diff options
author | Mark Whitley <markw@lineo.com> | 2001-01-23 22:30:04 +0000 |
---|---|---|
committer | Mark Whitley <markw@lineo.com> | 2001-01-23 22:30:04 +0000 |
commit | 59ab025363d884deb2013dcaae6c968585a6ec72 (patch) | |
tree | 852d97bdc34c44dbcf29cc8b5cd9257a8c90f7b3 /coreutils | |
parent | 2b8d07c590249991fae975652aae86f5fca91f81 (diff) | |
download | busybox-w32-59ab025363d884deb2013dcaae6c968585a6ec72.tar.gz busybox-w32-59ab025363d884deb2013dcaae6c968585a6ec72.tar.bz2 busybox-w32-59ab025363d884deb2013dcaae6c968585a6ec72.zip |
#define -> static const int. Also got rid of some big static buffers.
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 ead5322fa..e69cb024a 100644 --- a/coreutils/ln.c +++ b/coreutils/ln.c | |||
@@ -30,9 +30,9 @@ | |||
30 | #include <dirent.h> | 30 | #include <dirent.h> |
31 | #include <errno.h> | 31 | #include <errno.h> |
32 | 32 | ||
33 | #define LN_SYMLINK 1 | 33 | static const int LN_SYMLINK = 1; |
34 | #define LN_FORCE 2 | 34 | static const int LN_FORCE = 2; |
35 | #define LN_NODEREFERENCE 4 | 35 | static const int LN_NODEREFERENCE = 4; |
36 | 36 | ||
37 | /* | 37 | /* |
38 | * linkDestName is where the link points to, | 38 | * linkDestName is where the link points to, |
diff --git a/coreutils/ls.c b/coreutils/ls.c index 754a6d450..080768027 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c | |||
@@ -41,9 +41,9 @@ | |||
41 | * 1. requires lstat (BSD) - how do you do it without? | 41 | * 1. requires lstat (BSD) - how do you do it without? |
42 | */ | 42 | */ |
43 | 43 | ||
44 | #define TERMINAL_WIDTH 80 /* use 79 if your terminal has linefold bug */ | 44 | static const int TERMINAL_WIDTH = 80; /* use 79 if your terminal has linefold bug */ |
45 | #define COLUMN_WIDTH 14 /* default if AUTOWIDTH not defined */ | 45 | static const int COLUMN_WIDTH = 14; /* default if AUTOWIDTH not defined */ |
46 | #define COLUMN_GAP 2 /* includes the file type char, if present */ | 46 | static const int COLUMN_GAP = 2; /* includes the file type char, if present */ |
47 | 47 | ||
48 | /************************************************************************/ | 48 | /************************************************************************/ |
49 | 49 | ||
@@ -66,10 +66,12 @@ | |||
66 | #endif | 66 | #endif |
67 | 67 | ||
68 | /* what is the overall style of the listing */ | 68 | /* what is the overall style of the listing */ |
69 | #define STYLE_AUTO 0 | 69 | enum { |
70 | #define STYLE_LONG 1 /* one record per line, extended info */ | 70 | STYLE_AUTO = 0, |
71 | #define STYLE_SINGLE 2 /* one record per line */ | 71 | STYLE_LONG = 1, /* one record per line, extended info */ |
72 | #define STYLE_COLUMNS 3 /* fill columns */ | 72 | STYLE_SINGLE = 2, /* one record per line */ |
73 | STYLE_COLUMNS = 3 /* fill columns */ | ||
74 | }; | ||
73 | 75 | ||
74 | /* 51306 lrwxrwxrwx 1 root root 2 May 11 01:43 /bin/view -> vi* */ | 76 | /* 51306 lrwxrwxrwx 1 root root 2 May 11 01:43 /bin/view -> vi* */ |
75 | /* what file information will be listed */ | 77 | /* what file information will be listed */ |
@@ -99,23 +101,23 @@ | |||
99 | 101 | ||
100 | #ifdef BB_FEATURE_LS_SORTFILES | 102 | #ifdef BB_FEATURE_LS_SORTFILES |
101 | /* how will the files be sorted */ | 103 | /* how will the files be sorted */ |
102 | #define SORT_FORWARD 0 /* sort in reverse order */ | 104 | static const int SORT_FORWARD = 0; /* sort in reverse order */ |
103 | #define SORT_REVERSE 1 /* sort in reverse order */ | 105 | static const int SORT_REVERSE = 1; /* sort in reverse order */ |
104 | #define SORT_NAME 2 /* sort by file name */ | 106 | static const int SORT_NAME = 2; /* sort by file name */ |
105 | #define SORT_SIZE 3 /* sort by file size */ | 107 | static const int SORT_SIZE = 3; /* sort by file size */ |
106 | #define SORT_ATIME 4 /* sort by last access time */ | 108 | static const int SORT_ATIME = 4; /* sort by last access time */ |
107 | #define SORT_CTIME 5 /* sort by last change time */ | 109 | static const int SORT_CTIME = 5; /* sort by last change time */ |
108 | #define SORT_MTIME 6 /* sort by last modification time */ | 110 | static const int SORT_MTIME = 6; /* sort by last modification time */ |
109 | #define SORT_VERSION 7 /* sort by version */ | 111 | static const int SORT_VERSION = 7; /* sort by version */ |
110 | #define SORT_EXT 8 /* sort by file name extension */ | 112 | static const int SORT_EXT = 8; /* sort by file name extension */ |
111 | #define SORT_DIR 9 /* sort by file or directory */ | 113 | static const int SORT_DIR = 9; /* sort by file or directory */ |
112 | #endif | 114 | #endif |
113 | 115 | ||
114 | #ifdef BB_FEATURE_LS_TIMESTAMPS | 116 | #ifdef BB_FEATURE_LS_TIMESTAMPS |
115 | /* which of the three times will be used */ | 117 | /* which of the three times will be used */ |
116 | #define TIME_MOD 0 | 118 | static const int TIME_MOD = 0; |
117 | #define TIME_CHANGE 1 | 119 | static const int TIME_CHANGE = 1; |
118 | #define TIME_ACCESS 2 | 120 | static const int TIME_ACCESS = 2; |
119 | #endif | 121 | #endif |
120 | 122 | ||
121 | #define LIST_SHORT (LIST_FILENAME) | 123 | #define LIST_SHORT (LIST_FILENAME) |
@@ -125,9 +127,9 @@ | |||
125 | LIST_SYMLINK) | 127 | LIST_SYMLINK) |
126 | #define LIST_ILONG (LIST_INO | LIST_LONG) | 128 | #define LIST_ILONG (LIST_INO | LIST_LONG) |
127 | 129 | ||
128 | #define SPLIT_DIR 0 | 130 | static const int SPLIT_DIR = 0; |
129 | #define SPLIT_FILE 1 | 131 | static const int SPLIT_FILE = 1; |
130 | #define SPLIT_SUBDIR 2 | 132 | static const int SPLIT_SUBDIR = 2; |
131 | 133 | ||
132 | #define TYPEINDEX(mode) (((mode) >> 12) & 0x0f) | 134 | #define TYPEINDEX(mode) (((mode) >> 12) & 0x0f) |
133 | #define TYPECHAR(mode) ("0pcCd?bB-?l?s???" [TYPEINDEX(mode)]) | 135 | #define TYPECHAR(mode) ("0pcCd?bB-?l?s???" [TYPEINDEX(mode)]) |
@@ -150,15 +152,15 @@ struct dnode **list_dir(char *); | |||
150 | struct dnode **dnalloc(int); | 152 | struct dnode **dnalloc(int); |
151 | int list_single(struct dnode *); | 153 | int list_single(struct dnode *); |
152 | 154 | ||
153 | static unsigned int disp_opts= DISP_NORMAL; | 155 | static unsigned int disp_opts; |
154 | static unsigned int style_fmt= STYLE_AUTO ; | 156 | static unsigned int style_fmt; |
155 | static unsigned int list_fmt= LIST_SHORT ; | 157 | static unsigned int list_fmt; |
156 | #ifdef BB_FEATURE_LS_SORTFILES | 158 | #ifdef BB_FEATURE_LS_SORTFILES |
157 | static unsigned int sort_opts= SORT_FORWARD; | 159 | static unsigned int sort_opts; |
158 | static unsigned int sort_order= SORT_FORWARD; | 160 | static unsigned int sort_order; |
159 | #endif | 161 | #endif |
160 | #ifdef BB_FEATURE_LS_TIMESTAMPS | 162 | #ifdef BB_FEATURE_LS_TIMESTAMPS |
161 | static unsigned int time_fmt= TIME_MOD; | 163 | static unsigned int time_fmt; |
162 | #endif | 164 | #endif |
163 | #ifdef BB_FEATURE_LS_FOLLOWLINKS | 165 | #ifdef BB_FEATURE_LS_FOLLOWLINKS |
164 | static unsigned int follow_links=FALSE; | 166 | static unsigned int follow_links=FALSE; |
@@ -166,12 +168,9 @@ static unsigned int follow_links=FALSE; | |||
166 | 168 | ||
167 | static unsigned short column = 0; | 169 | static unsigned short column = 0; |
168 | #ifdef BB_FEATURE_AUTOWIDTH | 170 | #ifdef BB_FEATURE_AUTOWIDTH |
169 | static unsigned short terminal_width = TERMINAL_WIDTH; | 171 | static unsigned short terminal_width; |
170 | static unsigned short column_width = COLUMN_WIDTH; | 172 | static unsigned short column_width; |
171 | static unsigned short tabstops = 8; | 173 | static unsigned short tabstops; |
172 | #else | ||
173 | #define terminal_width TERMINAL_WIDTH | ||
174 | #define column_width COLUMN_WIDTH | ||
175 | #endif | 174 | #endif |
176 | 175 | ||
177 | static int status = EXIT_SUCCESS; | 176 | static int status = EXIT_SUCCESS; |
@@ -710,10 +709,16 @@ extern int ls_main(int argc, char **argv) | |||
710 | list_fmt= LIST_SHORT; | 709 | list_fmt= LIST_SHORT; |
711 | #ifdef BB_FEATURE_LS_SORTFILES | 710 | #ifdef BB_FEATURE_LS_SORTFILES |
712 | sort_opts= SORT_NAME; | 711 | sort_opts= SORT_NAME; |
712 | sort_order= SORT_FORWARD; | ||
713 | #endif | 713 | #endif |
714 | #ifdef BB_FEATURE_LS_TIMESTAMPS | 714 | #ifdef BB_FEATURE_LS_TIMESTAMPS |
715 | time_fmt= TIME_MOD; | 715 | time_fmt= TIME_MOD; |
716 | #endif | 716 | #endif |
717 | #ifdef BB_FEATURE_AUTOWIDTH | ||
718 | terminal_width = TERMINAL_WIDTH; | ||
719 | column_width = COLUMN_WIDTH; | ||
720 | tabstops = 8; | ||
721 | #endif | ||
717 | nfiles=0; | 722 | nfiles=0; |
718 | 723 | ||
719 | /* process options */ | 724 | /* process options */ |
diff --git a/coreutils/md5sum.c b/coreutils/md5sum.c index 3458f2e05..ad4078040 100644 --- a/coreutils/md5sum.c +++ b/coreutils/md5sum.c | |||
@@ -91,7 +91,7 @@ | |||
91 | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | 91 | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
92 | 92 | ||
93 | #ifndef _MD5_H | 93 | #ifndef _MD5_H |
94 | #define _MD5_H 1 | 94 | static const int _MD5_H = 1; |
95 | 95 | ||
96 | #include <stdio.h> | 96 | #include <stdio.h> |
97 | 97 | ||
@@ -251,7 +251,7 @@ void *md5_finish_ctx(struct md5_ctx *ctx, void *resbuf) | |||
251 | int md5_stream(FILE *stream, void *resblock) | 251 | int md5_stream(FILE *stream, void *resblock) |
252 | { | 252 | { |
253 | /* Important: BLOCKSIZE must be a multiple of 64. */ | 253 | /* Important: BLOCKSIZE must be a multiple of 64. */ |
254 | #define BLOCKSIZE 4096 | 254 | static const int BLOCKSIZE = 4096; |
255 | struct md5_ctx ctx; | 255 | struct md5_ctx ctx; |
256 | char buffer[BLOCKSIZE + 72]; | 256 | char buffer[BLOCKSIZE + 72]; |
257 | size_t sum; | 257 | size_t sum; |
@@ -529,7 +529,7 @@ void md5_process_block(const void *buffer, size_t len, struct md5_ctx *ctx) | |||
529 | /* The minimum length of a valid digest line in a file produced | 529 | /* The minimum length of a valid digest line in a file produced |
530 | by `md5sum FILE' and read by `md5sum -c'. This length does | 530 | by `md5sum FILE' and read by `md5sum -c'. This length does |
531 | not include any newline character at the end of a line. */ | 531 | not include any newline character at the end of a line. */ |
532 | #define MIN_DIGEST_LINE_LENGTH 35 /* 32 - message digest length | 532 | static const int MIN_DIGEST_LINE_LENGTH = 35; /* 32 - message digest length |
533 | 2 - blank and binary indicator | 533 | 2 - blank and binary indicator |
534 | 1 - minimum filename length */ | 534 | 1 - minimum filename length */ |
535 | 535 | ||
diff --git a/coreutils/printf.c b/coreutils/printf.c index 832ca13d6..72bc7ae89 100644 --- a/coreutils/printf.c +++ b/coreutils/printf.c | |||
@@ -59,7 +59,7 @@ | |||
59 | 59 | ||
60 | 60 | ||
61 | #ifndef S_IFMT | 61 | #ifndef S_IFMT |
62 | # define S_IFMT 0170000 | 62 | static const int S_IFMT = 0170000; |
63 | #endif | 63 | #endif |
64 | #if !defined(S_ISBLK) && defined(S_IFBLK) | 64 | #if !defined(S_ISBLK) && defined(S_IFBLK) |
65 | # define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) | 65 | # define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) |
diff --git a/coreutils/tr.c b/coreutils/tr.c index fd547b87d..d21e672fe 100644 --- a/coreutils/tr.c +++ b/coreutils/tr.c | |||
@@ -34,14 +34,15 @@ | |||
34 | #define bb_need_write_error | 34 | #define bb_need_write_error |
35 | #include "messages.c" | 35 | #include "messages.c" |
36 | 36 | ||
37 | #define ASCII 0377 | 37 | static const int ASCII = 0377; |
38 | 38 | ||
39 | /* some glabals shared across this file */ | 39 | /* some glabals shared across this file */ |
40 | static char com_fl, del_fl, sq_fl; | 40 | static char com_fl, del_fl, sq_fl; |
41 | static unsigned char output[BUFSIZ], input[BUFSIZ]; | ||
42 | static unsigned char vector[ASCII + 1]; | ||
43 | static char invec[ASCII + 1], outvec[ASCII + 1]; | ||
44 | static short in_index, out_index; | 41 | static short in_index, out_index; |
42 | /* these last are pointers to static buffers declared in tr_main */ | ||
43 | static unsigned char *poutput, *pinput; | ||
44 | static unsigned char *pvector; | ||
45 | static char *pinvec, *poutvec; | ||
45 | 46 | ||
46 | 47 | ||
47 | static void convert() | 48 | static void convert() |
@@ -52,22 +53,22 @@ static void convert() | |||
52 | 53 | ||
53 | for (;;) { | 54 | for (;;) { |
54 | if (in_index == read_chars) { | 55 | if (in_index == read_chars) { |
55 | if ((read_chars = read(0, (char *) input, BUFSIZ)) <= 0) { | 56 | if ((read_chars = read(0, (char *) pinput, BUFSIZ)) <= 0) { |
56 | if (write(1, (char *) output, out_index) != out_index) | 57 | if (write(1, (char *) poutput, out_index) != out_index) |
57 | write(2, write_error, strlen(write_error)); | 58 | write(2, write_error, strlen(write_error)); |
58 | exit(0); | 59 | exit(0); |
59 | } | 60 | } |
60 | in_index = 0; | 61 | in_index = 0; |
61 | } | 62 | } |
62 | c = input[in_index++]; | 63 | c = pinput[in_index++]; |
63 | coded = vector[c]; | 64 | coded = pvector[c]; |
64 | if (del_fl && invec[c]) | 65 | if (del_fl && pinvec[c]) |
65 | continue; | 66 | continue; |
66 | if (sq_fl && last == coded && (invec[c] || outvec[coded])) | 67 | if (sq_fl && last == coded && (pinvec[c] || poutvec[coded])) |
67 | continue; | 68 | continue; |
68 | output[out_index++] = last = coded; | 69 | poutput[out_index++] = last = coded; |
69 | if (out_index == BUFSIZ) { | 70 | if (out_index == BUFSIZ) { |
70 | if (write(1, (char *) output, out_index) != out_index) { | 71 | if (write(1, (char *) poutput, out_index) != out_index) { |
71 | write(2, write_error, strlen(write_error)); | 72 | write(2, write_error, strlen(write_error)); |
72 | exit(1); | 73 | exit(1); |
73 | } | 74 | } |
@@ -86,9 +87,9 @@ static void map(register unsigned char *string1, unsigned int string1_len, | |||
86 | 87 | ||
87 | for (j = 0, i = 0; i < string1_len; i++) { | 88 | for (j = 0, i = 0; i < string1_len; i++) { |
88 | if (string2_len <= j) | 89 | if (string2_len <= j) |
89 | vector[string1[i]] = last; | 90 | pvector[string1[i]] = last; |
90 | else | 91 | else |
91 | vector[string1[i]] = last = string2[j++]; | 92 | pvector[string1[i]] = last = string2[j++]; |
92 | } | 93 | } |
93 | } | 94 | } |
94 | 95 | ||
@@ -143,6 +144,17 @@ extern int tr_main(int argc, char **argv) | |||
143 | int output_length=0, input_length; | 144 | int output_length=0, input_length; |
144 | int index = 1; | 145 | int index = 1; |
145 | int i; | 146 | int i; |
147 | /* set up big arrays here (better than making a bunch of static arrays up top) */ | ||
148 | unsigned char output[BUFSIZ], input[BUFSIZ]; | ||
149 | unsigned char vector[ASCII + 1]; | ||
150 | char invec[ASCII + 1], outvec[ASCII + 1]; | ||
151 | |||
152 | /* ... but make them available globally */ | ||
153 | poutput = output; | ||
154 | pinput = input; | ||
155 | pvector = vector; | ||
156 | pinvec = invec; | ||
157 | poutvec = outvec; | ||
146 | 158 | ||
147 | if (argc > 1 && argv[index][0] == '-') { | 159 | if (argc > 1 && argv[index][0] == '-') { |
148 | for (ptr = (unsigned char *) &argv[index][1]; *ptr; ptr++) { | 160 | for (ptr = (unsigned char *) &argv[index][1]; *ptr; ptr++) { |
diff --git a/coreutils/uname.c b/coreutils/uname.c index e7e9ff331..4f7c643f9 100644 --- a/coreutils/uname.c +++ b/coreutils/uname.c | |||
@@ -44,22 +44,22 @@ static void print_element(unsigned int mask, char *element); | |||
44 | 44 | ||
45 | /* Values that are bitwise or'd into `toprint'. */ | 45 | /* Values that are bitwise or'd into `toprint'. */ |
46 | /* Operating system name. */ | 46 | /* Operating system name. */ |
47 | #define PRINT_SYSNAME 1 | 47 | static const int PRINT_SYSNAME = 1; |
48 | 48 | ||
49 | /* Node name on a communications network. */ | 49 | /* Node name on a communications network. */ |
50 | #define PRINT_NODENAME 2 | 50 | static const int PRINT_NODENAME = 2; |
51 | 51 | ||
52 | /* Operating system release. */ | 52 | /* Operating system release. */ |
53 | #define PRINT_RELEASE 4 | 53 | static const int PRINT_RELEASE = 4; |
54 | 54 | ||
55 | /* Operating system version. */ | 55 | /* Operating system version. */ |
56 | #define PRINT_VERSION 8 | 56 | static const int PRINT_VERSION = 8; |
57 | 57 | ||
58 | /* Machine hardware name. */ | 58 | /* Machine hardware name. */ |
59 | #define PRINT_MACHINE 16 | 59 | static const int PRINT_MACHINE = 16; |
60 | 60 | ||
61 | /* Host processor type. */ | 61 | /* Host processor type. */ |
62 | #define PRINT_PROCESSOR 32 | 62 | static const int PRINT_PROCESSOR = 32; |
63 | 63 | ||
64 | /* Mask indicating which elements of the name to print. */ | 64 | /* Mask indicating which elements of the name to print. */ |
65 | static unsigned char toprint; | 65 | static unsigned char toprint; |