git » fp-git.git » commit 6e0b9b6

better porting

author ecalot
2005-06-30 21:26:43 UTC
committer ecalot
2005-06-30 21:26:43 UTC
parent 4adf98da60841fc651a10f6d2d45eb619dce30ce

better porting

poprecog/poprecog.c +35 -6

diff --git a/poprecog/poprecog.c b/poprecog/poprecog.c
index fb20bc1..a550548 100644
--- a/poprecog/poprecog.c
+++ b/poprecog/poprecog.c
@@ -17,11 +17,32 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <time.h>
-#include <strings.h>
+#include <string.h>
 #include <dirent.h>
 //#include <qsort.h>
 #include <allegro.h>
 
+/* Defines */
+#ifndef WIN32
+#define UNIX
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#ifndef WIN32
+  #define defmkdir(a) mkdir (a,(mode_t)0755)
+	#define osIndepGetCharacter() getchar()
+	#define SEPS "\\"
+	#define SEPC '\\'
+#else
+	#include <direct.h> /* mkdir */ 
+  #define defmkdir(a) mkdir (a)
+	#define osIndepGetCharacter() getche()
+	#define SEPS "/"
+	#define SEPC '/'
+#endif
+
 /* Compile options */
 #define MAX_DIRS 9999
 #define MAX_SCREENSHOTS 99999
@@ -717,7 +738,7 @@ void recognizeScreenShot(int screenShotID)
   printf("\nRecognizing %s\n", screenShotList[screenShotID].fileName);
   fprintf(outputFile, "\nRecognizing %s\n", screenShotList[screenShotID].fileName);
   fprintf(outputSmallFile, "Recognizing %s\n", screenShotList[screenShotID].fileName);  
-  sprintf(buf, "%s\\%s", screenShotsDir, screenShotList[screenShotID].fileName);
+  sprintf(buf, "%s" SEPS "%s", screenShotsDir, screenShotList[screenShotID].fileName);
   screenShot = load_bmp(buf, 0);
   transparentScreenShot = load_bmp(buf, 0);  
   DEBUGScreenShot2 = load_bmp(buf, 0);  
@@ -1024,7 +1045,7 @@ void readDir(int dirID)
   struct dirent *file;
   FILE *optFile;
   
-  sprintf(buf, "%s\\bitmaps.cfg", dirInfo[dirID].dirName);
+  sprintf(buf, "%s" SEPS "bitmaps.cfg", dirInfo[dirID].dirName);
   if (optFile = fopen(buf, "r"))
   {
     //printf("Reading data from bitmaps.cfg\n");
@@ -1049,7 +1070,7 @@ void readDir(int dirID)
     if (match("*.bmp", file->d_name) || match("*.BMP", file->d_name))
     {
       strcpy(buf, dirInfo[dirID].dirName);
-      strcat(buf, "\\");      
+      strcat(buf, SEPS); 
       strcat(buf, file->d_name);
       image[imagesNumber].filePath = (char *) malloc(strlen(buf)+1);
       strcpy(image[imagesNumber].filePath, buf);
@@ -1196,14 +1217,22 @@ int main(int argc, char *argv[])
   set_color_conversion(COLORCONV_TOTAL);
   
   readParameters();
-  system("del ss_*.bmp");  
+  /*system("del ss_*.bmp");*/
 
-  mkdir(optResultsDir);
+  defmkdir(optResultsDir);
   
   sprintf(buf, "%s/%s", optResultsDir, "all_results.txt");
   outputFile = fopen(buf, "a");
+	if (!outputFile) {
+		printf("Cannot open %s for append\n",buf);
+		return -1;
+	}
   sprintf(buf, "%s/%s", optResultsDir, "small_results.txt");  
   outputSmallFile = fopen(buf, "a");
+	if (!outputFile) {
+		printf("Cannot open %s for append\n",buf);
+		return -1;
+	}
   fprintf(outputFile, "File generated by Prince Of Persia Screenshots Recognizer\n(c) Copyright 2005 Princed Development Team\nProgrammed by peter_k\nhttp://www.princed.com.ar\n\n");
 
   for (i = 0; i < dirsNumber; i++)