OSDN Git Service

2004-09-28 Andrew Haley <aph@redhat.com>
[pf3gnuchains/gcc-fork.git] / gcc / java / jcf-io.c
index d2e7793..0b21092 100644 (file)
@@ -120,7 +120,6 @@ opendir_in_zip (const char *zipfile, int is_system)
   zipf->next = SeenZipFiles;
   zipf->name = (char*)(zipf+1);
   strcpy (zipf->name, zipfile);
-  SeenZipFiles = zipf;
   fd = open (zipfile, O_RDONLY | O_BINARY);
   zipf->fd = fd;
   if (fd < 0)
@@ -140,6 +139,8 @@ opendir_in_zip (const char *zipfile, int is_system)
       if (read_zip_archive (zipf) != 0)
        return NULL;
     }
+
+  SeenZipFiles = zipf;  
   return zipf;
 }
 
@@ -186,48 +187,48 @@ open_in_zip (JCF *jcf, const char *zipfile, const char *zipmember,
 int
 read_zip_member (JCF *jcf,  ZipDirectory *zipd, ZipFile *zipf)
 {
-         jcf->filbuf = jcf_unexpected_eof;
-         jcf->zipd = (void *)zipd;
+  jcf->filbuf = jcf_unexpected_eof;
+  jcf->zipd = (void *)zipd;
 
-         if (zipd->compression_method == Z_NO_COMPRESSION)
-           {
-             jcf->buffer = ALLOC (zipd->size);
-             jcf->buffer_end = jcf->buffer + zipd->size;
-             jcf->read_ptr = jcf->buffer;
-             jcf->read_end = jcf->buffer_end;
-             if (lseek (zipf->fd, zipd->filestart, 0) < 0
-                 || read (zipf->fd, jcf->buffer, zipd->size) != (long) zipd->size)
-               return -2;
-           }
-         else
-           {
-             char *buffer;
-             z_stream d_stream; /* decompression stream */
-             d_stream.zalloc = (alloc_func) 0;
-             d_stream.zfree = (free_func) 0;
-             d_stream.opaque = (voidpf) 0;
-
-             jcf->buffer = ALLOC (zipd->uncompressed_size);
-             d_stream.next_out = jcf->buffer;
-             d_stream.avail_out = zipd->uncompressed_size;
-             jcf->buffer_end = jcf->buffer + zipd->uncompressed_size;
-             jcf->read_ptr = jcf->buffer;
-             jcf->read_end = jcf->buffer_end;
-             buffer = ALLOC (zipd->size);
-             d_stream.next_in = buffer;
-             d_stream.avail_in = zipd->size;
-             if (lseek (zipf->fd, zipd->filestart, 0) < 0
-                 || read (zipf->fd, buffer, zipd->size) != (long) zipd->size)
-               return -2;
-             /* Handle NO_HEADER using undocumented zlib feature.
-                 This is a very common hack.  */
-             inflateInit2 (&d_stream, -MAX_WBITS);
-             inflate (&d_stream, Z_NO_FLUSH);
-             inflateEnd (&d_stream);
-             FREE (buffer);
-           }
+  if (zipd->compression_method == Z_NO_COMPRESSION)
+    {
+      jcf->buffer = ALLOC (zipd->size);
+      jcf->buffer_end = jcf->buffer + zipd->size;
+      jcf->read_ptr = jcf->buffer;
+      jcf->read_end = jcf->buffer_end;
+      if (lseek (zipf->fd, zipd->filestart, 0) < 0
+         || read (zipf->fd, jcf->buffer, zipd->size) != (long) zipd->size)
+       return -2;
+    }
+  else
+    {
+      char *buffer;
+      z_stream d_stream; /* decompression stream */
+      d_stream.zalloc = (alloc_func) 0;
+      d_stream.zfree = (free_func) 0;
+      d_stream.opaque = (voidpf) 0;
+
+      jcf->buffer = ALLOC (zipd->uncompressed_size);
+      d_stream.next_out = jcf->buffer;
+      d_stream.avail_out = zipd->uncompressed_size;
+      jcf->buffer_end = jcf->buffer + zipd->uncompressed_size;
+      jcf->read_ptr = jcf->buffer;
+      jcf->read_end = jcf->buffer_end;
+      buffer = ALLOC (zipd->size);
+      d_stream.next_in = (unsigned char *) buffer;
+      d_stream.avail_in = zipd->size;
+      if (lseek (zipf->fd, zipd->filestart, 0) < 0
+         || read (zipf->fd, buffer, zipd->size) != (long) zipd->size)
+       return -2;
+      /* Handle NO_HEADER using undocumented zlib feature.
+        This is a very common hack.  */
+      inflateInit2 (&d_stream, -MAX_WBITS);
+      inflate (&d_stream, Z_NO_FLUSH);
+      inflateEnd (&d_stream);
+      FREE (buffer);
+    }
 
-         return 0;
+  return 0;
 }
 
 const char *
@@ -292,7 +293,7 @@ compare_path (const void *key, const void *entry)
 static int
 java_or_class_file (const struct dirent *entry)
 {
-  const char *base = basename (entry->d_name);
+  const char *base = lbasename (entry->d_name);
   return (fnmatch ("*.java", base, 0) == 0 || 
          fnmatch ("*.class", base, 0) == 0);
 }
@@ -310,7 +311,7 @@ typedef struct memoized_dirlist_entry
   struct dirent **files;
 } memoized_dirlist_entry;
 
