From 3208b3b2ff1f167cbb74ce36010e3f61d7df40ed Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Fri, 19 Jan 2007 03:23:47 +0000 Subject: [PATCH] *** empty log message *** --- ase/awk/Awk.java | 10 +++- ase/awk/jni.c | 10 ++-- ase/utl/printf.c | 116 +++++++++++++++++++++++++++-------------------- 3 files changed, 82 insertions(+), 54 deletions(-) diff --git a/ase/awk/Awk.java b/ase/awk/Awk.java index 6b16e04f..00df51dd 100644 --- a/ase/awk/Awk.java +++ b/ase/awk/Awk.java @@ -1,5 +1,5 @@ /* - * $Id: Awk.java,v 1.17 2007-01-18 14:34:17 bacon Exp $ + * $Id: Awk.java,v 1.18 2007-01-19 03:23:47 bacon Exp $ */ package ase.awk; @@ -20,12 +20,17 @@ public abstract class Awk System.getProperty("os.name")); os.arch / os.version; */ //System.load ("c://projects//ase/awk/aseawk.dll"); + URL url = ase.awk.Awk.class.getResource("aseawk.dll"); + if (url == null) url = ase.awk.Awk.class.getResource("libaseawk_jni.so"); + if (url != null) System.load (url.getFile()); + + /* AccessController.doPrivileged (new PrivilegedAction () { public Object run () { URL url = ase.awk.Awk.class.getResource("aseawk.dll"); - if (url == null) url = ase.awk.Awk.class.getResource("libaseawk.so"); + if (url == null) url = ase.awk.Awk.class.getResource("libaseawk_jni.so"); if (url != null) System.load (url.getFile()); //System.load ("c://projects//ase/awk/aseawk.dll"); @@ -33,6 +38,7 @@ public abstract class Awk return null; } }); + */ } private long handle; diff --git a/ase/awk/jni.c b/ase/awk/jni.c index 88767ae2..85f49dc6 100644 --- a/ase/awk/jni.c +++ b/ase/awk/jni.c @@ -1,5 +1,5 @@ /* - * $Id: jni.c,v 1.48 2007-01-07 07:30:40 bacon Exp $ + * $Id: jni.c,v 1.49 2007-01-19 03:23:47 bacon Exp $ */ #include @@ -13,6 +13,8 @@ #include #include +#include "../etc/printf.c" + #ifdef _WIN32 #include #include @@ -125,7 +127,7 @@ static int __awk_sprintf ( /* TODO: check buffer overflow */ n = vsprintf (buf, fmt, ap); #else - n = xp_vsprintf (buf, len, fmt, ap); + n = ase_vsprintf (buf, len, fmt, ap); #endif va_end (ap); return n; @@ -154,7 +156,7 @@ static void __awk_aprintf (const ase_char_t* fmt, ...) #elif defined(__MSDOS__) vprintf (fmt, ap); #else - xp_vprintf (fmt, ap); + ase_vprintf (fmt, ap); #endif va_end (ap); } @@ -169,7 +171,7 @@ static void __awk_dprintf (const ase_char_t* fmt, ...) #elif defined(__MSDOS__) vfprintf (stderr, fmt, ap); #else - xp_vfprintf (stderr, fmt, ap); + ase_vfprintf (stderr, fmt, ap); #endif va_end (ap); diff --git a/ase/utl/printf.c b/ase/utl/printf.c index 5fce3378..29a6b2dd 100644 --- a/ase/utl/printf.c +++ b/ase/utl/printf.c @@ -1,45 +1,46 @@ /* - * $Id: printf.c,v 1.1 2006-12-24 16:07:13 bacon Exp $ + * $Id: printf.c,v 1.2 2007-01-19 03:23:47 bacon Exp $ */ #include #include #include +#include static ase_char_t* __adjust_format (const ase_char_t* format); -int xp_vprintf (const ase_char_t* fmt, va_list ap); -int xp_vfprintf (FILE *stream, const ase_char_t* fmt, va_list ap); -int xp_vsprintf (ase_char_t* buf, size_t size, const ase_char_t* fmt, va_list ap); +int ase_vprintf (const ase_char_t* fmt, va_list ap); +int ase_vfprintf (FILE *stream, const ase_char_t* fmt, va_list ap); +int ase_vsprintf (ase_char_t* buf, size_t size, const ase_char_t* fmt, va_list ap); -int xp_printf (const ase_char_t* fmt, ...) +int ase_printf (const ase_char_t* fmt, ...) { int n; va_list ap; va_start (ap, fmt); - n = xp_vprintf (fmt, ap); + n = ase_vprintf (fmt, ap); va_end (ap); return n; } -int xp_fprintf (FILE* file, const ase_char_t* fmt, ...) +int ase_fprintf (FILE* file, const ase_char_t* fmt, ...) { int n; va_list ap; va_start (ap, fmt); - n = xp_vfprintf (file, fmt, ap); + n = ase_vfprintf (file, fmt, ap); va_end (ap); return n; } -int xp_vprintf (const ase_char_t* fmt, va_list ap) +int ase_vprintf (const ase_char_t* fmt, va_list ap) { - return xp_vfprintf (stdout, fmt, ap); + return ase_vfprintf (stdout, fmt, ap); } -int xp_vfprintf (FILE *stream, const ase_char_t* fmt, va_list ap) +int ase_vfprintf (FILE *stream, const ase_char_t* fmt, va_list ap) { int n; ase_char_t* nf = __adjust_format (fmt); @@ -54,18 +55,18 @@ int xp_vfprintf (FILE *stream, const ase_char_t* fmt, va_list ap) return n; } -int xp_sprintf (ase_char_t* buf, size_t size, const ase_char_t* fmt, ...) +int ase_sprintf (ase_char_t* buf, size_t size, const ase_char_t* fmt, ...) { int n; va_list ap; va_start (ap, fmt); - n = xp_vsprintf (buf, size, fmt, ap); + n = ase_vsprintf (buf, size, fmt, ap); va_end (ap); return n; } -int xp_vsprintf (ase_char_t* buf, size_t size, const ase_char_t* fmt, va_list ap) +int ase_vsprintf (ase_char_t* buf, size_t size, const ase_char_t* fmt, va_list ap) { int n; ase_char_t* nf = __adjust_format (fmt); @@ -92,35 +93,53 @@ int xp_vsprintf (ase_char_t* buf, size_t size, const ase_char_t* fmt, va_list ap #define MOD_LONG 2 #define MOD_LONGLONG 3 -#define ADDC(str,c) \ +#define ADDC(buf,c) \ do { \ - if (xp_str_ccat(&str, c) == (size_t)-1) { \ - xp_str_close (&str); \ - return NULL; \ + if (buf.len >= buf.cap) \ + { \ + ase_char_t* tmp; \ + tmp = (ase_char_t*)realloc ( \ + buf.ptr, sizeof(ase_char_t)*(buf.cap+256+1)); \ + if (tmp == NULL) \ + { \ + free (buf.ptr); \ + return NULL; \ + } \ + buf.ptr = tmp; \ + buf.cap = buf.cap + 256; \ } \ + buf.ptr[buf.len++] = c; \ } while (0) static ase_char_t* __adjust_format (const ase_char_t* format) { const ase_char_t* fp = format; int modifier; - xp_str_t str; ase_char_t ch; - if (xp_str_open (&str, 256) == NULL) return NULL; + struct + { + ase_char_t* ptr; + ase_size_t len; + ase_size_t cap; + } buf; + + buf.len = 0; + buf.cap = 256; + buf.ptr = (ase_char_t*) malloc (sizeof(ase_char_t)*(buf.cap+1)); + if (buf.ptr == NULL) return NULL; while (*fp != ASE_T('\0')) { while (*fp != ASE_T('\0') && *fp != ASE_T('%')) { - ADDC (str, *fp++); + ADDC (buf, *fp++); } if (*fp == ASE_T('\0')) break; - xp_assert (*fp == ASE_T('%')); ch = *fp++; - ADDC (str, ch); /* add % */ + ADDC (buf, ch); /* add % */ ch = *fp++; @@ -130,14 +149,14 @@ static ase_char_t* __adjust_format (const ase_char_t* format) if (ch == ASE_T(' ') || ch == ASE_T('+') || ch == ASE_T('-') || ch == ASE_T('#')) { - ADDC (str, ch); + ADDC (buf, ch); ch = *fp++; } else { if (ch == ASE_T('0')) { - ADDC (str, ch); + ADDC (buf, ch); ch = *fp++; } @@ -148,14 +167,14 @@ static ase_char_t* __adjust_format (const ase_char_t* format) /* check the width */ if (ch == ASE_T('*')) { - ADDC (str, ch); + ADDC (buf, ch); ch = *fp++; } else { - while (xp_isdigit(ch)) + while (ase_isdigit(ch)) { - ADDC (str, ch); + ADDC (buf, ch); ch = *fp++; } } @@ -163,19 +182,19 @@ static ase_char_t* __adjust_format (const ase_char_t* format) /* precision */ if (ch == ASE_T('.')) { - ADDC (str, ch); + ADDC (buf, ch); ch = *fp++; if (ch == ASE_T('*')) { - ADDC (str, ch); + ADDC (buf, ch); ch = *fp++; } else { - while (xp_isdigit(ch)) + while (ase_isdigit(ch)) { - ADDC (str, ch); + ADDC (buf, ch); ch = *fp++; } } @@ -195,23 +214,23 @@ static ase_char_t* __adjust_format (const ase_char_t* format) /* type */ - if (ch == ASE_T('%')) ADDC (str, ch); + if (ch == ASE_T('%')) ADDC (buf, ch); else if (ch == ASE_T('c') || ch == ASE_T('s')) { #if !defined(ASE_CHAR_IS_MCHAR) && !defined(_WIN32) - ADDC (str, 'l'); + ADDC (buf, 'l'); #endif - ADDC (str, ch); + ADDC (buf, ch); } else if (ch == ASE_T('C') || ch == ASE_T('S')) { #ifdef _WIN32 - ADDC (str, ch); + ADDC (buf, ch); #else #ifdef ASE_CHAR_IS_MCHAR - ADDC (str, 'l'); + ADDC (buf, 'l'); #endif - ADDC (str, xp_tolower(ch)); + ADDC (buf, ase_tolower(ch)); #endif } else if (ch == ASE_T('d') || ch == ASE_T('i') || @@ -220,29 +239,30 @@ static ase_char_t* __adjust_format (const ase_char_t* format) { if (modifier == MOD_SHORT) { - ADDC (str, 'h'); + ADDC (buf, 'h'); } else if (modifier == MOD_LONG) { - ADDC (str, 'l'); + ADDC (buf, 'l'); } else if (modifier == MOD_LONGLONG) { #if defined(_WIN32) && !defined(__LCC__) - ADDC (str, 'I'); - ADDC (str, '6'); - ADDC (str, '4'); + ADDC (buf, 'I'); + ADDC (buf, '6'); + ADDC (buf, '4'); #else - ADDC (str, 'l'); - ADDC (str, 'l'); + ADDC (buf, 'l'); + ADDC (buf, 'l'); #endif } - ADDC (str, ch); + ADDC (buf, ch); } else if (ch == ASE_T('\0')) break; - else ADDC (str, ch); + else ADDC (buf, ch); } - return xp_str_cield (&str); + buf.ptr[buf.len] = ASE_T('\0'); + return buf.ptr; }