texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

texinfo/makeinfo node.c,1.2,1.3 makeinfo.c,1.22,1.23


From: dirt
Subject: texinfo/makeinfo node.c,1.2,1.3 makeinfo.c,1.22,1.23
Date: Fri, 2 Jan 2004 16:20:46 +0100

Update of /cvsroot/texinfo/texinfo/makeinfo
In directory sheep:/tmp/cvs-serv4753/makeinfo

Modified Files:
        node.c makeinfo.c 
Log Message:
2004-01-02  Alper Ersoy  <address@hidden>

        * makeinfo/node.c (clean_old_split_files): new function.
        (split_file): moved filename generation code to a ...
        (enumerate_filename): new function.

        * makeinfo/makeinfo.c (convert_from_loaded_file): call
        clean_old_split_files before calling split_file.



Index: node.c
===================================================================
RCS file: /cvsroot/texinfo/texinfo/makeinfo/node.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** node.c      2003/12/28 11:48:52     1.2
--- node.c      2004/01/02 15:20:44     1.3
***************
*** 1616,1619 ****
--- 1616,1694 ----
  
  
+ char *
+ enumerate_filename (pathname, basename, number)
+      char *pathname;
+      char *basename;
+      int number;
+ {
+   /* Do we need to generate names of subfiles which don't exceed 8+3 limits? 
*/
+   static const int dos_file_names = !HAVE_LONG_FILENAMES (pathname ? pathname 
: ".");
+   unsigned name_len = strlen (basename);
+   char *filename = xmalloc (10 + strlen (pathname) + name_len);
+   char *base_filename = xmalloc (10 + name_len);
+ 
+   sprintf (base_filename, "%s-%d", basename, number);
+ 
+   if (dos_file_names)
+     {
+       char *dot = strchr (base_filename, '.');
+       unsigned base_len = strlen (base_filename);
+ 
+       if (dot)
+         { /* Make foobar.i1, .., foobar.i99, foobar.100, ... */
+           dot[1] = 'i';
+           memmove (number <= 99 ? dot + 2 : dot + 1,
+               base_filename + name_len + 1,
+               strlen (base_filename + name_len + 1) + 1);
+         }
+       else if (base_len > 8)
+         {
+           /* Make foobar-1, .., fooba-10, .., foob-100, ... */
+           unsigned numlen = base_len - name_len;
+ 
+           memmove (base_filename + 8 - numlen, base_filename + name_len, 
numlen + 1);
+         }
+     }
+ 
+   sprintf (filename, "%s%s", pathname, base_filename);
+ 
+   return filename;
+ }
+ 
+ /* Remove previously split files, to avoid
+    lingering parts of shrinked documents.  */
+ void
+ clean_old_split_files (filename)
+      char *filename;
+ {
+   char *root_filename = filename_part (filename);
+   char *root_pathname = pathname_part (filename);
+   int i;
+ 
+   /* We break as soon as we hit an inexistent file,
+      so looping until large numbers is harmless.  */
+   for (i = 1; i < 1000; i++)
+     {
+       struct stat st;
+       char *check_file = enumerate_filename (root_pathname, root_filename, i);
+ 
+       if (stat (check_file, &st) != 0)
+         break;
+       else if (!S_ISDIR (st.st_mode))
+         {
+           /* Give feedback if requested, removing a file is important.  */
+           if (verbose_mode)
+             printf (_("Removing %s\n"), check_file);
+ 
+           /* Warn user that we cannot remove the file.  */
+           if (unlink (check_file) != 0)
+             warning (_("Can't remove file `%s': %s"), check_file, strerror 
(errno));
+         }
+ 
+       free (check_file);
+     }
+ }
+ 
+ 
  /* Split large output files into a series of smaller files.  Each file
     is pointed to in the tag table, which then gets written out as the
***************
*** 1632,1636 ****
    char *the_header;
    int header_size;
-   int dos_file_names = 0;       /* if nonzero, don't exceed 8+3 limits */
  
    /* Can only do this to files with tag tables. */
--- 1707,1710 ----
***************
*** 1653,1659 ****
    root_pathname = pathname_part (filename);
  
-   /* Do we need to generate names of subfiles which don't exceed 8+3 limits? 
*/
-   dos_file_names = !HAVE_LONG_FILENAMES (root_pathname ? root_pathname : ".");
- 
    if (!root_pathname)
      root_pathname = xstrdup ("");
--- 1727,1730 ----
***************
*** 1758,1791 ****
                  {
                    int fd;
!                   char *split_filename, *split_basename;
!                   unsigned root_len = strlen (root_filename);
! 
!                   split_filename = xmalloc (10 + strlen (root_pathname)
!                                             + root_len);
!                   split_basename = xmalloc (10 + root_len);
!                   sprintf (split_basename, "%s-%d", root_filename, 
which_file);
!                   if (dos_file_names)
!                     {
!                       char *dot = strchr (split_basename, '.');
!                       unsigned base_len = strlen (split_basename);
! 
!                       if (dot)
!                         { /* Make foobar.i1, .., foobar.i99, foobar.100, ... 
*/
!                           dot[1] = 'i';
!                           memmove (which_file <= 99 ? dot + 2 : dot + 1,
!                                    split_basename + root_len + 1,
!                                    strlen (split_basename + root_len + 1) + 
1);
!                         }
!                       else if (base_len > 8)
!                         {
!                           /* Make foobar-1, .., fooba-10, .., foob-100, ... */
!                           unsigned numlen = base_len - root_len;
! 
!                           memmove (split_basename + 8 - numlen,
!                                    split_basename + root_len, numlen + 1);
!                         }
!                     }
!                   sprintf (split_filename, "%s%s", root_pathname,
!                            split_basename);
  
                    fd = open (split_filename, O_WRONLY|O_TRUNC|O_CREAT, 0666);
--- 1829,1835 ----
                  {
                    int fd;
!                   char *split_filename = enumerate_filename (root_pathname,
!                       root_filename, which_file);
!                   char *split_basename = filename_part (split_filename);
  
                    fd = open (split_filename, O_WRONLY|O_TRUNC|O_CREAT, 0666);

Index: makeinfo.c
===================================================================
RCS file: /cvsroot/texinfo/texinfo/makeinfo/makeinfo.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** makeinfo.c  2004/01/02 12:40:38     1.22
--- makeinfo.c  2004/01/02 15:20:44     1.23
***************
*** 1780,1784 ****
  
        if (splitting && !html && (!errors_printed || force))
!         split_file (real_output_filename, split_size);
        else if (errors_printed
                 && !force
--- 1780,1787 ----
  
        if (splitting && !html && (!errors_printed || force))
!         {
!           clean_old_split_files (real_output_filename);
!           split_file (real_output_filename, split_size);
!         }
        else if (errors_printed
                 && !force



reply via email to

[Prev in Thread] Current Thread [Next in Thread]