fastqdeloea.c: Return an exitcode of 1 instead of 0, when a fatal error happens and fix/add error messages.
Return an exitcode of 1 instead of 0, when a fatal error happens.
This way we can check if fastqdeloea failed when called from
another script/program.
Rewrite the text of some error messages.
Add some new error messages.
Fix also some error messages.
Also close the input file descriptor when we no longer need it.
--- a/fastqdeloea.c
+++ b/fastqdeloea.c
@@ -180,8 +180,10 @@ int main(int argc, char **argv){
ccut = 1;
acut = 0;
- if (argc < 2)
- return 0;
+ if (argc < 2) {
+ printf("\n%s -i <fastq1> -r <fastq2> -o <outputfile> -h <hashtype> [ -nc | -clean ]\n\n", argv[0]);
+ return 1;
+ }
fname[0]=0;
ofname[0]=0;
@@ -218,19 +220,28 @@ int main(int argc, char **argv){
}
- if(fname[0]==0){// || fname2[0]==0){
- fprintf(stderr, "input file?\n");
- return 0;
+ if(fname[0]==0){
+ fprintf(stderr, "Error: Forward fastq file is not specified.\n");
+ exit(1);
+ }
+
+ if(fname2[0]==0){
+ fprintf(stderr, "Error: Reverse fastq file is not specified.\n");
+ exit(1);
}
+ if(ofname[0]==0){
+ fprintf(stderr, "Error: Output filename is not specified.\n");
+ exit(1);
+ }
- in = myfopen(fname,"r");
+ in = myfopen(fname,"r");
if (in == NULL){// || rin == NULL){
- fprintf(stderr, "one file is missing\n");
- return 0;
+ fprintf(stderr, "Error: File '%s' could not be found.\n", fname);
+ exit(1);
}
@@ -250,12 +261,22 @@ int main(int argc, char **argv){
free(mark);
}
- return 1;
+ exit(0);
}
+
rin = myfopen(fname2,"r");
+ if (rin == NULL){// || rin == NULL){
+ // Close file hande of other input file, before we bail out.
+ fclose(in);
+ fprintf(stderr, "Error: File '%s' could not be found.\n", fname);
+ exit(1);
+ }
+
+
nseq = readFastq(in, hashtype);
+ fclose(in);
remcnt = 0;
while(fscanf(rin, "%s", removethis) > 0){
@@ -275,7 +296,8 @@ int main(int argc, char **argv){
if (ofname[0]!=0)
out = myfopen(ofname,"w");
if (out == NULL)
- return;
+ fprintf(stderr, "Error: Couldn't write to file '%s'.\n", ofname);
+ exit(1);
for (i=0;i<nseq;i++){
//if (names[i] != NULL && !doclean && mark[i] != 0){
@@ -302,7 +324,7 @@ int main(int argc, char **argv){
- return 1;
+ return 0;
}
@@ -658,7 +680,7 @@ int hash(char *this_name, int nseq, int type){
index = 0;
if (infloop){
printf("infinite loop!!!!!!!!!!!!!\n");
- exit(0);
+ exit(1);
}
infloop=1;
}
@@ -842,8 +864,8 @@ FILE *myfopen(char *fname, char *mode){
FILE *ret;
ret = fopen(fname, mode);
if (ret == 0){
- fprintf(stderr, "File %s not found.\n", fname);
- exit(0);
+ fprintf(stderr, "Error: File '%s' not found.\n", fname);
+ exit(1);
}
return ret;
}
@@ -854,8 +876,8 @@ void *mymalloc(size_t size){
ret = malloc(size);
if (ret == NULL){
- fprintf(stderr, "Insufficient memory.\n");
- exit (0);
+ fprintf(stderr, "Error: Insufficient memory.\n");
+ exit (1);
}
return ret;