source: git/Singular/utils.cc @ 82716e

spielwiese
Last change on this file since 82716e was 6be769, checked in by Kai Krüger <krueger@…>, 26 years ago
Changes for help-section of procedures git-svn-id: file:///usr/local/Singular/svn/trunk@1672 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 5.2 KB
Line 
1#include <stdio.h>
2#include <string.h>
3#include <stdlib.h>
4#include <ctype.h>
5#include "utils.h"
6
7extern FILE *yylpin;
8extern char *optarg;
9extern int optind, opterr, optopt;
10extern int lpverbose, check;
11extern int found_version, found_info, found_oldhelp, found_proc_in_proc;
12warning_info = 0, warning_version = 0;
13/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
14void main_init(int argc, char *argv[])
15{
16  char c, *file=NULL;
17
18  while((c=getopt(argc, argv, "d:sf:"))>=0) {
19    switch(c)
20      {
21      case 'd':
22        lpverbose = 1;
23        if(isdigit(argv[optind-1][0])) sscanf(optarg, "%d", &lpverbose);
24        else optind--;
25        break;
26      case 'f': file = argv[optind-1];
27        break;
28      case 's':
29        check++;
30        break;
31      case -1 : printf("no such option:%s\n", argv[optind]);
32        break;
33      default: printf("no such option.%x, %c %s\n", c&0xff, c, argv[optind]);
34      }
35  }
36  if(file!=NULL) {
37    yylpin = fopen( file, "rb" );
38    printf("Checking library '%s'\n", file);
39  } else {
40    while(argc>optind && yylpin==NULL) {
41      yylpin = fopen( argv[optind], "rb" );
42      if(yylpin!=NULL) printf("Checking library '%s'\n", argv[optind]);
43      else optind++;
44    }
45  }
46}
47
48/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
49void main_result(char *libname)
50{
51  if(!found_info)    printf("*** No info-string found!\n");
52  if(!found_version) printf("*** No version-string found!\n");
53  if(found_oldhelp)  printf("*** Library has stil OLD library-format.\n");
54  if(found_info && warning_info)
55    printf("*** INFO-string should come before every procedure definition.\n");
56  if(found_version && warning_version)
57    printf("*** VERSION-string should come before every procedure definition.\n");
58}
59/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
60
61procinfo *iiInitSingularProcinfo(procinfov pi, char *libname,
62                                 char *procname, int line, long pos,
63                                 BOOLEAN pstatic = FALSE)
64{
65  pi->libname = (char *)malloc(strlen(libname)+1);
66  memcpy(pi->libname, libname, strlen(libname));
67  *(pi->libname+strlen(libname)) = '\0';
68
69  pi->procname = (char *)malloc(strlen(procname)+1);
70  strcpy(pi->procname, procname/*, strlen(procname)*/);
71  pi->language = LANG_SINGULAR;
72  pi->ref = 1;
73  pi->is_static = pstatic;
74  pi->data.s.proc_start = pos;
75  pi->data.s.def_end    = 0L;
76  pi->data.s.help_start = 0L;
77  pi->data.s.body_start = 0L;
78  pi->data.s.body_end   = 0L;
79  pi->data.s.example_start = 0L;
80  pi->data.s.proc_lineno = line;
81  pi->data.s.body_lineno = 0;
82  pi->data.s.example_lineno = 0;
83  pi->data.s.body = NULL;
84  return(pi);
85}
86
87/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
88pi_clear(procinfov pi)
89{
90  free(pi->libname);
91  free(pi->procname);
92  free(pi);
93}
94
95/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
96printpi(procinfov pi)
97{
98  FILE *fp = fopen( pi->libname, "rb");
99  char *buf, name[256];
100  int len1, len2;
101
102  if(!found_info && !warning_info) warning_info++;
103  if(!found_version && !warning_version) warning_version++;
104  if(pi->data.s.body_end==0) 
105    pi->data.s.body_end = pi->data.s.proc_end;
106
107  if(lpverbose) printf("//     ");
108  printf( "%c %-15s  %20s ", pi->is_static ? 'l' : 'g', pi->libname,
109          pi->procname);
110  printf("line %4d,%5ld-%-5ld  %4d,%5ld-%-5ld  %4d,%5ld-%-5ld\n",
111         pi->data.s.proc_lineno, pi->data.s.proc_start, pi->data.s.def_end,
112         pi->data.s.body_lineno, pi->data.s.body_start, pi->data.s.body_end,
113         pi->data.s.example_lineno, pi->data.s.example_start,
114         pi->data.s.proc_end);
115  if(check) {
116    if(!pi->is_static && (pi->data.s.body_start-pi->data.s.def_end)<4)
117      printf("*** Procedure '%s' is global and has no help-section.\n",
118             pi->procname);
119    if(!pi->is_static && !pi->data.s.example_start)
120      printf("*** Procedure '%s' is global and has no example-section.\n",\
121             pi->procname);
122    if(found_proc_in_proc)
123      printf("*** found proc within procedure '%s'.\n", pi->procname);
124  }
125
126#if 0
127  if( fp != NULL) { // loading body
128    len1 = pi->data.s.def_end - pi->data.s.proc_start;
129    if(pi->data.s.body_end==0)
130      len2 = pi->data.s.proc_end - pi->data.s.body_start;
131    else len2 = pi->data.s.body_end - pi->data.s.body_start;
132    buf = (char *)malloc(len1 + len2 + 1);
133    fseek(fp, pi->data.s.proc_start, SEEK_SET);
134    fread( buf, len1, 1, fp);
135    *(buf+len1) = '\n';
136    fseek(fp, pi->data.s.body_start, SEEK_SET);
137    fread( buf+len1+1, len2, 1, fp);
138    *(buf+len1+len2+1)='\0';
139    printf("##BODY:'%s'##\n", buf);
140    free(buf);
141
142    // loading help
143    len1 = pi->data.s.body_start - pi->data.s.proc_start;
144    printf("len1=%d;\n", len1);
145    buf = (char *)malloc(len1+1);
146    fseek(fp, pi->data.s.proc_start, SEEK_SET);
147    fread( buf, len1, 1, fp);
148    *(buf+len1)='\0';
149    printf("##HELP:'%s'##\n", buf);
150    free(buf);
151
152    if(pi->data.s.example_start>0) { // loading example
153      fseek(fp, pi->data.s.example_start, SEEK_SET);
154      len2 = pi->data.s.proc_end - pi->data.s.example_start;
155      buf = (char *)malloc(len2+1);
156      fread( buf, len2, 1, fp);
157      *(buf+len2)='\0';
158      printf("##EXAMPLE:'%s'##\n", buf);
159      free(buf);
160    }
161
162    fclose(fp);
163    //getchar();
164  }
165#endif
166}
167
168/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
Note: See TracBrowser for help on using the repository browser.