Ejemplo n.º 1
0
int
unset_source(dbref player, dbref loc, dbref action)
{

    dbref oldsrc;

    if ((oldsrc = DBFETCH(action)->location) == NOTHING) {
        /* old-style, sourceless exit */
        if (!member(action, DBFETCH(loc)->exits)) {
            return 0;
        }
        DBSTORE(DBFETCH(player)->location, exits,
                remove_first(DBFETCH(DBFETCH(player)->location)->exits,
                             action));
    } else {
        switch (Typeof(oldsrc)) {
            case TYPE_PLAYER:
            case TYPE_ROOM:
            case TYPE_THING:
                DBSTORE(oldsrc, exits,
                        remove_first(DBFETCH(oldsrc)->exits, action));
                break;
            default:
                log_status("PANIC: source of action #%d was type: %d.\n",
                           action, Typeof(oldsrc));
                return 0;
                /* NOTREACHED */
                break;
        }
    }
    return 1;
}
Ejemplo n.º 2
0
Archivo: pb.c Proyecto: juliannieb/UVa
int main () {
	int t;

	while (scanf("%i%*c", &t) != EOF) {
		while (t) {

			struct list pila;

			pila.head = NULL;
			pila.size = 0;

			char str[128];
			gets(str);

			int len = strlen(str);
			int i;
			char p;
			int flag = 1;

			for (i = 0; i < len; i ++) {
				p = str[i];

				if (is_empty(&pila) && (p == ')' || p == ']')) {
					flag = 0;
					printf("No\n");
					break;
				}else if (p == '(' || p == '[') {
					add_first(&pila, p);
				}else if (p == ')') {
					if (get_first(&pila) == '(') remove_first(&pila);
					else {
						flag = 0;
						printf("No\n");
						break;
					}
				}else if (p == ']') {
					if (get_first(&pila) == '[') remove_first(&pila);
					else {
						flag = 0;
						printf("No\n");
						break;
					}
				}
			}

			if (flag) {
				if (is_empty(&pila)) {
					printf("Yes\n");
				}else {
					printf("No\n");
				}
			}
			t--;
		}
	}
	return 0;
}
Ejemplo n.º 3
0
     if arr1[0] < arr2[0]:
         print '1' // for debugging
         result.append(arr1[0])
         arr1.remove_first()
     else:
         print '2' // for debugging
         result.append(arr2[0])
         arr2.remove_first()
         
 result.append(arr1)
 result.append(arr2)
 return result
Ejemplo n.º 4
0
Archivo: boards.c Proyecto: Lopo/Lotos
/*** Show list of people board posts are from without seeing the whole lot ***/
void board_from(UR_OBJECT user)
{
    FILE *fp;
    int cnt;
    char id[ARR_SIZE],line[ARR_SIZE],fname[FNAME_LEN],rmname[ROOM_NAME_LEN+1];
    RM_OBJECT rm;

    set_crash();
    if (word_count<2) rm=user->room;
    else {
        if ((rm=get_room(word[1]))==NULL) {
            write_user(user,nosuchroom);
            return;
        }
        if (!has_room_access(user,rm)) {
            write_user(user,"That room is currently private, you cannot read the board.\n");
            return;
        }
    }
    if (!rm->mesg_cnt) {
        write_user(user,"That room has no messages on it's board.\n");
        return;
    }
    if (rm->access==PERSONAL_LOCKED || rm->access==PERSONAL_UNLOCKED) {
        midcpy(rm->name,rmname,1,strlen(rm->name)-2);
        rmname[0]=toupper(rmname[0]);
        sprintf(fname,"%s/%s.B", USERROOMS, rmname);
    }
    else sprintf(fname,"%s/%s.B", ROOMFILES, rm->name);
    if (!(fp=fopen(fname,"r"))) {
        write_user(user,"There was an error trying to read message board.\n");
        write_syslog(ERRLOG,1,"Unable to open message board for %s in board_from().\n",rm->name);
        return;
    }
    vwrite_user(user,"\n~FG~BB*** Posts on the %s message board from ***\n\n",rm->name);
    cnt=0;
    line[0]='\0';
    fgets(line,ARR_SIZE-1,fp);
    while (!feof(fp)) {
        sscanf(line,"%s",id);
        if (!strcmp(id,"PT:")) {
            cnt++;
            vwrite_user(user,"~FT%2d)~RS %s", cnt, remove_first(remove_first(remove_first(line))));
        }
        line[0]='\0';
        fgets(line,ARR_SIZE-1,fp);
    }
    fclose(fp);
    vwrite_user(user,"\nTotal of ~OL%d~RS messages.\n\n", rm->mesg_cnt);
}
Ejemplo n.º 5
0
static void
write_dsi_header_cb (GObject *object, GAsyncResult *res, gpointer user_data)
{
  GOutputStream *output = G_OUTPUT_STREAM (object);
  GVfsAfpConnection *afp_conn = G_VFS_AFP_CONNECTION (user_data);
  GVfsAfpConnectionPrivate *priv = afp_conn->priv;
  
  RequestData *req_data;

  char *data;
  gsize size;

  req_data = g_queue_peek_head (priv->request_queue);
  
  HANDLE_RES ();

  if (req_data->type == REQUEST_TYPE_TICKLE)
  {
    remove_first (priv->request_queue);
    send_request (afp_conn);
    return;
  }

  data = g_vfs_afp_command_get_data (req_data->command);
  size = g_vfs_afp_command_get_size (req_data->command);

  write_all_async (output, data, size, 0, NULL, write_command_cb, afp_conn);
}
Ejemplo n.º 6
0
/** Removes the first edge e = (s,s') with s' in passed from the linked list associated to s in succ_to_visit if there is one, the first edge of the list otherwise
 	Returns that edge
 	Note that t belongs to P_O
 	Note that the successors list is supposed to be non empty (a test must be done before) */
