-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcmdline.c
54 lines (47 loc) · 1.04 KB
/
cmdline.c
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
48
49
50
51
52
53
54
// File: cmdline.c
/*
* Process command line arguments.
*/
#include <stdio.h>
#include <stdlib.h>
#include "errorlib.h"
#include "cmdline.h"
/*
* processcmdlineargs: processes command line arguments. Output of function
* is error flag. Returns amoutn of memory to be allocated in bytes.
*/
int processcmdlineargs(int argc, char *argv[], long long int *memory)
{
int i, c, error;
if (argc == 1) {
fprintf(stderr,"Usage: jayci.x -m [memory]\n");
error = -1;
error_flag(error, "processcmdlineargs");
return error;
}
for (i = 1; i < argc; i++) {
if (*argv[i] == '-') {
while ((c = *(++argv[i]))) {
switch (c) {
case 'm':
*memory = atoi(argv[i+1]);
break;
default:
fprintf(stderr,"Illegal option: %c\n", c);
i = 100;
break;
}
}
}
}
if (argc != 3) {
fprintf(stderr,"Usage: jayci.x -m [memory]\n");
error = -1;
error_flag(error, "processcmdlineargs");
return error;
} else {
fprintf(stdout,"Allocated %lld bytes\n", *memory);
error = 0;
return error;
}
}