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; }
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)); }
str *joinl(list<str *> *l) { /** Join two or more pathname components, inserting '/' as needed */ list<str *> *__1, *__2, *p; list<str *>::for_in_loop __123; str *__0, *b, *path; __ss_int __4, __5; __0 = l->__getfast__(0); __1 = l->__slice__(1, 1, 0, 0); path = __0; p = __1; FOR_IN(b,p,2,4,123) if (b->startswith(const_4)) { path = b; } else if (__OR(__eq(path, const_0), path->endswith(const_4), 5)) { path = path->__iadd__(b); } else { path = __add_strs(3, path, const_4, b); } END_FOR return path; }
__ss_bool DynamInt::__lt__(DynamInt *num) { /** Overloaded < function Checks if this DynamInt is less than existing DynamInt @param num reference to an existing DynamInt @return added DynamInt */ /** The exact opposite of greater than above 1 0 3 4 5 < 1 2 3 4 ------------- F T F F F ------------- Where T refers to True, F to False It uses the last compare value, in this case, T which means 10345 is less than 1234 Another example, 1 0 3 4 5 < 9 2 3 4 0 ------------- T T F F F ------------- In this case it uses False, since 10345 is less than 92340 */ if (__eq(this, num)) { return False; } return __NOT(this->__gt__(num)); }
list<str *> *reader::next() { list<str *> *fields; str *__4, *line; this->parse_reset(); while (1) { line = (this->input_iter)->next(); this->line_num = (this->line_num+1); str *c; str::for_in_loop __3; int __2; str *__1; FOR_IN_NEW(c,line,1,2,3) if (__eq(c, const_7)) { throw ((new Error(const_15))); } this->parse_process_char(c); END_FOR this->parse_process_char(const_7); if ((this->state==START_RECORD)) { break; } } fields = this->fields; this->fields = (new list<str *>()); return fields; }
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)); }
tuple2<str *, str *> *splitdrive(str *p) { /** Split a pathname into drive and path specifiers. Returns a 2-tuple "(drive,path)"; either part may be empty */ if (__eq(p->__slice__(3, 1, 2, 0), const_19)) { return (new tuple2<str *, str *>(2, p->__slice__(3, 0, 2, 0), p->__slice__(1, 2, 0, 0))); } return (new tuple2<str *, str *>(2, const_1, p)); }
template<class T> __ss_bool tuple2<T, T>::__eq__(pyobj *p) { tuple2<T,T> *b; b = (tuple2<T,T> *)p; unsigned int sz = this->units.size(); if(b->units.size() != sz) return False; for(unsigned int i=0; i<sz; i++) if(!__eq(this->units[i], b->units[i])) return False; return True; }
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)); }
__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))); }
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); }
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); }
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)); }
template<class A, class B> __ss_bool tuple2<A, B>::__eq__(pyobj *p) { tuple2<A,B> *b = (tuple2<A,B> *)p; return __mbool(__eq(first, b->__getfirst__()) & __eq(second, b->__getsecond__())); }
template<class T> __ss_bool tuple2<T, T>::__contains__(T a) { for(int i=0; i<this->__len__(); i++) if(__eq(this->units[i], a)) return True; return False; }
__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; }
str *DynamInt::__sub__(DynamInt *num) { /** Overloaded Subtraction function subtracts an existing DynamInt from this one @param num reference to an existing DynamInt @return added DynamInt */ str *bottom, *sub, *sum, *top; int borrow, i, j, tempSub; /** Uses two's compliment on each element of both numbers */ if (__eq(this, num)) { return const_1; } if (__gt(this, num)) { top = this->data; bottom = num->data; } else if (__gt(num, this)) { top = num->data; bottom = this->data; } /** Temporary Variables used in addition process tempSub ----- Stores partial subtraction j ----- Stores length of bottom number i ----- Stores length of top number sub ----- Stores final sub string borrow ----- A flag that determines if it would need to borrow from next digit */ tempSub = 0; j = (len(bottom)-1); i = (len(top)-1); borrow = 0; sub = const_0; while ((i>=0)) { /** Have we run out of bottom digits ? */ if ((j>=0)) { tempSub = ((__int(top->__getitem__(i))-__int(bottom->__getitem__(j)))-borrow); if ((tempSub<0)) { borrow = 1; tempSub = (tempSub+10); } else { borrow = 0; } j = (j-1); } else { /** No more bottom digits, subtract any leftover borrow out */ tempSub = (__int(top->__getitem__(i))-borrow); if ((tempSub<0)) { borrow = 1; tempSub = (tempSub+10); } else { borrow = 0; } } /** lets concatenate the main sum outputed */ sub = (__str(tempSub))->__add__(sub); i = (i-1); } if ((borrow==1)) { sum = (const_2)->__add__(sub); } return sub; }
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; }
__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; }