]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/input.c
2 * Copyright (c) 2000-2001 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
47 static void popfile(void);
48 static int source_f(int argc
, char **argv
);
50 static const cmdinfo_t source_cmd
=
51 { "source", NULL
, source_f
, 1, 1, 0, "source-file",
52 "get commands from source-file", NULL
};
54 /* our homegrown strtok that understands strings */
60 static char *last_place
= NULL
;
69 if (last_place
== NULL
)
73 if (*last_place
!= '\0')
76 start
= last_place
+ 1;
81 while (*start
== ' ' || *start
== '\t')
85 for (;*walk
!= '\0'; walk
++) {
92 else if (*walk
== '\"')
95 if (!in_string
&& !in_escape
&&
96 (*walk
== ' ' || *walk
== '\t')) {
120 rval
= xcalloc(sizeof(char *), 1);
129 rval
= xrealloc(rval
, sizeof(*rval
) * (c
+ 1));
156 for (rlen
= iscont
= 0; ; ) {
157 if (inputstacksize
== 1) {
161 dbprintf("%s: ", progname
);
165 (!fgets(buf
, sizeof(buf
), curinput
) &&
166 ferror(curinput
) && seenint())) {
180 if (ferror(curinput
) || feof(curinput
) ||
181 (len
= strlen(buf
)) == 0) {
183 if (curinput
== NULL
) {
195 if (inputstacksize
== 1)
196 logprintf("%s", buf
);
197 rval
= xrealloc(rval
, rlen
+ len
+ 1);
202 if (buf
[len
- 1] == '\n') {
203 if (len
> 1 && buf
[len
- 2] == '\\') {
204 rval
[rlen
- 2] = ' ';
205 rval
[rlen
- 1] = '\0';
209 rval
[rlen
- 1] = '\0';
221 add_command(&source_cmd
);
227 if (inputstacksize
== 0) {
231 if (curinput
!= stdin
)
235 if (inputstacksize
) {
237 xrealloc(inputstack
, inputstacksize
* sizeof(*inputstack
));
238 curinput
= inputstack
[inputstacksize
- 1];
252 (inputstacksize
+ 1) * sizeof(*inputstack
));
254 curinput
= inputstack
[inputstacksize
- 1] = file
;
265 f
= fopen(argv
[1], "r");
267 dbprintf("can't open %s\n", argv
[0]);