www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2001/03/19/03:26:18

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, 19 Mar 2001 09:25:20 +0200
MIME-Version: 1.0
Subject: 2 suggestions for djtar
X-mailer: Pegasus Mail for Windows (v2.54DE)
Message-ID: <5081AB53B41@HRZ1.hrz.tu-darmstadt.de>
Reply-To: djgpp-workers AT delorie DOT com

1) A couple of days ago, Bruno Haible suggested to modify
djtar in such a way that it always extracts batch files with
DOS-style EOL. I do not know if such a "silent" EOL convertion
is welcome at all and I know that this will not really solve
the problem, but IMHO it is a nice feature that can be easily
implemented and that may be of some use. The code I suggest in
this patch consideres every file having as last extension ".bat"
as batch file. Before checking for ".bat" the extension is
converted to lower case. The LF -> CRLF convertion is done
automatically. No new option has been added to enable/disable
this feature. Let me know if this feature is not welcome.

2) If djtar is invoked on SFN environments it will perform
certain extension transformations like:
  .tar.gz -> .tgz
etc.
I have added a code snippet to get_new_name() in djtar.c
so appropiate renaming is also done for bzip2 generated files.
The bzip2 allowed extensions will be transformed like this:
  .bzip2     -> .bz2
  .tar.bzip2 -> .tbz
  .tar.bz2   -> .tbz
  .tar.bz    -> .tbz
These convertions will only be performed on SFN environments and
only if the extension is really the last extension of the file.

Regards,
Guerrero, Juan Manuel


