aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/ChangeLog10
-rw-r--r--util/fileutil.c25
-rw-r--r--util/riscos.c40
3 files changed, 56 insertions, 19 deletions
diff --git a/util/ChangeLog b/util/ChangeLog
index 82d47901c..330610ad5 100644
--- a/util/ChangeLog
+++ b/util/ChangeLog
@@ -1,3 +1,13 @@
+2002-10-29 Stefan Bellon <[email protected]>
+
+ * fileutil.c: Removed unnecessary left-over includes for RISC OS.
+ (make_filename): Tidied up RISC OS stuff.
+ (compare_filenames) [__riscos__]: Compare with ascii_strcasecmp().
+ (make_basename) [__riscos__]: Branch to own RISC OS routine from
+ here.
+
+ * riscos.c (riscos_make_basename): New.
+
2002-10-28 Stefan Bellon <[email protected]>
* fileutil.c (make_basename) [__riscos__]: Cut off RISC OS' filing
diff --git a/util/fileutil.c b/util/fileutil.c
index 0d49ef513..8651315f9 100644
--- a/util/fileutil.c
+++ b/util/fileutil.c
@@ -25,10 +25,6 @@
#include <string.h>
#include <assert.h>
#include <unistd.h>
-#ifdef __riscos__
-#include <kernel.h>
-#include <swis.h>
-#endif /* __riscos__ */
#include "util.h"
#include "memory.h"
#include "ttyio.h"
@@ -39,16 +35,18 @@
*
*/
char *
-make_basename(const char *filepath)
+make_basename(const char *filepath, const char *inputpath)
{
+#ifdef __riscos__
+ return riscos_make_basename(filepath, inputpath);
+#endif
+
char *p;
if ( !(p=strrchr(filepath, DIRSEP_C)) )
#ifdef HAVE_DRIVE_LETTERS
if ( !(p=strrchr(filepath, '\\')) )
if ( !(p=strrchr(filepath, ':')) )
-#elif defined(__riscos__)
- if ( !(p=strrchr(filepath, ':')) )
#endif
{
return m_strdup(filepath);
@@ -101,11 +99,7 @@ make_filename( const char *first_part, ... )
va_list arg_ptr ;
size_t n;
const char *s;
-#ifndef __riscos__
char *name, *home, *p;
-#else
- char *name, *p;
-#endif
va_start( arg_ptr, first_part ) ;
n = strlen(first_part)+1;
@@ -113,18 +107,15 @@ make_filename( const char *first_part, ... )
n += strlen(s) + 1;
va_end(arg_ptr);
-#ifndef __riscos__
home = NULL;
+#ifndef __riscos__
if( *first_part == '~' && first_part[1] == DIRSEP_C
&& (home = getenv("HOME")) && *home )
n += strlen(home);
+#endif
name = m_alloc(n);
p = home ? stpcpy(stpcpy(name,home), first_part+1)
: stpcpy(name, first_part);
-#else /* __riscos__ */
- name = m_alloc(n);
- p = stpcpy(name, first_part);
-#endif /* __riscos__ */
va_start( arg_ptr, first_part ) ;
while( (s=va_arg(arg_ptr, const char *)) )
p = stpcpy(stpcpy(p, DIRSEP_S), s);
@@ -159,7 +150,7 @@ compare_filenames( const char *a, const char *b )
abuf = gstrans(a);
bbuf = gstrans(b);
- c = strcasecmp (abuf, bbuf);
+ c = ascii_strcasecmp (abuf, bbuf);
m_free(abuf);
m_free(bbuf);
diff --git a/util/riscos.c b/util/riscos.c
index a66a05ad3..6c3bd375d 100644
--- a/util/riscos.c
+++ b/util/riscos.c
@@ -84,8 +84,8 @@ riscos_get_filetype_from_string(const char *string, int len)
{
int result = 0xfff;
- if (string[len - 4] != ',')
- return 0xfff;
+ if (strlen(string) < 5 || string[len - 4] != ',')
+ return -1;
sscanf(string+len-3, "%3x", &result);
@@ -211,6 +211,8 @@ fdopenfile(const char *filename, const int allow_write)
h = fds_list;
fds_list = (struct fds_item *) m_alloc(sizeof(struct fds_item));
+ if (!fds_list)
+ log_fatal("Can't claim memory for fdopenfile() buffer!\n");
fds_list->fd = fd;
fds_list->next = h;
@@ -275,6 +277,40 @@ gstrans(const char *old)
return tmp;
}
+/***************
+ * Extract from a given path the filename component.
+ * (cloned from util/fileutil.c and then heavily modified)
+ */
+char *
+riscos_make_basename(const char *filepath, const char *realfname)
+{
+ char *p = (char*)filepath-1, *result;
+ int i, filetype;
+
+ if ( !(p=strrchr(filepath, DIRSEP_C)) )
+ if ( !(p=strrchr(filepath, ':')) )
+ ;
+
+ i = strlen(p+1);
+ result = m_alloc(i + 5);
+ if (!result)
+ log_fatal("Can't claim memory for riscos_make_basename() buffer!\n");
+ strcpy(result, p+1);
+
+ filetype = riscos_get_filetype( realfname );
+ result[i++] = ',';
+ result[i++] = "0123456789abcdef"[(filetype >> 8) & 0xf];
+ result[i++] = "0123456789abcdef"[(filetype >> 4) & 0xf];
+ result[i++] = "0123456789abcdef"[(filetype >> 0) & 0xf];
+ result[i] = 0;
+
+ for(i=0; i<strlen(result); ++i)
+ if(result[i] == '/')
+ result[i] = '.';
+
+ return result;
+}
+
#ifdef DEBUG
void
list_openfiles(void)