/* * unix2dos.c * * Copyright (c) 1997-2000 DF7BE * * Logbuchprogramm DF7BE * Amateur-Radio log by DF7BE * Utility to convert UNIX to DOS-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 ! * +------------+-------------------------+----------------------------------+ * ! 01.12.2000 ! W.Brunken DF7BE ! first creation ! * +------------+-------------------------+----------------------------------+ * * Compiling: * * gcc unix2dos.c -o unix2dos.exe (DJGPP) * gcc unix2dos.c -o unix2dos (UNIX,LINUX) * cc unix2dos.c -o unix2dos (UNIX) * MICROSOFT QUICK C 2.5 : use Menu * set at Options model to "small" */ #include #include const char what_string[] = { "@(#)CLLOG UNIX2DOS.C V1.0 (c) DF7BE 1997-2003" } ; const char what_string2[] = { "@(#)$Id$" } ; char * dname (char * s) /* schneidet die Dateierweiterung ab cuts file extension */ /* alte Implementierung old implementation { char * h; h = strrchr(s,'.'); if (h != NULL) { h++; * h = '\0'; } return s; } */ /* 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,b; int c,rc; char tempfname[256]; char s[256]; if ( argc != 2 ) { printf("usage unix2dos \n"); printf("\n"); printf("Copyright (c) 1997-2000 DF7BE\n"); 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; b = 0; /* read first */ c = fgetc(fp1); a = (char) c; while ( c != EOF ) { if ( ( a == 10 ) && ( b != 13 ) ) { b = 13; rc = fprintf(fp2,"%c",b); if ( rc < 0 ) { printf(".. write error file %s\n",tempfname); fclose(fp1); fclose(fp2); exit(1); } } rc = fprintf(fp2,"%c",a); if ( rc < 0 ) { printf(".. write error file %s\n", tempfname); fclose(fp1); fclose(fp2); exit(1); } b = a; /* 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); }