Exemple #1
0
void Pipeline::BuildAtlasStage(QHash<QString,ImageList> images, Task* task)
{
	for(const QString& resolution : images.keys())
	{
		int width = task->atlasParams.sizes[resolution].width();
		int height = task->atlasParams.sizes[resolution].height();

		if(!MathUtils::IsPowerOfTwo(width) || !MathUtils::IsPowerOfTwo(height))
		{
			QString error = ERROR_MASK.arg(task->name).arg("Sizes of atlas for resolution \"%1\" must be power of two");
			errors.push_back(error.arg(resolution));
			return;
		}

		QPair<QImage,QJsonObject> atlas = atlasBuilder.Run(images[resolution], width, height,
			task->outputFormat, task->atlasParams);

		// Save atlas image
		QString imageFilename = MakeFilename(task->atlasParams.name, resolution, ExtensionForFormat(task->outputFormat));
		if(!SaveImage(atlas.first, task->outputDir, imageFilename, task->outputFormat))
		{
			errors.push_back(ERROR_MASK.arg(task->name).arg(ERROR_SAVE_MASK.arg(imageFilename)));
			return;
		}

		// Save atlas json description
		QDir outputDir(task->outputDir);
		QString filename = MakeFilename(task->atlasParams.name, resolution, "atlas");
		QFile file(outputDir.absoluteFilePath(filename));
		if(!file.open(QIODevice::WriteOnly))
		{
			errors.push_back(ERROR_MASK.arg(task->name).arg(ERROR_SAVE_MASK.arg(filename)));
			return;
		}

		QJsonDocument doc(atlas.second);
		file.write(doc.toJson());

		auto atlasErrors = atlasBuilder.GetErrors();
		if(!atlasErrors.empty())
		{
			for(auto& error : atlasErrors)
			{
				QString resError = QString("%1 for \"%2\" resolution").arg(error).arg(resolution);
				errors.push_back(ERROR_MASK.arg(task->name).arg(resError));
			}
		}

		UpdateProgress();
	}
}
void ServicesList :: AddService (const char * const service_name_s, ServicePrefsWidget *services_widget_p)
{
	char * const icon_path_s = MakeFilename ("images", service_name_s);
	QString service_name (service_name_s);
	ServicesListItem *item_p = 0;

	if (icon_path_s)
		{
			QIcon icon (icon_path_s);

			item_p = new ServicesListItem (icon, service_name, sl_services_p);
			FreeCopiedString (icon_path_s);
		}
	else
		{
			item_p = new ServicesListItem (service_name, sl_services_p);
		}

	sl_services_p -> addItem (item_p);
	int index = sl_stacked_widgets_p -> addWidget (services_widget_p);

	item_p -> setCheckState (Qt :: Unchecked);
	item_p -> setFlags (Qt :: ItemIsEnabled | Qt :: ItemIsUserCheckable | Qt :: ItemIsSelectable);

	connect (services_widget_p, &ServicePrefsWidget :: RunStatusChanged, this, &ServicesList :: SetServiceRunStatus);
}
Exemple #3
0
void Pipeline::ResizeStage(ImageList images, Task* task)
{
	// Resize images and split it by resolutions
	QHash<QString, ImageList> imagesByRes;
	for(QString res : task->outputRes)
	{
		imagesByRes[res] = resizer.Run(images, task->sourceRes, res, task->potSize);
		UpdateProgress();
	}

	// Pass images to build atals stage
	if(task->atlas) BuildAtlasStage(imagesByRes, task);

	// Save resized images without building atlas
	else
	{
		for(const QString& resolution : imagesByRes.keys())
		{
			for(auto entry : imagesByRes[resolution])
			{
				QString filename = MakeFilename(entry.first, resolution, ExtensionForFormat(task->outputFormat));
				if(!SaveImage(entry.second, task->outputDir, filename, task->outputFormat))
				{
					errors.push_back(ERROR_MASK.arg(task->name).arg(ERROR_SAVE_MASK.arg(filename)));
				}
			}
		}
	}
}
Exemple #4
0
static void Compile (const char* File)
/* Compile the given file */
{
    /* Remember the current compiler argument count */
    unsigned ArgCount = CC65.ArgCount;

    /* Set the target system */
    CmdSetTarget (&CC65, Target);

    /* Check if this is the final step */
    if (DoAssemble) {
        /* We will assemble this file later. If a dependency file is to be
        ** generated, set the dependency target to be the final object file,
        ** not the intermediate assembler file. But beware: There may be an
        ** output name specified for the assembler.
        */
        if (DepName || FullDepName) {
            /* Was an output name for the assembler specified? */
            if (!DoLink && OutputName) {
                /* Use this name as the dependency target */
                CmdAddArg2 (&CC65, "--dep-target", OutputName);
            } else {
                /* Use the object file name as the dependency target */
                char* ObjName = MakeFilename (File, ".o");
                CmdAddArg2 (&CC65, "--dep-target", ObjName);
                xfree (ObjName);
            }
        }
    } else {
        /* If we won't assemble, this is the final step. In this case, set
        ** the output name if it was given.
        */
        if (OutputName) {
            CmdSetOutput (&CC65, OutputName);
        }
    }

    /* Add the file as argument for the compiler */
    CmdAddArg (&CC65, File);

    /* Add a NULL pointer to terminate the argument list */
    CmdAddArg (&CC65, 0);

    /* Run the compiler */
    ExecProgram (&CC65);

    /* Remove the excess arguments */
    CmdDelArgs (&CC65, ArgCount);

    /* If this is not the final step, assemble the generated file, then
    ** remove it
    */
    if (DoAssemble) {
        /* Assemble the intermediate file and remove it */
        AssembleIntermediate (File);
    }
}
Exemple #5
0
/**
 *
 * @return A newly-allocated string with the name to use or NULL upon error.
 */
