1
1

Some compatibility improvements for older (C89) environments

Whether this actually works on older environments, I don't really know.
Этот коммит содержится в:
Yorhel 2022-02-07 13:28:14 +01:00
родитель b340c04450
Коммит 15ebd21195
8 изменённых файлов: 19 добавлений и 32 удалений

Просмотреть файл

@ -45,6 +45,8 @@ EXTRA_DIST=ncdu.1 doc/ncdu.pod
ncdu.1: $(srcdir)/doc/ncdu.pod ncdu.1: $(srcdir)/doc/ncdu.pod
pod2man --center "ncdu manual" --release "@PACKAGE@-@VERSION@" "$(srcdir)/doc/ncdu.pod" >ncdu.1 pod2man --center "ncdu manual" --release "@PACKAGE@-@VERSION@" "$(srcdir)/doc/ncdu.pod" >ncdu.1
# This target exists more for documentation purposes than actual use; some
# dependencies have minor ncdu-specific changes.
update-deps: update-deps:
wget -q https://raw.github.com/attractivechaos/klib/master/khashl.h -O "$(srcdir)/deps/khashl.h" wget -q https://raw.github.com/attractivechaos/klib/master/khashl.h -O "$(srcdir)/deps/khashl.h"
wget -q http://g.blicky.net/ylib.git/plain/yopt.h -O "$(srcdir)/deps/yopt.h" wget -q http://g.blicky.net/ylib.git/plain/yopt.h -O "$(srcdir)/deps/yopt.h"

Просмотреть файл

