Exemple #1
0
int		main(int argc, char **argv)
{
	char	*mapp;
	char	**tab;
	int		i;

	i = 0;
	if (argc != 2 || open(argv[1], O_RDONLY) == -1)
	{
		ft_putstr("error\n");
		return (0);
	}
	tab = tetritab(argv[1]);
	if (entrycheck(tab) == 0 || filecheck(argv[1]) == 0 || tabcount(tab) > 26)
	{
		ft_putstr("error\n");
		return (0);
	}
	else
	{
		tab = alphaconvert(tetriconvert(tab));
		mapp = squarefind(tab);
		ft_putstr(mapp);
	}
	return (0);
}
BOOL CGeometryProcDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
	CString fn = lpszPathName;
	char* filename = NULL;
	auto UnicodeToAnsi = [](char** file, CString& fn)
	{
		int P_Length = fn.GetLength();
		int nBytes = WideCharToMultiByte(CP_ACP, 0, fn, P_Length, NULL, 0, NULL, NULL);
		*file = new char[nBytes + 1];
		memset(*file, 0, P_Length + 1);
		WideCharToMultiByte(CP_OEMCP, 0, fn, P_Length, *file, nBytes, NULL, NULL);
	};
	UnicodeToAnsi(&filename, fn);
	string filecheck(filename);
	filecheck = filecheck.substr(filecheck.size()-4);
	std::transform(filecheck.begin(), filecheck.end(), filecheck.begin(), tolower);

	if (filecheck == (".stl"))
	{
		TriMesh* mesh = NULL;
		mesh = TriMesh::read_stl_helper(filename);
		mesh->need_bbox();
		meshes.push_back(mesh);
		Current_mesh = meshes.size() - 1;
		return TRUE;
	}
	return FALSE;
}
Exemple #3
0
//append a file
void append( int argc, char *argv[]) {
    int file, fd;
    char fname[16];
    struct stat info;
    struct ar_hdr hdr;
    int flag = 0;
    
    if (!(filecheck(argv[2]))){
        printf("%s dose not exist. Creating new Archive.\n",argv[2]);
    } else {
        printf("%s open.\n", argv[2]);
    }
    fd = open(argv[2], O_CREAT | O_APPEND | O_WRONLY, 0666);
    
    if(flag){
        printf("myar: %s: creating\n", argv[2]);
        write(fd, ARMAG, SARMAG);
    }
    printf("myar: %s\n", argv[2]);
    lseek(fd, 0, SEEK_END);
    
    for(int i = 3;i < argc; i++) {
        if ((file = open(argv[i], O_RDONLY)) < 0) {
            printf("myar: %s: No such file or directory\n",argv[i]);
            break;
        }
        printf("myar: testloop %s\n",argv[i]);
        if (fstat(file, &info) == 0) {                strcpy(fname, argv[i]);
            sprintf(hdr.ar_name, "%-11s", strcat(fname,"\0"));
            sprintf(hdr.ar_date, "%-15u", (uint32_t) info.st_mtime);
            sprintf(hdr.ar_uid, "%-10u", (uint32_t) info.st_uid);
            sprintf(hdr.ar_gid, "%-10u", (uint32_t) info.st_gid);
            sprintf(hdr.ar_mode, "%-10o", (uint32_t) info.st_mode);
            sprintf(hdr.ar_size, "%-10u", (uint32_t) info.st_size);
            memcpy(hdr.ar_fmag, ARFMAG, sizeof(hdr.ar_fmag));
            write(fd, (char*) &hdr, sizeof(hdr));
            write(fd, &ARFMAG, 2);
        } else {
            printf("myar: unable to archive %c.\n", fname[i]);
            exit(EXIT_FAILURE);
        }
        char buff[info.st_size];
        int buffering = sizeof(buff);
        read(file, buff, buffering);
        write(fd, buff, buffering);
        
        if (info.st_size % 2) {
            write(fd, "\n", 1);
        }
        close(file);
    }
}
Exemple #4
0
/*
 * Initilize drifile object and check file
 *   file    : file name array
 *   cnt     : number in file name array
 *   mmapping: mmap file or not
 *   return: drifile object
*/
drifiles *dri_init(char **file, int cnt, boolean mmapping) {
	drifiles *d = g_new0(drifiles, 1);
	FILE *fp;
	int i;
	boolean gotmap = FALSE;
	long filesize;
	char **filetop = file;
	
	for (i = 0; i < cnt; i++) {
		if (*(file + i) == NULL) continue;
		/* open check */
		if (NULL == (fp = fopen(*(file + i), "r"))) {
			SYSERROR("File %s is not found\n", *(file + i));
		}
		/* check is drifile or noe */
		if (!filecheck(fp)) {
			SYSERROR("File %s is not dri file\n", *(file + i));
		}
		/* get file map */
		if (!gotmap) {
			get_filemap(d, fp);
			gotmap = TRUE;
		}
		/* get pointer */
		get_fileptr(d, fp, i);
		/* get file size for mmap */
		filesize = getfilesize(fp);
		/* copy filenme */
		d->fnames[i] = strdup(*(file + i));
		/* close */
		fclose(fp);
		/* mmap */
		if (mmapping) {
			int fd;
			if (0 > (fd = open(*(file + i),  O_RDONLY))) {
				SYSERROR("open: %s\n", strerror(errno));
			}
			if (MAP_FAILED == (d->mmapadr[i] = mmap(0, filesize, PROT_READ, MAP_SHARED, fd, 0))) {
				WARNING("mmap: %s\n", strerror(errno));
				close(fd);
				mmapping = d->mmapped = FALSE;
				i = 0; file = filetop; /* retry */
				continue;
			}
			d->mmapped = TRUE;
		}
	}
	return d;
}
Exemple #5
0
int main(int argc, char **argv) {
  if (argc != 2) {
    usage();
    return 2;
  }

  if (!(checkstream = fopen(argv[1], "r"))) {
    fprintf(stderr, "filecheck: unable to open file '%s' for reading.\n", argv[1]);
    return 2;
  }

  return filecheck(argv[1], &check_in,
                   "<stdin>", &in,
                   &out, &err);
}
Exemple #6
0
void
MainWindow::setSizeLabel(const QString &fileName)
{
    if (fileName != "")
    {
        QFile filecheck(fileName);
        if(filecheck.exists())
        {
            int size = filecheck.size() / (1024*1024);
            fileSize->setText("(<b>" + QString::number(size) + " MB</b>)" );
        }
    }
    else
    {
        fileSize->setText("");
    }
    return;
}
Exemple #7
0
bool config_check(const char *filename) {
    char tmp[512];

    if(!js) {
        warning("javascript is not initialized");
        warning("no configuration is loaded");
        return(false);
    }

    snprintf(tmp, 512, "%s/.freej/%s", getenv("HOME"), filename);
    if(filecheck(tmp)) {
        js->open(tmp);
        return(true);
    }

    snprintf(tmp, 512, "/etc/freej/%s", filename);
    if(filecheck(tmp)) {
        js->open(tmp);
        return(true);
    }

#ifdef HAVE_DARWIN
    snprintf(tmp, 512, "%s/%s", "CHANGEME", filename);
#else
    snprintf(tmp, 512, "%s/%s", DATADIR, filename);
#endif
    if(filecheck(tmp)) {
        js->open(tmp);
        return(true);
    }

    snprintf(tmp, 512, "/usr/lib/freej/%s", filename);
    if(filecheck(tmp)) {
        js->open(tmp);
        return(true);
    }

    snprintf(tmp, 512, "/usr/local/lib/freej/%s", filename);
    if(filecheck(tmp)) {
        js->open(tmp);
        return(true);
    }

    snprintf(tmp, 512, "/opt/video/lib/freej/%s", filename);
    if(filecheck(tmp)) {
        js->open(tmp);
        return(true);
    }
    return(false);
}
Exemple #8
0
int getapikey(char* apikey, char* fname){
  // Check if vtconfig exists
  if(!filecheck(fname)){
    printf("No vtconfig found!\n");
    printf("First start? Enter apikey here: ");

    // fgets puts his own nullterminator, so the char array is 65 bytes long, so the first 64 bytes are filled with the apikey
    fgets(apikey, APIKEY_SIZE, stdin);
    
    // checking if the API-key is valid
    int i;
    for(i = 0; i < 65; i++){
      if(!isxdigit(apikey[i])){
        printf("Error, the API-Key is not valid!\n");
        printf("The API-Key must contain hexdigits\n");
        return 0;
        }
    }

    FILE *f = fopen(fname, "w"); // Write apikey to config for next start
    if(f == NULL){
      printf("Error while opening the %s. Please check the file permissions \n", fname); 
      return 0;
    } 

    fprintf(f, apikey);
    fclose(f);

  } 
  else{
    FILE *f = fopen(fname, "r"); // Read out key if file already exists
    if(f == NULL){
      printf("Error while opening the %s. Please check the file permissions \n", fname); 
      return 0;
    }

    fgets(apikey, APIKEY_SIZE, f);
    fclose(f);
    return 1;
  } 
} 
Exemple #9
0
int main(int argc, char *argv[])
{
  int continuing = 0;
  int count;
  int scores_only = 0;
  int i;

#ifndef NOGETOPT
  while(( i= getopt( argc, argv, "dsh")) != -1)
  {
     switch (i)
     {
       case 'd':
#ifdef DEBUG
         DG_debug_flag++;
#endif
         break;
       case 's':
         scores_only = 1;
         break;
       case 'h':
#ifdef DEBUG
         printf("Usage: omega [-shd] [savefile]\n");
#else
         printf("Usage: omega [-sh] [savefile]\n");
#endif
         printf("Options:\n");
         printf("  -s  Display high score list\n");
         printf("  -h  Display this message\n");
#ifdef DEBUG
         printf("  -d  Enable debug mode\n");
#endif
         exit(0);
         break;
       case '?':
         /* error parsing args... ignore? */
         printf("'%c' is an invalid option, ignoring\n", optopt );
         break;
     }
  }

  if (optind >= argc ) {
    /* no save file given */
#if defined( BSD ) || defined( SYSV )
    sprintf( SaveFileName, "Omega%d", getuid() );
#else
    strcpy( SaveFileName,"Omega");
#endif
  } else {
    /* savefile given */
    continuing = 1;
    strcpy(SaveFileName,argv[optind]);
  }

#else 
  /* alternate code for people who don't support getopt() -- no enhancement */
  if (argc ==2) {
    strcpy( SaveFileName, argv[1]);
    continuing = 1;
  } else {
    strcpy( SaveFileName,"Omega");
  }
#endif

  /* always catch ^c and hang-up signals */

#ifdef SIGINT
  signal(SIGINT,signalquit);
#endif
#ifdef SIGHUP
  signal(SIGHUP,signalsave);
#endif

#ifndef MSDOS
  if (CATCH_SIGNALS) {
    signal(SIGQUIT,signalexit);
    signal(SIGILL,signalexit);
#ifdef DEBUG
    if( DG_debug_flag ) {
#endif
    signal(SIGTRAP,signalexit);
    signal(SIGFPE,signalexit);
    signal(SIGSEGV,signalexit);
#ifdef DEBUG
    }
#endif
#ifdef SIGIOT
    signal(SIGIOT,signalexit);
#endif
#ifdef SIGABRT
    signal(SIGABRT,signalexit);
#endif
#ifdef SIGEMT
    signal(SIGEMT,signalexit);
#endif
#ifdef SIGBUS
    signal(SIGBUS,signalexit);
#endif
#ifdef SIGSYS
    signal(SIGSYS,signalexit);
#endif
    }
#endif

#ifndef FIXED_OMEGALIB
  if (!(Omegalib = getenv("OMEGALIB")))
#endif
    Omegalib = OMEGALIB;

  /* if filecheck is 0, some necessary data files are missing */
  if (filecheck() == 0) exit(0);

  /* all kinds of initialization */
  init_perms();
  initgraf();
#ifndef MSDOS_SUPPORTED_ANTIQUE
  initdirs();
#endif
  initrand(E_RANDOM, 0);
  initspells();

#ifdef DEBUG
  /* initialize debug log file */
  DG_debug_log = fopen( "/tmp/omega_dbg_log", "a" );
  assert( DG_debug_log ); /* WDT :) */
  setvbuf( DG_debug_log, NULL, _IOLBF, 0);
  fprintf(DG_debug_log, "##############  new game started ##############\n");
#endif

  for (count = 0; count < STRING_BUFFER_SIZE; count++)
    strcpy(Stringbuffer[count],"<nothing>");

#ifdef SAVE_LEVELS
  msdos_init();
#endif

  omega_title();
  showscores();

  if (scores_only ) {
    endgraf();
    exit(0);
  }

  /* game restore attempts to restore game if there is an argument */
  if (continuing) 
  {
     game_restore(SaveFileName);
     mprint("Your adventure continues....");
  }
  else
  {
    /* monsters initialized in game_restore if game is being restored */  
    /* items initialized in game_restore if game is being restored */
    inititem(TRUE);
    Date = random_range(360);
    Phase = random_range(24);
#ifdef NEW_BANK
    bank_init();
#else
    strcpy(Password,"");
#endif
    continuing = initplayer(); /* RM: 04-19-2000 loading patch */
  }
  if (!continuing)
  {
    init_world();  /* RM: 04-19-2000 loading patch */
    mprint("'?' for help or commandlist, 'Q' to quit.");
  }

  timeprint();
  calc_melee();
  if (Current_Environment != E_COUNTRYSIDE)
    showroom(Level->site[Player.x][Player.y].roomnumber);
  else
    terrain_check(FALSE);
  
  if (optionp(SHOW_COLOUR))
    colour_on();
  else
    colour_off();

  screencheck(Player.x,Player.y);

 /* game cycle */
  if (!continuing)
    time_clock(TRUE);
  while (TRUE) {
    if (Current_Environment == E_COUNTRYSIDE)
      p_country_process();
    else time_clock(FALSE);
  }
}
Exemple #10
0
molecule_t *read_insertion_molecules(system_t *system) {

	int j;

	molecule_t *molecules, 
	           *molecule_ptr;

	atom_t     *atom_ptr, 
	           *prev_atom_ptr;

	char       linebuf[MAXLINE], *n;

	FILE       *fp;
	char       token_atom[MAXLINE], token_atomid[MAXLINE], token_atomtype[MAXLINE],
	           token_moleculetype[MAXLINE],
	           token_frozen[MAXLINE],
	           token_moleculeid[MAXLINE],
	           token_x[MAXLINE], token_y[MAXLINE], token_z[MAXLINE],
	           token_mass[MAXLINE],
	           token_charge[MAXLINE],
	           token_alpha[MAXLINE], token_epsilon[MAXLINE], token_sigma[MAXLINE], 
	           token_omega[MAXLINE], token_gwp_alpha[MAXLINE],
		   token_c6[MAXLINE], token_c8[MAXLINE], token_c10[MAXLINE], token_c9[MAXLINE];
	
	int        current_frozen, 
	           current_adiabatic,
	           current_spectre, 
	           current_target,
	           current_moleculeid, 
	           current_atomid,
	           current_site_neighbor;
	double     current_x, current_y, current_z,
	           current_mass,  current_charge, 
	           current_alpha, current_epsilon, current_sigma, current_omega, current_gwp_alpha,
		   current_c6, current_c8, current_c10, current_c9; 

	int        atom_counter;


	// allocate the start of the list 
	molecules           = calloc(1, sizeof(molecule_t));
	memnullcheck(molecules,sizeof(molecule_t),__LINE__-1, __FILE__);
	molecule_ptr        = molecules;
	molecule_ptr->id    = 1;
	molecule_ptr->atoms = calloc(1, sizeof(atom_t));
	memnullcheck(molecule_ptr->atoms,sizeof(atom_t),__LINE__-1, __FILE__);
	atom_ptr            = molecule_ptr->atoms;
	prev_atom_ptr       = atom_ptr;
	
	// open the molecule input file 
	fp = fopen(system->insert_input, "r");
	filecheck(fp,system->insert_input,READ);

	// clear the linebuffer and read the tokens in 
	atom_counter = 0;
	memset(linebuf, 0, MAXLINE);
	n = fgets(linebuf, MAXLINE, fp);
	while(n) {

		// clear the tokens 
		memset( token_atom,         0, MAXLINE);
		memset( token_atomid,       0, MAXLINE);
		memset( token_atomtype,     0, MAXLINE);
		memset( token_moleculetype, 0, MAXLINE);
		memset( token_frozen,       0, MAXLINE);
		memset( token_moleculeid,   0, MAXLINE);
		memset( token_x,            0, MAXLINE);
		memset( token_y,            0, MAXLINE);
		memset( token_z,            0, MAXLINE);
		memset( token_mass,         0, MAXLINE);
		memset( token_charge,       0, MAXLINE);
		memset( token_alpha,        0, MAXLINE);
		memset( token_epsilon,      0, MAXLINE);
		memset( token_sigma,        0, MAXLINE);
		memset( token_omega,        0, MAXLINE);
		memset( token_gwp_alpha,    0, MAXLINE);
		memset(token_c6,            0, MAXLINE);
		memset(token_c8,            0, MAXLINE);
		memset(token_c10,           0, MAXLINE);
		memset(token_c9,            0, MAXLINE);

		// parse the input line 
		sscanf(linebuf, "%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s\n", 
		       token_atom, token_atomid, token_atomtype, 
		       token_moleculetype, 
		       token_frozen, 
		       token_moleculeid, 
		       token_x, token_y, token_z, 
		       token_mass, token_charge, 
		       token_alpha, token_epsilon, token_sigma, token_omega, token_gwp_alpha,
		       token_c6, token_c8, token_c10, token_c9
		);

		if(!strcasecmp(token_atom, "ATOM") && strcasecmp(token_moleculetype, "BOX")) {

			current_frozen = 0; current_adiabatic = 0; current_spectre = 0; current_target = 0;
			if(!strcasecmp(token_frozen, "F"))
				current_frozen = 1;
			if(!strcasecmp(token_frozen, "A"))
				current_adiabatic = 1;
			if(!strcasecmp(token_frozen, "S"))
				current_spectre = 1;
			if(!strcasecmp(token_frozen, "T"))
				current_target = 1;

			current_moleculeid    = atoi(token_moleculeid);
			current_atomid        = atoi(token_atomid);
			current_x             = atof(token_x);
			current_y             = atof(token_y);
			current_z             = atof(token_z);
			current_mass          = atof(token_mass);	// mass in amu 
			current_charge        = atof(token_charge);
			current_charge       *= E2REDUCED;		// convert charge into reduced units  
			current_alpha         = atof(token_alpha);
			current_epsilon       = atof(token_epsilon);
			current_sigma         = atof(token_sigma);
			current_omega         = atof(token_omega);
			current_gwp_alpha     = atof(token_gwp_alpha);
			current_c6            = atof(token_c6);
			current_c8            = atof(token_c8);
			current_c10           = atof(token_c10);
			current_c9            = atof(token_c9);

			if ( system->cdvdw_sig_repulsion ) {
				if ( current_epsilon != 1.0 ) {
					error("warning: setting epsilon to 1.0 (due to sig_repulsion)\n");
					current_epsilon = 1.0;
				}
			}
			else if ( system->polarvdw ) {
				if ( current_sigma != 1.0 ) {
					error("warning: setting sigma to 1.0 (due to polarvdw)\n");
					current_sigma = 1.0;
				}
			}

			// Functionality of site_neighbor disabled in favor of omega/gwp_alpha parameters
			// Current behavior is to default to atom 0, typically the center of mass for
			// the molecule.
			current_site_neighbor = 0;

			if(current_frozen)
				current_charge *= system->scale_charge;

			if(molecule_ptr->id != current_moleculeid) {
				molecule_ptr->next = calloc(1, sizeof(molecule_t));
				memnullcheck(molecule_ptr->next,sizeof(molecule_t),__LINE__-1, __FILE__);
				molecule_ptr = molecule_ptr->next;
				molecule_ptr->atoms = calloc(1, sizeof(atom_t));
				memnullcheck(molecule_ptr->atoms,sizeof(atom_t),__LINE__-1, __FILE__);
				prev_atom_ptr->next = NULL;
				free(atom_ptr);
				atom_ptr = molecule_ptr->atoms;
			}
			strcpy(molecule_ptr->moleculetype, token_moleculetype);

			molecule_ptr->id        = current_moleculeid;
			molecule_ptr->frozen    = current_frozen;
			molecule_ptr->adiabatic = current_adiabatic;
			molecule_ptr->spectre   = current_spectre;
			molecule_ptr->target    = current_target;
			molecule_ptr->mass     += current_mass;

#ifdef QM_ROTATION
			/* if quantum rot calc. enabled, allocate the necessary structures */
			if(system->quantum_rotation && !molecule_ptr->frozen && !molecule_ptr->quantum_rotational_energies )
				allocqmrotation(system,molecule_ptr);
#endif /* QM_ROTATION */

#ifdef XXX
			/* if quantum vib calc. enabled, allocate the necessary structures */
			if(system->quantum_vibration && !molecule_ptr->frozen)
				allocqmvibration(system,molecule_ptr);
#endif /* XXX */

			++atom_counter;
			atom_ptr->id        = atom_counter;
			atom_ptr->bond_id   = current_atomid;
			memset(atom_ptr->atomtype, 0, MAXLINE);
			strcpy(atom_ptr->atomtype, token_atomtype);
			atom_ptr->frozen    = current_frozen;
			atom_ptr->adiabatic = current_adiabatic;
			atom_ptr->spectre   = current_spectre;
			atom_ptr->target    = current_target;
			atom_ptr->pos[0]    = current_x;
			atom_ptr->pos[1]    = current_y;
			atom_ptr->pos[2]    = current_z;
			atom_ptr->mass      = current_mass;
			atom_ptr->charge    = current_charge;
			atom_ptr->polarizability = current_alpha;
			atom_ptr->epsilon   = current_epsilon;
			atom_ptr->sigma     = current_sigma;
			atom_ptr->omega     = current_omega;
			atom_ptr->gwp_alpha = current_gwp_alpha;
			atom_ptr->c6 = current_c6;
			atom_ptr->c8 = current_c8;
			atom_ptr->c10 = current_c10;
			atom_ptr->c9 = current_c9;
			if(current_gwp_alpha != 0.)
				atom_ptr->gwp_spin = 1;
			else
				atom_ptr->gwp_spin = 0;

			atom_ptr->site_neighbor_id = current_site_neighbor;
			atom_ptr->next = calloc(1, sizeof(atom_t));
			memnullcheck(atom_ptr->next,sizeof(atom_t),__LINE__-1, __FILE__);
			prev_atom_ptr  = atom_ptr;
			atom_ptr       = atom_ptr->next;
		}

		memset(linebuf, 0, MAXLINE);
		n = fgets(linebuf, MAXLINE, fp);
	}

	// terminate the atom list 
	prev_atom_ptr->next = NULL;
	free(atom_ptr);



	// Count the molecules and create an array of pointers, where each pointer
	// points directly to a molecule in the linked list. While counting the 
	// molecules, check to see whether or not each sorbate is included in the
	// sorbate statistics list, if it is not, we will create an entry for it
	// so that each unique class of sorbate will have its own node in the stats
	// list.
	/////////////////////////////////////////////////////////////////////////////

	// count	
	int molecule_counter = 0;
	for(molecule_ptr = molecules; molecule_ptr; molecule_ptr = molecule_ptr->next) { 
		molecule_counter++;
		// Check to see if this molecule is a new sorbate.
		if( sorbateIs_Not_InList(system, molecule_ptr->moleculetype) ) {
			system->sorbateCount++;
			addSorbateToList(system, molecule_ptr->moleculetype);
			for ( j=0; j<system->sorbateCount; j++ ) {
				if( !strcasecmp( system->sorbateInfo[j].id, molecule_ptr->moleculetype )){
					system->sorbateInfo[j].mass = molecule_ptr->mass;
					break;
				}
			}
		}
	}

	// allocate space for array that will give direct access to insertion-candidate
	// molecules in the linked list. 
	system->insertion_molecules_array = malloc( molecule_counter * sizeof(molecule_t*) );
	memnullcheck(system->insertion_molecules_array, molecule_counter*sizeof(molecule_t *), __LINE__-1, __FILE__);

	// point array pointers to their corresponding molecules
	molecule_counter=0;
	for(molecule_ptr = molecules; molecule_ptr; molecule_ptr = molecule_ptr->next) { 
		system->insertion_molecules_array[ molecule_counter ] = molecule_ptr;
		molecule_counter++;
	}
	system->num_insertion_molecules = molecule_counter;

	  //  ERROR CHECKING OF SOME SORT MAY NEED TO GO HERE
	 //   WHAT'S ALLOWED/DISALLOWED FOR INSERTED MOLECULES?
	/////////////////////////////////////////////////////////

	fclose(fp);
	
	return(molecules);
}
Exemple #11
0
std::pair <bool,bool> OBJECTLOADER::ContinueObjectLoad(	TRACK* track, 
	std::map <std::string, MODEL_JOE03> & model_library,
	std::map <std::string, TEXTURE_GL> & texture_library,
	std::list <TRACK_OBJECT> & objects,
 	const std::string & texture_size)
{
	std::string model_name;

	if (error)
		return std::pair <bool,bool> (true, false);

	if (!(GetParam(objectfile, model_name)))
	{
		info_output << "Track loaded: " << model_library.size() << " models, " << texture_library.size() << " textures, " << /*surfaces.size() << " surfaces" << */std::endl;
		return std::pair <bool,bool> (false, false);
	}

	assert(objectfile.good());

	std::string diffuse_texture_name;
	bool mipmap;
	bool nolighting;
	bool skybox;
	int transparent_blend;
	float bump_wavelength;
	float bump_amplitude;
	bool driveable;
	bool collideable;
	float friction_notread;
	float friction_tread;
	float rolling_resistance;
	float rolling_drag;
	bool isashadow(false);
	int clamptexture(0);
	int surface_type(2);

	std::string otherjunk;

	GetParam(objectfile, diffuse_texture_name);
	GetParam(objectfile, mipmap);
	GetParam(objectfile, nolighting);
	GetParam(objectfile, skybox);
	GetParam(objectfile, transparent_blend);
	GetParam(objectfile, bump_wavelength);
	GetParam(objectfile, bump_amplitude);
	GetParam(objectfile, driveable);
	GetParam(objectfile, collideable);
	GetParam(objectfile, friction_notread);
	GetParam(objectfile, friction_tread);
	GetParam(objectfile, rolling_resistance);
	GetParam(objectfile, rolling_drag);
	
	if (params_per_object >= 15)
		GetParam(objectfile, isashadow);
	
	if (params_per_object >= 16)
		GetParam(objectfile, clamptexture);
	
	if (params_per_object >= 17)
		GetParam(objectfile, surface_type);
		
		
	for (int i = 0; i < params_per_object - expected_params; i++)
		GetParam(objectfile, otherjunk);

	MODEL * model(NULL);

	if (model_library.find(model_name) == model_library.end())
	{
		if (packload)
		{
			if (!model_library[model_name].Load(model_name, error_output, true, &pack))
			{
				error_output << "Error loading model: " << objectpath + "/" + model_name << " from pack " << objectpath + "/objects.jpk" << std::endl;
				return std::pair <bool, bool> (true, false); //fail the entire track loading
			}
		}
		else/**/
		{
			if (!model_library[model_name].Load(objectpath + "/" + model_name, /*NULL,*/ error_output))
			{
				error_output << "Error loading model: " << objectpath + "/" + model_name << std::endl;
				return std::pair <bool, bool> (true, false); //fail the entire track loading
			}
		}
		model = &model_library[model_name];
	}

	bool skip = false;
	bool bNewMtr = false;///
	
	if (dynamicshadowsenabled && isashadow)
		skip = true;

	if (texture_library.find(diffuse_texture_name) == texture_library.end())
	{
		bNewMtr = true;///
		TEXTUREINFO texinfo;
		texinfo.SetName(objectpath + "/" + diffuse_texture_name);
		texinfo.SetMipMap(mipmap || anisotropy); //always mipmap if anisotropy is on
		texinfo.SetAnisotropy(anisotropy);
		bool clampu = clamptexture == 1 || clamptexture == 2;
		bool clampv = clamptexture == 1 || clamptexture == 3;
		texinfo.SetRepeat(!clampu, !clampv);
		if (!texture_library[diffuse_texture_name].Load(texinfo, error_output, texture_size))
		{
			error_output << "Error loading texture: " << objectpath + "/" + diffuse_texture_name << ", skipping object " << model_name << " and continuing" << std::endl;
			skip = true; //fail the loading of this model only
		}
	}

	if (!skip)
	{
		reseatable_reference <TEXTURE_GL> miscmap1;
		std::string miscmap1_texture_name = diffuse_texture_name.substr(0,std::max(0,(int)diffuse_texture_name.length()-4));
		miscmap1_texture_name += std::string("-misc1.png");
		if (texture_library.find(miscmap1_texture_name) == texture_library.end())
		{
			TEXTUREINFO texinfo;
			std::string filepath = objectpath + "/" + miscmap1_texture_name;
			texinfo.SetName(filepath);
			texinfo.SetMipMap(mipmap);
			texinfo.SetAnisotropy(anisotropy);

			std::ifstream filecheck(filepath.c_str());
			if (filecheck)
			{
				if (!texture_library[miscmap1_texture_name].Load(texinfo, error_output, texture_size))
				{
					error_output << "Error loading texture: " << objectpath + "/" + miscmap1_texture_name << " for object " << model_name << ", continuing" << std::endl;
					texture_library.erase(miscmap1_texture_name);
					//don't fail, this isn't a critical error
				}
				else
					miscmap1 = texture_library[miscmap1_texture_name];
			}
		}
		else
			miscmap1 = texture_library.find(miscmap1_texture_name)->second;

		TEXTURE_GL * diffuse = &texture_library[diffuse_texture_name];
		
		TRACK_OBJECT object(model, diffuse, /*surfacePtr*/collideable || driveable );
		objects.push_back(object);

		///-------------  push for ogre
		//bool mipmap;	bool nolighting;
		//bool isashadow(false);
		//int clamptexture(0);

		OGRE_MESH om;
		om.found = true;
		om.sky = skybox;
		om.alpha = transparent_blend;

		om.newMtr = bNewMtr;
		om.name = model_name;
		om.material = diffuse_texture_name;
		om.mesh = &model->mesh;
		
		track->ogre_meshes.push_back(om);///
	}

	return std::pair <bool, bool> (false, true);
}
int
main (int argc, char *argv[])
{
  int error;
  struct REGEX_INTERNAL_Automaton *a;
  unsigned int i;
  const char *filename = "test_graph.dot";

  const char *regex[12] = {
    "ab(c|d)+c*(a(b|c)+d)+(bla)+",
    "(bla)*",
    "b(lab)*la",
    "(ab)*",
    "ab(c|d)+c*(a(b|c)+d)+(bla)(bla)*",
    "z(abc|def)?xyz",
    "1*0(0|1)*",
    "a*b*",
    "a+X*y+c|p|R|Z*K*y*R+w|Y*6+n+h*k*w+V*F|W*B*e*",
    "a",
    "a|b",
    "PADPADPADPADPADPabcdefghixxxxxxxxxxxxxjklmnop*qstoisdjfguisdfguihsdfgbdsuivggsd"
  };

  GNUNET_log_setup ("test-regex", "WARNING", NULL);
  error = 0;
  for (i = 0; i < 12; i++)
  {
    /* Check NFA graph creation */
    a = REGEX_INTERNAL_construct_nfa (regex[i], strlen (regex[i]));
    REGEX_TEST_automaton_save_graph (a, filename, REGEX_TEST_GRAPH_DEFAULT);
    REGEX_INTERNAL_automaton_destroy (a);
    error += filecheck (filename);

    a = REGEX_INTERNAL_construct_nfa (regex[i], strlen (regex[i]));
    REGEX_TEST_automaton_save_graph (a, filename,
                                       REGEX_TEST_GRAPH_DEFAULT |
                                       REGEX_TEST_GRAPH_VERBOSE);
    REGEX_INTERNAL_automaton_destroy (a);
    error += filecheck (filename);

    a = REGEX_INTERNAL_construct_nfa (regex[i], strlen (regex[i]));
    REGEX_TEST_automaton_save_graph (a, filename,
                                       REGEX_TEST_GRAPH_DEFAULT |
                                       REGEX_TEST_GRAPH_COLORING);
    REGEX_INTERNAL_automaton_destroy (a);
    error += filecheck (filename);

    a = REGEX_INTERNAL_construct_nfa (regex[i], strlen (regex[i]));
    REGEX_TEST_automaton_save_graph (a, filename,
                                       REGEX_TEST_GRAPH_DEFAULT |
                                       REGEX_TEST_GRAPH_VERBOSE |
                                       REGEX_TEST_GRAPH_COLORING);
    REGEX_INTERNAL_automaton_destroy (a);
    error += filecheck (filename);


    /* Check DFA graph creation */
    a = REGEX_INTERNAL_construct_dfa (regex[i], strlen (regex[i]), 0);
    REGEX_TEST_automaton_save_graph (a, filename, REGEX_TEST_GRAPH_DEFAULT);
    REGEX_INTERNAL_automaton_destroy (a);
    error += filecheck (filename);

    a = REGEX_INTERNAL_construct_dfa (regex[i], strlen (regex[i]), 0);
    REGEX_TEST_automaton_save_graph (a, filename,
                                       REGEX_TEST_GRAPH_DEFAULT |
                                       REGEX_TEST_GRAPH_VERBOSE);
    REGEX_INTERNAL_automaton_destroy (a);
    error += filecheck (filename);

    a = REGEX_INTERNAL_construct_dfa (regex[i], strlen (regex[i]), 0);
    REGEX_TEST_automaton_save_graph (a, filename,
                                       REGEX_TEST_GRAPH_DEFAULT |
                                       REGEX_TEST_GRAPH_COLORING);
    REGEX_INTERNAL_automaton_destroy (a);
    error += filecheck (filename);


    a = REGEX_INTERNAL_construct_dfa (regex[i], strlen (regex[i]), 4);
    REGEX_TEST_automaton_save_graph (a, filename, REGEX_TEST_GRAPH_DEFAULT);
    REGEX_INTERNAL_automaton_destroy (a);
    error += filecheck (filename);

  }

  return error;
}