#include #include #include double atof(); /* #define DEBUG */ #define TOKEN 40 #define NVAR 250 #define COMMENTSIZE 2430 #define SEPARATOR " ,\n" char names[NVAR][TOKEN]; char values[NVAR][TOKEN]; char attr[NVAR][TOKEN]; char comments[COMMENTSIZE]; char tmp[1025]; char filename[256]; int nvarlevel[6]; int fresh[5]={1,1,1,1,1}; FILE *fl; int maxlev,newlev; int eofflag=0; int ateq=0; err(s,t) char *s,*t; { printf("&x error - %s%s",s,t); ioclose_(); exit(1); } htmlunescape(str) char *str; { char *i,*o; i=str; o=str; while(*i){ if(*i == '<'){ while(*i && *i != '>')i++; if(*i) i++; }; if(*i == '&'){ switch(*(i+1)){ case 'l':*o = '<'; i += 3; break; case 'g':*o = '>'; i += 3; break; case 'a':*o = '&'; i += 4; break; }; } else *o = *i; i++; o++; }; *o = 0; } readheader() { char *sp,*sp2; int ncnt,i; maxlev= -1; newlev=0; nvarlevel[0]=0; ncnt=0; strcpy(tmp,"#"); while(tmp[0] != '='){ if(fgets(tmp,1024,fl) == NULL)err("file structure",""); htmlunescape(tmp); if(tmp[0]=='#')strcat(comments,tmp+1); }; while(1) { maxlev++; if(fgets(tmp,1024,fl) == NULL)err("file structure",""); htmlunescape(tmp); sp=strtok(tmp," \t\r\n"); for(i=0;i=0;i--)if (*vn >= nvarlevel[i]) return i; return 0; } ioattrout_(vn,str) int *vn; char *str; { char *at; int j; j= *vn; if (attr[j][0]){ at=strchr(attr[j],';'); if(at){ *at = '\0'; strcpy(str,attr[j]); strcpy(attr[j],at+1); } else { strcpy(str,attr[j]); attr[j][0]='\0'; }; return 1; } else return 0; } int iocommout_(str) char *str; { char *at; if (comments[0]){ at=strchr(comments,'\n'); if(at){ *at = '\0'; strcpy(str,comments); strcpy(comments,at+1); } else { strcpy(str,comments); comments[0]='\0'; }; return 1; } else return 0; } iovalreal_(vn,f) int *vn; float *f; { int i; i= *vn; if(i<0){*f= -9999.0;return;}; if(strspn(values[i],"0123456789.+-")) *f=atof(values[i]); else *f= -9999.0; #ifdef DEBUG printf("iovalreal %d %f\n",*vn,f); #endif } iovalstr_(vn,tmp) int *vn; char *tmp; { static char *s; int i; i= *vn; if(i<0){strcpy(tmp,"nd");return;}; s=values[i]; s=s+strspn(s," "); strcpy(tmp,s); #ifdef DEBUG printf("iovalstr %d %s\n",*vn,tmp); #endif } readnewheader() { } int ioreadrec_(level) int *level; { int i,lev,nl; char *sp; if(eofflag)return 0; lev=*level; if(fresh[lev]){ fresh[lev]=0; return 1; }; if(feof(fl)){eofflag=1;return 0;}; if(*tmp == 0) if(fgets(tmp,1024,fl) == NULL){ eofflag=1; return 0;}; htmlunescape(tmp); if(tmp[0]=='='){ nl=0; while(nl