Macros | Functions | Variables
checklibs.c File Reference
#include <stdio.h>
#include <string.h>

Go to the source code of this file.

Macros

#define NUM_PROC   200
 
#define LINE_LEN   200
 
#define RECOMMENDED_LEN   100
 

Functions

void get_next ()
 
void scan_proc (int *l)
 
void scan_keywords (int *l)
 
void scan_info (int *l)
 
int main (int argc, char **argv)
 

Variables

FILE * f
 
int trailing_spaces =0
 
int tabs =0
 
int verylong_lines =0
 
int lines =0
 
unsigned char buf [LINE_LEN]
 
int proc_cnt =0
 
unsigned char * proc [NUM_PROC]
 
unsigned char have_doc [NUM_PROC]
 
unsigned char have_example [NUM_PROC]
 
unsigned char proc_found [NUM_PROC]
 
int non_ascii =0
 
int non_ascii_line =0
 
int star_nl =0
 
int footer =0
 
int header =0
 
int crlf =0
 

Macro Definition Documentation

§ LINE_LEN

#define LINE_LEN   200

Definition at line 5 of file checklibs.c.

§ NUM_PROC

#define NUM_PROC   200

Definition at line 4 of file checklibs.c.

§ RECOMMENDED_LEN

#define RECOMMENDED_LEN   100

Definition at line 6 of file checklibs.c.

Function Documentation

§ get_next()

void get_next ( )

Definition at line 25 of file checklibs.c.

26 {
27  int i;
28  memset(buf,0,LINE_LEN);
29  fgets(buf,LINE_LEN,f);
30  lines++;
31  if (buf[0]!='\0')
32  {
33  int non_ascii_found=0;
34  if (strchr(buf,'\r')!=NULL) crlf++;
35  if ((buf[LINE_LEN-1]!='\0')||(strlen(buf)>RECOMMENDED_LEN))
36  {
37  if (verylong_lines==0) printf("warning: very long line (%d):\n%s\n",lines,buf);
39  }
40  if ((strstr(buf," \n")!=NULL)||(strstr(buf," \r\n")!=NULL)) trailing_spaces++;
41  if (strchr(buf,'\t')!=NULL) tabs++;
42 
43  for(i=0;(i<LINE_LEN) && (buf[i]!='\0'); i++)
44  {
45  if (buf[i]>=127) { non_ascii_found=1;non_ascii++;non_ascii_line=lines; break; }
46  }
47  if (non_ascii_found) printf("non-ascii:>>%s<<\n",buf);
48  if (footer==0) /* we are still in the header */
49  {
50  if (strstr(buf,"@*")!=NULL) star_nl++;
51  }
52  }
53 }
int crlf
Definition: checklibs.c:23
#define RECOMMENDED_LEN
Definition: checklibs.c:6
int non_ascii
Definition: checklibs.c:18
int non_ascii_line
Definition: checklibs.c:19
FILE * f
Definition: checklibs.c:7
int i
Definition: cfEzgcd.cc:123
#define LINE_LEN
Definition: checklibs.c:5
int verylong_lines
Definition: checklibs.c:10
int trailing_spaces
Definition: checklibs.c:8
int lines
Definition: checklibs.c:11
unsigned char buf[LINE_LEN]
Definition: checklibs.c:12
#define NULL
Definition: omList.c:10
int footer
Definition: checklibs.c:21
int star_nl
Definition: checklibs.c:20
int tabs
Definition: checklibs.c:9

§ main()

int main ( int  argc,
char **  argv 
)

Definition at line 259 of file checklibs.c.

