-
Notifications
You must be signed in to change notification settings - Fork 0
/
rcs.c
executable file
·1469 lines (1282 loc) · 43.5 KB
/
rcs.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
/*
* RCS create/change operation
*/
/* 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:
*/
/* $Log: rcs.c,v $
* Revision 5.11 1991/01/30 14:21:32 apratt
* CI with RCS version 5
*
* Revision 5.10 91/01/30 12:02:40 apratt
* Changed RCS5AKP1 to RCS5AP1
*
* Revision 5.9 91/01/29 17:45:30 apratt
* Added RCS5AKP1 to usage message
*
* Revision 5.8 91/01/11 12:46:10 apratt
* First version that compiles.
*
* Revision 5.7 90/12/18 17:19:21 eggert
* checked in with -k by apratt at 91.01.10.13.15.02.
*
* Revision 5.7 1990/12/18 17:19:21 eggert
* Fix bug with multiple -n and -N options.
*
* Revision 5.6 1990/12/04 05:18:40 eggert
* Use -I for prompts and -q for diagnostics.
*
* Revision 5.5 1990/11/11 00:06:35 eggert
* Fix `rcs -e' core dump.
*
* Revision 5.4 1990/11/01 05:03:33 eggert
* Add -I and new -t behavior. Permit arbitrary data in logs.
*
* Revision 5.3 1990/10/04 06:30:16 eggert
* Accumulate exit status across files.
*
* Revision 5.2 1990/09/04 08:02:17 eggert
* Standardize yes-or-no procedure.
*
* Revision 5.1 1990/08/29 07:13:51 eggert
* Remove unused setuid support. Clean old log messages too.
*
* Revision 5.0 1990/08/22 08:12:42 eggert
* Don't lose names when applying -a option to multiple files.
* Remove compile-time limits; use malloc instead. Add setuid support.
* Permit dates past 1999/12/31. Make lock and temp files faster and safer.
* Ansify and Posixate. Add -V. Fix umask bug. Make linting easier. Tune.
* Yield proper exit status. Check diff's output.
*
* Revision 4.11 89/05/01 15:12:06 narten
* changed copyright header to reflect current distribution rules
*
* Revision 4.10 88/11/08 16:01:54 narten
* didn't install previous patch correctly
*
* Revision 4.9 88/11/08 13:56:01 narten
* removed include <sysexits.h> (not needed)
* minor fix for -A option
*
* Revision 4.8 88/08/09 19:12:27 eggert
* Don't access freed storage.
* Use execv(), not system(); yield proper exit status; remove lint.
*
* Revision 4.7 87/12/18 11:37:17 narten
* lint cleanups (Guy Harris)
*
* Revision 4.6 87/10/18 10:28:48 narten
* Updating verison numbers. Changes relative to 1.1 are actually
* relative to 4.3
*
* Revision 1.4 87/09/24 13:58:52 narten
* Sources now pass through lint (if you ignore printf/sprintf/fprintf
* warnings)
*
* Revision 1.3 87/03/27 14:21:55 jenkins
* Port to suns
*
* Revision 1.2 85/12/17 13:59:09 albitz
* Changed setstate to rcs_setstate because of conflict with random.o.
*
* Revision 4.3 83/12/15 12:27:33 wft
* rcs -u now breaks most recent lock if it can't find a lock by the caller.
*
* Revision 4.2 83/12/05 10:18:20 wft
* Added conditional compilation for sending mail.
* Alternatives: V4_2BSD, V6, USG, and other.
*
* Revision 4.1 83/05/10 16:43:02 wft
* Simplified breaklock(); added calls to findlock() and getcaller().
* Added option -b (default branch). Updated -s and -w for -b.
* Removed calls to stat(); now done by pairfilenames().
* Replaced most catchints() calls with restoreints().
* Removed check for exit status of delivermail().
* Directed all interactive output to stderr.
*
* Revision 3.9.1.1 83/12/02 22:08:51 wft
* Added conditional compilation for 4.2 sendmail and 4.1 delivermail.
*
* Revision 3.9 83/02/15 15:38:39 wft
* Added call to fastcopy() to copy remainder of RCS file.
*
* Revision 3.8 83/01/18 17:37:51 wft
* Changed sendmail(): now uses delivermail, and asks whether to break the lock.
*
* Revision 3.7 83/01/15 18:04:25 wft
* Removed putree(); replaced with puttree() in rcssyn.c.
* Combined putdellog() and scanlogtext(); deleted putdellog().
* Cleaned up diagnostics and error messages. Fixed problem with
* mutilated files in case of deletions in 2 files in a single command.
* Changed marking of selector from 'D' to DELETE.
*
* Revision 3.6 83/01/14 15:37:31 wft
* Added ignoring of interrupts while new RCS file is renamed;
* Avoids deletion of RCS files by interrupts.
*
* Revision 3.5 82/12/10 21:11:39 wft
* Removed unused variables, fixed checking of return code from diff,
* introduced variant COMPAT2 for skipping Suffix on -A files.
*
* Revision 3.4 82/12/04 13:18:20 wft
* Replaced getdelta() with gettree(), changed breaklock to update
* field lockedby, added some diagnostics.
*
* Revision 3.3 82/12/03 17:08:04 wft
* Replaced getlogin() with getpwuid(), flcose() with ffclose(),
* /usr/ucb/Mail with macro MAIL. Removed handling of Suffix (-x).
* fixed -u for missing revno. Disambiguated structure members.
*
* Revision 3.2 82/10/18 21:05:07 wft
* rcs -i now generates a file mode given by the umask minus write permission;
* otherwise, rcs keeps the mode, but removes write permission.
* I added a check for write error, fixed call to getlogin(), replaced
* curdir() with getfullRCSname(), cleaned up handling -U/L, and changed
* conflicting, long identifiers.
*
* Revision 3.1 82/10/13 16:11:07 wft
* fixed type of variables receiving from getc() (char -> int).
*/
#include "rcsbase.h"
struct Lockrev {
const char *revno;
struct Lockrev * nextrev;
};
struct Symrev {
const char *revno;
const char *ssymbol;
int override;
struct Symrev * nextsym;
};
struct Status {
const char *revno;
const char *status;
struct Status * nextstatus;
};
enum changeaccess {append, erase};
struct chaccess {
const char *login;
enum changeaccess command;
struct chaccess *nextchaccess;
};
struct delrevpair {
const char *strt;
const char *end;
int code;
};
static int buildeltatext P((const struct hshentries*));
static int removerevs P((void));
static int sendmail P((const char*,const char*));
static struct Lockrev *rmnewlocklst P((const struct Lockrev*));
static void breaklock P((const struct hshentry*));
static void buildtree P((void));
static void cleanup P((void));
static void getaccessor P((char*,enum changeaccess));
static void getassoclst P((int,char*));
static void getchaccess P((const char*,enum changeaccess));
static void getdelrev P((char*));
static void getstates P((char*));
static void rcs_setstate P((const char*,const char*));
static void scanlogtext P((struct hshentry*,int));
static void setlock P((const char*));
static void updateaccess P((void));
static void updateassoc P((void));
static void updatelocks P((void));
static struct buf numrev;
static const char *headstate;
static int chgheadstate, exitstatus, lockhead, unlockcaller;
static struct Lockrev *newlocklst, *rmvlocklst;
static struct Status *statelst, *laststate;
static struct Symrev *assoclst, *lastassoc;
static struct chaccess *chaccess, **nextchaccess;
static struct delrevpair delrev;
static struct hshentry *cuthead, *cuttail, *delstrt;
static struct hshentries *gendeltas;
mainProg(rcsId, "rcs", "$Id: rcs.c,v 5.11 1991/01/30 14:21:32 apratt Exp $")
{
static const char cmdusage[] =
"\nRCS5AP1 as modified for TOS by Allan Pratt, atari!apratt\nrcs usage: rcs -alogins -Aoldfile -{blu}[rev] -cstring -e[logins] -i -{LU} -{nN}name[:rev] -orange -sstate[:rev] -t[textfile] -Vn file ...";
const char *branchsym, *commsyml, *textfile;
int branchflag, expmode, initflag;
int r, strictlock, strict_selected, textflag;
mode_t defaultRCSmode; /* default mode for new RCS files */
struct buf branchnum;
struct Lockrev *curlock, * rmvlock, *lockpt;
struct Status * curstate;
initid();
catchints();
nextchaccess = &chaccess;
branchsym = commsyml = textfile = nil;
branchflag = strictlock = false;
bufautobegin(&branchnum);
curlock = rmvlock = nil;
defaultRCSmode = 0;
expmode = -1;
initflag= textflag = false;
strict_selected = 0;
/* preprocessing command options */
while (--argc,++argv, argc>=1 && ((*argv)[0] == '-')) {
switch ((*argv)[1]) {
case 'i': /* initial version */
initflag = true;
break;
case 'b': /* change default branch */
if (branchflag) redefined('b');
branchflag= true;
branchsym = (*argv)+2;
break;
case 'c': /* change comment symbol */
if (commsyml) redefined('c');
commsyml = (*argv)+2;
break;
case 'a': /* add new accessor */
getaccessor(*argv+1, append);
break;
case 'A': /* append access list according to accessfile */
*argv += 2;
if (!**argv) {
error("missing file name after -A");
break;
}
if (0 < pairfilenames(1,argv,rcsreadopen,true,false)) {
while (AccessList) {
getchaccess(strsave(AccessList->login), append);
AccessList = AccessList->nextaccess;
}
ffclose(finptr);
}
break;
case 'e': /* remove accessors */
getaccessor(*argv+1, erase);
break;
case 'l': /* lock a revision if it is unlocked */
if ( (*argv)[2] == '\0'){ /* lock head or def. branch */
lockhead = true;
break;
}
lockpt = talloc(struct Lockrev);
lockpt->revno = (*argv)+2;
lockpt->nextrev = nil;
if ( curlock )
curlock->nextrev = lockpt;
else
newlocklst = lockpt;
curlock = lockpt;
break;
case 'u': /* release lock of a locked revision */
if ( (*argv)[2] == '\0'){ /* unlock head */
unlockcaller=true;
break;
}
lockpt = talloc(struct Lockrev);
lockpt->revno = (*argv)+2;
lockpt->nextrev = nil;
if (rmvlock)
rmvlock->nextrev = lockpt;
else
rmvlocklst = lockpt;
rmvlock = lockpt;
curlock = rmnewlocklst(lockpt);
break;
case 'L': /* set strict locking */
if (strict_selected++) { /* Already selected L or U? */
if (!strictlock) /* Already selected -U? */
warn("-L overrides -U.");
}
strictlock = true;
break;
case 'U': /* release strict locking */
if (strict_selected++) { /* Already selected L or U? */
if (strictlock) /* Already selected -L? */
warn("-L overrides -U.");
}
else
strictlock = false;
break;
case 'n': /* add new association: error, if name exists */
if ( (*argv)[2] == '\0') {
error("missing symbolic name after -n");
break;
}
getassoclst(false, (*argv)+1);
break;
case 'N': /* add or change association */
if ( (*argv)[2] == '\0') {
error("missing symbolic name after -N");
break;
}
getassoclst(true, (*argv)+1);
break;
case 'o': /* delete revisions */
if (delrev.strt) redefined('o');
if ( (*argv)[2] == '\0' ) {
error("missing revision range after -o");
break;
}
getdelrev( (*argv)+1 );
break;
case 's': /* change state attribute of a revision */
if ( (*argv)[2] == '\0') {
error("state missing after -s");
break;
}
getstates( (*argv)+1);
break;
case 't': /* change descriptive text */
textflag=true;
if ((*argv)[2]!='\0'){
if (textfile) redefined('t');
textfile = (*argv)+2;
}
break;
case 'I':
interactiveflag = true;
break;
case 'q':
quietflag = true;
break;
case 'V':
setRCSversion(*argv);
break;
case 'k': /* set keyword expand mode */
if (0 <= expmode) redefined('k');
if (0 <= (expmode = str2expmode(*argv+2)))
break;
/* fall into */
default:
faterror("unknown option: %s%s", *argv, cmdusage);
};
} /* end processing of options */
if (argc<1) faterror("no input file%s", cmdusage);
if (nerror) {
diagnose("%s aborted\n",cmdid);
exitmain(EXIT_FAILURE);
}
if (initflag) {
defaultRCSmode = umask((mode_t)0);
VOID umask(defaultRCSmode);
defaultRCSmode = ~defaultRCSmode & 0444;
}
/* now handle all filenames */
do {
foutptr = NULL;
finptr=frewrite=NULL;
ffree();
if ( initflag ) {
switch (pairfilenames(argc, argv, rcswriteopen, false, false)) {
case -1: break; /* not exist; ok */
case 0: continue; /* error */
case 1: error("file %s exists already", RCSfilename);
continue;
}
}
else {
switch (pairfilenames(argc, argv, rcswriteopen, true, false)) {
case -1: continue; /* not exist */
case 0: continue; /* errors */
case 1: break; /* file exists; ok*/
}
}
/* now RCSfilename contains the name of the RCS file, and
* workfilename contains the name of the working file.
* if !initflag, finptr contains the file descriptor for the
* RCS file. The admin node is initialized.
*/
diagnose("RCS file: %s\n", RCSfilename);
if (initflag && !getworkstat()) continue; /* give up */
if (!initflag && !checkaccesslist()) continue; /* give up */
gettree(); /* read in delta tree */
/* update admin. node */
if (strict_selected) StrictLocks = strictlock;
if (commsyml) {
Comment.string = commsyml;
Comment.size = strlen(commsyml);
}
if (0 <= expmode) Expand = expmode;
/* update default branch */
if (branchflag && expandsym(branchsym, &branchnum)) {
if (countnumflds(branchnum.string)) {
Dbranch = branchnum.string;
} else
Dbranch = nil;
}
updateaccess(); /* update access list */
updateassoc(); /* update association list */
updatelocks(); /* update locks */
/* update state attribution */
if (chgheadstate) {
/* change state of default branch or head */
if (Dbranch==nil) {
if (Head==nil)
warn("can't change states in an empty tree");
else Head->state = headstate;
} else {
rcs_setstate(Dbranch,headstate); /* Can't set directly */
}
}
curstate = statelst;
while( curstate ) {
rcs_setstate(curstate->revno,curstate->status);
curstate = curstate->nextstatus;
}
cuthead = cuttail = nil;
if (delrev.strt && removerevs()) {
/* rebuild delta tree if some deltas are deleted */
if ( cuttail )
VOID genrevs(cuttail->num, (char *)nil,(char *)nil,
(char *)nil, &gendeltas);
buildtree();
}
putadmin(frewrite);
if ( Head )
puttree(Head, frewrite);
putdesc(textflag,textfile);
foutptr = NULL;
if ( Head) {
if (!delrev.strt) {
/* no revision deleted */
fastcopy(finptr,frewrite);
} else {
if (!cuttail || buildeltatext(gendeltas))
scanlogtext((struct hshentry *)nil,nil);
/* copy rest of delta text nodes that are not deleted */
}
}
if (finptr) {ffclose(finptr); finptr=NULL;} /* Help the file system. */
ffclose(frewrite); frewrite = NULL;
if ( ! nerror ) { /* move temporary file to RCS file if no error */
/* update mode */
seteid();
r = chmod(newRCSfilename,
(
!initflag ? RCSstat.st_mode
: haveworkstat==0 ? workstat.st_mode
: defaultRCSmode
) & ~(S_IWUSR|S_IWGRP|S_IWOTH)
);
if (r == 0) {
ignoreints();
r = re_name(newRCSfilename,RCSfilename);
keepdirtemp(newRCSfilename);
restoreints();
}
setrid();
if (r != 0) {
eerror(RCSfilename);
error("saved in %s", newRCSfilename);
dirtempunlink();
break;
}
diagnose("done\n");
} else {
diagnose("%s aborted; %s unchanged.\n",cmdid,RCSfilename);
}
} while (cleanup(),
++argv, --argc >=1);
tempunlink();
exitmain(exitstatus);
} /* end of main (rcs) */
static void
cleanup()
{
if (nerror) exitstatus = EXIT_FAILURE;
if (finptr) ffclose(finptr);
if (frewrite) ffclose(frewrite);
dirtempunlink();
}
exiting void
exiterr()
{
dirtempunlink();
tempunlink();
_exit(EXIT_FAILURE);
}
static void
getassoclst(flag, sp)
int flag;
char * sp;
/* Function: associate a symbolic name to a revision or branch, */
/* and store in assoclst */
{
struct Symrev * pt;
const char *temp;
int c;
while( (c=(*++sp)) == ' ' || c == '\t' || c =='\n') ;
temp = sp;
sp = checkid(sp, ':'); /* check for invalid symbolic name */
c = *sp; *sp = '\0';
while( c == ' ' || c == '\t' || c == '\n') c = *++sp;
if ( c != ':' && c != '\0') {
error("invalid string %s after option -n or -N",sp);
return;
}
pt = talloc(struct Symrev);
pt->ssymbol = temp;
pt->override = flag;
if (c == '\0') /* delete symbol */
pt->revno = nil;
else {
while( (c = *++sp) == ' ' || c == '\n' || c == '\t') ;
if ( c == '\0' )
pt->revno = nil;
else
pt->revno = sp;
}
pt->nextsym = nil;
if (lastassoc)
lastassoc->nextsym = pt;
else
assoclst = pt;
lastassoc = pt;
return;
}
static void
getchaccess(login, command)
const char *login;
enum changeaccess command;
{
register struct chaccess *pt;
*nextchaccess = pt = talloc(struct chaccess);
pt->login = login;
pt->command = command;
pt->nextchaccess = nil;
nextchaccess = &pt->nextchaccess;
}
static void
getaccessor(opt, command)
char *opt;
enum changeaccess command;
/* Function: get the accessor list of options -e and -a, */
/* and store in chaccess */
{
register c;
register char *sp;
sp = opt;
while( ( c = *++sp) == ' ' || c == '\n' || c == '\t' || c == ',') ;
if ( c == '\0') {
if (command == erase && sp-opt == 1) {
getchaccess((const char*)nil, command);
return;
}
error("missing login name after option -a or -e");
return;
}
while( c != '\0') {
getchaccess(sp, command);
sp = checkid(sp,',');
c = *sp; *sp = '\0';
while( c == ' ' || c == '\n' || c == '\t'|| c == ',')c =(*++sp);
}
}
static void
getstates(sp)
char *sp;
/* Function: get one state attribute and the corresponding */
/* revision and store in statelst */
{
const char *temp;
struct Status *pt;
register c;
while( (c=(*++sp)) ==' ' || c == '\t' || c == '\n') ;
temp = sp;
sp = checkid(sp,':'); /* check for invalid state attribute */
c = *sp; *sp = '\0';
while( c == ' ' || c == '\t' || c == '\n' ) c = *++sp;
if ( c == '\0' ) { /* change state of def. branch or Head */
chgheadstate = true;
headstate = temp;
return;
}
else if ( c != ':' ) {
error("missing ':' after state in option -s");
return;
}
while( (c = *++sp) == ' ' || c == '\t' || c == '\n') ;
pt = talloc(struct Status);
pt->status = temp;
pt->revno = sp;
pt->nextstatus = nil;
if (laststate)
laststate->nextstatus = pt;
else
statelst = pt;
laststate = pt;
}
static void
getdelrev(sp)
char *sp;
/* Function: get revision range or branch to be deleted, */
/* and place in delrev */
{
int c;
struct delrevpair *pt;
pt = &delrev;
while((c = (*++sp)) == ' ' || c == '\n' || c == '\t') ;
if ( c == '<' || c == '-' ) { /* -o -rev or <rev */
while( (c = (*++sp)) == ' ' || c == '\n' || c == '\t') ;
pt->strt = sp; pt->code = 1;
while( c != ' ' && c != '\n' && c != '\t' && c != '\0') c =(*++sp);
*sp = '\0';
pt->end = nil;
return;
}
else {
pt->strt = sp;
while( c != ' ' && c != '\n' && c != '\t' && c != '\0'
&& c != '-' && c != '<' ) c = *++sp;
*sp = '\0';
while( c == ' ' || c == '\n' || c == '\t' ) c = *++sp;
if ( c == '\0' ) { /* -o rev or branch */
pt->end = nil; pt->code = 0;
return;
}
if ( c != '-' && c != '<') {
faterror("invalid range %s %s after -o", pt->strt, sp);
}
while( (c = *++sp) == ' ' || c == '\n' || c == '\t') ;
if ( c == '\0') { /* -o rev- or rev< */
pt->end = nil; pt->code = 2;
return;
}
}
/* -o rev1-rev2 or rev1<rev2 */
pt->end = sp; pt->code = 3;
while( c!= ' ' && c != '\n' && c != '\t' && c != '\0') c = *++sp;
*sp = '\0';
}
static void
scanlogtext(delta,edit)
struct hshentry *delta;
int edit;
/* Function: Scans delta text nodes up to and including the one given
* by delta, or up to last one present, if delta==nil.
* For the one given by delta (if delta!=nil), the log message is saved into
* curlogmsg and the text is edited if 'edit' is set, copied otherwise.
* Assumes the initial lexeme must be read in first.
* Does not advance nexttok after it is finished, except if delta==nil.
*/
{
const struct hshentry *nextdelta;
struct cbuf cb;
for (;;) {
foutptr = NULL;
nextlex();
if (!(nextdelta=getnum())) {
if(delta)
faterror("can't find delta for revision %s", delta->num);
if (nexttok != EOFILE)
fatserror("expecting EOF");
return; /* no more delta text nodes */
}
if (nextdelta->selector) {
foutptr = frewrite;
aprintf(frewrite,DELNUMFORM,nextdelta->num,Klog);
}
getkeystring(Klog);
if (delta==nextdelta) {
cb = savestring(&curlogbuf);
delta->log = curlogmsg =
cleanlogmsg(curlogbuf.string, cb.size);
} else {readstring();
}
nextlex();
while (nexttok==ID && strcmp(NextString,Ktext)!=0)
ignorephrase();
getkeystring(Ktext);
if (delta==nextdelta)
break;
readstring(); /* skip over it */
}
/* got the one we're looking for */
if (edit)
editstring((struct hshentry *)nil);
else
copystring();
}
static struct Lockrev *
rmnewlocklst(which)
const struct Lockrev *which;
/* Function: remove lock to revision which->revno from newlocklst */
{
struct Lockrev * pt, *pre;
while( newlocklst && (! strcmp(newlocklst->revno, which->revno))){
struct Lockrev *pn = newlocklst->nextrev;
tfree(newlocklst);
newlocklst = pn;
}
pt = pre = newlocklst;
while( pt ) {
if ( ! strcmp(pt->revno, which->revno) ) {
pre->nextrev = pt->nextrev;
tfree(pt);
pt = pre->nextrev;
}
else {
pre = pt;
pt = pt->nextrev;
}
}
return pre;
}
static void
updateaccess()
{
register struct chaccess *ch;
register struct access **p, *t;
for (ch = chaccess; ch; ch = ch->nextchaccess) {
switch (ch->command) {
case erase:
if (!ch->login)
AccessList = nil;
else
for (p = &AccessList; (t = *p); )
if (strcmp(ch->login, t->login) == 0)
*p = t->nextaccess;
else
p = &t->nextaccess;
break;
case append:
for (p = &AccessList; ; p = &t->nextaccess)
if (!(t = *p)) {
*p = t = ftalloc(struct access);
t->login = ch->login;
t->nextaccess = nil;
break;
} else if (strcmp(ch->login, t->login) == 0)
break;
break;
}
}
}
static int
sendmail(Delta, who)
const char *Delta, *who;
/* Function: mail to who, informing him that his lock on delta was
* broken by caller. Ask first whether to go ahead. Return false on
* error or if user decides not to break the lock.
*/
{
#if !DONT_SEND_MAIL
const char *messagefile;
int old1, old2, c;
FILE * mailmess;
#endif
aprintf(stderr, "Revision %s is already locked by %s.\n", Delta, who);
if (!yesorno(false, "Do you want to break the lock? [ny](n): "))
return false;
/* go ahead with breaking */
#if !DONT_SEND_MAIL
messagefile = maketemp(0);
errno = 0;
if ( (mailmess = fopen(messagefile, "w")) == NULL) {
efaterror(messagefile);
}
aprintf(mailmess, "Subject: Broken lock on %s\n\nYour lock on revision %s of file %s\nhas been broken by %s for the following reason:\n",
bindex(RCSfilename,SLASH), Delta, getfullRCSname(), getcaller()
);
aputs("State the reason for breaking the lock:\n(terminate with single '.' or end of file)\n>> ", stderr);
old1 = '\n'; old2 = ' ';
for (; ;) {
c = getcstdin();
if ( c == EOF ) {
aprintf(mailmess, "%c\n", old1);
break;
}
else if ( c == '\n' && old1 == '.' && old2 == '\n')
break;
else {
afputc(old1, mailmess);
old2 = old1; old1 = c;
if (c=='\n') aputs(">> ", stderr);
}
}
ffclose(mailmess);
/* ignore the exit status, even if delivermail unsuccessful */
VOID run(messagefile, (char*)nil, SENDMAIL, who, (char*)nil);
#else
/* this is the DONT_SEND_MAIL case */
aprintf(stderr,"Please tell %s that you broke the lock and why.",who);
#endif
return(true);
}
static void
breaklock(delta)
const struct hshentry *delta;
/* function: Finds the lock held by caller on delta,
* and removes it.
* Sends mail if a lock different from the caller's is broken.
* Prints an error message if there is no such lock or error.
*/
{
register struct lock * next, * trail;
const char *num;
struct lock dummy;
num=delta->num;
dummy.nextlock=next=Locks;
trail = &dummy;
while (next!=nil) {
if (strcmp(num, next->delta->num) == 0) {
if (
strcmp(getcaller(),next->login) != 0
&& !sendmail(num, next->login)
) {
error("%s still locked by %s", num, next->login);
return;
}
break; /* exact match */
}
trail=next;
next=next->nextlock;
}
if (next!=nil) {
/*found one */
diagnose("%s unlocked\n",next->delta->num);
trail->nextlock=next->nextlock;
next->delta->lockedby=nil;
Locks=dummy.nextlock;
} else {
error("no lock set on revision %s", num);
}
}
static struct hshentry *
searchcutpt(object, length, store)
const char *object;
unsigned length;
struct hshentries *store;
/* Function: Search store and return entry with number being object. */
/* cuttail = nil, if the entry is Head; otherwise, cuttail */
/* is the entry point to the one with number being object */
{
cuthead = nil;
while (compartial(store->first->num, object, length)) {
cuthead = store->first;
store = store->rest;
}
return store->first;
}