This repository was archived by the owner on Apr 8, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlua-ada-conf.c
143 lines (126 loc) · 3.5 KB
/
lua-ada-conf.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include <stdio.h>
#include <stdlib.h>
#include "ctxt.h"
#include "_sd_sysinfo.h"
static unsigned int flag;
static int str_diff(register const char *, register const char *);
#define FLAG_INCDIR 0x0001
#define FLAG_DLIBDIR 0x0002
#define FLAG_SLIBDIR 0x0004
#define FLAG_NEWLINE 0x0008
#define FLAG_VERSION 0x0010
#define FLAG_COMPILE 0x0020
#define FLAG_HELP 0x0040
#define FLAG_CFLAGS 0x0080
#define FLAG_LDFLAGS 0x0100
/* PROJECT SPECIFIC */
const char progname[] = "lua-ada-conf";
void flag_incdir(void)
{
if (flag & FLAG_COMPILE) {
printf("-I%s ", ctxt_incdir);
} else {
printf("%s ", ctxt_incdir);
}
}
void flag_cflags(void)
{
}
void flag_dlibdir(void)
{
if (flag & FLAG_COMPILE) printf("-L");
printf("%s ", ctxt_dlibdir);
}
void flag_slibdir(void)
{
if (flag & FLAG_COMPILE) printf("-L");
printf("%s ", ctxt_slibdir);
}
void flag_ldflags(void)
{
printf("-llua-ada ");
}
/* PROJECT SPECIFIC END */
void flag_incdir(void);
void flag_dlibdir(void);
void flag_slibdir(void);
void flag_cflags(void);
void flag_ldflags(void);
static void flag_version(void);
static void flag_help(void);
static void flag_newline(void);
static const struct {
const char *flag;
void (*func)(void);
unsigned int val;
const char *desc;
} flags[] = {
{ "help", flag_help, FLAG_HELP, "this message" },
{ "compile", 0, FLAG_COMPILE, "modify output for use as compiler flags" },
{ "incdir", flag_incdir, FLAG_INCDIR, "print include directory" },
{ "cflags", flag_cflags, FLAG_CFLAGS, "output required compiler flags" },
{ "dlibdir", flag_dlibdir, FLAG_DLIBDIR, "print dynamic library directory" },
{ "slibdir", flag_slibdir, FLAG_SLIBDIR, "print static library directory" },
{ "ldflags", flag_ldflags, FLAG_LDFLAGS, "output required linker flags" },
{ "version", flag_version, FLAG_VERSION, "print library version" },
{ "newline", flag_newline, FLAG_NEWLINE, "print trailing newline" },
};
static void usage(void) { printf("%s: [help] ops ...\n", progname); }
static void help(void)
{
unsigned int ind;
usage();
printf("possible operators:\n");
for (ind = 0; ind < sizeof(flags) / sizeof(flags[0]); ++ind)
printf("%s - %s\n", flags[ind].flag, flags[ind].desc);
exit(0);
}
static void parse_flags(int argc, char *argv[])
{
int ind;
unsigned int jnd;
--argc;
++argv;
if (!argc) { usage(); exit(111); }
flag = 0;
for (ind = 0; ind < argc; ++ind) {
for (jnd = 0; jnd < sizeof(flags) / sizeof(flags[0]); ++jnd) {
if (str_diff(argv[ind], flags[jnd].flag) == 0) {
flag |= flags[jnd].val;
break;
}
}
}
}
static void call_flags(void)
{
unsigned int ind;
for (ind = 0; ind < sizeof(flags) / sizeof(flags[0]); ++ind) {
if (flag & flags[ind].val)
if (flags[ind].func)
flags[ind].func();
}
}
static void flag_version(void) { printf("%s ", ctxt_version); }
static void flag_newline(void) { printf("\n"); }
static void flag_help(void) { help(); }
int main(int argc, char *argv[])
{
parse_flags(argc, argv);
call_flags();
if (fflush(0) != 0) return 112;
return 0;
}
/* portability functions */
static int str_diff(register const char *s, register const char *t)
{
register char u;
for (;;) {
u = *s; if (u != *t) break; if (!u) break; ++s; ++t;
u = *s; if (u != *t) break; if (!u) break; ++s; ++t;
u = *s; if (u != *t) break; if (!u) break; ++s; ++t;
u = *s; if (u != *t) break; if (!u) break; ++s; ++t;
}
return ((int)(unsigned int)(unsigned char) u) -
((int)(unsigned int)(unsigned char) *t);
}