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.
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 YY_DECL int yylex(void)
49 extern int yylex(void);
51 extern void yyerror(char *s);
52 extern int yyparse(void);
53 int process_line(char *line);
64 LINEFEED [[:space:]]*("\n"|"\r"|"\r\n")
66 static char *string_buf = NULL;
72 /* literal keyword tokens */
75 listhost { BEGIN(needstring); return LISTHOST; }
76 listdisk { BEGIN(needstring); return LISTDISK; }
77 listproperty { BEGIN(needstring); return LISTPROPERTY; }
78 sethost { BEGIN(needstring); return SETHOST; }
79 setdisk { BEGIN(needstring); return SETDISK; }
80 setdate { BEGIN(needstring); return SETDATE; }
81 setmode { BEGIN(needmode); return SETMODE; }
82 settape { BEGIN(needstring); return SETTAPE; }
83 setdevice { BEGIN(needdevice); return SETDEVICE; }
84 setproperty { BEGIN(propertyappend); return SETPROPERTY; }
85 settranslate { BEGIN(needstring); return SETTRANSLATE; }
86 <needdevice>-h { BEGIN(needstring); return DASH_H; }
87 cd { BEGIN(needstring); return CD; }
88 cdx { BEGIN(needstring); return CDX; }
89 quit { BEGIN(needstring); return QUIT; }
90 exit { BEGIN(needstring); return QUIT; }
91 history { BEGIN(needstring); return DHIST; }
92 ls { BEGIN(needstring); return LS; }
93 add { BEGIN(needstring); return ADD; }
94 addx { BEGIN(needstring); return ADDX; }
95 list { BEGIN(needstring); return LIST; }
96 delete { BEGIN(needstring); return DELETE; }
97 deletex { BEGIN(needstring); return DELETEX; }
98 pwd { BEGIN(needstring); return PWD; }
99 clear { BEGIN(needstring); return CLEAR; }
100 <INITIAL>help { BEGIN(INITIAL); return HELP; }
101 \? { BEGIN(needstring); return HELP; }
102 lcd { BEGIN(needstring); return LCD; }
103 lpwd { BEGIN(needstring); return LPWD; }
104 extract { BEGIN(needstring); return EXTRACT; }
105 mode { BEGIN(needstring); return MODE; }
106 <needmode>tar { BEGIN(needstring); return TAR; }
107 <needmode>smb { BEGIN(needstring); return SMB; }
108 <INITIAL,needdevice,needmode,needstring,astring,propertyappend,propertypriority>{LINEFEED} { BEGIN(INITIAL); return NL; }
111 /* quoted file names */
114 <propertyappend>append {
115 BEGIN(propertypriority);
119 <propertyappend,propertypriority>priority {
124 <needdevice,needmode,needstring,astring,propertyappend,propertypriority>\" {
125 if(string_buf != NULL) {
126 g_printf("ERROR:string_buf != NULL: %s\n",string_buf);
129 strappend(string_buf, yytext);
132 <quotedstring>[^\\\"\n\r]+ {
133 strappend(string_buf, yytext);
137 /* escaped character (including quote) */
138 strappend(string_buf, yytext);
141 <quotedstring>\" { /* saw closing quote - all done */
142 strappend(string_buf, yytext);
143 yylval.strval = string_buf;
149 <quotedstring>{LINEFEED} {
150 fprintf(stderr,"Unterminated quoted string\n");
160 <INITIAL,needdevice,needmode,needstring,astring,propertyappend,propertypriority>[^[:space:][:cntrl:]"]+ {
161 yylval.strval = stralloc(yytext);
170 <INITIAL,needdevice,needmode,needstring,astring,propertyappend,propertypriority>[[:space:]]+ ; /* whitespace */
174 /* everything should have been handled by now, so this rule is disabled */
179 . { yyerror("invalid character"); }
192 char *line1 = stralloc2(line, "\n");
193 b = yy_scan_string(line1); /* tell lex to scan lineread */
194 result = yyparse(); /* parse lineread and act */