-/* Returns true if ENTRY (a memoized_dirlist_entry *) correponds to
+/* Returns true if ENTRY (a memoized_dirlist_entry *) corresponds to
    the directory given by KEY (a char *) giving the directory 
    name.  */
 
@@ -336,6 +337,7 @@ caching_stat (char *filename, struct stat *buf)
 {
 #if JCF_USE_SCANDIR
   char *sep;
+  char origsep = 0;
   char *base;
   memoized_dirlist_entry *dent;
   void **slot;
@@ -349,15 +351,20 @@ caching_stat (char *filename, struct stat *buf)
 
   /* Get the name of the directory.  */
   sep = strrchr (filename, DIR_SEPARATOR);
+#ifdef DIR_SEPARATOR_2
+  if (! sep)
+    sep = strrchr (filename, DIR_SEPARATOR_2);
+#endif
   if (sep)
     {
+      origsep = *sep;
       *sep = '\0';
       base = sep + 1;
     }
   else
     base = filename;
 
-  /* Obtain the entry for this directory form the hash table.  */
+  /* Obtain the entry for this directory from the hash table.  */
   slot = htab_find_slot (memoized_dirlists, filename, INSERT);
   if (!*slot)
     {
@@ -368,20 +375,19 @@ caching_stat (char *filename, struct stat *buf)
       /* Unfortunately, scandir is not fully standardized.  In
         particular, the type of the function pointer passed as the
         third argument sometimes takes a "const struct dirent *"
-        parameter, and sometimes just a "struct dirent *".  We rely
-        on the ability to interchange these two types of function
-        pointers.  */
+        parameter, and sometimes just a "struct dirent *".  We cast
+        to (void *) so that either way it is quietly accepted.  */
       dent->num_files = scandir (filename, &dent->files, 
-                                java_or_class_file, 
+                                (void *) java_or_class_file, 
                                 alphasort);
       *slot = dent;
     }
   else
     dent = *((memoized_dirlist_entry **) slot);
 
-  /* Put the spearator back.  */
+  /* Put the separator back.  */
   if (sep)
-    *sep = DIR_SEPARATOR;
+    *sep = origsep;
 
   /* If the file is not in the list, there is no need to stat it; it
      does not exist.  */
@@ -509,7 +515,8 @@ find_class (const char *classname, int classname_length, JCF *jcf,
          strcpy (java_buffer, path_name);
          l = strlen (java_buffer);
          for (m = 0; m < classname_length; ++m)
-           java_buffer[m + l] = (classname[m] == '.' ? '/' : classname[m]);
+           java_buffer[m + l] = (classname[m] == '.'
+                                 ? DIR_SEPARATOR : classname[m]);
          strcpy (java_buffer + m + l, ".java");
          java = caching_stat (java_buffer, &java_buf);
          if (java == 0)
@@ -539,7 +546,7 @@ find_class (const char *classname, int classname_length, JCF *jcf,
                              classname+classname_length-
                              (classname_length <= 30 ? 
                               classname_length : 30)));
-      fd = open (buffer, O_RDONLY | O_BINARY);
+      fd = JCF_OPEN_EXACT_CASE (buffer, O_RDONLY | O_BINARY);
       if (fd >= 0)
        goto found;
     }
@@ -551,7 +558,7 @@ find_class (const char *classname, int classname_length, JCF *jcf,
                              classname+classname_length-
                              (classname_length <= 30 ? 
                               classname_length : 30)));
-      fd = open (buffer, O_RDONLY);
+      fd = JCF_OPEN_EXACT_CASE (buffer, O_RDONLY);
       if (fd >= 0)
        {
          jcf->java_source = 1;
@@ -613,7 +620,7 @@ jcf_print_char (FILE *stream, int ch)
 /* Print UTF8 string at STR of length LENGTH bytes to STREAM. */
 
 void
-jcf_print_utf8 (FILE *stream, register const unsigned char *str, int length)
+jcf_print_utf8 (FILE *stream, const unsigned char *str, int length)
 {
   const unsigned char * limit = str + length;
   while (str < limit)
@@ -707,7 +714,7 @@ format_uint (char *buffer, uint64 value, int base)
 {
 #define WRITE_BUF_SIZE (4 + sizeof(uint64) * 8)
   char buf[WRITE_BUF_SIZE];
-  register char *buf_ptr = buf+WRITE_BUF_SIZE; /* End of buf. */
+  char *buf_ptr = buf+WRITE_BUF_SIZE; /* End of buf. */
   int chars_written;
   int i;