260 {
261  int have_version=0;
262  int have_category=0;
263  int have_info=0;
264  unsigned char *p;
265 
266  memset(proc,0,NUM_PROC*sizeof(char*));
267  memset(have_doc,0,NUM_PROC);
268  memset(have_example,0,NUM_PROC);
269  memset(proc_found,0,NUM_PROC);
270  if (argc!=2) { printf("usage: %s lib-file\n",argv[0]); return 1;}
271 
272  printf("\n CHECKING LIBRARY %s\n\n",argv[1]);
273 
274  f=fopen(argv[1],"r");
275  if(f==NULL) { printf("cannot read %s\n",argv[1]); return 2; }
276  buf[0]='\0';
277  get_next(); header++;
278  if (strncmp(buf,"//",2)!=0) { printf("error: lib must start with //\n"); }
279  else { get_next(); header++; }
280  /* pass 1: check header */
281  while(1)
282  {
283  if ((p=strstr(buf,"version="))!=NULL)
284  {
285  unsigned char *pp=buf;
286  while (pp!=p)
287  {
288  if ((*pp!=' ')&&(*pp!='\t')) break;
289  pp++;
290  }
291  if (p=pp)
292  {
293  have_version++;
294  pp=p+8;
295  while((*pp)==' ') pp++;
296  /* syntax of version string: "version <filename> <version> <date> "
297  if (*pp)!='"')
298  printf("error: version string should ....");
299  */
300  }
301  }
302  if ((p=strstr(buf,"category="))!=NULL)
303  {
304  unsigned char *pp=buf;
305  while (pp!=p)
306  {
307  if ((*pp!=' ')&&(*pp!='\t')) break;
308  pp++;
309  }
310  if (p=pp) have_category++;
311  }
312  if ((p=strstr(buf,"info="))!=NULL)
313  {
314  unsigned char *pp=buf;
315  while (pp!=p)
316  {
317  if ((*pp!=' ')&&(*pp!='\t')) break;
318  pp++;
319  }
320  if (p=pp) { have_info++; scan_info(&header); }
321  }
322  if ((p=strstr(buf,"LIB\""))!=NULL)
323  {
324  printf("error: use a space between LIB and \"\n");
325  if (p!=buf)
326  { printf("end of header ? LIB should be in col. 1:>>%s<<\n",buf); }
327  break; /* end of header */
328  }
329  if ((p=strstr(buf,"LIB \""))!=NULL)
330  {
331  if (p!=buf)
332  { printf("end of header ? LIB should be in col. 1:>>%s<<\n",buf); }
333  break; /* end of header */
334  }
335  if ((p=strstr(buf,"proc "))!=NULL)
336  {
337  if ((p!=buf)&&(strncmp(buf,"static proc ",12)!=0))
338  { printf("end of header ? proc should be in col. 1:>>%s<<\n",buf); }
339  break; /* end of header */
340  }
341  get_next(); header++;
342  if(feof(f)) break;
343  }
344  printf("header parsed: %d lines of %s\n\n",header,argv[1]);
345  /* part 2: procs */
346  while(!feof(f))
347  {
348  if ((strstr(buf,"static")==(char*)buf) && (strstr(buf,"proc")==NULL))
349  {
350  printf("error: 'static' without 'proc' found\n");
351  get_next();
352  }
353  if(((p=strstr(buf,"proc "))!=NULL)
354  &&(strncmp(buf,"static proc ",12)!=0))
355  {
356  unsigned char *pp=buf;
357  int i;
358  while(*pp==' ') pp++;
359  if ((pp!=buf)&&(pp==p))
360  {
361  printf("warning: proc should be in col. 1: line %d:%s",lines,buf);
362  }
363  else if (pp!=p)
364  {
365  footer++; get_next(); continue; /* this is not a proc start*/
366  }
367  p+=5; /* skip proc+blank*/
368  while(*p==' ') p++;
369  pp=p;
370  while(isalnum(*p)||(*p=='_')) p++;
371  *p='\0';
372  for(i=proc_cnt-1;i>=0;i--)
373  {
374  if(strcmp(proc[i],pp)==0) break;
375  }
376  if (i<0)
377  {
378  printf("hint: global proc %s not found in header\n",pp);
379  footer++; get_next();
380  }
381  else
382  {
383  proc_found[i]=1;
384  footer++; get_next(); /* doc should start at next line */
385  p=buf;
386  while(*p==' ') p++;
387  if (*p == '"') have_doc[i]=1;
388  /* serach for example */
389  while(!feof(f))
390  {
391  if(strncmp(buf,"proc ",5)==0) break;
392  if(strncmp(buf,"static proc ",12)==0) break;
393  if(strncmp(buf,"example",7)==0)
394  {
395  have_example[i]=1;
396  break;
397  }
398  footer++; get_next();
399  }
400  }
401  }
402  else {get_next();footer++;}
403  }
404  {
405  int i;
406  for(i=proc_cnt-1; i>=0;i--)
407  {
408  if(proc_found[i]==0) printf("proc %s not found\n",proc[i]);
409  else
410  {
411  if(have_doc[i]==0) printf("proc %s has no documentation\n",proc[i]);
412  if(have_example[i]==0) printf("proc %s has no example (or it does not start in col. 1)\n",proc[i]);
413  }
414  }
415  }
416  /* part 3: summary*/
417  printf("\nproc part parsed: %d lines of %s\n",footer,argv[1]);
418  if (have_version!=1) printf("version missing/duplicate (%d)\n",have_version);
419  if (have_category!=1) printf("category missing/duplicate (%d)\n",have_category);
420  if (have_info!=1) printf("info missing/duplicate (%d)\n",have_info);
421 
422  printf("\nGENERAL SUMMARY:\n");
423  if(tabs!=0) printf("warning: lib should not contain tabs, >=%d found\n",tabs);
424  if(trailing_spaces!=0) printf("hint: lib should not contain trailing_spaces, >=%d found\n",trailing_spaces);
425  if(verylong_lines!=0) printf("hint: lib should not contain very long lines, >=%d found\n",verylong_lines);
426  if(non_ascii>0)
427  printf("error: lib should not contain non-ascii characters, %d found, last in line %d\n",non_ascii, non_ascii_line);
428  if (crlf>=lines-1)
429  {
430  printf("warning: DOS format (%d)\n",crlf);
431  }
432  else if (crlf>0)
433  {
434  printf("error: some lines are in DOS format, some not (%d/%d)\n",crlf,lines);
435  }
436  printf("%d lines parsed\n",lines);
437  printf("%d proc found in header\n",proc_cnt);
438  fclose(f);
439  return 0;
440 }
unsigned char * proc[NUM_PROC]
Definition: checklibs.c:14
int crlf
Definition: checklibs.c:23
#define NUM_PROC
Definition: checklibs.c:4
return P p
Definition: myNF.cc:203
int non_ascii
Definition: checklibs.c:18
unsigned char proc_found[NUM_PROC]
Definition: checklibs.c:17
poly pp
Definition: myNF.cc:296
int non_ascii_line
Definition: checklibs.c:19
FILE * f
Definition: checklibs.c:7
int i
Definition: cfEzgcd.cc:123
int header
Definition: checklibs.c:22
int verylong_lines
Definition: checklibs.c:10
int trailing_spaces
Definition: checklibs.c:8
int lines
Definition: checklibs.c:11
unsigned char have_doc[NUM_PROC]
Definition: checklibs.c:15
unsigned char buf[LINE_LEN]
Definition: checklibs.c:12
int proc_cnt
Definition: checklibs.c:13
#define NULL
Definition: omList.c:10
int footer
Definition: checklibs.c:21
unsigned char have_example[NUM_PROC]
Definition: checklibs.c:16
void get_next()
Definition: checklibs.c:25
void scan_info(int *l)
Definition: checklibs.c:130
int tabs
Definition: checklibs.c:9

