Example #1
0
//read a state
void readState(int index){
	int i, aux;
	char a;
	
	states[index].id = index;
	//read the state parameters
	scanf("%f %d %d", &states[index].reward, &aux, &states[index].n_actions);
	
	if(aux == 1)
		states[index].n_actions = 0;
		
	i = 0;
	while(i < states[index].n_actions){
		a = getchar();
		
		if(a == '#')
			ignoreComments();
			
		else if(a == 45 || (a > 47 && a < 58)){
			ungetc(a, stdin);
			readAction(index, i);
			i++;
		}
	}
}
Example #2
0
Image *ImLoad::readImage(const char *fn){
  ifstream imfile(fn, ios::binary);
  if (!imfile.is_open()) {
    cerr << "Sorry, could not open: " << fn << endl;
    exit(0);
  }

  // Reading file header
  char P;
  char num;
  imfile >> P >> num; 
  ignoreComments(imfile);

  // Read image dimensions and extremum value
  int width, height, extr;
  imfile >> width;
  ignoreComments(imfile);
  imfile >> height;
  ignoreComments(imfile);
  imfile >> extr;

  // Check whether the file is OK
  if (P != 'P' || num != '5' ||
      width <= 0 || height <= 0 ||
      extr > 255) {
    cerr << "Input image has to be PGM format" << endl;
    exit(0);
  }

  // Get the image intensities and normalise to 0 - 1.
  imfile.get();
  Image *im = new Image(width, height);
  for (int y = 0; y < height; y++)
    for (int x = 0; x < width; x++)
      im->setPix(x, y, ((double) imfile.get()) / extr);
  return im;
}
Example #3
0
//Verifies all code lines(taking comments, labels and blank lines).
char* verifyLine(char *aux)
{
    //Takes the '\n'
    char *line = removeLast(aux);

    //If is not a blank line
    if (line != NULL)
        line = ignoreComments(line);

    //If is not only a comment
    if(line == NULL)
        return NULL;

    //If there is a label
    char *instruction = strchr(line, ':');
    if (instruction != NULL)
    {
        //Take the label
        char* label = strchr(strrev(line), ':');
        label = strrev(strchr(label, label[1]));

        //Inserts on hash
        addLabel(label, numberOfData + numberOfInstructions);
        //If is not a instruction too
        if (instruction[1] == '\0')
            return NULL;

        line = strchr(strrev(line), ':');
        //right clean
        int i = 0;
        line = ++line;
        while(line[i] == ' ')
            line = ++line;

    }
    line = leftClean(line);
    if(line == NULL)
        return NULL;

    return line;
}
Example #4
0
//méthode permettant d'extraire les microinstructions
vector<string> extractionInstructions()
{
	string ligne;
	vector<string> temp;
	//lecture des instructions
	//on va chercher les jeux d'instructions
	ifstream finInstrSet("jeu_Ins.txt", ios::in);
	if(!finInstrSet)
	{
		cout << "impossible d'ouvrir le fichier des jeux d'instructions" << endl;
		exit (EXIT_FAILURE);
	}
	//on parcourt le fichier qui contient les jeux d'instructions et on enregistre chaque ligne dans un vecteur
	while(getline(finInstrSet, ligne))
	{
		ligne = ignoreComments(ligne);
		if(!ligne.empty())
			temp.push_back(trim(ligne, " \t"));
	}
	// si le fichier est vide!
	if(temp.empty())
	{
		cerr << "Votre fichier est vide ! " << endl;
		exit (EXIT_FAILURE);
	}
	finInstrSet.close();
	//on va traiter les instructions afin de les séparer des bits d'activations des signaux
	map<string, string> temporaire = traitementInstructions(temp);
	//après avoir chargé les lignes des jeux d'instructions dans la map, on aprête les vecteurs à ne recevoir que les opcodes
	temp.clear();
	for(map<string, string>::iterator it = temporaire.begin(); it != temporaire.end(); ++it)
	{
		//it->second représente que les opcodes
		temp.push_back(it->second);
	}
	//on retourne le vecteur après la fin de la lecture du fichier
	return temp;
}