delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2000/11/27/02:08:50

From: "Juan Manuel Guerrero" <ST001906 AT HRZ1 DOT HRZ DOT TU-Darmstadt DOT De>
Organization: Darmstadt University of Technology
To: djgpp-workers AT delorie DOT com
Date: Mon, 27 Nov 2000 08:07:20 +0200
MIME-Version: 1.0
Subject: Patch for utod and dtou
CC: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>, Andris Pavenis <pavenis AT lanet DOT lv>
X-mailer: Pegasus Mail for Windows (v2.54DE)
Message-ID: <B8DF664CBC@HRZ1.hrz.tu-darmstadt.de>
Reply-To: djgpp-workers AT delorie DOT com

On Sat, 25 Nov 2000 20:26:07, Andris Pavenis wrote:

> On 25 Nov 2000, at 17:44, Juan Manuel Guerrero wrote:
[snip]
> > Missing '\n' issue. The '\n' has **not** been forgotten. This was intentional.
> > I wanted that the complete help text fits into **one** screen without scrolling
> >  the first line out of the screen.
>
> In this case we should add 
>
> #if !defined(MSDOS) && !defined(_Windows)
>	"\n"
> #endif
>
> at end of string as for example in Linux no extra LF is appended (I 
> tested CVS version of dtou on Linux). 
[snip]
This issue can be forgotten. The help text fits into the screen without
scrolling the first lines out of the screen.