§ scan_info()

void scan_info ( int *  l)

Definition at line 130 of file checklibs.c.

131 {
132  int have_LIBRARY=0;
133  int have_AUTHORS=0;
134  int have_PROCEDURES=0;
135  int have_SEEALSO=0;
136  int have_KEYWORDS=0;
137  int have_OVERVIEW=0;
138  int have_NOTE=0;
139  int have_other=0;
140  int texinfo=0;
141  unsigned char *p;
142 
143  while(!feof(f))
144  {
145  if (strstr(buf,"LIBRARY: ")!=NULL)
146  {
147  have_LIBRARY++;
148  /* musrt be first*/
149  if (have_other+have_AUTHORS+have_PROCEDURES+have_KEYWORDS+have_SEEALSO!=0)
150  printf("error: LIBRARY: must be the first section in info\n");
151  }
152  else if (strstr(buf,"NOTE:")!=NULL)
153  {
154  if (have_PROCEDURES!=0)
155  printf("error: only KEYWORDS/SEE ALSO may follow PROCEDURES\n");
156  have_NOTE++;
157  }
158  else if (strstr(buf,"OVERVIEW:")!=NULL)
159  {
160  have_OVERVIEW++;
161  if (have_PROCEDURES!=0)
162  printf("error: only KEYWORDS/SEE ALSO may follow PROCEDURES\n");
163  }
164  else if (strstr(buf,"KEYWORDS: ")!=NULL)
165  {
166  have_KEYWORDS++;
167  }
168  else if (strstr(buf,"SEE ALSO: ")!=NULL)
169  {
170  have_SEEALSO++;
171  }
172  else if ((strstr(buf,"AUTHORS: ")!=NULL)
173  ||(strstr(buf,"AUTHOR: ")!=NULL))
174  {
175  have_AUTHORS++;
176  if (have_PROCEDURES!=0)
177  printf("error: only KEYWORDS/SEE ALSO may follow PROCEDURES\n");
178  }
179  else if ((p=strstr(buf,"PROCEDURES"))!=NULL)
180  {
181  unsigned char *pp=buf;
182  while (pp!=p)
183  {
184  if ((*pp!=' ')&&(*pp!='\t')) break;
185  pp++;
186  }
187  if (p==pp)
188  {
189  have_PROCEDURES++;
190  scan_proc(l);
191  continue;
192  }
193  else
194  {
195  printf("error: unknown section in library header: %s",buf);
196  have_other++;
197  }
198  }
199  else if ((p=strstr(buf,":"))!=NULL)
200  {
201  int ch;
202  unsigned char *pp=buf;
203  while((*pp==' ')||(*pp=='\t')) pp++;
204  ch=strspn(pp,"ABCDEFGHIJKLMNOPQRSTUVWXYZ");
205  if ((ch>1)||(pp+ch==p))
206  {
207  /* check for other allowed sections: REFERENCES*/
208  if ((ch!=10)||(strncmp(pp,"REFERENCES",10)!=0))
209  {
210  printf("error: unknown section in library header: %s",buf);
211  have_other++;
212  }
213  if (have_PROCEDURES!=0)
214  printf("error: only KEYWORDS/SEE ALSO may follow PROCEDURES\n");
215  }
216  }
217  else if (strncmp(buf,"\";",2)==0) goto e_o_info; /* poor mans end-of-info*/
218  else
219  {
220  p=buf;
221  if (strchr(buf,'@')!=NULL)
222  { texinfo++; printf("%s",buf); }
223  }
224  get_next(); (*l)++;
225  }
226  e_o_info:
227  printf("\nSUMMARY OF THE HEADER:\n");
228  if (have_LIBRARY!=1)
229  printf("error: missing/duplicate LIBRARY (%d lines found, should be 1)\n",have_LIBRARY);
230  if (have_AUTHORS!=1)
231  printf("error: missing/duplicate AUTHOR/AUTHORS (%d lines found, should be 1)\n",have_AUTHORS);
232  if (have_PROCEDURES!=1)
233  printf("error: missing/duplicate PROCEDURES (%d lines found, should be 1)\n",have_PROCEDURES);
234  if (have_SEEALSO>1)
235  printf("error: duplicate SEE ALSO (%d lines found)\n",have_SEEALSO);
236  if (have_KEYWORDS>1)
237  printf("error: duplicate KEYWORDS (%d lines found)\n",have_KEYWORDS);
238  if (have_NOTE==1)
239  printf("hint: avoid NOTE: if not used for a library requirement\n");
240  else if (have_NOTE>1)
241  printf("error: duplicate NOTE (%d lines found)\n",have_NOTE);
242  if ((have_OVERVIEW==1)&&(proc_cnt<3))
243  printf("hint: avoid OVERVIEW: for small libraries\n");
244  else if (have_OVERVIEW>1)
245  printf("error: duplicate OVERVIEW (%d lines found)\n",have_OVERVIEW);
246 
247  if (have_other!=0)
248  printf("error: other header entries found (illegal ?) :%d lines found, should be 0\n",have_other);
249  if ((star_nl>0)&&(star_nl*10>=header))
250  {
251  printf("warning: %d forced line breaks in %d header lines: @* should be used very rarely!\n",star_nl,header);
252  }
253  if (texinfo>0)
254  {
255  printf("warning: %d texinfo commands in %d header lines: should be used very rarely!\n",texinfo,header);
256  }
257 }
return P p
Definition: myNF.cc:203
poly pp
Definition: myNF.cc:296
void scan_proc(int *l)
Definition: checklibs.c:55
FILE * f
Definition: checklibs.c:7
int header
Definition: checklibs.c:22
unsigned char buf[LINE_LEN]
Definition: checklibs.c:12
int proc_cnt
Definition: checklibs.c:13
#define NULL
Definition: omList.c:10
void get_next()
Definition: checklibs.c:25
int star_nl
Definition: checklibs.c:20
int l
Definition: cfEzgcd.cc:94

