aboutsummaryrefslogtreecommitdiffstats
path: root/g10
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--g10/ChangeLog7
-rw-r--r--g10/g10.c3
-rw-r--r--g10/main.h1
-rw-r--r--g10/openfile.c32
-rw-r--r--g10/options.h1
-rw-r--r--g10/plaintext.c15
6 files changed, 55 insertions, 4 deletions
diff --git a/g10/ChangeLog b/g10/ChangeLog
index 5096b94fa..f3a51cd4c 100644
--- a/g10/ChangeLog
+++ b/g10/ChangeLog
@@ -1,3 +1,10 @@
+Tue Jun 1 16:01:46 CEST 1999 Werner Koch <[email protected]>
+
+ * openfile.c (make_outfile_name): New.
+ * plaintext.c (handle_plaintext): Outputfile is now the inputfile
+ without the suffix.
+ * g10.c: New option --use-embedded-filename
+
Mon May 31 19:41:10 CEST 1999 Werner Koch <[email protected]>
* g10.c (main): Fix for SHM init (Michael).
diff --git a/g10/g10.c b/g10/g10.c
index eb6d32ff3..acc3f3098 100644
--- a/g10/g10.c
+++ b/g10/g10.c
@@ -144,6 +144,7 @@ enum cmd_and_opt_values { aNull = 0,
oRunAsShmCP,
oSetFilename,
oSetPolicyURL,
+ oUseEmbeddedFilename,
oComment,
oThrowKeyid,
oForceV3Sigs,
@@ -301,6 +302,7 @@ static ARGPARSE_OPTS opts[] = {
{ oEscapeFrom, "escape-from-lines", 0, "@" },
{ oLockOnce, "lock-once", 0, "@" },
{ oLoggerFD, "logger-fd",1, "@" },
+ { oUseEmbeddedFilename, "use-embedded-filename", 0, "@" },
{0} };
@@ -718,6 +720,7 @@ main( int argc, char **argv )
break;
case oSetFilename: opt.set_filename = pargs.r.ret_str; break;
case oSetPolicyURL: opt.set_policy_url = pargs.r.ret_str; break;
+ case oUseEmbeddedFilename: opt.use_embedded_filename = 1; break;
case oComment: opt.comment_string = pargs.r.ret_str; break;
case oThrowKeyid: opt.throw_keyid = 1; break;
case oForceV3Sigs: opt.force_v3_sigs = 1; break;
diff --git a/g10/main.h b/g10/main.h
index fa03d17a6..5889ccf71 100644
--- a/g10/main.h
+++ b/g10/main.h
@@ -96,6 +96,7 @@ int generate_subkeypair( KBNODE pub_keyblock, KBNODE sec_keyblock );
/*-- openfile.c --*/
int overwrite_filep( const char *fname );
+char *make_outfile_name( const char *iname );
int open_outfile( const char *iname, int mode, IOBUF *a );
IOBUF open_sigfile( const char *iname );
void copy_options_file( const char *destdir );
diff --git a/g10/openfile.c b/g10/openfile.c
index e60520adb..af0ab3c1d 100644
--- a/g10/openfile.c
+++ b/g10/openfile.c
@@ -71,6 +71,36 @@ overwrite_filep( const char *fname )
/****************
+ * Strip know extensions from iname and return a newly allocated
+ * filename. Return NULL if we can't do that.
+ */
+char *
+make_outfile_name( const char *iname )
+{
+ size_t n;
+
+ if( (!iname || (*iname=='-' && !iname[1]) ))
+ return m_strdup("-");
+
+ #ifdef HAVE_DRIVE_LETTERS
+ #warning add case insensitive compare
+ #endif
+ n = strlen(iname);
+ if( n > 4 && ( !strcmp(iname+n-4,".gpg")
+ || !strcmp(iname+n-4,".sig")
+ || !strcmp(iname+n-4,".asc") ) ) {
+ char *buf = m_strdup( iname );
+ buf[n-4] = 0;
+ return buf;
+ }
+
+ log_error(_("%s: unknown suffix\n"), iname );
+ return NULL;
+}
+
+
+
+/****************
* Make an output filename for the inputfile INAME.
* Returns an IOBUF and an errorcode
* Mode 0 = use ".gpg"
@@ -108,6 +138,7 @@ open_outfile( const char *iname, int mode, IOBUF *a )
mode==2 ? ".sig" : ".gpg");
name = buf;
}
+
if( overwrite_filep( name ) ) {
if( !(*a = iobuf_create( name )) ) {
log_error(_("%s: can't create: %s\n"), name, strerror(errno) );
@@ -124,6 +155,7 @@ open_outfile( const char *iname, int mode, IOBUF *a )
}
+
/****************
* Try to open a file without the extension ".sig" or ".asc"
* Return NULL if such a file is not available.
diff --git a/g10/options.h b/g10/options.h
index d40f59fb0..57265f9e4 100644
--- a/g10/options.h
+++ b/g10/options.h
@@ -76,6 +76,7 @@ struct {
int interactive;
STRLIST notation_data;
const char *set_policy_url;
+ int use_embedded_filename;
} opt;
diff --git a/g10/plaintext.c b/g10/plaintext.c
index 000ede0c3..1edca16e5 100644
--- a/g10/plaintext.c
+++ b/g10/plaintext.c
@@ -63,6 +63,13 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
log_info(_("data not saved; use option \"--output\" to save it\n"));
nooutput = 1;
}
+ else if( !opt.use_embedded_filename ) {
+ fname = make_outfile_name( iobuf_get_real_fname(pt->buf) );
+ if( !fname ) {
+ rc = G10ERR_CREATE_FILE;
+ goto leave;
+ }
+ }
else {
fname = m_alloc( pt->namelen +1 );
memcpy( fname, pt->name, pt->namelen );
@@ -90,7 +97,7 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
if( pt->len ) {
assert( !clearsig );
- if( convert ) { // text mode
+ if( convert ) { /* text mode */
for( ; pt->len; pt->len-- ) {
if( (c = iobuf_get(pt->buf)) == -1 ) {
log_error("Problem reading source (%u bytes remaining)\n",
@@ -112,7 +119,7 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
}
}
}
- else { // binary mode
+ else { /* binary mode */
byte *buffer = m_alloc( 32768 );
while( pt->len ) {
int len = pt->len > 32768 ? 32768 : pt->len;
@@ -141,7 +148,7 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
}
}
else if( !clearsig ) {
- if( convert ) { // text mode
+ if( convert ) { /* text mode */
while( (c = iobuf_get(pt->buf)) != -1 ) {
if( mfx->md )
md_putc(mfx->md, c );
@@ -157,7 +164,7 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
}
}
}
- else { // binary mode
+ else { /* binary mode */
byte *buffer = m_alloc( 32768 );
for( ;; ) {
int len = iobuf_read( pt->buf, buffer, 32768 );