tidied RISC OS filetype support

This commit is contained in:
Stefan Bellon 2002-10-29 14:37:12 +00:00
parent 557f65836d
commit e4021a4c95
10 changed files with 110 additions and 73 deletions

View File

@ -1,3 +1,17 @@
2002-10-29 Stefan Bellon <sbellon@sbellon.de>
* build-packet.c (calc_plaintext, do_plaintext): Removed RISC OS
specific filetype parts (it's now done in make_basename()).
* plaintext.c (handle_plaintext): Tidied up RISC OS specific
filetype parts.
* encode.c (encode_simple, encode_crypt): Added argument to
make_basename() call.
* sign.c (write_plaintext_packet): Added argument to
make_basename() call.
2002-10-28 Stefan Bellon <sbellon@sbellon.de>
* build-packet.c (calc_plaintext, do_plaintext): Added filetype

View File

@ -528,14 +528,7 @@ do_pubkey_enc( IOBUF out, int ctb, PKT_pubkey_enc *enc )
static u32
calc_plaintext( PKT_plaintext *pt )
{
#ifndef __riscos__
return pt->len? (1 + 1 + pt->namelen + 4 + pt->len) : 0;
#else
/* Under RISC OS, we add ",xxx" to the file name in order to
be able to recreate the correct file type on the recipients'
side. Therefore we need 4 bytes more. */
return pt->len? (1 + 1 + pt->namelen + 4 + pt->len + 4) : 0;
#endif
}
static int
@ -548,26 +541,9 @@ do_plaintext( IOBUF out, int ctb, PKT_plaintext *pt )
write_header(out, ctb, calc_plaintext( pt ) );
iobuf_put(out, pt->mode );
#ifndef __riscos__
iobuf_put(out, pt->namelen );
for(i=0; i < pt->namelen; i++ )
iobuf_put(out, pt->name[i] );
#else
/* Under RISC OS, we add ",xxx" to the file name in order to
be able to recreate the correct file type on the recipients'
side. Therefore we need 4 bytes more. */
iobuf_put(out, pt->namelen + 4);
for(i=0; i < pt->namelen; i++ )
if( pt->name[i] != '/' )
iobuf_put(out, pt->name[i] );
else
iobuf_put(out, '.' );
i = riscos_get_filetype( iobuf_get_real_fname( pt->buf ) );
iobuf_put(out, ',');
iobuf_put(out, "0123456789abcdef"[(i >> 8) & 0xf]);
iobuf_put(out, "0123456789abcdef"[(i >> 4) & 0xf]);
iobuf_put(out, "0123456789abcdef"[(i >> 0) & 0xf]);
#endif
if( write_32(out, pt->timestamp ) )
rc = G10ERR_WRITE_FILE;

View File

@ -267,7 +267,8 @@ encode_simple( const char *filename, int mode, int compat )
/* setup the inner packet */
if( filename || opt.set_filename ) {
char *s = make_basename( opt.set_filename ? opt.set_filename
: filename );
: filename,
iobuf_get_real_fname( inp ) );
pt = m_alloc( sizeof *pt + strlen(s) - 1 );
pt->namelen = strlen(s);
memcpy(pt->name, s, pt->namelen );
@ -503,7 +504,9 @@ encode_crypt( const char *filename, STRLIST remusr )
if (!opt.no_literal) {
/* setup the inner packet */
if( filename || opt.set_filename ) {
char *s = make_basename( opt.set_filename ? opt.set_filename : filename );
char *s = make_basename( opt.set_filename ? opt.set_filename
: filename,
iobuf_get_real_fname( inp ) );
pt = m_alloc( sizeof *pt + strlen(s) - 1 );
pt->namelen = strlen(s);
memcpy(pt->name, s, pt->namelen );

View File

@ -78,29 +78,9 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
rc = G10ERR_CREATE_FILE;
goto leave;
}
#ifdef __riscos__
/* If there's a ,xxx extension in the embedded filename,
get filetype from it and use it later on */
filetype = riscos_get_filetype_from_string( pt->name, pt->namelen );
c = riscos_get_filetype_from_string( fname, strlen(fname) );
if( c != 0xfff && filetype == 0xfff)
filetype = c;
#endif
}
else {
fname = make_printable_string( pt->name, pt->namelen, 0 );
#ifdef __riscos__
/* If there's a ,xxx extension in the embedded filename,
get filetype from it and use it later on, remove ,xxx from
actual filename */
if( fname[strlen(fname) - 4] == ',' ) {
filetype = riscos_get_filetype_from_string( pt->name, pt->namelen );
fname[strlen(fname) - 4] = 0;
}
for( c=0; fname[c]; ++c)
if( fname[c] == '.' )
fname[c] = '/';
#endif
}
if( nooutput )
@ -125,20 +105,39 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
}
}
#ifndef __riscos__
if( fp || nooutput )
;
else if( !(fp = fopen(fname,"wb")) ) {
log_error(_("error creating `%s': %s\n"), fname, strerror(errno) );
rc = G10ERR_CREATE_FILE;
#ifdef __riscos__
if (errno == 106)
log_info("perhaps the output file has the same name as the input file?\n");
#endif /* __riscos__ */
goto leave;
}
#ifdef __riscos__
#else /* __riscos__ */
/* Convert all '.' in fname to '/' -- we don't create directories! */
for( c=0; fname[c]; ++c )
if( fname[c] == '.' )
fname[c] = '/';
if( fp || nooutput )
;
else if( !(fp = fopen(fname,"wb")) ) {
log_error(_("error creating `%s': %s\n"), fname, strerror(errno) );
rc = G10ERR_CREATE_FILE;
if (errno == 106)
log_info("Do output file and input file have the same name?\n");
goto leave;
}
/* If there's a ,xxx extension in the embedded filename,
use that, else check whether the user input (in fname)
has a ,xxx appended, then use that in preference */
if( (c = riscos_get_filetype_from_string( pt->name, pt->namelen )) != -1 )
filetype = c;
if( (c = riscos_get_filetype_from_string( fname, strlen(fname) )) != -1 )
filetype = c;
riscos_set_filetype_by_number(fname, filetype);
#endif
#endif /* __riscos__ */
if( !pt->is_partial ) {
/* we have an actual length (which might be zero). */

View File

@ -443,7 +443,8 @@ write_plaintext_packet (IOBUF out, IOBUF inp, const char *fname, int ptmode)
if (!opt.no_literal) {
if (fname || opt.set_filename) {
char *s = make_basename (opt.set_filename? opt.set_filename
: fname);
: fname,
iobuf_get_real_fname(inp));
pt = m_alloc (sizeof *pt + strlen(s) - 1);
pt->namelen = strlen (s);
memcpy (pt->name, s, pt->namelen);

View File

@ -1,3 +1,9 @@
2002-10-29 Stefan Bellon <sbellon@sbellon.de>
* util.h: Added parameter argument to make_basename() needed for
filetype support.
[__riscos__]: Added prototype.
2002-10-28 Stefan Bellon <sbellon@sbellon.de>
* util.h [__riscos__]: Added prototypes for new filetype support.

View File

@ -152,7 +152,7 @@ int release_dotlock( DOTLOCK h );
void remove_lockfiles (void);
/*-- fileutil.c --*/
char * make_basename(const char *filepath);
char * make_basename(const char *filepath, const char *inputpath);
char * make_dirname(const char *filepath);
char *make_filename( const char *first_part, ... );
int compare_filenames( const char *a, const char *b );
@ -283,6 +283,7 @@ int fdopenfile(const char *filename, const int allow_write);
void close_fds(void);
int renamefile(const char *old, const char *new);
char *gstrans(const char *old);
char *riscos_make_basename(const char *filepath, const char *inputpath);
void not_implemented(const char *feature);
#ifdef DEBUG
void dump_fdlist(void);

View File

@ -1,3 +1,13 @@
2002-10-29 Stefan Bellon <sbellon@sbellon.de>
* 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 <sbellon@sbellon.de>
* fileutil.c (make_basename) [__riscos__]: Cut off RISC OS' filing

View File

@ -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);

View File

@ -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)