> 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')
OK. This have been done. dtou und utod will use getopt() to parse the command line.
In util.tex I have explained that the user can use `--' to separate
options from file names, if file names starts with a dash.

I have added the following command line options to utod:
-b: Backup mode.
-t: Will not preserve timestamp if file has been modified.
-v: Tells if file has been modified or not
-vv or -v -v: More verbose output.

For other changes, please inspect the patch.
The patch will modify the files utod.c, dtou.c and util.tex.

All tests on dos, no tests on linux.

------------------------------------------------------------------------------
Answers to mails I have read this morning.


Date: Sun, 26 Nov 2000 16:48:37 -0500
From: DJ Delorie <dj AT delorie DOT com>
> > I didn't say that in my original message, but for compatibility reasons
> > (old Makefiles) it might be a good idea to return non-zero exit status
> > only under a special option, and retain the current behavior if that
> > option was not given. 
> 
> dtou should return zero if it was successful.  "Successful" means it
> changed the files it should have, and left the files it should have.
> A non-success exit (nonzero) should be restricted to *unexpected*
> problems, such as file not found, disk full, access denied. read-only
> media, etc.
> 
> My preference is that the exit code should reflect the number of
> problems encountered, not the type.  If you wish a special option to
> make the exit code reflect the conversions done, that's OK, but it
> shouldn't be the default, no matter how many files are listed on the
> command line.
I think that the actual dtou.c does exactely this. The exit code reflects
the amount of *unsuccessfully* preocessed files. The dtou.c version that returned
an exit code reflecting the kind of fealure for a single file has been *rejected*
a couple of days before.
IMHO, this issue is closed, or am I missing something?


Date: Sun, 26 Nov 2000 16:57:06 -0500
From: DJ Delorie <dj AT delorie DOT com>
> > There are examples of software where additional -v simply increases 
> > verbosity level. First example which comes into mind is bzip2.
>
> I use this method a lot.  I'm not sure if getopt supports that
> gracefully.  I don't mind if people want to volunteer to switch
> programs to getopt (as long as it's the default getopt and not a
> custom one) but I don't personally use it.  I never know which getopt
> is going to be available.
This is very unfortunate because I have changed to getopt() as recuested.
Of course, I am using getopt() from libc.a and not some strange version
invented by myself. IIRC, libc's manual tells that it is posix.
It would be nice if someone could clearify this issue.
What shall be used???  What shall be done???
I have no preferences. I still have patches with *and* without getopt().



Date: Sun, 26 Nov 2000 01:18:09 +0200
From: "Eli Zaretskii" <eliz AT is DOT elta DOT co DOT il>
> > From: pavenis AT lanet DOT lv
> > Date: Sat, 25 Nov 2000 20:34:08 +0200
> >
> > > Missing '\n' issue. The '\n' has **not** been forgotten. This was
> > > intentional.  I wanted that the complete help text fits into
> > > **one** screen without scrolling the first line out of the screen.
> > 
> > In this case we should add 
> > 
> > #if !defined(MSDOS) && !defined(_Windows)
> > 	"\n"
> > #endif
> > 
> > at end of string as for example in Linux no extra LF is appended (I 
> > tested CVS version of dtou on Linux). 
> 
> I checked in a change similar to the above.
This is very unfortunate because this is no longer needed. IMHO, that change
should be discarted from the code because it is of **no** use.
The help text **fits** completely into one screen without scrolling the first
lines out of the screen.
Excuse the inconveniences caused.


Although the patch presented here uses getopt(), I submite them anyway.
May be the are of some use. If the use of getopt() is not wanted, please
notify me as soon as possible.



Regards,
Guerrero, Juan Manuel


diff -acprNC5 djgpp.orig/src/utils/dtou.c djgpp/src/utils/dtou.c
*** djgpp.orig/src/utils/dtou.c	Sat Nov 25 19:52:58 2000
--- djgpp/src/utils/dtou.c	Mon Nov 27 06:55:56 2000
***************
*** 9,58 ****
  #include <string.h>
  #include <unistd.h>
  #include <utime.h>
  
  #ifndef O_BINARY
! #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)         \
  do {                           \
    if ((flag) == 0) (flag) = 1; \
  } while (0)
  #define BUF_SIZE      16384
  
! /* Control characters. */    
  #define LF            0x0A
  #define CR            0x0D
  #define CntlZ         0x1A
  
  /* Exit codes. */
  #define NO_ERROR      0x00
  #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)
  {
    int i, k, sf, df, l, l2 = 0, is_CR = 0, is_nCR = 0, is_CR_sequence = 0;
    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];
--- 9,57 ----
  #include <string.h>
  #include <unistd.h>
  #include <utime.h>
  
  #ifndef O_BINARY
! # 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)         \
  do {                           \
    if ((flag) == 0) (flag) = 1; \
  } while (0)
  #define BUF_SIZE      16384
  
! /* Control characters. */
  #define LF            0x0A
  #define CR            0x0D
  #define CntlZ         0x1A
  
  /* Exit codes. */
  #define NO_ERROR      0x00
  #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 verbosity, int preserve_timestamp)
  {
    int i, k, sf, df, l, l2 = 0, is_CR = 0, is_nCR = 0, is_CR_sequence = 0;
    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];
*************** dtou(char *fname, int make_backup, int r
*** 71,96 ****
    tim1.actime = st.st_atime;
    tim1.modtime = st.st_mtime;
    nbufs = st.st_size / BUF_SIZE;
  
    strcpy (tfname, fname);
!   bn=BaseName(tfname);
!   *bn=0;
    strcat (tfname,"dtou.tm$");
    if (make_backup)
    {
      strcpy (bfname, fname);
!     if (pathconf ((fname), _PC_NAME_MAX) <= 12)
        for (i = strlen (bfname); i > -1; i--)
          if (bfname[i] == '.')
          {
            bfname[i] = '\0';
            break;
          }
!     strcat (bfname,".d2u");
    }
!   
    df = open (tfname, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644);
    if (df < 1)
    {
      perror (tfname);
      close (sf);
--- 70,95 ----
    tim1.actime = st.st_atime;
    tim1.modtime = st.st_mtime;
    nbufs = st.st_size / BUF_SIZE;
  
    strcpy (tfname, fname);
!   bn = BaseName (tfname);
!   *bn = 0;
    strcat (tfname,"dtou.tm$");
    if (make_backup)
    {
      strcpy (bfname, fname);
!     if (pathconf ((bfname), _PC_NAME_MAX) <= 12)
        for (i = strlen (bfname); i > -1; i--)
          if (bfname[i] == '.')
          {
            bfname[i] = '\0';
            break;
          }
!     strcat (bfname, ".d2u");
    }
! 
    df = open (tfname, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644);
    if (df < 1)
    {
      perror (tfname);
      close (sf);
*************** dtou(char *fname, int make_backup, int r
*** 107,118 ****
    {
      offset = -1;
      whence = SEEK_CUR;
    }
    while ((l = read (sf, buf, BUF_SIZE)) > 0)
!   { 
!     for (i = k = 0; i < l; i++) 
      {
        if (strip_mode)
        {
          if (buf[i] == LF)
          {
--- 106,117 ----
    {
      offset = -1;
      whence = SEEK_CUR;
    }
    while ((l = read (sf, buf, BUF_SIZE)) > 0)
!   {
!     for (i = k = 0; i < l; i++)
      {
        if (strip_mode)
        {
          if (buf[i] == LF)
          {
*************** dtou(char *fname, int make_backup, int r
*** 202,226 ****
  
    if (l >= 0 && l2 >= 0 && exit_status == NO_ERROR)
    {
      int file_has_changed = CR_flag || nCR_flag || CntlZ_flag || LF_flag;
  
!     if (verbose)
        printf ("File: %s successfully processed.\n",fname);
!     if (vverbose)
        printf ("File: %s\n",fname);
  
!     if (CR_flag && vverbose) 
        printf ("At least one CR/LF to LF transformation occurred.\n");
!     if (nCR_flag && vverbose) 
        printf ("Warning: At least one CR sequence stripped from a LF.\n");
!     if (CntlZ_flag && vverbose) 
        printf ("Warning: At least one Cntl-Z has been found. File truncated at line %i.\n", LF_counter);
!     if (LF_flag && vverbose) 
        printf ("Warning: At least one LF without a preceeding CR has been found.\n");
  
!     if (vverbose && !file_has_changed)
        printf ("File unchanged.\n");
  
      if (make_backup && file_has_changed)
        rename (fname, bfname);
      else
--- 201,225 ----
  
    if (l >= 0 && l2 >= 0 && exit_status == NO_ERROR)
    {
      int file_has_changed = CR_flag || nCR_flag || CntlZ_flag || LF_flag;
  
!     if (verbosity == 1)
        printf ("File: %s successfully processed.\n",fname);
!     if (verbosity == 2)
        printf ("File: %s\n",fname);
  
!     if (CR_flag && (verbosity == 2))
        printf ("At least one CR/LF to LF transformation occurred.\n");
!     if (nCR_flag && (verbosity == 2))
        printf ("Warning: At least one CR sequence stripped from a LF.\n");
!     if (CntlZ_flag && (verbosity == 2))
        printf ("Warning: At least one Cntl-Z has been found. File truncated at line %i.\n", LF_counter);
!     if (LF_flag && (verbosity == 2))
        printf ("Warning: At least one LF without a preceeding CR has been found.\n");
  
!     if ((verbosity == 2) && !file_has_changed)
        printf ("File unchanged.\n");
  
      if (make_backup && file_has_changed)
        rename (fname, bfname);
      else
*************** dtou(char *fname, int make_backup, int r
*** 232,252 ****
        utime (fname, &tim1);
    }
    else
    {
      remove (tfname);
!     if (verbose || vverbose)
        printf ("File: %s. An I/O error occurred\n",fname);
    }
  
    return exit_status;
  }
  
  static void
  usage(char *progname)
  {
!   printf ("Usage: %s [-b] [-h] [-r] [-s] [-t] [-v] [-vv] files...\n\n", progname);
    printf ("Options are:\n");
    printf ("            -b:  A backup of the original file is made using `.d2u' as backup\n");
    printf ("                 extension, if the file has been modified.\n");
    printf ("            -h:  Display this help and exit.\n");
    printf ("            -r:  Transform MSDOS-style EOF (CRLF) into UNIX-style EOL (LF).\n");
