home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / vers_con / dosrcs / rcsrev.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-18  |  23.9 KB  |  725 lines

  1. /*
  2.  *                     RCS revision number handling
  3.  */
  4. #ifndef lint
  5. static char rcsid[]= "$Id: rcsrev.c,v 5.3 90/07/16 21:40:12 lfk Release $ Purdue CS";
  6. #endif
  7.  
  8. /* Copyright (C) 1982, 1988, 1989 Walter Tichy
  9.    Distributed under license by the Free Software Foundation, Inc.
  10.  
  11. This file is part of RCS.
  12.  
  13. RCS is free software; you can redistribute it and/or modify
  14. it under the terms of the GNU General Public License as published by
  15. the Free Software Foundation; either version 1, or (at your option)
  16. any later version.
  17.  
  18. RCS is distributed in the hope that it will be useful,
  19. but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21. GNU General Public License for more details.
  22.  
  23. You should have received a copy of the GNU General Public License
  24. along with RCS; see the file COPYING.  If not, write to
  25. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  26.  
  27. Report problems and direct all questions to:
  28.  
  29.     rcs-bugs@cs.purdue.edu
  30.  
  31. */
  32.  
  33.  
  34.  
  35.  
  36. /* $Log:    rcsrev.c,v $
  37.  * Revision 5.3  90/07/16  21:40:12  lfk
  38.  * checkin for release compilation
  39.  * 
  40.  * Revision 5.2  90/07/15  11:34:46  ROOT_DOS
  41.  * DOS version of RCS 4.0 checked in for MODS
  42.  * by lfk@athena.mit.edu
  43.  * Also update to MSC 6.0
  44.  * 
  45.  * Revision 4.5  89/05/01  15:13:22  narten
  46.  * changed copyright header to reflect current distribution rules
  47.  * 
  48.  * Revision 4.4  87/12/18  11:45:22  narten
  49.  * more lint cleanups. Also, the NOTREACHED comment is no longer necessary, 
  50.  * since there's now a return value there with a value. (Guy Harris)
  51.  * 
  52.  * Revision 4.3  87/10/18  10:38:42  narten
  53.  * Updating version numbers. Changes relative to version 1.1 actually 
  54.  * relative to 4.1
  55.  * 
  56.  * Revision 1.3  87/09/24  14:00:37  narten
  57.  * Sources now pass through lint (if you ignore printf/sprintf/fprintf 
  58.  * warnings)
  59.  * 
  60.  * Revision 1.2  87/03/27  14:22:37  jenkins
  61.  * Port to suns
  62.  * 
  63.  * Revision 1.1  84/01/23  14:50:37  kcs
  64.  * Initial revision
  65.  * 
  66.  * Revision 4.1  83/03/25  21:10:45  wft
  67.  * Only changed $Header to $Id.
  68.  * 
  69.  * Revision 3.4  82/12/04  13:24:08  wft
  70.  * Replaced getdelta() with gettree().
  71.  *
  72.  * Revision 3.3  82/11/28  21:33:15  wft
  73.  * fixed compartial() and compnum() for nil-parameters; fixed nils
  74.  * in error messages. Testprogram output shortenend.
  75.  *
  76.  * Revision 3.2  82/10/18  21:19:47  wft
  77.  * renamed compnum->cmpnum, compnumfld->cmpnumfld,
  78.  * numericrevno->numricrevno.
  79.  *
  80.  * Revision 3.1  82/10/11  19:46:09  wft
  81.  * changed expandsym() to check for source==nil; returns zero length string
  82.  * in that case.
  83.  */
  84.  
  85.  
  86.  
  87. /*
  88. #define REVTEST
  89. /* version REVTEST is for testing the routines that generate a sequence
  90.  * of delta numbers needed to regenerate a given delta.
  91.  */
  92.  
  93. #include "rcsbase.h"
  94.  
  95. extern FILE * finptr;   /* RCS input file */
  96. extern char * getid();
  97. extern struct hshentry * getnum();
  98. extern int    getkey();
  99. extern int    getlex();
  100.  
  101. extern char * getkeyval();
  102. struct hshentry * genbranch(); /* forward */
  103.  
  104.  
  105.  
  106. int countnumflds(s)
  107. char * s;
  108. /* Given a pointer s to a dotted number (date or revision number),
  109.  * countnumflds returns the number of digitfields in s.
  110.  */
  111. {       register char * sp;
  112.         register int    count;
  113.         if ((sp=s)==nil) return(0);
  114.         if (*sp == '\0') return(0);
  115.         count = 1;
  116.         while (*sp) {
  117.                 if (*sp++ == '.') count++;
  118.         }
  119.         if (*(--sp) == '.') count--; /*trailing periods don't count*/
  120.         return(count);
  121. }
  122.  
  123. getbranchno(revno,branchno)
  124. char * revno, * branchno;
  125. /* Given a non-nil revision number revno, getbranchno copies the number of the branch
  126.  * on which revno is into branchnumber. If revno itself is a branch number,
  127.  * it is copied unchanged.
  128.  */
  129. {
  130.         register int i, numflds;
  131.         register char * tp, * sp;
  132.  
  133.         numflds=countnumflds(revno);
  134.         if (numflds%2 == 1)
  135.                 VOID strcpy(branchno,revno);
  136.         else {
  137.                 sp=revno; tp=branchno;
  138.                 for (i=1;i<numflds;i++) {
  139.                         while(*sp!='.') *tp++ = *sp++;
  140.                         *tp++ = *sp++;
  141.                 }
  142.                 *(tp-1)='\0';
  143.         }
  144. }
  145.  
  146.  
  147.  
  148. int cmpnum(num1, num2)
  149. char * num1, * num2;
  150. /* compares the two dotted numbers num1 and num2 lexicographically
  151.  * by field. Individual fields are compared numerically.
  152.  * returns <0, 0, >0 if num1<num2, num1==num2, and num1>num2, resp.
  153.  * omitted fields are assumed to be higher than the existing ones.
  154. */
  155. {
  156.         register char * s1, *s2;
  157.         register int n1, n2;
  158.  
  159.         s1=num1==nil?"":num1;
  160.         s2=num2==nil?"":num2;
  161.  
  162.         do {
  163.                 n1 = 0;
  164.                 while (('0' <= *s1) && (*s1 <= '9')) {
  165.                         n1 = n1*10 + (*s1 - '0');
  166.                         s1++;
  167.                 }
  168.                 /* skip '.' */
  169.                 if (*s1=='.') s1++;
  170.  
  171.                 n2 = 0;
  172.                 while (('0' <= *s2) && (*s2 <= '9')) {
  173.                         n2 = n2*10 + (*s2 - '0');
  174.                         s2++;
  175.                 }
  176.                 /* skip '.' */
  177.                 if (*s2=='.') s2++;
  178.  
  179.         } while ((n1==n2) && (*s1!='\0') && (*s2!='\0'));
  180.  
  181.         if (((*s1=='\0') && (*s2=='\0')) || (n1!=n2))
  182.                 return (n1 - n2);
  183.         /*now n1==n2 and one of s1 or s2 is shorter*/
  184.         /*give precedence to shorter one*/
  185.         if (*s1=='\0') return 1;
  186.         else           return -1;
  187.  
  188. }
  189.  
  190.  
  191.  
  192. int cmpnumfld(num1, num2, fld)
  193. char * num1, * num2; int fld;
  194. /* compares the two dotted numbers at field fld and returns
  195.  * num1[fld]-num2[fld]. Assumes that num1 and num2 have at least fld fields.
  196. */
  197. {
  198.         register char * s1, *s2;
  199.         register int n1, n2;
  200.  
  201.         s1=num1; n1=fld-1;
  202.         /* skip fld-1 fields */
  203.         while (n1) {
  204.                 while(*s1 != '.') s1++;
  205.                 n1--; s1++;
  206.         }
  207.         s2 = num2; n2=fld-1;
  208.         while (n2) {
  209.                 while(*s2 != '.') s2++;
  210.                 n2--; s2++;
  211.         }
  212.         /* Don't put the above into a single loop! */
  213.         /* Now s1 and s2 point to the beginning of the respective fields */
  214.         /* compute numerical value and compare */
  215.         n1 = 0;
  216.         while (('0' <= *s1) && (*s1 <= '9')) {
  217.                 n1 = n1*10 + (*s1 - '0');
  218.                 s1++;
  219.         }
  220.         n2 = 0;
  221.         while (('0' <= *s2) && (*s2 <= '9')) {
  222.                 n2 = n2*10 + (*s2 - '0');
  223.                 s2++;
  224.         }
  225.         return (n1 - n2);
  226. }
  227.  
  228.  
  229. int compartial(num1, num2, length)
  230. char    * num1;
  231. char    * num2;
  232. int     length;
  233.  
  234. /*   compare the first "length" fields of two dot numbers;
  235.      the omitted field is considered to be larger than any number  */
  236. /*   restriction:  at least one number has length or more fields   */
  237.  
  238. {
  239.         register        char    *s1, *s2;
  240.         register        int     n1, n2;
  241.  
  242.  
  243.         s1 = num1;      s2 = num2;
  244.         if ( s1==nil || *s1 == '\0' ) return 1;
  245.         if ( s2==nil || *s2 == '\0' ) return -1;
  246.  
  247.         do {
  248.             n1 = 0;
  249.             while( ('0' <= *s1) && (*s1 <= '9') ) {
  250.                 n1 = n1 * 10 + (*s1 - '0') ;
  251.                 s1++;
  252.             }
  253.             if ( *s1 == '.' ) s1++;    /*  skip .   */
  254.  
  255.             n2 = 0;
  256.             while( ( '0' <= *s2) && ( *s2 <= '9' ) ) {
  257.                    n2 = n2 * 10 + ( *s2 - '0' ) ;
  258.                 s2++;
  259.             }
  260.             if (*s2 == '.') s2++;
  261.         }   while(  ( n1 == n2) && ((--length) != 0) &&
  262.                     ( *s1 != '\0') && (*s2 != '\0')  );
  263.  
  264.         if ( (n1 != n2) || (length == 0) ){
  265.                 return(n1-n2);   }
  266.  
  267.         if ( *s1 == '\0' ) return 1;
  268.         if ( *s2 == '\0' ) return -1;
  269.     VOID fprintf(stderr, "RCS Internal error, routine: compartial\n");
  270.     return(0);
  271. }
  272.  
  273.  
  274.  
  275. incnum(onum,nnum)
  276. char * onum, *nnum;
  277. /* increments the last field of revision number onum by one and
  278.  * places the result into nnum
  279.  */
  280. {
  281.         register char * sp, *tp;
  282.         register int i;
  283.  
  284.         sp = onum; tp = nnum;
  285.         for (i=countnumflds(onum)-1; i>0; i--) {
  286.                 while (*sp != '.') *tp++ = *sp++;
  287.                 *tp++ = *sp++;  /* copy dot also */
  288.         }
  289.         VOID sprintf(tp,"%d",atoi(sp)+1);
  290. }
  291.  
  292.  
  293. char * partialno(rev1,rev2,length)
  294. char * rev1, * rev2; register int length;
  295. /* Function: Copies length fields of revision number rev2 into rev1.
  296.  * returns rev1.
  297.  */
  298. {       register char * r1,* r2;
  299.  
  300.         r1=rev1; r2=rev2;
  301.         while (length) {
  302.                 while(*r2 != '.' && *r2!='\0') *r1++ = *r2++;
  303.                 *r1++ = *r2++;
  304.                 length--;
  305.         }
  306.         /* eliminate last '.'*/
  307.         *(r1-1)='\0';
  308.         return rev1;
  309. }
  310.  
  311.  
  312.  
  313. char * getancestor(r1, r2, r3)
  314. char * r1, *r2, *r3;
  315. /* function: finds the common ancestor of r1 and r2 and
  316.  * places it into r3.
  317.  * returns r3 if successful, false otherwise.
  318.  * works reliably only if r1 and r2 are not branch numbers.
  319.  */
  320. {       int l1, l2, l3;
  321.         char t1[revlength], t2[revlength];
  322.  
  323.         l1=countnumflds(r1); l2=countnumflds(r2);
  324.         if ((l1<=2 && l2<=2)||(cmpnum(r1,r2)==0)) {
  325.                 /* on main trunk or identical */
  326.                 error("Common ancestor of %s and %s undefined.", r1, r2);
  327.                 return false;
  328.         }
  329.  
  330.         l3=0;
  331.         while ((cmpnumfld(r1, r2, l3+1)==0) && (cmpnumfld(r1, r2, l3+2)==0)){
  332.                 l3=l3+2;
  333.         }
  334.         /* This will terminate since r1 and r2 are not the same; see above*/
  335.         if (l3==0) {
  336.                 /* no common prefix. Common ancestor on main trunk. */
  337.                 VOID partialno(t1,r1,l1>2?2:l1); VOID partialno(t2,r2,l2>2?2:l2);
  338.                 if (cmpnum(t1,t2)<0)
  339.                         VOID strcpy(r3,t1);
  340.                 else    VOID strcpy(r3,t2);
  341.                 if ((cmpnum(r3,r1)==0)||(cmpnum(r3,r2)==0)) {
  342.                         error("Ancestor for %s and %s undefined.",r1,r2);
  343.                         return false;
  344.                 }
  345.                 return r3;
  346.         } else {
  347.                if (cmpnumfld(r1,r2,l3+1)==0) {
  348.                         error("Ancestor for %s and %s undefined.",r1,r2);
  349.                         return false;
  350.                 }
  351.                 return(partialno(r3,r1,l3));
  352.         }
  353. }
  354.  
  355.  
  356.  
  357.  
  358. struct hshentry * genrevs(revno,date,author,state,store)
  359. char * revno, * date, * author, * state;
  360. struct hshentry * * store;
  361. /* Function: finds the deltas needed for reconstructing the
  362.  * revision given by revno, date, author, and state, and stores pointers
  363.  * to these deltas into an array whose starting address is given by store.
  364.  * The last pointer stored is nil. The last delta (target delta) is returned.
  365.  * If the proper delta could not be found, nil is returned.
  366.  */
  367. {
  368.         int length;
  369.         register struct hshentry * next;
  370.         int result;
  371.         char * branchnum;
  372.         char t[revlength];
  373.  
  374.         if (Head == nil) {
  375.                 error("RCSfile empty.");
  376.                 return nil;
  377.         }
  378.  
  379.         length = countnumflds(revno);
  380.         next=Head;
  381.  
  382.         if (length >= 1) {
  383.                 /* at least one field; find branch exactly */
  384.                 while ((next!=nil) &&
  385.                        ((result=cmpnumfld(revno,next->num,1))<0)) {
  386.                         /*puts(next->num);*/
  387.                         *store++ = next;
  388.                         next = next->next;
  389.                 }
  390.  
  391.                 if (next==nil) {error("Branch number %s too low.",partialno(t,revno,1));return nil;}
  392.                 if (result>0)  {error("Branch number %s not present.",partialno(t,revno,1));return nil;}
  393.         }
  394.         if (length<=1){
  395.                 /* pick latest one on given branch */
  396.                 branchnum = next->num; /* works even for empty revno*/
  397.                 while ((next!=nil) &&
  398.                        (cmpnumfld(branchnum,next->num,1)==0) &&
  399.                        !(
  400.                         (date==nil?1:(cmpnum(date,next->date)>=0)) &&
  401.                         (author==nil?1:(strcmp(author,next->author)==0)) &&
  402.                         (state ==nil?1:(strcmp(state, next->state) ==0))
  403.                         )
  404.                        )
  405.                 {       /*puts(next->num);*/
  406.                         *store ++ = next;
  407.                         next=next->next;
  408.                 }
  409.                 if ((next==nil) ||
  410.                     (cmpnumfld(branchnum,next->num,1)!=0))/*overshot*/ {
  411.                         error("Cannot find revision on branch %s with a date before %s, author %s, and state %s.",
  412.                                 length==0?partialno(t,branchnum,1):revno,date==nil?"<now>":date,
  413.                                 author==nil?"<any>":author, state==nil?"<any>":state);
  414.                         return nil;
  415.                 } else {
  416.                         /*puts(next->num);*/
  417.                         *store++ = next;
  418.                 }
  419.                 *store = nil;
  420.                 return next;
  421.         }
  422.  
  423.         /* length >=2 */
  424.         /* find revision; may go low if length==2*/
  425.         while ((next!=nil) &&
  426.                ((result =cmpnumfld(revno,next->num,2)) <0) &&
  427.                (cmpnumfld(revno,next->num,1)==0) ) {
  428.                 /*puts(next->num);*/
  429.                 *store++ = next;
  430.                 next = next->next;
  431.         }
  432.  
  433.         if ((next==nil) || (cmpnumfld(revno,next->num,1)!=0)) {
  434.                 error("Revision number %s too low.",partialno(t,revno,2));
  435.                 return nil;
  436.         }
  437.         if ((length>2) && (result!=0)) {
  438.                 error("Revision %s not present.",partialno(t,revno,2));
  439.                 return nil;
  440.         }
  441.  
  442.         /* print last one */
  443.         /*puts(next->num);*/
  444.         *store++ = next;
  445.  
  446.         if (length>2)
  447.                 return genbranch(next,revno,length,date,author,state,store);
  448.         else { /* length == 2*/
  449.                 if ((date!=nil) && (cmpnum(date,next->date)<0)){
  450.                         error("Revision %s has date %s.",next->num, next->date);
  451.                         return nil;
  452.                 }
  453.                 if ((author!=nil)&&(strcmp(author,next->author)!=0)) {
  454.                         error("Revision %s has author %s.",next->num,next->author);
  455.                         return nil;
  456.                 }
  457.                 if ((state!=nil)&&(strcmp(state,next->state)!=0)) {
  458.                         error("Revision %s has state %s.",next->num,
  459.                                next->state==nil?"<empty>":next->state);
  460.                         return nil;
  461.                 }
  462.                 *store=nil;
  463.                 return next;
  464.         }
  465. }
  466.  
  467.  
  468.  
  469.  
  470. struct hshentry * genbranch(bpoint, revno, length,date,author,state,store)
  471. struct hshentry * bpoint;
  472. char * revno; int length;
  473. char * date, * author, * state;
  474. struct hshentry ** store;
  475. /* Function: given a branchpoint, a revision number, date, author, and state,
  476.  * genbranch finds the deltas necessary to reconstruct the given revision
  477.  * from the branch point on.
  478.  * Pointers to the found deltas are stored in an array beginning with store.
  479.  * revno must be on a side branch.
  480.  * return nil on error
  481.  */
  482. {
  483.         int field;
  484.         register struct hshentry * next, * trail;
  485.         register struct branchhead * bhead;
  486.         int result;
  487.         char t[revlength];
  488.  
  489.         bhead = bpoint->branches;
  490.  
  491.         for (field=3; field<=length; field=field+2) {
  492.  
  493.                 if (bhead==nil) {error("No side branches present for %s.",partialno(t,revno,field-1));return nil;}
  494.  
  495.                 /*find branch head*/
  496.                 /*branches are arranged in increasing order*/
  497.                 while ((bhead!=nil) &&
  498.                        ((result=cmpnumfld(revno,bhead->hsh->num,field))>0)) {
  499.                         bhead = bhead->nextbranch;
  500.                 }
  501.  
  502.                 if (bhead==nil) {error("Branch number %s too high.",partialno(t,revno,field));return nil;}
  503.                 if (result<0)   {error("Branch number %s not present.",partialno(t,revno,field));return nil;}
  504.  
  505.                 next = bhead->hsh;
  506.                 if (length==field) {
  507.                         /* pick latest one on that branch */
  508.                         trail=nil;
  509.                         do { if ((date==nil?1:(cmpnum(date,next->date)>=0)) &&
  510.                                  (author==nil?1:(strcmp(author,next->author)==0)) &&
  511.                                  (state ==nil?1:(strcmp(state, next->state) ==0))
  512.                              ) trail = next;
  513.                              next=next->next;
  514.                         } while (next!=nil);
  515.  
  516.                         if (trail==nil) {
  517.                              error("Cannot find revision on branch %s with a date before %s, author %s, and state %s.",
  518.                                         revno, date==nil?"<now>":date,
  519.                                         author==nil?"<any>":author, state==nil?"<any>":state);
  520.                              return nil;
  521.                         } else { /* print up to last one suitable */
  522.                              next = bhead->hsh;
  523.                              while (next!=trail) {
  524.                                   /*puts(next->num);*/
  525.                                   *store++ = next;
  526.                                   next=next->next;
  527.                              }
  528.                              /*puts(next->num);*/
  529.                              *store++ = next;
  530.                         }
  531.                         *store = nil;
  532.                         return next;
  533.                 }
  534.  
  535.                 /* length > field */
  536.                 /* find revision */
  537.                 /* check low */
  538.                 if (cmpnumfld(revno,next->num,field+1)<0) {
  539.                         error("Revision number %s too low.",partialno(t,revno,field+1));
  540.                         return(nil);
  541.                 }
  542.                 do {    /*puts(next->num);*/
  543.                         *store++ = next;
  544.                         trail = next;
  545.                         next = next->next;
  546.                 } while ((next!=nil) &&
  547.                        (cmpnumfld(revno,next->num,field+1) >=0));
  548.  
  549.                 if ((length>field+1) &&  /*need exact hit */
  550.                     (cmpnumfld(revno,trail->num,field+1) !=0)){
  551.                         error("Revision %s not present.",partialno(t,revno,field+1));
  552.                         return(nil);
  553.                 }
  554.                 if (length == field+1) {
  555.                         if ((date!=nil) && (cmpnum(date,trail->date)<0)){
  556.                                 error("Revision %s has date %s.",trail->num, trail->date);
  557.                                 return nil;
  558.                         }
  559.                         if ((author!=nil)&&(strcmp(author,trail->author)!=0)) {
  560.                                 error("Revision %s has author %s.",trail->num,trail->author);
  561.                                 return nil;
  562.                         }
  563.                         if ((state!=nil)&&(strcmp(state,trail->state)!=0)) {
  564.                                 error("Revision %s has state %s.",trail->num,
  565.                                        trail->state==nil?"<empty>":trail->state);
  566.                                 return nil;
  567.                         }
  568.                 }
  569.                 bhead = trail->branches;
  570.  
  571.         }
  572.         * store = nil;
  573.         return trail;
  574. }
  575.  
  576.  
  577. char * lookupsym(id)
  578. char * id;
  579. /* Function: looks up id in the list of symbolic names starting
  580.  * with pointer SYMBOLS, and returns a pointer to the corresponding
  581.  * revision number. Returns nil if not present.
  582.  */
  583. {
  584.         register struct assoc * next;
  585.         next = Symbols;
  586.         while (next!=nil) {
  587.                 if (strcmp(id, next->symbol)==0)
  588.                         return(next->delta->num);
  589.                 else    next=next->nextassoc;
  590.         }
  591.         return nil;
  592. }
  593.  
  594. int expandsym(source, target)
  595. char * source, * target;
  596. /* Function: Source points to a revision number. Expandsym copies
  597.  * the number to target, but replaces all symbolic fields in the
  598.  * source number with their numeric values.
  599.  * A trailing '.' is omitted; leading zeroes are compressed.
  600.  * returns false on error;
  601.  */
  602. {       register char * sp, * tp, *bp;
  603.         char symbuf[30];
  604.         register enum tokens d;
  605.  
  606.         sp = source; tp=target;
  607.         if (sp == nil) { /*accept nil pointer as a legal value*/
  608.                 *tp='\0';
  609.                 return true;
  610.         }
  611.  
  612.         while (*sp != '\0') {
  613.                 if (ctab[*sp] == DIGIT) {
  614.                         if (*sp=='0') {
  615.                                 /* skip leading zeroes */
  616.                                 sp++;
  617.                                 while(*sp == '0') sp++;
  618.                                 if (*sp=='\0' || *sp=='.') *tp++ = '0'; /*single zero*/
  619.                         }
  620.                         while(ctab[*sp] == DIGIT) *tp++ = *sp++;
  621.                         if ((*sp == '\0') || ((*sp=='.')&&(*(sp+1)=='\0'))) {
  622.                                 *tp='\0'; return true;
  623.                         }
  624.                         if (*sp == '.') *tp++ = *sp++;
  625.                         else {
  626.                             error("Improper revision number: %s",source);
  627.                             *tp = '\0';
  628.                             return false;
  629.                         }
  630.                 } elsif (ctab[*sp] == LETTER) {
  631.                         bp = symbuf;
  632.                         do {    *bp++ = *sp++;
  633.                         } while(((d=ctab[*sp])==LETTER) || (d==DIGIT) ||
  634.                               (d==IDCHAR));
  635.                         *bp= '\0';
  636.                         bp=lookupsym(symbuf);
  637.                         if (bp==nil) {
  638.                                 error("Symbolic number %s is undefined.",symbuf);
  639.                                 *tp='\0';
  640.                                 return false;
  641.                         } else { /* copy number */
  642.                                 while (*tp++ = *bp++); /* copies the trailing \0*/
  643.                         }
  644.                         if ((*sp == '\0') || ((*sp=='.')&&(*(sp+1)=='\0')))
  645.                                 return true;
  646.                         if (*sp == '.')  {
  647.                                 *(tp-1) = *sp++;
  648.                         } else {
  649.                                 error("Improper revision number: %s",source);
  650.                                 return false;
  651.                         }
  652.                 }else {
  653.                         error("Improper revision number: %s", source);
  654.                         *tp = '\0';
  655.                         return false;
  656.                 }
  657.         }
  658.         *tp = '\0';
  659.         return true;
  660. }
  661.  
  662.  
  663.  
  664. #ifdef REVTEST
  665.  
  666. main(argc,argv)
  667. int argc; char * argv[];
  668. {
  669.         char symrevno[revlength];       /* used for input of revision numbers */
  670.         char numricrevno[revlength];
  671.         char author[20];
  672.         char state[20];
  673.         char date[20];
  674.         struct hshentry * gendeltas[hshsize/2];
  675.         struct hshentry * target;
  676.         int i;
  677.  
  678.         cmdid = "revtest";
  679.         if (argc<2) {
  680.                 VOID fputs("No input file\n",stderr);
  681.                 exit(-1);
  682.         }
  683.         if ((finptr=fopen(argv[1], "r")) == NULL) {
  684.                 faterror("Can't open input file %s\n",argv[1]);
  685.         }
  686.         Lexinit();
  687.         getadmin();
  688.  
  689.         gettree();
  690.  
  691.         getdesc(false);
  692.  
  693.         do {
  694.                 /* all output goes to stderr, to have diagnostics and       */
  695.                 /* errors in sequence.                                      */
  696.                 VOID fprintf(stderr,"\nEnter revision number or <return> or '.': ");
  697.                 if(gets(symrevno)==NULL) break;
  698.                 if (*symrevno == '.') break;
  699.                 VOID fprintf(stderr,"%s;\n",symrevno);
  700.                 expandsym(symrevno,numricrevno);
  701.                 VOID fprintf(stderr,"expanded number: %s; ",numricrevno);
  702.                 VOID fprintf(stderr,"Date: ");
  703.                 gets(date); VOID fprintf(stderr,"%s; ",date);
  704.                 VOID fprintf(stderr,"Author: ");
  705.                 gets(author);VOID fprintf(stderr,"%s; ",author);
  706.                 VOID fprintf(stderr,"State: ");
  707.                 gets(state); VOID fprintf(stderr, "%s;\n", state);
  708.                 target=genrevs(numricrevno,*date=='\0'?(char *)nil:date, *author=='\0'?(char *)nil:author,
  709.                               *state=='\0'?(char *)nil:state,gendeltas);
  710.                 if (target!=nil) {
  711.                         i=0;
  712.                         while (gendeltas[i]!=nil) {
  713.                                 VOID fprintf(stderr,"%s\n",gendeltas[i++]->num);
  714.                         }
  715.                 }
  716.         } while (true);
  717.         VOID fprintf(stderr,"done\n");
  718.  
  719. }
  720.  
  721. cleanup(){}
  722. /*dummy*/
  723.  
  724. #endif /* REVTEST */
  725.