3 #ifdef STANDALONE_PARSER
16 extern int optind, opterr, optopt;
20 extern int category_out;
23 int warning_info = 0, warning_version = 0;
25 static void usage(
char *progname)
27 printf(
"libparse: a syntax-checker for Singular Libraries.\n");
28 printf(
"USAGE: %s [options] singular-library\n", progname);
30 printf(
" -f <singular library> : performs syntax-checks\n");
31 printf(
" -d [digit] : digit=1,..,4 increases the verbosity of the checks\n");
32 printf(
" -s : turns on reporting about violations of unenforced syntax rules\n");
33 printf(
" -i : perl output of examples and help of procs\n");
34 printf(
" -c : print category of lib to stdout and exit\n");
35 printf(
" -h : print this message\n");
39 static char* lib_file =
NULL;
42 void main_init(
int argc,
char *argv[])
46 while((c=
fe_getopt(argc, argv,
"ihdc:sf:"))>=0)
70 case -1 : printf(
"no such option:%s\n", argv[
fe_optind]);
73 default: printf(
"no such option.%x, %c %s\n", c&0xff, c, argv[
fe_optind]);
81 yylpin = fopen( lib_file,
"rb" );
83 printf(
"Checking library '%s'\n", lib_file);
84 else if (! category_out)
85 printf(
"$library = \"%s\";\n", lib_file);
96 printf(
"Checking library '%s'\n", argv[
fe_optind]);
97 else if (! category_out)
98 printf(
"$library = \"%s\";\n", lib_file);
105 printf(
"No library found to parse.\n");
111 void main_result(
char *)
113 if(!
found_info) printf(
"*** No info-string found!\n");
115 if(
found_oldhelp) printf(
"*** Library has stil OLD library-format.\n");
117 printf(
"*** INFO-string should come before every procedure definition.\n");
119 printf(
"*** VERSION-string should come before every procedure definition.\n");
123 const char *procname,
int line,
long pos,
127 memcpy(pi->
libname, libname, strlen(libname));
128 *(pi->
libname+strlen(libname)) =
'\0';
135 pi->
data.s.proc_start = pos;
136 pi->
data.s.def_end = 0L;
137 pi->
data.s.help_start = 0L;
138 pi->
data.s.body_start = 0L;
139 pi->
data.s.body_end = 0L;
140 pi->
data.s.example_start = 0L;
141 pi->
data.s.proc_lineno = line;
142 pi->
data.s.body_lineno = 0;
143 pi->
data.s.example_lineno = 0;
145 pi->
data.s.help_chksum = 0;
163 static void PrintOut(FILE *
fd,
int pos_start,
int pos_end)
165 if (pos_start <= 0 || pos_end - pos_start <= 4)
return;
169 while (pos_start++ <= pos_end)
174 if (c !=
'"') putchar(
'\\');
178 if (c ==
'@' || c ==
'$') putchar(
'\\');
179 if (c !=
'\r') putchar(c);
181 if (c ==
'\\') putchar(
'\\');
190 FILE *
fp = fopen( lib_file,
"rb");
194 printf(
"Can not open %s\n", lib_file);
198 if(!
found_info && !warning_info) warning_info++;
200 if(pi->
data.s.body_end==0)
201 pi->
data.s.body_end = pi->
data.s.proc_end;
206 (pi->
data.s.body_start - pi->
data.s.def_end > 10) &&
209 printf(
"push(@procs, \"%s\");\n", pi->
procname);
210 printf(
"$help{\"%s\"} = <<EOT;\n", pi->
procname);
211 PrintOut(fp, pi->
data.s.help_start, pi->
data.s.body_start-3);
213 if ((pi->
data.s.example_start > 0) &&
214 (pi->
data.s.proc_end - pi->
data.s.example_start > 10))
216 printf(
"$example{\"%s\"} = <<EOT;\n", pi->
procname);
217 PrintOut(fp, pi->
data.s.example_start, pi->
data.s.proc_end);
220 printf(
"$chksum{\"%s\"} = %ld;\n", pi->
procname, pi->
data.s.help_chksum);
223 else if (! category_out)
228 printf(
"line %4d,%5ld-%-5ld %4d,%5ld-%-5ld %4d,%5ld-%-5ld\n",
229 pi->
data.s.proc_lineno, pi->
data.s.proc_start, pi->
data.s.def_end,
230 pi->
data.s.body_lineno, pi->
data.s.body_start, pi->
data.s.body_end,
231 pi->
data.s.example_lineno, pi->
data.s.example_start,
232 pi->
data.s.proc_end);
235 printf(
"*** Procedure '%s' is global and has no help-section.\n",
238 printf(
"*** Procedure '%s' is global and has no example-section.\n",\
241 printf(
"*** found proc within procedure '%s'.\n", pi->
procname);
245 if (fp !=
NULL) fclose(fp);
int fe_getopt(int argc, char *const *argv, const char *optstring)
procinfo * iiInitSingularProcinfo(procinfov pi, const char *libname, const char *procname, int line, long pos, BOOLEAN pstatic)
void * malloc(size_t size)