void input::read( )
{
    std::string item_temp;
    if( !fin )
        throw( "Unable to open input." );
    getline( fin, item_temp );
    if( item_temp != "MERGER" )
        throw( "You might be using an incorrect "
	       "file as the input." );
    std::cout << item_temp << std::endl;
    
    do{
        getline( fin, item_temp );
        std::cout << item_temp;
    }while( item_temp[ 0 ] == '#' );
    std::cout << '\n';
    
    while( !fin.eof( ) )
    {
        getline( fin, item_temp );
        std::cout << item_temp << std::endl;
        if( item_temp == "Init" )
            break;
    }
    get_items( );
    return ;
}
Exemple #2
0
/**
 * Performs code-generation for a for statement node
 */
int generate_for(Pool *pool, FILE *out, AstFor *p)
{
  ListNode *items = get_items(p->outline);
  int need_comma = 0;

  /* Process the list: */
  if (p->reverse) {
    /* Warning: O(n^2) reversing algorithm */
    ListNode *item, *last = 0;
    while (items != last) {
      item = items;
      while (item->next != last)
        item = item->next;
      last = item;

      CHECK(generate_for_item(pool, out, p, item, &need_comma));
    }
  } else {
    ListNode *item;
    for (item = items; item; item = item->next)
      CHECK(generate_for_item(pool, out, p, item, &need_comma));
  }

  return 1;
}
		TITANIUM_PROPERTY_GETTER(ListSection, items)
		{
			std::vector<JSValue> js_items;
			for (auto & item : get_items()) {
				js_items.push_back(ListDataItem_to_js(get_context(), item));
			}
			return get_context().CreateArray(js_items);
		}
Exemple #4
0
void oskar_dir_items(const char* dir_path, const char* wildcard,
        int match_files, int match_dirs, int* num_items, char*** items)
{
    int i = 0, old_num_items = *num_items;

    /* Count the number of items. */
    *num_items = get_items(dir_path, wildcard, match_files, match_dirs, 0, 0);

    /* Get the sorted list of names if required. */
    if (items)
    {
        for (i = *num_items; i < old_num_items; ++i) free((*items)[i]);
        *items = (char**) realloc(*items, *num_items * sizeof(char**));
        for (i = old_num_items; i < *num_items; ++i) (*items)[i] = 0;
        (void) get_items(dir_path, wildcard, match_files, match_dirs,
                *num_items, *items);
        qsort(*items, *num_items, sizeof(char*), name_cmp);
    }
}
nc_color vehicle::part_color( const int p, const bool exact ) const
{
    if( p < 0 || p >= ( int )parts.size() ) {
        return c_black;
    }

    nc_color col;

    int parm = -1;

    //If armoring is present and the option is set, it colors the visible part
    if( get_option<bool>( "VEHICLE_ARMOR_COLOR" ) ) {
        parm = part_with_feature( p, VPFLAG_ARMOR, false );
    }

    if( parm >= 0 ) {
        col = part_info( parm ).color;
    } else {
        const int displayed_part = exact ? p : part_displayed_at( parts[p].mount.x, parts[p].mount.y );

        if( displayed_part < 0 || displayed_part >= ( int )parts.size() ) {
            return c_black;
        }
        if( parts[displayed_part].blood > 200 ) {
            col = c_red;
        } else if( parts[displayed_part].blood > 0 ) {
            col = c_light_red;
        } else if( parts[displayed_part].is_broken() ) {
            col = part_info( displayed_part ).color_broken;
        } else {
            col = part_info( displayed_part ).color;
        }

    }

    if( exact ) {
        return col;
    }

    // curtains turn windshields gray
    int curtains = part_with_feature( p, VPFLAG_CURTAIN, false );
    if( curtains >= 0 ) {
        if( part_with_feature( p, VPFLAG_WINDOW, true ) >= 0 && !parts[curtains].open ) {
            col = part_info( curtains ).color;
        }
    }

    //Invert colors for cargo parts with stuff in them
    int cargo_part = part_with_feature( p, VPFLAG_CARGO );
    if( cargo_part > 0 && !get_items( cargo_part ).empty() ) {
        return invert_color( col );
    } else {
        return col;
    }
}
// Get the item from the selection list in CLIENT_DATA
static string get_item(Widget, XtPointer client_data, XtPointer)
{
    StringArray itemids;
    Widget items = Widget(client_data);
    if (items != 0)
	get_items(items, itemids);

    if (itemids.size() == 1)
	return itemids[0];

    return "";
}
//Check on a queue and do something specific...
//If qtype == 0, directories, 
//qtype ==1, files
void queue_checker(queue_t * queue, 
unsigned int num_items, 
unsigned int qtype, 
queue_t * other_queue, 
unsigned int * num_found, 
char * to_find)
{
	//Alright, let's check if there something in here
	if(queue_empty(queue))
	{
		//Empty, done here.
		return;
	}
	else
	{
		//Queue not empty
		//Try to pull off some items
		
		unsigned int items_got = 0;
		queue_t * tmp_items = get_items(queue, num_items, &items_got);
		
		//Did we get some items?
		if(items_got > 0)
		{
			//Do the specfic task for these items, with specific args
			if(qtype == 0)
			{
				//Dirs
				//printf("%d got dir items\n", items_got);
				process_dirs(tmp_items, other_queue, queue);
			}
			else
			{
				//Files
				//printf("%d got file items\n", items_got);
				process_files(tmp_items, num_found, to_find);
			}
		}
		else
		{
			//No items gotten, done here
			return;
		}
	}
}
static void
update_text (study_screen_info *info)
{
  set_progress ((double)info->current / (double)get_item_count ());

  char *print_me = malloc (sizeof (char) * 25);
  char *wordish = number_to_wordish(info->current);
  char **items;

  items = get_items ();


  sprintf(print_me, "%s%s%s", "The ", wordish, " item is:");
  gtk_label_set_text (GTK_LABEL (info->instruction_label), print_me);

  gtk_label_set_text (GTK_LABEL (info->text), items[info->current-1]);
  free (print_me);
  free (wordish);
}
Exemple #9
0
/* Generator function for command completion.  STATE lets us know whether
 * to start from scratch; without any state (i.e. STATE == 0), then we
 * start at the top of the list.
 */
