diff options
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/ln.c | 6 | ||||
-rw-r--r-- | coreutils/ls.c | 75 | ||||
-rw-r--r-- | coreutils/md5sum.c | 6 | ||||
-rw-r--r-- | coreutils/printf.c | 2 | ||||
-rw-r--r-- | coreutils/tr.c | 40 | ||||
-rw-r--r-- | coreutils/uname.c | 12 |
6 files changed, 79 insertions, 62 deletions
diff --git a/coreutils/ln.c b/coreutils/ln.c index ead5322..e69cb02 100644 --- a/coreutils/ln.c +++ b/coreutils/ln.c @@ -30,9 +30,9 @@ #include <dirent.h> #include <errno.h> -#define LN_SYMLINK 1 -#define LN_FORCE 2 -#define LN_NODEREFERENCE 4 +static const int LN_SYMLINK = 1; +static const int LN_FORCE = 2; +static const int LN_NODEREFERENCE = 4; /* * linkDestName is where the link points to, diff --git a/coreutils/ls.c b/coreutils/ls.c index 754a6d4..0807680 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c @@ -41,9 +41,9 @@ * 1. requires lstat (BSD) - how do you do it without? */ -#define TERMINAL_WIDTH 80 /* use 79 if your terminal has linefold bug */ -#define COLUMN_WIDTH 14 /* default if AUTOWIDTH not defined */ -#define COLUMN_GAP 2 /* includes the file type char, if present */ +static const int TERMINAL_WIDTH = 80; /* use 79 if your terminal has linefold bug */ +static const int COLUMN_WIDTH = 14; /* default if AUTOWIDTH not defined */ +static const int COLUMN_GAP = 2; /* includes the file type char, if present */ /************************************************************************/ @@ -66,10 +66,12 @@ #endif /* what is the overall style of the listing */ -#define STYLE_AUTO 0 -#define STYLE_LONG 1 /* one record per line, extended info */ -#define STYLE_SINGLE 2 /* one record per line */ -#define STYLE_COLUMNS 3 /* fill columns */ +enum { +STYLE_AUTO = 0, +STYLE_LONG = 1, /* one record per line, extended info */ +STYLE_SINGLE = 2, /* one record per line */ +STYLE_COLUMNS = 3 /* fill columns */ +}; /* 51306 lrwxrwxrwx 1 root root 2 May 11 01:43 /bin/view -> vi* */ /* what file information will be listed */ @@ -99,23 +101,23 @@ #ifdef BB_FEATURE_LS_SORTFILES /* how will the files be sorted */ -#define SORT_FORWARD 0 /* sort in reverse order */ -#define SORT_REVERSE 1 /* sort in reverse order */ -#define SORT_NAME 2 /* sort by file name */ -#define SORT_SIZE 3 /* sort by file size */ -#define SORT_ATIME 4 /* sort by last access time */ -#define SORT_CTIME 5 /* sort by last change time */ -#define SORT_MTIME 6 /* sort by last modification time */ -#define SORT_VERSION 7 /* sort by version */ -#define SORT_EXT 8 /* sort by file name extension */ -#define SORT_DIR 9 /* sort by file or directory */ +static const int SORT_FORWARD = 0; /* sort in reverse order */ +static const int SORT_REVERSE = 1; /* sort in reverse order */ +static const int SORT_NAME = 2; /* sort by file name */ +static const int SORT_SIZE = 3; /* sort by file size */ +static const int SORT_ATIME = 4; /* sort by last access time */ +static const int SORT_CTIME = 5; /* sort by last change time */ +static const int SORT_MTIME = 6; /* sort by last modification time */ +static const int SORT_VERSION = 7; /* sort by version */ +static const int SORT_EXT = 8; /* sort by file name extension */ +static const int SORT_DIR = 9; /* sort by file or directory */ #endif #ifdef BB_FEATURE_LS_TIMESTAMPS /* which of the three times will be used */ -#define TIME_MOD 0 -#define TIME_CHANGE 1 -#define TIME_ACCESS 2 +static const int TIME_MOD = 0; +static const int TIME_CHANGE = 1; +static const int TIME_ACCESS = 2; #endif #define LIST_SHORT (LIST_FILENAME) @@ -125,9 +127,9 @@ LIST_SYMLINK) #define LIST_ILONG (LIST_INO | LIST_LONG) -#define SPLIT_DIR 0 -#define SPLIT_FILE 1 -#define SPLIT_SUBDIR 2 +static const int SPLIT_DIR = 0; +static const int SPLIT_FILE = 1; +static const int SPLIT_SUBDIR = 2; #define TYPEINDEX(mode) (((mode) >> 12) & 0x0f) #define TYPECHAR(mode) ("0pcCd?bB-?l?s???" [TYPEINDEX(mode)]) @@ -150,15 +152,15 @@ struct dnode **list_dir(char *); struct dnode **dnalloc(int); int list_single(struct dnode *); -static unsigned int disp_opts= DISP_NORMAL; -static unsigned int style_fmt= STYLE_AUTO ; -static unsigned int list_fmt= LIST_SHORT ; +static unsigned int disp_opts; +static unsigned int style_fmt; +static unsigned int list_fmt; #ifdef BB_FEATURE_LS_SORTFILES -static unsigned int sort_opts= SORT_FORWARD; -static unsigned int sort_order= SORT_FORWARD; +static unsigned int sort_opts; +static unsigned int sort_order; #endif #ifdef BB_FEATURE_LS_TIMESTAMPS -static unsigned int time_fmt= TIME_MOD; +static unsigned int time_fmt; #endif #ifdef BB_FEATURE_LS_FOLLOWLINKS static unsigned int follow_links=FALSE; @@ -166,12 +168,9 @@ static unsigned int follow_links=FALSE; static unsigned short column = 0; #ifdef BB_FEATURE_AUTOWIDTH -static unsigned short terminal_width = TERMINAL_WIDTH; -static unsigned short column_width = COLUMN_WIDTH; -static unsigned short tabstops = 8; -#else -#define terminal_width TERMINAL_WIDTH -#define column_width COLUMN_WIDTH +static unsigned short terminal_width; +static unsigned short column_width; +static unsigned short tabstops; #endif static int status = EXIT_SUCCESS; @@ -710,10 +709,16 @@ extern int ls_main(int argc, char **argv) list_fmt= LIST_SHORT; #ifdef BB_FEATURE_LS_SORTFILES sort_opts= SORT_NAME; + sort_order= SORT_FORWARD; #endif #ifdef BB_FEATURE_LS_TIMESTAMPS time_fmt= TIME_MOD; #endif +#ifdef BB_FEATURE_AUTOWIDTH + terminal_width = TERMINAL_WIDTH; + column_width = COLUMN_WIDTH; + tabstops = 8; +#endif nfiles=0; /* process options */ diff --git a/coreutils/md5sum.c b/coreutils/md5sum.c index 3458f2e..ad40780 100644 --- a/coreutils/md5sum.c +++ b/coreutils/md5sum.c @@ -91,7 +91,7 @@ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef _MD5_H -#define _MD5_H 1 +static const int _MD5_H = 1; #include <stdio.h> @@ -251,7 +251,7 @@ void *md5_finish_ctx(struct md5_ctx *ctx, void *resbuf) int md5_stream(FILE *stream, void *resblock) { /* Important: BLOCKSIZE must be a multiple of 64. */ -#define BLOCKSIZE 4096 +static const int BLOCKSIZE = 4096; struct md5_ctx ctx; char buffer[BLOCKSIZE + 72]; size_t sum; @@ -529,7 +529,7 @@ void md5_process_block(const void *buffer, size_t len, struct md5_ctx *ctx) /* The minimum length of a valid digest line in a file produced by `md5sum FILE' and read by `md5sum -c'. This length does not include any newline character at the end of a line. */ -#define MIN_DIGEST_LINE_LENGTH 35 /* 32 - message digest length +static const int MIN_DIGEST_LINE_LENGTH = 35; /* 32 - message digest length 2 - blank and binary indicator 1 - minimum filename length */ diff --git a/coreutils/printf.c b/coreutils/printf.c index 832ca13..72bc7ae 100644 --- a/coreutils/printf.c +++ b/coreutils/printf.c @@ -59,7 +59,7 @@ #ifndef S_IFMT -# define S_IFMT 0170000 +static const int S_IFMT = 0170000; #endif #if !defined(S_ISBLK) && defined(S_IFBLK) # define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) diff --git a/coreutils/tr.c b/coreutils/tr.c index fd547b8..d21e672 100644 --- a/coreutils/tr.c +++ b/coreutils/tr.c @@ -34,14 +34,15 @@ #define bb_need_write_error #include "messages.c" -#define ASCII 0377 +static const int ASCII = 0377; /* some glabals shared across this file */ static char com_fl, del_fl, sq_fl; -static unsigned char output[BUFSIZ], input[BUFSIZ]; -static unsigned char vector[ASCII + 1]; -static char invec[ASCII + 1], outvec[ASCII + 1]; static short in_index, out_index; +/* these last are pointers to static buffers declared in tr_main */ +static unsigned char *poutput, *pinput; +static unsigned char *pvector; +static char *pinvec, *poutvec; static void convert() @@ -52,22 +53,22 @@ static void convert() for (;;) { if (in_index == read_chars) { - if ((read_chars = read(0, (char *) input, BUFSIZ)) <= 0) { - if (write(1, (char *) output, out_index) != out_index) + if ((read_chars = read(0, (char *) pinput, BUFSIZ)) <= 0) { + if (write(1, (char *) poutput, out_index) != out_index) write(2, write_error, strlen(write_error)); exit(0); } in_index = 0; } - c = input[in_index++]; - coded = vector[c]; - if (del_fl && invec[c]) + c = pinput[in_index++]; + coded = pvector[c]; + if (del_fl && pinvec[c]) continue; - if (sq_fl && last == coded && (invec[c] || outvec[coded])) + if (sq_fl && last == coded && (pinvec[c] || poutvec[coded])) continue; - output[out_index++] = last = coded; + poutput[out_index++] = last = coded; if (out_index == BUFSIZ) { - if (write(1, (char *) output, out_index) != out_index) { + if (write(1, (char *) poutput, out_index) != out_index) { write(2, write_error, strlen(write_error)); exit(1); } @@ -86,9 +87,9 @@ static void map(register unsigned char *string1, unsigned int string1_len, for (j = 0, i = 0; i < string1_len; i++) { if (string2_len <= j) - vector[string1[i]] = last; + pvector[string1[i]] = last; else - vector[string1[i]] = last = string2[j++]; + pvector[string1[i]] = last = string2[j++]; } } @@ -143,6 +144,17 @@ extern int tr_main(int argc, char **argv) int output_length=0, input_length; int index = 1; int i; + /* set up big arrays here (better than making a bunch of static arrays up top) */ + unsigned char output[BUFSIZ], input[BUFSIZ]; + unsigned char vector[ASCII + 1]; + char invec[ASCII + 1], outvec[ASCII + 1]; + + /* ... but make them available globally */ + poutput = output; + pinput = input; + pvector = vector; + pinvec = invec; + poutvec = outvec; if (argc > 1 && argv[index][0] == '-') { for (ptr = (unsigned char *) &argv[index][1]; *ptr; ptr++) { diff --git a/coreutils/uname.c b/coreutils/uname.c index e7e9ff3..4f7c643 100644 --- a/coreutils/uname.c +++ b/coreutils/uname.c @@ -44,22 +44,22 @@ static void print_element(unsigned int mask, char *element); /* Values that are bitwise or'd into `toprint'. */ /* Operating system name. */ -#define PRINT_SYSNAME 1 +static const int PRINT_SYSNAME = 1; /* Node name on a communications network. */ -#define PRINT_NODENAME 2 +static const int PRINT_NODENAME = 2; /* Operating system release. */ -#define PRINT_RELEASE 4 +static const int PRINT_RELEASE = 4; /* Operating system version. */ -#define PRINT_VERSION 8 +static const int PRINT_VERSION = 8; /* Machine hardware name. */ -#define PRINT_MACHINE 16 +static const int PRINT_MACHINE = 16; /* Host processor type. */ -#define PRINT_PROCESSOR 32 +static const int PRINT_PROCESSOR = 32; /* Mask indicating which elements of the name to print. */ static unsigned char toprint; |