1 #pragma ident "%Z%%M% %I% %E% SMI"
4 * Copyright 1987, 1988 by MIT Student Information Processing Board
6 * For copyright information, see copyright.h.
10 #include "copyright.h"
11 #include "ss_internal.h" /* includes stdio and string */
13 extern FILE *output_file
;
15 char *gensym(), *str_concat3(), *quote();
18 void write_ct(hdr
, rql
)
19 char const *hdr
, *rql
;
23 fputs("static ss_request_entry ", output_file
);
24 fputs(sym
, output_file
);
25 fputs("[] = {\n", output_file
);
26 fputs(rql
, output_file
);
27 fputs(" { 0, 0, 0, 0 }\n", output_file
);
28 fputs("};\n\nss_request_table ", output_file
);
29 fputs(hdr
, output_file
);
30 fprintf(output_file
, " = { %d, ", SS_RQT_TBL_V2
);
31 fputs(sym
, output_file
);
32 fputs(" };\n", output_file
);
35 char * generate_cmds_string(cmds
)
38 char * var_name
= gensym("ssu");
39 fputs("static char const * const ", output_file
);
40 fputs(var_name
, output_file
);
41 fputs("[] = {\n", output_file
);
42 fputs(cmds
, output_file
);
43 fputs(",\n (char const *)0\n};\n", output_file
);
47 void generate_function_definition(func
)
50 fputs("extern void ", output_file
);
51 fputs(func
, output_file
);
52 fputs(" __SS_PROTO;\n", output_file
);
55 char * generate_rqte(func_name
, info_string
, cmds
, options
)
56 char const *func_name
;
57 char const *info_string
;
62 char *string
, *var_name
, numbuf
[16];
63 var_name
= generate_cmds_string(cmds
);
64 generate_function_definition(func_name
);
66 size
+= strlen(var_name
)+8; /* "quux, " */
67 size
+= strlen(func_name
)+8; /* "foo, " */
68 size
+= strlen(info_string
)+8; /* "\"Info!\", " */
69 sprintf(numbuf
, "%d", options
);
70 size
+= strlen(numbuf
)+5; /* " }," + NL + NUL */
71 string
= malloc(size
);
72 strcpy(string
, " { ");
73 strcat(string
, var_name
);
74 strcat(string
, ",\n ");
75 strcat(string
, func_name
);
76 strcat(string
, ",\n ");
77 strcat(string
, info_string
);
78 strcat(string
, ",\n ");
79 strcat(string
, numbuf
);
80 strcat(string
, " },\n");
90 symbol
= malloc((strlen(name
)+6) * sizeof(char));
92 sprintf(symbol
, "%s%05ld", name
, gensym_n
);
96 /* concatenate three strings and return the result */
97 char *str_concat3(a
, b
, c
)
98 register char *a
, *b
, *c
;
101 int size_a
= strlen(a
);
102 int size_b
= strlen(b
);
103 int size_c
= strlen(c
);
105 result
= malloc((size_a
+ size_b
+ size_c
+ 2)*sizeof(char));
107 strcpy(&result
[size_a
], c
);
108 strcpy(&result
[size_a
+size_c
], b
);
112 /* return copy of string enclosed in double-quotes */
114 register char *string
;
116 register char *result
;
118 len
= strlen(string
)+1;
119 result
= malloc(len
+2);
121 strncpy(&result
[1], string
, len
-1);
123 result
[len
+1] = '\0';
128 /* make duplicate of string and return pointer */
132 register int len
= strlen(s
) + 1;
135 strncpy(new, s
, len
);