コード例 #1
0
ファイル: test01.c プロジェクト: onyettr/c-llist
static int test03 ( void ) {
  list_t *p = NULL;

  printf("\ntest03 - test list_add_front\n" );

  p = list_create();
  printf("test03 - test list_add-front as first element\n");
  list_add_front (p, 666);
  list_show(p);

  printf("test03 - test list_add-front element\n");  
  list_add ( p, 101);
  list_add ( p, 201);
  list_add ( p, 301);
  list_add ( p, 401);
  list_show(p);
  list_add_front (p, 999);
  list_show(p);
  list_add_front (p, 888);
  list_show(p);
  list_add_front (p, 777);
  list_show(p);
  
  return 0;
}
コード例 #2
0
ファイル: 08.02.c プロジェクト: walrus7521/code
int main()
{
    int a[] = {0,1,2,3,4,5,6,7};
    list *l = list_create(a, 8);
    list_show(l);
    l->next = reverse(l);
    list_show(l);
    return 0;
}
コード例 #3
0
ファイル: list.c プロジェクト: void3/restrepo
int main()
{
	list_t head;
	list_t a, b, c;

    head.next = NULL;
    head.member = 0;     /* head member is dummy */
    list_show(&head);
    a.member=1; a.next=NULL;list_insert(&head, &a);
    list_show(&head);
    b.member=2; b.next=NULL;list_insert(&head, &b);
    list_show(&head);
    c.member=3; c.next=NULL;list_insert(&head, &c);
    list_show(&head);
    list_delete(&head, &a);
    list_show(&head);
    list_delete(&head, &c);
    list_show(&head);
    list_delete(&head, &c);
    list_show(&head);
    list_delete(&head, &b);
    list_show(&head);
    list_insert(&head, &c);
    list_insert(&head, &b);
    list_insert(&head, &a);
    list_show(&head);
    list_delete(&head, &c);
    list_delete(&head, &b);
    list_delete(&head, &a);
    return 0;
}
コード例 #4
0
ファイル: practice_problems.c プロジェクト: gaibo/C
void evidence_il_rev(void) {
    int_list* list_1 = cons(1, cons(2, cons(3, cons(4, NULL))));
    int_list* list_2 = cons(1, cons(2, cons(3, cons(4, NULL))));
    list_show(list_1);
    list_show(list_2);
    int_list* reversed_list_1 = il_rev(list_1);
    list_show(reversed_list_1);
    il_rev_d(&list_2);
    list_show(list_2);
    list_free(list_1);
    list_free(list_2);
    return;
}
コード例 #5
0
ファイル: test01.c プロジェクト: onyettr/c-llist
static int test04 ( void ) {
  list_t *p = NULL;
  node_t *n = NULL;
  int values[] = { 101, 201, 301, 401 };
  int dim = DIM(values);
  int i;
  
  printf("\ntest04 - search list, should fail\n" );

  n = list_search_value(p, 201);

  printf("\ntest04 - search list\n" );  
  p = list_create();

  for (i=0; i < dim; i++) {
    list_add ( p, values[i]);    
  }    
  list_show(p);

  for (i=0; i < dim; i++) {
    n = list_search_value(p, values[i]);
    if ( n != NULL ) {
      printf("Found value %d at %p\n", values[i], (void*)n);
    }
  }
  return 0;
}
コード例 #6
0
ファイル: string_2.c プロジェクト: Laukien/la-C
int main(void) {
	LIST *tokens = string_split("a number of words to be tokenized", " ");

	list_show(tokens);
	list_free(tokens);

	return EXIT_SUCCESS;
}
コード例 #7
0
ファイル: party.c プロジェクト: atrinik/atrinik
/** @copydoc widgetdata::draw_func */
static void widget_draw(widgetdata *widget)
{
    SDL_Rect box;
    size_t i;

    if (widget->redraw) {
        box.h = 0;
        box.w = widget->w;
        text_show(widget->surface, FONT_SERIF12, "Party", 0, 3, COLOR_HGOLD, TEXT_ALIGN_CENTER, &box);

        if (list_party) {
            list_party->surface = widget->surface;
            list_set_parent(list_party, widget->x, widget->y);
            list_show(list_party, 10, 23);
        }

        for (i = 0; i < BUTTON_NUM; i++) {
            buttons[i].surface = widget->surface;
            button_set_parent(&buttons[i], widget->x, widget->y);
        }

        /* Render the various buttons. */
        buttons[BUTTON_CLOSE].x = widget->w - TEXTURE_CLIENT("button_round")->w - 4;
        buttons[BUTTON_CLOSE].y = 4;
        button_show(&buttons[BUTTON_CLOSE], "X");

        buttons[BUTTON_HELP].x = widget->w - TEXTURE_CLIENT("button_round")->w * 2 - 4;
        buttons[BUTTON_HELP].y = 4;
        button_show(&buttons[BUTTON_HELP], "?");

        buttons[BUTTON_PARTIES].x = 244;
        buttons[BUTTON_PARTIES].y = 38;
        button_show(&buttons[BUTTON_PARTIES], list_contents == CMD_PARTY_LIST ? "[u]Parties[/u]" : "Parties");

        buttons[BUTTON_MEMBERS].x = buttons[BUTTON_FORM].x = 244;
        buttons[BUTTON_MEMBERS].y = buttons[BUTTON_FORM].y = 60;

        if (cpl.partyname[0] == '\0') {
            button_show(&buttons[BUTTON_FORM], "Form");
        } else {
            button_show(&buttons[BUTTON_MEMBERS], list_contents == CMD_PARTY_WHO ? "[u]Members[/u]" : "Members");
            buttons[BUTTON_LEAVE].x = buttons[BUTTON_PASSWORD].x = buttons[BUTTON_CHAT].x = 244;
            buttons[BUTTON_LEAVE].y = 82;
            buttons[BUTTON_PASSWORD].y = 104;
            buttons[BUTTON_CHAT].y = 126;
            button_show(&buttons[BUTTON_LEAVE], "Leave");
            button_show(&buttons[BUTTON_PASSWORD], "Password");
            button_show(&buttons[BUTTON_CHAT], "Chat");
        }
    }
}
コード例 #8
0
ファイル: skills.c プロジェクト: liwcezar/atrinik
/** @copydoc widgetdata::draw_func */
static void widget_draw(widgetdata *widget)
{
    SDL_Rect box;
    size_t i;

    /* Create the skill list. */
    if (!list_skills) {
        list_skills = list_create(5, 4, 8);
        list_skills->post_column_func = list_post_column;
        list_skills->row_color_func = list_row_color;
        list_skills->row_selected_func = NULL;
        list_skills->row_highlight_func = NULL;
        list_skills->surface = widget->surface;
        list_skills->row_height_adjust = INVENTORY_ICON_SIZE;
        list_set_font(list_skills, NULL);
        list_scrollbar_enable(list_skills);
        list_set_column(list_skills, 0, INVENTORY_ICON_SIZE, 0, NULL, -1);
        list_set_column(list_skills, 1, INVENTORY_ICON_SIZE, 0, NULL, -1);
        list_set_column(list_skills, 2, INVENTORY_ICON_SIZE, 0, NULL, -1);
        list_set_column(list_skills, 3, INVENTORY_ICON_SIZE, 0, NULL, -1);
        skill_list_reload();

        for (i = 0; i < BUTTON_NUM; i++) {
            button_create(&buttons[i]);
            buttons[i].texture = texture_get(TEXTURE_TYPE_CLIENT, "button_round");
            buttons[i].texture_pressed = texture_get(TEXTURE_TYPE_CLIENT, "button_round_down");
            buttons[i].texture_over = texture_get(TEXTURE_TYPE_CLIENT, "button_round_over");
        }
    }

    if (widget->redraw) {
        box.h = 0;
        box.w = widget->w;
        text_show(widget->surface, FONT_SERIF12, "Skills", 0, 3, COLOR_HGOLD, TEXT_ALIGN_CENTER, &box);
        list_set_parent(list_skills, widget->x, widget->y);
        list_show(list_skills, 10, 2);

        for (i = 0; i < BUTTON_NUM; i++) {
            buttons[i].surface = widget->surface;
            button_set_parent(&buttons[i], widget->x, widget->y);
        }

        buttons[BUTTON_CLOSE].x = widget->w - texture_surface(buttons[BUTTON_CLOSE].texture)->w - 4;
        buttons[BUTTON_CLOSE].y = 4;
        button_show(&buttons[BUTTON_CLOSE], "X");

        buttons[BUTTON_HELP].x = widget->w - texture_surface(buttons[BUTTON_HELP].texture)->w * 2 - 4;
        buttons[BUTTON_HELP].y = 4;
        button_show(&buttons[BUTTON_HELP], "?");
    }
}
コード例 #9
0
ファイル: directory_1.c プロジェクト: Laukien/la-C
int main(void) {
	LIST *list;
#ifdef SYSTEM_OS_TYPE_WINDOWS
	list = directory_list("C:\\WINDOWS", TRUE);
#else
	list = directory_list("/etc", TRUE);
#endif

	list_show(list);

	list_free(list);

	return 0;
}
コード例 #10
0
ファイル: test01.c プロジェクト: onyettr/c-llist
static int test01 ( void ) {
  list_t *p = NULL;

  printf("\ntest01 - create list\n" );

  p = list_create();

  printf("[%p] List created\n", (void*)p);
  list_show(p);

  list_delete(p);

  return 0;
}
コード例 #11
0
ファイル: main.c プロジェクト: williamsand/gitclone
void *bmpshow(void *arg)
{
	printf("enter bmpshow\n");
	
	printf("flag_bmp =%d\n",flag);
	int lcd_fd;
	lcd_fd= open("/dev/fb0", O_RDWR);
	if(lcd_fd<0)
	{
		printf(" open LCD Failed!\n");
		return  (void*)-1;
	}
	list_show(lcd_fd, flag);
	pthread_exit("bmp show is done");
	close(lcd_fd);
	
}
コード例 #12
0
/*-------------------------test our API---------------------------------*/
int main()
{
    struct node *p_head = init_list();
    int array[ARRAY_SIZE] = {1,2,3,4,5,6,7,8,9,10};

    int i = 0;
    for(i = 0; i < ARRAY_SIZE; i++)
    {
        if(list_insert(p_head, array[i]) < 0)
        {
            goto failed;
        }
    }

    list_show(p_head);
failed:
    release_list(p_head);
    return 0;
}
コード例 #13
0
ファイル: menu.c プロジェクト: pennwin2014/purchase_machine
static void easy_menu_loop(menu_item_t* menu, char* desc)
{
    list_dst* menu_ptr;
    menu_ptr = list_init();
    if (NULL == menu_ptr)
    {
        error_exit(3, "不能创建菜单控件");
    }
    list_props_set(menu_ptr , list_menu_property);
    int menu_count;
    for (menu_count = 0;; ++menu_count)
    {
        if (NULL == menu[menu_count].menu_desc)
            break;
        list_item_add(menu_ptr, menu[menu_count].menu_desc);
    }

    int32 ret;
    dis_mod_set(MAIN_DISP, INPUT_HZ_FONT, INPUT_ASC_FONT);
    while (1)
    {
        CLEAR_SCREEN;
        printf_str(MAIN_DISP, DISP_X_COOR, DISP_Y_COOR, ">", 1);
        printf_str(MAIN_DISP, DISP_X_COOR + 9, DISP_Y_COOR, desc, 1);
        line(MAIN_DISP , DISP_X_COOR, DISP_X_COOR + 28, DISP_X_COOR + 140, DISP_X_COOR + 28, 1);
        line(MAIN_DISP , DISP_X_COOR, DISP_X_COOR + 30, DISP_X_COOR + 140, DISP_X_COOR + 30, 1);
        list_show(MAIN_DISP, menu_ptr);
        lcd_160_upd();

        ret = list_key_manege(MAIN_DISP, menu_ptr, lcd_160_upd);
        if (ret < 0)
        {
            list_exit(menu_ptr) ;
            return ;
        }
        if (ret < menu_count)
        {
            menu[ret].func();
            dis_mod_set(MAIN_DISP, INPUT_HZ_FONT, INPUT_ASC_FONT);
        }
    }

}
コード例 #14
0
ファイル: atom.c プロジェクト: shouya/clisp
void atom_show(const Atom* atom, char** str) {
  char* buf = calloc(MAX_SHOW_BUFFER_SIZE, sizeof(char));
  switch (atom->type) {
  case ATOM_TYPE_UNKNOWN:
    break;
  case ATOM_TYPE_INT: {
    snprintf(buf, MAX_SHOW_BUFFER_SIZE, "%+ld", *atom->i32);
  } break;
  case ATOM_TYPE_UINT: {
    snprintf(buf, MAX_SHOW_BUFFER_SIZE, "%lu", *atom->ui32);
  } break;
  case ATOM_TYPE_BOOLEAN: {
    snprintf(buf, MAX_SHOW_BUFFER_SIZE, "%s",   \
             *atom->boolean ? "T" : "NIL");
  } break;
  case ATOM_TYPE_STRING: {
    snprintf(buf, MAX_SHOW_BUFFER_SIZE, "\"%s\"", atom->string);
  } break;
  case ATOM_TYPE_FUNCTION: {
    snprintf(buf, MAX_SHOW_BUFFER_SIZE, "FUNCTION(%p)", atom->function);
  } break;
  case ATOM_TYPE_LIST: {
    char* lst_shw;
    list_show(atom->list, &lst_shw);
    strcpy(buf, lst_shw);
    free(lst_shw);
  } break;
  case ATOM_TYPE_TOKEN: {
    snprintf(buf, MAX_SHOW_BUFFER_SIZE, "TOKEN(%s)", atom->token);
  } break;

  default:
    ;
  }

  
  *str = malloc(sizeof(char) * (strlen(buf)+1));
  strcpy(*str, buf);

  free(buf);
  return;
}
コード例 #15
0
ファイル: ls2.c プロジェクト: yangmiemie/books
void do_ls( char dirname[] )
/*
 *  list files in directory called dirname
 */
{
  DIR   *dir_ptr;   /* the directory */
  struct dirent *direntp;   /* each entry  */

  list_init();

  if ( ( dir_ptr = opendir( dirname ) ) == NULL )
    fatal("cannot open ", dirname);
  else
  {
    while ( ( direntp = readdir( dir_ptr ) ) != NULL )
      list_append( direntp->d_name );
    closedir(dir_ptr);
  }

  list_show();
  list_finish();
}
コード例 #16
0
ファイル: test01.c プロジェクト: onyettr/c-llist
static int test02 ( void ) {
  list_t *p = NULL;

  printf("\ntest02 - create list and add\n" );

  p = list_create();
  printf("[%p] list created\n", (void*)p);

  list_add ( p, 101);
  list_add ( p, 201);
  list_add ( p, 301);
  list_add ( p, 401);
  list_add ( p, 501);
  list_add ( p, 601);
  list_add ( p, 701);
  list_add ( p, 801);
  list_add ( p, 901);    
  
  list_show(p);
  list_delete(p);

  return 0;
}
コード例 #17
0
ファイル: intro.c プロジェクト: liwcezar/atrinik
/**
 * Show the main GUI after starting the client -- servers list, chat box,
 * connecting to server, etc.
 */
