Changeset b6e51b in git


Ignore:
Timestamp:
Sep 27, 2006, 7:46:28 PM (18 years ago)
Author:
Hans Schönemann <hannes@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
1e35790dc0937f1166846848cf844b2811aa49f0
Parents:
2245326a4cf500727c77d96a854a05d93f0cd772
Message:
*krueger: arith-change


git-svn-id: file:///usr/local/Singular/svn/trunk@9432 2c84dea3-7e68-4137-9b89-c4e89433aadc
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • Singular/Makefile.in

    r224532 rb6e51b  
    521521
    522522TAGS:   ${SOURCES} ${ESOURCES} ${HEADERS}
    523         etags ${SOURCES} ${ESOURCES} ${HEADERS}
     523        etags ${SOURCES} ${ESOURCES} ${HEADERS} ../kernel/*.[ch] ../kernel/*.cc ../kernel/*.inc
     524
    524525
    525526tags:   
  • Singular/iparith.cc

    r224532 rb6e51b  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: iparith.cc,v 1.411 2006-09-22 12:08:03 Singular Exp $ */
     4/* $Id: iparith.cc,v 1.412 2006-09-27 17:46:09 Singular Exp $ */
    55
    66/*
     
    5353#include "clapsing.h"
    5454#include "kstdfac.h"
    55 #endif
     55#endif /* HAVE_FACTORY */
    5656#ifdef HAVE_FGLM
    5757#include "fglm.h"
    58 #endif
     58#endif /* HAVE_FGLM */
    5959#define HAVE_INTERPOLATION
    6060#ifdef HAVE_INTERPOLATION
     
    7575#define COMM_PLURAL     ,2
    7676#define COMM_PLURAL_N    2
    77 #else
     77#else /* HAVE_PLURAL */
    7878#define ALLOW_PLURAL
    7979#define NO_PLURAL
    8080#define COMM_PLURAL
    81 #endif
     81#endif /* HAVE_PLURAL */
    8282
    8383/*=============== types =====================*/
     
    101101#ifdef HAVE_PLURAL
    102102  short valid_for_plural;
    103 #endif
     103# endif /* HAVE_PLURAL */
    104104};
    105105
     
    114114#ifdef HAVE_PLURAL
    115115  short valid_for_plural;
    116 #endif
     116# endif /* HAVE_PLURAL */
    117117};
    118118
     
    128128#ifdef HAVE_PLURAL
    129129  short valid_for_plural;
    130 #endif
     130# endif /* HAVE_PLURAL */
    131131};
    132132struct sValCmdM
     
    138138#ifdef HAVE_PLURAL
    139139  short valid_for_plural;
    140 #endif
     140# endif /* HAVE_PLURAL */
    141141};
    142 #endif
     142#endif /* GENTABLE */
     143
     144typedef struct {
     145  unsigned long nCmdUsed;      /**< number of commands used */
     146  unsigned long nCmdAllocated; /**< number of commands-slots allocated */
     147  unsigned long nLastIdentifier;
     148  cmdnames *sCmds;             /**< array of existing commands */
     149
     150#ifndef GENTABLE
     151  struct sValCmd1 *psValCmd1;
     152  struct sValCmd2 *psValCmd2;
     153  struct sValCmd3 *psValCmd3;
     154  struct sValCmdM *psValCmdM;
     155#endif /* GENTABLE */
     156} SArithBase;
     157
     158/*---------------------------------------------------------------------*
     159 * File scope Variables (Variables share by several functions in
     160 *                       the same file )
     161 *
     162 *---------------------------------------------------------------------*/
     163static SArithBase sArithBase;  /**< Base entry for arithmetic */
     164
     165/*---------------------------------------------------------------------*
     166 * Extern Functions declarations
     167 *
     168 *---------------------------------------------------------------------*/
     169static int _gentable_sort_cmds(const void *a, const void *b);
     170extern int iiArithRemoveCmd(char *szName);
     171extern int iiArithAddCmd(char *szName, short nAlias, short nTokval,
     172                         short nToktype, short nPos=-1);
    143173
    144174/*============= proc =======================*/
     
    345375  #ifdef OLD_RES
    346376  { "sres",        0, SRES_CMD ,          CMD_23},
    347   #else
     377#else /* OLD_RES */
    348378  { "sres",        0, SRES_CMD ,          CMD_2},
    349   #endif
     379#endif /* OLD_RES */
    350380  { "status",      0, STATUS_CMD,         CMD_M},
    351381  { "std",         0, STD_CMD ,           CMD_123},
     
    359389  #ifdef HAVE_PLURAL
    360390  { "twostd",      0, TWOSTD_CMD ,        CMD_1},
    361   #endif
     391#endif /* HAVE_PLURAL */
    362392  { "type",        0, TYPE_CMD ,          TYPE_CMD},
    363393  { "typeof",      0, TYPEOF_CMD ,        CMD_1},
     
    408438  { NULL, 0, 0, 0}
    409439};
    410 #endif
     440#endif /* GENTABLE */
    411441
    412442/*=================== operations with 2 args.: static proc =================*/
     
    798828        return TRUE;
    799829  }
    800 #else
     830#else /* HAVE_NS */
    801831  WerrorS("package is not supported in this version");
    802832#endif /* HAVE_NS */
     
    12001230      res->data=(void *)p;
    12011231    }
    1202 #else
     1232#else /* HAVE_FACTORY */
    12031233    WerrorS("division only by a monomial");
    12041234    return TRUE;
    1205 #endif
     1235#endif /* HAVE_FACTORY */
    12061236  }
    12071237  else
     
    12331263        MATELEM(mm,i,j) = singclap_pdivide( MATELEM(m,i,j) ,
    12341264                                           q /*(poly)(v->Data())*/ );
    1235       #else
     1265#else /* HAVE_FACTORY */
    12361266        WerrorS("division only by a monomial");
    12371267        return TRUE;
    1238       #endif
     1268#endif /* HAVE_FACTORY */
    12391269      }
    12401270      else
     
    17291759  //Print("exportto %s -> %s\n",v->Name(),u->Name() );
    17301760  return iiExport(v,0,(idhdl)u->data);
    1731 #else
     1761#else /* HAVE_NS */
    17321762  return TRUE;
    1733 #endif
     1763#endif /* HAVE_NS */
    17341764}
    17351765static BOOLEAN jjERROR(leftv res, leftv u)
     
    18061836  return FALSE;
    18071837}
    1808 #endif
     1838#endif /* HAVE_FACTORY */
    18091839static BOOLEAN jjFETCH(leftv res, leftv u, leftv v)
    18101840{
     
    19822012  return FALSE;
    19832013}
    1984 #endif
     2014#endif /* HAVE_FACTORY */
    19852015static BOOLEAN jjHILBERT2(leftv res, leftv u, leftv v)
    19862016{
     
    23192349#ifdef buildin_rand
    23202350  res->data =(char *)(long)((i > j) ? i : (siRand() % (j-i+1)) + i);
    2321 #else
     2351#else /* buildin_rand */
    23222352  res->data =(char *)(long)((i > j) ? i : (rand() % (j-i+1)) + i);
    2323 #endif
     2353#endif /* buildin_rand */
    23242354  return FALSE;
    23252355}
     
    39513981  int i = 1;
    39523982  int l = strlen(s);
    3953   while (cmds[i].tokval!=0)
    3954   {
    3955     if (strcmp(s, cmds[i].name) == 0)
     3983  for(i=0; i<sArithBase.nCmdUsed; i++) {
     3984    //while (cmds[i].tokval!=0){
     3985    if (strcmp(s, sArithBase.sCmds[i].name) == 0)
    39563986    {
    39573987      res->data = (char *)1;
     
    40284058    }
    40294059  }
    4030    
     4060
    40314061  assume(u_id->rank>=idRankFreeModule(u_id));
    4032   res->data=(char *)t_rep_gb(currRing, 
     4062  res->data=(char *)t_rep_gb(currRing,
    40334063    u_id,u_id->rank);
    40344064  //res->data=(char *)t_rep_gb(currRing, u_id);
    4035  
     4065
    40364066  if(!TEST_OPT_DEGBOUND) setFlag(res,FLAG_STD);
    40374067  if (w!=NULL) atSet(res,omStrDup("isHomog"),w,INTVEC_CMD);
     
    62316261{
    62326262  int i=1;
    6233   loop
    6234   {
    6235     Print("%-20s",cmds[i].name);
    6236     i++;
    6237     if(cmds[i].name==NULL)
    6238       break;
    6239     if ((i%3)==1) PrintLn();
     6263  unsigned short nCount = (sArithBase.nCmdUsed-1)/3;
     6264  if((3*nCount)<sArithBase.nCmdUsed) nCount++;
     6265  //Print("CMDS: %d/%d\n", sArithBase.nCmdUsed,
     6266  //      sArithBase.nCmdAllocated);
     6267  for(i=0; i<nCount; i++)
     6268  {
     6269    Print("%-20s",sArithBase.sCmds[i+1].name);
     6270    if(i+1+nCount<sArithBase.nCmdUsed)
     6271      Print("%-20s",sArithBase.sCmds[i+1+nCount].name);
     6272    if(i+1+2*nCount<sArithBase.nCmdUsed)
     6273      Print("%-20s",sArithBase.sCmds[i+1+2*nCount].name);
     6274    //if ((i%3)==1) PrintLn();
     6275    PrintLn();
    62406276  }
    62416277  PrintLn();
     
    65826618}
    65836619/*-------------------------------------------------------------------*/
     6620#if 0
    65846621void ttGen2()
    65856622{
     
    65936630
    65946631  fprintf(outfile,
    6595   "cmdnames cmds[] =\n"
     6632  "cmdnames OLDcmds[] =\n"
    65966633  "{  // name-string     alias  tokval toktype\n"
    65976634  "{ \"$INVALID$\",            0,  -1, 0},\n");
     
    67016738"  { NULL, 0, 0, 0}\n"
    67026739"};\n"
     6740"#ifdef HAVE_RTIMER\n"
     6741"#define LAST_IDENTIFIER %d\n"
     6742"#else\n"
     6743"#define LAST_IDENTIFIER %d\n"
     6744"#endif\n",id_nr,id_nr-1);
     6745  fclose(outfile);
     6746}
     6747#endif
     6748/*---------------------------------------------------------------------*/
     6749/**
     6750 * @brief generate cmds initialisation
     6751**/
     6752/*---------------------------------------------------------------------*/
     6753
     6754void ttGen2b()
     6755{
     6756  int cmd_size = (sizeof(cmds)/sizeof(cmdnames))-1;
     6757
     6758  FILE *outfile = myfopen("iparith.inc","a");
     6759  fprintf(outfile,
     6760  "/****************************************\n"
     6761  "*  Computer Algebra System SINGULAR     *\n"
     6762  "****************************************/\n\n");
     6763/*-------------------------------------------------------------------*/
     6764  fprintf(outfile,"// identifier table for Singular\n//\n");
     6765
     6766  fprintf(
     6767    outfile,
     6768    "void iiInitCmdName() {\n"
     6769    "  sArithBase.nCmdUsed      = 0;\n"
     6770    "  sArithBase.nCmdAllocated = %d;\n"
     6771    "  sArithBase.sCmds = (cmdnames*)omAlloc0(sArithBase.nCmdAllocated*sizeof(cmdnames));\n"
     6772    "\n"
     6773    "  // name-string        alias  tokval toktype\n",
     6774    cmd_size);
     6775  int m=0;
     6776  int id_nr=0;
     6777
     6778  qsort(&cmds, cmd_size, sizeof(cmdnames), (&_gentable_sort_cmds));
     6779
     6780  for(m=0; m<cmd_size; m++) {
     6781    if(cmds[m].tokval>0) id_nr++;
     6782    if(cmds[m].tokval==VRTIMER) fprintf(outfile,"#ifdef HAVE_RTIMER\n");
     6783    fprintf(outfile,"  iiArithAddCmd(\"%s\", %*d, %3d, ",cmds[m].name,
     6784            20-strlen(cmds[m].name),
     6785            cmds[m].alias,
     6786            cmds[m].tokval);
     6787    switch(cmds[m].toktype) {
     6788        case CMD_1:            fprintf(outfile,"CMD_1"); break;
     6789        case CMD_2:            fprintf(outfile,"CMD_2"); break;
     6790        case CMD_3:            fprintf(outfile,"CMD_3"); break;
     6791        case CMD_12:           fprintf(outfile,"CMD_12"); break;
     6792        case CMD_123 :         fprintf(outfile,"CMD_123"); break;
     6793        case CMD_23:           fprintf(outfile,"CMD_23"); break;
     6794        case CMD_M:            fprintf(outfile,"CMD_M"); break;
     6795        case SYSVAR:           fprintf(outfile,"SYSVAR"); break;
     6796        case ROOT_DECL:        fprintf(outfile,"ROOT_DECL"); break;
     6797        case ROOT_DECL_LIST:   fprintf(outfile,"ROOT_DECL_LIST"); break;
     6798        case RING_DECL:        fprintf(outfile,"RING_DECL"); break;
     6799        case NONE:             fprintf(outfile,"NONE"); break;
     6800        default:
     6801          if((cmds[m].toktype>' ') &&(cmds[m].toktype<127)) {
     6802            fprintf(outfile,"'%c'",cmds[m].toktype);
     6803          } else {
     6804            fprintf(outfile,"%d",cmds[m].toktype);
     6805          }
     6806          break;
     6807#if 0
     6808          fprintf(outfile,"  iiArithAddCmd(\"%s\", %*d,  -1, 0 );\n",
     6809              cmds[m].name, 20-strlen(cmds[m].name),
     6810              0/*cmds[m].alias*/
     6811              /*-1 cmds[m].tokval*/
     6812              /*0 cmds[m].toktype*/);
     6813#endif
     6814    }
     6815    fprintf(outfile,", %d);\n", m);
     6816    if(cmds[m].tokval==VRTIMER) fprintf(outfile,"#endif\n");
     6817  }
     6818  fprintf(outfile, "/* end of list marker */\n");
     6819  fprintf(outfile,
     6820          "#ifdef HAVE_RTIMER\n"
     6821          "  sArithBase.nLastIdentifier = %d;\n"
     6822          "#else /* HAVE_RTIMER */\n"
     6823          "  sArithBase.nLastIdentifier = %d;\n"
     6824          "#endif /* HAVE_RTIMER */\n",
     6825          id_nr,id_nr-1);
     6826
     6827
     6828  fprintf(outfile,
     6829"}\n"
    67036830"#ifdef HAVE_RTIMER\n"
    67046831"#define LAST_IDENTIFIER %d\n"
     
    75717698  int i,v;
    75727699#ifndef GENTABLE
    7573   int en=LAST_IDENTIFIER;
    7574 
    7575   loop
     7700  int en=sArithBase.nLastIdentifier;
     7701
     7702  //loop
     7703  for(an=0; an<sArithBase.nCmdUsed; )
    75767704  {
    75777705    if(an>=en-1)
    75787706    {
    7579       if (strcmp(n, cmds[an].name) == 0)
     7707      if (strcmp(n, sArithBase.sCmds[an].name) == 0)
    75807708      {
    75817709        i=an;
    75827710        break;
    75837711      }
    7584       else if ((an!=en) && (strcmp(n, cmds[en].name) == 0))
     7712      else if ((an!=en) && (strcmp(n, sArithBase.sCmds[en].name) == 0))
    75857713      {
    75867714        i=en;
     
    75937721    }
    75947722    i=(an+en)/2;
    7595     if (*n < *(cmds[i].name))
     7723    if (*n < *(sArithBase.sCmds[i].name))
    75967724    {
    75977725      en=i-1;
    75987726    }
    7599     else if (*n > *(cmds[i].name))
     7727    else if (*n > *(sArithBase.sCmds[i].name))
    76007728    {
    76017729      an=i+1;
     
    76037731    else
    76047732    {
    7605       v=strcmp(n,cmds[i].name);
     7733      v=strcmp(n,sArithBase.sCmds[i].name);
    76067734      if(v<0)
    76077735      {
     
    76187746    }
    76197747  }
    7620   lastreserved=cmds[i].name;
    7621   tok=cmds[i].tokval;
    7622   if(cmds[i].alias==2)
     7748  lastreserved=sArithBase.sCmds[i].name;
     7749  tok=sArithBase.sCmds[i].tokval;
     7750  if(sArithBase.sCmds[i].alias==2)
    76237751  {
    76247752    Warn("outdated identifier `%s` used - please change your code",
    7625     cmds[i].name);
    7626     cmds[i].alias=1;
     7753    sArithBase.sCmds[i].name);
     7754    sArithBase.sCmds[i].alias=1;
    76277755  }
    76287756  if (currRingHdl==NULL)
     
    76597787    }
    76607788  }
    7661   return cmds[i].toktype;
     7789  return sArithBase.sCmds[i].toktype;
    76627790#else
    76637791  return 0;
     
    76847812}
    76857813
     7814#ifdef GENTABLE
     7815char * Tok2Cmdname(int tok)
     7816{
     7817  int i = 0;
     7818  if (tok < 0)
     7819  {
     7820    return cmds[0].name;
     7821  }
     7822  if (tok==ANY_TYPE) return "any_type";
     7823  if (tok==NONE) return "nothing";
     7824  //if (tok==IFBREAK) return "if_break";
     7825  //if (tok==VECTOR_FROM_POLYS) return "vector_from_polys";
     7826  //if (tok==ORDER_VECTOR) return "ordering";
     7827  //if (tok==REF_VAR) return "ref";
     7828  //if (tok==OBJECT) return "object";
     7829  //if (tok==PRINT_EXPR) return "print_expr";
     7830  if (tok==IDHDL) return "identifier";
     7831  while (cmds[i].tokval!=0)
     7832  {
     7833    if ((cmds[i].tokval == tok)&&(cmds[i].alias==0))
     7834    {
     7835      return cmds[i].name;
     7836    }
     7837    i++;
     7838  }
     7839  return cmds[0].name;
     7840}
     7841#else /* GENTABLE */
     7842char * Tok2Cmdname(int tok)
     7843{
     7844  int i = 0;
     7845  if (tok < 0)
     7846  {
     7847    return sArithBase.sCmds[0].name;
     7848  }
     7849  if (tok==ANY_TYPE) return "any_type";
     7850  if (tok==NONE) return "nothing";
     7851  //if (tok==IFBREAK) return "if_break";
     7852  //if (tok==VECTOR_FROM_POLYS) return "vector_from_polys";
     7853  //if (tok==ORDER_VECTOR) return "ordering";
     7854  //if (tok==REF_VAR) return "ref";
     7855  //if (tok==OBJECT) return "object";
     7856  //if (tok==PRINT_EXPR) return "print_expr";
     7857  if (tok==IDHDL) return "identifier";
     7858  for(i=0; i<sArithBase.nCmdUsed; i++)
     7859    //while (sArithBase.sCmds[i].tokval!=0)
     7860  {
     7861    if ((sArithBase.sCmds[i].tokval == tok)&&
     7862        (sArithBase.sCmds[i].alias==0))
     7863    {
     7864      return sArithBase.sCmds[i].name;
     7865    }
     7866  }
     7867  return sArithBase.sCmds[0].name;
     7868}
     7869#endif /* GENTABLE */
     7870
     7871
     7872/*---------------------------------------------------------------------*/
     7873/**
     7874 * @brief compares to entry of cmdsname-list
     7875
     7876 @param[in] a
     7877 @param[in] b
     7878
     7879 @return <ReturnValue>
     7880**/
     7881/*---------------------------------------------------------------------*/
     7882static int _gentable_sort_cmds( const void *a, const void *b )
     7883{
     7884  cmdnames *pCmdL = (cmdnames*)a;
     7885  cmdnames *pCmdR = (cmdnames*)b;
     7886
     7887  if(a==NULL || b==NULL)             return 0;
     7888
     7889  /* empty entries goes to the end of the list for later reuse */
     7890  if(pCmdL->name==NULL) return 1;
     7891  if(pCmdR->name==NULL) return -1;
     7892
     7893  /* $INVALID$ must come first */
     7894  if(strcmp(pCmdL->name, "$INVALID$")==0) return -1;
     7895  if(strcmp(pCmdR->name, "$INVALID$")==0) return  1;
     7896
     7897  /* tokval=-1 are reserved names at the end */
     7898  if (pCmdL->tokval==-1)
     7899  {
     7900    if (pCmdR->tokval==-1)
     7901       return strcmp(pCmdL->name, pCmdR->name);
     7902    /* pCmdL->tokval==-1, pCmdL goes at the end */
     7903    return 1;
     7904  }
     7905  /* pCmdR->tokval==-1, pCmdR goes at the end */
     7906  if(pCmdR->tokval==-1) return -1;
     7907
     7908  return strcmp(pCmdL->name, pCmdR->name);
     7909}
     7910
     7911/*---------------------------------------------------------------------*/
     7912/**
     7913 * @brief initialisation of arithmetic structured data
     7914
     7915 @retval 0 on success
     7916
     7917**/
     7918/*---------------------------------------------------------------------*/
     7919int iiInitArithmetic()
     7920{
     7921  int i;
     7922  //printf("iiInitArithmetic()\n");
     7923#ifndef GENTABLE
     7924  memset(&sArithBase, 0, sizeof(sArithBase));
     7925  iiInitCmdName();
     7926  /* fix last-identifier */
     7927#if 0
     7928  /* we expect that gentable allready did every thing */
     7929  for(sArithBase.nLastIdentifier=sArithBase.nCmdUsed-1;
     7930      sArithBase.nLastIdentifier>0; sArithBase.nLastIdentifier--) {
     7931    if(sArithBase.sCmds[sArithBase.nLastIdentifier].tokval>=0) break;
     7932  }
     7933#endif
     7934  //Print("L=%d\n", sArithBase.nLastIdentifier);
     7935
     7936  //iiArithAddCmd(szName, nAlias, nTokval, nToktype);
     7937  //iiArithAddCmd("mygcd", 1, GCD_CMD, CMD_2);
     7938
     7939  //iiArithAddCmd("Top", 0,-1,0);
     7940
     7941
     7942  //for(i=0; i<sArithBase.nCmdUsed; i++) {
     7943  //  printf("CMD[%03d] %s, %d, %d, %d\n", i,
     7944  //         sArithBase.sCmds[i].name,
     7945  //         sArithBase.sCmds[i].alias,
     7946  //         sArithBase.sCmds[i].tokval,
     7947  //         sArithBase.sCmds[i].toktype);
     7948  //}
     7949  //iiArithRemoveCmd("Top");
     7950  //iiArithAddCmd("mygcd", 2, GCD_CMD, CMD_2);
     7951  //iiArithRemoveCmd("mygcd");
     7952  //iiArithAddCmd("kkk", 1, 1234, CMD_1);
     7953#endif   /* !GENTABLE */
     7954}
     7955
     7956/*---------------------------------------------------------------------*/
     7957/**
     7958 * @brief append newitem of size sizeofitem to the list named list.
     7959
     7960 @param[in,out] list
     7961 @param[in,out] item_count
     7962 @param[in] sizeofitem
     7963 @param[in] newitem
     7964
     7965 @retval  0 success
     7966 @retval -1 failure
     7967**/
     7968/*---------------------------------------------------------------------*/
     7969int iiArithAddItem2list(
     7970  void **list,
     7971  long  *item_count,
     7972  long sizeofitem,
     7973  void *newitem
     7974  )
     7975{
     7976  int count = *item_count;
     7977
     7978  //TRACE(0, "add_item_to_list(%p, %p, %ld, %p)\n", list, item_count,
     7979  //       sizeofitem, newitem);
     7980
     7981  if(count==0)
     7982  {
     7983    *list = (void *)omAlloc(sizeofitem);
     7984  }
     7985  else
     7986  {
     7987    *list = (void *)omRealloc(*list, (count+1) * sizeofitem);
     7988  }
     7989  if((*list)==NULL) return -1;
     7990
     7991  //memset((*list)+count*sizeofitem, 0, sizeofitem);
     7992  //memcpy((*list)+count*sizeofitem, newitem, sizeofitem);
     7993
     7994  /* erhoehe counter um 1 */
     7995  (count)++;
     7996  *item_count = count;
     7997  return 0;
     7998}
     7999
     8000int iiArithFindCmd(const char *szName)
     8001{
     8002#ifndef GENTABLE
     8003  int an=0;
     8004  int i = 0,v = 0;
     8005  int en=sArithBase.nLastIdentifier;
     8006
     8007  for(an=0; an<sArithBase.nCmdUsed; )
     8008  {
     8009    if(an>=en-1)
     8010    {
     8011      if (strcmp(szName, sArithBase.sCmds[an].name) == 0)
     8012      {
     8013        //Print("RET-an=%d %s\n", an, sArithBase.sCmds[an].name);
     8014        return an;
     8015      }
     8016      else if (strcmp(szName, sArithBase.sCmds[en].name) == 0)
     8017      {
     8018        //Print("RET-en=%d %s\n", en, sArithBase.sCmds[en].name);
     8019        return en;
     8020      }
     8021      else
     8022      {
     8023        //Print("RET- 1\n");
     8024        return -1;
     8025      }
     8026    }
     8027    i=(an+en)/2;
     8028    if (*szName < *(sArithBase.sCmds[i].name))
     8029    {
     8030      en=i-1;
     8031    }
     8032    else if (*szName > *(sArithBase.sCmds[i].name))
     8033    {
     8034      an=i+1;
     8035    }
     8036    else
     8037    {
     8038      v=strcmp(szName,sArithBase.sCmds[i].name);
     8039      if(v<0)
     8040      {
     8041        en=i-1;
     8042      }
     8043      else if(v>0)
     8044      {
     8045        an=i+1;
     8046      }
     8047      else /*v==0*/
     8048      {
     8049        //Print("RET-i=%d %s\n", i, sArithBase.sCmds[i].name);
     8050        return i;
     8051      }
     8052    }
     8053  }
     8054  //if(i>=0 && i<sArithBase.nCmdUsed)
     8055  //  return i;
     8056  //Print("RET-2\n");
     8057  return -2;
     8058#else
     8059  return 0;
     8060#endif
     8061}
     8062
     8063char *iiArithGetCmd( int nPos )
     8064{
     8065  if(nPos<0) return NULL;
     8066  if(nPos<sArithBase.nCmdUsed)
     8067    return sArithBase.sCmds[nPos].name;
     8068  return NULL;
     8069}
     8070
     8071int iiArithRemoveCmd( char *szName)
     8072{
     8073  int nIndex;
     8074  if(szName==NULL) return -1;
     8075
     8076  nIndex = iiArithFindCmd(szName);
     8077  if(nIndex<0 || nIndex>=sArithBase.nCmdUsed)
     8078  {
     8079    Print("'%s' not found (%d)\n", szName, nIndex);
     8080    return -1;
     8081  }
     8082  omFree(sArithBase.sCmds[nIndex].name);
     8083  sArithBase.sCmds[nIndex].name=0;
     8084  qsort(sArithBase.sCmds, sArithBase.nCmdUsed, sizeof(cmdnames),
     8085        (&_gentable_sort_cmds));
     8086  sArithBase.nCmdUsed--;
     8087
     8088  /* fix last-identifier */
     8089  for(sArithBase.nLastIdentifier=sArithBase.nCmdUsed-1;
     8090      sArithBase.nLastIdentifier>0; sArithBase.nLastIdentifier--)
     8091  {
     8092    if(sArithBase.sCmds[sArithBase.nLastIdentifier].tokval>=0) break;
     8093  }
     8094  //Print("L=%d\n", sArithBase.nLastIdentifier);
     8095  return 0;
     8096}
     8097
     8098int iiArithAddCmd(
     8099  char *szName,
     8100  short nAlias,
     8101  short nTokval,
     8102  short nToktype,
     8103  short nPos
     8104  )
     8105{
     8106  //printf("AddCmd(%s, %d, %d, %d, %d)\n", szName, nAlias,
     8107  //       nTokval, nToktype, nPos);
     8108  if(nPos>=0)
     8109  {
     8110    if(nPos>=sArithBase.nCmdAllocated) return -1;
     8111    if(szName!=NULL) sArithBase.sCmds[nPos].name    = omStrDup(szName);
     8112    else sArithBase.sCmds[nPos].name = NULL;
     8113    sArithBase.sCmds[nPos].alias   = nAlias;
     8114    sArithBase.sCmds[nPos].tokval  = nTokval;
     8115    sArithBase.sCmds[nPos].toktype = nToktype;
     8116    sArithBase.nCmdUsed++;
     8117    //if(nTokval>0) sArithBase.nLastIdentifier++;
     8118  }
     8119  else
     8120  {
     8121    if(szName==NULL) return -1;
     8122    int nIndex = iiArithFindCmd(szName);
     8123    if(nIndex>=0)
     8124    {
     8125      Print("'%s' already exists at %d\n", szName, nIndex);
     8126      return -1;
     8127    }
     8128
     8129    if(sArithBase.nCmdUsed>=sArithBase.nCmdAllocated)
     8130    {
     8131      /* needs to create new slots */
     8132      unsigned long nSize = (sArithBase.nCmdAllocated+1)*sizeof(cmdnames);
     8133      sArithBase.sCmds = (cmdnames *)omRealloc(sArithBase.sCmds, nSize);
     8134      if(sArithBase.sCmds==NULL) return -1;
     8135      sArithBase.nCmdAllocated++;
     8136    }
     8137    /* still free slots available */
     8138    sArithBase.sCmds[sArithBase.nCmdUsed].name    = omStrDup(szName);
     8139    sArithBase.sCmds[sArithBase.nCmdUsed].alias   = nAlias;
     8140    sArithBase.sCmds[sArithBase.nCmdUsed].tokval  = nTokval;
     8141    sArithBase.sCmds[sArithBase.nCmdUsed].toktype = nToktype;
     8142    sArithBase.nCmdUsed++;
     8143
     8144    qsort(sArithBase.sCmds, sArithBase.nCmdUsed, sizeof(cmdnames),
     8145          (&_gentable_sort_cmds));
     8146    for(sArithBase.nLastIdentifier=sArithBase.nCmdUsed-1;
     8147        sArithBase.nLastIdentifier>0; sArithBase.nLastIdentifier--)
     8148    {
     8149      if(sArithBase.sCmds[sArithBase.nLastIdentifier].tokval>=0) break;
     8150    }
     8151    //Print("L=%d\n", sArithBase.nLastIdentifier);
     8152  }
     8153  return 0;
     8154}
     8155
  • Singular/iplib.cc

    r224532 rb6e51b  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: iplib.cc,v 1.121 2006-08-10 12:52:21 Singular Exp $ */
     4/* $Id: iplib.cc,v 1.122 2006-09-27 17:46:11 Singular Exp $ */
    55/*
    66* ABSTRACT: interpreter: LIB and help
     
    3636#endif /* HAVE_LIBPARSER */
    3737#define NS_LRING (procstack->cRing)
     38
     39extern int iiArithAddCmd(char *szName, short nAlias, short nTokval,
     40                         short nToktype, short nPos);
    3841
    3942#include "mod_raw.h"
     
    10851088                               BOOLEAN pstatic,
    10861089                               BOOLEAN(*func)(leftv res, leftv v)));
    1087   fktn_t fktn;
     1090  typedef int (*fktn2_t)(SModulFunctions*);
     1091  fktn2_t fktn;
    10881092  idhdl pl;
    10891093  char *plib = iiConvName(newlib);
     
    11281132  else
    11291133  {
     1134    SModulFunctions sModulFunctions;
     1135   
    11301136#ifdef HAVE_NS
    11311137    package s=currPack;
    11321138    currPack=IDPACKAGE(pl);
    11331139#endif
    1134     fktn = (fktn_t)dynl_sym(IDPACKAGE(pl)->handle, "mod_init");
     1140    fktn = (fktn2_t)dynl_sym(IDPACKAGE(pl)->handle, "mod_init");
    11351141    if( fktn!= NULL)
    11361142    {
    1137       if (autoexport) (*fktn)(iiAddCprocTop);
    1138       else            (*fktn)(iiAddCproc);
     1143      sModulFunctions.iiArithAddCmd = iiArithAddCmd;
     1144      if (autoexport) sModulFunctions.iiAddCproc = iiAddCprocTop;
     1145      else            sModulFunctions.iiAddCproc = iiAddCproc;
     1146      (*fktn)(&sModulFunctions);
    11391147    }
    11401148    else Werror("mod_init: %s\n", dynl_error());
  • Singular/ipshell.cc

    r224532 rb6e51b  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: ipshell.cc,v 1.142 2006-07-26 13:49:28 Singular Exp $ */
     4/* $Id: ipshell.cc,v 1.143 2006-09-27 17:46:11 Singular Exp $ */
    55/*
    66* ABSTRACT:
     
    6666
    6767/*0 implementation*/
    68 
    69 char * Tok2Cmdname(int tok)
    70 {
    71   int i = 0;
    72   if (tok < 0)
    73   {
    74     return cmds[0].name;
    75   }
    76   if (tok==ANY_TYPE) return "any_type";
    77   if (tok==NONE) return "nothing";
    78   //if (tok==IFBREAK) return "if_break";
    79   //if (tok==VECTOR_FROM_POLYS) return "vector_from_polys";
    80   //if (tok==ORDER_VECTOR) return "ordering";
    81   //if (tok==REF_VAR) return "ref";
    82   //if (tok==OBJECT) return "object";
    83   //if (tok==PRINT_EXPR) return "print_expr";
    84   if (tok==IDHDL) return "identifier";
    85   while (cmds[i].tokval!=0)
    86   {
    87     if ((cmds[i].tokval == tok)&&(cmds[i].alias==0))
    88     {
    89       return cmds[i].name;
    90     }
    91     i++;
    92   }
    93   return cmds[0].name;
    94 }
    9568
    9669char * iiTwoOps(int t)
  • Singular/tesths.cc

    r224532 rb6e51b  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: tesths.cc,v 1.108 2006-09-21 17:00:39 Singular Exp $ */
     4/* $Id: tesths.cc,v 1.109 2006-09-27 17:46:12 Singular Exp $ */
    55
    66/*
     
    3737#endif
    3838
     39extern int iiInitArithmetic();
     40
    3941const char *singular_date=__DATE__ " " __TIME__;
    4042
     
    5759#ifdef GENTABLE
    5860  extern void ttGen1();
    59   extern void ttGen2();
     61  extern void ttGen2b();
    6062  extern void ttGen4();
    6163  extern void mpsr_ttGen(); // For initialization of (CMD, MP_COP) tables
     
    6365  ttGen4();
    6466  ttGen1();
    65   ttGen2();
     67  ttGen2b();
    6668#else
    6769  // Don't worry: ifdef OM_NDEBUG, then all these calls are undef'ed
     
    7779  // do this first, because -v might print version path
    7880  feInitResources(argv[0]);
     81  iiInitArithmetic();
    7982
    8083  // parse command line options
  • kernel/feread.cc

    r224532 rb6e51b  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: feread.cc,v 1.8 2006-07-18 11:25:05 bricken Exp $ */
     4/* $Id: feread.cc,v 1.9 2006-09-27 17:45:40 Singular Exp $ */
    55/*
    66* ABSTRACT: input from ttys, simulating fgets
     
    4949char * (*fe_fgets_stdin)(char *pr,char *s, int size)
    5050 = fe_fgets_stdin_init;
     51
     52extern char *iiArithGetCmd(int);
    5153
    5254/* ===================================================================*/
     
    8183
    8284  /* Return the next name which partially matches from the command list. */
    83   while ((name = cmds[list_index].name)!=NULL)
     85  while ((name = iiArithGetCmd(list_index))!=NULL)
    8486  {
    8587    list_index++;
  • kernel/longalg.cc

    r224532 rb6e51b  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: longalg.cc,v 1.16 2006-08-14 17:36:59 Singular Exp $ */
     4/* $Id: longalg.cc,v 1.17 2006-09-27 17:45:40 Singular Exp $ */
    55/*
    66* ABSTRACT:   algebraic numbers
     
    13531353  if ((zb!=NULL) && (zb->z!=NULL))
    13541354  {
    1355     //if (zb->n!=NULL)
    1356     //{
    1357     //  return TRUE;
    1358     //}
    13591355    return (nacGreaterZero(napGetCoeff(zb->z))||(!napIsConstant(zb->z)));
    13601356  }
  • modules/modgen/creat_top.cc

    r224532 rb6e51b  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: creat_top.cc,v 1.24 2006-06-25 16:06:19 motsak Exp $ */
     4/* $Id: creat_top.cc,v 1.25 2006-09-27 17:46:27 Singular Exp $ */
    55/*
    66* ABSTRACT: lib parsing
     
    122122  fprintf(fp, "#line @d \"%s.cc\"\n", module->name);
    123123  fprintf(fp, "extern \"C\" {\n");
     124#if 0
    124125  fprintf(fp, "int mod_init(\n  int (*iiAddCproc)(");
    125126#if 1
     
    128129#endif
    129130  fprintf(fp, ")\n  )\n{\n");
     131#else
     132  fprintf(fp, "int mod_init(\n  SModulFunctions* psModulFunctions");
     133  fprintf(fp, "\n  )\n{\n");
     134#endif
    130135  fprintf(fp, "  idhdl h;\n");
    131136  fprintf(fp, "  char * tempstr;\n");
  • modules/modgen/main.cc

    r224532 rb6e51b  
    6060moddef module_def;
    6161
     62extern int iiInitArithmetic();
    6263int init_modgen(
    6364  moddefv module_def,
     
    159160  }
    160161 
     162  iiInitArithmetic();
    161163  if(init_modgen(&module_def, argv[optind])) return 1;
    162164  init_type_conv();
  • modules/modgen/misc.cc

    r224532 rb6e51b  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: misc.cc,v 1.25 2006-04-06 19:37:00 anne Exp $ */
     4/* $Id: misc.cc,v 1.26 2006-09-27 17:46:27 Singular Exp $ */
    55/*
    66* ABSTRACT: lib parsing
     
    3535#endif
    3636
     37typedef struct {
     38  unsigned long nCmdUsed;      /**< number of commands used */
     39  unsigned long nCmdAllocated; /**< number of commands-slots allocated */
     40  unsigned long nLastIdentifier;
     41  cmdnames *sCmds;             /**< array of existing commands */
     42
     43#ifndef GENTABLE
     44  struct sValCmd1 *psValCmd1;
     45  struct sValCmd2 *psValCmd2;
     46  struct sValCmd3 *psValCmd3;
     47  struct sValCmdM *psValCmdM;
     48#endif /* GENTABLE */
     49} SArithBase;
     50
     51
     52/*---------------------------------------------------------------------*
     53 * File scope Variables (Variables share by several functions in
     54 *                       the same file )
     55 *
     56 *---------------------------------------------------------------------*/
     57static SArithBase sArithBase;  /**< Base entry for arithmetic */
     58
    3759char *DYNAinclude[] = {
    3860   "",
     
    5476#define SELF_CMD MAX_TOK+1
    5577
     78/*---------------------------------------------------------------------*
     79 * Extern Functions declarations
     80 *
     81 *---------------------------------------------------------------------*/
     82static int _gentable_sort_cmds(const void *a, const void *b);
     83extern int iiArithRemoveCmd(char *szName);
     84extern int iiArithAddCmd(char *szName, short nAlias, short nTokval,
     85                         short nToktype, short nPos=-1);
    5686extern void enter_id(FILE *fp, idtyp t, char *name, char *value,
    5787                     int lineno, char *file);
     
    78108  int an=1;
    79109  int i,v;
    80   int en=LAST_IDENTIFIER;
     110  int en=sArithBase.nLastIdentifier;
    81111 
    82112  if( strcmp(n, "SELF") == 0) {
     
    92122  }
    93123 
    94   loop
     124  for(an=0; an<sArithBase.nCmdUsed; )
    95125  {
    96126    if(an>=en-1)
    97127    {
    98       if (strcmp(n, cmds[an].name) == 0)
     128      if (strcmp(n, sArithBase.sCmds[an].name) == 0)
    99129      {
    100130        i=an;
    101131        break;
    102132      }
    103       else if (strcmp(n, cmds[en].name) == 0)
     133      else if ((an!=en) && (strcmp(n, sArithBase.sCmds[en].name) == 0))
    104134      {
    105135        i=en;
     
    112142    }
    113143    i=(an+en)/2;
    114     v=strcmp(n,cmds[i].name);
     144    if (*n < *(sArithBase.sCmds[i].name))
     145    {
     146      en=i-1;
     147    }
     148    else if (*n > *(sArithBase.sCmds[i].name))
     149    {
     150      an=i+1;
     151    }
     152    else
     153    {
     154      v=strcmp(n,sArithBase.sCmds[i].name);
    115155    if(v<0)
    116156    {
    117       en=i;
     157        en=i-1;
    118158    }
    119159    else if(v>0)
    120160    {
    121       an=i;
     161        an=i+1;
    122162    }
    123163    else /*v==0*/
     
    126166    }
    127167  }
    128   lastreserved=cmds[i].name;
    129   tok=cmds[i].tokval;
    130   if(cmds[i].alias==2)
    131   {
     168  }
     169  lastreserved=sArithBase.sCmds[i].name;
     170  tok=sArithBase.sCmds[i].tokval;
     171  if(sArithBase.sCmds[i].alias==2)
     172    {
    132173    if(trace)printf("outdated identifier `%s` used - please change your code",
    133     cmds[i].name);
    134     cmds[i].alias=1;
    135   }
    136 #if 0
    137   if (!expected_parms)
    138   {
    139     switch (tok)
    140     {
    141       case IDEAL_CMD:
    142       case INT_CMD:
    143       case INTVEC_CMD:
    144       case MAP_CMD:
    145       case MATRIX_CMD:
    146       case MODUL_CMD:
    147       case POLY_CMD:
    148       case PROC_CMD:
    149       case RING_CMD:
    150       case STRING_CMD:
    151         cmdtok = tok;
    152         break;
    153     }
    154   }
    155 #endif
     174    sArithBase.sCmds[i].name);
     175    sArithBase.sCmds[i].alias=1;
     176  }
     177
    156178  logx("IsCmd: [%d] %s\n", tok, n);
    157179 
    158   if( (cmds[i].toktype==ROOT_DECL) ||
    159       (cmds[i].toktype==ROOT_DECL_LIST) ||
    160       (cmds[i].toktype==RING_DECL) ||
    161       (cmds[i].toktype==IDEAL_CMD) ||
    162       (cmds[i].toktype==INTMAT_CMD) ||
    163       (cmds[i].toktype==MODUL_CMD) ||
    164       (cmds[i].toktype==MATRIX_CMD))// ||
    165 //      ((cmds[i].toktype>=DRING_CMD) && (cmds[i].toktype<=VECTOR_CMD)))
    166     return cmds[i].toktype;
     180  if( (sArithBase.sCmds[i].toktype==ROOT_DECL) ||
     181      (sArithBase.sCmds[i].toktype==ROOT_DECL_LIST) ||
     182      (sArithBase.sCmds[i].toktype==RING_DECL) ||
     183      (sArithBase.sCmds[i].toktype==IDEAL_CMD) ||
     184      (sArithBase.sCmds[i].toktype==INTMAT_CMD) ||
     185      (sArithBase.sCmds[i].toktype==MODUL_CMD) ||
     186      (sArithBase.sCmds[i].toktype==MATRIX_CMD))// ||
     187//      ((csArithBase.sCds[i].toktype>=DRING_CMD) && (cmds[i].toktype<=VECTOR_CMD)))
     188    return sArithBase.sCmds[i].toktype;
    167189  return 0;
    168190}
     191
    169192
    170193char * decl2str(int n, char *name)
     
    434457    printf("->%s, %s\n", module->procs[proccnt].procname,
    435458           module->procs[proccnt].funcname);
    436     fprintf(module->modfp, "  iiAddCproc(\"%s\",\"%s\",%s, mod_%s);\n",
     459    fprintf(module->modfp, "  psModulFunctions->iiAddCproc(\"%s\",\"%s\",%s, mod_%s);\n",
    437460            module->name, module->procs[proccnt].procname,
    438461            module->procs[proccnt].is_static ? "TRUE" : "FALSE",
     
    616639
    617640/*========================================================================*/
     641/*---------------------------------------------------------------------*/
     642/**
     643 * @brief compares to entry of cmdsname-list
     644
     645 @param[in] a   
     646 @param[in] b   
     647
     648 @return <ReturnValue>
     649**/
     650/*---------------------------------------------------------------------*/
     651static int _gentable_sort_cmds(
     652  const void *a,
     653  const void *b
     654  )
     655{
     656  cmdnames *pCmdL = (cmdnames*)a;
     657  cmdnames *pCmdR = (cmdnames*)b;
     658 
     659  if(a==NULL || b==NULL)             return 0;
     660
     661  /* empty entries goes to the end of the list for later reuse */
     662  if(pCmdL->name==NULL) return 1;
     663  if(pCmdR->name==NULL) return -1;
     664 
     665  /* $INVALID$ must come first */
     666  if(strcmp(pCmdL->name, "$INVALID$")==0) return -1;
     667  if(strcmp(pCmdR->name, "$INVALID$")==0) return  1;
     668 
     669  /* tokval=-1 are reserved names at the end */
     670  if( (pCmdL->tokval==-1) && pCmdR->tokval==-1)
     671    return strcmp(pCmdL->name, pCmdR->name);
     672
     673  /* pCmdL->tokval==-1, pCmdL goes at the end */
     674  if(pCmdL->tokval==-1) return 1;
     675  /* pCmdR->tokval==-1, pCmdR goes at the end */
     676  if(pCmdR->tokval==-1) return -1;
     677
     678  return strcmp(pCmdL->name, pCmdR->name);
     679}
     680
     681/*---------------------------------------------------------------------*/
     682/**
     683 * @brief initialisation of arithmetic structured data
     684
     685 @retval 0 on success
     686
     687**/
     688/*---------------------------------------------------------------------*/
     689int iiInitArithmetic()
     690{
     691  int i;
     692  //printf("iiInitArithmetic()\n");
     693#ifndef GENTABLE
     694  memset(&sArithBase, 0, sizeof(sArithBase));
     695  iiInitCmdName();
     696  /* fix last-identifier */
     697#endif   /* !GENTABLE */
     698}
     699
     700int iiArithFindCmd(const char *szName)
     701{
     702  int an=0;
     703  int i = 0,v = 0;
     704#ifndef GENTABLE
     705  int en=sArithBase.nLastIdentifier;
     706
     707  for(an=0; an<sArithBase.nCmdUsed; ) {
     708    if(an>=en-1) {
     709      if (strcmp(szName, sArithBase.sCmds[an].name) == 0) {
     710        //Print("RET-an=%d %s\n", an, sArithBase.sCmds[an].name);
     711        return an;
     712      } else if (strcmp(szName, sArithBase.sCmds[en].name) == 0)
     713      {
     714        //Print("RET-en=%d %s\n", en, sArithBase.sCmds[en].name);
     715        return en;
     716      }
     717      else
     718      {
     719        //Print("RET- 1\n");
     720        return -1;
     721      }
     722    }
     723    i=(an+en)/2;
     724    if (*szName < *(sArithBase.sCmds[i].name)) {
     725      en=i-1;
     726    }
     727    else if (*szName > *(sArithBase.sCmds[i].name))
     728    {
     729      an=i+1;
     730    }
     731    else
     732    {
     733      v=strcmp(szName,sArithBase.sCmds[i].name);
     734      if(v<0)
     735      {
     736        en=i-1;
     737      }
     738      else if(v>0)
     739      {
     740        an=i+1;
     741      }
     742      else /*v==0*/
     743      {
     744        //Print("RET-i=%d %s\n", i, sArithBase.sCmds[i].name);
     745        return i;
     746      }
     747    }
     748  }
     749  //if(i>=0 && i<sArithBase.nCmdUsed)
     750  //  return i;
     751  //Print("RET-2\n");
     752  return -2;
     753#else
     754  return 0;
     755#endif
     756}
     757
     758int iiArithAddCmd(
     759  char *szName,
     760  short nAlias,
     761  short nTokval,
     762  short nToktype,
     763  short nPos
     764  )
     765{
     766  //printf("AddCmd(%s, %d, %d, %d, %d)\n", szName, nAlias,
     767  //       nTokval, nToktype, nPos);
     768  if(nPos>=0) {
     769    if(nPos>=sArithBase.nCmdAllocated) return -1;
     770    if(szName!=NULL) sArithBase.sCmds[nPos].name    = strdup(szName);
     771    else sArithBase.sCmds[nPos].name = NULL;
     772    sArithBase.sCmds[nPos].alias   = nAlias;
     773    sArithBase.sCmds[nPos].tokval  = nTokval;
     774    sArithBase.sCmds[nPos].toktype = nToktype;
     775    sArithBase.nCmdUsed++;
     776    //if(nTokval>0) sArithBase.nLastIdentifier++;
     777  } else {
     778    if(szName==NULL) return -1;
     779    int nIndex = iiArithFindCmd(szName);
     780    if(nIndex>=0) {
     781      printf("'%s' already exists at %d\n", szName, nIndex);
     782      return -1;
     783    }
     784   
     785    if(sArithBase.nCmdUsed>=sArithBase.nCmdAllocated) {
     786      /* needs to create new slots */
     787      unsigned long nSize = (sArithBase.nCmdAllocated+1)*sizeof(cmdnames);
     788      sArithBase.sCmds = (cmdnames *)realloc(sArithBase.sCmds, nSize);
     789      if(sArithBase.sCmds==NULL) return -1;
     790      sArithBase.nCmdAllocated++;
     791    }
     792    /* still free slots available */
     793    sArithBase.sCmds[sArithBase.nCmdUsed].name    = strdup(szName);
     794    sArithBase.sCmds[sArithBase.nCmdUsed].alias   = nAlias;
     795    sArithBase.sCmds[sArithBase.nCmdUsed].tokval  = nTokval;
     796    sArithBase.sCmds[sArithBase.nCmdUsed].toktype = nToktype;
     797    sArithBase.nCmdUsed++;
     798
     799    qsort(sArithBase.sCmds, sArithBase.nCmdUsed, sizeof(cmdnames),
     800          (&_gentable_sort_cmds));
     801    for(sArithBase.nLastIdentifier=sArithBase.nCmdUsed-1;
     802        sArithBase.nLastIdentifier>0; sArithBase.nLastIdentifier--) {
     803      if(sArithBase.sCmds[sArithBase.nLastIdentifier].tokval>=0) break;
     804    }
     805    //Print("L=%d\n", sArithBase.nLastIdentifier);
     806  }
     807  return 0;
     808}
     809
  • modules/modgen/proc.cc

    r224532 rb6e51b  
    11/*
    2  * $Id: proc.cc,v 1.25 2006-06-25 16:19:16 motsak Exp $
     2 * $Id: proc.cc,v 1.26 2006-09-27 17:46:28 Singular Exp $
    33 */
    44
     
    5353        /* write call to add procname to list */
    5454        fprintf(module->modfp,
    55                 "  iiAddCproc(currPack->libname,\"%s\",%s, mod_%s);\n",
     55                "  psModulFunctions->iiAddCproc(currPack->libname,\"%s\",%s, mod_%s);\n",
    5656                proc->procname,
    5757                proc->is_static ? "TRUE" : "FALSE",
     
    524524/*========================================================================*/
    525525void write_help(
    526   moddefv module,
     526  moddefv pModule,
    527527  procdefv pi
    528528  )
     
    530530  unsigned int i;
    531531  if(pi->help_string!=NULL) {
    532     fprintf(module->fmtfp2, "#line %d \"%s\"\n", pi->lineno_other,
    533             module->filename);
    534     fprintf(module->fmtfp2, "  enter_id(\"%s_help\",", pi->procname);
    535     fprintf(module->fmtfp2, " \"");
     532    fprintf(pModule->fmtfp2, "#line %d \"%s\"\n", pi->lineno_other,
     533            pModule->filename);
     534    fprintf(pModule->fmtfp2, "  enter_id(\"%s_help\",", pi->procname);
     535    fprintf(pModule->fmtfp2, " \"");
    536536    for(i=0; i<strlen(pi->help_string); i++) {
    537         if(pi->help_string[i]=='\n') fprintf(module->fmtfp2,"\\n");
    538         else fprintf(module->fmtfp2,"%c", pi->help_string[i]);
    539     }
    540     fprintf(module->fmtfp2, "\", STRING_CMD);\n\n", pi->help_string);
     537        if(pi->help_string[i]=='\n') fprintf(pModule->fmtfp2,"\\n");
     538        else fprintf(pModule->fmtfp2,"%c", pi->help_string[i]);
     539    }
     540    fprintf(pModule->fmtfp2, "\", STRING_CMD);\n\n", pi->help_string);
    541541  }
    542542}
  • modules/modgen/scanner.cc

    r224532 rb6e51b  
    33
    44/* Scanner skeleton version:
    5  * $Header: /exports/cvsroot-2/cvsroot/modules/modgen/scanner.cc,v 1.2 2006-06-23 15:41:38 Singular Exp $
     5 * $Header: /exports/cvsroot-2/cvsroot/modules/modgen/scanner.cc,v 1.3 2006-09-27 17:46:28 Singular Exp $
    66 */
    77
     
    703703*  Computer Algebra System SINGULAR     *
    704704****************************************/
    705 /* $Id: scanner.cc,v 1.2 2006-06-23 15:41:38 Singular Exp $ */
     705/* $Id: scanner.cc,v 1.3 2006-09-27 17:46:28 Singular Exp $ */
    706706#include <stdio.h>
    707707#include <string.h>
Note: See TracChangeset for help on using the changeset viewer.