Metropoli BBS
VIEWER: readln.h MODE: TEXT (ASCII)
// used by PASM and iASM

void readln(void) {
  byte a=0;
  word p=0;
  word t;
  byte f1,f2;

  #ifdef DEBUG3
    printf("(readon)");
  #endif
  while (a!=10) {
    if (!bufis[ch]) {
      t=read(h,bufin[ch],bufsiz);
      bufis[ch]=t;
      if (!t) {
        EOFF[ch]=1;
        buf[p]=0;
  #ifdef DEBUG3
    printf("(readoff)");
  #endif
        return;
      }
      bufip[ch]=0;
    }
    a=*(bufin[ch]+(bufip[ch]++));
    bufis[ch]--;
    buf[p++]=a;
    if (p>200) error("Line too long (200)");
    if (a==13) buf[p-1]=0;
  }
  buf[p]=0;
  //convert 9 to 32
  f1=0;  //inside ''
  f2=0;  //inside ""
  p=0;
  while (buf[p]) {
    a=buf[p];
#ifdef IASM
    if (f1) {
      if ( a=='\'' ) {
        if ( buf[p+1] =='\'') {p+=2;continue;}
        f1=0;p++;continue;
      }
    }
#endif
    if (f2) {
      if ( a=='\"' ) {
        if ( buf[p+1] =='\"') {p+=2;continue;}
        f2=0;p++;continue;
      }
    }
    if (a==9) if ((!f1)&&(!f2)) {buf[p++]=32;continue;}  //convert 9 to 32
    if ((f1) || (f2)) {p++;continue;}
#ifdef IASM
    if ( a=='\'' ) f1=1;
#endif
    if ( a=='\"' ) f2=1;
    p++;
  }
  bufln[ch]++;
  #ifdef DEBUG3
    printf("(readoff)");
  #endif
}
[ RETURN TO DIRECTORY ]