--- YDEC.C Wed Nov 14 11:30:52 2001 +++ ydec.c Tue Feb 5 16:37:11 2002 @@ -21,24 +21,39 @@ */ +#ifdef WINDOWS // Includes for Windows-version. Only used to create a MessageBox #include #include +#endif + #include #include -#include +#include #include #include -// For SOPEN -#include #include -#include +#include -#include +#ifdef WINDOWS +#include #include +#include +// For SOPEN +#include +#include #pragma warn -pro +#else +#include +long filelength(int fd){ + struct stat st; + if (fstat(fd, &st)) + return -1; + return st.st_size; +} +#endif int errors,errparts,errfiles; @@ -276,7 +291,7 @@ } if (strncmp((char*) srcbuf,"=yend ",6)==0) { - if (aDsp) print("Endline (%d bytes): %s\r\n",decolen,srcbuf); + if (aDsp) print("Endline (%ld bytes): %s\r\n",decolen,srcbuf); goto end_of_file; } if (strncmp((char*) srcbuf,"=ybegin ",8)==0) @@ -723,9 +738,8 @@ char srcmask[260]; -int DecodeFile(char * fname) +int DecodeStream(FILE * fIn, char *fname) { - FILE * fIn; char line[8200]; char * cp; char filename[260]; @@ -734,13 +748,6 @@ long flen,wlen; char filename2[260]; - fIn=fopen(fname,"rb"); - if (fIn==NULL) - { - eprint("Cannot open sourcefile (%s) [reason:%d]\r\n",fname,errno); - errors++; - return(1); - } loop: cp=fgets(line,8192,fIn); // Read source line if (cp==NULL) goto eof1; @@ -808,8 +815,8 @@ // ----- Special Handling for offline decoder (missing parts or mixed sequence) if (y_part) { - sprintf(filename ,"%s%s%s(%ld).tmp",ad_despath,attname,attext,y_size); - sprintf(filename2,"%s%s%s(%ld).dec",ad_despath,attname,attext,y_size); + sprintf(filename ,"%s%s%s(%d).tmp",ad_despath,attname,attext,y_size); + sprintf(filename2,"%s%s%s(%d).dec",ad_despath,attname,attext,y_size); } // ---------------------------------------------------------------------- @@ -860,7 +867,7 @@ else { fclose(fOut); - eprint("Size mismatch on target multipart file !(act:%ld, new:%ld) (%s)\r\n",flen,y_size,filename); + eprint("Size mismatch on target multipart file !(act:%ld, new:%d) (%s)\r\n",flen,y_size,filename); errors++; goto abortus; } @@ -874,7 +881,7 @@ errors++; goto abortus; } - fprintf(fOut,"%ld,%ld\r\n",1,y_size); // Everything is missing ! + fprintf(fOut,"%d,%d\r\n",1,y_size); // Everything is missing ! fclose(fOut); } } @@ -884,7 +891,6 @@ { eprint("AutoDecode: Cannot create DesFile (%s)\r\n",filename); errors++; - fclose(fIn); return(-1); // goto loop; } @@ -902,7 +908,6 @@ { eprint("Could not create the target file (disk full?)\r\n"); fclose(fOut); - fclose(fIn); errors++; return(-2); } @@ -950,7 +955,7 @@ id=rename(filename,ad_desname); if (id) { - if (errno==35) + if (errno==EEXIST) { eprint("File exists already: (%s)\r\n",ad_desname); errors++; @@ -971,19 +976,36 @@ eof1: - fclose(fIn); return(0); } +int DecodeFile(char * fname) + { + int r; + FILE * fIn; + fIn=fopen(fname,"rb"); + if (fIn==NULL) + { + eprint("Cannot open sourcefile (%s) [reason:%d]\r\n",fname,errno); + errors++; + return(1); + } + + r=DecodeStream(fIn, fname); + fclose(fIn); + return r; + } int main(int ac, char * av[]) { - struct ffblk fblk; int id; +#ifdef WINDOWS + struct ffblk fblk; char mask[260]; char * cp; +#endif errors=0; // Counter for batch decoder errors errfiles=0; @@ -1003,6 +1025,7 @@ // if (ac>=2) print("[1]: %s\r\n",av[1]); // if (ac>=3) print("[2]: %s\r\n",av[2]); +#ifdef WINDOWS if (ac<2) { print("Missing parameter (filename or filename*.* required) !\r\n"); @@ -1064,6 +1087,26 @@ if (id==0) goto loop; done: +#else + id = 1; + if (id