various changes to cut down on binary size: per DB's patch, add new N_()

macro to mark strings that aren't translated immediately and convert
nano to use it where needed, overhaul the shortcut list and toggle list
initialization code for efficiency, and replace rcfile_msg() with
rcfile_error(); also add a few minor miscellaneous cleanups by DB and
myself


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1852 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
David Lawrence Ramsey 2004-07-12 03:10:30 +00:00
parent d717d4bac6
commit 576bf331ef
9 changed files with 592 additions and 595 deletions

View File

@ -16,6 +16,18 @@ CVS code -
descriptive. (DLR)
- Remove unused global variable search_offscreen. (David
Benbennick)
- Add new N_() macro to mark strings that aren't translated
immediately, and convert nano to use it in cases where the
same translated string is stored in a const char* and used
more than once. (David Benbennick) DLR: Do this for the
toggles list for consistency with the shortcut list.
- Overhaul the shortcut list and toggle list initialization
code for efficiency. Changes to shortcut_init() and
toggle_init(). (David Benbennick) DLR: Move "Cancel" to just
after "Get Help" in the file browser list, for consistency
with all the other lists, have the replace list accept all the
same function keys as the search list, and clarify a few
shortcut descriptions.
- files.c:
close_open_file()
- Tweak to no longer rely on the return values of
@ -32,6 +44,8 @@ CVS code -
shortcut_init()
- Fix erroneous #ifdef so that nano compiles with
--disable-justify again. (DLR; found by Mike Frysinger)
thanks_for_all_the_fish()
- Delete topwin, edit, and bottomwin. (David Benbennick)
- nano.c:
do_justify()
- Add on_next_line flag, used to indicate when we've moved to
@ -47,6 +61,12 @@ CVS code -
used in the actual functions. (DLR)
- Remove unused declaration of temp_opt. (David Benbennick)
- rcfile.c:
rcfile_msg()
- Removed along with the related static int errors, and replaced
with calls to rcfile_error(). (David Benbennick)
- Removed the reference to "starting nano" in the statusbar
message, as it may be called when we exit if the history file
can't be saved. (DLR)
parse_rcfile()
- Have whitespace display default to off instead of on. (Mike
Frysinger)

View File

