1772
|
1 /* genseq.c Routine to create a unique ID for UUCP spool files.
|
|
2 Copyright (C) 1990, 1993 Rick Adams and Bob Billson
|
|
3
|
|
4 This file is part of the OS-9 UUCP package, UUCPbb.
|
|
5
|
|
6 This program is free software; you can redistribute it and/or modify
|
|
7 it under the terms of the GNU General Public License as published by
|
|
8 the Free Software Foundation; either version 2 of the License, or
|
|
9 (at your option) any later version.
|
|
10
|
|
11 This program is distributed in the hope that it will be useful,
|
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 GNU General Public License for more details.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
|
17 along with this program; if not, write to the Free Software
|
|
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
19
|
|
20 The author of UUCPbb, Bob Billson, can be contacted at:
|
|
21 bob@kc2wz.bubble.org or uunet!kc2wz!bob or by snail mail:
|
|
22 21 Bates Way, Westfield, NJ 07090
|
|
23 */
|
|
24
|
|
25 /* Generate a unique sequence id for spool files. The last value used is
|
|
26 stored in the file GENSEQ (defined in uucp.h). The values run from '0000'
|
|
27 to '0zzz'. Three places gives us 46,656 unique combinations. (26 letters
|
|
28 plus 10 digits. -- 36^3) '0zzz' wraps around to '0000'. This should be
|
|
29 plenty for everyday use <grin>. Of course, if you wish, you can change the
|
|
30 value of MSB below to '0'. This will use all four places. You will then
|
|
31 have 1,679,616 unique combinations. To use them all in one year, you will
|
|
32 need to send about 4,600 messages/day. If you do that, you need more than
|
|
33 a CoCo! 8-) --REB */
|
|
34
|
|
35 #include "uucp.h"
|
|
36 #include <modes.h>
|
|
37
|
|
38 #define MSB 1 /* leftmost place of string before wrapping around */
|
|
39
|
|
40 EXTERN QQ unsigned myuid;
|
|
41
|
|
42 static char sequence[5];
|
|
43
|
|
44
|
|
45 char *genseq()
|
|
46 {
|
|
47 char seq[5], nextseq();
|
|
48 FILE *sfp;
|
|
49 register int i;
|
|
50 flag carry;
|
|
51
|
|
52 /* must be superuser to get at the sequence file */
|
|
53 asetuid (0);
|
|
54
|
|
55 if ((sfp = fopen (GENSEQ, "r")) == NULL)
|
|
56 strcpy (seq, "0000");
|
|
57 else
|
|
58 {
|
|
59 if ((fgets (seq, sizeof (seq), sfp) == NULL) || seq[0] == '\0')
|
|
60 /* file exists but empty? Start sequence over again */
|
|
61 strcpy (seq, "0000");
|
|
62
|
|
63 fclose (sfp);
|
|
64
|
|
65 /* Create next sequence id. As long as we have a carry, keep moving
|
|
66 one place to the left, up to place define by MSB. */
|
|
67
|
|
68 for (i = 3, carry = TRUE; carry && i >= MSB; --i)
|
|
69 seq[i] = nextseq (seq[i], &carry);
|
|
70 }
|
|
71
|
|
72 if ((sfp = fopen (GENSEQ, "w")) == NULL)
|
|
73 fatal ("genseq() can't open spool sequence file for writing");
|
|
74
|
|
75 strcpy (sequence, seq);
|
|
76 fprintf (sfp, "%s", seq);
|
|
77
|
|
78 /* protect the sequence file from prying eyes/hands */
|
|
79 fixperms (sfp);
|
|
80
|
|
81 fclose (sfp);
|
|
82 asetuid (myuid);
|
|
83 return (sequence);
|
|
84 }
|
|
85
|
|
86
|
|
87
|
|
88 /* Get the next value in the sequence which runs from 0 - 9 and a - z. Skip
|
|
89 any non-letters/numbers. If the value is > 'Z', we wrap around to '0' and
|
|
90 bump the next left place up one on our next pass. */
|
|
91
|
|
92 char nextseq (place_val, carry)
|
|
93 char place_val;
|
|
94 flag *carry;
|
|
95 {
|
|
96 ++place_val;
|
|
97
|
|
98 if (place_val > 'z')
|
|
99 {
|
|
100 place_val = '0';
|
|
101 *carry = TRUE;
|
|
102 }
|
|
103 else
|
|
104 {
|
|
105 if (place_val == ':')
|
|
106 place_val = 'a';
|
|
107
|
|
108 *carry = FALSE;
|
|
109 }
|
|
110 return (place_val);
|
|
111 }
|