# 2.11BSD#431 - /usr/src/local/mtools/expand.c

##### Functions

    expand            X
    memcpy            X
    memset            X
    strpbrk           X

##### Macros

    EXPAND_BUF        X

       1: /*
       2:  * Do filename expansion with the shell.  Returns a pointer to a
       3:  * static area.
       4:  */
       5:
       6: #define EXPAND_BUF  2048
       7:
       8: #include <stdio.h>
       9:
      10: char *
      11: expand(input)
      12: char *input;
      13: {
      14:     FILE *fp, *popen();
      15:     int last;
      16:     char buf[256], *strpbrk(), *strcpy();
      17:     static char ans[EXPAND_BUF];
      18:
      19:     if (input == NULL)
      20:         return(NULL);
      21:     if (*input == '\0')
      22:         return("");
      23:                     /* any thing to expand? */
      24:     if (!strpbrk(input, "$*{}[]\\?~")) {
      25:         strcpy(ans, input);
      26:         return(ans);
      27:     }
      28:                     /* popen an echo */
      29:     sprintf(buf, "echo %s", input);
      30:
      31:     fp = popen(buf, "r");
      32:     fgets(ans, EXPAND_BUF, fp);
      33:     pclose(fp);
      34:
      35:     if (!strlen(ans)) {
      36:         strcpy(ans, input);
      37:         return(ans);
      38:     }
      39:
      40:     /*
      41: 	 * A horrible kludge...  if the last character is not a line feed,
      42: 	 * then the csh has returned an error message.  Otherwise zap the
      43: 	 * line feed.
      44: 	 */
      45:     last = strlen(ans) - 1;
      46:     if (ans[last] != '\n') {
      47:         strcpy(ans, input);
      48:         return(ans);
      49:     }
      50:     else
      51:         ans[last] = '\0';
      52:
      53:     return(ans);
      54: }
      55:
      56: /*
      57:  * Miscellaneous routines probably missing from Bezerkely
      58:  */
      59:
      60: #ifdef BSD
      61: /*
      62:  * Return ptr to first occurrence of any character from `brkset'
      63:  * in the character string `string'; NULL if none exists.
      64:  */
      65:
      66: char *
      67: strpbrk(string, brkset)
      68: register char *string, *brkset;
      69: {
      70:     register char *p;
      71:
      72:     if (!string || !brkset)
      73:         return(0);
      74:     do {
      75:         for (p = brkset; *p != '\0' && *p != *string; ++p)
      76:             ;
      77:         if (*p != '\0')
      78:             return(string);
      79:     }
      80:     while (*string++);
      81:     return(0);
      82: }
      83:
      84: /*
      85:  * Copies the character c, n times to string s
      86:  */
      87:
      88: char *
      89: memset(s, c, n)
      90: char *s, c;
      91: int n;
      92: {
      93:     char *s1 = s;
      94:
      95:     while (n > 0) {
      96:         --n;
      97:         *s++ = c;
      98:     }
      99:     return(s1);
     100: }
     101:
     102: /*
     103:  * Copy contents of memory (with possible overlapping).
     104:  */
     105:
     106: char *
     107: memcpy(s1, s2, n)
     108: char *s1, *s2;
     109: int n;
     110: {
     111:     bcopy(s2, s1, n);
     112:     return(s1);
     113: }
     114: #endif /* BSD */

#### Defined functions

expand defined in line 10; used 9 times

- in /usr/src/local/mtools/init.c line 36, 63, 248, 256
- in /usr/src/local/mtools/mcd.c line 30, 86-87(2)
- in /usr/src/local/mtools/mformat.c line 31, 102

memcpy defined in line 106; used 13 times

- in /usr/src/local/mtools/buf_read.c line 26, 71
- in /usr/src/local/mtools/buf_write.c line 24, 78
- in /usr/src/local/mtools/dir_read.c line 19-24(2)
- in /usr/src/local/mtools/dir_write.c line 21-24(2)
- in /usr/src/local/mtools/mformat.c line 32, 237
- in /usr/src/local/mtools/mmd.c line 168, 179-181(2)

memset defined in line 88; used 10 times

- in /usr/src/local/mtools/dir_make.c line 22, 49
- in /usr/src/local/mtools/mformat.c line 32, 190, 217-222(2), 230, 240
- in /usr/src/local/mtools/mmd.c line 168, 184

strpbrk defined in line 66; used 7 times

- in line 16, 24
- in /usr/src/local/mtools/dir_write.c line 66, 118-122(2)
- in /usr/src/local/mtools/mdir.c line 34, 132

#### Defined macros

EXPAND_BUF defined in line 6; used 2 times

- in line 17, 32

Last modified: 1992-06-24 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 502 |