3#ifdef STANDALONE_PARSER
23VAR int warning_info = 0, warning_version = 0;
25static 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");
42void main_init(
int argc,
char *argv[])
46 while((c=getopt(argc, argv,
"ihdc:sf:"))>=0)
52 if(isdigit(argv[optind-1][0])) sscanf(optarg,
"%d", &
lpverbose);
55 case 'f': lib_file = argv[optind-1];
70 case -1 : printf(
"no such option:%s\n", argv[optind]);
73 default: printf(
"no such option.%x, %c %s\n", c&0xff, c, argv[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);
89 while(argc>optind && yylpin==
NULL)
91 yylpin = fopen( argv[optind],
"rb" );
94 lib_file = argv[optind];
96 printf(
"Checking library '%s'\n", argv[optind]);
97 else if (! category_out)
98 printf(
"$library = \"%s\";\n", lib_file);
105 printf(
"No library found to parse.\n");
111void 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,
126 pi->libname = (
char *)
malloc(strlen(libname)+1);
127 memcpy(
pi->libname, libname, strlen(libname));
128 *(
pi->libname+strlen(libname)) =
'\0';
130 pi->procname = (
char *)
malloc(strlen(procname)+1);
131 strcpy(
pi->procname, procname);
134 pi->is_static = pstatic;
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;
163static 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;
205 if ((!
pi->is_static) &&
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)
226 printf(
"%c %-15s %20s ",
pi->is_static ?
'l' :
'g',
pi->libname,
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);
234 if(!
pi->is_static && (
pi->data.s.body_start-
pi->data.s.def_end)<4)
235 printf(
"*** Procedure '%s' is global and has no help-section.\n",
237 if(!
pi->is_static && !
pi->data.s.example_start)
238 printf(
"*** Procedure '%s' is global and has no example-section.\n",\
241 printf(
"*** found proc within procedure '%s'.\n",
pi->procname);
procinfo * iiInitSingularProcinfo(procinfov pi, const char *libname, const char *procname, int, long pos, BOOLEAN pstatic)
VAR int found_proc_in_proc