示例#1
0
int main(void) {

    uint32_t mode[1] = {0};
    int ret = 0;

    while (1) {
        if ((ret = do_nonce()) == 0) {            
            RECV(mode, sizeof(uint32_t));

            switch (mode[0]) {
                case MODE_BUILD:
                    ret = do_build();
                    break;
                case MODE_EXAMINE:
                    ret = do_examine();
                    break;
                default:
                    ret = ERR_INVALID_MODE;
            }
        } 

        if (ret < 0) {
            SENDSI(ret);
            return ret;
        }
    }
    return ret;
}
示例#2
0
static PyObject* build2(PyObject* self, PyObject* args) { // Return result in-place without memory leaks
		coord tar_x, tar_y, x0, y0, x1, y1, x2, y2, x3, y3;
		PyObject *list_x, *list_y;
		int32_t debug;
        if(! PyArg_ParseTuple(args, "OOiiiiiiiiiii", &list_x, &list_y, &tar_x, &tar_y, &x0, &y0, &x1, &y1, &x2, &y2, &x3, &y3, &debug))
                return NULL;
        
		do_build(tar_x, tar_y, x0, y0, x1, y1, x2, y2, x3, y3, debug);

		int32_t i, len = tar_x * tar_y;
		for (i=0; i<len; i++) PyList_SetItem(list_x, i, PyInt_FromLong(res_x[i]));
		for (i=0; i<len; i++) PyList_SetItem(list_y, i, PyInt_FromLong(res_y[i]));
		
// 		return Py_BuildValue("i",0);
		return Py_BuildValue("OO", list_x, list_y);
}
示例#3
0
static PyObject* build(PyObject* self, PyObject* args)
{
        coord tar_x, tar_y, x0, y0, x1, y1, x2, y2, x3, y3;
		int32_t debug;
        if(! PyArg_ParseTuple(args, "iiiiiiiiiii", &tar_x, &tar_y, &x0, &y0, &x1, &y1, &x2, &y2, &x3, &y3, &debug))
                return NULL;
        
		do_build(tar_x, tar_y, x0, y0, x1, y1, x2, y2, x3, y3, debug);
		
		int32_t i, len = tar_x * tar_y;
		PyObject *list_x, *list_y;
		list_x = PyList_New(len);
		list_y = PyList_New(len);
		if (list_x != NULL) for (i=0; i<len; i++) PyList_SET_ITEM(list_x, i, PyInt_FromLong(res_x[i]));
		if (list_y != NULL) for (i=0; i<len; i++) PyList_SET_ITEM(list_y, i, PyInt_FromLong(res_y[i]));
		
        return Py_BuildValue("OO", list_x, list_y);
}
示例#4
0
/* execute selected actions */
void do_actions() {
    int i, missile, bomber, i2;
    struct action_node *action;

    for (i = 0; i < NUM_PLAYERS; i++) {
        if (IS_ACTIVE(i)) {
            action = find_action(i, current_turn);
            if (action) {
                missile = -1;
                bomber = -1;
                switch (action->action) {
                case ACTION_BUILD:
                    if (has_cities(i, 0))
                        do_build(i);
                    break;
                case ACTION_PROPAGANDA:
                    if (has_cities(i, 0)) {
                        do_propaganda(i);
                        /* random message */
                        if (i == me && players[action->target_player].ai)
                            ai_random_message(action->target_player);
                    }
                    break;
                case ACTION_MISSILE_10MT:
                case ACTION_MISSILE_20MT:
                case ACTION_MISSILE_50MT:
                case ACTION_MISSILE_100MT:
                    if (has_cities(i, 0)) {
                        do_missile(i);
                        missile = action->action - ACTION_MISSILE_10MT;
                    }
                    break;
                case ACTION_WARHEAD_10MT:
                case ACTION_WARHEAD_20MT:
                case ACTION_WARHEAD_50MT:
                case ACTION_WARHEAD_100MT:
                    do_nuke(i);
                    if (!players[i].ai)
                        bomber = GET_BOMBER(i);	/*	don't unset so we can reuse the bomber	*/
                    else {
                        if (players[i].mt_left) {
                            /* check if the ai player has a warhead and enough capacity to reuse the bomber */
                            for (i2 = 0; i2 < 4; i2++) {
                                if (GET_STOCK(i, WEAPON_WARHEAD_10MT + i2) && megatons[i2] <= players[i].mt_left)
                                    bomber = GET_BOMBER(i);
                            }
                        }
                    }
                    /* random message */
                    if (i == me && players[action->target_player].ai && has_cities(me, 0))
                        ai_random_message(action->target_player);
                    break;
                case ACTION_NP1:
                case ACTION_GR2:
                    if (has_cities(i, 0)) {
                        do_bomber(i);
                        bomber = action->action - ACTION_NP1;
                    }
                    break;
                case ACTION_LNDS:
                case ACTION_MEGA:
                    if (has_cities(i, 0))
                        do_defense(i);
                    break;
                }

                GET_PREVIOUS(i) = action->action;	/*	remember action for next turn	*/
                GET_MISSILE(i) = missile;
                GET_BOMBER(i) = bomber;
            }
        }
    }
}
示例#5
0
int
main (int    argc,
      char **argv)
{
  gint argi;
  gint i;

  if (argc == 1)
    usage (EXIT_SUCCESS);

  /* First scan for flags that affect our behaviour globally, but
   * are still allowed late on the command line.
   */
  argi = 0;
  while (++argi < argc)
    {
      if (strcmp (argv[argi], "-n") == 0 ||
	  strcmp (argv[argi], "--just-print") == 0 ||
	  strcmp (argv[argi], "--dry-run") == 0 ||
	  strcmp (argv[argi], "--recon") == 0)
        {
          dry_run = TRUE;
        }
      else if (strcmp (argv[argi], "--help") == 0)
        {
          usage (EXIT_SUCCESS);
        }
      else if (g_str_has_prefix (argv[argi], "--prefix="))
        {
          prefix = argv[argi] + strlen ("--prefix=");
        }
      else if (g_str_has_prefix (argv[argi], "--exec-prefix="))
        {
          exec_prefix = argv[argi] + strlen ("--exec_prefix=");
        }
      else if (strcmp (argv[argi], "--msvc-syntax") == 0)
        {
          msvc_syntax = TRUE;
        }
    }

#ifndef G_OS_WIN32
  if (msvc_syntax)
    {
      g_printerr ("Ignoring --msvc-syntax\n");
      msvc_syntax = FALSE;
    }
#endif

  find_out_env_flags ();

  /* Second pass, actually do something. */
  argi = 0;
  while (++argi < argc)
    {
      for (i = 0; i < G_N_ELEMENTS (dirs); i++)
        {
          if (strcmp (argv[argi],
                      g_strconcat ("--", dirs[i].option, NULL)) == 0)
            break;
        }

      if (i < G_N_ELEMENTS (dirs))
        {
          g_print ("%s\n", expand_and_munge (dirs[i].value));
        }
      else if (strcmp (argv[argi], "--quiet") == 0 ||
               strcmp (argv[argi], "--silent") == 0)
        {
          silent = TRUE;
        }
      else if (strcmp (argv[argi], "--version") == 0)
	{
	  g_print ("%d.%d.%d\n",
                   GIMP_MAJOR_VERSION, GIMP_MINOR_VERSION, GIMP_MICRO_VERSION);
	  exit (EXIT_SUCCESS);
	}
      else if (strcmp (argv[argi], "-n") == 0 ||
	       strcmp (argv[argi], "--just-print") == 0 ||
	       strcmp (argv[argi], "--dry-run") == 0 ||
	       strcmp (argv[argi], "--recon") == 0)
	;			/* Already handled */
      else if (strcmp (argv[argi], "--includedir") == 0)
	do_includedir ();
      else if (strcmp (argv[argi], "--cflags") == 0)
	do_cflags ();
      else if (strcmp (argv[argi], "--cflags-noui") == 0)
	do_cflags_noui ();
      else if (strcmp (argv[argi], "--cflags-nogimpui") == 0)
	do_cflags_nogimpui ();
      else if (strcmp (argv[argi], "--libs") == 0)
	do_libs ();
      else if (strcmp (argv[argi], "--libs-noui") == 0)
	do_libs_noui ();
      else if (strcmp (argv[argi], "--libs-nogimpui") == 0)
	do_libs_nogimpui ();
      else if (g_str_has_prefix (argv[argi], "--prefix="))
	;
      else if (g_str_has_prefix (argv[argi], "--exec-prefix="))
	;
      else if (strcmp (argv[argi], "--msvc-syntax") == 0)
	;
      else if (strcmp (argv[argi], "--build") == 0)
	do_build (argv[++argi]);
      else if (strcmp (argv[argi], "--build-noui") == 0)
	do_build_noui (argv[++argi]);
      else if (strcmp (argv[argi], "--build-nogimpui") == 0)
	do_build_nogimpui (argv[++argi]);
      else if (strcmp (argv[argi], "--install") == 0)
	do_install (argv[++argi]);
      else if (strcmp (argv[argi], "--install-noui") == 0)
	do_install_noui (argv[++argi]);
      else if (strcmp (argv[argi], "--install-nogimpui") == 0)
	do_install_nogimpui (argv[++argi]);
      else if (strcmp (argv[argi], "--install-admin") == 0)
	do_install_admin (argv[++argi]);
      else if (strcmp (argv[argi], "--install-admin-noui") == 0)
	do_install_admin_noui (argv[++argi]);
      else if (strcmp (argv[argi], "--install-admin-nogimpui") == 0)
	do_install_admin_nogimpui (argv[++argi]);
      else if (strcmp (argv[argi], "--install-bin") == 0)
	do_install_bin (argv[++argi]);
      else if (strcmp (argv[argi], "--install-admin-bin") == 0)
	do_install_admin_bin (argv[++argi]);
      else if (strcmp (argv[argi], "--uninstall-bin") == 0)
	do_uninstall_bin (argv[++argi]);
      else if (strcmp (argv[argi], "--uninstall-admin-bin") == 0)
	do_uninstall_admin_bin (argv[++argi]);
      else if (strcmp (argv[argi], "--install-script") == 0)
	do_install_script (argv[++argi]);
      else if (strcmp (argv[argi], "--install-admin-script") == 0)
	do_install_admin_script (argv[++argi]);
      else if (strcmp (argv[argi], "--uninstall-script") == 0)
	do_uninstall_script (argv[++argi]);
      else if (strcmp (argv[argi], "--uninstall-admin-script") == 0)
	do_uninstall_admin_script (argv[++argi]);
      else
	{
	  g_printerr ("Unrecognized switch %s\n", argv[argi]);
	  usage (EXIT_FAILURE);
	}
    }

  exit (EXIT_SUCCESS);
}
示例#6
0
static void
do_build_nogimpui (const gchar *what)
{
  do_build (what);
}
示例#7
0
文件: mkmakefile.c 项目: DINKIN/xnu
/*
 * Build the makefile from the skeleton
 */
