1: #define MAINLINE
   2: 
   3: #ifdef  RCSIDENT
   4: static char rcsid[] = "$Header: nfprint.c,v 1.7 85/01/18 15:28:54 notes Rel $";
   5: #endif	RCSIDENT
   6: 
   7: /*
   8:  *	nfprint - print out the contents of a notefile.
   9:  *
  10:  *	this program produces line printable output for the
  11:  *	notefile specified. Included is a table of contents
  12:  *	detailing where the notes are.
  13:  *
  14:  *	Call:
  15:  *		nfprint [-lnn] notefile list > output
  16:  *
  17:  *	list is an orders list on notenumbers.
  18:  *
  19:  *	Original Coding:	Ray Essick	January 1982
  20:  */
  21: 
  22: /*---------------------------------------------------------------------------
  23:  * COMPION (sep 84-8-21)
  24:  * added code to allow excluding or limiting to messages with director
  25:  * flag set (used here to toggle messages between 'pending' and
  26:  * 'completed' status)
  27:  *---------------------------------------------------------------------------
  28:  */
  29: 
  30: #include "parms.h"
  31: #include "structs.h"
  32: 
  33: #define PLENGTH 66                  /* length of a page */
  34: 
  35: int     length;                     /* length of a page */
  36: int     left;                       /* lines left on the current page */
  37: int     page;                       /* which page we are on */
  38: int     justtitles;                 /* no text */
  39: int     usepr = 1;                  /* paginate */
  40: /* COMPION (sep 84-8-21) added next two declares */
  41: int     exclude_director;               /* print no director messages */
  42: int     director_only;                  /* print only director messages */
  43: 
  44: main (argc, argv)
  45: char  **argv;
  46: {
  47:     struct io_f io;
  48:     FILE * toc;                     /* table of contents scratch file */
  49:     FILE * lprfile;
  50:     FILE * popen ();
  51:     char   *p;
  52:     char    buf[WDLEN];
  53:     char    cmdline[WDLEN];
  54:     struct note_f   note;
  55:     register int    i;
  56:     char    dfltrange[10];              /* hold default list */
  57:     int     bufptr,
  58:             start,
  59:             end;
  60:     int     singlepage;
  61:     char    fn[WDLEN];                  /* file name */
  62:     int     argp;
  63: 
  64:     startup (argc, argv);               /* common initialization */
  65: 
  66:     if (argc == 1)                  /* tell him how */
  67:     {
  68:     fprintf (stderr,
  69:         "Usage: %s [-lnn] [-c] [-p] [-{d,nd}] [-t] notesfile list\n",
  70:         argv[0]);
  71:     exit (BAD);
  72:     }
  73: 
  74: 
  75:     page = 1;
  76:     singlepage = 0;                 /* no page break between notes */
  77:     justtitles = 0;                 /* include text */
  78:     usepr = 1;                      /* default to pr */
  79:                             /* COMPION (sep 84-8-21) next two init lines added */
  80:     exclude_director = 0;               /* don't exclude director messages */
  81:     director_only = 0;                  /* don't limit to director messages */
  82:     length = PLENGTH;
  83:     argp = 1;                       /* arg parsing */
  84:     while (argv[argp][0] == '-')
  85:     {
  86:     switch (argv[argp][1])
  87:     {
  88:         case 'c':                   /* use cat instead */
  89:         usepr = 0;
  90:         break;
  91:         case 'l':                   /* page length */
  92:         length = atoi (&argv[argp][2]);
  93:         break;
  94: /* COMPION (sep 84-8-21) next two cases added */
  95:         case 'd':
  96:         director_only++;
  97:         break;
  98:         case 'n':
  99:         if (argv[argp][2] == 'd')
 100:         {
 101:             exclude_director++;
 102:         }
 103:         break;
 104:         case 'p':                   /* start all notes on fresh page */
 105:         singlepage++;
 106:         break;
 107: 
 108:         case 't':                   /* titles only */
 109:         justtitles++;
 110:         break;
 111: 
 112:         default:
 113:         fprintf (stderr, "Bad switch `%c'\n", argv[argp][1]);
 114:         exit (BAD);
 115:     }
 116: 
 117:     argp++;                     /* jump to next one */
 118:     }
 119:     if (init (&io, argv[argp]) < 0)         /* get the notesfile */
 120:     {
 121:     exit (NONF);
 122:     }
 123:     if (allow (&io, READOK) == 0)
 124:     {
 125:     fprintf (stderr, "You are not allowed to read %s\n", argv[argp]);
 126:     exit (BAD);
 127:     }
 128: 
 129:     sprintf (fn, "/tmp/nf%d", getpid ());       /* build toc file */
 130:     x ((toc = fopen (fn, "w")) == NULL, "nfprint: no scratch file");
 131: 
 132:     p = buf;
 133:     for (i = 0; i < NNLEN; i++)
 134:     *p++ = io.descr.d_title[i];         /* move title */
 135:     *p = '\0';                      /* and null terminate */
 136:     if (usepr)                      /* paginate with pr */
 137:     sprintf (cmdline, "pr -l%d -h '(%s) %s'", length, System, buf);
 138:     else
 139:     sprintf (cmdline, "cat -");         /* just use cat */
 140:     x ((lprfile = popen (cmdline, "w")) == NULL, "nfprint: can't run pr");
 141: 
 142: 
 143:     length -= 10;                   /* pr uses 5/5 header/footer */
 144:     left = length;                  /* empty page */
 145:     if (argp == (argc - 1))             /* last arg ... */
 146:     {
 147:     sprintf (dfltrange, "%d-%d", 1, io.descr.d_nnote);
 148:     argv[argp--] = dfltrange;           /* set up as an arg */
 149:     }
 150:     argp++;                     /* advance to next arg */
 151:     for (; argp < argc; argp++)
 152:     {
 153:     bufptr = 0;
 154:     while (listget (argv[argp], &bufptr, &start, &end))
 155:     {
 156:         if (start > end)
 157:         continue;               /* wrong order */
 158:         if (start > io.descr.d_nnote)
 159:         continue;               /* too far out */
 160:         if (start < 1)
 161:         start = 1;
 162:         if (end > io.descr.d_nnote)
 163:         end = io.descr.d_nnote;         /* max out */
 164:         for (i = start; i <= end; i++)
 165:         {
 166:         getnrec (&io, i, &note);
 167:         if (note.n_stat & DELETED)
 168:             continue;               /* its not really there */
 169: /*---------------------------------------------------------------------------
 170:  * COMPION (sep 84-8-21)
 171:  * added test to allow or inclusion/exclusion based on director message
 172:  * flag
 173:  *---------------------------------------------------------------------------
 174:  */
 175:         if ((exclude_director && (note.n_stat & DIRMES))
 176:             || (director_only && !(note.n_stat & DIRMES)))
 177:         {
 178:             continue;
 179:         }
 180:         if (singlepage && left != length)   /* want page breaks? */
 181:             pagebreak (lprfile);
 182:         lprnote (&io, lprfile, toc, i, &note, justtitles);
 183:         }
 184:     }
 185:     }
 186:     x (fclose (toc) == EOF, "nfprint: bad fclose 1");
 187:     x ((toc = fopen (fn, "r")) == NULL, "nfprint: bad reopen of toc");
 188:     if (!justtitles)                    /* only if w/ text */
 189:     pagebreak (lprfile);                /* force page break */
 190:     while ((i = getc (toc)) != EOF)
 191:     putc (i, lprfile);
 192:     fclose (toc);
 193:     x (unlink (fn) < 0, "nfprint: couldnt unlink scratch file");
 194:     pclose (lprfile);                   /* flush the pipe */
 195:                             /* and wait too! */
 196:     exit (GOOD);
 197: }

Defined functions

main defined in line 44; never used

Defined variables

director_only defined in line 42; used 3 times
exclude_director defined in line 41; used 3 times
justtitles defined in line 38; used 4 times
left defined in line 36; used 13 times
length defined in line 35; used 9 times
page defined in line 37; used 5 times
rcsid defined in line 4; never used
usepr defined in line 39; used 3 times

Defined macros

MAINLINE defined in line 1; never used
PLENGTH defined in line 33; used 1 times
  • in line 82
Last modified: 1985-10-30
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1314
Valid CSS Valid XHTML 1.0 Strict