Date: Sat, 25 Nov 2000 14:18:19 +0200 (WET) From: Andris Pavenis To: Eli Zaretskii cc: ST001906 AT HRZ1 DOT HRZ DOT TU-Darmstadt DOT De, djgpp-workers AT delorie DOT com Subject: Re: Patch #3 for dtou.c In-Reply-To: <2593-Sat25Nov2000131027+0200-eliz@is.elta.co.il> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: djgpp-workers AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp-workers AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk On Sat, 25 Nov 2000, Eli Zaretskii wrote: > > From: "Juan Manuel Guerrero" > > Date: Sat, 25 Nov 2000 10:52:38 +0200 > > > > Thank you for the advice. The bug has been fixed. > > I hope that there will be no more surprises. > > Thanks, I applied the patches. I also added a short fragment for > wc204.txi, and committed that as well. > > > diff -acprNC5 djgpp.orig/src/util/dtou.c djgpp/src/util/dtou.c > > *** djgpp.orig/src/util/dtou.c Wed Nov 22 23:43:52 2000 > > --- djgpp/src/util/dtou.c Sat Nov 25 06:47:42 2000 > > Btw, the correct directory is src/utils, not src/util (I needed to > edit the patch to get it apply cleanly). > > How about adding all the new switches, except -r and -s, to utod? > They seem all relevant. > > Thanks again for working on this. > Updated sources from CVS. Some initial comments: Perhaps there is no need to convert argv[0] to lowercase to print usage info. Function strlwr() used for this purpose is not portable (not ANSI,not POSIX). As result dtou.c is not compiling for me on Linux (glibc-2.2) and under AIX 4.3.1 on RS6000. Also we should strip path from argv[0] for displaying usage info Also I think it's better to return 0 unless return code is explicitly requested by some command line parameter. About -v and -vv: I think that we should use verbose=2 instead of vverbose=1 (so if we change to getopt() each -v increases variable verbose) This version of dtou will also not work for example if we want to convert single file '-v' (it's veird of course). So I think it's better to use getopt() for parsing options (so one can use 'dtou -- -v') I'm including patch with following fixes: - IS_DIR_SEPARATOR is system specific ('\\' and ':' is a separator not for all systems) - stripping path from executable name when displaying usage info - removal on non-portable function strlwr() - adding missing '\n' at end of output of usage info I didn't touch: - return code - conversion to use getopt() Andris PS. Anyway it's nice to have changes in so we can fix remaining problems instead of messing with big patches. *** djgpp/src/utils/dtou.c~1 Sat Nov 25 13:17:01 2000 --- djgpp/src/utils/dtou.c Sat Nov 25 14:13:34 2000 *************** *** 14,20 **** --- 14,25 ---- #define O_BINARY 0 #endif + #if defined(MSDOS) || defined(_Windows) #define IS_DIR_SEPARATOR(path) ((path) == '/' || (path) == '\\' || (path) == ':') + #else + #define IS_DIR_SEPARATOR(path) ((path) == '/') + #endif + #define IS_LAST_CR_IN_BUF (i == l - 1) #define IS_LAST_CR_IN_FILE (position + i + 1 == st.st_size) #define SET_FLAG(flag) \ *************** *** 33,38 **** --- 38,54 ---- #define IO_ERROR 0x01 /* Some I/O error occurred. */ + static char * + BaseName (char * name) + { + char * bn, *w; + for (bn = w = name; *w; w++) + if (IS_DIR_SEPARATOR (*w)) + bn = w+1; + return bn; + } + + static int dtou(char *fname, int make_backup, int repair_mode, int strip_mode, int verbose, int vverbose, int preserve_timestamp) { *************** *** 40,46 **** int CntlZ_flag = 0, CR_flag = 0, nCR_flag = 0, LF_flag = 0, exit_status = NO_ERROR; int buf_counter, nbufs, LF_counter, must_rewind, position, offset, whence; char buf[BUF_SIZE]; ! char bfname[FILENAME_MAX], tfname[FILENAME_MAX], *bn, *w; struct stat st; struct utimbuf tim1; --- 56,62 ---- int CntlZ_flag = 0, CR_flag = 0, nCR_flag = 0, LF_flag = 0, exit_status = NO_ERROR; int buf_counter, nbufs, LF_counter, must_rewind, position, offset, whence; char buf[BUF_SIZE]; ! char bfname[FILENAME_MAX], tfname[FILENAME_MAX], *bn; struct stat st; struct utimbuf tim1; *************** *** 57,66 **** nbufs = st.st_size / BUF_SIZE; strcpy (tfname, fname); ! for (bn = w = tfname; *w; w++) ! if (IS_DIR_SEPARATOR (*w)) ! bn = w+1; ! if (bn) *bn=0; strcat (tfname,"dtou.tm$"); if (make_backup) { --- 73,80 ---- nbufs = st.st_size / BUF_SIZE; strcpy (tfname, fname); ! bn=BaseName(tfname); ! *bn=0; strcat (tfname,"dtou.tm$"); if (make_backup) { *************** *** 249,255 **** printf ("are given at all. In this case, an occurrence of Cntl-Z will truncate the file,\n"); printf ("MSDOS-style EOL (CRLF) are transformed into UNIX-style EOL (LF) and CR sequence\n"); printf ("stripping will not happen at all. Also the timestamp will not be alterated and\n"); ! printf ("no backup of the original file will be done."); } int --- 263,269 ---- printf ("are given at all. In this case, an occurrence of Cntl-Z will truncate the file,\n"); printf ("MSDOS-style EOL (CRLF) are transformed into UNIX-style EOL (LF) and CR sequence\n"); printf ("stripping will not happen at all. Also the timestamp will not be alterated and\n"); ! printf ("no backup of the original file will be done.\n"); } int *************** *** 257,263 **** { int exit_status = NO_ERROR, i, make_backup, repair_mode; int strip_mode, verbose, vverbose, preserve_timestamp; ! char* progname = strlwr(strdup(argv[0])); if (argc < 2) { --- 271,277 ---- { int exit_status = NO_ERROR, i, make_backup, repair_mode; int strip_mode, verbose, vverbose, preserve_timestamp; ! char* progname = BaseName(argv[0]); if (argc < 2) {