/* * A new file included. * If ifiles == NULL, this is the first file and already opened (stdin). * Return 0 on success, -1 if file to be included is not found. */ int pushfile(const usch *file, const usch *fn, int idx, void *incs) { extern struct initar *initar; struct includ ibuf; struct includ *ic; int otrulvl; ic = &ibuf; ic->next = ifiles; if (file != NULL) { if ((ic->infil = open((const char *)file, O_RDONLY)) < 0) return -1; ic->orgfn = ic->fname = file; if (++inclevel > MAX_INCLEVEL) error("Limit for nested includes exceeded"); } else { ic->infil = 0; ic->orgfn = ic->fname = (const usch *)"<stdin>"; } ic->buffer = ic->bbuf+NAMEMAX; ic->curptr = ic->buffer; ifiles = ic; ic->lineno = 1; ic->maxread = ic->curptr; ic->idx = idx; ic->incs = incs; ic->fn = fn; prtline(); if (initar) { int oin = ic->infil; ic->infil = -1; *ic->maxread = 0; prinit(initar, ic); if (dMflag) write(ofd, ic->buffer, strlen((char *)ic->buffer)); fastscan(); prtline(); ic->infil = oin; initar = NULL; } otrulvl = trulvl; fastscan(); if (otrulvl != trulvl || flslvl) error("unterminated conditional"); ifiles = ic->next; close(ic->infil); inclevel--; return 0; }
void main (void) { pdata char buff[MAXLINE]; /*Required for Serial Interface*/ SCON = 0x52; /*Serial port configuration*/ TMOD = 0x20; TCON = 0x40; TH1 = 0xf3; /*2403 baudrate @12mhz*/ while(TRUE){ memset(buff, 0, sizeof(buff)); prtline("Enter Line: "); getline(buff); PROMPT; puts(buff); /*Reverse the characters in the line*/ /*Reverse the words in the line*/ rev_word(buff, buff + strlen(buff) - 2); reverse_words(buff); PROMPT; puts(buff); /*Convert the line to its original form*/ rev_word(buff, buff + strlen(buff) - 2); reverse_words(buff); /*Sort the characters in the words in alphabetical order*/ alph_sort_words(buff); PROMPT; puts(buff); } }
static void elifstmt(void) { if (flslvl == 0) elflvl = trulvl; if (flslvl) { if (elflvl > trulvl) ; else if (--flslvl!=0) ++flslvl; else { if (yyparse()) { ++trulvl; prtline(); } else { putch('\n'); ++flslvl; } } } else if (trulvl) { ++flslvl; --trulvl; } else error("If-less elif"); }
static void pragmastmt(void) { int ch; putstr((const usch *)"\n#pragma"); while ((ch = qcchar()) != '\n' && ch > 0) putch(ch); unch(ch); prtline(1); }
static void pragmastmt(void) { usch *sb; if (flslvl) return; if (sloscan() != WSPACE) error("bad #pragma"); sb = stringbuf; savstr((const usch *)"\n#pragma "); savln(); putstr(sb); prtline(); stringbuf = sb; }
static void endifstmt(void) { if (flslvl) { flslvl--; if (flslvl == 0) { putch('\n'); prtline(); } } else if (trulvl) trulvl--; else error("If-less endif"); if (flslvl == 0) elflvl = 0; elslvl = 0; chknl(1); }
static void pragmastmt(void) { int c; if (sloscan() != WSPACE) error("bad pragma"); if (!flslvl) putstr((const usch *)"#pragma "); do { c = inch(); if (!flslvl) putch(c); /* Do arg expansion instead? */ } while (c && c != '\n'); if (c == '\n') unch(c); prtline(); }
static void elsestmt(void) { if (flslvl) { if (elflvl > trulvl) ; else if (--flslvl!=0) { flslvl++; } else { trulvl++; prtline(); } } else if (trulvl) { flslvl++; trulvl--; } else error("If-less else"); if (elslvl==trulvl+flslvl) error("Too many else"); elslvl=trulvl+flslvl; chknl(1); }
/* * A new file included. * If ifiles == NULL, this is the first file and already opened (stdin). * Return 0 on success, -1 if file to be included is not found. */ int pushfile(const usch *file, const usch *fn, int idx, void *incs) { struct includ ibuf; struct includ *ic; int otrulvl; ic = &ibuf; ic->next = ifiles; if (file != NULL) { if ((ic->infil = open((const char *)file, O_RDONLY)) < 0) return -1; ic->orgfn = ic->fname = file; if (++inclevel > MAX_INCLEVEL) error("limit for nested includes exceeded"); } else { ic->infil = 0; ic->orgfn = ic->fname = (const usch *)"<stdin>"; } #if LIBVMF if (ifiles) { vmmodify(ifiles->vseg); vmunlock(ifiles->vseg); } ic->vseg = vmmapseg(&ibspc, inclevel); vmlock(ic->vseg); #endif ifiles = ic; ic->ib = getobuf(BINBUF); ic->lineno = 1; ic->escln = 0; ic->maxread = ic->curptr; ic->idx = idx; ic->incs = incs; ic->fn = fn; prtline(1); otrulvl = trulvl; fastscan(); if (otrulvl != trulvl || flslvl) error("unterminated conditional"); ifiles = ic->next; inclevel--; #if LIBVMF vmmodify(ic->vseg); vmunlock(ic->vseg); ic->ib->ro = 1; /* XXX no free */ if (ifiles) { ifiles->vseg = vmmapseg(&ibspc, inclevel); vmlock(ifiles->vseg); ifiles->ib->buf = (usch *)ifiles->vseg->s_cinfo; } #endif close(ic->infil); bufree(ic->ib); return 0; }