Beispiel #1
0
edict_t *
PlayerTrail_PickFirst(edict_t *self)
{
	int marker;
	int n;

	if (!self)
	{
		return NULL;
	}

	if (!trail_active)
	{
		return NULL;
	}

	for (marker = trail_head, n = TRAIL_LENGTH; n; n--)
	{
		if (trail[marker]->timestamp <= self->monsterinfo.trail_time)
		{
			marker = NEXT(marker);
		}
		else
		{
			break;
		}
	}

	if (visible(self, trail[marker]))
	{
		return trail[marker];
	}

	if (visible(self, trail[PREV(marker)]))
	{
		return trail[PREV(marker)];
	}

	return trail[marker];
}
Beispiel #2
0
static void screen_read_close(void)
{
	unsigned i, j;
	int vcsa_fd;
	char *data;

	// Close & re-open vcsa in case they have swapped virtual consoles
	vcsa_fd = xopen(G.vcsa_name, O_RDONLY);
	xread(vcsa_fd, &G.remote, 4);
	i = G.remote.cols * 2;
	G.first_line_offset = G.y * i;
	i *= G.remote.lines;
	if (G.data == NULL) {
		G.size = i;
		G.data = xzalloc(2 * i);
	}
	if (G.size != i) {
		cleanup(EXIT_FAILURE);
	}
	data = G.data + G.current;
	xread(vcsa_fd, data, G.size);
	close(vcsa_fd);
	for (i = 0; i < G.remote.lines; i++) {
		for (j = 0; j < G.remote.cols; j++, NEXT(data)) {
			unsigned x = j - G.x; // if will catch j < G.x too
			unsigned y = i - G.y; // if will catch i < G.y too

			if (y >= G.height || x >= G.width)
				DATA(data) = 0;
			else {
				uint8_t ch = CHAR(data);
				if (ch < ' ')
					CHAR(data) = ch | 0x40;
				else if (ch > 0x7e)
					CHAR(data) = '?';
			}
		}
	}
}
Beispiel #3
0
/**
 * bigobject_rfc3986_segment:
 * @str:  the string to analyze
 * @forbid: an optional forbidden character
 * @empty: allow an empty segment
 *
 * Parse a segment and fills in the appropriate fields
 * of the @uri structure
 *
 * segment       = *pchar
 * segment-nz    = 1*pchar
 * segment-nz-nc = 1*( unreserved / pct-encoded / sub-delims / "@" )
 *               ; non-zero-length segment without any colon ":"
 *
 * Returns 0 or the error code
 */
static int
bigobject_rfc3986_segment(const char **str, char forbid, int empty)
{
        const char *cur = NULL;
        int ret         = 0;

        if (str == NULL) {
                ret = -1;
                goto out;
        }
        cur = *str;
        if (!ISA_PCHAR(cur)) {
                if (!empty)
                        ret = 1;
                goto out;
        }
        while (ISA_PCHAR(cur) && (*cur != forbid))
                NEXT(cur);
        *str = cur;
out:
        return ret;
}
Beispiel #4
0
static void
grow_table(isc_symtab_t *symtab) {
	eltlist_t *newtable;
	unsigned int i, newsize, newmax;

	REQUIRE(symtab != NULL);

	newsize = symtab->size * 2;
	newmax = newsize * 3 / 4;
	INSIST(newsize > 0U && newmax > 0U);

	newtable = isc_mem_get(symtab->mctx, newsize * sizeof(eltlist_t));
	if (newtable == NULL)
		return;

	for (i = 0; i < newsize; i++)
		INIT_LIST(newtable[i]);

	for (i = 0; i < symtab->size; i++) {
		elt_t *elt, *nelt;

		for (elt = HEAD(symtab->table[i]); elt != NULL; elt = nelt) {
			unsigned int hv;

			nelt = NEXT(elt, link);

			UNLINK(symtab->table[i], elt, link);
			hv = hash(elt->key, symtab->case_sensitive);
			APPEND(newtable[hv % newsize], elt, link);
		}
	}

	isc_mem_put(symtab->mctx, symtab->table,
		    symtab->size * sizeof(eltlist_t));

	symtab->table = newtable;
	symtab->size = newsize;
	symtab->maxload = newmax;
}
Beispiel #5
0
struct lf_ordlist *lf_ordlist_create(size_t nbrelm,
				     int (*cmp)(void *a, void *b))
{
	struct lf_ordlist *lst;

	lst = calloc(1, sizeof(*lst));
	if (!lst)
		return NULL;
	lst->cmp = cmp;
	lst->nelms = nbrelm + 2;

	lst->fl = mem_freelist_create(lst->nelms, 1,
				      sizeof(struct lf_ordlist_node));
	if (!lst->fl)
		goto err_fl;

	lst->head = mem_new(lst->fl);
	if (!lst->head)
		goto err_head;

	lst->tail = mem_new(lst->fl);
	if (!lst->tail)
		goto err_tail;

	mem_incr_ref(lst->tail);
	NEXT(lst->head) = (struct node *) lst->tail;

	return lst;

err_tail:
	mem_release(lst->fl, lst->head);

err_head:
	mem_freelist_destroy(lst->fl);

err_fl:
	free(lst);
	return NULL;
}
Beispiel #6
0
void  inner_statement_any(OID v2548,OID v1741,OID v332)
{ GC_BIND;
  if (INHERIT(OWNER(v2548),Language._Do))
   { list * v1732 = GC_OBJECT(list,OBJECT(Do,v2548)->args);
    int  v1733 = v1732->length;
    ClaireBoolean * v1722 = Optimize.OPT->alloc_stack;
    int  v1734 = 0;
    (Optimize.OPT->alloc_stack = CFALSE);
    { ITERATE(v1744);
      for (START(v1732); NEXT(v1744);)
      { ++v1734;
        if (v1734 == v1733)
         { (Optimize.OPT->alloc_stack = v1722);
          inner_statement_any(v1744,v1741,v332);
          } 
        else if (boolean_I_any(v1744) == CTRUE)
         inner_statement_any(v1744,_oid_(Kernel.emptySet),v332);
        } 
      } 
    } 
  else statement_any(v2548,v1741,v332);
    GC_UNBIND;} 
