Commit dab017e7 authored by Chris Allegretta's avatar Chris Allegretta
Browse files

- More cleanups with DISABLE flags, better free_shortcutage and free_toggle,...

- More cleanups with DISABLE flags, better free_shortcutage and free_toggle, and get rid of unnecessary variable decls with NANO_SMALL in shortcut_init() by David Benbennick


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1194 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
parent b275175b
Showing with 269 additions and 200 deletions
+269 -200
...@@ -15,6 +15,9 @@ CVS code - ...@@ -15,6 +15,9 @@ CVS code -
- Change from read() and write() to file streams by Jay Carlson. - Change from read() and write() to file streams by Jay Carlson.
Allows OS to implement read and write ahead rather than making Allows OS to implement read and write ahead rather than making
us do it. Hopefully merged properly. us do it. Hopefully merged properly.
- More cleanups with DISABLE flags, better free_shortcutage and
free_toggle, and get rid of unnecessary variable decls with
NANO_SMALL in shortcut_init() by David Benbennick.
- configure.ac: - configure.ac:
- Define NDEBUG to silence asserts (David Benbennick). - Define NDEBUG to silence asserts (David Benbennick).
- files.c: - files.c:
......
This diff is collapsed.
...@@ -696,7 +696,8 @@ int no_help(void) ...@@ -696,7 +696,8 @@ int no_help(void)
return 0; return 0;
} }
#if defined(DISABLE_JUSTIFY) || defined(DISABLE_SPELLER) || defined(DISABLE_HELP) #if defined(DISABLE_JUSTIFY) || defined(DISABLE_SPELLER) || \
defined(DISABLE_HELP) || defined(NANO_SMALL)
void nano_disabled_msg(void) void nano_disabled_msg(void)
{ {
statusbar("Sorry, support for this function has been disabled"); statusbar("Sorry, support for this function has been disabled");
...@@ -746,33 +747,36 @@ int do_enter(filestruct * inptr) ...@@ -746,33 +747,36 @@ int do_enter(filestruct * inptr)
{ {
filestruct *newnode; filestruct *newnode;
char *tmp; char *tmp;
#ifndef NANO_SMALL
char *spc;
int extra = 0;
#endif
newnode = make_new_node(inptr); newnode = make_new_node(inptr);
assert(current->data != NULL);
tmp = &current->data[current_x]; tmp = &current->data[current_x];
current_x = 0;
#ifndef NANO_SMALL #ifndef NANO_SMALL
/* Do auto-indenting, like the neolithic Turbo Pascal editor */ /* Do auto-indenting, like the neolithic Turbo Pascal editor */
if (ISSET(AUTOINDENT)) { if (ISSET(AUTOINDENT)) {
spc = current->data; int extra = 0;
if (spc) { char *spc = current->data;
while ((*spc == ' ') || (*spc == '\t')) { while ((*spc == ' ') || (*spc == '\t')) {
extra++; extra++;
spc++; spc++;
current_x++;
totsize++;
} }
/* If the cursor is in the indentation, only indent to the cursor.
* Ex, if cursor is at col 0, don't indent at all.
*/
if (current_x < extra)
extra = current_x;
else
current_x = extra;
totsize += extra;
newnode->data = charalloc(strlen(tmp) + extra + 1); newnode->data = charalloc(strlen(tmp) + extra + 1);
strncpy(newnode->data, current->data, extra); strncpy(newnode->data, current->data, extra);
strcpy(&newnode->data[extra], tmp); strcpy(&newnode->data[extra], tmp);
}
} else } else
#endif #endif
{ {
current_x = 0;
newnode->data = charalloc(strlen(tmp) + 1); newnode->data = charalloc(strlen(tmp) + 1);
strcpy(newnode->data, tmp); strcpy(newnode->data, tmp);
} }
...@@ -2477,7 +2481,9 @@ void help_init(void) ...@@ -2477,7 +2481,9 @@ void help_init(void)
int i, sofar = 0, meta_shortcut = 0, helplen; int i, sofar = 0, meta_shortcut = 0, helplen;
long allocsize = 1; /* How much space we're gonna need for the help text */ long allocsize = 1; /* How much space we're gonna need for the help text */
char buf[BUFSIZ] = "", *ptr = NULL; char buf[BUFSIZ] = "", *ptr = NULL;
#ifndef NANO_SMALL
toggle *t; toggle *t;
#endif
shortcut *s; shortcut *s;
helplen = length_of_list(currshortcut); helplen = length_of_list(currshortcut);
...@@ -2579,12 +2585,14 @@ void help_init(void) ...@@ -2579,12 +2585,14 @@ void help_init(void)
s = s->next; s = s->next;
} }
#ifndef NANO_SMALL
/* If we're on the main list, we also allocate space for toggle help text. */ /* If we're on the main list, we also allocate space for toggle help text. */
if (currshortcut == main_list) { if (currshortcut == main_list) {
for (t = toggles; t != NULL; t = t->next) for (t = toggles; t != NULL; t = t->next)
if (t->desc != NULL) if (t->desc != NULL)
allocsize += strlen(t->desc) + 30; allocsize += strlen(t->desc) + 30;
} }
#endif /* !NANO_SMALL */
allocsize += strlen(ptr); allocsize += strlen(ptr);
...@@ -2658,6 +2666,7 @@ void help_init(void) ...@@ -2658,6 +2666,7 @@ void help_init(void)
s = s->next; s = s->next;
} }
#ifndef NANO_SMALL
/* And the toggles... */ /* And the toggles... */
if (currshortcut == main_list) if (currshortcut == main_list)
for (t = toggles; t != NULL; t = t->next) { for (t = toggles; t != NULL; t = t->next) {
...@@ -2670,15 +2679,13 @@ void help_init(void) ...@@ -2670,15 +2679,13 @@ void help_init(void)
strcat(help_text, buf); strcat(help_text, buf);
strcat(help_text, "\n"); strcat(help_text, "\n");
} }
#endif /* !NANO_SMALL */
} }
#endif #endif
#ifndef NANO_SMALL
void do_toggle(toggle *which) void do_toggle(toggle *which)
{ {
#ifdef NANO_SMALL
nano_disabled_msg();
#else
char *enabled = _("enabled"); char *enabled = _("enabled");
char *disabled = _("disabled"); char *disabled = _("disabled");
...@@ -2733,9 +2740,8 @@ void do_toggle(toggle *which) ...@@ -2733,9 +2740,8 @@ void do_toggle(toggle *which)
else else
statusbar("%s %s", which->desc, enabled); statusbar("%s %s", which->desc, enabled);
} }
#endif
} }
#endif /* !NANO_SMALL */
/* If the NumLock key has made the keypad go awry, print an error /* If the NumLock key has made the keypad go awry, print an error
message; hopefully we can address it later. */ message; hopefully we can address it later. */
......
...@@ -99,14 +99,16 @@ typedef struct shortcut { ...@@ -99,14 +99,16 @@ typedef struct shortcut {
int misc2; int misc2;
int viewok; /* is this function legal in view mode? */ int viewok; /* is this function legal in view mode? */
int (*func) (void); /* Function to call when we catch this key */ int (*func) (void); /* Function to call when we catch this key */
char *desc; /* Description, e.g. "Page Up" */ const char *desc; /* Description, e.g. "Page Up" */
char *help; /* Help file entry text */ #ifndef DISABLE_HELP
const char *help; /* Help file entry text */
#endif
struct shortcut *next; struct shortcut *next;
} shortcut; } shortcut;
typedef struct toggle { typedef struct toggle {
int val; /* Sequence to toggle the key. Should only need 1 */ int val; /* Sequence to toggle the key. Should only need 1 */
char *desc; /* Description for when toggle is, uh, toggled, const char *desc; /* Description for when toggle is, uh, toggled,
e.g. "Pico Messages"; we'll append Enabled or e.g. "Pico Messages"; we'll append Enabled or
Disabled */ Disabled */
int flag; /* What flag actually gets toggled */ int flag; /* What flag actually gets toggled */
......
...@@ -97,6 +97,13 @@ extern toggle *toggles; ...@@ -97,6 +97,13 @@ extern toggle *toggles;
/* Programs we want available */ /* Programs we want available */
/* public functions in global.c */
int length_of_list(const shortcut *s);
void shortcut_init(int unjustify);
void thanks_for_all_the_fish(void);
char *revstrstr(char *haystack, char *needle, char *rev_start); char *revstrstr(char *haystack, char *needle, char *rev_start);
char *stristr(char *haystack, char *needle); char *stristr(char *haystack, char *needle);
char *revstristr(char *haystack, char *needle, char *rev_start); char *revstristr(char *haystack, char *needle, char *rev_start);
...@@ -122,7 +129,6 @@ int no_help(void); ...@@ -122,7 +129,6 @@ int no_help(void);
int renumber_all(void); int renumber_all(void);
int open_file(char *filename, int insert, int quiet); int open_file(char *filename, int insert, int quiet);
int do_insertfile(int loading_file); int do_insertfile(int loading_file);
int length_of_list(shortcut *s);
int num_of_digits(int n); int num_of_digits(int n);
int open_pipe(char *command); int open_pipe(char *command);
int read_file(FILE *f, char *filename, int quiet); int read_file(FILE *f, char *filename, int quiet);
...@@ -156,7 +162,6 @@ int check_wildcard_match(const char *text, const char *pattern); ...@@ -156,7 +162,6 @@ int check_wildcard_match(const char *text, const char *pattern);
char *input_tab(char *buf, int place, int *lastWasTab, int *newplace, int *list); char *input_tab(char *buf, int place, int *lastWasTab, int *newplace, int *list);
char *real_dir_from_tilde(char *buf); char *real_dir_from_tilde(char *buf);
void shortcut_init(int unjustify);
void signal_init(void); void signal_init(void);
void lowercase(char *src); void lowercase(char *src);
void blank_bottombars(void); void blank_bottombars(void);
...@@ -223,8 +228,6 @@ void unlink_opennode(openfilestruct * fileptr); ...@@ -223,8 +228,6 @@ void unlink_opennode(openfilestruct * fileptr);
void cut_marked_segment(filestruct * top, int top_x, filestruct * bot, void cut_marked_segment(filestruct * top, int top_x, filestruct * bot,
int bot_x, int destructive); int bot_x, int destructive);
void free_shortcutage(shortcut **src);
void thanks_for_all_the_fish(void);
#ifdef ENABLE_NANORC #ifdef ENABLE_NANORC
void do_rcfile(void); void do_rcfile(void);
......
...@@ -579,7 +579,7 @@ void titlebar(char *path) ...@@ -579,7 +579,7 @@ void titlebar(char *path)
reset_cursor(); reset_cursor();
} }
void onekey(char *keystroke, char *desc, int len) void onekey(char *keystroke, const char *desc, int len)
{ {
int i; int i;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment