]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Starting to have the new test program "valide" to work
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Mon, 2 Sep 2024 02:28:12 +0000 (22:28 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Mon, 2 Sep 2024 02:28:12 +0000 (22:28 -0400)
Makefile
app/valide.c
lib/subrou.c

index 3919fb509a25c7e7890e4265fb9dce9e3eea8028..a37a63b71c22c0e90319fbbb2c904fb054686698 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -24,8 +24,8 @@ clean :
 #--------------------------------------------------------------------
 #test procedure
 #--------------------------------------------------------------------
-test   :  prod
-          @ echo $@ need to implemented
+test   :  clean debug
+          @ bin/valide data-tst/spf.tst
                
 #--------------------------------------------------------------------
 #Installation procedure
index 8bc801c8f90e0c000535f2d5cdc4ee933fc74484..3fc4771d926de8bf67f9b2708326a2829240283a 100644 (file)
@@ -84,7 +84,7 @@ return status;
 /*     Procedure to scan a line from the test file     */
 /*                                                     */
 /********************************************************/
-static int scanline(char *filename,FILE *fichier)
+static int scanlines(char *testname,FILE *fichier)
 
 {
 #define MAX     300
@@ -126,7 +126,7 @@ while (fgets(line,sizeof(line),fichier)!=(char *)0) {
   }
 if (status!=0) {
   (void) rou_alert(0,"SPF fail in file <%s> in line='%03d'",
-                      filename,num);
+                      testname,num);
   (void) rou_alert(0,"\t for domain <%s> peerip=<%s>",
                      domain,peerip);
   }
@@ -139,41 +139,38 @@ return status;
 */
 /********************************************************/
 /*                                                     */
-/*     Procedure to scan one file stop at soon test    */
-/*      line is not successful.                         */
+/*     Procedure to scan one file, return -1 if a test */
+/*      is not successfull, zero otherwise.             */
 /*                                                     */
 /********************************************************/
-static int scantest(char *testfile)
+static int scantest(char *tfile)
 
 {
+#define OPEP    "valide.c:scantest"
+
 int status;
-char *rootname;
 FILE *fichier;
 int phase;
 _Bool proceed;
 
 status=-1;
-rootname=rou_apppath(testfile);
 phase=0;
 proceed=true;
 while (proceed==true) {
+  (void) rou_alert(0,"%s phase='%d'",OPEP,phase);
   switch (phase) {
-    case 0      :       //using root directory if need
-      if ((fichier=fopen(rootname,"r"))==(FILE *)0) {
-        (void) rou_alert(0,"Unable to open file <%s> (error=<%s>)",
-                          rootname,strerror(errno));
-        phase=999;      //no need to go further
+    case 0      :       //opening the file
+      if ((fichier=fopen(tfile,"r"))==(FILE *)0) {
+        (void) rou_alert(0,"%s Unable to open file <%s> (error=<%s>)",
+                            OPEP,tfile,strerror(errno));
+        phase=999;
         }
       break;
     case 1      :       //scan the file
-      (void) rou_alert(0,"scanning test file <%s>",rootname);
-      status=scanline(rootname,fichier);
-      if (status==0)
-        (void) rou_alert(0,"\t Test OK");
+      status=scanlines(tfile,fichier);
       break;
     case 2      :       //scan the file
       (void) fclose(fichier);
-      status=0;
       break;
     default     :       //SAFE guard
       proceed=false;
@@ -181,7 +178,6 @@ while (proceed==true) {
     }
   phase++;
   }
-rootname=rou_freestr(rootname);
 return status;
 }
 /*
@@ -197,11 +193,47 @@ static int testfiles(ARGTYP *params)
 
 {
 int status;
+char *curdir;
 
 status=0;
+curdir=getcwd((char *)0,0);
 for (int i=0;i<params->argc;i++) {
-  (void) scantest(params->argv[i]);
+  char *basedir;
+  char *fname;
+  char *ptr;
+
+  basedir=strdup("");
+  fname=strdup(params->argv[i]);
+  ptr=strrchr(fname,'/');
+  if (ptr!=(char *)0) {
+    *ptr='\000';
+     (void) free(basedir);
+     basedir=strdup(fname);
+     ptr++;
+     (void) strcpy(fname,ptr);
+     }
+  if (strlen(basedir)>0) {
+    if (chdir(basedir)<0) {
+      (void) rou_alert(0,"%s Unable to chdir to <%s> (error=<%s>)",
+                          OPEP,basedir,strerror(errno));
+      fname=rou_freestr(fname);
+      basedir=rou_freestr(basedir);
+      continue;
+      }
+    }
+  status=scantest(fname);
+  if (chdir(curdir)<0) 
+    (void) rou_alert(0,"%s Unable to return  <%s> (error=<%s>) (Bug?)",
+                        OPEP,curdir,strerror(errno));
+  fname=rou_freestr(fname);
+  basedir=rou_freestr(basedir);
+  if (status<0) {
+    (void) rou_alert(0,"%s, <%s> test is no successfull exiting",
+                        OPEP,params->argv[i]);
+    break;
+    }
   }
+curdir=rou_freestr(curdir);
 return status;
 }
 /*
index 89f78bc4b159bd040b32f50bdd16401bda756de8..7b121bfd2fa81a3f945b71ca493848cabd543caa 100644 (file)
@@ -21,7 +21,7 @@
 
 //version definition 
 #define VERSION "0.4.2"
-#define RELEASE "27"
+#define RELEASE "28"
 
 //Public variables
 PUBLIC  int debug=0;            //debug level