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