-
Notifications
You must be signed in to change notification settings - Fork 0
/
vrgtest4.c
95 lines (74 loc) · 2.42 KB
/
vrgtest4.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#define VRGCLI
// re-define the internal messages for Japanese
// WARNING THIS IS ALL MACHINE-TL I do not claim to know Japanese!
#define VRG_STR_USAGE "使い方"
#define VRG_STR_ERROR "エラー"
#define VRG_STR_INVALID "%T '%N' に対する無効な値 '%V'"
#define VRG_STR_INV_OPTION "オプション"
#define VRG_STR_INV_ARGUMENT "引数"
#define VRG_STR_NO_ARGOPT "オプション '%.*s' の引数が不足しています"
#define VRG_STR_NO_ARGUMENT "引数 '%.*s' が不足しています"
#define VRG_STR_OPTIONS "オプション"
#define VRG_STR_ARGUMENTS "引数"
#include "vrg.h"
// CHeck if the string is an integer
int isint(char *arg)
{
if (arg == NULL || *arg == '\0') return 0;
for(;*arg; arg++) if (*arg < '0' || '9' < *arg) return 0;
return 1;
}
// Check if the string is an integer greater than n
int isgreaterthan(char *arg, int n)
{
if (arg == NULL || *arg == '\0') return 0;
if (strtol(arg,NULL,10)<= n) return 0;
return 1;
}
int isbool(char *arg)
{
if (arg == NULL || *arg == '\0') return 0;
if (strcmp("はい",arg) == 0) return 1;
if (strcmp("いいえ",arg) == 0) return 1;
return 0;
}
// check if the specified file exists and is readable.
int isfile(char *arg)
{
if (arg == NULL || *arg == '\0') return 0;
FILE *f = fopen(arg,"rb");
if (f == NULL) return 0;
fclose(f);
return 1;
}
int main (int argc, char *argv[])
{
vrgcli("バージョン: 1.3RC\n vrgli 関数 の デモ") {
vrgarg("モデル\tモデル の ファイル 名",isfile) {
printf("モデル: '%s'\n",vrgarg);
}
vrgarg("-h, --ヘルプ\tこ の ヘルプ を表示") {
vrgusage();
}
vrgarg("-n, --数-光線 数\t光線 の 数 (正 の 整数)", isgreaterthan, 0) {
printf("Rays: '%s'\n",vrgarg);
}
vrgarg("-t, --なぞる [はい/いいえ] \t\t輪郭をなぞる (ブーリアン)", isbool) {
printf("なぞる '%s'\n",vrgarg);
}
vrgarg("--練習") {
printf("練習 '%s'\n",vrgarg);
}
vrgarg("-r\t再びなぞる") {
printf("再びなぞる '%s'\n",vrgarg);
}
vrgarg("[出力ファイル名]\t\t生成するファイル") {
printf("出力ファイル名: '%s'\n",vrgarg);
}
vrgarg() {
if (vrgarg[0] == '-') vrgerror("未知 の オプション '%s'\n",vrgarg);
else printf("追加の引数 %s\n",vrgarg);
}
}
fprintf(stderr,"残りの引数: %d\n", argc - vrgargn);
}