Back to index

wims  3.65+svn20090927
Classes | Defines | Typedefs | Enumerations | Functions | Variables
calc.c File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  SORT_STRUCT
struct  MYFUNCTION

Defines

#define sort_keyw_no   (sizeof(sort_keyw)/sizeof(sort_keyw[0]))
#define append_obj_no   (sizeof(append_obj)/sizeof(append_obj[0]))
#define MAX_COLUMNS   256
#define CALC_FN_NO   (sizeof(calc_routine)/sizeof(calc_routine[0]))

Typedefs

typedef struct SORT_STRUCT SORT_STRUCT

Enumerations

enum  {
  sort_char, sort_word, sort_item, sort_line,
  sort_row, sort_numeric, sort_nocase, sort_reverse
}

Functions

void secure_exec (void)
int __sorter (const void *p1, const void *p2)
int _char_sorter (const void *c1, const void *c2)
void calc_sort (char *p)
void calc_debug (char *p)
void calc_daemon (char *p)
void _get_exec_error (char *errorfname, char *cmdname)
void calc_exec (char *p)
void calc_mexec (char *p)
void _calc_exec (char *p, char *arg0, char *arg1, int n)
void calc_sh (char *p)
void calc_perl (char *p)
void calc_evalue (char *p)
void calc_mathsubst (char *p)
void calc_evalsubst (char *p)
void calc_subst (char *p)
int _randrep (char *p)
void calc_randint (char *p)
void calc_randdouble (char *p)
void calc_randfile (char *p)
void calc_randchar (char *p)
void calc_randitem (char *p)
void calc_randline (char *p)
void calc_randrow (char *p)
void calc_randword (char *p)
void calc_randperm (char *p)
void calc_linenum (char *p)
void calc_rownum (char *p)
void calc_itemnum (char *p)
void calc_recordnum (char *p)
void calc_wordnum (char *p)
void calc_lengthof (char *p)
char * _blockof_one (char *buf, unsigned int len, char *(fnd_fn)(char *pl, int n, char bbuf[]), int i, char bbuf[])
void _blockof (char *p, unsigned int(len_fn)(char *pl), char *(fnd_fn)(char *pl, int n, char bbuf[]), char *append_char, char *msg_str)
void calc_lineof (char *p)
void calc_rowof (char *p)
void calc_itemof (char *p)
void calc_recordof (char *p)
void calc_wordof (char *p)
void calc_charof (char *p)
void calc_append (char *p)
void calc_translate (char *p)
void _pos (char *hay, char *stitch, int style, char *out, char *(fnd_obj)(char *p, int n, char bf[]), unsigned int(objnum)(char *p))
void calc_pos (char *p)
void _obj_replace (char *orig, char *by, char *in, int num, char separator, char *result, char *(fnd_obj)(char *p, int n, char bf[]), unsigned int(objnum)(char *p), char *(objchr)(char *p, char *w))
void calc_replace (char *p)
void calc_hex (char *p)
void calc_tolower (char *p)
void calc_toupper (char *p)
void calc_trim (char *p)
void calc_date (char *p)
void calc_listfile (char *p)
void calc_instexst (char *p)
void calc_nonempty (char *p)
void calc_listuniq (char *p)
void calc_listintersect (char *p)
void calc_listunion (char *p)
void calc_listcomplement (char *p)
void calc_module (char *p)
void calc_declosing (char *p)
void calc_detag (char *p)
void calc_reinput (char *p)
void calc_defof (char *p)
void calc_checkhost (char *p)
void calc_select (char *p)
void calc_columnof (char *p)
void calc_solve (char *p)
void _values (char *p, int type)
void calc_values (char *p)
void calc_sum (char *p)
void calc_product (char *p)
void calc_recursion (char *p)
void calc_makelist (char *p)
void calc_leveldata (char *p)
void _lookup (char *p, char *fname)
void calc_lookup (char *p)
void calc_rename (char *p)
void calc_imgrename (char *p)
void calc_unhttp (char *p)
void calc_passcheck (char *p)
void calc_passcrypt (char *p)
void exec_readproc (char *p)
void calc_mailurl (char *p)
void calc_getopt (char *p)
void _embraced (char buf[], void(app)(char *p))
void calc_embraced (char *p)
void calc_rows2lines (char *p)
void calc_lines2rows (char *p)
void calc_checkdata (char *p)

Variables

