/* outerqn2.c * Copyright (c) MIT/JGOFS * From outerqn, renamed to outergn2. Modified 8/8/95 WHOI/GLOBEC Georges Bank. (rcg) Increase token size from 880 to 160 This is a version of outer which allows - quoted strings "This is a string" - will not generate an anchor for these in html mode. - does not generate links to flat listings or other options grf 02/16/95 */ #include #include #include #include "../libsrc/htmlescape.c" double atof(); double strtod(); #define TOKEN 160 #define NPREFIX 2 #define NINFIX 6 #define NTEST 12 #define NCOMPS 10 int ntotal; int numsel; int maxlevel; int reqlevel; int cl; int minlevel; int htmlflag=0; int flatflag=0; int *level=NULL; static int anchor; static char *outnames=NULL; static char objsav[1024],parsav[1024]; char *getenv(); /* =========================================== Subroutines required: =========================================== */ int ioopen_(); /* int ioopen_(s,nparams,ntotal) char s[][80]; int *nparams,*ntotal; s[0..nparams-1]: parameter strings. Inner sets s[j][0]=0 for any strings which it processes; others will be processed by outer. Thus selection/projections would normally be ignored by inner. nparams: number of parameter strings ntotal (returned): total number of variable names */ int ioreadrec_(); /* int ioreadrec_(level) int *level; Read record at appropriate level. Return 0 if end at that level. Return 1 if ok. */ ioclose_(); /* ioclose_() Close files */ iovalreal_(); /* iovalreal_(vn,f) int *vn; float *f; Return real value (f) for variable indexed by vn. -9999 for strings */ iovalstr_(); /* iovalstr_(vn,tmp) int *vn; char *tmp; Return string value (tmp) for variable indexed by vn. */ int iovarlevel_(); /* int iovarlevel_(vn) int *vn; Return level corresponding to variable indexed by vn. */ int ioattrout_(); /* ioattrout_(vn, str) int *vn; char *str; Output next attribute for variable indexed by vn. 0=none left. */ ioname_(); /* ioname_(vn,s) int *vn; char *s; Return name (s) corresponding to variable number vn. */ int iocommout_(); /* int iocommout_(s) char *s; Return next comment string. 0=none left. */ quit(s1,s2) char *s1,*s2; { printf("&x %s %s\n",s1,s2); if(htmlflag)printf("\n"); if(level)free(level); if(outnames)free(outnames); ioclose_(); exit(1); } /* P-code form: 128..255 exec test(n-128) [negative #'s on Sun] 1=or,2=and,3=not 0: end */ static char *prefix[]={"!","not"}; static char *infix[]={"||","or","|","&&","and","&"}; static char *testop[]={"<","","=","==",">","","<=","","<>","!=",">=",""}; static struct { int testlev; int testvar; int testcode; float testval; char teststr[TOKEN]; int testres; } tst[NCOMPS]; static int tstcnt=0; static int tstproc[NCOMPS]; static int tstproccnt=0; parse(s) char *s; { int opstkp; float f; int opstack[20]; int opprior[20]; char *t,*t1,tok[TOKEN],tmp[TOKEN]; int i,state,typ,finaland; opstkp= 0; opstack[0]=0; opprior[0]= -1; state=0; if (tstproccnt==0) finaland=0; else finaland=1; strcat(s,"$"); t=s; while(t != NULL){ if(isalpha(*t) || *t=='#'){ i=strcspn(t," ()$=<>|&!"); strncpy(tok,t,i); tok[i]='\0'; t += i; typ=0; } else if(isdigit(*t) || *t=='.' || *t=='+' || *t=='-'){ f=strtod(t,&t1); typ=1; t=t1; } else if(*t == '('){ typ=2; t++; } else if(*t == ')'){ typ=3; t++; } else if(*t == '$'){ typ=4; t=NULL; } else { tok[0]= *t; if((int)strspn(t+1,"&|=>")>0){ tok[1]= *(++t); tok[2]='\0'; } else tok[1]='\0'; t++; typ=5; }; switch(state*10+typ){ case 0: /* variable,not */ for(i=0;i=128) printf("%d %d %f %s\n",tst[tstproc[i]-128].testvar, tst[tstproc[i]-128].testcode,tst[tstproc[i]-128].testval, tst[tstproc[i]-128].teststr); else printf("\n"); }; #endif return; default: quit("Parsing error",""); }; if(*t==' ')t++; }; } int test(cl) int cl; { float f; char tmp[TOKEN]; int i,j,m; int stk[NCOMPS],stkp; #ifdef DEBUG printf("entered test at level %d\n",cl); #endif stkp = -1; stk[0]=1; for(i=0;i= 128){ j=tstproc[i]-128; if(tst[j].testlev < cl)stk[++stkp]=tst[j].testres; else if(tst[j].testlev>cl)stk[++stkp]=1; else { m=0; if(tst[j].testcode<0){ iovalstr_(&(tst[j].testvar),tmp); switch (tst[j].testcode){ case -2:if(strcmp(tmp,tst[j].teststr)==0)m=1;break; case -5:if(strcmp(tmp,tst[j].teststr)!=0)m=1;break; }; } else { iovalreal_(&(tst[j].testvar),&f); #ifdef DEBUG printf("-- %f %d %f -- ",f,tst[j].testcode,tst[j].testval); #endif switch (tst[j].testcode){ case 1:if(ftst[j].testval)m=1;break; case 4:if(f<=tst[j].testval)m=1;break; case 5:if(f!=tst[j].testval)m=1;break; case 6:if(f>=tst[j].testval)m=1;break; }; }; tst[j].testres=m; stk[++stkp]=m; }; } else { switch(tstproc[i]){ case 1: stk[stkp-1]=stk[stkp-1] || stk[stkp];stkp--;break; case 2: stk[stkp-1]=stk[stkp-1] && stk[stkp];stkp--;break; case 3: stk[stkp]=1-stk[stkp]; }; }; }; #ifdef DEBUG printf("test result = %d\n",stk[0]); #endif return stk[0]; } outvar() { int i,j; char tmp[80],attr[1024]; printf("Content-type: text/plain\n\n"); i=1; while(iocommout_(tmp)){ if(i){printf("&c***********************\n");i=0;}; printf("%s\n",tmp); }; for(i=0;i<=maxlevel;i++){ printf("&v%d======================\n",i); for(j=0;j=0){ strcpy(attr,"["); while(ioattrout_(&j,tmp)){strcat(attr,tmp);strcat(attr,";");}; if(strcmp(attr,"[")) attr[strlen(attr)-1]=']'; else attr[0]=0; strcpy(tmp,outnames+j*TOKEN); strcat(tmp,attr); printf("%s\t",tmp); }; printf("\n"); } outputflat(firsttime) int firsttime; { int j; char tmp[80]; for(j=0;j=0){ iovalstr_(&j,tmp); printf("%s\t",tmp); }; printf("\n"); minlevel=maxlevel; } outvarhtml() { char tmp[80],*sp; printf("Content-type: text/html\n\n"); htmlescape(parsav); printf("%s -- Level %d\n",objsav,reqlevel); printf("

