Exemplo n.º 1
0
int main(void) {
	int i;
	char choice;
	char quit;

	main_init();

	quit = FALSE;
	do {
		choice = title_page();

		switch (choice) {
		case (0) :
		case (1) :
			gPlayers = choice + 1;
			break;
		case (2) :
			continue;
		default :
			quit = TRUE;
		};

		if (!quit) {
			game_reset();

			// main game loop
			do {
				key_check();

				for (i = 0; i != gPlayers; ++i) {
					player_key_check(i);
					player_stack_linecheck(i);
					player_update(i);
				}

				screen_draw();
				blit(gBuff, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
			} while (gWinner == 0);

			record_scores();
			table_display();
		}
	} while (!quit);

	table_display();
	main_exit();
	return 0;
}
Exemplo n.º 2
0
int		main()
{
  int		err;
  int		i;
  pthread_t	thd[NB_PHIL];
  t_table	table;

  i = 0;
  table_init(&table);
  table_display(&table);
  err = phil_creat(thd, &table);
  if (err == EXIT_FAILURE)
    {
      perror("phil_creat fail");
      exit(EXIT_FAILURE);
    }
  while(i < NB_PHIL && !pthread_join(thd[i], NULL))
    i++;
  table_display(&table);
  pthread_exit(NULL);
}
Exemplo n.º 3
0
// TODO: optionnal arguments fieldType and subDomain in query string
static command_status_t record_list(COMMAND_ARGS)
{
    domain_t *d;
    Iterator it;
    command_status_t ret;
    domain_record_argument_t *args;

    USED(mainopts);
    args = (domain_record_argument_t *) arg;
    assert(NULL != args->domain);
    if (COMMAND_SUCCESS == (ret = get_domain_records(args->domain, &d, args->nocache, error))) {
        // display
        table_t *t;

        t = table_new(
#ifdef PRINT_OVH_ID
            5, _("id"), TABLE_TYPE_INT,
#else
            4,
#endif /* PRINT_OVH_ID */
            _("subdomain"), TABLE_TYPE_STRING,
            _("type"), TABLE_TYPE_ENUM, domain_record_types,
            _("TTL"), TABLE_TYPE_INT,
            _("target"), TABLE_TYPE_STRING
        );
        hashtable_to_iterator(&it, d->records);
        for (iterator_first(&it); iterator_is_valid(&it); iterator_next(&it)) {
            record_t *r;

            r = iterator_current(&it, NULL);
            if (0 == args->type || r->type == args->type) {
                table_store(t,
#ifdef PRINT_OVH_ID
                    r->id,
#endif /* PRINT_OVH_ID */
                    r->name, r->type, r->ttl, r->target
                );
            }
        }
        iterator_close(&it);
        table_display(t, TABLE_FLAG_NONE);
        table_destroy(t);
    }

    return ret;
}
Exemplo n.º 4
0
/* prepare a list of pkgs to display */
static void _display_targets(alpm_list_t *targets, int verbose)
{
	char *str;
	const char *label;
	double size;
	off_t isize = 0, rsize = 0, dlsize = 0;
	unsigned short cols;
	alpm_list_t *i, *rows = NULL, *names = NULL;

	if(!targets) {
		return;
	}

	/* gather package info */
	for(i = targets; i; i = alpm_list_next(i)) {
		pm_target_t *target = i->data;

		if(target->install) {
			dlsize += alpm_pkg_download_size(target->install);
			isize += alpm_pkg_get_isize(target->install);
		}
		if(target->remove) {
			/* add up size of all removed packages */
			rsize += alpm_pkg_get_isize(target->remove);
		}
	}

	/* form data for both verbose and non-verbose display */
	for(i = targets; i; i = alpm_list_next(i)) {
		pm_target_t *target = i->data;

		rows = alpm_list_add(rows, create_verbose_row(target));
		if(target->install) {
			pm_asprintf(&str, "%s-%s", alpm_pkg_get_name(target->install),
					alpm_pkg_get_version(target->install));
		} else if(isize == 0) {
			pm_asprintf(&str, "%s-%s", alpm_pkg_get_name(target->remove),
					alpm_pkg_get_version(target->remove));
		} else {
			pm_asprintf(&str, "%s-%s [removal]", alpm_pkg_get_name(target->remove),
					alpm_pkg_get_version(target->remove));
		}
		names = alpm_list_add(names, str);
	}

	/* print to screen */
	pm_asprintf(&str, _("Packages (%d):"), alpm_list_count(targets));
	printf("\n");

	cols = getcols(fileno(stdout));
	if(verbose) {
		alpm_list_t *header = create_verbose_header();
		if(table_display(str, header, rows, cols) != 0) {
			/* fallback to list display if table wouldn't fit */
			list_display(str, names, cols);
		}
		alpm_list_free(header);
	} else {
		list_display(str, names, cols);
	}
	printf("\n");

	/* rows is a list of lists of strings, free inner lists here */
	for(i = rows; i; i = alpm_list_next(i)) {
		alpm_list_t *lp = i->data;
		FREELIST(lp);
	}
	alpm_list_free(rows);
	FREELIST(names);
	free(str);

	if(dlsize > 0 || config->op_s_downloadonly) {
		size = humanize_size(dlsize, 'M', 2, &label);
		printf(_("Total Download Size:    %.2f %s\n"), size, label);
	}
	if(!config->op_s_downloadonly) {
		if(isize > 0) {
			size = humanize_size(isize, 'M', 2, &label);
			printf(_("Total Installed Size:   %.2f %s\n"), size, label);
		}
		if(rsize > 0 && isize == 0) {
			size = humanize_size(rsize, 'M', 2, &label);
			printf(_("Total Removed Size:     %.2f %s\n"), size, label);
		}
		/* only show this net value if different from raw installed size */
		if(isize > 0 && rsize > 0) {
			size = humanize_size(isize - rsize, 'M', 2, &label);
			printf(_("Net Upgrade Size:       %.2f %s\n"), size, label);
		}
	}
}
Exemplo n.º 5
0
static void select_rows ()
{
  char in_str[200] = "", from_str[100] = "";
  char *where_str, *p;
  char attr[11] = "", op[3] = "";
  int val;
  tbl_p where_tbl = NULL, res_tbl = NULL, from_tbl = NULL;
  char *attrs[10];
  int num_res_attrs = 0, i;
  for ( i = 0; i < 10; i++ ) attrs[i] = NULL;

  fscanf (in_s, "%[^;];", in_str);

  p = strstr (in_str, " from ");
  if ( p == NULL )
    {
      put_msg (ERROR, "select %s: from which table to select?\n", in_str);
      return;
    }
  *p = '\0';
  p += 6;
  if ( sscanf (p, "%s", from_str) != 1 )
    {
      put_msg (ERROR, "select from what?\n");
      return;
    }

  num_res_attrs = str_split ( in_str, ',', attrs, 10);
  if (num_res_attrs == 0)
    {
      put_msg (ERROR, "select from %s: select what?\n", p);
      return;
    }

  p += 2;
  where_str = strstr (p, " where ");
  if ( where_str != NULL ) where_str += 7;

  put_msg (DEBUG, "from: \"%s\", where: \"%s\"\n", from_str, where_str);
  from_tbl = get_table (from_str);
  if (from_tbl == NULL)
    {
      put_msg (ERROR, "select: table \"%s\" does not exist.\n", from_str);
      return;
    }

  if ( where_str != NULL )
    {
      if (sscanf ( where_str, "%s %s %d", attr, op, &val) != 3)
	{
	  put_msg (ERROR, "query \"%s\" is not supported.\n", where_str);
	  return;
	}
      where_tbl = table_search_binary ( from_tbl, attr, op, val);
      if (where_tbl == NULL)
	return;
    }

  if ( attrs[0][0] == '*' )
    table_display (where_tbl ? where_tbl : from_tbl);
  else
    {
      res_tbl = table_project ( where_tbl ? where_tbl : from_tbl,
				"tmp_res_01", num_res_attrs, attrs);
      table_display (res_tbl);
    }

  remove_table (where_tbl);
  remove_table (res_tbl);
}
Exemplo n.º 6
0
/* prepare a list of pkgs to display */
static void _display_targets(alpm_list_t *targets, int verbose)
{
	char *str;
	off_t isize = 0, rsize = 0, dlsize = 0;
	unsigned short cols;
	alpm_list_t *i, *names = NULL, *header = NULL, *rows = NULL;

	if(!targets) {
		return;
	}

	/* gather package info */
	for(i = targets; i; i = alpm_list_next(i)) {
		pm_target_t *target = i->data;

		if(target->install) {
			dlsize += alpm_pkg_download_size(target->install);
			isize += alpm_pkg_get_isize(target->install);
		}
		if(target->remove) {
			/* add up size of all removed packages */
			rsize += alpm_pkg_get_isize(target->remove);
		}
	}

	/* form data for both verbose and non-verbose display */
	for(i = targets; i; i = alpm_list_next(i)) {
		pm_target_t *target = i->data;

		if(verbose) {
			rows = alpm_list_add(rows, create_verbose_row(target));
		}

		if(target->install) {
			pm_asprintf(&str, "%s-%s", alpm_pkg_get_name(target->install),
					alpm_pkg_get_version(target->install));
		} else if(isize == 0) {
			pm_asprintf(&str, "%s-%s", alpm_pkg_get_name(target->remove),
					alpm_pkg_get_version(target->remove));
		} else {
			pm_asprintf(&str, "%s-%s [%s]", alpm_pkg_get_name(target->remove),
					alpm_pkg_get_version(target->remove), _("removal"));
		}
		names = alpm_list_add(names, str);
	}

	/* print to screen */
	pm_asprintf(&str, "%s (%zd)", _("Packages"), alpm_list_count(targets));
	printf("\n");

	cols = getcols(fileno(stdout));
	if(verbose) {
		header = create_verbose_header(alpm_list_count(targets));
		if(table_display(header, rows, cols) != 0) {
			/* fallback to list display if table wouldn't fit */
			list_display(str, names, cols);
		}
	} else {
		list_display(str, names, cols);
	}
	printf("\n");

	table_free(header, rows);
	FREELIST(names);
	free(str);
	rows = NULL;

	if(dlsize > 0 || config->op_s_downloadonly) {
		add_transaction_sizes_row(&rows, _("Total Download Size:"), dlsize);
	}
	if(!config->op_s_downloadonly) {
		if(isize > 0) {
			add_transaction_sizes_row(&rows, _("Total Installed Size:"), isize);
		}
		if(rsize > 0 && isize == 0) {
			add_transaction_sizes_row(&rows, _("Total Removed Size:"), rsize);
		}
		/* only show this net value if different from raw installed size */
		if(isize > 0 && rsize > 0) {
			add_transaction_sizes_row(&rows, _("Net Upgrade Size:"), isize - rsize);
		}
	}
	table_display(NULL, rows, cols);
	table_free(NULL, rows);
}