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

1.1       root        1: #include "../h/rt.h"
                      2: 
                      3: /*
                      4:  * upto(c,s,i,j) - find each occurrence in s[i:j] of a character in c.
                      5:  * Generates successive positions.
                      6:  */
                      7: 
                      8: Xupto(nargs, arg4, arg3, arg2, arg1, arg0)
                      9: int nargs;
                     10: struct descrip arg4, arg3, arg2, arg1, arg0;
                     11:    {
                     12:    register int i, j;
                     13:    int t;
                     14:    long l1, l2;
                     15:    int *cs, csbuf[CSETSIZE];
                     16:    char sbuf[MAXSTRING];
                     17: 
                     18:    /*
                     19:     * c must be a cset.  s defaults to &subject; i defaults to &pos if
                     20:     *  s defaulted, 1 otherwise; j defaults to 0.
                     21:     */
                     22:    if (cvcset(&arg1, &cs, csbuf) == NULL)
                     23:       runerr(104, &arg1);
                     24:    if (defstr(&arg2, sbuf, &k_subject))
                     25:       defint(&arg3, &l1, k_pos);
                     26:    else
                     27:       defint(&arg3, &l1, 1);
                     28:    defint(&arg4, &l2, 0);
                     29: 
                     30:    /*
                     31:     * Convert i and j to positions in s and order them.
                     32:     */
                     33:    i = cvpos(l1, STRLEN(arg2));
                     34:    j = cvpos(l2, STRLEN(arg2));
                     35:    if (i > j) {
                     36:       t = i;
                     37:       i = j;
                     38:       j = t;
                     39:       }
                     40: 
                     41:    /*
                     42:     * Look through s[i:j] and suspend position of each occurrence of
                     43:     *  of a character in c.
                     44:     */
                     45:    while (i < j) {
                     46:       if (tstb(STRLOC(arg2)[i-1], cs)) {
                     47:          arg0.type = D_INTEGER;
                     48:          INTVAL(arg0) = i;
                     49:          suspend();
                     50:          }
                     51:       i++;
                     52:       }
                     53:    /*
                     54:     * Eventually fail.
                     55:     */
                     56:    fail();
                     57:    }
                     58: 
                     59: Procblock(upto,4)

unix.superglobalmegacorp.com

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