source: trunk/athena/bin/neos/fxmain.c @ 13635

Revision 13635, 4.2 KB checked in by danw, 25 years ago (diff)
NEOS clients, from athena/lib/neos/clients
Line 
1/**********************************************************************
2 * File Exchange fxmain module
3 *
4 * $Id: fxmain.c,v 1.1 1999-09-28 22:10:58 danw Exp $
5 *
6 * Copyright 1990 by the Massachusetts Institute of Technology.
7 *
8 * For copying and distribution information, please see the file
9 * <mit-copyright.h>.
10 **********************************************************************/
11
12#include <mit-copyright.h>
13#include <ctype.h>
14#include <sys/types.h>
15#include "fxmain.h"
16
17#define DAY (86400L)            /* number of seconds in one day */
18
19/*** Global variables ***/
20char fxmain_error_context[256];
21
22FX *
23fxmain_open(progname, course)
24     char *progname, *course;
25{
26  FX *fxp;
27  long code;
28
29  if (!course) {
30    fprintf(stderr, "%s: No course specified.\n", progname);
31    exit(1);
32  }
33  fxp = fx_open(course, &code);
34  if (!fxp) {
35    com_err(progname, code, "trying to open %s", course);
36    exit(1);
37  }
38
39  if (code)
40    fprintf(stderr, "%s: Warning: %s at %s\n", progname,
41            error_message(code), fxp->host);
42  return(fxp);
43}
44
45long
46fxmain(argc, argv, usage, p, special_arg, doproc)
47     int argc;
48     char *argv[];
49     char *usage;
50     Paper *p;
51     int (*special_arg)(int, char *[], int *, Paper *, int *);
52     long (*doproc)(FX *, Paper *, int, char *);
53{
54  FX *fxp = NULL;
55  long code = 0L;
56  int asgn_found = 0, specific = 0;
57  int i;
58  char *course;
59  int flags = VERBOSE;
60
61  course = (char *) getenv("COURSE");
62  if (!p->modified.tv_sec) p->modified.tv_sec = time(0);
63
64  for (i=1; i<argc; i++) {
65
66    /* Deal with arguments specific to one application */
67    if (special_arg)
68      if (special_arg(argc, argv, &i, p, &flags)) continue;
69
70    /* Time ceiling (for programs that choose to use it) */
71    if (argv[i][0] == '+' && isdigit(argv[i][1])) {
72      p->modified.tv_sec = time(0) - (DAY * (long) atol(argv[i]+1));
73      continue;
74    }
75
76    /* Hyphenated options */
77    if (argv[i][0] == '-') {
78      switch(argv[i][1]) {
79      case 'a':
80        p->assignment = atoi(argv[++i]);
81        asgn_found = 1;
82        break;
83      case 'c':
84        course = argv[++i];
85        if (fxp) {
86          fx_close(fxp);
87          fxp = NULL;
88        }
89        break;
90      case 'd':
91        if (chdir(argv[++i])) {
92          perror(argv[i]);
93          exit(1);
94        }
95        break;
96      case 'f':
97        p->filename = argv[++i];
98        break;
99      case 'u':
100        p->author = argv[++i];
101        break;
102      case 'o':
103        p->owner = argv[++i];
104      case 's':
105        p->desc = argv[++i];
106        break;
107      case 'q':
108        flags &= ~VERBOSE;
109        break;
110      case 'v':
111        flags |= VERBOSE;
112        break;
113      case 'l':
114        flags |= LISTONLY;
115        break;
116      case 'w':
117        flags &= ~LISTONLY;
118        break;
119      case 'p':
120        flags |= PRESERVE;
121        break;
122      case 'm':
123        flags &= ~PRESERVE;
124        break;
125      case '*':
126        p->type = TYPE_WILDCARD;
127        break;
128      case 'T':
129        p->type = TURNEDIN;
130        break;
131      case 't':
132        p->type = TAKEN;
133        break;
134      case 'g':
135        p->type = GRADED;
136        break;
137      case 'P':
138        p->type = PICKEDUP;
139        break;
140      case 'h':
141        p->type = HANDOUT;
142        break;
143      case 'e':
144        p->type = EXCHANGE;
145        break;
146      case 'A':
147        p->type = TEACHERS_ARCHIVE;
148        break;
149      case 'H':
150        p->type = TEACHERS_HANDOUT;
151        break;
152      default:
153        /* Time floor (for programs that choose to use it) */
154        if (isdigit(argv[i][1])) {
155          p->created.tv_sec = time(0) - (DAY * (long) atol(argv[i]+1));
156          break;
157        }
158        fprintf(stderr, usage, argv[0]);
159        exit(1);
160      }
161      continue;
162    }
163
164    /* Assignment number */
165    if (!asgn_found && isdigit(argv[i][0])) {
166      asgn_found = 1;
167      p->assignment = atoi(argv[i]);
168      continue;
169    }
170
171    /* specific argument (user or filename) */
172    if (!fxp) fxp = fxmain_open(argv[0], course);
173    specific = 1;
174    code = doproc(fxp, p, flags, argv[i]);
175    if (code == ERR_USAGE) {
176      fprintf(stderr, usage, argv[0]);
177      fx_close(fxp);
178      return(0L);
179    }
180    if (code) {
181      com_err(argv[0], code, "%s", fxmain_error_context);
182      goto FXMAIN_ABORT;
183    }
184  }
185  if (!specific) {
186    if (!fxp) fxp = fxmain_open(argv[0], course);
187    code = doproc(fxp, p, flags, NULL);
188    if (code == ERR_USAGE) {
189      fprintf(stderr, usage, argv[0]);
190      fx_close(fxp);
191      return(0L);
192    }
193    if (code) com_err(argv[0], code, "%s", fxmain_error_context);
194  }
195
196FXMAIN_ABORT:
197  fx_close(fxp);
198  return(code);
199}
Note: See TracBrowser for help on using the repository browser.