From 32ffcf1473c7bbba040a4f067e272fd9e5e85274 Mon Sep 17 00:00:00 2001 From: Pavel Charvat Date: Sat, 4 Mar 2006 20:45:08 +0100 Subject: [PATCH] Fix: .h indentation and ifdef names; some comments; stk-conv enlarges string 3 times; warning in string_table generator. --- charset/charconv.h | 4 ++-- charset/misc/gen-charconv | 3 +++ charset/mp-charconv.c | 1 - charset/mp-charconv.h | 7 +++---- charset/stk-charconv.c | 4 ++-- charset/stk-charconv.h | 10 +++++++--- charset/unicat.h | 4 ++-- 7 files changed, 19 insertions(+), 14 deletions(-) diff --git a/charset/charconv.h b/charset/charconv.h index d14493c1..ed775b13 100644 --- a/charset/charconv.h +++ b/charset/charconv.h @@ -7,8 +7,8 @@ * of the GNU Lesser General Public License. */ -#ifndef _CHARCONV_H -#define _CHARCONV_H +#ifndef _CHARSET_CHARCONV_H +#define _CHARSET_CHARCONV_H struct conv_context { diff --git a/charset/misc/gen-charconv b/charset/misc/gen-charconv index ab22b156..a731d9ab 100755 --- a/charset/misc/gen-charconv +++ b/charset/misc/gen-charconv @@ -182,6 +182,9 @@ print "static unsigned char string_table[] = {\n"; $i = 256; while ($i < $pstr) { $w = $strval{$i}; + if (length($w) > 3) { + print STDERR "Warning: Entries should have at most 3 characters, see charset/stk-charconv.c\n"; + } print length $w, ","; foreach $x (unpack("C256", $w)) { print " $x,"; diff --git a/charset/mp-charconv.c b/charset/mp-charconv.c index 731d591e..0235ae76 100644 --- a/charset/mp-charconv.c +++ b/charset/mp-charconv.c @@ -8,7 +8,6 @@ #include "lib/mempool.h" #include "charset/mp-charconv.h" #include "charset/stk-charconv.h" -#include byte * mp_conv(struct mempool *mp, byte *s, uns in_cs, uns out_cs) diff --git a/charset/mp-charconv.h b/charset/mp-charconv.h index 6519535a..f3d7bd23 100644 --- a/charset/mp-charconv.h +++ b/charset/mp-charconv.h @@ -4,14 +4,13 @@ * (c) 2006 Pavel Charvat */ -#ifndef _MP_CHARCONV_H -#define _MP_CHARCONV_H +#ifndef _CHARSET_MP_CHARCONV_H +#define _CHARSET_MP_CHARCONV_H #include "lib/mempool.h" #include "charset/charconv.h" -byte * -mp_conv(struct mempool *mp, byte *s, uns cs_in, uns cs_out); +byte *mp_conv(struct mempool *mp, byte *s, uns cs_in, uns cs_out); static inline byte * mp_conv_to_utf8(struct mempool *mp, byte *s, uns cs_in) diff --git a/charset/stk-charconv.c b/charset/stk-charconv.c index 6550ea35..3fbc07bb 100644 --- a/charset/stk-charconv.c +++ b/charset/stk-charconv.c @@ -26,7 +26,7 @@ stk_conv_internal(struct conv_context *c, byte *s, uns in_cs, uns out_cs) c->source_end = s + l + 1; /* Resulting string can be longer after the conversion. - * The following constatnt must be at least 4 for conversion to UTF-8 + * The following constant must be at least 3 for conversion to UTF-8 * and at least the maximum length of the strings in string_table for other charsets. */ - return 4 * l + 1; + return 3 * l + 1; } diff --git a/charset/stk-charconv.h b/charset/stk-charconv.h index c0d8568f..d63ba746 100644 --- a/charset/stk-charconv.h +++ b/charset/stk-charconv.h @@ -4,12 +4,16 @@ * (c) 2006 Pavel Charvat */ -#ifndef _STK_CHARCONV_H -#define _STK_CHARCONV_H +#ifndef _CHARSET_STK_CHARCONV_H +#define _CHARSET_STK_CHARCONV_H #include "charset/charconv.h" #include +/* The following macros convert strings between given charsets (CONV_CHARSET_x). + * The resulting string is allocated on the stack with the exception of cs_in == cs_out, + * when the pointer to the input string is returned. */ + #define stk_conv(s, cs_in, cs_out) \ ({ struct conv_context _c; uns _l=stk_conv_internal(&_c, (s), (cs_in), (cs_out)); \ if (_l) { _c.dest=_c.dest_start=alloca(_l); _c.dest_end=_c.dest+_l; conv_run(&_c); } \ @@ -18,6 +22,6 @@ #define stk_conv_to_utf8(s, cs_in) stk_conv(s, cs_in, CONV_CHARSET_UTF8) #define stk_conv_from_utf8(s, cs_out) stk_conv(s, CONV_CHARSET_UTF8, cs_out) -uns stk_conv_internal(struct conv_context *, byte *, uns, uns); +uns stk_conv_internal(struct conv_context *c, byte *s, uns cs_in, uns cs_out); #endif diff --git a/charset/unicat.h b/charset/unicat.h index 1ddfb8e6..021ec5c2 100644 --- a/charset/unicat.h +++ b/charset/unicat.h @@ -7,8 +7,8 @@ * of the GNU Lesser General Public License. */ -#ifndef _UNICAT_H -#define _UNICAT_H +#ifndef _CHARSET_UNICAT_H +#define _CHARSET_UNICAT_H extern const byte *_U_cat[]; extern const word *_U_upper[], *_U_lower[], *_U_unaccent[]; -- 2.39.2