* \e$B8=:_!"\e(Bnkf \e$B$O\e(B SorceForge \e$B$K$F%a%s%F%J%s%9$,B3$1$i$l$F$$$^$9!#\e(B
* http://sourceforge.jp/projects/nkf/
***********************************************************************/
-#define NKF_IDENT "$Id: nkf.c,v 1.192 2008/11/09 23:09:22 naruse Exp $"
#define NKF_VERSION "2.0.8"
-#define NKF_RELEASE_DATE "2008-12-25"
+#define NKF_RELEASE_DATE "2009-01-04"
#define COPY_RIGHT \
"Copyright (C) 1987, FUJITSU LTD. (I.Ichikawa),2000 S. Kono, COW\n" \
- "Copyright (C) 2002-2008 Kono, Furukawa, Naruse, mastodon"
+ "Copyright (C) 2002-2009 Kono, Furukawa, Naruse, mastodon"
#include "config.h"
#include "nkf.h"
#endif
#include <assert.h>
-#define nkf_debug(fmt, ...) \
- fprintf(stderr, "%s(%s)%d: " fmt "\n", __FILE__, __func__, __LINE__, __VA_ARGS__)
-
/* state of output_mode and input_mode
nkf_char std_gc_ndx;
static void *
-nkf_malloc(size_t size)
+nkf_xmalloc(size_t size)
{
void *ptr;
}
static void *
-nkf_realloc(void *ptr, size_t size)
+nkf_xrealloc(void *ptr, size_t size)
{
if (size == 0) size = 1;
return ptr;
}
-#define nkf_free(ptr) free(ptr)
+#define nkf_xfree(ptr) free(ptr)
static int
nkf_str_caseeql(const char *src, const char *target)
{
fprintf(HELP_OUTPUT,
"Summary of my nkf " NKF_VERSION " (" NKF_RELEASE_DATE ") configuration:\n"
- " nkf identity:\n"
- " " NKF_IDENT "\n"
" Compile-time options:\n"
" Compiled at: " __DATE__ " " __TIME__ "\n"
);
}
if(asterisk_count){
- backup_filename = nkf_malloc(strlen(suffix) + (asterisk_count * (filename_length - 1)) + 1);
+ backup_filename = nkf_xmalloc(strlen(suffix) + (asterisk_count * (filename_length - 1)) + 1);
for(i = 0, j = 0; suffix[i];){
if(suffix[i] == '*'){
backup_filename[j] = '\0';
backup_filename[j] = '\0';
}else{
j = filename_length + strlen(suffix);
- backup_filename = nkf_malloc(j + 1);
+ backup_filename = nkf_xmalloc(j + 1);
strcpy(backup_filename, filename);
strcat(backup_filename, suffix);
backup_filename[j] = '\0';
static nkf_ary *
nkf_ary_new(int length)
{
- nkf_ary *ary = nkf_malloc(sizeof(nkf_ary));
- ary->ary = nkf_malloc(length);
+ nkf_ary *ary = nkf_xmalloc(sizeof(nkf_ary));
+ ary->ary = nkf_xmalloc(length);
ary->max_length = length;
ary->count = 0;
return ary;
static void
nkf_ary_dispose(nkf_ary *ary)
{
- nkf_free(ary->ary);
- nkf_free(ary);
+ nkf_xfree(ary->ary);
+ nkf_xfree(ary);
}
#define nkf_ary_length(ary) ((ary)->count)
/* end Q encoding */
input_mode = exit_mode;
lwsp_count = 0;
- lwsp_buf = nkf_malloc((lwsp_size+5)*sizeof(char));
+ lwsp_buf = nkf_xmalloc((lwsp_size+5)*sizeof(char));
while ((c1=(*i_getc)(f))!=EOF) {
switch (c1) {
case LF:
lwsp_buf[lwsp_count] = (unsigned char)c1;
if (lwsp_count++>lwsp_size){
lwsp_size <<= 1;
- lwsp_buf_new = nkf_realloc(lwsp_buf, (lwsp_size+5)*sizeof(char));
+ lwsp_buf_new = nkf_xrealloc(lwsp_buf, (lwsp_size+5)*sizeof(char));
lwsp_buf = lwsp_buf_new;
}
continue;
i_ungetc(lwsp_buf[lwsp_count],f);
c1 = lwsp_buf[0];
}
- nkf_free(lwsp_buf);
+ nkf_xfree(lwsp_buf);
return c1;
}
if (c1=='='&&c2<SP) { /* this is soft wrap */
if ((c1 == '?') && (c2 == '=')) {
input_mode = ASCII;
lwsp_count = 0;
- lwsp_buf = nkf_malloc((lwsp_size+5)*sizeof(char));
+ lwsp_buf = nkf_xmalloc((lwsp_size+5)*sizeof(char));
while ((c1=(*i_getc)(f))!=EOF) {
switch (c1) {
case LF:
lwsp_buf[lwsp_count] = (unsigned char)c1;
if (lwsp_count++>lwsp_size){
lwsp_size <<= 1;
- lwsp_buf_new = nkf_realloc(lwsp_buf, (lwsp_size+5)*sizeof(char));
+ lwsp_buf_new = nkf_xrealloc(lwsp_buf, (lwsp_size+5)*sizeof(char));
lwsp_buf = lwsp_buf_new;
}
continue;
i_ungetc(lwsp_buf[lwsp_count],f);
c1 = lwsp_buf[0];
}
- nkf_free(lwsp_buf);
+ nkf_xfree(lwsp_buf);
return c1;
}
mime_c3_retry:
nkf_iconv_t converter;
converter->input_buffer_size = IOBUF_SIZE;
- converter->input_buffer = nkf_malloc(converter->input_buffer_size);
+ converter->input_buffer = nkf_xmalloc(converter->input_buffer_size);
converter->output_buffer_size = IOBUF_SIZE * 2;
- converter->output_buffer = nkf_malloc(converter->output_buffer_size);
+ converter->output_buffer = nkf_xmalloc(converter->output_buffer_size);
converter->cd = iconv_open(tocode, fromcode);
if (converter->cd == (iconv_t)-1)
{
static void
nkf_iconv_close(nkf_iconv_t *convert)
{
- nkf_free(converter->inbuf);
- nkf_free(converter->outbuf);
+ nkf_xfree(converter->inbuf);
+ nkf_xfree(converter->outbuf);
iconv_close(converter->cd);
}
#endif
if (file_out_f == TRUE) {
#ifdef OVERWRITE
if (overwrite_f){
- outfname = nkf_malloc(strlen(origfname)
+ outfname = nkf_xmalloc(strlen(origfname)
+ strlen(".nkftmpXXXXXX")
+ 1);
strcpy(outfname, origfname);
fprintf(stderr, "Can't rename %s to %s\n",
origfname, backup_filename);
}
- nkf_free(backup_filename);
+ nkf_xfree(backup_filename);
}else{
#ifdef MSDOS
if (unlink(origfname)){
fprintf(stderr, "Can't rename %s to %s\n",
outfname, origfname);
}
- nkf_free(outfname);
+ nkf_xfree(outfname);
}
#endif
}