Annotation of coherent/a/usr/bob/uusrc/modemcap/mgetent.c, revision 1.1

1.1     ! root        1: #include <stdio.h>
        !             2: 
        !             3: char   *__modemcap;
        !             4: char   *MODEMCAP = "/etc/modemcap";
        !             5: 
        !             6: static isent (ent, name)
        !             7: char   *ent;
        !             8: char   *name;
        !             9: {
        !            10:        char    buf[16];
        !            11:        register int    i;
        !            12: 
        !            13:        while (*ent != ':' && *ent != 0) {
        !            14:                for (i = 0;*ent != ':' && *ent != '|' && *ent != 0 && i < 15;i++)
        !            15:                        buf[i] = *ent++;
        !            16: 
        !            17:                if (*ent == '|')
        !            18:                        ent++;
        !            19: 
        !            20:                buf[i] = 0;
        !            21:                if (strcmp (buf, name) == 0)
        !            22:                        return (1);
        !            23:        }
        !            24:        return (0);
        !            25: }
        !            26: 
        !            27: mgetent (bp, name)
        !            28: char   *bp;
        !            29: char   *name;
        !            30: {
        !            31:        static  char    buf[1024];
        !            32:        register char   *cp;
        !            33:        register FILE   *modemcap;
        !            34:        register int    i;
        !            35:        char    *getenv ();
        !            36: 
        !            37:        if ((cp = getenv ("MODEMCAP")) != NULL) {
        !            38:                if (*cp != '/') {
        !            39:                        if (isent (cp, name)) {
        !            40:                                strcpy (buf, cp);
        !            41:                                return (1);
        !            42:                        }
        !            43:                }
        !            44:                MODEMCAP = cp;
        !            45:        }
        !            46:        if ((modemcap = fopen (MODEMCAP, "r")) == NULL)
        !            47:                return (-1);
        !            48: 
        !            49:        while (fgets (buf, 512, modemcap) != NULL) {
        !            50:                if (buf[0] == '#')              /* skip all comment lines*/
        !            51:                        continue;
        !            52: 
        !            53:                i = strlen (buf) - 1;           /* find last character in line*/
        !            54:                buf[i] = 0;                     /* remove trailing newline*/
        !            55:                if (i == 0)                     /* ignore blank lines   */
        !            56:                        continue;
        !            57: 
        !            58:                while (buf[(i = strlen (buf) - 1)] == '\\') {   /* is last character a \\, still more*/
        !            59:                        cp = &buf[i];           /* find last character  */
        !            60:                        cp[0] = 0;              /* nullify, end of this part*/
        !            61:                        if (fgets (cp, 512, modemcap) == NULL)  /* end of file? ...     */
        !            62:                                break;          /* ... end of entry     */
        !            63: 
        !            64:                        cp[strlen (cp) - 1] = 0;/* remove trailing newline*/
        !            65:                        if (cp[0] == '#') {     /* comment line? ...    */
        !            66:                                cp[0] = 0;      /* remove that line     */
        !            67:                                continue;       /* go get another line  */
        !            68:                        }
        !            69:                }
        !            70:                if (isent (buf, name)) {
        !            71:                        __modemcap = bp;
        !            72:                        strcpy (bp, buf);
        !            73:                        fclose (modemcap);
        !            74:                        return (1);
        !            75:                }
        !            76:        }
        !            77:        fclose (modemcap);
        !            78:        return (0);
        !            79: }

unix.superglobalmegacorp.com

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