Imported Upstream version 3.3.3
[debian/amanda] / oldrecover-src / uparse.y
1 /*
2  * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3  * Copyright (c) 1991-1998, 2000 University of Maryland at College Park
4  * Copyright (c) 2007-2012 Zmanda, Inc.  All Rights Reserved.
5  * All Rights Reserved.
6  *
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.
16  *
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.
23  *
24  * Authors: the Amanda Development Team.  Its members are listed in a
25  * file named AUTHORS, in the root directory of this distribution.
26  */
27 /*
28  * $Id: uparse.y,v 1.2 2006/05/25 01:47:13 johnfranks Exp $
29  *
30  * parser for amrecover interactive language
31  */
32 %{
33 #include "amanda.h"
34 #include "amrecover.h"
35
36 void            yyerror(char *s);
37 extern int      yylex(void);
38 extern char *   yytext;
39
40 %}
41
42 /* DECLARATIONS */
43 %union {
44         int     intval;
45         double  floatval;
46         char *  strval;
47         int     subtok;
48 }
49
50         /* literal keyword tokens */
51
52 %token LISTHOST LISTDISK SETHOST SETDISK SETDATE SETTAPE SETMODE
53 %token CD CDX QUIT DHIST LS ADD ADDX EXTRACT
54 %token LIST DELETE DELETEX PWD CLEAR HELP LCD LPWD MODE SMB TAR
55
56         /* typed tokens */
57
58 %token <strval> PATH
59 %token <strval> DATE
60
61
62 /* GRAMMAR */
63 %%
64
65 ucommand:
66         set_command
67   |     display_command
68   |     quit_command
69   |     add_command
70   |     addx_command
71   |     delete_command
72   |     deletex_command
73   |     local_command
74   |     help_command
75   |     extract_command
76   |     {
77             char * errstr = vstralloc("Invalid command: ", yytext, NULL);
78             yyerror(errstr);
79             amfree(errstr);
80             YYERROR;
81         } /* Quiets compiler warnings about unused label */
82   ;
83
84 set_command:
85         LISTHOST { list_host(); }
86   |     LISTDISK PATH { list_disk($2); amfree($2); }
87   |     LISTDISK { list_disk(NULL); }
88   |     SETDATE DATE { set_date($2); amfree($2); }
89   |     SETHOST PATH { set_host($2); amfree($2); }
90   |     SETDISK PATH PATH { set_disk($2, $3); amfree($2); amfree($3); }
91   |     SETDISK PATH { set_disk($2, NULL); amfree($2); }
92   |     SETTAPE PATH { set_tape($2); amfree($2); }
93   |     SETTAPE { set_tape(""); }
94   |     CD PATH { cd_glob($2); amfree($2); }
95   |     CDX PATH { cd_regex($2); amfree($2); }
96   |     SETMODE SMB {
97 #ifdef SAMBA_CLIENT
98                          set_mode(SAMBA_SMBCLIENT);
99 #endif /* SAMBA_CLIENT */
100                     }
101   |     SETMODE TAR {
102 #ifdef SAMBA_CLIENT
103                          set_mode(SAMBA_TAR);
104 #endif /* SAMBA_CLIENT */
105                     }
106   ;
107
108 display_command:
109         DHIST { list_disk_history(); }
110   |     LS { list_directory(); }
111   |     LIST PATH { display_extract_list($2); amfree($2); }
112   |     LIST { display_extract_list(NULL); }
113   |     PWD { show_directory(); }
114   |     CLEAR { clear_extract_list(); }    
115   |     MODE { show_mode (); }
116   ;
117
118 quit_command:
119         QUIT { quit(); }
120   ;
121
122 add_command:
123         ADD add_path
124   ;
125
126 add_path:
127         add_path PATH { add_glob($2); amfree($2); }
128   |     PATH { add_glob($1); amfree($1); }
129   ;
130
131 addx_command:
132         ADDX addx_path
133   ;
134
135 addx_path:
136         addx_path PATH { add_regex($2); amfree($2); }
137   |     PATH { add_regex($1); amfree($1); }
138   ;
139
140 delete_command:
141         DELETE delete_path
142   ;
143
144 delete_path:
145         delete_path PATH { delete_glob($2); amfree($2); }
146   |     PATH { delete_glob($1); amfree($1); }
147   ;
148
149 deletex_command:
150         DELETEX deletex_path
151   ;
152
153 deletex_path:
154         deletex_path PATH { delete_regex($2); amfree($2); }
155   |     PATH { delete_regex($1); amfree($1); }
156   ;
157
158 local_command:
159         LPWD { char buf[STR_SIZE]; puts(getcwd(buf, sizeof(buf))); }
160   |     LCD PATH {
161                 local_cd($2);
162                 amfree($2);
163         }
164   ;
165
166 help_command:
167         HELP { help_list(); }
168   ;
169
170 extract_command:
171         EXTRACT { extract_files(); }
172   ;
173
174 /* ADDITIONAL C CODE */
175 %%
176
177 void
178 yyerror(
179     char *      s)
180 {
181   g_printf("%s\n", s);
182 }