void save_args(int argc, char **argv) { int i; for(i = 0; i < argc; ++i) { save = add_to(save,argv[i]); save = add_to(save," "); } }
char *exe_name(char *source) { char *tmp = add_to("",source); int j = strlen(tmp)-2; if (j < 0) { j = 0; } while(j>0 && tmp[j] != '.') { --j; } if (tmp[j] == '.') { ++j; } tmp[j] = '\0'; return add_to(tmp,"exe"); }
void base::add_apply(base &x) { base a; add_to(x, a); swap(a); }
void res2_poly::sort(res2term *&f) const { // Divide f into two lists of equal length, sort each, // then add them together. This allows the same monomial // to appear more than once in 'f'. if (f == NULL || f->next == NULL) return; res2term *f1 = NULL; res2term *f2 = NULL; while (f != NULL) { res2term *t = f; f = f->next; t->next = f1; f1 = t; if (f == NULL) break; t = f; f = f->next; t->next = f2; f2 = t; } sort(f1); sort(f2); add_to(f1, f2); f = f1; }
val ld_fisher0(LDP ld) { val fim = zeros(3,3); int i; for(i=0;i<ld->nrays;i++) { double alpha = ld->true_alpha[i]; if(is_nan(alpha)) continue; double theta = ld->theta[i]; double beta = alpha-theta; double r = ld->readings[i]; double c = cos(alpha); double s = sin(alpha); double z = 1 / cos(beta); double t = tan(beta); double fim_k[9] ={ c*c*z*z, c*s*z*z, c*z *t*r, c*s*z*z, s*s*z*z, s*z *t*r, c*z*t*r, s*z*t*r, t*r *t*r }; egsl_push(); val k = egsl_vFda(3,3,fim_k); add_to(fim, k); egsl_pop(); } return fim; }
static GbbPowerState * read_state(GbbPowerMonitor *monitor, GbbPowerState *state) { GList *l; int n_batteries = 0; gbb_power_state_init(state); state->time_us = g_get_monotonic_time(); for (l = monitor->adapters; l; l = l->next) { GbbMains *mains = l->data; gboolean online = gbb_mains_poll(mains); if (online) state->online = TRUE; } for (l = monitor->batteries; l; l = l->next) { GbbBattery *battery = l->data; double energy_now = gbb_battery_poll(battery); double energy_full = -1.0; double energy_full_design = -1.0; g_object_get(battery, "energy-full", &energy_full, "energy-full-design", &energy_full_design, NULL); add_to (&state->energy_now, energy_now); add_to (&state->energy_full, energy_full); if (energy_full_design >= 0) { if (n_batteries == 0 || state->energy_full_design >= 0) add_to (&state->energy_full_design, energy_full_design); } else { state->energy_full_design = -1; } state->voltage_now = -1.0; n_batteries += 1; } return state; }
void res2_poly::subtract_multiple_to(res2term *& f, ring_elem c, const int *m, const res2term *g) const // f := f - c * m * g { ring_elem minus_c = K->negate(c); res2term *h = mult_by_term(g, minus_c, m); add_to(f, h); K->remove(minus_c); }
void res2_poly::ring_subtract_multiple_to(res2term *& f, ring_elem c, const int *m, res2_pair *x, const ring_elem g) const // f := f - c * m * g * x, where g is a ring element { ring_elem minus_c = K->negate(c); res2term *h = ring_mult_by_term(g, minus_c, m, x); add_to(f, h); K->remove(minus_c); }
void test_gc_with_pointer_array() { User *u, *t; String *s; Array *a; char *expected, *result_before, *result_after; gc(); GC_SAVE_RP; s = new_String("tim"); u = new_User(102, s); a = new_Array(2, ARRAY_POINTER); add_to(a, 0, s); add_to(a, 1, u); ADD_ROOT(a); expected = "heap1[116,1000]\n" "0068:Array[32+2]->[0, 36]\n" "0000:String[32+4]=\"tim\"\n" "0036:User[32]->[0]\n"; result_before = calloc(1000, sizeof(char)); heap_dump(result_before); ASSERT_STR(expected, result_before); free(result_before); gc(); t = new_User(102, NULL); ADD_ROOT(t); expected = "heap2[148,1000]\n" "0000:Array[32+2]->[48, 84]\n" "0048:String[32+4]=\"tim\"\n" "0084:User[32]->[48]\n" "0116:User[32]->[-1]\n"; result_after = calloc(1000, sizeof(char)); heap_dump(result_after); ASSERT_STR(expected, result_after); // printf("\n%s", result_after); free(result_after); GC_RESTORE_RP; }
static int CallBack_HaltQueue(PTASK_RECORD p) { if ( p->fpTask == Task_RunQueueEntry #ifdef QUERY_SLAVE || p->fpTask == Task_SQLTimeout #endif // QUERY_SLAVE || p->fpTask == Task_SemaphoreTimeout) { // This is a @wait, timed Semaphore Task, or timed SQL Query. // BQUE *point = (BQUE *)(p->arg_voidptr); if (que_want(point, Halt_Player_Target, Halt_Object_Target)) { // Accounting for pennies and queue quota. // dbref dbOwner = point->executor; if (!isPlayer(dbOwner)) { dbOwner = Owner(dbOwner); } if (dbOwner != Halt_Player_Run) { if (Halt_Player_Run != NOTHING) { giveto(Halt_Player_Run, mudconf.waitcost * Halt_Entries_Run); a_Queue(Halt_Player_Run, -Halt_Entries_Run); } Halt_Player_Run = dbOwner; Halt_Entries_Run = 0; } Halt_Entries++; Halt_Entries_Run++; if (p->fpTask == Task_SemaphoreTimeout) { add_to(point->sem, -1, point->attr); } for (int i = 0; i < MAX_GLOBAL_REGS; i++) { if (point->scr[i]) { RegRelease(point->scr[i]); point->scr[i] = NULL; } } MEMFREE(point->text); point->text = NULL; free_qentry(point); return IU_REMOVE_TASK; } } return IU_NEXT_TASK; }
static void Task_SemaphoreTimeout(void *pExpired, int iUnused) { UNUSED_PARAMETER(iUnused); // A semaphore has timed out. // BQUE *point = (BQUE *)pExpired; add_to(point->sem, -1, point->attr); point->sem = NOTHING; Task_RunQueueEntry(point, 0); }
void maybe_cleanup(void) { DIR *dir; struct dirent *dent; if (*tmpobjdir == '\0') { return; } if (!(dir = opendir(tmpobjdir))) { return; } while((dent = readdir(dir)) != NULL) { char *fullname = add_to("",tmpobjdir); fullname = add_to(fullname,"/"); fullname = add_to(fullname,dent->d_name); unlink(fullname); free(fullname); } closedir(dir); rmdir(tmpobjdir); }
void base::add_to(base &x, base &y) { if (s_kind() != BASE) { // cout << "add_to() not implemented for class "; // printobjectkindln(cout); // exit(1); add_to(x, y); return; } NOT_EXISTING_FUNCTION("base::add_to"); exit(1); }
void test_42() { struct number n1 = {0, 0, 21}; struct number n2 = {0, 0, 21}; //print_number(&n1); //std::cout << std::endl; //print_number(&n2); //std::cout << std::endl; add_to(&n1, &n2); //print_number(&n1); //std::cout << std::endl; }
// Show available users void show_users_available(User user) { assert(user is_not None); int start_x = user->x - user->rad; int start_y = user->y - user->rad; int final_x = user->x + user->rad; int final_y = user->y + user->rad; if (start_x < 0) { start_x = 0; } if (start_y < 0) { start_y = 0; } if (final_x >= 256) { final_x = 255; } if (final_y >= 256) { final_y = 255; } int x = 0; int y = 0; UserList resL = NULL; for (x = start_x ; x < final_x; x++) { for (y = start_y; y < final_y; y++) { if (map[x][y]->users is_not None) { pthread_mutex_lock(&map_mutex); UserList U = map[x][y]->users; while (U is_not None) { resL = add_to(resL, U->info); U = U->next; } pthread_mutex_unlock(&map_mutex); } } } char buffer[MAXBUF] = "\n## Utenti disponibili nella tua area \n "; int length = (int)strlen(buffer); int counter = 0; UserList M = resL; while (M is_not None) { length += sprintf(buffer+length, " (%d) %s \n ", counter, M->info->username); counter += 1; M = M->next; } strcat(buffer, "\n Premi 0 per continuare... "); _send(user->fd, buffer); _recv(user->fd, buffer, 0); _infoUser("Asked for available users.", user->username); }
struct node *get_input(void) { struct node *first = NULL; double x = 0; double y = 0; int input; do { input = 0; input = scanf("%lf%lf", &x, &y); first = add_to(first, x, y); } while (input == 2); return first; }
char *object_name(char *source) { char *tmp = add_to("",source); int j = strlen(tmp)-2; if (j < 0) { j = 0; } while(j>0 && tmp[j] != '.') { --j; } if (tmp[j] == '.') { ++j; } tmp[j++] = 'o'; tmp[j] = '\0'; return tmp; }
// Sets the user position into the global map void map_user(User user) { assert(user is_not None); if (user->x < 0) { user->x = 0; } if (user->y < 0) { user->y = 0; } if (user->x >= 256) { user->x = 255; } if (user->y >= 256) { user->y = 255; } map[user->x][user->y]->users = add_to(map[user->x][user->y]->users, user); _infoUser("User is now mapped.", user->username); }
int nfy_que(dbref sem, int attr, int key, int count) { int cSemaphore = 1; if (attr) { int aflags; dbref aowner; char *str = atr_get(sem, attr, &aowner, &aflags); cSemaphore = mux_atol(str); free_lbuf(str); } Notify_Num_Done = 0; if (cSemaphore > 0) { Notify_Key = key; Notify_Sem = sem; Notify_Attr = attr; Notify_Num_Max = count; if ( key == NFY_NFY || key == NFY_QUIET) { scheduler.TraverseOrdered(CallBack_NotifySemaphoreFirstOrQuiet); } else { scheduler.TraverseUnordered(CallBack_NotifySemaphoreDrainOrAll); } } // Update the sem waiters count. // if ( NFY_NFY == key || NFY_QUIET == key) { add_to(sem, -count, attr); } else { atr_clr(sem, attr); } return Notify_Num_Done; }
int main() { egsl_push(); val v1 = zeros(10,10); int i; for(i=0;i<1000000;i++) { egsl_push(); val v2 = zeros(10,10); add_to(v1, v2); egsl_pop(); } egsl_pop(); egsl_print_stats(); return 0; }
ring_elem SchurRing::mult_by_term(const ring_elem f, const ring_elem c, const int *m) const { // return c*m*f ring_elem result = ZERO_RINGELEM; for (Nterm *t = f; t != NULL; t = t->next) { ring_elem a = K_->mult(c, t->coeff); ring_elem g = const_cast<SchurRing *>(this)->mult_monomials(t->monom, m); for (Nterm *s = g; s != NULL; s = s->next) { ring_elem b = K_->mult(a, s->coeff); s->coeff = b; } Nterm *gt = g; sort(gt); g = gt; add_to(result, g); } return result; }
void remap_user(User user, int x, int y) { assert(user is_not None); if (x < 0) { x = 0; } if (y < 0) { y = 0; } if (x >= 256) { x = 255; } if (y >= 256) { y = 255; } pthread_mutex_lock(&map_mutex); map[user->x][user->y]->users = remove_from(map[user->x][user->y]->users, user); map[x][y]->users = add_to(map[x][y]->users, user); user->x = x; user->y = y; pthread_mutex_unlock(&map_mutex); _infoUser("User moved.", user->username); }
// --------------------------------------------------------------------------- // do_wait: Command interface to wait_que // void do_wait ( dbref executor, dbref caller, dbref enactor, int eval, int key, char *event, char *cmd, char *cargs[], int ncargs ) { CLinearTimeAbsolute ltaWhen; CLinearTimeDelta ltd; // If arg1 is all numeric, do simple (non-sem) timed wait. // if (is_rational(event)) { if (key & WAIT_UNTIL) { ltaWhen.SetSecondsString(event); } else { ltaWhen.GetUTC(); ltd.SetSecondsString(event); ltaWhen += ltd; } wait_que(executor, caller, enactor, eval, true, ltaWhen, NOTHING, 0, cmd, ncargs, cargs, mudstate.global_regs); return; } // Semaphore wait with optional timeout. // char *what = parse_to(&event, '/', 0); init_match(executor, what, NOTYPE); match_everything(0); dbref thing = noisy_match_result(); if (!Good_obj(thing)) { return; } else if (!Controls(executor, thing) && !Link_ok(thing)) { notify(executor, NOPERM_MESSAGE); } else { // Get timeout, default 0. // int atr = A_SEMAPHORE; bool bTimed = false; if (event && *event) { if (is_rational(event)) { if (key & WAIT_UNTIL) { ltaWhen.SetSecondsString(event); } else { ltaWhen.GetUTC(); ltd.SetSecondsString(event); ltaWhen += ltd; } bTimed = true; } else { ATTR *ap = atr_str(event); if (!ap) { atr = mkattr(executor, event); if (atr <= 0) { notify_quiet(executor, "Invalid attribute."); return; } ap = atr_num(atr); } else { atr = ap->number; } if (!bCanSetAttr(executor, thing, ap)) { notify_quiet(executor, NOPERM_MESSAGE); return; } } } int num = add_to(thing, 1, atr); if (num <= 0) { // Thing over-notified, run the command immediately. // thing = NOTHING; bTimed = false; } wait_que(executor, caller, enactor, eval, bTimed, ltaWhen, thing, atr, cmd, ncargs, cargs, mudstate.global_regs); } }
int main(int argc, char **argv) { int i; int x; char *s; char *mpath; char *debuglog; FILE *debugfile; char *common_cflags="-nologo -D__WIN32__ -DWIN32 -DWINDOWS -D_WIN32 -DNT -D_CRT_SECURE_NO_DEPRECATE"; char *md = "-MD"; char *debug_flags = ""; char *optimize_flags = ""; char *outfile = ""; char *cmd = ""; char **sources = NULL; char *accum_objects = ""; char *linkcmd = ""; int md_forced = 0; int preprocessing = 0; int debug_build = 0; int optimized_build = 0; int linking = 1; int retval; save_args(argc,argv); for(i = 1; i < argc; ++i) { if (argv[i][0] == '-') { char *opt = argv[i]+1; switch(*opt) { case 'W': if(strcmp(opt,"Wall")) { goto filename; } break; case 'c': if(strlen(opt) > 1) { goto filename; } linking = 0; break; case 'E': if(strlen(opt) > 1) { if (opt[1] == 'H') { cmd = add_to(cmd," "); cmd = add_to(cmd,opt); } else { goto filename; } } preprocessing = 1; linking = 0; break; case 'O': /* ignore what opt is requested, set hard */ optimize_flags = "-Ox -Zi"; debug_flags = ""; debug_build = 0; if (!md_forced) { md = "-MD"; } optimized_build = 1; break; case 'g': if (strcmp(opt,"g") && strcmp(opt,"ggdb")) { goto filename; } if (!optimized_build) { debug_flags = "-Z7"; if (!md_forced) { md = "-MDd"; } linkcmd = add_to(linkcmd," -g"); debug_build = 1; } break; case 'm': case 'M': if(!strcmp(opt,"mt") || !strcmp(opt,"MT")) { md = "-MT"; } else if (!strcmp(opt,"md") || !strcmp(opt,"MD")) { md = "-MD"; } else if (!strcmp(opt,"ml") || !strcmp(opt,"ML")) { md = "-ML"; } else if (!strcmp(opt,"mdd") || !strcmp(opt,"MDd") || !strcmp(opt,"MDD")) { md = "-MDd"; } else if (!strcmp(opt,"mtd") || !strcmp(opt,"MTd") || !strcmp(opt,"MTD")) { md = "-MTd"; } else if (!strcmp(opt,"mld") || !strcmp(opt,"MLd") || !strcmp(opt,"MLD")) { md = "-MLd"; } else { goto filename; } md_forced = 1; break; case 'o': if (!strcmp(opt,"o")) { ++i; if (i >= argc) { error("-o without filename"); } outfile = argv[i]; } else { outfile = opt+1; } break; case 'I': if(opt[1] == '/') { mpath = do_cyp(opt+1); cmd = add_to(cmd," -I\""); cmd = add_to(cmd,mpath); cmd = add_to(cmd,"\""); free(mpath); } else { cmd = add_to(cmd," "); cmd = add_to(cmd,opt); } break; case 'D': cmd = add_to(cmd," -"); cmd = add_to(cmd,opt); case 'l': linkcmd = add_to(linkcmd," -"); linkcmd = add_to(linkcmd,opt); break; default: goto filename; } continue; } filename: s = argv[i]; x = strlen(s); if (x > 1 && s[x-1] == 'c' && s[x-2] == '.') { /* C source */ sources = add_to_src(sources,s); } else if (x > 3 && !strcmp(s + (x - 4),".cpp")) { /* C++ */ sources = add_to_src(sources,s); } else if (x > 1 && s[x-1] == 'o' && s[x-2] == '.') { linkcmd = add_to(linkcmd," "); linkcmd = add_to(linkcmd,s); } else { /* Pass rest to linker */ linkcmd = add_to(linkcmd," "); linkcmd = add_to(linkcmd,s); } } if ((debuglog = getenv("CC_SH_DEBUG_LOG")) != NULL) { debugfile = fopen(debuglog,"wb+"); if (debugfile) { fprintf(debugfile,"----------------\n"); } } else { debugfile = NULL; } tmpobjdir = add_to("","/tmp/tmpobj"); { char pidstr[100]; pid_t pid = getpid(); sprintf(pidstr,"%d",pid); tmpobjdir = add_to(tmpobjdir,pidstr); } mkdir(tmpobjdir,0777); if (sources != NULL) { char *output_filename; char *output_flag; char *params; for (i=0;sources[i] != NULL; ++i) { if (!linking) { int x = strlen(outfile); if (x > 1 && outfile[x-1] == 'o' && outfile[x-2] == '.') { if (*outfile != '/') { /* non absolute object */ if (i > 0) { error("Single object multiple sources"); } output_filename = add_to("",outfile); } else { if (i > 0) { error("Single object multiple sources"); } output_filename = do_cyp(outfile); } } else { char *tmp = object_name(sources[i]); /*fprintf(stderr,"sources[i] = %s\ntmp = %s\n", sources[i],tmp);*/ if (!x || outfile[0] != '/') { /* non absolute directory */ output_filename = add_to("",outfile); } else { output_filename = do_cyp(outfile); } /*fprintf(stderr,"output_filename = %s\n",output_filename);*/ if (*output_filename != '\0') { output_filename = add_to(output_filename,"/"); } output_filename = add_to(output_filename,tmp); free(tmp); } } else { char *tmp = object_name(sources[i]); output_filename = add_to("",tmpobjdir); output_filename = add_to(output_filename,"/"); output_filename = add_to(output_filename,tmp); accum_objects = add_to(accum_objects," "); accum_objects = add_to(accum_objects,output_filename); /* reform to dos path */ free(output_filename); output_filename = do_cyp(tmpobjdir); output_filename = add_to(output_filename,"/"); output_filename = add_to(output_filename,tmp); } mpath = do_cyp(sources[i]); if (preprocessing) { output_flag = add_to("","-E"); } else { output_flag = add_to("","-c -Fo"); output_flag = add_to(output_flag,output_filename); } params = add_to("","cl.exe "); params = add_to(params,common_cflags); params = add_to(params," "); params = add_to(params,md); params = add_to(params," "); params = add_to(params,debug_flags); params = add_to(params," "); params = add_to(params,optimize_flags); params = add_to(params," "); params = add_to(params,cmd); params = add_to(params," "); params = add_to(params,output_flag); params = add_to(params," "); params = add_to(params,mpath); free(output_filename); free(output_flag); free(mpath); if (debugfile) { fprintf(debugfile,"%s\n",save); fprintf(debugfile,"%s\n",params); } if (preprocessing) { retval = run(params,0,1); } else { retval = run(params,1,0); } if (retval != 0) { maybe_cleanup(); return retval; } free(params); } } if (linking) { char *out_spec; char *stdlib; char *params; if (strlen(outfile) == 0) { if (sources != NULL && sources[0] != NULL) { char *tmp = exe_name(sources[0]); out_spec = add_to("","-o "); out_spec = add_to(out_spec,tmp); free(tmp); } else { out_spec = add_to("",""); } } else { out_spec = add_to("","-o "); out_spec = add_to(out_spec,outfile); } if (!strcmp(md,"-ML")) { stdlib="-lLIBC"; } else if (!strcmp(md,"-MLd")) { stdlib="-lLIBCD"; } else if (!strcmp(md,"-MD")) { stdlib="-lMSVCRT"; } else if (!strcmp(md,"-MDd")) { stdlib="-lMSVCRTD"; } else if (!strcmp(md,"-MT")) { stdlib="-lLIBCMT"; } else if (!strcmp(md,"-MTd")) { stdlib="-lLIBMTD"; } else { stdlib = ""; } #if 0 params = add_to("","bash ld.sh "); #else params = add_to("","ld_wrap.exe "); #endif params = add_to(params,accum_objects); params = add_to(params," "); params = add_to(params,out_spec); params = add_to(params," "); params = add_to(params,linkcmd); params = add_to(params," "); params = add_to(params,stdlib); free(out_spec); free(accum_objects); if (debugfile) { fprintf(debugfile,"%s\n",params); } if (retval = run(params,0,0) != 0) { maybe_cleanup(); return retval; } free(params); } maybe_cleanup(); return 0; }
//--------------------------------------------------------------------------- char HeightMap::copy_to(HeightMap *dst) { //地図の内容コピー dst->clear(); return (add_to(dst)); }
void cluster(point ps[], int n, int k, int cs[]) { point centers[k]; // the center point of each cluster int change; // any change since the last iteration? // the current point point c_point; ld c_dist; // the nearest cluster, and the distance to its center int n_cluster; ld n_dist; // the sum of all of a cluster's points, and the number // of points added together point sum_points; int num_points; /* // initialize the cluster means to be random points int j = 0; while(j < (k - 1)) { // choose a random point p = ps[random(0, n)]; // ensure we're not already using it }*/ // initialize all the points to be in random clusters for(int i = 0; i < n; i++) { cs[i] = random(0, k - 1); } // initialize the cluster centers to be the first k points for(int j = 0; j < k; j++) { centers[j] = ps[j]; } /*// initialize the cluster means to be random points for(int j = 0; j < k; j++) { centers[j] = ps[random(0, n - 1)]; }*/ // keep refining the clusters until there is no more change do { // reset the "changed" switch change = 0; // partition all the points to their nearest clusters for(int i = 0; i < n; i++) { // the point we're currently at c_point = ps[i]; // the nearest cluster to this point n_cluster = cs[i]; n_dist = dist(c_point, centers[n_cluster]); // search for the nearest cluster to this point for(int j = 0; j < k; j++) { // if the distance to this cluster center // is shorter than the shortest distance, // then this is the nearest cluster so far if( ( c_dist = dist(c_point, centers[j]) ) < n_dist ) { // update the nearest cluster n_cluster = j; n_dist = c_dist; // note that we performed a change change = 1; } } // assign this point to its nearest cluster cs[i] = n_cluster; } // set all the cluster centers to be the mean of their points for(int j = 0; j < k; j++) { // reset the points summed up initialize(&sum_points); num_points = 0; // go through all this cluster's points for(int i = 0; i < n; i++) { // if this point belongs to a different // cluster: we don't care about it if(cs[i] != j) { continue; } // add it to the sum add_to(&sum_points, ps[i]); num_points++; } // work out the mean center of the cluster divide(&sum_points, num_points); // let the cluster center be the mean of all the points centers[j] = sum_points; } } while(change); }