コード例 #1
0
ファイル: index.c プロジェクト: edgar-pek/PerspicuOS
int
index_menu(PkgNodePtr root, PkgNodePtr top, PkgNodePtr plist, int *pos, int *scroll)
{
    struct ListPtrs lists;
    size_t maxname;
    int n, rval;
    int curr, max;
    PkgNodePtr kp;
    dialogMenuItem *nitems;
    Boolean hasPackages;
    WINDOW *w;
    
    lists.root = root;
    lists.top = top;
    lists.plist = plist;

    hasPackages = FALSE;
    nitems = NULL;
    n = maxname = 0;

    /* Figure out if this menu is full of "leaves" or "branches" */
    for (kp = top->kids; kp && kp->name; kp = kp->next) {
	size_t len;

	++n;
	if (kp->type == PACKAGE && plist) {
	    hasPackages = TRUE;
	    if ((len = strlen(kp->name)) > maxname)
		maxname = len;
	}
    }
    if (!n && plist) {
	msgConfirm("The %s menu is empty.", top->name);
	return DITEM_LEAVE_MENU;
    }

    w = savescr();
    while (1) {
	n = 0;
	curr = max = 0;
	use_helpline(NULL);
	use_helpfile(NULL);
	kp = top->kids;
	if (!hasPackages && plist) {
	    nitems = item_add(nitems, "OK", NULL, NULL, NULL, NULL, NULL, NULL, &curr, &max);
	    nitems = item_add(nitems, "Install", NULL, NULL, NULL, NULL, NULL, NULL, &curr, &max);
	}
	while (kp && kp->name) {
	    char buf[256];
	    IndexEntryPtr ie = kp->data;

	    /* Brutally adjust description to fit in menu */
	    if (kp->type == PACKAGE)
		snprintf(buf, sizeof buf, "[%s]", ie->path ? ie->path : "External vendor");
	    else
		SAFE_STRCPY(buf, kp->desc);
	    if (strlen(buf) > (_MAX_DESC - maxname))
		buf[_MAX_DESC - maxname] = '\0';
	    nitems = item_add(nitems, kp->name, buf, pkg_checked, 
			      pkg_fire, pkg_selected, kp, &lists, 
			      &curr, &max);
	    ++n;
	    kp = kp->next;
	}
	/* NULL delimiter so item_free() knows when to stop later */
	nitems = item_add(nitems, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 
			  &curr, &max);

recycle:
	dialog_clear_norefresh();
	if (hasPackages)
	    rval = dialog_checklist(top->name, top->desc, -1, -1, n > MAX_MENU ? MAX_MENU : n, -n, nitems, NULL);
	else
	    rval = dialog_menu(top->name, top->desc, -1, -1, n > MAX_MENU ? MAX_MENU : n, -n, nitems + (plist ? 2 : 0), (char *)plist, pos, scroll);
	if (rval == -1 && plist) {
	    static char *cp;
	    PkgNodePtr menu;

	    /* Search */
	    if ((cp = msgGetInput(cp, "Search by package name.  Please enter search string:")) != NULL) {
		PkgNodePtr p = index_search(top, cp, &menu);

		if (p) {
		    int pos, scroll;

		    /* These need to be set to point at the found item, actually.  Hmmm! */
		    pos = scroll = 0;
		    index_menu(root, menu, plist, &pos, &scroll);
		}
		else
		    msgConfirm("Search string: %s yielded no hits.", cp);
	    }
	    goto recycle;
	}
	items_free(nitems, &curr, &max);
	restorescr(w);
	return rval ? DITEM_FAILURE : DITEM_SUCCESS;
    }
}
コード例 #2
0
ファイル: mapgen.c プロジェクト: basilfx/u8g2
int map_read_line(const char **s)
{
  const char *id;
  
  if ( is_inside_proc != 0 )
  {
    if ( uglReadLine(s) == 0 )
      is_inside_proc = 0;
    return 1;
  }
  skip_space(s);
  
  if ( **s == '#' )		/* comment (hmm handled by skip_space) */
    return 1;

  if ( **s == '\0' )		/* empty line */
    return 1;
  
  if ( **s == ':' )
  {
    (*s)++;
    return map_read_row(s);
  }
  
  id = get_identifier(s);
  if ( strcmp(id, "tile") == 0 )
  {
     return map_read_tile(s, 0, -1);
  }
  else if ( strcmp(id, "thing") == 0 )
  {
     return map_read_tile(s, 1, -1);
  }
  else if ( strcmp(id, "itemkey") == 0 )
  {
    const char *id;
    int idx;
    id = get_identifier(s);
    idx = item_get_idx_by_name(id);
    if ( idx < 0 )
    {
      printf("code line %d, item '%s' unknown.\n", ugl_current_input_line, id);
    }
    else
    {
     return map_read_tile(s, 1, idx);
    }
  }
  else if ( strcmp(id, "item") == 0 )
  {
    const char *id;
    int idx;
    id = get_identifier(s);
    idx = item_get_idx_by_name(id);
    if ( idx >= 0 )
    {
      printf("code line %d, item '%s' already exists.\n", ugl_current_input_line, id);
    }
    else
    {
      if ( item_add(id) < 0 )
      {
	printf("code line %d, item '%s': Too many items.\n", ugl_current_input_line, id);
      }
      else
      {
	idx = item_get_idx_by_name(id);
	assert( idx >= 0 );
	item_list[idx].fg_tile = get_num(s);
      }
    }  
    
    return 1;
  }
  else if ( strcmp(id, "mapinit") == 0 )
  {
    map_init_code_pos = uglStartNamelessProc(0);
    is_inside_proc = 1;
    return 1;
  }  
  else if ( strcmp(id, "iteminit") == 0 )
  {
    const char *id;
    int idx;
    uint16_t code_pos;
    
    id = get_identifier(s);
    idx = item_get_idx_by_name(id);
    code_pos = uglStartNamelessProc(0);
    if ( idx < 0 )
    {
	printf("code line %d, item '%s' not found.\n", ugl_current_input_line, id);
    }
    else
    {
      item_list[idx].init_proc= code_pos;
    }    
    is_inside_proc = 1;
    return 1;
  }
  else if ( strcmp(id, "itemhit") == 0 )
  {
    const char *id;
    int idx;
    uint16_t code_pos;
    
    id = get_identifier(s);
    idx = item_get_idx_by_name(id);
    code_pos = uglStartNamelessProc(0);
    if ( idx < 0 )
    {
	printf("code line %d, item '%s' not found.\n", ugl_current_input_line, id);
    }
    else
    {
      item_list[idx].hit_proc= code_pos;
    }    
    is_inside_proc = 1;
    return 1;
  }
  else if ( strcmp(id, "itemstep") == 0 )
  {
    const char *id;
    int idx;
    uint16_t code_pos;
    
    id = get_identifier(s);
    idx = item_get_idx_by_name(id);
    code_pos = uglStartNamelessProc(0);
    if ( idx < 0 )
    {
	printf("code line %d, item '%s' not found.\n", ugl_current_input_line, id);
    }
    else
    {
      item_list[idx].step_proc= code_pos;
    }    
    is_inside_proc = 1;
    return 1;
  }
  else if ( strcmp(id, "map") == 0 )
  {
    is_inside_map = 1;

    return map_read_map_cmd(s);
  }
  else if ( strcmp(id, "endmap") == 0 )
  {
    /* write existing map: once a map has been read, transform it to the target */
    if ( map_width > 0 && map_height > 0 )
    {
      if ( map_all_tiles() )
      {
	char buf[128];
	write_map();
	write_item_onmap();
	sprintf(buf, "%s.tga", map_name);
	write_tga_map(buf);
	write_map_struct();
      }
    }
    is_inside_map = 0;
    return 1;
  }
  else
  {
    printf("code line %d, map line %d: unkown command '%s'\n", ugl_current_input_line, map_curr_line, id);
  }
  
  return 1;
}