/* 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
}
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);
}
*/
/********************************************************/
/* */
-/* 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;
}
phase++;
}
-rootname=rou_freestr(rootname);
return status;
}
/*
{
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;
}
/*