static safety_game_edge*
get_first_successor_passed_non_losing(tuple *t, GHashTable *succ_to_visit, GHashTable *passed, antichain *losing_PO, antichain *losing_PI) {
	hash_table_key* key = new_hash_table_key(t, -1);

	// Try to retrieve the successors to visit list from succ_to_visit
	GList *succ_list = g_hash_table_lookup(succ_to_visit, key);
	safety_game_edge* first_succ_passed;
	GList *curlink = succ_list;
	char found = FALSE;
	int i=0;
	while(curlink != NULL) {
		if(is_passed(((safety_game_edge*)curlink->data)->to, passed) == TRUE && is_losing(((safety_game_edge*)curlink->data)->to, losing_PO, losing_PI) == FALSE) { // is passed?
			first_succ_passed = curlink->data;
			succ_list = g_list_delete_link(succ_list, curlink);
			g_hash_table_insert(succ_to_visit, (gconstpointer*)key, (gconstpointer*)succ_list);
			found = TRUE;
			break;
		}
		i++;
		curlink = curlink->next;
	}
	if(found == FALSE) { // no succ passed?
		first_succ_passed = succ_list->data;
		succ_list = remove_first(succ_list);
		g_hash_table_insert(succ_to_visit, (gconstpointer*)key, (gconstpointer*)succ_list);
	}

	return first_succ_passed;
}
Ejemplo n.º 7
0
Archivo: boards.c Proyecto: Lopo/Lotos
/*** Show list of people suggestions are from without seeing the whole lot ***/
void suggestions_from(UR_OBJECT user)
{
    FILE *fp;
    int cnt;
    char id[ARR_SIZE],line[ARR_SIZE], *str;

    set_crash();
    if (!amsys->suggestion_count) {
        write_user(user,"There are currently no suggestions.\n");
        return;
    }
    if (!(fp=fopen(SUGBOARD, "r"))) {
        write_user(user,"There was an error trying to read the suggestion board.\n");
        write_syslog(ERRLOG,1,"Unable to open suggestion board in suggestions_from().\n");
        return;
    }
    write_user(user,"\n~BB*** Suggestions on the suggestions board from ***\n\n");
    cnt=0;
    line[0]='\0';
    fgets(line,ARR_SIZE-1,fp);
    while (!feof(fp)) {
        sscanf(line,"%s",id);
        str=colour_com_strip(id);
        if (!strcmp(str,"From:")) {
            cnt++;
            vwrite_user(user,"~FT%2d)~RS %s",cnt,remove_first(line));
        }
        line[0]='\0';
        fgets(line,ARR_SIZE-1,fp);
    }
    fclose(fp);
    vwrite_user(user,"\nTotal of ~OL%d~RS suggestions.\n\n",amsys->suggestion_count);
}
Ejemplo n.º 8
0
Archivo: pipe.c Proyecto: orafce/orafce
static message_buffer*
get_from_pipe(text *pipe_name, bool *found)
{
	pipe *p;
	bool created;
	message_buffer *shm_msg;
	message_buffer *result = NULL;

	if (!ora_lock_shmem(SHMEMMSGSZ, MAX_PIPES, MAX_EVENTS, MAX_LOCKS, false))
		return NULL;

	if (NULL != (p = find_pipe(pipe_name, &created,false)))
	{
		if (!created)
		{
			if (NULL != (shm_msg = remove_first(p, found)))
			{
				p->size -= shm_msg->size;

				result = (message_buffer*) MemoryContextAlloc(TopMemoryContext, shm_msg->size);
				memcpy(result, shm_msg, shm_msg->size);
				ora_sfree(shm_msg);
			}
		}
	}

	LWLockRelease(shmem_lockid);

	return result;
}
Ejemplo n.º 9
0
void* malloc(size_t size)
{
	block_t* block;

	if(size <= 0)
		return NULL;
	
	unsigned char index;
	size = adjust_size(size, &index);

	if(index > K_VALUE)
		return NULL;

	if(!global_memory){ /*first time*/
		global_memory =	sbrk(1<<K_VALUE);

		if(global_memory == (void*)-1)
			return NULL;
		
		block =	global_memory;
		block->reserved = 0;
		block->kval	= K_VALUE;
		block->succ = NULL;
		block->pred = NULL;

		free_list[K_VALUE] = block;	
	}	

	block = reserve_first(index);
	if(block)
		return (block + 1);

	unsigned char new_index = index;

	while(!free_list[new_index] ){
		++new_index;
		if(new_index > K_VALUE)
			return NULL;
	}

	while(new_index > index){
		block = remove_first(new_index);

		block->reserved = 0;
		block->succ = NULL;
		block->pred = NULL;

		block_t* new_block = split_block(block);

		--new_index;
		
		block->succ = new_block;
		new_block->pred = block;

		free_list[new_index] = block;
	}
	block = reserve_first(index);
	return (block+1);
}
Ejemplo n.º 10
0
/* Mmmm...this function looks a lot like SquirT's host function. Thanks SquirT! */
static const char *
get_proc(const char *site)
{
  FILE *pp;
  static char str[256], temp[256];
  char temp2[5][256];
  int i;

  sprintf(str, "%s %s", HOSTBIN, site);
#ifdef DEBUG
  printf("[PROC] Getting: %s\n", str);
#endif
  pp = popen(str, "r");
  if (!pp) {
#ifdef DEBUG
    printf("[PROC] Not opened: %s\n", str);
#endif
    return site;
  }
  *str = '\0';
  *temp = '\0';
  for (i = 0; i < 5; ++i) {
    *temp2[i] = '\0';
  }
  fgets(str, 255, pp);
  pclose(pp);
#ifdef DEBUG
  printf("[PROC] Determined: %s\n", str);
#endif
  if (strstr(str, "Host not found")) {
#ifdef DEBUG
    printf("[PROC] Host not found\n");
#endif
    return site;
  }
  if (strstr(str, "domain name pointer")) {
#ifdef DEBUG
    printf("[PROC] Domain name pointer\n");
#endif
    return site;
  }
#if !!0
  sscanf(str, "%s %s %s %s %s", temp2[0], temp2[1], temp2[2], temp2[3],
         temp2[4]);
  strcpy(temp, temp2[1]);
#endif
#ifdef DEBUG
  printf("[PROC] str = %s\n", str);
#endif
  sscanf(str, "%s %s %s %s %s", temp2[0], temp2[1], temp2[2],
         temp2[3], temp2[4]);
  if (!strcasecmp("Name:", temp2[0])) {
    strcpy(temp, remove_first(str));
  } else {
    strcpy(temp, site);
  }
  return temp;
}
Ejemplo n.º 11
0
block_t* reserve_first(char index)
{
	if(free_list[index]){
		block_t* block = remove_first(index);
		block->reserved = 1;
		return block;
	}
	return NULL;
}
Ejemplo n.º 12
0
/* OPT NOTE: this function starts from root each time it searchs for the item
             to be removed. Much of the tree changes with removal, therefore
             this may be a required lag as appose to doing it in 1 search. 
             More analysis is required for me to be 100% certin */
