示例#1
0
void delcart_handler(http_response* resp, node* param, node* cookie) {
  char *itemnr, *item_name, *username;
  int bytes, max_n, n, del_n;
  node *node;
  char str[STR_SIZE];
  
  itemnr = list_lookup(param, "itemnr");
  if (itemnr) {
    node = cookie;
    sprintf(str, "item%s", itemnr);
    while (node) {
      if (strcmp(node->name, str) == 0) {
        break;
      }
      node = node->next;
    }
    if (node) {
      del_n = atoi(node->name + 4);
      max_n = max_item_nr(cookie);
      node = malloc(sizeof(node));
      sprintf(node->name, "item%i", max_n);
      strcpy(node->value, "0");
      node->next = NULL;
      resp->expire = append_list(resp->expire, node);
      for (n = del_n; n < max_n; n++) {
        sprintf(str, "item%i", n+1);
        item_name = list_lookup(cookie, str);
        node = malloc(sizeof(node));
        sprintf(node->name, "item%i", n);
        strcpy(node->value, item_name);
        node->next = NULL;
        resp->cookie = append_list(resp->cookie, node);
      }
      bytes = 0;
      username = list_lookup(cookie, "username"); 
      if (username) {
        bytes = sprintf(resp->body, "Username: %s\n", username);
      }
      for (n = 1; n < del_n; n++) {
        sprintf(str, "item%i", n);
        item_name = list_lookup(cookie, str);
        bytes += sprintf(resp->body + bytes, "%i. %s\r\n", n, item_name);
      }
      for (n = del_n; n < max_n; n++)   {
        sprintf(str, "item%i", n);
        item_name = list_lookup(resp->cookie, str);
        bytes += sprintf(resp->body + bytes, "%i. %s\r\n", n, item_name);
      }
      resp->status = OK;
      resp->opt_flags |= OPT_CONTENT_LENGTH;
      
    } else {
      resp->status = FORBIDDEN;
    }
  } else {
    resp->status = FORBIDDEN;
  }
  resp->content_type = TEXT;
  resp->cache_control = NO_CACHE;
}
示例#2
0
文件: list.c 项目: gatoravi/MFAST
void insert_after(struct llist *target, int pos, struct llist *insert)
{
	struct list_elem *elem;
	struct list_elem *after_insert;

	if (-1 == pos) {
		/* special case: prepend */
		prepend_list(target, insert);
		return ;
	} else if ((pos >= 0) && (pos <= target->count-2)) {
		/* general case */
		for (elem = target->head; pos > 0; pos--)
			elem = elem->next;
		after_insert = elem->next;
		elem->next = insert->head;
		insert->tail->next = after_insert;
		target->count += insert->count;
		return ;
	} else if (pos == target->count -1) {
		/* special case: append */
		append_list(target, insert);
		return ;
	} else {
		/* unexpected index - this is not too bad, but it does indicate
		 * wrong parameters */
		/* We do nothing in this case - caller should check arguments. */
		return ;
	}
}
示例#3
0
void		see(t_server *server, t_client *client, char *str)
{
  int		lvl;
  char		*old_string;
  char		*string;
  char		*tmp;

  string = xmalloc(1);
  lvl = 0;
  (void)str;
  while (lvl <= client->player->level)
    {
      old_string = string;
      tmp = get_line(server, client, lvl, 2 * lvl + 1);
      string = print_see(string, tmp, lvl, client->player->level);
      if (old_string)
	free(old_string);
      if (tmp)
	free(tmp);
      ++lvl;
    }
  client->player->delay_action = (7.f / server->delay) * 1000000;
  client->messages = append_list(client->messages, strdup(string));
  free(string);
}
int main ()
{
	// create a linked list
	//struct node_t * head_node = NULL;
	struct node_t * curr_node = NULL;

	head = create_list(8);
	print_list();
	//printf("head node var= %d\n",head->var);
	printf("length of the list= %d\n",length_list());
	// append a list
	curr_node = append_list(10);
	print_list();
	//printf("variable appended = %d\n",curr_node->var);
	printf("variable appended = %d\n",head->next->var);
	printf("length of the list= %d\n",length_list());

	// insert a list
	//curr_node = insert_list(9);
	print_list();

	printf("length of the list= %d\n",length_list());

	// delete a list



	return 1;
}
    void AST_t::append(AST_t t)
    {
        if (t._ast == NULL)
        {
            // Do nothing
            return;
        }

        if (ASTType(t._ast) != AST_NODE_LIST)
        {
            std::cerr << "The appended tree is not a list. No append performed" << std::endl;
            return;
        }

        AST appended_list = t._ast;

        AST enclosing_list = get_enclosing_list(this->_ast);

        if (enclosing_list == NULL)
        {
            std::cerr << "Cannot find a suitable list to append" << std::endl;
        }

        append_list(enclosing_list, appended_list);
    }
