Annotation of researchv10dc/cmd/post/pq.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Switch module
        !             3:  */
        !             4: 
        !             5: #include <malloc.h>
        !             6: #include "switch.h"
        !             7: 
        !             8: #define        DEFMOD  "opt", "join"
        !             9: 
        !            10: typedef struct {
        !            11:        modsw_t *mod;
        !            12:        char    *tag;
        !            13: } pq_t;
        !            14: 
        !            15: char *
        !            16: pq_open(argv)
        !            17: char   *argv[];
        !            18: {
        !            19:        register pq_t   *pq = (pq_t *) malloc(sizeof (pq_t));
        !            20:        static char     *defv[] = { DEFMOD, 0 };
        !            21: 
        !            22:        if (!argv || !argv[0])
        !            23:                argv = defv;
        !            24:        for (pq->mod = modsw; pq->mod->name; pq->mod++)
        !            25:                if (!strcmp(argv[0], pq->mod->name)) {
        !            26:                        if (pq->tag = (*pq->mod->open)(&argv[1]))
        !            27:                                return (char *) pq;
        !            28:                        break;
        !            29:                }
        !            30:        if (!pq->mod->name)
        !            31:                error(0, "pq %s: Not configured", argv[0]);
        !            32:        free((char *) pq);
        !            33:        return 0;
        !            34: }
        !            35: 
        !            36: pq_close(pq)
        !            37: pq_t   *pq;
        !            38: {
        !            39:        int rv = pq ? (*pq->mod->close)(pq->tag)
        !            40:                    : error(0, "pq: close: Not opened");
        !            41:        if (pq)
        !            42:                free((char *) pq);
        !            43:        return rv;
        !            44: }
        !            45: 
        !            46: pq_read(pq, arg, n)
        !            47: pq_t   *pq;
        !            48: char   *arg;
        !            49: {
        !            50:        return pq ? (*pq->mod->read)(pq->tag, arg, n)
        !            51:                  : error(0, "pq: read: Not opened");
        !            52: }
        !            53: 
        !            54: pq_write(pq, arg, n)
        !            55: pq_t   *pq;
        !            56: char   *arg;
        !            57: {
        !            58:        return pq ? (*pq->mod->write)(pq->tag, arg, n)
        !            59:                  : error(0, "pq: write: Not opened");
        !            60: }

unix.superglobalmegacorp.com

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