uint32_t remove_each(cardDeck_s *tree, const int32_t pin)/*#{{{*/
{   
    uint32_t removals = 0;
    
    /* while something gets removed, removes all instances of toRemove */
    while(remove_first(tree, pin)){
          ++removals;}

    return removals;
} /* end remove_each #}}} */
Ejemplo n.º 13
0
static void ICACHE_FLASH_ATTR
on_task_serviced() {
	// os_intr_lock();

	remove_first();
	my_sent_next();

	// os_intr_unlock();

}
Ejemplo n.º 14
0
Archivo: ct_msg.c Proyecto: Lopo/Lotos
void send_icqpage(UR_OBJECT user, char *inpstr)
{
	char fname[FNAME_LEN], icqnum[ICQ_LEN+1], subj[100], addr[100];
	int on;
	UR_OBJECT ur;
	FILE *fp;

	if (word_count<3) {
		write_usage(user, "%s <user>/<ICQ#> <text>", command_table[ICQPAGE].name);
		return;
		}
	icqnum[0]='\0';
	if (is_number(word[1])) strncpy(icqnum, word[1], ICQ_LEN);
	else {
		if (!(ur=get_user_name(user, word[1]))) {
			if (!(ur=create_user())) {
				vwrite_user(user, "%s: nemozem vytvorit docasny user objekt.\n", syserror);
				write_syslog(ERRLOG, 1, "Unable to create temp user object in send_icqpage()\n");
				return;
				}
			strcpy(ur->name, word[1]);
			if (!load_user_details(ur)) {
				write_user(user, nosuchuser);
				destruct_user(ur);
				destructed=0;
				return;
				}
			on=0;
			}
		else on=1;
		strcpy(icqnum, ur->icq);
		if (!on) {
			destruct_user(ur);
			destructed=0;
			}
		}
	if (icqnum[0]=='\0') {
		write_user(user, "sprava neposlana, chybne alebo nezistitelne ICQ cislo\n");
		return;
		}
	sprintf(fname, "%s/%s.icq", TEMPFILES, user->name);
	if (!(fp=fopen(fname, "w"))) {
		write_user(user, "nemozem vytvorit docasny subor pre spravu\n");
		write_syslog(ERRLOG, 1, "unable to open file in send_icqpage()\n");
		return;
		}
	fprintf(fp, icq_page_email);
	fprintf(fp, "%s\n", remove_first(inpstr));
	fclose(fp);
	sprintf(addr, "*****@*****.**", icqnum);
	sprintf(subj, "ICQ page from %s", user->name);
	send_email(addr, subj, fname);
	write_user(user, "sprava bola odoslana\n");
}
Ejemplo n.º 15
0
void* liveness_work(void* arg)
{
	vertex_t*	u = NULL;
	vertex_t*	v;
	set_t*		prev;
	size_t		j;
	list_t*		p;
	list_t*		h;
	list_t*		worklist = (list_t*) arg;
	while ((u = remove_first(&worklist)) != NULL) {
		pthread_mutex_lock(u->mutex); // Lock on current vertex
		u->listed = false;
		pthread_mutex_unlock(u->mutex); // Unlock

		reset(u->set[OUT]);

		for (j = 0; j < u->nsucc; ++j){
			pthread_mutex_lock((u->succ[j])->mutex); // Lock on successor
			or(u->set[OUT], u->set[OUT], u->succ[j]->set[IN]);
//			printf("Gathering from other vertexes\n");
			pthread_mutex_unlock((u->succ[j])->mutex); // Unlock
		}

		pthread_mutex_lock(u->mutex); // Lock current on vertex
		prev = u->prev;
		u->prev = u->set[IN];
		u->set[IN] = prev;

		/* in our case liveness information... */
		propagate(u->set[IN], u->set[OUT], u->set[DEF], u->set[USE]);
		pthread_mutex_unlock(u->mutex); // Unlock
//		printf("%p\n", (void*) u->pred);
		if (u->pred != NULL && !equal(u->prev, u->set[IN])) {
			p = h = u->pred;
			do {
				v = p->data;
				pthread_mutex_lock(v->mutex); // Lock on predecessor
//				printf("do-while...\n");
				if (!v->listed) {
//					printf("Not listed\n");
					v->listed = true;
					insert_last(&worklist, v);
				}
				pthread_mutex_unlock(v->mutex); // Unlock
				p = p->succ;

			} while (p != h);
		}
	}
//	printf("Thread done\n");
	return NULL;
}
Ejemplo n.º 16
0
void liveness(cfg_t* cfg)
{
        printf("I am orig\n");
        vertex_t*        u;
        vertex_t*        v;
        set_t*                prev;
        size_t                i;
        size_t                j;
        list_t*                worklist;
        list_t*                p;
        list_t*                h;

        worklist = NULL;

        for (i = 0; i < cfg->nvertex; ++i) {
                u = &cfg->vertex[i];

                insert_last(&worklist, u);
                u->listed = true;
        }

        while ((u = remove_first(&worklist)) != NULL) {
                u->listed = false;

                reset(u->set[OUT]);

                for (j = 0; j < u->nsucc; ++j)
                        or(u->set[OUT], u->set[OUT], u->succ[j]->set[IN]);

                prev = u->prev;
                u->prev = u->set[IN];
                u->set[IN] = prev;

                /* in our case liveness information... */
                propagate(u->set[IN], u->set[OUT], u->set[DEF], u->set[USE]);

                if (u->pred != NULL && !equal(u->prev, u->set[IN])) {
                        p = h = u->pred;
                        do {
                                v = p->data;
                                if (!v->listed) {
                                        v->listed = true;
                                        insert_last(&worklist, v);
                                }

                                p = p->succ;

                        } while (p != h);
                }
        }
}
Ejemplo n.º 17
0
void 
moveto(dbref what, dbref where)
{
    dbref   loc;

    /* do NOT move garbage */
    if (what != NOTHING && Typeof(what) == TYPE_GARBAGE) {
	return;
    }

    if(what != NOTHING && parent_loop_check(what, where)) {
	/* Prevent stupid loop holes elsewhere */
	return;
    }

    /* remove what from old loc */
    if ((loc = DBFETCH(what)->location) != NOTHING) {
	DBSTORE(loc, contents, remove_first(DBFETCH(loc)->contents, what));
    }
    /* test for special cases */
    switch (where) {
	case NOTHING:
	    DBSTORE(what, location, NOTHING);
	    return;		/* NOTHING doesn't have contents */
	case HOME:
	    switch (Typeof(what)) {
		case TYPE_PLAYER:
		    where = DBFETCH(what)->sp.player.home;
		    break;
		case TYPE_THING:
		    where = DBFETCH(what)->sp.thing.home;
		    if (parent_loop_check(what, where))
			where = DBFETCH(OWNER(what))->sp.player.home;
		    break;
		case TYPE_ROOM:
		    where = GLOBAL_ENVIRONMENT;
		    break;
		case TYPE_PROGRAM:
		    where = OWNER(what);
		    break;
	    }
    }

    /* now put what in where */
    PUSH(what, DBFETCH(where)->contents);
    DBDIRTY(where);
    DBSTORE(what, location, where);
}
Ejemplo n.º 18
0
int main(void)
{
	setup_locale();
	setup_tmpctx();

	sanity();
	remove_one();
	remove_first();
	remove_last();
	remove_multiple();
	remove_all();
	remove_complex();

	tal_free(tmpctx);
	printf("run-json_remove ok\n");
}
Ejemplo n.º 19
0
void remove_from_free_list(block_t* block)
{
	if(free_list[block->kval] == block){
		remove_first(block->kval);
	}else{
		block_t* succ = block->succ;
		block_t* pred = block->pred;
		if(succ){
			succ->pred = pred;
		}
		if(pred){
			pred->succ = succ;	
		}
		block->pred = NULL;
		block->succ = NULL;
	}
}
Ejemplo n.º 20
0
//----------------------------------------------------------------------------
// CTmTimerList::pop
// Purpose : Pop the first element off the timer list.  This also removes it
// from the list.
//----------------------------------------------------------------------------
CTmTimerEvent * CTmTimerList::pop(CTmTime *pp_time)
{
   CTmTimerEvent *lp_event = (CTmTimerEvent *) get_first();
   if (lp_event)
      pp_time->set(curr_key());
   else
      pp_time->set(0);
   int lv_count = count(curr_key());
   get_end();

   // Avoiding tracing here for efficiency
   if (lp_event)
   {
      //7/8/10 Temporary code to catch duplicates
      if (lv_count > 1)
      {
         TMTIME_TRACE(5, XATM_TraceTimer, ("CTmTimerList::pop : DUPLICATE KEY DETECTED. count=%d\n", lv_count));
         CTmTimerEvent * lp_ev = (CTmTimerEvent *) get_first();

         for (int lv_idx=0;lv_idx < lv_count; lv_idx++)
         {
             TMTIME_TRACE(5, XATM_TraceTimer, ("CTmTimerList::pop : DUPLICATE KEY DETECTED. %d: key " PFLL ", cmd %d, ID %d\n", 
                 lv_idx, curr_key(), lp_ev->command(), ((lp_ev->transaction())?lp_ev->transaction()->seqnum():-1)));
             lp_ev = (CTmTimerEvent *) get_next();
         }
         get_end();
      }

      CTmTimerEvent *lp_removedEvent = (CTmTimerEvent *) remove_first((pp_time->get()));
      if (lp_event != lp_removedEvent)
      {
          TMTIME_TRACE(1, XATM_TraceError, ("CTmTimerList::pop : PROGRAMMING ERROR! first event %p doesn't match removed event %p.\n",
             (void *) lp_event, (void *) lp_removedEvent));
          abort();
      }
      TMTIME_TRACE(5, XATM_TraceTimer, ("CTmTimerList::pop : EXIT event %p, inputTime %d, returnTime " PFLL ".\n",
         (void *) lp_event, lp_event->wakeupInterval(), pp_time->get()));
   }
   else
   {
      TMTIME_TRACE(5, XATM_TraceTimer, ("CTmTimerList::pop : EXIT Timer list empty, returnTime " PFLL ".\n",
         pp_time->get()));
   }
   return lp_event;
} // CTmTimerList::pop
Ejemplo n.º 21
0
/***
 * Send data if in Idle state
 */
