int main(int argc, char **argv)
{
#if (__GNUC__ >= 4)
	int cur_offset = 0;

	printf("%8s %-30s %3s\n", "offset", "field", "size");
	check_field(s_inodes_count, 4);
	check_field(s_blocks_count, 4);
	check_field(s_r_blocks_count, 4);
	check_field(s_free_blocks_count, 4);
	check_field(s_free_inodes_count, 4);
	check_field(s_first_data_block, 4);
	check_field(s_log_block_size, 4);
	check_field(s_log_cluster_size, 4);
	check_field(s_blocks_per_group, 4);
	check_field(s_clusters_per_group, 4);
	check_field(s_inodes_per_group, 4);
	check_field(s_mtime, 4);
	check_field(s_wtime, 4);
	check_field(s_mnt_count, 2);
	check_field(s_max_mnt_count, 2);
	check_field(s_magic, 2);
	check_field(s_state, 2);
	check_field(s_errors, 2);
	check_field(s_minor_rev_level, 2);
	check_field(s_lastcheck, 4);
	check_field(s_checkinterval, 4);
	check_field(s_creator_os, 4);
	check_field(s_rev_level, 4);
	check_field(s_def_resuid, 2);
	check_field(s_def_resgid, 2);
	check_field(s_first_ino, 4);
	check_field(s_inode_size, 2);
	check_field(s_block_group_nr, 2);
	check_field(s_feature_compat, 4);
	check_field(s_feature_incompat, 4);
	check_field(s_feature_ro_compat, 4);
	check_field(s_uuid, 16);
	check_field(s_volume_name, 16);
	check_field(s_last_mounted, 64);
	check_field(s_algorithm_usage_bitmap, 4);
	check_field(s_prealloc_blocks, 1);
	check_field(s_prealloc_dir_blocks, 1);
	check_field(s_reserved_gdt_blocks, 2);
	check_field(s_journal_uuid, 16);
	check_field(s_journal_inum, 4);
	check_field(s_journal_dev, 4);
	check_field(s_last_orphan, 4);
	check_field(s_hash_seed, 4 * 4);
	check_field(s_def_hash_version, 1);
	check_field(s_jnl_backup_type, 1);
	check_field(s_desc_size, 2);
	check_field(s_default_mount_opts, 4);
	check_field(s_first_meta_bg, 4);
	check_field(s_mkfs_time, 4);
	check_field(s_jnl_blocks, 17 * 4);
	check_field(s_blocks_count_hi, 4);
	check_field(s_r_blocks_count_hi, 4);
	check_field(s_free_blocks_hi, 4);
	check_field(s_min_extra_isize, 2);
	check_field(s_want_extra_isize, 2);
	check_field(s_flags, 4);
	check_field(s_raid_stride, 2);
	check_field(s_mmp_update_interval, 2);
	check_field(s_mmp_block, 8);
	check_field(s_raid_stripe_width, 4);
	check_field(s_log_groups_per_flex, 1);
	check_field(s_checksum_type, 1);
	check_field(s_encryption_level, 1);
	check_field(s_reserved_pad, 1);
	check_field(s_kbytes_written, 8);
	check_field(s_snapshot_inum, 4);
	check_field(s_snapshot_id, 4);
	check_field(s_snapshot_r_blocks_count, 8);
	check_field(s_snapshot_list, 4);
	check_field(s_error_count, 4);
	check_field(s_first_error_time, 4);
	check_field(s_first_error_ino, 4);
	check_field(s_first_error_block, 8);
	check_field(s_first_error_func, 32);
	check_field(s_first_error_line, 4);
	check_field(s_last_error_time, 4);
	check_field(s_last_error_ino, 4);
	check_field(s_last_error_line, 4);
	check_field(s_last_error_block, 8);
	check_field(s_last_error_func, 32);
	check_field(s_mount_opts, 64);
	check_field(s_usr_quota_inum, 4);
	check_field(s_grp_quota_inum, 4);
	check_field(s_overhead_blocks, 4);
 	check_field(s_backup_bgs, 8);
	check_field(s_encrypt_algos, 4);
	check_field(s_encrypt_pw_salt, 16);
	check_field(s_lpf_ino, 4);
	check_field(s_reserved, 100 * 4);
	check_field(s_checksum, 4);
	do_field("Superblock end", 0, 0, cur_offset, 1024);
#endif
	return 0;
}
Exemple #2
0
/*
 * PQprint()
 *
 * Format results of a query for printing.
 *
 * PQprintOpt is a typedef (structure) that contains
 * various flags and options. consult libpq-fe.h for
 * details
 *
 * This function should probably be removed sometime since psql
 * doesn't use it anymore. It is unclear to what extent this is used
 * by external clients, however.
 */
