This commit is contained in:
parent
d53810a1e2
commit
f952a670fc
@ -18,12 +18,13 @@ LIBS = @LIBS@
|
||||
MODE = @BUILDMODE@
|
||||
|
||||
CJ = @CJ@
|
||||
CJFLAGS = @CJFLAGS@ --classpath=@abs_top_builddir@/..
|
||||
CJFLAGS = @CJFLAGS@ --classpath=@abs_top_builddir@/.. -fjni
|
||||
BUILD_CJ = @BUILD_CJ@
|
||||
|
||||
JAVAC = @JAVAC@
|
||||
JAR = @JAR@
|
||||
CFLAGS_JNI = @CFLAGS_JNI@
|
||||
JNI = @JNI@
|
||||
BUILD_JNI = @BUILD_JNI@
|
||||
|
||||
LIBTOOL_COMPILE = ../libtool --mode=compile
|
||||
LIBTOOL_LINK = ../libtool --mode=link
|
||||
@ -62,7 +63,17 @@ OBJ_FILES_LIB_CXX = \
|
||||
|
||||
OBJ_FILES_LIB_CJ = \
|
||||
$(TMP_DIR)/cj/Awk.o \
|
||||
$(TMP_DIR)/cj/StdAwk.o
|
||||
$(TMP_DIR)/cj/StdAwk.o \
|
||||
$(TMP_DIR)/cj/Context.o \
|
||||
$(TMP_DIR)/cj/Extio.o \
|
||||
$(TMP_DIR)/cj/IO.o \
|
||||
$(TMP_DIR)/cj/Console.o \
|
||||
$(TMP_DIR)/cj/File.o \
|
||||
$(TMP_DIR)/cj/Pipe.o \
|
||||
$(TMP_DIR)/cj/Exception.o \
|
||||
$(TMP_DIR)/cj/Return.o \
|
||||
$(TMP_DIR)/cj/Argument.o \
|
||||
$(TMP_DIR)/cj/Clearable.o
|
||||
|
||||
OBJ_FILES_SO = $(OBJ_FILES_LIB:.o=.lo) $(OBJ_FILES_JNI:.o=.lo)
|
||||
|
||||
@ -77,14 +88,19 @@ OBJ_FILES_JAR = \
|
||||
$(TMP_DIR)/ase/awk/Pipe.class \
|
||||
$(TMP_DIR)/ase/awk/Exception.class \
|
||||
$(TMP_DIR)/ase/awk/Return.class \
|
||||
$(TMP_DIR)/ase/awk/Argument.class
|
||||
$(TMP_DIR)/ase/awk/Argument.class \
|
||||
$(TMP_DIR)/ase/awk/Clearable.class
|
||||
|
||||
lib: build$(JNI)
|
||||
lib: build$(BUILD_JNI)$(BUILD_CJ)
|
||||
|
||||
build: $(OUT_FILE_LIB) $(OUT_FILE_LIB_CXX)
|
||||
|
||||
buildjnicj: buildjni buildcj
|
||||
|
||||
buildjni: build $(OUT_FILE_JNI)
|
||||
|
||||
buildcj: build $(OUT_FILE_LIB_CJ)
|
||||
|
||||
$(OUT_FILE_LIB): $(TMP_DIR) $(OUT_DIR) $(OBJ_FILES_LIB)
|
||||
$(AR) cr $(OUT_FILE_LIB) $(OBJ_FILES_LIB)
|
||||
if [ "$(RANLIB)" = "ranlib" ]; then ranlib $(OUT_FILE_LIB); fi
|
||||
@ -176,6 +192,9 @@ $(TMP_DIR)/ase/awk/Return.class: Return.java
|
||||
$(TMP_DIR)/ase/awk/Argument.class: Argument.java
|
||||
$(JAVAC) -classpath ../.. -d $(TMP_DIR) Argument.java
|
||||
|
||||
$(TMP_DIR)/ase/awk/Clearable.class: Clearable.java
|
||||
$(JAVAC) -classpath ../.. -d $(TMP_DIR) Clearable.java
|
||||
|
||||
$(TMP_DIR)/cxx/Awk.o: Awk.cpp Awk.hpp
|
||||
$(CXX) $(CXXFLAGS) -o $@ -c Awk.cpp
|
||||
|
||||
@ -188,6 +207,36 @@ $(TMP_DIR)/cj/Awk.o: Awk.java
|
||||
$(TMP_DIR)/cj/StdAwk.o: StdAwk.java
|
||||
$(CJ) $(CJFLAGS) -o $@ -c StdAwk.java
|
||||
|
||||
$(TMP_DIR)/cj/Context.o: Context.java
|
||||
$(CJ) $(CJFLAGS) -o $@ -c Context.java
|
||||
|
||||
$(TMP_DIR)/cj/Extio.o: Extio.java
|
||||
$(CJ) $(CJFLAGS) -o $@ -c Extio.java
|
||||
|
||||
$(TMP_DIR)/cj/IO.o: IO.java
|
||||
$(CJ) $(CJFLAGS) -o $@ -c IO.java
|
||||
|
||||
$(TMP_DIR)/cj/Console.o: Console.java
|
||||
$(CJ) $(CJFLAGS) -o $@ -c Console.java
|
||||
|
||||
$(TMP_DIR)/cj/File.o: File.java
|
||||
$(CJ) $(CJFLAGS) -o $@ -c File.java
|
||||
|
||||
$(TMP_DIR)/cj/Pipe.o: Pipe.java
|
||||
$(CJ) $(CJFLAGS) -o $@ -c Pipe.java
|
||||
|
||||
$(TMP_DIR)/cj/Exception.o: Exception.java
|
||||
$(CJ) $(CJFLAGS) -o $@ -c Exception.java
|
||||
|
||||
$(TMP_DIR)/cj/Return.o: Return.java
|
||||
$(CJ) $(CJFLAGS) -o $@ -c Return.java
|
||||
|
||||
$(TMP_DIR)/cj/Argument.o: Argument.java
|
||||
$(CJ) $(CJFLAGS) -o $@ -c Argument.java
|
||||
|
||||
$(TMP_DIR)/cj/Clearable.o: Clearable.java
|
||||
$(CJ) $(CJFLAGS) -o $@ -c Clearable.java
|
||||
|
||||
$(OUT_DIR):
|
||||
mkdir -p $(OUT_DIR)
|
||||
|
||||
@ -201,5 +250,6 @@ $(TMP_DIR_CJ): $(TMP_DIR)
|
||||
mkdir -p $(TMP_DIR_CJ)
|
||||
|
||||
clean:
|
||||
rm -rf $(OUT_FILE_LIB) $(OUT_FILE_JNI) $(OUT_FILE_JAR) $(OUT_FILE_LIB_CXX) $(OBJ_FILES_LIB) $(OBJ_FILES_JNI) $(OBJ_FILES_JAR) $(OBJ_FILES_LIB_CXX)
|
||||
rm -rf $(OUT_FILE_LIB) $(OUT_FILE_JNI) $(OUT_FILE_JAR) $(OUT_FILE_LIB_CXX) $(OUT_FILE_LIB_CJ)
|
||||
rm -rf $(OBJ_FILES_LIB) $(OBJ_FILES_JNI) $(OBJ_FILES_JAR) $(OBJ_FILES_LIB_CXX) $(OBJ_FILES_LIB_CJ)
|
||||
|
||||
|
24
ase/configure
vendored
24
ase/configure
vendored
@ -463,7 +463,7 @@ ac_includes_default="\
|
||||
# include <unistd.h>
|
||||
#endif"
|
||||
|
||||
ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT build build_cpu build_vendor build_os host host_cpu host_vendor host_os EGREP LN_S ECHO AR ac_ct_AR RANLIB ac_ct_RANLIB STRIP ac_ct_STRIP CPP CXX CXXFLAGS ac_ct_CXX CXXCPP F77 FFLAGS ac_ct_F77 LIBTOOL CJ ac_ct_CJ LIBTOOL_DEPS BUILDMODE JAVAC_PATH JAR_PATH CFLAGS_JNI JAVAC JAR JNI CJFLAGS LIBOBJS LTLIBOBJS'
|
||||
ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT build build_cpu build_vendor build_os host host_cpu host_vendor host_os EGREP LN_S ECHO AR ac_ct_AR RANLIB ac_ct_RANLIB STRIP ac_ct_STRIP CPP CXX CXXFLAGS ac_ct_CXX CXXCPP F77 FFLAGS ac_ct_F77 LIBTOOL CJ ac_ct_CJ LIBTOOL_DEPS BUILDMODE JAVAC_PATH JAR_PATH CFLAGS_JNI JAVAC JAR BUILD_JNI CJFLAGS BUILD_CJ LIBOBJS LTLIBOBJS'
|
||||
ac_subst_files=''
|
||||
|
||||
# Initialize some variables set by options.
|
||||
@ -18548,9 +18548,14 @@ fi
|
||||
if test "$ac_test_CJFLAGS" = "set"
|
||||
then
|
||||
CJFLAGS=$ac_save_CJFLAGS
|
||||
else
|
||||
if test "$CJ" = "gcj"
|
||||
then
|
||||
CJFLAGS="-O2"
|
||||
else
|
||||
CJFLAGS=
|
||||
fi
|
||||
fi
|
||||
|
||||
# Checks for header files.
|
||||
echo "$as_me:$LINENO: checking for ANSI C header files" >&5
|
||||
@ -26007,13 +26012,19 @@ echo "${ECHO_T}no" >&6
|
||||
CFLAGS_JNI="$CFLAGS_JNI -I$i"
|
||||
done
|
||||
|
||||
JNI="jni"
|
||||
BUILD_JNI="jni"
|
||||
else
|
||||
JAVAC_PATH=""
|
||||
CFLAGS_JNI=""
|
||||
JNI=""
|
||||
BUILD_JNI=""
|
||||
fi
|
||||
|
||||
if test "$CJ" != ""
|
||||
then
|
||||
BUILD_CJ="cj"
|
||||
else
|
||||
BUILD_CJ=
|
||||
fi
|
||||
|
||||
CFLAGS_JNI=$CFLAGS_JNI
|
||||
|
||||
@ -26021,10 +26032,12 @@ JAVAC=$JAVAC_PATH
|
||||
|
||||
JAR=$JAR_PATH
|
||||
|
||||
JNI=$JNI
|
||||
BUILD_JNI=$BUILD_JNI
|
||||
|
||||
CJFLAGS=$CJFLAGS
|
||||
|
||||
BUILD_CJ=$BUILD_CJ
|
||||
|
||||
|
||||
ac_config_files="$ac_config_files makefile cmn/makefile awk/makefile lsp/makefile utl/makefile test/awk/makefile test/lsp/makefile"
|
||||
|
||||
@ -26686,8 +26699,9 @@ s,@JAR_PATH@,$JAR_PATH,;t t
|
||||
s,@CFLAGS_JNI@,$CFLAGS_JNI,;t t
|
||||
s,@JAVAC@,$JAVAC,;t t
|
||||
s,@JAR@,$JAR,;t t
|
||||
s,@JNI@,$JNI,;t t
|
||||
s,@BUILD_JNI@,$BUILD_JNI,;t t
|
||||
s,@CJFLAGS@,$CJFLAGS,;t t
|
||||
s,@BUILD_CJ@,$BUILD_CJ,;t t
|
||||
s,@LIBOBJS@,$LIBOBJS,;t t
|
||||
s,@LTLIBOBJS@,$LTLIBOBJS,;t t
|
||||
CEOF
|
||||
|
@ -46,9 +46,14 @@ fi
|
||||
if test "$ac_test_CJFLAGS" = "set"
|
||||
then
|
||||
CJFLAGS=$ac_save_CJFLAGS
|
||||
else
|
||||
if test "$CJ" = "gcj"
|
||||
then
|
||||
CJFLAGS="-O2"
|
||||
else
|
||||
CJFLAGS=
|
||||
fi
|
||||
fi
|
||||
|
||||
# Checks for header files.
|
||||
AC_HEADER_STDC
|
||||
@ -220,19 +225,26 @@ then
|
||||
CFLAGS_JNI="$CFLAGS_JNI -I$i"
|
||||
done
|
||||
|
||||
JNI="jni"
|
||||
BUILD_JNI="jni"
|
||||
else
|
||||
JAVAC_PATH=""
|
||||
CFLAGS_JNI=""
|
||||
JNI=""
|
||||
BUILD_JNI=""
|
||||
fi
|
||||
|
||||
if test "$CJ" != ""
|
||||
then
|
||||
BUILD_CJ="cj"
|
||||
else
|
||||
BUILD_CJ=
|
||||
fi
|
||||
|
||||
AC_SUBST(CFLAGS_JNI, $CFLAGS_JNI)
|
||||
AC_SUBST(JAVAC, $JAVAC_PATH)
|
||||
AC_SUBST(JAR, $JAR_PATH)
|
||||
AC_SUBST(JNI, $JNI)
|
||||
AC_SUBST(BUILD_JNI, $BUILD_JNI)
|
||||
AC_SUBST(CJFLAGS, $CJFLAGS)
|
||||
AC_SUBST(BUILD_CJ, $BUILD_CJ)
|
||||
|
||||
AC_CONFIG_FILES([makefile cmn/makefile awk/makefile lsp/makefile utl/makefile test/awk/makefile test/lsp/makefile])
|
||||
AC_OUTPUT
|
||||
|
@ -448,7 +448,7 @@ public class AseAwkPanel extends Panel implements DropTargetListener
|
||||
{
|
||||
public void itemStateChanged (ItemEvent e)
|
||||
{
|
||||
String name = (String)e.getItem();
|
||||
String name = ((Checkbox)e.getItem()).getLabel();
|
||||
for (int i = 0; i < options.length; i++)
|
||||
{
|
||||
if (options[i].getName().equals(name))
|
||||
@ -521,11 +521,13 @@ public class AseAwkPanel extends Panel implements DropTargetListener
|
||||
{
|
||||
if (osname.equals("win"))
|
||||
{
|
||||
jniLib.setText(System.getProperty("user.dir") + "\\lib\\" + System.mapLibraryName(libBase));
|
||||
jniLib.setText(System.getProperty("user.dir") +
|
||||
"\\.\\lib\\" + System.mapLibraryName(libBase));
|
||||
}
|
||||
else
|
||||
{
|
||||
jniLib.setText(System.getProperty("user.dir") + "/lib/.libs/" + System.mapLibraryName(libBase));
|
||||
jniLib.setText(System.getProperty("user.dir") +
|
||||
"/../lib/.libs/" + System.mapLibraryName(libBase));
|
||||
}
|
||||
|
||||
return;
|
||||
|
@ -8,12 +8,19 @@ CFLAGS = @CFLAGS@ -I@abs_top_builddir@/..
|
||||
LDFLAGS = @LDFLAGS@ -L@abs_top_builddir@/@BUILDMODE@/lib
|
||||
LIBS = @LIBS@ -laseawk -lasecmn -laseutl -lm
|
||||
LIBS_CXX = -laseawk++ ${LIBS}
|
||||
LIBS_CJ = -laseawkja
|
||||
MODE = @BUILDMODE@
|
||||
|
||||
CJ = @CJ@
|
||||
CJFLAGS = @CJFLAGS@ --classpath=@abs_top_builddir@/..:. -fjni
|
||||
BUILD_CJ = @BUILD_CJ@
|
||||
|
||||
JAVAC = @JAVAC@
|
||||
JAR = @JAR@
|
||||
CFLAGS_JNI = @CFLAGS_JNI@
|
||||
JNI = @JNI@
|
||||
BUILD_JNI = @BUILD_JNI@
|
||||
|
||||
AR = ar
|
||||
|
||||
OUT_DIR= ../../$(MODE)
|
||||
OUT_DIR_LIB = $(OUT_DIR)/lib
|
||||
@ -22,21 +29,34 @@ TMP_DIR = $(MODE)
|
||||
|
||||
ASEAWK_LIB =
|
||||
|
||||
all: build$(JNI)
|
||||
all: build$(BUILD_JNI)$(BUILD_CJ)
|
||||
|
||||
build: $(TMP_DIR) $(OUT_DIR_BIN) $(OUT_DIR_BIN)/aseawk $(OUT_DIR_BIN)/aseawk_mini $(OUT_DIR_BIN)/aseawk++
|
||||
|
||||
buildjnicj: buildjni buildcj
|
||||
|
||||
buildjni: build $(OUT_DIR_BIN)/aseawk.jar $(OUT_DIR)/AseAwkApplet.html $(OUT_DIR)/AseAwkApplet.js
|
||||
|
||||
buildcj: build $(OUT_DIR_BIN)/aseawkja
|
||||
|
||||
$(OUT_DIR_BIN)/aseawk: awk.c
|
||||
$(CC) $(CFLAGS) -o $@ awk.c $(LDFLAGS) $(LIBS)
|
||||
|
||||
$(OUT_DIR_BIN)/aseawk_mini: mini.c
|
||||
$(CC) $(CFLAGS) -o $@ mini.c $(LDFLAGS) $(LIBS)
|
||||
|
||||
$(OUT_DIR_BIN)/aseawk++: Awk.cpp
|
||||
$(CXX) $(CFLAGS) -o $@ Awk.cpp $(LDFLAGS) $(LIBS_CXX)
|
||||
|
||||
$(OUT_DIR_BIN)/aseawkja: $(TMP_DIR)/cj AseAwk.java AseAwkPanel.java AseAwkApplet.java
|
||||
$(CJ) $(CJFLAGS) -o $(TMP_DIR)/cj/AseAwk.o -c AseAwk.java
|
||||
$(CJ) $(CJFLAGS) -o $(TMP_DIR)/cj/AseAwkPanel.o -c AseAwkPanel.java
|
||||
$(CJ) $(CJFLAGS) -o $(TMP_DIR)/cj/AseAwkApplet.o -c AseAwkApplet.java
|
||||
mkdir -p $(TMP_DIR)/cj/lib
|
||||
cd $(TMP_DIR)/cj/lib; $(AR) xv @abs_top_builddir@/@BUILDMODE@/lib/libaseawkja.a
|
||||
$(CJ) --main=AseAwk -o $@ $(TMP_DIR)/cj/*.o $(TMP_DIR)/cj/lib/*.o
|
||||
rm -rf $(TMP_DIR)/cj/lib
|
||||
# Linking with the library seems to cause the resulting program
|
||||
# to crash for some JNI operations. Correct me if I'm wrong.
|
||||
#$(CJ) --main=AseAwk -o $@ $(TMP_DIR)/cj/*.o $(LDFLAGS) $(LIBS_CJ)
|
||||
|
||||
$(OUT_DIR_BIN)/aseawk.jar: $(TMP_DIR)/AseAwkPanel.class $(TMP_DIR)/AseAwk.class $(TMP_DIR)/AseAwkApplet.class
|
||||
cd $(TMP_DIR); $(JAR) -xvf ../$(OUT_DIR_LIB)/aseawk.jar
|
||||
cd $(TMP_DIR); $(JAR) -cvfm ../$@ ../manifest *.class ase
|
||||
@ -63,7 +83,10 @@ $(OUT_DIR_BIN):
|
||||
$(TMP_DIR):
|
||||
mkdir -p $(TMP_DIR)
|
||||
|
||||
$(TMP_DIR)/cj:
|
||||
mkdir -p $(TMP_DIR)/cj
|
||||
|
||||
clean:
|
||||
rm -rf $(OUT_DIR_BIN)/aseawk $(OUT_DIR_BIN)/aseawk_mini $(OUT_DIR_BIN)/aseawk++
|
||||
rm -rf $(OUT_DIR_BIN)/aseawk $(OUT_DIR_BIN)/aseawk++ $(OUT_DIR_BIN)/aseawkja
|
||||
rm -rf $(OUT_DIR_BIN)/aseawk.jar $(OUT_DIR)/AseAwkApplet.html $(OUT_DIR)/AseAwkApplet.js $(TMP_DIR)/*.class
|
||||
|
||||
|
@ -1,427 +0,0 @@
|
||||
/*
|
||||
* $Id: mini.c,v 1.4 2007/09/03 05:20:15 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <ase/awk/awk.h>
|
||||
|
||||
#include <ase/cmn/str.h>
|
||||
#include <ase/cmn/mem.h>
|
||||
|
||||
#include <ase/utl/ctype.h>
|
||||
#include <ase/utl/stdio.h>
|
||||
#include <ase/utl/main.h>
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
struct awk_src_io
|
||||
{
|
||||
const ase_char_t* file;
|
||||
FILE* handle;
|
||||
};
|
||||
|
||||
static const ase_char_t* data_file = ASE_NULL;
|
||||
|
||||
#if defined(vms) || defined(__vms)
|
||||
/* it seems that the main function should be placed in the main object file
|
||||
* in OpenVMS. otherwise, the first function in the main object file seems
|
||||
* to become the main function resulting in program start-up failure. */
|
||||
#include <ase/utl/main.c>
|
||||
#endif
|
||||
|
||||
#ifndef NDEBUG
|
||||
void ase_assert_abort (void)
|
||||
{
|
||||
abort ();
|
||||
}
|
||||
|
||||
void ase_assert_printf (const ase_char_t* fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start (ap, fmt);
|
||||
ase_vprintf (fmt, ap);
|
||||
va_end (ap);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* custom memory management function */
|
||||
void* awk_malloc (void* custom, ase_size_t n) { return malloc (n); }
|
||||
void* awk_realloc (void* custom, void* ptr, ase_size_t n) { return realloc (ptr, n); }
|
||||
void awk_free (void* custom, void* ptr) { free (ptr); }
|
||||
|
||||
/* custom character class functions */
|
||||
ase_bool_t awk_isupper (void* custom, ase_cint_t c) { return ase_isupper (c); }
|
||||
ase_bool_t awk_islower (void* custom, ase_cint_t c) { return ase_islower (c); }
|
||||
ase_bool_t awk_isalpha (void* custom, ase_cint_t c) { return ase_isalpha (c); }
|
||||
ase_bool_t awk_isdigit (void* custom, ase_cint_t c) { return ase_isdigit (c); }
|
||||
ase_bool_t awk_isxdigit (void* custom, ase_cint_t c) { return ase_isxdigit (c); }
|
||||
ase_bool_t awk_isalnum (void* custom, ase_cint_t c) { return ase_isalnum (c); }
|
||||
ase_bool_t awk_isspace (void* custom, ase_cint_t c) { return ase_isspace (c); }
|
||||
ase_bool_t awk_isprint (void* custom, ase_cint_t c) { return ase_isprint (c); }
|
||||
ase_bool_t awk_isgraph (void* custom, ase_cint_t c) { return ase_isgraph (c); }
|
||||
ase_bool_t awk_iscntrl (void* custom, ase_cint_t c) { return ase_iscntrl (c); }
|
||||
ase_bool_t awk_ispunct (void* custom, ase_cint_t c) { return ase_ispunct (c); }
|
||||
ase_cint_t awk_toupper (void* custom, ase_cint_t c) { return ase_toupper (c); }
|
||||
ase_cint_t awk_tolower (void* custom, ase_cint_t c) { return ase_tolower (c); }
|
||||
|
||||
/* custom miscellaneous functions */
|
||||
ase_real_t awk_pow (void* custom, ase_real_t x, ase_real_t y)
|
||||
{
|
||||
return pow (x, y);
|
||||
}
|
||||
|
||||
int awk_sprintf (void* custom, ase_char_t* buf, ase_size_t size, const ase_char_t* fmt, ...)
|
||||
{
|
||||
int n;
|
||||
|
||||
va_list ap;
|
||||
va_start (ap, fmt);
|
||||
n = ase_vsprintf (buf, size, fmt, ap);
|
||||
va_end (ap);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
void awk_dprintf (void* custom, const ase_char_t* fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start (ap, fmt);
|
||||
ase_vfprintf (stderr, fmt, ap);
|
||||
va_end (ap);
|
||||
}
|
||||
|
||||
/* source input handler */
|
||||
ase_ssize_t awk_srcio_in (int cmd, void* arg, ase_char_t* data, ase_size_t size)
|
||||
{
|
||||
struct awk_src_io* src_io = (struct awk_src_io*)arg;
|
||||
ase_cint_t c;
|
||||
|
||||
if (cmd == ASE_AWK_IO_OPEN)
|
||||
{
|
||||
if (src_io->file == ASE_NULL) return 0;
|
||||
src_io->handle = ase_fopen (src_io->file, ASE_T("r"));
|
||||
if (src_io->handle == NULL) return -1;
|
||||
return 1;
|
||||
}
|
||||
else if (cmd == ASE_AWK_IO_CLOSE)
|
||||
{
|
||||
if (src_io->file == ASE_NULL) return 0;
|
||||
fclose ((FILE*)src_io->handle);
|
||||
return 0;
|
||||
}
|
||||
else if (cmd == ASE_AWK_IO_READ)
|
||||
{
|
||||
if (size <= 0) return -1;
|
||||
c = ase_fgetc ((FILE*)src_io->handle);
|
||||
if (c == ASE_CHAR_EOF) return 0;
|
||||
*data = (ase_char_t)c;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* external i/o handler for pipe */
|
||||
ase_ssize_t awk_extio_pipe (int cmd, void* arg, ase_char_t* data, ase_size_t size)
|
||||
{
|
||||
ase_awk_extio_t* epa = (ase_awk_extio_t*)arg;
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case ASE_AWK_IO_OPEN:
|
||||
{
|
||||
FILE* handle;
|
||||
const ase_char_t* mode;
|
||||
|
||||
if (epa->mode == ASE_AWK_EXTIO_PIPE_READ)
|
||||
mode = ASE_T("r");
|
||||
else if (epa->mode == ASE_AWK_EXTIO_PIPE_WRITE)
|
||||
mode = ASE_T("w");
|
||||
else return -1;
|
||||
|
||||
handle = ase_popen (epa->name, mode);
|
||||
if (handle == NULL) return -1;
|
||||
epa->handle = (void*)handle;
|
||||
return 1;
|
||||
}
|
||||
|
||||
case ASE_AWK_IO_CLOSE:
|
||||
{
|
||||
fclose ((FILE*)epa->handle);
|
||||
epa->handle = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
case ASE_AWK_IO_READ:
|
||||
{
|
||||
if (ase_fgets (data, size, (FILE*)epa->handle) == ASE_NULL)
|
||||
{
|
||||
if (ferror((FILE*)epa->handle)) return -1;
|
||||
return 0;
|
||||
}
|
||||
return ase_strlen(data);
|
||||
}
|
||||
|
||||
case ASE_AWK_IO_WRITE:
|
||||
{
|
||||
#if defined(ASE_CHAR_IS_WCHAR) && defined(__linux)
|
||||
/* fwprintf seems to return an error with the file
|
||||
* pointer opened by popen, as of this writing.
|
||||
* anyway, hopefully the following replacement
|
||||
* will work all the way. */
|
||||
int n = fprintf (
|
||||
(FILE*)epa->handle, "%.*ls", size, data);
|
||||
#else
|
||||
int n = ase_fprintf (
|
||||
(FILE*)epa->handle, ASE_T("%.*s"), size, data);
|
||||
#endif
|
||||
if (n < 0) return -1;
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
case ASE_AWK_IO_FLUSH:
|
||||
{
|
||||
if (epa->mode == ASE_AWK_EXTIO_PIPE_READ) return -1;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
case ASE_AWK_IO_NEXT:
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* external i/o handler for file */
|
||||
ase_ssize_t awk_extio_file (int cmd, void* arg, ase_char_t* data, ase_size_t size)
|
||||
{
|
||||
ase_awk_extio_t* epa = (ase_awk_extio_t*)arg;
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case ASE_AWK_IO_OPEN:
|
||||
{
|
||||
FILE* handle;
|
||||
const ase_char_t* mode;
|
||||
|
||||
if (epa->mode == ASE_AWK_EXTIO_FILE_READ)
|
||||
mode = ASE_T("r");
|
||||
else if (epa->mode == ASE_AWK_EXTIO_FILE_WRITE)
|
||||
mode = ASE_T("w");
|
||||
else if (epa->mode == ASE_AWK_EXTIO_FILE_APPEND)
|
||||
mode = ASE_T("a");
|
||||
else return -1;
|
||||
|
||||
handle = ase_fopen (epa->name, mode);
|
||||
if (handle == NULL) return -1;
|
||||
|
||||
epa->handle = (void*)handle;
|
||||
return 1;
|
||||
}
|
||||
|
||||
case ASE_AWK_IO_CLOSE:
|
||||
{
|
||||
fclose ((FILE*)epa->handle);
|
||||
epa->handle = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
case ASE_AWK_IO_READ:
|
||||
{
|
||||
if (ase_fgets (data, size, (FILE*)epa->handle) == ASE_NULL)
|
||||
{
|
||||
if (ferror((FILE*)epa->handle)) return -1;
|
||||
return 0;
|
||||
}
|
||||
return ase_strlen(data);
|
||||
}
|
||||
|
||||
case ASE_AWK_IO_WRITE:
|
||||
{
|
||||
int n = ase_fprintf (
|
||||
(FILE*)epa->handle, ASE_T("%.*s"), size, data);
|
||||
if (n < 0) return -1;
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
case ASE_AWK_IO_FLUSH:
|
||||
{
|
||||
if (fflush ((FILE*)epa->handle) == EOF) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
case ASE_AWK_IO_NEXT:
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* external i/o handler for console */
|
||||
ase_ssize_t awk_extio_console (int cmd, void* arg, ase_char_t* data, ase_size_t size)
|
||||
{
|
||||
ase_awk_extio_t* epa = (ase_awk_extio_t*)arg;
|
||||
|
||||
if (cmd == ASE_AWK_IO_OPEN)
|
||||
{
|
||||
if (epa->mode == ASE_AWK_EXTIO_CONSOLE_READ)
|
||||
{
|
||||
FILE* fp = ase_fopen (data_file, ASE_T("r"));
|
||||
if (fp == ASE_NULL) return -1;
|
||||
|
||||
if (ase_awk_setfilename (
|
||||
epa->run, data_file, ase_strlen(data_file)) == -1)
|
||||
{
|
||||
fclose (fp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
epa->handle = fp;
|
||||
|
||||
return 1;
|
||||
}
|
||||
else if (epa->mode == ASE_AWK_EXTIO_CONSOLE_WRITE)
|
||||
{
|
||||
epa->handle = stdout;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
else if (cmd == ASE_AWK_IO_CLOSE)
|
||||
{
|
||||
fclose ((FILE*)epa->handle);
|
||||
epa->handle = NULL;
|
||||
return 0;
|
||||
}
|
||||
else if (cmd == ASE_AWK_IO_READ)
|
||||
{
|
||||
while (ase_fgets (data, size, (FILE*)epa->handle) == ASE_NULL)
|
||||
{
|
||||
if (ferror((FILE*)epa->handle)) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ase_strlen(data);
|
||||
}
|
||||
else if (cmd == ASE_AWK_IO_WRITE)
|
||||
{
|
||||
int n = ase_fprintf ((FILE*)epa->handle, ASE_T("%.*s"), size, data);
|
||||
if (n < 0) return -1;
|
||||
|
||||
return size;
|
||||
}
|
||||
else if (cmd == ASE_AWK_IO_FLUSH)
|
||||
{
|
||||
if (fflush ((FILE*)epa->handle) == EOF) return -1;
|
||||
return 0;
|
||||
}
|
||||
else if (cmd == ASE_AWK_IO_NEXT)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ase_main (int argc, ase_char_t* argv[])
|
||||
{
|
||||
ase_awk_t* awk;
|
||||
|
||||
ase_awk_prmfns_t prmfns;
|
||||
ase_awk_srcios_t srcios;
|
||||
ase_awk_runios_t runios;
|
||||
|
||||
struct awk_src_io src_io = { NULL, NULL };
|
||||
|
||||
if (argc != 3)
|
||||
{
|
||||
ase_printf (ASE_T("Usage: %s source-file data-file\n"), argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
src_io.file = argv[1];
|
||||
data_file = argv[2];
|
||||
|
||||
ase_memset (&prmfns, 0, ASE_SIZEOF(prmfns));
|
||||
|
||||
prmfns.mmgr.malloc = awk_malloc;
|
||||
prmfns.mmgr.realloc = awk_realloc;
|
||||
prmfns.mmgr.free = awk_free;
|
||||
prmfns.mmgr.custom_data = ASE_NULL;
|
||||
|
||||
prmfns.ccls.is_upper = awk_isupper;
|
||||
prmfns.ccls.is_lower = awk_islower;
|
||||
prmfns.ccls.is_alpha = awk_isalpha;
|
||||
prmfns.ccls.is_digit = awk_isdigit;
|
||||
prmfns.ccls.is_xdigit = awk_isxdigit;
|
||||
prmfns.ccls.is_alnum = awk_isalnum;
|
||||
prmfns.ccls.is_space = awk_isspace;
|
||||
prmfns.ccls.is_print = awk_isprint;
|
||||
prmfns.ccls.is_graph = awk_isgraph;
|
||||
prmfns.ccls.is_cntrl = awk_iscntrl;
|
||||
prmfns.ccls.is_punct = awk_ispunct;
|
||||
prmfns.ccls.to_upper = awk_toupper;
|
||||
prmfns.ccls.to_lower = awk_tolower;
|
||||
prmfns.ccls.custom_data = ASE_NULL;
|
||||
|
||||
prmfns.misc.pow = awk_pow;
|
||||
prmfns.misc.sprintf = awk_sprintf;
|
||||
prmfns.misc.dprintf = awk_dprintf;
|
||||
prmfns.misc.custom_data = ASE_NULL;
|
||||
|
||||
if ((awk = ase_awk_open(&prmfns, ASE_NULL)) == ASE_NULL)
|
||||
{
|
||||
ase_printf (ASE_T("ERROR: cannot open awk\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
ase_awk_setoption (awk,
|
||||
ASE_AWK_IMPLICIT | ASE_AWK_EXPLICIT | ASE_AWK_UNIQUEFN |
|
||||
ASE_AWK_IDIV | ASE_AWK_SHADING | ASE_AWK_SHIFT |
|
||||
ASE_AWK_EXTIO | ASE_AWK_BLOCKLESS | ASE_AWK_BASEONE |
|
||||
ASE_AWK_STRIPSPACES | ASE_AWK_NEXTOFILE);
|
||||
|
||||
srcios.in = awk_srcio_in;
|
||||
srcios.out = ASE_NULL;
|
||||
srcios.custom_data = &src_io;
|
||||
|
||||
if (ase_awk_parse (awk, &srcios) == -1)
|
||||
{
|
||||
ase_printf (
|
||||
ASE_T("PARSE ERROR: CODE [%d] LINE [%u] %s\n"),
|
||||
ase_awk_geterrnum(awk),
|
||||
(unsigned int)ase_awk_geterrlin(awk),
|
||||
ase_awk_geterrmsg(awk));
|
||||
ase_awk_close (awk);
|
||||
return -1;
|
||||
}
|
||||
|
||||
runios.pipe = awk_extio_pipe;
|
||||
runios.file = awk_extio_file;
|
||||
runios.console = awk_extio_console;
|
||||
runios.custom_data = ASE_NULL;
|
||||
|
||||
if (ase_awk_run (awk, ASE_NULL, &runios, ASE_NULL, ASE_NULL, ASE_NULL) == -1)
|
||||
{
|
||||
ase_printf (
|
||||
ASE_T("RUN ERROR: CODE [%d] LINE [%u] %s\n"),
|
||||
ase_awk_geterrnum(awk),
|
||||
(unsigned int)ase_awk_geterrlin(awk),
|
||||
ase_awk_geterrmsg(awk));
|
||||
|
||||
ase_awk_close (awk);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ase_awk_close (awk);
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user