diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-05-30 02:01:40 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-05-30 02:01:40 +0000 |
commit | 0b3b41b62acd6c2911ea4f08e0dd96f93334aff5 (patch) | |
tree | e8e0559748045acacaf5702eb72c6c05ca56268a | |
parent | 27f79ff03d2b4614d013948d95a5bc697ec41962 (diff) | |
download | busybox-w32-0b3b41b62acd6c2911ea4f08e0dd96f93334aff5.tar.gz busybox-w32-0b3b41b62acd6c2911ea4f08e0dd96f93334aff5.tar.bz2 busybox-w32-0b3b41b62acd6c2911ea4f08e0dd96f93334aff5.zip |
vi: move some data to malloc'ed space: ~500 less bss, code
size is smaller too (subject to arch differenced I guess)
-rw-r--r-- | editors/vi.c | 110 |
1 files changed, 68 insertions, 42 deletions
diff --git a/editors/vi.c b/editors/vi.c index 97ca802dc..cd64aacc9 100644 --- a/editors/vi.c +++ b/editors/vi.c | |||
@@ -104,61 +104,87 @@ static int vi_setops; | |||
104 | #define err_method (vi_setops & VI_ERR_METHOD) | 104 | #define err_method (vi_setops & VI_ERR_METHOD) |
105 | 105 | ||
106 | 106 | ||
107 | static int editing; // >0 while we are editing a file | 107 | static smallint editing; // >0 while we are editing a file |
108 | static int cmd_mode; // 0=command 1=insert 2=replace | 108 | // [code audit says "can be 0 or 1 only"] |
109 | static int file_modified; // buffer contents changed | 109 | static smallint cmd_mode; // 0=command 1=insert 2=replace |
110 | static int last_file_modified = -1; | 110 | static smallint file_modified; // buffer contents changed |
111 | static int fn_start; // index of first cmd line file name | 111 | static smallint last_file_modified = -1; |
112 | static int save_argc; // how many file names on cmd line | 112 | static int fn_start; // index of first cmd line file name |
113 | static int cmdcnt; // repetition count | 113 | static int save_argc; // how many file names on cmd line |
114 | static int rows, columns; // the terminal screen is this size | 114 | static int cmdcnt; // repetition count |
115 | static int crow, ccol, offset; // cursor is on Crow x Ccol with Horz Ofset | 115 | static int rows, columns; // the terminal screen is this size |
116 | static char *status_buffer; // mesages to the user | 116 | static int crow, ccol, offset; // cursor is on Crow x Ccol with Horz Ofset |
117 | static char *status_buffer; // mesages to the user | ||
117 | #define STATUS_BUFFER_LEN 200 | 118 | #define STATUS_BUFFER_LEN 200 |
118 | static int have_status_msg; // is default edit status needed? | 119 | static int have_status_msg; // is default edit status needed? |
120 | // [don't make smallint!] | ||
119 | static int last_status_cksum; // hash of current status line | 121 | static int last_status_cksum; // hash of current status line |
120 | static char *cfn; // previous, current, and next file name | 122 | static char *cfn; // previous, current, and next file name |
121 | static char *text, *end; // pointers to the user data in memory | 123 | //static char *text, *end; // pointers to the user data in memory |
122 | static char *screen; // pointer to the virtual screen buffer | 124 | static char *screen; // pointer to the virtual screen buffer |
123 | static int screensize; // and its size | 125 | static int screensize; // and its size |
124 | static char *screenbegin; // index into text[], of top line on the screen | 126 | static char *screenbegin; // index into text[], of top line on the screen |
125 | static char *dot; // where all the action takes place | 127 | //static char *dot; // where all the action takes place |
126 | static int tabstop; | 128 | static int tabstop; |
127 | static struct termios term_orig, term_vi; // remember what the cooked mode was | ||
128 | static char erase_char; // the users erase character | 129 | static char erase_char; // the users erase character |
129 | static char last_input_char; // last char read from user | 130 | static char last_input_char; // last char read from user |
130 | static char last_forward_char; // last char searched for with 'f' | 131 | static char last_forward_char; // last char searched for with 'f' |
131 | 132 | ||
133 | #if ENABLE_FEATURE_VI_READONLY | ||
134 | static smallint vi_readonly, readonly; | ||
135 | #endif | ||
136 | #if ENABLE_FEATURE_VI_DOT_CMD | ||
137 | static smallint adding2q; // are we currently adding user input to q | ||
138 | static char *last_modifying_cmd; // last modifying cmd for "." | ||
139 | static char *ioq, *ioq_start; // pointer to string for get_one_char to "read" | ||
140 | #endif | ||
132 | #if ENABLE_FEATURE_VI_OPTIMIZE_CURSOR | 141 | #if ENABLE_FEATURE_VI_OPTIMIZE_CURSOR |
133 | static int last_row; // where the cursor was last moved to | 142 | static int last_row; // where the cursor was last moved to |
134 | #endif | 143 | #endif |
135 | #if ENABLE_FEATURE_VI_USE_SIGNALS | ||
136 | static jmp_buf restart; // catch_sig() | ||
137 | #endif | ||
138 | #if ENABLE_FEATURE_VI_USE_SIGNALS || ENABLE_FEATURE_VI_CRASHME | 144 | #if ENABLE_FEATURE_VI_USE_SIGNALS || ENABLE_FEATURE_VI_CRASHME |
139 | static int my_pid; | 145 | static int my_pid; |
140 | #endif | 146 | #endif |
141 | #if ENABLE_FEATURE_VI_DOT_CMD | ||
142 | static int adding2q; // are we currently adding user input to q | ||
143 | static char *last_modifying_cmd; // last modifying cmd for "." | ||
144 | static char *ioq, *ioq_start; // pointer to string for get_one_char to "read" | ||
145 | #endif | ||
146 | #if ENABLE_FEATURE_VI_DOT_CMD || ENABLE_FEATURE_VI_YANKMARK | 147 | #if ENABLE_FEATURE_VI_DOT_CMD || ENABLE_FEATURE_VI_YANKMARK |
147 | static char *modifying_cmds; // cmds that modify text[] | 148 | static char *modifying_cmds; // cmds that modify text[] |
148 | #endif | ||
149 | #if ENABLE_FEATURE_VI_READONLY | ||
150 | static int vi_readonly, readonly; | ||
151 | #endif | ||
152 | #if ENABLE_FEATURE_VI_YANKMARK | ||
153 | static char *reg[28]; // named register a-z, "D", and "U" 0-25,26,27 | ||
154 | static int YDreg, Ureg; // default delete register and orig line for "U" | ||
155 | static char *mark[28]; // user marks points somewhere in text[]- a-z and previous context '' | ||
156 | static char *context_start, *context_end; | ||
157 | #endif | 149 | #endif |
158 | #if ENABLE_FEATURE_VI_SEARCH | 150 | #if ENABLE_FEATURE_VI_SEARCH |
159 | static char *last_search_pattern; // last pattern from a '/' or '?' search | 151 | static char *last_search_pattern; // last pattern from a '/' or '?' search |
160 | #endif | 152 | #endif |
161 | 153 | ||
154 | /* Moving biggest data to malloced space... */ | ||
155 | struct globals { | ||
156 | /* many references - keep near the top of globals */ | ||
157 | char *text, *end; // pointers to the user data in memory | ||
158 | char *dot; // where all the action takes place | ||
159 | #if ENABLE_FEATURE_VI_YANKMARK | ||
160 | char *reg[28]; // named register a-z, "D", and "U" 0-25,26,27 | ||
161 | int YDreg, Ureg; // default delete register and orig line for "U" | ||
162 | char *mark[28]; // user marks points somewhere in text[]- a-z and previous context '' | ||
163 | char *context_start, *context_end; | ||
164 | #endif | ||
165 | /* a few references only */ | ||
166 | #if ENABLE_FEATURE_VI_USE_SIGNALS | ||
167 | jmp_buf restart; // catch_sig() | ||
168 | #endif | ||
169 | struct termios term_orig, term_vi; // remember what the cooked mode was | ||
170 | #if ENABLE_FEATURE_VI_COLON | ||
171 | char *initial_cmds[3]; // currently 2 entries, NULL terminated | ||
172 | #endif | ||
173 | }; | ||
174 | #define G (*ptr_to_globals) | ||
175 | #define text (G.text ) | ||
176 | #define end (G.end ) | ||
177 | #define dot (G.dot ) | ||
178 | #define reg (G.reg ) | ||
179 | #define YDreg (G.YDreg ) | ||
180 | #define Ureg (G.Ureg ) | ||
181 | #define mark (G.mark ) | ||
182 | #define context_start (G.context_start ) | ||
183 | #define context_end (G.context_end ) | ||
184 | #define restart (G.restart ) | ||
185 | #define term_orig (G.term_orig ) | ||
186 | #define term_vi (G.term_vi ) | ||
187 | #define initial_cmds (G.initial_cmds ) | ||
162 | 188 | ||
163 | static void edit_file(char *); // edit one file | 189 | static void edit_file(char *); // edit one file |
164 | static void do_cmd(char); // execute a command | 190 | static void do_cmd(char); // execute a command |
@@ -258,9 +284,6 @@ static void crash_dummy(); | |||
258 | static void crash_test(); | 284 | static void crash_test(); |
259 | static int crashme = 0; | 285 | static int crashme = 0; |
260 | #endif | 286 | #endif |
261 | #if ENABLE_FEATURE_VI_COLON | ||
262 | static char *initial_cmds[] = { NULL, NULL , NULL }; // currently 2 entries, NULL terminated | ||
263 | #endif | ||
264 | 287 | ||
265 | 288 | ||
266 | static void write1(const char *out) | 289 | static void write1(const char *out) |
@@ -280,6 +303,9 @@ int vi_main(int argc, char **argv) | |||
280 | #if ENABLE_FEATURE_VI_USE_SIGNALS || ENABLE_FEATURE_VI_CRASHME | 303 | #if ENABLE_FEATURE_VI_USE_SIGNALS || ENABLE_FEATURE_VI_CRASHME |
281 | my_pid = getpid(); | 304 | my_pid = getpid(); |
282 | #endif | 305 | #endif |
306 | |||
307 | PTR_TO_GLOBALS = xzalloc(sizeof(G)); | ||
308 | |||
283 | #if ENABLE_FEATURE_VI_CRASHME | 309 | #if ENABLE_FEATURE_VI_CRASHME |
284 | srand((long) my_pid); | 310 | srand((long) my_pid); |
285 | #endif | 311 | #endif |
@@ -350,11 +376,11 @@ int vi_main(int argc, char **argv) | |||
350 | 376 | ||
351 | //----- This is the main file handling loop -------------- | 377 | //----- This is the main file handling loop -------------- |
352 | if (optind >= argc) { | 378 | if (optind >= argc) { |
353 | editing = 1; // 0= exit, 1= one file, 2= multiple files | 379 | editing = 1; // 0= exit, 1= one file, 2 = multiple files |
354 | edit_file(0); | 380 | edit_file(0); |
355 | } else { | 381 | } else { |
356 | for (; optind < argc; optind++) { | 382 | for (; optind < argc; optind++) { |
357 | editing = 1; // 0=exit, 1=one file, 2+ =many files | 383 | editing = 1; // 0=exit, 1=one file, 2+ = many files |
358 | free(cfn); | 384 | free(cfn); |
359 | cfn = xstrdup(argv[optind]); | 385 | cfn = xstrdup(argv[optind]); |
360 | edit_file(cfn); | 386 | edit_file(cfn); |
@@ -913,7 +939,7 @@ static void colon(char * buf) | |||
913 | #endif | 939 | #endif |
914 | ch = file_insert(fn, q, file_size(fn)); | 940 | ch = file_insert(fn, q, file_size(fn)); |
915 | #if ENABLE_FEATURE_VI_READONLY | 941 | #if ENABLE_FEATURE_VI_READONLY |
916 | readonly= l; | 942 | readonly = l; |
917 | #endif | 943 | #endif |
918 | if (ch < 0) | 944 | if (ch < 0) |
919 | goto vc1; // nothing was inserted | 945 | goto vc1; // nothing was inserted |
@@ -1054,7 +1080,7 @@ static void colon(char * buf) | |||
1054 | fn = args; | 1080 | fn = args; |
1055 | } | 1081 | } |
1056 | #if ENABLE_FEATURE_VI_READONLY | 1082 | #if ENABLE_FEATURE_VI_READONLY |
1057 | if ((vi_readonly || readonly) && ! useforce) { | 1083 | if ((vi_readonly || readonly) && !useforce) { |
1058 | psbs("\"%s\" File is read only", fn); | 1084 | psbs("\"%s\" File is read only", fn); |
1059 | goto vc3; | 1085 | goto vc3; |
1060 | } | 1086 | } |