File: opts_make.c

package info (click to toggle)
ngetty 1.0-1
  • links: PTS
  • area: main
  • in suites: squeeze, wheezy
  • size: 304 kB
  • ctags: 207
  • sloc: ansic: 1,503; makefile: 236; sh: 109; asm: 100
file content (106 lines) | stat: -rw-r--r-- 2,121 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
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
#include <unistd.h>
#include "str_defs.h"
#include "fmt_defs.h"
#include "vhangup_defs.h"

struct xx { char *a,*b,*c; };
char buf[8192], *p = buf;
unsigned char opt_len[512];

#define s(X) p += str_copy(p, X)
#define f(X) p += fmt_ulong(p, X)
#define sfs(a,b,c) s(a); f(b); s(c)

#define X(a,b,c) {#a,#b,#c}

struct xx o[] = {
  X(pri,nt,=),
  X(cl,ear,=),
  X(all,ow,=),
  X(de,ny,=),
  X(env,iron,=),
  X(new,line,=),
  X(sh,-A,=),
  X(sh,-B,=),
  X(t,z,=),
  X(day,s,=),
  X(month,s,=),
  X(ni,ce,=),
  X(ch,dir,=),
  X(de,lay,=),
  X(ch,root,=),
  X(time,out,=),
  X(issue,-file,=),
  X(login,-buffer,=),
  X(login,-prog,=),
  X(login,-argv,=),
  X(login,-prompt,=),
  X(noclear,-first,=),
  X(autologin,-name,=),
  X(autologin,-first,=),

  X(de,bu,g),
  X(echo,-o,ff),
#ifdef HAVE_SYSTEM_VHANGUP
  X(no,han,gup),
#endif
  X(no,user,name),
  X(date,-str,ing),
  X(long,-host,name),
  {0,0,0}
};

int main() {
  struct xx *x = o;
  int n,k, o_len;

  s("/* this file is auto generated.  do not edit! */\n\n"
    "#ifndef NGETTY_opts_defs_h\n"
    "#define NGETTY_opts_defs_h\n\n");
#ifdef HAVE_SYSTEM_VHANGUP
    s("#define HAVE_SYSTEM_VHANGUP\n\n");
#endif

  for (o_len=0, n=0, k=0, x=o; x->a; x++, n++) {
    char *t = x->b;
    int m = str_len(x->a) + str_len(x->b);

    if (*t=='-') t++;
    s("#define O"); s(x->a); s(t);

    if (x->c[0] != '=') { s(x->c); m += str_len(x->c); }
    else k++;

    opt_len[n] = m;
    o_len += m;
    sfs("\t", n, "\n"); 
  }

  sfs("\n#define MAX_equal\t", k, "\n");
  sfs("#define MAX_options\t", n, "\n");
  s("\nstatic char *o[MAX_options];\n"
    "extern char ** Oo;\n\n");

  sfs("const char P_opt[", o_len, "] = {\n");
  for (x=o,n=0; x->a; x++, n++) {
    char *t = "\"\t/* =";
    s("\t\""), s(x->a); s(x->b);
    if (x->c[0] != '=') { s(x->c); t = "\"\t/* "; }
    sfs(t, n, " */\n");
  }  
  s("};\n\n");
  
  s("const unsigned char P_len[MAX_options] = {\n");
  for (k=0; k<n; k++) {
    sfs("\t/* ", k, " */ ");
    sfs(" ", opt_len[k], ",\n");
  }

  p -= 2;
  s("\n};\n\n");
  s("#endif\n\n");

  n = p-buf;
  if (n != write(1, buf, n)) return 1;
  return 0;
}