Imported Upstream version 3.1.0
[debian/amanda] / recover-src / uparse.y
index 6be3562f6914ca8504aebfe9686854bcfd59aeaa..1562e9c7a7fc70dd09289dcec0e731ea46b02393 100644 (file)
@@ -24,7 +24,7 @@
  * file named AUTHORS, in the root directory of this distribution.
  */
 /*
- * $Id: uparse.y,v 1.13 2006/05/25 01:47:14 johnfranks Exp $
+ * $Id$
  *
  * parser for amrecover interactive language
  */
 #include "amanda.h"
 #include "amrecover.h"
 
+#define DATE_ALLOC_SIZE sizeof("YYYY-MM-DD-HH-MM-SS")   /* includes null */
+
 void           yyerror(char *s);
 extern int     yylex(void);
 extern char *  yytext;
-
 %}
 
 /* DECLARATIONS */
@@ -48,14 +49,16 @@ extern char *       yytext;
 
        /* literal keyword tokens */
 
-%token LISTHOST LISTDISK SETHOST SETDISK SETDATE SETTAPE SETMODE
-%token CD CDX QUIT DHIST LS ADD ADDX EXTRACT
+%token LISTHOST LISTDISK LISTPROPERTY
+%token SETHOST SETDISK SETDATE SETTAPE SETMODE SETDEVICE SETPROPERTY
+%token CD CDX QUIT DHIST LS ADD ADDX EXTRACT DASH_H
 %token LIST DELETE DELETEX PWD CLEAR HELP LCD LPWD MODE SMB TAR
+%token APPEND PRIORITY
+%token NL
 
         /* typed tokens */
 
-%token <strval> PATH
-%token <strval> DATE
+%token <strval> STRING
 
 
 /* GRAMMAR */
@@ -63,6 +66,7 @@ extern char * yytext;
 
 ucommand:
        set_command
+  |     setdate_command
   |     display_command
   |     quit_command
   |     add_command
@@ -72,104 +76,206 @@ ucommand:
   |     local_command
   |    help_command
   |     extract_command
-  |     {
-           char * errstr = vstralloc("Invalid command: ", yytext, NULL);
-           yyerror(errstr);
-           amfree(errstr);
-           YYERROR;
-       } /* Quiets compiler warnings about unused label */
+  |     invalid_command
   ;
 
 set_command:
