]> www.ginac.de Git - ginac.git/commitdiff
- ginsh can handle multiple input files which are specified on the command line
authorChristian Bauer <Christian.Bauer@uni-mainz.de>
Tue, 16 Nov 1999 18:05:11 +0000 (18:05 +0000)
committerChristian Bauer <Christian.Bauer@uni-mainz.de>
Tue, 16 Nov 1999 18:05:11 +0000 (18:05 +0000)
ginsh/ginsh.1
ginsh/ginsh.h
ginsh/ginsh_lexer.ll
ginsh/ginsh_parser.yy

index 35abed2e4764a65bd3ee6db62f8b0cd47e32fe4a..fbe21f4f46db5a04a9f5e55f92ec1d4367a34c4d 100644 (file)
@@ -3,6 +3,7 @@
 ginsh \- GiNaC Interactive Shell
 .SH SYNPOSIS
 .B ginsh
+.RI [ file\&... ]
 .SH DESCRIPTION
 .B ginsh
 is an interactive frontend for the GiNaC symbolic computation framework.
@@ -24,12 +25,15 @@ mathematical operators like
 .BR + " and  " * ,
 and functions (e.g.
 .BR sin " or " normal ).
-ginsh will evaluate the expression and print the result to stdout. Every
-input expression must be terminated by a semicolon
-.RB ( ; ),
-and it is possible to enter multiple expressions on one line. Whitespace
-(spaces, tabs, newlines) can be applied freely between tokens. To quit ginsh,
-enter
+Every input expression must be terminated with either a semicolon
+.RB ( ; )
+or a colon
+.RB ( : ).
+If terminated with a semicolon, ginsh will evaluate the expression and print
+the result to stdout. If terminated with a colon, ginsh will only evaluate the
+expression but not print the result. It is possible to enter multiple
+expressions on one line. Whitespace (spaces, tabs, newlines) can be applied
+freely between tokens. To quit ginsh, enter
 .BR quit " or " exit ,
 or type an EOF (Ctrl-D) at the prompt.
 .SS NUMBERS
index 3c225cd36312ce77443b3d6bb797398968cc1faa..fcd00390d9c7dc64d9de3610cab8342992a46249 100644 (file)
@@ -22,7 +22,7 @@
 #ifndef GINSH_H
 #define GINSH_H
 
-// yacc semantic type
+// yacc stack type
 #define YYSTYPE ex
 
 // lex functions/variables
@@ -33,14 +33,14 @@ extern char *yytext;
 #else
 extern char yytext[];
 #endif
+extern FILE *yyin;
+
+// List of input files to be processed
+extern int num_files;
+extern char **file_list;
 
 // Table of all used symbols
 typedef map<string, symbol> sym_tab;
 extern sym_tab syms;
 
-// Prototypes for missing functions
-#ifndef HAVE_STRDUP
-extern char *strdup(const char *s);
-#endif
-
 #endif
index 51076f9ace5fd54a9d7b28cc3e598257e0712f47..42a432b8afbb0c3ed257df0c1a05aa879bc7a628 100644 (file)
@@ -171,8 +171,27 @@ static int ginsh_input(char *buf, int max_size)
        return result;
 }
 
-// Scanner terminates on EOF
+// List of input files to be processed
+int num_files = 0;
+char **file_list = NULL;
+
+// EOF encountered, connect to next file. If this was the last file,
+// connect to stdin. If this was stdin, terminate the scanner.
 int yywrap()
 {
-       return 1;
+       if (yyin == stdin)
+               return 1;
+
+       fclose(yyin);
+       if (num_files) {
+               yyin = fopen(*file_list, "r");
+               if (yyin == NULL) {
+                       cerr << "Can't open " << *file_list << endl;
+                       return 1;
+               }
+               num_files--;
+               file_list++;
+       } else
+               yyin = stdin;
+       return 0;
 }
index 67d836060c3fdd93988570df40001def805e090b..dc282383a405876e30eecde9275e02be2ac22c45 100644 (file)
@@ -126,6 +126,15 @@ line       : ';'
                                YYERROR;
                        }
                }
+       | exp ':'
+               {
+                       try {
+                               push($1);
+                       } catch (exception &e) {
+                               cerr << e.what() << endl;
+                               YYERROR;
+                       }
+               }
        | T_PRINT '(' exp ')' ';'
                {
                        try {
@@ -146,6 +155,7 @@ line        : ';'
                        cout << " out of a possible 350.\n";
                }
        | error ';'             {yyclearin; yyerrok;}
+       | error ':'             {yyclearin; yyerrok;}
        ;
 
 exp    : T_NUMBER              {$$ = $1;}
@@ -658,6 +668,19 @@ int main(int argc, char **argv)
        orig_completion_append_character = rl_completion_append_character;
        orig_basic_word_break_characters = rl_basic_word_break_characters;
 
+       // Init input file list, open first file
+       num_files = argc - 1;
+       file_list = argv + 1;
+       if (num_files) {
+               yyin = fopen(*file_list, "r");
+               if (yyin == NULL) {
+                       cerr << "Can't open " << *file_list << endl;
+                       exit(1);
+               }
+               num_files--;
+               file_list++;
+       }
+
        // Parse input, catch all remaining exceptions
        int result;
 again: try {