/* * dos2unix.c * * Copyright (c) 1997-2002 DF7BE * * $Id$ * * Logbuchprogramm DF7BE * Amateur-Radio log by DF7BE * Utility to convert DOS to UNIX Files * Doesn't matter with german Umlaute ! * * 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 ! * +------------+-------------------------+----------------------------------+ * ! 20.11.2002 ! W.Brunken DF7BE ! ready for full pathnames ! * +------------+-------------------------+----------------------------------+ * ! 29.11.2000 ! W.Brunken DF7BE ! first creation ! * +------------+-------------------------+----------------------------------+ * * Compiling: * * gcc dos2unix.c -o dos2unix.exe (DJGPP) * gcc dos2unix.c -o dos2unix (UNIX,LINUX) * cc dos2unix.c -o dos2unix (UNIX) * MICROSOFT QUICK C 2.5 : use Make Menu * set at Options model to "small" */ #include #include /* what-String */ char far what_string[] = "@(#)CLLOG DOS2UNIX V1.1 (c) DF7BE 1997-2002"; char * dname (char * s) /* schneidet die Dateierweiterung ab cuts file extension s : Pointer to String with filename */ /* modifcation : for full pathnames */ { char *h; char *sld , *slu, *sl; /* search for name and path */ sl = NULL; sld = NULL; slu = NULL; sl = NULL; /* DOS */ sld = strrchr(s,'\\'); if ( sld != NULL ) { sl = sld; } /* LINUX / UNIX */ slu = strrchr(s,'/'); if ( slu != NULL ) { sl = slu; } h = strrchr(s,'.'); if (h != NULL) { /* point in path ? */ /* OK, point marks an extension */ h++; * h = '\0'; } return s; } int main(int argc, char * argv[] ) { FILE *fp1, *fp2; char a; int c,rc; char tempfname[256]; char s[256]; if ( argc != 2 ) { printf("usage dos2unix \n"); printf("\n"); printf("Copyright (c) 1997-2000 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(1); } /* get new name of temporary target file (change file extension to "tmp") */ strcpy(s,argv[1]); strcpy(tempfname,dname(s)); strcat(tempfname,"tmp"); /* open input file */ if ( ( fp1 = fopen(argv[1],"rb") ) == (FILE *) 0 ) { printf(".. cannot open file %s\n", argv[1]); exit(1); } /* open temporary output file */ if ( ( fp2 = fopen(tempfname,"wb") ) == (FILE *) 0 ) { printf(".. cannot open file %s\n", tempfname); exit(1); } a = 0; /* read first */ c = fgetc(fp1); a = (char) c; while ( c != EOF ) { if ( a != 13 ) { rc = fprintf(fp2,"%c",a); if ( rc < 0 ) { printf(".. write error file %s\n", tempfname); fclose(fp1); fclose(fp2); exit(1); } } /* read next */ c = fgetc(fp1); a = (char) c; } /* at EOF */ fclose(fp1); fclose(fp2); /* move the names */ remove(argv[1]); rename( tempfname,argv[1]); /* ready */ exit(0); return(0); }