/**
 * @brief Decompresses all palz files in a folder
 * @details Receives a folder name and scans it looking for palz files. If it finds one it calls the decompression routine.
 * 
 * @param dirname Name of the folder (directory) to decompress.
 * @return Returns 0 if succesful.
 */
int folderDecompress (const char *dirname) {
	int function = 2;
	LISTA_GENERICA_T* listOfDir = lista_criar(NULL);
	lista_inserir_inicio(listOfDir, strdup(dirname));

	while (lista_numero_elementos(listOfDir) > 0) {
		char *fdirname = lista_remover_inicio(listOfDir);
		DIR *workdir = opendir(fdirname);
		struct dirent *entry;

		while ( ( entry = readdir(workdir) ) ) {
			if( strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0 )
            	continue;

        	char *fullname = MALLOC(strlen(dirname) + strlen(entry->d_name) + 2);

        	sprintf(fullname, "%s/%s", dirname, entry->d_name);

        	struct stat info;

        	if( lstat(fullname, &info) != 0 ) {

            WARNING("lstat() failed for item %s", fullname);
            return -1;

        	}

	        if( S_ISDIR(info.st_mode) ) {

	            folderDecompress(fullname);

	        } else {

				if (is_extension_palz(fullname) == -1)
				{
					FREE(fullname);
					continue;
	               
				}else{
					printf("Decompress file %s\n", fullname);
	            	decompress(fullname, function);
				}
		         
        	}

        	FREE(fullname);
		}
		closedir(workdir);
		FREE(fdirname);
	}

	lista_destruir(&listOfDir);
	return 0;
}
Exemple #2
0
/**
 * Funcao que devolve um iterador para a lista.
 * @param lista ponteiro para a lista generica
 * @return iterador para a lista
 */
ITERADOR_T *lista_criar_iterador(LISTA_GENERICA_T * lista)
{
	ITERADOR_T *iterador = (ITERADOR_T *) malloc(sizeof(ITERADOR_T));

	/* Cria uma copia da lista */
	LISTA_GENERICA_T *nova_lista = lista_criar(NULL);
	NO_T *aux = lista->base->prox;

	while (aux != lista->base) {
		lista_inserir_fim(nova_lista, aux->elem);
		aux = aux->prox;
	}

	iterador->base = iterador->actual = nova_lista->base;

	free(nova_lista);

	return iterador;
}
Exemple #3
0
/**
 * Funcao que devolve um iterador para uma versao ordenada da lista.
 * @param lista ponteiro para a lista generica
 * @param compara_elem funcao de comparacao para ordenar a lista
 * @return iterador para uma versao ordenada da lista
 */