static char *item_generator(const char *text, int state,
                            const char *item, cpl_item_t type)
{
  static int list_index, len;
  char *name;

  /* If this is a new word to complete, initialize now.  This includes
   * saving the length of TEXT for efficiency, and initializing the index
   *  variable to 0.
   */
  if (!state)
  {
     list_index = 0;
     len = strlen(text);
     switch(type) {
     case ITEM_ARG:
        get_items(item);
        break;
     case ITEM_HELP:
        get_arguments(item);
        break;
     }
  }

  /* Return the next name which partially matches from the command list. */
  while (items && list_index < items->list.size())
  {
     name = (char *)items->list[list_index];
     list_index++;

     if (bstrncmp(name, text, len)) {
        char *ret = (char *) actuallymalloc(strlen(name)+1);
        strcpy(ret, name);
        return ret;
     }
  }

  /* If no names matched, then return NULL. */
  return ((char *)NULL);
}
/*
	Function: get_dimension
	------------------------
	Traverses a given file and finds the total number of users and items
	for this source. The acquired number is stored in this given source
	structure. This method is used in the case that the hint line is not
	presented.

	Parameter:
	file - source file
	src - source structure
*/
void get_dimension(FILE *file, Source *src)
{
	int user_num = 0;
	char chars[MAX_CHARS];
	char *token = NULL;
	char **seg = (char**)malloc(3 * sizeof(*seg));
	struct Item_Tree *item_tree = initialize();
	Item *items = NULL;
	
	while (fgets(chars, MAX_CHARS, file) != NULL) {
		// Gets all segments
		seg[0] = strtok_s(chars, _SEP, &token);
		if (seg[0] != NULL) {
			seg[1] = strtok_s(NULL, _SEP, &token);

			if (seg[1] != NULL) {
				seg[2] = strtok_s(NULL, _SEP, &token);

				if (seg[2] != NULL) {
					// Handles item segment
					input_item(item_tree, seg[0]);
					// Handles user IDs
					long temp = (long) find_number(seg[1]);
					if (temp > user_num) {
						user_num = temp;
					}
				}
			}
		}
	}

	free(seg);

	// Retrieves all item names and free its item tree
	get_items(item_tree, &items);
	src->items = items;
	// Sets user numbers
	src->N = user_num;
}
Exemple #11
0
	/// Range over all items by default
	std::vector<std::pair<std::shared_ptr<const wml_menu_item>, std::string> > get_items(const map_location& hex, game_data & gamedata, filter_context & fc, unit_map & units) const {
		return get_items(hex, gamedata, fc, units, begin(), end());
	}
