git » fp-git.git » commit 79ab37a

improved return value for main function and moved special errors to the list of normal errors

author ecalot
2006-01-07 20:57:39 UTC
committer ecalot
2006-01-07 20:57:39 UTC
parent f0b2f2b9251c3b58a4e80a40393cee7a191c55f9

improved return value for main function and moved special errors to the list of normal errors

PR/src/console/filedir.c +9 -10
PR/src/console/main.c +12 -23

diff --git a/PR/src/console/filedir.c b/PR/src/console/filedir.c
index f65b37c..3810c9b 100644
--- a/PR/src/console/filedir.c
+++ b/PR/src/console/filedir.c
@@ -62,7 +62,7 @@ int filedir_push(const char* text, tFileDir** list, int checkEquals) {
 		node=*list;
 		while (node) {
 			if (equalsIgnoreCase(node->text,text)) /* If file was in the list, do nothing */
-				return -1;
+				return -1; /* false */
 			node=node->next;
 		}
 	}
@@ -74,7 +74,7 @@ int filedir_push(const char* text, tFileDir** list, int checkEquals) {
 	node->text=strallocandcopy(text);
 	node->next=*list;
 	*list=node;
-	return 0;
+	return 0; /* true */
 }
 
 char* filedir_pop(tFileDir** list) {
@@ -146,7 +146,7 @@ int listAllDatFiles(const char* vResFile, const char* directory, const char* opt
 
 	/* All done */
 	list=pass.list;
-	return 0;
+	return PR_RESULT_SUCCESS;
 }
 
 /* layer 2, module check if a file is in the xml */
@@ -232,16 +232,16 @@ int fileDirGetFilesImport(tFileDir2* list1,tFileDir2* files,const char* resfile,
 
 	if (dirs>1) {
 		while ((file=filedir_pop(&(files->filenames)))) free(file); /* empty list */
-		return -20;
+		return PR_RESULT_FD_IMPORT_FROM_MORE_THAN_ONE_DIR;
 	}
 	if (!fils&&!dirs)
-		return -22; /* no files selected */
+		return PR_RESULT_FD_NO_FILES_SELECTED; /* no files selected */
 
 	if (parseError) {
 		while ((file=filedir_pop(&(files->filenames)))) free(file); /* empty list */
 		return parseError;
 	}
-	return 0;
+	return PR_RESULT_SUCCESS;
 }
 
 /* layer 2, module Export */
@@ -273,7 +273,7 @@ int fileDirGetFilesExport(tFileDir2* list1,tFileDir2* files,int notHasRecursiveF
 		free(opt);
 		free(file);
 	}
-	return 0;
+	return PR_RESULT_SUCCESS;
 }
 
 /* layer 3, primitives */
@@ -314,7 +314,7 @@ void fileDirAddOption(tFileDir2* list1, const char* option) {
 }
 
 int fileDirGetFiles(tFileDir2* list1,tFileDir2* files,int hasExportFlag,int notHasRecursiveFlag,const char* resfile,int given) {
-/* case 1: * import from more than one directory */
+	/* case 1: * import from more than one directory */
 
 	if (!hasExportFlag&&!notHasRecursiveFlag) {
 		char* file;
@@ -322,7 +322,7 @@ int fileDirGetFiles(tFileDir2* list1,tFileDir2* files,int hasExportFlag,int notH
 			free(filedir_pop(&(list1->options)));
 			free(file);
 		}
-		return -21; /* import with recursive flag is now allowed */
+		return PR_RESULT_FD_IMPORT_RECURSIVE; /* import with recursive flag is not allowed */
 	}
 
 	if (hasExportFlag)
@@ -336,4 +336,3 @@ char* fileDirGetFile(tFileDir2* files, char** datfile) {
 	*datfile=filedir_pop(&(files->options));
 	return filedir_pop(&(files->filenames));
 }
-
diff --git a/PR/src/console/main.c b/PR/src/console/main.c
index 97730be..cd60e98 100644
--- a/PR/src/console/main.c
+++ b/PR/src/console/main.c
@@ -154,7 +154,7 @@ int main (int argc, char **argv) {
 	} while (c!=-1);
 
 	outputStream=stdout;
-	c=0;
+	/*c=0;*/
 
 	/* At least one of these options must be selected, if not, the user needs help! */
 	if (!(optimizeXmlFile||hasFlag(import_flag|export_flag|classify_flag))) setFlag(help_flag);
@@ -169,7 +169,7 @@ int main (int argc, char **argv) {
 	/* Show version screen if requested */
 	if (hasFlag(version_flag)) {
 		fprintf(outputStream,PARSING_ABOUT);
-		return -1;
+		return PR_RESULT_HELP_SHOWN;
 	}
 
 	if (hasFlag(help_flag)) {
@@ -193,22 +193,12 @@ int main (int argc, char **argv) {
 		if (optind < argc) {
 			while (optind < argc)
 				fileDirAddOption(&input,argv[optind++]);
-        } else {
-				fileDirAddOption(&input,".");
-        }
-		c=fileDirGetFiles(&input,&files,!hasFlag(import_flag),!hasFlag(recursive_flag),resFile,datFileName!=NULL);
+		} else {
+			fileDirAddOption(&input,".");
+		}
+		result=fileDirGetFiles(&input,&files,!hasFlag(import_flag),!hasFlag(recursive_flag),resFile,datFileName!=NULL);
 
-		switch (c) {
-		case -20: /* import from more than one directory */
-			fprintf(stderr,PR_TEXT_ERROR_ONE_DIR);
-			break;
-		case -21: /* import with recursive flag */
-			fprintf(stderr,PR_TEXT_ERROR_IMPORT_NORECURSE);
-			break;
-		case -22: /* no files selected */
-			fprintf(stderr,PR_TEXT_ERROR_NO_FILES_SEL);
-			break;
-		case 0: {
+		if (result==PR_RESULT_SUCCESS) {
 			char  unknownFile[MAX_FILENAME_SIZE];
 			if (hasFlag(export_flag)) {
 				sprintf(unknownFile,"%s/" RES_XML_UNKNOWN_PATH "/" RES_XML_UNKNOWN_XML,dirNameDef);
@@ -254,12 +244,11 @@ int main (int argc, char **argv) {
 			}
 			fprintf(outputStream,"\n");
 			if (hasFlag(export_flag)) unknownLogStop();
-			} break;
-		default:
-			fprintf(stderr,PR_TEXT_ERROR_XML_FILE);
-			break;
+		} else {
+			fprintf(outputStream,PR_TEXT_RESULT,errors[-result],result);
 		}
 	}
+
 	freeParsingCache();
 	freeAllocation(datAuthor);
 	freeAllocation(datFileName);
@@ -267,7 +256,7 @@ int main (int argc, char **argv) {
 	freeAllocation(optimizeXmlFile);
 	freeAllocation(resFile);
 	freeAllocation(dirName);
-	
-	return c;
+
+	return result;
 }