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.14.2.3.4.1.2.3 2004/02/11 13:03:52 martinea Exp $
29 * lexer for amrecover interactive language
38 #define DATE_ALLOC_SIZE sizeof("YYYY-MM-DD") /* includes null */
40 extern void yyerror P((char *s));
41 extern int yyparse P((void));
42 static int ll_parse_date P((int type, char *text));
48 static char *string_buf = NULL;
54 /* literal keyword tokens */
57 listdisk { return LISTDISK; }
58 sethost { return SETHOST; }
59 setdisk { return SETDISK; }
60 setdate { return SETDATE; }
61 setmode { return SETMODE; }
62 settape { return SETTAPE; }
67 history { return DHIST; }
72 delete { return DELETE; }
73 deletex { return DELETEX; }
75 clear { return CLEAR; }
80 extract { return EXTRACT; }
89 ---[0-9]+ { return ll_parse_date(1, yytext); }
90 --[0-9]+-[0-9]+ { return ll_parse_date(2, yytext); }
91 [0-9]+-[0-9]+-[0-9]+ { return ll_parse_date(3, yytext); }
98 yylval.strval = stralloc(yytext); return PATH;
102 /* quoted file names */
105 \" { if(string_buf != NULL) {printf("ERROR:string_buf != NULL: %s\n",string_buf);}; BEGIN(quotedstring); }
107 <quotedstring>\" { /* saw closing quote - all done */
110 yylval.strval = string_buf;
120 strappend(string_buf, "\\\"");
124 /* error - unterminated string constant */
125 yyerror("unterminated string");
129 <quotedstring>[^\\\n\"]+ { strappend(string_buf, yytext); }
135 [ \t\r]+ ; /* whitespace */
139 /* everything should have been handled by now, so this rule is disabled */
144 . { yyerror("invalid character"); }
150 int process_line(line)
156 b = yy_scan_string(line); /* tell lex to scan lineread */
157 result = yyparse(); /* parse lineread and act */
162 static int ll_parse_date(type, text)
171 now = time((time_t *)NULL);
177 sscanf(text, "---%d", &d);
178 } else if(type == 2) {
179 sscanf(text, "--%d-%d", &m, &d);
181 sscanf(text, "%d-%d-%d", &y, &m, &d);
188 ret = PATH; /* cause a parse error */
189 if(y < 1000 || y > 9999) {
190 yyerror("invalid year");
191 } else if(m < 1 || m > 12) {
192 yyerror("invalid month");
193 } else if(d < 1 || d > 31) {
194 yyerror("invalid day");
196 yylval.strval = alloc(DATE_ALLOC_SIZE);
197 ap_snprintf(yylval.strval, DATE_ALLOC_SIZE, "%04d-%02d-%02d", y, m, d);