Imported Upstream version 2.4.4p3
[debian/amanda] / server-src / server_util.c
1 /*
2  * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3  * Copyright (c) 1991-1999 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: server_util.c,v 1.1.2.1.4.2.2.3 2002/04/13 19:24:17 jrjackson Exp $
28  *
29  */
30
31 #include "amanda.h"
32 #include "server_util.h"
33 #include "arglist.h"
34 #include "token.h"
35
36 const char *cmdstr[] = {
37     "BOGUS", "QUIT", "QUITTING", "DONE",
38     "FILE-DUMP", "PORT-DUMP", "CONTINUE", "ABORT",      /* dumper cmds */
39     "FAILED", "TRY-AGAIN", "NO-ROOM", "RQ-MORE-DISK",   /* dumper results */
40     "ABORT-FINISHED", "FATAL-TRYAGAIN", "BAD-COMMAND",  /* dumper results */
41     "START-TAPER", "FILE-WRITE", "PORT-WRITE",          /* taper cmds */
42     "PORT", "TAPE-ERROR", "TAPER-OK",                   /* taper results */
43     NULL
44 };
45
46 cmd_t getcmd(cmdargs)
47 struct cmdargs *cmdargs;
48 {
49     char *line;
50     cmd_t cmd_i;
51
52     assert(cmdargs != NULL);
53
54     if (isatty(0)) {
55         printf("%s> ", get_pname());
56         fflush(stdout);
57     }
58
59     if ((line = agets(stdin)) == NULL) {
60         line = stralloc("QUIT");
61     }
62
63     cmdargs->argc = split(line, cmdargs->argv,
64         sizeof(cmdargs->argv) / sizeof(cmdargs->argv[0]), " ");
65     amfree(line);
66
67 #if DEBUG
68     {
69         int i;
70         printf("argc = %d\n", cmdargs->argc);
71         for (i = 0; i < cmdargs->argc; i++)
72             printf("argv[%d] = \"%s\"\n", i, cmdargs->argv[i]);
73     }
74 #endif
75
76     if (cmdargs->argc < 1)
77         return (BOGUS);
78
79     for(cmd_i=BOGUS; cmdstr[cmd_i] != NULL; cmd_i++)
80         if(strcmp(cmdargs->argv[1], cmdstr[cmd_i]) == 0)
81             return (cmd_i);
82     return (BOGUS);
83 }
84
85
86 printf_arglist_function1(void putresult, cmd_t, result, const char *, format)
87 {
88     va_list argp;
89
90     arglist_start(argp, format);
91     printf("%s ",cmdstr[result]);
92     vprintf(format, argp);
93     fflush(stdout);
94     arglist_end(argp);
95 }
96