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