1: #include "hd.h"
   2: #include "strings.h"
   3: #include "command.h"
   4: 
   5: #define SPAGELEN    12  /* Number of Lines per Page */
   6: 
   7: static char EONE [] = "+1"; /* Default editor parameter */
   8: 
   9: /* Global data about file being shown */
  10: 
  11: FILE *sstream;          /* Stream being shown */
  12: 
  13: int cline;          /* Current (next) line to be shown */
  14: int tline;          /* Top line of page */
  15: 
  16: char *sdesc [2] = {"Grep", "Make"};
  17: 
  18: showerror () {
  19:     return show (MAKEMODE);
  20: }
  21: showgrep () {
  22:     return show (GREPMODE);
  23: }
  24: 
  25: show (p) int p; {       /* Use parms GREPMODE or MAKEMODE */
  26: 
  27:     FILE *showopen ();
  28:     int cmd, next, number, spaces;
  29:     int (*cproc)();
  30:     extern grep(), wmake(), showerror(), showgrep();
  31: 
  32:     sstream = showopen ("r", p);
  33:     if (sstream == NULL) return NOREPLOT;
  34: 
  35:     cline = 1;
  36:     next = REPLOT;
  37: 
  38:     for (;;) {
  39:         if (next & REPLOT) {
  40:             sdisp (p);
  41:             number = spaces = 0;
  42:         }
  43: 
  44:         if (number == 0)  {
  45:             at (2301);
  46:             printf ("  \r");
  47:         }
  48:         cmd = getch ();
  49:         next = REPLOT;
  50: 
  51:                     /* This accumulates a number */
  52:         if (NUMERIC (cmd) && spaces == 0) {
  53:             number = number * 10 + TONUM (cmd);
  54:             next = 0;
  55:         }
  56:         else if (cmd == '\b') {
  57:             if (spaces > 0) --spaces;
  58:             else number /= 10;
  59:             printf (" \b");
  60:             next = 0;
  61:         }
  62:         else if (cmd == ' ') {
  63:             if (number > 0) ++spaces;
  64:             next = 0;
  65:         }
  66: 
  67:                     /* These commands use number */
  68:         else if (cmd == LF || cmd == CR || cmd == 'e') {
  69:             putch (CR);
  70:             next = sedit (p, number);
  71:             number = spaces = 0;
  72:         }
  73:         else if (cmd == 'p') {
  74:             putch (CR);
  75:             seekline (number);
  76:         }
  77:         else {
  78:             number = spaces = 0;  putch (CR);
  79:             cproc = cmdproc(cmd);
  80:             if (cproc == showerror || cproc == showgrep) {
  81:                 next = cmd | REPLOT;
  82:                 break;
  83:             }
  84:             else if (cmd == '?') {
  85:                 next = help (SHOWHELP);
  86:             }
  87:             else if (cproc == grep) {
  88:                 next = grep ();
  89:                 if (next != FAILURE) break;
  90:             }
  91:             else if (cproc == wmake) {
  92:                 next = wmake ();
  93:                 if (next != FAILURE) break;
  94:             }
  95:             else if (cmd == 'q' || cmd == EOT) {
  96:                 break;
  97:             }
  98:             else {
  99:                 next = command (cmd, SHOWCMD);
 100:             }
 101:             if (next & ENTERDIR) break;
 102:             if (next & REPLOT) seekline (tline);
 103:         }
 104:     }
 105:     fclose (sstream);
 106:     return next | REPLOT;
 107: }
 108: 
 109: /* Position show file at specified location */
 110: seekline (line) int line; {
 111: 
 112:     register ch;
 113: 
 114:     cline = 1;  rewind (sstream);
 115:     while (cline < line && (ch = getc (sstream)) != EOF)
 116:         if (ch == LF) cline++;
 117: 
 118:     if (feof (sstream)) {
 119:         if (cline <= 2) {
 120:             rewind (sstream);  cline = 1;
 121:         } else {
 122:             seekline (cline - 1);
 123:         }
 124:     }
 125: }
 126: 
 127: sdisp (p)  int p; { /* display sstream */
 128: 
 129: register ch;        /* work char */
 130: int eline;      /* end line -- line to stop display */
 131: short lflag;        /* True if chars have printed on current line */
 132: 
 133: extern char wdname [];  /* Name of working dir */
 134: 
 135: if (feof (sstream)) seekline (1);
 136: 
 137: tline = cline;
 138: eline = cline + SPAGELEN;
 139: 
 140: clearmsg (-1);  bufout ();  tty_push (COOKEDMODE);
 141: 
 142: erase ();  printf ("%s", wdname);
 143: at (161);  printf ("Showfile -- %s     \n",  sdesc [p]);
 144: 
 145: while (cline < eline) {
 146:     lflag = 0;
 147: 
 148:     do {
 149:         ch = getc (sstream);
 150:         if (ch == EOF) ch = LF;
 151:         else if (!lflag)  {
 152:             printf ("%4d	", cline);
 153:             lflag = 1;
 154:         }
 155:         putchar (ch);
 156:     }  while (ch != LF);
 157: 
 158:     cline++;
 159:     if (feof (sstream)) {
 160:         seekline (1);  printf ("** End of File **\n");
 161:         break;
 162:     }
 163: }
 164: printf ("\nType the number of the line you wish to edit.\n");
 165: printf ("Type ^D to Leave.  Type ? for more options.");
 166: 
 167: at (2301); unbufout ();  tty_pop ();
 168: }
 169: 
 170: sedit (p, number) int p, number; {
 171:     char inbuf [STRMAX];
 172: 
 173:     int oldline;
 174: 
 175:     oldline = cline;
 176:     if (number == 0) return REPLOT;
 177:     seekline (number);
 178: 
 179:     fgetline (sstream, inbuf);
 180:     if (p == GREPMODE && grepfmt (inbuf));
 181:     else if (p == MAKEMODE &&
 182:         (ccfmt (inbuf) || grepfmt (inbuf) || cmdfmt (inbuf)));
 183:     else {
 184:         putmsg ("Cannot find file name");
 185:         seekline (oldline);
 186:         return NOREPLOT;
 187:     }
 188:     seekline (number);
 189:     return REPLOT;
 190: }
 191: 
 192: /* Extract file names and line numbers from various formats.  */
 193: 
 194: ccfmt (inbuf) char inbuf [STRMAX]; {    /*  Error from C compiler */
 195:     char filebuf [STRMAX];      /*  or lint		  */
 196:     char *enumber ();
 197:     register char *cpi, *cpo;
 198: 
 199:     cpi = inbuf;
 200:     while (*cpi != '"') if (*cpi++ == 0) return 0;
 201: 
 202:     cpi++;  cpo = filebuf;
 203:     while (*cpi != '"') {
 204:         if (*cpi == 0) return 0;
 205:         *cpo++ = *cpi++;
 206:     }
 207:     *cpo = 0;
 208: 
 209:     return nedit (filebuf, enumber (cpi));
 210: }
 211: 
 212: grepfmt (inbuf) char inbuf [STRMAX]; {  /*  Line from grep	  */
 213:     char filebuf [STRMAX];      /*  or C preprocessor	  */
 214:     char *enumber ();
 215:     register char *cpi, *cpo;
 216: 
 217:     cpi = inbuf;  cpo = filebuf;
 218:     while (*cpi != ':') {
 219:         if (*cpi == 0) return 0;
 220:         *cpo++ = *cpi++;
 221:     }
 222:     if (*cpi == 0) return 0;
 223:     *cpo = 0;
 224: 
 225:     return nedit (filebuf, enumber (cpi));
 226: }
 227: 
 228: cmdfmt (inbuf) char inbuf [STRMAX]; {   /*  Command line	  */
 229:     char filebuf [STRMAX];
 230:     register char *cpi, *cpo;
 231: 
 232:     cpi = inbuf;
 233: 
 234:     do  {
 235:         while (!WHITESPACE (*cpi)) if (*cpi++ == 0) return 0;
 236:         while ( WHITESPACE (*cpi)) cpi++;
 237:     }  while (*cpi == '-');
 238: 
 239:     if (*cpi == 0) return 0;
 240: 
 241:     cpo = filebuf;
 242:     while (!WHITESPACE (*cpi) && *cpi != 0) *cpo++ = *cpi++;
 243:     *cpo = 0;
 244: 
 245:     return nedit (filebuf, EONE);
 246: }
 247: 
 248: /* Extract number from line */
 249: 
 250: char *
 251: enumber (cpi) register char *cpi; {
 252: 
 253:     static char numbuf [8];
 254: #	define    NUMBUFLIM   (numbuf + sizeof numbuf)
 255: 
 256:     register char *cpo;
 257:     cpo = numbuf;  *cpo++ = '+';
 258: 
 259:     while (!NUMERIC (*cpi)) if (*cpi++ == 0) return EONE;
 260: 
 261:     while (NUMERIC (*cpi)) {
 262:         if (cpo >= NUMBUFLIM) return EONE;
 263:         *cpo++ = *cpi++;
 264:     }
 265:     *cpo = 0;
 266: 
 267:     return numbuf;
 268: }
 269: 
 270: nedit (file, number) char *file, *number; {
 271: 
 272:     if (access (file, 4)) return FAILURE;
 273:     f_exec (EDITOR, EDITOR, number, file, 0);
 274:     return REPLOT;
 275: }

Defined functions

ccfmt defined in line 194; used 1 times
cmdfmt defined in line 228; used 1 times
enumber defined in line 250; used 4 times
grepfmt defined in line 212; used 2 times
nedit defined in line 270; used 3 times
sdisp defined in line 127; used 1 times
  • in line 40
sedit defined in line 170; used 1 times
  • in line 70
seekline defined in line 110; used 8 times
show defined in line 25; used 2 times
showerror defined in line 18; used 6 times
showgrep defined in line 21; used 6 times

Defined variables

EONE defined in line 7; used 3 times
cline defined in line 13; used 13 times
sdesc defined in line 16; used 1 times
tline defined in line 14; used 2 times

Defined macros

NUMBUFLIM defined in line 254; used 1 times
SPAGELEN defined in line 5; used 1 times
Last modified: 1980-08-11
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1150
Valid CSS Valid XHTML 1.0 Strict