示例#6
0
void checkout_handler(http_response *resp, node* cookie) {
  char *username, *item_name;
  int max_n, n, bytes;
  char str[STR_SIZE];
  node* item;
  FILE *fp;

  username = list_lookup(cookie, "username");
  fp = fopen("CHECKOUT.txt", "a+");
  if (username && fp) {
    bytes = sprintf(resp->body, "Username: %s\n", username);
    max_n = max_item_nr(cookie);
    for (n = 1; n <= max_n; n++) {
      sprintf(str, "item%i", n);
      item_name = list_lookup(cookie, str);
      item = malloc(sizeof(node));
      strcpy(item->name, str);
      strcpy(item->value, "0");
      item->next = NULL;
      resp->expire = append_list(resp->expire, item);
      bytes += sprintf(resp->body + bytes, "%i. %s\r\n",n , item_name);
    }
    fwrite(resp->body, sizeof(char), bytes, fp);
    fclose(fp);
    resp->status = OK;
    resp->opt_flags |= OPT_CONTENT_LENGTH;
  } else {
    resp->status = FORBIDDEN;
  }
  resp->content_type = TEXT;
  resp->cache_control = NO_CACHE;
}
示例#7
0
/*
 *	dismount_media - unload a volser
 *
 */
req_comp_t
dismount_media(
	library_t *library,
	drive_state_t *drive)
{
	req_comp_t 	err;
	ibm_req_info_t 	*ibm_info;
	xport_state_t 	*transport;
	robo_event_t 	*dismount, *tmp;

	ibm_info = malloc_wait(sizeof (ibm_req_info_t), 2, 0);
	memset(ibm_info, 0, sizeof (ibm_req_info_t));
	ibm_info->drive_id = drive->drive_id;
	sprintf((void *)&ibm_info->volser, "%-8.8s", drive->bar_code);

	/* Build transport thread request */

	dismount = malloc_wait(sizeof (robo_event_t), 5, 0);
	(void) memset(dismount, 0, sizeof (robo_event_t));

	dismount->request.internal.command = ROBOT_INTRL_DISMOUNT_MEDIA;
	dismount->request.internal.address = (void *)ibm_info;

	if (DBG_LVL(SAM_DBG_TMOVE))
		sam_syslog(LOG_DEBUG, "dismount_media: from %s.",
		    drive->un->name);

	dismount->type = EVENT_TYPE_INTERNAL;
	dismount->status.bits = REST_SIGNAL;
	dismount->completion = REQUEST_NOT_COMPLETE;

	transport = library->transports;
	mutex_lock(&dismount->mutex);
	mutex_lock(&transport->list_mutex);
	if (transport->active_count == 0)
		transport->first = dismount;
	else {
		LISTEND(transport, tmp);
		append_list(tmp, dismount);
	}
	transport->active_count++;
	cond_signal(&transport->list_condit);
	mutex_unlock(&transport->list_mutex);

	/* Wait for the transport to do the unload */
	while (dismount->completion == REQUEST_NOT_COMPLETE)
		cond_wait(&dismount->condit, &dismount->mutex);
	mutex_unlock(&dismount->mutex);

	/* Check the dismount request/helper status */
	err = (req_comp_t)dismount->completion;
	if (DBG_LVL(SAM_DBG_TMOVE))
		sam_syslog(LOG_DEBUG, "Return from transport dismount (%#x).",
		    dismount->completion);
	free(ibm_info);
	mutex_destroy(&dismount->mutex);
	free(dismount);
	return (err);
}
示例#8
0
char		get_files_directories(t_list *roots, t_list **files,
				      t_list **directories, t_opt_args *args)
{
  t_root	*root;

  *files = 0;
  *directories = 0;
  while (roots != 0)
    {
      root = (t_root*)roots->datas;
      if (S_ISDIR(root->infos->stat->st_mode))
	append_list(directories, root);
      else
	append_list(files, root);
      roots = roots->next;
    }
}
示例#9
0
static t_client	*get_obj(t_server *server, t_client *client, int i)
{
  t_case	*pos;

  pos = find_case_by_index(server->map, client->player->x, client->player->y);
  if (pos->resources[g_res[i]] > 0)
    {
      client->player->resources[g_res[i]]++;
      pos->resources[g_res[i]]--;
      client->messages = append_list(client->messages, strdup("ok\n"));
      player_take(server, client, g_res[i]);
    }
  else
    client->messages = append_list(client->messages, strdup("ko\n"));

  return (client);
}
示例#10
0
文件: main.c 项目: fgr/whz-sysprog
int main(void)
{
	{
		list_t *dl = make_double_list(8);
		assert(dl->size == 0);
		assert(dl->elemsize == sizeof(double));

		double d = 1.00;
		append(dl, &d);
		assert(dl->size == 1);
		assert(((double* )dl->elements)[0] == d);

//		double d2 = 2.00;
//		assert(append_all(dl, 3, &d, &d, &d2));
//		assert(dl->size == 4);
//		assert(((double* )dl->elements)[0] == d);
//		assert(((double* )dl->elements)[1] == d);
//		assert(((double* )dl->elements)[2] == d);
//		assert(((double* )dl->elements)[3] == d2);

		free_list(dl);
	}

	{
		list_t *il = make_int_list(8);
		assert(il->size == 0);
		assert(il->elemsize == sizeof(int));

		int i1 = 42;
		append(il, &i1);
		assert(il->size == 1);
		assert(((int* )il->elements)[0] == i1);

		int i2 = 23;
		append(il, &i2);
		assert(il->size == 2);
		assert(((int* )il->elements)[0] == i1);
		assert(((int* )il->elements)[1] == i2);

		list_t *il2 = make_int_list(8);
		append(il2, &i2);
		append(il2, &i1);
		assert(il->size == 2);
		assert(((int* )il2->elements)[0] == i2);
		assert(((int* )il2->elements)[1] == i1);

		assert(append_list(il2, il));

		assert(il2->size == 4);
		assert(((int* )il2->elements)[0] == i2);
		assert(((int* )il2->elements)[1] == i1);
		assert(((int* )il2->elements)[2] == i1);
		assert(((int* )il2->elements)[3] == i2);

		free_list(il);
		free_list(il2);
	}
}
示例#11
0
/*
 * Add one more macro definition.  The macro must be of the form NAME[=VALUE].
 * Returns non-zero on success, or zero if the string is incorrectly formed.
 */
