*** empty log message ***

This commit is contained in:
hyung-hwan 2006-10-16 14:39:21 +00:00
parent 10d776577d
commit 3e462dbcf1
5 changed files with 77 additions and 30 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.h,v 1.128 2006-10-15 15:45:41 bacon Exp $
* $Id: awk.h,v 1.129 2006-10-16 14:38:43 bacon Exp $
*/
#ifndef _XP_AWK_AWK_H_
@ -25,10 +25,12 @@ typedef xp_ssize_t (*xp_awk_io_t) (
struct xp_awk_extio_t
{
xp_awk_run_t* run; /* [IN] */
int type; /* [IN] console, file, coproc, pipe */
int mode; /* [IN] read, write, etc */
xp_char_t* name; /* [IN] */
void* custom_data; /* [IN] */
void* handle; /* [OUT] */
/* input buffer */
@ -359,6 +361,9 @@ xp_awk_val_t* xp_awk_getglobal (xp_awk_run_t* run, xp_size_t idx);
int xp_awk_setglobal (xp_awk_run_t* run, xp_size_t idx, xp_awk_val_t* val);
void xp_awk_setretval (xp_awk_run_t* run, xp_awk_val_t* val);
int xp_awk_setconsolename (
xp_awk_run_t* run, const xp_char_t* name, xp_size_t len);
int xp_awk_getrunerrnum (xp_awk_run_t* run);
void xp_awk_setrunerrnum (xp_awk_run_t* run, int errnum);

View File

@ -1,5 +1,5 @@
/*
* $Id: extio.c,v 1.53 2006-10-13 10:18:10 bacon Exp $
* $Id: extio.c,v 1.54 2006-10-16 14:38:43 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -129,6 +129,7 @@ int xp_awk_readextio (
return -1;
}
p->run = run;
p->type = (extio_type | extio_mask);
p->mode = extio_mode;
p->handle = XP_NULL;
@ -453,6 +454,7 @@ int xp_awk_writeextio_str (
return -1;
}
p->run = run;
p->type = (extio_type | extio_mask);
p->mode = extio_mode;
p->handle = XP_NULL;

View File

@ -1,5 +1,5 @@
/*
* $Id: run.c,v 1.237 2006-10-16 09:11:53 bacon Exp $
* $Id: run.c,v 1.238 2006-10-16 14:38:43 bacon Exp $
*/
#include <xp/awk/awk_i.h>
@ -450,6 +450,30 @@ void xp_awk_setretval (xp_awk_run_t* run, xp_awk_val_t* val)
xp_awk_refupval (val);
}
int xp_awk_setconsolename (
xp_awk_run_t* run, const xp_char_t* name, xp_size_t len)
{
xp_awk_val_t* tmp;
int n;
if (len == 0) tmp = xp_awk_val_zls;
else
{
tmp = xp_awk_makestrval (run, name, len);
if (tmp == XP_NULL)
{
run->errnum = XP_AWK_ENOMEM;
return -1;
}
}
xp_awk_refupval (tmp);
n = xp_awk_setglobal (run, XP_AWK_GLOBAL_FILENAME, tmp);
xp_awk_refdownval (run, tmp);
return n;
}
int xp_awk_getrunerrnum (xp_awk_run_t* run)
{
return run->errnum;
@ -882,11 +906,12 @@ static int __set_globals_to_default (xp_awk_run_t* run)
static struct __gtab_t gtab[] =
{
{ XP_AWK_GLOBAL_CONVFMT, DEFAULT_CONVFMT },
{ XP_AWK_GLOBAL_OFMT, DEFAULT_OFMT },
{ XP_AWK_GLOBAL_OFS, DEFAULT_OFS },
{ XP_AWK_GLOBAL_ORS, DEFAULT_ORS },
{ XP_AWK_GLOBAL_SUBSEP, DEFAULT_SUBSEP },
{ XP_AWK_GLOBAL_CONVFMT, DEFAULT_CONVFMT },
{ XP_AWK_GLOBAL_FILENAME, XP_NULL },
{ XP_AWK_GLOBAL_OFMT, DEFAULT_OFMT },
{ XP_AWK_GLOBAL_OFS, DEFAULT_OFS },
{ XP_AWK_GLOBAL_ORS, DEFAULT_ORS },
{ XP_AWK_GLOBAL_SUBSEP, DEFAULT_SUBSEP },
};
xp_awk_val_t* tmp;
@ -894,11 +919,18 @@ static int __set_globals_to_default (xp_awk_run_t* run)
for (i = 0; i < xp_countof(gtab); i++)
{
tmp = xp_awk_makestrval0 (run, gtab[i].str);
if (tmp == XP_NULL)
if (gtab[i].str == XP_NULL || gtab[i].str[0] == XP_T('\0'))
{
run->errnum = XP_AWK_ENOMEM;
return -1;
tmp = xp_awk_val_zls;
}
else
{
tmp = xp_awk_makestrval0 (run, gtab[i].str);
if (tmp == XP_NULL)
{
run->errnum = XP_AWK_ENOMEM;
return -1;
}
}
xp_awk_refupval (tmp);

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.c,v 1.99 2006-10-16 09:11:53 bacon Exp $
* $Id: awk.c,v 1.100 2006-10-16 14:39:21 bacon Exp $
*/
#include <xp/awk/awk.h>
@ -295,6 +295,7 @@ static xp_ssize_t process_extio_file (
xp_printf (XP_TEXT("opending %s of type %d (file)\n"), epa->name, epa->type);
handle = fopen_t (epa->name, mode);
if (handle == NULL) return -1;
epa->handle = (void*)handle;
return 1;
}
@ -341,14 +342,13 @@ static int open_extio_console (xp_awk_extio_t* epa);
static int close_extio_console (xp_awk_extio_t* epa);
static int next_extio_console (xp_awk_extio_t* epa);
static const xp_char_t* infiles[] =
static xp_size_t infile_no = 0;
static const xp_char_t* infiles[10000] =
{
//XP_T(""),
XP_T("awk.in"),
XP_T(""),
XP_NULL
};
static xp_size_t infile_no = 0;
static xp_ssize_t process_extio_console (
int cmd, void* arg, xp_char_t* data, xp_size_t size)
@ -471,6 +471,14 @@ xp_printf (XP_TEXT("failed to open console of type %x - fopen failure\n"), epa->
}
xp_printf (XP_T(" console(r) - %s\n"), infiles[infile_no]);
if (xp_awk_setconsolename (
epa->run, infiles[infile_no],
xp_awk_strlen(infiles[infile_no])) == -1)
{
fclose (fp);
return -1;
}
epa->handle = fp;
}
@ -480,6 +488,8 @@ xp_printf (XP_T(" console(r) - %s\n"), infiles[infile_no]);
else if (epa->mode == XP_AWK_IO_CONSOLE_WRITE)
{
xp_printf (XP_T(" console(w) - <standard output>\n"));
/* TODO: does output console has a name??? */
/*xp_awk_setconsolename (XP_T(""));*/
epa->handle = stdout;
return 1;
}
@ -635,7 +645,7 @@ static int __main (int argc, xp_char_t* argv[])
if (argc <= 1)
{
xp_printf (XP_T("Usage: %s [-m] source_file [data_file]\n"), argv[0]);
xp_printf (XP_T("Usage: %s [-m] source_file [data_file ...]\n"), argv[0]);
return -1;
}
@ -654,14 +664,15 @@ static int __main (int argc, xp_char_t* argv[])
src_io.input_file = argv[i];
file_count++;
}
else if (file_count == 1)
else if (file_count >= 1 && file_count < xp_countof(infiles)-1)
{
infiles[0] = argv[i];
infiles[file_count-1] = argv[i];
infiles[file_count] = XP_NULL;
file_count++;
}
else
{
xp_printf (XP_T("Usage: %s [-m] source_file [data_file]\n"), argv[0]);
xp_printf (XP_T("Usage: %s [-m] [-f source_file] [data_file ...]\n"), argv[0]);
return -1;
}
}

View File

@ -1,20 +1,17 @@
/hello/
{
//print FILENAME;
/hello/ {
print FILENAME;
print "**1**" $0;
//nextfile;
#nextfile;
print "----------------";
}
/hello/
{
//print FILENAME;
/hello/ {
print FILENAME;
print "**2**" $0;
nextfile;
print "----------------";
}
END
{
END {
print "== END OF PROGRAM ==";
}