1 /* Copyright (c) 1979 Regents of the University of California */ 2 3 static char sccsid[] = "@(#)subr.c 1.1 08/27/80"; 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 <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 errno = 0; 99 sys_errlist[0] = error; 100 perror(file); 101 } 102 103 int * 104 calloc(num, size) 105 int num, size; 106 { 107 register int p1, *p2, nbyte; 108 109 nbyte = (num*size+( ( sizeof ( int ) ) - 1 ) ) & ~( ( sizeof ( int ) ) - 1 ); 110 if ((p1 = malloc(nbyte)) == -1 || p1==0) 111 return (-1); 112 p2 = p1; 113 nbyte /= sizeof ( int ); 114 do { 115 *p2++ = 0; 116 } while (--nbyte); 117 return (p1); 118 } 119 120 /* 121 * Compare strings: s1>s2: >0 s1==s2: 0 s1<s2: <0 122 */ 123 strcmp(s1, s2) 124 register char *s1, *s2; 125 { 126 127 while (*s1 == *s2++) 128 if (*s1++=='\0') 129 return (0); 130 return (*s1 - *--s2); 131 } 132 133 /* 134 * Copy string s2 to s1. 135 * S1 must be large enough. 136 * Return s1. 137 */ 138 strcpy(s1, s2) 139 register char *s1, *s2; 140 { 141 register os1; 142 143 os1 = s1; 144 while (*s1++ = *s2++) 145 continue; 146 return (os1); 147 } 148 149 /* 150 * Strlen is currently a freebie of perror 151 * Take the length of a string. 152 * Note that this does not include the trailing null! 153 strlen(cp) 154 register char *cp; 155 { 156 register int i; 157 158 for (i = 0; *cp != 0; cp++) 159 i++; 160 return (i); 161 } 162 */ 163 copy(to, from, bytes) 164 register char *to, *from; 165 register int bytes; 166 { 167 168 if (bytes != 0) 169 do 170 *to++ = *from++; 171 while (--bytes); 172 } 173 174 /* 175 * Is ch one of the characters in the string cp ? 176 */ 177 any(cp, ch) 178 register char *cp; 179 char ch; 180 { 181 182 while (*cp) 183 if (*cp++ == ch) 184 return (1); 185 return (0); 186 } 187 188 opush(c) 189 register CHAR c; 190 { 191 192 c -= 'A'; 193 optstk[c] <<= 1; 194 optstk[c] |= opts[c]; 195 opts[c] = 1; 196 #ifdef PI0 197 send(ROPUSH, c); 198 #endif 199 } 200 201 opop(c) 202 register CHAR c; 203 { 204 205 c -= 'A'; 206 opts[c] = optstk[c] & 1; 207 optstk[c] >>= 1; 208 #ifdef PI0 209 send(ROPOP, c); 210 #endif 211 } 212