From 16aa47dbdde420fe82032f7d2e166fdf4e974df5 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 14 Dec 2005 06:59:06 +0000 Subject: [PATCH] Move global initialization and cleanup code into main.c. Remove vestigial log infrastructure. Minor related cleanups. --- src/ChangeLog | 62 +++++++++++++ src/Makefile.am | 1 - src/ascii.c | 4 +- src/cmdline.c | 15 ++-- src/command.c | 2 +- src/error.c | 34 +++----- src/error.h | 2 +- src/expressions/parse.c | 25 +++--- src/glob.c | 187 ++++------------------------------------ src/glob.h | 7 +- src/lexer.c | 4 +- src/log.h | 38 -------- src/main.c | 133 +++++++++++++++++++--------- src/main.h | 10 ++- src/output.c | 128 +++++++++++++++------------ src/output.h | 6 +- src/postscript.c | 4 +- src/q2c.c | 8 +- src/set.q | 1 - src/settings.c | 12 +-- src/settings.h | 4 +- src/title.c | 6 +- src/vfm.c | 22 ++++- src/vfm.h | 5 +- 24 files changed, 334 insertions(+), 386 deletions(-) delete mode 100644 src/log.h diff --git a/src/ChangeLog b/src/ChangeLog index a94b5ef5..98bd9d09 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,65 @@ +Tue Dec 13 22:34:42 2005 Ben Pfaff + + Move global initialization and cleanup code into main.c. + Remove vestigial log infrastructure. + Minor related cleanups. + + * command.c: (shell) When execl() fails, use _exit(), not + err_hcf(). + + * error.c: (err_hcf) Move into main.c, rename terminate(). All + callers updated. + (err_done) New function with just the error.c-specific code for + err_hcf(). Called by terminate(). + + * glob.c: Removed all Borland C, DJGPP cruft. + (init_glob) Merged into main(). + (done_glob) Merged into terminate(). + (get_date) Removed. + (get_start_date) New function. All users of curdate updated to call + this function instead. + + * lexer.c: (lex_init) Moved initialization of tokstr here, from + init_glob(). + (lex_done) Moved destruction of tokstr here, from done_glob(). + + * main.c: (global var pgmname) Removed. Changed all references to + program_name, which is defined by gnulib. + (global var curdate) Removed. + (main) Moved init_glob() code here. Merged parse_script() in + here. + (parse_script) Removed. + (terminate) Moved err_hcf() here from error.c and renamed + terminate(). Merged done_glob() code in here. Call err_done(). + All callers updated. + (i18n_init) New function. + (fpu_init) New function. + + * output.c: (outp_init) Make void. + (init_default_drivers) New function. + (outp_read_devices) If no drivers are initialized successfully, + call init_default_drivers() to initialize a default driver. + (outp_done) Make void. + (static var prog) Make const. + (parse_options) Make parameter const. + (colon_tokenize) Make return value const. + (configure_driver) Change prototype to take a broken-down driver + configuration instead of a line of text. + (configure_driver_line) New function that does what + configure_driver() did before. + + * q2c.c: (global var pgmname) Rename program_name. + + * settings.c: (settings_init) Renamed from init_settings(). + (settings_done) Renamed from done_settings(). + + * vfm.c: (global var last_vfm_invocation) Make static. + (vfm_last_invocation) New function. All references to + last_vfm_invocation update to call this. + (procedure) Call update_last_vfm_invocation(). + (internal_procedure) Ditto. + (update_last_vfm_invocation) New function. + Sat Dec 10 23:30:19 2005 Ben Pfaff Separate random numbers from other settings because of GSL diff --git a/src/Makefile.am b/src/Makefile.am index 5289af2b..e3b3952e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -158,7 +158,6 @@ pspp_SOURCES = \ levene.h \ linked-list.c \ linked-list.h \ - log.h \ loop.c \ magic.c \ magic.h \ diff --git a/src/ascii.c b/src/ascii.c index bd55d0ef..738526f3 100644 --- a/src/ascii.c +++ b/src/ascii.c @@ -26,6 +26,7 @@ #include "alloc.h" #include "error.h" #include "filename.h" +#include "glob.h" #include "main.h" #include "misc.h" #include "output.h" @@ -1579,7 +1580,8 @@ ascii_close_page (struct outp_driver *this) { char temp[40]; - snprintf (temp, 80, _("%s - Page %d"), curdate, x->page_number); + snprintf (temp, 80, _("%s - Page %d"), get_start_date (), + x->page_number); memcpy (&s[x->w - strlen (temp)], temp, strlen (temp)); } diff --git a/src/cmdline.c b/src/cmdline.c index 68df7b47..b9205a14 100644 --- a/src/cmdline.c +++ b/src/cmdline.c @@ -26,17 +26,18 @@ #include #include #include "alloc.h" +#include "copyleft.h" #include "error.h" #include "filename.h" #include "getl.h" +#include "glob.h" #include "main.h" #include "output.h" +#include "progname.h" #include "settings.h" #include "str.h" #include "var.h" #include "version.h" -#include "copyleft.h" -#include "glob.h" #include "gettext.h" #define _(msgid) gettext (msgid) @@ -158,7 +159,7 @@ parse_command_line (int argc, char **argv) break; case 'l': outp_list_classes (); - err_hcf (1); + terminate (true); case 'n': printf (_("%s is not yet implemented."),"-n"); putchar('\n'); @@ -187,7 +188,7 @@ parse_command_line (int argc, char **argv) case 'V': puts (version); puts (legal); - err_hcf (1); + terminate (true); case 'T': force_long_view (); set_testing_mode (true); @@ -282,9 +283,9 @@ static const char post_syntax_message[] = N_("\nReport bugs to <%s>.\n"); static void usage (void) { - printf (gettext (pre_syntax_message), pgmname); + printf (gettext (pre_syntax_message), program_name); outp_list_classes (); - printf (gettext (post_syntax_message),PACKAGE_BUGREPORT); + printf (gettext (post_syntax_message), PACKAGE_BUGREPORT); - err_hcf (1); + terminate (true); } diff --git a/src/command.c b/src/command.c index 0d557b20..c6d7659d 100644 --- a/src/command.c +++ b/src/command.c @@ -739,7 +739,7 @@ shell (void) execl (shell_fn, shell_process, NULL); - err_hcf (1); + _exit (1); } case -1: diff --git a/src/error.c b/src/error.c index 28da450e..7ca387ab 100644 --- a/src/error.c +++ b/src/error.c @@ -30,6 +30,7 @@ #include "lexer.h" #include "main.h" #include "output.h" +#include "progname.h" #include "settings.h" #include "str.h" #include "var.h" @@ -93,10 +94,10 @@ err_failure (void) fflush (stdout); fflush (stderr); - fprintf (stderr, "%s: %s\n", pgmname, + fprintf (stderr, "%s: %s\n", program_name, _("Terminating NOW due to a fatal error!")); - err_hcf (0); + terminate (false); } /* Terminate unless we're interactive or will go interactive when the @@ -193,33 +194,18 @@ err_check_count (void) #define EXIT_FAILURE 1 #endif -static int terminating; +static void puts_stdout (const char *s); +static void dump_message (char *errbuf, unsigned indent, + void (*func) (const char *), unsigned width); -/* Halt-catch-fire. SUCCESS should be nonzero if exiting successfully - or zero if not. Despite the name, this is the usual way to finish, - successfully or not. */ void -err_hcf (int success) +err_done (void) { - terminating = 1; - - lex_done(); - getl_uninitialize (); - - free(file_loc); + free (file_loc); file_loc = NULL; nfile_loc = mfile_loc = 0; - - outp_done (); - done_glob(); - - exit (success ? EXIT_SUCCESS : EXIT_FAILURE); } -static void puts_stdout (const char *s); -static void dump_message (char *errbuf, unsigned indent, - void (*func) (const char *), unsigned width); - void err_vmsg (const struct error *e, const char *format, va_list args) { @@ -304,8 +290,8 @@ err_vmsg (const struct error *e, const char *format, va_list args) ds_destroy (&msg); - if (e->class == FE && !terminating) - err_hcf (0); + if (e->class == FE) + terminate (0); } /* Private functions. */ diff --git a/src/error.h b/src/error.h index ab38af62..e1016882 100644 --- a/src/error.h +++ b/src/error.h @@ -81,9 +81,9 @@ void err_pop_file_locator (const struct file_locator *); void err_location (struct file_locator *); /* Obscure functions. */ +void err_done (void); void err_break (void); void err_check_count (void); -void err_hcf (int exit_code) NO_RETURN; void err_vmsg (const struct error *, const char *, va_list); /* Used in panic situations only */ diff --git a/src/expressions/parse.c b/src/expressions/parse.c index b841953b..fcfd8ef3 100644 --- a/src/expressions/parse.c +++ b/src/expressions/parse.c @@ -731,6 +731,7 @@ parse_sysvar (struct expression *e) "JUL", "AUG", "SEP", "OCT", "NOV", "DEC", }; + time_t last_vfm_invocation = vfm_last_invocation (); struct tm *time; char temp_buf[10]; @@ -748,21 +749,23 @@ parse_sysvar (struct expression *e) return expr_allocate_number (e, SYSMIS); else if (lex_match_id ("$JDATE")) { - struct tm *time = localtime (&last_vfm_invocation); - return expr_allocate_number (e, expr_ymd_to_ofs (time->tm_year + 1900, - time->tm_mon + 1, - time->tm_mday)); + time_t time = vfm_last_invocation (); + struct tm *tm = localtime (&time); + return expr_allocate_number (e, expr_ymd_to_ofs (tm->tm_year + 1900, + tm->tm_mon + 1, + tm->tm_mday)); } else if (lex_match_id ("$TIME")) { - struct tm *time = localtime (&last_vfm_invocation); + time_t time = vfm_last_invocation (); + struct tm *tm = localtime (&time); return expr_allocate_number (e, - expr_ymd_to_date (time->tm_year + 1900, - time->tm_mon + 1, - time->tm_mday) - + time->tm_hour * 60 * 60. - + time->tm_min * 60. - + time->tm_sec); + expr_ymd_to_date (tm->tm_year + 1900, + tm->tm_mon + 1, + tm->tm_mday) + + tm->tm_hour * 60 * 60. + + tm->tm_min * 60. + + tm->tm_sec); } else if (lex_match_id ("$LENGTH")) return expr_allocate_number (e, get_viewlength ()); diff --git a/src/glob.c b/src/glob.c index 38dd3237..c0b3c905 100644 --- a/src/glob.c +++ b/src/glob.c @@ -19,66 +19,9 @@ #include #include "glob.h" -#include "error.h" -#include "progname.h" -#include -#include #include - -#if HAVE_LIBHISTORY -#if HAVE_READLINE_HISTORY_H -#include -#else /* no readline/history.h */ -extern void using_history (); -extern int read_history (); -extern void stifle_history (); -#endif /* no readline/history.h */ -#endif /* -lhistory */ - -#if HAVE_FPU_CONTROL_H -#include -#elif __BORLANDC__ -#include -#include -#endif - -#if __DJGPP__ -#include -#elif defined (__WIN32__) && defined (__BORLANDC__) -#undef gettext -#include -#define gettext(STRING) \ - STRING -#endif - -#if HAVE_LOCALE_H -#include -#endif - -#if HAVE_FENV_H -#include -#endif - -#include "alloc.h" -#include "calendar.h" -#include "command.h" -#include "dictionary.h" -#include "error.h" -#include "file-handle.h" -#include "filename.h" -#include "getl.h" -#include "hash.h" -#include "lexer.h" -#include "magic.h" -#include "main.h" -#include "random.h" -#include "settings.h" #include "str.h" -#include "var.h" -#include "version.h" -#include "vfm.h" - -#include "gettext.h" +#include "strftime.h" /* var.h */ struct dictionary *default_dict; @@ -90,128 +33,32 @@ size_t n_trns, m_trns, f_trns; int FILTER_before_TEMPORARY; struct file_handle *default_handle; - -/* log.h */ -char *logfn; -FILE *logfile; -int logging; /* Functions. */ -static void get_date (void); - - -void -init_glob (int argc UNUSED, char **argv) -{ - set_program_name (argv[0]); - - /* FIXME: Allow i18n of other locale items (besides LC_MESSAGES). */ -#if ENABLE_NLS -#if HAVE_LC_MESSAGES - setlocale (LC_MESSAGES, ""); -#endif - setlocale (LC_MONETARY, ""); - bindtextdomain (PACKAGE, locale_dir); - textdomain (PACKAGE); -#endif /* ENABLE_NLS */ - - fn_init (); - fh_init (); - getl_initialize (); - - /* PORTME: If your system/OS has the nasty tendency to halt with a - SIGFPE whenever there's a floating-point overflow (or other - exception), be sure to mask off those bits in the FPU here. - PSPP wants a guarantee that, no matter what boneheaded - floating-point operation it performs, the process will not halt. */ -#if HAVE_FEHOLDEXCEPT - { - fenv_t foo; - - feholdexcept (&foo); - } -#elif HAVE___SETFPUCW && defined(_FPU_IEEE) - __setfpucw (_FPU_IEEE); -#elif __BORLANDC__ - _control87 (0xffff, 0x137f); -#endif - - /* var.h */ - default_dict = dict_create (); - - last_vfm_invocation = time (NULL); - - /* lexer.h */ - ds_init (&tokstr, 64); - - /* common.h */ - { - char *cp; - - pgmname = argv[0]; - for (;;) - { - cp = strchr (pgmname, DIR_SEPARATOR); - if (!cp) - break; - pgmname = &cp[1]; - } - cur_proc = NULL; - } - - - init_settings (); - random_init (); - - /* log.h */ - logging = 1; - logfn = xstrdup ("pspp.log"); - logfile = NULL; - - get_date (); -} - -void -done_glob(void) -{ - cancel_transformations (); - dict_destroy (default_dict); - free (logfn); - random_done (); - done_settings (); - ds_destroy (&tokstr); - - fh_done(); -} - static void -get_date (void) +get_cur_date (char cur_date[12]) { + time_t now = time (NULL); - time_t t; - struct tm *tmp; - - if ((time_t) -1 == time (&t)) + if (now != (time_t) -1) { - strcpy (curdate, "?? ??? 2???"); - return; + struct tm *tm = localtime (&now); + if (tm != NULL) + { + strftime (cur_date, 12, "%d %b %Y", tm); + return; + } } - tmp = localtime (&t); - - strftime (curdate, 12, "%d %b %Y",tmp); + strcpy (cur_date, "?? ??? 2???"); } -#if __BORLANDC__ -int -_RTLENTRY _EXPFUNC _matherr (struct exception _FAR *__e) +const char * +get_start_date (void) { - return 1; -} + static char start_date[12]; -int -_RTLENTRY _EXPFUNC _matherrl (struct _exceptionl _FAR *__e) -{ - return 1; + if (start_date[0] == '\0') + get_cur_date (start_date); + return start_date; } -#endif diff --git a/src/glob.h b/src/glob.h index dd5eb95c..45ab3337 100644 --- a/src/glob.h +++ b/src/glob.h @@ -17,10 +17,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#if !INCLUDED_GLOB_H -#define INCLUDED_GLOB_H 1 +#if !GLOB_H +#define GLOB_H 1 -void init_glob (int argc UNUSED, char **argv); -void done_glob (void); +const char *get_start_date (void); #endif /* glob.h */ diff --git a/src/lexer.c b/src/lexer.c index fc6bf9d3..cc2f8ca8 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -92,6 +92,7 @@ static void dump_token (void); void lex_init (void) { + ds_init (&tokstr, 64); ds_init (&put_tokstr, 64); if (!lex_get_line ()) unexpected_eof (); @@ -100,7 +101,8 @@ lex_init (void) void lex_done (void) { - ds_destroy(&put_tokstr); + ds_destroy (&put_tokstr); + ds_destroy (&tokstr); } diff --git a/src/log.h b/src/log.h deleted file mode 100644 index 4d2829ed..00000000 --- a/src/log.h +++ /dev/null @@ -1,38 +0,0 @@ -/* PSPP - computes sample statistics. - Copyright (C) 1997-9, 2000 Free Software Foundation, Inc. - Written by Ben Pfaff . - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. */ - -#if !log_h -#define log_h 1 - -#include - -/* Whether logging is on. */ -extern int logging; - -/* The name of the log file. */ -extern char *logfn; - -/* The log file stream. */ -extern FILE *logfile; - -/* Log file management. */ -void open_logfile (void); -void close_logfile (void); - -#endif /* !log_h */ diff --git a/src/main.c b/src/main.c index f9c4e83b..4918eefc 100644 --- a/src/main.c +++ b/src/main.c @@ -18,20 +18,37 @@ 02110-1301, USA. */ #include -#include -#include #include "main.h" +#include +#include +#include #include "cmdline.h" #include "command.h" #include "dictionary.h" #include "error.h" +#include "file-handle.h" +#include "filename.h" #include "getl.h" #include "glob.h" #include "lexer.h" #include "output.h" +#include "progname.h" +#include "random.h" #include "settings.h" #include "var.h" -#include +#include "version.h" + +#if HAVE_FPU_CONTROL_H +#include +#endif + +#if HAVE_LOCALE_H +#include +#endif + +#if HAVE_FENV_H +#include +#endif #include "gettext.h" #define _(msgid) gettext (msgid) @@ -40,20 +57,14 @@ #include "debug-print.h" -static void parse_script (void) NO_RETURN; +static void i18n_init (void); +static void fpu_init (void); static void handle_error (int code); static int execute_command (void); -/* argv[0] with stripped leading directories. */ -char *pgmname; - /* Whether FINISH. has been executed. */ int finished; -/* The current date in the form DD MMM YYYY. */ -char curdate[12]; - - /* If a segfault happens, issue a message to that effect and halt */ void bug_handler(int sig); @@ -64,50 +75,66 @@ void interrupt_handler(int sig); we hit end-of-file unexpectedly (or whatever). */ int start_interactive; - - - - - /* Program entry point. */ int main (int argc, char **argv) { - signal (SIGSEGV, bug_handler); - signal (SIGFPE, bug_handler); - signal (SIGINT, interrupt_handler); + signal (SIGFPE, bug_handler); + signal (SIGINT, interrupt_handler); - gsl_set_error_handler_off(); + set_program_name ("pspp"); + i18n_init (); + fpu_init (); + gsl_set_error_handler_off (); - /* Initialization. */ - if (!outp_init ()) - err_hcf (0); - init_glob (argc, argv); - parse_command_line (argc, argv); - if (!outp_read_devices ()) - msg (FE, _("Error initializing output drivers.")); + outp_init (); + fn_init (); + fh_init (); + getl_initialize (); + settings_init (); + random_init (); - lex_init (); + default_dict = dict_create (); - /* Execution. */ - parse_script (); + parse_command_line (argc, argv); + outp_read_devices (); - /* Should never be reached */ - return (-1); -} + lex_init (); -/* Parses the entire script. */ -static void -parse_script (void) -{ while (!finished) { err_check_count (); handle_error (execute_command ()); } - err_hcf (err_error_count==0); + terminate (err_error_count == 0); + abort (); +} + +/* Terminate PSPP. SUCCESS should be true to exit successfully, + false to exit as a failure. */ +void +terminate (bool success) +{ + static bool terminating = false; + if (terminating) + return; + terminating = true; + + err_done (); + outp_done (); + + cancel_transformations (); + dict_destroy (default_dict); + + random_done (); + settings_done (); + fh_done (); + lex_done (); + getl_uninitialize (); + + exit (success ? EXIT_SUCCESS : EXIT_FAILURE); } /* Parse and execute a command, returning its return code. */ @@ -129,7 +156,7 @@ execute_command (void) break; if (!getl_perform_delayed_reset ()) - err_hcf (err_error_count==0); + terminate (err_error_count == 0); } /* Parse the command. */ @@ -191,12 +218,34 @@ handle_error (int code) lex_discard_line (); } } + +static void +i18n_init (void) +{ +#if ENABLE_NLS +#if HAVE_LC_MESSAGES + setlocale (LC_MESSAGES, ""); +#endif + setlocale (LC_MONETARY, ""); + bindtextdomain (PACKAGE, locale_dir); + textdomain (PACKAGE); +#endif /* ENABLE_NLS */ +} - +static void +fpu_init (void) +{ +#if HAVE_FEHOLDEXCEPT + fenv_t foo; + feholdexcept (&foo); +#elif HAVE___SETFPUCW && defined(_FPU_IEEE) + __setfpucw (_FPU_IEEE); +#endif +} /* If a segfault happens, issue a message to that effect and halt */ void -bug_handler(int sig UNUSED) +bug_handler(int sig) { switch (sig) { @@ -216,5 +265,5 @@ bug_handler(int sig UNUSED) void interrupt_handler(int sig UNUSED) { - err_hcf(0); + terminate (false); } diff --git a/src/main.h b/src/main.h index 152bfae3..38554a09 100644 --- a/src/main.h +++ b/src/main.h @@ -17,12 +17,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#if !main_h -#define main_h 1 +#if !MAIN_H +#define MAIN_H 1 + +#include -extern char *pgmname; -extern char curdate[]; extern int start_interactive; extern int finished; +void terminate (bool success); + #endif /* main.h */ diff --git a/src/output.c b/src/output.c index 63e1f810..c0b849a4 100644 --- a/src/output.c +++ b/src/output.c @@ -79,7 +79,9 @@ char *outp_subtitle; static int disabled_devices; static void destroy_driver (struct outp_driver *); -static void configure_driver (char *); +static void configure_driver_line (char *); +static void configure_driver (const char *, const char *, + const char *, const char *); #if GLOBAL_DEBUGGING /* This mechanism attempts to catch reentrant use of outp_driver_list. */ @@ -221,7 +223,7 @@ find_defn_value (const char *key) } /* Initializes global variables. */ -int +void outp_init (void) { extern struct outp_class ascii_class; @@ -229,7 +231,9 @@ outp_init (void) extern struct outp_class postscript_class; extern struct outp_class epsf_class; #endif +#if !NO_HTML extern struct outp_class html_class; +#endif char def[] = "default"; @@ -243,8 +247,6 @@ outp_init (void) add_class (&ascii_class); add_name (def, &def[strlen (def)], OUTP_S_INIT_FILE); - - return 1; } /* Deletes all the output macros. */ @@ -262,8 +264,19 @@ delete_macros (void) } } -/* Reads the initialization file; initializes outp_driver_list. */ -int +static void +init_default_drivers (void) +{ + msg (MM, _("Using default output driver configuration.")); + configure_driver ("list-ascii", "ascii", "listing", + "length=66 width=79 char-set=ascii " + "output-file=\"pspp.list\" " + "bold-on=\"\" italic-on=\"\" bold-italic-on=\"\""); +} + +/* Reads the initialization file; initializes + outp_driver_list. */ +void outp_read_devices (void) { int result = 0; @@ -329,7 +342,7 @@ outp_read_devices (void) struct outp_names *n = search_names (cp, ep); if (n) { - configure_driver (cp); + configure_driver_line (cp); delete_name (n); } } @@ -348,14 +361,18 @@ exit: free (init_fn); ds_destroy (&line); delete_macros (); - if (outp_driver_list == NULL) - msg (MW, _("No output drivers are active.")); - if (result) - msg (VM (2), _("Device definition file read successfully.")); + if (result) + { + msg (VM (2), _("Device definition file read successfully.")); + if (outp_driver_list == NULL) + msg (MW, _("No output drivers are active.")); + } else msg (VM (1), _("Error reading device definition file.")); - return result; + + if (!result || outp_driver_list == NULL) + init_default_drivers (); } /* Clear the list of drivers to configure. */ @@ -439,7 +456,7 @@ destroy_list (struct outp_driver ** dl) } /* Closes all the output drivers. */ -int +void outp_done (void) { struct outp_driver_class_list *n = outp_class_list ; @@ -462,8 +479,6 @@ outp_done (void) free (outp_subtitle); outp_subtitle = NULL; - - return 1; } /* Display on stdout a list of all registered driver classes. */ @@ -491,7 +506,7 @@ outp_list_classes (void) static int op_token; /* `=', 'a', 0. */ static struct string op_tokstr; -static char *prog; +static const char *prog; /* Parses a token from prog into op_token, op_tokstr. Sets op_token to '=' on an equals sign, to 'a' on a string or identifier token, @@ -622,7 +637,7 @@ tokener (void) /* Applies the user-specified options in string S to output driver D (at configuration time). */ static void -parse_options (char *s, struct outp_driver * d) +parse_options (const char *s, struct outp_driver * d) { prog = s; op_token = -1; @@ -683,7 +698,7 @@ find_driver (char *name) after all fields have been used up. FIXME: Should ignore colons inside double quotes. */ -static char * +static const char * colon_tokenize (char *s, char **cp) { char *token; @@ -711,49 +726,27 @@ colon_tokenize (char *s, char **cp) Adds a driver to outp_driver_list pursuant to the specification provided. */ static void -configure_driver (char *s) +configure_driver (const char *driver_name, const char *class_name, + const char *device_type, const char *options) { - char *token, *cp; struct outp_driver *d = NULL, *iter; struct outp_driver_class_list *c = NULL; - s = fn_interp_vars (s, find_defn_value); - - /* Driver name. */ - token = colon_tokenize (s, &cp); - if (!token) - { - msg (IS, _("Driver name expected.")); - goto error; - } - d = xmalloc (sizeof *d); - d->class = NULL; - d->name = xstrdup (token); + d->name = xstrdup (driver_name); d->driver_open = 0; d->page_open = 0; - d->next = d->prev = NULL; - d->device = OUTP_DEV_NONE; - d->ext = NULL; - /* Class name. */ - token = colon_tokenize (NULL, &cp); - if (!token) - { - msg (IS, _("Class name expected.")); - goto error; - } - for (c = outp_class_list; c; c = c->next) - if (!strcmp (c->class->name, token)) + if (!strcmp (c->class->name, class_name)) break; if (!c) { - msg (IS, _("Unknown output driver class `%s'."), token); + msg (IS, _("Unknown output driver class `%s'."), class_name); goto error; } @@ -773,12 +766,12 @@ configure_driver (char *s) } /* Device types. */ - token = colon_tokenize (NULL, &cp); - if (token) + if (device_type != NULL) { + char *copy = xstrdup (device_type); char *sp, *type; - for (type = strtok_r (token, " \t\r\v", &sp); type; + for (type = strtok_r (copy, " \t\r\v", &sp); type; type = strtok_r (NULL, " \t\r\v", &sp)) { if (!strcmp (type, "listing")) @@ -790,15 +783,16 @@ configure_driver (char *s) else { msg (IS, _("Unknown device type `%s'."), type); + free (copy); goto error; } } + free (copy); } /* Options. */ - token = colon_tokenize (NULL, &cp); - if (token) - parse_options (token, d); + if (options != NULL) + parse_options (options, d); if (!d->class->postopen_driver (d)) { msg (IS, _("Can't complete initialization of output driver `%s' of " @@ -817,13 +811,39 @@ configure_driver (char *s) if (outp_driver_list) outp_driver_list->prev = d; outp_driver_list = d; - goto exit; + return; error: if (d) destroy_driver (d); -exit: - free (s); + return; +} + +/* String S is in format: + DRIVERNAME:CLASSNAME:DEVICETYPE:OPTIONS + Adds a driver to outp_driver_list pursuant to the specification + provided. */ +static void +configure_driver_line (char *s) +{ + char *cp; + const char *driver_name, *class_name, *device_type, *options; + + s = fn_interp_vars (s, find_defn_value); + + /* Driver name. */ + driver_name = colon_tokenize (s, &cp); + class_name = colon_tokenize (NULL, &cp); + device_type = colon_tokenize (NULL, &cp); + options = colon_tokenize (NULL, &cp); + if (driver_name == NULL || class_name == NULL) + { + msg (IS, _("Driver definition line contains fewer fields " + "than expected")); + return; + } + + configure_driver (driver_name, class_name, device_type, options); } /* Destroys output driver D. */ diff --git a/src/output.h b/src/output.h index 3b5eeeba..03867e9f 100644 --- a/src/output.h +++ b/src/output.h @@ -242,9 +242,9 @@ extern struct outp_driver *outp_driver_list; extern char *outp_title; extern char *outp_subtitle; -int outp_init (void); -int outp_read_devices (void); -int outp_done (void); +void outp_init (void); +void outp_read_devices (void); +void outp_done (void); void outp_configure_clear (void); void outp_configure_add (char *); diff --git a/src/postscript.c b/src/postscript.c index 5acb02f5..f2bb3400 100644 --- a/src/postscript.c +++ b/src/postscript.c @@ -40,10 +40,10 @@ #include "font.h" #include "getl.h" #include "getline.h" +#include "glob.h" #include "hash.h" #include "main.h" #include "misc.h" -#include "misc.h" #include "output.h" #include "som.h" #include "version.h" @@ -2105,7 +2105,7 @@ draw_headers (struct outp_driver *this) int rh_width; char buf[128]; - sprintf (buf, _("%s - Page %d"), curdate, ext->page_number); + sprintf (buf, _("%s - Page %d"), get_start_date (), ext->page_number); rh_width = text_width (this, buf); out_text_plain (this, buf, this->width - this->prop_em_width - rh_width, diff --git a/src/q2c.c b/src/q2c.c index f771d466..c1b7e8d7 100644 --- a/src/q2c.c +++ b/src/q2c.c @@ -53,7 +53,7 @@ #define MAX_TOK_LEN 1024 /* argv[0]. */ -char *pgmname; +char *program_name; /* Have the input and output files been opened yet? */ int is_open; @@ -97,7 +97,7 @@ finish_up (void) fclose (in); fclose (out); if (remove (ofn) == -1) - fprintf (stderr, "%s: %s: remove: %s\n", pgmname, ofn, strerror (errno)); + fprintf (stderr, "%s: %s: remove: %s\n", program_name, ofn, strerror (errno)); } void hcf (void) NO_RETURN; @@ -120,7 +120,7 @@ fail (const char *format, ...) va_list args; va_start (args, format); - fprintf (stderr, "%s: ", pgmname); + fprintf (stderr, "%s: ", program_name); vfprintf (stderr, format, args); fprintf (stderr, "\n"); va_end (args); @@ -1992,7 +1992,7 @@ recognize_directive (void) int main (int argc, char *argv[]) { - pgmname = argv[0]; + program_name = argv[0]; if (argc != 3) fail ("Syntax: q2c input.q output.c"); diff --git a/src/set.q b/src/set.q index 8fb3a807..8df84654 100644 --- a/src/set.q +++ b/src/set.q @@ -30,7 +30,6 @@ #include "lexer.h" #include "error.h" #include "magic.h" -#include "log.h" #include "output.h" #include "random.h" #include "var.h" diff --git a/src/settings.c b/src/settings.c index 4961b564..94af922a 100644 --- a/src/settings.c +++ b/src/settings.c @@ -89,17 +89,17 @@ static int syntax = ENHANCED; static void init_viewport (void); void -done_settings (void) +settings_init (void) { - free (prompt); - free (cprompt); - free (dprompt); + init_viewport (); } void -init_settings (void) +settings_done (void) { - init_viewport (); + free (prompt); + free (cprompt); + free (dprompt); } /* Screen length in lines. */ diff --git a/src/settings.h b/src/settings.h index 0593f2d1..abb1743b 100644 --- a/src/settings.h +++ b/src/settings.h @@ -32,8 +32,8 @@ enum SET_ROUTE_DISABLE = 010 /* Disable output--overrides all other bits. */ }; -void init_settings (void); -void done_settings (void); +void settings_init (void); +void settings_done (void); void force_long_view (void); int get_viewlength (void); diff --git a/src/title.c b/src/title.c index d4a95c18..7edd2dad 100644 --- a/src/title.c +++ b/src/title.c @@ -24,6 +24,7 @@ #include "command.h" #include "dictionary.h" #include "error.h" +#include "glob.h" #include "lexer.h" #include "main.h" #include "output.h" @@ -135,14 +136,11 @@ cmd_document (void) /* Add a few header lines for reference. */ { char buf[256]; - struct tm *tmp = localtime (&last_vfm_invocation); if (dict_get_documents (default_dict) != NULL) add_document_line ("", 0); - sprintf (buf, _("Document entered %s %02d:%02d:%02d by %s (%s):"), - curdate, tmp->tm_hour, tmp->tm_min, tmp->tm_sec, version, - host_system); + sprintf (buf, _("Document entered %s by %s:"), get_start_date (), version); add_document_line (buf, 1); } diff --git a/src/vfm.c b/src/vfm.c index 7f2cb693..3d8f03ae 100644 --- a/src/vfm.c +++ b/src/vfm.c @@ -80,7 +80,7 @@ struct case_sink *vfm_sink; static int compaction_necessary; /* Time at which vfm was last invoked. */ -time_t last_vfm_invocation; +static time_t last_vfm_invocation; /* Lag queue. */ int n_lag; /* Number of cases to lag. */ @@ -90,6 +90,7 @@ static struct ccase *lag_queue; /* Array of n_lag ccase * elements. */ static void internal_procedure (int (*proc_func) (struct ccase *, void *), void *aux); +static void update_last_vfm_invocation (void); static void create_trns_case (struct ccase *, struct dictionary *); static void open_active_file (void); static int write_case (struct write_case_data *wc_data); @@ -104,6 +105,15 @@ static void close_active_file (void); /* Public functions. */ +/* Returns the last time the data was read. */ +time_t +vfm_last_invocation (void) +{ + if (last_vfm_invocation == 0) + update_last_vfm_invocation (); + return last_vfm_invocation; +} + /* Reads the data from the input program and writes it to a new active file. For each case we read from the input program, we do the following @@ -136,6 +146,7 @@ procedure (int (*proc_func) (struct ccase *, void *), void *aux) && n_trns == 0) { /* Nothing to do. */ + update_last_vfm_invocation (); return; } @@ -162,7 +173,7 @@ internal_procedure (int (*proc_func) (struct ccase *, void *), void *aux) case_create (&wc_data.sink_case, dict_get_next_value_idx (default_dict)); wc_data.cases_written = 0; - last_vfm_invocation = time (NULL); + update_last_vfm_invocation (); if (vfm_source != NULL) vfm_source->class->read (vfm_source, @@ -175,6 +186,13 @@ internal_procedure (int (*proc_func) (struct ccase *, void *), void *aux) assert (--recursive_call == 0); } +/* Updates last_vfm_invocation. */ +static void +update_last_vfm_invocation (void) +{ + last_vfm_invocation = time (NULL); +} + /* Creates and returns a case, initializing it from the vectors that say which `value's need to be initialized just once, and which ones need to be re-initialized before every case. */ diff --git a/src/vfm.h b/src/vfm.h index b35a0abd..d72568ce 100644 --- a/src/vfm.h +++ b/src/vfm.h @@ -22,9 +22,6 @@ #include -/* This is the time at which vfm was last invoked. */ -extern time_t last_vfm_invocation; - struct ccase; typedef struct write_case_data *write_case_data; typedef int write_case_func (write_case_data); @@ -134,5 +131,7 @@ struct ccase *lagged_case (int n_before); void multipass_procedure_with_splits (void (*) (const struct casefile *, void *), void *aux); + +time_t vfm_last_invocation (void); #endif /* !vfm_h */ -- 2.30.2