Annotation of researchv10no/cmd/lcc/ph/d411b.c, revision 1.1

1.1     ! root        1: /* The Plum Hall Validation Suite for C
        !             2:  * Unpublished copyright (c) 1986-1991, Chiron Systems Inc and Plum Hall Inc.
        !             3:  * VERSION: 4
        !             4:  * DATE: 1993-01-01
        !             5:  * The "ANSI" mode of this suite corresponds to official ANSI C, X3.159-1989.
        !             6:  * As per your license agreement, your distribution is not to be moved or copied outside the Designated Site
        !             7:  * without specific permission from Plum Hall Inc.
        !             8:  */
        !             9: 
        !            10: 
        !            11: #include "flags.h"
        !            12: #ifndef SKIP411
        !            13: #define LIB_TEST 1
        !            14: #include "defs.h"
        !            15: 
        !            16: /*
        !            17:  * 4.11(b) - String Handling (continued)
        !            18:  */
        !            19: 
        !            20: #if ANSI
        !            21: #include <stddef.h>
        !            22: #include <string.h>
        !            23: #else
        !            24: #if ALL_STRING_FNS
        !            25: char *memcpy();
        !            26: char *memset();
        !            27: char *strcpy();
        !            28: char *strncpy();
        !            29: char *strcat();
        !            30: char *strncat();
        !            31: char *memchr();
        !            32: char *strchr();
        !            33: char *strrchr();
        !            34: char *strpbrk();
        !            35: char *strtok();
        !            36: int strspn();
        !            37: int strcspn();
        !            38: #endif
        !            39: #endif
        !            40: 
        !            41: static char mem1[15] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
        !            42: static char mem2[15] = {9,9,9,9,9,9,9,9,9,9,9,9,9,9,9};
        !            43: static char string1[] = "aaaaaaaaaa";
        !            44: static char string2[] = "aaaa\0bbbb";
        !            45: static char string3[] = "cccccccccc";
        !            46: static char string4[21] = "dddddddddd";
        !            47: static char string5[] = "abcdefgX\0Y";
        !            48: static char string6[] = "abcXabcX\0Y";
        !            49: static char string7[] = "oneXtwoYXthreeYYXXZZfourGFGF";
        !            50: static char string8[] = "oneXtwoYXthreeYYXXZZfourGFGF";
        !            51: static char string9[60];
        !            52: static void d4_11_4();
        !            53: static void d4_11_5();
        !            54: static void d4_11_6();
        !            55: void d4_11b()
        !            56:        {
        !            57:        Filename = "d411b.c";
        !            58:        d4_11_4();
        !            59:        d4_11_5();
        !            60:        d4_11_6();
        !            61:        }
        !            62: 
        !            63: 
        !            64: /*
        !            65:  * 4.11.4 - Comparison functions
        !            66:  */
        !            67: static void d4_11_4()
        !            68:        {
        !            69: #ifndef SKIP4_114
        !            70:        int i;
        !            71:        char *p;
        !            72: 
        !            73:        /* 4.11.4.1 memcmp
        !            74:         * memory compare
        !            75:         */
        !            76:        checkthat(__LINE__, memcmp(string4, string3, 5) > 0);
        !            77:        checkthat(__LINE__, memcmp(string3, string4, 5) < 0);
        !            78:        checkthat(__LINE__, memcmp(string1, string2, 4) == 0);
        !            79: 
        !            80:        /* 4.11.4.2 strcmp
        !            81:         * string compare
        !            82:         */
        !            83:        checkthat(__LINE__, strcmp("bbc", "abc") > 0);
        !            84:        checkthat(__LINE__, strcmp("abc", "bbc") < 0);
        !            85:        checkthat(__LINE__, strcmp("hi ma", "hi ma") == 0);
        !            86: 
        !            87:        /* 4.11.4.4 strncmp
        !            88:         * string compare with length
        !            89:         */
        !            90:        checkthat(__LINE__, strncmp("bbc", "abc", 1) > 0);
        !            91:        checkthat(__LINE__, strncmp("abc", "bbc", 1) < 0);
        !            92:        checkthat(__LINE__, strncmp("hi max", "hi may", 5) == 0);
        !            93: 
        !            94: #if ANSI8612
        !            95:        /* 4.11.4.5 strxfrm
        !            96:         * make the string collatable through strcmp, memcmp.
        !            97:         * This is implementation dependent. For the "C" locale, this 
        !            98:         * just copies the source into the target, if space permits.
        !            99:         */
        !           100: 
        !           101:         checkthat(__LINE__, strxfrm(string9, string8, 60) > 0);
        !           102:         iequals(- __LINE__, strcmp(string9, string8), 0);
        !           103: 
        !           104:        /* 4.11.4.3 strcoll
        !           105:         * implementation dependent
        !           106:         */
        !           107:        iequals(- __LINE__, strcoll(string9, string8), 0);
        !           108: #if ANSI8706
        !           109:        checkthat(__LINE__, strxfrm(string9, "abc", 2) == 3);   /* ANSI8706: now returns required length */
        !           110: #endif
        !           111: #endif
        !           112: #endif /* SKIP4_114 */
        !           113:        }
        !           114: 
        !           115: 
        !           116: /*
        !           117:  * 4.11.5 - Search functions
        !           118:  */
        !           119: static void d4_11_5()
        !           120:        {
        !           121: #ifndef SKIP4_115
        !           122:        int i;
        !           123:        char *p;
        !           124: 
        !           125:        /* 4.11.5.1 memchr
        !           126:         * search memory
        !           127:         */
        !           128:        p = memchr(string5, 'X', 10);
        !           129:        aequals(__LINE__, p, string5+7);
        !           130:        p = memchr(string5, 'X', 3);
        !           131:        aequals(__LINE__, p, (char *)0);
        !           132:        p = memchr(string5, 'Y', 10);
        !           133:        aequals(__LINE__, p, string5+9);
        !           134:        p = memchr(string5, 'Z', 8);
        !           135:        aequals(__LINE__, p, (char *)0);
        !           136: 
        !           137:        /* 4.11.5.2 strchr
        !           138:         * search strings
        !           139:         */
        !           140:        p = strchr(string5, 'X');
        !           141:        aequals(__LINE__, p, string5+7);
        !           142:        p = strchr(string5, 'Y');
        !           143:        aequals(__LINE__, p, (char *)0);
        !           144: 
        !           145:        /* 4.11.5.3 strcspn
        !           146:         * count number of leading characters not in set
        !           147:         */
        !           148:        iequals(__LINE__, strcspn(string5, string5), 0);
        !           149:        iequals(__LINE__, strcspn(string5, "ABC"), 8);
        !           150:        iequals(__LINE__, strcspn(string5, "ABCX"), 7);
        !           151: 
        !           152:        /* 4.11.5.4 strpbrk
        !           153:         * get pointer to first character in the set
        !           154:         */
        !           155:        p = strpbrk(string5, string5);
        !           156:        aequals(__LINE__, p, string5);
        !           157:        p = strpbrk(string5, "ABC");
        !           158:        aequals(__LINE__, p, (char *)0);
        !           159:        p = strpbrk(string5, "ABCX");
        !           160:        aequals(__LINE__, p, string5+7);
        !           161: 
        !           162:        /* 4.11.5.5 strrchr
        !           163:         * locate last occurrence of character in a string
        !           164:         */
        !           165:        p = strrchr(string6, 'Y');
        !           166:        aequals(__LINE__, p, (char *)0);
        !           167:        p = strrchr(string6, 'X');
        !           168:        aequals(__LINE__, p, string6+7);
        !           169: 
        !           170:        /* 4.11.5.6 strspn
        !           171:         * length of segment consisting of characters in set
        !           172:         */
        !           173:        iequals(__LINE__, strspn(string6, "ABC"), 0);
        !           174:        iequals(__LINE__, strspn(string6, "cba"), 3);
        !           175:        iequals(__LINE__, strspn(string6, "cXba"), 8);
        !           176: 
        !           177:        /* 4.11.5.7 strstr
        !           178:         * locate a substring
        !           179:         */
        !           180: #if ANSI
        !           181:        aequals(__LINE__, strstr(string8, "one"), string8+0);
        !           182:        aequals(__LINE__, strstr(string8, "YX"), string8+7);
        !           183:        aequals(__LINE__, strstr(string8, "GFGF"), string8+24);
        !           184:        aequals(__LINE__, strstr(string8, "not there"), NULL);
        !           185:        aequals(__LINE__, strstr(string8, ""), string8);        /* ANSI8703: was previously vague */
        !           186: 
        !           187: #endif
        !           188:        /* 4.11.5.8 strtok
        !           189:         * string parsing
        !           190:         */
        !           191:        p = strtok(string7, "YX");
        !           192:        checkthat(__LINE__, strcmp(p, "one") == 0);
        !           193:        p = strtok((char *)0, "YZ");
        !           194:        checkthat(__LINE__, strcmp(p, "two") == 0);
        !           195:        p = strtok((char *)0, "ZYX");
        !           196:        checkthat(__LINE__, strcmp(p, "three") == 0);
        !           197:        p = strtok((char *)0, "ZYXFGHIJ");
        !           198:        checkthat(__LINE__, strcmp(p, "four") == 0);
        !           199:        /* this should detect that despite the "space", no token remains */
        !           200:        p = strtok((char *)0, "FGHIJ");
        !           201:        aequals(__LINE__, p, (char *)0);
        !           202:        /* re-initialize */
        !           203:        p = strtok(string8, "XY");
        !           204:        checkthat(__LINE__, strcmp(p, "one") == 0);
        !           205:        /* check for nothing available at first parse */
        !           206:        p = strtok("XYZ", "XYZ");
        !           207:        aequals(__LINE__, p, (char *)0);
        !           208: #endif /* SKIP4_115 */
        !           209:        }
        !           210: 
        !           211: /*
        !           212:  * 4.11.6 - Miscellaneous functions
        !           213:  */
        !           214: static void d4_11_6()
        !           215:        {
        !           216: #ifndef SKIP4_116
        !           217:        int i;
        !           218:        char *p;
        !           219: 
        !           220:        /* 4.11.6.1 memset
        !           221:         * memory fill
        !           222:         */
        !           223:        memcpy(mem2, mem1, 15);
        !           224:        p = memset(mem2+1, 99, 4);
        !           225:        aequals(__LINE__, mem2+1, p);
        !           226:        for (i = 0; i < 15; ++i)
        !           227:                if (1 <= i && i <= 4)
        !           228:                        iequals(__LINE__, mem2[i], 99);
        !           229:                else
        !           230:                        iequals(__LINE__, mem1[i], mem2[i]);
        !           231: #if ANSI
        !           232:        /* 4.11.6.2 strerror
        !           233:         * map to an error message string. Since the string
        !           234:         * is implementation defined, we can only check for existance.
        !           235:         */
        !           236:        p = strerror(0);
        !           237: #endif
        !           238:        /* 4.11.6.3 strlen
        !           239:         * find string length
        !           240:         */
        !           241:        iequals(__LINE__, strlen("123456789"), 9);
        !           242:        iequals(__LINE__, strlen(""), 0);
        !           243: #endif /* SKIP4_116 */
        !           244:        }
        !           245: 
        !           246: 
        !           247: #endif /* SKIP411 */

unix.superglobalmegacorp.com

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