/* * isdos.c * * Copyright (c) 1997-2003 DF7BE * * $Id$ * * Logbuchprogramm DF7BE * Amateur-Radio log by DF7BE * Utility to test files for DOS * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the license, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA ( or visit * their web site at http://www.gnu.org/ ). * * * Modification documentation * * +------------+-------------------------+----------------------------------+ * + Date ! Name and Call ! Modification ! * +------------+-------------------------+----------------------------------+ * ! 08.01.2003 ! W.Brunken DF7BE ! first creation ! * +------------+-------------------------+----------------------------------+ * * Compiling: * * gcc isdos.c -o isdos.exe (DJGPP) * gcc isdos.c -o isdos (UNIX,LINUX) * cc isdos.c -o isdos (UNIX) * MICROSOFT QUICK C 2.5 : use Make Menu * set at Options model to "small" */ #include #include /* what-String */ char far what_string[] = "@(#)CLLOG ISDOS V1.1 (c) DF7BE 1997-2003"; int main(int argc, char * argv[] ) { FILE *fp1; int c,rc; if ( argc != 2 ) { printf("usage isdos \n"); printf(" returning 0=DOS 1=UNIX , 2 or greater : error or binary\n"); printf("\n"); printf("Copyright (c) 1997-2003 DF7BE\n"); printf("%s",what_string); printf("\n"); printf("This program is free software; you can redistribute it and/or modify\n"); printf("it under the terms of the GNU General Public License as published by\n"); printf("the Free Software Foundation; either version 2 of the license, or\n"); printf("(at your option) any later version.\n"); printf("\n"); printf("This program is distributed in the hope that it will be useful,\n"); printf("but WITHOUT ANY WARRANTY; without even the implied warranty of\n"); printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"); printf("GNU General Public License for more details.\n"); printf("You should have received a copy of the GNU General Public License\n"); printf("along with this program; if not, write to the Free Software\n"); printf("Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA ( or visit\n"); printf("their web site at http://www.gnu.org/ ).\n"); exit(2); } rc = 0; /* counter */ /* open input file */ if ( ( fp1 = fopen(argv[1],"rb") ) == (FILE *) 0 ) { printf(".. cannot open file %s\n", argv[1]); exit(1); } /* read first */ c = fgetc(fp1); rc++; if( c == EOF ) { printf("empty file\n"); fclose(fp1); exit(2); } if( c == 0 ) /* 0x00 found */ { printf("binary file\n"); fclose(fp1); exit(0); } if( c == 13 ) /* 0x0D found */ { printf("DOS text file\n"); fclose(fp1); exit(0); } while ( c != EOF ) { /* read next */ c = fgetc(fp1); rc++; if( c == 0 ) /* 0x00 found */ { printf("binary file\n"); fclose(fp1); exit(0); } if( c == 13 ) /* 0x0D found */ { printf("DOS text file\n"); fclose(fp1); exit(0); } } /* at EOF */ fclose(fp1); /* no 0x00 or 0x0D found, UNIX textfile expected */ printf("UNIX text file\n"); exit(1); return(1); }