annotate 3rdparty/packages/uucpbb/src/genseq.c @ 3226:9749d0dfc4a2

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