Beispiel #7
0
/*>PDB *blDeleteAtomPDB(PDB *pdb, PDB *atom)
   -----------------------------------------
*//**
   \param[in]     *pdb    Start of PDB linked list
   \param[in]     *atom   Atom to delete
   \return                New start of PDB linked list

   Deletes an atom from the PDB linked list. Should be called as 
   pdb=blDeleteAtomPDB(pdb, atom);
   to allow for the first atom in the linked list being deleted.

   Returns NULL of all atoms have been deleted. Returns the input
   pdb linked list unmodified if the atom isn't found.

-  17.03.15  Original   By: ACRM
*/
PDB *blDeleteAtomPDB(PDB *pdb, PDB *atom)
{
   PDB *p, 
       *next,
       *prev=NULL;

   for(p=pdb; p!=NULL; NEXT(p))
   {
      if(p==atom)
      {
         next = blKillPDB(atom, prev);
         /* Killed atom from start of linked list                       */
         if(prev==NULL)
            return(next);
         return(pdb);
      }
      
      prev=p;
   }

   return(pdb);
}
Beispiel #8
0
static unsigned int
dequeue_events(isc_task_t *task, void *sender, isc_eventtype_t first,
	       isc_eventtype_t last, void *tag,
	       isc_eventlist_t *events, isc_boolean_t purging)
{
	isc_event_t *event, *next_event;
	unsigned int count = 0;

	REQUIRE(VALID_TASK(task));
	REQUIRE(last >= first);

	XTRACE("dequeue_events");

	/*
	 * Events matching 'sender', whose type is >= first and <= last, and
	 * whose tag is 'tag' will be dequeued.  If 'purging', matching events
	 * which are marked as unpurgable will not be dequeued.
	 *
	 * sender == NULL means "any sender", and tag == NULL means "any tag".
	 */

	LOCK(&task->lock);

	for (event = HEAD(task->events); event != NULL; event = next_event) {
		next_event = NEXT(event, ev_link);
		if (event->ev_type >= first && event->ev_type <= last &&
		    (sender == NULL || event->ev_sender == sender) &&
		    (tag == NULL || event->ev_tag == tag) &&
		    (!purging || PURGE_OK(event))) {
			DEQUEUE(task->events, event, ev_link);
			ENQUEUE(*events, event, ev_link);
			count++;
		}
	}

	UNLOCK(&task->lock);

	return (count);
}
Beispiel #9
0
int
etherrxflush(int ctlrno)
{
	int n;
	Ether *ctlr;
	RingBuf *ring;

	if((ctlr = attach(ctlrno)) == 0)
		return 0;

	n = 0;
	for(;;){
		ring = &ctlr->rb[ctlr->rh];
		if(wait(ring, Interface, 100) == 0)
			break;

		ring->owner = Interface;
		ctlr->rh = NEXT(ctlr->rh, ctlr->nrb);
		n++;
	}

	return n;
}
/*
 ==================
 SG_ClientTrail_PickFirst
 ==================
*/
edict_t *SG_ClientTrail_PickFirst (edict_t *self){

	int		marker;
	int		i;

	if (!trailActive)
		return NULL;

	for (marker = trailHead, i = TRAIL_LENGTH; i; i--){
		if (trail[marker]->timestamp <= self->monsterinfo.trail_time)
			marker = NEXT(marker);
		else
			break;
	}

	if (SG_IsEntityVisible(self, trail[marker]))
		return trail[marker];

	if (SG_IsEntityVisible(self, trail[PREV(marker)]))
		return trail[PREV(marker)];

	return trail[marker];
}
Beispiel #11
0
INLINE_STATIC block_t *
alloc_new_string (const char * string, int h)
{
    block_t *b;
    int len = strlen(string);
    int size;

    if (len > max_string_length) {
        len = max_string_length;
    }
    size = sizeof(block_t) + len + 1;
    b = (block_t *) DXALLOC(size, TAG_SHARED_STRING, "alloc_new_string");
    strncpy(STRING(b), string, len);
    STRING(b)[len] = '\0';      /* strncpy doesn't put on \0 if 'from' too
                                 * long */
    SIZE(b) = (len > USHRT_MAX ? USHRT_MAX : len);
    REFS(b) = 1;
    NEXT(b) = base_table[h];
    base_table[h] = b;
    ADD_NEW_STRING(SIZE(b), sizeof(block_t));
    ADD_STRING(SIZE(b));
    return (b);
}
Beispiel #12
0
/*
 - p_b_coll_elem - parse a collating-element name and look it up
 */
