static char *gamedate2(const struct locale *lang) { static char buf[256]; gamedate gd; const char *week = "a_week", *month = "a_month"; get_gamedate(turn, &gd); if (weeknames2) { week = weeknames2[gd.week]; } month = calendar_month(gd.month); sprintf(buf, "in %s des Monats %s im Jahre %d %s.", LOC(lang, mkname("calendar", week)), LOC(lang, mkname("calendar", month)), gd.year, LOC(lang, mkname("calendar", calendar_era()))); return buf; }
Node * mksliceexpr(Srcloc loc, Node *sl, Node *base, Node *off) { if (!base) base = mkintlit(loc, 0); if (!off) off = mkexpr(loc, Omemb, sl, mkname(loc, "len"), NULL); return mkexpr(loc, Oslice, sl, base, off, NULL); }
/* * C_SPARKLE */ static message *cinfo_sparkle(const void *obj, objtype_t typ, const curse * c, int self) { const char *effects[] = { NULL, /* end grau */ "sparkle_1", "sparkle_2", NULL, /* end traum */ "sparkle_3", "sparkle_4", NULL, /* end tybied */ "sparkle_5", "sparkle_6", "sparkle_7", "sparkle_8", NULL, /* end cerrdor */ "sparkle_9", "sparkle_10", "sparkle_11", "sparkle_12", NULL, /* end gwyrrd */ "sparkle_13", "sparkle_14", "sparkle_15", "sparkle_16", "sparkle_17", "sparkle_18", NULL, /* end draig */ }; int m, begin = 0, end = 0; unit *u; unused_arg(typ); assert(typ == TYP_UNIT); u = (unit *)obj; if (!c->magician || !c->magician->faction) return NULL; for (m = 0; m != c->magician->faction->magiegebiet; ++m) { while (effects[end] != NULL) ++end; begin = end + 1; end = begin; } while (effects[end] != NULL) ++end; if (end == begin) return NULL; else { int index = begin + curse_geteffect_int(c) % (end - begin); return msg_message(mkname("curseinfo", effects[index]), "unit id", u, c->no); } }
/* * C_ORC */ message *cinfo_unit(const void *obj, objtype_t typ, const curse * c, int self) { unused_arg(typ); assert(typ == TYP_UNIT); if (self != 0) { unit *u = (unit *) obj; return msg_message(mkname("curseinfo", c->type->cname), "unit id", u, c->no); } return NULL; }
static const char *b_namewall(const connection * b, const region * r, const struct faction *f, int gflags) { const char *bname = "wall"; unused_arg(f); unused_arg(r); unused_arg(b); if (gflags & GF_ARTICLE) bname = "a_wall"; if (gflags & GF_PURE) return bname; return LOC(f->locale, mkname("border", bname)); }
/* ------------------------------------------------------------- */ message *cinfo_simple(const void *obj, objtype_t typ, const struct curse * c, int self) { struct message *msg; unused_arg(typ); unused_arg(self); unused_arg(obj); msg = msg_message(mkname("curseinfo", c->type->cname), "id", c->no); if (msg == NULL) { log_error("There is no curseinfo for %s.\n", c->type->cname); } return msg; }
entrypt(int Class, int type, ftnint length, Extsym *entry, chainp args) #endif { register Namep q; register struct Entrypoint *p; if(Class != CLENTRY) puthead( procname = entry->cextname, Class); else fprintf(diagfile, " entry "); fprintf(diagfile, " %s:\n", entry->fextname); fflush(diagfile); q = mkname(entry->fextname); if (type == TYSUBR) q->vstg = STGEXT; type = lengtype(type, length); if(Class == CLPROC) { procclass = CLPROC; proctype = type; procleng = type == TYCHAR ? length : 0; } p = ALLOC(Entrypoint); p->entnextp = entries; entries = p; p->entryname = entry; p->arglist = revchain(args); p->enamep = q; if(Class == CLENTRY) { Class = CLPROC; if(proctype == TYSUBR) type = TYSUBR; } q->vclass = Class; q->vprocclass = 0; settype(q, type, length); q->vprocclass = PTHISPROC; /* hold all initial entry points till end of declarations */ if(parstate >= INDATA) doentry(p); }
static const char *b_namefirewall(const connection * b, const region * r, const faction * f, int gflags) { const char *bname; UNUSED_ARG(f); UNUSED_ARG(r); UNUSED_ARG(b); if (gflags & GF_ARTICLE) bname = "a_firewall"; else bname = "firewall"; if (gflags & GF_PURE) return bname; return LOC(f->locale, mkname("border", bname)); }
SYMB *mktmp(void) { extern int next_tmp; SYMB *old_yylval = yylval.symb; SYMB *temp; char name[12]; sprintf(name, "T%d", next_tmp++); mkname(table_ptr, name, T_TEMP); temp = yylval.symb; yylval.symb = old_yylval; return temp; }
static Node *gentemp(Simp *simp, Node *e, Type *ty, Node **dcl) { char buf[128]; static int nexttmp; Node *t, *r, *n; snprintf(buf, 128, ".t%d", nexttmp++); n = mkname(e->line, buf); t = mkdecl(e->line, n, ty); r = mkexpr(e->line, Ovar, n, NULL); r->expr.type = t->decl.type; r->expr.did = t->decl.did; if (dcl) *dcl = t; return r; }
Node * gentemp(Srcloc loc, Type *ty, Node **dcl) { char buf[128]; static int nexttmp; Node *t, *r, *n; bprintf(buf, 128, ".t%d", nexttmp++); n = mkname(loc, buf); t = mkdecl(loc, n, ty); r = mkexpr(loc, Ovar, n, NULL); r->expr.type = t->decl.type; r->expr.did = t->decl.did; if (dcl) *dcl = t; return r; }
message *cinfo_ship(const void *obj, objtype_t typ, const curse * c, int self) { message *msg; unused_arg(typ); unused_arg(obj); assert(typ == TYP_SHIP); if (self != 0) { /* owner or inside */ msg = msg_message(mkname("curseinfo", c->type->cname), "id", c->no); } else { msg = msg_message("curseinfo::ship_unknown", "id", c->no); } if (msg == NULL) { log_error("There is no curseinfo for %s.\n", c->type->cname); } return msg; }
static void* run_thr(void *arg) { thread_ctx *ctx = (thread_ctx*)arg; double t = 0; int i, start = ctx->start, end = ctx->end, nb = ctx->nb; char outname[1024], *path = ctx->path, *outfile = ctx->outfile; memset(outname, '\0', sizeof(outname)); printf("starting thread %d\n", start); for (i = start; i <= end; i+= nb) { IplImage *img = alignedImageFrom(mkname(path, i), 8); double start = get_time(); if (outfile) snprintf(outname, sizeof(outname), "%s/bin%06d.png", outfile, i); process(ctx->kdt, ctx->bkg, ctx->diff, img, outname); t += (get_time() - start); if ((cvWaitKey(1)&255)==27)break; // esc cvReleaseImage(&img); } printf("avg: %fms\n", t/(i-start)*1000); return NULL; }
static void tower_init(void) { int i, first = newarena; item_type *it_demonseye = it_find("demonseye"); item_type *it_griphonwing = it_find("griphonwing"); assert(it_griphonwing && it_demonseye); for (i = 0; i != 6; ++i) { region *r = tower_region[i] = findregion(arena_center->x + delta_x[i] * 3, arena_center->y + delta_y[i] * 3); if (r) { start_region[i] = findregion(arena_center->x + delta_x[i] * 2, arena_center->y + delta_y[i] * 2); if (rterrain(r) != T_DESERT) terraform(r, T_DESERT); if (!r->buildings) { building *b = new_building(bt_find("castle"), r, NULL); b->size = 10; if (i != 0) { sprintf(buf, "Turm des %s", LOC(default_locale, mkname("school", magic_school[i]))); } else sprintf(buf, "Turm der Ahnungslosen"); set_string(&b->name, buf); } } } if (first && !arena_center->buildings) { building *b = new_building(bt_find("castle"), arena_center, NULL); attrib *a; item *items; i_add(&items, i_new(it_griphonwing, 1)); i_add(&items, i_new(it_demonseye, 1)); a = a_add(&b->attribs, make_giveitem(b, items)); b->size = 10; set_string(&b->name, "Höhle des Greifen"); } }
static Node *simpblob(Simp *s, Node *blob, Node ***l, size_t *nl) { Node *n, *d, *r; char lbl[128]; n = mkname(blob->line, genlblstr(lbl, 128)); d = mkdecl(blob->line, n, blob->expr.type); r = mkexpr(blob->line, Ovar, n, NULL); d->decl.init = blob; d->decl.type = blob->expr.type; d->decl.isconst = 1; htput(s->globls, d, strdup(lbl)); r->expr.did = d->decl.did; r->expr.type = blob->expr.type; r->expr.isconst = 1; lappend(l, nl, d); return r; }
static const char *b_nameroad(const connection * b, const region * r, const struct faction *f, int gflags) { region *r2 = (r == b->to) ? b->from : b->to; int local = (r == b->from) ? b->data.sa[0] : b->data.sa[1]; static char buffer[64]; unused_arg(f); if (gflags & GF_PURE) return "road"; if (gflags & GF_ARTICLE) { if (!(gflags & GF_DETAILED)) return LOC(f->locale, mkname("border", "a_road")); else if (r->terrain->max_road <= local) { int remote = (r2 == b->from) ? b->data.sa[0] : b->data.sa[1]; if (r2->terrain->max_road <= remote) { return LOC(f->locale, mkname("border", "a_road")); } else { return LOC(f->locale, mkname("border", "an_incomplete_road")); } } else { int percent = _max(1, 100 * local / r->terrain->max_road); if (local) { slprintf(buffer, sizeof(buffer), LOC(f->locale, mkname("border", "a_road_percent")), percent); } else { return LOC(f->locale, mkname("border", "a_road_connection")); } } } else if (gflags & GF_PLURAL) return LOC(f->locale, mkname("border", "roads")); else return LOC(f->locale, mkname("border", "road")); return buffer; }
startproc(Extsym *progname, int Class) #endif { register struct Entrypoint *p; p = ALLOC(Entrypoint); if(Class == CLMAIN) { puthead(CNULL, CLMAIN); if (progname) strcpy (main_alias, progname->cextname); } else { if (progname) { /* Construct an empty subroutine with this name */ /* in case the name is needed to force loading */ /* of this block-data subprogram: the name can */ /* appear elsewhere in an external statement. */ entrypt(CLPROC, TYSUBR, (ftnint)0, progname, (chainp)0); endproc(); newproc(); } puthead(CNULL, CLBLOCK); } if(Class == CLMAIN) newentry( mkname(" MAIN"), 0 )->extinit = 1; p->entryname = progname; entries = p; procclass = Class; fprintf(diagfile, " %s", (Class==CLMAIN ? "MAIN" : "BLOCK DATA") ); if(progname) { fprintf(diagfile, " %s", progname->fextname); procname = progname->cextname; } fprintf(diagfile, ":\n"); fflush(diagfile); }
doentry(struct Entrypoint *ep) #endif { register int type; register Namep np; chainp p, p1; register Namep q; Addrp rs; int it, k; extern char dflttype[26]; Extsym *entryname = ep->entryname; if (++nentry > 1) p1_label((long)(extsymtab - entryname - 1)); /* The main program isn't allowed to have parameters, so any given parameters are ignored */ if(procclass == CLMAIN && !ep->arglist || procclass == CLBLOCK) return; /* Entry points in MAIN are an error, but we process them here */ /* to prevent faults elsewhere. */ /* So now we're working with something other than CLMAIN or CLBLOCK. Determine the type of its return value. */ impldcl( np = mkname(entryname->fextname) ); type = np->vtype; proc_argchanges = prev_proc && type != entryname->extype; entryname->extseen = 1; if(proctype == TYUNKNOWN) if( (proctype = type) == TYCHAR) procleng = np->vleng ? np->vleng->constblock.Const.ci : (ftnint) (-1); if(proctype == TYCHAR) { if(type != TYCHAR) err("noncharacter entry of character function"); /* Functions returning type char can only have multiple entries if all entries return the same length */ else if( (np->vleng ? np->vleng->constblock.Const.ci : (ftnint) (-1)) != procleng) err("mismatched character entry lengths"); } else if(type == TYCHAR) err("character entry of noncharacter function"); else if(type != proctype) multitype = YES; if(rtvlabel[type] == 0) rtvlabel[type] = (int)newlabel(); ep->typelabel = rtvlabel[type]; if(type == TYCHAR) { if(chslot < 0) { chslot = nextarg(TYADDR); chlgslot = nextarg(TYLENG); } np->vstg = STGARG; /* Put a new argument in the function, one which will hold the result of a character function. This will have to be named sometime, probably in mkarg(). */ if(procleng < 0) { np->vleng = (expptr) mkarg(TYLENG, chlgslot); np->vleng->addrblock.uname_tag = UNAM_IDENT; strcpy (np -> vleng -> addrblock.user.ident, new_func_length()); } if (!xretslot[TYCHAR]) { xretslot[TYCHAR] = rs = autovar(0, type, ISCONST(np->vleng) ? np->vleng : ICON(0), ""); strcpy(rs->user.ident, "ret_val"); } } /* Handle a complex return type -- declare a new parameter (pointer to a complex value) */ else if( ISCOMPLEX(type) ) { if (!xretslot[type]) xretslot[type] = autovar(0, type, EXNULL, " ret_val"); /* the blank is for use in out_addr */ np->vstg = STGARG; if(cxslot < 0) cxslot = nextarg(TYADDR); } else if (type != TYSUBR) { if (type == TYUNKNOWN) { dclerr("untyped function", np); proctype = type = np->vtype = dflttype[letter(np->fvarname[0])]; } if (!xretslot[type]) xretslot[type] = retslot = autovar(1, type, EXNULL, " ret_val"); /* the blank is for use in out_addr */ np->vstg = STGAUTO; } for(p = ep->arglist ; p ; p = p->nextp) if(! (( q = (Namep) (p->datap) )->vknownarg) ) { q->vknownarg = 1; q->vardesc.varno = nextarg(TYADDR); allargs = mkchain((char *)q, allargs); q->argno = nallargs++; } else if (nentry == 1) duparg(q); else for(p1 = ep->arglist ; p1 != p; p1 = p1->nextp) if ((Namep)p1->datap == q) duparg(q); k = 0; for(p = ep->arglist ; p ; p = p->nextp) { if(! (( q = (Namep) (p->datap) )->vdcldone) ) { impldcl(q); q->vdcldone = YES; if(q->vtype == TYCHAR) { /* If we don't know the length of a char*(*) (i.e. a string), we must add in this additional length argument. */ ++nallchargs; if (q->vclass == CLPROC) nallchargs--; else if (q->vleng == NULL) { /* character*(*) */ q->vleng = (expptr) mkarg(TYLENG, nextarg(TYLENG) ); unamstring((Addrp)q->vleng, new_arg_length(q)); } } } if (q->vdimfinish) dim_finish(q); if (q->vtype == TYCHAR && q->vclass != CLPROC) k++; } if (entryname->extype != type) changedtype(np); /* save information for checking consistency of arg lists */ it = infertypes; if (entryname->exproto) infertypes = 1; save_argtypes(ep->arglist, &entryname->arginfo, &np->arginfo, 0, np->fvarname, STGEXT, k, np->vtype, 2); infertypes = it; }
const char *rc_name(const race * rc, int n) { return rc ? mkname("race", rc->_name[n]) : NULL; }
void main(int argc, char **argv) { char *f[10], *local, *name, *remote, *s, *t, verb; int fd, havedb, havelocal, i, k, n, nf, resolve1, skip; int checkedmatch1, checkedmatch2, checkedmatch3, checkedmatch4; ulong now; Biobuf bin; Dir dbd, ld, nd, rd; Avlwalk *w; Entry *e; membogus(argv); quotefmtinstall(); ARGBEGIN{ case 's': case 'c': i = ARGC(); addresolve(i, EARGF(usage())); break; case 'n': donothing = 1; verbose = 1; break; case 'S': safeinstall = 0; break; case 'T': timefile = EARGF(usage()); break; case 't': tempspool = 0; break; case 'u': douid = 1; break; case 'v': verbose++; break; default: usage(); }ARGEND if(argc < 3) usage(); if(timefile) readtimefile(); lroot = argv[1]; if(!isdir(lroot)) sysfatal("bad local root directory"); rroot = argv[2]; if(!isdir(rroot)) sysfatal("bad remote root directory"); match = argv+3; nmatch = argc-3; for(i=0; i<nmatch; i++) if(match[i][0] == '/') match[i]++; if((clientdb = opendb(argv[0])) == nil) sysfatal("opendb %q: %r", argv[2]); copyerr = opendb(nil); skip = 0; Binit(&bin, 0, OREAD); for(; s=Brdstr(&bin, '\n', 1); free(s)){ t = estrdup(s); nf = tokenize(s, f, nelem(f)); if(nf != 10 || strlen(f[2]) != 1){ skip = 1; fprint(2, "warning: skipping bad log entry <%s>\n", t); free(t); continue; } free(t); now = strtoul(f[0], 0, 0); n = atoi(f[1]); verb = f[2][0]; name = f[3]; if(now < maxnow || (now==maxnow && n <= maxn)) continue; local = mkname(localbuf, sizeof localbuf, lroot, name); if(strcmp(f[4], "-") == 0) f[4] = f[3]; remote = mkname(remotebuf, sizeof remotebuf, rroot, f[4]); rd.name = f[4]; rd.mode = strtoul(f[5], 0, 8); rd.uid = f[6]; rd.gid = f[7]; rd.mtime = strtoul(f[8], 0, 10); rd.length = strtoll(f[9], 0, 10); havedb = finddb(clientdb, name, &dbd)>=0; havelocal = localdirstat(local, &ld)>=0; resolve1 = resolve(name); /* * if(!ismatch(name)){ * skip = 1; * continue; * } * * This check used to be right here, but we want * the time to be able to move forward past entries * that don't match and have already been applied. * So now every path below must checked !ismatch(name) * before making any changes to the local file * system. The fake variable checkedmatch * tracks whether !ismatch(name) has been checked. * If the compiler doesn't produce any used/set * warnings, then all the paths should be okay. * Even so, we have the asserts to fall back on. */ switch(verb){ case 'd': /* delete file */ delce(local); if(!havelocal) /* doesn't exist; who cares? */ break; if(access(remote, AEXIST) >= 0) /* got recreated! */ break; if(!ismatch(name)){ skip = prstopped(skip, name); continue; } SET(checkedmatch1); if(!havedb){ if(resolve1 == 's') goto DoRemove; else if(resolve1 == 'c') goto DoRemoveDb; conflict(name, "locally created; will not remove"); skip = 1; continue; } assert(havelocal && havedb); if(dbd.mtime > rd.mtime) /* we have a newer file than what was deleted */ break; if(samecontents(local, remote) > 0){ /* going to get recreated */ chat("= %q %luo %q %q %lud\n", name, rd.mode, rd.uid, rd.gid, rd.mtime); break; } if(!(dbd.mode&DMDIR) && (dbd.mtime != ld.mtime || dbd.length != ld.length)){ /* locally modified since we downloaded it */ if(resolve1 == 's') goto DoRemove; else if(resolve1 == 'c') break; conflict(name, "locally modified; will not remove"); skip = 1; continue; } DoRemove: USED(checkedmatch1); assert(ismatch(name)); chat("d %q %luo %q %q %lud\n", name, rd.mode, rd.uid, rd.gid, rd.mtime); if(donothing) break; if(remove(local) < 0){ error("removing %q: %r", name); skip = 1; continue; } DoRemoveDb: USED(checkedmatch1); assert(ismatch(name)); removedb(clientdb, name); break; case 'a': /* add file */ if(!havedb){ if(!ismatch(name)){ skip = prstopped(skip, name); continue; } SET(checkedmatch2); if(!havelocal) goto DoCreate; if((ld.mode&DMDIR) && (rd.mode&DMDIR)) break; if(samecontents(local, remote) > 0){ chat("= %q %luo %q %q %lud\n", name, rd.mode, rd.uid, rd.gid, rd.mtime); goto DoCreateDb; } if(resolve1 == 's') goto DoCreate; else if(resolve1 == 'c') goto DoCreateDb; conflict(name, "locally created; will not overwrite"); skip = 1; continue; } assert(havedb); if(dbd.mtime >= rd.mtime) /* already created this file; ignore */ break; if(havelocal){ if((ld.mode&DMDIR) && (rd.mode&DMDIR)) break; if(!ismatch(name)){ skip = prstopped(skip, name); continue; } SET(checkedmatch2); if(samecontents(local, remote) > 0){ chat("= %q %luo %q %q %lud\n", name, rd.mode, rd.uid, rd.gid, rd.mtime); goto DoCreateDb; } if(dbd.mtime==ld.mtime && dbd.length==ld.length) goto DoCreate; if(resolve1=='s') goto DoCreate; else if(resolve1 == 'c') goto DoCreateDb; conflict(name, "locally modified; will not overwrite"); skip = 1; continue; } if(!ismatch(name)){ skip = prstopped(skip, name); continue; } SET(checkedmatch2); DoCreate: USED(checkedmatch2); assert(ismatch(name)); if(notexists(remote)){ addce(local); /* no skip=1 */ break;; } chat("a %q %luo %q %q %lud\n", name, rd.mode, rd.uid, rd.gid, rd.mtime); if(donothing) break; if(rd.mode&DMDIR){ fd = create(local, OREAD, DMDIR); if(fd < 0 && isdir(local)) fd = open(local, OREAD); if(fd < 0){ error("mkdir %q: %r", name); skip = 1; continue; } nulldir(&nd); nd.mode = rd.mode; if(dirfwstat(fd, &nd) < 0) fprint(2, "warning: cannot set mode on %q\n", local); nulldir(&nd); nd.gid = rd.gid; if(dirfwstat(fd, &nd) < 0) fprint(2, "warning: cannot set gid on %q\n", local); if(douid){ nulldir(&nd); nd.uid = rd.uid; if(dirfwstat(fd, &nd) < 0) fprint(2, "warning: cannot set uid on %q\n", local); } close(fd); rd.mtime = now; }else{ if(copyfile(local, remote, name, &rd, 1, &k) < 0){ if(k) addce(local); skip = 1; continue; } } DoCreateDb: USED(checkedmatch2); assert(ismatch(name)); insertdb(clientdb, name, &rd); break; case 'c': /* change contents */ if(!havedb){ if(notexists(remote)){ addce(local); /* no skip=1 */ break; } if(!ismatch(name)){ skip = prstopped(skip, name); continue; } SET(checkedmatch3); if(resolve1 == 's') goto DoCopy; else if(resolve1=='c') goto DoCopyDb; if(samecontents(local, remote) > 0){ chat("= %q %luo %q %q %lud\n", name, rd.mode, rd.uid, rd.gid, rd.mtime); goto DoCopyDb; } if(havelocal) conflict(name, "locally created; will not update"); else conflict(name, "not replicated; will not update"); skip = 1; continue; } if(dbd.mtime >= rd.mtime) /* already have/had this version; ignore */ break; if(!ismatch(name)){ skip = prstopped(skip, name); continue; } SET(checkedmatch3); if(!havelocal){ if(notexists(remote)){ addce(local); /* no skip=1 */ break; } if(resolve1 == 's') goto DoCopy; else if(resolve1 == 'c') break; conflict(name, "locally removed; will not update"); skip = 1; continue; } assert(havedb && havelocal); if(dbd.mtime != ld.mtime || dbd.length != ld.length){ if(notexists(remote)){ addce(local); /* no skip=1 */ break; } if(samecontents(local, remote) > 0){ chat("= %q %luo %q %q %lud\n", name, rd.mode, rd.uid, rd.gid, rd.mtime); goto DoCopyDb; } if(resolve1 == 's') goto DoCopy; else if(resolve1 == 'c') goto DoCopyDb; conflict(name, "locally modified; will not update [%llud %lud -> %llud %lud]", dbd.length, dbd.mtime, ld.length, ld.mtime); skip = 1; continue; } DoCopy: USED(checkedmatch3); assert(ismatch(name)); if(notexists(remote)){ addce(local); /* no skip=1 */ break; } chat("c %q\n", name); if(donothing) break; if(copyfile(local, remote, name, &rd, 0, &k) < 0){ if(k) addce(local); skip = 1; continue; } DoCopyDb: USED(checkedmatch3); assert(ismatch(name)); if(!havedb){ if(havelocal) dbd = ld; else dbd = rd; } dbd.mtime = rd.mtime; dbd.length = rd.length; insertdb(clientdb, name, &dbd); break; case 'm': /* change metadata */ if(!havedb){ if(notexists(remote)){ addce(local); /* no skip=1 */ break; } if(!ismatch(name)){ skip = prstopped(skip, name); continue; } SET(checkedmatch4); if(resolve1 == 's'){ USED(checkedmatch4); SET(checkedmatch2); goto DoCreate; } else if(resolve1 == 'c') goto DoMetaDb; if(havelocal) conflict(name, "locally created; will not update metadata"); else conflict(name, "not replicated; will not update metadata"); skip = 1; continue; } if(!(dbd.mode&DMDIR) && dbd.mtime > rd.mtime) /* have newer version; ignore */ break; if((dbd.mode&DMDIR) && dbd.mtime > now) break; if(havelocal && (!douid || strcmp(ld.uid, rd.uid)==0) && strcmp(ld.gid, rd.gid)==0 && ld.mode==rd.mode) break; if(!havelocal){ if(notexists(remote)){ addce(local); /* no skip=1 */ break; } if(!ismatch(name)){ skip = prstopped(skip, name); continue; } SET(checkedmatch4); if(resolve1 == 's'){ USED(checkedmatch4); SET(checkedmatch2); goto DoCreate; } else if(resolve1 == 'c') break; conflict(name, "locally removed; will not update metadata"); skip = 1; continue; } if(!(dbd.mode&DMDIR) && (dbd.mtime != ld.mtime || dbd.length != ld.length)){ /* this check might be overkill */ if(notexists(remote)){ addce(local); /* no skip=1 */ break; } if(!ismatch(name)){ skip = prstopped(skip, name); continue; } SET(checkedmatch4); if(resolve1 == 's' || samecontents(local, remote) > 0) goto DoMeta; else if(resolve1 == 'c') break; conflict(name, "contents locally modified (%s); will not update metadata to %s %s %luo", dbd.mtime != ld.mtime ? "mtime" : dbd.length != ld.length ? "length" : "unknown", rd.uid, rd.gid, rd.mode); skip = 1; continue; } if((douid && strcmp(ld.uid, dbd.uid)!=0) || strcmp(ld.gid, dbd.gid)!=0 || ld.mode!=dbd.mode){ if(notexists(remote)){ addce(local); /* no skip=1 */ break; } if(!ismatch(name)){ skip = prstopped(skip, name); continue; } SET(checkedmatch4); if(resolve1 == 's') goto DoMeta; else if(resolve1 == 'c') break; conflict(name, "metadata locally changed; will not update metadata to %s %s %luo", rd.uid, rd.gid, rd.mode); skip = 1; continue; } if(!ismatch(name)){ skip = prstopped(skip, name); continue; } SET(checkedmatch4); DoMeta: USED(checkedmatch4); assert(ismatch(name)); if(notexists(remote)){ addce(local); /* no skip=1 */ break; } chat("m %q %luo %q %q %lud\n", name, rd.mode, rd.uid, rd.gid, rd.mtime); if(donothing) break; nulldir(&nd); nd.gid = rd.gid; nd.mode = rd.mode; if(douid) nd.uid = rd.uid; if(dirwstat(local, &nd) < 0){ error("dirwstat %q: %r", name); skip = 1; continue; } DoMetaDb: USED(checkedmatch4); assert(ismatch(name)); if(!havedb){ if(havelocal) dbd = ld; else dbd = rd; } if(dbd.mode&DMDIR) dbd.mtime = now; dbd.gid = rd.gid; dbd.mode = rd.mode; if(douid) dbd.uid = rd.uid; insertdb(clientdb, name, &dbd); break; } if(!skip && !donothing){ maxnow = now; maxn = n; } } w = avlwalk(copyerr->avl); while(e = (Entry*)avlnext(w)) error("copying %q: %s\n", e->name, e->d.name); if(timefile) writetimefile(); if(nconf) exits("conflicts"); if(errors) exits("errors"); exits(nil); }
int main(int argc, char **argv) { if (argc < 6) print_usage(argv); char *path = argv[1]; int start = atoi(argv[2]), end = atoi(argv[3]), i, *bkgc; //IplImage *bkg = alignedImageFrom(mkname(path, 1), 8); IplImage *bkg = alignedImageFrom(argv[4], 8); int dim = plane_coeffs[0] + plane_coeffs[1] + plane_coeffs[2]; CvSize bsz = cvGetSize(bkg); IplImage *d8 = alignedImageFrom(argv[5], 8); //IplImage *d8 = alignedImageFrom(mkname(path, 1), 8); int w = bsz.width - 8 + 1, h = bsz.height - 8 + 1, sz = w*h; kd_tree kdt; printf("cd: %s %d %d %s %s\n", path, start, end, argv[4], argv[5]); init_g(bkg); memset(&kdt, 0, sizeof(kd_tree)); /* IplImage *b32 = cvCreateImage(bsz, IPL_DEPTH_32F, bkg->nChannels); IplImage *i32 = cvCreateImage(bsz, IPL_DEPTH_32F, bkg->nChannels); IplImage *d32 = cvCreateImage(bsz, IPL_DEPTH_32F, bkg->nChannels); IplImage *diff= cvCreateImage(bsz, IPL_DEPTH_32F, bkg->nChannels); cvXor(b32, b32, b32, NULL); cvXor(d32, d32, d32, NULL); cvConvertScale(bkg, b32, 1/255.0, 0); for (i = 1; i < start; i++) { IplImage *img = alignedImageFrom(mkname(path, i), 8); cvConvertScale(img, i32, 1/256.0, 0); cvAbsDiff(i32, b32, diff); cvRunningAvg(diff, d32, 1.0/start, NULL); cvRunningAvg(i32, b32, 1.0/start, NULL); cvReleaseImage(&img); cvShowImage("avg diff", d32); cvWaitKey(1); printf("i: %d\r", i); } cvConvertScale(b32, bkg, 255, 0); cvReleaseImage(&b32); cvReleaseImage(&i32); if (argc >= 6) { cvSaveImage(argv[4], bkg, 0); cvConvertScale(d32, d8, 255, 0); cvSaveImage(argv[5], d8, 0); // difference image return 0; } */ int *imgc = block_coeffs(d8, plane_coeffs); IplImage *rev = splat(imgc, bsz, plane_coeffs); free(imgc); cvReleaseImage(&rev); prop_coeffs(bkg, plane_coeffs, &bkgc); kdt_new(&kdt, bkgc, sz, dim); /*thread_ctx ctxs[3]; pthread_t thrs[sizeof(ctxs)/sizeof(thread_ctx)]; for (i = 0; i < (int)(sizeof(ctxs)/sizeof(thread_ctx)); i++) { thread_ctx *ctx = &ctxs[i]; ctx->start = i+1; ctx->end = end; ctx->nb = sizeof(ctxs)/sizeof(thread_ctx); ctx->path = path; ctx->outfile = argc >= 7 ? argv[6] : NULL; ctx->bkg = bkg; ctx->diff = d8; ctx->kdt = &kdt; pthread_create(&thrs[i], NULL, run_thr, ctx); } for (i = 0; i < (int)(sizeof(ctxs)/sizeof(thread_ctx)); i++) { pthread_join(thrs[i], NULL); } printf("all done!\n");*/ double t; char outname[1024]; memset(outname, '\0', sizeof(outname)); for (i = start; i <= end; i++) { IplImage *img = alignedImageFrom(mkname(path, i), 8); double start = get_time(); if (argc >= 7) snprintf(outname, sizeof(outname), "%s/bin%06d.png", argv[6], i); //process(&kdt, bkg, d8, img, outname); //test(img); cvShowImage("image", img); t += (get_time() - start); if ((cvWaitKey(1)&255)==27)break; // esc cvReleaseImage(&img); } //free_g(); kdt_free(&kdt); free(bkgc); cvReleaseImage(&bkg); cvReleaseImage(&d8); return 0; }
static const char * skill_key(int sk) { assert(sk < MAXPARAMS && sk >= 0); return skill_disabled[sk] ? 0 : mkname("skill", skillnames[sk]); }
const char *keyword_name(keyword_t kwd, const struct locale *lang) { return LOC(lang, mkname("keyword", keywords[kwd])); }
const char *skillname(skill_t sk, const struct locale *lang) { if (skill_disabled[sk]) return 0; return LOC(lang, mkname("skill", skillnames[sk])); }