2 * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 * Copyright (c) 1991-1998, 2000 University of Maryland at College Park
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of U.M. not be used in advertising or
11 * publicity pertaining to distribution of the software without specific,
12 * written prior permission. U.M. makes no representations about the
13 * suitability of this software for any purpose. It is provided "as is"
14 * without express or implied warranty.
16 * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
18 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 * Authors: the Amanda Development Team. Its members are listed in a
24 * file named AUTHORS, in the root directory of this distribution.
29 * parser for amrecover interactive language
33 #include "amrecover.h"
35 #define DATE_ALLOC_SIZE sizeof("YYYY-MM-DD-HH-MM-SS") /* includes null */
37 void yyerror(char *s);
38 extern int yylex(void);
50 /* literal keyword tokens */
52 %token LISTHOST LISTDISK LISTPROPERTY
53 %token SETHOST SETDISK SETDATE SETTAPE SETMODE SETDEVICE SETPROPERTY
54 %token CD CDX QUIT DHIST LS ADD ADDX EXTRACT DASH_H
55 %token LIST DELETE DELETEX PWD CLEAR HELP LCD LPWD MODE SMB TAR
56 %token APPEND PRIORITY SETTRANSLATE
61 %token <strval> STRING
83 LISTHOST NL { list_host(); }
84 | LISTHOST invalid_string { yyerror("Invalid argument"); }
85 | LISTDISK STRING NL { list_disk($2); amfree($2); }
86 | LISTDISK NL { list_disk(NULL); }
87 | LISTDISK STRING invalid_string { yyerror("Invalid argument"); amfree($2); }
88 | LISTPROPERTY NL { list_property(); }
89 | LISTPROPERTY invalid_string { yyerror("Invalid argument"); }
90 | SETTRANSLATE NL { set_translate(NULL); }
91 | SETTRANSLATE STRING invalid_string NL { yyerror("Invalid argument"); }
92 | SETTRANSLATE STRING NL { set_translate($2); amfree($2); }
93 | SETHOST STRING NL { set_host($2); amfree($2); }
94 | SETHOST STRING invalid_string { yyerror("Invalid argument"); amfree($2); }
95 | SETHOST NL { yyerror("Argument required"); }
96 | SETDISK STRING STRING NL { set_disk($2, $3); amfree($2); amfree($3); }
97 | SETDISK STRING NL { set_disk($2, NULL); amfree($2); }
98 | SETDISK STRING STRING invalid_string { yyerror("Invalid argument"); amfree($2); amfree($3); }
99 | SETDISK { yyerror("Argument required"); }
100 | SETTAPE STRING NL { set_tape($2); amfree($2); }
101 | SETTAPE NL { set_tape("default"); }
102 | SETTAPE STRING invalid_string { yyerror("Invalid argument"); amfree($2); }
103 | SETDEVICE STRING NL { set_device(NULL, $2); amfree($2); }
104 | SETDEVICE DASH_H STRING STRING NL { set_device($3, $4); amfree($3); amfree($4); }
105 | SETDEVICE NL { set_device(NULL, NULL); }
106 | SETDEVICE STRING invalid_string { yyerror("Invalid argument"); amfree($2); }
107 | SETDEVICE DASH_H STRING NL { yyerror("Invalid argument"); amfree($3); }
108 | SETDEVICE DASH_H STRING STRING invalid_string { yyerror("Invalid argument"); amfree($3); amfree($4); }
109 | SETPROPERTY STRING property_value { set_property_name($2, 0); amfree($2); }
110 | SETPROPERTY APPEND STRING property_value { set_property_name($3, 1); amfree($3); }
111 | SETPROPERTY PRIORITY STRING property_value { set_property_name($3, 0); amfree($3); }
112 | SETPROPERTY APPEND PRIORITY STRING property_value { set_property_name($4, 1); amfree($4); }
113 | SETPROPERTY NL { yyerror("Invalid argument"); }
114 | SETPROPERTY APPEND NL { yyerror("Invalid argument"); }
115 | SETPROPERTY PRIORITY NL { yyerror("Invalid argument"); }
116 | SETPROPERTY APPEND PRIORITY NL { yyerror("Invalid argument"); }
117 | CD STRING NL { cd_glob($2, 1); amfree($2); }
118 | CD STRING invalid_string { yyerror("Invalid argument"); }
119 | CD NL { yyerror("Argument required"); }
120 | CDX STRING NL { cd_regex($2, 1); amfree($2); }
121 | CDX STRING invalid_string { yyerror("Invalid argument"); amfree($2); }
122 | CDX NL { yyerror("Argument required"); }
123 | SETMODE SMB NL { set_mode(SAMBA_SMBCLIENT); }
124 | SETMODE TAR NL { set_mode(SAMBA_TAR); }
125 | SETMODE SMB invalid_string { yyerror("Invalid argument"); }
126 | SETMODE TAR invalid_string { yyerror("Invalid argument"); }
127 | SETMODE invalid_string { yyerror("Invalid argument"); }
128 | SETMODE NL { yyerror("Argument required"); }
135 int y=2000, m=0, d=1, h=0, mi=0, s=0;
139 now = time((time_t *)NULL);
146 if (sscanf(mydate, "---%d", &d) == 1 ||
147 sscanf(mydate, "--%d-%d", &m, &d) == 2 ||
148 sscanf(mydate, "%d-%d-%d-%d-%d-%d", &y, &m, &d, &h, &mi, &s) >= 3) {
151 } else if (y < 100) {
154 if(y < 1000 || y > 9999) {
155 printf("invalid year");
156 } else if(m < 1 || m > 12) {
157 printf("invalid month");
158 } else if(d < 1 || d > 31) {
159 printf("invalid day");
160 } else if(h < 0 || h > 24) {
161 printf("invalid hour");
162 } else if(mi < 0 || mi > 59) {
163 printf("invalid minute");
164 } else if(s < 0 || s > 59) {
165 printf("invalid second");
167 char result[DATE_ALLOC_SIZE];
168 if (h == 0 && mi == 0 && s == 0)
169 g_snprintf(result, DATE_ALLOC_SIZE, "%04d-%02d-%02d", y, m, d);
171 g_snprintf(result, DATE_ALLOC_SIZE, "%04d-%02d-%02d-%02d-%02d-%02d", y, m, d, h, mi, s);
175 printf("Invalid date: %s\n", mydate);
178 | SETDATE NL { yyerror("Argument required"); }
179 | SETDATE STRING invalid_string { yyerror("Invalid argument"); }
183 DHIST NL { list_disk_history(); }
184 | DHIST invalid_string { yyerror("Invalid argument"); }
185 | LS NL { list_directory(); }
186 | LS invalid_string { yyerror("Invalid argument"); }
187 | LIST STRING NL { display_extract_list($2); amfree($2); }
188 | LIST NL { display_extract_list(NULL); }
189 | LIST STRING invalid_string { yyerror("Invalid argument"); }
190 | PWD NL { show_directory(); }
191 | PWD invalid_string { yyerror("Invalid argument"); }
192 | CLEAR NL { clear_extract_list(); }
193 | CLEAR invalid_string { yyerror("Invalid argument"); }
194 | MODE NL { show_mode (); }
195 | MODE invalid_string { yyerror("Invalid argument"); }
200 | QUIT invalid_string { yyerror("Invalid argument"); }
208 add_path STRING { add_glob($2); amfree($2); }
209 | STRING { add_glob($1); amfree($1); }
217 addx_path STRING { add_regex($2); amfree($2); }
218 | STRING { add_regex($1); amfree($1); }
222 DELETE delete_path NL
226 delete_path STRING { delete_glob($2); amfree($2); }
227 | STRING { delete_glob($1); amfree($1); }
231 DELETEX deletex_path NL
235 deletex_path STRING { delete_regex($2); amfree($2); }
236 | STRING { delete_regex($1); amfree($1); }
240 LPWD NL { char * buf= g_get_current_dir(); puts(buf); free(buf); }
241 | LPWD invalid_string { yyerror("Invalid argument"); }
246 | LCD STRING invalid_string { yyerror("Invalid argument"); }
247 | LCD NL { yyerror("Argument required"); }
251 HELP NL { help_list(); }
252 | HELP invalid_string { yyerror("Invalid argument"); }
256 EXTRACT NL { extract_files(); }
257 | EXTRACT invalid_string { yyerror("Invalid argument"); }
261 STRING bogus_string {
262 char * errstr = vstralloc("Invalid command: ", $1, NULL);
266 } /* Quiets compiler warnings about unused label */
270 STRING property_value { add_property_value($1); amfree( $1); }
275 STRING bogus_string { amfree($1); }
279 STRING bogus_string { amfree($1); }
282 /* ADDITIONAL C CODE */