@ -1,10 +1,11 @@
AC_INIT([ncdu],[1.16],[projects@yorhel.nl]) AC_INIT([ncdu],[1.16],[projects@yorhel.nl])
AC_CONFIG_SRCDIR([src/global.h]) AC_CONFIG_SRCDIR([src/global.h])
AC_CONFIG_HEADER([config.h]) AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE([foreign std-options subdir-objects]) AM_INIT_AUTOMAKE([foreign std-options subdir-objects])
# Check for programs. # Check for programs.
AC_USE_SYSTEM_EXTENSIONS
AC_PROG_CC AC_PROG_CC
AC_PROG_INSTALL AC_PROG_INSTALL
AC_PROG_RANLIB AC_PROG_RANLIB
@ -22,6 +23,8 @@ AC_TYPE_INT64_T
AC_TYPE_UINT64_T AC_TYPE_UINT64_T
AC_SYS_LARGEFILE AC_SYS_LARGEFILE
AC_STRUCT_ST_BLOCKS AC_STRUCT_ST_BLOCKS
AC_C_INLINE
AC_C_FLEXIBLE_ARRAY_MEMBER
# Check for library functions. # Check for library functions.
AC_CHECK_FUNCS( AC_CHECK_FUNCS(

27
deps/strnatcmp.c поставляемый
Просмотреть файл

@ -28,35 +28,22 @@
* Eric Sosman pointed out that ctype functions take a parameter whose * Eric Sosman pointed out that ctype functions take a parameter whose
* value must be that of an unsigned int, even on platforms that have * value must be that of an unsigned int, even on platforms that have
* negative chars in their default char type. * negative chars in their default char type.
*
* ncdu edits:
* - static inline -> #define for better compatibility
* - don't use ctype.h, for more predictable results
*/ */
#include <stddef.h> /* size_t */ #include <stddef.h> /* size_t */
#include <ctype.h>
#include "strnatcmp.h" #include "strnatcmp.h"
/* These are defined as macros to make it easier to adapt this code to /* These are defined as macros to make it easier to adapt this code to
* different characters types or comparison functions. */ * different characters types or comparison functions. */
static inline int #define nat_isdigit(a) ((a) >= '0' && (a) <= '9')
nat_isdigit(nat_char a) #define nat_isspace(a) ((a) == ' ' || (a) == '\t' || (a) == '\r' || (a) == '\n')
{ #define nat_toupper(a) (a)
return isdigit((unsigned char) a);
}
static inline int
nat_isspace(nat_char a)
{
return isspace((unsigned char) a);
}
static inline nat_char
nat_toupper(nat_char a)
{
return toupper((unsigned char) a);
}
static int static int

Просмотреть файл

@ -465,7 +465,7 @@ static int iteminfo(void) {
C(rint64(&iv, UINT64_MAX)); C(rint64(&iv, UINT64_MAX));
ctx->buf_dir->flags |= FF_EXT; ctx->buf_dir->flags |= FF_EXT;
ctx->buf_ext->mtime = iv; ctx->buf_ext->mtime = iv;
// Accept decimal numbers, but discard the fractional part because our data model doesn't support it. /* Accept decimal numbers, but discard the fractional part because our data model doesn't support it. */
if(*ctx->buf == '.') { if(*ctx->buf == '.') {
con(1); con(1);
while(*ctx->buf >= '0' && *ctx->buf <= '9') while(*ctx->buf >= '0' && *ctx->buf <= '9')

Просмотреть файл

@ -127,7 +127,7 @@ static int item(struct dir *dir, const char *name, struct dir_ext *ext, unsigned
item = xmalloc(dir->flags & FF_EXT ? dir_ext_memsize(name) : dir_memsize(name)); item = xmalloc(dir->flags & FF_EXT ? dir_ext_memsize(name) : dir_memsize(name));
memcpy(item, dir, offsetof(struct dir, name)); memcpy(item, dir, offsetof(struct dir, name));
strcpy(item->name, name); strcpy(item->name, name);
if(dir->flags & FF_EXT) if(item->flags & FF_EXT)
memcpy(dir_ext_ptr(item), ext, sizeof(struct dir_ext)); memcpy(dir_ext_ptr(item), ext, sizeof(struct dir_ext));
item_add(item); item_add(item);

Просмотреть файл

@ -70,7 +70,7 @@ struct dir {
struct dir *parent, *next, *prev, *sub, *hlnk; struct dir *parent, *next, *prev, *sub, *hlnk;
int items; int items;
unsigned short flags; unsigned short flags;
char name[]; char name[FLEXIBLE_ARRAY_MEMBER];
}; };
/* A note on the ino and dev fields above: ino is usually represented as ino_t, /* A note on the ino and dev fields above: ino is usually represented as ino_t,

Просмотреть файл

@ -40,7 +40,7 @@ static void set_level(void) {
if(done) if(done)
return; return;
const char *lvl = getenv("NCDU_LEVEL"); const char *lvl = getenv("NCDU_LEVEL");
// too lazy to count beyond 9 /* too lazy to count beyond 9 */
if(lvl && *lvl >= '1' && *lvl < '9' && lvl[1] == 0) { if(lvl && *lvl >= '1' && *lvl < '9' && lvl[1] == 0) {
nlvl[0] = 1 + *lvl; nlvl[0] = 1 + *lvl;
nlvl[1] = 0; nlvl[1] = 0;

Просмотреть файл

@ -73,17 +73,12 @@ extern int subwinr, subwinc;
extern int si; extern int si;
/* Macros/functions for managing struct dir and struct dir_ext */ /* Macros for managing struct dir and struct dir_ext */
#define dir_memsize(n) (offsetof(struct dir, name)+1+strlen(n)) #define dir_memsize(n) (offsetof(struct dir, name)+1+strlen(n))
#define dir_ext_offset(n) ((dir_memsize(n) + 7) & ~7) #define dir_ext_offset(n) ((dir_memsize(n) + 7) & ~7)
#define dir_ext_memsize(n) (dir_ext_offset(n) + sizeof(struct dir_ext)) #define dir_ext_memsize(n) (dir_ext_offset(n) + sizeof(struct dir_ext))
#define dir_ext_ptr(d) ((d)->flags & FF_EXT ? (struct dir_ext *) ( ((char *)(d)) + dir_ext_offset((d)->name) ) : NULL)
static inline struct dir_ext *dir_ext_ptr(struct dir *d) {
return d->flags & FF_EXT
? (struct dir_ext *) ( ((char *)d) + dir_ext_offset(d->name) )
: NULL;
}
/* Instead of using several ncurses windows, we only draw to stdscr. /* Instead of using several ncurses windows, we only draw to stdscr.