aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-05-30 02:01:40 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-05-30 02:01:40 +0000
commit0b3b41b62acd6c2911ea4f08e0dd96f93334aff5 (patch)
treee8e0559748045acacaf5702eb72c6c05ca56268a
parent27f79ff03d2b4614d013948d95a5bc697ec41962 (diff)
downloadbusybox-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.c110
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
107static int editing; // >0 while we are editing a file 107static smallint editing; // >0 while we are editing a file
108static int cmd_mode; // 0=command 1=insert 2=replace 108 // [code audit says "can be 0 or 1 only"]
109static int file_modified; // buffer contents changed 109static smallint cmd_mode; // 0=command 1=insert 2=replace
110static int last_file_modified = -1; 110static smallint file_modified; // buffer contents changed
111static int fn_start; // index of first cmd line file name 111static smallint last_file_modified = -1;
112static int save_argc; // how many file names on cmd line 112static int fn_start; // index of first cmd line file name
113static int cmdcnt; // repetition count 113static int save_argc; // how many file names on cmd line
114static int rows, columns; // the terminal screen is this size 114static int cmdcnt; // repetition count
115static int crow, ccol, offset; // cursor is on Crow x Ccol with Horz Ofset 115static int rows, columns; // the terminal screen is this size
116static char *status_buffer; // mesages to the user 116static int crow, ccol, offset; // cursor is on Crow x Ccol with Horz Ofset
117static char *status_buffer; // mesages to the user
117#define STATUS_BUFFER_LEN 200 118#define STATUS_BUFFER_LEN 200
118static int have_status_msg; // is default edit status needed? 119static int have_status_msg; // is default edit status needed?
120 // [don't make smallint!]
119static int last_status_cksum; // hash of current status line 121static int last_status_cksum; // hash of current status line
120static char *cfn; // previous, current, and next file name 122static char *cfn; // previous, current, and next file name
121static char *text, *end; // pointers to the user data in memory 123//static char *text, *end; // pointers to the user data in memory
122static char *screen; // pointer to the virtual screen buffer 124static char *screen; // pointer to the virtual screen buffer
123static int screensize; // and its size 125static int screensize; // and its size
124static char *screenbegin; // index into text[], of top line on the screen 126static char *screenbegin; // index into text[], of top line on the screen
125static char *dot; // where all the action takes place 127//static char *dot; // where all the action takes place
126static int tabstop; 128static int tabstop;
127static struct termios term_orig, term_vi; // remember what the cooked mode was
128static char erase_char; // the users erase character 129static char erase_char; // the users erase character
129static char last_input_char; // last char read from user 130static char last_input_char; // last char read from user
130static char last_forward_char; // last char searched for with 'f' 131static char last_forward_char; // last char searched for with 'f'
131 132
133#if ENABLE_FEATURE_VI_READONLY
134static smallint vi_readonly, readonly;
135#endif
136#if ENABLE_FEATURE_VI_DOT_CMD
137static smallint adding2q; // are we currently adding user input to q
138static char *last_modifying_cmd; // last modifying cmd for "."
139static 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
133static int last_row; // where the cursor was last moved to 142static int last_row; // where the cursor was last moved to
134#endif 143#endif
135#if ENABLE_FEATURE_VI_USE_SIGNALS
136static 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
139static int my_pid; 145static int my_pid;
140#endif 146#endif
141#if ENABLE_FEATURE_VI_DOT_CMD
142static int adding2q; // are we currently adding user input to q
143static char *last_modifying_cmd; // last modifying cmd for "."
144static 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
147static char *modifying_cmds; // cmds that modify text[] 148static char *modifying_cmds; // cmds that modify text[]
148#endif
149#if ENABLE_FEATURE_VI_READONLY
150static int vi_readonly, readonly;
151#endif
152#if ENABLE_FEATURE_VI_YANKMARK
153static char *reg[28]; // named register a-z, "D", and "U" 0-25,26,27
154static int YDreg, Ureg; // default delete register and orig line for "U"
155static char *mark[28]; // user marks points somewhere in text[]- a-z and previous context ''
156static char *context_start, *context_end;
157#endif 149#endif
158#if ENABLE_FEATURE_VI_SEARCH 150#if ENABLE_FEATURE_VI_SEARCH
159static char *last_search_pattern; // last pattern from a '/' or '?' search 151static char *last_search_pattern; // last pattern from a '/' or '?' search
160#endif 152#endif
161 153
154/* Moving biggest data to malloced space... */
155struct 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
163static void edit_file(char *); // edit one file 189static void edit_file(char *); // edit one file
164static void do_cmd(char); // execute a command 190static void do_cmd(char); // execute a command
@@ -258,9 +284,6 @@ static void crash_dummy();
258static void crash_test(); 284static void crash_test();
259static int crashme = 0; 285static int crashme = 0;
260#endif 286#endif
261#if ENABLE_FEATURE_VI_COLON
262static char *initial_cmds[] = { NULL, NULL , NULL }; // currently 2 entries, NULL terminated
263#endif
264 287
265 288
266static void write1(const char *out) 289static 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 }