static char			/* value of collating element */
p_b_coll_elem(struct parse *p,
    int endc)			/* name ended by endc,']' */
{
	char *sp = p->next;
	struct cname *cp;
	int len;

	while (MORE() && !SEETWO(endc, ']'))
		NEXT();
	if (!MORE()) {
		SETERROR(REG_EBRACK);
		return(0);
	}
	len = p->next - sp;
	for (cp = cnames; cp->name != NULL; cp++)
		if (strncmp(cp->name, sp, len) == 0 && cp->name[len] == '\0')
			return(cp->code);	/* known name */
	if (len == 1)
		return(*sp);	/* single character */
	SETERROR(REG_ECOLLATE);			/* neither */
	return(0);
}
Beispiel #13
0
static void
toringbuf(Ether* edev, uint8_t* data, int len)
{
	RingBuf *rb;
	extern int interesting(void*);

	if(!interesting(data))
		return;

	rb = &edev->rb[edev->ri];
	if(rb->owner == Interface){
		if(len > sizeof(rb->pkt))
			len = sizeof(rb->pkt);
		rb->len = len;
		memmove(rb->pkt, data, rb->len);
		rb->owner = Host;
		edev->ri = NEXT(edev->ri, edev->nrb);
	}
	else if(debug){
		print("#l%d: toringbuf: dropping packets @ ri %d\n",
			edev->ctlrno, edev->ri);
	}
}
Beispiel #14
0
static void inline play_buffer(void){
#ifndef THREADED_AUDIO
	// We should wait for the other buffer to finish its DMA transfer first
	while( AUDIO_GetDMABytesLeft() );
	AUDIO_StopDMA();

#else // THREADED_AUDIO
	// Wait for a sample to actually be played to work around a deadlock
	LWP_SemWait(first_audio);
	
	// This thread will keep giving buffers to the audio as they come
	while(thread_running){

	// Wait for a buffer to be processed
	LWP_SemWait(buffer_full);
#endif

	// Make sure the buffer is in RAM, not the cache
	DCFlushRange(buffer[thread_buffer], buffer_size);

	// Actually send the buffer out to be played next
	AUDIO_InitDMA((unsigned int)&buffer[thread_buffer], buffer_size);

#ifdef THREADED_AUDIO
	// Wait for the audio interface to be free before playing
	LWP_SemWait(audio_free);
#endif

	// Start playing the buffer
	AUDIO_StartDMA();

#ifdef THREADED_AUDIO
	// Move the index to the next buffer
	NEXT(thread_buffer);
	}
#endif
}
Beispiel #15
0
/**
 * Promote a block in temp space (or elsewhere for that matter) to old space.
 *
 * @param block to promote.
 */
static void xlat_promote_to_old_space( xlat_cache_block_t block )
{
    int allocation = (int)-sizeof(struct xlat_cache_block);
    int size = block->size;
    xlat_cache_block_t curr = xlat_old_cache_ptr;
    xlat_cache_block_t start_block = curr;
    do {
        allocation += curr->size + sizeof(struct xlat_cache_block);
        curr = NEXT(curr);
        if( allocation > size ) {
            break; /* done */
        }
        if( curr->size == 0 ) { /* End-of-cache Sentinel */
            /* Leave what we just released as free space and start again from the
             * top of the cache
             */
            start_block->active = 0;
            start_block->size = allocation;
            allocation = (int)-sizeof(struct xlat_cache_block);
            start_block = curr = xlat_old_cache;
        }
    } while(1);
    start_block->active = 1;
    start_block->size = allocation;
    start_block->lut_entry = block->lut_entry;
    start_block->chain = block->chain;
    start_block->fpscr_mask = block->fpscr_mask;
    start_block->fpscr = block->fpscr;
    start_block->recover_table_offset = block->recover_table_offset;
    start_block->recover_table_size = block->recover_table_size;
    *block->lut_entry = &start_block->code;
    memcpy( start_block->code, block->code, block->size );
    xlat_old_cache_ptr = xlat_cut_block(start_block, size );
    if( xlat_old_cache_ptr->size == 0 ) {
        xlat_old_cache_ptr = xlat_old_cache;
    }
}
Beispiel #16
0
/*>char *blGetTitleWholePDB(WHOLEPDB *wpdb)
   ----------------------------------------
*//**
   \param[in]    *wpdb    WHOLEPDB structure
   \return                Tit;le from PDB file (malloc()'d)

   Extracts the title from a PDB file malloc()ing a string in which to
   store the data. This must be freed by user code

-  28.04.15 Original   By: ACRM
-  11.05.15 Return NULL if TITLE line absent. By: CTP
-  09.06.15 Add columns 11 to 80 to title string for both start and 
            continuation lines. By: CTP
*/
char *blGetTitleWholePDB(WHOLEPDB *wpdb)
{
   char       *title = NULL,
              *cleanTitle = NULL;
   STRINGLIST *s;
   BOOL       inTitle = FALSE;

   for(s=wpdb->header; s!=NULL; NEXT(s))
   {
      if(!strncmp(s->string, "TITLE ", 6))
      {
         char buffer[MAXPDBANNOTATION];
         strcpy(buffer, s->string);
         TERMINATE(buffer);

         /* append cols 11-80 to title string                           */
         title = blStrcatalloc(title, buffer+10);

         if(title == NULL)
            return(NULL);
      }
      else if(inTitle)
      {
         break;
      }
   }

   /* title line not found                                              */
   if(title == NULL)
      return(NULL);

   cleanTitle = blCollapseSpaces(title);
   free(title);
   KILLTRAILSPACES(cleanTitle);
   
   return(cleanTitle);
}
Beispiel #17
0
static void
txstart(Ether* ether)
{
	Ctlr *ctlr;
	Block *bp;
	Des *des;
	int control;

	ctlr = ether->ctlr;
	while(ctlr->ntq < (ctlr->ntdr-1)){
		if(ctlr->setupbp){
			bp = ctlr->setupbp;
			ctlr->setupbp = 0;
			control = Ic|Set|BLEN(bp);
		}
		else{
			bp = qget(ether->oq);
			if(bp == nil)
				break;
			control = Ic|Lseg|Fseg|BLEN(bp);
		}

		ctlr->tdr[PREV(ctlr->tdrh, ctlr->ntdr)].control &= ~Ic;
		des = &ctlr->tdr[ctlr->tdrh];
		des->bp = bp;
		des->addr = PCIWADDR(bp->rp);
		des->control |= control;
		ctlr->ntq++;
		coherence();
		des->status = Own;
		csr32w(ctlr, 1, 0);
		ctlr->tdrh = NEXT(ctlr->tdrh, ctlr->ntdr);
	}

	if(ctlr->ntq > ctlr->ntqmax)
		ctlr->ntqmax = ctlr->ntq;
}
Beispiel #18
0
/*
 * coalesce - Coalesce adjacent free blocks. Sort the new free block into the
 *            appropriate list.
 */
