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

Defined functions

any defined in line 186; used 5 times
calloc defined in line 112; used 2 times
dotted defined in line 23; never used
gettime defined in line 49; used 1 times
inpflist defined in line 85; used 4 times
myctime defined in line 61; used 1 times
opop defined in line 210; used 3 times
opush defined in line 197; used 3 times
strcmp defined in line 132; used 4 times
togopt defined in line 36; used 2 times
Last modified: 1981-07-10
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 957
Valid CSS Valid XHTML 1.0 Strict