--- 231,251 ----
        utime (fname, &tim1);
    }
    else
    {
      remove (tfname);
!     if (verbosity)
        printf ("File: %s. An I/O error occurred\n",fname);
    }
  
    return exit_status;
  }
  
  static void
  usage(char *progname)
  {
!   printf ("Usage: %s [-b] [-h] [-r] [-s] [-t] [-v] [-v -v|-vv] files...\n\n", progname);
    printf ("Options are:\n");
    printf ("            -b:  A backup of the original file is made using `.d2u' as backup\n");
    printf ("                 extension, if the file has been modified.\n");
    printf ("            -h:  Display this help and exit.\n");
    printf ("            -r:  Transform MSDOS-style EOF (CRLF) into UNIX-style EOL (LF).\n");
*************** usage(char *progname)
*** 256,301 ****
    printf ("                 and strip a CR sequence of arbitrary length from the file,\n");
    printf ("                 if and only if the sequence is followed by LF. CR sequences\n");
    printf ("                 that are not followed by LF are always left unchanged.\n");
    printf ("            -t:  The timestamp of the modified file will not be preserved.\n");
    printf ("            -v:  Show if file processing has been successful or not.\n");
!   printf ("           -vv:  Show the kind of modifications that have been done to the file.\n");
    printf ("The program is backward compatible with previous program versions if no options\n");
    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
! main(int argc, char **argv)
  {
!   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)
    {
      usage (progname);
!     exit(NO_ERROR);
    }
  
!   /* Default for backward compatibility. */ 
!   make_backup = repair_mode = strip_mode = verbose = vverbose = 0;
    preserve_timestamp = 1;
  
!   i = 1;
!   while ((argc > i) && (argv[i][0] == '-') && argv[i][1])
    {
!     switch (argv[i][1])
      {
        case 'b':
          make_backup = 1;
          break;
        case 'h':
          usage (progname);
!         exit(NO_ERROR);
          break;
        case 'r':
          repair_mode = 1;
          strip_mode = 0;
          break;
--- 255,301 ----
    printf ("                 and strip a CR sequence of arbitrary length from the file,\n");
    printf ("                 if and only if the sequence is followed by LF. CR sequences\n");
    printf ("                 that are not followed by LF are always left unchanged.\n");
    printf ("            -t:  The timestamp of the modified file will not be preserved.\n");
    printf ("            -v:  Show if file processing has been successful or not.\n");
!   printf ("  -v -v or -vv:  Show the kind of modifications that have been done to the file.\n");
    printf ("The program is backward compatible with previous program versions if no options\n");
    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 file of the original file will be created.\n");
  }
  
  int
! main (int argc, char **argv)
  {
!   int exit_status = NO_ERROR, make_backup, repair_mode;
!   int strip_mode, verbosity, preserve_timestamp;
!   int option;
!   char *progname = BaseName(argv[0]);
  
    if (argc < 2)
    {
      usage (progname);
!     exit (NO_ERROR);
    }
  
!   /* Default for backward compatibility. */
!   make_backup = repair_mode = strip_mode = verbosity = 0;
    preserve_timestamp = 1;
  
!   opterr = 0;
!   while ((option = getopt (argc, argv, "bhrstv")) != -1)
    {
!     switch (option)
      {
        case 'b':
          make_backup = 1;
          break;
        case 'h':
          usage (progname);
!         exit (NO_ERROR);
          break;
        case 'r':
          repair_mode = 1;
          strip_mode = 0;
          break;
*************** main(int argc, char **argv)
*** 305,333 ****
          break;
        case 't':
          preserve_timestamp = 0;
          break;
        case 'v':
!         if (argv[i][2] == 'v')
!         {
!           vverbose = 1;
!           verbose = 0;
!         }
!         else
!         {
!           verbose = 1;
!           vverbose = 0;
!         }
          break;
!       default:
!         fprintf (stderr, "%s: invalid option -- %s\n", progname, &argv[i][1]);
          fprintf (stderr, "Try `%s -h' for more information.\n", progname);
          exit (IO_ERROR);
          break;
      }
-     i++;
    }
  
!   for (; i < argc; i++)
!     exit_status += dtou (argv[i], make_backup, repair_mode, strip_mode, verbose, vverbose, preserve_timestamp);
    return exit_status;
  }
--- 305,325 ----
          break;
        case 't':
          preserve_timestamp = 0;
          break;
        case 'v':
!         verbosity++;
!         if (verbosity > 2)
!           verbosity = 2;
          break;
!       case '?':
!         fprintf (stderr, "%s: invalid option -- %c.\n", progname, optopt);
          fprintf (stderr, "Try `%s -h' for more information.\n", progname);
          exit (IO_ERROR);
          break;
      }
    }
  
