Beispiel #1
0
/*
**TXTentryParse(name,filenam,&X,&Y,&Repeat,TXT,TRUE)
*/
Bool TXTentryParse(char *name,char *filenam,Int16 *x,Int16 *y,Bool
    *repeat, struct TXTFILE *TXT, Bool XY)
{ Int16 c=0,val=0; Bool comment;
  Int16 xx=INVALIDINT,yy=INVALIDINT;
  if(TXTreadIdent(TXT,name)!=TRUE) return FALSE;
  /* skip the equal*/
  if(TXTgetc(TXT,&c,&val)!=TRUE) return FALSE;
  if(c!='=') TXTungetc(TXT);
  /* read integer*/
  if(XY==TRUE)
  { xx=TXTreadOptionalShort(TXT);
    yy=TXTreadOptionalShort(TXT);
  }
  Normalise(filenam,name);
  TXTreadOptionalName(TXT,filenam);
  if(XY==TRUE)
  { if(xx==INVALIDINT) xx=TXTreadOptionalShort(TXT);
    if(yy==INVALIDINT) yy=TXTreadOptionalShort(TXT);
  }
  *repeat= TXTreadOptionalRepeat(TXT);
  *x=xx;
  *y=yy;
  for(comment=FALSE;;)
  { if(TXTgetc(TXT,&c,&val)!=TRUE)break;
    if(val & NEWLINE) break;
    if(val & COMMENT)        /*eat commentaries*/
       { comment=TRUE;  continue;}
    if(val & SPACE)          /*eat space*/
       { continue;}
    if(comment==FALSE)
       ProgError("TR87", "%s(%ld): bad entry format",
	   fname (TXT->pathname), (long) TXT->Lines);
  }
  return TRUE;
}
Beispiel #2
0
/*read string, skip space before, stop space/\n*/
static bool TXTread(struct TXTFILE *TXT, char name[8], int16_t valid)
{
    int16_t c = 0, val = 0, n = 0;
    while (1) {
        if (!TXTgetc(TXT, &c, &val))
            return false;
        if (val & NEWLINE)
            continue;
        if (val & SPACE)
            continue;
        if (val & valid)
            break;
        ProgError("TR11", "%s(%ld): illegal char %s", TXT->pathname,
                  (long) TXT->Lines, quotechar(c));
    }
    name[0] = (char) c;
    for (n = 1; n < 256; n++) {
        if (!TXTgetc(TXT, &c, &val))
            break;
        if (val & SPACE) {
            TXTungetc(TXT);
            break;
        }
        if (!(val & valid))
            ProgError("TR13", "%s(%ld): illegal char %s in word",
                      TXT->pathname, (long) TXT->Lines, quotechar(c));
        if (n < 8)
            name[n] = (char) c;
    }
    if (n < 8)
        name[n] = '\0';
    return true;
}
Beispiel #3
0
/* read Blocks of the form
** [BLOCKID]
** identifier   ... anything ...
** identifier   ... anything ...
*/
static Bool TXTfindSection(struct TXTFILE *TXT,Bool Match)
{ Int16 c=0,val=0,n;
  char buffer[8];
  while(1)
  { if(TXTskipComment(TXT)!=TRUE) return FALSE;
    if(TXTgetc(TXT,&c,&val)!=TRUE)return FALSE;
    if(c=='[')
    { for(n=0;n<256;n++)
      { if(TXTgetc(TXT,&c,&val)!=TRUE) return FALSE;
	if(c==']')
	{ if(n<8)buffer[n]='\0';
	  if(Match==FALSE) return TRUE;/*any section is ok*/
	  Normalise(buffer,buffer);        /*the right section?*/
	  if(strncmp(buffer,TXT->Section,8)==0) return TRUE;
	  break; 			   /*not the right section*/
	}
	if(!(val & (NAME|NUMBER))) break;  /*not a section*/
	if(n<8) buffer[n]=c;
      }
    }
    while(1) /*look for end of line*/
    { if(TXTgetc(TXT,&c,&val)!=TRUE)return FALSE;
      if(val & NEWLINE) break;
    }
  }
}
Beispiel #4
0
/*
** Read integer if exist before NEWLINE,
** but don't eat NEWLINE
*/
static Int16 TXTreadOptionalShort(struct TXTFILE *TXT)
{ static char name[9];
  Int16 n,c=0,val=0;
  while(1)
  { if(TXTgetc(TXT,&c,&val)!=TRUE)return INVALIDINT;
    if(!(val & NEWLINE))
    { if(val & SPACE)   continue; /*skip space*/
      if(val & STEQUAL) continue; /*skip '='*/
      if(val & NUMBER)  break;    /*look for number*/
    }
    TXTungetc(TXT);
    return INVALIDINT;               /*not a number. abort*/
   }
   name[0]=(char)c;
   for(n=1; n<256; n++ )
   { if(TXTgetc(TXT,&c,&val)!=TRUE) break;
     if(val&NEWLINE) {TXTungetc(TXT);break;}
     if(val&SPACE)break;
     if(!(val&NUMBER))
	ProgError("TR42", "%s(%ld): illegal char %s in number",
	    fname (TXT->pathname), (long) TXT->Lines, quotechar (c));
     if(n<8) name[n]=(char)c;
   }
   if(n<8)name[n]='\0';
   name[8]='\0';
   return (Int16)atoi(name);
}
Beispiel #5
0
bool TXTentryParse(char *name, char *filenam, int16_t * x, int16_t * y,
                   bool * repeat, struct TXTFILE * TXT, bool XY)
{
    int16_t c = 0, val = 0;
    bool comment;
    int16_t xx = INVALIDINT, yy = INVALIDINT;
    if (!TXTreadIdent(TXT, name))
        return false;
    /* skip the equal */
    if (!TXTgetc(TXT, &c, &val))
        return false;
    if (c != '=')
        TXTungetc(TXT);
    /* read integer */
    if (XY) {
        xx = TXTreadOptionalShort(TXT);
        yy = TXTreadOptionalShort(TXT);
    }
    Normalise(filenam, name);
    TXTreadOptionalName(TXT, filenam);
    if (XY) {
        if (xx == INVALIDINT)
            xx = TXTreadOptionalShort(TXT);
        if (yy == INVALIDINT)
            yy = TXTreadOptionalShort(TXT);
    }
    *repeat = TXTreadOptionalRepeat(TXT);
    *x = xx;
    *y = yy;
    for (comment = false;;) {
        if (!TXTgetc(TXT, &c, &val))
            break;
        if (val & NEWLINE)
            break;
        if (val & COMMENT) {    /*eat commentaries */
            comment = true;
            continue;
        }
        if (val & SPACE) {      /*eat space */
            continue;
        }
        if (!comment)
            ProgError("TR87", "%s(%ld): bad entry format",
                      fname(TXT->pathname), (long) TXT->Lines);
    }
    return true;
}
Beispiel #6
0
/* find '*' */
static bool TXTcheckStartPatch(struct TXTFILE *TXT)
{
    int16_t c = 0, val = 0;
    if (!TXTgetc(TXT, &c, &val))
        return false;
    if (val & STPATCH)
        return true;
    TXTungetc(TXT);
    return false;
}
Beispiel #7
0
/*
** STPATCH is also used to indicate repetition
*/
static Bool TXTreadOptionalRepeat(struct TXTFILE *TXT)
{ Int16 c=0,val=0;
  while(1)
  {  if(TXTgetc(TXT,&c,&val)!=TRUE) return FALSE;
     if(!(val & NEWLINE))
     { if(val & STPATCH) break;  /*look for STPATCH*/
       if(val & SPACE) continue; /*skip space*/
     }
     TXTungetc(TXT);
     return FALSE;
  }
  return TRUE;               /*found*/
}
Beispiel #8
0
/*skip lines beginning with # or ; */
Bool TXTskipComment(struct TXTFILE *TXT)
{ Int16 c=0,val=0; Bool comment;
  for(comment=FALSE;;)
  { if(TXTgetc(TXT,&c,&val)!=TRUE)return FALSE;
    if(val & NEWLINE)        /*eat newlines*/
       { comment=FALSE; continue;}
    if(val & COMMENT)        /*eat commentaries*/
       { comment=TRUE;  continue;}   
    if(val & SPACE)          /*eat space*/
       { continue;}
    if(comment==FALSE)
       { TXTungetc(TXT);return TRUE;}
  }
}
Beispiel #9
0
/* read Blocks of the form
** [BLOCKID]
** identifier   ... anything ...
** identifier   ... anything ...
*/
static bool TXTfindSection(struct TXTFILE *TXT, bool Match)
{
    int16_t c = 0, val = 0, n;
    char buffer[8];
    while (1) {
        if (!TXTskipComment(TXT))
            return false;
        if (!TXTgetc(TXT, &c, &val))
            return false;
        if (c == '[') {
            for (n = 0; n < 256; n++) {
                if (!TXTgetc(TXT, &c, &val))
                    return false;
                if (c == ']') {
                    if (n < 8)
                        buffer[n] = '\0';
                    if (!Match)
                        return true;    /*any section is ok */
                    Normalise(buffer, buffer);  /*the right section? */
                    if (strncmp(buffer, TXT->Section, 8) == 0)
                        return true;
                    break;      /*not the right section */
                }
                if (!(val & (NAME | NUMBER)))
                    break;      /*not a section */
                if (n < 8)
                    buffer[n] = c;
            }
        }
        while (1) {             /*look for end of line */
            if (!TXTgetc(TXT, &c, &val))
                return false;
            if (val & NEWLINE)
                break;
        }
    }
}
Beispiel #10
0
/*
** STPATCH is also used to indicate repetition
*/
static bool TXTreadOptionalRepeat(struct TXTFILE *TXT)
{
    int16_t c = 0, val = 0;
    while (1) {
        if (!TXTgetc(TXT, &c, &val))
            return false;
        if (!(val & NEWLINE)) {
            if (val & STPATCH)
                break;          /*look for STPATCH */
            if (val & SPACE)
                continue;       /*skip space */
        }
        TXTungetc(TXT);
        return false;
    }
    return true;                /*found */
}
Beispiel #11
0
/*
** find the section boundaries, from current position in file
*/
static Bool TXTboundSection(struct TXTFILE *TXT)
{ Int16 c=0,val=0;
  if(TXTfindSection(TXT,TRUE)!=TRUE) return FALSE;
  TXT->SectionStart=TXT->Lines+1;
  /*check that we don't read twice the same section*/
  if(TXT->SectionEnd>TXT->SectionStart) Bug("TR51", "TxtBdS");
  if(TXTfindSection(TXT,FALSE)==TRUE)
    TXT->SectionEnd=TXT->Lines-1;
  else
    TXT->SectionEnd=TXT->Lines;
  /* set pointer to first section line*/
  fseek(TXT->fp,0,SEEK_SET);
  TXT->Lines	   =1;/*start in line 1*/
  while(TXT->Lines<TXT->SectionStart)
  { if(TXTgetc(TXT,&c,&val)!=TRUE)return FALSE;
  }
  return TRUE;
}
Beispiel #12
0
/*
** STEQUAL is used to indicate alternate name
*/
static void TXTreadOptionalName(struct TXTFILE *TXT,char name[8])
{ Int16 c=0,val=0;
  while(1)
  {  if(TXTgetc(TXT,&c,&val)!=TRUE) return;
     if(!(val & NEWLINE))
     { if(val & STEQUAL) continue; /*skip '='*/
       if(val & SPACE) continue; /*skip space*/
       if(val & (NAME&(~NUMBER))) break;
     }
     TXTungetc(TXT);
     return; /*name is NOT modified*/
  }
  TXTungetc(TXT);
  if(TXTread(TXT,name,NAME|NUMBER)!=TRUE)
  { ProgError("TR32", "%s(%ld): invalid optional name",
      TXT->pathname, (long) TXT->Lines);
  }
}
Beispiel #13
0
/*
** find the section boundaries, from current position in file
*/
static bool TXTboundSection(struct TXTFILE *TXT)
{
    int16_t c = 0, val = 0;
    if (!TXTfindSection(TXT, true))
        return false;
    TXT->SectionStart = TXT->Lines + 1;
    /*check that we don't read twice the same section */
    if (TXT->SectionEnd > TXT->SectionStart)
        Bug("TR51", "TxtBdS");
    if (TXTfindSection(TXT, false))
        TXT->SectionEnd = TXT->Lines - 1;
    else
        TXT->SectionEnd = TXT->Lines;
    /* set pointer to first section line */
    fseek(TXT->fp, 0, SEEK_SET);
    TXT->Lines = 1;             /*start in line 1 */
    while (TXT->Lines < TXT->SectionStart) {
        if (!TXTgetc(TXT, &c, &val))
            return false;
    }
    return true;
}
Beispiel #14
0
/*skip lines beginning with # or ; */
bool TXTskipComment(struct TXTFILE *TXT)
{
    int16_t c = 0, val = 0;
    bool comment;
    for (comment = false;;) {
        if (!TXTgetc(TXT, &c, &val))
            return false;
        if (val & NEWLINE) {    /*eat newlines */
            comment = false;
            continue;
        }
        if (val & COMMENT) {    /*eat commentaries */
            comment = true;
            continue;
        }
        if (val & SPACE) {      /*eat space */
            continue;
        }
        if (!comment) {
            TXTungetc(TXT);
            return true;
        }
    }
}
Beispiel #15
0
/* find '*' */
static Bool TXTcheckStartPatch(struct TXTFILE *TXT)
{ Int16 c=0, val=0;
  if(TXTgetc(TXT,&c,&val)!=TRUE) return FALSE;
  if(val & STPATCH) return TRUE;
  TXTungetc(TXT); return FALSE;
}