Annotation of 43BSDReno/contrib/isode-beta/dsap/common/fax.c, revision 1.1

1.1     ! root        1: /* fax.c - facsimileTelephoneNumber attribute */
        !             2: 
        !             3: #ifndef        lint
        !             4: static char *rcsid = "$Header: /f/osi/dsap/common/RCS/fax.c,v 7.0 89/11/23 21:42:12 mrose Rel $";
        !             5: #endif
        !             6: 
        !             7: /* 
        !             8:  * $Header: /f/osi/dsap/common/RCS/fax.c,v 7.0 89/11/23 21:42:12 mrose Rel $
        !             9:  *
        !            10:  *
        !            11:  * $Log:       fax.c,v $
        !            12:  * Revision 7.0  89/11/23  21:42:12  mrose
        !            13:  * Release 6.0
        !            14:  * 
        !            15:  */
        !            16: 
        !            17: /*
        !            18:  *                               NOTICE
        !            19:  *
        !            20:  *    Acquisition, use, and distribution of this module and related
        !            21:  *    materials are subject to the restrictions of a license agreement.
        !            22:  *    Consult the Preface in the User's Manual for the full terms of
        !            23:  *    this agreement.
        !            24:  *
        !            25:  */
        !            26: 
        !            27: 
        !            28: /* 
        !            29:        SYNTAX 
        !            30:        fax ::= <printablestring> [ <parameters> ]
        !            31:        parameters ::= <parm> | <parm> $ <parameters>
        !            32:        <parm> ::= "twoDimensional" | "fineResolution" | "unlimitedLength" |
        !            33:                   "b4Length" | "a3Width" | "b4Width" | "uncompressed"
        !            34: 
        !            35:        EXAMPLE
        !            36:                123-4567 $ twoDimensional
        !            37: */
        !            38: 
        !            39: /* LINTLIBRARY */
        !            40: 
        !            41: #include "quipu/util.h"
        !            42: #include "quipu/entry.h"
        !            43: 
        !            44: /*  */
        !            45: 
        !            46: struct pair {
        !            47:     char   *p_name;
        !            48:     int            p_value;
        !            49: };
        !            50: 
        !            51: static struct pair pairs[] = {
        !            52:     "twoDimensional", 8,
        !            53:     "fineResolution", 9,
        !            54:     "unlimitedLength", 20,
        !            55:     "b4Length", 21,
        !            56:     "a3Width", 22,
        !            57:     "b4Width", 23,
        !            58:     "uncompressed", 30,
        !            59: 
        !            60:     NULL
        !            61: };
        !            62: 
        !            63: /*  */
        !            64: 
        !            65: static fax_free (f)
        !            66: register struct fax *f;
        !            67: {
        !            68:     free (f -> number);
        !            69: 
        !            70:     if (f -> bits)
        !            71:        pe_free (f -> bits);
        !            72: 
        !            73:     free ((char *) f);
        !            74: }
        !            75: 
        !            76: /*  */
        !            77: 
        !            78: static struct fax *fax_cpy (a)
        !            79: register struct fax *a;
        !            80: {
        !            81:     register struct fax *f;
        !            82: 
        !            83:     f = (struct fax *) smalloc (sizeof *f);
        !            84: 
        !            85:     f -> number = strdup (a -> number);
        !            86:     f -> bits = a -> bits ? pe_cpy (a -> bits) : NULLPE;
        !            87: 
        !            88:     return f;
        !            89: }
        !            90: 
        !            91: /*  */
        !            92: 
        !            93: static int  fax_cmp (a, b)
        !            94: register struct fax *a;
        !            95: register struct fax *b;
        !            96: {
        !            97:     int            i;
        !            98: 
        !            99:     if (a == (struct fax *) NULL)
        !           100:        return (b ? -1 : 0);
        !           101:     else
        !           102:        if  (b == (struct fax *) NULL)
        !           103:            return 1;
        !           104: 
        !           105:     if (i = telcmp (a -> number, b -> number))
        !           106:        return i;
        !           107: 
        !           108:     return pe_cmp (a -> bits, b -> bits);
        !           109: }
        !           110: 
        !           111: /*  */
        !           112: 
        !           113: static fax_print (ps, f, format)
        !           114: register PS ps;
        !           115: register struct fax *f;
        !           116: int    format;
        !           117: {
        !           118:     register int   i;
        !           119:     register struct pair *p;
        !           120:     register PE    pe;
        !           121: 
        !           122:     if (format == READOUT) {
        !           123:        ps_printf (ps, "%s", f -> number);
        !           124: 
        !           125:        if ((pe = f -> bits) && (i = pe -> pe_nbits) > 0) {
        !           126:            char    *cp = " {";
        !           127: 
        !           128:            while (i-- >= 0)
        !           129:                if (bit_test (pe, i) > OK) {
        !           130:                    for (p = pairs; p -> p_name; p++)
        !           131:                        if (p -> p_value == i)
        !           132:                            break;
        !           133:                    if (p -> p_name)
        !           134:                        ps_printf (ps, "%s %s", cp, p -> p_name);
        !           135:                    else
        !           136:                        ps_printf (ps, "%s %d", cp, i);
        !           137:                    cp = ",";
        !           138:                }
        !           139: 
        !           140:            if (*cp == ',')
        !           141:                ps_print (ps, " }");
        !           142:        }
        !           143:     }
        !           144:     else {
        !           145:        ps_printf (ps, "%s", f -> number);
        !           146: 
        !           147:        if ((pe = f -> bits) && (i = pe -> pe_nbits) > 0) {
        !           148:            char    *cp = " $";
        !           149: 
        !           150:            while (i-- >= 0)
        !           151:                if (bit_test (pe, i) > OK) {
        !           152:                    for (p = pairs; p -> p_name; p++)
        !           153:                        if (p -> p_value == i)
        !           154:                            break;
        !           155:                    if (p -> p_name)
        !           156:                        ps_printf (ps, "%s %s", cp, p -> p_name);
        !           157:                    else
        !           158:                        ps_printf (ps, "%s %d", cp, i);
        !           159:                    cp = "";
        !           160:                }
        !           161:        }
        !           162:     }
        !           163: }
        !           164: 
        !           165: /*  */
        !           166: 
        !           167: char   *TidyString ();
        !           168: 
        !           169: static struct fax *str2fax (str)
        !           170: register char  *str;
        !           171: {
        !           172:     int            value;
        !           173:     register char  *ptr,
        !           174:                  **ap;
        !           175:     char   *vec[NVEC + 1];
        !           176:     register struct fax *f;
        !           177:     register struct pair *p;
        !           178: 
        !           179:     f = (struct fax *) smalloc (sizeof *f);
        !           180: 
        !           181:     if (ptr = index (str, '$'))
        !           182:        *ptr = NULL;
        !           183:     if (strlen (str) > UB_TELEPHONE_NUMBER) {
        !           184:        parse_error ("fax phone number too big",NULLCP);
        !           185:        free ((char *) f);
        !           186:         return ((struct fax *) NULL);
        !           187:     }
        !           188:     f -> number = TidyString (strdup (str));
        !           189:     f -> bits = NULLPE;
        !           190: 
        !           191:     if (!ptr)
        !           192:        return f;
        !           193: 
        !           194:     *ptr++ = '$';
        !           195:     ptr = strdup (ptr);
        !           196: 
        !           197:     bzero ((char *) vec, sizeof vec);
        !           198:     (void) str2vec (ptr, vec);
        !           199: 
        !           200:     for (ap = vec; *ap; ap++) {
        !           201:        if (sscanf (*ap, "%d", &value) == 1 && value >= 0)
        !           202:            goto got_value;
        !           203: 
        !           204:        for (p = pairs; p -> p_name; p++)
        !           205:            if (lexequ (p -> p_name, *ap) == 0)
        !           206:                break;
        !           207:        if (! p -> p_name) {
        !           208:            parse_error ("unknown G3fax non-basic parameter: '%s'", *ap);
        !           209: 
        !           210: you_lose: ;
        !           211:            free (ptr);
        !           212:            free (f -> number);
        !           213:            if (f -> bits)
        !           214:                pe_free (f -> bits);
        !           215:            free ((char *) f);
        !           216: 
        !           217:            return ((struct fax *) NULL);
        !           218:        }
        !           219:        value = p -> p_value;
        !           220: 
        !           221: got_value: ;
        !           222:        if ((f -> bits == NULLPE
        !           223:                    && (f -> bits = prim2bit (pe_alloc (PE_CLASS_UNIV,
        !           224:                                                        PE_FORM_PRIM,
        !           225:                                                        PE_PRIM_BITS)))
        !           226:                            == NULLPE)
        !           227:                || bit_on (f -> bits, value) == NOTOK) {
        !           228: no_allocate: ;
        !           229:            parse_error ("unable to allocate G3fax non-basic parameter",NULLCP);
        !           230:            goto you_lose;
        !           231:        }
        !           232:     }
        !           233: 
        !           234:     if (bit2prim (f -> bits) == NULLPE)
        !           235:        goto no_allocate;
        !           236: 
        !           237:     free (ptr);
        !           238: 
        !           239:     return f;
        !           240: }
        !           241: 
        !           242: /*  */
        !           243: 
        !           244: static PE  fax_enc (f)
        !           245: struct fax *f;
        !           246: {
        !           247:     PE pe = NULLPE;
        !           248: 
        !           249:     (void) encode_SA_FacsimileTelephoneNumber (&pe, 0, 0, NULLCP, f);
        !           250: 
        !           251:     return pe;
        !           252: }
        !           253: 
        !           254: /*  */
        !           255: 
        !           256: static struct fax *fax_dec (pe)
        !           257: PE     pe;
        !           258: {
        !           259:     struct fax *f;
        !           260: 
        !           261:     f = (struct fax *) smalloc (sizeof *f);
        !           262: 
        !           263:     if (decode_SA_FacsimileTelephoneNumber (pe, 1, NULLIP, NULLVP, f)
        !           264:            == NOTOK) {
        !           265:        free ((char *) f);
        !           266:        return ((struct fax *) NULL);
        !           267:     }
        !           268: 
        !           269:     return f;
        !           270: }
        !           271: 
        !           272: /*  */
        !           273: 
        !           274: fax_syntax () {
        !           275:     (void) add_attribute_syntax ("FacsimileTelephoneNumber",
        !           276:                                 (IFP) fax_enc, (IFP) fax_dec,
        !           277:                                 (IFP) str2fax, fax_print,
        !           278:                                 (IFP) fax_cpy, fax_cmp,
        !           279:                                 fax_free,      NULLCP,
        !           280:                                 NULLIFP,       TRUE);
        !           281: }

unix.superglobalmegacorp.com

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