Add missing file and other changes.

This commit is contained in:
Werner Koch 2006-09-27 13:58:13 +00:00
parent f28d2d5c43
commit 3377456252
5 changed files with 143 additions and 19 deletions

View File

@ -1,3 +1,15 @@
2006-09-27 Werner Koch <wk@g10code.com>
* util.h: Do not include strsep.h and strpbrk.h.
(isascii): Removed as it is now in jnlib.
* iobuf.c (pop_filter, underflow, iobuf_close): Free the unget
buffer.
2006-09-27 Florian Weimer <fweimer@bfk.de> (wk)
* iobuf.c (iobuf_unread): New.
2006-09-22 Werner Koch <wk@g10code.com>
* i18n.h: Changed license to an all permissive one.

88
common/gpgrlhelp.c Normal file
View File

@ -0,0 +1,88 @@
/* gpgrlhelp.c - A readline wrapper.
* Copyright (C) 2006 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
* GnuPG is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* GnuPG is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*/
/* This module may by used by applications to initializes readline
support. It is required so that we can have hooks in other parts
of libcommon without actually requing to link against
libreadline. It works along ttyio.c which a proper part of
libcommon. */
#include <config.h>
#include <stdlib.h>
#include <stddef.h>
#ifdef HAVE_LIBREADLINE
#define GNUPG_LIBREADLINE_H_INCLUDED
#include <readline/readline.h>
#include <readline/history.h>
#endif
#include "util.h"
#include "common-defs.h"
static void
set_completer (rl_completion_func_t *completer)
{
rl_attempted_completion_function = completer;
rl_inhibit_completion = 0;
}
static void
inhibit_completion (int value)
{
rl_inhibit_completion = value;
}
static void
cleanup_after_signal (void)
{
rl_free_line_state ();
rl_cleanup_after_signal ();
}
static void
init_stream (FILE *fp)
{
rl_catch_signals = 0;
rl_instream = rl_outstream = fp;
rl_inhibit_completion = 1;
}
/* Initialize our readline code. This should be called as early as
possible as it is actually a constructur. */
void
gnupg_rl_initialize (void)
{
tty_private_set_rl_hooks (init_stream,
set_completer,
inhibit_completion,
cleanup_after_signal,
readline,
add_history);
rl_readline_name = "GnuPG";
}

View File

@ -1037,6 +1037,7 @@ iobuf_close (iobuf_t a)
{
memset (a->d.buf, 0, a->d.size); /* erase the buffer */
xfree (a->d.buf);
xfree (a->unget.buf);
}
xfree (a);
}
@ -1538,6 +1539,7 @@ pop_filter (iobuf_t a, int (*f) (void *opaque, int control,
b = a->chain;
assert (b);
xfree (a->d.buf);
xfree (a->unget.buf);
xfree (a->real_fname);
memcpy (a, b, sizeof *a);
xfree (b);
@ -1579,6 +1581,7 @@ pop_filter (iobuf_t a, int (*f) (void *opaque, int control,
*/
b = a->chain;
xfree (a->d.buf);
xfree (a->unget.buf);
xfree (a->real_fname);
memcpy (a, b, sizeof *a);
xfree (b);
@ -1621,6 +1624,7 @@ underflow (iobuf_t a)
log_debug ("iobuf-%d.%d: pop `%s' in underflow\n",
a->no, a->subno, a->desc);
xfree (a->d.buf);
xfree (a->unget.buf);
xfree (a->real_fname);
memcpy (a, b, sizeof *a);
xfree (b);
@ -1695,6 +1699,7 @@ underflow (iobuf_t a)
log_debug ("iobuf-%d.%d: pop `%s' in underflow (!len)\n",
a->no, a->subno, a->desc);
xfree (a->d.buf);
xfree (a->unget.buf);
xfree (a->real_fname);
memcpy (a, b, sizeof *a);
xfree (b);
@ -1859,6 +1864,31 @@ iobuf_read (iobuf_t a, void *buffer, unsigned int buflen)
}
/* This is a verly limited unget fucntion for an iobuf. It does only
work in certain cases and should be used with care. */
void
iobuf_unread (iobuf_t a, const unsigned char *buf, unsigned int buflen)
{
unsigned int new_len;
if (!buflen)
return;
/* We always relocate the buffer, which is not optimal. However,
the code is easier to read this way, and it is not on the fast
path. */
if ( !a->unget.buf )
a->unget.size = a->unget.start = a->unget.len = 0;
new_len = a->unget.len + buflen;
a->unget.buf = xrealloc(a->unget.buf, new_len);
memcpy(a->unget.buf + a->unget.len, buf, buflen);
a->unget.len = new_len;
a->nofast |= 2;
}
/****************
* Have a look at the iobuf.
* NOTE: This only works in special cases.

View File

@ -44,18 +44,21 @@ struct iobuf_struct
{
int use; /* 1 input , 2 output, 3 temp */
off_t nlimit;
off_t nbytes; /* used together with nlimit */
off_t ntotal; /* total bytes read (position of stream) */
int nofast; /* used by the iobuf_get() */
off_t nbytes; /* Used together with nlimit. */
off_t ntotal; /* Total bytes read (position of stream). */
int nofast; /* Used by the iobuf_get (). */
/* bit 0 (LSB): slow path because of limit. */
/* bit 1: slow path because of unread. */
void *directfp;
struct
{
size_t size; /* allocated size */
size_t start; /* number of invalid bytes at the begin of the buffer */
size_t len; /* currently filled to this size */
size_t size; /* Allocated size */
size_t start; /* Number of invalid bytes at the
begin of the buffer */
size_t len; /* Currently filled to this size */
byte *buf;
}
d;
} d;
int filter_eof;
int error;
int (*filter) (void *opaque, int control,
@ -77,8 +80,7 @@ struct iobuf_struct
begin of the buffer */
size_t len; /* currently filled to this size */
byte *buf;
}
unget;
} unget;
};
#ifndef EXTERN_UNLESS_MAIN_MODULE
@ -124,6 +126,7 @@ int iobuf_seek (iobuf_t a, off_t newpos);
int iobuf_readbyte (iobuf_t a);
int iobuf_read (iobuf_t a, void *buf, unsigned buflen);
void iobuf_unread (iobuf_t a, const unsigned char *buf, unsigned int buflen);
unsigned iobuf_read_line (iobuf_t a, byte ** addr_of_buffer,
unsigned *length_of_buffer, unsigned *max_length);
int iobuf_peek (iobuf_t a, byte * buf, unsigned buflen);

View File

@ -28,8 +28,6 @@
#include <gpg-error.h> /* We need gpg_error_t. */
/* Common GNUlib includes (-I ../gl/). */
#include "strpbrk.h"
#include "strsep.h"
#include "vasprintf.h"
@ -196,13 +194,6 @@ ttyname (int fd)
};
#endif /* !HAVE_TTYNAME */
#ifndef HAVE_ISASCII
static inline int
isascii (int c)
{
return (((c) & ~0x7f) == 0);
}
#endif /* !HAVE_ISASCII */
/*-- Macros to replace ctype ones to avoid locale problems. --*/
#define spacep(p) (*(p) == ' ' || *(p) == '\t')