summaryrefslogtreecommitdiff
path: root/lib/opencdk/literal.c
diff options
context:
space:
mode:
authorSimon Josefsson <simon@josefsson.org>2008-07-02 15:24:05 +0200
committerSimon Josefsson <simon@josefsson.org>2008-07-02 15:24:05 +0200
commitbade988016aa5d2936c6bdf53570125181cfe2f9 (patch)
tree65948be9cd75ccfb8fd2a6c26ad15caed4119cc5 /lib/opencdk/literal.c
parent36f07088e2979bf28e52fec4992d3da04e73eb6c (diff)
downloadgnutls-bade988016aa5d2936c6bdf53570125181cfe2f9.tar.gz
Indent code.
Diffstat (limited to 'lib/opencdk/literal.c')
-rw-r--r--lib/opencdk/literal.c115
1 files changed, 60 insertions, 55 deletions
diff --git a/lib/opencdk/literal.c b/lib/opencdk/literal.c
index 7a0a43453b..5e16bd1ef4 100644
--- a/lib/opencdk/literal.c
+++ b/lib/opencdk/literal.c
@@ -34,11 +34,11 @@
/* Duplicate the string @s but strip of possible
relative folder names of it. */
-static char*
+static char *
dup_trim_filename (const char *s)
{
char *p = NULL;
-
+
p = strrchr (s, '/');
if (!p)
p = strrchr (s, '\\');
@@ -47,9 +47,9 @@ dup_trim_filename (const char *s)
return cdk_strdup (p + 1);
}
-
+
static cdk_error_t
-literal_decode (void *opaque, FILE *in, FILE *out)
+literal_decode (void *opaque, FILE * in, FILE * out)
{
literal_filter_t *pfx = opaque;
cdk_stream_t si, so;
@@ -61,31 +61,31 @@ literal_decode (void *opaque, FILE *in, FILE *out)
cdk_error_t rc;
_cdk_log_debug ("literal filter: decode\n");
-
+
if (!pfx || !in || !out)
return CDK_Inv_Value;
-
+
rc = _cdk_stream_fpopen (in, STREAMCTL_READ, &si);
if (rc)
return rc;
-
+
cdk_pkt_new (&pkt);
rc = cdk_pkt_read (si, pkt);
if (rc || pkt->pkttype != CDK_PKT_LITERAL)
{
cdk_pkt_release (pkt);
cdk_stream_close (si);
- return !rc? CDK_Inv_Packet: rc;
+ return !rc ? CDK_Inv_Packet : rc;
}
-
+
rc = _cdk_stream_fpopen (out, STREAMCTL_WRITE, &so);
if (rc)
{
cdk_pkt_release (pkt);
cdk_stream_close (si);
return rc;
- }
-
+ }
+
pt = pkt->pkt.literal;
pfx->mode = pt->mode;
@@ -109,24 +109,25 @@ literal_decode (void *opaque, FILE *in, FILE *out)
cdk_pkt_release (pkt);
cdk_stream_close (si);
cdk_stream_close (so);
- _cdk_log_debug ("literal filter: no file name and no PGP extension\n");
+ _cdk_log_debug
+ ("literal filter: no file name and no PGP extension\n");
return CDK_Inv_Mode;
}
_cdk_log_debug ("literal filter: derrive file name from original\n");
pfx->filename = dup_trim_filename (pfx->orig_filename);
- pfx->filename[strlen (pfx->filename)-4] = '\0';
+ pfx->filename[strlen (pfx->filename) - 4] = '\0';
}
-
+
while (!feof (in))
- {
+ {
_cdk_log_debug ("literal_decode: part on %d size %lu\n",
pfx->blkmode.on, pfx->blkmode.size);
if (pfx->blkmode.on)
bufsize = pfx->blkmode.size;
else
- bufsize = pt->len < DIM (buf)? pt->len : DIM (buf);
+ bufsize = pt->len < DIM (buf) ? pt->len : DIM (buf);
nread = cdk_stream_read (pt->buf, buf, bufsize);
- if (nread == EOF)
+ if (nread == EOF)
{
rc = CDK_File_Error;
break;
@@ -136,15 +137,15 @@ literal_decode (void *opaque, FILE *in, FILE *out)
cdk_stream_write (so, buf, nread);
pt->len -= nread;
if (pfx->blkmode.on)
- {
+ {
pfx->blkmode.size = _cdk_pkt_read_len (in, &pfx->blkmode.on);
- if ((ssize_t)pfx->blkmode.size == EOF)
+ if ((ssize_t) pfx->blkmode.size == EOF)
return CDK_Inv_Packet;
- }
+ }
if (pt->len <= 0 && !pfx->blkmode.on)
break;
}
-
+
cdk_stream_close (si);
cdk_stream_close (so);
cdk_pkt_release (pkt);
@@ -157,18 +158,22 @@ intmode_to_char (int mode)
{
switch (mode)
{
- case CDK_LITFMT_BINARY: return 'b';
- case CDK_LITFMT_TEXT: return 't';
- case CDK_LITFMT_UNICODE:return 'u';
- default: return 'b';
+ case CDK_LITFMT_BINARY:
+ return 'b';
+ case CDK_LITFMT_TEXT:
+ return 't';
+ case CDK_LITFMT_UNICODE:
+ return 'u';
+ default:
+ return 'b';
}
-
+
return 'b';
}
-
-
+
+
static cdk_error_t
-literal_encode (void *opaque, FILE *in, FILE *out)
+literal_encode (void *opaque, FILE * in, FILE * out)
{
literal_filter_t *pfx = opaque;
cdk_pkt_literal_t pt;
@@ -176,17 +181,17 @@ literal_encode (void *opaque, FILE *in, FILE *out)
cdk_packet_t pkt;
size_t filelen;
cdk_error_t rc;
-
+
_cdk_log_debug ("literal filter: encode\n");
-
+
if (!pfx || !in || !out)
- return CDK_Inv_Value;
- if (!pfx->filename)
+ return CDK_Inv_Value;
+ if (!pfx->filename)
{
pfx->filename = cdk_strdup ("_CONSOLE");
if (!pfx->filename)
return CDK_Out_Of_Core;
- }
+ }
rc = _cdk_stream_fpopen (in, STREAMCTL_READ, &si);
if (rc)
@@ -200,11 +205,11 @@ literal_encode (void *opaque, FILE *in, FILE *out)
cdk_pkt_release (pkt);
cdk_stream_close (si);
return CDK_Out_Of_Core;
- }
+ }
memcpy (pt->name, pfx->filename, filelen);
pt->namelen = filelen;
pt->name[pt->namelen] = '\0';
- pt->timestamp = (u32)time (NULL);
+ pt->timestamp = (u32) time (NULL);
pt->mode = intmode_to_char (pfx->mode);
pt->len = cdk_stream_get_length (si);
pt->buf = si;
@@ -212,7 +217,7 @@ literal_encode (void *opaque, FILE *in, FILE *out)
pkt->pkttype = CDK_PKT_LITERAL;
pkt->pkt.literal = pt;
rc = _cdk_pkt_write_fp (out, pkt);
-
+
cdk_pkt_release (pkt);
cdk_stream_close (si);
return rc;
@@ -220,10 +225,10 @@ literal_encode (void *opaque, FILE *in, FILE *out)
int
-_cdk_filter_literal (void * opaque, int ctl, FILE * in, FILE * out)
+_cdk_filter_literal (void *opaque, int ctl, FILE * in, FILE * out)
{
if (ctl == STREAMCTL_READ)
- return literal_decode( opaque, in, out );
+ return literal_decode (opaque, in, out);
else if (ctl == STREAMCTL_WRITE)
return literal_encode (opaque, in, out);
else if (ctl == STREAMCTL_FREE)
@@ -244,54 +249,54 @@ _cdk_filter_literal (void * opaque, int ctl, FILE * in, FILE * out)
static int
-text_encode (void *opaque, FILE *in, FILE *out)
+text_encode (void *opaque, FILE * in, FILE * out)
{
const char *s;
char buf[2048];
-
+
if (!in || !out)
return CDK_Inv_Value;
-
+
/* FIXME: This code does not work for very long lines. */
- while (!feof (in))
+ while (!feof (in))
{
- s = fgets (buf, DIM (buf)-1, in);
+ s = fgets (buf, DIM (buf) - 1, in);
if (!s)
break;
_cdk_trim_string (buf, 1);
fwrite (buf, 1, strlen (buf), out);
}
-
+
return 0;
}
-
+
static int
-text_decode (void * opaque, FILE * in, FILE * out)
+text_decode (void *opaque, FILE * in, FILE * out)
{
text_filter_t *tfx = opaque;
const char *s;
char buf[2048];
-
+
if (!tfx || !in || !out)
return CDK_Inv_Value;
-
- while (!feof (in))
+
+ while (!feof (in))
{
- s = fgets (buf, DIM (buf)-1, in);
+ s = fgets (buf, DIM (buf) - 1, in);
if (!s)
break;
_cdk_trim_string (buf, 0);
fwrite (buf, 1, strlen (buf), out);
fwrite (tfx->lf, 1, strlen (tfx->lf), out);
}
-
+
return 0;
}
int
-_cdk_filter_text (void *opaque, int ctl, FILE *in, FILE *out)
+_cdk_filter_text (void *opaque, int ctl, FILE * in, FILE * out)
{
if (ctl == STREAMCTL_READ)
return text_encode (opaque, in, out);
@@ -299,8 +304,8 @@ _cdk_filter_text (void *opaque, int ctl, FILE *in, FILE *out)
return text_decode (opaque, in, out);
else if (ctl == STREAMCTL_FREE)
{
- text_filter_t * tfx = opaque;
- if (tfx)
+ text_filter_t *tfx = opaque;
+ if (tfx)
{
_cdk_log_debug ("free text filter\n");
tfx->lf = NULL;