ITERADOR_T *lista_criar_iterador_ordenado(LISTA_GENERICA_T * lista,
					  COMPARAR_FUNC compara_elem)
{
	ITERADOR_T *iterador = (ITERADOR_T *) malloc(sizeof(ITERADOR_T));

	/* Cria uma versao ordenada da lista */
	LISTA_GENERICA_T *lista_ordenada = lista_criar(NULL);
	NO_T *aux = lista->base->prox;

	while (aux != lista->base) {
		lista_inserir_ordenado(lista_ordenada, aux->elem, compara_elem);
		aux = aux->prox;
	}

	iterador->base = iterador->actual = lista_ordenada->base;

	free(lista_ordenada);

	return iterador;
}
Exemple #4
0
int main(int argc, char **argv)
{
	struct gengetopt_args_info args_info;

	char outputDir[PATH_MAX] = ""; // the output directory where files are to be saved
	char filename[PATH_MAX] = ""; // the name of the files (without extension) 
	char capitalFilename[PATH_MAX] = ""; // the name of the files (without extension) in capital letters
	char fullPath[PATH_MAX] = ""; // the full path of the file
	char fileType[4] = ""; // the extension of the file

	char mainTemplateName[PATH_MAX] = ""; // the path to the main template file (.c or .cu)
	char headerTemplateName[PATH_MAX] = ""; // the path to the header template file (.h)
	char makefileTemplateName[PATH_MAX] = ""; // the path to the makefile template file

	char fileVarMainTemplateName[PATH_MAX] = "";// the path to the main template variables file 
	char fileVarHeaderTemplateName[PATH_MAX] = ""; // the path to the header template variables file
	char fileVarMakefileTemplateName[PATH_MAX] = ""; // the path to the makefile template variables file
	char handleErrorTemplateName[PATH_MAX] = ""; // the path to the HandleError.h
	

	HASHTABLE_T *systemVarsTable; // an hashtable containing program genereted variables
	HASHTABLE_T *fileVarsTable;
	LISTA_GENERICA_T *varsIgnoreList; // an hashtable containing file fetched variables	
	
	char userName[PATH_MAX] = "your name"; // the name of the user
	char *fileVars = NULL; // a string with the vars fetched from a variables file


	char *template; // a string with the content of a template file
	unsigned int i = 0; // a utility index
	char *currentDate = NULL; // a string representing the current date
		
	struct passwd *passwd;
	passwd=getpwuid(getuid());
	char * homedir = passwd->pw_dir;
	if(homedir[strlen(homedir) - 1] == '/'){
		homedir[strlen(homedir) - 1] = 0;
	}
	
	
	// parse input parameters
	if (cmdline_parser(argc, argv, &args_info) != 0)
		exit(1);
	
	currentDate = getDateTime();

	//creates an hashtable with system generated template variables
	systemVarsTable = tabela_criar(11, (LIBERTAR_FUNC) free);

	
	varsIgnoreList = lista_criar((LIBERTAR_FUNC) free);
	
	tabela_inserir(systemVarsTable, "$!C_DATE!$", string_clone(currentDate));	
	tabela_inserir(systemVarsTable, "$!USER_NAME!$", string_clone(userName));

	
	// --about
	if (args_info.about_given) {
		return 0;
	} 
	
	// --student
	
	for(i = 0; i < args_info.student_given; i ++){
		lista_inserir(varsIgnoreList, string_clone(args_info.student_arg[i]));
	}
	
	// --proto
	if (args_info.proto_given) {
		tabela_inserir(systemVarsTable, "$!KERNEL_PROTO!$", string_clone(args_info.proto_arg));	
	} else {
		tabela_inserir(systemVarsTable, "$!KERNEL_PROTO!$", string_clone(""));	
	}
	
	// --kernel
	if (args_info.kernel_given) {
		tabela_inserir(systemVarsTable, "$!KERNEL_NAME!$", string_clone(args_info.kernel_arg));	
	} else {
		tabela_inserir(systemVarsTable, "$!KERNEL_NAME!$", string_clone("Kernel"));	
	}
	
	// --blocks
	store_grid_geometry(systemVarsTable, &args_info);
	// --threads
	store_blocks_geometry(systemVarsTable, &args_info);
	
	// --dir
	// get filename from path (the name of the last directory)
	getFilenameFromPath(args_info.dir_arg, filename);

	// the filename in capital letters
	for (i = 0; i < strlen(filename); i++) {
		capitalFilename[i] = toupper(filename[i]);
	}
	capitalFilename[i] = 0;
	
	tabela_inserir(systemVarsTable, "$!FILENAME!$", string_clone(filename));
	tabela_inserir(systemVarsTable, "$!CAPITAL_FILENAME!$", string_clone(capitalFilename));
	

	// removes the / character
	if (args_info.dir_arg[strlen(args_info.dir_arg) - 1] == '/') {
		args_info.dir_arg[strlen(args_info.dir_arg) - 1] = 0;
	}
	//creates the output directory
	if (!createDirectory(args_info.dir_arg)) {

		if (args_info.Force_given) {
			// removes the existing directoy        
			remove_directory(args_info.dir_arg);
			sprintf(outputDir, "%s", args_info.dir_arg);
		} else {
			// adds a date to the directory name
			sprintf(outputDir, "%s%s", args_info.dir_arg,
				currentDate);
		}

		createDirectory(outputDir);
	} else {
		sprintf(outputDir, "%s", args_info.dir_arg);
	}

	sprintf(outputDir, "%s/", outputDir);


	if (!args_info.measure_given) {
		char *var = malloc(strlen("MEASURE") + 1);
		strcpy(var, "MEASURE");
		lista_inserir(varsIgnoreList, var);

	}
	

	/* defines which templates to use */

	// cuda with prototype
	if (args_info.proto_given) {
		strcpy(mainTemplateName, homedir);
		strcat(mainTemplateName, CU_PROTO_TEMPLATE);

		strcpy(headerTemplateName, homedir);
		strcat(headerTemplateName, CU_HEADER_TEMPLATE);

		strcpy(makefileTemplateName, homedir);
		strcat(makefileTemplateName, CU_MAKEFILE_TEMPLATE);

		strcpy(fileVarMainTemplateName, homedir);
		strcat(fileVarMainTemplateName, CU_PROTO_TEMPLATE_VARS);

		strcpy(fileVarHeaderTemplateName, homedir);
		strcat(fileVarHeaderTemplateName, CU_HEADER_TEMPLATE_VARS);

		strcpy(fileVarMakefileTemplateName, homedir);
		strcat(fileVarMakefileTemplateName, CU_MAKEFILE_TEMPLATE_VARS);

		strcat(fileType, ".cu");

		// regular c template   
	} else if (args_info.regular_code_given) {
		strcpy(mainTemplateName, homedir);
		strcat(mainTemplateName, C_MAIN_TEMPLATE);
		
		strcpy(headerTemplateName, homedir);
		strcat(headerTemplateName, C_HEADER_TEMPLATE);

		strcpy(makefileTemplateName, homedir);
		strcat(makefileTemplateName, C_MAKEFILE_TEMPLATE);

		strcpy(fileVarMainTemplateName, homedir);
		strcat(fileVarMainTemplateName, C_MAIN_TEMPLATE_VARS);

		strcpy(fileVarHeaderTemplateName, homedir);
		strcat(fileVarHeaderTemplateName, C_HEADER_TEMPLATE_VARS);

		strcpy(fileVarMakefileTemplateName, homedir);
		strcat(fileVarMakefileTemplateName, C_MAKEFILE_TEMPLATE_VARS);

		strcat(fileType, ".c");

		// cuda default
	} else {
		strcpy(mainTemplateName, homedir);
		strcat(mainTemplateName, CU_MAIN_TEMPLATE);

		strcpy(headerTemplateName, homedir);
		strcat(headerTemplateName, CU_HEADER_TEMPLATE);

		strcpy(makefileTemplateName, homedir);
		strcat(makefileTemplateName, CU_MAKEFILE_TEMPLATE);

		strcpy(fileVarMainTemplateName, homedir);
		strcat(fileVarMainTemplateName, CU_MAIN_TEMPLATE_VARS);

		strcpy(fileVarHeaderTemplateName, homedir);
		strcat(fileVarHeaderTemplateName, CU_HEADER_TEMPLATE_VARS);

		strcpy(fileVarMakefileTemplateName, homedir);
		strcat(fileVarMakefileTemplateName, CU_MAKEFILE_TEMPLATE_VARS);

		strcat(fileType, ".cu");

	}
	
	// create HANDLE_ERROR_H file
	if (strcmp(fileType, ".cu") == 0) {
		// reads from source file
		strcpy(handleErrorTemplateName, homedir);
		strcat(handleErrorTemplateName, HANDLE_ERROR_H);