Author: kjs
Date: Sat Mar 31 04:04:28 2007
New Revision: 17880

Modified:
   trunk/compilers/pirc/src/pirmain.c   (contents, props changed)

Log:
compilers/pirc:
* add commandline switches for selecting output.
* do '-r' for PIR output, '-p' for PAST output
* (this is a simple solution for now)

Modified: trunk/compilers/pirc/src/pirmain.c
==============================================================================
--- trunk/compilers/pirc/src/pirmain.c  (original)
+++ trunk/compilers/pirc/src/pirmain.c  Sat Mar 31 04:04:28 2007
@@ -1,47 +1,126 @@
+/*
+
+=head1 NAME
+
+pirmain.c - Main file for PIR Compiler PIRC.
+
+=cut
+
+*/
 #include <stdio.h>
 #include <stdlib.h>
 #include "pirparser.h"
-#include "pirout.h"    /* for PIR output    */
-#include "pastout.h"   /* for PAST output   */
+#include "pirout.h"    /* for PIR output  */
+#include "pastout.h"   /* for PAST output */
+#include "pirvtable.h" /* vtable api      */
+
+
+
+
+/* command argument switches */
+typedef enum pirc_flags {
+        PIRC_VERBOSE     = 0,
+        PIRC_DEBUG       = 1,
+
+} pirc_flag;
 
 
 /* define output type: what kind of semantic routines
- * should be called in the parser? 
+ * should be called in the parser?
  */
 typedef enum outputtypes {
-               OUTPUT_NONE,    /* do nothing  */
-               OUTPUT_PIR,     /* output PIR  */
-               OUTPUT_PAST     /* output PAST */
-               
-} outputtype; 
+        OUTPUT_NONE,    /* do nothing  */
+        OUTPUT_PIR,     /* output PIR  */
+        OUTPUT_PAST     /* output PAST */
+/* future: OUTPUT_PBC  for outputting PBC files */
 
+} outputtype;
 
 
+/*
 
-/* main()
- *
- * Entry function for the PIR Compiler 'PIRC'
- *
- */
+=head1 FUNCTIONS
+
+=over 4
+
+=item print_help()
+
+=cut
+
+*/
+static void
+print_help(void) {
+    fprintf(stderr, "Usage: pirc [options] <file>\n");
+    fprintf(stderr, "\toptions:\n");
+    fprintf(stderr, "\t-d  debug messages (not implemented yet)\n");
+    fprintf(stderr, "\t-h  print this help message\n");
+    fprintf(stderr, "\t-v  verbose (not implemented yet)\n");
+    fprintf(stderr, "\t-r  print PIR output\n");
+    fprintf(stderr, "\t-p  print PAST output\n");
+    fprintf(stderr, "\n");
+}
+
+
+/*
+
+=item main()
+
+Entry function for the PIR Compiler 'PIRC'
+
+=cut
+
+*/
 int
 main(int argc, char **argv) {
+    struct parser_state *p = NULL;        /* create a parser */
+    pirvtable *vtable      = NULL;        /* create a vtable for semantic 
actions */
+    int flags              = 0;           /* argument parsing */
+    outputtype output      = OUTPUT_NONE; /* what kind of output? */
+
+    /* skip program name */
+    argv++;
+    argc--;
+
+    /* process options */
+    while (argc-- > 0) {
+        char opt;
+
+        if (argv[0][0] != '-') break; /* stop if there's only a '-' */
+        else opt = argv[0][1];   /* get the option letter */
+
+        switch (opt) {
+            case 'd':
+                flags |= PIRC_DEBUG;
+                break;
+            case 'h':
+                print_help();
+                break;
+            case 'v':
+                flags |= PIRC_VERBOSE;
+                break;
+            case 'p':
+                output = OUTPUT_PAST;
+                break;
+            case 'r':
+                output = OUTPUT_PIR;
+                break;
+            default:
+                fprintf(stderr, "Unknown option: '%c'\n", opt);
+                print_help();
+                exit(1);
+        }
+        /* get next commandline argument */
+        argv++;
+        argc--;
+    }
+
 
-    struct parser_state *p = NULL;
-    pirvtable *vtable      = NULL;
-    
-    /* make this a commandline switch */
-    int output;
-    
-    //output = OUTPUT_PAST;    
-    output = OUTPUT_PIR;
-    
-    
-    if (argc < 2) {
-        fprintf(stderr, "usage: %s <file>\n", argv[0]);
+    if (argv[0] == NULL) {
+        fprintf(stderr, "No file specified\n");
         exit(1);
     }
 
-    
+    /* create a vtable based on the desired output */
     switch (output) {
         case OUTPUT_NONE:
             /* just create an empty vtable, the default implementation does 
nothing */
@@ -57,10 +136,10 @@
             fprintf(stderr, "Unknown output type specified\n");
             exit(1);
     }
-    
-    
+
+
     /* create a new parser, specifying the file name and the vtable */
-    p = new_parser(argv[1], vtable);
+    p = new_parser(argv[0], vtable);
 
     /* start parsing */
     TOP(p);
@@ -78,9 +157,22 @@
     return 0;
 }
 
+
+
+/*
+
+=back
+
+=cut
+
+*/
+
 /*
  * Local variables:
  *   c-file-style: "parrot"
  * End:
  * vim: expandtab shiftwidth=4:
  */
+
+
+

Reply via email to