home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / rcs / sources / rlog.c < prev    next >
C/C++ Source or Header  |  1992-01-24  |  33KB  |  1,215 lines

  1. /*
  2.  *                       RLOG    operation
  3.  */
  4. /*****************************************************************************
  5.  *                       print contents of RCS files
  6.  *****************************************************************************
  7.  */
  8.  
  9. /* Copyright (C) 1982, 1988, 1989 Walter Tichy
  10.    Copyright 1990, 1991 by Paul Eggert
  11.    Distributed under license by the Free Software Foundation, Inc.
  12.  
  13. This file is part of RCS.
  14.  
  15. RCS is free software; you can redistribute it and/or modify
  16. it under the terms of the GNU General Public License as published by
  17. the Free Software Foundation; either version 2, or (at your option)
  18. any later version.
  19.  
  20. RCS is distributed in the hope that it will be useful,
  21. but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  23. GNU General Public License for more details.
  24.  
  25. You should have received a copy of the GNU General Public License
  26. along with RCS; see the file COPYING.  If not, write to
  27. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  28.  
  29. Report problems and direct all questions to:
  30.  
  31.     rcs-bugs@cs.purdue.edu
  32.  
  33. */
  34.  
  35.  
  36.  
  37.  
  38. /* $Log: rlog.c,v $
  39.  * Revision 5.11  1992/01/24  18:44:19  eggert
  40.  * Don't duplicate unexpected_EOF's function.  lint -> RCS_lint
  41.  *
  42.  * Revision 5.10  1992/01/06  02:42:34  eggert
  43.  * Update usage string.
  44.  * while (E) ; -> while (E) continue;
  45.  *
  46.  * Revision 5.9  1991/09/17  19:07:40  eggert
  47.  * Getscript() didn't uncache partial lines.
  48.  *
  49.  * Revision 5.8  1991/08/19  03:13:55  eggert
  50.  * Revision separator is `:', not `-'.
  51.  * Check for missing and duplicate logs.  Tune.
  52.  * Permit log messages that do not end in newline (including empty logs).
  53.  *
  54.  * Revision 5.7  1991/04/21  11:58:31  eggert
  55.  * Add -x, RCSINIT, MS-DOS support.
  56.  *
  57.  * Revision 5.6  1991/02/26  17:07:17  eggert
  58.  * Survive RCS files with missing logs.
  59.  * strsave -> str_save (DG/UX name clash)
  60.  *
  61.  * Revision 5.5  1990/11/01  05:03:55  eggert
  62.  * Permit arbitrary data in logs and comment leaders.
  63.  *
  64.  * Revision 5.4  1990/10/04  06:30:22  eggert
  65.  * Accumulate exit status across files.
  66.  *
  67.  * Revision 5.3  1990/09/11  02:41:16  eggert
  68.  * Plug memory leak.
  69.  *
  70.  * Revision 5.2  1990/09/04  08:02:33  eggert
  71.  * Count RCS lines better.
  72.  *
  73.  * Revision 5.0  1990/08/22  08:13:48  eggert
  74.  * Remove compile-time limits; use malloc instead.  Add setuid support.
  75.  * Switch to GMT.
  76.  * Report dates in long form, to warn about dates past 1999/12/31.
  77.  * Change "added/del" message to make room for the longer dates.
  78.  * Don't generate trailing white space.  Add -V.  Ansify and Posixate.
  79.  *
  80.  * Revision 4.7  89/05/01  15:13:48  narten
  81.  * changed copyright header to reflect current distribution rules
  82.  *
  83.  * Revision 4.6  88/08/09  19:13:28  eggert
  84.  * Check for memory exhaustion; don't access freed storage.
  85.  * Shrink stdio code size; remove lint.
  86.  *
  87.  * Revision 4.5  87/12/18  11:46:38  narten
  88.  * more lint cleanups (Guy Harris)
  89.  *
  90.  * Revision 4.4  87/10/18  10:41:12  narten
  91.  * Updating version numbers
  92.  * Changes relative to 1.1 actually relative to 4.2
  93.  *
  94.  * Revision 1.3  87/09/24  14:01:10  narten
  95.  * Sources now pass through lint (if you ignore printf/sprintf/fprintf
  96.  * warnings)
  97.  *
  98.  * Revision 1.2  87/03/27  14:22:45  jenkins
  99.  * Port to suns
  100.  *
  101.  * Revision 4.2  83/12/05  09:18:09  wft
  102.  * changed rewriteflag to external.
  103.  *
  104.  * Revision 4.1  83/05/11  16:16:55  wft
  105.  * Added -b, updated getnumericrev() accordingly.
  106.  * Replaced getpwuid() with getcaller().
  107.  *
  108.  * Revision 3.7  83/05/11  14:24:13  wft
  109.  * Added options -L and -R;
  110.  * Fixed selection bug with -l on multiple files.
  111.  * Fixed error on dates of the form -d'>date' (rewrote getdatepair()).
  112.  *
  113.  * Revision 3.6  82/12/24  15:57:53  wft
  114.  * shortened output format.
  115.  *
  116.  * Revision 3.5  82/12/08  21:45:26  wft
  117.  * removed call to checkaccesslist(); used DATEFORM to format all dates;
  118.  * removed unused variables.
  119.  *
  120.  * Revision 3.4  82/12/04  13:26:25  wft
  121.  * Replaced getdelta() with gettree(); removed updating of field lockedby.
  122.  *
  123.  * Revision 3.3  82/12/03  14:08:20  wft
  124.  * Replaced getlogin with getpwuid(), %02d with %.2d, fancydate with PRINTDATE.
  125.  * Fixed printing of nil, removed printing of Suffix,
  126.  * added shortcut if no revisions are printed, disambiguated struct members.
  127.  *
  128.  * Revision 3.2  82/10/18  21:09:06  wft
  129.  * call to curdir replaced with getfullRCSname(),
  130.  * fixed call to getlogin(), cosmetic changes on output,
  131.  * changed conflicting long identifiers.
  132.  *
  133.  * Revision 3.1  82/10/13  16:07:56  wft
  134.  * fixed type of variables receiving from getc() (char -> int).
  135.  */
  136.  
  137.  
  138.  
  139. #include "rcsbase.h"
  140.  
  141. struct  lockers {                     /* lockers in locker option; stored   */
  142.      char const        * login;      /* lockerlist                */
  143.      struct     lockers * lockerlink;
  144.      }  ;
  145.  
  146. struct  stateattri {                  /* states in state option; stored in  */
  147.      char const        * status;     /* statelist                */
  148.      struct  stateattri * nextstate;
  149.      }  ;
  150.  
  151. struct  authors {                     /* login names in author option;      */
  152.      char const        * login;      /* stored in authorlist            */
  153.      struct     authors * nextauthor;
  154.      }  ;
  155.  
  156. struct Revpairs{                      /* revision or branch range in -r     */
  157.      unsigned          numfld;     /* option; stored in revlist        */
  158.      char const        * strtrev;
  159.      char const        * endrev;
  160.      struct  Revpairs   * rnext;
  161.      } ;
  162.  
  163. struct Datepairs{                     /* date range in -d option; stored in */
  164.      char               strtdate[datesize];   /* duelst and datelist      */
  165.      char               enddate[datesize];
  166.      struct  Datepairs  * dnext;
  167.      };
  168.  
  169. static char extractdelta P((struct hshentry const*));
  170. static int checkrevpair P((char const*,char const*));
  171. static struct hshentry const *readdeltalog P((void));
  172. static unsigned extdate P((struct hshentry*));
  173. static void cleanup P((void));
  174. static void exttree P((struct hshentry*));
  175. static void getauthor P((char*));
  176. static void getdatepair P((char*));
  177. static void getlocker P((char*));
  178. static void getnumericrev P((void));
  179. static void getrevpairs P((char*));
  180. static void getscript P((struct hshentry*));
  181. static void getstate P((char*));
  182. static void putabranch P((struct hshentry const*));
  183. static void putadelta P((struct hshentry const*,struct hshentry const*,int));
  184. static void putforest P((struct branchhead const*));
  185. static void putree P((struct hshentry const*));
  186. static void putrunk P((void));
  187. static void recentdate P((struct hshentry const*,struct Datepairs*));
  188. static void trunclocks P((void));
  189.  
  190. static char const *insDelFormat;
  191. static int branchflag;    /*set on -b */
  192. static int exitstatus;
  193. static int lockflag;
  194. static struct Datepairs *datelist, *duelst;
  195. static struct Revpairs *revlist, *Revlst;
  196. static struct authors *authorlist;
  197. static struct lockers *lockerlist;
  198. static struct stateattri *statelist;
  199.  
  200.  
  201. mainProg(rlogId, "rlog", "$Id: rlog.c,v 5.11 1992/01/24 18:44:19 eggert Exp $")
  202. {
  203.     static char const cmdusage[] =
  204.         "\nrlog usage: rlog -{bhLRt} -ddates -l[lockers] -r[revs] -sstates -w[logins] -Vn -xsuff file ...";
  205.  
  206.     register FILE *out;
  207.     char *a, **newargv;
  208.     struct Datepairs *currdate;
  209.     char const *accessListString, *accessFormat, *commentFormat;
  210.     char const *headFormat, *symbolFormat;
  211.     struct access const *curaccess;
  212.     struct assoc const *curassoc;
  213.     struct hshentry const *delta;
  214.     struct lock const *currlock;
  215.     int descflag, selectflag;
  216.     int onlylockflag;  /* print only files with locks */
  217.     int onlyRCSflag;  /* print only RCS file name */
  218.     unsigned revno;
  219.  
  220.         descflag = selectflag = true;
  221.     onlylockflag = onlyRCSflag = false;
  222.     out = stdout;
  223.     suffixes = X_DEFAULT;
  224.  
  225.     argc = getRCSINIT(argc, argv, &newargv);
  226.     argv = newargv;
  227.     while (a = *++argv,  0<--argc && *a++=='-') {
  228.         switch (*a++) {
  229.  
  230.         case 'L':
  231.             onlylockflag = true;
  232.             break;
  233.  
  234.         case 'R':
  235.             onlyRCSflag =true;
  236.             break;
  237.  
  238.                 case 'l':
  239.                         lockflag = true;
  240.             getlocker(a);
  241.                         break;
  242.  
  243.                 case 'b':
  244.                         branchflag = true;
  245.                         break;
  246.  
  247.                 case 'r':
  248.             getrevpairs(a);
  249.                         break;
  250.  
  251.                 case 'd':
  252.             getdatepair(a);
  253.                         break;
  254.  
  255.                 case 's':
  256.             getstate(a);
  257.                         break;
  258.  
  259.                 case 'w':
  260.             getauthor(a);
  261.                         break;
  262.  
  263.                 case 'h':
  264.             descflag = false;
  265.                         break;
  266.  
  267.                 case 't':
  268.                         selectflag = false;
  269.                         break;
  270.  
  271.         case 'q':
  272.             /* This has no effect; it's here for consistency.  */
  273.             quietflag = true;
  274.             break;
  275.  
  276.         case 'x':
  277.             suffixes = a;
  278.             break;
  279.  
  280.         case 'V':
  281.             setRCSversion(*argv);
  282.             break;
  283.  
  284.                 default:
  285.             faterror("unknown option: %s%s", *argv, cmdusage);
  286.  
  287.                 };
  288.         } /* end of option processing */
  289.  
  290.     if (argc<1) faterror("no input file%s", cmdusage);
  291.  
  292.     if (! (descflag|selectflag)) {
  293.         warn("-t overrides -h.");
  294.         descflag = true;
  295.     }
  296.  
  297.     if (RCSversion < VERSION(5)) {
  298.         accessListString = "\naccess list:   ";
  299.         accessFormat = "  %s";
  300.         commentFormat = "\ncomment leader:  \"";
  301.         headFormat = "\nRCS file:        %s;   Working file:    %s\nhead:           %s%s\nbranch:         %s%s\nlocks:         ";
  302.         insDelFormat = "  lines added/del: %lu/%lu";
  303.         symbolFormat = "  %s: %s;";
  304.     } else {
  305.         accessListString = "\naccess list:";
  306.         accessFormat = "\n\t%s";
  307.         commentFormat = "\ncomment leader: \"";
  308.         headFormat = "\nRCS file: %s\nWorking file: %s\nhead:%s%s\nbranch:%s%s\nlocks:%s";
  309.         insDelFormat = "  lines: +%lu -%lu";
  310.         symbolFormat = "\n\t%s: %s";
  311.     }
  312.  
  313.         /* now handle all filenames */
  314.         do {
  315.         ffree();
  316.  
  317.         if (pairfilenames(argc, argv, rcsreadopen, true, false)  <=  0)
  318.         continue;
  319.  
  320.             /* now RCSfilename contains the name of the RCS file, and finptr
  321.              * the file descriptor. Workfilename contains the name of the
  322.              * working file.
  323.              */
  324.  
  325.         /* Keep only those locks given by -l.  */
  326.         if (lockflag)
  327.         trunclocks();
  328.  
  329.             /* do nothing if -L is given and there are no locks*/
  330.         if (onlylockflag && !Locks)
  331.         continue;
  332.  
  333.         if ( onlyRCSflag ) {
  334.         aprintf(out, "%s\n", RCSfilename);
  335.         continue;
  336.         }
  337.             /*   print RCS filename , working filename and optional
  338.                  administrative information                         */
  339.             /* could use getfullRCSname() here, but that is very slow */
  340.         aprintf(out, headFormat, RCSfilename, workfilename,
  341.             Head ? " " : "",  Head ? Head->num : "",
  342.             Dbranch ? " " : "",  Dbranch ? Dbranch : "",
  343.             StrictLocks ? " strict" : ""
  344.         );
  345.             currlock = Locks;
  346.             while( currlock ) {
  347.         aprintf(out, symbolFormat, currlock->login,
  348.                                 currlock->delta->num);
  349.                 currlock = currlock->nextlock;
  350.             }
  351.             if (StrictLocks && RCSversion<VERSION(5))
  352.         aputs("  strict", out);
  353.  
  354.         aputs(accessListString, out);      /*  print access list  */
  355.             curaccess = AccessList;
  356.             while(curaccess) {
  357.         aprintf(out, accessFormat, curaccess->login);
  358.                 curaccess = curaccess->nextaccess;
  359.             }
  360.  
  361.         aputs("\nsymbolic names:", out);   /*  print symbolic names   */
  362.         for (curassoc=Symbols; curassoc; curassoc=curassoc->nextassoc)
  363.         aprintf(out, symbolFormat, curassoc->symbol, curassoc->num);
  364.         aputs(commentFormat, out);
  365.         awrite(Comment.string, Comment.size, out);
  366.         aputs("\"\n", out);
  367.         if (VERSION(5)<=RCSversion  ||  Expand != KEYVAL_EXPAND)
  368.         aprintf(out, "keyword substitution: %s\n",
  369.             expand_names[Expand]
  370.         );
  371.  
  372.             gettree();
  373.  
  374.         aprintf(out, "total revisions: %u", TotalDeltas);
  375.  
  376.         revno = 0;
  377.  
  378.         if (Head  &&  selectflag & descflag) {
  379.  
  380.         getnumericrev();    /* get numeric revision or branch names */
  381.  
  382.         exttree(Head);
  383.  
  384.         /*  get most recently date of the dates pointed by duelst  */
  385.         currdate = duelst;
  386.         while( currdate) {
  387.             VOID sprintf(currdate->strtdate,DATEFORM,0,0,0,0,0,0);
  388.             recentdate(Head, currdate);
  389.             currdate = currdate->dnext;
  390.         }
  391.  
  392.         revno = extdate(Head);
  393.  
  394.         aprintf(out, ";\tselected revisions: %u", revno);
  395.         }
  396.  
  397.         afputc('\n',out);
  398.         if (descflag) {
  399.         aputs("description:\n", out);
  400.         getdesc(true);
  401.         }
  402.         if (revno) {
  403.         while (! (delta = readdeltalog())->selector  ||  --revno)
  404.             continue;
  405.         if (delta->next && countnumflds(delta->num)==2)
  406.             /* Read through delta->next to get its insertlns.  */
  407.             while (readdeltalog() != delta->next)
  408.             continue;
  409.         putrunk();
  410.         putree(Head);
  411.         }
  412.         aputs("=============================================================================\n",out);
  413.     } while (cleanup(),
  414.          ++argv, --argc >= 1);
  415.     Ofclose(out);
  416.     exitmain(exitstatus);
  417. }
  418.  
  419.     static void
  420. cleanup()
  421. {
  422.     if (nerror) exitstatus = EXIT_FAILURE;
  423.     Izclose(&finptr);
  424. }
  425.  
  426. #if RCS_lint
  427. #    define exiterr rlogExit
  428. #endif
  429.     exiting void
  430. exiterr()
  431. {
  432.     _exit(EXIT_FAILURE);
  433. }
  434.  
  435.  
  436.  
  437.     static void
  438. putrunk()
  439. /*  function:  print revisions chosen, which are in trunk      */
  440.  
  441. {
  442.     register struct hshentry const *ptr;
  443.  
  444.     for (ptr = Head;  ptr;  ptr = ptr->next)
  445.         putadelta(ptr, ptr->next, true);
  446. }
  447.  
  448.  
  449.  
  450.     static void
  451. putree(root)
  452.     struct hshentry const *root;
  453. /*   function: print delta tree (not including trunk) in reverse
  454.                order on each branch                                        */
  455.  
  456. {
  457.         if ( root == nil ) return;
  458.  
  459.         putree(root->next);
  460.  
  461.         putforest(root->branches);
  462. }
  463.  
  464.  
  465.  
  466.  
  467.     static void
  468. putforest(branchroot)
  469.     struct branchhead const *branchroot;
  470. /*   function:  print branches that has the same direct ancestor    */
  471. {
  472.  
  473.         if ( branchroot == nil ) return;
  474.  
  475.         putforest(branchroot->nextbranch);
  476.  
  477.         putabranch(branchroot->hsh);
  478.         putree(branchroot->hsh);
  479. }
  480.  
  481.  
  482.  
  483.  
  484.     static void
  485. putabranch(root)
  486.     struct hshentry const *root;
  487. /*   function  :  print one branch     */
  488.  
  489. {
  490.  
  491.         if ( root == nil) return;
  492.  
  493.         putabranch(root->next);
  494.  
  495.         putadelta(root, root, false);
  496. }
  497.  
  498.  
  499.  
  500.  
  501.  
  502.     static void
  503. putadelta(node,editscript,trunk)
  504.     register struct hshentry const *node, *editscript;
  505.     int trunk;
  506. /*  function: Print delta node if node->selector is set.        */
  507. /*      editscript indicates where the editscript is stored     */
  508. /*      trunk indicated whether this node is in trunk           */
  509. {
  510.     static char emptych[] = EMPTYLOG;
  511.  
  512.     register FILE *out;
  513.     char const *s;
  514.     size_t n;
  515.     struct branchhead const *newbranch;
  516.     struct buf branchnum;
  517.     char datebuf[datesize];
  518.  
  519.     if (!node->selector)
  520.             return;
  521.  
  522.     out = stdout;
  523.     aprintf(out,
  524.         "----------------------------\nrevision %s", node->num
  525.     );
  526.         if ( node->lockedby )
  527.        aprintf(out, "\tlocked by: %s;", node->lockedby);
  528.  
  529.     aprintf(out, "\ndate: %s;  author: %s;  state: %s;",
  530.         date2str(node->date, datebuf),
  531.         node->author, node->state
  532.     );
  533.  
  534.         if ( editscript )
  535.            if(trunk)
  536.           aprintf(out, insDelFormat,
  537.                              editscript->deletelns, editscript->insertlns);
  538.            else
  539.           aprintf(out, insDelFormat,
  540.                              editscript->insertlns, editscript->deletelns);
  541.  
  542.         newbranch = node->branches;
  543.         if ( newbranch ) {
  544.        bufautobegin(&branchnum);
  545.        aputs("\nbranches:", out);
  546.            while( newbranch ) {
  547.         getbranchno(newbranch->hsh->num, &branchnum);
  548.         aprintf(out, "  %s;", branchnum.string);
  549.                 newbranch = newbranch->nextbranch;
  550.            }
  551.        bufautoend(&branchnum);
  552.         }
  553.  
  554.     afputc('\n', out);
  555.     s = node->log.string;
  556.     if (!(n = node->log.size)) {
  557.         s = emptych;
  558.         n = sizeof(emptych)-1;
  559.     }
  560.     awrite(s, n, out);
  561.     if (s[n-1] != '\n')
  562.         afputc('\n', out);
  563. }
  564.  
  565.  
  566.  
  567.  
  568.  
  569.     static struct hshentry const *
  570. readdeltalog()
  571. /*  Function : get the log message and skip the text of a deltatext node.
  572.  *           Return the delta found.
  573.  *             Assumes the current lexeme is not yet in nexttok; does not
  574.  *             advance nexttok.
  575.  */
  576. {
  577.         register struct  hshentry  * Delta;
  578.     struct buf logbuf;
  579.     struct cbuf cb;
  580.  
  581.     if (eoflex())
  582.         fatserror("missing delta log");
  583.         nextlex();
  584.     if (!(Delta = getnum()))
  585.         fatserror("delta number corrupted");
  586.     getkeystring(Klog);
  587.     if (Delta->log.string)
  588.         fatserror("duplicate delta log");
  589.     bufautobegin(&logbuf);
  590.     cb = savestring(&logbuf);
  591.     Delta->log = bufremember(&logbuf, cb.size);
  592.  
  593.         nextlex();
  594.     while (nexttok==ID && strcmp(NextString,Ktext)!=0)
  595.         ignorephrase();
  596.     getkeystring(Ktext);
  597.         Delta->insertlns = Delta->deletelns = 0;
  598.         if ( Delta != Head)
  599.                 getscript(Delta);
  600.         else
  601.                 readstring();
  602.     return Delta;
  603. }
  604.  
  605.  
  606.     static void
  607. getscript(Delta)
  608. struct    hshentry   * Delta;
  609. /*   function:  read edit script of Delta and count how many lines added  */
  610. /*              and deleted in the script                                 */
  611.  
  612. {
  613.         int ed;   /*  editor command  */
  614.     declarecache;
  615.     register RILE *fin;
  616.         register  int   c;
  617.     register unsigned long i;
  618.     struct diffcmd dc;
  619.  
  620.     fin = finptr;
  621.     setupcache(fin);
  622.     initdiffcmd(&dc);
  623.     while (0  <=  (ed = getdiffcmd(fin,true,(FILE *)0,&dc)))
  624.         if (!ed)
  625.                  Delta->deletelns += dc.nlines;
  626.         else {
  627.                  /*  skip scripted lines  */
  628.          i = dc.nlines;
  629.          Delta->insertlns += i;
  630.          cache(fin);
  631.          do {
  632.              for (;;) {
  633.             cacheget(c);
  634.             switch (c) {
  635.                 default:
  636.                 continue;
  637.                 case SDELIM:
  638.                 cacheget(c);
  639.                 if (c == SDELIM)
  640.                     continue;
  641.                 if (--i)
  642.                     unexpected_EOF();
  643.                 nextc = c;
  644.                 uncache(fin);
  645.                 return;
  646.                 case '\n':
  647.                 break;
  648.             }
  649.             break;
  650.              }
  651.              ++rcsline;
  652.          } while (--i);
  653.          uncache(fin);
  654.             }
  655. }
  656.  
  657.  
  658.  
  659.  
  660.  
  661.  
  662.  
  663.     static void
  664. exttree(root)
  665. struct hshentry  *root;
  666. /*  function: select revisions , starting with root             */
  667.  
  668. {
  669.     struct branchhead const *newbranch;
  670.  
  671.         if (root == nil) return;
  672.  
  673.     root->selector = extractdelta(root);
  674.     root->log.string = nil;
  675.         exttree(root->next);
  676.  
  677.         newbranch = root->branches;
  678.         while( newbranch ) {
  679.             exttree(newbranch->hsh);
  680.             newbranch = newbranch->nextbranch;
  681.         }
  682. }
  683.  
  684.  
  685.  
  686.  
  687.     static void
  688. getlocker(argv)
  689. char    * argv;
  690. /*   function : get the login names of lockers from command line   */
  691. /*              and store in lockerlist.                           */
  692.  
  693. {
  694.         register char c;
  695.         struct   lockers   * newlocker;
  696.         argv--;
  697.     while ((c = *++argv)==',' || c==' ' || c=='\t' || c=='\n' || c==';')
  698.         continue;
  699.         if (  c == '\0') {
  700.             lockerlist=nil;
  701.             return;
  702.         }
  703.  
  704.         while( c != '\0' ) {
  705.         newlocker = talloc(struct lockers);
  706.             newlocker->lockerlink = lockerlist;
  707.             newlocker->login = argv;
  708.             lockerlist = newlocker;
  709.         while ((c = *++argv) && c!=',' && c!=' ' && c!='\t' && c!='\n' && c!=';')
  710.         continue;
  711.             *argv = '\0';
  712.             if ( c == '\0' ) return;
  713.         while ((c = *++argv)==',' || c==' ' || c=='\t' || c=='\n' || c==';')
  714.         continue;
  715.         }
  716. }
  717.  
  718.  
  719.  
  720.     static void
  721. getauthor(argv)
  722. char   *argv;
  723. /*   function:  get the author's name from command line   */
  724. /*              and store in authorlist                   */
  725.  
  726. {
  727.         register    c;
  728.         struct     authors  * newauthor;
  729.  
  730.         argv--;
  731.     while ((c = *++argv)==',' || c==' ' || c=='\t' || c=='\n' || c==';')
  732.         continue;
  733.         if ( c == '\0' ) {
  734.         authorlist = talloc(struct authors);
  735.         authorlist->login = getusername(false);
  736.             authorlist->nextauthor  = nil;
  737.             return;
  738.         }
  739.  
  740.         while( c != '\0' ) {
  741.         newauthor = talloc(struct authors);
  742.             newauthor->nextauthor = authorlist;
  743.             newauthor->login = argv;
  744.             authorlist = newauthor;
  745.         while ((c = *++argv) && c!=',' && c!=' ' && c!='\t' && c!='\n' && c!=';')
  746.         continue;
  747.             * argv = '\0';
  748.             if ( c == '\0') return;
  749.         while ((c = *++argv)==',' || c==' ' || c=='\t' || c=='\n' || c==';')
  750.         continue;
  751.         }
  752. }
  753.  
  754.  
  755.  
  756.  
  757.     static void
  758. getstate(argv)
  759. char   * argv;
  760. /*   function :  get the states of revisions from command line  */
  761. /*               and store in statelist                         */
  762.  
  763. {
  764.         register  char  c;
  765.         struct    stateattri    *newstate;
  766.  
  767.         argv--;
  768.     while ((c = *++argv)==',' || c==' ' || c=='\t' || c=='\n' || c==';')
  769.         continue;
  770.         if ( c == '\0'){
  771.         warn("missing state attributes after -s options");
  772.             return;
  773.         }
  774.  
  775.         while( c != '\0' ) {
  776.         newstate = talloc(struct stateattri);
  777.             newstate->nextstate = statelist;
  778.             newstate->status = argv;
  779.             statelist = newstate;
  780.         while ((c = *++argv) && c!=',' && c!=' ' && c!='\t' && c!='\n' && c!=';')
  781.         continue;
  782.             *argv = '\0';
  783.             if ( c == '\0' ) return;
  784.         while ((c = *++argv)==',' || c==' ' || c=='\t' || c=='\n' || c==';')
  785.         continue;
  786.         }
  787. }
  788.  
  789.  
  790.  
  791.     static void
  792. trunclocks()
  793. /*  Function:  Truncate the list of locks to those that are held by the  */
  794. /*             id's on lockerlist. Do not truncate if lockerlist empty.  */
  795.  
  796. {
  797.     struct lockers const *plocker;
  798.         struct lock     * plocked,  * nextlocked;
  799.  
  800.         if ( (lockerlist == nil) || (Locks == nil)) return;
  801.  
  802.         /* shorten Locks to those contained in lockerlist */
  803.         plocked = Locks;
  804.         Locks = nil;
  805.         while( plocked != nil) {
  806.             plocker = lockerlist;
  807.             while((plocker != nil) && ( strcmp(plocker->login, plocked->login)!=0))
  808.                 plocker = plocker->lockerlink;
  809.             nextlocked = plocked->nextlock;
  810.             if ( plocker != nil) {
  811.                 plocked->nextlock = Locks;
  812.                 Locks = plocked;
  813.             }
  814.             plocked = nextlocked;
  815.         }
  816. }
  817.  
  818.  
  819.  
  820.     static void
  821. recentdate(root, pd)
  822.     struct hshentry const *root;
  823.     struct Datepairs *pd;
  824. /*  function:  Finds the delta that is closest to the cutoff date given by   */
  825. /*             pd among the revisions selected by exttree.                   */
  826. /*             Successively narrows down the interval given by pd,           */
  827. /*             and sets the strtdate of pd to the date of the selected delta */
  828. {
  829.     struct branchhead const *newbranch;
  830.  
  831.     if ( root == nil) return;
  832.     if (root->selector) {
  833.              if ( cmpnum(root->date, pd->strtdate) >= 0 &&
  834.                   cmpnum(root->date, pd->enddate) <= 0)
  835.         VOID strcpy(pd->strtdate, root->date);
  836.         }
  837.  
  838.         recentdate(root->next, pd);
  839.         newbranch = root->branches;
  840.         while( newbranch) {
  841.            recentdate(newbranch->hsh, pd);
  842.            newbranch = newbranch->nextbranch;
  843.     }
  844. }
  845.  
  846.  
  847.  
  848.  
  849.  
  850.  
  851.     static unsigned
  852. extdate(root)
  853. struct  hshentry        * root;
  854. /*  function:  select revisions which are in the date range specified     */
  855. /*             in duelst  and datelist, start at root                     */
  856. /* Yield number of revisions selected, including those already selected.  */
  857. {
  858.     struct branchhead const *newbranch;
  859.     struct Datepairs const *pdate;
  860.     unsigned revno;
  861.  
  862.     if (!root)
  863.         return 0;
  864.  
  865.         if ( datelist || duelst) {
  866.             pdate = datelist;
  867.             while( pdate ) {
  868.                 if ( (pdate->strtdate)[0] == '\0' || cmpnum(root->date,pdate->strtdate) >= 0){
  869.                    if ((pdate->enddate)[0] == '\0' || cmpnum(pdate->enddate,root->date) >= 0)
  870.                         break;
  871.                 }
  872.                 pdate = pdate->dnext;
  873.             }
  874.             if ( pdate == nil) {
  875.                 pdate = duelst;
  876.         for (;;) {
  877.            if (!pdate) {
  878.             root->selector = false;
  879.             break;
  880.            }
  881.                    if ( cmpnum(root->date, pdate->strtdate) == 0)
  882.                       break;
  883.                    pdate = pdate->dnext;
  884.                 }
  885.             }
  886.         }
  887.     revno = root->selector + extdate(root->next);
  888.  
  889.         newbranch = root->branches;
  890.         while( newbranch ) {
  891.        revno += extdate(newbranch->hsh);
  892.            newbranch = newbranch->nextbranch;
  893.         }
  894.     return revno;
  895. }
  896.  
  897.  
  898.  
  899.     static char
  900. extractdelta(pdelta)
  901.     struct hshentry const *pdelta;
  902. /*  function:  compare information of pdelta to the authorlist, lockerlist,*/
  903. /*             statelist, revlist and yield true if pdelta is selected.    */
  904.  
  905. {
  906.     struct lock const *plock;
  907.     struct stateattri const *pstate;
  908.     struct authors const *pauthor;
  909.     struct Revpairs const *prevision;
  910.     unsigned length;
  911.  
  912.     if ((pauthor = authorlist)) /* only certain authors wanted */
  913.         while (strcmp(pauthor->login, pdelta->author) != 0)
  914.         if (!(pauthor = pauthor->nextauthor))
  915.             return false;
  916.     if ((pstate = statelist)) /* only certain states wanted */
  917.         while (strcmp(pstate->status, pdelta->state) != 0)
  918.         if (!(pstate = pstate->nextstate))
  919.             return false;
  920.     if (lockflag) /* only locked revisions wanted */
  921.         for (plock = Locks;  ;  plock = plock->nextlock)
  922.         if (!plock)
  923.             return false;
  924.         else if (plock->delta == pdelta)
  925.             break;
  926.     if ((prevision = Revlst)) /* only certain revs or branches wanted */
  927.         for (;;) {
  928.                 length = prevision->numfld;
  929.         if (
  930.             countnumflds(pdelta->num) == length+(length&1) &&
  931.             0 <= compartial(pdelta->num, prevision->strtrev, length) &&
  932.             0 <= compartial(prevision->endrev, pdelta->num, length)
  933.         )
  934.              break;
  935.         if (!(prevision = prevision->rnext))
  936.             return false;
  937.             }
  938.     return true;
  939. }
  940.  
  941.  
  942.  
  943.     static void
  944. getdatepair(argv)
  945.    char   * argv;
  946. /*  function:  get time range from command line and store in datelist if    */
  947. /*             a time range specified or in duelst if a time spot specified */
  948.  
  949. {
  950.         register   char         c;
  951.         struct     Datepairs    * nextdate;
  952.     char const        * rawdate;
  953.     int                     switchflag;
  954.  
  955.         argv--;
  956.     while ((c = *++argv)==',' || c==' ' || c=='\t' || c=='\n' || c==';')
  957.         continue;
  958.         if ( c == '\0' ) {
  959.         warn("missing date/time after -d");
  960.             return;
  961.         }
  962.  
  963.         while( c != '\0' )  {
  964.         switchflag = false;
  965.         nextdate = talloc(struct Datepairs);
  966.             if ( c == '<' ) {   /*   case: -d <date   */
  967.                 c = *++argv;
  968.                 (nextdate->strtdate)[0] = '\0';
  969.         } else if (c == '>') { /* case: -d'>date' */
  970.         c = *++argv;
  971.         (nextdate->enddate)[0] = '\0';
  972.         switchflag = true;
  973.         } else {
  974.                 rawdate = argv;
  975.         while( c != '<' && c != '>' && c != ';' && c != '\0')
  976.              c = *++argv;
  977.                 *argv = '\0';
  978.         if ( c == '>' ) switchflag=true;
  979.         str2date(rawdate,
  980.              switchflag ? nextdate->enddate : nextdate->strtdate);
  981.         if ( c == ';' || c == '\0') {  /*  case: -d date  */
  982.             VOID strcpy(nextdate->enddate,nextdate->strtdate);
  983.                     nextdate->dnext = duelst;
  984.                     duelst = nextdate;
  985.             goto end;
  986.         } else {
  987.             /*   case:   -d date<  or -d  date>; see switchflag */
  988.             while ((c = *++argv) == ' ' || c=='\t' || c=='\n')
  989.             continue;
  990.             if ( c == ';' || c == '\0') {
  991.             /* second date missing */
  992.             if (switchflag)
  993.                 *nextdate->strtdate= '\0';
  994.             else
  995.                 *nextdate->enddate= '\0';
  996.             nextdate->dnext = datelist;
  997.             datelist = nextdate;
  998.             goto end;
  999.             }
  1000.                 }
  1001.             }
  1002.             rawdate = argv;
  1003.         while( c != '>' && c != '<' && c != ';' && c != '\0')
  1004.          c = *++argv;
  1005.             *argv = '\0';
  1006.         str2date(rawdate,
  1007.              switchflag ? nextdate->strtdate : nextdate->enddate);
  1008.             nextdate->dnext = datelist;
  1009.         datelist = nextdate;
  1010.      end:
  1011.         if ( c == '\0')  return;
  1012.         while ((c = *++argv) == ';' || c == ' ' || c == '\t' || c =='\n')
  1013.         continue;
  1014.         }
  1015. }
  1016.  
  1017.  
  1018.  
  1019.     static void
  1020. getnumericrev()
  1021. /*  function:  get the numeric name of revisions which stored in revlist  */
  1022. /*             and then stored the numeric names in Revlst                */
  1023. /*             if branchflag, also add default branch                     */
  1024.  
  1025. {
  1026.         struct  Revpairs        * ptr, *pt;
  1027.     unsigned n;
  1028.     struct buf s, e;
  1029.     char const *lrev;
  1030.     struct buf const *rstart, *rend;
  1031.  
  1032.         Revlst = nil;
  1033.         ptr = revlist;
  1034.     bufautobegin(&s);
  1035.     bufautobegin(&e);
  1036.         while( ptr ) {
  1037.         n = 0;
  1038.         rstart = &s;
  1039.         rend = &e;
  1040.  
  1041.         switch (ptr->numfld) {
  1042.  
  1043.           case 1: /* -r rev */
  1044.         if (expandsym(ptr->strtrev, &s)) {
  1045.             rend = &s;
  1046.             n = countnumflds(s.string);
  1047.             if (!n  &&  (lrev = tiprev())) {
  1048.             bufscpy(&s, lrev);
  1049.             n = countnumflds(lrev);
  1050.             }
  1051.                 }
  1052.         break;
  1053.  
  1054.           case 2: /* -r rev- */
  1055.         if (expandsym(ptr->strtrev, &s)) {
  1056.             bufscpy(&e, s.string);
  1057.             n = countnumflds(s.string);
  1058.             (n<2 ? e.string : strrchr(e.string,'.'))[0]  =  0;
  1059.                 }
  1060.         break;
  1061.  
  1062.           case 3: /* -r -rev */
  1063.         if (expandsym(ptr->endrev, &e)) {
  1064.             if ((n = countnumflds(e.string)) < 2)
  1065.             bufscpy(&s, ".1");
  1066.             else {
  1067.             bufscpy(&s, e.string);
  1068.             VOID strcpy(strrchr(s.string,'.'), ".1");
  1069.             }
  1070.                 }
  1071.         break;
  1072.  
  1073.           default: /* -r rev1-rev2 */
  1074.         if (
  1075.             expandsym(ptr->strtrev, &s)
  1076.             &&    expandsym(ptr->endrev, &e)
  1077.             &&    checkrevpair(s.string, e.string)
  1078.         ) {
  1079.             n = countnumflds(s.string);
  1080.             /* Swap if out of order.  */
  1081.             if (compartial(s.string,e.string,n) > 0) {
  1082.             rstart = &e;
  1083.             rend = &s;
  1084.             }
  1085.         }
  1086.         break;
  1087.         }
  1088.  
  1089.         if (n) {
  1090.         pt = ftalloc(struct Revpairs);
  1091.         pt->numfld = n;
  1092.         pt->strtrev = fstr_save(rstart->string);
  1093.         pt->endrev = fstr_save(rend->string);
  1094.                 pt->rnext = Revlst;
  1095.                 Revlst = pt;
  1096.         }
  1097.         ptr = ptr->rnext;
  1098.         }
  1099.         /* Now take care of branchflag */
  1100.     if (branchflag && (Dbranch||Head)) {
  1101.         pt = ftalloc(struct Revpairs);
  1102.         pt->strtrev = pt->endrev =
  1103.         Dbranch ? Dbranch : fstr_save(partialno(&s,Head->num,1));
  1104.         pt->rnext=Revlst; Revlst=pt;
  1105.         pt->numfld = countnumflds(pt->strtrev);
  1106.         }
  1107.     bufautoend(&s);
  1108.     bufautoend(&e);
  1109. }
  1110.  
  1111.  
  1112.  
  1113.     static int
  1114. checkrevpair(num1,num2)
  1115.     char const *num1, *num2;
  1116. /*  function:  check whether num1, num2 are legal pair,i.e.
  1117.     only the last field are different and have same number of
  1118.     fields( if length <= 2, may be different if first field)   */
  1119.  
  1120. {
  1121.     unsigned length = countnumflds(num1);
  1122.  
  1123.     if (
  1124.             countnumflds(num2) != length
  1125.         ||    2 < length  &&  compartial(num1, num2, length-1) != 0
  1126.     ) {
  1127.         error("invalid branch or revision pair %s : %s", num1, num2);
  1128.             return false;
  1129.         }
  1130.  
  1131.         return true;
  1132. }
  1133.  
  1134.  
  1135.  
  1136.     static void
  1137. getrevpairs(argv)
  1138. register     char    * argv;
  1139. /*  function:  get revision or branch range from command line, and   */
  1140. /*             store in revlist                                      */
  1141.  
  1142. {
  1143.         register    char    c;
  1144.         struct      Revpairs  * nextrevpair;
  1145.     int separator;
  1146.  
  1147.     c = *argv;
  1148.  
  1149.     /* Support old ambiguous '-' syntax; this will go away.  */
  1150.     if (strchr(argv,':'))
  1151.         separator = ':';
  1152.     else {
  1153.         if (strchr(argv,'-')  &&  VERSION(5) <= RCSversion)
  1154.         warn("`-' is obsolete in `-r%s'; use `:' instead", argv);
  1155.         separator = '-';
  1156.     }
  1157.  
  1158.     for (;;) {
  1159.         while (c==' ' || c=='\t' || c=='\n')
  1160.         c = *++argv;
  1161.         nextrevpair = talloc(struct Revpairs);
  1162.             nextrevpair->rnext = revlist;
  1163.             revlist = nextrevpair;
  1164.         nextrevpair->numfld = 1;
  1165.         nextrevpair->strtrev = argv;
  1166.         for (;;  c = *++argv) {
  1167.         switch (c) {
  1168.             default:
  1169.             continue;
  1170.             case '\0': case ' ': case '\t': case '\n':
  1171.             case ',': case ';':
  1172.             break;
  1173.             case ':': case '-':
  1174.             if (c == separator)
  1175.                 break;
  1176.             continue;
  1177.         }
  1178.         break;
  1179.         }
  1180.         *argv = '\0';
  1181.         while (c==' ' || c=='\t' || c=='\n')
  1182.         c = *++argv;
  1183.         if (c == separator) {
  1184.         while ((c = *++argv) == ' ' || c == '\t' || c =='\n')
  1185.             continue;
  1186.         nextrevpair->endrev = argv;
  1187.         for (;;  c = *++argv) {
  1188.             switch (c) {
  1189.             default:
  1190.                 continue;
  1191.             case '\0': case ' ': case '\t': case '\n':
  1192.             case ',': case ';':
  1193.                 break;
  1194.             case ':': case '-':
  1195.                 if (c == separator)
  1196.                 continue;
  1197.                 break;
  1198.             }
  1199.             break;
  1200.         }
  1201.         *argv = '\0';
  1202.         while (c==' ' || c=='\t' || c =='\n')
  1203.             c = *++argv;
  1204.         nextrevpair->numfld =
  1205.             !nextrevpair->endrev[0] ? 2 /* -rrev- */ :
  1206.             !nextrevpair->strtrev[0] ? 3 /* -r-rev */ :
  1207.             4 /* -rrev1-rev2 */;
  1208.             }
  1209.         if (!c)
  1210.         break;
  1211.         if (c!=',' && c!=';')
  1212.         error("missing `,' near `%c%s'", c, argv+1);
  1213.     }
  1214. }
  1215.