home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OS9000 / APPS / rcs.lzh / rcs1 / rcsmerge.c < prev    next >
Text File  |  1996-04-20  |  8KB  |  234 lines

  1. /*
  2.  *                       rcsmerge operation
  3.  */
  4. #ifndef lint
  5. static char rcsid[]=
  6. "$Id: rcsmerge.c_v 1.1 93/04/02 01:35:58 hiro Exp $ Purdue CS";
  7. #endif
  8. /*****************************************************************************
  9.  *                       join 2 revisions with respect to a third
  10.  *****************************************************************************
  11.  */
  12.  
  13. /* Copyright (C) 1982, 1988, 1989 Walter Tichy
  14.    Distributed under license by the Free Software Foundation, Inc.
  15.  
  16. This file is part of RCS.
  17.  
  18. RCS is free software; you can redistribute it and/or modify
  19. it under the terms of the GNU General Public License as published by
  20. the Free Software Foundation; either version 1, or (at your option)
  21. any later version.
  22.  
  23. RCS is distributed in the hope that it will be useful,
  24. but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  26. GNU General Public License for more details.
  27.  
  28. You should have received a copy of the GNU General Public License
  29. along with RCS; see the file COPYING.  If not, write to
  30. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  31.  
  32. Report problems and direct all questions to:
  33.  
  34.     rcs-bugs@cs.purdue.edu
  35.  
  36. */
  37.  
  38.  
  39.  
  40. /* $Log:    rcsmerge.c_v $
  41.  * Revision 1.1  93/04/02  01:35:58  hiro
  42.  * Initial revision
  43.  * 
  44.  * Revision 1.1  90/07/19  15:22:12  momo
  45.  * Initial revision
  46.  * 
  47.  * Revision 4.5  89/05/01  15:13:16  narten
  48.  * changed copyright header to reflect current distribution rules
  49.  * 
  50.  * Revision 4.4  88/11/08  12:00:47  narten
  51.  * changes from  eggert@sm.unisys.com (Paul Eggert)
  52.  * 
  53.  * Revision 4.4  88/08/09  19:13:13  eggert
  54.  * Beware merging into a readonly file.
  55.  * Beware merging a revision to itself (no change).
  56.  * Use execv(), not system(); yield exit status like diff(1)'s.
  57.  * 
  58.  * Revision 4.3  87/10/18  10:38:02  narten
  59.  * Updating version numbers. Changes relative to version 1.1 
  60.  * actually relative to 4.1
  61.  * 
  62.  * Revision 1.3  87/09/24  14:00:31  narten
  63.  * Sources now pass through lint (if you ignore printf/sprintf/fprintf 
  64.  * warnings)
  65.  * 
  66.  * Revision 1.2  87/03/27  14:22:36  jenkins
  67.  * Port to suns
  68.  * 
  69.  * Revision 1.1  84/01/23  14:50:36  kcs
  70.  * Initial revision
  71.  * 
  72.  * Revision 4.1  83/03/28  11:14:57  wft
  73.  * Added handling of default branch.
  74.  * 
  75.  * Revision 3.3  82/12/24  15:29:00  wft
  76.  * Added call to catchsig().
  77.  *
  78.  * Revision 3.2  82/12/10  21:32:02  wft
  79.  * Replaced getdelta() with gettree(); improved error messages.
  80.  *
  81.  * Revision 3.1  82/11/28  19:27:44  wft
  82.  * Initial revision.
  83.  *
  84.  */
  85. #include "rcsbase.h"
  86. #ifndef lint
  87. static char rcsbaseid[] = RCSBASE;
  88. #endif
  89. static char co[] = CO;
  90. static char merge[] = MERGE;
  91.  
  92. extern int  cleanup();              /* cleanup after signals                */
  93. extern char * mktempfile();         /*temporary file name generator         */
  94. extern struct hshentry * genrevs(); /*generate delta numbers                */
  95. extern int  nerror;                 /*counter for errors                    */
  96.  
  97. #if defined(MSDOS) || defined(OSK)
  98. extern char *getmpdir();
  99. char    tmpdir[NCPPN];
  100. #endif /* MSODS */
  101.  
  102. char *RCSfilename;
  103. char *workfilename;
  104. char * temp1file, * temp2file;
  105.  
  106. main (argc, argv)
  107. int argc; char **argv;
  108. {
  109.         char * cmdusage;
  110.         int  revnums; /* counter for revision numbers given */
  111.         int tostdout;
  112.     int nochange;
  113.         char * rev1, * rev2; /*revision numbers*/
  114.     char commarg[revlength+3];
  115.         char numericrev[revlength];   /* holds expanded revision number     */
  116.         struct hshentry * gendeltas[hshsize];/*stores deltas to be generated*/
  117.         struct hshentry * target;
  118.  
  119.         catchints();
  120.         cmdid = "rcsmerge";
  121.         cmdusage = "command format:\n    rcsmerge -p -rrev1 -rrev2 file\n    rcsmerge -p -rrev1 file";
  122.     revnums=0;tostdout=false;nochange=false;
  123.  
  124.         while (--argc,++argv, argc>=1 && ((*argv)[0] == '-')) {
  125.                 switch ((*argv)[1]) {
  126.                 case 'p':
  127.                         tostdout=true;
  128.                         /* falls into -r */
  129.                 case 'r':
  130.                         if ((*argv)[2]!='\0') {
  131.                             if (revnums==0) {
  132.                                     rev1= *argv+2; revnums=1;
  133.                             } elif (revnums==1) {
  134.                                     rev2= *argv+2; revnums=2;
  135.                             } else {
  136.                                     faterror("too many revision numbers");
  137.                             }
  138.                         } /* do nothing for empty -r or -p */
  139.                         break;
  140.  
  141.                 default:
  142.                         faterror("unknown option: %s\n%s", *argv,cmdusage);
  143.                 };
  144.         } /* end of option processing */
  145.  
  146.         if (argc<1) faterror("No input file\n%s",cmdusage);
  147.         if (revnums<1) faterror("no base revision number given");
  148.  
  149. #if defined(MSDOS) || defined(OSK)
  150.     strcpy( tmpdir, gettmpdir() );
  151. #endif /* MSDOS */
  152.  
  153.         /* now handle all filenames */
  154.  
  155.         if (pairfilenames(argc,argv,true,false)==1) {
  156.  
  157.                 if (argc>2 || (argc==2&&argv[1]!=nil))
  158.                         warn("too many arguments");
  159.                 diagnose("RCS file: %s",RCSfilename);
  160.         if (!(access(workfilename,tostdout?4:6)==0))
  161.             nowork();
  162.  
  163.                 if (!trysema(RCSfilename,false)) goto end; /* give up */
  164.  
  165.                 gettree();  /* reads in the delta tree */
  166.  
  167.                 if (Head==nil) faterror("no revisions present");
  168.  
  169.  
  170.                 if (!expandsym(rev1,numericrev)) goto end;
  171.                 if (!(target=genrevs(numericrev, (char *)nil, (char *)nil, (char *)nil,gendeltas))) goto end;
  172.                 rev1=target->num;
  173.                 if (revnums==1)  /*get default for rev2 */
  174.                         rev2=Dbranch!=nil?Dbranch->num:Head->num;
  175.                 if (!expandsym(rev2,numericrev)) goto end;
  176.                 if (!(target=genrevs(numericrev, (char *)nil, (char *)nil, (char *)nil,gendeltas))) goto end;
  177.                 rev2=target->num;
  178.  
  179.         if (strcmp(rev1,rev2) == 0) {
  180.             diagnose("Merging revision %s to itself (no change)",
  181.                 rev1
  182.             );
  183.             nochange = true;
  184.             if (tostdout) {
  185.                 FILE *w = fopen(workfilename,"r");
  186.                 if (w==NULL)
  187.                     nowork();
  188.                 fastcopy(w,stdout);
  189.             }
  190.             goto end;
  191.         }
  192.  
  193. #if defined(MSDOS) || defined(OSK)
  194.                 temp1file=mktempfile(tmpdir,TMPFILE1);
  195.                 temp2file=mktempfile(tmpdir,TMPFILE2);
  196. #else
  197.                 temp1file=mktempfile("/tmp/",TMPFILE1);
  198.                 temp2file=mktempfile("/tmp/",TMPFILE2);
  199. #endif /* MSDOS */
  200.  
  201.                 diagnose("retrieving revision %s",rev1);
  202.                 VOID sprintf(commarg,"-p%s",rev1);
  203.                 if (run((char*)nil,temp1file, co,"-q",commarg,RCSfilename,(char*)nil)){
  204.                         faterror("co failed");
  205.                 }
  206.                 diagnose("retrieving revision %s",rev2);
  207.                 VOID sprintf(commarg,"-p%s",rev2);
  208.                 if (run((char*)nil,temp2file, co,"-q",commarg,RCSfilename,(char*)nil)){
  209.                         faterror("co failed");
  210.                 }
  211.                 diagnose("Merging differences between %s and %s into %s%s",
  212.                          rev1, rev2, workfilename,
  213.                          tostdout?"; result to stdout":"");
  214.  
  215.                 if (
  216.               tostdout
  217.             ? run((char*)nil,(char*)nil,merge,"-p",workfilename,temp1file,temp2file,workfilename,rev2,(char*)nil)
  218.             : run((char*)nil,(char*)nil,merge,     workfilename,temp1file,temp2file,workfilename,rev2,(char*)nil)) {
  219.                         faterror("merge failed");
  220.                 }
  221.         }
  222.  
  223. end:
  224.         VOID cleanup();
  225.     exit(2*(nerror!=0) + nochange);
  226.  
  227. }
  228.  
  229.  
  230. nowork()
  231. {
  232.     faterror("Can't open %s",workfilename);
  233. }
  234.