Example #1
0
void
VirtioDevice::DumpFeatures(const char* title, uint32 features,
	const char* (*get_feature_name)(uint32))
{
	char features_string[512] = "";
	for (uint32 i = 0; i < 32; i++) {
		uint32 feature = features & (1 << i);
		if (feature == 0)
			continue;
		const char* name = virtio_get_feature_name(feature);
		if (name == NULL)
			name = get_feature_name(feature);
		if (name != NULL) {
			snprintf(features_string, sizeof(features_string), "%s[%s] ",
			features_string, name);
		}
	}
	TRACE("%s: %s\n", title, features_string);
}
Example #2
0
/*
 * Use the monster racial information to a format easily parsed by a spreadsheet.
 *
 * Original function by -EB- (probably), revisions by -LM- & JG.
 * Note: This function needs some updating as it is missing some fields.
 */
void write_f_info_txt(void)
{
	int i, j, bc, x;
	int dlen;

	char buf[1024];

	int fd;
	FILE *fff = NULL;

	cptr desc;

	feature_type *f_ptr;

	/* We allow 75 characters on the line (plus 2) */
	u16b line_length = 75;

	/* Build the filename */
	path_build(buf, 1024, ANGBAND_DIR_EDIT, "f_output.txt");

	/* Check for existing file */
	fd = fd_open(buf, O_RDONLY);

	/* Existing file */
	if (fd >= 0)
	{
		char out_val[160];

		/* Close the file */
		fd_close(fd);

		/* Build query */
		sprintf(out_val, "Replace existing file %s? ", buf);

		/* Ask */
		if (get_check(out_val)) fd = -1;
	}

	/* Open the non-existing file */
	if (fd < 0) fff = my_fopen(buf, "w");

	/* No output file - fail */
	if (!fff) return;

	/* Write a note */
	fprintf(fff, "# File: f_info.txt (autogenerated)\n\n");

	/* Read and print out all the features */
	for (i = 0; i < z_info->f_max; i++)
	{

		cptr color_name;

		int counter = 1;

		desc = NULL;

		/* Get the monster */
		f_ptr = &f_info[i];

		/* Ignore empty monsters */
		if (!strlen(f_name + f_ptr->name))
		{
			fprintf(fff, "## empty space (available for terrain) ##\n\n");
			continue;
		}

		/* Perform any translations */

		/* Write New/Number/Name */
		fprintf(fff, "N:%d:%d:%s\n", i, i, f_name + f_ptr->name);

		/* Write Mimic  */
		if (f_ptr->f_mimic > 0)
		{
			/*hack, switch to a new f_ptr- t outpit out the name*/
			f_ptr = &f_info[f_info[i].f_mimic];
			fprintf(fff, "M:%d:%s\n", i, f_name + f_ptr->name);
			/* Switch Back*/
			f_ptr = &f_info[i];
		}

		/* Write Edge  */
		if (f_ptr->f_edge > 0)
		{
			/*hack, switch to a new f_ptr- t outpit out the name*/
			f_ptr = &f_info[f_info[i].f_edge];
			fprintf(fff, "E:%d:%s\n", i, f_name + f_ptr->name);
			/* Switch Back*/
			f_ptr = &f_info[i];
		}

		/*get the color name*/
		color_name = get_ext_color_name(f_ptr->d_attr);

		/* Write G: line */
		fprintf(fff, "G:%d:%c:%s\n",i, f_ptr->d_char, color_name);

		if (f_ptr->f_edge > 0)
		{
			/*hack, switch to a new f_ptr- t outpit out the name*/
			f_ptr = &f_info[f_info[i].f_edge];
			desc = (f_name + f_ptr->name);
			/* Switch Back*/
			f_ptr = &f_info[i];

		}
		else desc = NULL;

		/* Write W: line */
		fprintf(fff, "W:%d:%d:%d:%d:%d:\n", i, f_ptr->f_level, f_ptr->f_rarity,
	    	f_ptr->priority, f_ptr->f_power);

		/* Write C: line */
		fprintf(fff, "C:%d:%d:%d:%d:%d:%d:%d:\n", i, f_ptr->dam_non_native, f_ptr->native_energy_move,
	   	 	f_ptr->non_native_energy_move, f_ptr->native_to_hit_adj,
			f_ptr->non_native_to_hit_adj, f_ptr->f_stealth_adj);


		/* Write X: line */
		fprintf(fff, "X:%d:%d:%d:%d:%d:%d:%d:%d:\n", i, f_ptr->f_level, f_ptr->f_rarity,
	   	 	f_ptr->f_power, f_ptr->x_damage, f_ptr->x_gf_type,
			f_ptr->x_timeout_set, f_ptr->x_timeout_rand);


		/* Get the flags, store flag text in a format easily parsed by a
		 * database, but pretty much illegible to a person.
		 */
		dump_flags(fff, f_ptr->f_flags1, 1, i);
		dump_flags(fff, f_ptr->f_flags2, 2, i);
		dump_flags(fff, f_ptr->f_flags3, 3, i);

		/*Drop the default*/
		fprintf(fff, "DEFAULT:%d:%d\n", i, f_ptr->defaults);

		/* Find the next empty state slot (if any) */
		for (x = 0; x < MAX_FEAT_STATES; x++)
		{

			if (f_ptr->state[x].fs_action != FS_FLAGS_END)
			{
				char action_desc[80];

				get_feature_name(action_desc, sizeof(action_desc),
											f_ptr->state[x].fs_action);

				if (f_ptr->state[x].fs_result > 0)
				{
					/*Get the name of terrain switching to*/
					f_ptr = &f_info[f_ptr->state[x].fs_result];
					desc = (f_name + f_ptr->name);
					/* Switch Back*/
					f_ptr = &f_info[i];

				}
				else desc = NULL;

				/*drop the "K" line*/
				fprintf(fff, "K%d:%d:%s:%s:%d\n", i, x, action_desc, desc, f_ptr->state[x].fs_power);
			}
		}

		/* Acquire the description */
		desc = f_text + f_ptr->f_text;
		dlen = strlen(desc);

		/* Write Description */
		for (j = 0; j < dlen;)
		{

			char buf[160], *t;

			/* Initialize */
			t = buf;
			bc = 0;

			/* Build this line */
			while (TRUE)
			{
				/* Insert this character, count it */
				*t++ = desc[j++];

				/* Oops.  Line is too long. */
				if (bc++ >= line_length)
				{
					/* Parse backwards until we find a space */
					while (!my_isspace(desc[j-1]) && (bc-- > 40))
					{
						j--;
						t--;
					}

					/* Time to end this line */
					*t++ = '\0';
					break;
				}

				/* All done */
				if (j >= dlen)
				{
					/* Time to end this line */
					*t++ = '\0';
					break;
				}
			}

			/* Done with this line; write it */
			fprintf(fff, "D-%d:%d:%s\n", counter, i, buf);

			counter++;
		}

		/*
		 * Print out empty lines, so all monsters have
		 * an equal number of lines
		 * makes parsing and combining the description easier
		 */
		for (; counter <+ 3; counter++)
		{
			fprintf(fff, "D-%d:%d\n", counter, i);
		}

		/* Space between entries */
		fprintf(fff, "\n\n\n");

	}

	/* Done */
	fclose(fff);
}