@ -555,7 +555,7 @@ void do_insertfile(int loading_file)
} else {
#endif
realname = real_dir_from_tilde(answer);
i = open_file(realname, 1, loading_file);
i = open_file(realname, TRUE, loading_file);
#ifndef NANO_SMALL
}
#endif
@ -848,7 +848,8 @@ void load_open_file(void)
/* restore full file position: line number, x-coordinate, y-
coordinate, place we want */
do_gotopos(open_files->file_lineno, open_files->file_current_x, open_files->file_current_y, open_files->file_placewewant);
do_gotopos(open_files->file_lineno, open_files->file_current_x,
open_files->file_current_y, open_files->file_placewewant);
/* update the titlebar */
clearok(topwin, FALSE);
@ -1821,33 +1822,33 @@ int do_writeout(int exiting)
const char *formatstr, *backupstr;
if (ISSET(MAC_FILE))
formatstr = _(" [Mac Format]");
formatstr = N_(" [Mac Format]");
else if (ISSET(DOS_FILE))
formatstr = _(" [DOS Format]");
formatstr = N_(" [DOS Format]");
else
formatstr = "";
if (ISSET(BACKUP_FILE))
backupstr = _(" [Backup]");
backupstr = N_(" [Backup]");
else
backupstr = "";
/* Be nice to the translation folks. */
if (ISSET(MARK_ISSET) && !exiting) {
if (append == 2)
msg = _("Prepend Selection to File");
msg = N_("Prepend Selection to File");
else if (append == 1)
msg = _("Append Selection to File");
msg = N_("Append Selection to File");
else
msg = _("Write Selection to File");
msg = N_("Write Selection to File");
} else
#endif /* !NANO_SMALL */
if (append == 2)
msg = _("File Name to Prepend to");
msg = N_("File Name to Prepend to");
else if (append == 1)
msg = _("File Name to Append to");
msg = N_("File Name to Append to");
else
msg = _("File Name to Write");
msg = N_("File Name to Write");
/* If we're using restricted mode, the filename isn't blank,
* and we're at the "Write File" prompt, disable tab
@ -1855,9 +1856,9 @@ int do_writeout(int exiting)
i = statusq(!ISSET(RESTRICTED) || filename[0] == '\0' ? TRUE :
FALSE, writefile_list,
#ifndef NANO_SMALL
ans, NULL, "%s%s%s", msg, formatstr, backupstr
ans, NULL, "%s%s%s", _(msg), formatstr, backupstr
#else
filename, "%s", msg
filename, "%s", _(msg)
#endif
);
@ -2953,7 +2954,8 @@ void load_history(void)
if (errno != ENOENT) {
/* Don't save history when we quit. */
UNSET(HISTORYLOG);
rcfile_error(_("Unable to open ~/.nano_history file: %s"), strerror(errno));
rcfile_error(N_("Unable to open ~/.nano_history file: %s"),
strerror(errno));
}
free(nanohist);
} else {
@ -2986,8 +2988,8 @@ void save_history(void)
historytype *h;
/* don't save unchanged or empty histories */
if (!((search_history.count || replace_history.count) &&
ISSET(HISTORY_CHANGED) && !ISSET(VIEW_MODE)))
if ((search_history.count == 0 && replace_history.count == 0) ||
!ISSET(HISTORY_CHANGED) || ISSET(VIEW_MODE))
return;
if (homenv != NULL) {
@ -3003,7 +3005,8 @@ void save_history(void)
if (homenv != NULL || userage != NULL) {
hist = fopen(nanohist, "wb");
if (hist == NULL) {
rcfile_msg(_("Unable to write ~/.nano_history file: %s"), strerror(errno));
rcfile_error(N_("Unable to write ~/.nano_history file: %s"),
strerror(errno));
} else {
/* set rw only by owner for security ?? */
chmod(nanohist, S_IRUSR | S_IWUSR);
@ -3012,19 +3015,25 @@ void save_history(void)
h->data = charealloc(h->data, strlen(h->data) + 2);
strcat(h->data, "\n");
if (fputs(h->data, hist) == EOF) {
rcfile_msg(_("Unable to write ~/.nano_history file: %s"), strerror(errno));
rcfile_error(
N_("Unable to write ~/.nano_history file: %s"),
strerror(errno));
goto come_from;
}
}
if (fputs("\n", hist) == EOF) {
rcfile_msg(_("Unable to write ~/.nano_history file: %s"), strerror(errno));
rcfile_error(
N_("Unable to write ~/.nano_history file: %s"),
strerror(errno));
goto come_from;
}
for (h = replace_history.tail; h->prev; h = h->prev) {
h->data = charealloc(h->data, strlen(h->data) + 2);
strcat(h->data, "\n");
if (fputs(h->data, hist) == EOF) {
rcfile_msg(_("Unable to write ~/.nano_history file: %s"), strerror(errno));
rcfile_error(
N_("Unable to write ~/.nano_history file: %s"),
strerror(errno));
goto come_from;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1797,7 +1797,7 @@ const char *do_alt_speller(char *tempfile_name)
#endif
free_filestruct(fileage);
global_init(TRUE);
open_file(tempfile_name, 0, 1);
open_file(tempfile_name, FALSE, TRUE);
#ifndef NANO_SMALL
}
@ -3504,7 +3504,7 @@ int main(int argc, char *argv[])
fprintf(stderr, "Main: open file\n");
#endif
open_file(filename, 0, 0);
open_file(filename, FALSE, FALSE);
#ifdef ENABLE_MULTIBUFFER
/* If we're using multibuffers and more than one file is specified
on the command line, load them all and switch to the first one
@ -3516,7 +3516,7 @@ int main(int argc, char *argv[])
add_open_file(TRUE);
new_file();
filename = mallocstrcpy(filename, argv[optind]);
open_file(filename, 0, 0);
open_file(filename, FALSE, FALSE);
load_file(FALSE);
}
open_nextfile_void();

View File

@ -76,6 +76,9 @@
# define _(string) (string)
# define P_(singular, plural, number) (number == 1 ? singular : plural)
#endif
#define gettext_noop(string) (string)
#define N_(string) gettext_noop(string)
/* Mark a string that will be sent to gettext later. */
#include <sys/types.h>
#include <sys/stat.h>

View File

@ -219,12 +219,6 @@ char *do_browse_from(const char *inpath);
/* Public functions in global.c */
size_t length_of_list(const shortcut *s);
void sc_init_one(shortcut **shortcutage, int key, const char *desc,
#ifndef DISABLE_HELP
const char *help,
#endif
int metaval, int funcval, int miscval, int view, void
(*func)(void));
#ifndef NANO_SMALL
void toggle_init_one(int val, const char *desc, long flag);
void toggle_init(void);
@ -232,8 +226,14 @@ void toggle_init(void);
void free_toggles(void);
#endif
#endif
void free_shortcutage(shortcut **shortcutage);
void sc_init_one(shortcut **shortcutage, int key, const char *desc,
#ifndef DISABLE_HELP
const char *help,
#endif
int metaval, int funcval, int miscval, int view, void
(*func)(void));
void shortcut_init(int unjustify);
void free_shortcutage(shortcut **shortcutage);
#ifdef DEBUG
void thanks_for_all_the_fish(void);
#endif
@ -365,7 +365,6 @@ void enable_flow_control(void);
/* Public functions in rcfile.c */
#ifdef ENABLE_NANORC
void rcfile_error(const char *msg, ...);
void rcfile_msg(const char *msg, ...);
char *parse_next_word(char *ptr);
char *parse_argument(char *ptr);
#ifdef ENABLE_COLOR
@ -555,7 +554,7 @@ void total_refresh(void);
void display_main_list(void);
void do_cursorpos(int constant);
void do_cursorpos_void(void);
int line_len(const char *ptr);
size_t line_len(const char *ptr);
void do_help(void);
void do_replace_highlight(int highlight_flag, const char *word);
#ifdef DEBUG

View File

@ -100,7 +100,6 @@ const static rcoption rcopts[] = {
{NULL, 0}
};
static int errors = 0;
static int lineno = 0;
static char *nanorc;
@ -115,26 +114,12 @@ void rcfile_error(const char *msg, ...)
fprintf(stderr, _("Error in %s on line %d: "), nanorc, lineno);
va_start(ap, msg);
vfprintf(stderr, msg, ap);
vfprintf(stderr, _(msg), ap);
va_end(ap);
fprintf(stderr, _("\nPress return to continue starting nano\n"));
fprintf(stderr, _("\nPress Return to continue\n"));
while (getchar() != '\n');
}
/* Just print the error (one of many, perhaps) but don't abort, yet. */
void rcfile_msg(const char *msg, ...)
{
va_list ap;
if (!errors) {
errors = 1;
fprintf(stderr, "\n");
}
va_start(ap, msg);
vfprintf(stderr, msg, ap);
va_end(ap);
fprintf(stderr, "\n");
while (getchar() != '\n')
;
}
/* Parse the next word from the string. Returns NULL if we hit EOL. */
@ -183,7 +168,7 @@ char *parse_argument(char *ptr)
ptr = NULL;
else
*ptr++ = '\0';
rcfile_error(_("Argument %s has unterminated \""), ptr_bak);
rcfile_error(N_("Argument %s has unterminated \""), ptr_bak);
} else {
*last_quote = '\0';
ptr = last_quote + 1;
@ -225,7 +210,7 @@ int colortoint(const char *colorname, int *bright)
else if (!strcasecmp(colorname, "black"))
mcolor = COLOR_BLACK;
else {
rcfile_error(_("Color %s not understood.\n"
rcfile_error(N_("Color %s not understood.\n"
"Valid colors are \"green\", \"red\", \"blue\", \n"
"\"white\", \"yellow\", \"cyan\", \"magenta\" and \n"
"\"black\", with the optional prefix \"bright\" \n"
@ -264,7 +249,7 @@ int nregcomp(regex_t *preg, const char *regex, int eflags)
char *str = charalloc(len);
regerror(rc, preg, str, len);
rcfile_error(_("Bad regex \"%s\": %s"), regex, str);
rcfile_error(N_("Bad regex \"%s\": %s"), regex, str);
free(str);
}
return rc != 0;
@ -284,7 +269,8 @@ void parse_syntax(char *ptr)
return;
if (*ptr != '"') {
rcfile_error(_("Regex strings must begin and end with a \" character\n"));
rcfile_error(
N_("Regex strings must begin and end with a \" character\n"));
return;
}
ptr++;
@ -293,7 +279,7 @@ void parse_syntax(char *ptr)
ptr = parse_next_regex(ptr);
if (ptr == NULL) {
rcfile_error(_("Missing syntax name"));
rcfile_error(N_("Missing syntax name"));
return;
}
@ -362,7 +348,7 @@ void parse_colors(char *ptr)
ptr = parse_next_word(ptr);
if (ptr == NULL) {
rcfile_error(_("Missing color name"));
rcfile_error(N_("Missing color name"));
return;
}
@ -371,7 +357,8 @@ void parse_colors(char *ptr)
strtok(fgstr, ",");
bgcolorname = strtok(NULL, ",");
if (!strncasecmp(bgcolorname, "bright", 6)) {
rcfile_error(_("Background color %s cannot be bright"), bgcolorname);
rcfile_error(N_("Background color %s cannot be bright"),
bgcolorname);
return;
}
bg = colortoint(bgcolorname, &bright);
@ -385,7 +372,7 @@ void parse_colors(char *ptr)
return;
if (syntaxes == NULL) {
rcfile_error(_("Cannot add a color directive without a syntax line"));
rcfile_error(N_("Cannot add a color directive without a syntax line"));
return;
}
@ -414,7 +401,8 @@ void parse_colors(char *ptr)
}
if (*ptr != '"') {
rcfile_error(_("Regex strings must begin and end with a \" character\n"));
rcfile_error(
N_("Regex strings must begin and end with a \" character\n"));
ptr = parse_next_regex(ptr);
continue;
}
@ -452,16 +440,16 @@ void parse_colors(char *ptr)
if (expectend) {
if (ptr == NULL || strncasecmp(ptr, "end=", 4)) {
rcfile_error(_
("\"start=\" requires a corresponding \"end=\""));
rcfile_error(
N_("\"start=\" requires a corresponding \"end=\""));
return;
}
ptr += 4;
if (*ptr != '"') {
rcfile_error(_
("Regex strings must begin and end with a \" character\n"));
rcfile_error(
N_("Regex strings must begin and end with a \" character\n"));
continue;
}
ptr++;
@ -525,7 +513,7 @@ void parse_rcfile(FILE *rcstream)
parse_colors(ptr);
#endif /* ENABLE_COLOR */
else {
rcfile_msg(_("Command %s not understood"), keyword);
rcfile_error(N_("Command %s not understood"), keyword);
continue;
}
@ -564,9 +552,9 @@ void parse_rcfile(FILE *rcstream)
#endif
) {
if (*ptr == '\n' || *ptr == '\0') {
rcfile_error(_
("Option %s requires an argument"),
rcopts[i].name);
rcfile_error(
N_("Option %s requires an argument"),
rcopts[i].name);
continue;
}
option = ptr;
@ -590,8 +578,9 @@ void parse_rcfile(FILE *rcstream)
* errors. */
j = (int)strtol(option, &first_error, 10);
if (errno == ERANGE || *option == '\0' || *first_error != '\0')
rcfile_error(_("Requested fill size %d invalid"),
j);
rcfile_error(
N_("Requested fill size %d invalid"),
j);
else
wrap_at = j;
} else
@ -602,7 +591,8 @@ void parse_rcfile(FILE *rcstream)
whitespace = mallocstrcpy(NULL, option);
ws_len = strlen(whitespace);
if (ws_len != 2 || (ws_len == 2 && (is_cntrl_char(whitespace[0]) || is_cntrl_char(whitespace[1])))) {
rcfile_error(_("Two non-control characters required"));
rcfile_error(
N_("Two non-control characters required"));
free(whitespace);
whitespace = NULL;
}
@ -612,14 +602,16 @@ void parse_rcfile(FILE *rcstream)
if (!strcasecmp(rcopts[i].name, "punct")) {
punct = mallocstrcpy(NULL, option);
if (strchr(punct, '\t') != NULL || strchr(punct, ' ') != NULL) {
rcfile_error(_("Non-tab and non-space characters required"));
rcfile_error(
N_("Non-tab and non-space characters required"));
free(punct);
punct = NULL;
}
} else if (!strcasecmp(rcopts[i].name, "brackets")) {
brackets = mallocstrcpy(NULL, option);
if (strchr(brackets, '\t') != NULL || strchr(brackets, ' ') != NULL) {
rcfile_error(_("Non-tab and non-space characters required"));
rcfile_error(
N_("Non-tab and non-space characters required"));
free(brackets);
brackets = NULL;
}
@ -645,8 +637,8 @@ void parse_rcfile(FILE *rcstream)
* errors. */
j = (int)strtol(option, &first_error, 10);
if (errno == ERANGE || *option == '\0' || *first_error != '\0')
rcfile_error(_("Requested tab size %d invalid"),
j);
rcfile_error(N_("Requested tab size %d invalid"),
j);
else
tabsize = j;
}
@ -668,9 +660,6 @@ void parse_rcfile(FILE *rcstream)
}
}
free(buf);
if (errors)
rcfile_error(_("Errors found in .nanorc file"));
return;
}
@ -705,7 +694,7 @@ void do_rcfile(void)
endpwent();
if (userage == NULL) {
rcfile_error(_("I can't find my home directory! Wah!"));
rcfile_error(N_("I can't find my home directory! Wah!"));
SET(NO_RCFILE);
} else {
nanorc = charealloc(nanorc, strlen(userage->pw_dir) + 9);
@ -725,7 +714,7 @@ void do_rcfile(void)
if ((rcstream = fopen(nanorc, "r")) == NULL) {
/* Don't complain about the file not existing */
if (errno != ENOENT) {
rcfile_error(_("Unable to open ~/.nanorc file, %s"),
rcfile_error(N_("Unable to open ~/.nanorc file, %s"),
strerror(errno));
SET(NO_RCFILE);
}

View File

@ -361,7 +361,8 @@ int findnextstr(int can_display_wrap, int wholeword, const filestruct
/* Search for a string. */
void do_search(void)
{
int old_pww = placewewant, i, fileptr_x = current_x, didfind;
size_t old_pww = placewewant, i, fileptr_x = current_x;
int didfind;
filestruct *fileptr = current;
#ifndef DISABLE_WRAPPING
@ -428,7 +429,8 @@ void do_search(void)
/* Search for the next string without prompting. */
void do_research(void)
{
int old_pww = placewewant, fileptr_x = current_x, didfind;
size_t old_pww = placewewant, fileptr_x = current_x;
int didfind;
filestruct *fileptr = current;
#ifndef DISABLE_WRAPPING
@ -583,7 +585,7 @@ char *replace_line(const char *needle)
int do_replace_loop(const char *needle, const filestruct *real_current,
size_t *real_current_x, int wholewords)
{
int old_pww = placewewant, replaceall = 0, numreplaced = -1;
int old_pww = placewewant, replaceall = FALSE, numreplaced = -1;
size_t current_x_save = current_x;
const filestruct *current_save = current;
#ifdef HAVE_REGEX_H
@ -677,7 +679,7 @@ int do_replace_loop(const char *needle, const filestruct *real_current,
int length_change;
if (i == 2)
replaceall = 1;
replaceall = TRUE;
copy = replace_line(needle);

View File

@ -2945,9 +2945,9 @@ void display_main_list(void)
bottombars(main_list);
}
/* If constant is FALSE, the user typed ^C so we unconditionally display
* the cursor position. Otherwise, we display it only if the character
* position changed, and DISABLE_CURPOS is not set.
/* If constant is FALSE, the user typed Ctrl-C, so we unconditionally
* display the cursor position. Otherwise, we display it only if the
* character position changed and DISABLE_CURPOS is not set.
*
* If constant is TRUE and DISABLE_CURPOS is set, we unset it and update
* old_i and old_totsize. That way, we leave the current statusbar
@ -3007,9 +3007,9 @@ void do_cursorpos_void(void)
}
/* Calculate the next line of help_text, starting at ptr. */
int line_len(const char *ptr)
size_t line_len(const char *ptr)
{
int j = 0;
size_t j = 0;
while (*ptr != '\n' && *ptr != '\0' && j < COLS - 5) {
ptr++;
@ -3288,14 +3288,14 @@ void do_credits(void)
};
const char *xlcredits[XLCREDIT_LEN] = {
"The nano text editor",
"version",
"Brought to you by:",
"Special thanks to:",
"The Free Software Foundation",
"For ncurses:",
"and anyone else we forgot...",
"Thank you for using nano!"
N_("The nano text editor"),
N_("version"),
N_("Brought to you by:"),
N_("Special thanks to:"),
N_("The Free Software Foundation"),
N_("For ncurses:"),
N_("and anyone else we forgot..."),
N_("Thank you for using nano!")
};
curs_set(0);