Ejemplo n.º 1
0
// Main
// =================================================================================================
int main (int argc, char* argv[]) {
  Cons *c1 = create(1);
  Cons *c2 = create(2);
  Cons *c3 = create(3);
  Cons *c4 = create(4);
  Cons *c5 = create(5);

  c1->next = c2;
  c2->next = c3;
  c3->next = c4;
  c4->next = c5;

  Cons *first = c1;

  printf("normal: ");
  forEach(first, printer);

  // 1つ目
  Cons *squared = mapList(first, square);
  printf("\nsquare: ");
  forEach(squared, printer);

  // 2つ目
  Cons *inced = mapList(first, inc);
  printf("\n   inc: ");
  forEach(inced, printer);
  
  // incしたのを更にsquare
  Cons *squinc = mapList(inced, square);
  printf("\nsquinc: ");
  forEach(squinc, printer);

  // squareをsquare
  Cons *quad = mapList(squared, square);
  printf("\n  quad: ");
  forEach(quad, printer);

  // 元のリストが破壊されてないことを確認
  printf("\nnormal: ");
  forEach(first, printer);

  printf("\n   inc: ");
  forEach(inced, printer);

  
  printf("\n");

  release(first);
  release(squared);
  release(inced);
  release(squinc);
  release(quad);
}
Ejemplo n.º 2
0
// Map
// =================================================================================================
Cons* mapList (Cons* xs, MapFn f) {
  if (xs == NULL) {
    return NULL;
  }

  Cons* cell = create(f(xs->value));
  cell->next = mapList(xs->next, f);

  return cell;
}
Ejemplo n.º 3
0
int main()
{
  /* test de la liste */
  pthread_t th_test1 = 14862153215624521;
  /*pthread_t th_test2;
  pthread_t th_test3;
  pthread_t th_test4;*/
  
  Liste testList = creatList();
  printf("liste vide creee\n");
  
  if(isEmpty(testList))
    printf("la liste est bien vide\n");
  else 
  {
    printf("erreur liste non vide !\n") ;
    exit(99);
  }
  
  testList = addInList(testList, th_test1);
  printf("ajout d'un element dans la liste\n");
  
  mapList(testList);
  
  testList = removeFromList(testList, th_test1);
  
   if(isEmpty(testList))
    printf("la liste est bien vide\n");
   else
   {
    printf("erreur liste non vide !\n") ;
    exit(99);
  }
  
  destroyList(testList);
  
  /*Fin des test de la liste*/
  return 0;
}
Ejemplo n.º 4
0
int FieldArchivePS::open(const QString &path, ArchiveObserver *progress)
{
	FieldPS *field;
	QString desc;
	int i, currentMap=0, fieldID=0;

	if(iso)		delete iso;
	iso = new FF8DiscArchive(path);
	if(!iso->open(QIODevice::ReadOnly)) {
		errorMsg = QObject::tr("Impossible d'ouvrir le fichier image disque. (%1)").arg(iso->errorString());
		return 1;
	}

	if(!iso->findIMG()) {
		errorMsg = QObject::tr("Fichier FF8DISC?.IMG introuvable.");
		return 4;
	}

	const QList<FF8DiscFile> &fieldFiles = iso->fieldDirectory();
	int tocSize = fieldFiles.size();
	const int tocStart = iso->isDemo() ? 0 : 77;

	if(tocSize == 0) {
		errorMsg = QObject::tr("Impossible d'ouvrir le dossier field.");
		return 4;
	}

	clearFields();
	setMapList(QStringList());
	int indexOf;

	quint32 freq = ((tocSize - tocStart) / 3)/100;

	if(freq == 0) {
		freq = 1;
	}

	progress->setObserverMaximum((tocSize - tocStart) / 3);

	for(i=tocStart ; i<tocSize ; i += 3) {
		QCoreApplication::processEvents();
		if(progress->observerWasCanceled()) {
			clearFields();
			errorMsg = QObject::tr("Ouverture annulée.");
			return 2;
		}
		if(currentMap % freq == 0) {
			progress->setObserverValue(currentMap);
		}

		QByteArray fieldData = iso->fileLZS(fieldFiles.at(i));

		if(!fieldData.isEmpty()) {
			if (iso->isDemo()) {
				field = new FieldJpDemoPS(i);
			} else {
				field = new FieldPS(i);
			}
			if(field->open(fieldData)) {
				if(field->hasJsmFile())
					desc = Data::location(field->getJsmFile()->mapID());
				else
					desc = QString();

				indexOf = mapList().indexOf(field->name());
				QString mapId = indexOf==-1 ? "~" : QString("%1").arg(indexOf, 3, 10, QChar('0'));

				fields.append(field);
				fieldsSortByName.insert(field->name(), fieldID);
				fieldsSortByDesc.insert(desc, fieldID);
				fieldsSortByMapId.insert(mapId, fieldID);
				++fieldID;
			} else {
				delete field;
			}
		}
		++currentMap;
	}

	if(fields.isEmpty()) {
		errorMsg = QObject::tr("Aucun écran trouvé.");
		return 4;
	}

	openModels();

	if(iso->isJp() && Config::value("encoding", "00").toString() == "00") {
		Config::setValue("encoding", "01");
	} else if(!iso->isJp() && Config::value("encoding", "00").toString() == "01") {
		Config::setValue("encoding", "00");
	}

	return 0;
}