!   for (; optind < argc; optind++)
!     exit_status += dtou (argv[optind], make_backup, repair_mode, strip_mode, verbosity, preserve_timestamp);
    return exit_status;
  }
diff -acprNC5 djgpp.orig/src/utils/utils.tex djgpp/src/utils/utils.tex
*** djgpp.orig/src/utils/utils.tex	Sat Nov 25 19:53:18 2000
--- djgpp/src/utils/utils.tex	Mon Nov 27 06:43:34 2000
*************** so that they won't get mixed with the fi
*** 321,331 ****
  @c -----------------------------------------------------------------------------
  @node dtou, utod, djtar, Top
  @chapter dtou
  
  Usage: @code{dtou} [@code{-b}] [@code{-h}] [@code{-r}] [@code{-s}] [@code{-t}]
! [@code{-v}] [@code{-vv}] @file{files}
  
  Each file specified on the command line is converted from dos's CR/LF
  text file mode to unix's NL text file mode.
  
  All djgpp wildcards are supported.  Timestamps of the files are preserved.
--- 321,331 ----
  @c -----------------------------------------------------------------------------
  @node dtou, utod, djtar, Top
  @chapter dtou
  
  Usage: @code{dtou} [@code{-b}] [@code{-h}] [@code{-r}] [@code{-s}] [@code{-t}]