void
PQprint(FILE *fout, const PGresult *res, const PQprintOpt *po)
{
	int			nFields;

	nFields = PQnfields(res);

	if (nFields > 0)
	{							/* only print rows with at least 1 field.  */
		int			i,
					j;
		int			nTups;
		int		   *fieldMax = NULL;	/* in case we don't use them */
		unsigned char *fieldNotNum = NULL;
		char	   *border = NULL;
		char	  **fields = NULL;
		const char **fieldNames;
		int			fieldMaxLen = 0;
		int			numFieldName;
		int			fs_len = strlen(po->fieldSep);
		int			total_line_length = 0;
		int			usePipe = 0;
		char	   *pagerenv;

#if defined(ENABLE_THREAD_SAFETY) && !defined(WIN32)
		sigset_t	osigset;
		bool		sigpipe_masked = false;
		bool		sigpipe_pending;
#endif
#if !defined(ENABLE_THREAD_SAFETY) && !defined(WIN32)
		pqsigfunc	oldsigpipehandler = NULL;
#endif

#ifdef TIOCGWINSZ
		struct winsize screen_size;
#else
		struct winsize
		{
			int			ws_row;
			int			ws_col;
		}			screen_size;
#endif

		nTups = PQntuples(res);
		if (!(fieldNames = (const char **) calloc(nFields, sizeof(char *))))
		{
			fprintf(stderr, libpq_gettext("out of memory\n"));
			abort();
		}
		if (!(fieldNotNum = (unsigned char *) calloc(nFields, 1)))
		{
			fprintf(stderr, libpq_gettext("out of memory\n"));
			abort();
		}
		if (!(fieldMax = (int *) calloc(nFields, sizeof(int))))
		{
			fprintf(stderr, libpq_gettext("out of memory\n"));
			abort();
		}
		for (numFieldName = 0;
			 po->fieldName && po->fieldName[numFieldName];
			 numFieldName++)
			;
		for (j = 0; j < nFields; j++)
		{
			int			len;
			const char *s = (j < numFieldName && po->fieldName[j][0]) ?
			po->fieldName[j] : PQfname(res, j);

			fieldNames[j] = s;
			len = s ? strlen(s) : 0;
			fieldMax[j] = len;
			len += fs_len;
			if (len > fieldMaxLen)
				fieldMaxLen = len;
			total_line_length += len;
		}

		total_line_length += nFields * strlen(po->fieldSep) + 1;

		if (fout == NULL)
			fout = stdout;
		if (po->pager && fout == stdout && isatty(fileno(stdin)) &&
			isatty(fileno(stdout)))
		{
			/*
			 * If we think there'll be more than one screen of output, try to
			 * pipe to the pager program.
			 */
#ifdef TIOCGWINSZ
			if (ioctl(fileno(stdout), TIOCGWINSZ, &screen_size) == -1 ||
				screen_size.ws_col == 0 ||
				screen_size.ws_row == 0)
			{
				screen_size.ws_row = 24;
				screen_size.ws_col = 80;
			}
#else
			screen_size.ws_row = 24;
			screen_size.ws_col = 80;
#endif
			pagerenv = getenv("PAGER");
			if (pagerenv != NULL &&
				pagerenv[0] != '\0' &&
				!po->html3 &&
				((po->expanded &&
				  nTups * (nFields + 1) >= screen_size.ws_row) ||
				 (!po->expanded &&
				  nTups * (total_line_length / screen_size.ws_col + 1) *
				  (1 + (po->standard != 0)) >= screen_size.ws_row -
				  (po->header != 0) *
				  (total_line_length / screen_size.ws_col + 1) * 2
				  - (po->header != 0) * 2		/* row count and newline */
				  )))
			{
				fout = popen(pagerenv, "w");
				if (fout)
				{
					usePipe = 1;
#ifndef WIN32
#ifdef ENABLE_THREAD_SAFETY
					if (pq_block_sigpipe(&osigset, &sigpipe_pending) == 0)
						sigpipe_masked = true;
#else
					oldsigpipehandler = pqsignal(SIGPIPE, SIG_IGN);
#endif   /* ENABLE_THREAD_SAFETY */
#endif   /* WIN32 */
				}
				else
					fout = stdout;
			}
		}

		if (!po->expanded && (po->align || po->html3))
		{
			if (!(fields = (char **) calloc(nFields * (nTups + 1), sizeof(char *))))
			{
				fprintf(stderr, libpq_gettext("out of memory\n"));
				abort();
			}
		}
		else if (po->header && !po->html3)
		{
			if (po->expanded)
			{
				if (po->align)
					fprintf(fout, libpq_gettext("%-*s%s Value\n"),
							fieldMaxLen - fs_len, libpq_gettext("Field"), po->fieldSep);
				else
					fprintf(fout, libpq_gettext("%s%sValue\n"), libpq_gettext("Field"), po->fieldSep);
			}
			else
			{
				int			len = 0;

				for (j = 0; j < nFields; j++)
				{
					const char *s = fieldNames[j];

					fputs(s, fout);
					len += strlen(s) + fs_len;
					if ((j + 1) < nFields)
						fputs(po->fieldSep, fout);
				}
				fputc('\n', fout);
				for (len -= fs_len; len--; fputc('-', fout));
				fputc('\n', fout);
			}
		}
		if (po->expanded && po->html3)
		{
			if (po->caption)
				fprintf(fout, "<center><h2>%s</h2></center>\n", po->caption);
			else
				fprintf(fout,
						"<center><h2>"
						"Query retrieved %d rows * %d fields"
						"</h2></center>\n",
						nTups, nFields);
		}
		for (i = 0; i < nTups; i++)
		{
			if (po->expanded)
			{
				if (po->html3)
					fprintf(fout,
							"<table %s><caption align=\"top\">%d</caption>\n",
							po->tableOpt ? po->tableOpt : "", i);
				else
					fprintf(fout, libpq_gettext("-- RECORD %d --\n"), i);
			}
			for (j = 0; j < nFields; j++)
				do_field(po, res, i, j, fs_len, fields, nFields,
						 fieldNames, fieldNotNum,
						 fieldMax, fieldMaxLen, fout);
			if (po->html3 && po->expanded)
				fputs("</table>\n", fout);
		}
		if (!po->expanded && (po->align || po->html3))
		{
			if (po->html3)
			{
				if (po->header)
				{
					if (po->caption)
						fprintf(fout,
						   "<table %s><caption align=\"top\">%s</caption>\n",
								po->tableOpt ? po->tableOpt : "",
								po->caption);
					else
						fprintf(fout,
								"<table %s><caption align=\"top\">"
								"Retrieved %d rows * %d fields"
								"</caption>\n",
						   po->tableOpt ? po->tableOpt : "", nTups, nFields);
				}
				else
					fprintf(fout, "<table %s>", po->tableOpt ? po->tableOpt : "");
			}
			if (po->header)
				border = do_header(fout, po, nFields, fieldMax, fieldNames,
								   fieldNotNum, fs_len, res);
			for (i = 0; i < nTups; i++)
				output_row(fout, po, nFields, fields,
						   fieldNotNum, fieldMax, border, i);
			free(fields);
			if (border)
				free(border);
		}
		if (po->header && !po->html3)
			fprintf(fout, "(%d row%s)\n\n", PQntuples(res),
					(PQntuples(res) == 1) ? "" : "s");
		free(fieldMax);
		free(fieldNotNum);
		free((void *) fieldNames);
		if (usePipe)
		{
#ifdef WIN32
			_pclose(fout);
#else
			pclose(fout);

#ifdef ENABLE_THREAD_SAFETY
			/* we can't easily verify if EPIPE occurred, so say it did */
			if (sigpipe_masked)
				pq_reset_sigpipe(&osigset, sigpipe_pending, true);
#else
			pqsignal(SIGPIPE, oldsigpipehandler);
#endif   /* ENABLE_THREAD_SAFETY */
#endif   /* WIN32 */
		}
		if (po->html3 && !po->expanded)
			fputs("</table>\n", fout);
	}
}
Exemple #3
0
//Create zones of different climates.
void TerraformZones ()
{

  int             x, y;
  vector<Climate> climates;
  Region          r;
  int             radius;
  Climate         c;
  GLcoord         walk;
  UINT            spinner;

  walk.Clear ();
  spinner = 0;
  do {
    x = walk.x;
    y = walk.y;// + WorldNoisei (walk.x + walk.y * WORLD_GRID) % 4;
    radius = 2 + WorldNoisei (10 + walk.x + walk.y * WORLD_GRID) % 9;
    if (is_free (x, y, radius)) {
      r = WorldRegionGet (x, y);
      climates.clear ();
      //swamps only appear in wet areas that aren't cold.
      if (r.moisture > 0.8f && r.temperature > 0.5f)
        climates.push_back (CLIMATE_SWAMP);
      //mountains only appear in the middle
      if (abs (x - WORLD_GRID_CENTER) < 10 && radius > 1)
        climates.push_back (CLIMATE_MOUNTAIN);
      //Deserts are HOT and DRY. Duh.
      if (r.temperature > TEMP_HOT && r.moisture < 0.05f && radius > 1)
        climates.push_back (CLIMATE_DESERT);
      //fields should be not too hot or cold.
      if (r.temperature > TEMP_TEMPERATE && r.temperature < TEMP_HOT && r.moisture > 0.5f && radius == 1)
        climates.push_back (CLIMATE_FIELD);
      if (r.temperature > TEMP_TEMPERATE && r.temperature < TEMP_HOT && r.moisture > 0.25f && radius > 1)
        climates.push_back (CLIMATE_PLAINS);
      //Rocky wastelands favor cold areas
      if (r.temperature < TEMP_TEMPERATE)
        climates.push_back (CLIMATE_ROCKY);
      if (radius > 1 && !(WorldNoisei (spinner++) % 10))
        climates.push_back (CLIMATE_CANYON);
      if (r.temperature > TEMP_TEMPERATE && r.temperature < TEMP_HOT && r.moisture > 0.5f)
        climates.push_back (CLIMATE_FOREST);
      if (climates.empty ()) {
        walk.Walk (WORLD_GRID);
        continue;
      }              
      c = climates[RandomVal () % climates.size ()];
      switch (c) {
      case CLIMATE_ROCKY:
        do_rocky (x, y, radius);
        break;
      case CLIMATE_MOUNTAIN:
        do_mountain (x, y, radius);
        break;
      case CLIMATE_CANYON:
        do_canyon (x, y, radius);
        break;
      case CLIMATE_SWAMP:
        do_swamp (x, y, radius);
        break;
      case CLIMATE_FIELD:
        do_field (x, y, radius);
        break;
      case CLIMATE_DESERT:
        do_desert (x, y, radius);
        break;
      case CLIMATE_PLAINS:
        do_plains (x, y, radius);
        break;
      case CLIMATE_FOREST:
        do_forest (x, y, radius);
        break;
      }
    }
  } while (!walk.Walk (WORLD_GRID));

}