static void ICACHE_FLASH_ATTR
my_sent_next() {

	if (my_send_state == Idle && !fifo_is_empty(msg_queue)) {

		my_send_state = WaitingForSend;
		my_send_queue_item_t *i = (my_send_queue_item_t *) fifo_first(msg_queue);

		// when the connection is closed do not send the data
		if (i->l->free) {
			remove_first();
			my_sent_next();
		} else {
			espconn_sent(i->l->pCon, i->data, i->length);
		}
	}

}
Ejemplo n.º 22
0
/*
 * Show list of people suggestions are from without seeing the whole lot
 */
void
suggestions_from(UR_OBJECT user)
{
    char id[ARR_SIZE], line[ARR_SIZE], filename[80], *s, *str;
    FILE *fp;
    int valid;
    int cnt;

    if (!amsys->suggestion_count) {
        write_user(user, "There are currently no suggestions.\n");
        return;
    }
    sprintf(filename, "%s/%s", MISCFILES, SUGBOARD);
    fp = fopen(filename, "r");
    if (!fp) {
        write_user(user,
                "There was an error trying to read the suggestion board.\n");
        write_syslog(SYSLOG, 0,
                "Unable to open suggestion board in suggestions_from().\n");
        return;
    }
    vwrite_user(user, "\n~BB*** Suggestions on the %s board from ***\n\n",
            SUGBOARD);
    valid = 1;
    cnt = 0;
    for (s = fgets(line, ARR_SIZE - 1, fp); s;
            s = fgets(line, ARR_SIZE - 1, fp)) {
        if (*s == '\n') {
            valid = 1;
        }
        sscanf(s, "%s", id);
        str = colour_com_strip(id);
        if (valid && !strcmp(str, "From:")) {
            vwrite_user(user, "~FC%2d)~RS %s", ++cnt, remove_first(s));
            valid = 0;
        }
    }
    fclose(fp);
    vwrite_user(user, "\nTotal of ~OL%d~RS suggestions.\n\n",
            amsys->suggestion_count);
}
Ejemplo n.º 23
0
Archivo: move.c Proyecto: chazu/btmux
void move_object(dbref thing, dbref dest)
{
	dbref src;

	/*
	 * Remove from the source location 
	 */

	src = Location(thing);
	if(src != NOTHING)
		s_Contents(src, remove_first(Contents(src), thing));

	/*
	 * Special check for HOME 
	 */

	if(dest == HOME)
		dest = Home(thing);

	/*
	 * Add to destination location 
	 */

	if(dest != NOTHING)
		s_Contents(dest, insert_first(Contents(dest), thing));
	else
		s_Next(thing, NOTHING);
	s_Location(thing, dest);

	/*
	 * Look around and do the penny check 
	 */

	look_in(thing, dest, (LK_SHOWEXIT | LK_OBEYTERSE));
	if(isPlayer(thing) && (mudconf.payfind > 0) &&
	   (Pennies(thing) < mudconf.paylimit) && (!Controls(thing, dest)) &&
	   ((random() % mudconf.payfind) == 0)) {
		giveto(thing, 1);
		notify_printf(thing, "You found a %s!", mudconf.one_coin);
	}
}
Ejemplo n.º 24
0
Archivo: macros.c Proyecto: Lopo/Lotos
/* Get user's macros */
void get_macros(UR_OBJECT user)
{
	FILE *fp;
	int l_len=(MC_NAME_LEN+MC_COM_LEN+2);
	MC_OBJECT mc;
	char fname[FNAME_LEN], line[ARR_SIZE*2];

	set_crash();
#ifdef NETLINKS
	if (user->type==REMOTE_TYPE) return;
#endif
	sprintf(fname,"%s/%s.MAC",USERMACROS,user->name);

	if ((fp=fopen(fname, "r"))==NULL) return;
	fgets(line, l_len, fp);
	
	while (!feof(fp)) {
		line[strlen(line)-1]='\0';
		if ((mc=create_macro())==NULL) {
			fclose(fp);
			return;
			}
		if (user->first_macro==NULL) {
			user->first_macro=mc;
			mc->prev=NULL;
			}
		else {
			user->last_macro->next=mc;
			mc->prev=user->last_macro;
			}
		mc->next=NULL;
		user->last_macro=mc;

		sscanf(line, "%s ", mc->name);
		strcpy(mc->comstr, remove_first(line));
		fgets(line, l_len, fp);
		}
	fclose(fp);
}
Ejemplo n.º 25
0
Archivo: boards.c Proyecto: Lopo/Lotos
/* Check if a normal user can remove a message */
int check_board_wipe(UR_OBJECT user)
{
    FILE *fp;
    int valid,cnt,msg_number,yes,pt;
    char w1[ARR_SIZE],w2[ARR_SIZE],line[ARR_SIZE],line2[ARR_SIZE],fname[FNAME_LEN],id[ARR_SIZE],rmname[ROOM_NAME_LEN+1];
    RM_OBJECT rm;

    set_crash();
    if (word_count<2) {
        write_usage(user,"wipe <message #>");
        return 0;
    }
    rm=user->room;
    if (!rm->mesg_cnt) {
        write_user(user, no_message_prompt);
        return 0;
    }
    msg_number=atoi(word[1]);
    if (!msg_number) {
        write_usage(user,"wipe <#>");
        return 0;
    }
    if (msg_number>rm->mesg_cnt) {
        vwrite_user(user,"There %s only %d message%s on the board.\n",
                    PLTEXT_IS(rm->mesg_cnt),rm->mesg_cnt,PLTEXT_S(rm->mesg_cnt));
        return 0;
    }
    if (rm->access==PERSONAL_LOCKED || rm->access==PERSONAL_UNLOCKED) {
        midcpy(rm->name,rmname,1,strlen(rm->name)-2);
        rmname[0]=toupper(rmname[0]);
        sprintf(fname,"%s/%s.B", USERROOMS,rmname);
    }
    else sprintf(fname,"%s/%s.B", ROOMFILES, rm->name);
    if (!(fp=fopen(fname,"r"))) {
        write_user(user,"There was an error trying to read message board.\n");
        write_syslog(ERRLOG,1,"Unable to open message board for %s in check_board_wipe().\n",rm->name);
        return 0;
    }
    valid=1;
    cnt=1;
    yes=0;
    id[0]='\0';
    w1[0]='\0';
    w2[0]='\0';
    fgets(line,ARR_SIZE-1,fp);
    while(!feof(fp)) {
        if (*line=='\n') valid=1;
        sscanf(line,"%s %d",id,&pt);
        if (valid && !strcmp(id,"PT:")) {
            line2[0]='\0';
            strcpy(line2,remove_first(remove_first(line)));
            sscanf(line2,"%s %s",w1,w2);
            if (msg_number==cnt) {
                /* lower case the name incase of recapping */
                strtolower(w2);
                w2[0]=toupper(w2[0]);
                if (!strcmp(w2,user->name)) {
                    yes=1;
                    goto SKIP; /* found result, no need to go through rest of file */
                }
            }
            valid=0;
            cnt++;
            if (cnt>msg_number) goto SKIP; /* no point carrying on if checked already */
        }
        fgets(line,ARR_SIZE-1,fp);
    }
SKIP:
    fclose(fp);
    if (!yes) {
        write_user(user,"You did not post that message.  Use ~FTbfrom~RS to check the number again.\n");
        return 0;
    }
    user->wipe_from=msg_number;
    user->wipe_to=msg_number;
    return 1;
}
Ejemplo n.º 26
0
Archivo: main.c Proyecto: TristanDuck/C
int main(void)
{
	IntNode *head = NULL;  // An empty linked list.
    IntNode *empty = NULL; // Another empty linked list.

    printf("=== Testing insert_front ===\n\n");
	printf("Calling insert_front with list: ");
    print_linked_list(head);
    printf("\nInserting 3.\n");
	head = insert_front(head, 3);
	printf("Expected list: 3\n");
    printf("Actual list: ");
    print_linked_list(head);
	printf("\n\n");

	printf("Calling insert_front with list: ");
    print_linked_list(head);
    printf("\nInserting 2.\n");
	head = insert_front(head, 2);
	printf("Expected list: 2 -> 3\n");
    printf("Actual list: ");
    print_linked_list(head);
	printf("\n\n");

	printf("Calling insert_front with list: ");
    print_linked_list(head);
    printf("\nInserting 1.\n");
	head = insert_front(head, 1);
	printf("Expected list: 1 -> 2 -> 3\n");
    printf("Actual list: ");
    print_linked_list(head);
	printf("\n\n");

    printf("=== Testing contains ===\n\n");

	_Bool found;

	printf("Calling contains with list: ");
    print_linked_list(empty);
    printf("\nSearching for 1.\n");
	found = contains(empty, 1);
	printf("Expected result: false\n");
    printf("Actual result: ");
    print_boolean(found);
	printf("\n\n");

	printf("Calling contains with list: ");
    print_linked_list(head);
    printf("\nSearching for 1.\n");
	found = contains(head, 1);
	printf("Expected result: true\n");
    printf("Actual result: ");
    print_boolean(found);
	printf("\n\n");

	printf("Calling contains with list: ");
    print_linked_list(head);
    printf("\nSearching for 3.\n");
	found = contains(head, 3);
	printf("Expected result: true\n");
    printf("Actual result: ");
    print_boolean(found);
	printf("\n\n");

	printf("Calling contains with list: ");
    print_linked_list(head);
    printf("\nSearching for 6.\n");
	found = contains(head, 6);
	printf("Expected result: false\n");
    printf("Actual result: ");
    print_boolean(found);
	printf("\n\n");

    printf("=== Testing append_rear ===\n\n");

	printf("Calling append_rear with list: ");
    print_linked_list(head);
    printf("\nAppending 4.\n");
	head = append_rear(head, 4);
	printf("Expected list: 1 -> 2 -> 3 -> 4\n");
    printf("Actual list: ");
    print_linked_list(head);
	printf("\n\n");

    printf("=== Testing remove_first ===\n\n");

	printf("Calling remove_first with list: ");
    print_linked_list(head);
	head = remove_first(head);
	printf("\nExpected list: 2 -> 3 -> 4\n");
    printf("Actual list: ");
    print_linked_list(head);
	printf("\n\n");

    printf("=== Testing remove_last ===\n\n");

	printf("Calling remove_last with list: ");
    print_linked_list(head);
	head = remove_last(head);
	printf("\nExpected list: 2 -> 3\n");
    printf("Actual list: ");
    print_linked_list(head);
	printf("\n\n");

	printf("Calling remove_last with list: ");
    print_linked_list(head);
	head = remove_last(head);
	printf("\nExpected list: 2\n");
    printf("Actual list: ");
    print_linked_list(head);
	printf("\n\n");

	printf("Calling remove_last with list: ");
    print_linked_list(head);
	head = remove_last(head);
	printf("\nExpected list: empty list\n");
    printf("Actual list: ");
    print_linked_list(head);
	printf("\n\n");

    /* Tests for Exercise 1. */
    
    printf("Building linked list 1 -> 1 -> 2 -> 3 -> 3 -> 4 -> 5 -> 5 -> 5\n\n");

    head = NULL;
    head = intnode_construct(5, head);
    head = intnode_construct(5, head);
    head = intnode_construct(5, head);
    head = intnode_construct(4, head);
    head = intnode_construct(3, head);
    head = intnode_construct(3, head);
    head = intnode_construct(2, head);
    head = intnode_construct(1, head);
    head = intnode_construct(1, head);
    // print_linked_list(head);

    printf("=== Testing count ===\n\n");

    int occurrences;

	printf("Calling count with list: ");
    print_linked_list(empty);
    printf("\nCounting 1's.\n");
	occurrences = count(empty, 1);
	printf("Expected result: 0\n");
    printf("Actual result: %d\n\n", occurrences);

	printf("Calling count with list: ");
    print_linked_list(empty);
    printf("\nCounting 7's.\n");
	occurrences = count(empty, 7);
	printf("Expected result: 0\n");
    printf("Actual result: %d\n\n", occurrences);

	printf("Calling count with list: ");
    print_linked_list(head);
    printf("\nCounting 1's.\n");
	occurrences = count(head, 1);
	printf("Expected result: 2\n");
    printf("Actual result: %d\n\n", occurrences);

	printf("Calling count with list: ");
    print_linked_list(head);
    printf("\nCounting 2's.\n");
	occurrences = count(head, 2);
	printf("Expected result: 1\n");
    printf("Actual result: %d\n\n", occurrences);

	printf("Calling count with list: ");
    print_linked_list(head);
    printf("\nCounting 3's.\n");
	occurrences = count(head, 3);
	printf("Expected result: 2\n");
    printf("Actual result: %d\n\n", occurrences);

	printf("Calling count with list: ");
    print_linked_list(head);
    printf("\nCounting 4's.\n");
	occurrences = count(head, 4);
	printf("Expected result: 1\n");
    printf("Actual result: %d\n\n", occurrences);

	printf("Calling count with list: ");
    print_linked_list(head);
    printf("\nCounting 5's.\n");
	occurrences = count(head, 5);
	printf("Expected result: 3\n");
    printf("Actual result: %d\n\n", occurrences);

	printf("Calling count with list: ");
    print_linked_list(head);
    printf("\nCounting 7's.\n");
	occurrences = count(head, 7);
	printf("Expected result: 0\n");
    printf("Actual result: %d\n\n", occurrences);

    /* Tests for Exercise 2. */

    printf("=== Testing index ===\n\n");

    int posn;

	printf("Calling index with list: ");
    print_linked_list(empty);
    printf("\nSearching for 1.\n");
	posn = index(empty, 1);
	printf("Expected result: -1\n");
    printf("Actual result: %d\n\n", posn);

	printf("Calling index with list: ");
    print_linked_list(head);
    printf("\nSearching for 1.\n");
	posn = index(head, 1);
	printf("Expected result: 0\n");
    printf("Actual result: %d\n\n", posn);

	printf("Calling index with list: ");
    print_linked_list(head);
    printf("\nSearching for 2.\n");
	posn = index(head, 2);
	printf("Expected result: 2\n");
    printf("Actual result: %d\n\n", posn);

	printf("Calling index with list: ");
    print_linked_list(head);
    printf("\nSearching for 3.\n");
	posn = index(head, 3);
	printf("Expected result: 3\n");
    printf("Actual result: %d\n\n", posn);

	printf("Calling index with list: ");
    print_linked_list(head);
    printf("\nSearching for 4.\n");
	posn = index(head, 4);
	printf("Expected result: 5\n");
    printf("Actual result: %d\n\n", posn);

	printf("Calling index with list: ");
    print_linked_list(head);
    printf("\nSearching for 5.\n");
	posn = index(head, 5);
	printf("Expected result: 6\n");
    printf("Actual result: %d\n\n", posn);

	printf("Calling index with list: ");
    print_linked_list(head);
    printf("\nSearching for 7.\n");
	posn = index(head, 7);
	printf("Expected result: -1\n");
    printf("Actual result: %d\n\n", posn);

    /* Tests for Exercise 31. */

    printf("=== Testing fetch ===\n\n");

    /* We can't test these cases, because they should cause the function
     * to terminate via assert. 
     *
     * 1. The list is empty; terminate via assert.
     * 2. index < 0 or index >= # of nodes; terminate via assert.
     */

    int value;

	printf("Calling fetch with list: ");
    print_linked_list(head);
    printf("\nFetching value at index 0.\n");
	value = fetch(head, 0);
	printf("Expected result: 1\n");
    printf("Actual result: %d\n\n", value);

	printf("Calling fetch with list: ");
    print_linked_list(head);
    printf("\nFetching value at index 1.\n");
	value = fetch(head, 1);
	printf("Expected result: 1\n");
    printf("Actual result: %d\n\n", value);	
    
    printf("Calling fetch with list: ");
    print_linked_list(head);
    printf("\nFetching value at index 2.\n");
	value = fetch(head, 2);
	printf("Expected result: 2\n");
    printf("Actual result: %d\n\n", value);	
    
    printf("Calling fetch with list: ");
    print_linked_list(head);
    printf("\nFetching value at index 3.\n");
	value = fetch(head, 3);
	printf("Expected result: 3\n");
    printf("Actual result: %d\n\n", value);	
    
    printf("Calling fetch with list: ");
    print_linked_list(head);
    printf("\nFetching value at index 4.\n");
	value = fetch(head, 4);
	printf("Expected result: 3\n");
    printf("Actual result: %d\n\n", value);	
    
    printf("Calling fetch with list: ");
    print_linked_list(head);
    printf("\nFetching value at index 5.\n");
	value = fetch(head, 5);
	printf("Expected result: 4\n");
    printf("Actual result: %d\n\n", value);	
    
    printf("Calling fetch with list: ");
    print_linked_list(head);
    printf("\nFetching value at index 6.\n");
	value = fetch(head, 6);
	printf("Expected result: 5\n");
    printf("Actual result: %d\n\n", value);	
    
    printf("Calling fetch with list: ");
    print_linked_list(head);
    printf("\nFetching value at index 7.\n");
	value = fetch(head, 7);
	printf("Expected result: 5\n");
    printf("Actual result: %d\n\n", value);	
    
    printf("Calling fetch with list: ");
    print_linked_list(head);
    printf("\nFetching value at index 8.\n");
	value = fetch(head, 8);
	printf("Expected result: 5\n");
    printf("Actual result: %d\n\n", value);

    /* Tests for Exercise 4. */

    printf("Building linked list 1 -> 2 -> 3 -> 4\n\n");

    IntNode *list = NULL;
    list = intnode_construct(4, list);
    list = intnode_construct(3, list);
    list = intnode_construct(2, list);
    list = intnode_construct(1, list);

    printf("=== Testing remove_last_one_pointer ===\n\n");

	printf("Calling remove_last_one_pointer with list: ");
    print_linked_list(list);
	list = remove_last_one_pointer(list);
	printf("\nExpected list: 1 -> 2 -> 3\n");
    printf("Actual list: ");
    print_linked_list(list);
	printf("\n\n");

	printf("Calling remove_last_one_pointer with list: ");
    print_linked_list(list);
	list = remove_last_one_pointer(list);
	printf("\nExpected list: 1 -> 2\n");
    printf("Actual list: ");
    print_linked_list(list);
	printf("\n\n");

	printf("Calling remove_last_one_pointer with list: ");
    print_linked_list(list);
	list = remove_last_one_pointer(list);
	printf("\nExpected list: 1\n");
    printf("Actual list: ");
    print_linked_list(list);
	printf("\n\n");

	printf("Calling remove_last_one_pointer with list: ");
    print_linked_list(list);
	list = remove_last_one_pointer(list);
	printf("\nExpected list: empty list\n");
    printf("Actual list: ");
    print_linked_list(list);
	printf("\n\n");
}
Ejemplo n.º 27
0
static void
send_request (GVfsAfpConnection *afp_connection)
{
  GVfsAfpConnectionPrivate *priv = afp_connection->priv;

  RequestData *req_data;
  guint32 writeOffset;
  guint8 dsi_command;

  while ((req_data = g_queue_peek_head (priv->request_queue)))
  {
    if (req_data->cancellable && g_cancellable_is_cancelled (req_data->cancellable))
    {
      if (req_data->simple)
      {
        GError *err = NULL;

        g_cancellable_set_error_if_cancelled (req_data->cancellable, &err);
        g_simple_async_result_take_error (req_data->simple, err);
        g_simple_async_result_complete (req_data->simple);
      }
      remove_first (priv->request_queue);
    }
    else
      break;
  }

  if (!req_data) {
    priv->send_loop_running = FALSE;
    return;
  }

  switch (req_data->type)
  {
    case REQUEST_TYPE_TICKLE:
      priv->write_dsi_header.flags = 0x00;
      priv->write_dsi_header.command = DSI_TICKLE;
      priv->write_dsi_header.requestID = GUINT16_TO_BE (get_request_id (afp_connection));
      priv->write_dsi_header.writeOffset = 0;
      priv->write_dsi_header.totalDataLength = 0;
      priv->write_dsi_header.reserved = 0;
      break;

    case REQUEST_TYPE_COMMAND:
    {
      gsize size;
      
      switch (req_data->command->type)
      {
        case AFP_COMMAND_WRITE:
          writeOffset = 8;
          dsi_command = DSI_WRITE;
          break;
        case AFP_COMMAND_WRITE_EXT:
          writeOffset = 20;
          dsi_command = DSI_WRITE;
          break;

        default:
          writeOffset = 0;
          dsi_command = DSI_COMMAND;
          break;
      }

      priv->write_dsi_header.flags = 0x00;
      priv->write_dsi_header.command = dsi_command;
      priv->write_dsi_header.requestID = GUINT16_TO_BE (get_request_id (afp_connection));
      priv->write_dsi_header.writeOffset = GUINT32_TO_BE (writeOffset);

      /* totalDataLength */
      size = g_vfs_afp_command_get_size (req_data->command);
      if (dsi_command == DSI_WRITE && req_data->command->buf)
        size += req_data->command->buf_size;
      priv->write_dsi_header.totalDataLength = GUINT32_TO_BE (size);
      
      priv->write_dsi_header.reserved = 0;
      break;
    }

    default:
      g_assert_not_reached ();
  }


  write_all_async (g_io_stream_get_output_stream (priv->conn),
                   &priv->write_dsi_header, sizeof (DSIHeader), 0,
                   NULL, write_dsi_header_cb, afp_connection);
}
Ejemplo n.º 28
0
/*
 * Send mail message to everyone
 */
