static NormPtr templatedef (NormPtr i) { NormPtr pstart = i; Token tname = CODE [i++]; Token targ [32]; int argc = 0, j, blockno; if (!ISSYMBOL (tname)) parse_error (i, "template name missing"); if (tpls [tname - IDENTBASE]) parse_error (i, "template redefined"); if (CODE [i++] != '(') parse_error (i, "template name '('"); for (;;i++) { targ [argc] = CODE [i++]; if (!ISSYMBOL (targ [argc])) parse_error (i, "template argument name"); argc++; if (CODE [i] == ',') continue; break; } if (CODE [i++] != ')' || argc == 0) parse_error (i, "bad argument list for template"); OCD = (Token*) malloc ((nocd = 512) * sizeof (Token)); ncdpt = 0; if (CODE [i++] != '{') parse_error (i, "template '{'"); for (blockno = 1; CODE [i] != -1; i++) if (ISSYMBOL (CODE [i])) { for (j = 0; j < argc; j++) if (CODE [i] == targ [j]) break; if (j < argc) { output_templtok (ARGBASE + j); continue; } output_templtok (CODE [i]); } else if (CODE [i] == '{') { output_templtok ('{'); ++blockno; } else if (CODE [i] == '}') { if (--blockno == 0) break; output_templtok ('}'); } else output_templtok (CODE [i]); if (CODE [i] == -1) parse_error (i, "unclosed template definition"); Template *t = tpls [tname - IDENTBASE] = (Template*) malloc (sizeof (Template)); t->BODY = (Token*) realloc (OCD, ncdpt * sizeof (Token)); t->len = ncdpt; t->argc = argc; adjust_lines (pstart, pstart - i); return i; }
void pastein(void) { static unsigned page,offset,loc,recnum; static unsigned i; static unsigned paste_len,pos; static byte c; page=offset=0; while(loc=ozfindnext(TYPE_SYSTEM,&page,&offset,&recnum)) { if('\xF'!=(c=ozloadcluster(loc)[15]) && '!'!=c) continue; /* '!' is on 700M model */ ozopenfile(loc); for(i=0;i<15;i++) ozreadfilebyte(); paste_len=ozreadfilebyte(); paste_len+=256*ozreadfilebyte(); if(paste_len<=6) { ozclosefile(); return; } paste_len-=6; if(paste_len+file_length>MAX_FILE_LENGTH) paste_len=MAX_FILE_LENGTH-file_length; ozreadfilebyte(); ozreadfilebyte(); /* refresh_off(); */ save_lines(2); insert(cur_offset,paste_len); file_length+=paste_len; wrapped_length+=paste_len; pos=cur_offset; cur_offset+=paste_len; for(i=0;i<paste_len;i++,pos++) { int c=ozreadfilebyte(); if(-1==c) { ozclosefile(); return; } else if(c==0) ozwriteauxbyte(pos,' '); /* insert_char(' '); */ else if(c=='\x0D') ozwriteauxbyte(pos,13); /* insert_char(13); */ else if(c<32 || c>126) ozwriteauxbyte(pos,'*'); /* insert_char('.'); */ else ozwriteauxbyte(pos,c); /* insert_char(c); */ } ozclosefile(); adjust_lines(paste_len,1); /* refresh_on(); */ return; } }