int _sort_numeric
int _sort_nocase
struct {
char * name
int type
sort_keyw []
char * append_obj []
char apch_list [] = {',','\n',' '}
MYFUNCTION calc_routine []

Class Documentation

struct SORT_STRUCT

Definition at line 22 of file calc.c.

Class Members
int serial
char * str
double val

Define Documentation

#define append_obj_no   (sizeof(append_obj)/sizeof(append_obj[0]))

Definition at line 711 of file calc.c.

#define CALC_FN_NO   (sizeof(calc_routine)/sizeof(calc_routine[0]))

Definition at line 2261 of file calc.c.

#define MAX_COLUMNS   256

Definition at line 1439 of file calc.c.

#define sort_keyw_no   (sizeof(sort_keyw)/sizeof(sort_keyw[0]))

Definition at line 77 of file calc.c.


Typedef Documentation

typedef struct SORT_STRUCT SORT_STRUCT

Enumeration Type Documentation

anonymous enum
Enumerator:
sort_char 
sort_word 
sort_item 
sort_line 
sort_row 
sort_numeric 
sort_nocase 
sort_reverse 

Definition at line 53 of file calc.c.


Function Documentation

int __sorter ( const void *  p1,
const void *  p2 
)

Definition at line 32 of file calc.c.

{
    struct SORT_STRUCT *pp1, *pp2;
    
    pp1=(struct SORT_STRUCT *) p1; pp2=(struct SORT_STRUCT *) p2;
    if(_sort_numeric) {
       double dd=(pp1->val)-(pp2->val);
       if(dd>0) return 1;
       if(dd<0) return -1;
       return 0;
    }
    if(_sort_nocase) return strcasecmp(pp1->str,pp2->str);
    else return strcmp(pp1->str,pp2->str);
}

Here is the caller graph for this function:

void _blockof ( char *  p,
unsigned   intlen_fn)(char *pl,
char *  fnd_fn)(char *pl, int n, char bbuf[],
char *  append_char,
char *  msg_str 
)

Definition at line 609 of file calc.c.

{
    int i,j,l,started;
    char *pp, *pe, *po, *pnext;
    char buf[MAX_LINELEN+1], obuf[MAX_LINELEN+1], bbuf[MAX_LINELEN+1];
    pp=wordchr(p,"of");
    if(pp==NULL) {
       setvar(error_data_string,msg_str);
       module_error("no_of"); *p=0; return;
    }
    *pp=0; pp=find_word_start(pp+strlen("of")+1);
    mystrncpy(buf,pp,sizeof(buf)); substit(buf);
    obuf[0]=0; started=0; po=obuf;
    pp=strparstr(p,"to");
    while(*pp!=0 && ((pp>p && !isspace(*(pp-1))) || !isspace(*(pp+2))))
      pp=strparstr(pp+2,"to");
    if(*pp==0) pp=strparstr(p,"..");
    if(*pp!=0) {
       int t=len_fn(buf);
       *pp=0; pe=find_word_start(pp+2);
       i=evalue(p); j=evalue(pe); pnext=buf;
       if(i<0) i=t+i+1; if(i<1) i=1;
       if(j<0) j=t+j+1; if(j>t) j=t;
       for(; i<=j; i++) {
           if(started==0 || fnd_fn==datafile_fnd_record)
             pp=_blockof_one(buf,t,fnd_fn,i,bbuf);
           else
             pp=_blockof_one(pnext,1,fnd_fn,1,bbuf);
           l=strlen(pp); pnext=fnd_nextpos;
           if(l+(po-obuf)>=MAX_LINELEN-3) {
              too_long: user_error("cmd_output_too_long"); return;
           }
           if(started) {strcpy(po,append_char); po+=strlen(po);}
           memmove(po,pp,l); po+=l; *po=0; started++;
       }
    }
    else {
       char *p1,*p2,ibuf[MAX_LINELEN+1];
       int t=len_fn(buf);
       mystrncpy(ibuf,p,sizeof(ibuf)); substit(ibuf);
       for(p1=ibuf;*p1;p1=find_word_start(p2)) {
           p2=find_item_end(p1); if(*p2) *p2++=0;
           i=evalue(p1);
           if(i<0) i=t+i+1;
           if(i>t || i<0) continue;
           pp=_blockof_one(buf,t,fnd_fn,i,bbuf);l=strlen(pp);
           if(l+(po-obuf)>=MAX_LINELEN-3) goto too_long;
           if(started) {strcpy(po,append_char); po+=strlen(po);}
           memmove(po,pp,l); po+=l; *po=0; started++;
       }
    }
    mystrncpy(p,obuf,MAX_LINELEN);
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* _blockof_one ( char *  buf,
unsigned int  len,
char *  fnd_fn)(char *pl, int n, char bbuf[],
int  i,
char  bbuf[] 
)

Definition at line 598 of file calc.c.

{
    if(i<0 || i>len || (i==0 && fnd_fn!=datafile_fnd_record) ) {
       bbuf[0]=0; return bbuf;
    }
    return fnd_fn(buf,i,bbuf);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void _calc_exec ( char *  p,
char *  arg0,
char *  arg1,
int  n 
)

Definition at line 307 of file calc.c.

{
    char *abuf[8];
    char outfname[MAX_FNAME+1], errorfname[MAX_FNAME+1];

    if(robot_access) {*p=0; return;}
    if(!trusted_module() || is_class_module) {
       if(strcasecmp(tmp_debug,"yes")==0)
         accessfile(p,"w","%s/%s.cmd",tmp_dir,arg0);
       abuf[0]="bin/ch..root";
       abuf[1]="&"; abuf[2]=arg0; abuf[3]=p;
       abuf[4]=NULL;
    }
    else {
/*     if(strstr(p,PARENT_DIR_STRING)!=NULL) {
           setvar("wims_error_data",p);
           module_error("illegal_fname"); *p=0; return;
       }
*/     abuf[0]=arg0; abuf[1]=arg1; abuf[n]=p; abuf[n+1]=NULL;
    }
    mkfname(outfname,"%s/exec.out",tmp_dir);
    mkfname(errorfname,"%s/exec.err",tmp_dir);
    wrapexec=1; exportall();
    execredirected(abuf[0],NULL,outfname,errorfname,abuf);
    read_tmp_file(p,"exec.out");
    _get_exec_error(errorfname,arg0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int _char_sorter ( const void *  c1,
const void *  c2 
)

Definition at line 47 of file calc.c.

{
    if(_sort_nocase) return tolower(*(char *)c1)-tolower(*(char *)c2);
    else return *(char *)c1-*(char *)c2;
}

Here is the caller graph for this function:

void _embraced ( char  buf[],
void(app)(char *p)   
)

Definition at line 1975 of file calc.c.

{
    char *p1, *p2, buf2[MAX_LINELEN+1];
    for(p1=strchr(buf,'{'); p1; p1=strchr(p1,'{')) {
       p2=find_matching(p1+1,'}');
       if(p2==NULL) module_error("unmatched_parentheses");
       *p2=0; mystrncpy(buf2,p1+1,sizeof(buf2)); app(buf2);
       string_modify(buf,p1,p2+1,buf2);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void _get_exec_error ( char *  errorfname,
char *  cmdname 
)

Definition at line 157 of file calc.c.

{
    char *p2;
    char obuf[MAX_LINELEN+1];
    int l;
    if(errorfname) accessfile(obuf,"e","%s",errorfname);
    else {
       l=read(mxtab[multiexec_index].pipe_stderr[0],obuf,MAX_LINELEN/4);
       if(l<0 || l>MAX_LINELEN) l=0;
       obuf[l]=0;
    }
    if(obuf[0]) {
       p2=find_word_end(obuf);
       if((manageable<1 || strcasecmp(tmp_debug,"yes")!=0) && 
          !trusted_module() &&
          strncmp(p2," not_INStalled",strlen(" not_INStalled"))==0) {
           *p2=0; setvar("missing_software",obuf);
           snprintf(p2+1,MAX_LINELEN-strlen(obuf)-8,"missing_%s",obuf);
           if(!outputing) user_error(p2+1);
       }
       p2=getvar("wims_exec_error"); if(p2==NULL) p2="";
       snprintf(tmplbuf,sizeof(tmplbuf),"%s\nERROR from %s:\n%s",p2,cmdname,obuf);
       force_setvar("wims_exec_error",tmplbuf);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void _lookup ( char *  p,
char *  fname 
)

Definition at line 1763 of file calc.c.

{
    char buf1[MAX_LINELEN+1];
    char *p1, *p2, *mbuf;

    mbuf=readfile(fname,NULL,WORKFILE_LIMIT);
    if(mbuf==NULL) {abort: *p=0; return;}
    p1=find_word_start(p); strip_trailing_spaces(p1);
    snprintf(buf1,sizeof(buf1),"%s:",p1); substit(buf1);
    for(p1=strstr(mbuf,buf1);
       p1!=NULL && p1>mbuf && *(p1-1)!='\n';
       p1=strstr(p1+1,buf1));
    if(p1==NULL) {free(mbuf); goto abort;}
    p1+=strlen(buf1);
    for(p2=strchr(p1,'\n'); p2!=NULL; p2=strchr(p2+1,'\n')) {
       if(p2>p1 && *(p2-1)=='\\') {*(p2-1)=' '; continue;}
       else break;
    }
    if(p2==NULL) p2=p1+strlen(p1); else *p2=0;
    mystrncpy(p,p1,MAX_LINELEN); free(mbuf);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void _obj_replace ( char *  orig,
char *  by,
char *  in,
int  num,
char  separator,
char *  result,
char *  fnd_obj)(char *p, int n, char bf[],
unsigned   intobjnum)(char *p,
char *  objchr)(char *p, char *w 
)

Definition at line 862 of file calc.c.

{
    int i;
    char *p1, *p2;
    
    strcpy(result,in);
    if(num!=0) {
       num=objnum(in); i=evalue(orig);
       if(i==0) module_error("bad_index");
       if(i<0) i=num+i+1;
       if(i>num || i<1) return;
       if(separator==0) {  /* char */
           result[i-1]=by[0]; return;
       }
       fnd_obj(result,i,orig); p1=fnd_position;
       if(i<num) {
           fnd_obj(result,i+1,orig); p2=fnd_position;
       }
       else p2=result+strlen(result);
       if(p1==NULL || p2==NULL) internal_error("_obj_replace() error.");
       if(i<num) {
           i=strlen(by); by[i++]=separator;by[i]=0;
       }
       string_modify(result,p1,p2,"%s",by);
    }
    else {
       if(separator==0) {
           if(orig[0]==0 || by[0]==0) return;
           for(p1=strchr(result,orig[0]);p1!=NULL;p1=strchr(p1+1,orig[0]))
              *p1=by[0];
           return;
       }
       if(strlen(orig)+strlen(by)==0) return;
       for(p1=objchr(result,orig);p1!=NULL;p1=objchr(p1+strlen(by)+1,orig)) {
           string_modify(result,p1,p1+strlen(orig),"%s",by);
       }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void _pos ( char *  hay,
char *  stitch,
int  style,
char *  out,
char *  fnd_obj)(char *p, int n, char bf[],
unsigned   intobjnum)(char *p 
)

Definition at line 789 of file calc.c.

{
    int i,n,t;
    char buf[MAX_LINELEN+1], nbuf[10];
    
    n=objnum(hay);
    for(i=1;i<=n;i++) {
       fnd_obj(hay,i,buf);
       if(strcmp(buf,stitch)!=0) continue;
       t=strlen(out); if(t>MAX_LINELEN-12) return;
       if(t>0) strcat(out,",");
       snprintf(nbuf,sizeof(nbuf),"%d",i); strcat(out,nbuf);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int _randrep ( char *  p)

Definition at line 392 of file calc.c.

{
    char *rep;
    int i;
    rep=wordchr(p,"repeat"); if(rep==NULL) return 1;
    *rep=0; rep+=strlen("repeat"); i=evalue(rep);
    if(i<1) i=1; if(i>MAX_VALUE_LIST) i=MAX_VALUE_LIST;
    return i;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void _values ( char *  p,
int  type 
)

Definition at line 1579 of file calc.c.

{
    char *pp, *fp, *forp;
    char vbuf[MAX_LINELEN+1], buf[MAX_LINELEN+1], fbuf[MAX_LINELEN+1], tbuf[MAX_LINELEN+1];
    char *f[64];
    double v, dd, start, stop, step, v0;
    int i, k, fcnt, pos, posr;
    
    forp=wordchr(p,"for");
    if(forp==NULL) { syntax: module_error("syntax_error"); *p=0; return; }
    *forp=0; forp+=strlen("for"); forp=find_word_start(forp);
    fp=find_word_start(p); strip_trailing_spaces(fp);
    if(*fp==0) goto syntax;
    if(type<5) i=cutfor(forp,NULL); else i=cutfor(forp,tbuf);
    if(i<0) goto syntax; if(i>0) {*p=0; return;}
    start=forstruct.from; stop=forstruct.to; step=forstruct.step;
    forp=forstruct.var;
    mystrncpy(buf,fp,sizeof(buf)); substitute(buf);
    for(fp=varchr(buf,forp); fp!=NULL; fp=varchr(fp,forp)) {
       string_modify(buf,fp,fp+strlen(forp),EV_X); fp+=strlen(EV_X);
    }
    for(fp=varchr(buf,"last"); fp!=NULL; fp=varchr(fp,"last")) {
       string_modify(buf,fp,fp+strlen("last"),EV_S); fp+=strlen(EV_S);
    }
    fcnt=pos=posr=0;
    if(type==5) goto skip;
    fcnt=itemnum(buf); if(fcnt>64) fcnt=64; pp=fbuf;
    for(k=0; k<fcnt; k++) {
       fnd_item(buf,k+1,vbuf); evalue_compile(vbuf);
       if(pp-fbuf+strlen(vbuf)<MAX_LINELEN-1) {
           f[k]=pp; strcpy(pp,vbuf); pp+=strlen(pp)+1;
       }
       else f[k]="";
    }
    pos=eval_getpos(EV_X); posr=eval_getpos(EV_S);
    skip:
    if(step==0) step=1;/* if(step<0) step=-step;
    if(stop<start) {dd=start; start=stop; stop=dd;} */
    *p=0; v0=0;
    switch(type) {
       case 4:
       case 1: {
           pp=getvar("recursion_start");
           if(pp==NULL || *pp==0) v0=0;
           else {
              v0=evalue(pp); if(!finite(v0)) return;
           }
           break;
       }
       case 2: v0=0; break;
       case 3: v0=1; break;
       case 5: break;
    }
    pp=p;
    if(type==5) {
       char *ps, *pt, buf2[MAX_LINELEN+1];
       int l,ln;
       *p=0; l=strlen(buf); if(l>=MAX_LINELEN) return;
       for(i=0,v=start; i<MAX_VALUE_LIST && v*step<=stop*step; v+=step, i++) {
           if(forstruct.type==for_from) {
              float2str(v,vbuf); ps=vbuf;
           }
           else ps=forstruct.pos[i];
           strcpy(buf2,buf); l=strlen(ps);ln=strlen(EV_X);
           for(pt=varchr(buf2,EV_X);pt!=NULL;pt=varchr(pt+l,EV_X)) 
             string_modify(buf2,pt,pt+ln,"%s",ps);
           if(pp-p+strlen(buf2)>=MAX_LINELEN-1) return;
           if(pp>p) *pp++=','; strcpy(pp,buf2);
           pp+=strlen(pp);
       }
       return;
    }
    for(i=0,v=start; i<MAX_VALUE_LIST && v*step<=stop*step; v+=step, i++) {
       if(forstruct.type==for_from) eval_setval(pos,v);
       else eval_setval(pos,forstruct.list[i]);
       eval_setval(posr,v0);
       for(k=0; k<fcnt; k++) {
           set_evalue_error(0); set_evalue_pointer(f[k]); dd=_evalue(10);
           switch(type) {
              case 1: {     /* values */
                  float2str(dd,vbuf);
                  if(pp-p+strlen(vbuf)<MAX_LINELEN-1) {
                     if(pp>p) *pp++=','; strcpy(pp,vbuf);
                     pp+=strlen(pp);
                  }
                  v0=dd; break;
              }
              case 2: {     /* sum */
                  v0=v0+dd; break;
              }
              case 3: {     /* product */
                  v0=v0*dd; break;
              }
              case 4: {     /* recursion */
                  v0=dd; break;
              }
           }
       }
    }
    if(type!=1) float2str(v0,p);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void calc_append ( char *  p)

Definition at line 714 of file calc.c.

{
    char append_char, *p1,*p2,*p3,*p4;
    int i,l1,l2;
    p1=find_word_start(p);p2=find_word_end(p1);
    if(*p2!=0) *p2++=0;
    for(i=0;i<append_obj_no && strcmp(p1,append_obj[i])!=0;i++);
    if(i>=append_obj_no) {
       synterr:
       module_error("append_syntax");
       *p=0; return;
    }
    append_char=apch_list[i];
    p3=wordchr(p2,"to");
    if(p3==NULL) goto synterr;
    for(p4=p3-1;p4>p2 && isspace(*(p4-1));p4--);
    *p4=0;p3=find_word_start(p3+strlen("to"));
    memmove(tmplbuf,p2,p4-p2); tmplbuf[p4-p2]=0; strcpy(p,p3);
    substit(tmplbuf);substit(p);
    l1=strlen(p); l2=strlen(tmplbuf);
    if(l1+l2>=MAX_LINELEN-1) user_error("cmd_output_too_long");
    p3=find_word_start(p); p4=p+l1;
    if(*p3) *p4++=append_char;
    memmove(p4,tmplbuf,l2); p4[l2]=0;
}

Here is the call graph for this function:

void calc_charof ( char *  p)

Definition at line 702 of file calc.c.

{
    _blockof(p,charnum,fnd_char,"","char");
}

Here is the call graph for this function:

void calc_checkdata ( char *  p)

Definition at line 2028 of file calc.c.

{
    char *p1, *p2, buf[MAX_LINELEN+1], nbuf[MAX_FNAME+1];
    struct stat st;
    
    memmove(p,"yes",4);
    p1=getvar("module_data");
    if(p1==NULL || *p1==0) return;
    snprintf(buf,sizeof(buf),"%s",p1);
    for(p2=buf; *p2; p2++) if(*p2==',' || *p2==';') *p2=' ';
    if(strstr(buf,"..")!=NULL) {
       snprintf(p,MAX_LINELEN,"badly_defined_data_module");
       return;
    }
    for(p1=find_word_start(buf); *p1; p1=find_word_start(p2)) {
       p2=find_word_end(p1); if(*p2) *p2++=0;
       snprintf(nbuf,sizeof(nbuf),"%s/%s/INDEX",module_dir,p1);
       if(stat(nbuf,&st)<0) {
           snprintf(nbuf,sizeof(nbuf),"%s/%s/index",module_dir,p1);
           if(stat(nbuf,&st)<0) {
              snprintf(p,MAX_LINELEN,"%s",p1);
              return;
           }
       }
    }
}

Here is the call graph for this function:

void calc_checkhost ( char *  p)

Definition at line 1430 of file calc.c.

{
    int t;
    if(robot_access || !trusted_module()) strcpy(p,"0");
    else {
       t=checkhost(p); mystrncpy(p,int2str(t),MAX_LINELEN);
    }
}

Here is the call graph for this function:

void calc_columnof ( char *  p)

Definition at line 1493 of file calc.c.

{
    char *p1, *p2, *bufp, sep;
    char buf1[MAX_LINELEN+1], buf2[MAX_LINELEN+1];
    char buf[MAX_LINELEN+1];
    p2=wordchr(p,"of"); if(p2==NULL) module_error("syntax_error");
    *p2=0; p2+=strlen("of");
    p2=find_word_start(p2); strip_trailing_spaces(p2);
    p1=find_word_start(p) ; strip_trailing_spaces(p1);
    if(*p1==0) module_error("syntax_error");
    if(*p2==0) {*p=0; return;}
    strcpy(buf1,p1); strcpy(buf2,p2); sep='\n';
       /* buf1: number(s); buf2: matrix. */
    substit(buf1); substit(buf2); 
    if(rows2lines(buf2)) sep=';';
    if(strchr(buf1,',')==NULL && wordchr(buf1,"to")==NULL
       && strstr(buf1,"..")==NULL) sep=',';
    buf[0]=0; bufp=buf;
    for(p1=buf2; *p1; p1=p2) {
       char ibuf[MAX_LINELEN+1];
       p2=strchr(p1,'\n');
       if(p2==NULL) p2=p1+strlen(p1); else *p2++=0;
       snprintf(ibuf,sizeof(ibuf),"%s of %s",buf1,p1);
       calc_itemof(ibuf);
       snprintf(bufp,MAX_LINELEN-(bufp-buf),"%s%c",ibuf,sep);
       bufp+=strlen(bufp);
    }
    if(buf[0]!=0) buf[strlen(buf)-1]=0;
    mystrncpy(p,buf,MAX_LINELEN);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void calc_daemon ( char *  p)

Definition at line 151 of file calc.c.

{
    if(!trusted_module() || is_class_module) {*p=0; return;}
    _daemoncmd(p);
}

Here is the call graph for this function:

void calc_date ( char *  p)

Definition at line 1037 of file calc.c.

{
    char *p1, *p2, *p3;
    if(!trusted_module() || is_class_module) {
       if(strstr(p,"..")!=NULL) return;
       for(p1=find_word_start(p); *p1; p1=find_word_start(p2)) {
           p2=find_word_end(p1);
           while(*p1=='\'' || *p1=='"') p1++;
           if(*p1!='-') continue;
           for(p3=p1+1;p3<p2;p3++) if(strchr("rs",*p3)!=NULL) return;
       }
    }
    wrapexec=1;
    call_ssh("date %s >%s/date.out 2>/dev/null",p,tmp_dir);
    read_tmp_file(p,"date.out");
}

Here is the call graph for this function:

void calc_debug ( char *  p)

Definition at line 145 of file calc.c.

{
    secure_exec(); setvar("debug",p); module_error("debug");
}

Here is the call graph for this function:

void calc_declosing ( char *  p)

Definition at line 1385 of file calc.c.

Here is the call graph for this function:

void calc_defof ( char *  p)

Definition at line 1413 of file calc.c.

{
    char *p1;
    char fbuf[MAX_FNAME+1], nbuf[MAX_LINELEN+1], tbuf[MAX_LINELEN+1];
    
    secure_exec();
    p1=wordchr(p,"in"); if(p1==NULL) module_error("syntax_error");
    *p1=0; p1=find_word_start(p1+strlen("in"));
    mystrncpy(nbuf,p,sizeof(nbuf));  mystrncpy(tbuf,p1,sizeof(tbuf));
    substit(nbuf); substit(tbuf);
    p1=find_word_start(tbuf); *find_word_end(p1)=0;
    if(find_module_file(p1,fbuf,0)) {*p=0; return;}
    p1=find_word_start(nbuf); strip_trailing_spaces(p1);
    getdef(fbuf,p1,p);
}

Here is the call graph for this function:

void calc_detag ( char *  p)

Definition at line 1391 of file calc.c.

{
    char *p1, *p2;
    for(p1=strchr(p,'<'); p1!=NULL; p1=strchr(p1,'<')) {
       p2=strchr(p1,'>'); if(p2==NULL) p1++;
       else strcpy(p1,p2+1);
    }
}

Here is the caller graph for this function:

void calc_embraced ( char *  p)

Definition at line 1987 of file calc.c.

{
    char *p1, *p2, buf[MAX_LINELEN+1];

    p1=find_word_start(p); p2=find_word_end(p1);
    if(*p2==0) {*p=0; return;}
    *p2++=0; p2=find_word_start(p2);
    mystrncpy(buf,p2,sizeof(buf)); substit(buf);
    if(p1>p) strcpy(p,p1); substit(p);
    if(strcmp(p,"randitem")==0) {_embraced(buf,calc_randitem); goto end;}
    if(strcmp(p,"extract")==0) {
       p1=strchr(buf,'{'); if(p1!=NULL) {
           p2=find_matching(++p1,'}');
           if(p2!=NULL) {
              memmove(buf,p1,p2-p1); buf[p2-p1]=0;
           }
           else buf[0]=0;
       }
       else buf[0]=0;
       goto end;
    }
    if(strcmp(p,"delete")==0) {
       for(p1=strchr(buf,'{'); p1; p1=strchr(p1,'{')) {
           p2=find_matching(p1+1,'}');
           if(p2) strcpy(p1,p2+1); else p1++;
       }
       goto end;
    }
    module_error("syntax_error");
    
    end:
    mystrncpy(p,buf,MAX_LINELEN);
}

Here is the call graph for this function:

void calc_evalsubst ( char *  p)

Definition at line 380 of file calc.c.

Here is the call graph for this function:

void calc_evalue ( char *  p)

Definition at line 348 of file calc.c.

{
    double d;
    d=evalue(p); float2str(d,p); return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void calc_exec ( char *  p)

Definition at line 186 of file calc.c.

{
    int i,j,k;
    char *cmd, *parm, *pp;
    char namebuf[MAX_EXEC_NAME+1], cmdstr[MAX_LINELEN+256], obuf[MAX_LINELEN+1];
    char outfname[MAX_FNAME+1], errorfname[MAX_FNAME+1],
      typefname[MAX_FNAME+1], varfname[MAX_FNAME+1];
    char *abuf[2]={NULL,NULL};
    WORKING_FILE wf;
    if(robot_access || time(0)>=limtimex-1) {
       *p=0;return;
    }
    cmd=find_word_start(p); if(*cmd==0) return; /* No command. */
    parm=find_word_end(cmd);j=parm-cmd;parm=find_word_start(parm);
    if(j>MAX_EXEC_NAME) {
       wrong_command:
       setvar(error_data_string,namebuf); module_error("bad_cmd");
       *p=0; return; /* should not occur */
    }
    memmove(namebuf,cmd,j); namebuf[j]=0;
       /* Specifying parent directory in command name is of course
        * prohibited.
        * The module developper cannot start from root, for bin_dir
        * will be prefixed to cmd. */
    if(strstr(namebuf,parent_dir_string)!=NULL) {
       setvar(error_data_string,namebuf); module_error("illegal_cmd");
       *p=0; return;
    }
    snprintf(cmdstr,sizeof(cmdstr),"%s/%s",bin_dir,namebuf);
    if(ftest(cmdstr)!=is_exec) goto wrong_command;
    abuf[0]=cmdstr;
    mkfname(outfname,"%s/exec.out",tmp_dir);
    mkfname(errorfname,"%s/exec.err",tmp_dir);
    mkfname(typefname,"%s/exec.type",tmp_dir);
    unlink(typefname);
    mkfname(varfname,"%s/exec.var",tmp_dir);
    unlink(varfname);
    if(!trusted_module()) setenv("untrust","yes",1); else unsetenv("untrust");
    if(strcmp(parm,"about")!=0 && multiexec(namebuf,abuf)) {
       fd_set rset;
       struct timeval t;
       int v1, v2, fd;
       
       i=strlen(parm);
       fd=mxtab[multiexec_index].pipe_stdin[1];
       write(fd,parm,i);
       write(fd,multiexec_random,strlen(multiexec_random));
       *p=0; i=0; k=MAX_LINELEN; fd=mxtab[multiexec_index].pipe_stdout[0];
       while(k>0) {
           FD_ZERO(&rset); FD_SET(fd,&rset);
           t.tv_sec=0; t.tv_usec=100000; v1=0; v2=300;  /* 3 seconds */
           if(select(fd+1,&rset,NULL,NULL,&t)<=0) {
              v1++; if(v1>=v2) break;
              else continue;
           }
           j=read(fd,p+i,k);
           if(j<0 || j>k) break;
           i+=j; k-=j; p[i]=0;
           pp=strstr(p,multiexec_random);
           if(pp) {*pp=0; break;}
       }
       fd=mxtab[multiexec_index].pipe_stderr[0];
       FD_ZERO(&rset); FD_SET(fd,&rset);
       t.tv_sec=0; t.tv_usec=0;
       if(select(fd+1,&rset,NULL,NULL,&t)>0)
         _get_exec_error(NULL,namebuf);
       strip_trailing_spaces(p);
       return;
    }
    exportall(); setenv("wims_exec_parm",parm,1);
    execredirected(cmdstr,NULL,outfname,errorfname,abuf);
    if(open_working_file(&wf,varfname)==0) {
       char *pt, *pv;
       while(wgetline(tmplbuf,MAX_LINELEN, &wf)!=EOF) { 
           pt=find_word_start(tmplbuf); pv=strchr(pt,'=');
           if(pv==NULL || pv<=tmplbuf) continue;
           *pv=0; pv=find_word_start(++pv);
           *find_word_end(pt)=0;
           strip_trailing_spaces(pv);
           setvar(pt,pv);
       }
       close_working_file(&wf,0);
    }
    read_tmp_file(p,"exec.out");
    read_tmp_file(obuf,"exec.type");
    if(obuf[0]) k=atoi(obuf); else k=0;
    for(i=2;i<=k && i<256;i++) {
       char nbuf[32];
       snprintf(nbuf,sizeof(nbuf),"exec.out.%d",i);
       read_tmp_file(obuf,nbuf);
       if(obuf[0]) {
           snprintf(nbuf,sizeof(nbuf),"wims_exec_out_%d",i);
           force_setvar(nbuf,obuf);
       }
    }
    strip_trailing_spaces(p);
    _get_exec_error(errorfname,namebuf);
    return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void calc_getopt ( char *  p)

Definition at line 1921 of file calc.c.

{
    char *p1, *p2, *p3, *p4;
    char buf1[MAX_LINELEN+1], buf2[MAX_LINELEN+1];
    
    p1=wordchr(p,"in"); if(p1==NULL) module_error("syntax error");
    *p1=0; p1=find_word_start(p1+3);
    mystrncpy(buf1,p,MAX_LINELEN); mystrncpy(buf2,p1,MAX_LINELEN);
    substitute(buf1); substitute(buf2);
    p1=find_word_start(buf1); *find_word_end(p1)=0;
    for(p2=buf2;*p2;p2++) {
       if(myisspace(*p2)) *p2=' ';
       if(*p2=='=') *p2='   ';
    }
    *p=0;
    p2=wordchr(buf2,p1); if(p2==NULL) return;
    for(p3=find_word_end(p2);myisspace(*p3);p3++) {
       if(*p3=='     ') {
           p3=find_word_start(p3);
           switch(*p3) {
              case '"': {
                  p4=strchr(p3+1,'"');
                  goto tested;
              }
              case '(': {
                  p4=find_matching(p3+1,')');
                  goto tested;
              }
              case '[': {
                  p4=find_matching(p3+1,']');
                  goto tested;
              }
              case '{': {
                  p4=find_matching(p3+1,'}');
                  tested:
                  if(p4) {
                     p3++; *p4=0; break;
                  }
                  else goto nomatch;
              }
              default: {
                  nomatch: 
                  *find_word_end(p3)=0;
              }
           }
           mystrncpy(p,p3,MAX_LINELEN);
           return;
       }
    }
    *find_word_end(p2)=0;
    mystrncpy(p,p2,MAX_LINELEN);
}

Here is the call graph for this function:

void calc_hex ( char *  p)

Definition at line 1001 of file calc.c.

{
    unsigned char *p1, orig[MAX_LINELEN+1];
    char *p2;
    char *hex="0123456789ABCDEF";
    
    mystrncpy(orig,p,MAX_LINELEN);
    for(p1=orig, p2=p; *p1 && p2-p<MAX_LINELEN-2; p1++) {
       *p2++=hex[(*p1>>4)&15]; *p2++=hex[*p1&15];
    }
    *p2=0;    
}

Here is the call graph for this function:

void calc_imgrename ( char *  p)

Definition at line 1851 of file calc.c.

{
    char buf[MAX_LINELEN+1], buf2[MAX_LINELEN+1];
    char *p1, *p2, *p3, *p4;
    
    for(p1=varchr(p,"imgrename"); p1!=NULL; p1=varchr(p1,"imgrename")) {
       p2=find_word_start(p1+strlen("imgrename"));
       if(*p2!='(') {p1=p2; continue;}
       p2++; p3=find_matching(p2,')');
       if(*p3!=')') {p1=p2-1; continue;}
       p2=find_word_start(p2); p4=find_word_end(p2);
       memmove(buf,p2,p4-p2); buf[p4-p2]=0;
       calc_rename(buf); *p3=0;
       snprintf(buf2,sizeof(buf2),"<img src=\"%s\"%s>",buf, p4);
       *p3=')'; p3++;
       string_modify(p,p1,p3,"%s",buf2);
       p1+=strlen(buf2);
    }
    
}

Here is the call graph for this function:

void calc_instexst ( char *  p)

Definition at line 1076 of file calc.c.

{
    char nbuf[MAX_FNAME+1], bufc[MAX_LINELEN+1];
    char buf2[1024], altbuf[1024], buf[MAX_LINELEN+1], urlbuf[MAX_LINELEN+1];
    char *b, *at, *al, *md1, *md2;
    int t, border, vspace;
    struct stat st,stc;
    char *p1, *p2, *p3, *ppp, *pt;

    if(robot_access) {*p=0; return;}
    p1=find_word_start(p); p2=find_word_end(p1);
    p3=p2-4; vspace=0;
    fix_tex_size();
    t=untrust; untrust=0; 
    if(find_module_file(m_file.name,bufc,0)) module_error(m_file.name);
    else stat(bufc,&stc);
    untrust=t;
    if(*p3=='.' && (memcmp(p3+1,"gif",3)==0 || memcmp(p3+1,"png",3)==0)) {
       char mbuf[MAX_LINELEN+1];
       if(*p2!=0) *p2++=0;
       p2=find_word_start(p2);
       strcpy(mbuf,p1); substit(mbuf);
       if(strstr(mbuf,parent_dir_string)!=NULL) {
           setvar(error_data_string,mbuf);
           module_error("illegal_fname"); return;
       }
       mkfname(nbuf,"%s/%s",module_prefix,mbuf);
    }
    else {
       ppp=getvar(ro_name[ro_module]);
       if(ppp==NULL) internal_error("calc_instexst(): module name vanishes.");
       p2=p1;
       mkfname(nbuf,"w/instex/%d/%s/%s_%d.gif",
               current_tex_size,ppp,m_file.name,m_file.l);
    }
    snprintf(urlbuf,sizeof(urlbuf),"%s%s?%X",ref_base,nbuf,
            (unsigned short int) stc.st_mtime);
    mystrncpy(buf,nbuf,sizeof(buf));
    if((ppp=strrchr(buf,'/'))!=NULL) {
       *ppp=0;mkdirs(buf);
    }
    b=getvar("ins_border");
    at=getvar("ins_attr");
    al=getvar("ins_align");
    if(at==NULL) at="";
    if(al==NULL) al="";al=find_word_start(al);
    if(*al!=0) snprintf(buf2,sizeof(buf2),"align=%s",al); else buf2[0]=0;
    if(b==NULL || *b==0) border=0;
    else border=atoi(b);
    if(border<0) border=0; if(border>100) border=100;
    if(instex_ready(p2,urlbuf)) goto prt;
    if(stat(nbuf,&st)!=0 || st.st_mtime<stc.st_mtime || st.st_size<45) {
       setenv("texgif_style",instex_style,1);
       setenv("texgif_src",p2,1);
       setenv("texgif_outfile",nbuf,1);
       setenv("texgif_tmpdir",tmp_dir,1); exportall();
       wrapexec=0; call_ssh("%s &>%s/instexst.log",tex2gif,tmp_dir);
       setenv("instexst_src","",1);
    }
    prt: md1=md2="";
    if(strcasecmp(al,"middle")==0) {
       md1=mathalign_sup1; md2=mathalign_sup2;
       vspace=5;
    }
    if(ins_alt[0]==0) mystrncpy(ins_alt,p2,sizeof(ins_alt));
    if(strchr(ins_alt,'"')!=NULL || strlen(ins_alt)>256) ins_alt[0]=0;
    pt=getvar("wims_ins_alt"); if(pt==NULL) pt="";
    if(ins_alt[0] && strcmp(pt,"none")!=0)
      snprintf(altbuf,sizeof(altbuf)," alt=\"%s\"",ins_alt);
    else altbuf[0]=0;
    snprintf(p,MAX_LINELEN,"%s<img src=\"%s\" border=%d vspace=%d %s %s%s>%s",
            md1,urlbuf,border,vspace,at,buf2,altbuf,md2);
    setvar("ins_attr",""); ins_alt[0]=0;
    setvar("ins_url",urlbuf);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void calc_itemnum ( char *  p)

Definition at line 572 of file calc.c.

{
    int i=itemnum(p); mystrncpy(p,int2str(i),MAX_LINELEN);
}

Here is the call graph for this function:

void calc_itemof ( char *  p)

Definition at line 684 of file calc.c.

{
    _blockof(p,itemnum,fnd_item,", ","item");
}

Here is the call graph for this function:

Here is the caller graph for this function:

void calc_lengthof ( char *  p)

Definition at line 591 of file calc.c.

{
    int i;
/* Strip leading and trailing spaces? */  
    i=strlen(p); mystrncpy(p,int2str(i),MAX_LINELEN);
}

Here is the call graph for this function:

void calc_leveldata ( char *  p)

Definition at line 1702 of file calc.c.

{
    leveldata ld;
    char *sizep, *rangep, *fp, *levelp, *stepp;
    char *pp,*p2,fbuf[MAX_LINELEN+1],buf[MAX_LINELEN+1];
    double d[4];
    int i;
    
    sizep=wordchr(p,"size");
    rangep=wordchr(p,"ranges");
    fp=wordchr(p,"function");
    levelp=wordchr(p,"levels");
    stepp=wordchr(p,"step");
    if(sizep==NULL || rangep==NULL || fp==NULL) {
       syntax: module_error("syntax_error"); *p=0; return;
    }
    *sizep=0; sizep+=strlen("size");
    *rangep=0; rangep+=strlen("ranges");
    *fp=0; fp+=strlen("function");
    if(levelp!=NULL) {*levelp=0; levelp+=strlen("levels");}
    else levelp="0";
    if(stepp!=NULL) {*stepp=0; stepp+=strlen("step");}
    else stepp="0";
    mystrncpy(fbuf,fp,sizeof(fbuf)); substitute(fbuf);
    ld.fn=fbuf;
    ld.xname="x"; ld.yname="y"; ld.grain=evalue(stepp);
    mystrncpy(buf,sizep,sizeof(buf)); substitute(buf);
    for(i=0,pp=buf;i<2;i++,pp=p2) {
       if(*pp==0) goto syntax;
       p2=find_item_end(pp); if(*p2) *p2++=0;
       d[i]=evalue(pp);
    }
    ld.xsize=d[0]; ld.ysize=d[1];
    mystrncpy(buf,rangep,sizeof(buf)); substitute(buf);
    for(i=0,pp=buf;i<4;i++,pp=p2) {
       if(*pp==0) goto syntax;
       p2=find_item_end(pp); if(*p2) *p2++=0;
       d[i]=evalue(pp);
    }
    ld.xrange[0]=d[0]; ld.xrange[1]=d[1]; ld.yrange[0]=d[3]; ld.yrange[1]=d[2];
    mystrncpy(buf,levelp,sizeof(buf)); substitute(buf);
    ld.levelcnt=itemnum(buf); if(ld.levelcnt>LEVEL_LIM) ld.levelcnt=LEVEL_LIM;
    for(i=0,pp=buf;i<ld.levelcnt;i++,pp=p2) {
       if(*pp==0) goto syntax;
       p2=find_item_end(pp); if(*p2) *p2++=0;
       ld.levels[i]=evalue(pp);
    }
    levelcurve(&ld);
    for(i=0, pp=p; i<ld.datacnt && pp<p+MAX_LINELEN-16; i++) {
       float2str(ld.xdata[i],buf);
       if(pp-p+strlen(buf)<MAX_LINELEN-1) {
           if(pp>p) *pp++=';'; strcpy(pp,buf); pp+=strlen(pp);
       }
       float2str(ld.ydata[i],buf);
       if(pp-p+strlen(buf)<MAX_LINELEN-1) {
           if(pp>p) *pp++=','; strcpy(pp,buf); pp+=strlen(pp);
       }
    }
}

Here is the call graph for this function:

void calc_linenum ( char *  p)

Definition at line 560 of file calc.c.

{
    int i=linenum(p); mystrncpy(p,int2str(i),MAX_LINELEN);
}

Here is the call graph for this function:

void calc_lineof ( char *  p)

Definition at line 668 of file calc.c.

{
    _blockof(p,linenum,fnd_line,"\n","line");
}

Here is the call graph for this function:

void calc_lines2rows ( char *  p)

Definition at line 2024 of file calc.c.

{      lines2rows(p);       }

Here is the call graph for this function:

void calc_listcomplement ( char *  p)

Definition at line 1277 of file calc.c.

{
    char l1[MAX_LINELEN+1],l2[MAX_LINELEN+1],lout[MAX_LINELEN+2];
    char *cut[MAX_LIST];
    char *pp, *ll;
    int i,n;
    
    pp=wordchr(p,"in");
    if(pp==NULL) module_error("syntax_error");
    *pp=0;strcpy(l1,p); strcpy(l2,pp+strlen("in"));
    lout[0]=lout[1]=0; substit(l1); substit(l2);
    n=cutitems(l2,cut,MAX_LIST); if(n<=0) {*p=0; return;}
    for(i=0;i<n;i++) {
       ll=cut[i];
       if(ll[0] && itemchr(l1,ll)==NULL && itemchr(lout,ll)==NULL &&
          strlen(lout)+strlen(ll)<MAX_LINELEN-2) {
           strcat(lout,",");strcat(lout,ll);
       }
    }
    strcpy(p,lout+1);
}

Here is the call graph for this function:

void calc_listfile ( char *  p)

Definition at line 1055 of file calc.c.

{
    char *pp;
    
       /* only for trusted modules */
    if(!trusted_module() || is_class_module) {
       module_error("not_trusted"); *p=0; return; 
    }
       /* security measures. */
    for(pp=p;*pp;pp++) if(isspace(*pp) || *pp==';') *pp=' ';
    if(strstr(p,parent_dir_string)!=NULL) {
       setvar(error_data_string,p);
       module_error("illegal_fname"); return;
    }
    wrapexec=1;
    call_sh("ls %s >%s/ls.out 2>%s/ls.err",
           p,tmp_dir,tmp_dir);
    read_tmp_file(p,"ls.out");
}

Here is the call graph for this function:

void calc_listintersect ( char *  p)

Definition at line 1225 of file calc.c.

{
    char l1[MAX_LINELEN+1],l2[MAX_LINELEN+1],lout[MAX_LINELEN+2];
    char *cut[MAX_LIST];
    char *pp, *ll;
    int i,n;
    
    pp=wordchr(p,"and");
    if(pp==NULL) module_error("syntax_error");
    *pp=0;strcpy(l1,p); strcpy(l2,pp+strlen("and"));
    lout[0]=lout[1]=0; substit(l1); substit(l2);
    n=cutitems(l1,cut,MAX_LIST); if(n<=0) {*p=0; return;}
    for(i=0;i<n;i++) {
       ll=cut[i];
       if(ll[0] && itemchr(l2,ll)!=NULL && itemchr(lout,ll)==NULL &&
          strlen(lout)+strlen(ll)<MAX_LINELEN-2) {
           strcat(lout,",");strcat(lout,ll);
       }
    }
    strcpy(p,lout+1);
}

Here is the call graph for this function:

void calc_listunion ( char *  p)

Definition at line 1248 of file calc.c.

{
    char l1[MAX_LINELEN+1],l2[MAX_LINELEN+1],lout[MAX_LINELEN+2];
    char *cut[MAX_LIST];
    char *pp, *ll;
    int i,n;
    
    pp=wordchr(p,"and");
    if(pp==NULL) module_error("syntax_error");
    *pp=0;strcpy(l1,p); strcpy(l2,pp+strlen("and"));
    lout[0]=lout[1]=0; substit(l1); substit(l2);
    n=cutitems(l1,cut,MAX_LIST); for(i=0;i<n;i++) {
       ll=cut[i];
       if(ll[0] && itemchr(lout,ll)==NULL &&
          strlen(lout)+strlen(ll)<MAX_LINELEN-2) {
           strcat(lout,",");strcat(lout,ll);
       }
    }
    n=cutitems(l2,cut,MAX_LIST); for(i=0;i<n;i++) {
       ll=cut[i];
       if(ll[0] && itemchr(lout,ll)==NULL &&
          strlen(lout)+strlen(ll)<MAX_LINELEN-2) {
           strcat(lout,",");strcat(lout,ll);
       }
    }
    strcpy(p,lout+1);
}

Here is the call graph for this function:

void calc_listuniq ( char *  p)

Definition at line 1208 of file calc.c.

{
    int i,n;
    char lout[MAX_LINELEN+2], *ll;
    char *cut[MAX_LIST];
    lout[0]=lout[1]=0;
    n=cutitems(p,cut,MAX_LIST); for(i=0;i<n;i++) {
       ll=cut[i];
       if(*ll && itemchr(lout,ll)==NULL &&
          strlen(lout)+strlen(ll)<MAX_LINELEN-2) {
           strcat(lout,",");strcat(lout,ll);
       }
    }
    strcpy(p,lout+1);
}

Here is the call graph for this function:

void calc_lookup ( char *  p)

Definition at line 1786 of file calc.c.

{
    char buf2[MAX_LINELEN+1], buf3[MAX_FNAME+1];
    char *p2;
    
    p2=wordchr(p,"in"); if(p2==NULL) {abort: *p=0; return;}
    *p2=0;p2=find_word_start(p2+2);
    mystrncpy(buf2,p2,sizeof(buf2)); substit(buf2);
    *find_word_end(buf2)=0;
    if(strstr(buf2,parent_dir_string)!=NULL) {
       force_setvar("wims_error_data",buf2); module_error("illegal_cmd");
    }
    if(strncmp(buf2,"bases/",strlen("bases/"))!=0) {
       if(datafile_check(buf2)!=0 || find_module_file(buf2,buf3,0)!=0)
         goto abort;
       _lookup(p,buf3);
    }
    else _lookup(p,buf2); 
}

Here is the call graph for this function:

void calc_mailurl ( char *  p)

Definition at line 1909 of file calc.c.

{
    char *p0, buf[MAX_LINELEN+1];
    
    if(robot_access) {*p=0; return;}
    snprintf(buf,sizeof(buf),"mailurl.proc %s",p);
    exec_readproc(buf);
    p0=getvar("mailurl_"); if(p0==NULL) p0="";
    mystrncpy(p,p0,MAX_LINELEN);
}

Here is the call graph for this function:

void calc_makelist ( char *  p)

Definition at line 1698 of file calc.c.

{ _values(p,5); }

Here is the call graph for this function:

void calc_mathsubst ( char *  p)

Definition at line 355 of file calc.c.

{
    char *expr, *val, *nam, *pp;
    char buf[MAX_LINELEN+1];
    expr=wordchr(p,"in"); if(expr==NULL) goto error;
    strcpy(buf,find_word_start(expr+strlen("in")));substit(buf);
    *expr=0; substit(p);
    val=strchr(p,'=');
    if(val==NULL) {
       error:
       module_error("mathsubst_syntax"); *p=0;return; 
    }
    nam=find_word_start(p); *val=0;
    val=find_word_start(val+1);
    for(pp=val+strlen(val)-1;pp>=val && isspace(*pp);*pp--=0);
    *find_word_end(nam)=0;
    if(*nam==0) goto error;
    if(*nam) for(pp=varchr(buf,nam);pp!=NULL;pp=varchr(pp,nam)) {
       string_modify(buf,pp,pp+strlen(nam),"%s",val);
       pp+=strlen(val);
    }
    strcpy(p,buf);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void calc_mexec ( char *  p)

Definition at line 288 of file calc.c.

{
    char *public_bin;
    if(robot_access) return;
    if(trusted_module()!=1 || is_class_module) {
       module_error("not_trusted"); *p=0; return;
    }
       /* The following is useless, because mexec content is often given
        * by variables */
/*    if(strstr(p,PARENT_DIR_STRING)!=NULL) {
       setvar("wims_error_data",p);
       module_error("illegal_fname"); *p=0; return;
    }
*/    public_bin=bin_dir; bin_dir=module_prefix;
    exec_is_module=1;
    calc_exec(p); bin_dir=public_bin;
    exec_is_module=0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void calc_module ( char *  p)

Definition at line 1343 of file calc.c.

{
    char *p1,*p2, ind_buf[MAX_LINELEN+1], buf[MAX_FNAME+1];
    char *tp;
    
    p1=find_word_start(p); p2=find_word_end(p1);
    if(*p2!=0) *p2++=0;
    p2=find_word_start(p2); *find_word_end(p2)=0;
    if(*p1==0) {empty: *p=0; return;}
    if(*p2==0) {
       snprintf(buf,sizeof(buf),"module_%s",p1);
       p1=getvar(buf); if(p1==NULL) p1="";
       mystrncpy(p,p1,MAX_LINELEN); return;
    }
    mkfname(buf,"%s/%s/INDEX",module_dir,p2);
    tp=readfile(buf,ind_buf,MAX_LINELEN);
    if(tp==NULL) {
       mkfname(buf,"%s/%s/index",module_dir,p2);
       tp=readfile(buf,ind_buf,MAX_LINELEN);
    }
    if(tp==NULL && p2[strlen(p2)-3]!='.') {
       mkfname(buf,"%s/%s.%s/INDEX",module_dir,p2,lang);
       tp=readfile(buf,ind_buf,MAX_LINELEN); if(tp==NULL) {
           mkfname(buf,"%s/%s.%s/index",module_dir,p2,lang);
           tp=readfile(buf,ind_buf,MAX_LINELEN);
       }
       if(tp==NULL) {
           int i;
           for(i=0;i<available_lang_no;i++) {
              mkfname(buf,"%s/%s.%s/INDEX",module_dir,p2,available_lang[i]);
              tp=readfile(buf,ind_buf,MAX_LINELEN); if(tp) break;
              mkfname(buf,"%s/%s.%s/index",module_dir,p2,
                      available_lang[i]);
              tp=readfile(buf,ind_buf,MAX_LINELEN); if(tp) break;
           }
       }
    }
    if(tp==NULL) goto empty;       /* module not found */
    _getdef(ind_buf,p1,p);
}

Here is the call graph for this function:

void calc_nonempty ( char *  p)

Definition at line 1153 of file calc.c.

{
    int type, i, cnt;
    char *p1, *p2, buf[MAX_LINELEN+1], out[MAX_LINELEN+1];
    p1=find_word_start(p); p2=find_word_end(p1);
    if(*p2) *p2++=0; else {
       *p=0; return;
    }
    type=0;
    if(strcasecmp(p1,"item")==0 || strcasecmp(p1,"items")==0) type=1;
    if(type==0 && (strcasecmp(p1,"line")==0 || strcasecmp(p1,"lines")==0))
      type=2;
    if(type==0 && (strcasecmp(p1,"row")==0 || strcasecmp(p1,"rows")==0))
      type=3;
    if(type==0) module_error("syntax_error");
    out[0]=out[1]=0;
    switch(type) {
       case 1: {     /* items */
           cnt=itemnum(p2);
           for(i=1; i<=cnt; i++) {
              fnd_item(p2,i,buf);
              if(*find_word_start(buf)) {
                  strcat(out,",");strcat(out,buf);
              }
           }
           break;
       }
       case 2: {     /* lines */
           lines: cnt=linenum(p2);
           for(i=1; i<=cnt; i++) {
              fnd_line(p2,i,buf);
              if(*find_word_start(buf)) {
                  strcat(out,"\n");strcat(out,buf);
              }
           }
           break;
       }
       case 3: {     /* rows */
           int t=rows2lines(p2);
           if(t==0) goto lines;
           cnt=linenum(p2);
           for(i=1; i<=cnt; i++) {
              fnd_line(p2,i,buf);
              if(*find_word_start(buf)) {
                  strcat(out,";");strcat(out,buf);
              }
           }
           break;
       }
       default: break;
    }
    strcpy(p,out+1);
}

Here is the call graph for this function:

void calc_passcheck ( char *  p)

Definition at line 1882 of file calc.c.

{
    
}
void calc_passcrypt ( char *  p)

Definition at line 1887 of file calc.c.

{
#ifdef HAVE_CRYPT
    char saltstr[4];
    char *p1, *p2, *pp, *s, buf[MAX_LINELEN+1];
    saltstr[0]='N'; saltstr[1]='v'; saltstr[2]=0; buf[0]=0; pp=buf;
    for(p1=find_word_start(p);*p1;p1=find_word_start(p2)) {
       p2=find_word_end(p1); if(*p2) *p2++=0;
       pp=pp+strlen(pp);
       if(pp>buf) s=" "; else s="";
       if(*p1=='*')
         snprintf(pp,MAX_LINELEN-(pp-buf),"%s%s",s,p1);
       else
         snprintf(pp,MAX_LINELEN-(pp-buf),"%s*%s",s,crypt(p1,saltstr));
    }
    strcpy(p,buf);
#endif
}

Here is the call graph for this function:

void calc_perl ( char *  p)

Definition at line 342 of file calc.c.

{
    _calc_exec(p,"perl","-e",2);
}

Here is the call graph for this function:

void calc_pos ( char *  p)

Definition at line 807 of file calc.c.

{
    char buf[2][MAX_LINELEN+1];
    char *p1, *p2;
    int  style;
    
    p1=find_word_start(p); p2=wordchr(p1,"in");
    if(p2==NULL) module_error("syntax_error");
    *p2=0;p2=find_word_start(p2+strlen("in"));
    strip_trailing_spaces(p1);
    strcpy(buf[0],p1);*find_word_end(buf[0])=0; style=0;
    if(strcmp(buf[0],"word")==0) style=1;
    else {
       if(strcmp(buf[0],"item")==0) style=2;
       else {
           if(strcmp(buf[0],"line")==0) style=3;
           else {
              if(strcmp(buf[0],"char")==0) style=4;
           }
       }
    }
    if(style>0) p1=find_word_start(find_word_end(p1));
    strcpy(buf[0],p1); strcpy(buf[1],p2);
    substit(buf[0]); substit(buf[1]); *p=0;
    switch(style) {
       case 0: {     /* string */
           char *pp, nbuf[10];
           int i,t;
           for(pp=strstr(buf[1],buf[0]);pp!=NULL;pp=strstr(pp+1,buf[0])) {
              i=pp-buf[1]; t=strlen(p); if(t>MAX_LINELEN-12) return;
              if(t>0) strcat(p,",");
              snprintf(nbuf,sizeof(nbuf),"%d",i); strcat(p,nbuf);
           }
           return;
       }
       case 1: {     /* word */
           _pos(buf[1],buf[0],style,p,fnd_word,wordnum);
           return;
       }
       case 2: {     /* item */
           _pos(buf[1],buf[0],style,p,fnd_item,itemnum);
           return;
       }
       case 3: {     /* line */
           _pos(buf[1],buf[0],style,p,fnd_line,linenum);
           return;
       }
       case 4: {     /* char */
           _pos(buf[1],buf[0],style,p,fnd_char,charnum);
           return;
       }
    }
}

Here is the call graph for this function:

void calc_product ( char *  p)

Definition at line 1690 of file calc.c.

{ _values(p,3); }

Here is the call graph for this function:

void calc_randchar ( char *  p)

Definition at line 466 of file calc.c.

{
    p[0]=p[(int) irand(strlen(p))];p[1]=0;
}

Here is the call graph for this function:

void calc_randdouble ( char *  p)

Definition at line 427 of file calc.c.

{
    double lbound, ubound;
    int n, i, t;
    char *parm[2], *p1;
    
    t=_randrep(p); n=cutitems(p,parm,2);
    if(n<=0) {
       snprintf(p,3,"0"); return; /* Random without bound: return 0. */
    }
    lbound=evalue(parm[0]);
    if(n<=1) ubound=0; /* Missing ubound: random between 0 and lbound. */
    else ubound=evalue(parm[1]);
    for(i=0,p1=p;i<t;i++) {
       float2str(drand(ubound-lbound)+lbound,tmplbuf);
       mystrncpy(p1,tmplbuf,MAX_LINELEN-(p1-p));
       p1+=strlen(p1);
       if(i<t-1 && p1-p<MAX_LINELEN) *p1++=',';
    }
    *p1=0; return;
}

Here is the call graph for this function:

void calc_randfile ( char *  p)

Definition at line 450 of file calc.c.

{
    char *pp, n[MAX_FNAME+1];
    int i, j;
    
    pp=find_word_start(p); *find_word_end(pp)=0;
    mystrncpy(n,pp,sizeof(n));
    i=datafile_recordnum(pp);
    if(i<=0) {  /* zero records */
       *p=0; return;
    }
    j=irand(i); datafile_fnd_record(n,j+1,p);
    return;
}

Here is the call graph for this function:

void calc_randint ( char *  p)

Definition at line 403 of file calc.c.

{
    int lbound, ubound, n, i, t;
    char *p1, *parm[2];

    t=_randrep(p); n=cutitems(p,parm,2);
    if(n<=0) {
       snprintf(p,3,"0"); return; /* Random without bound: return 0. */
    }
    lbound=evalue(parm[0]);
       /* Missing ubound: random between +-1 and lbound. */
    if(n<=1) {if(lbound<0) ubound=-1; else ubound=1;}
    else ubound=evalue(parm[1]);
    if(lbound>ubound) {i=lbound; lbound=ubound; ubound=i;}
    for(i=0,p1=p;i<t;i++) {
       if(i>0) *p1++=',';
       mystrncpy(p1,int2str((int) irand(ubound-lbound+1)+lbound),
                MAX_LINELEN-(p1-p)-1);
       p1+=strlen(p1);
    }
    return;
}

Here is the call graph for this function:

void calc_randitem ( char *  p)

Definition at line 471 of file calc.c.

{
    int i; char *b;
    i=itemnum(p);
    b=fnd_item(p,irand(i)+1,tmplbuf);
    mystrncpy(p,tmplbuf,MAX_LINELEN);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void calc_randline ( char *  p)

Definition at line 479 of file calc.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void calc_randperm ( char *  p)

Definition at line 499 of file calc.c.

{
    int n, i, j, k, t, pt, type;
    double v;
    char buf1[MAX_LINELEN+1],buf2[MAX_LINELEN+1];
    char *list[MAX_RANDPERM];
    int table[MAX_RANDPERM];
    char *p1,*p2,*pp;
    
    t=0; pt=0; pp=p;
    p1=find_word_start(p); p2=find_word_end(p1);
    if(p2-p1==strlen("even") && strncasecmp(p1,"even",strlen("even"))==0) {
       t=1; pp=p2;
    }
    if(p2-p1==strlen("odd") && strncasecmp(p1,"odd",strlen("odd"))==0) {
       t=-1; pp=p2;
    }
    
    p1=find_item_end(pp); if(*p1==',') {
       type=1; n=cutitems(pp,list,MAX_RANDPERM); v=0;
    }
    else {
       v=evalue(pp); n=v; type=0;
    }
    if(n==1 && !finite(v)) {strcpy(p,pp); goto shorder;}
    if(n<=0) {*p=0; return;}
    if(n==1 && type==0) {
       strcpy(p,"1"); 
       shorder: force_setvar("wims_shuffle_order","1"); return;
    }
    if(n>MAX_RANDPERM) n=MAX_RANDPERM;
    for(i=0;i<n;i++) table[i]=i;
       /* Uniformity of this algorithm is easy to show by induction. */
    for(i=0;i<n-1;i++) {
       j=irand(n-i)+i;      if(j==i) continue;
       k=table[i]; table[i]=table[j]; table[j]=k;
       pt++;
    }
    pt&=1;
    if((t==1 && pt==1) || (t==-1 && pt==0)) {
       k=table[0]; table[0]=table[1]; table[1]=k;
    }
    if(type) {mystrncpy(buf1,list[table[0]],MAX_LINELEN); p1=buf1+strlen(buf1);}
    else buf1[0]=0;
    mystrncpy(buf2,int2str(table[0]+1),MAX_LINELEN); p2=buf2+strlen(buf2);
    for(i=1;i<n;i++) {
       if(type) {
           j=strlen(list[table[i]]);
           if(p1-buf1+j>=MAX_LINELEN-1) module_error("cmd_output_too_long");
           *p1++=','; memmove(p1,list[table[i]],j+1); p1+=j;
       }
       *p2++=',';
       mystrncpy(p2,int2str(table[i]+1), MAX_LINELEN-(p2-buf2)-1);
       p2+=strlen(p2);
    }
    if(type) mystrncpy(p,buf1,MAX_LINELEN);
    else mystrncpy(p,buf2,MAX_LINELEN);
    force_setvar("wims_shuffle_order",buf2);
}

Here is the call graph for this function:

void calc_randrow ( char *  p)

Definition at line 486 of file calc.c.

Here is the call graph for this function:

void calc_randword ( char *  p)

Definition at line 491 of file calc.c.

Here is the call graph for this function:

void calc_recordnum ( char *  p)

Definition at line 578 of file calc.c.

Here is the call graph for this function:

void calc_recordof ( char *  p)

Definition at line 690 of file calc.c.

Here is the call graph for this function:

void calc_recursion ( char *  p)

Definition at line 1694 of file calc.c.

{ _values(p,4); }

Here is the call graph for this function:

void calc_reinput ( char *  p)

Definition at line 1402 of file calc.c.

{
    char *p1;
    for(p1=strchr(p,'&'); p1!=NULL; p1=strchr(p1,'&')) {
       p1++; string_modify(p,p1,p1,"amp;");
    }
    for(p1=strchr(p,'<'); p1!=NULL; p1=strchr(++p1,'<'))
      string_modify(p,p1,p1+1,"&lt;");
}
void calc_rename ( char *  p)

Definition at line 1807 of file calc.c.

{
    char buf1[MAX_LINELEN+1], buf2[MAX_LINELEN+1];
    char *p1, *ext, *s;
    int i,t;
    
    if(robot_access || strstr(p,"getfile")!=NULL) return;
    p1=find_word_start(p); *find_word_end(p1)=0;
    if(strncmp(p1,ref_name,strlen(ref_name))==0) p1+=strlen(ref_name);
    if(p1>p) strcpy(p,p1);
    if(strstr(p,parent_dir_string)!=NULL ||
       strncmp(p,"modules/adm/",strlen("modules/adm/"))==0) {
       badfile: force_setvar("wims_error_data",p); module_error("illegal_cmd");
    }
    if(strncmp(p,module_dir,strlen(module_dir))!=0 &&
       strncmp(p,"modules/data/",strlen("modules/data/"))!=0 &&
       strncmp(p,"scripts/data/",strlen("scripts/data/"))!=0 &&
       strncmp(p,"gifs",strlen("gifs"))!=0) goto badfile;
    mkfname(buf1,"%s/getfile",session_prefix); mkdirs(buf1);
    mkfname(buf1,"%s/.rename",session_prefix);
    mystrncpy(buf2,p,sizeof(buf2)); _lookup(buf2,buf1);
    if(buf2[0]!=0) { /* already */
       mystrncpy(p,buf2,MAX_LINELEN); return;
    }
    if(cwdbuf[0]==0) return;
    p1=p+strlen(p)-1;
    while(p1>p && isalnum(*p1)) p1--;
    if(p1>p && *p1=='.') ext=p1; else ext="";
    rerand: t=random();
    mkfname(buf1,"%s/%s",cwdbuf,p);
    mkfname(buf2,"%s/getfile/rename-%u%s",session_prefix,t,ext);
    if(ftest(buf2)>=0) goto rerand;
    i=symlink(buf1,buf2);
    s=getvar("wims_session"); if(s==NULL) return;
    if(good_httpd) snprintf(buf1,sizeof(buf1),
                         "getfile/rename-%u%s?session=%s", t,ext,s);
    else snprintf(buf1,sizeof(buf1),"%s?cmd=getfile&+session=%s&+special_parm=rename-%u%s",
                ref_name, s, t,ext);
    snprintf(buf2,sizeof(buf2),"%s:%s\n",p,buf1);
    accessfile(buf2,"a","%s/.rename",session_prefix);
    mystrncpy(p,buf1,MAX_LINELEN);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void calc_replace ( char *  p)

Definition at line 906 of file calc.c.

{
    int i,style,num,internal;
    char *q[3], *pp;
    char bf[4][MAX_LINELEN+17];
    char fn[3][MAX_FNAME+1], *arglist[8];
    char regexp_char='/';

    style=num=0;
    q[0]=find_word_start(p); internal=0;
    if(strncasecmp(q[0],"internal",strlen("internal"))==0 &&
       isspace(*(q[0]+strlen("internal")))) {
       q[0]=find_word_start(q[0]+strlen("internal"));
       internal=1;
    }
    q[1]=wordchr(q[0],"by"); q[2]=wordchr(q[0],"in");
    if(q[1]==NULL || q[2]==NULL) {
       module_error("replace_syntax"); *p=0; return;
    }
    *q[1]=0; *q[2]=0;
    q[1]=find_word_start(q[1]+strlen("by"));
    q[2]=find_word_start(q[2]+strlen("in"));
    mystrncpy(bf[0],q[0],sizeof(bf[0]));
    pp=find_word_end(bf[0]); if(*pp) *(pp++)=0;
    if(strcmp(bf[0],"word")==0) style=1;
    else {
       if(strcmp(bf[0],"item")==0) style=2;
       else {
           if(strcmp(bf[0],"line")==0) style=3;
           else {
              if(strcmp(bf[0],"char")==0) style=4;
           }
       }
    }
    if(style>0) {
       q[0]=find_word_start(find_word_end(q[0]));
       mystrncpy(bf[0],q[0],sizeof(bf[0]));
       pp=find_word_end(bf[0]); if(*pp) *(pp++)=0;
       if(strcmp(bf[0],"number")==0) {
           num=1; q[0]=find_word_start(pp);
       }
    }
    for(i=0;i<3;i++) {
       strip_trailing_spaces(q[i]);
       mystrncpy(bf[i],q[i],sizeof(bf[i]));
       substit(bf[i]);
    }
    if(bf[0][0]==0) {mystrncpy(p,bf[2],MAX_LINELEN); return;}
    switch(style) {
       case 1: { /* word */
           _obj_replace(bf[0],bf[1],bf[2],num,' ',p,
                      fnd_word,wordnum,wordchr);
           return;
       }
       case 2: { /* item */
           _obj_replace(bf[0],bf[1],bf[2],num,',',p,
                      fnd_item,itemnum,itemchr);
           return;
       }
       case 3: { /* line */
           _obj_replace(bf[0],bf[1],bf[2],num,'\n',p,
                      fnd_line,linenum,linechr);
           return;
       }
       case 4: { /* char */
           if(bf[1][0]==0) bf[1][0]=' ';
           if(bf[0][0]==0) return;
           _obj_replace(bf[0],bf[1],bf[2],num,0,p,
                      fnd_char,charnum,charchr);
           return;
       }
       default: break;
    }
    if(internal || strstr(tmp_dir,"sessions")==NULL || (strpbrk(bf[0],"\\[^.*$")==NULL &&
       strpbrk(bf[1],"\\[^.*$")==NULL)) {
       /* No regexp, direct replace */    
       char *pp;
       for(pp=strstr(bf[2],bf[0]);pp<bf[2]+MAX_LINELEN && pp!=NULL;
           pp=strstr(pp+strlen(bf[1]),bf[0])) {
           string_modify(bf[2],pp,pp+strlen(bf[0]),"%s",bf[1]);
       }
       mystrncpy(p,bf[2],MAX_LINELEN);return;
    }
    mkfname(fn[0],"%s/sed.in",tmp_dir);
    mkfname(fn[1],"%s/sed.out",tmp_dir);
    accessfile(bf[2],"w",fn[0]);
    snprintf(bf[3],sizeof(bf[3]),"s%c%s%c%s%cg",
            regexp_char,bf[0],regexp_char,bf[1],regexp_char);
    arglist[0]=sed_prog; arglist[1]=bf[3]; arglist[2]=NULL;
    execredirected(sed_prog,fn[0],fn[1],"/dev/null",arglist);
    read_tmp_file(p,"sed.out");
    strip_trailing_spaces(p);
}

Here is the call graph for this function:

void calc_rownum ( char *  p)

Definition at line 566 of file calc.c.

{
    int i=rownum(p); mystrncpy(p,int2str(i),MAX_LINELEN);
}

Here is the call graph for this function:

void calc_rowof ( char *  p)

Definition at line 674 of file calc.c.

{
    char *cc, tbuf[MAX_LINELEN+1]; /* called by substit(); no right to use tmplbuf */
    mystrncpy(tbuf,p,sizeof(tbuf)); substit(tbuf);
    if(strchr(tbuf,'\n')==NULL && strchr(tbuf,';')!=NULL) cc=";";
    else cc="\n";
    _blockof(p,rownum,fnd_row,cc,"row");
}

Here is the call graph for this function:

Here is the caller graph for this function:

void calc_rows2lines ( char *  p)

Definition at line 2021 of file calc.c.

{      rows2lines(p);       }

Here is the call graph for this function:

void calc_select ( char *  p)

Definition at line 1442 of file calc.c.

{
    char *p1, *p2, *p3, *bufp, c, sep;
    char buf1[MAX_LINELEN+1], buf2[MAX_LINELEN+1];
    char buf[MAX_LINELEN+1];
    int i,j,lmax;
    p2=wordchr(p,"where"); if(p2==NULL) module_error("syntax_error");
    *p2=0; p2+=strlen("where");
    p2=find_word_start(p2); strip_trailing_spaces(p2);
    p1=find_word_start(p) ; strip_trailing_spaces(p1);
    if(*p1==0 || *p2==0) module_error("syntax_error");
    strcpy(buf1,p1); strcpy(buf2,p2); sep='\n';
       /* buf1: data; buf2: condition. */
    substit(buf1); 
    if(strstr(buf2,"column")!=NULL) {     /* matrix */
       lmax=0; if(rows2lines(buf1)) sep=';';
       for(p1=strstr(buf2,"column"); p1; p1=strstr(p1+1,"column")) {
           if(p1>buf2 && isalnum(*(p1-1))) continue;
           p2=find_word_start(p1+strlen("column"));
           for(p3=p2; myisdigit(*p3); p3++);
           if(p3==p2) continue;
           c=*p3; *p3=0; i=atoi(p2); *p3=c;
           if(i<=0 || i>MAX_COLUMNS) continue;
           if(i>lmax) lmax=i;
           string_modify(buf2,p1,p3,"$(wims_select_col_%d)",i);
       }
       buf[0]=0; bufp=buf;
       for(p1=buf1; *p1; p1=p2) {
           char ibuf[MAX_LINELEN+1], nbuf[MAX_NAMELEN+1];
           p2=strchr(p1,'\n');
           if(p2==NULL) p2=p1+strlen(p1); else *p2++=0;
           if(*find_word_start(p1)==0) continue;
           for(j=1;j<=lmax;j++) {
              snprintf(nbuf,sizeof(nbuf),"wims_select_col_%d",j);
              fnd_item(p1,j,ibuf); force_setvar(nbuf,ibuf);
           }
           strcpy(ibuf,buf2); if(compare(ibuf,0,0)) {
              snprintf(bufp,MAX_LINELEN-(bufp-buf),"%s%c",p1,sep);
              bufp+=strlen(bufp);
           }
       }
    }
    else {    /* datafile */
       module_error("syntax_error");
       
    }
    if(buf[0]!=0) buf[strlen(buf)-1]=0;
    mystrncpy(p,buf,MAX_LINELEN);
}

Here is the call graph for this function:

void calc_sh ( char *  p)

Definition at line 336 of file calc.c.

{
    _calc_exec(p,"sh","-c",2);
}

Here is the call graph for this function:

void calc_solve ( char *  p)

Definition at line 1525 of file calc.c.

{
    char *pp, *fp, *forp;
    char buf[MAX_LINELEN+1], vbuf[MAX_LINELEN+1];
    double v, dd, start, stop, step, old, v1, v2, v3, d1, d2, d3;
    int i, pos;
    
    forp=wordchr(p,"for");
    if(forp==NULL) { syntax: module_error("syntax_error"); *p=0; return; }
    *forp=0; forp+=strlen("for");
    fp=find_word_start(p); strip_trailing_spaces(fp);
    if(*fp==0) goto syntax;
    i=cutfor(forp,NULL); if(i<0 || forstruct.type==for_in) goto syntax;
    if(i>0) {*p=0; return;}
    start=forstruct.from; stop=forstruct.to; forp=forstruct.var;
    mystrncpy(buf,fp,sizeof(buf)); substitute(buf);
    *p=0; pp=strchr(buf,'='); if(pp!=NULL) {
       if(strlen(buf)>=MAX_LINELEN-16) return;
       strcat(buf,")");
       string_modify(buf,pp,pp+1,"-(");
    }
    i=0; for(fp=varchr(buf,forp); fp!=NULL; fp=varchr(fp,forp)) {
       string_modify(buf,fp,fp+strlen(forp),EV_X); fp+=strlen(EV_X); i++;
    }
    if(i==0 || start==stop) return;
    evalue_compile(buf); pos=eval_getpos(EV_X);
    if(start>stop) {dd=start; start=stop; stop=dd;}
    step=(stop-start)/100; if(step==0) return;
    pp=p; old=0;
    for(v=start; v<=stop; v+=step, old=dd) {
       eval_setval(pos,v); 
       set_evalue_error(0); set_evalue_pointer(buf); dd=_evalue(10);
       if(v==start) continue;
       if(!finite(old) || !finite(dd) || (old>0 && dd>0) || (old<0 && dd<0))
         continue;
       if(dd==0 && v<stop) continue;
       v1=v-step; v2=v; d1=old; d2=dd;
       for(i=0;i<30;i++) {
           v3=(v1+v2)/2; eval_setval(pos,v3);
           set_evalue_error(0); set_evalue_pointer(buf); d3=_evalue(10);
           if(!finite(d3)) goto next;
           if((d1>0 && d3>0) || (d1<0 && d3<0)) {d1=d3; v1=v3;}
           else {d2=d3; v2=v3;}
       }
       float2str(v3,vbuf); if(pp-p+strlen(vbuf)<MAX_LINELEN-1) {
           if(pp>p) *pp++=','; strcpy(pp,vbuf);
           pp+=strlen(pp);
       }
       else break;
       next: ;
    }
}

Here is the call graph for this function:

void calc_sort ( char *  p)

Definition at line 80 of file calc.c.

{
    char *p1, *p2, buf[MAX_LINELEN+1], *csep[MAX_SORT_ITEM+1];
    char fs=0;
    int (*cutfn)(char *p,char *list[],int max);
    int nocase=0, reverse=0, numeric=0, type;
    int i,j,l,t,total;
    
    cutfn=NULL;
    for(i=0,p1=find_word_start(p);i>=0;p1=find_word_start(p2)) {
       p2=find_word_end(p1); if(*p2!=0) *p2++=0;
       for(i=0;i<sort_keyw_no && strcasecmp(p1,sort_keyw[i].name)!=0;i++);
       if(i>=sort_keyw_no) module_error("syntax_error");
       switch(type=sort_keyw[i].type) {
           case sort_nocase: nocase=1; break;
           case sort_reverse: reverse=1; break;
           case sort_numeric: numeric=1; break;
           case sort_char: i=-1; break;
           case sort_word: cutfn=cutwords; fs=' '; i=-1; break;
           case sort_item: cutfn=cutitems; fs=','; i=-1; break;
           case sort_row:
           case sort_line: cutfn=cutlines; fs='\n'; i=-1; break;
       }
    }
    if(p1[0]=='o' && p1[1]=='f' && myisspace(p1[2])) p1=find_word_start(p1+2);
    mystrncpy(buf,p1,sizeof(buf)); substit(buf); *p=0;
    t=0; if(type==sort_row) t=rows2lines(buf);
    _sort_nocase=nocase; _sort_numeric=numeric;
    if(cutfn) {
       char ordbuf[MAX_LINELEN+1];
       total=cutfn(buf,csep,MAX_SORT_ITEM+1);
       if(total<=0 || total>MAX_SORT_ITEM) return;
       for(i=0;i<total;i++) {
           sort_sep[i].str=csep[i];
           if(numeric) sort_sep[i].val=evalue(csep[i]);
       }
       for(i=0;i<total;i++) sort_sep[i].serial=i+1;
       qsort(sort_sep,total,sizeof(sort_sep[0]),__sorter);
       p1=p;p2=ordbuf;ordbuf[0]=0;
       for(i=0;i<total;i++) {
           if(reverse) j=total-1-i; else j=i;
           l=strlen(sort_sep[j].str);
           if(p1-p+l>=MAX_LINELEN-1) module_error("cmd_output_too_long");
           if(p1>p) *p1++=fs;
           memmove(p1,sort_sep[j].str,l+1); p1+=l;
           if(i>0) *p2++=',';
           mystrncpy(p2,int2str(sort_sep[j].serial),
                    MAX_LINELEN-(p2-ordbuf)-1);
           p2+=strlen(p2);
       }
       force_setvar("wims_sort_order",ordbuf);
    }
    else { /* case of chars */
       qsort(buf,strlen(buf),1,_char_sorter);
       total=strlen(buf);
       if(reverse) {
           for(i=total-1;i>=0;i--) *(p+total-i-1)=buf[i];
           *(p+total)=0;
       }
       else memmove(p,buf,total+1);
    }
    if(t) lines2rows(p);
}

Here is the call graph for this function:

void calc_subst ( char *  p)

Definition at line 388 of file calc.c.

{
}
void calc_sum ( char *  p)

Definition at line 1686 of file calc.c.

{ _values(p,2); }

Here is the call graph for this function:

void calc_tolower ( char *  p)

Definition at line 1015 of file calc.c.

{
    char *pp;
    for(pp=p;*pp;pp++) *pp=tolower(*pp);
}

Here is the caller graph for this function:

void calc_toupper ( char *  p)

Definition at line 1021 of file calc.c.

{
    char *pp;
    for(pp=p;*pp;pp++) *pp=toupper(*pp);
}
void calc_translate ( char *  p)

Definition at line 741 of file calc.c.

{
    int i, internal;
    char *q[3];
    char bf[3][MAX_LINELEN+1];
    char fn[3][MAX_FNAME+1], *arglist[8];

    q[0]=find_word_start(p); internal=0;
    if(strncasecmp(q[0],"internal",strlen("internal"))==0 &&
       isspace(*(q[0]+strlen("internal")))) {
       q[0]=find_word_start(q[0]+strlen("internal"));
       internal=1;
    }
    q[1]=wordchr(q[0],"to"); q[2]=wordchr(q[0],"in");
    if(q[1]==NULL || q[2]==NULL) {
       module_error("tr_syntax"); *p=0; return;
    }
    *q[1]=0; *q[2]=0;
    q[1]=find_word_start(q[1]+strlen("to"));
    q[2]=find_word_start(q[2]+strlen("in"));
    for(i=0;i<3;i++) {
       strip_trailing_spaces(q[i]);
       mystrncpy(bf[i],q[i],sizeof(bf[i]));substit(bf[i]);
    }
    if(bf[0][0]==0) goto bailout;
    if(internal || strstr(tmp_dir,"sessions")==NULL || (strpbrk(bf[0],"\\[-")==NULL && 
       strpbrk(bf[1],"\\[-")==NULL)) {    /* direct internal translation */
       char *pp;
       if(strlen(bf[1])<strlen(bf[0])) bf[0][strlen(bf[1])]=0;
       for(pp=strpbrk(bf[2],bf[0]);pp!=NULL && *pp!=0 && pp<bf[2]+MAX_LINELEN;
           pp=strpbrk(pp+1,bf[0])) {
           for(i=0;bf[0][i]!=*pp && bf[0][i]!=0;i++);
           if(bf[0][i]!=0) *pp=bf[1][i];
       }          
       bailout: mystrncpy(p,bf[2],MAX_LINELEN);
       return;
    }
    mkfname(fn[0],"%s/tr.in",tmp_dir);
    mkfname(fn[1],"%s/tr.out",tmp_dir);
    accessfile(bf[2],"w",fn[0]);
    arglist[0]=tr_prog; arglist[1]=bf[0]; arglist[2]=bf[1];
    arglist[3]=NULL; exportall();
    execredirected(tr_prog,fn[0],fn[1],"/dev/null",arglist);
    read_tmp_file(p,"tr.out");
    strip_trailing_spaces(p);
}

Here is the call graph for this function:

void calc_trim ( char *  p)

Definition at line 1028 of file calc.c.

{
    char *s;
    s=find_word_start(p);
    if(s>p) memmove(p,s,MAX_LINELEN-(s-p)+1);
    strip_trailing_spaces(p);
}

Here is the call graph for this function:

void calc_unhttp ( char *  p)

Definition at line 1873 of file calc.c.

Here is the call graph for this function:

void calc_values ( char *  p)

Definition at line 1682 of file calc.c.

{ _values(p,1); }

Here is the call graph for this function:

void calc_wordnum ( char *  p)

Definition at line 585 of file calc.c.

{
    int i=wordnum(p); mystrncpy(p,int2str(i),MAX_LINELEN);
}

Here is the call graph for this function:

void calc_wordof ( char *  p)

Definition at line 696 of file calc.c.

{
    _blockof(p,wordnum,fnd_word," ","word");
}

Here is the call graph for this function:

void exec_readproc ( char *  p)

Definition at line 350 of file exec.c.

{
    int o=outputing; outputing=0; exec_read(p); outputing=o;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void secure_exec ( void  )

Definition at line 25 of file calc.c.

{
    if((untrust&6)==0) return;
    module_error("Illegal_command");
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 21 of file calc.c.

Definition at line 21 of file calc.c.

char apch_list[] = {',','\n',' '}

Definition at line 710 of file calc.c.

char* append_obj[]
Initial value:
{
    "item","line","word"
}

Definition at line 707 of file calc.c.

Definition at line 2062 of file calc.c.

struct { ... } sort_keyw[]