Exemplo n.º 1
0
/*Si le hero rencontre un coffre en ce deplacant,on le supprime
 * de la salle et on ajoute son contenu au hero*/
void OuvrirCoffre(salle s,hero h){
	if(s->z[h->x][h->y].C!=NULL){
		if((s->z[h->x][h->y]).C->ouvert==faux){
			if ((s->z[h->x][h->y]).C->inv!=NULL) {
				transfert((s->z[h->x][h->y]).C->inv,h->invHero);
				s->z[h->x][h->y].C->ouvert=vrai;
			}
			else
				h->pieces+=s->z[h->x][h->y].C->pieces;
		}
	}
}
Exemplo n.º 2
0
int main(){
  char ligne[MaxLigne];
  char pathname[MaxPathLength];
  char * mot[MaxMot];
  char * dirs[MaxDirs];
  char * wd;
  int i, tmp;
  short plsr;

  plsr=0; //cette commande comporte-elle plusieurs instructions?

  /* Decouper UNE COPIE de PATH en repertoires */
  decouper(strdup(getenv("PATH")), ":", dirs, MaxDirs);

  /* Lire et traiter chaque ligne de commande */
  for(wd=getcwd(NULL,0),printf("%s%s",wd,PROMPT); fgets(ligne, sizeof ligne, stdin) != NULL; wd=getcwd(NULL,0),printf("%s%s",wd,PROMPT)){
    free(wd);

    /* Traitement des ^C et ^Z */
    if (signal(SIGINT,SIG_IGN) == SIG_ERR)
      perror("signal");
    if (signal(SIGTSTP,ctrl) == SIG_ERR)
      perror("signal");
    if (signal(SIGQUIT,ctrl) == SIG_ERR)
      perror("signal");

    /* Traitement des "&" et des ";" */
    plsr=plusieurs(ligne);


    decouper(ligne, " \t\n", mot, MaxMot);
    if (mot[0] == NULL){            // ligne vide
      if(!plsr)
        continue;
      exit(0);
    }

    /*Traitement de la commande cd*/
    if (!strcmp(mot[0],"cd")){
      cd(mot,plsr);
      continue;
    }

    /*Traitement des commandes fg et bg*/
    if (!strcmp(mot[0],"fg")){
      fg();
      if(!plsr)
        continue;
      exit(0);
    }
    if (!strcmp(mot[0],"bg")){
      bg();
      if(!plsr)
        continue;
      exit(0);
    }


    if(!plsr){
      tmp = fork();               // lancer le processus enfant uniquement si ce n'est pas déjà un enfant à cause d'une multiplicité de commande
      if (tmp < 0){
        perror("fork");
        continue;
      }

      if (tmp != 0){             // parent : attendre la fin de l'enfant
        enfant=tmp;
        waitpid(tmp,NULL,WUNTRACED);
        enfant=0;
        continue;
      }
    }

				// enfant : exec du programme
    /* Traitement des "<", ">" ">>" et "2>" */
    redir(mot);


    /* Traitement des "|" */
    transfert(mot);

    
    for(i = 0; dirs[i] != NULL; i++){
      snprintf(pathname, sizeof pathname, "%s/%s", dirs[i], mot[0]);
      execv(pathname, mot);
    }
                                // aucun exec n'a fonctionne
    fprintf(stderr, "%s: not found\n", mot[0]);
    exit(1);
  }

  printf("Bye\n");
  return 0;

}
Exemplo n.º 3
0
int main(int argc, char *argv[])
{
	try
	{
		COptionParser optParser(appliOption, appliName, appliUsageShort, appliUsageLong, authorName, authorMail);
		
		optParser.PrintHeader(std::cout);

		if (!optParser.ParseCommandLine(&argc, &argv, 0, false))
		{
			optParser.PrintError(std::cout);
			optParser.PrintUsage(std::cout);
			return -1;
		}

		bool noLoop = false;
		std::string COMport = defaultComPort();
		std::string filename = "";
		std::string dir = "";
		int baudrate = 115200;

		
		int i=0;
		while (optParser.GetOptionI(i) != 0)
		{
			switch(optParser.GetOptionI(i))
			{
			case 'p':
				{
					COMport = optParser.GetStringOptionI(i);
					break;
				}
			case 'b':
				{
					baudrate = optParser.GetIntOptionI(i);
					break;
				}
			case 'f':
				{
					filename = optParser.GetStringOptionI(i);
					noLoop = true;
					break;
				}
			case 'd':
				{
					dir = optParser.GetStringOptionI(i);
					break;
				}
			case 'n':
				{
					noLoop = true;
					break;
				}
			default:
				{
					break;
				}
			}

			i++;
		}

		for(unsigned int i = 0; i < sizeof(devicePrefixes) / sizeof(devicePrefixes[0]); i++)
		{
			std::string device = devicePrefixes[i] + COMport;
			CAksFileTransfert transfert(device, baudrate);

			if (!transfert.IsOpen())
				continue;
			else
				std::cout << "AFT now listening on " << device << std::endl;

			if (filename.size() != 0)
				transfert.SetForceFilename(filename);

			if (dir.size() != 0)
				transfert.SetFilepath(dir);

			while (!noLoop || (noLoop && (transfert.GetNbTransfertDone() != 1)))
				transfert.Run();

			return 0;
		}

		std::cout << "Unable to open COM port " << COMport << std::endl;
		return -1;
	}
	catch(tools::CException &e)
	{
		std::cerr << e << std::endl;
		return -1;
	}
}