static char *GetStreamName (const char * const output_dir_s, const char *output_filename_s, char *stream_name_s, const char * const suffix_s)
{
	bool allocated_stream_name_flag = false;
	char *filename_s = NULL;


	if (!stream_name_s)
		{
			/*
				if stream_name_s is NULL use the output_filename instead and
				add the relevant suffix.
			*/

			if (output_filename_s)
				{
					stream_name_s = ConcatenateStrings (output_filename_s, suffix_s);
				}
			else
				{
					stream_name_s = ConcatenateStrings ("output", suffix_s);
				}

			if (stream_name_s)
				{
					allocated_stream_name_flag = TRUE;
				}
		}

	if (stream_name_s)
		{
			/* if we've got an output direrctory, put the files there */
			if (output_dir_s)
				{
					filename_s = MakeFilename (output_dir_s, stream_name_s);

					if (allocated_stream_name_flag)
						{
							FreeCopiedString (stream_name_s);
						}
				}
			else
				{
					/* if the stream_name_s was newly allocated, simply use it. */
					if (allocated_stream_name_flag)
						{
							filename_s = stream_name_s;
							allocated_stream_name_flag = false;
						}
					else
						{
							filename_s = CopyToNewString (stream_name_s, 0, TRUE);
						}
				}
		}

	return filename_s;
}
Exemple #6
0
PlayerImp(const char* name)
// Constructor.  Read data from the specified file.  The given name is only the basename;
// prepends a "../PlayerData/" and appends a ".srp" to form the full filename.
{
	Name = new char[strlen(name) + 1];
	strcpy(Name, name);

	LastMountain = NULL;

	// Form the filename and try to open the file.
	char	temp[1000];
	MakeFilename(temp, 1000, Name);
	FILE*	fp = fopen(temp, "rb");
	
	if (fp == NULL) {
		// Filename does not exist -- new player.  Use defaults.
	} else {
		// Load player info from disk.
		
		// Get the header, and check it.
		uint32	HeaderWord = Read32(fp);
		if ((HeaderWord & 0x00FFFFFF) != 0x00505253 /* "SRP" */) {
			Error e; e << "'" << temp << "' is not a Soul Ride player data file.";
			throw e;
		}
		int	Version = HeaderWord >> 24;
		
		if (Version > PLAYER_FILE_VERSION) {
			Error e; e << "Can't read '" << temp << "', version is unknown.";
			throw e;
		}
		
		// Get misc player info.
		
		// LastMountain
		
		// Mountain data.
		int	MountainCount = Read32(fp);
		for (int i = 0; i < MountainCount; i++) {
			// Load the mountain name.
			char	name[256];
			fgets(name, 256, fp);
			name[strlen(name) - 1] = 0;	// Get rid of trailing '\n'.
			Utility::StringLower(name);	// Convert to all lower-case to avoid confusion.

			// Get the user's stats on this mountain.
			MountainInfo*	m = new MountainInfo;
			m->Read(fp, Version);

			// Remember for later.
			Mountains.Add(m, name);
		}
		
		fclose(fp);
	}
}
Exemple #7
0
static void Link (void)
/* Link the resulting executable */
{
    unsigned I;

    /* Since linking is always the final step, if we have an output file name
    ** given, set it here. If we don't have an explicit output name given,
    ** try to build one from the name of the first input file.
    */
    if (OutputName) {

        CmdSetOutput (&LD65, OutputName);

    } else if (FirstInput && FindExt (FirstInput)) {  /* Only if ext present! */

        const char* Extension = Module? MODULE_EXT : "";
        char* Output = MakeFilename (FirstInput, Extension);
        CmdSetOutput (&LD65, Output);
        xfree (Output);

    }

    /* If we have a linker config file given, add it to the command line.
    ** Otherwise pass the target to the linker if we have one.
    */
    if (LinkerConfig) {
        if (Module) {
            Error ("Cannot use -C and --module together");
        }
        CmdAddArg2 (&LD65, "-C", LinkerConfig);
    } else if (Module) {
        CmdSetTarget (&LD65, TGT_MODULE);
    } else {
        CmdSetTarget (&LD65, Target);
    }

    /* Determine which target libraries are needed */
    SetTargetFiles ();

    /* Add all object files as parameters */
    for (I = 0; I < LD65.FileCount; ++I) {
        CmdAddArg (&LD65, LD65.Files [I]);
    }

    /* Add the system runtime library */
    if (TargetLib) {
        CmdAddArg (&LD65, TargetLib);
    }

    /* Terminate the argument list with a NULL pointer */
    CmdAddArg (&LD65, 0);

    /* Call the linker */
    ExecProgram (&LD65);
}
Exemple #8
0
void	Save()
// Write the player state info to our file.
{
	char	temp[1000];
	MakeFilename(temp, 1000, Name);

	// Make sure PlayerData subdirectory exists.
	chdir("..");
	if (chdir("PlayerData") != 0) {

#ifdef LINUX
		mkdir("PlayerData", 0775);
#else // not LINUX
		mkdir("PlayerData");
#endif // not LINUX
	} else {
		chdir("..");
	}
	chdir("data");

	// Try to open the file for output.
	FILE* fp = fopen(temp, "wb");
	if (fp == NULL) {
		Error e; e << "Can't open '" << temp << "' for output.";
		throw e;
	}

	// Write the header.
	Write32(fp, 0x00505253 | (PLAYER_FILE_VERSION << 24));
	
	BagOf<MountainInfo*>::Iterator	b;
	
	// Count the mountains we have info on.
	b = Mountains.GetIterator();
	int	MountainCount = 0;
	while (b.IsDone() == false) {
		MountainCount++;
		b++;
	}

	// Write the count.
	Write32(fp, MountainCount);

	// Write the actual mountain info.
	b = Mountains.GetIterator();
	while (b.IsDone() == false) {
		fputs(b.GetName(), fp);
		fputc('\n', fp);
		(*b)->Write(fp);
		b++;
	}
	
	fclose(fp);
}
bool ExternalBlastTool :: SetUpOutputFile ()
{
	bool success_flag = false;
	char *local_filename_s = 0;
	char uuid_s [UUID_STRING_BUFFER_SIZE];

	ConvertUUIDToString (bt_job_p -> bsj_job.sj_id, uuid_s);

	local_filename_s = ConcatenateStrings (uuid_s, BS_OUTPUT_SUFFIX_S);

	if (local_filename_s)
		{
			ebt_results_filename_s = MakeFilename (ebt_working_directory_s, local_filename_s);

			if (ebt_results_filename_s)
				{
					if (AddBlastArgsPair ("out", ebt_results_filename_s))
						{
							success_flag = true;
						}
					else
						{
							PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to set output filename to \"%s\"", ebt_results_filename_s);
						}
				}
			else
				{
					PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to create filename for %s, %s", ebt_working_directory_s, local_filename_s);
				}

			FreeCopiedString (local_filename_s);
		}
	else
		{
			PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to create local filename for %s, %s", uuid_s, BS_OUTPUT_SUFFIX_S);
		}



	return success_flag;
}
Exemple #10
0
static void AssembleIntermediate (const char* SourceFile)
/* Assemble an intermediate file which was generated by a previous processing
** step with SourceFile as input. The -dep options won't be added and
** the intermediate assembler file is removed after assembly.
*/
{
    /* Generate the name of the assembler output file from the source file
    ** name. It's the same name with the extension replaced by ".s"
    */
    char* AsmName = MakeFilename (SourceFile, ".s");

    /* Assemble the intermediate assembler file */
    AssembleFile (AsmName, CA65.ArgCount);

    /* Remove the input file */
    if (remove (AsmName) < 0) {
        Warning ("Cannot remove temporary file `%s': %s",
                 AsmName, strerror (errno));
    }

    /* Free the assembler file name which was allocated from the heap */
    xfree (AsmName);
}
static char *GetLocalJobFilename (const char *uuid_s, const BlastServiceData *blast_data_p)
{
	char *output_filename_s = NULL;
	char *output_filename_stem_s = MakeFilename (blast_data_p -> bsd_working_dir_s, uuid_s);

	if (output_filename_stem_s)
		{
			output_filename_s = ConcatenateStrings (output_filename_stem_s, s_remote_suffix_s);

			if (!output_filename_s)
				{
					PrintErrors (STM_LEVEL_WARNING, __FILE__, __LINE__, "Failed to create filename from \"%s\" and \"%s\"", output_filename_stem_s, s_remote_suffix_s);
				}

			FreeCopiedString (output_filename_stem_s);
		}		/* if (output_filename_stem_s) */
	else
		{
			PrintErrors (STM_LEVEL_WARNING, __FILE__, __LINE__, "Failed to create filename stem from \"%s\" and \"%s\"", output_filename_stem_s, uuid_s);
		}

	return output_filename_s;
}
Exemple #12
0
static void AssembleFile (const char* File, unsigned ArgCount)
/* Common routine to assemble a file. Will be called by Assemble() and
** AssembleIntermediate(). Adds options common for both routines and
** assembles the file. Will remove excess arguments after assembly.
*/
{
    /* Set the target system */
    CmdSetTarget (&CA65, Target);

    /* Check if this is the last processing step */
    if (DoLink) {
        /* We're linking later. Add the output file of the assembly
        ** the the file list of the linker. The name of the output
        ** file is that of the input file with ".s" replaced by ".o".
        */
        char* ObjName = MakeFilename (File, ".o");
        CmdAddFile (&LD65, ObjName);
        xfree (ObjName);
    } else {
        /* This is the final step. If an output name is given, set it */
        if (OutputName) {
            CmdSetOutput (&CA65, OutputName);
        }
    }

    /* Add the file as argument for the assembler */
    CmdAddArg (&CA65, File);

    /* Add a NULL pointer to terminate the argument list */
    CmdAddArg (&CA65, 0);

    /* Run the assembler */
    ExecProgram (&CA65);

    /* Remove the excess arguments */
    CmdDelArgs (&CA65, ArgCount);
}
int main( int argc, char *argv[] )
{
	if ( argc < 2 )
	{
		Msg("Usage:\nmakephx [options] <FILESPEC>\ne.g. makephx [-r] *.phy\n");
		return 0;
	}

	CommandLine()->CreateCmdLine( argc, argv );
	g_bRecursive = CommandLine()->FindParm("-r") > 0 ? true : false;
	g_bQuiet = CommandLine()->FindParm("-quiet") > 0 ? true : false;
	InitFilesystem( "*.*" );
	InitVPhysics();
	// disable automatic packing, we want to do this ourselves.
	physcollision->SetPackOnLoad( false );
	MathLib_Init( 2.2f, 2.2f, 0.0f, 2.0f, false, false, false, false );
	InstallSpewFunction();

	g_pModelConfig = new KeyValues("config");
	g_pModelConfig->LoadFromFile( g_pFullFileSystem, "phx.cfg", "GAME" );
	g_TotalOut = 0;
	g_TotalCompress = 0;
	FileFindHandle_t handle;
	char fullpath[1024], currentFile[1024], dirName[1024], nameext[256];
	strcpy( fullpath, argv[argc-1] );
	strcpy( fullpath, ExpandPath( fullpath ) );
	strcpy( fullpath, ExpandArg( fullpath ) );
	Q_strncpy(dirName, fullpath, sizeof(dirName));
	Q_StripFilename(dirName);
	Q_strncpy(nameext, fullpath + strlen(dirName)+1, sizeof(nameext));
	CUtlVector< const char * > directoryList;
	directoryList.AddToTail( strdup(dirName) );
	int current = 0;
	int count = 0;
	do 
	{
		if ( g_bRecursive )
		{
			MakeFilename( currentFile, sizeof(currentFile), directoryList[current], "*.*" );
			const char *pFilename = g_pFullFileSystem->FindFirst( currentFile, &handle );
			while ( pFilename )
			{
				if ( pFilename[0] != '.' && g_pFullFileSystem->FindIsDirectory( handle ) )
				{
					MakeDirname( currentFile, sizeof(currentFile), directoryList[current], pFilename );
					directoryList.AddToTail(strdup(currentFile));
				}
				pFilename = g_pFullFileSystem->FindNext( handle );
			}
			g_pFullFileSystem->FindClose( handle );
		}

		MakeFilename(currentFile, sizeof(currentFile), directoryList[current], nameext);
		const char *pFilename = g_pFullFileSystem->FindFirst( currentFile, &handle );
		while ( pFilename )
		{
			phyfile_t phy;
			MakeFilename(currentFile, sizeof(currentFile), directoryList[current], pFilename);
			LoadPHYFile( &phy, currentFile );
			if ( phy.collide.isPacked || phy.collide.solidCount < 1 )
			{
				Msg("%s is not a valid PHY file\n", currentFile );
			}
			else
			{
				WritePHXFile( currentFile, phy );
				count++;
			}
			UnloadPHYFile( &phy );
			pFilename = g_pFullFileSystem->FindNext( handle );
		}
		g_pFullFileSystem->FindClose( handle );
		current++;
	} while( current < directoryList.Count() );

	if ( count )
	{
		if (!g_bQuiet)
		{
			Msg("\n------\nTotal %s, %s\nSaved %s\n", Q_pretifymem( g_TotalOut ), Q_pretifymem( g_TotalCompress ), Q_pretifymem( g_TotalOut - g_TotalCompress ) );
			Msg("%.2f%% savings\n", ((float)(g_TotalOut-g_TotalCompress) / (float)g_TotalOut) * 100.0f );
		}
	}
	else
	{
		Msg("No files found in %s!\n", directoryList[current] );
	}

	return 0;
}
void MakeDirname( char *pDest, int destSize, const char *pPathname, const char *pSubdir )
{
	MakeFilename(pDest, destSize , pPathname, pSubdir);
}
Exemple #15
0
void *png_Open(char *name){
	FILE			*fp;
	png_infop		info_ptr;
	png_structp		png_ptr;
	png_uint_32		width, height;
	unsigned int	sig_read = 0;
	int				bit_depth, color_type, interlace_type;
//	int				MaxPics = 3;
	char			buf[PNG_BYTES_TO_CHECK];
	char			*filename;
	PngImgData		*pid;

	DynamicArray* ptrCache=new DynamicArray(DARRAY_GENID);	// fixme: GENID
	int i=-1;
	
	while(true){
redo:	filename=MakeFilename(i,name, ".png");		// fixme: Free filenames
		if((fp = fopen(filename,"rb")) == NULL){
			free(filename);
			if(i==-1){ i++; goto redo;}
			if(ptrCache){ 
				if(png_GetFrameCount(ptrCache)>0) return (void*)ptrCache;
				png_Deinitialize(ptrCache);
			}
			posix_printf("File \"%s\" not found!\n",filename); // File couldn't be opened.
			assert(false);
			return NULL;
		}
//_printf("File \"%s\" OK!\n",filename);

		if (fread(buf, 1, PNG_BYTES_TO_CHECK, fp) != PNG_BYTES_TO_CHECK){
			free(filename);
			fclose(fp);
			if (ptrCache){ 
				if (png_GetFrameCount(ptrCache)>0);
					return (void*)ptrCache;
				png_Deinitialize(ptrCache);
				}
			assert(false);
			return NULL;// Not a valid PNG file.
		}
		
		// This is a pngfile. Read its infostruct
		// FIXME:
		
		png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
		
		if (png_ptr == NULL){
			free(filename);
			fclose(fp);
			if (ptrCache){ 
				if (png_GetFrameCount(ptrCache)>0);
					return (void*)ptrCache;
				png_Deinitialize(ptrCache);
				}
			assert(false);
			return NULL;
		}

		info_ptr = png_create_info_struct(png_ptr);
		if (info_ptr == NULL){
			free(filename);
			fclose(fp);
			png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
			if (ptrCache){ 
				if (png_GetFrameCount(ptrCache)>0);
					return (void*)ptrCache;
				png_Deinitialize(ptrCache);
				}
			assert(false);
			return NULL;
		}
		
		if (setjmp(png_ptr->jmpbuf)){
			free(filename);
			png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
			fclose(fp);
			if (ptrCache){ 
				if (png_GetFrameCount(ptrCache)>0);
					return (void*)ptrCache;
				png_Deinitialize(ptrCache);
				}
			assert(false);
			return NULL;
		}
		png_init_io(png_ptr, fp);	
		png_set_sig_bytes(png_ptr, PNG_BYTES_TO_CHECK);
		
		png_read_info(png_ptr, info_ptr);
		png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
			&interlace_type, NULL, NULL);
png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
		
		// This is a file we want. Make a ptrCache for it and store it away!		
fclose(fp);		
		pid = new PngImgData();
		pid->ImgName=filename;
		pid->width=info_ptr->width; 
		pid->height=info_ptr->height;
		#ifdef _DEBUG
		ptrCache->Add(pid,__FILE__,__LINE__);
		#else
		ptrCache->Add(pid);
		#endif
		i++;
foo++;
	}
	return (void*)ptrCache;	//return pointer to cache;
}
char *ExternalBlastTool :: GetJobFilename (const char * const prefix_s, const char * const suffix_s)
{
	char *job_filename_s = NULL;
	char *job_id_s = GetUUIDAsString (bt_job_p -> bsj_job.sj_id);

	if (job_id_s)
		{
			char *file_stem_s = NULL;

			if (ebt_working_directory_s)
				{
					file_stem_s = MakeFilename (ebt_working_directory_s, job_id_s);
				}
			else
				{
					file_stem_s = job_id_s;
				}

			if (file_stem_s)
				{
					ByteBuffer *buffer_p = AllocateByteBuffer (1024);

					if (buffer_p)
						{
							bool success_flag = false;

							if (prefix_s)
								{
									success_flag = AppendStringsToByteBuffer (buffer_p, prefix_s, file_stem_s, NULL);
								}
							else
								{
									success_flag = AppendStringToByteBuffer (buffer_p, file_stem_s);
								}

							if (success_flag && suffix_s)
								{
									success_flag = AppendStringToByteBuffer (buffer_p, suffix_s);
								}

							if (success_flag)
								{
									job_filename_s = DetachByteBufferData (buffer_p);
								}
							else
								{
									FreeByteBuffer (buffer_p);
								}

						}		/* if (buffer_p) */

					FreeCopiedString (file_stem_s);
				}		/* if (file_stem_s) */
			else
				{
					PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to get file stem for \"%s\"", job_id_s);
				}

			FreeUUIDString (job_id_s);
		}		/* if (job_id_s) */
	else
		{
			PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to get uuid string for %s", bt_job_p -> bsj_job.sj_name_s);
		}

	return job_filename_s;
}
Exemple #17
0
LinkedList *GetMatchingFiles (const char * const pattern, const bool full_path_flag)
{
	LinkedList *list_p = AllocateLinkedList (FreeStringListNode);

	if (list_p)
		{
			char *filename_p = GetFilenameOnly (pattern);

			if (filename_p)
				{
					char *path_p = GetPathOnly (pattern);

					if (path_p)
						{
							DIR *dir_p = opendir (path_p);

							if (dir_p)
								{
									struct dirent entry;
									struct dirent *entry_p = &entry;

									while ((entry_p = readdir (dir_p)) != NULL)
										{
											if ((fnmatch (filename_p, entry_p -> d_name, 0)) == 0)
												{
													StringListNode *node_p = NULL;

													if (full_path_flag)
														{
															char *full_filename_s = MakeFilename (path_p, entry_p -> d_name);

															if (full_filename_s)
																{
																	node_p = AllocateStringListNode (full_filename_s, MF_SHALLOW_COPY);
																}
														}
													else
														{
															node_p = AllocateStringListNode (entry_p -> d_name, MF_DEEP_COPY);
														}

													if (node_p)
														{
															LinkedListAddTail (list_p, (ListItem *) node_p);
														}
												}
										}

									closedir (dir_p);
								}

							FreeMemory (path_p);
						}

					FreeMemory (filename_p);
				}


			if (list_p -> ll_size > 0)
				{
					return list_p;
				}
			else
				{
					FreeLinkedList (list_p);
				}
		}

	return NULL;
}