Пример #1
0
complex complex::parsevalue(str *s) {
    complex mult;

    if ((!___bool(s))) {
        return mcomplex(0.0, 0.0);
    }
    mult = mcomplex(1.0, 0.0);
    if (__eq(s->__getitem__((-1)), new str("j"))) {
        s = s->__slice__(2, 0, (-1), 0);
        mult = mcomplex(0.0, 1.0);
    }
    if (((new list<str *>(2, new str("+"), new str("-"))))->__contains__(s)) {
        s = s->__iadd__(new str("1"));
    }
    return mult * __float(s);
}
Пример #2
0
template <class B> str *filter(B (*func)(str *), str *a) {
    str *result = new str();
    int size = len(a);
    char e;
    str *c;
    for(int i=0; i<size; i++) {
        e = a->unit[i];
        if(func) {
            c = __char_cache[((unsigned char)e)];
            if(___bool((*func)(c)))
                result->unit.push_back(e);
        } else 
            result->unit.push_back(e);
    }
    return result;
}
Пример #3
0
tuple2<str *, str *> *split(str *p) {
    /**
    Split a pathname.  Returns tuple "(head, tail)" where "tail" is
    everything after the final slash.  Either part may be empty.
    */
    str *__7, *__8, *head, *tail;
    __ss_int i;

    i = (p->rfind(const_4)+1);
    __7 = p->__slice__(2, 0, i, 0);
    __8 = p->__slice__(1, i, 0, 0);
    head = __7;
    tail = __8;
    if ((___bool(head) && __ne(head, (const_4)->__mul__(len(head))))) {
        head = head->rstrip(const_4);
    }
    return (new tuple2<str *, str *>(2, head, tail));
}
Пример #4
0
__ss_bool DynamInt::__eq__(DynamInt *num) {
    /**
    Overloaded == function
    Checks if this DynamInt is equal to this one
    
    @param  num reference to an existing DynamInt
    @return added DynamInt
    */
    str *lhs, *rhs;
    __ss_bool compare;
    int i, j;

    if ((this->size>num->size)) {
        return False;
    }
    else if ((this->size<num->size)) {
        return False;
    }
    j = (this->size-1);
    i = (num->size-1);
    lhs = this->data;
    rhs = num->data;

    while ((i>=0)) {
        /**
         Have we run out of bottom digits ? 
        */
        if ((j>=0)) {
            compare = ___bool(__ne(lhs->__getitem__(i), rhs->__getitem__(i)));
            if (compare) {
                return False;
            }
            j = (j-1);
        }
        else {
            /**
             No more bottom digits, add any leftover carryover
            */
            return False;
        }
        i = (i-1);
    }
    return True;
}
Пример #5
0
str *commonprefix(list<str *> *m) {
    /**
    Given a list of pathnames, returns the longest common leading component
    */
    str *s1, *s2;
    __ss_int __11, __12, i, n;

    if ((!___bool(m))) {
        return const_0;
    }
    s1 = ___min(1, 0, m);
    s2 = ___max(1, 0, m);
    n = ___min(2, 0, len(s1), len(s2));

    FAST_FOR(i,0,n,1,11,12)
        if (__ne(s1->__getitem__(i), s2->__getitem__(i))) {
            return s1->__slice__(2, 0, i, 0);
        }
    END_FOR

    return s1->__slice__(2, 0, n, 0);
}
Пример #6
0
tuple2<list<tuple2<str *, str *> *> *, list<str *> *> *gnu_getopt(list<str *> *args, str *shortopts, pyiter<str *> *longopts) {
    /**
    getopt(args, options[, long_options]) -> opts, args

    This function works like getopt(), except that GNU style scanning
    mode is used by default. This means that option and non-option
    arguments may be intermixed. The getopt() function stops
    processing options as soon as a non-option argument is
    encountered.

    If the first character of the option string is `+', or if the
    environment variable POSIXLY_CORRECT is set, then option
    processing stops as soon as a non-option argument is encountered.

    */
    list<str *> *prog_args;
    list<tuple2<str *, str *> *> *opts;
    __ss_int all_options_first;
    tuple2<list<tuple2<str *, str *> *> *, list<str *> *> *__5, *__6;

    opts = (new list<tuple2<str *, str *> *>());
    prog_args = (new list<str *>());
    longopts = new list<str *>(longopts);
    if (shortopts->startswith(const_3)) {
        shortopts = shortopts->__slice__(1, 1, 0, 0);
        all_options_first = 1;
    }
    else if (___bool((__os__::__ss_environ)->get(const_4))) {
        all_options_first = 1;
    }
    else {
        all_options_first = 0;
    }

    while(___bool(args)) {
        if (__eq(args->__getfast__(0), const_2)) {
            prog_args = prog_args->__iadd__(args->__slice__(1, 1, 0, 0));
            break;
        }
        if (__eq((args->__getfast__(0))->__slice__(2, 0, 2, 0), const_2)) {
            __5 = do_longs(opts, (args->__getfast__(0))->__slice__(1, 2, 0, 0), longopts, args->__slice__(1, 1, 0, 0));
            opts = __5->__getfirst__();
            args = __5->__getsecond__();
        }
        else if (__eq((args->__getfast__(0))->__slice__(2, 0, 1, 0), const_1)) {
            __6 = do_shorts(opts, (args->__getfast__(0))->__slice__(1, 1, 0, 0), shortopts, args->__slice__(1, 1, 0, 0));
            opts = __6->__getfirst__();
            args = __6->__getsecond__();
        }
        else {
            if (all_options_first) {
                prog_args = prog_args->__iadd__(args);
                break;
            }
            else {
                prog_args->append(args->__getfast__(0));
                args = args->__slice__(1, 1, 0, 0);
            }
        }
    }
    return (new tuple2<list<tuple2<str *, str *> *> *, list<str *> *>(2, opts, prog_args));
}
Пример #7
0
__ss_int writer::join_append_data(str *field, __ss_int quote_empty, __ss_int quoted) {
    str *lineterm;
    Excel *dialect;
    __ss_int __17, __18, __19, __20, __21, __22, __23, want_escape;

    dialect = this->dialect;
    lineterm = dialect->lineterminator;
    if ((this->num_fields>0)) {
        (this->rec)->append(dialect->delimiter);
    }
    if (quoted) {
        (this->rec)->append(dialect->quotechar);
    }

    str *c;
    str::for_in_loop __3;
    int __2;
    str *__1;
    FOR_IN_NEW(c,field,1,2,3)
        want_escape = 0;
        if (__eq(c, const_7)) {
            break;
        }
        if (__OR(__eq(c, dialect->delimiter), __OR(__eq(c, dialect->escapechar), __OR(__eq(c, dialect->quotechar), lineterm->__contains__(c), 20), 19), 18)) {
            if ((dialect->quoting==QUOTE_NONE)) {
                want_escape = 1;
            }
            else {
                if (__eq(c, dialect->quotechar)) {
                    if (dialect->doublequote) {
                        (this->rec)->append(dialect->quotechar);
                    }
                    else {
                        want_escape = 1;
                    }
                }
                if ((!want_escape)) {
                    quoted = 1;
                }
            }
            if (want_escape) {
                if ((!___bool(dialect->escapechar))) {
                    throw ((new Error(const_18)));
                }
                (this->rec)->append(dialect->escapechar);
            }
        }
        (this->rec)->append(c);
    END_FOR

    if (__AND((!___bool(field)), quote_empty, 22)) {
        if ((dialect->quoting==QUOTE_NONE)) {
            throw ((new Error(const_19)));
        }
        else {
            quoted = 1;
        }
    }
    if (quoted) {
        (this->rec)->append(dialect->quotechar);
    }
    return quoted;
}
Пример #8
0
__ss_bool DynamInt::__gt__(DynamInt *num) {
    /**
    Overloaded > function
    Checks if this DynamInt is greater than existing DynamInt
    
    @param  num reference to an existing DynamInt
    @return added DynamInt
    */
    str *lhs, *rhs;
    __ss_bool greater;
    int i, j;

    /**
    Performs greater than function by applying > function on each pair of integers 
    i.e
    to find which is 12345 is greater than 1234, the code makes a configuration similar to
    
            1  0  3  4  5
          >    1  2  3  4
            -------------
            T  F  T  T  T
            -------------
    Where T refers to True, F to False
    It uses the last compare value, in this case, T which means 10345 is greater than 1234
    Another example,
             1  0  3  4  5
        >    9  2  3  4  0
             -------------
             F  F  T  T  T
             -------------
    In this case it uses False, since 10345 is less than 92340
    */
    if (__eq(this, num)) {
        return False;
    }
    if ((this->size>num->size)) {
        return True;
    }
    else if ((this->size<num->size)) {
        return False;
    }
    /**
    Temporary Variables used in addition process
    */
    greater = False;
    j = (this->size-1);
    i = (num->size-1);
    lhs = this->data;
    rhs = num->data;

    while ((i>=0)) {
        /**
         Have we run out of bottom digits ? 
        */
        if ((j>=0)) {
            greater = ___bool(__gt(lhs->__getitem__(i), rhs->__getitem__(i)));
            j = (j-1);
        }
        else {
            /**
             No more bottom digits, add any leftover carryover
            */
            greater = True;
        }
        i = (i-1);
    }
    return greater;
}