void main() { Name_pairs n; read_names(n); read_ages(n); n.sort(); cout << n; system("pause"); }
int main (int argc, char *argv[]) { FILE *fp; char **person[MAX_SIZE]; int num_names, *order; fp = fopen (argv[1], "r"); num_names = read_names(fp, person); order = sort(person, num_names); write_names (person, order, num_names); free_memory(person); fclose(fp); return 0; } //main()
/* extract_names_list: extract names from data into active_users */ void TwitchBot::extract_names_list(char *data) { char *s; for (s = data; s; data = s + 1) { if ((s = strchr(data, '\n'))) *s = '\0'; /* 353 signifies names list */ if (strstr(data, "353")) { read_names(data); continue; } /* 366 signifies end of names list */ if (strstr(data, "366")) break; } }
static int read_entry(xmlNode *entry_node, entry_t **dst) { xmlAttr *a; const char *a_val; /* allocate memory and prepare empty node */ if (!dst) return -1; *dst = (entry_t*)cds_malloc(sizeof(entry_t)); if (!(*dst)) return -2; memset(*dst, 0, sizeof(entry_t)); /* get attributes */ a = find_attr(entry_node->properties, "uri"); if (a) { a_val = get_attr_value(a); if (a_val) (*dst)->uri = zt_strdup(a_val); } return read_names(entry_node, &((*dst)->display_names)); }
dkinit() { register int i; register char *cp; static int once = 0; static char buf[1024]; if (once) return(1); nlist("/vmunix", nlst); if (nlst[X_DK_NDRIVE].n_value == 0) { error("dk_ndrive undefined in kernel"); return(0); } dk_ndrive = getw(nlst[X_DK_NDRIVE].n_value); if (dk_ndrive <= 0) { error("dk_ndrive=%d according to /vmunix", dk_ndrive); return(0); } dk_mspw = (float *)calloc(dk_ndrive, sizeof (float)); lseek(kmem, nlst[X_DK_MSPW].n_value, L_SET); read(kmem, dk_mspw, dk_ndrive * sizeof (float)); dr_name = (char **)calloc(dk_ndrive, sizeof (char *)); dk_select = (int *)calloc(dk_ndrive, sizeof (int)); for (cp = buf, i = 0; i < dk_ndrive; i++) { dr_name[i] = cp; sprintf(dr_name[i], "dk%d", i); cp += strlen(dr_name[i]) + 1; if (dk_mspw[i] != 0.0) dk_select[i] = 1; } if (! read_names()) { free(dr_name); free(dk_select); free(dk_mspw); return(0); } once = 1; return(1); }
int main(int argc, char *argv[]) { int howmany, i; int *table; printf("How many students? "); scanf("%d", &howmany); table = read_names(howmany); if (table == NULL) { printf("In main: Memory allocation problem. Exiting\n"); return(1); } for (i = 0; i < howmany; i++) { printf("%d\n", *(table + i)); /* printf("%d\n", table[i]);*/ } free(table); table = NULL; return(0); }
int main(int argc, const char * argv[]) { if ( argc != 12 ) { /* We print argv[0] assuming it is the program name */ printf( "usage: %s -DATA -EMBED_SIZE -LR -MAX_ITER -NUM_THREAD -ALPHA -DISTANCE -OCSAMPLE -ONSAMPLE -K -C\n", argv[0] ); } else { const char *indir = argv[1]; embed_size = atoi(argv[2]); lr = atof(argv[3]); max_iter = atoi(argv[4]); num_threads = atoi(argv[5]); alpha = atof(argv[6]); distance = atoi(argv[7]); ocsample = atoi(argv[8]); onsample = atoi(argv[9]); K = atoi(argv[10]); C = atof(argv[11]); char filename[BUFFER_SIZE]; time_t t; srand((unsigned) time(&t)); /* Load number of features, types, and mentions */ snprintf(filename, sizeof(filename), "Intermediate/%s/feature.txt", indir); feature_count = count_lines(filename); feautre_name = read_names(filename, feature_count); snprintf(filename, sizeof(filename), "Intermediate/%s/type.txt", indir); type_count = count_lines(filename); type_name = read_names(filename, type_count); snprintf(filename, sizeof(filename), "Intermediate/%s/mention.txt", indir); mention_count = count_lines(filename); printf("type: %d, feature: %d, mention: %d\n",type_count, feature_count, mention_count); /* Load type hierarchy */ snprintf(filename, sizeof(filename), "Intermediate/%s/supertype.txt", indir); hierarchy = new Hierarchy(filename); /* Load edit distances between types */ if (distance == 2) { // shortest path length snprintf(filename, sizeof(filename), "Intermediate/%s/type_type_sp.txt", indir); }else{ snprintf(filename, sizeof(filename), "Intermediate/%s/type_type_kb.txt", indir); } weights = load_weights(filename, type_count, alpha, distance, hierarchy); /* Initialize matrix A and B*/ A = malloc_matrix_double(feature_count, embed_size); B = malloc_matrix_double(type_count, embed_size); printf("Fininsh initialize matrix A and B\n"); Ag = (double *)calloc(feature_count * embed_size, sizeof(double)); Bg = (double *)calloc(type_count * embed_size, sizeof(double)); An = (int *)calloc(feature_count, sizeof(int)); Bn = (int *)calloc(type_count, sizeof(int)); snprintf(filename, sizeof(filename), "Intermediate/%s/mention_feature.txt", indir); train_x = (int **)malloc(mention_count * sizeof(int *)); x_count = (int *)calloc(mention_count, sizeof(int)); for(int i = 0; i < mention_count; i++){ train_x[i] = (int *)calloc(BUFFER_SIZE, sizeof(int)); if(train_x[i] == NULL){ printf("out of memory!\n"); exit(EXIT_FAILURE); } } load_data(filename, train_x, x_count); snprintf(filename, sizeof(filename), "Intermediate/%s/mention_type.txt", indir); train_y = (int **)malloc(mention_count * sizeof(int *)); y_count = (int *)calloc(mention_count, sizeof(int)); for(int i = 0; i < mention_count; i++){ train_y[i] = (int *)calloc(SMALL_BUFFER_SIZE, sizeof(int)); if(train_y[i] == NULL){ printf("out of memory!\n"); exit(EXIT_FAILURE); } } std::vector<std::vector<int> >clean_and_noise=load_data_noise(filename, train_y, y_count, hierarchy, mention_count); mention_set = clean_and_noise[0]; mention_set_noise = clean_and_noise[1]; printf("Start training process\n"); printf("Clean examples: %d, noise examples: %d\n", (int)mention_set.size(), (int)mention_set_noise.size()); long a; pthread_t *pt = (pthread_t *)malloc(num_threads * sizeof(pthread_t)); for (iter = 0; iter != max_iter; iter++) { error = 0; std::random_shuffle(mention_set.begin(), mention_set.end()); std::random_shuffle(mention_set_noise.begin(), mention_set_noise.end()); for (a = 0; a < num_threads; a++) pthread_create(&pt[a], NULL, train_BCD_thread, (void *)a); for (a = 0; a < num_threads; a++) pthread_join(pt[a], NULL); printf("Iter:%d, error:%f\n",iter, error); update_embedding(); } /* Save matrix A and B*/ snprintf(filename, sizeof(filename), "Results/%s/emb_pl_warp_bipartite_feature.txt", indir); print_matrix(filename, A, feature_count, embed_size, feautre_name); snprintf(filename, sizeof(filename), "Results/%s/emb_pl_warp_bipartite_type.txt", indir); print_matrix(filename, B, type_count, embed_size, type_name); free_matrix_double(A); return 0; } }
/* * main function - reads instantaneous power values (in W) from a trace * file (e.g. "gcc.ptrace") and outputs instantaneous temperature values (in C) to * a trace file("gcc.ttrace"). also outputs steady state temperature values * (including those of the internal nodes of the model) onto stdout. the * trace files are 2-d matrices with each column representing a functional * functional block and each row representing a time unit(sampling_intvl). * columns are tab-separated and each row is a separate line. the first * line contains the names of the functional blocks. the order in which * the columns are specified doesn't have to match that of the floorplan * file. */ int main(int argc, char **argv) { int i, j, idx, base = 0, count = 0, n = 0; int num, size, lines = 0, do_transient = TRUE; char **names; double *vals; /* trace file pointers */ FILE *pin, *tout = NULL; /* floorplan */ flp_t *flp; /* hotspot temperature model */ RC_model_t *model; /* instantaneous temperature and power values */ double *temp = NULL, *power; double total_power = 0.0; /* steady state temperature and power values */ double *overall_power, *steady_temp; /* thermal model configuration parameters */ thermal_config_t thermal_config; /* global configuration parameters */ global_config_t global_config; /* table to hold options and configuration */ str_pair table[MAX_ENTRIES]; /* variables for natural convection iterations */ int natural = 0; double avg_sink_temp = 0; int natural_convergence = 0; double r_convec_old; if (!(argc >= 5 && argc % 2)) { usage(argc, argv); return 1; } size = parse_cmdline(table, MAX_ENTRIES, argc, argv); global_config_from_strs(&global_config, table, size); /* no transient simulation, only steady state */ if(!strcmp(global_config.t_outfile, NULLFILE)) do_transient = FALSE; /* read configuration file */ if (strcmp(global_config.config, NULLFILE)) size += read_str_pairs(&table[size], MAX_ENTRIES, global_config.config); /* * earlier entries override later ones. so, command line options * have priority over config file */ size = str_pairs_remove_duplicates(table, size); /* get defaults */ thermal_config = default_thermal_config(); /* modify according to command line / config file */ thermal_config_add_from_strs(&thermal_config, table, size); /* if package model is used, run package model */ if (((idx = get_str_index(table, size, "package_model_used")) >= 0) && !(table[idx].value==0)) { if (thermal_config.package_model_used) { avg_sink_temp = thermal_config.ambient + SMALL_FOR_CONVEC; natural = package_model(&thermal_config, table, size, avg_sink_temp); if (thermal_config.r_convec<R_CONVEC_LOW || thermal_config.r_convec>R_CONVEC_HIGH) printf("Warning: Heatsink convection resistance is not realistic, double-check your package settings...\n"); } } /* dump configuration if specified */ if (strcmp(global_config.dump_config, NULLFILE)) { size = global_config_to_strs(&global_config, table, MAX_ENTRIES); size += thermal_config_to_strs(&thermal_config, &table[size], MAX_ENTRIES-size); /* prefix the name of the variable with a '-' */ dump_str_pairs(table, size, global_config.dump_config, "-"); } /* initialization: the flp_file global configuration * parameter is overridden by the layer configuration * file in the grid model when the latter is specified. */ flp = read_flp(global_config.flp_file, FALSE); /* allocate and initialize the RC model */ model = alloc_RC_model(&thermal_config, flp); populate_R_model(model, flp); if (do_transient) populate_C_model(model, flp); #if VERBOSE > 2 debug_print_model(model); #endif /* allocate the temp and power arrays */ /* using hotspot_vector to internally allocate any extra nodes needed */ if (do_transient) temp = hotspot_vector(model); power = hotspot_vector(model); steady_temp = hotspot_vector(model); overall_power = hotspot_vector(model); /* set up initial instantaneous temperatures */ if (do_transient && strcmp(model->config->init_file, NULLFILE)) { if (!model->config->dtm_used) /* initial T = steady T for no DTM */ read_temp(model, temp, model->config->init_file, FALSE); else /* initial T = clipped steady T with DTM */ read_temp(model, temp, model->config->init_file, TRUE); } else if (do_transient) /* no input file - use init_temp as the common temperature */ set_temp(model, temp, model->config->init_temp); /* n is the number of functional blocks in the block model * while it is the sum total of the number of functional blocks * of all the floorplans in the power dissipating layers of the * grid model. */ if (model->type == BLOCK_MODEL) n = model->block->flp->n_units; else if (model->type == GRID_MODEL) { for(i=0; i < model->grid->n_layers; i++) if (model->grid->layers[i].has_power) n += model->grid->layers[i].flp->n_units; } else fatal("unknown model type\n"); if(!(pin = fopen(global_config.p_infile, "r"))) fatal("unable to open power trace input file\n"); if(do_transient && !(tout = fopen(global_config.t_outfile, "w"))) fatal("unable to open temperature trace file for output\n"); /* names of functional units */ names = alloc_names(MAX_UNITS, STR_SIZE); if(read_names(pin, names) != n) fatal("no. of units in floorplan and trace file differ\n"); /* header line of temperature trace */ if (do_transient) write_names(tout, names, n); /* read the instantaneous power trace */ vals = dvector(MAX_UNITS); while ((num=read_vals(pin, vals)) != 0) { if(num != n) fatal("invalid trace file format\n"); /* permute the power numbers according to the floorplan order */ if (model->type == BLOCK_MODEL) for(i=0; i < n; i++) power[get_blk_index(flp, names[i])] = vals[i]; else for(i=0, base=0, count=0; i < model->grid->n_layers; i++) { if(model->grid->layers[i].has_power) { for(j=0; j < model->grid->layers[i].flp->n_units; j++) { idx = get_blk_index(model->grid->layers[i].flp, names[count+j]); power[base+idx] = vals[count+j]; } count += model->grid->layers[i].flp->n_units; } base += model->grid->layers[i].flp->n_units; } /* compute temperature */ if (do_transient) { /* if natural convection is considered, update transient convection resistance first */ if (natural) { avg_sink_temp = calc_sink_temp(model, temp); natural = package_model(model->config, table, size, avg_sink_temp); populate_R_model(model, flp); } /* for the grid model, only the first call to compute_temp * passes a non-null 'temp' array. if 'temp' is NULL, * compute_temp remembers it from the last non-null call. * this is used to maintain the internal grid temperatures * across multiple calls of compute_temp */ if (model->type == BLOCK_MODEL || lines == 0) compute_temp(model, power, temp, model->config->sampling_intvl); else compute_temp(model, power, NULL, model->config->sampling_intvl); /* permute back to the trace file order */ if (model->type == BLOCK_MODEL) for(i=0; i < n; i++) vals[i] = temp[get_blk_index(flp, names[i])]; else for(i=0, base=0, count=0; i < model->grid->n_layers; i++) { if(model->grid->layers[i].has_power) { for(j=0; j < model->grid->layers[i].flp->n_units; j++) { idx = get_blk_index(model->grid->layers[i].flp, names[count+j]); vals[count+j] = temp[base+idx]; } count += model->grid->layers[i].flp->n_units; } base += model->grid->layers[i].flp->n_units; } /* output instantaneous temperature trace */ write_vals(tout, vals, n); } /* for computing average */ if (model->type == BLOCK_MODEL) for(i=0; i < n; i++) overall_power[i] += power[i]; else for(i=0, base=0; i < model->grid->n_layers; i++) { if(model->grid->layers[i].has_power) for(j=0; j < model->grid->layers[i].flp->n_units; j++) overall_power[base+j] += power[base+j]; base += model->grid->layers[i].flp->n_units; } lines++; } if(!lines) fatal("no power numbers in trace file\n"); /* for computing average */ if (model->type == BLOCK_MODEL) for(i=0; i < n; i++) { overall_power[i] /= lines; //overall_power[i] /=150; //reduce input power for natural convection total_power += overall_power[i]; } else for(i=0, base=0; i < model->grid->n_layers; i++) { if(model->grid->layers[i].has_power) for(j=0; j < model->grid->layers[i].flp->n_units; j++) { overall_power[base+j] /= lines; total_power += overall_power[base+j]; } base += model->grid->layers[i].flp->n_units; } /* natural convection r_convec iteration, for steady-state only */ natural_convergence = 0; if (natural) { /* natural convection is used */ while (!natural_convergence) { r_convec_old = model->config->r_convec; /* steady state temperature */ steady_state_temp(model, overall_power, steady_temp); avg_sink_temp = calc_sink_temp(model, steady_temp) + SMALL_FOR_CONVEC; natural = package_model(model->config, table, size, avg_sink_temp); populate_R_model(model, flp); if (avg_sink_temp > MAX_SINK_TEMP) fatal("too high power for a natural convection package -- possible thermal runaway\n"); if (fabs(model->config->r_convec-r_convec_old)<NATURAL_CONVEC_TOL) natural_convergence = 1; } } else /* natural convection is not used, no need for iterations */ /* steady state temperature */ steady_state_temp(model, overall_power, steady_temp); /* print steady state results */ fprintf(stdout, "Unit\tSteady(Kelvin)\n"); dump_temp(model, steady_temp, "stdout"); /* dump steady state temperatures on to file if needed */ if (strcmp(model->config->steady_file, NULLFILE)) dump_temp(model, steady_temp, model->config->steady_file); /* for the grid model, optionally dump the most recent * steady state temperatures of the grid cells */ if (model->type == GRID_MODEL && strcmp(model->config->grid_steady_file, NULLFILE)) dump_steady_temp_grid(model->grid, model->config->grid_steady_file); #if VERBOSE > 2 if (model->type == BLOCK_MODEL) { if (do_transient) { fprintf(stdout, "printing temp...\n"); dump_dvector(temp, model->block->n_nodes); } fprintf(stdout, "printing steady_temp...\n"); dump_dvector(steady_temp, model->block->n_nodes); } else { if (do_transient) { fprintf(stdout, "printing temp...\n"); dump_dvector(temp, model->grid->total_n_blocks + EXTRA); } fprintf(stdout, "printing steady_temp...\n"); dump_dvector(steady_temp, model->grid->total_n_blocks + EXTRA); } #endif /* cleanup */ fclose(pin); if (do_transient) fclose(tout); delete_RC_model(model); free_flp(flp, FALSE); if (do_transient) free_dvector(temp); free_dvector(power); free_dvector(steady_temp); free_dvector(overall_power); free_names(names); free_dvector(vals); return 0; }
void ProcessPairedEndReads(const string& command, const string& index_file, const string& reads_file_p1, const string& reads_file_p2, const string& output_file, const uint32_t& n_reads_to_process, const uint32_t& max_mismatches, const string& adaptor, const uint32_t& top_k, const int& frag_range, const bool& ambiguous, const bool& unmapped, const bool& SAM, const int& num_of_threads) { // LOAD THE INDEX HEAD INFO Genome genome; HashTable hash_table; uint32_t size_of_index; ReadIndexHeadInfo(index_file, genome, size_of_index); genome.sequence.resize(genome.length_of_genome); hash_table.counter.resize(power(4, F2SEEDKEYWIGTH) + 1); hash_table.index.resize(size_of_index); vector<vector<string> > index_names(2, vector<string>(2)); index_names[0][0] = index_file + "_CT00"; index_names[0][1] = index_file + "_CT01"; index_names[1][0] = index_file + "_GA10"; index_names[1][1] = index_file + "_GA11"; vector<vector<string> > read_names(2, vector<string>(n_reads_to_process)); vector<vector<string> > read_seqs(2, vector<string>(n_reads_to_process)); vector<vector<string> > read_scores(2, vector<string>(n_reads_to_process)); vector<int> ranked_results_size(2); vector<vector<CandidatePosition> > ranked_results(2, vector<CandidatePosition>(MAX_NUM_EXACT_MAPPED)); vector<vector<TopCandidates> > top_results(2, vector<TopCandidates>(n_reads_to_process)); FILE * fin[2]; fin[0] = fopen(reads_file_p1.c_str(), "r"); if (!fin[0]) { throw SMITHLABException("cannot open input file " + reads_file_p1); } fin[1] = fopen(reads_file_p2.c_str(), "r"); if (!fin[1]) { throw SMITHLABException("cannot open input file " + reads_file_p2); } string adaptors[2]; extract_adaptors(adaptor, adaptors[0], adaptors[1]); clock_t start_t = clock(); FILE * fout = fopen(output_file.c_str(), "w"); if (!fout) { throw SMITHLABException("cannot open input file " + output_file); } uint32_t num_of_reads[2]; StatPairedReads stat_paired_reads(ambiguous, unmapped, output_file, SAM); bool AG_WILDCARD = true; fprintf(stderr, "[MAPPING PAIRED-END READS FROM THE FOLLOWING TWO FILES]\n"); fprintf(stderr, " %s (AND)\n %s\n", reads_file_p1.c_str(), reads_file_p2.c_str()); fprintf(stderr, "[OUTPUT MAPPING RESULTS TO %s]\n", output_file.c_str()); if (SAM) { SAMHead(index_file, command, fout); } omp_set_dynamic(0); omp_set_num_threads(num_of_threads); for (uint32_t i = 0;; i += n_reads_to_process) { num_of_reads[0] = num_of_reads[1] = 0; for (uint32_t pi = 0; pi < 2; ++pi) { // paired end reads _1 and _2 AG_WILDCARD = pi == 1 ? true : false; LoadReadsFromFastqFile(fin[pi], i, n_reads_to_process, adaptors[pi], num_of_reads[pi], read_names[pi], read_seqs[pi], read_scores[pi]); if (num_of_reads[pi] == 0) break; //Initialize the paired results for (uint32_t j = 0; j < num_of_reads[pi]; ++j) { top_results[pi][j].Clear(); top_results[pi][j].SetSize(top_k); } for (uint32_t fi = 0; fi < 2; ++fi) { ReadIndex(index_names[pi][fi], genome, hash_table); char strand = fi == 0 ? '+' : '-'; #pragma omp parallel for for (uint32_t j = 0; j < num_of_reads[pi]; ++j) { PairEndMapping(read_seqs[pi][j], genome, hash_table, strand, AG_WILDCARD, max_mismatches, top_results[pi][j]); } } } if (num_of_reads[0] != num_of_reads[1]) { fprintf(stderr, "The number of reads in paired-end files should be the same.\n"); exit( EXIT_FAILURE); } if (num_of_reads[0] == 0) { break; } stat_paired_reads.total_read_pairs += num_of_reads[0]; /////////////////////////////////////////////////////////// // Merge Paired-end results for (uint32_t j = 0; j < num_of_reads[0]; ++j) { for (uint32_t pi = 0; pi < 2; ++pi) { ranked_results_size[pi] = 0; while (!top_results[pi][j].candidates.empty()) { ranked_results[pi][ranked_results_size[pi]++] = top_results[pi][j].Top(); top_results[pi][j].Pop(); } } MergePairedEndResults(genome, read_names[0][j], read_seqs[0][j], read_scores[0][j], read_seqs[1][j], read_scores[1][j], ranked_results, ranked_results_size, frag_range, max_mismatches, SAM, stat_paired_reads, fout); } if (num_of_reads[0] < n_reads_to_process) break; } fclose(fin[0]); fclose(fin[1]); fclose(fout); OutputPairedStatInfo(stat_paired_reads, output_file); fprintf(stderr, "[MAPPING TAKES %.0lf SECONDS]\n", (double(clock() - start_t) / CLOCKS_PER_SEC)); }
void main() { Load_dialogs(); read_names(); read_program(); }
int main() { char* refId = "rs1048659"; char* name = "HG00372"; // CI part int i,j; read_names(); read_ids(); int size_names = size_of_names(); int size_ids = size_of_ids(); int refId_id = find_ids_id(refId); int name_id = find_name_id(name); read_encs(); char encC = get_char_in_enc((size_names*refId_id)+name_id); read_skeys(); char skeyC = get_char_in_skeys((size_names*refId_id)+name_id); // SPU -> GC building part GarbledCircuit garbledCircuit; GarblingContext garblingContext; int inputsNb = 32; int wiresNb = 50000; int gatesNb = 50000; int outputsNb = 32; //Create a circuit. block labels[2 * inputsNb]; createInputLabels(labels, inputsNb); InputLabels inputLabels = labels; createEmptyGarbledCircuit(&garbledCircuit, inputsNb, outputsNb, gatesNb, wiresNb, inputLabels); startBuilding(&garbledCircuit, &garblingContext); // Transform generator's input into fixed wire int zero = fixedZeroWire(&garbledCircuit,&garblingContext); int one = fixedOneWire(&garbledCircuit,&garblingContext); int onewire = getNextWire(&garblingContext); NOTGate(&garbledCircuit,&garblingContext,zero,onewire); int zerowire = getNextWire(&garblingContext); NOTGate(&garbledCircuit,&garblingContext,one,zerowire); int outputs[outputsNb]; int *inp = (int *) malloc(sizeof(int) * inputsNb*2); countToN(inp, inputsNb); //countToN(outputs, inputsNb); int bits[inputsNb]; int_into_ints(encC,bits); for (i = 0; i < inputsNb; i++) { if (bits[i]) { inp[inputsNb+i] = onewire; } else { inp[inputsNb+i] = zerowire; } } int tempOutput[2*outputsNb]; XORCircuit(&garbledCircuit, &garblingContext, inputsNb*2, inp, outputs); block *outputbs = (block*) malloc(sizeof(block) * outputsNb); OutputMap outputMap = outputbs; finishBuilding(&garbledCircuit, &garblingContext, outputMap, outputs); garbleCircuit(&garbledCircuit, inputLabels, outputMap); // MU -> Evaluation part block extractedLabels[inputsNb]; int extractedInputs[inputsNb]; int_into_ints(skeyC,extractedInputs); extractLabels(extractedLabels, inputLabels, extractedInputs, inputsNb); block computedOutputMap[outputsNb]; evaluate(&garbledCircuit, extractedLabels, computedOutputMap); int outputVals[outputsNb]; mapOutputs(outputMap, computedOutputMap, outputVals, outputsNb); //TODO int res = ints_into_int(outputVals); printf("RESULT IS : %d\n",res); return 0; }
void write_Cfunc(const char *name, int argc, char **argv, Coll * ex, Coll * nm) { char buf[1024 * 8]; char word1[80], word2[80], word3[80]; int i, use_asm = 0, count; FILE *in = 0, *out = 0; int shared = shared_flag || eshared_flag; time_t tbuf; Coll names; Coll fnames; Coll dnames; Coll rnames; Coll objs; Coll libs; Coll nlibs, slibs; Coll alibs; int labn, labcn; init_Coll(&names, free, strcmp); init_Coll(&fnames, free, 0 /*strcmp */ ); init_Coll(&dnames, free, strcmp); init_Coll(&rnames, free, strcmp); init_Coll(&objs, free, 0); init_Coll(&libs, free, 0); init_Coll(&nlibs, free, 0); init_Coll(&slibs, 0, strcmp); init_Coll(&alibs, 0, 0); strcpy(buf, NM_PRG); for (i = 0; i < argc; i++) { char *a = argv[i]; if (a[0] == '-' && a[1] == 'l') { char path[256]; snprintf(path, sizeof(path), "%s/lib/lib%s%s", CLIPROOT, a + 2, SLIBSUF); if (!access(path, R_OK)) append_Coll(&libs, strdup(path)); continue; } if (a[0] == '-') { continue; } if (strsuff(a, SLIBSUF) || strsuff(a, LIBSUF)) { if (a[0] == '/' || (a[0] == '.' && a[1] == '/') || (a[0] == '.' && a[1] == '.' && a[2] == '/')) { append_Coll(&libs, strdup(a)); } else { char path[256]; snprintf(path, sizeof(path), "%s/lib/%s", CLIPROOT, a); if (!access(path, R_OK)) append_Coll(&libs, strdup(path)); } } else if (strsuff(a, SOBJSUF) || strsuff(a, OBJSUF)) append_Coll(&objs, strdup(a)); } for (i = libs.count_of_Coll - 1; i >= 0; i--) { char *s = (char *) libs.items_of_Coll[i]; char *e, *r, *b; int l, j, ind, isA = 0; e = strsuff(s, SLIBSUF); if (!e) { e = strsuff(s, LIBSUF); isA = 1; } b = strrchr(s, '/'); if (!b) b = s; else b++; if (e && e > b + 1) l = e - b; else l = strlen(b); r = (char *) malloc(l + 1); for (j = 0; j < l; j++) { switch (b[j]) { case '-': r[j] = '_'; break; default: r[j] = b[j]; break; } } r[l] = 0; if (!search_Coll(&slibs, s, &ind)) { insert_Coll(&slibs, r); if (isA) { append_Coll(&alibs, s); free(r); } else append_Coll(&nlibs, r); } else free(r); read_names(s, ex, nm); } if (!shared) { for (i = 0; i < libs.count_of_Coll; i++) { char *s = (char *) libs.items_of_Coll[i]; strcat(buf, " "); strcat(buf, s); } } else { for (i = 0; i < alibs.count_of_Coll; i++) { char *s = (char *) alibs.items_of_Coll[i]; strcat(buf, " "); strcat(buf, s); } } for (i = 0; i < objs.count_of_Coll; i++) { char *s = (char *) objs.items_of_Coll[i]; strcat(buf, " "); strcat(buf, s); read_names(s, ex, nm); } v_printf(2, "%s\n", buf); in = popen(buf, "r"); if (!in) { yyerror("cannot open pipe '%s'", buf); goto end; } #ifdef USE_AS { char *s = strrchr(name, '.'); if (asm_flag && s && !strcmp(s, ".s")) use_asm = 1; } #endif out = fopen(name, "wb"); if (!out) { yyerror("cannot open output file '%s'", name); goto end; } fprintf(out, "/*\n"); fprintf(out, " *\tautomatically generated by clip-"); printVersion(out); fprintf(out, "\n"); time(&tbuf); fprintf(out, " *\tat %s", ctime(&tbuf)); fprintf(out, " *\tfrom sources:\n"); for (i = 0; i < argc; ++i) fprintf(out, " *\t%s\n", argv[i]); fprintf(out, " */\n"); if (!use_asm) { fprintf(out, "\n#include \"ci_clip.h\"\n"); } else { fprintf(out, "\n\t.file \"%s\"\n", name); } while (fgets(buf, sizeof(buf), in) != NULL) { char *s, *sp; int br; int n = sscanf(buf, "%s %s %s", word1, word2, word3); int l; if (n == 3) { if (!strcmp(word2, "T")) br = 1; else if (!strcmp(word2, "D")) br = 2; else continue; sp = word3; } else if (n == 2) { if (strcmp(word1, "U")) continue; sp = word2; br = 3; } else continue; #ifdef NM_UNDERSCORE sp++; #endif l = strlen(sp); if (l < 6 || memcmp(sp, "clip_", 5)) goto next; for (s = sp + 5; *s; ++s) if (!isupper(*s) && !isdigit(*s) && *s != '_') goto next; if (br == 2) { if (!memcmp(sp + 5, "_PCODE_", 7)) insert_Coll(&fnames, strdup(sp)); else if (!memcmp(sp + 5, "_RDD_", 4)) insert_Coll(&dnames, strdup(sp)); else if (!memcmp(sp + 5, "_RTTI_", 6)) insert_Coll(&rnames, strdup(sp)); } else insert_Coll(&names, strdup(sp)); next: ; } if (in) { pclose(in); in = 0; } for (i = 0; i < names.count_of_Coll; ++i) { VAR(char, s, names.items_of_Coll[i]); if (!use_asm) fprintf(out, "ClipFunction %s;\n", s); add_name(nm, s); } if (shared) { for (i = nlibs.count_of_Coll - 1; i >= 0; i--) { char *s = (char *) nlibs.items_of_Coll[i]; if (!use_asm) fprintf(out, "CLIP_DLLIMPORT ClipFunction *_clip_builtin_%s ( long hash );\n", s); } } labn = 3; labcn = 0; if (!use_asm) { fprintf(out, "\nstatic ClipFunction *\n_builtins(long hash)\n{\n"); if (shared) { fprintf(out, "\tClipFunction *rp = 0;\n"); for (i = nlibs.count_of_Coll - 1; i >= 0; i--) { char *s = (char *) nlibs.items_of_Coll[i]; fprintf(out, "\trp = _clip_builtin_%s ( hash );\n", s); fprintf(out, "\tif ( rp )\n\t\treturn rp;\n"); } } fprintf(out, "\n\tswitch( hash )\n\t{\n"); for (i = 0; i < names.count_of_Coll; ++i) { VAR(char, s, names.items_of_Coll[i]); if (!memcmp(s + 5, "INIT_", 5) || !memcmp(s + 5, "EXIT_", 5)) continue; fprintf(out, "\tcase %ld:\n", (long) hashstr(s + 5)); fprintf(out, "\t\treturn %s;\n", s); } fprintf(out, "\tdefault:\n\t\treturn 0;\n"); fprintf(out, "\t}\n"); fprintf(out, "};\n\n"); }