int DefineMacro( const char *defineStr )
/**************************************/
{
    ListElem            *newElem;
    const char *        p;
    char *              name;
    char *              value;
    size_t              len;
    const char *        str;
    bool                freeStrFlag = false;

    /*** Validate the string ***/
    str = validate_define_str( defineStr );
    if( str != NULL ) {
        freeStrFlag = true;
    } else {
        str = defineStr;
    }

    /*** Extract the macro name from str ***/
    for( p = str, len = 0; *p != '\0'; p++, len++ ) {
        if( *p == '=' ) {
            break;
        }
    }
    if( len == 0 )
        return( 0 );
    name = AllocMem( len + 1 );
    memcpy( name, str, len );
    name[len] = '\0';
    if( *p != '\0' )
        p++;

    /*** Extract the macro value from str ***/
    while( isspace( *p ) )
        p++;
    if( *p != '\0' ) {
        value = AllocMem( strlen( p ) + 1 );
        strcpy( value, p );
    } else {
        value = NULL;
    }

    /*** Initialize a new list element ***/
    newElem = AllocMem( sizeof( ListElem ) );
    newElem->type = DEFINE;
    newElem->name = name;
    newElem->value = value;
    newElem->next = NULL;

    /*** Add it to the list ***/
    purge_from_list( PURGE_ALL, name ); /* so we don't have any duplicates */
    append_list( newElem );

    if( freeStrFlag )
        FreeMem( (char*)str );
    return( 1 );
}
示例#12
0
void		aff_arg(t_list *list, int argc, char **argv)
{
  int		i;

  i = 0;
  while (++i < argc)
    append_list(list, argv[i]);
  aff_list(list);
}
示例#13
0
文件: parser2.c 项目: tungvx/FSE
static AST classdecls() {
    Token *t = &tok;
    AST a=0;
    AST a1=0, a2=0;

    /* at least one class is required */
    a = new_list(nCLASSDECLS);
    a1 = classdecl();
    if (a1) a = append_list(a, a1);

    while (true) {
	if (t->sym != tCLASS) break;

	a1 = classdecl();
	if (a1) a = append_list(a, a1);
    }
    return a;
}
示例#14
0
void push_skip_type(char * desc)
{
     char * buf;
     buf = (char *)malloc(strlen(desc));
     strncpy(buf, desc, strlen(desc)+1);
     snprintf(LOGBUF, LOG_BUF_SZ, "skipping files matching '%s'", buf);
     slog(LOGBUF, LOG_INF);
     skip_list = append_list(skip_list, buf);
}
示例#15
0
/*
 *	force_media - unload a drive. Issued as a delayed request.
 *
 */
