1 /* Copyright (c) 1979 Regents of the University of California */ 2 3 static char sccsid[] = "@(#)subr.c 1.5 04/16/82"; 4 5 #include "whoami.h" 6 #include "0.h" 7 8 #ifndef PI1 9 /* 10 * Does the string fp end in '.' and the character c ? 11 */ 12 dotted(fp, c) 13 register char *fp; 14 char c; 15 { 16 register int i; 17 18 i = strlen(fp); 19 return (i > 1 && fp[i - 2] == '.' && fp[i - 1] == c); 20 } 21 22 /* 23 * Toggle the option c. 24 */ 25 togopt(c) 26 char c; 27 { 28 register char *tp; 29 30 tp = &opt( c ); 31 *tp = 1 - *tp; 32 } 33 34 /* 35 * Set the time vector "tvec" to the 36 * modification time stamp of a file. 37 */ 38 gettime( filename ) 39 char *filename; 40 { 41 #include <sys/stat.h> 42 struct stat stb; 43 44 stat(filename, &stb); 45 tvec = stb.st_mtime; 46 } 47 48 /* 49 * Convert a "ctime" into a Pascal styple time line 50 */ 51 char * 52 myctime(tv) 53 int *tv; 54 { 55 register char *cp, *dp; 56 char *cpp; 57 register i; 58 static char mycbuf[26]; 59 60 cpp = ctime(tv); 61 dp = mycbuf; 62 cp = cpp; 63 cpp[16] = 0; 64 while (*dp++ = *cp++); 65 dp--; 66 cp = cpp+19; 67 cpp[24] = 0; 68 while (*dp++ = *cp++); 69 return (mycbuf); 70 } 71 72 /* 73 * Is "fp" in the command line list of names ? 74 */ 75 inpflist(fp) 76 char *fp; 77 { 78 register i, *pfp; 79 80 pfp = pflist; 81 for (i = pflstc; i > 0; i--) 82 if (strcmp(fp, *pfp++) == 0) 83 return (1); 84 return (0); 85 } 86 #endif 87 88 extern int errno; 89 extern char *sys_errlist[]; 90 91 /* 92 * Boom! 93 */ 94 Perror(file, error) 95 char *file, *error; 96 { 97 98 fprintf( stderr , "%s: %s\n" , file , error ); 99 } 100 101 int * 102 calloc(num, size) 103 int num, size; 104 { 105 register int p1, *p2, nbyte; 106 107 nbyte = (num*size+( ( sizeof ( int ) ) - 1 ) ) & ~( ( sizeof ( int ) ) - 1 ); 108 if ((p1 = malloc(nbyte)) == 0) 109 return (0); 110 p2 = p1; 111 nbyte /= sizeof ( int ); 112 do { 113 *p2++ = 0; 114 } while (--nbyte); 115 return (p1); 116 } 117 118 /* 119 * Compare strings: s1>s2: >0 s1==s2: 0 s1<s2: <0 120 */ 121 strcmp(s1, s2) 122 register char *s1, *s2; 123 { 124 125 while (*s1 == *s2++) 126 if (*s1++=='\0') 127 return (0); 128 return (*s1 - *--s2); 129 } 130 131 /* 132 * Copy string s2 to s1. 133 * S1 must be large enough. 134 * Return s1. 135 */ 136 strcpy(s1, s2) 137 register char *s1, *s2; 138 { 139 register os1; 140 141 os1 = s1; 142 while (*s1++ = *s2++) 143 continue; 144 return (os1); 145 } 146 147 /* 148 * Strlen is currently a freebie of perror 149 * Take the length of a string. 150 * Note that this does not include the trailing null! 151 strlen(cp) 152 register char *cp; 153 { 154 register int i; 155 156 for (i = 0; *cp != 0; cp++) 157 i++; 158 return (i); 159 } 160 */ 161 copy(to, from, bytes) 162 register char *to, *from; 163 register int bytes; 164 { 165 166 if (bytes != 0) 167 do 168 *to++ = *from++; 169 while (--bytes); 170 } 171 172 /* 173 * Is ch one of the characters in the string cp ? 174 */ 175 any(cp, ch) 176 register char *cp; 177 char ch; 178 { 179 180 while (*cp) 181 if (*cp++ == ch) 182 return (1); 183 return (0); 184 } 185 186 opush(c) 187 register CHAR c; 188 { 189 190 c -= 'A'; 191 optstk[c] <<= 1; 192 optstk[c] |= opts[c]; 193 opts[c] = 1; 194 #ifdef PI0 195 send(ROPUSH, c); 196 #endif 197 } 198 199 opop(c) 200 register CHAR c; 201 { 202 203 c -= 'A'; 204 opts[c] = optstk[c] & 1; 205 optstk[c] >>= 1; 206 #ifdef PI0 207 send(ROPOP, c); 208 #endif 209 } 210