1: /* 2: * rcsmerge operation 3: */ 4: static char rcsid[]= 5: "$Header: /usr/wft/RCS/SRC/RCS/rcsmerge.c,v 3.3 82/12/24 15:29:00 wft Exp $ Purdue CS"; 6: /***************************************************************************** 7: * join 2 revisions with respect to a third 8: ***************************************************************************** 9: * 10: * Copyright (C) 1982 by Walter F. Tichy 11: * Purdue University 12: * Computer Science Department 13: * West Lafayette, IN 47907 14: * 15: * All rights reserved. No part of this software may be sold or distributed 16: * in any form or by any means without the prior written permission of the 17: * author. 18: * Report problems and direct all inquiries to Tichy@purdue (ARPA net). 19: */ 20: 21: 22: /* $Log: rcsmerge.c,v $ 23: * Revision 3.3 82/12/24 15:29:00 wft 24: * Added call to catchsig(). 25: * 26: * Revision 3.2 82/12/10 21:32:02 wft 27: * Replaced getdelta() with gettree(); improved error messages. 28: * 29: * Revision 3.1 82/11/28 19:27:44 wft 30: * Initial revision. 31: * 32: */ 33: #include "rcsbase.h" 34: static char rcsbaseid[] = RCSBASE; 35: 36: extern int cleanup(); /* cleanup after signals */ 37: extern char * mktempfile(); /*temporary file name generator */ 38: extern struct hshentry * genrevs(); /*generate delta numbers */ 39: extern int nerror; /*counter for errors */ 40: 41: char *RCSfilename; 42: char *workfilename; 43: char * temp1file, * temp2file; 44: 45: main (argc, argv) 46: int argc; char **argv; 47: { 48: char * cmdusage; 49: char command[NCPPN+revlength+40]; 50: int revnums; /* counter for revision numbers given */ 51: int tostdout; 52: char * rev1, * rev2; /*revision numbers*/ 53: char numericrev[revlength]; /* holds expanded revision number */ 54: struct hshentry * gendeltas[hshsize];/*stores deltas to be generated*/ 55: struct hshentry * target; 56: 57: catchints(); 58: cmdid = "rcsmerge"; 59: cmdusage = "command format:\n rcsmerge -p -rrev1 -rrev2 file\n rcsmerge -p -rrev1 file"; 60: revnums=0;tostdout=false; 61: 62: while (--argc,++argv, argc>=1 && ((*argv)[0] == '-')) { 63: switch ((*argv)[1]) { 64: case 'p': 65: tostdout=true; 66: /* falls into -r */ 67: case 'r': 68: if ((*argv)[2]!='\0') { 69: if (revnums==0) { 70: rev1= *argv+2; revnums=1; 71: } elif (revnums==1) { 72: rev2= *argv+2; revnums=2; 73: } else { 74: faterror("too many revision numbers"); 75: } 76: } /* do nothing for empty -r or -p */ 77: break; 78: 79: default: 80: faterror("unknown option: %s\n%s", *argv,cmdusage); 81: }; 82: } /* end of option processing */ 83: 84: if (argc<1) faterror("No input file\n%s",cmdusage); 85: if (revnums<1) faterror("no base revision number given"); 86: 87: /* now handle all filenames */ 88: 89: if (pairfilenames(argc,argv,true,false)==1) { 90: 91: if (argc>2 || (argc==2&&argv[1]!=nil)) 92: warn("too many arguments"); 93: diagnose("RCS file: %s",RCSfilename); 94: if (!(access(workfilename,4)==0)) 95: faterror("Can't open %s",workfilename); 96: 97: if (!trysema(RCSfilename,false)) goto end; /* give up */ 98: 99: gettree(); /* reads in the delta tree */ 100: 101: if (Head==nil) faterror("no revisions present"); 102: 103: 104: if (!expandsym(rev1,numericrev)) goto end; 105: if (!(target=genrevs(numericrev,nil,nil,nil,gendeltas))) goto end; 106: rev1=target->num; 107: if (revnums==1) rev2=Head->num; /* default for rev2 */ 108: if (!expandsym(rev2,numericrev)) goto end; 109: if (!(target=genrevs(numericrev,nil,nil,nil,gendeltas))) goto end; 110: rev2=target->num; 111: 112: temp1file=mktempfile("/tmp/",TMPFILE1); 113: temp2file=mktempfile("/tmp/",TMPFILE2); 114: 115: diagnose("retrieving revision %s",rev1); 116: sprintf(command,"%s/co -q -p%s %s > %s\n", 117: TARGETDIR,rev1,RCSfilename,temp1file); 118: if (system(command)){ 119: faterror("co failed"); 120: } 121: diagnose("retrieving revision %s",rev2); 122: sprintf(command,"%s/co -q -p%s %s > %s\n", 123: TARGETDIR,rev2,RCSfilename,temp2file); 124: if (system(command)){ 125: faterror("co failed"); 126: } 127: diagnose("Merging differences between %s and %s into %s%s", 128: rev1, rev2, workfilename, 129: tostdout?"; result to stdout":""); 130: 131: sprintf(command,"%s %s%s %s %s %s %s\n",MERGE,tostdout?"-p ":"", 132: workfilename,temp1file,temp2file,workfilename,rev2); 133: if (system(command)) { 134: faterror("merge failed"); 135: } 136: } 137: 138: end: 139: cleanup(); 140: exit(nerror!=0); 141: 142: }