static void *coalesce(void *ptr)
{
  size_t prev_alloc = GET_ALLOC(HEAD(PREV(ptr)));
  size_t next_alloc = GET_ALLOC(HEAD(NEXT(ptr)));
  size_t size = GET_SIZE(HEAD(ptr));

  /* Return if previous and next blocks are allocated */
  if (prev_alloc && next_alloc) {
    return ptr;
  }

  /* Do not coalesce with previous block if it is tagged */
  if (GET_TAG(HEAD(PREV(ptr))))
    prev_alloc = 1;

  /* Remove old block from list */
  delete_node(ptr);

  /* Detect free blocks and merge, if possible */
  if (prev_alloc && !next_alloc) {
    delete_node(NEXT(ptr));
    size += GET_SIZE(HEAD(NEXT(ptr)));
    PUT(HEAD(ptr), PACK(size, 0));
    PUT(FOOT(ptr), PACK(size, 0));
  } else if (!prev_alloc && next_alloc) {
    delete_node(PREV(ptr));
    size += GET_SIZE(HEAD(PREV(ptr)));
    PUT(FOOT(ptr), PACK(size, 0));
    PUT(HEAD(PREV(ptr)), PACK(size, 0));
    ptr = PREV(ptr);
  } else {
    delete_node(PREV(ptr));
    delete_node(NEXT(ptr));
    size += GET_SIZE(HEAD(PREV(ptr))) + GET_SIZE(HEAD(NEXT(ptr)));
    PUT(HEAD(PREV(ptr)), PACK(size, 0));
    PUT(FOOT(NEXT(ptr)), PACK(size, 0));
    ptr = PREV(ptr);
  }

  /* Adjust segregated linked lists */
  insert_node(ptr, size);

  return ptr;
}
Beispiel #19
0
void *hash_next(void *_hash_table, struct hash_iterator *i)
{
	struct hash_table *t = _hash_table;
	unsigned int index;

	verify_hash_table(t);

restart:
	if(!i->ptr) {
		for(index = (unsigned int)(i->bucket + 1); index < t->table_size; index++) {
			if(t->table[index]) {
				i->bucket = index;
				i->ptr = t->table[index];
				break;
			}
		}
	} else {
		i->ptr = NEXT(t, i->ptr);
		if(!i->ptr)
			goto restart;
	}

	return i->ptr;
}
void			*ft_alg(void *p)
{
    t_env		*e;
    int			i;

    e = (t_env *)p;
    i = e->id;
    while (e->roll != 3)
    {
        never_die(e, i);
        if (!ft_strcmp(e->state[NEXT(i)], THINK) &&
                !ft_strcmp(e->state[PREV(i)], THINK))
            try_both(e, i);
        else if (TRY(&e->lock[FI]) == 0)
            ft_try(e, FI, NI, i);
        else if (TRY(&e->lock[NI]) == 0)
            ft_try(e, NI, FI, i);
        else
            ft_rest(e, i, 0);
    }
    if (pthread_detach(e->th[i]))
        ft_putendl("Error while detaching thread");
    return (p);
}
Beispiel #21
0
void AmeCtrlJobList::OnChar(wxKeyEvent& event){
	//POP(SP1("%d", event.GetKeyCode()));
	if(event.GetKeyCode()<128){
		long item = NEXT(-1);
		if(item>-1){
			AmeJob *j = GET(item);
			AdbFile *f = j->getAdbFile();
			if(f){
				switch(event.GetKeyCode()){
					case 'A': MYEXEC(f->urlAnime()); break;
					case 'M': MYEXEC(f->urlMylist()); break;
					case 'N': MYEXEC(f->urlMylistX()); break;
					case 'E': MYEXEC(f->urlEpisode()); break;
					case 'G': MYEXEC(f->urlGroup()); break;
					case 'F': MYEXEC(f->urlFile()); break;
					case 'K': MYEXEC(f->urlExport()); break;
					case 'C': AVDUMP(j->getAbsolutePath()); MYEXEC(f->urlFile()); break;
				}
			}
			switch(event.GetKeyCode()){
				case 'W': MYEXEC(j->getAbsolutePath()); break;
				case 'X': MYEXPL(j->getFolderPath()); break;
				case 'P': {UPDATE_STATUS(jH_PAUSED);} break;
				case 'S': AmeJobMan::updateStatus(j, jIDENTIFIED); break;
				case 'I':
					j->deleteAdbFile();
					AmeJobMan::updateStatus(j, jHASHED); break;
				case ' ':
				case 13: showInfo(this); break;
				//case 39: if(m_tt!=null) m_tt.expandRow(); break;
				//case 37: if(m_tt!=null) m_tt.collapseRow(); break;
				//default: POP(SP1("%d", event.GetKeyCode()));
			}
		}
	}else event.Skip();
}
Beispiel #22
0
/*>void WriteXYZ(FILE *out, PDB *pdb, int natoms, char *title)
   -----------------------------------------------------------
*//**

   \param[in]      *out      Output file pointer
   \param[in]      *pdb      PDB linked list
   \param[in]      natoms    Number of atoms
   \param[in]      title     Title for XYZ file or blank string

   Write the PDB linked list out in Gromos XYZ format

-  23.08.94 Original    By: ACRM
*/
void WriteXYZ(FILE *out, PDB *pdb, int natoms, char *title)
{
   PDB *p;
   int i = 1;

   if(title[0])
      fprintf(out,"%s\n",title);
   else
      fprintf(out,"Gromos XYZ file generated by PDB2XYZ\n");

   fprintf(out,"%5d\n",natoms);
   
   for(p=pdb; p!=NULL; NEXT(p))
   {
      fprintf(out,"%5d %-4s %-4s %5d%8.3f%8.3f%8.3f\n",
              p->resnum,
              p->resnam,
              p->atnam,
              i++,
              p->x,
              p->y,
              p->z);
   }
}
Beispiel #23
0
int
etherrxpkt(int ctlrno, Etherpkt* pkt, int timo)
{
	int n;
	Ether *ctlr;
	RingBuf *ring;

	if((ctlr = attach(ctlrno)) == 0)
		return 0;

	ring = &ctlr->rb[ctlr->rh];
	if(wait(ring, Interface, timo) == 0){
		if(debug)
			print("ether%d: rx timeout\n", ctlrno);
		return 0;
	}

	n = ring->len;
	memmove(pkt, ring->pkt, n);
	ring->owner = Interface;
	ctlr->rh = NEXT(ctlr->rh, ctlr->nrb);

	return n;
}
Beispiel #24
0
/*
 * extend_heap - Extend the heap with a system call. Insert the newly
 *               requested free block into the appropriate list.
 */