§ scan_keywords()

void scan_keywords ( int *  l)

Definition at line 99 of file checklibs.c.

100 {
101  /* the main problem with KEYWORDS: seperator between is ;,
102  * but it MUST NOT appear at the end */
103  unsigned char *p;
104  while(!feof(f))
105  {
106  p=strrchr(buf,';'); /* the last ; in the line*/
107  if (p==NULL) { get_next(); (*l)++; return; }
108  while (*p==' ') p++;
109  if (isalpha(*p)) { get_next(); (*l)++; return; }
110  if (*p=='\0') { get_next(); (*l)++; }
111  else if (strstr(buf,"LIB ")!=NULL) break;
112  else if (strstr(buf,"LIB\"")!=NULL) break;
113  else if (strstr(buf,"proc ")!=NULL) break;
114  else if (strncmp(buf,"\";",2)==0) break; /* poor mans end-of-info*/
115  else if ((p=strstr(buf,":"))!=NULL)
116  { /* handles all capital letters + : */
117  /* SEE ALSO, KEYWORDS, NOTE, ... */
118  int ch;
119  unsigned char *pp=buf;
120  while((*pp==' ')||(*pp=='\t')) pp++;
121  ch=strspn(pp,"ABCDEFGHIJKLMNOPQRSTUVWXYZ");
122  if ((ch>1)||(pp+ch==p))
123  {
124  break;
125  }
126  }
127  }
128  printf("error: seperate keywords by ; but do not have ; after the last keyword\n");
129 }
return P p
Definition: myNF.cc:203
poly pp
Definition: myNF.cc:296
FILE * f
Definition: checklibs.c:7
unsigned char buf[LINE_LEN]
Definition: checklibs.c:12
#define NULL
Definition: omList.c:10
void get_next()
Definition: checklibs.c:25

