Changeset 6c8772 in git for modules


Ignore:
Timestamp:
Apr 1, 1999, 12:03:24 AM (25 years ago)
Author:
Kai Krüger <krueger@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
dcafdbfd5e7cf5689011aad6c9b81fd43bd118b1
Parents:
740e1f7291b169d818475089a70366a328feb8d1
Message:
Major rewrite of modgen


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

Legend:

Unmodified
Added
Removed
  • modules/tools/misc.cc

    r740e1f7 r6c8772  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: misc.cc,v 1.4 1999-03-24 13:04:20 krueger Exp $ */
     4/* $Id: misc.cc,v 1.5 1999-03-31 22:03:22 krueger Exp $ */
    55/*
    66* ABSTRACT: lib parsing
     
    2828#define SYSTYP_HPUX10 3
    2929
    30 #if 0
     30#if 1
    3131#  define logx printf
    3232#else
     
    7575  if( strcmp(n, "SELF") == 0) {
    7676    tok = SELF_CMD;
     77    logx("IsCmd: [%d] %s\n", tok, n);
     78    return tok;
     79  }
     80 
     81  if( strcmp(n, "none") == 0) {
     82    tok = NONE;
     83    logx("IsCmd: [%d] %s\n", tok, n);
    7784    return tok;
    7885  }
     
    225232  }
    226233  module->revision = (char *)malloc(strlen(libnamebuf)+1);
    227   strcpy(module->revision, libnamebuf);
     234  memset(module->revision, '\0', strlen(libnamebuf)+1);
     235  memcpy(module->revision, libnamebuf, strlen(libnamebuf));
    228236}
    229237
     
    257265
    258266/*========================================================================*/
    259 /*  procdefv Add2proclist(procdefv pi, char *name)*/
    260267void Add2proclist(
    261268  moddefv module,
     
    270277 
    271278  memset((void *)&pnew, '\0', sizeof(procdef));
     279
    272280  pnew.procname = (char *)malloc(strlen(name)+1);
    273281  if(pnew.procname==NULL) printf("Error 1\n");
     282  memset(pnew.procname, '\0', strlen(name)+1);
     283  memcpy(pnew.procname, name, strlen(name));
     284
    274285  pnew.funcname = (char *)malloc(strlen(name)+1);
     286  if(pnew.funcname==NULL) printf("Error 1\n");
    275287  memset(pnew.funcname, '\0', strlen(name)+1);
    276   memset(pnew.procname, '\0', strlen(name)+1);
     288  memcpy(pnew.funcname, name, strlen(name));
     289
    277290  pnew.param = NULL;
    278291  (pnew).is_static = 0;
    279292  (pnew).paramcnt = 0;
    280   strcpy(pnew.procname, name);
    281   strcpy(pnew.funcname, name);
    282 
     293  pnew.c_code = NULL;
     294 
    283295  pnew.return_val.name = (char *)malloc(strlen(ret_val)+1);
    284296  memset(pnew.return_val.name, '\0', strlen(ret_val)+1);
     
    442454}
    443455
     456void gen_func_param_check(
     457  FILE *fp,
     458  procdefv pi,
     459  int i
     460  )
     461{
     462  fprintf(fp, "  if(v==NULL) goto mod_%s_error;\n", pi->funcname);
     463  fprintf(fp, "  tok = v->Typ();\n");
     464  fprintf(fp, "  if((index=iiTestConvert(tok, %s))==0)\n",
     465          pi->param[i].typname);
     466  fprintf(fp, "     goto mod_%s_error;\n", pi->funcname);
     467  fprintf(fp, "  v_save = v->next;\n");
     468  fprintf(fp, "  v->next = NULL;\n");
     469  fprintf(fp, "  if(iiConvert(tok, %s, index, v, res%d))\n",
     470          pi->param[i].typname, i);
     471  fprintf(fp, "     goto mod_%s_error;\n", pi->funcname);
     472  fprintf(fp, "  v = v_save;\n");
     473}
     474
    444475void generate_function(procdefv pi, FILE *fp)
    445476{
     
    450481  if(pi->paramcnt>0) {
    451482    if(pi->param[0].typ==SELF_CMD) {
     483      if(pi->c_code != NULL) fprintf(fp, "%s\n", pi->c_code);
     484 
    452485      fprintf(fp, "  return(%s(res,h));\n", pi->funcname);
    453486      fprintf(fp, "}\n\n");
    454487    }
    455488    else {
    456       fprintf(fp, "  leftv v = h;\n");
     489      fprintf(fp, "  leftv v = h, v_save;\n");
    457490      fprintf(fp, "  int tok = NONE, index = 0;\n");
    458491      for (i=0;i<pi->paramcnt; i++)
     
    461494      fprintf(fp, "\n");
    462495   
    463       for (i=0;i<pi->paramcnt; i++) {
    464         fprintf(fp, "  if(v==NULL) goto mod_%s_error;\n", pi->funcname);
    465         fprintf(fp, "  tok = v->Typ();\n");
    466         fprintf(fp, "  printf(\"test %d.1\\n\");\n", i);
    467         fprintf(fp, "  if((index=iiTestConvert(tok, %s))==0)\n",
    468                 pi->param[i].typname);
    469         logx("==>'%s'\n", pi->param[i].typname);
    470         fprintf(fp, "     goto mod_%s_error;\n", pi->funcname);
    471         fprintf(fp, "  printf(\"test %d.2\\n\");\n", i);
    472         fprintf(fp, "  if(iiConvert(tok, %s, index, v, res%d))\n",
    473                 pi->param[i].typname, cnt);
    474         fprintf(fp, "     goto mod_%s_error;\n", pi->funcname);
    475         fprintf(fp, "  printf(\"test %d.3\\n\");\n", i);
    476         fprintf(fp, "  v = v->next;\n");
    477       }
     496      if(pi->c_code != NULL) fprintf(fp, "%s\n", pi->c_code);
     497 
     498      for (i=0;i<pi->paramcnt; i++) gen_func_param_check(fp, pi, i);
     499
    478500      fprintf(fp, "  if(v!=NULL) { tok = v->Typ(); goto mod_%s_error; }\n",
    479501              pi->funcname);
    480       fprintf(fp, "  printf(\"test before return\\n\");\n");
    481502
    482503      fprintf(fp, "\n");
     
    513534    }
    514535  } else {
    515       fprintf(fp, "  return(%s(res));\n}\n\n", pi->funcname);
     536      switch( pi->return_val.typ) {
     537          case SELF_CMD:
     538            fprintf(fp, "  return(%s(res));\n}\n\n", pi->funcname);
     539           break;
     540
     541          case NONE:
     542            fprintf(fp, "  res->rtyp = %s;\n", pi->return_val.typname);
     543            fprintf(fp, "  res->data = NULL;\n");
     544            fprintf(fp, "  %s();\n", pi->funcname);
     545            fprintf(fp, "  return FALSE;\n}\n\n");
     546            break;
     547           
     548          default:
     549            fprintf(fp, "  res->rtyp = %s;\n", pi->return_val.typname);
     550            fprintf(fp, "  res->data = (void *)%s();\n", pi->funcname);
     551            fprintf(fp, "  return FALSE;\n}\n\n");
     552      }
     553   
    516554  }
    517555     
     
    613651  fprintf(fp, "CC\t= gcc\n");
    614652  fprintf(fp, "CXX\t= gcc\n");
    615   fprintf(fp, "CFLAGS\t= -DNDEBUG -I. -I../include\n");
     653  fprintf(fp, "CFLAGS\t= -DNDEBUG -DBUILD_MODULE -I. -I../include\n");
    616654  fprintf(fp, "#LD\t=\n");
    617655  fprintf(fp, "\n");
  • modules/tools/modgen.h

    r740e1f7 r6c8772  
    11/*
    2  *  $Id: modgen.h,v 1.3 1999-03-24 13:04:21 krueger Exp $
     2 *  $Id: modgen.h,v 1.4 1999-03-31 22:03:23 krueger Exp $
    33 *
    44 */
     
    3737  paramdefv param;
    3838  int       paramcnt;
     39  char *c_code;
    3940};
    4041
  • modules/tools/scanner.l

    r740e1f7 r6c8772  
    33*  Computer Algebra System SINGULAR     *
    44****************************************/
    5 /* $Id: scanner.l,v 1.3 1999-03-24 13:04:21 krueger Exp $ */
     5/* $Id: scanner.l,v 1.4 1999-03-31 22:03:23 krueger Exp $ */
    66#include <stdio.h>
    77#include <string.h>
     
    2020#include <tok.h>
    2121
     22#define DEBUG 0
     23 
     24#  define YYLP_ERR_NONE    0
     25#  define YYLP_DEF_BR2     1
     26#  define YYLP_BODY_BR2    2
     27#  define YYLP_BODY_BR3    3
     28#  define YYLP_BODY_TMBR2  4
     29#  define YYLP_BODY_TMBR3  5
     30#  define YYLP_EX_BR2      6
     31#  define YYLP_EX_BR3      7
     32#  define YYLP_BAD_CHAR    8
     33#  define YYLP_MISSQUOT    9
     34#  define YYLP_MISS_BR1   10
     35#  define YYLP_MISS_BR2   11
     36#  define YYLP_MISS_BR3   12
     37
    2238const char sNoName[]="_";
    23 char       my_yylinebuf[80];
    24 int old_state = 0;
     39int brace1 = 0;  /* { } */
     40int brace2 = 0;  /* ( ) */
     41int brace3 = 0;  /* [ ] */
     42int quote  = 0;  /* " */
     43int offset = 0;
     44
     45 char       my_yylinebuf[80];
     46int *old_states = NULL;
     47int state_level = -1;
     48int state_max = 0;
    2549int yylineno = 1;
    2650int tok;
     
    2852int  traceit = 0;
    2953moddef module_def;
     54 int yylplineno = 1;
     55 int yylp_errno = 0;
     56
     57 long C_start;
     58 long C_end;
     59 char c_codetype = 0;
     60#define C_CODE_NONE 0
     61#define C_CODE_PROC 1
     62#define C_CODE_MAIN 2
     63 
     64 char string_type = 0;
     65#define STRING_NONE 0
     66#define STRING_INFO 1
     67#define STRING_VERS 2
     68 long string_start = 0;
     69 long string_end = 0;
     70 
     71char *yylp_buffer_start;
     72
     73int libread(FILE* f, char* buf, int max_size);
     74int current_pos(int i);
     75int read_string(char **buffer, long *start, long end);
     76 
     77void push_state(int state, int new_state);
     78void pop_state();
     79 
     80#  undef YY_INPUT
     81#  define YY_INPUT(buf,result,max_size) \
     82          if ( ((result = libread( (yyin), (char *) buf, max_size )) < 0 ) \
     83                  && ferror( yyin ) ) \
     84                YY_FATAL_ERROR( "read in flex scanner failed" );
     85
    3086
    3187extern "C"
     
    52108tos            ({taborspace}*)
    53109eq             (=|{tos}+=|=+{tos}|{tos}+=+{tos})
     110tnl            ([ \t\n]*)
     111col            (;|{tos}+;)
     112eqnl           ([ \t\n]*+=[ \t\n]*)
    54113
    55114/* %start START */
     
    57116%x pdef
    58117%x comment
     118%x procdef
     119%x ctext
     120%x string
     121%x cstring
    59122
    60123%%
    61124(\/\/[^\n]*)|(^#![^\n]*)|([ \t]) { }
    62 \/\/*        { old_state = YYSTATE; BEGIN(comment); }
    63 
    64 (module+{eq}+\"+{name}\") {
     125\/\/*        { push_state(YYSTATE, comment); }
     126
     127(module+{eqnl}+{quote}+{name}+{quote}) {
    65128             char *buff = (char *)malloc(yyleng+4);
     129             memset(buff, '\0', yyleng+4);
    66130             sscanf( yytext, "%*[^\"]\"%[^\"]\"", buff);
    67131             module_def.name = (char *)malloc(strlen(buff)+1);
    68              strcpy(module_def.name, buff);
     132             memset(module_def.name, '\0', strlen(buff)+1);
     133             memcpy(module_def.name, buff, strlen(buff));
    69134             strcat(buff, ".cc");
    70              Add2files(&module_def,buff);
     135             Add2files(&module_def, buff);
    71136             free(buff);
    72137           }
    73138
    74 (version+{eq}+\"+{strings}\") {
    75              char *buff = (char *)malloc(yyleng);
    76              sscanf( yytext, "%*[^\"]\"%[^\"]\"", buff);
    77              module_def.version = (char *)malloc(strlen(buff)+1);
    78              strcpy(module_def.version, buff);
    79              make_version(module_def.version, &module_def);
    80              free(buff);
    81            }
    82 
    83 (helpfile+{eq}+\"+{fname}\") {
    84              char *buff = (char *)malloc(yyleng);
     139(version+{eqnl}+{quote}+{strings}+{quote}) {
     140             yyless(4);
     141             string_type = STRING_VERS;
     142             push_state(YYSTATE, cstring);
     143           }
     144
     145(helpfile+{eqnl}+{quote}+{fname}+{quote}) {
     146             char *buff = (char *)malloc(yyleng+1);
     147             memset(buff, '\0', yyleng+1);
    85148             sscanf( yytext, "%*[^\"]\"%[^\"]\"", buff);
    86149             module_def.helpfile = (char *)malloc(strlen(buff)+1);
    87              strcpy(module_def.helpfile, buff);
     150             memset(module_def.helpfile, '\0', strlen(buff)+1);
     151             memcpy(module_def.helpfile, buff, strlen(buff));
     152             printf("==>HELP:'%s'\n", module_def.helpfile);
    88153             free(buff);
    89154           }
    90155
    91 (cxxsource+{eq}+{fname}) {
    92              char *buff = (char *)malloc(yyleng);
     156(cxxsource+{eqnl}+{fname}) {
     157             char *buff = (char *)malloc(yyleng+1);
     158             memset(buff, '\0', yyleng+1);
    93159             sscanf( yytext, "%*[^=]=%s", buff);
    94160             Add2files(&module_def,buff);
     
    96162           }
    97163
    98 (info+{eq}+\"+{strings}\") {
    99              char *buff = (char *)malloc(yyleng);
    100              sscanf( yytext, "%*[^\"]\"%[^\"]\"", buff);
    101              module_def.info = (char *)malloc(strlen(buff)+1);
    102              strcpy(module_def.info, buff);
    103              free(buff);
    104            }
    105 
     164(info+{eqnl}+{quote}+{strings}+{quote}) {
     165             yyless(4);
     166             string_type = STRING_INFO;
     167             push_state(YYSTATE, cstring);
     168           }
     169
     170<cstring>{quote} { quote++; push_state(YYSTATE, string);
     171                string_start = current_pos(yyleng); }
     172<cstring>\n { yylplineno++; }
     173<cstring>{col} {
     174            switch(string_type) {
     175                case STRING_INFO:                     
     176                  read_string(&module_def.info, &string_start, string_end);
     177                  break;
     178                 
     179                case STRING_VERS:                     
     180                  read_string(&module_def.version, &string_start, string_end);
     181                  make_version(module_def.version, &module_def);
     182                  break;
     183            }
     184            string_type = STRING_NONE;
     185            pop_state(); }
     186<cstring>.  { }
     187
     188
     189
     190(proc+{tos}+{name})|({tos}+proc+{tos}+{name}) {
     191             char *proc = (char *)malloc(yyleng+1);
     192             memset(proc, '\0', yyleng+1);
     193             push_state(YYSTATE, pdef);
     194             sscanf( yytext, "%*[^p]proc %s", proc);
     195             if(strlen(proc)<1) sscanf( yytext, "proc %s", proc);
     196             Add2proclist(&module_def, proc, "none", "NONE", NONE);
     197             free(proc);
     198           }
    106199
    107200(proc+{tos}+{name}+{tos}+{name})|({tos}+proc+{tos}+{name}+{tos}+{name}) {
    108              char proc[256], ret_val[256], n2[32];
     201             char *proc = (char *)malloc(yyleng+1);
     202             char *ret_val = (char *)malloc(yyleng+1);
     203             memset(proc, '\0', yyleng+1);
     204             memset(ret_val, '\0', yyleng+1);
     205
     206             char n2[32];
    109207             int cmd;
    110              memset(proc, '\0', 256);
    111              memset(ret_val, '\0', 256);
    112208             memset(n2, '\0', 32);
    113              old_state = YYSTATE;
    114              BEGIN(pdef);
     209             push_state(YYSTATE, pdef);
    115210             sscanf( yytext, "%*[^p]proc %s %s", ret_val, proc);
    116211             if(strlen(proc)<1) sscanf( yytext, "proc %s %s", ret_val, proc);
     
    121216                Add2proclist(&module_def, proc, ret_val,
    122217                                          decl2str(tok,n2), tok);
    123              else printf("proc '%s': Invalid return parameter %s.\n",
    124                          module_def.procs[module_def.proccnt-1].procname,
    125                          ret_val);
    126            }
    127 
    128 (proc+{tos}+{name})|({tos}+proc+{tos}+{name}) {
    129              char proc[256];
    130              old_state = YYSTATE;
    131              BEGIN(pdef);
    132              proc[0]='\0';
    133              sscanf( yytext, "%*[^p]proc %s", proc);
    134              if(strlen(proc)<1) sscanf( yytext, "proc %s", proc);
    135              Add2proclist(&module_def, proc, "none", "NONE", 0);
     218             else {
     219               printf("proc '%s': Invalid return parameter %s.\n",
     220                         proc, ret_val);
     221               Add2proclist(&module_def, proc, "none",
     222                                          "NONE", NONE);
     223             }
     224             free(proc);
     225             free(ret_val);
    136226           }
    137227
    138228<pdef>[ \t]  { }
    139 <pdef>\(     {
    140              }
     229<pdef>"("    { }
    141230<pdef>{name}+, {
    142231             char param[256], n2[32];
     
    152241                         param);
    153242           }
    154 <pdef>{name}+\)+{eq}+{name} {
     243<pdef>{name}+")"+{tnl}+"{" {
     244             char param[256], n2[32];
     245             int cmd;
     246             BEGIN(procdef);
     247             memset(param, '\0', 256);
     248             memset(n2, '\0', 32);
     249             sscanf( yytext, "%[^)])", param);
     250             cmd = IsCmd(param, tok);
     251             if(cmd!=0)AddParam(&module_def,
     252                                param, decl2str(tok,n2), tok);
     253             else printf("proc '%s': Invalid parameter %s.\n",
     254                         module_def.procs[module_def.proccnt-1].procname,
     255                         param);
     256           }
     257<pdef>")"+{tnl}+"{" {
     258             BEGIN(procdef);
     259           }
     260
     261<pdef>"{" {
     262             BEGIN(procdef);
     263           }
     264
     265<pdef>(")"+{eqnl}+{name})|({eq}+{name}) {
     266             char funcname[256];
     267             pop_state();
     268             sscanf( yytext, "%*[^=]=%s", funcname);
     269             if(strlen(funcname)<=0)
     270                sscanf( yytext, "=%s", funcname);
     271             free(module_def.procs[module_def.proccnt-1].funcname);
     272             module_def.procs[module_def.proccnt-1].funcname =
     273                (char *)malloc(strlen(funcname)+1);
     274             memset(module_def.procs[module_def.proccnt-1].funcname,
     275                    '\0', strlen(funcname)+1);
     276             memcpy(module_def.procs[module_def.proccnt-1].funcname,
     277                    funcname, strlen(funcname));
     278           }
     279
     280<pdef>({name}+")"+{eqnl}+{name}) {
    155281             char param[256], n2[32],funcname[256];
    156282             int cmd;
    157              BEGIN(old_state);
     283             pop_state();
    158284             memset(param, '\0', 256);
    159285             memset(n2, '\0', 32);
     
    175301                         module_def.procs[module_def.proccnt-1].procname, param);
    176302           }
    177 <pdef>\)+{eq}+{name}|{eq}+{tos}+{name} {
    178              char funcname[256];
    179              BEGIN(old_state);
    180              sscanf( yytext, "%*[^=]=%s", funcname);
    181              if(strlen(funcname)<=0)
    182                 sscanf( yytext, "=%s", funcname);
    183              free(module_def.procs[module_def.proccnt-1].funcname);
    184              module_def.procs[module_def.proccnt-1].funcname =
    185                 (char *)malloc(strlen(funcname)+1);
    186              memset(module_def.procs[module_def.proccnt-1].funcname,
    187                     '\0', strlen(funcname)+1);
    188              memcpy(module_def.procs[module_def.proccnt-1].funcname,
    189                     funcname, strlen(funcname));
    190            }
    191303
    192304<pdef>.      { }
    193305
    194 <comment>\*\/            { BEGIN(old_state); }
     306<procdef>"}"  { pop_state(); }
     307<procdef>RETURN+{eqnl}+{name}+{col}   {
     308  printf("Return:\n");}
     309<procdef>function+{eqnl}+{name}+{col} {
     310       char *funcname = (char *)malloc(yyleng+1);
     311       memset(funcname, '\0', yyleng+1);
     312       sscanf( yytext, "%*[^=]=%[^;];", funcname);
     313       if(strlen(funcname)<=0)
     314         sscanf( yytext, "=%[^;];", funcname);
     315       free(module_def.procs[module_def.proccnt-1].funcname);
     316       module_def.procs[module_def.proccnt-1].funcname =
     317         (char *)malloc(strlen(funcname)+   1);
     318       memset(module_def.procs[module_def.proccnt-1].funcname,
     319              '\0', strlen(funcname)+1);
     320       memcpy(module_def.procs[module_def.proccnt-1].funcname,
     321              funcname, strlen(funcname));
     322     }
     323
     324<procdef>checkring+{col}            {
     325  printf("Do checkring\n"); }
     326<procdef>C+{eqnl}+"{" {
     327                push_state(YYSTATE, ctext);
     328                C_start=current_pos(yyleng);
     329                yyless(yyleng-1);
     330                c_codetype = C_CODE_PROC;
     331              }
     332<procdef>.                          { printf("%s", yytext); }
     333
     334<comment>\*\/            { pop_state(); }
    195335<comment>\n              { yylineno++; }
    196336<comment>.               { }
    197337
    198 
    199 \n                       { yylineno++; }
    200 \r                       { }
    201 .                        { }
     338<ctext>({comment}[^\n]*) { }
     339<ctext>\/\/*   { push_state(YYSTATE, comment); }
     340<ctext>{quote} { quote++; push_state(YYSTATE, string); }
     341<ctext>"{"     { brace1++; }
     342<ctext>"}"     {
     343       brace1--;
     344       if(brace2>0) {
     345         yylp_errno = YYLP_BODY_BR2;
     346         return(1);
     347       }
     348       if(brace3>0) {
     349         yylp_errno = YYLP_BODY_BR3;
     350         return(1);
     351       }
     352       if(brace1<=0) {
     353         C_end = current_pos(yyleng)-1;
     354         printf("Ctext: %d-%d\n", C_start, C_end);
     355         switch(c_codetype) {
     356             case C_CODE_PROC:
     357               read_string(&(module_def.procs[module_def.proccnt-1].c_code),
     358                           &C_start, C_end);
     359               break;
     360
     361             case C_CODE_MAIN:
     362               break;
     363         }
     364         c_codetype = C_CODE_NONE;
     365         pop_state();
     366       }
     367     }
     368<ctext>"("       { brace2++; }
     369<ctext>")"       { brace2--;
     370                   if(brace2<0) {
     371                     yylp_errno = YYLP_BODY_TMBR2;
     372                     return(1);
     373                   }
     374                 }
     375<ctext>"["       { brace3++; }
     376<ctext>"]"       { brace3--;
     377                   if(brace3<0) {
     378                     yylp_errno = YYLP_BODY_TMBR3;
     379                     return(1);
     380                   }
     381                 }
     382<ctext>\n  { yylineno++; }
     383<ctext>.   { }
     384
     385<string>{quote} { quote--; string_end = current_pos(yyleng)-1; pop_state(); }
     386<string>(\\\\)|(\\\") { }
     387<string>\n            { yylplineno++; }
     388<string>.             { }
     389
     390
     391C+{eqnl}+"{" { push_state(YYSTATE, ctext);
     392               C_start=current_pos(yyleng);
     393               yyless(yyleng-1);
     394             }
     395\n           { yylineno++; }
     396\r           { }
     397.            { }
    202398
    203399%%
     
    208404    return 1;
    209405  }
     406}
     407
     408int libread(FILE* f, char* buf, int max_size)
     409{ int rc;
     410
     411  offset = ftell(f);
     412  rc  = fread( buf, 1, max_size, f );
     413#if YYLPDEBUG >2
     414  printf("fread: %d of %d\n", rc, max_size);
     415#endif
     416  yylp_buffer_start = buf;
     417  return rc;
     418}
     419
     420int current_pos(int i)
     421{
     422  return(i+offset+(int)(yytext-yylp_buffer_start));
     423}
     424
     425int read_string(char **p, long *start, long end)
     426{
     427  char *buffer;
     428 
     429  if(*start > 0 ) {
     430    long len = end - *start;
     431    if(len>=0) {
     432      long cur = ftell(yyin);
     433      buffer = (char *)malloc(len+1);
     434      memset(buffer, '\0', len+1);
     435      fseek(yyin, *start, SEEK_SET);
     436      fread(buffer, 1, len, yyin);
     437      fseek(yyin, cur, SEEK_SET);
     438      *p = buffer;
     439    }
     440    *start = 0;
     441  }
     442}
     443               
     444void push_state(int state, int new_state)
     445{
     446  state_level++;
     447#if DEBUG
     448  printf("====>PUSH to new state %d/%d l=%d\n", state, new_state, state_level);
     449#endif
     450  if(state_level>=state_max) {
     451    state_max++;
     452    if(old_states == NULL)
     453      old_states = (int *)malloc(sizeof(int));
     454    else {
     455      old_states = (int *)realloc(old_states, state_max*sizeof(int));
     456    }
     457  }
     458  old_states[state_level] = state;
     459  BEGIN(new_state);
     460}
     461
     462void pop_state()
     463{
     464#if DEBUG
     465  printf("====>Back to old state %d, l=%d\n", old_states[state_level],
     466         state_level);
     467#endif
     468  BEGIN(old_states[state_level]);
     469  state_level--;
     470  if(state_level<0) state_level = -1;
    210471}
    211472
  • modules/tools/typmap.h

    r740e1f7 r6c8772  
    99void init_type_conv()
    1010{
     11  strcpy(type_conv[NONE], "none");
     12  strcpy(type_conv[NONE], "void");
    1113  strcpy(type_conv[INT_CMD], "int");
    1214  strcpy(type_conv[RING_CMD], "ring");
Note: See TracChangeset for help on using the changeset viewer.