diff options
-rw-r--r-- | coreutils/diff.c | 120 | ||||
-rw-r--r-- | miscutils/nmeter.c | 9 |
2 files changed, 79 insertions, 50 deletions
diff --git a/coreutils/diff.c b/coreutils/diff.c index f6b045b2d..faab287f8 100644 --- a/coreutils/diff.c +++ b/coreutils/diff.c | |||
@@ -65,36 +65,16 @@ | |||
65 | #define FLAG_U (1<<12) | 65 | #define FLAG_U (1<<12) |
66 | #define FLAG_w (1<<13) | 66 | #define FLAG_w (1<<13) |
67 | 67 | ||
68 | /* The following variables should be static, but gcc currently | ||
69 | * creates a much bigger object if we do this. [which version of gcc? --vda] */ | ||
70 | /* 4.x, IIRC also 3.x --bernhard */ | ||
71 | /* Works for gcc 3.4.3. Sizes without and with "static": | ||
72 | # size busybox.t[34]/coreutils/diff.o | ||
73 | text data bss dec hex filename | ||
74 | 6969 8 305 7282 1c72 busybox.t3/coreutils/diff.o | ||
75 | 6969 8 305 7282 1c72 busybox.t4/coreutils/diff.o | ||
76 | --vda | ||
77 | */ | ||
78 | /* This is the default number of lines of context. */ | ||
79 | static int context = 3; | ||
80 | static int status; | ||
81 | static char *start; | ||
82 | static const char *label1; | ||
83 | static const char *label2; | ||
84 | static struct stat stb1, stb2; | ||
85 | USE_FEATURE_DIFF_DIR(static char **dl;) | ||
86 | USE_FEATURE_DIFF_DIR(static int dl_count;) | ||
87 | |||
88 | struct cand { | 68 | struct cand { |
89 | int x; | 69 | int x; |
90 | int y; | 70 | int y; |
91 | int pred; | 71 | int pred; |
92 | }; | 72 | }; |
93 | 73 | ||
94 | static struct line { | 74 | struct line { |
95 | int serial; | 75 | int serial; |
96 | int value; | 76 | int value; |
97 | } *file[2]; | 77 | }; |
98 | 78 | ||
99 | /* | 79 | /* |
100 | * The following struct is used to record change information | 80 | * The following struct is used to record change information |
@@ -102,29 +82,79 @@ static struct line { | |||
102 | * understand the highly mnemonic field names) | 82 | * understand the highly mnemonic field names) |
103 | */ | 83 | */ |
104 | struct context_vec { | 84 | struct context_vec { |
105 | int a; /* start line in old file */ | 85 | int a; /* start line in old file */ |
106 | int b; /* end line in old file */ | 86 | int b; /* end line in old file */ |
107 | int c; /* start line in new file */ | 87 | int c; /* start line in new file */ |
108 | int d; /* end line in new file */ | 88 | int d; /* end line in new file */ |
89 | }; | ||
90 | |||
91 | struct globals { | ||
92 | USE_FEATURE_DIFF_DIR(char **dl;) | ||
93 | USE_FEATURE_DIFF_DIR(int dl_count;) | ||
94 | /* This is the default number of lines of context. */ | ||
95 | int context; | ||
96 | size_t max_context; | ||
97 | int status; | ||
98 | char *start; | ||
99 | const char *label1; | ||
100 | const char *label2; | ||
101 | struct line *file[2]; | ||
102 | int *J; /* will be overlaid on class */ | ||
103 | int *class; /* will be overlaid on file[0] */ | ||
104 | int *klist; /* will be overlaid on file[0] after class */ | ||
105 | int *member; /* will be overlaid on file[1] */ | ||
106 | int clen; | ||
107 | int len[2]; | ||
108 | int pref, suff; /* length of prefix and suffix */ | ||
109 | int slen[2]; | ||
110 | bool anychange; | ||
111 | long *ixnew; /* will be overlaid on file[1] */ | ||
112 | long *ixold; /* will be overlaid on klist */ | ||
113 | struct cand *clist; /* merely a free storage pot for candidates */ | ||
114 | int clistlen; /* the length of clist */ | ||
115 | struct line *sfile[2]; /* shortened by pruning common prefix/suffix */ | ||
116 | struct context_vec *context_vec_start; | ||
117 | struct context_vec *context_vec_end; | ||
118 | struct context_vec *context_vec_ptr; | ||
119 | struct stat stb1, stb2; | ||
109 | }; | 120 | }; |
121 | #define G (*ptr_to_globals) | ||
122 | #define dl (G.dl ) | ||
123 | #define dl_count (G.dl_count ) | ||
124 | #define context (G.context ) | ||
125 | #define max_context (G.max_context ) | ||
126 | #define status (G.status ) | ||
127 | #define start (G.start ) | ||
128 | #define label1 (G.label1 ) | ||
129 | #define label2 (G.label2 ) | ||
130 | #define file (G.file ) | ||
131 | #define J (G.J ) | ||
132 | #define class (G.class ) | ||
133 | #define klist (G.klist ) | ||
134 | #define member (G.member ) | ||
135 | #define clen (G.clen ) | ||
136 | #define len (G.len ) | ||
137 | #define pref (G.pref ) | ||
138 | #define suff (G.suff ) | ||
139 | #define slen (G.slen ) | ||
140 | #define anychange (G.anychange ) | ||
141 | #define ixnew (G.ixnew ) | ||
142 | #define ixold (G.ixold ) | ||
143 | #define clist (G.clist ) | ||
144 | #define clistlen (G.clistlen ) | ||
145 | #define sfile (G.sfile ) | ||
146 | #define context_vec_start (G.context_vec_start ) | ||
147 | #define context_vec_end (G.context_vec_end ) | ||
148 | #define context_vec_ptr (G.context_vec_ptr ) | ||
149 | #define stb1 (G.stb1 ) | ||
150 | #define stb2 (G.stb2 ) | ||
151 | #define INIT_G() do { \ | ||
152 | PTR_TO_GLOBALS = xzalloc(sizeof(G)); \ | ||
153 | context = 3; \ | ||
154 | max_context = 64; \ | ||
155 | } while (0) | ||
156 | |||
110 | 157 | ||
111 | static int *J; /* will be overlaid on class */ | ||
112 | static int *class; /* will be overlaid on file[0] */ | ||
113 | static int *klist; /* will be overlaid on file[0] after class */ | ||
114 | static int *member; /* will be overlaid on file[1] */ | ||
115 | static int clen; | ||
116 | static int len[2]; | ||
117 | static int pref, suff; /* length of prefix and suffix */ | ||
118 | static int slen[2]; | ||
119 | static bool anychange; | ||
120 | static long *ixnew; /* will be overlaid on file[1] */ | ||
121 | static long *ixold; /* will be overlaid on klist */ | ||
122 | static struct cand *clist; /* merely a free storage pot for candidates */ | ||
123 | static int clistlen; /* the length of clist */ | ||
124 | static struct line *sfile[2]; /* shortened by pruning common prefix/suffix */ | ||
125 | static struct context_vec *context_vec_start; | ||
126 | static struct context_vec *context_vec_end; | ||
127 | static struct context_vec *context_vec_ptr; | ||
128 | 158 | ||
129 | 159 | ||
130 | static void print_only(const char *path, size_t dirlen, const char *entry) | 160 | static void print_only(const char *path, size_t dirlen, const char *entry) |
@@ -761,8 +791,6 @@ static void print_header(const char *file1, const char *file2) | |||
761 | static void change(char *file1, FILE * f1, char *file2, FILE * f2, int a, | 791 | static void change(char *file1, FILE * f1, char *file2, FILE * f2, int a, |
762 | int b, int c, int d) | 792 | int b, int c, int d) |
763 | { | 793 | { |
764 | static size_t max_context = 64; | ||
765 | |||
766 | if ((a > b && c > d) || (option_mask32 & FLAG_q)) { | 794 | if ((a > b && c > d) || (option_mask32 & FLAG_q)) { |
767 | anychange = 1; | 795 | anychange = 1; |
768 | return; | 796 | return; |
@@ -1170,6 +1198,8 @@ int diff_main(int argc, char **argv) | |||
1170 | char *f1, *f2; | 1198 | char *f1, *f2; |
1171 | llist_t *L_arg = NULL; | 1199 | llist_t *L_arg = NULL; |
1172 | 1200 | ||
1201 | INIT_G(); | ||
1202 | |||
1173 | /* exactly 2 params; collect multiple -L <label> */ | 1203 | /* exactly 2 params; collect multiple -L <label> */ |
1174 | opt_complementary = "=2:L::"; | 1204 | opt_complementary = "=2:L::"; |
1175 | getopt32(argc, argv, "abdiL:NqrsS:tTU:wu" | 1205 | getopt32(argc, argv, "abdiL:NqrsS:tTU:wu" |
diff --git a/miscutils/nmeter.c b/miscutils/nmeter.c index 3152b74e3..1d58eb2c1 100644 --- a/miscutils/nmeter.c +++ b/miscutils/nmeter.c | |||
@@ -69,16 +69,16 @@ struct globals { | |||
69 | #define proc_meminfo (G.proc_meminfo ) | 69 | #define proc_meminfo (G.proc_meminfo ) |
70 | #define proc_diskstats (G.proc_diskstats ) | 70 | #define proc_diskstats (G.proc_diskstats ) |
71 | #define proc_sys_fs_filenr (G.proc_sys_fs_filenr) | 71 | #define proc_sys_fs_filenr (G.proc_sys_fs_filenr) |
72 | |||
73 | // We depend on this being a char[], not char* - we take sizeof() of it | ||
74 | #define outbuf bb_common_bufsiz1 | ||
75 | |||
76 | #define INIT_G() do { \ | 72 | #define INIT_G() do { \ |
73 | PTR_TO_GLOBALS = xzalloc(sizeof(G)); \ | ||
77 | cur_outbuf = outbuf; \ | 74 | cur_outbuf = outbuf; \ |
78 | final_str = "\n"; \ | 75 | final_str = "\n"; \ |
79 | deltanz = delta = 1000000; \ | 76 | deltanz = delta = 1000000; \ |
80 | } while (0) | 77 | } while (0) |
81 | 78 | ||
79 | // We depend on this being a char[], not char* - we take sizeof() of it | ||
80 | #define outbuf bb_common_bufsiz1 | ||
81 | |||
82 | static inline void reset_outbuf(void) | 82 | static inline void reset_outbuf(void) |
83 | { | 83 | { |
84 | cur_outbuf = outbuf; | 84 | cur_outbuf = outbuf; |
@@ -774,7 +774,6 @@ int nmeter_main(int argc, char **argv) | |||
774 | s_stat *s; | 774 | s_stat *s; |
775 | char *cur, *prev; | 775 | char *cur, *prev; |
776 | 776 | ||
777 | PTR_TO_GLOBALS = xzalloc(sizeof(G)); | ||
778 | INIT_G(); | 777 | INIT_G(); |
779 | 778 | ||
780 | xchdir("/proc"); | 779 | xchdir("/proc"); |