[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Directory restructuring
From: |
Ben Pfaff |
Subject: |
Re: Directory restructuring |
Date: |
Sun, 05 Feb 2006 14:37:06 -0800 |
User-agent: |
Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux) |
Ben Pfaff <address@hidden> writes:
> Ben Pfaff <address@hidden> writes:
>
>>> > main.[ch]: I don't know why we need a main.h ?
>>>
>>> main.c exports some interfaces?
>>>
>>> I'm of the opinion, that main.c should be moved to src/ui
>>
>> I took a closer look at what main.h exports. start_interactive
>> is actually unused anywhere, so it can be deleted. finished is
>> only used in command.c and main.c and could be implemented as
>> another CMD_* function return value.
>
> I am going to work on this and related cleanups.
Okay, here's a patch. At this point I'm going to stop working on
this cleanup until I see another tarball posted from you, because
I'm worried that I'll cause trouble with conflicts.
Also as:
http://footstool.stanford.edu/~blp/reorg3.patch
http://footstool.stanford.edu/~blp/reorg3.tar.gz
diff -urpN -X pat reorg2/src/language/command.c reorg3/src/language/command.c
--- reorg2/src/language/command.c 2006-02-05 08:47:32.000000000 -0800
+++ reorg3/src/language/command.c 2006-02-05 14:12:38.000000000 -0800
@@ -30,7 +30,6 @@
#include "glob.h"
#include "getl.h"
#include "lexer.h"
-#include "main.h"
#include "settings.h"
#include "som.h"
#include "str.h"
@@ -610,36 +609,32 @@ error:
int
cmd_exit (void)
{
- if (getl_reading_script())
+ if (!getl_reading_script ())
+ return CMD_EOF;
+ else
{
msg (SE, _("This command is not accepted in a syntax file. "
- "Instead, use FINISH to terminate a syntax file."));
+ "Instead, use FINISH to terminate a syntax file."));
lex_get ();
+ return CMD_FAILURE;
}
- else
- finished = 1;
-
- return CMD_SUCCESS;
}
/* Parse and execute FINISH command. */
int
cmd_finish (void)
{
- /* Do not check for `.'
- Do not fetch any extra tokens. */
- if (getl_interactive)
+ if (!getl_interactive)
+ return CMD_EOF;
+ else
{
msg (SM, _("This command is not executed "
- "in interactive mode. Instead, PSPP drops "
- "down to the command prompt. Use EXIT if you really want "
- "to quit."));
+ "in interactive mode. Instead, PSPP drops "
+ "down to the command prompt. Use EXIT if you really want "
+ "to quit."));
getl_close_all ();
+ return CMD_FAILURE;
}
- else
- finished = 1;
-
- return CMD_SUCCESS;
}
/* Parses the N command. */
diff -urpN -X pat reorg2/src/language/command.h reorg3/src/language/command.h
--- reorg2/src/language/command.h 2006-02-05 08:45:58.000000000 -0800
+++ reorg3/src/language/command.h 2006-02-05 14:03:22.000000000 -0800
@@ -37,7 +37,8 @@ enum
CMD_SUCCESS, /* Command successfully parsed and executed. */
CMD_PART_SUCCESS_MAYBE, /* Command may have been partially executed. */
CMD_PART_SUCCESS, /* Command fully executed up to error. */
- CMD_TRAILING_GARBAGE /* Command followed by garbage. */
+ CMD_TRAILING_GARBAGE, /* Command followed by garbage. */
+ CMD_EOF /* No commands remain. */
};
extern int pgm_state;
diff -urpN -X pat reorg2/src/language/utilities/title.c
reorg3/src/language/utilities/title.c
--- reorg2/src/language/utilities/title.c 2006-02-04 22:28:15.000000000
-0800
+++ reorg3/src/language/utilities/title.c 2006-02-05 14:09:56.000000000
-0800
@@ -25,7 +25,6 @@
#include "dictionary.h"
#include "pspp-error.h"
#include "lexer.h"
-#include "main.h"
#include "output.h"
#include "start-date.h"
#include "var.h"
diff -urpN -X pat reorg2/src/main.c reorg3/src/main.c
--- reorg2/src/main.c 2006-02-01 19:33:40.000000000 -0800
+++ reorg3/src/main.c 2006-02-05 14:27:05.000000000 -0800
@@ -63,19 +63,12 @@ static void fpu_init (void);
static void handle_error (int code);
static int execute_command (void);
-/* Whether FINISH. has been executed. */
-int finished;
-
/* If a segfault happens, issue a message to that effect and halt */
void bug_handler(int sig);
/* Handle quit/term/int signals */
void interrupt_handler(int sig);
-/* Whether we're dropping down to interactive mode immediately because
- we hit end-of-file unexpectedly (or whatever). */
-int start_interactive;
-
/* Program entry point. */
int
main (int argc, char **argv)
@@ -99,17 +92,24 @@ main (int argc, char **argv)
default_dict = dict_create ();
- parse_command_line (argc, argv);
- outp_read_devices ();
-
- lex_init ();
-
- while (!finished)
+ if (parse_command_line (argc, argv))
{
- err_check_count ();
- handle_error (execute_command ());
- }
+ outp_read_devices ();
+ lex_init ();
+ for (;;)
+ {
+ int retval;
+
+ err_check_count ();
+
+ retval = execute_command ();
+ if (retval == CMD_EOF)
+ break;
+ handle_error (retval);
+ }
+ }
+
terminate (err_error_count == 0);
abort ();
}
diff -urpN -X pat reorg2/src/main.h reorg3/src/main.h
--- reorg2/src/main.h 2006-02-01 19:33:36.000000000 -0800
+++ reorg3/src/main.h 2006-02-05 14:14:17.000000000 -0800
@@ -22,9 +22,6 @@
#include <stdbool.h>
-extern int start_interactive;
-extern int finished;
-
void terminate (bool success);
#endif /* main.h */
diff -urpN -X pat reorg2/src/output/ascii.c reorg3/src/output/ascii.c
--- reorg2/src/output/ascii.c 2006-02-04 22:28:15.000000000 -0800
+++ reorg3/src/output/ascii.c 2006-02-05 14:09:56.000000000 -0800
@@ -26,7 +26,6 @@
#include "alloc.h"
#include "pspp-error.h"
#include "filename.h"
-#include "main.h"
#include "misc.h"
#include "output.h"
#include "pool.h"
diff -urpN -X pat reorg2/src/output/postscript.c reorg3/src/output/postscript.c
--- reorg2/src/output/postscript.c 2006-02-04 22:27:40.000000000 -0800
+++ reorg3/src/output/postscript.c 2006-02-05 14:09:56.000000000 -0800
@@ -41,7 +41,6 @@
#include "getl.h"
#include "getline.h"
#include "hash.h"
-#include "main.h"
#include "misc.h"
#include "output.h"
#include "som.h"
diff -urpN -X pat reorg2/src/ui/cmdline.c reorg3/src/ui/cmdline.c
--- reorg2/src/ui/cmdline.c 2006-02-02 21:20:00.000000000 -0800
+++ reorg3/src/ui/cmdline.c 2006-02-05 14:26:26.000000000 -0800
@@ -51,8 +51,9 @@ static void usage (void);
char *subst_vars (char *);
/* Parses the command line specified by ARGC and ARGV as received by
- main(). */
-void
+ main(). Returns true if normal execution should proceed,
+ false if the command-line indicates that PSPP should exit. */
+bool
parse_command_line (int argc, char **argv)
{
static struct option long_options[] =
@@ -102,8 +103,8 @@ parse_command_line (int argc, char **arg
set_algorithm(ENHANCED);
else
{
- usage();
- assert(0);
+ usage ();
+ return false;
}
break;
@@ -114,8 +115,8 @@ parse_command_line (int argc, char **arg
set_syntax(ENHANCED);
else
{
- usage();
- assert(0);
+ usage ();
+ return false;
}
break;
@@ -149,7 +150,7 @@ parse_command_line (int argc, char **arg
break;
case 'h':
usage ();
- assert (0);
+ return false;
case 'i':
getl_interactive = 2;
break;
@@ -161,7 +162,7 @@ parse_command_line (int argc, char **arg
break;
case 'l':
outp_list_classes ();
- terminate (true);
+ return false;
case 'n':
printf (_("%s is not yet implemented."),"-n");
putchar('\n');
@@ -190,14 +191,14 @@ parse_command_line (int argc, char **arg
case 'V':
puts (version);
puts (legal);
- terminate (true);
+ return false;
case 'T':
force_long_view ();
set_testing_mode (true);
break;
case '?':
usage ();
- assert (0);
+ return false;
case 0:
break;
default:
@@ -212,8 +213,11 @@ parse_command_line (int argc, char **arg
if (!strcmp (argv[i], "+"))
{
separate = 0;
- if (++i >= argc)
- usage ();
+ if (++i >= argc)
+ {
+ usage ();
+ return false;
+ }
}
else if (strchr (argv[i], '='))
{
@@ -237,6 +241,8 @@ parse_command_line (int argc, char **arg
free (pspprc_fn);
}
+
+ return true;
}
/* Message that describes PSPP command-line syntax. */
@@ -281,13 +287,11 @@ N_("PSPP, a program for statistical anal
/* Message that describes PSPP command-line syntax, continued. */
static const char post_syntax_message[] = N_("\nReport bugs to <%s>.\n");
-/* Writes a syntax description to stdout and terminates. */
+/* Writes a syntax description to stdout. */
static void
usage (void)
{
printf (gettext (pre_syntax_message), program_name);
outp_list_classes ();
printf (gettext (post_syntax_message), PACKAGE_BUGREPORT);
-
- terminate (true);
}
diff -urpN -X pat reorg2/src/ui/cmdline.h reorg3/src/ui/cmdline.h
--- reorg2/src/ui/cmdline.h 2006-02-01 19:33:35.000000000 -0800
+++ reorg3/src/ui/cmdline.h 2006-02-05 14:27:13.000000000 -0800
@@ -20,6 +20,8 @@
#if !INCLUDED_CMDLINE_H
#define INCLUDED_CMDLINE_H 1
-void parse_command_line (int argc, char **argv);
+#include <stdbool.h>
+
+bool parse_command_line (int argc, char **argv);
#endif /* cmdline.h */
--
"Note that nobody reads every post in linux-kernel. In fact, nobody who
expects to have time left over to actually do any real kernel work will
read even half. Except Alan Cox, but he's actually not human, but about
a thousand gnomes working in under-ground caves in Swansea." --Linus
- Re: Directory restructuring, (continued)
- Re: Directory restructuring, John Darrington, 2006/02/03
- Re: Directory restructuring, Ben Pfaff, 2006/02/04
- Re: Directory restructuring, John Darrington, 2006/02/04
- Re: Directory restructuring, Ben Pfaff, 2006/02/04
- Re: Directory restructuring, John Darrington, 2006/02/04
- Re: Directory restructuring, Ben Pfaff, 2006/02/04
- Re: Directory restructuring, John Darrington, 2006/02/05
- Re: Directory restructuring, Ben Pfaff, 2006/02/05
- Re: Directory restructuring, John Darrington, 2006/02/05
- Re: Directory restructuring, Ben Pfaff, 2006/02/05
- Re: Directory restructuring,
Ben Pfaff <=
- Re: Directory restructuring, Ben Pfaff, 2006/02/05
- Re: Directory restructuring, John Darrington, 2006/02/05
- Re: Directory restructuring, Ben Pfaff, 2006/02/05
- Re: Directory restructuring, Ben Pfaff, 2006/02/05
- Re: Directory restructuring, Ben Pfaff, 2006/02/05
- Re: Directory restructuring, Ben Pfaff, 2006/02/05
- Re: Directory restructuring, John Darrington, 2006/02/05