2 * amanda, the advanced maryland automatic network disk archiver
3 * Copyright (c) 1991-2000 University of Maryland at College Park
4 * Copyright (c) 2007-2012 Zmanda, Inc. All Rights Reserved.
7 * Permission to use, copy, modify, distribute, and sell this software and its
8 * documentation for any purpose is hereby granted without fee, provided that
9 * the above copyright notice appear in all copies and that both that
10 * copyright notice and this permission notice appear in supporting
11 * documentation, and that the name of U.M. not be used in advertising or
12 * publicity pertaining to distribution of the software without specific,
13 * written prior permission. U.M. makes no representations about the
14 * suitability of this software for any purpose. It is provided "as is"
15 * without express or implied warranty.
17 * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
19 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
20 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
21 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
22 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 * Authors: the Amanda Development Team. Its members are listed in a
25 * file named AUTHORS, in the root directory of this distribution.
28 * $Id: uscan.l,v 1.3 2006/07/05 11:15:56 martinea Exp $
30 * lexer for amrecover interactive language
37 * We redefine this here to prevent compiler warning about ignoring fwrite
42 if (fwrite(yytext, (size_t)yyleng, 1, yyout) <= 0) { \
43 yyerror("ECHO failure"); \
49 #define DATE_ALLOC_SIZE sizeof("YYYY-MM-DD-HH-MM-SS") /* includes null */
51 #define YY_DECL int yylex()
52 extern int yylex(void);
54 extern void yyerror(char *s);
55 extern int yyparse(void);
56 static int ll_parse_date(int type, char *text);
57 int process_line(char *line);
63 static char *string_buf = NULL;
69 /* literal keyword tokens */
72 listhost { return LISTHOST; }
73 listdisk { return LISTDISK; }
74 sethost { return SETHOST; }
75 setdisk { return SETDISK; }
76 setdate { return SETDATE; }
77 setmode { return SETMODE; }
78 settape { return SETTAPE; }
83 history { return DHIST; }
88 delete { return DELETE; }
89 deletex { return DELETEX; }
91 clear { return CLEAR; }
96 extract { return EXTRACT; }
105 ---[0-9]+ { return ll_parse_date(1, yytext); }
106 --[0-9]+-[0-9]+ { return ll_parse_date(2, yytext); }
107 [0-9]+-[0-9]+-[0-9]+ { return ll_parse_date(3, yytext); }
108 [0-9]+-[0-9]+-[0-9]+-[0-9]+-[0-9]+-[0-9]+ { return ll_parse_date(4, yytext); }
109 [0-9]+-[0-9]+-[0-9]+-[0-9]+-[0-9]+ { return ll_parse_date(5, yytext); }
112 /* quoted file names */
116 if(string_buf != NULL) {
117 g_printf("ERROR:string_buf != NULL: %s\n",string_buf);
120 strappend(string_buf, yytext);
123 <quotedpath>[^\\\"]+ {
124 strappend(string_buf, yytext);
128 /* escaped character (including quote) */
129 strappend(string_buf, yytext);
132 <quotedpath>\" { /* saw closing quote - all done */
133 strappend(string_buf, yytext);
134 yylval.strval = string_buf;
144 [^[:space:][:cntrl:]"]+ {
145 yylval.strval = stralloc(yytext);
153 [[:space:]]+ ; /* whitespace */
157 /* everything should have been handled by now, so this rule is disabled */
162 . { yyerror("invalid character"); }
175 b = yy_scan_string(line); /* tell lex to scan lineread */
176 result = yyparse(); /* parse lineread and act */
188 int y=2000, m=0, d=1, h=0, mi=0, s=0;
191 now = time((time_t *)NULL);
200 if (sscanf(text, "---%d", &d) != 1) {
201 yyerror("invalid date");
205 if (sscanf(text, "--%d-%d", &m, &d) != 2) {
206 yyerror("invalid date");
210 if (sscanf(text, "%d-%d-%d", &y, &m, &d) != 3) {
211 yyerror("invalid date");
215 if (sscanf(text, "%d-%d-%d-%d-%d-%d", &y, &m, &d, &h, &mi, &s) != 6) {
216 yyerror("invalid date");
220 if (sscanf(text, "%d-%d-%d-%d-%d", &y, &m, &d, &h, &mi) != 5) {
221 yyerror("invalid date");
226 ret = PATH; /* cause a parse error */
232 if(y < 1000 || y > 9999) {
233 yyerror("invalid year");
234 } else if(m < 1 || m > 12) {
235 yyerror("invalid month");
236 } else if(d < 1 || d > 31) {
237 yyerror("invalid day");
238 } else if(h < 0 || h > 24) {
239 yyerror("invalid hour");
240 } else if(mi < 0 || mi > 59) {
241 yyerror("invalid minute");
242 } else if(s < 0 || s > 59) {
243 yyerror("invalid second");
244 } else if(type < 4) {
245 yylval.strval = alloc(DATE_ALLOC_SIZE);
246 g_snprintf(yylval.strval, DATE_ALLOC_SIZE, "%04d-%02d-%02d", y, m, d);
249 yylval.strval = alloc(DATE_ALLOC_SIZE);
250 g_snprintf(yylval.strval, DATE_ALLOC_SIZE, "%04d-%02d-%02d-%02d-%02d-%02d", y, m, d, h, mi, s);