void
makefile(void)
{
	FILE *ifp, *ofp;
	FILE *dfp;
	char pname[BUFSIZ];
	char line[BUFSIZ];
	struct opt *op;
	struct users *up;

	read_files();
	(void) sprintf(line, "%s/Makefile.template", config_directory);
	ifp = fopenp(VPATH, line, pname, "r");
	if (ifp == 0) {
		perror(line);
		exit(1);
	}
	dfp = fopen(path("Makefile"), "r");
	rename(path("Makefile"), path("Makefile.old"));
	unlink(path("Makefile.old"));
	unlink(path("M.d"));
	if ((ofp = fopen(path("M.d"), "w")) == NULL) {
		perror(path("M.d"));
		/* We'll let this error go */
	}
	else
	 	fclose(ofp);
	ofp = fopen(path("Makefile"), "w");
	if (ofp == 0) {
		perror(path("Makefile"));
		exit(1);
	}
	fprintf(ofp, "SOURCE_DIR=%s\n", source_directory);

	if (machine == MACHINE_SUN || machine == MACHINE_SUN2 
	    || machine == MACHINE_SUN3 || machine == MACHINE_SUN4)
		fprintf(ofp, "IDENT=-D%s -D%s", machinename, allCaps(ident));
	else
		fprintf(ofp, "IDENT=-D%s", allCaps(ident));
	if (profiling)
		fprintf(ofp, " -DGPROF");
	if (cputype == 0) {
		printf("cpu type must be specified\n");
		exit(1);
	}
	do_build("cputypes.h", build_cputypes);

	for (op = opt; op; op = op->op_next)
		if (op->op_value)
			fprintf(ofp, " -D%s=\"%s\"", op->op_name, op->op_value);
		else
			fprintf(ofp, " -D%s", op->op_name);
	fprintf(ofp, "\n");
	if ((unsigned)machine > NUSERS) {
		printf("maxusers config info isn't present, using vax\n");
		up = &users[MACHINE_VAX-1];
	} else
		up = &users[machine-1];
	if (maxusers < up->u_min) {
		maxusers = up->u_min;
	} else if (maxusers > up->u_max)
		printf("warning: maxusers > %d (%d)\n", up->u_max, maxusers);
	if (maxusers) {
		do_build("confdep.h", build_confdep);
	}
	for (op = mkopt; op; op = op->op_next)
		if (op->op_value)
			fprintf(ofp, "%s=%s\n", op->op_name, op->op_value);
		else
			fprintf(ofp, "%s\n", op->op_name);

	while (fgets(line, BUFSIZ, ifp) != 0) {
		if (*line == '%')
			goto percent;
		if (profiling && strncmp(line, "COPTS=", 6) == 0) {
			register char *cp;
			if (machine != MACHINE_MMAX)
			    fprintf(ofp,
				"GPROF.EX=$(SOURCE_DIR)/machdep/%s/gmon.ex\n", machinename);
			cp = index(line, '\n');
			if (cp)
				*cp = 0;
			cp = line + 6;
			while (*cp && (*cp == ' ' || *cp == '\t'))
				cp++;
			COPTS = malloc((unsigned)(strlen(cp) + 1));
			if (COPTS == 0) {
				printf("config: out of memory\n");
				exit(1);
			}
			strcpy(COPTS, cp);
			if (machine == MACHINE_MIPSY || machine == MACHINE_MIPS) {
				fprintf(ofp, "%s ${CCPROFOPT}\n", line);
				fprintf(ofp, "PCOPTS=%s\n", cp);
			} else if (machine == MACHINE_MMAX)
				fprintf(ofp, "%s -p\n",line);
			else
				fprintf(ofp, "%s -pg\n", line);
			continue;
		}
		fprintf(ofp, "%s", line);
		continue;
	percent:
		if (eq(line, "%OBJS\n")) {
			do_objs(ofp, "OBJS=", -1);
		} else if (eq(line, "%CFILES\n")) {
			do_files(ofp, "CFILES=", 'c');
			do_objs(ofp, "COBJS=", 'c');
		} else if (eq(line, "%MFILES\n")) {
			do_files(ofp, "MFILES=", 'm');
			do_objs(ofp, "MOBJS=", 'm');
		} else if (eq(line, "%SFILES\n")) {
			do_files(ofp, "SFILES=", 's');
			do_objs(ofp, "SOBJS=", 's');
		} else if (eq(line, "%BFILES\n"))
			do_files(ofp, "BFILES=", 'b');
		else if (eq(line, "%MACHDEP\n")) {
			/*
			 * Move do_machdep() after the mkopt stuff.
			 */
			for (op = mkopt; op; op = op->op_next)
				fprintf(ofp, "%s=%s\n", op->op_name, op->op_value);
			do_machdep(ofp);
		} else if (eq(line, "%ORDERED\n"))
			do_ordered(ofp);
		else if (eq(line, "%RULES\n"))
			do_rules(ofp);
		else if (eq(line, "%LOAD\n"))
			do_load(ofp);
		else
			fprintf(stderr,
			    "Unknown %% construct in generic makefile: %s",
			    line);
	}
	if (dfp != NULL)
	{
		copy_dependencies(dfp, ofp);
		(void) fclose(dfp);
	}
	(void) fclose(ifp);
	(void) fclose(ofp);
}