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

Defined functions

any defined in line 185; used 5 times
calloc defined in line 111; 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 209; used 3 times
opush defined in line 196; used 3 times
strcmp defined in line 131; used 4 times
togopt defined in line 36; used 2 times
Last modified: 1996-03-23
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2599
Valid CSS Valid XHTML 1.0 Strict