mirror of
https://github.com/sheumann/hush.git
synced 2025-01-03 00:31:16 +00:00
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:
parent
27f79ff03d
commit
0b3b41b62a
110
editors/vi.c
110
editors/vi.c
@ -104,61 +104,87 @@ 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 int fn_start; // index of first cmd line file name
|
static smallint last_file_modified = -1;
|
||||||
static int save_argc; // how many file names on cmd line
|
static int fn_start; // index of first cmd line file name
|
||||||
static int cmdcnt; // repetition count
|
static int save_argc; // how many file names on cmd line
|
||||||
static int rows, columns; // the terminal screen is this size
|
static int cmdcnt; // repetition count
|
||||||
static int crow, ccol, offset; // cursor is on Crow x Ccol with Horz Ofset
|
static int rows, columns; // the terminal screen is this size
|
||||||
static char *status_buffer; // mesages to the user
|
static int crow, ccol, offset; // cursor is on Crow x Ccol with Horz Ofset
|
||||||
|
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
|
|
||||||
#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
|
#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
|
||||||
@ -350,11 +376,11 @@ int vi_main(int argc, char **argv)
|
|||||||
|
|
||||||
//----- This is the main file handling loop --------------
|
//----- This is the main file handling loop --------------
|
||||||
if (optind >= argc) {
|
if (optind >= argc) {
|
||||||
editing = 1; // 0= exit, 1= one file, 2= multiple files
|
editing = 1; // 0= exit, 1= one file, 2 = multiple files
|
||||||
edit_file(0);
|
edit_file(0);
|
||||||
} else {
|
} else {
|
||||||
for (; optind < argc; optind++) {
|
for (; optind < argc; optind++) {
|
||||||
editing = 1; // 0=exit, 1=one file, 2+ =many files
|
editing = 1; // 0=exit, 1=one file, 2+ = many files
|
||||||
free(cfn);
|
free(cfn);
|
||||||
cfn = xstrdup(argv[optind]);
|
cfn = xstrdup(argv[optind]);
|
||||||
edit_file(cfn);
|
edit_file(cfn);
|
||||||
@ -913,7 +939,7 @@ static void colon(char * buf)
|
|||||||
#endif
|
#endif
|
||||||
ch = file_insert(fn, q, file_size(fn));
|
ch = file_insert(fn, q, file_size(fn));
|
||||||
#if ENABLE_FEATURE_VI_READONLY
|
#if ENABLE_FEATURE_VI_READONLY
|
||||||
readonly= l;
|
readonly = l;
|
||||||
#endif
|
#endif
|
||||||
if (ch < 0)
|
if (ch < 0)
|
||||||
goto vc1; // nothing was inserted
|
goto vc1; // nothing was inserted
|
||||||
@ -1054,7 +1080,7 @@ static void colon(char * buf)
|
|||||||
fn = args;
|
fn = args;
|
||||||
}
|
}
|
||||||
#if ENABLE_FEATURE_VI_READONLY
|
#if ENABLE_FEATURE_VI_READONLY
|
||||||
if ((vi_readonly || readonly) && ! useforce) {
|
if ((vi_readonly || readonly) && !useforce) {
|
||||||
psbs("\"%s\" File is read only", fn);
|
psbs("\"%s\" File is read only", fn);
|
||||||
goto vc3;
|
goto vc3;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user