diff -acprNC5 djgpp.orig/src/utils/djtar/djtar.c djgpp/src/utils/djtar/djtar.c
*** djgpp.orig/src/utils/djtar/djtar.c	Sat Mar 17 16:33:06 2001
--- djgpp/src/utils/djtar/djtar.c	Sun Mar 18 17:19:34 2001
*************** get_new_name(char *name_to_change, int *
*** 304,316 ****
  
    changed_name = get_entry(name_to_change);
    if (*should_be_written && !to_stdout && NO_LFN(changed_name))
    {
      static char info_[] = ".info-";
      static char _tar_gz[] = ".tar.gz", _tgz[] = ".tgz";
      static char xx[] = "++";
!     char *info, *tgz, *plus;
  
      strcpy(new, changed_name);
      info = strstr(new, info_);
      if (info && isdigit(info[sizeof(info_)-1]))
      {
--- 304,320 ----
  
    changed_name = get_entry(name_to_change);
    if (*should_be_written && !to_stdout && NO_LFN(changed_name))
    {
      static char info_[] = ".info-";
+     static char _bzip2[] = ".bzip2", _bz2[] = ".bz2";
+     static char *_tar_bz_extension[] = { ".tar.bz", ".tar.bz2", ".tar.bzip2", NULL};
+     static char _tbz[] = ".tbz";
      static char _tar_gz[] = ".tar.gz", _tgz[] = ".tgz";
      static char xx[] = "++";
!     char *bz2, *info, *tbz, *tgz, *plus;
!     int i = 0;
  
      strcpy(new, changed_name);
      info = strstr(new, info_);
      if (info && isdigit(info[sizeof(info_)-1]))
      {
*************** get_new_name(char *name_to_change, int *
*** 321,330 ****
--- 325,350 ----
      if (tgz && tgz[sizeof(_tar_gz)-1] == '\0')
      {
        strcpy(tgz, _tgz);
        fprintf(log_out, "[ changing %s to %s ]\n", changed_name, new);
      }
+     while (_tar_bz_extension[i])
+     {
+       tbz = strstr(new, _tar_bz_extension[i]);
+       if (tbz && tbz[strlen(_tar_bz_extension[i])] == '\0')
+       {
+         strcpy(tbz, _tbz);
+         fprintf(log_out, "[ changing %s to %s ]\n", changed_name, new);
+       }
+       i++;
+     }
+     bz2 = strstr(new, _bzip2);
+     if (bz2 && bz2[sizeof(_bzip2)-1] == '\0')
+     {
+       strcpy(bz2, _bz2);
+       fprintf(log_out, "[ changing %s to %s ]\n", changed_name, new);
+     }
      plus = strstr(new, xx);
      if (plus)
      {
        register char *s = plus;
  
diff -acprNC5 djgpp.orig/src/utils/djtar/untar.c djgpp/src/utils/djtar/untar.c
*** djgpp.orig/src/utils/djtar/untar.c	Sat Mar 17 16:39:54 2001
--- djgpp/src/utils/djtar/untar.c	Sun Mar 18 18:04:42 2001
***************
*** 6,15 ****
--- 6,16 ----
  #include <dos.h>
  #include <errno.h>
  #include <fcntl.h>
  #include <io.h>
  #include <stdio.h>
+ #include <stdlib.h>
  #include <string.h>
  #include <sys/stat.h>
  #include <time.h>
  #include <unistd.h>
  
*************** static int skipping;
*** 60,70 ****
  extern char new[];
  
  int
  tarread(char *buf, long buf_size)
  {
!   int should_be_written;
  
    while (buf_size)
    {
      int write_errno = 0;
      int dsize = 512, wsize;
--- 61,71 ----
  extern char new[];
  
  int
  tarread(char *buf, long buf_size)
  {
!   int should_be_written, batch_file_processing = 0;
  
    while (buf_size)
    {
      int write_errno = 0;
      int dsize = 512, wsize;
*************** tarread(char *buf, long buf_size)
*** 89,98 ****
--- 90,100 ----
        }
      }
  
      if (looking_for_header)
      {
+       char *base_name;
        int head_csum = 0;
        int i;
        size_t nlen;
  
        memcpy(&header, buf, sizeof header);
*************** tarread(char *buf, long buf_size)
*** 106,115 ****
--- 108,140 ----
        bytes_out += sizeof header;
        first_block = 1;
        file_type = DOS_BINARY;
        looking_for_header = 0;
  
+       /* command.com refuses to run batch files
+          that have been stored with UNIX-style EOL,
+          so we will extract them with DOS-style EOL. */
+       base_name = strrchr(header.name, '/');
+       if (base_name)
+       {
+         char *extension = strrchr(base_name, '.');
+         if (extension)
+         {
+           char *string = xmalloc(strlen(extension) + 1);
+           strcpy(string, extension);
+ 
+           i = 0;
+           while (string[++i])
+             if (string[i] >= 'A' && string[i] <= 'T')
+               string[i] = string[i] - 'A' + 'a';
+           if (strstr(string, ".bat") && string[sizeof(".bat") - 1] == '\0')
+             batch_file_processing = 1;  /* LF -> CRLF */
+ 
+           free(string);
+         }
+       }
+ 
        sscanf(header.operm, " %lo", &perm);
        sscanf(header.ouid, " %lo", &uid);
        sscanf(header.ogid, " %lo", &gid);
        sscanf(header.osize, " %lo", &size);
        sscanf(header.otime, " %o", &ftime);
*************** open_file:
*** 234,249 ****
          dsize = size;
        else if (buf_size < 512)
          dsize = buf_size;
        else
          dsize = 512;
!       if (first_block && (text_dos || text_unix || to_tty))
        {
          file_type = guess_file_type(buf, dsize);
          first_block = 0;
!         if (file_type == UNIX_TEXT && text_dos)
            setmode(r, O_TEXT);   /* will add CR chars to each line */
        }
        if ((text_unix || to_tty) && file_type == DOS_TEXT)
        {
          /* If they asked for text files to be written Unix style, or
             we are writing to console, remove the CR and ^Z characters
--- 259,277 ----
          dsize = size;
        else if (buf_size < 512)
          dsize = buf_size;
        else
          dsize = 512;
!       if (first_block && (text_dos || text_unix || to_tty || batch_file_processing))
        {
          file_type = guess_file_type(buf, dsize);
          first_block = 0;
!         if ((file_type == UNIX_TEXT && text_dos) || batch_file_processing)
!         {
            setmode(r, O_TEXT);   /* will add CR chars to each line */
+           batch_file_processing = 0;
+         }
        }
        if ((text_unix || to_tty) && file_type == DOS_TEXT)
        {
          /* If they asked for text files to be written Unix style, or
             we are writing to console, remove the CR and ^Z characters

- Raw text -


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