§ scan_proc()

void scan_proc ( int *  l)

Definition at line 55 of file checklibs.c.

56 {
57  unsigned char *p;
58  while(1)
59  {
60  get_next(); (*l)++;
61  if (((p=strchr(buf,'('))!=NULL)&&(isalnum(*(--p))||(*p=='_')))
62  {
63  unsigned char *s=buf;
64  while(*s==' ') s++;
65  p++; (*p)='\0';
66  if ((((int)(long)(s-buf))>10)||(strchr(s,' ')!=NULL))
67  {
68  printf("warning: probably not a proc ? (%s)\n",s);
69  }
70  else
71  {
72  if (strlen(s)<4)
73  printf("error: minimal length of a procedure name is 4: %s\n",s);
75  }
76  }
77  else if (strstr(buf,"LIB ")!=NULL) break;
78  else if (strstr(buf,"LIB\"")!=NULL) break;
79  else if (strstr(buf,"proc ")!=NULL) break;
80  else if (strncmp(buf,"\";",2)==0) break; /* poor mans end-of-info*/
81  else if ((p=strstr(buf,":"))!=NULL)
82  { /* handles all capital letters + : */
83  /* SEE ALSO, KEYWORDS, NOTE, ... */
84  int ch;
85  unsigned char *pp=buf;
86  while((*pp==' ')||(*pp=='\t')) pp++;
87  ch=strspn(pp,"ABCDEFGHIJKLMNOPQRSTUVWXYZ");
88  if ((ch>1)||(pp+ch==p))
89  {
90  break;
91  }
92  }
93  }
94  if (proc_cnt==0)
95  printf("warning: no proc found in the section PROCEDURES ?\n");
96  printf("\n# proc mentioned in the header: %d\n",proc_cnt);
97 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
unsigned char * proc[NUM_PROC]
Definition: checklibs.c:14
return P p
Definition: myNF.cc:203
poly pp
Definition: myNF.cc:296
#define strdup
Definition: omAllocFunc.c:17
unsigned char buf[LINE_LEN]
Definition: checklibs.c:12
int proc_cnt
Definition: checklibs.c:13
#define NULL
Definition: omList.c:10
void get_next()
Definition: checklibs.c:25

Variable Documentation

§ buf

unsigned char buf[LINE_LEN]

Definition at line 12 of file checklibs.c.

§ crlf

int crlf =0

Definition at line 23 of file checklibs.c.

§ f

FILE* f

Definition at line 7 of file checklibs.c.

§ footer

int footer =0

Definition at line 21 of file checklibs.c.

§ have_doc

unsigned char have_doc[NUM_PROC]

Definition at line 15 of file checklibs.c.

§ have_example

unsigned char have_example[NUM_PROC]

Definition at line 16 of file checklibs.c.

§ header

int header =0

Definition at line 22 of file checklibs.c.

§ lines

int lines =0

Definition at line 11 of file checklibs.c.

§ non_ascii

int non_ascii =0

Definition at line 18 of file checklibs.c.

§ non_ascii_line

int non_ascii_line =0

Definition at line 19 of file checklibs.c.

§ proc

unsigned char* proc[NUM_PROC]

Definition at line 14 of file checklibs.c.

§ proc_cnt

int proc_cnt =0

Definition at line 13 of file checklibs.c.

§ proc_found

unsigned char proc_found[NUM_PROC]

Definition at line 17 of file checklibs.c.

§ star_nl

int star_nl =0

Definition at line 20 of file checklibs.c.

§ tabs

int tabs =0

Definition at line 9 of file checklibs.c.

§ trailing_spaces

int trailing_spaces =0

Definition at line 8 of file checklibs.c.

§ verylong_lines

int verylong_lines =0

Definition at line 10 of file checklibs.c.