! [@code{-v}] [@code{-v -v}|@code{-vv}] @file{files}
  
  Each file specified on the command line is converted from dos's CR/LF
  text file mode to unix's NL text file mode.
  
  All djgpp wildcards are supported.  Timestamps of the files are preserved.
*************** All djgpp wildcards are supported.  Time
*** 334,343 ****
--- 334,348 ----
  files have been successfully processed and an exit status greater than 0 if
  not.  In this case, the exit status is equal to the amount of unsuccessfully
  processed files.  A file has not been successfully processed if some kind of
  I/O error occurred.
  
+ If a file name starts with a dash, you can place @code{--} in the command line
+ to separate it from the options.  @code{dtou} will stop scanning the command
+ line for options as soon as it finds @code{--} and will treat everything
+ beyond @code{--} as file names.
+ 
  @strong{Options:}
  
  @table @code
  
  @item -b
*************** Warning: At least one Cntl-Z has been fo
*** 396,413 ****
  Warning: At least one LF without a preceeding CR has been found.
  @end example
  
  Of course, not all of the above lines will appear all together.  The first
  line showing the file name will always be printed.  If the file has not been
! modified at all, then only the next line will be printed.  If the file has
! been modified an appropiate combination of the lines 3 to 6 will be printed,
  indicating what has been modified.  The above output is of some use, e.g.:
  if @code{dtou} reports a LF without a preceeding CR this will be a sure sign
  that the file is either binary or has inconsistent EOL format for some other
  reason.  If @code{dtou} reports that a Cntl-Z (software EOF) has been found,
! then the file will be truncated at that line and the rest of the file will be
! lost.
  
  @end table
  
  The program is backward compatible with previous program versions if no options
  are given at all.  In this case, an occurrence of Cntl-Z will truncate the file,
--- 401,419 ----
  Warning: At least one LF without a preceeding CR has been found.
  @end example
  
  Of course, not all of the above lines will appear all together.  The first
  line showing the file name will always be printed.  If the file has not been
