2 * amanda, the advanced maryland automatic network disk archiver
3 * Copyright (c) 1991-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.
27 * $Id: uscan.l,v 1.3 2006/07/05 11:15:56 martinea Exp $
29 * lexer for amrecover interactive language
36 * We redefine this here to prevent compiler warning about ignoring fwrite
41 if (fwrite(yytext, (size_t)yyleng, 1, yyout) <= 0) { \
42 yyerror("ECHO failure"); \
48 #define DATE_ALLOC_SIZE sizeof("YYYY-MM-DD-HH-MM-SS") /* includes null */
50 #define YY_DECL int yylex()
51 extern int yylex(void);
53 extern void yyerror(char *s);
54 extern int yyparse(void);
55 static int ll_parse_date(int type, char *text);
56 int process_line(char *line);
62 static char *string_buf = NULL;
68 /* literal keyword tokens */
71 listhost { return LISTHOST; }
72 listdisk { return LISTDISK; }
73 sethost { return SETHOST; }
74 setdisk { return SETDISK; }
75 setdate { return SETDATE; }
76 setmode { return SETMODE; }
77 settape { return SETTAPE; }
82 history { return DHIST; }
87 delete { return DELETE; }
88 deletex { return DELETEX; }
90 clear { return CLEAR; }
95 extract { return EXTRACT; }
104 ---[0-9]+ { return ll_parse_date(1, yytext); }
105 --[0-9]+-[0-9]+ { return ll_parse_date(2, yytext); }
106 [0-9]+-[0-9]+-[0-9]+ { return ll_parse_date(3, yytext); }
107 [0-9]+-[0-9]+-[0-9]+-[0-9]+-[0-9]+-[0-9]+ { return ll_parse_date(4, yytext); }
108 [0-9]+-[0-9]+-[0-9]+-[0-9]+-[0-9]+ { return ll_parse_date(5, yytext); }
111 /* quoted file names */
115 if(string_buf != NULL) {
116 g_printf("ERROR:string_buf != NULL: %s\n",string_buf);
119 strappend(string_buf, yytext);
122 <quotedpath>[^\\\"]+ {
123 strappend(string_buf, yytext);
127 /* escaped character (including quote) */
128 strappend(string_buf, yytext);
131 <quotedpath>\" { /* saw closing quote - all done */
132 strappend(string_buf, yytext);
133 yylval.strval = string_buf;
143 [^[:space:][:cntrl:]"]+ {
144 yylval.strval = stralloc(yytext);
152 [[:space:]]+ ; /* whitespace */
156 /* everything should have been handled by now, so this rule is disabled */
161 . { yyerror("invalid character"); }
174 b = yy_scan_string(line); /* tell lex to scan lineread */
175 result = yyparse(); /* parse lineread and act */
187 int y=2000, m=0, d=1, h=0, mi=0, s=0;
190 now = time((time_t *)NULL);
199 if (sscanf(text, "---%d", &d) != 1) {
200 yyerror("invalid date");
204 if (sscanf(text, "--%d-%d", &m, &d) != 2) {
205 yyerror("invalid date");
209 if (sscanf(text, "%d-%d-%d", &y, &m, &d) != 3) {
210 yyerror("invalid date");
214 if (sscanf(text, "%d-%d-%d-%d-%d-%d", &y, &m, &d, &h, &mi, &s) != 6) {
215 yyerror("invalid date");
219 if (sscanf(text, "%d-%d-%d-%d-%d", &y, &m, &d, &h, &mi) != 5) {
220 yyerror("invalid date");
225 ret = PATH; /* cause a parse error */
231 if(y < 1000 || y > 9999) {
232 yyerror("invalid year");
233 } else if(m < 1 || m > 12) {
234 yyerror("invalid month");
235 } else if(d < 1 || d > 31) {
236 yyerror("invalid day");
237 } else if(h < 0 || h > 24) {
238 yyerror("invalid hour");
239 } else if(mi < 0 || mi > 59) {
240 yyerror("invalid minute");
241 } else if(s < 0 || s > 59) {
242 yyerror("invalid second");
243 } else if(type < 4) {
244 yylval.strval = alloc(DATE_ALLOC_SIZE);
245 g_snprintf(yylval.strval, DATE_ALLOC_SIZE, "%04d-%02d-%02d", y, m, d);
248 yylval.strval = alloc(DATE_ALLOC_SIZE);
249 g_snprintf(yylval.strval, DATE_ALLOC_SIZE, "%04d-%02d-%02d-%02d-%02d-%02d", y, m, d, h, mi, s);