Example #1
0
gboolean
gitg_shell_run_parse (GitgShell       *shell,
                      GitgRepository  *repository,
                      const gchar     *cmdstr,
                      GError         **error)

{
	gboolean ret;
	GitgCommand **commands;

	g_return_val_if_fail (GITG_IS_SHELL (shell), FALSE);
	g_return_val_if_fail (cmdstr != NULL, FALSE);
	g_return_val_if_fail (repository == NULL || GITG_IS_REPOSITORY (repository), FALSE);

	commands = gitg_shell_parse_commands (repository, cmdstr, error);

	if (!commands)
	{
		return FALSE;
	}

	ret = run_commands (shell, commands, error);
	g_free (commands);

	return ret;
}
Example #2
0
static void
check_status (const gchar *status)
{
    gchar *pattern;

    if (getenv ("DEBUG"))
        g_print ("%s\n", status);

    if (failed)
        return;

    statuses = g_list_append (statuses, g_strdup (status));

    /* Try and match against expected */
    pattern = get_script_line ();
    if (!pattern || !g_regex_match_simple (pattern, status, 0, 0))
    {
        fail (NULL, pattern);
        return;
    }
    script_iter = script_iter->next;

    /* Restart timeout */
    if (status_timeout)
        g_source_remove (status_timeout);
    status_timeout = g_timeout_add (STATUS_TIMEOUT, status_timeout_cb, NULL);

    run_commands ();
}
Example #3
0
gboolean
gitg_shell_run_list (GitgShell    *shell,
                     GitgCommand **commands,
                     GError      **error)
{
	g_return_val_if_fail (GITG_IS_SHELL (shell), FALSE);

	return run_commands (shell, commands, error);
}
/* check to see if the size of the file is > 0. if so, run commands */
void init_file() {
	/* most of this was taken from Bash v2.04 by the FSF */
	struct stat finfo;
	char file[256];

	sprintf(file, "%s/.gaim/control", getenv("HOME"));

	if ((stat (file, &finfo) == 0) && (finfo.st_size > 0))
		run_commands();
}
Example #5
0
File: run.c Project: ameenross/dex
static void run_command(const struct command *cmds, char **av)
{
	const struct command *cmd = find_command(cmds, av[0]);
	const char *pf;
	char **args;

	if (!cmd) {
		PTR_ARRAY(array);
		const char *alias_name = av[0];
		const char *alias_value = find_alias(alias_name);
		struct error *err = NULL;
		int i;

		if (alias_value == NULL) {
			error_msg("No such command or alias: %s", alias_name);
			return;
		}
		if (!parse_commands(&array, alias_value, &err)) {
			error_msg("Parsing alias %s: %s", alias_name, err->msg);
			error_free(err);
			ptr_array_free(&array);
			return;
		}

		/* remove NULL */
		array.count--;

		for (i = 1; av[i]; i++)
			ptr_array_add(&array, xstrdup(av[i]));
		ptr_array_add(&array, NULL);

		run_commands(cmds, &array);
		ptr_array_free(&array);
		return;
	}

	if (config_file && cmds == commands && !allowed_command(cmd->name)) {
		error_msg("Command %s not allowed in config file.", cmd->name);
		return;
	}

	// By default change can't be merged with previous on.
	// Any command can override this by calling begin_change() again.
	begin_change(CHANGE_MERGE_NONE);

	current_command = cmd;
	args = av + 1;
	pf = parse_args(args, cmd->flags, cmd->min_args, cmd->max_args);
	if (pf)
		cmd->cmd(pf, args);
	current_command = NULL;

	end_change();
}
Example #6
0
	/*
	 * PURPOSE: The command line driven program does matrix creation, reading, writing, and other 
	 *		miscellaneous operations. The program automatically creates a matrix and writes 
	 *		that out called temp_mat (in binary do not use the cat command on it). You are 
	 *		able to display any matrix by using the display command. You can create a new 
	 *		blank matrix with the command create. To fill a matrix with random values use the 
	 *		random command between a range of values. To get some experience with bit shifting 
	 *		there is a command called shift. If you want to write and read in a matrix from 
	 *		the filesystem use the respective read and write commands. To see memory operations 
	 *		in action use the duplicate and equal commands. The others commands are sum and add. 
	 *		To exit the program use the exit command.  
	 * INPUTS: No inputs needed
	 * RETURN: Returns 0 on successful exectution otherwise -1 if there was an error 
	 **/