static void *extend_heap(size_t size)
{
  void *ptr;                   /* Pointer to newly allocated memory */
  size_t words = size / WSIZE; /* Size of extension in words */
  size_t asize;                /* Adjusted size */

  /* Allocate an even number of words to maintain alignment */
  asize = (words % 2) ? (words + 1) * WSIZE : words * WSIZE;

  /* Extend the heap */
  if ((long)(ptr = mem_sbrk(asize)) == -1)
    return NULL;

  /* Set headers and footer */
  PUT_NOTAG(HEAD(ptr), PACK(asize, 0));   /* Free block header */
  PUT_NOTAG(FOOT(ptr), PACK(asize, 0));   /* Free block footer */
  PUT_NOTAG(HEAD(NEXT(ptr)), PACK(0, 1)); /* Epilogue header */

  /* Insert new block into appropriate list */
  insert_node(ptr, asize);

  /* Coalesce if the previous block was free */
  return coalesce(ptr);
}
Beispiel #25
0
static void test_next_token2(void)
{
    h2o_iovec_t iter, value;
    const char *name;
    size_t name_len;

#define NEXT()                                                                                                                     \
    if ((name = h2o_next_token(&iter, ',', &name_len, &value)) == NULL) {                                                          \
        ok(0);                                                                                                                     \
        return;                                                                                                                    \
    }

    iter = h2o_iovec_init(H2O_STRLIT("public, max-age=86400, must-revalidate"));
    NEXT();
    ok(h2o_memis(name, name_len, H2O_STRLIT("public")));
    ok(value.base == NULL);
    ok(value.len == 0);
    NEXT();
    ok(h2o_memis(name, name_len, H2O_STRLIT("max-age")));
    ok(h2o_memis(value.base, value.len, H2O_STRLIT("86400")));
    NEXT();
    ok(h2o_memis(name, name_len, H2O_STRLIT("must-revalidate")));
    ok(value.base == NULL);
    ok(value.len == 0);
    name = h2o_next_token(&iter, ',', &name_len, &value);
    ok(name == NULL);

    iter = h2o_iovec_init(H2O_STRLIT("public, max-age = 86400 = c , must-revalidate="));
    NEXT();
    ok(h2o_memis(name, name_len, H2O_STRLIT("public")));
    ok(value.base == NULL);
    ok(value.len == 0);
    NEXT();
    ok(h2o_memis(name, name_len, H2O_STRLIT("max-age")));
    ok(h2o_memis(value.base, value.len, H2O_STRLIT("86400 = c")));
    NEXT();
    ok(h2o_memis(name, name_len, H2O_STRLIT("must-revalidate")));
    name = h2o_next_token(&iter, ',', &name_len, &value);
    ok(h2o_memis(value.base, value.len, H2O_STRLIT("")));

#undef NEXT
}
Beispiel #26
0
Datei: mm.c Projekt: js6450/CSO
static void *coalesce(void *currblock)
{
  size_t prev_alloc = FULL(HEADER(PREV(currblock)));
  size_t next_alloc = FULL(HEADER(NEXT(currblock)));
  size_t size = GETSIZE(HEADER(currblock));
  
  if (prev_alloc && next_alloc) {
    return currblock;
  }
  
  if (RTAG(HEADER(PREV(currblock))))
    prev_alloc = 1;
  
  deletefree(currblock);
  
  if (prev_alloc && !next_alloc) {
    deletefree(NEXT(currblock));
    size += GETSIZE(HEADER(NEXT(currblock)));
    PUT(HEADER(currblock), PACK(size, 0));
    PUT(FOOTER(currblock), PACK(size, 0));
  } else if (!prev_alloc && next_alloc) {
    deletefree(PREV(currblock));
    size += GETSIZE(HEADER(PREV(currblock)));
    PUT(FOOTER(currblock), PACK(size, 0));
    PUT(HEADER(PREV(currblock)), PACK(size, 0));
    currblock = PREV(currblock);
  } else {
    deletefree(PREV(currblock));
    deletefree(NEXT(currblock));
    size += GETSIZE(HEADER(PREV(currblock))) + GETSIZE(HEADER(NEXT(currblock)));
    PUT(HEADER(PREV(currblock)), PACK(size, 0));
    PUT(FOOTER(NEXT(currblock)), PACK(size, 0));
    currblock = PREV(currblock);
  }
  
  insertfree(currblock, size);
  
  return coalesce(currblock);
}
Beispiel #27
0
// Subdivide a mesh
void subdiv(TriMesh *mesh, int scheme /* = SUBDIV_LOOP */)
{
	bool have_col = !mesh->colors.empty();
	bool have_conf = !mesh->confidences.empty();
	mesh->flags.clear();
	mesh->normals.clear();
	mesh->pdir1.clear(); mesh->pdir2.clear();
	mesh->curv1.clear(); mesh->curv2.clear();
	mesh->dcurv.clear();
	mesh->cornerareas.clear(); mesh->pointareas.clear();
	mesh->bbox.valid = false;
	mesh->bsphere.valid = false;
	mesh->need_faces(); mesh->tstrips.clear(); mesh->grid.clear();
	mesh->grid_width = mesh->grid_height = -1;
	mesh->neighbors.clear();
	mesh->need_adjacentfaces();
	mesh->need_across_edge();


	dprintf("Subdividing mesh... ");

	// Introduce new vertices
	int nf = mesh->faces.size();
	vector<TriMesh::Face> newverts(nf, TriMesh::Face(-1,-1,-1));
	int old_nv = mesh->vertices.size();
	mesh->vertices.reserve(4 * old_nv);
	vector<int> newvert_count(old_nv + 3*nf);
	if (have_col)
		mesh->colors.reserve(4 * old_nv);
	if (have_conf)
		mesh->confidences.reserve(4 * old_nv);

	for (int i = 0; i < nf; i++) {
		for (int j = 0; j < 3; j++) {
			if (newverts[i][j] != -1)
				continue;
			int ae = mesh->across_edge[i][j];
			if (ae != -1) {
				if (mesh->across_edge[ae][0] == i)
					newverts[i][j] = newverts[ae][0];
				else if (mesh->across_edge[ae][1] == i)
					newverts[i][j] = newverts[ae][1];
				else if (mesh->across_edge[ae][2] == i)
					newverts[i][j] = newverts[ae][2];
			}
			if (newverts[i][j] != -1)
				continue;

			insert_vert(mesh, scheme, i, j);
			newverts[i][j] = mesh->vertices.size() - 1;
			if (ae != -1) {
				if (mesh->across_edge[ae][0] == i)
					newverts[ae][0] = newverts[i][j];
				else if (mesh->across_edge[ae][1] == i)
					newverts[ae][1] = newverts[i][j];
				else if (mesh->across_edge[ae][2] == i)
					newverts[ae][2] = newverts[i][j];
			}
			const TriMesh::Face &v = mesh->faces[i];
			if (have_col) {
				mesh->colors.push_back(0.5f *
					(mesh->colors[v[NEXT(j)]] +
					 mesh->colors[v[PREV(j)]]));
			}
			if (have_conf)
				mesh->confidences.push_back(0.5f *
					(mesh->confidences[v[NEXT(j)]] +
					 mesh->confidences[v[PREV(j)]]));
		}
	}

	// Update old vertices
	if (scheme == SUBDIV_LOOP ||
	    scheme == SUBDIV_LOOP_ORIG ||
	    scheme == SUBDIV_LOOP_NEW) {

		vector<point> oldvertices = mesh->vertices;
#pragma omp parallel for
		for (int i = 0; i < old_nv; i++) {
			point bdyavg, nbdyavg;
			int nbdy = 0, nnbdy = 0;
			int naf = mesh->adjacentfaces[i].size();
			if (!naf)
				continue;
			for (int j = 0; j < naf; j++) {
				int af = mesh->adjacentfaces[i][j];
				int afi = mesh->faces[af].indexof(i);
				int n1 = NEXT(afi);
				int n2 = PREV(afi);
				if (mesh->across_edge[af][n1] == -1) {
					bdyavg += oldvertices[mesh->faces[af][n2]];
					nbdy++;
				} else {
					nbdyavg += oldvertices[mesh->faces[af][n2]];
					nnbdy++;
				}
				if (mesh->across_edge[af][n2] == -1) {
					bdyavg += oldvertices[mesh->faces[af][n1]];
					nbdy++;
				} else {
					nbdyavg += oldvertices[mesh->faces[af][n1]];
					nnbdy++;
				}
			}

			float alpha;
			point newpt;
			if (nbdy) {
				newpt = bdyavg / (float) nbdy;
				alpha = 0.75f;
			} else if (nnbdy) {
				newpt = nbdyavg / (float) nnbdy;
				alpha = loop_update_alpha(scheme, nnbdy/2);
			} else {
				continue;
			}
			mesh->vertices[i] *= alpha;
			mesh->vertices[i] += (1.0f - alpha) * newpt;
		}
	}

	// Insert new faces
	mesh->adjacentfaces.clear(); mesh->across_edge.clear();
	mesh->faces.reserve(4*nf);
	for (int i = 0; i < nf; i++) {
		TriMesh::Face &v = mesh->faces[i];
		TriMesh::Face &n = newverts[i];
		mesh->faces.push_back(TriMesh::Face(v[0], n[2], n[1]));
		mesh->faces.push_back(TriMesh::Face(v[1], n[0], n[2]));
		mesh->faces.push_back(TriMesh::Face(v[2], n[1], n[0]));
		v = n;
	}

	dprintf("Done.\n");
}
Beispiel #28
0
#include "../headers.h"

