Changeset 664898 in git for modules


Ignore:
Timestamp:
Feb 18, 2000, 2:33:49 PM (24 years ago)
Author:
Kai Krüger <krueger@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
e6189d7d94063f84c1afeb64ccf22c4873faa388
Parents:
f3929a22e27e0ec2f0392fd4d0f481110133cffc
Message:
 	* creat_top.cc, grammar.y, makefile.cc, modgen.h
	* proc.cc, utils.cc, scanner.l
	  fixed generation syntax (e.g. missing ';')
	  Packed example and help into separated sections
	  Added generation of makefile


git-svn-id: file:///usr/local/Singular/svn/trunk@4157 2c84dea3-7e68-4137-9b89-c4e89433aadc
Location:
modules/modgen
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • modules/modgen/creat_top.cc

    rf3929a r664898  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: creat_top.cc,v 1.5 2000-02-14 21:44:39 krueger Exp $ */
     4/* $Id: creat_top.cc,v 1.6 2000-02-18 13:33:47 krueger Exp $ */
    55/*
    66* ABSTRACT: lib parsing
     
    3232void write_enter_id(FILE *fp)
    3333{
    34   fprintf(fp, "idhdl enter_id(char *name, char *value, idtyp t)\n");
     34  fprintf(fp, "\nidhdl enter_id(char *name, char *value, idtyp t)\n");
    3535  fprintf(fp, "{\n");
    3636  fprintf(fp, "  idhdl h;\n");
     
    3939  fprintf(fp, "  if(h!=NULL) {\n");
    4040  fprintf(fp, "     switch(t) {\n");
    41   fprintf(fp, "       case STRING_CMD: IDSTRING(h) = mstrdup(value);break\n");
    42   fprintf(fp, "       case PACKAGE_CMD: break;\n");
    43   fprintf(fp, "       case PROC_CMD: break;\n");
     41  fprintf(fp, "         case STRING_CMD: IDSTRING(h) = mstrdup(value);break;\n");
     42  fprintf(fp, "         case PACKAGE_CMD: break;\n");
     43  fprintf(fp, "         case PROC_CMD: break;\n");
    4444  fprintf(fp, "     }\n");
    4545  fprintf(fp, "  }\n");
     
    5151void write_add_singular_proc(FILE *fp)
    5252{
    53   fprintf(fp, "idhdl add_singular_proc(char *procname, int line,\n");
     53  fprintf(fp, "\nidhdl add_singular_proc(char *procname, int line,\n");
    5454  fprintf(fp, "                       long pos, long end, BOOLEAN pstatic)\n");
    5555  fprintf(fp, "{\n");
    5656  fprintf(fp, "  idhdl h;\n");
    5757  fprintf(fp, "  procinfov pi;\n\n");
    58   fprintf(fp, "  h = enter_id(name, NULL, PROC_CMD);\n");
     58  fprintf(fp, "  h = enter_id(procname, NULL, PROC_CMD);\n");
    5959  fprintf(fp, "  if(h == NULL) return NULL;\n");
    6060  fprintf(fp, "\n");
     
    117117  fclose(module->fmtfp);
    118118  if(create_tmpfile(module)) return -1;
    119 
     119  if(create_tmpfile(module, 1)) return -1;
     120  if(create_tmpfile(module, 2)) return -1;
     121  if(module->fmtfp2 == NULL) { printf("Cannot write HELP\n"); return -1; }
     122  if(module->fmtfp3 == NULL) { printf("Cannot write EXAMPLE\n"); return -1; }
     123  printf("%p %p %p\n", module->fmtfp, module->fmtfp2, module->fmtfp3);
     124 
     125 
    120126  sprintf(filename, "tmp/%s.h", module->name);
    121127  if( (module->modfp_h = fopen(filename, "w")) == NULL) {
     
    128134  free(filename);
    129135//  write_enter_id(module->modfp);
     136  return 0;
    130137}
  • modules/modgen/grammar.y

    rf3929a r664898  
    11/*
    2  * $Id: grammar.y,v 1.6 2000-02-14 21:41:59 krueger Exp $
     2 * $Id: grammar.y,v 1.7 2000-02-18 13:33:47 krueger Exp $
    33 */
    44
     
    8888part1: initmod sect1 sect1end
    8989        {
    90          if(write_intro(&module_def))
    91            myyyerror("Error while creating files\n");
     90          mod_create_makefile(&module_def);
     91          if(write_intro(&module_def)) {
     92            myyyerror("Error while creating files\n");
     93            return 1;
     94          }
    9295        };
    9396
     
    151154          switch(sectnum) {
    152155              case 1: /* pass 1: */
     156                Add2files(&module_def, $3);
    153157                break;
    154158              case 2: /* pass 2: procedure declaration */
     
    231235        {
    232236          printf(">>>>>>>>files '%s' , '%s'\n", $1, $3);
     237          Add2files(&module_def, $1);
     238          Add2files(&module_def, $3);
    233239          free($1);
    234240          free($3);
     
    293299         {
    294300           write_singular_parameter(&module_def, yylineno, "list", "#");
     301           procedure_decl.lineno_other = yylineno;
    295302         }
    296303        | procdecl1 '(' ')'
    297304         {
    298305           write_singular_parameter(&module_def, yylineno, "list", "#");
     306           procedure_decl.lineno_other = yylineno;
    299307         }
    300308        ;
     
    331339        {
    332340          procedure_decl.help_string = $1;
    333           printf("\t\thelp=%p, %d\n", procedure_decl.help_string, strlen($1));
     341          printf("\t\thelp at %d\n", yylineno);
     342          write_help(&module_def, &procedure_decl);
    334343        }
    335344        ;
     
    353362        };
    354363
    355 procdeclexample: EXAMPLETOK '{' examplecodeline MCODETOK
    356         {
    357           printf("Example\n");
    358           if(procedure_decl.procname != NULL) {
    359             //write_example(&module_def, &procedure_decl);
    360           } else {
     364procdeclexample: examplestart '{' examplecodeline MCODETOK
     365        {
     366          write_example(&module_def, &procedure_decl);
     367        }
     368        ;
     369
     370examplestart: EXAMPLETOK
     371        {
     372          if(procedure_decl.procname == NULL) {
    361373            myyyerror("example without proc-declaration at line %d\n",
    362374                     yylineno);
    363375          }
    364         }
    365         ;
    366 
     376          printf("Example at %d\n", yylineno);
     377          procedure_decl.lineno_other = yylineno;
     378        };
     379 
    367380examplecodeline: CODEPART
    368381        {
    369           printf(">>1\n");
    370           procedure_decl.example_len = strlen($1);
    371           procedure_decl.example_string = (char *)malloc(strlen($1)+1);
    372           memset(procedure_decl.example_string, 0, strlen($1)+1);
    373           memcpy(procedure_decl.example_string, $1, strlen($1));
     382          int len = strlen($1);
     383          procedure_decl.example_len = len;
     384          procedure_decl.example_string = (char *)malloc(len+1);
     385          memset(procedure_decl.example_string, 0, len+1);
     386          memcpy(procedure_decl.example_string, $1, len);
    374387        }
    375388        | examplecodeline CODEPART
    376389        {
    377           long newlen = procedure_decl.example_len + strlen($2);
    378           //procedure_decl.example_len += strlen($2);
    379           printf(">>2 (%d+%d) %p\n", procedure_decl.example_len, strlen($2),
    380                  procedure_decl.example_string);
     390          long len = strlen($2);
     391          long newlen = procedure_decl.example_len + len;
     392         
    381393          procedure_decl.example_string =
    382             (char *)realloc((void *)procedure_decl.example_string, newlen);
    383           printf(">>2 (%d)\n", procedure_decl.example_len);
     394            (char *)realloc((void *)procedure_decl.example_string, newlen+1);
    384395          memset(procedure_decl.example_string+procedure_decl.example_len,
    385                  0, strlen($2));
     396                 0, len+1);
    386397          memcpy(procedure_decl.example_string+procedure_decl.example_len,
    387                  $2, strlen($2));
    388          
     398                 $2, len);
     399          procedure_decl.example_len = newlen;
    389400          //strncat(procedure_decl.example_string, $2, strlen($2));
    390401          //procedure_decl.example_string[procedure_decl.example_len] = '\0';
    391           printf(">>2b\n");
    392402        };
    393403
  • modules/modgen/makefile.cc

    rf3929a r664898  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: makefile.cc,v 1.1 1999-11-23 21:30:21 krueger Exp $ */
     4/* $Id: makefile.cc,v 1.2 2000-02-18 13:33:48 krueger Exp $ */
    55/*
    66* ABSTRACT: lib parsing
     
    2222#include "pathnames.h"
    2323
    24 void build_head_section(FILE *fp, moddefv module);
    25 void build_compile_section(FILE *fp, moddefv module);
    26 void build_clean_section(FILE *fp, moddefv module);
    27 void build_install_section(FILE *fp, moddefv module);
     24extern void mod_create_makefile(moddefv module);
     25extern void build_head_section(FILE *fp, moddefv module);
     26extern void build_clean_section(FILE *fp, moddefv module);
     27extern void build_install_section(FILE *fp, moddefv module);
     28extern void build_compile_section(FILE *fp, moddefv module);
     29
    2830static char *object_name(char *p);
     31/*========================================================================*/
     32/*
     33  run mod_create_makefile();
     34   
     35 */
     36/*========================================================================*/
    2937
    3038
     
    3341{
    3442  FILE *fp;
    35   fp = fopen("Makefile", "w");
     43  fp = fopen("tmp/Makefile", "w");
    3644  cfilesv cf = module->files;
    3745  int i;
     
    4048  write_header(fp, module->name, "#");
    4149  build_head_section(fp, module);
    42   fprintf(fp, "SRCS\t= ");
     50  fprintf(fp, "SRCS\t= %s.cc", module->name);
    4351 
    4452  for(i=0; i<module->filecnt; i++)
    45     fprintf(fp, "%s ", cf[i].filename);
    46 
    47   fprintf(fp, "\nOBJS\t= ");
     53    fprintf(fp, " %s", cf[i].filename);
     54
     55  fprintf(fp, "\nOBJS\t= %s.o", module->name);
    4856  for(i=0; i<module->filecnt; i++)
    49     fprintf(fp, "%s ", object_name(cf[i].filename));
     57    fprintf(fp, " %s", object_name(cf[i].filename));
    5058
    5159  fprintf(fp, "\n\n");
     
    6977  fprintf(fp, "CC\t= gcc\n");
    7078  fprintf(fp, "CXX\t= gcc\n");
    71   fprintf(fp, "CFLAGS\t= -DNDEBUG -DBUILD_MODULE -I. -I../include\n");
     79  fprintf(fp, "CFLAGS\t= -DNDEBUG -DBUILD_MODULE -I. -I../../include\n");
    7280  fprintf(fp, "#LD\t=\n");
    7381  fprintf(fp, "\n");
     
    163171
    164172/*========================================================================*/
    165 #  ifdef 68k_MPW
     173#  ifdef m68k_MPW
    166174void build_compile_section(
    167175  FILE *fp,
  • modules/modgen/modgen.h

    rf3929a r664898  
    11/*
    2  *  $Id: modgen.h,v 1.6 2000-02-14 21:43:32 krueger Exp $
     2 *  $Id: modgen.h,v 1.7 2000-02-18 13:33:48 krueger Exp $
    33 *
    44 */
     
    5252  language_defs language;
    5353  int          lineno;
     54  int          lineno_other;
    5455  int          is_static;
    5556  paramdef     return_val;
     
    7677  FILE * modfp_h;         /* header file */
    7778  FILE * fmtfp;           /* temporary file */
     79  FILE * fmtfp2;          /* temporary file */
     80  FILE * fmtfp3;          /* temporary file */
    7881  FILE * binfp;           /* include singular procedures are stored
    7982                             in an extra file */
     
    138141void AddParam(procdefv p, paramdefv vnew, char *name = NULL);
    139142
    140 extern int create_tmpfile(moddefv module_def);
     143/* from makefile.cc */
     144extern void mod_create_makefile(moddefv module);
     145extern void build_head_section(FILE *fp, moddefv module);
     146extern void build_clean_section(FILE *fp, moddefv module);
     147extern void build_install_section(FILE *fp, moddefv module);
     148static char *object_name(char *p);
     149extern void build_compile_section(FILE *fp, moddefv module);
     150
     151/* from utils.cc */
     152extern int create_tmpfile(moddefv module_def, int which = 0);
    141153
    142154/* from proc_setup.cc */
     
    144156
    145157/* from proc.cc */
    146 extern void write_example(moddefv module, procdefv proc);
    147 
    148158extern void write_procedure_typecheck(moddefv module, procdefv pi, FILE *fmtfp);
    149159extern void write_procedure_return(moddefv module, procdefv pi, FILE *fmtfp);
     
    152162extern void write_function_return(moddefv module, procdefv pi, void *arg = NULL);
    153163extern void write_function_errorhandling(moddefv module, procdefv pi);
     164extern void write_help(moddefv module, procdefv pi);
     165extern void write_example(moddefv module, procdefv pi);
    154166extern int  write_singular_procedures(moddefv module, procdefv proc);
    155167extern void write_singular_parameter(moddefv module,int lineno,
  • modules/modgen/proc.cc

    rf3929a r664898  
    11/*
    2  * $Id: proc.cc,v 1.6 2000-02-14 21:44:40 krueger Exp $
     2 * $Id: proc.cc,v 1.7 2000-02-18 13:33:48 krueger Exp $
    33 */
    44
     
    5151        }
    5252 
    53         printf("iiAddCproc %s is C\n", proc->procname);
    5453        /* write call to add procname to list */
    5554        fprintf(module->modfp, "  iiAddCproc(\"%s\",\"%s\",%s, mod_%s);\n",
     
    5756                proc->is_static ? "TRUE" : "FALSE",
    5857                proc->procname);
     58       
    5959        if(proc->help_string!=NULL) {
    60           fprintf(module->modfp, "  namespaceroot->push( IDPACKAGE(helphdl) ,");
    61           fprintf(module->modfp, " IDID(helphdl));\n");
    62           fprintf(module->modfp, "  enter_id(\"%s\",", proc->procname);
    63           fprintf(module->modfp, " \"%s\", STRING_CMD);\n", proc->help_string);
    64           fprintf(module->modfp, "  namespaceroot->push();\n");
     60          printf("WRITE HELP\n");
     61//          fprintf(module->modfp, "  namespaceroot->push( IDPACKAGE(helphdl) ,");
     62//          fprintf(module->modfp, " IDID(helphdl));\n");
     63          fprintf(module->fmtfp2, "  enter_id(\"%s\",", proc->procname);
     64          fprintf(module->fmtfp2, " \"%s\", STRING_CMD);\n", proc->help_string);
     65//          fprintf(module->modfp, "  namespaceroot->push();\n");
     66        }
     67        if(proc->example_string!=NULL) {
     68          printf("WRITE EXAMPLE\n");
     69          fprintf(module->fmtfp3, "  enter_id(\"%s\",", proc->procname);
     70          fprintf(module->fmtfp3, " \"%s\", STRING_CMD);\n",
     71                  proc->example_string);
    6572        }
    6673        fprintf(module->modfp, "\n");
     
    7380      case LANG_SINGULAR:
    7481        fprintf(module->modfp,
    75                 "  h = add_singular_proc(%s, %d, %ld, %ld, %s);\n",
     82                "  h = add_singular_proc(\"%s\", %d, %ld, %ld, %s);\n",
    7683                proc->procname, proc->lineno,
    7784                proc->sing_start, proc->sing_end,
     
    8390}
    8491
    85 /*========================================================================*/
    86 void write_example(
    87   moddefv module,
    88   procdefv proc
    89   )
    90 {
    91   /* if proc is NULL, just return */
    92   if( proc == NULL ) return;
    93 
    94   if(proc->example_string!=NULL) {
    95     fprintf(module->modfp, "  namespaceroot->push( IDPACKAGE(examplehdl) ,");
    96     fprintf(module->modfp, " IDID(examplehdl));\n");
    97     fprintf(module->modfp, "  enter_id(\"%s\",", proc->procname);
    98     fprintf(module->modfp, " \"%s\", STRING_CMD);\n", proc->example_string);
    99     fprintf(module->modfp, "  namespaceroot->push();\n");
    100   }
    101 }
    10292/*========================================================================*/
    10393/*
     
    265255  fprintf(module->modfp, "  return 0;\n}\n\n");
    266256  fflush(module->modfp);
    267  
     257
     258  fprintf(module->modfp, "#if 0 /* Help section */\n");
     259  mod_copy_tmp(module->modfp, module->fmtfp2);
     260  fprintf(module->modfp, "#endif /* End of Help section */\n\n");
     261  fprintf(module->modfp, "#if 0 /* Example section */\n");
     262  mod_copy_tmp(module->modfp, module->fmtfp3);
     263  fprintf(module->modfp, "#endif /* End of Example section */\n\n");
    268264  mod_copy_tmp(module->modfp, module->fmtfp);
    269265  printf("  done.\n");fflush(stdout);
    270266  fclose(module->fmtfp);
     267  fclose(module->fmtfp2);
     268  fclose(module->fmtfp3);
    271269  return;
    272270}
     
    402400        break;
    403401  }
    404  
     402}
     403
     404/*========================================================================*/
     405void write_help(
     406  moddefv module,
     407  procdefv pi
     408  )
     409{
     410  if(pi->help_string!=NULL) {
     411    fprintf(module->fmtfp2, "#line %d \"%s\"\n", pi->lineno_other,
     412            module->filename);
     413//     fprintf(module->modfp, "  namespaceroot->push( IDPACKAGE(helphdl) ,");
     414//     fprintf(module->modfp, " IDID(helphdl));\n");
     415    fprintf(module->fmtfp2, "  enter_id(\"%s\",", pi->procname);
     416    fprintf(module->fmtfp2, " \"%s\", STRING_CMD);\n\n", pi->help_string);
     417//     fprintf(module->modfp, "  namespaceroot->push();\n");
     418  }
     419}
     420
     421/*========================================================================*/
     422void write_example(
     423  moddefv module,
     424  procdefv pi
     425  )
     426{
     427  /* if proc is NULL, just return */
     428  if( pi == NULL ) return;
     429
     430  if(pi->example_string!=NULL) {
     431    fprintf(module->fmtfp3, "#line %d \"%s\"\n", pi->lineno_other,
     432            module->filename);
     433    fprintf(module->fmtfp3, "  enter_id(\"%s\",\n", pi->procname);
     434    fprintf(module->fmtfp3, " \"%s\", STRING_CMD);\n\n", pi->example_string);
     435  }
     436 
     437#if 0
     438    fprintf(module->modfp, "  namespaceroot->push( IDPACKAGE(examplehdl) ,");
     439    fprintf(module->modfp, " IDID(examplehdl));\n");
     440    fprintf(module->modfp, "  enter_id(\"%s\",", proc->procname);
     441    fprintf(module->modfp, " \"%s\", STRING_CMD);\n", proc->example_string);
     442    fprintf(module->modfp, "  namespaceroot->push();\n");
     443#endif
    405444}
    406445
  • modules/modgen/scanner.l

    rf3929a r664898  
    33*  Computer Algebra System SINGULAR     *
    44****************************************/
    5 /* $Id: scanner.l,v 1.6 2000-02-14 21:47:10 krueger Exp $ */
     5/* $Id: scanner.l,v 1.7 2000-02-18 13:33:49 krueger Exp $ */
    66#include <stdio.h>
    77#include <string.h>
     
    1313#include "grammar.h"
    1414
    15 #define DEBUG 3
     15/* #define DEBUG 3 */
    1616 
    1717#  define YYLP_ERR_NONE    0
     
    4949  int read_string(char **buffer, long *start, long end);
    5050  int libread(FILE* f, char* buf, int max_size);
    51   add_action(char *new_text);
     51  void add_action(char *new_text);
    5252 
    5353  void push_state(int state, int new_state, char *name);
     
    231231
    232232<COMMENT>{
    233         "*/"            /*ACTION_ECHO;*/ pop_state(); yymore();
    234         "*"             /*ACTION_ECHO;*/ yymore();
     233        "*/"            ACTION_ECHO; pop_state(); yymore();
     234        "*"             ACTION_ECHO; yymore();
    235235        {NL}          { yylineno++; yymore(); }
    236236        .             { yymore(); }
     
    261261                }
    262262        example {
     263#if DEBUG > 1
    263264                  printf(">>>EXAMPLE\n");
     265#endif
    264266                  brace1 = 0; /* { */
    265267                  brace2 = 0; /* ( */
     
    389391                   } else {
    390392                     yymore();
    391                      /*yylineno++;*/
    392393                   }
    393394                 }
     
    484485}
    485486
    486 add_action(char *new_text)
     487void add_action(char *new_text)
    487488{
    488 
    489    printf("%s", new_text);
    490 }
     489  return;
     490  switch(sectnum) {
     491    case 1:
     492      printf("1>%s", new_text);
     493      break;
     494    case 2:
     495      printf("2>%s", new_text);
     496      break;
     497    case 3:
     498      printf("3>%s", new_text);
     499      break;
     500  }
     501}
  • modules/modgen/utils.cc

    rf3929a r664898  
    11/*
    2  * $Id: utils.cc,v 1.4 2000-01-27 12:40:53 krueger Exp $
     2 * $Id: utils.cc,v 1.5 2000-02-18 13:33:49 krueger Exp $
    33 */
    44
     
    4646/*========================================================================*/
    4747int create_tmpfile(
    48   moddefv module_def
     48  moddefv module_def,
     49  int which
    4950)
    5051{
    5152  char tmpfile[64];
    52 
     53  FILE *fp;
     54 
    5355  memset(tmpfile, '\0', sizeof(tmpfile));
    5456  snprintf(tmpfile, sizeof(tmpfile), "tmp/modgen.tmpXXXXXX");
    5557  mktemp(tmpfile);
    5658
     59  printf("create_tmpfile (%d\n", which );
     60 
    5761  if (close(creat(tmpfile, 0600)) < 0) {
    5862    (void) unlink (tmpfile);        /*  Blow it away!!  */
    5963    return -1;
    60   } else if ((module_def->fmtfp = fopen(tmpfile, "a+")) == NULL) {
     64  } else if ((fp = fopen(tmpfile, "a+")) == NULL) {
    6165    (void) unlink (tmpfile);        /*  Blow it away!!  */
    6266    return -1;
     
    6468    (void) unlink (tmpfile); /* delete now to avoid turds... */
    6569  }
     70
     71  printf("2)create_tmpfile (%d\n", which );
     72  switch(which) {
     73      case 0: module_def->fmtfp  = fp; break;
     74      case 1: module_def->fmtfp2 = fp; break;
     75      case 2: module_def->fmtfp3 = fp; break;
     76      default:
     77        fclose(fp);
     78        return -1;
     79  }
     80 
    6681  return 0;
    67  
    6882}
    6983
Note: See TracChangeset for help on using the changeset viewer.