-
Notifications
You must be signed in to change notification settings - Fork 2
/
CommandLineParser.c
67 lines (48 loc) · 1.13 KB
/
CommandLineParser.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
55
56
57
58
59
60
61
62
63
64
65
66
#include "CommandLineParser.h"
void CommandLineParserInit(CMDLINE *CmdLine, int argc, char *argv[])
{
if (argc < 0) CmdLine->argc=0;
if (! argv) CmdLine->argc=0;
else CmdLine->argc=argc;
CmdLine->argv=(const char **) argv;
}
CMDLINE *CommandLineParserCreate(int argc, char *argv[])
{
CMDLINE *CmdLine;
CmdLine=(CMDLINE *) calloc(1,sizeof(CMDLINE));
CommandLineParserInit(CmdLine, argc, argv);
return(CmdLine);
}
const char *CommandLineCurr(CMDLINE *CmdLine)
{
const char *ptr=NULL;
if (CmdLine->curr < CmdLine->argc)
{
ptr=CmdLine->argv[CmdLine->curr];
}
return(ptr);
}
const char *CommandLineNext(CMDLINE *CmdLine)
{
const char *ptr=NULL;
if (CmdLine->curr < CmdLine->argc)
{
CmdLine->curr++;
ptr=CmdLine->argv[CmdLine->curr];
}
return(ptr);
}
const char *CommandLineFirst(CMDLINE *CmdLine)
{
CmdLine->curr=0;
return(CommandLineNext(CmdLine));
}
const char *CommandLinePeek(CMDLINE *CmdLine)
{
const char *ptr=NULL;
if ((CmdLine->curr+1) < CmdLine->argc)
{
ptr=CmdLine->argv[CmdLine->curr+1];
}
return(ptr);
}