Annotation of 43BSD/contrib/icon/operators/cat.c, revision 1.1

1.1     ! root        1: #include "../h/rt.h"
        !             2: 
        !             3: /*
        !             4:  * x || y - concatenate strings x and y.
        !             5:  */
        !             6: 
        !             7: cat(nargs, arg2, arg1, arg0)
        !             8: int nargs;
        !             9: struct descrip arg2, arg1, arg0;
        !            10:    {
        !            11:    DclSave
        !            12:    char sbuf1[MAXSTRING], sbuf2[MAXSTRING];
        !            13:    extern char *alcstr();
        !            14: 
        !            15:    SetBound;
        !            16:    /*
        !            17:     * x and y must be strings.
        !            18:     */
        !            19:    if (cvstr(&arg1, sbuf1) == NULL)
        !            20:       runerr(103, &arg1);
        !            21:    if (cvstr(&arg2, sbuf2) == NULL)
        !            22:       runerr(103, &arg2);
        !            23: 
        !            24:    /*
        !            25:     * Ensure space for the resulting string.
        !            26:     */
        !            27:    sneed(STRLEN(arg1)+STRLEN(arg2));
        !            28:    if (STRLOC(arg1) + STRLEN(arg1) == sfree)
        !            29:       /*
        !            30:        * The end of x is at the end of the string space, hence, x was the
        !            31:        *  last string allocated.  x is not recopied, rather, y is appended
        !            32:        *  to the string space and the result is pointed at the start of x.
        !            33:        */
        !            34:       STRLOC(arg0) = STRLOC(arg1);
        !            35:    else
        !            36:       /*
        !            37:        * Append x to the end of the string space and point the result
        !            38:        *  at the start of x.
        !            39:        */
        !            40:       STRLOC(arg0) = alcstr(STRLOC(arg1),STRLEN(arg1));
        !            41:    /*
        !            42:     * Append y to the end of the string space.
        !            43:     */
        !            44:    alcstr(STRLOC(arg2),STRLEN(arg2));
        !            45:    /*
        !            46:     *  Set the length of the result and return.
        !            47:     */
        !            48:    STRLEN(arg0) = STRLEN(arg1) + STRLEN(arg2);
        !            49:    ClearBound;
        !            50:    }
        !            51: 
        !            52: Opblock(cat,2,"||")

unix.superglobalmegacorp.com

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