req_comp_t
force_media(
	library_t *library,
	drive_state_t *drive)
{
	req_comp_t 	err;
	ibm_req_info_t 	*ibm_info;
	robo_event_t 	*force, *tmp;
	xport_state_t 	*transport;

	ibm_info = (ibm_req_info_t *)malloc_wait(sizeof (ibm_req_info_t), 2, 0);
	memset(ibm_info, 0, sizeof (ibm_req_info_t));
	ibm_info->drive_id = drive->drive_id;

	/* Build transport thread request */

	force = malloc_wait(sizeof (robo_event_t), 5, 0);
	(void) memset(force, 0, sizeof (robo_event_t));

	force->request.internal.command = ROBOT_INTRL_FORCE_MEDIA;
	force->request.internal.address = (void *)ibm_info;

	if (DBG_LVL(SAM_DBG_TMOVE))
		sam_syslog(LOG_DEBUG, "force_media: from %s.", drive->un->name);

	force->type = EVENT_TYPE_INTERNAL;
	force->status.bits = REST_SIGNAL;
	force->completion = REQUEST_NOT_COMPLETE;

	transport = library->transports;
	mutex_lock(&force->mutex);
	mutex_lock(&transport->list_mutex);
	if (transport->active_count == 0)
		transport->first = force;
	else {
		LISTEND(transport, tmp);
		append_list(tmp, force);
	}
	transport->active_count++;
	cond_signal(&transport->list_condit);
	mutex_unlock(&transport->list_mutex);

	/* Wait for the transport to do the unload */
	while (force->completion == REQUEST_NOT_COMPLETE)
		cond_wait(&force->condit, &force->mutex);
	mutex_unlock(&force->mutex);

	err = (req_comp_t)force->completion;
	if (DBG_LVL(SAM_DBG_TMOVE))
		sam_syslog(LOG_DEBUG,
		    "Return from transport force (%#x).", force->completion);

	free(ibm_info);
	mutex_destroy(&force->mutex);
	free(force);
	return (err);
}
示例#16
0
int main(){
    List list;
    List list2;
    int i;
    
    init_list( &list );
    printf( "Empty: %d\n", empty_list( list ) );
    for( i = 1; i <= 5; i++ ){
        append_node( &i, sizeof( int ), list );
        printf( "Length: %d | ", length( list ) );
        print_list( list );
    }
    for( i = 6; i <= 10; i++ ){
        insert_front( &i, sizeof( int ), list );
        printf( "Length: %d | ", length( list ) );
        print_list( list );
    }
    printf( "Empty: %d\n", empty_list( list ) );
    printf( "First: %d\n", get_int( list_op_first( list ) -> data ) );
    printf( "Last:  %d\n", get_int( list_op_last( list ) -> data ) );
    printf( "Second to last: %d\n", get_int( list_op_prev( list_op_last( list ), list ) -> data ) );
    printf( "Second element: %d\n", get_int( get_elem_at( 1, list ) -> data ) );
    
    place_after( &i, sizeof( int ), get_elem_at( 1, list ), list );
    print_list( list );
    i++;
    insert_at( &i, sizeof( int ), 2, list );
    print_list( list );
    i++;
    insert_at( &i, sizeof( int ), 0, list );
    print_list( list );
    
    init_list( &list2 );
    for( i = 100; i > 95; i-- ){
        insert_front( &i, sizeof( int ), list2 );
    }
    append_list( list, &list2 );
    free( list2 );
    print_list( list );
    
    printf( "Erasing 5th element...\n" );
    erase_at( 4, list );
    print_list( list );
    printf( "Erasing 1st element...\n" );
    erase_at( 0, list );
    print_list( list );
    printf( "Erasing last element...\n" );
    erase_node( list_op_last( list ), list );
    print_list( list );
    printf( "Erasing 3rd element...\n" );
    erase_node( get_elem_at( 2, list ), list );
    print_list( list );
    
    clear_list( &list );
    
    return 0;
}
示例#17
0
list *split_words(const char *line, int add_term)
{
    char *p = NULL;
    char *line_end = NULL;
    list *words = NULL;

    if (!line)
        return NULL;

    p = calloc(1, cgc_strlen(line) + 1);
    char *to_free = p;
    if (!p)
        error(EALLOC);
    strncpy(p, line, cgc_strlen(line));
    line_end = p + cgc_strlen(line);

    while (p < line_end) {
        while(isspace(*p))
            p++;

        char *word_start = p;
        char *word_end = p;

        while (word_end < line_end && isprint(*word_end) && !isspace(*word_end))
            word_end++;
        *word_end = '\0';

        char *wc = calloc(1, cgc_strlen(word_start) + 1);
        strcpy(wc, word_start);
        append_list(&words, wc, 1);
        p = word_end + 1;
    }

    if (add_term) {
        char *wc = calloc(1, cgc_strlen(chain_term) + 1);
        strcpy(wc, chain_term);
        append_list(&words, chain_term, 1);
    }

    free(to_free);
    return words;
}
示例#18
0
文件: list.c 项目: huntrax11/DS-HW-1
D reversed_list(D list){
    if(list->next != NULL){
        D a = make_copy(list);
        D r = reversed_list(list->next);
        a->next = NULL;
        append_list(r, a);
        return r;
    }else{
        return make_copy(list);
    }
}
示例#19
0
void PrivPtr::append_ptr_list(priv_ptr assign_ptr, priv_ptr right_ptr)
{
	dlist list = right_ptr->list; 
	listnode node = list->head->next; 
	while(node != list->tail)
	{
		append_list(assign_ptr->list, node->u.ptr_location->list); 
		node = node->next; 
	}
	return; 
}
示例#20
0
文件: parser2.c 项目: tungvx/FSE
static AST structdecls(AST sdl){
    Token *t = &tok;
    AST a = 0;
    while (true){
	if (t->sym != tSTRUCT) break;
	gettoken();
	a = structdecl();
	if (a) sdl = append_list(sdl, a);
    }
    return sdl;
}
示例#21
0
static void	print_resources(t_client *client, t_case *pos, int x, int y)
{
  char		*s;
  int		*res;

  res = pos->resources;
  asprintf(&s, "bct %d %d %d %d %d %d %d %d %d\n", x, y, res[FOOD], \
	   res[LINEMATE], res[DERAUMERE], res[SIBUR], \
	   res[MENDIANE], res[PHIRAS], res[THYSTAME]);
  client->messages = append_list(client->messages, strdup(s));
  free(s);
}
示例#22
0
文件: parser2.c 项目: tungvx/FSE
static AST funcdecls(AST fdl) {
    Token *t = &tok;
    AST a=0;
    AST a1=0;

    while (true) {
	if ( !isrettype(t->sym) && !isclasstype() && !isstructtype()) break;
	a1 = funcdecl();
	if(a1) fdl = append_list(fdl, a1);
    }
    return fdl;
}
示例#23
0
void		connect_number(t_server *server, t_client *client, char *str)
{
  t_team	*team;
  char		*s;

  (void)str;
  team = find_team_by_name(server->teams, client->team);
  client->player->delay_action = 0;

  asprintf(&s, "%d\n", server->max_clients - team->clients);
  client->messages = append_list(client->messages, strdup(s));
  free(str);
}
示例#24
0
void		put_obj(t_server *server, t_client *client, char *str)
{
  char		*resources;
  int		i;

  resources = split_string(str, ' ', 1);
  if (resources)
    {
      i = 0;
      while (g_str[i] && strcmp(g_str[i], resources) != 0)
	i++;

      if (g_str[i] != NULL)
	get_obj(server, client, i);
      else
	client->messages = append_list(client->messages, strdup("ko\n"));
      free(resources);
    }
  else
    client->messages = append_list(client->messages, strdup("ko\n"));

  client->player->delay_action = (7.f / server->delay) * 1000000;
}
示例#25
0
文件: parser2.c 项目: tungvx/FSE
static AST vardecls(AST vdl, AST fdl) {
    Token *t = &tok;
    AST a=0;
    AST a1=0;
    bool isfuncdecl = false;

    while (true) {
	if (!isprimtype(t->sym) && !isclasstype() && !isstructtype()) break;
	a1 = vardecl();
	if (a1 && nodetype(a1) == nFUNCDECL) /* expect var, but it was func */
	{ isfuncdecl = true; break; }
	if (a1) vdl = append_list(vdl, a1);

	if (t->sym == ';') gettoken();
	else parse_error("expected ;");
    }

    if (isfuncdecl) {
	fdl = append_list(fdl, a1);    /* add first elem of fdl */
    }

    return vdl;
}
示例#26
0
文件: myre.c 项目: vobiscum/myre
/*-------------------------------button---------------------------------*/
void
on_entry1_activate() {

    debug("Entry activated");
    if(!viewsAssembled)
        assemble_views();
    myre_start_request();
    /*use processed word mark or raw input*/
    gchar *string = (gchar *)gtk_entry_get_text(GTK_ENTRY(entry));
    if(strlen(string) > 0) {
        append_list(store, string);
    }

}
示例#27
0
/*
 * Remove a macro definition.
 */
