예제 #1
0
파일: main.c 프로젝트: kompass/kgdflow
/**
* \fn int main(int argc, char *argv[])
* \brief Fonction principale.
*
*
* La fonction principale récupère les arguments et le fichier de configuration,
* initialise la vue, le modèle, puis éxécute la boucle de calcul.
* Une fois cette boucle terminée, elle libère la mémoire et finalise l'éxécution.
*
*
*/
int main(int argc, char *argv[])
{
	config_t *conf = parse_args(argc, argv);

	int error = 0;
	error_t *error_cell = NULL;

	if(conf == NULL)
	{
		return 1;
	}

	view_t *view = init_view(conf);

	model_t *model = init_model(conf);

	double delta_time = 0;
	event_t event;

	init_event(&event);

	vect_t chunk_pos;
	init_vect(&chunk_pos, 0.4, 0.4, 0.4);
	add_chunk(model, &chunk_pos);
	//add_chunk(model, &chunk_pos);
	//add_chunk(model, &chunk_pos);
	//add_chunk(model, &chunk_pos);
	//add_chunk(model, &chunk_pos);
	//add_chunk(model, &chunk_pos);


	while(!event.exit_wanted)
	{
		delta_time = temporize(conf);
		get_event(&event, view);

		if(event.click_callback != NULL)
			(*(event.click_callback))(model);

		error = update_model(model, &event, delta_time);

		if(error)
		{
			printf("ERREUR DETECTEE !\n");
			error_cell = get_error_list();
			int error_count = 0;

			while(error_cell != NULL)
			{
				printf("%s\n", error_cell->comment);
				error_cell = error_cell->next;
				error_count++;
				if(error_count >= 10)
				{
					printf("Appuyez sur ENTREE pour voir la suite, q puis ENTREE pour quitter.\n");
					if(getchar() == 'q')
						return 1;
					error_count = 0;
				}
			}
			return 1;
		}

		update_view(view, model, &event);
	}

	close_conf(conf);
	close_view(view);
	close_model(model);

	return 0;
}
예제 #2
0
파일: keywords.c 프로젝트: bluejack/Zn
int zn_shell_exec(command *cmd)
{
  pid_t pid;
  int status = 0;
  char* arglist[MAX_ARG_LIST];
  char* appname = command_next_arg(cmd);
  char  path_buffer[FILENAME_MAX];
  arglist[0] = appname;
  bool wait_for_pid = true;
  
  if (*appname != '/') {
    appname = _find_file_in_path(path_buffer, appname);
    if (!appname) {
      display_err("%s not found\n", arglist[0]);
      return -1;
    }
  }

  int c = 1;

  while (c < MAX_ARG_LIST) {
    char* arg = (char*)command_next_arg(cmd);
    if (arg && strcmp(arg, "&") == 0) {
      wait_for_pid = false;
    } else {
      arglist[c++] = arg;
    }
    if (arg == NULL) break; /* break after writing null to term the list. */
  }

  /* Special shell view should be suspended until shell resumes. */
  close_view();

  switch(pid = fork()) {
  case -1:
    /* Fork failed! */
    fprintf(stderr, "Failed to execute.\n");
    break;
  case 0: 
    /* Child process */
    status = execve(appname, arglist, zn_env);
    /* If we got here, exec failed. TODO: Figure out why. */
    fprintf(stderr, "Failed to execute %s.\n", appname);
    exit(status);
  default:
    /* Parent */
    if (wait_for_pid) {
      if (waitpid(pid, &status, 0) < 0) {
	/* Wait for pid failed!! */
	fprintf(stderr, "System error tracking process %s\n", appname);
      }
      if ( !WIFEXITED(status)) {      
	fprintf(stderr, "Debug, system error -- exit failure?\n");
      }
    } else {
      printf("Started Process %d\n", pid);
    }

    initialize_view();

  }

  return status;
}