LISP_BUILTIN(randint, "") {
    Int lower;
    Int upper;
    ENSURE_NOT_EMPTY(args);
    Value first = NEXT(args);
    if (first.type != INTEGER) {
        return VALUE_ERROR;
    }
    if (args.type == CONS) {
        Value second = NEXT(args);
        if (second.type != INTEGER) {
            return VALUE_ERROR;
        }
        lower = first.val.integer_val;
        upper = second.val.integer_val;
    } else {
        lower = 0;
        upper = first.val.integer_val;
    }
    ENSURE_EMPTY(args);
    ENSURE(lower < upper);
    return VALUE_INTEGER(random_int(lower, upper));
}

LISP_BUILTIN(choice, "") {
    ENSURE_NOT_EMPTY(args);
    Value choices;
    if (CDR(args).type == NIL) {
        choices = CAR(args);
Beispiel #29
0
/*
 - p_simp_re - parse a simple RE, an atom possibly followed by a repetition
 */
static int			/* was the simple RE an unbackslashed $? */
p_simp_re(struct parse *p,
    int starordinary)		/* is a leading * an ordinary character? */
{
	int c;
	int count;
	int count2;
	sopno pos;
	int i;
	sopno subno;
#	define	BACKSL	(1<<CHAR_BIT)

	pos = HERE();		/* repetion op, if any, covers from here */

	assert(MORE());		/* caller should have ensured this */
	c = GETNEXT();
	if (c == '\\') {
		REQUIRE(MORE(), REG_EESCAPE);
		c = BACKSL | GETNEXT();
	}
	switch (c) {
	case '.':
		if (p->g->cflags&REG_NEWLINE)
			nonnewline(p);
		else
			EMIT(OANY, 0);
		break;
	case '[':
		p_bracket(p);
		break;
	case BACKSL|'{':
		SETERROR(REG_BADRPT);
		break;
	case BACKSL|'(':
		p->g->nsub++;
		subno = p->g->nsub;
		if (subno < NPAREN)
			p->pbegin[subno] = HERE();
		EMIT(OLPAREN, subno);
		/* the MORE here is an error heuristic */
		if (MORE() && !SEETWO('\\', ')'))
			p_bre(p, '\\', ')');
		if (subno < NPAREN) {
			p->pend[subno] = HERE();
			assert(p->pend[subno] != 0);
		}
		EMIT(ORPAREN, subno);
		REQUIRE(EATTWO('\\', ')'), REG_EPAREN);
		break;
	case BACKSL|')':	/* should not get here -- must be user */
	case BACKSL|'}':
		SETERROR(REG_EPAREN);
		break;
	case BACKSL|'1':
	case BACKSL|'2':
	case BACKSL|'3':
	case BACKSL|'4':
	case BACKSL|'5':
	case BACKSL|'6':
	case BACKSL|'7':
	case BACKSL|'8':
	case BACKSL|'9':
		i = (c&~BACKSL) - '0';
		assert(i < NPAREN);
		if (p->pend[i] != 0) {
			assert(i <= p->g->nsub);
			EMIT(OBACK_, i);
			assert(p->pbegin[i] != 0);
			assert(OP(p->strip[p->pbegin[i]]) == OLPAREN);
			assert(OP(p->strip[p->pend[i]]) == ORPAREN);
			(void) dupl(p, p->pbegin[i]+1, p->pend[i]);
			EMIT(O_BACK, i);
		} else
			SETERROR(REG_ESUBREG);
		p->g->backrefs = 1;
		break;
	case '*':
		REQUIRE(starordinary, REG_BADRPT);
		/* FALLTHROUGH */
	default:
		ordinary(p, (char)c);
		break;
	}

	if (EAT('*')) {		/* implemented as +? */
		/* this case does not require the (y|) trick, noKLUDGE */
		INSERT(OPLUS_, pos);
		ASTERN(O_PLUS, pos);
		INSERT(OQUEST_, pos);
		ASTERN(O_QUEST, pos);
	} else if (EATTWO('\\', '{')) {
		count = p_count(p);
		if (EAT(',')) {
			if (MORE() && isdigit((uch)PEEK())) {
				count2 = p_count(p);
				REQUIRE(count <= count2, REG_BADBR);
			} else		/* single number with comma */
				count2 = INFINITY;
		} else		/* just a single number */
			count2 = count;
		repeat(p, pos, count, count2);
		if (!EATTWO('\\', '}')) {	/* error heuristics */
			while (MORE() && !SEETWO('\\', '}'))
				NEXT();
			REQUIRE(MORE(), REG_EBRACE);
			SETERROR(REG_BADBR);
		}
	} else if (c == '$')	/* $ (but not \$) ends it */
		return(1);

	return(0);
}
Beispiel #30
0
/*
 - p_ere_exp - parse one subERE, an atom possibly followed by a repetition op
 */
static void
p_ere_exp(struct parse *p)
{
	char c;
	sopno pos;
	int count;
	int count2;
	sopno subno;
	int wascaret = 0;

	assert(MORE());		/* caller should have ensured this */
	c = GETNEXT();

	pos = HERE();
	switch (c) {
	case '(':
		REQUIRE(MORE(), REG_EPAREN);
		p->g->nsub++;
		subno = p->g->nsub;
		if (subno < NPAREN)
			p->pbegin[subno] = HERE();
		EMIT(OLPAREN, subno);
		if (!SEE(')'))
			p_ere(p, ')');
		if (subno < NPAREN) {
			p->pend[subno] = HERE();
			assert(p->pend[subno] != 0);
		}
		EMIT(ORPAREN, subno);
		MUSTEAT(')', REG_EPAREN);
		break;
#ifndef POSIX_MISTAKE
	case ')':		/* happens only if no current unmatched ( */
		/*
		 * You may ask, why the ifndef?  Because I didn't notice
		 * this until slightly too late for 1003.2, and none of the
		 * other 1003.2 regular-expression reviewers noticed it at
		 * all.  So an unmatched ) is legal POSIX, at least until
		 * we can get it fixed.
		 */
		SETERROR(REG_EPAREN);
		break;
#endif
	case '^':
		EMIT(OBOL, 0);
		p->g->iflags |= USEBOL;
		p->g->nbol++;
		wascaret = 1;
		break;
	case '$':
		EMIT(OEOL, 0);
		p->g->iflags |= USEEOL;
		p->g->neol++;
		break;
	case '|':
		SETERROR(REG_EMPTY);
		break;
	case '*':
	case '+':
	case '?':
		SETERROR(REG_BADRPT);
		break;
	case '.':
		if (p->g->cflags&REG_NEWLINE)
			nonnewline(p);
		else
			EMIT(OANY, 0);
		break;
	case '[':
		p_bracket(p);
		break;
	case '\\':
		REQUIRE(MORE(), REG_EESCAPE);
		c = GETNEXT();
		ordinary(p, c);
		break;
	case '{':		/* okay as ordinary except if digit follows */
		REQUIRE(!MORE() || !isdigit((uch)PEEK()), REG_BADRPT);
		/* FALLTHROUGH */
	default:
		ordinary(p, c);
		break;
	}

	if (!MORE())
		return;
	c = PEEK();
	/* we call { a repetition if followed by a digit */
	if (!( c == '*' || c == '+' || c == '?' ||
				(c == '{' && MORE2() && isdigit((uch)PEEK2())) ))
		return;		/* no repetition, we're done */
	NEXT();

	REQUIRE(!wascaret, REG_BADRPT);
	switch (c) {
	case '*':	/* implemented as +? */
		/* this case does not require the (y|) trick, noKLUDGE */
		INSERT(OPLUS_, pos);
		ASTERN(O_PLUS, pos);
		INSERT(OQUEST_, pos);
		ASTERN(O_QUEST, pos);
		break;
	case '+':
		INSERT(OPLUS_, pos);
		ASTERN(O_PLUS, pos);
		break;
	case '?':
		/* KLUDGE: emit y? as (y|) until subtle bug gets fixed */
		INSERT(OCH_, pos);		/* offset slightly wrong */
		ASTERN(OOR1, pos);		/* this one's right */
		AHEAD(pos);			/* fix the OCH_ */
		EMIT(OOR2, 0);			/* offset very wrong... */
		AHEAD(THERE());			/* ...so fix it */
		ASTERN(O_CH, THERETHERE());
		break;
	case '{':
		count = p_count(p);
		if (EAT(',')) {
			if (isdigit((uch)PEEK())) {
				count2 = p_count(p);
				REQUIRE(count <= count2, REG_BADBR);
			} else		/* single number with comma */
				count2 = INFINITY;
		} else		/* just a single number */
			count2 = count;
		repeat(p, pos, count, count2);
		if (!EAT('}')) {	/* error heuristics */
			while (MORE() && PEEK() != '}')
				NEXT();
			REQUIRE(MORE(), REG_EBRACE);
			SETERROR(REG_BADBR);
		}
		break;
	}

	if (!MORE())
		return;
	c = PEEK();
	if (!( c == '*' || c == '+' || c == '?' ||
				(c == '{' && MORE2() && isdigit((uch)PEEK2())) ) )
		return;
	SETERROR(REG_BADRPT);
}