vi: move some data to malloc'ed space: ~500 less bss, code
size is smaller too (subject to arch differenced I guess)
This commit is contained in:
80
editors/vi.c
80
editors/vi.c
@ -104,10 +104,11 @@ static int vi_setops;
|
|||||||
#define err_method (vi_setops & VI_ERR_METHOD)
|
#define err_method (vi_setops & VI_ERR_METHOD)
|
||||||
|
|
||||||
|
|
||||||
static int editing; // >0 while we are editing a file
|
static smallint editing; // >0 while we are editing a file
|
||||||
static int cmd_mode; // 0=command 1=insert 2=replace
|
// [code audit says "can be 0 or 1 only"]
|
||||||
static int file_modified; // buffer contents changed
|
static smallint cmd_mode; // 0=command 1=insert 2=replace
|
||||||
static int last_file_modified = -1;
|
static smallint file_modified; // buffer contents changed
|
||||||
|
static smallint last_file_modified = -1;
|
||||||
static int fn_start; // index of first cmd line file name
|
static int fn_start; // index of first cmd line file name
|
||||||
static int save_argc; // how many file names on cmd line
|
static int save_argc; // how many file names on cmd line
|
||||||
static int cmdcnt; // repetition count
|
static int cmdcnt; // repetition count
|
||||||
@ -116,49 +117,74 @@ static int crow, ccol, offset; // cursor is on Crow x Ccol with Horz Ofset
|
|||||||
static char *status_buffer; // mesages to the user
|
static char *status_buffer; // mesages to the user
|
||||||
#define STATUS_BUFFER_LEN 200
|
#define STATUS_BUFFER_LEN 200
|
||||||
static int have_status_msg; // is default edit status needed?
|
static int have_status_msg; // is default edit status needed?
|
||||||
|
// [don't make smallint!]
|
||||||
static int last_status_cksum; // hash of current status line
|
static int last_status_cksum; // hash of current status line
|
||||||
static char *cfn; // previous, current, and next file name
|
static char *cfn; // previous, current, and next file name
|
||||||
static char *text, *end; // pointers to the user data in memory
|
//static char *text, *end; // pointers to the user data in memory
|
||||||
static char *screen; // pointer to the virtual screen buffer
|
static char *screen; // pointer to the virtual screen buffer
|
||||||
static int screensize; // and its size
|
static int screensize; // and its size
|
||||||
static char *screenbegin; // index into text[], of top line on the screen
|
static char *screenbegin; // index into text[], of top line on the screen
|
||||||
static char *dot; // where all the action takes place
|
//static char *dot; // where all the action takes place
|
||||||
static int tabstop;
|
static int tabstop;
|
||||||
static struct termios term_orig, term_vi; // remember what the cooked mode was
|
|
||||||
static char erase_char; // the users erase character
|
static char erase_char; // the users erase character
|
||||||
static char last_input_char; // last char read from user
|
static char last_input_char; // last char read from user
|
||||||
static char last_forward_char; // last char searched for with 'f'
|
static char last_forward_char; // last char searched for with 'f'
|
||||||
|
|
||||||
|
#if ENABLE_FEATURE_VI_READONLY
|
||||||
|
static smallint vi_readonly, readonly;
|
||||||
|
#endif
|
||||||
|
#if ENABLE_FEATURE_VI_DOT_CMD
|
||||||
|
static smallint adding2q; // are we currently adding user input to q
|
||||||
|
static char *last_modifying_cmd; // last modifying cmd for "."
|
||||||
|
static char *ioq, *ioq_start; // pointer to string for get_one_char to "read"
|
||||||
|
#endif
|
||||||
#if ENABLE_FEATURE_VI_OPTIMIZE_CURSOR
|
#if ENABLE_FEATURE_VI_OPTIMIZE_CURSOR
|
||||||
static int last_row; // where the cursor was last moved to
|
static int last_row; // where the cursor was last moved to
|
||||||
#endif
|
#endif
|
||||||
#if ENABLE_FEATURE_VI_USE_SIGNALS
|
|
||||||
static jmp_buf restart; // catch_sig()
|
|
||||||
#endif
|
|
||||||
#if ENABLE_FEATURE_VI_USE_SIGNALS || ENABLE_FEATURE_VI_CRASHME
|
#if ENABLE_FEATURE_VI_USE_SIGNALS || ENABLE_FEATURE_VI_CRASHME
|
||||||
static int my_pid;
|
static int my_pid;
|
||||||
#endif
|
#endif
|
||||||
#if ENABLE_FEATURE_VI_DOT_CMD
|
|
||||||
static int adding2q; // are we currently adding user input to q
|
|
||||||
static char *last_modifying_cmd; // last modifying cmd for "."
|
|
||||||
static char *ioq, *ioq_start; // pointer to string for get_one_char to "read"
|
|
||||||
#endif
|
|
||||||
#if ENABLE_FEATURE_VI_DOT_CMD || ENABLE_FEATURE_VI_YANKMARK
|
#if ENABLE_FEATURE_VI_DOT_CMD || ENABLE_FEATURE_VI_YANKMARK
|
||||||
static char *modifying_cmds; // cmds that modify text[]
|
static char *modifying_cmds; // cmds that modify text[]
|
||||||
#endif
|
#endif
|
||||||
#if ENABLE_FEATURE_VI_READONLY
|
|
||||||
static int vi_readonly, readonly;
|
|
||||||
#endif
|
|
||||||
#if ENABLE_FEATURE_VI_YANKMARK
|
|
||||||
static char *reg[28]; // named register a-z, "D", and "U" 0-25,26,27
|
|
||||||
static int YDreg, Ureg; // default delete register and orig line for "U"
|
|
||||||
static char *mark[28]; // user marks points somewhere in text[]- a-z and previous context ''
|
|
||||||
static char *context_start, *context_end;
|
|
||||||
#endif
|
|
||||||
#if ENABLE_FEATURE_VI_SEARCH
|
#if ENABLE_FEATURE_VI_SEARCH
|
||||||
static char *last_search_pattern; // last pattern from a '/' or '?' search
|
static char *last_search_pattern; // last pattern from a '/' or '?' search
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Moving biggest data to malloced space... */
|
||||||
|
struct globals {
|
||||||
|
/* many references - keep near the top of globals */
|
||||||
|
char *text, *end; // pointers to the user data in memory
|
||||||
|
char *dot; // where all the action takes place
|
||||||
|
#if ENABLE_FEATURE_VI_YANKMARK
|
||||||
|
char *reg[28]; // named register a-z, "D", and "U" 0-25,26,27
|
||||||
|
int YDreg, Ureg; // default delete register and orig line for "U"
|
||||||
|
char *mark[28]; // user marks points somewhere in text[]- a-z and previous context ''
|
||||||
|
char *context_start, *context_end;
|
||||||
|
#endif
|
||||||
|
/* a few references only */
|
||||||
|
#if ENABLE_FEATURE_VI_USE_SIGNALS
|
||||||
|
jmp_buf restart; // catch_sig()
|
||||||
|
#endif
|
||||||
|
struct termios term_orig, term_vi; // remember what the cooked mode was
|
||||||
|
#if ENABLE_FEATURE_VI_COLON
|
||||||
|
char *initial_cmds[3]; // currently 2 entries, NULL terminated
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
#define G (*ptr_to_globals)
|
||||||
|
#define text (G.text )
|
||||||
|
#define end (G.end )
|
||||||
|
#define dot (G.dot )
|
||||||
|
#define reg (G.reg )
|
||||||
|
#define YDreg (G.YDreg )
|
||||||
|
#define Ureg (G.Ureg )
|
||||||
|
#define mark (G.mark )
|
||||||
|
#define context_start (G.context_start )
|
||||||
|
#define context_end (G.context_end )
|
||||||
|
#define restart (G.restart )
|
||||||
|
#define term_orig (G.term_orig )
|
||||||
|
#define term_vi (G.term_vi )
|
||||||
|
#define initial_cmds (G.initial_cmds )
|
||||||
|
|
||||||
static void edit_file(char *); // edit one file
|
static void edit_file(char *); // edit one file
|
||||||
static void do_cmd(char); // execute a command
|
static void do_cmd(char); // execute a command
|
||||||
@ -258,9 +284,6 @@ static void crash_dummy();
|
|||||||
static void crash_test();
|
static void crash_test();
|
||||||
static int crashme = 0;
|
static int crashme = 0;
|
||||||
#endif
|
#endif
|
||||||
#if ENABLE_FEATURE_VI_COLON
|
|
||||||
static char *initial_cmds[] = { NULL, NULL , NULL }; // currently 2 entries, NULL terminated
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
static void write1(const char *out)
|
static void write1(const char *out)
|
||||||
@ -280,6 +303,9 @@ int vi_main(int argc, char **argv)
|
|||||||
#if ENABLE_FEATURE_VI_USE_SIGNALS || ENABLE_FEATURE_VI_CRASHME
|
#if ENABLE_FEATURE_VI_USE_SIGNALS || ENABLE_FEATURE_VI_CRASHME
|
||||||
my_pid = getpid();
|
my_pid = getpid();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
PTR_TO_GLOBALS = xzalloc(sizeof(G));
|
||||||
|
|
||||||
#if ENABLE_FEATURE_VI_CRASHME
|
#if ENABLE_FEATURE_VI_CRASHME
|
||||||
srand((long) my_pid);
|
srand((long) my_pid);
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user