Annotation of 43BSDReno/games/battlestar/getcom.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1983 Regents of the University of California.
        !             3:  * All rights reserved.
        !             4:  *
        !             5:  * Redistribution and use in source and binary forms are permitted
        !             6:  * provided that: (1) source distributions retain this entire copyright
        !             7:  * notice and comment, and (2) distributions including binaries display
        !             8:  * the following acknowledgement:  ``This product includes software
        !             9:  * developed by the University of California, Berkeley and its contributors''
        !            10:  * in the documentation or other materials provided with the distribution
        !            11:  * and in all advertising materials mentioning features or use of this
        !            12:  * software. Neither the name of the University nor the names of its
        !            13:  * contributors may be used to endorse or promote products derived
        !            14:  * from this software without specific prior written permission.
        !            15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
        !            16:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
        !            17:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
        !            18:  */
        !            19: 
        !            20: #ifndef lint
        !            21: static char sccsid[] = "@(#)getcom.c   5.3 (Berkeley) 6/1/90";
        !            22: #endif /* not lint */
        !            23: 
        !            24: #include <stdio.h>
        !            25: #include <ctype.h>
        !            26: 
        !            27: char *
        !            28: getcom(buf, size, prompt, error)
        !            29:        char *buf;
        !            30:        int size;
        !            31:        char *prompt, *error;
        !            32: {
        !            33:        for (;;) {
        !            34:                fputs(prompt, stdout); 
        !            35:                if (fgets(buf, size, stdin) == 0) {
        !            36:                        clearerr(stdin);
        !            37:                        continue;
        !            38:                }
        !            39:                while (isspace(*buf))
        !            40:                        buf++;
        !            41:                if (*buf)
        !            42:                        break;
        !            43:                if (error)
        !            44:                        puts(error);
        !            45:        }
        !            46:        return (buf);
        !            47: }
        !            48: 
        !            49: 
        !            50: /*
        !            51:  * shifts to UPPERCASE if flag > 0, lowercase if flag < 0,
        !            52:  * and leaves it unchanged if flag = 0
        !            53:  */
        !            54: char *
        !            55: getword(buf1, buf2, flag)
        !            56:        register char *buf1, *buf2;
        !            57:        register flag;
        !            58: {
        !            59:        while (isspace(*buf1))
        !            60:                buf1++;
        !            61:        if (*buf1 != ',') {
        !            62:                if (!*buf1) {
        !            63:                        *buf2 = 0;
        !            64:                        return (0);
        !            65:                }
        !            66:                while (*buf1 && !isspace(*buf1) && *buf1 != ',')
        !            67:                        if (flag < 0)
        !            68:                                if (isupper(*buf1))
        !            69:                                        *buf2++ = tolower(*buf1++);
        !            70:                                else
        !            71:                                        *buf2++ = *buf1++;
        !            72:                        else if (flag > 0)
        !            73:                                if (islower(*buf1))
        !            74:                                        *buf2++ = toupper(*buf1++);
        !            75:                                else
        !            76:                                        *buf2++ = *buf1++;
        !            77:                        else
        !            78:                                *buf2++ = *buf1++;
        !            79:        } else
        !            80:                *buf2++ = *buf1++;
        !            81:        *buf2 = 0;
        !            82:        while (isspace(*buf1))
        !            83:                buf1++;
        !            84:        return (*buf1 ? buf1 : 0);
        !            85: }

unix.superglobalmegacorp.com

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