# 2.11BSD#431 - /usr/src/new/notes/src/checknotes.c

##### Functions

    checknf           X
    main              X

##### Variables

    ncount            X
    nfptr             X
    verbosity         X

##### Macros

    MAINLINE          X
    VERBN             X
    VERBQ             X
    VERBS             X
    VERBV             X

       1: #define MAINLINE
       2: #include "parms.h"
       3: #include "structs.h"
       4:
       5: #ifdef  FASTSEQ
       6: #include    <sys/types.h>
       7: #include    <sys/stat.h>
       8: #endif	FASTSEQ
       9:
      10: #ifdef  RCSIDENT
      11: static char rcsid[] = "$Header: checknotes.c,v 1.7.0.1 85/02/01 09:56:54 notes Rel $";
      12: #endif	RCSIDENT
      13:
      14: /*
      15:  *	checknotes
      16:  *
      17:  *	A program which prints the notesfiles modified since the
      18:  *	user's last entry. The output is a list of the modified
      19:  *	notesfiles.
      20:  *
      21:  *	The program exits with a zero status if there ARE modified
      22:  *	notesfiles, and non-zero if there are not. This is to
      23:  *	correspond with the "true" and "false" programs and
      24:  *	to permit use of the program in shell scripts.
      25:  *
      26:  *	The optional "-q" parameter disables the printing of the
      27:  *	names of the notesfiles, the exit code is the only metho
      28:  *	of determining the existence of new notes.
      29:  *
      30:  *	Original Coding:	Ray Essick	June 12, 1982
      31:  */
      32:
      33: #define VERBQ   0
      34: #define VERBN   1
      35: #define VERBV   2
      36: #define VERBS   3
      37:
      38: int     verbosity = VERBQ;              /* be verbose */
      39: int     ncount = 0;                 /* number of modified notesfiles */
      40: struct nflist_f *nfptr;
      41:
      42: checknf (nfname)
      43: char   *nfname;
      44: {
      45:     struct io_f io;
      46:     int     retcode;
      47:
      48:
      49: #ifdef  FASTSEQ
      50:     {                           /* for FAST checknotes ... */
      51:     struct when_f   whenvec;
      52:     char    NoteFile[WDLEN];
      53:     struct stat StatBuf;
      54:
      55:     if (nfname[0] == '/')               /* absolute pathname */
      56:     {
      57:         getlast (&io.stime, rindex (nfname, '/') + 1, NORMSEQ, Seqname);
      58:         sprintf (NoteFile, "%s/%s", nfname, TEXT);
      59:     }
      60:     else                        /* relative to Mstdir */
      61:     {
      62:         getlast (&io.stime, nfname, NORMSEQ, Seqname);
      63:         sprintf (NoteFile, "%s/%s/%s", Mstdir, nfname, TEXT);
      64:     }
      65:     if (stat (NoteFile, &StatBuf) >= 0)
      66:     {
      67:         maketime (&whenvec, (long) StatBuf.st_mtime);
      68:         if (inorder (&whenvec, &io.stime))
      69:         {
      70:         return (0);
      71:         }
      72:         /*
      73: 	     * not in order means that we should check the hard way
      74: 	     */
      75:     }
      76:     }
      77: #endif	FASTSEQ
      78:
      79: /*
      80:  *	Do it the hard way -- open the notesfile and read the descriptor
      81:  */
      82:     if (opennf (&io, nfname) < 0)
      83:     return 0;                   /* ignore this one */
      84:     getdscr (&io, &io.descr);
      85:     getlast (&io.stime, io.nf, NORMSEQ, Seqname);   /* last date */
      86:     if (inorder (&io.stime, &io.descr.d_lastm))
      87:     {
      88:     ncount++;                   /* bump count of touched notesfiles */
      89:     if (verbosity == VERBV)
      90:         printf ("%s\n", nfname);
      91:     if (verbosity == VERBQ || verbosity == VERBS)
      92:         retcode = QUITFAST;
      93:     else
      94:         retcode = 1;
      95:     }
      96:     else
      97:     retcode = 0;
      98:     closenf (&io);                  /* close the notesfile */
      99:     return retcode;
     100: }
     101:
     102:
     103: main (argc, argv)
     104: char  **argv;
     105: {
     106:     char   *p;
     107:     int     i;
     108:
     109:     startup (argc, argv);               /* common initialization */
     110:
     111:     if ((p = getenv ("NFSEQ")) == NULL)
     112:     p = DFLTSEQ;                    /* use default */
     113:
     114:     expand (p);                     /* put it in */
     115:
     116:     for (i = 1; i < argc; i++)
     117:     if (argv[i][0] == '-')              /* see if options */
     118:         switch (argv[i][1])
     119:         {
     120:         case 'q':               /* "are new notes" */
     121:             verbosity = VERBQ;
     122:             break;
     123:
     124:         case 'n':               /* spit "no new notes" */
     125:             verbosity = VERBN;
     126:             break;
     127:
     128:         case 'v':               /* tell everything */
     129:             verbosity = VERBV;
     130:             break;
     131:
     132:         case 's':               /* silent */
     133:             verbosity = VERBS;
     134:             break;
     135:
     136:         case 'a':               /* alternate sequencer */
     137:             if (++i == argc)            /* supplied name? */
     138:             {
     139:             fprintf (stderr, "-a requires a name\n");
     140:             exit (BAD);
     141:             }
     142:             else
     143:             {
     144:             struct auth_f   whoami;
     145:             getname (&whoami, 0);       /* grab real name */
     146:             sprintf (Seqname, "%s:%s", whoami.aname, argv[i]);
     147:             }
     148:             break;
     149:
     150:         default:
     151:             fprintf (stderr, "Usage: %s [-qvns] [-a seqname]\n", argv[0]);
     152:             exit (BAD);
     153:         }
     154:     else                        /* a notesfile! */
     155:         expand (argv[i]);               /* put it in */
     156:
     157:     while ((nfptr = nextgroup ()) != (struct nflist_f *) NULL)
     158:     {
     159:     i = checknf (nfptr -> nf_name);
     160:     if (i == QUITFAST)
     161:         break;                  /* don't need more */
     162:     }
     163:
     164:     switch (verbosity)
     165:     {
     166:     case VERBQ:                     /* "there are new" */
     167:         if (ncount)
     168:         printf ("There are new notes\n");
     169:         break;
     170:
     171:     case VERBN:                     /* there are no new */
     172:         if (ncount == 0)
     173:         printf ("There are no new notes\n");
     174:         break;
     175:
     176:     case VERBV:                     /* told elsewhere */
     177:     case VERBS:                     /* silent */
     178:     default:
     179:         break;
     180:     }
     181:     if (ncount)
     182:     exit (0);                   /* TRUE/success for the shell */
     183:     else
     184:     exit (1);                   /* FALSE/failure to the shell */
     185:
     186: }

#### Defined functions

checknf defined in line 42; used 1 times

- in line 159

main defined in line 103; never used

#### Defined variables

ncount defined in line 39; used 4 times

- in line 88, 167-172(2), 181

nfptr defined in line 40; used 2 times

- in line 157-159(2)

rcsid defined in line 11; never used
verbosity defined in line 38; used 8 times

- in line 89-91(3), 121-133(4), 164

#### Defined macros

MAINLINE defined in line 1; never used
VERBN defined in line 34; used 1 times

- in line 125

VERBQ defined in line 33; used 3 times

- in line 38, 91, 121

VERBS defined in line 36; used 2 times

- in line 91, 133

VERBV defined in line 35; used 2 times

- in line 89, 129

Last modified: 1985-02-01 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 863 |