int main(void) { printf("Enter the size of operand 1, followed by the size of operand 2, followed by the " "numbers in operand 1, followed by the numbers in operand 2.\n"); size_t op1_sz, op2_sz; while (scanf("%zu%zu", &op1_sz, &op2_sz) == 2) { read_list(operand1, op1_sz); read_list(operand2, op2_sz); printf("\t"); print_list(&operand1[0]); printf("+\t"); print_list(&operand2[0]); printf("----------------------------------------------------\n"); struct list_node *res; res = bigint_sum(&operand1[0], &operand2[0], &result[0]); printf("\t"); print_list(res); printf("\n"); } return 0; }
int run_program(int argc, char **argv) { CommandLineArgument<std::string> input_pathnames_filename; CommandLineArgument<std::string> output_pathnames_filename; CommandLineArgument<std::string> new_directory; CommandLineArgument<std::string> new_type; for (int i = 1; i < argc; i++) { std::string argument = argv[i]; if (argument == "--help") { print_usage(); return 0; } else if (argument == "--directory") { new_directory = get_argument(&i, argc, argv); } else if (argument == "--type") { new_type = get_argument(&i, argc, argv); } else if (!assign_argument(argument, input_pathnames_filename, output_pathnames_filename)) { throw make_runtime_error("Unable to process argument '%s'", argument.c_str()); } } if (!have_arguments_p(input_pathnames_filename, output_pathnames_filename)) { print_usage(); return -1; } std::list<std::string> input_pathnames; if (*input_pathnames_filename == "-") input_pathnames = read_list(std::cin); else input_pathnames = read_list(input_pathnames_filename->c_str()); std::ostream *out; std::ofstream out_f; if (*output_pathnames_filename == "-") out = &std::cout; else { out_f.open(output_pathnames_filename->c_str(), std::ios::out | std::ios::trunc); if (!out_f.is_open()) throw make_runtime_error("Failed to open file '%s'", output_pathnames_filename->c_str()); out = &out_f; } if (have_arguments_p(new_directory, new_type)) output_new_pathnames(input_pathnames, *out, DirectoryAndType(*new_directory, *new_type)); else if (have_argument_p(new_directory)) output_new_pathnames(input_pathnames, *out, DirectoryOnly(*new_directory)); else if (have_argument_p(new_type)) output_new_pathnames(input_pathnames, *out, TypeOnly(*new_type)); return 0; }
int main(int argc, char ** argv) { list l1 = 0; list l2 = 0; read_list(&l1); read_list(&l2); print_list(l1); print_list(l2); insert(&l1, &l2); print_list(l1); return 0; }
RESET_DATA *resetRead (STORAGE_SET *set) { RESET_DATA *reset = malloc(sizeof(RESET_DATA)); reset->type = read_int(set, "type"); reset->times = read_int(set, "times"); reset->chance = read_int(set, "chance"); reset->max = read_int(set, "max"); reset->room_max = read_int(set, "room_max"); reset->on = gen_read_list(read_list(set, "on"), resetRead); reset->in = gen_read_list(read_list(set, "in"), resetRead); reset->then = gen_read_list(read_list(set, "then"), resetRead); reset->arg = newBuffer(1); bufferCat(reset->arg, read_string(set, "arg")); return reset; }
int mix_database::load() { if (!td_list.empty() || !ra_list.empty() || !ts_list.empty()) return 0; Cvirtual_binary f; if (f.load(xcc_dirs::get_data_dir() + "global mix database.dat") || f.size() < 16) return 1; const char* data = reinterpret_cast<const char*>(f.data()); read_list(game_td, data); read_list(game_ra, data); read_list(game_ts, data); read_list(game_ra2, data); if (0) { ofstream log_f("c:\\log.txt"); for (auto& i : ts_list) log_f << i.second.name << '\t' << i.second.description << endl; } return 0; char name[12] = "scg00ea.bin"; const char char1[] = "bgjm"; const char char2[] = "ew"; const char char3[] = "abc"; for (int i = 0; i < 2; i++) { if (i) strcpy(name + 8, "ini"); for (int j = 0; j < 4; j++) { name[2] = char1[j]; for (int k = 0; k < 100; k++) { memcpy(name + 3, nwzl(2, k).c_str(), 2); for (int l = 0; l < 2; l++) { name[5] = char2[l]; for (int m = 0; m < 3; m++) { name[6] = char3[m]; mix_database::add_name(game_td, name, ""); mix_database::add_name(game_ra, name, ""); mix_database::add_name(game_ts, name, ""); } } } } } return 0; }
static int benc_decode_full(char *in, struct benc **b) { unsigned char first = *in++; switch (first) { case 'i': return 1 + read_number(b, in, 'e', 0); case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': return 1 + read_string(b, in, ':', first - '0'); case 'l': return 1 + read_list(b, in, 'e'); case 'd': return 1 + read_dict(b, in, 'e'); default: fprintf(stderr, "%s: stream possibly corrupt\n", "benc_decode_full"); return -1; } }
Value * read_value(Globals *g) { Value *v; while (g->buflen > 0) { switch (PEEK_CHAR(g)) { case ' ': case '\t': case '\n': case '\0': NEXT_CHAR(g); break; case '\"': /* begin string */ NEXT_CHAR(g); return read_string(g); break; case '(': NEXT_CHAR(g); return read_list(g); break; case ')': case '.': return NULL; break; default: return read_num_or_symbol(g); break; } } ABORT(g, 23); }
pointer _read(port *in) { pointer token; switch (get_next_token(in, &token)) { case FILE_END: return E_O_F; case STRING: case SYMBOL: case NUMBER: return token; case LIST_START: return read_list(in); case LIST_END: pair_count--; return NULL; case QUOTE: return cons_with_symbol("quote", cons(_read(in), NULL)); case BACKQUOTE: return cons_with_symbol("backquote", cons(_read(in), NULL)); case UNQUOTE: return cons_with_symbol("unquote", cons(_read(in), NULL)); case SPLICE: return cons_with_symbol("splice", cons(_read(in), NULL)); case DOT: return cons_with_symbol("dot", cons(_read(in), NULL)); default: printf("Unknown token %s\n", str(token)); exit(1); break; } }
// // read a storage list from the storage set PyObject *PyStorageSet_readList (PyObject *self, PyObject *args) { char *key = PyStorageSet_readParseKey(args); if(key == NULL) return NULL; else return newPyStorageList(read_list(((PyStorageSet*)self)->set, key)); }
int gestorFilehandling(char *basepath, const char *filename) { int res = 0; initHT(); read_list(basepath, filename); res = criaG(); return res; }
int read_service(xmlNode *list_node, service_t **dst) { int res = 0; xmlAttr *a; const char *a_val; xmlNode *n; int first_node; DEBUG_LOG("read_service(): called\n"); /* allocate memory and prepare empty node */ if (!dst) return -1; *dst = (service_t*)cds_malloc(sizeof(service_t)); if (!(*dst)) return -2; memset(*dst, 0, sizeof(service_t)); /* get attributes */ a = find_attr(list_node->properties, "uri"); if (a) { a_val = get_attr_value(a); if (a_val) (*dst)->uri = zt_strdup(a_val); } /* read child nodes */ n = list_node->children; first_node = 1; while (n) { if (n->type == XML_ELEMENT_NODE) { if (first_node) { /* element must be list or resource-list */ if (cmp_node(n, "list", rls_namespace) >= 0) { res = read_list(n, &(*dst)->content.list, 0); if ( (res == 0) && ((*dst)->content.list) ) { (*dst)->content_type = stc_list; } else return -1; } else if (cmp_node(n, "resource-list", rls_namespace) >= 0) { a_val = get_node_value(n); if (a_val) (*dst)->content.resource_list = zt_strdup(a_val); else (*dst)->content.resource_list = NULL; (*dst)->content_type = stc_resource_list; } else return -1; first_node = 0; } else { /* packages node */ if (cmp_node(n, "packages", rls_namespace) >= 0) { res = read_packages(n, &(*dst)->packages); } break; } } n = n->next; } return 0; }
int main(int argc, char **argv) { Node *head = NULL; char **filenames = init_filenames(); char arg; char *listfile = "index"; char *namefile = "filenames"; while ((arg = getopt(argc,argv,"i:n:")) > 0){ switch(arg){ case 'i': listfile = optarg; break; case 'n': namefile = optarg; break; default: fprintf(stderr, "Bad arguments for printindex\n"); exit(1); } } read_list(listfile, namefile, &head, filenames); display_list(head, filenames); return 0; }
atom_t* read_atom(scanner_t *scan){ slice_t slice; int c = scan_while_func(scan, NULL, isspace); while (c == ';'){ scan_until(scan, NULL, '\n'); c = scan_peek(scan); } if (c == EOF) { return nil_atom(); } else if (c == '(') { return read_list(scan); } else if (c == '\'') { // Quote scan_one_of(scan, '\''); atom_t *content = read_atom(scan); return pair_atom_alloc(sym_atom_alloc("quote"), pair_atom_alloc(content, nil_atom())); } else if (c == '"') { // String scan_one_of(scan, '"'); scan_until(scan, &slice, '"'); return str_atom_alloc(slice.ptr); } else if ( isdigit(c) ) { // Number scan_while_func(scan, &slice, isdigit); int64_t value = strtoll(slice.ptr, NULL, 10); free(slice.ptr); return num_atom_alloc(value); } else { return read_sym(scan); } }
static Obj *read_expr(void *root) { for (;;) { int c = getchar(); if (c == ' ' || c == '\n' || c == '\r' || c == '\t') continue; if (c == EOF) return NULL; if (c == ';') { skip_line(); continue; } if (c == '(') return read_list(root); if (c == ')') return Cparen; if (c == '.') return Dot; if (c == '\'') return read_quote(root); if (isdigit(c)) return make_int(root, read_number(c - '0')); if (c == '-' && isdigit(peek())) return make_int(root, -read_number(0)); if (isalpha(c) || strchr(symbol_chars, c)) return read_symbol(root, c); error("Don't know how to handle %c", c); } }
/********************************************************************** * read_variables * * Read a file that contains assignments for all the desired variables. * This type of file can be written using the function write_variables. **********************************************************************/ void read_variables(const char *filename) { int x = 0; char *this_string; LIST var_strings; char name[1024]; FILE *fp; /* Read the strings */ if (filename == NULL || filename[0] == '\0') return; strcpy(name, demodir); strcat (name, "tessdata/tessconfigs/"); strcat(name, filename); if ((fp = fopen (name, "r")) == NULL) strcpy(name, filename); else fclose(fp); var_strings = read_list (name); iterate(var_strings) { /* Get the name string */ this_string = (char *) first_node (var_strings); if (this_string[0] != '#') { for (x = 0; x < strlen (this_string) && this_string[x] != ' ' && this_string[x] != '\t'; x++); this_string[x] = '\0'; /* Find variable record */ if (!set_old_style_variable(this_string, this_string + x + 1)) { tprintf("error: Could not find variable '%s'\n", this_string); exit(1); // ?err_exit (); } } } }
/* miread: Read an s-expression into a node structure Supported list elements: -List -Natural numbers -Symbols */ struct node *miread() { struct token t; struct node *newn; t = read_token(); if( t.tag == TEOF ) { return NULL; } else if ( t.tag == LPAR ) { debug("Reading a list."); newn = malloc(NSIZE); check_mem(newn); newn->tag = LST; newn->sublst = read_list(); return newn; } else if( t.tag == RPAR ) { printf( "unmatched right parenthesis\n" ); abort(); } else { token_to_node(t); } error: return NULL; }
static int dfs_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi) { DMSG("%s",path); int r_size = 0; if (is_special_path(path)) { return read_list(buf, size, offset); } DfsFile *file = dfsDir.find(path + 1); if(!is_file_exist(file)) return -ENOENT; switch(file->status) { case DfsFile::REMOVED: return -ENOENT; default: r_size = file->read(buf, size, offset); DMSG("read %d bytes from offset %ld", r_size, (long)offset); break; } return r_size; }
AssocContainCanvas * AssocContainCanvas::read(char * & st, UmlCanvas * canvas, char * k) { if (!strcmp(k, "containcanvas_ref")) return ((AssocContainCanvas *) dict_get(read_id(st), "contain canvas", canvas)); else if (!strcmp(k, "containcanvas")) { int id = read_id(st); LineGeometry geo; bool fixed; k = read_keyword(st); // may read id if (!strcmp(k, "geometry")) { geo = line_geometry(read_keyword(st)); k = read_keyword(st); if (! strcmp(k, "unfixed")) { k = read_keyword(st); fixed = FALSE; } else fixed = TRUE; } else { geo = NoGeometry; fixed = FALSE; } float dbegin; float dend; if (! strcmp(k, "decenter_begin")) { dbegin = read_double(st) / 1000; k = read_keyword(st); } else dbegin = -1; if (! strcmp(k, "decenter_end")) { dend = read_double(st) / 1000; k = read_keyword(st); } else dend = -1; unread_keyword(k, st); AssocContainCanvas * r = (AssocContainCanvas *) read_list(st, canvas, UmlContain, geo, fixed, dbegin, dend, id, &make); // remove association between components available in the // 2.0 deployment diagrams if (r->begin->type() == UmlComponent) Undefined.append(r); else if (read_file_format() == 30) // to remove redondant transitions made by release 2.22 RelsToCheck.append(r); return r; } else return 0; }
int main(int argc, char ** argv) { list l = 0; read_list(&l); process_list(l); print_list(l); return 0; }
void init_socials() { // create the social table social_table = newHashtable(); // open up the storage set STORAGE_SET *set = storage_read(SOCIALS_FILE); STORAGE_SET_LIST *list = read_list(set, "socials"); STORAGE_SET *social = NULL; // parse all of the socials while( (social = storage_list_next(list)) != NULL) add_social(socialRead(social)); // close the storage set storage_close(set); // add all of the socials to the command table HASH_ITERATOR *hash_i = newHashIterator(social_table); const char *cmd = NULL; SOCIAL_DATA *data = NULL; ITERATE_HASH(cmd, data, hash_i) { add_cmd(cmd, NULL, cmd_social, "player", FALSE); if(data->min_pos == POS_SITTING) add_cmd_check(cmd, chk_conscious); else if(data->min_pos == POS_STANDING) add_cmd_check(cmd, chk_can_move); else if(data->max_pos == POS_STANDING) add_cmd_check(cmd, chk_grounded); } deleteHashIterator(hash_i);
value_t read_sexpr(FILE *f) { value_t v; switch (peek(f)) { case TOK_CLOSE: take(); lerror("read: error: unexpected ')'\n"); case TOK_DOT: take(); lerror("read: error: unexpected '.'\n"); case TOK_SYM: case TOK_NUM: take(); return tokval; case TOK_QUOTE: take(); v = read_sexpr(f); PUSH(v); v = cons_("E, cons(&Stack[SP-1], &NIL)); POPN(2); return v; case TOK_OPEN: take(); PUSH(NIL); read_list(f, &Stack[SP-1]); return POP(); } return NIL; }
/* R5RS library procedure read * (read) * (read [port]) */ SCM scm_proc_read(FILE *file) { int c = skip_comment_and_space(file); switch (c) { case '(': return read_list(file); case ')': /* List end */ scheme_error("symtax error"); case '[': case ']': scheme_error("unsupport bracket"); case '{': case '}': scheme_error("unsupport brace"); case '|': scheme_error("unsupport bar"); case '#': c = fgetc(file); if ('(' == c) { return read_vector(file); } else { ungetc(c, file); return read_simple_datum(file, '#'); } case '\'': /* Quotation */ return new_cons(SCM_SYMBOL_QUOTE, new_cons(scm_proc_read(file), SCM_NULL)); case '`': /* Quasiquotation */ scheme_error("unsupport quasiquotation"); case ',': /* (Splicing) Uuquotation */ scheme_error("unsupport (splicing) unquotation"); default: return read_simple_datum(file, c); } }
static ptr read_list() { INT t; ptr v, x; t = read_token(&v); if (t == r_RPAREN) return Snil; x = readx(t, v); return Scons(x, read_list()); }
struct value* read_input(FILE* in){ int c; for (c = fgetc(in); !isalpha(c); c = fgetc(in)); ungetc(c, in); return read_list(in); }
/* loads MIME database from given file. a good example of such file is 'mime.types' supplied with Apache. */ int mime_load (char *filename) { char **input, *p; int i; input = read_list (filename); if (input == NULL || input[0] == NULL) return -1; /* count lines and allocate memory */ for (n=0; ; n++) { if (input[n] == NULL) break; } if (n == 0) return -1; mimetypes = xmalloc (sizeof(mimetypes[0]) * n); /* assign and parse each line */ for (i=0; i<n; i++) { mimetypes[i].type = input[i]; mimetypes[i].next = 0; mimetypes[i].extensions = NULL; str_translate (mimetypes[i].type, '\t', ' '); p = strchr (mimetypes[i].type, ' '); if (p == NULL) continue; *p = '\0'; mimetypes[i].next = str_words (p+1, &mimetypes[i].extensions, WSEP_SPACES); if (mimetypes[i].next <= 0) { mimetypes[i].next = 0; mimetypes[i].extensions = NULL; } #if 0 /* this code exists simply for testing memory leaks. it is not * needed */ { char **p = xmalloc (sizeof (char **)); memcpy (p, mimetypes[i].extensions, sizeof (char **)); free (mimetypes[i].extensions); mimetypes[i].extensions = p; } #endif } /* sort assignments for quick location of names */ qsort (mimetypes, n, sizeof(mimetypes[0]), cmp_mimetypes); free (input); mime_HTML = mime_name2num ("text/html"); mime_PLAIN = mime_name2num ("text/plain"); if (mime_HTML < 0 || mime_PLAIN < 0) return -2; return 0; }
AST_expr* readASTExpr(BufferedReader* reader) { uint8_t type = reader->readByte(); if (VERBOSITY("parsing") >= 2) printf("type = %d\n", type); if (type == 0) return NULL; uint8_t checkbyte = reader->readByte(); assert(checkbyte == 0xae); switch (type) { case AST_TYPE::Attribute: return read_attribute(reader); case AST_TYPE::BinOp: return read_binop(reader); case AST_TYPE::BoolOp: return read_boolop(reader); case AST_TYPE::Call: return read_call(reader); case AST_TYPE::Compare: return read_compare(reader); case AST_TYPE::Dict: return read_dict(reader); case AST_TYPE::DictComp: return read_dictcomp(reader); case AST_TYPE::IfExp: return read_ifexp(reader); case AST_TYPE::Index: return read_index(reader); case AST_TYPE::Lambda: return read_lambda(reader); case AST_TYPE::List: return read_list(reader); case AST_TYPE::ListComp: return read_listcomp(reader); case AST_TYPE::Name: return read_name(reader); case AST_TYPE::Num: return read_num(reader); case AST_TYPE::Repr: return read_repr(reader); case AST_TYPE::Slice: return read_slice(reader); case AST_TYPE::Str: return read_str(reader); case AST_TYPE::Subscript: return read_subscript(reader); case AST_TYPE::Tuple: return read_tuple(reader); case AST_TYPE::UnaryOp: return read_unaryop(reader); default: fprintf(stderr, "Unknown expr node type (parser.cpp:" STRINGIFY(__LINE__) "): %d\n", type); abort(); break; } }
StrVec read_lists (const StrVec& fnames) { StrVec rv; StrVec::const_iterator itr = fnames.begin (); while (itr != fnames.end ()) { StrVec vals = read_list (*itr); std::copy (vals.begin (), vals.end (), std::back_inserter (rv)); itr ++; } return rv; }
ExprPtr Parser::read_expr() { ExprPtr expr; if (m_word.type == "(") { expr = read_list(); } else { expr = read_single(); } return expr; }
int main(int argc, char *argv[]){ int num; char *ofile=NULL; int opt; while((opt=getopt(argc, argv, "i:"))!=-1){ switch(opt){ case 'i': ofile=strdup(optarg); break; case '?': case ':': default : usage(); break; } } if(optind!=argc){ printf("Unknow argument '%s'\n",argv[optind]); usage(); } else if(strcmp(argv[optind-1], "--")==0){ printf("Unknow argument '%s'\n",argv[optind-1]); usage(); } if(ofile==NULL){ ofile=strdup("default-make-list-file.dat"); } time_t entire_start=time(NULL); int i=0; long sum=0; int *A; read_list(ofile,&num,&A); time_t comp_start=time(NULL); for(i=0;i<num;i++){ sum+=A[i]; } printf("%ld\n",sum); time_t entire_stop=time(NULL); printf("ENTIRE:%d\tCOMPUTATION:%d\n",(int)(entire_stop-entire_start),(int)(entire_stop-comp_start)); free(ofile); free(A); return 0; }
int main(int argc, char *argv[]) { int ret; int i; struct ftdi_context *ftdi; unsigned int chipid; unsigned char buf[256]; track *tracks; int ntracks; ftdi = ftdi_new(); ret = ftdi_usb_open(ftdi, 0x0403, 0xB70A); if (ret < -1) { fprintf(stderr, "unable to open ftdi device: %d (%s)\n", ret, ftdi_get_error_string(ftdi)); return ret; } printf("type=%d\n", ftdi->type); ftdi_read_chipid(ftdi, &chipid); printf("chipid=%x\n", chipid); setup(ftdi); ftdi_setrts(ftdi, 1); while((ret = ftdi_read_data(ftdi, buf, 256)) > 0) { for(i = 0; i < ret; ++i) printf("%02X ", buf[i]); } ftdi_setrts(ftdi, 0); read_version(ftdi); read_product(ftdi); read_list(ftdi, &tracks, &ntracks); if (argc > 1) { i = atoi(argv[1]); printf("tracks[%d].no=%d\n", i, tracks[i].no); read_track_points(ftdi, &tracks[i], i); } free(tracks); ftdi_usb_close(ftdi); ftdi_free(ftdi); return 0; }