uint8_t * sindnt() { int j; /* Scratch */ long i4, k4; /* Scratch */ /* * In fact look back for a non-blank line */ i4 = ptrpos; /* Remember pos'n on entry */ k4 = 1; /* # of lines we are going back */ if (modify) k4 = 2; /* To skip over line being modified */ lstvld = true; /* Will be true after we finish */ do { if (i4 == k4) { /* At start of file */ ndntch = 0; /* No indent if at s.o.f. */ prev->bchars = 0; /* No data in 0th line */ prev->bcurs = 0; /* Cursor at line strt */ *prev->bdata = 0; /* Null-terminate bdata */ return prev->bdata; } /* if (i4 != k4) */ setaux(i4 - k4); rdlin(prev, true); k4 = k4 + 1; /* In case line empty */ } while (prev->bchars == 0); if (INDENT) { /* * Set the INDENT - code copied from SCRDIT with CURR -> PREV */ j = prev->bchars; /* Finish when find non-space */ for (ndntch = 0; ndntch < j; ndntch++) if (!isspace(prev->bdata[ndntch])) break; } /* if (INDENT) */ return prev->bdata; }
void sindnt() { int j; /* Scratch */ long i4, k4; /* Scratch */ /* * In fact look back for a non-blank line */ i4 = ptrpos; /* Remember pos'n on entry */ k4 = 1; /* # of lines we are going back */ if (modify) k4 = 2; /* To skip over line being modified */ lstvld = true; /* Will be true after we finish */ p1002: if (i4 != k4) goto p1001; /* J not at s.o.f. */ ndntch = 0; /* No indent if at s.o.f. */ prev->bchars = 0; /* No data in 0th line */ prev->bcurs = 0; /* Cursor at line strt */ return; p1001:setaux(i4 - k4); (void)rdlin(prev, 1); k4 = k4 + 1; /* In case line empty */ if (prev->bchars == 0) goto p1002; /* J line was empty */ if (!INDENT) return; /* Finished if no indenting */ /* * Set the INDENT - code copied from SCRDIT with CURR -> PREV */ j = prev->bchars; /* Finish when find non-space */ for (ndntch = 0; ndntch < j; ndntch++) if (prev->bdata[ndntch] != SPACE) return; }
void writfl(long wrtnum) { int bytes; long todo, count; uint8_t *p, *q, thisch; short tabfnd, spacnt, chrpos; int inindent; /* Inside indenting whitespace */ /* * Initialise */ count = 0; /* No lines written yet */ todo = wrtnum; /* Max # to write */ q = fbuf; /* 1st char goes here */ unused = Q_BUFSIZ; /* Room for this many in file fbuf */ fscode = 0; /* * Main loop on lines */ for (; todo > 0; todo--) { if (!rdlin(curr, false)) { fprintf(stderr, "End of file reached:- %ld lines written\r\n", count); break; } count++; p = curr->bdata; /* Next char from here */ bytes = curr->bchars; /* Bytes in this line */ /* * Strip trailing spaces (usually)... */ if (!(fmode & 020 || binary)) while (bytes > 0) { if (curr->bdata[bytes - 1] != SPACE) break; bytes--; } spacnt = 0; /* Not pending any spaces */ tabfnd = 0; /* Not seen a real tab yet */ chrpos = 0; /* At line start */ /* In putative w/s at line start, if we care */ inindent = fmode & 040000; /* * Inner loop for this line */ for (; bytes > 0; bytes--) { thisch = *p++; /* Get editor char */ /* * Compress spaces to tabs if requested */ if (!binary && (fmode & 010 || fmode & inindent) && !tabfnd) { /* If on 8-char bdry & have spaces */ if (!(chrpos % tabsiz) && spacnt) { if (spacnt == 1) STC(SPACE); else STC('\t'); spacnt = 0; } /* if(!(chrpos%tabsiz)&&spacnt) */ chrpos++; /* Track pos'n in line */ if (thisch == '\t') tabfnd = 1; if (thisch == SPACE) /* Always increase space count, even if zero previously... */ { spacnt++; continue; /* for(;bytes>0;bytes--) */ } /* if(thisch==SPACE) */ else if (inindent) inindent = 0; for (; spacnt > 0; spacnt--) STC(SPACE); /* Flush any spaces */ } /* if (!binary && ... */ STC(thisch); /* O/p the char */ } /* for(; bytes > 0; bytes--) */ /* * Finish off line */ if (!binary) { if (spacnt) { if (!(chrpos % tabsiz)) { if (spacnt == 1) STC(SPACE); else STC('\t'); } /* if(!(chrpos%tabsiz)) */ else for (; spacnt > 0; spacnt--) STC(SPACE); } /* if(spacnt) */ if (fmode & 2) STC('\r'); /* If DOS o/p wanted */ STC('\n'); } /* if(!binary) */ } /* for(;todo>0;todo--) */ /* * All requested lines read from Workfile. Write out any partial file * buffer and close the file. Then we are finished... */ if (unused != Q_BUFSIZ) /* If any chars in buffer */ if (do_write() < 0) errlbl: fscode = errno; if (fscode) fprintf(stderr, "%s. fd %d (write)\r\n", strerror(fscode), funit); SYSCALL(bytes, close(funit)); if (bytes == -1) fprintf(stderr, "%s. fd %d (close)\r\n", strerror(errno), funit); return; }