# 2.11BSD#431 - /usr/src/ucb/PORT/pascal/src/subr.c

##### Functions

    Perror            X
    any               X
    copy              X
    dotted            X
    gettime           X
    inpflist          X
    myctime           X
    opop              X
    opush             X
    pcalloc           X
    pstrcmp           X
    pstrcpy           X
    togopt            X

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

#### Defined functions

Perror defined in line 101; used 6 times

- in /usr/src/ucb/PORT/pascal/src/error.c line 42-44(2)
- in /usr/src/ucb/PORT/pascal/src/main.c line 178, 281, 295
- in /usr/src/ucb/PORT/pascal/src/yymain.c line 41

any defined in line 183; used 5 times

- in /usr/src/ucb/PORT/pascal/src/yyid.c line 244, 252, 258-260(2)
- in /usr/src/ucb/PORT/pascal/src/yylex.c line 181

copy defined in line 169; used 14 times

- in /usr/src/ucb/PORT/pascal/src/pas.y line 530
- in /usr/src/ucb/PORT/pascal/src/yylex.c line 31, 46
- in /usr/src/ucb/PORT/pascal/src/yypanic.c line 40, 146
- in /usr/src/ucb/PORT/pascal/src/yyrecover.c line 226, 238, 293, 314, 368, 381, 428, 471, 725

dotted defined in line 18; used 5 times

- in /usr/src/ucb/PORT/pascal/src/main.c line 153, 227, 294
- in /usr/src/ucb/PORT/pascal/src/yyget.c line 220(2)

gettime defined in line 44; used 3 times

- in /usr/src/ucb/PORT/pascal/src/error.c line 139
- in /usr/src/ucb/PORT/pascal/src/main.c line 431
- in /usr/src/ucb/PORT/pascal/src/yyput.c line 281

inpflist defined in line 81; used 4 times

- in /usr/src/ucb/PORT/pascal/src/fend.c line 474
- in /usr/src/ucb/PORT/pascal/src/fhdr.c line 54
- in /usr/src/ucb/PORT/pascal/src/yyget.c line 261, 325

myctime defined in line 57; used 6 times

- in /usr/src/ucb/PORT/pascal/src/0.h line 724
- in /usr/src/ucb/PORT/pascal/src/error.c line 140
- in /usr/src/ucb/PORT/pascal/src/main.c line 81, 437-441(2)
- in /usr/src/ucb/PORT/pascal/src/yyput.c line 282

opop defined in line 207; used 3 times

- in /usr/src/ucb/PORT/pascal/src/fend.c line 475
- in /usr/src/ucb/PORT/pascal/src/yyget.c line 327-330(2)

opush defined in line 194; used 3 times

- in /usr/src/ucb/PORT/pascal/src/fhdr.c line 55
- in /usr/src/ucb/PORT/pascal/src/yyget.c line 263-266(2)

pcalloc defined in line 108; used 2 times

- in /usr/src/ucb/PORT/pascal/src/0.h line 714
- in /usr/src/ucb/PORT/pascal/src/hash.c line 154

pstrcmp defined in line 128; used 4 times

- in line 89
- in /usr/src/ucb/PORT/pascal/src/fend.c line 218-222(2)
- in /usr/src/ucb/PORT/pascal/src/hash.c line 187

pstrcpy defined in line 143; used 4 times

- in /usr/src/ucb/PORT/pascal/src/0.h line 723
- in /usr/src/ucb/PORT/pascal/src/string.c line 85
- in /usr/src/ucb/PORT/pascal/src/tree.c line 182
- in /usr/src/ucb/PORT/pascal/src/yyget.c line 126

togopt defined in line 31; used 9 times

- in /usr/src/ucb/PORT/pascal/src/main.c line 129, 168, 174, 201, 246, 253, 259, 265, 277

#### Defined variables

sccsid defined in line 8; never used

Last modified: 1985-06-06 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 833 |