Annotation of researchv10no/cmd/lcc/ph/d411.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 - String Handling
        !            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 void d4_11_2();
        !            42: static void d4_11_3();
        !            43: void d4_11b();
        !            44: 
        !            45: 
        !            46: 
        !            47: 
        !            48: 
        !            49: 
        !            50: 
        !            51: 
        !            52: 
        !            53: static char mem1[15] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
        !            54: static char mem2[15] = {9,9,9,9,9,9,9,9,9,9,9,9,9,9,9};
        !            55: static char string1[] = "aaaaaaaaaa";
        !            56: static char string2[] = "bbbb\0bbbb";
        !            57: static char string3[] = "cccccccccc";
        !            58: static char string4[21] = "dddddddddd";
        !            59: static char string5[] = "abcdefgX\0Y";
        !            60: static char string6[] = "abcXabcX\0Y";
        !            61: static char string7[] = "oneXtwoYXthreeYYXXZZfourGFGF";
        !            62: static char string8[] = "oneXtwoYXthreeYYXXZZfourGFGF";
        !            63: static char string9[60];
        !            64: void d4_11()
        !            65:        {
        !            66: 
        !            67:        Filename = "d411.c";
        !            68:        d4_11_2();
        !            69:        d4_11_3();
        !            70:        d4_11b();
        !            71:        }
        !            72: 
        !            73: /*
        !            74:  * 4.11.2 - Copying functions
        !            75:  */
        !            76: static void d4_11_2()
        !            77:        {
        !            78: #ifndef SKIP4_112
        !            79:        int i;
        !            80:        char *p;
        !            81: 
        !            82:        /* 4.11.2.1 memcpy
        !            83:         * basic copy
        !            84:         */
        !            85:        p = memcpy(mem2, mem1, 15);
        !            86:        aequals(__LINE__, mem2, p);
        !            87:        for (i = 0; i < 15; ++i)
        !            88:                iequals(__LINE__, mem1[i], mem2[i]);
        !            89: 
        !            90: #if ANSI
        !            91:        /* 4.11.2.2 memmove
        !            92:         * "correct" memory copy.
        !            93:         * First, shift left copy
        !            94:         */
        !            95:        memmove(mem2, mem2+1, 14);
        !            96:        for (i = 0; i < 14; ++i)
        !            97:                iequals(__LINE__, mem2[i], mem1[i+1]);
        !            98:        iequals(__LINE__, mem2[14], mem1[14]);
        !            99: 
        !           100:        /* Then shift right copy */
        !           101:        memmove(mem2+1, mem2, 14);
        !           102:        for (i = 1; i < 15; ++i)
        !           103:                iequals(__LINE__, mem2[i], mem1[i]);
        !           104:        iequals(__LINE__, mem2[0], mem2[1]);
        !           105: #endif
        !           106:        /* 4.11.2.3 strcpy
        !           107:         * string copy
        !           108:         */
        !           109:        p = strcpy(string1+1, string2);
        !           110:        aequals(__LINE__, p, string1+1);
        !           111:        iequals(__LINE__, string1[0], 'a');
        !           112:        for (i = 1; i < 10; ++i)
        !           113:                if (i < 5)
        !           114:                        iequals(__LINE__, string1[i], 'b');
        !           115:                else if (i == 5)
        !           116:                        iequals(__LINE__, string1[i], 0);
        !           117:                else
        !           118:                        iequals(__LINE__, string1[i], 'a');
        !           119:        iequals(__LINE__, string1[10], 0);
        !           120: 
        !           121:        /* 4.11.2.4 strncpy
        !           122:         * string copy with count
        !           123:         */
        !           124:        p = strncpy(string1, string3, 9);
        !           125:        aequals(__LINE__, p, string1);
        !           126:        for (i = 0; i < 9; ++i)
        !           127:                iequals(__LINE__, string1[i], 'c');
        !           128:        iequals(__LINE__, string1[9], 'a');
        !           129:        iequals(__LINE__, string1[10], 0);
        !           130: 
        !           131:        /* fill with nulls if too few */
        !           132:        strncpy(string1, string2, 8);
        !           133:        for (i = 0; i < 8; ++i)
        !           134:                if (i < 4)
        !           135:                        iequals(__LINE__, string1[i], 'b');
        !           136:                else
        !           137:                        iequals(__LINE__, string1[i], 0);
        !           138:        iequals(__LINE__, string1[9], 'a');
        !           139:        iequals(__LINE__, string1[10], 0);
        !           140: #endif /* SKIP4_112 */
        !           141:        }
        !           142: 
        !           143: /*
        !           144:  * 4.11.3 - Concatenation functions
        !           145:  */
        !           146: static void d4_11_3()
        !           147:        {
        !           148: #ifndef SKIP4_113
        !           149:        int i;
        !           150:        char *p;
        !           151: 
        !           152:        /* 4.11.3.1 strcat
        !           153:         * string concatenation
        !           154:         */
        !           155:        p = strcat(string4, string3);
        !           156:        aequals(__LINE__, p, string4);
        !           157:        for (i = 0; i < 20; ++i)
        !           158:                if (i < 10)
        !           159:                        iequals(__LINE__, string4[i], 'd');
        !           160:                else
        !           161:                        iequals(__LINE__, string4[i], 'c');
        !           162:        iequals(__LINE__, string4[20], 0);
        !           163: 
        !           164:        /* 4.11.3.2 strncat
        !           165:         * string concatenation with maximum length
        !           166:         */
        !           167:        string4[10] = 0;
        !           168:        /* if there are not enough chars, then it is the same as strcat */
        !           169:        p = strncat(string4, string3, 12);
        !           170:        aequals(__LINE__, p, string4);
        !           171:        for (i = 0; i < 20; ++i)
        !           172:                if (i < 10)
        !           173:                        iequals(__LINE__, string4[i], 'd');
        !           174:                else
        !           175:                        iequals(__LINE__, string4[i], 'c');
        !           176:        iequals(__LINE__, string4[20], 0);
        !           177:        string4[10] = 0;
        !           178:        /* otherwise concatenate fewer characters */
        !           179:        strncat(string4, string3, 4);
        !           180:        for (i = 0; i < 14; ++i)
        !           181:                if (i < 10)
        !           182:                        iequals(__LINE__, string4[i], 'd');
        !           183:                else
        !           184:                        iequals(__LINE__, string4[i], 'c');
        !           185:        iequals(__LINE__, string4[14], 0);
        !           186: #endif /* SKIP4_113 */
        !           187:        }
        !           188: 
        !           189: #else /* if SKIP411 */
        !           190: void d4_11() { pr_skip("d4_11: SKIPPED ENTIRELY\n"); }
        !           191: #endif

unix.superglobalmegacorp.com

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