%s --%s-- Level %d

\n",objsav,parsav,reqlevel); /* printf("List all at next level | ", objsav,reqlevel+1,parsav); printf("Flat listing | ", objsav,reqlevel,parsav); printf("Other options

\n", OPTIONHOST,MYADDR,objsav,reqlevel,parsav); */ printf("

\n");
  if (*parsav) strcat(parsav,",");
  while(iocommout_(tmp)) {
    htmlescape(tmp);
    printf("# %s\n",tmp);
  };
}

outputhtml(firsttime)
int firsttime;
{
  int i,j;
  char tmp[80];
  if(minlevel%s\t",
            objsav,reqlevel+1,parsav,outnames+j*TOKEN,tmp,tmp);
	else printf("%s\t",tmp);
      };
      printf("\n");
    };
    minlevel=maxlevel;
  } else {
    for(j=0;j%s\t",
	       objsav,reqlevel+1,parsav,outnames+j*TOKEN,tmp,tmp);
      else printf("%s\t",tmp);
    };
    printf("\n");
  };
}

main(argc,argv)
int argc;
char *argv[];
{
  int i,j,k,nparams,noprojflag;
  char tmp[80],stmp[80],*pp,*sp;

  reqlevel=999;
  pp=getenv("PATH_INFO");
  if(pp) {
    if(sp=strstr(pp,".html")) htmlflag=1;
    else if(sp=strstr(pp,".flat")) flatflag=1;
    if(htmlflag || flatflag) {
      reqlevel=atoi(sp+5);
      *sp=0;
      strcpy(objsav,pp);
      pp=getenv("QUERY_STRING");
      if(pp) strcpy(parsav,pp); else *parsav=0;
    };
  };
  level=NULL;
/*
  system("printenv > /d3/glenn/jg/temp");
*/


  nparams=argc-1;
  k=ioopen_(argv+1,&nparams,&ntotal);
  if(k>reqlevel) anchor=1; else anchor=0;
  noprojflag=1;numsel= -1;
  outnames=(char *)malloc(TOKEN*ntotal);
  for(j=0;j=")) parse(stmp);
      else {
	for(k=0;k= -reqlevel-1) 
	  *(level+k)= - *(level+k)-1;
	noprojflag=0;
      };
    };
  };

  if(noprojflag)for(i=0;i= -reqlevel-1) *(level+i)= - *(level+i)-1;

  maxlevel=0;
  for(j=0;jmaxlevel)maxlevel= *(level+j);
/*
  for(j=0;j= 128)
      if(tst[j].testlev > maxlevel) maxlevel=tst[j].testlev;
*/
  if(reqlevel>maxlevel) reqlevel=maxlevel;

#ifdef DEBUG
  printf("maxlevel %d\n",maxlevel);
#endif

  minlevel=maxlevel;
  cl=0;
  k=1;
  if(htmlflag) outvarhtml();
  else if (flatflag) outvarflat();
  else outvar();

  while(1){
    if(ioreadrec_(&cl)){
#ifdef DEBUG
      printf("succ. read at lev %d\n",cl);
#endif
      if(test(cl))
	if(cl\n"); 
  else if(!flatflag)printf("&e**** End of object ****\n");
}