示例#1
0
文件: path.cpp 项目: GINK03/shedskin
str *joinl(list<str *> *l) {
    /**
    Join two or more pathname components, inserting "\" as needed
    */
    list<str *> *__3, *__4, *p;
    list<str *>::for_in_loop __123;
    __iter<str *> *__5;
    str *__2, *b, *path;
    __ss_int __10, __11, __12, __13, __14, __6, __7, __8, __9, b_wins;

    __2 = l->__getfast__(0);
    __3 = l->__slice__(1, 1, 0, 0);
    path = __2;
    p = __3;

    FOR_IN(b,p,4,6,123)
        b_wins = 0;
        if (__eq(path, const_1)) {
            b_wins = 1;
        }
        else if (isabs(b)) {
            if (__OR(__ne(path->__slice__(3, 1, 2, 0), const_19), __eq(b->__slice__(3, 1, 2, 0), const_19), 7)) {
                b_wins = 1;
            }
            else if (__OR((len(path)>3), __AND((len(path)==3), (!(const_18)->__contains__(path->__getitem__(-1))), 10), 9)) {
                b_wins = 1;
            }
        }
        if (b_wins) {
            path = b;
        }
        else {
            ASSERT((len(path)>0), 0);
            if ((const_18)->__contains__(path->__getitem__(-1))) {
                if ((___bool(b) && (const_18)->__contains__(b->__getitem__(0)))) {
                    path = path->__iadd__(b->__slice__(1, 1, 0, 0));
                }
                else {
                    path = path->__iadd__(b);
                }
            }
            else if (__eq(path->__getitem__(-1), const_19)) {
                path = path->__iadd__(b);
            }
            else if (___bool(b)) {
                if ((const_18)->__contains__(b->__getitem__(0))) {
                    path = path->__iadd__(b);
                }
                else {
                    path = __add_strs(3, path, const_4, b);
                }
            }
            else {
                path = path->__iadd__(const_4);
            }
        }
    END_FOR

    return path;
}
示例#2
0
tuple2<list<tuple2<str *, str *> *> *, list<str *> *> *do_shorts(list<tuple2<str *, str *> *> *opts, str *optstring, str *shortopts, list<str *> *args) {
    list<str *> *__22;
    str *__19, *__20, *__21, *__23, *opt, *optarg;


    while(__ne(optstring, const_0)) {
        __19 = optstring->__getitem__(0);
        __20 = optstring->__slice__(1, 1, 0, 0);
        opt = __19;
        optstring = __20;
        if (short_has_arg(opt, shortopts)) {
            if (__eq(optstring, const_0)) {
                if ((!___bool(args))) {
                    throw ((new GetoptError(__modct(const_10, 1, opt),opt)));
                }
                __21 = args->__getfast__(0);
                __22 = args->__slice__(1, 1, 0, 0);
                optstring = __21;
                args = __22;
            }
            __23 = optstring;
            optarg = __23;
            optstring = const_0;
        }
        else {
            optarg = const_0;
        }
        opts->append((new tuple2<str *, str *>(2, (const_1)->__add__(opt), optarg)));
    }
    return (new tuple2<list<tuple2<str *, str *> *> *, list<str *> *>(2, opts, args));
}
示例#3
0
文件: path.cpp 项目: GINK03/shedskin
str *commonprefix(list<str *> *m) {
    /**
    Given a list of pathnames, returns the longest common leading component
    */
    list<str *> *__24;
    list<str *>::for_in_loop __123;
    __ss_int __26, __27, __28, i;
    str *item, *prefix;

    if ((!___bool(m))) {
        return const_1;
    }
    prefix = m->__getfast__(0);

    FOR_IN(item,m,24,26,123)

        FAST_FOR(i,0,len(prefix),1,27,28)
            if (__ne(prefix->__slice__(2, 0, (i+1), 0), item->__slice__(2, 0, (i+1), 0))) {
                prefix = prefix->__slice__(2, 0, i, 0);
                if ((i==0)) {
                    return const_1;
                }
                break;
            }
        END_FOR

    END_FOR

    return prefix;
}
示例#4
0
文件: path.cpp 项目: GINK03/shedskin
__ss_bool isabs(str *s) {
    /**
    Test whether a path is absolute
    */
    __ss_int __0, __1;

    s = (splitdrive(s))->__getsecond__();
    return __mbool(__AND(__ne(s, const_1), (const_18)->__contains__(s->__slice__(2, 0, 1, 0)), 0));
}
示例#5
0
文件: path.cpp 项目: GINK03/shedskin
str *normpath(str *path) {
    /**
    Normalize path, eliminating double slashes, etc.
    */
    tuple2<str *, str *> *__36;
    list<str *> *comps;
    str *prefix;
    __ss_int __37, __38, __39, __40, __41, __42, i;

    path = path->replace(const_6, const_4);
    __36 = splitdrive(path);
    prefix = __36->__getfirst__();
    path = __36->__getsecond__();
    if (__eq(prefix, const_1)) {

        while(__eq(path->__slice__(2, 0, 1, 0), const_4)) {
            prefix = prefix->__add__(const_4);
            path = path->__slice__(1, 1, 0, 0);
        }
    }
    else {
        if (path->startswith(const_4)) {
            prefix = prefix->__add__(const_4);
            path = path->lstrip(const_4);
        }
    }
    comps = path->split(const_4);
    i = 0;

    while((i<len(comps))) {
        if ((const_2)->__contains__(comps->__getfast__(i))) {
            comps->__delitem__(i);
        }
        else if (__eq(comps->__getfast__(i), const_3)) {
            if (__AND((i>0), __ne(comps->__getfast__((i-1)), const_3), 37)) {
                comps->__delete__(3, (i-1), (i+1), 0);
                i = (i-1);
            }
            else if (__AND((i==0), prefix->endswith(const_4), 39)) {
                comps->__delitem__(i);
            }
            else {
                i = (i+1);
            }
        }
        else {
            i = (i+1);
        }
    }
    if (__AND((!___bool(prefix)), (!___bool(comps)), 41)) {
        comps->append(const_0);
    }
    return prefix->__add__((const_4)->join(comps));
}
示例#6
0
tuple2<list<tuple2<str *, str *> *> *, list<str *> *> *getopt(list<str *> *args, str *shortopts, pyiter<str *> *longopts) {
    /**
    getopt(args, options[, long_options]) -> opts, args

    Parses command line options and parameter list.  args is the
    argument list to be parsed, without the leading reference to the
    running program.  Typically, this means "sys.argv[1:]".  shortopts
    is the string of option letters that the script wants to
    recognize, with options that require an argument followed by a
    colon (i.e., the same format that Unix getopt() uses).  If
    specified, longopts is a list of strings with the names of the
    long options which should be supported.  The leading '--'
    characters should not be included in the option name.  Options
    which require an argument should be followed by an equal sign
    ('=').

    The return value consists of two elements: the first is a list of
    (option, value) pairs; the second is the list of program arguments
    left after the option list was stripped (this is a trailing slice
    of the first argument).  Each option-and-value pair returned has
    the option as its first element, prefixed with a hyphen (e.g.,
    '-x'), and the option argument as its second element, or an empty
    string if the option has no argument.  The options occur in the
    list in the same order in which they were found, thus allowing
    multiple occurrences.  Long and short options may be mixed.

    */
    list<str *> *__0, *__1, *__2;
    list<tuple2<str *, str *> *> *opts;
    tuple2<list<tuple2<str *, str *> *> *, list<str *> *> *__3, *__4;

    opts = (new list<tuple2<str *, str *> *>());
    longopts = new list<str *>(longopts);

    while((___bool(args) && (args->__getfast__(0))->startswith(const_1) && __ne(args->__getfast__(0), const_1))) {
        if (__eq(args->__getfast__(0), const_2)) {
            args = args->__slice__(1, 1, 0, 0);
            break;
        }
        if ((args->__getfast__(0))->startswith(const_2)) {
            __3 = do_longs(opts, (args->__getfast__(0))->__slice__(1, 2, 0, 0), longopts, args->__slice__(1, 1, 0, 0));
            opts = __3->__getfirst__();
            args = __3->__getsecond__();
        }
        else {
            __4 = do_shorts(opts, (args->__getfast__(0))->__slice__(1, 1, 0, 0), shortopts, args->__slice__(1, 1, 0, 0));
            opts = __4->__getfirst__();
            args = __4->__getsecond__();
        }
    }
    return (new tuple2<list<tuple2<str *, str *> *> *, list<str *> *>(2, opts, args));
}
示例#7
0
__ss_bool short_has_arg(str *opt, str *shortopts) {
    str *__26;
    __ss_int __24, __25, i;


    FAST_FOR(i,0,len(shortopts),1,24,25)
        if ((__eq(opt, (__26=shortopts->__getitem__(i)))&&__ne(__26, const_11))) {
            return __mbool(shortopts->startswith(const_11, (i+1)));
        }
    END_FOR

    throw ((new GetoptError(__modct(const_12, 1, opt),opt)));
}
示例#8
0
文件: path.cpp 项目: GINK03/shedskin
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));
}
示例#9
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;
}
示例#10
0
文件: path.cpp 项目: GINK03/shedskin
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);
}
示例#11
0
文件: path.cpp 项目: GINK03/shedskin
str *normpath(str *path) {
    /**
    Normalize path, eliminating double slashes, etc.
    */
    list<str *> *__28, *comps, *new_comps;
    list<str *>::for_in_loop __123;
    str *__38, *comp;
    __ss_int __25, __26, __30, __32, initial_slashes;

    if (__eq(path, const_0)) {
        return const_1;
    }
    initial_slashes = path->startswith(const_4);
    if (__AND(initial_slashes, __AND(path->startswith(const_14), (!path->startswith(const_15)), 26), 25)) {
        initial_slashes = 2;
    }
    comps = path->split(const_4);
    new_comps = (new list<str *>());

    FOR_IN(comp,comps,28,30,123)
        if ((const_2)->__contains__(comp)) {
            continue;
        }
        if ((__ne(comp, const_3) || __AND((!initial_slashes), (!___bool(new_comps)), 32) || ___bool((___bool(new_comps) && __eq(new_comps->__getfast__(-1), const_3))))) {
            new_comps->append(comp);
        }
        else if (___bool(new_comps)) {
            new_comps->pop();
        }
    END_FOR

    comps = new_comps;
    path = (const_4)->join(comps);
    if (initial_slashes) {
        path = ((const_4)->__mul__(initial_slashes))->__add__(path);
    }
    return __OR(path, const_1, 38);
}