fixed a bug in hawk_rtx_makembsvalwithbchars2() and hawk_rtx_makembsvalwithuchars2()
fixing sed code being imported
This commit is contained in:
parent
a604d40e6e
commit
55a024bff2
@ -13,7 +13,7 @@ LDFLAGS_COMMON = -L$(abs_builddir)/../lib -L$(libdir)
|
||||
##Use -l for third party libraries for automatic inclusion to DEPENDENCIES .
|
||||
LIBADD_COMMON = ../lib/libhawk.la
|
||||
|
||||
bin_PROGRAMS = hawk #hsed
|
||||
bin_PROGRAMS = hawk hsed
|
||||
|
||||
##################################################
|
||||
# hawk
|
||||
@ -38,8 +38,8 @@ hawk_LDFLAGS = $(LDFLAGS_COMMON)
|
||||
##
|
||||
hawk_LDADD = $(LIBADD_COMMON) $(LIBM)
|
||||
|
||||
#hsed_SOURCES = main-hsed.c
|
||||
#hsed_CPPFLAGS = $(CPPFLAGS_COMMON)
|
||||
#hsed_CFLAGS = $(CFLAGS_COMMON)
|
||||
#hsed_LDFLAGS = $(LDFLAGS_COMMON)
|
||||
#hsed_LDADD = $(LIBADD_COMMON) $(LIBM)
|
||||
hsed_SOURCES = main-hsed.c
|
||||
hsed_CPPFLAGS = $(CPPFLAGS_COMMON)
|
||||
hsed_CFLAGS = $(CFLAGS_COMMON)
|
||||
hsed_LDFLAGS = $(LDFLAGS_COMMON)
|
||||
hsed_LDADD = $(LIBADD_COMMON) $(LIBM)
|
||||
|
@ -88,7 +88,7 @@ PRE_UNINSTALL = :
|
||||
POST_UNINSTALL = :
|
||||
build_triplet = @build@
|
||||
host_triplet = @host@
|
||||
bin_PROGRAMS = hawk$(EXEEXT)
|
||||
bin_PROGRAMS = hawk$(EXEEXT) hsed$(EXEEXT)
|
||||
subdir = bin
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_sign.m4 \
|
||||
@ -120,6 +120,12 @@ am__v_lt_1 =
|
||||
hawk_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
|
||||
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(hawk_CFLAGS) $(CFLAGS) \
|
||||
$(hawk_LDFLAGS) $(LDFLAGS) -o $@
|
||||
am_hsed_OBJECTS = hsed-main-hsed.$(OBJEXT)
|
||||
hsed_OBJECTS = $(am_hsed_OBJECTS)
|
||||
hsed_DEPENDENCIES = $(LIBADD_COMMON) $(am__DEPENDENCIES_1)
|
||||
hsed_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
|
||||
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(hsed_CFLAGS) $(CFLAGS) \
|
||||
$(hsed_LDFLAGS) $(LDFLAGS) -o $@
|
||||
AM_V_P = $(am__v_P_@AM_V@)
|
||||
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
|
||||
am__v_P_0 = false
|
||||
@ -135,7 +141,8 @@ am__v_at_1 =
|
||||
DEFAULT_INCLUDES =
|
||||
depcomp = $(SHELL) $(top_srcdir)/ac/depcomp
|
||||
am__maybe_remake_depfiles = depfiles
|
||||
am__depfiles_remade = ./$(DEPDIR)/hawk-main-hawk.Po
|
||||
am__depfiles_remade = ./$(DEPDIR)/hawk-main-hawk.Po \
|
||||
./$(DEPDIR)/hsed-main-hsed.Po
|
||||
am__mv = mv -f
|
||||
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
|
||||
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
@ -155,8 +162,8 @@ AM_V_CCLD = $(am__v_CCLD_@AM_V@)
|
||||
am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
|
||||
am__v_CCLD_0 = @echo " CCLD " $@;
|
||||
am__v_CCLD_1 =
|
||||
SOURCES = $(hawk_SOURCES)
|
||||
DIST_SOURCES = $(hawk_SOURCES)
|
||||
SOURCES = $(hawk_SOURCES) $(hsed_SOURCES)
|
||||
DIST_SOURCES = $(hawk_SOURCES) $(hsed_SOURCES)
|
||||
am__can_run_installinfo = \
|
||||
case $$AM_UPDATE_INFO_DIR in \
|
||||
n|no|NO) false;; \
|
||||
@ -351,6 +358,11 @@ hawk_CPPFLAGS = $(CPPFLAGS_COMMON)
|
||||
hawk_CFLAGS = $(CFLAGS_COMMON)
|
||||
hawk_LDFLAGS = $(LDFLAGS_COMMON)
|
||||
hawk_LDADD = $(LIBADD_COMMON) $(LIBM)
|
||||
hsed_SOURCES = main-hsed.c
|
||||
hsed_CPPFLAGS = $(CPPFLAGS_COMMON)
|
||||
hsed_CFLAGS = $(CFLAGS_COMMON)
|
||||
hsed_LDFLAGS = $(LDFLAGS_COMMON)
|
||||
hsed_LDADD = $(LIBADD_COMMON) $(LIBM)
|
||||
all: all-am
|
||||
|
||||
.SUFFIXES:
|
||||
@ -438,6 +450,10 @@ hawk$(EXEEXT): $(hawk_OBJECTS) $(hawk_DEPENDENCIES) $(EXTRA_hawk_DEPENDENCIES)
|
||||
@rm -f hawk$(EXEEXT)
|
||||
$(AM_V_CCLD)$(hawk_LINK) $(hawk_OBJECTS) $(hawk_LDADD) $(LIBS)
|
||||
|
||||
hsed$(EXEEXT): $(hsed_OBJECTS) $(hsed_DEPENDENCIES) $(EXTRA_hsed_DEPENDENCIES)
|
||||
@rm -f hsed$(EXEEXT)
|
||||
$(AM_V_CCLD)$(hsed_LINK) $(hsed_OBJECTS) $(hsed_LDADD) $(LIBS)
|
||||
|
||||
mostlyclean-compile:
|
||||
-rm -f *.$(OBJEXT)
|
||||
|
||||
@ -445,6 +461,7 @@ distclean-compile:
|
||||
-rm -f *.tab.c
|
||||
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hawk-main-hawk.Po@am__quote@ # am--include-marker
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hsed-main-hsed.Po@am__quote@ # am--include-marker
|
||||
|
||||
$(am__depfiles_remade):
|
||||
@$(MKDIR_P) $(@D)
|
||||
@ -490,6 +507,20 @@ hawk-main-hawk.obj: main-hawk.c
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hawk_CPPFLAGS) $(CPPFLAGS) $(hawk_CFLAGS) $(CFLAGS) -c -o hawk-main-hawk.obj `if test -f 'main-hawk.c'; then $(CYGPATH_W) 'main-hawk.c'; else $(CYGPATH_W) '$(srcdir)/main-hawk.c'; fi`
|
||||
|
||||
hsed-main-hsed.o: main-hsed.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hsed_CPPFLAGS) $(CPPFLAGS) $(hsed_CFLAGS) $(CFLAGS) -MT hsed-main-hsed.o -MD -MP -MF $(DEPDIR)/hsed-main-hsed.Tpo -c -o hsed-main-hsed.o `test -f 'main-hsed.c' || echo '$(srcdir)/'`main-hsed.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/hsed-main-hsed.Tpo $(DEPDIR)/hsed-main-hsed.Po
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='main-hsed.c' object='hsed-main-hsed.o' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hsed_CPPFLAGS) $(CPPFLAGS) $(hsed_CFLAGS) $(CFLAGS) -c -o hsed-main-hsed.o `test -f 'main-hsed.c' || echo '$(srcdir)/'`main-hsed.c
|
||||
|
||||
hsed-main-hsed.obj: main-hsed.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hsed_CPPFLAGS) $(CPPFLAGS) $(hsed_CFLAGS) $(CFLAGS) -MT hsed-main-hsed.obj -MD -MP -MF $(DEPDIR)/hsed-main-hsed.Tpo -c -o hsed-main-hsed.obj `if test -f 'main-hsed.c'; then $(CYGPATH_W) 'main-hsed.c'; else $(CYGPATH_W) '$(srcdir)/main-hsed.c'; fi`
|
||||
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/hsed-main-hsed.Tpo $(DEPDIR)/hsed-main-hsed.Po
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='main-hsed.c' object='hsed-main-hsed.obj' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hsed_CPPFLAGS) $(CPPFLAGS) $(hsed_CFLAGS) $(CFLAGS) -c -o hsed-main-hsed.obj `if test -f 'main-hsed.c'; then $(CYGPATH_W) 'main-hsed.c'; else $(CYGPATH_W) '$(srcdir)/main-hsed.c'; fi`
|
||||
|
||||
mostlyclean-libtool:
|
||||
-rm -f *.lo
|
||||
|
||||
@ -624,6 +655,7 @@ clean-am: clean-binPROGRAMS clean-generic clean-libtool mostlyclean-am
|
||||
|
||||
distclean: distclean-am
|
||||
-rm -f ./$(DEPDIR)/hawk-main-hawk.Po
|
||||
-rm -f ./$(DEPDIR)/hsed-main-hsed.Po
|
||||
-rm -f Makefile
|
||||
distclean-am: clean-am distclean-compile distclean-generic \
|
||||
distclean-tags
|
||||
@ -670,6 +702,7 @@ installcheck-am:
|
||||
|
||||
maintainer-clean: maintainer-clean-am
|
||||
-rm -f ./$(DEPDIR)/hawk-main-hawk.Po
|
||||
-rm -f ./$(DEPDIR)/hsed-main-hsed.Po
|
||||
-rm -f Makefile
|
||||
maintainer-clean-am: distclean-am maintainer-clean-generic
|
||||
|
||||
@ -707,12 +740,6 @@ uninstall-am: uninstall-binPROGRAMS
|
||||
.PRECIOUS: Makefile
|
||||
|
||||
|
||||
#hsed_SOURCES = main-hsed.c
|
||||
#hsed_CPPFLAGS = $(CPPFLAGS_COMMON)
|
||||
#hsed_CFLAGS = $(CFLAGS_COMMON)
|
||||
#hsed_LDFLAGS = $(LDFLAGS_COMMON)
|
||||
#hsed_LDADD = $(LIBADD_COMMON) $(LIBM)
|
||||
|
||||
# Tell versions [3.59,3.63) of GNU make to not export all variables.
|
||||
# Otherwise a system limit (for SysV at least) may be exceeded.
|
||||
.NOEXPORT:
|
||||
|
@ -69,6 +69,8 @@ hawk_oow_t hawk_becs_ncatuchars (hawk_becs_t* str, const hawk_uch_t* s, hawk_oow
|
||||
{
|
||||
hawk_oow_t bcslen, ucslen;
|
||||
|
||||
if (!cmgr) cmgr = str->gem->cmgr;
|
||||
|
||||
ucslen = len;
|
||||
if (hawk_conv_uchars_to_bchars_with_cmgr(s, &ucslen, HAWK_NULL, &bcslen, cmgr) <= -1) return (hawk_oow_t)-1;
|
||||
|
||||
@ -87,6 +89,8 @@ hawk_oow_t hawk_uecs_ncatbchars (hawk_uecs_t* str, const hawk_bch_t* s, hawk_oow
|
||||
{
|
||||
hawk_oow_t bcslen, ucslen;
|
||||
|
||||
if (!cmgr) cmgr = str->gem->cmgr;
|
||||
|
||||
bcslen = len;
|
||||
if (hawk_conv_bchars_to_uchars_with_cmgr(s, &bcslen, HAWK_NULL, &ucslen, cmgr, all) <= -1) return (hawk_oow_t)-1;
|
||||
|
||||
|
@ -223,38 +223,6 @@ hawk_errstr_t hawk_geterrstr (hawk_t* hawk)
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
const hawk_bch_t* hawk_geterrbmsg (hawk_t* hawk)
|
||||
{
|
||||
return hawk_gem_geterrbmsg(hawk_getgem(hawk));
|
||||
}
|
||||
|
||||
const hawk_uch_t* hawk_geterrumsg (hawk_t* hawk)
|
||||
{
|
||||
return hawk_gem_geterrumsg(hawk_getgem(hawk));
|
||||
}
|
||||
|
||||
void hawk_geterrinf (hawk_t* hawk, hawk_errinf_t* errinf)
|
||||
{
|
||||
hawk_gem_geterrinf (hawk_getgem(hawk), errinf);
|
||||
}
|
||||
|
||||
void hawk_geterror (hawk_t* hawk, hawk_errnum_t* errnum, const hawk_ooch_t** errmsg, hawk_loc_t* errloc)
|
||||
{
|
||||
hawk_gem_geterror (hawk_getgem(hawk), errnum, errmsg, errloc);
|
||||
}
|
||||
|
||||
const hawk_ooch_t* hawk_backuperrmsg (hawk_t* hawk)
|
||||
{
|
||||
hawk_copy_oocstr (hawk->errmsg_backup, HAWK_COUNTOF(hawk->errmsg_backup), hawk_geterrmsg(hawk));
|
||||
return hawk->errmsg_backup;
|
||||
}
|
||||
|
||||
void hawk_seterrinf (hawk_t* hawk, const hawk_errinf_t* errinf)
|
||||
{
|
||||
hawk_gem_seterrinf (hawk_getgem(hawk), errinf);
|
||||
}
|
||||
|
||||
void hawk_seterrbfmt (hawk_t* hawk, const hawk_loc_t* errloc, hawk_errnum_t errnum, const hawk_bch_t* errfmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
@ -281,44 +249,8 @@ void hawk_seterruvfmt (hawk_t* hawk, const hawk_loc_t* errloc, hawk_errnum_t err
|
||||
hawk_gem_seterruvfmt (hawk_getgem(hawk), errloc, errnum, errfmt, ap);
|
||||
}
|
||||
|
||||
void hawk_seterror (hawk_t* hawk, const hawk_loc_t* errloc, hawk_errnum_t errnum, const hawk_oocs_t* errarg)
|
||||
{
|
||||
hawk_gem_seterror (hawk_getgem(hawk), errloc, errnum, errarg);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
const hawk_bch_t* hawk_rtx_geterrbmsg (hawk_rtx_t* rtx)
|
||||
{
|
||||
return hawk_gem_geterrbmsg(hawk_rtx_getgem(rtx));
|
||||
}
|
||||
|
||||
const hawk_uch_t* hawk_rtx_geterrumsg (hawk_rtx_t* rtx)
|
||||
{
|
||||
return hawk_gem_geterrumsg(hawk_rtx_getgem(rtx));
|
||||
}
|
||||
|
||||
void hawk_rtx_geterrinf (hawk_rtx_t* rtx, hawk_errinf_t* errinf)
|
||||
{
|
||||
hawk_gem_geterrinf (hawk_rtx_getgem(rtx), errinf);
|
||||
}
|
||||
|
||||
void hawk_rtx_geterror (hawk_rtx_t* rtx, hawk_errnum_t* errnum, const hawk_ooch_t** errmsg, hawk_loc_t* errloc)
|
||||
{
|
||||
hawk_gem_geterror (hawk_rtx_getgem(rtx), errnum, errmsg, errloc);
|
||||
}
|
||||
|
||||
const hawk_ooch_t* hawk_rtx_backuperrmsg (hawk_rtx_t* rtx)
|
||||
{
|
||||
hawk_copy_oocstr (rtx->errmsg_backup, HAWK_COUNTOF(rtx->errmsg_backup), hawk_rtx_geterrmsg(rtx));
|
||||
return rtx->errmsg_backup;
|
||||
}
|
||||
|
||||
void hawk_rtx_seterrinf (hawk_rtx_t* rtx, const hawk_errinf_t* errinf)
|
||||
{
|
||||
hawk_gem_seterrinf (hawk_rtx_getgem(rtx), errinf);
|
||||
}
|
||||
|
||||
void hawk_rtx_seterrbfmt (hawk_rtx_t* rtx, const hawk_loc_t* errloc, hawk_errnum_t errnum, const hawk_bch_t* errfmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
@ -345,11 +277,6 @@ void hawk_rtx_seterruvfmt (hawk_rtx_t* rtx, const hawk_loc_t* errloc, hawk_errnu
|
||||
hawk_gem_seterruvfmt (hawk_rtx_getgem(rtx), errloc, errnum, errfmt, ap);
|
||||
}
|
||||
|
||||
void hawk_rtx_seterror (hawk_rtx_t* rtx, const hawk_loc_t* errloc, hawk_errnum_t errnum, const hawk_oocs_t* errarg)
|
||||
{
|
||||
hawk_gem_seterror (hawk_rtx_getgem(rtx), errloc, errnum, errarg);
|
||||
}
|
||||
|
||||
void hawk_rtx_errortohawk (hawk_rtx_t* rtx, hawk_t* hawk)
|
||||
{
|
||||
/* copy error information in 'rtx' to the 'hawk' object */
|
||||
@ -562,3 +489,9 @@ void hawk_gem_seterror (hawk_gem_t* gem, const hawk_loc_t* errloc, hawk_errnum_t
|
||||
if (errloc != HAWK_NULL) gem->errloc = *errloc;
|
||||
else HAWK_MEMSET (&gem->errloc, 0, HAWK_SIZEOF(gem->errloc));
|
||||
}
|
||||
|
||||
const hawk_ooch_t* hawk_gem_backuperrmsg (hawk_gem_t* gem)
|
||||
{
|
||||
hawk_copy_oocstr (gem->errmsg_backup, HAWK_COUNTOF(gem->errmsg_backup), hawk_gem_geterrmsg(gem));
|
||||
return gem->errmsg_backup;
|
||||
}
|
||||
|
@ -1123,6 +1123,7 @@ struct hawk_gem_t
|
||||
#else
|
||||
hawk_bch_t xerrmsg[HAWK_ERRMSG_CAPA * 2];
|
||||
#endif
|
||||
hawk_ooch_t errmsg_backup[HAWK_ERRMSG_CAPA];
|
||||
};
|
||||
|
||||
enum hawk_log_mask_t
|
||||
|
@ -461,6 +461,12 @@ HAWK_EXPORT const hawk_uch_t* hawk_gem_geterrumsg (
|
||||
hawk_gem_t* gem
|
||||
);
|
||||
|
||||
#if defined(HAWK_OOCH_IS_BCH)
|
||||
# define hawk_gem_geterrmsg hawk_gem_geterrbmsg
|
||||
#else
|
||||
# define hawk_gem_geterrmsg hawk_gem_geterrumsg
|
||||
#endif
|
||||
|
||||
HAWK_EXPORT void hawk_gem_seterrinf (
|
||||
hawk_gem_t* gem,
|
||||
const hawk_errinf_t* errinf
|
||||
@ -511,6 +517,10 @@ HAWK_EXPORT void hawk_gem_seterruvfmt (
|
||||
va_list ap
|
||||
);
|
||||
|
||||
HAWK_EXPORT const hawk_ooch_t* hawk_gem_backuperrmsg (
|
||||
hawk_gem_t* gem
|
||||
);
|
||||
|
||||
HAWK_EXPORT int hawk_gem_buildrex (
|
||||
hawk_gem_t* gem,
|
||||
const hawk_ooch_t* ptn,
|
||||
|
@ -336,15 +336,7 @@ struct hawk_t
|
||||
} tmp;
|
||||
|
||||
/* housekeeping */
|
||||
//hawk_oow_t errmsg_len; /* used by errbfmt() and errufmt(). don't rely on this. some other funtions don't set this properly */
|
||||
hawk_ooch_t errmsg_backup[HAWK_ERRMSG_CAPA];
|
||||
#if 0
|
||||
#if defined(HAWK_OOCH_IS_BCH)
|
||||
hawk_uch_t xerrmsg[HAWK_ERRMSG_CAPA];
|
||||
#else
|
||||
hawk_bch_t xerrmsg[HAWK_ERRMSG_CAPA * 2];
|
||||
#endif
|
||||
#endif
|
||||
|
||||
struct
|
||||
{
|
||||
@ -546,16 +538,7 @@ struct hawk_rtx_t
|
||||
hawk_oow_t capa;
|
||||
} forin; /* keys for for (x in y) ... */
|
||||
|
||||
//hawk_oow_t errmsg_len; /* used by errbfmt() and errufmt(). don't rely on this. some other funtions don't set this properly */
|
||||
hawk_ooch_t errmsg_backup[HAWK_ERRMSG_CAPA];
|
||||
#if 0
|
||||
#if defined(HAWK_OOCH_IS_BCH)
|
||||
hawk_uch_t xerrmsg[HAWK_ERRMSG_CAPA];
|
||||
#else
|
||||
hawk_bch_t xerrmsg[HAWK_ERRMSG_CAPA * 2];
|
||||
#endif
|
||||
#endif
|
||||
|
||||
hawk_rtx_ecb_t* ecb;
|
||||
};
|
||||
|
||||
|
@ -371,12 +371,14 @@ typedef enum hawk_sed_space_t hawk_sed_space_t;
|
||||
*/
|
||||
enum hawk_sed_iostd_type_t
|
||||
{
|
||||
HAWK_SED_IOSTD_NULL, /**< null resource type */
|
||||
HAWK_SED_IOSTD_FILE, /**< file */
|
||||
HAWK_SED_IOSTD_NULL, /**< null resource type */
|
||||
HAWK_SED_IOSTD_FILE, /**< file */
|
||||
HAWK_SED_IOSTD_FILEB, /**< file */
|
||||
HAWK_SED_IOSTD_FILEU, /**< file */
|
||||
HAWK_SED_IOSTD_STR, /**< string */
|
||||
HAWK_SED_IOSTD_SIO /**< sio */
|
||||
HAWK_SED_IOSTD_OOCS, /**< string */
|
||||
HAWK_SED_IOSTD_BCS,
|
||||
HAWK_SED_IOSTD_UCS,
|
||||
HAWK_SED_IOSTD_SIO /**< sio */
|
||||
};
|
||||
typedef enum hawk_sed_iostd_type_t hawk_sed_iostd_type_t;
|
||||
|
||||
@ -429,7 +431,9 @@ struct hawk_sed_iostd_t
|
||||
* the ptr field with hawk_sed_freemem() once you're done with it
|
||||
* to avoid memory leaks.
|
||||
*/
|
||||
hawk_oocs_t str;
|
||||
hawk_oocs_t oocs;
|
||||
hawk_bcs_t bcs;
|
||||
hawk_ucs_t ucs;
|
||||
|
||||
/** pre-opened sio stream */
|
||||
hawk_sio_t* sio;
|
||||
@ -488,10 +492,12 @@ static HAWK_INLINE hawk_gem_t* hawk_sed_getgem (hawk_sed_t* sed) { return &((haw
|
||||
* hawk_sed_open().
|
||||
*/
|
||||
static HAWK_INLINE hawk_mmgr_t* hawk_sed_getmmgr (hawk_sed_t* sed) { return ((hawk_sed_alt_t*)sed)->_gem.mmgr; }
|
||||
static HAWK_INLINE hawk_cmgr_t* hawk_sed_getcmgr (hawk_sed_t* sed) { return ((hawk_sed_alt_t*)sed)->_gem.cmgr; }
|
||||
#else
|
||||
#define hawk_sed_getxtn(sed) ((void*)((hawk_uint8_t*)sed + ((hawk_sed_alt_t*)sed)->_instsize))
|
||||
#define hawk_sed_getgem(sed) (&((hawk_sed_alt_t*)(sed))->_gem)
|
||||
#define hawk_sed_getmmgr(sed) (((hawk_sed_alt_t*)(sed))->_gem.mmgr)
|
||||
#define hawk_sed_getcmgr(sed) (((hawk_sed_alt_t*)(sed))->_gem.cmgr)
|
||||
#endif /* HAWK_HAVE_INLINE */
|
||||
|
||||
|
||||
@ -535,30 +541,27 @@ HAWK_EXPORT int hawk_sed_setopt (
|
||||
* \return error number
|
||||
*/
|
||||
|
||||
#if defined(HAWK_HAVE_INLINE)
|
||||
static HAWK_INLINE hawk_errnum_t hawk_sed_geterrnum (hawk_sed_t* sed) { return hawk_gem_geterrnum(hawk_sed_getgem(sed)); }
|
||||
static HAWK_INLINE const hawk_loc_t* hawk_sed_geterrloc (hawk_sed_t* sed) { return hawk_gem_geterrloc(hawk_sed_getgem(sed)); }
|
||||
static HAWK_INLINE const hawk_bch_t* hawk_sed_geterrbmsg (hawk_sed_t* sed) { return hawk_gem_geterrbmsg(hawk_sed_getgem(sed)); }
|
||||
static HAWK_INLINE const hawk_uch_t* hawk_sed_geterrumsg (hawk_sed_t* sed) { return hawk_gem_geterrumsg(hawk_sed_getgem(sed)); }
|
||||
#else
|
||||
#define hawk_sed_geterrnum(sed) hawk_gem_geterrnum(hawk_sed_getgem(sed))
|
||||
#define hawk_sed_geterrloc(sed) hawk_gem_geterrloc(hawk_sed_getgem(sed))
|
||||
#define hawk_sed_geterrbmsg(sed) hawk_gem_geterrbmsg(hawk_sed_getgem(sed))
|
||||
#define hawk_sed_geterrumsg(sed) hawk_gem_geterrumsg(hawk_sed_getgem(sed))
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* The hawk_sed_geterror() function gets an error number, an error location,
|
||||
* and an error message. The information is set to the memory area pointed
|
||||
* to by each parameter.
|
||||
*/
|
||||
HAWK_EXPORT void hawk_sed_geterror (
|
||||
hawk_sed_t* sed, /**< stream editor */
|
||||
hawk_errnum_t* errnum, /**< error number */
|
||||
const hawk_ooch_t** errmsg, /**< error message */
|
||||
hawk_loc_t* errloc /**< error location */
|
||||
);
|
||||
#if defined(HAWK_HAVE_INLINE)
|
||||
static HAWK_INLINE hawk_errnum_t hawk_sed_geterrnum (hawk_sed_t* sed) { return hawk_gem_geterrnum(hawk_sed_getgem(sed)); }
|
||||
static HAWK_INLINE const hawk_loc_t* hawk_sed_geterrloc (hawk_sed_t* sed) { return hawk_gem_geterrloc(hawk_sed_getgem(sed)); }
|
||||
static HAWK_INLINE const hawk_bch_t* hawk_sed_geterrbmsg (hawk_sed_t* sed) { return hawk_gem_geterrbmsg(hawk_sed_getgem(sed)); }
|
||||
static HAWK_INLINE const hawk_uch_t* hawk_sed_geterrumsg (hawk_sed_t* sed) { return hawk_gem_geterrumsg(hawk_sed_getgem(sed)); }
|
||||
static HAWK_INLINE void hawk_sed_geterrinf (hawk_sed_t* sed, hawk_errinf_t* errinf) { return hawk_gem_geterrinf(hawk_sed_getgem(sed), errinf); }
|
||||
static HAWK_INLINE void hawk_sed_geterror (hawk_sed_t* sed, hawk_errnum_t* errnum, const hawk_ooch_t** errmsg, hawk_loc_t* errloc) { return hawk_gem_geterror(hawk_sed_getgem(sed), errnum, errmsg, errloc); }
|
||||
#else
|
||||
#define hawk_sed_geterrnum(sed) hawk_gem_geterrnum(hawk_sed_getgem(sed))
|
||||
#define hawk_sed_geterrloc(sed) hawk_gem_geterrloc(hawk_sed_getgem(sed))
|
||||
#define hawk_sed_geterrbmsg(sed) hawk_gem_geterrbmsg(hawk_sed_getgem(sed))
|
||||
#define hawk_sed_geterrumsg(sed) hawk_gem_geterrumsg(hawk_sed_getgem(sed))
|
||||
#define hawk_sed_geterrinf(sed, errinf) (hawk_gem_geterrinf(hawk_sed_getgem(sed), errinf))
|
||||
#define hawk_sed_geterror(sed, errnum, errmsg, errloc) (hawk_gem_geterror(hawk_sed_getgem(sed), errnum, errmsg, errloc))
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* The hawk_sed_seterrnum() function sets the error information omitting
|
||||
@ -568,12 +571,33 @@ HAWK_EXPORT void hawk_sed_geterror (
|
||||
*/
|
||||
#if defined(HAWK_HAVE_INLINE)
|
||||
static HAWK_INLINE void hawk_sed_seterrnum (hawk_sed_t* sed, const hawk_loc_t* errloc, hawk_errnum_t errnum) { hawk_gem_seterrnum (hawk_sed_getgem(sed), errloc, errnum); }
|
||||
static HAWK_INLINE void hawk_sed_seterrinf (hawk_sed_t* sed, const hawk_errinf_t* errinf) { hawk_gem_seterrinf (hawk_sed_getgem(sed), errinf); }
|
||||
static HAWK_INLINE void hawk_sed_seterror (hawk_sed_t* sed, const hawk_loc_t* errloc, hawk_errnum_t errnum, const hawk_oocs_t* errarg) { hawk_gem_seterror(hawk_sed_getgem(sed), errloc, errnum, errarg); }
|
||||
static HAWK_INLINE const hawk_ooch_t* hawk_sed_backuperrmsg (hawk_sed_t* sed) { return hawk_gem_backuperrmsg(hawk_sed_getgem(sed)); }
|
||||
#else
|
||||
#define hawk_sed_seterrnum(sed, errloc, errnum) hawk_gem_seterrnum(hawk_sed_getgem(sed), errloc, errnum)
|
||||
#define hawk_set_seterror(sed, errloc, errnum, errarg) hawk_sed_seterror(hawk_sed_getgem(sed), errloc, errnum, errarg)
|
||||
#define hawk_sed_seterrinf(sed, errinf) hawk_gem_seterrinf(hawk_sed_getgem(sed), errinf)
|
||||
#define hawk_sed_seterror(sed, errloc, errnum, errarg) hawk_gem_seterror(hawk_sed_getgem(sed), errloc, errnum, errarg)
|
||||
#define hawk_sed_backuperrmsg(sed) hawk_gem_backuperrmsg(hawk_sed_getgem(sed))
|
||||
#endif
|
||||
|
||||
|
||||
HAWK_EXPORT void hawk_sed_seterrbfmt (
|
||||
hawk_sed_t* sed,
|
||||
const hawk_loc_t* errloc,
|
||||
hawk_errnum_t errnum,
|
||||
const hawk_bch_t* fmt,
|
||||
...
|
||||
);
|
||||
|
||||
HAWK_EXPORT void hawk_sed_seterrufmt (
|
||||
hawk_sed_t* sed,
|
||||
const hawk_loc_t* errloc,
|
||||
hawk_errnum_t errnum,
|
||||
const hawk_uch_t* fmt,
|
||||
...
|
||||
);
|
||||
|
||||
/**
|
||||
* The hawk_sed_popecb() function pops an sed event callback set
|
||||
* and returns the pointer to it. If no callback set can be popped,
|
||||
@ -642,9 +666,20 @@ HAWK_EXPORT const hawk_ooch_t* hawk_sed_getcompid (
|
||||
* If this function fails, the location set in the command
|
||||
* may be wrong.
|
||||
*/
|
||||
HAWK_EXPORT const hawk_ooch_t* hawk_sed_setcompid (
|
||||
#if defined(HAWK_OOCH_IS_BCH)
|
||||
#define hawk_sed_setcompid(sed, id) hawk_sed_setcompidwithbcstr(sed, id)
|
||||
#else
|
||||
#define hawk_sed_setcompid(sed, id) hawk_sed_setcompidwithucstr(sed, id)
|
||||
#endif
|
||||
|
||||
HAWK_EXPORT const hawk_ooch_t* hawk_sed_setcompidwithbcstr (
|
||||
hawk_sed_t* sed,
|
||||
const hawk_ooch_t* id
|
||||
const hawk_bch_t* id
|
||||
);
|
||||
|
||||
HAWK_EXPORT const hawk_ooch_t* hawk_sed_setcompidwithucstr (
|
||||
hawk_sed_t* sed,
|
||||
const hawk_uch_t* id
|
||||
);
|
||||
|
||||
/**
|
||||
@ -782,21 +817,21 @@ HAWK_EXPORT int hawk_sed_compstdfileu (
|
||||
);
|
||||
|
||||
/**
|
||||
* The hawk_sed_compstdstr() function compiles a sed script stored
|
||||
* The hawk_sed_compstdoocstr() function compiles a sed script stored
|
||||
* in a null-terminated string pointed to by \a script.
|
||||
* \return 0 on success, -1 on failure
|
||||
*/
|
||||
HAWK_EXPORT int hawk_sed_compstdstr (
|
||||
HAWK_EXPORT int hawk_sed_compstdoocstr (
|
||||
hawk_sed_t* sed,
|
||||
const hawk_ooch_t* script
|
||||
);
|
||||
|
||||
/**
|
||||
* The hawk_sed_compstdxstr() function compiles a sed script of the
|
||||
* The hawk_sed_compstdoocs() function compiles a sed script of the
|
||||
* length \a script->len pointed to by \a script->ptr.
|
||||
* \return 0 on success, -1 on failure
|
||||
*/
|
||||
HAWK_EXPORT int hawk_sed_compstdxstr (
|
||||
HAWK_EXPORT int hawk_sed_compstdoocs (
|
||||
hawk_sed_t* sed,
|
||||
const hawk_oocs_t* script
|
||||
);
|
||||
|
@ -159,7 +159,7 @@ HAWK_EXPORT hawk_t* hawk_openstdwithmmgr (
|
||||
* in[0].u.str.len = hawk_count_oocstr(in.u.str.ptr);
|
||||
* in[1].type = HAWK_PARSESTD_NULL;
|
||||
* out.type = HAWK_PARSESTD_OOCS;
|
||||
* n = hawk_parsestd (hawk, in, &out);
|
||||
* n = hawk_parsestd(hawk, in, &out);
|
||||
* if (n >= 0)
|
||||
* {
|
||||
* hawk_printf (HAWK_T("%s\n"), out.u.str.ptr);
|
||||
|
157
hawk/lib/hawk.h
157
hawk/lib/hawk.h
@ -1589,23 +1589,12 @@ HAWK_EXPORT hawk_errstr_t hawk_geterrstr (
|
||||
* last error has occurred.
|
||||
*/
|
||||
|
||||
#if defined(HAWK_HAVE_INLINE)
|
||||
static HAWK_INLINE hawk_errnum_t hawk_geterrnum (hawk_t* hawk) { return ((hawk_alt_t*)hawk)->_gem.errnum; }
|
||||
static HAWK_INLINE const hawk_loc_t* hawk_geterrloc (hawk_t* hawk) { return hawk_gem_geterrloc(hawk_getgem(hawk)); }
|
||||
#else
|
||||
# define hawk_geterrnum(hawk) (((hawk_alt_t*)(hawk))->_gem.errnum)
|
||||
# define hawk_geterrloc(hawk) (hawk_gem_geterrloc(hawk_getgem(hawk)))
|
||||
#endif
|
||||
|
||||
/**
|
||||
* The hawk_geterrbmsg() function returns the error message describing
|
||||
* the last error occurred.
|
||||
*
|
||||
* \return error message
|
||||
*/
|
||||
HAWK_EXPORT const hawk_bch_t* hawk_geterrbmsg (
|
||||
hawk_t* hawk /**< hawk */
|
||||
);
|
||||
|
||||
/**
|
||||
* The hawk_geterrumsg() function returns the error message describing
|
||||
@ -1613,10 +1602,25 @@ HAWK_EXPORT const hawk_bch_t* hawk_geterrbmsg (
|
||||
*
|
||||
* \return error message
|
||||
*/
|
||||
HAWK_EXPORT const hawk_uch_t* hawk_geterrumsg (
|
||||
hawk_t* hawk /**< hawk */
|
||||
);
|
||||
|
||||
/**
|
||||
* The hawk_geterrinf() function copies error information into memory
|
||||
* pointed to by \a errinf from \a hawk.
|
||||
*/
|
||||
|
||||
#if defined(HAWK_HAVE_INLINE)
|
||||
static HAWK_INLINE hawk_errnum_t hawk_geterrnum (hawk_t* hawk) { return ((hawk_alt_t*)hawk)->_gem.errnum; }
|
||||
static HAWK_INLINE const hawk_loc_t* hawk_geterrloc (hawk_t* hawk) { return hawk_gem_geterrloc(hawk_getgem(hawk)); }
|
||||
static HAWK_INLINE const hawk_bch_t* hawk_geterrbmsg (hawk_t* hawk) { return hawk_gem_geterrbmsg(hawk_getgem(hawk)); }
|
||||
static HAWK_INLINE const hawk_uch_t* hawk_geterrumsg (hawk_t* hawk) { return hawk_gem_geterrumsg(hawk_getgem(hawk)); }
|
||||
static HAWK_INLINE void hawk_geterrinf (hawk_t* hawk, hawk_errinf_t* errinf) { return hawk_gem_geterrinf(hawk_getgem(hawk), errinf); }
|
||||
#else
|
||||
#define hawk_geterrnum(hawk) (((hawk_alt_t*)(hawk))->_gem.errnum)
|
||||
#define hawk_geterrloc(hawk) (hawk_gem_geterrloc(hawk_getgem(hawk)))
|
||||
#define hawk_geterrbmsg(hawk) (hawk_gem_geterrbmsg(hawk_getgem(hawk)))
|
||||
#define hawk_geterrumsg(hawk) (hawk_gem_geterrumsg(hawk_getgem(hawk)))
|
||||
#define hawk_geterrinf(hawk, errinf) (hawk_gem_geterrinf(hawk_getgem(hawk), errinf))
|
||||
#endif
|
||||
|
||||
#if defined(HAWK_OOCH_IS_BCH)
|
||||
# define hawk_geterrmsg hawk_geterrbmsg
|
||||
@ -1624,33 +1628,33 @@ HAWK_EXPORT const hawk_uch_t* hawk_geterrumsg (
|
||||
# define hawk_geterrmsg hawk_geterrumsg
|
||||
#endif
|
||||
|
||||
|
||||
HAWK_EXPORT const hawk_ooch_t* hawk_backuperrmsg (
|
||||
hawk_t* hawk /**< hawk */
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* The hawk_geterrinf() function copies error information into memory
|
||||
* pointed to by \a errinf from \a hawk.
|
||||
*/
|
||||
HAWK_EXPORT void hawk_geterrinf (
|
||||
hawk_t* hawk, /**< hawk */
|
||||
hawk_errinf_t* errinf /**< error information buffer */
|
||||
);
|
||||
|
||||
/**
|
||||
* The hawk_seterrnum() function sets the error information omitting
|
||||
* error location. You must pass a non-NULL for \a errarg if the specified
|
||||
* error number \a errnum requires one or more arguments to format an
|
||||
* error message.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The hawk_seterrinf() function sets the error information. This function
|
||||
* may be useful if you want to set a custom error message rather than letting
|
||||
* it automatically formatted.
|
||||
*/
|
||||
#if defined(HAWK_HAVE_INLINE)
|
||||
static HAWK_INLINE void hawk_seterrnum (hawk_t* hawk, const hawk_loc_t* errloc, hawk_errnum_t errnum) { hawk_gem_seterrnum (hawk_getgem(hawk), errloc, errnum); }
|
||||
static HAWK_INLINE void hawk_seterrinf (hawk_t* hawk, const hawk_errinf_t* errinf) { hawk_gem_seterrinf (hawk_getgem(hawk), errinf); }
|
||||
static HAWK_INLINE void hawk_seterror (hawk_t* hawk, const hawk_loc_t* errloc, hawk_errnum_t errnum, const hawk_oocs_t* errarg) { hawk_gem_seterror(hawk_getgem(hawk), errloc, errnum, errarg); }
|
||||
static HAWK_INLINE const hawk_ooch_t* hawk_backuperrmsg (hawk_t* hawk) { return hawk_gem_backuperrmsg(hawk_getgem(hawk)); }
|
||||
static HAWK_INLINE void hawk_geterror (hawk_t* hawk, hawk_errnum_t* errnum, const hawk_ooch_t** errmsg, hawk_loc_t* errloc) { return hawk_gem_geterror(hawk_getgem(hawk), errnum, errmsg, errloc); }
|
||||
#else
|
||||
#define hawk_seterrnum(hawk, errloc, errnum) hawk_gem_seterrnum(hawk_getgem(hawk), errloc, errnum)
|
||||
#define hawk_seterrinf(hawk, errinf) hawk_gem_seterrinf(hawk_getgem(hawk), errinf)
|
||||
#define hawk_seterror(hawk, errloc, errnum, errarg) hawk_gem_seterror(hawk_getgem(hawk), errloc, errnum, errarg)
|
||||
#define hawk_backuperrmsg(hawk) hawk_gem_backuperrmsg(hawk_getgem(hawk))
|
||||
#define hawk_geterror(hawk, errnum, errmsg, errloc) (hawk_gem_geterror(hawk_getgem(hawk), errnum, errmsg, errloc))
|
||||
#endif
|
||||
|
||||
|
||||
HAWK_EXPORT void hawk_seterrbfmt (
|
||||
hawk_t* hawk,
|
||||
const hawk_loc_t* errloc,
|
||||
@ -1691,17 +1695,6 @@ HAWK_EXPORT void hawk_seterruvfmt (
|
||||
# define hawk_seterrvfmt hawk_seterrbvfmt
|
||||
#endif
|
||||
|
||||
/**
|
||||
* The hawk_seterrinf() function sets the error information. This function
|
||||
* may be useful if you want to set a custom error message rather than letting
|
||||
* it automatically formatted.
|
||||
*/
|
||||
HAWK_EXPORT void hawk_seterrinf (
|
||||
hawk_t* hawk, /**< hawk */
|
||||
const hawk_errinf_t* errinf /**< error information */
|
||||
);
|
||||
|
||||
|
||||
HAWK_EXPORT void hawk_seterror (
|
||||
hawk_t* hawk,
|
||||
const hawk_loc_t* errloc,
|
||||
@ -1709,16 +1702,6 @@ HAWK_EXPORT void hawk_seterror (
|
||||
const hawk_oocs_t* errarg
|
||||
);
|
||||
|
||||
/**
|
||||
* The hawk_geterror() function gets error information via parameters.
|
||||
*/
|
||||
HAWK_EXPORT void hawk_geterror (
|
||||
hawk_t* hawk, /**< hawk */
|
||||
hawk_errnum_t* errnum, /**< error number */
|
||||
const hawk_ooch_t** errmsg, /**< error message */
|
||||
hawk_loc_t* errloc /**< error location */
|
||||
);
|
||||
|
||||
/**
|
||||
* The hawk_getopt() function gets the value of an option
|
||||
* specified by \a id into the buffer pointed to by \a value.
|
||||
@ -2578,50 +2561,23 @@ HAWK_EXPORT hawk_htb_t* hawk_rtx_getnvmap (
|
||||
* occurred during runtime. The
|
||||
* \return error location
|
||||
*/
|
||||
#if defined(HAWK_HAVE_INLINE)
|
||||
static HAWK_INLINE hawk_errnum_t hawk_rtx_geterrnum (hawk_rtx_t* rtx) { return ((hawk_rtx_alt_t*)rtx)->_gem.errnum; }
|
||||
static HAWK_INLINE const hawk_loc_t* hawk_rtx_geterrloc (hawk_rtx_t* rtx) { return hawk_gem_geterrloc(hawk_rtx_getgem(rtx)); }
|
||||
#else
|
||||
# define hawk_rtx_geterrnum(rtx) (((hawk_rtx_alt_t*)(rtx))->_gem.errnum)
|
||||
# define hawk_rtx_geterrloc(rtx) (hawk_gem_geterrloc(hawk_rtx_getgem(rtx)))
|
||||
#endif
|
||||
|
||||
/**
|
||||
* The hawk_rtx_geterrbmsg() function gets the string describing the last
|
||||
* error occurred during runtime.
|
||||
* \return error message
|
||||
*/
|
||||
HAWK_EXPORT const hawk_bch_t* hawk_rtx_geterrbmsg (
|
||||
hawk_rtx_t* rtx /**< runtime context */
|
||||
);
|
||||
|
||||
/**
|
||||
* The hawk_rtx_geterrumsg() function gets the string describing the last
|
||||
* error occurred during runtime.
|
||||
* \return error message
|
||||
*/
|
||||
HAWK_EXPORT const hawk_uch_t* hawk_rtx_geterrumsg (
|
||||
hawk_rtx_t* rtx /**< runtime context */
|
||||
);
|
||||
|
||||
#if defined(HAWK_OOCH_IS_BCH)
|
||||
# define hawk_rtx_geterrmsg hawk_rtx_geterrbmsg
|
||||
#else
|
||||
# define hawk_rtx_geterrmsg hawk_rtx_geterrumsg
|
||||
#endif
|
||||
|
||||
HAWK_EXPORT const hawk_ooch_t* hawk_rtx_backuperrmsg (
|
||||
hawk_rtx_t* rtx /**< runtime context */
|
||||
);
|
||||
|
||||
/**
|
||||
* The hawk_rtx_geterrinf() function copies error information into memory
|
||||
* pointed to by \a errinf from a runtime context \a rtx.
|
||||
*/
|
||||
HAWK_EXPORT void hawk_rtx_geterrinf (
|
||||
hawk_rtx_t* rtx, /**< runtime context */
|
||||
hawk_errinf_t* errinf /**< error information */
|
||||
);
|
||||
|
||||
/**
|
||||
* The hawk_rtx_geterror() function retrieves error information from a
|
||||
@ -2629,33 +2585,44 @@ HAWK_EXPORT void hawk_rtx_geterrinf (
|
||||
* to by \a errnum; the error message pointer into memory pointed to by
|
||||
* \a errmsg; the error line into memory pointed to by \a errlin.
|
||||
*/
|
||||
HAWK_EXPORT void hawk_rtx_geterror (
|
||||
hawk_rtx_t* rtx, /**< runtime context */
|
||||
hawk_errnum_t* errnum, /**< error number */
|
||||
const hawk_ooch_t** errmsg, /**< error message */
|
||||
hawk_loc_t* errloc /**< error location */
|
||||
);
|
||||
|
||||
#if defined(HAWK_HAVE_INLINE)
|
||||
static HAWK_INLINE void hawk_rtx_seterrnum (hawk_rtx_t* rtx, const hawk_loc_t* errloc, hawk_errnum_t errnum) { hawk_gem_seterrnum (hawk_rtx_getgem(rtx), errloc, errnum); }
|
||||
static HAWK_INLINE hawk_errnum_t hawk_rtx_geterrnum (hawk_rtx_t* rtx) { return ((hawk_rtx_alt_t*)rtx)->_gem.errnum; }
|
||||
static HAWK_INLINE const hawk_loc_t* hawk_rtx_geterrloc (hawk_rtx_t* rtx) { return hawk_gem_geterrloc(hawk_rtx_getgem(rtx)); }
|
||||
static HAWK_INLINE const hawk_bch_t* hawk_rtx_geterrbmsg (hawk_rtx_t* rtx) { return hawk_gem_geterrbmsg(hawk_rtx_getgem(rtx)); }
|
||||
static HAWK_INLINE const hawk_uch_t* hawk_rtx_geterrumsg (hawk_rtx_t* rtx) { return hawk_gem_geterrumsg(hawk_rtx_getgem(rtx)); }
|
||||
static HAWK_INLINE void hawk_rtx_geterrinf (hawk_rtx_t* rtx, hawk_errinf_t* errinf) { return hawk_gem_geterrinf(hawk_rtx_getgem(rtx), errinf); }
|
||||
static HAWK_INLINE void hawk_rtx_geterror (hawk_rtx_t* rtx, hawk_errnum_t* errnum, const hawk_ooch_t** errmsg, hawk_loc_t* errloc) { return hawk_gem_geterror(hawk_rtx_getgem(rtx), errnum, errmsg, errloc); }
|
||||
#else
|
||||
#define hawk_rtx_seterrnum(rtx, errloc, errnum) hawk_gem_seterrnum(hawk_rtx_getgem(rtx), errloc, errnum)
|
||||
#define hawk_rtx_geterrnum(rtx) (((hawk_rtx_alt_t*)(rtx))->_gem.errnum)
|
||||
#define hawk_rtx_geterrloc(rtx) (hawk_gem_geterrloc(hawk_rtx_getgem(rtx)))
|
||||
#define hawk_rtx_geterrbmsg(rtx) (hawk_gem_geterrbmsg(hawk_rtx_getgem(rtx)))
|
||||
#define hawk_rtx_geterrumsg(rtx) (hawk_gem_geterrumsg(hawk_rtx_getgem(rtx)))
|
||||
#define hawk_rtx_geterrinf(rtx, errinf) (hawk_gem_geterrinf(hawk_rtx_getgem(rtx), errinf))
|
||||
#define hawk_rtx_geterror(rtx, errnum, errmsg, errloc) (hawk_gem_geterror(hawk_rtx_getgem(rtx), errnum, errmsg, errloc))
|
||||
#endif
|
||||
|
||||
#if defined(HAWK_OOCH_IS_BCH)
|
||||
# define hawk_rtx_geterrmsg hawk_rtx_geterrbmsg
|
||||
#else
|
||||
# define hawk_rtx_geterrmsg hawk_rtx_geterrumsg
|
||||
#endif
|
||||
|
||||
/**
|
||||
* The hawk_rtx_seterrinf() function sets error information.
|
||||
*/
|
||||
HAWK_EXPORT void hawk_rtx_seterrinf (
|
||||
hawk_rtx_t* rtx, /**< runtime context */
|
||||
const hawk_errinf_t* errinf /**< error information */
|
||||
);
|
||||
#if defined(HAWK_HAVE_INLINE)
|
||||
static HAWK_INLINE void hawk_rtx_seterrnum (hawk_rtx_t* rtx, const hawk_loc_t* errloc, hawk_errnum_t errnum) { hawk_gem_seterrnum (hawk_rtx_getgem(rtx), errloc, errnum); }
|
||||
static HAWK_INLINE void hawk_rtx_seterrinf (hawk_rtx_t* rtx, const hawk_errinf_t* errinf) { hawk_gem_seterrinf (hawk_rtx_getgem(rtx), errinf); }
|
||||
static HAWK_INLINE void hawk_rtx_seterror (hawk_rtx_t* rtx, const hawk_loc_t* errloc, hawk_errnum_t errnum, const hawk_oocs_t* errarg) { hawk_gem_seterror(hawk_rtx_getgem(rtx), errloc, errnum, errarg); }
|
||||
static HAWK_INLINE const hawk_ooch_t* hawk_rtx_backuperrmsg (hawk_rtx_t* rtx) { return hawk_gem_backuperrmsg(hawk_rtx_getgem(rtx)); }
|
||||
#else
|
||||
#define hawk_rtx_seterrnum(rtx, errloc, errnum) hawk_gem_seterrnum(hawk_rtx_getgem(rtx), errloc, errnum)
|
||||
#define hawk_rtx_seterrinf(rtx, errinf) hawk_gem_seterrinf(hawk_rtx_getgem(rtx), errinf)
|
||||
#define hawk_rtx_seterror(rtx, errloc, errnum, errarg) hawk_gem_seterror(hawk_rtx_getgem(rtx), errloc, errnum, errarg)
|
||||
#define hawk_rtx_backuperrmsg(rtx) hawk_gem_backuperrmsg(hawk_rtx_getgem(rtx))
|
||||
#endif
|
||||
|
||||
HAWK_EXPORT void hawk_rtx_seterror (
|
||||
hawk_rtx_t* rtx,
|
||||
const hawk_loc_t* errloc,
|
||||
hawk_errnum_t errnum,
|
||||
const hawk_oocs_t* errarg
|
||||
);
|
||||
|
||||
HAWK_EXPORT void hawk_rtx_seterrbfmt (
|
||||
hawk_rtx_t* rtx,
|
||||
|
248
hawk/lib/sed.c
248
hawk/lib/sed.c
@ -37,9 +37,6 @@ static int emit_output (hawk_sed_t* sed, int skipline);
|
||||
|
||||
#define EMPTY_REX ((void*)1)
|
||||
|
||||
#define ERRNUM(sed) ((sed)->_gem.errnum)
|
||||
#define CLRERR(sed) hawk_sed_seterrnum(sed, HAWK_NULL, HAWK_ENOERR)
|
||||
|
||||
#define ADJERR_LOC(sed,l) do { (sed)->_gem.errloc = *(l); } while (0)
|
||||
|
||||
#define SETERR1(sed,num,argp,argl,loc) \
|
||||
@ -148,6 +145,22 @@ void hawk_sed_fini (hawk_sed_t* sed)
|
||||
hawk_ooecs_fini (&sed->tmp.rex);
|
||||
}
|
||||
|
||||
void hawk_sed_seterrbfmt (hawk_sed_t* sed, const hawk_loc_t* errloc, hawk_errnum_t errnum, const hawk_bch_t* fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start (ap, fmt);
|
||||
hawk_gem_seterrbvfmt (hawk_sed_getgem(sed), errloc, errnum, fmt, ap);
|
||||
va_end (ap);
|
||||
}
|
||||
|
||||
void hawk_sed_seterrufmt (hawk_sed_t* sed, const hawk_loc_t* errloc, hawk_errnum_t errnum, const hawk_uch_t* fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start (ap, fmt);
|
||||
hawk_gem_seterruvfmt (hawk_sed_getgem(sed), errloc, errnum, fmt, ap);
|
||||
va_end (ap);
|
||||
}
|
||||
|
||||
int hawk_sed_setopt (hawk_sed_t* sed, hawk_sed_opt_t id, const void* value)
|
||||
{
|
||||
switch (id)
|
||||
@ -309,14 +322,8 @@ static int open_script_stream (hawk_sed_t* sed)
|
||||
{
|
||||
hawk_ooi_t n;
|
||||
|
||||
CLRERR (sed);
|
||||
n = sed->src.fun (sed, HAWK_SED_IO_OPEN, &sed->src.arg, HAWK_NULL, 0);
|
||||
if (n <= -1)
|
||||
{
|
||||
if (ERRNUM(sed) == HAWK_ENOERR)
|
||||
hawk_sed_seterrnum (sed, HAWK_NULL, HAWK_EIOIMPL);
|
||||
return -1;
|
||||
}
|
||||
n = sed->src.fun(sed, HAWK_SED_IO_OPEN, &sed->src.arg, HAWK_NULL, 0);
|
||||
if (n <= -1) return -1;
|
||||
|
||||
sed->src.cur = sed->src.buf;
|
||||
sed->src.end = sed->src.buf;
|
||||
@ -328,37 +335,20 @@ static int open_script_stream (hawk_sed_t* sed)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int close_script_stream (hawk_sed_t* sed)
|
||||
static HAWK_INLINE int close_script_stream (hawk_sed_t* sed)
|
||||
{
|
||||
hawk_ooi_t n;
|
||||
|
||||
CLRERR (sed);
|
||||
n = sed->src.fun (sed, HAWK_SED_IO_CLOSE, &sed->src.arg, HAWK_NULL, 0);
|
||||
if (n <= -1)
|
||||
{
|
||||
if (ERRNUM(sed) == HAWK_ENOERR)
|
||||
hawk_sed_seterrnum (sed, HAWK_NULL, HAWK_EIOIMPL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return sed->src.fun(sed, HAWK_SED_IO_CLOSE, &sed->src.arg, HAWK_NULL, 0);
|
||||
}
|
||||
|
||||
static int read_script_stream (hawk_sed_t* sed)
|
||||
{
|
||||
hawk_ooi_t n;
|
||||
|
||||
CLRERR (sed);
|
||||
n = sed->src.fun (
|
||||
sed, HAWK_SED_IO_READ, &sed->src.arg,
|
||||
sed->src.buf, HAWK_COUNTOF(sed->src.buf)
|
||||
);
|
||||
if (n <= -1)
|
||||
{
|
||||
if (ERRNUM(sed) == HAWK_ENOERR)
|
||||
hawk_sed_seterrnum (sed, HAWK_NULL, HAWK_EIOIMPL);
|
||||
return -1; /* error */
|
||||
}
|
||||
if (n <= -1) return -1; /* error */
|
||||
|
||||
if (n == 0)
|
||||
{
|
||||
@ -399,9 +389,7 @@ static int getnextsc (hawk_sed_t* sed, hawk_ooci_t* c)
|
||||
if (read_script_stream (sed) <= -1) return -1;
|
||||
}
|
||||
|
||||
sed->src.cc =
|
||||
(sed->src.cur < sed->src.end)?
|
||||
(*sed->src.cur++): HAWK_OOCI_EOF;
|
||||
sed->src.cc = (sed->src.cur < sed->src.end)? (*sed->src.cur++): HAWK_OOCI_EOF;
|
||||
|
||||
*c = sed->src.cc;
|
||||
return 0;
|
||||
@ -1194,7 +1182,7 @@ static int get_subst (hawk_sed_t* sed, hawk_sed_cmd_t* cmd)
|
||||
c = CURSC (sed);
|
||||
CHECK_CMDIC (sed, cmd, c, goto oops);
|
||||
|
||||
delim = c;
|
||||
delim = c;
|
||||
if (delim == HAWK_T('\\'))
|
||||
{
|
||||
/* backspace is an illegal delimiter */
|
||||
@ -1608,9 +1596,10 @@ static int get_command (hawk_sed_t* sed, hawk_sed_cmd_t* cmd)
|
||||
{
|
||||
hawk_ooci_t c;
|
||||
|
||||
c = CURSC (sed);
|
||||
c = CURSC(sed);
|
||||
cmd->lid = sed->src.cid? ((const hawk_ooch_t*)(sed->src.cid + 1)): HAWK_NULL;
|
||||
cmd->loc = sed->src.loc;
|
||||
|
||||
switch (c)
|
||||
{
|
||||
default:
|
||||
@ -1623,7 +1612,7 @@ static int get_command (hawk_sed_t* sed, hawk_sed_cmd_t* cmd)
|
||||
case HAWK_OOCI_EOF:
|
||||
case HAWK_T('\n'):
|
||||
hawk_sed_seterrnum (sed, &sed->src.loc, HAWK_SED_ECMDMS);
|
||||
return -1;
|
||||
return -1;
|
||||
|
||||
case HAWK_T(':'):
|
||||
if (cmd->a1.type != HAWK_SED_ADR_NONE)
|
||||
@ -1731,7 +1720,7 @@ static int get_command (hawk_sed_t* sed, hawk_sed_cmd_t* cmd)
|
||||
hawk_sed_seterrnum (sed, &sed->src.loc, HAWK_SED_EBSEXP);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
NXTSC (sed, c, -1);
|
||||
while (IS_SPACE(c)) NXTSC (sed, c, -1);
|
||||
|
||||
@ -1752,7 +1741,7 @@ static int get_command (hawk_sed_t* sed, hawk_sed_cmd_t* cmd)
|
||||
|
||||
sameline_ok:
|
||||
/* get_text() starts from the next line */
|
||||
if (get_text (sed, cmd) <= -1) return -1;
|
||||
if (get_text(sed, cmd) <= -1) return -1;
|
||||
|
||||
break;
|
||||
}
|
||||
@ -1768,31 +1757,27 @@ static int get_command (hawk_sed_t* sed, hawk_sed_cmd_t* cmd)
|
||||
|
||||
case HAWK_T('d'):
|
||||
case HAWK_T('D'):
|
||||
|
||||
case HAWK_T('p'):
|
||||
case HAWK_T('P'):
|
||||
case HAWK_T('l'):
|
||||
|
||||
case HAWK_T('h'):
|
||||
case HAWK_T('H'):
|
||||
case HAWK_T('g'):
|
||||
case HAWK_T('G'):
|
||||
case HAWK_T('x'):
|
||||
|
||||
case HAWK_T('n'):
|
||||
case HAWK_T('N'):
|
||||
|
||||
case HAWK_T('N'):
|
||||
case HAWK_T('z'):
|
||||
cmd->type = c;
|
||||
NXTSC (sed, c, -1);
|
||||
if (terminate_command (sed) <= -1) return -1;
|
||||
if (terminate_command(sed) <= -1) return -1;
|
||||
break;
|
||||
|
||||
case HAWK_T('b'):
|
||||
case HAWK_T('t'):
|
||||
cmd->type = c;
|
||||
NXTSC (sed, c, -1);
|
||||
if (get_branch_target (sed, cmd) <= -1) return -1;
|
||||
if (get_branch_target(sed, cmd) <= -1) return -1;
|
||||
break;
|
||||
|
||||
case HAWK_T('r'):
|
||||
@ -1801,25 +1786,25 @@ static int get_command (hawk_sed_t* sed, hawk_sed_cmd_t* cmd)
|
||||
case HAWK_T('W'):
|
||||
cmd->type = c;
|
||||
NXTSC (sed, c, -1);
|
||||
if (get_file (sed, &cmd->u.file) <= -1) return -1;
|
||||
if (get_file(sed, &cmd->u.file) <= -1) return -1;
|
||||
break;
|
||||
|
||||
case HAWK_T('s'):
|
||||
cmd->type = c;
|
||||
NXTSC (sed, c, -1);
|
||||
if (get_subst (sed, cmd) <= -1) return -1;
|
||||
if (get_subst(sed, cmd) <= -1) return -1;
|
||||
break;
|
||||
|
||||
case HAWK_T('y'):
|
||||
cmd->type = c;
|
||||
NXTSC (sed, c, -1);
|
||||
if (get_transet (sed, cmd) <= -1) return -1;
|
||||
if (get_transet(sed, cmd) <= -1) return -1;
|
||||
break;
|
||||
|
||||
case HAWK_T('C'):
|
||||
cmd->type = c;
|
||||
NXTSC (sed, c, -1);
|
||||
if (get_cut (sed, cmd) <= -1) return -1;
|
||||
if (get_cut(sed, cmd) <= -1) return -1;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1835,7 +1820,7 @@ int hawk_sed_comp (hawk_sed_t* sed, hawk_sed_io_impl_t inf)
|
||||
if (inf == HAWK_NULL)
|
||||
{
|
||||
hawk_sed_seterrnum (sed, HAWK_NULL, HAWK_EINVAL);
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* free all the commands previously compiled */
|
||||
@ -1998,11 +1983,12 @@ int hawk_sed_comp (hawk_sed_t* sed, hawk_sed_io_impl_t inf)
|
||||
|
||||
while (IS_SPACE(c)) NXTSC_GOTO (sed, c, oops);
|
||||
}
|
||||
|
||||
n = get_command (sed, cmd);
|
||||
|
||||
|
||||
n = get_command(sed, cmd);
|
||||
if (n <= -1) goto oops;
|
||||
|
||||
c = CURSC (sed);
|
||||
c = CURSC(sed);
|
||||
|
||||
/* cmd's end of life */
|
||||
cmd = HAWK_NULL;
|
||||
@ -2013,7 +1999,7 @@ int hawk_sed_comp (hawk_sed_t* sed, hawk_sed_io_impl_t inf)
|
||||
{
|
||||
/* the number of commands in the block has
|
||||
* reaches the maximum. add a new command block */
|
||||
if (add_command_block (sed) <= -1) goto oops;
|
||||
if (add_command_block(sed) <= -1) goto oops;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2041,24 +2027,17 @@ static int read_char (hawk_sed_t* sed, hawk_ooch_t* c)
|
||||
{
|
||||
if (sed->e.in.pos >= sed->e.in.len)
|
||||
{
|
||||
CLRERR (sed);
|
||||
n = sed->e.in.fun (
|
||||
sed, HAWK_SED_IO_READ, &sed->e.in.arg,
|
||||
sed->e.in.buf, HAWK_COUNTOF(sed->e.in.buf)
|
||||
);
|
||||
if (n <= -1)
|
||||
{
|
||||
if (ERRNUM(sed) == HAWK_ENOERR)
|
||||
hawk_sed_seterrnum (sed, HAWK_NULL, HAWK_EIOIMPL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (n <= -1) return -1;
|
||||
if (n == 0) return 0; /* end of file */
|
||||
|
||||
|
||||
sed->e.in.len = n;
|
||||
sed->e.in.pos = 0;
|
||||
}
|
||||
|
||||
|
||||
*c = sed->e.in.buf[sed->e.in.pos++];
|
||||
return 1;
|
||||
}
|
||||
@ -2072,7 +2051,7 @@ static int read_char (hawk_sed_t* sed, hawk_ooch_t* c)
|
||||
{
|
||||
HAWK_ASSERT (sed->e.in.xbuf_len == -1);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int read_line (hawk_sed_t* sed, int append)
|
||||
@ -2125,26 +2104,12 @@ static int flush (hawk_sed_t* sed)
|
||||
|
||||
while (sed->e.out.len > 0)
|
||||
{
|
||||
CLRERR (sed);
|
||||
|
||||
n = sed->e.out.fun (
|
||||
sed, HAWK_SED_IO_WRITE, &sed->e.out.arg,
|
||||
&sed->e.out.buf[pos], sed->e.out.len);
|
||||
|
||||
if (n <= -1)
|
||||
{
|
||||
if (ERRNUM(sed) == HAWK_ENOERR)
|
||||
hawk_sed_seterrnum (sed, HAWK_NULL, HAWK_EIOIMPL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (n == 0)
|
||||
{
|
||||
/* reached the end of file - this is also an error */
|
||||
if (ERRNUM(sed) == HAWK_ENOERR)
|
||||
hawk_sed_seterrnum (sed, HAWK_NULL, HAWK_EIOIMPL);
|
||||
return -1;
|
||||
}
|
||||
if (n <= -1) return -1;
|
||||
if (n == 0) return -1; /* reached the end of file - this is also an error */
|
||||
|
||||
pos += n;
|
||||
sed->e.out.len -= n;
|
||||
@ -2356,31 +2321,23 @@ static int write_str_to_file (
|
||||
ap = HAWK_MAP_VPTR(pair);
|
||||
if (ap->handle == HAWK_NULL)
|
||||
{
|
||||
CLRERR (sed);
|
||||
ap->path = path;
|
||||
n = sed->e.out.fun(sed, HAWK_SED_IO_OPEN, ap, HAWK_NULL, 0);
|
||||
if (n <= -1)
|
||||
{
|
||||
if (ERRNUM(sed) == HAWK_ENOERR)
|
||||
SETERR1 (sed, HAWK_SED_EIOFIL, path, plen, &cmd->loc);
|
||||
else
|
||||
ADJERR_LOC (sed, &cmd->loc);
|
||||
ADJERR_LOC (sed, &cmd->loc);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
while (len > 0)
|
||||
{
|
||||
CLRERR (sed);
|
||||
n = sed->e.out.fun(sed, HAWK_SED_IO_WRITE, ap, (hawk_ooch_t*)str, len);
|
||||
if (n <= -1)
|
||||
{
|
||||
sed->e.out.fun (sed, HAWK_SED_IO_CLOSE, ap, HAWK_NULL, 0);
|
||||
ap->handle = HAWK_NULL;
|
||||
if (ERRNUM(sed) == HAWK_ENOERR)
|
||||
SETERR1 (sed, HAWK_SED_EIOFIL, path, plen, &cmd->loc);
|
||||
else
|
||||
ADJERR_LOC (sed, &cmd->loc);
|
||||
ADJERR_LOC (sed, &cmd->loc);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -2412,28 +2369,21 @@ static int write_file (hawk_sed_t* sed, hawk_sed_cmd_t* cmd, int first_line)
|
||||
|
||||
arg.handle = HAWK_NULL;
|
||||
arg.path = cmd->u.file.ptr;
|
||||
CLRERR (sed);
|
||||
n = sed->e.in.fun(sed, HAWK_SED_IO_OPEN, &arg, HAWK_NULL, 0);
|
||||
if (n <= -1)
|
||||
{
|
||||
/*if (ERRNUM(sed) != HAWK_ENOERR)
|
||||
* hawk_sed_seterrnum (sed, &cmd->loc, HAWK_EIOIMPL);
|
||||
*return -1;*/
|
||||
/*return -1;*/
|
||||
/* it is ok if it is not able to open a file */
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
CLRERR (sed);
|
||||
n = sed->e.in.fun(sed, HAWK_SED_IO_READ, &arg, buf, HAWK_COUNTOF(buf));
|
||||
if (n <= -1)
|
||||
{
|
||||
sed->e.in.fun(sed, HAWK_SED_IO_CLOSE, &arg, HAWK_NULL, 0);
|
||||
if (ERRNUM(sed) == HAWK_ENOERR)
|
||||
SETERR1 (sed, HAWK_SED_EIOFIL, cmd->u.file.ptr, cmd->u.file.len, &cmd->loc);
|
||||
else
|
||||
ADJERR_LOC (sed, &cmd->loc);
|
||||
ADJERR_LOC (sed, &cmd->loc);
|
||||
return -1;
|
||||
}
|
||||
if (n == 0) break;
|
||||
@ -3706,25 +3656,19 @@ int hawk_sed_exec (hawk_sed_t* sed, hawk_sed_io_impl_t inf, hawk_sed_io_impl_t o
|
||||
return -1;
|
||||
}
|
||||
|
||||
CLRERR (sed);
|
||||
sed->e.in.arg.path = HAWK_NULL;
|
||||
n = sed->e.in.fun(sed, HAWK_SED_IO_OPEN, &sed->e.in.arg, HAWK_NULL, 0);
|
||||
if (n <= -1)
|
||||
{
|
||||
ret = -1;
|
||||
if (ERRNUM(sed) == HAWK_ENOERR)
|
||||
hawk_sed_seterrnum (sed, HAWK_NULL, HAWK_EIOIMPL);
|
||||
goto done3;
|
||||
}
|
||||
|
||||
CLRERR (sed);
|
||||
|
||||
sed->e.out.arg.path = HAWK_NULL;
|
||||
n = sed->e.out.fun(sed, HAWK_SED_IO_OPEN, &sed->e.out.arg, HAWK_NULL, 0);
|
||||
if (n <= -1)
|
||||
{
|
||||
ret = -1;
|
||||
if (ERRNUM(sed) == HAWK_ENOERR)
|
||||
hawk_sed_seterrnum (sed, HAWK_NULL, HAWK_EIOIMPL);
|
||||
goto done2;
|
||||
}
|
||||
|
||||
@ -3822,6 +3766,7 @@ const hawk_ooch_t* hawk_sed_getcompid (hawk_sed_t* sed)
|
||||
return sed->src.cid? ((const hawk_ooch_t*)(sed->src.cid + 1)): HAWK_NULL;
|
||||
}
|
||||
|
||||
#if 0
|
||||
const hawk_ooch_t* hawk_sed_setcompid (hawk_sed_t* sed, const hawk_ooch_t* id)
|
||||
{
|
||||
hawk_sed_cid_t* cid;
|
||||
@ -3853,6 +3798,93 @@ const hawk_ooch_t* hawk_sed_setcompid (hawk_sed_t* sed, const hawk_ooch_t* id)
|
||||
sed->src.cid = cid;
|
||||
return (const hawk_ooch_t*)(cid + 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
const hawk_ooch_t* hawk_sed_setcompidwithbcstr (hawk_sed_t* sed, const hawk_bch_t* id)
|
||||
{
|
||||
hawk_sed_cid_t* cid;
|
||||
hawk_oow_t len;
|
||||
#if !defined(HAWK_OOCH_IS_BCH)
|
||||
hawk_oow_t tmplen;
|
||||
#endif
|
||||
|
||||
if (sed->src.cid == (hawk_sed_cid_t*)&sed->src.unknown_cid)
|
||||
{
|
||||
/* if an error has occurred in a previously, you can't set it
|
||||
* any more */
|
||||
return (const hawk_ooch_t*)(sed->src.cid + 1);
|
||||
}
|
||||
|
||||
if (id == HAWK_NULL) id = HAWK_BT("");
|
||||
|
||||
#if defined(HAWK_OOCH_IS_BCH)
|
||||
len = hawk_count_oocstr(id);
|
||||
#else
|
||||
hawk_conv_bcstr_to_ucstr_with_cmgr(id, &tmplen, HAWK_NULL, &len, hawk_sed_getcmgr(sed), 1);
|
||||
#endif
|
||||
cid = hawk_sed_allocmem(sed, HAWK_SIZEOF(*cid) + ((len + 1) * HAWK_SIZEOF(*id)));
|
||||
if (cid == HAWK_NULL)
|
||||
{
|
||||
/* mark that an error has occurred */
|
||||
sed->src.unknown_cid.buf[0] = HAWK_T('\0');
|
||||
cid = (hawk_sed_cid_t*)&sed->src.unknown_cid;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined(HAWK_OOCH_IS_BCH)
|
||||
hawk_copy_oocstr_unlimited ((hawk_ooch_t*)(cid + 1), id);
|
||||
#else
|
||||
hawk_conv_bcstr_to_ucstr_with_cmgr(id, &tmplen, (hawk_ooch_t*)(cid + 1), &len, hawk_sed_getcmgr(sed), 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
cid->next = sed->src.cid;
|
||||
sed->src.cid = cid;
|
||||
return (const hawk_ooch_t*)(cid + 1);
|
||||
}
|
||||
|
||||
const hawk_ooch_t* hawk_sed_setcompidwithucstr (hawk_sed_t* sed, const hawk_uch_t* id)
|
||||
{
|
||||
hawk_sed_cid_t* cid;
|
||||
hawk_oow_t len;
|
||||
#if defined(HAWK_OOCH_IS_BCH)
|
||||
hawk_oow_t tmplen;
|
||||
#endif
|
||||
|
||||
if (sed->src.cid == (hawk_sed_cid_t*)&sed->src.unknown_cid)
|
||||
{
|
||||
/* if an error has occurred in a previously, you can't set it
|
||||
* any more */
|
||||
return (const hawk_ooch_t*)(sed->src.cid + 1);
|
||||
}
|
||||
|
||||
if (id == HAWK_NULL) id = HAWK_UT("");
|
||||
|
||||
#if defined(HAWK_OOCH_IS_BCH)
|
||||
hawk_conv_ucstr_to_bcstr_with_cmgr(id, &tmplen, HAWK_NULL, &len, hawk_sed_getcmgr(sed));
|
||||
#else
|
||||
len = hawk_count_oocstr(id);
|
||||
#endif
|
||||
cid = hawk_sed_allocmem(sed, HAWK_SIZEOF(*cid) + ((len + 1) * HAWK_SIZEOF(hawk_ooch_t)));
|
||||
if (cid == HAWK_NULL)
|
||||
{
|
||||
/* mark that an error has occurred */
|
||||
sed->src.unknown_cid.buf[0] = HAWK_T('\0');
|
||||
cid = (hawk_sed_cid_t*)&sed->src.unknown_cid;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined(HAWK_OOCH_IS_BCH)
|
||||
hawk_conv_ucstr_to_bcstr_with_cmgr(id, &tmplen, (hawk_ooch_t*)(cid + 1), &len, hawk_sed_getcmgr(sed));
|
||||
#else
|
||||
hawk_copy_oocstr_unlimited ((hawk_ooch_t*)(cid + 1), id);
|
||||
#endif
|
||||
}
|
||||
|
||||
cid->next = sed->src.cid;
|
||||
sed->src.cid = cid;
|
||||
return (const hawk_ooch_t*)(cid + 1);
|
||||
}
|
||||
|
||||
hawk_oow_t hawk_sed_getlinenum (hawk_sed_t* sed)
|
||||
{
|
||||
|
@ -33,14 +33,18 @@ struct xtn_in_t
|
||||
{
|
||||
hawk_sed_iostd_t* ptr;
|
||||
hawk_sed_iostd_t* cur;
|
||||
hawk_oow_t mempos;
|
||||
hawk_oow_t mempos;
|
||||
};
|
||||
|
||||
typedef struct xtn_out_t xtn_out_t;
|
||||
struct xtn_out_t
|
||||
{
|
||||
hawk_sed_iostd_t* ptr;
|
||||
hawk_ooecs_t* memstr;
|
||||
struct
|
||||
{
|
||||
hawk_becs_t* be;
|
||||
hawk_uecs_t* ue;
|
||||
} memstr;
|
||||
};
|
||||
|
||||
typedef struct xtn_t xtn_t;
|
||||
@ -133,7 +137,7 @@ static int verify_iostd_in (hawk_sed_t* sed, hawk_sed_iostd_t in[])
|
||||
{
|
||||
/* if 'in' is specified, it must contains at least one
|
||||
* valid entry */
|
||||
hawk_sed_seterrnum (sed, HAWK_NULL, HAWK_EINVAL);
|
||||
hawk_sed_seterrbfmt (sed, HAWK_NULL, HAWK_EINVAL, "no input handler provided");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -142,10 +146,12 @@ static int verify_iostd_in (hawk_sed_t* sed, hawk_sed_iostd_t in[])
|
||||
if (in[i].type != HAWK_SED_IOSTD_FILE &&
|
||||
in[i].type != HAWK_SED_IOSTD_FILEB &&
|
||||
in[i].type != HAWK_SED_IOSTD_FILEU &&
|
||||
in[i].type != HAWK_SED_IOSTD_STR &&
|
||||
in[i].type != HAWK_SED_IOSTD_OOCS &&
|
||||
in[i].type != HAWK_SED_IOSTD_BCS &&
|
||||
in[i].type != HAWK_SED_IOSTD_UCS &&
|
||||
in[i].type != HAWK_SED_IOSTD_SIO)
|
||||
{
|
||||
hawk_sed_seterrnum (sed, HAWK_NULL, HAWK_EINVAL);
|
||||
hawk_sed_seterrbfmt (sed, HAWK_NULL, HAWK_EINVAL, "unsupported input type provided - handler %d type %d", i, in[i].type);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -158,12 +164,10 @@ static hawk_sio_t* open_sio_file (hawk_sed_t* sed, const hawk_ooch_t* file, int
|
||||
hawk_sio_t* sio;
|
||||
|
||||
sio = hawk_sio_open(hawk_sed_getgem(sed), 0, file, flags);
|
||||
if (sio == HAWK_NULL)
|
||||
if (sio == HAWK_NULL)
|
||||
{
|
||||
hawk_oocs_t ea;
|
||||
ea.ptr = (hawk_ooch_t*)file;
|
||||
ea.len = hawk_count_oocstr(file);
|
||||
hawk_sed_seterror (sed, HAWK_NULL, HAWK_SED_EIOFIL, &ea);
|
||||
const hawk_ooch_t* bem = hawk_sed_backuperrmsg(sed);
|
||||
hawk_sed_seterrbfmt (sed, HAWK_NULL, HAWK_SED_EIOFIL, "unable to open %js - %js", file, bem);
|
||||
}
|
||||
return sio;
|
||||
}
|
||||
@ -264,6 +268,41 @@ static hawk_sio_t* open_sio_std (hawk_sed_t* sed, hawk_sio_std_t std, int flags)
|
||||
return sio;
|
||||
}
|
||||
|
||||
static void set_eiofil_for_iostd (hawk_sed_t* sed, hawk_sed_iostd_t* io)
|
||||
{
|
||||
HAWK_ASSERT (io->type == HAWK_SED_IOSTD_FILE || io->type == HAWK_SED_IOSTD_FILEB || io->type == HAWK_SED_IOSTD_FILEU);
|
||||
|
||||
if (io->u.file.path) /* file, fileb, fileu are union members. checking file.path regardless of io->type must be safe */
|
||||
{
|
||||
switch (io->type)
|
||||
{
|
||||
#if defined(HAWK_OOCH_IS_BCH)
|
||||
case HAWK_SED_IOSTD_FILE:
|
||||
#endif
|
||||
case HAWK_SED_IOSTD_FILEB:
|
||||
hawk_sed_seterrbfmt (sed, HAWK_NULL, HAWK_SED_EIOFIL, "I/O error with file '%hs'", io->u.fileb.path);
|
||||
break;
|
||||
|
||||
#if defined(HAWK_OOCH_IS_UCH)
|
||||
case HAWK_SED_IOSTD_FILE:
|
||||
#endif
|
||||
case HAWK_SED_IOSTD_FILEU:
|
||||
hawk_sed_seterrbfmt (sed, HAWK_NULL, HAWK_SED_EIOFIL, "I/O error with file '%ls'", io->u.fileu.path);
|
||||
break;
|
||||
|
||||
default:
|
||||
HAWK_ASSERT (!"should never happen - unknown file I/O type");
|
||||
hawk_sed_seterrnum (sed, HAWK_NULL, HAWK_EINVAL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
hawk_sed_seterrbfmt (sed, HAWK_NULL, HAWK_SED_EIOFIL, "I/O error with file '%js'", &sio_std_names[HAWK_SIO_STDIN]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void close_main_stream (hawk_sed_t* sed, hawk_sed_io_arg_t* arg, hawk_sed_iostd_t* io)
|
||||
{
|
||||
switch (io->type)
|
||||
@ -274,10 +313,11 @@ static void close_main_stream (hawk_sed_t* sed, hawk_sed_io_arg_t* arg, hawk_sed
|
||||
hawk_sio_close (arg->handle);
|
||||
break;
|
||||
|
||||
case HAWK_SED_IOSTD_STR:
|
||||
/* nothing to do for input.
|
||||
* i don't close xtn->e.out.memstr intentionally.
|
||||
* i close this in hawk_awk_execstd()
|
||||
case HAWK_SED_IOSTD_OOCS:
|
||||
case HAWK_SED_IOSTD_BCS:
|
||||
case HAWK_SED_IOSTD_UCS:
|
||||
/* for input, there is nothing to do here.
|
||||
* for output, closing xtn->e.out.memstr is required. but put it to hawk_awk_execstd().
|
||||
*/
|
||||
break;
|
||||
|
||||
@ -355,7 +395,9 @@ static int open_input_stream (hawk_sed_t* sed, hawk_sed_io_arg_t* arg, hawk_sed_
|
||||
break;
|
||||
}
|
||||
|
||||
case HAWK_SED_IOSTD_STR:
|
||||
case HAWK_SED_IOSTD_OOCS:
|
||||
case HAWK_SED_IOSTD_BCS:
|
||||
case HAWK_SED_IOSTD_UCS:
|
||||
/* don't store anything to arg->handle */
|
||||
base->mempos = 0;
|
||||
break;
|
||||
@ -370,29 +412,49 @@ static int open_input_stream (hawk_sed_t* sed, hawk_sed_io_arg_t* arg, hawk_sed_
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (base == &xtn->s.in)
|
||||
{
|
||||
/* reset script location */
|
||||
if (io->type == HAWK_SED_IOSTD_FILE)
|
||||
switch (io->type)
|
||||
{
|
||||
hawk_sed_setcompid (
|
||||
sed,
|
||||
((io->u.file.path == HAWK_NULL)? sio_std_names[HAWK_SIO_STDIN].ptr: io->u.file.path)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
hawk_ooch_t buf[64];
|
||||
case HAWK_SED_IOSTD_FILE:
|
||||
if (io->u.fileb.path)
|
||||
{
|
||||
hawk_sed_setcompid (sed, io->u.file.path);
|
||||
}
|
||||
else
|
||||
{
|
||||
compid_stdin:
|
||||
hawk_sed_setcompid (sed, sio_std_names[HAWK_SIO_STDIN].ptr);
|
||||
}
|
||||
break;
|
||||
|
||||
/* format an identifier to be something like M#1, S#5 */
|
||||
buf[0] = (io->type == HAWK_SED_IOSTD_STR)? HAWK_T('M'): HAWK_T('S');
|
||||
buf[1] = HAWK_T('#');
|
||||
int_to_str (io - xtn->s.in.ptr, &buf[2], HAWK_COUNTOF(buf) - 2);
|
||||
case HAWK_SED_IOSTD_FILEB:
|
||||
if (!io->u.fileb.path) goto compid_stdin;
|
||||
hawk_sed_setcompidwithbcstr (sed, io->u.fileb.path);
|
||||
break;
|
||||
|
||||
/* don't care about failure int_to_str() though it's not
|
||||
* likely to happen */
|
||||
hawk_sed_setcompid (sed, buf);
|
||||
case HAWK_SED_IOSTD_FILEU:
|
||||
if (!io->u.fileu.path) goto compid_stdin;
|
||||
hawk_sed_setcompid (sed, sio_std_names[HAWK_SIO_STDIN].ptr);
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
hawk_ooch_t buf[64];
|
||||
|
||||
/* format an identifier to be something like M#1, S#5 */
|
||||
buf[0] = (io->type == HAWK_SED_IOSTD_OOCS ||
|
||||
io->type == HAWK_SED_IOSTD_BCS ||
|
||||
io->type == HAWK_SED_IOSTD_UCS)? HAWK_T('M'): HAWK_T('S');
|
||||
buf[1] = HAWK_T('#');
|
||||
int_to_str (io - xtn->s.in.ptr, &buf[2], HAWK_COUNTOF(buf) - 2);
|
||||
|
||||
/* don't care about failure int_to_str() though it's not
|
||||
* likely to happen */
|
||||
hawk_sed_setcompid (sed, buf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
sed->src.loc.line = 1;
|
||||
sed->src.loc.colm = 1;
|
||||
@ -487,14 +549,21 @@ static int open_output_stream (hawk_sed_t* sed, hawk_sed_io_arg_t* arg, hawk_sed
|
||||
break;
|
||||
}
|
||||
|
||||
case HAWK_SED_IOSTD_STR:
|
||||
#if defined(HAWK_OOCH_IS_BCH)
|
||||
case HAWK_SED_IOSTD_OOCS:
|
||||
#endif
|
||||
case HAWK_SED_IOSTD_BCS:
|
||||
xtn->e.out.memstr.be = hawk_becs_open(hawk_sed_getgem(sed), 0, 512);
|
||||
if (xtn->e.out.memstr.be == HAWK_NULL) return -1;
|
||||
break;
|
||||
|
||||
#if defined(HAWK_OOCH_IS_UCH)
|
||||
case HAWK_SED_IOSTD_OOCS:
|
||||
#endif
|
||||
case HAWK_SED_IOSTD_UCS:
|
||||
/* don't store anything to arg->handle */
|
||||
xtn->e.out.memstr = hawk_ooecs_open(hawk_sed_getgem(sed), 0, 512);
|
||||
if (xtn->e.out.memstr == HAWK_NULL)
|
||||
{
|
||||
hawk_sed_seterrnum (sed, HAWK_NULL, HAWK_ENOMEM);
|
||||
return -1;
|
||||
}
|
||||
xtn->e.out.memstr.ue = hawk_uecs_open(hawk_sed_getgem(sed), 0, 512);
|
||||
if (xtn->e.out.memstr.ue == HAWK_NULL) return -1;
|
||||
break;
|
||||
|
||||
case HAWK_SED_IOSTD_SIO:
|
||||
@ -510,6 +579,7 @@ static int open_output_stream (hawk_sed_t* sed, hawk_sed_io_arg_t* arg, hawk_sed
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static hawk_ooi_t read_input_stream (hawk_sed_t* sed, hawk_sed_io_arg_t* arg, hawk_ooch_t* buf, hawk_oow_t len, xtn_in_t* base)
|
||||
{
|
||||
xtn_t* xtn = GET_XTN(sed);
|
||||
@ -531,41 +601,77 @@ static hawk_ooi_t read_input_stream (hawk_sed_t* sed, hawk_sed_io_arg_t* arg, ha
|
||||
|
||||
HAWK_ASSERT (io != HAWK_NULL);
|
||||
|
||||
if (io->type == HAWK_SED_IOSTD_STR)
|
||||
if (io->type == HAWK_SED_IOSTD_OOCS)
|
||||
{
|
||||
iostd_oocs:
|
||||
n = 0;
|
||||
while (base->mempos < io->u.str.len && n < len)
|
||||
buf[n++] = io->u.str.ptr[base->mempos++];
|
||||
while (base->mempos < io->u.oocs.len && n < len)
|
||||
buf[n++] = io->u.oocs.ptr[base->mempos++];
|
||||
}
|
||||
else if (io->type == HAWK_SED_IOSTD_BCS)
|
||||
{
|
||||
#if defined(HAWK_OOCH_IS_BCH)
|
||||
goto iostd_oocs;
|
||||
#else
|
||||
int m;
|
||||
hawk_oow_t mbslen, wcslen;
|
||||
|
||||
mbslen = io->u.bcs.len - base->mempos;
|
||||
wcslen = len;
|
||||
if ((m = hawk_conv_bchars_to_uchars_with_cmgr(&io->u.bcs.ptr[base->mempos], &mbslen, buf, &wcslen, hawk_sed_getcmgr(sed), 0)) <= -1 && m != -2)
|
||||
{
|
||||
hawk_sed_seterrnum (sed, HAWK_NULL, HAWK_EECERR);
|
||||
n = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
base->mempos += mbslen;
|
||||
n = wcslen;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else if (io->type == HAWK_SED_IOSTD_UCS)
|
||||
{
|
||||
#if defined(HAWK_OOCH_IS_UCH)
|
||||
goto iostd_oocs;
|
||||
#else
|
||||
int m;
|
||||
hawk_oow_t mbslen, wcslen;
|
||||
|
||||
wcslen = io->u.ucs.len - base->mempos;
|
||||
mbslen = len;
|
||||
if ((m = hawk_conv_uchars_to_bchars_with_cmgr(&io->u.ucs.ptr[base->mempos], &wcslen, buf, &mbslen, hawk_sed_getcmgr(sed))) <= -1 && m != -2)
|
||||
{
|
||||
hawk_sed_seterrnum (sed, HAWK_NULL, HAWK_EECERR);
|
||||
n = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
base->mempos += mbslen;
|
||||
n = mbslen;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
n = hawk_sio_getoochars(arg->handle, buf, len);
|
||||
if (n <= -1)
|
||||
{
|
||||
set_eiofil_for_iostd (sed, io);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else n = hawk_sio_getoochars(arg->handle, buf, len);
|
||||
|
||||
if (n != 0)
|
||||
{
|
||||
if (n <= -1)
|
||||
if (base == &xtn->s.in)
|
||||
{
|
||||
if (io->type == HAWK_SED_IOSTD_FILE)
|
||||
{
|
||||
hawk_oocs_t ea;
|
||||
if (io->u.file.path)
|
||||
{
|
||||
ea.ptr = io->u.file.path;
|
||||
ea.len = hawk_count_oocstr(io->u.file.path);
|
||||
}
|
||||
else
|
||||
{
|
||||
ea = sio_std_names[HAWK_SIO_STDIN];
|
||||
}
|
||||
hawk_sed_seterror (sed, HAWK_NULL, HAWK_SED_EIOFIL, &ea);
|
||||
}
|
||||
}
|
||||
else if (base == &xtn->s.in)
|
||||
{
|
||||
xtn->s.last = buf[n-1];
|
||||
xtn->s.last = buf[n - 1];
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
/* ============================================= */
|
||||
/* == end of file on the current input stream == */
|
||||
/* ============================================= */
|
||||
@ -583,7 +689,7 @@ static hawk_ooi_t read_input_stream (hawk_sed_t* sed, hawk_sed_io_arg_t* arg, ha
|
||||
next = base->cur + 1;
|
||||
if (next->type == HAWK_SED_IOSTD_NULL)
|
||||
{
|
||||
/* no next stream available - return 0 */
|
||||
/* no next stream available - return 0 */
|
||||
break;
|
||||
}
|
||||
|
||||
@ -593,21 +699,7 @@ static hawk_ooi_t read_input_stream (hawk_sed_t* sed, hawk_sed_io_arg_t* arg, ha
|
||||
if (open_input_stream(sed, arg, next, base) <= -1)
|
||||
{
|
||||
/* failed to open the next input stream */
|
||||
if (next->type == HAWK_SED_IOSTD_FILE)
|
||||
{
|
||||
hawk_oocs_t ea;
|
||||
if (next->u.file.path)
|
||||
{
|
||||
ea.ptr = next->u.file.path;
|
||||
ea.len = hawk_count_oocstr (next->u.file.path);
|
||||
}
|
||||
else
|
||||
{
|
||||
ea = sio_std_names[HAWK_SIO_STDIN];
|
||||
}
|
||||
hawk_sed_seterror (sed, HAWK_NULL, HAWK_SED_EIOFIL, &ea);
|
||||
}
|
||||
|
||||
set_eiofil_for_iostd (sed, next);
|
||||
n = -1;
|
||||
break;
|
||||
}
|
||||
@ -832,37 +924,39 @@ static hawk_ooi_t x_out (
|
||||
else
|
||||
{
|
||||
hawk_sed_iostd_t* io = xtn->e.out.ptr;
|
||||
if (io->type == HAWK_SED_IOSTD_STR)
|
||||
switch (io->type)
|
||||
{
|
||||
if (len > HAWK_TYPE_MAX(hawk_ooi_t)) len = HAWK_TYPE_MAX(hawk_ooi_t);
|
||||
#if defined(HAWK_OOCH_IS_BCH)
|
||||
case HAWK_SED_IOSTD_OOCS:
|
||||
#endif
|
||||
case HAWK_SED_IOSTD_BCS:
|
||||
if (len > HAWK_TYPE_MAX(hawk_ooi_t)) len = HAWK_TYPE_MAX(hawk_ooi_t);
|
||||
#if defined(HAWK_OOCH_IS_BCH)
|
||||
if (hawk_becs_ncat(xtn->e.out.memstr.be, dat, len) == (hawk_oow_t)-1) return -1;
|
||||
#else
|
||||
if (hawk_becs_ncatuchars(xtn->e.out.memstr.be, dat, len, HAWK_NULL) == (hawk_oow_t)-1) return -1;
|
||||
#endif
|
||||
return len;
|
||||
|
||||
if (hawk_ooecs_ncat(xtn->e.out.memstr, dat, len) == (hawk_oow_t)-1)
|
||||
{
|
||||
hawk_sed_seterrnum (sed, HAWK_NULL, HAWK_ENOMEM);
|
||||
return -1;
|
||||
}
|
||||
#if defined(HAWK_OOCH_IS_UCH)
|
||||
case HAWK_SED_IOSTD_OOCS:
|
||||
#endif
|
||||
case HAWK_SED_IOSTD_UCS:
|
||||
if (len > HAWK_TYPE_MAX(hawk_ooi_t)) len = HAWK_TYPE_MAX(hawk_ooi_t);
|
||||
#if defined(HAWK_OOCH_IS_UCH)
|
||||
if (hawk_uecs_ncat(xtn->e.out.memstr.ue, dat, len) == (hawk_oow_t)-1) return -1;
|
||||
#else
|
||||
if (hawk_uecs_ncatbchars(xtn->e.out.memstr.ue, dat, len, HAWK_NULL, 1) == (hawk_oow_t)-1) return -1;
|
||||
#endif
|
||||
return len;
|
||||
|
||||
return len;
|
||||
}
|
||||
else
|
||||
{
|
||||
hawk_ooi_t n;
|
||||
n = hawk_sio_putoochars(arg->handle, dat, len);
|
||||
if (n <= -1)
|
||||
{
|
||||
hawk_oocs_t ea;
|
||||
if (io->u.file.path)
|
||||
default:
|
||||
{
|
||||
ea.ptr = io->u.file.path;
|
||||
ea.len = hawk_count_oocstr(io->u.file.path);
|
||||
hawk_ooi_t n;
|
||||
n = hawk_sio_putoochars(arg->handle, dat, len);
|
||||
if (n <= -1) set_eiofil_for_iostd (sed, io);
|
||||
return n;
|
||||
}
|
||||
else
|
||||
{
|
||||
ea = sio_std_names[HAWK_SIO_STDOUT];
|
||||
}
|
||||
hawk_sed_seterror (sed, HAWK_NULL, HAWK_SED_EIOFIL, &ea);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -896,10 +990,15 @@ int hawk_sed_compstd (hawk_sed_t* sed, hawk_sed_iostd_t in[], hawk_oow_t* count)
|
||||
if (in == HAWK_NULL)
|
||||
{
|
||||
/* it requires a valid array unlike hawk_sed_execstd(). */
|
||||
hawk_sed_seterrnum (sed, HAWK_NULL, HAWK_EINVAL);
|
||||
hawk_sed_seterrbfmt (sed, HAWK_NULL, HAWK_EINVAL, "no input handler provided");
|
||||
if (count) *count = 0;
|
||||
return -1;
|
||||
}
|
||||
if (verify_iostd_in(sed, in) <= -1)
|
||||
{
|
||||
if (count) *count = 0;
|
||||
return -1;
|
||||
}
|
||||
if (verify_iostd_in(sed, in) <= -1) return -1;
|
||||
|
||||
HAWK_MEMSET (&xtn->s, 0, HAWK_SIZEOF(xtn->s));
|
||||
xtn->s.in.ptr = in;
|
||||
@ -925,7 +1024,7 @@ int hawk_sed_execstd (hawk_sed_t* sed, hawk_sed_iostd_t in[], hawk_sed_iostd_t*
|
||||
if (out->type != HAWK_SED_IOSTD_FILE &&
|
||||
out->type != HAWK_SED_IOSTD_FILEB &&
|
||||
out->type != HAWK_SED_IOSTD_FILEU &&
|
||||
out->type != HAWK_SED_IOSTD_STR &&
|
||||
out->type != HAWK_SED_IOSTD_OOCS &&
|
||||
out->type != HAWK_SED_IOSTD_SIO)
|
||||
{
|
||||
hawk_sed_seterrnum (sed, HAWK_NULL, HAWK_EINVAL);
|
||||
@ -938,16 +1037,41 @@ int hawk_sed_execstd (hawk_sed_t* sed, hawk_sed_iostd_t in[], hawk_sed_iostd_t*
|
||||
xtn->e.in.cur = in;
|
||||
xtn->e.out.ptr = out;
|
||||
|
||||
n = hawk_sed_exec (sed, x_in, x_out);
|
||||
n = hawk_sed_exec(sed, x_in, x_out);
|
||||
|
||||
if (out && out->type == HAWK_SED_IOSTD_STR)
|
||||
if (out && out->type == HAWK_SED_IOSTD_OOCS)
|
||||
{
|
||||
if (n >= 0)
|
||||
switch (out->type)
|
||||
{
|
||||
HAWK_ASSERT (xtn->e.out.memstr != HAWK_NULL);
|
||||
hawk_ooecs_yield (xtn->e.out.memstr, &out->u.str, 0);
|
||||
#if defined(HAWK_OOCH_IS_BCH)
|
||||
case HAWK_SED_IOSTD_OOCS:
|
||||
#endif
|
||||
case HAWK_SED_IOSTD_BCS:
|
||||
if (n >= 0)
|
||||
{
|
||||
HAWK_ASSERT (xtn->e.out.memstr.be != HAWK_NULL);
|
||||
hawk_becs_yield (xtn->e.out.memstr.be, &out->u.bcs, 0);
|
||||
}
|
||||
if (xtn->e.out.memstr.be) hawk_becs_close (xtn->e.out.memstr.be);
|
||||
break;
|
||||
|
||||
#if defined(HAWK_OOCH_IS_UCH)
|
||||
case HAWK_SED_IOSTD_OOCS:
|
||||
#endif
|
||||
case HAWK_SED_IOSTD_UCS:
|
||||
if (n >= 0)
|
||||
{
|
||||
HAWK_ASSERT (xtn->e.out.memstr.ue != HAWK_NULL);
|
||||
hawk_uecs_yield (xtn->e.out.memstr.ue, &out->u.ucs, 0);
|
||||
}
|
||||
if (xtn->e.out.memstr.ue) hawk_uecs_close (xtn->e.out.memstr.ue);
|
||||
break;
|
||||
|
||||
default:
|
||||
/* don't handle other types */
|
||||
break;
|
||||
}
|
||||
if (xtn->e.out.memstr) hawk_ooecs_close (xtn->e.out.memstr);
|
||||
|
||||
}
|
||||
|
||||
clear_sio_names (sed);
|
||||
@ -990,27 +1114,27 @@ int hawk_sed_compstdfileu (hawk_sed_t* sed, const hawk_uch_t* file, hawk_cmgr_t*
|
||||
return hawk_sed_compstd(sed, in, HAWK_NULL);
|
||||
}
|
||||
|
||||
int hawk_sed_compstdstr (hawk_sed_t* sed, const hawk_ooch_t* script)
|
||||
int hawk_sed_compstdoocstr (hawk_sed_t* sed, const hawk_ooch_t* script)
|
||||
{
|
||||
hawk_sed_iostd_t in[2];
|
||||
|
||||
in[0].type = HAWK_SED_IOSTD_STR;
|
||||
in[0].u.str.ptr = (hawk_ooch_t*)script;
|
||||
in[0].u.str.len = hawk_count_oocstr(script);
|
||||
in[0].type = HAWK_SED_IOSTD_OOCS;
|
||||
in[0].u.oocs.ptr = (hawk_ooch_t*)script;
|
||||
in[0].u.oocs.len = hawk_count_oocstr(script);
|
||||
in[1].type = HAWK_SED_IOSTD_NULL;
|
||||
|
||||
return hawk_sed_compstd (sed, in, HAWK_NULL);
|
||||
return hawk_sed_compstd(sed, in, HAWK_NULL);
|
||||
}
|
||||
|
||||
int hawk_sed_compstdxstr (hawk_sed_t* sed, const hawk_oocs_t* script)
|
||||
int hawk_sed_compstdoocs (hawk_sed_t* sed, const hawk_oocs_t* script)
|
||||
{
|
||||
hawk_sed_iostd_t in[2];
|
||||
|
||||
in[0].type = HAWK_SED_IOSTD_STR;
|
||||
in[0].u.str = *script;
|
||||
in[0].type = HAWK_SED_IOSTD_OOCS;
|
||||
in[0].u.oocs = *script;
|
||||
in[1].type = HAWK_SED_IOSTD_NULL;
|
||||
|
||||
return hawk_sed_compstd (sed, in, HAWK_NULL);
|
||||
return hawk_sed_compstd(sed, in, HAWK_NULL);
|
||||
}
|
||||
|
||||
int hawk_sed_execstdfile (hawk_sed_t* sed, const hawk_ooch_t* infile, const hawk_ooch_t* outfile, hawk_cmgr_t* cmgr)
|
||||
@ -1045,15 +1169,15 @@ int hawk_sed_execstdxstr (hawk_sed_t* sed, const hawk_oocs_t* instr, hawk_oocs_t
|
||||
hawk_sed_iostd_t out;
|
||||
int n;
|
||||
|
||||
in[0].type = HAWK_SED_IOSTD_STR;
|
||||
in[0].u.str = *instr;
|
||||
in[0].type = HAWK_SED_IOSTD_OOCS;
|
||||
in[0].u.oocs = *instr;
|
||||
in[1].type = HAWK_SED_IOSTD_NULL;
|
||||
|
||||
out.type = HAWK_SED_IOSTD_STR;
|
||||
out.type = HAWK_SED_IOSTD_OOCS;
|
||||
|
||||
n = hawk_sed_execstd(sed, in, &out);
|
||||
|
||||
if (n >= 0) *outstr = out.u.str;
|
||||
if (n >= 0) *outstr = out.u.oocs;
|
||||
|
||||
return n;
|
||||
}
|
||||
|
@ -1385,7 +1385,6 @@ static hawk_ooi_t sf_in_read (hawk_t* hawk, hawk_sio_arg_t* arg, hawk_ooch_t* da
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case HAWK_PARSESTD_OOCS:
|
||||
parsestd_str:
|
||||
n = 0;
|
||||
|
@ -919,7 +919,6 @@ hawk_val_t* hawk_rtx_makembsvalwithucs (hawk_rtx_t* rtx, const hawk_ucs_t* ucs)
|
||||
return hawk_rtx_makembsvalwithuchars(rtx, ucs->ptr, ucs->len);
|
||||
}
|
||||
|
||||
|
||||
hawk_val_t* hawk_rtx_makembsvalwithbcstr (hawk_rtx_t* rtx, const hawk_bch_t* bcs)
|
||||
{
|
||||
return make_mbs_val(rtx, bcs, hawk_count_bcstr(bcs), HAWK_NULL, 0);
|
||||
@ -933,7 +932,6 @@ hawk_val_t* hawk_rtx_makembsvalwithucstr (hawk_rtx_t* rtx, const hawk_uch_t* ucs
|
||||
|
||||
hawk_val_t* hawk_rtx_makembsvalwithuchars2 (hawk_rtx_t* rtx, const hawk_uch_t* ucs1, hawk_oow_t len1, const hawk_uch_t* ucs2, hawk_oow_t len2)
|
||||
{
|
||||
#if defined(HAWK_OOCH_IS_UCH)
|
||||
hawk_val_t* v;
|
||||
hawk_bch_t* bcs;
|
||||
hawk_oow_t bcslen;
|
||||
@ -944,27 +942,11 @@ hawk_val_t* hawk_rtx_makembsvalwithuchars2 (hawk_rtx_t* rtx, const hawk_uch_t* u
|
||||
v = make_mbs_val(rtx, bcs, bcslen, HAWK_NULL, 0);
|
||||
hawk_rtx_freemem (rtx, bcs);
|
||||
return v;
|
||||
#else
|
||||
return make_mbs_val(rtx, ucs1, len1, ucs2, len2);
|
||||
#endif
|
||||
}
|
||||
|
||||
hawk_val_t* hawk_rtx_makembsvalwithbchars2 (hawk_rtx_t* rtx, const hawk_bch_t* bcs1, hawk_oow_t len1, const hawk_bch_t* bcs2, hawk_oow_t len2)
|
||||
{
|
||||
#if defined(HAWK_OOCH_IS_UCH)
|
||||
return make_mbs_val(rtx, bcs1, len1, bcs2, len2);
|
||||
#else
|
||||
hawk_val_t* v;
|
||||
hawk_uch_t* ucs;
|
||||
hawk_oow_t ucslen;
|
||||
|
||||
ucs = hawk_rtx_dupb2tobchars(rtx, bcs1, len1, bcs2, len2, &ucslen, 1);
|
||||
if (HAWK_UNLIKELY(!ucs)) return HAWK_NULL;
|
||||
|
||||
v = make_mbs_val(rtx, ucs, ucslen, HAWK_NULL, 0);
|
||||
hawk_rtx_freemem (rtx, ucs);
|
||||
return v;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
Loading…
Reference in New Issue
Block a user