! modified at all, then only the next line will be printed.  This will be the
! case if the file does not contain any CR/LF pair at all.  If the file has been
! modified an appropiate combination of the lines 3 to 6 will be printed,
  indicating what has been modified.  The above output is of some use, e.g.:
  if @code{dtou} reports a LF without a preceeding CR this will be a sure sign
  that the file is either binary or has inconsistent EOL format for some other
  reason.  If @code{dtou} reports that a Cntl-Z (software EOF) has been found,
! then the file will be truncated at that line and the rest of the file contents
! will be lost.
  
  @end table
  
  The program is backward compatible with previous program versions if no options
  are given at all.  In this case, an occurrence of Cntl-Z will truncate the file,
*************** no backup of the original file will be d
*** 417,431 ****
--- 423,501 ----
  
  @c -----------------------------------------------------------------------------
  @node utod, gxx, dtou, Top
  @chapter utod
  
+ Usage: @code{utod} [@code{-b}] [@code{-h}] [@code{-t}]
+ [@code{-v}] [@code{-v -v}|@code{-vv}] @file{files}
+ 
  Each file specified on the command line is converted from unix's NL text
  file mode to dos's CR/LF text file mode.
  
  All djgpp wildcards are supported.  Timestamps of the files are preserved.
  
+ @code{utod} will pass an exit status of 0 to the calling context if all the
+ files have been successfully processed and an exit status greater than 0 if
+ not.  In this case, the exit status is equal to the amount of unsuccessfully
+ processed files.  A file has not been successfully processed if some kind of
+ I/O error occurred.
+ 
+ If a file name starts with a dash, you can place @code{--} in the command line
+ to separate it from the options.  @code{utod} will stop scanning the command
+ line for options as soon as it finds @code{--} and will treat everything
+ beyond @code{--} as file names.
+ 
+ @strong{Options:}
+ 
+ @table @code
+ 
+ @item -b
+ 
+ Creates a backup of the original file if the file has been modified.
+ @file{.u2d} is used as backup suffix.  On systems with LFN support, the
+ backup suffix will be appended to the file name.  If no LFN support is
+ available the backup suffix will overwrite the original file suffix.
+ 
+ @item -h
+ 
+ Displays a help text and exits.
+ 
+ @item -t
+ 
+ Timestamp.  With this option the timestamp of a modified file will not be
+ preserved.  The timestamp of an unmodified file will always be preserved.
+ 
+ @item -v
+ 
+ Verbose mode.  Prints a single line showing the file name and if file
+ processing has been successful or not.  The only case that a file is
+ considered as unsuccessfully processed is if an I/O error has occurred.
+ 
+ @item -vv
+ 
+ Very verbose mode.  Prints the file name and shows the kind of modifications
+ that have been done to the file.  The possible output looks like:
+ 
+ @example
+ File: foo.c
+ File unchanged.
+ At least one LF to CR/LF transformation occurred.
+ @end example
+ 
+ Of course, not all of the above lines will appear all together.  The first
+ line showing the file name will always be printed.  If the file has not been
+ modified at all, then only the next line will be printed.  This will be the
+ case if the file does not contain any LF at all or if it is already a dos
+ text file.  If the file has been modified line 3 will be printed.
+ 
+ @end table
+ 
+ The program is backward compatible with previous program versions if no options
+ are given at all.  In this case, UNIX-style EOL (LF) are transformed into
+ MSDOS-style EOL (CR/LF), the timestamp will not be alterated and no backup
+ of the original file will be done.
+ 
  @c -----------------------------------------------------------------------------
  @node gxx, redir, utod, Top
  @chapter gxx
  
  This program is exactly like @code{gcc} (in fact, it @i{calls} gcc), except
diff -acprNC5 djgpp.orig/src/utils/utod.c djgpp/src/utils/utod.c
*** djgpp.orig/src/utils/utod.c	Sat Nov 25 19:53:36 2000
--- djgpp/src/utils/utod.c	Mon Nov 27 06:55:58 2000
***************
*** 10,95 ****
  #include <string.h>
  #include <unistd.h>
  #include <utime.h>
  
  #ifndef O_BINARY
