[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[tim-3] Improved DJGPP support in src/files.c
From: |
Tim Van Holder |
Subject: |
[tim-3] Improved DJGPP support in src/files.c |
Date: |
Sun, 6 Jan 2002 18:47:36 +0100 |
This is a bit bigger than the previous two, so I'll probably need
papers. Could you send me the request form, Akim?
What this does:
- improved skeleton_find() so it properly handles paths that
have both / and \ as dirsep. It now also favors / over \ when
building paths for DJGPP.
- makes skeleton_find() const-correct (was modifying a const char*
before), and adds a comment about the memory leak introduced in
the MSDOS-specific code.
It might be even better to disable this entire block for DJGPP,
but I'll leave it in for now, as some people might currently
depend on this behaviour.
- Use xstrndup() in compute_base_names() instead of strndup(), as
strndup() is not ANSI and is not provided.
- Don't lowercase file name parts on DJGPP if LFN is available.
2002-01-06 Tim Van Holder <address@hidden>
* src/files.c: Improved support for DJGPP.
Index: src/files.c
===================================================================
RCS file: /cvsroot/bison/bison/src/files.c,v
retrieving revision 1.64
diff -u -r1.64 files.c
--- src/files.c 30 Dec 2001 14:50:15 -0000 1.64
+++ src/files.c 6 Jan 2002 16:08:32 -0000
@@ -26,6 +26,10 @@
#include "error.h"
#include "complain.h"
+#if defined(__DJGPP__)
+# include <fcntl.h>
+#endif
+
FILE *finput = NULL;
struct obstack action_obstack;
@@ -182,15 +186,20 @@
const char *
skeleton_find (const char *envvar, const char *skeleton_name)
{
- const char *res = getenv (envvar);
+ char *res = getenv (envvar);
#if defined (MSDOS) || defined (_WIN32)
+ /* More dynamic search for DOSish systems.
+ FIXME: This introduces a memory leak, as the result is allocated
+ sing XMALLOC, but can never be freed (as it's supposed to be a
+ const char*). */
if (!res)
{
/* Skeleton file name without path */
- const char *skel_name = strrchr (skeleton_name, '/');
- if (!skel_name)
- skel_name = strrchr (skeleton_name, '\\');
+ const char *skel_name = strrchr (skeleton_name, '/');
+ const char *skel_name_2 = strrchr (skeleton_name, '\\');
+ if (skel_name_2 > skel_name)
+ skel_name = skel_name_2;
if (!skel_name)
skel_name = skeleton_name;
else
@@ -201,15 +210,24 @@
if (cp)
{
res = XMALLOC (char, strlen (cp) + strlen (skel_name) + 2);
+#if defined(__DJGPP__)
+ sprintf (res, "%s%c%s", cp, '/', skel_name);
+#else
sprintf (res, "%s%c%s", cp, '\\', skel_name);
+#endif
}
else if (access (skel_name, 4) == 0) /* Look in current dir. */
- res = skel_name;
+ return skel_name;
else
{
/* Look in program locations dir. */
extern char *program_name;
- cp = strrchr(program_name, '\\');
+ cp = strrchr (program_name, '\\');
+ {
+ const char *cp2 = strrchr (skeleton_name, '/');
+ if (cp2 > cp)
+ cp = cp2;
+ }
if (!cp)
return skeleton_name;
else
@@ -221,7 +239,7 @@
}
#endif /* defined (MSDOS) || defined (_WIN32) */
if (!res)
- res = skeleton_name;
+ return skeleton_name;
return res;
}
@@ -293,8 +311,6 @@
header_extension = tr (header_extension, 'C', 'H');
}
-/* FIXME: Should use xstrndup. */
-
static void
compute_base_names (void)
{
@@ -312,8 +328,11 @@
files, remove the ".c" or ".tab.c" suffix. */
if (spec_outfile)
{
-#ifdef MSDOS
- strlwr (spec_outfile);
+#if defined (MSDOS)
+# if defined(__DJGPP__)
+ if (!_USE_LFN)
+# endif
+ strlwr (spec_outfile);
#endif /* MSDOS */
/* BASE_LENGTH includes ".tab" but not ".c". */
base_length = strlen (spec_outfile);
@@ -330,12 +349,12 @@
compute_exts_from_src (spec_outfile + ext_index);
}
- base_name = strndup (spec_outfile, base_length);
+ base_name = xstrndup (spec_outfile, base_length);
/* SHORT_BASE_LENGTH includes neither ".tab" nor ".c". */
short_base_length = base_length;
if (strsuffix (base_name, ".tab") || strsuffix (base_name,
"_tab"))
short_base_length -= 4;
- short_base_name = strndup (spec_outfile, short_base_length);
+ short_base_name = xstrndup (spec_outfile, short_base_length);
/* FIXME: This is a quick and dirty way for me to find out if we
should .tab or not, using the computations above. */
@@ -351,8 +370,11 @@
Construct names from it. */
if (spec_file_prefix)
{
-#ifdef MSDOS
- strlwr (spec_file_prefix);
+#if defined (MSDOS)
+# if defined(__DJGPP__)
+ if (!_USE_LFN)
+# endif
+ strlwr (spec_outfile);
#endif /* MSDOS */
short_base_name = xstrdup (spec_file_prefix);
base_name = XMALLOC (char,
@@ -399,7 +421,7 @@
}
short_base_length = base_length;
- short_base_name = strndup (name_base, short_base_length);
+ short_base_name = xstrndup (name_base, short_base_length);
base_name = XMALLOC (char,
strlen (short_base_name) + strlen (EXT_TAB) +
1);
@@ -441,7 +463,8 @@
spec_verbose_file = stringappend (short_base_name, EXT_OUTPUT);
attrsfile = stringappend (short_base_name, EXT_STYPE_H);
-#ifndef MSDOS
+#if !defined(MSDOS)
+ /* FIXME: Should this be run on DJGPP? (perhaps with a USE_LFN
check?) */
attrsfile = stringappend (attrsfile, header_extension);
#endif /* MSDOS */
}
- [tim-3] Improved DJGPP support in src/files.c,
Tim Van Holder <=
- Re: [tim-3] Improved DJGPP support in src/files.c, Akim Demaille, 2002/01/07
- Re: [tim-3] Improved DJGPP support in src/files.c, Akim Demaille, 2002/01/11
- Re: [tim-3] Improved DJGPP support in src/files.c, Tim Van Holder, 2002/01/11
- Re: [tim-3] Improved DJGPP support in src/files.c, Akim Demaille, 2002/01/11
- Re: [tim-3] Improved DJGPP support in src/files.c, Tim Van Holder, 2002/01/11
- Re: [tim-3] Improved DJGPP support in src/files.c, Tim Van Holder, 2002/01/13
- Re: [tim-3] Improved DJGPP support in src/files.c, Akim Demaille, 2002/01/15
- Re: [tim-3] Improved DJGPP support in src/files.c, Paul Eggert, 2002/01/15
- Re: [tim-3] Improved DJGPP support in src/files.c, Tim Van Holder, 2002/01/15
- Re: [tim-3] Improved DJGPP support in src/files.c, Paul Eggert, 2002/01/15