-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathci.c
executable file
·1099 lines (980 loc) · 35 KB
/
ci.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Copyright (C) 1982, 1988, 1989 Walter Tichy
Copyright 1990 by Paul Eggert
Distributed under license by the Free Software Foundation, Inc.
This file is part of RCS.
RCS is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
any later version.
RCS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with RCS; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
Report problems and direct all questions to:
*/
/*
* RCS checkin operation
*/
/*******************************************************************
* check revisions into RCS files
*******************************************************************
*/
/* $Log: ci.c,v $
* Revision 5.16 1991/01/30 14:21:32 apratt
* CI with RCS version 5
*
* Revision 5.15 91/01/30 12:02:28 apratt
* Changed RCS5AKP1 to RCS5AP1
*
* Revision 5.14 91/01/29 17:45:16 apratt
* Added RCS5AKP1 to usage message
*
* Revision 5.13 91/01/16 15:43:44 apratt
* This version works passably on the ST.
*
* Revision 5.12 1990/12/31 01:00:12 eggert
* Don't use uninitialized storage when handling -{N,n}.
*
* Revision 5.11 1990/12/04 05:18:36 eggert
* Use -I for prompts and -q for diagnostics.
*
* Revision 5.10 1990/11/05 20:30:10 eggert
* Don't remove working file when aborting due to no changes.
*
* Revision 5.9 1990/11/01 05:03:23 eggert
* Add -I and new -t behavior. Permit arbitrary data in logs.
*
* Revision 5.8 1990/10/04 06:30:09 eggert
* Accumulate exit status across files.
*
* Revision 5.7 1990/09/25 20:11:46 hammer
* fixed another small typo
*
* Revision 5.6 1990/09/24 21:48:50 hammer
* added cleanups from Paul Eggert.
*
* Revision 5.5 1990/09/21 06:16:38 hammer
* made it handle multiple -{N,n}'s. Also, made it treat re-directed stdin
* the same as the terminal
*
* Revision 5.4 1990/09/20 02:38:51 eggert
* ci -k now checks dates more thoroughly.
*
* Revision 5.3 1990/09/11 02:41:07 eggert
* Fix revision bug with `ci -k file1 file2'.
*
* Revision 5.2 1990/09/04 08:02:10 eggert
* Permit adjacent revisions with identical time stamps (possible on fast hosts).
* Improve incomplete line handling. Standardize yes-or-no procedure.
*
* Revision 5.1 1990/08/29 07:13:44 eggert
* Expand locker value like co. Clean old log messages too.
*
* Revision 5.0 1990/08/22 08:10:00 eggert
* Don't require a final newline.
* Make lock and temp files faster and safer.
* Remove compile-time limits; use malloc instead.
* Permit dates past 1999/12/31. Switch to GMT.
* Add setuid support. Don't pass +args to diff. Check diff's output.
* Ansify and Posixate. Add -k, -V. Remove snooping. Tune.
* Check diff's output.
*
* Revision 4.9 89/05/01 15:10:54 narten
* changed copyright header to reflect current distribution rules
*
* Revision 4.8 88/11/08 13:38:23 narten
* changes from [email protected] (Super User)
* -d with no arguments uses the mod time of the file it is checking in
*
* Revision 4.7 88/08/09 19:12:07 eggert
* Make sure workfile is a regular file; use its mode if RCSfile doesn't have one.
* Use execv(), not system(); allow cc -R; remove lint.
* isatty(fileno(stdin)) -> ttystdin()
*
* Revision 4.6 87/12/18 11:34:41 narten
* lint cleanups (from Guy Harris)
*
* Revision 4.5 87/10/18 10:18:48 narten
* Updating version numbers. Changes relative to revision 1.1 are actually
* relative to 4.3
*
* Revision 1.3 87/09/24 13:57:19 narten
* Sources now pass through lint (if you ignore printf/sprintf/fprintf
* warnings)
*
* Revision 1.2 87/03/27 14:21:33 jenkins
* Port to suns
*
* Revision 4.3 83/12/15 12:28:54 wft
* ci -u and ci -l now set mode of working file properly.
*
* Revision 4.2 83/12/05 13:40:54 wft
* Merged with 3.9.1.1: added calls to clearerr(stdin).
* made rewriteflag external.
*
* Revision 4.1 83/05/10 17:03:06 wft
* Added option -d and -w, and updated assingment of date, etc. to new delta.
* Added handling of default branches.
* Option -k generates std. log message; fixed undef. pointer in reading of log.
* Replaced getlock() with findlock(), link--unlink with rename(),
* getpwuid() with getcaller().
* Moved all revision number generation to new routine addelta().
* Removed calls to stat(); now done by pairfilenames().
* Changed most calls to catchints() with restoreints().
* Directed all interactive messages to stderr.
*
* Revision 3.9.1.1 83/10/19 04:21:03 lepreau
* Added clearerr(stdin) to getlogmsg() for re-reading stdin.
*
* Revision 3.9 83/02/15 15:25:44 wft
* 4.2 prerelease
*
* Revision 3.9 83/02/15 15:25:44 wft
* Added call to fastcopy() to copy remainder of RCS file.
*
* Revision 3.8 83/01/14 15:34:05 wft
* Added ignoring of interrupts while new RCS file is renamed;
* Avoids deletion of RCS files by interrupts.
*
* Revision 3.7 82/12/10 16:09:20 wft
* Corrected checking of return code from diff.
*
* Revision 3.6 82/12/08 21:34:49 wft
* Using DATEFORM to prepare date of checked-in revision;
* Fixed return from addbranch().
*
* Revision 3.5 82/12/04 18:32:42 wft
* Replaced getdelta() with gettree(), SNOOPDIR with SNOOPFILE. Updated
* field lockedby in removelock(), moved getlogmsg() before calling diff.
*
* Revision 3.4 82/12/02 13:27:13 wft
* added option -k.
*
* Revision 3.3 82/11/28 20:53:31 wft
* Added mustcheckin() to check for redundant checkins.
* Added xpandfile() to do keyword expansion for -u and -l;
* -m appends linefeed to log message if necessary.
* getlogmsg() suppresses prompt if stdin is not a terminal.
* Replaced keeplock with lockflag, fclose() with ffclose(),
* %02d with %.2d, getlogin() with getpwuid().
*
* Revision 3.2 82/10/18 20:57:23 wft
* An RCS file inherits its mode during the first ci from the working file,
* otherwise it stays the same, except that write permission is removed.
* Fixed ci -l, added ci -u (both do an implicit co after the ci).
* Fixed call to getlogin(), added call to getfullRCSname(), added check
* for write error.
* Changed conflicting identifiers.
*
* Revision 3.1 82/10/13 16:04:59 wft
* fixed type of variables receiving from getc() (char -> int).
* added include file dbm.h for getting BYTESIZ. This is used
* to check the return code from diff portably.
*/
#include "rcsbase.h"
struct Symrev {
const char *ssymbol;
int override;
struct Symrev * nextsym;
};
/* rcsfcmp */
int rcsfcmp P((const char*,const char*,const struct hshentry*));
/* rcskeep */
extern char prevdate[];
extern struct buf prevauthor, prevrev, prevstate;
int getoldkeys P((FILE*));
static const char *xpandfile P((const char*,const char*,const struct hshentry*));
static const char *getdate P((void));
static int addbranch P((struct hshentry*,struct buf*));
static int addelta P((void));
static int mustcheckin P((const char*,const struct hshentry*));
static struct cbuf getlogmsg P((void));
static struct hshentry *removelock P((struct hshentry*));
static void cleanup P((void));
static void incnum P((const char*,struct buf*));
static void addassoclst P((int, char *));
static const char diff[] = DIFF;
static FILE *workptr; /* working file pointer */
static const char *olddeltanum; /* number of old delta */
static struct buf newdelnum; /* new revision number */
static struct cbuf msg;
static int exitstatus;
static int forceciflag; /* forces check in */
static int keepflag, keepworkingfile, rcsinitflag;
static struct hshentries *gendeltas; /* deltas to be generated */
static struct hshentry *targetdelta; /* old delta to be generated */
static struct hshentry newdelta; /* new delta to be inserted */
static struct Symrev *assoclst, *lastassoc;
mainProg(ciId, "ci", "$Id: ci.c,v 5.16 1991/01/30 14:21:32 apratt Exp $")
{
static const char cmdusage[] =
"\nRCS5AP1 as modified for TOS by Allan Pratt, atari!apratt\nci usage: ci -{fklqru}[rev] -mmsg -{nN}name -sstate -t[textfile] -Vn file ...";
char altdate[datesize];
const char *author, *krev, *rev, *state, *textfile;
const char *diffilename, *expfilename;
const char *workdiffname, *newworkfilename;
int exit_stats; /* return code for command invocations */
int lockflag;
int r;
int usestatdate; /* Use mod time of file for -d. */
mode_t newRCSmode; /* mode for RCS file */
mode_t newworkmode; /* mode for working file */
struct Symrev *curassoc;
initid();
catchints();
author = rev = state = textfile = nil;
curassoc = assoclst = lastassoc = (struct Symrev *) nil;
lockflag = false;
altdate[0]= '\0'; /* empty alternate date for -d */
usestatdate=false;
while (--argc,++argv, argc>=1 && ((*argv)[0] == '-')) {
switch ((*argv)[1]) {
case 'r':
keepworkingfile = lockflag = false;
revno: if ((*argv)[2]!='\0') {
if (rev) warn("redefinition of revision number");
rev = (*argv)+2;
}
break;
case 'l':
keepworkingfile=lockflag=true;
goto revno;
case 'u':
keepworkingfile=true; lockflag=false;
goto revno;
case 'I':
interactiveflag = true;
goto revno;
case 'q':
quietflag=true;
goto revno;
case 'f':
forceciflag=true;
goto revno;
case 'k':
keepflag=true;
goto revno;
case 'm':
if (msg.size) redefined('m');
msg = cleanlogmsg(*argv+2, strlen(*argv+2));
if (!msg.size)
warn("missing message for -m option");
break;
case 'n':
if ((*argv)[2] == '\0') {
error("missing symbolic name after -n");
break;
}
checksid((*argv)+2);
addassoclst(false, (*argv)+2);
break;
case 'N':
if ((*argv)[2] == '\0') {
error("missing symbolic name after -N");
break;
}
checksid((*argv)+2);
addassoclst(true, (*argv)+2);
break;
case 's':
if ((*argv)[2]!='\0'){
if (state) redefined('s');
checksid((*argv)+2);
state = (*argv)+2;
} else
warn("missing state for -s option");
break;
case 't':
if ((*argv)[2]!='\0'){
if (textfile) redefined('t');
textfile = (*argv)+2;
}
break;
case 'd':
if (altdate[0] || usestatdate)
redefined('d');
altdate[0] = 0;
usestatdate = false;
if ((*argv)[2])
str2date(*argv+2, altdate);
else
usestatdate = true;
break;
case 'w':
if ((*argv)[2]!='\0'){
if (author) redefined('w');
checksid((*argv)+2);
author = (*argv)+2;
} else
warn("missing author for -w option");
break;
case 'V':
setRCSversion(*argv);
break;
default:
faterror("unknown option: %s%s", *argv, cmdusage);
};
} /* end processing of options */
if (argc<1) faterror("no input file%s", cmdusage);
/* now handle all filenames */
do {
finptr=frewrite=NULL;
fcopy = foutptr = NULL;
workptr = NULL;
targetdelta=nil;
olddeltanum=nil;
ffree();
switch (pairfilenames(argc, argv, rcswriteopen, false, false)) {
case -1: /* New RCS file */
rcsinitflag = true;
break;
case 0: /* Error */
continue;
case 1: /* Normal checkin with prev . RCS file */
rcsinitflag = !Head;
}
/* now RCSfilename contains the name of the RCS file, and
* workfilename contains the name of the working file.
* If the RCS file exists, finptr contains the file descriptor for the
* RCS file. The admin node is initialized.
* RCSstat is set.
*/
diagnose("%s <-- %s\n", RCSfilename,workfilename);
errno = 0;
if (!(workptr = fopen(workfilename,"r"))) {
eerror(workfilename);
continue;
}
if (!getfworkstat(fileno(workptr))) continue;
newRCSmode =
(rcsinitflag ? workstat.st_mode : RCSstat.st_mode)
& ~(S_IWUSR|S_IWGRP|S_IWOTH);
/* newRCSmode also adjusts mode of working file for -u and -l. */
if (finptr && !checkaccesslist()) continue; /* give up */
krev = rev;
if (keepflag) {
/* get keyword values from working file */
if (!getoldkeys(workptr)) continue;
if (!rev && !*(krev = prevrev.string)) {
error("can't find a revision number in %s",workfilename);
continue;
}
if (*prevdate=='\0' && *altdate=='\0' && usestatdate==false)
warn("can't find a date in %s", workfilename);
if (!*prevauthor.string && !author)
warn("can't find an author in %s", workfilename);
if (!*prevstate.string && !state)
warn("can't find a state in %s", workfilename);
} /* end processing keepflag */
gettree(); /* reads in the delta tree.*/
/* expand symbolic revision number */
if (!expandsym(krev,&newdelnum)) continue;
/* splice new delta into tree */
if (!addelta()) continue;
if (rcsinitflag) {
diagnose("initial revision: %s\n", newdelnum.string);
} else diagnose("new revision: %s; previous revision: %s\n",
newdelnum.string, olddeltanum);
newdelta.num = newdelnum.string;
newdelta.branches=nil;
newdelta.lockedby=nil; /*might be changed by addlock() */
newdelta.selector = true;
/* set author */
if (author!=nil)
newdelta.author=author; /* set author given by -w */
else if (keepflag && *prevauthor.string)
newdelta.author=prevauthor.string; /* preserve old author if possible*/
else newdelta.author=getcaller();/* otherwise use caller's id */
if (state!=nil)
newdelta.state=state; /* set state given by -s */
else if (keepflag && *prevstate.string)
newdelta.state=prevstate.string; /* preserve old state if possible */
else newdelta.state=DEFAULTSTATE;/* otherwise use default state */
if (usestatdate) {
time2date(workstat.st_mtime, altdate);
}
if (*altdate!='\0')
newdelta.date=altdate; /* set date given by -d */
else if (keepflag && *prevdate) /* preserve old date if possible */
newdelta.date = prevdate;
else
newdelta.date = getdate(); /* use current date */
/* now check validity of date -- needed because of -d and -k */
if (targetdelta!=nil &&
cmpnum(newdelta.date,targetdelta->date) < 0) {
error("Date %s precedes %s in existing revision %s.",
newdelta.date,targetdelta->date, targetdelta->num);
continue;
}
if (lockflag && addlock(&newdelta) < 0) continue;
curassoc = assoclst;
while (curassoc) {
if (!addsymbol(newdelta.num, curassoc->ssymbol, curassoc->override))
break;
curassoc = curassoc->nextsym;
}
if (curassoc) continue;
putadmin(frewrite);
puttree(Head,frewrite);
putdesc(false,textfile);
/* build rest of file */
if (rcsinitflag) {
/* get logmessage */
newdelta.log=getlogmsg();
if (!putdftext(newdelnum.string,newdelta.log,workptr,frewrite,false)) continue;
} else {
diffilename = maketemp(0);
workdiffname = workfilename;
if (workdiffname[0] == '+') {
/* Some diffs have options with leading '+'. */
char *w = ftnalloc(char, strlen(workfilename)+3);
workdiffname = w;
*w++ = '.';
*w++ = SLASH;
VOID strcpy(w, workfilename);
}
if (&newdelta==Head) {
/* prepend new one */
foutptr = NULL;
if (!(expfilename=
buildrevision(gendeltas,targetdelta,false,false))) continue;
if (!mustcheckin(expfilename,targetdelta)) continue;
/* don't check in files that aren't different, unless forced*/
newdelta.log=getlogmsg();
exit_stats = run((char*)nil,diffilename,
diff DIFF_FLAGS, workdiffname, expfilename,
(char*)nil);
if (!WIFEXITED(exit_stats) || 1<WEXITSTATUS(exit_stats))
faterror ("diff failed");
/* diff status is EXIT_TROUBLE on failure. */
if (!putdftext(newdelnum.string,newdelta.log,workptr,frewrite,false)) continue;
if (!putdtext(olddeltanum,targetdelta->log,diffilename,frewrite,true)) continue;
} else {
/* insert new delta text */
foutptr = frewrite;
if (!(expfilename=
buildrevision(gendeltas,targetdelta,false,false))) continue;
if (!mustcheckin(expfilename,targetdelta)) continue;
/* don't check in files that aren't different, unless forced*/
newdelta.log=getlogmsg();
exit_stats = run((char*)nil, diffilename,
diff DIFF_FLAGS, expfilename, workdiffname,
(char*)nil);
if (!WIFEXITED(exit_stats) || 1<WEXITSTATUS(exit_stats))
faterror ("diff failed");
if (!putdtext(newdelnum.string,newdelta.log,diffilename,frewrite,true)) continue;
}
/* rewrite rest of RCS file */
fastcopy(finptr,frewrite);
ffclose(finptr); finptr=NULL; /* Help the file system. */
}
ffclose(frewrite); frewrite=NULL;
ffclose(workptr); workptr=NULL;
seteid();
if ((r = chmod(newRCSfilename,newRCSmode)) == 0) {
ignoreints();
r = re_name(newRCSfilename,RCSfilename);
keepdirtemp(newRCSfilename);
restoreints();
}
setrid();
if (r != 0) {
eerror(RCSfilename);
error("saved in %s", newRCSfilename);
dirtempunlink();
break;
}
if (!keepworkingfile) {
r = unlink(workfilename); /* Get rid of old file */
} else {
newworkmode = WORKMODE(newRCSmode,
!(Expand == OLD_EXPAND || !lockflag && StrictLocks)
);
/* Expand if !OLD_EXPAND, or if mode can't be fixed. */
if (
Expand != OLD_EXPAND
|| ( workstat.st_mode != newworkmode
&& (r = chmod(workfilename,newworkmode)) < 0
)
) {
/* Expand keywords in file. */
locker_expansion = lockflag;
newworkfilename=
xpandfile(workfilename,workfilename /*for directory*/,&newdelta);
if (!newworkfilename) continue; /* expand failed */
if ((r = chmod(newworkfilename, newworkmode)) == 0) {
ignoreints();
r = re_name(newworkfilename,workfilename);
keepdirtemp(newworkfilename);
restoreints();
}
}
}
if (r != 0) {
eerror(workfilename);
continue;
}
diagnose("done\n");
} while (cleanup(),
++argv, --argc >=1);
tempunlink();
exitmain(exitstatus);
} /* end of main (ci) */
static void
cleanup()
{
if (nerror) exitstatus = EXIT_FAILURE;
if (finptr) ffclose(finptr);
if (frewrite) ffclose(frewrite);
if (workptr) ffclose(workptr);
dirtempunlink();
}
#if lint
# define exiterr ciExit
#endif
exiting void
exiterr()
{
dirtempunlink();
tempunlink();
_exit(EXIT_FAILURE);
}
/*****************************************************************/
/* the rest are auxiliary routines */
static int
addelta()
/* Function: Appends a delta to the delta tree, whose number is
* given by newdelnum. Updates Head, newdelnum, newdelnumlength,
* olddeltanum and the links in newdelta.
* Returns false on error, true on success.
*/
{
register char *tp;
register unsigned i;
unsigned newdnumlength; /* actual length of new rev. num. */
newdnumlength = countnumflds(newdelnum.string);
if (rcsinitflag) {
/* this covers non-existing RCS file and a file initialized with rcs -i */
if ((newdnumlength==0)&&(Dbranch!=nil)) {
bufscpy(&newdelnum, Dbranch);
newdnumlength = countnumflds(Dbranch);
}
if (newdnumlength==0) bufscpy(&newdelnum, "1.1");
else if (newdnumlength==1) bufscat(&newdelnum, ".1");
else if (newdnumlength>2) {
error("Branch point doesn't exist for %s.",newdelnum.string);
return false;
} /* newdnumlength == 2 is OK; */
olddeltanum=nil;
Head = &newdelta;
newdelta.next=nil;
return true;
}
if (newdnumlength==0) {
/* derive new revision number from locks */
switch (findlock(true, &targetdelta)) {
default:
/* found two or more old locks */
return false;
case 1:
/* found an old lock */
olddeltanum=targetdelta->num;
/* check whether locked revision exists */
if (!genrevs(olddeltanum,(char*)nil,(char*)nil,(char*)nil,&gendeltas)) return false;
if (targetdelta==Head) {
/* make new head */
newdelta.next=Head;
Head= &newdelta;
incnum(olddeltanum, &newdelnum);
} else if (!targetdelta->next && countnumflds(olddeltanum)>2) {
/* new tip revision on side branch */
targetdelta->next= &newdelta;
newdelta.next = nil;
incnum(olddeltanum, &newdelnum);
} else {
/* middle revision; start a new branch */
bufscpy(&newdelnum, "");
if (!addbranch(targetdelta,&newdelnum)) return false;
}
return true; /* successful use of existing lock */
case 0:
/* no existing lock; try Dbranch */
/* update newdelnum */
if (StrictLocks || !myself(RCSstat.st_uid)) {
error("no lock set by %s",getcaller());
return false;
}
if (Dbranch) {
bufscpy(&newdelnum, Dbranch);
} else {
incnum(Head->num, &newdelnum);
}
newdnumlength = countnumflds(newdelnum.string);
/* now fall into next statement */
}
}
if (newdnumlength<=2) {
/* add new head per given number */
olddeltanum=Head->num;
if(newdnumlength==1) {
/* make a two-field number out of it*/
if (cmpnumfld(newdelnum.string,olddeltanum,1)==0)
incnum(olddeltanum, &newdelnum);
else
bufscat(&newdelnum, ".1");
}
if (cmpnum(newdelnum.string,olddeltanum) <= 0) {
error("deltanumber %s too low; must be higher than %s",
newdelnum.string, Head->num);
return false;
}
if (!(targetdelta=removelock(Head))) return false;
if (!genrevs(olddeltanum,(char*)nil,(char*)nil,(char*)nil,&gendeltas)) return false;
newdelta.next=Head;
Head= &newdelta;
} else {
/* put new revision on side branch */
/*first, get branch point */
tp = newdelnum.string;
for (i = newdnumlength - (newdnumlength&1 ^ 1); (--i); )
while (*tp++ != '.')
;
*--tp = 0; /* Kill final dot to get old delta temporarily. */
if (!(targetdelta=genrevs(newdelnum.string,(char*)nil,(char*)nil,(char*)nil,&gendeltas)))
return false;
olddeltanum = targetdelta->num;
if (cmpnum(olddeltanum, newdelnum.string) != 0) {
error("can't find branchpoint %s", newdelnum.string);
return false;
}
*tp = '.'; /* Restore final dot. */
if (!addbranch(targetdelta,&newdelnum)) return false;
}
return true;
}
static int
addbranch(branchpoint,num)
struct hshentry *branchpoint;
struct buf *num;
/* adds a new branch and branch delta at branchpoint.
* If num is the null string, appends the new branch, incrementing
* the highest branch number (initially 1), and setting the level number to 1.
* the new delta and branchhead are in globals newdelta and newbranch, resp.
* the new number is placed into num.
* returns false on error.
*/
{
struct branchhead *bhead, **btrail;
struct buf branchnum;
int result;
unsigned field, numlength;
static struct branchhead newbranch; /* new branch to be inserted */
numlength = countnumflds(num->string);
if (branchpoint->branches==nil) {
/* start first branch */
branchpoint->branches = &newbranch;
if (numlength==0) {
bufscpy(num, branchpoint->num);
bufscat(num, ".1.1");
} else if (numlength&1)
bufscat(num, ".1");
newbranch.nextbranch=nil;
} else if (numlength==0) {
/* append new branch to the end */
bhead=branchpoint->branches;
while (bhead->nextbranch) bhead=bhead->nextbranch;
bhead->nextbranch = &newbranch;
bufautobegin(&branchnum);
getbranchno(bhead->hsh->num, &branchnum);
incnum(branchnum.string, num);
bufautoend(&branchnum);
bufscat(num, ".1");
newbranch.nextbranch=nil;
} else {
/* place the branch properly */
field = numlength - (numlength&1 ^ 1);
/* field of branch number */
btrail = &branchpoint->branches;
while (0 < (result=cmpnumfld(num->string,(*btrail)->hsh->num,field))) {
btrail = &(*btrail)->nextbranch;
if (!*btrail) {
result = -1;
break;
}
}
if (result < 0) {
/* insert/append new branchhead */
newbranch.nextbranch = *btrail;
*btrail = &newbranch;
if (numlength&1) bufscat(num, ".1");
} else {
/* branch exists; append to end */
bufautobegin(&branchnum);
getbranchno(num->string, &branchnum);
targetdelta=genrevs(branchnum.string,(char*)nil,
(char*)nil,(char*)nil,&gendeltas);
bufautoend(&branchnum);
if (!targetdelta) return false;
olddeltanum=targetdelta->num;
if (cmpnum(num->string,olddeltanum) <= 0) {
error("deltanumber %s too low; must be higher than %s",
num->string,olddeltanum);
return false;
}
if (!removelock(targetdelta)) return false;
if (numlength&1) incnum(olddeltanum,num);
targetdelta->next= &newdelta;
newdelta.next=nil;
return true; /* Don't do anything to newbranch */
}
}
newbranch.hsh = &newdelta;
newdelta.next=nil;
return true;
}
static void
incnum(onum,nnum)
const char *onum;
struct buf *nnum;
/* Increment the last field of revision number onum by one and
* place the result into nnum.
*/
{
register const char *sp;
register char *tp;
register unsigned i;
sp = onum;
bufalloc(nnum, strlen(sp)+2);
tp = nnum->string;
for (i=countnumflds(sp); (--i); ) {
while (*sp != '.') *tp++ = *sp++;
*tp++ = *sp++; /* copy dot also */
}
VOID sprintf(tp, "%d", atoi(sp)+1);
}
static struct hshentry *
removelock(delta)
struct hshentry * delta;
/* function: Finds the lock held by caller on delta,
* removes it, and returns a pointer to the delta.
* Prints an error message and returns nil if there is no such lock.
* An exception is if !StrictLocks, and caller is the owner of
* the RCS file. If caller does not have a lock in this case,
* delta is returned.
*/
{
register struct lock * next, * trail;
const char *num;
struct lock dummy;
int whomatch, nummatch;
num=delta->num;
dummy.nextlock=next=Locks;
trail = &dummy;
while (next!=nil) {
whomatch = strcmp(getcaller(), next->login);
nummatch=strcmp(num,next->delta->num);
if ((whomatch==0) && (nummatch==0)) break;
/*found a lock on delta by caller*/
if ((whomatch!=0)&&(nummatch==0)) {
error("revision %s locked by %s",num,next->login);
return nil;
}
trail=next;
next=next->nextlock;
}
if (next!=nil) {
/*found one; delete it */
trail->nextlock=next->nextlock;
Locks=dummy.nextlock;
next->delta->lockedby=nil; /* reset locked-by */
return next->delta;
} else {
if (StrictLocks || !myself(RCSstat.st_uid)) {
error("no lock set by %s for revision %s",getcaller(),num);
return nil;
} else {
return delta;
}
}
}
static const char *
getdate()
/* Return a pointer to the current date. */
{
static char buffer[datesize]; /* date buffer */
time_t t;
if (!buffer[0]) {
t = time((time_t *)0);
if (t == -1)
faterror("time not available");
time2date(t, buffer);
}
return buffer;
}
static const char *
xpandfile (unexfname,dir,delta)
const char *unexfname, *dir;
const struct hshentry *delta;
/* Function: Reads file unexpfname and copies it to a
* file in dir, performing keyword substitution with data from delta.
* returns the name of the expanded file if successful, nil otherwise.
*/
{
const char *targetfname;
FILE * unexfile, *exfile;
targetfname = makedirtemp(dir,0);
errno = 0;
if (!(unexfile = fopen(unexfname, "r"))) {
eerror(unexfname);
return nil;
}
errno = 0;
if (!(exfile = fopen(targetfname, "w"))) {
eerror(targetfname);
error("can't expand file %s",unexfname);
ffclose(unexfile);
return nil;
}
if (Expand == OLD_EXPAND)
fastcopy(unexfile,exfile);
else
while (0 < expandline(unexfile,exfile,delta,false,(FILE*)nil))
;
ffclose(unexfile);ffclose(exfile);
return targetfname;
}
static int
mustcheckin (unexfname,delta)
const char *unexfname;
const struct hshentry *delta;
/* Function: determines whether checkin should proceed.
* Compares the workfilename with unexfname, disregarding keywords.
* If the 2 files differ, returns true. If they do not differ, asks the user
* whether to return true or false (i.e., whether to checkin the file anyway);
* the default answer is false.
* Shortcut: If forceciflag is set, mustcheckin() always returns true.
*/
{
int result;
if (forceciflag) return true;
if (!rcsfcmp(workfilename,unexfname,delta)) return true;
/* If files are different, must check them in. */
/* files are the same */
if (!(result = yesorno(false,
"File %s is unchanged with respect to revision %s\ncheckin anyway? [ny](n): ",
workfilename, delta->num
))) {
error("%scheckin aborted",
!quietflag && ttystdin() ? "" : "file is unchanged; "
);
}
return result;
}
/* --------------------- G E T L O G M S G --------------------------------*/
static struct cbuf
getlogmsg()
/* Function: obtains a log message and returns a pointer to it.
* If a log message is given via the -m option, a pointer to that
* string is returned.
* If this is the initial revision, a standard log message is returned.
* Otherwise, reads a character string from the terminal.
* Stops after reading EOF or a single '.' on a
* line. getlogmsg prompts the first time it is called for the
* log message; during all later calls it asks whether the previous
* log message can be reused.
* returns a pointer to the character string; the pointer is always non-nil.
*/
{
static const char