Annotation of 43BSD/contrib/icon/functions/reverse.c, revision 1.1.1.1

1.1       root        1: #include "../h/rt.h"
                      2: 
                      3: /*
                      4:  * reverse(s) - reverse string s.
                      5:  */
                      6: 
                      7: Xreverse(nargs, arg1, arg0)
                      8: int nargs;
                      9: struct descrip arg1, arg0;
                     10:    {
                     11:    register char c, *floc, *lloc;
                     12:    register int slen;
                     13:    char sbuf[MAXSTRING];
                     14:    extern char *alcstr();
                     15: 
                     16:    /*
                     17:     * Make sure that s is a string.
                     18:     */
                     19:    if (cvstr(&arg1, sbuf) == NULL)
                     20:       runerr(103, &arg1);
                     21: 
                     22:    /*
                     23:     * Ensure that there is enough room and allocate a copy of s.
                     24:     */
                     25:    slen = STRLEN(arg1);
                     26:    sneed(slen);
                     27:    STRLEN(arg0) = slen;
                     28:    STRLOC(arg0) = alcstr(STRLOC(arg1), slen);
                     29: 
                     30:    /*
                     31:     * Point floc at the start of s and lloc at the end of s.  Work floc
                     32:     *  and sloc along s in opposite directions, swapping the characters
                     33:     *  at floc and lloc.
                     34:     */
                     35:    floc = STRLOC(arg0);
                     36:    lloc = floc + --slen;
                     37:    while (floc < lloc) {
                     38:       c = *floc;
                     39:       *floc++ = *lloc;
                     40:       *lloc-- = c;
                     41:       }
                     42:    }
                     43: 
                     44: Procblock(reverse,1)

unix.superglobalmegacorp.com

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