void intro_show(void)
{
    SDL_Surface *texture;
    int x, y;
    size_t server_count;
    server_struct *node;
    char buf[MAX_BUF];
    SDL_Rect box;

    sound_start_bg_music("intro.ogg", setting_get_int(OPT_CAT_SOUND, OPT_VOLUME_MUSIC), -1);

    texture = TEXTURE_CLIENT("intro");

    /* Background */
    surface_show(ScreenSurface, 0, 0, NULL, texture);
    textwin_show(ScreenSurface, texture->w, 1, ScreenSurface->w - texture->w - 2, ScreenSurface->h - 3);

    /* Calculate whether to show the eyes or not. Blinks every
     * EYES_BLINK_TIME ticks, then waits EYES_BLINK_DELAY ticks until
     * showing the eyes again. */
    if (SDL_GetTicks() - eyes_blink_ticks >= (eyes_draw ? EYES_BLINK_TIME : EYES_BLINK_DELAY)) {
        eyes_blink_ticks = SDL_GetTicks();
        eyes_draw++;
    }

    if (eyes_draw) {
        SDL_Rect src_box;

        src_box.x = 0;
        src_box.y = eyes_draw - 1;
        src_box.w = TEXTURE_CLIENT("eyes")->w;
        src_box.h = TEXTURE_CLIENT("eyes")->h;
        surface_show(ScreenSurface, texture->w - 90, 310 + src_box.y, &src_box, TEXTURE_CLIENT("eyes"));

        if (eyes_draw > 1) {
            eyes_draw++;

            if (eyes_draw > src_box.h) {
                eyes_draw = 1;
            }
        }
    }

    texture = TEXTURE_CLIENT("servers_bg");
    x = 15;
    y = ScreenSurface->h - texture->h - 5;
    surface_show(ScreenSurface, x, y, NULL, texture);

    server_count = server_get_count();

    /* Create the buttons. */
    if (!list_servers) {
        button_create(&button_play);
        button_create(&button_refresh);
        button_create(&button_server);
        button_create(&button_settings);
        button_create(&button_update);
        button_create(&button_help);
        button_create(&button_credits);
        button_create(&button_quit);
    }

    /* List doesn't exist or the count changed? Create new list. */
    if (!list_servers || last_server_count != server_count) {
        size_t i;

        /* Remove it if it exists already. */
        if (list_servers) {
            list_remove(list_servers);
        }

        /* Create the servers list. */
        list_servers = list_create(11, 3, 8);
        list_servers->handle_enter_func = list_handle_enter;
        list_servers->handle_esc_func = list_handle_esc;
        list_servers->text_color_hook = list_text_color;
        list_scrollbar_enable(list_servers);
        list_set_column(list_servers, 0, 295, 7, "Server", -1);
        list_set_column(list_servers, 1, 50, 9, "Port", 1);
        list_set_column(list_servers, 2, 46, 7, "Players", 1);

        /* Add the servers to the list. */
        for (i = 0; i < server_count; i++) {
            node = server_get_id(i);

            list_add(list_servers, i, 0, node->name);
            snprintf(VS(buf),
                     "%d",
                     node->port_crypto == -1 ? node->port : node->port_crypto);
            list_add(list_servers, i, 1, buf);

            if (node->player >= 0) {
                snprintf(buf, sizeof(buf), "%d", node->player);
            } else {
                strcpy(buf, "-");
            }

            list_add(list_servers, i, 2, buf);
        }

        /* Store the new count. */
        last_server_count = server_count;
    }

    /* Actually draw the list. */
    list_show(list_servers, x + 12, y + 8);
    node = server_get_id(list_servers->row_selected - 1);

    /* Do we have any selected server? If so, show its version and
     * description. */
    if (node) {
        snprintf(buf, sizeof(buf), "Version: %s", node->version);
        text_show_shadow(ScreenSurface, FONT_ARIAL10, buf, x + 13, y + 185, COLOR_HGOLD, COLOR_BLACK, 0, NULL);

        box.w = 410;
        box.h = 48;
        text_show(ScreenSurface, FONT_ARIAL10, node->desc, x + 13, y + 197, COLOR_WHITE, TEXT_WORD_WRAP | TEXT_MARKUP, &box);
    }

    /* Show whether we are connecting to the metaserver or not. */
    if (ms_connecting(-1)) {
        text_show_shadow(ScreenSurface, FONT_ARIAL10, "Connecting to metaserver, please wait...", x + 105, y + 8, COLOR_HGOLD, COLOR_BLACK, 0, NULL);
    } else {
        text_show_shadow(ScreenSurface, FONT_ARIAL10, "Select a secure server.", x + 196, y + 8, COLOR_GREEN, COLOR_BLACK, 0, NULL);
    }

    texture = TEXTURE_CLIENT("servers_bg_over");
    surface_show(ScreenSurface, x, y, NULL, texture);

    x += texture->w + 20;
    texture = TEXTURE_CLIENT("news_bg");
    surface_show(ScreenSurface, x, y, NULL, texture);

    box.w = texture->w;
    box.h = 0;
    text_show_shadow(ScreenSurface, FONT_SERIF12, "Game News", x, y + 10, COLOR_HGOLD, COLOR_BLACK, TEXT_ALIGN_CENTER, &box);

    /* No list yet, make one and start downloading the data. */
    if (!list_news) {
        /* Start downloading. */
        news_request = curl_request_create(clioption_settings.game_news_url,
                                           CURL_PKEY_TRUST_ULTIMATE);
        curl_request_start_get(news_request);

        list_news = list_create(18, 1, 8);
        list_news->focus = 0;
        list_news->handle_enter_func = list_handle_enter;
        list_news->handle_esc_func = list_handle_esc;
        list_set_column(list_news, 0, 150, 7, NULL, -1);
        list_set_font(list_news, FONT_ARIAL10);
    }

    /* Download in progress? */
    if (news_request != NULL) {
        curl_state_t state = curl_request_get_state(news_request);
        /* Finished downloading, parse the data. */
        if (state == CURL_STATE_OK) {
            char *body = curl_request_get_body(news_request, NULL);
            if (body != NULL) {
                uint32_t i = 0;
                char *cp = strtok(body, "\n");
                while (cp != NULL) {
                    list_add(list_news, i++, 0, cp);
                    cp = strtok(NULL, "\n");
                }
            }
        }

        /* Finished downloading or there was an error: clean up in either
         * case. */
        if (state != CURL_STATE_INPROGRESS) {
            curl_request_free(news_request);
            news_request = NULL;
        }
    }

    /* Show the news list. */
    list_show(list_news, x + 13, y + 10);

    button_play.x = button_refresh.x = button_server.x = button_settings.x = button_update.x = button_help.x = button_credits.x = button_quit.x = 489;
    y += 2;

    button_play.y = y + 10;
    button_show(&button_play, "Play");

    button_refresh.y = y + 35;
    button_show(&button_refresh, "Refresh");

    button_server.y = y + 60;
    button_show(&button_server, "Server");

    button_settings.y = y + 86;
    button_show(&button_settings, "Settings");

    button_update.y = y + 110;
    button_show(&button_update, "Update");

    button_help.y = y + 135;
    button_show(&button_help, "Help");

    button_credits.y = y + 160;
    button_show(&button_credits, "Credits");

    button_quit.y = y + 224;
    button_show(&button_quit, "Quit");

    if (clioption_settings.connect[0] && cpl.state < ST_STARTCONNECT) {
        size_t i;

        for (i = 0; i < server_count; i++) {
            node = server_get_id(i);

            if (strcasecmp(clioption_settings.connect[0], node->name) == 0) {
                list_servers->row_selected = i + 1;

                if (!clioption_settings.reconnect) {
                    efree(clioption_settings.connect[0]);
                    clioption_settings.connect[0] = NULL;
                }

                event_push_key_once(SDLK_RETURN, 0);
                break;
            }
        }
    }
}
コード例 #18
0
ファイル: test_add.c プロジェクト: onyettr/c-llist
int test_add ( void )
{
  list_t *addTest;
  list_t *emplaceTest;
  
  // Sign on
  printf("**** Linked List Test - add\n");

  /*
   * create a new list
   */ 
  addTest = list_create();  
  printf("\tTest01a - add single element\n");
  list_add_element(addTest,10);
  list_show(addTest);  

  printf("\tTest01b - add more   elements\n");
  list_add_element(addTest,20);
  list_add_element(addTest,30);
  list_add_element(addTest,40);
  list_add_element(addTest,50);
  list_add_element(addTest,60);  
  list_show(addTest);
  printf("\tTest01b - size of list %d\n", list_size(addTest));

  printf("\tTest02a - add to front\n");  
  list_push_front(addTest, 111);
  list_show(addTest);
  printf("\tTest02a - size of list %d\n", list_size(addTest));

  printf("\tTest03a - add to back\n");;  
  list_push_back(addTest, 222);
  list_show(addTest);
  printf("\tTest03a - size of list %d\n", list_size(addTest));

  emplaceTest = list_create();
  
  printf("\tTest04a - emplace\n");
  list_add_element(emplaceTest, 1);
  list_add_element(emplaceTest, 2);
  list_add_element(emplaceTest, 3);
  list_add_element(emplaceTest, 4);  
  list_show(emplaceTest);
  printf("\tTest04a - size of list 4 = %d\n", list_size(emplaceTest));

  printf("\tTest05a - emplace at position 2\n");    
  list_add_position(emplaceTest, 2, 5);
  list_show(emplaceTest);  
  printf("\tTest05a - size of list %d\n", list_size(emplaceTest));

  printf("\tTest05b get at position 2 (5) %d\n", list_get_position(emplaceTest, 2));
  
  printf("\tTest05c - emplace at position 0\n");    
  list_add_position(emplaceTest, 0, 555);
  list_show(emplaceTest);  
  printf("\tTest05c - size of list %d\n", list_size(emplaceTest));
  printf("\tTest05c get at position 2 (555) %d\n", list_get_position(emplaceTest, 0));

  printf("\tTest05d - emplace at position size+1\n");    
  list_add_position(emplaceTest, (list_size(emplaceTest)+1), 100);
  
  printf("**** Linked List Test - add Ends\n");
  
  return 0;
}
コード例 #19
0
ファイル: mplayer.c プロジェクト: atrinik/atrinik
/** @copydoc widgetdata::draw_func */
static void widget_draw(widgetdata *widget)
{
    SDL_Rect box;
    char buf[HUGE_BUF];
    size_t i;

    /* The list doesn't exist yet, create it. */
    if (!list_mplayer) {
        char version[MAX_BUF];

        /* Create the list and set up settings. */
        list_mplayer = list_create(12, 1, 8);
        list_mplayer->handle_enter_func = list_handle_enter;
        list_mplayer->text_color_hook = list_text_color_hook;
        list_mplayer->surface = widget->surface;
        list_scrollbar_enable(list_mplayer);
        list_set_column(list_mplayer, 0, 130, 7, NULL, -1);
        list_set_font(list_mplayer, FONT_ARIAL10);

        /* Add default media directory songs. */
        get_data_dir_file(buf, sizeof(buf), DIRECTORY_MEDIA);
        mplayer_list_init(list_mplayer, buf, 0);

        /* Now add custom ones, but ignore duplicates. */
        snprintf(buf, sizeof(buf), "%s/.atrinik/%s/"DIRECTORY_MEDIA, get_config_dir(), package_get_version_partial(version, sizeof(version)));
        mplayer_list_init(list_mplayer, buf, 1);

        /* If we added any, sort the list alphabetically and add an entry
         * to disable background music. */
        if (list_mplayer->rows) {
            FILE *fp;

            /* Allocate the blacklist. + 1 is for the last entry added
             * further down. It is not actually used by the blacklist as
             * it's not possible to toggle it on/off using the button, but
             * it simplifies other logic checks. */
            shuffle_blacklist = ecalloc(1, sizeof(*shuffle_blacklist) * (list_mplayer->rows + 1));

            /* Sort the list. */
            list_sort(list_mplayer, LIST_SORT_ALPHA);

            /* Read the blacklist file contents. */
            fp = path_fopen(FILE_MPLAYER_BLACKLIST, "r");

            if (fp) {
                size_t row;

                while (fgets(buf, sizeof(buf) - 1, fp)) {
                    for (row = 0; row < list_mplayer->rows; row++) {
                        if (!strncmp(buf, list_mplayer->text[row][0], strlen(buf) - 1)) {
                            shuffle_blacklist[row] = 1;
                            break;
                        }
                    }
                }

                fclose(fp);
            }

            list_add(list_mplayer, list_mplayer->rows, 0, "Disable music");
        }

        scrollbar_create(&scrollbar_progress, 130, 11, &scrollbar_progress_info.scroll_offset, &scrollbar_progress_info.num_lines, 1);
        scrollbar_progress.redraw = &scrollbar_progress_info.redraw;
    }

    if (widget->redraw) {
        const char *bg_music;

        box.h = 0;
        box.w = widget->w;
        text_show(widget->surface, FONT_SERIF12, "Music Player", 0, 3, COLOR_HGOLD, TEXT_ALIGN_CENTER, &box);
        list_set_parent(list_mplayer, widget->x, widget->y);
        list_show(list_mplayer, 10, 2);
        box.w /= 2;
        text_show(widget->surface, FONT_SANS10, "Currently playing:", widget->w / 2, 22, COLOR_WHITE, TEXT_ALIGN_CENTER, &box);

        bg_music = sound_get_bg_music_basename();
        box.h = 0;
        box.w = widget->w / 2;

        /* Store the background music file name in temporary buffer and
         * make sure it won't overflow by truncating it if necessary. */
        if (bg_music) {
            strncpy(buf, bg_music, sizeof(buf) - 1);
            buf[sizeof(buf) - 1] = '\0';
            text_truncate_overflow(FONT_SANS11, buf, 150);
        }

        /* Show the music that is being played. */
        text_show(widget->surface, FONT_SANS11, bg_music ? buf : "No music", widget->w / 2 - 5, 34, COLOR_HGOLD, TEXT_ALIGN_CENTER, &box);

        scrollbar_progress.px = widget->x;
        scrollbar_progress.py = widget->y;
        scrollbar_show(&scrollbar_progress, widget->surface, 170, 50);

        box.h = 120;
        box.w -= 6 * 2;
        text_show(widget->surface, FONT_ARIAL10, "You can use the music player to play your favorite tunes from the game, or play them all one-by-one in random order (shuffle).\n\nNote that if you use the music player, in-game areas won't change your music until you click [b]Stop[/b].", widget->w / 2 + 6, 62, COLOR_WHITE, TEXT_WORD_WRAP | TEXT_MARKUP, &box);

        for (i = 0; i < BUTTON_NUM; i++) {
            buttons[i].surface = widget->surface;
            button_set_parent(&buttons[i], widget->x, widget->y);
        }

        buttons[BUTTON_PLAY].x = 10;
        buttons[BUTTON_PLAY].y = widget->h - TEXTURE_CLIENT("button")->h - 4;
        button_show(&buttons[BUTTON_PLAY], sound_map_background(-1) ? "Stop" : "Play");

        buttons[BUTTON_SHUFFLE].x = 10 + TEXTURE_CLIENT("button")->w + 5;
        buttons[BUTTON_SHUFFLE].y = widget->h - TEXTURE_CLIENT("button")->h - 4;
        buttons[BUTTON_SHUFFLE].pressed_forced = shuffle;
        button_show(&buttons[BUTTON_SHUFFLE], "Shuffle");

        buttons[BUTTON_BLACKLIST].x = 10 + TEXTURE_CLIENT("button")->w * 2 + 5 * 2;
        buttons[BUTTON_BLACKLIST].y = widget->h - TEXTURE_CLIENT("button_round")->h - 5;
        buttons[BUTTON_BLACKLIST].disabled = list_mplayer->row_selected == list_mplayer->rows;
        button_show(&buttons[BUTTON_BLACKLIST], mplayer_blacklisted(list_mplayer) ? "+" : "-");

        /* Show close button. */
        buttons[BUTTON_CLOSE].x = widget->w - TEXTURE_CLIENT("button_round")->w - 4;
        buttons[BUTTON_CLOSE].y = 4;
        button_show(&buttons[BUTTON_CLOSE], "X");

        /* Show help button. */
        buttons[BUTTON_HELP].x = widget->w - TEXTURE_CLIENT("button_round")->w * 2 - 4;
        buttons[BUTTON_HELP].y = 4;
        button_show(&buttons[BUTTON_HELP], "?");
    }
}