source: git/Singular/utils.cc @ f5d2647

spielwiese
Last change on this file since f5d2647 was ba5e9e, checked in by Oleksandr Motsak <motsak@…>, 11 years ago
Changed configure-scripts to generate individual public config files for each package: resources, libpolys, singular (main) fix: sources should include correct corresponding config headers.
  • Property mode set to 100644
File size: 7.3 KB
RevLine 
[45d13f1]1#ifdef STANDALONE_PARSER
[16f511]2#ifdef HAVE_CONFIG_H
[ba5e9e]3#include "singularconfig.h"
[16f511]4#endif /* HAVE_CONFIG_H */
[762407]5#include <kernel/mod2.h>
6
[33d539]7#include <stdio.h>
8#include <string.h>
9#include <stdlib.h>
10#include <ctype.h>
[bd795d]11
12#include <Singular/fegetopt.h>
[599326]13#include <Singular/utils.h>
14#include <Singular/libparse.h>
[33d539]15
[d2b2a7]16extern FILE *yylpin;
17extern char *optarg;
18extern int optind, opterr, optopt;
19extern int lpverbose, check;
[f36635]20extern int texinfo_out;
[eb0708]21
[45d13f1]22extern int category_out;
[eb0708]23
[d2b2a7]24extern int found_version, found_info, found_oldhelp, found_proc_in_proc;
[901748b]25int warning_info = 0, warning_version = 0;
[a5279ce]26
[a70441f]27static void usage(char *progname)
[a5279ce]28{
29  printf("libparse: a syntax-checker for Singular Libraries.\n");
30  printf("USAGE: %s [options] singular-library\n", progname);
31  printf("Options:\n");
[c052d0]32  printf("   -f <singular library> : performs syntax-checks\n");
[a5279ce]33  printf("   -d [digit]            : digit=1,..,4 increases the verbosity of the checks\n");
[c052d0]34  printf("   -s                    : turns on reporting about violations of unenforced syntax rules\n");
[f36635]35  printf("   -i                    : perl output of examples and help of procs\n");
[5ecf042]36  printf("   -c                    : print category of lib to stdout and exit\n");
[a5279ce]37  printf("   -h                    : print this message\n");
38  exit(1);
39}
[a3bc95e]40
[f36635]41static char* lib_file = NULL;
[8a150b]42
[d2b2a7]43/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
44void main_init(int argc, char *argv[])
45{
[f36635]46  char c;
[d2b2a7]47
[f2c53c0]48  while((c=fe_getopt(argc, argv, "ihdc:sf:"))>=0)
49  {
50    switch(c)
51    {
[a5279ce]52        case 'd':
53          lpverbose = 1;
[c06a32]54          if(isdigit(argv[fe_optind-1][0])) sscanf(optarg, "%d", &lpverbose);
55          else fe_optind--;
[a5279ce]56          break;
[c06a32]57        case 'f': lib_file = argv[fe_optind-1];
[a5279ce]58          break;
59        case 's':
60          check++;
61          break;
[f36635]62        case 'i':
63          texinfo_out = 1;
64          break;
[5ecf042]65        case 'c':
66          category_out = 1;
67          break;
68
[a5279ce]69        case 'h' :
70          usage(argv[0]);
71          break;
[c06a32]72        case -1 : printf("no such option:%s\n", argv[fe_optind]);
[a5279ce]73          usage(argv[0]);
74          break;
[c06a32]75        default: printf("no such option.%x, %c %s\n", c&0xff, c, argv[fe_optind]);
[a5279ce]76          usage(argv[0]);
77    }
[d2b2a7]78  }
[5ecf042]79  if (texinfo_out || category_out) lpverbose = 0;
[a3bc95e]80
[f2c53c0]81  if(lib_file!=NULL)
82  {
[f36635]83    yylpin = fopen( lib_file, "rb" );
[a3bc95e]84    if (! (texinfo_out || category_out))
[f36635]85      printf("Checking library '%s'\n", lib_file);
[5ecf042]86    else if (! category_out)
[f36635]87      printf("$library = \"%s\";\n", lib_file);
[f2c53c0]88  }
89  else
90  {
91    while(argc>fe_optind && yylpin==NULL)
92    {
[c06a32]93      yylpin = fopen( argv[fe_optind], "rb" );
[a3bc95e]94      if(yylpin!=NULL)
[f36635]95      {
[c06a32]96        lib_file = argv[fe_optind];
[5ecf042]97        if (! (texinfo_out || category_out) )
[c06a32]98          printf("Checking library '%s'\n", argv[fe_optind]);
[5ecf042]99        else if (! category_out)
[f36635]100          printf("$library = \"%s\";\n", lib_file);
101      }
[c06a32]102      else fe_optind++;
[6be769]103    }
104  }
[f2c53c0]105  if(yylpin == NULL)
106  {
[a5279ce]107    printf("No library found to parse.\n");
108    usage(argv[0]);
109  }
[d2b2a7]110}
111
112/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
[2e4ec14]113void main_result(char */*libname*/)
[d2b2a7]114{
115  if(!found_info)    printf("*** No info-string found!\n");
116  if(!found_version) printf("*** No version-string found!\n");
117  if(found_oldhelp)  printf("*** Library has stil OLD library-format.\n");
118  if(found_info && warning_info)
119    printf("*** INFO-string should come before every procedure definition.\n");
120  if(found_version && warning_version)
121    printf("*** VERSION-string should come before every procedure definition.\n");
122}
[33d539]123/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
[45d13f1]124procinfo *iiInitSingularProcinfo(procinfo* pi, const char *libname,
125                                 const char *procname, int line, long pos,
126                                 BOOLEAN pstatic /*= FALSE*/)
127{
128  pi->libname = (char *)malloc(strlen(libname)+1);
129  memcpy(pi->libname, libname, strlen(libname));
130  *(pi->libname+strlen(libname)) = '\0';
131
132  pi->procname = (char *)malloc(strlen(procname)+1);
133  strcpy(pi->procname, procname/*, strlen(procname)*/);
134  pi->language = LANG_SINGULAR;
135  pi->ref = 1;
136  pi->is_static = pstatic;
137  pi->data.s.proc_start = pos;
138  pi->data.s.def_end    = 0L;
139  pi->data.s.help_start = 0L;
140  pi->data.s.body_start = 0L;
141  pi->data.s.body_end   = 0L;
142  pi->data.s.example_start = 0L;
143  pi->data.s.proc_lineno = line;
144  pi->data.s.body_lineno = 0;
145  pi->data.s.example_lineno = 0;
146  pi->data.s.body = NULL;
147  pi->data.s.help_chksum = 0;
148  return(pi);
149}
[33d539]150
151/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
[a70441f]152void pi_clear(procinfov pi)
[33d539]153{
154  free(pi->libname);
155  free(pi->procname);
156  free(pi);
157}
158
159/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
[f36635]160
161#ifndef SEEK_SET
162#define SEEK_SET 0
163#endif
164
165static void PrintOut(FILE *fd, int pos_start, int pos_end)
166{
167  if (pos_start <= 0 || pos_end - pos_start <= 4) return;
[dcc635]168  char c = 0;
[a3bc95e]169
[f36635]170  fseek(fd, pos_start, SEEK_SET);
[a3bc95e]171  while (pos_start++ <= pos_end)
[f36635]172  {
[dcc635]173    if (c == '\\')
174    {
175      c = fgetc(fd);
176      if (c != '"') putchar('\\');
177    }
178    else
179      c = fgetc(fd);
180    if (c == '@' || c == '$') putchar('\\');
[f36635]181    if (c != '\r') putchar(c);
182  }
[dcc635]183  if (c == '\\') putchar('\\');
[f36635]184}
185
186
[a70441f]187void printpi(procinfov pi)
[33d539]188{
[6909cfb]189  // char *buf, name[256];
190  // int len1, len2;
[f36635]191  /* pi->libname is badly broken -- use file, instead */
192  FILE *fp = fopen( lib_file, "rb");
193
[a3bc95e]194  if (fp == NULL)
[f36635]195  {
196    printf("Can not open %s\n", lib_file);
[a70441f]197    return;
[f36635]198  }
[33d539]199
[d2b2a7]200  if(!found_info && !warning_info) warning_info++;
201  if(!found_version && !warning_version) warning_version++;
[8a150b]202  if(pi->data.s.body_end==0)
[33d539]203    pi->data.s.body_end = pi->data.s.proc_end;
204
[f36635]205  if (texinfo_out)
206  {
[b0d726]207   if ((! pi->is_static) &&
[f36635]208        (pi->data.s.body_start - pi->data.s.def_end > 10) &&
209        (! found_proc_in_proc))
210    {
211      printf("push(@procs, \"%s\");\n", pi->procname);
212      printf("$help{\"%s\"} = <<EOT;\n", pi->procname);
213      PrintOut(fp, pi->data.s.help_start, pi->data.s.body_start-3);
214      printf("\nEOT\n");
[b0d726]215      if ((pi->data.s.example_start > 0) &&
216          (pi->data.s.proc_end - pi->data.s.example_start > 10))
217      {
218        printf("$example{\"%s\"} = <<EOT;\n", pi->procname);
219        PrintOut(fp, pi->data.s.example_start, pi->data.s.proc_end);
220        printf("\nEOT\n");
221      }
[f2c53c0]222      printf("$chksum{\"%s\"} = %ld;\n", pi->procname, pi->data.s.help_chksum);
[f36635]223    }
224  }
[5ecf042]225  else if (! category_out)
[f36635]226  {
227    if(lpverbose) printf("//     ");
228    printf( "%c %-15s  %20s ", pi->is_static ? 'l' : 'g', pi->libname,
229            pi->procname);
230    printf("line %4d,%5ld-%-5ld  %4d,%5ld-%-5ld  %4d,%5ld-%-5ld\n",
231           pi->data.s.proc_lineno, pi->data.s.proc_start, pi->data.s.def_end,
232           pi->data.s.body_lineno, pi->data.s.body_start, pi->data.s.body_end,
233           pi->data.s.example_lineno, pi->data.s.example_start,
234           pi->data.s.proc_end);
235    if(check) {
236      if(!pi->is_static && (pi->data.s.body_start-pi->data.s.def_end)<4)
237        printf("*** Procedure '%s' is global and has no help-section.\n",
238               pi->procname);
239      if(!pi->is_static && !pi->data.s.example_start)
240        printf("*** Procedure '%s' is global and has no example-section.\n",\
241               pi->procname);
242      if(found_proc_in_proc)
243        printf("*** found proc within procedure '%s'.\n", pi->procname);
244    }
[d2b2a7]245  }
[a3bc95e]246
[902ef1]247  if (fp != NULL) fclose(fp);
[33d539]248
249}
250
251/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
[45d13f1]252#endif
Note: See TracBrowser for help on using the repository browser.