void
level_mail(UR_OBJECT user, char *inpstr)
{
    if (inpstr) {
        static const char usage[] = "Usage: lmail <level>|wizzes|all [<text>]\n";

        /* FIXME: Use sentinel other JAILED */
        if (user->muzzled != JAILED) {
            write_user(user, "You are muzzled, you cannot mail anyone.\n");
            return;
        }
        if (word_count < 2) {
            write_user(user, usage);
            return;
        }
        strtoupper(word[1]);
        user->lmail_lev = get_level(word[1]);
        if (user->lmail_lev == NUM_LEVELS) {
            if (!strcmp(word[1], "WIZZES")) {
                user->lmail_lev = WIZ;
            } else if (!strcmp(word[1], "ALL")) {
                user->lmail_lev = JAILED;
            } else {
                write_user(user, usage);
                return;
            }
            user->lmail_all = !0;
        } else {
            user->lmail_all = 0;
        }
        if (word_count < 3) {
#ifdef NETLINKS
            if (user->type == REMOTE_TYPE) {
                write_user(user,
                        "Sorry, due to software limitations remote users cannot use the line editor.\nUse the \".lmail <level>|wizzes|all <text>\" method instead.\n");
                return;
            }
#endif
            if (!user->lmail_all) {
                vwrite_user(user,
                        "\n~FG*** Writing broadcast level mail message to all the %ss ***\n\n",
                        user_level[user->lmail_lev].name);
            } else {
                if (user->lmail_lev == WIZ) {
                    write_user(user,
                            "\n~FG*** Writing broadcast level mail message to all the Wizzes ***\n\n");
                } else {
                    write_user(user,
                            "\n~FG*** Writing broadcast level mail message to everyone ***\n\n");
                }
            }
            user->misc_op = 9;
            editor(user, NULL);
            return;
        }
        strcat(inpstr, "\n"); /* XXX: risky but hopefully it will be ok */
        inpstr = remove_first(inpstr);
    } else {
        inpstr = user->malloc_start;
    }
    if (!send_broadcast_mail(user, inpstr, user->lmail_lev, user->lmail_all)) {
        write_user(user, "There does not seem to be anyone to send mail to.\n");
        user->lmail_all = 0;
        user->lmail_lev = NUM_LEVELS;
        return;
    }
    if (!user->lmail_all) {
        vwrite_user(user, "You have sent mail to all the %ss.\n",
                user_level[user->lmail_lev].name);
        write_syslog(SYSLOG, 1, "%s sent mail to all the %ss.\n", user->name,
                user_level[user->lmail_lev].name);
    } else {
        if (user->lmail_lev == WIZ) {
            write_user(user, "You have sent mail to all the Wizzes.\n");
            write_syslog(SYSLOG, 1, "%s sent mail to all the Wizzes.\n",
                    user->name);
        } else {
            write_user(user, "You have sent mail to all the users.\n");
            write_syslog(SYSLOG, 1, "%s sent mail to all the users.\n", user->name);
        }
    }
    user->lmail_all = 0;
    user->lmail_lev = NUM_LEVELS;
}
Ejemplo n.º 29
0
 void remove(byte* elem)
 {
     remove_first(elem);
 }
Ejemplo n.º 30
0
// dequeue an item and return it
struct node dequeue(struct node* head) {
  return remove_first(head);
}