forked from CS429-S2022/CI-Lab-Student
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandle_args.c
More file actions
47 lines (43 loc) · 1.57 KB
/
Copy pathhandle_args.c
File metadata and controls
47 lines (43 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**************************************************************************
* C S 429 EEL interpreter
*
* handle_args.c - Module for handling command-line arguments.
*
* Copyright (c) 2021. S. Chatterjee, X. Shen, T. Byrd. All rights reserved.
* May not be used, modified, or copied without permission.
**************************************************************************/
#include "ci.h"
static char printbuf[100];
void handle_args(int argc, char **argv) {
int option;
outfile = stdout;
errfile = stderr;
while ((option = getopt(argc, argv, "i:o:")) != -1) {
switch(option) {
case 'i':
if ((infile = fopen(optarg, "r")) == NULL) {
sprintf(printbuf, "input file %s not found", optarg);
logging(LOG_FATAL, printbuf);
return;
}
break;
case 'o':
if ((outfile = fopen(optarg, "w")) == NULL) {
sprintf(printbuf, "failed to open output file %s", optarg);
logging(LOG_FATAL, printbuf);
return;
}
break;
default:
sprintf(printbuf, "Ignoring unknown option %c", optopt);
logging(LOG_INFO, printbuf);
break;
}
}
for(; optind < argc; optind++) { // when some extra arguments are passed
sprintf(printbuf, "Ignoring extra argument %s", argv[optind]);
logging(LOG_INFO, printbuf);
}
if (infile == NULL) infile = stdin;
return;
}