*** empty log message ***

This commit is contained in:
hyung-hwan 2006-12-24 16:07:13 +00:00
parent 3628069938
commit c929b2ca09
3 changed files with 302 additions and 26 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.c,v 1.147 2006-12-24 15:14:09 bacon Exp $
* $Id: awk.c,v 1.148 2006-12-24 16:07:13 bacon Exp $
*/
#include <ase/awk/awk.h>
@ -26,14 +26,11 @@
#include <wctype.h>
#include <locale.h>
#include "printf.c"
/*
#include <xp/bas/stdio.h>
#include <xp/bas/stdlib.h>
#include <xp/bas/string.h>
#include <xp/bas/memory.h>
#include <xp/bas/sysapi.h>
*/
#endif
#if defined(_WIN32) && defined(_MSC_VER) && defined(_DEBUG)
@ -197,14 +194,17 @@ static FILE* awk_popen (const ase_char_t* cmd, const ase_char_t* mode)
#if defined(_WIN32)
#define awk_fgets _fgetts
#define awk_fgetc _fgettc
#define awk_fputs _fputts
#define awk_fputc _fputtc
#elif defined(ASE_CHAR_IS_MCHAR)
#define awk_fgets fgets
#define awk_fgetc fgetc
#define awk_fputs fputs
#define awk_fputc fputc
#else
#define awk_fgets fgetws
#define awk_fgetc fgetwc
#define awk_fputs fputws
#define awk_fputc fputwc
#endif
@ -231,11 +231,7 @@ static ase_ssize_t process_source (
else if (cmd == ASE_AWK_IO_READ)
{
if (size <= 0) return -1;
#ifdef ASE_CHAR_IS_MCHAR
c = fgetc ((FILE*)src_io->input_handle);
#else
c = fgetwc ((FILE*)src_io->input_handle);
#endif
c = awk_fgetc ((FILE*)src_io->input_handle);
if (c == ASE_CHAR_EOF) return 0;
*data = c;
return 1;
@ -250,17 +246,17 @@ static ase_ssize_t dump_source (
/*struct src_io* src_io = (struct src_io*)arg;*/
if (cmd == ASE_AWK_IO_OPEN) return 1;
else if (cmd == ASE_AWK_IO_CLOSE) return 0;
else if (cmd == ASE_AWK_IO_CLOSE)
{
fflush (stdout);
return 0;
}
else if (cmd == ASE_AWK_IO_WRITE)
{
ase_size_t i;
for (i = 0; i < size; i++)
{
#ifdef ASE_CHAR_IS_MCHAR
fputc (data[i], stdout);
#else
fputwc (data[i], stdout);
#endif
if (awk_fputc (data[i], stdout) == ASE_CHAR_EOF) return -1;
}
return size;
}
@ -309,14 +305,23 @@ static ase_ssize_t process_extio_pipe (
case ASE_AWK_IO_WRITE:
{
int n;
/*
ase_size_t i;
/* TODO: how to return error or 0 */
for (i = 0; i < size; i++)
{
int n;
n = awk_fputc (data[i], (FILE*)epa->handle);
//if (n == -1) wprintf (L"errno = %d, %d\n", errno, EINVAL);
if (awk_fputc (data[i], (FILE*)epa->handle) == ASE_CHAR_EOF) return -1;
}
*/
#if defined(ASE_CHAR_IS_MCHAR)
n = fprintf (epa->handle, "%.*s", size, data);
#elif defined(_WIN32)
n = fwprintf (epa->handle, "%.*s", size, data);
#else
n = fprintf (epa->handle, "%.*ls", size, data);
#endif
if (n < 0) return -1;
return size;
}
@ -380,12 +385,25 @@ static ase_ssize_t process_extio_file (
case ASE_AWK_IO_WRITE:
{
/*
ase_size_t i;
/* TODO: how to return error or 0 */
for (i = 0; i < size; i++)
{
awk_fputc (data[i], (FILE*)epa->handle);
if (awk_fputc (data[i], (FILE*)epa->handle) == ASE_CHAR_EOF) return -1;
}
*/
int n;
#if defined(ASE_CHAR_IS_MCHAR)
n = fprintf (epa->handle, "%.*s", size, data);
#elif defined(_WIN32)
n = fwprintf (epa->handle, "%.*s", size, data);
#else
n = fprintf (epa->handle, "%.*ls", size, data);
#endif
if (n < 0) return -1;
return size;
}
@ -491,13 +509,11 @@ static ase_ssize_t process_extio_console (
else if (cmd == ASE_AWK_IO_WRITE)
{
ase_size_t i;
/* TODO: how to return error or 0 */
for (i = 0; i < size; i++)
{
awk_fputc (data[i], (FILE*)epa->handle);
if (awk_fputc (data[i], (FILE*)epa->handle) == ASE_CHAR_EOF) return -1;
}
/*MessageBox (NULL, data, data, MB_OK);*/
return size;
}
else if (cmd == ASE_AWK_IO_FLUSH)

View File

@ -55,8 +55,14 @@ run_test()
echo "###################################"
echo "PROBLEM(S) DETECTED IN $script.".
echo "###################################"
echo "Do you want to abort? [y/n]"
read ans
if [ "$ans" = "y" -o "$ans" = "Y" ]
then
return 1
fi
fi
done
for script in cou-???.awk
@ -67,8 +73,14 @@ run_test()
echo "###################################"
echo "PROBLEM(S) DETECTED IN $script.".
echo "###################################"
echo "Do you want to abort? [y/n]"
read ans
if [ "$ans" = "y" -o "$ans" = "Y" ]
then
return 1
fi
fi
done
return 0

248
ase/utl/printf.c Normal file
View File

@ -0,0 +1,248 @@
/*
* $Id: printf.c,v 1.1 2006-12-24 16:07:13 bacon Exp $
*/
#include <stdarg.h>
#include <stdio.h>
#include <wchar.h>
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 xp_printf (const ase_char_t* fmt, ...)
{
int n;
va_list ap;
va_start (ap, fmt);
n = xp_vprintf (fmt, ap);
va_end (ap);
return n;
}
int xp_fprintf (FILE* file, const ase_char_t* fmt, ...)
{
int n;
va_list ap;
va_start (ap, fmt);
n = xp_vfprintf (file, fmt, ap);
va_end (ap);
return n;
}
int xp_vprintf (const ase_char_t* fmt, va_list ap)
{
return xp_vfprintf (stdout, fmt, ap);
}
int xp_vfprintf (FILE *stream, const ase_char_t* fmt, va_list ap)
{
int n;
ase_char_t* nf = __adjust_format (fmt);
if (nf == NULL) return -1;
#ifdef ASE_CHAR_IS_MCHAR
n = vfprintf (stream, nf, ap);
#else
n = vfwprintf (stream, nf, ap);
#endif
free (nf);
return n;
}
int xp_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);
va_end (ap);
return n;
}
int xp_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);
if (nf == NULL) return -1;
#if defined(ASE_CHAR_IS_MCHAR)
n = vsnprintf (buf, size, nf, ap);
#elif defined(_WIN32)
n = _vsnwprintf (buf, size, nf, ap);
#else
n = vswprintf (buf, size, nf, ap);
#endif
if (n < 0 || (size_t)n >= size)
{
if (size > 0) buf[size-1] = ASE_T('\0');
n = -1;
}
free (nf);
return n;
}
#define MOD_SHORT 1
#define MOD_LONG 2
#define MOD_LONGLONG 3
#define ADDC(str,c) \
do { \
if (xp_str_ccat(&str, c) == (size_t)-1) { \
xp_str_close (&str); \
return NULL; \
} \
} 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;
while (*fp != ASE_T('\0'))
{
while (*fp != ASE_T('\0') && *fp != ASE_T('%'))
{
ADDC (str, *fp++);
}
if (*fp == ASE_T('\0')) break;
xp_assert (*fp == ASE_T('%'));
ch = *fp++;
ADDC (str, ch); /* add % */
ch = *fp++;
/* flags */
while (1)
{
if (ch == ASE_T(' ') || ch == ASE_T('+') ||
ch == ASE_T('-') || ch == ASE_T('#'))
{
ADDC (str, ch);
ch = *fp++;
}
else
{
if (ch == ASE_T('0'))
{
ADDC (str, ch);
ch = *fp++;
}
break;
}
}
/* check the width */
if (ch == ASE_T('*'))
{
ADDC (str, ch);
ch = *fp++;
}
else
{
while (xp_isdigit(ch))
{
ADDC (str, ch);
ch = *fp++;
}
}
/* precision */
if (ch == ASE_T('.'))
{
ADDC (str, ch);
ch = *fp++;
if (ch == ASE_T('*'))
{
ADDC (str, ch);
ch = *fp++;
}
else
{
while (xp_isdigit(ch))
{
ADDC (str, ch);
ch = *fp++;
}
}
}
/* modifier */
for (modifier = 0;;)
{
if (ch == ASE_T('h')) modifier = MOD_SHORT;
else if (ch == ASE_T('l'))
{
modifier = (modifier == MOD_LONG)? MOD_LONGLONG: MOD_LONG;
}
else break;
ch = *fp++;
}
/* type */
if (ch == ASE_T('%')) ADDC (str, ch);
else if (ch == ASE_T('c') || ch == ASE_T('s'))
{
#if !defined(ASE_CHAR_IS_MCHAR) && !defined(_WIN32)
ADDC (str, 'l');
#endif
ADDC (str, ch);
}
else if (ch == ASE_T('C') || ch == ASE_T('S'))
{
#ifdef _WIN32
ADDC (str, ch);
#else
#ifdef ASE_CHAR_IS_MCHAR
ADDC (str, 'l');
#endif
ADDC (str, xp_tolower(ch));
#endif
}
else if (ch == ASE_T('d') || ch == ASE_T('i') ||
ch == ASE_T('o') || ch == ASE_T('u') ||
ch == ASE_T('x') || ch == ASE_T('X'))
{
if (modifier == MOD_SHORT)
{
ADDC (str, 'h');
}
else if (modifier == MOD_LONG)
{
ADDC (str, 'l');
}
else if (modifier == MOD_LONGLONG)
{
#if defined(_WIN32) && !defined(__LCC__)
ADDC (str, 'I');
ADDC (str, '6');
ADDC (str, '4');
#else
ADDC (str, 'l');
ADDC (str, 'l');
#endif
}
ADDC (str, ch);
}
else if (ch == ASE_T('\0')) break;
else ADDC (str, ch);
}
return xp_str_cield (&str);
}