void sortname(File *f) { int i, cmp, w; int dupwarned; w = whichmenu(f); dupwarned = FALSE; dellist(&file, w); if(f == cmd) i = 0; else{ for(i=0; i<file.nused; i++){ cmp = Strcmp(&f->name, &file.filepptr[i]->name); if(cmp==0 && !dupwarned){ dupwarned = TRUE; warn_S(Wdupname, &f->name); }else if(cmp<0 && (i>0 || cmd==0)) break; } } inslist(&file, i, f); if(downloaded) outTsS(Hmovname, f->tag, &f->name); }
void aa_recommendhi(aa_linkedlist ** l, __AA_CONST char *name) { aa_linkedlist *m = (aa_linkedlist *) malloc(sizeof(*m)), *o = aa_find(*l, name); if (o != NULL) remove(*l, o); m->text = strdup(name); inslist(*l, m); }
Cmd * newcmd(void){ Cmd *p; p = emalloc(sizeof(Cmd)); inslist(&cmdlist, cmdlist.nused, p); return p; }
void bkfree(Disc *d, int n) { Discdesc *dd = d->desc; inslist(&dd->free, dd->free.nused, d->block.blkptr[n].bnum); dellist(&d->block, n); }
Addr* newaddr(void) { Addr *p; p = emalloc(sizeof(Addr)); inslist(&addrlist, addrlist.nused, p); return p; }
String* newstring(int n) { String *p; p = allocstring(n); inslist(&stringlist, stringlist.nused, p); return p; }
String* newstring(void) { String *p; p = emalloc(sizeof(String)); inslist(&stringlist, stringlist.nused, p); Strinit(p); return p; }
String* newre(void) { String *p; p = emalloc(sizeof(String)); inslist(&relist, relist.nused, p); Strinit(p); return p; }
File * newfile(void) { File *f; f = fileopen(); inslist(&file, 0, f); f->tag = tag++; if(downloaded) outTs(Hnewname, f->tag); /* already sorted; file name is "" */ return f; }
void bkalloc(Disc *d, int n) { Discdesc *dd = d->desc; ulong bnum; if(dd->free.nused) bnum = dd->free.longptr[--dd->free.nused]; else bnum = dd->nbk++; if(bnum >= 1<<(8*(sizeof(((Block*)0)->bnum)))) error(Etmpovfl); inslist(&d->block, n, 0L); d->block.blkptr[n].bnum = bnum; }
static void add2slist( /* add source list to ray's */ RAY *r, int *sl ) { static int slspare[MAXSLIST+1]; /* in case of emergence */ int i; if (sl == NULL || sl[0] == 0) /* nothing to add */ return; if (r->slights == NULL) (r->slights = slspare)[0] = 0; /* just once per ray path */ for (i = sl[0]; i > 0; i--) if (!inslist(r->slights, sl[i])) { if (r->slights[0] >= MAXSLIST) error(INTERNAL, "scattering source list overflow"); r->slights[++r->slights[0]] = sl[i]; } }
int m_mist( /* process a ray entering or leaving some mist */ OBJREC *m, RAY *r ) { RAY p; int *myslist = NULL; int newslist[MAXSLIST+1]; COLOR mext; double re, ge, be; int i, j; /* check arguments */ if (m->oargs.nfargs > 7) objerror(m, USER, "bad arguments"); /* get source indices */ if (m->oargs.nsargs > 0 && (myslist = (int *)m->os) == NULL) { if (m->oargs.nsargs > MAXSLIST) objerror(m, INTERNAL, "too many sources in list"); myslist = (int *)malloc((m->oargs.nsargs+1)*sizeof(int)); if (myslist == NULL) goto memerr; myslist[0] = 0; /* size is first in list */ for (j = 0; j < m->oargs.nsargs; j++) { i = nsources; /* look up each source id */ while (i--) if (srcmatch(source+i, m->oargs.sarg[j])) break; if (i < 0) { sprintf(errmsg, "unknown source \"%s\"", m->oargs.sarg[j]); objerror(m, WARNING, errmsg); } else if (inslist(myslist, i)) { sprintf(errmsg, "duplicate source \"%s\"", m->oargs.sarg[j]); objerror(m, WARNING, errmsg); } else myslist[++myslist[0]] = i; } m->os = (char *)myslist; } if (m->oargs.nfargs > 2) { /* compute extinction */ setcolor(mext, m->oargs.farg[0], m->oargs.farg[1], m->oargs.farg[2]); raytexture(r, m->omod); /* get modifiers */ multcolor(mext, r->pcol); } else setcolor(mext, 0., 0., 0.); /* start transmitted ray */ if (rayorigin(&p, TRANS, r, NULL) < 0) return(1); VCOPY(p.rdir, r->rdir); p.slights = newslist; if (r->slights != NULL) /* copy old list if one */ for (j = r->slights[0]; j >= 0; j--) p.slights[j] = r->slights[j]; else p.slights[0] = 0; if (r->rod > 0.) { /* entering ray */ addcolor(p.cext, mext); if (m->oargs.nfargs > 5) setcolor(p.albedo, m->oargs.farg[3], m->oargs.farg[4], m->oargs.farg[5]); if (m->oargs.nfargs > 6) p.gecc = m->oargs.farg[6]; add2slist(&p, myslist); /* add to list */ } else { /* leaving ray */ if (myslist != NULL) { /* delete from list */ for (j = myslist[0]; j > 0; j--) if ( (i = inslist(p.slights, myslist[j])) ) p.slights[i] = -1; for (i = 0, j = 1; j <= p.slights[0]; j++) if (p.slights[j] != -1) p.slights[++i] = p.slights[j]; if (p.slights[0] - i < myslist[0]) { /* fix old */ addcolor(r->cext, mext); if (m->oargs.nfargs > 5) setcolor(r->albedo, m->oargs.farg[3], m->oargs.farg[4], m->oargs.farg[5]); if (m->oargs.nfargs > 6) r->gecc = m->oargs.farg[6]; add2slist(r, myslist); } p.slights[0] = i; } if ((re = colval(r->cext,RED) - colval(mext,RED)) < colval(cextinction,RED)) re = colval(cextinction,RED); if ((ge = colval(r->cext,GRN) - colval(mext,GRN)) < colval(cextinction,GRN)) ge = colval(cextinction,GRN); if ((be = colval(r->cext,BLU) - colval(mext,BLU)) < colval(cextinction,BLU)) be = colval(cextinction,BLU); setcolor(p.cext, re, ge, be); if (m->oargs.nfargs > 5) copycolor(p.albedo, salbedo); if (m->oargs.nfargs > 6) p.gecc = seccg; } rayvalue(&p); /* calls rayparticipate() */ copycolor(r->rcol, p.rcol); /* return value */ r->rt = r->rot + p.rt; return(1); memerr: error(SYSTEM, "out of memory in m_mist"); return 0; /* pro forma return */ }