Imported Upstream version 3.1.0
[debian/amanda] / recover-src / uscan.l
1 /*
2  * amanda, the advanced maryland automatic network disk archiver
3  * Copyright (c) 1991-2000 University of Maryland at College Park
4  * All Rights Reserved.
5  *
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.
15  *
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.
22  *
23  * Authors: the Amanda Development Team.  Its members are listed in a
24  * file named AUTHORS, in the root directory of this distribution.
25  */
26 /*
27  * $Id$
28  *
29  * lexer for amrecover interactive language
30  */
31 %{
32 #include "amanda.h"
33 #include "uparse.h"
34
35 /*
36  * We redefine this here to prevent compiler warning about ignoring fwrite
37  * return value...
38  */
39 #undef ECHO
40 #define ECHO do {                                               \
41         if (fwrite(yytext, (size_t)yyleng, 1, yyout) <= 0) {    \
42             yyerror("ECHO failure");                            \
43         }                                                       \
44 } while (0)
45
46 #define YY_NO_UNPUT
47
48 #define YY_DECL int yylex(void)
49 extern int      yylex(void);
50
51 extern void     yyerror(char *s);
52 extern int      yyparse(void);
53 int             process_line(char *line);
54 %}
55
56 %x quotedstring
57 %x needdevice
58 %x needstring
59 %x needmode
60 %x astring
61 %x propertyappend
62 %x propertypriority
63
64 LINEFEED        [[:space:]]*("\n"|"\r"|"\r\n")
65 %{
66 static char *string_buf = NULL;
67 %}
68
69 %%
70
71 %{
72     /* literal keyword tokens */
73 %}
74
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 <needdevice>-h  { BEGIN(needstring); return DASH_H; }
86 cd              { BEGIN(needstring); return CD; }
87 cdx             { BEGIN(needstring); return CDX; }
88 quit            { BEGIN(needstring); return QUIT; }
89 exit            { BEGIN(needstring); return QUIT; }
90 history         { BEGIN(needstring); return DHIST; }
91 ls              { BEGIN(needstring); return LS; }
92 add             { BEGIN(needstring); return ADD; }
93 addx            { BEGIN(needstring); return ADDX; }
94 list            { BEGIN(needstring); return LIST; }
95 delete          { BEGIN(needstring); return DELETE; }
96 deletex         { BEGIN(needstring); return DELETEX; }
97 pwd             { BEGIN(needstring); return PWD; }
98 clear           { BEGIN(needstring); return CLEAR; }
99 <INITIAL>help   { BEGIN(INITIAL); return HELP; }
100 \?              { BEGIN(needstring); return HELP; }
101 lcd             { BEGIN(needstring); return LCD; }
102 lpwd            { BEGIN(needstring); return LPWD; }
103 extract         { BEGIN(needstring); return EXTRACT; }
104 mode            { BEGIN(needstring); return MODE; }
105 <needmode>tar   { BEGIN(needstring); return TAR; }
106 <needmode>smb   { BEGIN(needstring); return SMB; }
107 <INITIAL,needdevice,needmode,needstring,astring,propertyappend,propertypriority>{LINEFEED}      { BEGIN(INITIAL); return NL; }
108
109 %{
110     /* quoted file names */
111 %}
112
113 <propertyappend>append {
114     BEGIN(propertypriority);
115     return APPEND;
116 }
117
118 <propertyappend,propertypriority>priority {
119     BEGIN(needstring);
120     return PRIORITY;
121 }
122
123 <needdevice,needmode,needstring,astring,propertyappend,propertypriority>\"                      {
124     if(string_buf != NULL) {
125         g_printf("ERROR:string_buf != NULL: %s\n",string_buf);
126     }
127     BEGIN(quotedstring);
128     strappend(string_buf, yytext);
129 }
130
131 <quotedstring>[^\\\"\n\r]+      {
132     strappend(string_buf, yytext);
133 }
134
135 <quotedstring>\\.       {
136     /* escaped character (including quote) */
137     strappend(string_buf, yytext);
138 }
139
140 <quotedstring>\"        { /* saw closing quote - all done */
141     strappend(string_buf, yytext);
142     yylval.strval = string_buf;
143     string_buf = NULL;
144     BEGIN(needstring);
145     return STRING;
146 }
147
148 <quotedstring>{LINEFEED} {
149     fprintf(stderr,"Unterminated quoted string\n");
150     string_buf = NULL;
151     BEGIN(INITIAL);
152     return NL;
153 }
154
155 %{
156     /* file names */
157 %}
158
159 <INITIAL,needdevice,needmode,needstring,astring,propertyappend,propertypriority>[^[:space:][:cntrl:]"]+         {
160     yylval.strval = stralloc(yytext);
161     BEGIN(needstring);
162     return STRING;
163 }
164
165 %{
166     /* whitespace */
167 %}
168
169 <INITIAL,needdevice,needmode,needstring,astring,propertyappend,propertypriority>[[:space:]]+ ; /* whitespace */
170
171 %{
172     /* anything else */
173     /* everything should have been handled by now, so this rule is disabled */
174 %}
175
176 %{
177 #if 0
178 .       { yyerror("invalid character"); }
179 #endif
180 %}
181
182 %%
183
184 int
185 process_line(
186     char *      line)
187 {
188     YY_BUFFER_STATE b;
189     int result;
190
191     char *line1 = stralloc2(line, "\n");
192     b = yy_scan_string(line1);          /* tell lex to scan lineread */
193     result = yyparse();                 /* parse lineread and act */
194     yy_delete_buffer(b);
195     amfree(line1);
196     return result;
197 }
198
199
200 int
201 yywrap(void)
202 {
203   return 1;
204 }
205