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