! #define O_BINARY 0
  #endif
  
  
  static int
! utod(char *fname)
  {
!   int i, k, sf, df, l, l2=0, err=0, iscr=0;
!   char buf[16384], buf2[32768];
!   char tfname[FILENAME_MAX], *bn, *w;
    struct stat st;
    struct utimbuf tim1;
!   sf = open(fname, O_RDONLY|O_BINARY);
    if (sf < 0)
    {
!     perror(fname);
!     return 1;
    }
  
    fstat (sf,&st);
    tim1.actime = st.st_atime;
    tim1.modtime = st.st_mtime;
  
    strcpy (tfname, fname);
!   for (bn=w=tfname; *w; w++) 
!     if (*w=='/' || *w=='\\' || *w==':') 
!       bn = w+1;  
!   if (bn) *bn=0;
!   strcat (tfname,"utod.tm$");
!   
!   df = open(tfname, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644);
    if (df < 0)
    {
!     perror(tfname);
!     close(sf);
!     return 1;
    }
  
!   while ((l=read(sf, buf, 16384)) > 0)
    {
!     for (i=k=0; i<l; i++)
      {
!       if (buf[i]==10 && !iscr) buf2[k++]=13;
!       iscr=(buf[i]==13 ? 1 : 0);
!       buf2[k++]=buf[i];
      }
!     l2=write(df, buf2, k);
!     if (l2<0) break;
!     if (l2!=k) { err=1; break; }
    }
  
!   if (l<0) perror (fname);
!   if (l2<0) perror (tfname);
!   if (err) fprintf (stderr,"Cannot process file %s\n",fname);
  
!   close(sf);
!   close(df);
  
!   if (l>=0 && l2>=0 && err==0)
    {
!     remove(fname);
!     rename(tfname, fname);
!     utime(fname, &tim1);
!     chown(fname, st.st_uid, st.st_gid);
!     chmod(fname, st.st_mode);
    }
!   else 
    {
!     remove(tfname);
    }
!   return 0;
  }
  
  int
! main(int argc, char **argv)
  {
!   int rv = 0;
!   for (argc--, argv++; argc; argc--, argv++)
!     rv += utod(*argv);
!   return rv;
  }
--- 10,214 ----
  #include <string.h>
  #include <unistd.h>
  #include <utime.h>
  
  #ifndef O_BINARY
! # 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
+ 
+ /* Buffer size. */
+ #define SBUF_SIZE     16384    /* Suorce buffer. */
+ #define DBUF_SIZE     32768    /* Destination buffer. */
+ 
+ /* Control characters. */    
+ #define LF            0x0A
+ #define CR            0x0D
+ 
+ /* Exit codes. */
+ #define NO_ERROR      0x00
+ #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 verbosity, int preserve_timestamp)
  {
!   int i, k, sf, df, l, l2 = 0, exit_status = NO_ERROR, file_has_changed = 0, is_CR = 0;
!   char sbuf[SBUF_SIZE], dbuf[DBUF_SIZE];
!   char bfname[FILENAME_MAX], tfname[FILENAME_MAX], *bn;
    struct stat st;
    struct utimbuf tim1;
! 
!   sf = open (fname, O_RDONLY|O_BINARY);
    if (sf < 0)
    {
!     perror (fname);
!     return IO_ERROR;
    }
  
    fstat (sf,&st);
    tim1.actime = st.st_atime;
    tim1.modtime = st.st_mtime;
  
    strcpy (tfname, fname);
!   bn = BaseName (tfname);
!   *bn = 0;
!   strcat (tfname, "utod.tm$");
!   if (make_backup)
!   {
!     strcpy (bfname, fname);
!     if (pathconf ((bfname), _PC_NAME_MAX) <= 12)
!       for (i = strlen (bfname); i > -1; i--)
!         if (bfname[i

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019