1: #include "hd.h"
   2: #include "strings.h"
   3: #include "command.h"
   4: 
   5: /* Interface to grep */
   6: 
   7: #define GBUFLEN 200
   8: #define LIM1    (gbuf + 100)
   9: 
  10: #define QUOTE   '\''
  11: #define BSLASH  '\\'
  12: 
  13: #define GSTR1   " -n '"
  14: #define GSTR2   "' /dev/null "
  15: 
  16: #define CPSET   {cp = gbuf + strlen (gbuf);}
  17: 
  18: #define GREPLEAVE   {tty_pop ();  clearmsg (0);  return NOREPLOT;}
  19: 
  20: /* User is asked to supply patterns and file names.  Grep is then
  21:    run with its output directed to .grepout.  If the user changes his
  22:    mind, and leaves without running grep, NOREPLOT is returned.
  23:    Else REPLOT | CMD_SG is returned.
  24: */
  25: grep () {
  26:     register char *cp, *clim;  register ch;
  27:     char gbuf [GBUFLEN];
  28:     char inline [STRMAX];  int inlength;  register char *incp;
  29: 
  30:     FILE *sstream;
  31:     extern FILE *showopen ();
  32: 
  33:     int saveout;
  34: 
  35:     extern char wdname [];
  36: 
  37:     tty_push (COOKEDMODE);
  38:     strcpy (gbuf, GREP);  strcat (gbuf, GSTR1);
  39:     clearmsg (2);  printf ("Grep pattern: ");
  40:     CPSET;  clim = LIM1;
  41: 
  42:     inlength = getline (inline);  incp = inline;
  43:     if (inlength == 0) GREPLEAVE;
  44: 
  45:     while ((ch = *incp++) && cp < clim) {
  46:         if (ch == QUOTE) {
  47:             *cp++ = QUOTE;  *cp++ = BSLASH;
  48:             *cp++ = QUOTE;  *cp++ = QUOTE;
  49:         } else *cp++ = ch;
  50:     }
  51:     *cp=0;
  52:     strcat (gbuf, GSTR2);
  53:     at (2317 + inlength);  printf ("--  Grep files: ");
  54: 
  55:     CPSET;
  56:     inlength = xgetline (stdin, cp, GBUFLEN - strlen (gbuf));
  57:     if (inlength == 0) GREPLEAVE;
  58: 
  59:     /* Now run the command in gbuf */
  60: 
  61:     sstream = showopen ("w", GREPMODE);
  62:     if (sstream == NULL) GREPLEAVE;
  63: 
  64:     printf ("Searching\n");
  65: 
  66:     saveout = dup (outfile);    /* Set up files */
  67:     close (outfile); dup (fileno (sstream)); fclose (sstream);
  68: 
  69:     printf ("%s is search directory\n", wdname);
  70:     mysystem (gbuf);
  71:     close (outfile);  dup (saveout);  close (saveout);
  72: 
  73: 
  74:     tty_pop ();  return CMD_SG | REPLOT;
  75: }

Defined functions

grep defined in line 25; used 6 times

Defined macros

BSLASH defined in line 11; used 1 times
  • in line 47
CPSET defined in line 16; used 2 times
GBUFLEN defined in line 7; used 2 times
GREPLEAVE defined in line 18; used 3 times
GSTR1 defined in line 13; used 1 times
  • in line 38
GSTR2 defined in line 14; used 1 times
  • in line 52
LIM1 defined in line 8; used 1 times
  • in line 40
QUOTE defined in line 10; used 4 times
Last modified: 1980-08-11
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 822
Valid CSS Valid XHTML 1.0 Strict