Exemple #12
0
int main(int argc, char** argv){
    
    bool result=input(argc, argv);
    get_items(cfgs);
    print_items();
}
Exemple #13
0
void process_keys() {
	if (game.cooldown <= 0) {
		scanKeys();
		u32 keys = keysHeld();
		u32 down = keysDown();
		touchPosition touch = touchReadXY();

		if (down & KEY_START) {
			new_game();
			return;
		}

		if (down & KEY_SELECT) {
			test_map();

			torch.buf.scroll.x = game.player.x - 16;
			torch.buf.scroll.y = game.player.y - 12;
			torch.buf.bounded(torch.buf.scroll.x, torch.buf.scroll.y);
			torch.dirty_screen();
			torch.reset_luminance();

			return;
		}

		if (down & KEY_X) {
			inventory(); return;
		}
		if (down & KEY_L) {
			overview(); return;
		}

		if (down & KEY_TOUCH && touch.px != 0 && touch.py != 0) {
			if (!(keys & KEY_R) && game.player.projectile) {
				game.player.chuck(torch.buf.scroll.x + touch.px/8,
													torch.buf.scroll.y + touch.py/8);
			}
			return;
		}

		if (down & KEY_R) {
			printf("Saving... ");
			fflush(stdout);
			game.save("blah.adrift");
			printf("done\n");
			printf("Loading... ");
			fflush(stdout);
			game.load("blah.adrift");
			printf("done\n");
		}

		if (keys & KEY_Y) {
			if (get_items()) return;
		}

		DIRECTION dir = 0;
		if (keys & KEY_RIGHT)
			dir |= D_EAST;
		else if (keys & KEY_LEFT)
			dir |= D_WEST;
		if (keys & KEY_DOWN)
			dir |= D_SOUTH;
		else if (keys & KEY_UP)
			dir |= D_NORTH;

		if (dir) {
			game.player.moveDir(dir, keys & KEY_B);
			return;
		}

		if (down & KEY_A) {
			seek_and_destroy();
			if (!game.player.target) {
				// no monsters in range
				for (int x = game.player.x-1; x <= game.player.x+1; x++) {
					for (int y = game.player.y-1; y <= game.player.y+1; y++) {
						Object *o = game.map.at(x,y)->objects.head();
						if (!o) continue;
						if (o->type == VENDING_MACHINE) {
							if (game.player.x == x+D_DX[o->orientation] && game.player.y == y+D_DY[o->orientation]) {
								iprintf("You kick the vending machine. ");
								if (o->quantity > 0 && rand4() < 5) {
									if (rand4() & 1) {
										iprintf("Clunk! A can rolls out.\n");
										addObject(game.player.x, game.player.y, CAN_OF_STEWED_BEEF);
									} else {
										iprintf("Clunk! A bottle rolls out.\n");
										addObject(game.player.x, game.player.y, BOTTLE_OF_WATER);
									}
									o->quantity--;
								} else {
									iprintf("Nothing happens.\n");
								}
								game.cooldown += 5;
							}
						}
					}
				}
			} else return;
		}
		if (keys & KEY_A) {
			seek_and_destroy(); return;
		}

	} else if (game.cooldown > 0)
		game.cooldown--;
}