Esempio n. 1
0
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));
}
Esempio n. 2
0
tuple2<str *, str *> *split(str *p) {
    /**
    Split a pathname.

    Return tuple (head, tail) where tail is everything after the final slash.
    Either part may be empty.
    */
    tuple2<str *, str *> *__15;
    str *__18, *__19, *__22, *__23, *d, *head, *head2, *tail;
    __ss_int __16, __17, __20, __21, i;

    __15 = splitdrive(p);
    d = __15->__getfirst__();
    p = __15->__getsecond__();
    i = len(p);

    while(__AND(i, (!(const_18)->__contains__(p->__getitem__((i-1)))), 16)) {
        i = (i-1);
    }
    __18 = p->__slice__(2, 0, i, 0);
    __19 = p->__slice__(1, i, 0, 0);
    head = __18;
    tail = __19;
    head2 = head;

    while((___bool(head2) && (const_18)->__contains__(head2->__getitem__(-1)))) {
        head2 = head2->__slice__(2, 0, -1, 0);
    }
    head = __OR(head2, head, 22);
    return (new tuple2<str *, str *>(2, d->__add__(head), tail));
}
Esempio n. 3
0
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;
}
Esempio n. 4
0
__ss_bool samestat(__os__::__cstat *s1, __os__::__cstat *s2) {
    /**
    Test whether two stat buffers reference the same file
    */
    __ss_int __18;
    return __mbool(__AND((s1->st_ino==s2->st_ino), (s1->st_dev==s2->st_dev), 18));
}
Esempio n. 5
0
__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));
}
Esempio n. 6
0
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);
}
Esempio n. 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;
}
Esempio n. 8
0
void *reader::parse_process_char(str *c) {
    Excel *dialect;
    __ss_int __10, __11, __12, __13, __14, __7, __8, __9;

    dialect = this->dialect;
    if ((this->state==START_RECORD)) {
        if (__eq(c, const_7)) {
            return NULL;
        }
        else if ((const_8)->__contains__(c)) {
            this->state = EAT_CRNL;
            return NULL;
        }
        this->state = START_FIELD;
    }
    if ((this->state==START_FIELD)) {
        if ((const_9)->__contains__(c)) {
            this->parse_save_field();
            if (__eq(c, const_7)) {
                this->state = START_RECORD;
            }
            else {
                this->state = EAT_CRNL;
            }
        }
        else if (__AND(__eq(c, dialect->quotechar), (dialect->quoting!=QUOTE_NONE), 7)) {
            this->state = IN_QUOTED_FIELD;
        }
        else if (__eq(c, dialect->escapechar)) {
            this->state = ESCAPED_CHAR;
        }
        else if (__AND(__eq(c, const_10), dialect->skipinitialspace, 9)) {
        }
        else if (__eq(c, dialect->delimiter)) {
            this->parse_save_field();
        }
        else {
            if ((dialect->quoting==QUOTE_NONNUMERIC)) {
                this->numeric_field = 1;
            }
            this->parse_add_char(c);
            this->state = IN_FIELD;
        }
    }
    else if ((this->state==ESCAPED_CHAR)) {
        if (__eq(c, const_7)) {
            c = const_11;
        }
        this->parse_add_char(c);
        this->state = IN_FIELD;
    }
    else if ((this->state==IN_FIELD)) {
        if ((const_12)->__contains__(c)) {
            this->parse_save_field();
            if (__eq(c, const_7)) {
                this->state = START_RECORD;
            }
            else {
                this->state = EAT_CRNL;
            }
        }
        else if (__eq(c, dialect->escapechar)) {
            this->state = ESCAPED_CHAR;
        }
        else if (__eq(c, dialect->delimiter)) {
            this->parse_save_field();
            this->state = START_FIELD;
        }
        else {
            this->parse_add_char(c);
        }
    }
    else if ((this->state==IN_QUOTED_FIELD)) {
        if (__eq(c, const_7)) {
        }
        else if (__eq(c, dialect->escapechar)) {
            this->state = ESCAPE_IN_QUOTED_FIELD;
        }
        else if (__AND(__eq(c, dialect->quotechar), (dialect->quoting!=QUOTE_NONE), 11)) {
            if (dialect->doublequote) {
                this->state = QUOTE_IN_QUOTED_FIELD;
            }
            else {
                this->state = IN_FIELD;
            }
        }
        else {
            this->parse_add_char(c);
        }
    }
    else if ((this->state==ESCAPE_IN_QUOTED_FIELD)) {
        if (__eq(c, const_7)) {
            c = const_11;
        }
        this->parse_add_char(c);
        this->state = IN_QUOTED_FIELD;
    }
    else if ((this->state==QUOTE_IN_QUOTED_FIELD)) {
        if (__AND((dialect->quoting!=QUOTE_NONE), __eq(c, dialect->quotechar), 13)) {
            this->parse_add_char(c);
            this->state = IN_QUOTED_FIELD;
        }
        else if (__eq(c, dialect->delimiter)) {
            this->parse_save_field();
            this->state = START_FIELD;
        }
        else if ((const_12)->__contains__(c)) {
            this->parse_save_field();
            if (__eq(c, const_7)) {
                this->state = START_RECORD;
            }
            else {
                this->state = EAT_CRNL;
            }
        }
        else if ((!dialect->strict)) {
            this->parse_add_char(c);
            this->state = IN_FIELD;
        }
        else {
            throw ((new Error(__modct(const_13, 2, dialect->delimiter, dialect->quotechar))));
        }
    }
    else if ((this->state==EAT_CRNL)) {
        if ((const_8)->__contains__(c)) {
        }
        else if (__eq(c, const_7)) {
            this->state = START_RECORD;
        }
        else {
            throw ((new Error(const_14)));
        }
    }
    return 0;
}