-       LISTHOST { list_host(); }
-  |    LISTDISK PATH { list_disk($2); amfree($2); }
-  |    LISTDISK { list_disk(NULL); }
-  |    SETDATE DATE { set_date($2); amfree($2); }
-  |     SETHOST PATH { set_host($2); amfree($2); }
-  |     SETDISK PATH PATH { set_disk($2, $3); amfree($2); amfree($3); }
-  |     SETDISK PATH { set_disk($2, NULL); amfree($2); }
-  |     SETTAPE PATH { set_tape($2); amfree($2); }
-  |     SETTAPE { set_tape(""); }
-  |     CD PATH { cd_glob($2); amfree($2); }
-  |     CDX PATH { cd_regex($2); amfree($2); }
-  |     SETMODE SMB {
-#ifdef SAMBA_CLIENT
-                        set_mode(SAMBA_SMBCLIENT);
-#endif /* SAMBA_CLIENT */
-                    }
-  |     SETMODE TAR {
-#ifdef SAMBA_CLIENT
-                        set_mode(SAMBA_TAR);
-#endif /* SAMBA_CLIENT */
-                    }
+       LISTHOST NL { list_host(); }
+  |    LISTHOST invalid_string { yyerror("Invalid argument"); }
+  |    LISTDISK STRING NL { list_disk($2); amfree($2); }
+  |    LISTDISK NL { list_disk(NULL); }
+  |    LISTDISK STRING invalid_string { yyerror("Invalid argument"); amfree($2); }
+  |    LISTPROPERTY NL { list_property(); }
+  |    LISTPROPERTY invalid_string { yyerror("Invalid argument"); }
+  |    SETHOST STRING NL { set_host($2); amfree($2); }
+  |    SETHOST STRING invalid_string { yyerror("Invalid argument"); amfree($2); }
+  |    SETHOST NL { yyerror("Argument required"); }
+  |    SETDISK STRING STRING NL { set_disk($2, $3); amfree($2); amfree($3); }
+  |    SETDISK STRING NL { set_disk($2, NULL); amfree($2); }
+  |    SETDISK STRING STRING invalid_string { yyerror("Invalid argument"); amfree($2); amfree($3); }
+  |    SETDISK { yyerror("Argument required"); }
+  |    SETTAPE STRING NL { set_tape($2); amfree($2); }
+  |    SETTAPE NL { set_tape("default"); }
+  |    SETTAPE STRING invalid_string { yyerror("Invalid argument"); amfree($2); }
+  |    SETDEVICE STRING NL { set_device(NULL, $2); amfree($2); }
+  |    SETDEVICE DASH_H STRING STRING NL { set_device($3, $4); amfree($3); amfree($4);  }
+  |    SETDEVICE NL { set_device(NULL, NULL); }
+  |    SETDEVICE STRING invalid_string { yyerror("Invalid argument"); amfree($2); }
+  |    SETDEVICE DASH_H STRING NL { yyerror("Invalid argument"); amfree($3); }
+  |    SETDEVICE DASH_H STRING STRING invalid_string { yyerror("Invalid argument"); amfree($3); amfree($4); }
+  |    SETPROPERTY STRING property_value { set_property_name($2, 0); amfree($2); }
+  |    SETPROPERTY APPEND STRING property_value { set_property_name($3, 1); amfree($3); }
+  |    SETPROPERTY PRIORITY STRING property_value { set_property_name($3, 0); amfree($3); }
+  |    SETPROPERTY APPEND PRIORITY STRING property_value { set_property_name($4, 1); amfree($4); }
+  |    SETPROPERTY NL { yyerror("Invalid argument"); }
+  |    SETPROPERTY APPEND NL { yyerror("Invalid argument"); }
+  |    SETPROPERTY PRIORITY NL { yyerror("Invalid argument"); }
+  |    SETPROPERTY APPEND PRIORITY NL { yyerror("Invalid argument"); }
+  |    CD STRING NL { cd_glob($2, 1); amfree($2); }
+  |    CD STRING invalid_string { yyerror("Invalid argument"); }
+  |    CD NL { yyerror("Argument required"); }
+  |     CDX STRING NL { cd_regex($2, 1); amfree($2); }
+  |    CDX STRING invalid_string { yyerror("Invalid argument"); amfree($2); }
+  |    CDX NL { yyerror("Argument required"); }
+  |    SETMODE SMB NL { set_mode(SAMBA_SMBCLIENT); }
+  |    SETMODE TAR NL { set_mode(SAMBA_TAR); }
+  |    SETMODE SMB invalid_string { yyerror("Invalid argument"); }
+  |    SETMODE TAR invalid_string { yyerror("Invalid argument"); }
+  |    SETMODE invalid_string { yyerror("Invalid argument"); }
+  |    SETMODE NL { yyerror("Argument required"); }
+  ;
+
+setdate_command:
+       SETDATE STRING NL {
+                       time_t now;
+                       struct tm *t;
+                       int y=2000, m=0, d=1, h=0, mi=0, s=0;
+                       int ret;
+                       char *mydate = $2;
+
+                       now = time((time_t *)NULL);
+                       t = localtime(&now);
+                       if (t) {
+                           y = 1900+t->tm_year;
+                           m = t->tm_mon+1;
+                           d = t->tm_mday;
+                       }
+                       if (sscanf(mydate, "---%d", &d) == 1 ||
+                           sscanf(mydate, "--%d-%d", &m, &d) == 2 ||
+                           sscanf(mydate, "%d-%d-%d-%d-%d-%d", &y, &m, &d, &h, &mi, &s) >= 3) {
+                           if (y < 70) {
+                               y += 2000;
+                           } else if (y < 100) {
+                               y += 1900;
+                           }
+                           if(y < 1000 || y > 9999) {
+                               printf("invalid year");
+                           } else if(m < 1 || m > 12) {
+                               printf("invalid month");
+                           } else if(d < 1 || d > 31) {
+                               printf("invalid day");
+                           } else if(h < 0 || h > 24) {
+                               printf("invalid hour");
+                           } else if(mi < 0 || mi > 59) {
+                               printf("invalid minute");
+                           } else if(s < 0 || s > 59) {
+                               printf("invalid second");
+                           } else {
+                               char result[DATE_ALLOC_SIZE];
+                               if (h == 0 && mi == 0 && s == 0)
+                                   g_snprintf(result, DATE_ALLOC_SIZE, "%04d-%02d-%02d", y, m, d);
+                               else
+                                   g_snprintf(result, DATE_ALLOC_SIZE, "%04d-%02d-%02d-%02d-%02d-%02d", y, m, d, h, mi, s);
+                               set_date(result);
+                           }
+                       } else {
+                           printf("Invalid date: %s\n", mydate);
+                       }
+                    }
+  |    SETDATE NL { yyerror("Argument required"); }
+  |    SETDATE STRING invalid_string { yyerror("Invalid argument"); }
   ;
 
 display_command:
-       DHIST { list_disk_history(); }
-  |     LS { list_directory(); }
-  |     LIST PATH { display_extract_list($2); amfree($2); }
-  |     LIST { display_extract_list(NULL); }
-  |     PWD { show_directory(); }
-  |     CLEAR { clear_extract_list(); }    
-  |     MODE { show_mode (); }
+       DHIST NL { list_disk_history(); }
+  |    DHIST invalid_string { yyerror("Invalid argument"); }
+  |    LS NL { list_directory(); }
+  |    LS invalid_string { yyerror("Invalid argument"); }
+  |    LIST STRING NL { display_extract_list($2); amfree($2); }
+  |    LIST NL { display_extract_list(NULL); }
+  |    LIST STRING invalid_string { yyerror("Invalid argument"); }
+  |    PWD NL { show_directory(); }
+  |    PWD invalid_string { yyerror("Invalid argument"); }
+  |    CLEAR NL { clear_extract_list(); }
+  |    CLEAR invalid_string { yyerror("Invalid argument"); }
+  |    MODE NL { show_mode (); }
+  |    MODE invalid_string { yyerror("Invalid argument"); }
   ;
 
 quit_command:
-       QUIT { quit(); }
+       QUIT NL { quit(); }
+  |    QUIT invalid_string { yyerror("Invalid argument"); }
   ;
 
 add_command:
-       ADD add_path
+       ADD add_path NL
   ;
 
 add_path:
-       add_path PATH { add_glob($2); amfree($2); }
-  |     PATH { add_glob($1); amfree($1); }
+       add_path STRING { add_glob($2); amfree($2); }
+  |    STRING { add_glob($1); amfree($1); }
   ;
 
 addx_command:
-       ADDX addx_path
+       ADDX addx_path NL
   ;
 
 addx_path:
-       addx_path PATH { add_regex($2); amfree($2); }
-  |     PATH { add_regex($1); amfree($1); }
+       addx_path STRING { add_regex($2); amfree($2); }
+  |    STRING { add_regex($1); amfree($1); }
   ;
 
 delete_command:
-       DELETE delete_path
+       DELETE delete_path NL
   ;
 
 delete_path:
-       delete_path PATH { delete_glob($2); amfree($2); }
-  |     PATH { delete_glob($1); amfree($1); }
+       delete_path STRING { delete_glob($2); amfree($2); }
+  |    STRING { delete_glob($1); amfree($1); }
   ;
 
 deletex_command:
-       DELETEX deletex_path
+       DELETEX deletex_path NL
   ;
 
 deletex_path:
-       deletex_path PATH { delete_regex($2); amfree($2); }
-  |     PATH { delete_regex($1); amfree($1); }
+       deletex_path STRING { delete_regex($2); amfree($2); }
+  |    STRING { delete_regex($1); amfree($1); }
   ;
 
 local_command:
-       LPWD { char buf[STR_SIZE]; puts(getcwd(buf, sizeof(buf))); }
-  |     LCD PATH {
+       LPWD NL { char * buf= g_get_current_dir(); puts(buf); free(buf); }
+  |    LPWD invalid_string { yyerror("Invalid argument"); }
+  |    LCD STRING NL {
                local_cd($2);
                amfree($2);
        }
+  |    LCD STRING invalid_string { yyerror("Invalid argument"); }
+  |    LCD NL { yyerror("Argument required"); }
   ;
 
 help_command:
-       HELP { help_list(); }
+       HELP NL { help_list(); }
+  |    HELP invalid_string { yyerror("Invalid argument"); }
   ;
 
 extract_command:
-       EXTRACT { extract_files(); }
+       EXTRACT NL { extract_files(); }
+  |    EXTRACT invalid_string { yyerror("Invalid argument"); }
+  ;
+
+invalid_command:
+        STRING bogus_string {
+           char * errstr = vstralloc("Invalid command: ", $1, NULL);
+           yyerror(errstr);
+           amfree(errstr);
+           YYERROR;
+       } /* Quiets compiler warnings about unused label */
   ;
 
+property_value:
+       STRING property_value { add_property_value($1); amfree( $1); }
+  |     NL { ; }
+  ;
+
+invalid_string:
+       STRING bogus_string { amfree($1); }
+  ;
+
+bogus_string:
+        STRING bogus_string { amfree($1); }
+  |    NL { ; }
+
 /* ADDITIONAL C CODE */
 %%
 
@@ -177,5 +283,5 @@ void
 yyerror(
     char *     s)
 {
-       printf("%s\n", s);
+       g_printf("%s\n", s);
 }