/* * hasnoel.c * * Copyright (c) 1997-2003 DF7BE * * $Id$ * * Logbuchprogramm DF7BE * Amateur-Radio log by DF7BE * Utility to test files for "noeol" (Incomplete last line) * * 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 ! * +------------+-------------------------+----------------------------------+ * ! 31.10.2003 ! W.Brunken DF7BE ! first creation ! * +------------+-------------------------+----------------------------------+ * * Compiling: * * gcc hasnoel.c -o hasnoel.exe (DJGPP) * gcc hasnoel.c -o hasnoel (UNIX,LINUX) * cc hasnoel.c -o hasnoel (UNIX) * MICROSOFT QUICK C 2.5 : use Make Menu * set at Options model to "small" * * hint for IBM-AIX: * set environment before compiling: * LIBPATH=/usr/lib * or add option: * -L/usr/lib * */ #include #include /* what-String */ char far what_string[] = "@(#)CLLOG hasnoel V1.1 (c) DF7BE 1997-2003"; int main(int argc, char * argv[] ) { FILE *fp1; int c,rc,pc; if ( argc != 2 ) { printf("usage hasnoel \n"); printf(" returning 0=with EOL, 1 or greater : noeol or error\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 */ pc = 0; /* previos char */ /* open input file */ if ( ( fp1 = fopen(argv[1],"rb") ) == (FILE *) 0 ) { printf(".. cannot open file %s\n", argv[1]); exit(2); } /* read first */ c = fgetc(fp1); rc++; if( c == EOF ) { printf("empty file\n"); fclose(fp1); exit(2); } while ( c != EOF ) { /* read next */ c = fgetc(fp1); rc++; /* previous char */ if ( c != EOF ) { pc = c; } /* first read the complete file */ } /* at EOF */ fclose(fp1); /* previous char must be 0a = 10 , (0d0a DOS, 0a UNIX) */ if ( pc == 10 && c == EOF ) { /* OK */ exit(0); return(0); } exit(1); return(1); }