1
0
Fork 0
mirror of git://git.gnupg.org/gnupg.git synced 2025-07-03 22:56:33 +02:00

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