~ubuntu-branches/ubuntu/edgy/xfsprogs/edgy

« back to all changes in this revision

Viewing changes to db/input.c

  • Committer: Bazaar Package Importer
  • Author(s): Nathan Scott
  • Date: 2004-07-28 21:11:38 UTC
  • Revision ID: james.westby@ubuntu.com-20040728211138-0v4pdnunnp7na5lm
Tags: 2.6.20-1
* New upstream release.
* Fix xfs_io segfault on non-XFS files.  (closes: #260470)
* Fix packaging botch, deleted files included.  (closes: #260491)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
3
 
 * 
 
2
 * Copyright (c) 2000-2003 Silicon Graphics, Inc.  All Rights Reserved.
 
3
 *
4
4
 * This program is free software; you can redistribute it and/or modify it
5
5
 * under the terms of version 2 of the GNU General Public License as
6
6
 * published by the Free Software Foundation.
7
 
 * 
 
7
 *
8
8
 * This program is distributed in the hope that it would be useful, but
9
9
 * WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 
 * 
 
11
 *
12
12
 * Further, this software is distributed without any warranty that it is
13
13
 * free of the rightful claim of any third person regarding infringement
14
14
 * or the like.  Any license provided herein, whether implied or
15
15
 * otherwise, applies only to this software file.  Patent licenses, if
16
16
 * any, provided herein do not apply to combinations of this program with
17
17
 * other software, or any other product whatsoever.
18
 
 * 
 
18
 *
19
19
 * You should have received a copy of the GNU General Public License along
20
20
 * with this program; if not, write the Free Software Foundation, Inc., 59
21
21
 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22
 
 * 
 
22
 *
23
23
 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24
24
 * Mountain View, CA  94043, or:
25
 
 * 
26
 
 * http://www.sgi.com 
27
 
 * 
28
 
 * For further information regarding this notice, see: 
29
 
 * 
 
25
 *
 
26
 * http://www.sgi.com
 
27
 *
 
28
 * For further information regarding this notice, see:
 
29
 *
30
30
 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31
31
 */
32
32
 
33
 
#include <libxfs.h>
 
33
#include <xfs/libxfs.h>
34
34
#include <signal.h>
35
35
#include "command.h"
36
 
#include "data.h"
37
36
#include "input.h"
38
37
#include "output.h"
39
38
#include "sig.h"
40
39
#include "malloc.h"
41
40
#include "init.h"
42
41
 
 
42
#if defined(ENABLE_READLINE)
 
43
# include <readline/history.h>
 
44
# include <readline/readline.h>
 
45
#elif defined(ENABLE_EDITLINE)
 
46
# include <histedit.h>
 
47
#endif
 
48
 
43
49
int     inputstacksize;
44
50
FILE    **inputstack;
45
51
FILE    *curinput;
143
149
        xfree(vec);
144
150
}
145
151
 
146
 
char *
147
 
fetchline(void)
 
152
static char *
 
153
get_prompt(void)
 
154
{
 
155
        static char     prompt[FILENAME_MAX + 1];
 
156
 
 
157
        if (!prompt[0])
 
158
                snprintf(prompt, sizeof(prompt), "%s> ", progname);
 
159
        return prompt;
 
160
}
 
161
 
 
162
static char *
 
163
fetchline_internal(void)
148
164
{
149
165
        char    buf[1024];
150
166
        int     iscont;
158
174
                        if (iscont)
159
175
                                dbprintf("... ");
160
176
                        else
161
 
                                dbprintf("%s: ", progname);
 
177
                                dbprintf(get_prompt(), progname);
162
178
                        fflush(stdin);
163
179
                }
164
180
                if (seenint() ||
215
231
        return rval;
216
232
}
217
233
 
218
 
void
219
 
input_init(void)
 
234
#ifdef ENABLE_READLINE
 
235
char *
 
236
fetchline(void)
220
237
{
221
 
        add_command(&source_cmd);
222
 
}
 
238
        char    *line;
 
239
 
 
240
        if (inputstacksize == 1) {
 
241
                line = readline(get_prompt());
 
242
                if (line && *line) {
 
243
                        add_history(line);
 
244
                        logprintf("%s", line);
 
245
                }
 
246
        } else {
 
247
                line = fetchline_internal();
 
248
        }
 
249
        return line;
 
250
}
 
251
#elif defined(ENABLE_EDITLINE)
 
252
static char *el_get_prompt(EditLine *e) { return get_prompt(); }
 
253
char *
 
254
fetchline(void)
 
255
{     
 
256
        static EditLine *el;
 
257
        static History  *hist;
 
258
        HistEvent       hevent;
 
259
        char            *line;    
 
260
        int             count;
 
261
 
 
262
        if (!el) {
 
263
                hist = history_init();
 
264
                history(hist, &hevent, H_SETSIZE, 100);
 
265
                el = el_init(progname, stdin, stdout, stderr);
 
266
                el_source(el, NULL);
 
267
                el_set(el, EL_SIGNAL, 1);
 
268
                el_set(el, EL_PROMPT, el_get_prompt);
 
269
                el_set(el, EL_HIST, history, (const char *)hist);
 
270
        }
 
271
 
 
272
        if (inputstacksize == 1) {
 
273
                line = xstrdup(el_gets(el, &count));
 
274
                if (line) {
 
275
                        if (count > 0)
 
276
                                line[count-1] = '\0';
 
277
                        if (*line) {
 
278
                                history(hist, &hevent, H_ENTER, line);
 
279
                                logprintf("%s", line);
 
280
                        }
 
281
                }
 
282
        } else {
 
283
                line = fetchline_internal();
 
284
        }
 
285
        return line;
 
286
}
 
287
#else
 
288
char * fetchline(void) { return fetchline_internal(); }
 
289
#endif
223
290
 
224
291
static void
225
292
popfile(void)
230
297
        }
231
298
        if (curinput != stdin)
232
299
                fclose(curinput);
233
 
        
 
300
 
234
301
        inputstacksize--;
235
 
        if (inputstacksize) {
 
302
        if (inputstacksize) {
236
303
            inputstack =
237
304
                    xrealloc(inputstack, inputstacksize * sizeof(*inputstack));
238
 
            curinput = inputstack[inputstacksize - 1];
239
 
        } else {
240
 
            free(inputstack);
241
 
            curinput = NULL;
242
 
            inputstack = NULL;
243
 
        }
 
305
            curinput = inputstack[inputstacksize - 1];
 
306
        } else {
 
307
            free(inputstack);
 
308
            curinput = NULL;
 
309
            inputstack = NULL;
 
310
        }
244
311
}
245
312
 
246
313
void
269
336
                pushfile(f);
270
337
        return 0;
271
338
}
 
339
 
 
340
void
 
341
input_init(void)
 
342
{
 
343
        add_command(&source_cmd);
 
344
}