Annotation of researchv10no/cmd/nupas/ipc/ipcpath.c, revision 1.1.1.1

1.1       root        1: #include <stdio.h>
                      2: #include <string.h>
                      3: 
                      4: extern int ipcdebug;
                      5: 
                      6: #define CAT(x) if (x) for(cp=x;bp-buf<sizeof(buf)-1&&*cp;) *bp++ = *cp++; *bp='\0'
                      7: 
                      8: /*
                      9:  *     Create an ipc path that starts in the /cs directory
                     10:  *
                     11:  *     ipcpath("x!y!z", "d", "s") -> "x!y!z"
                     12:  *     ipcpath("x!y", "d", "s") -> "x!y!s"
                     13:  *     ipcpath("x", "d", "s") -> "d!x!s"
                     14:  *
                     15:  *     all other combinations abort with an error
                     16:  */
                     17: char *
                     18: ipcpath(machine, defdialer, service)
                     19:        char *machine;
                     20:        char *defdialer;
                     21:        char *service;
                     22: {
                     23:        char *field[3];
                     24:        static char buf[256];
                     25:        char ibuf[sizeof buf];
                     26:        char *bp = buf;
                     27: 
                     28:        *bp = '\0';
                     29: 
                     30:        if (machine == NULL)
                     31:                machine = "";
                     32:        strcpy(ibuf, machine);
                     33:        if (ipcdebug)
                     34:                printf("ipcpath called with %s, %s, %s\n",
                     35:                        ibuf, defdialer, service);
                     36: 
                     37:        setfields("!");
                     38: 
                     39:        switch (getfields(ibuf, field, 3)) {
                     40:        case 3: bp = strcat(bp, field[0]);
                     41:                bp = strcat(bp, "!");
                     42:                bp = strcat(bp, field[1]);
                     43:                bp = strcat(bp, "!");
                     44:                bp = strcat(bp, field[2]);
                     45:                break;
                     46: 
                     47:        case 2: bp = strcat(bp, field[0]);
                     48:                bp = strcat(bp, "!");
                     49:                bp = strcat(bp, field[1]);
                     50:                bp = strcat(bp, "!");
                     51:                if (service!=NULL && *service!='\0')
                     52:                        bp = strcat(bp, service);
                     53:                break;
                     54: 
                     55:        case 1: bp = strcat(bp, defdialer);
                     56:                bp = strcat(bp, "!");
                     57:                bp = strcat(bp, field[0]);
                     58:                bp = strcat(bp, "!");
                     59:                if (service!=NULL && *service!='\0')
                     60:                        bp = strcat(bp, service);
                     61:                break;
                     62: 
                     63:        default:
                     64:                fprintf(stderr, "Illegal machine: %s\n", machine);
                     65:                exit(1);
                     66:        }
                     67:        if(ipcdebug)
                     68:                printf("ipcpath returning %s\n", buf);
                     69:        return buf;
                     70: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.