int main (int argc, char **argv) {
	srand(time(NULL));		
	char *line = NULL;
	Commands_t* cmd;

	Matrix_t *mats[10];
	memset(&mats,0, sizeof(Matrix_t*) * 10); // IMPORTANT C FUNCTION TO LEARN

	Matrix_t *temp = NULL;
	
	// TODO ERROR CHECK
	if(!create_matrix (&temp,"temp_mat", 5, 5)) { 
		return -1; 
	}
 
	//TODO ERROR CHECK NEEDED
	if( (add_matrix_to_array(mats,temp, 10)) < 0) {
		return -1;
	}

	int mat_idx = find_matrix_given_name(mats,10,"temp_mat");

	if (mat_idx < 0) {
		perror("PROGRAM FAILED TO INIT\n");
		return -1;
	}
	random_matrix(mats[mat_idx], 10, 15);
	
	// TODO ERROR CHECK
	if(!write_matrix("temp_mat", mats[mat_idx])) {
		return -1; 
	}

	line = readline("> ");
	while (strncmp(line,"exit", strlen("exit")  + 1) != 0) {
		
		if (!parse_user_input(line,&cmd)) {
			printf("Failed at parsing command\n\n");
		}
		
		if (cmd->num_cmds > 1) {	
			run_commands(cmd,mats,10);
		}
		if (line) {
			free(line);
		}
		destroy_commands(&cmd);
		line = readline("> ");
	}
	free(line);
	destroy_remaining_heap_allocations(mats,10);
	return 0;	
}
Example #7
0
void run_commands(unsigned int num_command, const char commands_list[max_commands][max_command_length], int to_file)
{
    if(to_file)
    {
        FILE* f = fopen("/home/box/result.out", "w");
        if(f)
        {
            close(STDOUT_FILENO);
            dup2(f->_fileno, STDOUT_FILENO);
            fclose(f);
        }
    }

    if(num_command > 0)
    {
        int pfd[2];
        pipe(pfd);

        if(!fork())
        {
            // child
            close(STDOUT_FILENO);
            dup2(pfd[1], STDOUT_FILENO);

            close(pfd[1]);
            close(pfd[0]);

            run_commands(num_command-1, commands_list, 0);
        }
        else
        {
            // parent
            close(STDIN_FILENO);
            dup2(pfd[0], STDIN_FILENO);

            close(pfd[1]);
            close(pfd[0]);

            char params[2][max_command_length];
            parce_command(commands_list[num_command], params);
            do_command(params);
        }
    }
    else
    {
        char params[2][max_command_length];
        parce_command(commands_list[num_command], params);
        do_command(params);
    }
}
Example #8
0
File: run.c Project: ameenross/dex
void handle_command(const struct command *cmds, const char *cmd)
{
	struct error *err = NULL;
	PTR_ARRAY(array);

	if (!parse_commands(&array, cmd, &err)) {
		error_msg("%s", err->msg);
		error_free(err);
		ptr_array_free(&array);
		return;
	}

	run_commands(cmds, &array);
	ptr_array_free(&array);
}
/* check to see if we need to run commands from the file */
gboolean check_file() {
	/* most of this was taken from Bash v2.04 by the FSF */
	struct stat finfo;
	char file[256];

	sprintf(file, "%s/.gaim/control", getenv("HOME"));

	if ((stat (file, &finfo) == 0) && (finfo.st_size > 0))
	{
		if (mtime != finfo.st_mtime) {
			gaim_debug(GAIM_DEBUG_INFO, "filectl",
					   "control changed, checking\n");
			run_commands();
		}
	}

	return TRUE;
}
Example #10
0
void	set_commands(char *command_line, char *paths, char ***env)
{
	int			i;
	t_command	*list;
	char		**split;

	if (syntax_error(command_line) == 0)
		return ;
	while (ft_strchr(command_line, '~') && get_elem(*env, "HOME=") != NULL)
		command_line = strchange(command_line, '~', get_elem(*env, "HOME="));
	split = ft_strsplit(command_line, ';');
	i = 0;
	while (split[i])
	{
		list = init_list(paths, split[i]);
		run_commands(list, env);
		i++;
	}
}
Example #11
0
int run_commands( cmd_node_t * head , char ** cvec )
{
   int ret;

   if(!head || !cvec ) error_ret("null args",-1);

   cmd_node_t * next;

   /* XXX: what if an argument to a command is also a command itself? */

   if(!(next = find_command( head->opts , cvec[0] ))) /* we're here */
   {
      if( head->cmd )
         ret = head->cmd->func( cvec );
      else
         error_ret("no command",-1);
   }
   else
      ret = run_commands( next , ++cvec );

   return(ret);
}
Example #12
0
int main(int argv, char** argc)
{
	const unsigned int command_line_length = max_commands*max_command_length;
    char commands_line[command_line_length];
    //gets(commands_line);
    //sprintf(commands_line, "who | sort | uniq -c | sort -nk1");
	fgets(commands_line, command_line_length, stdin);

    FILE* flog = fopen("log.txt", "a+");
    if(flog)
    {
        fprintf(flog, "%s\n", commands_line);
        fclose(flog);
    }

    char command_list[max_commands][max_command_length];
    unsigned int num_current_command = parce_command_list(commands_line, command_list);

    run_commands(num_current_command, command_list, 1);

    return 0;
}
Example #13
0
int main (int argc, char **argv) {
	srand(time(NULL));	
	char *line = NULL;
	Commands_t* cmd;
	line = readline("> ");

	Matrix_t mats[10];
	memset(&mats,0, sizeof(Matrix_t) * 10);

	while (strncmp(line,"exit", strlen("exit")  + 1) != 0) {
		
		if (!parse_user_input(line,&cmd)) {
			printf("ERROR\n\n");
		}
		
		run_commands(cmd,mats,10);

		free(line);
		destroy_commands(&cmd);
		line = readline("> ");
	}
	free(line);
	return 0;	
}
Example #14
0
blargg_err_t Vgm_Emu::run_clocks( blip_time_t& time_io, int msec )
{
	time_io = run_commands( msec * vgm_rate / 1000 );
	psg.end_frame( time_io );
	return 0;
}
Example #15
0
File: main.c Project: huynhrene/dex
int main(int argc, char *argv[])
{
	const char *term = getenv("TERM");
	const char *home = getenv("HOME");
	const char *tag = NULL;
	const char *rc = NULL;
	const char *command = NULL;
	char *command_history_filename;
	char *search_history_filename;
	char *editor_dir;
	bool read_rc = true;
	int i;

	if (!home)
		home = "";
	home_dir = xstrdup(home);

	for (i = 1; i < argc; i++) {
		const char *opt = argv[i];

		if (opt[0] != '-' || !opt[1])
			break;
		if (!opt[2]) {
			switch (opt[1]) {
			case 'R':
				read_rc = false;
				continue;
			case 't':
				tag = opt_arg(opt, argv[++i]);
				continue;
			case 'r':
				rc = opt_arg(opt, argv[++i]);
				continue;
			case 'c':
				command = opt_arg(opt, argv[++i]);
				continue;
			case 'V':
				printf("%s %s\nWritten by Timo Hirvonen\n", program, version);
				return 0;
			}
			if (opt[1] == '-') {
				i++;
				break;
			}
		}
		printf("Usage: %s [-R] [-V] [-c command] [-t tag] [-r rcfile] [file]...\n", argv[0]);
		return 1;
	}

	if (!isatty(1)) {
		fprintf(stderr, "stdout doesn't refer to a terminal\n");
		return 1;
	}
	if (term == NULL || term[0] == 0) {
		fprintf(stderr, "TERM not set\n");
		return 1;
	}
	switch (term_init(term)) {
	case -1:
		fprintf(stderr, "terminal is hardcopy\n");
		return 1;
	case -2:
		fprintf(stderr, "terminal could not be found\n");
		return 1;
	case -3:
		fprintf(stderr, "terminfo database could not be found\n");
		return 1;
	}

	// create this early. needed if lock-files is true
	editor_dir = editor_file("");
	mkdir(editor_dir, 0755);
	free(editor_dir);

	setlocale(LC_CTYPE, "");
	charset = nl_langinfo(CODESET);
	if (streq(charset, "UTF-8"))
		term_utf8 = true;

	exec_builtin_rc(builtin_rc);
	fill_builtin_colors();

	// NOTE: syntax_changed() uses window. should possibly create window after reading rc
	window = new_window();
	root_frame = new_root_frame(window);

	if (read_rc) {
		if (rc) {
			read_config(commands, rc, true);
		} else {
			char *filename = editor_file("rc");
			if (read_config(commands, filename, false)) {
				free(filename);
				filename = xsprintf("%s/rc", pkgdatadir);
				read_config(commands, filename, true);
			}
			free(filename);
		}
	}

	update_all_syntax_colors();
	sort_aliases();

	/* Terminal does not generate signals for control keys. */
	set_signal_handler(SIGINT, SIG_IGN);
	set_signal_handler(SIGQUIT, SIG_IGN);
	set_signal_handler(SIGPIPE, SIG_IGN);

	/* Terminal does not generate signal for ^Z but someone can send
	 * us SIGTSTP nevertheless. SIGSTOP can't be caught.
	 */
	set_signal_handler(SIGTSTP, handle_sigtstp);

	set_signal_handler(SIGCONT, handle_sigcont);
	set_signal_handler(SIGWINCH, handle_sigwinch);

	load_file_history();
	command_history_filename = editor_file("command-history");
	search_history_filename = editor_file("search-history");
	history_load(&command_history, command_history_filename, command_history_size);
	history_load(&search_history, search_history_filename, search_history_size);
	if (search_history.count)
		search_set_regexp(search_history.ptrs[search_history.count - 1]);

	/* Initialize terminal but don't update screen yet.  Also display
	 * "Press any key to continue" prompt if there were any errors
	 * during reading configuration files.
	 */
	term_raw();
	if (nr_errors) {
		any_key();
		clear_error();
	}

	editor_status = EDITOR_RUNNING;

	for (; i < argc; i++)
		window_open_buffer(window, argv[i], false, NULL);
	if (window->views.count == 0)
		window_open_empty_buffer(window);
	set_view(window->views.ptrs[0]);

	if (command || tag)
		resize();

	if (command)
		handle_command(commands, command);
	if (tag) {
		PTR_ARRAY(array);
		ptr_array_add(&array, xstrdup("tag"));
		ptr_array_add(&array, xstrdup(tag));
		ptr_array_add(&array, NULL);
		run_commands(commands, &array);
		ptr_array_free(&array);
	}
	resize();
	main_loop();
	ui_end();

	// unlock files and add files to file history
	remove_frame(root_frame);

	history_save(&command_history, command_history_filename);
	history_save(&search_history, search_history_filename);
	free(command_history_filename);
	free(search_history_filename);
	save_file_history();
	return 0;
}
Example #16
0
int main(int argc, char **argv)
{
  program_name = argv[0];
  static char stderr_buf[BUFSIZ];
  setbuf(stderr, stderr_buf);
  assert(NCOMMANDS <= MAX_COMMANDS);
  string Pargs, Largs, Fargs;
  int vflag = 0;
  int Vflag = 0;
  int zflag = 0;
  int iflag = 0;
  int Xflag = 0;
  int oflag = 0;
  int safer_flag = 1;
  int opt;
  const char *command_prefix = getenv("GROFF_COMMAND_PREFIX");
  if (!command_prefix)
    command_prefix = PROG_PREFIX;
  commands[TROFF_INDEX].set_name(command_prefix, "troff");
  static const struct option long_options[] = {
    { "help", no_argument, 0, 'h' },
    { "version", no_argument, 0, 'v' },
    { NULL, 0, 0, 0 }
  };
  while ((opt = getopt_long(argc, argv,
			    "abcCd:eEf:F:gGhiI:lL:m:M:n:No:pP:r:RsStT:UvVw:W:XzZ",
			    long_options, NULL))
	 != EOF) {
    char buf[3];
    buf[0] = '-';
    buf[1] = opt;
    buf[2] = '\0';
    switch (opt) {
    case 'i':
      iflag = 1;
      break;
    case 'I':
      commands[SOELIM_INDEX].set_name(command_prefix, "soelim");
      commands[SOELIM_INDEX].append_arg(buf, optarg);
      // .psbb may need to search for files
      commands[TROFF_INDEX].append_arg(buf, optarg);
      // \X'ps:import' may need to search for files
      Pargs += buf;
      Pargs += optarg;
      Pargs += '\0';
      break;
    case 't':
      commands[TBL_INDEX].set_name(command_prefix, "tbl");
      break;
    case 'p':
      commands[PIC_INDEX].set_name(command_prefix, "pic");
      break;
    case 'g':
      commands[GRN_INDEX].set_name(command_prefix, "grn");
      break;
    case 'G':
      commands[GRAP_INDEX].set_name(command_prefix, "grap");
      break;
    case 'e':
      commands[EQN_INDEX].set_name(command_prefix, "eqn");
      break;
    case 's':
      commands[SOELIM_INDEX].set_name(command_prefix, "soelim");
      break;
    case 'R':
      commands[REFER_INDEX].set_name(command_prefix, "refer");
      break;
    case 'z':
    case 'a':
      commands[TROFF_INDEX].append_arg(buf);
      // fall through
    case 'Z':
      zflag++;
      break;
    case 'l':
      lflag++;
      break;
    case 'V':
      Vflag++;
      break;
    case 'v':
      vflag = 1;
      {
	printf("GNU groff version %s\n", Version_string);
	printf("Copyright (C) 2004 Free Software Foundation, Inc.\n"
	       "GNU groff comes with ABSOLUTELY NO WARRANTY.\n"
	       "You may redistribute copies of groff and its subprograms\n"
	       "under the terms of the GNU General Public License.\n"
	       "For more information about these matters, see the file named COPYING.\n");
	printf("\ncalled subprograms:\n\n");
        fflush(stdout);
      }
      commands[POST_INDEX].append_arg(buf);
      // fall through
    case 'C':
      commands[SOELIM_INDEX].append_arg(buf);
      commands[REFER_INDEX].append_arg(buf);
      commands[PIC_INDEX].append_arg(buf);
      commands[GRAP_INDEX].append_arg(buf);
      commands[TBL_INDEX].append_arg(buf);
      commands[GRN_INDEX].append_arg(buf);
      commands[EQN_INDEX].append_arg(buf);
      commands[TROFF_INDEX].append_arg(buf);
      break;
    case 'N':
      commands[EQN_INDEX].append_arg(buf);
      break;
    case 'h':
      help();
      break;
    case 'E':
    case 'b':
      commands[TROFF_INDEX].append_arg(buf);
      break;
    case 'c':
      commands[TROFF_INDEX].append_arg(buf);
      break;
    case 'S':
      safer_flag = 1;
      break;
    case 'U':
      safer_flag = 0;
      break;
    case 'T':
      if (strcmp(optarg, "html") == 0) {
	// force soelim to aid the html preprocessor
	commands[SOELIM_INDEX].set_name(command_prefix, "soelim");
      }
      if (strcmp(optarg, "Xps") == 0) {
	warning("-TXps option is obsolete: use -X -Tps instead");
	device = "ps";
	Xflag++;
      }
      else
	device = optarg;
      break;
    case 'F':
      font::command_line_font_dir(optarg);
      if (Fargs.length() > 0) {
	Fargs += PATH_SEP_CHAR;
	Fargs += optarg;
      }
      else
	Fargs = optarg;
      break;
    case 'o':
      oflag = 1;
    case 'f':
    case 'm':
    case 'r':
    case 'd':
    case 'n':
    case 'w':
    case 'W':
      commands[TROFF_INDEX].append_arg(buf, optarg);
      break;
    case 'M':
      commands[EQN_INDEX].append_arg(buf, optarg);
      commands[GRAP_INDEX].append_arg(buf, optarg);
      commands[GRN_INDEX].append_arg(buf, optarg);
      commands[TROFF_INDEX].append_arg(buf, optarg);
      break;
    case 'P':
      Pargs += optarg;
      Pargs += '\0';
      break;
    case 'L':
      append_arg_to_string(optarg, Largs);
      break;
    case 'X':
      Xflag++;
      break;
    case '?':
      usage(stderr);
      exit(1);
      break;
    default:
      assert(0);
      break;
    }
  }
  if (safer_flag)
    commands[PIC_INDEX].append_arg("-S");
  else
    commands[TROFF_INDEX].insert_arg("-U");
  font::set_unknown_desc_command_handler(handle_unknown_desc_command);
  if (!font::load_desc())
    fatal("invalid device `%1'", device);
  if (!postdriver)
    fatal("no `postpro' command in DESC file for device `%1'", device);
  if (predriver && !zflag) {
    commands[TROFF_INDEX].insert_arg(commands[TROFF_INDEX].get_name());
    commands[TROFF_INDEX].set_name(predriver);
    // pass the device arguments to the predrivers as well
    commands[TROFF_INDEX].insert_args(Pargs);
    if (vflag)
      commands[TROFF_INDEX].insert_arg("-v");
  }
  const char *real_driver = 0;
  if (Xflag) {
    real_driver = postdriver;
    postdriver = (char *)GXDITVIEW;
    commands[TROFF_INDEX].append_arg("-r" XREG "=", "1");
  }
  if (postdriver)
    commands[POST_INDEX].set_name(postdriver);
  int gxditview_flag = postdriver && strcmp(xbasename(postdriver), GXDITVIEW) == 0;
  if (gxditview_flag && argc - optind == 1) {
    commands[POST_INDEX].append_arg("-title");
    commands[POST_INDEX].append_arg(argv[optind]);
    commands[POST_INDEX].append_arg("-xrm");
    commands[POST_INDEX].append_arg("*iconName:", argv[optind]);
    string filename_string("|");
    append_arg_to_string(argv[0], filename_string);
    append_arg_to_string("-Z", filename_string);
    for (int i = 1; i < argc; i++)
      append_arg_to_string(argv[i], filename_string);
    filename_string += '\0';
    commands[POST_INDEX].append_arg("-filename");
    commands[POST_INDEX].append_arg(filename_string.contents());
  }
  if (gxditview_flag && Xflag) {
    string print_string(real_driver);
    if (spooler) {
      print_string += " | ";
      print_string += spooler;
      print_string += Largs;
    }
    print_string += '\0';
    commands[POST_INDEX].append_arg("-printCommand");
    commands[POST_INDEX].append_arg(print_string.contents());
  }
  const char *p = Pargs.contents();
  const char *end = p + Pargs.length();
  while (p < end) {
    commands[POST_INDEX].append_arg(p);
    p = strchr(p, '\0') + 1;
  }
  if (gxditview_flag)
    commands[POST_INDEX].append_arg("-");
  if (lflag && !vflag && !Xflag && spooler) {
    commands[SPOOL_INDEX].set_name(BSHELL);
    commands[SPOOL_INDEX].append_arg(BSHELL_DASH_C);
    Largs += '\0';
    Largs = spooler + Largs;
    commands[SPOOL_INDEX].append_arg(Largs.contents());
  }
  if (zflag) {
    commands[POST_INDEX].set_name(0);
    commands[SPOOL_INDEX].set_name(0);
  }
  commands[TROFF_INDEX].append_arg("-T", device);
  // html renders equations as images via ps
  if (strcmp(device, "html") == 0) {
    if (oflag)
      fatal("`-o' option is invalid with device `html'");
    commands[EQN_INDEX].append_arg("-Tps:html");
  }
  else
    commands[EQN_INDEX].append_arg("-T", device);

  commands[GRN_INDEX].append_arg("-T", device);

  int first_index;
  for (first_index = 0; first_index < TROFF_INDEX; first_index++)
    if (commands[first_index].get_name() != 0)
      break;
  if (optind < argc) {
    if (argv[optind][0] == '-' && argv[optind][1] != '\0')
      commands[first_index].append_arg("--");
    for (int i = optind; i < argc; i++)
      commands[first_index].append_arg(argv[i]);
    if (iflag)
      commands[first_index].append_arg("-");
  }
  if (Fargs.length() > 0) {
    string e = "GROFF_FONT_PATH";
    e += '=';
    e += Fargs;
    char *fontpath = getenv("GROFF_FONT_PATH");
    if (fontpath && *fontpath) {
      e += PATH_SEP_CHAR;
      e += fontpath;
    }
    e += '\0';
    if (putenv(strsave(e.contents())))
      fatal("putenv failed");
  }
  {
    // we save the original path in GROFF_PATH__ and put it into the
    // environment -- troff will pick it up later.
    char *path = getenv("PATH");
    string e = "GROFF_PATH__";
    e += '=';
    if (path && *path)
      e += path;
    e += '\0';
    if (putenv(strsave(e.contents())))
      fatal("putenv failed");
    char *binpath = getenv("GROFF_BIN_PATH");
    string f = "PATH";
    f += '=';
    if (binpath && *binpath)
      f += binpath;
    else
      f += BINPATH;
    if (path && *path) {
      f += PATH_SEP_CHAR;
      f += path;
    }
    f += '\0';
    if (putenv(strsave(f.contents())))
      fatal("putenv failed");
  }
  if (Vflag)
    print_commands(Vflag == 1 ? stdout : stderr);
  if (Vflag == 1)
    exit(0);
  return run_commands(vflag);
}
Example #17
0
int main(int argc, char *argv[])
{
    int opt, ret = 0;
    int terminal_mode = 0;

    char *host = NULL;
    char *pass = "";
    char *port = "25575";

    if(argc < 2) usage();

    opterr = 1; /* default error handler enabled */
    while((opt = getopt(argc, argv, "tcshH:p:P:i")) != -1)
    {
        switch(opt)
        {
            case 'H': host = optarg;        break;
            case 'P': port = optarg;        break;
            case 'p': pass = optarg;        break;
            case 'C':
            case 'c': print_colors = 0;     break;
            case 'S':
            case 's': silent_mode = 1;      break;
            case 'T':
            case 't':
            case 'I':
            case 'i': terminal_mode = 1;    break;
            case 'h':
            case '?':
                /*
                if(optopt == 'P' || optopt == 'H' || optopt == 'p')
                    fprintf (stderr, "Option -%c requires an argument.\n\n", optopt);
                */

                /* else fprintf (stderr, "Unknown option -%c\n\n", optopt); */

                usage();
            break;

            default: abort();
        }
    }

    if(host == NULL) {
        fputs("Host not defined. Check -H flag.\n\n", stdout);
        usage();
    }

    if(optind == argc && terminal_mode == 0) {
        fputs("No commands specified.\n\n", stdout);
        usage();
    }

    /* safety features to prevent "IO: Connection reset" bug on the server side */
    atexit(&exit_proc);
    signal(SIGABRT, &sighandler);
    signal(SIGTERM, &sighandler);
    signal(SIGINT, &sighandler);

    #ifdef _WIN32
      net_init_WSA();
      console_handle = GetStdHandle(STD_OUTPUT_HANDLE);
      if(console_handle == INVALID_HANDLE_VALUE) console_handle = NULL;
    #endif

    /* open socket */
    rsock = net_open_socket(host, port);

    /* auth & commands */
    if(rcon_auth(rsock, pass))
    {
        if(terminal_mode)
            ret = run_terminal_mode(rsock);
        else
            ret = run_commands(argc, argv);
    }
    else /* auth failed */
    {
        ret = -1;
        fprintf(stdout, "Authentication failed!\n");
    }

    /* cleanup */
    net_close_socket(rsock);
    rsock = -1;

    return ret;
}
Example #18
0
int
main (int argc, char **argv)
{
    GMainLoop *loop;
    XigScreen *screen;
    XigVisual *visual;
    gchar *script_name, *config_file, *config_path;
    GString *command_line;
    gchar **compiz_env, **compiz_argv;
    gint compiz_stdin, compiz_stdout, compiz_stderr;
    GIOChannel *compiz_stdout_channel = NULL;
    GError *error = NULL;

    signal (SIGINT, signal_cb);
    signal (SIGTERM, signal_cb);

    g_type_init ();

    loop = g_main_loop_new (NULL, FALSE);

    if (argc != 2)
    {
        g_printerr ("Usage %s SCRIPT-NAME\n", argv[0]);
        quit (EXIT_FAILURE);
    }
    script_name = argv[1];
    config_file = g_strdup_printf ("%s.conf", script_name);
    config_path = g_build_filename (COMPIZ_XIG_TEST_SOURCE_DIR "/scripts", config_file, NULL);
    g_free (config_file);

    config = g_key_file_new ();
    g_key_file_load_from_file (config, config_path, G_KEY_FILE_NONE, NULL);

    load_script (config_path);

    /* Disable config if requested */
    if (g_key_file_has_key (config, "test-runner-config", "have-config", NULL) &&
        !g_key_file_get_boolean (config, "test-runner-config", "have-config", NULL))
        config_path = NULL;

    g_print ("----------------------------------------\n");
    g_print ("Running script %s\n", script_name);

    /* Create an X server to test with */
    xserver = xig_server_new ("compiz-test", 99);
    xig_server_set_listen_tcp (xserver, FALSE);
    g_signal_connect (xserver, "client-connected", G_CALLBACK (client_connected_cb), NULL);
    g_signal_connect (xserver, "client-disconnected", G_CALLBACK (client_disconnected_cb), NULL);
    xig_server_add_pixmap_format (xserver, 1, 1, 32);
    xig_server_add_pixmap_format (xserver, 4, 8, 32);
    xig_server_add_pixmap_format (xserver, 8, 8, 32);
    xig_server_add_pixmap_format (xserver, 15, 16, 32);
    xig_server_add_pixmap_format (xserver, 16, 16, 32);
    xig_server_add_pixmap_format (xserver, 24, 32, 32);
    xig_server_add_pixmap_format (xserver, 32, 32, 32);
    screen = xig_server_add_screen (xserver, 0x00FFFFFF, 0x00000000, 1024, 768, 1024, 768);
    visual = xig_screen_add_visual (screen, 24, XIG_VISUAL_CLASS_TrueColor, 8, 1, 0x00FF0000, 0x0000FF00, 0x000000FF);
    xig_screen_add_root (screen, visual);

    run_commands ();

    status_timeout = g_timeout_add (STATUS_TIMEOUT, status_timeout_cb, NULL);

    if (!xig_server_start (xserver, &error))
    {
        g_printerr ("Failed to start Xig X server: %s", error->message);
        quit (EXIT_FAILURE);
    }

    compiz_env = g_strsplit ("DISPLAY=:99", " ", -1);
    command_line = g_string_new (compiz_BINARY_DIR "/src/compiz");
    g_print ("Start Compiz with command: %s\n", command_line->str);
    if (!g_shell_parse_argv (command_line->str, NULL, &compiz_argv, &error))
    {
        g_warning ("Error parsing command line: %s", error->message);
        quit (EXIT_FAILURE);
    }
    g_clear_error (&error);
    if (!g_spawn_async_with_pipes (NULL, /* working directory */
                                   compiz_argv,
                                   compiz_env,
                                   G_SPAWN_DO_NOT_REAP_CHILD,
                                   NULL, NULL, /* child setup */
                                   &compiz_pid,
                                   &compiz_stdin,
                                   &compiz_stdout,
                                   &compiz_stderr,
                                   &error))
    {
        g_warning ("Error launching Compiz: %s", error->message);
        quit (EXIT_FAILURE);
    }
    g_clear_error (&error);
    g_child_watch_add (compiz_pid, compiz_exit_cb, NULL);
    if (getenv ("DEBUG"))
        g_print ("Compiz running with PID %d\n", compiz_pid);

    compiz_stdout_channel = g_io_channel_unix_new (compiz_stdout);
    g_io_channel_set_flags (compiz_stdout_channel, G_IO_FLAG_NONBLOCK, NULL);
    g_io_add_watch (compiz_stdout_channel, G_IO_IN, client_stdout_cb, NULL);

    check_status ("COMPIZ START");

    g_main_loop_run (loop);

    g_object_unref (compiz_stdout_channel);

    return EXIT_FAILURE;
}
Example #19
0
void main_game_loop(void)
{

 ALLEGRO_EVENT ev;

 int fps = 0;
 int cps = 0;
 int force_display_update = 0; // display always runs at least once each second
 int playing = 1;

 view.fps = 0;
 view.cycles_per_second = 0;


 int skip_frame = 0; // if game is running too slowly, it will skip frames to save drawing time.
// if (game.phase == GAME_PHASE_PREGAME)
//  skip_frame = 1; // display is not updated during pregame phase.

 do // main game loop
 {
//  if (game.phase != GAME_PHASE_PREGAME) // no input in pregame phase
   get_ex_control(0, (game.pause_soft == 0)); // ex_control needs to be updated even when halted (control will not be updated)

   run_input();

  	run_panels();

   run_editor();
/*
// should probably run display at the end of the loop rather than the start
//  - so that the game has run through at least once when loading game
  if (!skip_frame || force_display_update)
  {
   run_display();
   fps ++;
   force_display_update = 0;
  }
*/
  game.total_time++;

//  if (game.pause_hard == 0)
//  {


//   if (view.focus_proc != NULL
//    && view.focus_proc->exists != 1) // will be -1 if proc has just been deallocated
//   {
//    view.focus_proc = NULL;
  //  reset_proc_box_height(NULL);
//   } // need to find a better place to put this

   if (game.phase == GAME_PHASE_WORLD
				|| game.phase == GAME_PHASE_OVER) // game continues to run while over.
			{
				if (!game.pause_soft)
				{
				if (game.watching != WATCH_PAUSED_TO_WATCH)
    {

//    if (run_turns()) // returns 0 if game has left world phase (e.g. because time has run out), 1 if still in world phase
     {
     	if (game.watching == WATCH_FINISHED_AND_STOP_WATCHING
						 || game.watching == WATCH_FINISHED_BUT_STILL_WATCHING
						 || game.watching == WATCH_FINISHED_JUST_STOP_PAUSING)
						{
        w.core[bcp_state.watch_core_index].next_execution_timestamp = w.world_time;
        run_cores_and_procs(bcp_state.watch_core_index);
        w.core[bcp_state.watch_core_index].next_execution_timestamp = w.world_time + EXECUTION_COUNT;
        switch(game.watching)
        {
        	case WATCH_FINISHED_AND_STOP_WATCHING:
 									game.watching = WATCH_OFF;
									 bcp_state.watch_core_index = -1;
									 bcp_state.bcp_mode = BCP_MODE_EMPTY;
									 break;
        	case WATCH_FINISHED_BUT_STILL_WATCHING:
  								game.watching = WATCH_ON;
  								break;
        	case WATCH_FINISHED_JUST_STOP_PAUSING:
  								game.watching = WATCH_OFF;
  								break;
        }
						}
						 else
							{
        run_world(); // runs the world and also the mission, if this is a mission. Can end the game.
// should run_world be after the next three function calls? Maybe.

//      run_clouds(); clouds don't need to be run
        run_fragments();
        run_cores_and_procs(-1);
							}

						if (game.watching != WATCH_PAUSED_TO_WATCH) // this may have been set in either of the run_cores_and_procs() calls above
						{

       run_packets();

       cps ++;
       w.world_time ++;
       w.world_seconds = (w.world_time - BASE_WORLD_TIME) / 60;

       update_vision_area(); // update fog of war after w.world_time is incremented so that the vision_time timestamps are up to date

       if (game.phase != GAME_PHASE_OVER)
						 {
        if (game.type == GAME_TYPE_BASIC)
						 	 run_custom_game();
						    else
						 			 run_mission(); // for now ignore return values
						 }

       play_sound_list();

						}

     }
    } // end if (!game.pause_watch)
     else
						run_bcode_watch();
				} // end if (!game.pause_soft)
   } // end game phase test

   if (game.phase == GAME_PHASE_OVER)
			{
					game.fast_forward = 0;
     if (run_game_over())
						break; // user clicked game over button
			}

   if (game.phase == GAME_PHASE_PREGAME)
			{
					game.fast_forward = 0;
     run_pregame();
			}

//   w.total_time ++; // total_time is affected by hard pause, but unlike world_time is not affected by soft pause (so it can only be used for things that don't affect gameplay, like console line highlighting)

//   run_input(); // this derives control (available to programs) from ex_control. doesn't need to be run for user to be able to use mode buttons and interact with sysmenu/editor/templates etc (as these use ex_control directly)

   if (game.phase == GAME_PHASE_FORCE_QUIT)
				break; // can be set in run_input() if user clicks on quit in system menu

   run_commands();

   view.just_resized = 0;

// fps_queue generates an event once each second - used for calculating fps and forcing a display update at least once per second
  if (al_get_next_event(fps_queue, &ev))
  {
   view.fps = fps;
   fps = 0;
   view.cycles_per_second = cps;
   cps = 0;
//   if (game.phase != GAME_PHASE_PREGAME)
//    force_display_update = 1; // this is checked next time through this loop (see display call above)
  }

//  if (!skip_frame)
  {
//  	run_panels();

//     run_editor();
// may need to set playing to 0 here if player quits using sysmenu

/*   switch(settings.edit_window)
   {
    case EDIT_WINDOW_EDITOR:
     run_editor(); break;
    case EDIT_WINDOW_TEMPLATES:
     run_templates(); break;
    case EDIT_WINDOW_SYSMENU:
     playing = run_sysmenu(); break;
//    case EDIT_WINDOW_PROGRAMS:
//     run_programs_menu(); break;
   }*/
  }

  if (playing == 0)
   break;

  run_consoles(); // I think it's okay to call this even when halted

  skip_frame = 0;

// check for fast-forward (skip). Ignore FF if not in world, or if paused
  if (game.fast_forward > 0
   && game.phase == GAME_PHASE_WORLD // let's not allow ff in GAME_PHASE_OVER
   && game.pause_soft == 0
   && game.watching != WATCH_PAUSED_TO_WATCH)
//   && game.pause_hard == 0)
   {
    switch (game.fast_forward_type)
    {
     case FAST_FORWARD_TYPE_NO_DISPLAY:
      if (game.fast_forward == FAST_FORWARD_JUST_STARTED)
       game.fast_forward = FAST_FORWARD_ON; // don't skip this frame (to prevent a delay before "FAST FORWARD" message appears on screen)
        else
								{
/*									if (fps == 0)
									{
          fps = 1;
									}
									 else*/
           skip_frame = 1;
//           else
								}
      break;

     case FAST_FORWARD_TYPE_SMOOTH:
      game.fast_forward = FAST_FORWARD_ON;
      al_flush_event_queue(event_queue);
      break;
     case FAST_FORWARD_TYPE_SKIP:
      game.fast_forward = FAST_FORWARD_ON;
      if (w.world_time % 8 != 0)
							skip_frame = 1;
      break;
/*     case FAST_FORWARD_TYPE_8X:
      game.fast_forward = FAST_FORWARD_ON;
      if (w.world_time % 8 != 0)
							skip_frame = 1;
      break;*/
    }
   }

// now check whether the timer has expired during game processing. If it has, don't generate a display this tick (unless force_display_update==1)
  if (al_get_next_event(event_queue, &ev))
  {
//   switch(ev.type)
//   {
//    case ALLEGRO_EVENT_TIMER: this should be the only possible type.
     skip_frame = 1;
//     break;
//   }
//   al_flush_event_queue(event_queue);
  }

  if (!skip_frame || force_display_update)
  {
   run_display();
   fps ++;
   force_display_update = 0;
  }


// wait for the timer so we can go to the next tick (unless we're fast-forwarding or the timer has already expired)
  if (!skip_frame
   && (game.fast_forward == FAST_FORWARD_OFF
				|| game.pause_soft
				|| game.watching == WATCH_PAUSED_TO_WATCH)) // don't skip frames if paused, even if fast-forwarding
  {
   al_wait_for_event(event_queue, &ev);
//   al_flush_event_queue(event_queue);
  }

 } while (TRUE); // end main game loop

// if game has been finished or quit, we can end up here outside the loop

}
Example #20
0
int run_command( char ** cvec )
{
   return( run_commands( &command_head  , cvec ) );
}