From: Ben Pfaff Date: Tue, 6 Nov 2007 06:23:25 +0000 (+0000) Subject: Patch #6258. X-Git-Tag: v0.6.0~199 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=51d8c9b54d65bd0aa3944b8fb9d4460875048e14;p=pspp-builds.git Patch #6258. * command.c (report_state_mismatch): Replace code to construct an error message from bits and pieces by a switch statement that hard-codes each possible error. Makes i18n easier. Suggested by Chusslove Illich . * file-handle-def.c (fh_lock): Add comment that TYPE should be marked with N_() in the caller. Added these markings to each caller too. Should make i18n easier. Suggested by Chusslove Illich . --- diff --git a/src/data/ChangeLog b/src/data/ChangeLog index 0353c638..16ba1ca1 100644 --- a/src/data/ChangeLog +++ b/src/data/ChangeLog @@ -1,3 +1,12 @@ +2007-11-05 Ben Pfaff + + Patch #6258. Reviewed by John Darrington. + + * file-handle-def.c (fh_lock): Add comment that TYPE should be + marked with N_() in the caller. Added these markings to each + caller too. Should make i18n easier. + Suggested by Chusslove Illich . + 2007-11-03 Ben Pfaff Allow output files to overwrite input files (bug #21280). diff --git a/src/data/file-handle-def.c b/src/data/file-handle-def.c index 87255915..0f6b142a 100644 --- a/src/data/file-handle-def.c +++ b/src/data/file-handle-def.c @@ -403,6 +403,10 @@ static unsigned int hash_fh_lock (const void *, const void *); and similarly for writing. If successful, a reference to TYPE is retained, so it should probably be a string literal. + TYPE should be marked with N_() in the caller: that is, the + caller should not translate it with gettext, but fh_lock will + do so. + ACCESS specifies whether the lock is for reading or writing. EXCLUSIVE is true to require exclusive access, false to allow sharing with other accessors. Exclusive read access precludes diff --git a/src/data/por-file-reader.c b/src/data/por-file-reader.c index 668a8429..ce1f562f 100644 --- a/src/data/por-file-reader.c +++ b/src/data/por-file-reader.c @@ -46,6 +46,7 @@ #include "gettext.h" #define _(msgid) gettext (msgid) +#define N_(msgid) (msgid) /* portable_to_local[PORTABLE] translates the given portable character into the local character set. */ @@ -261,7 +262,9 @@ pfm_open_reader (struct file_handle *fh, struct dictionary **dict, goto error; /* Lock file. */ - r->lock = fh_lock (fh, FH_REF_FILE, "portable file", FH_ACC_READ, false); + /* TRANSLATORS: this fragment will be interpolated into + messages in fh_lock() that identify types of files. */ + r->lock = fh_lock (fh, FH_REF_FILE, N_("portable file"), FH_ACC_READ, false); if (r->lock == NULL) goto error; diff --git a/src/data/por-file-writer.c b/src/data/por-file-writer.c index 3d62078e..fad89bf7 100644 --- a/src/data/por-file-writer.c +++ b/src/data/por-file-writer.c @@ -49,6 +49,7 @@ #include "gettext.h" #define _(msgid) gettext (msgid) +#define N_(msgid) (msgid) /* Maximum width of a variable in a portable file. */ #define MAX_POR_WIDTH 255 @@ -142,7 +143,9 @@ pfm_open_writer (struct file_handle *fh, struct dictionary *dict, } /* Lock file. */ - w->lock = fh_lock (fh, FH_REF_FILE, "portable file", FH_ACC_WRITE, true); + /* TRANSLATORS: this fragment will be interpolated into + messages in fh_lock() that identify types of files. */ + w->lock = fh_lock (fh, FH_REF_FILE, N_("portable file"), FH_ACC_WRITE, true); if (w->lock == NULL) goto error; diff --git a/src/data/scratch-writer.c b/src/data/scratch-writer.c index 70a65ce9..e4d977fb 100644 --- a/src/data/scratch-writer.c +++ b/src/data/scratch-writer.c @@ -34,6 +34,8 @@ #include "xalloc.h" +#define N_(msgid) (msgid) + /* A scratch file writer. */ struct scratch_writer { @@ -60,7 +62,9 @@ scratch_writer_open (struct file_handle *fh, size_t dict_value_cnt; /* Get exclusive write access to handle. */ - lock = fh_lock (fh, FH_REF_SCRATCH, "scratch file", FH_ACC_WRITE, true); + /* TRANSLATORS: this fragment will be interpolated into + messages in fh_lock() that identify types of files. */ + lock = fh_lock (fh, FH_REF_SCRATCH, N_("scratch file"), FH_ACC_WRITE, true); if (lock == NULL) return NULL; diff --git a/src/data/sys-file-reader.c b/src/data/sys-file-reader.c index 7c0312d2..b00a7b23 100644 --- a/src/data/sys-file-reader.c +++ b/src/data/sys-file-reader.c @@ -192,7 +192,9 @@ sfm_open_reader (struct file_handle *fh, struct dictionary **dict, r->has_long_var_names = false; r->opcode_idx = sizeof r->opcodes; - r->lock = fh_lock (fh, FH_REF_FILE, "system file", FH_ACC_READ, false); + /* TRANSLATORS: this fragment will be interpolated into + messages in fh_lock() that identify types of files. */ + r->lock = fh_lock (fh, FH_REF_FILE, N_("system file"), FH_ACC_READ, false); if (r->lock == NULL) goto error; diff --git a/src/data/sys-file-writer.c b/src/data/sys-file-writer.c index d25d5e8d..3e0d3499 100644 --- a/src/data/sys-file-writer.c +++ b/src/data/sys-file-writer.c @@ -53,6 +53,7 @@ #include "gettext.h" #define _(msgid) gettext (msgid) +#define N_(msgid) (msgid) /* Compression bias used by PSPP. Values between (1 - COMPRESSION_BIAS) and (251 - COMPRESSION_BIAS) inclusive can be @@ -184,7 +185,9 @@ sfm_open_writer (struct file_handle *fh, struct dictionary *d, &w->sfm_var_cnt); /* Open file handle as an exclusive writer. */ - w->lock = fh_lock (fh, FH_REF_FILE, "system file", FH_ACC_WRITE, true); + /* TRANSLATORS: this fragment will be interpolated into + messages in fh_lock() that identify types of files. */ + w->lock = fh_lock (fh, FH_REF_FILE, N_("system file"), FH_ACC_WRITE, true); if (w->lock == NULL) goto error; diff --git a/src/language/ChangeLog b/src/language/ChangeLog index 840278b2..65b97e6b 100644 --- a/src/language/ChangeLog +++ b/src/language/ChangeLog @@ -1,3 +1,12 @@ +2007-11-05 Ben Pfaff + + Patch #6258. Reviewed by John Darrington. + + * command.c (report_state_mismatch): Replace code to construct an + error message from bits and pieces by a switch statement that + hard-codes each possible error. Makes i18n easier. + Suggested by Chusslove Illich . + 2007-09-22 Ben Pfaff Bug #21128. Reviewed by John Darrington. diff --git a/src/language/command.c b/src/language/command.c index 62538c64..42580166 100644 --- a/src/language/command.c +++ b/src/language/command.c @@ -621,32 +621,72 @@ report_state_mismatch (const struct command *command, enum cmd_state state) assert (!in_correct_state (command, state)); if (state == CMD_STATE_INITIAL || state == CMD_STATE_DATA) { - const char *allowed[3]; - int allowed_cnt; - char *s; - - allowed_cnt = 0; - if (command->states & S_INITIAL) - allowed[allowed_cnt++] = _("before the active file has been defined"); - else if (command->states & S_DATA) - allowed[allowed_cnt++] = _("after the active file has been defined"); - if (command->states & S_INPUT_PROGRAM) - allowed[allowed_cnt++] = _("inside INPUT PROGRAM"); - if (command->states & S_FILE_TYPE) - allowed[allowed_cnt++] = _("inside FILE TYPE"); - - if (allowed_cnt == 1) - s = xstrdup (allowed[0]); - else if (allowed_cnt == 2) - s = xasprintf (_("%s or %s"), allowed[0], allowed[1]); - else if (allowed_cnt == 3) - s = xasprintf (_("%s, %s, or %s"), allowed[0], allowed[1], allowed[2]); - else - NOT_REACHED (); - - msg (SE, _("%s is allowed only %s."), command->name, s); - - free (s); + switch (command->states) + { + /* One allowed state. */ + case S_INITIAL: + msg (SE, _("%s is allowed only before the active file has " + "been defined."), command->name); + break; + case S_DATA: + msg (SE, _("%s is allowed only after the active file has " + "been defined."), command->name); + break; + case S_INPUT_PROGRAM: + msg (SE, _("%s is allowed only inside INPUT PROGRAM."), + command->name); + break; + case S_FILE_TYPE: + msg (SE, _("%s is allowed only inside FILE TYPE."), command->name); + break; + + /* Two allowed states. */ + case S_INITIAL | S_DATA: + NOT_REACHED (); + case S_INITIAL | S_INPUT_PROGRAM: + msg (SE, _("%s is allowed only before the active file has " + "been defined or inside INPUT PROGRAM."), command->name); + break; + case S_INITIAL | S_FILE_TYPE: + msg (SE, _("%s is allowed only before the active file has " + "been defined or inside FILE TYPE."), command->name); + break; + case S_DATA | S_INPUT_PROGRAM: + msg (SE, _("%s is allowed only after the active file has " + "been defined or inside INPUT PROGRAM."), command->name); + break; + case S_DATA | S_FILE_TYPE: + msg (SE, _("%s is allowed only after the active file has " + "been defined or inside FILE TYPE."), command->name); + break; + case S_INPUT_PROGRAM | S_FILE_TYPE: + msg (SE, _("%s is allowed only inside INPUT PROGRAM " + "or inside FILE TYPE."), command->name); + break; + + /* Three allowed states. */ + case S_DATA | S_INPUT_PROGRAM | S_FILE_TYPE: + msg (SE, _("%s is allowed only after the active file has " + "been defined, inside INPUT PROGRAM, or inside " + "FILE TYPE."), command->name); + break; + case S_INITIAL | S_INPUT_PROGRAM | S_FILE_TYPE: + msg (SE, _("%s is allowed only before the active file has " + "been defined, inside INPUT PROGRAM, or inside " + "FILE TYPE."), command->name); + break; + case S_INITIAL | S_DATA | S_FILE_TYPE: + NOT_REACHED (); + case S_INITIAL | S_DATA | S_INPUT_PROGRAM: + NOT_REACHED (); + + /* Four allowed states. */ + case S_INITIAL | S_DATA | S_INPUT_PROGRAM | S_FILE_TYPE: + NOT_REACHED (); + + default: + NOT_REACHED (); + } } else if (state == CMD_STATE_INPUT_PROGRAM) msg (SE, _("%s is not allowed inside INPUT PROGRAM."), command->name); diff --git a/src/language/data-io/data-reader.c b/src/language/data-io/data-reader.c index 6113bf74..c4e71830 100644 --- a/src/language/data-io/data-reader.c +++ b/src/language/data-io/data-reader.c @@ -41,6 +41,7 @@ #include "gettext.h" #define _(msgid) gettext (msgid) +#define N_(msgid) (msgid) /* Flags for DFM readers. */ enum dfm_reader_flags @@ -110,7 +111,9 @@ dfm_open_reader (struct file_handle *fh, struct lexer *lexer) struct dfm_reader *r; struct fh_lock *lock; - lock = fh_lock (fh, FH_REF_FILE | FH_REF_INLINE, "data file", + /* TRANSLATORS: this fragment will be interpolated into + messages in fh_lock() that identify types of files. */ + lock = fh_lock (fh, FH_REF_FILE | FH_REF_INLINE, N_("data file"), FH_ACC_READ, false); if (lock == NULL) return NULL; diff --git a/src/language/data-io/data-writer.c b/src/language/data-io/data-writer.c index b1b955c8..32caa1e2 100644 --- a/src/language/data-io/data-writer.c +++ b/src/language/data-io/data-writer.c @@ -35,6 +35,7 @@ #include "gettext.h" #define _(msgid) gettext (msgid) +#define N_(msgid) (msgid) /* Data file writer. */ struct dfm_writer @@ -52,7 +53,7 @@ dfm_open_writer (struct file_handle *fh) struct dfm_writer *w; struct fh_lock *lock; - lock = fh_lock (fh, FH_REF_FILE, "data file", FH_ACC_WRITE, false); + lock = fh_lock (fh, FH_REF_FILE, N_("data file"), FH_ACC_WRITE, false); if (lock == NULL) return NULL;