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.27 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(void)
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; }
78 setdevice { return SETDEVICE; }
84 history { return DHIST; }
89 delete { return DELETE; }
90 deletex { return DELETEX; }
92 clear { return CLEAR; }
97 extract { return EXTRACT; }
100 mode { return MODE; }
106 ---[0-9]+ { return ll_parse_date(1, yytext); }
107 --[0-9]+-[0-9]+ { return ll_parse_date(2, yytext); }
108 [0-9]+-[0-9]+-[0-9]+ { return ll_parse_date(3, yytext); }
109 [0-9]+-[0-9]+-[0-9]+-[0-9]+-[0-9]+-[0-9]+ { return ll_parse_date(4, yytext); }
110 [0-9]+-[0-9]+-[0-9]+-[0-9]+-[0-9]+ { return ll_parse_date(5, yytext); }
113 /* quoted file names */
117 if(string_buf != NULL) {
118 g_printf("ERROR:string_buf != NULL: %s\n",string_buf);
121 strappend(string_buf, yytext);
124 <quotedpath>[^\\\"]+ {
125 strappend(string_buf, yytext);
129 /* escaped character (including quote) */
130 strappend(string_buf, yytext);
133 <quotedpath>\" { /* saw closing quote - all done */
134 strappend(string_buf, yytext);
135 yylval.strval = string_buf;
145 [^[:space:][:cntrl:]"]+ {
146 yylval.strval = stralloc(yytext);
154 [[:space:]]+ ; /* whitespace */
158 /* everything should have been handled by now, so this rule is disabled */
163 . { yyerror("invalid character"); }
176 b = yy_scan_string(line); /* tell lex to scan lineread */
177 result = yyparse(); /* parse lineread and act */
189 int y=2000, m=0, d=1, h=0, mi=0, s=0;
192 now = time((time_t *)NULL);
201 if (sscanf(text, "---%d", &d) != 1) {
202 yyerror("invalid date");
206 if (sscanf(text, "--%d-%d", &m, &d) != 2) {
207 yyerror("invalid date");
211 if (sscanf(text, "%d-%d-%d", &y, &m, &d) != 3) {
212 yyerror("invalid date");
216 if (sscanf(text, "%d-%d-%d-%d-%d-%d", &y, &m, &d, &h, &mi, &s) != 6) {
217 yyerror("invalid date");
221 if (sscanf(text, "%d-%d-%d-%d-%d", &y, &m, &d, &h, &mi) != 5) {
222 yyerror("invalid date");
227 ret = PATH; /* cause a parse error */
233 if(y < 1000 || y > 9999) {
234 yyerror("invalid year");
235 } else if(m < 1 || m > 12) {
236 yyerror("invalid month");
237 } else if(d < 1 || d > 31) {
238 yyerror("invalid day");
239 } else if(h < 0 || h > 24) {
240 yyerror("invalid hour");
241 } else if(mi < 0 || mi > 59) {
242 yyerror("invalid minute");
243 } else if(s < 0 || s > 59) {
244 yyerror("invalid second");
245 } else if(type < 4) {
246 yylval.strval = alloc(DATE_ALLOC_SIZE);
247 g_snprintf(yylval.strval, DATE_ALLOC_SIZE, "%04d-%02d-%02d", y, m, d);
250 yylval.strval = alloc(DATE_ALLOC_SIZE);
251 g_snprintf(yylval.strval, DATE_ALLOC_SIZE, "%04d-%02d-%02d-%02d-%02d-%02d", y, m, d, h, mi, s);