File: cmdline.c

package info (click to toggle)
asciijump 1.0.2~beta-7.1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 860 kB
  • ctags: 742
  • sloc: ansic: 4,665; sh: 2,598; makefile: 190
file content (73 lines) | stat: -rw-r--r-- 1,712 bytes parent folder | download | duplicates (4)
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
67
68
69
70
71
72
73
/* :: asciijump (client), gnu gpl v 2
   :: copyright (c) grzegorz moskal, g.moskal@opengruop.org */

#define CMDLINE_C
#include "cmdline.h"

static char 
*usage =
" usage: "PACKAGE" [ARG]\n"
" --help or -h          show this message\n"
" --version or -V       show version info message\n"
" --matrix or -m\n"
" --matrix_full or -mf  use one of matrix mode\n",

*version =
"  "PACKAGE" v "VERSION"\n"
"  [ copyright (c) grzegorz moskal,  eldevarth@nemerle.org ]\n\n" 
"  this program comes with absolutely no warranty; for details\n"
"  please see the file 'COPYING' supplied with the source code.\n"
"  this is free software, and you are welcome to redistribute it\n"
"  under certain conditions; again, see 'COPYING' for details.\n"
"  this program is released under the gnu general public license v2.\n";


int parse_cmdline(int argc, char **argv)
{
	int i = 1;
	
	for (; i < argc; i++) 
		switch(optionid(argv[i])) {
		case Help:
			printf("%s", usage);
			return 0;
		case Version:
			printf("%s", version);
			return 0;
		case Matrix_full:
			mx_mode = MATRIX_FULL;
			break;
		case Matrix:
			mx_mode = MATRIX;
			break;
		default:
			printf("option ``%s'' not recognized :(", argv[i]);
			printf("try %s --help", argv[0]);
			return 0;
		}
		
	return 1;
}

static int opt(char *pattern, char *src1, char *src2)
{
	if (strcmp(pattern, src2) == 0 || strcmp(pattern, src1) == 0) 
		return 1;

	return 0;
}

#define OPTION(a,b) opt(arg, a, b)

static int optionid(char *arg)
{
	if (OPTION("--help", "-h")) 
		return Help;
	else if (OPTION("--version", "-V")) 
		return Version;
	else if (OPTION("--matrix_full", "-mf"))
		return Matrix_full;
	else if (OPTION("--matrix", "-m"))
		return Matrix;
	return 0;
}