void UndefineMacro( const char *name )
/************************************/
{
    ListElem    *newElem;

    /*** Add an undefine directive if needed ***/
    if( purge_from_list( PURGE_DEFINE, name )  ==  PURGE_NOACTION ) {
        newElem = AllocMem( sizeof( ListElem ) );
        newElem->type = UNDEFINE;
        newElem->name = (char*)name;
        newElem->value = NULL;
        newElem->next = NULL;
        append_list( newElem );
    }
}
示例#28
0
文件: link.c 项目: godlikeJia/cpp
int main(int argc, char** argv)
{
    list_t* list = create_list();
    for (int i=0; i<10; i++) {
        append_list(list, i);
    }

    traverse(list);

    reverse(list);

    traverse(list);

    list_t* foo = create_list();
    list_t* bar = create_list();
    for (int i=0; i<10; i++) {
        append_list(foo, 2*i);
        append_list(bar, 2*i + 1);
    }
    traverse(foo);
    traverse(bar);
    traverse(merge_sorted_list(foo, bar));
    return 0;
}
示例#29
0
void		case_content(t_server *server, t_client *client, char *str)
{
  t_case	*pos;
  char		*x;
  char		*y;

  if ((x = split_string(str, ' ', 1)) != NULL)
    {
      if ((y = split_string(str, ' ', 2)) != NULL)
	{
	  pos = find_case_by_index(server->map, atoi(x), atoi(y));
	  if (pos != NULL)
	    print_resources(client, pos, atoi(x), atoi(y));
	  else
	    client->messages = append_list(client->messages, strdup("sbp\n"));
	  free(y);
	}
      else
	client->messages = append_list(client->messages, strdup("sbp\n"));
      free(x);
    }
  else
    client->messages = append_list(client->messages, strdup("sbp\n"));
}
示例#30
0
文件: link.c 项目: godlikeJia/cpp
list_t* merge_sorted_list(list_t* foo, list_t* bar) {
    list_t* ret = create_list();
    node_t* f = foo->next;
    node_t* b = bar->next;
    while (b && f) {
        if (b->val < f->val) {
            append_list(ret, b->val);
            b = b->next;
        }
        if (b->val > f->val) {
            append_list(ret, f->val);
            f = f->next;
        }
    }
    while (b) {
        append_list(ret, b->val);
        b = b->next;
    }
    while (f) {
        append_list(ret, f->val);
        f = f->next;
    }
    return ret;
}