From 76daf75d928b1a26f85bad4c4b0d281484a410bc Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Mon, 30 Apr 2007 18:34:00 +0000 Subject: [PATCH] Recovered from cvs revision 2007-04-30 05:47:00 --- ase/ase.dsw | 113 - ase/awk/Awk.java | 345 - ase/awk/Exception.java | 51 - ase/awk/Extio.java | 75 - ase/awk/StdAwk.java | 846 --- ase/awk/aseawk.dsp | 202 - ase/awk/aseawk_jni.dsp | 113 - ase/awk/awk.c | 256 - ase/awk/awk.h | 502 -- ase/awk/awk.txt | 71 - ase/awk/awk_i.h | 338 - ase/awk/descrip.mms | 28 - ase/awk/err.c | 466 -- ase/awk/extio.c | 951 --- ase/awk/extio.h | 51 - ase/awk/func.c | 1364 ---- ase/awk/func.h | 49 - ase/awk/jni.c | 2346 ------ ase/awk/jni.def | 24 - ase/awk/jni.h | 60 - ase/awk/makefile.in | 89 - ase/awk/makefile.lnx.gcc | 47 - ase/awk/makefile.mac.gcc | 41 - ase/awk/makefile.msw.bcc | 54 - ase/awk/makefile.msw.cl | 45 - ase/awk/map.c | 285 - ase/awk/map.h | 78 - ase/awk/misc.c | 905 --- ase/awk/misc.h | 45 - ase/awk/parse.c | 5113 ------------- ase/awk/parse.h | 29 - ase/awk/rec.c | 449 -- ase/awk/rex.c | 1880 ----- ase/awk/rex.h | 75 - ase/awk/run.c | 7046 ------------------ ase/awk/run.h | 119 - ase/awk/tab.c | 239 - ase/awk/tab.h | 69 - ase/awk/tree.c | 1176 --- ase/awk/tree.h | 403 -- ase/awk/val.c | 839 --- ase/awk/val.h | 206 - ase/build.xml | 68 - ase/cmn/asecmn.dsp | 124 - ase/cmn/conf_msw.h | 64 - ase/cmn/conf_unx.h.in | 44 - ase/cmn/conf_vms.h | 90 - ase/cmn/descrip.mms | 17 - ase/cmn/macros.h | 139 - ase/cmn/makefile.in | 49 - ase/cmn/makefile.msw.bcc | 29 - ase/cmn/makefile.msw.cl | 23 - ase/cmn/mem.c | 52 - ase/cmn/mem.h | 25 - ase/cmn/misc.c | 34 - ase/cmn/pack.h | 17 - ase/cmn/str.c | 385 - ase/cmn/str.h | 88 - ase/cmn/types.h | 276 - ase/cmn/unpack.h | 17 - ase/com/Awk.cpp | 1286 ---- ase/com/Awk.h | 162 - ase/com/Awk.rgs | 25 - ase/com/AwkExtio.cpp | 70 - ase/com/AwkExtio.h | 53 - ase/com/AwkExtio.rgs | 26 - ase/com/Buffer.cpp | 51 - ase/com/Buffer.h | 40 - ase/com/Buffer.rgs | 26 - ase/com/asecom.cpp | 78 - ase/com/asecom.def | 9 - ase/com/asecom.dsp | 211 - ase/com/asecom.idl | 303 - ase/com/asecom.rc | 126 - ase/com/aseps.def | 11 - ase/com/aseps.mk | 16 - ase/com/awk_cp.h | 601 -- ase/com/resource.h | 19 - ase/com/stdafx.cpp | 18 - ase/com/stdafx.h | 29 - ase/configure | 11056 ----------------------------- ase/configure.ac | 110 - ase/doc/ase-en.man | 30 - ase/doc/ase-ko.man | 29 - ase/doc/awk-en.man | 202 - ase/doc/awk-mini-en.man | 458 -- ase/doc/awk.man | 93 - ase/doc/diff.man | 11 - ase/doc/doc.css | 86 - ase/doc/embed.man | 51 - ase/doc/license.man | 19 - ase/doc/lsp-en.man | 22 - ase/doc/quickstart-en.man | 82 - ase/lsp/aselsp.dsp | 180 - ase/lsp/descrip.mms | 28 - ase/lsp/env.c | 146 - ase/lsp/env.h | 63 - ase/lsp/err.c | 130 - ase/lsp/eval.c | 380 - ase/lsp/lsp.c | 218 - ase/lsp/lsp.h | 123 - ase/lsp/lsp_i.h | 87 - ase/lsp/makefile.in | 93 - ase/lsp/makefile.msw.bcc | 21 - ase/lsp/makefile.msw.cl | 24 - ase/lsp/mem.c | 601 -- ase/lsp/mem.h | 99 - ase/lsp/misc.c | 575 -- ase/lsp/misc.h | 26 - ase/lsp/name.c | 125 - ase/lsp/name.h | 42 - ase/lsp/obj.h | 161 - ase/lsp/prim.c | 621 -- ase/lsp/prim.h | 69 - ase/lsp/prim_compar.c | 141 - ase/lsp/prim_let.c | 186 - ase/lsp/prim_math.c | 351 - ase/lsp/prim_prog.c | 53 - ase/lsp/print.c | 150 - ase/lsp/read.c | 567 -- ase/makefile.in | 63 - ase/rel/doc.awk | 266 - ase/rel/lic.awk | 21 - ase/rel/rel.sh | 144 - ase/rel/unix2dos.awk | 2 - ase/stx/array.c | 18 - ase/stx/array.h | 21 - ase/stx/bootstrp.c | 676 -- ase/stx/bootstrp.h | 21 - ase/stx/bytecode.c | 193 - ase/stx/bytecode.h | 56 - ase/stx/class.c | 168 - ase/stx/class.h | 81 - ase/stx/context.c | 75 - ase/stx/context.h | 43 - ase/stx/dict.c | 190 - ase/stx/dict.h | 42 - ase/stx/interp.c | 380 - ase/stx/interp.h | 20 - ase/stx/makefile.bcc | 21 - ase/stx/makefile.cl | 23 - ase/stx/makefile.in | 28 - ase/stx/makefile.lcc | 22 - ase/stx/makefile.tcc | 22 - ase/stx/memory.c | 98 - ase/stx/memory.h | 26 - ase/stx/method.h | 50 - ase/stx/misc.c | 70 - ase/stx/misc.h | 63 - ase/stx/name.c | 146 - ase/stx/name.h | 39 - ase/stx/object.c | 246 - ase/stx/object.h | 40 - ase/stx/parser.c | 1608 ----- ase/stx/parser.h | 107 - ase/stx/stx.bnf | 196 - ase/stx/stx.c | 70 - ase/stx/stx.h | 163 - ase/stx/stx.txt | 90 - ase/stx/symbol.c | 94 - ase/stx/symbol.h | 40 - ase/stx/token.c | 77 - ase/stx/token.h | 66 - ase/test/awk/Awk.java | 134 - ase/test/awk/AwkApplet.html | 11 - ase/test/awk/AwkApplet.java | 65 - ase/test/awk/arg.awk | 34 - ase/test/awk/arr.awk | 18 - ase/test/awk/asetestawk.dsp | 102 - ase/test/awk/awk.c | 1081 --- ase/test/awk/comp.awk | 121 - ase/test/awk/cou-001.awk | 1 - ase/test/awk/cou-001.out | 15 - ase/test/awk/cou-002.awk | 15 - ase/test/awk/cou-002.out | 29 - ase/test/awk/cou-003.awk | 1 - ase/test/awk/cou-003.out | 6 - ase/test/awk/cou-004.awk | 1 - ase/test/awk/cou-004.out | 5 - ase/test/awk/cou-005.awk | 1 - ase/test/awk/cou-005.out | 6 - ase/test/awk/cou-006.awk | 1 - ase/test/awk/cou-006.out | 5 - ase/test/awk/cou-007.awk | 1 - ase/test/awk/cou-007.out | 6 - ase/test/awk/cou-008.awk | 1 - ase/test/awk/cou-008.out | 6 - ase/test/awk/cou-009.awk | 1 - ase/test/awk/cou-009.out | 9 - ase/test/awk/cou-010.awk | 1 - ase/test/awk/cou-010.out | 6 - ase/test/awk/cou-011.awk | 3 - ase/test/awk/cou-011.out | 2 - ase/test/awk/cou-012.awk | 1 - ase/test/awk/cou-012.out | 4 - ase/test/awk/cou-013.awk | 1 - ase/test/awk/cou-013.out | 9 - ase/test/awk/cou-014.awk | 1 - ase/test/awk/cou-014.out | 9 - ase/test/awk/cou-015.awk | 1 - ase/test/awk/cou-015.out | 9 - ase/test/awk/cou-016.awk | 1 - ase/test/awk/cou-016.out | 9 - ase/test/awk/cou-017.awk | 1 - ase/test/awk/cou-017.out | 5 - ase/test/awk/cou-018.awk | 1 - ase/test/awk/cou-018.out | 2 - ase/test/awk/cou-019.awk | 1 - ase/test/awk/cou-019.out | 9 - ase/test/awk/cou-020.awk | 1 - ase/test/awk/cou-020.out | 9 - ase/test/awk/cou-021.awk | 1 - ase/test/awk/cou-021.out | 8 - ase/test/awk/cou-022.awk | 6 - ase/test/awk/cou-022.out | 27 - ase/test/awk/cou-023.awk | 2 - ase/test/awk/cou-023.out | 20 - ase/test/awk/cou-024.awk | 4 - ase/test/awk/cou-024.out | 9 - ase/test/awk/cou-025.awk | 6 - ase/test/awk/cou-025.out | 14 - ase/test/awk/cou-026.awk | 3 - ase/test/awk/cou-026.out | 16 - ase/test/awk/cou-027.awk | 5 - ase/test/awk/cou-027.out | 16 - ase/test/awk/cou-en.data | 11 - ase/test/awk/crash01.awk | 1 - ase/test/awk/crash02.awk | 9 - ase/test/awk/crash04.awk | 17 - ase/test/awk/crash05.awk | 5 - ase/test/awk/crash08.awk | 23 - ase/test/awk/descrip.mms | 13 - ase/test/awk/emp-001.awk | 1 - ase/test/awk/emp-001.out | 8 - ase/test/awk/emp-002.awk | 1 - ase/test/awk/emp-002.out | 6 - ase/test/awk/emp-003.awk | 1 - ase/test/awk/emp-003.out | 10 - ase/test/awk/emp-004.awk | 1 - ase/test/awk/emp-004.out | 10 - ase/test/awk/emp-005.awk | 1 - ase/test/awk/emp-005.out | 10 - ase/test/awk/emp-006.awk | 1 - ase/test/awk/emp-006.out | 10 - ase/test/awk/emp-007.awk | 1 - ase/test/awk/emp-007.out | 10 - ase/test/awk/emp-008.awk | 1 - ase/test/awk/emp-008.out | 4 - ase/test/awk/emp-009.awk | 1 - ase/test/awk/emp-009.out | 7 - ase/test/awk/emp-010.awk | 1 - ase/test/awk/emp-010.out | 3 - ase/test/awk/emp-011.awk | 1 - ase/test/awk/emp-011.out | 3 - ase/test/awk/emp-012.awk | 1 - ase/test/awk/emp-012.out | 7 - ase/test/awk/emp-013.awk | 2 - ase/test/awk/emp-013.out | 11 - ase/test/awk/emp-014.awk | 1 - ase/test/awk/emp-014.out | 7 - ase/test/awk/emp-015.awk | 5 - ase/test/awk/emp-015.out | 20 - ase/test/awk/emp-016.awk | 2 - ase/test/awk/emp-016.out | 17 - ase/test/awk/emp-017.awk | 2 - ase/test/awk/emp-017.out | 8 - ase/test/awk/emp-018.awk | 1 - ase/test/awk/emp-018.out | 4 - ase/test/awk/emp-019.awk | 5 - ase/test/awk/emp-019.out | 12 - ase/test/awk/emp-020.awk | 2 - ase/test/awk/emp-020.out | 9 - ase/test/awk/emp-021.awk | 2 - ase/test/awk/emp-021.out | 8 - ase/test/awk/emp-022.awk | 2 - ase/test/awk/emp-022.out | 8 - ase/test/awk/emp-023.awk | 1 - ase/test/awk/emp-023.out | 10 - ase/test/awk/emp-024.awk | 4 - ase/test/awk/emp-024.out | 9 - ase/test/awk/emp-025.awk | 7 - ase/test/awk/emp-025.out | 12 - ase/test/awk/emp-026.awk | 12 - ase/test/awk/emp-026.out | 18 - ase/test/awk/emp-027.awk | 8 - ase/test/awk/emp-027.out | 15 - ase/test/awk/emp-en.data | 6 - ase/test/awk/emp-ko.data | 6 - ase/test/awk/err-001.awk | Bin 10 -> 0 bytes ase/test/awk/err-001.out | 1 - ase/test/awk/err-002.awk | 3 - ase/test/awk/err-002.out | 4 - ase/test/awk/err-003.awk | 6 - ase/test/awk/err-003.out | 8 - ase/test/awk/err-004.awk | 3 - ase/test/awk/err-004.out | 5 - ase/test/awk/err-005.awk | 4 - ase/test/awk/err-005.out | 6 - ase/test/awk/err-006.awk | 3 - ase/test/awk/err-006.out | 5 - ase/test/awk/err-007.awk | 4 - ase/test/awk/err-007.out | 1 - ase/test/awk/err-008.awk | 6 - ase/test/awk/err-008.out | 1 - ase/test/awk/err-009.awk | 19 - ase/test/awk/err-009.out | 1 - ase/test/awk/err-010.awk | 15 - ase/test/awk/err-010.out | 1 - ase/test/awk/err-011.awk | 13 - ase/test/awk/err-011.out | 1 - ase/test/awk/err-012.awk | 14 - ase/test/awk/err-012.out | 1 - ase/test/awk/err-013.awk | 3 - ase/test/awk/err-013.out | 1 - ase/test/awk/err-014.awk | 7 - ase/test/awk/err-014.out | 1 - ase/test/awk/err-015.awk | 3 - ase/test/awk/err-015.out | 1 - ase/test/awk/err-016.awk | 5 - ase/test/awk/err-016.out | 1 - ase/test/awk/err-017.awk | 1 - ase/test/awk/err-017.out | 1 - ase/test/awk/err-018.awk | 2 - ase/test/awk/err-018.out | 1 - ase/test/awk/err-019.awk | 5 - ase/test/awk/err-019.out | 1 - ase/test/awk/err-020.awk | 4 - ase/test/awk/err-020.out | 5 - ase/test/awk/err-021.awk | 4 - ase/test/awk/err-021.out | 6 - ase/test/awk/err-en.data | 2 - ase/test/awk/histsort.awk | 8 - ase/test/awk/ite-001.awk | 7 - ase/test/awk/ite-002.awk | 4 - ase/test/awk/makefile.in | 26 - ase/test/awk/makefile.lnx.gcc | 25 - ase/test/awk/makefile.mac.gcc | 26 - ase/test/awk/makefile.msw.bcc | 34 - ase/test/awk/makefile.msw.cl | 43 - ase/test/awk/match.awk | 19 - ase/test/awk/mini.c | 427 -- ase/test/awk/mkjar.bat | 8 - ase/test/awk/negnum.data | 6 - ase/test/awk/num.awk | 27 - ase/test/awk/pow.awk | 43 - ase/test/awk/regress.sh | 140 - ase/test/awk/t1.awk | 21 - ase/test/awk/t10.awk | 22 - ase/test/awk/t11.awk | 17 - ase/test/awk/t12.awk | 38 - ase/test/awk/t13.awk | 22 - ase/test/awk/t14.awk | 28 - ase/test/awk/t15.awk | 16 - ase/test/awk/t16.awk | 1 - ase/test/awk/t17.awk | 18 - ase/test/awk/t18.awk | 21 - ase/test/awk/t19.awk | 4 - ase/test/awk/t2.awk | 24 - ase/test/awk/t20.awk | 8 - ase/test/awk/t21.awk | 8 - ase/test/awk/t22.awk | 15 - ase/test/awk/t23.awk | 19 - ase/test/awk/t24.awk | 6 - ase/test/awk/t25.awk | 13 - ase/test/awk/t26.awk | 13 - ase/test/awk/t27.awk | 6 - ase/test/awk/t28.awk | 41 - ase/test/awk/t29.awk | 3 - ase/test/awk/t3.awk | 25 - ase/test/awk/t30.awk | 3 - ase/test/awk/t31.awk | 2 - ase/test/awk/t32.awk | 2 - ase/test/awk/t33.awk | 15 - ase/test/awk/t34.awk | 1 - ase/test/awk/t35.awk | 4 - ase/test/awk/t36.awk | 47 - ase/test/awk/t37.awk | 6 - ase/test/awk/t38.awk | 9 - ase/test/awk/t39.awk | 9 - ase/test/awk/t4.awk | 21 - ase/test/awk/t40.awk | 8 - ase/test/awk/t41.awk | 4 - ase/test/awk/t42.awk | 13 - ase/test/awk/t43.awk | 3 - ase/test/awk/t44.awk | 3 - ase/test/awk/t45.awk | 1 - ase/test/awk/t46.awk | 1 - ase/test/awk/t47.awk | 19 - ase/test/awk/t48.awk | 3 - ase/test/awk/t49.awk | 5 - ase/test/awk/t5.awk | 10 - ase/test/awk/t50.awk | 6 - ase/test/awk/t6.awk | 21 - ase/test/awk/t7.awk | 5 - ase/test/awk/t8.awk | 2 - ase/test/awk/t9.awk | 25 - ase/test/awk/unr-001.awk | 6 - ase/test/awk/wordfreq.awk | 20 - ase/test/awk/x.awk | 31 - ase/test/com/AwkExtioConsole.cls | 32 - ase/test/com/AwkForm.frm | 468 -- ase/test/com/AwkForm.frx | Bin 17 -> 0 bytes ase/test/com/ase.vbp | 37 - ase/test/com/ase.vbw | 2 - ase/test/com/awk.js | 72 - ase/test/com/awk.vbs | 30 - ase/test/lsp/asetestlsp.dsp | 102 - ase/test/lsp/descrip.mms | 13 - ase/test/lsp/lsp.c | 398 -- ase/test/lsp/makefile.in | 23 - ase/test/lsp/makefile.msw.bcc | 19 - ase/test/lsp/makefile.msw.cl | 17 - ase/test/lsp/t1.lsp | 21 - ase/test/lsp/t2.lsp | 170 - ase/test/lsp/t3.lsp | 8 - ase/test/lsp/t4.lsp | 7 - ase/test/lsp/t5.lsp | 8 - ase/test/lsp/t6.lsp | 9 - ase/test/lsp/t7.lsp | 4 - ase/test/stx/helper.st | 13 - ase/test/stx/makefile.bcc | 21 - ase/test/stx/makefile.cl | 20 - ase/test/stx/makefile.in | 19 - ase/test/stx/makefile.lcc | 24 - ase/test/stx/makefile.tcc | 19 - ase/test/stx/parser.c | 230 - ase/test/stx/stx.c | 237 - ase/test/stx/test.st | 13 - ase/test/stx/test1.st | 10 - ase/test/stx/test2.st | 2 - ase/test/stx/test3.st | 2 - ase/utl/aseutl.dsp | 127 - ase/utl/ctype.c | 150 - ase/utl/ctype.h | 34 - ase/utl/descrip.mms | 16 - ase/utl/main.c | 89 - ase/utl/main.h | 26 - ase/utl/makefile.in | 49 - ase/utl/makefile.msw.bcc | 31 - ase/utl/makefile.msw.cl | 23 - ase/utl/stdio.c | 366 - ase/utl/stdio.h | 55 - 442 files changed, 62624 deletions(-) delete mode 100644 ase/ase.dsw delete mode 100644 ase/awk/Awk.java delete mode 100644 ase/awk/Exception.java delete mode 100644 ase/awk/Extio.java delete mode 100644 ase/awk/StdAwk.java delete mode 100644 ase/awk/aseawk.dsp delete mode 100644 ase/awk/aseawk_jni.dsp delete mode 100644 ase/awk/awk.c delete mode 100644 ase/awk/awk.h delete mode 100644 ase/awk/awk.txt delete mode 100644 ase/awk/awk_i.h delete mode 100644 ase/awk/descrip.mms delete mode 100644 ase/awk/err.c delete mode 100644 ase/awk/extio.c delete mode 100644 ase/awk/extio.h delete mode 100644 ase/awk/func.c delete mode 100644 ase/awk/func.h delete mode 100644 ase/awk/jni.c delete mode 100644 ase/awk/jni.def delete mode 100644 ase/awk/jni.h delete mode 100644 ase/awk/makefile.in delete mode 100644 ase/awk/makefile.lnx.gcc delete mode 100644 ase/awk/makefile.mac.gcc delete mode 100644 ase/awk/makefile.msw.bcc delete mode 100644 ase/awk/makefile.msw.cl delete mode 100644 ase/awk/map.c delete mode 100644 ase/awk/map.h delete mode 100644 ase/awk/misc.c delete mode 100644 ase/awk/misc.h delete mode 100644 ase/awk/parse.c delete mode 100644 ase/awk/parse.h delete mode 100644 ase/awk/rec.c delete mode 100644 ase/awk/rex.c delete mode 100644 ase/awk/rex.h delete mode 100644 ase/awk/run.c delete mode 100644 ase/awk/run.h delete mode 100644 ase/awk/tab.c delete mode 100644 ase/awk/tab.h delete mode 100644 ase/awk/tree.c delete mode 100644 ase/awk/tree.h delete mode 100644 ase/awk/val.c delete mode 100644 ase/awk/val.h delete mode 100644 ase/build.xml delete mode 100644 ase/cmn/asecmn.dsp delete mode 100644 ase/cmn/conf_msw.h delete mode 100644 ase/cmn/conf_unx.h.in delete mode 100644 ase/cmn/conf_vms.h delete mode 100644 ase/cmn/descrip.mms delete mode 100644 ase/cmn/macros.h delete mode 100644 ase/cmn/makefile.in delete mode 100644 ase/cmn/makefile.msw.bcc delete mode 100644 ase/cmn/makefile.msw.cl delete mode 100644 ase/cmn/mem.c delete mode 100644 ase/cmn/mem.h delete mode 100644 ase/cmn/misc.c delete mode 100644 ase/cmn/pack.h delete mode 100644 ase/cmn/str.c delete mode 100644 ase/cmn/str.h delete mode 100644 ase/cmn/types.h delete mode 100644 ase/cmn/unpack.h delete mode 100644 ase/com/Awk.cpp delete mode 100644 ase/com/Awk.h delete mode 100644 ase/com/Awk.rgs delete mode 100644 ase/com/AwkExtio.cpp delete mode 100644 ase/com/AwkExtio.h delete mode 100644 ase/com/AwkExtio.rgs delete mode 100644 ase/com/Buffer.cpp delete mode 100644 ase/com/Buffer.h delete mode 100644 ase/com/Buffer.rgs delete mode 100644 ase/com/asecom.cpp delete mode 100644 ase/com/asecom.def delete mode 100644 ase/com/asecom.dsp delete mode 100644 ase/com/asecom.idl delete mode 100644 ase/com/asecom.rc delete mode 100644 ase/com/aseps.def delete mode 100644 ase/com/aseps.mk delete mode 100644 ase/com/awk_cp.h delete mode 100644 ase/com/resource.h delete mode 100644 ase/com/stdafx.cpp delete mode 100644 ase/com/stdafx.h delete mode 100755 ase/configure delete mode 100644 ase/configure.ac delete mode 100644 ase/doc/ase-en.man delete mode 100644 ase/doc/ase-ko.man delete mode 100644 ase/doc/awk-en.man delete mode 100644 ase/doc/awk-mini-en.man delete mode 100644 ase/doc/awk.man delete mode 100644 ase/doc/diff.man delete mode 100644 ase/doc/doc.css delete mode 100644 ase/doc/embed.man delete mode 100644 ase/doc/license.man delete mode 100644 ase/doc/lsp-en.man delete mode 100644 ase/doc/quickstart-en.man delete mode 100644 ase/lsp/aselsp.dsp delete mode 100644 ase/lsp/descrip.mms delete mode 100644 ase/lsp/env.c delete mode 100644 ase/lsp/env.h delete mode 100644 ase/lsp/err.c delete mode 100644 ase/lsp/eval.c delete mode 100644 ase/lsp/lsp.c delete mode 100644 ase/lsp/lsp.h delete mode 100644 ase/lsp/lsp_i.h delete mode 100644 ase/lsp/makefile.in delete mode 100644 ase/lsp/makefile.msw.bcc delete mode 100644 ase/lsp/makefile.msw.cl delete mode 100644 ase/lsp/mem.c delete mode 100644 ase/lsp/mem.h delete mode 100644 ase/lsp/misc.c delete mode 100644 ase/lsp/misc.h delete mode 100644 ase/lsp/name.c delete mode 100644 ase/lsp/name.h delete mode 100644 ase/lsp/obj.h delete mode 100644 ase/lsp/prim.c delete mode 100644 ase/lsp/prim.h delete mode 100644 ase/lsp/prim_compar.c delete mode 100644 ase/lsp/prim_let.c delete mode 100644 ase/lsp/prim_math.c delete mode 100644 ase/lsp/prim_prog.c delete mode 100644 ase/lsp/print.c delete mode 100644 ase/lsp/read.c delete mode 100644 ase/makefile.in delete mode 100644 ase/rel/doc.awk delete mode 100644 ase/rel/lic.awk delete mode 100755 ase/rel/rel.sh delete mode 100644 ase/rel/unix2dos.awk delete mode 100644 ase/stx/array.c delete mode 100644 ase/stx/array.h delete mode 100644 ase/stx/bootstrp.c delete mode 100644 ase/stx/bootstrp.h delete mode 100644 ase/stx/bytecode.c delete mode 100644 ase/stx/bytecode.h delete mode 100644 ase/stx/class.c delete mode 100644 ase/stx/class.h delete mode 100644 ase/stx/context.c delete mode 100644 ase/stx/context.h delete mode 100644 ase/stx/dict.c delete mode 100644 ase/stx/dict.h delete mode 100644 ase/stx/interp.c delete mode 100644 ase/stx/interp.h delete mode 100644 ase/stx/makefile.bcc delete mode 100644 ase/stx/makefile.cl delete mode 100644 ase/stx/makefile.in delete mode 100644 ase/stx/makefile.lcc delete mode 100644 ase/stx/makefile.tcc delete mode 100644 ase/stx/memory.c delete mode 100644 ase/stx/memory.h delete mode 100644 ase/stx/method.h delete mode 100644 ase/stx/misc.c delete mode 100644 ase/stx/misc.h delete mode 100644 ase/stx/name.c delete mode 100644 ase/stx/name.h delete mode 100644 ase/stx/object.c delete mode 100644 ase/stx/object.h delete mode 100644 ase/stx/parser.c delete mode 100644 ase/stx/parser.h delete mode 100644 ase/stx/stx.bnf delete mode 100644 ase/stx/stx.c delete mode 100644 ase/stx/stx.h delete mode 100644 ase/stx/stx.txt delete mode 100644 ase/stx/symbol.c delete mode 100644 ase/stx/symbol.h delete mode 100644 ase/stx/token.c delete mode 100644 ase/stx/token.h delete mode 100644 ase/test/awk/Awk.java delete mode 100644 ase/test/awk/AwkApplet.html delete mode 100644 ase/test/awk/AwkApplet.java delete mode 100644 ase/test/awk/arg.awk delete mode 100644 ase/test/awk/arr.awk delete mode 100644 ase/test/awk/asetestawk.dsp delete mode 100644 ase/test/awk/awk.c delete mode 100644 ase/test/awk/comp.awk delete mode 100644 ase/test/awk/cou-001.awk delete mode 100644 ase/test/awk/cou-001.out delete mode 100644 ase/test/awk/cou-002.awk delete mode 100644 ase/test/awk/cou-002.out delete mode 100644 ase/test/awk/cou-003.awk delete mode 100644 ase/test/awk/cou-003.out delete mode 100644 ase/test/awk/cou-004.awk delete mode 100644 ase/test/awk/cou-004.out delete mode 100644 ase/test/awk/cou-005.awk delete mode 100644 ase/test/awk/cou-005.out delete mode 100644 ase/test/awk/cou-006.awk delete mode 100644 ase/test/awk/cou-006.out delete mode 100644 ase/test/awk/cou-007.awk delete mode 100644 ase/test/awk/cou-007.out delete mode 100644 ase/test/awk/cou-008.awk delete mode 100644 ase/test/awk/cou-008.out delete mode 100644 ase/test/awk/cou-009.awk delete mode 100644 ase/test/awk/cou-009.out delete mode 100644 ase/test/awk/cou-010.awk delete mode 100644 ase/test/awk/cou-010.out delete mode 100644 ase/test/awk/cou-011.awk delete mode 100644 ase/test/awk/cou-011.out delete mode 100644 ase/test/awk/cou-012.awk delete mode 100644 ase/test/awk/cou-012.out delete mode 100644 ase/test/awk/cou-013.awk delete mode 100644 ase/test/awk/cou-013.out delete mode 100644 ase/test/awk/cou-014.awk delete mode 100644 ase/test/awk/cou-014.out delete mode 100644 ase/test/awk/cou-015.awk delete mode 100644 ase/test/awk/cou-015.out delete mode 100644 ase/test/awk/cou-016.awk delete mode 100644 ase/test/awk/cou-016.out delete mode 100644 ase/test/awk/cou-017.awk delete mode 100644 ase/test/awk/cou-017.out delete mode 100644 ase/test/awk/cou-018.awk delete mode 100644 ase/test/awk/cou-018.out delete mode 100644 ase/test/awk/cou-019.awk delete mode 100644 ase/test/awk/cou-019.out delete mode 100644 ase/test/awk/cou-020.awk delete mode 100644 ase/test/awk/cou-020.out delete mode 100644 ase/test/awk/cou-021.awk delete mode 100644 ase/test/awk/cou-021.out delete mode 100644 ase/test/awk/cou-022.awk delete mode 100644 ase/test/awk/cou-022.out delete mode 100644 ase/test/awk/cou-023.awk delete mode 100644 ase/test/awk/cou-023.out delete mode 100644 ase/test/awk/cou-024.awk delete mode 100644 ase/test/awk/cou-024.out delete mode 100644 ase/test/awk/cou-025.awk delete mode 100644 ase/test/awk/cou-025.out delete mode 100644 ase/test/awk/cou-026.awk delete mode 100644 ase/test/awk/cou-026.out delete mode 100644 ase/test/awk/cou-027.awk delete mode 100644 ase/test/awk/cou-027.out delete mode 100644 ase/test/awk/cou-en.data delete mode 100644 ase/test/awk/crash01.awk delete mode 100644 ase/test/awk/crash02.awk delete mode 100644 ase/test/awk/crash04.awk delete mode 100644 ase/test/awk/crash05.awk delete mode 100644 ase/test/awk/crash08.awk delete mode 100644 ase/test/awk/descrip.mms delete mode 100644 ase/test/awk/emp-001.awk delete mode 100644 ase/test/awk/emp-001.out delete mode 100644 ase/test/awk/emp-002.awk delete mode 100644 ase/test/awk/emp-002.out delete mode 100644 ase/test/awk/emp-003.awk delete mode 100644 ase/test/awk/emp-003.out delete mode 100644 ase/test/awk/emp-004.awk delete mode 100644 ase/test/awk/emp-004.out delete mode 100644 ase/test/awk/emp-005.awk delete mode 100644 ase/test/awk/emp-005.out delete mode 100644 ase/test/awk/emp-006.awk delete mode 100644 ase/test/awk/emp-006.out delete mode 100644 ase/test/awk/emp-007.awk delete mode 100644 ase/test/awk/emp-007.out delete mode 100644 ase/test/awk/emp-008.awk delete mode 100644 ase/test/awk/emp-008.out delete mode 100644 ase/test/awk/emp-009.awk delete mode 100644 ase/test/awk/emp-009.out delete mode 100644 ase/test/awk/emp-010.awk delete mode 100644 ase/test/awk/emp-010.out delete mode 100644 ase/test/awk/emp-011.awk delete mode 100644 ase/test/awk/emp-011.out delete mode 100644 ase/test/awk/emp-012.awk delete mode 100644 ase/test/awk/emp-012.out delete mode 100644 ase/test/awk/emp-013.awk delete mode 100644 ase/test/awk/emp-013.out delete mode 100644 ase/test/awk/emp-014.awk delete mode 100644 ase/test/awk/emp-014.out delete mode 100644 ase/test/awk/emp-015.awk delete mode 100644 ase/test/awk/emp-015.out delete mode 100644 ase/test/awk/emp-016.awk delete mode 100644 ase/test/awk/emp-016.out delete mode 100644 ase/test/awk/emp-017.awk delete mode 100644 ase/test/awk/emp-017.out delete mode 100644 ase/test/awk/emp-018.awk delete mode 100644 ase/test/awk/emp-018.out delete mode 100644 ase/test/awk/emp-019.awk delete mode 100644 ase/test/awk/emp-019.out delete mode 100644 ase/test/awk/emp-020.awk delete mode 100644 ase/test/awk/emp-020.out delete mode 100644 ase/test/awk/emp-021.awk delete mode 100644 ase/test/awk/emp-021.out delete mode 100644 ase/test/awk/emp-022.awk delete mode 100644 ase/test/awk/emp-022.out delete mode 100644 ase/test/awk/emp-023.awk delete mode 100644 ase/test/awk/emp-023.out delete mode 100644 ase/test/awk/emp-024.awk delete mode 100644 ase/test/awk/emp-024.out delete mode 100644 ase/test/awk/emp-025.awk delete mode 100644 ase/test/awk/emp-025.out delete mode 100644 ase/test/awk/emp-026.awk delete mode 100644 ase/test/awk/emp-026.out delete mode 100644 ase/test/awk/emp-027.awk delete mode 100644 ase/test/awk/emp-027.out delete mode 100644 ase/test/awk/emp-en.data delete mode 100644 ase/test/awk/emp-ko.data delete mode 100644 ase/test/awk/err-001.awk delete mode 100644 ase/test/awk/err-001.out delete mode 100644 ase/test/awk/err-002.awk delete mode 100644 ase/test/awk/err-002.out delete mode 100644 ase/test/awk/err-003.awk delete mode 100644 ase/test/awk/err-003.out delete mode 100644 ase/test/awk/err-004.awk delete mode 100644 ase/test/awk/err-004.out delete mode 100644 ase/test/awk/err-005.awk delete mode 100644 ase/test/awk/err-005.out delete mode 100644 ase/test/awk/err-006.awk delete mode 100644 ase/test/awk/err-006.out delete mode 100644 ase/test/awk/err-007.awk delete mode 100644 ase/test/awk/err-007.out delete mode 100644 ase/test/awk/err-008.awk delete mode 100644 ase/test/awk/err-008.out delete mode 100644 ase/test/awk/err-009.awk delete mode 100644 ase/test/awk/err-009.out delete mode 100644 ase/test/awk/err-010.awk delete mode 100644 ase/test/awk/err-010.out delete mode 100644 ase/test/awk/err-011.awk delete mode 100644 ase/test/awk/err-011.out delete mode 100644 ase/test/awk/err-012.awk delete mode 100644 ase/test/awk/err-012.out delete mode 100644 ase/test/awk/err-013.awk delete mode 100644 ase/test/awk/err-013.out delete mode 100644 ase/test/awk/err-014.awk delete mode 100644 ase/test/awk/err-014.out delete mode 100644 ase/test/awk/err-015.awk delete mode 100644 ase/test/awk/err-015.out delete mode 100644 ase/test/awk/err-016.awk delete mode 100644 ase/test/awk/err-016.out delete mode 100644 ase/test/awk/err-017.awk delete mode 100644 ase/test/awk/err-017.out delete mode 100644 ase/test/awk/err-018.awk delete mode 100644 ase/test/awk/err-018.out delete mode 100644 ase/test/awk/err-019.awk delete mode 100644 ase/test/awk/err-019.out delete mode 100644 ase/test/awk/err-020.awk delete mode 100644 ase/test/awk/err-020.out delete mode 100644 ase/test/awk/err-021.awk delete mode 100644 ase/test/awk/err-021.out delete mode 100644 ase/test/awk/err-en.data delete mode 100644 ase/test/awk/histsort.awk delete mode 100644 ase/test/awk/ite-001.awk delete mode 100644 ase/test/awk/ite-002.awk delete mode 100644 ase/test/awk/makefile.in delete mode 100644 ase/test/awk/makefile.lnx.gcc delete mode 100644 ase/test/awk/makefile.mac.gcc delete mode 100644 ase/test/awk/makefile.msw.bcc delete mode 100644 ase/test/awk/makefile.msw.cl delete mode 100644 ase/test/awk/match.awk delete mode 100644 ase/test/awk/mini.c delete mode 100644 ase/test/awk/mkjar.bat delete mode 100644 ase/test/awk/negnum.data delete mode 100644 ase/test/awk/num.awk delete mode 100644 ase/test/awk/pow.awk delete mode 100755 ase/test/awk/regress.sh delete mode 100644 ase/test/awk/t1.awk delete mode 100644 ase/test/awk/t10.awk delete mode 100644 ase/test/awk/t11.awk delete mode 100644 ase/test/awk/t12.awk delete mode 100644 ase/test/awk/t13.awk delete mode 100644 ase/test/awk/t14.awk delete mode 100644 ase/test/awk/t15.awk delete mode 100644 ase/test/awk/t16.awk delete mode 100644 ase/test/awk/t17.awk delete mode 100644 ase/test/awk/t18.awk delete mode 100644 ase/test/awk/t19.awk delete mode 100644 ase/test/awk/t2.awk delete mode 100644 ase/test/awk/t20.awk delete mode 100644 ase/test/awk/t21.awk delete mode 100644 ase/test/awk/t22.awk delete mode 100644 ase/test/awk/t23.awk delete mode 100644 ase/test/awk/t24.awk delete mode 100644 ase/test/awk/t25.awk delete mode 100644 ase/test/awk/t26.awk delete mode 100644 ase/test/awk/t27.awk delete mode 100644 ase/test/awk/t28.awk delete mode 100644 ase/test/awk/t29.awk delete mode 100644 ase/test/awk/t3.awk delete mode 100644 ase/test/awk/t30.awk delete mode 100644 ase/test/awk/t31.awk delete mode 100644 ase/test/awk/t32.awk delete mode 100644 ase/test/awk/t33.awk delete mode 100644 ase/test/awk/t34.awk delete mode 100644 ase/test/awk/t35.awk delete mode 100644 ase/test/awk/t36.awk delete mode 100644 ase/test/awk/t37.awk delete mode 100644 ase/test/awk/t38.awk delete mode 100644 ase/test/awk/t39.awk delete mode 100644 ase/test/awk/t4.awk delete mode 100644 ase/test/awk/t40.awk delete mode 100644 ase/test/awk/t41.awk delete mode 100644 ase/test/awk/t42.awk delete mode 100644 ase/test/awk/t43.awk delete mode 100644 ase/test/awk/t44.awk delete mode 100644 ase/test/awk/t45.awk delete mode 100644 ase/test/awk/t46.awk delete mode 100644 ase/test/awk/t47.awk delete mode 100644 ase/test/awk/t48.awk delete mode 100644 ase/test/awk/t49.awk delete mode 100644 ase/test/awk/t5.awk delete mode 100644 ase/test/awk/t50.awk delete mode 100644 ase/test/awk/t6.awk delete mode 100644 ase/test/awk/t7.awk delete mode 100644 ase/test/awk/t8.awk delete mode 100644 ase/test/awk/t9.awk delete mode 100644 ase/test/awk/unr-001.awk delete mode 100644 ase/test/awk/wordfreq.awk delete mode 100644 ase/test/awk/x.awk delete mode 100644 ase/test/com/AwkExtioConsole.cls delete mode 100644 ase/test/com/AwkForm.frm delete mode 100644 ase/test/com/AwkForm.frx delete mode 100644 ase/test/com/ase.vbp delete mode 100644 ase/test/com/ase.vbw delete mode 100644 ase/test/com/awk.js delete mode 100644 ase/test/com/awk.vbs delete mode 100644 ase/test/lsp/asetestlsp.dsp delete mode 100644 ase/test/lsp/descrip.mms delete mode 100644 ase/test/lsp/lsp.c delete mode 100644 ase/test/lsp/makefile.in delete mode 100644 ase/test/lsp/makefile.msw.bcc delete mode 100644 ase/test/lsp/makefile.msw.cl delete mode 100644 ase/test/lsp/t1.lsp delete mode 100644 ase/test/lsp/t2.lsp delete mode 100644 ase/test/lsp/t3.lsp delete mode 100644 ase/test/lsp/t4.lsp delete mode 100644 ase/test/lsp/t5.lsp delete mode 100644 ase/test/lsp/t6.lsp delete mode 100644 ase/test/lsp/t7.lsp delete mode 100644 ase/test/stx/helper.st delete mode 100644 ase/test/stx/makefile.bcc delete mode 100644 ase/test/stx/makefile.cl delete mode 100644 ase/test/stx/makefile.in delete mode 100644 ase/test/stx/makefile.lcc delete mode 100644 ase/test/stx/makefile.tcc delete mode 100644 ase/test/stx/parser.c delete mode 100644 ase/test/stx/stx.c delete mode 100644 ase/test/stx/test.st delete mode 100644 ase/test/stx/test1.st delete mode 100644 ase/test/stx/test2.st delete mode 100644 ase/test/stx/test3.st delete mode 100644 ase/utl/aseutl.dsp delete mode 100644 ase/utl/ctype.c delete mode 100644 ase/utl/ctype.h delete mode 100644 ase/utl/descrip.mms delete mode 100644 ase/utl/main.c delete mode 100644 ase/utl/main.h delete mode 100644 ase/utl/makefile.in delete mode 100644 ase/utl/makefile.msw.bcc delete mode 100644 ase/utl/makefile.msw.cl delete mode 100644 ase/utl/stdio.c delete mode 100644 ase/utl/stdio.h diff --git a/ase/ase.dsw b/ase/ase.dsw deleted file mode 100644 index 5565d7d0..00000000 --- a/ase/ase.dsw +++ /dev/null @@ -1,113 +0,0 @@ -Microsoft Developer Studio Workspace File, Format Version 6.00 -# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! - -############################################################################### - -Project: "asecmn"=.\cmn\asecmn.dsp - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ -}}} - -############################################################################### - -Project: "aseutl"=.\utl\aseutl.dsp - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ -}}} - -############################################################################### - -Project: "aseawk"=.\awk\aseawk.dsp - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ -}}} - -############################################################################### - -Project: "aseawk_jni"=.\awk\aseawk_jni.dsp - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ -}}} - -############################################################################### - -Project: "asecom"=.\com\asecom.dsp - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ -}}} - -############################################################################### - -Project: "asetestawk"=.\test\awk\asetestawk.dsp - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ -}}} - -############################################################################### - -Project: "aselsp"=.\lsp\aselsp.dsp - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ -}}} - -############################################################################### - -Project: "asetestlsp"=.\test\lsp\asetestlsp.dsp - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ -}}} - -############################################################################### - -Global: - -Package=<5> -{{{ -}}} - -Package=<3> -{{{ -}}} - -############################################################################### - diff --git a/ase/awk/Awk.java b/ase/awk/Awk.java deleted file mode 100644 index acda82c9..00000000 --- a/ase/awk/Awk.java +++ /dev/null @@ -1,345 +0,0 @@ -/* - * $Id: Awk.java,v 1.1.1.1 2007/03/28 14:05:12 bacon Exp $ - * - * {License} - */ - -package ase.awk; - -public abstract class Awk -{ - // mode for open_source & close_source - public static final int SOURCE_READ = 1; - public static final int SOURCE_WRITE = 2; - - // depth id - public static final int DEPTH_BLOCK_PARSE = (1 << 0); - public static final int DEPTH_BLOCK_RUN = (1 << 1); - public static final int DEPTH_EXPR_PARSE = (1 << 2); - public static final int DEPTH_EXPR_RUN = (1 << 3); - public static final int DEPTH_REX_BUILD = (1 << 4); - public static final int DEPTH_REX_MATCH = (1 << 5); - - // options - public static final int OPTION_IMPLICIT = (1 << 0); - public static final int OPTION_EXPLICIT = (1 << 1); - public static final int OPTION_UNIQUEFN = (1 << 2); - public static final int OPTION_SHADING = (1 << 3); - public static final int OPTION_SHIFT = (1 << 4); - public static final int OPTION_IDIV = (1 << 5); - public static final int OPTION_STRCONCAT = (1 << 6); - public static final int OPTION_EXTIO = (1 << 7); - public static final int OPTION_COPROC = (1 << 8); - public static final int OPTION_BLOCKLESS = (1 << 9); - public static final int OPTION_STRBASEONE = (1 << 10); - public static final int OPTION_STRIPSPACES = (1 << 11); - public static final int OPTION_NEXTOFILE = (1 << 12); - public static final int OPTION_CRLF = (1 << 13); - - private long handle; - - public Awk () throws Exception - { - this.handle = 0; - - open (); - } - - /* == just in case == */ - protected void finalize () throws Throwable - { - super.finalize (); - if (handle != 0) close (); - } - - /* == native methods == */ - private native void open () throws Exception; - public native void close (); - public native void parse () throws Exception; - public native void run (String main, String[] args) throws Exception; - - private native int getmaxdepth (int id); - private native void setmaxdepth (int id, int depth); - - private native int getoption (); - private native void setoption (int opt); - - private native boolean getdebug (); - private native void setdebug (boolean debug); - - private native void addbfn ( - String name, int min_args, int max_args) throws Exception; - private native void delbfn (String name) throws Exception; - - private native void setfilename ( - long runid, String name) throws Exception; - private native void setofilename ( - long runid, String name) throws Exception; - - private native Object strtonum ( - long runid, String str) throws Exception; - private native String valtostr ( - long runid, Object obj) throws Exception; - - /* == simpler run methods == */ - public void run (String main) throws Exception - { - run (main, null); - } - - public void run (String[] args) throws Exception - { - run (null, args); - } - - public void run () throws Exception - { - run (null, null); - } - - /* == builtin functions == */ - public void addBuiltinFunction ( - String name, int min_args, int max_args) throws Exception - { - addbfn (name, min_args, max_args); - } - - public void deleteBuiltinFunction (String name) throws Exception - { - delbfn (name); - } - - protected long builtinFunctionArgumentToLong ( - long runid, Object obj) throws Exception - { - long n; - - if (obj == null) n = 0; - else - { - if (obj instanceof String) - obj = strtonum (runid, (String)obj); - - if (obj instanceof Long) - { - n = ((Long)obj).longValue (); - } - else if (obj instanceof Double) - { - n = ((Double)obj).longValue (); - } - else if (obj instanceof Integer) - { - n = ((Integer)obj).longValue (); - } - else if (obj instanceof Short) - { - n = ((Short)obj).longValue (); - } - else if (obj instanceof Float) - { - n = ((Float)obj).longValue (); - } - else n = 0; - } - - return n; - } - - protected double builtinFunctionArgumentToDouble ( - long runid, Object obj) throws Exception - { - double n; - - if (obj == null) n = 0.0; - else - { - if (obj instanceof String) - obj = strtonum (runid, (String)obj); - - if (obj instanceof Long) - { - n = ((Long)obj).doubleValue (); - } - else if (obj instanceof Double) - { - n = ((Double)obj).doubleValue (); - } - else if (obj instanceof Integer) - { - n = ((Integer)obj).doubleValue (); - } - else if (obj instanceof Short) - { - n = ((Short)obj).doubleValue (); - } - else if (obj instanceof Float) - { - n = ((Float)obj).doubleValue (); - } - else n = 0.0; - } - - return n; - } - - protected String builtinFunctionArgumentToString ( - long runid, Object obj) throws Exception - { - String str; - - if (obj == null) str = ""; - else if (obj instanceof String) str = (String)obj; - else str = valtostr (runid, obj); - - return str; - } - - /* == console name setters == */ - protected void setConsoleInputName ( - Extio extio, String name) throws Exception - { - /* TODO: setfilename is not safe. for example, it can - * crash the program if runid is invalid. so this wrapper - * needs to do some sanity check. */ - setfilename (extio.getRunId(), name); - } - - protected void setConsoleOutputName ( - Extio extio, String name) throws Exception - { - setofilename (extio.getRunId(), name); - } - - /* == depth limiting == */ - public int getMaxDepth (int id) - { - return getmaxdepth (id); - } - - public void setMaxDepth (int ids, int depth) - { - setmaxdepth (ids, depth); - } - - /* == option == */ - public int getOption () - { - return getoption (); - } - - public void setOption (int opt) - { - setoption (opt); - } - - /* == debug == */ - public boolean getDebug () - { - return getdebug (); - } - - public void setDebug (boolean debug) - { - setdebug (debug); - } - - /* == source code management == */ - protected abstract int openSource (int mode); - protected abstract int closeSource (int mode); - protected abstract int readSource (char[] buf, int len); - protected abstract int writeSource (char[] buf, int len); - - /* == external io interface == */ - protected int openExtio (Extio extio) - { - int type = extio.getType (); - if (type == Extio.TYPE_CONSOLE) return openConsole (extio); - if (type == Extio.TYPE_FILE) return openFile (extio); - if (type == Extio.TYPE_PIPE) return openPipe (extio); - //if (type == Extio.TYPE_COPROC) return openCoproc (extio); - return -1; - } - - protected int closeExtio (Extio extio) - { - int type = extio.getType (); - if (type == Extio.TYPE_CONSOLE) return closeConsole (extio); - if (type == Extio.TYPE_FILE) return closeFile (extio); - if (type == Extio.TYPE_PIPE) return closePipe (extio); - //if (type == Extio.TYPE_COPROC) return closeCoproc (extio); - return -1; - } - - protected int readExtio (Extio extio, char[] buf, int len) - { - // this check is needed because 0 is used to indicate - // the end of the stream. java streams can return 0 - // if the data given is 0 bytes and it didn't reach - // the end of the stream. - if (len <= 0) return -1; - - int type = extio.getType (); - if (type == Extio.TYPE_CONSOLE) - return readConsole (extio, buf, len); - if (type == Extio.TYPE_FILE) - return readFile (extio, buf, len); - if (type == Extio.TYPE_PIPE) - return readPipe (extio, buf, len); - //if (type == Extio.TYPE_COPROC) - // return readCoproc (extio, buf, len); - return -1; - } - - protected int writeExtio (Extio extio, char[] buf, int len) - { - if (len <= 0) return -1; - - int type = extio.getType (); - if (type == Extio.TYPE_CONSOLE) - return writeConsole (extio, buf, len); - if (type == Extio.TYPE_FILE) - return writeFile (extio, buf, len); - if (type == Extio.TYPE_PIPE) - return writePipe (extio, buf, len); - //if (type == Extio.TYPE_COPROC) - // return writeCoproc (extio, buf, len); - return -1; - } - - protected int flushExtio (Extio extio) - { - int type = extio.getType (); - if (type == Extio.TYPE_CONSOLE) return flushConsole (extio); - if (type == Extio.TYPE_FILE) return flushFile (extio); - if (type == Extio.TYPE_PIPE) return flushPipe (extio); - //if (type == Extio.TYPE_COPROC) return flushCoproc (extio); - return -1; - } - - protected int nextExtio (Extio extio) - { - int type = extio.getType (); - if (type == Extio.TYPE_CONSOLE) return nextConsole (extio); - return -1; - } - - protected abstract int openConsole (Extio extio); - protected abstract int closeConsole (Extio extio); - protected abstract int readConsole (Extio extio, char[] buf, int len); - protected abstract int writeConsole (Extio extio, char[] buf, int len); - protected abstract int flushConsole (Extio extio); - protected abstract int nextConsole (Extio extio); - - protected abstract int openFile (Extio extio); - protected abstract int closeFile (Extio extio); - protected abstract int readFile (Extio extio, char[] buf, int len); - protected abstract int writeFile (Extio extio, char[] buf, int len); - protected abstract int flushFile (Extio extio); - - protected abstract int openPipe (Extio extio); - protected abstract int closePipe (Extio extio); - protected abstract int readPipe (Extio extio, char[] buf, int len); - protected abstract int writePipe (Extio extio, char[] buf, int len); - protected abstract int flushPipe (Extio extio); -} diff --git a/ase/awk/Exception.java b/ase/awk/Exception.java deleted file mode 100644 index 62c9a7e0..00000000 --- a/ase/awk/Exception.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * $Id: Exception.java,v 1.1.1.1 2007/03/28 14:05:12 bacon Exp $ - * - * {License} - */ - -package ase.awk; - -public class Exception extends java.lang.Exception -{ - private int code; - private int line; - - public Exception () - { - super (); - this.code = 0; - this.line = 0; - } - - public Exception (String msg) - { - super (msg); - this.code = 0; - this.line = 0; - } - - public Exception (String msg, int code) - { - super (msg); - this.code = code; - this.line = 0; - } - - public Exception (String msg, int code, int line) - { - super (msg); - this.code = code; - this.line = line; - } - - public int getCode () - { - return this.code; - } - - public int getLine () - { - return this.line; - } -} diff --git a/ase/awk/Extio.java b/ase/awk/Extio.java deleted file mode 100644 index 78b9591f..00000000 --- a/ase/awk/Extio.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * $Id: Extio.java,v 1.1.1.1 2007/03/28 14:05:13 bacon Exp $ - * - * {License} - */ - -package ase.awk; - -public class Extio -{ - public static final int TYPE_PIPE = 0; - public static final int TYPE_COPROC = 1; - public static final int TYPE_FILE = 2; - public static final int TYPE_CONSOLE = 3; - - public static final int MODE_PIPE_READ = 0; - public static final int MODE_PIPE_WRITE = 1; - - public static final int MODE_FILE_READ = 0; - public static final int MODE_FILE_WRITE = 1; - public static final int MODE_FILE_APPEND = 2; - - public static final int MODE_CONSOLE_READ = 0; - public static final int MODE_CONSOLE_WRITE = 1; - - private String name; - private int type; - private int mode; - private long run_id; - private Object handle; - - protected Extio (String name, int type, int mode, long run_id) - { - this.name = name; - this.type = type; - this.mode = mode; - this.run_id = run_id; - this.handle = null; - } - - public String getName () - { - return this.name; - } - - public int getType () - { - return this.type; - } - - public int getMode () - { - return this.mode; - } - - public long getRunId () - { - return this.run_id; - } - - public void setHandle (Object handle) - { - this.handle = handle; - } - - public Object getHandle () - { - return this.handle; - } - - protected void finalize () throws Throwable - { - super.finalize (); - } -}; diff --git a/ase/awk/StdAwk.java b/ase/awk/StdAwk.java deleted file mode 100644 index a595ed78..00000000 --- a/ase/awk/StdAwk.java +++ /dev/null @@ -1,846 +0,0 @@ -/* - * $Id: StdAwk.java,v 1.1.1.1 2007/03/28 14:05:13 bacon Exp $ - * - * {License} - */ - -package ase.awk; - -import java.io.*; - -public abstract class StdAwk extends Awk -{ - private Reader src_in = null; - private Writer src_out = null; - - private String[] sin = null; - private int sin_no = 0; - - private String[] sout = null; - private int sout_no = 0; - - private String[] cin = null; - private int cin_no = 0; - private String[] cout = null; - private int cout_no = 0; - - private long seed; - private java.util.Random random; - - private static Reader stdin = null; - private static Writer stdout = null; - - static - { - stdin = new BufferedReader ( - new InputStreamReader (System.in)); - stdout = new BufferedWriter ( - new OutputStreamWriter (System.out)); - } - - public StdAwk () throws Exception - { - super (); - - seed = System.currentTimeMillis(); - random = new java.util.Random (seed); - } - - /* == major methods == */ - public void parse () throws Exception - { - sin = sourceInputNames (); sin_no = 0; - sout = sourceOutputNames (); sout_no = 0; - super.parse (); - } - - public void run (String main, String[] args) throws Exception - { - cin = consoleInputNames (); cin_no = 0; - cout = consoleOutputNames (); cout_no = 0; - super.run (main, args); - } - - public void run (String main) throws Exception - { - run (main, null); - } - - public void run (String[] args) throws Exception - { - run (null, args); - } - - public void run () throws Exception - { - run (null, null); - } - - - /* == source code names == */ - protected abstract String[] sourceInputNames (); - protected String[] sourceOutputNames () { return null; } - - /* == console names == */ - protected abstract String[] consoleInputNames (); - protected abstract String[] consoleOutputNames (); - - /* == source code == */ - protected int openSource (int mode) - { - if (mode == SOURCE_READ) - { - Reader isr; - sin_no = 0; - - if (sin == null || sin_no >= sin.length) return 0; - - isr = get_stream_reader (sin[sin_no]); - if (isr == null) return -1; - - src_in = isr; - sin_no++; - return 1; - } - else if (mode == SOURCE_WRITE) - { - Writer osw; - sout_no = 0; - - // when sout is null, the source output is treated - // as if the operation has been successful with - // the writeSource and closeSource method. - if (sout == null) return 1; - if (sout_no >= sin.length) return 0; - - osw = get_stream_writer (sout[sout_no]); - if (osw == null) return -1; - - src_out = osw; - sout_no++; - return 1; - } - - return -1; - } - - protected int closeSource (int mode) - { - if (mode == SOURCE_READ) - { - if (src_in != StdAwk.stdin) - { - try { src_in.close (); } - catch (IOException e) { return -1; } - } - return 0; - } - else if (mode == SOURCE_WRITE) - { - if (src_out == null) return 0; - - if (src_out != StdAwk.stdout) - { - try { src_out.close (); } - catch (IOException e) { return -1; } - } - return 0; - } - - return -1; - } - - protected int readSource (char[] buf, int len) - { - try { - int n = src_in.read (buf, 0, len); - while (n == -1) - { - Reader isr; - if (sin == null || sin_no >= sin.length) return 0; - - isr = get_stream_reader (sin[sin_no]); - if (isr == null) return -1; - - if (src_in != StdAwk.stdin) - { - try { src_in.close (); } - catch (IOException ec) { /* ignore */ } - } - - src_in = isr; - sin_no++; - - n = src_in.read (buf, 0, len); - } - - return n; - } - catch (IOException e) - { - return -1; - } - } - - protected int writeSource (char[] buf, int len) - { - if (src_out == null) return len; - - // only the first file is used at the moment. - // this is because the write message doesn't indicate - // the end of the output stream. - try { src_out.write (buf, 0, len); } - catch (IOException e) { return -1; } - - return len; - } - - /* == console interface == */ - protected int openConsole (Extio extio) - { - //System.err.println ("[openConsole called.... name: " + extio.getName() + " mode: " + extio.getMode()); - - int mode = extio.getMode (); - - if (mode == Extio.MODE_CONSOLE_READ) - { - /*InputStream*/Reader isr; - cin_no = 0; - - if (cin == null || cin_no >= cin.length) return 0; - isr = get_stream_reader (cin[cin_no]); - if (isr == null) return -1; - - extio.setHandle (isr); - - try { setConsoleInputName (extio, cin[cin_no]); } - catch (Exception e) { return -1; } - - cin_no++; - return 1; - } - else if (mode == Extio.MODE_CONSOLE_WRITE) - { - Writer osw; - cout_no = 0; - - if (cout == null || cout_no >= cout.length) return 0; - - osw = get_stream_writer (cout[cout_no]); - if (osw == null) return -1; - - extio.setHandle (osw); - try { setConsoleOutputName (extio, cout[cout_no]); } - catch (Exception e) { return -1; } - - cout_no++; - return 1; - } - - return -1; - } - - protected int closeConsole (Extio extio) - { - //System.err.println ("[closeConsole called.... name: " + extio.getName() + " mode: " + extio.getMode()); - - int mode = extio.getMode (); - - if (mode == Extio.MODE_CONSOLE_READ) - { - Reader isr = (Reader)extio.getHandle (); - - if (isr != StdAwk.stdin) - { - try { isr.close (); } - catch (IOException e) { return -1; } - } - return 0; - } - else if (mode == Extio.MODE_CONSOLE_WRITE) - { - Writer osw = (Writer)extio.getHandle (); - /* TODO: selective close the stream... - * system.out should not be closed??? */ - - if (osw != StdAwk.stdout) - { - try { osw.close (); } - catch (IOException e) { return -1; } - } - return 0; - } - - return -1; - } - - protected int readConsole (Extio extio, char[] buf, int len) - { - int mode = extio.getMode (); - - if (mode == Extio.MODE_CONSOLE_READ) - { - Reader isr, tmp; - int n; - - isr = (Reader)extio.getHandle (); - - try { n = isr.read (buf, 0, len); } - catch (IOException e) { return -1; } - - while (n == -1) - { - if (cin == null || cin_no >= cin.length) return 0; - tmp = get_stream_reader (cin[cin_no]); - if (tmp == null) return -1; - - if (isr != StdAwk.stdin) - { - try { isr.close (); } - catch (IOException e) { /* ignore */ } - } - - extio.setHandle (tmp); - try { setConsoleInputName (extio, cin[cin_no]); } - catch (Exception e) { return -1; } - - isr = (Reader)extio.getHandle (); - cin_no++; - - try { n = isr.read (buf, 0, len); } - catch (IOException e) { return -1; } - } - - return n; - } - - return -1; - } - - protected int writeConsole (Extio extio, char[] buf, int len) - { - int mode = extio.getMode (); - - //System.err.println ("[writeConsole called name: " + extio.getName() + " mode: " + extio.getMode()); - - if (mode == Extio.MODE_CONSOLE_WRITE) - { - Writer osw; - - osw = (Writer)extio.getHandle (); - // as the write operation below doesn't - // indicate if it has reached the end, console - // can't be switched here unlike in read_console - try { osw.write (buf, 0, len); osw.flush (); } - catch (IOException e) { return -1; } - - return len; - } - - return -1; - } - - protected int flushConsole (Extio extio) - { - int mode = extio.getMode (); - - if (mode == Extio.MODE_CONSOLE_WRITE) - { - Writer osw; - - osw = (Writer)extio.getHandle (); - - try { osw.flush (); } - catch (IOException e) { return -1; } - - return 0; - } - - return -1; - } - - protected int nextConsole (Extio extio) - { - int mode = extio.getMode (); - - if (mode == Extio.MODE_CONSOLE_READ) - { - Reader isr, tmp; - - isr = (Reader)extio.getHandle (); - - if (cin == null || cin_no >= cin.length) return 0; - tmp = get_stream_reader (cin[cin_no]); - if (tmp == null) return -1; - - if (isr != StdAwk.stdin) - { - try { isr.close (); } - catch (IOException e) { /* ignore */ } - } - - extio.setHandle (tmp); - try { setConsoleInputName (extio, cin[cin_no]); } - catch (Exception e) { return -1; } - - cin_no++; - return 1; - } - else if (mode == Extio.MODE_CONSOLE_WRITE) - { - Writer osw, tmp; - - osw = (Writer)extio.getHandle (); - - if (cout == null || cout_no >= cout.length) return 0; - tmp = get_stream_writer (cout[cout_no]); - if (tmp == null) return -1; - - if (osw != StdAwk.stdout) - { - try { osw.close (); } - catch (IOException e) { /* ignore */ } - } - - extio.setHandle (tmp); - try { setConsoleOutputName (extio, cout[cout_no]); } - catch (Exception e) { return -1;} - - cout_no++; - return 1; - } - - return -1; - } - - private Reader get_stream_reader (String name) - { - Reader isr; - - if (name == null || name.length() == 0) - { - //FileInputStream fis; - //fis = new FileInputStream (FileDescriptor.in); - //isr = new BufferedReader (new InputStreamReader (fis)); - - //isr = new BufferedReader ( - // new InputStreamReader (System.in)); - - isr = StdAwk.stdin; - } - else - { - FileInputStream fis; - try { fis = new FileInputStream (name); } - catch (IOException e) { return null; } - isr = new BufferedReader(new InputStreamReader (fis)); - } - - return isr; - } - - private Writer get_stream_writer (String name) - { - Writer osw; - - if (name == null || name.length() == 0) - { - - //FileOutputStream fos; - //fos = new FileOutputStream (FileDescriptor.out); - //osw = new BufferedWriter (new OutputStreamWriter (fos)); - - //osw = new BufferedWriter( - // new OutputStreamWriter (System.out)); - - osw = StdAwk.stdout; - } - else - { - FileOutputStream fos; - try { fos = new FileOutputStream (name); } - catch (IOException e) { return null; } - osw = new BufferedWriter (new OutputStreamWriter (fos)); - } - - return osw; - } - - /* == file interface == */ - protected int openFile (Extio extio) - { - int mode = extio.getMode(); - - if (mode == Extio.MODE_FILE_READ) - { - FileInputStream fis; - Reader isr; - - try { fis = new FileInputStream (extio.getName()); } - catch (IOException e) { return -1; } - - isr = new BufferedReader (new InputStreamReader (fis)); - extio.setHandle (isr); - return 1; - } - else if (mode == Extio.MODE_FILE_WRITE) - { - FileOutputStream fos; - Writer osw; - - try { fos = new FileOutputStream (extio.getName()); } - catch (IOException e) { return -1; } - - osw = new BufferedWriter (new OutputStreamWriter (fos)); - extio.setHandle (osw); - return 1; - } - else if (mode == Extio.MODE_FILE_APPEND) - { - FileOutputStream fos; - Writer osw; - - try { fos = new FileOutputStream (extio.getName(), true); } - catch (IOException e) { return -1; } - - osw = new BufferedWriter (new OutputStreamWriter (fos)); - extio.setHandle (osw); - return 1; - } - - return -1; - } - - protected int closeFile (Extio extio) - { - int mode = extio.getMode(); - - if (mode == Extio.MODE_FILE_READ) - { - Reader isr; - isr = (Reader)extio.getHandle(); - if (isr != StdAwk.stdin) - { - try { isr.close (); } - catch (IOException e) { return -1; } - } - return 0; - } - else if (mode == Extio.MODE_FILE_WRITE) - { - Writer osw; - osw = (Writer)extio.getHandle(); - if (osw != StdAwk.stdout) - { - try { osw.close (); } - catch (IOException e) { return -1; } - } - return 0; - } - else if (mode == Extio.MODE_FILE_APPEND) - { - Writer osw; - osw = (Writer)extio.getHandle(); - if (osw != StdAwk.stdout) - { - try { osw.close (); } - catch (IOException e) { return -1; } - } - return 0; - } - - return -1; - } - - protected int readFile (Extio extio, char[] buf, int len) - { - int mode = extio.getMode(); - - if (mode == Extio.MODE_FILE_READ) - { - Reader isr; - isr = (Reader)extio.getHandle(); - - try - { - len = isr.read (buf, 0, len); - if (len == -1) len = 0; - } - catch (IOException e) { len = -1; } - return len; - } - - return -1; - } - - protected int writeFile (Extio extio, char[] buf, int len) - { - int mode = extio.getMode(); - - if (mode == Extio.MODE_FILE_WRITE || - mode == Extio.MODE_FILE_APPEND) - { - Writer osw; - osw = (Writer)extio.getHandle(); - try { osw.write (buf, 0, len); } - catch (IOException e) { len = -1; } - return len; - } - - return -1; - } - - protected int flushFile (Extio extio) - { - int mode = extio.getMode (); - - if (mode == Extio.MODE_FILE_WRITE || - mode == Extio.MODE_FILE_APPEND) - { - Writer osw; - osw = (Writer)extio.getHandle (); - try { osw.flush (); } - catch (IOException e) { return -1; } - return 0; - } - - return -1; - } - - /* == pipe interface == */ - protected int openPipe (Extio extio) - { - int mode = extio.getMode(); - - if (mode == Extio.MODE_PIPE_READ) - { - - Process proc; - Reader isr; - - try { proc = popen (extio.getName()); } - catch (IOException e) { return -1; } - - isr = new BufferedReader (new InputStreamReader (proc.getInputStream())); - extio.setHandle (isr); - return 1; - } - else if (mode == Extio.MODE_PIPE_WRITE) - { - Process proc; - Writer osw; - - try { proc = popen (extio.getName()); } - catch (IOException e) { return -1; } - - osw = new BufferedWriter (new OutputStreamWriter (proc.getOutputStream())); - extio.setHandle (osw); - return 1; - } - - return -1; - } - - protected int closePipe (Extio extio) - { - int mode = extio.getMode(); - - if (mode == Extio.MODE_PIPE_READ) - { - Reader isr; - isr = (Reader)extio.getHandle(); - if (isr != StdAwk.stdin) - { - try { isr.close (); } - catch (IOException e) { return -1; } - } - return 0; - } - else if (mode == Extio.MODE_PIPE_WRITE) - { - Writer osw; - osw = (Writer)extio.getHandle(); - if (osw != StdAwk.stdout) - { - try { osw.close (); } - catch (IOException e) { return -1; } - } - return 0; - } - - return -1; - } - - protected int readPipe (Extio extio, char[] buf, int len) - { - int mode = extio.getMode(); - - if (mode == Extio.MODE_PIPE_READ) - { - Reader isr; - isr = (Reader)extio.getHandle(); - - try - { - len = isr.read (buf, 0, len); - if (len == -1) len = 0; - } - catch (IOException e) { len = -1; } - return len; - } - - return -1; - } - - protected int writePipe (Extio extio, char[] buf, int len) - { - int mode = extio.getMode(); - - if (mode == Extio.MODE_PIPE_WRITE) - { - Writer osw; - osw = (Writer)extio.getHandle(); - try { osw.write (buf, 0, len); } - catch (IOException e) { len = -1; } - return len; - } - - return -1; - } - - protected int flushPipe (Extio extio) - { - int mode = extio.getMode (); - - if (mode == Extio.MODE_PIPE_WRITE) - { - Writer osw; - osw = (Writer)extio.getHandle (); - try { osw.flush (); } - catch (IOException e) { return -1; } - return 0; - } - - return -1; - } - - - /* == arithmetic built-in functions */ - public Object sin (long runid, Object[] args) throws Exception - { - double x = builtinFunctionArgumentToDouble (runid, args[0]); - return new Double (Math.sin(x)); - } - - public Object cos (long runid, Object[] args) throws Exception - { - double x = builtinFunctionArgumentToDouble (runid, args[0]); - return new Double (Math.cos(x)); - } - - public Object tan (long runid, Object[] args) throws Exception - { - double x = builtinFunctionArgumentToDouble (runid, args[0]); - return new Double (Math.tan(x)); - } - - public Object atan2 (long runid, Object[] args) throws Exception - { - double y = builtinFunctionArgumentToDouble (runid, args[0]); - double x = builtinFunctionArgumentToDouble (runid, args[1]); - return new Double (Math.atan2(y,x)); - } - - public Object log (long runid, Object[] args) throws Exception - { - double x = builtinFunctionArgumentToDouble (runid, args[0]); - return new Double (Math.log(x)); - } - - public Object exp (long runid, Object[] args) throws Exception - { - double x = builtinFunctionArgumentToDouble (runid, args[0]); - return new Double (Math.exp(x)); - } - - public Object sqrt (long runid, Object[] args) throws Exception - { - double x = builtinFunctionArgumentToDouble (runid, args[0]); - return new Double (Math.sqrt(x)); - } - - public Object rand (long runid, Object[] args) - { - return new Double (random.nextDouble ()); - } - - public Object srand (long runid, Object[] args) throws Exception - { - long prev_seed = seed; - - seed = (args == null || args.length == 0)? - System.currentTimeMillis (): - builtinFunctionArgumentToLong (runid, args[0]); - - random.setSeed (seed); - return new Long (prev_seed); - } - - /* miscellaneous built-in functions */ - public Object system (long runid, Object[] args) throws Exception - { - String str = builtinFunctionArgumentToString (runid, args[0]); - Process proc = null; - int n = 0; - - str = builtinFunctionArgumentToString (runid, args[0]); - - try { proc = popen (str); } - catch (IOException e) { n = -1; } - - if (proc != null) - { - InputStream is; - byte[] buf = new byte[1024]; - - is = proc.getInputStream(); - - // TODO; better error handling... program execution.. io redirection??? - try { while (is.read (buf) != -1) ; } - catch (IOException e) { n = -1; }; - - try { n = proc.waitFor (); } - catch (InterruptedException e) - { - proc.destroy (); - n = -1; - } - } - - return new Long (n); - } - - /* == utility functions == */ - private Process popen (String command) throws IOException - { - String full; - - /* TODO: consider OS names and versions */ - full = System.getenv ("ComSpec"); - if (full != null) - { - full = full + " /c " + command; - } - else - { - full = System.getenv ("SHELL"); - if (full != null) - { - full = "/bin/sh -c \"" + command + "\""; - } - else full = command; - } - - return Runtime.getRuntime().exec (full); - } -} diff --git a/ase/awk/aseawk.dsp b/ase/awk/aseawk.dsp deleted file mode 100644 index 8387e03b..00000000 --- a/ase/awk/aseawk.dsp +++ /dev/null @@ -1,202 +0,0 @@ -# Microsoft Developer Studio Project File - Name="aseawk" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Static Library" 0x0104 - -CFG=aseawk - Win32 Release -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "aseawk.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "aseawk.mak" CFG="aseawk - Win32 Release" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "aseawk - Win32 Release" (based on "Win32 (x86) Static Library") -!MESSAGE "aseawk - Win32 Debug" (based on "Win32 (x86) Static Library") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -RSC=rc.exe - -!IF "$(CFG)" == "aseawk - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "../release/lib" -# PROP Intermediate_Dir "release" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -MTL=midl.exe -# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_UNICODE" /D "_USRDLL" /Yu"stdafx.h" /FD /c -# ADD CPP /nologo /MT /Za /W3 /GX /O2 /I "..\.." /D "NDEBUG" /D "WIN32" /D "_UNICODE" /FD /c -# SUBTRACT CPP /YX /Yc /Yu -# ADD BASE RSC /l 0x409 /d "NDEBUG" -# ADD RSC /l 0x409 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LIB32=link.exe -lib -# ADD BASE LIB32 /nologo -# ADD LIB32 /nologo - -!ELSEIF "$(CFG)" == "aseawk - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "../debug/lib" -# PROP Intermediate_Dir "debug" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -MTL=midl.exe -# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_UNICODE" /D "_USRDLL" /Yu"stdafx.h" /FD /GZ /c -# ADD CPP /nologo /MTd /Za /W3 /Gm /GX /ZI /Od /I "..\.." /D "_DEBUG" /D "WIN32" /D "_UNICODE" /FD /GZ /c -# SUBTRACT CPP /YX /Yc /Yu -# ADD BASE RSC /l 0x409 /d "_DEBUG" -# ADD RSC /l 0x409 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LIB32=link.exe -lib -# ADD BASE LIB32 /nologo -# ADD LIB32 /nologo - -!ENDIF - -# Begin Target - -# Name "aseawk - Win32 Release" -# Name "aseawk - Win32 Debug" -# Begin Group "Source Files" - -# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" -# Begin Source File - -SOURCE=.\awk.c -# End Source File -# Begin Source File - -SOURCE=.\err.c -# End Source File -# Begin Source File - -SOURCE=.\extio.c -# End Source File -# Begin Source File - -SOURCE=.\func.c -# End Source File -# Begin Source File - -SOURCE=.\map.c -# End Source File -# Begin Source File - -SOURCE=.\misc.c -# End Source File -# Begin Source File - -SOURCE=.\parse.c -# End Source File -# Begin Source File - -SOURCE=.\rec.c -# End Source File -# Begin Source File - -SOURCE=.\rex.c -# End Source File -# Begin Source File - -SOURCE=.\run.c -# End Source File -# Begin Source File - -SOURCE=.\tab.c -# End Source File -# Begin Source File - -SOURCE=.\tree.c -# End Source File -# Begin Source File - -SOURCE=.\val.c -# End Source File -# End Group -# Begin Group "Header Files" - -# PROP Default_Filter "h;hpp;hxx;hm;inl" -# Begin Source File - -SOURCE=.\awk.h -# End Source File -# Begin Source File - -SOURCE=.\awk_i.h -# End Source File -# Begin Source File - -SOURCE=.\extio.h -# End Source File -# Begin Source File - -SOURCE=.\func.h -# End Source File -# Begin Source File - -SOURCE=.\map.h -# End Source File -# Begin Source File - -SOURCE=.\parse.h -# End Source File -# Begin Source File - -SOURCE=.\rex.h -# End Source File -# Begin Source File - -SOURCE=.\run.h -# End Source File -# Begin Source File - -SOURCE=.\tab.h -# End Source File -# Begin Source File - -SOURCE=.\tree.h -# End Source File -# Begin Source File - -SOURCE=.\val.h -# End Source File -# End Group -# Begin Group "Resource Files" - -# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" -# End Group -# End Target -# End Project diff --git a/ase/awk/aseawk_jni.dsp b/ase/awk/aseawk_jni.dsp deleted file mode 100644 index 4e8679ec..00000000 --- a/ase/awk/aseawk_jni.dsp +++ /dev/null @@ -1,113 +0,0 @@ -# Microsoft Developer Studio Project File - Name="aesawk_jni" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 - -CFG=aesawk_jni - Win32 Debug -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "aseawk_jni.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "aseawk_jni.mak" CFG="aesawk_jni - Win32 Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "aesawk_jni - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE "aesawk_jni - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -MTL=midl.exe -RSC=rc.exe - -!IF "$(CFG)" == "aesawk_jni - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "../release/lib" -# PROP Intermediate_Dir "release" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "JNI_EXPORTS" /YX /FD /c -# ADD CPP /nologo /MT /W3 /GX /O2 /I "..\.." /I "C:\Program Files\java\jdk1.5.0_09\include" /I "C:\Program Files\java\jdk1.5.0_09\include\win32" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_UNICODE" /D "_USRDLL" /FD /c -# SUBTRACT CPP /YX -# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0x409 /d "NDEBUG" -# ADD RSC /l 0x409 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 -# ADD LINK32 asecmn.lib aseawk.lib aseutl.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /implib:"release/aseawk_jni.lib" /libpath:"$(OutDir)" - -!ELSEIF "$(CFG)" == "aesawk_jni - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "../debug/lib" -# PROP Intermediate_Dir "debug" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "JNI_EXPORTS" /YX /FD /GZ /c -# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "..\.." /I "C:\Program Files\java\jdk1.5.0_09\include" /I "C:\Program Files\java\jdk1.5.0_09\include\win32" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_UNICODE" /D "_USRDLL" /FD /GZ /c -# SUBTRACT CPP /YX -# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0x409 /d "_DEBUG" -# ADD RSC /l 0x409 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept -# ADD LINK32 asecmn.lib aseawk.lib aseutl.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /implib:"debug/aseawk_jni.lib" /pdbtype:sept /libpath:"$(OutDir)" - -!ENDIF - -# Begin Target - -# Name "aesawk_jni - Win32 Release" -# Name "aesawk_jni - Win32 Debug" -# Begin Group "Source Files" - -# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" -# Begin Source File - -SOURCE=.\jni.c -# End Source File -# End Group -# Begin Group "Header Files" - -# PROP Default_Filter "h;hpp;hxx;hm;inl" -# Begin Source File - -SOURCE=.\jni.h -# End Source File -# End Group -# Begin Group "Resource Files" - -# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" -# End Group -# End Target -# End Project diff --git a/ase/awk/awk.c b/ase/awk/awk.c deleted file mode 100644 index e65c0851..00000000 --- a/ase/awk/awk.c +++ /dev/null @@ -1,256 +0,0 @@ -/* - * $Id: awk.c,v 1.1.1.1 2007/03/28 14:05:13 bacon Exp $ - * - * {License} - */ - -#if defined(__BORLANDC__) -#pragma hdrstop -#define Library -#endif - -#include - -static void free_afn (void* awk, void* afn); - -ase_awk_t* ase_awk_open (const ase_awk_prmfns_t* prmfns, void* custom_data) -{ - ase_awk_t* awk; - - ASE_ASSERT (prmfns != ASE_NULL); - - ASE_ASSERT (prmfns->mmgr.malloc != ASE_NULL && - prmfns->mmgr.free != ASE_NULL); - - ASE_ASSERT (prmfns->ccls.is_upper != ASE_NULL && - prmfns->ccls.is_lower != ASE_NULL && - prmfns->ccls.is_alpha != ASE_NULL && - prmfns->ccls.is_digit != ASE_NULL && - prmfns->ccls.is_xdigit != ASE_NULL && - prmfns->ccls.is_alnum != ASE_NULL && - prmfns->ccls.is_space != ASE_NULL && - prmfns->ccls.is_print != ASE_NULL && - prmfns->ccls.is_graph != ASE_NULL && - prmfns->ccls.is_cntrl != ASE_NULL && - prmfns->ccls.is_punct != ASE_NULL && - prmfns->ccls.to_upper != ASE_NULL && - prmfns->ccls.to_lower != ASE_NULL); - - ASE_ASSERT (prmfns->misc.pow != ASE_NULL && - prmfns->misc.sprintf != ASE_NULL && - prmfns->misc.dprintf != ASE_NULL); - -#if defined(_WIN32) && defined(_MSC_VER) && defined(_DEBUG) - awk = (ase_awk_t*) malloc (ASE_SIZEOF(ase_awk_t)); -#else - awk = (ase_awk_t*) prmfns->mmgr.malloc ( - prmfns->mmgr.custom_data, ASE_SIZEOF(ase_awk_t)); -#endif - if (awk == ASE_NULL) return ASE_NULL; - - /* it uses the built-in ase_awk_memset because awk is not - * fully initialized yet */ - ase_memset (awk, 0, ASE_SIZEOF(ase_awk_t)); - ase_memcpy (&awk->prmfns, prmfns, ASE_SIZEOF(awk->prmfns)); - - if (ase_str_open ( - &awk->token.name, 128, &awk->prmfns.mmgr) == ASE_NULL) - { - ASE_AWK_FREE (awk, awk); - return ASE_NULL; - } - - /* TODO: initial map size?? */ - if (ase_awk_map_open ( - &awk->tree.afns, awk, 256, free_afn, awk) == ASE_NULL) - { - ase_str_close (&awk->token.name); - ASE_AWK_FREE (awk, awk); - return ASE_NULL; - } - - if (ase_awk_tab_open (&awk->parse.globals, awk) == ASE_NULL) - { - ase_str_close (&awk->token.name); - ase_awk_map_close (&awk->tree.afns); - ASE_AWK_FREE (awk, awk); - return ASE_NULL; - } - - if (ase_awk_tab_open (&awk->parse.locals, awk) == ASE_NULL) - { - ase_str_close (&awk->token.name); - ase_awk_map_close (&awk->tree.afns); - ase_awk_tab_close (&awk->parse.globals); - ASE_AWK_FREE (awk, awk); - return ASE_NULL; - } - - if (ase_awk_tab_open (&awk->parse.params, awk) == ASE_NULL) - { - ase_str_close (&awk->token.name); - ase_awk_map_close (&awk->tree.afns); - ase_awk_tab_close (&awk->parse.globals); - ase_awk_tab_close (&awk->parse.locals); - ASE_AWK_FREE (awk, awk); - return ASE_NULL; - } - - awk->option = 0; - awk->errnum = ASE_AWK_ENOERR; - awk->errlin = 0; - - awk->parse.nlocals_max = 0; - - awk->tree.nglobals = 0; - awk->tree.nbglobals = 0; - awk->tree.begin = ASE_NULL; - awk->tree.end = ASE_NULL; - awk->tree.chain = ASE_NULL; - awk->tree.chain_tail = ASE_NULL; - awk->tree.chain_size = 0; - - awk->token.prev.type = 0; - awk->token.prev.line = 0; - awk->token.prev.column = 0; - awk->token.type = 0; - awk->token.line = 0; - awk->token.column = 0; - - awk->src.lex.curc = ASE_CHAR_EOF; - awk->src.lex.ungotc_count = 0; - awk->src.lex.line = 1; - awk->src.lex.column = 1; - awk->src.shared.buf_pos = 0; - awk->src.shared.buf_len = 0; - - awk->bfn.sys = ASE_NULL; - awk->bfn.user = ASE_NULL; - - awk->parse.depth.cur.block = 0; - awk->parse.depth.cur.loop = 0; - awk->parse.depth.cur.expr = 0; - - ase_awk_setmaxdepth (awk, ASE_AWK_DEPTH_BLOCK_PARSE, 0); - ase_awk_setmaxdepth (awk, ASE_AWK_DEPTH_BLOCK_RUN, 0); - ase_awk_setmaxdepth (awk, ASE_AWK_DEPTH_EXPR_PARSE, 0); - ase_awk_setmaxdepth (awk, ASE_AWK_DEPTH_EXPR_RUN, 0); - ase_awk_setmaxdepth (awk, ASE_AWK_DEPTH_REX_BUILD, 0); - ase_awk_setmaxdepth (awk, ASE_AWK_DEPTH_REX_MATCH, 0); - - awk->custom_data = custom_data; - return awk; -} - -static void free_afn (void* owner, void* afn) -{ - ase_awk_afn_t* f = (ase_awk_afn_t*)afn; - - /* f->name doesn't have to be freed */ - /*ASE_AWK_FREE ((ase_awk_t*)owner, f->name);*/ - - ase_awk_clrpt ((ase_awk_t*)owner, f->body); - ASE_AWK_FREE ((ase_awk_t*)owner, f); -} - -int ase_awk_close (ase_awk_t* awk) -{ - ase_size_t i; - - if (ase_awk_clear (awk) == -1) return -1; - ase_awk_clrbfn (awk); - - ase_awk_map_close (&awk->tree.afns); - ase_awk_tab_close (&awk->parse.globals); - ase_awk_tab_close (&awk->parse.locals); - ase_awk_tab_close (&awk->parse.params); - ase_str_close (&awk->token.name); - - for (i = 0; i < ASE_COUNTOF(awk->errstr); i++) - { - if (awk->errstr[i] != ASE_NULL) - { - ASE_AWK_FREE (awk, awk->errstr[i]); - awk->errstr[i] = ASE_NULL; - } - } - - /* ASE_AWK_ALLOC, ASE_AWK_FREE, etc can not be used - * from the next line onwards */ - ASE_AWK_FREE (awk, awk); - return 0; -} - -int ase_awk_clear (ase_awk_t* awk) -{ - ase_memset (&awk->src.ios, 0, ASE_SIZEOF(awk->src.ios)); - awk->src.lex.curc = ASE_CHAR_EOF; - awk->src.lex.ungotc_count = 0; - awk->src.lex.line = 1; - awk->src.lex.column = 1; - awk->src.shared.buf_pos = 0; - awk->src.shared.buf_len = 0; - - ase_awk_tab_clear (&awk->parse.globals); - ase_awk_tab_clear (&awk->parse.locals); - ase_awk_tab_clear (&awk->parse.params); - - awk->parse.nlocals_max = 0; - awk->parse.depth.cur.block = 0; - awk->parse.depth.cur.loop = 0; - awk->parse.depth.cur.expr = 0; - - /* clear parse trees */ - awk->tree.ok = 0; - awk->tree.nbglobals = 0; - awk->tree.nglobals = 0; - awk->tree.cur_afn.ptr = ASE_NULL; - awk->tree.cur_afn.len = 0; - ase_awk_map_clear (&awk->tree.afns); - - if (awk->tree.begin != ASE_NULL) - { - ASE_ASSERT (awk->tree.begin->next == ASE_NULL); - ase_awk_clrpt (awk, awk->tree.begin); - awk->tree.begin = ASE_NULL; - } - - if (awk->tree.end != ASE_NULL) - { - ASE_ASSERT (awk->tree.end->next == ASE_NULL); - ase_awk_clrpt (awk, awk->tree.end); - awk->tree.end = ASE_NULL; - } - - while (awk->tree.chain != ASE_NULL) - { - ase_awk_chain_t* next = awk->tree.chain->next; - - if (awk->tree.chain->pattern != ASE_NULL) - ase_awk_clrpt (awk, awk->tree.chain->pattern); - if (awk->tree.chain->action != ASE_NULL) - ase_awk_clrpt (awk, awk->tree.chain->action); - ASE_AWK_FREE (awk, awk->tree.chain); - awk->tree.chain = next; - } - - awk->tree.chain_tail = ASE_NULL; - awk->tree.chain_size = 0; - - return 0; -} - -int ase_awk_getoption (ase_awk_t* awk) -{ - return awk->option; -} - -void ase_awk_setoption (ase_awk_t* awk, int opt) -{ - awk->option = opt; -} - -void* ase_awk_getcustomdata (ase_awk_t* awk) -{ - return awk->custom_data; -} diff --git a/ase/awk/awk.h b/ase/awk/awk.h deleted file mode 100644 index ceab4ba3..00000000 --- a/ase/awk/awk.h +++ /dev/null @@ -1,502 +0,0 @@ -/* - * $Id: awk.h,v 1.1.1.1 2007/03/28 14:05:15 bacon Exp $ - * - * {License} - */ - -#ifndef _ASE_AWK_AWK_H_ -#define _ASE_AWK_AWK_H_ - -#include -#include - -typedef struct ase_awk_t ase_awk_t; -typedef struct ase_awk_run_t ase_awk_run_t; -typedef struct ase_awk_val_t ase_awk_val_t; -typedef struct ase_awk_map_t ase_awk_map_t; -typedef struct ase_awk_extio_t ase_awk_extio_t; - -typedef struct ase_awk_prmfns_t ase_awk_prmfns_t; -typedef struct ase_awk_srcios_t ase_awk_srcios_t; -typedef struct ase_awk_runios_t ase_awk_runios_t; -typedef struct ase_awk_runcbs_t ase_awk_runcbs_t; -typedef struct ase_awk_runarg_t ase_awk_runarg_t; - -typedef ase_real_t (*ase_awk_pow_t) (void* custom, ase_real_t x, ase_real_t y); -typedef int (*ase_awk_sprintf_t) ( - void* custom, ase_char_t* buf, ase_size_t size, - const ase_char_t* fmt, ...); -typedef void (*ase_awk_dprintf_t) (void* custom, const ase_char_t* fmt, ...); - -typedef ase_ssize_t (*ase_awk_io_t) ( - int cmd, void* arg, ase_char_t* data, ase_size_t count); - -struct ase_awk_extio_t -{ - ase_awk_run_t* run; /* [IN] */ - int type; /* [IN] console, file, coproc, pipe */ - int mode; /* [IN] read, write, etc */ - ase_char_t* name; /* [IN] */ - void* custom_data; /* [IN] */ - void* handle; /* [OUT] */ - - /* input */ - struct - { - ase_char_t buf[2048]; - ase_size_t pos; - ase_size_t len; - ase_bool_t eof; - ase_bool_t eos; - } in; - - /* output */ - struct - { - ase_bool_t eof; - ase_bool_t eos; - } out; - - ase_awk_extio_t* next; -}; - -struct ase_awk_prmfns_t -{ - ase_mmgr_t mmgr; - ase_ccls_t ccls; - - struct - { - /* utilities */ - ase_awk_pow_t pow; /* required */ - ase_awk_sprintf_t sprintf; /* required */ - ase_awk_dprintf_t dprintf; /* required in the debug mode */ - - /* user-defined data passed to the functions above */ - void* custom_data; /* optional */ - } misc; -}; - -struct ase_awk_srcios_t -{ - ase_awk_io_t in; - ase_awk_io_t out; - void* custom_data; -}; - -struct ase_awk_runios_t -{ - ase_awk_io_t pipe; - ase_awk_io_t coproc; - ase_awk_io_t file; - ase_awk_io_t console; - void* custom_data; -}; - -struct ase_awk_runcbs_t -{ - void (*on_start) ( - ase_awk_run_t* run, void* custom_data); - - void (*on_statement) ( - ase_awk_run_t* run, ase_size_t line, void* custom_data); - - void (*on_return) ( - ase_awk_run_t* run, ase_awk_val_t* ret, void* custom_data); - - void (*on_end) ( - ase_awk_run_t* run, int errnum, void* custom_data); - - void* custom_data; -}; - -struct ase_awk_runarg_t -{ - ase_char_t* ptr; - ase_size_t len; -}; - -/* io function commands */ -enum -{ - ASE_AWK_IO_OPEN = 0, - ASE_AWK_IO_CLOSE = 1, - ASE_AWK_IO_READ = 2, - ASE_AWK_IO_WRITE = 3, - ASE_AWK_IO_FLUSH = 4, - ASE_AWK_IO_NEXT = 5 -}; - -/* various options */ -enum -{ - /* allow undeclared variables and implicit concatenation */ - ASE_AWK_IMPLICIT = (1 << 0), - - /* allow explicit variable declaration and the concatenation - * operator, a period. */ - ASE_AWK_EXPLICIT = (1 << 1), - - /* a function name should not coincide to be a variable name */ - ASE_AWK_UNIQUEFN = (1 << 2), - - /* allow variable shading */ - ASE_AWK_SHADING = (1 << 3), - - /* support shift operators */ - ASE_AWK_SHIFT = (1 << 4), - - /* enable the idiv operator (double slashes) */ - ASE_AWK_IDIV = (1 << 5), - - /* support string concatenation in tokenization. - * this option can change the behavior of a certain construct. - * getline < "abc" ".def" is treated as if it is getline < "abc.def" - * when this option is on. If this option is off, the same expression - * is treated as if it is (getline < "abc") ".def". */ - ASE_AWK_STRCONCAT = (1 << 6), - - /* support getline and print */ - ASE_AWK_EXTIO = (1 << 7), - - /* support co-process */ - ASE_AWK_COPROC = (1 << 8), - - /* support blockless patterns */ - ASE_AWK_BLOCKLESS = (1 << 9), - - /* use 1 as the start index for string operations */ - ASE_AWK_STRBASEONE = (1 << 10), - - /* strip off leading and trailing spaces when splitting a record - * into fields with a regular expression. - * - * Consider the following program. - * BEGIN { FS="[:[:space:]]+"; } - * { - * print "NF=" NF; - * for (i = 0; i < NF; i++) print i " [" $(i+1) "]"; - * } - * - * The program splits " a b c " into [a], [b], [c] when this - * option is on while into [], [a], [b], [c], [] when it is off. - */ - ASE_AWK_STRIPSPACES = (1 << 11), - - /* enable the nextoutfile keyword */ - ASE_AWK_NEXTOFILE = (1 << 12), - - /* cr + lf by default */ - ASE_AWK_CRLF = (1 << 13) -}; - -/* error code */ -enum -{ - ASE_AWK_ENOERR, /* no error */ - - ASE_AWK_EINVAL, /* invalid parameter */ - ASE_AWK_ENOMEM, /* out of memory */ - ASE_AWK_ENOSUP, /* not supported */ - ASE_AWK_ENOPER, /* operation not allowed */ - ASE_AWK_ENODEV, /* function '%.*s' not found */ - ASE_AWK_ENOSPC, /* no space left on device */ - ASE_AWK_EMFILE, /* too many open files */ - ASE_AWK_EMLINK, /* too many links */ - ASE_AWK_EAGAIN, /* resource temporarily unavailable */ - ASE_AWK_ENOENT, /* file or data not existing */ - ASE_AWK_EEXIST, /* file or data exists */ - ASE_AWK_EFTBIG, /* file or data too big */ - ASE_AWK_ETBUSY, /* system too busy */ - ASE_AWK_EISDIR, /* is a directory */ - ASE_AWK_EIOERR, /* i/o error */ - - ASE_AWK_EOPEN, /* cannot open */ - ASE_AWK_EREAD, /* cannot read */ - ASE_AWK_EWRITE, /* cannot write */ - ASE_AWK_ECLOSE, /* cannot close */ - - ASE_AWK_EINTERN, /* internal error */ - ASE_AWK_ERUNTIME, /* run-time error */ - ASE_AWK_EBLKNST, /* blocke nested too deeply */ - ASE_AWK_EEXPRNST, /* expression nested too deeply */ - - ASE_AWK_ESINOP, - ASE_AWK_ESINCL, - ASE_AWK_ESINRD, - - ASE_AWK_ESOUTOP, - ASE_AWK_ESOUTCL, - ASE_AWK_ESOUTWR, - - ASE_AWK_ELXCHR, /* lexer came accross an wrong character */ - ASE_AWK_ELXUNG, /* lexer failed to unget a character */ - - ASE_AWK_EENDSRC, /* unexpected end of source */ - ASE_AWK_EENDCMT, /* a comment not closed properly */ - ASE_AWK_EENDSTR, /* a string not closed with a quote */ - ASE_AWK_EENDREX, /* unexpected end of a regular expression */ - ASE_AWK_ELBRACE, /* left brace expected */ - ASE_AWK_ELPAREN, /* left parenthesis expected */ - ASE_AWK_ERPAREN, /* right parenthesis expected */ - ASE_AWK_ERBRACK, /* right bracket expected */ - ASE_AWK_ECOMMA, /* comma expected */ - ASE_AWK_ESCOLON, /* semicolon expected */ - ASE_AWK_ECOLON, /* colon expected */ - ASE_AWK_ESTMEND, /* statement not ending with a semicolon */ - ASE_AWK_EIN, /* keyword 'in' is expected */ - ASE_AWK_ENOTVAR, /* not a variable name after 'in' */ - ASE_AWK_EEXPRES, /* expression expected */ - - ASE_AWK_EWHILE, /* keyword 'while' is expected */ - ASE_AWK_EASSIGN, /* assignment statement expected */ - ASE_AWK_EIDENT, /* identifier expected */ - ASE_AWK_EFNNAME, /* not a valid function name */ - ASE_AWK_EBLKBEG, /* BEGIN requires an action block */ - ASE_AWK_EBLKEND, /* END requires an action block */ - ASE_AWK_EDUPBEG, /* duplicate BEGIN */ - ASE_AWK_EDUPEND, /* duplicate END */ - ASE_AWK_EBFNRED, /* builtin function redefined */ - ASE_AWK_EAFNRED, /* function redefined */ - ASE_AWK_EGBLRED, /* global variable redefined */ - ASE_AWK_EPARRED, /* parameter redefined */ - ASE_AWK_EDUPPAR, /* duplicate parameter name */ - ASE_AWK_EDUPGBL, /* duplicate global variable name */ - ASE_AWK_EDUPLCL, /* duplicate local variable name */ - ASE_AWK_EBADPAR, /* not a valid parameter name */ - ASE_AWK_EBADVAR, /* not a valid variable name */ - ASE_AWK_EUNDEF, /* undefined identifier */ - ASE_AWK_ELVALUE, /* l-value required */ - ASE_AWK_EGBLTM, /* too many global variables */ - ASE_AWK_ELCLTM, /* too many local variables */ - ASE_AWK_EPARTM, /* too many parameters */ - ASE_AWK_EDELETE, /* delete not followed by a variable */ - ASE_AWK_EBREAK, /* break outside a loop */ - ASE_AWK_ECONTINUE, /* continue outside a loop */ - ASE_AWK_ENEXTBEG, /* next illegal in BEGIN block */ - ASE_AWK_ENEXTEND, /* next illegal in END block */ - ASE_AWK_ENEXTFBEG, /* nextfile illegal in BEGIN block */ - ASE_AWK_ENEXTFEND, /* nextfile illegal in END block */ - ASE_AWK_EPRINTFARG, /* printf not followed by any arguments */ - ASE_AWK_EPREPST, /* both prefix and postfix increment/decrement - operator present */ - ASE_AWK_EGLNCPS, /* coprocess not supported by getline */ - - /* run time error */ - ASE_AWK_EDIVBY0, /* divide by zero */ - ASE_AWK_EOPERAND, /* invalid operand */ - ASE_AWK_EPOSIDX, /* wrong position index */ - ASE_AWK_EARGTF, /* too few arguments */ - ASE_AWK_EARGTM, /* too many arguments */ - ASE_AWK_EFNNONE, /* no such function */ - ASE_AWK_ENOTIDX, /* variable not indexable */ - ASE_AWK_ENOTDEL, /* variable not deletable */ - ASE_AWK_ENOTMAP, /* value not a map */ - ASE_AWK_ENOTMAPIN, /* right-hand side of 'in' not a map */ - ASE_AWK_ENOTMAPNILIN, /* right-hand side of 'in' not a map nor nil */ - ASE_AWK_ENOTREF, /* value not referenceable */ - ASE_AWK_ENOTASS, /* value not assignable */ - ASE_AWK_EIDXVALASSMAP, /* indexed value cannot be assigned a map */ - ASE_AWK_EPOSVALASSMAP, /* a positional cannot be assigned a map */ - ASE_AWK_EMAPTOSCALAR, /* cannot change a map to a scalar value */ - ASE_AWK_ESCALARTOMAP, /* cannot change a scalar value to a map */ - ASE_AWK_EMAPNOTALLOWED, /* a map is not allowed */ - ASE_AWK_EVALTYPE, /* wrong value type */ - ASE_AWK_ERDELETE, /* delete called with a wrong target */ - ASE_AWK_ERNEXTBEG, /* next called from BEGIN */ - ASE_AWK_ERNEXTEND, /* next called from END */ - ASE_AWK_ERNEXTFBEG, /* nextfile called from BEGIN */ - ASE_AWK_ERNEXTFEND, /* nextfile called from END */ - ASE_AWK_EBFNUSER, /* wrong builtin function implementation */ - ASE_AWK_EBFNIMPL, /* builtin function handler failed */ - ASE_AWK_EIOUSER, /* wrong user io handler implementation */ - ASE_AWK_EIONONE, /* no such io name found */ - ASE_AWK_EIOIMPL, /* i/o callback returned an error */ - ASE_AWK_EIONMEM, /* i/o name empty */ - ASE_AWK_EIONMNL, /* i/o name contains '\0' */ - ASE_AWK_EFMTARG, /* arguments to format string not sufficient */ - ASE_AWK_EFMTCNV, /* recursion detected in format conversion */ - ASE_AWK_ECONVFMTCHR, /* an invalid character found in CONVFMT */ - ASE_AWK_EOFMTCHR, /* an invalid character found in OFMT */ - - /* regular expression error */ - ASE_AWK_EREXRECUR, /* recursion too deep */ - ASE_AWK_EREXRPAREN, /* a right parenthesis is expected */ - ASE_AWK_EREXRBRACKET, /* a right bracket is expected */ - ASE_AWK_EREXRBRACE, /* a right brace is expected */ - ASE_AWK_EREXUNBALPAR, /* unbalanced parenthesis */ - ASE_AWK_EREXCOLON, /* a colon is expected */ - ASE_AWK_EREXCRANGE, /* invalid character range */ - ASE_AWK_EREXCCLASS, /* invalid character class */ - ASE_AWK_EREXBRANGE, /* invalid boundary range */ - ASE_AWK_EREXEND, /* unexpected end of the pattern */ - ASE_AWK_EREXGARBAGE, /* garbage after the pattern */ - - /* the number of error numbers, internal use only */ - ASE_AWK_NUMERRNUM -}; - -/* depth types */ -enum ase_awk_depth_t -{ - ASE_AWK_DEPTH_BLOCK_PARSE = (1 << 0), - ASE_AWK_DEPTH_BLOCK_RUN = (1 << 1), - ASE_AWK_DEPTH_EXPR_PARSE = (1 << 2), - ASE_AWK_DEPTH_EXPR_RUN = (1 << 3), - ASE_AWK_DEPTH_REX_BUILD = (1 << 4), - ASE_AWK_DEPTH_REX_MATCH = (1 << 5) -}; - -/* extio types */ -enum ase_awk_extio_type_t -{ - /* extio types available */ - ASE_AWK_EXTIO_PIPE, - ASE_AWK_EXTIO_COPROC, - ASE_AWK_EXTIO_FILE, - ASE_AWK_EXTIO_CONSOLE, - - /* reserved for internal use only */ - ASE_AWK_EXTIO_NUM -}; - -enum -{ - ASE_AWK_EXTIO_PIPE_READ = 0, - ASE_AWK_EXTIO_PIPE_WRITE = 1, - - /* - ASE_AWK_EXTIO_COPROC_READ = 0, - ASE_AWK_EXTIO_COPROC_WRITE = 1, - ASE_AWK_EXTIO_COPROC_RDWR = 2, - */ - - ASE_AWK_EXTIO_FILE_READ = 0, - ASE_AWK_EXTIO_FILE_WRITE = 1, - ASE_AWK_EXTIO_FILE_APPEND = 2, - - ASE_AWK_EXTIO_CONSOLE_READ = 0, - ASE_AWK_EXTIO_CONSOLE_WRITE = 1 -}; - -#ifdef __cplusplus -extern "C" { -#endif - -ase_awk_t* ase_awk_open (const ase_awk_prmfns_t* prmfns, void* custom_data); -int ase_awk_close (ase_awk_t* awk); -int ase_awk_clear (ase_awk_t* awk); - -void* ase_awk_getcustomdata (ase_awk_t* awk); - -const ase_char_t* ase_awk_geterrstr (ase_awk_t* awk, int num); -int ase_awk_seterrstr (ase_awk_t* awk, int num, const ase_char_t* str); - -int ase_awk_geterrnum (ase_awk_t* awk); -ase_size_t ase_awk_geterrlin (ase_awk_t* awk); -const ase_char_t* ase_awk_geterrmsg (ase_awk_t* awk); -void ase_awk_seterrnum (ase_awk_t* awk, int errnum); - -void ase_awk_geterror ( - ase_awk_t* awk, int* errnum, - ase_size_t* errlin, const ase_char_t** errmsg); - -void ase_awk_seterror ( - ase_awk_t* awk, int errnum, ase_size_t errlin, - const ase_cstr_t* errarg, ase_size_t argcnt); - -int ase_awk_getoption (ase_awk_t* awk); -void ase_awk_setoption (ase_awk_t* awk, int opt); - -ase_size_t ase_awk_getmaxdepth (ase_awk_t* awk, int type); -void ase_awk_setmaxdepth (ase_awk_t* awk, int types, ase_size_t depth); - -int ase_awk_parse (ase_awk_t* awk, ase_awk_srcios_t* srcios); - -/* - * ase_awk_run return 0 on success and -1 on failure, generally speaking. - * A runtime context is required for it to start running the program. - * Once the runtime context is created, the program starts to run. - * The context creation failure is reported by the return value -1 of - * this function. however, the runtime error after the context creation - * is reported differently depending on the use of the callback. - * When no callback is specified (i.e. runcbs is ASE_NULL), ase_awk_run - * returns -1 on an error and awk->errnum is set accordingly. - * However, if a callback is specified (i.e. runcbs is not ASE_NULL), - * ase_awk_run returns 0 on both success and failure. Instead, the - * on_end handler of the callback is triggered with the relevant - * error number. The third parameter to on_end denotes this error number. - */ -int ase_awk_run ( - ase_awk_t* awk, const ase_char_t* main, - ase_awk_runios_t* runios, ase_awk_runcbs_t* runcbs, - ase_awk_runarg_t* runarg, void* custom_data); - -int ase_awk_stop (ase_awk_run_t* run); - -/* functions to access internal stack structure */ -ase_size_t ase_awk_getnargs (ase_awk_run_t* run); -ase_awk_val_t* ase_awk_getarg (ase_awk_run_t* run, ase_size_t idx); -ase_awk_val_t* ase_awk_getglobal (ase_awk_run_t* run, ase_size_t idx); -int ase_awk_setglobal (ase_awk_run_t* run, ase_size_t idx, ase_awk_val_t* val); -void ase_awk_setretval (ase_awk_run_t* run, ase_awk_val_t* val); - -int ase_awk_setfilename ( - ase_awk_run_t* run, const ase_char_t* name, ase_size_t len); -int ase_awk_setofilename ( - ase_awk_run_t* run, const ase_char_t* name, ase_size_t len); - -ase_awk_t* ase_awk_getrunawk (ase_awk_run_t* awk); -void* ase_awk_getruncustomdata (ase_awk_run_t* awk); -ase_awk_map_t* ase_awk_getrunnamedvarmap (ase_awk_run_t* awk); - -/* functions to manipulate the run-time error */ -int ase_awk_getrunerrnum (ase_awk_run_t* run); -ase_size_t ase_awk_getrunerrlin (ase_awk_run_t* run); -const ase_char_t* ase_awk_getrunerrmsg (ase_awk_run_t* run); -void ase_awk_setrunerrnum (ase_awk_run_t* run, int errnum); - -void ase_awk_getrunerror ( - ase_awk_run_t* run, int* errnum, - ase_size_t* errlin, const ase_char_t** errmsg); - -void ase_awk_setrunerror ( - ase_awk_run_t* run, int errnum, ase_size_t errlin, - const ase_cstr_t* errarg, ase_size_t argcnt); - -/* functions to manipulate built-in functions */ -void* ase_awk_addbfn ( - ase_awk_t* awk, const ase_char_t* name, ase_size_t name_len, - int when_valid, ase_size_t min_args, ase_size_t max_args, - const ase_char_t* arg_spec, - int (*handler)(ase_awk_run_t*,const ase_char_t*,ase_size_t)); - -int ase_awk_delbfn ( - ase_awk_t* awk, const ase_char_t* name, ase_size_t name_len); - -void ase_awk_clrbfn (ase_awk_t* awk); - -/* record and field functions */ -int ase_awk_clrrec (ase_awk_run_t* run, ase_bool_t skip_inrec_line); -int ase_awk_setrec (ase_awk_run_t* run, ase_size_t idx, const ase_char_t* str, ase_size_t len); - -/* utility functions exported by awk.h */ -void* ase_awk_malloc (ase_awk_t* awk, ase_size_t size); -void ase_awk_free (ase_awk_t* awk, void* ptr); - -ase_long_t ase_awk_strxtolong ( - ase_awk_t* awk, const ase_char_t* str, ase_size_t len, - int base, const ase_char_t** endptr); -ase_real_t ase_awk_strxtoreal ( - ase_awk_t* awk, const ase_char_t* str, ase_size_t len, - const ase_char_t** endptr); - -ase_size_t ase_awk_longtostr ( - ase_long_t value, int radix, const ase_char_t* prefix, - ase_char_t* buf, ase_size_t size); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ase/awk/awk.txt b/ase/awk/awk.txt deleted file mode 100644 index 6e2ea48a..00000000 --- a/ase/awk/awk.txt +++ /dev/null @@ -1,71 +0,0 @@ -Programs - - pattern { action } - function name (parameter-list) { statement } - -Patterns - BEGIN - END - expresion - /regular expression/ - pattern && pattern - pattern || pattern - !pattern - (pattern) - pattern, pattern -> range pattern - -Actions - break - continue - delete array-element - do statement while (expression) - exit [expression] - expression - if (expression) statement [else statement] - input-output statement - for (expression; expression; expression) statement - for (variable in array) statement - next - return [expression] - while (expression) statement - { statements } - -Variables - -global variables (enabled when awk->opt & XP_AWK_OPT_VARDCL) - - global x; - global x, y; - -local variables (enabled when awk->opt & XP_AWK_OPT_VARDCL) - - local x; - local x, y; - -function arguments (enabled always) - - function funca (x, y) - - -local variables in function declaration (enabled when awk->opt & XP_AWK_OPT_FUNCLOCAL) - - function funca (x, y, v1, v2) - - -variables without any declarations (enabled when awk->opt & XP_AWK_OPT_NAMEDVAR) - - x = 10; // x is put into the global hash table. - - -Optimization - -constant folding - 2 * 10 => 20 - -loop - remove while (0) { ... } - -if - remove if (0) {} - use else_part only - diff --git a/ase/awk/awk_i.h b/ase/awk/awk_i.h deleted file mode 100644 index e127f331..00000000 --- a/ase/awk/awk_i.h +++ /dev/null @@ -1,338 +0,0 @@ -/* - * $Id: awk_i.h,v 1.1.1.1 2007/03/28 14:05:15 bacon Exp $ - * - * {License} - */ - -#ifndef _ASE_AWK_AWKI_H_ -#define _ASE_AWK_AWKI_H_ - -#include -#include - -typedef struct ase_awk_chain_t ase_awk_chain_t; -typedef struct ase_awk_tree_t ase_awk_tree_t; - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef _MSC_VER -#pragma warning (disable: 4996) -#pragma warning (disable: 4296) -#endif - -#define ASE_AWK_MAX_GLOBALS 9999 -#define ASE_AWK_MAX_LOCALS 9999 -#define ASE_AWK_MAX_PARAMS 9999 - -#if defined(_WIN32) && defined(_MSC_VER) && defined(_DEBUG) - #define _CRTDBG_MAP_ALLOC - #include - - #define ASE_AWK_MALLOC(awk,size) malloc (size) - #define ASE_AWK_REALLOC(awk,ptr,size) realloc (ptr, size) - #define ASE_AWK_FREE(awk,ptr) free (ptr) -#else - #define ASE_AWK_MALLOC(awk,size) ASE_MALLOC(&(awk)->prmfns.mmgr,size) - #define ASE_AWK_REALLOC(awk,ptr,size) ASE_REALLOC(&(awk)->prmfns.mmgr,ptr,size) - #define ASE_AWK_FREE(awk,ptr) ASE_FREE(&(awk)->prmfns.mmgr,ptr) -#endif - -#define ASE_AWK_ISUPPER(awk,c) ASE_ISUPPER(&(awk)->prmfns.ccls,c) -#define ASE_AWK_ISLOWER(awk,c) ASE_ISLOWER(&(awk)->prmfns.ccls,c) -#define ASE_AWK_ISALPHA(awk,c) ASE_ISALPHA(&(awk)->prmfns.ccls,c) -#define ASE_AWK_ISDIGIT(awk,c) ASE_ISDIGIT(&(awk)->prmfns.ccls,c) -#define ASE_AWK_ISXDIGIT(awk,c) ASE_ISXDIGIT(&(awk)->prmfns.ccls,c) -#define ASE_AWK_ISALNUM(awk,c) ASE_ISALNUM(&(awk)->prmfns.ccls,c) -#define ASE_AWK_ISSPACE(awk,c) ASE_ISSPACE(&(awk)->prmfns.ccls,c) -#define ASE_AWK_ISPRINT(awk,c) ASE_ISPRINT(&(awk)->prmfns.ccls,c) -#define ASE_AWK_ISGRAPH(awk,c) ASE_ISGRAPH(&(awk)->prmfns.ccls,c) -#define ASE_AWK_ISCNTRL(awk,c) ASE_ISCNTRL(&(awk)->prmfns.ccls,c) -#define ASE_AWK_ISPUNCT(awk,c) ASE_ISPUNCT(&(awk)->prmfns.ccls,c) -#define ASE_AWK_TOUPPER(awk,c) ASE_TOUPPER(&(awk)->prmfns.ccls,c) -#define ASE_AWK_TOLOWER(awk,c) ASE_TOLOWER(&(awk)->prmfns.ccls,c) - -struct ase_awk_tree_t -{ - ase_size_t nglobals; /* total number of globals */ - ase_size_t nbglobals; /* number of builtin globals */ - ase_cstr_t cur_afn; - ase_awk_map_t afns; /* awk function map */ - ase_awk_nde_t* begin; - ase_awk_nde_t* end; - ase_awk_chain_t* chain; - ase_awk_chain_t* chain_tail; - ase_size_t chain_size; /* number of nodes in the chain */ - int ok; -}; - -struct ase_awk_t -{ - ase_awk_prmfns_t prmfns; - void* custom_data; - - /* options */ - int option; - - /* parse tree */ - ase_awk_tree_t tree; - - /* temporary information that the parser needs */ - struct - { - struct - { - int block; - int loop; - int stmnt; /* statement */ - } id; - - struct - { - struct - { - ase_size_t block; - ase_size_t loop; - ase_size_t expr; /* expression */ - } cur; - - struct - { - ase_size_t block; - ase_size_t expr; - } max; - } depth; - - ase_awk_tab_t globals; - ase_awk_tab_t locals; - ase_awk_tab_t params; - ase_size_t nlocals_max; - - ase_awk_nde_t* (*parse_block) ( - ase_awk_t*,ase_size_t,ase_bool_t); - } parse; - - /* source code management */ - struct - { - ase_awk_srcios_t ios; - - struct - { - ase_cint_t curc; - ase_cint_t ungotc[5]; - ase_size_t ungotc_line[5]; - ase_size_t ungotc_column[5]; - ase_size_t ungotc_count; - - ase_size_t line; - ase_size_t column; - } lex; - - struct - { - ase_char_t buf[512]; - ase_size_t buf_pos; - ase_size_t buf_len; - } shared; - } src; - - /* token */ - struct - { - struct - { - int type; - ase_size_t line; - ase_size_t column; - } prev; - - int type; - ase_str_t name; - ase_size_t line; - ase_size_t column; - } token; - - /* builtin functions */ - struct - { - ase_awk_bfn_t* sys; - ase_awk_bfn_t* user; - } bfn; - - struct - { - struct - { - struct - { - ase_size_t block; - ase_size_t expr; - } max; - } depth; - } run; - - struct - { - struct - { - struct - { - ase_size_t build; - ase_size_t match; - } max; - } depth; - } rex; - - struct - { - ase_char_t fmt[1024]; - } tmp; - - /* housekeeping */ - int errnum; - ase_size_t errlin; - ase_char_t errmsg[256]; - - ase_char_t* errstr[ASE_AWK_NUMERRNUM]; -}; - -struct ase_awk_chain_t -{ - ase_awk_nde_t* pattern; - ase_awk_nde_t* action; - ase_awk_chain_t* next; -}; - -struct ase_awk_run_t -{ - int id; - ase_awk_map_t named; - - void** stack; - ase_size_t stack_top; - ase_size_t stack_base; - ase_size_t stack_limit; - int exit_level; - - ase_awk_val_int_t* icache[200]; /* TODO: choose the optimal size */ - ase_awk_val_real_t* rcache[200]; /* TODO: choose the optimal size */ - ase_awk_val_ref_t* fcache[200]; /* TODO: choose the optimal size */ - ase_size_t icache_count; - ase_size_t rcache_count; - ase_size_t fcache_count; - - ase_awk_nde_blk_t* active_block; - ase_byte_t* pattern_range_state; - - struct - { - ase_char_t buf[1024]; - ase_size_t buf_pos; - ase_size_t buf_len; - ase_bool_t eof; - - ase_str_t line; - ase_awk_val_t* d0; /* $0 */ - - ase_size_t maxflds; - ase_size_t nflds; /* NF */ - struct - { - ase_char_t* ptr; - ase_size_t len; - ase_awk_val_t* val; /* $1 .. $NF */ - }* flds; - - } inrec; - - struct - { - void* rs; - void* fs; - int ignorecase; - ase_size_t fnr; - - struct - { - ase_char_t* ptr; - ase_size_t len; - } convfmt; - struct - { - ase_char_t* ptr; - ase_size_t len; - } ofmt; - struct - { - ase_char_t* ptr; - ase_size_t len; - } ofs; - struct - { - ase_char_t* ptr; - ase_size_t len; - } ors; - struct - { - ase_char_t* ptr; - ase_size_t len; - } subsep; - } global; - - /* extio chain */ - struct - { - ase_awk_io_t handler[ASE_AWK_EXTIO_NUM]; - void* custom_data; - ase_awk_extio_t* chain; - } extio; - - struct - { - ase_str_t fmt; - ase_str_t out; - - struct - { - ase_char_t* ptr; - ase_size_t len; /* length */ - ase_size_t inc; /* increment */ - } tmp; - } format; - - struct - { - struct - { - ase_size_t block; - ase_size_t expr; /* expression */ - } cur; - - struct - { - ase_size_t block; - ase_size_t expr; - } max; - } depth; - - int errnum; - ase_size_t errlin; - ase_char_t errmsg[256]; - - void* custom_data; - - ase_awk_t* awk; - ase_awk_runcbs_t* cbs; -}; - -#endif diff --git a/ase/awk/descrip.mms b/ase/awk/descrip.mms deleted file mode 100644 index 0623de56..00000000 --- a/ase/awk/descrip.mms +++ /dev/null @@ -1,28 +0,0 @@ -# -# OpenVMS MMS/MMK -# - -objects = awk.obj,err.obj,tree.obj,str.obj,tab.obj,map.obj,parse.obj,run.obj,rec.obj,val.obj,func.obj,misc.obj,extio.obj,rex.obj - -CFLAGS = /include="../.." -#CFLAGS = /pointer_size=long /include="../.." -LIBRFLAGS = - -aseawk.olb : $(objects) - $(LIBR)/create $(MMS$TARGET) $(objects) -# $(LIBR)/replace $(LIBRFLAGS) $(MMS$TARGET),$(objects) - -awk.obj depends_on awk.c -err.obj depends_on err.c -tree.obj depends_on tree.c -str.obj depends_on str.c -tab.obj depends_on tab.c -map.obj depends_on map.c -parse.obj depends_on parse.c -run.obj depends_on run.c -rec.obj depends_on rec.c -val.obj depends_on val.c -func.obj depends_on func.c -misc.obj depends_on misc.c -extio.obj depends_on extio.c -rex.obj depends_on rex.c diff --git a/ase/awk/err.c b/ase/awk/err.c deleted file mode 100644 index 8ad548bd..00000000 --- a/ase/awk/err.c +++ /dev/null @@ -1,466 +0,0 @@ -/* - * $Id: err.c,v 1.1.1.1 2007/03/28 14:05:15 bacon Exp $ - * - * {License} - */ - -#include - -static const ase_char_t* __geterrstr (int errnum) -{ - static const ase_char_t* errstr[] = - { - ASE_T("no error"), - - ASE_T("invalid parameter"), - ASE_T("out of memory"), - ASE_T("not supported"), - ASE_T("operation not allowed"), - ASE_T("no such device"), - ASE_T("no space left on device"), - ASE_T("too many open files"), - ASE_T("too many links"), - ASE_T("resource temporarily unavailable"), - ASE_T("'%.*s' not existing"), - ASE_T("'%.*s' already exists"), - ASE_T("file or data too big"), - ASE_T("system too busy"), - ASE_T("is a directory"), - ASE_T("i/o error"), - - ASE_T("cannot open '%.*s'"), - ASE_T("cannot read '%.*s'"), - ASE_T("cannot write '%.*s'"), - ASE_T("cannot close '%.*s'"), - - ASE_T("internal error that should never have happened"), - ASE_T("general run-time error"), - ASE_T("block nested too deeply"), - ASE_T("expressio nested too deeply"), - - ASE_T("cannot open source input"), - ASE_T("cannot close source input"), - ASE_T("cannot read source input"), - - ASE_T("cannot open source output"), - ASE_T("cannot close source output"), - ASE_T("cannot write source output"), - - ASE_T("invalid character '%.*s'"), - ASE_T("cannot unget character"), - - ASE_T("unexpected end of source"), - ASE_T("a comment not closed properly"), - ASE_T("a string not closed with a quote"), - ASE_T("unexpected end of a regular expression"), - ASE_T("a left brace expected n place of '%.*s'"), - ASE_T("a left parenthesis expected in place of '%.*s'"), - ASE_T("a right parenthesis expected in place of '%.*s'"), - ASE_T("a right bracket expected in place of '%.*s'"), - ASE_T("a comma expected in place of '%.*s'"), - ASE_T("a semicolon expected in place of '%.*s'"), - ASE_T("a colon expected in place of '%.*s'"), - ASE_T("statement not ending with a semicolon"), - ASE_T("'in' expected in place of '%.*s'"), - ASE_T("right-hand side of the 'in' operator not a variable"), - ASE_T("invalid expression"), - - ASE_T("keyword 'while' expected in place of '%.*s'"), - ASE_T("invalid assignment statement"), - ASE_T("an identifier expected in place of '%.*s'"), - ASE_T("'%.*s' not a valid function name"), - ASE_T("BEGIN not followed by a left bracket on the same line"), - ASE_T("END not followed by a left bracket on the same line"), - ASE_T("duplicate BEGIN"), - ASE_T("duplicate END"), - ASE_T("built-in function '%.*s' redefined"), - ASE_T("function '%.*s' redefined"), - ASE_T("global variable '%.*s' redefined"), - ASE_T("parameter '%.*s' redefined"), - ASE_T("duplicate parameter name '%.*s'"), - ASE_T("duplicate global variable '%.*s'"), - ASE_T("duplicate local variable '%.*s'"), - ASE_T("'%.*s' not a valid parameter name"), - ASE_T("'%.*s' not a valid variable name"), - ASE_T("undefined identifier '%.*s'"), - ASE_T("l-value required"), - ASE_T("too many global variables"), - ASE_T("too many local variables"), - ASE_T("too many parameters"), - ASE_T("delete statement not followed by a normal variable"), - ASE_T("break statement outside a loop"), - ASE_T("continue statement outside a loop"), - ASE_T("next statement illegal in the BEGIN block"), - ASE_T("next statement illegal in the END block"), - ASE_T("nextfile statement illegal in the BEGIN block"), - ASE_T("nextfile statement illegal in the END block"), - ASE_T("printf not followed by any arguments"), - ASE_T("both prefix and postfix increment/decrement operator present"), - ASE_T("coprocess not supported by getline"), - - ASE_T("divide by zero"), - ASE_T("invalid operand"), - ASE_T("wrong position index"), - ASE_T("too few arguments"), - ASE_T("too many arguments"), - ASE_T("function '%.*s' not found"), - ASE_T("variable not indexable"), - ASE_T("variable '%.*s' not deletable"), - ASE_T("value not a map"), - ASE_T("right-hand side of the 'in' operator not a map"), - ASE_T("right-hand side of the 'in' operator not a map nor nil"), - ASE_T("value not referenceable"), - ASE_T("value not assignable"), - ASE_T("an indexed value cannot be assigned a map"), - ASE_T("a positional value cannot be assigned a map"), - ASE_T("map '%.*s' not assignable with a scalar"), - ASE_T("cannot change a scalar value to a map"), - ASE_T("a map is not allowed"), - ASE_T("invalid value type"), - ASE_T("delete statement called with a wrong target"), - ASE_T("next statement called from the BEGIN block"), - ASE_T("next statement called from the END block"), - ASE_T("nextfile statement called from the BEGIN block"), - ASE_T("nextfile statement called from the END block"), - ASE_T("wrong implementation of built-in function handler"), - ASE_T("built-in function handler returned an error"), - ASE_T("wrong implementation of user-defined io handler"), - ASE_T("no such io name found"), - ASE_T("i/o handler returned an error"), - ASE_T("i/o name empty"), - ASE_T("i/o name containing a null character"), - ASE_T("not sufficient arguments to formatting sequence"), - ASE_T("recursion detected in format conversion"), - ASE_T("invalid character in CONVFMT"), - ASE_T("invalid character in OFMT"), - - ASE_T("recursion too deep in the regular expression"), - ASE_T("a right parenthesis expected in the regular expression"), - ASE_T("a right bracket expected in the regular expression"), - ASE_T("a right brace expected in the regular expression"), - ASE_T("unbalanced parenthesis in the regular expression"), - ASE_T("a colon expected in the regular expression"), - ASE_T("invalid character range in the regular expression"), - ASE_T("invalid character class in the regular expression"), - ASE_T("invalid boundary range in the regular expression"), - ASE_T("unexpected end of the regular expression"), - ASE_T("garbage after the regular expression") - }; - - if (errnum >= 0 && errnum < ASE_COUNTOF(errstr)) - { - return errstr[errnum]; - } - - return ASE_T("unknown error"); -} - -const ase_char_t* ase_awk_geterrstr (ase_awk_t* awk, int num) -{ - if (awk != ASE_NULL && - awk->errstr[num] != ASE_NULL) return awk->errstr[num]; - return __geterrstr (num); -} - -int ase_awk_seterrstr (ase_awk_t* awk, int num, const ase_char_t* str) -{ - ase_char_t* dup; - - if (str == ASE_NULL) dup = ASE_NULL; - else - { - dup = ase_strdup (str, &awk->prmfns.mmgr); - if (dup == ASE_NULL) return -1; - } - - if (awk->errstr[num] != ASE_NULL) - ASE_AWK_FREE (awk, awk->errstr[num]); - - else awk->errstr[num] = dup; - return 0; -} - -int ase_awk_geterrnum (ase_awk_t* awk) -{ - return awk->errnum; -} - -ase_size_t ase_awk_geterrlin (ase_awk_t* awk) -{ - return awk->errlin; -} - -const ase_char_t* ase_awk_geterrmsg (ase_awk_t* awk) -{ - if (awk->errmsg[0] == ASE_T('\0')) - return ase_awk_geterrstr (awk, awk->errnum); - return awk->errmsg; -} - -void ase_awk_geterror ( - ase_awk_t* awk, int* errnum, - ase_size_t* errlin, const ase_char_t** errmsg) -{ - if (errnum != ASE_NULL) *errnum = awk->errnum; - if (errlin != ASE_NULL) *errlin = awk->errlin; - if (errmsg != ASE_NULL) - { - if (awk->errmsg[0] == ASE_T('\0')) - *errmsg = ase_awk_geterrstr (awk, awk->errnum); - else - *errmsg = awk->errmsg; - } -} - -void ase_awk_seterrnum (ase_awk_t* awk, int errnum) -{ - awk->errnum = errnum; - awk->errlin = 0; - awk->errmsg[0] = ASE_T('\0'); -} - -void ase_awk_seterror ( - ase_awk_t* awk, int errnum, ase_size_t errlin, - const ase_cstr_t* errarg, ase_size_t argcnt) -{ - const ase_char_t* errfmt; - ase_size_t fmtlen; - - ASE_ASSERT (argcnt <= 5); - - awk->errnum = errnum; - awk->errlin = errlin; - - errfmt = ase_awk_geterrstr (awk, errnum); - fmtlen = ase_strlen(errfmt); - - switch (argcnt) - { - case 0: - awk->prmfns.misc.sprintf ( - awk->prmfns.misc.custom_data, - awk->errmsg, - ASE_COUNTOF(awk->errmsg), - errfmt); - return; - - case 1: - { - ase_char_t tmp[ASE_COUNTOF(awk->errmsg)]; - ase_size_t len, tl; - - if (fmtlen < ASE_COUNTOF(awk->errmsg) && - errarg[0].len + fmtlen >= ASE_COUNTOF(awk->errmsg)) - { - len = ASE_COUNTOF(awk->errmsg) - fmtlen - 3 - 1; - tl = ase_strxncpy (tmp, ASE_COUNTOF(tmp), errarg[0].ptr, len); - tmp[tl] = ASE_T('.'); - tmp[tl+1] = ASE_T('.'); - tmp[tl+2] = ASE_T('.'); - len += 3; - } - else - { - len = errarg[0].len; - ase_strxncpy (tmp, ASE_COUNTOF(tmp), errarg[0].ptr, len); - } - - awk->prmfns.misc.sprintf ( - awk->prmfns.misc.custom_data, - awk->errmsg, - ASE_COUNTOF(awk->errmsg), - errfmt, len, tmp); - return; - } - - case 2: - awk->prmfns.misc.sprintf ( - awk->prmfns.misc.custom_data, - awk->errmsg, - ASE_COUNTOF(awk->errmsg), - errfmt, - errarg[0].len, errarg[0].ptr, - errarg[1].len, errarg[1].ptr); - return; - - case 3: - awk->prmfns.misc.sprintf ( - awk->prmfns.misc.custom_data, - awk->errmsg, - ASE_COUNTOF(awk->errmsg), - errfmt, - errarg[0].len, errarg[0].ptr, - errarg[1].len, errarg[1].ptr, - errarg[2].len, errarg[2].ptr); - return; - - case 4: - awk->prmfns.misc.sprintf ( - awk->prmfns.misc.custom_data, - awk->errmsg, - ASE_COUNTOF(awk->errmsg), - errfmt, - errarg[0].len, errarg[0].ptr, - errarg[1].len, errarg[1].ptr, - errarg[2].len, errarg[2].ptr, - errarg[3].len, errarg[3].ptr); - return; - - case 5: - awk->prmfns.misc.sprintf ( - awk->prmfns.misc.custom_data, - awk->errmsg, - ASE_COUNTOF(awk->errmsg), - errfmt, - errarg[0].len, errarg[0].ptr, - errarg[1].len, errarg[1].ptr, - errarg[2].len, errarg[2].ptr, - errarg[3].len, errarg[3].ptr, - errarg[4].len, errarg[4].ptr); - return; - } -} - -int ase_awk_getrunerrnum (ase_awk_run_t* run) -{ - return run->errnum; -} - -ase_size_t ase_awk_getrunerrlin (ase_awk_run_t* run) -{ - return run->errlin; -} - -const ase_char_t* ase_awk_getrunerrmsg (ase_awk_run_t* run) -{ - if (run->errmsg[0] == ASE_T('\0')) - return ase_awk_geterrstr (run->awk, run->errnum); - - return run->errmsg; -} - -void ase_awk_setrunerrnum (ase_awk_run_t* run, int errnum) -{ - run->errnum = errnum; - run->errlin = 0; - run->errmsg[0] = ASE_T('\0'); -} - -void ase_awk_getrunerror ( - ase_awk_run_t* run, int* errnum, - ase_size_t* errlin, const ase_char_t** errmsg) -{ - if (errnum != ASE_NULL) *errnum = run->errnum; - if (errlin != ASE_NULL) *errlin = run->errlin; - if (errmsg != ASE_NULL) - { - if (run->errmsg[0] == ASE_T('\0')) - *errmsg = ase_awk_geterrstr (run->awk, run->errnum); - else - *errmsg = run->errmsg; - } -} - -void ase_awk_setrunerror ( - ase_awk_run_t* run, int errnum, ase_size_t errlin, - const ase_cstr_t* errarg, ase_size_t argcnt) -{ - const ase_char_t* errfmt; - ase_size_t fmtlen; - - ASE_ASSERT (argcnt <= 5); - - run->errnum = errnum; - run->errlin = errlin; - - errfmt = ase_awk_geterrstr (run->awk, errnum); - fmtlen = ase_strlen (errfmt); - - switch (argcnt) - { - case 0: - /* TODO: convert % to %% if the original % is not - * the first % of the %% sequence */ - run->awk->prmfns.misc.sprintf ( - run->awk->prmfns.misc.custom_data, - run->errmsg, - ASE_COUNTOF(run->errmsg), - errfmt); - return; - - case 1: - { - ase_char_t tmp[ASE_COUNTOF(run->errmsg)]; - ase_size_t len, tl; - - if (fmtlen < ASE_COUNTOF(run->errmsg) && - errarg[0].len + fmtlen >= ASE_COUNTOF(run->errmsg)) - { - len = ASE_COUNTOF(run->errmsg) - fmtlen - 3 - 1; - tl = ase_strxncpy (tmp, ASE_COUNTOF(tmp), errarg[0].ptr, len); - tmp[tl] = ASE_T('.'); - tmp[tl+1] = ASE_T('.'); - tmp[tl+2] = ASE_T('.'); - len += 3; - } - else - { - len = errarg[0].len; - ase_strxncpy (tmp, ASE_COUNTOF(tmp), errarg[0].ptr, len); - } - - run->awk->prmfns.misc.sprintf ( - run->awk->prmfns.misc.custom_data, - run->errmsg, - ASE_COUNTOF(run->errmsg), - errfmt, len, tmp); - return; - } - - case 2: - run->awk->prmfns.misc.sprintf ( - run->awk->prmfns.misc.custom_data, - run->errmsg, - ASE_COUNTOF(run->errmsg), - errfmt, - errarg[0].len, errarg[0].ptr, - errarg[1].len, errarg[1].ptr); - return; - - case 3: - run->awk->prmfns.misc.sprintf ( - run->awk->prmfns.misc.custom_data, - run->errmsg, - ASE_COUNTOF(run->errmsg), - errfmt, - errarg[0].len, errarg[0].ptr, - errarg[1].len, errarg[1].ptr, - errarg[2].len, errarg[2].ptr); - return; - - case 4: - run->awk->prmfns.misc.sprintf ( - run->awk->prmfns.misc.custom_data, - run->errmsg, - ASE_COUNTOF(run->errmsg), - errfmt, - errarg[0].len, errarg[0].ptr, - errarg[1].len, errarg[1].ptr, - errarg[2].len, errarg[2].ptr, - errarg[3].len, errarg[3].ptr); - return; - - case 5: - run->awk->prmfns.misc.sprintf ( - run->awk->prmfns.misc.custom_data, - run->errmsg, - ASE_COUNTOF(run->errmsg), - errfmt, - errarg[0].len, errarg[0].ptr, - errarg[1].len, errarg[1].ptr, - errarg[2].len, errarg[2].ptr, - errarg[3].len, errarg[3].ptr, - errarg[4].len, errarg[4].ptr); - return; - } -} diff --git a/ase/awk/extio.c b/ase/awk/extio.c deleted file mode 100644 index 741185cd..00000000 --- a/ase/awk/extio.c +++ /dev/null @@ -1,951 +0,0 @@ -/* - * $Id: extio.c,v 1.1.1.1 2007/03/28 14:05:15 bacon Exp $ - * - * {License} - */ - -#include - -enum -{ - MASK_READ = 0x0100, - MASK_WRITE = 0x0200, - MASK_RDWR = 0x0400, - - MASK_CLEAR = 0x00FF -}; - -static int in_type_map[] = -{ - /* the order should match the order of the - * ASE_AWK_IN_XXX values in tree.h */ - ASE_AWK_EXTIO_PIPE, - ASE_AWK_EXTIO_COPROC, - ASE_AWK_EXTIO_FILE, - ASE_AWK_EXTIO_CONSOLE -}; - -static int in_mode_map[] = -{ - /* the order should match the order of the - * ASE_AWK_IN_XXX values in tree.h */ - ASE_AWK_EXTIO_PIPE_READ, - 0, - ASE_AWK_EXTIO_FILE_READ, - ASE_AWK_EXTIO_CONSOLE_READ -}; - -static int in_mask_map[] = -{ - MASK_READ, - MASK_RDWR, - MASK_READ, - MASK_READ -}; - -static int out_type_map[] = -{ - /* the order should match the order of the - * ASE_AWK_OUT_XXX values in tree.h */ - ASE_AWK_EXTIO_PIPE, - ASE_AWK_EXTIO_COPROC, - ASE_AWK_EXTIO_FILE, - ASE_AWK_EXTIO_FILE, - ASE_AWK_EXTIO_CONSOLE -}; - -static int out_mode_map[] = -{ - /* the order should match the order of the - * ASE_AWK_OUT_XXX values in tree.h */ - ASE_AWK_EXTIO_PIPE_WRITE, - 0, - ASE_AWK_EXTIO_FILE_WRITE, - ASE_AWK_EXTIO_FILE_APPEND, - ASE_AWK_EXTIO_CONSOLE_WRITE -}; - -static int out_mask_map[] = -{ - MASK_WRITE, - MASK_RDWR, - MASK_WRITE, - MASK_WRITE, - MASK_WRITE -}; - -int ase_awk_readextio ( - ase_awk_run_t* run, int in_type, - const ase_char_t* name, ase_str_t* buf) -{ - ase_awk_extio_t* p = run->extio.chain; - ase_awk_io_t handler; - int extio_type, extio_mode, extio_mask, n, ret; - ase_awk_val_t* rs; - ase_char_t* rs_ptr; - ase_size_t rs_len; - ase_size_t line_len = 0; - ase_char_t c = ASE_T('\0'), pc; - - ASE_ASSERT (in_type >= 0 && in_type <= ASE_COUNTOF(in_type_map)); - ASE_ASSERT (in_type >= 0 && in_type <= ASE_COUNTOF(in_mode_map)); - ASE_ASSERT (in_type >= 0 && in_type <= ASE_COUNTOF(in_mask_map)); - - /* translate the in_type into the relevant extio type and mode */ - extio_type = in_type_map[in_type]; - extio_mode = in_mode_map[in_type]; - extio_mask = in_mask_map[in_type]; - - handler = run->extio.handler[extio_type]; - if (handler == ASE_NULL) - { - /* no io handler provided */ - ase_awk_setrunerrnum (run, ASE_AWK_EIOUSER); - return -1; - } - - while (p != ASE_NULL) - { - if (p->type == (extio_type | extio_mask) && - ase_strcmp (p->name,name) == 0) break; - p = p->next; - } - - if (p == ASE_NULL) - { - p = (ase_awk_extio_t*) ASE_AWK_MALLOC ( - run->awk, ASE_SIZEOF(ase_awk_extio_t)); - if (p == ASE_NULL) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - - p->name = ase_strdup (name, &run->awk->prmfns.mmgr); - if (p->name == ASE_NULL) - { - ASE_AWK_FREE (run->awk, p); - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - - p->run = run; - p->type = (extio_type | extio_mask); - p->mode = extio_mode; - p->handle = ASE_NULL; - p->next = ASE_NULL; - p->custom_data = run->extio.custom_data; - - p->in.buf[0] = ASE_T('\0'); - p->in.pos = 0; - p->in.len = 0; - p->in.eof = ase_false; - p->in.eos = ase_false; - - ase_awk_setrunerrnum (run, ASE_AWK_ENOERR); - - n = handler (ASE_AWK_IO_OPEN, p, ASE_NULL, 0); - if (n <= -1) - { - ASE_AWK_FREE (run->awk, p->name); - ASE_AWK_FREE (run->awk, p); - - if (run->errnum == ASE_AWK_ENOERR) - { - /* if the error number has not been - * set by the user handler */ - ase_awk_setrunerrnum (run, ASE_AWK_EIOIMPL); - } - - return -1; - } - - /* chain it */ - p->next = run->extio.chain; - run->extio.chain = p; - - /* usually, n == 0 indicates that it has reached the end - * of the input. the user io handler can return 0 for the - * open request if it doesn't have any files to open. One - * advantage of doing this would be that you can skip the - * entire pattern-block matching and exeuction. */ - if (n == 0) - { - p->in.eos = ase_true; - return 0; - } - } - - if (p->in.eos) - { - /* no more streams. */ - return 0; - } - - /* ready to read a line */ - ase_str_clear (buf); - - /* get the record separator */ - rs = ase_awk_getglobal (run, ASE_AWK_GLOBAL_RS); - ase_awk_refupval (run, rs); - - if (rs->type == ASE_AWK_VAL_NIL) - { - rs_ptr = ASE_NULL; - rs_len = 0; - } - else if (rs->type == ASE_AWK_VAL_STR) - { - rs_ptr = ((ase_awk_val_str_t*)rs)->buf; - rs_len = ((ase_awk_val_str_t*)rs)->len; - } - else - { - rs_ptr = ase_awk_valtostr ( - run, rs, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &rs_len); - if (rs_ptr == ASE_NULL) - { - ase_awk_refdownval (run, rs); - return -1; - } - } - - ret = 1; - - /* call the io handler */ - while (1) - { - if (p->in.pos >= p->in.len) - { - ase_ssize_t n; - - if (p->in.eof) - { - if (ASE_STR_LEN(buf) == 0) ret = 0; - break; - } - - ase_awk_setrunerrnum (run, ASE_AWK_ENOERR); - - n = handler (ASE_AWK_IO_READ, - p, p->in.buf, ASE_COUNTOF(p->in.buf)); - if (n <= -1) - { - if (run->errnum == ASE_AWK_ENOERR) - { - /* if the error number has not been - * set by the user handler */ - ase_awk_setrunerrnum (run, ASE_AWK_EIOIMPL); - } - - ret = -1; - break; - } - - if (n == 0) - { - p->in.eof = ase_true; - if (ASE_STR_LEN(buf) == 0) ret = 0; - break; - } - - p->in.len = n; - p->in.pos = 0; - } - - pc = c; - c = p->in.buf[p->in.pos++]; - - if (rs_ptr == ASE_NULL) - { - /* separate by a new line */ - if (c == ASE_T('\n')) - { - if (pc == ASE_T('\r') && - ASE_STR_LEN(buf) > 0) - { - ASE_STR_LEN(buf) -= 1; - } - break; - } - } - else if (rs_len == 0) - { - /* separate by a blank line */ - if (c == ASE_T('\n')) - { - if (pc == ASE_T('\r') && - ASE_STR_LEN(buf) > 0) - { - ASE_STR_LEN(buf) -= 1; - } - } - - if (line_len == 0 && c == ASE_T('\n')) - { - if (ASE_STR_LEN(buf) <= 0) - { - /* if the record is empty when a blank - * line is encountered, the line - * terminator should not be added to - * the record */ - continue; - } - - /* when a blank line is encountered, - * it needs to snip off the line - * terminator of the previous line */ - ASE_STR_LEN(buf) -= 1; - break; - } - } - else if (rs_len == 1) - { - if (c == rs_ptr[0]) break; - } - else - { - const ase_char_t* match_ptr; - ase_size_t match_len; - - ASE_ASSERT (run->global.rs != ASE_NULL); - - n = ase_awk_matchrex ( - run->awk, run->global.rs, - ((run->global.ignorecase)? ASE_AWK_REX_IGNORECASE: 0), - ASE_STR_BUF(buf), ASE_STR_LEN(buf), - &match_ptr, &match_len, &run->errnum); - if (n == -1) - { - ret = -1; - break; - } - - if (n == 1) - { - /* the match should be found at the end of - * the current buffer */ - ASE_ASSERT ( - ASE_STR_BUF(buf) + ASE_STR_LEN(buf) == - match_ptr + match_len); - - ASE_STR_LEN(buf) -= match_len; - break; - } - } - - if (ase_str_ccat (buf, c) == (ase_size_t)-1) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - ret = -1; - break; - } - - /* TODO: handle different line terminator like \r\n */ - if (c == ASE_T('\n')) line_len = 0; - else line_len = line_len + 1; - } - - if (rs_ptr != ASE_NULL && - rs->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, rs_ptr); - ase_awk_refdownval (run, rs); - - /* increment NR */ - if (ret != -1 && ret != 0) - { - ase_awk_val_t* nr; - ase_long_t lv; - ase_real_t rv; - - nr = ase_awk_getglobal (run, ASE_AWK_GLOBAL_NR); - ase_awk_refupval (run, nr); - n = ase_awk_valtonum (run, nr, &lv, &rv); - ase_awk_refdownval (run, nr); - - if (n == -1) ret = -1; - else - { - if (n == 1) lv = (ase_long_t)rv; - - nr = ase_awk_makeintval (run, lv + 1); - if (nr == ASE_NULL) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - ret = -1; - } - else - { - if (ase_awk_setglobal ( - run, ASE_AWK_GLOBAL_NR, nr) == -1) ret = -1; - } - } - } - - return ret; -} - -int ase_awk_writeextio_val ( - ase_awk_run_t* run, int out_type, - const ase_char_t* name, ase_awk_val_t* v) -{ - ase_char_t* str; - ase_size_t len; - int n; - - if (v->type == ASE_AWK_VAL_STR) - { - str = ((ase_awk_val_str_t*)v)->buf; - len = ((ase_awk_val_str_t*)v)->len; - } - else - { - str = ase_awk_valtostr ( - run, v, - ASE_AWK_VALTOSTR_CLEAR | ASE_AWK_VALTOSTR_PRINT, - ASE_NULL, &len); - if (str == ASE_NULL) return -1; - } - - n = ase_awk_writeextio_str (run, out_type, name, str, len); - - if (v->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, str); - return n; -} - -int ase_awk_writeextio_str ( - ase_awk_run_t* run, int out_type, - const ase_char_t* name, ase_char_t* str, ase_size_t len) -{ - ase_awk_extio_t* p = run->extio.chain; - ase_awk_io_t handler; - int extio_type, extio_mode, extio_mask, n; - - ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_type_map)); - ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_mode_map)); - ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_mask_map)); - - /* translate the out_type into the relevant extio type and mode */ - extio_type = out_type_map[out_type]; - extio_mode = out_mode_map[out_type]; - extio_mask = out_mask_map[out_type]; - - handler = run->extio.handler[extio_type]; - if (handler == ASE_NULL) - { - /* no io handler provided */ - ase_awk_setrunerrnum (run, ASE_AWK_EIOUSER); - return -1; - } - - /* look for the corresponding extio for name */ - while (p != ASE_NULL) - { - /* the file "1.tmp", in the following code snippets, - * would be opened by the first print statement, but not by - * the second print statement. this is because - * both ASE_AWK_OUT_FILE and ASE_AWK_OUT_FILE_APPEND are - * translated to ASE_AWK_EXTIO_FILE and it is used to - * keep track of file handles.. - * - * print "1111" >> "1.tmp" - * print "1111" > "1.tmp" - */ - if (p->type == (extio_type | extio_mask) && - ase_strcmp (p->name, name) == 0) break; - p = p->next; - } - - /* if there is not corresponding extio for name, create one */ - if (p == ASE_NULL) - { - p = (ase_awk_extio_t*) ASE_AWK_MALLOC ( - run->awk, ASE_SIZEOF(ase_awk_extio_t)); - if (p == ASE_NULL) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - - p->name = ase_strdup (name, &run->awk->prmfns.mmgr); - if (p->name == ASE_NULL) - { - ASE_AWK_FREE (run->awk, p); - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - - p->run = run; - p->type = (extio_type | extio_mask); - p->mode = extio_mode; - p->handle = ASE_NULL; - p->next = ASE_NULL; - p->custom_data = run->extio.custom_data; - - p->out.eof = ase_false; - p->out.eos = ase_false; - - ase_awk_setrunerrnum (run, ASE_AWK_ENOERR); - n = handler (ASE_AWK_IO_OPEN, p, ASE_NULL, 0); - if (n <= -1) - { - ASE_AWK_FREE (run->awk, p->name); - ASE_AWK_FREE (run->awk, p); - - if (run->errnum == ASE_AWK_ENOERR) - ase_awk_setrunerrnum (run, ASE_AWK_EIOIMPL); - - return -1; - } - - /* chain it */ - p->next = run->extio.chain; - run->extio.chain = p; - - /* usually, n == 0 indicates that it has reached the end - * of the input. the user io handler can return 0 for the - * open request if it doesn't have any files to open. One - * advantage of doing this would be that you can skip the - * entire pattern-block matching and exeuction. */ - if (n == 0) - { - p->out.eos = ase_true; - return 0; - } - } - - if (p->out.eos) - { - /* no more streams */ - return 0; - } - - if (p->out.eof) - { - /* it has reached the end of the stream but this function - * has been recalled */ - return 0; - } - - while (len > 0) - { - ase_awk_setrunerrnum (run, ASE_AWK_ENOERR); - n = handler (ASE_AWK_IO_WRITE, p, str, len); - if (n <= -1) - { - if (run->errnum == ASE_AWK_ENOERR) - ase_awk_setrunerrnum (run, ASE_AWK_EIOIMPL); - - return -1; - } - - if (n == 0) - { - p->out.eof = ase_true; - return 0; - } - - len -= n; - str += n; - } - - return 1; -} - -int ase_awk_flushextio ( - ase_awk_run_t* run, int out_type, const ase_char_t* name) -{ - ase_awk_extio_t* p = run->extio.chain; - ase_awk_io_t handler; - int extio_type, /*extio_mode,*/ extio_mask, n; - ase_bool_t ok = ase_false; - - ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_type_map)); - ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_mode_map)); - ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_mask_map)); - - /* translate the out_type into the relevant extio type and mode */ - extio_type = out_type_map[out_type]; - /*extio_mode = out_mode_map[out_type];*/ - extio_mask = out_mask_map[out_type]; - - handler = run->extio.handler[extio_type]; - if (handler == ASE_NULL) - { - /* no io handler provided */ - ase_awk_setrunerrnum (run, ASE_AWK_EIOUSER); - return -1; - } - - /* look for the corresponding extio for name */ - while (p != ASE_NULL) - { - if (p->type == (extio_type | extio_mask) && - (name == ASE_NULL || ase_strcmp(p->name,name) == 0)) - { - ase_awk_setrunerrnum (run, ASE_AWK_ENOERR); - n = handler (ASE_AWK_IO_FLUSH, p, ASE_NULL, 0); - - if (n <= -1) - { - if (run->errnum == ASE_AWK_ENOERR) - ase_awk_setrunerrnum (run, ASE_AWK_EIOIMPL); - return -1; - } - - ok = ase_true; - } - - p = p->next; - } - - if (ok) return 0; - - /* there is no corresponding extio for name */ - ase_awk_setrunerrnum (run, ASE_AWK_EIONONE); - return -1; -} - -int ase_awk_nextextio_read ( - ase_awk_run_t* run, int in_type, const ase_char_t* name) -{ - ase_awk_extio_t* p = run->extio.chain; - ase_awk_io_t handler; - int extio_type, /*extio_mode,*/ extio_mask, n; - - ASE_ASSERT (in_type >= 0 && in_type <= ASE_COUNTOF(in_type_map)); - ASE_ASSERT (in_type >= 0 && in_type <= ASE_COUNTOF(in_mode_map)); - ASE_ASSERT (in_type >= 0 && in_type <= ASE_COUNTOF(in_mask_map)); - - /* translate the in_type into the relevant extio type and mode */ - extio_type = in_type_map[in_type]; - /*extio_mode = in_mode_map[in_type];*/ - extio_mask = in_mask_map[in_type]; - - handler = run->extio.handler[extio_type]; - if (handler == ASE_NULL) - { - /* no io handler provided */ - ase_awk_setrunerrnum (run, ASE_AWK_EIOUSER); - return -1; - } - - while (p != ASE_NULL) - { - if (p->type == (extio_type | extio_mask) && - ase_strcmp (p->name,name) == 0) break; - p = p->next; - } - - if (p == ASE_NULL) - { - /* something is totally wrong */ - ASE_ASSERT ( - !"should never happen - cannot find the relevant extio entry"); - ase_awk_setrunerror (run, ASE_AWK_EINTERN, 0, ASE_NULL, 0); - return -1; - } - - if (p->in.eos) - { - /* no more streams. */ - return 0; - } - - ase_awk_setrunerrnum (run, ASE_AWK_ENOERR); - n = handler (ASE_AWK_IO_NEXT, p, ASE_NULL, 0); - if (n <= -1) - { - if (run->errnum == ASE_AWK_ENOERR) - ase_awk_setrunerrnum (run, ASE_AWK_EIOIMPL); - return -1; - } - - if (n == 0) - { - /* the next stream cannot be opened. - * set the eos flags so that the next call to nextextio_read - * will return 0 without executing the handler */ - p->in.eos = ase_true; - } - else - { - /* as the next stream has been opened successfully, - * the eof flag should be cleared if set */ - p->in.eof = ase_false; - - /* also the previous input buffer must be reset */ - p->in.pos = 0; - p->in.len = 0; - } - - return n; -} - -int ase_awk_nextextio_write ( - ase_awk_run_t* run, int out_type, const ase_char_t* name) -{ - ase_awk_extio_t* p = run->extio.chain; - ase_awk_io_t handler; - int extio_type, /*extio_mode,*/ extio_mask, n; - - ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_type_map)); - ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_mode_map)); - ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_mask_map)); - - /* translate the out_type into the relevant extio type and mode */ - extio_type = out_type_map[out_type]; - /*extio_mode = out_mode_map[out_type];*/ - extio_mask = out_mask_map[out_type]; - - handler = run->extio.handler[extio_type]; - if (handler == ASE_NULL) - { - /* no io handler provided */ - ase_awk_setrunerrnum (run, ASE_AWK_EIOUSER); - return -1; - } - - while (p != ASE_NULL) - { - if (p->type == (extio_type | extio_mask) && - ase_strcmp (p->name,name) == 0) break; - p = p->next; - } - - if (p == ASE_NULL) - { - /* something is totally wrong */ - ASE_ASSERT (!"should never happen - cannot find the relevant extio entry"); - - ase_awk_setrunerror (run, ASE_AWK_EINTERN, 0, ASE_NULL, 0); - return -1; - } - - if (p->out.eos) - { - /* no more streams. */ - return 0; - } - - ase_awk_setrunerrnum (run, ASE_AWK_ENOERR); - n = handler (ASE_AWK_IO_NEXT, p, ASE_NULL, 0); - if (n <= -1) - { - if (run->errnum == ASE_AWK_ENOERR) - ase_awk_setrunerrnum (run, ASE_AWK_EIOIMPL); - return -1; - } - - if (n == 0) - { - /* the next stream cannot be opened. - * set the eos flags so that the next call to nextextio_write - * will return 0 without executing the handler */ - p->out.eos = ase_true; - } - else - { - /* as the next stream has been opened successfully, - * the eof flag should be cleared if set */ - p->out.eof = ase_false; - } - - return n; -} - -int ase_awk_closeextio_read ( - ase_awk_run_t* run, int in_type, const ase_char_t* name) -{ - ase_awk_extio_t* p = run->extio.chain, * px = ASE_NULL; - ase_awk_io_t handler; - int extio_type, /*extio_mode,*/ extio_mask; - - ASE_ASSERT (in_type >= 0 && in_type <= ASE_COUNTOF(in_type_map)); - ASE_ASSERT (in_type >= 0 && in_type <= ASE_COUNTOF(in_mode_map)); - ASE_ASSERT (in_type >= 0 && in_type <= ASE_COUNTOF(in_mask_map)); - - /* translate the in_type into the relevant extio type and mode */ - extio_type = in_type_map[in_type]; - /*extio_mode = in_mode_map[in_type];*/ - extio_mask = in_mask_map[in_type]; - - handler = run->extio.handler[extio_type]; - if (handler == ASE_NULL) - { - /* no io handler provided */ - ase_awk_setrunerrnum (run, ASE_AWK_EIOUSER); - return -1; - } - - while (p != ASE_NULL) - { - if (p->type == (extio_type | extio_mask) && - ase_strcmp (p->name, name) == 0) - { - ase_awk_io_t handler; - - handler = run->extio.handler[p->type & MASK_CLEAR]; - if (handler != ASE_NULL) - { - if (handler (ASE_AWK_IO_CLOSE, p, ASE_NULL, 0) <= -1) - { - /* this is not a run-time error.*/ - ase_awk_setrunerror (run, ASE_AWK_EIOIMPL, 0, ASE_NULL, 0); - return -1; - } - } - - if (px != ASE_NULL) px->next = p->next; - else run->extio.chain = p->next; - - ASE_AWK_FREE (run->awk, p->name); - ASE_AWK_FREE (run->awk, p); - return 0; - } - - px = p; - p = p->next; - } - - /* the name given is not found */ - ase_awk_setrunerrnum (run, ASE_AWK_EIONONE); - return -1; -} - -int ase_awk_closeextio_write ( - ase_awk_run_t* run, int out_type, const ase_char_t* name) -{ - ase_awk_extio_t* p = run->extio.chain, * px = ASE_NULL; - ase_awk_io_t handler; - int extio_type, /*extio_mode,*/ extio_mask; - - ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_type_map)); - ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_mode_map)); - ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_mask_map)); - - /* translate the out_type into the relevant extio type and mode */ - extio_type = out_type_map[out_type]; - /*extio_mode = out_mode_map[out_type];*/ - extio_mask = out_mask_map[out_type]; - - handler = run->extio.handler[extio_type]; - if (handler == ASE_NULL) - { - /* no io handler provided */ - ase_awk_setrunerror (run, ASE_AWK_EIOUSER, 0, ASE_NULL, 0); - return -1; - } - - while (p != ASE_NULL) - { - if (p->type == (extio_type | extio_mask) && - ase_strcmp (p->name, name) == 0) - { - ase_awk_io_t handler; - - handler = run->extio.handler[p->type & MASK_CLEAR]; - if (handler != ASE_NULL) - { - ase_awk_setrunerrnum (run, ASE_AWK_ENOERR); - if (handler (ASE_AWK_IO_CLOSE, p, ASE_NULL, 0) <= -1) - { - if (run->errnum == ASE_AWK_ENOERR) - ase_awk_setrunerrnum (run, ASE_AWK_EIOIMPL); - return -1; - } - } - - if (px != ASE_NULL) px->next = p->next; - else run->extio.chain = p->next; - - ASE_AWK_FREE (run->awk, p->name); - ASE_AWK_FREE (run->awk, p); - return 0; - } - - px = p; - p = p->next; - } - - ase_awk_setrunerrnum (run, ASE_AWK_EIONONE); - return -1; -} - -int ase_awk_closeextio (ase_awk_run_t* run, const ase_char_t* name) -{ - ase_awk_extio_t* p = run->extio.chain, * px = ASE_NULL; - - while (p != ASE_NULL) - { - /* it handles the first that matches the given name - * regardless of the extio type */ - if (ase_strcmp (p->name, name) == 0) - { - ase_awk_io_t handler; - - handler = run->extio.handler[p->type & MASK_CLEAR]; - if (handler != ASE_NULL) - { - ase_awk_setrunerrnum (run, ASE_AWK_ENOERR); - if (handler (ASE_AWK_IO_CLOSE, p, ASE_NULL, 0) <= -1) - { - /* this is not a run-time error.*/ - if (run->errnum == ASE_AWK_ENOERR) - ase_awk_setrunerrnum (run, ASE_AWK_EIOIMPL); - return -1; - } - } - - if (px != ASE_NULL) px->next = p->next; - else run->extio.chain = p->next; - - ASE_AWK_FREE (run->awk, p->name); - ASE_AWK_FREE (run->awk, p); - - return 0; - } - - px = p; - p = p->next; - } - - ase_awk_setrunerrnum (run, ASE_AWK_EIONONE); - return -1; -} - -void ase_awk_clearextio (ase_awk_run_t* run) -{ - ase_awk_extio_t* next; - ase_awk_io_t handler; - int n; - - while (run->extio.chain != ASE_NULL) - { - handler = run->extio.handler[ - run->extio.chain->type & MASK_CLEAR]; - next = run->extio.chain->next; - - if (handler != ASE_NULL) - { - ase_awk_setrunerrnum (run, ASE_AWK_ENOERR); - n = handler (ASE_AWK_IO_CLOSE, run->extio.chain, ASE_NULL, 0); - if (n <= -1) - { - if (run->errnum == ASE_AWK_ENOERR) - ase_awk_setrunerrnum (run, ASE_AWK_EIOIMPL); - /* TODO: some warnings need to be shown??? */ - } - } - - ASE_AWK_FREE (run->awk, run->extio.chain->name); - ASE_AWK_FREE (run->awk, run->extio.chain); - - run->extio.chain = next; - } -} diff --git a/ase/awk/extio.h b/ase/awk/extio.h deleted file mode 100644 index e80d18e7..00000000 --- a/ase/awk/extio.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * $Id: extio.h,v 1.1.1.1 2007/03/28 14:05:15 bacon Exp $ - * - * {License} - */ - -#ifndef _ASE_AWK_EXTIO_H_ -#define _ASE_AWK_EXTIO_H_ - -#ifndef _ASE_AWK_AWK_H_ -#error Never include this file directly. Include instead -#endif - -#ifdef __cplusplus -extern "C" -#endif - -int ase_awk_readextio ( - ase_awk_run_t* run, int in_type, - const ase_char_t* name, ase_str_t* buf); - -int ase_awk_writeextio_val ( - ase_awk_run_t* run, int out_type, - const ase_char_t* name, ase_awk_val_t* v); - -int ase_awk_writeextio_str ( - ase_awk_run_t* run, int out_type, - const ase_char_t* name, ase_char_t* str, ase_size_t len); - -int ase_awk_flushextio ( - ase_awk_run_t* run, int out_type, const ase_char_t* name); - -int ase_awk_nextextio_read ( - ase_awk_run_t* run, int in_type, const ase_char_t* name); - -int ase_awk_nextextio_write ( - ase_awk_run_t* run, int out_type, const ase_char_t* name); - -int ase_awk_closeextio_read ( - ase_awk_run_t* run, int in_type, const ase_char_t* name); -int ase_awk_closeextio_write ( - ase_awk_run_t* run, int out_type, const ase_char_t* name); -int ase_awk_closeextio (ase_awk_run_t* run, const ase_char_t* name); - -void ase_awk_clearextio (ase_awk_run_t* run); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ase/awk/func.c b/ase/awk/func.c deleted file mode 100644 index d0660f01..00000000 --- a/ase/awk/func.c +++ /dev/null @@ -1,1364 +0,0 @@ -/* - * $Id: func.c,v 1.1.1.1 2007/03/28 14:05:15 bacon Exp $ - * - * {License} - */ - -#include - -static int __bfn_close (ase_awk_run_t*, const ase_char_t*, ase_size_t); -static int __bfn_fflush (ase_awk_run_t*, const ase_char_t*, ase_size_t); -static int __bfn_index (ase_awk_run_t*, const ase_char_t*, ase_size_t); -static int __bfn_length (ase_awk_run_t*, const ase_char_t*, ase_size_t); -static int __bfn_substr (ase_awk_run_t*, const ase_char_t*, ase_size_t); -static int __bfn_split (ase_awk_run_t*, const ase_char_t*, ase_size_t); -static int __bfn_tolower (ase_awk_run_t*, const ase_char_t*, ase_size_t); -static int __bfn_toupper (ase_awk_run_t*, const ase_char_t*, ase_size_t); -static int __bfn_gsub (ase_awk_run_t*, const ase_char_t*, ase_size_t); -static int __bfn_sub (ase_awk_run_t*, const ase_char_t*, ase_size_t); -static int __bfn_match (ase_awk_run_t*, const ase_char_t*, ase_size_t); -static int __bfn_sprintf (ase_awk_run_t*, const ase_char_t*, ase_size_t); - -#undef MAX -#define MAX ASE_TYPE_UNSIGNED_MAX(ase_size_t) - -static ase_awk_bfn_t __sys_bfn[] = -{ - /* io functions */ - { {ASE_T("close"), 5}, ASE_AWK_EXTIO, {1, 1, ASE_NULL}, __bfn_close}, - { {ASE_T("fflush"), 6}, ASE_AWK_EXTIO, {0, 1, ASE_NULL}, __bfn_fflush}, - - /* string functions */ - { {ASE_T("index"), 5}, 0, {2, 2, ASE_NULL}, __bfn_index}, - { {ASE_T("substr"), 6}, 0, {2, 3, ASE_NULL}, __bfn_substr}, - { {ASE_T("length"), 6}, 0, {1, 1, ASE_NULL}, __bfn_length}, - { {ASE_T("split"), 5}, 0, {2, 3, ASE_T("vrv")}, __bfn_split}, - { {ASE_T("tolower"), 7}, 0, {1, 1, ASE_NULL}, __bfn_tolower}, - { {ASE_T("toupper"), 7}, 0, {1, 1, ASE_NULL}, __bfn_toupper}, - { {ASE_T("gsub"), 4}, 0, {2, 3, ASE_T("xvr")}, __bfn_gsub}, - { {ASE_T("sub"), 3}, 0, {2, 3, ASE_T("xvr")}, __bfn_sub}, - { {ASE_T("match"), 5}, 0, {2, 2, ASE_T("vx")}, __bfn_match}, - { {ASE_T("sprintf"), 7}, 0, {1, MAX, ASE_NULL}, __bfn_sprintf}, - - { {ASE_NULL, 0}, 0, {0, 0, ASE_NULL}, ASE_NULL} -}; - -void* ase_awk_addbfn ( - ase_awk_t* awk, const ase_char_t* name, ase_size_t name_len, - int when_valid, ase_size_t min_args, ase_size_t max_args, - const ase_char_t* arg_spec, - int (*handler)(ase_awk_run_t*,const ase_char_t*,ase_size_t)) -{ - ase_awk_bfn_t* p; - - if (ase_awk_getbfn (awk, name, name_len) != ASE_NULL) - { - ase_cstr_t errarg; - - errarg.ptr = name; - errarg.len = name_len; - - ase_awk_seterror (awk, ASE_AWK_EEXIST, 0, &errarg, 1); - return ASE_NULL; - } - - p = (ase_awk_bfn_t*) ASE_AWK_MALLOC (awk, ASE_SIZEOF(ase_awk_bfn_t)); - if (p == ASE_NULL) - { - ase_awk_seterror (awk, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return ASE_NULL; - } - - p->name.ptr = ase_strxdup (name, name_len, &awk->prmfns.mmgr); - if (p->name.ptr == ASE_NULL) - { - ASE_AWK_FREE (awk, p); - ase_awk_seterror (awk, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return ASE_NULL; - } - - p->name.len = name_len; - p->valid = when_valid; - p->arg.min = min_args; - p->arg.max = max_args; - if (arg_spec == ASE_NULL) p->arg.spec = ASE_NULL; - else - { - p->arg.spec = ase_strdup (arg_spec, &awk->prmfns.mmgr); - if (p->arg.spec == ASE_NULL) - { - ASE_AWK_FREE (awk, p->name.ptr); - ASE_AWK_FREE (awk, p); - ase_awk_seterror (awk, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return ASE_NULL; - } - } - p->handler = handler; - - p->next = awk->bfn.user; - awk->bfn.user = p; - - return p; -} - -int ase_awk_delbfn (ase_awk_t* awk, const ase_char_t* name, ase_size_t name_len) -{ - ase_awk_bfn_t* p, * pp = ASE_NULL; - ase_cstr_t errarg; - - for (p = awk->bfn.user; p != ASE_NULL; p = p->next) - { - if (ase_strxncmp ( - p->name.ptr, p->name.len, name, name_len) == 0) - { - if (pp == ASE_NULL) - awk->bfn.user = p->next; - else pp->next = p->next; - - if (p->arg.spec != ASE_NULL) - ASE_AWK_FREE (awk, p->arg.spec); - ASE_AWK_FREE (awk, p->name.ptr); - ASE_AWK_FREE (awk, p); - return 0; - } - - pp = p; - } - - errarg.ptr = name; - errarg.len = name_len; - - ase_awk_seterror (awk, ASE_AWK_ENOENT, 0, &errarg, 1); - return -1; -} - -void ase_awk_clrbfn (ase_awk_t* awk) -{ - ase_awk_bfn_t* p, * np; - - p = awk->bfn.user; - while (p != ASE_NULL) - { - np = p->next; - if (p->arg.spec != ASE_NULL) - ASE_AWK_FREE (awk, p->arg.spec); - ASE_AWK_FREE (awk, p->name.ptr); - ASE_AWK_FREE (awk, p); - p = np; - } - - awk->bfn.user = ASE_NULL; -} - -ase_awk_bfn_t* ase_awk_getbfn ( - ase_awk_t* awk, const ase_char_t* name, ase_size_t len) -{ - ase_awk_bfn_t* p; - - for (p = __sys_bfn; p->name.ptr != ASE_NULL; p++) - { - if (p->valid != 0 && - (awk->option & p->valid) == 0) continue; - - if (ase_strxncmp ( - p->name.ptr, p->name.len, name, len) == 0) return p; - } - - for (p = awk->bfn.user; p != ASE_NULL; p = p->next) - { - if (p->valid != 0 && - (awk->option & p->valid) == 0) continue; - - if (ase_strxncmp ( - p->name.ptr, p->name.len, name, len) == 0) return p; - } - - return ASE_NULL; -} - -static int __bfn_close ( - ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl) -{ - ase_size_t nargs; - ase_awk_val_t* v, * a0; - int n; - - ase_char_t* name; - ase_size_t len; - - nargs = ase_awk_getnargs (run); - ASE_ASSERT (nargs == 1); -/* TODO: support close (xxx, "to"/"from") like gawk */ - - a0 = ase_awk_getarg (run, 0); - ASE_ASSERT (a0 != ASE_NULL); - - if (a0->type == ASE_AWK_VAL_STR) - { - name = ((ase_awk_val_str_t*)a0)->buf; - len = ((ase_awk_val_str_t*)a0)->len; - } - else - { - name = ase_awk_valtostr ( - run, a0, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &len); - if (name == ASE_NULL) return -1; - } - - if (len == 0) - { - /* getline or print doesn't allow an emptry for the - * input or output file name. so close should not allow - * it either. - * another reason for this is if close is called explicitly - * with an empty string, it may close the console that uses - * an empty string for its identification because closeextio - * closes any extios that match the name given unlike - * closeextio_read or closeextio_write. */ - if (a0->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, name); - n = -1; - goto skip_close; - } - - while (len > 0) - { - if (name[--len] == ASE_T('\0')) - { - /* the name contains a null string. - * make close return -1 */ - if (a0->type != ASE_AWK_VAL_STR) - ASE_AWK_FREE (run->awk, name); - n = -1; - goto skip_close; - } - } - - n = ase_awk_closeextio (run, name); - /* - if (n == -1 && run->errnum != ASE_AWK_EIONONE) - { - if (a0->type != ASE_AWK_VAL_STR) - ASE_AWK_FREE (run->awk, name); - return -1; - } - */ - - if (a0->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, name); - -skip_close: - v = ase_awk_makeintval (run, (ase_long_t)n); - if (v == ASE_NULL) - { - ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); - return -1; - } - - ase_awk_setretval (run, v); - return 0; -} - -static int __flush_extio ( - ase_awk_run_t* run, int extio, const ase_char_t* name, int n) -{ - int n2; - - if (run->extio.handler[extio] != ASE_NULL) - { - n2 = ase_awk_flushextio (run, extio, name); - if (n2 == -1) - { - /* - if (run->errnum == ASE_AWK_EIOIMPL) n = -1; - else if (run->errnum == ASE_AWK_EIONONE) - { - if (n != 0) n = -2; - } - else n = -99; - */ - if (run->errnum == ASE_AWK_EIONONE) - { - if (n != 0) n = -2; - } - else n = -1; - } - else if (n != -1) n = 0; - } - - return n; -} - -static int __bfn_fflush ( - ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl) -{ - ase_size_t nargs; - ase_awk_val_t* a0; - ase_char_t* str0; - ase_size_t len0; - int n; - - nargs = ase_awk_getnargs (run); - ASE_ASSERT (nargs == 0 || nargs == 1); - - if (nargs == 0) - { - /* flush the console output. - * fflush() should return -1 on errors */ - n = ase_awk_flushextio (run, ASE_AWK_OUT_CONSOLE, ASE_T("")); - } - else - { - ase_char_t* ptr, * end; - - a0 = ase_awk_getarg (run, 0); - if (a0->type == ASE_AWK_VAL_STR) - { - str0 = ((ase_awk_val_str_t*)a0)->buf; - len0 = ((ase_awk_val_str_t*)a0)->len; - } - else - { - str0 = ase_awk_valtostr ( - run, a0, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &len0); - if (str0 == ASE_NULL) return -1; - - } - - /* the target name contains a null character. - * make fflush return -1 */ - ptr = str0; end = str0 + len0; - while (ptr < end) - { - if (*ptr == ASE_T('\0')) - { - if (a0->type != ASE_AWK_VAL_STR) - ASE_AWK_FREE (run->awk, str0); - n = -1; - goto skip_flush; - } - - ptr++; - } - - /* flush the given extio */ - n = __flush_extio ( - run, ASE_AWK_EXTIO_FILE, - ((len0 == 0)? ASE_NULL: str0), 1); - /*if (n == -99) return -1;*/ - n = __flush_extio ( - run, ASE_AWK_EXTIO_PIPE, - ((len0 == 0)? ASE_NULL: str0), n); - /*if (n == -99) return -1;*/ - n = __flush_extio ( - run, ASE_AWK_EXTIO_COPROC, - ((len0 == 0)? ASE_NULL: str0), n); - /*if (n == -99) return -1;*/ - - /* if n remains 1, no ip handlers have been defined for - * file, pipe, and coproc. so make fflush return -1. - * if n is -2, no such named io has been found at all - * if n is -1, the io handler has returned an error */ - if (n != 0) n = -1; - - if (a0->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, str0); - } - -skip_flush: - a0 = ase_awk_makeintval (run, (ase_long_t)n); - if (a0 == ASE_NULL) - { - ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); - return -1; - } - - ase_awk_setretval (run, a0); - return 0; -} - -static int __bfn_index ( - ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl) -{ - ase_size_t nargs; - ase_awk_val_t* a0, * a1; - ase_char_t* str0, * str1, * ptr; - ase_size_t len0, len1; - ase_long_t idx; - - nargs = ase_awk_getnargs (run); - ASE_ASSERT (nargs == 2); - - a0 = ase_awk_getarg (run, 0); - a1 = ase_awk_getarg (run, 1); - - if (a0->type == ASE_AWK_VAL_STR) - { - str0 = ((ase_awk_val_str_t*)a0)->buf; - len0 = ((ase_awk_val_str_t*)a0)->len; - } - else - { - str0 = ase_awk_valtostr ( - run, a0, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &len0); - if (str0 == ASE_NULL) return -1; - } - - if (a1->type == ASE_AWK_VAL_STR) - { - str1 = ((ase_awk_val_str_t*)a1)->buf; - len1 = ((ase_awk_val_str_t*)a1)->len; - } - else - { - str1 = ase_awk_valtostr ( - run, a1, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &len1); - if (str1 == ASE_NULL) - { - if (a0->type != ASE_AWK_VAL_STR) - ASE_AWK_FREE (run->awk, str0); - return -1; - } - } - - ptr = ase_strxnstr (str0, len0, str1, len1); - idx = (ptr == ASE_NULL)? -1: (ase_long_t)(ptr - str0); - - if (ase_awk_getoption(run->awk) & ASE_AWK_STRBASEONE) idx = idx + 1; - - if (a0->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, str0); - if (a1->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, str1); - - a0 = ase_awk_makeintval (run, idx); - if (a0 == ASE_NULL) - { - ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); - return -1; - } - - ase_awk_setretval (run, a0); - return 0; -} - -static int __bfn_length ( - ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl) -{ - ase_size_t nargs; - ase_awk_val_t* v; - ase_char_t* str; - ase_size_t len; - - nargs = ase_awk_getnargs (run); - ASE_ASSERT (nargs == 1); - - v = ase_awk_getarg (run, 0); - if (v->type == ASE_AWK_VAL_STR) - { - len = ((ase_awk_val_str_t*)v)->len; - } - else - { - str = ase_awk_valtostr ( - run, v, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &len); - if (str == ASE_NULL) return -1; - ASE_AWK_FREE (run->awk, str); - } - - v = ase_awk_makeintval (run, len); - if (v == ASE_NULL) - { - ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); - return -1; - } - - ase_awk_setretval (run, v); - return 0; -} - -static int __bfn_substr ( - ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl) -{ - ase_size_t nargs; - ase_awk_val_t* a0, * a1, * a2, * r; - ase_char_t* str; - ase_size_t len; - ase_long_t lindex, lcount; - ase_real_t rindex, rcount; - int n; - - nargs = ase_awk_getnargs (run); - ASE_ASSERT (nargs >= 2 && nargs <= 3); - - a0 = ase_awk_getarg (run, 0); - a1 = ase_awk_getarg (run, 1); - a2 = (nargs >= 3)? ase_awk_getarg (run, 2): ASE_NULL; - - if (a0->type == ASE_AWK_VAL_STR) - { - str = ((ase_awk_val_str_t*)a0)->buf; - len = ((ase_awk_val_str_t*)a0)->len; - } - else - { - str = ase_awk_valtostr ( - run, a0, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &len); - if (str == ASE_NULL) return -1; - } - - n = ase_awk_valtonum (run, a1, &lindex, &rindex); - if (n == -1) - { - if (a0->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, str); - return -1; - } - if (n == 1) lindex = (ase_long_t)rindex; - - if (a2 == ASE_NULL) lcount = (ase_long_t)len; - else - { - n = ase_awk_valtonum (run, a2, &lcount, &rcount); - if (n == -1) - { - if (a0->type != ASE_AWK_VAL_STR) - ASE_AWK_FREE (run->awk, str); - return -1; - } - if (n == 1) lcount = (ase_long_t)rcount; - } - - if (ase_awk_getoption(run->awk) & ASE_AWK_STRBASEONE) lindex = lindex - 1; - if (lindex >= len) lindex = len; - else if (lindex < 0) lindex = 0; - - if (lcount < 0) lcount = 0; - else if (lcount > len - lindex) lcount = len - lindex; - - r = ase_awk_makestrval (run, &str[lindex], (ase_size_t)lcount); - if (r == ASE_NULL) - { - if (a0->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, str); - ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); - return -1; - } - - if (a0->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, str); - ase_awk_setretval (run, r); - return 0; -} - -static int __bfn_split ( - ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl) -{ - ase_size_t nargs; - ase_awk_val_t* a0, * a1, * a2, * t1, * t2, ** a1_ref; - ase_char_t* str, * str_free, * p, * tok; - ase_size_t str_len, str_left, tok_len; - ase_long_t sta, num; - ase_char_t key[ASE_SIZEOF(ase_long_t)*8+2]; - ase_size_t key_len; - ase_char_t* fs_ptr, * fs_free; - ase_size_t fs_len; - void* fs_rex = ASE_NULL; - void* fs_rex_free = ASE_NULL; - int errnum; - - nargs = ase_awk_getnargs (run); - ASE_ASSERT (nargs >= 2 && nargs <= 3); - - a0 = ase_awk_getarg (run, 0); - a1 = ase_awk_getarg (run, 1); - a2 = (nargs >= 3)? ase_awk_getarg (run, 2): ASE_NULL; - - ASE_ASSERT (a1->type == ASE_AWK_VAL_REF); - - if (((ase_awk_val_ref_t*)a1)->id >= ASE_AWK_VAL_REF_NAMEDIDX && - ((ase_awk_val_ref_t*)a1)->id <= ASE_AWK_VAL_REF_ARGIDX) - { - /* an indexed value should not be assigned another map */ - ase_awk_setrunerrnum (run, ASE_AWK_EIDXVALASSMAP); - return -1; - } - - if (((ase_awk_val_ref_t*)a1)->id == ASE_AWK_VAL_REF_POS) - { - /* a positional should not be assigned a map */ - ase_awk_setrunerrnum (run, ASE_AWK_EPOSVALASSMAP); - return -1; - } - - a1_ref = (ase_awk_val_t**)((ase_awk_val_ref_t*)a1)->adr; - if ((*a1_ref)->type != ASE_AWK_VAL_NIL && - (*a1_ref)->type != ASE_AWK_VAL_MAP) - { - /* cannot change a scalar value to a map */ - ase_awk_setrunerrnum (run, ASE_AWK_ESCALARTOMAP); - return -1; - } - - if (a0->type == ASE_AWK_VAL_STR) - { - str = ((ase_awk_val_str_t*)a0)->buf; - str_len = ((ase_awk_val_str_t*)a0)->len; - str_free = ASE_NULL; - } - else - { - str = ase_awk_valtostr ( - run, a0, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &str_len); - if (str == ASE_NULL) return -1; - str_free = str; - } - - if (a2 == ASE_NULL) - { - /* get the value from FS */ - t1 = ase_awk_getglobal (run, ASE_AWK_GLOBAL_FS); - if (t1->type == ASE_AWK_VAL_NIL) - { - fs_ptr = ASE_T(" "); - fs_len = 1; - fs_free = ASE_NULL; - } - else if (t1->type == ASE_AWK_VAL_STR) - { - fs_ptr = ((ase_awk_val_str_t*)t1)->buf; - fs_len = ((ase_awk_val_str_t*)t1)->len; - fs_free = ASE_NULL; - } - else - { - fs_ptr = ase_awk_valtostr ( - run, t1, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &fs_len); - if (fs_ptr == ASE_NULL) - { - if (str_free != ASE_NULL) - ASE_AWK_FREE (run->awk, str_free); - return -1; - } - fs_free = fs_ptr; - } - - if (fs_len > 1) - { - fs_rex = run->global.fs; - fs_rex_free = ASE_NULL; - } - } - else - { - if (a2->type == ASE_AWK_VAL_STR) - { - fs_ptr = ((ase_awk_val_str_t*)a2)->buf; - fs_len = ((ase_awk_val_str_t*)a2)->len; - fs_free = ASE_NULL; - } - else - { - fs_ptr = ase_awk_valtostr ( - run, a2, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &fs_len); - if (fs_ptr == ASE_NULL) - { - if (str_free != ASE_NULL) - ASE_AWK_FREE (run->awk, str_free); - return -1; - } - fs_free = fs_ptr; - } - - if (fs_len > 1) - { - fs_rex = ase_awk_buildrex ( - run->awk, fs_ptr, fs_len, &errnum); - if (fs_rex == ASE_NULL) - { - if (str_free != ASE_NULL) - ASE_AWK_FREE (run->awk, str_free); - if (fs_free != ASE_NULL) - ASE_AWK_FREE (run->awk, fs_free); - ase_awk_setrunerrnum (run, errnum); - return -1; - } - fs_rex_free = fs_rex; - } - } - - t1 = ase_awk_makemapval (run); - if (t1 == ASE_NULL) - { - if (str_free != ASE_NULL) - ASE_AWK_FREE (run->awk, str_free); - if (fs_free != ASE_NULL) - ASE_AWK_FREE (run->awk, fs_free); - if (fs_rex_free != ASE_NULL) - ase_awk_freerex (run->awk, fs_rex_free); - ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); - return -1; - } - - ase_awk_refdownval (run, *a1_ref); - *a1_ref = t1; - ase_awk_refupval (run, *a1_ref); - - p = str; str_left = str_len; - sta = (ase_awk_getoption(run->awk) & ASE_AWK_STRBASEONE)? 1: 0; - num = sta; - - while (p != ASE_NULL) - { - if (fs_len <= 1) - { - p = ase_awk_strxntok (run, - p, str_len, fs_ptr, fs_len, &tok, &tok_len); - } - else - { - p = ase_awk_strxntokbyrex (run, p, str_len, - fs_rex, &tok, &tok_len, &errnum); - if (p == ASE_NULL && errnum != ASE_AWK_ENOERR) - { - if (str_free != ASE_NULL) - ASE_AWK_FREE (run->awk, str_free); - if (fs_free != ASE_NULL) - ASE_AWK_FREE (run->awk, fs_free); - if (fs_rex_free != ASE_NULL) - ase_awk_freerex (run->awk, fs_rex_free); - ase_awk_setrunerrnum (run, errnum); - return -1; - } - } - - if (num == 0 && p == ASE_NULL && tok_len == 0) - { - /* no field at all*/ - break; - } - - ASE_ASSERT ( - (tok != ASE_NULL && tok_len > 0) || tok_len == 0); - - /* create the field string */ - t2 = ase_awk_makestrval (run, tok, tok_len); - if (t2 == ASE_NULL) - { - if (str_free != ASE_NULL) - ASE_AWK_FREE (run->awk, str_free); - if (fs_free != ASE_NULL) - ASE_AWK_FREE (run->awk, fs_free); - if (fs_rex_free != ASE_NULL) - ase_awk_freerex (run->awk, fs_rex_free); - ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); - return -1; - } - - /* put it into the map */ - key_len = ase_awk_longtostr ( - num, 10, ASE_NULL, key, ASE_COUNTOF(key)); - ASE_ASSERT (key_len != (ase_size_t)-1); - - /* don't forget to update the reference count when you - * handle the assignment-like situation. anyway, it is - * incremented in advance as if the assignment was successful. - * it is decremented if the assignement fails. */ - ase_awk_refupval (run, t2); - - if (ase_awk_map_putx ( - ((ase_awk_val_map_t*)t1)->map, - key, key_len, t2, ASE_NULL) == -1) - { - ase_awk_refdownval (run, t2); - - if (str_free != ASE_NULL) - ASE_AWK_FREE (run->awk, str_free); - if (fs_free != ASE_NULL) - ASE_AWK_FREE (run->awk, fs_free); - if (fs_rex_free != ASE_NULL) - ase_awk_freerex (run->awk, fs_rex_free); - ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); - return -1; - } - - num++; - str_len = str_left - (p - str); - } - - if (str_free != ASE_NULL) ASE_AWK_FREE (run->awk, str_free); - if (fs_free != ASE_NULL) ASE_AWK_FREE (run->awk, fs_free); - if (fs_rex_free != ASE_NULL) ase_awk_freerex (run->awk, fs_rex_free); - - if (sta == 1) num--; - - t1 = ase_awk_makeintval (run, num); - if (t1 == ASE_NULL) - { - ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); - return -1; - } - - ase_awk_setretval (run, t1); - return 0; -} - -static int __bfn_tolower ( - ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl) -{ - ase_size_t nargs; - ase_char_t* str; - ase_size_t len, i; - ase_awk_val_t* a0, * r; - - nargs = ase_awk_getnargs (run); - ASE_ASSERT (nargs == 1); - - a0 = ase_awk_getarg (run, 0); - - if (a0->type == ASE_AWK_VAL_STR) - { - str = ((ase_awk_val_str_t*)a0)->buf; - len = ((ase_awk_val_str_t*)a0)->len; - } - else - { - str = ase_awk_valtostr ( - run, a0, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &len); - if (str == ASE_NULL) return -1; - } - - for (i = 0; i < len; i++) str[i] = ASE_AWK_TOLOWER (run->awk, str[i]); - - r = ase_awk_makestrval (run, str, len); - if (r == ASE_NULL) - { - if (a0->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, str); - ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); - return -1; - } - - if (a0->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, str); - ase_awk_setretval (run, r); - return 0; -} - -static int __bfn_toupper ( - ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl) -{ - ase_size_t nargs; - ase_char_t* str; - ase_size_t len, i; - ase_awk_val_t* a0, * r; - - nargs = ase_awk_getnargs (run); - ASE_ASSERT (nargs == 1); - - a0 = ase_awk_getarg (run, 0); - - if (a0->type == ASE_AWK_VAL_STR) - { - str = ((ase_awk_val_str_t*)a0)->buf; - len = ((ase_awk_val_str_t*)a0)->len; - } - else - { - str = ase_awk_valtostr ( - run, a0, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &len); - if (str == ASE_NULL) return -1; - } - - for (i = 0; i < len; i++) str[i] = ASE_AWK_TOUPPER (run->awk, str[i]); - - r = ase_awk_makestrval (run, str, len); - if (r == ASE_NULL) - { - if (a0->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, str); - ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); - return -1; - } - - if (a0->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, str); - ase_awk_setretval (run, r); - return 0; -} - -static int __substitute (ase_awk_run_t* run, ase_long_t max_count) -{ - ase_size_t nargs; - ase_awk_val_t* a0, * a1, * a2, ** a2_ref, * v; - ase_char_t* a0_ptr, * a1_ptr, * a2_ptr; - ase_size_t a0_len, a1_len, a2_len; - ase_char_t* a0_ptr_free = ASE_NULL; - ase_char_t* a1_ptr_free = ASE_NULL; - ase_char_t* a2_ptr_free = ASE_NULL; - void* rex = ASE_NULL; - int opt, n; - const ase_char_t* cur_ptr, * mat_ptr; - ase_size_t cur_len, mat_len, i, m; - ase_str_t new; - ase_long_t sub_count; - - nargs = ase_awk_getnargs (run); - ASE_ASSERT (nargs >= 2 && nargs <= 3); - - a0 = ase_awk_getarg (run, 0); - a1 = ase_awk_getarg (run, 1); - a2 = (nargs >= 3)? ase_awk_getarg (run, 2): ASE_NULL; - - ASE_ASSERT (a2 == ASE_NULL || a2->type == ASE_AWK_VAL_REF); - -#define FREE_A_PTRS(awk) \ - do { \ - if (a2_ptr_free != ASE_NULL) ASE_AWK_FREE (awk, a2_ptr_free); \ - if (a1_ptr_free != ASE_NULL) ASE_AWK_FREE (awk, a1_ptr_free); \ - if (a0_ptr_free != ASE_NULL) ASE_AWK_FREE (awk, a0_ptr_free); \ - } while (0) -#define FREE_A0_REX(awk,rex) \ - do { \ - if (a0->type != ASE_AWK_VAL_REX) ase_awk_freerex (awk, rex); \ - } while (0) - - if (a0->type == ASE_AWK_VAL_REX) - { - rex = ((ase_awk_val_rex_t*)a0)->code; - } - else if (a0->type == ASE_AWK_VAL_STR) - { - a0_ptr = ((ase_awk_val_str_t*)a0)->buf; - a0_len = ((ase_awk_val_str_t*)a0)->len; - } - else - { - a0_ptr = ase_awk_valtostr ( - run, a0, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &a0_len); - if (a0_ptr == ASE_NULL) - { - FREE_A_PTRS (run->awk); - return -1; - } - a0_ptr_free = a0_ptr; - } - - if (a1->type == ASE_AWK_VAL_STR) - { - a1_ptr = ((ase_awk_val_str_t*)a1)->buf; - a1_len = ((ase_awk_val_str_t*)a1)->len; - } - else - { - a1_ptr = ase_awk_valtostr ( - run, a1, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &a1_len); - if (a1_ptr == ASE_NULL) - { - FREE_A_PTRS (run->awk); - return -1; - } - a1_ptr_free = a1_ptr; - } - - if (a2 == ASE_NULL) - { - /* is this correct? any needs to use inrec.d0? */ - a2_ptr = ASE_STR_BUF(&run->inrec.line); - a2_len = ASE_STR_LEN(&run->inrec.line); - } - else if (((ase_awk_val_ref_t*)a2)->id == ASE_AWK_VAL_REF_POS) - { - ase_size_t idx; - - idx = (ase_size_t)((ase_awk_val_ref_t*)a2)->adr; - if (idx == 0) - { - a2_ptr = ASE_STR_BUF(&run->inrec.line); - a2_len = ASE_STR_LEN(&run->inrec.line); - } - else if (idx <= run->inrec.nflds) - { - a2_ptr = run->inrec.flds[idx-1].ptr; - a2_len = run->inrec.flds[idx-1].len; - } - else - { - a2_ptr = ASE_T(""); - a2_len = 0; - } - } - else - { - a2_ref = (ase_awk_val_t**)((ase_awk_val_ref_t*)a2)->adr; - - if ((*a2_ref)->type == ASE_AWK_VAL_MAP) - { - FREE_A_PTRS (run->awk); - /* a map is not allowed as the third parameter */ - ase_awk_setrunerrnum (run, ASE_AWK_EMAPNOTALLOWED); - return -1; - } - - if ((*a2_ref)->type == ASE_AWK_VAL_STR) - { - a2_ptr = ((ase_awk_val_str_t*)(*a2_ref))->buf; - a2_len = ((ase_awk_val_str_t*)(*a2_ref))->len; - } - else - { - a2_ptr = ase_awk_valtostr ( - run, *a2_ref, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &a2_len); - if (a2_ptr == ASE_NULL) - { - FREE_A_PTRS (run->awk); - return -1; - } - a2_ptr_free = a2_ptr; - } - } - - if (ase_str_open (&new, a2_len, &run->awk->prmfns.mmgr) == ASE_NULL) - { - FREE_A_PTRS (run->awk); - ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); - return -1; - } - - if (a0->type != ASE_AWK_VAL_REX) - { - rex = ase_awk_buildrex (run->awk, a0_ptr, a0_len, &run->errnum); - if (rex == ASE_NULL) - { - ase_str_close (&new); - FREE_A_PTRS (run->awk); - return -1; - } - } - - opt = (run->global.ignorecase)? ASE_AWK_REX_IGNORECASE: 0; - cur_ptr = a2_ptr; - cur_len = a2_len; - sub_count = 0; - - while (1) - { - if (max_count == 0 || sub_count < max_count) - { - n = ase_awk_matchrex ( - run->awk, rex, opt, cur_ptr, cur_len, - &mat_ptr, &mat_len, &run->errnum); - } - else n = 0; - - if (n == -1) - { - FREE_A0_REX (run->awk, rex); - ase_str_close (&new); - FREE_A_PTRS (run->awk); - return -1; - } - - if (n == 0) - { - /* no more match found */ - if (ase_str_ncat ( - &new, cur_ptr, cur_len) == (ase_size_t)-1) - { - FREE_A0_REX (run->awk, rex); - ase_str_close (&new); - FREE_A_PTRS (run->awk); - return -1; - } - break; - } - - if (ase_str_ncat ( - &new, cur_ptr, mat_ptr - cur_ptr) == (ase_size_t)-1) - { - FREE_A0_REX (run->awk, rex); - ase_str_close (&new); - FREE_A_PTRS (run->awk); - return -1; - } - - for (i = 0; i < a1_len; i++) - { - if ((i+1) < a1_len && - a1_ptr[i] == ASE_T('\\') && - a1_ptr[i+1] == ASE_T('&')) - { - m = ase_str_ccat (&new, ASE_T('&')); - i++; - } - else if (a1_ptr[i] == ASE_T('&')) - { - m = ase_str_ncat (&new, mat_ptr, mat_len); - } - else - { - m = ase_str_ccat (&new, a1_ptr[i]); - } - - if (m == (ase_size_t)-1) - { - FREE_A0_REX (run->awk, rex); - ase_str_close (&new); - FREE_A_PTRS (run->awk); - return -1; - } - } - - sub_count++; - cur_len = cur_len - ((mat_ptr - cur_ptr) + mat_len); - cur_ptr = mat_ptr + mat_len; - } - - FREE_A0_REX (run->awk, rex); - - if (sub_count > 0) - { - if (a2 == ASE_NULL) - { - if (ase_awk_setrec (run, 0, - ASE_STR_BUF(&new), ASE_STR_LEN(&new)) == -1) - { - ase_str_close (&new); - FREE_A_PTRS (run->awk); - return -1; - } - } - else if (((ase_awk_val_ref_t*)a2)->id == ASE_AWK_VAL_REF_POS) - { - int n; - - n = ase_awk_setrec ( - run, (ase_size_t)((ase_awk_val_ref_t*)a2)->adr, - ASE_STR_BUF(&new), ASE_STR_LEN(&new)); - - if (n == -1) - { - ase_str_close (&new); - FREE_A_PTRS (run->awk); - return -1; - } - } - else - { - v = ase_awk_makestrval (run, - ASE_STR_BUF(&new), ASE_STR_LEN(&new)); - if (v == ASE_NULL) - { - ase_str_close (&new); - FREE_A_PTRS (run->awk); - return -1; - } - - ase_awk_refdownval (run, *a2_ref); - *a2_ref = v; - ase_awk_refupval (run, *a2_ref); - } - } - - ase_str_close (&new); - FREE_A_PTRS (run->awk); - -#undef FREE_A0_REX -#undef FREE_A_PTRS - - v = ase_awk_makeintval (run, sub_count); - if (v == ASE_NULL) - { - ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); - return -1; - } - - ase_awk_setretval (run, v); - return 0; -} - -static int __bfn_gsub ( - ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl) -{ - return __substitute (run, 0); -} - -static int __bfn_sub ( - ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl) -{ - return __substitute (run, 1); -} - -static int __bfn_match ( - ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl) -{ - ase_size_t nargs; - ase_awk_val_t* a0, * a1; - ase_char_t* str0, * str1; - ase_size_t len0, len1; - ase_long_t idx; - void* rex; - int opt, n; - const ase_char_t* mat_ptr; - ase_size_t mat_len; - - nargs = ase_awk_getnargs (run); - ASE_ASSERT (nargs == 2); - - a0 = ase_awk_getarg (run, 0); - a1 = ase_awk_getarg (run, 1); - - if (a0->type == ASE_AWK_VAL_STR) - { - str0 = ((ase_awk_val_str_t*)a0)->buf; - len0 = ((ase_awk_val_str_t*)a0)->len; - } - else - { - str0 = ase_awk_valtostr ( - run, a0, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &len0); - if (str0 == ASE_NULL) return -1; - } - - if (a1->type == ASE_AWK_VAL_REX) - { - rex = ((ase_awk_val_rex_t*)a1)->code; - } - else - { - if (a1->type == ASE_AWK_VAL_STR) - { - str1 = ((ase_awk_val_str_t*)a1)->buf; - len1 = ((ase_awk_val_str_t*)a1)->len; - } - else - { - str1 = ase_awk_valtostr ( - run, a1, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &len1); - if (str1 == ASE_NULL) - { - if (a0->type != ASE_AWK_VAL_STR) - ASE_AWK_FREE (run->awk, str0); - return -1; - } - } - - rex = ase_awk_buildrex (run->awk, str1, len1, &run->errnum); - if (rex == ASE_NULL) - { - if (a0->type != ASE_AWK_VAL_STR) - ASE_AWK_FREE (run->awk, str0); - return -1; - } - - if (a1->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, str1); - } - - opt = (run->global.ignorecase)? ASE_AWK_REX_IGNORECASE: 0; - n = ase_awk_matchrex ( - run->awk, rex, opt, str0, len0, - &mat_ptr, &mat_len, &run->errnum); - - if (a0->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, str0); - if (a1->type != ASE_AWK_VAL_REX) ase_awk_freerex (run->awk, rex); - - if (n == -1) return -1; - - idx = (n == 0)? -1: (ase_long_t)(mat_ptr - str0); - if (ase_awk_getoption(run->awk) & ASE_AWK_STRBASEONE) idx = idx + 1; - - a0 = ase_awk_makeintval (run, idx); - if (a0 == ASE_NULL) - { - ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); - return -1; - } - - ase_awk_refupval (run, a0); - - a1 = ase_awk_makeintval (run, - ((n == 0)? (ase_long_t)-1: (ase_long_t)mat_len)); - if (a1 == ASE_NULL) - { - ase_awk_refdownval (run, a0); - ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); - return -1; - } - - ase_awk_refupval (run, a1); - - if (ase_awk_setglobal (run, ASE_AWK_GLOBAL_RSTART, a0) == -1) - { - ase_awk_refdownval (run, a1); - ase_awk_refdownval (run, a0); - return -1; - } - - if (ase_awk_setglobal (run, ASE_AWK_GLOBAL_RLENGTH, a1) == -1) - { - ase_awk_refdownval (run, a1); - ase_awk_refdownval (run, a0); - return -1; - } - - ase_awk_setretval (run, a0); - - ase_awk_refdownval (run, a1); - ase_awk_refdownval (run, a0); - return 0; -} - -static int __bfn_sprintf ( - ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl) -{ - ase_size_t nargs; - ase_awk_val_t* a0; - ase_char_t* str0, * ptr; - ase_size_t len0, len; - ase_str_t out, fbu; - - nargs = ase_awk_getnargs (run); - ASE_ASSERT (nargs > 0); - - if (ase_str_open (&out, 256, &run->awk->prmfns.mmgr) == ASE_NULL) - { - ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); - return -1; - } - if (ase_str_open (&fbu, 256, &run->awk->prmfns.mmgr) == ASE_NULL) - { - ase_str_close (&out); - ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); - return -1; - } - - a0 = ase_awk_getarg (run, 0); - if (a0->type == ASE_AWK_VAL_STR) - { - str0 = ((ase_awk_val_str_t*)a0)->buf; - len0 = ((ase_awk_val_str_t*)a0)->len; - } - else - { - str0 = ase_awk_valtostr ( - run, a0, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &len0); - if (str0 == ASE_NULL) - { - ase_str_close (&fbu); - ase_str_close (&out); - return -1; - } - } - - ptr = ase_awk_format (run, - &out, &fbu, str0, len0, nargs, ASE_NULL, &len); - if (a0->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, str0); - if (ptr == ASE_NULL) - { - ase_str_close (&fbu); - ase_str_close (&out); - return -1; - } - - a0 = ase_awk_makestrval_nodup (run, ptr, len); - if (a0 == ASE_NULL) - { - ase_str_close (&fbu); - ase_str_close (&out); - ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); - return -1; - } - - ase_str_close (&fbu); - ase_str_forfeit (&out); - ase_awk_setretval (run, a0); - return 0; -} diff --git a/ase/awk/func.h b/ase/awk/func.h deleted file mode 100644 index 05a7a1cf..00000000 --- a/ase/awk/func.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * $Id: func.h,v 1.1.1.1 2007/03/28 14:05:15 bacon Exp $ - * - * {License} - */ - -#ifndef _ASE_AWK_FUNC_H_ -#define _ASE_AWK_FUNC_H_ - -#ifndef _ASE_AWK_AWK_H_ -#error Never include this file directly. Include instead -#endif - -typedef struct ase_awk_bfn_t ase_awk_bfn_t; - -struct ase_awk_bfn_t -{ - struct - { - ase_char_t* ptr; - ase_size_t len; - } name; - - int valid; /* the entry is valid when this option is set */ - - struct - { - ase_size_t min; - ase_size_t max; - ase_char_t* spec; - } arg; - - int (*handler) (ase_awk_run_t*, const ase_char_t*, ase_size_t); - - ase_awk_bfn_t* next; -}; - -#ifdef __cplusplus -extern "C" { -#endif - -ase_awk_bfn_t* ase_awk_getbfn ( - ase_awk_t* awk, const ase_char_t* name, ase_size_t len); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ase/awk/jni.c b/ase/awk/jni.c deleted file mode 100644 index 1a142887..00000000 --- a/ase/awk/jni.c +++ /dev/null @@ -1,2346 +0,0 @@ -/* - * $Id: jni.c,v 1.1.1.1 2007/03/28 14:05:15 bacon Exp $ - * - * {License} - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#ifdef _WIN32 -#include -#include -#endif - -#ifndef ASE_CHAR_IS_WCHAR - #error this module supports ASE_CHAR_IS_WCHAR only -#endif - -#define CLASS_OUTOFMEMORYERROR "java/lang/OutOfMemoryError" -#define CLASS_EXCEPTION "ase/awk/Exception" -#define CLASS_EXTIO "ase/awk/Extio" -#define FIELD_HANDLE "handle" - -#define MSG_SIZE 256 - -enum -{ - SOURCE_READ = 1, - SOURCE_WRITE = 2 -}; - -static ase_ssize_t __read_source ( - int cmd, void* arg, ase_char_t* data, ase_size_t count); -static ase_ssize_t __write_source ( - int cmd, void* arg, ase_char_t* data, ase_size_t count); -static ase_ssize_t __process_extio ( - int cmd, void* arg, ase_char_t* data, ase_size_t count); - -typedef struct awk_data_t awk_data_t; -typedef struct srcio_data_t srcio_data_t; -typedef struct runio_data_t runio_data_t; -typedef struct run_data_t run_data_t; - -struct awk_data_t -{ - int debug; -}; - -struct srcio_data_t -{ - JNIEnv* env; - jobject obj; -}; - -struct runio_data_t -{ - JNIEnv* env; - jobject obj; -}; - -struct run_data_t -{ - JNIEnv* env; - jobject obj; - - jclass string_class; - jclass integer_class; - jclass long_class; - jclass short_class; - jclass float_class; - jclass double_class; - jclass object_class; - - jmethodID integer_init; - jmethodID long_init; - jmethodID short_init; - jmethodID float_init; - jmethodID double_init; - - jmethodID integer_value; - jmethodID long_value; - jmethodID short_value; - jmethodID float_value; - jmethodID double_value; -}; - -static void* awk_malloc (void* custom, ase_size_t n) -{ - return malloc (n); -} - -static void* awk_realloc (void* custom, void* ptr, ase_size_t n) -{ - return realloc (ptr, n); -} - -static void awk_free (void* custom, void* ptr) -{ - free (ptr); -} - -/* custom character class functions */ -static ase_bool_t awk_isupper (void* custom, ase_cint_t c) -{ - return ase_isupper (c); -} - -static ase_bool_t awk_islower (void* custom, ase_cint_t c) -{ - return ase_islower (c); -} - -static ase_bool_t awk_isalpha (void* custom, ase_cint_t c) -{ - return ase_isalpha (c); -} - -static ase_bool_t awk_isdigit (void* custom, ase_cint_t c) -{ - return ase_isdigit (c); -} - -static ase_bool_t awk_isxdigit (void* custom, ase_cint_t c) -{ - return ase_isxdigit (c); -} - -static ase_bool_t awk_isalnum (void* custom, ase_cint_t c) -{ - return ase_isalnum (c); -} - -static ase_bool_t awk_isspace (void* custom, ase_cint_t c) -{ - return ase_isspace (c); -} - -static ase_bool_t awk_isprint (void* custom, ase_cint_t c) -{ - return ase_isprint (c); -} - -static ase_bool_t awk_isgraph (void* custom, ase_cint_t c) -{ - return ase_isgraph (c); -} - -static ase_bool_t awk_iscntrl (void* custom, ase_cint_t c) -{ - return ase_iscntrl (c); -} - -static ase_bool_t awk_ispunct (void* custom, ase_cint_t c) -{ - return ase_ispunct (c); -} - -static ase_cint_t awk_toupper (void* custom, ase_cint_t c) -{ - return ase_toupper (c); -} - -static ase_cint_t awk_tolower (void* custom, ase_cint_t c) -{ - return ase_tolower (c); -} - -static ase_real_t awk_pow (void* custom, ase_real_t x, ase_real_t y) -{ - return pow (x, y); -} - -static 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; -} - -static 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); -} - -#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_vfprintf (stdout, fmt, ap); - va_end (ap); -} -#endif - -static void throw_exception ( - JNIEnv* env, const ase_char_t* msg, jint code, jint line) -{ - jclass except_class; - jmethodID except_cons; - jstring except_msg; - jthrowable except_obj; - ase_size_t len; - - except_class = (*env)->FindClass (env, CLASS_EXCEPTION); - if (except_class == NULL) - { - /* the exception to be thrown by FindClass is not cleared. - * 1. this should not happend as the ase.awk.Exception - * class should always be there. - * 2. if it happens, this exception may abort the entire - * program as the exception is not likely to be handled - * explicitly by the java program. */ - return; - } - - except_cons = (*env)->GetMethodID ( - env, except_class, "", "(Ljava/lang/String;II)V"); - if (except_cons == NULL) - { - /* the potential exception to be thrown by the GetMethodID - * method is not cleared here for the same reason as the - * FindClass method above */ - (*env)->DeleteLocalRef (env, except_class); - return; - } - - len = ase_strlen(msg); - if (len > 0 && ASE_SIZEOF(jchar) != ASE_SIZEOF(ase_char_t)) - { - ase_size_t i; - jchar* tmp = (jchar*) malloc (ASE_SIZEOF(jchar)*len); - if (tmp == NULL) - { - (*env)->DeleteLocalRef (env, except_class); - - except_class = (*env)->FindClass ( - env, CLASS_OUTOFMEMORYERROR); - if (except_class == NULL) return; - - (*env)->ThrowNew (env, except_class, "out of memory"); - (*env)->DeleteLocalRef (env, except_class); - return; - } - - for (i = 0; i < len; i++) tmp[i] = (jchar)msg[i]; - except_msg = (*env)->NewString (env, tmp, len); - free (tmp); - } - else - { - except_msg = (*env)->NewString (env, (jchar*)msg, len); - } - - if (except_msg == NULL) - { - (*env)->DeleteLocalRef (env, except_class); - return; - } - - except_obj = (*env)->NewObject ( - env, except_class, except_cons, - except_msg, code, line); - - (*env)->DeleteLocalRef (env, except_msg); - (*env)->DeleteLocalRef (env, except_class); - - if (except_obj == NULL) return; - - (*env)->Throw (env, except_obj); - (*env)->DeleteLocalRef (env, except_obj); -} - -static jboolean is_debug (ase_awk_t* awk) -{ - awk_data_t* awk_data = (awk_data_t*)ase_awk_getcustomdata (awk); - return awk_data->debug? JNI_TRUE: JNI_FALSE; -} - -JNIEXPORT void JNICALL Java_ase_awk_Awk_open (JNIEnv* env, jobject obj) -{ - jclass class; - jfieldID handle; - ase_awk_t* awk; - ase_awk_prmfns_t prmfns; - awk_data_t* awk_data; - int opt; - - memset (&prmfns, 0, sizeof(prmfns)); - - prmfns.mmgr.malloc = awk_malloc; - prmfns.mmgr.realloc = awk_realloc; - prmfns.mmgr.free = awk_free; - prmfns.mmgr.custom_data = 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 = NULL; - - prmfns.misc.pow = awk_pow; - prmfns.misc.sprintf = awk_sprintf; - prmfns.misc.dprintf = awk_dprintf; - prmfns.misc.custom_data = NULL; - - awk_data = (awk_data_t*) malloc (sizeof(awk_data_t)); - if (awk_data == NULL) - { - throw_exception ( - env, - ase_awk_geterrstr(ASE_NULL, ASE_AWK_ENOMEM), - ASE_AWK_ENOMEM, - 0); - return; - } - - memset (awk_data, 0, sizeof(awk_data_t)); - - awk = ase_awk_open (&prmfns, awk_data); - if (awk == NULL) - { - throw_exception ( - env, - ase_awk_geterrstr(ASE_NULL, ASE_AWK_ENOMEM), - ASE_AWK_ENOMEM, - 0); - return; - } - - class = (*env)->GetObjectClass(env, obj); - handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); - (*env)->DeleteLocalRef (env, class); - if (handle == NULL) - { - /* internal error. no handle field - * NoSuchFieldError, ExceptionInitializerError, - * OutOfMemoryError might occur */ - - ase_awk_close (awk); - free (awk_data); - return; - } - - (*env)->SetLongField (env, obj, handle, (jlong)awk); - - opt = ASE_AWK_EXPLICIT | ASE_AWK_UNIQUEFN | ASE_AWK_SHADING | - ASE_AWK_IMPLICIT | ASE_AWK_SHIFT | ASE_AWK_IDIV | - ASE_AWK_EXTIO | ASE_AWK_BLOCKLESS | ASE_AWK_NEXTOFILE; - ase_awk_setoption (awk, opt); -} - -JNIEXPORT void JNICALL Java_ase_awk_Awk_close (JNIEnv* env, jobject obj) -{ - jclass class; - jfieldID handle; - ase_awk_t* awk; - - class = (*env)->GetObjectClass(env, obj); - handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); - (*env)->DeleteLocalRef (env, class); - if (handle == NULL) - { - /* internal error. no handle field - * NoSuchFieldError, ExceptionInitializerError, - * OutOfMemoryError might occur */ - return; - } - - awk = (ase_awk_t*) (*env)->GetLongField (env, obj, handle); - if (awk != NULL) - { - /* the handle is not NULL. close it */ - void* tmp = ase_awk_getcustomdata (awk); - ase_awk_close (awk); - (*env)->SetLongField (env, obj, handle, (jlong)0); - free (tmp); - } -} - -JNIEXPORT void JNICALL Java_ase_awk_Awk_parse (JNIEnv* env, jobject obj) -{ - jclass class; - jfieldID handle; - - ase_awk_t* awk; - ase_awk_srcios_t srcios; - srcio_data_t srcio_data; - - class = (*env)->GetObjectClass (env, obj); - handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); - (*env)->DeleteLocalRef (env, class); - if (handle == NULL) - { - /* internal error. no handle field - * NoSuchFieldError, ExceptionInitializerError, - * OutOfMemoryError might occur */ - return; - } - - awk = (ase_awk_t*) (*env)->GetLongField (env, obj, handle); - - srcio_data.env = env; - srcio_data.obj = obj; - - srcios.in = __read_source; - srcios.out = __write_source; - srcios.custom_data = &srcio_data; - - if (ase_awk_parse (awk, &srcios) == -1) - { - throw_exception ( - env, - ase_awk_geterrmsg(awk), - ase_awk_geterrnum(awk), - ase_awk_geterrlin(awk)); - - return; - } -} - -#define DELETE_CLASS_REFS(env, run_data) \ - do { \ - (*env)->DeleteLocalRef (env, run_data.integer_class); \ - (*env)->DeleteLocalRef (env, run_data.long_class); \ - (*env)->DeleteLocalRef (env, run_data.float_class); \ - (*env)->DeleteLocalRef (env, run_data.double_class); \ - (*env)->DeleteLocalRef (env, run_data.string_class); \ - (*env)->DeleteLocalRef (env, run_data.object_class); \ - } while (0) - -static ase_char_t* java_strxdup (const jchar* str, jint len) -{ - if (len > 0 && ASE_SIZEOF(jchar) != ASE_SIZEOF(ase_char_t)) - { - ase_char_t* tmp; - ase_size_t i; - - tmp = (ase_char_t*) malloc ((len+1) * ASE_SIZEOF(ase_char_t)); - if (tmp == ASE_NULL) return ASE_NULL; - - for (i = 0; i < (ase_size_t)len; i++) tmp[i] = (ase_char_t)str[i]; - tmp[i] = ASE_T('\0'); - - return tmp; - } - else - { - ase_char_t* tmp; - - tmp = (ase_char_t*) malloc ((len+1) * ASE_SIZEOF(ase_char_t)); - if (tmp == ASE_NULL) return ASE_NULL; - - ase_strncpy (tmp, (ase_char_t*)str, (ase_size_t)len); - return tmp; - } -} - -JNIEXPORT void JNICALL Java_ase_awk_Awk_run (JNIEnv* env, jobject obj, jstring mfn, jobjectArray args) -{ - jclass class; - jfieldID handle; - - ase_awk_t* awk; - ase_awk_runios_t runios; - runio_data_t runio_data; - run_data_t run_data; - ase_char_t* mmm; - - ase_size_t len, i; - const jchar* ptr; - - ase_awk_runarg_t* runarg = NULL; - - class = (*env)->GetObjectClass (env, obj); - handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); - (*env)->DeleteLocalRef (env, class); - if (handle == 0) - { - /* internal error. no handle field - * NoSuchFieldError, ExceptionInitializerError, - * OutOfMemoryError might occur */ - return; - } - - awk = (ase_awk_t*) (*env)->GetLongField (env, obj, handle); - - run_data.env = env; - run_data.obj = obj; - - /* would global reference be necessary? */ - run_data.string_class = (*env)->FindClass (env, "java/lang/String"); - run_data.integer_class = (*env)->FindClass (env, "java/lang/Integer"); - run_data.long_class = (*env)->FindClass (env, "java/lang/Long"); - run_data.short_class = (*env)->FindClass (env, "java/lang/Short"); - run_data.float_class = (*env)->FindClass (env, "java/lang/Float"); - run_data.double_class = (*env)->FindClass (env, "java/lang/Double"); - run_data.object_class = (*env)->FindClass (env, "java/lang/Object"); - - ASE_ASSERT (run_data.string_class != NULL); - ASE_ASSERT (run_data.integer_class != NULL); - ASE_ASSERT (run_data.short_class != NULL); - ASE_ASSERT (run_data.long_class != NULL); - ASE_ASSERT (run_data.float_class != NULL); - ASE_ASSERT (run_data.double_class != NULL); - ASE_ASSERT (run_data.object_class != NULL); - - run_data.integer_init = (*env)->GetMethodID ( - env, run_data.integer_class, "", "(I)V"); - run_data.long_init = (*env)->GetMethodID ( - env, run_data.long_class, "", "(J)V"); - run_data.short_init = (*env)->GetMethodID ( - env, run_data.short_class, "", "(S)V"); - run_data.float_init = (*env)->GetMethodID ( - env, run_data.float_class, "", "(F)V"); - run_data.double_init = (*env)->GetMethodID ( - env, run_data.double_class, "", "(D)V"); - - ASE_ASSERT (run_data.integer_init != NULL); - ASE_ASSERT (run_data.long_init != NULL); - ASE_ASSERT (run_data.short_init != NULL); - ASE_ASSERT (run_data.float_init != NULL); - ASE_ASSERT (run_data.double_init != NULL); - - run_data.integer_value = (*env)->GetMethodID ( - env, run_data.integer_class, "intValue", "()I"); - run_data.long_value = (*env)->GetMethodID ( - env, run_data.long_class, "longValue", "()J"); - run_data.short_value = (*env)->GetMethodID ( - env, run_data.short_class, "shortValue", "()S"); - run_data.float_value = (*env)->GetMethodID ( - env, run_data.float_class, "floatValue", "()F"); - run_data.double_value = (*env)->GetMethodID ( - env, run_data.double_class, "doubleValue", "()D"); - - ASE_ASSERTX (run_data.integer_value != NULL, - "The Integer class must has the method - int intValue()"); - ASE_ASSERTX (run_data.long_value != NULL, - "The Long class must has the method - long longValue()"); - ASE_ASSERTX (run_data.short_value != NULL, - "The Short class must has the method - short shortValue()"); - ASE_ASSERTX (run_data.float_value != NULL, - "The Float class must has the method - float floatValue()"); - ASE_ASSERTX (run_data.double_value != NULL, - "The Double class must has the method - double doubleValue()"); - - runio_data.env = env; - runio_data.obj = obj; - - runios.pipe = __process_extio; - runios.coproc = ASE_NULL; - runios.file = __process_extio; - runios.console = __process_extio; - runios.custom_data = &runio_data; - - if (mfn == NULL) - { - mmm = NULL; - ptr = NULL; - } - else - { - /* process the main entry point */ - - len = (*env)->GetStringLength (env, mfn); - - if (len > 0) - { - ase_size_t i; - - ptr = (*env)->GetStringChars (env, mfn, JNI_FALSE); - if (ptr == NULL) - { - (*env)->ExceptionClear (env); - DELETE_CLASS_REFS (env, run_data); - throw_exception ( - env, - ase_awk_geterrstr(ASE_NULL, ASE_AWK_ENOMEM), - ASE_AWK_ENOMEM, - 0); - return; - } - - mmm = (ase_char_t*) malloc (ASE_SIZEOF(ase_char_t)*(len+1)); - if (mmm == ASE_NULL) - { - (*env)->ReleaseStringChars (env, mfn, ptr); - DELETE_CLASS_REFS (env, run_data); - throw_exception ( - env, - ase_awk_geterrstr(ASE_NULL, ASE_AWK_ENOMEM), - ASE_AWK_ENOMEM, - 0); - return; - } - - for (i = 0; i < len; i++) - { - mmm[i] = (ase_char_t)ptr[i]; - if (mmm[i] == ASE_T('\0')) - { - free (mmm); - (*env)->ReleaseStringChars (env, mfn, ptr); - DELETE_CLASS_REFS (env, run_data); - throw_exception ( - env, - ASE_T("main function name not valid"), - ASE_AWK_EINVAL, - 0); - return; - } - } - mmm[len] = ASE_T('\0'); - } - else - { - mmm = NULL; - ptr = NULL; - } - } - - if (args != NULL) - { - /* compose arguments */ - - len = (*env)->GetArrayLength (env, args); - - runarg = malloc (sizeof(ase_awk_runarg_t) * (len+1)); - if (runarg == NULL) - { - if (mmm != NULL) free (mmm); - if (ptr != NULL) (*env)->ReleaseStringChars (env, mfn, ptr); - DELETE_CLASS_REFS (env, run_data); - - throw_exception ( - env, - ase_awk_geterrstr(ASE_NULL, ASE_AWK_ENOMEM), - ASE_AWK_ENOMEM, - 0); - - return; - } - - for (i = 0; i < len; i++) - { - const jchar* tmp; - jstring obj = (jstring)(*env)->GetObjectArrayElement (env, args, i); - - runarg[i].len = (*env)->GetStringLength (env, obj); - tmp = (*env)->GetStringChars (env, obj, JNI_FALSE); - if (tmp == NULL) - { - ase_size_t j; - - for (j = 0; j < i; j++) free (runarg[j].ptr); - free (runarg); - - (*env)->DeleteLocalRef (env, obj); - - if (mmm != NULL && mmm) free (mmm); - if (ptr != NULL) (*env)->ReleaseStringChars (env, mfn, ptr); - DELETE_CLASS_REFS (env, run_data); - - throw_exception ( - env, - ase_awk_geterrstr(ASE_NULL, ASE_AWK_ENOMEM), - ASE_AWK_ENOMEM, - 0); - - return; - } - - runarg[i].ptr = java_strxdup (tmp, runarg[i].len); - if (runarg[i].ptr == NULL) - { - ase_size_t j; - - for (j = 0; j < i; j++) free (runarg[j].ptr); - free (runarg); - - (*env)->ReleaseStringChars (env, obj, tmp); - (*env)->DeleteLocalRef (env, obj); - - if (mmm != NULL) free (mmm); - if (ptr != NULL) (*env)->ReleaseStringChars (env, mfn, ptr); - DELETE_CLASS_REFS (env, run_data); - - throw_exception ( - env, - ase_awk_geterrstr(ASE_NULL, ASE_AWK_ENOMEM), - ASE_AWK_ENOMEM, - 0); - - return; - } - - (*env)->ReleaseStringChars (env, obj, tmp); - (*env)->DeleteLocalRef (env, obj); - } - - runarg[i].ptr = NULL; - runarg[i].len = 0; - } - - if (ase_awk_run (awk, - mmm, &runios, ASE_NULL, runarg, &run_data) == -1) - { - if (runarg != NULL) - { - for (i = 0; i < len; i++) free (runarg[i].ptr); - free (runarg); - } - - if (mmm != NULL) free (mmm); - if (ptr != NULL) (*env)->ReleaseStringChars (env, mfn, ptr); - DELETE_CLASS_REFS (env, run_data); - - throw_exception ( - env, - ase_awk_geterrmsg(awk), - ase_awk_geterrnum(awk), - ase_awk_geterrlin(awk)); - return; - } - - if (runarg != NULL) - { - for (i = 0; i < len; i++) free (runarg[i].ptr); - free (runarg); - } - - if (mmm != NULL) free (mmm); - if (ptr != NULL) (*env)->ReleaseStringChars (env, mfn, ptr); - DELETE_CLASS_REFS (env, run_data); -} - -static ase_ssize_t __java_open_source (JNIEnv* env, jobject obj, int mode) -{ - jclass class; - jfieldID handle; - jmethodID mid; - jint ret; - ase_awk_t* awk; - - class = (*env)->GetObjectClass(env, obj); - handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); - mid = (*env)->GetMethodID (env, class, "openSource", "(I)I"); - (*env)->DeleteLocalRef (env, class); - if (handle == NULL) - { - (*env)->ExceptionClear (env); - return -1; - } - awk = (ase_awk_t*)(*env)->GetLongField (env, obj, handle); - - if (mid == NULL) - { - if (is_debug(awk)) (*env)->ExceptionDescribe (env); - (*env)->ExceptionClear (env); - return -1; - } - - ret = (*env)->CallIntMethod (env, obj, mid, mode); - if ((*env)->ExceptionOccurred (env)) - { - if (is_debug(awk)) (*env)->ExceptionDescribe (env); - (*env)->ExceptionClear (env); - ret = -1; - } - - return ret; -} - -static ase_ssize_t __java_close_source (JNIEnv* env, jobject obj, int mode) -{ - jclass class; - jfieldID handle; - jmethodID mid; - jint ret; - ase_awk_t* awk; - - class = (*env)->GetObjectClass(env, obj); - handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); - mid = (*env)->GetMethodID (env, class, "closeSource", "(I)I"); - (*env)->DeleteLocalRef (env, class); - if (handle == NULL) - { - (*env)->ExceptionClear (env); - return -1; - } - awk = (ase_awk_t*)(*env)->GetLongField (env, obj, handle); - - if (mid == NULL) - { - if (is_debug(awk)) (*env)->ExceptionDescribe (env); - (*env)->ExceptionClear (env); - return -1; - } - - ret = (*env)->CallIntMethod (env, obj, mid, mode); - if ((*env)->ExceptionOccurred (env)) - { - if (is_debug(awk)) (*env)->ExceptionDescribe (env); - (*env)->ExceptionClear (env); - ret = -1; - } - - return ret; -} - -static ase_ssize_t __java_read_source ( - JNIEnv* env, jobject obj, ase_char_t* buf, ase_size_t size) -{ - jclass class; - jfieldID handle; - jmethodID mid; - jcharArray array; - jchar* tmp; - jint ret, i; - ase_awk_t* awk; - - class = (*env)->GetObjectClass(env, obj); - handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); - mid = (*env)->GetMethodID (env, class, "readSource", "([CI)I"); - (*env)->DeleteLocalRef (env, class); - if (handle == NULL) - { - (*env)->ExceptionClear (env); - return -1; - } - awk = (ase_awk_t*)(*env)->GetLongField (env, obj, handle); - - if (mid == NULL) - { - if (is_debug(awk)) (*env)->ExceptionDescribe (env); - (*env)->ExceptionClear (env); - return -1; - } - - array = (*env)->NewCharArray (env, size); - if (array == NULL) - { - if (is_debug(awk)) (*env)->ExceptionDescribe (env); - (*env)->ExceptionClear (env); - return -1; - } - - ret = (*env)->CallIntMethod (env, obj, mid, array, size); - if ((*env)->ExceptionOccurred (env)) - { - if (is_debug(awk)) (*env)->ExceptionDescribe (env); - (*env)->ExceptionClear (env); - ret = -1; - } - - tmp = (*env)->GetCharArrayElements (env, array, 0); - for (i = 0; i < ret; i++) buf[i] = (ase_char_t)tmp[i]; - (*env)->ReleaseCharArrayElements (env, array, tmp, 0); - - (*env)->DeleteLocalRef (env, array); - return i; -} - -static ase_ssize_t __java_write_source ( - JNIEnv* env, jobject obj, ase_char_t* buf, ase_size_t size) -{ - jclass class; - jfieldID handle; - jmethodID mid; - jcharArray array; - jchar* tmp; - jint ret; - ase_size_t i; - ase_awk_t* awk; - - class = (*env)->GetObjectClass(env, obj); - handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); - mid = (*env)->GetMethodID (env, class, "writeSource", "([CI)I"); - (*env)->DeleteLocalRef (env, class); - if (handle == NULL) - { - (*env)->ExceptionClear (env); - return -1; - } - awk = (ase_awk_t*)(*env)->GetLongField (env, obj, handle); - - if (mid == NULL) - { - if (is_debug(awk)) (*env)->ExceptionDescribe (env); - (*env)->ExceptionClear (env); - return -1; - } - - array = (*env)->NewCharArray (env, size); - if (array == NULL) - { - if (is_debug(awk)) (*env)->ExceptionDescribe (env); - (*env)->ExceptionClear (env); - return -1; - } - - tmp = (*env)->GetCharArrayElements (env, array, 0); - for (i = 0; i < size; i++) tmp[i] = (jchar)buf[i]; - (*env)->ReleaseCharArrayElements (env, array, tmp, 0); - - ret = (*env)->CallIntMethod (env, obj, mid, array, size); - if ((*env)->ExceptionOccurred (env)) - { - if (is_debug(awk)) (*env)->ExceptionDescribe (env); - (*env)->ExceptionClear (env); - ret = -1; - } - - (*env)->DeleteLocalRef (env, array); - return ret; -} - -static ase_ssize_t __java_open_extio ( - JNIEnv* env, jobject obj, char* meth, ase_awk_extio_t* extio) -{ - jclass class; - jfieldID handle; - jmethodID mid; - jclass extio_class; - jmethodID extio_cons; - jobject extio_object; - jstring extio_name; - jint ret; - ase_awk_t* awk; - ase_size_t len; - - /* get the method - meth */ - class = (*env)->GetObjectClass(env, obj); - handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); - mid = (*env)->GetMethodID (env, class, meth, "(Lase/awk/Extio;)I"); - (*env)->DeleteLocalRef (env, class); - - if (handle == NULL) - { - (*env)->ExceptionClear (env); - return -1; - } - awk = (ase_awk_t*)(*env)->GetLongField (env, obj, handle); - - if (mid == NULL) - { - if (is_debug(awk)) (*env)->ExceptionDescribe (env); - (*env)->ExceptionClear (env); - return -1; - } - - /* look for extio class */ - extio_class = (*env)->FindClass (env, CLASS_EXTIO); - if (extio_class == NULL) - { - if (is_debug(awk)) (*env)->ExceptionDescribe (env); - (*env)->ExceptionClear (env); - return -1; - } - - /* get the constructor */ - extio_cons = (*env)->GetMethodID ( - env, extio_class, "", "(Ljava/lang/String;IIJ)V"); - if (extio_cons == NULL) - { - if (is_debug(awk)) (*env)->ExceptionDescribe (env); - (*env)->ExceptionClear (env); - (*env)->DeleteLocalRef (env, extio_class); - return -1; - } - - /* construct the name */ - len = ase_strlen(extio->name); - if (len > 0 && ASE_SIZEOF(jchar) != ASE_SIZEOF(ase_char_t)) - { - ase_size_t i; - jchar* tmp = (jchar*) malloc (ASE_SIZEOF(jchar)*len); - if (tmp == NULL) - { - (*env)->DeleteLocalRef (env, extio_class); - return -1; - } - - for (i = 0; i < len; i++) tmp[i] = (jchar)extio->name[i]; - extio_name = (*env)->NewString (env, tmp, len); - free (tmp); - } - else - { - extio_name = (*env)->NewString (env, (jchar*)extio->name, len); - } - - if (extio_name == NULL) - { - if (is_debug(awk)) (*env)->ExceptionDescribe (env); - (*env)->ExceptionClear (env); - (*env)->DeleteLocalRef (env, extio_class); - return -1; - } - - /* construct the extio object */ - extio_object = (*env)->NewObject ( - env, extio_class, extio_cons, - extio_name, extio->type & 0xFF, extio->mode, (jlong)extio->run); - (*env)->DeleteLocalRef (env, extio_class); - if (extio_object == NULL) - { - if (is_debug(awk)) (*env)->ExceptionDescribe (env); - (*env)->ExceptionClear (env); - (*env)->DeleteLocalRef (env, extio_name); - return -1; - } - - (*env)->DeleteLocalRef (env, extio_name); - - /* execute the method */ - ret = (*env)->CallIntMethod (env, obj, mid, extio_object); - if ((*env)->ExceptionOccurred(env)) - { - /* clear the exception */ - if (is_debug(awk)) (*env)->ExceptionDescribe (env); - (*env)->ExceptionClear (env); - ret = -1; - } - - if (ret >= 0) - { - /* ret == -1 failed to open the stream - * ret == 0 opened the stream and reached its end - * ret == 1 opened the stream. */ - extio->handle = (*env)->NewGlobalRef (env, extio_object); - /* - if (extio->handle == NULL) - { - // TODO: close the stream ... - if (is_debug(awk)) (*env)->ExceptionDescribe (env); - (*env)->ExceptionClear (env); - ret = -1; - } - */ - } - - (*env)->DeleteLocalRef (env, extio_object); - return ret; -} - -static ase_ssize_t __java_close_extio ( - JNIEnv* env, jobject obj, char* meth, ase_awk_extio_t* extio) -{ - jclass class; - jfieldID handle; - jmethodID mid; - jint ret; - ase_awk_t* awk; - - class = (*env)->GetObjectClass(env, obj); - handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); - mid = (*env)->GetMethodID (env, class, meth, "(Lase/awk/Extio;)I"); - (*env)->DeleteLocalRef (env, class); - - if (handle == NULL) - { - (*env)->ExceptionClear (env); - return -1; - } - awk = (ase_awk_t*)(*env)->GetLongField (env, obj, handle); - if (mid == NULL) - { - if (is_debug(awk)) (*env)->ExceptionDescribe (env); - (*env)->ExceptionClear (env); - return -1; - } - - ret = (*env)->CallIntMethod (env, obj, mid, extio->handle); - if ((*env)->ExceptionOccurred (env)) - { - if (is_debug(awk)) (*env)->ExceptionDescribe (env); - (*env)->ExceptionClear (env); - ret = -1; - } - - if (ret >= 0) - { - /* ret == -1 failed to close the stream - * ret == 0 closed the stream */ - (*env)->DeleteGlobalRef (env, extio->handle); - extio->handle = NULL; - } - - return ret; -} - -static ase_ssize_t __java_read_extio ( - JNIEnv* env, jobject obj, char* meth, - ase_awk_extio_t* extio, ase_char_t* buf, ase_size_t size) -{ - jclass class; - jfieldID handle; - jmethodID mid; - jcharArray array; - jchar* tmp; - jint ret, i; - ase_awk_t* awk; - - class = (*env)->GetObjectClass(env, obj); - handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); - mid = (*env)->GetMethodID (env, class, meth, "(Lase/awk/Extio;[CI)I"); - (*env)->DeleteLocalRef (env, class); - - if (handle == NULL) - { - (*env)->ExceptionClear (env); - return -1; - } - awk = (ase_awk_t*)(*env)->GetLongField (env, obj, handle); - - if (mid == NULL) - { - if (is_debug(awk)) (*env)->ExceptionDescribe (env); - (*env)->ExceptionClear (env); - return -1; - } - - array = (*env)->NewCharArray (env, size); - if (array == NULL) - { - if (is_debug(awk)) (*env)->ExceptionDescribe (env); - (*env)->ExceptionClear (env); - return -1; - } - - ret = (*env)->CallIntMethod (env, obj, mid, extio->handle, array, size); - if ((*env)->ExceptionOccurred (env)) - { - if (is_debug(awk)) (*env)->ExceptionDescribe (env); - (*env)->ExceptionClear (env); - ret = -1; - } - - if (ret > 0) - { - tmp = (*env)->GetCharArrayElements (env, array, 0); - for (i = 0; i < ret; i++) buf[i] = (ase_char_t)tmp[i]; - (*env)->ReleaseCharArrayElements (env, array, tmp, 0); - } - - (*env)->DeleteLocalRef (env, array); - return ret; -} - -static ase_ssize_t __java_write_extio ( - JNIEnv* env, jobject obj, char* meth, - ase_awk_extio_t* extio, ase_char_t* data, ase_size_t size) -{ - jclass class; - jfieldID handle; - jmethodID mid; - jcharArray array; - jchar* tmp; - jint ret; - ase_size_t i; - ase_awk_t* awk; - - class = (*env)->GetObjectClass(env, obj); - handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); - mid = (*env)->GetMethodID (env, class, meth, "(Lase/awk/Extio;[CI)I"); - (*env)->DeleteLocalRef (env, class); - - if (handle == NULL) - { - (*env)->ExceptionClear (env); - return -1; - } - awk = (ase_awk_t*)(*env)->GetLongField (env, obj, handle); - if (mid == NULL) - { - if (is_debug(awk)) (*env)->ExceptionDescribe (env); - (*env)->ExceptionClear (env); - return -1; - } - - array = (*env)->NewCharArray (env, size); - if (array == NULL) - { - if (is_debug(awk)) (*env)->ExceptionDescribe (env); - (*env)->ExceptionClear (env); - return -1; - } - - tmp = (*env)->GetCharArrayElements (env, array, 0); - for (i = 0; i < size; i++) tmp[i] = (jchar)data[i]; - (*env)->ReleaseCharArrayElements (env, array, tmp, 0); - - ret = (*env)->CallIntMethod (env, obj, mid, extio->handle, array, size); - if ((*env)->ExceptionOccurred (env)) - { - if (is_debug(awk)) (*env)->ExceptionDescribe (env); - (*env)->ExceptionClear (env); - ret = -1; - } - - (*env)->DeleteLocalRef (env, array); - return ret; -} - - -static ase_ssize_t __java_flush_extio ( - JNIEnv* env, jobject obj, char* meth, ase_awk_extio_t* extio) -{ - jclass class; - jfieldID handle; - jmethodID mid; - jint ret; - ase_awk_t* awk; - - class = (*env)->GetObjectClass(env, obj); - handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); - mid = (*env)->GetMethodID (env, class, meth, "(Lase/awk/Extio;)I"); - (*env)->DeleteLocalRef (env, class); - if (handle == NULL) - { - (*env)->ExceptionClear (env); - return -1; - } - awk = (ase_awk_t*)(*env)->GetLongField (env, obj, handle); - if (mid == NULL) - { - if (is_debug(awk)) (*env)->ExceptionDescribe (env); - (*env)->ExceptionClear (env); - return -1; - } - - ret = (*env)->CallIntMethod (env, obj, mid, extio->handle); - if ((*env)->ExceptionOccurred (env)) - { - if (is_debug(awk)) (*env)->ExceptionDescribe (env); - (*env)->ExceptionClear (env); - ret = -1; - } - - return ret; -} - -static ase_ssize_t __java_next_extio ( - JNIEnv* env, jobject obj, char* meth, ase_awk_extio_t* extio) -{ - jclass class; - jfieldID handle; - jmethodID mid; - jint ret; - ase_awk_t* awk; - - class = (*env)->GetObjectClass(env, obj); - handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); - mid = (*env)->GetMethodID (env, class, meth, "(Lase/awk/Extio;)I"); - (*env)->DeleteLocalRef (env, class); - if (handle == NULL) - { - (*env)->ExceptionClear (env); - return -1; - } - awk = (ase_awk_t*)(*env)->GetLongField (env, obj, handle); - if (mid == NULL) - { - (*env)->ExceptionClear (env); - return -1; - } - - ret = (*env)->CallIntMethod (env, obj, mid, extio->handle); - if ((*env)->ExceptionOccurred (env)) - { - if (is_debug(awk)) (*env)->ExceptionDescribe (env); - (*env)->ExceptionClear (env); - ret = -1; - } - - return ret; -} - -static ase_ssize_t __read_source ( - int cmd, void* arg, ase_char_t* data, ase_size_t count) -{ - srcio_data_t* srcio_data = (srcio_data_t*)arg; - - if (cmd == ASE_AWK_IO_OPEN) - { - return __java_open_source ( - srcio_data->env, srcio_data->obj, SOURCE_READ); - } - else if (cmd == ASE_AWK_IO_CLOSE) - { - return __java_close_source ( - srcio_data->env, srcio_data->obj, SOURCE_READ); - } - else if (cmd == ASE_AWK_IO_READ) - { - return __java_read_source ( - srcio_data->env, srcio_data->obj, data, count); - } - - return -1; -} - -static ase_ssize_t __write_source ( - int cmd, void* arg, ase_char_t* data, ase_size_t count) -{ - srcio_data_t* srcio_data = (srcio_data_t*)arg; - - if (cmd == ASE_AWK_IO_OPEN) - { - return __java_open_source ( - srcio_data->env, srcio_data->obj, SOURCE_WRITE); - } - else if (cmd == ASE_AWK_IO_CLOSE) - { - return __java_close_source ( - srcio_data->env, srcio_data->obj, SOURCE_WRITE); - } - else if (cmd == ASE_AWK_IO_WRITE) - { - return __java_write_source ( - srcio_data->env, srcio_data->obj, data, count); - } - - return -1; -} - -static ase_ssize_t __process_extio ( - int cmd, void* arg, ase_char_t* data, ase_size_t size) -{ - ase_awk_extio_t* epa = (ase_awk_extio_t*)arg; - runio_data_t* runio_data = (runio_data_t*)epa->custom_data; - - if (cmd == ASE_AWK_IO_OPEN) - { - return __java_open_extio ( - runio_data->env, runio_data->obj, - "openExtio", epa); - } - else if (cmd == ASE_AWK_IO_CLOSE) - { - return __java_close_extio ( - runio_data->env, runio_data->obj, - "closeExtio", epa); - } - else if (cmd == ASE_AWK_IO_READ) - { - return __java_read_extio ( - runio_data->env, runio_data->obj, - "readExtio", epa, data, size); - } - else if (cmd == ASE_AWK_IO_WRITE) - { - return __java_write_extio ( - runio_data->env, runio_data->obj, - "writeExtio", epa, data, size); - } - else if (cmd == ASE_AWK_IO_FLUSH) - { - return __java_flush_extio ( - runio_data->env, runio_data->obj, - "flushExtio", epa); - } - else if (cmd == ASE_AWK_IO_NEXT) - { - return __java_next_extio ( - runio_data->env, runio_data->obj, - "nextExtio", epa); - } - - return -1; -} - -static int __handle_bfn ( - ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl) -{ - jclass class; - jmethodID method; - jstring name; - const char* name_utf; - run_data_t* run_data; - JNIEnv* env; - jobject obj; - jint i, nargs; - jobjectArray args; - jobject arg, ret; - ase_awk_val_t* v; - ase_awk_t* awk; - - run_data = ase_awk_getruncustomdata (run); - nargs = ase_awk_getnargs (run); - awk = ase_awk_getrunawk (run); - - env = run_data->env; - obj = run_data->obj; - - if (fnl > 0 && ASE_SIZEOF(jchar) != ASE_SIZEOF(ase_char_t)) - { - ase_size_t i; - jchar* tmp = (jchar*) malloc (ASE_SIZEOF(jchar)*fnl); - if (tmp == NULL) - { - ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); - return -1; - } - - for (i = 0; i < fnl; i++) tmp[i] = (jchar)fnm[i]; - name = (*env)->NewString (env, tmp, fnl); - free (tmp); - } - else - { - name = (*env)->NewString (env, (jchar*)fnm, fnl); - } - - if (name == NULL) - { - if (is_debug(awk)) (*env)->ExceptionDescribe (env); - (*env)->ExceptionClear (env); - ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); - return -1; - } - name_utf = (*env)->GetStringUTFChars (env, name, JNI_FALSE); - if (name_utf == NULL) - { - (*env)->DeleteLocalRef (env, name); - ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); - return -1; - } - - class = (*env)->GetObjectClass(env, obj); - method = (*env)->GetMethodID ( - env, class, name_utf, - "(J[Ljava/lang/Object;)Ljava/lang/Object;"); - (*env)->DeleteLocalRef (env, class); - (*env)->ReleaseStringUTFChars (env, name, name_utf); - (*env)->DeleteLocalRef (env, name); - if (method == NULL) - { - /* if the method is not found, the exception is thrown. - * clear it to prevent it from being thrown */ - if (is_debug(awk)) (*env)->ExceptionDescribe (env); - (*env)->ExceptionClear (env); - ase_awk_setrunerrnum (run, ASE_AWK_EBFNUSER); - return -1; - } - - args = (*env)->NewObjectArray ( - env, nargs, run_data->object_class, NULL); - if (args == NULL) - { - if (is_debug(awk)) (*env)->ExceptionDescribe (env); - (*env)->ExceptionClear (env); - ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); - return -1; - } - - for (i = 0; i < nargs; i++) - { - v = ase_awk_getarg (run, i); - - arg = NULL; - - if (v->type == ASE_AWK_VAL_INT) - { - jlong jv; - - jv = ((ase_awk_val_int_t*)v)->val; - arg = (*env)->NewObject (env, - run_data->long_class, - run_data->long_init, jv); - } - else if (v->type == ASE_AWK_VAL_REAL) - { - jdouble jv; - - jv = ((ase_awk_val_real_t*)v)->val; - arg = (*env)->NewObject (env, - run_data->double_class, - run_data->double_init, jv); - } - else if (v->type == ASE_AWK_VAL_STR) - { - ase_size_t len = ((ase_awk_val_str_t*)v)->len; - - if (ASE_SIZEOF(jchar) != ASE_SIZEOF(ase_char_t)) - { - ase_size_t i; - - jchar* tmp = (jchar*) malloc (ASE_SIZEOF(jchar)*len); - if (tmp == NULL) - { - (*env)->DeleteLocalRef (env, args); - ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); - return -1; - } - - for (i = 0; i < len; i++) - tmp[i] = (jchar)((ase_awk_val_str_t*)v)->buf[i]; - - arg = (*env)->NewString (env, tmp, len); - - free (tmp); - } - else - { - arg = (*env)->NewString ( - env, (jchar*)((ase_awk_val_str_t*)v)->buf, len); - } - } - - if (v->type != ASE_AWK_VAL_NIL && arg == NULL) - { - if ((*env)->ExceptionOccurred (env)) - { - if (is_debug(awk)) - (*env)->ExceptionDescribe (env); - (*env)->ExceptionClear (env); - } - (*env)->DeleteLocalRef (env, args); - ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); - return -1; - } - - (*env)->SetObjectArrayElement (env, args, i, arg); - if (arg != NULL) (*env)->DeleteLocalRef (env, arg); - } - - ret = (*env)->CallObjectMethod (env, obj, method, (jlong)run, args); - if ((*env)->ExceptionOccurred (env)) - { - if (is_debug(ase_awk_getrunawk(run))) - (*env)->ExceptionDescribe (env); - - (*env)->ExceptionClear (env); - (*env)->DeleteLocalRef (env, args); - - ase_awk_setrunerrnum (run, ASE_AWK_EBFNIMPL); - return -1; - } - - (*env)->DeleteLocalRef (env, args); - - if (ret == NULL) - { - ase_awk_setretval (run, ase_awk_val_nil); - } - else if ((*env)->IsInstanceOf (env, ret, run_data->integer_class)) - { - jint jv = (*env)->CallIntMethod ( - env, ret, run_data->integer_value); - - v = ase_awk_makeintval (run, jv); - if (v == NULL) - { - (*env)->DeleteLocalRef (env, ret); - ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); - return -1; - } - - (*env)->DeleteLocalRef (env, ret); - ase_awk_setretval (run, v); - } - else if ((*env)->IsInstanceOf (env, ret, run_data->long_class)) - { - jlong jv = (*env)->CallLongMethod ( - env, ret, run_data->long_value); - - v = ase_awk_makeintval (run, jv); - if (v == NULL) - { - (*env)->DeleteLocalRef (env, ret); - ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); - return -1; - } - - (*env)->DeleteLocalRef (env, ret); - ase_awk_setretval (run, v); - } - else if ((*env)->IsInstanceOf (env, ret, run_data->short_class)) - { - jshort jv = (*env)->CallShortMethod ( - env, ret, run_data->short_value); - - v = ase_awk_makeintval (run, jv); - if (v == NULL) - { - (*env)->DeleteLocalRef (env, ret); - ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); - return -1; - } - - (*env)->DeleteLocalRef (env, ret); - ase_awk_setretval (run, v); - } - else if ((*env)->IsInstanceOf (env, ret, run_data->float_class)) - { - jfloat jv = (*env)->CallFloatMethod ( - env, ret, run_data->float_value); - v = ase_awk_makerealval (run, jv); - if (v == NULL) - { - (*env)->DeleteLocalRef (env, ret); - ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); - return -1; - } - - (*env)->DeleteLocalRef (env, ret); - ase_awk_setretval (run, v); - } - else if ((*env)->IsInstanceOf (env, ret, run_data->double_class)) - { - jdouble jv = (*env)->CallDoubleMethod ( - env, ret, run_data->double_value); - v = ase_awk_makerealval (run, jv); - if (v == NULL) - { - (*env)->DeleteLocalRef (env, ret); - ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); - return -1; - } - - (*env)->DeleteLocalRef (env, ret); - ase_awk_setretval (run, v); - } - else if ((*env)->IsInstanceOf (env, ret, run_data->string_class)) - { - jsize len; - const jchar* ptr; - - len = (*env)->GetStringLength (env, ret); - ptr = (*env)->GetStringChars (env, ret, JNI_FALSE); - if (ptr == NULL) - { - (*env)->DeleteLocalRef (env, ret); - ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); - return -1; - } - - if (len > 0 && ASE_SIZEOF(jchar) != ASE_SIZEOF(ase_char_t)) - { - ase_size_t i; - ase_char_t* tmp = (ase_char_t*) - malloc (ASE_SIZEOF(ase_char_t)*len); - if (tmp == ASE_NULL) - { - (*env)->ReleaseStringChars (env, ret, ptr); - (*env)->DeleteLocalRef (env, ret); - ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); - return -1; - } - - for (i = 0; i < len; i++) tmp[i] = (ase_char_t)ptr[i]; - v = ase_awk_makestrval (run, tmp, len); - free (tmp); - } - else - { - v = ase_awk_makestrval (run, (ase_char_t*)ptr, len); - } - - if (v == NULL) - { - (*env)->ReleaseStringChars (env, ret, ptr); - (*env)->DeleteLocalRef (env, ret); - ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); - return -1; - } - - (*env)->ReleaseStringChars (env, ret, ptr); - (*env)->DeleteLocalRef (env, ret); - ase_awk_setretval (run, v); - } - else - { - (*env)->DeleteLocalRef (env, ret); - ase_awk_setrunerrnum (run, ASE_AWK_EBFNUSER); - return -1; - } - - return 0; -} - -JNIEXPORT void JNICALL Java_ase_awk_Awk_addbfn ( - JNIEnv* env, jobject obj, jstring name, jint min_args, jint max_args) -{ - jclass class; - jfieldID handle; - jint n; - - ase_awk_t* awk; - const jchar* ptr; - jsize len; - - class = (*env)->GetObjectClass(env, obj); - handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); - (*env)->DeleteLocalRef (env, class); - if (handle == NULL) - { - /* internal error. no handle field - * NoSuchFieldError, ExceptionInitializerError, - * OutOfMemoryError might occur */ - return; - } - - awk = (ase_awk_t*) (*env)->GetLongField (env, obj, handle); - - len = (*env)->GetStringLength (env, name); - ptr = (*env)->GetStringChars (env, name, JNI_FALSE); - if (ptr == NULL) - { - (*env)->ExceptionClear (env); - - throw_exception ( - env, - ase_awk_geterrstr(ASE_NULL, ASE_AWK_ENOMEM), - ASE_AWK_ENOMEM, - 0); - return; - } - - if (len > 0 && ASE_SIZEOF(jchar) != ASE_SIZEOF(ase_char_t)) - { - ase_size_t i; - ase_char_t* tmp = (ase_char_t*) - malloc (ASE_SIZEOF(ase_char_t)*len); - if (tmp == ASE_NULL) - { - (*env)->ReleaseStringChars (env, name, ptr); - throw_exception ( - env, - ase_awk_geterrstr(ASE_NULL, ASE_AWK_ENOMEM), - ASE_AWK_ENOMEM, - 0); - return; - } - - for (i = 0; i < len; i++) tmp[i] = (ase_char_t)ptr[i]; - n = (ase_awk_addbfn (awk, tmp, len, 0, - min_args, max_args, ASE_NULL, __handle_bfn) == NULL)? -1: 0; - free (tmp); - } - else - { - n = (ase_awk_addbfn (awk, (ase_char_t*)ptr, len, 0, - min_args, max_args, ASE_NULL, __handle_bfn) == NULL)? -1: 0; - } - - - (*env)->ReleaseStringChars (env, name, ptr); - - if (n == -1) - { - throw_exception ( - env, - ase_awk_geterrmsg(awk), - ase_awk_geterrnum(awk), - ase_awk_geterrlin(awk)); - } -} - -JNIEXPORT void JNICALL Java_ase_awk_Awk_delbfn ( - JNIEnv* env, jobject obj, jstring name) -{ - jclass class; - jfieldID handle; - jint n; - - ase_awk_t* awk; - const jchar* ptr; - jsize len; - - class = (*env)->GetObjectClass(env, obj); - handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); - (*env)->DeleteLocalRef (env, class); - if (handle == NULL) - { - /* internal error. no handle field - * NoSuchFieldError, ExceptionInitializerError, - * OutOfMemoryError might occur */ - return; - } - - awk = (ase_awk_t*) (*env)->GetLongField (env, obj, handle); - - len = (*env)->GetStringLength (env, name); - ptr = (*env)->GetStringChars (env, name, JNI_FALSE); - if (ptr == NULL) - { - (*env)->ExceptionClear (env); - throw_exception ( - env, - ase_awk_geterrstr(ASE_NULL, ASE_AWK_ENOMEM), - ASE_AWK_ENOMEM, - 0); - return; - } - - if (len > 0 && ASE_SIZEOF(jchar) != ASE_SIZEOF(ase_char_t)) - { - ase_size_t i; - ase_char_t* tmp = (ase_char_t*) - malloc (ASE_SIZEOF(ase_char_t)*len); - if (tmp == ASE_NULL) - { - (*env)->ReleaseStringChars (env, name, ptr); - throw_exception ( - env, - ase_awk_geterrstr(ASE_NULL, ASE_AWK_ENOMEM), - ASE_AWK_ENOMEM, - 0); - return; - } - - for (i = 0; i < len; i++) tmp[i] = (ase_char_t)ptr[i]; - n = ase_awk_delbfn (awk, tmp, len); - free (tmp); - } - else - { - n = ase_awk_delbfn (awk, (ase_char_t*)ptr, len); - } - - (*env)->ReleaseStringChars (env, name, ptr); - - if (n == -1) - { - throw_exception ( - env, - ase_awk_geterrmsg(awk), - ase_awk_geterrnum(awk), - ase_awk_geterrlin(awk)); - } -} - -JNIEXPORT jint JNICALL Java_ase_awk_Awk_getmaxdepth ( - JNIEnv* env, jobject obj, jint id) -{ - jclass class; - jfieldID handle; - ase_awk_t* awk; - - class = (*env)->GetObjectClass(env, obj); - handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); - (*env)->DeleteLocalRef (env, class); - if (handle == NULL) return 0; /* should never happen */ - - awk = (ase_awk_t*) (*env)->GetLongField (env, obj, handle); - return (jint)ase_awk_getmaxdepth (awk, id); -} - -JNIEXPORT void JNICALL Java_ase_awk_Awk_setmaxdepth ( - JNIEnv* env, jobject obj, jint ids, jint depth) -{ - jclass class; - jfieldID handle; - ase_awk_t* awk; - - class = (*env)->GetObjectClass(env, obj); - handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); - (*env)->DeleteLocalRef (env, class); - if (handle == NULL) - { - /* internal error. no handle field - * NoSuchFieldError, ExceptionInitializerError, - * OutOfMemoryError might occur */ - return; - } - - awk = (ase_awk_t*) (*env)->GetLongField (env, obj, handle); - ase_awk_setmaxdepth (awk, ids, depth); -} - -JNIEXPORT jint JNICALL Java_ase_awk_Awk_getoption ( - JNIEnv* env, jobject obj) -{ - jclass class; - jfieldID handle; - ase_awk_t* awk; - - class = (*env)->GetObjectClass(env, obj); - handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); - (*env)->DeleteLocalRef (env, class); - if (handle == NULL) - { - /* internal error. no handle field - * NoSuchFieldError, ExceptionInitializerError, - * OutOfMemoryError might occur */ - return 0; - } - - awk = (ase_awk_t*) (*env)->GetLongField (env, obj, handle); - return ase_awk_getoption (awk); -} - -JNIEXPORT void JNICALL Java_ase_awk_Awk_setoption ( - JNIEnv* env, jobject obj, jint options) -{ - jclass class; - jfieldID handle; - ase_awk_t* awk; - - class = (*env)->GetObjectClass(env, obj); - handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); - (*env)->DeleteLocalRef (env, class); - if (handle == NULL) - { - /* internal error. no handle field - * NoSuchFieldError, ExceptionInitializerError, - * OutOfMemoryError might occur */ - return; - } - - awk = (ase_awk_t*) (*env)->GetLongField (env, obj, handle); - ase_awk_setoption (awk, (int)options); -} - -JNIEXPORT jboolean JNICALL Java_ase_awk_Awk_getdebug ( - JNIEnv* env, jobject obj) -{ - jclass class; - jfieldID handle; - ase_awk_t* awk; - - class = (*env)->GetObjectClass(env, obj); - handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); - (*env)->DeleteLocalRef (env, class); - if (handle == NULL) - { - /* internal error. no handle field - * NoSuchFieldError, ExceptionInitializerError, - * OutOfMemoryError might occur */ - return JNI_FALSE; - } - - awk = (ase_awk_t*) (*env)->GetLongField (env, obj, handle); - return ((awk_data_t*)ase_awk_getcustomdata(awk))->debug? JNI_TRUE: JNI_FALSE; -} - -JNIEXPORT void JNICALL Java_ase_awk_Awk_setdebug ( - JNIEnv* env, jobject obj, jboolean debug) -{ - jclass class; - jfieldID handle; - ase_awk_t* awk; - - class = (*env)->GetObjectClass(env, obj); - handle = (*env)->GetFieldID (env, class, FIELD_HANDLE, "J"); - (*env)->DeleteLocalRef (env, class); - if (handle == NULL) - { - /* internal error. no handle field - * NoSuchFieldError, ExceptionInitializerError, - * OutOfMemoryError might occur */ - return; - } - - awk = (ase_awk_t*) (*env)->GetLongField (env, obj, handle); - ((awk_data_t*)ase_awk_getcustomdata(awk))->debug = debug; -} - -JNIEXPORT void JNICALL Java_ase_awk_Awk_setfilename ( - JNIEnv* env, jobject obj, jlong runid, jstring name) -{ - ase_awk_run_t* run = (ase_awk_run_t*)runid; - const jchar* ptr; - jsize len; - jint n; - - len = (*env)->GetStringLength (env, name); - ptr = (*env)->GetStringChars (env, name, JNI_FALSE); - if (ptr == NULL) - { - (*env)->ExceptionClear (env); - throw_exception ( - env, - ase_awk_geterrstr(ASE_NULL, ASE_AWK_ENOMEM), - ASE_AWK_ENOMEM, - 0); - return; - } - - if (len > 0 && ASE_SIZEOF(jchar) != ASE_SIZEOF(ase_char_t)) - { - ase_size_t i; - ase_char_t* tmp = (ase_char_t*) - malloc (ASE_SIZEOF(ase_char_t)*len); - if (tmp == ASE_NULL) - { - (*env)->ReleaseStringChars (env, name, ptr); - - throw_exception ( - env, - ase_awk_geterrstr(ASE_NULL, ASE_AWK_ENOMEM), - ASE_AWK_ENOMEM, - 0); - return; - } - - for (i = 0; i < len; i++) tmp[i] = (ase_char_t)ptr[i]; - n = ase_awk_setfilename (run, tmp, len); - free (tmp); - } - else - { - n = ase_awk_setfilename (run, (ase_char_t*)ptr, len); - } - - (*env)->ReleaseStringChars (env, name, ptr); - - if (n == -1) - { - throw_exception ( - env, - ase_awk_getrunerrmsg(run), - ase_awk_getrunerrnum(run), - ase_awk_getrunerrlin(run)); - } -} - -JNIEXPORT void JNICALL Java_ase_awk_Awk_setofilename ( - JNIEnv* env, jobject obj, jlong runid, jstring name) -{ - ase_awk_run_t* run = (ase_awk_run_t*)runid; - const jchar* ptr; - jsize len; - jint n; - - len = (*env)->GetStringLength (env, name); - ptr = (*env)->GetStringChars (env, name, JNI_FALSE); - if (ptr == NULL) - { - (*env)->ExceptionClear (env); - throw_exception ( - env, - ase_awk_geterrstr(ASE_NULL, ASE_AWK_ENOMEM), - ASE_AWK_ENOMEM, - 0); - return; - } - - if (len > 0 && ASE_SIZEOF(jchar) != ASE_SIZEOF(ase_char_t)) - { - ase_size_t i; - ase_char_t* tmp = (ase_char_t*) - malloc (ASE_SIZEOF(ase_char_t)*len); - if (tmp == ASE_NULL) - { - (*env)->ReleaseStringChars (env, name, ptr); - - throw_exception ( - env, - ase_awk_geterrstr(ASE_NULL, ASE_AWK_ENOMEM), - ASE_AWK_ENOMEM, - 0); - return; - } - - for (i = 0; i < len; i++) tmp[i] = (ase_char_t)ptr[i]; - n = ase_awk_setofilename (run, tmp, len); - free (tmp); - } - else - { - n = ase_awk_setofilename (run, (ase_char_t*)ptr, len); - } - - (*env)->ReleaseStringChars (env, name, ptr); - - if (n == -1) - { - throw_exception ( - env, - ase_awk_getrunerrmsg(run), - ase_awk_getrunerrnum(run), - ase_awk_getrunerrlin(run)); - } -} - -JNIEXPORT jobject JNICALL Java_ase_awk_Awk_strtonum ( - JNIEnv* env, jobject obj, jlong runid, jstring str) -{ - const jchar* ptr; - jsize len; - jint n; - ase_long_t lv; - ase_real_t rv; - jobject ret; - run_data_t* run_data; - - len = (*env)->GetStringLength (env, str); - ptr = (*env)->GetStringChars (env, str, JNI_FALSE); - if (ptr == NULL) - { - (*env)->ExceptionClear (env); - throw_exception ( - env, - ase_awk_geterrstr(ASE_NULL, ASE_AWK_ENOMEM), - ASE_AWK_ENOMEM, - 0); - return NULL; - } - - if (len > 0 && ASE_SIZEOF(jchar) != ASE_SIZEOF(ase_char_t)) - { - ase_size_t i; - ase_char_t* tmp = (ase_char_t*) - malloc (ASE_SIZEOF(ase_char_t)*len); - if (tmp == ASE_NULL) - { - (*env)->ReleaseStringChars (env, str, ptr); - throw_exception ( - env, - ase_awk_geterrstr(ASE_NULL, ASE_AWK_ENOMEM), - ASE_AWK_ENOMEM, - 0); - return NULL; - } - - for (i = 0; i < len; i++) tmp[i] = (ase_char_t)ptr[i]; - n = ase_awk_strtonum ( - (ase_awk_run_t*)runid, tmp, len, &lv, &rv); - free (tmp); - } - else - { - n = ase_awk_strtonum ( - (ase_awk_run_t*)runid, - (ase_char_t*)ptr, len, &lv, &rv); - } - (*env)->ReleaseStringChars (env, str, ptr); - - run_data = ase_awk_getruncustomdata ((ase_awk_run_t*)runid); - if (n == 0) - { - ret = (*env)->NewObject (env, - run_data->long_class, - run_data->long_init, (jlong)lv); - } - else - { - ret = (*env)->NewObject (env, - run_data->double_class, - run_data->double_init, (jdouble)rv); - } - - return ret; -} - - -JNIEXPORT jstring JNICALL Java_ase_awk_Awk_valtostr ( - JNIEnv* env, jobject obj, jlong runid, jobject val) -{ - ase_awk_run_t* run = (ase_awk_run_t*)runid; - run_data_t* run_data; - jstring ret; - ase_awk_val_t* v; - ase_char_t* str; - ase_size_t len; - ase_awk_t* awk; - - awk = ase_awk_getrunawk (run); - - if (val == NULL) - { - ret = (*env)->NewString (env, NULL, 0); - - if (ret == NULL) - { - (*env)->ExceptionClear (env); - - throw_exception ( - env, - ase_awk_geterrstr(ASE_NULL, ASE_AWK_ENOMEM), - ASE_AWK_ENOMEM, - 0); - } - return ret; - } - - run_data = ase_awk_getruncustomdata (run); - - if ((*env)->IsInstanceOf (env, val, run_data->string_class)) - { - const jchar* ptr; - - len = (*env)->GetStringLength (env, val); - ptr = (*env)->GetStringChars (env, val, JNI_FALSE); - if (ptr == NULL) - { - (*env)->ExceptionClear (env); - - throw_exception ( - env, - ase_awk_geterrstr(ASE_NULL, ASE_AWK_ENOMEM), - ASE_AWK_ENOMEM, - 0); - - return NULL; - } - - ret = (*env)->NewString (env, ptr, len); - (*env)->ReleaseStringChars (env, ret, ptr); - return ret; - } - - if ((*env)->IsInstanceOf (env, val, run_data->integer_class)) - { - jint jv; - jv = (*env)->CallIntMethod ( - env, val, run_data->integer_value); - v = ase_awk_makeintval (run, jv); - } - else if ((*env)->IsInstanceOf (env, val, run_data->long_class)) - { - jlong jv = (*env)->CallLongMethod ( - env, val, run_data->long_value); - v = ase_awk_makeintval (run, jv); - } - else if ((*env)->IsInstanceOf (env, val, run_data->short_class)) - { - jshort jv = (*env)->CallShortMethod ( - env, val, run_data->short_value); - v = ase_awk_makeintval (run, jv); - } - else if ((*env)->IsInstanceOf (env, val, run_data->float_class)) - { - jfloat jv = (*env)->CallFloatMethod ( - env, val, run_data->float_value); - v = ase_awk_makerealval (run, jv); - } - else if ((*env)->IsInstanceOf (env, val, run_data->double_class)) - { - jdouble jv = (*env)->CallDoubleMethod ( - env, val, run_data->double_value); - v = ase_awk_makerealval (run, jv); - } - else - { - throw_exception ( - env, - ase_awk_geterrstr(ASE_NULL, ASE_AWK_EVALTYPE), - ASE_AWK_EVALTYPE, - 0); - return NULL; - } - - if (v == NULL) - { - throw_exception ( - env, - ase_awk_geterrstr(ASE_NULL, ASE_AWK_ENOMEM), - ASE_AWK_ENOMEM, - 0); - return NULL; - } - - ase_awk_refupval (run, v); - str = ase_awk_valtostr (run, v, ASE_AWK_VALTOSTR_CLEAR, NULL, &len); - ase_awk_refdownval (run, v); - - if (str == NULL) - { - - throw_exception ( - env, - ase_awk_geterrstr(ASE_NULL, ASE_AWK_ENOMEM), - ASE_AWK_ENOMEM, - 0); - return NULL; - } - - if (len > 0 && ASE_SIZEOF(jchar) != ASE_SIZEOF(ase_char_t)) - { - ase_size_t i; - jchar* tmp = (jchar*) malloc (ASE_SIZEOF(jchar)*len); - if (tmp == NULL) - { - ase_awk_free (awk, str); - throw_exception ( - env, - ase_awk_geterrstr(ASE_NULL, ASE_AWK_ENOMEM), - ASE_AWK_ENOMEM, - 0); - return NULL; - } - - for (i = 0; i < len; i++) tmp[i] = (jchar)str[i]; - ret = (*env)->NewString (env, tmp, len); - free (tmp); - } - else - { - ret = (*env)->NewString (env, (jchar*)str, len); - } - - ase_awk_free (awk, str); - if (ret == NULL) - { - (*env)->ExceptionClear (env); - - throw_exception ( - env, - ase_awk_geterrstr(ASE_NULL, ASE_AWK_ENOMEM), - ASE_AWK_ENOMEM, - 0); - } - - return ret; -} - diff --git a/ase/awk/jni.def b/ase/awk/jni.def deleted file mode 100644 index d15dd6b9..00000000 --- a/ase/awk/jni.def +++ /dev/null @@ -1,24 +0,0 @@ -LIBRARY "aseawk_jni.dll" - -EXPORTS - Java_ase_awk_Awk_open - Java_ase_awk_Awk_close - Java_ase_awk_Awk_parse - Java_ase_awk_Awk_run - - Java_ase_awk_Awk_getmaxdepth - Java_ase_awk_Awk_setmaxdepth - - Java_ase_awk_Awk_getoption - Java_ase_awk_Awk_setoption - - Java_ase_awk_Awk_getdebug - Java_ase_awk_Awk_setdebug - - Java_ase_awk_Awk_addbfn - Java_ase_awk_Awk_delbfn - Java_ase_awk_Awk_setfilename - Java_ase_awk_Awk_setofilename - Java_ase_awk_Awk_strtonum - Java_ase_awk_Awk_valtostr - diff --git a/ase/awk/jni.h b/ase/awk/jni.h deleted file mode 100644 index e4a8c3cf..00000000 --- a/ase/awk/jni.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * $Id: jni.h,v 1.1.1.1 2007/03/28 14:05:15 bacon Exp $ - * - * {License} - */ - -#ifndef _ASE_AWK_JNI_H_ -#define _ASE_AWK_JNI_H_ - -#if defined(__APPLE__) && defined(__MACH__) -#include -#else -#include -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -JNIEXPORT void JNICALL Java_ase_awk_Awk_open (JNIEnv* env, jobject obj); -JNIEXPORT void JNICALL Java_ase_awk_Awk_close (JNIEnv* env, jobject obj); -JNIEXPORT void JNICALL Java_ase_awk_Awk_parse (JNIEnv* env, jobject obj); -JNIEXPORT void JNICALL Java_ase_awk_Awk_run ( - JNIEnv* env, jobject obj, jstring mfn, jobjectArray args); - -JNIEXPORT void JNICALL Java_ase_awk_Awk_addbfn ( - JNIEnv* env, jobject obj, jstring name, jint min_args, jint max_args); -JNIEXPORT void JNICALL Java_ase_awk_Awk_delbfn ( - JNIEnv* env, jobject obj, jstring name); - -JNIEXPORT jint JNICALL Java_ase_awk_Awk_getmaxdepth ( - JNIEnv* env, jobject obj, jint id); -JNIEXPORT void JNICALL Java_ase_awk_Awk_setmaxdepth ( - JNIEnv* env, jobject obj, jint ids, jint depth); - -JNIEXPORT jint JNICALL Java_ase_awk_Awk_getoption ( - JNIEnv* env, jobject obj); -JNIEXPORT void JNICALL Java_ase_awk_Awk_setoption ( - JNIEnv* env, jobject obj, jint options); - -JNIEXPORT jboolean JNICALL Java_ase_awk_Awk_getdebug ( - JNIEnv* env, jobject obj); -JNIEXPORT void JNICALL Java_ase_awk_Awk_setdebug ( - JNIEnv* env, jobject obj, jboolean debug); - -JNIEXPORT void JNICALL Java_ase_awk_Awk_setfilename ( - JNIEnv* env, jobject obj, jlong runid, jstring name); -JNIEXPORT void JNICALL Java_ase_awk_Awk_setofilename ( - JNIEnv* env, jobject obj, jlong runid, jstring name); - -JNIEXPORT jobject JNICALL Java_ase_awk_Awk_strtonum ( - JNIEnv* env, jobject obj, jlong runid, jstring str); -JNIEXPORT jstring JNICALL Java_ase_awk_Awk_valtostr ( - JNIEnv* env, jobject obj, jlong runid, jobject val); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ase/awk/makefile.in b/ase/awk/makefile.in deleted file mode 100644 index 95d3ec85..00000000 --- a/ase/awk/makefile.in +++ /dev/null @@ -1,89 +0,0 @@ -# -# $Id: makefile.in,v 1.1.1.1 2007/03/28 14:05:15 bacon Exp $ -# - -NAME = aseawk - -CC = @CC@ -AR = ar -MAKE = @MAKE@ -RANLIB = @RANLIB@ -CFLAGS = @CFLAGS@ -I@abs_top_builddir@/.. -LDFLAGS = @LDFLAGS@ -LIBS = @LIBS@ -MODE = @BUILDMODE@ - -OUT_DIR = ../$(MODE)/lib -OUT_FILE = $(OUT_DIR)/lib$(NAME).a - -TMP_DIR = $(MODE) - -OBJ_FILES = \ - $(TMP_DIR)/awk.o \ - $(TMP_DIR)/err.o \ - $(TMP_DIR)/tree.o \ - $(TMP_DIR)/tab.o \ - $(TMP_DIR)/map.o \ - $(TMP_DIR)/parse.o \ - $(TMP_DIR)/run.o \ - $(TMP_DIR)/rec.o \ - $(TMP_DIR)/val.o \ - $(TMP_DIR)/func.o \ - $(TMP_DIR)/misc.o \ - $(TMP_DIR)/extio.o \ - $(TMP_DIR)/rex.o - -lib: $(OUT_FILE) - -$(OUT_FILE): $(OBJ_FILES) $(OUT_DIR) - $(AR) cr $(OUT_FILE) $(OBJ_FILES) - if [ "$(RANLIB)" = "ranlib" ]; then ranlib $(OUT_FILE); fi - -$(TMP_DIR)/awk.o: $(TMP_DIR) - $(CC) $(CFLAGS) -o $@ -c awk.c - -$(TMP_DIR)/err.o: $(TMP_DIR) - $(CC) $(CFLAGS) -o $@ -c err.c - -$(TMP_DIR)/tree.o: $(TMP_DIR) - $(CC) $(CFLAGS) -o $@ -c tree.c - -$(TMP_DIR)/tab.o: $(TMP_DIR) - $(CC) $(CFLAGS) -o $@ -c tab.c - -$(TMP_DIR)/map.o: $(TMP_DIR) - $(CC) $(CFLAGS) -o $@ -c map.c - -$(TMP_DIR)/parse.o: $(TMP_DIR) - $(CC) $(CFLAGS) -o $@ -c parse.c - -$(TMP_DIR)/run.o: $(TMP_DIR) - $(CC) $(CFLAGS) -o $@ -c run.c - -$(TMP_DIR)/rec.o: $(TMP_DIR) - $(CC) $(CFLAGS) -o $@ -c rec.c - -$(TMP_DIR)/val.o: $(TMP_DIR) - $(CC) $(CFLAGS) -o $@ -c val.c - -$(TMP_DIR)/func.o: $(TMP_DIR) - $(CC) $(CFLAGS) -o $@ -c func.c - -$(TMP_DIR)/misc.o: $(TMP_DIR) - $(CC) $(CFLAGS) -o $@ -c misc.c - -$(TMP_DIR)/extio.o: $(TMP_DIR) - $(CC) $(CFLAGS) -o $@ -c extio.c - -$(TMP_DIR)/rex.o: $(TMP_DIR) - $(CC) $(CFLAGS) -o $@ -c rex.c - -$(OUT_DIR): - mkdir -p $(OUT_DIR) - -$(TMP_DIR): - mkdir -p $(TMP_DIR) - -clean: - rm -rf $(OUT_FILE) $(OBJ_FILES) - diff --git a/ase/awk/makefile.lnx.gcc b/ase/awk/makefile.lnx.gcc deleted file mode 100644 index 467b6778..00000000 --- a/ase/awk/makefile.lnx.gcc +++ /dev/null @@ -1,47 +0,0 @@ -OUT = aseawk - -C_SRCS = awk.c err.c tree.c str.c tab.c map.c parse.c \ - run.c rec.c val.c func.c misc.c extio.c rex.c -JNI_SRCS = jni.c -JAVA_SRCS = Exception.java Extio.java Awk.java StdAwk.java - -C_OBJS = $(C_SRCS:.c=.o) -JNI_OBJS = $(JNI_SRCS:.c=.o) -JAVA_OBJS = $(JAVA_SRCS:.java=.class) - -JNI_INCPATH= \ - -I"$(JAVA_HOME)/include" \ - -I"$(JAVA_HOME)/include/linux" - -CC = gcc -AR = ar -LD = ld -RANLIB = ranlib -CFLAGS = -Wall -O2 -D_REENTRANT -D_THREAD_SAFE -fPIC -I../.. $(JNI_INCPATH) -LDFLAGS = -LIBS = - -JAVAC = javac -JAVACFLAGS = -classpath ../.. - -all: lib jni - -lib: $(C_OBJS) - $(AR) cr lib$(OUT).a $(C_OBJS) - -jni: lib $(JNI_OBJS) $(JAVA_OBJS) - $(CC) -shared -o $(OUT)_jni.so $(JNI_OBJS) -lm -L. -l$(OUT) - -#$(CC) -fPIC -shared -static-libgcc -o $(OUT)_jni.so -L. -laseawk -lm libaseawk.a jni.o -#$(LD) -fPIC -shared -soname lib$(OUT).so -o $(OUT)_jni.so -L . -l aseawk jni.o - -clean: - rm -rf $(C_OBJS) $(JNI_OBJS) $(JAVA_OBJS) lib$(OUT).a lib$(OUT).so *.o - -.SUFFIXES: .c .o .java .class -.c.o: - $(CC) $(CFLAGS) -c $< - -.java.class: - $(JAVAC) $(JAVACFLAGS) $< - diff --git a/ase/awk/makefile.mac.gcc b/ase/awk/makefile.mac.gcc deleted file mode 100644 index 0c6605b3..00000000 --- a/ase/awk/makefile.mac.gcc +++ /dev/null @@ -1,41 +0,0 @@ -OUT = aseawk - -C_SRCS = awk.c err.c tree.c str.c tab.c map.c parse.c \ - run.c rec.c val.c func.c misc.c extio.c rex.c -JNI_SRCS = jni.c -JAVA_SRCS = Exception.java Extio.java Awk.java StdAwk.java - -C_OBJS = $(C_SRCS:.c=.o) -JNI_OBJS = $(JNI_SRCS:.c=.o) -JAVA_OBJS = $(JAVA_SRCS:.java=.class) - -CC = gcc -AR = ar -LD = ld -RANLIB = ranlib -CFLAGS = -Wall -O2 -D_REENTRANT -D_THREAD_SAFE -I../.. -LDFLAGS = -LIBS = - -JAVAC = javac -JAVACFLAGS = -classpath ../.. - -all: lib jni - -lib: $(C_OBJS) - $(AR) cr lib$(OUT).a $(C_OBJS) - ranlib lib$(OUT).a - -jni: lib $(JNI_OBJS) $(JAVA_OBJS) - $(CC) -bundle -o $(OUT)_jni.so $(JNI_OBJS) -lm -L. -l$(OUT) - -clean: - rm -rf $(C_OBJS) $(JNI_OBJS) $(JAVA_OBJS) lib$(OUT).a lib$(OUT).so *.o - -.SUFFIXES: .c .o .java .class -.c.o: - $(CC) $(CFLAGS) -c $< - -.java.class: - $(JAVAC) $(JAVACFLAGS) $< - diff --git a/ase/awk/makefile.msw.bcc b/ase/awk/makefile.msw.bcc deleted file mode 100644 index d6b74775..00000000 --- a/ase/awk/makefile.msw.bcc +++ /dev/null @@ -1,54 +0,0 @@ -OUT = aseawk - -C_SRCS = awk.c err.c tree.c tab.c map.c parse.c \ - run.c rec.c val.c func.c misc.c extio.c rex.c -JNI_SRCS = jni.c -JAVA_SRCS = Exception.java Extio.java Awk.java StdAwk.java - -C_OBJS = $(C_SRCS:.c=.obj) -JNI_OBJS = $(JNI_SRCS:.c=.obj) -JAVA_OBJS = $(JAVA_SRCS:.java=.class) - -JNI_INCPATH = \ - -I"$(JAVA_HOME)/include" \ - -I"$(JAVA_HOME)/include/win32" - -CC = bcc32 -LD = ilink32 -AR = tlib -JAVAC = javac - -CFLAGS_COMMON = -O2 -WM -WU -RT- -w -q -I../.. $(JNI_INCPATH) -CFLAGS_RELEASE = $(CFLAGS_COMMON) -DNDEBUG -CFLAGS_DEBUG = $(CFLAGS_COMMON) -D_DEBUG #-DDEBUG_REX -CFLAGS = $(CFLAGS_DEBUG) -#CFLAGS = $(CFLAGS_RELEASE) -JAVACFLAGS = -classpath ../.. - -LDFLAGS = -Tpd -ap -Gn -c -q -STARTUP = c0d32w.obj -LIBS = import32.lib cw32mt.lib - -JNI_LDFLAGS = $(LDFLAGS) -L..\cmn -L..\utl -JNI_LIBS = $(LIBS) $(OUT).lib asecmn.lib aseutl.lib - -all: lib - -lib: $(C_OBJS) - $(AR) $(OUT).lib @&&! -+-$(**: = &^ -+-) -! - -jni: lib $(JNI_OBJS) $(JAVA_OBJS) - $(LD) $(JNI_LDFLAGS) $(STARTUP) $(JNI_OBJS),$(OUT)_jni.dll,,$(JNI_LIBS),jni.def, - -clean: - -del $(OBJS) $(OUT).lib $(OUT)_jni.dll *.obj *.class - -.SUFFIXES: .c .obj .java .class -.c.obj: - $(CC) $(CFLAGS) -c $< - -.java.class: - $(JAVAC) $(JAVACFLAGS) $< diff --git a/ase/awk/makefile.msw.cl b/ase/awk/makefile.msw.cl deleted file mode 100644 index 00d5c35a..00000000 --- a/ase/awk/makefile.msw.cl +++ /dev/null @@ -1,45 +0,0 @@ -OUT = aseawk - -C_SRCS = awk.c err.c tree.c tab.c map.c parse.c \ - run.c rec.c val.c func.c misc.c extio.c rex.c -JNI_SRCS = jni.c -JAVA_SRCS = Exception.java Extio.java Awk.java StdAwk.java - -C_OBJS = $(C_SRCS:.c=.obj) -JNI_OBJS = $(JNI_SRCS:.c=.obj) -JAVA_OBJS = $(JAVA_SRCS:.java=.class) - -JNI_INC = \ - /I"$(JAVA_HOME)/include" \ - /I"$(JAVA_HOME)/include\win32" - -CC = cl -LD = link -JAVAC = javac - -#CFLAGS = /nologo /O2 /MT /W3 /GR- /Za -I../.. $(JNI_INC) -CFLAGS = /nologo /O2 /MT /W3 /GR- -I../.. $(JNI_INC) -JAVACFLAGS = -classpath ../.. -Xlint:unchecked - -all: lib - -lib: $(C_OBJS) - $(LD) /lib @<< -/nologo /out:$(OUT).lib $(C_OBJS) -<< - -jni: lib $(JNI_OBJS) $(JAVA_OBJS) - $(LD) /dll /def:jni.def /subsystem:windows /version:0.1 /release @<< -/nologo /out:$(OUT)_jni.dll $(JNI_OBJS) /libpath:../cmn /libpath:../utl /implib:tmp.lib user32.lib $(OUT).lib asecmn.lib aseutl.lib -<< - del tmp.lib tmp.exp - -clean: - del $(OBJS) $(OUT).lib $(OUT)_jni.dll *.obj *.class - -.SUFFIXES: .c .obj .java .class -.c.obj: - $(CC) $(CFLAGS) /c $< - -.java.class: - $(JAVAC) $(JAVACFLAGS) $< diff --git a/ase/awk/map.c b/ase/awk/map.c deleted file mode 100644 index 2c52f8c4..00000000 --- a/ase/awk/map.c +++ /dev/null @@ -1,285 +0,0 @@ -/* - * $Id: map.c,v 1.1.1.1 2007/03/28 14:05:16 bacon Exp $ - * - * {License} - */ - -#include - -/* TODO: improve the entire map routines. - support automatic bucket resizing and remaping, etc. */ - -static ase_size_t hash (const ase_char_t* key, ase_size_t key_len); - -#define FREE_PAIR(map,pair) \ - do { \ - ASE_AWK_FREE ((map)->awk, (ase_char_t*)(pair)->key); \ - if ((map)->freeval != ASE_NULL) \ - (map)->freeval ((map)->owner, (pair)->val); \ - ASE_AWK_FREE ((map)->awk, pair); \ - } while (0) - -ase_awk_map_t* ase_awk_map_open ( - ase_awk_map_t* map, void* owner, ase_size_t capa, - void(*freeval)(void*,void*), ase_awk_t* awk) -{ - ASE_ASSERTX (capa > 0, "the initial capacity should be greater than 0"); - - if (map == ASE_NULL) - { - map = (ase_awk_map_t*) ASE_AWK_MALLOC ( - awk, ASE_SIZEOF(ase_awk_map_t)); - if (map == ASE_NULL) return ASE_NULL; - map->__dynamic = ase_true; - } - else map->__dynamic = ase_false; - - map->awk = awk; - map->buck = (ase_awk_pair_t**) - ASE_AWK_MALLOC (awk, ASE_SIZEOF(ase_awk_pair_t*) * capa); - if (map->buck == ASE_NULL) - { - if (map->__dynamic) ASE_AWK_FREE (awk, map); - return ASE_NULL; - } - - map->owner = owner; - map->capa = capa; - map->size = 0; - map->freeval = freeval; - while (capa > 0) map->buck[--capa] = ASE_NULL; - - return map; -} - -void ase_awk_map_close (ase_awk_map_t* map) -{ - ase_awk_map_clear (map); - ASE_AWK_FREE (map->awk, map->buck); - if (map->__dynamic) ASE_AWK_FREE (map->awk, map); -} - -void ase_awk_map_clear (ase_awk_map_t* map) -{ - ase_size_t i; - ase_awk_pair_t* pair, * next; - - for (i = 0; i < map->capa; i++) - { - pair = map->buck[i]; - - while (pair != ASE_NULL) - { - next = pair->next; - FREE_PAIR (map, pair); - map->size--; - pair = next; - } - - map->buck[i] = ASE_NULL; - } -} - -ase_size_t ase_awk_map_getsize (ase_awk_map_t* map) -{ - return map->size; -} - -ase_awk_pair_t* ase_awk_map_get ( - ase_awk_map_t* map, const ase_char_t* key, ase_size_t key_len) -{ - ase_awk_pair_t* pair; - ase_size_t hc; - - hc = hash(key,key_len) % map->capa; - pair = map->buck[hc]; - - while (pair != ASE_NULL) - { - - if (ase_strxncmp ( - pair->key, pair->key_len, - key, key_len) == 0) return pair; - - pair = pair->next; - } - - return ASE_NULL; -} - -ase_awk_pair_t* ase_awk_map_put ( - ase_awk_map_t* map, ase_char_t* key, ase_size_t key_len, void* val) -{ - int n; - ase_awk_pair_t* px; - - n = ase_awk_map_putx (map, key, key_len, val, &px); - if (n < 0) return ASE_NULL; - return px; -} - -int ase_awk_map_putx ( - ase_awk_map_t* map, ase_char_t* key, ase_size_t key_len, - void* val, ase_awk_pair_t** px) -{ - ase_awk_pair_t* pair; - ase_size_t hc; - - hc = hash(key,key_len) % map->capa; - pair = map->buck[hc]; - - while (pair != ASE_NULL) - { - if (ase_strxncmp ( - pair->key, pair->key_len, key, key_len) == 0) - { - if (px != ASE_NULL) - *px = ase_awk_map_setpair (map, pair, val); - else - ase_awk_map_setpair (map, pair, val); - - return 0; /* value changed for the existing key */ - } - pair = pair->next; - } - - pair = (ase_awk_pair_t*) ASE_AWK_MALLOC ( - map->awk, ASE_SIZEOF(ase_awk_pair_t)); - if (pair == ASE_NULL) return -1; /* error */ - - /*pair->key = key;*/ - - /* duplicate the key if it is new */ - pair->key = ase_strxdup (key, key_len, &map->awk->prmfns.mmgr); - if (pair->key == ASE_NULL) - { - ASE_AWK_FREE (map->awk, pair); - return -1; /* error */ - } - - pair->key_len = key_len; - pair->val = val; - pair->next = map->buck[hc]; - map->buck[hc] = pair; - map->size++; - - if (px != ASE_NULL) *px = pair; - return 1; /* new key added */ -} - -ase_awk_pair_t* ase_awk_map_set ( - ase_awk_map_t* map, ase_char_t* key, ase_size_t key_len, void* val) -{ - ase_awk_pair_t* pair; - ase_size_t hc; - - hc = hash(key,key_len) % map->capa; - pair = map->buck[hc]; - - while (pair != ASE_NULL) - { - if (ase_strxncmp ( - pair->key, pair->key_len, key, key_len) == 0) - { - return ase_awk_map_setpair (map, pair, val); - } - pair = pair->next; - } - - return ASE_NULL; -} - -ase_awk_pair_t* ase_awk_map_getpair ( - ase_awk_map_t* map, const ase_char_t* key, ase_size_t key_len, void** val) -{ - ase_awk_pair_t* pair; - - pair = ase_awk_map_get (map, key, key_len); - if (pair == ASE_NULL) return ASE_NULL; - *val = pair->val; - - return pair; -} - -ase_awk_pair_t* ase_awk_map_setpair ( - ase_awk_map_t* map, ase_awk_pair_t* pair, void* val) -{ - /* use this function with care */ - if (pair->val != val) - { - if (map->freeval != ASE_NULL) - { - map->freeval (map->owner, pair->val); - } - pair->val = val; - } - - return pair; -} - -int ase_awk_map_remove (ase_awk_map_t* map, ase_char_t* key, ase_size_t key_len) -{ - ase_awk_pair_t* pair, * prev; - ase_size_t hc; - - hc = hash(key,key_len) % map->capa; - pair = map->buck[hc]; - prev = ASE_NULL; - - while (pair != ASE_NULL) - { - if (ase_strxncmp ( - pair->key, pair->key_len, key, key_len) == 0) - { - if (prev == ASE_NULL) - map->buck[hc] = pair->next; - else prev->next = pair->next; - - FREE_PAIR (map, pair); - map->size--; - - return 0; - } - - prev = pair; - pair = pair->next; - } - - return -1; -} - -int ase_awk_map_walk (ase_awk_map_t* map, - int (*walker) (ase_awk_pair_t*,void*), void* arg) -{ - ase_size_t i; - ase_awk_pair_t* pair, * next; - - for (i = 0; i < map->capa; i++) - { - pair = map->buck[i]; - - while (pair != ASE_NULL) - { - next = pair->next; - if (walker(pair,arg) == -1) return -1; - pair = next; - } - } - - return 0; -} - -static ase_size_t hash (const ase_char_t* key, ase_size_t key_len) -{ - ase_size_t n = 0, i; - const ase_char_t* end = key + key_len; - - while (key < end) - { - ase_byte_t* bp = (ase_byte_t*)key; - for (i = 0; i < ASE_SIZEOF(*key); i++) n = n * 31 + *bp++; - key++; - } - - return n; -} diff --git a/ase/awk/map.h b/ase/awk/map.h deleted file mode 100644 index 77775ff1..00000000 --- a/ase/awk/map.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * $Id: map.h,v 1.1.1.1 2007/03/28 14:05:16 bacon Exp $ - * - * {License} - */ - -#ifndef _ASE_AWK_MAP_H_ -#define _ASE_AWK_MAP_H_ - -#ifndef _ASE_AWK_AWK_H_ -#error Include first -#endif - -/*typedef struct ase_awk_map_t ase_awk_map_t;*/ -typedef struct ase_awk_pair_t ase_awk_pair_t; - -struct ase_awk_pair_t -{ - ase_char_t* key; - ase_size_t key_len; - void* val; - ase_awk_pair_t* next; -}; - -struct ase_awk_map_t -{ - void* owner; - ase_size_t size; - ase_size_t capa; - ase_awk_pair_t** buck; - void (*freeval) (void*,void*); - ase_awk_t* awk; - ase_bool_t __dynamic; -}; - -#ifdef __cplusplus -extern "C" { -#endif - -ase_awk_map_t* ase_awk_map_open ( - ase_awk_map_t* map, void* owner, ase_size_t capa, - void(*freeval)(void*,void*), ase_awk_t* awk); - -void ase_awk_map_close (ase_awk_map_t* map); - -void ase_awk_map_clear (ase_awk_map_t* map); - -ase_size_t ase_awk_map_getsize (ase_awk_map_t* map); - -ase_awk_pair_t* ase_awk_map_get ( - ase_awk_map_t* map, const ase_char_t* key, ase_size_t key_len); - -ase_awk_pair_t* ase_awk_map_put ( - ase_awk_map_t* map, ase_char_t* key, ase_size_t key_len, void* val); - -int ase_awk_map_putx ( - ase_awk_map_t* map, ase_char_t* key, ase_size_t key_len, - void* val, ase_awk_pair_t** px); - -ase_awk_pair_t* ase_awk_map_set ( - ase_awk_map_t* map, ase_char_t* key, ase_size_t key_len, void* val); - -ase_awk_pair_t* ase_awk_map_getpair ( - ase_awk_map_t* map, const ase_char_t* key, ase_size_t key_len, void** val); - -ase_awk_pair_t* ase_awk_map_setpair ( - ase_awk_map_t* map, ase_awk_pair_t* pair, void* val); - -int ase_awk_map_remove (ase_awk_map_t* map, ase_char_t* key, ase_size_t key_len); - -int ase_awk_map_walk (ase_awk_map_t* map, - int (*walker)(ase_awk_pair_t*,void*), void* arg); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ase/awk/misc.c b/ase/awk/misc.c deleted file mode 100644 index 7a30459b..00000000 --- a/ase/awk/misc.c +++ /dev/null @@ -1,905 +0,0 @@ -/* - * $Id: misc.c,v 1.1.1.1 2007/03/28 14:05:16 bacon Exp $ - * - * {License} - */ - -#include - -void* ase_awk_malloc (ase_awk_t* awk, ase_size_t size) -{ - return ASE_AWK_MALLOC (awk, size); -} - -void ase_awk_free (ase_awk_t* awk, void* ptr) -{ - ASE_AWK_FREE (awk, ptr); -} - -ase_long_t ase_awk_strxtolong ( - ase_awk_t* awk, const ase_char_t* str, ase_size_t len, - int base, const ase_char_t** endptr) -{ - ase_long_t n = 0; - const ase_char_t* p; - const ase_char_t* end; - ase_size_t rem; - int digit, negative = 0; - - ASE_ASSERT (base < 37); - - p = str; - end = str + len; - - /* strip off leading spaces */ - /*while (ASE_AWK_ISSPACE(awk,*p)) p++;*/ - - /* check for a sign */ - /*while (*p != ASE_T('\0')) */ - while (p < end) - { - if (*p == ASE_T('-')) - { - negative = ~negative; - p++; - } - else if (*p == ASE_T('+')) p++; - else break; - } - - /* check for a binary/octal/hexadecimal notation */ - rem = end - p; - if (base == 0) - { - if (rem >= 1 && *p == ASE_T('0')) - { - p++; - - if (rem == 1) base = 8; - else if (*p == ASE_T('x') || *p == ASE_T('X')) - { - p++; base = 16; - } - else if (*p == ASE_T('b') || *p == ASE_T('B')) - { - p++; base = 2; - } - else base = 8; - } - else base = 10; - } - else if (rem >= 2 && base == 16) - { - if (*p == ASE_T('0') && - (*(p+1) == ASE_T('x') || *(p+1) == ASE_T('X'))) p += 2; - } - else if (rem >= 2 && base == 2) - { - if (*p == ASE_T('0') && - (*(p+1) == ASE_T('b') || *(p+1) == ASE_T('B'))) p += 2; - } - - /* process the digits */ - /*while (*p != ASE_T('\0'))*/ - while (p < end) - { - if (*p >= ASE_T('0') && *p <= ASE_T('9')) - digit = *p - ASE_T('0'); - else if (*p >= ASE_T('A') && *p <= ASE_T('Z')) - digit = *p - ASE_T('A') + 10; - else if (*p >= ASE_T('a') && *p <= ASE_T('z')) - digit = *p - ASE_T('a') + 10; - else break; - - if (digit >= base) break; - n = n * base + digit; - - p++; - } - - if (endptr != ASE_NULL) *endptr = p; - return (negative)? -n: n; -} - - -/* - * ase_awk_strtoreal is almost a replica of strtod. - * - * strtod.c -- - * - * Source code for the "strtod" library procedure. - * - * Copyright (c) 1988-1993 The Regents of the University of California. - * Copyright (c) 1994 Sun Microsystems, Inc. - * - * Permission to use, copy, modify, and distribute this - * software and its documentation for any purpose and without - * fee is hereby granted, provided that the above copyright - * notice appear in all copies. The University of California - * makes no representations about the suitability of this - * software for any purpose. It is provided "as is" without - * express or implied warranty. - */ - -#define MAX_EXPONENT 511 - -ase_real_t ase_awk_strtoreal (ase_awk_t* awk, const ase_char_t* str) -{ - /* - * Table giving binary powers of 10. Entry is 10^2^i. - * Used to convert decimal exponents into floating-point numbers. - */ - static ase_real_t powers_of_10[] = - { - 10., 100., 1.0e4, 1.0e8, 1.0e16, - 1.0e32, 1.0e64, 1.0e128, 1.0e256 - }; - - ase_real_t fraction, dbl_exp, * d; - const ase_char_t* p; - ase_cint_t c; - int exp = 0; /* Esseonent read from "EX" field */ - - /* - * Esseonent that derives from the fractional part. Under normal - * circumstatnces, it is the negative of the number of digits in F. - * However, if I is very long, the last digits of I get dropped - * (otherwise a long I with a large negative exponent could cause an - * unnecessary overflow on I alone). In this case, frac_exp is - * incremented one for each dropped digit. - */ - - int frac_exp; - int mant_size; /* Number of digits in mantissa. */ - int dec_pt; /* Number of mantissa digits BEFORE decimal point */ - const ase_char_t *pexp; /* Temporarily holds location of exponent in string */ - int negative = 0, exp_negative = 0; - - p = str; - - /* strip off leading blanks */ - /*while (ASE_AWK_ISSPACE(awk,*p)) p++;*/ - - /* check for a sign */ - while (*p != ASE_T('\0')) - { - if (*p == ASE_T('-')) - { - negative = ~negative; - p++; - } - else if (*p == ASE_T('+')) p++; - else break; - } - - /* Count the number of digits in the mantissa (including the decimal - * point), and also locate the decimal point. */ - dec_pt = -1; - for (mant_size = 0; ; mant_size++) - { - c = *p; - if (!ASE_AWK_ISDIGIT (awk, c)) - { - if ((c != ASE_T('.')) || (dec_pt >= 0)) break; - dec_pt = mant_size; - } - p++; - } - - /* - * Now suck up the digits in the mantissa. Use two integers to - * collect 9 digits each (this is faster than using floating-point). - * If the mantissa has more than 18 digits, ignore the extras, since - * they can't affect the value anyway. - */ - pexp = p; - p -= mant_size; - if (dec_pt < 0) - { - dec_pt = mant_size; - } - else - { - mant_size--; /* One of the digits was the point */ - } - - if (mant_size > 18) - { - frac_exp = dec_pt - 18; - mant_size = 18; - } - else - { - frac_exp = dec_pt - mant_size; - } - - if (mant_size == 0) - { - fraction = 0.0; - /*p = str;*/ - p = pexp; - goto done; - } - else - { - int frac1, frac2; - frac1 = 0; - for ( ; mant_size > 9; mant_size--) - { - c = *p; - p++; - if (c == ASE_T('.')) - { - c = *p; - p++; - } - frac1 = 10 * frac1 + (c - ASE_T('0')); - } - frac2 = 0; - for (; mant_size > 0; mant_size--) { - c = *p; - p++; - if (c == ASE_T('.')) - { - c = *p; - p++; - } - frac2 = 10*frac2 + (c - ASE_T('0')); - } - fraction = (1.0e9 * frac1) + frac2; - } - - /* Skim off the exponent */ - p = pexp; - if ((*p == ASE_T('E')) || (*p == ASE_T('e'))) - { - p++; - if (*p == ASE_T('-')) - { - exp_negative = 1; - p++; - } - else - { - if (*p == ASE_T('+')) p++; - exp_negative = 0; - } - if (!ASE_AWK_ISDIGIT (awk, *p)) - { - /* p = pexp; */ - /* goto done; */ - goto no_exp; - } - while (ASE_AWK_ISDIGIT (awk, *p)) - { - exp = exp * 10 + (*p - ASE_T('0')); - p++; - } - } - -no_exp: - if (exp_negative) exp = frac_exp - exp; - else exp = frac_exp + exp; - - /* - * Generate a floating-point number that represents the exponent. - * Do this by processing the exponent one bit at a time to combine - * many powers of 2 of 10. Then combine the exponent with the - * fraction. - */ - if (exp < 0) - { - exp_negative = 1; - exp = -exp; - } - else exp_negative = 0; - - if (exp > MAX_EXPONENT) exp = MAX_EXPONENT; - - dbl_exp = 1.0; - - for (d = powers_of_10; exp != 0; exp >>= 1, d++) - { - if (exp & 01) dbl_exp *= *d; - } - - if (exp_negative) fraction /= dbl_exp; - else fraction *= dbl_exp; - -done: - return (negative)? -fraction: fraction; -} - -ase_real_t ase_awk_strxtoreal ( - ase_awk_t* awk, const ase_char_t* str, ase_size_t len, - const ase_char_t** endptr) -{ - /* - * Table giving binary powers of 10. Entry is 10^2^i. - * Used to convert decimal exponents into floating-point numbers. - */ - static ase_real_t powers_of_10[] = - { - 10., 100., 1.0e4, 1.0e8, 1.0e16, - 1.0e32, 1.0e64, 1.0e128, 1.0e256 - }; - - ase_real_t fraction, dbl_exp, * d; - const ase_char_t* p, * end; - ase_cint_t c; - int exp = 0; /* Esseonent read from "EX" field */ - - /* - * Esseonent that derives from the fractional part. Under normal - * circumstatnces, it is the negative of the number of digits in F. - * However, if I is very long, the last digits of I get dropped - * (otherwise a long I with a large negative exponent could cause an - * unnecessary overflow on I alone). In this case, frac_exp is - * incremented one for each dropped digit. - */ - - int frac_exp; - int mant_size; /* Number of digits in mantissa. */ - int dec_pt; /* Number of mantissa digits BEFORE decimal point */ - const ase_char_t *pexp; /* Temporarily holds location of exponent in string */ - int negative = 0, exp_negative = 0; - - p = str; - end = str + len; - - /* Strip off leading blanks and check for a sign */ - /*while (ASE_AWK_ISSPACE(awk,*p)) p++;*/ - - /*while (*p != ASE_T('\0')) */ - while (p < end) - { - if (*p == ASE_T('-')) - { - negative = ~negative; - p++; - } - else if (*p == ASE_T('+')) p++; - else break; - } - - /* Count the number of digits in the mantissa (including the decimal - * point), and also locate the decimal point. */ - dec_pt = -1; - /*for (mant_size = 0; ; mant_size++) */ - for (mant_size = 0; p < end; mant_size++) - { - c = *p; - if (!ASE_AWK_ISDIGIT (awk, c)) - { - if (c != ASE_T('.') || dec_pt >= 0) break; - dec_pt = mant_size; - } - p++; - } - - /* - * Now suck up the digits in the mantissa. Use two integers to - * collect 9 digits each (this is faster than using floating-point). - * If the mantissa has more than 18 digits, ignore the extras, since - * they can't affect the value anyway. - */ - pexp = p; - p -= mant_size; - if (dec_pt < 0) - { - dec_pt = mant_size; - } - else - { - mant_size--; /* One of the digits was the point */ - } - - if (mant_size > 18) /* TODO: is 18 correct for ase_real_t??? */ - { - frac_exp = dec_pt - 18; - mant_size = 18; - } - else - { - frac_exp = dec_pt - mant_size; - } - - if (mant_size == 0) - { - fraction = 0.0; - /*p = str;*/ - p = pexp; - goto done; - } - else - { - int frac1, frac2; - - frac1 = 0; - for ( ; mant_size > 9; mant_size--) - { - c = *p; - p++; - if (c == ASE_T('.')) - { - c = *p; - p++; - } - frac1 = 10 * frac1 + (c - ASE_T('0')); - } - - frac2 = 0; - for (; mant_size > 0; mant_size--) { - c = *p++; - if (c == ASE_T('.')) - { - c = *p; - p++; - } - frac2 = 10 * frac2 + (c - ASE_T('0')); - } - fraction = (1.0e9 * frac1) + frac2; - } - - /* Skim off the exponent */ - p = pexp; - if (p < end && (*p == ASE_T('E') || *p == ASE_T('e'))) - { - p++; - - if (p < end) - { - if (*p == ASE_T('-')) - { - exp_negative = 1; - p++; - } - else - { - if (*p == ASE_T('+')) p++; - exp_negative = 0; - } - } - else exp_negative = 0; - - if (!(p < end && ASE_AWK_ISDIGIT (awk, *p))) - { - /*p = pexp;*/ - /*goto done;*/ - goto no_exp; - } - - while (p < end && ASE_AWK_ISDIGIT (awk, *p)) - { - exp = exp * 10 + (*p - ASE_T('0')); - p++; - } - } - -no_exp: - if (exp_negative) exp = frac_exp - exp; - else exp = frac_exp + exp; - - /* - * Generate a floating-point number that represents the exponent. - * Do this by processing the exponent one bit at a time to combine - * many powers of 2 of 10. Then combine the exponent with the - * fraction. - */ - if (exp < 0) - { - exp_negative = 1; - exp = -exp; - } - else exp_negative = 0; - - if (exp > MAX_EXPONENT) exp = MAX_EXPONENT; - - dbl_exp = 1.0; - - for (d = powers_of_10; exp != 0; exp >>= 1, d++) - { - if (exp & 01) dbl_exp *= *d; - } - - if (exp_negative) fraction /= dbl_exp; - else fraction *= dbl_exp; - -done: - if (endptr != ASE_NULL) *endptr = p; - return (negative)? -fraction: fraction; -} - -ase_size_t ase_awk_longtostr ( - ase_long_t value, int radix, const ase_char_t* prefix, - ase_char_t* buf, ase_size_t size) -{ - ase_long_t t, rem; - ase_size_t len, ret, i; - ase_size_t prefix_len; - - prefix_len = (prefix != ASE_NULL)? ase_strlen(prefix): 0; - - t = value; - if (t == 0) - { - /* zero */ - if (buf == ASE_NULL) - { - /* if buf is not given, - * return the number of bytes required */ - return prefix_len + 1; - } - - if (size < prefix_len+1) - { - /* buffer too small */ - return (ase_size_t)-1; - } - - for (i = 0; i < prefix_len; i++) buf[i] = prefix[i]; - buf[prefix_len] = ASE_T('0'); - if (size > prefix_len+1) buf[prefix_len+1] = ASE_T('\0'); - return prefix_len+1; - } - - /* non-zero values */ - len = prefix_len; - if (t < 0) { t = -t; len++; } - while (t > 0) { len++; t /= radix; } - - if (buf == ASE_NULL) - { - /* if buf is not given, return the number of bytes required */ - return len; - } - - if (size < len) return (ase_size_t)-1; /* buffer too small */ - if (size > len) buf[len] = ASE_T('\0'); - ret = len; - - t = value; - if (t < 0) t = -t; - - while (t > 0) - { - rem = t % radix; - if (rem >= 10) - buf[--len] = (ase_char_t)rem + ASE_T('a') - 10; - else - buf[--len] = (ase_char_t)rem + ASE_T('0'); - t /= radix; - } - - if (value < 0) - { - for (i = 1; i <= prefix_len; i++) - { - buf[i] = prefix[i-1]; - len--; - } - buf[--len] = ASE_T('-'); - } - else - { - for (i = 0; i < prefix_len; i++) buf[i] = prefix[i]; - } - - return ret; -} - -ase_char_t* ase_awk_strtok ( - ase_awk_run_t* run, const ase_char_t* s, - const ase_char_t* delim, ase_char_t** tok, ase_size_t* tok_len) -{ - return ase_awk_strxntok ( - run, s, ase_strlen(s), - delim, ase_strlen(delim), tok, tok_len); -} - -ase_char_t* ase_awk_strxtok ( - ase_awk_run_t* run, const ase_char_t* s, ase_size_t len, - const ase_char_t* delim, ase_char_t** tok, ase_size_t* tok_len) -{ - return ase_awk_strxntok ( - run, s, len, - delim, ase_strlen(delim), tok, tok_len); -} - -ase_char_t* ase_awk_strntok ( - ase_awk_run_t* run, const ase_char_t* s, - const ase_char_t* delim, ase_size_t delim_len, - ase_char_t** tok, ase_size_t* tok_len) -{ - return ase_awk_strxntok ( - run, s, ase_strlen(s), - delim, delim_len, tok, tok_len); -} - -ase_char_t* ase_awk_strxntok ( - ase_awk_run_t* run, const ase_char_t* s, ase_size_t len, - const ase_char_t* delim, ase_size_t delim_len, - ase_char_t** tok, ase_size_t* tok_len) -{ - const ase_char_t* p = s, *d; - const ase_char_t* end = s + len; - const ase_char_t* sp = ASE_NULL, * ep = ASE_NULL; - const ase_char_t* delim_end = delim + delim_len; - ase_char_t c; - int delim_mode; - -#define __DELIM_NULL 0 -#define __DELIM_EMPTY 1 -#define __DELIM_SPACES 2 -#define __DELIM_NOSPACES 3 -#define __DELIM_COMPOSITE 4 - if (delim == ASE_NULL) delim_mode = __DELIM_NULL; - else - { - delim_mode = __DELIM_EMPTY; - - for (d = delim; d < delim_end; d++) - { - if (ASE_AWK_ISSPACE(run->awk,*d)) - { - if (delim_mode == __DELIM_EMPTY) - delim_mode = __DELIM_SPACES; - else if (delim_mode == __DELIM_NOSPACES) - { - delim_mode = __DELIM_COMPOSITE; - break; - } - } - else - { - if (delim_mode == __DELIM_EMPTY) - delim_mode = __DELIM_NOSPACES; - else if (delim_mode == __DELIM_SPACES) - { - delim_mode = __DELIM_COMPOSITE; - break; - } - } - } - - /* TODO: verify the following statement... */ - if (delim_mode == __DELIM_SPACES && - delim_len == 1 && - delim[0] != ASE_T(' ')) delim_mode = __DELIM_NOSPACES; - } - - if (delim_mode == __DELIM_NULL) - { - /* when ASE_NULL is given as "delim", it trims off the - * leading and trailing spaces characters off the source - * string "s" eventually. */ - - while (p < end && ASE_AWK_ISSPACE(run->awk,*p)) p++; - while (p < end) - { - c = *p; - - if (!ASE_AWK_ISSPACE(run->awk,c)) - { - if (sp == ASE_NULL) sp = p; - ep = p; - } - p++; - } - } - else if (delim_mode == __DELIM_EMPTY) - { - /* each character in the source string "s" becomes a token. */ - if (p < end) - { - c = *p; - sp = p; - ep = p++; - } - } - else if (delim_mode == __DELIM_SPACES) - { - /* each token is delimited by space characters. all leading - * and trailing spaces are removed. */ - - while (p < end && ASE_AWK_ISSPACE(run->awk,*p)) p++; - while (p < end) - { - c = *p; - if (ASE_AWK_ISSPACE(run->awk,c)) break; - if (sp == ASE_NULL) sp = p; - ep = p++; - } - while (p < end && ASE_AWK_ISSPACE(run->awk,*p)) p++; - } - else if (delim_mode == __DELIM_NOSPACES) - { - /* each token is delimited by one of charaters - * in the delimeter set "delim". */ - if (run->global.ignorecase) - { - while (p < end) - { - c = ASE_AWK_TOUPPER(run->awk, *p); - for (d = delim; d < delim_end; d++) - { - if (c == ASE_AWK_TOUPPER(run->awk,*d)) goto exit_loop; - } - - if (sp == ASE_NULL) sp = p; - ep = p++; - } - } - else - { - while (p < end) - { - c = *p; - for (d = delim; d < delim_end; d++) - { - if (c == *d) goto exit_loop; - } - - if (sp == ASE_NULL) sp = p; - ep = p++; - } - } - } - else /* if (delim_mode == __DELIM_COMPOSITE) */ - { - /* each token is delimited by one of non-space charaters - * in the delimeter set "delim". however, all space characters - * surrounding the token are removed */ - while (p < end && ASE_AWK_ISSPACE(run->awk,*p)) p++; - if (run->global.ignorecase) - { - while (p < end) - { - c = ASE_AWK_TOUPPER(run->awk, *p); - if (ASE_AWK_ISSPACE(run->awk,c)) - { - p++; - continue; - } - for (d = delim; d < delim_end; d++) - { - if (c == ASE_AWK_TOUPPER(run->awk,*d)) goto exit_loop; - } - if (sp == ASE_NULL) sp = p; - ep = p++; - } - } - else - { - while (p < end) - { - c = *p; - if (ASE_AWK_ISSPACE(run->awk,c)) - { - p++; - continue; - } - for (d = delim; d < delim_end; d++) - { - if (c == *d) goto exit_loop; - } - if (sp == ASE_NULL) sp = p; - ep = p++; - } - } - } - -exit_loop: - if (sp == ASE_NULL) - { - *tok = ASE_NULL; - *tok_len = (ase_size_t)0; - } - else - { - *tok = (ase_char_t*)sp; - *tok_len = ep - sp + 1; - } - - /* if ASE_NULL is returned, this function should not be called anymore */ - if (p >= end) return ASE_NULL; - if (delim_mode == __DELIM_EMPTY || - delim_mode == __DELIM_SPACES) return (ase_char_t*)p; - return (ase_char_t*)++p; -} - -ase_char_t* ase_awk_strxntokbyrex ( - ase_awk_run_t* run, const ase_char_t* s, ase_size_t len, - void* rex, ase_char_t** tok, ase_size_t* tok_len, int* errnum) -{ - int n; - ase_char_t* match_ptr; - ase_size_t match_len, i; - ase_size_t left = len; - const ase_char_t* ptr = s; - const ase_char_t* str_ptr = s; - ase_size_t str_len = len; - - while (len > 0) - { - n = ase_awk_matchrex ( - run->awk, rex, - ((run->global.ignorecase)? ASE_AWK_REX_IGNORECASE: 0), - ptr, left, (const ase_char_t**)&match_ptr, &match_len, - errnum); - if (n == -1) return ASE_NULL; - if (n == 0) - { - /* no match has been found. - * return the entire string as a token */ - *tok = (ase_char_t*)str_ptr; - *tok_len = str_len; - *errnum = ASE_AWK_ENOERR; - return ASE_NULL; - } - - ASE_ASSERT (n == 1); - - if (match_len == 0) - { - ptr++; - left--; - } - else if (run->awk->option & ASE_AWK_STRIPSPACES) - { - /* match at the beginning of the input string */ - if (match_ptr == s) - { - for (i = 0; i < match_len; i++) - { - if (!ASE_AWK_ISSPACE(run->awk, match_ptr[i])) - goto exit_loop; - } - - /* the match that are all spaces at the - * beginning of the input string is skipped */ - ptr += match_len; - left -= match_len; - str_ptr = s + match_len; - str_len -= match_len; - } - else break; - } - else break; - } - -exit_loop: - if (len == 0) - { - *tok = (ase_char_t*)str_ptr; - *tok_len = str_len; - *errnum = ASE_AWK_ENOERR; - return ASE_NULL; - } - - *tok = (ase_char_t*)str_ptr; - *tok_len = match_ptr - str_ptr; - - for (i = 0; i < match_len; i++) - { - if (!ASE_AWK_ISSPACE(run->awk, match_ptr[i])) - { - *errnum = ASE_AWK_ENOERR; - return match_ptr+match_len; - } - } - - *errnum = ASE_AWK_ENOERR; - - if (run->awk->option & ASE_AWK_STRIPSPACES) - { - return (match_ptr+match_len >= s+len)? - ASE_NULL: (match_ptr+match_len); - } - else - { - return (match_ptr+match_len > s+len)? - ASE_NULL: (match_ptr+match_len); - } -} - diff --git a/ase/awk/misc.h b/ase/awk/misc.h deleted file mode 100644 index 1a0f175c..00000000 --- a/ase/awk/misc.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * $Id: misc.h,v 1.1.1.1 2007/03/28 14:05:16 bacon Exp $ - * - * {License} - */ - -#ifndef _ASE_AWK_MISC_H_ -#define _ASE_AWK_MISC_H_ - -#ifndef _ASE_AWK_AWK_H_ -#error Never include this file directly. Include instead -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -ase_char_t* ase_awk_strtok ( - ase_awk_run_t* run, const ase_char_t* s, - const ase_char_t* delim, ase_char_t** tok, ase_size_t* tok_len); - -ase_char_t* ase_awk_strxtok ( - ase_awk_run_t* run, const ase_char_t* s, ase_size_t len, - const ase_char_t* delim, ase_char_t** tok, ase_size_t* tok_len); - -ase_char_t* ase_awk_strntok ( - ase_awk_run_t* run, const ase_char_t* s, - const ase_char_t* delim, ase_size_t delim_len, - ase_char_t** tok, ase_size_t* tok_len); - -ase_char_t* ase_awk_strxntok ( - ase_awk_run_t* run, const ase_char_t* s, ase_size_t len, - const ase_char_t* delim, ase_size_t delim_len, - ase_char_t** tok, ase_size_t* tok_len); - -ase_char_t* ase_awk_strxntokbyrex ( - ase_awk_run_t* run, const ase_char_t* s, ase_size_t len, - void* rex, ase_char_t** tok, ase_size_t* tok_len, int* errnum); - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/ase/awk/parse.c b/ase/awk/parse.c deleted file mode 100644 index 19ee5266..00000000 --- a/ase/awk/parse.c +++ /dev/null @@ -1,5113 +0,0 @@ -/* - * $Id: parse.c,v 1.1.1.1 2007/03/28 14:05:17 bacon Exp $ - * - * {License} - */ - -#include - -enum -{ - TOKEN_EOF, - TOKEN_NEWLINE, - - /* TOKEN_XXX_ASSIGNs should in sync - * with assop in assign_to_opcode */ - TOKEN_ASSIGN, - TOKEN_PLUS_ASSIGN, - TOKEN_MINUS_ASSIGN, - TOKEN_MUL_ASSIGN, - TOKEN_DIV_ASSIGN, - TOKEN_IDIV_ASSIGN, - TOKEN_MOD_ASSIGN, - TOKEN_EXP_ASSIGN, - - TOKEN_EQ, - TOKEN_NE, - TOKEN_LE, - TOKEN_LT, - TOKEN_GE, - TOKEN_GT, - TOKEN_NM, /* not match */ - TOKEN_NOT, - TOKEN_PLUS, - TOKEN_PLUSPLUS, - TOKEN_MINUS, - TOKEN_MINUSMINUS, - TOKEN_MUL, - TOKEN_DIV, - TOKEN_IDIV, - TOKEN_MOD, - TOKEN_LOR, - TOKEN_LAND, - TOKEN_BOR, - TOKEN_BXOR, - TOKEN_BAND, - TOKEN_BORAND, - TOKEN_TILDE, /* used for unary bitwise-not and regex match */ - TOKEN_RSHIFT, - TOKEN_LSHIFT, - TOKEN_IN, - TOKEN_EXP, - - TOKEN_LPAREN, - TOKEN_RPAREN, - TOKEN_LBRACE, - TOKEN_RBRACE, - TOKEN_LBRACK, - TOKEN_RBRACK, - - TOKEN_DOLLAR, - TOKEN_COMMA, - TOKEN_PERIOD, - TOKEN_SEMICOLON, - TOKEN_COLON, - TOKEN_QUEST, - - TOKEN_BEGIN, - TOKEN_END, - TOKEN_FUNCTION, - - TOKEN_LOCAL, - TOKEN_GLOBAL, - - TOKEN_IF, - TOKEN_ELSE, - TOKEN_WHILE, - TOKEN_FOR, - TOKEN_DO, - TOKEN_BREAK, - TOKEN_CONTINUE, - TOKEN_RETURN, - TOKEN_EXIT, - TOKEN_NEXT, - TOKEN_NEXTFILE, - TOKEN_NEXTINFILE, - TOKEN_NEXTOFILE, - TOKEN_DELETE, - TOKEN_PRINT, - TOKEN_PRINTF, - - TOKEN_GETLINE, - TOKEN_IDENT, - TOKEN_INT, - TOKEN_REAL, - TOKEN_STR, - TOKEN_REX, - - __TOKEN_COUNT__ -}; - -enum -{ - PARSE_GLOBAL, - PARSE_FUNCTION, - PARSE_BEGIN, - PARSE_END, - PARSE_BEGIN_BLOCK, - PARSE_END_BLOCK, - PARSE_PATTERN, - PARSE_ACTION_BLOCK -}; - -enum -{ - PARSE_LOOP_NONE, - PARSE_LOOP_WHILE, - PARSE_LOOP_FOR, - PARSE_LOOP_DOWHILE -}; - -typedef struct binmap_t binmap_t; - -struct binmap_t -{ - int token; - int binop; -}; - -static int parse (ase_awk_t* awk); - -static ase_awk_t* parse_progunit (ase_awk_t* awk); -static ase_awk_t* collect_globals (ase_awk_t* awk); -static ase_awk_t* add_builtin_globals (ase_awk_t* awk); -static ase_awk_t* add_global ( - ase_awk_t* awk, const ase_char_t* name, ase_size_t len, - ase_size_t line, int force); -static ase_awk_t* collect_locals (ase_awk_t* awk, ase_size_t nlocals); - -static ase_awk_nde_t* parse_function (ase_awk_t* awk); -static ase_awk_nde_t* parse_begin (ase_awk_t* awk); -static ase_awk_nde_t* parse_end (ase_awk_t* awk); -static ase_awk_chain_t* parse_pattern_block ( - ase_awk_t* awk, ase_awk_nde_t* ptn, ase_bool_t blockless); - -static ase_awk_nde_t* parse_block (ase_awk_t* awk, ase_size_t line, ase_bool_t is_top); -static ase_awk_nde_t* parse_block_dc (ase_awk_t* awk, ase_size_t line, ase_bool_t is_top); -static ase_awk_nde_t* parse_statement (ase_awk_t* awk, ase_size_t line); -static ase_awk_nde_t* parse_statement_nb (ase_awk_t* awk, ase_size_t line); - -static ase_awk_nde_t* parse_expression (ase_awk_t* awk, ase_size_t line); -static ase_awk_nde_t* parse_expression0 (ase_awk_t* awk, ase_size_t line); -static ase_awk_nde_t* parse_basic_expr (ase_awk_t* awk, ase_size_t line); - -static ase_awk_nde_t* parse_binary_expr ( - ase_awk_t* awk, ase_size_t line, const binmap_t* binmap, - ase_awk_nde_t*(*next_level_func)(ase_awk_t*,ase_size_t)); - -static ase_awk_nde_t* parse_logical_or (ase_awk_t* awk, ase_size_t line); -static ase_awk_nde_t* parse_logical_and (ase_awk_t* awk, ase_size_t line); -static ase_awk_nde_t* parse_in (ase_awk_t* awk, ase_size_t line); -static ase_awk_nde_t* parse_regex_match (ase_awk_t* awk, ase_size_t line); -static ase_awk_nde_t* parse_bitwise_or (ase_awk_t* awk, ase_size_t line); -static ase_awk_nde_t* parse_bitwise_or_with_extio (ase_awk_t* awk, ase_size_t line); -static ase_awk_nde_t* parse_bitwise_xor (ase_awk_t* awk, ase_size_t line); -static ase_awk_nde_t* parse_bitwise_and (ase_awk_t* awk, ase_size_t line); -static ase_awk_nde_t* parse_equality (ase_awk_t* awk, ase_size_t line); -static ase_awk_nde_t* parse_relational (ase_awk_t* awk, ase_size_t line); -static ase_awk_nde_t* parse_shift (ase_awk_t* awk, ase_size_t line); -static ase_awk_nde_t* parse_concat (ase_awk_t* awk, ase_size_t line); -static ase_awk_nde_t* parse_additive (ase_awk_t* awk, ase_size_t line); -static ase_awk_nde_t* parse_multiplicative (ase_awk_t* awk, ase_size_t line); - -static ase_awk_nde_t* parse_unary (ase_awk_t* awk, ase_size_t line); -static ase_awk_nde_t* parse_exponent (ase_awk_t* awk, ase_size_t line); -static ase_awk_nde_t* parse_unary_exp (ase_awk_t* awk, ase_size_t line); -static ase_awk_nde_t* parse_increment (ase_awk_t* awk, ase_size_t line); -static ase_awk_nde_t* parse_primary (ase_awk_t* awk, ase_size_t line); -static ase_awk_nde_t* parse_primary_ident (ase_awk_t* awk, ase_size_t line); - -static ase_awk_nde_t* parse_hashidx ( - ase_awk_t* awk, ase_char_t* name, ase_size_t name_len, - ase_size_t line); -static ase_awk_nde_t* parse_fncall ( - ase_awk_t* awk, ase_char_t* name, ase_size_t name_len, - ase_awk_bfn_t* bfn, ase_size_t line); -static ase_awk_nde_t* parse_if (ase_awk_t* awk, ase_size_t line); -static ase_awk_nde_t* parse_while (ase_awk_t* awk, ase_size_t line); -static ase_awk_nde_t* parse_for (ase_awk_t* awk, ase_size_t line); -static ase_awk_nde_t* parse_dowhile (ase_awk_t* awk, ase_size_t line); -static ase_awk_nde_t* parse_break (ase_awk_t* awk, ase_size_t line); -static ase_awk_nde_t* parse_continue (ase_awk_t* awk, ase_size_t line); -static ase_awk_nde_t* parse_return (ase_awk_t* awk, ase_size_t line); -static ase_awk_nde_t* parse_exit (ase_awk_t* awk, ase_size_t line); -static ase_awk_nde_t* parse_next (ase_awk_t* awk, ase_size_t line); -static ase_awk_nde_t* parse_nextfile (ase_awk_t* awk, ase_size_t line, int out); -static ase_awk_nde_t* parse_delete (ase_awk_t* awk, ase_size_t line); -static ase_awk_nde_t* parse_print (ase_awk_t* awk, ase_size_t line, int type); - -static int get_token (ase_awk_t* awk); -static int get_number (ase_awk_t* awk); -static int get_charstr (ase_awk_t* awk); -static int get_rexstr (ase_awk_t* awk); -static int get_string ( - ase_awk_t* awk, ase_char_t end_char, - ase_char_t esc_char, ase_bool_t keep_esc_char); -static int get_char (ase_awk_t* awk); -static int unget_char (ase_awk_t* awk, ase_cint_t c); -static int skip_spaces (ase_awk_t* awk); -static int skip_comment (ase_awk_t* awk); -static int classify_ident ( - ase_awk_t* awk, const ase_char_t* name, ase_size_t len); -static int assign_to_opcode (ase_awk_t* awk); -static int is_plain_var (ase_awk_nde_t* nde); -static int is_var (ase_awk_nde_t* nde); - -static int deparse (ase_awk_t* awk); -static int deparse_func (ase_awk_pair_t* pair, void* arg); -static int put_char (ase_awk_t* awk, ase_char_t c); -static int flush_out (ase_awk_t* awk); - -typedef struct kwent_t kwent_t; - -struct kwent_t -{ - const ase_char_t* name; - ase_size_t name_len; - int type; - int valid; /* the entry is valid when this option is set */ -}; - -static kwent_t kwtab[] = -{ - /* operators */ - { ASE_T("in"), 2, TOKEN_IN, 0 }, - - /* top-level block starters */ - { ASE_T("BEGIN"), 5, TOKEN_BEGIN, 0 }, - { ASE_T("END"), 3, TOKEN_END, 0 }, - { ASE_T("function"), 8, TOKEN_FUNCTION, 0 }, - { ASE_T("func"), 4, TOKEN_FUNCTION, 0 }, - - /* keywords for variable declaration */ - { ASE_T("local"), 5, TOKEN_LOCAL, ASE_AWK_EXPLICIT }, - { ASE_T("global"), 6, TOKEN_GLOBAL, ASE_AWK_EXPLICIT }, - - /* keywords that start statements excluding expression statements */ - { ASE_T("if"), 2, TOKEN_IF, 0 }, - { ASE_T("else"), 4, TOKEN_ELSE, 0 }, - { ASE_T("while"), 5, TOKEN_WHILE, 0 }, - { ASE_T("for"), 3, TOKEN_FOR, 0 }, - { ASE_T("do"), 2, TOKEN_DO, 0 }, - { ASE_T("break"), 5, TOKEN_BREAK, 0 }, - { ASE_T("continue"), 8, TOKEN_CONTINUE, 0 }, - { ASE_T("return"), 6, TOKEN_RETURN, 0 }, - { ASE_T("exit"), 4, TOKEN_EXIT, 0 }, - { ASE_T("next"), 4, TOKEN_NEXT, 0 }, - { ASE_T("nextfile"), 8, TOKEN_NEXTFILE, 0 }, - { ASE_T("nextofile"), 9, TOKEN_NEXTOFILE, ASE_AWK_NEXTOFILE }, - { ASE_T("delete"), 6, TOKEN_DELETE, 0 }, - { ASE_T("print"), 5, TOKEN_PRINT, ASE_AWK_EXTIO }, - { ASE_T("printf"), 6, TOKEN_PRINTF, ASE_AWK_EXTIO }, - - /* keywords that can start an expression */ - { ASE_T("getline"), 7, TOKEN_GETLINE, ASE_AWK_EXTIO }, - - { ASE_NULL, 0, 0, 0 } -}; - -typedef struct global_t global_t; - -struct global_t -{ - const ase_char_t* name; - ase_size_t name_len; - int valid; -}; - -static global_t gtab[] = -{ - { ASE_T("ARGC"), 4, 0 }, - { ASE_T("ARGV"), 4, 0 }, - { ASE_T("CONVFMT"), 7, 0 }, - { ASE_T("ENVIRON"), 7, 0 }, - { ASE_T("FILENAME"), 8, 0 }, - { ASE_T("FNR"), 3, 0 }, - { ASE_T("FS"), 2, 0 }, - { ASE_T("IGNORECASE"), 10, 0 }, - { ASE_T("NF"), 2, 0 }, - { ASE_T("NR"), 2, 0 }, - { ASE_T("OFILENAME"), 9, ASE_AWK_NEXTOFILE }, - { ASE_T("OFMT"), 4, 0 }, - { ASE_T("OFS"), 3, 0 }, - { ASE_T("ORS"), 3, 0 }, - { ASE_T("RLENGTH"), 7, 0 }, - { ASE_T("RS"), 2, 0 }, - { ASE_T("RSTART"), 6, 0 }, - { ASE_T("SUBSEP"), 6, 0 }, - { ASE_NULL, 0, 0 } -}; - -#define GET_CHAR(awk) \ - do { if (get_char (awk) == -1) return -1; } while(0) - -#define GET_CHAR_TO(awk,c) \ - do { \ - if (get_char (awk) == -1) return -1; \ - c = (awk)->src.lex.curc; \ - } while(0) - -#define SET_TOKEN_TYPE(awk,code) do { (awk)->token.type = (code); } while (0) - -#define ADD_TOKEN_CHAR(awk,c) \ - do { \ - if (ase_str_ccat(&(awk)->token.name,(c)) == (ase_size_t)-1) \ - { \ - ase_awk_seterror (awk, ASE_AWK_ENOMEM, (awk)->token.line, ASE_NULL, 0); \ - return -1; \ - } \ - } while (0) - -#define MATCH(awk,token_type) ((awk)->token.type == (token_type)) - -#define CLRERR(awk) ase_awk_seterrnum(awk,ASE_AWK_ENOERR) -#define ISNOERR(awk) ((awk)->errnum == ASE_AWK_ENOERR) -#define SETERR(awk,code) ase_awk_seterrnum(awk,code) -#define SETERRLIN(awk,code,line) ase_awk_seterror(awk,code,line,ASE_NULL,0) -#define SETERRTOK(awk,code) \ - do { \ - ase_cstr_t errarg; \ - errarg.len = ASE_STR_LEN(&(awk)->token.name); \ - errarg.ptr = ASE_STR_BUF(&(awk)->token.name); \ - if (MATCH(awk,TOKEN_EOF)) \ - ase_awk_seterror (awk, code, (awk)->token.prev.line, &errarg, 1); \ - else \ - ase_awk_seterror (awk, code, (awk)->token.line, &errarg, 1); \ - } while (0) - -#define SETERRARG(awk,code,line,arg,leng) \ - do { \ - ase_cstr_t errarg; \ - errarg.len = (leng); \ - errarg.ptr = (arg); \ - ase_awk_seterror ((awk), (code), (line), &errarg, 1); \ - } while (0) - -ase_size_t ase_awk_getmaxdepth (ase_awk_t* awk, int type) -{ - return (type == ASE_AWK_DEPTH_BLOCK_PARSE)? awk->parse.depth.max.block: - (type == ASE_AWK_DEPTH_BLOCK_RUN)? awk->run.depth.max.block: - (type == ASE_AWK_DEPTH_EXPR_PARSE)? awk->parse.depth.max.expr: - (type == ASE_AWK_DEPTH_EXPR_RUN)? awk->run.depth.max.expr: - (type == ASE_AWK_DEPTH_REX_BUILD)? awk->rex.depth.max.build: - (type == ASE_AWK_DEPTH_REX_MATCH)? awk->rex.depth.max.match: 0; -} - -void ase_awk_setmaxdepth (ase_awk_t* awk, int types, ase_size_t depth) -{ - if (types & ASE_AWK_DEPTH_BLOCK_PARSE) - { - awk->parse.depth.max.block = depth; - if (depth <= 0) - awk->parse.parse_block = parse_block; - else - awk->parse.parse_block = parse_block_dc; - } - - if (types & ASE_AWK_DEPTH_EXPR_PARSE) - { - awk->parse.depth.max.expr = depth; - } - - if (types & ASE_AWK_DEPTH_BLOCK_RUN) - { - awk->run.depth.max.block = depth; - } - - if (types & ASE_AWK_DEPTH_EXPR_RUN) - { - awk->run.depth.max.expr = depth; - } - - if (types & ASE_AWK_DEPTH_REX_BUILD) - { - awk->rex.depth.max.build = depth; - } - - if (types & ASE_AWK_DEPTH_REX_MATCH) - { - awk->rex.depth.max.match = depth; - } -} - -const ase_char_t* ase_awk_getglobalname ( - ase_awk_t* awk, ase_size_t idx, ase_size_t* len) -{ - *len = gtab[idx].name_len; - return gtab[idx].name; -} - -int ase_awk_parse (ase_awk_t* awk, ase_awk_srcios_t* srcios) -{ - int n; - - ASE_ASSERTX ( - srcios != ASE_NULL && srcios->in != ASE_NULL, - "the source code input stream must be provided at least"); - ASE_ASSERT (awk->parse.depth.cur.loop == 0); - ASE_ASSERT (awk->parse.depth.cur.expr == 0); - - ase_awk_clear (awk); - ase_memcpy (&awk->src.ios, srcios, ASE_SIZEOF(awk->src.ios)); - - n = parse (awk); - - ASE_ASSERT (awk->parse.depth.cur.loop == 0); - ASE_ASSERT (awk->parse.depth.cur.expr == 0); - - return n; -} - -static int parse (ase_awk_t* awk) -{ - int n = 0, op; - - ASE_ASSERT (awk->src.ios.in != ASE_NULL); - - CLRERR (awk); - op = awk->src.ios.in ( - ASE_AWK_IO_OPEN, awk->src.ios.custom_data, ASE_NULL, 0); - if (op <= -1) - { - /* cannot open the source file. - * it doesn't even have to call CLOSE */ - if (ISNOERR(awk)) SETERR (awk, ASE_AWK_ESINOP); - return -1; - } - - if (add_builtin_globals (awk) == ASE_NULL) - { - n = -1; - goto exit_parse; - } - - /* the user io handler for the source code input returns 0 when - * it doesn't have any files to open. this is the same condition - * as the source code file is empty. so it will perform the parsing - * when op is positive, which means there are something to parse */ - if (op > 0) - { - /* get the first character */ - if (get_char(awk) == -1) - { - n = -1; - goto exit_parse; - } - - /* get the first token */ - if (get_token(awk) == -1) - { - n = -1; - goto exit_parse; - } - - while (1) - { - if (MATCH(awk,TOKEN_EOF)) break; - if (MATCH(awk,TOKEN_NEWLINE)) continue; - - if (parse_progunit (awk) == ASE_NULL) - { - n = -1; - goto exit_parse; - } - } - } - - awk->tree.nglobals = ase_awk_tab_getsize(&awk->parse.globals); - - if (awk->src.ios.out != ASE_NULL) - { - if (deparse (awk) == -1) - { - n = -1; - goto exit_parse; - } - } - -exit_parse: - if (n == 0) CLRERR (awk); - if (awk->src.ios.in ( - ASE_AWK_IO_CLOSE, awk->src.ios.custom_data, ASE_NULL, 0) != 0) - { - if (n == 0) - { - /* this is to keep the earlier error above - * that might be more critical than this */ - if (ISNOERR(awk)) SETERR (awk, ASE_AWK_ESINCL); - n = -1; - } - } - - if (n == -1) ase_awk_clear (awk); - else awk->tree.ok = 1; - - return n; -} - -static ase_awk_t* parse_progunit (ase_awk_t* awk) -{ - /* - pattern { action } - function name (parameter-list) { statement } - */ - - ASE_ASSERT (awk->parse.depth.cur.loop == 0); - - if ((awk->option & ASE_AWK_EXPLICIT) && MATCH(awk,TOKEN_GLOBAL)) - { - ase_size_t nglobals; - - awk->parse.id.block = PARSE_GLOBAL; - - if (get_token(awk) == -1) return ASE_NULL; - - nglobals = ase_awk_tab_getsize(&awk->parse.globals); - if (collect_globals (awk) == ASE_NULL) - { - ase_awk_tab_remove ( - &awk->parse.globals, nglobals, - ase_awk_tab_getsize(&awk->parse.globals) - nglobals); - return ASE_NULL; - } - } - else if (MATCH(awk,TOKEN_FUNCTION)) - { - awk->parse.id.block = PARSE_FUNCTION; - if (parse_function (awk) == ASE_NULL) return ASE_NULL; - } - else if (MATCH(awk,TOKEN_BEGIN)) - { - awk->parse.id.block = PARSE_BEGIN; - if (get_token(awk) == -1) return ASE_NULL; - - if ((awk->option & ASE_AWK_BLOCKLESS) && - (MATCH(awk,TOKEN_NEWLINE) || MATCH(awk,TOKEN_EOF))) - { - /* when the blockless pattern is supported - * BEGIN and { should be located on the same line */ - SETERRLIN (awk, ASE_AWK_EBLKBEG, awk->token.prev.line); - return ASE_NULL; - } - - if (!MATCH(awk,TOKEN_LBRACE)) - { - SETERRTOK (awk, ASE_AWK_ELBRACE); - return ASE_NULL; - } - - awk->parse.id.block = PARSE_BEGIN_BLOCK; - if (parse_begin (awk) == ASE_NULL) return ASE_NULL; - } - else if (MATCH(awk,TOKEN_END)) - { - awk->parse.id.block = PARSE_END; - if (get_token(awk) == -1) return ASE_NULL; - - if ((awk->option & ASE_AWK_BLOCKLESS) && - (MATCH(awk,TOKEN_NEWLINE) || MATCH(awk,TOKEN_EOF))) - { - /* when the blockless pattern is supported - * END and { should be located on the same line */ - SETERRLIN (awk, ASE_AWK_EBLKEND, awk->token.prev.line); - return ASE_NULL; - } - - if (!MATCH(awk,TOKEN_LBRACE)) - { - SETERRTOK (awk, ASE_AWK_ELBRACE); - return ASE_NULL; - } - - awk->parse.id.block = PARSE_END_BLOCK; - if (parse_end (awk) == ASE_NULL) return ASE_NULL; - } - else if (MATCH(awk,TOKEN_LBRACE)) - { - /* patternless block */ - awk->parse.id.block = PARSE_ACTION_BLOCK; - if (parse_pattern_block ( - awk, ASE_NULL, ase_false) == ASE_NULL) return ASE_NULL; - } - else - { - /* - expressions - /regular expression/ - pattern && pattern - pattern || pattern - !pattern - (pattern) - pattern, pattern - */ - ase_awk_nde_t* ptn; - - awk->parse.id.block = PARSE_PATTERN; - - ptn = parse_expression (awk, awk->token.line); - if (ptn == ASE_NULL) return ASE_NULL; - - ASE_ASSERT (ptn->next == ASE_NULL); - - if (MATCH(awk,TOKEN_COMMA)) - { - if (get_token (awk) == -1) - { - ase_awk_clrpt (awk, ptn); - return ASE_NULL; - } - - ptn->next = parse_expression (awk, awk->token.line); - if (ptn->next == ASE_NULL) - { - ase_awk_clrpt (awk, ptn); - return ASE_NULL; - } - } - - if ((awk->option & ASE_AWK_BLOCKLESS) && - (MATCH(awk,TOKEN_NEWLINE) || MATCH(awk,TOKEN_EOF))) - { - /* blockless pattern */ - ase_bool_t newline = MATCH(awk,TOKEN_NEWLINE); - - awk->parse.id.block = PARSE_ACTION_BLOCK; - if (parse_pattern_block ( - awk, ptn, ase_true) == ASE_NULL) - { - ase_awk_clrpt (awk, ptn); - return ASE_NULL; - } - - if (newline) - { - if (get_token (awk) == -1) - { - /* ptn has been added to the chain. - * it doesn't have to be cleared here - * as ase_awk_clear does it */ - /*ase_awk_clrpt (awk, ptn);*/ - return ASE_NULL; - } - } - } - else - { - /* parse the action block */ - if (!MATCH(awk,TOKEN_LBRACE)) - { - ase_awk_clrpt (awk, ptn); - SETERRTOK (awk, ASE_AWK_ELBRACE); - return ASE_NULL; - } - - awk->parse.id.block = PARSE_ACTION_BLOCK; - if (parse_pattern_block ( - awk, ptn, ase_false) == ASE_NULL) - { - ase_awk_clrpt (awk, ptn); - return ASE_NULL; - } - } - } - - return awk; -} - -static ase_awk_nde_t* parse_function (ase_awk_t* awk) -{ - ase_char_t* name; - ase_char_t* name_dup; - ase_size_t name_len; - ase_awk_nde_t* body; - ase_awk_afn_t* afn; - ase_size_t nargs; - ase_awk_pair_t* pair; - int n; - - /* eat up the keyword 'function' and get the next token */ - ASE_ASSERT (MATCH(awk,TOKEN_FUNCTION)); - if (get_token(awk) == -1) return ASE_NULL; - - /* match a function name */ - if (!MATCH(awk,TOKEN_IDENT)) - { - /* cannot find a valid identifier for a function name */ - SETERRTOK (awk, ASE_AWK_EFNNAME); - return ASE_NULL; - } - - name = ASE_STR_BUF(&awk->token.name); - name_len = ASE_STR_LEN(&awk->token.name); - - /* check if it is a builtin function */ - if (ase_awk_getbfn (awk, name, name_len) != ASE_NULL) - { - SETERRARG (awk, ASE_AWK_EBFNRED, awk->token.line, name, name_len); - return ASE_NULL; - } - - if (ase_awk_map_get(&awk->tree.afns, name, name_len) != ASE_NULL) - { - /* the function is defined previously */ - SETERRARG ( - awk, ASE_AWK_EAFNRED, awk->token.line, - name, name_len); - return ASE_NULL; - } - - if (awk->option & ASE_AWK_UNIQUEFN) - { - /* check if it coincides to be a global variable name */ - ase_size_t g; - - g = ase_awk_tab_find (&awk->parse.globals, 0, name, name_len); - if (g != (ase_size_t)-1) - { - SETERRARG ( - awk, ASE_AWK_EGBLRED, awk->token.line, - name, name_len); - - return ASE_NULL; - } - } - - /* clone the function name before it is overwritten */ - name_dup = ase_strxdup (name, name_len, &awk->prmfns.mmgr); - if (name_dup == ASE_NULL) - { - SETERRLIN (awk, ASE_AWK_ENOMEM, awk->token.line); - return ASE_NULL; - } - - /* get the next token */ - if (get_token(awk) == -1) - { - ASE_AWK_FREE (awk, name_dup); - return ASE_NULL; - } - - /* match a left parenthesis */ - if (!MATCH(awk,TOKEN_LPAREN)) - { - /* a function name is not followed by a left parenthesis */ - ASE_AWK_FREE (awk, name_dup); - - SETERRTOK (awk, ASE_AWK_ELPAREN); - return ASE_NULL; - } - - /* get the next token */ - if (get_token(awk) == -1) - { - ASE_AWK_FREE (awk, name_dup); - return ASE_NULL; - } - - /* make sure that parameter table is empty */ - ASE_ASSERT (ase_awk_tab_getsize(&awk->parse.params) == 0); - - /* read parameter list */ - if (MATCH(awk,TOKEN_RPAREN)) - { - /* no function parameter found. get the next token */ - if (get_token(awk) == -1) - { - ASE_AWK_FREE (awk, name_dup); - return ASE_NULL; - } - } - else - { - while (1) - { - ase_char_t* param; - ase_size_t param_len; - - if (!MATCH(awk,TOKEN_IDENT)) - { - ASE_AWK_FREE (awk, name_dup); - ase_awk_tab_clear (&awk->parse.params); - SETERRTOK (awk, ASE_AWK_EBADPAR); - return ASE_NULL; - } - - param = ASE_STR_BUF(&awk->token.name); - param_len = ASE_STR_LEN(&awk->token.name); - - if (awk->option & ASE_AWK_UNIQUEFN) - { - /* check if a parameter conflicts with a function */ - if (ase_strxncmp (name_dup, name_len, param, param_len) == 0 || - ase_awk_map_get (&awk->tree.afns, param, param_len) != ASE_NULL) - { - ASE_AWK_FREE (awk, name_dup); - ase_awk_tab_clear (&awk->parse.params); - - SETERRARG ( - awk, ASE_AWK_EAFNRED, awk->token.line, - param, param_len); - - return ASE_NULL; - } - - /* NOTE: the following is not a conflict - * global x; - * function f (x) { print x; } - * x in print x is a parameter - */ - } - - /* check if a parameter conflicts with other parameters */ - if (ase_awk_tab_find ( - &awk->parse.params, - 0, param, param_len) != (ase_size_t)-1) - { - ASE_AWK_FREE (awk, name_dup); - ase_awk_tab_clear (&awk->parse.params); - - SETERRARG ( - awk, ASE_AWK_EDUPPAR, awk->token.line, - param, param_len); - - return ASE_NULL; - } - - /* push the parameter to the parameter list */ - if (ase_awk_tab_getsize ( - &awk->parse.params) >= ASE_AWK_MAX_PARAMS) - { - ASE_AWK_FREE (awk, name_dup); - ase_awk_tab_clear (&awk->parse.params); - - SETERRTOK (awk, ASE_AWK_EPARTM); - return ASE_NULL; - } - - if (ase_awk_tab_add ( - &awk->parse.params, - param, param_len) == (ase_size_t)-1) - { - ASE_AWK_FREE (awk, name_dup); - ase_awk_tab_clear (&awk->parse.params); - - SETERRLIN (awk, ASE_AWK_ENOMEM, awk->token.line); - return ASE_NULL; - } - - if (get_token (awk) == -1) - { - ASE_AWK_FREE (awk, name_dup); - ase_awk_tab_clear (&awk->parse.params); - return ASE_NULL; - } - - if (MATCH(awk,TOKEN_RPAREN)) break; - - if (!MATCH(awk,TOKEN_COMMA)) - { - ASE_AWK_FREE (awk, name_dup); - ase_awk_tab_clear (&awk->parse.params); - - SETERRTOK (awk, ASE_AWK_ECOMMA); - return ASE_NULL; - } - - if (get_token(awk) == -1) - { - ASE_AWK_FREE (awk, name_dup); - ase_awk_tab_clear (&awk->parse.params); - return ASE_NULL; - } - } - - if (get_token(awk) == -1) - { - ASE_AWK_FREE (awk, name_dup); - ase_awk_tab_clear (&awk->parse.params); - return ASE_NULL; - } - } - - /* check if the function body starts with a left brace */ - if (!MATCH(awk,TOKEN_LBRACE)) - { - ASE_AWK_FREE (awk, name_dup); - ase_awk_tab_clear (&awk->parse.params); - - SETERRTOK (awk, ASE_AWK_ELBRACE); - return ASE_NULL; - } - if (get_token(awk) == -1) - { - ASE_AWK_FREE (awk, name_dup); - ase_awk_tab_clear (&awk->parse.params); - return ASE_NULL; - } - - /* remember the current function name so that the body parser - * can know the name of the current function being parsed */ - awk->tree.cur_afn.ptr = name_dup; - awk->tree.cur_afn.len = name_len; - - /* actual function body */ - body = awk->parse.parse_block (awk, awk->token.prev.line, ase_true); - - /* clear the current function name remembered */ - awk->tree.cur_afn.ptr = ASE_NULL; - awk->tree.cur_afn.len = 0; - - if (body == ASE_NULL) - { - ASE_AWK_FREE (awk, name_dup); - ase_awk_tab_clear (&awk->parse.params); - return ASE_NULL; - } - - /* TODO: study furthur if the parameter names should be saved - * for some reasons - might be need for deparsing output */ - nargs = ase_awk_tab_getsize (&awk->parse.params); - /* parameter names are not required anymore. clear them */ - ase_awk_tab_clear (&awk->parse.params); - - afn = (ase_awk_afn_t*) - ASE_AWK_MALLOC (awk, ASE_SIZEOF(ase_awk_afn_t)); - if (afn == ASE_NULL) - { - ASE_AWK_FREE (awk, name_dup); - ase_awk_clrpt (awk, body); - - SETERRLIN (awk, ASE_AWK_ENOMEM, awk->token.line); - return ASE_NULL; - } - - afn->name = ASE_NULL; /* function name set below */ - afn->name_len = 0; - afn->nargs = nargs; - afn->body = body; - - n = ase_awk_map_putx (&awk->tree.afns, name_dup, name_len, afn, &pair); - if (n < 0) - { - ASE_AWK_FREE (awk, name_dup); - ase_awk_clrpt (awk, body); - ASE_AWK_FREE (awk, afn); - - SETERRLIN (awk, ASE_AWK_ENOMEM, awk->token.line); - return ASE_NULL; - } - - /* duplicate functions should have been detected previously */ - ASE_ASSERT (n != 0); - - afn->name = pair->key; /* do some trick to save a string. */ - afn->name_len = pair->key_len; - ASE_AWK_FREE (awk, name_dup); - - return body; -} - -static ase_awk_nde_t* parse_begin (ase_awk_t* awk) -{ - ase_awk_nde_t* nde; - - ASE_ASSERT (MATCH(awk,TOKEN_LBRACE)); - - if (get_token(awk) == -1) return ASE_NULL; - nde = awk->parse.parse_block (awk, awk->token.prev.line, ase_true); - if (nde == ASE_NULL) return ASE_NULL; - - awk->tree.begin = nde; - return nde; -} - -static ase_awk_nde_t* parse_end (ase_awk_t* awk) -{ - ase_awk_nde_t* nde; - - ASE_ASSERT (MATCH(awk,TOKEN_LBRACE)); - - if (get_token(awk) == -1) return ASE_NULL; - nde = awk->parse.parse_block (awk, awk->token.prev.line, ase_true); - if (nde == ASE_NULL) return ASE_NULL; - - awk->tree.end = nde; - return nde; -} - -static ase_awk_chain_t* parse_pattern_block ( - ase_awk_t* awk, ase_awk_nde_t* ptn, ase_bool_t blockless) -{ - ase_awk_nde_t* nde; - ase_awk_chain_t* chain; - ase_size_t line = awk->token.line; - - if (blockless) nde = ASE_NULL; - else - { - ASE_ASSERT (MATCH(awk,TOKEN_LBRACE)); - if (get_token(awk) == -1) return ASE_NULL; - nde = awk->parse.parse_block (awk, line, ase_true); - if (nde == ASE_NULL) return ASE_NULL; - } - - chain = (ase_awk_chain_t*) - ASE_AWK_MALLOC (awk, ASE_SIZEOF(ase_awk_chain_t)); - if (chain == ASE_NULL) - { - ase_awk_clrpt (awk, nde); - - SETERRLIN (awk, ASE_AWK_ENOMEM, line); - return ASE_NULL; - } - - chain->pattern = ptn; - chain->action = nde; - chain->next = ASE_NULL; - - if (awk->tree.chain == ASE_NULL) - { - awk->tree.chain = chain; - awk->tree.chain_tail = chain; - awk->tree.chain_size++; - } - else - { - awk->tree.chain_tail->next = chain; - awk->tree.chain_tail = chain; - awk->tree.chain_size++; - } - - return chain; -} - -static ase_awk_nde_t* parse_block ( - ase_awk_t* awk, ase_size_t line, ase_bool_t is_top) -{ - ase_awk_nde_t* head, * curr, * nde; - ase_awk_nde_blk_t* block; - ase_size_t nlocals, nlocals_max, tmp; - - nlocals = ase_awk_tab_getsize(&awk->parse.locals); - nlocals_max = awk->parse.nlocals_max; - - /* local variable declarations */ - if (awk->option & ASE_AWK_EXPLICIT) - { - while (1) - { - if (!MATCH(awk,TOKEN_LOCAL)) break; - - if (get_token(awk) == -1) - { - ase_awk_tab_remove ( - &awk->parse.locals, nlocals, - ase_awk_tab_getsize(&awk->parse.locals) - nlocals); - return ASE_NULL; - } - - if (collect_locals (awk, nlocals) == ASE_NULL) - { - ase_awk_tab_remove ( - &awk->parse.locals, nlocals, - ase_awk_tab_getsize(&awk->parse.locals) - nlocals); - return ASE_NULL; - } - } - } - - /* block body */ - head = ASE_NULL; curr = ASE_NULL; - - while (1) - { - if (MATCH(awk,TOKEN_EOF)) - { - ase_awk_tab_remove ( - &awk->parse.locals, nlocals, - ase_awk_tab_getsize(&awk->parse.locals) - nlocals); - if (head != ASE_NULL) ase_awk_clrpt (awk, head); - - SETERRLIN (awk, ASE_AWK_EENDSRC, awk->token.prev.line); - return ASE_NULL; - } - - if (MATCH(awk,TOKEN_RBRACE)) - { - if (get_token(awk) == -1) - { - ase_awk_tab_remove ( - &awk->parse.locals, nlocals, - ase_awk_tab_getsize(&awk->parse.locals) - nlocals); - if (head != ASE_NULL) ase_awk_clrpt (awk, head); - return ASE_NULL; - } - break; - } - - nde = parse_statement (awk, awk->token.line); - if (nde == ASE_NULL) - { - ase_awk_tab_remove ( - &awk->parse.locals, nlocals, - ase_awk_tab_getsize(&awk->parse.locals)-nlocals); - if (head != ASE_NULL) ase_awk_clrpt (awk, head); - return ASE_NULL; - } - - /* remove unnecessary statements */ - if (nde->type == ASE_AWK_NDE_NULL || - (nde->type == ASE_AWK_NDE_BLK && - ((ase_awk_nde_blk_t*)nde)->body == ASE_NULL)) continue; - - if (curr == ASE_NULL) head = nde; - else curr->next = nde; - curr = nde; - } - - block = (ase_awk_nde_blk_t*) - ASE_AWK_MALLOC (awk, ASE_SIZEOF(ase_awk_nde_blk_t)); - if (block == ASE_NULL) - { - ase_awk_tab_remove ( - &awk->parse.locals, nlocals, - ase_awk_tab_getsize(&awk->parse.locals)-nlocals); - ase_awk_clrpt (awk, head); - - SETERRLIN (awk, ASE_AWK_ENOMEM, line); - return ASE_NULL; - } - - tmp = ase_awk_tab_getsize(&awk->parse.locals); - if (tmp > awk->parse.nlocals_max) awk->parse.nlocals_max = tmp; - - ase_awk_tab_remove ( - &awk->parse.locals, nlocals, tmp - nlocals); - - /* adjust the number of locals for a block without any statements */ - /* if (head == ASE_NULL) tmp = 0; */ - - block->type = ASE_AWK_NDE_BLK; - block->line = line; - block->next = ASE_NULL; - block->body = head; - -/* TODO: not only local variables but also nested blocks, -unless it is part of other constructs such as if, can be promoted -and merged to top-level block */ - - /* migrate all block-local variables to a top-level block */ - if (is_top) - { - block->nlocals = awk->parse.nlocals_max - nlocals; - awk->parse.nlocals_max = nlocals_max; - } - else - { - /*block->nlocals = tmp - nlocals;*/ - block->nlocals = 0; - } - - return (ase_awk_nde_t*)block; -} - -static ase_awk_nde_t* parse_block_dc ( - ase_awk_t* awk, ase_size_t line, ase_bool_t is_top) -{ - ase_awk_nde_t* nde; - - ASE_ASSERT (awk->parse.depth.max.block > 0); - - if (awk->parse.depth.cur.block >= awk->parse.depth.max.block) - { - SETERRLIN (awk, ASE_AWK_EBLKNST, awk->token.prev.line); - return ASE_NULL; - } - - awk->parse.depth.cur.block++; - nde = parse_block (awk, line, is_top); - awk->parse.depth.cur.block--; - - return nde; -} - -static ase_awk_t* add_builtin_globals (ase_awk_t* awk) -{ - global_t* p = gtab; - ase_awk_t* tmp; - - awk->tree.nbglobals = 0; - while (p->name != ASE_NULL) - { - - if (p->valid != 0 && (awk->option & p->valid) == 0) - { - /* an invalid global variable are still added - * to the global variable table with an empty name. - * this is to prevent the run-time from looking up - * the variable */ - tmp = add_global (awk, ASE_T(""), 0, 0, 1); - } - else - { - tmp = add_global (awk, p->name, p->name_len, 0, 0); - } - if (tmp == ASE_NULL) return ASE_NULL; - - awk->tree.nbglobals++; - p++; - } - - return awk; -} - -static ase_awk_t* add_global ( - ase_awk_t* awk, const ase_char_t* name, ase_size_t len, - ase_size_t line, int force) -{ - if (!force) - { - if (awk->option & ASE_AWK_UNIQUEFN) - { - /* check if it conflict with a builtin function name */ - if (ase_awk_getbfn (awk, name, len) != ASE_NULL) - { - SETERRARG ( - awk, ASE_AWK_EBFNRED, awk->token.line, - name, len); - - return ASE_NULL; - } - - /* check if it conflict with a function name */ - if (ase_awk_map_get ( - &awk->tree.afns, name, len) != ASE_NULL) - { - SETERRARG ( - awk, ASE_AWK_EAFNRED, line, - name, len); - - return ASE_NULL; - } - } - - /* check if it conflicts with other global variable names */ - if (ase_awk_tab_find ( - &awk->parse.globals, 0, name, len) != (ase_size_t)-1) - { - SETERRARG (awk, ASE_AWK_EDUPGBL, line, name, len); - return ASE_NULL; - } - } - - if (ase_awk_tab_getsize(&awk->parse.globals) >= ASE_AWK_MAX_GLOBALS) - { - SETERRLIN (awk, ASE_AWK_EGBLTM, line); - return ASE_NULL; - } - - if (ase_awk_tab_add (&awk->parse.globals, name, len) == (ase_size_t)-1) - { - SETERRLIN (awk, ASE_AWK_ENOMEM, line); - return ASE_NULL; - } - - return awk; -} - -static ase_awk_t* collect_globals (ase_awk_t* awk) -{ - while (1) - { - if (!MATCH(awk,TOKEN_IDENT)) - { - SETERRTOK (awk, ASE_AWK_EBADVAR); - return ASE_NULL; - } - - if (add_global ( - awk, - ASE_STR_BUF(&awk->token.name), - ASE_STR_LEN(&awk->token.name), - awk->token.line, - 0) == ASE_NULL) return ASE_NULL; - - if (get_token(awk) == -1) return ASE_NULL; - - if (MATCH(awk,TOKEN_SEMICOLON)) break; - - if (!MATCH(awk,TOKEN_COMMA)) - { - SETERRTOK (awk, ASE_AWK_ECOMMA); - return ASE_NULL; - } - - if (get_token(awk) == -1) return ASE_NULL; - } - - /* skip a semicolon */ - if (get_token(awk) == -1) return ASE_NULL; - - return awk; -} - -static ase_awk_t* collect_locals (ase_awk_t* awk, ase_size_t nlocals) -{ - ase_char_t* local; - ase_size_t local_len; - - while (1) - { - if (!MATCH(awk,TOKEN_IDENT)) - { - SETERRTOK (awk, ASE_AWK_EBADVAR); - return ASE_NULL; - } - - local = ASE_STR_BUF(&awk->token.name); - local_len = ASE_STR_LEN(&awk->token.name); - - /* NOTE: it is not checked againt globals names */ - - if (awk->option & ASE_AWK_UNIQUEFN) - { - /* check if it conflict with a builtin function name */ - if (ase_awk_getbfn (awk, local, local_len) != ASE_NULL) - { - SETERRARG ( - awk, ASE_AWK_EBFNRED, awk->token.line, - local, local_len); - return ASE_NULL; - } - - /* check if it conflict with a function name */ - if (ase_strxncmp ( - awk->tree.cur_afn.ptr, awk->tree.cur_afn.len, - local, local_len) == 0 || - ase_awk_map_get ( - &awk->tree.afns, local, local_len) != ASE_NULL) - { - SETERRARG ( - awk, ASE_AWK_EAFNRED, awk->token.line, - local, local_len); - return ASE_NULL; - } - } - - /* check if it conflicts with a paremeter name */ - if (ase_awk_tab_find (&awk->parse.params, - 0, local, local_len) != (ase_size_t)-1) - { - SETERRARG ( - awk, ASE_AWK_EPARRED, awk->token.line, - local, local_len); - return ASE_NULL; - } - - /* check if it conflicts with other local variable names */ - if (ase_awk_tab_find (&awk->parse.locals, - ((awk->option & ASE_AWK_SHADING)? nlocals: 0), - local, local_len) != (ase_size_t)-1) - { - SETERRARG ( - awk, ASE_AWK_EDUPLCL, awk->token.line, - local, local_len); - - return ASE_NULL; - } - - if (ase_awk_tab_getsize(&awk->parse.locals) >= ASE_AWK_MAX_LOCALS) - { - SETERRLIN (awk, ASE_AWK_ELCLTM, awk->token.line); - return ASE_NULL; - } - - if (ase_awk_tab_add ( - &awk->parse.locals, local, local_len) == (ase_size_t)-1) - { - SETERRLIN (awk, ASE_AWK_ENOMEM, awk->token.line); - return ASE_NULL; - } - - if (get_token(awk) == -1) return ASE_NULL; - - if (MATCH(awk,TOKEN_SEMICOLON)) break; - - if (!MATCH(awk,TOKEN_COMMA)) - { - SETERRTOK (awk, ASE_AWK_ECOMMA); - return ASE_NULL; - } - - if (get_token(awk) == -1) return ASE_NULL; - } - - /* skip a semicolon */ - if (get_token(awk) == -1) return ASE_NULL; - - return awk; -} - -static ase_awk_nde_t* parse_statement (ase_awk_t* awk, ase_size_t line) -{ - ase_awk_nde_t* nde; - - if (MATCH(awk,TOKEN_SEMICOLON)) - { - /* null statement */ - nde = (ase_awk_nde_t*) - ASE_AWK_MALLOC (awk, ASE_SIZEOF(ase_awk_nde_t)); - if (nde == ASE_NULL) - { - SETERRLIN (awk, ASE_AWK_ENOMEM, line); - return ASE_NULL; - } - - nde->type = ASE_AWK_NDE_NULL; - nde->line = line; - nde->next = ASE_NULL; - - if (get_token(awk) == -1) - { - ASE_AWK_FREE (awk, nde); - return ASE_NULL; - } - } - else if (MATCH(awk,TOKEN_LBRACE)) - { - if (get_token(awk) == -1) return ASE_NULL; - nde = awk->parse.parse_block ( - awk, awk->token.prev.line, ase_false); - } - else - { - /* the statement id held in awk->parse.id.stmnt denotes - * the token id of the statement currently being parsed. - * the current statement id is saved here because the - * statement id can be changed in parse_statement_nb. - * it will, in turn, call parse_statement which will - * eventually change the statement id. */ - int old_id = awk->parse.id.stmnt; - - /* set the current statement id */ - awk->parse.id.stmnt = awk->token.type; - - /* proceed parsing the statement */ - nde = parse_statement_nb (awk, line); - - /* restore the statement id saved previously */ - awk->parse.id.stmnt = old_id; - } - - return nde; -} - -static ase_awk_nde_t* parse_statement_nb (ase_awk_t* awk, ase_size_t line) -{ - ase_awk_nde_t* nde; - - /* keywords that don't require any terminating semicolon */ - if (MATCH(awk,TOKEN_IF)) - { - if (get_token(awk) == -1) return ASE_NULL; - return parse_if (awk, line); - } - else if (MATCH(awk,TOKEN_WHILE)) - { - if (get_token(awk) == -1) return ASE_NULL; - - awk->parse.depth.cur.loop++; - nde = parse_while (awk, line); - awk->parse.depth.cur.loop--; - - return nde; - } - else if (MATCH(awk,TOKEN_FOR)) - { - if (get_token(awk) == -1) return ASE_NULL; - - awk->parse.depth.cur.loop++; - nde = parse_for (awk, line); - awk->parse.depth.cur.loop--; - - return nde; - } - - /* keywords that require a terminating semicolon */ - if (MATCH(awk,TOKEN_DO)) - { - if (get_token(awk) == -1) return ASE_NULL; - - awk->parse.depth.cur.loop++; - nde = parse_dowhile (awk, line); - awk->parse.depth.cur.loop--; - - return nde; - } - else if (MATCH(awk,TOKEN_BREAK)) - { - if (get_token(awk) == -1) return ASE_NULL; - nde = parse_break (awk, line); - } - else if (MATCH(awk,TOKEN_CONTINUE)) - { - if (get_token(awk) == -1) return ASE_NULL; - nde = parse_continue (awk, line); - } - else if (MATCH(awk,TOKEN_RETURN)) - { - if (get_token(awk) == -1) return ASE_NULL; - nde = parse_return (awk, line); - } - else if (MATCH(awk,TOKEN_EXIT)) - { - if (get_token(awk) == -1) return ASE_NULL; - nde = parse_exit (awk, line); - } - else if (MATCH(awk,TOKEN_NEXT)) - { - if (get_token(awk) == -1) return ASE_NULL; - nde = parse_next (awk, line); - } - else if (MATCH(awk,TOKEN_NEXTFILE)) - { - if (get_token(awk) == -1) return ASE_NULL; - nde = parse_nextfile (awk, line, 0); - } - else if (MATCH(awk,TOKEN_NEXTOFILE)) - { - if (get_token(awk) == -1) return ASE_NULL; - nde = parse_nextfile (awk, line, 1); - } - else if (MATCH(awk,TOKEN_DELETE)) - { - if (get_token(awk) == -1) return ASE_NULL; - nde = parse_delete (awk, line); - } - else if (MATCH(awk,TOKEN_PRINT)) - { - if (get_token(awk) == -1) return ASE_NULL; - nde = parse_print (awk, line, ASE_AWK_NDE_PRINT); - } - else if (MATCH(awk,TOKEN_PRINTF)) - { - if (get_token(awk) == -1) return ASE_NULL; - nde = parse_print (awk, line, ASE_AWK_NDE_PRINTF); - } - else - { - nde = parse_expression (awk, line); - } - - if (nde == ASE_NULL) return ASE_NULL; - - /* check if a statement ends with a semicolon */ - if (!MATCH(awk,TOKEN_SEMICOLON)) - { - if (nde != ASE_NULL) ase_awk_clrpt (awk, nde); - - SETERRLIN (awk, ASE_AWK_ESTMEND, awk->token.prev.line); - return ASE_NULL; - } - - /* eat up the semicolon and read in the next token */ - if (get_token(awk) == -1) - { - if (nde != ASE_NULL) ase_awk_clrpt (awk, nde); - return ASE_NULL; - } - - return nde; -} - -static ase_awk_nde_t* parse_expression (ase_awk_t* awk, ase_size_t line) -{ - ase_awk_nde_t* nde; - - if (awk->parse.depth.max.expr > 0 && - awk->parse.depth.cur.expr >= awk->parse.depth.max.expr) - { - SETERRLIN (awk, ASE_AWK_EEXPRNST, line); - return ASE_NULL; - } - - awk->parse.depth.cur.expr++; - nde = parse_expression0 (awk, line); - awk->parse.depth.cur.expr--; - - return nde; -} - -static ase_awk_nde_t* parse_expression0 (ase_awk_t* awk, ase_size_t line) -{ - ase_awk_nde_t* x, * y; - ase_awk_nde_ass_t* nde; - int opcode; - - x = parse_basic_expr (awk, line); - if (x == ASE_NULL) return ASE_NULL; - - opcode = assign_to_opcode (awk); - if (opcode == -1) - { - /* no assignment operator found. */ - return x; - } - - ASE_ASSERT (x->next == ASE_NULL); - if (!is_var(x) && x->type != ASE_AWK_NDE_POS) - { - ase_awk_clrpt (awk, x); - SETERRLIN (awk, ASE_AWK_EASSIGN, line); - return ASE_NULL; - } - - if (get_token(awk) == -1) - { - ase_awk_clrpt (awk, x); - return ASE_NULL; - } - - /*y = parse_basic_expr (awk);*/ - y = parse_expression (awk, awk->token.line); - if (y == ASE_NULL) - { - ase_awk_clrpt (awk, x); - return ASE_NULL; - } - - nde = (ase_awk_nde_ass_t*) - ASE_AWK_MALLOC (awk, ASE_SIZEOF(ase_awk_nde_ass_t)); - if (nde == ASE_NULL) - { - ase_awk_clrpt (awk, x); - ase_awk_clrpt (awk, y); - - SETERRLIN (awk, ASE_AWK_ENOMEM, line); - return ASE_NULL; - } - - nde->type = ASE_AWK_NDE_ASS; - nde->line = line; - nde->next = ASE_NULL; - nde->opcode = opcode; - nde->left = x; - nde->right = y; - - return (ase_awk_nde_t*)nde; -} - -static ase_awk_nde_t* parse_basic_expr (ase_awk_t* awk, ase_size_t line) -{ - ase_awk_nde_t* nde, * n1, * n2; - - nde = parse_logical_or (awk, line); - if (nde == ASE_NULL) return ASE_NULL; - - if (MATCH(awk,TOKEN_QUEST)) - { - ase_awk_nde_cnd_t* tmp; - - if (get_token(awk) == -1) return ASE_NULL; - - /*n1 = parse_basic_expr (awk, awk->token.line);*/ - n1 = parse_expression (awk, awk->token.line); - if (n1 == ASE_NULL) - { - ase_awk_clrpt (awk, nde); - return ASE_NULL; - } - - if (!MATCH(awk,TOKEN_COLON)) - { - SETERRTOK (awk, ASE_AWK_ECOLON); - return ASE_NULL; - } - if (get_token(awk) == -1) return ASE_NULL; - - /*n2 = parse_basic_expr (awk, awk->token.line);*/ - n2 = parse_expression (awk, awk->token.line); - if (n2 == ASE_NULL) - { - ase_awk_clrpt (awk, nde); - ase_awk_clrpt (awk, n1); - return ASE_NULL; - } - - tmp = (ase_awk_nde_cnd_t*) ASE_AWK_MALLOC ( - awk, ASE_SIZEOF(ase_awk_nde_cnd_t)); - if (tmp == ASE_NULL) - { - ase_awk_clrpt (awk, nde); - ase_awk_clrpt (awk, n1); - ase_awk_clrpt (awk, n2); - - SETERRLIN (awk, ASE_AWK_ENOMEM, line); - return ASE_NULL; - } - - tmp->type = ASE_AWK_NDE_CND; - tmp->line = line; - tmp->next = ASE_NULL; - tmp->test = nde; - tmp->left = n1; - tmp->right = n2; - - nde = (ase_awk_nde_t*)tmp; - } - - return nde; -} - -static ase_awk_nde_t* parse_binary_expr ( - ase_awk_t* awk, ase_size_t line, const binmap_t* binmap, - ase_awk_nde_t*(*next_level_func)(ase_awk_t*,ase_size_t)) -{ - ase_awk_nde_exp_t* nde; - ase_awk_nde_t* left, * right; - int opcode; - - left = next_level_func (awk, line); - if (left == ASE_NULL) return ASE_NULL; - - while (1) - { - const binmap_t* p = binmap; - ase_bool_t matched = ase_false; - - while (p->token != TOKEN_EOF) - { - if (MATCH(awk,p->token)) - { - opcode = p->binop; - matched = ase_true; - break; - } - p++; - } - if (!matched) break; - - if (get_token(awk) == -1) - { - ase_awk_clrpt (awk, left); - return ASE_NULL; - } - - right = next_level_func (awk, awk->token.line); - if (right == ASE_NULL) - { - ase_awk_clrpt (awk, left); - return ASE_NULL; - } - - nde = (ase_awk_nde_exp_t*) ASE_AWK_MALLOC ( - awk, ASE_SIZEOF(ase_awk_nde_exp_t)); - if (nde == ASE_NULL) - { - ase_awk_clrpt (awk, right); - ase_awk_clrpt (awk, left); - - SETERRLIN (awk, ASE_AWK_ENOMEM, line); - return ASE_NULL; - } - - nde->type = ASE_AWK_NDE_EXP_BIN; - nde->line = line; - nde->next = ASE_NULL; - nde->opcode = opcode; - nde->left = left; - nde->right = right; - - left = (ase_awk_nde_t*)nde; - } - - return left; -} - -static ase_awk_nde_t* parse_logical_or (ase_awk_t* awk, ase_size_t line) -{ - static binmap_t map[] = - { - { TOKEN_LOR, ASE_AWK_BINOP_LOR }, - { TOKEN_EOF, 0 } - }; - - return parse_binary_expr (awk, line, map, parse_logical_and); -} - -static ase_awk_nde_t* parse_logical_and (ase_awk_t* awk, ase_size_t line) -{ - static binmap_t map[] = - { - { TOKEN_LAND, ASE_AWK_BINOP_LAND }, - { TOKEN_EOF, 0 } - }; - - return parse_binary_expr (awk, line, map, parse_in); -} - -static ase_awk_nde_t* parse_in (ase_awk_t* awk, ase_size_t line) -{ - /* - static binmap_t map[] = - { - { TOKEN_IN, ASE_AWK_BINOP_IN }, - { TOKEN_EOF, 0 } - }; - - return parse_binary_expr (awk, line, map, parse_regex_match); - */ - - ase_awk_nde_exp_t* nde; - ase_awk_nde_t* left, * right; - ase_size_t line2; - - left = parse_regex_match (awk, line); - if (left == ASE_NULL) return ASE_NULL; - - while (1) - { - if (!MATCH(awk,TOKEN_IN)) break; - - if (get_token(awk) == -1) - { - ase_awk_clrpt (awk, left); - return ASE_NULL; - } - - line2 = awk->token.line; - - right = parse_regex_match (awk, line2); - if (right == ASE_NULL) - { - ase_awk_clrpt (awk, left); - return ASE_NULL; - } - - if (!is_plain_var(right)) - { - ase_awk_clrpt (awk, right); - ase_awk_clrpt (awk, left); - - SETERRLIN (awk, ASE_AWK_ENOTVAR, line2); - return ASE_NULL; - } - - nde = (ase_awk_nde_exp_t*) ASE_AWK_MALLOC ( - awk, ASE_SIZEOF(ase_awk_nde_exp_t)); - if (nde == ASE_NULL) - { - ase_awk_clrpt (awk, right); - ase_awk_clrpt (awk, left); - - SETERRLIN (awk, ASE_AWK_ENOMEM, line); - return ASE_NULL; - } - - nde->type = ASE_AWK_NDE_EXP_BIN; - nde->line = line; - nde->next = ASE_NULL; - nde->opcode = ASE_AWK_BINOP_IN; - nde->left = left; - nde->right = right; - - left = (ase_awk_nde_t*)nde; - } - - return left; -} - -static ase_awk_nde_t* parse_regex_match (ase_awk_t* awk, ase_size_t line) -{ - static binmap_t map[] = - { - { TOKEN_TILDE, ASE_AWK_BINOP_MA }, - { TOKEN_NM, ASE_AWK_BINOP_NM }, - { TOKEN_EOF, 0 }, - }; - - return parse_binary_expr (awk, line, map, parse_bitwise_or); -} - -static ase_awk_nde_t* parse_bitwise_or (ase_awk_t* awk, ase_size_t line) -{ - if (awk->option & ASE_AWK_EXTIO) - { - return parse_bitwise_or_with_extio (awk, line); - } - else - { - static binmap_t map[] = - { - { TOKEN_BOR, ASE_AWK_BINOP_BOR }, - { TOKEN_EOF, 0 } - }; - - return parse_binary_expr ( - awk, line, map, parse_bitwise_xor); - } -} - -static ase_awk_nde_t* parse_bitwise_or_with_extio (ase_awk_t* awk, ase_size_t line) -{ - ase_awk_nde_t* left, * right; - - left = parse_bitwise_xor (awk, line); - if (left == ASE_NULL) return ASE_NULL; - - while (1) - { - int in_type; - - if (MATCH(awk,TOKEN_BOR)) - in_type = ASE_AWK_IN_PIPE; - else if (MATCH(awk,TOKEN_BORAND)) - in_type = ASE_AWK_IN_COPROC; - else break; - - if (get_token(awk) == -1) - { - ase_awk_clrpt (awk, left); - return ASE_NULL; - } - - if (MATCH(awk,TOKEN_GETLINE)) - { - ase_awk_nde_getline_t* nde; - ase_awk_nde_t* var = ASE_NULL; - - /* piped getline */ - if (get_token(awk) == -1) - { - ase_awk_clrpt (awk, left); - return ASE_NULL; - } - - /* TODO: is this correct? */ - - if (MATCH(awk,TOKEN_IDENT)) - { - /* command | getline var */ - - var = parse_primary (awk, awk->token.line); - if (var == ASE_NULL) - { - ase_awk_clrpt (awk, left); - return ASE_NULL; - } - } - - nde = (ase_awk_nde_getline_t*) ASE_AWK_MALLOC ( - awk, ASE_SIZEOF(ase_awk_nde_getline_t)); - if (nde == ASE_NULL) - { - ase_awk_clrpt (awk, left); - - SETERRLIN (awk, ASE_AWK_ENOMEM, line); - return ASE_NULL; - } - - nde->type = ASE_AWK_NDE_GETLINE; - nde->line = line; - nde->next = ASE_NULL; - nde->var = var; - nde->in_type = in_type; - nde->in = left; - - left = (ase_awk_nde_t*)nde; - } - else - { - ase_awk_nde_exp_t* nde; - - if (in_type == ASE_AWK_IN_COPROC) - { - ase_awk_clrpt (awk, left); - - /* TODO: support coprocess */ - SETERRLIN (awk, ASE_AWK_EGLNCPS, line); - return ASE_NULL; - } - - right = parse_bitwise_xor (awk, awk->token.line); - if (right == ASE_NULL) - { - ase_awk_clrpt (awk, left); - return ASE_NULL; - } - - nde = (ase_awk_nde_exp_t*) ASE_AWK_MALLOC ( - awk, ASE_SIZEOF(ase_awk_nde_exp_t)); - if (nde == ASE_NULL) - { - ase_awk_clrpt (awk, right); - ase_awk_clrpt (awk, left); - - SETERRLIN (awk, ASE_AWK_ENOMEM, line); - return ASE_NULL; - } - - nde->type = ASE_AWK_NDE_EXP_BIN; - nde->line = line; - nde->next = ASE_NULL; - nde->opcode = ASE_AWK_BINOP_BOR; - nde->left = left; - nde->right = right; - - left = (ase_awk_nde_t*)nde; - } - } - - return left; -} - -static ase_awk_nde_t* parse_bitwise_xor (ase_awk_t* awk, ase_size_t line) -{ - static binmap_t map[] = - { - { TOKEN_BXOR, ASE_AWK_BINOP_BXOR }, - { TOKEN_EOF, 0 } - }; - - return parse_binary_expr (awk, line, map, parse_bitwise_and); -} - -static ase_awk_nde_t* parse_bitwise_and (ase_awk_t* awk, ase_size_t line) -{ - static binmap_t map[] = - { - { TOKEN_BAND, ASE_AWK_BINOP_BAND }, - { TOKEN_EOF, 0 } - }; - - return parse_binary_expr (awk, line, map, parse_equality); -} - -static ase_awk_nde_t* parse_equality (ase_awk_t* awk, ase_size_t line) -{ - static binmap_t map[] = - { - { TOKEN_EQ, ASE_AWK_BINOP_EQ }, - { TOKEN_NE, ASE_AWK_BINOP_NE }, - { TOKEN_EOF, 0 } - }; - - return parse_binary_expr (awk, line, map, parse_relational); -} - -static ase_awk_nde_t* parse_relational (ase_awk_t* awk, ase_size_t line) -{ - static binmap_t map[] = - { - { TOKEN_GT, ASE_AWK_BINOP_GT }, - { TOKEN_GE, ASE_AWK_BINOP_GE }, - { TOKEN_LT, ASE_AWK_BINOP_LT }, - { TOKEN_LE, ASE_AWK_BINOP_LE }, - { TOKEN_EOF, 0 } - }; - - return parse_binary_expr (awk, line, map, parse_shift); -} - -static ase_awk_nde_t* parse_shift (ase_awk_t* awk, ase_size_t line) -{ - static binmap_t map[] = - { - { TOKEN_LSHIFT, ASE_AWK_BINOP_LSHIFT }, - { TOKEN_RSHIFT, ASE_AWK_BINOP_RSHIFT }, - { TOKEN_EOF, 0 } - }; - - return parse_binary_expr (awk, line, map, parse_concat); -} - -static ase_awk_nde_t* parse_concat (ase_awk_t* awk, ase_size_t line) -{ - ase_awk_nde_exp_t* nde; - ase_awk_nde_t* left, * right; - - left = parse_additive (awk, line); - if (left == ASE_NULL) return ASE_NULL; - - while (1) - { - if (MATCH(awk,TOKEN_PERIOD)) - { - if ((awk->option & ASE_AWK_EXPLICIT) == 0) break; - if (get_token(awk) == -1) return ASE_NULL; - } - else if (MATCH(awk,TOKEN_LPAREN) || - MATCH(awk,TOKEN_DOLLAR) || - awk->token.type >= TOKEN_GETLINE) - { - /* TODO: is the check above sufficient? */ - if ((awk->option & ASE_AWK_IMPLICIT) == 0) break; - } - else break; - - right = parse_additive (awk, awk->token.line); - if (right == ASE_NULL) - { - ase_awk_clrpt (awk, left); - return ASE_NULL; - } - - nde = (ase_awk_nde_exp_t*) ASE_AWK_MALLOC ( - awk, ASE_SIZEOF(ase_awk_nde_exp_t)); - if (nde == ASE_NULL) - { - ase_awk_clrpt (awk, left); - ase_awk_clrpt (awk, right); - - SETERRLIN (awk, ASE_AWK_ENOMEM, line); - return ASE_NULL; - } - - nde->type = ASE_AWK_NDE_EXP_BIN; - nde->line = line; - nde->next = ASE_NULL; - nde->opcode = ASE_AWK_BINOP_CONCAT; - nde->left = left; - nde->right = right; - - left = (ase_awk_nde_t*)nde; - } - - return left; -} - -static ase_awk_nde_t* parse_additive (ase_awk_t* awk, ase_size_t line) -{ - static binmap_t map[] = - { - { TOKEN_PLUS, ASE_AWK_BINOP_PLUS }, - { TOKEN_MINUS, ASE_AWK_BINOP_MINUS }, - { TOKEN_EOF, 0 } - }; - - return parse_binary_expr (awk, line, map, parse_multiplicative); -} - -static ase_awk_nde_t* parse_multiplicative (ase_awk_t* awk, ase_size_t line) -{ - static binmap_t map[] = - { - { TOKEN_MUL, ASE_AWK_BINOP_MUL }, - { TOKEN_DIV, ASE_AWK_BINOP_DIV }, - { TOKEN_IDIV, ASE_AWK_BINOP_IDIV }, - { TOKEN_MOD, ASE_AWK_BINOP_MOD }, - /* { TOKEN_EXP, ASE_AWK_BINOP_EXP }, */ - { TOKEN_EOF, 0 } - }; - - return parse_binary_expr (awk, line, map, parse_unary); -} - -static ase_awk_nde_t* parse_unary (ase_awk_t* awk, ase_size_t line) -{ - ase_awk_nde_exp_t* nde; - ase_awk_nde_t* left; - int opcode; - - opcode = (MATCH(awk,TOKEN_PLUS))? ASE_AWK_UNROP_PLUS: - (MATCH(awk,TOKEN_MINUS))? ASE_AWK_UNROP_MINUS: - (MATCH(awk,TOKEN_NOT))? ASE_AWK_UNROP_NOT: - (MATCH(awk,TOKEN_TILDE))? ASE_AWK_UNROP_BNOT: -1; - - /*if (opcode == -1) return parse_increment (awk);*/ - if (opcode == -1) return parse_exponent (awk, line); - - if (get_token(awk) == -1) return ASE_NULL; - - if (awk->parse.depth.max.expr > 0 && - awk->parse.depth.cur.expr >= awk->parse.depth.max.expr) - { - SETERRLIN (awk, ASE_AWK_EEXPRNST, awk->token.line); - return ASE_NULL; - } - awk->parse.depth.cur.expr++; - left = parse_unary (awk, awk->token.line); - awk->parse.depth.cur.expr--; - if (left == ASE_NULL) return ASE_NULL; - - nde = (ase_awk_nde_exp_t*) - ASE_AWK_MALLOC (awk, ASE_SIZEOF(ase_awk_nde_exp_t)); - if (nde == ASE_NULL) - { - ase_awk_clrpt (awk, left); - - SETERRLIN (awk, ASE_AWK_ENOMEM, line); - return ASE_NULL; - } - - nde->type = ASE_AWK_NDE_EXP_UNR; - nde->line = line; - nde->next = ASE_NULL; - nde->opcode = opcode; - nde->left = left; - nde->right = ASE_NULL; - - return (ase_awk_nde_t*)nde; -} - -static ase_awk_nde_t* parse_exponent (ase_awk_t* awk, ase_size_t line) -{ - static binmap_t map[] = - { - { TOKEN_EXP, ASE_AWK_BINOP_EXP }, - { TOKEN_EOF, 0 } - }; - - return parse_binary_expr (awk, line, map, parse_unary_exp); -} - -static ase_awk_nde_t* parse_unary_exp (ase_awk_t* awk, ase_size_t line) -{ - ase_awk_nde_exp_t* nde; - ase_awk_nde_t* left; - int opcode; - - opcode = (MATCH(awk,TOKEN_PLUS))? ASE_AWK_UNROP_PLUS: - (MATCH(awk,TOKEN_MINUS))? ASE_AWK_UNROP_MINUS: - (MATCH(awk,TOKEN_NOT))? ASE_AWK_UNROP_NOT: - (MATCH(awk,TOKEN_TILDE))? ASE_AWK_UNROP_BNOT: -1; - - if (opcode == -1) return parse_increment (awk, line); - - if (get_token(awk) == -1) return ASE_NULL; - - if (awk->parse.depth.max.expr > 0 && - awk->parse.depth.cur.expr >= awk->parse.depth.max.expr) - { - SETERRLIN (awk, ASE_AWK_EEXPRNST, awk->token.line); - return ASE_NULL; - } - awk->parse.depth.cur.expr++; - left = parse_unary (awk, awk->token.line); - awk->parse.depth.cur.expr--; - if (left == ASE_NULL) return ASE_NULL; - - nde = (ase_awk_nde_exp_t*) - ASE_AWK_MALLOC (awk, ASE_SIZEOF(ase_awk_nde_exp_t)); - if (nde == ASE_NULL) - { - ase_awk_clrpt (awk, left); - - SETERRLIN (awk, ASE_AWK_ENOMEM, line); - return ASE_NULL; - } - - nde->type = ASE_AWK_NDE_EXP_UNR; - nde->line = line; - nde->next = ASE_NULL; - nde->opcode = opcode; - nde->left = left; - nde->right = ASE_NULL; - - return (ase_awk_nde_t*)nde; -} - -static ase_awk_nde_t* parse_increment (ase_awk_t* awk, ase_size_t line) -{ - ase_awk_nde_exp_t* nde; - ase_awk_nde_t* left; - int type, opcode, opcode1, opcode2; - - /* check for prefix increment operator */ - opcode1 = MATCH(awk,TOKEN_PLUSPLUS)? ASE_AWK_INCOP_PLUS: - MATCH(awk,TOKEN_MINUSMINUS)? ASE_AWK_INCOP_MINUS: -1; - - if (opcode1 != -1) - { - if (get_token(awk) == -1) return ASE_NULL; - } - - left = parse_primary (awk, line); - if (left == ASE_NULL) return ASE_NULL; - - /* check for postfix increment operator */ - opcode2 = MATCH(awk,TOKEN_PLUSPLUS)? ASE_AWK_INCOP_PLUS: - MATCH(awk,TOKEN_MINUSMINUS)? ASE_AWK_INCOP_MINUS: -1; - - if (opcode1 != -1 && opcode2 != -1) - { - /* both prefix and postfix increment operator. - * not allowed */ - ase_awk_clrpt (awk, left); - - SETERRLIN (awk, ASE_AWK_EPREPST, line); - return ASE_NULL; - } - else if (opcode1 == -1 && opcode2 == -1) - { - /* no increment operators */ - return left; - } - else if (opcode1 != -1) - { - /* prefix increment operator */ - type = ASE_AWK_NDE_EXP_INCPRE; - opcode = opcode1; - } - else if (opcode2 != -1) - { - /* postfix increment operator */ - type = ASE_AWK_NDE_EXP_INCPST; - opcode = opcode2; - - if (get_token(awk) == -1) return ASE_NULL; - } - - nde = (ase_awk_nde_exp_t*) - ASE_AWK_MALLOC (awk, ASE_SIZEOF(ase_awk_nde_exp_t)); - if (nde == ASE_NULL) - { - ase_awk_clrpt (awk, left); - - SETERRLIN (awk, ASE_AWK_ENOMEM, line); - return ASE_NULL; - } - - nde->type = type; - nde->line = line; - nde->next = ASE_NULL; - nde->opcode = opcode; - nde->left = left; - nde->right = ASE_NULL; - - return (ase_awk_nde_t*)nde; -} - -static ase_awk_nde_t* parse_primary (ase_awk_t* awk, ase_size_t line) -{ - if (MATCH(awk,TOKEN_IDENT)) - { - return parse_primary_ident (awk, line); - } - else if (MATCH(awk,TOKEN_INT)) - { - ase_awk_nde_int_t* nde; - - nde = (ase_awk_nde_int_t*) ASE_AWK_MALLOC ( - awk, ASE_SIZEOF(ase_awk_nde_int_t)); - if (nde == ASE_NULL) - { - SETERRLIN (awk, ASE_AWK_ENOMEM, line); - return ASE_NULL; - } - - nde->type = ASE_AWK_NDE_INT; - nde->line = line; - nde->next = ASE_NULL; - nde->val = ase_awk_strxtolong (awk, - ASE_STR_BUF(&awk->token.name), - ASE_STR_LEN(&awk->token.name), 0, ASE_NULL); - nde->str = ase_strxdup ( - ASE_STR_BUF(&awk->token.name), - ASE_STR_LEN(&awk->token.name), - &awk->prmfns.mmgr); - if (nde->str == ASE_NULL) - { - ASE_AWK_FREE (awk, nde); - return ASE_NULL; - } - nde->len = ASE_STR_LEN(&awk->token.name); - - ASE_ASSERT ( - ASE_STR_LEN(&awk->token.name) == - ase_strlen(ASE_STR_BUF(&awk->token.name))); - - if (get_token(awk) == -1) - { - ASE_AWK_FREE (awk, nde->str); - ASE_AWK_FREE (awk, nde); - return ASE_NULL; - } - - return (ase_awk_nde_t*)nde; - } - else if (MATCH(awk,TOKEN_REAL)) - { - ase_awk_nde_real_t* nde; - - nde = (ase_awk_nde_real_t*) ASE_AWK_MALLOC ( - awk, ASE_SIZEOF(ase_awk_nde_real_t)); - if (nde == ASE_NULL) - { - SETERRLIN (awk, ASE_AWK_ENOMEM, line); - return ASE_NULL; - } - - nde->type = ASE_AWK_NDE_REAL; - nde->line = line; - nde->next = ASE_NULL; - nde->val = ase_awk_strxtoreal (awk, - ASE_STR_BUF(&awk->token.name), - ASE_STR_LEN(&awk->token.name), ASE_NULL); - nde->str = ase_strxdup ( - ASE_STR_BUF(&awk->token.name), - ASE_STR_LEN(&awk->token.name), - &awk->prmfns.mmgr); - if (nde->str == ASE_NULL) - { - ASE_AWK_FREE (awk, nde); - return ASE_NULL; - } - nde->len = ASE_STR_LEN(&awk->token.name); - - ASE_ASSERT ( - ASE_STR_LEN(&awk->token.name) == - ase_strlen(ASE_STR_BUF(&awk->token.name))); - - if (get_token(awk) == -1) - { - ASE_AWK_FREE (awk, nde->str); - ASE_AWK_FREE (awk, nde); - return ASE_NULL; - } - - return (ase_awk_nde_t*)nde; - } - else if (MATCH(awk,TOKEN_STR)) - { - ase_awk_nde_str_t* nde; - - nde = (ase_awk_nde_str_t*) ASE_AWK_MALLOC ( - awk, ASE_SIZEOF(ase_awk_nde_str_t)); - if (nde == ASE_NULL) - { - SETERRLIN (awk, ASE_AWK_ENOMEM, line); - return ASE_NULL; - } - - nde->type = ASE_AWK_NDE_STR; - nde->line = line; - nde->next = ASE_NULL; - nde->len = ASE_STR_LEN(&awk->token.name); - nde->buf = ase_strxdup ( - ASE_STR_BUF(&awk->token.name), - nde->len, - &awk->prmfns.mmgr); - if (nde->buf == ASE_NULL) - { - ASE_AWK_FREE (awk, nde); - SETERRLIN (awk, ASE_AWK_ENOMEM, line); - return ASE_NULL; - } - - if (get_token(awk) == -1) - { - ASE_AWK_FREE (awk, nde->buf); - ASE_AWK_FREE (awk, nde); - return ASE_NULL; - } - - return (ase_awk_nde_t*)nde; - } - else if (MATCH(awk,TOKEN_DIV)) - { - ase_awk_nde_rex_t* nde; - int errnum; - - /* the regular expression is tokenized here because - * of the context-sensitivity of the slash symbol */ - SET_TOKEN_TYPE (awk, TOKEN_REX); - - ase_str_clear (&awk->token.name); - if (get_rexstr (awk) == -1) return ASE_NULL; - ASE_ASSERT (MATCH(awk,TOKEN_REX)); - - nde = (ase_awk_nde_rex_t*) ASE_AWK_MALLOC ( - awk, ASE_SIZEOF(ase_awk_nde_rex_t)); - if (nde == ASE_NULL) - { - SETERRLIN (awk, ASE_AWK_ENOMEM, line); - return ASE_NULL; - } - - nde->type = ASE_AWK_NDE_REX; - nde->line = line; - nde->next = ASE_NULL; - - nde->len = ASE_STR_LEN(&awk->token.name); - nde->buf = ase_strxdup ( - ASE_STR_BUF(&awk->token.name), - ASE_STR_LEN(&awk->token.name), - &awk->prmfns.mmgr); - if (nde->buf == ASE_NULL) - { - ASE_AWK_FREE (awk, nde); - SETERRLIN (awk, ASE_AWK_ENOMEM, line); - return ASE_NULL; - } - - nde->code = ase_awk_buildrex (awk, - ASE_STR_BUF(&awk->token.name), - ASE_STR_LEN(&awk->token.name), - &errnum); - if (nde->code == ASE_NULL) - { - ASE_AWK_FREE (awk, nde->buf); - ASE_AWK_FREE (awk, nde); - - SETERRLIN (awk, errnum, line); - return ASE_NULL; - } - - if (get_token(awk) == -1) - { - ASE_AWK_FREE (awk, nde->buf); - ASE_AWK_FREE (awk, nde->code); - ASE_AWK_FREE (awk, nde); - return ASE_NULL; - } - - return (ase_awk_nde_t*)nde; - } - else if (MATCH(awk,TOKEN_DOLLAR)) - { - ase_awk_nde_pos_t* nde; - ase_awk_nde_t* prim; - - if (get_token(awk)) return ASE_NULL; - - prim = parse_primary (awk, awk->token.line); - if (prim == ASE_NULL) return ASE_NULL; - - nde = (ase_awk_nde_pos_t*) ASE_AWK_MALLOC ( - awk, ASE_SIZEOF(ase_awk_nde_pos_t)); - if (nde == ASE_NULL) - { - ase_awk_clrpt (awk, prim); - SETERRLIN (awk, ASE_AWK_ENOMEM, line); - return ASE_NULL; - } - - nde->type = ASE_AWK_NDE_POS; - nde->line = line; - nde->next = ASE_NULL; - nde->val = prim; - - return (ase_awk_nde_t*)nde; - } - else if (MATCH(awk,TOKEN_LPAREN)) - { - ase_awk_nde_t* nde; - ase_awk_nde_t* last; - - /* eat up the left parenthesis */ - if (get_token(awk) == -1) return ASE_NULL; - - /* parse the sub-expression inside the parentheses */ - nde = parse_expression (awk, awk->token.line); - if (nde == ASE_NULL) return ASE_NULL; - - /* parse subsequent expressions separated by a comma, if any */ - last = nde; - ASE_ASSERT (last->next == ASE_NULL); - - while (MATCH(awk,TOKEN_COMMA)) - { - ase_awk_nde_t* tmp; - - if (get_token(awk) == -1) - { - ase_awk_clrpt (awk, nde); - return ASE_NULL; - } - - tmp = parse_expression (awk, awk->token.line); - if (tmp == ASE_NULL) - { - ase_awk_clrpt (awk, nde); - return ASE_NULL; - } - - ASE_ASSERT (tmp->next == ASE_NULL); - last->next = tmp; - last = tmp; - } - /* ----------------- */ - - /* check for the closing parenthesis */ - if (!MATCH(awk,TOKEN_RPAREN)) - { - ase_awk_clrpt (awk, nde); - - SETERRTOK (awk, ASE_AWK_ERPAREN); - return ASE_NULL; - } - - if (get_token(awk) == -1) - { - ase_awk_clrpt (awk, nde); - return ASE_NULL; - } - - /* check if it is a chained node */ - if (nde->next != ASE_NULL) - { - /* if so, it is a expression group */ - /* (expr1, expr2, expr2) */ - - ase_awk_nde_grp_t* tmp; - - if ((awk->parse.id.stmnt != TOKEN_PRINT && - awk->parse.id.stmnt != TOKEN_PRINTF) || - awk->parse.depth.cur.expr != 1) - { - if (!MATCH(awk,TOKEN_IN)) - { - ase_awk_clrpt (awk, nde); - - SETERRTOK (awk, ASE_AWK_EIN); - return ASE_NULL; - } - } - - tmp = (ase_awk_nde_grp_t*) ASE_AWK_MALLOC ( - awk, ASE_SIZEOF(ase_awk_nde_grp_t)); - if (tmp == ASE_NULL) - { - ase_awk_clrpt (awk, nde); - SETERRLIN (awk, ASE_AWK_ENOMEM, line); - return ASE_NULL; - } - - tmp->type = ASE_AWK_NDE_GRP; - tmp->line = line; - tmp->next = ASE_NULL; - tmp->body = nde; - - nde = (ase_awk_nde_t*)tmp; - } - /* ----------------- */ - - return nde; - } - else if (MATCH(awk,TOKEN_GETLINE)) - { - ase_awk_nde_getline_t* nde; - ase_awk_nde_t* var = ASE_NULL; - ase_awk_nde_t* in = ASE_NULL; - - if (get_token(awk) == -1) return ASE_NULL; - - if (MATCH(awk,TOKEN_IDENT)) - { - /* getline var */ - var = parse_primary (awk, awk->token.line); - if (var == ASE_NULL) return ASE_NULL; - } - - if (MATCH(awk, TOKEN_LT)) - { - /* getline [var] < file */ - if (get_token(awk) == -1) - { - if (var != ASE_NULL) ase_awk_clrpt (awk, var); - return ASE_NULL; - } - - /* TODO: is this correct? */ - /*in = parse_expression (awk);*/ - in = parse_primary (awk, awk->token.line); - if (in == ASE_NULL) - { - if (var != ASE_NULL) ase_awk_clrpt (awk, var); - return ASE_NULL; - } - } - - nde = (ase_awk_nde_getline_t*) ASE_AWK_MALLOC ( - awk, ASE_SIZEOF(ase_awk_nde_getline_t)); - if (nde == ASE_NULL) - { - if (var != ASE_NULL) ase_awk_clrpt (awk, var); - if (in != ASE_NULL) ase_awk_clrpt (awk, in); - SETERRLIN (awk, ASE_AWK_ENOMEM, line); - return ASE_NULL; - } - - nde->type = ASE_AWK_NDE_GETLINE; - nde->line = line; - nde->next = ASE_NULL; - nde->var = var; - nde->in_type = (in == ASE_NULL)? - ASE_AWK_IN_CONSOLE: ASE_AWK_IN_FILE; - nde->in = in; - - return (ase_awk_nde_t*)nde; - } - - /* valid expression introducer is expected */ - SETERRLIN (awk, ASE_AWK_EEXPRES, - (MATCH(awk,TOKEN_EOF)? awk->token.prev.line: line)); - return ASE_NULL; -} - -static ase_awk_nde_t* parse_primary_ident (ase_awk_t* awk, ase_size_t line) -{ - ase_char_t* name_dup; - ase_size_t name_len; - ase_awk_bfn_t* bfn; - - ASE_ASSERT (MATCH(awk,TOKEN_IDENT)); - - name_dup = ase_strxdup ( - ASE_STR_BUF(&awk->token.name), - ASE_STR_LEN(&awk->token.name), - &awk->prmfns.mmgr); - if (name_dup == ASE_NULL) - { - SETERRLIN (awk, ASE_AWK_ENOMEM, line); - return ASE_NULL; - } - name_len = ASE_STR_LEN(&awk->token.name); - - if (get_token(awk) == -1) - { - ASE_AWK_FREE (awk, name_dup); - return ASE_NULL; - } - - /* check if name_dup is a built-in function name */ - bfn = ase_awk_getbfn (awk, name_dup, name_len); - if (bfn != ASE_NULL) - { - ase_awk_nde_t* nde; - - if (!MATCH(awk,TOKEN_LPAREN)) - { - /* built-in function should be in the form - * of the function call */ - ASE_AWK_FREE (awk, name_dup); - - SETERRTOK (awk, ASE_AWK_ELPAREN); - return ASE_NULL; - } - - ASE_AWK_FREE (awk, name_dup); - nde = parse_fncall (awk, ASE_NULL, 0, bfn, line); - return (ase_awk_nde_t*)nde; - } - - /* now we know that name_dup is a normal identifier. */ - if (MATCH(awk,TOKEN_LBRACK)) - { - ase_awk_nde_t* nde; - nde = parse_hashidx (awk, name_dup, name_len, line); - if (nde == ASE_NULL) ASE_AWK_FREE (awk, name_dup); - return (ase_awk_nde_t*)nde; - } - else if (MATCH(awk,TOKEN_LPAREN)) - { - /* function call */ - ase_awk_nde_t* nde; - nde = parse_fncall (awk, name_dup, name_len, ASE_NULL, line); - if (nde == ASE_NULL) ASE_AWK_FREE (awk, name_dup); - return (ase_awk_nde_t*)nde; - } - else - { - /* normal variable */ - ase_awk_nde_var_t* nde; - ase_size_t idxa; - - nde = (ase_awk_nde_var_t*) ASE_AWK_MALLOC ( - awk, ASE_SIZEOF(ase_awk_nde_var_t)); - if (nde == ASE_NULL) - { - ASE_AWK_FREE (awk, name_dup); - SETERRLIN (awk, ASE_AWK_ENOMEM, line); - return ASE_NULL; - } - - /* search the parameter name list */ - idxa = ase_awk_tab_find ( - &awk->parse.params, 0, name_dup, name_len); - if (idxa != (ase_size_t)-1) - { - nde->type = ASE_AWK_NDE_ARG; - nde->line = line; - nde->next = ASE_NULL; - /*nde->id.name = ASE_NULL;*/ - nde->id.name = name_dup; - nde->id.name_len = name_len; - nde->id.idxa = idxa; - nde->idx = ASE_NULL; - - return (ase_awk_nde_t*)nde; - } - - /* search the local variable list */ - idxa = ase_awk_tab_rrfind ( - &awk->parse.locals, 0, name_dup, name_len); - if (idxa != (ase_size_t)-1) - { - nde->type = ASE_AWK_NDE_LOCAL; - nde->line = line; - nde->next = ASE_NULL; - /*nde->id.name = ASE_NULL;*/ - nde->id.name = name_dup; - nde->id.name_len = name_len; - nde->id.idxa = idxa; - nde->idx = ASE_NULL; - - return (ase_awk_nde_t*)nde; - } - - /* search the global variable list */ - idxa = ase_awk_tab_rrfind ( - &awk->parse.globals, 0, name_dup, name_len); - if (idxa != (ase_size_t)-1) - { - nde->type = ASE_AWK_NDE_GLOBAL; - nde->line = line; - nde->next = ASE_NULL; - /*nde->id.name = ASE_NULL;*/ - nde->id.name = name_dup; - nde->id.name_len = name_len; - nde->id.idxa = idxa; - nde->idx = ASE_NULL; - - return (ase_awk_nde_t*)nde; - } - - if (awk->option & ASE_AWK_IMPLICIT) - { - nde->type = ASE_AWK_NDE_NAMED; - nde->line = line; - nde->next = ASE_NULL; - nde->id.name = name_dup; - nde->id.name_len = name_len; - nde->id.idxa = (ase_size_t)-1; - nde->idx = ASE_NULL; - - return (ase_awk_nde_t*)nde; - } - - SETERRARG (awk, ASE_AWK_EUNDEF, line, name_dup, name_len); - - /* undefined variable */ - ASE_AWK_FREE (awk, name_dup); - ASE_AWK_FREE (awk, nde); - - return ASE_NULL; - } -} - -static ase_awk_nde_t* parse_hashidx ( - ase_awk_t* awk, ase_char_t* name, ase_size_t name_len, ase_size_t line) -{ - ase_awk_nde_t* idx, * tmp, * last; - ase_awk_nde_var_t* nde; - ase_size_t idxa; - - idx = ASE_NULL; - last = ASE_NULL; - - do - { - if (get_token(awk) == -1) - { - if (idx != ASE_NULL) ase_awk_clrpt (awk, idx); - return ASE_NULL; - } - - tmp = parse_expression (awk, awk->token.line); - if (tmp == ASE_NULL) - { - if (idx != ASE_NULL) ase_awk_clrpt (awk, idx); - return ASE_NULL; - } - - if (idx == ASE_NULL) - { - ASE_ASSERT (last == ASE_NULL); - idx = tmp; last = tmp; - } - else - { - last->next = tmp; - last = tmp; - } - } - while (MATCH(awk,TOKEN_COMMA)); - - ASE_ASSERT (idx != ASE_NULL); - - if (!MATCH(awk,TOKEN_RBRACK)) - { - ase_awk_clrpt (awk, idx); - - SETERRTOK (awk, ASE_AWK_ERBRACK); - return ASE_NULL; - } - - if (get_token(awk) == -1) - { - ase_awk_clrpt (awk, idx); - return ASE_NULL; - } - - nde = (ase_awk_nde_var_t*) - ASE_AWK_MALLOC (awk, ASE_SIZEOF(ase_awk_nde_var_t)); - if (nde == ASE_NULL) - { - ase_awk_clrpt (awk, idx); - SETERRLIN (awk, ASE_AWK_ENOMEM, line); - return ASE_NULL; - } - - /* search the parameter name list */ - idxa = ase_awk_tab_find (&awk->parse.params, 0, name, name_len); - if (idxa != (ase_size_t)-1) - { - nde->type = ASE_AWK_NDE_ARGIDX; - nde->line = line; - nde->next = ASE_NULL; - /*nde->id.name = ASE_NULL; */ - nde->id.name = name; - nde->id.name_len = name_len; - nde->id.idxa = idxa; - nde->idx = idx; - - return (ase_awk_nde_t*)nde; - } - - /* search the local variable list */ - idxa = ase_awk_tab_rrfind(&awk->parse.locals, 0, name, name_len); - if (idxa != (ase_size_t)-1) - { - nde->type = ASE_AWK_NDE_LOCALIDX; - nde->line = line; - nde->next = ASE_NULL; - /*nde->id.name = ASE_NULL; */ - nde->id.name = name; - nde->id.name_len = name_len; - nde->id.idxa = idxa; - nde->idx = idx; - - return (ase_awk_nde_t*)nde; - } - - /* search the global variable list */ - idxa = ase_awk_tab_rrfind(&awk->parse.globals, 0, name, name_len); - if (idxa != (ase_size_t)-1) - { - nde->type = ASE_AWK_NDE_GLOBALIDX; - nde->line = line; - nde->next = ASE_NULL; - /*nde->id.name = ASE_NULL;*/ - nde->id.name = name; - nde->id.name_len = name_len; - nde->id.idxa = idxa; - nde->idx = idx; - - return (ase_awk_nde_t*)nde; - } - - if (awk->option & ASE_AWK_IMPLICIT) - { - nde->type = ASE_AWK_NDE_NAMEDIDX; - nde->line = line; - nde->next = ASE_NULL; - nde->id.name = name; - nde->id.name_len = name_len; - nde->id.idxa = (ase_size_t)-1; - nde->idx = idx; - - return (ase_awk_nde_t*)nde; - } - - /* undefined variable */ - ase_awk_clrpt (awk, idx); - ASE_AWK_FREE (awk, nde); - - SETERRARG (awk, ASE_AWK_EUNDEF, line, name, name_len); - return ASE_NULL; -} - -static ase_awk_nde_t* parse_fncall ( - ase_awk_t* awk, ase_char_t* name, ase_size_t name_len, - ase_awk_bfn_t* bfn, ase_size_t line) -{ - ase_awk_nde_t* head, * curr, * nde; - ase_awk_nde_call_t* call; - ase_size_t nargs; - - if (get_token(awk) == -1) return ASE_NULL; - - head = curr = ASE_NULL; - nargs = 0; - - if (MATCH(awk,TOKEN_RPAREN)) - { - /* no parameters to the function call */ - if (get_token(awk) == -1) return ASE_NULL; - } - else - { - /* parse function parameters */ - - while (1) - { - nde = parse_expression (awk, awk->token.line); - if (nde == ASE_NULL) - { - if (head != ASE_NULL) ase_awk_clrpt (awk, head); - return ASE_NULL; - } - - if (head == ASE_NULL) head = nde; - else curr->next = nde; - curr = nde; - - nargs++; - - if (MATCH(awk,TOKEN_RPAREN)) - { - if (get_token(awk) == -1) - { - if (head != ASE_NULL) - ase_awk_clrpt (awk, head); - return ASE_NULL; - } - break; - } - - if (!MATCH(awk,TOKEN_COMMA)) - { - if (head != ASE_NULL) ase_awk_clrpt (awk, head); - - SETERRTOK (awk, ASE_AWK_ECOMMA); - return ASE_NULL; - } - - if (get_token(awk) == -1) - { - if (head != ASE_NULL) ase_awk_clrpt (awk, head); - return ASE_NULL; - } - } - - } - - call = (ase_awk_nde_call_t*) - ASE_AWK_MALLOC (awk, ASE_SIZEOF(ase_awk_nde_call_t)); - if (call == ASE_NULL) - { - if (head != ASE_NULL) ase_awk_clrpt (awk, head); - - SETERRLIN (awk, ASE_AWK_ENOMEM, line); - return ASE_NULL; - } - - if (bfn != ASE_NULL) - { - call->type = ASE_AWK_NDE_BFN; - call->line = line; - call->next = ASE_NULL; - - /*call->what.bfn = bfn; */ - call->what.bfn.name.ptr = bfn->name.ptr; - call->what.bfn.name.len = bfn->name.len; - call->what.bfn.arg.min = bfn->arg.min; - call->what.bfn.arg.max = bfn->arg.max; - call->what.bfn.arg.spec = bfn->arg.spec; - call->what.bfn.handler = bfn->handler; - - call->args = head; - call->nargs = nargs; - } - else - { - call->type = ASE_AWK_NDE_AFN; - call->line = line; - call->next = ASE_NULL; - call->what.afn.name.ptr = name; - call->what.afn.name.len = name_len; - call->args = head; - call->nargs = nargs; - } - - return (ase_awk_nde_t*)call; -} - -static ase_awk_nde_t* parse_if (ase_awk_t* awk, ase_size_t line) -{ - ase_awk_nde_t* test; - ase_awk_nde_t* then_part; - ase_awk_nde_t* else_part; - ase_awk_nde_if_t* nde; - - if (!MATCH(awk,TOKEN_LPAREN)) - { - SETERRTOK (awk, ASE_AWK_ELPAREN); - return ASE_NULL; - - } - if (get_token(awk) == -1) return ASE_NULL; - - test = parse_expression (awk, awk->token.line); - if (test == ASE_NULL) return ASE_NULL; - - if (!MATCH(awk,TOKEN_RPAREN)) - { - ase_awk_clrpt (awk, test); - - SETERRTOK (awk, ASE_AWK_ERPAREN); - return ASE_NULL; - } - - if (get_token(awk) == -1) - { - ase_awk_clrpt (awk, test); - return ASE_NULL; - } - - then_part = parse_statement (awk, awk->token.line); - if (then_part == ASE_NULL) - { - ase_awk_clrpt (awk, test); - return ASE_NULL; - } - - if (MATCH(awk,TOKEN_ELSE)) - { - if (get_token(awk) == -1) - { - ase_awk_clrpt (awk, then_part); - ase_awk_clrpt (awk, test); - return ASE_NULL; - } - - else_part = parse_statement (awk, awk->token.prev.line); - if (else_part == ASE_NULL) - { - ase_awk_clrpt (awk, then_part); - ase_awk_clrpt (awk, test); - return ASE_NULL; - } - } - else else_part = ASE_NULL; - - nde = (ase_awk_nde_if_t*) - ASE_AWK_MALLOC (awk, ASE_SIZEOF(ase_awk_nde_if_t)); - if (nde == ASE_NULL) - { - ase_awk_clrpt (awk, else_part); - ase_awk_clrpt (awk, then_part); - ase_awk_clrpt (awk, test); - - SETERRLIN (awk, ASE_AWK_ENOMEM, line); - return ASE_NULL; - } - - nde->type = ASE_AWK_NDE_IF; - nde->line = line; - nde->next = ASE_NULL; - nde->test = test; - nde->then_part = then_part; - nde->else_part = else_part; - - return (ase_awk_nde_t*)nde; -} - -static ase_awk_nde_t* parse_while (ase_awk_t* awk, ase_size_t line) -{ - ase_awk_nde_t* test, * body; - ase_awk_nde_while_t* nde; - - if (!MATCH(awk,TOKEN_LPAREN)) - { - SETERRTOK (awk, ASE_AWK_ELPAREN); - return ASE_NULL; - } - if (get_token(awk) == -1) return ASE_NULL; - - test = parse_expression (awk, awk->token.line); - if (test == ASE_NULL) return ASE_NULL; - - if (!MATCH(awk,TOKEN_RPAREN)) - { - ase_awk_clrpt (awk, test); - - SETERRTOK (awk, ASE_AWK_ERPAREN); - return ASE_NULL; - } - - if (get_token(awk) == -1) - { - ase_awk_clrpt (awk, test); - return ASE_NULL; - } - - body = parse_statement (awk, awk->token.line); - if (body == ASE_NULL) - { - ase_awk_clrpt (awk, test); - return ASE_NULL; - } - - nde = (ase_awk_nde_while_t*) - ASE_AWK_MALLOC (awk, ASE_SIZEOF(ase_awk_nde_while_t)); - if (nde == ASE_NULL) - { - ase_awk_clrpt (awk, body); - ase_awk_clrpt (awk, test); - - SETERRLIN (awk, ASE_AWK_ENOMEM, line); - return ASE_NULL; - } - - nde->type = ASE_AWK_NDE_WHILE; - nde->line = line; - nde->next = ASE_NULL; - nde->test = test; - nde->body = body; - - return (ase_awk_nde_t*)nde; -} - -static ase_awk_nde_t* parse_for (ase_awk_t* awk, ase_size_t line) -{ - ase_awk_nde_t* init, * test, * incr, * body; - ase_awk_nde_for_t* nde; - ase_awk_nde_foreach_t* nde2; - - if (!MATCH(awk,TOKEN_LPAREN)) - { - SETERRTOK (awk, ASE_AWK_ELPAREN); - return ASE_NULL; - } - if (get_token(awk) == -1) return ASE_NULL; - - if (MATCH(awk,TOKEN_SEMICOLON)) init = ASE_NULL; - else - { - /* this line is very ugly. it checks the entire next - * expression or the first element in the expression - * is wrapped by a parenthesis */ - int no_foreach = MATCH(awk,TOKEN_LPAREN); - - init = parse_expression (awk, awk->token.line); - if (init == ASE_NULL) return ASE_NULL; - - if (!no_foreach && init->type == ASE_AWK_NDE_EXP_BIN && - ((ase_awk_nde_exp_t*)init)->opcode == ASE_AWK_BINOP_IN && - is_plain_var(((ase_awk_nde_exp_t*)init)->left)) - { - /* switch to foreach */ - - if (!MATCH(awk,TOKEN_RPAREN)) - { - ase_awk_clrpt (awk, init); - SETERRTOK (awk, ASE_AWK_ERPAREN); - return ASE_NULL; - } - - if (get_token(awk) == -1) - { - ase_awk_clrpt (awk, init); - return ASE_NULL; - } - - body = parse_statement (awk, awk->token.line); - if (body == ASE_NULL) - { - ase_awk_clrpt (awk, init); - return ASE_NULL; - } - - nde2 = (ase_awk_nde_foreach_t*) ASE_AWK_MALLOC ( - awk, ASE_SIZEOF(ase_awk_nde_foreach_t)); - if (nde2 == ASE_NULL) - { - ase_awk_clrpt (awk, init); - ase_awk_clrpt (awk, body); - - SETERRLIN (awk, ASE_AWK_ENOMEM, line); - return ASE_NULL; - } - - nde2->type = ASE_AWK_NDE_FOREACH; - nde2->line = line; - nde2->next = ASE_NULL; - nde2->test = init; - nde2->body = body; - - return (ase_awk_nde_t*)nde2; - } - - if (!MATCH(awk,TOKEN_SEMICOLON)) - { - ase_awk_clrpt (awk, init); - - SETERRTOK (awk, ASE_AWK_ESCOLON); - return ASE_NULL; - } - } - - if (get_token(awk) == -1) - { - ase_awk_clrpt (awk, init); - return ASE_NULL; - } - - if (MATCH(awk,TOKEN_SEMICOLON)) test = ASE_NULL; - else - { - test = parse_expression (awk, awk->token.line); - if (test == ASE_NULL) - { - ase_awk_clrpt (awk, init); - return ASE_NULL; - } - - if (!MATCH(awk,TOKEN_SEMICOLON)) - { - ase_awk_clrpt (awk, init); - ase_awk_clrpt (awk, test); - - SETERRTOK (awk, ASE_AWK_ESCOLON); - return ASE_NULL; - } - } - - if (get_token(awk) == -1) - { - ase_awk_clrpt (awk, init); - ase_awk_clrpt (awk, test); - return ASE_NULL; - } - - if (MATCH(awk,TOKEN_RPAREN)) incr = ASE_NULL; - else - { - incr = parse_expression (awk, awk->token.line); - if (incr == ASE_NULL) - { - ase_awk_clrpt (awk, init); - ase_awk_clrpt (awk, test); - return ASE_NULL; - } - - if (!MATCH(awk,TOKEN_RPAREN)) - { - ase_awk_clrpt (awk, init); - ase_awk_clrpt (awk, test); - ase_awk_clrpt (awk, incr); - - SETERRTOK (awk, ASE_AWK_ERPAREN); - return ASE_NULL; - } - } - - if (get_token(awk) == -1) - { - ase_awk_clrpt (awk, init); - ase_awk_clrpt (awk, test); - ase_awk_clrpt (awk, incr); - return ASE_NULL; - } - - body = parse_statement (awk, awk->token.line); - if (body == ASE_NULL) - { - ase_awk_clrpt (awk, init); - ase_awk_clrpt (awk, test); - ase_awk_clrpt (awk, incr); - return ASE_NULL; - } - - nde = (ase_awk_nde_for_t*) - ASE_AWK_MALLOC (awk, ASE_SIZEOF(ase_awk_nde_for_t)); - if (nde == ASE_NULL) - { - ase_awk_clrpt (awk, init); - ase_awk_clrpt (awk, test); - ase_awk_clrpt (awk, incr); - ase_awk_clrpt (awk, body); - - SETERRLIN (awk, ASE_AWK_ENOMEM, line); - return ASE_NULL; - } - - nde->type = ASE_AWK_NDE_FOR; - nde->line = line; - nde->next = ASE_NULL; - nde->init = init; - nde->test = test; - nde->incr = incr; - nde->body = body; - - return (ase_awk_nde_t*)nde; -} - -static ase_awk_nde_t* parse_dowhile (ase_awk_t* awk, ase_size_t line) -{ - ase_awk_nde_t* test, * body; - ase_awk_nde_while_t* nde; - - ASE_ASSERT (awk->token.prev.type == TOKEN_DO); - - body = parse_statement (awk, awk->token.line); - if (body == ASE_NULL) return ASE_NULL; - - if (!MATCH(awk,TOKEN_WHILE)) - { - ase_awk_clrpt (awk, body); - - SETERRTOK (awk, ASE_AWK_EWHILE); - return ASE_NULL; - } - - if (get_token(awk) == -1) - { - ase_awk_clrpt (awk, body); - return ASE_NULL; - } - - if (!MATCH(awk,TOKEN_LPAREN)) - { - ase_awk_clrpt (awk, body); - - SETERRTOK (awk, ASE_AWK_ELPAREN); - return ASE_NULL; - } - - if (get_token(awk) == -1) - { - ase_awk_clrpt (awk, body); - return ASE_NULL; - } - - test = parse_expression (awk, awk->token.line); - if (test == ASE_NULL) - { - ase_awk_clrpt (awk, body); - return ASE_NULL; - } - - if (!MATCH(awk,TOKEN_RPAREN)) - { - ase_awk_clrpt (awk, body); - ase_awk_clrpt (awk, test); - - SETERRTOK (awk, ASE_AWK_ERPAREN); - return ASE_NULL; - } - - if (get_token(awk) == -1) - { - ase_awk_clrpt (awk, body); - ase_awk_clrpt (awk, test); - return ASE_NULL; - } - - nde = (ase_awk_nde_while_t*) - ASE_AWK_MALLOC (awk, ASE_SIZEOF(ase_awk_nde_while_t)); - if (nde == ASE_NULL) - { - ase_awk_clrpt (awk, body); - ase_awk_clrpt (awk, test); - - SETERRLIN (awk, ASE_AWK_ENOMEM, line); - return ASE_NULL; - } - - nde->type = ASE_AWK_NDE_DOWHILE; - nde->line = line; - nde->next = ASE_NULL; - nde->test = test; - nde->body = body; - - return (ase_awk_nde_t*)nde; -} - -static ase_awk_nde_t* parse_break (ase_awk_t* awk, ase_size_t line) -{ - ase_awk_nde_break_t* nde; - - ASE_ASSERT (awk->token.prev.type == TOKEN_BREAK); - if (awk->parse.depth.cur.loop <= 0) - { - SETERRLIN (awk, ASE_AWK_EBREAK, line); - return ASE_NULL; - } - - nde = (ase_awk_nde_break_t*) - ASE_AWK_MALLOC (awk, ASE_SIZEOF(ase_awk_nde_break_t)); - if (nde == ASE_NULL) - { - SETERRLIN (awk, ASE_AWK_ENOMEM, line); - return ASE_NULL; - } - - nde->type = ASE_AWK_NDE_BREAK; - nde->line = line; - nde->next = ASE_NULL; - - return (ase_awk_nde_t*)nde; -} - -static ase_awk_nde_t* parse_continue (ase_awk_t* awk, ase_size_t line) -{ - ase_awk_nde_continue_t* nde; - - ASE_ASSERT (awk->token.prev.type == TOKEN_CONTINUE); - if (awk->parse.depth.cur.loop <= 0) - { - SETERRLIN (awk, ASE_AWK_ECONTINUE, line); - return ASE_NULL; - } - - nde = (ase_awk_nde_continue_t*) - ASE_AWK_MALLOC (awk, ASE_SIZEOF(ase_awk_nde_continue_t)); - if (nde == ASE_NULL) - { - SETERRLIN (awk, ASE_AWK_ENOMEM, line); - return ASE_NULL; - } - - nde->type = ASE_AWK_NDE_CONTINUE; - nde->line = line; - nde->next = ASE_NULL; - - return (ase_awk_nde_t*)nde; -} - -static ase_awk_nde_t* parse_return (ase_awk_t* awk, ase_size_t line) -{ - ase_awk_nde_return_t* nde; - ase_awk_nde_t* val; - - ASE_ASSERT (awk->token.prev.type == TOKEN_RETURN); - - nde = (ase_awk_nde_return_t*) ASE_AWK_MALLOC ( - awk, ASE_SIZEOF(ase_awk_nde_return_t)); - if (nde == ASE_NULL) - { - SETERRLIN (awk, ASE_AWK_ENOMEM, line); - return ASE_NULL; - } - - nde->type = ASE_AWK_NDE_RETURN; - nde->line = line; - nde->next = ASE_NULL; - - if (MATCH(awk,TOKEN_SEMICOLON)) - { - /* no return value */ - val = ASE_NULL; - } - else - { - val = parse_expression (awk, awk->token.line); - if (val == ASE_NULL) - { - ASE_AWK_FREE (awk, nde); - return ASE_NULL; - } - } - - nde->val = val; - return (ase_awk_nde_t*)nde; -} - -static ase_awk_nde_t* parse_exit (ase_awk_t* awk, ase_size_t line) -{ - ase_awk_nde_exit_t* nde; - ase_awk_nde_t* val; - - ASE_ASSERT (awk->token.prev.type == TOKEN_EXIT); - - nde = (ase_awk_nde_exit_t*) - ASE_AWK_MALLOC (awk, ASE_SIZEOF(ase_awk_nde_exit_t)); - if (nde == ASE_NULL) - { - SETERRLIN (awk, ASE_AWK_ENOMEM, line); - return ASE_NULL; - } - - nde->type = ASE_AWK_NDE_EXIT; - nde->line = line; - nde->next = ASE_NULL; - - if (MATCH(awk,TOKEN_SEMICOLON)) - { - /* no exit code */ - val = ASE_NULL; - } - else - { - val = parse_expression (awk, awk->token.line); - if (val == ASE_NULL) - { - ASE_AWK_FREE (awk, nde); - return ASE_NULL; - } - } - - nde->val = val; - return (ase_awk_nde_t*)nde; -} - -static ase_awk_nde_t* parse_next (ase_awk_t* awk, ase_size_t line) -{ - ase_awk_nde_next_t* nde; - - ASE_ASSERT (awk->token.prev.type == TOKEN_NEXT); - - if (awk->parse.id.block == PARSE_BEGIN_BLOCK) - { - SETERRLIN (awk, ASE_AWK_ENEXTBEG, line); - return ASE_NULL; - } - if (awk->parse.id.block == PARSE_END_BLOCK) - { - SETERRLIN (awk, ASE_AWK_ENEXTEND, line); - return ASE_NULL; - } - - nde = (ase_awk_nde_next_t*) - ASE_AWK_MALLOC (awk, ASE_SIZEOF(ase_awk_nde_next_t)); - if (nde == ASE_NULL) - { - SETERRLIN (awk, ASE_AWK_ENOMEM, line); - return ASE_NULL; - } - nde->type = ASE_AWK_NDE_NEXT; - nde->line = line; - nde->next = ASE_NULL; - - return (ase_awk_nde_t*)nde; -} - -static ase_awk_nde_t* parse_nextfile (ase_awk_t* awk, ase_size_t line, int out) -{ - ase_awk_nde_nextfile_t* nde; - - if (awk->parse.id.block == PARSE_BEGIN_BLOCK) - { - SETERRLIN (awk, ASE_AWK_ENEXTFBEG, line); - return ASE_NULL; - } - if (awk->parse.id.block == PARSE_END_BLOCK) - { - SETERRLIN (awk, ASE_AWK_ENEXTFEND, line); - return ASE_NULL; - } - - nde = (ase_awk_nde_nextfile_t*) - ASE_AWK_MALLOC (awk, ASE_SIZEOF(ase_awk_nde_nextfile_t)); - if (nde == ASE_NULL) - { - SETERRLIN (awk, ASE_AWK_ENOMEM, line); - return ASE_NULL; - } - - nde->type = ASE_AWK_NDE_NEXTFILE; - nde->line = line; - nde->next = ASE_NULL; - nde->out = out; - - return (ase_awk_nde_t*)nde; -} - -static ase_awk_nde_t* parse_delete (ase_awk_t* awk, ase_size_t line) -{ - ase_awk_nde_delete_t* nde; - ase_awk_nde_t* var; - - ASE_ASSERT (awk->token.prev.type == TOKEN_DELETE); - if (!MATCH(awk,TOKEN_IDENT)) - { - SETERRTOK (awk, ASE_AWK_EIDENT); - return ASE_NULL; - } - - var = parse_primary_ident (awk, awk->token.line); - if (var == ASE_NULL) return ASE_NULL; - - if (!is_var (var)) - { - /* a normal identifier is expected */ - ase_awk_clrpt (awk, var); - SETERRLIN (awk, ASE_AWK_EDELETE, line); - return ASE_NULL; - } - - nde = (ase_awk_nde_delete_t*) ASE_AWK_MALLOC ( - awk, ASE_SIZEOF(ase_awk_nde_delete_t)); - if (nde == ASE_NULL) - { - SETERRLIN (awk, ASE_AWK_ENOMEM, line); - return ASE_NULL; - } - - nde->type = ASE_AWK_NDE_DELETE; - nde->line = line; - nde->next = ASE_NULL; - nde->var = var; - - return (ase_awk_nde_t*)nde; -} - -static ase_awk_nde_t* parse_print (ase_awk_t* awk, ase_size_t line, int type) -{ - ase_awk_nde_print_t* nde; - ase_awk_nde_t* args = ASE_NULL; - ase_awk_nde_t* out = ASE_NULL; - int out_type; - - if (!MATCH(awk,TOKEN_SEMICOLON) && - !MATCH(awk,TOKEN_GT) && - !MATCH(awk,TOKEN_RSHIFT) && - !MATCH(awk,TOKEN_BOR) && - !MATCH(awk,TOKEN_BORAND)) - { - ase_awk_nde_t* args_tail; - ase_awk_nde_t* tail_prev; - - args = parse_expression (awk, awk->token.line); - if (args == ASE_NULL) return ASE_NULL; - - args_tail = args; - tail_prev = ASE_NULL; - - if (args->type != ASE_AWK_NDE_GRP) - { - /* args->type == ASE_AWK_NDE_GRP when print (a, b, c) - * args->type != ASE_AWK_NDE_GRP when print a, b, c */ - - while (MATCH(awk,TOKEN_COMMA)) - { - if (get_token(awk) == -1) - { - ase_awk_clrpt (awk, args); - return ASE_NULL; - } - - args_tail->next = parse_expression (awk, awk->token.line); - if (args_tail->next == ASE_NULL) - { - ase_awk_clrpt (awk, args); - return ASE_NULL; - } - - tail_prev = args_tail; - args_tail = args_tail->next; - } - } - - /* print 1 > 2 would print 1 to the file named 2. - * print (1 > 2) would print (1 > 2) on the console */ - if (awk->token.prev.type != TOKEN_RPAREN && - args_tail->type == ASE_AWK_NDE_EXP_BIN) - { - ase_awk_nde_exp_t* ep = (ase_awk_nde_exp_t*)args_tail; - if (ep->opcode == ASE_AWK_BINOP_GT) - { - ase_awk_nde_t* tmp = args_tail; - - if (tail_prev != ASE_NULL) - tail_prev->next = ep->left; - else args = ep->left; - - out = ep->right; - out_type = ASE_AWK_OUT_FILE; - - ASE_AWK_FREE (awk, tmp); - } - else if (ep->opcode == ASE_AWK_BINOP_RSHIFT) - { - ase_awk_nde_t* tmp = args_tail; - - if (tail_prev != ASE_NULL) - tail_prev->next = ep->left; - else args = ep->left; - - out = ep->right; - out_type = ASE_AWK_OUT_FILE_APPEND; - - ASE_AWK_FREE (awk, tmp); - } - else if (ep->opcode == ASE_AWK_BINOP_BOR) - { - ase_awk_nde_t* tmp = args_tail; - - if (tail_prev != ASE_NULL) - tail_prev->next = ep->left; - else args = ep->left; - - out = ep->right; - out_type = ASE_AWK_OUT_PIPE; - - ASE_AWK_FREE (awk, tmp); - } - } - } - - if (out == ASE_NULL) - { - out_type = MATCH(awk,TOKEN_GT)? ASE_AWK_OUT_FILE: - MATCH(awk,TOKEN_RSHIFT)? ASE_AWK_OUT_FILE_APPEND: - MATCH(awk,TOKEN_BOR)? ASE_AWK_OUT_PIPE: - MATCH(awk,TOKEN_BORAND)? ASE_AWK_OUT_COPROC: - ASE_AWK_OUT_CONSOLE; - - if (out_type != ASE_AWK_OUT_CONSOLE) - { - if (get_token(awk) == -1) - { - if (args != ASE_NULL) ase_awk_clrpt (awk, args); - return ASE_NULL; - } - - out = parse_expression (awk, awk->token.line); - if (out == ASE_NULL) - { - if (args != ASE_NULL) ase_awk_clrpt (awk, args); - return ASE_NULL; - } - } - } - - nde = (ase_awk_nde_print_t*) - ASE_AWK_MALLOC (awk, ASE_SIZEOF(ase_awk_nde_print_t)); - if (nde == ASE_NULL) - { - if (args != ASE_NULL) ase_awk_clrpt (awk, args); - if (out != ASE_NULL) ase_awk_clrpt (awk, out); - - SETERRLIN (awk, ASE_AWK_ENOMEM, line); - return ASE_NULL; - } - - ASE_ASSERTX ( - type == ASE_AWK_NDE_PRINT || type == ASE_AWK_NDE_PRINTF, - "the node type should be either ASE_AWK_NDE_PRINT or ASE_AWK_NDE_PRINTF"); - - if (type == ASE_AWK_NDE_PRINTF && args == ASE_NULL) - { - if (out != ASE_NULL) ase_awk_clrpt (awk, out); - SETERRLIN (awk, ASE_AWK_EPRINTFARG, line); - return ASE_NULL; - } - - nde->type = type; - nde->line = line; - nde->next = ASE_NULL; - nde->args = args; - nde->out_type = out_type; - nde->out = out; - - return (ase_awk_nde_t*)nde; -} - -static int get_token (ase_awk_t* awk) -{ - ase_cint_t c; - ase_size_t line; - int n; - - line = awk->token.line; - - awk->token.prev.type = awk->token.type; - awk->token.prev.line = awk->token.line; - awk->token.prev.column = awk->token.column; - - do - { - if (skip_spaces(awk) == -1) return -1; - if ((n = skip_comment(awk)) == -1) return -1; - } - while (n == 1); - - ase_str_clear (&awk->token.name); - awk->token.line = awk->src.lex.line; - awk->token.column = awk->src.lex.column; - - if (line != 0 && (awk->option & ASE_AWK_BLOCKLESS) && - (awk->parse.id.block == PARSE_PATTERN || - awk->parse.id.block == PARSE_BEGIN || - awk->parse.id.block == PARSE_END)) - { - if (awk->token.line != line) - { - SET_TOKEN_TYPE (awk, TOKEN_NEWLINE); - return 0; - } - } - - c = awk->src.lex.curc; - - if (c == ASE_CHAR_EOF) - { - ADD_TOKEN_CHAR (awk, ASE_T('<')); - ADD_TOKEN_CHAR (awk, ASE_T('E')); - ADD_TOKEN_CHAR (awk, ASE_T('O')); - ADD_TOKEN_CHAR (awk, ASE_T('F')); - ADD_TOKEN_CHAR (awk, ASE_T('>')); - - SET_TOKEN_TYPE (awk, TOKEN_EOF); - } - else if (ASE_AWK_ISDIGIT (awk, c)/*|| c == ASE_T('.')*/) - { - if (get_number (awk) == -1) return -1; - } - else if (c == ASE_T('.')) - { - if (get_char (awk) == -1) return -1; - c = awk->src.lex.curc; - - if ((awk->option & ASE_AWK_EXPLICIT) == 0 && - ASE_AWK_ISDIGIT (awk, c)) - { - awk->src.lex.curc = ASE_T('.'); - if (unget_char (awk, c) == -1) return -1; - if (get_number (awk) == -1) return -1; - - } - else /*if (ASE_AWK_ISSPACE (awk, c) || c == ASE_CHAR_EOF)*/ - { - SET_TOKEN_TYPE (awk, TOKEN_PERIOD); - ADD_TOKEN_CHAR (awk, ASE_T('.')); - } - /* - else - { - ase_awk_seterror ( - awk, ASE_AWK_ELXCHR, awk->token.line, - ASE_T("floating point not followed by any valid digits")); - return -1; - } - */ - } - else if (ASE_AWK_ISALPHA (awk, c) || c == ASE_T('_')) - { - int type; - - /* identifier */ - do - { - ADD_TOKEN_CHAR (awk, c); - GET_CHAR_TO (awk, c); - } - while (ASE_AWK_ISALPHA (awk, c) || - c == ASE_T('_') || ASE_AWK_ISDIGIT(awk,c)); - - type = classify_ident (awk, - ASE_STR_BUF(&awk->token.name), - ASE_STR_LEN(&awk->token.name)); - SET_TOKEN_TYPE (awk, type); - } - else if (c == ASE_T('\"')) - { - SET_TOKEN_TYPE (awk, TOKEN_STR); - - if (get_charstr(awk) == -1) return -1; - - while (awk->option & ASE_AWK_STRCONCAT) - { - do - { - if (skip_spaces(awk) == -1) return -1; - if ((n = skip_comment(awk)) == -1) return -1; - } - while (n == 1); - - c = awk->src.lex.curc; - if (c != ASE_T('\"')) break; - - if (get_charstr(awk) == -1) return -1; - } - - } - else if (c == ASE_T('=')) - { - ADD_TOKEN_CHAR (awk, c); - GET_CHAR_TO (awk, c); - if (c == ASE_T('=')) - { - SET_TOKEN_TYPE (awk, TOKEN_EQ); - ADD_TOKEN_CHAR (awk, c); - GET_CHAR (awk); - } - else - { - SET_TOKEN_TYPE (awk, TOKEN_ASSIGN); - } - } - else if (c == ASE_T('!')) - { - ADD_TOKEN_CHAR (awk, c); - GET_CHAR_TO (awk, c); - if (c == ASE_T('=')) - { - SET_TOKEN_TYPE (awk, TOKEN_NE); - ADD_TOKEN_CHAR (awk, c); - GET_CHAR (awk); - } - else if (c == ASE_T('~')) - { - SET_TOKEN_TYPE (awk, TOKEN_NM); - ADD_TOKEN_CHAR (awk, c); - GET_CHAR (awk); - } - else - { - SET_TOKEN_TYPE (awk, TOKEN_NOT); - } - } - else if (c == ASE_T('>')) - { - ADD_TOKEN_CHAR (awk, c); - GET_CHAR_TO (awk, c); - if ((awk->option & ASE_AWK_SHIFT) && c == ASE_T('>')) - { - SET_TOKEN_TYPE (awk, TOKEN_RSHIFT); - ADD_TOKEN_CHAR (awk, c); - GET_CHAR (awk); - } - else if (c == ASE_T('=')) - { - SET_TOKEN_TYPE (awk, TOKEN_GE); - ADD_TOKEN_CHAR (awk, c); - GET_CHAR (awk); - } - else - { - SET_TOKEN_TYPE (awk, TOKEN_GT); - } - } - else if (c == ASE_T('<')) - { - ADD_TOKEN_CHAR (awk, c); - GET_CHAR_TO (awk, c); - - if ((awk->option & ASE_AWK_SHIFT) && c == ASE_T('<')) - { - SET_TOKEN_TYPE (awk, TOKEN_LSHIFT); - ADD_TOKEN_CHAR (awk, c); - GET_CHAR (awk); - } - else if (c == ASE_T('=')) - { - SET_TOKEN_TYPE (awk, TOKEN_LE); - ADD_TOKEN_CHAR (awk, c); - GET_CHAR (awk); - } - else - { - SET_TOKEN_TYPE (awk, TOKEN_LT); - } - } - else if (c == ASE_T('|')) - { - ADD_TOKEN_CHAR (awk, c); - GET_CHAR_TO (awk, c); - if (c == ASE_T('|')) - { - SET_TOKEN_TYPE (awk, TOKEN_LOR); - ADD_TOKEN_CHAR (awk, c); - GET_CHAR (awk); - } - else if ((awk->option & ASE_AWK_COPROC) && c == ASE_T('&')) - { - SET_TOKEN_TYPE (awk, TOKEN_BORAND); - ADD_TOKEN_CHAR (awk, c); - GET_CHAR (awk); - } - else - { - SET_TOKEN_TYPE (awk, TOKEN_BOR); - } - } - else if (c == ASE_T('&')) - { - ADD_TOKEN_CHAR (awk, c); - GET_CHAR_TO (awk, c); - if (c == ASE_T('&')) - { - SET_TOKEN_TYPE (awk, TOKEN_LAND); - ADD_TOKEN_CHAR (awk, c); - GET_CHAR (awk); - } - else - { - SET_TOKEN_TYPE (awk, TOKEN_BAND); - } - } - else if (c == ASE_T('~')) - { - SET_TOKEN_TYPE (awk, TOKEN_TILDE); - ADD_TOKEN_CHAR (awk, c); - GET_CHAR (awk); - } - else if (c == ASE_T('^')) - { - SET_TOKEN_TYPE (awk, TOKEN_BXOR); - ADD_TOKEN_CHAR (awk, c); - GET_CHAR (awk); - } - else if (c == ASE_T('+')) - { - ADD_TOKEN_CHAR (awk, c); - GET_CHAR_TO (awk, c); - if (c == ASE_T('+')) - { - SET_TOKEN_TYPE (awk, TOKEN_PLUSPLUS); - ADD_TOKEN_CHAR (awk, c); - GET_CHAR (awk); - } - else if (c == ASE_T('=')) - { - SET_TOKEN_TYPE (awk, TOKEN_PLUS_ASSIGN); - ADD_TOKEN_CHAR (awk, c); - GET_CHAR (awk); - } - else - { - SET_TOKEN_TYPE (awk, TOKEN_PLUS); - } - } - else if (c == ASE_T('-')) - { - ADD_TOKEN_CHAR (awk, c); - GET_CHAR_TO (awk, c); - if (c == ASE_T('-')) - { - SET_TOKEN_TYPE (awk, TOKEN_MINUSMINUS); - ADD_TOKEN_CHAR (awk, c); - GET_CHAR (awk); - } - else if (c == ASE_T('=')) - { - SET_TOKEN_TYPE (awk, TOKEN_MINUS_ASSIGN); - ADD_TOKEN_CHAR (awk, c); - GET_CHAR (awk); - } - else - { - SET_TOKEN_TYPE (awk, TOKEN_MINUS); - } - } - else if (c == ASE_T('*')) - { - ADD_TOKEN_CHAR (awk, c); - GET_CHAR_TO (awk, c); - - if (c == ASE_T('=')) - { - SET_TOKEN_TYPE (awk, TOKEN_MUL_ASSIGN); - ADD_TOKEN_CHAR (awk, c); - GET_CHAR (awk); - } - else if (c == ASE_T('*')) - { - ADD_TOKEN_CHAR (awk, c); - GET_CHAR_TO (awk, c); - if (c == ASE_T('=')) - { - SET_TOKEN_TYPE (awk, TOKEN_EXP_ASSIGN); - ADD_TOKEN_CHAR (awk, c); - GET_CHAR (awk); - } - else - { - SET_TOKEN_TYPE (awk, TOKEN_EXP); - } - } - else - { - SET_TOKEN_TYPE (awk, TOKEN_MUL); - } - } - else if (c == ASE_T('/')) - { - ADD_TOKEN_CHAR (awk, c); - GET_CHAR_TO (awk, c); - - if (c == ASE_T('=')) - { - SET_TOKEN_TYPE (awk, TOKEN_DIV_ASSIGN); - ADD_TOKEN_CHAR (awk, c); - GET_CHAR (awk); - } - else if ((awk->option & ASE_AWK_IDIV) && c == ASE_T('/')) - { - ADD_TOKEN_CHAR (awk, c); - GET_CHAR_TO (awk, c); - if (c == ASE_T('=')) - { - SET_TOKEN_TYPE (awk, TOKEN_IDIV_ASSIGN); - ADD_TOKEN_CHAR (awk, c); - GET_CHAR (awk); - } - else - { - SET_TOKEN_TYPE (awk, TOKEN_IDIV); - } - } - else - { - SET_TOKEN_TYPE (awk, TOKEN_DIV); - } - } -#if 0 - /* TODO: is it a good idea to use a back-slash for - * the idiv operator like BASIC? */ - else if ((awk->option & ASE_AWK_IDIV) && c == ASE_T('\\')) - { - ADD_TOKEN_CHAR (awk, c); - GET_CHAR_TO (awk, c); - - if (c == ASE_T('=')) - { - SET_TOKEN_TYPE (awk, TOKEN_IDIV_ASSIGN); - ADD_TOKEN_CHAR (awk, c); - GET_CHAR (awk); - } - else - { - SET_TOKEN_TYPE (awk, TOKEN_IDIV); - } - } -#endif - else if (c == ASE_T('%')) - { - ADD_TOKEN_CHAR (awk, c); - GET_CHAR_TO (awk, c); - - if (c == ASE_T('=')) - { - SET_TOKEN_TYPE (awk, TOKEN_MOD_ASSIGN); - ADD_TOKEN_CHAR (awk, c); - GET_CHAR (awk); - } - else - { - SET_TOKEN_TYPE (awk, TOKEN_MOD); - } - } - else if (c == ASE_T('(')) - { - SET_TOKEN_TYPE (awk, TOKEN_LPAREN); - ADD_TOKEN_CHAR (awk, c); - GET_CHAR (awk); - } - else if (c == ASE_T(')')) - { - SET_TOKEN_TYPE (awk, TOKEN_RPAREN); - ADD_TOKEN_CHAR (awk, c); - GET_CHAR (awk); - } - else if (c == ASE_T('{')) - { - SET_TOKEN_TYPE (awk, TOKEN_LBRACE); - ADD_TOKEN_CHAR (awk, c); - GET_CHAR (awk); - } - else if (c == ASE_T('}')) - { - SET_TOKEN_TYPE (awk, TOKEN_RBRACE); - ADD_TOKEN_CHAR (awk, c); - GET_CHAR (awk); - } - else if (c == ASE_T('[')) - { - SET_TOKEN_TYPE (awk, TOKEN_LBRACK); - ADD_TOKEN_CHAR (awk, c); - GET_CHAR (awk); - } - else if (c == ASE_T(']')) - { - SET_TOKEN_TYPE (awk, TOKEN_RBRACK); - ADD_TOKEN_CHAR (awk, c); - GET_CHAR (awk); - } - else if (c == ASE_T('$')) - { - SET_TOKEN_TYPE (awk, TOKEN_DOLLAR); - ADD_TOKEN_CHAR (awk, c); - GET_CHAR (awk); - } - else if (c == ASE_T(',')) - { - SET_TOKEN_TYPE (awk, TOKEN_COMMA); - ADD_TOKEN_CHAR (awk, c); - GET_CHAR (awk); - } - else if (c == ASE_T(';')) - { - SET_TOKEN_TYPE (awk, TOKEN_SEMICOLON); - ADD_TOKEN_CHAR (awk, c); - GET_CHAR (awk); - } - else if (c == ASE_T(':')) - { - SET_TOKEN_TYPE (awk, TOKEN_COLON); - ADD_TOKEN_CHAR (awk, c); - GET_CHAR (awk); - } - else if (c == ASE_T('?')) - { - SET_TOKEN_TYPE (awk, TOKEN_QUEST); - ADD_TOKEN_CHAR (awk, c); - GET_CHAR (awk); - } - else - { - ase_char_t cc = (ase_char_t)c; - SETERRARG (awk, ASE_AWK_ELXCHR, awk->token.line, &cc, 1); - return -1; - } - - return 0; -} - -static int get_number (ase_awk_t* awk) -{ - ase_cint_t c; - - ASE_ASSERT (ASE_STR_LEN(&awk->token.name) == 0); - SET_TOKEN_TYPE (awk, TOKEN_INT); - - c = awk->src.lex.curc; - - if (c == ASE_T('0')) - { - ADD_TOKEN_CHAR (awk, c); - GET_CHAR_TO (awk, c); - - if (c == ASE_T('x') || c == ASE_T('X')) - { - /* hexadecimal number */ - do - { - ADD_TOKEN_CHAR (awk, c); - GET_CHAR_TO (awk, c); - } - while (ASE_AWK_ISXDIGIT (awk, c)); - - return 0; - } - #if 0 - else if (c == ASE_T('b') || c == ASE_T('B')) - { - /* binary number */ - do - { - ADD_TOKEN_CHAR (awk, c); - GET_CHAR_TO (awk, c); - } - while (c == ASE_T('0') || c == ASE_T('1')); - - return 0; - } - #endif - else if (c != '.') - { - /* octal number */ - while (c >= ASE_T('0') && c <= ASE_T('7')) - { - ADD_TOKEN_CHAR (awk, c); - GET_CHAR_TO (awk, c); - } - - return 0; - } - } - - while (ASE_AWK_ISDIGIT (awk, c)) - { - ADD_TOKEN_CHAR (awk, c); - GET_CHAR_TO (awk, c); - } - - if (c == ASE_T('.')) - { - /* floating-point number */ - SET_TOKEN_TYPE (awk, TOKEN_REAL); - - ADD_TOKEN_CHAR (awk, c); - GET_CHAR_TO (awk, c); - - while (ASE_AWK_ISDIGIT (awk, c)) - { - ADD_TOKEN_CHAR (awk, c); - GET_CHAR_TO (awk, c); - } - } - - if (c == ASE_T('E') || c == ASE_T('e')) - { - SET_TOKEN_TYPE (awk, TOKEN_REAL); - - ADD_TOKEN_CHAR (awk, c); - GET_CHAR_TO (awk, c); - - if (c == ASE_T('+') || c == ASE_T('-')) - { - ADD_TOKEN_CHAR (awk, c); - GET_CHAR_TO (awk, c); - } - - while (ASE_AWK_ISDIGIT (awk, c)) - { - ADD_TOKEN_CHAR (awk, c); - GET_CHAR_TO (awk, c); - } - } - - return 0; -} - -static int get_charstr (ase_awk_t* awk) -{ - if (awk->src.lex.curc != ASE_T('\"')) - { - /* the starting quote has been consumed before this function - * has been called */ - ADD_TOKEN_CHAR (awk, awk->src.lex.curc); - } - return get_string (awk, ASE_T('\"'), ASE_T('\\'), ase_false); -} - -static int get_rexstr (ase_awk_t* awk) -{ - if (awk->src.lex.curc == ASE_T('/')) - { - /* this part of the function is different from get_charstr - * because of the way this function is called */ - GET_CHAR (awk); - return 0; - } - else - { - ADD_TOKEN_CHAR (awk, awk->src.lex.curc); - return get_string (awk, ASE_T('/'), ASE_T('\\'), ase_true); - } -} - -static int get_string ( - ase_awk_t* awk, ase_char_t end_char, - ase_char_t esc_char, ase_bool_t keep_esc_char) -{ - ase_cint_t c; - int escaped = 0; - int digit_count = 0; - ase_cint_t c_acc = 0; - - while (1) - { - GET_CHAR_TO (awk, c); - - if (c == ASE_CHAR_EOF) - { - SETERRTOK (awk, ASE_AWK_EENDSTR); - return -1; - } - - if (escaped == 3) - { - if (c >= ASE_T('0') && c <= ASE_T('7')) - { - c_acc = c_acc * 8 + c - ASE_T('0'); - digit_count++; - if (digit_count >= escaped) - { - ADD_TOKEN_CHAR (awk, c_acc); - escaped = 0; - } - continue; - } - else - { - ADD_TOKEN_CHAR (awk, c_acc); - escaped = 0; - } - } - else if (escaped == 2 || escaped == 4 || escaped == 8) - { - if (c >= ASE_T('0') && c <= ASE_T('9')) - { - c_acc = c_acc * 16 + c - ASE_T('0'); - digit_count++; - if (digit_count >= escaped) - { - ADD_TOKEN_CHAR (awk, c_acc); - escaped = 0; - } - continue; - } - else if (c >= ASE_T('A') && c <= ASE_T('F')) - { - c_acc = c_acc * 16 + c - ASE_T('A') + 10; - digit_count++; - if (digit_count >= escaped) - { - ADD_TOKEN_CHAR (awk, c_acc); - escaped = 0; - } - continue; - } - else if (c >= ASE_T('a') && c <= ASE_T('f')) - { - c_acc = c_acc * 16 + c - ASE_T('a') + 10; - digit_count++; - if (digit_count >= escaped) - { - ADD_TOKEN_CHAR (awk, c_acc); - escaped = 0; - } - continue; - } - else - { - ase_char_t rc; - - rc = (escaped == 2)? ASE_T('x'): - (escaped == 4)? ASE_T('u'): ASE_T('U'); - - if (digit_count == 0) ADD_TOKEN_CHAR (awk, rc); - else ADD_TOKEN_CHAR (awk, c_acc); - - escaped = 0; - } - } - - if (escaped == 0 && c == end_char) - { - /* terminating quote */ - /*GET_CHAR_TO (awk, c);*/ - GET_CHAR (awk); - break; - } - - if (escaped == 0 && c == esc_char) - { - escaped = 1; - continue; - } - - if (escaped == 1) - { - if (c == ASE_T('n')) c = ASE_T('\n'); - else if (c == ASE_T('r')) c = ASE_T('\r'); - else if (c == ASE_T('t')) c = ASE_T('\t'); - else if (c == ASE_T('f')) c = ASE_T('\f'); - else if (c == ASE_T('b')) c = ASE_T('\b'); - else if (c == ASE_T('v')) c = ASE_T('\v'); - else if (c == ASE_T('a')) c = ASE_T('\a'); - else if (c >= ASE_T('0') && c <= ASE_T('7')) - { - escaped = 3; - digit_count = 1; - c_acc = c - ASE_T('0'); - continue; - } - else if (c == ASE_T('x')) - { - escaped = 2; - digit_count = 0; - c_acc = 0; - continue; - } - #ifdef ASE_CHAR_IS_WCHAR - else if (c == ASE_T('u') && ASE_SIZEOF(ase_char_t) >= 2) - { - escaped = 4; - digit_count = 0; - c_acc = 0; - continue; - } - else if (c == ASE_T('U') && ASE_SIZEOF(ase_char_t) >= 4) - { - escaped = 8; - digit_count = 0; - c_acc = 0; - continue; - } - #endif - else if (keep_esc_char) - { - ADD_TOKEN_CHAR (awk, esc_char); - } - - escaped = 0; - } - - ADD_TOKEN_CHAR (awk, c); - } - - return 0; -} - -static int get_char (ase_awk_t* awk) -{ - ase_ssize_t n; - /*ase_char_t c;*/ - - if (awk->src.lex.ungotc_count > 0) - { - awk->src.lex.curc = awk->src.lex.ungotc[--awk->src.lex.ungotc_count]; - awk->src.lex.line = awk->src.lex.ungotc_line[awk->src.lex.ungotc_count]; - awk->src.lex.column = awk->src.lex.ungotc_column[awk->src.lex.ungotc_count]; - return 0; - } - - if (awk->src.shared.buf_pos >= awk->src.shared.buf_len) - { - CLRERR (awk); - n = awk->src.ios.in ( - ASE_AWK_IO_READ, awk->src.ios.custom_data, - awk->src.shared.buf, ASE_COUNTOF(awk->src.shared.buf)); - if (n <= -1) - { - if (ISNOERR(awk)) SETERR (awk, ASE_AWK_ESINRD); - return -1; - } - - if (n == 0) - { - awk->src.lex.curc = ASE_CHAR_EOF; - return 0; - } - - awk->src.shared.buf_pos = 0; - awk->src.shared.buf_len = n; - } - - awk->src.lex.curc = awk->src.shared.buf[awk->src.shared.buf_pos++]; - - if (awk->src.lex.curc == ASE_T('\n')) - { - awk->src.lex.line++; - awk->src.lex.column = 1; - } - else awk->src.lex.column++; - - return 0; -} - -static int unget_char (ase_awk_t* awk, ase_cint_t c) -{ - if (awk->src.lex.ungotc_count >= ASE_COUNTOF(awk->src.lex.ungotc)) - { - SETERRLIN (awk, ASE_AWK_ELXUNG, awk->src.lex.line); - return -1; - } - - awk->src.lex.ungotc_line[awk->src.lex.ungotc_count] = awk->src.lex.line; - awk->src.lex.ungotc_column[awk->src.lex.ungotc_count] = awk->src.lex.column; - awk->src.lex.ungotc[awk->src.lex.ungotc_count++] = c; - return 0; -} - -static int skip_spaces (ase_awk_t* awk) -{ - ase_cint_t c = awk->src.lex.curc; - while (ASE_AWK_ISSPACE (awk, c)) GET_CHAR_TO (awk, c); - return 0; -} - -static int skip_comment (ase_awk_t* awk) -{ - ase_cint_t c = awk->src.lex.curc; - ase_size_t line, column; - - if (c == ASE_T('#')) - { - do - { - GET_CHAR_TO (awk, c); - } - while (c != ASE_T('\n') && c != ASE_CHAR_EOF); - - GET_CHAR (awk); - return 1; /* comment by # */ - } - - if (c != ASE_T('/')) return 0; /* not a comment */ - - line = awk->src.lex.line; - column = awk->src.lex.column; - GET_CHAR_TO (awk, c); - - if (c == ASE_T('*')) - { - do - { - GET_CHAR_TO (awk, c); - if (c == ASE_CHAR_EOF) - { - SETERRLIN (awk, ASE_AWK_EENDCMT, awk->src.lex.line); - return -1; - } - - if (c == ASE_T('*')) - { - GET_CHAR_TO (awk, c); - if (c == ASE_CHAR_EOF) - { - SETERRLIN (awk, ASE_AWK_EENDCMT, awk->src.lex.line); - return -1; - } - - if (c == ASE_T('/')) - { - /*GET_CHAR_TO (awk, c);*/ - GET_CHAR (awk); - break; - } - } - } - while (1); - - return 1; /* c-style comment */ - } - - if (unget_char (awk, c) == -1) return -1; /* error */ - awk->src.lex.curc = ASE_T('/'); - awk->src.lex.line = line; - awk->src.lex.column = column; - - return 0; -} - -static int classify_ident ( - ase_awk_t* awk, const ase_char_t* name, ase_size_t len) -{ - kwent_t* kwp; - - for (kwp = kwtab; kwp->name != ASE_NULL; kwp++) - { - if (kwp->valid != 0 && - (awk->option & kwp->valid) == 0) continue; - - if (ase_strxncmp (kwp->name, kwp->name_len, name, len) == 0) - { - return kwp->type; - } - } - - return TOKEN_IDENT; -} - -static int assign_to_opcode (ase_awk_t* awk) -{ - static int assop[] = - { - ASE_AWK_ASSOP_NONE, - ASE_AWK_ASSOP_PLUS, - ASE_AWK_ASSOP_MINUS, - ASE_AWK_ASSOP_MUL, - ASE_AWK_ASSOP_DIV, - ASE_AWK_ASSOP_IDIV, - ASE_AWK_ASSOP_MOD, - ASE_AWK_ASSOP_EXP - }; - - if (awk->token.type >= TOKEN_ASSIGN && - awk->token.type <= TOKEN_EXP_ASSIGN) - { - return assop[awk->token.type - TOKEN_ASSIGN]; - } - - return -1; -} - -static int is_plain_var (ase_awk_nde_t* nde) -{ - return nde->type == ASE_AWK_NDE_GLOBAL || - nde->type == ASE_AWK_NDE_LOCAL || - nde->type == ASE_AWK_NDE_ARG || - nde->type == ASE_AWK_NDE_NAMED; -} - -static int is_var (ase_awk_nde_t* nde) -{ - return nde->type == ASE_AWK_NDE_GLOBAL || - nde->type == ASE_AWK_NDE_LOCAL || - nde->type == ASE_AWK_NDE_ARG || - nde->type == ASE_AWK_NDE_NAMED || - nde->type == ASE_AWK_NDE_GLOBALIDX || - nde->type == ASE_AWK_NDE_LOCALIDX || - nde->type == ASE_AWK_NDE_ARGIDX || - nde->type == ASE_AWK_NDE_NAMEDIDX; -} - -struct deparse_func_t -{ - ase_awk_t* awk; - ase_char_t* tmp; - ase_size_t tmp_len; -}; - -static int deparse (ase_awk_t* awk) -{ - ase_awk_chain_t* chain; - ase_char_t tmp[ASE_SIZEOF(ase_size_t)*8 + 32]; - struct deparse_func_t df; - int n = 0, op; - - ASE_ASSERT (awk->src.ios.out != ASE_NULL); - - awk->src.shared.buf_len = 0; - awk->src.shared.buf_pos = 0; - - CLRERR (awk); - op = awk->src.ios.out ( - ASE_AWK_IO_OPEN, awk->src.ios.custom_data, ASE_NULL, 0); - if (op <= -1) - { - if (ISNOERR(awk)) SETERR (awk, ASE_AWK_ESOUTOP); - return -1; - } - - if (op == 0) - { - /* the result of the open operation indicates that the - * file has been open but reached the end. so it has to - * skip the entire deparsing procedure as it can't write - * any single characters on such an io handler. but note - * that this is not really an error for the parse and deparser. - * - * in fact, there are two ways to skip deparsing. - * 1. set awk->src.ios.out to NULL. - * 2. set awk->src.ios.out to a normal handler but - * make it return 0 on the OPEN request. - */ - n = 0; - goto exit_deparse; - } - -#define EXIT_DEPARSE() do { n = -1; goto exit_deparse; } while(0) - - if (awk->tree.nglobals > awk->tree.nbglobals) - { - ase_size_t i/*, len*/; - - ASE_ASSERT (awk->tree.nglobals > 0); - if (ase_awk_putsrcstr (awk, ASE_T("global ")) == -1) - { - EXIT_DEPARSE (); - } - - for (i = awk->tree.nbglobals; i < awk->tree.nglobals - 1; i++) - { - /* - len = ase_awk_longtostr ((ase_long_t)i, - 10, ASE_T("__global"), tmp, ASE_COUNTOF(tmp)); - ASE_ASSERT (len != (ase_size_t)-1); - if (ase_awk_putsrcstrx (awk, tmp, len) == -1) - { - EXIT_DEPARSE (); - } - */ - if (ase_awk_putsrcstrx (awk, - awk->parse.globals.buf[i].name, - awk->parse.globals.buf[i].name_len) == -1) - { - EXIT_DEPARSE (); - } - - if (ase_awk_putsrcstr (awk, ASE_T(", ")) == -1) - EXIT_DEPARSE (); - } - - /* - len = ase_awk_longtostr ((ase_long_t)i, - 10, ASE_T("__global"), tmp, ASE_COUNTOF(tmp)); - ASE_ASSERT (len != (ase_size_t)-1); - if (ase_awk_putsrcstrx (awk, tmp, len) == -1) - { - EXIT_DEPARSE (); - } - */ - if (ase_awk_putsrcstrx (awk, - awk->parse.globals.buf[i].name, - awk->parse.globals.buf[i].name_len) == -1) - { - EXIT_DEPARSE (); - } - - if (awk->option & ASE_AWK_CRLF) - { - if (ase_awk_putsrcstr (awk, ASE_T(";\r\n\r\n")) == -1) - { - EXIT_DEPARSE (); - } - } - else - { - if (ase_awk_putsrcstr (awk, ASE_T(";\n\n")) == -1) - { - EXIT_DEPARSE (); - } - } - } - - df.awk = awk; - df.tmp = tmp; - df.tmp_len = ASE_COUNTOF(tmp); - - if (ase_awk_map_walk (&awk->tree.afns, deparse_func, &df) == -1) - { - EXIT_DEPARSE (); - } - - if (awk->tree.begin != ASE_NULL) - { - if (ase_awk_putsrcstr (awk, ASE_T("BEGIN ")) == -1) - { - EXIT_DEPARSE (); - } - - if (ase_awk_prnpt (awk, awk->tree.begin) == -1) EXIT_DEPARSE (); - - if (awk->option & ASE_AWK_CRLF) - { - if (put_char (awk, ASE_T('\r')) == -1) - EXIT_DEPARSE (); - } - - if (put_char (awk, ASE_T('\n')) == -1) EXIT_DEPARSE (); - } - - chain = awk->tree.chain; - while (chain != ASE_NULL) - { - if (chain->pattern != ASE_NULL) - { - if (ase_awk_prnptnpt (awk, chain->pattern) == -1) - EXIT_DEPARSE (); - } - - if (chain->action == ASE_NULL) - { - /* blockless pattern */ - if (awk->option & ASE_AWK_CRLF) - { - if (put_char (awk, ASE_T('\r')) == -1) - EXIT_DEPARSE (); - } - - if (put_char (awk, ASE_T('\n')) == -1) - EXIT_DEPARSE (); - } - else - { - if (chain->pattern != ASE_NULL) - { - if (put_char (awk, ASE_T(' ')) == -1) - EXIT_DEPARSE (); - } - if (ase_awk_prnpt (awk, chain->action) == -1) - EXIT_DEPARSE (); - } - - if (awk->option & ASE_AWK_CRLF) - { - if (put_char (awk, ASE_T('\r')) == -1) - EXIT_DEPARSE (); - } - - if (put_char (awk, ASE_T('\n')) == -1) - EXIT_DEPARSE (); - - chain = chain->next; - } - - if (awk->tree.end != ASE_NULL) - { - if (ase_awk_putsrcstr (awk, ASE_T("END ")) == -1) - EXIT_DEPARSE (); - if (ase_awk_prnpt (awk, awk->tree.end) == -1) - EXIT_DEPARSE (); - } - - if (flush_out (awk) == -1) EXIT_DEPARSE (); - -exit_deparse: - if (n == 0) CLRERR (awk); - if (awk->src.ios.out ( - ASE_AWK_IO_CLOSE, awk->src.ios.custom_data, ASE_NULL, 0) != 0) - { - if (n == 0) - { - if (ISNOERR(awk)) SETERR (awk, ASE_AWK_ESOUTCL); - n = -1; - } - } - - return n; -} - -static int deparse_func (ase_awk_pair_t* pair, void* arg) -{ - struct deparse_func_t* df = (struct deparse_func_t*)arg; - ase_awk_afn_t* afn = (ase_awk_afn_t*)pair->val; - ase_size_t i, n; - - ASE_ASSERT (ase_strxncmp (pair->key, pair->key_len, afn->name, afn->name_len) == 0); - - if (ase_awk_putsrcstr (df->awk, ASE_T("function ")) == -1) return -1; - if (ase_awk_putsrcstr (df->awk, afn->name) == -1) return -1; - if (ase_awk_putsrcstr (df->awk, ASE_T(" (")) == -1) return -1; - - for (i = 0; i < afn->nargs; ) - { - n = ase_awk_longtostr (i++, 10, - ASE_T("__param"), df->tmp, df->tmp_len); - ASE_ASSERT (n != (ase_size_t)-1); - if (ase_awk_putsrcstrx (df->awk, df->tmp, n) == -1) return -1; - if (i >= afn->nargs) break; - if (ase_awk_putsrcstr (df->awk, ASE_T(", ")) == -1) return -1; - } - - if (ase_awk_putsrcstr (df->awk, ASE_T(")")) == -1) return -1; - if (df->awk->option & ASE_AWK_CRLF) - { - if (put_char (df->awk, ASE_T('\r')) == -1) return -1; - } - if (put_char (df->awk, ASE_T('\n')) == -1) return -1; - - if (ase_awk_prnpt (df->awk, afn->body) == -1) return -1; - if (df->awk->option & ASE_AWK_CRLF) - { - if (put_char (df->awk, ASE_T('\r')) == -1) return -1; - } - if (put_char (df->awk, ASE_T('\n')) == -1) return -1; - - return 0; -} - -static int put_char (ase_awk_t* awk, ase_char_t c) -{ - awk->src.shared.buf[awk->src.shared.buf_len++] = c; - if (awk->src.shared.buf_len >= ASE_COUNTOF(awk->src.shared.buf)) - { - if (flush_out (awk) == -1) return -1; - } - return 0; -} - -static int flush_out (ase_awk_t* awk) -{ - ase_ssize_t n; - - ASE_ASSERT (awk->src.ios.out != ASE_NULL); - - while (awk->src.shared.buf_pos < awk->src.shared.buf_len) - { - CLRERR (awk); - - n = awk->src.ios.out ( - ASE_AWK_IO_WRITE, awk->src.ios.custom_data, - &awk->src.shared.buf[awk->src.shared.buf_pos], - awk->src.shared.buf_len - awk->src.shared.buf_pos); - if (n <= 0) - { - if (ISNOERR(awk)) SETERR (awk, ASE_AWK_ESOUTWR); - return -1; - } - - awk->src.shared.buf_pos += n; - } - - awk->src.shared.buf_pos = 0; - awk->src.shared.buf_len = 0; - return 0; -} - -int ase_awk_putsrcstr (ase_awk_t* awk, const ase_char_t* str) -{ - while (*str != ASE_T('\0')) - { - if (put_char (awk, *str) == -1) return -1; - str++; - } - - return 0; -} - -int ase_awk_putsrcstrx ( - ase_awk_t* awk, const ase_char_t* str, ase_size_t len) -{ - const ase_char_t* end = str + len; - - while (str < end) - { - if (put_char (awk, *str) == -1) return -1; - str++; - } - - return 0; -} - diff --git a/ase/awk/parse.h b/ase/awk/parse.h deleted file mode 100644 index 8d49d01d..00000000 --- a/ase/awk/parse.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * $Id: parse.h,v 1.1.1.1 2007/03/28 14:05:17 bacon Exp $ - * - * {License} - */ - -#ifndef _ASE_AWK_PARSE_H_ -#define _ASE_AWK_PARSE_H_ - -#ifndef _ASE_AWK_AWK_H_ -#error Never include this file directly. Include instead -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -int ase_awk_putsrcstr (ase_awk_t* awk, const ase_char_t* str); -int ase_awk_putsrcstrx ( - ase_awk_t* awk, const ase_char_t* str, ase_size_t len); - -const ase_char_t* ase_awk_getglobalname ( - ase_awk_t* awk, ase_size_t idx, ase_size_t* len); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ase/awk/rec.c b/ase/awk/rec.c deleted file mode 100644 index ae2c41d6..00000000 --- a/ase/awk/rec.c +++ /dev/null @@ -1,449 +0,0 @@ -/* - * $Id: rec.c,v 1.1.1.1 2007/03/28 14:05:17 bacon Exp $ - * - * {License} - */ - -#include - -static int __split_record (ase_awk_run_t* run); -static int __recomp_record_fields ( - ase_awk_run_t* run, ase_size_t lv, - const ase_char_t* str, ase_size_t len); - -int ase_awk_setrec ( - ase_awk_run_t* run, ase_size_t idx, - const ase_char_t* str, ase_size_t len) -{ - ase_awk_val_t* v; - - if (idx == 0) - { - if (str == ASE_STR_BUF(&run->inrec.line) && - len == ASE_STR_LEN(&run->inrec.line)) - { - if (ase_awk_clrrec (run, ase_true) == -1) return -1; - } - else - { - if (ase_awk_clrrec (run, ase_false) == -1) return -1; - - if (ase_str_ncpy (&run->inrec.line, str, len) == (ase_size_t)-1) - { - ase_awk_clrrec (run, ase_false); - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - } - - v = ase_awk_makestrval (run, str, len); - if (v == ASE_NULL) - { - ase_awk_clrrec (run, ase_false); - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - - ASE_ASSERT (run->inrec.d0->type == ASE_AWK_VAL_NIL); - /* d0 should be cleared before the next line is reached - * as it doesn't call ase_awk_refdownval on run->inrec.d0 */ - run->inrec.d0 = v; - ase_awk_refupval (run, v); - - if (__split_record (run) == -1) - { - ase_awk_clrrec (run, ase_false); - return -1; - } - } - else - { - if (__recomp_record_fields (run, idx, str, len) == -1) - { - ase_awk_clrrec (run, ase_false); - return -1; - } - - /* recompose $0 */ - v = ase_awk_makestrval (run, - ASE_STR_BUF(&run->inrec.line), - ASE_STR_LEN(&run->inrec.line)); - if (v == ASE_NULL) - { - ase_awk_clrrec (run, ase_false); - ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - - ase_awk_refdownval (run, run->inrec.d0); - run->inrec.d0 = v; - ase_awk_refupval (run, v); - } - - return 0; -} - -static int __split_record (ase_awk_run_t* run) -{ - ase_char_t* p, * tok; - ase_size_t len, tok_len, nflds; - ase_awk_val_t* v, * fs; - ase_char_t* fs_ptr, * fs_free; - ase_size_t fs_len; - int errnum; - - /* inrec should be cleared before __split_record is called */ - ASE_ASSERT (run->inrec.nflds == 0); - - /* get FS */ - fs = ase_awk_getglobal (run, ASE_AWK_GLOBAL_FS); - if (fs->type == ASE_AWK_VAL_NIL) - { - fs_ptr = ASE_T(" "); - fs_len = 1; - fs_free = ASE_NULL; - } - else if (fs->type == ASE_AWK_VAL_STR) - { - fs_ptr = ((ase_awk_val_str_t*)fs)->buf; - fs_len = ((ase_awk_val_str_t*)fs)->len; - fs_free = ASE_NULL; - } - else - { - fs_ptr = ase_awk_valtostr ( - run, fs, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &fs_len); - if (fs_ptr == ASE_NULL) return -1; - fs_free = fs_ptr; - } - - /* scan the input record to count the fields */ - p = ASE_STR_BUF(&run->inrec.line); - len = ASE_STR_LEN(&run->inrec.line); - - nflds = 0; - while (p != ASE_NULL) - { - if (fs_len <= 1) - { - p = ase_awk_strxntok (run, - p, len, fs_ptr, fs_len, &tok, &tok_len); - } - else - { - p = ase_awk_strxntokbyrex (run, p, len, - run->global.fs, &tok, &tok_len, &errnum); - if (p == ASE_NULL && errnum != ASE_AWK_ENOERR) - { - if (fs_free != ASE_NULL) - ASE_AWK_FREE (run->awk, fs_free); - ase_awk_setrunerror (run, errnum, 0, ASE_NULL, 0); - return -1; - } - } - - if (nflds == 0 && p == ASE_NULL && tok_len == 0) - { - /* there are no fields. it can just return here - * as ase_awk_clrrec has been called before this */ - if (fs_free != ASE_NULL) ASE_AWK_FREE (run->awk, fs_free); - return 0; - } - - ASE_ASSERT ((tok != ASE_NULL && tok_len > 0) || tok_len == 0); - - nflds++; - len = ASE_STR_LEN(&run->inrec.line) - - (p - ASE_STR_BUF(&run->inrec.line)); - } - - /* allocate space */ - if (nflds > run->inrec.maxflds) - { - void* tmp = ASE_AWK_MALLOC ( - run->awk, ASE_SIZEOF(*run->inrec.flds) * nflds); - if (tmp == ASE_NULL) - { - if (fs_free != ASE_NULL) ASE_AWK_FREE (run->awk, fs_free); - ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - - if (run->inrec.flds != ASE_NULL) - ASE_AWK_FREE (run->awk, run->inrec.flds); - run->inrec.flds = tmp; - run->inrec.maxflds = nflds; - } - - /* scan again and split it */ - p = ASE_STR_BUF(&run->inrec.line); - len = ASE_STR_LEN(&run->inrec.line); - - while (p != ASE_NULL) - { - if (fs_len <= 1) - { - p = ase_awk_strxntok ( - run, p, len, fs_ptr, fs_len, &tok, &tok_len); - } - else - { - p = ase_awk_strxntokbyrex (run, p, len, - run->global.fs, &tok, &tok_len, &errnum); - if (p == ASE_NULL && errnum != ASE_AWK_ENOERR) - { - if (fs_free != ASE_NULL) - ASE_AWK_FREE (run->awk, fs_free); - ase_awk_setrunerror (run, errnum, 0, ASE_NULL, 0); - return -1; - } - } - - ASE_ASSERT ((tok != ASE_NULL && tok_len > 0) || tok_len == 0); - - run->inrec.flds[run->inrec.nflds].ptr = tok; - run->inrec.flds[run->inrec.nflds].len = tok_len; - run->inrec.flds[run->inrec.nflds].val = - ase_awk_makestrval (run, tok, tok_len); - - if (run->inrec.flds[run->inrec.nflds].val == ASE_NULL) - { - if (fs_free != ASE_NULL) ASE_AWK_FREE (run->awk, fs_free); - ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - - ase_awk_refupval (run, run->inrec.flds[run->inrec.nflds].val); - run->inrec.nflds++; - - len = ASE_STR_LEN(&run->inrec.line) - - (p - ASE_STR_BUF(&run->inrec.line)); - } - - if (fs_free != ASE_NULL) ASE_AWK_FREE (run->awk, fs_free); - - /* set the number of fields */ - v = ase_awk_makeintval (run, (ase_long_t)nflds); - if (v == ASE_NULL) - { - ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - - if (ase_awk_setglobal (run, ASE_AWK_GLOBAL_NF, v) == -1) return -1; - - ASE_ASSERT (nflds == run->inrec.nflds); - return 0; -} - -int ase_awk_clrrec (ase_awk_run_t* run, ase_bool_t skip_inrec_line) -{ - ase_size_t i; - int n = 0; - - if (run->inrec.d0 != ase_awk_val_nil) - { - ase_awk_refdownval (run, run->inrec.d0); - run->inrec.d0 = ase_awk_val_nil; - } - - if (run->inrec.nflds > 0) - { - ASE_ASSERT (run->inrec.flds != ASE_NULL); - - for (i = 0; i < run->inrec.nflds; i++) - { - ASE_ASSERT (run->inrec.flds[i].val != ASE_NULL); - ase_awk_refdownval (run, run->inrec.flds[i].val); - } - run->inrec.nflds = 0; - - if (ase_awk_setglobal ( - run, ASE_AWK_GLOBAL_NF, ase_awk_val_zero) == -1) - { - /* first of all, this should never happen. - * if it happened, it would return an error - * after all the clearance tasks */ - n = -1; - } - } - - ASE_ASSERT (run->inrec.nflds == 0); - if (!skip_inrec_line) ase_str_clear (&run->inrec.line); - - return n; -} - -static int __recomp_record_fields ( - ase_awk_run_t* run, ase_size_t lv, - const ase_char_t* str, ase_size_t len) -{ - ase_awk_val_t* v; - ase_size_t max, i, nflds; - - /* recomposes the record and the fields when $N has been assigned - * a new value and recomputes NF accordingly */ - - ASE_ASSERT (lv > 0); - max = (lv > run->inrec.nflds)? lv: run->inrec.nflds; - - nflds = run->inrec.nflds; - if (max > run->inrec.maxflds) - { - void* tmp; - - /* if the given field number is greater than the maximum - * number of fields that the current record can hold, - * the field spaces are resized */ - - if (run->awk->prmfns.mmgr.realloc != ASE_NULL) - { - tmp = ASE_AWK_REALLOC ( - run->awk, run->inrec.flds, - ASE_SIZEOF(*run->inrec.flds) * max); - if (tmp == ASE_NULL) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - } - else - { - tmp = ASE_AWK_MALLOC ( - run->awk, ASE_SIZEOF(*run->inrec.flds) * max); - if (tmp == ASE_NULL) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - if (run->inrec.flds != ASE_NULL) - { - ase_memcpy (tmp, run->inrec.flds, - ASE_SIZEOF(*run->inrec.flds)*run->inrec.maxflds); - ASE_AWK_FREE (run->awk, run->inrec.flds); - } - } - - run->inrec.flds = tmp; - run->inrec.maxflds = max; - } - - lv = lv - 1; /* adjust the value to 0-based index */ - - ase_str_clear (&run->inrec.line); - - for (i = 0; i < max; i++) - { - if (i > 0) - { - if (ase_str_ncat ( - &run->inrec.line, - run->global.ofs.ptr, - run->global.ofs.len) == (ase_size_t)-1) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - } - - if (i == lv) - { - ase_awk_val_t* tmp; - - run->inrec.flds[i].ptr = - ASE_STR_BUF(&run->inrec.line) + - ASE_STR_LEN(&run->inrec.line); - run->inrec.flds[i].len = len; - - if (ase_str_ncat ( - &run->inrec.line, str, len) == (ase_size_t)-1) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - - tmp = ase_awk_makestrval (run, str,len); - if (tmp == ASE_NULL) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - - if (i < nflds) - ase_awk_refdownval (run, run->inrec.flds[i].val); - else run->inrec.nflds++; - - run->inrec.flds[i].val = tmp; - ase_awk_refupval (run, tmp); - } - else if (i >= nflds) - { - run->inrec.flds[i].ptr = - ASE_STR_BUF(&run->inrec.line) + - ASE_STR_LEN(&run->inrec.line); - run->inrec.flds[i].len = 0; - - if (ase_str_cat ( - &run->inrec.line, ASE_T("")) == (ase_size_t)-1) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - - /* ase_awk_refdownval should not be called over - * run->inrec.flds[i].val as it is not initialized - * to any valid values */ - /*ase_awk_refdownval (run, run->inrec.flds[i].val);*/ - run->inrec.flds[i].val = ase_awk_val_zls; - ase_awk_refupval (run, ase_awk_val_zls); - run->inrec.nflds++; - } - else - { - ase_awk_val_str_t* tmp; - - tmp = (ase_awk_val_str_t*)run->inrec.flds[i].val; - - run->inrec.flds[i].ptr = - ASE_STR_BUF(&run->inrec.line) + - ASE_STR_LEN(&run->inrec.line); - run->inrec.flds[i].len = tmp->len; - - if (ase_str_ncat (&run->inrec.line, - tmp->buf, tmp->len) == (ase_size_t)-1) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - } - } - - v = ase_awk_getglobal (run, ASE_AWK_GLOBAL_NF); - ASE_ASSERT (v->type == ASE_AWK_VAL_INT); - - if (((ase_awk_val_int_t*)v)->val != max) - { - v = ase_awk_makeintval (run, (ase_long_t)max); - if (v == ASE_NULL) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - - if (ase_awk_setglobal ( - run, ASE_AWK_GLOBAL_NF, v) == -1) return -1; - } - - return 0; -} - diff --git a/ase/awk/rex.c b/ase/awk/rex.c deleted file mode 100644 index b94b6316..00000000 --- a/ase/awk/rex.c +++ /dev/null @@ -1,1880 +0,0 @@ -/* - * $Id: rex.c,v 1.1.1.1 2007/03/28 14:05:17 bacon Exp $ - * - * {License} - */ - -#include - -#ifdef DEBUG_REX -#include -#endif - -enum -{ - CT_EOF, - CT_SPECIAL, - CT_NORMAL -}; - -enum -{ - LEVEL_TOP, - LEVEL_CHARSET, - LEVEL_RANGE -}; - -enum -{ - CMD_BOL, - CMD_EOL, - CMD_ANY_CHAR, - CMD_ORD_CHAR, - CMD_CHARSET, - CMD_GROUP -}; - -enum -{ - CHARSET_ONE, - CHARSET_RANGE, - CHARSET_CLASS -}; - -enum -{ - CHARSET_CLASS_PUNCT, - CHARSET_CLASS_SPACE, - CHARSET_CLASS_DIGIT, - CHARSET_CLASS_ALNUM -}; - -#define DEF_CODE_CAPA 512 -#define BOUND_MIN 0 -#define BOUND_MAX (ASE_TYPE_MAX(ase_size_t)) - -typedef struct builder_t builder_t; -typedef struct matcher_t matcher_t; -typedef struct match_t match_t; - -typedef struct code_t code_t; -typedef struct rhdr_t rhdr_t; -typedef struct bhdr_t bhdr_t; -typedef struct cshdr_t cshdr_t; - -struct builder_t -{ - ase_awk_t* awk; - - struct - { - const ase_char_t* ptr; - const ase_char_t* end; - const ase_char_t* curp; - struct - { - int type; - ase_char_t value; - } curc; - } ptn; - - struct - { - ase_byte_t* buf; - ase_size_t size; - ase_size_t capa; - } code; - - struct - { - int max; - int cur; - } depth; - - int errnum; -}; - -struct matcher_t -{ - ase_awk_t* awk; - - struct - { - struct - { - const ase_char_t* ptr; - const ase_char_t* end; - } str; - } match; - - struct - { - int max; - int cur; - } depth; - - int ignorecase; - int errnum; -}; - -struct match_t -{ - const ase_char_t* match_ptr; - - ase_bool_t matched; - ase_size_t match_len; - - const ase_byte_t* branch; - const ase_byte_t* branch_end; -}; - -#include - -ASE_BEGIN_PACKED_STRUCT (code_t) - /*ase_byte_t cmd;*/ - short cmd; - short negate; /* only for CMD_CHARSET */ - ase_size_t lbound; - ase_size_t ubound; -ASE_END_PACKED_STRUCT () - -/* compiled regular expression header */ -ASE_BEGIN_PACKED_STRUCT (rhdr_t) - ase_size_t nb; /* number of branches */ - ase_size_t el; /* expression length in bytes */ -ASE_END_PACKED_STRUCT () - -/* branch header */ -ASE_BEGIN_PACKED_STRUCT (bhdr_t) - ase_size_t na; /* number of atoms */ - ase_size_t bl; /* branch length in bytes */ -ASE_END_PACKED_STRUCT () - -/* character set header */ -ASE_BEGIN_PACKED_STRUCT (cshdr_t) - ase_size_t csc; /* count */ - ase_size_t csl; /* length */ -ASE_END_PACKED_STRUCT () - -#include - -typedef const ase_byte_t* (*atom_matcher_t) ( - matcher_t* matcher, const ase_byte_t* base, match_t* mat); - -#define NCHARS_REMAINING(rex) ((rex)->ptn.end - (rex)->ptn.curp) - -#define NEXT_CHAR(rex,level) \ - do { if (__next_char(rex,level) == -1) return -1; } while (0) - -#define ADD_CODE(rex,data,len) \ - do { if (__add_code(rex,data,len) == -1) return -1; } while (0) - -static int __build_pattern (builder_t* rex); -static int __build_pattern0 (builder_t* rex); -static int __build_branch (builder_t* rex); -static int __build_atom (builder_t* rex); -static int __build_charset (builder_t* rex, code_t* cmd); -static int __build_occurrences (builder_t* rex, code_t* cmd); -static int __build_cclass (builder_t* rex, ase_char_t* cc); -static int __build_range (builder_t* rex, code_t* cmd); -static int __next_char (builder_t* rex, int level); -static int __add_code (builder_t* rex, void* data, ase_size_t len); - -static ase_bool_t __begin_with ( - const ase_char_t* str, ase_size_t len, const ase_char_t* what); - -static const ase_byte_t* __match_pattern ( - matcher_t* matcher, const ase_byte_t* base, match_t* mat); -static const ase_byte_t* __match_branch ( - matcher_t* matcher, const ase_byte_t* base, match_t* mat); -static const ase_byte_t* __match_branch_body ( - matcher_t* matcher, const ase_byte_t* base, match_t* mat); -static const ase_byte_t* __match_branch_body0 ( - matcher_t* matcher, const ase_byte_t* base, match_t* mat); -static const ase_byte_t* __match_atom ( - matcher_t* matcher, const ase_byte_t* base, match_t* mat); -static const ase_byte_t* __match_bol ( - matcher_t* matcher, const ase_byte_t* base, match_t* mat); -static const ase_byte_t* __match_eol ( - matcher_t* matcher, const ase_byte_t* base, match_t* mat); -static const ase_byte_t* __match_any_char ( - matcher_t* matcher, const ase_byte_t* base, match_t* mat); -static const ase_byte_t* __match_ord_char ( - matcher_t* matcher, const ase_byte_t* base, match_t* mat); -static const ase_byte_t* __match_charset ( - matcher_t* matcher, const ase_byte_t* base, match_t* mat); -static const ase_byte_t* __match_group ( - matcher_t* matcher, const ase_byte_t* base, match_t* mat); - -static const ase_byte_t* __match_occurrences ( - matcher_t* matcher, ase_size_t si, const ase_byte_t* p, - ase_size_t lbound, ase_size_t ubound, match_t* mat); - -static ase_bool_t __test_charset ( - matcher_t* matcher, const ase_byte_t* p, ase_size_t csc, ase_char_t c); - -static ase_bool_t cc_isalnum (ase_awk_t* awk, ase_char_t c); -static ase_bool_t cc_isalpha (ase_awk_t* awk, ase_char_t c); -static ase_bool_t cc_isblank (ase_awk_t* awk, ase_char_t c); -static ase_bool_t cc_iscntrl (ase_awk_t* awk, ase_char_t c); -static ase_bool_t cc_isdigit (ase_awk_t* awk, ase_char_t c); -static ase_bool_t cc_isgraph (ase_awk_t* awk, ase_char_t c); -static ase_bool_t cc_islower (ase_awk_t* awk, ase_char_t c); -static ase_bool_t cc_isprint (ase_awk_t* awk, ase_char_t c); -static ase_bool_t cc_ispunct (ase_awk_t* awk, ase_char_t c); -static ase_bool_t cc_isspace (ase_awk_t* awk, ase_char_t c); -static ase_bool_t cc_isupper (ase_awk_t* awk, ase_char_t c); -static ase_bool_t cc_isxdigit (ase_awk_t* awk, ase_char_t c); - -static const ase_byte_t* __print_pattern (ase_awk_t* awk, const ase_byte_t* p); -static const ase_byte_t* __print_branch (ase_awk_t* awk, const ase_byte_t* p); -static const ase_byte_t* __print_atom (ase_awk_t* awk, const ase_byte_t* p); - -struct __char_class_t -{ - const ase_char_t* name; - ase_size_t name_len; - ase_bool_t (*func) (ase_awk_t* awk, ase_char_t c); -}; - -static struct __char_class_t __char_class[] = -{ - { ASE_T("alnum"), 5, cc_isalnum }, - { ASE_T("alpha"), 5, cc_isalpha }, - { ASE_T("blank"), 5, cc_isblank }, - { ASE_T("cntrl"), 5, cc_iscntrl }, - { ASE_T("digit"), 5, cc_isdigit }, - { ASE_T("graph"), 5, cc_isgraph }, - { ASE_T("lower"), 5, cc_islower }, - { ASE_T("print"), 5, cc_isprint }, - { ASE_T("punct"), 5, cc_ispunct }, - { ASE_T("space"), 5, cc_isspace }, - { ASE_T("upper"), 5, cc_isupper }, - { ASE_T("xdigit"), 6, cc_isxdigit }, - - /* - { ASE_T("arabic"), 6, cc_isarabic }, - { ASE_T("chinese"), 7, cc_ischinese }, - { ASE_T("english"), 7, cc_isenglish }, - { ASE_T("japanese"), 8, cc_isjapanese }, - { ASE_T("korean"), 6, cc_iskorean }, - { ASE_T("thai"), 4, cc_isthai }, - */ - - { ASE_NULL, 0, ASE_NULL } -}; - -void* ase_awk_buildrex ( - ase_awk_t* awk, const ase_char_t* ptn, ase_size_t len, int* errnum) -{ - builder_t builder; - - builder.awk = awk; - builder.code.capa = DEF_CODE_CAPA; - builder.code.size = 0; - builder.code.buf = (ase_byte_t*) - ASE_AWK_MALLOC (builder.awk, builder.code.capa); - if (builder.code.buf == ASE_NULL) - { - *errnum = ASE_AWK_ENOMEM; - return ASE_NULL; - } - - builder.ptn.ptr = ptn; - builder.ptn.end = builder.ptn.ptr + len; - builder.ptn.curp = builder.ptn.ptr; - - builder.ptn.curc.type = CT_EOF; - builder.ptn.curc.value = ASE_T('\0'); - - builder.depth.max = awk->rex.depth.max.build; - builder.depth.cur = 0; - - if (__next_char (&builder, LEVEL_TOP) == -1) - { - if (errnum != ASE_NULL) *errnum = builder.errnum; - ASE_AWK_FREE (builder.awk, builder.code.buf); - return ASE_NULL; - } - - if (__build_pattern (&builder) == -1) - { - if (errnum != ASE_NULL) *errnum = builder.errnum; - ASE_AWK_FREE (builder.awk, builder.code.buf); - return ASE_NULL; - } - - if (builder.ptn.curc.type != CT_EOF) - { - if (errnum != ASE_NULL) - { - if (builder.ptn.curc.type == CT_SPECIAL && - builder.ptn.curc.value == ASE_T(')')) - { - *errnum = ASE_AWK_EREXUNBALPAR; - } - else - { - *errnum = ASE_AWK_EREXGARBAGE; - } - } - - ASE_AWK_FREE (builder.awk, builder.code.buf); - return ASE_NULL; - } - - return builder.code.buf; -} - -int ase_awk_matchrex ( - ase_awk_t* awk, void* code, int option, - const ase_char_t* str, ase_size_t len, - const ase_char_t** match_ptr, ase_size_t* match_len, int* errnum) -{ - matcher_t matcher; - match_t mat; - ase_size_t offset = 0; - /*const ase_char_t* match_ptr_zero = ASE_NULL;*/ - - matcher.awk = awk; - - /* store the source string */ - matcher.match.str.ptr = str; - matcher.match.str.end = str + len; - - matcher.depth.max = awk->rex.depth.max.match; - matcher.depth.cur = 0; - matcher.ignorecase = (option & ASE_AWK_REX_IGNORECASE)? 1: 0; - - mat.matched = ase_false; - /* TODO: should it allow an offset here??? */ - mat.match_ptr = str + offset; - - /*while (mat.match_ptr < matcher.match.str.end)*/ - while (mat.match_ptr <= matcher.match.str.end) - { - if (__match_pattern (&matcher, code, &mat) == ASE_NULL) - { - if (errnum != ASE_NULL) *errnum = matcher.errnum; - return -1; - } - - if (mat.matched) - { - /* - if (mat.match_len == 0) - { - if (match_ptr_zero == ASE_NULL) - match_ptr_zero = mat.match_ptr; - mat.match_ptr++; - continue; - } - */ - - if (match_ptr != ASE_NULL) *match_ptr = mat.match_ptr; - if (match_len != ASE_NULL) *match_len = mat.match_len; - - /*match_ptr_zero = ASE_NULL;*/ - break; - } - - mat.match_ptr++; - } - - /* - if (match_ptr_zero != ASE_NULL) - { - if (match_ptr != ASE_NULL) *match_ptr = match_ptr_zero; - if (match_len != ASE_NULL) *match_len = 0; - return 1; - } - */ - - return (mat.matched)? 1: 0; -} - -void ase_awk_freerex (ase_awk_t* awk, void* code) -{ - ASE_ASSERT (code != ASE_NULL); - ASE_AWK_FREE (awk, code); -} - -ase_bool_t ase_awk_isemptyrex (ase_awk_t* awk, void* code) -{ - rhdr_t* rhdr = (rhdr_t*) code; - ASE_ASSERT (rhdr != ASE_NULL); - - /* an empty regular expression look like: - * | expression | - * | header | branch | - * | | branch header | - * | NB(1) | EL(16) | NA(1) | BL(8) | */ - return (rhdr->nb == 1 && - rhdr->el == ASE_SIZEOF(ase_size_t)*4)? ase_true: ase_false; -} - -static int __build_pattern (builder_t* builder) -{ - int n; - - if (builder->depth.max > 0 && builder->depth.cur >= builder->depth.max) - { - builder->errnum = ASE_AWK_EREXRECUR; - return -1; - } - - builder->depth.cur++; - n = __build_pattern0 (builder); - builder->depth.cur--; - - return n; -} - -static int __build_pattern0 (builder_t* builder) -{ - ase_size_t zero = 0; - ase_size_t old_size; - ase_size_t pos_nb; - rhdr_t* rhdr; - int n; - - old_size = builder->code.size; - - /* secure space for header and set the header fields to zero */ - pos_nb = builder->code.size; - ADD_CODE (builder, &zero, ASE_SIZEOF(zero)); - ADD_CODE (builder, &zero, ASE_SIZEOF(zero)); - - /* handle the first branch */ - n = __build_branch (builder); - if (n == -1) return -1; - if (n == 0) - { - /* if the pattern is empty, the control reaches here */ - return 0; - } - - rhdr = (rhdr_t*)&builder->code.buf[pos_nb]; - rhdr->nb++; - - /* handle subsequent branches if any */ - while (builder->ptn.curc.type == CT_SPECIAL && - builder->ptn.curc.value == ASE_T('|')) - { - NEXT_CHAR (builder, LEVEL_TOP); - - n = __build_branch(builder); - if (n == -1) return -1; - if (n == 0) - { - /* if the pattern ends with a vertical bar(|), - * this block can be reached. however, such a - * pattern is highly discouraged */ - break; - } - - rhdr = (rhdr_t*)&builder->code.buf[pos_nb]; - rhdr->nb++; - } - - rhdr = (rhdr_t*)&builder->code.buf[pos_nb]; - rhdr->el = builder->code.size - old_size; - - return 1; -} - -static int __build_branch (builder_t* builder) -{ - int n; - ase_size_t zero = 0; - ase_size_t old_size; - ase_size_t pos_na; - code_t* cmd; - bhdr_t* bhdr; - - old_size = builder->code.size; - - pos_na = builder->code.size; - ADD_CODE (builder, &zero, ASE_SIZEOF(zero)); - ADD_CODE (builder, &zero, ASE_SIZEOF(zero)); - - while (1) - { - cmd = (code_t*)&builder->code.buf[builder->code.size]; - - n = __build_atom (builder); - if (n == -1) - { - builder->code.size = old_size; - return -1; - } - - if (n == 0) break; /* no atom */ - - n = __build_occurrences (builder, cmd); - if (n == -1) - { - builder->code.size = old_size; - return -1; - } - - /* n == 0 no bound character. just continue */ - /* n == 1 bound has been applied by build_occurrences */ - - bhdr = (bhdr_t*)&builder->code.buf[pos_na]; - bhdr->na++; - } - - bhdr = (bhdr_t*)&builder->code.buf[pos_na]; - bhdr->bl = builder->code.size - old_size; - - return (builder->code.size == old_size)? 0: 1; -} - -static int __build_atom (builder_t* builder) -{ - int n; - code_t tmp; - - if (builder->ptn.curc.type == CT_EOF) return 0; - - if (builder->ptn.curc.type == CT_SPECIAL) - { - if (builder->ptn.curc.value == ASE_T('(')) - { - tmp.cmd = CMD_GROUP; - tmp.negate = 0; - tmp.lbound = 1; - tmp.ubound = 1; - ADD_CODE (builder, &tmp, ASE_SIZEOF(tmp)); - - NEXT_CHAR (builder, LEVEL_TOP); - - n = __build_pattern (builder); - if (n == -1) return -1; - - if (builder->ptn.curc.type != CT_SPECIAL || - builder->ptn.curc.value != ASE_T(')')) - { - builder->errnum = ASE_AWK_EREXRPAREN; - return -1; - } - } - else if (builder->ptn.curc.value == ASE_T('^')) - { - tmp.cmd = CMD_BOL; - tmp.negate = 0; - tmp.lbound = 1; - tmp.ubound = 1; - ADD_CODE (builder, &tmp, ASE_SIZEOF(tmp)); - } - else if (builder->ptn.curc.value == ASE_T('$')) - { - tmp.cmd = CMD_EOL; - tmp.negate = 0; - tmp.lbound = 1; - tmp.ubound = 1; - ADD_CODE (builder, &tmp, ASE_SIZEOF(tmp)); - } - else if (builder->ptn.curc.value == ASE_T('.')) - { - tmp.cmd = CMD_ANY_CHAR; - tmp.negate = 0; - tmp.lbound = 1; - tmp.ubound = 1; - ADD_CODE (builder, &tmp, ASE_SIZEOF(tmp)); - } - else if (builder->ptn.curc.value == ASE_T('[')) - { - code_t* cmd; - - cmd = (code_t*)&builder->code.buf[builder->code.size]; - - tmp.cmd = CMD_CHARSET; - tmp.negate = 0; - tmp.lbound = 1; - tmp.ubound = 1; - ADD_CODE (builder, &tmp, ASE_SIZEOF(tmp)); - - NEXT_CHAR (builder, LEVEL_CHARSET); - - n = __build_charset (builder, cmd); - if (n == -1) return -1; - - ASE_ASSERT (n != 0); - - if (builder->ptn.curc.type != CT_SPECIAL || - builder->ptn.curc.value != ASE_T(']')) - { - builder->errnum = ASE_AWK_EREXRBRACKET; - return -1; - } - - } - else return 0; - - NEXT_CHAR (builder, LEVEL_TOP); - return 1; - } - else - { - ASE_ASSERT (builder->ptn.curc.type == CT_NORMAL); - - tmp.cmd = CMD_ORD_CHAR; - tmp.negate = 0; - tmp.lbound = 1; - tmp.ubound = 1; - ADD_CODE (builder, &tmp, ASE_SIZEOF(tmp)); - - ADD_CODE (builder, - &builder->ptn.curc.value, - ASE_SIZEOF(builder->ptn.curc.value)); - NEXT_CHAR (builder, LEVEL_TOP); - - return 1; - } -} - -static int __build_charset (builder_t* builder, code_t* cmd) -{ - ase_size_t zero = 0; - ase_size_t old_size; - ase_size_t pos_csc; - cshdr_t* cshdr; - - old_size = builder->code.size; - - pos_csc = builder->code.size; - ADD_CODE (builder, &zero, ASE_SIZEOF(zero)); - ADD_CODE (builder, &zero, ASE_SIZEOF(zero)); - - if (builder->ptn.curc.type == CT_NORMAL && - builder->ptn.curc.value == ASE_T('^')) - { - cmd->negate = 1; - NEXT_CHAR (builder, LEVEL_CHARSET); - } - - while (builder->ptn.curc.type == CT_NORMAL) - { - ase_char_t c0, c1, c2; - int cc = 0; - - c1 = builder->ptn.curc.value; - NEXT_CHAR(builder, LEVEL_CHARSET); - - if (c1 == ASE_T('[') && - builder->ptn.curc.type == CT_NORMAL && - builder->ptn.curc.value == ASE_T(':')) - { - if (__build_cclass (builder, &c1) == -1) return -1; - cc = cc | 1; - } - - c2 = c1; - if (builder->ptn.curc.type == CT_NORMAL && - builder->ptn.curc.value == ASE_T('-')) - { - NEXT_CHAR (builder, LEVEL_CHARSET); - - if (builder->ptn.curc.type == CT_NORMAL) - { - c2 = builder->ptn.curc.value; - NEXT_CHAR (builder, LEVEL_CHARSET); - - if (c2 == ASE_T('[') && - builder->ptn.curc.type == CT_NORMAL && - builder->ptn.curc.value == ASE_T(':')) - { - if (__build_cclass (builder, &c2) == -1) - { - return -1; - } - - cc = cc | 2; - } - } - else cc = cc | 4; - } - - - if (cc == 0 || cc == 4) - { - if (c1 == c2) - { - c0 = CHARSET_ONE; - ADD_CODE (builder, &c0, ASE_SIZEOF(c0)); - ADD_CODE (builder, &c1, ASE_SIZEOF(c1)); - } - else - { - c0 = CHARSET_RANGE; - ADD_CODE (builder, &c0, ASE_SIZEOF(c0)); - ADD_CODE (builder, &c1, ASE_SIZEOF(c1)); - ADD_CODE (builder, &c2, ASE_SIZEOF(c2)); - } - } - else if (cc == 1) - { - c0 = CHARSET_CLASS; - ADD_CODE (builder, &c0, ASE_SIZEOF(c0)); - ADD_CODE (builder, &c1, ASE_SIZEOF(c1)); - } - else - { - /* invalid range */ - #ifdef DEBUG_REX - ase_dprintf ( - ASE_T("__build_charset: invalid character set range\n")); - #endif - builder->errnum = ASE_AWK_EREXCRANGE; - return -1; - } - - cshdr = (cshdr_t*)&builder->code.buf[pos_csc]; - cshdr->csc++; - } - - cshdr = (cshdr_t*)&builder->code.buf[pos_csc]; - cshdr->csl = builder->code.size - old_size; - - return 1; -} - -static int __build_cclass (builder_t* builder, ase_char_t* cc) -{ - const struct __char_class_t* ccp = __char_class; - ase_size_t len = builder->ptn.end - builder->ptn.curp; - - while (ccp->name != ASE_NULL) - { - if (__begin_with (builder->ptn.curp, len, ccp->name)) break; - ccp++; - } - - if (ccp->name == ASE_NULL) - { - /* wrong class name */ - #ifdef DEBUG_REX - ase_dprintf (ASE_T("__build_cclass: wrong class name\n")); - #endif - builder->errnum = ASE_AWK_EREXCCLASS; - return -1; - } - - builder->ptn.curp += ccp->name_len; - - NEXT_CHAR (builder, LEVEL_CHARSET); - if (builder->ptn.curc.type != CT_NORMAL || - builder->ptn.curc.value != ASE_T(':')) - { - #ifdef DEBUG_REX - ase_dprintf (ASE_T("__build_cclass: a colon(:) expected\n")); - #endif - builder->errnum = ASE_AWK_EREXCOLON; - return -1; - } - - NEXT_CHAR (builder, LEVEL_CHARSET); - - /* ] happens to be the charset ender ] */ - if (builder->ptn.curc.type != CT_SPECIAL || - builder->ptn.curc.value != ASE_T(']')) - { - #ifdef DEBUG_REX - ase_dprintf (ASE_T("__build_cclass: ] expected\n")); - #endif - builder->errnum = ASE_AWK_EREXRBRACKET; - return -1; - } - - NEXT_CHAR (builder, LEVEL_CHARSET); - - *cc = (ase_char_t)(ccp - __char_class); - return 1; -} - -static int __build_occurrences (builder_t* builder, code_t* cmd) -{ - if (builder->ptn.curc.type != CT_SPECIAL) return 0; - - switch (builder->ptn.curc.value) - { - case ASE_T('+'): - { - cmd->lbound = 1; - cmd->ubound = BOUND_MAX; - NEXT_CHAR(builder, LEVEL_TOP); - return 1; - } - - case ASE_T('*'): - { - cmd->lbound = 0; - cmd->ubound = BOUND_MAX; - NEXT_CHAR(builder, LEVEL_TOP); - return 1; - } - - case ASE_T('?'): - { - cmd->lbound = 0; - cmd->ubound = 1; - NEXT_CHAR(builder, LEVEL_TOP); - return 1; - } - - case ASE_T('{'): - { - NEXT_CHAR (builder, LEVEL_RANGE); - - if (__build_range(builder, cmd) == -1) return -1; - - if (builder->ptn.curc.type != CT_SPECIAL || - builder->ptn.curc.value != ASE_T('}')) - { - builder->errnum = ASE_AWK_EREXRBRACE; - return -1; - } - - NEXT_CHAR (builder, LEVEL_TOP); - return 1; - } - } - - return 0; -} - -static int __build_range (builder_t* builder, code_t* cmd) -{ - ase_size_t bound; - -/* TODO: should allow white spaces in the range??? -what if it is not in the raight format? convert it to ordinary characters?? */ - bound = 0; - while (builder->ptn.curc.type == CT_NORMAL && - (builder->ptn.curc.value >= ASE_T('0') && - builder->ptn.curc.value <= ASE_T('9'))) - { - bound = bound * 10 + builder->ptn.curc.value - ASE_T('0'); - NEXT_CHAR (builder, LEVEL_RANGE); - } - - cmd->lbound = bound; - - if (builder->ptn.curc.type == CT_SPECIAL && - builder->ptn.curc.value == ASE_T(',')) - { - NEXT_CHAR (builder, LEVEL_RANGE); - - bound = 0; - while (builder->ptn.curc.type == CT_NORMAL && - (builder->ptn.curc.value >= ASE_T('0') && - builder->ptn.curc.value <= ASE_T('9'))) - { - bound = bound * 10 + builder->ptn.curc.value - ASE_T('0'); - NEXT_CHAR (builder, LEVEL_RANGE); - } - - cmd->ubound = bound; - } - else cmd->ubound = BOUND_MAX; - - if (cmd->lbound > cmd->ubound) - { - /* invalid occurrences range */ - builder->errnum = ASE_AWK_EREXBRANGE; - return -1; - } - - return 0; -} - -static int __next_char (builder_t* builder, int level) -{ - if (builder->ptn.curp >= builder->ptn.end) - { - builder->ptn.curc.type = CT_EOF; - builder->ptn.curc.value = ASE_T('\0'); - return 0; - } - - builder->ptn.curc.type = CT_NORMAL; - builder->ptn.curc.value = *builder->ptn.curp++; - - if (builder->ptn.curc.value == ASE_T('\\')) - { - if (builder->ptn.curp >= builder->ptn.end) - { - builder->errnum = ASE_AWK_EREXEND; - return -1; - } - - builder->ptn.curc.value = *builder->ptn.curp++; - return 0; - } - else - { - if (level == LEVEL_TOP) - { - if (builder->ptn.curc.value == ASE_T('[') || - builder->ptn.curc.value == ASE_T('|') || - builder->ptn.curc.value == ASE_T('^') || - builder->ptn.curc.value == ASE_T('$') || - builder->ptn.curc.value == ASE_T('{') || - builder->ptn.curc.value == ASE_T('+') || - builder->ptn.curc.value == ASE_T('?') || - builder->ptn.curc.value == ASE_T('*') || - builder->ptn.curc.value == ASE_T('.') || - builder->ptn.curc.value == ASE_T('(') || - builder->ptn.curc.value == ASE_T(')')) - { - builder->ptn.curc.type = CT_SPECIAL; - } - } - else if (level == LEVEL_CHARSET) - { - if (builder->ptn.curc.value == ASE_T(']')) - { - builder->ptn.curc.type = CT_SPECIAL; - } - } - else if (level == LEVEL_RANGE) - { - if (builder->ptn.curc.value == ASE_T(',') || - builder->ptn.curc.value == ASE_T('}')) - { - builder->ptn.curc.type = CT_SPECIAL; - } - } - } - - return 0; -} - -static int __add_code (builder_t* builder, void* data, ase_size_t len) -{ - if (len > builder->code.capa - builder->code.size) - { - ase_size_t capa = builder->code.capa * 2; - ase_byte_t* tmp; - - if (capa == 0) capa = DEF_CODE_CAPA; - while (len > capa - builder->code.size) { capa = capa * 2; } - - if (builder->awk->prmfns.mmgr.realloc != ASE_NULL) - { - tmp = (ase_byte_t*) ASE_AWK_REALLOC ( - builder->awk, builder->code.buf, capa); - if (tmp == ASE_NULL) - { - builder->errnum = ASE_AWK_ENOMEM; - return -1; - } - } - else - { - tmp = (ase_byte_t*) ASE_AWK_MALLOC (builder->awk, capa); - if (tmp == ASE_NULL) - { - builder->errnum = ASE_AWK_ENOMEM; - return -1; - } - - if (builder->code.buf != ASE_NULL) - { - ase_memcpy (tmp, builder->code.buf, builder->code.capa); - ASE_AWK_FREE (builder->awk, builder->code.buf); - } - } - - builder->code.buf = tmp; - builder->code.capa = capa; - } - - ase_memcpy (&builder->code.buf[builder->code.size], data, len); - builder->code.size += len; - - return 0; -} - -static ase_bool_t __begin_with ( - const ase_char_t* str, ase_size_t len, const ase_char_t* what) -{ - const ase_char_t* end = str + len; - - while (str < end) - { - if (*what == ASE_T('\0')) return ase_true; - if (*what != *str) return ase_false; - - str++; what++; - } - - if (*what == ASE_T('\0')) return ase_true; - return ase_false; -} - -static const ase_byte_t* __match_pattern ( - matcher_t* matcher, const ase_byte_t* base, match_t* mat) -{ - match_t mat2; - ase_size_t i; - const ase_byte_t* p; - rhdr_t* rhdr; - - p = base; - rhdr = (rhdr_t*) p; p += ASE_SIZEOF(*rhdr); - -#ifdef DEBUG_REX - ase_dprintf ( - ASE_T("__match_pattern: NB = %u, EL = %u\n"), - (unsigned int)rhdr->nb, (unsigned int)rhdr->el); -#endif - - mat->matched = ase_false; - mat->match_len = 0; - - for (i = 0; i < rhdr->nb; i++) - { - mat2.match_ptr = mat->match_ptr; - - p = __match_branch (matcher, p, &mat2); - if (p == ASE_NULL) return ASE_NULL; - - if (mat2.matched) - { - mat->matched = ase_true; - mat->match_len = mat2.match_len; - break; - } - } - - return base + rhdr->el; -} - -static const ase_byte_t* __match_branch ( - matcher_t* matcher, const ase_byte_t* base, match_t* mat) -{ - /* branch body base+sizeof(NA)+sizeof(BL)-----+ - * BL base+sizeof(NA) ----------+ | - * base NA ------+ | | - * | | | - * |NA(ase_size_t)|BL(ase_size_t)|ATOMS.........| - */ - mat->branch = base; - mat->branch_end = base + ((bhdr_t*)base)->bl; - - return __match_branch_body ( - matcher, (const ase_byte_t*)((bhdr_t*)base+1), mat); -} - -static const ase_byte_t* __match_branch_body ( - matcher_t* matcher, const ase_byte_t* base, match_t* mat) -{ - const ase_byte_t* n; - - if (matcher->depth.max > 0 && matcher->depth.cur >= matcher->depth.max) - { - matcher->errnum = ASE_AWK_EREXRECUR; - return ASE_NULL; - } - - matcher->depth.cur++; - n = __match_branch_body0 (matcher, base, mat); - matcher->depth.cur--; - - return n; -} - -static const ase_byte_t* __match_branch_body0 ( - matcher_t* matcher, const ase_byte_t* base, match_t* mat) -{ - const ase_byte_t* p; -/* match_t mat2;*/ - ase_size_t match_len = 0; - - mat->matched = ase_false; - mat->match_len = 0; - -/* TODO: is mat2 necessary here ? */ -/* - mat2.match_ptr = mat->match_ptr; - mat2.branch = mat->branch; - mat2.branch_end = mat->branch_end; -*/ - - p = base; - - while (p < mat->branch_end) - { - p = __match_atom (matcher, p, mat); - if (p == ASE_NULL) return ASE_NULL; - - if (!mat->matched) break; - - mat->match_ptr = &mat->match_ptr[mat->match_len]; - match_len += mat->match_len; -#if 0 - p = __match_atom (matcher, p, &mat2); - if (p == ASE_NULL) return ASE_NULL; - - if (!mat2.matched) - { - mat->matched = ase_false; - break; /* stop matching */ - } - - mat->matched = ase_true; - mat->match_len += mat2.match_len; - - mat2.match_ptr = &mat2.match_ptr[mat2.match_len]; -#endif - } - - if (mat->matched) mat->match_len = match_len; - return mat->branch_end; -} - -static const ase_byte_t* __match_atom ( - matcher_t* matcher, const ase_byte_t* base, match_t* mat) -{ - static atom_matcher_t matchers[] = - { - __match_bol, - __match_eol, - __match_any_char, - __match_ord_char, - __match_charset, - __match_group - }; - - ASE_ASSERT ( - ((code_t*)base)->cmd >= 0 && - ((code_t*)base)->cmd < ASE_COUNTOF(matchers)); - - return matchers[((code_t*)base)->cmd] (matcher, base, mat); -} - -static const ase_byte_t* __match_bol ( - matcher_t* matcher, const ase_byte_t* base, match_t* mat) -{ - const ase_byte_t* p = base; - const code_t* cp; - - cp = (const code_t*)p; p += ASE_SIZEOF(*cp); - ASE_ASSERT (cp->cmd == CMD_BOL); - - mat->matched = (mat->match_ptr == matcher->match.str.ptr || - (cp->lbound == cp->ubound && cp->lbound == 0)); - mat->match_len = 0; - - return p; -} - -static const ase_byte_t* __match_eol ( - matcher_t* matcher, const ase_byte_t* base, match_t* mat) -{ - const ase_byte_t* p = base; - const code_t* cp; - - cp = (const code_t*)p; p += ASE_SIZEOF(*cp); - ASE_ASSERT (cp->cmd == CMD_EOL); - - mat->matched = (mat->match_ptr == matcher->match.str.end || - (cp->lbound == cp->ubound && cp->lbound == 0)); - mat->match_len = 0; - - return p; -} - -static const ase_byte_t* __match_any_char ( - matcher_t* matcher, const ase_byte_t* base, match_t* mat) -{ - const ase_byte_t* p = base; - const code_t* cp; - ase_size_t si = 0, lbound, ubound; - - cp = (const code_t*)p; p += ASE_SIZEOF(*cp); - ASE_ASSERT (cp->cmd == CMD_ANY_CHAR); - - lbound = cp->lbound; - ubound = cp->ubound; - - mat->matched = ase_false; - mat->match_len = 0; - - /* merge the same consecutive codes */ - while (p < mat->branch_end && - cp->cmd == ((const code_t*)p)->cmd) - { - lbound += ((const code_t*)p)->lbound; - ubound += ((const code_t*)p)->ubound; - - p += ASE_SIZEOF(*cp); - } - -#ifdef DEBUG_REX - ase_dprintf ( - ASE_T("__match_any_char: lbound = %u, ubound = %u\n"), - (unsigned int)lbound, (unsigned int)ubound); -#endif - - /* find the longest match */ - while (si < ubound) - { - if (&mat->match_ptr[si] >= matcher->match.str.end) break; - si++; - } - -#ifdef DEBUG_REX - ase_dprintf ( - ASE_T("__match_any_char: max si = %u\n"), (unsigned)si); -#endif - - if (si >= lbound && si <= ubound) - { - p = __match_occurrences (matcher, si, p, lbound, ubound, mat); - } - - return p; -} - -static const ase_byte_t* __match_ord_char ( - matcher_t* matcher, const ase_byte_t* base, match_t* mat) -{ - const ase_byte_t* p = base; - const code_t* cp; - ase_size_t si = 0, lbound, ubound; - ase_char_t cc; - - cp = (const code_t*)p; p += ASE_SIZEOF(*cp); - ASE_ASSERT (cp->cmd == CMD_ORD_CHAR); - - lbound = cp->lbound; - ubound = cp->ubound; - - cc = *(ase_char_t*)p; p += ASE_SIZEOF(cc); - if (matcher->ignorecase) cc = ASE_AWK_TOUPPER(matcher->awk, cc); - - /* merge the same consecutive codes - * for example, a{1,10}a{0,10} is shortened to a{1,20} */ - if (matcher->ignorecase) - { - while (p < mat->branch_end && - cp->cmd == ((const code_t*)p)->cmd) - { - if (ASE_AWK_TOUPPER (matcher->awk, *(ase_char_t*)(p+ASE_SIZEOF(*cp))) != cc) break; - - lbound += ((const code_t*)p)->lbound; - ubound += ((const code_t*)p)->ubound; - - p += ASE_SIZEOF(*cp) + ASE_SIZEOF(cc); - } - } - else - { - while (p < mat->branch_end && - cp->cmd == ((const code_t*)p)->cmd) - { - if (*(ase_char_t*)(p+ASE_SIZEOF(*cp)) != cc) break; - - lbound += ((const code_t*)p)->lbound; - ubound += ((const code_t*)p)->ubound; - - p += ASE_SIZEOF(*cp) + ASE_SIZEOF(cc); - } - } - -#ifdef DEBUG_REX - ase_dprintf ( - ASE_T("__match_ord_char: cc = %c, lbound = %u, ubound = %u\n"), - cc, (unsigned int)lbound, (unsigned int)ubound); -#endif - - mat->matched = ase_false; - mat->match_len = 0; - - /* find the longest match */ - if (matcher->ignorecase) - { - while (si < ubound) - { - if (&mat->match_ptr[si] >= matcher->match.str.end) break; -#ifdef DEBUG_REX - ase_dprintf ( - ASE_T("__match_ord_char: %c %c\n"), - cc, mat->match_ptr[si]); -#endif - if (cc != ASE_AWK_TOUPPER (matcher->awk, mat->match_ptr[si])) break; - si++; - } - } - else - { - while (si < ubound) - { - if (&mat->match_ptr[si] >= matcher->match.str.end) break; -#ifdef DEBUG_REX - ase_dprintf ( - ASE_T("__match_ord_char: %c %c\n"), - cc, mat->match_ptr[si]); -#endif - if (cc != mat->match_ptr[si]) break; - si++; - } - } - -#ifdef DEBUG_REX - ase_dprintf ( - ASE_T("__match_ord_char: max occurrences=%u, lbound=%u, ubound=%u\n"), - (unsigned)si, (unsigned)lbound, (unsigned)ubound); -#endif - - if (si >= lbound && si <= ubound) - { - p = __match_occurrences (matcher, si, p, lbound, ubound, mat); - } - - return p; -} - -static const ase_byte_t* __match_charset ( - matcher_t* matcher, const ase_byte_t* base, match_t* mat) -{ - const ase_byte_t* p = base; - ase_size_t si = 0; - ase_bool_t n; - ase_char_t c; - - code_t* cp; - cshdr_t* cshdr; - - cp = (code_t*)p; p += ASE_SIZEOF(*cp); - ASE_ASSERT (cp->cmd == CMD_CHARSET); - - cshdr = (cshdr_t*)p; p += ASE_SIZEOF(*cshdr); - -#ifdef DEBUG_REX - ase_dprintf ( - ASE_T("__match_charset: lbound = %u, ubound = %u\n"), - (unsigned int)cp->lbound, (unsigned int)cp->ubound); -#endif - - mat->matched = ase_false; - mat->match_len = 0; - - while (si < cp->ubound) - { - if (&mat->match_ptr[si] >= matcher->match.str.end) break; - - c = mat->match_ptr[si]; - if (matcher->ignorecase) c = ASE_AWK_TOUPPER(matcher->awk, c); - - n = __test_charset (matcher, p, cshdr->csc, c); - if (cp->negate) n = !n; - if (!n) break; - - si++; - } - - p = p + cshdr->csl - ASE_SIZEOF(*cshdr); - -#ifdef DEBUG_REX - ase_dprintf ( - ASE_T("__match_charset: max occurrences=%u, lbound=%u, ubound=%u\n"), - (unsigned)si, (unsigned)cp->lbound, (unsigned)cp->ubound); -#endif - - if (si >= cp->lbound && si <= cp->ubound) - { - p = __match_occurrences (matcher, si, p, cp->lbound, cp->ubound, mat); - } - - return p; -} - -static const ase_byte_t* __match_group ( - matcher_t* matcher, const ase_byte_t* base, match_t* mat) -{ - const ase_byte_t* p = base; - const code_t* cp; - match_t mat2; - ase_size_t si = 0, grp_len_static[16], * grp_len; - - cp = (const code_t*)p; p += ASE_SIZEOF(*cp); - ASE_ASSERT (cp->cmd == CMD_GROUP); - - mat->matched = ase_false; - mat->match_len = 0; - - /* - * A grouped pattern, unlike other atoms, can match one or more - * characters. When it is requested with a variable occurrences, - * the number of characters that have matched at each occurrence - * needs to be remembered for the backtracking purpose. - * - * An array "grp_len" is used to store the accumulated number of - * characters. grp_len[0] is set to zero always for convenience. - * grp_len[1] holds the number of characters that have matched - * at the first occurrence, grp_len[2] at the second occurrence, - * and so on. - * - * Look at the following example - * - * pattern: (abc){1,3}x string: abcabcabcxyz - * - * grp_len[3] => 9 -----------+ - * grp_len[2] => 6 --------+ | - * grp_len[1] => 3 -----+ | | - * grp_len[0] => 0 --+ | | | - * | | | | - * abcabcabcxyz - */ - - if (cp->ubound < ASE_COUNTOF(grp_len_static)) - { - grp_len = grp_len_static; - } - else - { - grp_len = (ase_size_t*) ASE_AWK_MALLOC ( - matcher->awk, ASE_SIZEOF(ase_size_t) * cp->ubound); - if (grp_len == ASE_NULL) - { - matcher->errnum = ASE_AWK_ENOMEM; - return ASE_NULL; - } - } - - grp_len[si] = 0; - - mat2.match_ptr = mat->match_ptr; - while (si < cp->ubound) - { - if (mat2.match_ptr >= matcher->match.str.end) break; - - if (__match_pattern (matcher, p, &mat2) == ASE_NULL) - { - if (grp_len != grp_len_static) - ASE_AWK_FREE (matcher->awk, grp_len); - return ASE_NULL; - } - if (!mat2.matched) break; - - grp_len[si+1] = grp_len[si] + mat2.match_len; - - mat2.match_ptr += mat2.match_len; - mat2.match_len = 0; - mat2.matched = ase_false; - - si++; - } - - /* increment p by the length of the subpattern */ - p += *(ase_size_t*)(p+ASE_SIZEOF(ase_size_t)); - - /* check the occurrences */ - if (si >= cp->lbound && si <= cp->ubound) - { - if (cp->lbound == cp->ubound || p >= mat->branch_end) - { - mat->matched = ase_true; - mat->match_len = grp_len[si]; - } - else - { - ASE_ASSERT (cp->ubound > cp->lbound); - - do - { - const ase_byte_t* tmp; - - mat2.match_ptr = &mat->match_ptr[grp_len[si]]; - mat2.branch = mat->branch; - mat2.branch_end = mat->branch_end; - - #ifdef DEBUG_REX - ase_dprintf ( - ASE_T("__match_group: GROUP si=%d [%s]\n"), - (unsigned)si, mat->match_ptr); - #endif - tmp = __match_branch_body (matcher, p, &mat2); - if (tmp == ASE_NULL) - { - if (grp_len != grp_len_static) - ASE_AWK_FREE (matcher->awk, grp_len); - return ASE_NULL; - } - - if (mat2.matched) - { - mat->matched = ase_true; - mat->match_len = grp_len[si] + mat2.match_len; - p = tmp; - break; - } - - if (si <= cp->lbound) break; - si--; - } - while (1); - } - - } - - if (grp_len != grp_len_static) ASE_AWK_FREE (matcher->awk, grp_len); - return p; -} - -static const ase_byte_t* __match_occurrences ( - matcher_t* matcher, ase_size_t si, const ase_byte_t* p, - ase_size_t lbound, ase_size_t ubound, match_t* mat) -{ - ASE_ASSERT (si >= lbound && si <= ubound); - /* the match has been found */ - - if (lbound == ubound || p >= mat->branch_end) - { - /* if the match for fixed occurrences was - * requested or no atoms remain unchecked in - * the branch, the match is returned. */ - mat->matched = ase_true; - mat->match_len = si; - } - else - { - /* Otherwise, it checks if the remaining atoms - * match the rest of the string - * - * Let's say the caller of this function was processing - * the first period character in the following example. - * - * pattern: .{1,3}xx string: xxxyy - * - * It scans up to the third "x" in the string. si is set - * to 3 and p points to the first "x" in the pattern. - * It doesn't change mat.match_ptr so mat.match_ptr remains - * the same. - * - * si = 3 p -----+ mat.match_ptr ---+ - * | | - * .{1,3}xx xxxyy - * - * When the code reaches here, the string pointed at by - * &mat.match_ptr[si] is tried to match against the remaining - * pattern pointed at p. - * - * &mat.match_ptr[si] ---+ - * | - * xxxyy - * - * If a match is found, the match and the previous match are - * merged and returned. - * - * If not, si is decremented by one and the match is performed - * from the string pointed at by &mat.match_ptr[si]. - * - * &mat.match_ptr[si] --+ - * | - * xxxyy - * - * This process is repeated until a match is found or si - * becomes less than lbound. (si never becomes less than - * lbound in the implementation below, though) - */ - - ASE_ASSERT (ubound > lbound); - - do - { - match_t mat2; - const ase_byte_t* tmp; - - mat2.match_ptr = &mat->match_ptr[si]; - mat2.branch = mat->branch; - mat2.branch_end = mat->branch_end; - - #ifdef DEBUG_REX - ase_dprintf ( - ASE_T("__match occurrences: si=%u [%s]\n"), - (unsigned)si, mat->match_ptr); - #endif - tmp = __match_branch_body (matcher, p, &mat2); - - if (mat2.matched) - { - mat->matched = ase_true; - mat->match_len = si + mat2.match_len; - p = tmp; - break; - } - - if (si <= lbound) break; - si--; - } - while (1); - } - - return p; -} - -static ase_bool_t __test_charset ( - matcher_t* matcher, const ase_byte_t* p, ase_size_t csc, ase_char_t c) -{ - ase_size_t i; - - for (i = 0; i < csc; i++) - { - ase_char_t c0, c1, c2; - - c0 = *(const ase_char_t*)p; - p += ASE_SIZEOF(c0); - if (c0 == CHARSET_ONE) - { - c1 = *(const ase_char_t*)p; - if (matcher->ignorecase) - c1 = ASE_AWK_TOUPPER(matcher->awk, c1); - #ifdef DEBUG_REX - ase_dprintf ( - ASE_T("__match_charset: %c %c\n"), c, c1); - #endif - if (c == c1) return ase_true; - } - else if (c0 == CHARSET_RANGE) - { - c1 = *(const ase_char_t*)p; - p += ASE_SIZEOF(c1); - c2 = *(const ase_char_t*)p; - - if (matcher->ignorecase) - { - c1 = ASE_AWK_TOUPPER(matcher->awk, c1); - c2 = ASE_AWK_TOUPPER(matcher->awk, c2); - } - #ifdef DEBUG_REX - ase_dprintf ( - ASE_T("__match_charset: %c %c-%c\n"), c, c1, c2); - #endif - if (c >= c1 && c <= c2) return ase_true; - } - else if (c0 == CHARSET_CLASS) - { - c1 = *(const ase_char_t*)p; - #ifdef DEBUG_REX - ase_dprintf ( - ASE_T("__match_charset: %c %s\n"), - c, __char_class[c1].name); - #endif - if (__char_class[c1].func ( - matcher->awk, c)) return ase_true; - } - else - { - ASE_ASSERT (!"should never happen - invalid charset code"); - break; - } - - p += ASE_SIZEOF(c1); - } - - return ase_false; -} - -static ase_bool_t cc_isalnum (ase_awk_t* awk, ase_char_t c) -{ - return ASE_AWK_ISALNUM (awk, c); -} - -static ase_bool_t cc_isalpha (ase_awk_t* awk, ase_char_t c) -{ - return ASE_AWK_ISALPHA (awk, c); -} - -static ase_bool_t cc_isblank (ase_awk_t* awk, ase_char_t c) -{ - return c == ASE_T(' ') || c == ASE_T('\t'); -} - -static ase_bool_t cc_iscntrl (ase_awk_t* awk, ase_char_t c) -{ - return ASE_AWK_ISCNTRL (awk, c); -} - -static ase_bool_t cc_isdigit (ase_awk_t* awk, ase_char_t c) -{ - return ASE_AWK_ISDIGIT (awk, c); -} - -static ase_bool_t cc_isgraph (ase_awk_t* awk, ase_char_t c) -{ - return ASE_AWK_ISGRAPH (awk, c); -} - -static ase_bool_t cc_islower (ase_awk_t* awk, ase_char_t c) -{ - return ASE_AWK_ISLOWER (awk, c); -} - -static ase_bool_t cc_isprint (ase_awk_t* awk, ase_char_t c) -{ - return ASE_AWK_ISPRINT (awk, c); -} - -static ase_bool_t cc_ispunct (ase_awk_t* awk, ase_char_t c) -{ - return ASE_AWK_ISPUNCT (awk, c); -} - -static ase_bool_t cc_isspace (ase_awk_t* awk, ase_char_t c) -{ - return ASE_AWK_ISSPACE (awk, c); -} - -static ase_bool_t cc_isupper (ase_awk_t* awk, ase_char_t c) -{ - return ASE_AWK_ISUPPER (awk, c); -} - -static ase_bool_t cc_isxdigit (ase_awk_t* awk, ase_char_t c) -{ - return ASE_AWK_ISXDIGIT (awk, c); -} - -#define DPRINTF awk->prmfns.misc.dprintf -#define DCUSTOM awk->prmfns.misc.custom_data - -void ase_awk_dprintrex (ase_awk_t* awk, void* rex) -{ - __print_pattern (awk, rex); - DPRINTF (DCUSTOM, awk->prmfns.misc.custom_data, ASE_T("\n")); -} - -static const ase_byte_t* __print_pattern (ase_awk_t* awk, const ase_byte_t* p) -{ - ase_size_t i; - rhdr_t* rhdr; - - rhdr = (rhdr_t*)p; p += ASE_SIZEOF(*rhdr); - - for (i = 0; i < rhdr->nb; i++) - { - if (i != 0) DPRINTF (DCUSTOM, ASE_T("|")); - p = __print_branch (awk, p); - } - - return p; -} - -static const ase_byte_t* __print_branch (ase_awk_t* awk, const ase_byte_t* p) -{ - ase_size_t i; - bhdr_t* bhdr; - - bhdr = (bhdr_t*)p; p += ASE_SIZEOF(*bhdr); - - for (i = 0; i < bhdr->na; i++) - { - p = __print_atom (awk, p); - } - - return p; -} - -static const ase_byte_t* __print_atom (ase_awk_t* awk, const ase_byte_t* p) -{ - const code_t* cp = (const code_t*)p; - - if (cp->cmd == CMD_BOL) - { - DPRINTF (DCUSTOM, ASE_T("^")); - p += ASE_SIZEOF(*cp); - } - else if (cp->cmd == CMD_EOL) - { - DPRINTF (DCUSTOM, ASE_T("$")); - p += ASE_SIZEOF(*cp); - } - else if (cp->cmd == CMD_ANY_CHAR) - { - DPRINTF (DCUSTOM, ASE_T(".")); - p += ASE_SIZEOF(*cp); - } - else if (cp->cmd == CMD_ORD_CHAR) - { - p += ASE_SIZEOF(*cp); - DPRINTF (DCUSTOM, ASE_T("%c"), *(ase_char_t*)p); - p += ASE_SIZEOF(ase_char_t); - } - else if (cp->cmd == CMD_CHARSET) - { - ase_size_t i; - cshdr_t* cshdr; - - p += ASE_SIZEOF(*cp); - DPRINTF (DCUSTOM, ASE_T("[")); - if (cp->negate) DPRINTF (DCUSTOM, ASE_T("^")); - - cshdr = (cshdr_t*)p; p += ASE_SIZEOF(*cshdr); - - for (i = 0; i < cshdr->csc; i++) - { - ase_char_t c0, c1, c2; - - c0 = *(ase_char_t*)p; - p += ASE_SIZEOF(c0); - - if (c0 == CHARSET_ONE) - { - c1 = *(ase_char_t*)p; - DPRINTF (DCUSTOM, ASE_T("%c"), c1); - } - else if (c0 == CHARSET_RANGE) - { - c1 = *(ase_char_t*)p; - p += ASE_SIZEOF(c1); - c2 = *(ase_char_t*)p; - DPRINTF (DCUSTOM, ASE_T("%c-%c"), c1, c2); - } - else if (c0 == CHARSET_CLASS) - { - c1 = *(ase_char_t*)p; - DPRINTF (DCUSTOM, ASE_T("[:%s:]"), __char_class[c1].name); - } - else - { - DPRINTF (DCUSTOM, ASE_T("should never happen - invalid charset code\n")); - } - - p += ASE_SIZEOF(c1); - } - - DPRINTF (DCUSTOM, ASE_T("]")); - } - else if (cp->cmd == CMD_GROUP) - { - p += ASE_SIZEOF(*cp); - DPRINTF (DCUSTOM, ASE_T("(")); - p = __print_pattern (awk, p); - DPRINTF (DCUSTOM, ASE_T(")")); - } - else - { - DPRINTF (DCUSTOM, ASE_T("should never happen - invalid atom code\n")); - } - - if (cp->lbound == 0 && cp->ubound == BOUND_MAX) - DPRINTF (DCUSTOM, ASE_T("*")); - else if (cp->lbound == 1 && cp->ubound == BOUND_MAX) - DPRINTF (DCUSTOM, ASE_T("+")); - else if (cp->lbound == 0 && cp->ubound == 1) - DPRINTF (DCUSTOM, ASE_T("?")); - else if (cp->lbound != 1 || cp->ubound != 1) - { - DPRINTF (DCUSTOM, ASE_T("{%lu,%lu}"), - (unsigned long)cp->lbound, (unsigned long)cp->ubound); - } - - return p; -} - diff --git a/ase/awk/rex.h b/ase/awk/rex.h deleted file mode 100644 index d856bac6..00000000 --- a/ase/awk/rex.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * $Id: rex.h,v 1.1.1.1 2007/03/28 14:05:17 bacon Exp $ - * - * {License} - */ - -#ifndef _ASE_AWK_REX_H_ -#define _ASE_AWK_REX_H_ - -#ifndef _ASE_AWK_AWK_H_ -#error Never include this file directly. Include instead -#endif - -/* - * Regular Esseression Syntax - * A regular expression is zero or more branches, separated by '|'. - * ...... - * ...... - * - * Compiled form of a regular expression: - * - * | expression | - * | header | branch | branch | branch | - * | nb | el | na | bl | cmd | arg | cmd | arg | na | bl | cmd | arg | na | bl | cmd | - * - * nb: the number of branches - * el: the length of a expression including the length of nb and el - * na: the number of atoms - * bl: the length of a branch including the length of na and bl - * cmd: The command and repetition info encoded together. - * Some commands require an argument to follow them but some other don't. - * It is encoded as follows: - * - * Subexpressions can be nested by having the command "GROUP" - * and a subexpression as its argument. - * - * Examples: - * a.c -> |1|6|5|ORD_CHAR(no bound)|a|ANY_CHAR(no bound)|ORD_CHAR(no bound)|c| - * ab|xy -> |2|10|4|ORD_CHAR(no bound)|a|ORD_CHAR(no bound)|b|4|ORD_CHAR(no bound)|x|ORD_CHAR(no bound)|y| - */ - -#define ASE_AWK_REX_NA(code) (*(ase_size_t*)(code)) - -#define ASE_AWK_REX_LEN(code) \ - (*(ase_size_t*)((ase_byte_t*)(code)+ASE_SIZEOF(ase_size_t))) - -enum ase_awk_rex_opt_t -{ - ASE_AWK_REX_IGNORECASE = (1 << 0) -}; - -#ifdef __cplusplus -extern "C" { -#endif - -void* ase_awk_buildrex ( - ase_awk_t* awk, const ase_char_t* ptn, - ase_size_t len, int* errnum); - -int ase_awk_matchrex ( - ase_awk_t* awk, void* code, int option, - const ase_char_t* str, ase_size_t len, - const ase_char_t** match_ptr, ase_size_t* match_len, int* errnum); - -void ase_awk_freerex (ase_awk_t* awk, void* code); - -ase_bool_t ase_awk_isemptyrex (ase_awk_t* awk, void* code); - -void ase_awk_dprintrex (ase_awk_t* awk, void* rex); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ase/awk/run.c b/ase/awk/run.c deleted file mode 100644 index 9e59dd1e..00000000 --- a/ase/awk/run.c +++ /dev/null @@ -1,7046 +0,0 @@ -/* - * $Id: run.c,v 1.1.1.1 2007/03/28 14:05:20 bacon Exp $ - * - * {License} - */ - -#include - -#ifdef DEBUG_RUN -#include -#endif - -#define CMP_ERROR -99 -#define DEF_BUF_CAPA 256 -#define STACK_INCREMENT 512 - -#define STACK_AT(run,n) ((run)->stack[(run)->stack_base+(n)]) -#define STACK_NARGS(run) (STACK_AT(run,3)) -#define STACK_ARG(run,n) STACK_AT(run,3+1+(n)) -#define STACK_LOCAL(run,n) STACK_AT(run,3+(ase_size_t)STACK_NARGS(run)+1+(n)) -#define STACK_RETVAL(run) STACK_AT(run,2) -#define STACK_GLOBAL(run,n) ((run)->stack[(n)]) -#define STACK_RETVAL_GLOBAL(run) ((run)->stack[(run)->awk->tree.nglobals+2]) - -enum exit_level_t -{ - EXIT_NONE, - EXIT_BREAK, - EXIT_CONTINUE, - EXIT_FUNCTION, - EXIT_NEXT, - EXIT_GLOBAL, - EXIT_ABORT -}; - -#define DEFAULT_CONVFMT ASE_T("%.6g") -#define DEFAULT_OFMT ASE_T("%.6g") -#define DEFAULT_OFS ASE_T(" ") -#define DEFAULT_ORS ASE_T("\n") -#define DEFAULT_ORS_CRLF ASE_T("\r\n") -#define DEFAULT_SUBSEP ASE_T("\034") - -/* the index of a positional variable should be a positive interger - * equal to or less than the maximum value of the type by which - * the index is represented. but it has an extra check against the - * maximum value of ase_size_t as the reference is represented - * in a pointer variable of ase_awk_val_ref_t and sizeof(void*) is - * equal to sizeof(ase_size_t). */ -#define IS_VALID_POSIDX(idx) \ - ((idx) >= 0 && \ - (idx) < ASE_TYPE_MAX(ase_long_t) && \ - (idx) < ASE_TYPE_MAX(ase_size_t)) - -static int __set_global ( - ase_awk_run_t* run, ase_size_t idx, - ase_awk_nde_var_t* var, ase_awk_val_t* val); - -static int __init_run ( - ase_awk_run_t* run, ase_awk_t* awk, - ase_awk_runios_t* runios, void* custom_data); -static void __deinit_run (ase_awk_run_t* run); - -static int __build_runarg ( - ase_awk_run_t* run, ase_awk_runarg_t* runarg, ase_size_t* nargs); -static void __cleanup_globals (ase_awk_run_t* run); -static int __set_globals_to_default (ase_awk_run_t* run); - -static int run_main ( - ase_awk_run_t* run, const ase_char_t* main, - ase_awk_runarg_t* runarg); - -static int __run_pattern_blocks (ase_awk_run_t* run); -static int __run_pattern_block_chain ( - ase_awk_run_t* run, ase_awk_chain_t* chain); -static int __run_pattern_block ( - ase_awk_run_t* run, ase_awk_chain_t* chain, ase_size_t block_no); -static int __run_block (ase_awk_run_t* run, ase_awk_nde_blk_t* nde); -static int __run_block0 (ase_awk_run_t* run, ase_awk_nde_blk_t* nde); -static int __run_statement (ase_awk_run_t* run, ase_awk_nde_t* nde); -static int __run_if (ase_awk_run_t* run, ase_awk_nde_if_t* nde); -static int __run_while (ase_awk_run_t* run, ase_awk_nde_while_t* nde); -static int __run_for (ase_awk_run_t* run, ase_awk_nde_for_t* nde); -static int __run_foreach (ase_awk_run_t* run, ase_awk_nde_foreach_t* nde); -static int __run_break (ase_awk_run_t* run, ase_awk_nde_break_t* nde); -static int __run_continue (ase_awk_run_t* run, ase_awk_nde_continue_t* nde); -static int __run_return (ase_awk_run_t* run, ase_awk_nde_return_t* nde); -static int __run_exit (ase_awk_run_t* run, ase_awk_nde_exit_t* nde); -static int __run_next (ase_awk_run_t* run, ase_awk_nde_next_t* nde); -static int __run_nextfile (ase_awk_run_t* run, ase_awk_nde_nextfile_t* nde); -static int __run_delete (ase_awk_run_t* run, ase_awk_nde_delete_t* nde); -static int __run_print (ase_awk_run_t* run, ase_awk_nde_print_t* nde); -static int __run_printf (ase_awk_run_t* run, ase_awk_nde_print_t* nde); -static int __formatted_output ( - ase_awk_run_t* run, int out_type, const ase_char_t* dst, - const ase_char_t* fmt, ase_size_t fmt_len, ase_awk_nde_t* args); - -static ase_awk_val_t* __eval_expression (ase_awk_run_t* run, ase_awk_nde_t* nde); -static ase_awk_val_t* __eval_expression0 (ase_awk_run_t* run, ase_awk_nde_t* nde); - -static ase_awk_val_t* __eval_group (ase_awk_run_t* run, ase_awk_nde_t* nde); - -static ase_awk_val_t* __eval_assignment ( - ase_awk_run_t* run, ase_awk_nde_t* nde); -static ase_awk_val_t* __do_assignment ( - ase_awk_run_t* run, ase_awk_nde_t* var, ase_awk_val_t* val); -static ase_awk_val_t* __do_assignment_scalar ( - ase_awk_run_t* run, ase_awk_nde_var_t* var, ase_awk_val_t* val); -static ase_awk_val_t* __do_assignment_map ( - ase_awk_run_t* run, ase_awk_nde_var_t* var, ase_awk_val_t* val); -static ase_awk_val_t* __do_assignment_pos ( - ase_awk_run_t* run, ase_awk_nde_pos_t* pos, ase_awk_val_t* val); - -static ase_awk_val_t* __eval_binary ( - ase_awk_run_t* run, ase_awk_nde_t* nde); -static ase_awk_val_t* __eval_binop_lor ( - ase_awk_run_t* run, ase_awk_nde_t* left, ase_awk_nde_t* right); -static ase_awk_val_t* __eval_binop_land ( - ase_awk_run_t* run, ase_awk_nde_t* left, ase_awk_nde_t* right); -static ase_awk_val_t* __eval_binop_in ( - ase_awk_run_t* run, ase_awk_nde_t* left, ase_awk_nde_t* right); -static ase_awk_val_t* __eval_binop_bor ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right); -static ase_awk_val_t* __eval_binop_bxor ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right); -static ase_awk_val_t* __eval_binop_band ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right); -static ase_awk_val_t* __eval_binop_eq ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right); -static ase_awk_val_t* __eval_binop_ne ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right); -static ase_awk_val_t* __eval_binop_gt ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right); -static ase_awk_val_t* __eval_binop_ge ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right); -static ase_awk_val_t* __eval_binop_lt ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right); -static ase_awk_val_t* __eval_binop_le ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right); -static ase_awk_val_t* __eval_binop_lshift ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right); -static ase_awk_val_t* __eval_binop_rshift ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right); -static ase_awk_val_t* __eval_binop_plus ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right); -static ase_awk_val_t* __eval_binop_minus ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right); -static ase_awk_val_t* __eval_binop_mul ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right); -static ase_awk_val_t* __eval_binop_div ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right); -static ase_awk_val_t* __eval_binop_idiv ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right); -static ase_awk_val_t* __eval_binop_mod ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right); -static ase_awk_val_t* __eval_binop_exp ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right); -static ase_awk_val_t* __eval_binop_concat ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right); -static ase_awk_val_t* __eval_binop_ma ( - ase_awk_run_t* run, ase_awk_nde_t* left, ase_awk_nde_t* right); -static ase_awk_val_t* __eval_binop_nm ( - ase_awk_run_t* run, ase_awk_nde_t* left, ase_awk_nde_t* right); -static ase_awk_val_t* __eval_binop_match0 ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right, - ase_size_t lline, ase_size_t rline, int ret); - -static ase_awk_val_t* __eval_unary (ase_awk_run_t* run, ase_awk_nde_t* nde); -static ase_awk_val_t* __eval_incpre (ase_awk_run_t* run, ase_awk_nde_t* nde); -static ase_awk_val_t* __eval_incpst (ase_awk_run_t* run, ase_awk_nde_t* nde); -static ase_awk_val_t* __eval_cnd (ase_awk_run_t* run, ase_awk_nde_t* nde); - -static ase_awk_val_t* __eval_bfn (ase_awk_run_t* run, ase_awk_nde_t* nde); -static ase_awk_val_t* __eval_afn (ase_awk_run_t* run, ase_awk_nde_t* nde); -static ase_awk_val_t* __eval_call ( - ase_awk_run_t* run, ase_awk_nde_t* nde, - const ase_char_t* bfn_arg_spec, ase_awk_afn_t* afn); - -static int __get_reference ( - ase_awk_run_t* run, ase_awk_nde_t* nde, ase_awk_val_t*** ref); -static ase_awk_val_t** __get_reference_indexed ( - ase_awk_run_t* run, ase_awk_nde_var_t* nde, ase_awk_val_t** val); - -static ase_awk_val_t* __eval_int (ase_awk_run_t* run, ase_awk_nde_t* nde); -static ase_awk_val_t* __eval_real (ase_awk_run_t* run, ase_awk_nde_t* nde); -static ase_awk_val_t* __eval_str (ase_awk_run_t* run, ase_awk_nde_t* nde); -static ase_awk_val_t* __eval_rex (ase_awk_run_t* run, ase_awk_nde_t* nde); -static ase_awk_val_t* __eval_named (ase_awk_run_t* run, ase_awk_nde_t* nde); -static ase_awk_val_t* __eval_global (ase_awk_run_t* run, ase_awk_nde_t* nde); -static ase_awk_val_t* __eval_local (ase_awk_run_t* run, ase_awk_nde_t* nde); -static ase_awk_val_t* __eval_arg (ase_awk_run_t* run, ase_awk_nde_t* nde); -static ase_awk_val_t* __eval_namedidx (ase_awk_run_t* run, ase_awk_nde_t* nde); -static ase_awk_val_t* __eval_globalidx (ase_awk_run_t* run, ase_awk_nde_t* nde); -static ase_awk_val_t* __eval_localidx (ase_awk_run_t* run, ase_awk_nde_t* nde); -static ase_awk_val_t* __eval_argidx (ase_awk_run_t* run, ase_awk_nde_t* nde); -static ase_awk_val_t* __eval_pos (ase_awk_run_t* run, ase_awk_nde_t* nde); -static ase_awk_val_t* __eval_getline (ase_awk_run_t* run, ase_awk_nde_t* nde); - -static int __raw_push (ase_awk_run_t* run, void* val); -#define __raw_pop(run) \ - do { \ - ASE_ASSERT ((run)->stack_top > (run)->stack_base); \ - (run)->stack_top--; \ - } while (0) -static void __raw_pop_times (ase_awk_run_t* run, ase_size_t times); - -static int __read_record (ase_awk_run_t* run); -static int __shorten_record (ase_awk_run_t* run, ase_size_t nflds); - -static ase_char_t* __idxnde_to_str ( - ase_awk_run_t* run, ase_awk_nde_t* nde, ase_size_t* len); - -typedef ase_awk_val_t* (*binop_func_t) ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right); -typedef ase_awk_val_t* (*eval_expr_t) (ase_awk_run_t* run, ase_awk_nde_t* nde); - -ase_size_t ase_awk_getnargs (ase_awk_run_t* run) -{ - return (ase_size_t) STACK_NARGS (run); -} - -ase_awk_val_t* ase_awk_getarg (ase_awk_run_t* run, ase_size_t idx) -{ - return STACK_ARG (run, idx); -} - -ase_awk_val_t* ase_awk_getglobal (ase_awk_run_t* run, ase_size_t idx) -{ - return STACK_GLOBAL (run, idx); -} - -int ase_awk_setglobal (ase_awk_run_t* run, ase_size_t idx, ase_awk_val_t* val) -{ - return __set_global (run, idx, ASE_NULL, val); -} - -static int __set_global ( - ase_awk_run_t* run, ase_size_t idx, - ase_awk_nde_var_t* var, ase_awk_val_t* val) -{ - ase_awk_val_t* old; - - old = STACK_GLOBAL (run, idx); - if (old->type == ASE_AWK_VAL_MAP) - { - /* once a variable becomes a map, - * it cannot be changed to a scalar variable */ - - if (var != ASE_NULL) - { - /* global variable */ - ase_cstr_t errarg; - - errarg.ptr = var->id.name; - errarg.len = var->id.name_len; - - ase_awk_setrunerror (run, - ASE_AWK_EMAPTOSCALAR, var->line, &errarg, 1); - } - else - { - /* ase_awk_setglobal has been called */ - ase_cstr_t errarg; - - errarg.ptr = ase_awk_getglobalname ( - run->awk, idx, &errarg.len); - ase_awk_setrunerror (run, - ASE_AWK_EMAPTOSCALAR, 0, &errarg, 1); - } - return -1; - } - - /* builtin variables except ARGV cannot be assigned a map */ - if (val->type == ASE_AWK_VAL_MAP && - (idx >= ASE_AWK_GLOBAL_ARGC && idx <= ASE_AWK_GLOBAL_SUBSEP) && - idx != ASE_AWK_GLOBAL_ARGV) - { - /* TODO: better error code */ - ase_awk_setrunerror (run, ASE_AWK_ESCALARTOMAP, 0, ASE_NULL, 0); - return -1; - } - - if (idx == ASE_AWK_GLOBAL_CONVFMT) - { - ase_char_t* convfmt_ptr; - ase_size_t convfmt_len, i; - - convfmt_ptr = ase_awk_valtostr (run, - val, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &convfmt_len); - if (convfmt_ptr == ASE_NULL) return -1; - - for (i = 0; i < convfmt_len; i++) - { - if (convfmt_ptr[i] == ASE_T('\0')) - { - ASE_AWK_FREE (run->awk, convfmt_ptr); - ase_awk_setrunerror (run, ASE_AWK_ECONVFMTCHR, 0, ASE_NULL, 0); - return -1; - } - } - - if (run->global.convfmt.ptr != ASE_NULL) - ASE_AWK_FREE (run->awk, run->global.convfmt.ptr); - run->global.convfmt.ptr = convfmt_ptr; - run->global.convfmt.len = convfmt_len; - } - else if (idx == ASE_AWK_GLOBAL_FS) - { - ase_char_t* fs_ptr; - ase_size_t fs_len; - - if (val->type == ASE_AWK_VAL_STR) - { - fs_ptr = ((ase_awk_val_str_t*)val)->buf; - fs_len = ((ase_awk_val_str_t*)val)->len; - } - else - { - /* due to the expression evaluation rule, the - * regular expression can not be an assigned value */ - ASE_ASSERT (val->type != ASE_AWK_VAL_REX); - - fs_ptr = ase_awk_valtostr ( - run, val, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &fs_len); - if (fs_ptr == ASE_NULL) return -1; - } - - if (fs_len > 1) - { - void* rex; - - /* compile the regular expression */ - /* TODO: use safebuild */ - rex = ase_awk_buildrex ( - run->awk, fs_ptr, fs_len, &run->errnum); - if (rex == ASE_NULL) - { - if (val->type != ASE_AWK_VAL_STR) - ASE_AWK_FREE (run->awk, fs_ptr); - return -1; - } - - if (run->global.fs != ASE_NULL) - { - ase_awk_freerex (run->awk, run->global.fs); - } - run->global.fs = rex; - } - - if (val->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, fs_ptr); - } - else if (idx == ASE_AWK_GLOBAL_IGNORECASE) - { - if ((val->type == ASE_AWK_VAL_INT && - ((ase_awk_val_int_t*)val)->val == 0) || - (val->type == ASE_AWK_VAL_REAL && - ((ase_awk_val_real_t*)val)->val == 0.0) || - (val->type == ASE_AWK_VAL_STR && - ((ase_awk_val_str_t*)val)->len == 0)) - { - run->global.ignorecase = 0; - } - else - { - run->global.ignorecase = 1; - } - } - else if (idx == ASE_AWK_GLOBAL_NF) - { - int n; - ase_long_t lv; - ase_real_t rv; - - n = ase_awk_valtonum (run, val, &lv, &rv); - if (n == -1) return -1; - if (n == 1) lv = (ase_long_t)rv; - - if (lv < run->inrec.nflds) - { - if (__shorten_record (run, (ase_size_t)lv) == -1) - { - /* adjust the error line */ - if (var != ASE_NULL) run->errlin = var->line; - return -1; - } - } - } - else if (idx == ASE_AWK_GLOBAL_OFMT) - { - ase_char_t* ofmt_ptr; - ase_size_t ofmt_len, i; - - ofmt_ptr = ase_awk_valtostr ( - run, val, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &ofmt_len); - if (ofmt_ptr == ASE_NULL) return -1; - - for (i = 0; i < ofmt_len; i++) - { - if (ofmt_ptr[i] == ASE_T('\0')) - { - ASE_AWK_FREE (run->awk, ofmt_ptr); - ase_awk_setrunerror (run, ASE_AWK_EOFMTCHR, 0, ASE_NULL, 0); - return -1; - } - } - - if (run->global.ofmt.ptr != ASE_NULL) - ASE_AWK_FREE (run->awk, run->global.ofmt.ptr); - run->global.ofmt.ptr = ofmt_ptr; - run->global.ofmt.len = ofmt_len; - } - else if (idx == ASE_AWK_GLOBAL_OFS) - { - ase_char_t* ofs_ptr; - ase_size_t ofs_len; - - ofs_ptr = ase_awk_valtostr ( - run, val, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &ofs_len); - if (ofs_ptr == ASE_NULL) return -1; - - if (run->global.ofs.ptr != ASE_NULL) - ASE_AWK_FREE (run->awk, run->global.ofs.ptr); - run->global.ofs.ptr = ofs_ptr; - run->global.ofs.len = ofs_len; - } - else if (idx == ASE_AWK_GLOBAL_ORS) - { - ase_char_t* ors_ptr; - ase_size_t ors_len; - - ors_ptr = ase_awk_valtostr ( - run, val, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &ors_len); - if (ors_ptr == ASE_NULL) return -1; - - if (run->global.ors.ptr != ASE_NULL) - ASE_AWK_FREE (run->awk, run->global.ors.ptr); - run->global.ors.ptr = ors_ptr; - run->global.ors.len = ors_len; - } - else if (idx == ASE_AWK_GLOBAL_RS) - { - ase_char_t* rs_ptr; - ase_size_t rs_len; - - if (val->type == ASE_AWK_VAL_STR) - { - rs_ptr = ((ase_awk_val_str_t*)val)->buf; - rs_len = ((ase_awk_val_str_t*)val)->len; - } - else - { - /* due to the expression evaluation rule, the - * regular expression can not be an assigned value */ - ASE_ASSERT (val->type != ASE_AWK_VAL_REX); - - rs_ptr = ase_awk_valtostr ( - run, val, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &rs_len); - if (rs_ptr == ASE_NULL) return -1; - } - - if (rs_len > 1) - { - void* rex; - - /* compile the regular expression */ - /* TODO: use safebuild */ - rex = ase_awk_buildrex ( - run->awk, rs_ptr, rs_len, &run->errnum); - if (rex == ASE_NULL) - { - if (val->type != ASE_AWK_VAL_STR) - ASE_AWK_FREE (run->awk, rs_ptr); - return -1; - } - - if (run->global.rs != ASE_NULL) - { - ase_awk_freerex (run->awk, run->global.rs); - } - run->global.rs = rex; - } - - if (val->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, rs_ptr); - } - else if (idx == ASE_AWK_GLOBAL_SUBSEP) - { - ase_char_t* subsep_ptr; - ase_size_t subsep_len; - - subsep_ptr = ase_awk_valtostr ( - run, val, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &subsep_len); - if (subsep_ptr == ASE_NULL) return -1; - - if (run->global.subsep.ptr != ASE_NULL) - ASE_AWK_FREE (run->awk, run->global.subsep.ptr); - run->global.subsep.ptr = subsep_ptr; - run->global.subsep.len = subsep_len; - } - - ase_awk_refdownval (run, old); - STACK_GLOBAL(run,idx) = val; - ase_awk_refupval (run, val); - - return 0; -} - -void ase_awk_setretval (ase_awk_run_t* run, ase_awk_val_t* val) -{ - ase_awk_refdownval (run, STACK_RETVAL(run)); - STACK_RETVAL(run) = val; - /* should use the same trick as __run_return_statement */ - ase_awk_refupval (run, val); -} - -int ase_awk_setfilename ( - ase_awk_run_t* run, const ase_char_t* name, ase_size_t len) -{ - ase_awk_val_t* tmp; - int n; - - if (len == 0) tmp = ase_awk_val_zls; - else - { - tmp = ase_awk_makestrval (run, name, len); - if (tmp == ASE_NULL) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - } - - ase_awk_refupval (run, tmp); - n = ase_awk_setglobal (run, ASE_AWK_GLOBAL_FILENAME, tmp); - ase_awk_refdownval (run, tmp); - - return n; -} - -int ase_awk_setofilename ( - ase_awk_run_t* run, const ase_char_t* name, ase_size_t len) -{ - ase_awk_val_t* tmp; - int n; - - if (run->awk->option & ASE_AWK_NEXTOFILE) - { - if (len == 0) tmp = ase_awk_val_zls; - else - { - tmp = ase_awk_makestrval (run, name, len); - if (tmp == ASE_NULL) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - } - - ase_awk_refupval (run, tmp); - n = ase_awk_setglobal (run, ASE_AWK_GLOBAL_OFILENAME, tmp); - ase_awk_refdownval (run, tmp); - } - else n = 0; - - return n; -} - -ase_awk_t* ase_awk_getrunawk (ase_awk_run_t* run) -{ - return run->awk; -} - -void* ase_awk_getruncustomdata (ase_awk_run_t* run) -{ - return run->custom_data; -} - -ase_awk_map_t* ase_awk_getrunnamedvarmap (ase_awk_run_t* awk) -{ - return &awk->named; -} - -int ase_awk_run (ase_awk_t* awk, - const ase_char_t* main, - ase_awk_runios_t* runios, - ase_awk_runcbs_t* runcbs, - ase_awk_runarg_t* runarg, - void* custom_data) -{ - ase_awk_run_t* run; - int n; - - /* clear the awk error code */ - ase_awk_seterror (awk, ASE_AWK_ENOERR, 0, ASE_NULL, 0); - - /* check if the code has ever been parsed */ - if (awk->tree.nglobals == 0 && - awk->tree.begin == ASE_NULL && - awk->tree.end == ASE_NULL && - awk->tree.chain_size == 0 && - ase_awk_map_getsize(&awk->tree.afns) == 0) - { - /* if not, deny the run */ - ase_awk_seterror (awk, ASE_AWK_ENOPER, 0, ASE_NULL, 0); - return -1; - } - - /* allocate the storage for the run object */ - run = (ase_awk_run_t*) ASE_AWK_MALLOC (awk, ASE_SIZEOF(ase_awk_run_t)); - if (run == ASE_NULL) - { - /* if it fails, the failure is reported thru - * the awk object */ - ase_awk_seterror (awk, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - - /* clear the run object space */ - ase_memset (run, 0, ASE_SIZEOF(ase_awk_run_t)); - - /* initialize the run object */ - if (__init_run (run, awk, runios, custom_data) == -1) - { - ASE_AWK_FREE (awk, run); - return -1; - } - - /* clear the run error */ - run->errnum = ASE_AWK_ENOERR; - run->errlin = 0; - run->errmsg[0] = ASE_T('\0'); - - run->cbs = runcbs; - - /* execute the start callback if it exists */ - if (runcbs != ASE_NULL && runcbs->on_start != ASE_NULL) - { - runcbs->on_start (run, runcbs->custom_data); - } - - /* enter the main run loop */ - n = run_main (run, main, runarg); - if (n == -1) - { - /* if no callback is specified, awk's error number - * is updated with the run's error number */ - if (runcbs == ASE_NULL) - { - awk->errnum = run->errnum; - awk->errlin = run->errlin; - - ase_strxcpy ( - awk->errmsg, ASE_COUNTOF(awk->errmsg), - run->errmsg); - } - else - { - ase_awk_seterror (awk, ASE_AWK_ERUNTIME, 0, ASE_NULL, 0); - } - } - - /* the run loop ended. execute the end callback if it exists */ - if (runcbs != ASE_NULL && runcbs->on_end != ASE_NULL) - { - runcbs->on_end (run, - ((n == -1)? run->errnum: ASE_AWK_ENOERR), - runcbs->custom_data); - - /* when using callbacks, this function always returns 0 - * after the start callbacks has been triggered */ - n = 0; - } - - /* uninitialize the run object */ - __deinit_run (run); - - ASE_AWK_FREE (awk, run); - return n; -} - -int ase_awk_stop (ase_awk_run_t* run) -{ - run->exit_level = EXIT_ABORT; - return 0; -} - -static void __free_namedval (void* run, void* val) -{ - ase_awk_refdownval ((ase_awk_run_t*)run, val); -} - -static int __init_run ( - ase_awk_run_t* run, ase_awk_t* awk, - ase_awk_runios_t* runios, void* custom_data) -{ - run->awk = awk; - run->custom_data = custom_data; - - run->stack = ASE_NULL; - run->stack_top = 0; - run->stack_base = 0; - run->stack_limit = 0; - - run->exit_level = EXIT_NONE; - - run->icache_count = 0; - run->rcache_count = 0; - run->fcache_count = 0; - - run->errnum = ASE_AWK_ENOERR; - run->errlin = 0; - run->errmsg[0] = ASE_T('\0'); - - run->inrec.buf_pos = 0; - run->inrec.buf_len = 0; - run->inrec.flds = ASE_NULL; - run->inrec.nflds = 0; - run->inrec.maxflds = 0; - run->inrec.d0 = ase_awk_val_nil; - if (ase_str_open ( - &run->inrec.line, - DEF_BUF_CAPA, &run->awk->prmfns.mmgr) == ASE_NULL) - { - ase_awk_seterror (awk, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - - if (ase_str_open ( - &run->format.out, 256, &run->awk->prmfns.mmgr) == ASE_NULL) - { - ase_str_close (&run->inrec.line); - ase_awk_seterror (awk, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - - if (ase_str_open ( - &run->format.fmt, 256, &run->awk->prmfns.mmgr) == ASE_NULL) - { - ase_str_close (&run->format.out); - ase_str_close (&run->inrec.line); - ase_awk_seterror (awk, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - - if (ase_awk_map_open (&run->named, - run, DEF_BUF_CAPA, __free_namedval, run->awk) == ASE_NULL) - { - ase_str_close (&run->format.fmt); - ase_str_close (&run->format.out); - ase_str_close (&run->inrec.line); - ase_awk_seterror (awk, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - - run->format.tmp.ptr = (ase_char_t*) - ASE_AWK_MALLOC (run->awk, 4096*ASE_SIZEOF(ase_char_t*)); - if (run->format.tmp.ptr == ASE_NULL) - { - ase_awk_map_close (&run->named); - ase_str_close (&run->format.fmt); - ase_str_close (&run->format.out); - ase_str_close (&run->inrec.line); - ase_awk_seterror (awk, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - run->format.tmp.len = 4096; - run->format.tmp.inc = 4096*2; - - if (run->awk->tree.chain_size > 0) - { - run->pattern_range_state = (ase_byte_t*) ASE_AWK_MALLOC ( - run->awk, run->awk->tree.chain_size*ASE_SIZEOF(ase_byte_t)); - if (run->pattern_range_state == ASE_NULL) - { - ASE_AWK_FREE (run->awk, run->format.tmp.ptr); - ase_awk_map_close (&run->named); - ase_str_close (&run->format.fmt); - ase_str_close (&run->format.out); - ase_str_close (&run->inrec.line); - ase_awk_seterror (awk, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - - ase_memset ( - run->pattern_range_state, 0, - run->awk->tree.chain_size * ASE_SIZEOF(ase_byte_t)); - } - else run->pattern_range_state = ASE_NULL; - - if (runios != ASE_NULL) - { - run->extio.handler[ASE_AWK_EXTIO_PIPE] = runios->pipe; - run->extio.handler[ASE_AWK_EXTIO_COPROC] = runios->coproc; - run->extio.handler[ASE_AWK_EXTIO_FILE] = runios->file; - run->extio.handler[ASE_AWK_EXTIO_CONSOLE] = runios->console; - run->extio.custom_data = runios->custom_data; - run->extio.chain = ASE_NULL; - } - - run->global.rs = ASE_NULL; - run->global.fs = ASE_NULL; - run->global.ignorecase = 0; - - run->depth.max.block = awk->run.depth.max.block; - run->depth.max.expr = awk->run.depth.max.expr; - run->depth.cur.block = 0; - run->depth.cur.expr = 0; - - return 0; -} - -static void __deinit_run (ase_awk_run_t* run) -{ - if (run->pattern_range_state != ASE_NULL) - ASE_AWK_FREE (run->awk, run->pattern_range_state); - - /* close all pending extio's */ - /* TODO: what if this operation fails? */ - ase_awk_clearextio (run); - ASE_ASSERT (run->extio.chain == ASE_NULL); - - if (run->global.rs != ASE_NULL) - { - ASE_AWK_FREE (run->awk, run->global.rs); - run->global.rs = ASE_NULL; - } - if (run->global.fs != ASE_NULL) - { - ASE_AWK_FREE (run->awk, run->global.fs); - run->global.fs = ASE_NULL; - } - - if (run->global.convfmt.ptr != ASE_NULL && - run->global.convfmt.ptr != DEFAULT_CONVFMT) - { - ASE_AWK_FREE (run->awk, run->global.convfmt.ptr); - run->global.convfmt.ptr = ASE_NULL; - run->global.convfmt.len = 0; - } - - if (run->global.ofmt.ptr != ASE_NULL && - run->global.ofmt.ptr != DEFAULT_OFMT) - { - ASE_AWK_FREE (run->awk, run->global.ofmt.ptr); - run->global.ofmt.ptr = ASE_NULL; - run->global.ofmt.len = 0; - } - - if (run->global.ofs.ptr != ASE_NULL && - run->global.ofs.ptr != DEFAULT_OFS) - { - ASE_AWK_FREE (run->awk, run->global.ofs.ptr); - run->global.ofs.ptr = ASE_NULL; - run->global.ofs.len = 0; - } - - if (run->global.ors.ptr != ASE_NULL && - run->global.ors.ptr != DEFAULT_ORS && - run->global.ors.ptr != DEFAULT_ORS_CRLF) - { - ASE_AWK_FREE (run->awk, run->global.ors.ptr); - run->global.ors.ptr = ASE_NULL; - run->global.ors.len = 0; - } - - if (run->global.subsep.ptr != ASE_NULL && - run->global.subsep.ptr != DEFAULT_SUBSEP) - { - ASE_AWK_FREE (run->awk, run->global.subsep.ptr); - run->global.subsep.ptr = ASE_NULL; - run->global.subsep.len = 0; - } - - ASE_AWK_FREE (run->awk, run->format.tmp.ptr); - run->format.tmp.ptr = ASE_NULL; - run->format.tmp.len = 0; - ase_str_close (&run->format.fmt); - ase_str_close (&run->format.out); - - /* destroy input record. ase_awk_clrrec should be called - * before the run stack has been destroyed because it may try - * to change the value to ASE_AWK_GLOBAL_NF. */ - ase_awk_clrrec (run, ase_false); - if (run->inrec.flds != ASE_NULL) - { - ASE_AWK_FREE (run->awk, run->inrec.flds); - run->inrec.flds = ASE_NULL; - run->inrec.maxflds = 0; - } - ase_str_close (&run->inrec.line); - - /* destroy run stack */ - if (run->stack != ASE_NULL) - { - ASE_ASSERT (run->stack_top == 0); - - ASE_AWK_FREE (run->awk, run->stack); - run->stack = ASE_NULL; - run->stack_top = 0; - run->stack_base = 0; - run->stack_limit = 0; - } - - /* destroy named variables */ - ase_awk_map_close (&run->named); - - /* destroy values in free list */ - while (run->icache_count > 0) - { - ase_awk_val_int_t* tmp = run->icache[--run->icache_count]; - ase_awk_freeval (run, (ase_awk_val_t*)tmp, ase_false); - } - - while (run->rcache_count > 0) - { - ase_awk_val_real_t* tmp = run->rcache[--run->rcache_count]; - ase_awk_freeval (run, (ase_awk_val_t*)tmp, ase_false); - } - - while (run->fcache_count > 0) - { - ase_awk_val_ref_t* tmp = run->fcache[--run->fcache_count]; - ase_awk_freeval (run, (ase_awk_val_t*)tmp, ase_false); - } -} - -static int __build_runarg ( - ase_awk_run_t* run, ase_awk_runarg_t* runarg, ase_size_t* nargs) -{ - ase_awk_runarg_t* p; - ase_size_t argc; - ase_awk_val_t* v_argc; - ase_awk_val_t* v_argv; - ase_awk_val_t* v_tmp; - ase_char_t key[ASE_SIZEOF(ase_long_t)*8+2]; - ase_size_t key_len; - - v_argv = ase_awk_makemapval (run); - if (v_argv == ASE_NULL) - { - ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - ase_awk_refupval (run, v_argv); - - if (runarg == ASE_NULL) argc = 0; - else - { - for (argc = 0, p = runarg; p->ptr != ASE_NULL; argc++, p++) - { - v_tmp = ase_awk_makestrval (run, p->ptr, p->len); - if (v_tmp == ASE_NULL) - { - ase_awk_refdownval (run, v_argv); - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - - key_len = ase_awk_longtostr ( - argc, 10, ASE_NULL, key, ASE_COUNTOF(key)); - ASE_ASSERT (key_len != (ase_size_t)-1); - - /* increment reference count of v_tmp in advance as if - * it has successfully been assigned into ARGV. */ - ase_awk_refupval (run, v_tmp); - - if (ase_awk_map_putx ( - ((ase_awk_val_map_t*)v_argv)->map, - key, key_len, v_tmp, ASE_NULL) == -1) - { - /* if the assignment operation fails, decrements - * the reference of v_tmp to free it */ - ase_awk_refdownval (run, v_tmp); - - /* the values previously assigned into the - * map will be freeed when v_argv is freed */ - ase_awk_refdownval (run, v_argv); - - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - } - } - - v_argc = ase_awk_makeintval (run, (ase_long_t)argc); - if (v_argc == ASE_NULL) - { - ase_awk_refdownval (run, v_argv); - ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - - ase_awk_refupval (run, v_argc); - - ASE_ASSERT ( - STACK_GLOBAL(run,ASE_AWK_GLOBAL_ARGC) == ase_awk_val_nil); - - if (ase_awk_setglobal (run, ASE_AWK_GLOBAL_ARGC, v_argc) == -1) - { - ase_awk_refdownval (run, v_argc); - ase_awk_refdownval (run, v_argv); - return -1; - } - - if (ase_awk_setglobal (run, ASE_AWK_GLOBAL_ARGV, v_argv) == -1) - { - /* ARGC is assigned nil when ARGV assignment has failed. - * However, this requires preconditions, as follows: - * 1. __build_runarg should be called in a proper place - * as it is not a generic-purpose routine. - * 2. ARGC should be nil before __build_runarg is called - * If the restoration fails, nothing can salvage it. */ - ase_awk_setglobal (run, ASE_AWK_GLOBAL_ARGC, ase_awk_val_nil); - ase_awk_refdownval (run, v_argc); - ase_awk_refdownval (run, v_argv); - return -1; - } - - ase_awk_refdownval (run, v_argc); - ase_awk_refdownval (run, v_argv); - - *nargs = argc; - return 0; -} - -static void __cleanup_globals (ase_awk_run_t* run) -{ - ase_size_t nglobals = run->awk->tree.nglobals; - while (nglobals > 0) - { - --nglobals; - ase_awk_refdownval (run, STACK_GLOBAL(run,nglobals)); - STACK_GLOBAL (run, nglobals) = ase_awk_val_nil; - } -} - -static int __update_fnr (ase_awk_run_t* run, ase_size_t fnr) -{ - ase_awk_val_t* tmp; - - tmp = ase_awk_makeintval (run, fnr); - if (tmp == ASE_NULL) - { - ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - - ase_awk_refupval (run, tmp); - if (ase_awk_setglobal (run, ASE_AWK_GLOBAL_FNR, tmp) == -1) - { - ase_awk_refdownval (run, tmp); - return -1; - } - - ase_awk_refdownval (run, tmp); - run->global.fnr = fnr; - return 0; -} - -static int __set_globals_to_default (ase_awk_run_t* run) -{ - struct __gtab_t - { - int idx; - const ase_char_t* str; - }; - - struct __gtab_t gtab[] = - { - { ASE_AWK_GLOBAL_CONVFMT, DEFAULT_CONVFMT }, - { ASE_AWK_GLOBAL_FILENAME, ASE_NULL }, - { ASE_AWK_GLOBAL_OFILENAME, ASE_NULL }, - { ASE_AWK_GLOBAL_OFMT, DEFAULT_OFMT }, - { ASE_AWK_GLOBAL_OFS, DEFAULT_OFS }, - { ASE_AWK_GLOBAL_ORS, DEFAULT_ORS }, - { ASE_AWK_GLOBAL_SUBSEP, DEFAULT_SUBSEP }, - }; - - ase_awk_val_t* tmp; - ase_size_t i, j; - - if (run->awk->option & ASE_AWK_CRLF) - { - /* ugly */ - gtab[5].str = DEFAULT_ORS_CRLF; - } - - for (i = 0; i < ASE_COUNTOF(gtab); i++) - { - if (gtab[i].str == ASE_NULL || gtab[i].str[0] == ASE_T('\0')) - { - tmp = ase_awk_val_zls; - } - else - { - tmp = ase_awk_makestrval0 (run, gtab[i].str); - if (tmp == ASE_NULL) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - } - - ase_awk_refupval (run, tmp); - - ASE_ASSERT ( - STACK_GLOBAL(run,gtab[i].idx) == ase_awk_val_nil); - - if (ase_awk_setglobal (run, gtab[i].idx, tmp) == -1) - { - for (j = 0; j < i; j++) - { - ase_awk_setglobal ( - run, gtab[i].idx, ase_awk_val_nil); - } - - ase_awk_refdownval (run, tmp); - return -1; - } - - ase_awk_refdownval (run, tmp); - } - - return 0; -} - -static int run_main ( - ase_awk_run_t* run, const ase_char_t* main, - ase_awk_runarg_t* runarg) -{ - ase_size_t nglobals, nargs, nrunargs, i; - ase_size_t saved_stack_top; - ase_awk_val_t* v; - int n; - - ASE_ASSERT (run->stack_base == 0 && run->stack_top == 0); - - /* secure space for global variables */ - saved_stack_top = run->stack_top; - - nglobals = run->awk->tree.nglobals; - - while (nglobals > 0) - { - --nglobals; - if (__raw_push(run,ase_awk_val_nil) == -1) - { - /* restore the stack_top with the saved value - * instead of calling __raw_pop as many times as - * the successful __raw_push. it is ok because - * the values pushed so far are all ase_awk_val_nil */ - run->stack_top = saved_stack_top; - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - } - - if (ase_awk_setglobal (run, ASE_AWK_GLOBAL_NR, ase_awk_val_zero) == -1) - { - /* it can simply restore the top of the stack this way - * because the values pused onto the stack so far are - * all ase_awk_val_nils */ - run->stack_top = saved_stack_top; - return -1; - } - - if (ase_awk_setglobal (run, ASE_AWK_GLOBAL_NF, ase_awk_val_zero) == -1) - { - /* it can simply restore the top of the stack this way - * because the values pused onto the stack so far are - * all ase_awk_val_nils and ase_awk_val_zeros */ - run->stack_top = saved_stack_top; - return -1; - } - - if (runarg == ASE_NULL) nrunargs = 0; - else if (__build_runarg (run, runarg, &nrunargs) == -1) - { - /* it can simply restore the top of the stack this way - * because the values pused onto the stack so far are - * all ase_awk_val_nils and ase_awk_val_zeros and - * __build_runarg doesn't push other values than them - * when it has failed */ - run->stack_top = saved_stack_top; - return -1; - } - - run->exit_level = EXIT_NONE; - - n = __update_fnr (run, 0); - if (n == 0) n = __set_globals_to_default (run); - if (n == 0 && main != ASE_NULL) - { - /* run the given function */ - ase_awk_nde_call_t nde; - - nde.type = ASE_AWK_NDE_AFN; - nde.line = 0; - nde.next = ASE_NULL; - nde.what.afn.name.ptr = (ase_char_t*)main; - nde.what.afn.name.len = ase_strlen(main); - - nde.args = ASE_NULL; - nde.nargs = 0; - - if (runarg != ASE_NULL) - { - /* prepare to pass the arguments to the main function */ - for (i = nrunargs; i > 0; ) - { - ase_awk_nde_str_t* tmp, * tmp2; - - i--; - tmp = (ase_awk_nde_str_t*) ASE_AWK_MALLOC ( - run->awk, ASE_SIZEOF(*tmp)); - if (tmp == ASE_NULL) - { - tmp = (ase_awk_nde_str_t*)nde.args; - while (tmp != ASE_NULL) - { - tmp2 = (ase_awk_nde_str_t*)tmp->next; - ASE_AWK_FREE (run->awk, tmp->buf); - ASE_AWK_FREE (run->awk, tmp); - tmp = tmp2; - } - __cleanup_globals (run); - run->stack_top = saved_stack_top; - - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - - tmp->type = ASE_AWK_NDE_STR; - tmp->buf = ase_strxdup ( - runarg[i].ptr, runarg[i].len, - &run->awk->prmfns.mmgr); - if (tmp->buf == ASE_NULL) - { - ASE_AWK_FREE (run->awk, tmp); - tmp = (ase_awk_nde_str_t*)nde.args; - while (tmp != ASE_NULL) - { - tmp2 = (ase_awk_nde_str_t*)tmp->next; - ASE_AWK_FREE (run->awk, tmp->buf); - ASE_AWK_FREE (run->awk, tmp); - tmp = tmp2; - } - __cleanup_globals (run); - run->stack_top = saved_stack_top; - - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - - tmp->len = runarg[i].len; - tmp->next = nde.args; - nde.args = (ase_awk_nde_t*)tmp; - nde.nargs++; - } - - ASE_ASSERT (nrunargs == nde.nargs); - } - - v = __eval_afn (run, (ase_awk_nde_t*)&nde); - if (v == ASE_NULL) n = -1; - else - { - ase_awk_refupval (run, v); - - if (run->cbs != ASE_NULL && run->cbs->on_return != ASE_NULL) - { - run->cbs->on_return (run, v, run->cbs->custom_data); - } - - ase_awk_refdownval (run, v); - } - - if (nde.args != ASE_NULL) ase_awk_clrpt (run->awk, nde.args); - } - else if (n == 0) - { - /* no main function is specified. - * run the normal patter blocks including BEGIN and END */ - saved_stack_top = run->stack_top; - - if (__raw_push(run,(void*)run->stack_base) == -1) - { - /* restore the stack top in a cheesy(?) way */ - run->stack_top = saved_stack_top; - /* pops off global variables in a decent way */ - __cleanup_globals (run); - __raw_pop_times (run, run->awk->tree.nglobals); - - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - - if (__raw_push(run,(void*)saved_stack_top) == -1) - { - run->stack_top = saved_stack_top; - __cleanup_globals (run); - __raw_pop_times (run, run->awk->tree.nglobals); - - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - - /* secure space for a return value */ - if (__raw_push(run,ase_awk_val_nil) == -1) - { - run->stack_top = saved_stack_top; - __cleanup_globals (run); - __raw_pop_times (run, run->awk->tree.nglobals); - - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - - /* secure space for nargs */ - if (__raw_push(run,ase_awk_val_nil) == -1) - { - run->stack_top = saved_stack_top; - __cleanup_globals (run); - __raw_pop_times (run, run->awk->tree.nglobals); - - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - - run->stack_base = saved_stack_top; - - /* set nargs to zero */ - nargs = 0; - STACK_NARGS(run) = (void*)nargs; - - /* stack set up properly. ready to exeucte statement blocks */ - if (n == 0 && - run->awk->tree.begin != ASE_NULL && - run->exit_level != EXIT_ABORT) - { - ase_awk_nde_blk_t* blk; - - blk = (ase_awk_nde_blk_t*)run->awk->tree.begin; - ASE_ASSERT (blk->type == ASE_AWK_NDE_BLK); - - run->active_block = blk; - run->exit_level = EXIT_NONE; - if (__run_block (run, blk) == -1) n = -1; - } - - if (n == 0 && - (run->awk->tree.chain != ASE_NULL || - run->awk->tree.end != ASE_NULL) && - run->exit_level != EXIT_ABORT) - { - if (__run_pattern_blocks (run) == -1) n = -1; - } - - if (n == 0 && - run->awk->tree.end != ASE_NULL && - run->exit_level != EXIT_ABORT) - { - ase_awk_nde_blk_t* blk; - - blk = (ase_awk_nde_blk_t*)run->awk->tree.end; - ASE_ASSERT (blk->type == ASE_AWK_NDE_BLK); - - run->active_block = blk; - run->exit_level = EXIT_NONE; - if (__run_block (run, blk) == -1) n = -1; - } - - /* restore stack */ - nargs = (ase_size_t)STACK_NARGS(run); - ASE_ASSERT (nargs == 0); - for (i = 0; i < nargs; i++) - { - ase_awk_refdownval (run, STACK_ARG(run,i)); - } - - v = STACK_RETVAL(run); - if (n == 0) - { - if (run->cbs != ASE_NULL && run->cbs->on_return != ASE_NULL) - { - run->cbs->on_return (run, v, run->cbs->custom_data); - } - } - /* end the life of the global return value */ - ase_awk_refdownval (run, v); - - run->stack_top = - (ase_size_t)run->stack[run->stack_base+1]; - run->stack_base = - (ase_size_t)run->stack[run->stack_base+0]; - } - - /* pops off the global variables */ - nglobals = run->awk->tree.nglobals; - while (nglobals > 0) - { - --nglobals; - ase_awk_refdownval (run, STACK_GLOBAL(run,nglobals)); - __raw_pop (run); - } - - /* reset the exit level */ - run->exit_level = EXIT_NONE; - - return n; -} - -static int __run_pattern_blocks (ase_awk_run_t* run) -{ - int n; - -#define ADJUST_ERROR_LINE(run) \ - if (run->awk->tree.chain != ASE_NULL) \ - { \ - if (run->awk->tree.chain->pattern != ASE_NULL) \ - run->errlin = run->awk->tree.chain->pattern->line; \ - else if (run->awk->tree.chain->action != ASE_NULL) \ - run->errlin = run->awk->tree.chain->action->line; \ - } \ - else if (run->awk->tree.end != ASE_NULL) \ - { \ - run->errlin = run->awk->tree.end->line; \ - } - - run->inrec.buf_pos = 0; - run->inrec.buf_len = 0; - run->inrec.eof = ase_false; - - /* run each pattern block */ - while (run->exit_level != EXIT_GLOBAL && - run->exit_level != EXIT_ABORT) - { - run->exit_level = EXIT_NONE; - - n = __read_record (run); - if (n == -1) - { - ADJUST_ERROR_LINE (run); - return -1; /* error */ - } - if (n == 0) break; /* end of input */ - - if (__update_fnr (run, run->global.fnr+1) == -1) - { - ADJUST_ERROR_LINE (run); - return -1; - } - - if (run->awk->tree.chain != ASE_NULL) - { - if (__run_pattern_block_chain ( - run, run->awk->tree.chain) == -1) return -1; - } - } - -#undef ADJUST_ERROR_LINE - return 0; -} - -static int __run_pattern_block_chain (ase_awk_run_t* run, ase_awk_chain_t* chain) -{ - ase_size_t block_no = 0; - - while (run->exit_level != EXIT_GLOBAL && - run->exit_level != EXIT_ABORT && chain != ASE_NULL) - { - if (run->exit_level == EXIT_NEXT) - { - run->exit_level = EXIT_NONE; - break; - } - - if (__run_pattern_block (run, chain, block_no) == -1) return -1; - - chain = chain->next; - block_no++; - } - - return 0; -} - -static int __run_pattern_block ( - ase_awk_run_t* run, ase_awk_chain_t* chain, ase_size_t block_no) -{ - ase_awk_nde_t* ptn; - ase_awk_nde_blk_t* blk; - - ptn = chain->pattern; - blk = (ase_awk_nde_blk_t*)chain->action; - - if (ptn == ASE_NULL) - { - /* just execute the block */ - run->active_block = blk; - if (__run_block (run, blk) == -1) return -1; - } - else - { - if (ptn->next == ASE_NULL) - { - /* pattern { ... } */ - ase_awk_val_t* v1; - - v1 = __eval_expression (run, ptn); - if (v1 == ASE_NULL) return -1; - - ase_awk_refupval (run, v1); - - if (ase_awk_valtobool (run, v1)) - { - run->active_block = blk; - if (__run_block (run, blk) == -1) - { - ase_awk_refdownval (run, v1); - return -1; - } - } - - ase_awk_refdownval (run, v1); - } - else - { - /* pattern, pattern { ... } */ - ASE_ASSERT (ptn->next->next == ASE_NULL); - ASE_ASSERT (run->pattern_range_state != ASE_NULL); - - if (run->pattern_range_state[block_no] == 0) - { - ase_awk_val_t* v1; - - v1 = __eval_expression (run, ptn); - if (v1 == ASE_NULL) return -1; - ase_awk_refupval (run, v1); - - if (ase_awk_valtobool (run, v1)) - { - run->active_block = blk; - if (__run_block (run, blk) == -1) - { - ase_awk_refdownval (run, v1); - return -1; - } - - run->pattern_range_state[block_no] = 1; - } - - ase_awk_refdownval (run, v1); - } - else if (run->pattern_range_state[block_no] == 1) - { - ase_awk_val_t* v2; - - v2 = __eval_expression (run, ptn->next); - if (v2 == ASE_NULL) return -1; - ase_awk_refupval (run, v2); - - run->active_block = blk; - if (__run_block (run, blk) == -1) - { - ase_awk_refdownval (run, v2); - return -1; - } - - if (ase_awk_valtobool (run, v2)) - run->pattern_range_state[block_no] = 0; - - ase_awk_refdownval (run, v2); - } - } - } - - return 0; -} - -static int __run_block (ase_awk_run_t* run, ase_awk_nde_blk_t* nde) -{ - int n; - - if (run->depth.max.block > 0 && - run->depth.cur.block >= run->depth.max.block) - { - ase_awk_setrunerror ( - run, ASE_AWK_EBLKNST, nde->line, ASE_NULL, 0); - return -1;; - } - - run->depth.cur.block++; - n = __run_block0 (run, nde); - run->depth.cur.block--; - - return n; -} - -static int __run_block0 (ase_awk_run_t* run, ase_awk_nde_blk_t* nde) -{ - ase_awk_nde_t* p; - ase_size_t nlocals; - ase_size_t saved_stack_top; - int n = 0; - - if (nde == ASE_NULL) - { - /* blockless pattern - execute print $0*/ - ase_awk_refupval (run, run->inrec.d0); - - n = ase_awk_writeextio_str (run, - ASE_AWK_OUT_CONSOLE, ASE_T(""), - ASE_STR_BUF(&run->inrec.line), - ASE_STR_LEN(&run->inrec.line)); - if (n == -1) - { - ase_awk_refdownval (run, run->inrec.d0); - - /* adjust the error line */ - run->errlin = nde->line; - - return -1; - } - - n = ase_awk_writeextio_str ( - run, ASE_AWK_OUT_CONSOLE, ASE_T(""), - run->global.ors.ptr, run->global.ors.len); - if (n == -1) - { - ase_awk_refdownval (run, run->inrec.d0); - - /* adjust the error line */ - run->errlin = nde->line; - - return -1; - } - - ase_awk_refdownval (run, run->inrec.d0); - return 0; - } - - ASE_ASSERT (nde->type == ASE_AWK_NDE_BLK); - - p = nde->body; - nlocals = nde->nlocals; - -#ifdef DEBUG_RUN - ase_dprintf ( - ASE_T("securing space for local variables nlocals = %d\n"), - (int)nlocals); -#endif - - saved_stack_top = run->stack_top; - - /* secure space for local variables */ - while (nlocals > 0) - { - --nlocals; - if (__raw_push(run,ase_awk_val_nil) == -1) - { - /* restore stack top */ - run->stack_top = saved_stack_top; - return -1; - } - - /* refupval is not required for ase_awk_val_nil */ - } - -#ifdef DEBUG_RUN - ase_dprintf (ASE_T("executing block statements\n")); -#endif - - while (p != ASE_NULL && run->exit_level == EXIT_NONE) - { - if (__run_statement (run, p) == -1) - { - n = -1; - break; - } - p = p->next; - } - - /* pop off local variables */ -#ifdef DEBUG_RUN - ase_dprintf (ASE_T("popping off local variables\n")); -#endif - nlocals = nde->nlocals; - while (nlocals > 0) - { - --nlocals; - ase_awk_refdownval (run, STACK_LOCAL(run,nlocals)); - __raw_pop (run); - } - - return n; -} - -static int __run_statement (ase_awk_run_t* run, ase_awk_nde_t* nde) -{ - if (run->cbs != ASE_NULL && run->cbs->on_statement != ASE_NULL) - { - run->cbs->on_statement (run, nde->line, run->custom_data); - } - - switch (nde->type) - { - case ASE_AWK_NDE_NULL: - { - /* do nothing */ - break; - } - - case ASE_AWK_NDE_BLK: - { - if (__run_block (run, - (ase_awk_nde_blk_t*)nde) == -1) return -1; - break; - } - - case ASE_AWK_NDE_IF: - { - if (__run_if (run, - (ase_awk_nde_if_t*)nde) == -1) return -1; - break; - } - - case ASE_AWK_NDE_WHILE: - case ASE_AWK_NDE_DOWHILE: - { - if (__run_while (run, - (ase_awk_nde_while_t*)nde) == -1) return -1; - break; - } - - case ASE_AWK_NDE_FOR: - { - if (__run_for (run, - (ase_awk_nde_for_t*)nde) == -1) return -1; - break; - } - - case ASE_AWK_NDE_FOREACH: - { - if (__run_foreach (run, - (ase_awk_nde_foreach_t*)nde) == -1) return -1; - break; - } - - case ASE_AWK_NDE_BREAK: - { - if (__run_break (run, - (ase_awk_nde_break_t*)nde) == -1) return -1; - break; - } - - case ASE_AWK_NDE_CONTINUE: - { - if (__run_continue (run, - (ase_awk_nde_continue_t*)nde) == -1) return -1; - break; - } - - case ASE_AWK_NDE_RETURN: - { - if (__run_return (run, - (ase_awk_nde_return_t*)nde) == -1) return -1; - break; - } - - case ASE_AWK_NDE_EXIT: - { - if (__run_exit (run, - (ase_awk_nde_exit_t*)nde) == -1) return -1; - break; - } - - case ASE_AWK_NDE_NEXT: - { - if (__run_next (run, - (ase_awk_nde_next_t*)nde) == -1) return -1; - break; - } - - case ASE_AWK_NDE_NEXTFILE: - { - if (__run_nextfile (run, - (ase_awk_nde_nextfile_t*)nde) == -1) return -1; - break; - } - - case ASE_AWK_NDE_DELETE: - { - if (__run_delete (run, - (ase_awk_nde_delete_t*)nde) == -1) return -1; - break; - } - - case ASE_AWK_NDE_PRINT: - { - if (__run_print (run, - (ase_awk_nde_print_t*)nde) == -1) return -1; - break; - } - - case ASE_AWK_NDE_PRINTF: - { - if (__run_printf (run, - (ase_awk_nde_print_t*)nde) == -1) return -1; - break; - } - - default: - { - ase_awk_val_t* v; - v = __eval_expression (run, nde); - if (v == ASE_NULL) return -1; - - /* destroy the value if not referenced */ - ase_awk_refupval (run, v); - ase_awk_refdownval (run, v); - - break; - } - } - - return 0; -} - -static int __run_if (ase_awk_run_t* run, ase_awk_nde_if_t* nde) -{ - ase_awk_val_t* test; - int n = 0; - - /* the test expression for the if statement cannot have - * chained expressions. this should not be allowed by the - * parser first of all */ - ASE_ASSERT (nde->test->next == ASE_NULL); - - test = __eval_expression (run, nde->test); - if (test == ASE_NULL) return -1; - - ase_awk_refupval (run, test); - if (ase_awk_valtobool (run, test)) - { - n = __run_statement (run, nde->then_part); - } - else if (nde->else_part != ASE_NULL) - { - n = __run_statement (run, nde->else_part); - } - - ase_awk_refdownval (run, test); /* TODO: is this correct?*/ - return n; -} - -static int __run_while (ase_awk_run_t* run, ase_awk_nde_while_t* nde) -{ - ase_awk_val_t* test; - - if (nde->type == ASE_AWK_NDE_WHILE) - { - /* no chained expressions are allowed for the test - * expression of the while statement */ - ASE_ASSERT (nde->test->next == ASE_NULL); - - while (1) - { - test = __eval_expression (run, nde->test); - if (test == ASE_NULL) return -1; - - ase_awk_refupval (run, test); - - if (ase_awk_valtobool (run, test)) - { - if (__run_statement(run,nde->body) == -1) - { - ase_awk_refdownval (run, test); - return -1; - } - } - else - { - ase_awk_refdownval (run, test); - break; - } - - ase_awk_refdownval (run, test); - - if (run->exit_level == EXIT_BREAK) - { - run->exit_level = EXIT_NONE; - break; - } - else if (run->exit_level == EXIT_CONTINUE) - { - run->exit_level = EXIT_NONE; - } - else if (run->exit_level != EXIT_NONE) break; - } - } - else if (nde->type == ASE_AWK_NDE_DOWHILE) - { - /* no chained expressions are allowed for the test - * expression of the while statement */ - ASE_ASSERT (nde->test->next == ASE_NULL); - - do - { - if (__run_statement(run,nde->body) == -1) return -1; - - if (run->exit_level == EXIT_BREAK) - { - run->exit_level = EXIT_NONE; - break; - } - else if (run->exit_level == EXIT_CONTINUE) - { - run->exit_level = EXIT_NONE; - } - else if (run->exit_level != EXIT_NONE) break; - - test = __eval_expression (run, nde->test); - if (test == ASE_NULL) return -1; - - ase_awk_refupval (run, test); - - if (!ase_awk_valtobool (run, test)) - { - ase_awk_refdownval (run, test); - break; - } - - ase_awk_refdownval (run, test); - } - while (1); - } - - return 0; -} - -static int __run_for (ase_awk_run_t* run, ase_awk_nde_for_t* nde) -{ - ase_awk_val_t* val; - - if (nde->init != ASE_NULL) - { - ASE_ASSERT (nde->init->next == ASE_NULL); - val = __eval_expression(run,nde->init); - if (val == ASE_NULL) return -1; - - ase_awk_refupval (run, val); - ase_awk_refdownval (run, val); - } - - while (1) - { - if (nde->test != ASE_NULL) - { - ase_awk_val_t* test; - - /* no chained expressions for the test expression of - * the for statement are allowed */ - ASE_ASSERT (nde->test->next == ASE_NULL); - - test = __eval_expression (run, nde->test); - if (test == ASE_NULL) return -1; - - ase_awk_refupval (run, test); - if (ase_awk_valtobool (run, test)) - { - if (__run_statement(run,nde->body) == -1) - { - ase_awk_refdownval (run, test); - return -1; - } - } - else - { - ase_awk_refdownval (run, test); - break; - } - - ase_awk_refdownval (run, test); - } - else - { - if (__run_statement(run,nde->body) == -1) return -1; - } - - if (run->exit_level == EXIT_BREAK) - { - run->exit_level = EXIT_NONE; - break; - } - else if (run->exit_level == EXIT_CONTINUE) - { - run->exit_level = EXIT_NONE; - } - else if (run->exit_level != EXIT_NONE) break; - - if (nde->incr != ASE_NULL) - { - ASE_ASSERT (nde->incr->next == ASE_NULL); - val = __eval_expression(run,nde->incr); - if (val == ASE_NULL) return -1; - - ase_awk_refupval (run, val); - ase_awk_refdownval (run, val); - } - } - - return 0; -} - -struct __foreach_walker_t -{ - ase_awk_run_t* run; - ase_awk_nde_t* var; - ase_awk_nde_t* body; -}; - -static int __walk_foreach (ase_awk_pair_t* pair, void* arg) -{ - struct __foreach_walker_t* w = (struct __foreach_walker_t*)arg; - ase_awk_val_t* str; - - str = (ase_awk_val_t*) ase_awk_makestrval ( - w->run, pair->key, ase_strlen(pair->key)); - if (str == ASE_NULL) - { - ase_awk_setrunerror ( - w->run, ASE_AWK_ENOMEM, w->var->line, ASE_NULL, 0); - return -1; - } - - ase_awk_refupval (w->run, str); - if (__do_assignment (w->run, w->var, str) == ASE_NULL) - { - ase_awk_refdownval (w->run, str); - return -1; - } - - if (__run_statement (w->run, w->body) == -1) - { - ase_awk_refdownval (w->run, str); - return -1; - } - - ase_awk_refdownval (w->run, str); - return 0; -} - -static int __run_foreach (ase_awk_run_t* run, ase_awk_nde_foreach_t* nde) -{ - int n; - ase_awk_nde_exp_t* test; - ase_awk_val_t* rv; - ase_awk_map_t* map; - struct __foreach_walker_t walker; - - test = (ase_awk_nde_exp_t*)nde->test; - ASE_ASSERT ( - test->type == ASE_AWK_NDE_EXP_BIN && - test->opcode == ASE_AWK_BINOP_IN); - - /* chained expressions should not be allowed - * by the parser first of all */ - ASE_ASSERT (test->right->next == ASE_NULL); - - rv = __eval_expression (run, test->right); - if (rv == ASE_NULL) return -1; - - ase_awk_refupval (run, rv); - if (rv->type != ASE_AWK_VAL_MAP) - { - ase_awk_refdownval (run, rv); - - ase_awk_setrunerror ( - run, ASE_AWK_ENOTMAPIN, test->right->line, ASE_NULL, 0); - return -1; - } - map = ((ase_awk_val_map_t*)rv)->map; - - walker.run = run; - walker.var = test->left; - walker.body = nde->body; - n = ase_awk_map_walk (map, __walk_foreach, &walker); - - ase_awk_refdownval (run, rv); - return n; -} - -static int __run_break (ase_awk_run_t* run, ase_awk_nde_break_t* nde) -{ - run->exit_level = EXIT_BREAK; - return 0; -} - -static int __run_continue (ase_awk_run_t* run, ase_awk_nde_continue_t* nde) -{ - run->exit_level = EXIT_CONTINUE; - return 0; -} - -static int __run_return (ase_awk_run_t* run, ase_awk_nde_return_t* nde) -{ - if (nde->val != ASE_NULL) - { - ase_awk_val_t* val; - - /* chained expressions should not be allowed - * by the parser first of all */ - ASE_ASSERT (nde->val->next == ASE_NULL); - - val = __eval_expression (run, nde->val); - if (val == ASE_NULL) return -1; - - ase_awk_refdownval (run, STACK_RETVAL(run)); - STACK_RETVAL(run) = val; - ase_awk_refupval (run, val); /* see __eval_call for the trick */ - } - - run->exit_level = EXIT_FUNCTION; - return 0; -} - -static int __run_exit (ase_awk_run_t* run, ase_awk_nde_exit_t* nde) -{ - if (nde->val != ASE_NULL) - { - ase_awk_val_t* val; - - /* chained expressions should not be allowed - * by the parser first of all */ - ASE_ASSERT (nde->val->next == ASE_NULL); - - val = __eval_expression (run, nde->val); - if (val == ASE_NULL) return -1; - - ase_awk_refdownval (run, STACK_RETVAL_GLOBAL(run)); - STACK_RETVAL_GLOBAL(run) = val; /* global return value */ - - ase_awk_refupval (run, val); - } - - run->exit_level = EXIT_GLOBAL; - return 0; -} - -static int __run_next (ase_awk_run_t* run, ase_awk_nde_next_t* nde) -{ - /* the parser checks if next has been called in the begin/end - * block or whereever inappropriate. so the runtime doesn't - * check that explicitly */ - if (run->active_block == (ase_awk_nde_blk_t*)run->awk->tree.begin) - { - ase_awk_setrunerror ( - run, ASE_AWK_ERNEXTBEG, nde->line, ASE_NULL, 0); - return -1; - } - else if (run->active_block == (ase_awk_nde_blk_t*)run->awk->tree.end) - { - ase_awk_setrunerror ( - run, ASE_AWK_ERNEXTEND, nde->line, ASE_NULL, 0); - return -1; - } - - run->exit_level = EXIT_NEXT; - return 0; -} - -static int __run_nextinfile (ase_awk_run_t* run, ase_awk_nde_nextfile_t* nde) -{ - int n; - - /* normal nextfile statement */ - if (run->active_block == (ase_awk_nde_blk_t*)run->awk->tree.begin) - { - ase_awk_setrunerror ( - run, ASE_AWK_ERNEXTFBEG, nde->line, ASE_NULL, 0); - return -1; - } - else if (run->active_block == (ase_awk_nde_blk_t*)run->awk->tree.end) - { - ase_awk_setrunerror ( - run, ASE_AWK_ERNEXTFEND, nde->line, ASE_NULL, 0); - return -1; - } - - n = ase_awk_nextextio_read (run, ASE_AWK_IN_CONSOLE, ASE_T("")); - if (n == -1) - { - /* adjust the error line */ - run->errlin = nde->line; - return -1; - } - - if (n == 0) - { - /* no more input console */ - run->exit_level = EXIT_GLOBAL; - return 0; - } - - if (__update_fnr (run, 0) == -1) - { - run->errlin = nde->line; - return -1; - } - - run->exit_level = EXIT_NEXT; - return 0; - -} - -static int __run_nextoutfile (ase_awk_run_t* run, ase_awk_nde_nextfile_t* nde) -{ - int n; - - n = ase_awk_nextextio_write (run, ASE_AWK_OUT_CONSOLE, ASE_T("")); - if (n == -1) - { - /* adjust the error line */ - run->errlin = nde->line; - return -1; - } - - if (n == 0) - { - /* TODO: should it terminate the program - * when there is no more output console? */ - /*run->exit_level = EXIT_GLOBAL;*/ - return 0; - } - - return 0; -} - -static int __run_nextfile (ase_awk_run_t* run, ase_awk_nde_nextfile_t* nde) -{ - return (nde->out)? - __run_nextoutfile (run, nde): - __run_nextinfile (run, nde); -} - -static int __run_delete (ase_awk_run_t* run, ase_awk_nde_delete_t* nde) -{ - ase_awk_nde_var_t* var; - - var = (ase_awk_nde_var_t*) nde->var; - - if (var->type == ASE_AWK_NDE_NAMED || - var->type == ASE_AWK_NDE_NAMEDIDX) - { - ase_awk_pair_t* pair; - - ASE_ASSERTX ( - (var->type == ASE_AWK_NDE_NAMED && var->idx == ASE_NULL) || - (var->type == ASE_AWK_NDE_NAMEDIDX && var->idx != ASE_NULL), - "if a named variable has an index part and a named indexed variable doesn't have an index part, the program is definitely wrong"); - - pair = ase_awk_map_get ( - &run->named, var->id.name, var->id.name_len); - if (pair == ASE_NULL) - { - ase_awk_val_t* tmp; - - /* value not set for the named variable. - * create a map and assign it to the variable */ - - tmp = ase_awk_makemapval (run); - if (tmp == ASE_NULL) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, - ASE_NULL, 0); - return -1; - } - - if (ase_awk_map_put (&run->named, - var->id.name, var->id.name_len, tmp) == ASE_NULL) - { - ase_awk_refupval (run, tmp); - ase_awk_refdownval (run, tmp); - - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, var->line, - ASE_NULL, 0); - return -1; - } - - /* as this is the assignment, it needs to update - * the reference count of the target value */ - ase_awk_refupval (run, tmp); - } - else - { - ase_awk_val_t* val; - ase_awk_map_t* map; - - val = (ase_awk_val_t*)pair->val; - ASE_ASSERT (val != ASE_NULL); - - if (val->type != ASE_AWK_VAL_MAP) - { - ase_cstr_t errarg; - - errarg.ptr = var->id.name; - errarg.len = var->id.name_len; - - ase_awk_setrunerror ( - run, ASE_AWK_ENOTDEL, var->line, - &errarg, 1); - return -1; - } - - map = ((ase_awk_val_map_t*)val)->map; - if (var->type == ASE_AWK_NDE_NAMEDIDX) - { - ase_char_t* key; - ase_size_t key_len; - ase_awk_val_t* idx; - - ASE_ASSERT (var->idx != ASE_NULL); - - idx = __eval_expression (run, var->idx); - if (idx == ASE_NULL) return -1; - - ase_awk_refupval (run, idx); - key = ase_awk_valtostr ( - run, idx, ASE_AWK_VALTOSTR_CLEAR, - ASE_NULL, &key_len); - ase_awk_refdownval (run, idx); - - if (key == ASE_NULL) - { - /* change the error line */ - run->errlin = var->line; - return -1; - } - - ase_awk_map_remove (map, key, key_len); - ASE_AWK_FREE (run->awk, key); - } - else - { - ase_awk_map_clear (map); - } - } - } - else if (var->type == ASE_AWK_NDE_GLOBAL || - var->type == ASE_AWK_NDE_LOCAL || - var->type == ASE_AWK_NDE_ARG || - var->type == ASE_AWK_NDE_GLOBALIDX || - var->type == ASE_AWK_NDE_LOCALIDX || - var->type == ASE_AWK_NDE_ARGIDX) - { - ase_awk_val_t* val; - - if (var->type == ASE_AWK_NDE_GLOBAL || - var->type == ASE_AWK_NDE_GLOBALIDX) - val = STACK_GLOBAL (run,var->id.idxa); - else if (var->type == ASE_AWK_NDE_LOCAL || - var->type == ASE_AWK_NDE_LOCALIDX) - val = STACK_LOCAL (run,var->id.idxa); - else val = STACK_ARG (run,var->id.idxa); - - ASE_ASSERT (val != ASE_NULL); - - if (val->type == ASE_AWK_VAL_NIL) - { - ase_awk_val_t* tmp; - - /* value not set for the named variable. - * create a map and assign it to the variable */ - - tmp = ase_awk_makemapval (run); - if (tmp == ASE_NULL) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, - ASE_NULL, 0); - return -1; - } - - /* no need to reduce the reference count of - * the previous value because it was nil. */ - if (var->type == ASE_AWK_NDE_GLOBAL || - var->type == ASE_AWK_NDE_GLOBALIDX) - { - if (ase_awk_setglobal ( - run, var->id.idxa, tmp) == -1) - { - ase_awk_refupval (run, tmp); - ase_awk_refdownval (run, tmp); - - run->errlin = var->line; - return -1; - } - } - else if (var->type == ASE_AWK_NDE_LOCAL || - var->type == ASE_AWK_NDE_LOCALIDX) - { - STACK_LOCAL(run,var->id.idxa) = tmp; - ase_awk_refupval (run, tmp); - } - else - { - STACK_ARG(run,var->id.idxa) = tmp; - ase_awk_refupval (run, tmp); - } - } - else - { - ase_awk_map_t* map; - - if (val->type != ASE_AWK_VAL_MAP) - { - ase_cstr_t errarg; - - errarg.ptr = var->id.name; - errarg.len = var->id.name_len; - - ase_awk_setrunerror ( - run, ASE_AWK_ENOTDEL, var->line, - &errarg, 1); - return -1; - } - - map = ((ase_awk_val_map_t*)val)->map; - if (var->type == ASE_AWK_NDE_GLOBALIDX || - var->type == ASE_AWK_NDE_LOCALIDX || - var->type == ASE_AWK_NDE_ARGIDX) - { - ase_char_t* key; - ase_size_t key_len; - ase_awk_val_t* idx; - - ASE_ASSERT (var->idx != ASE_NULL); - - idx = __eval_expression (run, var->idx); - if (idx == ASE_NULL) return -1; - - ase_awk_refupval (run, idx); - key = ase_awk_valtostr ( - run, idx, ASE_AWK_VALTOSTR_CLEAR, - ASE_NULL, &key_len); - ase_awk_refdownval (run, idx); - - if (key == ASE_NULL) - { - run->errlin = var->line; - return -1; - } - - ase_awk_map_remove (map, key, key_len); - ASE_AWK_FREE (run->awk, key); - } - else - { - ase_awk_map_clear (map); - } - } - } - else - { - ASE_ASSERTX ( - !"should never happen - wrong target for delete", - "the delete statement cannot be called with other nodes than the variables such as a named variable, a named indexed variable, etc"); - - ase_awk_setrunerror ( - run, ASE_AWK_ERDELETE, var->line, ASE_NULL, 0); - return -1; - } - - return 0; -} - -static int __run_print (ase_awk_run_t* run, ase_awk_nde_print_t* nde) -{ - ase_char_t* out = ASE_NULL; - const ase_char_t* dst; - ase_awk_val_t* v; - int n; - - ASE_ASSERT ( - (nde->out_type == ASE_AWK_OUT_PIPE && nde->out != ASE_NULL) || - (nde->out_type == ASE_AWK_OUT_COPROC && nde->out != ASE_NULL) || - (nde->out_type == ASE_AWK_OUT_FILE && nde->out != ASE_NULL) || - (nde->out_type == ASE_AWK_OUT_FILE_APPEND && nde->out != ASE_NULL) || - (nde->out_type == ASE_AWK_OUT_CONSOLE && nde->out == ASE_NULL)); - - /* check if destination has been specified. */ - if (nde->out != ASE_NULL) - { - ase_size_t len; - - /* if so, resolve the destination name */ - v = __eval_expression (run, nde->out); - if (v == ASE_NULL) return -1; - - ase_awk_refupval (run, v); - out = ase_awk_valtostr ( - run, v, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &len); - if (out == ASE_NULL) - { - ase_awk_refdownval (run, v); - - /* change the error line */ - run->errlin = nde->line; - return -1; - } - ase_awk_refdownval (run, v); - - if (len <= 0) - { - /* the destination name is empty */ - ASE_AWK_FREE (run->awk, out); - ase_awk_setrunerror ( - run, ASE_AWK_EIONMEM, nde->line, ASE_NULL, 0); - return -1; - } - - /* it needs to check if the destination name contains - * any invalid characters to the underlying system */ - while (len > 0) - { - if (out[--len] == ASE_T('\0')) - { - /* if so, it skips writing */ - ASE_AWK_FREE (run->awk, out); - ase_awk_setrunerror ( - run, ASE_AWK_EIONMNL, nde->line, - ASE_NULL, 0); - return -1; - } - } - } - - /* transforms the destination to suit the usage with extio */ - dst = (out == ASE_NULL)? ASE_T(""): out; - - /* check if print is followed by any arguments */ - if (nde->args == ASE_NULL) - { - /* if it doesn't have any arguments, print the entire - * input record */ - n = ase_awk_writeextio_str ( - run, nde->out_type, dst, - ASE_STR_BUF(&run->inrec.line), - ASE_STR_LEN(&run->inrec.line)); - if (n <= -1 /*&& run->errnum != ASE_AWK_EIOIMPL*/) - { - if (out != ASE_NULL) - ASE_AWK_FREE (run->awk, out); - - /* adjust the error line */ - run->errlin = nde->line; - return -1; - } - } - else - { - /* if it has any arguments, print the arguments separated by - * the value OFS */ - ase_awk_nde_t* head, * np; - - if (nde->args->type == ASE_AWK_NDE_GRP) - { - /* parenthesized print */ - ASE_ASSERT (nde->args->next == ASE_NULL); - head = ((ase_awk_nde_grp_t*)nde->args)->body; - } - else head = nde->args; - - for (np = head; np != ASE_NULL; np = np->next) - { - if (np != head) - { - n = ase_awk_writeextio_str ( - run, nde->out_type, dst, - run->global.ofs.ptr, - run->global.ofs.len); - if (n <= -1 /*&& run->errnum != ASE_AWK_EIOIMPL*/) - { - if (out != ASE_NULL) - ASE_AWK_FREE (run->awk, out); - - /* adjust the error line */ - run->errlin = nde->line; - return -1; - } - } - - v = __eval_expression (run, np); - if (v == ASE_NULL) - { - if (out != ASE_NULL) - ASE_AWK_FREE (run->awk, out); - return -1; - } - ase_awk_refupval (run, v); - - n = ase_awk_writeextio_val (run, nde->out_type, dst, v); - if (n <= -1 /*&& run->errnum != ASE_AWK_EIOIMPL*/) - { - if (out != ASE_NULL) - ASE_AWK_FREE (run->awk, out); - - ase_awk_refdownval (run, v); - /* adjust the error line */ - run->errlin = nde->line; - return -1; - } - - ase_awk_refdownval (run, v); - } - } - - /* print the value ORS to terminate the operation */ - n = ase_awk_writeextio_str ( - run, nde->out_type, dst, - run->global.ors.ptr, run->global.ors.len); - if (n <= -1 /*&& run->errnum != ASE_AWK_EIOIMPL*/) - { - if (out != ASE_NULL) ASE_AWK_FREE (run->awk, out); - - /* change the error line */ - run->errlin = nde->line; - return -1; - } - - if (out != ASE_NULL) ASE_AWK_FREE (run->awk, out); - -/*skip_write:*/ - return 0; -} - -static int __run_printf (ase_awk_run_t* run, ase_awk_nde_print_t* nde) -{ - ase_char_t* out = ASE_NULL; - const ase_char_t* dst; - ase_awk_val_t* v; - ase_awk_nde_t* head; - int n; - - ASE_ASSERT ( - (nde->out_type == ASE_AWK_OUT_PIPE && nde->out != ASE_NULL) || - (nde->out_type == ASE_AWK_OUT_COPROC && nde->out != ASE_NULL) || - (nde->out_type == ASE_AWK_OUT_FILE && nde->out != ASE_NULL) || - (nde->out_type == ASE_AWK_OUT_FILE_APPEND && nde->out != ASE_NULL) || - (nde->out_type == ASE_AWK_OUT_CONSOLE && nde->out == ASE_NULL)); - - if (nde->out != ASE_NULL) - { - ase_size_t len; - - v = __eval_expression (run, nde->out); - if (v == ASE_NULL) return -1; - - ase_awk_refupval (run, v); - out = ase_awk_valtostr ( - run, v, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &len); - if (out == ASE_NULL) - { - ase_awk_refdownval (run, v); - - /* change the error line */ - run->errlin = nde->line; - return -1; - } - ase_awk_refdownval (run, v); - - if (len <= 0) - { - /* the output destination name is empty. */ - ASE_AWK_FREE (run->awk, out); - ase_awk_setrunerror ( - run, ASE_AWK_EIONMEM, nde->line, ASE_NULL, 0); - return -1; - } - - while (len > 0) - { - if (out[--len] == ASE_T('\0')) - { - /* the output destination name contains a null - * character. */ - ASE_AWK_FREE (run->awk, out); - ase_awk_setrunerror ( - run, ASE_AWK_EIONMNL, nde->line, - ASE_NULL, 0); - return -1; - } - } - } - - dst = (out == ASE_NULL)? ASE_T(""): out; - - ASE_ASSERTX (nde->args != ASE_NULL, - "a valid printf statement should have at least one argument. the parser must ensure this."); - - if (nde->args->type == ASE_AWK_NDE_GRP) - { - /* parenthesized print */ - ASE_ASSERT (nde->args->next == ASE_NULL); - head = ((ase_awk_nde_grp_t*)nde->args)->body; - } - else head = nde->args; - - ASE_ASSERTX (head != ASE_NULL, - "a valid printf statement should have at least one argument. the parser must ensure this."); - - v = __eval_expression (run, head); - if (v == ASE_NULL) - { - if (out != ASE_NULL) ASE_AWK_FREE (run->awk, out); - return -1; - } - - ase_awk_refupval (run, v); - if (v->type != ASE_AWK_VAL_STR) - { - /* the remaining arguments are ignored as the format cannot - * contain any % characters */ - n = ase_awk_writeextio_val (run, nde->out_type, dst, v); - if (n <= -1 /*&& run->errnum != ASE_AWK_EIOIMPL*/) - { - if (out != ASE_NULL) ASE_AWK_FREE (run->awk, out); - ase_awk_refdownval (run, v); - - /* change the error line */ - run->errlin = nde->line; - return -1; - } - } - else - { - /* perform the formatted output */ - if (__formatted_output ( - run, nde->out_type, dst, - ((ase_awk_val_str_t*)v)->buf, - ((ase_awk_val_str_t*)v)->len, - head->next) == -1) - { - if (out != ASE_NULL) ASE_AWK_FREE (run->awk, out); - ase_awk_refdownval (run, v); - - /* adjust the error line */ - run->errlin = nde->line; - return -1; - } - } - ase_awk_refdownval (run, v); - - if (out != ASE_NULL) ASE_AWK_FREE (run->awk, out); - -/*skip_write:*/ - return 0; -} - -static int __formatted_output ( - ase_awk_run_t* run, int out_type, const ase_char_t* dst, - const ase_char_t* fmt, ase_size_t fmt_len, ase_awk_nde_t* args) -{ - ase_char_t* ptr; - ase_size_t len; - int n; - - ptr = ase_awk_format (run, - ASE_NULL, ASE_NULL, fmt, fmt_len, 0, args, &len); - if (ptr == ASE_NULL) return -1; - - n = ase_awk_writeextio_str (run, out_type, dst, ptr, len); - if (n <= -1 /*&& run->errnum != ASE_AWK_EIOIMPL*/) return -1; - - return 0; -} - -static ase_awk_val_t* __eval_expression (ase_awk_run_t* run, ase_awk_nde_t* nde) -{ - ase_awk_val_t* v; - int n, errnum; - - v = __eval_expression0 (run, nde); - if (v == ASE_NULL) return ASE_NULL; - - if (v->type == ASE_AWK_VAL_REX) - { - ase_awk_refupval (run, v); - - if (run->inrec.d0->type == ASE_AWK_VAL_NIL) - { - /* the record has never been read. - * probably, this functions has been triggered - * by the statements in the BEGIN block */ - n = ase_awk_isemptyrex ( - run->awk, ((ase_awk_val_rex_t*)v)->code)? 1: 0; - } - else - { - ASE_ASSERTX ( - run->inrec.d0->type == ASE_AWK_VAL_STR, - "the internal value representing $0 should always be of the string type once it has been set/updated. it is nil initially."); - - n = ase_awk_matchrex ( - ((ase_awk_run_t*)run)->awk, - ((ase_awk_val_rex_t*)v)->code, - ((((ase_awk_run_t*)run)->global.ignorecase)? ASE_AWK_REX_IGNORECASE: 0), - ((ase_awk_val_str_t*)run->inrec.d0)->buf, - ((ase_awk_val_str_t*)run->inrec.d0)->len, - ASE_NULL, ASE_NULL, &errnum); - - if (n == -1) - { - ase_awk_refdownval (run, v); - - /* matchrex should never set the error number - * whose message contains a formatting - * character. otherwise, the following way of - * setting the error information may not work */ - ase_awk_setrunerror ( - run, errnum, nde->line, ASE_NULL, 0); - return ASE_NULL; - } - } - - ase_awk_refdownval (run, v); - - v = ase_awk_makeintval (run, (n != 0)); - if (v == ASE_NULL) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, ASE_NULL, 0); - return ASE_NULL; - } - } - - return v; -} - -static ase_awk_val_t* __eval_expression0 (ase_awk_run_t* run, ase_awk_nde_t* nde) -{ - static eval_expr_t __eval_func[] = - { - /* the order of functions here should match the order - * of node types declared in tree.h */ - __eval_group, - __eval_assignment, - __eval_binary, - __eval_unary, - __eval_incpre, - __eval_incpst, - __eval_cnd, - __eval_bfn, - __eval_afn, - __eval_int, - __eval_real, - __eval_str, - __eval_rex, - __eval_named, - __eval_global, - __eval_local, - __eval_arg, - __eval_namedidx, - __eval_globalidx, - __eval_localidx, - __eval_argidx, - __eval_pos, - __eval_getline - }; - - ASE_ASSERT (nde->type >= ASE_AWK_NDE_GRP && - (nde->type - ASE_AWK_NDE_GRP) < ASE_COUNTOF(__eval_func)); - - return __eval_func[nde->type-ASE_AWK_NDE_GRP] (run, nde); -} - -static ase_awk_val_t* __eval_group (ase_awk_run_t* run, ase_awk_nde_t* nde) -{ - /* __eval_binop_in evaluates the ASE_AWK_NDE_GRP specially. - * so this function should never be reached. */ - ASE_ASSERT (!"should never happen - NDE_GRP only for in"); - ase_awk_setrunerror (run, ASE_AWK_EINTERN, nde->line, ASE_NULL, 0); - return ASE_NULL; -} - -static ase_awk_val_t* __eval_assignment (ase_awk_run_t* run, ase_awk_nde_t* nde) -{ - ase_awk_val_t* val, * ret; - ase_awk_nde_ass_t* ass = (ase_awk_nde_ass_t*)nde; - - ASE_ASSERT (ass->left != ASE_NULL); - ASE_ASSERT (ass->right != ASE_NULL); - - ASE_ASSERT (ass->right->next == ASE_NULL); - val = __eval_expression (run, ass->right); - if (val == ASE_NULL) return ASE_NULL; - - ase_awk_refupval (run, val); - - if (ass->opcode != ASE_AWK_ASSOP_NONE) - { - ase_awk_val_t* val2, * tmp; - static binop_func_t __binop_func[] = - { - ASE_NULL, /* ASE_AWK_ASSOP_NONE */ - __eval_binop_plus, - __eval_binop_minus, - __eval_binop_mul, - __eval_binop_div, - __eval_binop_idiv, - __eval_binop_mod, - __eval_binop_exp - }; - - ASE_ASSERT (ass->left->next == ASE_NULL); - val2 = __eval_expression (run, ass->left); - if (val2 == ASE_NULL) - { - ase_awk_refdownval (run, val); - return ASE_NULL; - } - - ase_awk_refupval (run, val2); - - ASE_ASSERT (ass->opcode >= 0); - ASE_ASSERT (ass->opcode < ASE_COUNTOF(__binop_func)); - ASE_ASSERT (__binop_func[ass->opcode] != ASE_NULL); - - tmp = __binop_func[ass->opcode] (run, val2, val); - if (tmp == ASE_NULL) - { - ase_awk_refdownval (run, val2); - ase_awk_refdownval (run, val); - return ASE_NULL; - } - - ase_awk_refdownval (run, val2); - ase_awk_refdownval (run, val); - - val = tmp; - ase_awk_refupval (run, val); - } - - ret = __do_assignment (run, ass->left, val); - ase_awk_refdownval (run, val); - - return ret; -} - -static ase_awk_val_t* __do_assignment ( - ase_awk_run_t* run, ase_awk_nde_t* var, ase_awk_val_t* val) -{ - ase_awk_val_t* ret; - - if (val->type == ASE_AWK_VAL_MAP) - { - /* a map cannot be assigned to a variable */ - ase_awk_setrunerror ( - run, ASE_AWK_ENOTASS, var->line, ASE_NULL, 0); - return ASE_NULL; - } - - if (var->type == ASE_AWK_NDE_NAMED || - var->type == ASE_AWK_NDE_GLOBAL || - var->type == ASE_AWK_NDE_LOCAL || - var->type == ASE_AWK_NDE_ARG) - { - ret = __do_assignment_scalar (run, (ase_awk_nde_var_t*)var, val); - } - else if (var->type == ASE_AWK_NDE_NAMEDIDX || - var->type == ASE_AWK_NDE_GLOBALIDX || - var->type == ASE_AWK_NDE_LOCALIDX || - var->type == ASE_AWK_NDE_ARGIDX) - { - ret = __do_assignment_map (run, (ase_awk_nde_var_t*)var, val); - } - else if (var->type == ASE_AWK_NDE_POS) - { - ret = __do_assignment_pos (run, (ase_awk_nde_pos_t*)var, val); - } - else - { - ASE_ASSERT ( - !"should never happen - invalid variable type"); - ase_awk_setrunerror ( - run, ASE_AWK_EINTERN, var->line, ASE_NULL, 0); - return ASE_NULL; - } - - return ret; -} - -static ase_awk_val_t* __do_assignment_scalar ( - ase_awk_run_t* run, ase_awk_nde_var_t* var, ase_awk_val_t* val) -{ - ASE_ASSERT ( - (var->type == ASE_AWK_NDE_NAMED || - var->type == ASE_AWK_NDE_GLOBAL || - var->type == ASE_AWK_NDE_LOCAL || - var->type == ASE_AWK_NDE_ARG) && var->idx == ASE_NULL); - - ASE_ASSERT (val->type != ASE_AWK_VAL_MAP); - - if (var->type == ASE_AWK_NDE_NAMED) - { - ase_awk_pair_t* pair; - int n; - - pair = ase_awk_map_get ( - &run->named, var->id.name, var->id.name_len); - if (pair != ASE_NULL && - ((ase_awk_val_t*)pair->val)->type == ASE_AWK_VAL_MAP) - { - /* once a variable becomes a map, - * it cannot be changed to a scalar variable */ - ase_cstr_t errarg; - - errarg.ptr = var->id.name; - errarg.len = var->id.name_len; - - ase_awk_setrunerror (run, - ASE_AWK_EMAPTOSCALAR, var->line, &errarg, 1); - return ASE_NULL; - } - - n = ase_awk_map_putx (&run->named, - var->id.name, var->id.name_len, val, ASE_NULL); - if (n < 0) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, var->line, ASE_NULL, 0); - return ASE_NULL; - } - - ase_awk_refupval (run, val); - } - else if (var->type == ASE_AWK_NDE_GLOBAL) - { - if (__set_global (run, var->id.idxa, var, val) == -1) - { - return ASE_NULL; - } - } - else if (var->type == ASE_AWK_NDE_LOCAL) - { - ase_awk_val_t* old = STACK_LOCAL(run,var->id.idxa); - if (old->type == ASE_AWK_VAL_MAP) - { - /* once the variable becomes a map, - * it cannot be changed to a scalar variable */ - ase_cstr_t errarg; - - errarg.ptr = var->id.name; - errarg.len = var->id.name_len; - - ase_awk_setrunerror (run, - ASE_AWK_EMAPTOSCALAR, var->line, &errarg, 1); - return ASE_NULL; - } - - ase_awk_refdownval (run, old); - STACK_LOCAL(run,var->id.idxa) = val; - ase_awk_refupval (run, val); - } - else /* if (var->type == ASE_AWK_NDE_ARG) */ - { - ase_awk_val_t* old = STACK_ARG(run,var->id.idxa); - if (old->type == ASE_AWK_VAL_MAP) - { - /* once the variable becomes a map, - * it cannot be changed to a scalar variable */ - ase_cstr_t errarg; - - errarg.ptr = var->id.name; - errarg.len = var->id.name_len; - - ase_awk_setrunerror (run, - ASE_AWK_EMAPTOSCALAR, var->line, &errarg, 1); - return ASE_NULL; - } - - ase_awk_refdownval (run, old); - STACK_ARG(run,var->id.idxa) = val; - ase_awk_refupval (run, val); - } - - return val; -} - -static ase_awk_val_t* __do_assignment_map ( - ase_awk_run_t* run, ase_awk_nde_var_t* var, ase_awk_val_t* val) -{ - ase_awk_val_map_t* map; - ase_char_t* str; - ase_size_t len; - int n; - - ASE_ASSERT ( - (var->type == ASE_AWK_NDE_NAMEDIDX || - var->type == ASE_AWK_NDE_GLOBALIDX || - var->type == ASE_AWK_NDE_LOCALIDX || - var->type == ASE_AWK_NDE_ARGIDX) && var->idx != ASE_NULL); - ASE_ASSERT (val->type != ASE_AWK_VAL_MAP); - - if (var->type == ASE_AWK_NDE_NAMEDIDX) - { - ase_awk_pair_t* pair; - pair = ase_awk_map_get ( - &run->named, var->id.name, var->id.name_len); - map = (pair == ASE_NULL)? - (ase_awk_val_map_t*)ase_awk_val_nil: - (ase_awk_val_map_t*)pair->val; - } - else - { - map = (var->type == ASE_AWK_NDE_GLOBALIDX)? - (ase_awk_val_map_t*)STACK_GLOBAL(run,var->id.idxa): - (var->type == ASE_AWK_NDE_LOCALIDX)? - (ase_awk_val_map_t*)STACK_LOCAL(run,var->id.idxa): - (ase_awk_val_map_t*)STACK_ARG(run,var->id.idxa); - } - - if (map->type == ASE_AWK_VAL_NIL) - { - /* the map is not initialized yet */ - ase_awk_val_t* tmp; - - tmp = ase_awk_makemapval (run); - if (tmp == ASE_NULL) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, var->line, ASE_NULL, 0); - return ASE_NULL; - } - - if (var->type == ASE_AWK_NDE_NAMEDIDX) - { - /* doesn't have to decrease the reference count - * of the previous value here as it is done by - * ase_awk_map_put */ - if (ase_awk_map_put (&run->named, - var->id.name, var->id.name_len, tmp) == ASE_NULL) - { - ase_awk_refupval (run, tmp); - ase_awk_refdownval (run, tmp); - - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, var->line, ASE_NULL, 0); - return ASE_NULL; - } - - ase_awk_refupval (run, tmp); - } - else if (var->type == ASE_AWK_NDE_GLOBALIDX) - { - ase_awk_refupval (run, tmp); - if (ase_awk_setglobal (run, var->id.idxa, tmp) == -1) - { - ase_awk_refdownval (run, tmp); - - /* change error line */ - run->errlin = var->line; - return ASE_NULL; - } - ase_awk_refdownval (run, tmp); - } - else if (var->type == ASE_AWK_NDE_LOCALIDX) - { - ase_awk_refdownval (run, (ase_awk_val_t*)map); - STACK_LOCAL(run,var->id.idxa) = tmp; - ase_awk_refupval (run, tmp); - } - else /* if (var->type == ASE_AWK_NDE_ARGIDX) */ - { - ase_awk_refdownval (run, (ase_awk_val_t*)map); - STACK_ARG(run,var->id.idxa) = tmp; - ase_awk_refupval (run, tmp); - } - - map = (ase_awk_val_map_t*) tmp; - } - else if (map->type != ASE_AWK_VAL_MAP) - { - /* variable assigned is not a map */ - ase_awk_setrunerror ( - run, ASE_AWK_ENOTIDX, var->line, ASE_NULL, 0); - return ASE_NULL; - } - - str = __idxnde_to_str (run, var->idx, &len); - if (str == ASE_NULL) return ASE_NULL; - -#ifdef DEBUG_RUN - ase_dprintf (ASE_T("**** index str=>%s, map->ref=%d, map->type=%d\n"), - str, (int)map->ref, (int)map->type); -#endif - - n = ase_awk_map_putx (map->map, str, len, val, ASE_NULL); - if (n < 0) - { - ASE_AWK_FREE (run->awk, str); - ase_awk_setrunerror (run, ASE_AWK_ENOMEM, var->line, ASE_NULL, 0); - return ASE_NULL; - } - - ASE_AWK_FREE (run->awk, str); - ase_awk_refupval (run, val); - return val; -} - -static ase_awk_val_t* __do_assignment_pos ( - ase_awk_run_t* run, ase_awk_nde_pos_t* pos, ase_awk_val_t* val) -{ - ase_awk_val_t* v; - ase_long_t lv; - ase_real_t rv; - ase_char_t* str; - ase_size_t len; - int n; - - v = __eval_expression (run, pos->val); - if (v == ASE_NULL) return ASE_NULL; - - ase_awk_refupval (run, v); - n = ase_awk_valtonum (run, v, &lv, &rv); - ase_awk_refdownval (run, v); - - if (n == -1) - { - ase_awk_setrunerror ( - run, ASE_AWK_EPOSIDX, pos->line, ASE_NULL, 0); - return ASE_NULL; - } - if (n == 1) lv = (ase_long_t)rv; - if (!IS_VALID_POSIDX(lv)) - { - ase_awk_setrunerror ( - run, ASE_AWK_EPOSIDX, pos->line, ASE_NULL, 0); - return ASE_NULL; - } - - if (val->type == ASE_AWK_VAL_STR) - { - str = ((ase_awk_val_str_t*)val)->buf; - len = ((ase_awk_val_str_t*)val)->len; - } - else - { - str = ase_awk_valtostr ( - run, val, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &len); - if (str == ASE_NULL) - { - /* change error line */ - run->errlin = pos->line; - return ASE_NULL; - } - } - - n = ase_awk_setrec (run, (ase_size_t)lv, str, len); - - if (val->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, str); - - if (n == -1) return ASE_NULL; - return (lv == 0)? run->inrec.d0: run->inrec.flds[lv-1].val; -} - -static ase_awk_val_t* __eval_binary (ase_awk_run_t* run, ase_awk_nde_t* nde) -{ - static binop_func_t __binop_func[] = - { - /* the order of the functions should be inline with - * the operator declaration in run.h */ - - ASE_NULL, /* __eval_binop_lor */ - ASE_NULL, /* __eval_binop_land */ - ASE_NULL, /* __eval_binop_in */ - - __eval_binop_bor, - __eval_binop_bxor, - __eval_binop_band, - - __eval_binop_eq, - __eval_binop_ne, - __eval_binop_gt, - __eval_binop_ge, - __eval_binop_lt, - __eval_binop_le, - - __eval_binop_lshift, - __eval_binop_rshift, - - __eval_binop_plus, - __eval_binop_minus, - __eval_binop_mul, - __eval_binop_div, - __eval_binop_idiv, - __eval_binop_mod, - __eval_binop_exp, - - __eval_binop_concat, - ASE_NULL, /* __eval_binop_ma */ - ASE_NULL /* __eval_binop_nm */ - }; - - ase_awk_nde_exp_t* exp = (ase_awk_nde_exp_t*)nde; - ase_awk_val_t* left, * right, * res; - - ASE_ASSERT (exp->type == ASE_AWK_NDE_EXP_BIN); - - if (exp->opcode == ASE_AWK_BINOP_LAND) - { - res = __eval_binop_land (run, exp->left, exp->right); - } - else if (exp->opcode == ASE_AWK_BINOP_LOR) - { - res = __eval_binop_lor (run, exp->left, exp->right); - } - else if (exp->opcode == ASE_AWK_BINOP_IN) - { - /* treat the in operator specially */ - res = __eval_binop_in (run, exp->left, exp->right); - } - else if (exp->opcode == ASE_AWK_BINOP_NM) - { - res = __eval_binop_nm (run, exp->left, exp->right); - } - else if (exp->opcode == ASE_AWK_BINOP_MA) - { - res = __eval_binop_ma (run, exp->left, exp->right); - } - else - { - ASE_ASSERT (exp->left->next == ASE_NULL); - left = __eval_expression (run, exp->left); - if (left == ASE_NULL) return ASE_NULL; - - ase_awk_refupval (run, left); - - ASE_ASSERT (exp->right->next == ASE_NULL); - right = __eval_expression (run, exp->right); - if (right == ASE_NULL) - { - ase_awk_refdownval (run, left); - return ASE_NULL; - } - - ase_awk_refupval (run, right); - - ASE_ASSERT (exp->opcode >= 0 && - exp->opcode < ASE_COUNTOF(__binop_func)); - ASE_ASSERT (__binop_func[exp->opcode] != ASE_NULL); - - res = __binop_func[exp->opcode] (run, left, right); - if (res == ASE_NULL) - { - /* change the error line */ - run->errlin = nde->line; - } - - ase_awk_refdownval (run, left); - ase_awk_refdownval (run, right); - } - - return res; -} - -static ase_awk_val_t* __eval_binop_lor ( - ase_awk_run_t* run, ase_awk_nde_t* left, ase_awk_nde_t* right) -{ - /* - ase_awk_val_t* res = ASE_NULL; - - res = ase_awk_makeintval (run, - ase_awk_valtobool(run left) || ase_awk_valtobool(run,right)); - if (res == ASE_NULL) - { - ase_awk_setrunerror (run, ASE_AWK_ENOMEM, left->line, ASE_NULL, 0); - return ASE_NULL; - } - - return res; - */ - - /* short-circuit evaluation required special treatment */ - ase_awk_val_t* lv, * rv, * res; - - ASE_ASSERT (left->next == ASE_NULL); - lv = __eval_expression (run, left); - if (lv == ASE_NULL) return ASE_NULL; - - ase_awk_refupval (run, lv); - if (ase_awk_valtobool (run, lv)) - { - res = ase_awk_val_one; - } - else - { - ASE_ASSERT (right->next == ASE_NULL); - rv = __eval_expression (run, right); - if (rv == ASE_NULL) - { - ase_awk_refdownval (run, lv); - return ASE_NULL; - } - ase_awk_refupval (run, rv); - - res = ase_awk_valtobool(run,rv)? ase_awk_val_one: ase_awk_val_zero; - ase_awk_refdownval (run, rv); - } - - ase_awk_refdownval (run, lv); - - return res; -} - -static ase_awk_val_t* __eval_binop_land ( - ase_awk_run_t* run, ase_awk_nde_t* left, ase_awk_nde_t* right) -{ - /* - ase_awk_val_t* res = ASE_NULL; - - res = ase_awk_makeintval (run, - ase_awk_valtobool(run,left) && ase_awk_valtobool(run,right)); - if (res == ASE_NULL) - { - ase_awk_setrunerror (run, ASE_AWK_ENOMEM, left->line, ASE_NULL, 0); - return ASE_NULL; - } - - return res; - */ - - /* short-circuit evaluation required special treatment */ - ase_awk_val_t* lv, * rv, * res; - - ASE_ASSERT (left->next == ASE_NULL); - lv = __eval_expression (run, left); - if (lv == ASE_NULL) return ASE_NULL; - - ase_awk_refupval (run, lv); - if (!ase_awk_valtobool (run, lv)) - { - res = ase_awk_val_zero; - } - else - { - ASE_ASSERT (right->next == ASE_NULL); - rv = __eval_expression (run, right); - if (rv == ASE_NULL) - { - ase_awk_refdownval (run, lv); - return ASE_NULL; - } - ase_awk_refupval (run, rv); - - res = ase_awk_valtobool(run,rv)? ase_awk_val_one: ase_awk_val_zero; - ase_awk_refdownval (run, rv); - } - - ase_awk_refdownval (run, lv); - - return res; -} - -static ase_awk_val_t* __eval_binop_in ( - ase_awk_run_t* run, ase_awk_nde_t* left, ase_awk_nde_t* right) -{ - ase_awk_val_t* rv; - ase_char_t* str; - ase_size_t len; - - if (right->type != ASE_AWK_NDE_GLOBAL && - right->type != ASE_AWK_NDE_LOCAL && - right->type != ASE_AWK_NDE_ARG && - right->type != ASE_AWK_NDE_NAMED) - { - /* the compiler should have handled this case */ - ASE_ASSERT ( - !"should never happen - in needs a plain variable"); - - ase_awk_setrunerror ( - run, ASE_AWK_EINTERN, right->line, ASE_NULL, 0); - return ASE_NULL; - } - - /* evaluate the left-hand side of the operator */ - str = (left->type == ASE_AWK_NDE_GRP)? - __idxnde_to_str (run, ((ase_awk_nde_grp_t*)left)->body, &len): - __idxnde_to_str (run, left, &len); - if (str == ASE_NULL) return ASE_NULL; - - /* evaluate the right-hand side of the operator */ - ASE_ASSERT (right->next == ASE_NULL); - rv = __eval_expression (run, right); - if (rv == ASE_NULL) - { - ASE_AWK_FREE (run->awk, str); - return ASE_NULL; - } - - ase_awk_refupval (run, rv); - - if (rv->type == ASE_AWK_VAL_NIL) - { - ASE_AWK_FREE (run->awk, str); - ase_awk_refdownval (run, rv); - return ase_awk_val_zero; - } - else if (rv->type == ASE_AWK_VAL_MAP) - { - ase_awk_val_t* res; - ase_awk_map_t* map; - - map = ((ase_awk_val_map_t*)rv)->map; - res = (ase_awk_map_get (map, str, len) == ASE_NULL)? - ase_awk_val_zero: ase_awk_val_one; - - ASE_AWK_FREE (run->awk, str); - ase_awk_refdownval (run, rv); - return res; - } - - /* need a map */ - ASE_AWK_FREE (run->awk, str); - ase_awk_refdownval (run, rv); - - ase_awk_setrunerror ( - run, ASE_AWK_ENOTMAPNILIN, right->line, ASE_NULL, 0); - return ASE_NULL; -} - -static ase_awk_val_t* __eval_binop_bor ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right) -{ - int n1, n2, n3; - ase_long_t l1, l2; - ase_real_t r1, r2; - ase_awk_val_t* res; - - n1 = ase_awk_valtonum (run, left, &l1, &r1); - n2 = ase_awk_valtonum (run, right, &l2, &r2); - - if (n1 == -1 || n2 == -1) - { - ase_awk_setrunerror (run, ASE_AWK_EOPERAND, 0, ASE_NULL, 0); - return ASE_NULL; - } - - n3 = n1 + (n2 << 1); - ASE_ASSERT (n3 >= 0 && n3 <= 3); - res = (n3 == 0)? ase_awk_makeintval(run,(ase_long_t)l1|(ase_long_t)l2): - (n3 == 1)? ase_awk_makeintval(run,(ase_long_t)r1|(ase_long_t)l2): - (n3 == 2)? ase_awk_makeintval(run,(ase_long_t)l1|(ase_long_t)r2): - ase_awk_makeintval(run,(ase_long_t)r1|(ase_long_t)r2); - - if (res == ASE_NULL) - { - ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return ASE_NULL; - } - return res; -} - -static ase_awk_val_t* __eval_binop_bxor ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right) -{ - int n1, n2, n3; - ase_long_t l1, l2; - ase_real_t r1, r2; - ase_awk_val_t* res; - - n1 = ase_awk_valtonum (run, left, &l1, &r1); - n2 = ase_awk_valtonum (run, right, &l2, &r2); - - if (n1 == -1 || n2 == -1) - { - ase_awk_setrunerror (run, ASE_AWK_EOPERAND, 0, ASE_NULL, 0); - return ASE_NULL; - } - - n3 = n1 + (n2 << 1); - ASE_ASSERT (n3 >= 0 && n3 <= 3); - res = (n3 == 0)? ase_awk_makeintval(run,(ase_long_t)l1^(ase_long_t)l2): - (n3 == 1)? ase_awk_makeintval(run,(ase_long_t)r1^(ase_long_t)l2): - (n3 == 2)? ase_awk_makeintval(run,(ase_long_t)l1^(ase_long_t)r2): - ase_awk_makeintval(run,(ase_long_t)r1^(ase_long_t)r2); - - if (res == ASE_NULL) - { - ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return ASE_NULL; - } - return res; -} - -static ase_awk_val_t* __eval_binop_band ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right) -{ - int n1, n2, n3; - ase_long_t l1, l2; - ase_real_t r1, r2; - ase_awk_val_t* res; - - n1 = ase_awk_valtonum (run, left, &l1, &r1); - n2 = ase_awk_valtonum (run, right, &l2, &r2); - - if (n1 == -1 || n2 == -1) - { - ase_awk_setrunerror (run, ASE_AWK_EOPERAND, 0, ASE_NULL, 0); - return ASE_NULL; - } - - n3 = n1 + (n2 << 1); - ASE_ASSERT (n3 >= 0 && n3 <= 3); - res = (n3 == 0)? ase_awk_makeintval(run,(ase_long_t)l1&(ase_long_t)l2): - (n3 == 1)? ase_awk_makeintval(run,(ase_long_t)r1&(ase_long_t)l2): - (n3 == 2)? ase_awk_makeintval(run,(ase_long_t)l1&(ase_long_t)r2): - ase_awk_makeintval(run,(ase_long_t)r1&(ase_long_t)r2); - - if (res == ASE_NULL) - { - ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return ASE_NULL; - } - return res; -} - -static int __cmp_nil_nil ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right) -{ - return 0; -} - -static int __cmp_nil_int ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right) -{ - if (((ase_awk_val_int_t*)right)->val < 0) return 1; - if (((ase_awk_val_int_t*)right)->val > 0) return -1; - return 0; -} - -static int __cmp_nil_real ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right) -{ - if (((ase_awk_val_real_t*)right)->val < 0) return 1; - if (((ase_awk_val_real_t*)right)->val > 0) return -1; - return 0; -} - -static int __cmp_nil_str ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right) -{ - return (((ase_awk_val_str_t*)right)->len == 0)? 0: -1; -} - -static int __cmp_int_nil ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right) -{ - if (((ase_awk_val_int_t*)left)->val > 0) return 1; - if (((ase_awk_val_int_t*)left)->val < 0) return -1; - return 0; -} - -static int __cmp_int_int ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right) -{ - if (((ase_awk_val_int_t*)left)->val > - ((ase_awk_val_int_t*)right)->val) return 1; - if (((ase_awk_val_int_t*)left)->val < - ((ase_awk_val_int_t*)right)->val) return -1; - return 0; -} - -static int __cmp_int_real ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right) -{ - if (((ase_awk_val_int_t*)left)->val > - ((ase_awk_val_real_t*)right)->val) return 1; - if (((ase_awk_val_int_t*)left)->val < - ((ase_awk_val_real_t*)right)->val) return -1; - return 0; -} - -static int __cmp_int_str ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right) -{ - ase_char_t* str; - ase_size_t len; - ase_long_t r; - ase_real_t rr; - int n; - - r = ase_awk_strxtolong (run->awk, - ((ase_awk_val_str_t*)right)->buf, - ((ase_awk_val_str_t*)right)->len, 0, (const ase_char_t**)&str); - if (str == ((ase_awk_val_str_t*)right)->buf + - ((ase_awk_val_str_t*)right)->len) - { - if (((ase_awk_val_int_t*)left)->val > r) return 1; - if (((ase_awk_val_int_t*)left)->val < r) return -1; - return 0; - } -/* TODO: should i do this??? conversion to real and comparision... */ - else if (*str == ASE_T('.') || *str == ASE_T('E') || *str == ASE_T('e')) - { - rr = ase_awk_strxtoreal (run->awk, - ((ase_awk_val_str_t*)right)->buf, - ((ase_awk_val_str_t*)right)->len, - (const ase_char_t**)&str); - if (str == ((ase_awk_val_str_t*)right)->buf + - ((ase_awk_val_str_t*)right)->len) - { - if (((ase_awk_val_int_t*)left)->val > rr) return 1; - if (((ase_awk_val_int_t*)left)->val < rr) return -1; - return 0; - } - } - - str = ase_awk_valtostr ( - run, left, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &len); - if (str == ASE_NULL) return CMP_ERROR; - - if (run->global.ignorecase) - { - n = ase_strxncasecmp ( - str, len, - ((ase_awk_val_str_t*)right)->buf, - ((ase_awk_val_str_t*)right)->len, - &run->awk->prmfns.ccls); - } - else - { - n = ase_strxncmp ( - str, len, - ((ase_awk_val_str_t*)right)->buf, - ((ase_awk_val_str_t*)right)->len); - } - - ASE_AWK_FREE (run->awk, str); - return n; -} - -static int __cmp_real_nil ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right) -{ - if (((ase_awk_val_real_t*)left)->val > 0) return 1; - if (((ase_awk_val_real_t*)left)->val < 0) return -1; - return 0; -} - -static int __cmp_real_int ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right) -{ - if (((ase_awk_val_real_t*)left)->val > - ((ase_awk_val_int_t*)right)->val) return 1; - if (((ase_awk_val_real_t*)left)->val < - ((ase_awk_val_int_t*)right)->val) return -1; - return 0; -} - -static int __cmp_real_real ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right) -{ - if (((ase_awk_val_real_t*)left)->val > - ((ase_awk_val_real_t*)right)->val) return 1; - if (((ase_awk_val_real_t*)left)->val < - ((ase_awk_val_real_t*)right)->val) return -1; - return 0; -} - -static int __cmp_real_str ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right) -{ - ase_char_t* str; - ase_size_t len; - ase_real_t rr; - int n; - - rr = ase_awk_strxtoreal (run->awk, - ((ase_awk_val_str_t*)right)->buf, - ((ase_awk_val_str_t*)right)->len, - (const ase_char_t**)&str); - if (str == ((ase_awk_val_str_t*)right)->buf + - ((ase_awk_val_str_t*)right)->len) - { - if (((ase_awk_val_real_t*)left)->val > rr) return 1; - if (((ase_awk_val_real_t*)left)->val < rr) return -1; - return 0; - } - - str = ase_awk_valtostr ( - run, left, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &len); - if (str == ASE_NULL) return CMP_ERROR; - - if (run->global.ignorecase) - { - n = ase_strxncasecmp ( - str, len, - ((ase_awk_val_str_t*)right)->buf, - ((ase_awk_val_str_t*)right)->len, - &run->awk->prmfns.ccls); - } - else - { - n = ase_strxncmp ( - str, len, - ((ase_awk_val_str_t*)right)->buf, - ((ase_awk_val_str_t*)right)->len); - } - - ASE_AWK_FREE (run->awk, str); - return n; -} - -static int __cmp_str_nil ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right) -{ - return (((ase_awk_val_str_t*)left)->len == 0)? 0: 1; -} - -static int __cmp_str_int ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right) -{ - return -__cmp_int_str (run, right, left); -} - -static int __cmp_str_real ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right) -{ - return -__cmp_real_str (run, right, left); -} - -static int __cmp_str_str ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right) -{ - int n; - ase_awk_val_str_t* ls, * rs; - - ls = (ase_awk_val_str_t*)left; - rs = (ase_awk_val_str_t*)right; - - if (run->global.ignorecase) - { - n = ase_strxncasecmp ( - ls->buf, ls->len, rs->buf, rs->len, - &run->awk->prmfns.ccls); - } - else - { - n = ase_strxncmp ( - ls->buf, ls->len, rs->buf, rs->len); - } - - return n; -} - -static int __cmp_val ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right) -{ - typedef int (*cmp_val_t) (ase_awk_run_t*, ase_awk_val_t*, ase_awk_val_t*); - - static cmp_val_t func[] = - { - /* this table must be synchronized with - * the ASE_AWK_VAL_XXX values in val.h */ - __cmp_nil_nil, __cmp_nil_int, __cmp_nil_real, __cmp_nil_str, - __cmp_int_nil, __cmp_int_int, __cmp_int_real, __cmp_int_str, - __cmp_real_nil, __cmp_real_int, __cmp_real_real, __cmp_real_str, - __cmp_str_nil, __cmp_str_int, __cmp_str_real, __cmp_str_str, - }; - - if (left->type == ASE_AWK_VAL_MAP || right->type == ASE_AWK_VAL_MAP) - { - /* a map can't be compared againt other values */ - ase_awk_setrunerror (run, ASE_AWK_EOPERAND, 0, ASE_NULL, 0); - return CMP_ERROR; - } - - ASE_ASSERT ( - left->type >= ASE_AWK_VAL_NIL && - left->type <= ASE_AWK_VAL_STR); - ASE_ASSERT ( - right->type >= ASE_AWK_VAL_NIL && - right->type <= ASE_AWK_VAL_STR); - - return func[left->type*4+right->type] (run, left, right); -} - -static ase_awk_val_t* __eval_binop_eq ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right) -{ - int n = __cmp_val (run, left, right); - if (n == CMP_ERROR) return ASE_NULL; - return (n == 0)? ase_awk_val_one: ase_awk_val_zero; -} - -static ase_awk_val_t* __eval_binop_ne ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right) -{ - int n = __cmp_val (run, left, right); - if (n == CMP_ERROR) return ASE_NULL; - return (n != 0)? ase_awk_val_one: ase_awk_val_zero; -} - -static ase_awk_val_t* __eval_binop_gt ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right) -{ - int n = __cmp_val (run, left, right); - if (n == CMP_ERROR) return ASE_NULL; - return (n > 0)? ase_awk_val_one: ase_awk_val_zero; -} - -static ase_awk_val_t* __eval_binop_ge ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right) -{ - int n = __cmp_val (run, left, right); - if (n == CMP_ERROR) return ASE_NULL; - return (n >= 0)? ase_awk_val_one: ase_awk_val_zero; -} - -static ase_awk_val_t* __eval_binop_lt ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right) -{ - int n = __cmp_val (run, left, right); - if (n == CMP_ERROR) return ASE_NULL; - return (n < 0)? ase_awk_val_one: ase_awk_val_zero; -} - -static ase_awk_val_t* __eval_binop_le ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right) -{ - int n = __cmp_val (run, left, right); - if (n == CMP_ERROR) return ASE_NULL; - return (n <= 0)? ase_awk_val_one: ase_awk_val_zero; -} - -static ase_awk_val_t* __eval_binop_lshift ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right) -{ - int n1, n2, n3; - ase_long_t l1, l2; - ase_real_t r1, r2; - ase_awk_val_t* res; - - n1 = ase_awk_valtonum (run, left, &l1, &r1); - n2 = ase_awk_valtonum (run, right, &l2, &r2); - - if (n1 == -1 || n2 == -1) - { - ase_awk_setrunerror (run, ASE_AWK_EOPERAND, 0, ASE_NULL, 0); - return ASE_NULL; - } - - n3 = n1 + (n2 << 1); - if (n3 == 0) - { - res = ase_awk_makeintval ( - run, (ase_long_t)l1<<(ase_long_t)l2); - } - else - { - ase_awk_setrunerror (run, ASE_AWK_EOPERAND, 0, ASE_NULL, 0); - return ASE_NULL; - } - - if (res == ASE_NULL) - { - ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return ASE_NULL; - } - return res; -} - -static ase_awk_val_t* __eval_binop_rshift ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right) -{ - int n1, n2, n3; - ase_long_t l1, l2; - ase_real_t r1, r2; - ase_awk_val_t* res; - - n1 = ase_awk_valtonum (run, left, &l1, &r1); - n2 = ase_awk_valtonum (run, right, &l2, &r2); - - if (n1 == -1 || n2 == -1) - { - ase_awk_setrunerror (run, ASE_AWK_EOPERAND, 0, ASE_NULL, 0); - return ASE_NULL; - } - - n3 = n1 + (n2 << 1); - if (n3 == 0) - { - res = ase_awk_makeintval ( - run, (ase_long_t)l1>>(ase_long_t)l2); - } - else - { - ase_awk_setrunerror (run, ASE_AWK_EOPERAND, 0, ASE_NULL, 0); - return ASE_NULL; - } - - if (res == ASE_NULL) - { - ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return ASE_NULL; - } - return res; -} - -static ase_awk_val_t* __eval_binop_plus ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right) -{ - int n1, n2, n3; - ase_long_t l1, l2; - ase_real_t r1, r2; - ase_awk_val_t* res; - - n1 = ase_awk_valtonum (run, left, &l1, &r1); - n2 = ase_awk_valtonum (run, right, &l2, &r2); - - if (n1 == -1 || n2 == -1) - { - ase_awk_setrunerror (run, ASE_AWK_EOPERAND, 0, ASE_NULL, 0); - return ASE_NULL; - } - /* - n1 n2 n3 - 0 0 = 0 - 1 0 = 1 - 0 1 = 2 - 1 1 = 3 - */ - n3 = n1 + (n2 << 1); - ASE_ASSERT (n3 >= 0 && n3 <= 3); - res = (n3 == 0)? ase_awk_makeintval(run,(ase_long_t)l1+(ase_long_t)l2): - (n3 == 1)? ase_awk_makerealval(run,(ase_real_t)r1+(ase_real_t)l2): - (n3 == 2)? ase_awk_makerealval(run,(ase_real_t)l1+(ase_real_t)r2): - ase_awk_makerealval(run,(ase_real_t)r1+(ase_real_t)r2); - - if (res == ASE_NULL) - { - ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return ASE_NULL; - } - return res; -} - -static ase_awk_val_t* __eval_binop_minus ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right) -{ - int n1, n2, n3; - ase_long_t l1, l2; - ase_real_t r1, r2; - ase_awk_val_t* res; - - n1 = ase_awk_valtonum (run, left, &l1, &r1); - n2 = ase_awk_valtonum (run, right, &l2, &r2); - - if (n1 == -1 || n2 == -1) - { - ase_awk_setrunerror (run, ASE_AWK_EOPERAND, 0, ASE_NULL, 0); - return ASE_NULL; - } - - n3 = n1 + (n2 << 1); - ASE_ASSERT (n3 >= 0 && n3 <= 3); - res = (n3 == 0)? ase_awk_makeintval(run,(ase_long_t)l1-(ase_long_t)l2): - (n3 == 1)? ase_awk_makerealval(run,(ase_real_t)r1-(ase_real_t)l2): - (n3 == 2)? ase_awk_makerealval(run,(ase_real_t)l1-(ase_real_t)r2): - ase_awk_makerealval(run,(ase_real_t)r1-(ase_real_t)r2); - - if (res == ASE_NULL) - { - ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return ASE_NULL; - } - return res; -} - -static ase_awk_val_t* __eval_binop_mul ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right) -{ - int n1, n2, n3; - ase_long_t l1, l2; - ase_real_t r1, r2; - ase_awk_val_t* res; - - n1 = ase_awk_valtonum (run, left, &l1, &r1); - n2 = ase_awk_valtonum (run, right, &l2, &r2); - - if (n1 == -1 || n2 == -1) - { - ase_awk_setrunerror (run, ASE_AWK_EOPERAND, 0, ASE_NULL, 0); - return ASE_NULL; - } - - n3 = n1 + (n2 << 1); - ASE_ASSERT (n3 >= 0 && n3 <= 3); - res = (n3 == 0)? ase_awk_makeintval(run,(ase_long_t)l1*(ase_long_t)l2): - (n3 == 1)? ase_awk_makerealval(run,(ase_real_t)r1*(ase_real_t)l2): - (n3 == 2)? ase_awk_makerealval(run,(ase_real_t)l1*(ase_real_t)r2): - ase_awk_makerealval(run,(ase_real_t)r1*(ase_real_t)r2); - - if (res == ASE_NULL) - { - ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return ASE_NULL; - } - return res; -} - -static ase_awk_val_t* __eval_binop_div ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right) -{ - int n1, n2, n3; - ase_long_t l1, l2; - ase_real_t r1, r2; - ase_awk_val_t* res; - - n1 = ase_awk_valtonum (run, left, &l1, &r1); - n2 = ase_awk_valtonum (run, right, &l2, &r2); - - if (n1 == -1 || n2 == -1) - { - ase_awk_setrunerror (run, ASE_AWK_EOPERAND, 0, ASE_NULL, 0); - return ASE_NULL; - } - - n3 = n1 + (n2 << 1); - if (n3 == 0) - { - if (l2 == 0) - { - ase_awk_setrunerror ( - run, ASE_AWK_EDIVBY0, 0, ASE_NULL, 0); - return ASE_NULL; - } - - if (((ase_long_t)l1 % (ase_long_t)l2) == 0) - { - res = ase_awk_makeintval ( - run, (ase_long_t)l1 / (ase_long_t)l2); - } - else - { - res = ase_awk_makerealval ( - run, (ase_real_t)l1 / (ase_real_t)l2); - } - } - else if (n3 == 1) - { - res = ase_awk_makerealval ( - run, (ase_real_t)r1 / (ase_real_t)l2); - } - else if (n3 == 2) - { - res = ase_awk_makerealval ( - run, (ase_real_t)l1 / (ase_real_t)r2); - } - else - { - ASE_ASSERT (n3 == 3); - res = ase_awk_makerealval ( - run, (ase_real_t)r1 / (ase_real_t)r2); - } - - if (res == ASE_NULL) - { - ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return ASE_NULL; - } - return res; -} - -static ase_awk_val_t* __eval_binop_idiv ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right) -{ - int n1, n2, n3; - ase_long_t l1, l2; - ase_real_t r1, r2, quo; - ase_awk_val_t* res; - - n1 = ase_awk_valtonum (run, left, &l1, &r1); - n2 = ase_awk_valtonum (run, right, &l2, &r2); - - if (n1 == -1 || n2 == -1) - { - ase_awk_setrunerror (run, ASE_AWK_EOPERAND, 0, ASE_NULL, 0); - return ASE_NULL; - } - - n3 = n1 + (n2 << 1); - if (n3 == 0) - { - if (l2 == 0) - { - ase_awk_setrunerror ( - run, ASE_AWK_EDIVBY0, 0, ASE_NULL, 0); - return ASE_NULL; - } - res = ase_awk_makeintval ( - run, (ase_long_t)l1 / (ase_long_t)l2); - } - else if (n3 == 1) - { - quo = (ase_real_t)r1 / (ase_real_t)l2; - res = ase_awk_makeintval (run, (ase_long_t)quo); - } - else if (n3 == 2) - { - quo = (ase_real_t)l1 / (ase_real_t)r2; - res = ase_awk_makeintval (run, (ase_long_t)quo); - } - else - { - ASE_ASSERT (n3 == 3); - - quo = (ase_real_t)r1 / (ase_real_t)r2; - res = ase_awk_makeintval (run, (ase_long_t)quo); - } - - if (res == ASE_NULL) - { - ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return ASE_NULL; - } - return res; -} - -static ase_awk_val_t* __eval_binop_mod ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right) -{ - int n1, n2, n3; - ase_long_t l1, l2; - ase_real_t r1, r2; - ase_awk_val_t* res; - - n1 = ase_awk_valtonum (run, left, &l1, &r1); - n2 = ase_awk_valtonum (run, right, &l2, &r2); - - if (n1 == -1 || n2 == -1) - { - ase_awk_setrunerror (run, ASE_AWK_EOPERAND, 0, ASE_NULL, 0); - return ASE_NULL; - } - - n3 = n1 + (n2 << 1); - if (n3 == 0) - { - if (l2 == 0) - { - ase_awk_setrunerror (run, ASE_AWK_EDIVBY0, 0, ASE_NULL, 0); - return ASE_NULL; - } - res = ase_awk_makeintval ( - run, (ase_long_t)l1 % (ase_long_t)l2); - } - else - { - ase_awk_setrunerror (run, ASE_AWK_EOPERAND, 0, ASE_NULL, 0); - return ASE_NULL; - } - - if (res == ASE_NULL) - { - ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return ASE_NULL; - } - return res; -} - -static ase_awk_val_t* __eval_binop_exp ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right) -{ - int n1, n2, n3; - ase_long_t l1, l2; - ase_real_t r1, r2; - ase_awk_val_t* res; - - ASE_ASSERTX (run->awk->prmfns.misc.pow != ASE_NULL, - "the pow function should be provided when the awk object is created to make the exponentiation work properly."); - - n1 = ase_awk_valtonum (run, left, &l1, &r1); - n2 = ase_awk_valtonum (run, right, &l2, &r2); - - if (n1 == -1 || n2 == -1) - { - ase_awk_setrunerror (run, ASE_AWK_EOPERAND, 0, ASE_NULL, 0); - return ASE_NULL; - } - - n3 = n1 + (n2 << 1); - if (n3 == 0) - { - /* left - int, right - int */ - if (l2 >= 0) - { - ase_long_t v = 1; - while (l2-- > 0) v *= l1; - res = ase_awk_makeintval (run, v); - } - else if (l1 == 0) - { - ase_awk_setrunerror ( - run, ASE_AWK_EDIVBY0, 0, ASE_NULL, 0); - return ASE_NULL; - } - else - { - ase_real_t v = 1.0; - l2 *= -1; - while (l2-- > 0) v /= l1; - res = ase_awk_makerealval (run, v); - } - } - else if (n3 == 1) - { - /* left - real, right - int */ - if (l2 >= 0) - { - ase_real_t v = 1.0; - while (l2-- > 0) v *= r1; - res = ase_awk_makerealval (run, v); - } - else if (r1 == 0.0) - { - ase_awk_setrunerror ( - run, ASE_AWK_EDIVBY0, 0, ASE_NULL, 0); - return ASE_NULL; - } - else - { - ase_real_t v = 1.0; - l2 *= -1; - while (l2-- > 0) v /= r1; - res = ase_awk_makerealval (run, v); - } - } - else if (n3 == 2) - { - /* left - int, right - real */ - res = ase_awk_makerealval (run, - run->awk->prmfns.misc.pow ( - run->awk->prmfns.misc.custom_data, - (ase_real_t)l1,(ase_real_t)r2)); - } - else - { - /* left - real, right - real */ - ASE_ASSERT (n3 == 3); - res = ase_awk_makerealval (run, - run->awk->prmfns.misc.pow( - run->awk->prmfns.misc.custom_data, - (ase_real_t)r1,(ase_real_t)r2)); - } - - if (res == ASE_NULL) - { - ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return ASE_NULL; - } - - return res; -} - -static ase_awk_val_t* __eval_binop_concat ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right) -{ - ase_char_t* strl, * strr; - ase_size_t strl_len, strr_len; - ase_awk_val_t* res; - - strl = ase_awk_valtostr ( - run, left, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &strl_len); - if (strl == ASE_NULL) return ASE_NULL; - - strr = ase_awk_valtostr ( - run, right, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &strr_len); - if (strr == ASE_NULL) - { - ASE_AWK_FREE (run->awk, strl); - return ASE_NULL; - } - - res = ase_awk_makestrval2 (run, strl, strl_len, strr, strr_len); - if (res == ASE_NULL) - { - ASE_AWK_FREE (run->awk, strl); - ASE_AWK_FREE (run->awk, strr); - - ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return ASE_NULL; - } - - ASE_AWK_FREE (run->awk, strl); - ASE_AWK_FREE (run->awk, strr); - - return res; -} - -static ase_awk_val_t* __eval_binop_ma ( - ase_awk_run_t* run, ase_awk_nde_t* left, ase_awk_nde_t* right) -{ - ase_awk_val_t* lv, * rv, * res; - - ASE_ASSERT (left->next == ASE_NULL); - ASE_ASSERT (right->next == ASE_NULL); - - lv = __eval_expression (run, left); - if (lv == ASE_NULL) - { - return ASE_NULL; - } - - ase_awk_refupval (run, lv); - - rv = __eval_expression0 (run, right); - if (rv == ASE_NULL) - { - ase_awk_refdownval (run, lv); - return ASE_NULL; - } - - ase_awk_refupval (run, rv); - - res = __eval_binop_match0 ( - run, lv, rv, left->line, right->line, 1); - - ase_awk_refdownval (run, lv); - ase_awk_refdownval (run, rv); - - return res; -} - -static ase_awk_val_t* __eval_binop_nm ( - ase_awk_run_t* run, ase_awk_nde_t* left, ase_awk_nde_t* right) -{ - ase_awk_val_t* lv, * rv, * res; - - ASE_ASSERT (left->next == ASE_NULL); - ASE_ASSERT (right->next == ASE_NULL); - - lv = __eval_expression (run, left); - if (lv == ASE_NULL) return ASE_NULL; - - ase_awk_refupval (run, lv); - - rv = __eval_expression0 (run, right); - if (rv == ASE_NULL) - { - ase_awk_refdownval (run, lv); - return ASE_NULL; - } - - ase_awk_refupval (run, rv); - - res = __eval_binop_match0 ( - run, lv, rv, left->line, right->line, 0); - - ase_awk_refdownval (run, lv); - ase_awk_refdownval (run, rv); - - return res; -} - -static ase_awk_val_t* __eval_binop_match0 ( - ase_awk_run_t* run, ase_awk_val_t* left, ase_awk_val_t* right, - ase_size_t lline, ase_size_t rline, int ret) -{ - ase_awk_val_t* res; - int n, errnum; - ase_char_t* str; - ase_size_t len; - void* rex_code; - - if (right->type == ASE_AWK_VAL_REX) - { - rex_code = ((ase_awk_val_rex_t*)right)->code; - } - else if (right->type == ASE_AWK_VAL_STR) - { - rex_code = ase_awk_buildrex ( - run->awk, - ((ase_awk_val_str_t*)right)->buf, - ((ase_awk_val_str_t*)right)->len, &errnum); - if (rex_code == ASE_NULL) - { - ase_awk_setrunerror (run, errnum, rline, ASE_NULL, 0); - return ASE_NULL; - } - } - else - { - str = ase_awk_valtostr ( - run, right, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &len); - if (str == ASE_NULL) return ASE_NULL; - - rex_code = ase_awk_buildrex (run->awk, str, len, &errnum); - if (rex_code == ASE_NULL) - { - ASE_AWK_FREE (run->awk, str); - - ase_awk_setrunerror (run, errnum, rline, ASE_NULL, 0); - return ASE_NULL; - } - - ASE_AWK_FREE (run->awk, str); - } - - if (left->type == ASE_AWK_VAL_STR) - { - n = ase_awk_matchrex ( - run->awk, rex_code, - ((run->global.ignorecase)? ASE_AWK_REX_IGNORECASE: 0), - ((ase_awk_val_str_t*)left)->buf, - ((ase_awk_val_str_t*)left)->len, - ASE_NULL, ASE_NULL, &errnum); - if (n == -1) - { - if (right->type != ASE_AWK_VAL_REX) - ASE_AWK_FREE (run->awk, rex_code); - - ase_awk_setrunerror (run, errnum, lline, ASE_NULL, 0); - return ASE_NULL; - } - - res = ase_awk_makeintval (run, (n == ret)); - if (res == ASE_NULL) - { - if (right->type != ASE_AWK_VAL_REX) - ASE_AWK_FREE (run->awk, rex_code); - - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, lline, ASE_NULL, 0); - return ASE_NULL; - } - } - else - { - str = ase_awk_valtostr ( - run, left, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &len); - if (str == ASE_NULL) - { - if (right->type != ASE_AWK_VAL_REX) - ASE_AWK_FREE (run->awk, rex_code); - return ASE_NULL; - } - - n = ase_awk_matchrex ( - run->awk, rex_code, - ((run->global.ignorecase)? ASE_AWK_REX_IGNORECASE: 0), - str, len, ASE_NULL, ASE_NULL, &errnum); - if (n == -1) - { - ASE_AWK_FREE (run->awk, str); - if (right->type != ASE_AWK_VAL_REX) - ASE_AWK_FREE (run->awk, rex_code); - - ase_awk_setrunerror (run, errnum, lline, ASE_NULL, 0); - return ASE_NULL; - } - - res = ase_awk_makeintval (run, (n == ret)); - if (res == ASE_NULL) - { - ASE_AWK_FREE (run->awk, str); - if (right->type != ASE_AWK_VAL_REX) - ASE_AWK_FREE (run->awk, rex_code); - - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, lline, ASE_NULL, 0); - return ASE_NULL; - } - - ASE_AWK_FREE (run->awk, str); - } - - if (right->type != ASE_AWK_VAL_REX) ASE_AWK_FREE (run->awk, rex_code); - return res; -} - -static ase_awk_val_t* __eval_unary (ase_awk_run_t* run, ase_awk_nde_t* nde) -{ - ase_awk_val_t* left, * res = ASE_NULL; - ase_awk_nde_exp_t* exp = (ase_awk_nde_exp_t*)nde; - int n; - ase_long_t l; - ase_real_t r; - - ASE_ASSERT ( - exp->type == ASE_AWK_NDE_EXP_UNR); - ASE_ASSERT ( - exp->left != ASE_NULL && exp->right == ASE_NULL); - ASE_ASSERT ( - exp->opcode == ASE_AWK_UNROP_PLUS || - exp->opcode == ASE_AWK_UNROP_MINUS || - exp->opcode == ASE_AWK_UNROP_NOT || - exp->opcode == ASE_AWK_UNROP_BNOT); - - ASE_ASSERT (exp->left->next == ASE_NULL); - left = __eval_expression (run, exp->left); - if (left == ASE_NULL) return ASE_NULL; - - ase_awk_refupval (run, left); - - if (exp->opcode == ASE_AWK_UNROP_MINUS) - { - n = ase_awk_valtonum (run, left, &l, &r); - if (n == -1) - { - ase_awk_refdownval (run, left); - return ASE_NULL; - } - - res = (n == 0)? ase_awk_makeintval (run, -l): - ase_awk_makerealval (run, -r); - } - else if (exp->opcode == ASE_AWK_UNROP_NOT) - { - if (left->type == ASE_AWK_VAL_STR) - { - res = ase_awk_makeintval ( - run, !(((ase_awk_val_str_t*)left)->len > 0)); - } - else - { - n = ase_awk_valtonum (run, left, &l, &r); - if (n == -1) - { - ase_awk_refdownval (run, left); - return ASE_NULL; - } - - res = (n == 0)? ase_awk_makeintval (run, !l): - ase_awk_makerealval (run, !r); - } - } - else if (exp->opcode == ASE_AWK_UNROP_BNOT) - { - n = ase_awk_valtonum (run, left, &l, &r); - if (n == -1) - { - ase_awk_refdownval (run, left); - return ASE_NULL; - } - - if (n == 1) l = (ase_long_t)r; - res = ase_awk_makeintval (run, ~l); - } - else if (exp->opcode == ASE_AWK_UNROP_PLUS) - { - n = ase_awk_valtonum (run, left, &l, &r); - if (n == -1) - { - ase_awk_refdownval (run, left); - return ASE_NULL; - } - - res = (n == 0)? ase_awk_makeintval (run, l): - ase_awk_makerealval (run, r); - } - - if (res == ASE_NULL) - { - ase_awk_refdownval (run, left); - - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, ASE_NULL, 0); - return ASE_NULL; - } - - ase_awk_refdownval (run, left); - return res; -} - -static ase_awk_val_t* __eval_incpre (ase_awk_run_t* run, ase_awk_nde_t* nde) -{ - ase_awk_val_t* left, * res; - ase_awk_nde_exp_t* exp = (ase_awk_nde_exp_t*)nde; - - ASE_ASSERT ( - exp->type == ASE_AWK_NDE_EXP_INCPRE); - ASE_ASSERT ( - exp->left != ASE_NULL && exp->right == ASE_NULL); - - /* this way of checking if the l-value is assignable is - * ugly as it is dependent of the values defined in tree.h. - * but let's keep going this way for the time being. */ - if (exp->left->type < ASE_AWK_NDE_NAMED || - exp->left->type > ASE_AWK_NDE_ARGIDX) - { - ase_awk_setrunerror ( - run, ASE_AWK_EOPERAND, nde->line, ASE_NULL, 0); - return ASE_NULL; - } - - ASE_ASSERT (exp->left->next == ASE_NULL); - left = __eval_expression (run, exp->left); - if (left == ASE_NULL) return ASE_NULL; - - ase_awk_refupval (run, left); - - if (exp->opcode == ASE_AWK_INCOP_PLUS) - { - if (left->type == ASE_AWK_VAL_INT) - { - ase_long_t r = ((ase_awk_val_int_t*)left)->val; - res = ase_awk_makeintval (run, r + 1); - if (res == ASE_NULL) - { - ase_awk_refdownval (run, left); - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, - ASE_NULL, 0); - return ASE_NULL; - } - } - else if (left->type == ASE_AWK_VAL_REAL) - { - ase_real_t r = ((ase_awk_val_real_t*)left)->val; - res = ase_awk_makerealval (run, r + 1.0); - if (res == ASE_NULL) - { - ase_awk_refdownval (run, left); - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, - ASE_NULL, 0); - return ASE_NULL; - } - } - else - { - ase_long_t v1; - ase_real_t v2; - int n; - - n = ase_awk_valtonum (run, left, &v1, &v2); - if (n == -1) - { - ase_awk_refdownval (run, left); - ase_awk_setrunerror ( - run, ASE_AWK_EOPERAND, nde->line, ASE_NULL, 0); - return ASE_NULL; - } - - if (n == 0) - { - res = ase_awk_makeintval (run, v1 + 1); - } - else /* if (n == 1) */ - { - ASE_ASSERT (n == 1); - res = ase_awk_makerealval (run, v2 + 1.0); - } - - if (res == ASE_NULL) - { - ase_awk_refdownval (run, left); - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, - ASE_NULL, 0); - return ASE_NULL; - } - } - } - else if (exp->opcode == ASE_AWK_INCOP_MINUS) - { - if (left->type == ASE_AWK_VAL_INT) - { - ase_long_t r = ((ase_awk_val_int_t*)left)->val; - res = ase_awk_makeintval (run, r - 1); - if (res == ASE_NULL) - { - ase_awk_refdownval (run, left); - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, - ASE_NULL, 0); - return ASE_NULL; - } - } - else if (left->type == ASE_AWK_VAL_REAL) - { - ase_real_t r = ((ase_awk_val_real_t*)left)->val; - res = ase_awk_makerealval (run, r - 1.0); - if (res == ASE_NULL) - { - ase_awk_refdownval (run, left); - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, - ASE_NULL, 0); - return ASE_NULL; - } - } - else - { - ase_long_t v1; - ase_real_t v2; - int n; - - n = ase_awk_valtonum (run, left, &v1, &v2); - if (n == -1) - { - ase_awk_refdownval (run, left); - ase_awk_setrunerror ( - run, ASE_AWK_EOPERAND, nde->line, - ASE_NULL, 0); - return ASE_NULL; - } - - if (n == 0) - { - res = ase_awk_makeintval (run, v1 - 1); - } - else /* if (n == 1) */ - { - ASE_ASSERT (n == 1); - res = ase_awk_makerealval (run, v2 - 1.0); - } - - if (res == ASE_NULL) - { - ase_awk_refdownval (run, left); - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, - ASE_NULL, 0); - return ASE_NULL; - } - } - } - else - { - ASE_ASSERT ( - !"should never happen - invalid opcode"); - ase_awk_refdownval (run, left); - - ase_awk_setrunerror ( - run, ASE_AWK_EINTERN, nde->line, ASE_NULL, 0); - return ASE_NULL; - } - - if (__do_assignment (run, exp->left, res) == ASE_NULL) - { - ase_awk_refdownval (run, left); - return ASE_NULL; - } - - ase_awk_refdownval (run, left); - return res; -} - -static ase_awk_val_t* __eval_incpst (ase_awk_run_t* run, ase_awk_nde_t* nde) -{ - ase_awk_val_t* left, * res, * res2; - ase_awk_nde_exp_t* exp = (ase_awk_nde_exp_t*)nde; - - ASE_ASSERT ( - exp->type == ASE_AWK_NDE_EXP_INCPST); - ASE_ASSERT ( - exp->left != ASE_NULL && exp->right == ASE_NULL); - - /* this way of checking if the l-value is assignable is - * ugly as it is dependent of the values defined in tree.h. - * but let's keep going this way for the time being. */ - if (exp->left->type < ASE_AWK_NDE_NAMED || - exp->left->type > ASE_AWK_NDE_ARGIDX) - { - ase_awk_setrunerror ( - run, ASE_AWK_EOPERAND, nde->line, ASE_NULL, 0); - return ASE_NULL; - } - - ASE_ASSERT (exp->left->next == ASE_NULL); - left = __eval_expression (run, exp->left); - if (left == ASE_NULL) return ASE_NULL; - - ase_awk_refupval (run, left); - - if (exp->opcode == ASE_AWK_INCOP_PLUS) - { - if (left->type == ASE_AWK_VAL_INT) - { - ase_long_t r = ((ase_awk_val_int_t*)left)->val; - res = ase_awk_makeintval (run, r); - if (res == ASE_NULL) - { - ase_awk_refdownval (run, left); - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, - ASE_NULL, 0); - return ASE_NULL; - } - - res2 = ase_awk_makeintval (run, r + 1); - if (res2 == ASE_NULL) - { - ase_awk_refdownval (run, left); - ase_awk_freeval (run, res, ase_true); - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, - ASE_NULL, 0); - return ASE_NULL; - } - } - else if (left->type == ASE_AWK_VAL_REAL) - { - ase_real_t r = ((ase_awk_val_real_t*)left)->val; - res = ase_awk_makerealval (run, r); - if (res == ASE_NULL) - { - ase_awk_refdownval (run, left); - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, - ASE_NULL, 0); - return ASE_NULL; - } - - res2 = ase_awk_makerealval (run, r + 1.0); - if (res2 == ASE_NULL) - { - ase_awk_refdownval (run, left); - ase_awk_freeval (run, res, ase_true); - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, - ASE_NULL, 0); - return ASE_NULL; - } - } - else - { - ase_long_t v1; - ase_real_t v2; - int n; - - n = ase_awk_valtonum (run, left, &v1, &v2); - if (n == -1) - { - ase_awk_refdownval (run, left); - ase_awk_setrunerror ( - run, ASE_AWK_EOPERAND, nde->line, - ASE_NULL, 0); - return ASE_NULL; - } - - if (n == 0) - { - res = ase_awk_makeintval (run, v1); - if (res == ASE_NULL) - { - ase_awk_refdownval (run, left); - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, - ASE_NULL, 0); - return ASE_NULL; - } - - res2 = ase_awk_makeintval (run, v1 + 1); - if (res2 == ASE_NULL) - { - ase_awk_refdownval (run, left); - ase_awk_freeval (run, res, ase_true); - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, - ASE_NULL, 0); - return ASE_NULL; - } - } - else /* if (n == 1) */ - { - ASE_ASSERT (n == 1); - res = ase_awk_makerealval (run, v2); - if (res == ASE_NULL) - { - ase_awk_refdownval (run, left); - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, - ASE_NULL, 0); - return ASE_NULL; - } - - res2 = ase_awk_makerealval (run, v2 + 1.0); - if (res2 == ASE_NULL) - { - ase_awk_refdownval (run, left); - ase_awk_freeval (run, res, ase_true); - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, - ASE_NULL, 0); - return ASE_NULL; - } - } - } - } - else if (exp->opcode == ASE_AWK_INCOP_MINUS) - { - if (left->type == ASE_AWK_VAL_INT) - { - ase_long_t r = ((ase_awk_val_int_t*)left)->val; - res = ase_awk_makeintval (run, r); - if (res == ASE_NULL) - { - ase_awk_refdownval (run, left); - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, - ASE_NULL, 0); - return ASE_NULL; - } - - res2 = ase_awk_makeintval (run, r - 1); - if (res2 == ASE_NULL) - { - ase_awk_refdownval (run, left); - ase_awk_freeval (run, res, ase_true); - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, - ASE_NULL, 0); - return ASE_NULL; - } - } - else if (left->type == ASE_AWK_VAL_REAL) - { - ase_real_t r = ((ase_awk_val_real_t*)left)->val; - res = ase_awk_makerealval (run, r); - if (res == ASE_NULL) - { - ase_awk_refdownval (run, left); - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, - ASE_NULL, 0); - return ASE_NULL; - } - - res2 = ase_awk_makerealval (run, r - 1.0); - if (res2 == ASE_NULL) - { - ase_awk_refdownval (run, left); - ase_awk_freeval (run, res, ase_true); - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, - ASE_NULL, 0); - return ASE_NULL; - } - } - else - { - ase_long_t v1; - ase_real_t v2; - int n; - - n = ase_awk_valtonum (run, left, &v1, &v2); - if (n == -1) - { - ase_awk_refdownval (run, left); - ase_awk_setrunerror ( - run, ASE_AWK_EOPERAND, nde->line, - ASE_NULL, 0); - return ASE_NULL; - } - - if (n == 0) - { - res = ase_awk_makeintval (run, v1); - if (res == ASE_NULL) - { - ase_awk_refdownval (run, left); - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, - ASE_NULL, 0); - return ASE_NULL; - } - - res2 = ase_awk_makeintval (run, v1 - 1); - if (res2 == ASE_NULL) - { - ase_awk_refdownval (run, left); - ase_awk_freeval (run, res, ase_true); - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, - ASE_NULL, 0); - return ASE_NULL; - } - } - else /* if (n == 1) */ - { - ASE_ASSERT (n == 1); - res = ase_awk_makerealval (run, v2); - if (res == ASE_NULL) - { - ase_awk_refdownval (run, left); - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, - ASE_NULL, 0); - return ASE_NULL; - } - - res2 = ase_awk_makerealval (run, v2 - 1.0); - if (res2 == ASE_NULL) - { - ase_awk_refdownval (run, left); - ase_awk_freeval (run, res, ase_true); - - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, - ASE_NULL, 0); - return ASE_NULL; - } - } - } - } - else - { - ASE_ASSERT ( - !"should never happen - invalid opcode"); - ase_awk_refdownval (run, left); - - ase_awk_setrunerror ( - run, ASE_AWK_EINTERN, nde->line, ASE_NULL, 0); - return ASE_NULL; - } - - if (__do_assignment (run, exp->left, res2) == ASE_NULL) - { - ase_awk_refdownval (run, left); - return ASE_NULL; - } - - ase_awk_refdownval (run, left); - return res; -} - -static ase_awk_val_t* __eval_cnd (ase_awk_run_t* run, ase_awk_nde_t* nde) -{ - ase_awk_val_t* tv, * v; - ase_awk_nde_cnd_t* cnd = (ase_awk_nde_cnd_t*)nde; - - ASE_ASSERT (cnd->test->next == ASE_NULL); - - tv = __eval_expression (run, cnd->test); - if (tv == ASE_NULL) return ASE_NULL; - - ase_awk_refupval (run, tv); - - ASE_ASSERT ( - cnd->left->next == ASE_NULL && - cnd->right->next == ASE_NULL); - v = (ase_awk_valtobool (run, tv))? - __eval_expression (run, cnd->left): - __eval_expression (run, cnd->right); - - ase_awk_refdownval (run, tv); - return v; -} - -static ase_awk_val_t* __eval_bfn (ase_awk_run_t* run, ase_awk_nde_t* nde) -{ - ase_awk_nde_call_t* call = (ase_awk_nde_call_t*)nde; - - /* built-in function */ - if (call->nargs < call->what.bfn.arg.min) - { - ase_awk_setrunerror ( - run, ASE_AWK_EARGTF, nde->line, ASE_NULL, 0); - return ASE_NULL; - } - - if (call->nargs > call->what.bfn.arg.max) - { - ase_awk_setrunerror ( - run, ASE_AWK_EARGTM, nde->line, ASE_NULL, 0); - return ASE_NULL; - } - - return __eval_call (run, nde, call->what.bfn.arg.spec, ASE_NULL); -} - -static ase_awk_val_t* __eval_afn (ase_awk_run_t* run, ase_awk_nde_t* nde) -{ - ase_awk_nde_call_t* call = (ase_awk_nde_call_t*)nde; - ase_awk_afn_t* afn; - ase_awk_pair_t* pair; - - pair = ase_awk_map_get (&run->awk->tree.afns, - call->what.afn.name.ptr, call->what.afn.name.len); - if (pair == ASE_NULL) - { - ase_cstr_t errarg; - - errarg.ptr = call->what.afn.name.ptr; - errarg.len = call->what.afn.name.len, - - ase_awk_setrunerror (run, - ASE_AWK_EFNNONE, nde->line, &errarg, 1); - return ASE_NULL; - } - - afn = (ase_awk_afn_t*)pair->val; - ASE_ASSERT (afn != ASE_NULL); - - if (call->nargs > afn->nargs) - { - /* TODO: is this correct? what if i want to - * allow arbitarary numbers of arguments? */ - ase_awk_setrunerror ( - run, ASE_AWK_EARGTM, nde->line, ASE_NULL, 0); - return ASE_NULL; - } - - return __eval_call (run, nde, ASE_NULL, afn); -} - - -/* run->stack_base has not been set for this - * stack frame. so the STACK_ARG macro cannot be used as in - * ase_awk_refdownval (run, STACK_ARG(run,nargs));*/ - -#define UNWIND_RUN_STACK(run,nargs) \ - do { \ - while ((nargs) > 0) \ - { \ - --(nargs); \ - ase_awk_refdownval ((run), \ - (run)->stack[(run)->stack_top-1]); \ - __raw_pop (run); \ - } \ - __raw_pop (run); /* nargs */ \ - __raw_pop (run); /* return */ \ - __raw_pop (run); /* prev stack top */ \ - __raw_pop (run); /* prev stack back */ \ - } while (0) - -static ase_awk_val_t* __eval_call ( - ase_awk_run_t* run, ase_awk_nde_t* nde, - const ase_char_t* bfn_arg_spec, ase_awk_afn_t* afn) -{ - ase_awk_nde_call_t* call = (ase_awk_nde_call_t*)nde; - ase_size_t saved_stack_top; - ase_size_t nargs, i; - ase_awk_nde_t* p; - ase_awk_val_t* v; - int n; - - /* - * --------------------- - * localn <- stack top - * --------------------- - * .... - * --------------------- - * local0 local variables are pushed by __run_block - * ===================== - * argn - * --------------------- - * .... - * --------------------- - * arg1 - * --------------------- - * arg0 - * --------------------- - * nargs - * --------------------- - * return value - * --------------------- - * previous stack top - * --------------------- - * previous stack base <- stack base - * ===================== - * 0 (nargs) <- stack top - * --------------------- - * return value - * --------------------- - * previous stack top - * --------------------- - * previous stack base <- stack base - * ===================== - * globaln - * --------------------- - * .... - * --------------------- - * global0 - * --------------------- - */ - - ASE_ASSERT ( - ASE_SIZEOF(void*) >= ASE_SIZEOF(run->stack_top)); - ASE_ASSERT ( - ASE_SIZEOF(void*) >= ASE_SIZEOF(run->stack_base)); - - saved_stack_top = run->stack_top; - -#ifdef DEBUG_RUN - ase_dprintf (ASE_T("setting up function stack frame top=%ld base=%ld\n"), - (long)run->stack_top, (long)run->stack_base); -#endif - if (__raw_push(run,(void*)run->stack_base) == -1) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, ASE_NULL, 0); - return ASE_NULL; - } - - if (__raw_push(run,(void*)saved_stack_top) == -1) - { - __raw_pop (run); - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, ASE_NULL, 0); - return ASE_NULL; - } - - /* secure space for a return value. */ - if (__raw_push(run,ase_awk_val_nil) == -1) - { - __raw_pop (run); - __raw_pop (run); - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, ASE_NULL, 0); - return ASE_NULL; - } - - /* secure space for nargs */ - if (__raw_push(run,ase_awk_val_nil) == -1) - { - __raw_pop (run); - __raw_pop (run); - __raw_pop (run); - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, ASE_NULL, 0); - return ASE_NULL; - } - - for (p = call->args, nargs = 0; p != ASE_NULL; p = p->next, nargs++) - { - ASE_ASSERT ( - bfn_arg_spec == ASE_NULL || - (bfn_arg_spec != ASE_NULL && - ase_strlen(bfn_arg_spec) > nargs)); - - if (bfn_arg_spec != ASE_NULL && - bfn_arg_spec[nargs] == ASE_T('r')) - { - ase_awk_val_t** ref; - - if (__get_reference (run, p, &ref) == -1) - { - UNWIND_RUN_STACK (run, nargs); - return ASE_NULL; - } - - /* p->type-ASE_AWK_NDE_NAMED assumes that the - * derived value matches ASE_AWK_VAL_REF_XXX */ - v = ase_awk_makerefval ( - run, p->type-ASE_AWK_NDE_NAMED, ref); - } - else if (bfn_arg_spec != ASE_NULL && - bfn_arg_spec[nargs] == ASE_T('x')) - { - /* a regular expression is passed to - * the function as it is */ - v = __eval_expression0 (run, p); - } - else - { - v = __eval_expression (run, p); - } - if (v == ASE_NULL) - { - UNWIND_RUN_STACK (run, nargs); - return ASE_NULL; - } - - if (__raw_push(run,v) == -1) - { - /* ugly - v needs to be freed if it doesn't have - * any reference. but its reference has not been - * updated yet as it is carried out after the - * successful stack push. so it adds up a reference - * and dereferences it */ - ase_awk_refupval (run, v); - ase_awk_refdownval (run, v); - - UNWIND_RUN_STACK (run, nargs); - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, ASE_NULL, 0); - return ASE_NULL; - } - - ase_awk_refupval (run, v); - /*nargs++; p = p->next;*/ - } - - ASE_ASSERT (nargs == call->nargs); - - if (afn != ASE_NULL) - { - /* extra step for normal awk functions */ - - while (nargs < afn->nargs) - { - /* push as many nils as the number of missing actual arguments */ - if (__raw_push(run,ase_awk_val_nil) == -1) - { - UNWIND_RUN_STACK (run, nargs); - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, - ASE_NULL, 0); - return ASE_NULL; - } - - nargs++; - } - } - - run->stack_base = saved_stack_top; - STACK_NARGS(run) = (void*)nargs; - -#ifdef DEBUG_RUN - ase_dprintf (ASE_T("running function body\n")); -#endif - - if (afn != ASE_NULL) - { - /* normal awk function */ - ASE_ASSERT (afn->body->type == ASE_AWK_NDE_BLK); - n = __run_block(run,(ase_awk_nde_blk_t*)afn->body); - } - else - { - n = 0; - - /* built-in function */ - ASE_ASSERT ( - call->nargs >= call->what.bfn.arg.min && - call->nargs <= call->what.bfn.arg.max); - - if (call->what.bfn.handler != ASE_NULL) - { - run->errnum = ASE_AWK_ENOERR; - - n = call->what.bfn.handler ( - run, - call->what.bfn.name.ptr, - call->what.bfn.name.len); - - if (n <= -1) - { - if (run->errnum == ASE_AWK_ENOERR) - { - /* the handler has not set the error. - * fix it */ - ase_awk_setrunerror ( - run, ASE_AWK_EBFNIMPL, - nde->line, ASE_NULL, 0); - } - else - { - /* adjust the error line */ - run->errlin = nde->line; - } - - /* correct the return code just in case */ - if (n < -1) n = -1; - } - } - } - - /* refdown args in the run.stack */ - nargs = (ase_size_t)STACK_NARGS(run); -#ifdef DEBUG_RUN - ase_dprintf (ASE_T("block run complete nargs = %d\n"), (int)nargs); -#endif - for (i = 0; i < nargs; i++) - { - ase_awk_refdownval (run, STACK_ARG(run,i)); - } - -#ifdef DEBUG_RUN - ase_dprintf (ASE_T("got return value\n")); -#endif - - /* this trick has been mentioned in __run_return. - * adjust the reference count of the return value. - * the value must not be freed even if the reference count - * is decremented to zero because its reference has been incremented - * in __run_return regardless of its reference count. */ - v = STACK_RETVAL(run); - ase_awk_refdownval_nofree (run, v); - - run->stack_top = (ase_size_t)run->stack[run->stack_base+1]; - run->stack_base = (ase_size_t)run->stack[run->stack_base+0]; - - if (run->exit_level == EXIT_FUNCTION) run->exit_level = EXIT_NONE; - -#ifdef DEBUG_RUN - ase_dprintf (ASE_T("returning from function top=%ld, base=%ld\n"), - (long)run->stack_top, (long)run->stack_base); -#endif - return (n == -1)? ASE_NULL: v; -} - -static int __get_reference ( - ase_awk_run_t* run, ase_awk_nde_t* nde, ase_awk_val_t*** ref) -{ - ase_awk_nde_var_t* tgt = (ase_awk_nde_var_t*)nde; - ase_awk_val_t** tmp; - - /* refer to __eval_indexed for application of a similar concept */ - - if (nde->type == ASE_AWK_NDE_NAMED) - { - ase_awk_pair_t* pair; - - pair = ase_awk_map_get ( - &run->named, tgt->id.name, tgt->id.name_len); - if (pair == ASE_NULL) - { - /* it is bad that the named variable has to be - * created in the function named "__get_refernce". - * would there be any better ways to avoid this? */ - pair = ase_awk_map_put ( - &run->named, tgt->id.name, - tgt->id.name_len, ase_awk_val_nil); - if (pair == ASE_NULL) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, - ASE_NULL, 0); - return -1; - } - } - - *ref = (ase_awk_val_t**)&pair->val; - return 0; - } - - if (nde->type == ASE_AWK_NDE_GLOBAL) - { - *ref = (ase_awk_val_t**)&STACK_GLOBAL(run,tgt->id.idxa); - return 0; - } - - if (nde->type == ASE_AWK_NDE_LOCAL) - { - *ref = (ase_awk_val_t**)&STACK_LOCAL(run,tgt->id.idxa); - return 0; - } - - if (nde->type == ASE_AWK_NDE_ARG) - { - *ref = (ase_awk_val_t**)&STACK_ARG(run,tgt->id.idxa); - return 0; - } - - if (nde->type == ASE_AWK_NDE_NAMEDIDX) - { - ase_awk_pair_t* pair; - - pair = ase_awk_map_get ( - &run->named, tgt->id.name, tgt->id.name_len); - if (pair == ASE_NULL) - { - pair = ase_awk_map_put ( - &run->named, tgt->id.name, - tgt->id.name_len, ase_awk_val_nil); - if (pair == ASE_NULL) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, - ASE_NULL, 0); - return -1; - } - } - - tmp = __get_reference_indexed ( - run, tgt, (ase_awk_val_t**)&pair->val); - if (tmp == ASE_NULL) return -1; - *ref = tmp; - } - - if (nde->type == ASE_AWK_NDE_GLOBALIDX) - { - tmp = __get_reference_indexed (run, tgt, - (ase_awk_val_t**)&STACK_GLOBAL(run,tgt->id.idxa)); - if (tmp == ASE_NULL) return -1; - *ref = tmp; - } - - if (nde->type == ASE_AWK_NDE_LOCALIDX) - { - tmp = __get_reference_indexed (run, tgt, - (ase_awk_val_t**)&STACK_LOCAL(run,tgt->id.idxa)); - if (tmp == ASE_NULL) return -1; - *ref = tmp; - } - - if (nde->type == ASE_AWK_NDE_ARGIDX) - { - tmp = __get_reference_indexed (run, tgt, - (ase_awk_val_t**)&STACK_ARG(run,tgt->id.idxa)); - if (tmp == ASE_NULL) return -1; - *ref = tmp; - } - - if (nde->type == ASE_AWK_NDE_POS) - { - int n; - ase_long_t lv; - ase_real_t rv; - ase_awk_val_t* v; - - /* the position number is returned for the positional - * variable unlike other reference types. */ - v = __eval_expression (run, ((ase_awk_nde_pos_t*)nde)->val); - if (v == ASE_NULL) return -1; - - ase_awk_refupval (run, v); - n = ase_awk_valtonum (run, v, &lv, &rv); - ase_awk_refdownval (run, v); - - if (n == -1) - { - ase_awk_setrunerror ( - run, ASE_AWK_EPOSIDX, nde->line, ASE_NULL, 0); - return -1; - } - if (n == 1) lv = (ase_long_t)rv; - if (!IS_VALID_POSIDX(lv)) - { - ase_awk_setrunerror ( - run, ASE_AWK_EPOSIDX, nde->line, ASE_NULL, 0); - return -1; - } - - *ref = (ase_awk_val_t**)((ase_size_t)lv); - return 0; - } - - ase_awk_setrunerror (run, ASE_AWK_ENOTREF, nde->line, ASE_NULL, 0); - return -1; -} - -static ase_awk_val_t** __get_reference_indexed ( - ase_awk_run_t* run, ase_awk_nde_var_t* nde, ase_awk_val_t** val) -{ - ase_awk_pair_t* pair; - ase_char_t* str; - ase_size_t len; - - ASE_ASSERT (val != ASE_NULL); - - if ((*val)->type == ASE_AWK_VAL_NIL) - { - ase_awk_val_t* tmp; - - tmp = ase_awk_makemapval (run); - if (tmp == ASE_NULL) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, ASE_NULL, 0); - return ASE_NULL; - } - - ase_awk_refdownval (run, *val); - *val = tmp; - ase_awk_refupval (run, (ase_awk_val_t*)*val); - } - else if ((*val)->type != ASE_AWK_VAL_MAP) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOTMAP, nde->line, ASE_NULL, 0); - return ASE_NULL; - } - - ASE_ASSERT (nde->idx != ASE_NULL); - - str = __idxnde_to_str (run, nde->idx, &len); - if (str == ASE_NULL) return ASE_NULL; - - pair = ase_awk_map_get ((*(ase_awk_val_map_t**)val)->map, str, len); - if (pair == ASE_NULL) - { - pair = ase_awk_map_put ( - (*(ase_awk_val_map_t**)val)->map, - str, len, ase_awk_val_nil); - if (pair == ASE_NULL) - { - ASE_AWK_FREE (run->awk, str); - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, ASE_NULL, 0); - return ASE_NULL; - } - - ase_awk_refupval (run, pair->val); - } - - ASE_AWK_FREE (run->awk, str); - return (ase_awk_val_t**)&pair->val; -} - -static ase_awk_val_t* __eval_int (ase_awk_run_t* run, ase_awk_nde_t* nde) -{ - ase_awk_val_t* val; - - val = ase_awk_makeintval (run, ((ase_awk_nde_int_t*)nde)->val); - if (val == ASE_NULL) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, ASE_NULL, 0); - return ASE_NULL; - } - ((ase_awk_val_int_t*)val)->nde = (ase_awk_nde_int_t*)nde; - - return val; -} - -static ase_awk_val_t* __eval_real (ase_awk_run_t* run, ase_awk_nde_t* nde) -{ - ase_awk_val_t* val; - - val = ase_awk_makerealval (run, ((ase_awk_nde_real_t*)nde)->val); - if (val == ASE_NULL) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, ASE_NULL, 0); - return ASE_NULL; - } - ((ase_awk_val_real_t*)val)->nde = (ase_awk_nde_real_t*)nde; - - return val; -} - -static ase_awk_val_t* __eval_str (ase_awk_run_t* run, ase_awk_nde_t* nde) -{ - ase_awk_val_t* val; - - val = ase_awk_makestrval (run, - ((ase_awk_nde_str_t*)nde)->buf, - ((ase_awk_nde_str_t*)nde)->len); - if (val == ASE_NULL) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, ASE_NULL, 0); - return ASE_NULL; - } - - return val; -} - -static ase_awk_val_t* __eval_rex (ase_awk_run_t* run, ase_awk_nde_t* nde) -{ - ase_awk_val_t* val; - - val = ase_awk_makerexval (run, - ((ase_awk_nde_rex_t*)nde)->buf, - ((ase_awk_nde_rex_t*)nde)->len, - ((ase_awk_nde_rex_t*)nde)->code); - if (val == ASE_NULL) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, ASE_NULL, 0); - return ASE_NULL; - } - - return val; -} - -static ase_awk_val_t* __eval_named (ase_awk_run_t* run, ase_awk_nde_t* nde) -{ - ase_awk_pair_t* pair; - - pair = ase_awk_map_get (&run->named, - ((ase_awk_nde_var_t*)nde)->id.name, - ((ase_awk_nde_var_t*)nde)->id.name_len); - - return (pair == ASE_NULL)? ase_awk_val_nil: pair->val; -} - -static ase_awk_val_t* __eval_global (ase_awk_run_t* run, ase_awk_nde_t* nde) -{ - return STACK_GLOBAL(run,((ase_awk_nde_var_t*)nde)->id.idxa); -} - -static ase_awk_val_t* __eval_local (ase_awk_run_t* run, ase_awk_nde_t* nde) -{ - return STACK_LOCAL(run,((ase_awk_nde_var_t*)nde)->id.idxa); -} - -static ase_awk_val_t* __eval_arg (ase_awk_run_t* run, ase_awk_nde_t* nde) -{ - return STACK_ARG(run,((ase_awk_nde_var_t*)nde)->id.idxa); -} - -static ase_awk_val_t* __eval_indexed ( - ase_awk_run_t* run, ase_awk_nde_var_t* nde, ase_awk_val_t** val) -{ - ase_awk_pair_t* pair; - ase_char_t* str; - ase_size_t len; - - ASE_ASSERT (val != ASE_NULL); - - if ((*val)->type == ASE_AWK_VAL_NIL) - { - ase_awk_val_t* tmp; - - tmp = ase_awk_makemapval (run); - if (tmp == ASE_NULL) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, ASE_NULL, 0); - return ASE_NULL; - } - - ase_awk_refdownval (run, *val); - *val = tmp; - ase_awk_refupval (run, (ase_awk_val_t*)*val); - } - else if ((*val)->type != ASE_AWK_VAL_MAP) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOTMAP, nde->line, ASE_NULL, 0); - return ASE_NULL; - } - - ASE_ASSERT (nde->idx != ASE_NULL); - - str = __idxnde_to_str (run, nde->idx, &len); - if (str == ASE_NULL) return ASE_NULL; - - pair = ase_awk_map_get ((*(ase_awk_val_map_t**)val)->map, str, len); - ASE_AWK_FREE (run->awk, str); - - return (pair == ASE_NULL)? ase_awk_val_nil: (ase_awk_val_t*)pair->val; -} - -static ase_awk_val_t* __eval_namedidx (ase_awk_run_t* run, ase_awk_nde_t* nde) -{ - ase_awk_nde_var_t* tgt = (ase_awk_nde_var_t*)nde; - ase_awk_pair_t* pair; - - pair = ase_awk_map_get (&run->named, tgt->id.name, tgt->id.name_len); - if (pair == ASE_NULL) - { - pair = ase_awk_map_put (&run->named, - tgt->id.name, tgt->id.name_len, ase_awk_val_nil); - if (pair == ASE_NULL) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, ASE_NULL, 0); - return ASE_NULL; - } - - ase_awk_refupval (run, pair->val); - } - - return __eval_indexed (run, tgt, (ase_awk_val_t**)&pair->val); -} - -static ase_awk_val_t* __eval_globalidx (ase_awk_run_t* run, ase_awk_nde_t* nde) -{ - return __eval_indexed (run, (ase_awk_nde_var_t*)nde, - (ase_awk_val_t**)&STACK_GLOBAL(run,((ase_awk_nde_var_t*)nde)->id.idxa)); -} - -static ase_awk_val_t* __eval_localidx (ase_awk_run_t* run, ase_awk_nde_t* nde) -{ - return __eval_indexed (run, (ase_awk_nde_var_t*)nde, - (ase_awk_val_t**)&STACK_LOCAL(run,((ase_awk_nde_var_t*)nde)->id.idxa)); -} - -static ase_awk_val_t* __eval_argidx (ase_awk_run_t* run, ase_awk_nde_t* nde) -{ - return __eval_indexed (run, (ase_awk_nde_var_t*)nde, - (ase_awk_val_t**)&STACK_ARG(run,((ase_awk_nde_var_t*)nde)->id.idxa)); -} - -static ase_awk_val_t* __eval_pos (ase_awk_run_t* run, ase_awk_nde_t* nde) -{ - ase_awk_nde_pos_t* pos = (ase_awk_nde_pos_t*)nde; - ase_awk_val_t* v; - ase_long_t lv; - ase_real_t rv; - int n; - - v = __eval_expression (run, pos->val); - if (v == ASE_NULL) return ASE_NULL; - - ase_awk_refupval (run, v); - n = ase_awk_valtonum (run, v, &lv, &rv); - ase_awk_refdownval (run, v); - if (n == -1) - { - ase_awk_setrunerror ( - run, ASE_AWK_EPOSIDX, nde->line, ASE_NULL, 0); - return ASE_NULL; - } - if (n == 1) lv = (ase_long_t)rv; - - if (lv < 0) - { - ase_awk_setrunerror ( - run, ASE_AWK_EPOSIDX, nde->line, ASE_NULL, 0); - return ASE_NULL; - } - if (lv == 0) v = run->inrec.d0; - else if (lv > 0 && lv <= run->inrec.nflds) - v = run->inrec.flds[lv-1].val; - else v = ase_awk_val_zls; /*ase_awk_val_nil;*/ - - return v; -} - -static ase_awk_val_t* __eval_getline (ase_awk_run_t* run, ase_awk_nde_t* nde) -{ - ase_awk_nde_getline_t* p; - ase_awk_val_t* v, * res; - ase_char_t* in = ASE_NULL; - const ase_char_t* dst; - ase_str_t buf; - int n; - - p = (ase_awk_nde_getline_t*)nde; - - ASE_ASSERT ( - (p->in_type == ASE_AWK_IN_PIPE && p->in != ASE_NULL) || - (p->in_type == ASE_AWK_IN_COPROC && p->in != ASE_NULL) || - (p->in_type == ASE_AWK_IN_FILE && p->in != ASE_NULL) || - (p->in_type == ASE_AWK_IN_CONSOLE && p->in == ASE_NULL)); - - if (p->in != ASE_NULL) - { - ase_size_t len; - - v = __eval_expression (run, p->in); - if (v == ASE_NULL) return ASE_NULL; - - /* TODO: distinction between v->type == ASE_AWK_VAL_STR - * and v->type != ASE_AWK_VAL_STR - * if you use the buffer the v directly when - * v->type == ASE_AWK_VAL_STR, ase_awk_refdownval(v) - * should not be called immediately below */ - ase_awk_refupval (run, v); - in = ase_awk_valtostr ( - run, v, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &len); - if (in == ASE_NULL) - { - ase_awk_refdownval (run, v); - return ASE_NULL; - } - ase_awk_refdownval (run, v); - - if (len <= 0) - { - /* the input source name is empty. - * make getline return -1 */ - ASE_AWK_FREE (run->awk, in); - n = -1; - goto skip_read; - } - - while (len > 0) - { - if (in[--len] == ASE_T('\0')) - { - /* the input source name contains a null - * character. make getline return -1 */ - ASE_AWK_FREE (run->awk, in); - n = -1; - goto skip_read; - } - } - } - - dst = (in == ASE_NULL)? ASE_T(""): in; - - /* TODO: optimize the line buffer management */ - if (ase_str_open (&buf, DEF_BUF_CAPA, &run->awk->prmfns.mmgr) == ASE_NULL) - { - if (in != ASE_NULL) ASE_AWK_FREE (run->awk, in); - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, ASE_NULL, 0); - return ASE_NULL; - } - - n = ase_awk_readextio (run, p->in_type, dst, &buf); - if (in != ASE_NULL) ASE_AWK_FREE (run->awk, in); - - if (n <= -1) - { - /* make getline return -1 */ - n = -1; - } - - if (n > 0) - { - if (p->var == ASE_NULL) - { - /* set $0 with the input value */ - if (ase_awk_setrec (run, 0, - ASE_STR_BUF(&buf), - ASE_STR_LEN(&buf)) == -1) - { - ase_str_close (&buf); - return ASE_NULL; - } - - ase_str_close (&buf); - } - else - { - ase_awk_val_t* v; - - v = ase_awk_makestrval (run, - ASE_STR_BUF(&buf), ASE_STR_LEN(&buf)); - ase_str_close (&buf); - if (v == ASE_NULL) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, - ASE_NULL, 0); - return ASE_NULL; - } - - ase_awk_refupval (run, v); - if (__do_assignment(run, p->var, v) == ASE_NULL) - { - ase_awk_refdownval (run, v); - return ASE_NULL; - } - ase_awk_refdownval (run, v); - } - } - else - { - ase_str_close (&buf); - } - -skip_read: - res = ase_awk_makeintval (run, n); - if (res == ASE_NULL) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, ASE_NULL, 0); - return ASE_NULL; - } - - return res; -} - -static int __raw_push (ase_awk_run_t* run, void* val) -{ - if (run->stack_top >= run->stack_limit) - { - void** tmp; - ase_size_t n; - - n = run->stack_limit + STACK_INCREMENT; - - if (run->awk->prmfns.mmgr.realloc != ASE_NULL) - { - tmp = (void**) ASE_AWK_REALLOC ( - run->awk, run->stack, n * ASE_SIZEOF(void*)); - if (tmp == ASE_NULL) return -1; - } - else - { - tmp = (void**) ASE_AWK_MALLOC ( - run->awk, n * ASE_SIZEOF(void*)); - if (tmp == ASE_NULL) return -1; - if (run->stack != ASE_NULL) - { - ase_memcpy ( - tmp, run->stack, - run->stack_limit * ASE_SIZEOF(void*)); - ASE_AWK_FREE (run->awk, run->stack); - } - } - run->stack = tmp; - run->stack_limit = n; - } - - run->stack[run->stack_top++] = val; - return 0; -} - -static void __raw_pop_times (ase_awk_run_t* run, ase_size_t times) -{ - while (times > 0) - { - --times; - __raw_pop (run); - } -} - -static int __read_record (ase_awk_run_t* run) -{ - ase_ssize_t n; - - if (ase_awk_clrrec (run, ase_false) == -1) return -1; - - n = ase_awk_readextio ( - run, ASE_AWK_IN_CONSOLE, ASE_T(""), &run->inrec.line); - if (n <= -1) - { - ase_awk_clrrec (run, ase_false); - return -1; - } - -#ifdef DEBUG_RUN - ase_dprintf (ASE_T("record len = %d str=[%.*s]\n"), - (int)ASE_STR_LEN(&run->inrec.line), - (int)ASE_STR_LEN(&run->inrec.line), - ASE_STR_BUF(&run->inrec.line)); -#endif - if (n == 0) - { - ASE_ASSERT (ASE_STR_LEN(&run->inrec.line) == 0); - return 0; - } - - if (ase_awk_setrec (run, 0, - ASE_STR_BUF(&run->inrec.line), - ASE_STR_LEN(&run->inrec.line)) == -1) return -1; - - return 1; -} - -static int __shorten_record (ase_awk_run_t* run, ase_size_t nflds) -{ - ase_awk_val_t* v; - ase_char_t* ofs_free = ASE_NULL, * ofs; - ase_size_t ofs_len, i; - ase_str_t tmp; - - ASE_ASSERT (nflds <= run->inrec.nflds); - - if (nflds > 1) - { - v = STACK_GLOBAL(run, ASE_AWK_GLOBAL_OFS); - ase_awk_refupval (run, v); - - if (v->type == ASE_AWK_VAL_NIL) - { - /* OFS not set */ - ofs = ASE_T(" "); - ofs_len = 1; - } - else if (v->type == ASE_AWK_VAL_STR) - { - ofs = ((ase_awk_val_str_t*)v)->buf; - ofs_len = ((ase_awk_val_str_t*)v)->len; - } - else - { - ofs = ase_awk_valtostr ( - run, v, ASE_AWK_VALTOSTR_CLEAR, - ASE_NULL, &ofs_len); - if (ofs == ASE_NULL) return -1; - - ofs_free = ofs; - } - } - - if (ase_str_open ( - &tmp, ASE_STR_LEN(&run->inrec.line), - &run->awk->prmfns.mmgr) == ASE_NULL) - { - ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - - for (i = 0; i < nflds; i++) - { - if (i > 0 && ase_str_ncat(&tmp,ofs,ofs_len) == (ase_size_t)-1) - { - if (ofs_free != ASE_NULL) - ASE_AWK_FREE (run->awk, ofs_free); - if (nflds > 1) ase_awk_refdownval (run, v); - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - - if (ase_str_ncat (&tmp, - run->inrec.flds[i].ptr, - run->inrec.flds[i].len) == (ase_size_t)-1) - { - if (ofs_free != ASE_NULL) - ASE_AWK_FREE (run->awk, ofs_free); - if (nflds > 1) ase_awk_refdownval (run, v); - - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - } - - if (ofs_free != ASE_NULL) ASE_AWK_FREE (run->awk, ofs_free); - if (nflds > 1) ase_awk_refdownval (run, v); - - v = (ase_awk_val_t*) ase_awk_makestrval ( - run, ASE_STR_BUF(&tmp), ASE_STR_LEN(&tmp)); - if (v == ASE_NULL) - { - ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return -1; - } - - ase_awk_refdownval (run, run->inrec.d0); - run->inrec.d0 = v; - ase_awk_refupval (run, run->inrec.d0); - - ase_str_swap (&tmp, &run->inrec.line); - ase_str_close (&tmp); - - for (i = nflds; i < run->inrec.nflds; i++) - { - ase_awk_refdownval (run, run->inrec.flds[i].val); - } - - run->inrec.nflds = nflds; - return 0; -} - -static ase_char_t* __idxnde_to_str ( - ase_awk_run_t* run, ase_awk_nde_t* nde, ase_size_t* len) -{ - ase_char_t* str; - ase_awk_val_t* idx; - - ASE_ASSERT (nde != ASE_NULL); - - if (nde->next == ASE_NULL) - { - /* single node index */ - idx = __eval_expression (run, nde); - if (idx == ASE_NULL) return ASE_NULL; - - ase_awk_refupval (run, idx); - - str = ase_awk_valtostr ( - run, idx, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, len); - if (str == ASE_NULL) - { - ase_awk_refdownval (run, idx); - /* change error line */ - run->errlin = nde->line; - return ASE_NULL; - } - - ase_awk_refdownval (run, idx); - } - else - { - /* multidimensional index */ - ase_str_t idxstr; - - if (ase_str_open ( - &idxstr, - DEF_BUF_CAPA, - &run->awk->prmfns.mmgr) == ASE_NULL) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, ASE_NULL, 0); - return ASE_NULL; - } - - while (nde != ASE_NULL) - { - idx = __eval_expression (run, nde); - if (idx == ASE_NULL) - { - ase_str_close (&idxstr); - return ASE_NULL; - } - - ase_awk_refupval (run, idx); - - if (ASE_STR_LEN(&idxstr) > 0 && - ase_str_ncat (&idxstr, - run->global.subsep.ptr, - run->global.subsep.len) == (ase_size_t)-1) - { - ase_awk_refdownval (run, idx); - ase_str_close (&idxstr); - - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, nde->line, - ASE_NULL, 0); - - return ASE_NULL; - } - - if (ase_awk_valtostr ( - run, idx, 0, &idxstr, ASE_NULL) == ASE_NULL) - { - ase_awk_refdownval (run, idx); - ase_str_close (&idxstr); - return ASE_NULL; - } - - ase_awk_refdownval (run, idx); - nde = nde->next; - } - - str = ASE_STR_BUF(&idxstr); - *len = ASE_STR_LEN(&idxstr); - ase_str_forfeit (&idxstr); - } - - return str; -} - -ase_char_t* ase_awk_format ( - ase_awk_run_t* run, ase_str_t* out, ase_str_t* fbu, - const ase_char_t* fmt, ase_size_t fmt_len, - ase_size_t nargs_on_stack, ase_awk_nde_t* args, ase_size_t* len) -{ - ase_size_t i, j; - ase_size_t stack_arg_idx = 1; - ase_awk_val_t* val; - -#define OUT_CHAR(c) \ - do { \ - if (ase_str_ccat (out, (c)) == -1) \ - { \ - ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); \ - return ASE_NULL; \ - } \ - } while (0) - -#define FMT_CHAR(c) \ - do { \ - if (ase_str_ccat (fbu, (c)) == -1) \ - { \ - ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); \ - return ASE_NULL; \ - } \ - } while (0) - -#define GROW(buf) \ - do { \ - if ((buf)->ptr != ASE_NULL) \ - { \ - ASE_AWK_FREE (run->awk, (buf)->ptr); \ - (buf)->ptr = ASE_NULL; \ - } \ - (buf)->len += (buf)->inc; \ - (buf)->ptr = (ase_char_t*)ASE_AWK_MALLOC ( \ - run->awk, (buf)->len * ASE_SIZEOF(ase_char_t)); \ - if ((buf)->ptr == ASE_NULL) (buf)->len = 0; \ - } while (0) - - ASE_ASSERTX (run->format.tmp.ptr != ASE_NULL, - "run->format.tmp.ptr should have been assigned a pointer to a block of memory before this function has been called"); - - if (nargs_on_stack == (ase_size_t)-1) - { - val = (ase_awk_val_t*)args; - nargs_on_stack = 2; - } - else - { - val = ASE_NULL; - } - - if (out == ASE_NULL) out = &run->format.out; - if (fbu == ASE_NULL) fbu = &run->format.fmt; - - ase_str_clear (out); - ase_str_clear (fbu); - - for (i = 0; i < fmt_len; i++) - { - ase_long_t width = -1, prec = -1; - ase_bool_t minus = ase_false; - - if (ASE_STR_LEN(fbu) == 0) - { - if (fmt[i] == ASE_T('%')) FMT_CHAR (fmt[i]); - else OUT_CHAR (fmt[i]); - continue; - } - - while (i < fmt_len && - (fmt[i] == ASE_T(' ') || fmt[i] == ASE_T('#') || - fmt[i] == ASE_T('0') || fmt[i] == ASE_T('+') || - fmt[i] == ASE_T('-'))) - { - if (fmt[i] == ASE_T('-')) minus = ase_true; - FMT_CHAR (fmt[i]); i++; - } - - if (i < fmt_len && fmt[i] == ASE_T('*')) - { - ase_awk_val_t* v; - ase_real_t r; - ase_char_t* p; - int n; - - if (args == ASE_NULL) - { - if (stack_arg_idx >= nargs_on_stack) - { - ase_awk_setrunerror (run, ASE_AWK_EFMTARG, 0, ASE_NULL, 0); - return ASE_NULL; - } - v = ase_awk_getarg (run, stack_arg_idx); - } - else - { - if (val != ASE_NULL) - { - if (stack_arg_idx >= nargs_on_stack) - { - ase_awk_setrunerror (run, ASE_AWK_EFMTARG, 0, ASE_NULL, 0); - return ASE_NULL; - } - v = val; - } - else - { - v = __eval_expression (run, args); - if (v == ASE_NULL) return ASE_NULL; - } - } - - ase_awk_refupval (run, v); - n = ase_awk_valtonum (run, v, &width, &r); - ase_awk_refdownval (run, v); - - if (n == -1) return ASE_NULL; - if (n == 1) width = (ase_long_t)r; - - do - { - n = run->awk->prmfns.misc.sprintf ( - run->awk->prmfns.misc.custom_data, - run->format.tmp.ptr, - run->format.tmp.len, - #if ASE_SIZEOF_LONG_LONG > 0 - ASE_T("%lld"), (long long)width - #elif ASE_SIZEOF___INT64 > 0 - ASE_T("%I64d"), (__int64)width - #elif ASE_SIZEOF_LONG > 0 - ASE_T("%ld"), (long)width - #elif ASE_SIZEOF_INT > 0 - ASE_T("%d"), (int)width - #else - #error unsupported size - #endif - ); - if (n == -1) - { - GROW (&run->format.tmp); - if (run->format.tmp.ptr == ASE_NULL) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, - ASE_NULL, 0); - return ASE_NULL; - } - - continue; - } - - break; - } - while (1); - - p = run->format.tmp.ptr; - while (*p != ASE_T('\0')) - { - FMT_CHAR (*p); - p++; - } - - if (args == ASE_NULL || val != ASE_NULL) stack_arg_idx++; - else args = args->next; - i++; - } - else - { - if (i < fmt_len && ASE_AWK_ISDIGIT(run->awk, fmt[i])) - { - width = 0; - do - { - width = width * 10 + fmt[i] - ASE_T('0'); - FMT_CHAR (fmt[i]); i++; - } - while (i < fmt_len && ASE_AWK_ISDIGIT(run->awk, fmt[i])); - } - } - - if (i < fmt_len && fmt[i] == ASE_T('.')) - { - prec = 0; - FMT_CHAR (fmt[i]); i++; - } - - if (i < fmt_len && fmt[i] == ASE_T('*')) - { - ase_awk_val_t* v; - ase_real_t r; - ase_char_t* p; - int n; - - if (args == ASE_NULL) - { - if (stack_arg_idx >= nargs_on_stack) - { - ase_awk_setrunerror (run, ASE_AWK_EFMTARG, 0, ASE_NULL, 0); - return ASE_NULL; - } - v = ase_awk_getarg (run, stack_arg_idx); - } - else - { - if (val != ASE_NULL) - { - if (stack_arg_idx >= nargs_on_stack) - { - ase_awk_setrunerror (run, ASE_AWK_EFMTARG, 0, ASE_NULL, 0); - return ASE_NULL; - } - v = val; - } - else - { - v = __eval_expression (run, args); - if (v == ASE_NULL) return ASE_NULL; - } - } - - ase_awk_refupval (run, v); - n = ase_awk_valtonum (run, v, &prec, &r); - ase_awk_refdownval (run, v); - - if (n == -1) return ASE_NULL; - if (n == 1) prec = (ase_long_t)r; - - do - { - n = run->awk->prmfns.misc.sprintf ( - run->awk->prmfns.misc.custom_data, - run->format.tmp.ptr, - run->format.tmp.len, - #if ASE_SIZEOF_LONG_LONG > 0 - ASE_T("%lld"), (long long)prec - #elif ASE_SIZEOF___INT64 > 0 - ASE_T("%I64d"), (__int64)prec - #elif ASE_SIZEOF_LONG > 0 - ASE_T("%ld"), (long)prec - #elif ASE_SIZEOF_INT > 0 - ASE_T("%d"), (int)prec - #endif - ); - if (n == -1) - { - GROW (&run->format.tmp); - if (run->format.tmp.ptr == ASE_NULL) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, - ASE_NULL, 0); - return ASE_NULL; - } - - continue; - } - - break; - } - while (1); - - p = run->format.tmp.ptr; - while (*p != ASE_T('\0')) - { - FMT_CHAR (*p); - p++; - } - - if (args == ASE_NULL || val != ASE_NULL) stack_arg_idx++; - else args = args->next; - i++; - } - else - { - if (i < fmt_len && ASE_AWK_ISDIGIT(run->awk, fmt[i])) - { - prec = 0; - do - { - prec = prec * 10 + fmt[i] - ASE_T('0'); - FMT_CHAR (fmt[i]); i++; - } - while (i < fmt_len && ASE_AWK_ISDIGIT(run->awk, fmt[i])); - } - } - - if (i >= fmt_len) break; - - if (fmt[i] == ASE_T('d') || fmt[i] == ASE_T('i') || - fmt[i] == ASE_T('x') || fmt[i] == ASE_T('X') || - fmt[i] == ASE_T('o')) - { - ase_awk_val_t* v; - ase_long_t l; - ase_real_t r; - ase_char_t* p; - int n; - - #if ASE_SIZEOF_LONG_LONG > 0 - FMT_CHAR (ASE_T('l')); - FMT_CHAR (ASE_T('l')); - FMT_CHAR (fmt[i]); - #elif ASE_SIZEOF___INT64 > 0 - FMT_CHAR (ASE_T('I')); - FMT_CHAR (ASE_T('6')); - FMT_CHAR (ASE_T('4')); - FMT_CHAR (fmt[i]); - #elif ASE_SIZEOF_LONG > 0 - FMT_CHAR (ASE_T('l')); - FMT_CHAR (fmt[i]); - #elif ASE_SIZEOF_INT > 0 - FMT_CHAR (fmt[i]); - #else - #error unsupported integer size - #endif - - if (args == ASE_NULL) - { - if (stack_arg_idx >= nargs_on_stack) - { - ase_awk_setrunerror (run, ASE_AWK_EFMTARG, 0, ASE_NULL, 0); - return ASE_NULL; - } - v = ase_awk_getarg (run, stack_arg_idx); - } - else - { - if (val != ASE_NULL) - { - if (stack_arg_idx >= nargs_on_stack) - { - ase_awk_setrunerror (run, ASE_AWK_EFMTARG, 0, ASE_NULL, 0); - return ASE_NULL; - } - v = val; - } - else - { - v = __eval_expression (run, args); - if (v == ASE_NULL) return ASE_NULL; - } - } - - ase_awk_refupval (run, v); - n = ase_awk_valtonum (run, v, &l, &r); - ase_awk_refdownval (run, v); - - if (n == -1) return ASE_NULL; - if (n == 1) l = (ase_long_t)r; - - do - { - n = run->awk->prmfns.misc.sprintf ( - run->awk->prmfns.misc.custom_data, - run->format.tmp.ptr, - run->format.tmp.len, - ASE_STR_BUF(fbu), - #if ASE_SIZEOF_LONG_LONG > 0 - (long long)l - #elif ASE_SIZEOF___INT64 > 0 - (__int64)l - #elif ASE_SIZEOF_LONG > 0 - (long)l - #elif ASE_SIZEOF_INT > 0 - (int)l - #endif - ); - - if (n == -1) - { - GROW (&run->format.tmp); - if (run->format.tmp.ptr == ASE_NULL) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, - ASE_NULL, 0); - return ASE_NULL; - } - - continue; - } - - break; - } - while (1); - - p = run->format.tmp.ptr; - while (*p != ASE_T('\0')) - { - OUT_CHAR (*p); - p++; - } - } - else if (fmt[i] == ASE_T('e') || fmt[i] == ASE_T('E') || - fmt[i] == ASE_T('g') || fmt[i] == ASE_T('G') || - fmt[i] == ASE_T('f')) - { - ase_awk_val_t* v; - ase_long_t l; - ase_real_t r; - ase_char_t* p; - int n; - - FMT_CHAR (ASE_T('L')); - FMT_CHAR (fmt[i]); - - if (args == ASE_NULL) - { - if (stack_arg_idx >= nargs_on_stack) - { - ase_awk_setrunerror (run, ASE_AWK_EFMTARG, 0, ASE_NULL, 0); - return ASE_NULL; - } - v = ase_awk_getarg (run, stack_arg_idx); - } - else - { - if (val != ASE_NULL) - { - if (stack_arg_idx >= nargs_on_stack) - { - ase_awk_setrunerror (run, ASE_AWK_EFMTARG, 0, ASE_NULL, 0); - return ASE_NULL; - } - v = val; - } - else - { - v = __eval_expression (run, args); - if (v == ASE_NULL) return ASE_NULL; - } - } - - ase_awk_refupval (run, v); - n = ase_awk_valtonum (run, v, &l, &r); - ase_awk_refdownval (run, v); - - if (n == -1) return ASE_NULL; - if (n == 0) r = (ase_real_t)l; - - do - { - n = run->awk->prmfns.misc.sprintf ( - run->awk->prmfns.misc.custom_data, - run->format.tmp.ptr, - run->format.tmp.len, - ASE_STR_BUF(fbu), - (long double)r); - - if (n == -1) - { - GROW (&run->format.tmp); - if (run->format.tmp.ptr == ASE_NULL) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return ASE_NULL; - } - - continue; - } - - break; - } - while (1); - - p = run->format.tmp.ptr; - while (*p != ASE_T('\0')) - { - OUT_CHAR (*p); - p++; - } - } - else if (fmt[i] == ASE_T('c')) - { - ase_char_t ch; - ase_size_t ch_len; - ase_awk_val_t* v; - - if (args == ASE_NULL) - { - if (stack_arg_idx >= nargs_on_stack) - { - ase_awk_setrunerror (run, ASE_AWK_EFMTARG, 0, ASE_NULL, 0); - return ASE_NULL; - } - v = ase_awk_getarg (run, stack_arg_idx); - } - else - { - if (val != ASE_NULL) - { - if (stack_arg_idx >= nargs_on_stack) - { - ase_awk_setrunerror (run, ASE_AWK_EFMTARG, 0, ASE_NULL, 0); - return ASE_NULL; - } - v = val; - } - else - { - v = __eval_expression (run, args); - if (v == ASE_NULL) return ASE_NULL; - } - } - - ase_awk_refupval (run, v); - if (v->type == ASE_AWK_VAL_NIL) - { - ch = ASE_T('\0'); - ch_len = 0; - } - else if (v->type == ASE_AWK_VAL_INT) - { - ch = (ase_char_t)((ase_awk_val_int_t*)v)->val; - ch_len = 1; - } - else if (v->type == ASE_AWK_VAL_REAL) - { - ch = (ase_char_t)((ase_awk_val_real_t*)v)->val; - ch_len = 1; - } - else if (v->type == ASE_AWK_VAL_STR) - { - ch_len = ((ase_awk_val_str_t*)v)->len; - if (ch_len > 0) - { - ch = ((ase_awk_val_str_t*)v)->buf[0]; - ch_len = 1; - } - else ch = ASE_T('\0'); - } - else - { - ase_awk_refdownval (run, v); - ase_awk_setrunerror ( - run, ASE_AWK_EVALTYPE, 0, ASE_NULL, 0); - return ASE_NULL; - } - - if (prec == -1 || prec == 0 || prec > ch_len) prec = ch_len; - if (prec > width) width = prec; - - if (!minus) - { - while (width > prec) - { - if (ase_str_ccat (out, ASE_T(' ')) == -1) - { - ase_awk_refdownval (run, v); - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return ASE_NULL; - } - width--; - } - } - - if (prec > 0) - { - if (ase_str_ccat (out, ch) == -1) - { - ase_awk_refdownval (run, v); - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return ASE_NULL; - } - } - - if (minus) - { - while (width > prec) - { - if (ase_str_ccat (out, ASE_T(' ')) == -1) - { - ase_awk_refdownval (run, v); - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return ASE_NULL; - } - width--; - } - } - - ase_awk_refdownval (run, v); - } - else if (fmt[i] == ASE_T('s')) - { - ase_char_t* str, * str_free = ASE_NULL; - ase_size_t str_len, k; - ase_awk_val_t* v; - - if (args == ASE_NULL) - { - if (stack_arg_idx >= nargs_on_stack) - { - ase_awk_setrunerror (run, ASE_AWK_EFMTARG, 0, ASE_NULL, 0); - return ASE_NULL; - } - v = ase_awk_getarg (run, stack_arg_idx); - } - else - { - if (val != ASE_NULL) - { - if (stack_arg_idx >= nargs_on_stack) - { - ase_awk_setrunerror (run, ASE_AWK_EFMTARG, 0, ASE_NULL, 0); - return ASE_NULL; - } - v = val; - } - else - { - v = __eval_expression (run, args); - if (v == ASE_NULL) return ASE_NULL; - } - } - - ase_awk_refupval (run, v); - if (v->type == ASE_AWK_VAL_NIL) - { - str = ASE_T(""); - str_len = 0; - } - else if (v->type == ASE_AWK_VAL_STR) - { - str = ((ase_awk_val_str_t*)v)->buf; - str_len = ((ase_awk_val_str_t*)v)->len; - } - else - { - if (v == val) - { - ase_awk_refdownval (run, v); - ase_awk_setrunerror (run, ASE_AWK_EFMTCNV, 0, ASE_NULL, 0); - return ASE_NULL; - } - - str = ase_awk_valtostr (run, v, - ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &str_len); - if (str == ASE_NULL) - { - ase_awk_refdownval (run, v); - return ASE_NULL; - } - - str_free = str; - } - - if (prec == -1 || prec > str_len ) prec = str_len; - if (prec > width) width = prec; - - if (!minus) - { - while (width > prec) - { - if (ase_str_ccat (out, ASE_T(' ')) == -1) - { - if (str_free != ASE_NULL) - ASE_AWK_FREE (run->awk, str_free); - ase_awk_refdownval (run, v); - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return ASE_NULL; - } - width--; - } - } - - for (k = 0; k < prec; k++) - { - if (ase_str_ccat (out, str[k]) == -1) - { - if (str_free != ASE_NULL) - ASE_AWK_FREE (run->awk, str_free); - ase_awk_refdownval (run, v); - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return ASE_NULL; - } - } - - if (str_free != ASE_NULL) ASE_AWK_FREE (run->awk, str_free); - - if (minus) - { - while (width > prec) - { - if (ase_str_ccat (out, ASE_T(' ')) == -1) - { - ase_awk_refdownval (run, v); - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return ASE_NULL; - } - width--; - } - } - - ase_awk_refdownval (run, v); - } - else /*if (fmt[i] == ASE_T('%'))*/ - { - for (j = 0; j < ASE_STR_LEN(fbu); j++) - OUT_CHAR (ASE_STR_CHAR(fbu,j)); - OUT_CHAR (fmt[i]); - } - - if (args == ASE_NULL || val != ASE_NULL) stack_arg_idx++; - else args = args->next; - ase_str_clear (fbu); - } - - /* flush uncompleted formatting sequence */ - for (j = 0; j < ASE_STR_LEN(fbu); j++) - OUT_CHAR (ASE_STR_CHAR(fbu,j)); - - *len = ASE_STR_LEN(out); - return ASE_STR_BUF(out); -} - diff --git a/ase/awk/run.h b/ase/awk/run.h deleted file mode 100644 index ce2d33ed..00000000 --- a/ase/awk/run.h +++ /dev/null @@ -1,119 +0,0 @@ -/* - * $Id: run.h,v 1.1.1.1 2007/03/28 14:05:20 bacon Exp $ - * - * {License} - */ - -#ifndef _ASE_AWK_RUN_H_ -#define _ASE_AWK_RUN_H_ - -#ifndef _ASE_AWK_AWK_H_ -#error Never include this file directly. Include instead -#endif - -enum ase_awk_assop_type_t -{ - /* if you change this, you have to change __assop_str in tree.c */ - ASE_AWK_ASSOP_NONE, - ASE_AWK_ASSOP_PLUS, /* += */ - ASE_AWK_ASSOP_MINUS, /* -= */ - ASE_AWK_ASSOP_MUL, /* *= */ - ASE_AWK_ASSOP_DIV, /* /= */ - ASE_AWK_ASSOP_IDIV, /* //= */ - ASE_AWK_ASSOP_MOD, /* %= */ - ASE_AWK_ASSOP_EXP /* **= */ -}; - -enum ase_awk_binop_type_t -{ - /* if you change this, you have to change - * __binop_str in tree.c and __binop_func in run.c accordingly. */ - ASE_AWK_BINOP_LOR, - ASE_AWK_BINOP_LAND, - ASE_AWK_BINOP_IN, - - ASE_AWK_BINOP_BOR, - ASE_AWK_BINOP_BXOR, - ASE_AWK_BINOP_BAND, - - ASE_AWK_BINOP_EQ, - ASE_AWK_BINOP_NE, - ASE_AWK_BINOP_GT, - ASE_AWK_BINOP_GE, - ASE_AWK_BINOP_LT, - ASE_AWK_BINOP_LE, - - ASE_AWK_BINOP_LSHIFT, - ASE_AWK_BINOP_RSHIFT, - - ASE_AWK_BINOP_PLUS, - ASE_AWK_BINOP_MINUS, - ASE_AWK_BINOP_MUL, - ASE_AWK_BINOP_DIV, - ASE_AWK_BINOP_IDIV, - ASE_AWK_BINOP_MOD, - ASE_AWK_BINOP_EXP, - - ASE_AWK_BINOP_CONCAT, - ASE_AWK_BINOP_MA, - ASE_AWK_BINOP_NM -}; - -enum ase_awk_unrop_type_t -{ - /* if you change this, you have to change - * __unrop_str in tree.c accordingly. */ - ASE_AWK_UNROP_PLUS, - ASE_AWK_UNROP_MINUS, - ASE_AWK_UNROP_NOT, - ASE_AWK_UNROP_BNOT -}; - -enum ase_awk_incop_type_t -{ - /* if you change this, you have to change - * __incop_str in tree.c accordingly. */ - ASE_AWK_INCOP_PLUS, - ASE_AWK_INCOP_MINUS -}; - -enum ase_awk_global_id_t -{ - /* this table should match __bvtab in parse.c. - * in addition, ase_awk_setglobal also counts - * on the order of these values */ - - ASE_AWK_GLOBAL_ARGC, - ASE_AWK_GLOBAL_ARGV, - ASE_AWK_GLOBAL_CONVFMT, - ASE_AWK_GLOBAL_ENVIRON, - ASE_AWK_GLOBAL_FILENAME, - ASE_AWK_GLOBAL_FNR, - ASE_AWK_GLOBAL_FS, - ASE_AWK_GLOBAL_IGNORECASE, - ASE_AWK_GLOBAL_NF, - ASE_AWK_GLOBAL_NR, - ASE_AWK_GLOBAL_OFILENAME, - ASE_AWK_GLOBAL_OFMT, - ASE_AWK_GLOBAL_OFS, - ASE_AWK_GLOBAL_ORS, - ASE_AWK_GLOBAL_RLENGTH, - ASE_AWK_GLOBAL_RS, - ASE_AWK_GLOBAL_RSTART, - ASE_AWK_GLOBAL_SUBSEP -}; - -#ifdef __cplusplus -extern "C" { -#endif - -ase_char_t* ase_awk_format ( - ase_awk_run_t* run, ase_str_t* out, ase_str_t* fbu, - const ase_char_t* fmt, ase_size_t fmt_len, - ase_size_t nargs_on_stack, ase_awk_nde_t* args, ase_size_t* len); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ase/awk/tab.c b/ase/awk/tab.c deleted file mode 100644 index 42d77089..00000000 --- a/ase/awk/tab.c +++ /dev/null @@ -1,239 +0,0 @@ -/* - * $Id: tab.c,v 1.1.1.1 2007/03/28 14:05:20 bacon Exp $ - * - * {License} - */ - -#include - -ase_awk_tab_t* ase_awk_tab_open (ase_awk_tab_t* tab, ase_awk_t* awk) -{ - if (tab == ASE_NULL) - { - tab = (ase_awk_tab_t*) ASE_AWK_MALLOC ( - awk, ASE_SIZEOF(ase_awk_tab_t)); - if (tab == ASE_NULL) return ASE_NULL; - tab->__dynamic = ase_true; - } - else tab->__dynamic = ase_false; - - tab->awk = awk; - tab->buf = ASE_NULL; - tab->size = 0; - tab->capa = 0; - - return tab; -} - -void ase_awk_tab_close (ase_awk_tab_t* tab) -{ - ase_awk_tab_clear (tab); - if (tab->buf != ASE_NULL) - { - ASE_AWK_FREE (tab->awk, tab->buf); - tab->buf = ASE_NULL; - tab->capa = 0; - } - - if (tab->__dynamic) ASE_AWK_FREE (tab->awk, tab); -} - -ase_size_t ase_awk_tab_getsize (ase_awk_tab_t* tab) -{ - return tab->size; -} - -ase_size_t ase_awk_tab_getcapa (ase_awk_tab_t* tab) -{ - return tab->capa; -} - -ase_awk_tab_t* ase_awk_tab_setcapa (ase_awk_tab_t* tab, ase_size_t capa) -{ - void* tmp; - - if (tab->size > capa) - { - ase_awk_tab_remove (tab, capa, tab->size - capa); - ASE_ASSERT (tab->size <= capa); - } - - if (capa > 0) - { - if (tab->awk->prmfns.mmgr.realloc != ASE_NULL) - { - tmp = ASE_AWK_REALLOC (tab->awk, - tab->buf, ASE_SIZEOF(*tab->buf) * capa); - if (tmp == ASE_NULL) return ASE_NULL; - } - else - { - tmp = ASE_AWK_MALLOC ( - tab->awk, ASE_SIZEOF(*tab->buf) * capa); - if (tmp == ASE_NULL) return ASE_NULL; - if (tab->buf != ASE_NULL) - { - ase_size_t x; - x = (capa > tab->capa)? tab->capa: capa; - ase_memcpy ( - tmp, tab->buf, - ASE_SIZEOF(*tab->buf) * x); - ASE_AWK_FREE (tab->awk, tab->buf); - } - } - } - else - { - if (tab->buf != ASE_NULL) ASE_AWK_FREE (tab->awk, tab->buf); - tmp = ASE_NULL; - } - - tab->buf = tmp; - tab->capa = capa; - - return tab; -} - -void ase_awk_tab_clear (ase_awk_tab_t* tab) -{ - ase_size_t i; - - for (i = 0; i < tab->size; i++) - { - ASE_AWK_FREE (tab->awk, tab->buf[i].name); - tab->buf[i].name = ASE_NULL; - tab->buf[i].name_len = 0; - } - - tab->size = 0; -} - - -ase_size_t ase_awk_tab_insert ( - ase_awk_tab_t* tab, ase_size_t index, - const ase_char_t* str, ase_size_t len) -{ - ase_size_t i; - ase_char_t* str_dup; - - str_dup = ase_strxdup (str, len, &tab->awk->prmfns.mmgr); - if (str_dup == ASE_NULL) return (ase_size_t)-1; - - if (index >= tab->capa) - { - ase_size_t capa; - - if (tab->capa <= 0) capa = (index + 1); - else - { - do { capa = tab->capa * 2; } while (index >= capa); - } - - if (ase_awk_tab_setcapa(tab,capa) == ASE_NULL) - { - ASE_AWK_FREE (tab->awk, str_dup); - return (ase_size_t)-1; - } - } - - for (i = tab->size; i > index; i--) tab->buf[i] = tab->buf[i-1]; - tab->buf[index].name = str_dup; - tab->buf[index].name_len = len; - - if (index > tab->size) tab->size = index + 1; - else tab->size++; - - return index; -} - -ase_size_t ase_awk_tab_remove ( - ase_awk_tab_t* tab, ase_size_t index, ase_size_t count) -{ - ase_size_t i, j, k; - - if (index >= tab->size) return 0; - if (count > tab->size - index) count = tab->size - index; - - i = index; - j = index + count; - k = index + count; - - while (i < k) - { - ASE_AWK_FREE (tab->awk, tab->buf[i].name); - - if (j >= tab->size) - { - tab->buf[i].name = ASE_NULL; - tab->buf[i].name_len = 0; - i++; - } - else - { - tab->buf[i].name = tab->buf[j].name; - tab->buf[i].name_len = tab->buf[j].name_len; - i++; j++; - } - } - - tab->size -= count; - return count; -} - -ase_size_t ase_awk_tab_add ( - ase_awk_tab_t* tab, const ase_char_t* str, ase_size_t len) -{ - return ase_awk_tab_insert (tab, tab->size, str, len); -} - -ase_size_t ase_awk_tab_find ( - ase_awk_tab_t* tab, ase_size_t index, - const ase_char_t* str, ase_size_t len) -{ - ase_size_t i; - - for (i = index; i < tab->size; i++) - { - if (ase_strxncmp ( - tab->buf[i].name, tab->buf[i].name_len, - str, len) == 0) return i; - } - - return (ase_size_t)-1; -} - -ase_size_t ase_awk_tab_rfind ( - ase_awk_tab_t* tab, ase_size_t index, - const ase_char_t* str, ase_size_t len) -{ - ase_size_t i; - - if (index >= tab->size) return (ase_size_t)-1; - - for (i = index + 1; i-- > 0; ) - { - if (ase_strxncmp ( - tab->buf[i].name, tab->buf[i].name_len, - str, len) == 0) return i; - } - - return (ase_size_t)-1; -} - -ase_size_t ase_awk_tab_rrfind ( - ase_awk_tab_t* tab, ase_size_t index, - const ase_char_t* str, ase_size_t len) -{ - ase_size_t i; - - if (index >= tab->size) return (ase_size_t)-1; - - for (i = tab->size - index; i-- > 0; ) - { - if (ase_strxncmp ( - tab->buf[i].name, tab->buf[i].name_len, - str, len) == 0) return i; - } - - return (ase_size_t)-1; -} diff --git a/ase/awk/tab.h b/ase/awk/tab.h deleted file mode 100644 index 3e5e4277..00000000 --- a/ase/awk/tab.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * $Id: tab.h,v 1.1.1.1 2007/03/28 14:05:20 bacon Exp $ - * - * {License} - */ - -#ifndef _ASE_AWK_TAB_H_ -#define _ASE_AWK_TAB_H_ - -#ifndef _ASE_AWK_AWK_H_ -#error Never include this file directly. Include instead -#endif - -/* TODO: you have to turn this into a hash table. - as of now, this is an arrayed table. */ - -typedef struct ase_awk_tab_t ase_awk_tab_t; - -struct ase_awk_tab_t -{ - struct - { - ase_char_t* name; - ase_size_t name_len; - }* buf; - ase_size_t size; - ase_size_t capa; - ase_awk_t* awk; - ase_bool_t __dynamic; -}; - -#ifdef __cplusplus -extern "C" { -#endif - -ase_awk_tab_t* ase_awk_tab_open (ase_awk_tab_t* tab, ase_awk_t* awk); -void ase_awk_tab_close (ase_awk_tab_t* tab); - -ase_size_t ase_awk_tab_getsize (ase_awk_tab_t* tab); -ase_size_t ase_awk_tab_getcapa (ase_awk_tab_t* tab); -ase_awk_tab_t* ase_awk_tab_setcapa (ase_awk_tab_t* tab, ase_size_t capa); - -void ase_awk_tab_clear (ase_awk_tab_t* tab); - -ase_size_t ase_awk_tab_insert ( - ase_awk_tab_t* tab, ase_size_t index, - const ase_char_t* str, ase_size_t len); - -ase_size_t ase_awk_tab_remove ( - ase_awk_tab_t* tab, ase_size_t index, ase_size_t count); - -ase_size_t ase_awk_tab_add ( - ase_awk_tab_t* tab, const ase_char_t* str, ase_size_t len); - -ase_size_t ase_awk_tab_find ( - ase_awk_tab_t* tab, ase_size_t index, - const ase_char_t* str, ase_size_t len); -ase_size_t ase_awk_tab_rfind ( - ase_awk_tab_t* tab, ase_size_t index, - const ase_char_t* str, ase_size_t len); -ase_size_t ase_awk_tab_rrfind ( - ase_awk_tab_t* tab, ase_size_t index, - const ase_char_t* str, ase_size_t len); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ase/awk/tree.c b/ase/awk/tree.c deleted file mode 100644 index bee3c13f..00000000 --- a/ase/awk/tree.c +++ /dev/null @@ -1,1176 +0,0 @@ -/* - * $Id: tree.c,v 1.1.1.1 2007/03/28 14:05:20 bacon Exp $ - * - * {License} - */ - -#include - -static const ase_char_t* assop_str[] = -{ - ASE_T("="), - ASE_T("+="), - ASE_T("-="), - ASE_T("*="), - ASE_T("/="), - ASE_T("//="), - ASE_T("%="), - ASE_T("**=") -}; - -static const ase_char_t* binop_str[] = -{ - ASE_T("||"), - ASE_T("&&"), - ASE_T("in"), - - ASE_T("|"), - ASE_T("^"), - ASE_T("&"), - - ASE_T("=="), - ASE_T("!="), - ASE_T(">"), - ASE_T(">="), - ASE_T("<"), - ASE_T("<="), - - ASE_T("<<"), - ASE_T(">>"), - - ASE_T("+"), - ASE_T("-"), - ASE_T("*"), - ASE_T("/"), - ASE_T("//"), - ASE_T("%"), - ASE_T("**"), - - ASE_T(" "), - ASE_T("~"), - ASE_T("!~") -}; - -static const ase_char_t* unrop_str[] = -{ - ASE_T("+"), - ASE_T("-"), - ASE_T("!"), - ASE_T("~") -}; - -static const ase_char_t* incop_str[] = -{ - ASE_T("++"), - ASE_T("--"), - ASE_T("++"), - ASE_T("--") -}; - -static const ase_char_t* getline_inop_str[] = -{ - ASE_T("|"), - ASE_T("|&"), - ASE_T("<"), - ASE_T("") -}; - -static const ase_char_t* print_outop_str[] = -{ - ASE_T("|"), - ASE_T("|&"), - ASE_T(">"), - ASE_T(">>"), - ASE_T("") -}; - -#define PUT_SRCSTR(awk,str) \ - do { if (ase_awk_putsrcstr (awk, str) == -1) return -1; } while (0) - -#define PUT_NEWLINE(awk) \ - do { \ - if (awk->option & ASE_AWK_CRLF) PUT_SRCSTR (awk, ASE_T("\r")); \ - PUT_SRCSTR (awk, ASE_T("\n")); \ - } while (0) - -#define PUT_SRCSTRX(awk,str,len) \ - do { if (ase_awk_putsrcstrx (awk, str, len) == -1) return -1; } while (0) - -#define PRINT_TABS(awk,depth) \ - do { if (print_tabs(awk,depth) == -1) return -1; } while (0) - -#define PRINT_EXPRESSION(awk,nde) \ - do { if (print_expression(awk,nde) == -1) return -1; } while (0) - -#define PRINT_EXPRESSION_LIST(awk,nde) \ - do { if (print_expression_list(awk,nde) == -1) return -1; } while (0) - -#define PRINT_STATEMENTS(awk,nde,depth) \ - do { if (print_statements(awk,nde,depth) == -1) return -1; } while (0) - -static int print_tabs (ase_awk_t* awk, int depth); -static int print_expression (ase_awk_t* awk, ase_awk_nde_t* nde); -static int print_expression_list (ase_awk_t* awk, ase_awk_nde_t* tree); -static int print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth); - -static int print_tabs (ase_awk_t* awk, int depth) -{ - while (depth > 0) - { - PUT_SRCSTR (awk, ASE_T("\t")); - depth--; - } - - return 0; -} - -static int print_expression (ase_awk_t* awk, ase_awk_nde_t* nde) -{ - switch (nde->type) - { - case ASE_AWK_NDE_GRP: - { - ase_awk_nde_t* p = ((ase_awk_nde_grp_t*)nde)->body; - - PUT_SRCSTR (awk, ASE_T("(")); - while (p != ASE_NULL) - { - PRINT_EXPRESSION (awk, p); - if (p->next != ASE_NULL) - PUT_SRCSTR (awk, ASE_T(",")); - p = p->next; - } - PUT_SRCSTR (awk, ASE_T(")")); - break; - } - - case ASE_AWK_NDE_ASS: - { - ase_awk_nde_ass_t* px = (ase_awk_nde_ass_t*)nde; - - PRINT_EXPRESSION (awk, px->left); - PUT_SRCSTR (awk, ASE_T(" ")); - PUT_SRCSTR (awk, assop_str[px->opcode]); - PUT_SRCSTR (awk, ASE_T(" ")); - PRINT_EXPRESSION (awk, px->right); - - ASE_ASSERT (px->right->next == ASE_NULL); - break; - } - - case ASE_AWK_NDE_EXP_BIN: - { - ase_awk_nde_exp_t* px = (ase_awk_nde_exp_t*)nde; - - PUT_SRCSTR (awk, ASE_T("(")); - PRINT_EXPRESSION (awk, px->left); - ASE_ASSERT (px->left->next == ASE_NULL); - - PUT_SRCSTR (awk, ASE_T(" ")); - PUT_SRCSTR (awk, binop_str[px->opcode]); - PUT_SRCSTR (awk, ASE_T(" ")); - - if (px->right->type == ASE_AWK_NDE_ASS) - PUT_SRCSTR (awk, ASE_T("(")); - PRINT_EXPRESSION (awk, px->right); - if (px->right->type == ASE_AWK_NDE_ASS) - PUT_SRCSTR (awk, ASE_T(")")); - ASE_ASSERT (px->right->next == ASE_NULL); - PUT_SRCSTR (awk, ASE_T(")")); - break; - } - - case ASE_AWK_NDE_EXP_UNR: - { - ase_awk_nde_exp_t* px = (ase_awk_nde_exp_t*)nde; - ASE_ASSERT (px->right == ASE_NULL); - - PUT_SRCSTR (awk, ASE_T("(")); - PUT_SRCSTR (awk, unrop_str[px->opcode]); - PUT_SRCSTR (awk, ASE_T("(")); - PRINT_EXPRESSION (awk, px->left); - PUT_SRCSTR (awk, ASE_T(")")); - PUT_SRCSTR (awk, ASE_T(")")); - break; - } - - case ASE_AWK_NDE_EXP_INCPRE: - { - ase_awk_nde_exp_t* px = (ase_awk_nde_exp_t*)nde; - ASE_ASSERT (px->right == ASE_NULL); - - PUT_SRCSTR (awk, incop_str[px->opcode]); - PUT_SRCSTR (awk, ASE_T("(")); - PRINT_EXPRESSION (awk, px->left); - PUT_SRCSTR (awk, ASE_T(")")); - break; - } - - case ASE_AWK_NDE_EXP_INCPST: - { - ase_awk_nde_exp_t* px = (ase_awk_nde_exp_t*)nde; - ASE_ASSERT (px->right == ASE_NULL); - - PUT_SRCSTR (awk, ASE_T("(")); - PRINT_EXPRESSION (awk, px->left); - PUT_SRCSTR (awk, ASE_T(")")); - PUT_SRCSTR (awk, incop_str[px->opcode]); - break; - } - - case ASE_AWK_NDE_CND: - { - ase_awk_nde_cnd_t* px = (ase_awk_nde_cnd_t*)nde; - - PUT_SRCSTR (awk, ASE_T("(")); - PRINT_EXPRESSION (awk, px->test); - PUT_SRCSTR (awk, ASE_T(")?")); - - PRINT_EXPRESSION (awk, px->left); - PUT_SRCSTR (awk, ASE_T(":")); - PRINT_EXPRESSION (awk, px->right); - break; - } - - case ASE_AWK_NDE_INT: - { - if (((ase_awk_nde_int_t*)nde)->str == ASE_NULL) - { - ase_size_t n; - - n = ase_awk_longtostr ( - ((ase_awk_nde_int_t*)nde)->val, 10, ASE_NULL, - awk->tmp.fmt, ASE_COUNTOF(awk->tmp.fmt)); - - PUT_SRCSTRX (awk, awk->tmp.fmt, n); - } - else - { - PUT_SRCSTRX (awk, - ((ase_awk_nde_int_t*)nde)->str, - ((ase_awk_nde_int_t*)nde)->len); - } - break; - } - - case ASE_AWK_NDE_REAL: - { - if (((ase_awk_nde_real_t*)nde)->str == ASE_NULL) - { - #if (ASE_SIZEOF_LONG_DOUBLE != 0) - awk->prmfns.misc.sprintf ( - awk->prmfns.misc.custom_data, - awk->tmp.fmt, ASE_COUNTOF(awk->tmp.fmt), ASE_T("%Lf"), - (long double)((ase_awk_nde_real_t*)nde)->val); - #elif (ASE_SIZEOF_DOUBLE != 0) - awk->prmfns.misc.sprintf ( - awk->prmfns.misc.custom_data, - awk->tmp.fmt, ASE_COUNTOF(awk->tmp.fmt), ASE_T("%f"), - (double)((ase_awk_nde_real_t*)nde)->val); - #else - #error unsupported floating-point data type - #endif - PUT_SRCSTR (awk, awk->tmp.fmt); - } - else - { - PUT_SRCSTRX (awk, - ((ase_awk_nde_real_t*)nde)->str, - ((ase_awk_nde_real_t*)nde)->len); - } - break; - } - - case ASE_AWK_NDE_STR: - { - ase_char_t* ptr; - ase_size_t len, i; - - PUT_SRCSTR (awk, ASE_T("\"")); - - ptr = ((ase_awk_nde_str_t*)nde)->buf; - len = ((ase_awk_nde_str_t*)nde)->len; - for (i = 0; i < len; i++) - { - /* TODO: maybe more de-escaping?? */ - if (ptr[i] == ASE_T('\n')) - PUT_SRCSTR (awk, ASE_T("\\n")); - else if (ptr[i] == ASE_T('\r')) - PUT_SRCSTR (awk, ASE_T("\\r")); - else if (ptr[i] == ASE_T('\f')) - PUT_SRCSTR (awk, ASE_T("\\f")); - else if (ptr[i] == ASE_T('\b')) - PUT_SRCSTR (awk, ASE_T("\\b")); - else if (ptr[i] == ASE_T('\v')) - PUT_SRCSTR (awk, ASE_T("\\v")); - else if (ptr[i] == ASE_T('\a')) - PUT_SRCSTR (awk, ASE_T("\\a")); - else if (ptr[i] == ASE_T('\0')) - PUT_SRCSTR (awk, ASE_T("\\0")); - else - PUT_SRCSTRX (awk, &ptr[i], 1); - } - PUT_SRCSTR (awk, ASE_T("\"")); - break; - } - - case ASE_AWK_NDE_REX: - { - PUT_SRCSTR (awk, ASE_T("/")); - PUT_SRCSTRX (awk, - ((ase_awk_nde_rex_t*)nde)->buf, - ((ase_awk_nde_rex_t*)nde)->len); - PUT_SRCSTR (awk, ASE_T("/")); - break; - } - - case ASE_AWK_NDE_ARG: - { - ase_char_t tmp[ASE_SIZEOF(ase_long_t)*8+2]; - ase_size_t n; - ase_awk_nde_var_t* px = (ase_awk_nde_var_t*)nde; - ASE_ASSERT (px->id.idxa != (ase_size_t)-1); - - n = ase_awk_longtostr ( - px->id.idxa, 10, ASE_NULL, tmp, ASE_COUNTOF(tmp)); - - PUT_SRCSTR (awk, ASE_T("__param")); - PUT_SRCSTRX (awk, tmp, n); - - ASE_ASSERT (px->idx == ASE_NULL); - break; - } - - case ASE_AWK_NDE_ARGIDX: - { - ase_size_t n; - ase_awk_nde_var_t* px = (ase_awk_nde_var_t*)nde; - ASE_ASSERT (px->id.idxa != (ase_size_t)-1); - ASE_ASSERT (px->idx != ASE_NULL); - - PUT_SRCSTR (awk, ASE_T("__param")); - n = ase_awk_longtostr ( - px->id.idxa, 10, ASE_NULL, - awk->tmp.fmt, ASE_COUNTOF(awk->tmp.fmt)); - PUT_SRCSTRX (awk, awk->tmp.fmt, n); - PUT_SRCSTR (awk, ASE_T("[")); - PRINT_EXPRESSION_LIST (awk, px->idx); - PUT_SRCSTR (awk, ASE_T("]")); - break; - } - - case ASE_AWK_NDE_NAMED: - { - ase_awk_nde_var_t* px = (ase_awk_nde_var_t*)nde; - ASE_ASSERT (px->id.idxa == (ase_size_t)-1); - ASE_ASSERT (px->idx == ASE_NULL); - - PUT_SRCSTRX (awk, px->id.name, px->id.name_len); - break; - } - - case ASE_AWK_NDE_NAMEDIDX: - { - ase_awk_nde_var_t* px = (ase_awk_nde_var_t*)nde; - ASE_ASSERT (px->id.idxa == (ase_size_t)-1); - ASE_ASSERT (px->idx != ASE_NULL); - - PUT_SRCSTRX (awk, px->id.name, px->id.name_len); - PUT_SRCSTR (awk, ASE_T("[")); - PRINT_EXPRESSION_LIST (awk, px->idx); - PUT_SRCSTR (awk, ASE_T("]")); - break; - } - - case ASE_AWK_NDE_GLOBAL: - { - /*ase_char_t tmp[ASE_SIZEOF(ase_long_t)*8+2]; - ase_size_t n;*/ - ase_awk_nde_var_t* px = (ase_awk_nde_var_t*)nde; - - if (px->id.idxa != (ase_size_t)-1) - { - /* - PUT_SRCSTR (awk, ASE_T("__global")); - n = ase_awk_longtostr ( - px->id.idxa, 10, - ASE_NULL, tmp, ASE_COUNTOF(tmp)); - PUT_SRCSTRX (awk, tmp, n); - */ - PUT_SRCSTRX (awk, px->id.name, px->id.name_len); - } - else - { - PUT_SRCSTRX (awk, px->id.name, px->id.name_len); - } - ASE_ASSERT (px->idx == ASE_NULL); - break; - } - - case ASE_AWK_NDE_GLOBALIDX: - { - /*ase_char_t tmp[ASE_SIZEOF(ase_long_t)*8+2]; - ase_size_t n;*/ - ase_awk_nde_var_t* px = (ase_awk_nde_var_t*)nde; - - if (px->id.idxa != (ase_size_t)-1) - { - /* - PUT_SRCSTR (awk, ASE_T("__global")); - n = ase_awk_longtostr ( - px->id.idxa, 10, - ASE_NULL, tmp, ASE_COUNTOF(tmp)); - PUT_SRCSTRX (awk, tmp, n); - */ - PUT_SRCSTRX (awk, px->id.name, px->id.name_len); - PUT_SRCSTR (awk, ASE_T("[")); - } - else - { - PUT_SRCSTRX (awk, px->id.name, px->id.name_len); - PUT_SRCSTR (awk, ASE_T("[")); - } - ASE_ASSERT (px->idx != ASE_NULL); - PRINT_EXPRESSION_LIST (awk, px->idx); - PUT_SRCSTR (awk, ASE_T("]")); - break; - } - - case ASE_AWK_NDE_LOCAL: - { - ase_size_t n; - ase_awk_nde_var_t* px = (ase_awk_nde_var_t*)nde; - - if (px->id.idxa != (ase_size_t)-1) - { - PUT_SRCSTR (awk, ASE_T("__local")); - n = ase_awk_longtostr ( - px->id.idxa, 10, ASE_NULL, - awk->tmp.fmt, ASE_COUNTOF(awk->tmp.fmt)); - PUT_SRCSTRX (awk, awk->tmp.fmt, n); - } - else - { - PUT_SRCSTRX (awk, px->id.name, px->id.name_len); - } - ASE_ASSERT (px->idx == ASE_NULL); - break; - } - - case ASE_AWK_NDE_LOCALIDX: - { - ase_size_t n; - ase_awk_nde_var_t* px = (ase_awk_nde_var_t*)nde; - - if (px->id.idxa != (ase_size_t)-1) - { - PUT_SRCSTR (awk, ASE_T("__local")); - n = ase_awk_longtostr ( - px->id.idxa, 10, ASE_NULL, - awk->tmp.fmt, ASE_COUNTOF(awk->tmp.fmt)); - PUT_SRCSTRX (awk, awk->tmp.fmt, n); - PUT_SRCSTR (awk, ASE_T("[")); - } - else - { - PUT_SRCSTRX (awk, px->id.name, px->id.name_len); - PUT_SRCSTR (awk, ASE_T("[")); - } - ASE_ASSERT (px->idx != ASE_NULL); - PRINT_EXPRESSION_LIST (awk, px->idx); - PUT_SRCSTR (awk, ASE_T("]")); - break; - } - - case ASE_AWK_NDE_POS: - { - PUT_SRCSTR (awk, ASE_T("$")); - PRINT_EXPRESSION (awk, ((ase_awk_nde_pos_t*)nde)->val); - break; - } - - case ASE_AWK_NDE_BFN: - { - ase_awk_nde_call_t* px = (ase_awk_nde_call_t*)nde; - PUT_SRCSTRX (awk, - px->what.bfn.name.ptr, px->what.bfn.name.len); - PUT_SRCSTR (awk, ASE_T(" (")); - PRINT_EXPRESSION_LIST (awk, px->args); - PUT_SRCSTR (awk, ASE_T(")")); - break; - } - - case ASE_AWK_NDE_AFN: - { - ase_awk_nde_call_t* px = (ase_awk_nde_call_t*)nde; - PUT_SRCSTRX (awk, - px->what.afn.name.ptr, px->what.afn.name.len); - PUT_SRCSTR (awk, ASE_T(" (")); - PRINT_EXPRESSION_LIST (awk, px->args); - PUT_SRCSTR (awk, ASE_T(")")); - break; - } - - case ASE_AWK_NDE_GETLINE: - { - ase_awk_nde_getline_t* px = (ase_awk_nde_getline_t*)nde; - if (px->in != ASE_NULL && - (px->in_type == ASE_AWK_IN_PIPE || - px->in_type == ASE_AWK_IN_COPROC)) - { - PRINT_EXPRESSION (awk, px->in); - PUT_SRCSTR (awk, ASE_T(" ")); - PUT_SRCSTR (awk, getline_inop_str[px->in_type]); - PUT_SRCSTR (awk, ASE_T(" ")); - } - - PUT_SRCSTR (awk, ASE_T("getline")); - if (px->var != ASE_NULL) - { - PUT_SRCSTR (awk, ASE_T(" ")); - PRINT_EXPRESSION (awk, px->var); - } - - if (px->in != ASE_NULL && - px->in_type == ASE_AWK_IN_FILE) - { - PUT_SRCSTR (awk, ASE_T(" ")); - PUT_SRCSTR (awk, getline_inop_str[px->in_type]); - PUT_SRCSTR (awk, ASE_T(" ")); - PRINT_EXPRESSION (awk, px->in); - } - break; - } - - default: - { - return -1; - } - } - - return 0; -} - -static int print_expression_list (ase_awk_t* awk, ase_awk_nde_t* tree) -{ - ase_awk_nde_t* p = tree; - - while (p != ASE_NULL) - { - PRINT_EXPRESSION (awk, p); - p = p->next; - if (p != ASE_NULL) PUT_SRCSTR (awk, ASE_T(",")); - } - - return 0; -} - -static int print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth) -{ - ase_awk_nde_t* p = tree; - ase_size_t i; - - while (p != ASE_NULL) - { - - switch (p->type) - { - case ASE_AWK_NDE_NULL: - { - PRINT_TABS (awk, depth); - PUT_SRCSTR (awk, ASE_T(";")); - PUT_NEWLINE (awk); - break; - } - - case ASE_AWK_NDE_BLK: - { - ase_size_t n; - ase_awk_nde_blk_t* px = (ase_awk_nde_blk_t*)p; - - PRINT_TABS (awk, depth); - PUT_SRCSTR (awk, ASE_T("{")); - PUT_NEWLINE (awk); - - if (px->nlocals > 0) - { - PRINT_TABS (awk, depth + 1); - PUT_SRCSTR (awk, ASE_T("local ")); - - for (i = 0; i < px->nlocals - 1; i++) - { - PUT_SRCSTR (awk, ASE_T("__local")); - n = ase_awk_longtostr ( - i, 10, ASE_NULL, - awk->tmp.fmt, ASE_COUNTOF(awk->tmp.fmt)); - PUT_SRCSTRX (awk, awk->tmp.fmt, n); - PUT_SRCSTR (awk, ASE_T(", ")); - } - - PUT_SRCSTR (awk, ASE_T("__local")); - n = ase_awk_longtostr ( - i, 10, ASE_NULL, - awk->tmp.fmt, ASE_COUNTOF(awk->tmp.fmt)); - PUT_SRCSTRX (awk, awk->tmp.fmt, n); - PUT_SRCSTR (awk, ASE_T(";")); - PUT_NEWLINE (awk); - } - - PRINT_STATEMENTS (awk, px->body, depth + 1); - PRINT_TABS (awk, depth); - PUT_SRCSTR (awk, ASE_T("}")); - PUT_NEWLINE (awk); - break; - } - - case ASE_AWK_NDE_IF: - { - ase_awk_nde_if_t* px = (ase_awk_nde_if_t*)p; - - PRINT_TABS (awk, depth); - PUT_SRCSTR (awk, ASE_T("if (")); - PRINT_EXPRESSION (awk, px->test); - PUT_SRCSTR (awk, ASE_T(")")); - PUT_NEWLINE (awk); - - ASE_ASSERT (px->then_part != ASE_NULL); - if (px->then_part->type == ASE_AWK_NDE_BLK) - PRINT_STATEMENTS (awk, px->then_part, depth); - else - PRINT_STATEMENTS (awk, px->then_part, depth + 1); - - if (px->else_part != ASE_NULL) - { - PRINT_TABS (awk, depth); - PUT_SRCSTR (awk, ASE_T("else")); - PUT_NEWLINE (awk); - if (px->else_part->type == ASE_AWK_NDE_BLK) - PRINT_STATEMENTS (awk, px->else_part, depth); - else - PRINT_STATEMENTS (awk, px->else_part, depth + 1); - } - break; - } - - case ASE_AWK_NDE_WHILE: - { - ase_awk_nde_while_t* px = (ase_awk_nde_while_t*)p; - - PRINT_TABS (awk, depth); - PUT_SRCSTR (awk, ASE_T("while (")); - PRINT_EXPRESSION (awk, px->test); - PUT_SRCSTR (awk, ASE_T(")")); - PUT_NEWLINE (awk); - if (px->body->type == ASE_AWK_NDE_BLK) - { - PRINT_STATEMENTS (awk, px->body, depth); - } - else - { - PRINT_STATEMENTS (awk, px->body, depth + 1); - } - break; - } - - case ASE_AWK_NDE_DOWHILE: - { - ase_awk_nde_while_t* px = (ase_awk_nde_while_t*)p; - - PRINT_TABS (awk, depth); - PUT_SRCSTR (awk, ASE_T("do")); - PUT_NEWLINE (awk); - if (px->body->type == ASE_AWK_NDE_BLK) - { - PRINT_STATEMENTS (awk, px->body, depth); - } - else - { - PRINT_STATEMENTS (awk, px->body, depth + 1); - } - - PRINT_TABS (awk, depth); - PUT_SRCSTR (awk, ASE_T("while (")); - PRINT_EXPRESSION (awk, px->test); - PUT_SRCSTR (awk, ASE_T(");")); - PUT_NEWLINE (awk); - break; - } - - case ASE_AWK_NDE_FOR: - { - ase_awk_nde_for_t* px = (ase_awk_nde_for_t*)p; - - PRINT_TABS (awk, depth); - PUT_SRCSTR (awk, ASE_T("for (")); - if (px->init != ASE_NULL) - { - PRINT_EXPRESSION (awk, px->init); - } - PUT_SRCSTR (awk, ASE_T("; ")); - if (px->test != ASE_NULL) - { - PRINT_EXPRESSION (awk, px->test); - } - PUT_SRCSTR (awk, ASE_T("; ")); - if (px->incr != ASE_NULL) - { - PRINT_EXPRESSION (awk, px->incr); - } - PUT_SRCSTR (awk, ASE_T(")")); - PUT_NEWLINE (awk); - - if (px->body->type == ASE_AWK_NDE_BLK) - { - PRINT_STATEMENTS (awk, px->body, depth); - } - else - { - PRINT_STATEMENTS (awk, px->body, depth + 1); - } - break; - } - - case ASE_AWK_NDE_FOREACH: - { - ase_awk_nde_foreach_t* px = (ase_awk_nde_foreach_t*)p; - - PRINT_TABS (awk, depth); - PUT_SRCSTR (awk, ASE_T("for ")); - PRINT_EXPRESSION (awk, px->test); - PUT_NEWLINE (awk); - if (px->body->type == ASE_AWK_NDE_BLK) - { - PRINT_STATEMENTS (awk, px->body, depth); - } - else - { - PRINT_STATEMENTS (awk, px->body, depth + 1); - } - break; - } - - case ASE_AWK_NDE_BREAK: - { - PRINT_TABS (awk, depth); - PUT_SRCSTR (awk, ASE_T("break;")); - PUT_NEWLINE (awk); - break; - } - - case ASE_AWK_NDE_CONTINUE: - { - PRINT_TABS (awk, depth); - PUT_SRCSTR (awk, ASE_T("continue;")); - PUT_NEWLINE (awk); - break; - } - - case ASE_AWK_NDE_RETURN: - { - PRINT_TABS (awk, depth); - if (((ase_awk_nde_return_t*)p)->val == ASE_NULL) - { - PUT_SRCSTR (awk, ASE_T("return;")); - PUT_NEWLINE (awk); - } - else - { - PUT_SRCSTR (awk, ASE_T("return ")); - ASE_ASSERT (((ase_awk_nde_return_t*)p)->val->next == ASE_NULL); - - PRINT_EXPRESSION (awk, ((ase_awk_nde_return_t*)p)->val); - PUT_SRCSTR (awk, ASE_T(";")); - PUT_NEWLINE (awk); - } - break; - } - - case ASE_AWK_NDE_EXIT: - { - ase_awk_nde_exit_t* px = (ase_awk_nde_exit_t*)p; - PRINT_TABS (awk, depth); - - if (px->val == ASE_NULL) - { - PUT_SRCSTR (awk, ASE_T("exit;")); - PUT_NEWLINE (awk); - } - else - { - PUT_SRCSTR (awk, ASE_T("exit ")); - ASE_ASSERT (px->val->next == ASE_NULL); - PRINT_EXPRESSION (awk, px->val); - PUT_SRCSTR (awk, ASE_T(";")); - PUT_NEWLINE (awk); - } - break; - } - - case ASE_AWK_NDE_NEXT: - { - PRINT_TABS (awk, depth); - PUT_SRCSTR (awk, ASE_T("next;")); - PUT_NEWLINE (awk); - break; - } - - case ASE_AWK_NDE_NEXTFILE: - { - PRINT_TABS (awk, depth); - PUT_SRCSTR (awk, ASE_T("nextfile;")); - PUT_NEWLINE (awk); - break; - } - - case ASE_AWK_NDE_DELETE: - { - PRINT_TABS (awk, depth); - PUT_SRCSTR (awk, ASE_T("delete ")); - ase_awk_prnpt (awk, ((ase_awk_nde_delete_t*)p)->var); - break; - } - - case ASE_AWK_NDE_PRINT: - case ASE_AWK_NDE_PRINTF: - { - ase_awk_nde_print_t* px = (ase_awk_nde_print_t*)p; - - PRINT_TABS (awk, depth); - - if (p->type == ASE_AWK_NDE_PRINT) - PUT_SRCSTR (awk, ASE_T("print")); - else PUT_SRCSTR (awk, ASE_T("printf")); - - if (px->args != ASE_NULL) - { - PUT_SRCSTR (awk, ASE_T(" ")); - PRINT_EXPRESSION_LIST (awk, px->args); - } - - if (px->out != ASE_NULL) - { - PUT_SRCSTR (awk, ASE_T(" ")); - PUT_SRCSTR (awk, print_outop_str[px->out_type]); - PUT_SRCSTR (awk, ASE_T(" ")); - PRINT_EXPRESSION (awk, px->out); - } - - PUT_SRCSTR (awk, ASE_T(";")); - PUT_NEWLINE (awk); - break; - } - - default: - { - PRINT_TABS (awk, depth); - PRINT_EXPRESSION (awk, p); - PUT_SRCSTR (awk, ASE_T(";")); - PUT_NEWLINE (awk); - } - } - - p = p->next; - } - - return 0; -} - -int ase_awk_prnpt (ase_awk_t* awk, ase_awk_nde_t* tree) -{ - return print_statements (awk, tree, 0); -} - -int ase_awk_prnptnpt (ase_awk_t* awk, ase_awk_nde_t* tree) -{ - ase_awk_nde_t* nde = tree; - - while (nde != ASE_NULL) - { - if (print_expression (awk, nde) == -1) return -1; - if (nde->next == ASE_NULL) break; - - PUT_SRCSTR (awk, ASE_T(",")); - nde = nde->next; - } - - return 0; -} - -void ase_awk_clrpt (ase_awk_t* awk, ase_awk_nde_t* tree) -{ - ase_awk_nde_t* p = tree; - ase_awk_nde_t* next; - - while (p != ASE_NULL) - { - next = p->next; - - switch (p->type) - { - case ASE_AWK_NDE_NULL: - { - ASE_AWK_FREE (awk, p); - break; - } - - case ASE_AWK_NDE_BLK: - { - ase_awk_clrpt (awk, ((ase_awk_nde_blk_t*)p)->body); - ASE_AWK_FREE (awk, p); - break; - } - - case ASE_AWK_NDE_IF: - { - ase_awk_nde_if_t* px = (ase_awk_nde_if_t*)p; - ase_awk_clrpt (awk, px->test); - ase_awk_clrpt (awk, px->then_part); - - if (px->else_part != ASE_NULL) - ase_awk_clrpt (awk, px->else_part); - ASE_AWK_FREE (awk, p); - break; - } - - case ASE_AWK_NDE_WHILE: - case ASE_AWK_NDE_DOWHILE: - { - ase_awk_clrpt (awk, ((ase_awk_nde_while_t*)p)->test); - ase_awk_clrpt (awk, ((ase_awk_nde_while_t*)p)->body); - ASE_AWK_FREE (awk, p); - break; - } - - case ASE_AWK_NDE_FOR: - { - ase_awk_nde_for_t* px = (ase_awk_nde_for_t*)p; - - if (px->init != ASE_NULL) - ase_awk_clrpt (awk, px->init); - if (px->test != ASE_NULL) - ase_awk_clrpt (awk, px->test); - if (px->incr != ASE_NULL) - ase_awk_clrpt (awk, px->incr); - ase_awk_clrpt (awk, px->body); - ASE_AWK_FREE (awk, p); - break; - } - - case ASE_AWK_NDE_FOREACH: - { - ase_awk_clrpt (awk, ((ase_awk_nde_foreach_t*)p)->test); - ase_awk_clrpt (awk, ((ase_awk_nde_foreach_t*)p)->body); - ASE_AWK_FREE (awk, p); - break; - } - - case ASE_AWK_NDE_BREAK: - { - ASE_AWK_FREE (awk, p); - break; - } - - case ASE_AWK_NDE_CONTINUE: - { - ASE_AWK_FREE (awk, p); - break; - } - - case ASE_AWK_NDE_RETURN: - { - ase_awk_nde_return_t* px = - (ase_awk_nde_return_t*)p; - if (px->val != ASE_NULL) - ase_awk_clrpt (awk, px->val); - ASE_AWK_FREE (awk, p); - break; - } - - case ASE_AWK_NDE_EXIT: - { - if (((ase_awk_nde_exit_t*)p)->val != ASE_NULL) - ase_awk_clrpt (awk, ((ase_awk_nde_exit_t*)p)->val); - ASE_AWK_FREE (awk, p); - break; - } - - case ASE_AWK_NDE_NEXT: - case ASE_AWK_NDE_NEXTFILE: - { - ASE_AWK_FREE (awk, p); - break; - } - - case ASE_AWK_NDE_DELETE: - { - ase_awk_clrpt (awk, ((ase_awk_nde_delete_t*)p)->var); - ASE_AWK_FREE (awk, p); - break; - } - - case ASE_AWK_NDE_PRINT: - case ASE_AWK_NDE_PRINTF: - { - ase_awk_nde_print_t* px = - (ase_awk_nde_print_t*)p; - if (px->args != ASE_NULL) - ase_awk_clrpt (awk, px->args); - if (px->out != ASE_NULL) - ase_awk_clrpt (awk, px->out); - ASE_AWK_FREE (awk, p); - break; - } - - case ASE_AWK_NDE_GRP: - { - ase_awk_clrpt (awk, ((ase_awk_nde_grp_t*)p)->body); - ASE_AWK_FREE (awk, p); - break; - } - - case ASE_AWK_NDE_ASS: - { - ase_awk_clrpt (awk, ((ase_awk_nde_ass_t*)p)->left); - ase_awk_clrpt (awk, ((ase_awk_nde_ass_t*)p)->right); - ASE_AWK_FREE (awk, p); - break; - } - - case ASE_AWK_NDE_EXP_BIN: - { - ase_awk_nde_exp_t* px = (ase_awk_nde_exp_t*)p; - ASE_ASSERT (px->left->next == ASE_NULL); - ASE_ASSERT (px->right->next == ASE_NULL); - - ase_awk_clrpt (awk, px->left); - ase_awk_clrpt (awk, px->right); - ASE_AWK_FREE (awk, p); - break; - } - - case ASE_AWK_NDE_EXP_UNR: - case ASE_AWK_NDE_EXP_INCPRE: - case ASE_AWK_NDE_EXP_INCPST: - { - ase_awk_nde_exp_t* px = (ase_awk_nde_exp_t*)p; - ASE_ASSERT (px->right == ASE_NULL); - ase_awk_clrpt (awk, px->left); - ASE_AWK_FREE (awk, p); - break; - } - - case ASE_AWK_NDE_CND: - { - ase_awk_clrpt (awk, ((ase_awk_nde_cnd_t*)p)->test); - ase_awk_clrpt (awk, ((ase_awk_nde_cnd_t*)p)->left); - ase_awk_clrpt (awk, ((ase_awk_nde_cnd_t*)p)->right); - ASE_AWK_FREE (awk, p); - break; - } - - case ASE_AWK_NDE_INT: - { - if (((ase_awk_nde_int_t*)p)->str != ASE_NULL) - ASE_AWK_FREE (awk, ((ase_awk_nde_int_t*)p)->str); - ASE_AWK_FREE (awk, p); - break; - } - - case ASE_AWK_NDE_REAL: - { - if (((ase_awk_nde_real_t*)p)->str != ASE_NULL) - ASE_AWK_FREE (awk, ((ase_awk_nde_real_t*)p)->str); - ASE_AWK_FREE (awk, p); - break; - } - - case ASE_AWK_NDE_STR: - { - ASE_AWK_FREE (awk, ((ase_awk_nde_str_t*)p)->buf); - ASE_AWK_FREE (awk, p); - break; - } - - case ASE_AWK_NDE_REX: - { - ASE_AWK_FREE (awk, ((ase_awk_nde_rex_t*)p)->buf); - ASE_AWK_FREE (awk, ((ase_awk_nde_rex_t*)p)->code); - ASE_AWK_FREE (awk, p); - break; - } - - case ASE_AWK_NDE_NAMED: - case ASE_AWK_NDE_GLOBAL: - case ASE_AWK_NDE_LOCAL: - case ASE_AWK_NDE_ARG: - { - ase_awk_nde_var_t* px = (ase_awk_nde_var_t*)p; - ASE_ASSERT (px->idx == ASE_NULL); - if (px->id.name != ASE_NULL) - ASE_AWK_FREE (awk, px->id.name); - ASE_AWK_FREE (awk, p); - break; - } - - case ASE_AWK_NDE_NAMEDIDX: - case ASE_AWK_NDE_GLOBALIDX: - case ASE_AWK_NDE_LOCALIDX: - case ASE_AWK_NDE_ARGIDX: - { - ase_awk_nde_var_t* px = (ase_awk_nde_var_t*)p; - ASE_ASSERT (px->idx != ASE_NULL); - ase_awk_clrpt (awk, px->idx); - if (px->id.name != ASE_NULL) - ASE_AWK_FREE (awk, px->id.name); - ASE_AWK_FREE (awk, p); - break; - } - - case ASE_AWK_NDE_POS: - { - ase_awk_clrpt (awk, ((ase_awk_nde_pos_t*)p)->val); - ASE_AWK_FREE (awk, p); - break; - } - - case ASE_AWK_NDE_BFN: - { - ase_awk_nde_call_t* px = (ase_awk_nde_call_t*)p; - /* ASE_AWK_FREE (awk, px->what.bfn); */ - ase_awk_clrpt (awk, px->args); - ASE_AWK_FREE (awk, p); - break; - } - - case ASE_AWK_NDE_AFN: - { - ase_awk_nde_call_t* px = (ase_awk_nde_call_t*)p; - ASE_AWK_FREE (awk, px->what.afn.name.ptr); - ase_awk_clrpt (awk, px->args); - ASE_AWK_FREE (awk, p); - break; - } - - case ASE_AWK_NDE_GETLINE: - { - ase_awk_nde_getline_t* px = - (ase_awk_nde_getline_t*)p; - if (px->var != ASE_NULL) - ase_awk_clrpt (awk, px->var); - if (px->in != ASE_NULL) - ase_awk_clrpt (awk, px->in); - ASE_AWK_FREE (awk, p); - break; - } - - default: - { - ASE_ASSERT (!"should never happen - invalid node type"); - ASE_AWK_FREE (awk, p); - break; - } - } - - p = next; - } -} diff --git a/ase/awk/tree.h b/ase/awk/tree.h deleted file mode 100644 index 5c13666b..00000000 --- a/ase/awk/tree.h +++ /dev/null @@ -1,403 +0,0 @@ -/* - * $Id: tree.h,v 1.1.1.1 2007/03/28 14:05:20 bacon Exp $ - * - * {License} - */ - -#ifndef _ASE_AWK_TREE_H_ -#define _ASE_AWK_TREE_H_ - -#ifndef _ASE_AWK_AWK_H_ -#error Never include this file directly. Include instead -#endif - -enum ase_awk_nde_type_t -{ - ASE_AWK_NDE_NULL, - - /* statement */ - ASE_AWK_NDE_BLK, - ASE_AWK_NDE_IF, - ASE_AWK_NDE_WHILE, - ASE_AWK_NDE_DOWHILE, - ASE_AWK_NDE_FOR, - ASE_AWK_NDE_FOREACH, - ASE_AWK_NDE_BREAK, - ASE_AWK_NDE_CONTINUE, - ASE_AWK_NDE_RETURN, - ASE_AWK_NDE_EXIT, - ASE_AWK_NDE_NEXT, - ASE_AWK_NDE_NEXTFILE, - ASE_AWK_NDE_DELETE, - ASE_AWK_NDE_PRINT, - ASE_AWK_NDE_PRINTF, - - /* expression */ - /* if you change the following values including their order, - * you should change __eval_func of __eval_expression - * in run.c accordingly */ - ASE_AWK_NDE_GRP, - ASE_AWK_NDE_ASS, - ASE_AWK_NDE_EXP_BIN, - ASE_AWK_NDE_EXP_UNR, - ASE_AWK_NDE_EXP_INCPRE, - ASE_AWK_NDE_EXP_INCPST, - ASE_AWK_NDE_CND, - ASE_AWK_NDE_BFN, - ASE_AWK_NDE_AFN, - ASE_AWK_NDE_INT, - ASE_AWK_NDE_REAL, - ASE_AWK_NDE_STR, - ASE_AWK_NDE_REX, - - /* keep this order for the following items otherwise, you may have - * to change __eval_incpre and __eval_incpst in run.c as well as - * ASE_AWK_VAL_REF_XXX in val.h */ - ASE_AWK_NDE_NAMED, - ASE_AWK_NDE_GLOBAL, - ASE_AWK_NDE_LOCAL, - ASE_AWK_NDE_ARG, - ASE_AWK_NDE_NAMEDIDX, - ASE_AWK_NDE_GLOBALIDX, - ASE_AWK_NDE_LOCALIDX, - ASE_AWK_NDE_ARGIDX, - ASE_AWK_NDE_POS, - /* ---------------------------------- */ - - ASE_AWK_NDE_GETLINE -}; - -enum ase_awk_in_type_t -{ - /* the order of these values match - * __in_type_map and __in_opt_map in extio.c */ - - ASE_AWK_IN_PIPE, - ASE_AWK_IN_COPROC, - ASE_AWK_IN_FILE, - ASE_AWK_IN_CONSOLE -}; - -enum ase_awk_out_type_t -{ - /* the order of these values match - * __out_type_map and __out_opt_map in extio.c */ - - ASE_AWK_OUT_PIPE, - ASE_AWK_OUT_COPROC, - ASE_AWK_OUT_FILE, - ASE_AWK_OUT_FILE_APPEND, - ASE_AWK_OUT_CONSOLE -}; - -/* afn (awk function defined with the keyword function) */ -typedef struct ase_awk_afn_t ase_awk_afn_t; -typedef struct ase_awk_nde_t ase_awk_nde_t; -typedef struct ase_awk_nde_blk_t ase_awk_nde_blk_t; -typedef struct ase_awk_nde_grp_t ase_awk_nde_grp_t; -typedef struct ase_awk_nde_ass_t ase_awk_nde_ass_t; -typedef struct ase_awk_nde_exp_t ase_awk_nde_exp_t; -typedef struct ase_awk_nde_cnd_t ase_awk_nde_cnd_t; -typedef struct ase_awk_nde_pos_t ase_awk_nde_pos_t; - -#ifndef ASE_AWK_NDE_INT_DEFINED -#define ASE_AWK_NDE_INT_DEFINED -typedef struct ase_awk_nde_int_t ase_awk_nde_int_t; -#endif - -#ifndef ASE_AWK_NDE_REAL_DEFINED -#define ASE_AWK_NDE_REAL_DEFINED -typedef struct ase_awk_nde_real_t ase_awk_nde_real_t; -#endif - -typedef struct ase_awk_nde_str_t ase_awk_nde_str_t; -typedef struct ase_awk_nde_rex_t ase_awk_nde_rex_t; -typedef struct ase_awk_nde_var_t ase_awk_nde_var_t; -typedef struct ase_awk_nde_call_t ase_awk_nde_call_t; -typedef struct ase_awk_nde_getline_t ase_awk_nde_getline_t; - -typedef struct ase_awk_nde_if_t ase_awk_nde_if_t; -typedef struct ase_awk_nde_while_t ase_awk_nde_while_t; -typedef struct ase_awk_nde_for_t ase_awk_nde_for_t; -typedef struct ase_awk_nde_foreach_t ase_awk_nde_foreach_t; -typedef struct ase_awk_nde_break_t ase_awk_nde_break_t; -typedef struct ase_awk_nde_continue_t ase_awk_nde_continue_t; -typedef struct ase_awk_nde_return_t ase_awk_nde_return_t; -typedef struct ase_awk_nde_exit_t ase_awk_nde_exit_t; -typedef struct ase_awk_nde_next_t ase_awk_nde_next_t; -typedef struct ase_awk_nde_nextfile_t ase_awk_nde_nextfile_t; -typedef struct ase_awk_nde_delete_t ase_awk_nde_delete_t; -typedef struct ase_awk_nde_print_t ase_awk_nde_print_t; - -struct ase_awk_afn_t -{ - ase_char_t* name; - ase_size_t name_len; - ase_size_t nargs; - ase_awk_nde_t* body; -}; - -#define ASE_AWK_NDE_HDR \ - int type; \ - ase_size_t line; \ - ase_awk_nde_t* next - -struct ase_awk_nde_t -{ - ASE_AWK_NDE_HDR; -}; - -/* ASE_AWK_NDE_BLK - block statement including top-level blocks */ -struct ase_awk_nde_blk_t -{ - ASE_AWK_NDE_HDR; - ase_size_t nlocals; - ase_awk_nde_t* body; -}; - -/* ASE_AWK_NDE_GRP - expression group */ -struct ase_awk_nde_grp_t -{ - ASE_AWK_NDE_HDR; - ase_awk_nde_t* body; -}; - -/* ASE_AWK_NDE_ASS - assignment */ -struct ase_awk_nde_ass_t -{ - ASE_AWK_NDE_HDR; - int opcode; - ase_awk_nde_t* left; - ase_awk_nde_t* right; -}; - -/* ASE_AWK_NDE_EXP_BIN, ASE_AWK_NDE_EXP_UNR, - * ASE_AWK_NDE_EXP_INCPRE, ASE_AW_NDE_EXP_INCPST */ -struct ase_awk_nde_exp_t -{ - ASE_AWK_NDE_HDR; - int opcode; - ase_awk_nde_t* left; - ase_awk_nde_t* right; /* ASE_NULL for UNR, INCPRE, INCPST */ -}; - -/* ASE_AWK_NDE_CND */ -struct ase_awk_nde_cnd_t -{ - ASE_AWK_NDE_HDR; - ase_awk_nde_t* test; - ase_awk_nde_t* left; - ase_awk_nde_t* right; -}; - -/* ASE_AWK_NDE_POS - positional - $1, $2, $x, etc */ -struct ase_awk_nde_pos_t -{ - ASE_AWK_NDE_HDR; - ase_awk_nde_t* val; -}; - -/* ASE_AWK_NDE_INT */ -struct ase_awk_nde_int_t -{ - ASE_AWK_NDE_HDR; - ase_long_t val; - ase_char_t* str; - ase_size_t len; -}; - -/* ASE_AWK_NDE_REAL */ -struct ase_awk_nde_real_t -{ - ASE_AWK_NDE_HDR; - ase_real_t val; - ase_char_t* str; - ase_size_t len; -}; - -/* ASE_AWK_NDE_STR */ -struct ase_awk_nde_str_t -{ - ASE_AWK_NDE_HDR; - ase_char_t* buf; - ase_size_t len; -}; - -/* ASE_AWK_NDE_REX */ -struct ase_awk_nde_rex_t -{ - ASE_AWK_NDE_HDR; - ase_char_t* buf; - ase_size_t len; - void* code; -}; - -/* ASE_AWK_NDE_NAMED, ASE_AWK_NDE_GLOBAL, - * ASE_AWK_NDE_LOCAL, ASE_AWK_NDE_ARG - * ASE_AWK_NDE_NAMEDIDX, ASE_AWK_NDE_GLOBALIDX, - * ASE_AWK_NDE_LOCALIDX, ASE_AWK_NDE_ARGIDX */ -struct ase_awk_nde_var_t -{ - ASE_AWK_NDE_HDR; - struct - { - ase_char_t* name; - ase_size_t name_len; - ase_size_t idxa; - } id; - ase_awk_nde_t* idx; /* ASE_NULL for non-XXXXIDX */ -}; - -/* ASE_AWK_NDE_BFN, ASE_AWK_NDE_AFN */ -struct ase_awk_nde_call_t -{ - ASE_AWK_NDE_HDR; - union - { - struct - { - struct - { - ase_char_t* ptr; - ase_size_t len; - } name; - } afn; - - /* minimum information of a built-in function - * needed during run-time. */ - struct - { - struct - { - const ase_char_t* ptr; - ase_size_t len; - } name; - - struct - { - ase_size_t min; - ase_size_t max; - const ase_char_t* spec; - } arg; - - int (*handler) ( - ase_awk_run_t*, const ase_char_t*, ase_size_t); - } bfn; - } what; - ase_awk_nde_t* args; - ase_size_t nargs; -}; - -/* ASE_AWK_NDE_GETLINE */ -struct ase_awk_nde_getline_t -{ - ASE_AWK_NDE_HDR; - ase_awk_nde_t* var; - int in_type; /* ASE_AWK_GETLINE_XXX */ - ase_awk_nde_t* in; -}; - -/* ASE_AWK_NDE_IF */ -struct ase_awk_nde_if_t -{ - ASE_AWK_NDE_HDR; - ase_awk_nde_t* test; - ase_awk_nde_t* then_part; - ase_awk_nde_t* else_part; /* optional */ -}; - -/* ASE_AWK_NDE_WHILE, ASE_AWK_NDE_DOWHILE */ -struct ase_awk_nde_while_t -{ - ASE_AWK_NDE_HDR; - ase_awk_nde_t* test; - ase_awk_nde_t* body; -}; - -/* ASE_AWK_NDE_FOR */ -struct ase_awk_nde_for_t -{ - ASE_AWK_NDE_HDR; - ase_awk_nde_t* init; /* optional */ - ase_awk_nde_t* test; /* optional */ - ase_awk_nde_t* incr; /* optional */ - ase_awk_nde_t* body; -}; - -/* ASE_AWK_NDE_FOREACH */ -struct ase_awk_nde_foreach_t -{ - ASE_AWK_NDE_HDR; - ase_awk_nde_t* test; - ase_awk_nde_t* body; -}; - -/* ASE_AWK_NDE_BREAK */ -struct ase_awk_nde_break_t -{ - ASE_AWK_NDE_HDR; -}; - -/* ASE_AWK_NDE_CONTINUE */ -struct ase_awk_nde_continue_t -{ - ASE_AWK_NDE_HDR; -}; - -/* ASE_AWK_NDE_RETURN */ -struct ase_awk_nde_return_t -{ - ASE_AWK_NDE_HDR; - ase_awk_nde_t* val; /* optional (no return code if ASE_NULL) */ -}; - -/* ASE_AWK_NDE_EXIT */ -struct ase_awk_nde_exit_t -{ - ASE_AWK_NDE_HDR; - ase_awk_nde_t* val; /* optional (no exit code if ASE_NULL) */ -}; - -/* ASE_AWK_NDE_NEXT */ -struct ase_awk_nde_next_t -{ - ASE_AWK_NDE_HDR; -}; - -/* ASE_AWK_NDE_NEXTFILE */ -struct ase_awk_nde_nextfile_t -{ - ASE_AWK_NDE_HDR; - int out; -}; - -/* ASE_AWK_NDE_DELETE */ -struct ase_awk_nde_delete_t -{ - ASE_AWK_NDE_HDR; - ase_awk_nde_t* var; -}; - -/* ASE_AWK_NDE_PRINT */ -struct ase_awk_nde_print_t -{ - ASE_AWK_NDE_HDR; - ase_awk_nde_t* args; - int out_type; /* ASE_AWK_OUT_XXX */ - ase_awk_nde_t* out; -}; - -#ifdef __cplusplus -extern "C" { -#endif - -int ase_awk_prnpt (ase_awk_t* awk, ase_awk_nde_t* tree); -int ase_awk_prnptnpt (ase_awk_t* awk, ase_awk_nde_t* tree); - -void ase_awk_clrpt (ase_awk_t* awk, ase_awk_nde_t* tree); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ase/awk/val.c b/ase/awk/val.c deleted file mode 100644 index dbefa6c1..00000000 --- a/ase/awk/val.c +++ /dev/null @@ -1,839 +0,0 @@ -/* - * $Id: val.c,v 1.1.1.1 2007/03/28 14:05:20 bacon Exp $ - * - * {License} - */ - -#include - -#ifdef DEBUG_VAL -#include -#endif - - -static ase_char_t* str_to_str ( - ase_awk_run_t* run, const ase_char_t* str, ase_size_t str_len, - int opt, ase_str_t* buf, ase_size_t* len); -static ase_char_t* val_int_to_str ( - ase_awk_run_t* run, ase_awk_val_int_t* v, - int opt, ase_str_t* buf, ase_size_t* len); -static ase_char_t* val_real_to_str ( - ase_awk_run_t* run, ase_awk_val_real_t* v, - int opt, ase_str_t* buf, ase_size_t* len); - -static ase_awk_val_nil_t awk_nil = { ASE_AWK_VAL_NIL, 0 }; -static ase_awk_val_str_t awk_zls = { ASE_AWK_VAL_STR, 0, ASE_T(""), 0 }; - -ase_awk_val_t* ase_awk_val_nil = (ase_awk_val_t*)&awk_nil; -ase_awk_val_t* ase_awk_val_zls = (ase_awk_val_t*)&awk_zls; - -static ase_awk_val_int_t awk_int[] = -{ - { ASE_AWK_VAL_INT, 0, -1, ASE_NULL }, - { ASE_AWK_VAL_INT, 0, 0, ASE_NULL }, - { ASE_AWK_VAL_INT, 0, 1, ASE_NULL }, - { ASE_AWK_VAL_INT, 0, 2, ASE_NULL }, - { ASE_AWK_VAL_INT, 0, 3, ASE_NULL }, - { ASE_AWK_VAL_INT, 0, 4, ASE_NULL }, - { ASE_AWK_VAL_INT, 0, 5, ASE_NULL }, - { ASE_AWK_VAL_INT, 0, 6, ASE_NULL }, - { ASE_AWK_VAL_INT, 0, 7, ASE_NULL }, - { ASE_AWK_VAL_INT, 0, 8, ASE_NULL }, - { ASE_AWK_VAL_INT, 0, 9, ASE_NULL }, - { ASE_AWK_VAL_INT, 0, 10, ASE_NULL }, - { ASE_AWK_VAL_INT, 0, 11, ASE_NULL }, - { ASE_AWK_VAL_INT, 0, 12, ASE_NULL }, - { ASE_AWK_VAL_INT, 0, 13, ASE_NULL }, - { ASE_AWK_VAL_INT, 0, 14, ASE_NULL }, - { ASE_AWK_VAL_INT, 0, 15, ASE_NULL }, - { ASE_AWK_VAL_INT, 0, 16, ASE_NULL }, - { ASE_AWK_VAL_INT, 0, 17, ASE_NULL }, - { ASE_AWK_VAL_INT, 0, 18, ASE_NULL }, - { ASE_AWK_VAL_INT, 0, 19, ASE_NULL }, - { ASE_AWK_VAL_INT, 0, 20, ASE_NULL } -}; - -ase_awk_val_t* ase_awk_val_negone = (ase_awk_val_t*)&awk_int[0]; -ase_awk_val_t* ase_awk_val_zero = (ase_awk_val_t*)&awk_int[1]; -ase_awk_val_t* ase_awk_val_one = (ase_awk_val_t*)&awk_int[2]; - -ase_awk_val_t* ase_awk_makeintval (ase_awk_run_t* run, ase_long_t v) -{ - ase_awk_val_int_t* val; - - if (v >= awk_int[0].val && - v <= awk_int[ASE_COUNTOF(awk_int)-1].val) - { - return (ase_awk_val_t*)&awk_int[v-awk_int[0].val]; - } - - if (run->icache_count > 0) - { - val = run->icache[--run->icache_count]; - } - else - { - val = (ase_awk_val_int_t*) ASE_AWK_MALLOC ( - run->awk, ASE_SIZEOF(ase_awk_val_int_t)); - if (val == ASE_NULL) return ASE_NULL; - } - - val->type = ASE_AWK_VAL_INT; - val->ref = 0; - val->val = v; - val->nde = ASE_NULL; - -#ifdef DEBUG_VAL - ase_dprintf (ASE_T("makeintval => %p\n"), val); -#endif - return (ase_awk_val_t*)val; -} - -ase_awk_val_t* ase_awk_makerealval (ase_awk_run_t* run, ase_real_t v) -{ - ase_awk_val_real_t* val; - - if (run->rcache_count > 0) - { - val = run->rcache[--run->rcache_count]; - } - else - { - val = (ase_awk_val_real_t*) ASE_AWK_MALLOC ( - run->awk, ASE_SIZEOF(ase_awk_val_real_t)); - if (val == ASE_NULL) return ASE_NULL; - } - - val->type = ASE_AWK_VAL_REAL; - val->ref = 0; - val->val = v; - val->nde = ASE_NULL; - -#ifdef DEBUG_VAL - ase_dprintf (ASE_T("makerealval => %p\n"), val); -#endif - return (ase_awk_val_t*)val; -} - -ase_awk_val_t* ase_awk_makestrval0 (ase_awk_run_t* run, const ase_char_t* str) -{ - return ase_awk_makestrval (run, str, ase_strlen(str)); -} - -ase_awk_val_t* ase_awk_makestrval ( - ase_awk_run_t* run, const ase_char_t* str, ase_size_t len) -{ - ase_awk_val_str_t* val; - - val = (ase_awk_val_str_t*) ASE_AWK_MALLOC ( - run->awk, ASE_SIZEOF(ase_awk_val_str_t)); - if (val == ASE_NULL) return ASE_NULL; - - val->type = ASE_AWK_VAL_STR; - val->ref = 0; - val->len = len; - val->buf = ase_strxdup (str, len, &run->awk->prmfns.mmgr); - if (val->buf == ASE_NULL) - { - ASE_AWK_FREE (run->awk, val); - return ASE_NULL; - } - -#ifdef DEBUG_VAL - ase_dprintf (ASE_T("makestrval => %p\n"), val); -#endif - return (ase_awk_val_t*)val; -} - -ase_awk_val_t* ase_awk_makestrval_nodup ( - ase_awk_run_t* run, ase_char_t* str, ase_size_t len) -{ - ase_awk_val_str_t* val; - - val = (ase_awk_val_str_t*) ASE_AWK_MALLOC ( - run->awk, ASE_SIZEOF(ase_awk_val_str_t)); - if (val == ASE_NULL) return ASE_NULL; - - val->type = ASE_AWK_VAL_STR; - val->ref = 0; - val->len = len; - val->buf = str; - return (ase_awk_val_t*)val; -} - -ase_awk_val_t* ase_awk_makestrval2 ( - ase_awk_run_t* run, - const ase_char_t* str1, ase_size_t len1, - const ase_char_t* str2, ase_size_t len2) -{ - ase_awk_val_str_t* val; - - val = (ase_awk_val_str_t*) ASE_AWK_MALLOC ( - run->awk, ASE_SIZEOF(ase_awk_val_str_t)); - if (val == ASE_NULL) return ASE_NULL; - - val->type = ASE_AWK_VAL_STR; - val->ref = 0; - val->len = len1 + len2; - val->buf = ase_strxdup2 (str1, len1, str2, len2, &run->awk->prmfns.mmgr); - if (val->buf == ASE_NULL) - { - ASE_AWK_FREE (run->awk, val); - return ASE_NULL; - } - -#ifdef DEBUG_VAL - ase_dprintf (ASE_T("makestrval2 => %p\n"), val); -#endif - return (ase_awk_val_t*)val; -} - -ase_awk_val_t* ase_awk_makerexval ( - ase_awk_run_t* run, const ase_char_t* buf, ase_size_t len, void* code) -{ - ase_awk_val_rex_t* val; - - val = (ase_awk_val_rex_t*) ASE_AWK_MALLOC ( - run->awk, ASE_SIZEOF(ase_awk_val_rex_t)); - if (val == ASE_NULL) return ASE_NULL; - - val->type = ASE_AWK_VAL_REX; - val->ref = 0; - val->len = len; - val->buf = ase_strxdup (buf, len, &run->awk->prmfns.mmgr); - if (val->buf == ASE_NULL) - { - ASE_AWK_FREE (run->awk, val); - return ASE_NULL; - } - - val->code = ASE_AWK_MALLOC (run->awk, ASE_AWK_REX_LEN(code)); - if (val->code == ASE_NULL) - { - ASE_AWK_FREE (run->awk, val->buf); - ASE_AWK_FREE (run->awk, val); - return ASE_NULL; - } - - ase_memcpy (val->code, code, ASE_AWK_REX_LEN(code)); - return (ase_awk_val_t*)val; -} - -static void free_map_val (void* run, void* v) -{ -#ifdef DEBUG_VAL - ase_dprintf (ASE_T("refdown in map free...")); - ase_awk_dprintval (run, v); - ase_dprintf (ASE_T("\n")); -#endif - - ase_awk_refdownval (run, v); -} - -ase_awk_val_t* ase_awk_makemapval (ase_awk_run_t* run) -{ - ase_awk_val_map_t* val; - - val = (ase_awk_val_map_t*) ASE_AWK_MALLOC ( - run->awk, ASE_SIZEOF(ase_awk_val_map_t)); - if (val == ASE_NULL) return ASE_NULL; - - val->type = ASE_AWK_VAL_MAP; - val->ref = 0; - val->map = ase_awk_map_open ( - ASE_NULL, run, 256, free_map_val, run->awk); - if (val->map == ASE_NULL) - { - ASE_AWK_FREE (run->awk, val); - return ASE_NULL; - } - - return (ase_awk_val_t*)val; -} - -ase_awk_val_t* ase_awk_makerefval (ase_awk_run_t* run, int id, ase_awk_val_t** adr) -{ - ase_awk_val_ref_t* val; - - if (run->fcache_count > 0) - { - val = run->fcache[--run->fcache_count]; - } - else - { - val = (ase_awk_val_ref_t*) ASE_AWK_MALLOC ( - run->awk, ASE_SIZEOF(ase_awk_val_ref_t)); - if (val == ASE_NULL) return ASE_NULL; - } - - val->type = ASE_AWK_VAL_REF; - val->ref = 0; - val->id = id; - val->adr = adr; - - return (ase_awk_val_t*)val; -} - -ase_bool_t ase_awk_isbuiltinval (ase_awk_val_t* val) -{ - return val == ASE_NULL || - val == ase_awk_val_nil || - val == ase_awk_val_zls || - val == ase_awk_val_zero || - val == ase_awk_val_one || - (val >= (ase_awk_val_t*)&awk_int[0] && - val <= (ase_awk_val_t*)&awk_int[ASE_COUNTOF(awk_int)-1]); -} - -void ase_awk_freeval (ase_awk_run_t* run, ase_awk_val_t* val, ase_bool_t cache) -{ - if (ase_awk_isbuiltinval(val)) return; - -#ifdef DEBUG_VAL - ase_dprintf (ASE_T("freeing [cache=%d] ... "), cache); - ase_awk_dprintval (run, val); - ase_dprintf (ASE_T("\n")); -#endif - - if (val->type == ASE_AWK_VAL_NIL) - { - ASE_AWK_FREE (run->awk, val); - } - else if (val->type == ASE_AWK_VAL_INT) - { - if (cache == ase_true && - run->icache_count < ASE_COUNTOF(run->icache)) - { - run->icache[run->icache_count++] = - (ase_awk_val_int_t*)val; - } - else ASE_AWK_FREE (run->awk, val); - } - else if (val->type == ASE_AWK_VAL_REAL) - { - if (cache == ase_true && - run->rcache_count < ASE_COUNTOF(run->rcache)) - { - run->rcache[run->rcache_count++] = - (ase_awk_val_real_t*)val; - } - else ASE_AWK_FREE (run->awk, val); - } - else if (val->type == ASE_AWK_VAL_STR) - { - ASE_AWK_FREE (run->awk, ((ase_awk_val_str_t*)val)->buf); - ASE_AWK_FREE (run->awk, val); - } - else if (val->type == ASE_AWK_VAL_REX) - { - ASE_AWK_FREE (run->awk, ((ase_awk_val_rex_t*)val)->buf); - ase_awk_freerex (run->awk, ((ase_awk_val_rex_t*)val)->code); - ASE_AWK_FREE (run->awk, val); - } - else if (val->type == ASE_AWK_VAL_MAP) - { - ase_awk_map_close (((ase_awk_val_map_t*)val)->map); - ASE_AWK_FREE (run->awk, val); - } - else if (val->type == ASE_AWK_VAL_REF) - { - if (cache == ase_true && - run->fcache_count < ASE_COUNTOF(run->fcache)) - { - run->fcache[run->fcache_count++] = - (ase_awk_val_ref_t*)val; - } - else ASE_AWK_FREE (run->awk, val); - } - else - { - ASE_ASSERTX ( - !"should never happen - invalid value type", - "the type of a value should be one of ASE_AWK_VAL_XXX's defined in val.h"); - } -} - -void ase_awk_refupval (ase_awk_run_t* run, ase_awk_val_t* val) -{ - if (ase_awk_isbuiltinval(val)) return; - -#ifdef DEBUG_VAL - ase_dprintf (ASE_T("ref up [ptr=%p] [count=%d] "), val, (int)val->ref); - ase_awk_dprintval (run, val); - ase_dprintf (ASE_T("\n")); -#endif - - val->ref++; -} - -void ase_awk_refdownval (ase_awk_run_t* run, ase_awk_val_t* val) -{ - if (ase_awk_isbuiltinval(val)) return; - -#ifdef DEBUG_VAL - ase_dprintf (ASE_T("ref down [ptr=%p] [count=%d]\n"), val, (int)val->ref); - ase_awk_dprintval (run, val); - ase_dprintf (ASE_T("\n")); -#endif - - ASE_ASSERTX (val->ref > 0, - "the reference count of a value should be greater than zero for it to be decremented. check the source code for any bugs"); - - val->ref--; - if (val->ref <= 0) - { - ase_awk_freeval(run, val, ase_true); - } -} - -void ase_awk_refdownval_nofree (ase_awk_run_t* run, ase_awk_val_t* val) -{ - if (ase_awk_isbuiltinval(val)) return; - - ASE_ASSERTX (val->ref > 0, - "the reference count of a value should be greater than zero for it to be decremented. check the source code for any bugs"); - val->ref--; -} - -ase_bool_t ase_awk_valtobool (ase_awk_run_t* run, ase_awk_val_t* val) -{ - if (val == ASE_NULL) return ase_false; - - switch (val->type) - { - case ASE_AWK_VAL_NIL: - return ase_false; - case ASE_AWK_VAL_INT: - return ((ase_awk_val_int_t*)val)->val != 0; - case ASE_AWK_VAL_REAL: - return ((ase_awk_val_real_t*)val)->val != 0.0; - case ASE_AWK_VAL_STR: - return ((ase_awk_val_str_t*)val)->len > 0; - case ASE_AWK_VAL_REX: /* TODO: is this correct? */ - return ((ase_awk_val_rex_t*)val)->len > 0; - case ASE_AWK_VAL_MAP: - return ase_false; /* TODO: is this correct? */ - case ASE_AWK_VAL_REF: - return ase_false; /* TODO: is this correct? */ - } - - ASE_ASSERTX ( - !"should never happen - invalid value type", - "the type of a value should be one of ASE_AWK_VAL_XXX's defined in val.h"); - return ase_false; -} - -ase_char_t* ase_awk_valtostr ( - ase_awk_run_t* run, ase_awk_val_t* v, - int opt, ase_str_t* buf, ase_size_t* len) -{ - if (v->type == ASE_AWK_VAL_NIL) - { - return str_to_str (run, ASE_T(""), 0, opt, buf, len); - } - - if (v->type == ASE_AWK_VAL_INT) - { - ase_awk_val_int_t* vi = (ase_awk_val_int_t*)v; - - /* - if (vi->nde != ASE_NULL && vi->nde->str != ASE_NULL) - { - return str_to_str ( - run, vi->nde->str, vi->nde->len, - opt, buf, len); - } - else - { - */ - return val_int_to_str (run, vi, opt, buf, len); - /*}*/ - } - - if (v->type == ASE_AWK_VAL_REAL) - { - ase_awk_val_real_t* vr = (ase_awk_val_real_t*)v; - - /* - if (vr->nde != ASE_NULL && vr->nde->str != ASE_NULL) - { - return str_to_str ( - run, vr->nde->str, vr->nde->len, - opt, buf, len); - } - else - {*/ - return val_real_to_str (run, vr, opt, buf, len); - /*}*/ - } - - if (v->type == ASE_AWK_VAL_STR) - { - ase_awk_val_str_t* vs = (ase_awk_val_str_t*)v; - - return str_to_str ( - run, vs->buf, vs->len, opt, buf, len); - } - -#ifdef DEBUG_VAL - ase_dprintf ( - ASE_T("ERROR: WRONG VALUE TYPE [%d] in ase_awk_valtostr\n"), - v->type); -#endif - - ase_awk_setrunerror (run, ASE_AWK_EVALTYPE, 0, ASE_NULL, 0); - return ASE_NULL; -} - -static ase_char_t* str_to_str ( - ase_awk_run_t* run, const ase_char_t* str, ase_size_t str_len, - int opt, ase_str_t* buf, ase_size_t* len) -{ - if (buf == ASE_NULL) - { - ase_char_t* tmp; - tmp = ase_strxdup (str, str_len, &run->awk->prmfns.mmgr); - if (tmp == ASE_NULL) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return ASE_NULL; - } - - if (len != ASE_NULL) *len = str_len; - return tmp; - } - else - { - ase_size_t n; - - if (opt & ASE_AWK_VALTOSTR_CLEAR) ase_str_clear (buf); - n = ase_str_ncat (buf, str, str_len); - if (n == (ase_size_t)-1) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return ASE_NULL; - } - - if (len != ASE_NULL) *len = ASE_STR_LEN(buf); - return ASE_STR_BUF(buf); - } -} - -static ase_char_t* val_int_to_str ( - ase_awk_run_t* run, ase_awk_val_int_t* v, - int opt, ase_str_t* buf, ase_size_t* len) -{ - ase_char_t* tmp; - ase_long_t t; - ase_size_t l = 0; - - t = v->val; - if (t == 0) - { - /* handle zero */ - if (buf == ASE_NULL) - { - tmp = ASE_AWK_MALLOC ( - run->awk, 2 * ASE_SIZEOF(ase_char_t)); - if (tmp == ASE_NULL) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return ASE_NULL; - } - - tmp[0] = ASE_T('0'); - tmp[1] = ASE_T('\0'); - if (len != ASE_NULL) *len = 1; - return tmp; - } - else - { - if (opt & ASE_AWK_VALTOSTR_CLEAR) ase_str_clear (buf); - if (ase_str_cat (buf, ASE_T("0")) == (ase_size_t)-1) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return ASE_NULL; - } - - if (len != ASE_NULL) *len = ASE_STR_LEN(buf); - return ASE_STR_BUF(buf); - } - } - - /* non-zero values */ - if (t < 0) { t = -t; l++; } - while (t > 0) { l++; t /= 10; } - - if (buf == ASE_NULL) - { - tmp = ASE_AWK_MALLOC ( - run->awk, (l + 1) * ASE_SIZEOF(ase_char_t)); - if (tmp == ASE_NULL) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return ASE_NULL; - } - - tmp[l] = ASE_T('\0'); - if (len != ASE_NULL) *len = l; - } - else - { - /* clear the buffer */ - if (opt & ASE_AWK_VALTOSTR_CLEAR) ase_str_clear (buf); - - tmp = ASE_STR_BUF(buf) + ASE_STR_LEN(buf); - - /* extend the buffer */ - if (ase_str_nccat ( - buf, ASE_T(' '), l) == (ase_size_t)-1) - { - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return ASE_NULL; - } - } - - t = v->val; - if (t < 0) t = -t; - - while (t > 0) - { - tmp[--l] = (ase_char_t)(t % 10) + ASE_T('0'); - t /= 10; - } - - if (v->val < 0) tmp[--l] = ASE_T('-'); - - if (buf != ASE_NULL) - { - tmp = ASE_STR_BUF(buf); - if (len != ASE_NULL) *len = ASE_STR_LEN(buf); - } - - return tmp; -} - -static ase_char_t* val_real_to_str ( - ase_awk_run_t* run, ase_awk_val_real_t* v, - int opt, ase_str_t* buf, ase_size_t* len) -{ - ase_char_t* tmp; - ase_size_t tmp_len; - ase_str_t out, fbu; - - if (opt & ASE_AWK_VALTOSTR_PRINT) - { - tmp = run->global.ofmt.ptr; - tmp_len = run->global.ofmt.len; - } - else - { - tmp = run->global.convfmt.ptr; - tmp_len = run->global.convfmt.len; - } - - if (ase_str_open (&out, 256, &run->awk->prmfns.mmgr) == ASE_NULL) - { - ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return ASE_NULL; - } - - if (ase_str_open (&fbu, 256, &run->awk->prmfns.mmgr) == ASE_NULL) - { - ase_str_close (&out); - ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return ASE_NULL; - } - - tmp = ase_awk_format (run, &out, &fbu, tmp, tmp_len, - (ase_size_t)-1, (ase_awk_nde_t*)v, &tmp_len); - if (tmp == ASE_NULL) - { - ase_str_close (&fbu); - ase_str_close (&out); - return ASE_NULL; - } - - if (buf == ASE_NULL) - { - ase_str_close (&fbu); - ase_str_forfeit (&out); - if (len != ASE_NULL) *len = tmp_len; - } - else - { - if (opt & ASE_AWK_VALTOSTR_CLEAR) ase_str_clear (buf); - - if (ase_str_ncat (buf, tmp, tmp_len) == (ase_size_t)-1) - { - ase_str_close (&fbu); - ase_str_close (&out); - ase_awk_setrunerror ( - run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0); - return ASE_NULL; - } - - tmp = ASE_STR_BUF(buf); - if (len != ASE_NULL) *len = ASE_STR_LEN(buf); - - ase_str_close (&fbu); - ase_str_close (&out); - } - - return tmp; -} - -int ase_awk_valtonum ( - ase_awk_run_t* run, ase_awk_val_t* v, ase_long_t* l, ase_real_t* r) -{ - if (v->type == ASE_AWK_VAL_NIL) - { - *l = 0; - return 0; - } - - if (v->type == ASE_AWK_VAL_INT) - { - *l = ((ase_awk_val_int_t*)v)->val; - return 0; /* long */ - } - - if (v->type == ASE_AWK_VAL_REAL) - { - *r = ((ase_awk_val_real_t*)v)->val; - return 1; /* real */ - } - - if (v->type == ASE_AWK_VAL_STR) - { - return ase_awk_strtonum (run, - ((ase_awk_val_str_t*)v)->buf, - ((ase_awk_val_str_t*)v)->len, l, r); - -#if 0 - const ase_char_t* endptr; - - *l = ase_awk_strxtolong (run->awk, - ((ase_awk_val_str_t*)v)->buf, - ((ase_awk_val_str_t*)v)->len, 0, &endptr); - if (*endptr == ASE_T('.') || - *endptr == ASE_T('E') || - *endptr == ASE_T('e')) - { - *r = ase_awk_strxtoreal (run->awk, - ((ase_awk_val_str_t*)v)->buf, - ((ase_awk_val_str_t*)v)->len, ASE_NULL); -/* TODO: need to check if it is a valid number using endptr for strxtoreal? */ - return 1; /* real */ - } -/* TODO: do should i handle strings ending with invalid number characters like "123xx" or "dkdkdkd"? */ - return 0; /* long */ -#endif - } - -#ifdef DEBUG_VAL - ase_dprintf ( - ASE_T("ERROR: WRONG VALUE TYPE [%d] in ase_awk_valtonum\n"), - v->type); -#endif - - ase_awk_setrunerror (run, ASE_AWK_EVALTYPE, 0, ASE_NULL, 0); - return -1; /* error */ -} - -int ase_awk_strtonum ( - ase_awk_run_t* run, const ase_char_t* ptr, ase_size_t len, - ase_long_t* l, ase_real_t* r) -{ - const ase_char_t* endptr; - - *l = ase_awk_strxtolong (run->awk, ptr, len, 0, &endptr); - if (*endptr == ASE_T('.') || - *endptr == ASE_T('E') || - *endptr == ASE_T('e')) - { - *r = ase_awk_strxtoreal (run->awk, ptr, len, ASE_NULL); -/* TODO: need to check if it is a valid number using endptr for strxtoreal? */ - return 1; /* real */ - } -/* TODO: do should i handle strings ending with invalid number characters like "123xx" or "dkdkdkd"? */ - return 0; /* long */ - -} - -#define DPRINTF run->awk->prmfns.misc.dprintf -#define DCUSTOM run->awk->prmfns.misc.custom_data - -static int print_pair (ase_awk_pair_t* pair, void* arg) -{ - ase_awk_run_t* run = (ase_awk_run_t*)arg; - - DPRINTF (DCUSTOM, ASE_T(" %s=>"), pair->key); - ase_awk_dprintval ((ase_awk_run_t*)arg, pair->val); - DPRINTF (DCUSTOM, ASE_T(" ")); - return 0; -} - -void ase_awk_dprintval (ase_awk_run_t* run, ase_awk_val_t* val) -{ - /* TODO: better value printing ... */ - - switch (val->type) - { - case ASE_AWK_VAL_NIL: - DPRINTF (DCUSTOM, ASE_T("nil")); - break; - - case ASE_AWK_VAL_INT: - #if ASE_SIZEOF_LONG_LONG > 0 - DPRINTF (DCUSTOM, ASE_T("%lld"), - (long long)((ase_awk_val_int_t*)val)->val); - #elif ASE_SIZEOF___INT64 > 0 - DPRINTF (DCUSTOM, ASE_T("%I64d"), - (__int64)((ase_awk_val_int_t*)val)->val); - #elif ASE_SIZEOF_LONG > 0 - DPRINTF (DCUSTOM, ASE_T("%ld"), - (long)((ase_awk_val_int_t*)val)->val); - #elif ASE_SIZEOF_INT > 0 - DPRINTF (DCUSTOM, ASE_T("%d"), - (int)((ase_awk_val_int_t*)val)->val); - #else - #error unsupported size - #endif - break; - - case ASE_AWK_VAL_REAL: - DPRINTF (DCUSTOM, ASE_T("%Lf"), - (long double)((ase_awk_val_real_t*)val)->val); - break; - - case ASE_AWK_VAL_STR: - DPRINTF (DCUSTOM, ASE_T("%s"), ((ase_awk_val_str_t*)val)->buf); - break; - - case ASE_AWK_VAL_REX: - DPRINTF (DCUSTOM, ASE_T("REX[%s]"), ((ase_awk_val_rex_t*)val)->buf); - break; - - case ASE_AWK_VAL_MAP: - DPRINTF (DCUSTOM, ASE_T("MAP[")); - ase_awk_map_walk (((ase_awk_val_map_t*)val)->map, print_pair, run); - DPRINTF (DCUSTOM, ASE_T("]")); - break; - - case ASE_AWK_VAL_REF: - DPRINTF (DCUSTOM, ASE_T("REF[id=%d,val="), ((ase_awk_val_ref_t*)val)->id); - ase_awk_dprintval (run, *((ase_awk_val_ref_t*)val)->adr); - DPRINTF (DCUSTOM, ASE_T("]")); - break; - - default: - DPRINTF (DCUSTOM, ASE_T("**** INTERNAL ERROR - INVALID VALUE TYPE ****\n")); - } -} diff --git a/ase/awk/val.h b/ase/awk/val.h deleted file mode 100644 index e6f82907..00000000 --- a/ase/awk/val.h +++ /dev/null @@ -1,206 +0,0 @@ -/* - * $Id: val.h,v 1.1.1.1 2007/03/28 14:05:21 bacon Exp $ - * - * {License} - */ - -#ifndef _ASE_AWK_VAL_H_ -#define _ASE_AWK_VAL_H_ - -#ifndef _ASE_AWK_AWK_H_ -#error Include first -#endif - -#include -#include - -enum ase_awk_val_type_t -{ - /* the values between ASE_AWK_VAL_NIL and ASE_AWK_VAL_STR inclusive - * must be synchronized with an internal table of the __cmp_val - * function in run.c */ - ASE_AWK_VAL_NIL = 0, - ASE_AWK_VAL_INT = 1, - ASE_AWK_VAL_REAL = 2, - ASE_AWK_VAL_STR = 3, - - ASE_AWK_VAL_REX = 4, - ASE_AWK_VAL_MAP = 5, - ASE_AWK_VAL_REF = 6 -}; - -enum ase_awk_val_ref_id_t -{ - /* keep these items in the same order as corresponding items - * in tree.h */ - ASE_AWK_VAL_REF_NAMED, - ASE_AWK_VAL_REF_GLOBAL, - ASE_AWK_VAL_REF_LOCAL, - ASE_AWK_VAL_REF_ARG, - ASE_AWK_VAL_REF_NAMEDIDX, - ASE_AWK_VAL_REF_GLOBALIDX, - ASE_AWK_VAL_REF_LOCALIDX, - ASE_AWK_VAL_REF_ARGIDX, - ASE_AWK_VAL_REF_POS -}; - -enum ase_awk_valtostr_opt_t -{ - ASE_AWK_VALTOSTR_CLEAR = (1 << 0), - ASE_AWK_VALTOSTR_PRINT = (1 << 1) -}; - -typedef struct ase_awk_val_nil_t ase_awk_val_nil_t; -typedef struct ase_awk_val_int_t ase_awk_val_int_t; -typedef struct ase_awk_val_real_t ase_awk_val_real_t; -typedef struct ase_awk_val_str_t ase_awk_val_str_t; -typedef struct ase_awk_val_rex_t ase_awk_val_rex_t; -typedef struct ase_awk_val_map_t ase_awk_val_map_t; -typedef struct ase_awk_val_ref_t ase_awk_val_ref_t; - -#if ASE_SIZEOF_INT == 2 -#define ASE_AWK_VAL_HDR \ - unsigned int type: 3; \ - unsigned int ref: 13 -#else -#define ASE_AWK_VAL_HDR \ - unsigned int type: 3; \ - unsigned int ref: 29 -#endif - -#ifndef ASE_AWK_NDE_INT_DEFINED -#define ASE_AWK_NDE_INT_DEFINED -typedef struct ase_awk_nde_int_t ase_awk_nde_int_t; -#endif - -#ifndef ASE_AWK_NDE_REAL_DEFINED -#define ASE_AWK_NDE_REAL_DEFINED -typedef struct ase_awk_nde_real_t ase_awk_nde_real_t; -#endif - - -struct ase_awk_val_t -{ - ASE_AWK_VAL_HDR; -}; - -/* ASE_AWK_VAL_NIL */ -struct ase_awk_val_nil_t -{ - ASE_AWK_VAL_HDR; -}; - -/* ASE_AWK_VAL_INT */ -struct ase_awk_val_int_t -{ - ASE_AWK_VAL_HDR; - ase_long_t val; - ase_awk_nde_int_t* nde; -}; - -/* ASE_AWK_VAL_REAL */ -struct ase_awk_val_real_t -{ - ASE_AWK_VAL_HDR; - ase_real_t val; - ase_awk_nde_real_t* nde; -}; - -/* ASE_AWK_VAL_STR */ -struct ase_awk_val_str_t -{ - ASE_AWK_VAL_HDR; - ase_char_t* buf; - ase_size_t len; -}; - -/* ASE_AWK_VAL_REX */ -struct ase_awk_val_rex_t -{ - ASE_AWK_VAL_HDR; - ase_char_t* buf; - ase_size_t len; - void* code; -}; - -/* ASE_AWK_VAL_MAP */ -struct ase_awk_val_map_t -{ - ASE_AWK_VAL_HDR; - - /* TODO: make val_map to array if the indices used are all - * integers switch to map dynamically once the - * non-integral index is seen. - */ - ase_awk_map_t* map; -}; - -/* ASE_AWK_VAL_REF */ -struct ase_awk_val_ref_t -{ - ASE_AWK_VAL_HDR; - - int id; - /* if id is ASE_AWK_VAL_REF_POS, adr holds an index of the - * positional variable. Otherwise, adr points to the value - * directly. */ - ase_awk_val_t** adr; -}; - -#ifdef __cplusplus -extern "C" { -#endif - -extern ase_awk_val_t* ase_awk_val_nil; -extern ase_awk_val_t* ase_awk_val_zls; -extern ase_awk_val_t* ase_awk_val_negone; -extern ase_awk_val_t* ase_awk_val_zero; -extern ase_awk_val_t* ase_awk_val_one; - -ase_awk_val_t* ase_awk_makeintval (ase_awk_run_t* run, ase_long_t v); -ase_awk_val_t* ase_awk_makerealval (ase_awk_run_t* run, ase_real_t v); - -ase_awk_val_t* ase_awk_makestrval0 ( - ase_awk_run_t* run, const ase_char_t* str); -ase_awk_val_t* ase_awk_makestrval ( - ase_awk_run_t* run, const ase_char_t* str, ase_size_t len); -ase_awk_val_t* ase_awk_makestrval_nodup ( - ase_awk_run_t* run, ase_char_t* str, ase_size_t len); -ase_awk_val_t* ase_awk_makestrval2 ( - ase_awk_run_t* run, - const ase_char_t* str1, ase_size_t len1, - const ase_char_t* str2, ase_size_t len2); - -ase_awk_val_t* ase_awk_makerexval ( - ase_awk_run_t* run, const ase_char_t* buf, ase_size_t len, void* code); -ase_awk_val_t* ase_awk_makemapval (ase_awk_run_t* run); -ase_awk_val_t* ase_awk_makerefval ( - ase_awk_run_t* run, int id, ase_awk_val_t** adr); - -ase_bool_t ase_awk_isbuiltinval (ase_awk_val_t* val); - -void ase_awk_freeval (ase_awk_run_t* run, ase_awk_val_t* val, ase_bool_t cache); -void ase_awk_refupval (ase_awk_run_t* run, ase_awk_val_t* val); -void ase_awk_refdownval (ase_awk_run_t* run, ase_awk_val_t* val); -void ase_awk_refdownval_nofree (ase_awk_run_t* run, ase_awk_val_t* val); - -ase_bool_t ase_awk_valtobool ( - ase_awk_run_t* run, ase_awk_val_t* val); - -ase_char_t* ase_awk_valtostr ( - ase_awk_run_t* run, ase_awk_val_t* val, - int opt, ase_str_t* buf, ase_size_t* len); - -int ase_awk_valtonum ( - ase_awk_run_t* run, ase_awk_val_t* v, ase_long_t* l, ase_real_t* r); -int ase_awk_strtonum ( - ase_awk_run_t* run, const ase_char_t* ptr, ase_size_t len, - ase_long_t* l, ase_real_t* r); - -void ase_awk_dprintval (ase_awk_run_t* run, ase_awk_val_t* val); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ase/build.xml b/ase/build.xml deleted file mode 100644 index a457ce41..00000000 --- a/ase/build.xml +++ /dev/null @@ -1,68 +0,0 @@ - - - - - - ANT build script for ASE - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/ase/cmn/asecmn.dsp b/ase/cmn/asecmn.dsp deleted file mode 100644 index a39dd245..00000000 --- a/ase/cmn/asecmn.dsp +++ /dev/null @@ -1,124 +0,0 @@ -# Microsoft Developer Studio Project File - Name="asecmn" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Static Library" 0x0104 - -CFG=asecmn - Win32 Release -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "asecmn.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "asecmn.mak" CFG="asecmn - Win32 Release" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "asecmn - Win32 Release" (based on "Win32 (x86) Static Library") -!MESSAGE "asecmn - Win32 Debug" (based on "Win32 (x86) Static Library") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -RSC=rc.exe - -!IF "$(CFG)" == "asecmn - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "../release/lib" -# PROP Intermediate_Dir "release" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -MTL=midl.exe -# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_UNICODE" /D "_USRDLL" /Yu"stdafx.h" /FD /c -# ADD CPP /nologo /MT /Za /W3 /GX /O2 /I "../.." /D "NDEBUG" /D "WIN32" /D "_UNICODE" /FD /c -# SUBTRACT CPP /YX /Yc /Yu -# ADD BASE RSC /l 0x409 /d "NDEBUG" -# ADD RSC /l 0x409 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LIB32=link.exe -lib -# ADD BASE LIB32 /nologo - -!ELSEIF "$(CFG)" == "asecmn - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "../debug/lib" -# PROP Intermediate_Dir "debug" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -MTL=midl.exe -# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_UNICODE" /D "_USRDLL" /Yu"stdafx.h" /FD /GZ /c -# ADD CPP /nologo /MTd /Za /W3 /Gm /GX /ZI /Od /I "../.." /D "_DEBUG" /D "WIN32" /D "_UNICODE" /FD /GZ /c -# SUBTRACT CPP /YX /Yc /Yu -# ADD BASE RSC /l 0x409 /d "_DEBUG" -# ADD RSC /l 0x409 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LIB32=link.exe -lib -# ADD BASE LIB32 /nologo - -!ENDIF - -# Begin Target - -# Name "asecmn - Win32 Release" -# Name "asecmn - Win32 Debug" -# Begin Group "Source Files" - -# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" -# Begin Source File - -SOURCE=.\mem.c -# End Source File -# Begin Source File - -SOURCE=.\misc.c -# End Source File -# Begin Source File - -SOURCE=.\str.c -# End Source File -# End Group -# Begin Group "Header Files" - -# PROP Default_Filter "h;hpp;hxx;hm;inl" -# Begin Source File - -SOURCE=.\mem.h -# End Source File -# Begin Source File - -SOURCE=.\str.h -# End Source File -# End Group -# Begin Group "Resource Files" - -# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" -# End Group -# End Target -# End Project diff --git a/ase/cmn/conf_msw.h b/ase/cmn/conf_msw.h deleted file mode 100644 index 0d713a68..00000000 --- a/ase/cmn/conf_msw.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * $Id: conf_msw.h,v 1.1.1.1 2007/03/28 14:05:21 bacon Exp $ - * - * {License} - */ - -/* -Macro Meaning -_WIN64 A 64-bit platform. -_WIN32 A 32-bit platform. This value is also defined by the 64-bit - compiler for backward compatibility. -_WIN16 A 16-bit platform - -The following macros are specific to the architecture. - -Macro Meaning -_M_IA64 Intel Itanium Processor Family -_M_IX86 x86 platform -_M_X64 x64 platform -*/ - -#define ASE_ENDIAN_LITTLE - -#define ASE_SIZEOF_CHAR 1 -#define ASE_SIZEOF_SHORT 2 -#define ASE_SIZEOF_INT 4 - -/*#ifdef _WIN64 - #define ASE_SIZEOF_LONG 8 -#else*/ - #define ASE_SIZEOF_LONG 4 -/*#endif*/ - -#ifdef __POCC__ - /* pelles c with no microsoft extension */ - #define ASE_SIZEOF_LONG_LONG 8 - - #define ASE_SIZEOF___INT8 0 - #define ASE_SIZEOF___INT16 0 - #define ASE_SIZEOF___INT32 0 - #define ASE_SIZEOF___INT64 0 - #define ASE_SIZEOF___INT96 0 - #define ASE_SIZEOF___INT128 0 -#else - #define ASE_SIZEOF_LONG_LONG 0 - - #define ASE_SIZEOF___INT8 1 - #define ASE_SIZEOF___INT16 2 - #define ASE_SIZEOF___INT32 4 - #define ASE_SIZEOF___INT64 8 - #define ASE_SIZEOF___INT96 0 - #define ASE_SIZEOF___INT128 0 -#endif - -#ifdef _WIN64 - #define ASE_SIZEOF_VOID_P 8 -#else - #define ASE_SIZEOF_VOID_P 4 -#endif - -#define ASE_SIZEOF_FLOAT 4 -#define ASE_SIZEOF_DOUBLE 8 -#define ASE_SIZEOF_LONG_DOUBLE 16 -#define ASE_SIZEOF_WCHAR_T 2 diff --git a/ase/cmn/conf_unx.h.in b/ase/cmn/conf_unx.h.in deleted file mode 100644 index 43260fcd..00000000 --- a/ase/cmn/conf_unx.h.in +++ /dev/null @@ -1,44 +0,0 @@ -/* - * $Id: conf_unx.h.in,v 1.1.1.1 2007/03/28 14:05:21 bacon Exp $ - * - * {License} - */ - -/* Big Endian */ -#undef ASE_ENDIAN_BIG - -/* Little Endian */ -#undef ASE_ENDIAN_LITTLE - -/* Unknown Endian */ -#undef ASE_ENDIAN_UNKNOWN - -/* long long */ -#undef ASE_HAVE_LONG_LONG - -/* long double */ -#undef ASE_HAVE_LONG_DOUBLE - -/* data type size */ -#define ASE_SIZEOF_CHAR 0 -#define ASE_SIZEOF_SHORT 0 -#define ASE_SIZEOF_INT 0 -#define ASE_SIZEOF_LONG 0 -#define ASE_SIZEOF_LONG_LONG 0 -#define ASE_SIZEOF___INT8 0 -#define ASE_SIZEOF___INT16 0 -#define ASE_SIZEOF___INT32 0 -#define ASE_SIZEOF___INT64 0 -#define ASE_SIZEOF___INT128 0 -#define ASE_SIZEOF_VOID_P 0 -#define ASE_SIZEOF_FLOAT 0 -#define ASE_SIZEOF_DOUBLE 0 -#define ASE_SIZEOF_LONG_DOUBLE 0 -#define ASE_SIZEOF_WCHAR_T 0 - -/* char is wchar */ -#undef ASE_CHAR_IS_WCHAR - -/* char is mchar */ -#undef ASE_CHAR_IS_MCHAR - diff --git a/ase/cmn/conf_vms.h b/ase/cmn/conf_vms.h deleted file mode 100644 index 481d73ea..00000000 --- a/ase/cmn/conf_vms.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - * $Id: conf_vms.h,v 1.1.1.1 2007/03/28 14:05:21 bacon Exp $ - * - * {License} - */ - -/* all of vax, alpha, ia64 are in the little endian. */ -#define ASE_ENDIAN_LITTLE - -/* - * Refer to the chapter 3 of the following URL for the data sizes. - * http://h71000.www7.hp.com/commercial/c/docs/6180profile.html - */ - -#define ASE_SIZEOF_CHAR 1 -#define ASE_SIZEOF_SHORT 2 -#define ASE_SIZEOF_INT 4 -#define ASE_SIZEOF_LONG 4 - -#if defined(vax) || defined(__vax) - #define ASE_SIZEOF_LONG_LONG 0 -#elif defined(alpha) || defined(__alpha) - #define ASE_SIZEOF_LONG_LONG 8 -#elif defined(ia64) || defined(__ia64) - #define ASE_SIZEOF_LONG_LONG 8 -#else - #define ASE_SIZEOF_LONG_LONG 0 -#endif - -#define ASE_SIZEOF___INT8 1 -#define ASE_SIZEOF___INT16 2 -#define ASE_SIZEOF___INT32 4 - -#if defined(vax) || defined(__vax) - #define ASE_SIZEOF___INT64 0 -#elif defined(alpha) || defined(__alpha) - #define ASE_SIZEOF___INT64 8 -#elif defined(ia64) || defined(__ia64) - #define ASE_SIZEOF___INT64 8 -#else - #define ASE_SIZEOF___INT64 0 -#endif - -#define ASE_SIZEOF___INT96 0 -#define ASE_SIZEOF___INT128 0 - -#if defined(vax) || defined(__vax) - #define ASE_SIZEOF_VOID_P 4 -#elif defined(alpha) || defined(__alpha) - #if __INITIAL_POINTER_SIZE==64 - #pragma pointer_size 64 - #define ASE_SIZEOF_VOID_P 8 - #elif __INITIAL_POINTER_SIZE==32 - #pragma pointer_size 32 - #define ASE_SIZEOF_VOID_P 4 - #elif __INITIAL_POINTER_SIZE==0 - #define ASE_SIZEOF_VOID_P 4 - #else - #error "unsupported initial pointer size" - #endif -#elif defined(ia64) || defined(__ia64) - #if __INITIAL_POINTER_SIZE==64 - #pragma pointer_size 64 - #define ASE_SIZEOF_VOID_P 8 - #elif __INITIAL_POINTER_SIZE==32 - #pragma pointer_size 32 - #define ASE_SIZEOF_VOID_P 4 - #elif __INITIAL_POINTER_SIZE==0 - #define ASE_SIZEOF_VOID_P 4 - #else - #error "unsupported initial pointer size" - #endif -#else - #error "unsupported architecture" -#endif - -#define ASE_SIZEOF_FLOAT 4 -#define ASE_SIZEOF_DOUBLE 8 - -#if defined(vax) || defined(__vax) - #define ASE_SIZEOF_LONG_DOUBLE 8 -#elif defined(alpha) || defined(__alpha) - #define ASE_SIZEOF_LONG_DOUBLE 16 -#elif defined(ia64) || defined(__ia64) - #define ASE_SIZEOF_LONG_DOUBLE 16 -#else - #define ASE_SIZEOF_LONG_DOUBLE 0 -#endif - -#define ASE_SIZEOF_WCHAR_T 4 diff --git a/ase/cmn/descrip.mms b/ase/cmn/descrip.mms deleted file mode 100644 index 09fd3271..00000000 --- a/ase/cmn/descrip.mms +++ /dev/null @@ -1,17 +0,0 @@ -# -# OpenVMS MMS/MMK -# - -objects = mem.obj,str.obj,misc.obj - -CFLAGS = /include="../.." -#CFLAGS = /pointer_size=long /include="../.." -LIBRFLAGS = - -asecmn.olb : $(objects) - $(LIBR)/create $(MMS$TARGET) $(objects) -# $(LIBR)/replace $(LIBRFLAGS) $(MMS$TARGET),$(objects) - -mem.obj depends_on mem.c -str.obj depends_on str.c -misc.obj depends_on misc.c diff --git a/ase/cmn/macros.h b/ase/cmn/macros.h deleted file mode 100644 index 5e83b428..00000000 --- a/ase/cmn/macros.h +++ /dev/null @@ -1,139 +0,0 @@ -/* - * $Id: macros.h,v 1.1.1.1 2007/03/28 14:05:21 bacon Exp $ - * - * {License} - */ - -#ifndef _ASE_MACROS_H_ -#define _ASE_MACROS_H_ - -#include - -#ifdef __cplusplus - /*#define ASE_NULL ((ase_uint_t)0)*/ - #define ASE_NULL (0) -#else - #define ASE_NULL ((void*)0) -#endif - -#define ASE_CHAR_EOF ((ase_cint_t)-1) - -#define ASE_SIZEOF(n) (sizeof(n)) -#define ASE_COUNTOF(n) (sizeof(n)/sizeof(n[0])) -#define ASE_OFFSETOF(type,member) ((ase_size_t)&((type*)0)->member) - -#define ASE_TYPE_IS_SIGNED(type) (((type)0) > ((type)-1)) -#define ASE_TYPE_IS_UNSIGNED(type) (((type)0) < ((type)-1)) - -#define ASE_TYPE_SIGNED_MAX(type) \ - ((type)~((type)1 << (ASE_SIZEOF(type) * 8 - 1))) -#define ASE_TYPE_UNSIGNED_MAX(type) ((type)(~(type)0)) - -#define ASE_TYPE_SIGNED_MIN(type) \ - ((type)((type)1 << (ASE_SIZEOF(type) * 8 - 1))) -#define ASE_TYPE_UNSIGNED_MIN(type) ((type)0) - -#define ASE_TYPE_MAX(type) \ - ((ASE_TYPE_IS_SIGNED(type)? ASE_TYPE_SIGNED_MAX(type): ASE_TYPE_UNSIGNED_MAX(type))) -#define ASE_TYPE_MIN(type) \ - ((ASE_TYPE_IS_SIGNED(type)? ASE_TYPE_SIGNED_MIN(type): ASE_TYPE_UNSIGNED_MIN(type))) - -#define ASE_IS_POWOF2(x) (((x) & ((x) - 1)) == 0) - -#define ASE_SWAP(x,y,original_type,casting_type) \ - do { \ - x = (original_type)((casting_type)(x) ^ (casting_type)(y)); \ - y = (original_type)((casting_type)(y) ^ (casting_type)(x)); \ - x = (original_type)((casting_type)(x) ^ (casting_type)(y)); \ - } while (0) - -#define ASE_ABS(x) ((x) < 0? -(x): (x)) - -#define ASE_LOOP_CONTINUE(id) goto __loop_ ## id ## _begin__; -#define ASE_LOOP_BREAK(id) goto __loop_ ## id ## _end__; -#define ASE_LOOP_BEGIN(id) __loop_ ## id ## _begin__: { -#define ASE_LOOP_END(id) ASE_LOOP_CONTINUE(id) } __loop_ ## id ## _end__:; - -#define ASE_REPEAT(n,blk) \ - do { \ - ase_size_t __ase_repeat_x1__ = (ase_size_t)(n); \ - ase_size_t __ase_repeat_x2__ = __ase_repeat_x1__ >> 4; \ - __ase_repeat_x1__ &= 15; \ - while (__ase_repeat_x1__-- > 0) { blk; } \ - while (__ase_repeat_x2__-- > 0) { \ - blk; blk; blk; blk; blk; blk; blk; blk; \ - blk; blk; blk; blk; blk; blk; blk; blk; \ - } \ - } while (0); - -#define ASE_MQ_I(val) #val -#define ASE_MQ(val) ASE_MQ_I(val) -#define ASE_MC(ch) ((ase_mchar_t)ch) -#define ASE_MS(str) ((const ase_mchar_t*)str) -#define ASE_MT(txt) (txt) - -#define ASE_WQ_I(val) (L ## #val) -#define ASE_WQ(val) ASE_WQ_I(val) -#define ASE_WC(ch) ((ase_wchar_t)L ## ch) -#define ASE_WS(str) ((const ase_wchar_t*)L ## str) -#define ASE_WT(txt) (L ## txt) - -#if defined(ASE_CHAR_IS_MCHAR) - #define ASE_C(ch) ASE_MC(ch) - #define ASE_S(str) ASE_MS(str) - #define ASE_T(txt) ASE_MT(txt) -#else - #define ASE_C(ch) ASE_WC(ch) - #define ASE_S(str) ASE_WS(str) - #define ASE_T(txt) ASE_WT(txt) -#endif - -#if defined(__GNUC__) - #define ASE_BEGIN_PACKED_STRUCT(x) struct x { - #define ASE_END_PACKED_STRUCT() } __attribute__((packed)); -#else - #define ASE_BEGIN_PACKED_STRUCT(x) struct x { - #define ASE_END_PACKED_STRUCT() }; -#endif - -#ifdef NDEBUG - #define ASE_ASSERT(expr) ((void)0) - #define ASE_ASSERTX(expr,desc) ((void)0) -#else - #ifdef __cplusplus - extern "C" { - #endif - void ase_assert_abort (void); - void ase_assert_printf (const ase_char_t* fmt, ...); - int ase_assert_failed ( - const ase_char_t* expr, const ase_char_t* desc, - const ase_char_t* file, ase_size_t line); - #ifdef __cplusplus - } - #endif - - #define ASE_ASSERT(expr) (void)((expr) || \ - (ase_assert_failed (ASE_T(#expr), ASE_NULL, ASE_T(__FILE__), __LINE__), 0)) - #define ASE_ASSERTX(expr,desc) (void)((expr) || \ - (ase_assert_failed (ASE_T(#expr), ASE_T(desc), ASE_T(__FILE__), __LINE__), 0)) -#endif - -#define ASE_MALLOC(mmgr,size) (mmgr)->malloc((mmgr)->custom_data, size) -#define ASE_REALLOC(mmgr,ptr,size) (mmgr)->realloc((mmgr)->custom_data, ptr, size) -#define ASE_FREE(mmgr,ptr) (mmgr)->free((mmgr)->custom_data, ptr) - -#define ASE_ISUPPER(ccls,c) (ccls)->is_upper((ccls)->custom_data,c) -#define ASE_ISLOWER(ccls,c) (ccls)->is_lower((ccls)->custom_data,c) -#define ASE_ISALPHA(ccls,c) (ccls)->is_alpha((ccls)->custom_data,c) -#define ASE_ISDIGIT(ccls,c) (ccls)->is_digit((ccls)->custom_data,c) -#define ASE_ISXDIGIT(ccls,c) (ccls)->is_xdigit((ccls)->custom_data,c) -#define ASE_ISALNUM(ccls,c) (ccls)->is_alnum((ccls)->custom_data,c) -#define ASE_ISSPACE(ccls,c) (ccls)->is_space((ccls)->custom_data,c) -#define ASE_ISPRINT(ccls,c) (ccls)->is_print((ccls)->custom_data,c) -#define ASE_ISGRAPH(ccls,c) (ccls)->is_graph((ccls)->custom_data,c) -#define ASE_ISCNTRL(ccls,c) (ccls)->is_cntrl((ccls)->custom_data,c) -#define ASE_ISPUNCT(ccls,c) (ccls)->is_punct((ccls)->custom_data,c) -#define ASE_TOUPPER(ccls,c) (ccls)->to_upper((ccls)->custom_data,c) -#define ASE_TOLOWER(ccls,c) (ccls)->to_lower((ccls)->custom_data,c) - -#endif diff --git a/ase/cmn/makefile.in b/ase/cmn/makefile.in deleted file mode 100644 index 4d590ad6..00000000 --- a/ase/cmn/makefile.in +++ /dev/null @@ -1,49 +0,0 @@ -# -# $Id: makefile.in,v 1.1.1.1 2007/03/28 14:05:21 bacon Exp $ -# - -NAME = asecmn - -CC = @CC@ -AR = ar -MAKE = @MAKE@ -RANLIB = @RANLIB@ -CFLAGS = @CFLAGS@ -I@abs_top_builddir@/.. -LDFLAGS = @LDFLAGS@ -LIBS = @LIBS@ -MODE = @BUILDMODE@ - -OUT_DIR = ../$(MODE)/lib -OUT_FILE = $(OUT_DIR)/lib$(NAME).a - -TMP_DIR = $(MODE) - -OBJ_FILES = \ - $(TMP_DIR)/mem.o \ - $(TMP_DIR)/str.o \ - $(TMP_DIR)/misc.o - -lib: $(OUT_FILE) - -$(OUT_FILE): $(OBJ_FILES) $(OUT_DIR) - $(AR) cr $(OUT_FILE) $(OBJ_FILES) - if [ "$(RANLIB)" = "ranlib" ]; then ranlib $(OUT_FILE); fi - -$(TMP_DIR)/mem.o: $(TMP_DIR) - $(CC) $(CFLAGS) -o $@ -c mem.c - -$(TMP_DIR)/str.o: $(TMP_DIR) - $(CC) $(CFLAGS) -o $@ -c str.c - -$(TMP_DIR)/misc.o: $(TMP_DIR) - $(CC) $(CFLAGS) -o $@ -c misc.c - -$(OUT_DIR): - mkdir -p $(OUT_DIR) - -$(TMP_DIR): - mkdir -p $(TMP_DIR) - -clean: - rm -rf $(OUT_FILE) $(OBJ_FILES) - diff --git a/ase/cmn/makefile.msw.bcc b/ase/cmn/makefile.msw.bcc deleted file mode 100644 index 8aee0bbb..00000000 --- a/ase/cmn/makefile.msw.bcc +++ /dev/null @@ -1,29 +0,0 @@ -OUT = asecmn - -C_SRCS = mem.c str.c misc.c -C_OBJS = $(C_SRCS:.c=.obj) - -CC = bcc32 -LD = ilink32 -AR = tlib -JAVAC = javac - -CFLAGS = -O2 -WM -WU -RT- -w -q -I../.. -DNDEBUG -LDFLAGS = -Tpd -ap -Gn -c -q -STARTUP = c0d32w.obj -LIBS = import32.lib cw32mt.lib - -all: lib - -lib: $(C_OBJS) - $(AR) $(OUT).lib @&&! -+-$(**: = &^ -+-) -! - -clean: - -del $(OBJS) $(OUT).lib *.obj - -.SUFFIXES: .c .obj -.c.obj: - $(CC) $(CFLAGS) -c $< diff --git a/ase/cmn/makefile.msw.cl b/ase/cmn/makefile.msw.cl deleted file mode 100644 index db6e3f3f..00000000 --- a/ase/cmn/makefile.msw.cl +++ /dev/null @@ -1,23 +0,0 @@ -OUT = asecmn - -C_SRCS = mem.c str.c misc.c -C_OBJS = $(C_SRCS:.c=.obj) - -CC = cl -LD = link - -CFLAGS = /nologo /O2 /MT /W3 /GR- /Za -I../.. - -all: lib - -lib: $(C_OBJS) - $(LD) /lib @<< -/nologo /out:$(OUT).lib $(C_OBJS) -<< - -clean: - del $(OBJS) $(OUT).lib *.obj - -.SUFFIXES: .c .obj -.c.obj: - $(CC) $(CFLAGS) /c $< diff --git a/ase/cmn/mem.c b/ase/cmn/mem.c deleted file mode 100644 index 0e8cf420..00000000 --- a/ase/cmn/mem.c +++ /dev/null @@ -1,52 +0,0 @@ -/* - * $Id: mem.c,v 1.1.1.1 2007/03/28 14:05:21 bacon Exp $ - * - * {License} - */ - -#include - -void* ase_memcpy (void* dst, const void* src, ase_size_t n) -{ - void* p = dst; - void* e = (ase_byte_t*)dst + n; - - while (dst < e) - { - *(ase_byte_t*)dst = *(ase_byte_t*)src; - dst = (ase_byte_t*)dst + 1; - src = (ase_byte_t*)src + 1; - } - - return p; -} - -void* ase_memset (void* dst, int val, ase_size_t n) -{ - void* p = dst; - void* e = (ase_byte_t*)p + n; - - while (p < e) - { - *(ase_byte_t*)p = (ase_byte_t)val; - p = (ase_byte_t*)p + 1; - } - - return dst; -} - -int ase_memcmp (const void* s1, const void* s2, ase_size_t n) -{ - const void* e; - - if (n == 0) return 0; - - e = (const ase_byte_t*)s1 + n - 1; - while (s1 < e && *(ase_byte_t*)s1 == *(ase_byte_t*)s2) - { - s1 = (ase_byte_t*)s1 + 1; - s2 = (ase_byte_t*)s2 + 1; - } - - return *((ase_byte_t*)s1) - *((ase_byte_t*)s2); -} diff --git a/ase/cmn/mem.h b/ase/cmn/mem.h deleted file mode 100644 index 06685dd2..00000000 --- a/ase/cmn/mem.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * $Id: mem.h,v 1.1.1.1 2007/03/28 14:05:21 bacon Exp $ - * - * {License} - */ - -#ifndef _ASE_CMN_MEM_H_ -#define _ASE_CMN_MEM_H_ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -void* ase_memcpy (void* dst, const void* src, ase_size_t n); -void* ase_memset (void* dst, int val, ase_size_t n); -int ase_memcmp (const void* s1, const void* s2, ase_size_t n); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ase/cmn/misc.c b/ase/cmn/misc.c deleted file mode 100644 index 870025d8..00000000 --- a/ase/cmn/misc.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * $Id: misc.c,v 1.1.1.1 2007/03/28 14:05:21 bacon Exp $ - * - * {License} - */ - -#include -#include - -#ifndef NDEBUG -int ase_assert_failed ( - const ase_char_t* expr, const ase_char_t* desc, - const ase_char_t* file, ase_size_t line) -{ - if (desc == ASE_NULL) - { - ase_assert_printf ( - ASE_T("ASSERTION FAILURE AT FILE %s LINE %lu\n%s\n"), - file, (unsigned long)line, expr); - } - else - { - ase_assert_printf ( - ASE_T("ASSERTION FAILURE AT FILE %s LINE %lu\n%s\n\nDESCRIPTION:\n%s\n"), - file, (unsigned long)line, expr, desc); - - } - - ase_assert_abort (); - return 0; -} - -#endif - diff --git a/ase/cmn/pack.h b/ase/cmn/pack.h deleted file mode 100644 index 70cda120..00000000 --- a/ase/cmn/pack.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * $Id: pack.h,v 1.1.1.1 2007/03/28 14:05:21 bacon Exp $ - * - * {License} - */ - -#if defined(__GNUC__) - #pragma pack(1) -#elif defined(__HP_aCC) || defined(__HP_cc) - #pragma PACK 1 -#elif defined(_MSC_VER) || defined(__BORLANDC__) - #pragma pack(push,1) -#elif defined(__DECC) - #pragma pack(push,1) -#else - #pragma pack(1) -#endif diff --git a/ase/cmn/str.c b/ase/cmn/str.c deleted file mode 100644 index bcc7cd3c..00000000 --- a/ase/cmn/str.c +++ /dev/null @@ -1,385 +0,0 @@ -/* - * $Id: str.c,v 1.1.1.1 2007/03/28 14:05:21 bacon Exp $ - * - * {License} - */ - -#include -#include - -ase_size_t ase_strlen (const ase_char_t* str) -{ - const ase_char_t* p = str; - while (*p != ASE_T('\0')) p++; - return p - str; -} - -ase_size_t ase_strcpy (ase_char_t* buf, const ase_char_t* str) -{ - ase_char_t* org = buf; - while ((*buf++ = *str++) != ASE_T('\0')); - return buf - org - 1; -} - -ase_size_t ase_strxcpy ( - ase_char_t* buf, ase_size_t bsz, const ase_char_t* str) -{ - ase_char_t* p, * p2; - - p = buf; p2 = buf + bsz - 1; - - while (p < p2) - { - if (*str == ASE_T('\0')) break; - *p++ = *str++; - } - - if (bsz > 0) *p = ASE_T('\0'); - return p - buf; -} - -ase_size_t ase_strncpy ( - ase_char_t* buf, const ase_char_t* str, ase_size_t len) -{ - const ase_char_t* end = str + len; - while (str < end) *buf++ = *str++; - *buf = ASE_T('\0'); - return len; -} - -ase_size_t ase_strxncpy ( - ase_char_t* buf, ase_size_t bsz, const ase_char_t* str, ase_size_t len) -{ - ase_size_t n; - - if (bsz <= 0) return 0; - if ((n = bsz - 1) > len) n = len; - ase_memcpy (buf, str, n * ASE_SIZEOF(ase_char_t)); - buf[n] = ASE_T('\0'); - - return n; -} - -ase_size_t ase_strxncat ( - ase_char_t* buf, ase_size_t bsz, const ase_char_t* str, ase_size_t len) -{ - ase_char_t* p, * p2; - const ase_char_t* end; - ase_size_t blen; - - blen = ase_strlen(buf); - if (blen >= bsz) return blen; /* something wrong */ - - p = buf + blen; - p2 = buf + bsz - 1; - - end = str + len; - - while (p < p2) - { - if (str >= end) break; - *p++ = *str++; - } - - if (bsz > 0) *p = ASE_T('\0'); - return p - buf; -} - -int ase_strcmp (const ase_char_t* s1, const ase_char_t* s2) -{ - while (*s1 == *s2) - { - if (*s1 == ASE_C('\0')) return 0; - s1++, s2++; - } - - return (*s1 > *s2)? 1: -1; -} - -int ase_strxncmp ( - const ase_char_t* s1, ase_size_t len1, - const ase_char_t* s2, ase_size_t len2) -{ - ase_char_t c1, c2; - const ase_char_t* end1 = s1 + len1; - const ase_char_t* end2 = s2 + len2; - - while (s1 < end1) - { - c1 = *s1; - if (s2 < end2) - { - c2 = *s2; - if (c1 > c2) return 1; - if (c1 < c2) return -1; - } - else return 1; - s1++; s2++; - } - - return (s2 < end2)? -1: 0; -} - -int ase_strcasecmp ( - const ase_char_t* s1, const ase_char_t* s2, ase_ccls_t* ccls) -{ - while (ASE_TOUPPER(ccls,*s1) == ASE_TOUPPER(ccls,*s2)) - { - if (*s1 == ASE_C('\0')) return 0; - s1++, s2++; - } - - return (ASE_TOUPPER(ccls,*s1) > ASE_TOUPPER(ccls,*s2))? 1: -1; -} - -int ase_strxncasecmp ( - const ase_char_t* s1, ase_size_t len1, - const ase_char_t* s2, ase_size_t len2, ase_ccls_t* ccls) -{ - ase_char_t c1, c2; - const ase_char_t* end1 = s1 + len1; - const ase_char_t* end2 = s2 + len2; - - while (s1 < end1) - { - c1 = ASE_TOUPPER (ccls, *s1); - if (s2 < end2) - { - c2 = ASE_TOUPPER (ccls, *s2); - if (c1 > c2) return 1; - if (c1 < c2) return -1; - } - else return 1; - s1++; s2++; - } - - return (s2 < end2)? -1: 0; -} - -ase_char_t* ase_strdup (const ase_char_t* str, ase_mmgr_t* mmgr) -{ - ase_char_t* tmp; - - tmp = (ase_char_t*) ASE_MALLOC ( - mmgr, (ase_strlen(str)+1)*ASE_SIZEOF(ase_char_t)); - if (tmp == ASE_NULL) return ASE_NULL; - - ase_strcpy (tmp, str); - return tmp; -} - -ase_char_t* ase_strxdup ( - const ase_char_t* str, ase_size_t len, ase_mmgr_t* mmgr) -{ - ase_char_t* tmp; - - tmp = (ase_char_t*) ASE_MALLOC ( - mmgr, (len+1)*ASE_SIZEOF(ase_char_t)); - if (tmp == ASE_NULL) return ASE_NULL; - - ase_strncpy (tmp, str, len); - return tmp; -} - -ase_char_t* ase_strxdup2 ( - const ase_char_t* str1, ase_size_t len1, - const ase_char_t* str2, ase_size_t len2, ase_mmgr_t* mmgr) -{ - ase_char_t* tmp; - - tmp = (ase_char_t*) ASE_MALLOC ( - mmgr, (len1+len2+1) * ASE_SIZEOF(ase_char_t)); - if (tmp == ASE_NULL) return ASE_NULL; - - ase_strncpy (tmp, str1, len1); - ase_strncpy (tmp + len1, str2, len2); - return tmp; -} - -ase_char_t* ase_strxnstr ( - const ase_char_t* str, ase_size_t strsz, - const ase_char_t* sub, ase_size_t subsz) -{ - const ase_char_t* end, * subp; - - if (subsz == 0) return (ase_char_t*)str; - if (strsz < subsz) return ASE_NULL; - - end = str + strsz - subsz; - subp = sub + subsz; - - while (str <= end) - { - const ase_char_t* x = str; - const ase_char_t* y = sub; - - while (ase_true) - { - if (y >= subp) return (ase_char_t*)str; - if (*x != *y) break; - x++; y++; - } - - str++; - } - - return ASE_NULL; -} - -ase_str_t* ase_str_open (ase_str_t* str, ase_size_t capa, ase_mmgr_t* mmgr) -{ - if (str == ASE_NULL) - { - str = (ase_str_t*) - ASE_MALLOC (mmgr, ASE_SIZEOF(ase_str_t)); - if (str == ASE_NULL) return ASE_NULL; - str->__dynamic = ase_true; - } - else str->__dynamic = ase_false; - - str->mmgr = mmgr; - str->buf = (ase_char_t*) ASE_MALLOC ( - mmgr, ASE_SIZEOF(ase_char_t) * (capa + 1)); - if (str->buf == ASE_NULL) - { - if (str->__dynamic) ASE_FREE (mmgr, str); - return ASE_NULL; - } - - str->size = 0; - str->capa = capa; - str->buf[0] = ASE_T('\0'); - - return str; -} - -void ase_str_close (ase_str_t* str) -{ - ASE_FREE (str->mmgr, str->buf); - if (str->__dynamic) ASE_FREE (str->mmgr, str); -} - -void ase_str_clear (ase_str_t* str) -{ - str->size = 0; - str->buf[0] = ASE_T('\0'); -} - -void ase_str_forfeit (ase_str_t* str) -{ - if (str->__dynamic) ASE_FREE (str->mmgr, str); -} - -void ase_str_swap (ase_str_t* str, ase_str_t* str1) -{ - ase_str_t tmp; - - tmp.buf = str->buf; - tmp.size = str->size; - tmp.capa = str->capa; - tmp.mmgr = str->mmgr; - - str->buf = str1->buf; - str->size = str1->size; - str->capa = str1->capa; - str->mmgr = str1->mmgr; - - str1->buf = tmp.buf; - str1->size = tmp.size; - str1->capa = tmp.capa; - str1->mmgr = tmp.mmgr; -} - -ase_size_t ase_str_cpy (ase_str_t* str, const ase_char_t* s) -{ - /* TODO: improve it */ - return ase_str_ncpy (str, s, ase_strlen(s)); -} - -ase_size_t ase_str_ncpy (ase_str_t* str, const ase_char_t* s, ase_size_t len) -{ - ase_char_t* buf; - - if (len > str->capa) - { - buf = (ase_char_t*) ASE_MALLOC ( - str->mmgr, ASE_SIZEOF(ase_char_t) * (len + 1)); - if (buf == ASE_NULL) return (ase_size_t)-1; - - ASE_FREE (str->mmgr, str->buf); - str->capa = len; - str->buf = buf; - } - - str->size = ase_strncpy (str->buf, s, len); - str->buf[str->size] = ASE_T('\0'); - return str->size; -} - -ase_size_t ase_str_cat (ase_str_t* str, const ase_char_t* s) -{ - /* TODO: improve it */ - return ase_str_ncat (str, s, ase_strlen(s)); -} - -ase_size_t ase_str_ncat (ase_str_t* str, const ase_char_t* s, ase_size_t len) -{ - if (len > str->capa - str->size) - { - ase_char_t* tmp; - ase_size_t capa; - - capa = str->size + len; - - /* double the capa if necessary for concatenation */ - if (capa < str->capa * 2) capa = str->capa * 2; - - if (str->mmgr->realloc != ASE_NULL) - { - tmp = (ase_char_t*) ASE_REALLOC ( - str->mmgr, str->buf, - ASE_SIZEOF(ase_char_t) * (capa + 1)); - if (tmp == ASE_NULL) return (ase_size_t)-1; - } - else - { - tmp = (ase_char_t*) ASE_MALLOC ( - str->mmgr, ASE_SIZEOF(ase_char_t)*(capa+1)); - if (tmp == ASE_NULL) return (ase_size_t)-1; - if (str->buf != ASE_NULL) - { - ase_memcpy (tmp, str->buf, - ASE_SIZEOF(ase_char_t)*(str->capa+1)); - ASE_FREE (str->mmgr, str->buf); - } - } - - str->capa = capa; - str->buf = tmp; - } - - str->size += ase_strncpy (&str->buf[str->size], s, len); - str->buf[str->size] = ASE_T('\0'); - return str->size; -} - -ase_size_t ase_str_ccat (ase_str_t* str, ase_char_t c) -{ - return ase_str_ncat (str, &c, 1); -} - -ase_size_t ase_str_nccat (ase_str_t* str, ase_char_t c, ase_size_t len) -{ - while (len > 0) - { - if (ase_str_ncat (str, &c, 1) == (ase_size_t)-1) - { - return (ase_size_t)-1; - } - - len--; - } - return str->size; -} - - diff --git a/ase/cmn/str.h b/ase/cmn/str.h deleted file mode 100644 index f5fe4b9e..00000000 --- a/ase/cmn/str.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - * $Id: str.h,v 1.1.1.1 2007/03/28 14:05:21 bacon Exp $ - * - * {License} - */ - -#ifndef _ASE_CMN_STR_H_ -#define _ASE_CMN_STR_H_ - -#include -#include - -#define ASE_STR_LEN(x) ((x)->size) -#define ASE_STR_SIZE(x) ((x)->size + 1) -#define ASE_STR_CAPA(x) ((x)->capa) -#define ASE_STR_BUF(x) ((x)->buf) -#define ASE_STR_CHAR(x,idx) ((x)->buf[idx]) - -typedef struct ase_str_t ase_str_t; - -struct ase_str_t -{ - ase_char_t* buf; - ase_size_t size; - ase_size_t capa; - ase_mmgr_t* mmgr; - ase_bool_t __dynamic; -}; - -#ifdef __cplusplus -extern "C" { -#endif - -ase_size_t ase_strlen (const ase_char_t* str); - -ase_size_t ase_strcpy ( - ase_char_t* buf, const ase_char_t* str); -ase_size_t ase_strxcpy ( - ase_char_t* buf, ase_size_t bsz, const ase_char_t* str); -ase_size_t ase_strncpy ( - ase_char_t* buf, const ase_char_t* str, ase_size_t len); -ase_size_t ase_strxncpy ( - ase_char_t* buf, ase_size_t bsz, const ase_char_t* str, ase_size_t len); - -ase_size_t ase_strxncat ( - ase_char_t* buf, ase_size_t bsz, const ase_char_t* str, ase_size_t len); - -int ase_strcmp (const ase_char_t* s1, const ase_char_t* s2); -int ase_strxncmp ( - const ase_char_t* s1, ase_size_t len1, - const ase_char_t* s2, ase_size_t len2); -int ase_strcasecmp ( - const ase_char_t* s1, const ase_char_t* s2, ase_ccls_t* ccls); -int ase_strxncasecmp ( - const ase_char_t* s1, ase_size_t len1, - const ase_char_t* s2, ase_size_t len2, ase_ccls_t* ccls); - -ase_char_t* ase_strdup (const ase_char_t* str, ase_mmgr_t* mmgr); -ase_char_t* ase_strxdup ( - const ase_char_t* str, ase_size_t len, ase_mmgr_t* mmgr); -ase_char_t* ase_strxdup2 ( - const ase_char_t* str1, ase_size_t len1, - const ase_char_t* str2, ase_size_t len2, ase_mmgr_t* mmgr); - -ase_char_t* ase_strxnstr ( - const ase_char_t* str, ase_size_t strsz, - const ase_char_t* sub, ase_size_t subsz); - -ase_str_t* ase_str_open (ase_str_t* str, ase_size_t capa, ase_mmgr_t* mmgr); -void ase_str_close (ase_str_t* str); -void ase_str_clear (ase_str_t* str); - -void ase_str_forfeit (ase_str_t* str); -void ase_str_swap (ase_str_t* str, ase_str_t* str2); - -ase_size_t ase_str_cpy (ase_str_t* str, const ase_char_t* s); -ase_size_t ase_str_ncpy (ase_str_t* str, const ase_char_t* s, ase_size_t len); - -ase_size_t ase_str_cat (ase_str_t* str, const ase_char_t* s); -ase_size_t ase_str_ncat (ase_str_t* str, const ase_char_t* s, ase_size_t len); -ase_size_t ase_str_ccat (ase_str_t* str, ase_char_t c); -ase_size_t ase_str_nccat (ase_str_t* str, ase_char_t c, ase_size_t len); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ase/cmn/types.h b/ase/cmn/types.h deleted file mode 100644 index 20c3e85d..00000000 --- a/ase/cmn/types.h +++ /dev/null @@ -1,276 +0,0 @@ -/* - * $Id: types.h,v 1.1.1.1 2007/03/28 14:05:22 bacon Exp $ - * - * {License} - */ - -#ifndef _ASE_TYPES_H_ -#define _ASE_TYPES_H_ - -#if defined(_WIN32) - #include -#elif defined(vms) || defined(__vms) - #include -#elif defined(__unix__) || defined(__unix) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || (defined(__APPLE__) && defined(__MACH__)) - #if !defined(__unix__) - #define __unix__ - #endif - #if !defined(__unix) - #define __unix - #endif - #include -#else - #error unsupported operating system -#endif - -/* boolean type */ -typedef int ase_bool_t; -#define ase_true (0 == 0) -#define ase_false (0 != 0) - -/* tri-state type */ -typedef int ase_tri_t; -#define ase_alive 1 -#define ase_zombie 0 -#define ase_dead -1 - -/* integer that can hold a pointer */ -#if ASE_SIZEOF_VOID_P == ASE_SIZEOF_INT - typedef int ase_int_t; - typedef unsigned int ase_uint_t; -#elif ASE_SIZEOF_VOID_P == ASE_SIZEOF_LONG - typedef long ase_int_t; - typedef unsigned long ase_uint_t; -#elif ASE_SIZEOF_VOID_P == ASE_SIZEOF_LONG_LONG - typedef long long ase_int_t; - typedef unsigned long long ase_uint_t; -#elif ASE_SIZEOF_VOID_P == ASE_SIZEOF___INT32 - typedef __int32 ase_int_t; - typedef unsigned __int32 ase_uint_t; -#elif ASE_SIZEOF_VOID_P == ASE_SIZEOF___INT64 - typedef __int64 ase_int_t; - typedef unsigned __int64 ase_uint_t; -#else - #error unsupported pointer size -#endif - - -/* the largest integer supported by the system */ -#if ASE_SIZEOF_LONG_LONG != 0 - typedef long long ase_long_t; - typedef unsigned long long ase_ulong_t; -#elif ASE_SIZEOF___INT64 != 0 - typedef __int64 ase_long_t; - typedef unsigned __int64 ase_ulong_t; -#else - typedef long ase_long_t; - typedef unsigned long ase_ulong_t; -#endif - -/* integers of specific size */ -#if ASE_SIZEOF_CHAR == 1 - typedef char ase_int8_t; - typedef unsigned char ase_uint8_t; -#elif ASE_SIZEOF___INT8 == 1 - typedef __int8 ase_int8_t; - typedef unsigned __int8 ase_uint8_t; -#endif - -#if ASE_SIZEOF_SHORT == 2 - typedef short ase_int16_t; - typedef unsigned short ase_uint16_t; -#elif ASE_SIZEOF___INT16 == 2 - typedef __int16 ase_int16_t; - typedef unsigned __int16 ase_uint16_t; -#endif - -#if ASE_SIZEOF_INT == 4 - typedef int ase_int32_t; - typedef unsigned int ase_uint32_t; -#elif ASE_SIZEOF_LONG == 4 - typedef long ase_int32_t; - typedef unsigned long ase_uint32_t; -#elif ASE_SIZEOF___INT32 == 4 - typedef __int32 ase_int32_t; - typedef unsigned __int32 ase_uint32_t; -#endif - -#if ASE_SIZEOF_INT == 8 - #define ASE_HAVE_INT64_T - #define ASE_HAVE_UINT64_T - typedef int ase_int64_t; - typedef unsigned int ase_uint64_t; -#elif ASE_SIZEOF_LONG == 8 - #define ASE_HAVE_INT64_T - #define ASE_HAVE_UINT64_T - typedef long ase_int64_t; - typedef unsigned long ase_uint64_t; -#elif ASE_SIZEOF_LONG_LONG == 8 - #define ASE_HAVE_INT64_T - #define ASE_HAVE_UINT64_T - typedef long long ase_int64_t; - typedef unsigned long long ase_uint64_t; -#elif ASE_SIZEOF___INT64 == 8 - #define ASE_HAVE_INT64_T - #define ASE_HAVE_UINT64_T - typedef __int64 ase_int64_t; - typedef unsigned __int64 ase_uint64_t; -#endif - -#if ASE_SIZEOF_INT == 16 - #define ASE_HAVE_INT128_T - #define ASE_HAVE_UINT128_T - typedef int ase_int128_t; - typedef unsigned int ase_uint128_t; -#elif ASE_SIZEOF_LONG == 16 - #define ASE_HAVE_INT128_T - #define ASE_HAVE_UINT128_T - typedef long ase_int128_t; - typedef unsigned long ase_uint128_t; -#elif ASE_SIZEOF_LONG_LONG == 16 - #define ASE_HAVE_INT128_T - #define ASE_HAVE_UINT128_T - typedef long long ase_int128_t; - typedef unsigned long long ase_uint128_t; -#elif ASE_SIZEOF___INT128 == 16 - #define ASE_HAVE_INT128_T - #define ASE_HAVE_UINT128_T - typedef __int128 ase_int128_t; - typedef unsigned __int128 ase_uint128_t; -#endif - -/* miscellaneous integral types */ -typedef ase_uint8_t ase_byte_t; -typedef ase_uint_t ase_size_t; -typedef ase_int_t ase_ssize_t; -typedef ase_uint_t ase_word_t; - -/* floating-point number */ -#if defined(__FreeBSD__) - /* TODO: check if the support for long double is complete. - * if so, use long double for ase_real_t */ - #define ASE_SIZEOF_REAL ASE_SIZEOF_DOUBLE - typedef double ase_real_t; -#elif ASE_SIZEOF_LONG_DOUBLE > ASE_SIZEOF_DOUBLE - #define ASE_SIZEOF_REAL ASE_SIZEOF_LONG_DOUBLE - typedef long double ase_real_t; -#else - #define ASE_SIZEOF_REAL ASE_SIZEOF_DOUBLE - typedef double ase_real_t; -#endif - -/* character types */ -typedef char ase_mchar_t; -typedef int ase_mcint_t; - -#if defined(__cplusplus) - /* C++ */ - typedef wchar_t ase_wchar_t; - typedef wchar_t ase_wcint_t; - - /* all the way down from here for C */ -#elif (ASE_SIZEOF_WCHAR_T == 2) || (ASE_SIZEOF_WCHAR_T == 0) - typedef unsigned short ase_wchar_t; - typedef unsigned short ase_wcint_t; -#elif (ASE_SIZEOF_WCHAR_T == 4) - #if defined(vms) || defined(__vms) - typedef unsigned int ase_wchar_t; - typedef int ase_wcint_t; - #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) - typedef int ase_wchar_t; - typedef int ase_wcint_t; - #elif (defined(sun) || defined(__sun)) && defined(_LP64) - typedef int ase_wchar_t; - typedef int ase_wcint_t; - #elif defined(__APPLE__) && defined(__MACH__) - typedef int ase_wchar_t; - typedef int ase_wcint_t; - #elif defined(hpux) || defined(__hpux) - typedef unsigned int ase_wchar_t; - typedef int ase_wcint_t; - #elif ASE_SIZEOF_LONG == 4 - typedef long ase_wchar_t; - typedef long ase_wcint_t; - #else - typedef int ase_wchar_t; - typedef int ase_wcint_t; - #endif -#else - #error unsupported size of wchar_t -#endif - -#if defined(_WIN32) && (defined(UNICODE)||defined(_UNICODE)) - #define ASE_CHAR_IS_WCHAR - typedef ase_wchar_t ase_char_t; - typedef ase_wcint_t ase_cint_t; -#else - #if defined(ASE_CHAR_IS_MCHAR) - typedef ase_mchar_t ase_char_t; - typedef ase_mcint_t ase_cint_t; - #elif defined(ASE_CHAR_IS_WCHAR) - typedef ase_wchar_t ase_char_t; - typedef ase_wcint_t ase_cint_t; - #elif defined(_MBCS) - #define ASE_CHAR_IS_MCHAR - typedef ase_mchar_t ase_char_t; - typedef ase_mcint_t ase_cint_t; - #else - #define ASE_CHAR_IS_WCHAR - typedef ase_wchar_t ase_char_t; - typedef ase_wcint_t ase_cint_t; - #endif -#endif - -#if defined(ASE_CHAR_IS_WCHAR) && defined(_WIN32) - #ifndef UNICODE - #define UNICODE - #endif - #ifndef _UNICODE - #define _UNICODE - #endif -#endif - -typedef struct ase_cstr_t ase_cstr_t; -typedef struct ase_mmgr_t ase_mmgr_t; -typedef struct ase_ccls_t ase_ccls_t; - -typedef void* (*ase_malloc_t) (void* custom, ase_size_t n); -typedef void* (*ase_realloc_t) (void* custom, void* ptr, ase_size_t n); -typedef void (*ase_free_t) (void* custom, void* ptr); - -typedef ase_bool_t (*ase_isccls_t) (void* custom, ase_cint_t c); -typedef ase_cint_t (*ase_toccls_t) (void* custom, ase_cint_t c); - -struct ase_cstr_t -{ - const ase_char_t* ptr; - ase_size_t len; -}; - -struct ase_mmgr_t -{ - ase_malloc_t malloc; - ase_realloc_t realloc; - ase_free_t free; - void* custom_data; -}; - -struct ase_ccls_t -{ - ase_isccls_t is_upper; - ase_isccls_t is_lower; - ase_isccls_t is_alpha; - ase_isccls_t is_digit; - ase_isccls_t is_xdigit; - ase_isccls_t is_alnum; - ase_isccls_t is_space; - ase_isccls_t is_print; - ase_isccls_t is_graph; - ase_isccls_t is_cntrl; - ase_isccls_t is_punct; - ase_toccls_t to_upper; - ase_toccls_t to_lower; - void* custom_data; -}; - -#endif diff --git a/ase/cmn/unpack.h b/ase/cmn/unpack.h deleted file mode 100644 index 21c820a2..00000000 --- a/ase/cmn/unpack.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * $Id: unpack.h,v 1.1.1.1 2007/03/28 14:05:22 bacon Exp $ - * - * {License} - */ - -#if defined(__GNUC__) - #pragma pack() -#elif defined(__HP_aCC) || defined(__HP_cc) - #pragma PACK -#elif defined(_MSC_VER) || defined(__BORLANDC__) - #pragma pack(pop) -#elif defined(__DECC) - #pragma pack(pop) -#else - #pragma pack() -#endif diff --git a/ase/com/Awk.cpp b/ase/com/Awk.cpp deleted file mode 100644 index a183708d..00000000 --- a/ase/com/Awk.cpp +++ /dev/null @@ -1,1286 +0,0 @@ -/* - * $Id: Awk.cpp,v 1.1.1.1 2007/03/28 14:05:22 bacon Exp $ - * - * {License} - */ - -#include "stdafx.h" -#include "asecom.h" -#include "Awk.h" -#include "AwkExtio.h" -#include "Buffer.h" -#include -#include -#include -#include -#include - -#include -#include -#include - -#define DBGOUT(x) do { if (debug) OutputDebugString (x); } while(0) -#define DBGOUT2(awk,x) do { if (awk->debug) OutputDebugString (x); } while(0) - -STDMETHODIMP CAwk::InterfaceSupportsErrorInfo(REFIID riid) -{ - static const IID* arr[] = - { - &IID_IAwk, - }; - - for (int i=0;inext; - free (bfn_list->name.ptr); - free (bfn_list); - bfn_list = next; - } - - if (entry_point != NULL) SysFreeString (entry_point); - - if (write_extio_buf != NULL) write_extio_buf->Release (); - if (write_src_buf != NULL) write_src_buf->Release (); - if (read_src_buf != NULL) read_src_buf->Release (); - - if (handle != NULL) - { - ase_awk_close (handle); - handle = NULL; - DBGOUT (_T("closed awk")); - } -} - -#ifndef NDEBUG -void ase_assert_abort (void) -{ - abort (); -} - -void ase_assert_printf (const ase_char_t* fmt, ...) -{ - va_list ap; - int n; - ase_char_t buf[1024]; - - va_start (ap, fmt); - n = _vsntprintf (buf, ASE_COUNTOF(buf), fmt, ap); - if (n < 0) buf[ASE_COUNTOF(buf)-1] = ASE_T('\0'); - - MessageBox (NULL, buf, ASE_T("Assertion Failure"), MB_OK|MB_ICONERROR); - va_end (ap); -} -#endif - -static void* custom_awk_malloc (void* custom, ase_size_t n) -{ - return malloc (n); -} - -static void* custom_awk_realloc (void* custom, void* ptr, ase_size_t n) -{ - return realloc (ptr, n); -} - -static void custom_awk_free (void* custom, void* ptr) -{ - free (ptr); -} - -ase_bool_t custom_awk_isupper (void* custom, ase_cint_t c) -{ - return ase_isupper (c); -} - -ase_bool_t custom_awk_islower (void* custom, ase_cint_t c) -{ - return ase_islower (c); -} - -ase_bool_t custom_awk_isalpha (void* custom, ase_cint_t c) -{ - return ase_isalpha (c); -} - -ase_bool_t custom_awk_isdigit (void* custom, ase_cint_t c) -{ - return ase_isdigit (c); -} - -ase_bool_t custom_awk_isxdigit (void* custom, ase_cint_t c) -{ - return ase_isxdigit (c); -} - -ase_bool_t custom_awk_isalnum (void* custom, ase_cint_t c) -{ - return ase_isalnum (c); -} - -ase_bool_t custom_awk_isspace (void* custom, ase_cint_t c) -{ - return ase_isspace (c); -} - -ase_bool_t custom_awk_isprint (void* custom, ase_cint_t c) -{ - return ase_isprint (c); -} - -ase_bool_t custom_awk_isgraph (void* custom, ase_cint_t c) -{ - return ase_isgraph (c); -} - -ase_bool_t custom_awk_iscntrl (void* custom, ase_cint_t c) -{ - return ase_iscntrl (c); -} - -ase_bool_t custom_awk_ispunct (void* custom, ase_cint_t c) -{ - return ase_ispunct (c); -} - -ase_cint_t custom_awk_toupper (void* custom, ase_cint_t c) -{ - return ase_toupper (c); -} - -ase_cint_t custom_awk_tolower (void* custom, ase_cint_t c) -{ - return ase_tolower (c); -} - -static ase_real_t custom_awk_pow (void* custom, ase_real_t x, ase_real_t y) -{ - return pow (x, y); -} - - -static int custom_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; -} - -static void custom_awk_dprintf (void* custom, const ase_char_t* fmt, ...) -{ - va_list ap; - va_start (ap, fmt); - _vftprintf (stderr, fmt, ap); - va_end (ap); -} - -static ase_ssize_t __read_source ( - int cmd, void* arg, ase_char_t* data, ase_size_t count) -{ - CAwk* awk = (CAwk*)arg; - - if (cmd == ASE_AWK_IO_OPEN) - { - return (ase_ssize_t)awk->Fire_OpenSource (0); - } - else if (cmd == ASE_AWK_IO_CLOSE) - { - return (ase_ssize_t)awk->Fire_CloseSource (0); - } - else if (cmd == ASE_AWK_IO_READ) - { - if (awk->read_src_buf == NULL) - { - HRESULT hr = CoCreateInstance ( - CLSID_Buffer, NULL, CLSCTX_ALL, - IID_IBuffer, (void**)&awk->read_src_buf); - if (FAILED(hr)) - { - DBGOUT2 (awk, _T("cannot create source input buffer")); - return -1; - } - - awk->read_src_pos = 0; - awk->read_src_len = 0; - } - - CBuffer* tmp = (CBuffer*)awk->read_src_buf; - - if (awk->read_src_pos >= awk->read_src_len) - { - INT n = awk->Fire_ReadSource (awk->read_src_buf); - if (n <= 0) return (ase_ssize_t)n; - - if (SysStringLen(tmp->str) < (UINT)n) return -1; - awk->read_src_pos = 0; - awk->read_src_len = n; - } - - ASE_ASSERT (awk->read_src_pos < awk->read_src_len); - - BSTR str = tmp->str; - INT left = awk->read_src_len - awk->read_src_pos; - if (left > (ase_ssize_t)count) - { - memcpy (data, - ((TCHAR*)str)+awk->read_src_pos, - count * ASE_SIZEOF(ase_char_t)); - awk->read_src_pos += count; - return count; - } - else - { - memcpy (data, - ((TCHAR*)str)+awk->read_src_pos, - left * ASE_SIZEOF(ase_char_t)); - awk->read_src_pos = 0; - awk->read_src_len = 0; - return (ase_ssize_t)left; - } - } - - return -1; -} - -static ase_ssize_t __write_source ( - int cmd, void* arg, ase_char_t* data, ase_size_t count) -{ - CAwk* awk = (CAwk*)arg; - - if (cmd == ASE_AWK_IO_OPEN) - { - return (ase_ssize_t)awk->Fire_OpenSource (1); - } - else if (cmd == ASE_AWK_IO_CLOSE) - { - return (ase_ssize_t)awk->Fire_CloseSource (1); - } - else if (cmd == ASE_AWK_IO_WRITE) - { - HRESULT hr; - - if (awk->write_src_buf == NULL) - { - hr = CoCreateInstance ( - CLSID_Buffer, NULL, CLSCTX_ALL, - IID_IBuffer, (void**)&awk->write_src_buf); - if (FAILED(hr)) - { - DBGOUT2 (awk, _T("cannot create source output buffer")); - return -1; - } - } - - CBuffer* tmp = (CBuffer*)awk->write_src_buf; - if (tmp->PutValue (data, count) == FALSE) - { - DBGOUT2 (awk, _T("cannot set source output buffer")); - return -1; - } - - INT n = awk->Fire_WriteSource (awk->write_src_buf); - if (n > (INT)count) return -1; - return (ase_ssize_t)n; - } - - return -1; -} - -static int __handle_bfn ( - ase_awk_run_t* run, const ase_char_t* fnm, ase_size_t fnl) -{ - CAwk* awk = (CAwk*)ase_awk_getruncustomdata (run); - long nargs = (long)ase_awk_getnargs (run); - ase_awk_val_t* v; - - SAFEARRAY* aa; - SAFEARRAYBOUND bound[1]; - - bound[0].lLbound = 0; - bound[0].cElements = nargs; - - aa = SafeArrayCreate (VT_VARIANT, ASE_COUNTOF(bound), bound); - if (aa == NULL) - { - ase_char_t buf[128]; - _sntprintf (buf, ASE_COUNTOF(buf), - _T("out of memory in creating argument array for '%.*s'"), - fnl, fnm); - //TODO: ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, buf); - return -1; - } - - for (long i = 0; i < nargs; i++) - { - VARIANT arg; - - VariantInit (&arg); - - v = ase_awk_getarg (run, i); - - if (v->type == ASE_AWK_VAL_INT) - { - if (awk->use_longlong) - { - arg.vt = VT_I8; - arg.llVal = ((ase_awk_val_int_t*)v)->val; - } - else - { - arg.vt = VT_I4; - arg.lVal = (LONG)((ase_awk_val_int_t*)v)->val; - } - } - else if (v->type == ASE_AWK_VAL_REAL) - { - arg.vt = VT_R8; - arg.dblVal = ((ase_awk_val_real_t*)v)->val; - } - else if (v->type == ASE_AWK_VAL_STR) - { - BSTR tmp = SysAllocStringLen ( - ((ase_awk_val_str_t*)v)->buf, - ((ase_awk_val_str_t*)v)->len); - - if (arg.bstrVal == NULL) - { - VariantClear (&arg); - SafeArrayDestroy (aa); - - ase_char_t buf[128]; - _sntprintf (buf, ASE_COUNTOF(buf), - _T("out of memory in handling '%.*s'"), - fnl, fnm); - //TODO: ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, buf); - return -1; - } - - arg.vt = VT_BSTR; - arg.bstrVal = tmp; - } - else if (v->type == ASE_AWK_VAL_NIL) - { - arg.vt = VT_NULL; - } - - HRESULT hr = SafeArrayPutElement (aa, &i, &arg); - if (hr != S_OK) - { - VariantClear (&arg); - SafeArrayDestroy (aa); - - ase_char_t buf[128]; - _sntprintf (buf, ASE_COUNTOF(buf), - _T("out of memory in handling '%.*s'"), - fnl, fnm); - //TODO: ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, buf); - return -1; - } - - VariantClear (&arg); - } - - BSTR name = SysAllocStringLen (fnm, fnl); - if (name == NULL) - { - SafeArrayDestroy (aa); - - ase_char_t buf[128]; - _sntprintf (buf, ASE_COUNTOF(buf), - _T("out of memory in handling '%.*s'"), - fnl, fnm); - //TODO: ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, buf); - - return -1; - } - - ase_awk_val_t* ret; - int n = awk->Fire_HandleBuiltinFunction (run, name, aa, &ret); - if (n == 1) - { - ase_char_t buf[128]; - _sntprintf (buf, ASE_COUNTOF(buf), - _T("out of memory in handling '%.*s'"), - fnl, fnm); - //TODO: ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, buf); - return -1; - } - else if (n == 2) - { - ase_char_t buf[128]; - _sntprintf (buf, ASE_COUNTOF(buf), - _T("no handler for '%.*s'"), - fnl, fnm); - //TODO: ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, buf); - return -1; - } - else if (n == 3) - { - ase_char_t buf[128]; - _sntprintf (buf, ASE_COUNTOF(buf), - _T("return value not supported for '%.*s'"), - fnl, fnm); - //TODO: ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, buf); - return -1; - } - - /* name and aa are destroyed in HandleBuiltinFunction */ - //SafeArrayDestroy (aa); - //SysFreeString (name); - - ase_awk_setretval (run, ret); - return 0; -} - -HRESULT CAwk::Parse (int* ret) -{ - if (handle == NULL) - { - ase_awk_prmfns_t prmfns; - - memset (&prmfns, 0, sizeof(prmfns)); - - prmfns.mmgr.malloc = custom_awk_malloc; - prmfns.mmgr.realloc = custom_awk_realloc; - prmfns.mmgr.free = custom_awk_free; - - prmfns.ccls.is_upper = custom_awk_isupper; - prmfns.ccls.is_lower = custom_awk_islower; - prmfns.ccls.is_alpha = custom_awk_isalpha; - prmfns.ccls.is_digit = custom_awk_isdigit; - prmfns.ccls.is_xdigit = custom_awk_isxdigit; - prmfns.ccls.is_alnum = custom_awk_isalnum; - prmfns.ccls.is_space = custom_awk_isspace; - prmfns.ccls.is_print = custom_awk_isprint; - prmfns.ccls.is_graph = custom_awk_isgraph; - prmfns.ccls.is_cntrl = custom_awk_iscntrl; - prmfns.ccls.is_punct = custom_awk_ispunct; - prmfns.ccls.to_upper = custom_awk_toupper; - prmfns.ccls.to_lower = custom_awk_tolower; - - prmfns.misc.pow = custom_awk_pow; - prmfns.misc.sprintf = custom_awk_sprintf; - prmfns.misc.dprintf = custom_awk_dprintf; - - handle = ase_awk_open (&prmfns, NULL); - if (handle == NULL) - { - errlin = 0; - ase_strxcpy ( - errmsg, ASE_COUNTOF(errmsg), - ase_awk_geterrstr(NULL, ASE_AWK_ENOMEM)); - - *ret = -1; - - DBGOUT (_T("cannot open awk")); - return S_OK; - } - else DBGOUT (_T("opened awk successfully")); - - ase_awk_setoption (handle, option); - - ase_awk_setmaxdepth (handle, - ASE_AWK_DEPTH_BLOCK_PARSE, max_depth.block.parse); - ase_awk_setmaxdepth (handle, - ASE_AWK_DEPTH_BLOCK_RUN, max_depth.block.run); - ase_awk_setmaxdepth (handle, - ASE_AWK_DEPTH_EXPR_PARSE, max_depth.expr.parse); - ase_awk_setmaxdepth (handle, - ASE_AWK_DEPTH_EXPR_RUN, max_depth.expr.run); - ase_awk_setmaxdepth (handle, - ASE_AWK_DEPTH_REX_BUILD, max_depth.rex.build); - ase_awk_setmaxdepth (handle, - ASE_AWK_DEPTH_REX_MATCH, max_depth.rex.match); - } - - ase_awk_clrbfn (handle); - - for (bfn_t* bfn = bfn_list; bfn != NULL; bfn = bfn->next) - { - if (ase_awk_addbfn ( - handle, bfn->name.ptr, bfn->name.len, 0, - bfn->min_args, bfn->max_args, NULL, - __handle_bfn) == NULL) - { - const ase_char_t* msg; - - DBGOUT (_T("cannot add the builtin function")); - - ase_awk_geterror (handle, &errnum, &errlin, &msg); - ase_strxcpy (errmsg, ASE_COUNTOF(errmsg), msg); - - *ret = -1; - return S_OK; - } - } - - ase_awk_srcios_t srcios; - - srcios.in = __read_source; - srcios.out = __write_source; - srcios.custom_data = this; - - if (ase_awk_parse (handle, &srcios) == -1) - { - const ase_char_t* msg; - - ase_awk_geterror (handle, &errnum, &errlin, &msg); - ase_strxcpy (errmsg, ASE_COUNTOF(errmsg), msg); - - DBGOUT (_T("cannot parse the source code")); - - *ret = -1; - return S_OK; - } - else DBGOUT (_T("parsed the source code successfully")); - - *ret = 0; - return S_OK; -} - -static ase_ssize_t __process_extio ( - int cmd, void* arg, ase_char_t* data, ase_size_t size) -{ - ase_awk_extio_t* epa = (ase_awk_extio_t*)arg; - CAwk* awk = (CAwk*)epa->custom_data; - - if (cmd == ASE_AWK_IO_OPEN) - { - IAwkExtio* extio; - CAwkExtio* extio2; - IBuffer* read_buf; - - HRESULT hr = CoCreateInstance ( - CLSID_AwkExtio, NULL, CLSCTX_ALL, - IID_IAwkExtio, (void**)&extio); - if (FAILED(hr)) - { - DBGOUT2 (awk, _T("cannot create extio")); - return -1; - } - - hr = CoCreateInstance ( - CLSID_Buffer, NULL, CLSCTX_ALL, - IID_IBuffer, (void**)&read_buf); - if (FAILED(hr)) - { - DBGOUT2 (awk, _T("cannot create extio input buffer")); - extio->Release (); - return -1; - } - - extio2 = (CAwkExtio*)extio; - if (extio2->PutName (epa->name) == FALSE) - { - read_buf->Release (); - extio->Release (); - DBGOUT2 (awk, _T("cannot set the name of the extio input buffer")); - return -1; - } - extio2->type = epa->type & 0xFF; - extio2->mode = epa->mode; - - read_buf->AddRef (); - extio2->read_buf = read_buf; - extio2->read_buf_pos = 0; - extio2->read_buf_len = 0; - - INT n = awk->Fire_OpenExtio (extio); - if (n >= 0) - { - extio->AddRef (); - epa->handle = extio; - } - - read_buf->Release (); - extio->Release (); - return n; - } - else if (cmd == ASE_AWK_IO_CLOSE) - { - IAwkExtio* extio; - CAwkExtio* extio2; - - extio = (IAwkExtio*)epa->handle; - extio2 = (CAwkExtio*)extio; - - ASE_ASSERT (extio != NULL); - - INT n = awk->Fire_CloseExtio (extio); - if (n >= 0) - { - extio2->read_buf->Release(); - extio->Release(); - epa->handle = NULL; - } - - return n; - } - else if (cmd == ASE_AWK_IO_READ) - { - IAwkExtio* extio; - CAwkExtio* extio2; - - extio = (IAwkExtio*)epa->handle; - extio2 = (CAwkExtio*)extio; - - ASE_ASSERT (extio != NULL); - - CBuffer* tmp = (CBuffer*)extio2->read_buf; - if (extio2->read_buf_pos >= extio2->read_buf_len) - { - INT n = awk->Fire_ReadExtio (extio, extio2->read_buf); - if (n <= 0) return (ase_ssize_t)n; - - if (SysStringLen(tmp->str) < (UINT)n) return -1; - extio2->read_buf_pos = 0; - extio2->read_buf_len = n; - } - - ASE_ASSERT (extio2->read_buf_pos < extio2->read_buf_len); - - BSTR str = tmp->str; - INT left = extio2->read_buf_len - extio2->read_buf_pos; - if (left > (ase_ssize_t)size) - { - memcpy (data, - ((TCHAR*)str)+extio2->read_buf_pos, - size * ASE_SIZEOF(ase_char_t)); - extio2->read_buf_pos += size; - return size; - } - else - { - memcpy (data, - ((TCHAR*)str)+extio2->read_buf_pos, - left * ASE_SIZEOF(ase_char_t)); - extio2->read_buf_pos = 0; - extio2->read_buf_len = 0; - return (ase_ssize_t)left; - } - } - else if (cmd == ASE_AWK_IO_WRITE) - { - HRESULT hr; - IAwkExtio* extio = (IAwkExtio*)epa->handle; - ASE_ASSERT (extio != NULL); - - if (awk->write_extio_buf == NULL) - { - hr = CoCreateInstance ( - CLSID_Buffer, NULL, CLSCTX_ALL, - IID_IBuffer, (void**)&awk->write_extio_buf); - if (FAILED(hr)) - { - DBGOUT2 (awk, _T("cannot create extio output buffer")); - return -1; - } - } - - CBuffer* tmp = (CBuffer*)awk->write_extio_buf; - if (tmp->PutValue (data, size) == FALSE) return -1; - - INT n = awk->Fire_WriteExtio (extio, awk->write_extio_buf); - if (n > (INT)size) return -1; - return (ase_ssize_t)n; - } - else if (cmd == ASE_AWK_IO_FLUSH) - { - IAwkExtio* extio = (IAwkExtio*)epa->handle; - ASE_ASSERT (extio != NULL); - return awk->Fire_FlushExtio (extio); - } - else if (cmd == ASE_AWK_IO_NEXT) - { - IAwkExtio* extio = (IAwkExtio*)epa->handle; - ASE_ASSERT (extio != NULL); - return awk->Fire_NextExtio (extio); - } - - return -1; -} - -HRESULT CAwk::Run (int* ret) -{ - const ase_char_t* entry = NULL; - - if (handle == NULL) - { - errnum = ASE_AWK_EINTERN; - errlin = 0; - _tcscpy (errmsg, _T("parse not called yet")); - - *ret = -1; - return S_OK; - } - - ase_awk_runios_t runios; - runios.pipe = NULL; - runios.coproc = NULL; - runios.file = __process_extio; - runios.console = __process_extio; - runios.custom_data = this; - - if (entry_point != NULL && - SysStringLen(entry_point) > 0) entry = entry_point; - - if (ase_awk_run (handle, entry, &runios, NULL, NULL, this) == -1) - { - const ase_char_t* msg; - - ase_awk_geterror (handle, &errnum, &errlin, &msg); - ase_strxcpy (errmsg, ASE_COUNTOF(errmsg), msg); - - DBGOUT (_T("cannot run the program")); - *ret = -1; - return S_OK; - } - else DBGOUT (_T("run the program successfully")); - - *ret = 0; - return S_OK; -} - -STDMETHODIMP CAwk::AddBuiltinFunction ( - BSTR name, int min_args, int max_args, int* ret) -{ - bfn_t* bfn; - size_t name_len = SysStringLen(name); - - for (bfn = bfn_list; bfn != NULL; bfn = bfn->next) - { - if (ase_strxncmp ( - bfn->name.ptr, bfn->name.len, - name, name_len) == 0) - { - errnum = ASE_AWK_EEXIST; - errlin = 0; - _sntprintf ( - errmsg, ASE_COUNTOF(errmsg), - _T("'%.*s' added already"), - bfn->name.len, bfn->name.ptr); - - *ret = -1; - return S_OK; - } - } - - bfn = (bfn_t*)malloc (sizeof(bfn_t)); - if (bfn == NULL) - { - errnum = ASE_AWK_ENOMEM; - errlin = 0; - ase_strxcpy ( - errmsg, ASE_COUNTOF(errmsg), - ase_awk_geterrstr(NULL, errnum)); - - *ret = -1; - return S_OK; - } - - bfn->name.len = name_len; - bfn->name.ptr = (TCHAR*)malloc (bfn->name.len * sizeof(TCHAR)); - if (bfn->name.ptr == NULL) - { - free (bfn); - - errnum = ASE_AWK_ENOMEM; - errlin = 0; - ase_strxcpy ( - errmsg, ASE_COUNTOF(errmsg), - ase_awk_geterrstr(NULL, errnum)); - - *ret = -1; - return S_OK; - } - memcpy (bfn->name.ptr, name, sizeof(TCHAR) * bfn->name.len); - - bfn->min_args = min_args; - bfn->max_args = max_args; - bfn->next = bfn_list; - bfn_list = bfn; - - *ret = 0; - return S_OK; -} - -STDMETHODIMP CAwk::DeleteBuiltinFunction (BSTR name, int* ret) -{ - size_t name_len = SysStringLen(name); - bfn_t* bfn, * next, * prev = NULL; - - for (bfn = bfn_list; bfn != NULL; bfn = next) - { - next = bfn->next; - - if (ase_strxncmp ( - bfn->name.ptr, bfn->name.len, - name, name_len) == 0) - { - free (bfn->name.ptr); - free (bfn); - - if (prev == NULL) bfn_list = next; - else prev->next = next; - - *ret = 0; - return S_OK; - } - - prev = bfn; - } - - errnum = ASE_AWK_ENOENT; - errlin = 0; - ase_strxcpy ( - errmsg, ASE_COUNTOF(errmsg), - ase_awk_geterrstr(NULL, errnum)); - - *ret = -1; - return S_OK; -} - -STDMETHODIMP CAwk::get_ErrorCode(int *pVal) -{ - *pVal = errnum; - return S_OK; -} - -STDMETHODIMP CAwk::get_ErrorLine(int *pVal) -{ - *pVal = errlin; - return S_OK; -} - -STDMETHODIMP CAwk::get_ErrorMessage(BSTR *pVal) -{ - BSTR tmp = SysAllocStringLen (errmsg, _tcslen(errmsg)); - if (tmp == NULL) return E_OUTOFMEMORY; - *pVal = tmp; - return S_OK; -} - -STDMETHODIMP CAwk::get_ImplicitVariable(BOOL *pVal) -{ - if (handle != NULL) option = ase_awk_getoption (handle); - *pVal = (option & ASE_AWK_IMPLICIT) == 1; - return S_OK; -} - -STDMETHODIMP CAwk::put_ImplicitVariable(BOOL newVal) -{ - if (newVal) option = option | ASE_AWK_IMPLICIT; - else option = option & ~ASE_AWK_IMPLICIT; - if (handle != NULL) ase_awk_setoption (handle, option); - return S_OK; -} - -STDMETHODIMP CAwk::get_ExplicitVariable(BOOL *pVal) -{ - if (handle != NULL) option = ase_awk_getoption (handle); - *pVal = (option & ASE_AWK_EXPLICIT) == 1; - return S_OK; -} - -STDMETHODIMP CAwk::put_ExplicitVariable(BOOL newVal) -{ - if (newVal) option = option | ASE_AWK_EXPLICIT; - else option = option & ~ASE_AWK_EXPLICIT; - if (handle != NULL) ase_awk_setoption (handle, option); - return S_OK; -} - -STDMETHODIMP CAwk::get_UniqueFunction(BOOL *pVal) -{ - if (handle != NULL) option = ase_awk_getoption (handle); - *pVal = (option & ASE_AWK_UNIQUEFN) == 1; - return S_OK; -} - -STDMETHODIMP CAwk::put_UniqueFunction(BOOL newVal) -{ - if (newVal) option = option | ASE_AWK_UNIQUEFN; - else option = option & ~ASE_AWK_UNIQUEFN; - if (handle != NULL) ase_awk_setoption (handle, option); - return S_OK; -} - -STDMETHODIMP CAwk::get_VariableShading(BOOL *pVal) -{ - if (handle != NULL) option = ase_awk_getoption (handle); - *pVal = (option & ASE_AWK_SHADING) == 1; - return S_OK; -} - -STDMETHODIMP CAwk::put_VariableShading(BOOL newVal) -{ - if (newVal) option = option | ASE_AWK_SHADING; - else option = option & ~ASE_AWK_SHADING; - if (handle != NULL) ase_awk_setoption (handle, option); - return S_OK; -} - -STDMETHODIMP CAwk::get_ShiftOperators(BOOL *pVal) -{ - if (handle != NULL) option = ase_awk_getoption (handle); - *pVal = (option & ASE_AWK_SHIFT) == 1; - return S_OK; -} - -STDMETHODIMP CAwk::put_ShiftOperators(BOOL newVal) -{ - if (newVal) option = option | ASE_AWK_SHIFT; - else option = option & ~ASE_AWK_SHIFT; - if (handle != NULL) ase_awk_setoption (handle, option); - return S_OK; -} - -STDMETHODIMP CAwk::get_IdivOperator(BOOL *pVal) -{ - if (handle != NULL) option = ase_awk_getoption (handle); - *pVal = (option & ASE_AWK_IDIV) == 1; - return S_OK; -} - -STDMETHODIMP CAwk::put_IdivOperator(BOOL newVal) -{ - if (newVal) option = option | ASE_AWK_IDIV; - else option = option & ~ASE_AWK_IDIV; - if (handle != NULL) ase_awk_setoption (handle, option); - return S_OK; -} - -STDMETHODIMP CAwk::get_ConcatString(BOOL *pVal) -{ - if (handle != NULL) option = ase_awk_getoption (handle); - *pVal = (option & ASE_AWK_STRCONCAT) == 1; - return S_OK; -} - -STDMETHODIMP CAwk::put_ConcatString(BOOL newVal) -{ - if (newVal) option = option | ASE_AWK_STRCONCAT; - else option = option & ~ASE_AWK_STRCONCAT; - if (handle != NULL) ase_awk_setoption (handle, option); - return S_OK; -} - -STDMETHODIMP CAwk::get_SupportExtio(BOOL *pVal) -{ - if (handle != NULL) option = ase_awk_getoption (handle); - *pVal = (option & ASE_AWK_EXTIO) == 1; - return S_OK; -} - -STDMETHODIMP CAwk::put_SupportExtio(BOOL newVal) -{ - if (newVal) option = option | ASE_AWK_EXTIO; - else option = option & ~ASE_AWK_EXTIO; - if (handle != NULL) ase_awk_setoption (handle, option); - return S_OK; -} - -STDMETHODIMP CAwk::get_SupportBlockless(BOOL *pVal) -{ - if (handle != NULL) option = ase_awk_getoption (handle); - *pVal = (option & ASE_AWK_BLOCKLESS) == 1; - return S_OK; -} - -STDMETHODIMP CAwk::put_SupportBlockless(BOOL newVal) -{ - if (newVal) option = option | ASE_AWK_BLOCKLESS; - else option = option & ~ASE_AWK_BLOCKLESS; - if (handle != NULL) ase_awk_setoption (handle, option); - return S_OK; -} - -STDMETHODIMP CAwk::get_StringBaseOne(BOOL *pVal) -{ - if (handle != NULL) option = ase_awk_getoption (handle); - *pVal = (option & ASE_AWK_STRBASEONE) == 1; - return S_OK; -} - -STDMETHODIMP CAwk::put_StringBaseOne(BOOL newVal) -{ - if (newVal) option = option | ASE_AWK_STRBASEONE; - else option = option & ~ASE_AWK_STRBASEONE; - if (handle != NULL) ase_awk_setoption (handle, option); - return S_OK; -} - -STDMETHODIMP CAwk::get_StripSpaces(BOOL *pVal) -{ - if (handle != NULL) option = ase_awk_getoption (handle); - *pVal = (option & ASE_AWK_STRIPSPACES) == 1; - return S_OK; -} - -STDMETHODIMP CAwk::put_StripSpaces(BOOL newVal) -{ - if (newVal) option = option | ASE_AWK_STRIPSPACES; - else option = option & ~ASE_AWK_STRIPSPACES; - if (handle != NULL) ase_awk_setoption (handle, option); - return S_OK; -} - -STDMETHODIMP CAwk::get_Nextofile(BOOL *pVal) -{ - if (handle != NULL) option = ase_awk_getoption (handle); - *pVal = (option & ASE_AWK_NEXTOFILE) == 1; - return S_OK; -} - -STDMETHODIMP CAwk::put_Nextofile(BOOL newVal) -{ - if (newVal) option = option | ASE_AWK_NEXTOFILE; - else option = option & ~ASE_AWK_NEXTOFILE; - if (handle != NULL) ase_awk_setoption (handle, option); - return S_OK; -} - -STDMETHODIMP CAwk::get_UseCrlf(BOOL *pVal) -{ - if (handle != NULL) option = ase_awk_getoption (handle); - *pVal = (option & ASE_AWK_CRLF) == 1; - return S_OK; -} - -STDMETHODIMP CAwk::put_UseCrlf(BOOL newVal) -{ - if (newVal) option = option | ASE_AWK_CRLF; - else option = option & ~ASE_AWK_CRLF; - if (handle != NULL) ase_awk_setoption (handle, option); - return S_OK; -} - -STDMETHODIMP CAwk::get_MaxDepthForBlockParse(int *pVal) -{ - if (handle != NULL) - { - max_depth.block.parse = - ase_awk_getmaxdepth (handle, ASE_AWK_DEPTH_BLOCK_PARSE); - } - *pVal = max_depth.block.parse; - return S_OK; -} - -STDMETHODIMP CAwk::put_MaxDepthForBlockParse(int newVal) -{ - max_depth.block.parse = newVal; - if (handle != NULL) - { - ase_awk_setmaxdepth (handle, - ASE_AWK_DEPTH_BLOCK_PARSE, max_depth.block.parse); - } - return S_OK; -} - -STDMETHODIMP CAwk::get_MaxDepthForBlockRun(int *pVal) -{ - if (handle != NULL) - { - max_depth.block.run = - ase_awk_getmaxdepth (handle, ASE_AWK_DEPTH_BLOCK_RUN); - } - *pVal = max_depth.block.run; - return S_OK; -} - -STDMETHODIMP CAwk::put_MaxDepthForBlockRun(int newVal) -{ - max_depth.block.run = newVal; - if (handle != NULL) - { - ase_awk_setmaxdepth (handle, - ASE_AWK_DEPTH_BLOCK_RUN, max_depth.block.run); - } - return S_OK; -} - -STDMETHODIMP CAwk::get_MaxDepthForExprParse(int *pVal) -{ - if (handle != NULL) - { - max_depth.expr.parse = - ase_awk_getmaxdepth (handle, ASE_AWK_DEPTH_EXPR_PARSE); - } - *pVal = max_depth.expr.parse; - return S_OK; -} - -STDMETHODIMP CAwk::put_MaxDepthForExprParse(int newVal) -{ - max_depth.expr.parse = newVal; - if (handle != NULL) - { - ase_awk_setmaxdepth (handle, - ASE_AWK_DEPTH_EXPR_PARSE, max_depth.expr.parse); - } - return S_OK; -} - -STDMETHODIMP CAwk::get_MaxDepthForExprRun(int *pVal) -{ - if (handle != NULL) - { - max_depth.expr.run = - ase_awk_getmaxdepth (handle, ASE_AWK_DEPTH_EXPR_RUN); - } - *pVal = max_depth.expr.run; - return S_OK; -} - -STDMETHODIMP CAwk::put_MaxDepthForExprRun(int newVal) -{ - max_depth.expr.run = newVal; - if (handle != NULL) - { - ase_awk_setmaxdepth (handle, - ASE_AWK_DEPTH_EXPR_RUN, max_depth.expr.run); - } - return S_OK; -} - -STDMETHODIMP CAwk::get_MaxDepthForRexBuild(int *pVal) -{ - if (handle != NULL) - { - max_depth.rex.build = - ase_awk_getmaxdepth (handle, ASE_AWK_DEPTH_REX_BUILD); - } - *pVal = max_depth.rex.build; - return S_OK; -} - -STDMETHODIMP CAwk::put_MaxDepthForRexBuild(int newVal) -{ - max_depth.rex.build = newVal; - if (handle != NULL) - { - ase_awk_setmaxdepth (handle, - ASE_AWK_DEPTH_REX_BUILD, max_depth.rex.build); - } - return S_OK; -} - -STDMETHODIMP CAwk::get_MaxDepthForRexMatch(int *pVal) -{ - if (handle != NULL) - { - max_depth.rex.match = - ase_awk_getmaxdepth (handle, ASE_AWK_DEPTH_REX_MATCH); - } - *pVal = max_depth.rex.match; - return S_OK; -} - -STDMETHODIMP CAwk::put_MaxDepthForRexMatch(int newVal) -{ - max_depth.rex.match = newVal; - if (handle != NULL) - { - ase_awk_setmaxdepth (handle, - ASE_AWK_DEPTH_REX_MATCH, max_depth.rex.match); - } - return S_OK; -} - -STDMETHODIMP CAwk::get_EntryPoint(BSTR *pVal) -{ - if (entry_point == NULL) *pVal = NULL; - else - { - BSTR tmp = SysAllocStringLen ( - entry_point, SysStringLen(entry_point)); - if (tmp == NULL) return E_OUTOFMEMORY; - *pVal = tmp; - } - - return S_OK; -} - -STDMETHODIMP CAwk::put_EntryPoint(BSTR newVal) -{ - if (entry_point != NULL) SysFreeString (entry_point); - if (newVal == NULL) entry_point = newVal; - else - { - entry_point = SysAllocStringLen (newVal, SysStringLen(newVal)); - if (entry_point == NULL) return E_OUTOFMEMORY; - } - - return S_OK; -} - -STDMETHODIMP CAwk::get_Debug(BOOL *pVal) -{ - *pVal = debug; - return S_OK; -} - -STDMETHODIMP CAwk::put_Debug(BOOL newVal) -{ - debug = newVal; - return S_OK; -} - -STDMETHODIMP CAwk::get_UseLongLong(BOOL *pVal) -{ - *pVal = use_longlong; - return S_OK; -} - -STDMETHODIMP CAwk::put_UseLongLong(BOOL newVal) -{ - use_longlong = newVal; - return S_OK; -} diff --git a/ase/com/Awk.h b/ase/com/Awk.h deleted file mode 100644 index 1b5fe1ef..00000000 --- a/ase/com/Awk.h +++ /dev/null @@ -1,162 +0,0 @@ -/* - * $Id: Awk.h,v 1.1.1.1 2007/03/28 14:05:23 bacon Exp $ - * - * {License} - */ - -#ifndef _ASE_COM_AWK_H_ -#define _ASE_COM_AWK_H_ - -#if _MSC_VER > 1000 -#pragma once -#endif - -#include "resource.h" -#include "asecom.h" -#include -#include -#include "awk_cp.h" - -///////////////////////////////////////////////////////////////////////////// -// CAwk - -class CAwk : - public IDispatchImpl, - public ISupportErrorInfo, - /*public CComObjectRoot,*/ - public CComObjectRootEx, - public CComCoClass, - public IConnectionPointContainerImpl, - public IProvideClassInfo2Impl<&CLSID_Awk, &DIID_IAwkEvents, &LIBID_ASELib>, - public CProxyIAwkEvents< CAwk > - -{ -public: - ase_awk_t* handle; - int option; - int errnum; - ase_size_t errlin; - ase_char_t errmsg[256]; - - struct - { - struct - { - int parse; - int run; - } block; - struct - { - int parse; - int run; - } expr; - struct - { - int build; - int match; - } rex; - } max_depth; - - IBuffer* read_src_buf; - IBuffer* write_src_buf; - ase_size_t read_src_pos; - ase_size_t read_src_len; - - IBuffer* write_extio_buf; - - struct bfn_t - { - struct - { - TCHAR* ptr; - size_t len; - } name; - size_t min_args; - size_t max_args; - struct bfn_t* next; - } * bfn_list; - - BSTR entry_point; - BOOL debug; - BOOL use_longlong; -public: - CAwk(); - ~CAwk (); - -BEGIN_COM_MAP(CAwk) - COM_INTERFACE_ENTRY(IDispatch) - COM_INTERFACE_ENTRY(IAwk) - COM_INTERFACE_ENTRY(ISupportErrorInfo) - COM_INTERFACE_ENTRY_IMPL(IConnectionPointContainer) - COM_INTERFACE_ENTRY(IProvideClassInfo) - COM_INTERFACE_ENTRY(IProvideClassInfo2) -END_COM_MAP() - -BEGIN_CONNECTION_POINT_MAP(CAwk) -CONNECTION_POINT_ENTRY(DIID_IAwkEvents) -END_CONNECTION_POINT_MAP() - -//DECLARE_NOT_AGGREGATABLE(CAwk) -// Remove the comment from the line above if you don't want your object to -// support aggregation. - -DECLARE_REGISTRY_RESOURCEID(IDR_AWK) -// ISupportsErrorInfo - STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid); - -// IAwk -public: - STDMETHOD(put_UseLongLong)(/*[in]*/ BOOL newVal); - STDMETHOD(get_Debug)(/*[out, retval]*/ BOOL *pVal); - STDMETHOD(put_Debug)(/*[in]*/ BOOL newVal); - STDMETHOD(get_EntryPoint)(/*[out, retval]*/ BSTR *pVal); - STDMETHOD(put_EntryPoint)(/*[in]*/ BSTR newVal); - STDMETHOD(get_MaxDepthForRexMatch)(/*[out, retval]*/ int *pVal); - STDMETHOD(put_MaxDepthForRexMatch)(/*[in]*/ int newVal); - STDMETHOD(get_MaxDepthForRexBuild)(/*[out, retval]*/ int *pVal); - STDMETHOD(put_MaxDepthForRexBuild)(/*[in]*/ int newVal); - STDMETHOD(get_MaxDepthForExprRun)(/*[out, retval]*/ int *pVal); - STDMETHOD(put_MaxDepthForExprRun)(/*[in]*/ int newVal); - STDMETHOD(get_MaxDepthForExprParse)(/*[out, retval]*/ int *pVal); - STDMETHOD(put_MaxDepthForExprParse)(/*[in]*/ int newVal); - STDMETHOD(get_MaxDepthForBlockRun)(/*[out, retval]*/ int *pVal); - STDMETHOD(put_MaxDepthForBlockRun)(/*[in]*/ int newVal); - STDMETHOD(get_MaxDepthForBlockParse)(/*[out, retval]*/ int *pVal); - STDMETHOD(put_MaxDepthForBlockParse)(/*[in]*/ int newVal); - STDMETHOD(get_UseCrlf)(/*[out, retval]*/ BOOL *pVal); - STDMETHOD(put_UseCrlf)(/*[in]*/ BOOL newVal); - STDMETHOD(get_Nextofile)(/*[out, retval]*/ BOOL *pVal); - STDMETHOD(put_Nextofile)(/*[in]*/ BOOL newVal); - STDMETHOD(get_StripSpaces)(/*[out, retval]*/ BOOL *pVal); - STDMETHOD(put_StripSpaces)(/*[in]*/ BOOL newVal); - STDMETHOD(get_StringBaseOne)(/*[out, retval]*/ BOOL *pVal); - STDMETHOD(put_StringBaseOne)(/*[in]*/ BOOL newVal); - STDMETHOD(get_SupportBlockless)(/*[out, retval]*/ BOOL *pVal); - STDMETHOD(put_SupportBlockless)(/*[in]*/ BOOL newVal); - STDMETHOD(get_SupportExtio)(/*[out, retval]*/ BOOL *pVal); - STDMETHOD(put_SupportExtio)(/*[in]*/ BOOL newVal); - STDMETHOD(get_ConcatString)(/*[out, retval]*/ BOOL *pVal); - STDMETHOD(put_ConcatString)(/*[in]*/ BOOL newVal); - STDMETHOD(get_IdivOperator)(/*[out, retval]*/ BOOL *pVal); - STDMETHOD(put_IdivOperator)(/*[in]*/ BOOL newVal); - STDMETHOD(get_ShiftOperators)(/*[out, retval]*/ BOOL *pVal); - STDMETHOD(put_ShiftOperators)(/*[in]*/ BOOL newVal); - STDMETHOD(get_VariableShading)(/*[out, retval]*/ BOOL *pVal); - STDMETHOD(put_VariableShading)(/*[in]*/ BOOL newVal); - STDMETHOD(get_UniqueFunction)(/*[out, retval]*/ BOOL *pVal); - STDMETHOD(put_UniqueFunction)(/*[in]*/ BOOL newVal); - STDMETHOD(get_ExplicitVariable)(/*[out, retval]*/ BOOL *pVal); - STDMETHOD(put_ExplicitVariable)(/*[in]*/ BOOL newVal); - STDMETHOD(get_ImplicitVariable)(/*[out, retval]*/ BOOL *pVal); - STDMETHOD(put_ImplicitVariable)(/*[in]*/ BOOL newVal); - STDMETHOD(get_ErrorMessage)(/*[out, retval]*/ BSTR *pVal); - STDMETHOD(get_ErrorLine)(/*[out, retval]*/ int *pVal); - STDMETHOD(get_ErrorCode)(/*[out, retval]*/ int *pVal); - STDMETHOD(DeleteBuiltinFunction)(/*[in]*/ BSTR name, /*[out, retval]*/ int* ret); - STDMETHOD(AddBuiltinFunction)(/*[in]*/ BSTR name, /*[in]*/ int min_args, /*[in]*/ int max_args, /*[out, retval]*/ int* ret); - STDMETHOD(get_UseLongLong)(/*[out, retval]*/ BOOL *pVal); - HRESULT __stdcall Parse (/*[out, retval]*/ int* ret); - HRESULT __stdcall Run (/*[out, retval]*/ int* ret); -}; - -#endif diff --git a/ase/com/Awk.rgs b/ase/com/Awk.rgs deleted file mode 100644 index 14991e89..00000000 --- a/ase/com/Awk.rgs +++ /dev/null @@ -1,25 +0,0 @@ -HKCR -{ - ASE.Awk.1 = s 'ASE Awk Class' - { - CLSID = s '{AD863B53-F5EC-45C3-8B1C-6AC678227DC8}' - } - ASE.Awk = s 'ASE Awk Class' - { - CLSID = s '{AD863B53-F5EC-45C3-8B1C-6AC678227DC8}' - } - NoRemove CLSID - { - ForceRemove {AD863B53-F5EC-45C3-8B1C-6AC678227DC8} = s 'ASE Awk Class' - { - ProgID = s 'ASE.Awk.1' - VersionIndependentProgID = s 'ASE.Awk' - ForceRemove 'Programmable' - InprocServer32 = s '%MODULE%' - { - val ThreadingModel = s 'Apartment' - } - 'TypeLib' = s '{F9C69806-16A1-4162-998A-876B33C470BF}' - } - } -} diff --git a/ase/com/AwkExtio.cpp b/ase/com/AwkExtio.cpp deleted file mode 100644 index 635a938e..00000000 --- a/ase/com/AwkExtio.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* - * $Id: AwkExtio.cpp,v 1.1.1.1 2007/03/28 14:05:22 bacon Exp $ - * - * {License} - */ - -#include "stdafx.h" -#include "asecom.h" -#include "AwkExtio.h" - -#include -///////////////////////////////////////////////////////////////////////////// -// CAwkExtio - -CAwkExtio::CAwkExtio (): name (NULL) -{ - VariantInit (&handle); -} - -CAwkExtio::~CAwkExtio () -{ - if (name != NULL) SysFreeString (name); - VariantClear (&handle); -} - -STDMETHODIMP CAwkExtio::get_Name (BSTR *pVal) -{ - if (name == NULL) *pVal = name; - else - { - BSTR tmp = SysAllocStringLen (name, SysStringLen(name)); - if (tmp == NULL) return E_OUTOFMEMORY; - *pVal = tmp; - } - - return S_OK; -} - -BOOL CAwkExtio::PutName (const TCHAR* val) -{ - if (name != NULL) SysFreeString (name); - name = SysAllocString (val); - return (name == NULL)? FALSE: TRUE; -} - -STDMETHODIMP CAwkExtio::get_Type(int *pVal) -{ - *pVal = type; - return S_OK; -} - -STDMETHODIMP CAwkExtio::get_Mode(int *pVal) -{ - *pVal = mode; - return S_OK; -} - -STDMETHODIMP CAwkExtio::get_Handle (VARIANT *pVal) -{ - VariantClear (pVal); - VariantCopy (pVal, &handle); - return S_OK; -} - -STDMETHODIMP CAwkExtio::put_Handle (VARIANT newVal) -{ - VariantClear (&handle); - VariantCopy (&handle, &newVal); - return S_OK; -} diff --git a/ase/com/AwkExtio.h b/ase/com/AwkExtio.h deleted file mode 100644 index d4451559..00000000 --- a/ase/com/AwkExtio.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * $Id: AwkExtio.h,v 1.1.1.1 2007/03/28 14:05:23 bacon Exp $ - * - * {License} - */ - -#ifndef _ASE_COM_AWKEXTIO_H_ -#define _ASE_COM_AWKEXTIO_H_ - -#include "resource.h" -#include - -///////////////////////////////////////////////////////////////////////////// -// CAwkExtio -class ATL_NO_VTABLE CAwkExtio : - public CComObjectRootEx, - public CComCoClass, - public IDispatchImpl -{ -public: - BSTR name; - int type; - int mode; - VARIANT handle; - - IBuffer* read_buf; - ase_size_t read_buf_pos; - ase_size_t read_buf_len; - - BOOL PutName (const TCHAR* val); - - CAwkExtio (); - ~CAwkExtio (); - -DECLARE_REGISTRY_RESOURCEID(IDR_AWKEXTIO) - -DECLARE_PROTECT_FINAL_CONSTRUCT() - -BEGIN_COM_MAP(CAwkExtio) - COM_INTERFACE_ENTRY(IAwkExtio) - COM_INTERFACE_ENTRY(IDispatch) -END_COM_MAP() - -// IAwkExtio -public: - STDMETHOD(get_Handle)(/*[out, retval]*/ VARIANT *pVal); - STDMETHOD(put_Handle)(/*[in]*/ VARIANT newVal); - STDMETHOD(get_Mode)(/*[out, retval]*/ int *pVal); - STDMETHOD(get_Type)(/*[out, retval]*/ int *pVal); - STDMETHOD(get_Name)(/*[out, retval]*/ BSTR *pVal); -}; - -#endif //__AWKEXTIO_H_ diff --git a/ase/com/AwkExtio.rgs b/ase/com/AwkExtio.rgs deleted file mode 100644 index 25dd5757..00000000 --- a/ase/com/AwkExtio.rgs +++ /dev/null @@ -1,26 +0,0 @@ -HKCR -{ - ASE.AwkExtio.1 = s 'ASE AwkExtio Class' - { - CLSID = s '{F52F065A-5FD4-4F4D-AFEA-F5E446B16383}' - } - ASE.AwkExtio = s 'ASE AwkExtio Class' - { - CLSID = s '{F52F065A-5FD4-4F4D-AFEA-F5E446B16383}' - CurVer = s 'ASE.AwkExtio.1' - } - NoRemove CLSID - { - ForceRemove {F52F065A-5FD4-4F4D-AFEA-F5E446B16383} = s 'ASE AwkExtio Class' - { - ProgID = s 'ASE.AwkExtio.1' - VersionIndependentProgID = s 'ASE.AwkExtio' - ForceRemove 'Programmable' - InprocServer32 = s '%MODULE%' - { - val ThreadingModel = s 'Apartment' - } - 'TypeLib' = s '{F9C69806-16A1-4162-998A-876B33C470BF}' - } - } -} diff --git a/ase/com/Buffer.cpp b/ase/com/Buffer.cpp deleted file mode 100644 index 0ef56310..00000000 --- a/ase/com/Buffer.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * $Id: Buffer.cpp,v 1.1.1.1 2007/03/28 14:05:23 bacon Exp $ - * - * {License} - */ - -#include "stdafx.h" -#include "Buffer.h" - -CBuffer::CBuffer () -{ - str = NULL; -} - -CBuffer::~CBuffer () -{ - if (str != NULL) SysFreeString (str); -} - -STDMETHODIMP CBuffer::get_Value (BSTR *pVal) -{ - if (str == NULL) *pVal = NULL; - else - { - BSTR tmp = SysAllocStringLen(str, SysStringLen(str)); - if (tmp == NULL) return E_OUTOFMEMORY; - *pVal = tmp; - } - - return S_OK; -} - -STDMETHODIMP CBuffer::put_Value (BSTR newVal) -{ - if (str != NULL) SysFreeString (str); - if (newVal == NULL) str = newVal; - else - { - str = SysAllocStringLen (newVal, SysStringLen(newVal)); - if (str == NULL) return E_OUTOFMEMORY; - } - - return S_OK; -} - -BOOL CBuffer::PutValue (const TCHAR* val, SIZE_T len) -{ - if (str != NULL) SysFreeString (str); - str = SysAllocStringLen (val, len); - return (str == NULL)? FALSE: TRUE; -} diff --git a/ase/com/Buffer.h b/ase/com/Buffer.h deleted file mode 100644 index 472b1472..00000000 --- a/ase/com/Buffer.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * $Id: Buffer.h,v 1.1.1.1 2007/03/28 14:05:23 bacon Exp $ - * - * {License} - */ - -#ifndef _ASE_COM_BUFFER_H_ -#define _ASE_COM_BUFFER_H_ - -#include "resource.h" -#include "asecom.h" - -class ATL_NO_VTABLE CBuffer : - public CComObjectRootEx, - public CComCoClass, - public IDispatchImpl -{ -public: - BSTR str; - BOOL PutValue (const TCHAR* val, SIZE_T len); - -public: - CBuffer (); - ~CBuffer (); - -DECLARE_REGISTRY_RESOURCEID(IDR_BUFFER) - -DECLARE_PROTECT_FINAL_CONSTRUCT() - -BEGIN_COM_MAP(CBuffer) - COM_INTERFACE_ENTRY(IBuffer) - COM_INTERFACE_ENTRY(IDispatch) -END_COM_MAP() - -public: - STDMETHOD(get_Value)(/*[out, retval]*/ BSTR *pVal); - STDMETHOD(put_Value)(/*[in]*/ BSTR newVal); -}; - -#endif diff --git a/ase/com/Buffer.rgs b/ase/com/Buffer.rgs deleted file mode 100644 index e4ffa37e..00000000 --- a/ase/com/Buffer.rgs +++ /dev/null @@ -1,26 +0,0 @@ -HKCR -{ - ASE.Buffer.1 = s 'ASE Buffer Class' - { - CLSID = s '{866B79A7-7628-4808-8AE7-784BE2491C80}' - } - ASE.Buffer = s 'ASE Buffer Class' - { - CLSID = s '{866B79A7-7628-4808-8AE7-784BE2491C80}' - CurVer = s 'ASE.Buffer.1' - } - NoRemove CLSID - { - ForceRemove {866B79A7-7628-4808-8AE7-784BE2491C80} = s 'ASE Buffer Class' - { - ProgID = s 'ASE.Buffer.1' - VersionIndependentProgID = s 'ASE.Buffer' - ForceRemove 'Programmable' - InprocServer32 = s '%MODULE%' - { - val ThreadingModel = s 'Apartment' - } - 'TypeLib' = s '{F9C69806-16A1-4162-998A-876B33C470BF}' - } - } -} diff --git a/ase/com/asecom.cpp b/ase/com/asecom.cpp deleted file mode 100644 index 54e1c01e..00000000 --- a/ase/com/asecom.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* - * $Id: asecom.cpp,v 1.1.1.1 2007/03/28 14:05:23 bacon Exp $ - * - * {License} - */ - -// Note: Proxy/Stub Information -// To build a separate proxy/stub DLL, -// run nmake -f aseps.mk in the project directory. - -#include "stdafx.h" -#include "resource.h" -#include -#include "asecom.h" - -#include "asecom_i.c" -#include "Awk.h" -#include "Buffer.h" -#include "AwkExtio.h" - -CComModule _Module; - -BEGIN_OBJECT_MAP(ObjectMap) -OBJECT_ENTRY(CLSID_Awk, CAwk) -OBJECT_ENTRY(CLSID_Buffer, CBuffer) -OBJECT_ENTRY(CLSID_AwkExtio, CAwkExtio) -END_OBJECT_MAP() - -///////////////////////////////////////////////////////////////////////////// -// DLL Entry Point - -extern "C" -BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/) -{ - if (dwReason == DLL_PROCESS_ATTACH) - { - _Module.Init(ObjectMap, hInstance, &LIBID_ASELib); - DisableThreadLibraryCalls(hInstance); - } - else if (dwReason == DLL_PROCESS_DETACH) - _Module.Term(); - return TRUE; // ok -} - -///////////////////////////////////////////////////////////////////////////// -// Used to determine whether the DLL can be unloaded by OLE - -STDAPI DllCanUnloadNow(void) -{ - return (_Module.GetLockCount()==0) ? S_OK : S_FALSE; -} - -///////////////////////////////////////////////////////////////////////////// -// Returns a class factory to create an object of the requested type - -STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv) -{ - return _Module.GetClassObject(rclsid, riid, ppv); -} - -///////////////////////////////////////////////////////////////////////////// -// DllRegisterServer - Adds entries to the system registry - -STDAPI DllRegisterServer(void) -{ - // registers object, typelib and all interfaces in typelib - return _Module.RegisterServer(TRUE); -} - -///////////////////////////////////////////////////////////////////////////// -// DllUnregisterServer - Removes entries from the system registry - -STDAPI DllUnregisterServer(void) -{ - return _Module.UnregisterServer(TRUE); -} - - diff --git a/ase/com/asecom.def b/ase/com/asecom.def deleted file mode 100644 index 66d3ab70..00000000 --- a/ase/com/asecom.def +++ /dev/null @@ -1,9 +0,0 @@ -; ase.def : Declares the module parameters. - -LIBRARY "asecom.dll" - -EXPORTS - DllCanUnloadNow @1 PRIVATE - DllGetClassObject @2 PRIVATE - DllRegisterServer @3 PRIVATE - DllUnregisterServer @4 PRIVATE diff --git a/ase/com/asecom.dsp b/ase/com/asecom.dsp deleted file mode 100644 index 48767653..00000000 --- a/ase/com/asecom.dsp +++ /dev/null @@ -1,211 +0,0 @@ -# Microsoft Developer Studio Project File - Name="asecom" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 - -CFG=asecom - Win32 Debug -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "asecom.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "asecom.mak" CFG="asecom - Win32 Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "asecom - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE "asecom - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -MTL=midl.exe -RSC=rc.exe - -!IF "$(CFG)" == "asecom - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "../debug/lib" -# PROP Intermediate_Dir "debug" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MTd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_USRDLL" /D "_UNICODE" /Yu"stdafx.h" /FD /GZ /c -# ADD CPP /nologo /MTd /W3 /Gm /ZI /Od /I "../.." /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_USRDLL" /D "_UNICODE" /FR /Yu"stdafx.h" /FD /GZ /c -# ADD BASE RSC /l 0x409 /d "_DEBUG" -# ADD RSC /l 0x409 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo /o"debug/asecom.bsc" -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept -# ADD LINK32 aseawk.lib asecmn.lib aseutl.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /implib:"debug/asecom.lib" /pdbtype:sept /libpath:"$(OutDir)" -# Begin Custom Build - Performing registration -IntDir=./debug -OutDir=./../debug/lib -#TargetPath=\projects\ase\debug\lib\asecom.dll -#InputPath=\projects\ase\debug\lib\asecom.dll -#SOURCE="$(InputPath)" - -"$(IntDir)\regsvr32.trg" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - copy .\asecom.tlb "$(OUTDIR)\asecom.tlb" - if "%OS%"=="" goto NOTNT - if not "%OS%"=="Windows_NT" goto NOTNT - regsvr32 /s /c "$(TargetPath)" - echo regsvr32 exec. time > "$(IntDir)\regsvr32.trg" - goto end - :NOTNT - echo Warning : Cannot register DLL on Windows 95 - :end - -# End Custom Build - -!ELSEIF "$(CFG)" == "asecom - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "../release/lib" -# PROP Intermediate_Dir "release" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MT /W3 /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_USRDLL" /D "_UNICODE" /D "_ATL_STATIC_REGISTRY" /D "_ATL_MIN_CRT" /Yu"stdafx.h" /FD /c -# ADD CPP /nologo /MT /W3 /O1 /I "../.." /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_USRDLL" /D "_UNICODE" /D "_ATL_STATIC_REGISTRY" /Yu"stdafx.h" /FD /c -# ADD BASE RSC /l 0x409 /d "NDEBUG" -# ADD RSC /l 0x409 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo /o"release/awk.bsc" -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 -# ADD LINK32 aseawk.lib asecmn.lib aseutl.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 /implib:"release/asecom.lib" /libpath:"$(OutDir)" -# Begin Custom Build - Performing registration -IntDir=./release -OutDir=./../release/lib -#TargetPath=\projects\ase\release\lib\asecom.dll -#InputPath=\projects\ase\release\lib\asecom.dll -#SOURCE="$(InputPath)" - -"$(IntDir)\regsvr32.trg" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - copy .\asecom.tlb "$(OUTDIR)\asecom.tlb" - if "%OS%"=="" goto NOTNT - if not "%OS%"=="Windows_NT" goto NOTNT - regsvr32 /s /c "$(TargetPath)" - echo regsvr32 exec. time > "$(IntDir)\regsvr32.trg" - goto end - :NOTNT - echo Warning : Cannot register DLL on Windows 95 - :end - -# End Custom Build - -!ENDIF - -# Begin Target - -# Name "asecom - Win32 Debug" -# Name "asecom - Win32 Release" -# Begin Group "Source Files" - -# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" -# Begin Source File - -SOURCE=.\asecom.cpp -# End Source File -# Begin Source File - -SOURCE=.\asecom.def -# End Source File -# Begin Source File - -SOURCE=.\asecom.idl -# ADD MTL /tlb ".\asecom.tlb" /h "asecom.h" /iid "asecom_i.c" /Oicf -# End Source File -# Begin Source File - -SOURCE=.\asecom.rc -# End Source File -# Begin Source File - -SOURCE=.\Awk.cpp -# End Source File -# Begin Source File - -SOURCE=.\AwkExtio.cpp -# End Source File -# Begin Source File - -SOURCE=.\Buffer.cpp -# End Source File -# Begin Source File - -SOURCE=.\stdafx.cpp -# ADD CPP /Yc"stdafx.h" -# End Source File -# End Group -# Begin Group "Header Files" - -# PROP Default_Filter "h;hpp;hxx;hm;inl" -# Begin Source File - -SOURCE=.\Awk.h -# End Source File -# Begin Source File - -SOURCE=.\awk_cp.h -# End Source File -# Begin Source File - -SOURCE=.\AwkExtio.h -# End Source File -# Begin Source File - -SOURCE=.\Buffer.h -# End Source File -# Begin Source File - -SOURCE=.\resource.h -# End Source File -# Begin Source File - -SOURCE=.\stdafx.h -# End Source File -# Begin Source File - -SOURCE=.\xxx.h -# End Source File -# End Group -# Begin Group "Resource Files" - -# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" -# Begin Source File - -SOURCE=.\Awk.rgs -# End Source File -# Begin Source File - -SOURCE=.\AwkExtio.rgs -# End Source File -# Begin Source File - -SOURCE=.\Buffer.rgs -# End Source File -# End Group -# End Target -# End Project diff --git a/ase/com/asecom.idl b/ase/com/asecom.idl deleted file mode 100644 index 61edcef1..00000000 --- a/ase/com/asecom.idl +++ /dev/null @@ -1,303 +0,0 @@ -/* - * $Id: asecom.idl,v 1.1.1.1 2007/03/28 14:05:23 bacon Exp $ - */ - -import "oaidl.idl"; -import "ocidl.idl"; - -/* IAwk */ -[ - object, - uuid(05BC1C9F-7C4E-4F77-B186-2E0FD26C0641), - dual, - helpstring("ASE Awk Interface"), - pointer_default(unique) -] -interface IAwk : IDispatch -{ - [id(1), helpstring("method Parse")] - HRESULT Parse([out, retval] int* ret); - - [id(2), helpstring("method Run")] - HRESULT Run([out, retval] int* ret); - - [id(3), helpstring("method AddBuiltinFunction")] - HRESULT AddBuiltinFunction([in] BSTR name, [in] int min_args, [in] int max_args, [out, retval] int* ret); - - [id(4), helpstring("method DeleteBuiltinFunction")] - HRESULT DeleteBuiltinFunction([in] BSTR name, [out, retval] int* ret); - - [propget, id(5), helpstring("property ErrorCode")] - HRESULT ErrorCode([out, retval] int *pVal); - - [propget, id(6), helpstring("property ErrorLine")] - HRESULT ErrorLine([out, retval] int *pVal); - - [propget, id(7), helpstring("property ErrorMessage")] - HRESULT ErrorMessage([out, retval] BSTR *pVal); - - [propget, id(8), helpstring("property ImplicitVariable")] - HRESULT ImplicitVariable([out, retval] BOOL *pVal); - [propput, id(8), helpstring("property ImplicitVariable")] - HRESULT ImplicitVariable([in] BOOL newVal); - - [propget, id(9), helpstring("property ExplicitVariable")] - HRESULT ExplicitVariable([out, retval] BOOL *pVal); - [propput, id(9), helpstring("property ExplicitVariable")] - HRESULT ExplicitVariable([in] BOOL newVal); - - [propget, id(10), helpstring("property UniqueFunction")] - HRESULT UniqueFunction([out, retval] BOOL *pVal); - [propput, id(10), helpstring("property UniqueFunction")] - HRESULT UniqueFunction([in] BOOL newVal); - - [propget, id(11), helpstring("property VariableShading")] - HRESULT VariableShading([out, retval] BOOL *pVal); - [propput, id(11), helpstring("property VariableShading")] - HRESULT VariableShading([in] BOOL newVal); - - [propget, id(12), helpstring("property ShiftOperators")] - HRESULT ShiftOperators([out, retval] BOOL *pVal); - [propput, id(12), helpstring("property ShiftOperators")] - HRESULT ShiftOperators([in] BOOL newVal); - - [propget, id(13), helpstring("property IdivOperator")] - HRESULT IdivOperator([out, retval] BOOL *pVal); - [propput, id(13), helpstring("property IdivOperator")] - HRESULT IdivOperator([in] BOOL newVal); - - [propget, id(14), helpstring("property ConcatString")] - HRESULT ConcatString([out, retval] BOOL *pVal); - [propput, id(14), helpstring("property ConcatString")] - HRESULT ConcatString([in] BOOL newVal); - - [propget, id(15), helpstring("property SupportExtio")] - HRESULT SupportExtio([out, retval] BOOL *pVal); - [propput, id(15), helpstring("property SupportExtio")] - HRESULT SupportExtio([in] BOOL newVal); - - [propget, id(16), helpstring("property SupportBlockless")] - HRESULT SupportBlockless([out, retval] BOOL *pVal); - [propput, id(16), helpstring("property SupportBlockless")] - HRESULT SupportBlockless([in] BOOL newVal); - - [propget, id(17), helpstring("property StringBaseOne")] - HRESULT StringBaseOne([out, retval] BOOL *pVal); - [propput, id(17), helpstring("property StringBaseOne")] - HRESULT StringBaseOne([in] BOOL newVal); - - [propget, id(18), helpstring("property StripSpaces")] - HRESULT StripSpaces([out, retval] BOOL *pVal); - [propput, id(18), helpstring("property StripSpaces")] - HRESULT StripSpaces([in] BOOL newVal); - - [propget, id(19), helpstring("property Nextofile")] - HRESULT Nextofile([out, retval] BOOL *pVal); - [propput, id(19), helpstring("property Nextofile")] - HRESULT Nextofile([in] BOOL newVal); - - [propget, id(20), helpstring("property UseCrlf")] - HRESULT UseCrlf([out, retval] BOOL *pVal); - [propput, id(20), helpstring("property UseCrlf")] - HRESULT UseCrlf([in] BOOL newVal); - - [propget, id(21), helpstring("property MaxDepthForBlockParse")] - HRESULT MaxDepthForBlockParse([out, retval] int *pVal); - [propput, id(21), helpstring("property MaxDepthForBlockParse")] - HRESULT MaxDepthForBlockParse([in] int newVal); - - [propget, id(22), helpstring("property MaxDepthForBlockRun")] - HRESULT MaxDepthForBlockRun([out, retval] int *pVal); - [propput, id(22), helpstring("property MaxDepthForBlockRun")] - HRESULT MaxDepthForBlockRun([in] int newVal); - - [propget, id(23), helpstring("property MaxDepthForExprParse")] - HRESULT MaxDepthForExprParse([out, retval] int *pVal); - [propput, id(23), helpstring("property MaxDepthForExprParse")] - HRESULT MaxDepthForExprParse([in] int newVal); - - [propget, id(24), helpstring("property MaxDepthForExprRun")] - HRESULT MaxDepthForExprRun([out, retval] int *pVal); - [propput, id(24), helpstring("property MaxDepthForExprRun")] - HRESULT MaxDepthForExprRun([in] int newVal); - - [propget, id(25), helpstring("property MaxDepthForRexBuild")] - HRESULT MaxDepthForRexBuild([out, retval] int *pVal); - [propput, id(25), helpstring("property MaxDepthForRexBuild")] - HRESULT MaxDepthForRexBuild([in] int newVal); - - [propget, id(26), helpstring("property MaxDepthForRexMatch")] - HRESULT MaxDepthForRexMatch([out, retval] int *pVal); - [propput, id(26), helpstring("property MaxDepthForRexMatch")] - HRESULT MaxDepthForRexMatch([in] int newVal); - - [propget, id(27), helpstring("property EntryPoint")] - HRESULT EntryPoint([out, retval] BSTR *pVal); - [propput, id(27), helpstring("property EntryPoint")] - HRESULT EntryPoint([in] BSTR newVal); - - [propget, id(28), helpstring("property Debug")] - HRESULT Debug([out, retval] BOOL *pVal); - [propput, id(28), helpstring("property Debug")] - HRESULT Debug([in] BOOL newVal); - - [propget, id(29), helpstring("property UseLongLong")] - HRESULT UseLongLong([out, retval] BOOL *pVal); - [propput, id(29), helpstring("property UseLongLong")] - HRESULT UseLongLong([in] BOOL newVal); -}; - -/* ASELib */ -[ - uuid(F9C69806-16A1-4162-998A-876B33C470BF), - version(1.0), - helpstring("ASE 1.0 Type Library") -] -library ASELib -{ - importlib("stdole32.tlb"); - importlib("stdole2.tlb"); - - [helpstring("AwkExtio tpe")] - typedef [v1_enum] enum AwkExtioType - { - AWK_EXTIO_PIPE = 0, - AWK_EXTIO_COPROC = 1, - AWK_EXTIO_FILE = 2, - AWK_EXTIO_CONSOLE = 3 - } AwkExtioType; - - [helpstring("AwkExtio mode")] - typedef [v1_enum] enum AwkExtioMode - { - AWK_EXTIO_PIPE_READ = 0, - AWK_EXTIO_PIPE_WRITE = 1, - - AWK_EXTIO_COPROC_READ = 0, - AWK_EXTIO_COPROC_WRITE = 1, - AWK_EXTIO_COPROC_RDWR = 2, - - AWK_EXTIO_FILE_READ = 0, - AWK_EXTIO_FILE_WRITE = 1, - AWK_EXTIO_FILE_APPEND = 2, - - AWK_EXTIO_CONSOLE_READ = 0, - AWK_EXTIO_CONSOLE_WRITE = 1 - } AwkExtioMode; - - /* IBuffer */ - [ - object, - uuid(AD5EA986-37E9-410E-A78E-21799104293A), - dual, - helpstring("IBuffer Interface"), - pointer_default(unique) - ] - interface IBuffer : IDispatch - { - [propget, id(1), helpstring("property Value")] - HRESULT Value([out, retval] BSTR *pVal); - - [propput, id(1), helpstring("property Value")] - HRESULT Value([in] BSTR newVal); - }; - - /* IAwkExtio */ - [ - object, - uuid(BE0B91FF-9944-4DFC-A55B-1FE14E24AFEE), - dual, - helpstring("IAwkExtio Interface"), - pointer_default(unique) - ] - interface IAwkExtio : IDispatch - { - [propget, id(1), helpstring("property Name")] - HRESULT Name([out, retval] BSTR *pVal); - - [propget, id(2), helpstring("property Type")] - HRESULT Type([out, retval] int *pVal); - - [propget, id(3), helpstring("property Mode")] - HRESULT Mode([out, retval] int *pVal); - - [propget, id(4), helpstring("property Handle")] - HRESULT Handle([out, retval] VARIANT *pVal); - [propput, id(4), helpstring("property Handle")] - HRESULT Handle([in] VARIANT newVal); - }; - - /* IAwkEvents */ - [ - uuid(1351DC8F-10AD-4C40-A2FA-9A2E89C27AC8), - helpstring("ASE Awk Events Interface") - ] - dispinterface IAwkEvents - { - properties: - methods: - [id(1), helpstring("open the source code")] - int OpenSource([in] int mode); - - [id(2), helpstring("close the source code")] - int CloseSource([in] int mode); - - [id(3), helpstring("read the source code")] - int ReadSource([in] IBuffer* buf); - - [id(4), helpstring("write the source code")] - int WriteSource([in] IBuffer* buf); - - [id(5), helpstring("method OpenExtio")] - int OpenExtio([in] IAwkExtio* extio); - - [id(6), helpstring("method CloseExtio")] - int CloseExtio([in] IAwkExtio* extio); - - [id(7), helpstring("method ReadExtio")] - int ReadExtio([in] IAwkExtio* extio, [in] IBuffer* buf); - - [id(8), helpstring("method WriteExtio")] - int WriteExtio([in] IAwkExtio* extio, [in] IBuffer* buf); - - [id(9), helpstring("method FlushExtio")] - int FlushExtio([in] IAwkExtio* extio); - - [id(10), helpstring("method NextExtio")] - int NextExtio([in] IAwkExtio* extio); - - [id(11), helpstring("method HandleBuiltinFunction")] - int HandleBuiltinFunction([in] BSTR name, [in] VARIANT argarray, [out, retval] VARIANT* ret); - }; - - /* Awk */ - [ - uuid(AD863B53-F5EC-45C3-8B1C-6AC678227DC8), - helpstring("ASE Awk Class") - ] - coclass Awk - { - [default] interface IAwk; - [default,source] dispinterface IAwkEvents; - }; - - /* AwkExtio */ - [ - uuid(F52F065A-5FD4-4F4D-AFEA-F5E446B16383), - helpstring("ASE AwkExtio Class") - ] - coclass AwkExtio - { - [default] interface IAwkExtio; - }; - - /* Buffer */ - [ - uuid(866B79A7-7628-4808-8AE7-784BE2491C80), - helpstring("ASE Buffer Class") - ] - coclass Buffer - { - [default] interface IBuffer; - }; -}; diff --git a/ase/com/asecom.rc b/ase/com/asecom.rc deleted file mode 100644 index df9571c1..00000000 --- a/ase/com/asecom.rc +++ /dev/null @@ -1,126 +0,0 @@ -//Microsoft Developer Studio generated resource script. -// -#include "resource.h" - -#define APSTUDIO_READONLY_SYMBOLS -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 2 resource. -// -#include "winres.h" - -///////////////////////////////////////////////////////////////////////////// -#undef APSTUDIO_READONLY_SYMBOLS - -///////////////////////////////////////////////////////////////////////////// -// English (U.S.) resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) -#ifdef _WIN32 -LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US -#pragma code_page(1252) -#endif //_WIN32 - -#ifdef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// TEXTINCLUDE -// - -1 TEXTINCLUDE DISCARDABLE -BEGIN - "resource.h\0" -END - -2 TEXTINCLUDE DISCARDABLE -BEGIN - "#include ""winres.h""\r\n" - "\0" -END - -3 TEXTINCLUDE DISCARDABLE -BEGIN - "1 TYPELIB ""asecom.tlb""\r\n" - "\0" -END - -#endif // APSTUDIO_INVOKED - - -#ifndef _MAC -///////////////////////////////////////////////////////////////////////////// -// -// Version -// - -VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,0,0,1 - PRODUCTVERSION 1,0,0,1 - FILEFLAGSMASK 0x3fL -#ifdef _DEBUG - FILEFLAGS 0x1L -#else - FILEFLAGS 0x0L -#endif - FILEOS 0x4L - FILETYPE 0x2L - FILESUBTYPE 0x0L -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904B0" - BEGIN - VALUE "CompanyName", "\0" - VALUE "FileDescription", "ASE COM Module\0" - VALUE "FileVersion", "1, 0, 0, 1\0" - VALUE "InternalName", "ASE\0" - VALUE "LegalCopyright", "Copyright 2006\0" - VALUE "OriginalFilename", "asecom.dll\0" - VALUE "ProductName", "ASE COM Module\0" - VALUE "ProductVersion", "1, 0, 0, 1\0" - VALUE "OLESelfRegister", "\0" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x409, 1200 - END -END - -#endif // !_MAC - - -///////////////////////////////////////////////////////////////////////////// -// -// REGISTRY -// - -IDR_AWK REGISTRY DISCARDABLE "Awk.rgs" -IDR_AWKEXTIO REGISTRY DISCARDABLE "AwkExtio.rgs" -IDR_BUFFER REGISTRY DISCARDABLE "Buffer.rgs" - -///////////////////////////////////////////////////////////////////////////// -// -// String Table -// - -STRINGTABLE DISCARDABLE -BEGIN - IDS_PROJNAME "ASE COM Project" -END - -#endif // English (U.S.) resources -///////////////////////////////////////////////////////////////////////////// - - - -#ifndef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 3 resource. -// -1 TYPELIB "asecom.tlb" - -///////////////////////////////////////////////////////////////////////////// -#endif // not APSTUDIO_INVOKED - diff --git a/ase/com/aseps.def b/ase/com/aseps.def deleted file mode 100644 index 291123a5..00000000 --- a/ase/com/aseps.def +++ /dev/null @@ -1,11 +0,0 @@ - -LIBRARY "asePS" - -DESCRIPTION 'Proxy/Stub DLL' - -EXPORTS - DllGetClassObject @1 PRIVATE - DllCanUnloadNow @2 PRIVATE - GetProxyDllInfo @3 PRIVATE - DllRegisterServer @4 PRIVATE - DllUnregisterServer @5 PRIVATE diff --git a/ase/com/aseps.mk b/ase/com/aseps.mk deleted file mode 100644 index 5093ad12..00000000 --- a/ase/com/aseps.mk +++ /dev/null @@ -1,16 +0,0 @@ - -aseps.dll: dlldata.obj ase_p.obj ase_i.obj - link /dll /out:aseps.dll /def:aseps.def /entry:DllMain dlldata.obj ase_p.obj ase_i.obj \ - kernel32.lib rpcndr.lib rpcns4.lib rpcrt4.lib oleaut32.lib uuid.lib \ - -.c.obj: - cl /c /Ox /DWIN32 /D_WIN32_WINNT=0x0400 /DREGISTER_PROXY_DLL \ - $< - -clean: - @del aseps.dll - @del aseps.lib - @del aseps.exp - @del dlldata.obj - @del ase_p.obj - @del ase_i.obj diff --git a/ase/com/awk_cp.h b/ase/com/awk_cp.h deleted file mode 100644 index f0f98de5..00000000 --- a/ase/com/awk_cp.h +++ /dev/null @@ -1,601 +0,0 @@ -/* - * $Id: awk_cp.h,v 1.1.1.1 2007/03/28 14:05:23 bacon Exp $ - * - * {License} - */ - -#ifndef _AWK_CP_H_ -#define _AWK_CP_H_ - -template -class CProxyIAwkEvents: - public IConnectionPointImpl -{ -public: - INT Fire_OpenSource(INT mode) - { - T* pT = static_cast(this); - int i, nconns = m_vec.GetSize(); - CComVariant args[1], ret; - - for (i = 0; i < nconns; i++) - { - pT->Lock(); - CComPtr sp = m_vec.GetAt(i); - pT->Unlock(); - - IDispatch* pDispatch = - reinterpret_cast(sp.p); - if (pDispatch == NULL) continue; - - VariantClear (&ret); - VariantClear (&args[0]); - - args[0] = mode; - - DISPPARAMS disp = { args, NULL, 1, 0 }; - HRESULT hr = pDispatch->Invoke ( - 0x1, IID_NULL, LOCALE_USER_DEFAULT, - DISPATCH_METHOD, &disp, &ret, NULL, NULL); - if (FAILED(hr)) continue; - - if (ret.vt == VT_EMPTY) - { - /* probably, the handler has not been implemeted*/ - continue; - } - - hr = ret.ChangeType (VT_I4); - if (FAILED(hr)) - { - /* TODO: set the error code properly... */ - /* invalid value returned... */ - return -1; - } - - return ret.lVal; - } - - return -1; - } - - INT Fire_CloseSource(INT mode) - { - T* pT = static_cast(this); - int i, nconns = m_vec.GetSize(); - CComVariant args[1], ret; - - for (i = 0; i < nconns; i++) - { - pT->Lock(); - CComPtr sp = m_vec.GetAt(i); - pT->Unlock(); - - IDispatch* pDispatch = - reinterpret_cast(sp.p); - if (pDispatch == NULL) continue; - - VariantClear (&ret); - VariantClear (&args[0]); - - args[0] = mode; - - DISPPARAMS disp = { args, NULL, 1, 0 }; - HRESULT hr = pDispatch->Invoke ( - 0x2, IID_NULL, LOCALE_USER_DEFAULT, - DISPATCH_METHOD, &disp, &ret, NULL, NULL); - if (FAILED(hr)) continue; - - if (ret.vt == VT_EMPTY) - { - /* probably, the handler has not been implemeted*/ - continue; - } - - hr = ret.ChangeType (VT_I4); - if (FAILED(hr)) - { - /* TODO: set the error code properly... */ - /* invalid value returned... */ - return -1; - } - - return ret.lVal; - } - - return -1; - } - - INT Fire_ReadSource (IBuffer* buf) - { - T* pT = static_cast(this); - int i, nconns = m_vec.GetSize(); - CComVariant args[1], ret; - - for (i = 0; i < nconns; i++) - { - pT->Lock(); - CComPtr sp = m_vec.GetAt(i); - pT->Unlock(); - - IDispatch* pDispatch = - reinterpret_cast(sp.p); - if (pDispatch == NULL) continue; - - VariantClear (&ret); - VariantClear (&args[0]); - - args[0] = (IUnknown*)buf; - - DISPPARAMS disp = { args, NULL, 1, 0 }; - HRESULT hr = pDispatch->Invoke ( - 0x3, IID_NULL, LOCALE_USER_DEFAULT, - DISPATCH_METHOD, &disp, &ret, NULL, NULL); - if (FAILED(hr)) - { - continue; - } - - if (ret.vt == VT_EMPTY) - { - /* probably, the handler has not been implemeted*/ - continue; - } - - hr = ret.ChangeType (VT_I4); - if (FAILED(hr)) - { - /* TODO: set the error code properly... */ - /* invalid value returned... */ - return -1; - } - - return ret.lVal; - } - - /* no event handler attached for the source code read. */ - /* TODO: set error code ... */ - return -1; - } - - INT Fire_WriteSource (IBuffer* buf) - { - T* pT = static_cast(this); - int i, nconns = m_vec.GetSize(); - CComVariant args[1], ret; - - for (i = 0; i < nconns; i++) - { - pT->Lock(); - CComPtr sp = m_vec.GetAt(i); - pT->Unlock(); - - IDispatch* pDispatch = - reinterpret_cast(sp.p); - if (pDispatch == NULL) continue; - - VariantClear (&ret); - VariantClear (&args[0]); - - args[0] = (IUnknown*)buf; - - DISPPARAMS disp = { args, NULL, 1, 0 }; - HRESULT hr = pDispatch->Invoke ( - 0x4, IID_NULL, LOCALE_USER_DEFAULT, - DISPATCH_METHOD, &disp, &ret, NULL, NULL); - if (FAILED(hr)) - { - continue; - } - - if (ret.vt == VT_EMPTY) - { - /* probably, the handler has not been implemeted*/ - continue; - } - - hr = ret.ChangeType (VT_I4); - if (FAILED(hr)) - { - /* TODO: set the error code properly... */ - /* invalid value returned... */ - return -1; - } - - return ret.lVal; - } - - /* no event handler attached for the source code write. - * make the operation succeed by returning the reqested - * data length. */ - CComBSTR bstr; - buf->get_Value (&bstr); - return bstr.Length(); - } - - INT Fire_OpenExtio (IAwkExtio* extio) - { - T* pT = static_cast(this); - int i, nconns = m_vec.GetSize(); - CComVariant args[1], ret; - - for (i = 0; i < nconns; i++) - { - pT->Lock(); - CComPtr sp = m_vec.GetAt(i); - pT->Unlock(); - - IDispatch* pDispatch = - reinterpret_cast(sp.p); - if (pDispatch == NULL) continue; - - VariantClear (&ret); - VariantClear (&args[0]); - - args[0] = (IUnknown*)extio; - - DISPPARAMS disp = { args, NULL, 1, 0 }; - HRESULT hr = pDispatch->Invoke ( - 0x5, IID_NULL, LOCALE_USER_DEFAULT, - DISPATCH_METHOD, &disp, &ret, NULL, NULL); - if (FAILED(hr)) continue; - - if (ret.vt == VT_EMPTY) - { - /* probably, the handler has not been implemeted*/ - continue; - } - - hr = ret.ChangeType (VT_I4); - if (FAILED(hr)) - { - /* TODO: set the error code properly... */ - /* invalid value returned... */ - return -1; - } - - return ret.lVal; - } - - return -1; - } - - INT Fire_CloseExtio (IAwkExtio* extio) - { - T* pT = static_cast(this); - int i, nconns = m_vec.GetSize(); - CComVariant args[1], ret; - - for (i = 0; i < nconns; i++) - { - pT->Lock(); - CComPtr sp = m_vec.GetAt(i); - pT->Unlock(); - - IDispatch* pDispatch = - reinterpret_cast(sp.p); - if (pDispatch == NULL) continue; - - VariantClear (&ret); - VariantClear (&args[0]); - - args[0] = (IUnknown*)extio; - - DISPPARAMS disp = { args, NULL, 1, 0 }; - HRESULT hr = pDispatch->Invoke ( - 0x6, IID_NULL, LOCALE_USER_DEFAULT, - DISPATCH_METHOD, &disp, &ret, NULL, NULL); - if (FAILED(hr)) continue; - - if (ret.vt == VT_EMPTY) - { - /* probably, the handler has not been implemeted*/ - continue; - } - - hr = ret.ChangeType (VT_I4); - if (FAILED(hr)) - { - /* TODO: set the error code properly... */ - /* invalid value returned... */ - return -1; - } - - return ret.lVal; - } - - return -1; - } - - INT Fire_ReadExtio (IAwkExtio* extio, IBuffer* buf) - { - T* pT = static_cast(this); - int i, nconns = m_vec.GetSize(); - CComVariant args[2], ret; - - for (i = 0; i < nconns; i++) - { - pT->Lock(); - CComPtr sp = m_vec.GetAt(i); - pT->Unlock(); - - IDispatch* pDispatch = - reinterpret_cast(sp.p); - if (pDispatch == NULL) continue; - - VariantClear (&ret); - VariantClear (&args[0]); - VariantClear (&args[1]); - - args[1] = (IUnknown*)extio; - args[0] = (IUnknown*)buf; - - DISPPARAMS disp = { args, NULL, 2, 0 }; - HRESULT hr = pDispatch->Invoke ( - 0x7, IID_NULL, LOCALE_USER_DEFAULT, - DISPATCH_METHOD, &disp, &ret, NULL, NULL); - if (FAILED(hr)) - { - continue; - } - - if (ret.vt == VT_EMPTY) - { - /* probably, the handler has not been implemeted*/ - continue; - } - - hr = ret.ChangeType (VT_I4); - if (FAILED(hr)) - { - /* TODO: set the error code properly... */ - /* invalid value returned... */ - return -1; - } - - return ret.lVal; - } - - return -1; - } - - INT Fire_WriteExtio (IAwkExtio* extio, IBuffer* buf) - { - T* pT = static_cast(this); - int i, nconns = m_vec.GetSize(); - CComVariant args[2], ret; - - for (i = 0; i < nconns; i++) - { - pT->Lock(); - CComPtr sp = m_vec.GetAt(i); - pT->Unlock(); - - IDispatch* pDispatch = - reinterpret_cast(sp.p); - if (pDispatch == NULL) continue; - - VariantClear (&ret); - VariantClear (&args[0]); - VariantClear (&args[1]); - - args[1] = (IUnknown*)extio; - args[0] = (IUnknown*)buf; - - DISPPARAMS disp = { args, NULL, 2, 0 }; - HRESULT hr = pDispatch->Invoke ( - 0x8, IID_NULL, LOCALE_USER_DEFAULT, - DISPATCH_METHOD, &disp, &ret, NULL, NULL); - if (FAILED(hr)) - { - continue; - } - - if (ret.vt == VT_EMPTY) - { - /* probably, the handler has not been implemeted*/ - continue; - } - - hr = ret.ChangeType (VT_I4); - if (FAILED(hr)) - { - /* TODO: set the error code properly... */ - /* invalid value returned... */ - return -1; - } - - return ret.lVal; - } - - return -1; - } - - - INT Fire_FlushExtio (IAwkExtio* extio) - { - T* pT = static_cast(this); - int i, nconns = m_vec.GetSize(); - CComVariant args[1], ret; - - for (i = 0; i < nconns; i++) - { - pT->Lock(); - CComPtr sp = m_vec.GetAt(i); - pT->Unlock(); - - IDispatch* pDispatch = - reinterpret_cast(sp.p); - if (pDispatch == NULL) continue; - - VariantClear (&ret); - VariantClear (&args[0]); - - args[0] = (IUnknown*)extio; - - DISPPARAMS disp = { args, NULL, 1, 0 }; - HRESULT hr = pDispatch->Invoke ( - 0x9, IID_NULL, LOCALE_USER_DEFAULT, - DISPATCH_METHOD, &disp, &ret, NULL, NULL); - if (FAILED(hr)) continue; - - if (ret.vt == VT_EMPTY) - { - /* probably, the handler has not been implemeted*/ - continue; - } - - hr = ret.ChangeType (VT_I4); - if (FAILED(hr)) - { - /* TODO: set the error code properly... */ - /* invalid value returned... */ - return -1; - } - - return ret.lVal; - } - - return -1; - } - - INT Fire_NextExtio (IAwkExtio* extio) - { - T* pT = static_cast(this); - int i, nconns = m_vec.GetSize(); - CComVariant args[1], ret; - - for (i = 0; i < nconns; i++) - { - pT->Lock(); - CComPtr sp = m_vec.GetAt(i); - pT->Unlock(); - - IDispatch* pDispatch = - reinterpret_cast(sp.p); - if (pDispatch == NULL) continue; - - VariantClear (&ret); - VariantClear (&args[0]); - - args[0] = (IUnknown*)extio; - - DISPPARAMS disp = { args, NULL, 1, 0 }; - HRESULT hr = pDispatch->Invoke ( - 0xA, IID_NULL, LOCALE_USER_DEFAULT, - DISPATCH_METHOD, &disp, &ret, NULL, NULL); - if (FAILED(hr)) continue; - - if (ret.vt == VT_EMPTY) - { - /* probably, the handler has not been implemeted*/ - continue; - } - - hr = ret.ChangeType (VT_I4); - if (FAILED(hr)) - { - /* TODO: set the error code properly... */ - /* invalid value returned... */ - return -1; - } - - return ret.lVal; - } - - return -1; - } - - int Fire_HandleBuiltinFunction ( - ase_awk_run_t* run, BSTR name, SAFEARRAY* argarray, ase_awk_val_t** retv) - { - T* pT = static_cast(this); - int i, nconns = m_vec.GetSize(); - CComVariant ret; - VARIANT args[2]; - ase_awk_val_t* v; - - VariantInit (&args[0]); - VariantInit (&args[1]); - - args[1].vt = VT_BSTR; - args[1].bstrVal = name; - - args[0].vt = VT_ARRAY | VT_VARIANT; - args[0].parray = argarray; - - for (i = 0; i < nconns; i++) - { - pT->Lock(); - CComPtr sp = m_vec.GetAt(i); - pT->Unlock(); - - IDispatch* pDispatch = - reinterpret_cast(sp.p); - if (pDispatch == NULL) continue; - - VariantClear (&ret); - - DISPPARAMS disp = { args, NULL, 2, 0 }; - HRESULT hr = pDispatch->Invoke ( - 0xB, IID_NULL, LOCALE_USER_DEFAULT, - DISPATCH_METHOD, &disp, &ret, NULL, NULL); - if (FAILED(hr)) continue; - - if (ret.vt == VT_EMPTY) - { - /* probably, the handler has not been implemeted*/ - continue; - } - - VariantClear (&args[1]); - VariantClear (&args[0]); - - if (ret.vt == VT_I1) - v = ase_awk_makeintval (run, ret.cVal); - else if (ret.vt == VT_I2) - v = ase_awk_makeintval (run, ret.iVal); - else if (ret.vt == VT_I4) - v = ase_awk_makeintval (run, ret.lVal); - else if (ret.vt == VT_I8) - v = ase_awk_makeintval (run, ret.llVal); - else if (ret.vt == VT_UI1) - v = ase_awk_makeintval (run, ret.bVal); - else if (ret.vt == VT_UI2) - v = ase_awk_makeintval (run, ret.uiVal); - else if (ret.vt == VT_UI4) - v = ase_awk_makeintval (run, ret.ulVal); - else if (ret.vt == VT_UI8) - v = ase_awk_makeintval (run, ret.ullVal); - else if (ret.vt == VT_INT) - v = ase_awk_makeintval (run, ret.intVal); - else if (ret.vt == VT_UINT) - v = ase_awk_makeintval (run, ret.uintVal); - else if (ret.vt == VT_BOOL) - v = ase_awk_makeintval (run, ((ret.boolVal == 0)? 0: 1)); - else if (ret.vt == VT_R4) - v = ase_awk_makerealval (run, ret.fltVal); - else if (ret.vt == VT_R8) - v = ase_awk_makerealval (run, ret.dblVal); - else if (ret.vt == VT_BSTR) - v = ase_awk_makestrval (run, ret.bstrVal, SysStringLen(ret.bstrVal)); - else if (ret.vt == VT_NULL) - - v = ase_awk_val_nil; - else return 3; /* wrong return value */ - - if (v == ASE_NULL) return 1; /* out of memory */ - - *retv = v; - return 0; /* success */ - } - - VariantClear (&args[1]); - VariantClear (&args[0]); - return 2; /* no proper handler */ - } - - -}; - -#endif diff --git a/ase/com/resource.h b/ase/com/resource.h deleted file mode 100644 index 0c5f206a..00000000 --- a/ase/com/resource.h +++ /dev/null @@ -1,19 +0,0 @@ -//{{NO_DEPENDENCIES}} -// Microsoft Developer Studio generated include file. -// Used by ase.rc -// -#define IDS_PROJNAME 100 -#define IDR_AWK 101 -#define IDR_AWKEXTIO 102 -#define IDR_BUFFER 103 - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 201 -#define _APS_NEXT_COMMAND_VALUE 32768 -#define _APS_NEXT_CONTROL_VALUE 201 -#define _APS_NEXT_SYMED_VALUE 105 -#endif -#endif diff --git a/ase/com/stdafx.cpp b/ase/com/stdafx.cpp deleted file mode 100644 index 84568a5f..00000000 --- a/ase/com/stdafx.cpp +++ /dev/null @@ -1,18 +0,0 @@ -/* - * $Id: stdafx.cpp,v 1.1.1.1 2007/03/28 14:05:23 bacon Exp $ - * - * {License} - */ - -// stdafx.cpp : source file that includes just the standard includes -// stdafx.pch will be the pre-compiled header -// stdafx.obj will contain the pre-compiled type information - -#include "stdafx.h" - -#ifdef _ATL_STATIC_REGISTRY -#include -#include -#endif - -#include diff --git a/ase/com/stdafx.h b/ase/com/stdafx.h deleted file mode 100644 index 7955d52e..00000000 --- a/ase/com/stdafx.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * $Id: stdafx.h,v 1.1.1.1 2007/03/28 14:05:23 bacon Exp $ - * - * {License} - */ - -#ifndef _ASE_COM_STDAFX_H_ -#define _ASE_COM_STDAFX_H_ - -#if _MSC_VER > 1000 -#pragma once -#endif // _MSC_VER > 1000 - -#define STRICT -#ifndef _WIN32_WINNT -#define _WIN32_WINNT 0x0400 -#endif -#define _ATL_APARTMENT_THREADED - -#include -//You may derive a class from CComModule and use it if you want to override -//something, but do not change the name of _Module -extern CComModule _Module; -#include - -//{{AFX_INSERT_LOCATION}} -// Microsoft Visual C++ will insert additional declarations immediately before the previous line. - -#endif diff --git a/ase/configure b/ase/configure deleted file mode 100755 index 1233e620..00000000 --- a/ase/configure +++ /dev/null @@ -1,11056 +0,0 @@ -#! /bin/sh -# From configure.ac Revision: 1.78 . -# Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.59 for ase deb-0.1.0. -# -# Copyright (C) 2003 Free Software Foundation, Inc. -# This configure script is free software; the Free Software Foundation -# gives unlimited permission to copy, distribute and modify it. -## --------------------- ## -## M4sh Initialization. ## -## --------------------- ## - -# Be Bourne compatible -if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then - emulate sh - NULLCMD=: - # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which - # is contrary to our usage. Disable this feature. - alias -g '${1+"$@"}'='"$@"' -elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then - set -o posix -fi -DUALCASE=1; export DUALCASE # for MKS sh - -# Support unset when possible. -if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then - as_unset=unset -else - as_unset=false -fi - - -# Work around bugs in pre-3.0 UWIN ksh. -$as_unset ENV MAIL MAILPATH -PS1='$ ' -PS2='> ' -PS4='+ ' - -# NLS nuisances. -for as_var in \ - LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \ - LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \ - LC_TELEPHONE LC_TIME -do - if (set +x; test -z "`(eval $as_var=C; export $as_var) 2>&1`"); then - eval $as_var=C; export $as_var - else - $as_unset $as_var - fi -done - -# Required to use basename. -if expr a : '\(a\)' >/dev/null 2>&1; then - as_expr=expr -else - as_expr=false -fi - -if (basename /) >/dev/null 2>&1 && test "X`basename / 2>&1`" = "X/"; then - as_basename=basename -else - as_basename=false -fi - - -# Name of the executable. -as_me=`$as_basename "$0" || -$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ - X"$0" : 'X\(//\)$' \| \ - X"$0" : 'X\(/\)$' \| \ - . : '\(.\)' 2>/dev/null || -echo X/"$0" | - sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/; q; } - /^X\/\(\/\/\)$/{ s//\1/; q; } - /^X\/\(\/\).*/{ s//\1/; q; } - s/.*/./; q'` - - -# PATH needs CR, and LINENO needs CR and PATH. -# Avoid depending upon Character Ranges. -as_cr_letters='abcdefghijklmnopqrstuvwxyz' -as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' -as_cr_Letters=$as_cr_letters$as_cr_LETTERS -as_cr_digits='0123456789' -as_cr_alnum=$as_cr_Letters$as_cr_digits - -# The user is always right. -if test "${PATH_SEPARATOR+set}" != set; then - echo "#! /bin/sh" >conf$$.sh - echo "exit 0" >>conf$$.sh - chmod +x conf$$.sh - if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then - PATH_SEPARATOR=';' - else - PATH_SEPARATOR=: - fi - rm -f conf$$.sh -fi - - - as_lineno_1=$LINENO - as_lineno_2=$LINENO - as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null` - test "x$as_lineno_1" != "x$as_lineno_2" && - test "x$as_lineno_3" = "x$as_lineno_2" || { - # Find who we are. Look in the path if we contain no path at all - # relative or not. - case $0 in - *[\\/]* ) as_myself=$0 ;; - *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break -done - - ;; - esac - # We did not find ourselves, most probably we were run as `sh COMMAND' - # in which case we are not to be found in the path. - if test "x$as_myself" = x; then - as_myself=$0 - fi - if test ! -f "$as_myself"; then - { echo "$as_me: error: cannot find myself; rerun with an absolute path" >&2 - { (exit 1); exit 1; }; } - fi - case $CONFIG_SHELL in - '') - as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for as_base in sh bash ksh sh5; do - case $as_dir in - /*) - if ("$as_dir/$as_base" -c ' - as_lineno_1=$LINENO - as_lineno_2=$LINENO - as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null` - test "x$as_lineno_1" != "x$as_lineno_2" && - test "x$as_lineno_3" = "x$as_lineno_2" ') 2>/dev/null; then - $as_unset BASH_ENV || test "${BASH_ENV+set}" != set || { BASH_ENV=; export BASH_ENV; } - $as_unset ENV || test "${ENV+set}" != set || { ENV=; export ENV; } - CONFIG_SHELL=$as_dir/$as_base - export CONFIG_SHELL - exec "$CONFIG_SHELL" "$0" ${1+"$@"} - fi;; - esac - done -done -;; - esac - - # Create $as_me.lineno as a copy of $as_myself, but with $LINENO - # uniformly replaced by the line number. The first 'sed' inserts a - # line-number line before each line; the second 'sed' does the real - # work. The second script uses 'N' to pair each line-number line - # with the numbered line, and appends trailing '-' during - # substitution so that $LINENO is not a special case at line end. - # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the - # second 'sed' script. Blame Lee E. McMahon for sed's syntax. :-) - sed '=' <$as_myself | - sed ' - N - s,$,-, - : loop - s,^\(['$as_cr_digits']*\)\(.*\)[$]LINENO\([^'$as_cr_alnum'_]\),\1\2\1\3, - t loop - s,-$,, - s,^['$as_cr_digits']*\n,, - ' >$as_me.lineno && - chmod +x $as_me.lineno || - { echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2 - { (exit 1); exit 1; }; } - - # Don't try to exec as it changes $[0], causing all sort of problems - # (the dirname of $[0] is not the place where we might find the - # original and so on. Autoconf is especially sensible to this). - . ./$as_me.lineno - # Exit status is that of the last command. - exit -} - - -case `echo "testing\c"; echo 1,2,3`,`echo -n testing; echo 1,2,3` in - *c*,-n*) ECHO_N= ECHO_C=' -' ECHO_T=' ' ;; - *c*,* ) ECHO_N=-n ECHO_C= ECHO_T= ;; - *) ECHO_N= ECHO_C='\c' ECHO_T= ;; -esac - -if expr a : '\(a\)' >/dev/null 2>&1; then - as_expr=expr -else - as_expr=false -fi - -rm -f conf$$ conf$$.exe conf$$.file -echo >conf$$.file -if ln -s conf$$.file conf$$ 2>/dev/null; then - # We could just check for DJGPP; but this test a) works b) is more generic - # and c) will remain valid once DJGPP supports symlinks (DJGPP 2.04). - if test -f conf$$.exe; then - # Don't use ln at all; we don't have any links - as_ln_s='cp -p' - else - as_ln_s='ln -s' - fi -elif ln conf$$.file conf$$ 2>/dev/null; then - as_ln_s=ln -else - as_ln_s='cp -p' -fi -rm -f conf$$ conf$$.exe conf$$.file - -if mkdir -p . 2>/dev/null; then - as_mkdir_p=: -else - test -d ./-p && rmdir ./-p - as_mkdir_p=false -fi - -as_executable_p="test -f" - -# Sed expression to map a string onto a valid CPP name. -as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" - -# Sed expression to map a string onto a valid variable name. -as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" - - -# IFS -# We need space, tab and new line, in precisely that order. -as_nl=' -' -IFS=" $as_nl" - -# CDPATH. -$as_unset CDPATH - - -# Name of the host. -# hostname on some systems (SVR3.2, Linux) returns a bogus exit status, -# so uname gets run too. -ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q` - -exec 6>&1 - -# -# Initializations. -# -ac_default_prefix=/usr/local -ac_config_libobj_dir=. -cross_compiling=no -subdirs= -MFLAGS= -MAKEFLAGS= -SHELL=${CONFIG_SHELL-/bin/sh} - -# Maximum number of lines to put in a shell here document. -# This variable seems obsolete. It should probably be removed, and -# only ac_max_sed_lines should be used. -: ${ac_max_here_lines=38} - -# Identity of this package. -PACKAGE_NAME='ase' -PACKAGE_TARNAME='ase' -PACKAGE_VERSION='deb-0.1.0' -PACKAGE_STRING='ase deb-0.1.0' -PACKAGE_BUGREPORT='' - -# Factoring default headers for most tests. -ac_includes_default="\ -#include -#if HAVE_SYS_TYPES_H -# include -#endif -#if HAVE_SYS_STAT_H -# include -#endif -#if STDC_HEADERS -# include -# include -#else -# if HAVE_STDLIB_H -# include -# endif -#endif -#if HAVE_STRING_H -# if !STDC_HEADERS && HAVE_MEMORY_H -# include -# endif -# include -#endif -#if HAVE_STRINGS_H -# include -#endif -#if HAVE_INTTYPES_H -# include -#else -# if HAVE_STDINT_H -# include -# endif -#endif -#if HAVE_UNISTD_H -# include -#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 RANLIB ac_ct_RANLIB CPP EGREP BUILDMODE LIBOBJS LTLIBOBJS' -ac_subst_files='' - -# Initialize some variables set by options. -ac_init_help= -ac_init_version=false -# The variables have the same names as the options, with -# dashes changed to underlines. -cache_file=/dev/null -exec_prefix=NONE -no_create= -no_recursion= -prefix=NONE -program_prefix=NONE -program_suffix=NONE -program_transform_name=s,x,x, -silent= -site= -srcdir= -verbose= -x_includes=NONE -x_libraries=NONE - -# Installation directory options. -# These are left unexpanded so users can "make install exec_prefix=/foo" -# and all the variables that are supposed to be based on exec_prefix -# by default will actually change. -# Use braces instead of parens because sh, perl, etc. also accept them. -bindir='${exec_prefix}/bin' -sbindir='${exec_prefix}/sbin' -libexecdir='${exec_prefix}/libexec' -datadir='${prefix}/share' -sysconfdir='${prefix}/etc' -sharedstatedir='${prefix}/com' -localstatedir='${prefix}/var' -libdir='${exec_prefix}/lib' -includedir='${prefix}/include' -oldincludedir='/usr/include' -infodir='${prefix}/info' -mandir='${prefix}/man' - -ac_prev= -for ac_option -do - # If the previous option needs an argument, assign it. - if test -n "$ac_prev"; then - eval "$ac_prev=\$ac_option" - ac_prev= - continue - fi - - ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'` - - # Accept the important Cygnus configure options, so we can diagnose typos. - - case $ac_option in - - -bindir | --bindir | --bindi | --bind | --bin | --bi) - ac_prev=bindir ;; - -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) - bindir=$ac_optarg ;; - - -build | --build | --buil | --bui | --bu) - ac_prev=build_alias ;; - -build=* | --build=* | --buil=* | --bui=* | --bu=*) - build_alias=$ac_optarg ;; - - -cache-file | --cache-file | --cache-fil | --cache-fi \ - | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) - ac_prev=cache_file ;; - -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ - | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) - cache_file=$ac_optarg ;; - - --config-cache | -C) - cache_file=config.cache ;; - - -datadir | --datadir | --datadi | --datad | --data | --dat | --da) - ac_prev=datadir ;; - -datadir=* | --datadir=* | --datadi=* | --datad=* | --data=* | --dat=* \ - | --da=*) - datadir=$ac_optarg ;; - - -disable-* | --disable-*) - ac_feature=`expr "x$ac_option" : 'x-*disable-\(.*\)'` - # Reject names that are not valid shell variable names. - expr "x$ac_feature" : ".*[^-_$as_cr_alnum]" >/dev/null && - { echo "$as_me: error: invalid feature name: $ac_feature" >&2 - { (exit 1); exit 1; }; } - ac_feature=`echo $ac_feature | sed 's/-/_/g'` - eval "enable_$ac_feature=no" ;; - - -enable-* | --enable-*) - ac_feature=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` - # Reject names that are not valid shell variable names. - expr "x$ac_feature" : ".*[^-_$as_cr_alnum]" >/dev/null && - { echo "$as_me: error: invalid feature name: $ac_feature" >&2 - { (exit 1); exit 1; }; } - ac_feature=`echo $ac_feature | sed 's/-/_/g'` - case $ac_option in - *=*) ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`;; - *) ac_optarg=yes ;; - esac - eval "enable_$ac_feature='$ac_optarg'" ;; - - -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ - | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ - | --exec | --exe | --ex) - ac_prev=exec_prefix ;; - -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ - | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ - | --exec=* | --exe=* | --ex=*) - exec_prefix=$ac_optarg ;; - - -gas | --gas | --ga | --g) - # Obsolete; use --with-gas. - with_gas=yes ;; - - -help | --help | --hel | --he | -h) - ac_init_help=long ;; - -help=r* | --help=r* | --hel=r* | --he=r* | -hr*) - ac_init_help=recursive ;; - -help=s* | --help=s* | --hel=s* | --he=s* | -hs*) - ac_init_help=short ;; - - -host | --host | --hos | --ho) - ac_prev=host_alias ;; - -host=* | --host=* | --hos=* | --ho=*) - host_alias=$ac_optarg ;; - - -includedir | --includedir | --includedi | --included | --include \ - | --includ | --inclu | --incl | --inc) - ac_prev=includedir ;; - -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ - | --includ=* | --inclu=* | --incl=* | --inc=*) - includedir=$ac_optarg ;; - - -infodir | --infodir | --infodi | --infod | --info | --inf) - ac_prev=infodir ;; - -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) - infodir=$ac_optarg ;; - - -libdir | --libdir | --libdi | --libd) - ac_prev=libdir ;; - -libdir=* | --libdir=* | --libdi=* | --libd=*) - libdir=$ac_optarg ;; - - -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ - | --libexe | --libex | --libe) - ac_prev=libexecdir ;; - -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ - | --libexe=* | --libex=* | --libe=*) - libexecdir=$ac_optarg ;; - - -localstatedir | --localstatedir | --localstatedi | --localstated \ - | --localstate | --localstat | --localsta | --localst \ - | --locals | --local | --loca | --loc | --lo) - ac_prev=localstatedir ;; - -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ - | --localstate=* | --localstat=* | --localsta=* | --localst=* \ - | --locals=* | --local=* | --loca=* | --loc=* | --lo=*) - localstatedir=$ac_optarg ;; - - -mandir | --mandir | --mandi | --mand | --man | --ma | --m) - ac_prev=mandir ;; - -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) - mandir=$ac_optarg ;; - - -nfp | --nfp | --nf) - # Obsolete; use --without-fp. - with_fp=no ;; - - -no-create | --no-create | --no-creat | --no-crea | --no-cre \ - | --no-cr | --no-c | -n) - no_create=yes ;; - - -no-recursion | --no-recursion | --no-recursio | --no-recursi \ - | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) - no_recursion=yes ;; - - -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \ - | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \ - | --oldin | --oldi | --old | --ol | --o) - ac_prev=oldincludedir ;; - -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ - | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ - | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) - oldincludedir=$ac_optarg ;; - - -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) - ac_prev=prefix ;; - -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) - prefix=$ac_optarg ;; - - -program-prefix | --program-prefix | --program-prefi | --program-pref \ - | --program-pre | --program-pr | --program-p) - ac_prev=program_prefix ;; - -program-prefix=* | --program-prefix=* | --program-prefi=* \ - | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) - program_prefix=$ac_optarg ;; - - -program-suffix | --program-suffix | --program-suffi | --program-suff \ - | --program-suf | --program-su | --program-s) - ac_prev=program_suffix ;; - -program-suffix=* | --program-suffix=* | --program-suffi=* \ - | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) - program_suffix=$ac_optarg ;; - - -program-transform-name | --program-transform-name \ - | --program-transform-nam | --program-transform-na \ - | --program-transform-n | --program-transform- \ - | --program-transform | --program-transfor \ - | --program-transfo | --program-transf \ - | --program-trans | --program-tran \ - | --progr-tra | --program-tr | --program-t) - ac_prev=program_transform_name ;; - -program-transform-name=* | --program-transform-name=* \ - | --program-transform-nam=* | --program-transform-na=* \ - | --program-transform-n=* | --program-transform-=* \ - | --program-transform=* | --program-transfor=* \ - | --program-transfo=* | --program-transf=* \ - | --program-trans=* | --program-tran=* \ - | --progr-tra=* | --program-tr=* | --program-t=*) - program_transform_name=$ac_optarg ;; - - -q | -quiet | --quiet | --quie | --qui | --qu | --q \ - | -silent | --silent | --silen | --sile | --sil) - silent=yes ;; - - -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) - ac_prev=sbindir ;; - -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ - | --sbi=* | --sb=*) - sbindir=$ac_optarg ;; - - -sharedstatedir | --sharedstatedir | --sharedstatedi \ - | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ - | --sharedst | --shareds | --shared | --share | --shar \ - | --sha | --sh) - ac_prev=sharedstatedir ;; - -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \ - | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ - | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ - | --sha=* | --sh=*) - sharedstatedir=$ac_optarg ;; - - -site | --site | --sit) - ac_prev=site ;; - -site=* | --site=* | --sit=*) - site=$ac_optarg ;; - - -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) - ac_prev=srcdir ;; - -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) - srcdir=$ac_optarg ;; - - -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ - | --syscon | --sysco | --sysc | --sys | --sy) - ac_prev=sysconfdir ;; - -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ - | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) - sysconfdir=$ac_optarg ;; - - -target | --target | --targe | --targ | --tar | --ta | --t) - ac_prev=target_alias ;; - -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) - target_alias=$ac_optarg ;; - - -v | -verbose | --verbose | --verbos | --verbo | --verb) - verbose=yes ;; - - -version | --version | --versio | --versi | --vers | -V) - ac_init_version=: ;; - - -with-* | --with-*) - ac_package=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` - # Reject names that are not valid shell variable names. - expr "x$ac_package" : ".*[^-_$as_cr_alnum]" >/dev/null && - { echo "$as_me: error: invalid package name: $ac_package" >&2 - { (exit 1); exit 1; }; } - ac_package=`echo $ac_package| sed 's/-/_/g'` - case $ac_option in - *=*) ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`;; - *) ac_optarg=yes ;; - esac - eval "with_$ac_package='$ac_optarg'" ;; - - -without-* | --without-*) - ac_package=`expr "x$ac_option" : 'x-*without-\(.*\)'` - # Reject names that are not valid shell variable names. - expr "x$ac_package" : ".*[^-_$as_cr_alnum]" >/dev/null && - { echo "$as_me: error: invalid package name: $ac_package" >&2 - { (exit 1); exit 1; }; } - ac_package=`echo $ac_package | sed 's/-/_/g'` - eval "with_$ac_package=no" ;; - - --x) - # Obsolete; use --with-x. - with_x=yes ;; - - -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \ - | --x-incl | --x-inc | --x-in | --x-i) - ac_prev=x_includes ;; - -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ - | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) - x_includes=$ac_optarg ;; - - -x-libraries | --x-libraries | --x-librarie | --x-librari \ - | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) - ac_prev=x_libraries ;; - -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ - | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) - x_libraries=$ac_optarg ;; - - -*) { echo "$as_me: error: unrecognized option: $ac_option -Try \`$0 --help' for more information." >&2 - { (exit 1); exit 1; }; } - ;; - - *=*) - ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='` - # Reject names that are not valid shell variable names. - expr "x$ac_envvar" : ".*[^_$as_cr_alnum]" >/dev/null && - { echo "$as_me: error: invalid variable name: $ac_envvar" >&2 - { (exit 1); exit 1; }; } - ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` - eval "$ac_envvar='$ac_optarg'" - export $ac_envvar ;; - - *) - # FIXME: should be removed in autoconf 3.0. - echo "$as_me: WARNING: you should use --build, --host, --target" >&2 - expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && - echo "$as_me: WARNING: invalid host type: $ac_option" >&2 - : ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option} - ;; - - esac -done - -if test -n "$ac_prev"; then - ac_option=--`echo $ac_prev | sed 's/_/-/g'` - { echo "$as_me: error: missing argument to $ac_option" >&2 - { (exit 1); exit 1; }; } -fi - -# Be sure to have absolute paths. -for ac_var in exec_prefix prefix -do - eval ac_val=$`echo $ac_var` - case $ac_val in - [\\/$]* | ?:[\\/]* | NONE | '' ) ;; - *) { echo "$as_me: error: expected an absolute directory name for --$ac_var: $ac_val" >&2 - { (exit 1); exit 1; }; };; - esac -done - -# Be sure to have absolute paths. -for ac_var in bindir sbindir libexecdir datadir sysconfdir sharedstatedir \ - localstatedir libdir includedir oldincludedir infodir mandir -do - eval ac_val=$`echo $ac_var` - case $ac_val in - [\\/$]* | ?:[\\/]* ) ;; - *) { echo "$as_me: error: expected an absolute directory name for --$ac_var: $ac_val" >&2 - { (exit 1); exit 1; }; };; - esac -done - -# There might be people who depend on the old broken behavior: `$host' -# used to hold the argument of --host etc. -# FIXME: To remove some day. -build=$build_alias -host=$host_alias -target=$target_alias - -# FIXME: To remove some day. -if test "x$host_alias" != x; then - if test "x$build_alias" = x; then - cross_compiling=maybe - echo "$as_me: WARNING: If you wanted to set the --build type, don't use --host. - If a cross compiler is detected then cross compile mode will be used." >&2 - elif test "x$build_alias" != "x$host_alias"; then - cross_compiling=yes - fi -fi - -ac_tool_prefix= -test -n "$host_alias" && ac_tool_prefix=$host_alias- - -test "$silent" = yes && exec 6>/dev/null - - -# Find the source files, if location was not specified. -if test -z "$srcdir"; then - ac_srcdir_defaulted=yes - # Try the directory containing this script, then its parent. - ac_confdir=`(dirname "$0") 2>/dev/null || -$as_expr X"$0" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ - X"$0" : 'X\(//\)[^/]' \| \ - X"$0" : 'X\(//\)$' \| \ - X"$0" : 'X\(/\)' \| \ - . : '\(.\)' 2>/dev/null || -echo X"$0" | - sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; } - /^X\(\/\/\)[^/].*/{ s//\1/; q; } - /^X\(\/\/\)$/{ s//\1/; q; } - /^X\(\/\).*/{ s//\1/; q; } - s/.*/./; q'` - srcdir=$ac_confdir - if test ! -r $srcdir/$ac_unique_file; then - srcdir=.. - fi -else - ac_srcdir_defaulted=no -fi -if test ! -r $srcdir/$ac_unique_file; then - if test "$ac_srcdir_defaulted" = yes; then - { echo "$as_me: error: cannot find sources ($ac_unique_file) in $ac_confdir or .." >&2 - { (exit 1); exit 1; }; } - else - { echo "$as_me: error: cannot find sources ($ac_unique_file) in $srcdir" >&2 - { (exit 1); exit 1; }; } - fi -fi -(cd $srcdir && test -r ./$ac_unique_file) 2>/dev/null || - { echo "$as_me: error: sources are in $srcdir, but \`cd $srcdir' does not work" >&2 - { (exit 1); exit 1; }; } -srcdir=`echo "$srcdir" | sed 's%\([^\\/]\)[\\/]*$%\1%'` -ac_env_build_alias_set=${build_alias+set} -ac_env_build_alias_value=$build_alias -ac_cv_env_build_alias_set=${build_alias+set} -ac_cv_env_build_alias_value=$build_alias -ac_env_host_alias_set=${host_alias+set} -ac_env_host_alias_value=$host_alias -ac_cv_env_host_alias_set=${host_alias+set} -ac_cv_env_host_alias_value=$host_alias -ac_env_target_alias_set=${target_alias+set} -ac_env_target_alias_value=$target_alias -ac_cv_env_target_alias_set=${target_alias+set} -ac_cv_env_target_alias_value=$target_alias -ac_env_CC_set=${CC+set} -ac_env_CC_value=$CC -ac_cv_env_CC_set=${CC+set} -ac_cv_env_CC_value=$CC -ac_env_CFLAGS_set=${CFLAGS+set} -ac_env_CFLAGS_value=$CFLAGS -ac_cv_env_CFLAGS_set=${CFLAGS+set} -ac_cv_env_CFLAGS_value=$CFLAGS -ac_env_LDFLAGS_set=${LDFLAGS+set} -ac_env_LDFLAGS_value=$LDFLAGS -ac_cv_env_LDFLAGS_set=${LDFLAGS+set} -ac_cv_env_LDFLAGS_value=$LDFLAGS -ac_env_CPPFLAGS_set=${CPPFLAGS+set} -ac_env_CPPFLAGS_value=$CPPFLAGS -ac_cv_env_CPPFLAGS_set=${CPPFLAGS+set} -ac_cv_env_CPPFLAGS_value=$CPPFLAGS -ac_env_CPP_set=${CPP+set} -ac_env_CPP_value=$CPP -ac_cv_env_CPP_set=${CPP+set} -ac_cv_env_CPP_value=$CPP - -# -# Report the --help message. -# -if test "$ac_init_help" = "long"; then - # Omit some internal or obsolete options to make the list less imposing. - # This message is too long to be a string in the A/UX 3.1 sh. - cat <<_ACEOF -\`configure' configures ase deb-0.1.0 to adapt to many kinds of systems. - -Usage: $0 [OPTION]... [VAR=VALUE]... - -To assign environment variables (e.g., CC, CFLAGS...), specify them as -VAR=VALUE. See below for descriptions of some of the useful variables. - -Defaults for the options are specified in brackets. - -Configuration: - -h, --help display this help and exit - --help=short display options specific to this package - --help=recursive display the short help of all the included packages - -V, --version display version information and exit - -q, --quiet, --silent do not print \`checking...' messages - --cache-file=FILE cache test results in FILE [disabled] - -C, --config-cache alias for \`--cache-file=config.cache' - -n, --no-create do not create output files - --srcdir=DIR find the sources in DIR [configure dir or \`..'] - -_ACEOF - - cat <<_ACEOF -Installation directories: - --prefix=PREFIX install architecture-independent files in PREFIX - [$ac_default_prefix] - --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX - [PREFIX] - -By default, \`make install' will install all the files in -\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify -an installation prefix other than \`$ac_default_prefix' using \`--prefix', -for instance \`--prefix=\$HOME'. - -For better control, use the options below. - -Fine tuning of the installation directories: - --bindir=DIR user executables [EPREFIX/bin] - --sbindir=DIR system admin executables [EPREFIX/sbin] - --libexecdir=DIR program executables [EPREFIX/libexec] - --datadir=DIR read-only architecture-independent data [PREFIX/share] - --sysconfdir=DIR read-only single-machine data [PREFIX/etc] - --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] - --localstatedir=DIR modifiable single-machine data [PREFIX/var] - --libdir=DIR object code libraries [EPREFIX/lib] - --includedir=DIR C header files [PREFIX/include] - --oldincludedir=DIR C header files for non-gcc [/usr/include] - --infodir=DIR info documentation [PREFIX/info] - --mandir=DIR man documentation [PREFIX/man] -_ACEOF - - cat <<\_ACEOF -_ACEOF -fi - -if test -n "$ac_init_help"; then - case $ac_init_help in - short | recursive ) echo "Configuration of ase deb-0.1.0:";; - esac - cat <<\_ACEOF - -Optional Features: - --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) - --enable-FEATURE[=ARG] include FEATURE [ARG=yes] - --enable-wchar use wchar_t a default charater type when enabled - (default. yes) - --enable-debug build the library in the debug mode (default. no) - --enable-reentrant define _REENTRANT (default. yes) - -Some influential environment variables: - CC C compiler command - CFLAGS C compiler flags - LDFLAGS linker flags, e.g. -L if you have libraries in a - nonstandard directory - CPPFLAGS C/C++ preprocessor flags, e.g. -I if you have - headers in a nonstandard directory - CPP C preprocessor - -Use these variables to override the choices made by `configure' or to help -it to find libraries and programs with nonstandard names/locations. - -_ACEOF -fi - -if test "$ac_init_help" = "recursive"; then - # If there are subdirs, report their specific --help. - ac_popdir=`pwd` - for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue - test -d $ac_dir || continue - ac_builddir=. - -if test "$ac_dir" != .; then - ac_dir_suffix=/`echo "$ac_dir" | sed 's,^\.[\\/],,'` - # A "../" for each directory in $ac_dir_suffix. - ac_top_builddir=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,../,g'` -else - ac_dir_suffix= ac_top_builddir= -fi - -case $srcdir in - .) # No --srcdir option. We are building in place. - ac_srcdir=. - if test -z "$ac_top_builddir"; then - ac_top_srcdir=. - else - ac_top_srcdir=`echo $ac_top_builddir | sed 's,/$,,'` - fi ;; - [\\/]* | ?:[\\/]* ) # Absolute path. - ac_srcdir=$srcdir$ac_dir_suffix; - ac_top_srcdir=$srcdir ;; - *) # Relative path. - ac_srcdir=$ac_top_builddir$srcdir$ac_dir_suffix - ac_top_srcdir=$ac_top_builddir$srcdir ;; -esac - -# Do not use `cd foo && pwd` to compute absolute paths, because -# the directories may not exist. -case `pwd` in -.) ac_abs_builddir="$ac_dir";; -*) - case "$ac_dir" in - .) ac_abs_builddir=`pwd`;; - [\\/]* | ?:[\\/]* ) ac_abs_builddir="$ac_dir";; - *) ac_abs_builddir=`pwd`/"$ac_dir";; - esac;; -esac -case $ac_abs_builddir in -.) ac_abs_top_builddir=${ac_top_builddir}.;; -*) - case ${ac_top_builddir}. in - .) ac_abs_top_builddir=$ac_abs_builddir;; - [\\/]* | ?:[\\/]* ) ac_abs_top_builddir=${ac_top_builddir}.;; - *) ac_abs_top_builddir=$ac_abs_builddir/${ac_top_builddir}.;; - esac;; -esac -case $ac_abs_builddir in -.) ac_abs_srcdir=$ac_srcdir;; -*) - case $ac_srcdir in - .) ac_abs_srcdir=$ac_abs_builddir;; - [\\/]* | ?:[\\/]* ) ac_abs_srcdir=$ac_srcdir;; - *) ac_abs_srcdir=$ac_abs_builddir/$ac_srcdir;; - esac;; -esac -case $ac_abs_builddir in -.) ac_abs_top_srcdir=$ac_top_srcdir;; -*) - case $ac_top_srcdir in - .) ac_abs_top_srcdir=$ac_abs_builddir;; - [\\/]* | ?:[\\/]* ) ac_abs_top_srcdir=$ac_top_srcdir;; - *) ac_abs_top_srcdir=$ac_abs_builddir/$ac_top_srcdir;; - esac;; -esac - - cd $ac_dir - # Check for guested configure; otherwise get Cygnus style configure. - if test -f $ac_srcdir/configure.gnu; then - echo - $SHELL $ac_srcdir/configure.gnu --help=recursive - elif test -f $ac_srcdir/configure; then - echo - $SHELL $ac_srcdir/configure --help=recursive - elif test -f $ac_srcdir/configure.ac || - test -f $ac_srcdir/configure.in; then - echo - $ac_configure --help - else - echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2 - fi - cd $ac_popdir - done -fi - -test -n "$ac_init_help" && exit 0 -if $ac_init_version; then - cat <<\_ACEOF -ase configure deb-0.1.0 -generated by GNU Autoconf 2.59 - -Copyright (C) 2003 Free Software Foundation, Inc. -This configure script is free software; the Free Software Foundation -gives unlimited permission to copy, distribute and modify it. -_ACEOF - exit 0 -fi -exec 5>config.log -cat >&5 <<_ACEOF -This file contains any messages produced by compilers while -running configure, to aid debugging if configure makes a mistake. - -It was created by ase $as_me deb-0.1.0, which was -generated by GNU Autoconf 2.59. Invocation command line was - - $ $0 $@ - -_ACEOF -{ -cat <<_ASUNAME -## --------- ## -## Platform. ## -## --------- ## - -hostname = `(hostname || uname -n) 2>/dev/null | sed 1q` -uname -m = `(uname -m) 2>/dev/null || echo unknown` -uname -r = `(uname -r) 2>/dev/null || echo unknown` -uname -s = `(uname -s) 2>/dev/null || echo unknown` -uname -v = `(uname -v) 2>/dev/null || echo unknown` - -/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown` -/bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown` - -/bin/arch = `(/bin/arch) 2>/dev/null || echo unknown` -/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown` -/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown` -hostinfo = `(hostinfo) 2>/dev/null || echo unknown` -/bin/machine = `(/bin/machine) 2>/dev/null || echo unknown` -/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown` -/bin/universe = `(/bin/universe) 2>/dev/null || echo unknown` - -_ASUNAME - -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - echo "PATH: $as_dir" -done - -} >&5 - -cat >&5 <<_ACEOF - - -## ----------- ## -## Core tests. ## -## ----------- ## - -_ACEOF - - -# Keep a trace of the command line. -# Strip out --no-create and --no-recursion so they do not pile up. -# Strip out --silent because we don't want to record it for future runs. -# Also quote any args containing shell meta-characters. -# Make two passes to allow for proper duplicate-argument suppression. -ac_configure_args= -ac_configure_args0= -ac_configure_args1= -ac_sep= -ac_must_keep_next=false -for ac_pass in 1 2 -do - for ac_arg - do - case $ac_arg in - -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;; - -q | -quiet | --quiet | --quie | --qui | --qu | --q \ - | -silent | --silent | --silen | --sile | --sil) - continue ;; - *" "*|*" "*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?\"\']*) - ac_arg=`echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; - esac - case $ac_pass in - 1) ac_configure_args0="$ac_configure_args0 '$ac_arg'" ;; - 2) - ac_configure_args1="$ac_configure_args1 '$ac_arg'" - if test $ac_must_keep_next = true; then - ac_must_keep_next=false # Got value, back to normal. - else - case $ac_arg in - *=* | --config-cache | -C | -disable-* | --disable-* \ - | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \ - | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \ - | -with-* | --with-* | -without-* | --without-* | --x) - case "$ac_configure_args0 " in - "$ac_configure_args1"*" '$ac_arg' "* ) continue ;; - esac - ;; - -* ) ac_must_keep_next=true ;; - esac - fi - ac_configure_args="$ac_configure_args$ac_sep'$ac_arg'" - # Get rid of the leading space. - ac_sep=" " - ;; - esac - done -done -$as_unset ac_configure_args0 || test "${ac_configure_args0+set}" != set || { ac_configure_args0=; export ac_configure_args0; } -$as_unset ac_configure_args1 || test "${ac_configure_args1+set}" != set || { ac_configure_args1=; export ac_configure_args1; } - -# When interrupted or exit'd, cleanup temporary files, and complete -# config.log. We remove comments because anyway the quotes in there -# would cause problems or look ugly. -# WARNING: Be sure not to use single quotes in there, as some shells, -# such as our DU 5.0 friend, will then `close' the trap. -trap 'exit_status=$? - # Save into config.log some information that might help in debugging. - { - echo - - cat <<\_ASBOX -## ---------------- ## -## Cache variables. ## -## ---------------- ## -_ASBOX - echo - # The following way of writing the cache mishandles newlines in values, -{ - (set) 2>&1 | - case `(ac_space='"'"' '"'"'; set | grep ac_space) 2>&1` in - *ac_space=\ *) - sed -n \ - "s/'"'"'/'"'"'\\\\'"'"''"'"'/g; - s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='"'"'\\2'"'"'/p" - ;; - *) - sed -n \ - "s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1=\\2/p" - ;; - esac; -} - echo - - cat <<\_ASBOX -## ----------------- ## -## Output variables. ## -## ----------------- ## -_ASBOX - echo - for ac_var in $ac_subst_vars - do - eval ac_val=$`echo $ac_var` - echo "$ac_var='"'"'$ac_val'"'"'" - done | sort - echo - - if test -n "$ac_subst_files"; then - cat <<\_ASBOX -## ------------- ## -## Output files. ## -## ------------- ## -_ASBOX - echo - for ac_var in $ac_subst_files - do - eval ac_val=$`echo $ac_var` - echo "$ac_var='"'"'$ac_val'"'"'" - done | sort - echo - fi - - if test -s confdefs.h; then - cat <<\_ASBOX -## ----------- ## -## confdefs.h. ## -## ----------- ## -_ASBOX - echo - sed "/^$/d" confdefs.h | sort - echo - fi - test "$ac_signal" != 0 && - echo "$as_me: caught signal $ac_signal" - echo "$as_me: exit $exit_status" - } >&5 - rm -f core *.core && - rm -rf conftest* confdefs* conf$$* $ac_clean_files && - exit $exit_status - ' 0 -for ac_signal in 1 2 13 15; do - trap 'ac_signal='$ac_signal'; { (exit 1); exit 1; }' $ac_signal -done -ac_signal=0 - -# confdefs.h avoids OS command line length limits that DEFS can exceed. -rm -rf conftest* confdefs.h -# AIX cpp loses on an empty file, so make sure it contains at least a newline. -echo >confdefs.h - -# Predefined preprocessor variables. - -cat >>confdefs.h <<_ACEOF -#define PACKAGE_NAME "$PACKAGE_NAME" -_ACEOF - - -cat >>confdefs.h <<_ACEOF -#define PACKAGE_TARNAME "$PACKAGE_TARNAME" -_ACEOF - - -cat >>confdefs.h <<_ACEOF -#define PACKAGE_VERSION "$PACKAGE_VERSION" -_ACEOF - - -cat >>confdefs.h <<_ACEOF -#define PACKAGE_STRING "$PACKAGE_STRING" -_ACEOF - - -cat >>confdefs.h <<_ACEOF -#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT" -_ACEOF - - -# Let the site file select an alternate cache file if it wants to. -# Prefer explicitly selected file to automatically selected ones. -if test -z "$CONFIG_SITE"; then - if test "x$prefix" != xNONE; then - CONFIG_SITE="$prefix/share/config.site $prefix/etc/config.site" - else - CONFIG_SITE="$ac_default_prefix/share/config.site $ac_default_prefix/etc/config.site" - fi -fi -for ac_site_file in $CONFIG_SITE; do - if test -r "$ac_site_file"; then - { echo "$as_me:$LINENO: loading site script $ac_site_file" >&5 -echo "$as_me: loading site script $ac_site_file" >&6;} - sed 's/^/| /' "$ac_site_file" >&5 - . "$ac_site_file" - fi -done - -if test -r "$cache_file"; then - # Some versions of bash will fail to source /dev/null (special - # files actually), so we avoid doing that. - if test -f "$cache_file"; then - { echo "$as_me:$LINENO: loading cache $cache_file" >&5 -echo "$as_me: loading cache $cache_file" >&6;} - case $cache_file in - [\\/]* | ?:[\\/]* ) . $cache_file;; - *) . ./$cache_file;; - esac - fi -else - { echo "$as_me:$LINENO: creating cache $cache_file" >&5 -echo "$as_me: creating cache $cache_file" >&6;} - >$cache_file -fi - -# Check that the precious variables saved in the cache have kept the same -# value. -ac_cache_corrupted=false -for ac_var in `(set) 2>&1 | - sed -n 's/^ac_env_\([a-zA-Z_0-9]*\)_set=.*/\1/p'`; do - eval ac_old_set=\$ac_cv_env_${ac_var}_set - eval ac_new_set=\$ac_env_${ac_var}_set - eval ac_old_val="\$ac_cv_env_${ac_var}_value" - eval ac_new_val="\$ac_env_${ac_var}_value" - case $ac_old_set,$ac_new_set in - set,) - { echo "$as_me:$LINENO: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 -echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} - ac_cache_corrupted=: ;; - ,set) - { echo "$as_me:$LINENO: error: \`$ac_var' was not set in the previous run" >&5 -echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} - ac_cache_corrupted=: ;; - ,);; - *) - if test "x$ac_old_val" != "x$ac_new_val"; then - { echo "$as_me:$LINENO: error: \`$ac_var' has changed since the previous run:" >&5 -echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} - { echo "$as_me:$LINENO: former value: $ac_old_val" >&5 -echo "$as_me: former value: $ac_old_val" >&2;} - { echo "$as_me:$LINENO: current value: $ac_new_val" >&5 -echo "$as_me: current value: $ac_new_val" >&2;} - ac_cache_corrupted=: - fi;; - esac - # Pass precious variables to config.status. - if test "$ac_new_set" = set; then - case $ac_new_val in - *" "*|*" "*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?\"\']*) - ac_arg=$ac_var=`echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;; - *) ac_arg=$ac_var=$ac_new_val ;; - esac - case " $ac_configure_args " in - *" '$ac_arg' "*) ;; # Avoid dups. Use of quotes ensures accuracy. - *) ac_configure_args="$ac_configure_args '$ac_arg'" ;; - esac - fi -done -if $ac_cache_corrupted; then - { echo "$as_me:$LINENO: error: changes in the environment can compromise the build" >&5 -echo "$as_me: error: changes in the environment can compromise the build" >&2;} - { { echo "$as_me:$LINENO: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&5 -echo "$as_me: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&2;} - { (exit 1); exit 1; }; } -fi - -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ac_config_headers="$ac_config_headers cmn/conf_unx.h" - - -# Checks for programs. -#AC_PROG_CXX -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu -if test -n "$ac_tool_prefix"; then - # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. -set dummy ${ac_tool_prefix}gcc; ac_word=$2 -echo "$as_me:$LINENO: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$CC"; then - ac_cv_prog_CC="$CC" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then - ac_cv_prog_CC="${ac_tool_prefix}gcc" - echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done -done - -fi -fi -CC=$ac_cv_prog_CC -if test -n "$CC"; then - echo "$as_me:$LINENO: result: $CC" >&5 -echo "${ECHO_T}$CC" >&6 -else - echo "$as_me:$LINENO: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - -fi -if test -z "$ac_cv_prog_CC"; then - ac_ct_CC=$CC - # Extract the first word of "gcc", so it can be a program name with args. -set dummy gcc; ac_word=$2 -echo "$as_me:$LINENO: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_ac_ct_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$ac_ct_CC"; then - ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then - ac_cv_prog_ac_ct_CC="gcc" - echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done -done - -fi -fi -ac_ct_CC=$ac_cv_prog_ac_ct_CC -if test -n "$ac_ct_CC"; then - echo "$as_me:$LINENO: result: $ac_ct_CC" >&5 -echo "${ECHO_T}$ac_ct_CC" >&6 -else - echo "$as_me:$LINENO: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - - CC=$ac_ct_CC -else - CC="$ac_cv_prog_CC" -fi - -if test -z "$CC"; then - if test -n "$ac_tool_prefix"; then - # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. -set dummy ${ac_tool_prefix}cc; ac_word=$2 -echo "$as_me:$LINENO: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$CC"; then - ac_cv_prog_CC="$CC" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then - ac_cv_prog_CC="${ac_tool_prefix}cc" - echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done -done - -fi -fi -CC=$ac_cv_prog_CC -if test -n "$CC"; then - echo "$as_me:$LINENO: result: $CC" >&5 -echo "${ECHO_T}$CC" >&6 -else - echo "$as_me:$LINENO: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - -fi -if test -z "$ac_cv_prog_CC"; then - ac_ct_CC=$CC - # Extract the first word of "cc", so it can be a program name with args. -set dummy cc; ac_word=$2 -echo "$as_me:$LINENO: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_ac_ct_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$ac_ct_CC"; then - ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then - ac_cv_prog_ac_ct_CC="cc" - echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done -done - -fi -fi -ac_ct_CC=$ac_cv_prog_ac_ct_CC -if test -n "$ac_ct_CC"; then - echo "$as_me:$LINENO: result: $ac_ct_CC" >&5 -echo "${ECHO_T}$ac_ct_CC" >&6 -else - echo "$as_me:$LINENO: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - - CC=$ac_ct_CC -else - CC="$ac_cv_prog_CC" -fi - -fi -if test -z "$CC"; then - # Extract the first word of "cc", so it can be a program name with args. -set dummy cc; ac_word=$2 -echo "$as_me:$LINENO: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$CC"; then - ac_cv_prog_CC="$CC" # Let the user override the test. -else - ac_prog_rejected=no -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then - if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then - ac_prog_rejected=yes - continue - fi - ac_cv_prog_CC="cc" - echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done -done - -if test $ac_prog_rejected = yes; then - # We found a bogon in the path, so make sure we never use it. - set dummy $ac_cv_prog_CC - shift - if test $# != 0; then - # We chose a different compiler from the bogus one. - # However, it has the same basename, so the bogon will be chosen - # first if we set CC to just the basename; use the full file name. - shift - ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@" - fi -fi -fi -fi -CC=$ac_cv_prog_CC -if test -n "$CC"; then - echo "$as_me:$LINENO: result: $CC" >&5 -echo "${ECHO_T}$CC" >&6 -else - echo "$as_me:$LINENO: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - -fi -if test -z "$CC"; then - if test -n "$ac_tool_prefix"; then - for ac_prog in cl - do - # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. -set dummy $ac_tool_prefix$ac_prog; ac_word=$2 -echo "$as_me:$LINENO: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$CC"; then - ac_cv_prog_CC="$CC" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then - ac_cv_prog_CC="$ac_tool_prefix$ac_prog" - echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done -done - -fi -fi -CC=$ac_cv_prog_CC -if test -n "$CC"; then - echo "$as_me:$LINENO: result: $CC" >&5 -echo "${ECHO_T}$CC" >&6 -else - echo "$as_me:$LINENO: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - - test -n "$CC" && break - done -fi -if test -z "$CC"; then - ac_ct_CC=$CC - for ac_prog in cl -do - # Extract the first word of "$ac_prog", so it can be a program name with args. -set dummy $ac_prog; ac_word=$2 -echo "$as_me:$LINENO: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_ac_ct_CC+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$ac_ct_CC"; then - ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then - ac_cv_prog_ac_ct_CC="$ac_prog" - echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done -done - -fi -fi -ac_ct_CC=$ac_cv_prog_ac_ct_CC -if test -n "$ac_ct_CC"; then - echo "$as_me:$LINENO: result: $ac_ct_CC" >&5 -echo "${ECHO_T}$ac_ct_CC" >&6 -else - echo "$as_me:$LINENO: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - - test -n "$ac_ct_CC" && break -done - - CC=$ac_ct_CC -fi - -fi - - -test -z "$CC" && { { echo "$as_me:$LINENO: error: no acceptable C compiler found in \$PATH -See \`config.log' for more details." >&5 -echo "$as_me: error: no acceptable C compiler found in \$PATH -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } - -# Provide some information about the compiler. -echo "$as_me:$LINENO:" \ - "checking for C compiler version" >&5 -ac_compiler=`set X $ac_compile; echo $2` -{ (eval echo "$as_me:$LINENO: \"$ac_compiler --version &5\"") >&5 - (eval $ac_compiler --version &5) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } -{ (eval echo "$as_me:$LINENO: \"$ac_compiler -v &5\"") >&5 - (eval $ac_compiler -v &5) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } -{ (eval echo "$as_me:$LINENO: \"$ac_compiler -V &5\"") >&5 - (eval $ac_compiler -V &5) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } - -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -int -main () -{ - - ; - return 0; -} -_ACEOF -ac_clean_files_save=$ac_clean_files -ac_clean_files="$ac_clean_files a.out a.exe b.out" -# Try to create an executable without -o first, disregard a.out. -# It will help us diagnose broken compilers, and finding out an intuition -# of exeext. -echo "$as_me:$LINENO: checking for C compiler default output file name" >&5 -echo $ECHO_N "checking for C compiler default output file name... $ECHO_C" >&6 -ac_link_default=`echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'` -if { (eval echo "$as_me:$LINENO: \"$ac_link_default\"") >&5 - (eval $ac_link_default) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; then - # Find the output, starting from the most likely. This scheme is -# not robust to junk in `.', hence go to wildcards (a.*) only as a last -# resort. - -# Be careful to initialize this variable, since it used to be cached. -# Otherwise an old cache value of `no' led to `EXEEXT = no' in a Makefile. -ac_cv_exeext= -# b.out is created by i960 compilers. -for ac_file in a_out.exe a.exe conftest.exe a.out conftest a.* conftest.* b.out -do - test -f "$ac_file" || continue - case $ac_file in - *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.o | *.obj ) - ;; - conftest.$ac_ext ) - # This is the source file. - ;; - [ab].out ) - # We found the default executable, but exeext='' is most - # certainly right. - break;; - *.* ) - ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` - # FIXME: I believe we export ac_cv_exeext for Libtool, - # but it would be cool to find out if it's true. Does anybody - # maintain Libtool? --akim. - export ac_cv_exeext - break;; - * ) - break;; - esac -done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -{ { echo "$as_me:$LINENO: error: C compiler cannot create executables -See \`config.log' for more details." >&5 -echo "$as_me: error: C compiler cannot create executables -See \`config.log' for more details." >&2;} - { (exit 77); exit 77; }; } -fi - -ac_exeext=$ac_cv_exeext -echo "$as_me:$LINENO: result: $ac_file" >&5 -echo "${ECHO_T}$ac_file" >&6 - -# Check the compiler produces executables we can run. If not, either -# the compiler is broken, or we cross compile. -echo "$as_me:$LINENO: checking whether the C compiler works" >&5 -echo $ECHO_N "checking whether the C compiler works... $ECHO_C" >&6 -# FIXME: These cross compiler hacks should be removed for Autoconf 3.0 -# If not cross compiling, check that we can run a simple program. -if test "$cross_compiling" != yes; then - if { ac_try='./$ac_file' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - cross_compiling=no - else - if test "$cross_compiling" = maybe; then - cross_compiling=yes - else - { { echo "$as_me:$LINENO: error: cannot run C compiled programs. -If you meant to cross compile, use \`--host'. -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot run C compiled programs. -If you meant to cross compile, use \`--host'. -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } - fi - fi -fi -echo "$as_me:$LINENO: result: yes" >&5 -echo "${ECHO_T}yes" >&6 - -rm -f a.out a.exe conftest$ac_cv_exeext b.out -ac_clean_files=$ac_clean_files_save -# Check the compiler produces executables we can run. If not, either -# the compiler is broken, or we cross compile. -echo "$as_me:$LINENO: checking whether we are cross compiling" >&5 -echo $ECHO_N "checking whether we are cross compiling... $ECHO_C" >&6 -echo "$as_me:$LINENO: result: $cross_compiling" >&5 -echo "${ECHO_T}$cross_compiling" >&6 - -echo "$as_me:$LINENO: checking for suffix of executables" >&5 -echo $ECHO_N "checking for suffix of executables... $ECHO_C" >&6 -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; then - # If both `conftest.exe' and `conftest' are `present' (well, observable) -# catch `conftest.exe'. For instance with Cygwin, `ls conftest' will -# work properly (i.e., refer to `conftest.exe'), while it won't with -# `rm'. -for ac_file in conftest.exe conftest conftest.*; do - test -f "$ac_file" || continue - case $ac_file in - *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.o | *.obj ) ;; - *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` - export ac_cv_exeext - break;; - * ) break;; - esac -done -else - { { echo "$as_me:$LINENO: error: cannot compute suffix of executables: cannot compile and link -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute suffix of executables: cannot compile and link -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -fi - -rm -f conftest$ac_cv_exeext -echo "$as_me:$LINENO: result: $ac_cv_exeext" >&5 -echo "${ECHO_T}$ac_cv_exeext" >&6 - -rm -f conftest.$ac_ext -EXEEXT=$ac_cv_exeext -ac_exeext=$EXEEXT -echo "$as_me:$LINENO: checking for suffix of object files" >&5 -echo $ECHO_N "checking for suffix of object files... $ECHO_C" >&6 -if test "${ac_cv_objext+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -int -main () -{ - - ; - return 0; -} -_ACEOF -rm -f conftest.o conftest.obj -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; then - for ac_file in `(ls conftest.o conftest.obj; ls conftest.*) 2>/dev/null`; do - case $ac_file in - *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg ) ;; - *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'` - break;; - esac -done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -{ { echo "$as_me:$LINENO: error: cannot compute suffix of object files: cannot compile -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute suffix of object files: cannot compile -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -fi - -rm -f conftest.$ac_cv_objext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: $ac_cv_objext" >&5 -echo "${ECHO_T}$ac_cv_objext" >&6 -OBJEXT=$ac_cv_objext -ac_objext=$OBJEXT -echo "$as_me:$LINENO: checking whether we are using the GNU C compiler" >&5 -echo $ECHO_N "checking whether we are using the GNU C compiler... $ECHO_C" >&6 -if test "${ac_cv_c_compiler_gnu+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -int -main () -{ -#ifndef __GNUC__ - choke me -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_compiler_gnu=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_compiler_gnu=no -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -ac_cv_c_compiler_gnu=$ac_compiler_gnu - -fi -echo "$as_me:$LINENO: result: $ac_cv_c_compiler_gnu" >&5 -echo "${ECHO_T}$ac_cv_c_compiler_gnu" >&6 -GCC=`test $ac_compiler_gnu = yes && echo yes` -ac_test_CFLAGS=${CFLAGS+set} -ac_save_CFLAGS=$CFLAGS -CFLAGS="-g" -echo "$as_me:$LINENO: checking whether $CC accepts -g" >&5 -echo $ECHO_N "checking whether $CC accepts -g... $ECHO_C" >&6 -if test "${ac_cv_prog_cc_g+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -int -main () -{ - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_prog_cc_g=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_prog_cc_g=no -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: $ac_cv_prog_cc_g" >&5 -echo "${ECHO_T}$ac_cv_prog_cc_g" >&6 -if test "$ac_test_CFLAGS" = set; then - CFLAGS=$ac_save_CFLAGS -elif test $ac_cv_prog_cc_g = yes; then - if test "$GCC" = yes; then - CFLAGS="-g -O2" - else - CFLAGS="-g" - fi -else - if test "$GCC" = yes; then - CFLAGS="-O2" - else - CFLAGS= - fi -fi -echo "$as_me:$LINENO: checking for $CC option to accept ANSI C" >&5 -echo $ECHO_N "checking for $CC option to accept ANSI C... $ECHO_C" >&6 -if test "${ac_cv_prog_cc_stdc+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - ac_cv_prog_cc_stdc=no -ac_save_CC=$CC -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -#include -#include -#include -/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ -struct buf { int x; }; -FILE * (*rcsopen) (struct buf *, struct stat *, int); -static char *e (p, i) - char **p; - int i; -{ - return p[i]; -} -static char *f (char * (*g) (char **, int), char **p, ...) -{ - char *s; - va_list v; - va_start (v,p); - s = g (p, va_arg (v,int)); - va_end (v); - return s; -} - -/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has - function prototypes and stuff, but not '\xHH' hex character constants. - These don't provoke an error unfortunately, instead are silently treated - as 'x'. The following induces an error, until -std1 is added to get - proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an - array size at least. It's necessary to write '\x00'==0 to get something - that's true only with -std1. */ -int osf4_cc_array ['\x00' == 0 ? 1 : -1]; - -int test (int i, double x); -struct s1 {int (*f) (int a);}; -struct s2 {int (*f) (double a);}; -int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); -int argc; -char **argv; -int -main () -{ -return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; - ; - return 0; -} -_ACEOF -# Don't try gcc -ansi; that turns off useful extensions and -# breaks some systems' header files. -# AIX -qlanglvl=ansi -# Ultrix and OSF/1 -std1 -# HP-UX 10.20 and later -Ae -# HP-UX older versions -Aa -D_HPUX_SOURCE -# SVR4 -Xc -D__EXTENSIONS__ -for ac_arg in "" -qlanglvl=ansi -std1 -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" -do - CC="$ac_save_CC $ac_arg" - rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_prog_cc_stdc=$ac_arg -break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -fi -rm -f conftest.err conftest.$ac_objext -done -rm -f conftest.$ac_ext conftest.$ac_objext -CC=$ac_save_CC - -fi - -case "x$ac_cv_prog_cc_stdc" in - x|xno) - echo "$as_me:$LINENO: result: none needed" >&5 -echo "${ECHO_T}none needed" >&6 ;; - *) - echo "$as_me:$LINENO: result: $ac_cv_prog_cc_stdc" >&5 -echo "${ECHO_T}$ac_cv_prog_cc_stdc" >&6 - CC="$CC $ac_cv_prog_cc_stdc" ;; -esac - -# Some people use a C++ compiler to compile C. Since we use `exit', -# in C++ we need to declare it. In case someone uses the same compiler -# for both compiling C and C++ we need to have the C++ compiler decide -# the declaration of exit, since it's the most demanding environment. -cat >conftest.$ac_ext <<_ACEOF -#ifndef __cplusplus - choke me -#endif -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - for ac_declaration in \ - '' \ - 'extern "C" void std::exit (int) throw (); using std::exit;' \ - 'extern "C" void std::exit (int); using std::exit;' \ - 'extern "C" void exit (int) throw ();' \ - 'extern "C" void exit (int);' \ - 'void exit (int);' -do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_declaration -#include -int -main () -{ -exit (42); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - : -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -continue -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_declaration -int -main () -{ -exit (42); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -done -rm -f conftest* -if test -n "$ac_declaration"; then - echo '#ifdef __cplusplus' >>confdefs.h - echo $ac_declaration >>confdefs.h - echo '#endif' >>confdefs.h -fi - -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu - -if test -n "$ac_tool_prefix"; then - # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args. -set dummy ${ac_tool_prefix}ranlib; ac_word=$2 -echo "$as_me:$LINENO: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_RANLIB+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$RANLIB"; then - ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then - ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib" - echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done -done - -fi -fi -RANLIB=$ac_cv_prog_RANLIB -if test -n "$RANLIB"; then - echo "$as_me:$LINENO: result: $RANLIB" >&5 -echo "${ECHO_T}$RANLIB" >&6 -else - echo "$as_me:$LINENO: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - -fi -if test -z "$ac_cv_prog_RANLIB"; then - ac_ct_RANLIB=$RANLIB - # Extract the first word of "ranlib", so it can be a program name with args. -set dummy ranlib; ac_word=$2 -echo "$as_me:$LINENO: checking for $ac_word" >&5 -echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 -if test "${ac_cv_prog_ac_ct_RANLIB+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test -n "$ac_ct_RANLIB"; then - ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then - ac_cv_prog_ac_ct_RANLIB="ranlib" - echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done -done - - test -z "$ac_cv_prog_ac_ct_RANLIB" && ac_cv_prog_ac_ct_RANLIB=":" -fi -fi -ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB -if test -n "$ac_ct_RANLIB"; then - echo "$as_me:$LINENO: result: $ac_ct_RANLIB" >&5 -echo "${ECHO_T}$ac_ct_RANLIB" >&6 -else - echo "$as_me:$LINENO: result: no" >&5 -echo "${ECHO_T}no" >&6 -fi - - RANLIB=$ac_ct_RANLIB -else - RANLIB="$ac_cv_prog_RANLIB" -fi - - -# Overrides the default CFLAGS setting -if test "$ac_test_CFLAGS" = "set" -then - CFLAGS=$ac_save_CFLAGS -else - if test "$GCC" = "yes" - then - CFLAGS="-O2" - else - CFLAGS= - fi -fi - -# Checks for header files. - -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu -echo "$as_me:$LINENO: checking how to run the C preprocessor" >&5 -echo $ECHO_N "checking how to run the C preprocessor... $ECHO_C" >&6 -# On Suns, sometimes $CPP names a directory. -if test -n "$CPP" && test -d "$CPP"; then - CPP= -fi -if test -z "$CPP"; then - if test "${ac_cv_prog_CPP+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - # Double quotes because CPP needs to be expanded - for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp" - do - ac_preproc_ok=false -for ac_c_preproc_warn_flag in '' yes -do - # Use a header file that comes with gcc, so configuring glibc - # with a fresh cross-compiler works. - # Prefer to if __STDC__ is defined, since - # exists even on freestanding compilers. - # On the NeXT, cc -E runs the code through the compiler's parser, - # not just through cpp. "Syntax error" is here to catch this case. - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#ifdef __STDC__ -# include -#else -# include -#endif - Syntax error -_ACEOF -if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - ac_cpp_err=$ac_cpp_err$ac_c_werror_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - : -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - # Broken: fails on valid input. -continue -fi -rm -f conftest.err conftest.$ac_ext - - # OK, works on sane cases. Now check whether non-existent headers - # can be detected and how. - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -_ACEOF -if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - ac_cpp_err=$ac_cpp_err$ac_c_werror_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - # Broken: success on invalid input. -continue -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - # Passes both tests. -ac_preproc_ok=: -break -fi -rm -f conftest.err conftest.$ac_ext - -done -# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. -rm -f conftest.err conftest.$ac_ext -if $ac_preproc_ok; then - break -fi - - done - ac_cv_prog_CPP=$CPP - -fi - CPP=$ac_cv_prog_CPP -else - ac_cv_prog_CPP=$CPP -fi -echo "$as_me:$LINENO: result: $CPP" >&5 -echo "${ECHO_T}$CPP" >&6 -ac_preproc_ok=false -for ac_c_preproc_warn_flag in '' yes -do - # Use a header file that comes with gcc, so configuring glibc - # with a fresh cross-compiler works. - # Prefer to if __STDC__ is defined, since - # exists even on freestanding compilers. - # On the NeXT, cc -E runs the code through the compiler's parser, - # not just through cpp. "Syntax error" is here to catch this case. - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#ifdef __STDC__ -# include -#else -# include -#endif - Syntax error -_ACEOF -if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - ac_cpp_err=$ac_cpp_err$ac_c_werror_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - : -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - # Broken: fails on valid input. -continue -fi -rm -f conftest.err conftest.$ac_ext - - # OK, works on sane cases. Now check whether non-existent headers - # can be detected and how. - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -_ACEOF -if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - ac_cpp_err=$ac_cpp_err$ac_c_werror_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - # Broken: success on invalid input. -continue -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - # Passes both tests. -ac_preproc_ok=: -break -fi -rm -f conftest.err conftest.$ac_ext - -done -# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. -rm -f conftest.err conftest.$ac_ext -if $ac_preproc_ok; then - : -else - { { echo "$as_me:$LINENO: error: C preprocessor \"$CPP\" fails sanity check -See \`config.log' for more details." >&5 -echo "$as_me: error: C preprocessor \"$CPP\" fails sanity check -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -fi - -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu - - -echo "$as_me:$LINENO: checking for egrep" >&5 -echo $ECHO_N "checking for egrep... $ECHO_C" >&6 -if test "${ac_cv_prog_egrep+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if echo a | (grep -E '(a|b)') >/dev/null 2>&1 - then ac_cv_prog_egrep='grep -E' - else ac_cv_prog_egrep='egrep' - fi -fi -echo "$as_me:$LINENO: result: $ac_cv_prog_egrep" >&5 -echo "${ECHO_T}$ac_cv_prog_egrep" >&6 - EGREP=$ac_cv_prog_egrep - - -echo "$as_me:$LINENO: checking for ANSI C header files" >&5 -echo $ECHO_N "checking for ANSI C header files... $ECHO_C" >&6 -if test "${ac_cv_header_stdc+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -#include -#include -#include - -int -main () -{ - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_header_stdc=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_header_stdc=no -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext - -if test $ac_cv_header_stdc = yes; then - # SunOS 4.x string.h does not declare mem*, contrary to ANSI. - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include - -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - $EGREP "memchr" >/dev/null 2>&1; then - : -else - ac_cv_header_stdc=no -fi -rm -f conftest* - -fi - -if test $ac_cv_header_stdc = yes; then - # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include - -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - $EGREP "free" >/dev/null 2>&1; then - : -else - ac_cv_header_stdc=no -fi -rm -f conftest* - -fi - -if test $ac_cv_header_stdc = yes; then - # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. - if test "$cross_compiling" = yes; then - : -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -#if ((' ' & 0x0FF) == 0x020) -# define ISLOWER(c) ('a' <= (c) && (c) <= 'z') -# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) -#else -# define ISLOWER(c) \ - (('a' <= (c) && (c) <= 'i') \ - || ('j' <= (c) && (c) <= 'r') \ - || ('s' <= (c) && (c) <= 'z')) -# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) -#endif - -#define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) -int -main () -{ - int i; - for (i = 0; i < 256; i++) - if (XOR (islower (i), ISLOWER (i)) - || toupper (i) != TOUPPER (i)) - exit(2); - exit (0); -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - : -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -ac_cv_header_stdc=no -fi -rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi -fi -fi -echo "$as_me:$LINENO: result: $ac_cv_header_stdc" >&5 -echo "${ECHO_T}$ac_cv_header_stdc" >&6 -if test $ac_cv_header_stdc = yes; then - -cat >>confdefs.h <<\_ACEOF -#define STDC_HEADERS 1 -_ACEOF - -fi - - -# Checks for typedefs, structures, and compiler characteristics. -echo "$as_me:$LINENO: checking whether byte ordering is bigendian" >&5 -echo $ECHO_N "checking whether byte ordering is bigendian... $ECHO_C" >&6 -if test "${ac_cv_c_bigendian+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - # See if sys/param.h defines the BYTE_ORDER macro. -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -#include - -int -main () -{ -#if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN - bogus endian macros -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - # It does; now see whether it defined to BIG_ENDIAN or not. -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -#include - -int -main () -{ -#if BYTE_ORDER != BIG_ENDIAN - not big endian -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_c_bigendian=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_c_bigendian=no -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -# It does not; compile a test program. -if test "$cross_compiling" = yes; then - # try to guess the endianness by grepping values into an object file - ac_cv_c_bigendian=unknown - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -short ascii_mm[] = { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 }; -short ascii_ii[] = { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 }; -void _ascii () { char *s = (char *) ascii_mm; s = (char *) ascii_ii; } -short ebcdic_ii[] = { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 }; -short ebcdic_mm[] = { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 }; -void _ebcdic () { char *s = (char *) ebcdic_mm; s = (char *) ebcdic_ii; } -int -main () -{ - _ascii (); _ebcdic (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - if grep BIGenDianSyS conftest.$ac_objext >/dev/null ; then - ac_cv_c_bigendian=yes -fi -if grep LiTTleEnDian conftest.$ac_objext >/dev/null ; then - if test "$ac_cv_c_bigendian" = unknown; then - ac_cv_c_bigendian=no - else - # finding both strings is unlikely to happen, but who knows? - ac_cv_c_bigendian=unknown - fi -fi -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -int -main () -{ - /* Are we little or big endian? From Harbison&Steele. */ - union - { - long l; - char c[sizeof (long)]; - } u; - u.l = 1; - exit (u.c[sizeof (long) - 1] == 1); -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_c_bigendian=no -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -ac_cv_c_bigendian=yes -fi -rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: $ac_cv_c_bigendian" >&5 -echo "${ECHO_T}$ac_cv_c_bigendian" >&6 -case $ac_cv_c_bigendian in - yes) - -cat >>confdefs.h <<\_ACEOF -#define ASE_ENDIAN_BIG -_ACEOF - ;; - no) - -cat >>confdefs.h <<\_ACEOF -#define ASE_ENDIAN_LITTLE -_ACEOF - ;; - *) - -cat >>confdefs.h <<\_ACEOF -#define ASE_ENDIAN_UNKNOWN -_ACEOF - ;; -esac - - -# Checks for data types -# On IRIX 5.3, sys/types and inttypes.h are conflicting. - - - - - - - - - -for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \ - inttypes.h stdint.h unistd.h -do -as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` -echo "$as_me:$LINENO: checking for $ac_header" >&5 -echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 -if eval "test \"\${$as_ac_Header+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default - -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - eval "$as_ac_Header=yes" -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -eval "$as_ac_Header=no" -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6 -if test `eval echo '${'$as_ac_Header'}'` = yes; then - cat >>confdefs.h <<_ACEOF -#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - - -echo "$as_me:$LINENO: checking for long long" >&5 -echo $ECHO_N "checking for long long... $ECHO_C" >&6 -if test "${ac_cv_type_long_long+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if ((long long *) 0) - return 0; -if (sizeof (long long)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type_long_long=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_type_long_long=no -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: $ac_cv_type_long_long" >&5 -echo "${ECHO_T}$ac_cv_type_long_long" >&6 -if test $ac_cv_type_long_long = yes; then - -cat >>confdefs.h <<\_ACEOF -#define ASE_HAVE_LONG_LONG -_ACEOF - -fi - -echo "$as_me:$LINENO: checking for long double" >&5 -echo $ECHO_N "checking for long double... $ECHO_C" >&6 -if test "${ac_cv_type_long_double+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if ((long double *) 0) - return 0; -if (sizeof (long double)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type_long_double=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_type_long_double=no -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: $ac_cv_type_long_double" >&5 -echo "${ECHO_T}$ac_cv_type_long_double" >&6 -if test $ac_cv_type_long_double = yes; then - -cat >>confdefs.h <<\_ACEOF -#define ASE_HAVE_LONG_DOUBLE -_ACEOF - -fi - - -echo "$as_me:$LINENO: checking for char" >&5 -echo $ECHO_N "checking for char... $ECHO_C" >&6 -if test "${ac_cv_type_char+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if ((char *) 0) - return 0; -if (sizeof (char)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type_char=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_type_char=no -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: $ac_cv_type_char" >&5 -echo "${ECHO_T}$ac_cv_type_char" >&6 - -echo "$as_me:$LINENO: checking size of char" >&5 -echo $ECHO_N "checking size of char... $ECHO_C" >&6 -if test "${ac_cv_sizeof_char+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test "$ac_cv_type_char" = yes; then - # The cast to unsigned long works around a bug in the HP C Compiler - # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects - # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. - # This bug is HP SR number 8606223364. - if test "$cross_compiling" = yes; then - # Depending upon the size, compute the lo and hi bounds. -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (char))) >= 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=0 ac_mid=0 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (char))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo=`expr $ac_mid + 1` - if test $ac_lo -le $ac_mid; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid + 1` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (char))) < 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=-1 ac_mid=-1 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (char))) >= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_hi=`expr '(' $ac_mid ')' - 1` - if test $ac_mid -le $ac_hi; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo= ac_hi= -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -# Binary search between lo and hi bounds. -while test "x$ac_lo" != "x$ac_hi"; do - ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (char))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo=`expr '(' $ac_mid ')' + 1` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -done -case $ac_lo in -?*) ac_cv_sizeof_char=$ac_lo;; -'') { { echo "$as_me:$LINENO: error: cannot compute sizeof (char), 77 -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute sizeof (char), 77 -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } ;; -esac -else - if test "$cross_compiling" = yes; then - { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot run test program while cross compiling -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -long longval () { return (long) (sizeof (char)); } -unsigned long ulongval () { return (long) (sizeof (char)); } -#include -#include -int -main () -{ - - FILE *f = fopen ("conftest.val", "w"); - if (! f) - exit (1); - if (((long) (sizeof (char))) < 0) - { - long i = longval (); - if (i != ((long) (sizeof (char)))) - exit (1); - fprintf (f, "%ld\n", i); - } - else - { - unsigned long i = ulongval (); - if (i != ((long) (sizeof (char)))) - exit (1); - fprintf (f, "%lu\n", i); - } - exit (ferror (f) || fclose (f) != 0); - - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_sizeof_char=`cat conftest.val` -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -{ { echo "$as_me:$LINENO: error: cannot compute sizeof (char), 77 -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute sizeof (char), 77 -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -fi -rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi -fi -rm -f conftest.val -else - ac_cv_sizeof_char=0 -fi -fi -echo "$as_me:$LINENO: result: $ac_cv_sizeof_char" >&5 -echo "${ECHO_T}$ac_cv_sizeof_char" >&6 -cat >>confdefs.h <<_ACEOF -#define SIZEOF_CHAR $ac_cv_sizeof_char -_ACEOF - - -echo "$as_me:$LINENO: checking for short" >&5 -echo $ECHO_N "checking for short... $ECHO_C" >&6 -if test "${ac_cv_type_short+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if ((short *) 0) - return 0; -if (sizeof (short)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type_short=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_type_short=no -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: $ac_cv_type_short" >&5 -echo "${ECHO_T}$ac_cv_type_short" >&6 - -echo "$as_me:$LINENO: checking size of short" >&5 -echo $ECHO_N "checking size of short... $ECHO_C" >&6 -if test "${ac_cv_sizeof_short+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test "$ac_cv_type_short" = yes; then - # The cast to unsigned long works around a bug in the HP C Compiler - # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects - # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. - # This bug is HP SR number 8606223364. - if test "$cross_compiling" = yes; then - # Depending upon the size, compute the lo and hi bounds. -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (short))) >= 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=0 ac_mid=0 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (short))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo=`expr $ac_mid + 1` - if test $ac_lo -le $ac_mid; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid + 1` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (short))) < 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=-1 ac_mid=-1 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (short))) >= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_hi=`expr '(' $ac_mid ')' - 1` - if test $ac_mid -le $ac_hi; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo= ac_hi= -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -# Binary search between lo and hi bounds. -while test "x$ac_lo" != "x$ac_hi"; do - ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (short))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo=`expr '(' $ac_mid ')' + 1` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -done -case $ac_lo in -?*) ac_cv_sizeof_short=$ac_lo;; -'') { { echo "$as_me:$LINENO: error: cannot compute sizeof (short), 77 -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute sizeof (short), 77 -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } ;; -esac -else - if test "$cross_compiling" = yes; then - { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot run test program while cross compiling -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -long longval () { return (long) (sizeof (short)); } -unsigned long ulongval () { return (long) (sizeof (short)); } -#include -#include -int -main () -{ - - FILE *f = fopen ("conftest.val", "w"); - if (! f) - exit (1); - if (((long) (sizeof (short))) < 0) - { - long i = longval (); - if (i != ((long) (sizeof (short)))) - exit (1); - fprintf (f, "%ld\n", i); - } - else - { - unsigned long i = ulongval (); - if (i != ((long) (sizeof (short)))) - exit (1); - fprintf (f, "%lu\n", i); - } - exit (ferror (f) || fclose (f) != 0); - - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_sizeof_short=`cat conftest.val` -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -{ { echo "$as_me:$LINENO: error: cannot compute sizeof (short), 77 -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute sizeof (short), 77 -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -fi -rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi -fi -rm -f conftest.val -else - ac_cv_sizeof_short=0 -fi -fi -echo "$as_me:$LINENO: result: $ac_cv_sizeof_short" >&5 -echo "${ECHO_T}$ac_cv_sizeof_short" >&6 -cat >>confdefs.h <<_ACEOF -#define SIZEOF_SHORT $ac_cv_sizeof_short -_ACEOF - - -echo "$as_me:$LINENO: checking for int" >&5 -echo $ECHO_N "checking for int... $ECHO_C" >&6 -if test "${ac_cv_type_int+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if ((int *) 0) - return 0; -if (sizeof (int)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type_int=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_type_int=no -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: $ac_cv_type_int" >&5 -echo "${ECHO_T}$ac_cv_type_int" >&6 - -echo "$as_me:$LINENO: checking size of int" >&5 -echo $ECHO_N "checking size of int... $ECHO_C" >&6 -if test "${ac_cv_sizeof_int+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test "$ac_cv_type_int" = yes; then - # The cast to unsigned long works around a bug in the HP C Compiler - # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects - # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. - # This bug is HP SR number 8606223364. - if test "$cross_compiling" = yes; then - # Depending upon the size, compute the lo and hi bounds. -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (int))) >= 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=0 ac_mid=0 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (int))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo=`expr $ac_mid + 1` - if test $ac_lo -le $ac_mid; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid + 1` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (int))) < 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=-1 ac_mid=-1 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (int))) >= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_hi=`expr '(' $ac_mid ')' - 1` - if test $ac_mid -le $ac_hi; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo= ac_hi= -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -# Binary search between lo and hi bounds. -while test "x$ac_lo" != "x$ac_hi"; do - ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (int))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo=`expr '(' $ac_mid ')' + 1` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -done -case $ac_lo in -?*) ac_cv_sizeof_int=$ac_lo;; -'') { { echo "$as_me:$LINENO: error: cannot compute sizeof (int), 77 -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute sizeof (int), 77 -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } ;; -esac -else - if test "$cross_compiling" = yes; then - { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot run test program while cross compiling -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -long longval () { return (long) (sizeof (int)); } -unsigned long ulongval () { return (long) (sizeof (int)); } -#include -#include -int -main () -{ - - FILE *f = fopen ("conftest.val", "w"); - if (! f) - exit (1); - if (((long) (sizeof (int))) < 0) - { - long i = longval (); - if (i != ((long) (sizeof (int)))) - exit (1); - fprintf (f, "%ld\n", i); - } - else - { - unsigned long i = ulongval (); - if (i != ((long) (sizeof (int)))) - exit (1); - fprintf (f, "%lu\n", i); - } - exit (ferror (f) || fclose (f) != 0); - - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_sizeof_int=`cat conftest.val` -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -{ { echo "$as_me:$LINENO: error: cannot compute sizeof (int), 77 -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute sizeof (int), 77 -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -fi -rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi -fi -rm -f conftest.val -else - ac_cv_sizeof_int=0 -fi -fi -echo "$as_me:$LINENO: result: $ac_cv_sizeof_int" >&5 -echo "${ECHO_T}$ac_cv_sizeof_int" >&6 -cat >>confdefs.h <<_ACEOF -#define SIZEOF_INT $ac_cv_sizeof_int -_ACEOF - - -echo "$as_me:$LINENO: checking for long" >&5 -echo $ECHO_N "checking for long... $ECHO_C" >&6 -if test "${ac_cv_type_long+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if ((long *) 0) - return 0; -if (sizeof (long)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type_long=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_type_long=no -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: $ac_cv_type_long" >&5 -echo "${ECHO_T}$ac_cv_type_long" >&6 - -echo "$as_me:$LINENO: checking size of long" >&5 -echo $ECHO_N "checking size of long... $ECHO_C" >&6 -if test "${ac_cv_sizeof_long+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test "$ac_cv_type_long" = yes; then - # The cast to unsigned long works around a bug in the HP C Compiler - # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects - # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. - # This bug is HP SR number 8606223364. - if test "$cross_compiling" = yes; then - # Depending upon the size, compute the lo and hi bounds. -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (long))) >= 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=0 ac_mid=0 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (long))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo=`expr $ac_mid + 1` - if test $ac_lo -le $ac_mid; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid + 1` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (long))) < 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=-1 ac_mid=-1 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (long))) >= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_hi=`expr '(' $ac_mid ')' - 1` - if test $ac_mid -le $ac_hi; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo= ac_hi= -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -# Binary search between lo and hi bounds. -while test "x$ac_lo" != "x$ac_hi"; do - ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (long))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo=`expr '(' $ac_mid ')' + 1` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -done -case $ac_lo in -?*) ac_cv_sizeof_long=$ac_lo;; -'') { { echo "$as_me:$LINENO: error: cannot compute sizeof (long), 77 -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute sizeof (long), 77 -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } ;; -esac -else - if test "$cross_compiling" = yes; then - { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot run test program while cross compiling -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -long longval () { return (long) (sizeof (long)); } -unsigned long ulongval () { return (long) (sizeof (long)); } -#include -#include -int -main () -{ - - FILE *f = fopen ("conftest.val", "w"); - if (! f) - exit (1); - if (((long) (sizeof (long))) < 0) - { - long i = longval (); - if (i != ((long) (sizeof (long)))) - exit (1); - fprintf (f, "%ld\n", i); - } - else - { - unsigned long i = ulongval (); - if (i != ((long) (sizeof (long)))) - exit (1); - fprintf (f, "%lu\n", i); - } - exit (ferror (f) || fclose (f) != 0); - - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_sizeof_long=`cat conftest.val` -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -{ { echo "$as_me:$LINENO: error: cannot compute sizeof (long), 77 -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute sizeof (long), 77 -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -fi -rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi -fi -rm -f conftest.val -else - ac_cv_sizeof_long=0 -fi -fi -echo "$as_me:$LINENO: result: $ac_cv_sizeof_long" >&5 -echo "${ECHO_T}$ac_cv_sizeof_long" >&6 -cat >>confdefs.h <<_ACEOF -#define SIZEOF_LONG $ac_cv_sizeof_long -_ACEOF - - -echo "$as_me:$LINENO: checking for long long" >&5 -echo $ECHO_N "checking for long long... $ECHO_C" >&6 -if test "${ac_cv_type_long_long+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if ((long long *) 0) - return 0; -if (sizeof (long long)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type_long_long=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_type_long_long=no -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: $ac_cv_type_long_long" >&5 -echo "${ECHO_T}$ac_cv_type_long_long" >&6 - -echo "$as_me:$LINENO: checking size of long long" >&5 -echo $ECHO_N "checking size of long long... $ECHO_C" >&6 -if test "${ac_cv_sizeof_long_long+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test "$ac_cv_type_long_long" = yes; then - # The cast to unsigned long works around a bug in the HP C Compiler - # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects - # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. - # This bug is HP SR number 8606223364. - if test "$cross_compiling" = yes; then - # Depending upon the size, compute the lo and hi bounds. -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (long long))) >= 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=0 ac_mid=0 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (long long))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo=`expr $ac_mid + 1` - if test $ac_lo -le $ac_mid; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid + 1` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (long long))) < 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=-1 ac_mid=-1 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (long long))) >= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_hi=`expr '(' $ac_mid ')' - 1` - if test $ac_mid -le $ac_hi; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo= ac_hi= -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -# Binary search between lo and hi bounds. -while test "x$ac_lo" != "x$ac_hi"; do - ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (long long))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo=`expr '(' $ac_mid ')' + 1` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -done -case $ac_lo in -?*) ac_cv_sizeof_long_long=$ac_lo;; -'') { { echo "$as_me:$LINENO: error: cannot compute sizeof (long long), 77 -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute sizeof (long long), 77 -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } ;; -esac -else - if test "$cross_compiling" = yes; then - { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot run test program while cross compiling -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -long longval () { return (long) (sizeof (long long)); } -unsigned long ulongval () { return (long) (sizeof (long long)); } -#include -#include -int -main () -{ - - FILE *f = fopen ("conftest.val", "w"); - if (! f) - exit (1); - if (((long) (sizeof (long long))) < 0) - { - long i = longval (); - if (i != ((long) (sizeof (long long)))) - exit (1); - fprintf (f, "%ld\n", i); - } - else - { - unsigned long i = ulongval (); - if (i != ((long) (sizeof (long long)))) - exit (1); - fprintf (f, "%lu\n", i); - } - exit (ferror (f) || fclose (f) != 0); - - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_sizeof_long_long=`cat conftest.val` -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -{ { echo "$as_me:$LINENO: error: cannot compute sizeof (long long), 77 -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute sizeof (long long), 77 -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -fi -rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi -fi -rm -f conftest.val -else - ac_cv_sizeof_long_long=0 -fi -fi -echo "$as_me:$LINENO: result: $ac_cv_sizeof_long_long" >&5 -echo "${ECHO_T}$ac_cv_sizeof_long_long" >&6 -cat >>confdefs.h <<_ACEOF -#define SIZEOF_LONG_LONG $ac_cv_sizeof_long_long -_ACEOF - - -echo "$as_me:$LINENO: checking for __int8" >&5 -echo $ECHO_N "checking for __int8... $ECHO_C" >&6 -if test "${ac_cv_type___int8+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if ((__int8 *) 0) - return 0; -if (sizeof (__int8)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type___int8=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_type___int8=no -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: $ac_cv_type___int8" >&5 -echo "${ECHO_T}$ac_cv_type___int8" >&6 - -echo "$as_me:$LINENO: checking size of __int8" >&5 -echo $ECHO_N "checking size of __int8... $ECHO_C" >&6 -if test "${ac_cv_sizeof___int8+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test "$ac_cv_type___int8" = yes; then - # The cast to unsigned long works around a bug in the HP C Compiler - # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects - # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. - # This bug is HP SR number 8606223364. - if test "$cross_compiling" = yes; then - # Depending upon the size, compute the lo and hi bounds. -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (__int8))) >= 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=0 ac_mid=0 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (__int8))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo=`expr $ac_mid + 1` - if test $ac_lo -le $ac_mid; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid + 1` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (__int8))) < 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=-1 ac_mid=-1 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (__int8))) >= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_hi=`expr '(' $ac_mid ')' - 1` - if test $ac_mid -le $ac_hi; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo= ac_hi= -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -# Binary search between lo and hi bounds. -while test "x$ac_lo" != "x$ac_hi"; do - ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (__int8))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo=`expr '(' $ac_mid ')' + 1` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -done -case $ac_lo in -?*) ac_cv_sizeof___int8=$ac_lo;; -'') { { echo "$as_me:$LINENO: error: cannot compute sizeof (__int8), 77 -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute sizeof (__int8), 77 -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } ;; -esac -else - if test "$cross_compiling" = yes; then - { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot run test program while cross compiling -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -long longval () { return (long) (sizeof (__int8)); } -unsigned long ulongval () { return (long) (sizeof (__int8)); } -#include -#include -int -main () -{ - - FILE *f = fopen ("conftest.val", "w"); - if (! f) - exit (1); - if (((long) (sizeof (__int8))) < 0) - { - long i = longval (); - if (i != ((long) (sizeof (__int8)))) - exit (1); - fprintf (f, "%ld\n", i); - } - else - { - unsigned long i = ulongval (); - if (i != ((long) (sizeof (__int8)))) - exit (1); - fprintf (f, "%lu\n", i); - } - exit (ferror (f) || fclose (f) != 0); - - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_sizeof___int8=`cat conftest.val` -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -{ { echo "$as_me:$LINENO: error: cannot compute sizeof (__int8), 77 -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute sizeof (__int8), 77 -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -fi -rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi -fi -rm -f conftest.val -else - ac_cv_sizeof___int8=0 -fi -fi -echo "$as_me:$LINENO: result: $ac_cv_sizeof___int8" >&5 -echo "${ECHO_T}$ac_cv_sizeof___int8" >&6 -cat >>confdefs.h <<_ACEOF -#define SIZEOF___INT8 $ac_cv_sizeof___int8 -_ACEOF - - -echo "$as_me:$LINENO: checking for __int16" >&5 -echo $ECHO_N "checking for __int16... $ECHO_C" >&6 -if test "${ac_cv_type___int16+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if ((__int16 *) 0) - return 0; -if (sizeof (__int16)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type___int16=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_type___int16=no -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: $ac_cv_type___int16" >&5 -echo "${ECHO_T}$ac_cv_type___int16" >&6 - -echo "$as_me:$LINENO: checking size of __int16" >&5 -echo $ECHO_N "checking size of __int16... $ECHO_C" >&6 -if test "${ac_cv_sizeof___int16+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test "$ac_cv_type___int16" = yes; then - # The cast to unsigned long works around a bug in the HP C Compiler - # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects - # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. - # This bug is HP SR number 8606223364. - if test "$cross_compiling" = yes; then - # Depending upon the size, compute the lo and hi bounds. -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (__int16))) >= 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=0 ac_mid=0 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (__int16))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo=`expr $ac_mid + 1` - if test $ac_lo -le $ac_mid; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid + 1` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (__int16))) < 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=-1 ac_mid=-1 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (__int16))) >= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_hi=`expr '(' $ac_mid ')' - 1` - if test $ac_mid -le $ac_hi; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo= ac_hi= -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -# Binary search between lo and hi bounds. -while test "x$ac_lo" != "x$ac_hi"; do - ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (__int16))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo=`expr '(' $ac_mid ')' + 1` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -done -case $ac_lo in -?*) ac_cv_sizeof___int16=$ac_lo;; -'') { { echo "$as_me:$LINENO: error: cannot compute sizeof (__int16), 77 -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute sizeof (__int16), 77 -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } ;; -esac -else - if test "$cross_compiling" = yes; then - { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot run test program while cross compiling -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -long longval () { return (long) (sizeof (__int16)); } -unsigned long ulongval () { return (long) (sizeof (__int16)); } -#include -#include -int -main () -{ - - FILE *f = fopen ("conftest.val", "w"); - if (! f) - exit (1); - if (((long) (sizeof (__int16))) < 0) - { - long i = longval (); - if (i != ((long) (sizeof (__int16)))) - exit (1); - fprintf (f, "%ld\n", i); - } - else - { - unsigned long i = ulongval (); - if (i != ((long) (sizeof (__int16)))) - exit (1); - fprintf (f, "%lu\n", i); - } - exit (ferror (f) || fclose (f) != 0); - - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_sizeof___int16=`cat conftest.val` -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -{ { echo "$as_me:$LINENO: error: cannot compute sizeof (__int16), 77 -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute sizeof (__int16), 77 -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -fi -rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi -fi -rm -f conftest.val -else - ac_cv_sizeof___int16=0 -fi -fi -echo "$as_me:$LINENO: result: $ac_cv_sizeof___int16" >&5 -echo "${ECHO_T}$ac_cv_sizeof___int16" >&6 -cat >>confdefs.h <<_ACEOF -#define SIZEOF___INT16 $ac_cv_sizeof___int16 -_ACEOF - - -echo "$as_me:$LINENO: checking for __int32" >&5 -echo $ECHO_N "checking for __int32... $ECHO_C" >&6 -if test "${ac_cv_type___int32+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if ((__int32 *) 0) - return 0; -if (sizeof (__int32)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type___int32=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_type___int32=no -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: $ac_cv_type___int32" >&5 -echo "${ECHO_T}$ac_cv_type___int32" >&6 - -echo "$as_me:$LINENO: checking size of __int32" >&5 -echo $ECHO_N "checking size of __int32... $ECHO_C" >&6 -if test "${ac_cv_sizeof___int32+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test "$ac_cv_type___int32" = yes; then - # The cast to unsigned long works around a bug in the HP C Compiler - # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects - # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. - # This bug is HP SR number 8606223364. - if test "$cross_compiling" = yes; then - # Depending upon the size, compute the lo and hi bounds. -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (__int32))) >= 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=0 ac_mid=0 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (__int32))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo=`expr $ac_mid + 1` - if test $ac_lo -le $ac_mid; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid + 1` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (__int32))) < 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=-1 ac_mid=-1 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (__int32))) >= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_hi=`expr '(' $ac_mid ')' - 1` - if test $ac_mid -le $ac_hi; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo= ac_hi= -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -# Binary search between lo and hi bounds. -while test "x$ac_lo" != "x$ac_hi"; do - ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (__int32))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo=`expr '(' $ac_mid ')' + 1` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -done -case $ac_lo in -?*) ac_cv_sizeof___int32=$ac_lo;; -'') { { echo "$as_me:$LINENO: error: cannot compute sizeof (__int32), 77 -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute sizeof (__int32), 77 -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } ;; -esac -else - if test "$cross_compiling" = yes; then - { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot run test program while cross compiling -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -long longval () { return (long) (sizeof (__int32)); } -unsigned long ulongval () { return (long) (sizeof (__int32)); } -#include -#include -int -main () -{ - - FILE *f = fopen ("conftest.val", "w"); - if (! f) - exit (1); - if (((long) (sizeof (__int32))) < 0) - { - long i = longval (); - if (i != ((long) (sizeof (__int32)))) - exit (1); - fprintf (f, "%ld\n", i); - } - else - { - unsigned long i = ulongval (); - if (i != ((long) (sizeof (__int32)))) - exit (1); - fprintf (f, "%lu\n", i); - } - exit (ferror (f) || fclose (f) != 0); - - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_sizeof___int32=`cat conftest.val` -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -{ { echo "$as_me:$LINENO: error: cannot compute sizeof (__int32), 77 -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute sizeof (__int32), 77 -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -fi -rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi -fi -rm -f conftest.val -else - ac_cv_sizeof___int32=0 -fi -fi -echo "$as_me:$LINENO: result: $ac_cv_sizeof___int32" >&5 -echo "${ECHO_T}$ac_cv_sizeof___int32" >&6 -cat >>confdefs.h <<_ACEOF -#define SIZEOF___INT32 $ac_cv_sizeof___int32 -_ACEOF - - -echo "$as_me:$LINENO: checking for __int64" >&5 -echo $ECHO_N "checking for __int64... $ECHO_C" >&6 -if test "${ac_cv_type___int64+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if ((__int64 *) 0) - return 0; -if (sizeof (__int64)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type___int64=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_type___int64=no -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: $ac_cv_type___int64" >&5 -echo "${ECHO_T}$ac_cv_type___int64" >&6 - -echo "$as_me:$LINENO: checking size of __int64" >&5 -echo $ECHO_N "checking size of __int64... $ECHO_C" >&6 -if test "${ac_cv_sizeof___int64+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test "$ac_cv_type___int64" = yes; then - # The cast to unsigned long works around a bug in the HP C Compiler - # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects - # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. - # This bug is HP SR number 8606223364. - if test "$cross_compiling" = yes; then - # Depending upon the size, compute the lo and hi bounds. -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (__int64))) >= 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=0 ac_mid=0 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (__int64))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo=`expr $ac_mid + 1` - if test $ac_lo -le $ac_mid; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid + 1` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (__int64))) < 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=-1 ac_mid=-1 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (__int64))) >= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_hi=`expr '(' $ac_mid ')' - 1` - if test $ac_mid -le $ac_hi; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo= ac_hi= -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -# Binary search between lo and hi bounds. -while test "x$ac_lo" != "x$ac_hi"; do - ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (__int64))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo=`expr '(' $ac_mid ')' + 1` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -done -case $ac_lo in -?*) ac_cv_sizeof___int64=$ac_lo;; -'') { { echo "$as_me:$LINENO: error: cannot compute sizeof (__int64), 77 -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute sizeof (__int64), 77 -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } ;; -esac -else - if test "$cross_compiling" = yes; then - { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot run test program while cross compiling -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -long longval () { return (long) (sizeof (__int64)); } -unsigned long ulongval () { return (long) (sizeof (__int64)); } -#include -#include -int -main () -{ - - FILE *f = fopen ("conftest.val", "w"); - if (! f) - exit (1); - if (((long) (sizeof (__int64))) < 0) - { - long i = longval (); - if (i != ((long) (sizeof (__int64)))) - exit (1); - fprintf (f, "%ld\n", i); - } - else - { - unsigned long i = ulongval (); - if (i != ((long) (sizeof (__int64)))) - exit (1); - fprintf (f, "%lu\n", i); - } - exit (ferror (f) || fclose (f) != 0); - - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_sizeof___int64=`cat conftest.val` -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -{ { echo "$as_me:$LINENO: error: cannot compute sizeof (__int64), 77 -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute sizeof (__int64), 77 -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -fi -rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi -fi -rm -f conftest.val -else - ac_cv_sizeof___int64=0 -fi -fi -echo "$as_me:$LINENO: result: $ac_cv_sizeof___int64" >&5 -echo "${ECHO_T}$ac_cv_sizeof___int64" >&6 -cat >>confdefs.h <<_ACEOF -#define SIZEOF___INT64 $ac_cv_sizeof___int64 -_ACEOF - - -echo "$as_me:$LINENO: checking for __int96" >&5 -echo $ECHO_N "checking for __int96... $ECHO_C" >&6 -if test "${ac_cv_type___int96+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if ((__int96 *) 0) - return 0; -if (sizeof (__int96)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type___int96=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_type___int96=no -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: $ac_cv_type___int96" >&5 -echo "${ECHO_T}$ac_cv_type___int96" >&6 - -echo "$as_me:$LINENO: checking size of __int96" >&5 -echo $ECHO_N "checking size of __int96... $ECHO_C" >&6 -if test "${ac_cv_sizeof___int96+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test "$ac_cv_type___int96" = yes; then - # The cast to unsigned long works around a bug in the HP C Compiler - # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects - # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. - # This bug is HP SR number 8606223364. - if test "$cross_compiling" = yes; then - # Depending upon the size, compute the lo and hi bounds. -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (__int96))) >= 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=0 ac_mid=0 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (__int96))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo=`expr $ac_mid + 1` - if test $ac_lo -le $ac_mid; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid + 1` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (__int96))) < 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=-1 ac_mid=-1 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (__int96))) >= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_hi=`expr '(' $ac_mid ')' - 1` - if test $ac_mid -le $ac_hi; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo= ac_hi= -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -# Binary search between lo and hi bounds. -while test "x$ac_lo" != "x$ac_hi"; do - ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (__int96))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo=`expr '(' $ac_mid ')' + 1` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -done -case $ac_lo in -?*) ac_cv_sizeof___int96=$ac_lo;; -'') { { echo "$as_me:$LINENO: error: cannot compute sizeof (__int96), 77 -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute sizeof (__int96), 77 -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } ;; -esac -else - if test "$cross_compiling" = yes; then - { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot run test program while cross compiling -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -long longval () { return (long) (sizeof (__int96)); } -unsigned long ulongval () { return (long) (sizeof (__int96)); } -#include -#include -int -main () -{ - - FILE *f = fopen ("conftest.val", "w"); - if (! f) - exit (1); - if (((long) (sizeof (__int96))) < 0) - { - long i = longval (); - if (i != ((long) (sizeof (__int96)))) - exit (1); - fprintf (f, "%ld\n", i); - } - else - { - unsigned long i = ulongval (); - if (i != ((long) (sizeof (__int96)))) - exit (1); - fprintf (f, "%lu\n", i); - } - exit (ferror (f) || fclose (f) != 0); - - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_sizeof___int96=`cat conftest.val` -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -{ { echo "$as_me:$LINENO: error: cannot compute sizeof (__int96), 77 -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute sizeof (__int96), 77 -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -fi -rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi -fi -rm -f conftest.val -else - ac_cv_sizeof___int96=0 -fi -fi -echo "$as_me:$LINENO: result: $ac_cv_sizeof___int96" >&5 -echo "${ECHO_T}$ac_cv_sizeof___int96" >&6 -cat >>confdefs.h <<_ACEOF -#define SIZEOF___INT96 $ac_cv_sizeof___int96 -_ACEOF - - -echo "$as_me:$LINENO: checking for __int128" >&5 -echo $ECHO_N "checking for __int128... $ECHO_C" >&6 -if test "${ac_cv_type___int128+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if ((__int128 *) 0) - return 0; -if (sizeof (__int128)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type___int128=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_type___int128=no -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: $ac_cv_type___int128" >&5 -echo "${ECHO_T}$ac_cv_type___int128" >&6 - -echo "$as_me:$LINENO: checking size of __int128" >&5 -echo $ECHO_N "checking size of __int128... $ECHO_C" >&6 -if test "${ac_cv_sizeof___int128+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test "$ac_cv_type___int128" = yes; then - # The cast to unsigned long works around a bug in the HP C Compiler - # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects - # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. - # This bug is HP SR number 8606223364. - if test "$cross_compiling" = yes; then - # Depending upon the size, compute the lo and hi bounds. -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (__int128))) >= 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=0 ac_mid=0 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (__int128))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo=`expr $ac_mid + 1` - if test $ac_lo -le $ac_mid; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid + 1` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (__int128))) < 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=-1 ac_mid=-1 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (__int128))) >= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_hi=`expr '(' $ac_mid ')' - 1` - if test $ac_mid -le $ac_hi; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo= ac_hi= -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -# Binary search between lo and hi bounds. -while test "x$ac_lo" != "x$ac_hi"; do - ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (__int128))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo=`expr '(' $ac_mid ')' + 1` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -done -case $ac_lo in -?*) ac_cv_sizeof___int128=$ac_lo;; -'') { { echo "$as_me:$LINENO: error: cannot compute sizeof (__int128), 77 -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute sizeof (__int128), 77 -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } ;; -esac -else - if test "$cross_compiling" = yes; then - { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot run test program while cross compiling -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -long longval () { return (long) (sizeof (__int128)); } -unsigned long ulongval () { return (long) (sizeof (__int128)); } -#include -#include -int -main () -{ - - FILE *f = fopen ("conftest.val", "w"); - if (! f) - exit (1); - if (((long) (sizeof (__int128))) < 0) - { - long i = longval (); - if (i != ((long) (sizeof (__int128)))) - exit (1); - fprintf (f, "%ld\n", i); - } - else - { - unsigned long i = ulongval (); - if (i != ((long) (sizeof (__int128)))) - exit (1); - fprintf (f, "%lu\n", i); - } - exit (ferror (f) || fclose (f) != 0); - - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_sizeof___int128=`cat conftest.val` -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -{ { echo "$as_me:$LINENO: error: cannot compute sizeof (__int128), 77 -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute sizeof (__int128), 77 -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -fi -rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi -fi -rm -f conftest.val -else - ac_cv_sizeof___int128=0 -fi -fi -echo "$as_me:$LINENO: result: $ac_cv_sizeof___int128" >&5 -echo "${ECHO_T}$ac_cv_sizeof___int128" >&6 -cat >>confdefs.h <<_ACEOF -#define SIZEOF___INT128 $ac_cv_sizeof___int128 -_ACEOF - - -echo "$as_me:$LINENO: checking for void *" >&5 -echo $ECHO_N "checking for void *... $ECHO_C" >&6 -if test "${ac_cv_type_void_p+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if ((void * *) 0) - return 0; -if (sizeof (void *)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type_void_p=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_type_void_p=no -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: $ac_cv_type_void_p" >&5 -echo "${ECHO_T}$ac_cv_type_void_p" >&6 - -echo "$as_me:$LINENO: checking size of void *" >&5 -echo $ECHO_N "checking size of void *... $ECHO_C" >&6 -if test "${ac_cv_sizeof_void_p+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test "$ac_cv_type_void_p" = yes; then - # The cast to unsigned long works around a bug in the HP C Compiler - # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects - # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. - # This bug is HP SR number 8606223364. - if test "$cross_compiling" = yes; then - # Depending upon the size, compute the lo and hi bounds. -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (void *))) >= 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=0 ac_mid=0 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (void *))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo=`expr $ac_mid + 1` - if test $ac_lo -le $ac_mid; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid + 1` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (void *))) < 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=-1 ac_mid=-1 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (void *))) >= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_hi=`expr '(' $ac_mid ')' - 1` - if test $ac_mid -le $ac_hi; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo= ac_hi= -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -# Binary search between lo and hi bounds. -while test "x$ac_lo" != "x$ac_hi"; do - ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (void *))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo=`expr '(' $ac_mid ')' + 1` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -done -case $ac_lo in -?*) ac_cv_sizeof_void_p=$ac_lo;; -'') { { echo "$as_me:$LINENO: error: cannot compute sizeof (void *), 77 -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute sizeof (void *), 77 -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } ;; -esac -else - if test "$cross_compiling" = yes; then - { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot run test program while cross compiling -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -long longval () { return (long) (sizeof (void *)); } -unsigned long ulongval () { return (long) (sizeof (void *)); } -#include -#include -int -main () -{ - - FILE *f = fopen ("conftest.val", "w"); - if (! f) - exit (1); - if (((long) (sizeof (void *))) < 0) - { - long i = longval (); - if (i != ((long) (sizeof (void *)))) - exit (1); - fprintf (f, "%ld\n", i); - } - else - { - unsigned long i = ulongval (); - if (i != ((long) (sizeof (void *)))) - exit (1); - fprintf (f, "%lu\n", i); - } - exit (ferror (f) || fclose (f) != 0); - - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_sizeof_void_p=`cat conftest.val` -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -{ { echo "$as_me:$LINENO: error: cannot compute sizeof (void *), 77 -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute sizeof (void *), 77 -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -fi -rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi -fi -rm -f conftest.val -else - ac_cv_sizeof_void_p=0 -fi -fi -echo "$as_me:$LINENO: result: $ac_cv_sizeof_void_p" >&5 -echo "${ECHO_T}$ac_cv_sizeof_void_p" >&6 -cat >>confdefs.h <<_ACEOF -#define SIZEOF_VOID_P $ac_cv_sizeof_void_p -_ACEOF - - -echo "$as_me:$LINENO: checking for float" >&5 -echo $ECHO_N "checking for float... $ECHO_C" >&6 -if test "${ac_cv_type_float+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if ((float *) 0) - return 0; -if (sizeof (float)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type_float=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_type_float=no -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: $ac_cv_type_float" >&5 -echo "${ECHO_T}$ac_cv_type_float" >&6 - -echo "$as_me:$LINENO: checking size of float" >&5 -echo $ECHO_N "checking size of float... $ECHO_C" >&6 -if test "${ac_cv_sizeof_float+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test "$ac_cv_type_float" = yes; then - # The cast to unsigned long works around a bug in the HP C Compiler - # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects - # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. - # This bug is HP SR number 8606223364. - if test "$cross_compiling" = yes; then - # Depending upon the size, compute the lo and hi bounds. -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (float))) >= 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=0 ac_mid=0 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (float))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo=`expr $ac_mid + 1` - if test $ac_lo -le $ac_mid; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid + 1` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (float))) < 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=-1 ac_mid=-1 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (float))) >= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_hi=`expr '(' $ac_mid ')' - 1` - if test $ac_mid -le $ac_hi; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo= ac_hi= -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -# Binary search between lo and hi bounds. -while test "x$ac_lo" != "x$ac_hi"; do - ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (float))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo=`expr '(' $ac_mid ')' + 1` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -done -case $ac_lo in -?*) ac_cv_sizeof_float=$ac_lo;; -'') { { echo "$as_me:$LINENO: error: cannot compute sizeof (float), 77 -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute sizeof (float), 77 -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } ;; -esac -else - if test "$cross_compiling" = yes; then - { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot run test program while cross compiling -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -long longval () { return (long) (sizeof (float)); } -unsigned long ulongval () { return (long) (sizeof (float)); } -#include -#include -int -main () -{ - - FILE *f = fopen ("conftest.val", "w"); - if (! f) - exit (1); - if (((long) (sizeof (float))) < 0) - { - long i = longval (); - if (i != ((long) (sizeof (float)))) - exit (1); - fprintf (f, "%ld\n", i); - } - else - { - unsigned long i = ulongval (); - if (i != ((long) (sizeof (float)))) - exit (1); - fprintf (f, "%lu\n", i); - } - exit (ferror (f) || fclose (f) != 0); - - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_sizeof_float=`cat conftest.val` -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -{ { echo "$as_me:$LINENO: error: cannot compute sizeof (float), 77 -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute sizeof (float), 77 -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -fi -rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi -fi -rm -f conftest.val -else - ac_cv_sizeof_float=0 -fi -fi -echo "$as_me:$LINENO: result: $ac_cv_sizeof_float" >&5 -echo "${ECHO_T}$ac_cv_sizeof_float" >&6 -cat >>confdefs.h <<_ACEOF -#define SIZEOF_FLOAT $ac_cv_sizeof_float -_ACEOF - - -echo "$as_me:$LINENO: checking for double" >&5 -echo $ECHO_N "checking for double... $ECHO_C" >&6 -if test "${ac_cv_type_double+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if ((double *) 0) - return 0; -if (sizeof (double)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type_double=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_type_double=no -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: $ac_cv_type_double" >&5 -echo "${ECHO_T}$ac_cv_type_double" >&6 - -echo "$as_me:$LINENO: checking size of double" >&5 -echo $ECHO_N "checking size of double... $ECHO_C" >&6 -if test "${ac_cv_sizeof_double+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test "$ac_cv_type_double" = yes; then - # The cast to unsigned long works around a bug in the HP C Compiler - # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects - # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. - # This bug is HP SR number 8606223364. - if test "$cross_compiling" = yes; then - # Depending upon the size, compute the lo and hi bounds. -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (double))) >= 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=0 ac_mid=0 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (double))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo=`expr $ac_mid + 1` - if test $ac_lo -le $ac_mid; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid + 1` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (double))) < 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=-1 ac_mid=-1 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (double))) >= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_hi=`expr '(' $ac_mid ')' - 1` - if test $ac_mid -le $ac_hi; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo= ac_hi= -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -# Binary search between lo and hi bounds. -while test "x$ac_lo" != "x$ac_hi"; do - ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (double))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo=`expr '(' $ac_mid ')' + 1` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -done -case $ac_lo in -?*) ac_cv_sizeof_double=$ac_lo;; -'') { { echo "$as_me:$LINENO: error: cannot compute sizeof (double), 77 -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute sizeof (double), 77 -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } ;; -esac -else - if test "$cross_compiling" = yes; then - { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot run test program while cross compiling -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -long longval () { return (long) (sizeof (double)); } -unsigned long ulongval () { return (long) (sizeof (double)); } -#include -#include -int -main () -{ - - FILE *f = fopen ("conftest.val", "w"); - if (! f) - exit (1); - if (((long) (sizeof (double))) < 0) - { - long i = longval (); - if (i != ((long) (sizeof (double)))) - exit (1); - fprintf (f, "%ld\n", i); - } - else - { - unsigned long i = ulongval (); - if (i != ((long) (sizeof (double)))) - exit (1); - fprintf (f, "%lu\n", i); - } - exit (ferror (f) || fclose (f) != 0); - - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_sizeof_double=`cat conftest.val` -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -{ { echo "$as_me:$LINENO: error: cannot compute sizeof (double), 77 -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute sizeof (double), 77 -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -fi -rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi -fi -rm -f conftest.val -else - ac_cv_sizeof_double=0 -fi -fi -echo "$as_me:$LINENO: result: $ac_cv_sizeof_double" >&5 -echo "${ECHO_T}$ac_cv_sizeof_double" >&6 -cat >>confdefs.h <<_ACEOF -#define SIZEOF_DOUBLE $ac_cv_sizeof_double -_ACEOF - - -echo "$as_me:$LINENO: checking for long double" >&5 -echo $ECHO_N "checking for long double... $ECHO_C" >&6 -if test "${ac_cv_type_long_double+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if ((long double *) 0) - return 0; -if (sizeof (long double)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type_long_double=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_type_long_double=no -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: $ac_cv_type_long_double" >&5 -echo "${ECHO_T}$ac_cv_type_long_double" >&6 - -echo "$as_me:$LINENO: checking size of long double" >&5 -echo $ECHO_N "checking size of long double... $ECHO_C" >&6 -if test "${ac_cv_sizeof_long_double+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test "$ac_cv_type_long_double" = yes; then - # The cast to unsigned long works around a bug in the HP C Compiler - # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects - # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. - # This bug is HP SR number 8606223364. - if test "$cross_compiling" = yes; then - # Depending upon the size, compute the lo and hi bounds. -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (long double))) >= 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=0 ac_mid=0 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (long double))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo=`expr $ac_mid + 1` - if test $ac_lo -le $ac_mid; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid + 1` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (long double))) < 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=-1 ac_mid=-1 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (long double))) >= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_hi=`expr '(' $ac_mid ')' - 1` - if test $ac_mid -le $ac_hi; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo= ac_hi= -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -# Binary search between lo and hi bounds. -while test "x$ac_lo" != "x$ac_hi"; do - ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (long double))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo=`expr '(' $ac_mid ')' + 1` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -done -case $ac_lo in -?*) ac_cv_sizeof_long_double=$ac_lo;; -'') { { echo "$as_me:$LINENO: error: cannot compute sizeof (long double), 77 -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute sizeof (long double), 77 -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } ;; -esac -else - if test "$cross_compiling" = yes; then - { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot run test program while cross compiling -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -long longval () { return (long) (sizeof (long double)); } -unsigned long ulongval () { return (long) (sizeof (long double)); } -#include -#include -int -main () -{ - - FILE *f = fopen ("conftest.val", "w"); - if (! f) - exit (1); - if (((long) (sizeof (long double))) < 0) - { - long i = longval (); - if (i != ((long) (sizeof (long double)))) - exit (1); - fprintf (f, "%ld\n", i); - } - else - { - unsigned long i = ulongval (); - if (i != ((long) (sizeof (long double)))) - exit (1); - fprintf (f, "%lu\n", i); - } - exit (ferror (f) || fclose (f) != 0); - - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_sizeof_long_double=`cat conftest.val` -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -{ { echo "$as_me:$LINENO: error: cannot compute sizeof (long double), 77 -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute sizeof (long double), 77 -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -fi -rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi -fi -rm -f conftest.val -else - ac_cv_sizeof_long_double=0 -fi -fi -echo "$as_me:$LINENO: result: $ac_cv_sizeof_long_double" >&5 -echo "${ECHO_T}$ac_cv_sizeof_long_double" >&6 -cat >>confdefs.h <<_ACEOF -#define SIZEOF_LONG_DOUBLE $ac_cv_sizeof_long_double -_ACEOF - - -echo "$as_me:$LINENO: checking for wchar_t" >&5 -echo $ECHO_N "checking for wchar_t... $ECHO_C" >&6 -if test "${ac_cv_type_wchar_t+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if ((wchar_t *) 0) - return 0; -if (sizeof (wchar_t)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_type_wchar_t=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_cv_type_wchar_t=no -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: $ac_cv_type_wchar_t" >&5 -echo "${ECHO_T}$ac_cv_type_wchar_t" >&6 - -echo "$as_me:$LINENO: checking size of wchar_t" >&5 -echo $ECHO_N "checking size of wchar_t... $ECHO_C" >&6 -if test "${ac_cv_sizeof_wchar_t+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - if test "$ac_cv_type_wchar_t" = yes; then - # The cast to unsigned long works around a bug in the HP C Compiler - # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects - # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. - # This bug is HP SR number 8606223364. - if test "$cross_compiling" = yes; then - # Depending upon the size, compute the lo and hi bounds. -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (wchar_t))) >= 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=0 ac_mid=0 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (wchar_t))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo=`expr $ac_mid + 1` - if test $ac_lo -le $ac_mid; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid + 1` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (wchar_t))) < 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=-1 ac_mid=-1 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (wchar_t))) >= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_lo=$ac_mid; break -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_hi=`expr '(' $ac_mid ')' - 1` - if test $ac_mid -le $ac_hi; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo= ac_hi= -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -# Binary search between lo and hi bounds. -while test "x$ac_lo" != "x$ac_hi"; do - ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long) (sizeof (wchar_t))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_hi=$ac_mid -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_lo=`expr '(' $ac_mid ')' + 1` -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -done -case $ac_lo in -?*) ac_cv_sizeof_wchar_t=$ac_lo;; -'') { { echo "$as_me:$LINENO: error: cannot compute sizeof (wchar_t), 77 -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute sizeof (wchar_t), 77 -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } ;; -esac -else - if test "$cross_compiling" = yes; then - { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot run test program while cross compiling -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -long longval () { return (long) (sizeof (wchar_t)); } -unsigned long ulongval () { return (long) (sizeof (wchar_t)); } -#include -#include -int -main () -{ - - FILE *f = fopen ("conftest.val", "w"); - if (! f) - exit (1); - if (((long) (sizeof (wchar_t))) < 0) - { - long i = longval (); - if (i != ((long) (sizeof (wchar_t)))) - exit (1); - fprintf (f, "%ld\n", i); - } - else - { - unsigned long i = ulongval (); - if (i != ((long) (sizeof (wchar_t)))) - exit (1); - fprintf (f, "%lu\n", i); - } - exit (ferror (f) || fclose (f) != 0); - - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_sizeof_wchar_t=`cat conftest.val` -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -{ { echo "$as_me:$LINENO: error: cannot compute sizeof (wchar_t), 77 -See \`config.log' for more details." >&5 -echo "$as_me: error: cannot compute sizeof (wchar_t), 77 -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; } -fi -rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi -fi -rm -f conftest.val -else - ac_cv_sizeof_wchar_t=0 -fi -fi -echo "$as_me:$LINENO: result: $ac_cv_sizeof_wchar_t" >&5 -echo "${ECHO_T}$ac_cv_sizeof_wchar_t" >&6 -cat >>confdefs.h <<_ACEOF -#define SIZEOF_WCHAR_T $ac_cv_sizeof_wchar_t -_ACEOF - - - -cat >>confdefs.h <<_ACEOF -#define ASE_SIZEOF_CHAR ${ac_cv_sizeof_char} -_ACEOF - -cat >>confdefs.h <<_ACEOF -#define ASE_SIZEOF_SHORT ${ac_cv_sizeof_short} -_ACEOF - -cat >>confdefs.h <<_ACEOF -#define ASE_SIZEOF_INT ${ac_cv_sizeof_int} -_ACEOF - -cat >>confdefs.h <<_ACEOF -#define ASE_SIZEOF_LONG ${ac_cv_sizeof_long} -_ACEOF - -cat >>confdefs.h <<_ACEOF -#define ASE_SIZEOF_LONG_LONG ${ac_cv_sizeof_long_long} -_ACEOF - -cat >>confdefs.h <<_ACEOF -#define ASE_SIZEOF___INT8 ${ac_cv_sizeof___int8} -_ACEOF - -cat >>confdefs.h <<_ACEOF -#define ASE_SIZEOF___INT16 ${ac_cv_sizeof___int16} -_ACEOF - -cat >>confdefs.h <<_ACEOF -#define ASE_SIZEOF___INT32 ${ac_cv_sizeof___int32} -_ACEOF - -cat >>confdefs.h <<_ACEOF -#define ASE_SIZEOF___INT64 ${ac_cv_sizeof___int64} -_ACEOF - -cat >>confdefs.h <<_ACEOF -#define ASE_SIZEOF___INT96 ${ac_cv_sizeof___int96} -_ACEOF - -cat >>confdefs.h <<_ACEOF -#define ASE_SIZEOF___INT128 ${ac_cv_sizeof___int128} -_ACEOF - -cat >>confdefs.h <<_ACEOF -#define ASE_SIZEOF_VOID_P ${ac_cv_sizeof_void_p} -_ACEOF - -cat >>confdefs.h <<_ACEOF -#define ASE_SIZEOF_FLOAT ${ac_cv_sizeof_float} -_ACEOF - -cat >>confdefs.h <<_ACEOF -#define ASE_SIZEOF_DOUBLE ${ac_cv_sizeof_double} -_ACEOF - -cat >>confdefs.h <<_ACEOF -#define ASE_SIZEOF_LONG_DOUBLE ${ac_cv_sizeof_long_double} -_ACEOF - -cat >>confdefs.h <<_ACEOF -#define ASE_SIZEOF_WCHAR_T ${ac_cv_sizeof_wchar_t} -_ACEOF - - -# Defines extra options - -# Check whether --enable-wchar or --disable-wchar was given. -if test "${enable_wchar+set}" = set; then - enableval="$enable_wchar" - enable_wchar_is=$enableval -else - enable_wchar_is=yes -fi; -if test "$enable_wchar_is" = "yes" -then - -cat >>confdefs.h <<\_ACEOF -#define ASE_CHAR_IS_WCHAR -_ACEOF - -else - -cat >>confdefs.h <<\_ACEOF -#define ASE_CHAR_IS_MCHAR -_ACEOF - -fi - -# Check whether --enable-mode or --disable-mode was given. -if test "${enable_mode+set}" = set; then - enableval="$enable_mode" - enable_debug_is=$enableval -else - enable_debug_is=no -fi; -if test "$enable_debug_is" = "yes" -then - CFLAGS="$CFLAGS -g -D_DEBUG -UNDEBUG" - BUILDMODE="debug" - -else - CFLAGS="$CFLAGS -DNDEBUG -U_DEBUG" - BUILDMODE="release" - -fi - -# Configure makefiles -# Check whether --enable-reentrant or --disable-reentrant was given. -if test "${enable_reentrant+set}" = set; then - enableval="$enable_reentrant" - enable_reentrant_is=$enableval -else - enable_reentrant_is=yes -fi; -if test "$enable_reentrant_is" = "yes" -then - CFLAGS="$CFLAGS -D_REENTRANT -D_THREAD_SAFE" -fi - - ac_config_files="$ac_config_files makefile cmn/makefile awk/makefile lsp/makefile utl/makefile test/awk/makefile test/lsp/makefile" - -cat >confcache <<\_ACEOF -# This file is a shell script that caches the results of configure -# tests run on this system so they can be shared between configure -# scripts and configure runs, see configure's option --config-cache. -# It is not useful on other systems. If it contains results you don't -# want to keep, you may remove or edit it. -# -# config.status only pays attention to the cache file if you give it -# the --recheck option to rerun configure. -# -# `ac_cv_env_foo' variables (set or unset) will be overridden when -# loading this file, other *unset* `ac_cv_foo' will be assigned the -# following values. - -_ACEOF - -# The following way of writing the cache mishandles newlines in values, -# but we know of no workaround that is simple, portable, and efficient. -# So, don't put newlines in cache variables' values. -# Ultrix sh set writes to stderr and can't be redirected directly, -# and sets the high bit in the cache file unless we assign to the vars. -{ - (set) 2>&1 | - case `(ac_space=' '; set | grep ac_space) 2>&1` in - *ac_space=\ *) - # `set' does not quote correctly, so add quotes (double-quote - # substitution turns \\\\ into \\, and sed turns \\ into \). - sed -n \ - "s/'/'\\\\''/g; - s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p" - ;; - *) - # `set' quotes correctly as required by POSIX, so do not add quotes. - sed -n \ - "s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1=\\2/p" - ;; - esac; -} | - sed ' - t clear - : clear - s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/ - t end - /^ac_cv_env/!s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/ - : end' >>confcache -if diff $cache_file confcache >/dev/null 2>&1; then :; else - if test -w $cache_file; then - test "x$cache_file" != "x/dev/null" && echo "updating cache $cache_file" - cat confcache >$cache_file - else - echo "not updating unwritable cache $cache_file" - fi -fi -rm -f confcache - -test "x$prefix" = xNONE && prefix=$ac_default_prefix -# Let make expand exec_prefix. -test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' - -# VPATH may cause trouble with some makes, so we remove $(srcdir), -# ${srcdir} and @srcdir@ from VPATH if srcdir is ".", strip leading and -# trailing colons and then remove the whole line if VPATH becomes empty -# (actually we leave an empty line to preserve line numbers). -if test "x$srcdir" = x.; then - ac_vpsub='/^[ ]*VPATH[ ]*=/{ -s/:*\$(srcdir):*/:/; -s/:*\${srcdir}:*/:/; -s/:*@srcdir@:*/:/; -s/^\([^=]*=[ ]*\):*/\1/; -s/:*$//; -s/^[^=]*=[ ]*$//; -}' -fi - -DEFS=-DHAVE_CONFIG_H - -ac_libobjs= -ac_ltlibobjs= -for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue - # 1. Remove the extension, and $U if already installed. - ac_i=`echo "$ac_i" | - sed 's/\$U\././;s/\.o$//;s/\.obj$//'` - # 2. Add them. - ac_libobjs="$ac_libobjs $ac_i\$U.$ac_objext" - ac_ltlibobjs="$ac_ltlibobjs $ac_i"'$U.lo' -done -LIBOBJS=$ac_libobjs - -LTLIBOBJS=$ac_ltlibobjs - - - -: ${CONFIG_STATUS=./config.status} -ac_clean_files_save=$ac_clean_files -ac_clean_files="$ac_clean_files $CONFIG_STATUS" -{ echo "$as_me:$LINENO: creating $CONFIG_STATUS" >&5 -echo "$as_me: creating $CONFIG_STATUS" >&6;} -cat >$CONFIG_STATUS <<_ACEOF -#! $SHELL -# Generated by $as_me. -# Run this file to recreate the current configuration. -# Compiler output produced by configure, useful for debugging -# configure, is in config.log if it exists. - -debug=false -ac_cs_recheck=false -ac_cs_silent=false -SHELL=\${CONFIG_SHELL-$SHELL} -_ACEOF - -cat >>$CONFIG_STATUS <<\_ACEOF -## --------------------- ## -## M4sh Initialization. ## -## --------------------- ## - -# Be Bourne compatible -if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then - emulate sh - NULLCMD=: - # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which - # is contrary to our usage. Disable this feature. - alias -g '${1+"$@"}'='"$@"' -elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then - set -o posix -fi -DUALCASE=1; export DUALCASE # for MKS sh - -# Support unset when possible. -if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then - as_unset=unset -else - as_unset=false -fi - - -# Work around bugs in pre-3.0 UWIN ksh. -$as_unset ENV MAIL MAILPATH -PS1='$ ' -PS2='> ' -PS4='+ ' - -# NLS nuisances. -for as_var in \ - LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \ - LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \ - LC_TELEPHONE LC_TIME -do - if (set +x; test -z "`(eval $as_var=C; export $as_var) 2>&1`"); then - eval $as_var=C; export $as_var - else - $as_unset $as_var - fi -done - -# Required to use basename. -if expr a : '\(a\)' >/dev/null 2>&1; then - as_expr=expr -else - as_expr=false -fi - -if (basename /) >/dev/null 2>&1 && test "X`basename / 2>&1`" = "X/"; then - as_basename=basename -else - as_basename=false -fi - - -# Name of the executable. -as_me=`$as_basename "$0" || -$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ - X"$0" : 'X\(//\)$' \| \ - X"$0" : 'X\(/\)$' \| \ - . : '\(.\)' 2>/dev/null || -echo X/"$0" | - sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/; q; } - /^X\/\(\/\/\)$/{ s//\1/; q; } - /^X\/\(\/\).*/{ s//\1/; q; } - s/.*/./; q'` - - -# PATH needs CR, and LINENO needs CR and PATH. -# Avoid depending upon Character Ranges. -as_cr_letters='abcdefghijklmnopqrstuvwxyz' -as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' -as_cr_Letters=$as_cr_letters$as_cr_LETTERS -as_cr_digits='0123456789' -as_cr_alnum=$as_cr_Letters$as_cr_digits - -# The user is always right. -if test "${PATH_SEPARATOR+set}" != set; then - echo "#! /bin/sh" >conf$$.sh - echo "exit 0" >>conf$$.sh - chmod +x conf$$.sh - if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then - PATH_SEPARATOR=';' - else - PATH_SEPARATOR=: - fi - rm -f conf$$.sh -fi - - - as_lineno_1=$LINENO - as_lineno_2=$LINENO - as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null` - test "x$as_lineno_1" != "x$as_lineno_2" && - test "x$as_lineno_3" = "x$as_lineno_2" || { - # Find who we are. Look in the path if we contain no path at all - # relative or not. - case $0 in - *[\\/]* ) as_myself=$0 ;; - *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break -done - - ;; - esac - # We did not find ourselves, most probably we were run as `sh COMMAND' - # in which case we are not to be found in the path. - if test "x$as_myself" = x; then - as_myself=$0 - fi - if test ! -f "$as_myself"; then - { { echo "$as_me:$LINENO: error: cannot find myself; rerun with an absolute path" >&5 -echo "$as_me: error: cannot find myself; rerun with an absolute path" >&2;} - { (exit 1); exit 1; }; } - fi - case $CONFIG_SHELL in - '') - as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for as_base in sh bash ksh sh5; do - case $as_dir in - /*) - if ("$as_dir/$as_base" -c ' - as_lineno_1=$LINENO - as_lineno_2=$LINENO - as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null` - test "x$as_lineno_1" != "x$as_lineno_2" && - test "x$as_lineno_3" = "x$as_lineno_2" ') 2>/dev/null; then - $as_unset BASH_ENV || test "${BASH_ENV+set}" != set || { BASH_ENV=; export BASH_ENV; } - $as_unset ENV || test "${ENV+set}" != set || { ENV=; export ENV; } - CONFIG_SHELL=$as_dir/$as_base - export CONFIG_SHELL - exec "$CONFIG_SHELL" "$0" ${1+"$@"} - fi;; - esac - done -done -;; - esac - - # Create $as_me.lineno as a copy of $as_myself, but with $LINENO - # uniformly replaced by the line number. The first 'sed' inserts a - # line-number line before each line; the second 'sed' does the real - # work. The second script uses 'N' to pair each line-number line - # with the numbered line, and appends trailing '-' during - # substitution so that $LINENO is not a special case at line end. - # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the - # second 'sed' script. Blame Lee E. McMahon for sed's syntax. :-) - sed '=' <$as_myself | - sed ' - N - s,$,-, - : loop - s,^\(['$as_cr_digits']*\)\(.*\)[$]LINENO\([^'$as_cr_alnum'_]\),\1\2\1\3, - t loop - s,-$,, - s,^['$as_cr_digits']*\n,, - ' >$as_me.lineno && - chmod +x $as_me.lineno || - { { echo "$as_me:$LINENO: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&5 -echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2;} - { (exit 1); exit 1; }; } - - # Don't try to exec as it changes $[0], causing all sort of problems - # (the dirname of $[0] is not the place where we might find the - # original and so on. Autoconf is especially sensible to this). - . ./$as_me.lineno - # Exit status is that of the last command. - exit -} - - -case `echo "testing\c"; echo 1,2,3`,`echo -n testing; echo 1,2,3` in - *c*,-n*) ECHO_N= ECHO_C=' -' ECHO_T=' ' ;; - *c*,* ) ECHO_N=-n ECHO_C= ECHO_T= ;; - *) ECHO_N= ECHO_C='\c' ECHO_T= ;; -esac - -if expr a : '\(a\)' >/dev/null 2>&1; then - as_expr=expr -else - as_expr=false -fi - -rm -f conf$$ conf$$.exe conf$$.file -echo >conf$$.file -if ln -s conf$$.file conf$$ 2>/dev/null; then - # We could just check for DJGPP; but this test a) works b) is more generic - # and c) will remain valid once DJGPP supports symlinks (DJGPP 2.04). - if test -f conf$$.exe; then - # Don't use ln at all; we don't have any links - as_ln_s='cp -p' - else - as_ln_s='ln -s' - fi -elif ln conf$$.file conf$$ 2>/dev/null; then - as_ln_s=ln -else - as_ln_s='cp -p' -fi -rm -f conf$$ conf$$.exe conf$$.file - -if mkdir -p . 2>/dev/null; then - as_mkdir_p=: -else - test -d ./-p && rmdir ./-p - as_mkdir_p=false -fi - -as_executable_p="test -f" - -# Sed expression to map a string onto a valid CPP name. -as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" - -# Sed expression to map a string onto a valid variable name. -as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" - - -# IFS -# We need space, tab and new line, in precisely that order. -as_nl=' -' -IFS=" $as_nl" - -# CDPATH. -$as_unset CDPATH - -exec 6>&1 - -# Open the log real soon, to keep \$[0] and so on meaningful, and to -# report actual input values of CONFIG_FILES etc. instead of their -# values after options handling. Logging --version etc. is OK. -exec 5>>config.log -{ - echo - sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX -## Running $as_me. ## -_ASBOX -} >&5 -cat >&5 <<_CSEOF - -This file was extended by ase $as_me deb-0.1.0, which was -generated by GNU Autoconf 2.59. Invocation command line was - - CONFIG_FILES = $CONFIG_FILES - CONFIG_HEADERS = $CONFIG_HEADERS - CONFIG_LINKS = $CONFIG_LINKS - CONFIG_COMMANDS = $CONFIG_COMMANDS - $ $0 $@ - -_CSEOF -echo "on `(hostname || uname -n) 2>/dev/null | sed 1q`" >&5 -echo >&5 -_ACEOF - -# Files that config.status was made for. -if test -n "$ac_config_files"; then - echo "config_files=\"$ac_config_files\"" >>$CONFIG_STATUS -fi - -if test -n "$ac_config_headers"; then - echo "config_headers=\"$ac_config_headers\"" >>$CONFIG_STATUS -fi - -if test -n "$ac_config_links"; then - echo "config_links=\"$ac_config_links\"" >>$CONFIG_STATUS -fi - -if test -n "$ac_config_commands"; then - echo "config_commands=\"$ac_config_commands\"" >>$CONFIG_STATUS -fi - -cat >>$CONFIG_STATUS <<\_ACEOF - -ac_cs_usage="\ -\`$as_me' instantiates files from templates according to the -current configuration. - -Usage: $0 [OPTIONS] [FILE]... - - -h, --help print this help, then exit - -V, --version print version number, then exit - -q, --quiet do not print progress messages - -d, --debug don't remove temporary files - --recheck update $as_me by reconfiguring in the same conditions - --file=FILE[:TEMPLATE] - instantiate the configuration file FILE - --header=FILE[:TEMPLATE] - instantiate the configuration header FILE - -Configuration files: -$config_files - -Configuration headers: -$config_headers - -Report bugs to ." -_ACEOF - -cat >>$CONFIG_STATUS <<_ACEOF -ac_cs_version="\\ -ase config.status deb-0.1.0 -configured by $0, generated by GNU Autoconf 2.59, - with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\" - -Copyright (C) 2003 Free Software Foundation, Inc. -This config.status script is free software; the Free Software Foundation -gives unlimited permission to copy, distribute and modify it." -srcdir=$srcdir -_ACEOF - -cat >>$CONFIG_STATUS <<\_ACEOF -# If no file are specified by the user, then we need to provide default -# value. By we need to know if files were specified by the user. -ac_need_defaults=: -while test $# != 0 -do - case $1 in - --*=*) - ac_option=`expr "x$1" : 'x\([^=]*\)='` - ac_optarg=`expr "x$1" : 'x[^=]*=\(.*\)'` - ac_shift=: - ;; - -*) - ac_option=$1 - ac_optarg=$2 - ac_shift=shift - ;; - *) # This is not an option, so the user has probably given explicit - # arguments. - ac_option=$1 - ac_need_defaults=false;; - esac - - case $ac_option in - # Handling of the options. -_ACEOF -cat >>$CONFIG_STATUS <<\_ACEOF - -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) - ac_cs_recheck=: ;; - --version | --vers* | -V ) - echo "$ac_cs_version"; exit 0 ;; - --he | --h) - # Conflict between --help and --header - { { echo "$as_me:$LINENO: error: ambiguous option: $1 -Try \`$0 --help' for more information." >&5 -echo "$as_me: error: ambiguous option: $1 -Try \`$0 --help' for more information." >&2;} - { (exit 1); exit 1; }; };; - --help | --hel | -h ) - echo "$ac_cs_usage"; exit 0 ;; - --debug | --d* | -d ) - debug=: ;; - --file | --fil | --fi | --f ) - $ac_shift - CONFIG_FILES="$CONFIG_FILES $ac_optarg" - ac_need_defaults=false;; - --header | --heade | --head | --hea ) - $ac_shift - CONFIG_HEADERS="$CONFIG_HEADERS $ac_optarg" - ac_need_defaults=false;; - -q | -quiet | --quiet | --quie | --qui | --qu | --q \ - | -silent | --silent | --silen | --sile | --sil | --si | --s) - ac_cs_silent=: ;; - - # This is an error. - -*) { { echo "$as_me:$LINENO: error: unrecognized option: $1 -Try \`$0 --help' for more information." >&5 -echo "$as_me: error: unrecognized option: $1 -Try \`$0 --help' for more information." >&2;} - { (exit 1); exit 1; }; } ;; - - *) ac_config_targets="$ac_config_targets $1" ;; - - esac - shift -done - -ac_configure_extra_args= - -if $ac_cs_silent; then - exec 6>/dev/null - ac_configure_extra_args="$ac_configure_extra_args --silent" -fi - -_ACEOF -cat >>$CONFIG_STATUS <<_ACEOF -if \$ac_cs_recheck; then - echo "running $SHELL $0 " $ac_configure_args \$ac_configure_extra_args " --no-create --no-recursion" >&6 - exec $SHELL $0 $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion -fi - -_ACEOF - - - - - -cat >>$CONFIG_STATUS <<\_ACEOF -for ac_config_target in $ac_config_targets -do - case "$ac_config_target" in - # Handling of arguments. - "makefile" ) CONFIG_FILES="$CONFIG_FILES makefile" ;; - "cmn/makefile" ) CONFIG_FILES="$CONFIG_FILES cmn/makefile" ;; - "awk/makefile" ) CONFIG_FILES="$CONFIG_FILES awk/makefile" ;; - "lsp/makefile" ) CONFIG_FILES="$CONFIG_FILES lsp/makefile" ;; - "utl/makefile" ) CONFIG_FILES="$CONFIG_FILES utl/makefile" ;; - "test/awk/makefile" ) CONFIG_FILES="$CONFIG_FILES test/awk/makefile" ;; - "test/lsp/makefile" ) CONFIG_FILES="$CONFIG_FILES test/lsp/makefile" ;; - "cmn/conf_unx.h" ) CONFIG_HEADERS="$CONFIG_HEADERS cmn/conf_unx.h" ;; - *) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5 -echo "$as_me: error: invalid argument: $ac_config_target" >&2;} - { (exit 1); exit 1; }; };; - esac -done - -# If the user did not use the arguments to specify the items to instantiate, -# then the envvar interface is used. Set only those that are not. -# We use the long form for the default assignment because of an extremely -# bizarre bug on SunOS 4.1.3. -if $ac_need_defaults; then - test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files - test "${CONFIG_HEADERS+set}" = set || CONFIG_HEADERS=$config_headers -fi - -# Have a temporary directory for convenience. Make it in the build tree -# simply because there is no reason to put it here, and in addition, -# creating and moving files from /tmp can sometimes cause problems. -# Create a temporary directory, and hook for its removal unless debugging. -$debug || -{ - trap 'exit_status=$?; rm -rf $tmp && exit $exit_status' 0 - trap '{ (exit 1); exit 1; }' 1 2 13 15 -} - -# Create a (secure) tmp directory for tmp files. - -{ - tmp=`(umask 077 && mktemp -d -q "./confstatXXXXXX") 2>/dev/null` && - test -n "$tmp" && test -d "$tmp" -} || -{ - tmp=./confstat$$-$RANDOM - (umask 077 && mkdir $tmp) -} || -{ - echo "$me: cannot create a temporary directory in ." >&2 - { (exit 1); exit 1; } -} - -_ACEOF - -cat >>$CONFIG_STATUS <<_ACEOF - -# -# CONFIG_FILES section. -# - -# No need to generate the scripts if there are no CONFIG_FILES. -# This happens for instance when ./config.status config.h -if test -n "\$CONFIG_FILES"; then - # Protect against being on the right side of a sed subst in config.status. - sed 's/,@/@@/; s/@,/@@/; s/,;t t\$/@;t t/; /@;t t\$/s/[\\\\&,]/\\\\&/g; - s/@@/,@/; s/@@/@,/; s/@;t t\$/,;t t/' >\$tmp/subs.sed <<\\CEOF -s,@SHELL@,$SHELL,;t t -s,@PATH_SEPARATOR@,$PATH_SEPARATOR,;t t -s,@PACKAGE_NAME@,$PACKAGE_NAME,;t t -s,@PACKAGE_TARNAME@,$PACKAGE_TARNAME,;t t -s,@PACKAGE_VERSION@,$PACKAGE_VERSION,;t t -s,@PACKAGE_STRING@,$PACKAGE_STRING,;t t -s,@PACKAGE_BUGREPORT@,$PACKAGE_BUGREPORT,;t t -s,@exec_prefix@,$exec_prefix,;t t -s,@prefix@,$prefix,;t t -s,@program_transform_name@,$program_transform_name,;t t -s,@bindir@,$bindir,;t t -s,@sbindir@,$sbindir,;t t -s,@libexecdir@,$libexecdir,;t t -s,@datadir@,$datadir,;t t -s,@sysconfdir@,$sysconfdir,;t t -s,@sharedstatedir@,$sharedstatedir,;t t -s,@localstatedir@,$localstatedir,;t t -s,@libdir@,$libdir,;t t -s,@includedir@,$includedir,;t t -s,@oldincludedir@,$oldincludedir,;t t -s,@infodir@,$infodir,;t t -s,@mandir@,$mandir,;t t -s,@build_alias@,$build_alias,;t t -s,@host_alias@,$host_alias,;t t -s,@target_alias@,$target_alias,;t t -s,@DEFS@,$DEFS,;t t -s,@ECHO_C@,$ECHO_C,;t t -s,@ECHO_N@,$ECHO_N,;t t -s,@ECHO_T@,$ECHO_T,;t t -s,@LIBS@,$LIBS,;t t -s,@CC@,$CC,;t t -s,@CFLAGS@,$CFLAGS,;t t -s,@LDFLAGS@,$LDFLAGS,;t t -s,@CPPFLAGS@,$CPPFLAGS,;t t -s,@ac_ct_CC@,$ac_ct_CC,;t t -s,@EXEEXT@,$EXEEXT,;t t -s,@OBJEXT@,$OBJEXT,;t t -s,@RANLIB@,$RANLIB,;t t -s,@ac_ct_RANLIB@,$ac_ct_RANLIB,;t t -s,@CPP@,$CPP,;t t -s,@EGREP@,$EGREP,;t t -s,@BUILDMODE@,$BUILDMODE,;t t -s,@LIBOBJS@,$LIBOBJS,;t t -s,@LTLIBOBJS@,$LTLIBOBJS,;t t -CEOF - -_ACEOF - - cat >>$CONFIG_STATUS <<\_ACEOF - # Split the substitutions into bite-sized pieces for seds with - # small command number limits, like on Digital OSF/1 and HP-UX. - ac_max_sed_lines=48 - ac_sed_frag=1 # Number of current file. - ac_beg=1 # First line for current file. - ac_end=$ac_max_sed_lines # Line after last line for current file. - ac_more_lines=: - ac_sed_cmds= - while $ac_more_lines; do - if test $ac_beg -gt 1; then - sed "1,${ac_beg}d; ${ac_end}q" $tmp/subs.sed >$tmp/subs.frag - else - sed "${ac_end}q" $tmp/subs.sed >$tmp/subs.frag - fi - if test ! -s $tmp/subs.frag; then - ac_more_lines=false - else - # The purpose of the label and of the branching condition is to - # speed up the sed processing (if there are no `@' at all, there - # is no need to browse any of the substitutions). - # These are the two extra sed commands mentioned above. - (echo ':t - /@[a-zA-Z_][a-zA-Z_0-9]*@/!b' && cat $tmp/subs.frag) >$tmp/subs-$ac_sed_frag.sed - if test -z "$ac_sed_cmds"; then - ac_sed_cmds="sed -f $tmp/subs-$ac_sed_frag.sed" - else - ac_sed_cmds="$ac_sed_cmds | sed -f $tmp/subs-$ac_sed_frag.sed" - fi - ac_sed_frag=`expr $ac_sed_frag + 1` - ac_beg=$ac_end - ac_end=`expr $ac_end + $ac_max_sed_lines` - fi - done - if test -z "$ac_sed_cmds"; then - ac_sed_cmds=cat - fi -fi # test -n "$CONFIG_FILES" - -_ACEOF -cat >>$CONFIG_STATUS <<\_ACEOF -for ac_file in : $CONFIG_FILES; do test "x$ac_file" = x: && continue - # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in". - case $ac_file in - - | *:- | *:-:* ) # input from stdin - cat >$tmp/stdin - ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'` - ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;; - *:* ) ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'` - ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;; - * ) ac_file_in=$ac_file.in ;; - esac - - # Compute @srcdir@, @top_srcdir@, and @INSTALL@ for subdirectories. - ac_dir=`(dirname "$ac_file") 2>/dev/null || -$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ - X"$ac_file" : 'X\(//\)[^/]' \| \ - X"$ac_file" : 'X\(//\)$' \| \ - X"$ac_file" : 'X\(/\)' \| \ - . : '\(.\)' 2>/dev/null || -echo X"$ac_file" | - sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; } - /^X\(\/\/\)[^/].*/{ s//\1/; q; } - /^X\(\/\/\)$/{ s//\1/; q; } - /^X\(\/\).*/{ s//\1/; q; } - s/.*/./; q'` - { if $as_mkdir_p; then - mkdir -p "$ac_dir" - else - as_dir="$ac_dir" - as_dirs= - while test ! -d "$as_dir"; do - as_dirs="$as_dir $as_dirs" - as_dir=`(dirname "$as_dir") 2>/dev/null || -$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ - X"$as_dir" : 'X\(//\)[^/]' \| \ - X"$as_dir" : 'X\(//\)$' \| \ - X"$as_dir" : 'X\(/\)' \| \ - . : '\(.\)' 2>/dev/null || -echo X"$as_dir" | - sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; } - /^X\(\/\/\)[^/].*/{ s//\1/; q; } - /^X\(\/\/\)$/{ s//\1/; q; } - /^X\(\/\).*/{ s//\1/; q; } - s/.*/./; q'` - done - test ! -n "$as_dirs" || mkdir $as_dirs - fi || { { echo "$as_me:$LINENO: error: cannot create directory \"$ac_dir\"" >&5 -echo "$as_me: error: cannot create directory \"$ac_dir\"" >&2;} - { (exit 1); exit 1; }; }; } - - ac_builddir=. - -if test "$ac_dir" != .; then - ac_dir_suffix=/`echo "$ac_dir" | sed 's,^\.[\\/],,'` - # A "../" for each directory in $ac_dir_suffix. - ac_top_builddir=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,../,g'` -else - ac_dir_suffix= ac_top_builddir= -fi - -case $srcdir in - .) # No --srcdir option. We are building in place. - ac_srcdir=. - if test -z "$ac_top_builddir"; then - ac_top_srcdir=. - else - ac_top_srcdir=`echo $ac_top_builddir | sed 's,/$,,'` - fi ;; - [\\/]* | ?:[\\/]* ) # Absolute path. - ac_srcdir=$srcdir$ac_dir_suffix; - ac_top_srcdir=$srcdir ;; - *) # Relative path. - ac_srcdir=$ac_top_builddir$srcdir$ac_dir_suffix - ac_top_srcdir=$ac_top_builddir$srcdir ;; -esac - -# Do not use `cd foo && pwd` to compute absolute paths, because -# the directories may not exist. -case `pwd` in -.) ac_abs_builddir="$ac_dir";; -*) - case "$ac_dir" in - .) ac_abs_builddir=`pwd`;; - [\\/]* | ?:[\\/]* ) ac_abs_builddir="$ac_dir";; - *) ac_abs_builddir=`pwd`/"$ac_dir";; - esac;; -esac -case $ac_abs_builddir in -.) ac_abs_top_builddir=${ac_top_builddir}.;; -*) - case ${ac_top_builddir}. in - .) ac_abs_top_builddir=$ac_abs_builddir;; - [\\/]* | ?:[\\/]* ) ac_abs_top_builddir=${ac_top_builddir}.;; - *) ac_abs_top_builddir=$ac_abs_builddir/${ac_top_builddir}.;; - esac;; -esac -case $ac_abs_builddir in -.) ac_abs_srcdir=$ac_srcdir;; -*) - case $ac_srcdir in - .) ac_abs_srcdir=$ac_abs_builddir;; - [\\/]* | ?:[\\/]* ) ac_abs_srcdir=$ac_srcdir;; - *) ac_abs_srcdir=$ac_abs_builddir/$ac_srcdir;; - esac;; -esac -case $ac_abs_builddir in -.) ac_abs_top_srcdir=$ac_top_srcdir;; -*) - case $ac_top_srcdir in - .) ac_abs_top_srcdir=$ac_abs_builddir;; - [\\/]* | ?:[\\/]* ) ac_abs_top_srcdir=$ac_top_srcdir;; - *) ac_abs_top_srcdir=$ac_abs_builddir/$ac_top_srcdir;; - esac;; -esac - - - - if test x"$ac_file" != x-; then - { echo "$as_me:$LINENO: creating $ac_file" >&5 -echo "$as_me: creating $ac_file" >&6;} - rm -f "$ac_file" - fi - # Let's still pretend it is `configure' which instantiates (i.e., don't - # use $as_me), people would be surprised to read: - # /* config.h. Generated by config.status. */ - if test x"$ac_file" = x-; then - configure_input= - else - configure_input="$ac_file. " - fi - configure_input=$configure_input"Generated from `echo $ac_file_in | - sed 's,.*/,,'` by configure." - - # First look for the input files in the build tree, otherwise in the - # src tree. - ac_file_inputs=`IFS=: - for f in $ac_file_in; do - case $f in - -) echo $tmp/stdin ;; - [\\/$]*) - # Absolute (can't be DOS-style, as IFS=:) - test -f "$f" || { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5 -echo "$as_me: error: cannot find input file: $f" >&2;} - { (exit 1); exit 1; }; } - echo "$f";; - *) # Relative - if test -f "$f"; then - # Build tree - echo "$f" - elif test -f "$srcdir/$f"; then - # Source tree - echo "$srcdir/$f" - else - # /dev/null tree - { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5 -echo "$as_me: error: cannot find input file: $f" >&2;} - { (exit 1); exit 1; }; } - fi;; - esac - done` || { (exit 1); exit 1; } -_ACEOF -cat >>$CONFIG_STATUS <<_ACEOF - sed "$ac_vpsub -$extrasub -_ACEOF -cat >>$CONFIG_STATUS <<\_ACEOF -:t -/@[a-zA-Z_][a-zA-Z_0-9]*@/!b -s,@configure_input@,$configure_input,;t t -s,@srcdir@,$ac_srcdir,;t t -s,@abs_srcdir@,$ac_abs_srcdir,;t t -s,@top_srcdir@,$ac_top_srcdir,;t t -s,@abs_top_srcdir@,$ac_abs_top_srcdir,;t t -s,@builddir@,$ac_builddir,;t t -s,@abs_builddir@,$ac_abs_builddir,;t t -s,@top_builddir@,$ac_top_builddir,;t t -s,@abs_top_builddir@,$ac_abs_top_builddir,;t t -" $ac_file_inputs | (eval "$ac_sed_cmds") >$tmp/out - rm -f $tmp/stdin - if test x"$ac_file" != x-; then - mv $tmp/out $ac_file - else - cat $tmp/out - rm -f $tmp/out - fi - -done -_ACEOF -cat >>$CONFIG_STATUS <<\_ACEOF - -# -# CONFIG_HEADER section. -# - -# These sed commands are passed to sed as "A NAME B NAME C VALUE D", where -# NAME is the cpp macro being defined and VALUE is the value it is being given. -# -# ac_d sets the value in "#define NAME VALUE" lines. -ac_dA='s,^\([ ]*\)#\([ ]*define[ ][ ]*\)' -ac_dB='[ ].*$,\1#\2' -ac_dC=' ' -ac_dD=',;t' -# ac_u turns "#undef NAME" without trailing blanks into "#define NAME VALUE". -ac_uA='s,^\([ ]*\)#\([ ]*\)undef\([ ][ ]*\)' -ac_uB='$,\1#\2define\3' -ac_uC=' ' -ac_uD=',;t' - -for ac_file in : $CONFIG_HEADERS; do test "x$ac_file" = x: && continue - # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in". - case $ac_file in - - | *:- | *:-:* ) # input from stdin - cat >$tmp/stdin - ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'` - ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;; - *:* ) ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'` - ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;; - * ) ac_file_in=$ac_file.in ;; - esac - - test x"$ac_file" != x- && { echo "$as_me:$LINENO: creating $ac_file" >&5 -echo "$as_me: creating $ac_file" >&6;} - - # First look for the input files in the build tree, otherwise in the - # src tree. - ac_file_inputs=`IFS=: - for f in $ac_file_in; do - case $f in - -) echo $tmp/stdin ;; - [\\/$]*) - # Absolute (can't be DOS-style, as IFS=:) - test -f "$f" || { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5 -echo "$as_me: error: cannot find input file: $f" >&2;} - { (exit 1); exit 1; }; } - # Do quote $f, to prevent DOS paths from being IFS'd. - echo "$f";; - *) # Relative - if test -f "$f"; then - # Build tree - echo "$f" - elif test -f "$srcdir/$f"; then - # Source tree - echo "$srcdir/$f" - else - # /dev/null tree - { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5 -echo "$as_me: error: cannot find input file: $f" >&2;} - { (exit 1); exit 1; }; } - fi;; - esac - done` || { (exit 1); exit 1; } - # Remove the trailing spaces. - sed 's/[ ]*$//' $ac_file_inputs >$tmp/in - -_ACEOF - -# Transform confdefs.h into two sed scripts, `conftest.defines' and -# `conftest.undefs', that substitutes the proper values into -# config.h.in to produce config.h. The first handles `#define' -# templates, and the second `#undef' templates. -# And first: Protect against being on the right side of a sed subst in -# config.status. Protect against being in an unquoted here document -# in config.status. -rm -f conftest.defines conftest.undefs -# Using a here document instead of a string reduces the quoting nightmare. -# Putting comments in sed scripts is not portable. -# -# `end' is used to avoid that the second main sed command (meant for -# 0-ary CPP macros) applies to n-ary macro definitions. -# See the Autoconf documentation for `clear'. -cat >confdef2sed.sed <<\_ACEOF -s/[\\&,]/\\&/g -s,[\\$`],\\&,g -t clear -: clear -s,^[ ]*#[ ]*define[ ][ ]*\([^ (][^ (]*\)\(([^)]*)\)[ ]*\(.*\)$,${ac_dA}\1${ac_dB}\1\2${ac_dC}\3${ac_dD},gp -t end -s,^[ ]*#[ ]*define[ ][ ]*\([^ ][^ ]*\)[ ]*\(.*\)$,${ac_dA}\1${ac_dB}\1${ac_dC}\2${ac_dD},gp -: end -_ACEOF -# If some macros were called several times there might be several times -# the same #defines, which is useless. Nevertheless, we may not want to -# sort them, since we want the *last* AC-DEFINE to be honored. -uniq confdefs.h | sed -n -f confdef2sed.sed >conftest.defines -sed 's/ac_d/ac_u/g' conftest.defines >conftest.undefs -rm -f confdef2sed.sed - -# This sed command replaces #undef with comments. This is necessary, for -# example, in the case of _POSIX_SOURCE, which is predefined and required -# on some systems where configure will not decide to define it. -cat >>conftest.undefs <<\_ACEOF -s,^[ ]*#[ ]*undef[ ][ ]*[a-zA-Z_][a-zA-Z_0-9]*,/* & */, -_ACEOF - -# Break up conftest.defines because some shells have a limit on the size -# of here documents, and old seds have small limits too (100 cmds). -echo ' # Handle all the #define templates only if necessary.' >>$CONFIG_STATUS -echo ' if grep "^[ ]*#[ ]*define" $tmp/in >/dev/null; then' >>$CONFIG_STATUS -echo ' # If there are no defines, we may have an empty if/fi' >>$CONFIG_STATUS -echo ' :' >>$CONFIG_STATUS -rm -f conftest.tail -while grep . conftest.defines >/dev/null -do - # Write a limited-size here document to $tmp/defines.sed. - echo ' cat >$tmp/defines.sed <>$CONFIG_STATUS - # Speed up: don't consider the non `#define' lines. - echo '/^[ ]*#[ ]*define/!b' >>$CONFIG_STATUS - # Work around the forget-to-reset-the-flag bug. - echo 't clr' >>$CONFIG_STATUS - echo ': clr' >>$CONFIG_STATUS - sed ${ac_max_here_lines}q conftest.defines >>$CONFIG_STATUS - echo 'CEOF - sed -f $tmp/defines.sed $tmp/in >$tmp/out - rm -f $tmp/in - mv $tmp/out $tmp/in -' >>$CONFIG_STATUS - sed 1,${ac_max_here_lines}d conftest.defines >conftest.tail - rm -f conftest.defines - mv conftest.tail conftest.defines -done -rm -f conftest.defines -echo ' fi # grep' >>$CONFIG_STATUS -echo >>$CONFIG_STATUS - -# Break up conftest.undefs because some shells have a limit on the size -# of here documents, and old seds have small limits too (100 cmds). -echo ' # Handle all the #undef templates' >>$CONFIG_STATUS -rm -f conftest.tail -while grep . conftest.undefs >/dev/null -do - # Write a limited-size here document to $tmp/undefs.sed. - echo ' cat >$tmp/undefs.sed <>$CONFIG_STATUS - # Speed up: don't consider the non `#undef' - echo '/^[ ]*#[ ]*undef/!b' >>$CONFIG_STATUS - # Work around the forget-to-reset-the-flag bug. - echo 't clr' >>$CONFIG_STATUS - echo ': clr' >>$CONFIG_STATUS - sed ${ac_max_here_lines}q conftest.undefs >>$CONFIG_STATUS - echo 'CEOF - sed -f $tmp/undefs.sed $tmp/in >$tmp/out - rm -f $tmp/in - mv $tmp/out $tmp/in -' >>$CONFIG_STATUS - sed 1,${ac_max_here_lines}d conftest.undefs >conftest.tail - rm -f conftest.undefs - mv conftest.tail conftest.undefs -done -rm -f conftest.undefs - -cat >>$CONFIG_STATUS <<\_ACEOF - # Let's still pretend it is `configure' which instantiates (i.e., don't - # use $as_me), people would be surprised to read: - # /* config.h. Generated by config.status. */ - if test x"$ac_file" = x-; then - echo "/* Generated by configure. */" >$tmp/config.h - else - echo "/* $ac_file. Generated by configure. */" >$tmp/config.h - fi - cat $tmp/in >>$tmp/config.h - rm -f $tmp/in - if test x"$ac_file" != x-; then - if diff $ac_file $tmp/config.h >/dev/null 2>&1; then - { echo "$as_me:$LINENO: $ac_file is unchanged" >&5 -echo "$as_me: $ac_file is unchanged" >&6;} - else - ac_dir=`(dirname "$ac_file") 2>/dev/null || -$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ - X"$ac_file" : 'X\(//\)[^/]' \| \ - X"$ac_file" : 'X\(//\)$' \| \ - X"$ac_file" : 'X\(/\)' \| \ - . : '\(.\)' 2>/dev/null || -echo X"$ac_file" | - sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; } - /^X\(\/\/\)[^/].*/{ s//\1/; q; } - /^X\(\/\/\)$/{ s//\1/; q; } - /^X\(\/\).*/{ s//\1/; q; } - s/.*/./; q'` - { if $as_mkdir_p; then - mkdir -p "$ac_dir" - else - as_dir="$ac_dir" - as_dirs= - while test ! -d "$as_dir"; do - as_dirs="$as_dir $as_dirs" - as_dir=`(dirname "$as_dir") 2>/dev/null || -$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ - X"$as_dir" : 'X\(//\)[^/]' \| \ - X"$as_dir" : 'X\(//\)$' \| \ - X"$as_dir" : 'X\(/\)' \| \ - . : '\(.\)' 2>/dev/null || -echo X"$as_dir" | - sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; } - /^X\(\/\/\)[^/].*/{ s//\1/; q; } - /^X\(\/\/\)$/{ s//\1/; q; } - /^X\(\/\).*/{ s//\1/; q; } - s/.*/./; q'` - done - test ! -n "$as_dirs" || mkdir $as_dirs - fi || { { echo "$as_me:$LINENO: error: cannot create directory \"$ac_dir\"" >&5 -echo "$as_me: error: cannot create directory \"$ac_dir\"" >&2;} - { (exit 1); exit 1; }; }; } - - rm -f $ac_file - mv $tmp/config.h $ac_file - fi - else - cat $tmp/config.h - rm -f $tmp/config.h - fi -done -_ACEOF - -cat >>$CONFIG_STATUS <<\_ACEOF - -{ (exit 0); exit 0; } -_ACEOF -chmod +x $CONFIG_STATUS -ac_clean_files=$ac_clean_files_save - - -# configure is writing to config.log, and then calls config.status. -# config.status does its own redirection, appending to config.log. -# Unfortunately, on DOS this fails, as config.log is still kept open -# by configure, so config.status won't be able to write to it; its -# output is simply discarded. So we exec the FD to /dev/null, -# effectively closing config.log, so it can be properly (re)opened and -# appended to by config.status. When coming back to configure, we -# need to make the FD available again. -if test "$no_create" != yes; then - ac_cs_success=: - ac_config_status_args= - test "$silent" = yes && - ac_config_status_args="$ac_config_status_args --quiet" - exec 5>/dev/null - $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false - exec 5>>config.log - # Use ||, not &&, to avoid exiting from the if with $? = 1, which - # would make configure fail if this is the last instruction. - $ac_cs_success || { (exit 1); exit 1; } -fi - diff --git a/ase/configure.ac b/ase/configure.ac deleted file mode 100644 index 2ccb8dc4..00000000 --- a/ase/configure.ac +++ /dev/null @@ -1,110 +0,0 @@ -# -# $Id: configure.ac,v 1.1 2007/03/28 14:05:10 bacon Exp $ -# - -AC_PREREQ(2.53) -AC_INIT([ase], [deb-0.1.0]) -AC_REVISION([$Revision: 1.1 $]) -AC_CONFIG_HEADER([cmn/conf_unx.h]) - -# Checks for programs. -AC_PROG_CC -AC_PROG_RANLIB - -#AC_PROG_CXX - -# Overrides the default CFLAGS setting -if test "$ac_test_CFLAGS" = "set" -then - CFLAGS=$ac_save_CFLAGS -else - if test "$GCC" = "yes" - then - CFLAGS="-O2" - else - CFLAGS= - fi -fi - -# Checks for header files. -AC_HEADER_STDC - -# Checks for typedefs, structures, and compiler characteristics. -AC_C_BIGENDIAN( - [AC_DEFINE([ASE_ENDIAN_BIG],[],[Big Endian])], - [AC_DEFINE([ASE_ENDIAN_LITTLE],[],[Little Endian])], - [AC_DEFINE([ASE_ENDIAN_UNKNOWN],[],[Unknown Endian])]) - -# Checks for data types -AC_CHECK_TYPE(long long, [AC_DEFINE([ASE_HAVE_LONG_LONG],[],[long long])]) -AC_CHECK_TYPE(long double, [AC_DEFINE([ASE_HAVE_LONG_DOUBLE],[],[long double])]) - -AC_CHECK_SIZEOF(char) -AC_CHECK_SIZEOF(short) -AC_CHECK_SIZEOF(int) -AC_CHECK_SIZEOF(long) -AC_CHECK_SIZEOF(long long) -AC_CHECK_SIZEOF(__int8) -AC_CHECK_SIZEOF(__int16) -AC_CHECK_SIZEOF(__int32) -AC_CHECK_SIZEOF(__int64) -AC_CHECK_SIZEOF(__int96) -AC_CHECK_SIZEOF(__int128) -AC_CHECK_SIZEOF(void *) -AC_CHECK_SIZEOF(float) -AC_CHECK_SIZEOF(double) -AC_CHECK_SIZEOF(long double) -AC_CHECK_SIZEOF(wchar_t) - -AC_DEFINE_UNQUOTED(ASE_SIZEOF_CHAR,${ac_cv_sizeof_char}) -AC_DEFINE_UNQUOTED(ASE_SIZEOF_SHORT,${ac_cv_sizeof_short}) -AC_DEFINE_UNQUOTED(ASE_SIZEOF_INT,${ac_cv_sizeof_int}) -AC_DEFINE_UNQUOTED(ASE_SIZEOF_LONG,${ac_cv_sizeof_long}) -AC_DEFINE_UNQUOTED(ASE_SIZEOF_LONG_LONG,${ac_cv_sizeof_long_long}) -AC_DEFINE_UNQUOTED(ASE_SIZEOF___INT8,${ac_cv_sizeof___int8}) -AC_DEFINE_UNQUOTED(ASE_SIZEOF___INT16,${ac_cv_sizeof___int16}) -AC_DEFINE_UNQUOTED(ASE_SIZEOF___INT32,${ac_cv_sizeof___int32}) -AC_DEFINE_UNQUOTED(ASE_SIZEOF___INT64,${ac_cv_sizeof___int64}) -AC_DEFINE_UNQUOTED(ASE_SIZEOF___INT96,${ac_cv_sizeof___int96}) -AC_DEFINE_UNQUOTED(ASE_SIZEOF___INT128,${ac_cv_sizeof___int128}) -AC_DEFINE_UNQUOTED(ASE_SIZEOF_VOID_P,${ac_cv_sizeof_void_p}) -AC_DEFINE_UNQUOTED(ASE_SIZEOF_FLOAT,${ac_cv_sizeof_float}) -AC_DEFINE_UNQUOTED(ASE_SIZEOF_DOUBLE,${ac_cv_sizeof_double}) -AC_DEFINE_UNQUOTED(ASE_SIZEOF_LONG_DOUBLE,${ac_cv_sizeof_long_double}) -AC_DEFINE_UNQUOTED(ASE_SIZEOF_WCHAR_T,${ac_cv_sizeof_wchar_t}) - -# Defines extra options - -AC_ARG_ENABLE([wchar], [AC_HELP_STRING([--enable-wchar], - [use wchar_t a default charater type when enabled (default. yes)])], - enable_wchar_is=$enableval,enable_wchar_is=yes) -if test "$enable_wchar_is" = "yes" -then - AC_DEFINE([ASE_CHAR_IS_WCHAR],[],[char is wchar]) -else - AC_DEFINE([ASE_CHAR_IS_MCHAR],[],[char is mchar]) -fi - -AC_ARG_ENABLE([mode], [AC_HELP_STRING([--enable-debug], - [build the library in the debug mode (default. no)])], - enable_debug_is=$enableval,enable_debug_is=no) -if test "$enable_debug_is" = "yes" -then - [CFLAGS="$CFLAGS -g -D_DEBUG -UNDEBUG"] - AC_SUBST(BUILDMODE, "debug") -else - [CFLAGS="$CFLAGS -DNDEBUG -U_DEBUG"] - AC_SUBST(BUILDMODE, "release") -fi - -# Configure makefiles -AC_ARG_ENABLE([reentrant], [AC_HELP_STRING([--enable-reentrant], - [define _REENTRANT (default. yes)])], - enable_reentrant_is=$enableval,enable_reentrant_is=yes) -if test "$enable_reentrant_is" = "yes" -then - [CFLAGS="$CFLAGS -D_REENTRANT -D_THREAD_SAFE"] -fi - -AC_CONFIG_FILES([makefile cmn/makefile awk/makefile lsp/makefile utl/makefile test/awk/makefile test/lsp/makefile]) -AC_OUTPUT diff --git a/ase/doc/ase-en.man b/ase/doc/ase-en.man deleted file mode 100644 index 2779be1b..00000000 --- a/ase/doc/ase-en.man +++ /dev/null @@ -1,30 +0,0 @@ -.title ASE - -= ASE = - -ASE is a programming library implementing various programming languages and text utilities for embedding purposes. The library is developed in the C programming language and provides the JNI binding to JAVA and the COM interface. - -(Warning: This page is only for the test purpose prior to proper release and the contents can be changed anytime without prior notice.) - -== Download == - -Download the library source code from the following links. - -ase-0.1.0.tgz -[[[ -* {Link 1,ase-0.1.0.tgz} -* Link 2 -]]] - -== Documentation == - -[[[ -* {Quickstart,quickstart-en.html} -* {AWK Embedder's guide,awk-en.html} -* {LISP Embedder's guide,lsp-en.html} -* {Frequently Asked Questions,faq-en.html} -]]] - -== Licensing == - -ASE is distributed under a {BSD license,license.html} and is free for all uses. diff --git a/ase/doc/ase-ko.man b/ase/doc/ase-ko.man deleted file mode 100644 index 4ee3e885..00000000 --- a/ase/doc/ase-ko.man +++ /dev/null @@ -1,29 +0,0 @@ -.title ASE - -= ASE = - -ASE는 임베딩을 목적으로 여러가지 프로그래밍언어를 구현하는 라이브러리이다. C언어로 개발되며 자바 JNI인터페이스와 COM인터페이스를 제공한다. - -(경고: 본 페이지는 정식 배포전에 시험용으로 제작된것이므로, 언제든지 내용이 변경될 수 있다.) - -== Download == - -다음 링크에서 소스코드를 받을수 있다. - -ase-0.1.0.tgz -[[[ -* {링크 1,ase-0.1.0.tgz} -* 링크 2 -]]] - -== Documentation == - -[[[ -* {초간단가이드,quickstart-ko.html} -* {사용자가이드,awk-en.html} -* {자주받는질문,faq-ko.html} -]]] - -== Licensing == - -ASE는 {BSD 라이센스,license.html}하에 무료로 배포된다. 단 {라이센스,license.html}는 번역상에 발생할수 있는 문제를 최소화하기 위해 영문으로만 제공된다. diff --git a/ase/doc/awk-en.man b/ase/doc/awk-en.man deleted file mode 100644 index e0584aab..00000000 --- a/ase/doc/awk-en.man +++ /dev/null @@ -1,202 +0,0 @@ -.title ASEAWK - -= ASEAWK = -ASE provides an embeddable processor of a dialect of the AWK programming language. The language implemented is slightly different from {the version developed by Brian W. Kernighan, http://cm.bell-labs.com/cm/cs/awkbook/index.html} and has been adjusted to the author's preference. - -== Overview == -The following code fragment illustrates the basic steps of embedding the processor. - -{{{ -1) #include - -2) ase_awk_t* awk; -3) awk = ase_awk_open (...); -4) if (ase_awk_parse (awk, ...) == -1) - { - /* parse error */ - } - else - { -5) if (ase_awk_run (awk, ...) == -1) - { - /* run-time error */ - } - } -6) ase_awk_close (awk); -}}} - -((( -* Most of the functions and data types needed are defined in the header file [[ase/awk/awk.h]]. -* [[ase_awk_t]] represents the processor. However, the internal representation is not exposed. -* [[ase_awk_open]] creates the processor instance. -* [[ase_awk_parse]] parses an AWK script. -* [[ase_awk_run]] executes the script parsed. -* [[ase_awk_close]] destroys the processor instance. -))) - -More detailed description is available {here,awk-mini-en.html}. You may refer to other sample files such as [[ase/test/awk/awk.c]] and [[ase/awk/jni.c]]. - -== Primitive Functions == -A set of primitive functions is needed to create an instance of the AWK processor. A primitive function is a user-defined function to help the library perform system-dependent operations such as memory allocation, character class handling. - -{{{ -typedef struct ase_awk_prmfns_t ase_awk_prmfns_t; - -struct ase_awk_prmfns_t -{ - ase_mmgr_t mmgr; - ase_ccls_t ccls; - - struct - { - ase_awk_pow_t pow; - ase_awk_sprintf_t sprintf; - ase_awk_dprintf_t dprintf; - void* custom_data; - } misc; -}; -}}} - -A caller of [[ase_awk_open]] should fill in most of the fields of a [[ase_awk_prmfns_t]] structure and pass the structure to it. The function pointers in the miscellaneous group labeled [misc] is defined as follows: - -{{{ -/* returns the value of x raised to the power of y */ -typedef ase_real_t (*ase_awk_pow_t) (void* custom, ase_real_t x, ase_real_t y); - -/* similar to snprintf of the standard C library. */ -typedef int (*ase_awk_sprintf_t) (void* custom, ase_char_t* buf, ase_size_t size, const ase_char_t* fmt, ...); - -/* similar to printf of the standard C library. called by a few uncommonly - * used output functions usually for debugging purpose */ -typedef void (*ase_awk_dprintf_t) (void* custom, const ase_char_t* fmt, ...); -}}} - -The fourth field of the group is passed to its member functions as the first argument on invocation. The function pointed by the [[sprintf]] field should ensure that the resuliting string is null-terminated and [[%s]] and [[%c]] are accepted for the [[ase_char_t*]] and [[ase_char_t]] type respectively regardless the character mode. - -The memory manager group labeled [mmgr] and the character class group labled [ccls] are defined as follows: - -{{{ -typedef void* (*ase_malloc_t) (void* custom, ase_size_t n); -typedef void* (*ase_realloc_t) (void* custom, void* ptr, ase_size_t n); -typedef void (*ase_free_t) (void* custom, void* ptr); - -typedef ase_bool_t (*ase_isccls_t) (void* custom, ase_cint_t c); -typedef ase_cint_t (*ase_toccls_t) (void* custom, ase_cint_t c); - -struct ase_mmgr_t -{ - ase_malloc_t malloc; - ase_realloc_t realloc; - ase_free_t free; - void* custom_data; -}; - -struct ase_ccls_t -{ - ase_isccls_t is_upper; - ase_isccls_t is_lower; - ase_isccls_t is_alpha; - ase_isccls_t is_digit; - ase_isccls_t is_xdigit; - ase_isccls_t is_alnum; - ase_isccls_t is_space; - ase_isccls_t is_print; - ase_isccls_t is_graph; - ase_isccls_t is_cntrl; - ase_isccls_t is_punct; - ase_toccls_t to_upper; - ase_toccls_t to_lower; - void* custom_data; -}; -}}} - -The functions in these groups perform the memory operations and character class related operations respectively. They follow the style of the memory allocation functions and character class handling functions of the standard C library except that they accept a pointer to the user-defined data as the first argument, thus providing more flexibility. The pointer to the user-defined data is specified into the [[custom_data]] field of each group. The [[realloc]] field, however, can be [[ASE_NULL]], in which case the functions pointed by the free and the malloc field replace the role of the function pointed by the [[realloc]] field. - -== Source IO Handler == - -The source code is handled by a source input handler provided by the user. The optional source code output handler can be provided to have the internal parse tree converted back to the source code. - -The source code handler is defined as follows: - -{{{ -typedef ase_ssize_t (*ase_awk_io_t) (int cmd, void* custom, ase_char_t* data, ase_size_t count); - -typedef struct ase_awk_srcios_t ase_awk_srcios_t; - -struct ase_awk_srcios_t -{ - ase_awk_io_t in; /* source input */ - ase_awk_io_t out; /* source output */ - void* custom_data; -}; -}}} - -The [[in]] field of the ase_awk_srcios_t is mandatory and should be filled in. The [[out]] field can be set to [[ASE_NULL]] or can point to a source output handling function. The [[custom_data]] field is passed to the source handlers as the second argument. The first parameter [[cmd]] of the source input handler is one of [[ASE_AWK_IO_OPEN]], [[ASE_AWK_IO_CLOSE]], [[ASE_AWK_IO_READ]]. The first parameter [[cmd]] of the source output handler is one of [[ASE_AWK_IO_OPEN]], [[ASE_AWK_IO_CLOSE]], [[ASE_AWK_IO_WRITE]]. The third parameter [[data]] and the fourth parameter [[count]] are the pointer to the buffer to read data into and its size if the first parameter [[cmd]] is [[ASE_AWK_IO_READ]] while they are the pointer to the data and its size if [[cmd]] is [[ASE_AWK_IO_WRITE]]. - -The source handler should return a negative value for an error and zero or a positive value otherwise. However, there is a subtle difference in the meaning of the return value depending on the value of the first parameter [[cmd]]. - -When [[cmd]] is [[ASE_AWK_IO_OPEN]], the return value of -1 and 1 indicates the failure and the success respectively. In addition, the return value of 0 indicates that the operation is successful but has reached the end of the stream. The library calls the handler with [[ASE_AWK_IO_CLOSE]] for deinitialization if the return value is 0 or 1. When [[cmd]] is [[ASE_AWK_IO_CLOSE]], the return value of -1 and 0 indicate the failure and the success respectively. When [[cmd]] is [[ASE_AWK_IO_READ]] or [[ASE_AWK_IO_WRITE]], the return value of -1 indicates the failure, 0 the end of the stream, and other positive values the number of characters read or written. - -The typical source handler will look as follows: -{{{ -ase_ssize_t awk_srcio_in (int cmd, void* arg, ase_char_t* data, ase_size_t size) -{ - if (cmd == ASE_AWK_IO_OPEN) - { - /* open the stream */ - return 1; - } - else if (cmd == ASE_AWK_IO_CLOSE) - { - /* close the stream */ - return 0; - } - else if (cmd == ASE_AWK_IO_READ) - { - /* read the stream */ - return the number of characters read; - } - - return -1; -} - -ase_ssize_t awk_srcio_out (int cmd, void* arg, ase_char_t* data, ase_size_t size) -{ - if (cmd == ASE_AWK_IO_OPEN) - { - /* open the stream */ - return 1; - } - else if (cmd == ASE_AWK_IO_CLOSE) - { - /* close the stream after flushing it */ - return 0; - } - else if (cmd == ASE_AWK_IO_WRITE) - { - /* write the stream */ - return the number of characters written; - } - - return -1; -} -}}} - -Once you have the source handler ready, you can fill in the fields of a [[ase_awk_srcios_t]] structure and pass it to the call of [[ase_awk_parse]]. - -{{{ -ase_awk_srcios_t srcios; - -srcios.in = awk_srcio_in; -srcios.out = awk_srcio_out; -srcios.custom_data = point to the extra information necessary; - -if (ase_awk_parse (awk, &srcios) == -1) -{ - /* handle error */ -} -}}} - -== External IO Handler == - -External IO handlers should be provided to support the AWK's built-in IO facilities. diff --git a/ase/doc/awk-mini-en.man b/ase/doc/awk-mini-en.man deleted file mode 100644 index 2ccb86b6..00000000 --- a/ase/doc/awk-mini-en.man +++ /dev/null @@ -1,458 +0,0 @@ -.title Annotated ASEAWK Embedding Sample - -= Annotated ASEAWK Embedding Sample = - -This document annotates a simple embedding sample code [[ase/test/awk/mini.c]]. Locate the [[ase_main]] function to begin exploring the sample. - -== mini.c == - -{{{ -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -}}} - -Most of the data types and functions needed to embed a AWK processor is defined in [[ase/awk/awk.h]]. Other headers files are included as this sample code uses functions from them. - -{{{ -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 -#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 -}}} - -The library requires [[ase_assert_abort]] and [[ase_assert_printf]] to be defined to support the assertion statements [[ASE_ASSERT]] and [[ASE_ASSERTX]] defined in [[ase/cmn/macros.h]] when [[NDEBUG]] is not defined. [[ASE_ASSERT]] behaves the same as the standard [[assert]] statement while an additional textual description can be passed to [[ASE_ASSERTX]]. They are all usuable in the caller program as well. - -{{{ -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); } -}}} - -The memory management functions are required by the library. They need to form a part of the [[ase_awk_prmfns_t]] structure and be passed to [[ase_awk_open]]. Each function looks after the counterpart in the standard C library except that the first parameter to each function is a pointer to a custom data provided by the caller. - -{{{ -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); } -}}} - -The character class handling functions must be provided by the caller. Like the memory management functions, they form a part of the [[ase_awk_prmfns_t]] structure and passwd to [[ase_awk_open]]. - -{{{ -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); -} -}}} - -The [[awk_pow]] function returns the value of the second parameter [[x]] raised to the third parameter [[y]]. The [[awk_sprintf]] function is similar to the standard [[snprintf]] to the standard [[snprintf]]. It should make sure that the buffer [[buf]] is null-terminated if the size [[size]] is greater than 0. Refer to [[ase_sprintf]] in [[ase/utl/stdio.h]] for details. The [[awk_dprintf]] fucntion is similar to [[fprintf(stderr,...)]] is called when the text output is performed for debugging purpose. - -{{{ -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; -} -}}} - -The source code is read in by the source code input handler as specified in the [[in]] field of the [[ase_awk_srcios_t]] structure passed to the [[ase_awk_parse]] function. This sample, however, doesn't use the source output handler which is used to show the internal parse tree. - -{{{ -/* 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; -} -}}} - -External Input-Output Handler. - -{{{ -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_STRBASEONE | - 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; -} -}}} - -The main function. diff --git a/ase/doc/awk.man b/ase/doc/awk.man deleted file mode 100644 index f192fdfc..00000000 --- a/ase/doc/awk.man +++ /dev/null @@ -1,93 +0,0 @@ -.title Introduction To ASE AWK - -== OVERVIEW == - -=== What is it? === -'''''ASE AWK''''' is an embeddable implementation of the AWK programming language. It is composed of a set of C functions to help programmers embed the AWK interpreter to their own applications easily. - -=== What does it do? === -'''''ASE AWK''''' can do most of the things that other existing AWK interpreters can do. - -=== Differences with other implementations === -There exist a number of AWK interpreters available. Most of Unix/Linux operating systems come with an AWK interpreter. - -== DESCRIPTION == - -=== Interpreter === -Multiple instances of interpreters can be created in a single application and each instance of the interpreter created maintains its own state in the data structure pointed at by its handle of the type ''ase_awk_t''. - - * ase_awk_t - an abstract type to an interpreter object. - * ase_awk_open - creates an interpreter object. - * ase_awk_close - destroys the interprer object created by ase_awk_open. - -{{{ -ase_awk_t* ase_awk_open (void); -void ase_awk_close (ase_awk_t* awk); -}}} - -The interpreter provides two distinct functionalites in large; the parser and the executor. The parser transforms the source code into the internal parse tree and the executor evaluates the parse tree and runs the code. - -{{{ -int ase_awk_parse (ase_awk_t* awk); -int ase_awk_run (ase_awk_t* awk, ase_awk_io_t txtio, void* txtio_arg); -}}} - -=== IO Handlers === -'''''ASE AWK''''' does not provide any built-in IO handling routines. Instead, it requires users to provide them. 4 different IO streams should be provided to take full advantage of the interpreter. - - * Source code input - * Source code output - * Data input - * Data output - -{{{ -enum -{ - XP_AWK_INPUT_OPEN = 0, - XP_AWK_INPUT_CLOSE = 1, - XP_AWK_INPUT_NEXT = 2, - XP_AWK_INPUT_DATA = 3, - - XP_AWK_OUTPUT_OPEN = 4, - XP_AWK_OUTPUT_CLOSE = 5, - XP_AWK_OUTPUT_NEXT = 6, - XP_AWK_OUTPUT_DATA = 7 -}; - -typedef ase_ssize_t (*ase_awk_io_t) (int cmd, void* arg, ase_char_t* data, ase_size_t count); -}}} - -=== Miscellaneous Functions === -'''''ASE AWK''''' provides extra utility routines as well as the interpreter. These routines used by the interpreter can be accessed from the interested applications directly without regard to the interpreter. - -==== String ==== - -==== Conversion ==== - * ase_awk_strtolong - convert a numeric string to an integer of the ase_long_t type. - * ase_awk_strtoreal - convert a numeric string to a decimal number of the ase_real_t type. - -{{{ -ase_long_t ase_awk_strtolong (const ase_char_t* str, int base, const ase_char_t** endptr); -ase_real_t ase_awk_strtoreal (const ase_char_t* str); -}}} - -==== Regular Expression ==== -The regular expression routines built into the interpreter can replace other regular expression libraries available. By utilizing this, the application can have the identical regular expression functionalities as the embedded AWK interpreter. - -{{{ -ase_awk_rex_t* ase_awk_rex_open (ase_awk_rex_t* rex); -void ase_awk_rex_close (ase_awk_rex_t* rex); -}}} - -=== User-defined Built-in Functions === -Custom built-in functions can be added to the interpreter. This requires the deeper look into the internals of the interpreter. - -== EXAMPLE == -{{{ -#include - -int ase_main () -{ - return 0; -} -}}} diff --git a/ase/doc/diff.man b/ase/doc/diff.man deleted file mode 100644 index 0a8337f5..00000000 --- a/ase/doc/diff.man +++ /dev/null @@ -1,11 +0,0 @@ -== Difference From The Standard AWK == - -== line terminiator == -it doesn't accept the new line as a line terminator. - -== print/printf == -if the statement succeeds, it sets ERRNO to 0. otherwise, it sets ERRNO to -1. - - - - diff --git a/ase/doc/doc.css b/ase/doc/doc.css deleted file mode 100644 index fe7f3705..00000000 --- a/ase/doc/doc.css +++ /dev/null @@ -1,86 +0,0 @@ -body -{ - font-family: verdana, "times new roman", tahoma, lucida, sans-serif; - background-color: white; - color: black; - #padding: 10px 10px 10px 10px; - - font-size: 90%; - padding-left: 10px; - padding-right: 10px; - line-height: 1.3; - text-align: justify; -} - -#a:link { color: #F89E59;} -#a:visited { color: #F89E59;} -#a:hover { color:#000000;} - -h1,h2,h3,h4,h5 -{ - font-family: tahoma, "times new roman", verdana; - border-bottom: 1px solid #779098; -} -h1 { font-size: 120%; } -h2 { font-size: 115%; padding-left: 5px; } -h3 { font-size: 110%; padding-left: 10px; } -h4 { font-size: 105%; padding-left: 15px; } -h5 { font-size: 100%; padding-left: 20px; } - -.header -{ - font-family: verdana, tahoma; - font-size: 120%; - font-weight: bold; - #padding-right: 20px; - text-decoration: none; - border-bottom: 1px solid black; -} - -.footer -{ - font-family: "times new roman", tahoma; - font-size: 14px; - #padding-right: 20px; - text-decoration: none; - text-align: right; - border-top: 1px solid black; -} - -.contents -{ - font-family: "times new roman", tahoma; - font-size: 95%; -} - -.maintext -{ - font-size: 90%; - #color: #555555; - color: black; - padding-left: 20px; - padding-right: 20px; - line-height: 1.3; - text-align: justify; -} - -pre.code -{ - font-family: "Lucida TypeWriter", monotype, lucida, fixed; - font-size: 80%; - padding: 6px 6px 6px 6px; - xbackground-color: #000000; - xcolor: #FFD700; - #border: 1px dashed #779098; - #border: 1px solid #779098; - border: none; - background-color: yellow; -} - -.linenum -{ - font-weight: bold; -} - - - diff --git a/ase/doc/embed.man b/ase/doc/embed.man deleted file mode 100644 index 3202c9cc..00000000 --- a/ase/doc/embed.man +++ /dev/null @@ -1,51 +0,0 @@ -.title Embedding AWK - -To embed the awk interpreter to an application, the developer should provide the following routines. - - * System functions including memory management - * Source code I/O functions - * I/O functions to interface with the console, files, and pipes. - -ase_awk_open creates an awk object and requires a pointer to a structure holding system functions. The structure is described in ase_awk_prmfns_t. - -{{{ -struct ase_awk_prmfns_t -{ - /* memory */ - void* (*malloc) (ase_size_t n, void* custom_data); - void* (*realloc) (void* ptr, ase_size_t n, void* custom_data); - void (*free) (void* ptr, void* custom_data); - - /* thread lock */ - ase_awk_lk_t lock; - ase_awk_lk_t unlock; - - /* character class */ - ase_bool_t (*is_upper) (ase_cint_t c); - ase_bool_t (*is_lower) (ase_cint_t c); - ase_bool_t (*is_alpha) (ase_cint_t c); - ase_bool_t (*is_digit) (ase_cint_t c); - ase_bool_t (*is_xdigit) (ase_cint_t c); - ase_bool_t (*is_alnum) (ase_cint_t c); - ase_bool_t (*is_space) (ase_cint_t c); - ase_bool_t (*is_print) (ase_cint_t c); - ase_bool_t (*is_graph) (ase_cint_t c); - ase_bool_t (*is_cntrl) (ase_cint_t c); - ase_bool_t (*is_punct) (ase_cint_t c); - ase_cint_t (*to_upper) (ase_cint_t c); - ase_cint_t (*to_lower) (ase_cint_t c); - - /* utilities */ - void* (*memcpy) (void* dst, const void* src, ase_size_t n); - void* (*memset) (void* dst, int val, ase_size_t n); - ase_real_t (*pow) (ase_real_t x, ase_real_t y); - - int (*sprintf) (ase_char_t* buf, ase_size_t size, const ase_char_t* fmt, ...); - void (*aprintf) (const ase_char_t* fmt, ...); /* assertion */ - void (*dprintf) (const ase_char_t* fmt, ...); /* debug */ - void (*abort) (void); - - void* custom_data; -}; -}}} - diff --git a/ase/doc/license.man b/ase/doc/license.man deleted file mode 100644 index 2b2ed8e1..00000000 --- a/ase/doc/license.man +++ /dev/null @@ -1,19 +0,0 @@ -.title ASE License Agreement - -Software License Agreement (BSD License) - -Copyright (c) 2006-2007, Hyung-Hwan Chung -All rights reserved. - -Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - -[[[ -* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - -* Neither the name of the copyright owner nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. -]]] - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT OWNER AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - diff --git a/ase/doc/lsp-en.man b/ase/doc/lsp-en.man deleted file mode 100644 index f36a3cc2..00000000 --- a/ase/doc/lsp-en.man +++ /dev/null @@ -1,22 +0,0 @@ - -= ASELSP = - -ASELSP is an implementation of a lisp-like language for embedding purposes. - -== Types == - -[[[ -* ase_lsp_t -* ase_lsp_io_t -* ase_lsp_obj_t -]]] - -== Functions == - -[[[ -* ase_lsp_open -* ase_lsp_close -* ase_lsp_read -* ase_lsp_eval -* ase_lsp_print -]]] diff --git a/ase/doc/quickstart-en.man b/ase/doc/quickstart-en.man deleted file mode 100644 index c74b4abb..00000000 --- a/ase/doc/quickstart-en.man +++ /dev/null @@ -1,82 +0,0 @@ -.title ASE Quick Start Guide - -= ASE Quick Start Guide = - -The first step in using this library is to build it as the pre-compiled binary is not available at this moment. This document shows how to build the core library on various operating systems. - -== Unix/Linux == - -You may run the [[configure]] script on most of the Unix-like operation systems to set up the build environment and then run the [[make]] utility at the top-level directory. - -{{{ -$ ./configure -$ make -}}} - -The [[make]] utility visits each core module directory and build the library there. The [[test]] directory and its subdirectories are not built by default. - -If you have preference for a particular compiler and the flags, you may explicitly specify them when you run the [[configure]] script. Here are presented a few such examples. - -{{{ -# HP-UX B.11.23 with HP ANSI C -CC=cc CFLAGS="-O2 +DD64" LDFLAGS="+DD64" ./configure # 64-bit -CC=cc CFLAGS="-O2 +DD32" LDFLAGS="+DD32" ./configure # 32-bit - -# SCO OpenServer Release 5.0.7 (SCO_SV 3.2 5.0.7) with SCO OpenServer Development System -CC=cc CFLAGS="-Xc -a ansi -O2" ./configure - -# Solaris 10 with GCC -CC=gcc CFLAGS="-Wall -O2 -m64" LDFLAGS="-m64" ./configure # 64-bit -CC=gcc CFLAGS="-Wall -O2" ./configure # 32-bit -}}} - -== OpenVMS == - -You may use the [[mms]] command or the [[mmk]] command to build the library. No counterpart for the [[configure]] script is provided. As not top-level build script is provided, you have to run the command in each directory that you want to build the library in. - -Let's build the AWK library and its test program, for instance. - -{{{ -set default [.ase.cmn] -mms -set default [-.awk] -mms -set default [-.utl] -mms -set default [-.test.awk] -mms -}}} - -For those who are not familar with OpenVMS, here is one of the ways how to run the test program. - -{{{ -; define the foreign command. -aseawk :== $DISK$GEIN_SYS:[USERS.BACON.ASE.TEST.AWK]aseawk.exe -; run the command. -aseawk -f hello.awk -}}} - -== MS-Windows == - -You may use the Visual Studio 6 or later to use the provided project file. Otherwise open the command-line build environment and use the [[make]] utility. - -A set of make scripts is provided to support the Microsoft build environement and the Borland build environment. The script for the Miscrosoft build environment is named [[makefile.msw.cl]] while it is [[makefile.msw.bcc]] for the Borland counterpart. - -If you are building the AWK library and the test program, this is probably what you have to do. - -{{{ -cd ase\cmn -nmake /f makefile.msw.cl -cd ..\awk -nmake /f makefile.msw.cl -cd ..\utl -nmake /f makefile.msw.cl -cd ..\test\awk -nmake /f makefile.msw.cl -}}} - -However, The COM module can only be built within the Visual Studio environment. After having built the COM module, you may open [[ase/test/com/ase.vbp]] for testing. - -== JNI Interface == - -Some make scripts contain the target to build the JNI interface for Java. The Java class files can be built with the standard [[javac]] command. diff --git a/ase/lsp/aselsp.dsp b/ase/lsp/aselsp.dsp deleted file mode 100644 index 032c3d77..00000000 --- a/ase/lsp/aselsp.dsp +++ /dev/null @@ -1,180 +0,0 @@ -# Microsoft Developer Studio Project File - Name="aselsp" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Static Library" 0x0104 - -CFG=aselsp - Win32 Debug -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "aselsp.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "aselsp.mak" CFG="aselsp - Win32 Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "aselsp - Win32 Release" (based on "Win32 (x86) Static Library") -!MESSAGE "aselsp - Win32 Debug" (based on "Win32 (x86) Static Library") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -RSC=rc.exe - -!IF "$(CFG)" == "aselsp - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "../release/lib" -# PROP Intermediate_Dir "release" -# PROP Target_Dir "" -MTL=midl.exe -# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c -# ADD CPP /nologo /MT /W3 /GX /O2 /I "../.." /D "NDEBUG" /D "WIN32" /D "_UNICODE" /YX /FD /c -# ADD BASE RSC /l 0x409 /d "NDEBUG" -# ADD RSC /l 0x409 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LIB32=link.exe -lib -# ADD BASE LIB32 /nologo - -!ELSEIF "$(CFG)" == "aselsp - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "../debug/lib" -# PROP Intermediate_Dir "debug" -# PROP Target_Dir "" -MTL=midl.exe -# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c -# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../.." /D "_DEBUG" /D "WIN32" /D "_UNICODE" /YX /FD /GZ /c -# ADD BASE RSC /l 0x409 /d "_DEBUG" -# ADD RSC /l 0x409 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LIB32=link.exe -lib -# ADD BASE LIB32 /nologo - -!ENDIF - -# Begin Target - -# Name "aselsp - Win32 Release" -# Name "aselsp - Win32 Debug" -# Begin Group "Source Files" - -# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" -# Begin Source File - -SOURCE=.\env.c -# End Source File -# Begin Source File - -SOURCE=.\err.c -# End Source File -# Begin Source File - -SOURCE=.\eval.c -# End Source File -# Begin Source File - -SOURCE=.\lsp.c -# End Source File -# Begin Source File - -SOURCE=.\mem.c -# End Source File -# Begin Source File - -SOURCE=.\misc.c -# End Source File -# Begin Source File - -SOURCE=.\name.c -# End Source File -# Begin Source File - -SOURCE=.\prim.c -# End Source File -# Begin Source File - -SOURCE=.\prim_compar.c -# End Source File -# Begin Source File - -SOURCE=.\prim_let.c -# End Source File -# Begin Source File - -SOURCE=.\prim_math.c -# End Source File -# Begin Source File - -SOURCE=.\prim_prog.c -# End Source File -# Begin Source File - -SOURCE=.\print.c -# End Source File -# Begin Source File - -SOURCE=.\read.c -# End Source File -# End Group -# Begin Group "Header Files" - -# PROP Default_Filter "h;hpp;hxx;hm;inl" -# Begin Source File - -SOURCE=.\env.h -# End Source File -# Begin Source File - -SOURCE=.\lsp.h -# End Source File -# Begin Source File - -SOURCE=.\lsp_i.h -# End Source File -# Begin Source File - -SOURCE=.\mem.h -# End Source File -# Begin Source File - -SOURCE=.\misc.h -# End Source File -# Begin Source File - -SOURCE=.\name.h -# End Source File -# Begin Source File - -SOURCE=.\obj.h -# End Source File -# Begin Source File - -SOURCE=.\prim.h -# End Source File -# End Group -# End Target -# End Project diff --git a/ase/lsp/descrip.mms b/ase/lsp/descrip.mms deleted file mode 100644 index 95564785..00000000 --- a/ase/lsp/descrip.mms +++ /dev/null @@ -1,28 +0,0 @@ -# -# OpenVMS MMS/MMK -# - -objects = lsp.obj name.obj mem.obj env.obj err.obj read.obj eval.obj print.obj misc.obj prim.obj prim_prog.obj prim_let.obj prim_compar.obj prim_math.obj - -CFLAGS = /include="../.." -#CFLAGS = /pointer_size=long /include="../.." - -aselsp.olb : $(objects) - $(LIBR)/create $(MMS$TARGET) *.obj -# $(LIBR)/create $(MMS$TARGET) $(objects) - -lsp.obj depends_on lsp.c -name.obj depends_on name.c -mem.obj depends_on mem.c -env.obj depends_on env.c -err.obj depends_on err.c -read.obj depends_on read.c -eval.obj depends_on eval.c -print.obj depends_on print.c -misc.obj depends_on misc.c -prim.obj depends_on prim.c -prim_prog.obj depends_on prim_prog.c -prim_let.obj depends_on prim_let.c -prim_compar.obj depends_on prim_compar.c -prim_math.obj depends_on prim_math.c - diff --git a/ase/lsp/env.c b/ase/lsp/env.c deleted file mode 100644 index d55a6938..00000000 --- a/ase/lsp/env.c +++ /dev/null @@ -1,146 +0,0 @@ -/* - * $Id: env.c,v 1.1.1.1 2007/03/28 14:05:24 bacon Exp $ - * - * {License} - */ - -#include - -/* TODO: make the frame hash accessible */ - -static ase_lsp_assoc_t* __new_assoc ( - ase_lsp_t* lsp, ase_lsp_obj_t* name, - ase_lsp_obj_t* value, ase_lsp_obj_t* func) -{ - ase_lsp_assoc_t* assoc; - - assoc = (ase_lsp_assoc_t*) - ASE_LSP_MALLOC (lsp, sizeof(ase_lsp_assoc_t)); - if (assoc == ASE_NULL) - { - ase_lsp_seterror (lsp, ASE_LSP_ENOMEM, ASE_NULL, 0); - return ASE_NULL; - } - - assoc->name = name; - assoc->value = value; - assoc->func = func; - assoc->link = ASE_NULL; - - return assoc; -} - -ase_lsp_frame_t* ase_lsp_newframe (ase_lsp_t* lsp) -{ - ase_lsp_frame_t* frame; - - frame = (ase_lsp_frame_t*) - ASE_LSP_MALLOC (lsp, sizeof(ase_lsp_frame_t)); - if (frame == ASE_NULL) - { - ase_lsp_seterror (lsp, ASE_LSP_ENOMEM, ASE_NULL, 0); - return ASE_NULL; - } - - frame->assoc = ASE_NULL; - frame->link = ASE_NULL; - - return frame; -} - -void ase_lsp_freeframe (ase_lsp_t* lsp, ase_lsp_frame_t* frame) -{ - ase_lsp_assoc_t* assoc, * link; - - /* destroy the associations */ - assoc = frame->assoc; - while (assoc != ASE_NULL) - { - link = assoc->link; - ASE_LSP_FREE (lsp, assoc); - assoc = link; - } - - ASE_LSP_FREE (lsp, frame); -} - -ase_lsp_assoc_t* ase_lsp_lookupinframe ( - ase_lsp_t* lsp, ase_lsp_frame_t* frame, ase_lsp_obj_t* name) -{ - ase_lsp_assoc_t* assoc; - - ASE_ASSERT (ASE_LSP_TYPE(name) == ASE_LSP_OBJ_SYM); - - assoc = frame->assoc; - while (assoc != ASE_NULL) - { - if (name == assoc->name) return assoc; - assoc = assoc->link; - } - return ASE_NULL; -} - -ase_lsp_assoc_t* ase_lsp_insvalueintoframe ( - ase_lsp_t* lsp, ase_lsp_frame_t* frame, - ase_lsp_obj_t* name, ase_lsp_obj_t* value) -{ - ase_lsp_assoc_t* assoc; - - ASE_ASSERT (ASE_LSP_TYPE(name) == ASE_LSP_OBJ_SYM); - - assoc = __new_assoc (lsp, name, value, ASE_NULL); - if (assoc == ASE_NULL) return ASE_NULL; - - assoc->link = frame->assoc; - frame->assoc = assoc; - return assoc; -} - -ase_lsp_assoc_t* ase_lsp_insfuncintoframe ( - ase_lsp_t* lsp, ase_lsp_frame_t* frame, - ase_lsp_obj_t* name, ase_lsp_obj_t* func) -{ - ase_lsp_assoc_t* assoc; - - ASE_ASSERT (ASE_LSP_TYPE(name) == ASE_LSP_OBJ_SYM); - - assoc = __new_assoc (lsp, name, ASE_NULL, func); - if (assoc == ASE_NULL) return ASE_NULL; - - assoc->link = frame->assoc; - frame->assoc = assoc; - return assoc; -} - -ase_lsp_tlink_t* ase_lsp_pushtmp (ase_lsp_t* lsp, ase_lsp_obj_t* obj) -{ - ase_lsp_tlink_t* tlink; - - tlink = (ase_lsp_tlink_t*) - ASE_LSP_MALLOC (lsp, sizeof(ase_lsp_tlink_t)); - if (tlink == ASE_NULL) - { - ase_lsp_seterror (lsp, ASE_LSP_ENOMEM, ASE_NULL, 0); - return ASE_NULL; - } - - tlink->obj = obj; - tlink->link = lsp->mem->tlink; - lsp->mem->tlink = tlink; - lsp->mem->tlink_count++; - - return tlink; -} - -void ase_lsp_poptmp (ase_lsp_t* lsp) -{ - ase_lsp_tlink_t* top; - - ASE_ASSERT (lsp->mem->tlink != ASE_NULL); - - top = lsp->mem->tlink; - lsp->mem->tlink = top->link; - lsp->mem->tlink_count--; - - ASE_LSP_FREE (lsp, top); -} diff --git a/ase/lsp/env.h b/ase/lsp/env.h deleted file mode 100644 index 0e10baf0..00000000 --- a/ase/lsp/env.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * $Id: env.h,v 1.1.1.1 2007/03/28 14:05:24 bacon Exp $ - * - * {License} - */ - -#ifndef _ASE_LSP_ENV_H_ -#define _ASE_LSP_ENV_H_ - -#ifndef _ASE_LSP_LSP_H_ -#error Never include this file directly. Include instead -#endif - -typedef struct ase_lsp_assoc_t ase_lsp_assoc_t; -typedef struct ase_lsp_frame_t ase_lsp_frame_t; -typedef struct ase_lsp_tlink_t ase_lsp_tlink_t; - -struct ase_lsp_assoc_t -{ - ase_lsp_obj_t* name; /* ase_lsp_obj_sym_t */ - ase_lsp_obj_t* value; /* value as a variable */ - ase_lsp_obj_t* func; /* function definition */ - - ase_lsp_assoc_t* link; -}; - -struct ase_lsp_frame_t -{ - ase_lsp_assoc_t* assoc; - ase_lsp_frame_t* link; -}; - -struct ase_lsp_tlink_t -{ - ase_lsp_obj_t* obj; - ase_lsp_tlink_t* link; -}; - -#ifdef __cplusplus -extern "C" { -#endif - -ase_lsp_frame_t* ase_lsp_newframe (ase_lsp_t* lsp); -void ase_lsp_freeframe (ase_lsp_t* lsp, ase_lsp_frame_t* frame); - -ase_lsp_assoc_t* ase_lsp_lookupinframe ( - ase_lsp_t* lsp, ase_lsp_frame_t* frame, ase_lsp_obj_t* name); - -ase_lsp_assoc_t* ase_lsp_insvalueintoframe ( - ase_lsp_t* lsp, ase_lsp_frame_t* frame, - ase_lsp_obj_t* name, ase_lsp_obj_t* value); -ase_lsp_assoc_t* ase_lsp_insfuncintoframe ( - ase_lsp_t* lsp, ase_lsp_frame_t* frame, - ase_lsp_obj_t* name, ase_lsp_obj_t* func); - -ase_lsp_tlink_t* ase_lsp_pushtmp (ase_lsp_t* lsp, ase_lsp_obj_t* obj); -void ase_lsp_poptmp (ase_lsp_t* lsp); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ase/lsp/err.c b/ase/lsp/err.c deleted file mode 100644 index fe736a85..00000000 --- a/ase/lsp/err.c +++ /dev/null @@ -1,130 +0,0 @@ -/* - * $Id: err.c,v 1.1.1.1 2007/03/28 14:05:24 bacon Exp $ - * - * {License} - */ - -#include - -static const ase_char_t* __geterrstr (int errnum) -{ - static const ase_char_t* __errstr[] = - { - ASE_T("no error"), - ASE_T("out of memory"), - ASE_T("exit"), - ASE_T("end of source"), - ASE_T("unexpected end of string"), - ASE_T("input not attached"), - ASE_T("input"), - ASE_T("output not attached"), - ASE_T("output"), - ASE_T("syntax"), - ASE_T("right parenthesis expected"), - ASE_T("bad arguments"), - ASE_T("too few arguments"), - ASE_T("too many arguments"), - ASE_T("undefined function '%s'"), - ASE_T("bad function"), - ASE_T("duplicate formal"), - ASE_T("bad symbol"), - ASE_T("undefined symbol '%s'"), - ASE_T("empty body"), - ASE_T("bad value"), - ASE_T("divide by zero") - }; - - if (errnum >= 0 && errnum < ASE_COUNTOF(__errstr)) - { - return __errstr[errnum]; - } - - return ASE_T("unknown error"); -} - -void ase_lsp_geterror ( - ase_lsp_t* lsp, int* errnum, const ase_char_t** errmsg) -{ - if (errnum != ASE_NULL) *errnum = lsp->errnum; - if (errmsg != ASE_NULL) *errmsg = lsp->errmsg; -} - -void ase_lsp_seterror ( - ase_lsp_t* lsp, int errnum, - const ase_char_t** errarg, ase_size_t argcnt) -{ - const ase_char_t* errfmt; - - ASE_ASSERT (argcnt <= 5); - - lsp->errnum = errnum; - errfmt = __geterrstr (errnum); - - switch (argcnt) - { - case 0: - lsp->prmfns.misc.sprintf ( - lsp->prmfns.misc.custom_data, - lsp->errmsg, - ASE_COUNTOF(lsp->errmsg), - errfmt); - return; - - case 1: - lsp->prmfns.misc.sprintf ( - lsp->prmfns.misc.custom_data, - lsp->errmsg, - ASE_COUNTOF(lsp->errmsg), - errfmt, - errarg[0]); - return; - - case 2: - lsp->prmfns.misc.sprintf ( - lsp->prmfns.misc.custom_data, - lsp->errmsg, - ASE_COUNTOF(lsp->errmsg), - errfmt, - errarg[0], - errarg[1]); - return; - - case 3: - lsp->prmfns.misc.sprintf ( - lsp->prmfns.misc.custom_data, - lsp->errmsg, - ASE_COUNTOF(lsp->errmsg), - errfmt, - errarg[0], - errarg[1], - errarg[2]); - return; - - case 4: - lsp->prmfns.misc.sprintf ( - lsp->prmfns.misc.custom_data, - lsp->errmsg, - ASE_COUNTOF(lsp->errmsg), - errfmt, - errarg[0], - errarg[1], - errarg[2], - errarg[3]); - return; - - case 5: - lsp->prmfns.misc.sprintf ( - lsp->prmfns.misc.custom_data, - lsp->errmsg, - ASE_COUNTOF(lsp->errmsg), - errfmt, - errarg[0], - errarg[1], - errarg[2], - errarg[3], - errarg[4]); - return; - } -} - - diff --git a/ase/lsp/eval.c b/ase/lsp/eval.c deleted file mode 100644 index 46d922ee..00000000 --- a/ase/lsp/eval.c +++ /dev/null @@ -1,380 +0,0 @@ -/* - * $Id: eval.c,v 1.1.1.1 2007/03/28 14:05:24 bacon Exp $ - * - * {License} - */ - -#include - -static ase_lsp_obj_t* __eval (ase_lsp_t* lsp, ase_lsp_obj_t* obj); -static ase_lsp_obj_t* makefn ( - ase_lsp_t* lsp, ase_lsp_obj_t* cdr, int is_macro); -static ase_lsp_obj_t* eval_cons ( - ase_lsp_t* lsp, ase_lsp_obj_t* cons); -static ase_lsp_obj_t* apply ( - ase_lsp_t* lsp, ase_lsp_obj_t* func, ase_lsp_obj_t* actual); -static ase_lsp_obj_t* apply_to_prim ( - ase_lsp_t* lsp, ase_lsp_obj_t* func, ase_lsp_obj_t* actual); - -ase_lsp_obj_t* ase_lsp_eval (ase_lsp_t* lsp, ase_lsp_obj_t* obj) -{ - if (ASE_LSP_TYPE(obj) == ASE_LSP_OBJ_CONS) - { - return eval_cons (lsp, obj); - } - else if (ASE_LSP_TYPE(obj) == ASE_LSP_OBJ_SYM) - { - ase_lsp_assoc_t* assoc; - - /* - if (obj == lsp->mem->lambda || obj == lsp->mem->macro) { - ase_char_t* arg[1]; - - arg[0] = ASE_LSP_SYMPTR(obj); - - printf ("lambda or macro can't be used as a normal symbol\n"); - ase_lsp_seterror ( - lsp, ASE_LSP_EBADSYM, - arg, ASE_COUNTOF(arg)); - return ASE_NULL; - } - */ - - assoc = ase_lsp_lookup(lsp->mem, obj); - if (assoc == ASE_NULL || assoc->value == ASE_NULL) - { - if (lsp->opt_undef_symbol) - { - const ase_char_t* arg[1]; - - arg[0] = ASE_LSP_SYMPTR(obj); - - ase_lsp_seterror ( - lsp, ASE_LSP_EUNDEFSYM, - arg, ASE_COUNTOF(arg)); - return ASE_NULL; - } - return lsp->mem->nil; - } - - obj = assoc->value; - } - - return obj; -} - -static ase_lsp_obj_t* makefn (ase_lsp_t* lsp, ase_lsp_obj_t* cdr, int is_macro) -{ - ase_lsp_obj_t* func, * formal, * body, * p; - - if (cdr == lsp->mem->nil) - { - ase_lsp_seterror (lsp, ASE_LSP_EARGFEW, ASE_NULL, 0); - return ASE_NULL; - } - - if (ASE_LSP_TYPE(cdr) != ASE_LSP_OBJ_CONS) - { - ase_lsp_seterror (lsp, ASE_LSP_EARGBAD, ASE_NULL, 0); - return ASE_NULL; - } - - formal = ASE_LSP_CAR(cdr); - body = ASE_LSP_CDR(cdr); - - if (body == lsp->mem->nil) - { - ase_lsp_seterror (lsp, ASE_LSP_EEMPBDY, ASE_NULL, 0); - return ASE_NULL; - } - -/* TODO: more lambda expression syntax checks required???. */ - - /* check if the lambda express has non-nil value - * at the terminating cdr */ - for (p = body; ASE_LSP_TYPE(p) == ASE_LSP_OBJ_CONS; p = ASE_LSP_CDR(p)); - if (p != lsp->mem->nil) - { - /* like in (lambda (x) (+ x 10) . 4) */ - ase_lsp_seterror (lsp, ASE_LSP_EARGBAD, ASE_NULL, 0); - return ASE_NULL; - } - - func = (is_macro)? - ase_lsp_makemacro (lsp->mem, formal, body): - ase_lsp_makefunc (lsp->mem, formal, body); - if (func == ASE_NULL) return ASE_NULL; - - return func; -} - -static ase_lsp_obj_t* eval_cons (ase_lsp_t* lsp, ase_lsp_obj_t* cons) -{ - ase_lsp_obj_t* car, * cdr; - - ASE_ASSERT (ASE_LSP_TYPE(cons) == ASE_LSP_OBJ_CONS); - - car = ASE_LSP_CAR(cons); - cdr = ASE_LSP_CDR(cons); - - if (car == lsp->mem->lambda) - { - /* (lambda (x) (+ x 20)) */ - return makefn (lsp, cdr, 0); - } - else if (car == lsp->mem->macro) - { - /* (macro (x) (+ x 20)) */ - return makefn (lsp, cdr, 1); - } - else if (ASE_LSP_TYPE(car) == ASE_LSP_OBJ_SYM) - { - ase_lsp_assoc_t* assoc; - - if ((assoc = ase_lsp_lookup(lsp->mem, car)) != ASE_NULL) - { - /*ase_lsp_obj_t* func = assoc->value;*/ - ase_lsp_obj_t* func = assoc->func; - if (func == ASE_NULL) - { - /* the symbol's function definition is void */ - const ase_char_t* arg[1]; - - arg[0] = ASE_LSP_SYMPTR(car); - ase_lsp_seterror ( - lsp, ASE_LSP_EUNDEFFN, - arg, ASE_COUNTOF(arg)); - - return ASE_NULL; - } - - if (ASE_LSP_TYPE(func) == ASE_LSP_OBJ_FUNC || - ASE_LSP_TYPE(func) == ASE_LSP_OBJ_MACRO) - { - return apply (lsp, func, cdr); - } - else if (ASE_LSP_TYPE(func) == ASE_LSP_OBJ_PRIM) - { - /* primitive function */ - return apply_to_prim (lsp, func, cdr); - } - else - { - const ase_char_t* arg[1]; - - arg[0] = ASE_LSP_SYMPTR(car); - ase_lsp_seterror ( - lsp, ASE_LSP_EUNDEFFN, - arg, ASE_COUNTOF(arg)); - - return ASE_NULL; - } - } - else - { - const ase_char_t* arg[1]; - - arg[0] = ASE_LSP_SYMPTR(car); - ase_lsp_seterror ( - lsp, ASE_LSP_EUNDEFFN, - arg, ASE_COUNTOF(arg)); - - return ASE_NULL; - } - } - else if (ASE_LSP_TYPE(car) == ASE_LSP_OBJ_FUNC || - ASE_LSP_TYPE(car) == ASE_LSP_OBJ_MACRO) - { - return apply (lsp, car, cdr); - } - else if (ASE_LSP_TYPE(car) == ASE_LSP_OBJ_CONS) - { - /* anonymous function or macros - * ((lambda (x) (+ x 10)) 50) */ - if (ASE_LSP_CAR(car) == lsp->mem->lambda) - { - ase_lsp_obj_t* func = makefn (lsp, ASE_LSP_CDR(car), 0); - if (func == ASE_NULL) return ASE_NULL; - return apply (lsp, func, cdr); - } - else if (ASE_LSP_CAR(car) == lsp->mem->macro) - { - ase_lsp_obj_t* func = makefn (lsp, ASE_LSP_CDR(car), 1); - if (func == ASE_NULL) return ASE_NULL; - return apply (lsp, func, cdr); - } - } - - ase_lsp_seterror (lsp, ASE_LSP_EBADFN, ASE_NULL, 0); - return ASE_NULL; -} - -static ase_lsp_obj_t* apply ( - ase_lsp_t* lsp, ase_lsp_obj_t* func, ase_lsp_obj_t* actual) -{ - ase_lsp_frame_t* frame; - ase_lsp_obj_t* formal; - ase_lsp_obj_t* body; - ase_lsp_obj_t* value; - ase_lsp_mem_t* mem; - - ASE_ASSERT (ASE_LSP_TYPE(func) == ASE_LSP_OBJ_FUNC || - ASE_LSP_TYPE(func) == ASE_LSP_OBJ_MACRO); - - ASE_ASSERT (ASE_LSP_TYPE(ASE_LSP_CDR(func)) == ASE_LSP_OBJ_CONS); - - mem = lsp->mem; - - if (ASE_LSP_TYPE(func) == ASE_LSP_OBJ_MACRO) - { - formal = ASE_LSP_MFORMAL (func); - body = ASE_LSP_MBODY (func); - } - else - { - formal = ASE_LSP_FFORMAL (func); - body = ASE_LSP_FBODY (func); - } - - /* make a new frame. */ - frame = ase_lsp_newframe (lsp); - if (frame == ASE_NULL) return ASE_NULL; - - /* attach it to the brooding frame list to - * prevent them from being garbage-collected. */ - frame->link = mem->brooding_frame; - mem->brooding_frame = frame; - - /* evaluate arguments and push them into the frame. */ - while (formal != mem->nil) - { - if (actual == mem->nil) - { - mem->brooding_frame = frame->link; - ase_lsp_freeframe (lsp, frame); - - ase_lsp_seterror (lsp, ASE_LSP_EARGFEW, ASE_NULL, 0); - return ASE_NULL; - } - - value = ASE_LSP_CAR(actual); - if (ASE_LSP_TYPE(func) != ASE_LSP_OBJ_MACRO) - { - /* macro doesn't evaluate actual arguments. */ - value = ase_lsp_eval (lsp, value); - if (value == ASE_NULL) - { - mem->brooding_frame = frame->link; - ase_lsp_freeframe (lsp, frame); - return ASE_NULL; - } - } - - if (ase_lsp_lookupinframe ( - lsp, frame, ASE_LSP_CAR(formal)) != ASE_NULL) - { - mem->brooding_frame = frame->link; - ase_lsp_freeframe (lsp, frame); - - ase_lsp_seterror (lsp, ASE_LSP_EDUPFML, ASE_NULL, 0); - return ASE_NULL; - } - - if (ase_lsp_insvalueintoframe ( - lsp, frame, ASE_LSP_CAR(formal), value) == ASE_NULL) - { - mem->brooding_frame = frame->link; - ase_lsp_freeframe (lsp, frame); - return ASE_NULL; - } - - actual = ASE_LSP_CDR(actual); - formal = ASE_LSP_CDR(formal); - } - - if (ASE_LSP_TYPE(actual) == ASE_LSP_OBJ_CONS) - { - mem->brooding_frame = frame->link; - ase_lsp_freeframe (lsp, frame); - - ase_lsp_seterror (lsp, ASE_LSP_EARGMANY, ASE_NULL, 0); - return ASE_NULL; - } - else if (actual != mem->nil) - { - mem->brooding_frame = frame->link; - ase_lsp_freeframe (lsp, frame); - - ase_lsp_seterror (lsp, ASE_LSP_EARGBAD, ASE_NULL, 0); - return ASE_NULL; - } - - /* push the frame */ - mem->brooding_frame = frame->link; - frame->link = mem->frame; - mem->frame = frame; - - /* do the evaluation of the body */ - value = mem->nil; - while (body != mem->nil) - { - value = ase_lsp_eval(lsp, ASE_LSP_CAR(body)); - if (value == ASE_NULL) - { - mem->frame = frame->link; - ase_lsp_freeframe (lsp, frame); - return ASE_NULL; - } - body = ASE_LSP_CDR(body); - } - - /* pop the frame. */ - mem->frame = frame->link; - - /* destroy the frame. */ - ase_lsp_freeframe (lsp, frame); - - /*if (ASE_LSP_CAR(func) == mem->macro) {*/ - if (ASE_LSP_TYPE(func) == ASE_LSP_OBJ_MACRO) - { - value = ase_lsp_eval (lsp, value); - if (value == ASE_NULL) return ASE_NULL; - } - - return value; -} - -static ase_lsp_obj_t* apply_to_prim ( - ase_lsp_t* lsp, ase_lsp_obj_t* func, ase_lsp_obj_t* actual) -{ - ase_lsp_obj_t* obj; - ase_size_t count = 0; - - ASE_ASSERT (ASE_LSP_TYPE(func) == ASE_LSP_OBJ_PRIM); - - obj = actual; - while (ASE_LSP_TYPE(obj) == ASE_LSP_OBJ_CONS) - { - count++; - obj = ASE_LSP_CDR(obj); - } - if (obj != lsp->mem->nil) - { - ase_lsp_seterror (lsp, ASE_LSP_EARGBAD, ASE_NULL, 0); - return ASE_NULL; - } - - if (count < ASE_LSP_PMINARGS(func)) - { - ase_lsp_seterror (lsp, ASE_LSP_EARGFEW, ASE_NULL, 0); - return ASE_NULL; - } - - if (count > ASE_LSP_PMAXARGS(func)) - { - ase_lsp_seterror (lsp, ASE_LSP_EARGMANY, ASE_NULL, 0); - return ASE_NULL; - } - - return ASE_LSP_PIMPL(func) (lsp, actual); -} diff --git a/ase/lsp/lsp.c b/ase/lsp/lsp.c deleted file mode 100644 index fb5e26ef..00000000 --- a/ase/lsp/lsp.c +++ /dev/null @@ -1,218 +0,0 @@ -/* - * $Id: lsp.c,v 1.1.1.1 2007/03/28 14:05:24 bacon Exp $ - * - * {License} - */ - -#if defined(__BORLANDC__) -#pragma hdrstop -#define Library -#endif - -#include - -static int __add_builtin_prims (ase_lsp_t* lsp); - -ase_lsp_t* ase_lsp_open ( - const ase_lsp_prmfns_t* prmfns, - ase_size_t mem_ubound, ase_size_t mem_ubound_inc) -{ - ase_lsp_t* lsp; - - if (prmfns == ASE_NULL) return ASE_NULL; - - if (prmfns->mmgr.malloc == ASE_NULL || - prmfns->mmgr.realloc == ASE_NULL || - prmfns->mmgr.free == ASE_NULL) return ASE_NULL; - - if (prmfns->ccls.is_upper == ASE_NULL || - prmfns->ccls.is_lower == ASE_NULL || - prmfns->ccls.is_alpha == ASE_NULL || - prmfns->ccls.is_digit == ASE_NULL || - prmfns->ccls.is_xdigit == ASE_NULL || - prmfns->ccls.is_alnum == ASE_NULL || - prmfns->ccls.is_space == ASE_NULL || - prmfns->ccls.is_print == ASE_NULL || - prmfns->ccls.is_graph == ASE_NULL || - prmfns->ccls.is_cntrl == ASE_NULL || - prmfns->ccls.is_punct == ASE_NULL || - prmfns->ccls.to_upper == ASE_NULL || - prmfns->ccls.to_lower == ASE_NULL) return ASE_NULL; - - if (prmfns->misc.sprintf == ASE_NULL || - prmfns->misc.dprintf == ASE_NULL) return ASE_NULL; - -#if defined(_WIN32) && defined(_MSC_VER) && defined(_DEBUG) - lsp = (ase_lsp_t*) malloc (ASE_SIZEOF(ase_lsp_t)); -#else - lsp = (ase_lsp_t*) prmfns->mmgr.malloc ( - prmfns->mmgr.custom_data, ASE_SIZEOF(ase_lsp_t)); -#endif - if (lsp == ASE_NULL) return ASE_NULL; - - /* it uses the built-in ase_lsp_memset because lsp is not - * fully initialized yet */ - ase_memset (lsp, 0, ASE_SIZEOF(ase_lsp_t)); - ase_memcpy (&lsp->prmfns, prmfns, ASE_SIZEOF(lsp->prmfns)); - - if (ase_lsp_name_open(&lsp->token.name, 0, lsp) == ASE_NULL) - { - ASE_LSP_FREE (lsp, lsp); - return ASE_NULL; - } - - lsp->errnum = ASE_LSP_ENOERR; - lsp->errmsg[0] = ASE_T('\0'); - lsp->opt_undef_symbol = 1; - /*lsp->opt_undef_symbol = 0;*/ - - lsp->curc = ASE_CHAR_EOF; - lsp->input_func = ASE_NULL; - lsp->output_func = ASE_NULL; - lsp->input_arg = ASE_NULL; - lsp->output_arg = ASE_NULL; - - lsp->mem = ase_lsp_openmem (lsp, mem_ubound, mem_ubound_inc); - if (lsp->mem == ASE_NULL) - { - ase_lsp_name_close (&lsp->token.name); - ASE_LSP_FREE (lsp, lsp); - return ASE_NULL; - } - - if (__add_builtin_prims(lsp) == -1) - { - ase_lsp_closemem (lsp->mem); - ase_lsp_name_close (&lsp->token.name); - ASE_LSP_FREE (lsp, lsp); - return ASE_NULL; - } - - lsp->max_eval_depth = 0; /* TODO: put restriction here.... */ - lsp->cur_eval_depth = 0; - - return lsp; -} - -void ase_lsp_close (ase_lsp_t* lsp) -{ - ase_lsp_closemem (lsp->mem); - ase_lsp_name_close (&lsp->token.name); - ASE_LSP_FREE (lsp, lsp); -} - -int ase_lsp_attinput (ase_lsp_t* lsp, ase_lsp_io_t input, void* arg) -{ - if (ase_lsp_detinput(lsp) == -1) return -1; - - ASE_ASSERT (lsp->input_func == ASE_NULL); - - if (input(ASE_LSP_IO_OPEN, arg, ASE_NULL, 0) == -1) - { - /* TODO: set error number */ - return -1; - } - - lsp->input_func = input; - lsp->input_arg = arg; - lsp->curc = ASE_CHAR_EOF; - return 0; -} - -int ase_lsp_detinput (ase_lsp_t* lsp) -{ - if (lsp->input_func != ASE_NULL) - { - if (lsp->input_func ( - ASE_LSP_IO_CLOSE, lsp->input_arg, ASE_NULL, 0) == -1) - { - /* TODO: set error number */ - return -1; - } - lsp->input_func = ASE_NULL; - lsp->input_arg = ASE_NULL; - lsp->curc = ASE_CHAR_EOF; - } - - return 0; -} - -int ase_lsp_attoutput (ase_lsp_t* lsp, ase_lsp_io_t output, void* arg) -{ - if (ase_lsp_detoutput(lsp) == -1) return -1; - - ASE_ASSERT (lsp->output_func == ASE_NULL); - - if (output(ASE_LSP_IO_OPEN, arg, ASE_NULL, 0) == -1) - { - /* TODO: set error number */ - return -1; - } - lsp->output_func = output; - lsp->output_arg = arg; - return 0; -} - -int ase_lsp_detoutput (ase_lsp_t* lsp) -{ - if (lsp->output_func != ASE_NULL) - { - if (lsp->output_func ( - ASE_LSP_IO_CLOSE, lsp->output_arg, ASE_NULL, 0) == -1) - { - /* TODO: set error number */ - return -1; - } - lsp->output_func = ASE_NULL; - lsp->output_arg = ASE_NULL; - } - - return 0; -} - -static int __add_builtin_prims (ase_lsp_t* lsp) -{ - -#define ADD_PRIM(mem,name,name_len,pimpl,min_args,max_args) \ - if (ase_lsp_addprim(mem,name,name_len,pimpl,min_args,max_args) == -1) return -1; -#define MAX_ARGS ASE_TYPE_MAX(ase_size_t) - - ADD_PRIM (lsp, ASE_T("exit"), 4, ase_lsp_prim_exit, 0, 0); - ADD_PRIM (lsp, ASE_T("eval"), 4, ase_lsp_prim_eval, 1, 1); - ADD_PRIM (lsp, ASE_T("prog1"), 5, ase_lsp_prim_prog1, 1, MAX_ARGS); - ADD_PRIM (lsp, ASE_T("progn"), 5, ase_lsp_prim_progn, 1, MAX_ARGS); - ADD_PRIM (lsp, ASE_T("gc"), 2, ase_lsp_prim_gc, 0, 0); - - ADD_PRIM (lsp, ASE_T("cond"), 4, ase_lsp_prim_cond, 0, MAX_ARGS); - ADD_PRIM (lsp, ASE_T("if"), 2, ase_lsp_prim_if, 2, MAX_ARGS); - ADD_PRIM (lsp, ASE_T("while"), 5, ase_lsp_prim_while, 1, MAX_ARGS); - - ADD_PRIM (lsp, ASE_T("car"), 3, ase_lsp_prim_car, 1, 1); - ADD_PRIM (lsp, ASE_T("cdr"), 3, ase_lsp_prim_cdr, 1, 1); - ADD_PRIM (lsp, ASE_T("cons"), 4, ase_lsp_prim_cons, 2, 2); - ADD_PRIM (lsp, ASE_T("length"), 6, ase_lsp_prim_length, 1, 1); - - ADD_PRIM (lsp, ASE_T("set"), 3, ase_lsp_prim_set, 2, 2); - ADD_PRIM (lsp, ASE_T("setq"), 4, ase_lsp_prim_setq, 1, MAX_ARGS); - ADD_PRIM (lsp, ASE_T("quote"), 5, ase_lsp_prim_quote, 1, 1); - ADD_PRIM (lsp, ASE_T("defun"), 5, ase_lsp_prim_defun, 3, MAX_ARGS); - ADD_PRIM (lsp, ASE_T("demac"), 5, ase_lsp_prim_demac, 3, MAX_ARGS); - ADD_PRIM (lsp, ASE_T("let"), 3, ase_lsp_prim_let, 1, MAX_ARGS); - ADD_PRIM (lsp, ASE_T("let*"), 4, ase_lsp_prim_letx, 1, MAX_ARGS); - /*ADD_PRIM (lsp, ASE_T("or"), 2, ase_lsp_prim_or, 2, MAX_ARGS);*/ - - ADD_PRIM (lsp, ASE_T("="), 1, ase_lsp_prim_eq, 2, 2); - ADD_PRIM (lsp, ASE_T("/="), 2, ase_lsp_prim_ne, 2, 2); - ADD_PRIM (lsp, ASE_T(">"), 1, ase_lsp_prim_gt, 2, 2); - ADD_PRIM (lsp, ASE_T("<"), 1, ase_lsp_prim_lt, 2, 2); - ADD_PRIM (lsp, ASE_T(">="), 2, ase_lsp_prim_ge, 2, 2); - ADD_PRIM (lsp, ASE_T("<="), 2, ase_lsp_prim_le, 2, 2); - - ADD_PRIM (lsp, ASE_T("+"), 1, ase_lsp_prim_plus, 1, MAX_ARGS); - ADD_PRIM (lsp, ASE_T("-"), 1, ase_lsp_prim_minus, 1, MAX_ARGS); - ADD_PRIM (lsp, ASE_T("*"), 1, ase_lsp_prim_mul, 1, MAX_ARGS); - ADD_PRIM (lsp, ASE_T("/"), 1, ase_lsp_prim_div, 1, MAX_ARGS); - ADD_PRIM (lsp, ASE_T("%"), 1, ase_lsp_prim_mod , 1, MAX_ARGS); - - return 0; -} diff --git a/ase/lsp/lsp.h b/ase/lsp/lsp.h deleted file mode 100644 index efed6e77..00000000 --- a/ase/lsp/lsp.h +++ /dev/null @@ -1,123 +0,0 @@ -/* - * $Id: lsp.h,v 1.1.1.1 2007/03/28 14:05:24 bacon Exp $ - * - * {License} - */ - -#ifndef _ASE_LSP_LSP_H_ -#define _ASE_LSP_LSP_H_ - -#include -#include - -typedef struct ase_lsp_t ase_lsp_t; -typedef struct ase_lsp_obj_t ase_lsp_obj_t; -typedef struct ase_lsp_prmfns_t ase_lsp_prmfns_t; - -typedef ase_ssize_t (*ase_lsp_io_t) ( - int cmd, void* arg, ase_char_t* data, ase_size_t count); - -typedef ase_real_t (*ase_lsp_pow_t) ( - void* custom, ase_real_t x, ase_real_t y); -typedef int (*ase_lsp_sprintf_t) ( - void* custom, ase_char_t* buf, ase_size_t size, - const ase_char_t* fmt, ...); -typedef void (*ase_lsp_dprintf_t) (void* custom, const ase_char_t* fmt, ...); - -struct ase_lsp_prmfns_t -{ - ase_mmgr_t mmgr; - ase_ccls_t ccls; - - /* utilities */ - struct - { - ase_lsp_sprintf_t sprintf; - ase_lsp_dprintf_t dprintf; - void* custom_data; - } misc; -}; - -/* io function commands */ -enum -{ - ASE_LSP_IO_OPEN = 0, - ASE_LSP_IO_CLOSE = 1, - ASE_LSP_IO_READ = 2, - ASE_LSP_IO_WRITE = 3 -}; - -/* option code */ -enum -{ - ASE_LSP_UNDEFSYMBOL = (1 << 0) -}; - -/* error code */ -enum -{ - ASE_LSP_ENOERR, - ASE_LSP_ENOMEM, - - ASE_LSP_EEXIT, - ASE_LSP_EEND, - ASE_LSP_EENDSTR, - ASE_LSP_ENOINP, - ASE_LSP_EINPUT, - ASE_LSP_ENOOUTP, - ASE_LSP_EOUTPUT, - - ASE_LSP_ESYNTAX, - ASE_LSP_ERPAREN, - ASE_LSP_EARGBAD, - ASE_LSP_EARGFEW, - ASE_LSP_EARGMANY, - ASE_LSP_EUNDEFFN, - ASE_LSP_EBADFN, - ASE_LSP_EDUPFML, - ASE_LSP_EBADSYM, - ASE_LSP_EUNDEFSYM, - ASE_LSP_EEMPBDY, - ASE_LSP_EVALBAD, - ASE_LSP_EDIVBY0 -}; - -typedef ase_lsp_obj_t* (*ase_lsp_prim_t) (ase_lsp_t* lsp, ase_lsp_obj_t* obj); - -#ifdef __cplusplus -extern "C" { -#endif - -ase_lsp_t* ase_lsp_open ( - const ase_lsp_prmfns_t* prmfns, - ase_size_t mem_ubound, ase_size_t mem_ubound_inc); - -void ase_lsp_close (ase_lsp_t* lsp); - -void ase_lsp_geterror ( - ase_lsp_t* lsp, int* errnum, const ase_char_t** errmsg); - -void ase_lsp_seterror ( - ase_lsp_t* lsp, int errnum, - const ase_char_t** errarg, ase_size_t argcnt); - -int ase_lsp_attinput (ase_lsp_t* lsp, ase_lsp_io_t input, void* arg); -int ase_lsp_detinput (ase_lsp_t* lsp); - -int ase_lsp_attoutput (ase_lsp_t* lsp, ase_lsp_io_t output, void* arg); -int ase_lsp_detoutput (ase_lsp_t* lsp); - -ase_lsp_obj_t* ase_lsp_read (ase_lsp_t* lsp); -ase_lsp_obj_t* ase_lsp_eval (ase_lsp_t* lsp, ase_lsp_obj_t* obj); -int ase_lsp_print (ase_lsp_t* lsp, const ase_lsp_obj_t* obj); - -int ase_lsp_addprim ( - ase_lsp_t* lsp, const ase_char_t* name, ase_size_t name_len, - ase_lsp_prim_t prim, ase_size_t min_args, ase_size_t max_args); -int ase_lsp_removeprim (ase_lsp_t* lsp, const ase_char_t* name); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ase/lsp/lsp_i.h b/ase/lsp/lsp_i.h deleted file mode 100644 index cd7b38a8..00000000 --- a/ase/lsp/lsp_i.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * $Id: lsp_i.h,v 1.1.1.1 2007/03/28 14:05:24 bacon Exp $ - * - * {License} - */ - -#ifndef _ASE_LSP_LSPI_H_ -#define _ASE_LSP_LSPI_H_ - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#ifdef _MSC_VER -#pragma warning (disable: 4996) -#endif - -#if defined(_WIN32) && defined(_MSC_VER) && defined(_DEBUG) - #define _CRTDBG_MAP_ALLOC - #include - - #define ASE_LSP_MALLOC(lsp,size) malloc (size) - #define ASE_LSP_REALLOC(lsp,ptr,size) realloc (ptr, size) - #define ASE_LSP_FREE(lsp,ptr) free (ptr) -#else - #define ASE_LSP_MALLOC(lsp,size) ASE_MALLOC(&(lsp)->prmfns.mmgr,size) - #define ASE_LSP_REALLOC(lsp,ptr,size) ASE_REALLOC(&(lsp)->prmfns.mmgr,ptr,size) - #define ASE_LSP_FREE(lsp,ptr) ASE_FREE(&(lsp)->prmfns.mmgr,ptr) -#endif - -#define ASE_LSP_ISUPPER(lsp,c) ASE_ISUPPER(&(lsp)->prmfns.ccls,c) -#define ASE_LSP_ISLOWER(lsp,c) ASE_ISLOWER(&(lsp)->prmfns.ccls,c) -#define ASE_LSP_ISALPHA(lsp,c) ASE_ISALPHA(&(lsp)->prmfns.ccls,c) -#define ASE_LSP_ISDIGIT(lsp,c) ASE_ISDIGIT(&(lsp)->prmfns.ccls,c) -#define ASE_LSP_ISXDIGIT(lsp,c) ASE_ISXDIGIT(&(lsp)->prmfns.ccls,c) -#define ASE_LSP_ISALNUM(lsp,c) ASE_ISALNUM(&(lsp)->prmfns.ccls,c) -#define ASE_LSP_ISSPACE(lsp,c) ASE_ISSPACE(&(lsp)->prmfns.ccls,c) -#define ASE_LSP_ISPRINT(lsp,c) ASE_ISPRINT(&(lsp)->prmfns.ccls,c) -#define ASE_LSP_ISGRAPH(lsp,c) ASE_ISGRAPH(&(lsp)->prmfns.ccls,c) -#define ASE_LSP_ISCNTRL(lsp,c) ASE_ISCNTRL(&(lsp)->prmfns.ccls,c) -#define ASE_LSP_ISPUNCT(lsp,c) ASE_ISPUNCT(&(lsp)->prmfns.ccls,c) -#define ASE_LSP_TOUPPER(lsp,c) ASE_TOUPPER(&(lsp)->prmfns.ccls,c) -#define ASE_LSP_TOLOWER(lsp,c) ASE_TOLOWER(&(lsp)->prmfns.ccls,c) - -struct ase_lsp_t -{ - ase_lsp_prmfns_t prmfns; - - /* error */ - int errnum; - ase_char_t errmsg[256]; - - /* options */ - int opt_undef_symbol; - - /* for read */ - ase_cint_t curc; - struct - { - int type; - ase_long_t ival; - ase_real_t rval; - ase_lsp_name_t name; - } token; - - /* io functions */ - ase_lsp_io_t input_func; - ase_lsp_io_t output_func; - void* input_arg; - void* output_arg; - - /* security options */ - ase_size_t max_eval_depth; - ase_size_t cur_eval_depth; - - /* memory manager */ - ase_lsp_mem_t* mem; -}; - -#endif diff --git a/ase/lsp/makefile.in b/ase/lsp/makefile.in deleted file mode 100644 index 7ce32d3a..00000000 --- a/ase/lsp/makefile.in +++ /dev/null @@ -1,93 +0,0 @@ -# -# $Id: makefile.in,v 1.1.1.1 2007/03/28 14:05:24 bacon Exp $ -# - -NAME = aselsp - -CC = @CC@ -AR = ar -MAKE = @MAKE@ -RANLIB = @RANLIB@ -CFLAGS = @CFLAGS@ -I@abs_top_builddir@/.. -LDFLAGS = @LDFLAGS@ -LIBS = @LIBS@ -MODE = @BUILDMODE@ - -OUT_DIR = ../$(MODE)/lib -OUT_FILE = $(OUT_DIR)/lib$(NAME).a - -TMP_DIR = $(MODE) - -OBJ_FILES = \ - $(TMP_DIR)/lsp.o \ - $(TMP_DIR)/name.o \ - $(TMP_DIR)/mem.o \ - $(TMP_DIR)/env.o \ - $(TMP_DIR)/err.o \ - $(TMP_DIR)/eval.o \ - $(TMP_DIR)/read.o \ - $(TMP_DIR)/print.o \ - $(TMP_DIR)/misc.o \ - $(TMP_DIR)/prim.o \ - $(TMP_DIR)/prim_prog.o \ - $(TMP_DIR)/prim_let.o \ - $(TMP_DIR)/prim_compar.o \ - $(TMP_DIR)/prim_math.o - -lib: $(OUT_FILE) - -$(OUT_FILE): $(OBJ_FILES) $(OUT_DIR) - $(AR) cr $(OUT_FILE) $(OBJ_FILES) - if [ "$(RANLIB)" = "ranlib" ]; then ranlib $(OUT_FILE); fi - -$(TMP_DIR)/lsp.o: $(TMP_DIR) - $(CC) $(CFLAGS) -o $@ -c lsp.c - -$(TMP_DIR)/name.o: $(TMP_DIR) - $(CC) $(CFLAGS) -o $@ -c name.c - -$(TMP_DIR)/mem.o: $(TMP_DIR) - $(CC) $(CFLAGS) -o $@ -c mem.c - -$(TMP_DIR)/env.o: $(TMP_DIR) - $(CC) $(CFLAGS) -o $@ -c env.c - -$(TMP_DIR)/err.o: $(TMP_DIR) - $(CC) $(CFLAGS) -o $@ -c err.c - -$(TMP_DIR)/eval.o: $(TMP_DIR) - $(CC) $(CFLAGS) -o $@ -c eval.c - -$(TMP_DIR)/read.o: $(TMP_DIR) - $(CC) $(CFLAGS) -o $@ -c read.c - -$(TMP_DIR)/print.o: $(TMP_DIR) - $(CC) $(CFLAGS) -o $@ -c print.c - -$(TMP_DIR)/misc.o: $(TMP_DIR) - $(CC) $(CFLAGS) -o $@ -c misc.c - -$(TMP_DIR)/prim.o: $(TMP_DIR) - $(CC) $(CFLAGS) -o $@ -c prim.c - -$(TMP_DIR)/prim_prog.o: $(TMP_DIR) - $(CC) $(CFLAGS) -o $@ -c prim_prog.c - -$(TMP_DIR)/prim_let.o: $(TMP_DIR) - $(CC) $(CFLAGS) -o $@ -c prim_let.c - -$(TMP_DIR)/prim_compar.o: $(TMP_DIR) - $(CC) $(CFLAGS) -o $@ -c prim_compar.c - -$(TMP_DIR)/prim_math.o: $(TMP_DIR) - $(CC) $(CFLAGS) -o $@ -c prim_math.c - -$(OUT_DIR): - mkdir -p $(OUT_DIR) - -$(TMP_DIR): - mkdir -p $(TMP_DIR) - -clean: - rm -rf $(OUT_FILE) $(OBJ_FILES) - diff --git a/ase/lsp/makefile.msw.bcc b/ase/lsp/makefile.msw.bcc deleted file mode 100644 index d3a13f88..00000000 --- a/ase/lsp/makefile.msw.bcc +++ /dev/null @@ -1,21 +0,0 @@ -SRCS = lsp.c name.c mem.c env.c err.c read.c eval.c print.c misc.c \ - prim.c prim_prog.c prim_let.c prim_compar.c prim_math.c -OBJS = $(SRCS:.c=.obj) -OUT = aselsp.lib - -CC = bcc32 -CFLAGS = -O2 -WM -w -w-inl -w-sig -w-spa -w-hid -RT- -I../.. - -all: $(OBJS) - tlib $(OUT) @&&! -+-$(**: = &^ -+-) -! - -clean: - -del $(OBJS) $(OUT) *.obj - -.SUFFIXES: .c .obj -.c.obj: - $(CC) $(CFLAGS) -c $< - diff --git a/ase/lsp/makefile.msw.cl b/ase/lsp/makefile.msw.cl deleted file mode 100644 index e7e9c797..00000000 --- a/ase/lsp/makefile.msw.cl +++ /dev/null @@ -1,24 +0,0 @@ -OUT = aselsp - -SRCS = lsp.c name.c mem.c env.c err.c read.c eval.c print.c misc.c \ - prim.c prim_prog.c prim_let.c prim_compar.c prim_math.c -OBJS = $(SRCS:.c=.obj) - -CC = cl -LD = link -CFLAGS = /nologo /O2 /MT /W3 /GR- /Za -I../.. - -all: lib - -lib: $(OBJS) - $(LD) -lib @<< -/nologo /out:$(OUT).lib $(OBJS) -<< - -clean: - del $(OBJS) $(OUT) *.obj - -.SUFFIXES: .c .obj -.c.obj: - $(CC) $(CFLAGS) /c $< - diff --git a/ase/lsp/mem.c b/ase/lsp/mem.c deleted file mode 100644 index 1e866a32..00000000 --- a/ase/lsp/mem.c +++ /dev/null @@ -1,601 +0,0 @@ -/* - * $Id: mem.c,v 1.1.1.1 2007/03/28 14:05:24 bacon Exp $ - * - * {License} - */ - -#include - -ase_lsp_mem_t* ase_lsp_openmem ( - ase_lsp_t* lsp, ase_size_t ubound, ase_size_t ubound_inc) -{ - ase_lsp_mem_t* mem; - ase_size_t i; - - /* allocate memory */ - mem = (ase_lsp_mem_t*) ASE_LSP_MALLOC (lsp, ASE_SIZEOF(ase_lsp_mem_t)); - if (mem == ASE_NULL) return ASE_NULL; - - ase_memset (mem, 0, ASE_SIZEOF(ase_lsp_mem_t)); - mem->lsp = lsp; - - /* create a new root environment frame */ - mem->frame = ase_lsp_newframe (lsp); - if (mem->frame == ASE_NULL) - { - ASE_LSP_FREE (lsp, mem); - return ASE_NULL; - } - mem->root_frame = mem->frame; - mem->brooding_frame = ASE_NULL; - mem->tlink = ASE_NULL; - mem->tlink_count = 0; - - /* initialize object allocation list */ - mem->ubound = ubound; - mem->ubound_inc = ubound_inc; - mem->count = 0; - for (i = 0; i < ASE_LSP_TYPE_COUNT; i++) - { - mem->used[i] = ASE_NULL; - mem->free[i] = ASE_NULL; - } - mem->read = ASE_NULL; - - /* when "ubound" is too small, the garbage collection can - * be performed while making the common objects. */ - mem->nil = ASE_NULL; - mem->t = ASE_NULL; - mem->quote = ASE_NULL; - mem->lambda = ASE_NULL; - mem->macro = ASE_NULL; - - /* initialize common object pointers */ - mem->nil = ase_lsp_makenil (mem); - mem->t = ase_lsp_maketrue (mem); - mem->quote = ase_lsp_makesym (mem, ASE_T("quote"), 5); - mem->lambda = ase_lsp_makesym (mem, ASE_T("lambda"), 6); - mem->macro = ase_lsp_makesym (mem, ASE_T("macro"), 5); - - if (mem->nil == ASE_NULL || - mem->t == ASE_NULL || - mem->quote == ASE_NULL || - mem->lambda == ASE_NULL || - mem->macro == ASE_NULL) - { - ase_lsp_dispose_all (mem); - ase_lsp_freeframe (lsp, mem->frame); - ASE_LSP_FREE (lsp, mem); - return ASE_NULL; - } - - ASE_LSP_PERM(mem->nil) = 1; - ASE_LSP_PERM(mem->t) = 1; - ASE_LSP_PERM(mem->quote) = 1; - ASE_LSP_PERM(mem->lambda) = 1; - ASE_LSP_PERM(mem->macro) = 1; - - return mem; -} - -void ase_lsp_closemem (ase_lsp_mem_t* mem) -{ - /* dispose of the allocated objects */ - ase_lsp_dispose_all (mem); - - /* dispose of environment frames */ - ase_lsp_freeframe (mem->lsp, mem->frame); - - /* free the memory */ - ASE_LSP_FREE (mem->lsp, mem); -} - -ase_lsp_obj_t* ase_lsp_alloc (ase_lsp_mem_t* mem, int type, ase_size_t size) -{ - ase_lsp_obj_t* obj; - -/* TODO: remove the following line... */ -ase_lsp_gc (mem); - - if (mem->count >= mem->ubound) ase_lsp_gc (mem); - if (mem->count >= mem->ubound) - { - mem->ubound += mem->ubound_inc; - if (mem->count >= mem->ubound) return ASE_NULL; - } - - obj = (ase_lsp_obj_t*) ASE_LSP_MALLOC (mem->lsp, size); - if (obj == ASE_NULL) - { - ase_lsp_gc (mem); - - obj = (ase_lsp_obj_t*) ASE_LSP_MALLOC (mem->lsp, size); - if (obj == ASE_NULL) - { - ase_lsp_seterror (mem->lsp, ASE_LSP_ENOMEM, ASE_NULL, 0); - return ASE_NULL; - } - } - - ASE_LSP_TYPE(obj) = type; - ASE_LSP_SIZE(obj) = size; - ASE_LSP_MARK(obj) = 0; - ASE_LSP_PERM(obj) = 0; - ASE_LSP_LOCK(obj) = 0; - - /* insert the object at the head of the used list */ - ASE_LSP_LINK(obj) = mem->used[type]; - mem->used[type] = obj; - mem->count++; - -#if 0 - ase_dprint1 (ASE_T("mem->count: %u\n"), mem->count); -#endif - - return obj; -} - -void ase_lsp_dispose ( - ase_lsp_mem_t* mem, ase_lsp_obj_t* prev, ase_lsp_obj_t* obj) -{ - ASE_ASSERT (obj != ASE_NULL); - ASE_ASSERT (mem->count > 0); - - /* TODO: push the object to the free list for more - * efficient memory management */ - - if (prev == ASE_NULL) - mem->used[ASE_LSP_TYPE(obj)] = ASE_LSP_LINK(obj); - else ASE_LSP_LINK(prev) = ASE_LSP_LINK(obj); - - mem->count--; -#if 0 - ase_dprint1 (ASE_T("mem->count: %u\n"), mem->count); -#endif - - ASE_LSP_FREE (mem->lsp, obj); -} - -void ase_lsp_dispose_all (ase_lsp_mem_t* mem) -{ - ase_lsp_obj_t* obj, * next; - ase_size_t i; - - for (i = 0; i < ASE_LSP_TYPE_COUNT; i++) - { - obj = mem->used[i]; - - while (obj != ASE_NULL) - { - next = ASE_LSP_LINK(obj); - ase_lsp_dispose (mem, ASE_NULL, obj); - obj = next; - } - } -} - -static void __mark_obj (ase_lsp_t* lsp, ase_lsp_obj_t* obj) -{ - ASE_ASSERT (obj != ASE_NULL); - - /* TODO: can it be recursive? */ - if (ASE_LSP_MARK(obj) != 0) return; - - ASE_LSP_MARK(obj) = 1; - - if (ASE_LSP_TYPE(obj) == ASE_LSP_OBJ_CONS) - { - __mark_obj (lsp, ASE_LSP_CAR(obj)); - __mark_obj (lsp, ASE_LSP_CDR(obj)); - } - else if (ASE_LSP_TYPE(obj) == ASE_LSP_OBJ_FUNC) - { - __mark_obj (lsp, ASE_LSP_FFORMAL(obj)); - __mark_obj (lsp, ASE_LSP_FBODY(obj)); - } - else if (ASE_LSP_TYPE(obj) == ASE_LSP_OBJ_MACRO) - { - __mark_obj (lsp, ASE_LSP_MFORMAL(obj)); - __mark_obj (lsp, ASE_LSP_MBODY(obj)); - } -} - -/* - * ase_lsp_lockobj and ase_lsp_deepunlockobj are just called by ase_lsp_read. - */ -void ase_lsp_lockobj (ase_lsp_t* lsp, ase_lsp_obj_t* obj) -{ - ASE_ASSERTX (obj != ASE_NULL, - "an object pointer should not be ASE_NULL"); - if (ASE_LSP_PERM(obj) == 0) ASE_LSP_LOCK(obj)++; -} - -void ase_lsp_unlockobj (ase_lsp_t* lsp, ase_lsp_obj_t* obj) -{ - ASE_ASSERTX (obj != ASE_NULL, - "an object pointer should not be ASE_NULL"); - - if (ASE_LSP_PERM(obj) != 0) return; - ASE_ASSERTX (ASE_LSP_LOCK(obj) > 0, - "the lock count should be greater than zero to be unlocked"); - - ASE_LSP_LOCK(obj)--; -} - -void ase_lsp_deepunlockobj (ase_lsp_t* lsp, ase_lsp_obj_t* obj) -{ - ASE_ASSERTX (obj != ASE_NULL, - "an object pointer should not be ASE_NULL"); - - if (ASE_LSP_PERM(obj) == 0) - { - ASE_ASSERTX (ASE_LSP_LOCK(obj) > 0, - "the lock count should be greater than zero to be unlocked"); - ASE_LSP_LOCK(obj)--; - } - - if (ASE_LSP_TYPE(obj) == ASE_LSP_OBJ_CONS) - { - ase_lsp_deepunlockobj (lsp, ASE_LSP_CAR(obj)); - ase_lsp_deepunlockobj (lsp, ASE_LSP_CDR(obj)); - } - else if (ASE_LSP_TYPE(obj) == ASE_LSP_OBJ_FUNC) - { - ase_lsp_deepunlockobj (lsp, ASE_LSP_FFORMAL(obj)); - ase_lsp_deepunlockobj (lsp, ASE_LSP_FBODY(obj)); - } - else if (ASE_LSP_TYPE(obj) == ASE_LSP_OBJ_MACRO) - { - ase_lsp_deepunlockobj (lsp, ASE_LSP_MFORMAL(obj)); - ase_lsp_deepunlockobj (lsp, ASE_LSP_MBODY(obj)); - } -} - -static void __mark_objs_in_use (ase_lsp_mem_t* mem) -{ - ase_lsp_frame_t* frame; - ase_lsp_assoc_t* assoc; - ase_lsp_tlink_t* tlink; - /*ase_lsp_arr_t* arr;*/ - /*ase_size_t i;*/ - -#if 0 - ase_dprint0 (ASE_T("marking environment frames\n")); -#endif - /* mark objects in the environment frames */ - frame = mem->frame; - while (frame != ASE_NULL) - { - assoc = frame->assoc; - while (assoc != ASE_NULL) - { - __mark_obj (mem->lsp, assoc->name); - - if (assoc->value != ASE_NULL) - __mark_obj (mem->lsp, assoc->value); - if (assoc->func != ASE_NULL) - __mark_obj (mem->lsp, assoc->func); - - assoc = assoc->link; - } - - frame = frame->link; - } - -#if 0 - ase_dprint0 (ASE_T("marking interim frames\n")); -#endif - - /* mark objects in the interim frames */ - frame = mem->brooding_frame; - while (frame != ASE_NULL) - { - assoc = frame->assoc; - while (assoc != ASE_NULL) - { - __mark_obj (mem->lsp, assoc->name); - - if (assoc->value != ASE_NULL) - __mark_obj (mem->lsp, assoc->value); - if (assoc->func != ASE_NULL) - __mark_obj (mem->lsp, assoc->func); - - assoc = assoc->link; - } - - frame = frame->link; - } - - /* ase_dprint0 (ASE_T("marking the read object\n"));*/ - if (mem->read != ASE_NULL) __mark_obj (mem->lsp, mem->read); - - /* ase_dprint0 (ASE_T("marking the temporary objects\n"));*/ - for (tlink = mem->tlink; tlink != ASE_NULL; tlink = tlink->link) - { - __mark_obj (mem->lsp, tlink->obj); - } - -#if 0 - ase_dprint0 (ASE_T("marking builtin objects\n")); -#endif - /* mark common objects */ - if (mem->t != ASE_NULL) __mark_obj (mem->lsp, mem->t); - if (mem->nil != ASE_NULL) __mark_obj (mem->lsp, mem->nil); - if (mem->quote != ASE_NULL) __mark_obj (mem->lsp, mem->quote); - if (mem->lambda != ASE_NULL) __mark_obj (mem->lsp, mem->lambda); - if (mem->macro != ASE_NULL) __mark_obj (mem->lsp, mem->macro); -} - -#include -static void __sweep_unmarked_objs (ase_lsp_mem_t* mem) -{ - ase_lsp_obj_t* obj, * prev, * next; - ase_size_t i; - - /* scan all the allocated objects and get rid of unused objects */ - for (i = 0; i < ASE_LSP_TYPE_COUNT; i++) - { - prev = ASE_NULL; - obj = mem->used[i]; - -#if 0 - ase_dprint1 (ASE_T("sweeping objects of type: %u\n"), i); -#endif - while (obj != ASE_NULL) - { - next = ASE_LSP_LINK(obj); - - if (ASE_LSP_LOCK(obj) == 0 && - ASE_LSP_MARK(obj) == 0 && - ASE_LSP_PERM(obj) == 0) - { - /* dispose of unused objects */ -if (i == ASE_LSP_OBJ_INT) -ase_printf (ASE_T("disposing....%d [%d]\n"), i, (int)ASE_LSP_IVAL(obj)); -if (i == ASE_LSP_OBJ_REAL) -ase_printf (ASE_T("disposing....%d [%Lf]\n"), i, (double)ASE_LSP_RVAL(obj)); -else if (i == ASE_LSP_OBJ_SYM) -ase_printf (ASE_T("disposing....%d [%s]\n"), i, ASE_LSP_SYMPTR(obj)); -else if (i == ASE_LSP_OBJ_STR) -ase_printf (ASE_T("disposing....%d [%s]\n"), i, ASE_LSP_STRPTR(obj)); -else -ase_printf (ASE_T("disposing....%d\n"), i); - ase_lsp_dispose (mem, prev, obj); - } - else - { - /* unmark the object in use */ - ASE_LSP_MARK(obj) = 0; - prev = obj; - } - - obj = next; - } - } -} - -void ase_lsp_gc (ase_lsp_mem_t* mem) -{ - __mark_objs_in_use (mem); - __sweep_unmarked_objs (mem); -} - -ase_lsp_obj_t* ase_lsp_makenil (ase_lsp_mem_t* mem) -{ - if (mem->nil != ASE_NULL) return mem->nil; - mem->nil = ase_lsp_alloc ( - mem, ASE_LSP_OBJ_NIL, ASE_SIZEOF(ase_lsp_obj_nil_t)); - return mem->nil; -} - -ase_lsp_obj_t* ase_lsp_maketrue (ase_lsp_mem_t* mem) -{ - if (mem->t != ASE_NULL) return mem->t; - mem->t = ase_lsp_alloc ( - mem, ASE_LSP_OBJ_TRUE, ASE_SIZEOF(ase_lsp_obj_true_t)); - return mem->t; -} - -ase_lsp_obj_t* ase_lsp_makeintobj (ase_lsp_mem_t* mem, ase_long_t value) -{ - ase_lsp_obj_t* obj; - - obj = ase_lsp_alloc (mem, - ASE_LSP_OBJ_INT, ASE_SIZEOF(ase_lsp_obj_int_t)); - if (obj == ASE_NULL) return ASE_NULL; - - ASE_LSP_IVAL(obj) = value; - - return obj; -} - -ase_lsp_obj_t* ase_lsp_makerealobj (ase_lsp_mem_t* mem, ase_real_t value) -{ - ase_lsp_obj_t* obj; - - obj = ase_lsp_alloc (mem, - ASE_LSP_OBJ_REAL, ASE_SIZEOF(ase_lsp_obj_real_t)); - if (obj == ASE_NULL) return ASE_NULL; - - ASE_LSP_RVAL(obj) = value; - - return obj; -} - -ase_lsp_obj_t* ase_lsp_makesym ( - ase_lsp_mem_t* mem, const ase_char_t* str, ase_size_t len) -{ - ase_lsp_obj_t* obj; - - /* look for a sysmbol with the given name */ - obj = mem->used[ASE_LSP_OBJ_SYM]; - while (obj != ASE_NULL) - { - /* if there is a symbol with the same name, it is just used. */ - if (ase_strxncmp ( - ASE_LSP_SYMPTR(obj), - ASE_LSP_SYMLEN(obj), - str, len) == 0) return obj; - obj = ASE_LSP_LINK(obj); - } - - /* no such symbol found. create a new one */ - obj = ase_lsp_alloc (mem, ASE_LSP_OBJ_SYM, - ASE_SIZEOF(ase_lsp_obj_sym_t)+(len + 1)*ASE_SIZEOF(ase_char_t)); - if (obj == ASE_NULL) return ASE_NULL; - - /* fill in the symbol buffer */ - ase_strncpy (ASE_LSP_SYMPTR(obj), str, len); - - return obj; -} - -ase_lsp_obj_t* ase_lsp_makestr ( - ase_lsp_mem_t* mem, const ase_char_t* str, ase_size_t len) -{ - ase_lsp_obj_t* obj; - - /* allocate memory for the string */ - obj = ase_lsp_alloc (mem, ASE_LSP_OBJ_STR, - ASE_SIZEOF(ase_lsp_obj_str_t)+(len + 1)*ASE_SIZEOF(ase_char_t)); - if (obj == ASE_NULL) return ASE_NULL; - - /* fill in the string buffer */ - ase_strncpy (ASE_LSP_STRPTR(obj), str, len); - - return obj; -} - -ase_lsp_obj_t* ase_lsp_makecons ( - ase_lsp_mem_t* mem, ase_lsp_obj_t* car, ase_lsp_obj_t* cdr) -{ - ase_lsp_obj_t* obj; - - obj = ase_lsp_alloc (mem, - ASE_LSP_OBJ_CONS, ASE_SIZEOF(ase_lsp_obj_cons_t)); - if (obj == ASE_NULL) return ASE_NULL; - - ASE_LSP_CAR(obj) = car; - ASE_LSP_CDR(obj) = cdr; - - return obj; -} - -ase_lsp_obj_t* ase_lsp_makefunc ( - ase_lsp_mem_t* mem, ase_lsp_obj_t* formal, ase_lsp_obj_t* body) -{ - ase_lsp_obj_t* obj; - - obj = ase_lsp_alloc (mem, - ASE_LSP_OBJ_FUNC, ASE_SIZEOF(ase_lsp_obj_func_t)); - if (obj == ASE_NULL) return ASE_NULL; - - ASE_LSP_FFORMAL(obj) = formal; - ASE_LSP_FBODY(obj) = body; - - return obj; -} - -ase_lsp_obj_t* ase_lsp_makemacro ( - ase_lsp_mem_t* mem, ase_lsp_obj_t* formal, ase_lsp_obj_t* body) -{ - ase_lsp_obj_t* obj; - - obj = ase_lsp_alloc (mem, - ASE_LSP_OBJ_MACRO, ASE_SIZEOF(ase_lsp_obj_macro_t)); - if (obj == ASE_NULL) return ASE_NULL; - - ASE_LSP_MFORMAL(obj) = formal; - ASE_LSP_MBODY(obj) = body; - - return obj; -} - -ase_lsp_obj_t* ase_lsp_makeprim (ase_lsp_mem_t* mem, - ase_lsp_prim_t impl, ase_size_t min_args, ase_size_t max_args) -{ - ase_lsp_obj_t* obj; - - obj = ase_lsp_alloc ( - mem, ASE_LSP_OBJ_PRIM, ASE_SIZEOF(ase_lsp_obj_prim_t)); - if (obj == ASE_NULL) return ASE_NULL; - - ASE_LSP_PIMPL(obj) = impl; - ASE_LSP_PMINARGS(obj) = min_args; - ASE_LSP_PMAXARGS(obj) = max_args; - return obj; -} - -ase_lsp_assoc_t* ase_lsp_lookup (ase_lsp_mem_t* mem, ase_lsp_obj_t* name) -{ - ase_lsp_frame_t* frame; - ase_lsp_assoc_t* assoc; - - ASE_ASSERT (ASE_LSP_TYPE(name) == ASE_LSP_OBJ_SYM); - - frame = mem->frame; - - while (frame != ASE_NULL) - { - assoc = ase_lsp_lookupinframe (mem->lsp, frame, name); - if (assoc != ASE_NULL) return assoc; - frame = frame->link; - } - - return ASE_NULL; -} - -ase_lsp_assoc_t* ase_lsp_setvalue ( - ase_lsp_mem_t* mem, ase_lsp_obj_t* name, ase_lsp_obj_t* value) -{ - ase_lsp_assoc_t* assoc; - - assoc = ase_lsp_lookup (mem, name); - if (assoc == ASE_NULL) - { - assoc = ase_lsp_insvalueintoframe ( - mem->lsp, mem->root_frame, name, value); - if (assoc == ASE_NULL) return ASE_NULL; - } - else assoc->value = value; - - return assoc; -} - -ase_lsp_assoc_t* ase_lsp_setfunc ( - ase_lsp_mem_t* mem, ase_lsp_obj_t* name, ase_lsp_obj_t* func) -{ - ase_lsp_assoc_t* assoc; - - assoc = ase_lsp_lookup (mem, name); - if (assoc == ASE_NULL) - { - assoc = ase_lsp_insfuncintoframe ( - mem->lsp, mem->root_frame, name, func); - if (assoc == ASE_NULL) return ASE_NULL; - } - else assoc->func = func; - - return assoc; -} - -ase_size_t ase_lsp_conslen (ase_lsp_mem_t* mem, ase_lsp_obj_t* obj) -{ - ase_size_t count; - - ASE_ASSERT ( - obj == mem->nil || ASE_LSP_TYPE(obj) == ASE_LSP_OBJ_CONS); - - count = 0; - /*while (obj != mem->nil) {*/ - while (ASE_LSP_TYPE(obj) == ASE_LSP_OBJ_CONS) - { - count++; - obj = ASE_LSP_CDR(obj); - } - - return count; -} - - - diff --git a/ase/lsp/mem.h b/ase/lsp/mem.h deleted file mode 100644 index 5feaa347..00000000 --- a/ase/lsp/mem.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * $Id: mem.h,v 1.1.1.1 2007/03/28 14:05:24 bacon Exp $ - * - * {License} - */ - -#ifndef _ASE_LSP_MEM_H_ -#define _ASE_LSP_MEM_H_ - -#ifndef _ASE_LSP_LSP_H_ -#error Never include this file directly. Include instead -#endif - -typedef struct ase_lsp_mem_t ase_lsp_mem_t; - -struct ase_lsp_mem_t -{ - ase_lsp_t* lsp; - - /* object allocation list */ - ase_size_t ubound; /* upper bounds of the maximum number of objects */ - ase_size_t ubound_inc; /* increment of the upper bounds */ - ase_size_t count; /* the number of objects currently allocated */ - ase_lsp_obj_t* used[ASE_LSP_TYPE_COUNT]; - ase_lsp_obj_t* free[ASE_LSP_TYPE_COUNT]; - ase_lsp_obj_t* read; - - /* commonly accessed objects */ - ase_lsp_obj_t* nil; /* ase_lsp_obj_nil_t */ - ase_lsp_obj_t* t; /* ase_lsp_obj_true_t */ - ase_lsp_obj_t* quote; /* ase_lsp_obj_sym_t */ - ase_lsp_obj_t* lambda; /* ase_lsp_obj_sym_t */ - ase_lsp_obj_t* macro; /* ase_lsp_obj_sym_t */ - - /* run-time environment frame */ - ase_lsp_frame_t* frame; - /* pointer to a global-level frame */ - ase_lsp_frame_t* root_frame; - /* pointer to an interim frame not yet added to "frame" */ - ase_lsp_frame_t* brooding_frame; - - /* links for temporary objects */ - ase_lsp_tlink_t* tlink; - ase_size_t tlink_count; -}; - -#ifdef __cplusplus -extern "C" { -#endif - -ase_lsp_mem_t* ase_lsp_openmem ( - ase_lsp_t* lsp, ase_size_t ubound, ase_size_t ubound_inc); -void ase_lsp_closemem (ase_lsp_mem_t* mem); - -ase_lsp_obj_t* ase_lsp_alloc (ase_lsp_mem_t* mem, int type, ase_size_t size); -void ase_lsp_dispose (ase_lsp_mem_t* mem, ase_lsp_obj_t* prev, ase_lsp_obj_t* obj); -void ase_lsp_dispose_all (ase_lsp_mem_t* mem); -void ase_lsp_gc (ase_lsp_mem_t* mem); - -void ase_lsp_lockobj (ase_lsp_t* lsp, ase_lsp_obj_t* obj); -void ase_lsp_unlockobj (ase_lsp_t* lsp, ase_lsp_obj_t* obj); -void ase_lsp_deepunlockobj (ase_lsp_t* lsp, ase_lsp_obj_t* obj); - -/* object creation of standard types */ -ase_lsp_obj_t* ase_lsp_makenil (ase_lsp_mem_t* mem); -ase_lsp_obj_t* ase_lsp_maketrue (ase_lsp_mem_t* mem); -ase_lsp_obj_t* ase_lsp_makeintobj (ase_lsp_mem_t* mem, ase_long_t value); -ase_lsp_obj_t* ase_lsp_makerealobj (ase_lsp_mem_t* mem, ase_real_t value); - -ase_lsp_obj_t* ase_lsp_makesym ( - ase_lsp_mem_t* mem, const ase_char_t* str, ase_size_t len); -ase_lsp_obj_t* ase_lsp_makestr ( - ase_lsp_mem_t* mem, const ase_char_t* str, ase_size_t len); - -ase_lsp_obj_t* ase_lsp_makecons ( - ase_lsp_mem_t* mem, ase_lsp_obj_t* car, ase_lsp_obj_t* cdr); -ase_lsp_obj_t* ase_lsp_makefunc ( - ase_lsp_mem_t* mem, ase_lsp_obj_t* formal, ase_lsp_obj_t* body); -ase_lsp_obj_t* ase_lsp_makemacro ( - ase_lsp_mem_t* mem, ase_lsp_obj_t* formal, ase_lsp_obj_t* body); - -ase_lsp_obj_t* ase_lsp_makeprim (ase_lsp_mem_t* mem, - ase_lsp_prim_t impl, ase_size_t min_args, ase_size_t max_args); - -/* frame lookup */ -ase_lsp_assoc_t* ase_lsp_lookup (ase_lsp_mem_t* mem, ase_lsp_obj_t* name); -ase_lsp_assoc_t* ase_lsp_setvalue ( - ase_lsp_mem_t* mem, ase_lsp_obj_t* name, ase_lsp_obj_t* value); -ase_lsp_assoc_t* ase_lsp_setfunc ( - ase_lsp_mem_t* mem, ase_lsp_obj_t* name, ase_lsp_obj_t* func); - -/* cons operations */ -ase_size_t ase_lsp_conslen (ase_lsp_mem_t* mem, ase_lsp_obj_t* obj); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ase/lsp/misc.c b/ase/lsp/misc.c deleted file mode 100644 index c989b8e6..00000000 --- a/ase/lsp/misc.c +++ /dev/null @@ -1,575 +0,0 @@ -/* - * $Id: misc.c,v 1.1.1.1 2007/03/28 14:05:24 bacon Exp $ - * - * {License} - */ - -#include - -ase_long_t ase_lsp_strxtolong ( - ase_lsp_t* lsp, const ase_char_t* str, ase_size_t len, - int base, const ase_char_t** endptr) -{ - ase_long_t n = 0; - const ase_char_t* p; - const ase_char_t* end; - ase_size_t rem; - int digit, negative = 0; - - ASE_ASSERT (base < 37); - - p = str; - end = str + len; - - /* strip off leading spaces */ - /*while (ASE_LSP_ISSPACE(lsp,*p)) p++;*/ - - /* check for a sign */ - /*while (*p != ASE_T('\0')) */ - while (p < end) - { - if (*p == ASE_T('-')) - { - negative = ~negative; - p++; - } - else if (*p == ASE_T('+')) p++; - else break; - } - - /* check for a binary/octal/hexadecimal notation */ - rem = end - p; - if (base == 0) - { - if (rem >= 1 && *p == ASE_T('0')) - { - p++; - - if (rem == 1) base = 8; - else if (*p == ASE_T('x') || *p == ASE_T('X')) - { - p++; base = 16; - } - else if (*p == ASE_T('b') || *p == ASE_T('B')) - { - p++; base = 2; - } - else base = 8; - } - else base = 10; - } - else if (rem >= 2 && base == 16) - { - if (*p == ASE_T('0') && - (*(p+1) == ASE_T('x') || *(p+1) == ASE_T('X'))) p += 2; - } - else if (rem >= 2 && base == 2) - { - if (*p == ASE_T('0') && - (*(p+1) == ASE_T('b') || *(p+1) == ASE_T('B'))) p += 2; - } - - /* process the digits */ - /*while (*p != ASE_T('\0'))*/ - while (p < end) - { - if (*p >= ASE_T('0') && *p <= ASE_T('9')) - digit = *p - ASE_T('0'); - else if (*p >= ASE_T('A') && *p <= ASE_T('Z')) - digit = *p - ASE_T('A') + 10; - else if (*p >= ASE_T('a') && *p <= ASE_T('z')) - digit = *p - ASE_T('a') + 10; - else break; - - if (digit >= base) break; - n = n * base + digit; - - p++; - } - - if (endptr != ASE_NULL) *endptr = p; - return (negative)? -n: n; -} - - -/* - * ase_lsp_strtoreal is almost a replica of strtod. - * - * strtod.c -- - * - * Source code for the "strtod" library procedure. - * - * Copyright (c) 1988-1993 The Regents of the University of California. - * Copyright (c) 1994 Sun Microsystems, Inc. - * - * Permission to use, copy, modify, and distribute this - * software and its documentation for any purpose and without - * fee is hereby granted, provided that the above copyright - * notice appear in all copies. The University of California - * makes no representations about the suitability of this - * software for any purpose. It is provided "as is" without - * express or implied warranty. - */ - -#define MAX_EXPONENT 511 - -ase_real_t ase_lsp_strtoreal (ase_lsp_t* lsp, const ase_char_t* str) -{ - /* - * Table giving binary powers of 10. Entry is 10^2^i. - * Used to convert decimal exponents into floating-point numbers. - */ - static ase_real_t powers_of_10[] = - { - 10., 100., 1.0e4, 1.0e8, 1.0e16, - 1.0e32, 1.0e64, 1.0e128, 1.0e256 - }; - - ase_real_t fraction, dbl_exp, * d; - const ase_char_t* p; - ase_cint_t c; - int exp = 0; /* Esseonent read from "EX" field */ - - /* - * Esseonent that derives from the fractional part. Under normal - * circumstatnces, it is the negative of the number of digits in F. - * However, if I is very long, the last digits of I get dropped - * (otherwise a long I with a large negative exponent could cause an - * unnecessary overflow on I alone). In this case, frac_exp is - * incremented one for each dropped digit. - */ - - int frac_exp; - int mant_size; /* Number of digits in mantissa. */ - int dec_pt; /* Number of mantissa digits BEFORE decimal point */ - const ase_char_t *pexp; /* Temporarily holds location of exponent in string */ - int negative = 0, exp_negative = 0; - - p = str; - - /* strip off leading blanks */ - /*while (ASE_LSP_ISSPACE(lsp,*p)) p++;*/ - - /* check for a sign */ - while (*p != ASE_T('\0')) - { - if (*p == ASE_T('-')) - { - negative = ~negative; - p++; - } - else if (*p == ASE_T('+')) p++; - else break; - } - - /* Count the number of digits in the mantissa (including the decimal - * point), and also locate the decimal point. */ - dec_pt = -1; - for (mant_size = 0; ; mant_size++) - { - c = *p; - if (!ASE_LSP_ISDIGIT (lsp, c)) - { - if ((c != ASE_T('.')) || (dec_pt >= 0)) break; - dec_pt = mant_size; - } - p++; - } - - /* - * Now suck up the digits in the mantissa. Use two integers to - * collect 9 digits each (this is faster than using floating-point). - * If the mantissa has more than 18 digits, ignore the extras, since - * they can't affect the value anyway. - */ - pexp = p; - p -= mant_size; - if (dec_pt < 0) - { - dec_pt = mant_size; - } - else - { - mant_size--; /* One of the digits was the point */ - } - - if (mant_size > 18) - { - frac_exp = dec_pt - 18; - mant_size = 18; - } - else - { - frac_exp = dec_pt - mant_size; - } - - if (mant_size == 0) - { - fraction = 0.0; - /*p = str;*/ - p = pexp; - goto done; - } - else - { - int frac1, frac2; - frac1 = 0; - for ( ; mant_size > 9; mant_size--) - { - c = *p; - p++; - if (c == ASE_T('.')) - { - c = *p; - p++; - } - frac1 = 10 * frac1 + (c - ASE_T('0')); - } - frac2 = 0; - for (; mant_size > 0; mant_size--) { - c = *p; - p++; - if (c == ASE_T('.')) - { - c = *p; - p++; - } - frac2 = 10*frac2 + (c - ASE_T('0')); - } - fraction = (1.0e9 * frac1) + frac2; - } - - /* Skim off the exponent */ - p = pexp; - if ((*p == ASE_T('E')) || (*p == ASE_T('e'))) - { - p++; - if (*p == ASE_T('-')) - { - exp_negative = 1; - p++; - } - else - { - if (*p == ASE_T('+')) p++; - exp_negative = 0; - } - if (!ASE_LSP_ISDIGIT (lsp, *p)) - { - /* p = pexp; */ - /* goto done; */ - goto no_exp; - } - while (ASE_LSP_ISDIGIT (lsp, *p)) - { - exp = exp * 10 + (*p - ASE_T('0')); - p++; - } - } - -no_exp: - if (exp_negative) exp = frac_exp - exp; - else exp = frac_exp + exp; - - /* - * Generate a floating-point number that represents the exponent. - * Do this by processing the exponent one bit at a time to combine - * many powers of 2 of 10. Then combine the exponent with the - * fraction. - */ - if (exp < 0) - { - exp_negative = 1; - exp = -exp; - } - else exp_negative = 0; - - if (exp > MAX_EXPONENT) exp = MAX_EXPONENT; - - dbl_exp = 1.0; - - for (d = powers_of_10; exp != 0; exp >>= 1, d++) - { - if (exp & 01) dbl_exp *= *d; - } - - if (exp_negative) fraction /= dbl_exp; - else fraction *= dbl_exp; - -done: - return (negative)? -fraction: fraction; -} - -ase_real_t ase_lsp_strxtoreal ( - ase_lsp_t* lsp, const ase_char_t* str, ase_size_t len, - const ase_char_t** endptr) -{ - /* - * Table giving binary powers of 10. Entry is 10^2^i. - * Used to convert decimal exponents into floating-point numbers. - */ - static ase_real_t powers_of_10[] = - { - 10., 100., 1.0e4, 1.0e8, 1.0e16, - 1.0e32, 1.0e64, 1.0e128, 1.0e256 - }; - - ase_real_t fraction, dbl_exp, * d; - const ase_char_t* p, * end; - ase_cint_t c; - int exp = 0; /* Esseonent read from "EX" field */ - - /* - * Esseonent that derives from the fractional part. Under normal - * circumstatnces, it is the negative of the number of digits in F. - * However, if I is very long, the last digits of I get dropped - * (otherwise a long I with a large negative exponent could cause an - * unnecessary overflow on I alone). In this case, frac_exp is - * incremented one for each dropped digit. - */ - - int frac_exp; - int mant_size; /* Number of digits in mantissa. */ - int dec_pt; /* Number of mantissa digits BEFORE decimal point */ - const ase_char_t *pexp; /* Temporarily holds location of exponent in string */ - int negative = 0, exp_negative = 0; - - p = str; - end = str + len; - - /* Strip off leading blanks and check for a sign */ - /*while (ASE_LSP_ISSPACE(lsp,*p)) p++;*/ - - /*while (*p != ASE_T('\0')) */ - while (p < end) - { - if (*p == ASE_T('-')) - { - negative = ~negative; - p++; - } - else if (*p == ASE_T('+')) p++; - else break; - } - - /* Count the number of digits in the mantissa (including the decimal - * point), and also locate the decimal point. */ - dec_pt = -1; - /*for (mant_size = 0; ; mant_size++) */ - for (mant_size = 0; p < end; mant_size++) - { - c = *p; - if (!ASE_LSP_ISDIGIT (lsp, c)) - { - if (c != ASE_T('.') || dec_pt >= 0) break; - dec_pt = mant_size; - } - p++; - } - - /* - * Now suck up the digits in the mantissa. Use two integers to - * collect 9 digits each (this is faster than using floating-point). - * If the mantissa has more than 18 digits, ignore the extras, since - * they can't affect the value anyway. - */ - pexp = p; - p -= mant_size; - if (dec_pt < 0) - { - dec_pt = mant_size; - } - else - { - mant_size--; /* One of the digits was the point */ - } - - if (mant_size > 18) /* TODO: is 18 correct for ase_real_t??? */ - { - frac_exp = dec_pt - 18; - mant_size = 18; - } - else - { - frac_exp = dec_pt - mant_size; - } - - if (mant_size == 0) - { - fraction = 0.0; - /*p = str;*/ - p = pexp; - goto done; - } - else - { - int frac1, frac2; - - frac1 = 0; - for ( ; mant_size > 9; mant_size--) - { - c = *p; - p++; - if (c == ASE_T('.')) - { - c = *p; - p++; - } - frac1 = 10 * frac1 + (c - ASE_T('0')); - } - - frac2 = 0; - for (; mant_size > 0; mant_size--) { - c = *p++; - if (c == ASE_T('.')) - { - c = *p; - p++; - } - frac2 = 10 * frac2 + (c - ASE_T('0')); - } - fraction = (1.0e9 * frac1) + frac2; - } - - /* Skim off the exponent */ - p = pexp; - if (p < end && (*p == ASE_T('E') || *p == ASE_T('e'))) - { - p++; - - if (p < end) - { - if (*p == ASE_T('-')) - { - exp_negative = 1; - p++; - } - else - { - if (*p == ASE_T('+')) p++; - exp_negative = 0; - } - } - else exp_negative = 0; - - if (!(p < end && ASE_LSP_ISDIGIT (lsp, *p))) - { - /*p = pexp;*/ - /*goto done;*/ - goto no_exp; - } - - while (p < end && ASE_LSP_ISDIGIT (lsp, *p)) - { - exp = exp * 10 + (*p - ASE_T('0')); - p++; - } - } - -no_exp: - if (exp_negative) exp = frac_exp - exp; - else exp = frac_exp + exp; - - /* - * Generate a floating-point number that represents the exponent. - * Do this by processing the exponent one bit at a time to combine - * many powers of 2 of 10. Then combine the exponent with the - * fraction. - */ - if (exp < 0) - { - exp_negative = 1; - exp = -exp; - } - else exp_negative = 0; - - if (exp > MAX_EXPONENT) exp = MAX_EXPONENT; - - dbl_exp = 1.0; - - for (d = powers_of_10; exp != 0; exp >>= 1, d++) - { - if (exp & 01) dbl_exp *= *d; - } - - if (exp_negative) fraction /= dbl_exp; - else fraction *= dbl_exp; - -done: - if (endptr != ASE_NULL) *endptr = p; - return (negative)? -fraction: fraction; -} - -ase_size_t ase_lsp_longtostr ( - ase_long_t value, int radix, const ase_char_t* prefix, - ase_char_t* buf, ase_size_t size) -{ - ase_long_t t, rem; - ase_size_t len, ret, i; - ase_size_t prefix_len; - - prefix_len = (prefix != ASE_NULL)? ase_strlen(prefix): 0; - - t = value; - if (t == 0) - { - /* zero */ - if (buf == ASE_NULL) return prefix_len + 1; - - if (size < prefix_len+1) - { - /* buffer too small */ - return (ase_size_t)-1; - } - - for (i = 0; i < prefix_len; i++) buf[i] = prefix[i]; - buf[prefix_len] = ASE_T('0'); - if (size > prefix_len+1) buf[prefix_len+1] = ASE_T('\0'); - return 1; - } - - /* non-zero values */ - len = prefix_len; - if (t < 0) { t = -t; len++; } - while (t > 0) { len++; t /= radix; } - - if (buf == ASE_NULL) - { - /* if buf is not given, return the number of bytes required */ - return len; - } - - if (size < len) return (ase_size_t)-1; /* buffer too small */ - if (size > len) buf[len] = ASE_T('\0'); - ret = len; - - t = value; - if (t < 0) t = -t; - - while (t > 0) - { - rem = t % radix; - if (rem >= 10) - buf[--len] = (ase_char_t)rem + ASE_T('a') - 10; - else - buf[--len] = (ase_char_t)rem + ASE_T('0'); - t /= radix; - } - - if (value < 0) - { - for (i = 1; i <= prefix_len; i++) - { - buf[i] = prefix[i-1]; - len--; - } - buf[--len] = ASE_T('-'); - } - else - { - for (i = 0; i < prefix_len; i++) buf[i] = prefix[i]; - } - - return ret; -} - diff --git a/ase/lsp/misc.h b/ase/lsp/misc.h deleted file mode 100644 index adc6817b..00000000 --- a/ase/lsp/misc.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * $Id: misc.h,v 1.1.1.1 2007/03/28 14:05:24 bacon Exp $ - * - * {License} - */ - -#ifndef _ASE_LSP_MISC_H_ -#define _ASE_LSP_MISC_H_ - -#ifndef _ASE_LSP_LSP_H_ -#error Never include this file directly. Include instead -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -void* ase_lsp_memcpy (void* dst, const void* src, ase_size_t n); -void* ase_lsp_memset (void* dst, int val, ase_size_t n); - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/ase/lsp/name.c b/ase/lsp/name.c deleted file mode 100644 index bef563f5..00000000 --- a/ase/lsp/name.c +++ /dev/null @@ -1,125 +0,0 @@ -/* - * $Id: name.c,v 1.1.1.1 2007/03/28 14:05:24 bacon Exp $ - * - * {License} - */ - -#include - -ase_lsp_name_t* ase_lsp_name_open ( - ase_lsp_name_t* name, ase_size_t capa, ase_lsp_t* lsp) -{ - if (capa == 0) capa = ASE_COUNTOF(name->static_buf) - 1; - - if (name == ASE_NULL) - { - name = (ase_lsp_name_t*) - ASE_LSP_MALLOC (lsp, ASE_SIZEOF(ase_lsp_name_t)); - if (name == ASE_NULL) return ASE_NULL; - name->__dynamic = ase_true; - } - else name->__dynamic = ase_false; - - if (capa < ASE_COUNTOF(name->static_buf)) - { - name->buf = name->static_buf; - } - else - { - name->buf = (ase_char_t*) - ASE_LSP_MALLOC (lsp, (capa+1)*ASE_SIZEOF(ase_char_t)); - if (name->buf == ASE_NULL) - { - if (name->__dynamic) ASE_LSP_FREE (lsp, name); - return ASE_NULL; - } - } - - name->size = 0; - name->capa = capa; - name->buf[0] = ASE_T('\0'); - name->lsp = lsp; - - return name; -} - -void ase_lsp_name_close (ase_lsp_name_t* name) -{ - if (name->capa >= ASE_COUNTOF(name->static_buf)) - { - ASE_ASSERT (name->buf != name->static_buf); - ASE_LSP_FREE (name->lsp, name->buf); - } - if (name->__dynamic) ASE_LSP_FREE (name->lsp, name); -} - -int ase_lsp_name_addc (ase_lsp_name_t* name, ase_cint_t c) -{ - if (name->size >= name->capa) - { - /* double the capacity */ - ase_size_t new_capa = name->capa * 2; - - if (new_capa >= ASE_COUNTOF(name->static_buf)) - { - ase_char_t* space; - - if (name->capa < ASE_COUNTOF(name->static_buf)) - { - space = (ase_char_t*) ASE_LSP_MALLOC ( - name->lsp, (new_capa+1)*ASE_SIZEOF(ase_char_t)); - if (space == ASE_NULL) return -1; - - /* don't need to copy up to the terminating null */ - ase_memcpy (space, name->buf, name->capa*ASE_SIZEOF(ase_char_t)); - } - else - { - space = (ase_char_t*) ASE_LSP_REALLOC ( - name->lsp, name->buf, - (new_capa+1)*ASE_SIZEOF(ase_char_t)); - if (space == ASE_NULL) return -1; - } - - name->buf = space; - } - - name->capa = new_capa; - } - - name->buf[name->size++] = c; - name->buf[name->size] = ASE_T('\0'); - return 0; -} - -int ase_lsp_name_adds (ase_lsp_name_t* name, const ase_char_t* s) -{ - while (*s != ASE_T('\0')) - { - if (ase_lsp_name_addc(name, *s) == -1) return -1; - s++; - } - - return 0; -} - -void ase_lsp_name_clear (ase_lsp_name_t* name) -{ - name->size = 0; - name->buf[0] = ASE_T('\0'); -} - -int ase_lsp_name_compare (ase_lsp_name_t* name, const ase_char_t* str) -{ - ase_char_t* p = name->buf; - ase_size_t index = 0; - - while (index < name->size) - { - if (*p > *str) return 1; - if (*p < *str) return -1; - index++; p++; str++; - } - - return (*str == ASE_T('\0'))? 0: -1; -} diff --git a/ase/lsp/name.h b/ase/lsp/name.h deleted file mode 100644 index e0b55c86..00000000 --- a/ase/lsp/name.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * $Id: name.h,v 1.1.1.1 2007/03/28 14:05:24 bacon Exp $ - * - * {License} - */ - -#ifndef _ASE_LSP_NAME_H_ -#define _ASE_LSP_NAME_H_ - -#include -#include - -struct ase_lsp_name_t -{ - ase_size_t capa; - ase_size_t size; - ase_char_t* buf; - ase_char_t static_buf[128]; - ase_lsp_t* lsp; - ase_bool_t __dynamic; -}; - -typedef struct ase_lsp_name_t ase_lsp_name_t; - -#ifdef __cplusplus -extern "C" { -#endif - -ase_lsp_name_t* ase_lsp_name_open ( - ase_lsp_name_t* name, ase_size_t capa, ase_lsp_t* lsp); -void ase_lsp_name_close (ase_lsp_name_t* name); - -int ase_lsp_name_addc (ase_lsp_name_t* name, ase_cint_t c); -int ase_lsp_name_adds (ase_lsp_name_t* name, const ase_char_t* s); -void ase_lsp_name_clear (ase_lsp_name_t* name); -int ase_lsp_name_compare (ase_lsp_name_t* name, const ase_char_t* str); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ase/lsp/obj.h b/ase/lsp/obj.h deleted file mode 100644 index e1375e98..00000000 --- a/ase/lsp/obj.h +++ /dev/null @@ -1,161 +0,0 @@ -/* - * $Id: obj.h,v 1.1.1.1 2007/03/28 14:05:24 bacon Exp $ - * - * {License} - */ - -#ifndef _ASE_LSP_OBJ_H_ -#define _ASE_LSP_OBJ_H_ - -#ifndef _ASE_LSP_LSP_H_ -#error Never include this file directly. Include instead -#endif - -/* object types */ -enum -{ - ASE_LSP_OBJ_NIL = 0, - ASE_LSP_OBJ_TRUE, - ASE_LSP_OBJ_INT, - ASE_LSP_OBJ_REAL, - ASE_LSP_OBJ_SYM, - ASE_LSP_OBJ_STR, - ASE_LSP_OBJ_CONS, - ASE_LSP_OBJ_FUNC, - ASE_LSP_OBJ_MACRO, - ASE_LSP_OBJ_PRIM, - - ASE_LSP_TYPE_COUNT /* the number of lsp object types */ -}; - -typedef struct ase_lsp_objhdr_t ase_lsp_objhdr_t; -typedef struct ase_lsp_obj_nil_t ase_lsp_obj_nil_t; -typedef struct ase_lsp_obj_true_t ase_lsp_obj_true_t; -typedef struct ase_lsp_obj_int_t ase_lsp_obj_int_t; -typedef struct ase_lsp_obj_real_t ase_lsp_obj_real_t; -typedef struct ase_lsp_obj_sym_t ase_lsp_obj_sym_t; -typedef struct ase_lsp_obj_str_t ase_lsp_obj_str_t; -typedef struct ase_lsp_obj_cons_t ase_lsp_obj_cons_t; -typedef struct ase_lsp_obj_func_t ase_lsp_obj_func_t; -typedef struct ase_lsp_obj_macro_t ase_lsp_obj_macro_t; -typedef struct ase_lsp_obj_prim_t ase_lsp_obj_prim_t; - -struct ase_lsp_objhdr_t -{ - ase_uint32_t type: 8; - ase_uint32_t mark: 4; - ase_uint32_t perm: 4; - ase_uint32_t lock: 16; - ase_size_t size; - ase_lsp_obj_t* link; -}; - -struct ase_lsp_obj_t -{ - ase_lsp_objhdr_t hdr; -}; - -struct ase_lsp_obj_nil_t -{ - ase_lsp_objhdr_t hdr; -}; - -struct ase_lsp_obj_true_t -{ - ase_lsp_objhdr_t hdr; -}; - -struct ase_lsp_obj_int_t -{ - ase_lsp_objhdr_t hdr; - ase_long_t value; -}; - -struct ase_lsp_obj_real_t -{ - ase_lsp_objhdr_t hdr; - ase_real_t value; -}; - -struct ase_lsp_obj_sym_t -{ - ase_lsp_objhdr_t hdr; -#if defined(__GNUC__) - ase_char_t buffer[0]; -#endif -}; - -struct ase_lsp_obj_str_t -{ - ase_lsp_objhdr_t hdr; -#if defined(__GNUC__) - ase_char_t buffer[0]; -#endif -}; - -struct ase_lsp_obj_cons_t -{ - ase_lsp_objhdr_t hdr; - ase_lsp_obj_t* car; - ase_lsp_obj_t* cdr; -}; - -struct ase_lsp_obj_func_t -{ - ase_lsp_objhdr_t hdr; - ase_lsp_obj_t* formal; - ase_lsp_obj_t* body; -}; - -struct ase_lsp_obj_macro_t -{ - ase_lsp_objhdr_t hdr; - ase_lsp_obj_t* formal; - ase_lsp_obj_t* body; -}; - -struct ase_lsp_obj_prim_t -{ - ase_lsp_objhdr_t hdr; - ase_lsp_prim_t impl; - ase_size_t min_args; - ase_size_t max_args; -}; - -/* header access */ -#define ASE_LSP_TYPE(x) (((ase_lsp_obj_t*)x)->hdr.type) -#define ASE_LSP_SIZE(x) (((ase_lsp_obj_t*)x)->hdr.size) -#define ASE_LSP_MARK(x) (((ase_lsp_obj_t*)x)->hdr.mark) -#define ASE_LSP_PERM(x) (((ase_lsp_obj_t*)x)->hdr.perm) -#define ASE_LSP_LOCK(x) (((ase_lsp_obj_t*)x)->hdr.lock) -#define ASE_LSP_LINK(x) (((ase_lsp_obj_t*)x)->hdr.link) - -/* value access */ -#define ASE_LSP_IVAL(x) (((ase_lsp_obj_int_t*)x)->value) -#define ASE_LSP_RVAL(x) (((ase_lsp_obj_real_t*)x)->value) - -#if defined(__GNUC__) - #define ASE_LSP_SYMPTR(x) (((ase_lsp_obj_sym_t*)x)->buffer) -#else - #define ASE_LSP_SYMPTR(x) ((ase_char_t*)(((ase_lsp_obj_sym_t*)x) + 1)) -#endif -#define ASE_LSP_SYMLEN(x) ((((ase_lsp_obj_sym_t*)x)->hdr.size - sizeof(ase_lsp_obj_t)) / sizeof(ase_char_t) - 1) - -#if defined(__GNUC__) - #define ASE_LSP_STRPTR(x) (((ase_lsp_obj_str_t*)x)->buffer) -#else - #define ASE_LSP_STRPTR(x) ((ase_char_t*)(((ase_lsp_obj_str_t*)x) + 1)) -#endif -#define ASE_LSP_STRLEN(x) ((((ase_lsp_obj_str_t*)x)->hdr.size - sizeof(ase_lsp_obj_t)) / sizeof(ase_char_t) - 1) - -#define ASE_LSP_CAR(x) (((ase_lsp_obj_cons_t*)x)->car) -#define ASE_LSP_CDR(x) (((ase_lsp_obj_cons_t*)x)->cdr) -#define ASE_LSP_FFORMAL(x) (((ase_lsp_obj_func_t*)x)->formal) -#define ASE_LSP_FBODY(x) (((ase_lsp_obj_func_t*)x)->body) -#define ASE_LSP_MFORMAL(x) (((ase_lsp_obj_macro_t*)x)->formal) -#define ASE_LSP_MBODY(x) (((ase_lsp_obj_macro_t*)x)->body) -#define ASE_LSP_PIMPL(x) (((ase_lsp_obj_prim_t*)x)->impl) -#define ASE_LSP_PMINARGS(x) (((ase_lsp_obj_prim_t*)x)->min_args) -#define ASE_LSP_PMAXARGS(x) (((ase_lsp_obj_prim_t*)x)->max_args) - -#endif diff --git a/ase/lsp/prim.c b/ase/lsp/prim.c deleted file mode 100644 index addae492..00000000 --- a/ase/lsp/prim.c +++ /dev/null @@ -1,621 +0,0 @@ -/* - * $Id: prim.c,v 1.1.1.1 2007/03/28 14:05:24 bacon Exp $ - * - * {License} - */ - -#include - -static int __add_prim (ase_lsp_mem_t* mem, - const ase_char_t* name, ase_size_t len, - ase_lsp_prim_t pimpl, ase_size_t min_args, ase_size_t max_args); - -int ase_lsp_addprim ( - ase_lsp_t* lsp, const ase_char_t* name, ase_size_t name_len, - ase_lsp_prim_t prim, ase_size_t min_args, ase_size_t max_args) -{ - return __add_prim (lsp->mem, name, name_len, prim, min_args, max_args); -} - -int ase_lsp_removeprim (ase_lsp_t* lsp, const ase_char_t* name) -{ - /* TODO: */ - return -1; -} - -static int __add_prim (ase_lsp_mem_t* mem, - const ase_char_t* name, ase_size_t name_len, - ase_lsp_prim_t pimpl, ase_size_t min_args, ase_size_t max_args) -{ - ase_lsp_obj_t* n, * p; - - n = ase_lsp_makesym (mem, name, name_len); - if (n == ASE_NULL) return -1; - - if (ase_lsp_pushtmp (mem->lsp, n) == ASE_NULL) return -1; - - p = ase_lsp_makeprim (mem, pimpl, min_args, max_args); - if (p == ASE_NULL) - { - ase_lsp_poptmp (mem->lsp); - return -1; - } - - if (ase_lsp_pushtmp (mem->lsp, p) == ASE_NULL) - { - ase_lsp_poptmp (mem->lsp); - return -1; - } - - if (ase_lsp_setfunc(mem, n, p) == ASE_NULL) - { - ase_lsp_poptmp (mem->lsp); - ase_lsp_poptmp (mem->lsp); - return -1; - } - - ase_lsp_poptmp (mem->lsp); - ase_lsp_poptmp (mem->lsp); - return 0; -} - -ase_lsp_obj_t* ase_lsp_prim_exit (ase_lsp_t* lsp, ase_lsp_obj_t* args) -{ - lsp->errnum = ASE_LSP_EEXIT; - return ASE_NULL; -} - -ase_lsp_obj_t* ase_lsp_prim_eval (ase_lsp_t* lsp, ase_lsp_obj_t* args) -{ - ase_lsp_obj_t* tmp1, * tmp2; - - ASE_ASSERT (ASE_LSP_TYPE(args) == ASE_LSP_OBJ_CONS); - - tmp1 = ase_lsp_eval (lsp, ASE_LSP_CAR(args)); - if (tmp1 == ASE_NULL) return ASE_NULL; - - if (ase_lsp_pushtmp (lsp, tmp1) == ASE_NULL) return ASE_NULL; - - tmp2 = ase_lsp_eval (lsp, tmp1); - if (tmp2 == ASE_NULL) - { - ase_lsp_poptmp (lsp); - return ASE_NULL; - } - - ase_lsp_poptmp (lsp); - return tmp2; -} - -ase_lsp_obj_t* ase_lsp_prim_gc (ase_lsp_t* lsp, ase_lsp_obj_t* args) -{ - ase_lsp_gc (lsp->mem); - return lsp->mem->nil; -} - -ase_lsp_obj_t* ase_lsp_prim_cond (ase_lsp_t* lsp, ase_lsp_obj_t* args) -{ - /* - * (cond - * (condition1 result1) - * (consition2 result2) - * ... - * (t resultN)) - */ - - ase_lsp_obj_t* tmp, * ret; - - while (ASE_LSP_TYPE(args) == ASE_LSP_OBJ_CONS) - { - if (ASE_LSP_TYPE(ASE_LSP_CAR(args)) != ASE_LSP_OBJ_CONS) - { - ase_lsp_seterror (lsp, ASE_LSP_EARGBAD, ASE_NULL, 0); - return ASE_NULL; - } - - tmp = ase_lsp_eval (lsp, ASE_LSP_CAR(ASE_LSP_CAR(args))); - if (tmp == ASE_NULL) return ASE_NULL; - - if (ase_lsp_pushtmp (lsp, tmp) == ASE_NULL) return ASE_NULL; - - if (tmp != lsp->mem->nil) - { - int f = 0; - - tmp = ASE_LSP_CDR(ASE_LSP_CAR(args)); - ret = lsp->mem->nil; - - while (ASE_LSP_TYPE(tmp) == ASE_LSP_OBJ_CONS) - { - ret = ase_lsp_eval (lsp, ASE_LSP_CAR(tmp)); - if (ret == ASE_NULL) - { - if (!f) ase_lsp_poptmp (lsp); /* ret */ - ase_lsp_poptmp (lsp); /* tmp */ - return ASE_NULL; - } - - if (!f) ase_lsp_poptmp (lsp); /* ret */ - if (ase_lsp_pushtmp (lsp, ret) == ASE_NULL) - { - ase_lsp_poptmp (lsp); /* tmp */ - return ASE_NULL; - } - - f = 1; - tmp = ASE_LSP_CDR(tmp); - } - if (tmp != lsp->mem->nil) - { - if (!f) ase_lsp_poptmp (lsp); /* ret */ - ase_lsp_poptmp (lsp); /* tmp */ - - ase_lsp_seterror (lsp, ASE_LSP_EARGBAD, ASE_NULL, 0); - return ASE_NULL; - } - - if (!f) ase_lsp_poptmp (lsp); /* ret */ - ase_lsp_poptmp (lsp); /* tmp */ - return ret; - } - - ase_lsp_poptmp (lsp); /* tmp */ - args = ASE_LSP_CDR(args); - } - - return lsp->mem->nil; -} - -ase_lsp_obj_t* ase_lsp_prim_if (ase_lsp_t* lsp, ase_lsp_obj_t* args) -{ - ase_lsp_obj_t* tmp; - - ASE_ASSERT (ASE_LSP_TYPE(args) == ASE_LSP_OBJ_CONS); - - tmp = ase_lsp_eval (lsp, ASE_LSP_CAR(args)); - if (tmp == ASE_NULL) return ASE_NULL; - - if (ase_lsp_pushtmp (lsp, tmp) == ASE_NULL) return ASE_NULL; - - if (tmp != lsp->mem->nil) - { - tmp = ase_lsp_eval (lsp, ASE_LSP_CAR(ASE_LSP_CDR(args))); - if (tmp == ASE_NULL) - { - ase_lsp_poptmp (lsp); /* tmp */ - return ASE_NULL; - } - - ase_lsp_poptmp (lsp); /* tmp */ - return tmp; - } - else - { - ase_lsp_obj_t* res = lsp->mem->nil; - int f = 0; - - tmp = ASE_LSP_CDR(ASE_LSP_CDR(args)); - - while (ASE_LSP_TYPE(tmp) == ASE_LSP_OBJ_CONS) - { - res = ase_lsp_eval (lsp, ASE_LSP_CAR(tmp)); - if (res == ASE_NULL) - { - if (!f) ase_lsp_poptmp (lsp); /* res */ - ase_lsp_poptmp (lsp); /* tmp */ - return ASE_NULL; - } - - if (!f) ase_lsp_poptmp (lsp); /* res */ - if (ase_lsp_pushtmp (lsp, res) == ASE_NULL) - { - ase_lsp_poptmp (lsp); /* tmp */ - return ASE_NULL; - } - - f = 1; - tmp = ASE_LSP_CDR(tmp); - } - - if (tmp != lsp->mem->nil) - { - if (!f) ase_lsp_poptmp (lsp); /* ret */ - ase_lsp_poptmp (lsp); /* tmp */ - - ase_lsp_seterror (lsp, ASE_LSP_EARGBAD, ASE_NULL, 0); - return ASE_NULL; - } - - if (!f) ase_lsp_poptmp (lsp); /* ret */ - ase_lsp_poptmp (lsp); /* tmp */ - return res; - } -} - -ase_lsp_obj_t* ase_lsp_prim_while (ase_lsp_t* lsp, ase_lsp_obj_t* args) -{ - /* - * (setq a 1) - * (while (< a 100) (setq a (+ a 1))) - */ - - ase_lsp_obj_t* tmp; - - ASE_ASSERT (ASE_LSP_TYPE(args) == ASE_LSP_OBJ_CONS); - - while (1) - { - tmp = ase_lsp_eval (lsp, ASE_LSP_CAR(args)); - if (tmp == ASE_NULL) return ASE_NULL; - if (tmp == lsp->mem->nil) break; - - if (ase_lsp_pushtmp (lsp, tmp) == ASE_NULL) return ASE_NULL; - - tmp = ASE_LSP_CDR(args); - while (ASE_LSP_TYPE(tmp) == ASE_LSP_OBJ_CONS) - { - if (ase_lsp_eval(lsp, ASE_LSP_CAR(tmp)) == ASE_NULL) - { - ase_lsp_poptmp (lsp); /* tmp */ - return ASE_NULL; - } - - tmp = ASE_LSP_CDR(tmp); - } - - if (tmp != lsp->mem->nil) - { - ase_lsp_poptmp (lsp); /* tmp */ - - ase_lsp_seterror (lsp, ASE_LSP_EARGBAD, ASE_NULL, 0); - return ASE_NULL; - } - - ase_lsp_poptmp (lsp); /* tmp */ - } - - return lsp->mem->nil; -} - -ase_lsp_obj_t* ase_lsp_prim_car (ase_lsp_t* lsp, ase_lsp_obj_t* args) -{ - /* - * (car '(10 20 30)) - */ - - ase_lsp_obj_t* tmp; - - ASE_ASSERT (ASE_LSP_TYPE(args) == ASE_LSP_OBJ_CONS); - - tmp = ase_lsp_eval (lsp, ASE_LSP_CAR(args)); - if (tmp == ASE_NULL) return ASE_NULL; - if (tmp == lsp->mem->nil) return lsp->mem->nil; - - if (ASE_LSP_TYPE(tmp) != ASE_LSP_OBJ_CONS) - { - ase_lsp_seterror (lsp, ASE_LSP_EARGBAD, ASE_NULL, 0); - return ASE_NULL; - } - - return ASE_LSP_CAR(tmp); -} - -ase_lsp_obj_t* ase_lsp_prim_cdr (ase_lsp_t* lsp, ase_lsp_obj_t* args) -{ - /* - * (cdr '(10 20 30)) - */ - - ase_lsp_obj_t* tmp; - - ASE_ASSERT (ASE_LSP_TYPE(args) == ASE_LSP_OBJ_CONS); - - tmp = ase_lsp_eval (lsp, ASE_LSP_CAR(args)); - if (tmp == ASE_NULL) return ASE_NULL; - if (tmp == lsp->mem->nil) return lsp->mem->nil; - - if (ASE_LSP_TYPE(tmp) != ASE_LSP_OBJ_CONS) - { - ase_lsp_seterror (lsp, ASE_LSP_EARGBAD, ASE_NULL, 0); - return ASE_NULL; - } - - return ASE_LSP_CDR(tmp); -} - -ase_lsp_obj_t* ase_lsp_prim_cons (ase_lsp_t* lsp, ase_lsp_obj_t* args) -{ - /* - * (cons 10 20) - * (cons '(10 20) 30) - */ - - ase_lsp_obj_t* car, * cdr, * cons; - - ASE_ASSERT (ASE_LSP_TYPE(args) == ASE_LSP_OBJ_CONS); - - car = ase_lsp_eval (lsp, ASE_LSP_CAR(args)); - if (car == ASE_NULL) return ASE_NULL; - - if (ase_lsp_pushtmp (lsp, car) == ASE_NULL) return ASE_NULL; - - cdr = ase_lsp_eval (lsp, ASE_LSP_CAR(ASE_LSP_CDR(args))); - if (cdr == ASE_NULL) - { - ase_lsp_poptmp (lsp); /* car */ - return ASE_NULL; - } - - if (ase_lsp_pushtmp (lsp, cdr) == ASE_NULL) - { - ase_lsp_poptmp (lsp); /* car */ - return ASE_NULL; - } - - cons = ase_lsp_makecons (lsp->mem, car, cdr); - if (cons == ASE_NULL) - { - ase_lsp_poptmp (lsp); /* cdr */ - ase_lsp_poptmp (lsp); /* car */ - return ASE_NULL; - } - - ase_lsp_poptmp (lsp); /* cdr */ - ase_lsp_poptmp (lsp); /* car */ - return cons; -} - -ase_lsp_obj_t* ase_lsp_prim_length (ase_lsp_t* lsp, ase_lsp_obj_t* args) -{ - ase_lsp_obj_t* body, * tmp; - ase_long_t len = 0; - - ASE_ASSERT (ASE_LSP_TYPE(args) == ASE_LSP_OBJ_CONS); - - body = args; - while (ASE_LSP_TYPE(body) == ASE_LSP_OBJ_CONS) - { - tmp = ase_lsp_eval (lsp, ASE_LSP_CAR(body)); - if (tmp == ASE_NULL) return ASE_NULL; - - if (ASE_LSP_TYPE(tmp) == ASE_LSP_OBJ_NIL) - { - len = 0; - } - else if (ASE_LSP_TYPE(tmp) == ASE_LSP_OBJ_STR) - { - len = ASE_LSP_STRLEN(tmp); - } - else if (ASE_LSP_TYPE(tmp) == ASE_LSP_OBJ_SYM) - { - len = ASE_LSP_SYMLEN(tmp); - } - else if (ASE_LSP_TYPE(tmp) == ASE_LSP_OBJ_CONS) - { - len = 0; - do - { - len++; - tmp = ASE_LSP_CDR(tmp); - } - while (ASE_LSP_TYPE(tmp) == ASE_LSP_OBJ_CONS); - - /* TODO: more flexible without the check below? - * both of the following expression evalute - * to 3 without it. - * (length '(9 9 9 . 9)) - * (length '(9 9 9)) - */ - if (ASE_LSP_TYPE(tmp) != ASE_LSP_OBJ_NIL) - { - ase_lsp_seterror (lsp, ASE_LSP_EVALBAD, ASE_NULL, 0); - return ASE_NULL; - } - } - else - { - ase_lsp_seterror (lsp, ASE_LSP_EVALBAD, ASE_NULL, 0); - return ASE_NULL; - } - - body = ASE_LSP_CDR(body); - } - - ASE_ASSERT (body == lsp->mem->nil); - return ase_lsp_makeintobj (lsp->mem, len); -} - -ase_lsp_obj_t* ase_lsp_prim_set (ase_lsp_t* lsp, ase_lsp_obj_t* args) -{ - /* - * (set 'flowers 'rose) - * (set flowers 20) - * rose - */ - - ase_lsp_obj_t* p1, * p2; - - ASE_ASSERT (ASE_LSP_TYPE(args) == ASE_LSP_OBJ_CONS); - - p1 = ase_lsp_eval (lsp, ASE_LSP_CAR(args)); - if (p1 == ASE_NULL) return ASE_NULL; - - if (ase_lsp_pushtmp (lsp, p1) == ASE_NULL) return ASE_NULL; - - if (ASE_LSP_TYPE(p1) != ASE_LSP_OBJ_SYM) - { - ase_lsp_poptmp (lsp); /* p1 */ - - ase_lsp_seterror (lsp, ASE_LSP_EARGBAD, ASE_NULL, 0); - return ASE_NULL; - } - - p2 = ase_lsp_eval (lsp, ASE_LSP_CAR(ASE_LSP_CDR(args))); - if (p2 == ASE_NULL) - { - ase_lsp_poptmp (lsp); /* p1 */ - return ASE_NULL; - } - - if (ase_lsp_pushtmp (lsp, p2) == ASE_NULL) - { - ase_lsp_poptmp (lsp); /* p1 */ - return ASE_NULL; - } - - if (ase_lsp_setvalue (lsp->mem, p1, p2) == ASE_NULL) - { - ase_lsp_poptmp (lsp); /* p2 */ - ase_lsp_poptmp (lsp); /* p1 */ - return ASE_NULL; - } - - ase_lsp_poptmp (lsp); /* p2 */ - ase_lsp_poptmp (lsp); /* p1 */ - return p2; -} - -ase_lsp_obj_t* ase_lsp_prim_setq (ase_lsp_t* lsp, ase_lsp_obj_t* args) -{ - /* - * (setq x 10) - * (setq x "string") - */ - - ase_lsp_obj_t* p = args, * p1, * p2 = lsp->mem->nil; - - while (p != lsp->mem->nil) - { - ASE_ASSERT (ASE_LSP_TYPE(p) == ASE_LSP_OBJ_CONS); - - p1 = ASE_LSP_CAR(p); - if (ASE_LSP_TYPE(p1) != ASE_LSP_OBJ_SYM) - { - ase_lsp_seterror (lsp, ASE_LSP_EARGBAD, ASE_NULL, 0); - return ASE_NULL; - } - - if (ASE_LSP_TYPE(ASE_LSP_CDR(p)) != ASE_LSP_OBJ_CONS) - { - lsp->errnum = ASE_LSP_EARGFEW; - return ASE_NULL; - } - - p2 = ase_lsp_eval (lsp, ASE_LSP_CAR(ASE_LSP_CDR(p))); - if (p2 == ASE_NULL) return ASE_NULL; - - if (ase_lsp_pushtmp (lsp, p2) == ASE_NULL) return ASE_NULL; - - if (ase_lsp_setvalue (lsp->mem, p1, p2) == ASE_NULL) - { - ase_lsp_poptmp (lsp); - return ASE_NULL; - } - - ase_lsp_poptmp (lsp); - p = ASE_LSP_CDR(ASE_LSP_CDR(p)); - } - - return p2; -} - -ase_lsp_obj_t* ase_lsp_prim_quote (ase_lsp_t* lsp, ase_lsp_obj_t* args) -{ - /* - * (quote (10 20 30 50)) - */ - - ASE_ASSERT (ASE_LSP_TYPE(args) == ASE_LSP_OBJ_CONS); - return ASE_LSP_CAR(args); -} - -ase_lsp_obj_t* ase_lsp_prim_defun (ase_lsp_t* lsp, ase_lsp_obj_t* args) -{ - /* - * (defun x (a b) (+ a b 100)) - * (x 40 50) - * - * (setq x (lambda (x y) (setq temp 10) (+ x y temp))) - * (x 40 50) - * temp - */ - - ase_lsp_obj_t* name, * fun; - - name = ASE_LSP_CAR(args); - if (ASE_LSP_TYPE(name) != ASE_LSP_OBJ_SYM) - { - ase_lsp_seterror (lsp, ASE_LSP_EARGBAD, ASE_NULL, 0); - return ASE_NULL; - } - - fun = ase_lsp_makefunc (lsp->mem, - ASE_LSP_CAR(ASE_LSP_CDR(args)), ASE_LSP_CDR(ASE_LSP_CDR(args))); - if (fun == ASE_NULL) return ASE_NULL; - - if (ase_lsp_pushtmp (lsp, fun) == ASE_NULL) return ASE_NULL; - - if (ase_lsp_setfunc (lsp->mem, ASE_LSP_CAR(args), fun) == ASE_NULL) - { - ase_lsp_poptmp (lsp); - return ASE_NULL; - } - - ase_lsp_poptmp (lsp); - return fun; -} - -ase_lsp_obj_t* ase_lsp_prim_demac (ase_lsp_t* lsp, ase_lsp_obj_t* args) -{ - /* - * (demac x (abc) x y z) - * (setq x (macro (abc) x y z)) - */ - - ase_lsp_obj_t* name, * mac; - - name = ASE_LSP_CAR(args); - if (ASE_LSP_TYPE(name) != ASE_LSP_OBJ_SYM) - { - ase_lsp_seterror (lsp, ASE_LSP_EARGBAD, ASE_NULL, 0); - return ASE_NULL; - } - - mac = ase_lsp_makemacro (lsp->mem, - ASE_LSP_CAR(ASE_LSP_CDR(args)), ASE_LSP_CDR(ASE_LSP_CDR(args))); - if (mac == ASE_NULL) return ASE_NULL; - - if (ase_lsp_pushtmp (lsp, mac) == ASE_NULL) return ASE_NULL; - - if (ase_lsp_setfunc (lsp->mem, ASE_LSP_CAR(args), mac) == ASE_NULL) - { - ase_lsp_poptmp (lsp); - return ASE_NULL; - } - - ase_lsp_poptmp (lsp); - return mac; -} - -ase_lsp_obj_t* ase_lsp_prim_or (ase_lsp_t* lsp, ase_lsp_obj_t* args) -{ - /* - * (or 10 20 30 40) - * (or (= n 20) (= n 30)) - */ - ase_lsp_obj_t* tmp; - -/* TODO: this is wrong. redo the work */ - while (ASE_LSP_TYPE(args) == ASE_LSP_OBJ_CONS) - { - tmp = ase_lsp_eval (lsp, ASE_LSP_CAR(args)); - if (tmp == ASE_NULL) return ASE_NULL; - - if (ASE_LSP_TYPE(args) == ASE_LSP_OBJ_INT) - if (tmp != lsp->mem->nil) return lsp->mem->t; - args = ASE_LSP_CDR(args); - } - - return lsp->mem->nil; -} - diff --git a/ase/lsp/prim.h b/ase/lsp/prim.h deleted file mode 100644 index 61900f7a..00000000 --- a/ase/lsp/prim.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * $Id: prim.h,v 1.1.1.1 2007/03/28 14:05:24 bacon Exp $ - * - * {License} - */ - -#ifndef _ASE_LSP_PRIM_H_ -#define _ASE_LSP_PRIM_H_ - -#ifndef _ASE_LSP_LSP_H_ -#error Never include this file directly. Include instead -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -ase_lsp_obj_t* ase_lsp_prim_exit (ase_lsp_t* lsp, ase_lsp_obj_t* args); -ase_lsp_obj_t* ase_lsp_prim_eval (ase_lsp_t* lsp, ase_lsp_obj_t* args); -ase_lsp_obj_t* ase_lsp_prim_prog1 (ase_lsp_t* lsp, ase_lsp_obj_t* args); -ase_lsp_obj_t* ase_lsp_prim_progn (ase_lsp_t* lsp, ase_lsp_obj_t* args); -ase_lsp_obj_t* ase_lsp_prim_gc (ase_lsp_t* lsp, ase_lsp_obj_t* args); -ase_lsp_obj_t* ase_lsp_prim_cond (ase_lsp_t* lsp, ase_lsp_obj_t* args); -ase_lsp_obj_t* ase_lsp_prim_if (ase_lsp_t* lsp, ase_lsp_obj_t* args); -ase_lsp_obj_t* ase_lsp_prim_while (ase_lsp_t* lsp, ase_lsp_obj_t* args); - -ase_lsp_obj_t* ase_lsp_prim_car (ase_lsp_t* lsp, ase_lsp_obj_t* args); -ase_lsp_obj_t* ase_lsp_prim_cdr (ase_lsp_t* lsp, ase_lsp_obj_t* args); -ase_lsp_obj_t* ase_lsp_prim_cons (ase_lsp_t* lsp, ase_lsp_obj_t* args); -ase_lsp_obj_t* ase_lsp_prim_length (ase_lsp_t* lsp, ase_lsp_obj_t* args); - -ase_lsp_obj_t* ase_lsp_prim_set (ase_lsp_t* lsp, ase_lsp_obj_t* args); -ase_lsp_obj_t* ase_lsp_prim_setq (ase_lsp_t* lsp, ase_lsp_obj_t* args); -ase_lsp_obj_t* ase_lsp_prim_quote (ase_lsp_t* lsp, ase_lsp_obj_t* args); -ase_lsp_obj_t* ase_lsp_prim_defun (ase_lsp_t* lsp, ase_lsp_obj_t* args); -ase_lsp_obj_t* ase_lsp_prim_demac (ase_lsp_t* lsp, ase_lsp_obj_t* args); -ase_lsp_obj_t* ase_lsp_prim_let (ase_lsp_t* lsp, ase_lsp_obj_t* args); -ase_lsp_obj_t* ase_lsp_prim_letx (ase_lsp_t* lsp, ase_lsp_obj_t* args); -ase_lsp_obj_t* ase_lsp_prim_or (ase_lsp_t* lsp, ase_lsp_obj_t* args); - -/*--------------------- - prim_compar.c - ---------------------*/ -ase_lsp_obj_t* ase_lsp_prim_eq (ase_lsp_t* lsp, ase_lsp_obj_t* args); -ase_lsp_obj_t* ase_lsp_prim_ne (ase_lsp_t* lsp, ase_lsp_obj_t* args); -ase_lsp_obj_t* ase_lsp_prim_gt (ase_lsp_t* lsp, ase_lsp_obj_t* args); -ase_lsp_obj_t* ase_lsp_prim_lt (ase_lsp_t* lsp, ase_lsp_obj_t* args); -ase_lsp_obj_t* ase_lsp_prim_ge (ase_lsp_t* lsp, ase_lsp_obj_t* args); -ase_lsp_obj_t* ase_lsp_prim_le (ase_lsp_t* lsp, ase_lsp_obj_t* args); - -/*--------------------- - prim_math.c - ---------------------*/ -ase_lsp_obj_t* ase_lsp_prim_plus (ase_lsp_t* lsp, ase_lsp_obj_t* args); -ase_lsp_obj_t* ase_lsp_prim_minus (ase_lsp_t* lsp, ase_lsp_obj_t* args); -ase_lsp_obj_t* ase_lsp_prim_mul (ase_lsp_t* lsp, ase_lsp_obj_t* args); -ase_lsp_obj_t* ase_lsp_prim_div (ase_lsp_t* lsp, ase_lsp_obj_t* args); -ase_lsp_obj_t* ase_lsp_prim_mod (ase_lsp_t* lsp, ase_lsp_obj_t* args); - -/*--------------------- - prim_fact.c - ---------------------*/ -ase_lsp_obj_t* ase_lsp_prim_fact (ase_lsp_t* lsp, ase_lsp_obj_t* args); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ase/lsp/prim_compar.c b/ase/lsp/prim_compar.c deleted file mode 100644 index f0888cf8..00000000 --- a/ase/lsp/prim_compar.c +++ /dev/null @@ -1,141 +0,0 @@ -/* - * $Id: prim_compar.c,v 1.1.1.1 2007/03/28 14:05:24 bacon Exp $ - * - * {License} - */ - -#include - -#define PRIM_COMPAR(lsp,args,op) \ -{ \ - ase_lsp_obj_t* p1, * p2; \ - int res; \ - ASE_ASSERT (ASE_LSP_TYPE(args) == ASE_LSP_OBJ_CONS); \ -\ - p1 = ase_lsp_eval (lsp, ASE_LSP_CAR(args)); \ - if (p1 == ASE_NULL) return ASE_NULL; \ - if (ase_lsp_pushtmp (lsp, p1) == ASE_NULL) return ASE_NULL; \ -\ - p2 = ase_lsp_eval (lsp, ASE_LSP_CAR(ASE_LSP_CDR(args))); \ - if (p2 == ASE_NULL) \ - { \ - ase_lsp_poptmp (lsp); \ - return ASE_NULL; \ - } \ -\ - if (ase_lsp_pushtmp (lsp, p2) == ASE_NULL) \ - { \ - ase_lsp_poptmp (lsp); \ - return ASE_NULL; \ - } \ -\ - if (ASE_LSP_TYPE(p1) == ASE_LSP_OBJ_INT) \ - { \ - if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_INT) \ - { \ - res = ASE_LSP_IVAL(p1) op ASE_LSP_IVAL(p2); \ - } \ - else if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_REAL) \ - { \ - res = ASE_LSP_IVAL(p1) op ASE_LSP_RVAL(p2); \ - } \ - else \ - { \ - ase_lsp_poptmp (lsp); \ - ase_lsp_poptmp (lsp); \ - ase_lsp_seterror (lsp, ASE_LSP_EVALBAD, ASE_NULL, 0); \ - return ASE_NULL; \ - } \ - } \ - else if (ASE_LSP_TYPE(p1) == ASE_LSP_OBJ_REAL) \ - { \ - if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_INT) \ - { \ - res = ASE_LSP_RVAL(p1) op ASE_LSP_IVAL(p2); \ - } \ - else if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_REAL) \ - { \ - res = ASE_LSP_RVAL(p1) op ASE_LSP_RVAL(p2); \ - } \ - else \ - { \ - ase_lsp_poptmp (lsp); \ - ase_lsp_poptmp (lsp); \ - ase_lsp_seterror (lsp, ASE_LSP_EVALBAD, ASE_NULL, 0); \ - return ASE_NULL; \ - } \ - } \ - else if (ASE_LSP_TYPE(p1) == ASE_LSP_OBJ_SYM) \ - { \ - if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_SYM) \ - { \ - res = ase_strxncmp ( \ - ASE_LSP_SYMPTR(p1), ASE_LSP_SYMLEN(p1), \ - ASE_LSP_SYMPTR(p2), ASE_LSP_SYMLEN(p2)) op 0; \ - } \ - else \ - { \ - ase_lsp_poptmp (lsp); \ - ase_lsp_poptmp (lsp); \ - ase_lsp_seterror (lsp, ASE_LSP_EVALBAD, ASE_NULL, 0); \ - return ASE_NULL; \ - } \ - } \ - else if (ASE_LSP_TYPE(p1) == ASE_LSP_OBJ_STR) \ - { \ - if (ASE_LSP_TYPE(p2) == ASE_LSP_OBJ_STR) \ - { \ - res = ase_strxncmp ( \ - ASE_LSP_STRPTR(p1), ASE_LSP_STRLEN(p1), \ - ASE_LSP_STRPTR(p2), ASE_LSP_STRLEN(p2)) op 0; \ - } \ - else \ - { \ - ase_lsp_poptmp (lsp); \ - ase_lsp_poptmp (lsp); \ - ase_lsp_seterror (lsp, ASE_LSP_EVALBAD, ASE_NULL, 0); \ - return ASE_NULL; \ - } \ - } \ - else \ - { \ - ase_lsp_poptmp (lsp); \ - ase_lsp_poptmp (lsp); \ - ase_lsp_seterror (lsp, ASE_LSP_EVALBAD, ASE_NULL, 0); \ - return ASE_NULL; \ - } \ -\ - ase_lsp_poptmp (lsp); \ - ase_lsp_poptmp (lsp); \ - return (res)? lsp->mem->t: lsp->mem->nil; \ -} - -ase_lsp_obj_t* ase_lsp_prim_eq (ase_lsp_t* lsp, ase_lsp_obj_t* args) -{ - PRIM_COMPAR (lsp, args, ==); -} - -ase_lsp_obj_t* ase_lsp_prim_ne (ase_lsp_t* lsp, ase_lsp_obj_t* args) -{ - PRIM_COMPAR (lsp, args, !=); -} - -ase_lsp_obj_t* ase_lsp_prim_gt (ase_lsp_t* lsp, ase_lsp_obj_t* args) -{ - PRIM_COMPAR (lsp, args, >); -} - -ase_lsp_obj_t* ase_lsp_prim_lt (ase_lsp_t* lsp, ase_lsp_obj_t* args) -{ - PRIM_COMPAR (lsp, args, <); -} - -ase_lsp_obj_t* ase_lsp_prim_ge (ase_lsp_t* lsp, ase_lsp_obj_t* args) -{ - PRIM_COMPAR (lsp, args, >=); -} - -ase_lsp_obj_t* ase_lsp_prim_le (ase_lsp_t* lsp, ase_lsp_obj_t* args) -{ - PRIM_COMPAR (lsp, args, <=); -} diff --git a/ase/lsp/prim_let.c b/ase/lsp/prim_let.c deleted file mode 100644 index 855506b2..00000000 --- a/ase/lsp/prim_let.c +++ /dev/null @@ -1,186 +0,0 @@ -/* - * $Id: prim_let.c,v 1.1.1.1 2007/03/28 14:05:24 bacon Exp $ - * - * {License} - */ - -#include - -/* - * (let ((variable value) - * (variable value) - * ...) - * body...) - */ - -static ase_lsp_obj_t* __prim_let ( - ase_lsp_t* lsp, ase_lsp_obj_t* args, int sequential) -{ - ase_lsp_frame_t* frame; - ase_lsp_obj_t* assoc; - ase_lsp_obj_t* body; - ase_lsp_obj_t* value; - - /* create a new frameq */ - frame = ase_lsp_newframe (lsp); - if (frame == ASE_NULL) return ASE_NULL; - /*frame->link = lsp->mem->frame;*/ - - if (sequential) - { - frame->link = lsp->mem->frame; - lsp->mem->frame = frame; - } - else - { - frame->link = lsp->mem->brooding_frame; - lsp->mem->brooding_frame = frame; - } - - assoc = ASE_LSP_CAR(args); - - /*while (assoc != lsp->mem->nil) {*/ - while (ASE_LSP_TYPE(assoc) == ASE_LSP_OBJ_CONS) - { - ase_lsp_obj_t* ass = ASE_LSP_CAR(assoc); - if (ASE_LSP_TYPE(ass) == ASE_LSP_OBJ_CONS) - { - ase_lsp_obj_t* n = ASE_LSP_CAR(ass); - ase_lsp_obj_t* v = ASE_LSP_CDR(ass); - - if (ASE_LSP_TYPE(n) != ASE_LSP_OBJ_SYM) - { - if (sequential) lsp->mem->frame = frame->link; - else lsp->mem->brooding_frame = frame->link; - ase_lsp_freeframe (lsp, frame); - - ase_lsp_seterror (lsp, ASE_LSP_EARGBAD, ASE_NULL, 0); - return ASE_NULL; - } - - if (v != lsp->mem->nil) - { - if (ASE_LSP_CDR(v) != lsp->mem->nil) - { - if (sequential) lsp->mem->frame = frame->link; - else lsp->mem->brooding_frame = frame->link; - ase_lsp_freeframe (lsp, frame); - - ase_lsp_seterror (lsp, ASE_LSP_EARGMANY, ASE_NULL, 0); - return ASE_NULL; - } - if ((v = ase_lsp_eval(lsp, ASE_LSP_CAR(v))) == ASE_NULL) - { - if (sequential) lsp->mem->frame = frame->link; - else lsp->mem->brooding_frame = frame->link; - ase_lsp_freeframe (lsp, frame); - return ASE_NULL; - } - } - - if (ase_lsp_lookupinframe (lsp, frame, n) != ASE_NULL) - { - if (sequential) lsp->mem->frame = frame->link; - else lsp->mem->brooding_frame = frame->link; - ase_lsp_freeframe (lsp, frame); - - ase_lsp_seterror (lsp, ASE_LSP_EDUPFML, ASE_NULL, 0); - return ASE_NULL; - } - if (ase_lsp_insvalueintoframe (lsp, frame, n, v) == ASE_NULL) - { - if (sequential) lsp->mem->frame = frame->link; - else lsp->mem->brooding_frame = frame->link; - ase_lsp_freeframe (lsp, frame); - return ASE_NULL; - } - } - else if (ASE_LSP_TYPE(ass) == ASE_LSP_OBJ_SYM) - { - if (ase_lsp_lookupinframe (lsp, frame, ass) != ASE_NULL) - { - if (sequential) lsp->mem->frame = frame->link; - else lsp->mem->brooding_frame = frame->link; - ase_lsp_freeframe (lsp, frame); - - ase_lsp_seterror (lsp, ASE_LSP_EDUPFML, ASE_NULL, 0); - return ASE_NULL; - } - if (ase_lsp_insvalueintoframe (lsp, frame, ass, lsp->mem->nil) == ASE_NULL) - { - if (sequential) lsp->mem->frame = frame->link; - else lsp->mem->brooding_frame = frame->link; - ase_lsp_freeframe (lsp, frame); - return ASE_NULL; - } - } - else - { - if (sequential) lsp->mem->frame = frame->link; - else lsp->mem->brooding_frame = frame->link; - ase_lsp_freeframe (lsp, frame); - - ase_lsp_seterror (lsp, ASE_LSP_EARGBAD, ASE_NULL, 0); - return ASE_NULL; - } - - assoc = ASE_LSP_CDR(assoc); - } - - if (assoc != lsp->mem->nil) - { - if (sequential) lsp->mem->frame = frame->link; - else lsp->mem->brooding_frame = frame->link; - ase_lsp_freeframe (lsp, frame); - - ase_lsp_seterror (lsp, ASE_LSP_EARGBAD, ASE_NULL, 0); - return ASE_NULL; - } - - /* push the frame */ - if (!sequential) - { - lsp->mem->brooding_frame = frame->link; - frame->link = lsp->mem->frame; - lsp->mem->frame = frame; - } - - /* evaluate forms in the body */ - value = lsp->mem->nil; - body = ASE_LSP_CDR(args); - while (body != lsp->mem->nil) - { - value = ase_lsp_eval (lsp, ASE_LSP_CAR(body)); - if (value == ASE_NULL) - { - lsp->mem->frame = frame->link; - ase_lsp_freeframe (lsp, frame); - return ASE_NULL; - } - body = ASE_LSP_CDR(body); - } - - /* pop the frame */ - lsp->mem->frame = frame->link; - - /* destroy the frame */ - ase_lsp_freeframe (lsp, frame); - return value; -} - -ase_lsp_obj_t* ase_lsp_prim_let (ase_lsp_t* lsp, ase_lsp_obj_t* args) -{ - /* - * (defun x (x y) - * (let ((temp1 10) (temp2 20)) - * (+ x y temp1 temp2))) - * (x 40 50) - * temp1 - */ - return __prim_let (lsp, args, 0); -} - -ase_lsp_obj_t* ase_lsp_prim_letx (ase_lsp_t* lsp, ase_lsp_obj_t* args) -{ - return __prim_let (lsp, args, 1); -} diff --git a/ase/lsp/prim_math.c b/ase/lsp/prim_math.c deleted file mode 100644 index 4d21feca..00000000 --- a/ase/lsp/prim_math.c +++ /dev/null @@ -1,351 +0,0 @@ -/* - * $Id: prim_math.c,v 1.1.1.1 2007/03/28 14:05:24 bacon Exp $ - * - * {License} - */ - -#include - -ase_lsp_obj_t* ase_lsp_prim_plus (ase_lsp_t* lsp, ase_lsp_obj_t* args) -{ - ase_lsp_obj_t* body, * tmp; - ase_long_t ival = 0; - ase_real_t rval = .0; - ase_bool_t realnum = ase_false; - - ASE_ASSERT (ASE_LSP_TYPE(args) == ASE_LSP_OBJ_CONS); - - body = args; - while (ASE_LSP_TYPE(body) == ASE_LSP_OBJ_CONS) - { - tmp = ase_lsp_eval (lsp, ASE_LSP_CAR(body)); - if (tmp == ASE_NULL) return ASE_NULL; - - if (ASE_LSP_TYPE(tmp) == ASE_LSP_OBJ_INT) - { - if (body == args) - { - ASE_ASSERT (realnum == ase_false); - ival = ASE_LSP_IVAL(tmp); - } - else - { - if (!realnum) - ival = ival + ASE_LSP_IVAL(tmp); - else - rval = rval + ASE_LSP_IVAL(tmp); - } - } - else if (ASE_LSP_TYPE(tmp) == ASE_LSP_OBJ_REAL) - { - if (body == args) - { - ASE_ASSERT (realnum == ase_false); - realnum = ase_true; - rval = ASE_LSP_RVAL(tmp); - } - else - { - if (!realnum) - { - realnum = ase_true; - rval = (ase_real_t)ival; - } - rval = rval + ASE_LSP_RVAL(tmp); - } - } - else - { - ase_lsp_seterror (lsp, ASE_LSP_EVALBAD, ASE_NULL, 0); - return ASE_NULL; - } - - - body = ASE_LSP_CDR(body); - } - - ASE_ASSERT (body == lsp->mem->nil); - - tmp = (realnum)? - ase_lsp_makerealobj (lsp->mem, rval): - ase_lsp_makeintobj (lsp->mem, ival); - if (tmp == ASE_NULL) return ASE_NULL; - - return tmp; -} - -ase_lsp_obj_t* ase_lsp_prim_minus (ase_lsp_t* lsp, ase_lsp_obj_t* args) -{ - ase_lsp_obj_t* body, * tmp; - ase_long_t ival = 0; - ase_real_t rval = .0; - ase_bool_t realnum = ase_false; - - ASE_ASSERT (ASE_LSP_TYPE(args) == ASE_LSP_OBJ_CONS); - - body = args; - while (ASE_LSP_TYPE(body) == ASE_LSP_OBJ_CONS) - { - tmp = ase_lsp_eval (lsp, ASE_LSP_CAR(body)); - if (tmp == ASE_NULL) return ASE_NULL; - - - if (ASE_LSP_TYPE(tmp) == ASE_LSP_OBJ_INT) - { - if (body == args) - { - ASE_ASSERT (realnum == ase_false); - ival = ASE_LSP_IVAL(tmp); - } - else - { - if (!realnum) - ival = ival - ASE_LSP_IVAL(tmp); - else - rval = rval - ASE_LSP_IVAL(tmp); - } - } - else if (ASE_LSP_TYPE(tmp) == ASE_LSP_OBJ_REAL) - { - if (body == args) - { - ASE_ASSERT (realnum == ase_false); - realnum = ase_true; - rval = ASE_LSP_RVAL(tmp); - } - else - { - if (!realnum) - { - realnum = ase_true; - rval = (ase_real_t)ival; - } - rval = rval - ASE_LSP_RVAL(tmp); - } - } - else - { - ase_lsp_seterror (lsp, ASE_LSP_EVALBAD, ASE_NULL, 0); - return ASE_NULL; - } - - - body = ASE_LSP_CDR(body); - } - - ASE_ASSERT (body == lsp->mem->nil); - - tmp = (realnum)? - ase_lsp_makerealobj (lsp->mem, rval): - ase_lsp_makeintobj (lsp->mem, ival); - if (tmp == ASE_NULL) return ASE_NULL; - - return tmp; -} - -ase_lsp_obj_t* ase_lsp_prim_mul (ase_lsp_t* lsp, ase_lsp_obj_t* args) -{ - ase_lsp_obj_t* body, * tmp; - ase_long_t ival = 0; - ase_real_t rval = .0; - ase_bool_t realnum = ase_false; - - ASE_ASSERT (ASE_LSP_TYPE(args) == ASE_LSP_OBJ_CONS); - - body = args; - while (ASE_LSP_TYPE(body) == ASE_LSP_OBJ_CONS) - { - tmp = ase_lsp_eval (lsp, ASE_LSP_CAR(body)); - if (tmp == ASE_NULL) return ASE_NULL; - - if (ASE_LSP_TYPE(tmp) == ASE_LSP_OBJ_INT) - { - if (body == args) - { - ASE_ASSERT (realnum == ase_false); - ival = ASE_LSP_IVAL(tmp); - } - else - { - if (!realnum) - ival = ival * ASE_LSP_IVAL(tmp); - else - rval = rval * ASE_LSP_IVAL(tmp); - } - } - else if (ASE_LSP_TYPE(tmp) == ASE_LSP_OBJ_REAL) - { - if (body == args) - { - ASE_ASSERT (realnum == ase_false); - realnum = ase_true; - rval = ASE_LSP_RVAL(tmp); - } - else - { - if (!realnum) - { - realnum = ase_true; - rval = (ase_real_t)ival; - } - rval = rval * ASE_LSP_RVAL(tmp); - } - } - else - { - ase_lsp_seterror (lsp, ASE_LSP_EVALBAD, ASE_NULL, 0); - return ASE_NULL; - } - - - body = ASE_LSP_CDR(body); - } - - ASE_ASSERT (body == lsp->mem->nil); - - tmp = (realnum)? - ase_lsp_makerealobj (lsp->mem, rval): - ase_lsp_makeintobj (lsp->mem, ival); - if (tmp == ASE_NULL) return ASE_NULL; - - return tmp; -} - -ase_lsp_obj_t* ase_lsp_prim_div (ase_lsp_t* lsp, ase_lsp_obj_t* args) -{ - ase_lsp_obj_t* body, * tmp; - ase_long_t ival = 0; - ase_real_t rval = .0; - ase_bool_t realnum = ase_false; - - ASE_ASSERT (ASE_LSP_TYPE(args) == ASE_LSP_OBJ_CONS); - - body = args; - while (ASE_LSP_TYPE(body) == ASE_LSP_OBJ_CONS) - { - tmp = ase_lsp_eval (lsp, ASE_LSP_CAR(body)); - if (tmp == ASE_NULL) return ASE_NULL; - - if (ASE_LSP_TYPE(tmp) == ASE_LSP_OBJ_INT) - { - if (body == args) - { - ASE_ASSERT (realnum == ase_false); - ival = ASE_LSP_IVAL(tmp); - } - else - { - if (!realnum) - { - if (ASE_LSP_IVAL(tmp) == 0) - { - ase_lsp_seterror (lsp, ASE_LSP_EDIVBY0, ASE_NULL, 0); - return ASE_NULL; - } - ival = ival / ASE_LSP_IVAL(tmp); - } - else - rval = rval / ASE_LSP_IVAL(tmp); - } - } - else if (ASE_LSP_TYPE(tmp) == ASE_LSP_OBJ_REAL) - { - if (body == args) - { - ASE_ASSERT (realnum == ase_false); - realnum = ase_true; - rval = ASE_LSP_RVAL(tmp); - } - else - { - if (!realnum) - { - realnum = ase_true; - rval = (ase_real_t)ival; - } - rval = rval / ASE_LSP_RVAL(tmp); - } - } - else - { - ase_lsp_seterror (lsp, ASE_LSP_EVALBAD, ASE_NULL, 0); - return ASE_NULL; - } - - - body = ASE_LSP_CDR(body); - } - - ASE_ASSERT (body == lsp->mem->nil); - - tmp = (realnum)? - ase_lsp_makerealobj (lsp->mem, rval): - ase_lsp_makeintobj (lsp->mem, ival); - if (tmp == ASE_NULL) return ASE_NULL; - - return tmp; -} - -ase_lsp_obj_t* ase_lsp_prim_mod (ase_lsp_t* lsp, ase_lsp_obj_t* args) -{ - ase_lsp_obj_t* body, * tmp; - ase_long_t ival = 0; - - ASE_ASSERT (ASE_LSP_TYPE(args) == ASE_LSP_OBJ_CONS); - - body = args; - while (ASE_LSP_TYPE(body) == ASE_LSP_OBJ_CONS) - { - tmp = ase_lsp_eval (lsp, ASE_LSP_CAR(body)); - if (tmp == ASE_NULL) return ASE_NULL; - - if (ASE_LSP_TYPE(tmp) == ASE_LSP_OBJ_INT) - { - if (body == args) - { - ival = ASE_LSP_IVAL(tmp); - } - else - { - if (ASE_LSP_IVAL(tmp) == 0) - { - ase_lsp_seterror (lsp, ASE_LSP_EDIVBY0, ASE_NULL, 0); - return ASE_NULL; - } - ival = ival % ASE_LSP_IVAL(tmp); - } - } - else if (ASE_LSP_TYPE(tmp) == ASE_LSP_OBJ_REAL) - { - if (body == args) - { - ival = (ase_long_t)ASE_LSP_RVAL(tmp); - } - else - { - ase_long_t tmpi = (ase_long_t)ASE_LSP_RVAL(tmp); - if (tmpi == 0) - { - ase_lsp_seterror (lsp, ASE_LSP_EDIVBY0, ASE_NULL, 0); - return ASE_NULL; - } - ival = ival % tmpi; - } - } - else - { - ase_lsp_seterror (lsp, ASE_LSP_EVALBAD, ASE_NULL, 0); - return ASE_NULL; - } - - - body = ASE_LSP_CDR(body); - } - - ASE_ASSERT (body == lsp->mem->nil); - - tmp = ase_lsp_makeintobj (lsp->mem, ival); - if (tmp == ASE_NULL) return ASE_NULL; - - return tmp; -} diff --git a/ase/lsp/prim_prog.c b/ase/lsp/prim_prog.c deleted file mode 100644 index 46ceb46c..00000000 --- a/ase/lsp/prim_prog.c +++ /dev/null @@ -1,53 +0,0 @@ -/* - * $Id: prim_prog.c,v 1.1.1.1 2007/03/28 14:05:24 bacon Exp $ - * - * {License} - */ - -#include - -ase_lsp_obj_t* ase_lsp_prim_prog1 (ase_lsp_t* lsp, ase_lsp_obj_t* args) -{ - /* (prog1 1 2 3) returns 1 */ - ase_lsp_obj_t* res = ASE_NULL, * tmp; - - /*while (args != lsp->mem->nil) {*/ - while (ASE_LSP_TYPE(args) == ASE_LSP_OBJ_CONS) - { - tmp = ase_lsp_eval (lsp, ASE_LSP_CAR(args)); - if (tmp == ASE_NULL) return ASE_NULL; - - if (res == ASE_NULL) - { - res = tmp; - if (ase_lsp_pushtmp (lsp, res) == ASE_NULL) - { - return ASE_NULL; - } - } - args = ASE_LSP_CDR(args); - } - - if (res != ASE_NULL) ase_lsp_poptmp (lsp); - return res; -} - -ase_lsp_obj_t* ase_lsp_prim_progn (ase_lsp_t* lsp, ase_lsp_obj_t* args) -{ - /* (progn 1 2 3) returns 3 */ - - ase_lsp_obj_t* res, * tmp; - - res = lsp->mem->nil; - /*while (args != lsp->mem->nil) {*/ - while (ASE_LSP_TYPE(args) == ASE_LSP_OBJ_CONS) - { - tmp = ase_lsp_eval (lsp, ASE_LSP_CAR(args)); - if (tmp == ASE_NULL) return ASE_NULL; - - res = tmp; - args = ASE_LSP_CDR(args); - } - - return res; -} diff --git a/ase/lsp/print.c b/ase/lsp/print.c deleted file mode 100644 index fcebb109..00000000 --- a/ase/lsp/print.c +++ /dev/null @@ -1,150 +0,0 @@ -/* - * $Id: print.c,v 1.1.1.1 2007/03/28 14:05:24 bacon Exp $ - * - * {License} - */ - -#include - -#define OUTPUT_STR(lsp,str) \ - do { \ - if (lsp->output_func(ASE_LSP_IO_WRITE, lsp->output_arg, (ase_char_t*)str, ase_strlen(str)) == -1) { \ - ase_lsp_seterror (lsp, ASE_LSP_EOUTPUT, ASE_NULL, 0); \ - return -1; \ - } \ - } while (0) - -#define OUTPUT_STRX(lsp,str,len) \ - do { \ - if (lsp->output_func(ASE_LSP_IO_WRITE, lsp->output_arg, (ase_char_t*)str, len) == -1) { \ - ase_lsp_seterror (lsp, ASE_LSP_EOUTPUT, ASE_NULL, 0); \ - return -1; \ - } \ - } while (0) - -static int __print (ase_lsp_t* lsp, const ase_lsp_obj_t* obj, ase_bool_t prt_cons_par) -{ - ase_char_t buf[256]; - - if (lsp->output_func == ASE_NULL) - { - ase_lsp_seterror (lsp, ASE_LSP_ENOOUTP, ASE_NULL, 0); - return -1; - } - - switch (ASE_LSP_TYPE(obj)) - { - case ASE_LSP_OBJ_NIL: - OUTPUT_STR (lsp, ASE_T("nil")); - break; - - case ASE_LSP_OBJ_TRUE: - OUTPUT_STR (lsp, ASE_T("t")); - break; - - case ASE_LSP_OBJ_INT: - #if ASE_SIZEOF_LONG_LONG > 0 - lsp->prmfns.misc.sprintf ( - lsp->prmfns.misc.custom_data, - buf, ASE_COUNTOF(buf), - ASE_T("%lld"), (long long)ASE_LSP_IVAL(obj)); - #elif ASE_SIZEOF___INT64 > 0 - lsp->prmfns.misc.sprintf ( - lsp->prmfns.misc.custom_data, - buf, ASE_COUNTOF(buf), - ASE_T("%I64d"), (__int64)ASE_LSP_IVAL(obj)); - #elif ASE_SIZEOF_LONG > 0 - lsp->prmfns.misc.sprintf ( - lsp->prmfns.misc.custom_data, - buf, ASE_COUNTOF(buf), - ASE_T("%ld"), (long)ASE_LSP_IVAL(obj)); - #elif ASE_SIZEOF_INT > 0 - lsp->prmfns.misc.sprintf ( - lsp->prmfns.misc.custom_data, - buf, ASE_COUNTOF(buf), - ASE_T("%d"), (int)ASE_LSP_IVAL(obj)); - #else - #error unsupported size - #endif - OUTPUT_STR (lsp, buf); - break; - - case ASE_LSP_OBJ_REAL: - lsp->prmfns.misc.sprintf ( - lsp->prmfns.misc.custom_data, - buf, ASE_COUNTOF(buf), - ASE_T("%Lf"), (long double)ASE_LSP_RVAL(obj)); - - OUTPUT_STR (lsp, buf); - break; - - case ASE_LSP_OBJ_SYM: - OUTPUT_STRX (lsp, ASE_LSP_SYMPTR(obj), ASE_LSP_SYMLEN(obj)); - break; - - case ASE_LSP_OBJ_STR: - OUTPUT_STR (lsp, ASE_T("\"")); - /* TODO: deescaping */ - OUTPUT_STRX (lsp, ASE_LSP_STRPTR(obj), ASE_LSP_STRLEN(obj)); - OUTPUT_STR (lsp, ASE_T("\"")); - break; - - case ASE_LSP_OBJ_CONS: - { - const ase_lsp_obj_t* p = obj; - if (prt_cons_par) OUTPUT_STR (lsp, ASE_T("(")); - do - { - ase_lsp_print (lsp, ASE_LSP_CAR(p)); - p = ASE_LSP_CDR(p); - if (p != lsp->mem->nil) - { - OUTPUT_STR (lsp, ASE_T(" ")); - if (ASE_LSP_TYPE(p) != ASE_LSP_OBJ_CONS) - { - OUTPUT_STR (lsp, ASE_T(". ")); - ase_lsp_print (lsp, p); - } - } - } - while (p != lsp->mem->nil && ASE_LSP_TYPE(p) == ASE_LSP_OBJ_CONS); - if (prt_cons_par) OUTPUT_STR (lsp, ASE_T(")")); - - break; - } - - case ASE_LSP_OBJ_FUNC: - /*OUTPUT_STR (lsp, ASE_T("func"));*/ - OUTPUT_STR (lsp, ASE_T("(lambda ")); - if (__print (lsp, ASE_LSP_FFORMAL(obj), ase_true) == -1) return -1; - OUTPUT_STR (lsp, ASE_T(" ")); - if (__print (lsp, ASE_LSP_FBODY(obj), ase_false) == -1) return -1; - OUTPUT_STR (lsp, ASE_T(")")); - break; - - case ASE_LSP_OBJ_MACRO: - OUTPUT_STR (lsp, ASE_T("(macro ")); - if (__print (lsp, ASE_LSP_FFORMAL(obj), ase_true) == -1) return -1; - OUTPUT_STR (lsp, ASE_T(" ")); - if (__print (lsp, ASE_LSP_FBODY(obj), ase_false) == -1) return -1; - OUTPUT_STR (lsp, ASE_T(")")); - break; - case ASE_LSP_OBJ_PRIM: - OUTPUT_STR (lsp, ASE_T("prim")); - break; - - default: - lsp->prmfns.misc.sprintf ( - lsp->prmfns.misc.custom_data, - buf, ASE_COUNTOF(buf), - ASE_T("unknown object type: %d"), ASE_LSP_TYPE(obj)); - OUTPUT_STR (lsp, buf); - } - - return 0; -} - -int ase_lsp_print (ase_lsp_t* lsp, const ase_lsp_obj_t* obj) -{ - return __print (lsp, obj, ase_true); -} diff --git a/ase/lsp/read.c b/ase/lsp/read.c deleted file mode 100644 index b7a9ea49..00000000 --- a/ase/lsp/read.c +++ /dev/null @@ -1,567 +0,0 @@ -/* - * $Id: read.c,v 1.1.1.1 2007/03/28 14:05:24 bacon Exp $ - * - * {License} - */ - -#include - -#define IS_IDENT(c) \ - ((c) == ASE_T('+') || (c) == ASE_T('-') || \ - (c) == ASE_T('*') || (c) == ASE_T('/') || \ - (c) == ASE_T('%') || (c) == ASE_T('&') || \ - (c) == ASE_T('<') || (c) == ASE_T('>') || \ - (c) == ASE_T('=') || (c) == ASE_T('_') || \ - (c) == ASE_T('?')) - -#define TOKEN_CLEAR(lsp) ase_lsp_name_clear (&(lsp)->token.name) -#define TOKEN_TYPE(lsp) (lsp)->token.type -#define TOKEN_IVAL(lsp) (lsp)->token.ival -#define TOKEN_RVAL(lsp) (lsp)->token.rval -#define TOKEN_SPTR(lsp) (lsp)->token.name.buf -#define TOKEN_SLEN(lsp) (lsp)->token.name.size - -#define TOKEN_ADD_CHAR(lsp,ch) \ - do { \ - if (ase_lsp_name_addc(&(lsp)->token.name, ch) == -1) { \ - ase_lsp_seterror (lsp, ASE_LSP_ENOMEM, ASE_NULL, 0); \ - return -1; \ - } \ - } while (0) - -#define TOKEN_COMPARE(lsp,str) \ - ase_lsp_name_compare (&(lsp)->token.name, str) - -#define TOKEN_END 0 -#define TOKEN_INT 1 -#define TOKEN_REAL 2 -#define TOKEN_STRING 3 -#define TOKEN_LPAREN 4 -#define TOKEN_RPAREN 5 -#define TOKEN_IDENT 6 -#define TOKEN_QUOTE 7 -#define TOKEN_DOT 8 -#define TOKEN_INVALID 50 -#define TOKEN_UNTERM_STRING 51 - -#define NEXT_CHAR(lsp) \ - do { if (read_char(lsp) == -1) return -1;} while (0) - -#define NEXT_CHAR_TO(lsp,c) \ - do { \ - if (read_char(lsp) == -1) return -1;\ - c = (lsp)->curc; \ - } while (0) - -#define NEXT_TOKEN(lsp) \ - do { if (read_token(lsp) == -1) return ASE_NULL; } while (0) - -static ase_lsp_obj_t* read_obj (ase_lsp_t* lsp); -static ase_lsp_obj_t* read_list (ase_lsp_t* lsp); -static ase_lsp_obj_t* read_quote (ase_lsp_t* lsp); - -static int read_char (ase_lsp_t* lsp); -static int read_token (ase_lsp_t* lsp); -static int read_number (ase_lsp_t* lsp, int negative); -static int read_ident (ase_lsp_t* lsp); -static int read_string (ase_lsp_t* lsp); - -ase_lsp_obj_t* ase_lsp_read (ase_lsp_t* lsp) -{ - if (lsp->curc == ASE_CHAR_EOF && - read_char(lsp) == -1) return ASE_NULL; - - NEXT_TOKEN (lsp); - - lsp->mem->read = read_obj (lsp); - if (lsp->mem->read != ASE_NULL) - ase_lsp_deepunlockobj (lsp, lsp->mem->read); - return lsp->mem->read; -} - -static ase_lsp_obj_t* read_obj (ase_lsp_t* lsp) -{ - ase_lsp_obj_t* obj; - - switch (TOKEN_TYPE(lsp)) - { - case TOKEN_END: - ase_lsp_seterror (lsp, ASE_LSP_EEND, ASE_NULL, 0); - return ASE_NULL; - - case TOKEN_LPAREN: - NEXT_TOKEN (lsp); - return read_list (lsp); - - case TOKEN_QUOTE: - NEXT_TOKEN (lsp); - return read_quote (lsp); - - case TOKEN_INT: - obj = ase_lsp_makeintobj (lsp->mem, TOKEN_IVAL(lsp)); - if (obj == ASE_NULL) return ASE_NULL; - ase_lsp_lockobj (lsp, obj); - return obj; - - case TOKEN_REAL: - obj = ase_lsp_makerealobj (lsp->mem, TOKEN_RVAL(lsp)); - if (obj == ASE_NULL) return ASE_NULL; - ase_lsp_lockobj (lsp, obj); - return obj; - - case TOKEN_STRING: - obj = ase_lsp_makestr ( - lsp->mem, TOKEN_SPTR(lsp), TOKEN_SLEN(lsp)); - if (obj == ASE_NULL) return ASE_NULL; - ase_lsp_lockobj (lsp, obj); - return obj; - - case TOKEN_IDENT: - ASE_ASSERT ( - lsp->mem->nil != ASE_NULL && - lsp->mem->t != ASE_NULL); - - if (TOKEN_COMPARE(lsp,ASE_T("nil")) == 0) - { - obj = lsp->mem->nil; - } - else if (TOKEN_COMPARE(lsp,ASE_T("t")) == 0) - { - obj = lsp->mem->t; - } - else - { - obj = ase_lsp_makesym ( - lsp->mem, - TOKEN_SPTR(lsp), - TOKEN_SLEN(lsp)); - if (obj == ASE_NULL) return ASE_NULL; - ase_lsp_lockobj (lsp, obj); - } - - return obj; - } - - ase_lsp_seterror (lsp, ASE_LSP_ESYNTAX, ASE_NULL, 0); - return ASE_NULL; -} - -static ase_lsp_obj_t* read_list (ase_lsp_t* lsp) -{ - ase_lsp_obj_t* obj; - ase_lsp_obj_cons_t* p, * first = ASE_NULL, * prev = ASE_NULL; - - while (TOKEN_TYPE(lsp) != TOKEN_RPAREN) - { - if (TOKEN_TYPE(lsp) == TOKEN_END) - { - /* unexpected end of input */ - ase_lsp_seterror (lsp, ASE_LSP_ESYNTAX, ASE_NULL, 0); - return ASE_NULL; - } - - if (TOKEN_TYPE(lsp) == TOKEN_DOT) - { - if (prev == ASE_NULL) - { - /* unexpected dot */ - ase_lsp_seterror (lsp, ASE_LSP_ESYNTAX, ASE_NULL, 0); - return ASE_NULL; - } - - NEXT_TOKEN (lsp); - obj = read_obj (lsp); - if (obj == ASE_NULL) - { - if (lsp->errnum == ASE_LSP_EEND) - { - /* unexpected end of input */ - ase_lsp_seterror (lsp, ASE_LSP_ESYNTAX, ASE_NULL, 0); - } - return ASE_NULL; - } - prev->cdr = obj; - - NEXT_TOKEN (lsp); - if (TOKEN_TYPE(lsp) != TOKEN_RPAREN) - { - /* ) expected */ - ase_lsp_seterror (lsp, ASE_LSP_ERPAREN, ASE_NULL, 0); - return ASE_NULL; - } - - break; - } - - obj = read_obj (lsp); - if (obj == ASE_NULL) - { - if (lsp->errnum == ASE_LSP_EEND) - { - /* unexpected end of input */ - ase_lsp_seterror (lsp, ASE_LSP_ESYNTAX, ASE_NULL, 0); - } - return ASE_NULL; - } - - p = (ase_lsp_obj_cons_t*)ase_lsp_makecons ( - lsp->mem, lsp->mem->nil, lsp->mem->nil); - if (p == ASE_NULL) return ASE_NULL; - ase_lsp_lockobj (lsp, (ase_lsp_obj_t*)p); - - if (first == ASE_NULL) first = p; - if (prev != ASE_NULL) prev->cdr = (ase_lsp_obj_t*)p; - - p->car = obj; - prev = p; - - NEXT_TOKEN (lsp); - } - - return (first == ASE_NULL)? lsp->mem->nil: (ase_lsp_obj_t*)first; -} - -static ase_lsp_obj_t* read_quote (ase_lsp_t* lsp) -{ - ase_lsp_obj_t* cons, * tmp; - - tmp = read_obj (lsp); - if (tmp == ASE_NULL) - { - if (lsp->errnum == ASE_LSP_EEND) - { - /* unexpected end of input */ - ase_lsp_seterror (lsp, ASE_LSP_ESYNTAX, ASE_NULL, 0); - } - return ASE_NULL; - } - - cons = ase_lsp_makecons (lsp->mem, tmp, lsp->mem->nil); - if (cons == ASE_NULL) return ASE_NULL; - ase_lsp_lockobj (lsp, cons); - - cons = ase_lsp_makecons (lsp->mem, lsp->mem->quote, cons); - if (cons == ASE_NULL) return ASE_NULL; - ase_lsp_lockobj (lsp, cons); - - return cons; -} - -static int read_char (ase_lsp_t* lsp) -{ - ase_ssize_t n; - ase_char_t c; - - if (lsp->input_func == ASE_NULL) - { - ase_lsp_seterror (lsp, ASE_LSP_ENOINP, ASE_NULL, 0); - return -1; - } - - n = lsp->input_func(ASE_LSP_IO_READ, lsp->input_arg, &c, 1); - if (n == -1) - { - ase_lsp_seterror (lsp, ASE_LSP_EINPUT, ASE_NULL, 0); - return -1; - } - - if (n == 0) lsp->curc = ASE_CHAR_EOF; - else lsp->curc = c; - return 0; -} - -static int read_token (ase_lsp_t* lsp) -{ - ASE_ASSERT (lsp->input_func != ASE_NULL); - - TOKEN_CLEAR (lsp); - - while (1) - { - /* skip white spaces */ - while (ASE_LSP_ISSPACE(lsp, lsp->curc)) NEXT_CHAR (lsp); - - /* skip the comments here */ - if (lsp->curc == ASE_T(';')) - { - do - { - NEXT_CHAR (lsp); - } - while (lsp->curc != ASE_T('\n') && - lsp->curc != ASE_CHAR_EOF); - } - else break; - } - - if (lsp->curc == ASE_CHAR_EOF) - { - TOKEN_TYPE(lsp) = TOKEN_END; - return 0; - } - else if (lsp->curc == ASE_T('(')) - { - TOKEN_ADD_CHAR (lsp, lsp->curc); - TOKEN_TYPE(lsp) = TOKEN_LPAREN; - NEXT_CHAR (lsp); - return 0; - } - else if (lsp->curc == ASE_T(')')) - { - TOKEN_ADD_CHAR (lsp, lsp->curc); - TOKEN_TYPE(lsp) = TOKEN_RPAREN; - NEXT_CHAR (lsp); - return 0; - } - else if (lsp->curc == ASE_T('\'')) - { - TOKEN_ADD_CHAR (lsp, lsp->curc); - TOKEN_TYPE(lsp) = TOKEN_QUOTE; - NEXT_CHAR (lsp); - return 0; - } - else if (lsp->curc == ASE_T('.')) - { - TOKEN_ADD_CHAR (lsp, lsp->curc); - TOKEN_TYPE(lsp) = TOKEN_DOT; - NEXT_CHAR (lsp); - return 0; - } - else if (lsp->curc == ASE_T('-')) - { - TOKEN_ADD_CHAR (lsp, lsp->curc); - NEXT_CHAR (lsp); - if (ASE_LSP_ISDIGIT(lsp,lsp->curc)) - { - return read_number (lsp, 1); - } - else if (IS_IDENT(lsp->curc)) - { - return read_ident (lsp); - } - else - { - TOKEN_TYPE(lsp) = TOKEN_IDENT; - return 0; - } - } - else if (ASE_LSP_ISDIGIT(lsp,lsp->curc)) - { - return read_number (lsp, 0); - } - else if (ASE_LSP_ISALPHA(lsp,lsp->curc) || IS_IDENT(lsp->curc)) - { - return read_ident (lsp); - } - else if (lsp->curc == ASE_T('\"')) - { - return read_string (lsp); - } - - TOKEN_TYPE(lsp) = TOKEN_INVALID; - NEXT_CHAR (lsp); /* consume */ - return 0; -} - -static int read_number (ase_lsp_t* lsp, int negative) -{ - ase_long_t ival = 0; - ase_real_t rval = .0; - - do - { - ival = ival * 10 + (lsp->curc - ASE_T('0')); - TOKEN_ADD_CHAR (lsp, lsp->curc); - NEXT_CHAR (lsp); - } - while (ASE_LSP_ISDIGIT(lsp, lsp->curc)); - -/* TODO: extend parsing floating point number */ - if (lsp->curc == ASE_T('.')) - { - ase_real_t fraction = 0.1; - - NEXT_CHAR (lsp); - rval = (ase_real_t)ival; - - while (ASE_LSP_ISDIGIT(lsp, lsp->curc)) - { - rval += (ase_real_t)(lsp->curc - ASE_T('0')) * fraction; - fraction *= 0.1; - NEXT_CHAR (lsp); - } - - TOKEN_RVAL(lsp) = rval; - TOKEN_TYPE(lsp) = TOKEN_REAL; - if (negative) rval *= -1; - } - else - { - TOKEN_IVAL(lsp) = ival; - TOKEN_TYPE(lsp) = TOKEN_INT; - if (negative) ival *= -1; - } - - return 0; -} - -static int read_ident (ase_lsp_t* lsp) -{ - do - { - TOKEN_ADD_CHAR (lsp, lsp->curc); - NEXT_CHAR (lsp); - } - while (ASE_LSP_ISALNUM(lsp,lsp->curc) || IS_IDENT(lsp->curc)); - TOKEN_TYPE(lsp) = TOKEN_IDENT; - return 0; -} - -static int read_string (ase_lsp_t* lsp) -{ - ase_cint_t c; - int escaped = 0; - int digit_count = 0; - ase_cint_t c_acc = 0; - - while (1) - { - NEXT_CHAR_TO (lsp, c); - - if (c == ASE_CHAR_EOF) - { - ase_lsp_seterror (lsp, ASE_LSP_EENDSTR, ASE_NULL, 0); - return -1; - } - - if (escaped == 3) - { - if (c >= ASE_T('0') && c <= ASE_T('7')) - { - c_acc = c_acc * 8 + c - ASE_T('0'); - digit_count++; - if (digit_count >= escaped) - { - TOKEN_ADD_CHAR (lsp, c_acc); - escaped = 0; - } - continue; - } - else - { - TOKEN_ADD_CHAR (lsp, c_acc); - escaped = 0; - } - } - else if (escaped == 2 || escaped == 4 || escaped == 8) - { - if (c >= ASE_T('0') && c <= ASE_T('9')) - { - c_acc = c_acc * 16 + c - ASE_T('0'); - digit_count++; - if (digit_count >= escaped) - { - TOKEN_ADD_CHAR (lsp, c_acc); - escaped = 0; - } - continue; - } - else if (c >= ASE_T('A') && c <= ASE_T('F')) - { - c_acc = c_acc * 16 + c - ASE_T('A') + 10; - digit_count++; - if (digit_count >= escaped) - { - TOKEN_ADD_CHAR (lsp, c_acc); - escaped = 0; - } - continue; - } - else if (c >= ASE_T('a') && c <= ASE_T('f')) - { - c_acc = c_acc * 16 + c - ASE_T('a') + 10; - digit_count++; - if (digit_count >= escaped) - { - TOKEN_ADD_CHAR (lsp, c_acc); - escaped = 0; - } - continue; - } - else - { - ase_char_t rc; - - rc = (escaped == 2)? ASE_T('x'): - (escaped == 4)? ASE_T('u'): ASE_T('U'); - - if (digit_count == 0) TOKEN_ADD_CHAR (lsp, rc); - else TOKEN_ADD_CHAR (lsp, c_acc); - - escaped = 0; - } - } - - if (escaped == 0 && c == ASE_T('\"')) - { - /* terminating quote */ - /*NEXT_CHAR_TO (lsp, c);*/ - NEXT_CHAR (lsp); - break; - } - - if (escaped == 0 && c == ASE_T('\\')) - { - escaped = 1; - continue; - } - - if (escaped == 1) - { - if (c == ASE_T('n')) c = ASE_T('\n'); - else if (c == ASE_T('r')) c = ASE_T('\r'); - else if (c == ASE_T('t')) c = ASE_T('\t'); - else if (c == ASE_T('f')) c = ASE_T('\f'); - else if (c == ASE_T('b')) c = ASE_T('\b'); - else if (c == ASE_T('v')) c = ASE_T('\v'); - else if (c == ASE_T('a')) c = ASE_T('\a'); - else if (c >= ASE_T('0') && c <= ASE_T('7')) - { - escaped = 3; - digit_count = 1; - c_acc = c - ASE_T('0'); - continue; - } - else if (c == ASE_T('x')) - { - escaped = 2; - digit_count = 0; - c_acc = 0; - continue; - } - #ifdef ASE_CHAR_IS_WCHAR - else if (c == ASE_T('u') && ASE_SIZEOF(ase_char_t) >= 2) - { - escaped = 4; - digit_count = 0; - c_acc = 0; - continue; - } - else if (c == ASE_T('U') && ASE_SIZEOF(ase_char_t) >= 4) - { - escaped = 8; - digit_count = 0; - c_acc = 0; - continue; - } - #endif - - escaped = 0; - } - - TOKEN_ADD_CHAR (lsp, c); - } - - TOKEN_TYPE(lsp) = TOKEN_STRING; - return 0; -} diff --git a/ase/makefile.in b/ase/makefile.in deleted file mode 100644 index 5b4c8b80..00000000 --- a/ase/makefile.in +++ /dev/null @@ -1,63 +0,0 @@ -# -# $Id: makefile.in,v 1.1.1.1 2007/03/28 14:05:12 bacon Exp $ -# - - -LIBDIRS=cmn awk lsp utl -MODE=@BUILDMODE@ - -all: libs #incs - -incs: - @for i in $(LIBDIRS); \ - do \ - if [ ! -d $$i ]; \ - then \ - echo Error: $$i not a directory; \ - exit 1; \ - fi; \ - cd $$i; \ - if make inc; \ - then \ - echo > /dev/null; \ - else \ - exit 1; \ - fi; \ - cd ..; \ - done - -libs: - @for i in $(LIBDIRS); \ - do \ - if [ ! -d $$i ]; \ - then \ - echo Error: $$i not a directory; \ - exit 1; \ - fi; \ - cd $$i; \ - if make lib; \ - then \ - echo > /dev/null; \ - else \ - exit 1; \ - fi; \ - cd ..; \ - done - -clean: - @for i in $(LIBDIRS); \ - do \ - if [ ! -d $$i ]; \ - then \ - echo Error: $$i not a directory; \ - exit 1; \ - fi; \ - cd $$i; \ - if make $@; \ - then \ - echo > /dev/null; \ - else \ - exit 1; \ - fi; \ - cd ..; \ - done diff --git a/ase/rel/doc.awk b/ase/rel/doc.awk deleted file mode 100644 index 0284d75c..00000000 --- a/ase/rel/doc.awk +++ /dev/null @@ -1,266 +0,0 @@ -/* - * $Id: doc.awk,v 1.1.1.1 2007/03/28 14:05:25 bacon Exp $ - * - * {License} - */ - -global header, mode; -global empty_line_count; -global para_started; -global list_count; - -func print_text (full) -{ - local fra1, fra2, link, idx, t1, t2; - - gsub ("<", "\\<", full); - gsub (">", "\\>", full); - - while (match (full, /\{[^{},]+,[^{},]+\}/) > 0) - { - fra1 = substr (full, 1, RSTART-1); - link = substr (full, RSTART, RLENGTH); - fra2 = substr (full, RSTART+RLENGTH, length(full)-RLENGTH); - - idx = index(link, ","); - t1 = substr (link, 2, idx-2); - t2 = substr (link, idx+1, length(link)-idx-1); - - full = sprintf ("%s%s%s", fra1, t2, t1, fra2); - } - - while (match (full, /\[\[[^\[\][:space:]]+\]\]/) > 0) - { - fra1 = substr (full, 1, RSTART-1); - link = substr (full, RSTART+2, RLENGTH-4); - fra2 = substr (full, RSTART+RLENGTH, length(full)-RLENGTH); - - full = sprintf ("%s%s%s", fra1, link, fra2); - } - - while (match (full, /##[^#[:space:]]+##/) > 0) - { - fra1 = substr (full, 1, RSTART-1); - link = substr (full, RSTART+2, RLENGTH-4); - fra2 = substr (full, RSTART+RLENGTH, length(full)-RLENGTH); - - full = sprintf ("%s%s%s", fra1, link, fra2); - } - - print full; -} - -BEGIN { - header = 1; - mode = 0; - empty_line_count = 0; - para_started = 0; - - #output=ARGV[0]; - #gsub (/\.man/, ".html", output); - #print "OUTPUT TO: " output; - - print ""; - print ""; - print ""; - print ""; -} - -header && /^\.[[:alpha:]]+[[:space:]]/ { - if ($1 == ".title") - { - local i; - - printf ""; - for (i = 2; i <= NF; i++) printf "%s ", $i; - print ""; - } -} - -header && !/^\.[[:alpha:]]+[[:space:]]/ { - - header = 0; - print ""; - print ""; -} - -!header { - local text; - - if (mode == 0) - { - if (/^$/) - { - # empty line - if (para_started) - { - para_started = 0; - print "

"; - } - empty_line_count++; - } - else - { - if (/^= [^=]+ =$/) - { - if (para_started) - { - print "

"; - para_started = 0; - } - text=substr($0, 2, length($0)-2); - print "

" text "

"; - } - else if (/^== [^=]+ ==$/) - { - if (para_started) - { - print "

"; - para_started = 0; - } - text=substr($0, 3, length($0)-4); - print "

" text "

"; - } - else if (/^=== [^=]+ ===$/) - { - if (para_started) - { - print "

"; - para_started = 0; - } - text=substr($0, 4, length($0)-6); - print "

" text "

"; - } - else if (/^==== [^=]+ ====$/) - { - if (para_started) - { - print "

"; - para_started = 0; - } - text=substr($0, 5, length($0)-8); - print "

" text "

"; - } - else if (/^\{\{\{$/) - { - # {{{ - if (para_started) - { - print "

"; - para_started = 0; - } - print "
";
-				mode = 1;
-			}
-			else if (/\[\[\[/)
-			{
-				if (para_started)
-				{
-					print "

"; - para_started = 0; - } - print "
    "; - mode = 2; - list_count = 0; - } - else if (/\(\(\(/) - { - if (para_started) - { - print "

    "; - para_started = 0; - } - print "
      "; - mode = 3; - list_count = 0; - } - else - { - if (!para_started > 0) - { - print "

      "; - para_started = 1; - } - - /* - gsub ("<", "\\<"); - gsub (">", "\\>"); - print $0; - */ - - print_text ($0); - print "
      "; - } - - empty_line_count = 0; - } - } - else if (mode == 1) - { - if (/^}}}$/) - { - # }}} - print "

"; - mode = 0; - } - else - { - gsub ("<", "\\<"); - gsub (">", "\\>"); - print $0; - } - } - else if (mode == 2) - { - if (/^]]]$/) - { - # ]]] - print ""; - print ""; - mode = 0; - } - else if (/^\* [^[:space:]]+/) - { - gsub ("<", "\\<"); - gsub (">", "\\>"); - if (list_count > 0) print ""; - print "
  • "; - - print_text (substr ($0, 3, length($0)-2)); - list_count++; - } - else - { - print_text ($0); - } - } - else if (mode == 3) - { - if (/^\)\)\)$/) - { - # ))) - print "
  • "; - print ""; - mode = 0; - } - else if (/^\* [^[:space:]]+/) - { - gsub ("<", "\\<"); - gsub (">", "\\>"); - if (list_count > 0) print ""; - print "
  • "; - - print_text (substr ($0, 3, length($0)-2)); - list_count++; - } - else - { - print_text ($0); - } - } -} - -END { - print ""; - print ""; -} diff --git a/ase/rel/lic.awk b/ase/rel/lic.awk deleted file mode 100644 index 9be1d630..00000000 --- a/ase/rel/lic.awk +++ /dev/null @@ -1,21 +0,0 @@ -/* - * $Id: lic.awk,v 1.1.1.1 2007/03/28 14:05:25 bacon Exp $ - * - * {License} - */ - -NR == 1 { - new_file = ARGV[0]; - printf "" > new_file; /* clear the file */ -} - -/^ \* \{License\}/ { - print " * Copyright (c) 2007, Hyung-Hwan Chung." >> new_file; - print " * All rights reserved." >> new_file; - print " * Licensed under the BSD license: " >> new_file; - print " * http://www.abiyo.net/ase/license.html" >> new_file; -} - -!/^ \* \{License\}/ { - print $0 >> new_file; -} diff --git a/ase/rel/rel.sh b/ase/rel/rel.sh deleted file mode 100755 index 32e2a33a..00000000 --- a/ase/rel/rel.sh +++ /dev/null @@ -1,144 +0,0 @@ -#!/bin/sh - -finalize () -{ - cur="$1"; dir="$2"; - - if [ "$dir" = "" ] - then - cd "$BASE" - else - cd "$BASE/$dir" - fi - - for i in * - do - if [ "$i" = "*" ]; then continue; fi - if [ "$i" = "CVS" ]; then continue; fi - if [ "$i" = "stx" ]; then continue; fi - - if [ "$cur" = "" ] - then - file="$i" - full="$BASE/$i" - else - file="$cur/$i" - full="$BASE/$cur/$i" - fi - - if [ -d "$full" ] - then - if [ "$dir" = "" ] - then - new="$i" - else - new="$dir/$i" - fi - - finalize "$file" "$new" - cur="$1"; dir="$2"; - elif [ -f "$full" ] - then - target="$SOURCE_ROOT/ase" - mkdir -p "$target/$cur" - - case "$i" in - *.h|*.c|*.cc|*.cpp|*.java|*.awk|*.in) - "$ASEAWK" -f "$BASE/rel/lic.awk" -a "$target/$file" "$full" - ;; - *.man) - html=`echo $i | sed 's/.man$/.html/'` - "$ASEAWK" -f "$BASE/rel/doc.awk" "$full" > "$SOURCE_ROOT/html/$html" - "$ASEAWK" -f "$BASE/rel/doc.awk" "$full" > "$ASETGT/$html" - cp -f "$full" "$target/$file" - ;; - *.css) - cp -f "$full" "$target/$file" - cp -f "$full" "$SOURCE_ROOT/html/$i" - cp -f "$full" "$ASETGT/$i" - ;; - *.dsp|*.dsw|*.sln|*.vcproj|*.bat|*.cmd) - "$ASEAWK" -f "$BASE/rel/unix2dos.awk" "$full" > "$target/$file" - ;; - descrip.mms) - "$ASEAWK" -f "$BASE/rel/unix2dos.awk" "$full" > "$target/$file" - ;; - *.frx) - cp -f "$full" "$target/$file" - ;; - *) - if [ "$dir" = "test/com" ] - then - "$ASEAWK" -f "$BASE/rel/unix2dos.awk" "$full" > "$target/$file" - else - cp -f "$full" "$target/$file" - fi - ;; - esac - fi - done -} - - -print_usage () -{ - echo "Usage: $0 awk version target archiver" - echo "where awk := full path to aseawk" - echo " version := any string" - echo " target := full path to the target directory" - echo " archiver := gzip | zip" -} - -############################ -# BEGINNING OF THE PROGRAM # -############################ - -if [ $# -ne 4 ] -then - print_usage "$0" - exit 1 -fi - -if [ "$4" != "gzip" -a "$4" != "zip" ] -then - print_usage "$0" - exit 1 -fi - -ASEAWK="$1" -ASEVER="$2" -ASETGT="$3" -ASEARC="$4" - -CURDIR=`pwd` -cd ".." -BASE=`pwd` - -SOURCE_ROOT="$ASETGT/ase-$ASEVER" - -rm -rf "$ASETGT" -mkdir -p "$ASETGT" -mkdir -p "$SOURCE_ROOT" -mkdir -p "$SOURCE_ROOT/html" - -finalize "" "" - -cd "$ASETGT" - -if [ "$ASEARC" = "gzip" ] -then - tar -cvf "ase-$ASEVER.tar" "ase-$ASEVER" - gzip "ase-$ASEVER.tar" - mv "ase-$ASEVER.tar.gz" "ase-$ASEVER.tgz" -elif [ "$ASEARC" = "zip" ] -then - ls -l - echo zip -r "ase-$ASEVER" "ase-$ASEVER" - zip -r ase "ase-$ASEVER" - mv -f ase.zip "ase-$ASEVER.zip" -fi - -rm -rf "ase-$ASEVER" - -cd "$CURDIR" -exit 0 diff --git a/ase/rel/unix2dos.awk b/ase/rel/unix2dos.awk deleted file mode 100644 index b8a6e3ef..00000000 --- a/ase/rel/unix2dos.awk +++ /dev/null @@ -1,2 +0,0 @@ -BEGIN { ORS="\r\n"; } -{ print $0; } diff --git a/ase/stx/array.c b/ase/stx/array.c deleted file mode 100644 index 1758d601..00000000 --- a/ase/stx/array.c +++ /dev/null @@ -1,18 +0,0 @@ -/* - * $Id: array.c,v 1.1.1.1 2007/03/28 14:05:25 bacon Exp $ - */ - -#include -#include -#include - -ase_word_t ase_stx_new_array (ase_stx_t* stx, ase_word_t size) -{ - ase_word_t x; - - ase_assert (stx->class_array != stx->nil); - x = ase_stx_alloc_word_object (stx, ASE_NULL, 0, ASE_NULL, size); - ASE_STX_CLASS(stx,x) = stx->class_array; - - return x; -} diff --git a/ase/stx/array.h b/ase/stx/array.h deleted file mode 100644 index 760a6d29..00000000 --- a/ase/stx/array.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * $Id: array.h,v 1.1.1.1 2007/03/28 14:05:25 bacon Exp $ - */ - -#ifndef _ASE_STX_ARRAY_H_ -#define _ASE_STX_ARRAY_H_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -ase_word_t ase_stx_new_array (ase_stx_t* stx, ase_word_t size); - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/ase/stx/bootstrp.c b/ase/stx/bootstrp.c deleted file mode 100644 index b587cfb8..00000000 --- a/ase/stx/bootstrp.c +++ /dev/null @@ -1,676 +0,0 @@ -/* - * $Id: bootstrp.c,v 1.1.1.1 2007/03/28 14:05:25 bacon Exp $ - */ - -#include -#include -#include -#include -#include -#include - -static void __create_bootstrapping_objects (ase_stx_t* stx); -static void __create_builtin_classes (ase_stx_t* stx); -static ase_word_t __make_classvar_dict ( - ase_stx_t* stx, ase_word_t class, const ase_char_t* names); -static void __filein_kernel (ase_stx_t* stx); - -static ase_word_t __count_names (const ase_char_t* str); -static void __set_names ( - ase_stx_t* stx, ase_word_t* array, const ase_char_t* str); - -static ase_word_t __count_subclasses (const ase_char_t* str); -static void __set_subclasses ( - ase_stx_t* stx, ase_word_t* array, const ase_char_t* str); -static void __set_metaclass_subclasses ( - ase_stx_t* stx, ase_word_t* array, const ase_char_t* str); - -struct class_info_t -{ - const ase_char_t* name; - const ase_char_t* superclass; - const ase_char_t* instance_variables; - const ase_char_t* class_variables; - const ase_char_t* pool_dictionaries; - const int indexable; -}; - -typedef struct class_info_t class_info_t; - -static class_info_t class_info[] = -{ - { - ASE_T("Object"), - ASE_NULL, - ASE_NULL, - ASE_NULL, - ASE_NULL, - ASE_STX_SPEC_NOT_INDEXABLE - }, - { - ASE_T("UndefinedObject"), - ASE_T("Object"), - ASE_NULL, - ASE_NULL, - ASE_NULL, - ASE_STX_SPEC_NOT_INDEXABLE - }, - { - ASE_T("Behavior"), - ASE_T("Object"), - ASE_T("spec methods superclass"), - ASE_NULL, - ASE_NULL, - ASE_STX_SPEC_NOT_INDEXABLE - }, - { - ASE_T("Class"), - ASE_T("Behavior"), - ASE_T("name variables classVariables poolDictionaries"), - ASE_NULL, - ASE_NULL, - ASE_STX_SPEC_NOT_INDEXABLE - }, - { - ASE_T("Metaclass"), - ASE_T("Behavior"), - ASE_T("instanceClass"), - ASE_NULL, - ASE_NULL, - ASE_STX_SPEC_NOT_INDEXABLE - }, - { - ASE_T("Block"), - ASE_T("Object"), - ASE_T("context argCount argLoc bytePointer"), - ASE_NULL, - ASE_NULL, - ASE_STX_SPEC_NOT_INDEXABLE - }, - { - ASE_T("Boolean"), - ASE_T("Object"), - ASE_NULL, - ASE_NULL, - ASE_NULL, - ASE_STX_SPEC_NOT_INDEXABLE - }, - { - ASE_T("True"), - ASE_T("Boolean"), - ASE_NULL, - ASE_NULL, - ASE_NULL, - ASE_STX_SPEC_NOT_INDEXABLE - }, - { - ASE_T("False"), - ASE_T("Boolean"), - ASE_NULL, - ASE_NULL, - ASE_NULL, - ASE_STX_SPEC_NOT_INDEXABLE - }, - { - ASE_T("Context"), - ASE_T("Object"), - ASE_T("stack stackTop receiver pc method"), - ASE_NULL, - ASE_NULL, - ASE_STX_SPEC_NOT_INDEXABLE - }, - { - ASE_T("Method"), - ASE_T("Object"), - ASE_T("text selector bytecodes tmpCount argCount"), - ASE_NULL, - ASE_NULL, - ASE_STX_SPEC_WORD_INDEXABLE - }, - { - ASE_T("Magnitude"), - ASE_T("Object"), - ASE_NULL, - ASE_NULL, - ASE_NULL, - ASE_STX_SPEC_NOT_INDEXABLE - }, - { - ASE_T("Association"), - ASE_T("Magnitude"), - ASE_T("key value"), - ASE_NULL, - ASE_NULL, - ASE_STX_SPEC_NOT_INDEXABLE - }, - { - ASE_T("Character"), - ASE_T("Magnitude"), - ASE_T("value"), - ASE_NULL, - ASE_NULL, - ASE_STX_SPEC_NOT_INDEXABLE - }, - { - ASE_T("Number"), - ASE_T("Magnitude"), - ASE_NULL, - ASE_NULL, - ASE_NULL, - ASE_STX_SPEC_NOT_INDEXABLE - }, - { - ASE_T("Integer"), - ASE_T("Number"), - ASE_NULL, - ASE_NULL, - ASE_NULL, - ASE_STX_SPEC_NOT_INDEXABLE - }, - { - ASE_T("SmallInteger"), - ASE_T("Integer"), - ASE_NULL, - ASE_NULL, - ASE_NULL, - ASE_STX_SPEC_NOT_INDEXABLE - }, - { - ASE_T("LargeInteger"), - ASE_T("Integer"), - ASE_NULL, - ASE_NULL, - ASE_NULL, - ASE_STX_SPEC_BYTE_INDEXABLE - }, - { - ASE_T("Collection"), - ASE_T("Magnitude"), - ASE_NULL, - ASE_NULL, - ASE_NULL, - ASE_STX_SPEC_NOT_INDEXABLE - }, - { - ASE_T("IndexedCollection"), - ASE_T("Collection"), - ASE_NULL, - ASE_NULL, - ASE_NULL, - ASE_STX_SPEC_NOT_INDEXABLE - }, - { - ASE_T("Array"), - ASE_T("IndexedCollection"), - ASE_NULL, - ASE_NULL, - ASE_NULL, - ASE_STX_SPEC_WORD_INDEXABLE - }, - { - ASE_T("ByteArray"), - ASE_T("IndexedCollection"), - ASE_NULL, - ASE_NULL, - ASE_NULL, - ASE_STX_SPEC_BYTE_INDEXABLE - }, - { - ASE_T("Dictionary"), - ASE_T("IndexedCollection"), - ASE_T("tally"), - ASE_NULL, - ASE_NULL, - ASE_STX_SPEC_WORD_INDEXABLE - }, - { - ASE_T("SystemDictionary"), - ASE_T("Dictionary"), - ASE_NULL, - ASE_NULL, - ASE_NULL, - ASE_STX_SPEC_WORD_INDEXABLE - }, - { - ASE_T("PoolDictionary"), - ASE_T("Dictionary"), - ASE_NULL, - ASE_NULL, - ASE_NULL, - ASE_STX_SPEC_WORD_INDEXABLE - }, - { - ASE_T("String"), - ASE_T("IndexedCollection"), - ASE_NULL, - ASE_NULL, - ASE_NULL, - ASE_STX_SPEC_CHAR_INDEXABLE - }, - { - ASE_T("Symbol"), - ASE_T("String"), - ASE_NULL, - ASE_NULL, - ASE_NULL, - ASE_STX_SPEC_CHAR_INDEXABLE - }, - { - ASE_T("Link"), - ASE_T("Object"), - ASE_T("link"), - ASE_NULL, - ASE_NULL, - ASE_STX_SPEC_NOT_INDEXABLE - }, - { - ASE_NULL, - ASE_NULL, - ASE_NULL, - ASE_NULL, - ASE_NULL, - ASE_STX_SPEC_NOT_INDEXABLE - } -}; - -ase_word_t INLINE __new_string (ase_stx_t* stx, const ase_char_t* str) -{ - ase_word_t x; - - ase_assert (stx->class_string != stx->nil); - x = ase_stx_alloc_char_object (stx, str); - ASE_STX_CLASS(stx,x) = stx->class_string; - - return x; -} - -int ase_stx_bootstrap (ase_stx_t* stx) -{ - ase_word_t symbol_Smalltalk; - ase_word_t object_meta; - - __create_bootstrapping_objects (stx); - - /* object, class, and array are precreated for easier instantiation - * of builtin classes */ - stx->class_object = ase_stx_new_class (stx, ASE_T("Object")); - stx->class_class = ase_stx_new_class (stx, ASE_T("Class")); - stx->class_array = ase_stx_new_class (stx, ASE_T("Array")); - stx->class_bytearray = ase_stx_new_class (stx, ASE_T("ByteArray")); - stx->class_string = ase_stx_new_class (stx, ASE_T("String")); - stx->class_character = ase_stx_new_class (stx, ASE_T("Character")); - stx->class_context = ase_stx_new_class (stx, ASE_T("Context")); - stx->class_system_dictionary = - ase_stx_new_class (stx, ASE_T("SystemDictionary")); - stx->class_method = - ase_stx_new_class (stx, ASE_T("Method")); - stx->class_smallinteger = - ase_stx_new_class (stx, ASE_T("SmallInteger")); - - __create_builtin_classes (stx); - - /* (Object class) setSuperclass: Class */ - object_meta = ASE_STX_CLASS(stx,stx->class_object); - ASE_STX_WORD_AT(stx,object_meta,ASE_STX_METACLASS_SUPERCLASS) = stx->class_class; - /* instance class for Object is set here as it is not - * set in __create_builtin_classes */ - ASE_STX_WORD_AT(stx,object_meta,ASE_STX_METACLASS_INSTANCE_CLASS) = stx->class_object; - - /* for some fun here */ - { - ase_word_t array; - array = ase_stx_new_array (stx, 1); - ASE_STX_WORD_AT(stx,array,0) = object_meta; - ASE_STX_WORD_AT(stx,stx->class_class,ASE_STX_CLASS_SUBCLASSES) = array; - } - - /* more initialization */ - ASE_STX_CLASS(stx,stx->smalltalk) = stx->class_system_dictionary; - - symbol_Smalltalk = ase_stx_new_symbol (stx, ASE_T("Smalltalk")); - ase_stx_dict_put (stx, stx->smalltalk, symbol_Smalltalk, stx->smalltalk); - - /* create #nil, #true, #false */ - ase_stx_new_symbol (stx, ASE_T("nil")); - ase_stx_new_symbol (stx, ASE_T("true")); - ase_stx_new_symbol (stx, ASE_T("false")); - - /* nil setClass: UndefinedObject */ - ASE_STX_CLASS(stx,stx->nil) = - ase_stx_lookup_class(stx, ASE_T("UndefinedObject")); - /* true setClass: True */ - ASE_STX_CLASS(stx,stx->true) = - ase_stx_lookup_class (stx, ASE_T("True")); - /* fales setClass: False */ - ASE_STX_CLASS(stx,stx->false) = - ase_stx_lookup_class (stx, ASE_T("False")); - - __filein_kernel (stx); - return 0; -} - -static void __create_bootstrapping_objects (ase_stx_t* stx) -{ - ase_word_t class_SymbolMeta; - ase_word_t class_MetaclassMeta; - ase_word_t class_AssociationMeta; - ase_word_t symbol_Symbol; - ase_word_t symbol_Metaclass; - ase_word_t symbol_Association; - - /* allocate three keyword objects */ - stx->nil = ase_stx_alloc_word_object (stx, ASE_NULL, 0, ASE_NULL, 0); - stx->true = ase_stx_alloc_word_object (stx, ASE_NULL, 0, ASE_NULL, 0); - stx->false = ase_stx_alloc_word_object (stx, ASE_NULL, 0, ASE_NULL, 0); - - ase_assert (stx->nil == ASE_STX_NIL); - ase_assert (stx->true == ASE_STX_TRUE); - ase_assert (stx->false == ASE_STX_FALSE); - - /* system dictionary */ - /* TODO: dictionary size */ - stx->smalltalk = ase_stx_alloc_word_object ( - stx, ASE_NULL, 1, ASE_NULL, 256); - /* set tally */ - ASE_STX_WORD_AT(stx,stx->smalltalk,0) = ASE_STX_TO_SMALLINT(0); - - /* Symbol */ - stx->class_symbol = ase_stx_alloc_word_object( - stx, ASE_NULL, ASE_STX_CLASS_SIZE, ASE_NULL, 0); - /* Metaclass */ - stx->class_metaclass = ase_stx_alloc_word_object( - stx, ASE_NULL, ASE_STX_CLASS_SIZE, ASE_NULL, 0); - /* Association */ - stx->class_association = ase_stx_alloc_word_object( - stx, ASE_NULL, ASE_STX_CLASS_SIZE, ASE_NULL, 0); - - /* Metaclass is a class so it has the same structure - * as a normal class. "Metaclass class" is an instance of - * Metaclass. */ - - /* Symbol class */ - class_SymbolMeta = ase_stx_alloc_word_object( - stx, ASE_NULL, ASE_STX_METACLASS_SIZE, ASE_NULL, 0); - /* Metaclass class */ - class_MetaclassMeta = ase_stx_alloc_word_object( - stx, ASE_NULL, ASE_STX_METACLASS_SIZE, ASE_NULL, 0); - /* Association class */ - class_AssociationMeta = ase_stx_alloc_word_object( - stx, ASE_NULL, ASE_STX_METACLASS_SIZE, ASE_NULL, 0); - - /* (Symbol class) setClass: Metaclass */ - ASE_STX_CLASS(stx,class_SymbolMeta) = stx->class_metaclass; - /* (Metaclass class) setClass: Metaclass */ - ASE_STX_CLASS(stx,class_MetaclassMeta) = stx->class_metaclass; - /* (Association class) setClass: Metaclass */ - ASE_STX_CLASS(stx,class_AssociationMeta) = stx->class_metaclass; - - /* Symbol setClass: (Symbol class) */ - ASE_STX_CLASS(stx,stx->class_symbol) = class_SymbolMeta; - /* Metaclass setClass: (Metaclass class) */ - ASE_STX_CLASS(stx,stx->class_metaclass) = class_MetaclassMeta; - /* Association setClass: (Association class) */ - ASE_STX_CLASS(stx,stx->class_association) = class_AssociationMeta; - - /* (Symbol class) setSpec: CLASS_SIZE */ - ASE_STX_WORD_AT(stx,class_SymbolMeta,ASE_STX_CLASS_SPEC) = - ASE_STX_TO_SMALLINT((ASE_STX_CLASS_SIZE << ASE_STX_SPEC_INDEXABLE_BITS) | ASE_STX_SPEC_NOT_INDEXABLE); - /* (Metaclass class) setSpec: CLASS_SIZE */ - ASE_STX_WORD_AT(stx,class_MetaclassMeta,ASE_STX_CLASS_SPEC) = - ASE_STX_TO_SMALLINT((ASE_STX_CLASS_SIZE << ASE_STX_SPEC_INDEXABLE_BITS) | ASE_STX_SPEC_NOT_INDEXABLE); - /* (Association class) setSpec: CLASS_SIZE */ - ASE_STX_WORD_AT(stx,class_AssociationMeta,ASE_STX_CLASS_SPEC) = - ASE_STX_TO_SMALLINT((ASE_STX_CLASS_SIZE << ASE_STX_SPEC_INDEXABLE_BITS) | ASE_STX_SPEC_NOT_INDEXABLE); - - /* specs for class_metaclass, class_association, - * class_symbol are set later in __create_builtin_classes */ - - /* #Symbol */ - symbol_Symbol = ase_stx_new_symbol (stx, ASE_T("Symbol")); - /* #Metaclass */ - symbol_Metaclass = ase_stx_new_symbol (stx, ASE_T("Metaclass")); - /* #Association */ - symbol_Association = ase_stx_new_symbol (stx, ASE_T("Association")); - - /* Symbol setName: #Symbol */ - ASE_STX_WORD_AT(stx,stx->class_symbol,ASE_STX_CLASS_NAME) = symbol_Symbol; - /* Metaclass setName: #Metaclass */ - ASE_STX_WORD_AT(stx,stx->class_metaclass,ASE_STX_CLASS_NAME) = symbol_Metaclass; - /* Association setName: #Association */ - ASE_STX_WORD_AT(stx,stx->class_association,ASE_STX_CLASS_NAME) = symbol_Association; - - /* register class names into the system dictionary */ - ase_stx_dict_put (stx, - stx->smalltalk, symbol_Symbol, stx->class_symbol); - ase_stx_dict_put (stx, - stx->smalltalk, symbol_Metaclass, stx->class_metaclass); - ase_stx_dict_put (stx, - stx->smalltalk, symbol_Association, stx->class_association); -} - -static void __create_builtin_classes (ase_stx_t* stx) -{ - class_info_t* p; - ase_word_t class, superclass, array; - ase_stx_class_t* class_obj, * superclass_obj; - ase_word_t metaclass; - ase_stx_metaclass_t* metaclass_obj; - ase_word_t n, nfields; - - ase_assert (stx->class_array != stx->nil); - - for (p = class_info; p->name != ASE_NULL; p++) { - class = ase_stx_lookup_class(stx, p->name); - if (class == stx->nil) { - class = ase_stx_new_class (stx, p->name); - } - - ase_assert (class != stx->nil); - class_obj = (ase_stx_class_t*)ASE_STX_OBJECT(stx, class); - class_obj->superclass = (p->superclass == ASE_NULL)? - stx->nil: ase_stx_lookup_class(stx,p->superclass); - - nfields = 0; - if (p->superclass != ASE_NULL) { - ase_word_t meta; - ase_stx_metaclass_t* meta_obj; - - superclass = ase_stx_lookup_class(stx,p->superclass); - ase_assert (superclass != stx->nil); - - meta = class_obj->header.class; - meta_obj = (ase_stx_metaclass_t*)ASE_STX_OBJECT(stx,meta); - meta_obj->superclass = ASE_STX_CLASS(stx,superclass); - meta_obj->instance_class = class; - - while (superclass != stx->nil) { - superclass_obj = (ase_stx_class_t*) - ASE_STX_OBJECT(stx,superclass); - nfields += - ASE_STX_FROM_SMALLINT(superclass_obj->spec) >> - ASE_STX_SPEC_INDEXABLE_BITS; - superclass = superclass_obj->superclass; - } - - } - - if (p->instance_variables != ASE_NULL) { - nfields += __count_names (p->instance_variables); - class_obj->variables = - __new_string (stx, p->instance_variables); - } - - ase_assert (nfields <= 0 || (nfields > 0 && - (p->indexable == ASE_STX_SPEC_NOT_INDEXABLE || - p->indexable == ASE_STX_SPEC_WORD_INDEXABLE))); - - class_obj->spec = ASE_STX_TO_SMALLINT( - (nfields << ASE_STX_SPEC_INDEXABLE_BITS) | p->indexable); - } - - for (p = class_info; p->name != ASE_NULL; p++) { - class = ase_stx_lookup_class(stx, p->name); - ase_assert (class != stx->nil); - - class_obj = (ase_stx_class_t*)ASE_STX_OBJECT(stx, class); - - if (p->class_variables != ASE_NULL) { - class_obj->class_variables = - __make_classvar_dict(stx, class, p->class_variables); - } - - /* - TODO: - if (p->pool_dictionaries != ASE_NULL) { - class_obj->pool_dictionaries = - __make_pool_dictionary(stx, class, p->pool_dictionaries); - } - */ - } - - /* fill subclasses */ - for (p = class_info; p->name != ASE_NULL; p++) { - n = __count_subclasses (p->name); - array = ase_stx_new_array (stx, n); - __set_subclasses (stx, ASE_STX_DATA(stx,array), p->name); - - class = ase_stx_lookup_class(stx, p->name); - ase_assert (class != stx->nil); - class_obj = (ase_stx_class_t*)ASE_STX_OBJECT(stx, class); - class_obj->subclasses = array; - } - - /* fill subclasses for metaclasses */ - for (p = class_info; p->name != ASE_NULL; p++) { - n = __count_subclasses (p->name); - array = ase_stx_new_array (stx, n); - __set_metaclass_subclasses (stx, ASE_STX_DATA(stx,array), p->name); - - class = ase_stx_lookup_class(stx, p->name); - ase_assert (class != stx->nil); - metaclass = ASE_STX_CLASS(stx,class); - metaclass_obj = (ase_stx_metaclass_t*)ASE_STX_OBJECT(stx, metaclass); - metaclass_obj->subclasses = array; - } -} - -static ase_word_t __count_names (const ase_char_t* str) -{ - ase_word_t n = 0; - const ase_char_t* p = str; - - do { - while (*p == ASE_T(' ') || - *p == ASE_T('\t')) p++; - if (*p == ASE_T('\0')) break; - - n++; - while (*p != ASE_T(' ') && - *p != ASE_T('\t') && - *p != ASE_T('\0')) p++; - } while (1); - - return n; -} - -static void __set_names ( - ase_stx_t* stx, ase_word_t* array, const ase_char_t* str) -{ - ase_word_t n = 0; - const ase_char_t* p = str; - const ase_char_t* name; - - do { - while (*p == ASE_T(' ') || - *p == ASE_T('\t')) p++; - if (*p == ASE_T('\0')) break; - - name = p; - while (*p != ASE_T(' ') && - *p != ASE_T('\t') && - *p != ASE_T('\0')) p++; - - array[n++] = ase_stx_new_symbolx (stx, name, p - name); - } while (1); -} - -static ase_word_t __count_subclasses (const ase_char_t* str) -{ - class_info_t* p; - ase_word_t n = 0; - - for (p = class_info; p->name != ASE_NULL; p++) { - if (p->superclass == ASE_NULL) continue; - if (ase_strcmp (str, p->superclass) == 0) n++; - } - - return n; -} - -static void __set_subclasses ( - ase_stx_t* stx, ase_word_t* array, const ase_char_t* str) -{ - class_info_t* p; - ase_word_t n = 0, class; - - for (p = class_info; p->name != ASE_NULL; p++) { - if (p->superclass == ASE_NULL) continue; - if (ase_strcmp (str, p->superclass) != 0) continue; - class = ase_stx_lookup_class (stx, p->name); - ase_assert (class != stx->nil); - array[n++] = class; - } -} - -static void __set_metaclass_subclasses ( - ase_stx_t* stx, ase_word_t* array, const ase_char_t* str) -{ - class_info_t* p; - ase_word_t n = 0, class; - - for (p = class_info; p->name != ASE_NULL; p++) { - if (p->superclass == ASE_NULL) continue; - if (ase_strcmp (str, p->superclass) != 0) continue; - class = ase_stx_lookup_class (stx, p->name); - ase_assert (class != stx->nil); - array[n++] = ASE_STX_CLASS(stx,class); - } -} - -static ase_word_t __make_classvar_dict ( - ase_stx_t* stx, ase_word_t class, const ase_char_t* names) -{ - ase_word_t dict, symbol; - const ase_char_t* p = names; - const ase_char_t* name; - - dict = ase_stx_instantiate ( - stx, stx->class_system_dictionary, - ASE_NULL, ASE_NULL, __count_names(names)); - - do { - while (*p == ASE_T(' ') || - *p == ASE_T('\t')) p++; - if (*p == ASE_T('\0')) break; - - name = p; - while (*p != ASE_T(' ') && - *p != ASE_T('\t') && - *p != ASE_T('\0')) p++; - - symbol = ase_stx_new_symbolx (stx, name, p - name); - ase_stx_dict_put (stx, dict, symbol, stx->nil); - } while (1); - - return dict; -} - -static void __filein_kernel (ase_stx_t* stx) -{ - class_info_t* p; - - for (p = class_info; p->name != ASE_NULL; p++) { - /* TODO: */ - } -} - diff --git a/ase/stx/bootstrp.h b/ase/stx/bootstrp.h deleted file mode 100644 index ad407b22..00000000 --- a/ase/stx/bootstrp.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * $Id: bootstrp.h,v 1.1.1.1 2007/03/28 14:05:25 bacon Exp $ - */ - -#ifndef _ASE_STX_BOOTSTRP_H_ -#define _ASE_STX_BOOTSTRP_H_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -ase_word_t ase_stx_new_array (ase_stx_t* stx, ase_word_t size); -int ase_stx_bootstrap (ase_stx_t* stx); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ase/stx/bytecode.c b/ase/stx/bytecode.c deleted file mode 100644 index e3252413..00000000 --- a/ase/stx/bytecode.c +++ /dev/null @@ -1,193 +0,0 @@ -/* - * $Id: bytecode.c,v 1.1.1.1 2007/03/28 14:05:25 bacon Exp $ - */ -#include -#include -#include -#include - -static void __decode1 (ase_stx_t* stx, ase_word_t idx, void* data); -static int __decode2 (ase_stx_t* stx, - ase_stx_class_t* class_obj, ase_stx_method_t* method_obj); - -int ase_stx_decode (ase_stx_t* stx, ase_word_t class) -{ - ase_stx_class_t* class_obj; - - class_obj = (ase_stx_class_t*)ASE_STX_OBJECT(stx, class); - if (class_obj->methods == stx->nil) return 0; - -/* TODO */ - ase_stx_dict_traverse (stx, class_obj->methods, __decode1, class_obj); - return 0; -} - -#include -static void __dump_object (ase_stx_t* stx, ase_word_t obj) -{ - if (ASE_STX_IS_SMALLINT(obj)) { - ase_printf (ASE_T("%d"), ASE_STX_FROM_SMALLINT(obj)); - } - else if (ASE_STX_CLASS(stx,obj) == stx->class_character) { - ase_printf (ASE_T("$%c"), ASE_STX_WORD_AT(stx,obj,0)); - } - else if (ASE_STX_CLASS(stx,obj) == stx->class_string) { - ase_printf (ASE_T("'%s'"), ASE_STX_DATA(stx,obj)); - } - else if (ASE_STX_CLASS(stx,obj) == stx->class_symbol) { - ase_printf (ASE_T("#%s"), ASE_STX_DATA(stx,obj)); - } - else if (ASE_STX_IS_CHAR_OBJECT(stx, obj)) { - ase_printf (ASE_T("unknow char object [%s]"), ASE_STX_DATA(stx,obj)); - } - else if (ASE_STX_IS_BYTE_OBJECT(stx, obj)) { - ase_printf (ASE_T("unknown byte object"), ASE_STX_DATA(stx,obj)); - } - else if (ASE_STX_IS_WORD_OBJECT(stx, obj)) { - ase_printf (ASE_T("unknown word object"), ASE_STX_DATA(stx,obj)); - } - else { - ase_printf (ASE_T("invalid object type")); - } -} - -static void __decode1 (ase_stx_t* stx, ase_word_t idx, void* data) -{ - ase_stx_method_t* method_obj; - ase_stx_class_t* class_obj; - ase_word_t key = ASE_STX_WORD_AT(stx,idx,ASE_STX_ASSOCIATION_KEY); - ase_word_t value = ASE_STX_WORD_AT(stx,idx,ASE_STX_ASSOCIATION_VALUE); - ase_word_t* literals; - ase_word_t literal_count, i; - - ase_word_t method_class; - ase_stx_class_t* method_class_obj; - - class_obj = (ase_stx_class_t*)data; - - ase_printf (ASE_T("* Method: %s\n"), ASE_STX_DATA(stx, key)); - method_obj = (ase_stx_method_t*)ASE_STX_OBJECT(stx, value); - - literals = method_obj->literals; - /* - literal_count = ASE_STX_SIZE(stx, value) - - (ASE_STX_FROM_SMALLINT(class_obj->spec) >> ASE_STX_SPEC_INDEXABLE_BITS); - */ - method_class = ASE_STX_CLASS(stx,value); - method_class_obj = ASE_STX_OBJECT(stx, method_class); - literal_count = ASE_STX_SIZE(stx,value) - - (ASE_STX_FROM_SMALLINT(method_class_obj->spec) >> ASE_STX_SPEC_INDEXABLE_BITS); - - ase_printf (ASE_T("* Literal Count: %d, Temporary Count: %d, Argument Count: %d\n"), - literal_count, - ASE_STX_FROM_SMALLINT(method_obj->tmpcount), - ASE_STX_FROM_SMALLINT(method_obj->argcount)); - for (i = 0; i < literal_count; i++) { - ase_printf (ASE_T("%d. ["), i); - __dump_object (stx, literals[i]); - ase_printf (ASE_T("]\n")); - } - __decode2 (stx, data, method_obj); -} - -static int __decode2 (ase_stx_t* stx, - ase_stx_class_t* class_obj, ase_stx_method_t* method_obj) -{ - ase_stx_byte_object_t* bytecodes; - ase_word_t bytecode_size, pc = 0; - int code, next, next2; - - static const ase_char_t* stack_opcode_names[] = - { - ASE_T("push_receiver_variable"), - ASE_T("push_temporary_location"), - ASE_T("push_literal_constant"), - ASE_T("push_literal_variable"), - ASE_T("store_receiver_variable"), - ASE_T("store_temporary_location") - }; - - static const ase_char_t* send_opcode_names[] = - { - ASE_T("send_to_self"), - ASE_T("send_to_super") - }; - - static const ase_char_t* stack_special_opcode_names[] = - { - ASE_T("pop_stack_top"), - ASE_T("duplicate_pop_stack_top"), - ASE_T("push_active_context"), - ASE_T("push_nil"), - ASE_T("push_true"), - ASE_T("push_false"), - ASE_T("push_receiver") - }; - - static const ase_char_t* return_opcode_names[] = - { - ASE_T("return_receiver"), - ASE_T("return_true"), - ASE_T("return_false"), - ASE_T("return_nil"), - ASE_T("return_from_message"), - ASE_T("return_from_block") - }; - - bytecodes = ASE_STX_BYTE_OBJECT(stx, method_obj->bytecodes); - bytecode_size = ASE_STX_SIZE(stx, method_obj->bytecodes); - - while (pc < bytecode_size) { - code = bytecodes->data[pc++]; - - if (code >= 0x00 && code <= 0x5F) { - /* stack */ - ase_printf (ASE_T("%s %d\n"), - stack_opcode_names[code >> 4], code & 0x0F); - } - else if (code >= 0x60 && code <= 0x65) { - /* stack extended */ - next = bytecodes->data[pc++]; - ase_printf (ASE_T("%s %d\n"), - stack_opcode_names[code & 0x0F], next); - } - else if (code >= 0x67 && code <= 0x6D) { - /* stack special */ - ase_printf (ASE_T("%s\n"), - stack_special_opcode_names[code - 0x67]); - } - - else if (code >= 0x70 && code <= 0x71 ) { - /* send message */ - next = bytecodes->data[pc++]; - ase_printf (ASE_T("%s nargs(%d) selector(%d)\n"), - send_opcode_names[code - 0x70], next >> 5, next & 0x1F); - } - else if (code >= 0x72 && code <= 0x73 ) { - /* send message extended */ - next = bytecodes->data[pc++]; - next2 = bytecodes->data[pc++]; - ase_printf (ASE_T("%s %d %d\n"), - send_opcode_names[code - 0x72], next, next2); - - } - else if (code >= 0x78 && code <= 0x7D) { - ase_printf (ASE_T("%s\n"), - return_opcode_names[code - 0x78]); - } - else if (code >= 0x80 && code <= 0x8F) { - // jump - } - else if (code >= 0xF0 && code <= 0xFF) { - // primitive - next = bytecodes->data[pc++]; - ase_printf (ASE_T("do_primitive %d\n"), ((code & 0x0F) << 8) | next); - - } - else { - ase_printf (ASE_T("unknown byte code 0x%x\n"), code); - } - } - - return 0; -} diff --git a/ase/stx/bytecode.h b/ase/stx/bytecode.h deleted file mode 100644 index 1d26204f..00000000 --- a/ase/stx/bytecode.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * $Id: bytecode.h,v 1.1.1.1 2007/03/28 14:05:25 bacon Exp $ - */ - -#ifndef _ASE_STX_BYTECODE_H_ -#define _ASE_STX_BYTECODE_H_ - -#include - -#define PUSH_RECEIVER_VARIABLE 0x00 -#define PUSH_TEMPORARY_LOCATION 0x10 -#define PUSH_LITERAL_CONSTANT 0x20 -#define PUSH_LITERAL_VARIABLE 0x30 -#define STORE_RECEIVER_VARIABLE 0x40 -#define STORE_TEMPORARY_LOCATION 0x50 - -#define PUSH_RECEIVER_VARIABLE_EXTENDED 0x60 -#define PUSH_TEMPORARY_LOCATION_EXTENDED 0x61 -#define PUSH_LITERAL_CONSTANT_EXTENDED 0x62 -#define PUSH_LITERAL_VARIABLE_EXTENDED 0x63 -#define STORE_RECEIVER_VARIABLE_EXTENDED 0x64 -#define STORE_TEMPORARY_LOCATION_EXTENDED 0x65 - -#define POP_STACK_TOP 0x67 -#define DUPLICATE_POP_STACK_TOP 0x68 -#define PUSH_ACTIVE_CONTEXT 0x69 -#define PUSH_NIL 0x6A -#define PUSH_TRUE 0x6B -#define PUSH_FALSE 0x6C -#define PUSH_RECEIVER 0x6D - -#define SEND_TO_SELF 0x70 -#define SEND_TO_SUPER 0x71 -#define SEND_TO_SELF_EXTENDED 0x72 -#define SEND_TO_SUPER_EXTENDED 0x73 - -#define RETURN_RECEIVER 0x78 -#define RETURN_TRUE 0x79 -#define RETURN_FALSE 0x7A -#define RETURN_NIL 0x7B -#define RETURN_FROM_MESSAGE 0x7C -#define RETURN_FROM_BLOCK 0x7D - -#define DO_PRIMITIVE 0xF0 - -#ifdef __cplusplus -extern "C" { -#endif - -int ase_stx_decode (ase_stx_t* stx, ase_word_t class_idx); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ase/stx/class.c b/ase/stx/class.c deleted file mode 100644 index f613a2ae..00000000 --- a/ase/stx/class.c +++ /dev/null @@ -1,168 +0,0 @@ -/* - * $Id: class.c,v 1.1.1.1 2007/03/28 14:05:25 bacon Exp $ - */ - -#include -#include -#include -#include -#include - -ase_word_t ase_stx_new_class (ase_stx_t* stx, const ase_char_t* name) -{ - ase_word_t meta, class; - ase_word_t class_name; - - meta = ase_stx_alloc_word_object ( - stx, ASE_NULL, ASE_STX_METACLASS_SIZE, ASE_NULL, 0); - ASE_STX_CLASS(stx,meta) = stx->class_metaclass; - /* the spec of the metaclass must be the spec of its - * instance. so the ASE_STX_CLASS_SIZE is set */ - ASE_STX_WORD_AT(stx,meta,ASE_STX_METACLASS_SPEC) = - ASE_STX_TO_SMALLINT((ASE_STX_CLASS_SIZE << ASE_STX_SPEC_INDEXABLE_BITS) | ASE_STX_SPEC_NOT_INDEXABLE); - - /* the spec of the class is set later in __create_builtin_classes */ - class = ase_stx_alloc_word_object ( - stx, ASE_NULL, ASE_STX_CLASS_SIZE, ASE_NULL, 0); - ASE_STX_CLASS(stx,class) = meta; - class_name = ase_stx_new_symbol (stx, name); - ASE_STX_WORD_AT(stx,class,ASE_STX_CLASS_NAME) = class_name; - - ase_stx_dict_put (stx, stx->smalltalk, class_name, class); - return class; -} - -ase_word_t ase_stx_lookup_class (ase_stx_t* stx, const ase_char_t* name) -{ - ase_word_t assoc, meta, value; - - assoc = ase_stx_dict_lookup (stx, stx->smalltalk, name); - if (assoc == stx->nil) { - return stx->nil; - } - - value = ASE_STX_WORD_AT(stx,assoc,ASE_STX_ASSOCIATION_VALUE); - meta = ASE_STX_CLASS(stx,value); - if (ASE_STX_CLASS(stx,meta) != stx->class_metaclass) return stx->nil; - - return value; -} - -int ase_stx_get_instance_variable_index ( - ase_stx_t* stx, ase_word_t class_index, - const ase_char_t* name, ase_word_t* index) -{ - ase_word_t index_super = 0; - ase_stx_class_t* class_obj; - ase_stx_char_object_t* string; - - class_obj = (ase_stx_class_t*)ASE_STX_OBJECT(stx, class_index); - ase_assert (class_obj != ASE_NULL); - - if (class_obj->superclass != stx->nil) { - if (ase_stx_get_instance_variable_index ( - stx, class_obj->superclass, name, &index_super) == 0) { - *index = index_super; - return 0; - } - } - - if (class_obj->header.class == stx->class_metaclass) { - /* metaclass */ - /* TODO: can a metaclas have instance variables? */ - *index = index_super; - } - else { - if (class_obj->variables == stx->nil) *index = 0; - else { - string = ASE_STX_CHAR_OBJECT(stx, class_obj->variables); - if (ase_stx_strword(string->data, name, index) != ASE_NULL) { - *index += index_super; - return 0; - } - } - - *index += index_super; - } - - return -1; -} - -ase_word_t ase_stx_lookup_class_variable ( - ase_stx_t* stx, ase_word_t class_index, const ase_char_t* name) -{ - ase_stx_class_t* class_obj; - - class_obj = (ase_stx_class_t*)ASE_STX_OBJECT(stx, class_index); - ase_assert (class_obj != ASE_NULL); - - if (class_obj->superclass != stx->nil) { - ase_word_t tmp; - tmp = ase_stx_lookup_class_variable ( - stx, class_obj->superclass, name); - if (tmp != stx->nil) return tmp; - } - - /* TODO: can a metaclas have class variables? */ - if (class_obj->header.class != stx->class_metaclass && - class_obj->class_variables != stx->nil) { - if (ase_stx_dict_lookup(stx, - class_obj->class_variables,name) != stx->nil) return class_index; - } - - return stx->nil; -} - -ase_word_t ase_stx_lookup_method (ase_stx_t* stx, - ase_word_t class_index, const ase_char_t* name, ase_bool_t from_super) -{ - ase_stx_class_t* class_obj; - - class_obj = (ase_stx_class_t*)ASE_STX_OBJECT(stx, class_index); - ase_assert (class_obj != ASE_NULL); - -#if 0 - if (class_obj->header.class != stx->class_metaclass && - class_obj->methods != stx->nil) { - ase_word_t assoc; - assoc = ase_stx_dict_lookup(stx, class_obj->methods, name); - if (assoc != stx->nil) { - ase_assert (ASE_STX_CLASS(stx,assoc) == stx->class_association); - return ASE_STX_WORD_AT(stx, assoc, ASE_STX_ASSOCIATION_VALUE); - } - } - - if (class_obj->superclass != stx->nil) { - ase_word_t tmp; - tmp = ase_stx_lookup_method ( - stx, class_obj->superclass, name); - if (tmp != stx->nil) return tmp; - } -#endif - - while (class_index != stx->nil) { - class_obj = (ase_stx_class_t*)ASE_STX_OBJECT(stx, class_index); - - ase_assert (class_obj != ASE_NULL); - ase_assert ( - class_obj->header.class == stx->class_metaclass || - ASE_STX_CLASS(stx,class_obj->header.class) == stx->class_metaclass); - - if (from_super) { - from_super = ase_false; - } - else if (class_obj->methods != stx->nil) { - ase_word_t assoc; - assoc = ase_stx_dict_lookup(stx, class_obj->methods, name); - if (assoc != stx->nil) { - ase_assert (ASE_STX_CLASS(stx,assoc) == stx->class_association); - return ASE_STX_WORD_AT(stx, assoc, ASE_STX_ASSOCIATION_VALUE); - } - } - - class_index = class_obj->superclass; - } - - return stx->nil; -} - diff --git a/ase/stx/class.h b/ase/stx/class.h deleted file mode 100644 index 65673fb2..00000000 --- a/ase/stx/class.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * $Id: class.h,v 1.1.1.1 2007/03/28 14:05:28 bacon Exp $ - */ - -#ifndef _ASE_STX_CLASS_H_ -#define _ASE_STX_CLASS_H_ - -#include - -/* definitions for common objects */ -#define ASE_STX_CLASS_SIZE 8 -#define ASE_STX_CLASS_SPEC 0 -#define ASE_STX_CLASS_METHODS 1 -#define ASE_STX_CLASS_SUPERCLASS 2 -#define ASE_STX_CLASS_SUBCLASSES 3 -#define ASE_STX_CLASS_NAME 4 -#define ASE_STX_CLASS_VARIABLES 5 -#define ASE_STX_CLASS_CLASS_VARIABLES 6 -#define ASE_STX_CLASS_POOL_DICTIONARIES 7 - -#define ASE_STX_METACLASS_SIZE 5 -#define ASE_STX_METACLASS_SPEC 0 -#define ASE_STX_METACLASS_METHODS 1 -#define ASE_STX_METACLASS_SUPERCLASS 2 -#define ASE_STX_METACLASS_SUBCLASSES 3 -#define ASE_STX_METACLASS_INSTANCE_CLASS 4 - -#define ASE_STX_SPEC_INDEXABLE_BITS 2 -#define ASE_STX_SPEC_INDEXABLE_MASK 3 -#define ASE_STX_SPEC_NOT_INDEXABLE 0 -#define ASE_STX_SPEC_WORD_INDEXABLE 1 -#define ASE_STX_SPEC_BYTE_INDEXABLE 2 -#define ASE_STX_SPEC_CHAR_INDEXABLE 3 - -struct ase_stx_class_t -{ - ase_stx_objhdr_t header; - ase_word_t spec; /* indexable: 2, nfields: the rest */ - ase_word_t methods; - ase_word_t superclass; - ase_word_t subclasses; - ase_word_t name; - ase_word_t variables; - ase_word_t class_variables; - ase_word_t pool_dictonaries; -}; - -struct ase_stx_metaclass_t -{ - ase_stx_objhdr_t header; - ase_word_t spec; - ase_word_t methods; - ase_word_t superclass; - ase_word_t subclasses; - ase_word_t instance_class; -}; - -typedef struct ase_stx_class_t ase_stx_class_t; -typedef struct ase_stx_metaclass_t ase_stx_metaclass_t; - -#ifdef __cplusplus -extern "C" { -#endif - -ase_word_t ase_stx_new_class (ase_stx_t* stx, const ase_char_t* name); -ase_word_t ase_stx_lookup_class (ase_stx_t* stx, const ase_char_t* name); - -int ase_stx_get_instance_variable_index ( - ase_stx_t* stx, ase_word_t class_index, - const ase_char_t* name, ase_word_t* index); - -ase_word_t ase_stx_lookup_class_variable ( - ase_stx_t* stx, ase_word_t class_index, const ase_char_t* name); -ase_word_t ase_stx_lookup_method (ase_stx_t* stx, - ase_word_t class_index, const ase_char_t* name, ase_bool_t from_super); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ase/stx/context.c b/ase/stx/context.c deleted file mode 100644 index 8f6ec5cc..00000000 --- a/ase/stx/context.c +++ /dev/null @@ -1,75 +0,0 @@ -/* - * $Id: context.c,v 1.1.1.1 2007/03/28 14:05:28 bacon Exp $ - */ - -#include -#include -#include -#include - -ase_word_t ase_stx_new_context (ase_stx_t* stx, - ase_word_t method, ase_word_t args, ase_word_t temp) -{ - ase_word_t context; - ase_stx_context_t* obj; - - context = ase_stx_alloc_word_object( - stx, ASE_NULL, ASE_STX_CONTEXT_SIZE, ASE_NULL, 0); - obj = (ase_stx_context_t*)ASE_STX_OBJECT(stx,context); - obj->header.class = ase_stx_lookup_class(stx,ASE_T("Context")); - obj->ip = ASE_STX_TO_SMALLINT(0); - obj->method = method; - obj->arguments = args; - obj->temporaries = temp; - - return context; -} - -static ase_byte_t __fetch_byte ( - ase_stx_t* stx, ase_stx_context_t* context_obj) -{ - ase_word_t ip, method; - - ase_assert (ASE_STX_IS_SMALLINT(context_obj->ip)); - ip = ASE_STX_FROM_SMALLINT(context_obj->ip); - method = context_obj->method; - - /* increment instruction pointer */ - context_obj->ip = ASE_STX_TO_SMALLINT(ip + 1); - - ase_assert (ASE_STX_TYPE(stx,method) == ASE_STX_BYTE_INDEXED); - return ASE_STX_BYTE_AT(stx,method,ip); -} - -int ase_stx_run_context (ase_stx_t* stx, ase_word_t context) -{ - ase_byte_t byte, operand; - ase_stx_context_t* context_obj; - - context_obj = (ase_stx_context_t*)ASE_STX_OBJECT(stx,context); - - while (!stx->__wantabort) { - /* check_process_switch (); // hopefully */ - byte = __fetch_byte (stx, context_obj); - -#ifdef _DOS -printf (ASE_T("code: %x\n"), byte); -#else -ase_printf (ASE_T("code: %x\n"), byte); -#endif - - switch (byte) { - case PUSH_OBJECT: - operand = __fetch_byte (stx, context_obj); - break; - case SEND_UNARY_MESSAGE: - operand = __fetch_byte (stx, context_obj); - break; - case HALT: - goto exit_run_context; - } - } - -exit_run_context: - return 0; -} diff --git a/ase/stx/context.h b/ase/stx/context.h deleted file mode 100644 index 3cf7d195..00000000 --- a/ase/stx/context.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * $Id: context.h,v 1.1.1.1 2007/03/28 14:05:28 bacon Exp $ - */ - -#ifndef _ASE_STX_CONTEXT_H_ -#define _ASE_STX_CONTEXT_H_ - -#include - -#define PUSH_OBJECT 0xA0 -#define SEND_UNARY_MESSAGE 0xB0 -#define HALT 0xFF - -#define ASE_STX_CONTEXT_SIZE 4 -#define ASE_STX_CONTEXT_IP 0 -#define ASE_STX_CONTEXT_METHOD 1 -#define ASE_STX_CONTEXT_ARGUMENTS 2 -#define ASE_STX_CONTEXT_TEMPORARIES 3 - -struct ase_stx_context_t -{ - ase_stx_objhdr_t header; - ase_word_t ip; - ase_word_t method; - ase_word_t arguments; - ase_word_t temporaries; -}; - -typedef struct ase_stx_context_t ase_stx_context_t; - -#ifdef __cplusplus -extern "C" { -#endif - -ase_word_t ase_stx_new_context (ase_stx_t* stx, - ase_word_t method, ase_word_t args, ase_word_t temp); -int ase_stx_run_context (ase_stx_t* stx, ase_word_t context); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ase/stx/dict.c b/ase/stx/dict.c deleted file mode 100644 index f962036c..00000000 --- a/ase/stx/dict.c +++ /dev/null @@ -1,190 +0,0 @@ -/* - * $Id: dict.c,v 1.1.1.1 2007/03/28 14:05:28 bacon Exp $ - */ - -#include -#include -#include - -/* NOTE: - * The code here implements SystemDictionary whose key is always a symbol. - * Dictionary, on the contrary, can accept any object as a key. - */ - -ase_word_t __new_association ( - ase_stx_t* stx, ase_word_t key, ase_word_t value) -{ - ase_word_t x; -#ifdef __GNUC__ - ase_word_t data[2] = { key, value }; -#else - ase_word_t data[2]; - data[0] = key; - data[1] = value; -#endif - x = ase_stx_alloc_word_object ( - stx, data, ASE_STX_ASSOCIATION_SIZE, ASE_NULL, 0); - ASE_STX_CLASS(stx,x) = stx->class_association; - return x; -} - -static ase_word_t __dict_find_slot ( - ase_stx_t* stx, ase_word_t dict, ase_word_t key) -{ - ase_word_t size, hash, index, assoc, symbol; - ase_stx_word_object_t* dict_obj; - - ase_assert (!ASE_STX_IS_SMALLINT(dict) && - ASE_STX_IS_WORD_OBJECT(stx, dict)); - ase_assert (dict == stx->smalltalk || - ase_stx_classof(stx,dict) == stx->class_system_dictionary); - ase_assert (ase_stx_classof(stx,key) == stx->class_symbol); - - size = ASE_STX_SIZE(stx,dict); - hash = ase_stx_hash_object(stx, key); - - /* consider tally, the only instance variable of a system dictionary */ - index = hash % (size - 1) + 1; - - dict_obj = ASE_STX_WORD_OBJECT(stx,dict); - - while (1) { - assoc = dict_obj->data[index]; - if (assoc == stx->nil) break; - - symbol = ASE_STX_WORD_AT(stx,assoc,ASE_STX_ASSOCIATION_KEY); - ase_assert (ase_stx_classof(stx,symbol) == stx->class_symbol); - - /* NOTE: - * shallow comparison is enough for identity check - * because a symbol can just be a key of a system dictionary - */ - if (ase_strxncmp( - ASE_STX_DATA(stx,key), ASE_STX_SIZE(stx,key), - ASE_STX_DATA(stx,symbol), ASE_STX_SIZE(stx,symbol)) == 0) break; - - /* consider tally here too */ - index = index % (size - 1) + 1; - } - - return index; -} - -static void __grow_dict (ase_stx_t* stx, ase_word_t dict) -{ - ase_word_t new, size, index, assoc; - - /* WARNING: - * if this assertion fails, adjust the initial size of the - * system dictionary. i don't want this function to be called - * during the bootstrapping. - */ - ase_assert (stx->class_system_dictionary != stx->nil); - ase_assert (ase_stx_classof(stx,dict) == stx->class_system_dictionary); - - size = ASE_STX_SIZE(stx,dict); - new = ase_stx_instantiate (stx, - ASE_STX_CLASS(stx,dict), ASE_NULL, ASE_NULL, (size - 1) * 2); - ASE_STX_WORD_AT(stx,new,0) = ASE_STX_TO_SMALLINT(0); - - for (index = 1; index < size; index++) { - assoc = ASE_STX_WORD_AT(stx,dict,index); - if (assoc == stx->nil) continue; - - ase_stx_dict_put (stx, new, - ASE_STX_WORD_AT(stx,assoc,ASE_STX_ASSOCIATION_KEY), - ASE_STX_WORD_AT(stx,assoc,ASE_STX_ASSOCIATION_VALUE)); - } - - /* TODO: explore if dict can be immediately destroyed. */ - - ase_assert (ase_sizeof(ase_stx_object_t*) == ase_sizeof(ase_uint_t)); - ASE_SWAP (ASE_STX_OBJECT(stx,dict), - ASE_STX_OBJECT(stx,new), - ase_stx_object_t*, ase_uint_t); -} - -ase_word_t ase_stx_dict_lookup ( - ase_stx_t* stx, ase_word_t dict, const ase_char_t* key) -{ - ase_word_t size, hash, index, assoc, symbol; - ase_stx_word_object_t* dict_obj; - - ase_assert (!ASE_STX_IS_SMALLINT(dict) && - ASE_STX_IS_WORD_OBJECT(stx, dict)); - ase_assert (dict == stx->smalltalk || - ase_stx_classof(stx,dict) == stx->class_system_dictionary); - - size = ASE_STX_SIZE(stx,dict); - hash = ase_stx_hash(key, ase_strlen(key) * ase_sizeof(ase_char_t)); - - /* consider tally, the only instance variable of a system dictionary */ - index = hash % (size - 1) + 1; - - dict_obj = ASE_STX_WORD_OBJECT(stx,dict); - - while (1) { - assoc = dict_obj->data[index]; - if (assoc == stx->nil) break; - - symbol = ASE_STX_WORD_AT(stx,assoc,ASE_STX_ASSOCIATION_KEY); - ase_assert (ase_stx_classof(stx,symbol) == stx->class_symbol); - - if (ase_strxcmp (ASE_STX_DATA(stx,symbol), - ASE_STX_SIZE(stx,symbol), key) == 0) break; - - /* consider tally here too */ - index = index % (size - 1) + 1; - } - - return ASE_STX_WORD_AT(stx,dict,index); -} - -ase_word_t ase_stx_dict_get (ase_stx_t* stx, ase_word_t dict, ase_word_t key) -{ - return ASE_STX_WORD_AT(stx,dict,__dict_find_slot(stx, dict, key)); -} - -ase_word_t ase_stx_dict_put ( - ase_stx_t* stx, ase_word_t dict, ase_word_t key, ase_word_t value) -{ - ase_word_t slot, capa, tally, assoc; - - /* the dictionary must have at least one slot excluding tally */ - ase_assert (ASE_STX_SIZE(stx,dict) > 1); - - capa = ASE_STX_SIZE(stx,dict) - 1; - tally = ASE_STX_FROM_SMALLINT(ASE_STX_WORD_AT(stx,dict,0)); - if (capa <= tally + 1) { - __grow_dict (stx, dict); - /* refresh tally */ - tally = ASE_STX_FROM_SMALLINT(ASE_STX_WORD_AT(stx,dict,0)); - } - - slot = __dict_find_slot (stx, dict, key); - - assoc = ASE_STX_WORD_AT(stx,dict,slot); - if (assoc == stx->nil) { - ASE_STX_WORD_AT(stx,dict,slot) = - __new_association (stx, key, value); - ASE_STX_WORD_AT(stx,dict,0) = ASE_STX_TO_SMALLINT(tally + 1); - } - else ASE_STX_WORD_AT(stx,assoc,ASE_STX_ASSOCIATION_VALUE) = value; - - return ASE_STX_WORD_AT(stx,dict,slot); -} - -void ase_stx_dict_traverse ( - ase_stx_t* stx, ase_word_t dict, - void (*func) (ase_stx_t*,ase_word_t,void*), void* data) -{ - ase_word_t index, assoc; - ase_word_t size = ASE_STX_SIZE(stx,dict); - - for (index = 1; index < size; index++) { - assoc = ASE_STX_WORD_AT(stx,dict,index); - if (assoc == stx->nil) continue; - func (stx, assoc, data); - } -} - diff --git a/ase/stx/dict.h b/ase/stx/dict.h deleted file mode 100644 index d9d56242..00000000 --- a/ase/stx/dict.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * $Id: dict.h,v 1.1.1.1 2007/03/28 14:05:28 bacon Exp $ - */ - -#ifndef _ASE_STX_DICT_H_ -#define _ASE_STX_DICT_H_ - -#include - -#define ASE_STX_ASSOCIATION_SIZE 2 -#define ASE_STX_ASSOCIATION_KEY 0 -#define ASE_STX_ASSOCIATION_VALUE 1 - -struct ase_stx_association_t -{ - ase_stx_objhdr_t header; - ase_word_t key; - ase_word_t value; -}; - -typedef struct ase_stx_association_t ase_stx_association_t; - -#ifdef __cplusplus -extern "C" -#endif - -ase_word_t ase_stx_dict_lookup ( - ase_stx_t* stx, ase_word_t dict, const ase_char_t* key); -ase_word_t ase_stx_dict_get ( - ase_stx_t* stx, ase_word_t dict, ase_word_t key); -ase_word_t ase_stx_dict_put ( - ase_stx_t* stx, ase_word_t dict, ase_word_t key, ase_word_t value); -void ase_stx_dict_traverse ( - ase_stx_t* stx, ase_word_t dict, - void (*func) (ase_stx_t*,ase_word_t,void*), void* data); - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ase/stx/interp.c b/ase/stx/interp.c deleted file mode 100644 index 4a7aa689..00000000 --- a/ase/stx/interp.c +++ /dev/null @@ -1,380 +0,0 @@ -/* - * $Id: interp.c,v 1.1.1.1 2007/03/28 14:05:28 bacon Exp $ - */ - -#include -#include -#include -#include -#include -#include -#include - -/* -activation record - -.... -.... -.... -------------------- -previous stack_base -------------------- -method -------------------- -pc -------------------- -temporaries -------------------- -arguments -------------------- -receiver -------------------- <----- current stack_base -.... -.... -.... - - */ - -struct process_t -{ - ase_word_t* stack; - ase_word_t stack_size; - ase_word_t stack_base; - ase_word_t stack_top; - - ase_word_t receiver; - ase_word_t method; - ase_word_t pc; - - /* cached information about the method above */ - ase_word_t* literals; - ase_byte_t* bytecodes; - ase_word_t bytecode_size; - ase_size_t argcount; - ase_size_t tmpcount; -}; - -typedef struct process_t process_t; - -static int __run_process (ase_stx_t* stx, process_t* proc); -static int __push_to_stack (ase_stx_t* stx, - process_t* proc, ase_word_t what, ase_word_t index); -static int __store_from_stack (ase_stx_t* stx, - process_t* proc, ase_word_t what, ase_word_t index); -static int __send_message (ase_stx_t* stx, process_t* proc, - ase_word_t nargs, ase_word_t selector, ase_bool_t to_super); -static int __return_from_message (ase_stx_t* stx, process_t* proc); -static int __dispatch_primitive (ase_stx_t* stx, process_t* proc, ase_word_t no); - -int ase_stx_interp (ase_stx_t* stx, ase_word_t receiver, ase_word_t method) -{ - process_t proc; - ase_stx_method_t* mthobj; - ase_word_t i; - int n; - - // TODO: size of process stack. - proc.stack = (ase_word_t*)ase_malloc (10000 * ase_sizeof(ase_word_t)); - if (proc.stack == ASE_NULL) { -ase_printf (ASE_T("out of memory in ase_stx_interp\n")); - return -1; - } - - proc.stack_size = 10000; - proc.stack_base = 0; - proc.stack_top = 0; - - mthobj = (ase_stx_method_t*)ASE_STX_OBJECT(stx,method); - ase_assert (mthobj != ASE_NULL); - - proc.literals = mthobj->literals; - proc.bytecodes = ASE_STX_DATA(stx, mthobj->bytecodes); - proc.bytecode_size = ASE_STX_SIZE(stx, mthobj->bytecodes); - /* TODO: disable the method with arguments for start-up */ - proc.argcount = ASE_STX_FROM_SMALLINT(mthobj->argcount); - proc.tmpcount = ASE_STX_FROM_SMALLINT(mthobj->tmpcount); - - proc.receiver = receiver; - proc.method = method; - proc.pc = 0; - - proc.stack_base = proc.stack_top; - - /* push the receiver */ - proc.stack[proc.stack_top++] = receiver; - - /* push arguments */ - for (i = 0; i < proc.argcount; i++) { - proc.stack[proc.stack_top++] = stx->nil; - } - - /* secure space for temporaries */ - for (i = 0; i < proc.tmpcount; i++) - proc.stack[proc.stack_top++] = stx->nil; - - /* push dummy pc */ - proc.stack[proc.stack_top++] = 0; - /* push dummy method */ - proc.stack[proc.stack_top++] = stx->nil; - /* push dummy previous stack base */ - proc.stack[proc.stack_top++] = 0; - - n = __run_process (stx, &proc); - - ase_free (proc.stack); - return n; -} - -static int __run_process (ase_stx_t* stx, process_t* proc) -{ - int code, next, next2; - - while (proc->pc < proc->bytecode_size) { - code = proc->bytecodes[proc->pc++]; - -#ifdef DEBUG - ase_printf (ASE_T("code = 0x%x\n"), code); -#endif - - if (code >= 0x00 && code <= 0x3F) { - /* stack - push */ - __push_to_stack (stx, proc, code >> 4, code & 0x0F); - } - else if (code >= 0x40 && code <= 0x5F) { - /* stack - store */ - int what = code >> 4; - int index = code & 0x0F; - __store_from_stack (stx, proc, code >> 4, code & 0x0F); - } - - /* TODO: more here .... */ - - else if (code == 0x67) { - /* pop stack top */ - proc->stack_top--; - } - - /* TODO: more here .... */ - - else if (code == 0x6A) { - proc->stack[proc->stack_top++] = stx->nil; - } - else if (code == 0x6B) { - proc->stack[proc->stack_top++] = stx->true; - } - else if (code == 0x6C) { - proc->stack[proc->stack_top++] = stx->false; - } - else if (code == 0x6D) { - /* push receiver */ - proc->stack[proc->stack_top++] = proc->receiver; - } - - /* TODO: more here .... */ - - else if (code == 0x70) { - /* send message to self */ - next = proc->bytecodes[proc->pc++]; - if (__send_message (stx, proc, next >> 5, - proc->literals[next & 0x1F], ase_false) == -1) break; - } - else if (code == 0x71) { - /* send message to super */ - next = proc->bytecodes[proc->pc++]; - if (__send_message (stx, proc, next >> 5, - proc->literals[next & 0x1F], ase_true) == -1) break; - } - else if (code == 0x72) { - /* send message to self extended */ - next = proc->bytecodes[proc->pc++]; - next2 = proc->bytecodes[proc->pc++]; - if (__send_message (stx, proc, next >> 5, - proc->literals[next2], ase_false) == -1) break; - } - else if (code == 0x73) { - /* send message to super extended */ - next = proc->bytecodes[proc->pc++]; - next2 = proc->bytecodes[proc->pc++]; - if (__send_message (stx, proc, next >> 5, - proc->literals[next2], ase_true) == -1) break; - } - - /* more code .... */ - else if (code == 0x78) { - /* return receiver */ - proc->stack[proc->stack_top++] = proc->receiver; - if (__return_from_message (stx, proc) == -1) break; - } - - else if (code == 0x7C) { - /* return from message */ - if (__return_from_message (stx, proc) == -1) break; - } - - else if (code >= 0xF0 && code <= 0xFF) { - /* primitive */ - next = proc->bytecodes[proc->pc++]; - __dispatch_primitive (stx, proc, ((code & 0x0F) << 8) | next); - } - - else { -ase_printf (ASE_T("INVALID OPCODE...........\n")); -break; - } - } - - return 0; -} - -static int __push_to_stack (ase_stx_t* stx, - process_t* proc, ase_word_t what, ase_word_t index) -{ - switch (what) { - case 0: /* receiver variable */ - proc->stack[proc->stack_top++] = - ASE_STX_WORD_AT(stx, proc->stack[proc->stack_base], index); - break; - case 1: /* temporary variable */ - proc->stack[proc->stack_top++] = - proc->stack[proc->stack_base + 1 + index]; - break; - case 2: /* literal constant */ - proc->stack[proc->stack_top++] = proc->literals[index]; - break; - case 3: /* literal variable */ - break; - } - - return 0; -} - -static int __store_from_stack (ase_stx_t* stx, - process_t* proc, ase_word_t what, ase_word_t index) -{ - switch (what) { - case 4: /* receiver variable */ - ASE_STX_WORD_AT(stx,proc->stack[proc->stack_base],index) = proc->stack[--proc->stack_top]; - break; - case 5: /* temporary location */ - proc->stack[proc->stack_base + 1 + index] = proc->stack[--proc->stack_top]; - break; - } - - return 0; -} - -static int __send_message (ase_stx_t* stx, process_t* proc, - ase_word_t nargs, ase_word_t selector, ase_bool_t to_super) -{ - ase_word_t receiver, method; - ase_word_t i, tmpcount, argcount; - ase_stx_method_t* mthobj; - - ase_assert (ASE_STX_CLASS(stx,selector) == stx->class_symbol); - - receiver = proc->stack[proc->stack_top - nargs - 1]; - method = ase_stx_lookup_method ( - stx, ASE_STX_CLASS(stx,receiver), - ASE_STX_DATA(stx,selector), to_super); - if (method == stx->nil) { -ase_printf (ASE_T("cannot find the method....\n")); - return -1; - } - - mthobj = (ase_stx_method_t*)ASE_STX_OBJECT(stx,method); - - argcount = ASE_STX_FROM_SMALLINT(mthobj->argcount); - tmpcount = ASE_STX_FROM_SMALLINT(mthobj->tmpcount); - ase_assert (argcount == nargs); - - /* secure space for temporaries */ - for (i = 0; i < tmpcount; i++) { - proc->stack[proc->stack_top++] = stx->nil; - } - - /* push pc */ - proc->stack[proc->stack_top++] = proc->pc; - /* push method */ - proc->stack[proc->stack_top++] = proc->method; - /* push previous stack base */ - proc->stack[proc->stack_top++] = proc->stack_base; - - proc->stack_base = proc->stack_top - 3 - tmpcount - argcount - 1; - ase_assert (proc->stack_base > 0); - - proc->receiver = receiver; - proc->method = method; - proc->pc = 0; - - proc->literals = mthobj->literals; - proc->bytecodes = ASE_STX_DATA(stx, mthobj->bytecodes); - proc->bytecode_size = ASE_STX_SIZE(stx, mthobj->bytecodes); - proc->argcount = argcount; - proc->tmpcount = tmpcount; - - return 0; -} - -static int __return_from_message (ase_stx_t* stx, process_t* proc) -{ - ase_word_t method, pc, stack_base; - ase_stx_method_t* mthobj; - - if (proc->stack_base == 0) { - /* return from the startup method */ - return -1; - } - - stack_base = proc->stack[proc->stack_base + 1 + proc->tmpcount + proc->argcount + 2]; - method = proc->stack[proc->stack_base + 1 + proc->tmpcount + proc->argcount + 1]; - pc = proc->stack[proc->stack_base + 1 + proc->tmpcount + proc->argcount]; - - mthobj = (ase_stx_method_t*)ASE_STX_OBJECT(stx,method); - ase_assert (mthobj != ASE_NULL); - - /* return value is located on top of the previous stack */ - proc->stack[proc->stack_base - 1] = proc->stack[proc->stack_top - 1]; - - /* restore the stack pointers */ - proc->stack_top = proc->stack_base; - proc->stack_base = stack_base; - - proc->receiver = proc->stack[stack_base]; - proc->method = method; - proc->pc = pc; - - proc->literals = mthobj->literals; - proc->bytecodes = ASE_STX_DATA(stx, mthobj->bytecodes); - proc->bytecode_size = ASE_STX_SIZE(stx, mthobj->bytecodes); - proc->argcount = ASE_STX_FROM_SMALLINT(mthobj->argcount); - proc->tmpcount = ASE_STX_FROM_SMALLINT(mthobj->tmpcount); - - return 0; -} - - -static int __dispatch_primitive (ase_stx_t* stx, process_t* proc, ase_word_t no) -{ - switch (no) { - case 0: - ase_printf (ASE_T("[[ hello stx smalltalk ]]\n")); - break; - case 1: - ase_printf (ASE_T("<< AMAZING STX SMALLTALK WORLD >>\n")); - break; - case 2: - ase_printf (ASE_T("<< FUNKY STX SMALLTALK >> %d\n"), - ASE_STX_FROM_SMALLINT(proc->stack[proc->stack_base + 1])); - break; - case 3: - ase_printf (ASE_T("<< HIGH STX SMALLTALK >> %d, %d\n"), - ASE_STX_FROM_SMALLINT(proc->stack[proc->stack_base + 1]), - ASE_STX_FROM_SMALLINT(proc->stack[proc->stack_base + 2])); - break; - case 20: - ase_printf (ASE_T("<< PRIMITIVE 20 >>\n")); - break; - } - - return 0; -} diff --git a/ase/stx/interp.h b/ase/stx/interp.h deleted file mode 100644 index 51d0b501..00000000 --- a/ase/stx/interp.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * $Id: interp.h,v 1.1.1.1 2007/03/28 14:05:28 bacon Exp $ - */ - -#ifndef _ASE_STX_INTERP_H_ -#define _ASE_STX_INTERP_H_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -int ase_stx_interp (ase_stx_t* stx, ase_word_t receiver, ase_word_t method); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ase/stx/makefile.bcc b/ase/stx/makefile.bcc deleted file mode 100644 index a23bf9cf..00000000 --- a/ase/stx/makefile.bcc +++ /dev/null @@ -1,21 +0,0 @@ -SRCS = stx.c memory.c object.c symbol.c class.c dict.c misc.c array.c \ - name.c token.c parser.c bootstrp.c bytecode.c interp.c -OBJS = $(SRCS:.c=.obj) -OUT = xpstx.lib - -CC = bcc32 -CFLAGS = -O2 -WM -w -w-inl -w-sig -w-spa -w-hid -RT- -I../.. - -all: $(OBJS) - tlib $(OUT) @&&! -+-$(**: = &^ -+-) -! - -clean: - del $(OBJS) $(OUT) *.obj - -.SUFFIXES: .c .obj -.c.obj: - $(CC) $(CFLAGS) -c $< - diff --git a/ase/stx/makefile.cl b/ase/stx/makefile.cl deleted file mode 100644 index 6f6b7511..00000000 --- a/ase/stx/makefile.cl +++ /dev/null @@ -1,23 +0,0 @@ -SRCS = \ - stx.c memory.c object.c symbol.c class.c array.c \ - dict.c misc.c name.c token.c parser.c bootstrp.c \ - bytecode.c interp.c -OBJS = $(SRCS:.c=.obj) -OUT = xpstx.lib - -CC = cl -CFLAGS = /nologo /MT /GX /W3 /GR- /D_WIN32_WINNT=0x0400 -I../.. - -all: $(OBJS) - link -lib @<< -/nologo /out:$(OUT) $(OBJS) -<< - - -clean: - del $(OBJS) $(OUT) *.obj - -.SUFFIXES: .c .obj -.c.obj: - $(CC) $(CFLAGS) /c $< - diff --git a/ase/stx/makefile.in b/ase/stx/makefile.in deleted file mode 100644 index 89d3d474..00000000 --- a/ase/stx/makefile.in +++ /dev/null @@ -1,28 +0,0 @@ -OUT = asestx - -C_SRCS = stx.c memory.c object.c symbol.c class.c array.c \ - dict.c misc.c context.c name.c token.c parser.c bootstrp.c \ - bytecode.c interp.c - -C_OBJS = $(C_SRCS:.c=.o) - -CC = @CC@ -AR = ar -RANLIB = @RANLIB@ -CFLAGS = @CFLAGS@ -I@abs_top_builddir@/.. -LDFLAGS = @LDFLAGS@ -LIBS = @LIBS@ - -all: lib - -lib: $(C_OBJS) - $(AR) cr lib$(OUT).a $(C_OBJS) - if [ "$(RANLIB)" = "ranlib" ]; then ranlib lib$(OUT).a; fi - -clean: - rm -rf $(OBJS) lib$(OUT).a *.o - -.SUFFIXES: .c .o -.c.o: - $(CC) $(CFLAGS) -c $< - diff --git a/ase/stx/makefile.lcc b/ase/stx/makefile.lcc deleted file mode 100644 index 21f10a9b..00000000 --- a/ase/stx/makefile.lcc +++ /dev/null @@ -1,22 +0,0 @@ -SRCS = stx.c memory.c object.c symbol.c class.c array.c \ - dict.c misc.c name.c token.c parser.c bootstrp.c \ - bytecode.c interp.c -OBJS = stx.obj memory.obj object.obj symbol.obj class.obj array.obj \ - dict.obj misc.obj name.obj token.obj parser.obj bootstrp.obj \ - bytecode.obj interp.obj -OUT = xpstx.lib - -CC = lcc -CFLAGS = -I../.. -A -ansic #-libcdll -LDFLAGS = -LIBS = - -all: $(OBJS) - lcclib $(OUT) $(OBJS) - -clean: - del $(OBJS) $(OUT) *.obj - -.SUFFIXES: .c .obj -.c.obj: - $(CC) $(CFLAGS) -c $< diff --git a/ase/stx/makefile.tcc b/ase/stx/makefile.tcc deleted file mode 100644 index 85f31683..00000000 --- a/ase/stx/makefile.tcc +++ /dev/null @@ -1,22 +0,0 @@ -SRCS = \ - stx.c memory.c object.c symbol.c dict.c misc.c context.c -OBJS = $(SRCS:.c=.obj) -OUT = xpstx.lib - -TC = \dos\tcc -CC = $(TC)\tcc -CFLAGS = -I..\.. -D_DOS -ml -w - -all: $(OBJS) - $(TC)\tlib $(OUT) @&&! -+-$(**: = &^ -+-) -! - -clean: - del $(OBJS) $(OUT) *.obj - -.SUFFIXES: .c .obj -.c.obj: - $(CC) $(CFLAGS) -c $< - diff --git a/ase/stx/memory.c b/ase/stx/memory.c deleted file mode 100644 index b9734945..00000000 --- a/ase/stx/memory.c +++ /dev/null @@ -1,98 +0,0 @@ -/* - * $Id: memory.c,v 1.1.1.1 2007/03/28 14:05:28 bacon Exp $ - */ - -#include -#include - -ase_stx_memory_t* ase_stx_memory_open ( - ase_stx_memory_t* mem, ase_word_t capacity) -{ - ase_stx_object_t** slots; - ase_word_t n; - - ase_assert (capacity > 0); - if (mem == ASE_NULL) { - mem = (ase_stx_memory_t*)ase_malloc(ase_sizeof(ase_stx_memory_t)); - if (mem == ASE_NULL) return ASE_NULL; - mem->__dynamic = ase_true; - } - else mem->__dynamic = ase_false; - - slots = (ase_stx_object_t**)ase_malloc ( - capacity * ase_sizeof(ase_stx_object_t*)); - if (slots == ASE_NULL) { - if (mem->__dynamic) ase_free (mem); - mem = ASE_NULL; - } - - mem->capacity = capacity; - mem->slots = slots; - - /* weave the free slot list */ - mem->free = &slots[0]; - for (n = 0; n < capacity - 1; n++) { - mem->slots[n] = (ase_stx_object_t*)&mem->slots[n + 1]; - } - mem->slots[n] = ASE_NULL; - - return mem; -} - -void ase_stx_memory_close (ase_stx_memory_t* mem) -{ - /* TODO: free all linked objects... */ - - ase_free (mem->slots); - mem->capacity = 0; - mem->slots = ASE_NULL; - mem->free = ASE_NULL; - if (mem->__dynamic) ase_free (mem); -} - -void ase_stx_memory_gc (ase_stx_memory_t* mem) -{ - /* TODO: implement this function */ -} - -ase_word_t ase_stx_memory_alloc (ase_stx_memory_t* mem, ase_word_t nbytes) -{ - ase_stx_object_t** slot; - ase_stx_object_t* object; - - /* find the free object slot */ - if (mem->free == ASE_NULL) { - ase_stx_memory_gc (mem); - if (mem->free == ASE_NULL) return mem->capacity;; - } - - object = (ase_stx_object_t*)ase_malloc (nbytes); - if (object == ASE_NULL) { - ase_stx_memory_gc (mem); - object = (ase_stx_object_t*)ase_malloc (nbytes); - /*if (object == ASE_NULL) return mem->capacity;*/ -if (object == ASE_NULL) { -ase_assert (ASE_T("MEMORY ALLOCATION ERROR\n") == ASE_NULL); -exit (1); -} - } - - slot = mem->free; - mem->free = (ase_stx_object_t**)*slot; - *slot = object; - - return (ase_word_t)(slot - mem->slots); -} - -void ase_stx_memory_dealloc (ase_stx_memory_t* mem, ase_word_t object_index) -{ - /* - * THIS IS PRIMITIVE LOW-LEVEL DEALLOC. THIS WILL NOT - * DEALLOCATE MEMORY ALLOCATED FOR ITS INSTANCE VARIABLES. - */ - - ase_free (mem->slots[object_index]); - mem->slots[object_index] = (ase_stx_object_t*)mem->free; - mem->free = &mem->slots[object_index]; -} - diff --git a/ase/stx/memory.h b/ase/stx/memory.h deleted file mode 100644 index 94ef7ff5..00000000 --- a/ase/stx/memory.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * $Id: memory.h,v 1.1.1.1 2007/03/28 14:05:28 bacon Exp $ - */ - -#ifndef _ASE_STX_MEMORY_H_ -#define _ASE_STX_MEMORY_H_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -ase_stx_memory_t* ase_stx_memory_open ( - ase_stx_memory_t* mem, ase_word_t capacity); -void ase_stx_memory_close (ase_stx_memory_t* mem); - -void ase_stx_memory_gc (ase_stx_memory_t* mem); -ase_word_t ase_stx_memory_alloc (ase_stx_memory_t* mem, ase_word_t size); -void ase_stx_memory_dealloc (ase_stx_memory_t* mem, ase_word_t object_index); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ase/stx/method.h b/ase/stx/method.h deleted file mode 100644 index 7f85b25e..00000000 --- a/ase/stx/method.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * $Id: method.h,v 1.1.1.1 2007/03/28 14:05:28 bacon Exp $ - */ - -#ifndef _ASE_STX_METHOD_H_ -#define _ASE_STX_METHOD_H_ - -#include - -#define ASE_STX_METHOD_SIZE 5 -#define ASE_STX_METHOD_TEXT 0 -#define ASE_STX_METHOD_SELECTOR 1 -#define ASE_STX_METHOD_BYTECODES 2 -#define ASE_STX_METHOD_TMPCOUNT 3 -#define ASE_STX_METHOD_ARGCOUNT 4 - - -/* dolphin smalltalk's flags representation - 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 -------------------------------------------------------------------------------------------------- -| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 1| | | | 0| 0| 0| 1| -------------------------------------------------------------------------------------------------- -\----------|-----------/ \----------|----------/ \---------|-----------/ | \---|--/ | - extraIndex arg Count temp Count | flags | - | | - Block flag SmallInteger flag" -*/ - -struct ase_stx_method_t -{ - ase_stx_objhdr_t header; - ase_word_t text; - ase_word_t selector; /* is this necessary? */ - ase_word_t bytecodes; - ase_word_t tmpcount; - ase_word_t argcount; - ase_word_t literals[1]; -}; - -typedef struct ase_stx_method_t ase_stx_method_t; - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ase/stx/misc.c b/ase/stx/misc.c deleted file mode 100644 index 53d2856a..00000000 --- a/ase/stx/misc.c +++ /dev/null @@ -1,70 +0,0 @@ -/* - * $Id: misc.c,v 1.1.1.1 2007/03/28 14:05:28 bacon Exp $ - */ - -#include - -ase_word_t ase_stx_hash (const void* data, ase_word_t len) -{ - ase_word_t h = 0; - ase_byte_t* bp, * be; - - bp = (ase_byte_t*)data; be = bp + len; - while (bp < be) h = h * 31 + *bp++; - - return h; -} - -ase_word_t ase_stx_strhash (const ase_char_t* str) -{ - ase_word_t h = 0; - ase_byte_t* bp, * be; - const ase_char_t* p = str; - - while (*p != ASE_T('\0')) { - bp = (ase_byte_t*)p; - be = bp + ase_sizeof(ase_char_t); - while (bp < be) h = h * 31 + *bp++; - p++; - } - - return h; -} - -ase_word_t ase_stx_strxhash (const ase_char_t* str, ase_word_t len) -{ - ase_word_t h = 0; - ase_byte_t* bp, * be; - const ase_char_t* p = str, * end = str + len; - - while (p < end) { - bp = (ase_byte_t*)p; - be = bp + ase_sizeof(ase_char_t); - while (bp < be) h = h * 31 + *bp++; - p++; - } - - return h; -} - -ase_char_t* ase_stx_strword ( - const ase_char_t* str, const ase_char_t* word, ase_word_t* word_index) -{ - ase_char_t* p = (ase_char_t*)str; - ase_char_t* tok; - ase_size_t len; - ase_word_t index = 0; - - while (p != ASE_NULL) { - p = ase_strtok (p, ASE_T(""), &tok, &len); - if (ase_strxcmp (tok, len, word) == 0) { - *word_index = index; - return tok; - } - - index++; - } - - *word_index = index; - return ASE_NULL; -} diff --git a/ase/stx/misc.h b/ase/stx/misc.h deleted file mode 100644 index d7d8eb7c..00000000 --- a/ase/stx/misc.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * $Id: misc.h,v 1.1.1.1 2007/03/28 14:05:28 bacon Exp $ - */ - -#ifndef _ASE_STX_MISC_H_ -#define _ASE_STX_MISC_H_ - -#include - -/* TODO: remove this header later */ -#include - -#ifdef _DOS - #include - #include - #include - #include - #include - #include - - #define ase_assert assert - #define ase_malloc malloc - #define ase_realloc realloc - #define ase_free free - #define ase_va_list va_list - #define ase_va_start va_start - #define ase_va_end va_end - #define ase_va_arg va_arg - #define ase_isspace isspace - #define ase_isdigit isdigit - #define ase_isalpha isalpha - #define ase_isalnum isalnum -#else - #include - #include - #include - #include - #include - #include -#endif - -#if defined(__BORLANDC__) || defined(_MSC_VER) - #define INLINE -#else - #define INLINE inline -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -ase_word_t ase_stx_hash (const void* data, ase_word_t len); -ase_word_t ase_stx_strhash (const ase_char_t* str); -ase_word_t ase_stx_strxhash (const ase_char_t* str, ase_word_t len); - -ase_char_t* ase_stx_strword ( - const ase_char_t* str, const ase_char_t* word, ase_word_t* word_index); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ase/stx/name.c b/ase/stx/name.c deleted file mode 100644 index 09301168..00000000 --- a/ase/stx/name.c +++ /dev/null @@ -1,146 +0,0 @@ -/* - * $Id: name.c,v 1.1.1.1 2007/03/28 14:05:28 bacon Exp $ - */ - -#include -#include - -ase_stx_name_t* ase_stx_name_open ( - ase_stx_name_t* name, ase_word_t capacity) -{ - if (capacity == 0) - capacity = ase_countof(name->static_buffer) - 1; - - if (name == ASE_NULL) { - name = (ase_stx_name_t*) - ase_malloc (ase_sizeof(ase_stx_name_t)); - if (name == ASE_NULL) return ASE_NULL; - name->__dynamic = ase_true; - } - else name->__dynamic = ase_false; - - if (capacity < ase_countof(name->static_buffer)) { - name->buffer = name->static_buffer; - } - else { - name->buffer = (ase_char_t*) - ase_malloc ((capacity + 1) * ase_sizeof(ase_char_t)); - if (name->buffer == ASE_NULL) { - if (name->__dynamic) ase_free (name); - return ASE_NULL; - } - } - - name->size = 0; - name->capacity = capacity; - name->buffer[0] = ASE_T('\0'); - - return name; -} - -void ase_stx_name_close (ase_stx_name_t* name) -{ - if (name->capacity >= ase_countof(name->static_buffer)) { - ase_assert (name->buffer != name->static_buffer); - ase_free (name->buffer); - } - if (name->__dynamic) ase_free (name); -} - -int ase_stx_name_addc (ase_stx_name_t* name, ase_cint_t c) -{ - if (name->size >= name->capacity) { - /* double the capacity. */ - ase_size_t new_capacity = name->capacity * 2; - - if (new_capacity >= ase_countof(name->static_buffer)) { - ase_char_t* space; - - if (name->capacity < ase_countof(name->static_buffer)) { - space = (ase_char_t*)ase_malloc ( - (new_capacity + 1) * ase_sizeof(ase_char_t)); - if (space == ASE_NULL) return -1; - - /* don't need to copy up to the terminating null */ - ase_memcpy (space, name->buffer, - name->capacity * ase_sizeof(ase_char_t)); - } - else { - space = (ase_char_t*)ase_realloc (name->buffer, - (new_capacity + 1) * ase_sizeof(ase_char_t)); - if (space == ASE_NULL) return -1; - } - - name->buffer = space; - } - - name->capacity = new_capacity; - } - - name->buffer[name->size++] = c; - name->buffer[name->size] = ASE_T('\0'); - return 0; -} - -int ase_stx_name_adds (ase_stx_name_t* name, const ase_char_t* s) -{ - while (*s != ASE_T('\0')) { - if (ase_stx_name_addc(name, *s) == -1) return -1; - s++; - } - - return 0; -} - -void ase_stx_name_clear (ase_stx_name_t* name) -{ - name->size = 0; - name->buffer[0] = ASE_T('\0'); -} - -ase_char_t* ase_stx_name_yield (ase_stx_name_t* name, ase_word_t capacity) -{ - ase_char_t* old_buffer, * new_buffer; - - if (capacity == 0) - capacity = ase_countof(name->static_buffer) - 1; - - if (name->capacity < ase_countof(name->static_buffer)) { - old_buffer = (ase_char_t*) - ase_malloc((name->capacity + 1) * ase_sizeof(ase_char_t)); - if (old_buffer == ASE_NULL) return ASE_NULL; - ase_memcpy (old_buffer, name->buffer, - (name->capacity + 1) * ase_sizeof(ase_char_t)); - } - else old_buffer = name->buffer; - - if (capacity < ase_countof(name->static_buffer)) { - new_buffer = name->static_buffer; - } - else { - new_buffer = (ase_char_t*) - ase_malloc((capacity + 1) * ase_sizeof(ase_char_t)); - if (new_buffer == ASE_NULL) return ASE_NULL; - } - - name->buffer = new_buffer; - name->size = 0; - name->capacity = capacity; - name->buffer[0] = ASE_T('\0'); - - return old_buffer; -} - -int ase_stx_name_compare (ase_stx_name_t* name, const ase_char_t* str) -{ - ase_char_t* p = name->buffer; - ase_word_t index = 0; - - while (index < name->size) { - if (*p > *str) return 1; - if (*p < *str) return -1; - index++; p++; str++; - } - - return (*str == ASE_T('\0'))? 0: -1; -} diff --git a/ase/stx/name.h b/ase/stx/name.h deleted file mode 100644 index d10abf7f..00000000 --- a/ase/stx/name.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * $Id: name.h,v 1.1.1.1 2007/03/28 14:05:28 bacon Exp $ - */ - -#ifndef _ASE_STX_NAME_H_ -#define _ASE_STX_NAME_H_ - -#include - -struct ase_stx_name_t -{ - ase_word_t capacity; - ase_word_t size; - ase_char_t* buffer; - ase_char_t static_buffer[128]; - ase_bool_t __dynamic; -}; - -typedef struct ase_stx_name_t ase_stx_name_t; - -#ifdef __cplusplus -extern "C" { -#endif - -ase_stx_name_t* ase_stx_name_open ( - ase_stx_name_t* name, ase_word_t capacity); -void ase_stx_name_close (ase_stx_name_t* name); - -int ase_stx_name_addc (ase_stx_name_t* name, ase_cint_t c); -int ase_stx_name_adds (ase_stx_name_t* name, const ase_char_t* s); -void ase_stx_name_clear (ase_stx_name_t* name); -ase_char_t* ase_stx_name_yield (ase_stx_name_t* name, ase_word_t capacity); -int ase_stx_name_compare (ase_stx_name_t* name, const ase_char_t* str); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ase/stx/object.c b/ase/stx/object.c deleted file mode 100644 index 60519bf1..00000000 --- a/ase/stx/object.c +++ /dev/null @@ -1,246 +0,0 @@ -/* - * $Id: object.c,v 1.1.1.1 2007/03/28 14:05:28 bacon Exp $ - */ - -#include -#include -#include -#include -#include - -/* n: number of instance variables */ -ase_word_t ase_stx_alloc_word_object ( - ase_stx_t* stx, const ase_word_t* data, ase_word_t nfields, - const ase_word_t* variable_data, ase_word_t variable_nfields) -{ - ase_word_t idx, n; - ase_stx_word_object_t* obj; - - ase_assert (stx->nil == ASE_STX_NIL); - - /* bytes to allocated = - * (number of instance variables + - * number of variable instance variables) * word_size - */ - n = nfields + variable_nfields; - idx = ase_stx_memory_alloc (&stx->memory, - n * ase_sizeof(ase_word_t) + ase_sizeof(ase_stx_object_t)); - if (idx >= stx->memory.capacity) return idx; /* failed TODO: return a difference value OINDEX_INVALID */ - - idx = ASE_STX_TO_OINDEX(idx); - obj = ASE_STX_WORD_OBJECT(stx,idx); - obj->header.class = stx->nil; - obj->header.access = (n << 2) | ASE_STX_WORD_INDEXED; - - if (variable_data == ASE_NULL) { - while (n > nfields) obj->data[--n] = stx->nil; - } - else { - while (n > nfields) { - n--; obj->data[n] = variable_data[n - nfields]; - } - } - - if (data == ASE_NULL) { - while (n > 0) obj->data[--n] = stx->nil; - } - else { - while (n > 0) { - n--; obj->data[n] = data[n]; - } - } - - return idx; -} - -/* n: number of bytes */ -ase_word_t ase_stx_alloc_byte_object ( - ase_stx_t* stx, const ase_byte_t* data, ase_word_t n) -{ - ase_word_t idx; - ase_stx_byte_object_t* obj; - - ase_assert (stx->nil == ASE_STX_NIL); - - idx = ase_stx_memory_alloc ( - &stx->memory, n + ase_sizeof(ase_stx_object_t)); - if (idx >= stx->memory.capacity) return idx; /* failed */ - - idx = ASE_STX_TO_OINDEX(idx); - obj = ASE_STX_BYTE_OBJECT(stx,idx); - obj->header.class = stx->nil; - obj->header.access = (n << 2) | ASE_STX_BYTE_INDEXED; - - if (data == ASE_NULL) { - while (n-- > 0) obj->data[n] = 0; - } - else { - while (n-- > 0) obj->data[n] = data[n]; - } - - return idx; -} - -ase_word_t ase_stx_alloc_char_object ( - ase_stx_t* stx, const ase_char_t* str) -{ - return (str == ASE_NULL)? - ase_stx_alloc_char_objectx (stx, ASE_NULL, 0): - ase_stx_alloc_char_objectx (stx, str, ase_strlen(str)); -} - -/* n: number of characters */ -ase_word_t ase_stx_alloc_char_objectx ( - ase_stx_t* stx, const ase_char_t* str, ase_word_t n) -{ - ase_word_t idx; - ase_stx_char_object_t* obj; - - ase_assert (stx->nil == ASE_STX_NIL); - - idx = ase_stx_memory_alloc (&stx->memory, - (n + 1) * ase_sizeof(ase_char_t) + ase_sizeof(ase_stx_object_t)); - if (idx >= stx->memory.capacity) return idx; /* failed */ - - idx = ASE_STX_TO_OINDEX(idx); - obj = ASE_STX_CHAR_OBJECT(stx,idx); - obj->header.class = stx->nil; - obj->header.access = (n << 2) | ASE_STX_CHAR_INDEXED; - obj->data[n] = ASE_T('\0'); - - if (str == ASE_NULL) { - while (n-- > 0) obj->data[n] = ASE_T('\0'); - } - else { - while (n-- > 0) obj->data[n] = str[n]; - } - - return idx; -} - -ase_word_t ase_stx_allocn_char_object (ase_stx_t* stx, ...) -{ - ase_word_t idx, n = 0; - const ase_char_t* p; - ase_va_list ap; - ase_stx_char_object_t* obj; - - ase_assert (stx->nil == ASE_STX_NIL); - - ase_va_start (ap, stx); - while ((p = ase_va_arg(ap, const ase_char_t*)) != ASE_NULL) { - n += ase_strlen(p); - } - ase_va_end (ap); - - idx = ase_stx_memory_alloc (&stx->memory, - (n + 1) * ase_sizeof(ase_char_t) + ase_sizeof(ase_stx_object_t)); - if (idx >= stx->memory.capacity) return idx; /* failed */ - - idx = ASE_STX_TO_OINDEX(idx); - obj = ASE_STX_CHAR_OBJECT(stx,idx); - obj->header.class = stx->nil; - obj->header.access = (n << 2) | ASE_STX_CHAR_INDEXED; - obj->data[n] = ASE_T('\0'); - - ase_va_start (ap, stx); - n = 0; - while ((p = ase_va_arg(ap, const ase_char_t*)) != ASE_NULL) { - while (*p != ASE_T('\0')) { - /*ASE_STX_CHAR_AT(stx,idx,n++) = *p++;*/ - obj->data[n++] = *p++; - } - } - ase_va_end (ap); - - return idx; -} - -ase_word_t ase_stx_hash_object (ase_stx_t* stx, ase_word_t object) -{ - ase_word_t hv; - - if (ASE_STX_IS_SMALLINT(object)) { - ase_word_t tmp = ASE_STX_FROM_SMALLINT(object); - hv = ase_stx_hash(&tmp, ase_sizeof(tmp)); - } - else if (ASE_STX_IS_CHAR_OBJECT(stx,object)) { - /* the additional null is not taken into account */ - hv = ase_stx_hash (ASE_STX_DATA(stx,object), - ASE_STX_SIZE(stx,object) * ase_sizeof(ase_char_t)); - } - else if (ASE_STX_IS_BYTE_OBJECT(stx,object)) { - hv = ase_stx_hash ( - ASE_STX_DATA(stx,object), ASE_STX_SIZE(stx,object)); - } - else { - ase_assert (ASE_STX_IS_WORD_OBJECT(stx,object)); - hv = ase_stx_hash (ASE_STX_DATA(stx,object), - ASE_STX_SIZE(stx,object) * ase_sizeof(ase_word_t)); - } - - return hv; -} - -ase_word_t ase_stx_instantiate ( - ase_stx_t* stx, ase_word_t class, const void* data, - const void* variable_data, ase_word_t variable_nfields) -{ - ase_stx_class_t* class_obj; - ase_word_t spec, nfields, new; - int indexable; - - ase_assert (class != stx->class_smallinteger); - class_obj = (ase_stx_class_t*)ASE_STX_OBJECT(stx, class); - - /* don't instantiate a metaclass whose instance must be - created in a different way */ - /* TODO: maybe delete the following line */ - ase_assert (class_obj->header.class != stx->class_metaclass); - ase_assert (ASE_STX_IS_SMALLINT(class_obj->spec)); - - spec = ASE_STX_FROM_SMALLINT(class_obj->spec); - nfields = (spec >> ASE_STX_SPEC_INDEXABLE_BITS); - indexable = spec & ASE_STX_SPEC_INDEXABLE_MASK; - - if (indexable == ASE_STX_SPEC_BYTE_INDEXABLE) { - ase_assert (nfields == 0 && data == ASE_NULL); - new = ase_stx_alloc_byte_object( - stx, variable_data, variable_nfields); - } - else if (indexable == ASE_STX_SPEC_CHAR_INDEXABLE) { - ase_assert (nfields == 0 && data == ASE_NULL); - new = ase_stx_alloc_char_objectx( - stx, variable_data, variable_nfields); - } - else if (indexable == ASE_STX_SPEC_WORD_INDEXABLE) { - new = ase_stx_alloc_word_object ( - stx, data, nfields, variable_data, variable_nfields); - } - else { - ase_assert (indexable == ASE_STX_SPEC_NOT_INDEXABLE); - ase_assert (variable_nfields == 0 && variable_data == ASE_NULL); - new = ase_stx_alloc_word_object ( - stx, data, nfields, ASE_NULL, 0); - } - - ASE_STX_CLASS(stx, new) = class; - return new; -} - -ase_word_t ase_stx_class (ase_stx_t* stx, ase_word_t obj) -{ - return ASE_STX_IS_SMALLINT(obj)? - stx->class_smallinteger: ASE_STX_CLASS(stx,obj); -} - -ase_word_t ase_stx_classof (ase_stx_t* stx, ase_word_t obj) -{ - return ASE_STX_IS_SMALLINT(obj)? - stx->class_smallinteger: ASE_STX_CLASS(stx,obj); -} - -ase_word_t ase_stx_sizeof (ase_stx_t* stx, ase_word_t obj) -{ - return ASE_STX_IS_SMALLINT(obj)? 1: ASE_STX_SIZE(stx,obj); -} diff --git a/ase/stx/object.h b/ase/stx/object.h deleted file mode 100644 index 1c705733..00000000 --- a/ase/stx/object.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * $Id: object.h,v 1.1.1.1 2007/03/28 14:05:28 bacon Exp $ - */ - -#ifndef _ASE_STX_OBJECT_H_ -#define _ASE_STX_OBJECT_H_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -ase_word_t ase_stx_alloc_word_object ( - ase_stx_t* stx, const ase_word_t* data, ase_word_t nfields, - const ase_word_t* variable_data, ase_word_t variable_nfields); - -ase_word_t ase_stx_alloc_byte_object ( - ase_stx_t* stx, const ase_byte_t* data, ase_word_t n); - -ase_word_t ase_stx_alloc_char_object ( - ase_stx_t* stx, const ase_char_t* str); -ase_word_t ase_stx_alloc_char_objectx ( - ase_stx_t* stx, const ase_char_t* str, ase_word_t n); -ase_word_t ase_stx_allocn_char_object (ase_stx_t* stx, ...); - -ase_word_t ase_stx_hash_object (ase_stx_t* stx, ase_word_t object); - -ase_word_t ase_stx_instantiate ( - ase_stx_t* stx, ase_word_t class_index, const void* data, - const void* variable_data, ase_word_t variable_nfields); -ase_word_t ase_stx_classof (ase_stx_t* stx, ase_word_t obj); -ase_word_t ase_stx_sizeof (ase_stx_t* stx, ase_word_t obj); - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ase/stx/parser.c b/ase/stx/parser.c deleted file mode 100644 index 61a3c9ec..00000000 --- a/ase/stx/parser.c +++ /dev/null @@ -1,1608 +0,0 @@ -/* - * $Id: parser.c,v 1.1.1.1 2007/03/28 14:05:28 bacon Exp $ - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -static int __parse_method ( - ase_stx_parser_t* parser, - ase_word_t method_class, void* input); -static int __finish_method (ase_stx_parser_t* parser); - -static int __parse_message_pattern (ase_stx_parser_t* parser); -static int __parse_unary_pattern (ase_stx_parser_t* parser); -static int __parse_binary_pattern (ase_stx_parser_t* parser); -static int __parse_keyword_pattern (ase_stx_parser_t* parser); - -static int __parse_temporaries (ase_stx_parser_t* parser); -static int __parse_primitive (ase_stx_parser_t* parser); -static int __parse_statements (ase_stx_parser_t* parser); -static int __parse_block_statements (ase_stx_parser_t* parser); -static int __parse_statement (ase_stx_parser_t* parser); -static int __parse_expression (ase_stx_parser_t* parser); - -static int __parse_assignment ( - ase_stx_parser_t* parser, const ase_char_t* target); -static int __parse_basic_expression ( - ase_stx_parser_t* parser, const ase_char_t* ident); -static int __parse_primary ( - ase_stx_parser_t* parser, const ase_char_t* ident, ase_bool_t* is_super); -static int __parse_primary_ident ( - ase_stx_parser_t* parser, const ase_char_t* ident, ase_bool_t* is_super); - -static int __parse_block_constructor (ase_stx_parser_t* parser); -static int __parse_message_continuation ( - ase_stx_parser_t* parser, ase_bool_t is_super); -static int __parse_keyword_message ( - ase_stx_parser_t* parser, ase_bool_t is_super); -static int __parse_binary_message ( - ase_stx_parser_t* parser, ase_bool_t is_super); -static int __parse_unary_message ( - ase_stx_parser_t* parser, ase_bool_t is_super); - -static int __get_token (ase_stx_parser_t* parser); -static int __get_ident (ase_stx_parser_t* parser); -static int __get_numlit (ase_stx_parser_t* parser, ase_bool_t negated); -static int __get_charlit (ase_stx_parser_t* parser); -static int __get_strlit (ase_stx_parser_t* parser); -static int __get_binary (ase_stx_parser_t* parser); -static int __skip_spaces (ase_stx_parser_t* parser); -static int __skip_comment (ase_stx_parser_t* parser); -static int __get_char (ase_stx_parser_t* parser); -static int __unget_char (ase_stx_parser_t* parser, ase_cint_t c); -static int __open_input (ase_stx_parser_t* parser, void* input); -static int __close_input (ase_stx_parser_t* parser); - -ase_stx_parser_t* ase_stx_parser_open (ase_stx_parser_t* parser, ase_stx_t* stx) -{ - if (parser == ASE_NULL) { - parser = (ase_stx_parser_t*) - ase_malloc (ase_sizeof(ase_stx_parser_t)); - if (parser == ASE_NULL) return ASE_NULL; - parser->__dynamic = ase_true; - } - else parser->__dynamic = ase_false; - - if (ase_stx_name_open (&parser->method_name, 0) == ASE_NULL) { - if (parser->__dynamic) ase_free (parser); - return ASE_NULL; - } - - if (ase_stx_token_open (&parser->token, 0) == ASE_NULL) { - ase_stx_name_close (&parser->method_name); - if (parser->__dynamic) ase_free (parser); - return ASE_NULL; - } - - if (ase_arr_open ( - &parser->bytecode, 256, - ase_sizeof(ase_byte_t), ASE_NULL) == ASE_NULL) { - ase_stx_name_close (&parser->method_name); - ase_stx_token_close (&parser->token); - if (parser->__dynamic) ase_free (parser); - return ASE_NULL; - } - - parser->stx = stx; - parser->error_code = ASE_STX_PARSER_ERROR_NONE; - - parser->temporary_count = 0; - parser->argument_count = 0; - parser->literal_count = 0; - - parser->curc = ASE_T_EOF; - parser->ungotc_count = 0; - - parser->input_owner = ASE_NULL; - parser->input_func = ASE_NULL; - return parser; -} - -void ase_stx_parser_close (ase_stx_parser_t* parser) -{ - while (parser->temporary_count > 0) { - ase_free (parser->temporaries[--parser->temporary_count]); - } - parser->argument_count = 0; - - ase_arr_close (&parser->bytecode); - ase_stx_name_close (&parser->method_name); - ase_stx_token_close (&parser->token); - - if (parser->__dynamic) ase_free (parser); -} - -#define GET_CHAR(parser) \ - do { if (__get_char(parser) == -1) return -1; } while (0) -#define UNGET_CHAR(parser,c) \ - do { if (__unget_char(parser,c) == -1) return -1; } while (0) -#define GET_TOKEN(parser) \ - do { if (__get_token(parser) == -1) return -1; } while (0) -#define ADD_TOKEN_CHAR(parser,c) \ - do { \ - if (ase_stx_token_addc (&(parser)->token, c) == -1) { \ - (parser)->error_code = ASE_STX_PARSER_ERROR_MEMORY; \ - return -1; \ - } \ - } while (0) - -const ase_char_t* ase_stx_parser_error_string (ase_stx_parser_t* parser) -{ - static const ase_char_t* msg[] = - { - ASE_T("no error"), - - ASE_T("input fucntion not ready"), - ASE_T("input function error"), - ASE_T("out of memory"), - - ASE_T("invalid character"), - ASE_T("incomplete character literal"), - ASE_T("incomplete string literal"), - ASE_T("incomplete literal"), - - ASE_T("message selector"), - ASE_T("invalid argument name"), - ASE_T("too many arguments"), - - ASE_T("invalid primitive type"), - ASE_T("primitive number expected"), - ASE_T("primitive number out of range"), - ASE_T("primitive not closed"), - - ASE_T("temporary list not closed"), - ASE_T("too many temporaries"), - ASE_T("cannot redefine pseudo variable"), - ASE_T("invalid primary/expression-start"), - - ASE_T("no period at end of statement"), - ASE_T("no closing parenthesis"), - ASE_T("block argument name missing"), - ASE_T("block argument list not closed"), - ASE_T("block not closed"), - - ASE_T("undeclared name"), - ASE_T("too many literals") - }; - - if (parser->error_code >= 0 && - parser->error_code < ase_countof(msg)) return msg[parser->error_code]; - - return ASE_T("unknown error"); -} - -static INLINE ase_bool_t __is_pseudo_variable (const ase_stx_token_t* token) -{ - return token->type == ASE_STX_TOKEN_IDENT && - (ase_strcmp(token->name.buffer, ASE_T("self")) == 0 || - ase_strcmp(token->name.buffer, ASE_T("super")) == 0 || - ase_strcmp(token->name.buffer, ASE_T("nil")) == 0 || - ase_strcmp(token->name.buffer, ASE_T("true")) == 0 || - ase_strcmp(token->name.buffer, ASE_T("false")) == 0); -} - -static INLINE ase_bool_t __is_vbar_token (const ase_stx_token_t* token) -{ - return - token->type == ASE_STX_TOKEN_BINARY && - token->name.size == 1 && - token->name.buffer[0] == ASE_T('|'); -} - -static INLINE ase_bool_t __is_primitive_opener (const ase_stx_token_t* token) -{ - return - token->type == ASE_STX_TOKEN_BINARY && - token->name.size == 1 && - token->name.buffer[0] == ASE_T('<'); -} - -static INLINE ase_bool_t __is_primitive_closer (const ase_stx_token_t* token) -{ - return - token->type == ASE_STX_TOKEN_BINARY && - token->name.size == 1 && - token->name.buffer[0] == ASE_T('>'); -} - -static INLINE ase_bool_t __is_binary_char (ase_cint_t c) -{ - /* - * binaryCharacter ::= - * '!' | '%' | '&' | '*' | '+' | ',' | - * '/' | '<' | '=' | '>' | '?' | '@' | - * '\' | '~' | '|' | '-' - */ - - return - c == ASE_T('!') || c == ASE_T('%') || - c == ASE_T('&') || c == ASE_T('*') || - c == ASE_T('+') || c == ASE_T(',') || - c == ASE_T('/') || c == ASE_T('<') || - c == ASE_T('=') || c == ASE_T('>') || - c == ASE_T('?') || c == ASE_T('@') || - c == ASE_T('\\') || c == ASE_T('|') || - c == ASE_T('~') || c == ASE_T('-'); -} - -static INLINE ase_bool_t __is_closing_char (ase_cint_t c) -{ - return - c == ASE_T('.') || c == ASE_T(']') || - c == ASE_T(')') || c == ASE_T(';') || - c == ASE_T('\"') || c == ASE_T('\''); -} - -#define EMIT_CODE_TEST(parser,high,low) \ - do { if (__emit_code_test(parser,high,low) == -1) return -1; } while (0) - -#define EMIT_CODE(parser,code) \ - do { if (__emit_code(parser,code) == -1) return -1; } while(0) - -#define EMIT_PUSH_RECEIVER_VARIABLE(parser,pos) \ - do { \ - if (__emit_stack_positional ( \ - parser, PUSH_RECEIVER_VARIABLE, pos) == -1) return -1; \ - } while (0) - -#define EMIT_PUSH_TEMPORARY_LOCATION(parser,pos) \ - do { \ - if (__emit_stack_positional ( \ - parser, PUSH_TEMPORARY_LOCATION, pos) == -1) return -1; \ - } while (0) - -#define EMIT_PUSH_LITERAL_CONSTANT(parser,pos) \ - do { \ - if (__emit_stack_positional ( \ - parser, PUSH_LITERAL_CONSTANT, pos) == -1) return -1; \ - } while (0) - - -#define EMIT_PUSH_LITERAL_VARIABLE(parser,pos) \ - do { \ - if (__emit_stack_positional ( \ - parser, PUSH_LITERAL_VARIABLE, pos) == -1) return -1; \ - } while (0) - -#define EMIT_STORE_RECEIVER_VARIABLE(parser,pos) \ - do { \ - if (__emit_stack_positional ( \ - parser, STORE_RECEIVER_VARIABLE, pos) == -1) return -1; \ - } while (0) - -#define EMIT_STORE_TEMPORARY_LOCATION(parser,pos) \ - do { \ - if (__emit_stack_positional ( \ - parser, STORE_TEMPORARY_LOCATION, pos) == -1) return -1; \ - } while (0) - - -#define EMIT_POP_STACK_TOP(parser) EMIT_CODE(parser, POP_STACK_TOP) -#define EMIT_DUPLICATE_STACK_TOP(parser) EMIT_CODE(parser, DUPLICATE_STACK_TOP) -#define EMIT_PUSH_ACTIVE_CONTEXT(parser) EMIT_CODE(parser, PUSH_ACTIVE_CONTEXT) -#define EMIT_RETURN_FROM_MESSAGE(parser) EMIT_CODE(parser, RETURN_FROM_MESSAGE) -#define EMIT_RETURN_FROM_BLOCK(parser) EMIT_CODE(parser, RETURN_FROM_BLOCK) - -#define EMIT_SEND_TO_SELF(parser,nargs,selector) \ - do { \ - if (__emit_send_to_self(parser,nargs,selector) == -1) return -1; \ - } while (0) - -#define EMIT_SEND_TO_SUPER(parser,nargs,selector) \ - do { \ - if (__emit_send_to_super(parser,nargs,selector) == -1) return -1; \ - } while (0) - -#define EMIT_DO_PRIMITIVE(parser,no) \ - do { if (__emit_do_primitive(parser,no) == -1) return -1; } while(0) - -static INLINE int __emit_code_test ( - ase_stx_parser_t* parser, const ase_char_t* high, const ase_char_t* low) -{ - ase_printf (ASE_T("CODE: %s %s\n"), high, low); - return 0; -} - -static INLINE int __emit_code (ase_stx_parser_t* parser, ase_byte_t code) -{ - if (ase_arr_adddatum(&parser->bytecode, &code) == ASE_NULL) { - parser->error_code = ASE_STX_PARSER_ERROR_MEMORY; - return -1; - } - - return 0; -} - -static INLINE int __emit_stack_positional ( - ase_stx_parser_t* parser, int opcode, int pos) -{ - ase_assert (pos >= 0x0 && pos <= 0xFF); - - if (pos <= 0x0F) { - EMIT_CODE (parser, (opcode & 0xF0) | (pos & 0x0F)); - } - else { - EMIT_CODE (parser, (opcode >> 4) & 0x6F); - EMIT_CODE (parser, pos & 0xFF); - } - - return 0; -} - -static INLINE int __emit_send_to_self ( - ase_stx_parser_t* parser, int nargs, int selector) -{ - ase_assert (nargs >= 0x00 && nargs <= 0xFF); - ase_assert (selector >= 0x00 && selector <= 0xFF); - - if (nargs <= 0x08 && selector <= 0x1F) { - EMIT_CODE (parser, SEND_TO_SELF); - EMIT_CODE (parser, (nargs << 5) | selector); - } - else { - EMIT_CODE (parser, SEND_TO_SELF_EXTENDED); - EMIT_CODE (parser, nargs); - EMIT_CODE (parser, selector); - } - - return 0; -} - -static INLINE int __emit_send_to_super ( - ase_stx_parser_t* parser, int nargs, int selector) -{ - ase_assert (nargs >= 0x00 && nargs <= 0xFF); - ase_assert (selector >= 0x00 && selector <= 0xFF); - - if (nargs <= 0x08 && selector <= 0x1F) { - EMIT_CODE (parser, SEND_TO_SUPER); - EMIT_CODE (parser, (nargs << 5) | selector); - } - else { - EMIT_CODE (parser, SEND_TO_SUPER_EXTENDED); - EMIT_CODE (parser, nargs); - EMIT_CODE (parser, selector); - } - - return 0; -} - -static INLINE int __emit_do_primitive (ase_stx_parser_t* parser, int no) -{ - ase_assert (no >= 0x0 && no <= 0xFFF); - - EMIT_CODE (parser, DO_PRIMITIVE | ((no >> 8) & 0x0F)); - EMIT_CODE (parser, no & 0xFF); - - return 0; -} - -static int __add_literal (ase_stx_parser_t* parser, ase_word_t literal) -{ - ase_word_t i; - - for (i = 0; i < parser->literal_count; i++) { - /* - * it would remove redundancy of symbols and small integers. - * more complex redundacy check may be done somewhere else - * like in __add_string_literal. - */ - if (parser->literals[i] == literal) return i; - } - - if (parser->literal_count >= ase_countof(parser->literals)) { - parser->error_code = ASE_STX_PARSER_ERROR_TOO_MANY_LITERALS; - return -1; - } - - parser->literals[parser->literal_count++] = literal; - return parser->literal_count - 1; -} - -static int __add_character_literal (ase_stx_parser_t* parser, ase_char_t ch) -{ - ase_word_t i, c, literal; - ase_stx_t* stx = parser->stx; - - for (i = 0; i < parser->literal_count; i++) { - c = ASE_STX_IS_SMALLINT(parser->literals[i])? - stx->class_smallinteger: ASE_STX_CLASS (stx, parser->literals[i]); - if (c != stx->class_character) continue; - - if (ch == ASE_STX_CHAR_AT(stx,parser->literals[i],0)) return i; - } - - literal = ase_stx_instantiate ( - stx, stx->class_character, &ch, ASE_NULL, 0); - return __add_literal (parser, literal); -} - -static int __add_string_literal ( - ase_stx_parser_t* parser, const ase_char_t* str, ase_word_t size) -{ - ase_word_t i, c, literal; - ase_stx_t* stx = parser->stx; - - for (i = 0; i < parser->literal_count; i++) { - c = ASE_STX_IS_SMALLINT(parser->literals[i])? - stx->class_smallinteger: ASE_STX_CLASS (stx, parser->literals[i]); - if (c != stx->class_string) continue; - - if (ase_strxncmp (str, size, - ASE_STX_DATA(stx,parser->literals[i]), - ASE_STX_SIZE(stx,parser->literals[i])) == 0) return i; - } - - literal = ase_stx_instantiate ( - stx, stx->class_string, ASE_NULL, str, size); - return __add_literal (parser, literal); -} - -static int __add_symbol_literal ( - ase_stx_parser_t* parser, const ase_char_t* str, ase_word_t size) -{ - ase_stx_t* stx = parser->stx; - return __add_literal (parser, ase_stx_new_symbolx(stx, str, size)); -} - -int ase_stx_parser_parse_method ( - ase_stx_parser_t* parser, ase_word_t method_class, void* input) -{ - int n; - - if (parser->input_func == ASE_NULL) { - parser->error_code = ASE_STX_PARSER_ERROR_INPUT_FUNC; - return -1; - } - - parser->method_class = method_class; - if (__open_input(parser, input) == -1) return -1; - n = __parse_method (parser, method_class, input); - if (__close_input(parser) == -1) return -1; - - return n; -} - -static int __parse_method ( - ase_stx_parser_t* parser, ase_word_t method_class, void* input) -{ - /* - * ::= - * [] [] [] - */ - - GET_CHAR (parser); - GET_TOKEN (parser); - - ase_stx_name_clear (&parser->method_name); - ase_arr_clear (&parser->bytecode); - - while (parser->temporary_count > 0) { - ase_free (parser->temporaries[--parser->temporary_count]); - } - parser->argument_count = 0; - parser->literal_count = 0; - - if (__parse_message_pattern(parser) == -1) return -1; - if (__parse_temporaries(parser) == -1) return -1; - if (__parse_primitive(parser) == -1) return -1; - if (__parse_statements(parser) == -1) return -1; - if (__finish_method (parser) == -1) return -1; - - return 0; -} - -static int __finish_method (ase_stx_parser_t* parser) -{ - ase_stx_t* stx = parser->stx; - ase_stx_class_t* class_obj; - ase_stx_method_t* method_obj; - ase_word_t method, selector; - - ase_assert (parser->bytecode.size != 0); - - class_obj = (ase_stx_class_t*) - ASE_STX_OBJECT(stx, parser->method_class); - - if (class_obj->methods == stx->nil) { - /* TODO: reconfigure method dictionary size */ - class_obj->methods = ase_stx_instantiate ( - stx, stx->class_system_dictionary, - ASE_NULL, ASE_NULL, 64); - } - ase_assert (class_obj->methods != stx->nil); - - selector = ase_stx_new_symbolx ( - stx, parser->method_name.buffer, parser->method_name.size); - - method = ase_stx_instantiate(stx, stx->class_method, - ASE_NULL, parser->literals, parser->literal_count); - method_obj = (ase_stx_method_t*)ASE_STX_OBJECT(stx, method); - - /* TODO: text saving must be optional */ - /*method_obj->text = ase_stx_instantiate ( - stx, stx->class_string, ASE_NULL, - parser->text, ase_strlen(parser->text)); - */ - method_obj->selector = selector; - method_obj->bytecodes = ase_stx_instantiate ( - stx, stx->class_bytearray, ASE_NULL, - parser->bytecode.buf, parser->bytecode.size); - - /* TODO: better way to store argument count & temporary count */ - method_obj->tmpcount = - ASE_STX_TO_SMALLINT(parser->temporary_count - parser->argument_count); - method_obj->argcount = ASE_STX_TO_SMALLINT(parser->argument_count); - - ase_stx_dict_put (stx, class_obj->methods, selector, method); - return 0; -} - -static int __parse_message_pattern (ase_stx_parser_t* parser) -{ - /* - * ::= - * | | - * ::= unarySelector - * ::= binarySelector - * ::= (keyword )+ - */ - int n; - - if (parser->token.type == ASE_STX_TOKEN_IDENT) { - n = __parse_unary_pattern (parser); - } - else if (parser->token.type == ASE_STX_TOKEN_BINARY) { - n = __parse_binary_pattern (parser); - } - else if (parser->token.type == ASE_STX_TOKEN_KEYWORD) { - n = __parse_keyword_pattern (parser); - } - else { - parser->error_code = ASE_STX_PARSER_ERROR_MESSAGE_SELECTOR; - n = -1; - } - - parser->temporary_count = parser->argument_count; - return n; -} - -static int __parse_unary_pattern (ase_stx_parser_t* parser) -{ - /* TODO: check if the method name exists */ - - if (ase_stx_name_adds( - &parser->method_name, parser->token.name.buffer) == -1) { - parser->error_code = ASE_STX_PARSER_ERROR_MEMORY; - return -1; - } - - GET_TOKEN (parser); - return 0; -} - -static int __parse_binary_pattern (ase_stx_parser_t* parser) -{ - /* TODO: check if the method name exists */ - - if (ase_stx_name_adds( - &parser->method_name, parser->token.name.buffer) == -1) { - parser->error_code = ASE_STX_PARSER_ERROR_MEMORY; - return -1; - } - - GET_TOKEN (parser); - if (parser->token.type != ASE_STX_TOKEN_IDENT) { - parser->error_code = ASE_STX_PARSER_ERROR_ARGUMENT_NAME; - return -1; - } - - if (parser->argument_count >= ase_countof(parser->temporaries)) { - parser->error_code = ASE_STX_PARSER_ERROR_TOO_MANY_ARGUMENTS; - return -1; - } - - /* TODO: check for duplicate entries...in instvars */ - parser->temporaries[parser->argument_count] = - ase_stx_token_yield (&parser->token, 0); - if (parser->temporaries[parser->argument_count] == ASE_NULL) { - parser->error_code = ASE_STX_PARSER_ERROR_MEMORY; - return -1; - } - parser->argument_count++; - - GET_TOKEN (parser); - return 0; -} - -static int __parse_keyword_pattern (ase_stx_parser_t* parser) -{ - do { - if (ase_stx_name_adds( - &parser->method_name, parser->token.name.buffer) == -1) { - parser->error_code = ASE_STX_PARSER_ERROR_MEMORY; - return -1; - } - - GET_TOKEN (parser); - if (parser->token.type != ASE_STX_TOKEN_IDENT) { - parser->error_code = ASE_STX_PARSER_ERROR_ARGUMENT_NAME; - return -1; - } - - if (__is_pseudo_variable(&parser->token)) { - parser->error_code = ASE_STX_PARSER_ERROR_PSEUDO_VARIABLE; - return -1; - } - - if (parser->argument_count >= ase_countof(parser->temporaries)) { - parser->error_code = ASE_STX_PARSER_ERROR_TOO_MANY_ARGUMENTS; - return -1; - } - - parser->temporaries[parser->argument_count] = - ase_stx_token_yield (&parser->token, 0); - if (parser->temporaries[parser->argument_count] == ASE_NULL) { - parser->error_code = ASE_STX_PARSER_ERROR_MEMORY; - return -1; - } - -/* TODO: check for duplicate entries...in instvars/arguments */ - parser->argument_count++; - - GET_TOKEN (parser); - } while (parser->token.type == ASE_STX_TOKEN_KEYWORD); - - /* TODO: check if the method name exists */ - /* if it exists, collapse arguments */ -ase_printf (ASE_T("METHOD NAME ==> [%s]\n"), parser->method_name.buffer); - - return 0; -} - -static int __parse_temporaries (ase_stx_parser_t* parser) -{ - /* - * ::= '|' '|' - * ::= identifier* - */ - - if (!__is_vbar_token(&parser->token)) return 0; - - GET_TOKEN (parser); - while (parser->token.type == ASE_STX_TOKEN_IDENT) { - if (parser->temporary_count >= ase_countof(parser->temporaries)) { - parser->error_code = ASE_STX_PARSER_ERROR_TOO_MANY_TEMPORARIES; - return -1; - } - - if (__is_pseudo_variable(&parser->token)) { - parser->error_code = ASE_STX_PARSER_ERROR_PSEUDO_VARIABLE; - return -1; - } - - parser->temporaries[parser->temporary_count] = - ase_stx_token_yield (&parser->token, 0); - if (parser->temporaries[parser->temporary_count] == ASE_NULL) { - parser->error_code = ASE_STX_PARSER_ERROR_MEMORY; - return -1; - } - -/* TODO: check for duplicate entries...in instvars/arguments/temporaries */ - parser->temporary_count++; - - GET_TOKEN (parser); - } - if (!__is_vbar_token(&parser->token)) { - parser->error_code = ASE_STX_PARSER_ERROR_TEMPORARIES_NOT_CLOSED; - return -1; - } - - GET_TOKEN (parser); - return 0; -} - -static int __parse_primitive (ase_stx_parser_t* parser) -{ - /* - * ::= '<' 'primitive:' number '>' - */ - - int prim_no; - - if (!__is_primitive_opener(&parser->token)) return 0; - GET_TOKEN (parser); - - if (parser->token.type != ASE_STX_TOKEN_KEYWORD || - ase_strcmp (parser->token.name.buffer, ASE_T("primitive:")) != 0) { - parser->error_code = ASE_STX_PARSER_ERROR_PRIMITIVE_KEYWORD; - return -1; - } - - GET_TOKEN (parser); /* TODO: only integer */ - if (parser->token.type != ASE_STX_TOKEN_NUMLIT) { - parser->error_code = ASE_STX_PARSER_ERROR_PRIMITIVE_NUMBER; - return -1; - } - -/*TODO: more checks the validity of the primitive number */ - if (!ase_stristype(parser->token.name.buffer, ase_isdigit)) { - parser->error_code = ASE_STX_PARSER_ERROR_PRIMITIVE_NUMBER; - return -1; - } - - ASE_STRTOI (prim_no, parser->token.name.buffer, ASE_NULL, 10); - if (prim_no < 0 || prim_no > 0xFF) { - parser->error_code = ASE_STX_PARSER_ERROR_PRIMITIVE_NUMBER_RANGE; - return -1; - } - - EMIT_DO_PRIMITIVE (parser, prim_no); - - GET_TOKEN (parser); - if (!__is_primitive_closer(&parser->token)) { - parser->error_code = ASE_STX_PARSER_ERROR_PRIMITIVE_NOT_CLOSED; - return -1; - } - - GET_TOKEN (parser); - return 0; -} - -static int __parse_statements (ase_stx_parser_t* parser) -{ - /* - * ::= (ORIGINAL->maybe wrong) - * ( ['.'] ) | - * ( ['.' []]) - * ::= (REVISED->correct?) - * ['. []] - */ - - while (parser->token.type != ASE_STX_TOKEN_END) { - if (__parse_statement (parser) == -1) return -1; - - if (parser->token.type == ASE_STX_TOKEN_PERIOD) { - GET_TOKEN (parser); - continue; - } - - if (parser->token.type != ASE_STX_TOKEN_END) { - parser->error_code = ASE_STX_PARSER_ERROR_NO_PERIOD; - return -1; - } - } - - EMIT_CODE (parser, RETURN_RECEIVER); - return 0; -} - -static int __parse_block_statements (ase_stx_parser_t* parser) -{ - while (parser->token.type != ASE_STX_TOKEN_RBRACKET && - parser->token.type != ASE_STX_TOKEN_END) { - - if (__parse_statement(parser) == -1) return -1; - if (parser->token.type != ASE_STX_TOKEN_PERIOD) break; - GET_TOKEN (parser); - } - - return 0; -} - -static int __parse_statement (ase_stx_parser_t* parser) -{ - /* - * ::= | - * ::= returnOperator - * returnOperator ::= '^' - */ - - if (parser->token.type == ASE_STX_TOKEN_RETURN) { - GET_TOKEN (parser); - if (__parse_expression(parser) == -1) return -1; - EMIT_RETURN_FROM_MESSAGE (parser); - } - else { - if (__parse_expression(parser) == -1) return -1; - } - - return 0; -} - -static int __parse_expression (ase_stx_parser_t* parser) -{ - /* - * ::= | - * ::= assignmentOperator - * ::= [ ] - * ::= identifier - * assignmentOperator ::= ':=' - */ - ase_stx_t* stx = parser->stx; - - if (parser->token.type == ASE_STX_TOKEN_IDENT) { - ase_char_t* ident = ase_stx_token_yield (&parser->token, 0); - if (ident == ASE_NULL) { - parser->error_code = ASE_STX_PARSER_ERROR_MEMORY; - return -1; - } - - GET_TOKEN (parser); - if (parser->token.type == ASE_STX_TOKEN_ASSIGN) { - GET_TOKEN (parser); - if (__parse_assignment(parser, ident) == -1) { - ase_free (ident); - return -1; - } - } - else { - if (__parse_basic_expression(parser, ident) == -1) { - ase_free (ident); - return -1; - } - } - - ase_free (ident); - } - else { - if (__parse_basic_expression(parser, ASE_NULL) == -1) return -1; - } - - return 0; -} - -static int __parse_basic_expression ( - ase_stx_parser_t* parser, const ase_char_t* ident) -{ - /* - * ::= [ ] - */ - ase_bool_t is_super; - - if (__parse_primary(parser, ident, &is_super) == -1) return -1; - if (parser->token.type != ASE_STX_TOKEN_END && - parser->token.type != ASE_STX_TOKEN_PERIOD) { - if (__parse_message_continuation(parser, is_super) == -1) return -1; - } - return 0; -} - -static int __parse_assignment ( - ase_stx_parser_t* parser, const ase_char_t* target) -{ - /* - * ::= assignmentOperator - */ - - ase_word_t i; - ase_stx_t* stx = parser->stx; - - for (i = parser->argument_count; i < parser->temporary_count; i++) { - if (ase_strcmp (target, parser->temporaries[i]) == 0) { - if (__parse_expression(parser) == -1) return -1; - EMIT_STORE_TEMPORARY_LOCATION (parser, i); - return 0; - } - } - - if (ase_stx_get_instance_variable_index ( - stx, parser->method_class, target, &i) == 0) { - if (__parse_expression(parser) == -1) return -1; - EMIT_STORE_RECEIVER_VARIABLE (parser, i); - return 0; - } - - if (ase_stx_lookup_class_variable ( - stx, parser->method_class, target) != stx->nil) { - if (__parse_expression(parser) == -1) return -1; - - /* TODO */ - EMIT_CODE_TEST (parser, ASE_T("ASSIGN_CLASSVAR #"), target); - //EMIT_STORE_CLASS_VARIABLE (parser, target); - return 0; - } - - /* TODO: IMPLEMENT POOL DICTIONARIES */ - - /* TODO: IMPLEMENT GLOBLAS, but i don't like this idea */ - - parser->error_code = ASE_STX_PARSER_ERROR_UNDECLARED_NAME; - return -1; -} - -static int __parse_primary ( - ase_stx_parser_t* parser, const ase_char_t* ident, ase_bool_t* is_super) -{ - /* - * ::= - * identifier | | - * | ( '('')' ) - */ - - ase_stx_t* stx = parser->stx; - - if (ident == ASE_NULL) { - int pos; - ase_word_t literal; - - *is_super = ase_false; - - if (parser->token.type == ASE_STX_TOKEN_IDENT) { - if (__parse_primary_ident(parser, - parser->token.name.buffer, is_super) == -1) return -1; - GET_TOKEN (parser); - } - else if (parser->token.type == ASE_STX_TOKEN_CHARLIT) { - pos = __add_character_literal( - parser, parser->token.name.buffer[0]); - if (pos == -1) return -1; - EMIT_PUSH_LITERAL_CONSTANT (parser, pos); - GET_TOKEN (parser); - } - else if (parser->token.type == ASE_STX_TOKEN_STRLIT) { - pos = __add_string_literal (parser, - parser->token.name.buffer, parser->token.name.size); - if (pos == -1) return -1; - EMIT_PUSH_LITERAL_CONSTANT (parser, pos); - GET_TOKEN (parser); - } - else if (parser->token.type == ASE_STX_TOKEN_NUMLIT) { - /* TODO: other types of numbers, negative numbers, etc */ - ase_word_t tmp; - ASE_STRTOI (tmp, parser->token.name.buffer, ASE_NULL, 10); - literal = ASE_STX_TO_SMALLINT(tmp); - pos = __add_literal(parser, literal); - if (pos == -1) return -1; - EMIT_PUSH_LITERAL_CONSTANT (parser, pos); - GET_TOKEN (parser); - } - else if (parser->token.type == ASE_STX_TOKEN_SYMLIT) { - pos = __add_symbol_literal (parser, - parser->token.name.buffer, parser->token.name.size); - if (pos == -1) return -1; - EMIT_PUSH_LITERAL_CONSTANT (parser, pos); - GET_TOKEN (parser); - } - else if (parser->token.type == ASE_STX_TOKEN_LBRACKET) { - GET_TOKEN (parser); - if (__parse_block_constructor(parser) == -1) return -1; - } - else if (parser->token.type == ASE_STX_TOKEN_APAREN) { - /* TODO: array literal */ - } - else if (parser->token.type == ASE_STX_TOKEN_LPAREN) { - GET_TOKEN (parser); - if (__parse_expression(parser) == -1) return -1; - if (parser->token.type != ASE_STX_TOKEN_RPAREN) { - parser->error_code = ASE_STX_PARSER_ERROR_NO_RPAREN; - return -1; - } - GET_TOKEN (parser); - } - else { - parser->error_code = ASE_STX_PARSER_ERROR_PRIMARY; - return -1; - } - } - else { - /*if (__parse_primary_ident(parser, parser->token.name.buffer) == -1) return -1;*/ - if (__parse_primary_ident(parser, ident, is_super) == -1) return -1; - } - - return 0; -} - -static int __parse_primary_ident ( - ase_stx_parser_t* parser, const ase_char_t* ident, ase_bool_t* is_super) -{ - ase_word_t i; - ase_stx_t* stx = parser->stx; - - *is_super = ase_false; - - if (ase_strcmp(ident, ASE_T("self")) == 0) { - EMIT_CODE (parser, PUSH_RECEIVER); - return 0; - } - else if (ase_strcmp(ident, ASE_T("super")) == 0) { - *is_super = ase_true; - EMIT_CODE (parser, PUSH_RECEIVER); - return 0; - } - else if (ase_strcmp(ident, ASE_T("nil")) == 0) { - EMIT_CODE (parser, PUSH_NIL); - return 0; - } - else if (ase_strcmp(ident, ASE_T("true")) == 0) { - EMIT_CODE (parser, PUSH_TRUE); - return 0; - } - else if (ase_strcmp(ident, ASE_T("false")) == 0) { - EMIT_CODE (parser, PUSH_FALSE); - return 0; - } - - /* Refer to __parse_assignment for identifier lookup */ - - for (i = 0; i < parser->temporary_count; i++) { - if (ase_strcmp(ident, parser->temporaries[i]) == 0) { - EMIT_PUSH_TEMPORARY_LOCATION (parser, i); - return 0; - } - } - - if (ase_stx_get_instance_variable_index ( - stx, parser->method_class, ident, &i) == 0) { - EMIT_PUSH_RECEIVER_VARIABLE (parser, i); - return 0; - } - - /* TODO: what is the best way to look up a class variable? */ - /* 1. Use the class containing it and using its position */ - /* 2. Use a primitive method after pushing the name as a symbol */ - /* 3. Implement a vm instruction to do it */ -/* - if (ase_stx_lookup_class_variable ( - stx, parser->method_class, ident) != stx->nil) { - //EMIT_LOOKUP_CLASS_VARIABLE (parser, ident); - return 0; - } -*/ - - /* TODO: IMPLEMENT POOL DICTIONARIES */ - - /* TODO: IMPLEMENT GLOBLAS, but i don't like this idea */ - - parser->error_code = ASE_STX_PARSER_ERROR_UNDECLARED_NAME; - return -1; -} - -static int __parse_block_constructor (ase_stx_parser_t* parser) -{ - /* - * ::= '[' ']' - * ::= [* '|'] - * [] [] - * ::= ':' identifier - */ - - if (parser->token.type == ASE_STX_TOKEN_COLON) { - do { - GET_TOKEN (parser); - - if (parser->token.type != ASE_STX_TOKEN_IDENT) { - parser->error_code = ASE_STX_PARSER_ERROR_BLOCK_ARGUMENT_NAME; - return -1; - } - - /* TODO : store block arguments */ - GET_TOKEN (parser); - } while (parser->token.type == ASE_STX_TOKEN_COLON); - - if (!__is_vbar_token(&parser->token)) { - parser->error_code = ASE_STX_PARSER_ERROR_BLOCK_ARGUMENT_LIST; - return -1; - } - - GET_TOKEN (parser); - } - - /* TODO: create a block closure */ - if (__parse_temporaries(parser) == -1) return -1; - if (__parse_block_statements(parser) == -1) return -1; - - if (parser->token.type != ASE_STX_TOKEN_RBRACKET) { - parser->error_code = ASE_STX_PARSER_ERROR_BLOCK_NOT_CLOSED; - return -1; - } - - GET_TOKEN (parser); - - /* TODO: do special treatment for block closures */ - - return 0; -} - -static int __parse_message_continuation ( - ase_stx_parser_t* parser, ase_bool_t is_super) -{ - /* - * ::= - * (+ * [] ) | - * (+ [] ) | - * - * ::= (';' )* - */ - if (__parse_keyword_message(parser, is_super) == -1) return -1; - - while (parser->token.type == ASE_STX_TOKEN_SEMICOLON) { - EMIT_CODE_TEST (parser, ASE_T("DoSpecial(DUP_RECEIVER(CASCADE))"), ASE_T("")); - GET_TOKEN (parser); - - if (__parse_keyword_message(parser, ase_false) == -1) return -1; - EMIT_CODE_TEST (parser, ASE_T("DoSpecial(POP_TOP)"), ASE_T("")); - } - - return 0; -} - -static int __parse_keyword_message (ase_stx_parser_t* parser, ase_bool_t is_super) -{ - /* - * ::= (keyword )+ - * ::= * * - */ - - ase_stx_name_t name; - ase_word_t pos; - ase_bool_t is_super2; - int nargs = 0, n; - - if (__parse_binary_message (parser, is_super) == -1) return -1; - if (parser->token.type != ASE_STX_TOKEN_KEYWORD) return 0; - - if (ase_stx_name_open(&name, 0) == ASE_NULL) { - parser->error_code = ASE_STX_PARSER_ERROR_MEMORY; - return -1; - } - - do { - if (ase_stx_name_adds(&name, parser->token.name.buffer) == -1) { - parser->error_code = ASE_STX_PARSER_ERROR_MEMORY; - ase_stx_name_close (&name); - return -1; - } - - GET_TOKEN (parser); - if (__parse_primary(parser, ASE_NULL, &is_super2) == -1) { - ase_stx_name_close (&name); - return -1; - } - - if (__parse_binary_message(parser, is_super2) == -1) { - ase_stx_name_close (&name); - return -1; - } - - nargs++; - /* TODO: check if it has too many arguments.. */ - } while (parser->token.type == ASE_STX_TOKEN_KEYWORD); - - pos = __add_symbol_literal (parser, name.buffer, name.size); - if (pos == -1) { - ase_stx_name_close (&name); - return -1; - } - - n = (is_super)? - __emit_send_to_super(parser,nargs,pos): - __emit_send_to_self(parser,nargs,pos); - if (n == -1) { - ase_stx_name_close (&name); - return -1; - } - - ase_stx_name_close (&name); - return 0; -} - -static int __parse_binary_message (ase_stx_parser_t* parser, ase_bool_t is_super) -{ - /* - * ::= binarySelector - * ::= * - */ - ase_word_t pos; - ase_bool_t is_super2; - int n; - - if (__parse_unary_message (parser, is_super) == -1) return -1; - - while (parser->token.type == ASE_STX_TOKEN_BINARY) { - ase_char_t* op = ase_stx_token_yield (&parser->token, 0); - if (op == ASE_NULL) { - parser->error_code = ASE_STX_PARSER_ERROR_MEMORY; - return -1; - } - - GET_TOKEN (parser); - if (__parse_primary(parser, ASE_NULL, &is_super2) == -1) { - ase_free (op); - return -1; - } - - if (__parse_unary_message(parser, is_super2) == -1) { - ase_free (op); - return -1; - } - - pos = __add_symbol_literal (parser, op, ase_strlen(op)); - if (pos == -1) { - ase_free (op); - return -1; - } - - n = (is_super)? - __emit_send_to_super(parser,2,pos): - __emit_send_to_self(parser,2,pos); - if (n == -1) { - ase_free (op); - return -1; - } - - ase_free (op); - } - - return 0; -} - -static int __parse_unary_message (ase_stx_parser_t* parser, ase_bool_t is_super) -{ - /* ::= unarySelector */ - - ase_word_t pos; - int n; - - while (parser->token.type == ASE_STX_TOKEN_IDENT) { - pos = __add_symbol_literal (parser, - parser->token.name.buffer, parser->token.name.size); - if (pos == -1) return -1; - - n = (is_super)? - __emit_send_to_super(parser,0,pos): - __emit_send_to_self(parser,0,pos); - if (n == -1) return -1; - - GET_TOKEN (parser); - } - - return 0; -} - -static int __get_token (ase_stx_parser_t* parser) -{ - ase_cint_t c; - - do { - if (__skip_spaces(parser) == -1) return -1; - if (parser->curc == ASE_T('"')) { - GET_CHAR (parser); - if (__skip_comment(parser) == -1) return -1; - } - else break; - } while (1); - - c = parser->curc; - ase_stx_token_clear (&parser->token); - - if (c == ASE_T_EOF) { - parser->token.type = ASE_STX_TOKEN_END; - } - else if (ase_isalpha(c)) { - if (__get_ident(parser) == -1) return -1; - } - else if (ase_isdigit(c)) { - if (__get_numlit(parser, ase_false) == -1) return -1; - } - else if (c == ASE_T('$')) { - GET_CHAR (parser); - if (__get_charlit(parser) == -1) return -1; - } - else if (c == ASE_T('\'')) { - GET_CHAR (parser); - if (__get_strlit(parser) == -1) return -1; - } - else if (c == ASE_T(':')) { - parser->token.type = ASE_STX_TOKEN_COLON; - ADD_TOKEN_CHAR(parser, c); - GET_CHAR (parser); - - c = parser->curc; - if (c == ASE_T('=')) { - parser->token.type = ASE_STX_TOKEN_ASSIGN; - ADD_TOKEN_CHAR(parser, c); - GET_CHAR (parser); - } - } - else if (c == ASE_T('^')) { - parser->token.type = ASE_STX_TOKEN_RETURN; - ADD_TOKEN_CHAR(parser, c); - GET_CHAR (parser); - } - else if (c == ASE_T('[')) { - parser->token.type = ASE_STX_TOKEN_LBRACKET; - ADD_TOKEN_CHAR(parser, c); - GET_CHAR (parser); - } - else if (c == ASE_T(']')) { - parser->token.type = ASE_STX_TOKEN_RBRACKET; - ADD_TOKEN_CHAR(parser, c); - GET_CHAR (parser); - } - else if (c == ASE_T('(')) { - parser->token.type = ASE_STX_TOKEN_LPAREN; - ADD_TOKEN_CHAR(parser, c); - GET_CHAR (parser); - } - else if (c == ASE_T(')')) { - parser->token.type = ASE_STX_TOKEN_RPAREN; - ADD_TOKEN_CHAR(parser, c); - GET_CHAR (parser); - } - else if (c == ASE_T('#')) { - /*ADD_TOKEN_CHAR(parser, c);*/ - GET_CHAR (parser); - - c = parser->curc; - if (c == ASE_T_EOF) { - parser->error_code = ASE_STX_PARSER_ERROR_LITERAL; - return -1; - } - else if (c == ASE_T('(')) { - ADD_TOKEN_CHAR(parser, c); - parser->token.type = ASE_STX_TOKEN_APAREN; - GET_CHAR (parser); - } - else if (c == ASE_T('\'')) { - GET_CHAR (parser); - if (__get_strlit(parser) == -1) return -1; - parser->token.type = ASE_STX_TOKEN_SYMLIT; - } - else if (!__is_closing_char(c) && !ase_isspace(c)) { - do { - ADD_TOKEN_CHAR(parser, c); - GET_CHAR (parser); - c = parser->curc; - } while (!__is_closing_char(c) && !ase_isspace(c)); - - parser->token.type = ASE_STX_TOKEN_SYMLIT; - } - else { - parser->error_code = ASE_STX_PARSER_ERROR_LITERAL; - return -1; - } - } - else if (c == ASE_T('.')) { - parser->token.type = ASE_STX_TOKEN_PERIOD; - ADD_TOKEN_CHAR(parser, c); - GET_CHAR (parser); - } - else if (c == ASE_T(';')) { - parser->token.type = ASE_STX_TOKEN_SEMICOLON; - ADD_TOKEN_CHAR(parser, c); - GET_CHAR (parser); - } - else if (__is_binary_char(c)) { - if (__get_binary(parser) == -1) return -1; - } - else { - parser->error_code = ASE_STX_PARSER_ERROR_CHAR; - return -1; - } - -//ase_printf (ASE_T("TOKEN: %s\n"), parser->token.name.buffer); - return 0; -} - -static int __get_ident (ase_stx_parser_t* parser) -{ - /* - * identifier ::= letter (letter | digit)* - * keyword ::= identifier ':' - */ - - ase_cint_t c = parser->curc; - parser->token.type = ASE_STX_TOKEN_IDENT; - - do { - ADD_TOKEN_CHAR(parser, c); - GET_CHAR (parser); - c = parser->curc; - } while (ase_isalnum(c)); - - if (c == ASE_T(':')) { - ADD_TOKEN_CHAR (parser, c); - parser->token.type = ASE_STX_TOKEN_KEYWORD; - GET_CHAR (parser); - } - - return 0; -} - -static int __get_numlit (ase_stx_parser_t* parser, ase_bool_t negated) -{ - /* - * ::= ['-'] - * ::= integer | float | scaledDecimal - * integer ::= decimalInteger | radixInteger - * decimalInteger ::= digits - * digits ::= digit+ - * radixInteger ::= radixSpecifier 'r' radixDigits - * radixSpecifier := digits - * radixDigits ::= (digit | uppercaseAlphabetic)+ - * float ::= mantissa [exponentLetter exponent] - * mantissa ::= digits'.' digits - * exponent ::= ['-']decimalInteger - * exponentLetter ::= 'e' | 'd' | 'q' - * scaledDecimal ::= scaledMantissa 's' [fractionalDigits] - * scaledMantissa ::= decimalInteger | mantissa - * fractionalDigits ::= decimalInteger - */ - - ase_cint_t c = parser->curc; - parser->token.type = ASE_STX_TOKEN_NUMLIT; - - do { - ADD_TOKEN_CHAR(parser, c); - GET_CHAR (parser); - c = parser->curc; - } while (ase_isalnum(c)); - - /* TODO; more */ - return 0; -} - -static int __get_charlit (ase_stx_parser_t* parser) -{ - /* - * character_literal ::= '$' character - * character ::= "Any character in the implementation-defined character set" - */ - - ase_cint_t c = parser->curc; /* even a new-line or white space would be taken */ - if (c == ASE_T_EOF) { - parser->error_code = ASE_STX_PARSER_ERROR_CHARLIT; - return -1; - } - - parser->token.type = ASE_STX_TOKEN_CHARLIT; - ADD_TOKEN_CHAR(parser, c); - GET_CHAR (parser); - return 0; -} - -static int __get_strlit (ase_stx_parser_t* parser) -{ - /* - * string_literal ::= stringDelimiter stringBody stringDelimiter - * stringBody ::= (nonStringDelimiter | (stringDelimiter stringDelimiter)*) - * stringDelimiter ::= ''' "a single quote" - */ - - /* TODO: C-like string */ - - ase_cint_t c = parser->curc; - parser->token.type = ASE_STX_TOKEN_STRLIT; - - do { - do { - ADD_TOKEN_CHAR (parser, c); - GET_CHAR (parser); - c = parser->curc; - - if (c == ASE_T_EOF) { - parser->error_code = ASE_STX_PARSER_ERROR_STRLIT; - return -1; - } - } while (c != ASE_T('\'')); - - GET_CHAR (parser); - c = parser->curc; - } while (c == ASE_T('\'')); - - return 0; -} - -static int __get_binary (ase_stx_parser_t* parser) -{ - /* - * binarySelector ::= binaryCharacter+ - */ - - ase_cint_t c = parser->curc; - ADD_TOKEN_CHAR (parser, c); - - if (c == ASE_T('-')) { - GET_CHAR (parser); - c = parser->curc; - if (ase_isdigit(c)) return __get_numlit(parser,ase_true); - } - else { - GET_CHAR (parser); - c = parser->curc; - } - - /* up to 2 characters only */ - if (__is_binary_char(c)) { - ADD_TOKEN_CHAR (parser, c); - GET_CHAR (parser); - c = parser->curc; - } - - /* or up to any occurrences */ - /* - while (__is_binary_char(c)) { - ADD_TOKEN_CHAR (parser, c); - GET_CHAR (parser); - c = parser->curc; - } - */ - - parser->token.type = ASE_STX_TOKEN_BINARY; - return 0; -} - -static int __skip_spaces (ase_stx_parser_t* parser) -{ - while (ase_isspace(parser->curc)) GET_CHAR (parser); - return 0; -} - -static int __skip_comment (ase_stx_parser_t* parser) -{ - while (parser->curc != ASE_T('"')) GET_CHAR (parser); - GET_CHAR (parser); - return 0; -} - -static int __get_char (ase_stx_parser_t* parser) -{ - ase_cint_t c; - - if (parser->ungotc_count > 0) { - parser->curc = parser->ungotc[parser->ungotc_count--]; - } - else { - if (parser->input_func ( - ASE_STX_PARSER_INPUT_CONSUME, - parser->input_owner, (void*)&c) == -1) { - parser->error_code = ASE_STX_PARSER_ERROR_INPUT; - return -1; - } - parser->curc = c; - } - return 0; -} - -static int __unget_char (ase_stx_parser_t* parser, ase_cint_t c) -{ - if (parser->ungotc_count >= ase_countof(parser->ungotc)) return -1; - parser->ungotc[parser->ungotc_count++] = c; - return 0; -} - -static int __open_input (ase_stx_parser_t* parser, void* input) -{ - if (parser->input_func( - ASE_STX_PARSER_INPUT_OPEN, - (void*)&parser->input_owner, input) == -1) { - parser->error_code = ASE_STX_PARSER_ERROR_INPUT; - return -1; - } - - parser->error_code = ASE_STX_PARSER_ERROR_NONE; - parser->curc = ASE_T_EOF; - parser->ungotc_count = 0; - return 0; -} - -static int __close_input (ase_stx_parser_t* parser) -{ - if (parser->input_func( - ASE_STX_PARSER_INPUT_CLOSE, - parser->input_owner, ASE_NULL) == -1) { - parser->error_code = ASE_STX_PARSER_ERROR_INPUT; - return -1; - } - - return 0; -} - diff --git a/ase/stx/parser.h b/ase/stx/parser.h deleted file mode 100644 index e0e5d282..00000000 --- a/ase/stx/parser.h +++ /dev/null @@ -1,107 +0,0 @@ -/* - * $Id: parser.h,v 1.1.1.1 2007/03/28 14:05:28 bacon Exp $ - */ - -#ifndef _ASE_STX_PARSER_H_ -#define _ASE_STX_PARSER_H_ - -#include -#include -#include -#include - -enum -{ - ASE_STX_PARSER_ERROR_NONE, - - /* system errors */ - ASE_STX_PARSER_ERROR_INPUT_FUNC, - ASE_STX_PARSER_ERROR_INPUT, - ASE_STX_PARSER_ERROR_MEMORY, - - /* lexical errors */ - ASE_STX_PARSER_ERROR_CHAR, - ASE_STX_PARSER_ERROR_CHARLIT, - ASE_STX_PARSER_ERROR_STRLIT, - ASE_STX_PARSER_ERROR_LITERAL, - - /* syntatic error */ - ASE_STX_PARSER_ERROR_MESSAGE_SELECTOR, - ASE_STX_PARSER_ERROR_ARGUMENT_NAME, - ASE_STX_PARSER_ERROR_TOO_MANY_ARGUMENTS, - - ASE_STX_PARSER_ERROR_PRIMITIVE_KEYWORD, - ASE_STX_PARSER_ERROR_PRIMITIVE_NUMBER, - ASE_STX_PARSER_ERROR_PRIMITIVE_NUMBER_RANGE, - ASE_STX_PARSER_ERROR_PRIMITIVE_NOT_CLOSED, - - ASE_STX_PARSER_ERROR_TEMPORARIES_NOT_CLOSED, - ASE_STX_PARSER_ERROR_TOO_MANY_TEMPORARIES, - ASE_STX_PARSER_ERROR_PSEUDO_VARIABLE, - ASE_STX_PARSER_ERROR_PRIMARY, - - ASE_STX_PARSER_ERROR_NO_PERIOD, - ASE_STX_PARSER_ERROR_NO_RPAREN, - ASE_STX_PARSER_ERROR_BLOCK_ARGUMENT_NAME, - ASE_STX_PARSER_ERROR_BLOCK_ARGUMENT_LIST, - ASE_STX_PARSER_ERROR_BLOCK_NOT_CLOSED, - - ASE_STX_PARSER_ERROR_UNDECLARED_NAME, - ASE_STX_PARSER_ERROR_TOO_MANY_LITERALS -}; - -enum -{ - /* input_func cmd */ - ASE_STX_PARSER_INPUT_OPEN, - ASE_STX_PARSER_INPUT_CLOSE, - ASE_STX_PARSER_INPUT_CONSUME, - ASE_STX_PARSER_INPUT_REWIND -}; - -typedef struct ase_stx_parser_t ase_stx_parser_t; - -struct ase_stx_parser_t -{ - ase_stx_t* stx; - int error_code; - - ase_word_t method_class; - ase_stx_name_t method_name; - - ase_char_t* temporaries[256]; /* TODO: different size? or dynamic? */ - ase_word_t argument_count; - ase_word_t temporary_count; - - ase_word_t literals[256]; /* TODO: make it a dynamic array */ - ase_word_t literal_count; - - ase_arr_t bytecode; - - ase_stx_token_t token; - ase_cint_t curc; - ase_cint_t ungotc[5]; - ase_size_t ungotc_count; - - void* input_owner; - int (*input_func) (int cmd, void* owner, void* arg); - - ase_bool_t __dynamic; -}; - -#ifdef __cplusplus -extern "C" { -#endif - -ase_stx_parser_t* ase_stx_parser_open (ase_stx_parser_t* parser, ase_stx_t* stx); -void ase_stx_parser_close (ase_stx_parser_t* parser); - -const ase_char_t* ase_stx_parser_error_string (ase_stx_parser_t* parser); -int ase_stx_parser_parse_method ( - ase_stx_parser_t* parser, ase_word_t method_class, void* input); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ase/stx/stx.bnf b/ase/stx/stx.bnf deleted file mode 100644 index 81112540..00000000 --- a/ase/stx/stx.bnf +++ /dev/null @@ -1,196 +0,0 @@ -~~~ method grammar ~~~ - - ::= - - [ ] - [] - - ::= | - | - - - ::= unarySelector - - ::= binarySelector - - ::= (keyword )+ - - ::= '|' '|' - - ::= identifier* - - ::= '[' ']' - - ::= [* '|'] - [] [] - - ::= ':' identifier - - ::= - ( ['.'] ) | - ( ['.' []]) - - ::= returnOperator - - ::= - | - - - ::= assignmentOperator - - ::= - [ ] - - := identifier - - ::= - identifier | - | - | - ( '(' ')' ) - - - ::= - (+ * [] ) | - (+ [] ) | - - - ::= unarySelector - - ::= binarySelector - - ::= * - - ::= (keyword )+ - - ::= * * - - ::= (';' )* - - ::= - | - | - | - | - | - - - ::= ['-'] - - ::= integer | float | scaledDecimal - - ::= quotedCharacter - - ::= quotedString - - ::= hashedString - - ::= quotedSelector - - ::= '#(' * ')' - - ::= | identifier - -reserved identifiers -> nil true false self super - - -~~~ lexical grammar ~~~ - -character ::= - "Any character in the implementation-defined character set" - -whitespace ::= - "Any non-printing character interpreted as white space - including spaces, tabs, and line breaks" - -digit ::= - '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' - -uppercaseAlphabetic ::= - 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | - 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' | - 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z' - -lowercaseAlphabetic ::= - 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | - 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | - 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z' - -nonCaseLetter ::= '_' - -letter ::= - uppercaseAlphabetic | - lowercaseAlphabetic | - nonCaseLetter | - "implementation defined letters" - -commentDelimiter ::= '"' - -nonCommentDelimiter::= -"any character that is not a commentDelimiter " - - comment := - commentDelimiter nonCommentDelimiter * commentDelimiter - -identifier ::= letter (letter | digit)* - -keyword ::= identifier ':' - -binaryCharacter ::= - '!' | '%' | '&' | '*' | '+' | ',' | - '/' | '<' | '=' | '>' | '?' | '@' | - '\' | '~' | '|' | '-' - -binarySelector ::= binaryCharacter+ - -returnOperator ::= '^' - -assignmentOperator ::= ':=' - - -integer ::= decimalInteger | radixInteger - -decimalInteger ::= digits - -digits ::= digit+ - -radixInteger ::= radixSpecifier 'r' radixDigits - -radixSpecifier := digits - -radixDigits ::= (digit | uppercaseAlphabetic)+ - - -float ::= mantissa [exponentLetter exponent] - -mantissa ::= digits'.' digits - -exponent ::= ['-']decimalInteger - -exponentLetter ::= 'e' | 'd' | 'q' - -scaledDecimal ::= scaledMantissa 's' [fractionalDigits] - -scaledMantissa ::= decimalInteger | mantissa - -fractionalDigits ::= decimalInteger - -quotedCharacter ::= '$' character - -quotedString ::= stringDelimiter stringBody stringDelimiter - -stringBody ::= (nonStringDelimiter | (stringDelimiter stringDelimiter)*) - -stringDelimiter ::= ''' "a single quote" - -nonStringDelimiter ::= "any character except stringDelimiter" - -hashedString ::= '#' quotedString - -quotedSelector ::= '#' (unarySelector | binarySelector | keywordSelector) - -keywordSelector ::= keyword+ - -separator ::= (whitespace | comment)* - - diff --git a/ase/stx/stx.c b/ase/stx/stx.c deleted file mode 100644 index 3fbd4d81..00000000 --- a/ase/stx/stx.c +++ /dev/null @@ -1,70 +0,0 @@ -/* - * $Id: stx.c,v 1.1.1.1 2007/03/28 14:05:28 bacon Exp $ - */ - -#include -#include -#include - -ase_stx_t* ase_stx_open (ase_stx_t* stx, ase_word_t capacity) -{ - ase_word_t i; - - if (stx == ASE_NULL) { - stx = (ase_stx_t*)ase_malloc (ase_sizeof(stx)); - if (stx == ASE_NULL) return ASE_NULL; - stx->__dynamic = ase_true; - } - else stx->__dynamic = ase_false; - - if (ase_stx_memory_open (&stx->memory, capacity) == ASE_NULL) { - if (stx->__dynamic) ase_free (stx); - return ASE_NULL; - } - - stx->symtab.size = 0; - stx->symtab.capacity = 128; /* TODO: symbol table size */ - stx->symtab.datum = (ase_word_t*)ase_malloc ( - ase_sizeof(ase_word_t) * stx->symtab.capacity); - if (stx->symtab.datum == ASE_NULL) { - ase_stx_memory_close (&stx->memory); - if (stx->__dynamic) ase_free (stx); - return ASE_NULL; - } - - stx->nil = ASE_STX_NIL; - stx->true = ASE_STX_TRUE; - stx->false = ASE_STX_FALSE; - - stx->smalltalk = ASE_STX_NIL; - - stx->class_symbol = ASE_STX_NIL; - stx->class_metaclass = ASE_STX_NIL; - stx->class_association = ASE_STX_NIL; - - stx->class_object = ASE_STX_NIL; - stx->class_class = ASE_STX_NIL; - stx->class_array = ASE_STX_NIL; - stx->class_bytearray = ASE_STX_NIL; - stx->class_string = ASE_STX_NIL; - stx->class_character = ASE_STX_NIL; - stx->class_context = ASE_STX_NIL; - stx->class_system_dictionary = ASE_STX_NIL; - stx->class_method = ASE_STX_NIL; - stx->class_smallinteger = ASE_STX_NIL; - - for (i = 0; i < stx->symtab.capacity; i++) { - stx->symtab.datum[i] = stx->nil; - } - - stx->__wantabort = ase_false; - return stx; -} - -void ase_stx_close (ase_stx_t* stx) -{ - ase_free (stx->symtab.datum); - ase_stx_memory_close (&stx->memory); - if (stx->__dynamic) ase_free (stx); -} - diff --git a/ase/stx/stx.h b/ase/stx/stx.h deleted file mode 100644 index 6c153e91..00000000 --- a/ase/stx/stx.h +++ /dev/null @@ -1,163 +0,0 @@ -/* - * $Id: stx.h,v 1.1.1.1 2007/03/28 14:05:28 bacon Exp $ - */ - -#ifndef _ASE_STX_STX_H_ -#define _ASE_STX_STX_H_ - -#include -#include - -typedef struct ase_stx_objhdr_t ase_stx_objhdr_t; -typedef struct ase_stx_object_t ase_stx_object_t; -typedef struct ase_stx_word_object_t ase_stx_word_object_t; -typedef struct ase_stx_byte_object_t ase_stx_byte_object_t; -typedef struct ase_stx_char_object_t ase_stx_char_object_t; -typedef struct ase_stx_memory_t ase_stx_memory_t; -typedef struct ase_stx_symtab_t ase_stx_symtab_t; -typedef struct ase_stx_t ase_stx_t; - -/* common object structure */ -struct ase_stx_objhdr_t -{ - /* access - type: 2; size: rest; - * type - word indexed: 00 byte indexed: 01 char indexed: 10 - */ - ase_word_t access; - ase_word_t class; -}; - -struct ase_stx_object_t -{ - ase_stx_objhdr_t header; -}; - -struct ase_stx_word_object_t -{ - ase_stx_objhdr_t header; - ase_word_t data[1]; -}; - -struct ase_stx_byte_object_t -{ - ase_stx_objhdr_t header; - ase_byte_t data[1]; -}; - -struct ase_stx_char_object_t -{ - ase_stx_objhdr_t header; - ase_char_t data[1]; -}; - - -struct ase_stx_memory_t -{ - ase_word_t capacity; - ase_stx_object_t** slots; - ase_stx_object_t** free; - ase_bool_t __dynamic; -}; - -struct ase_stx_symtab_t -{ - ase_word_t* datum; - ase_word_t size; - ase_word_t capacity; -}; - -struct ase_stx_t -{ - ase_stx_memory_t memory; - ase_stx_symtab_t symtab; - - ase_word_t nil; - ase_word_t true; - ase_word_t false; - - ase_word_t smalltalk; - - ase_word_t class_symbol; - ase_word_t class_metaclass; - ase_word_t class_association; - - ase_word_t class_object; - ase_word_t class_class; - ase_word_t class_array; - ase_word_t class_bytearray; - ase_word_t class_string; - ase_word_t class_character; - ase_word_t class_context; - ase_word_t class_system_dictionary; - ase_word_t class_method; - ase_word_t class_smallinteger; - - ase_bool_t __dynamic; - ase_bool_t __wantabort; /* TODO: make it a function pointer */ -}; - -#define ASE_STX_IS_SMALLINT(x) (((x) & 0x01) == 0x01) -#define ASE_STX_TO_SMALLINT(x) (((x) << 1) | 0x01) -#define ASE_STX_FROM_SMALLINT(x) ((x) >> 1) - -#define ASE_STX_IS_OINDEX(x) (((x) & 0x01) == 0x00) -#define ASE_STX_TO_OINDEX(x) (((x) << 1) | 0x00) -#define ASE_STX_FROM_OINDEX(x) ((x) >> 1) - -#define ASE_STX_NIL ASE_STX_TO_OINDEX(0) -#define ASE_STX_TRUE ASE_STX_TO_OINDEX(1) -#define ASE_STX_FALSE ASE_STX_TO_OINDEX(2) - -#define ASE_STX_OBJECT(stx,idx) (((stx)->memory).slots[ASE_STX_FROM_OINDEX(idx)]) -#define ASE_STX_CLASS(stx,idx) (ASE_STX_OBJECT(stx,(idx))->header.class) -#define ASE_STX_ACCESS(stx,idx) (ASE_STX_OBJECT(stx,(idx))->header.access) -#define ASE_STX_DATA(stx,idx) ((void*)(ASE_STX_OBJECT(stx,idx) + 1)) - -#define ASE_STX_TYPE(stx,idx) (ASE_STX_ACCESS(stx,idx) & 0x03) -#define ASE_STX_SIZE(stx,idx) (ASE_STX_ACCESS(stx,idx) >> 0x02) - -#define ASE_STX_WORD_INDEXED (0x00) -#define ASE_STX_BYTE_INDEXED (0x01) -#define ASE_STX_CHAR_INDEXED (0x02) - -#define ASE_STX_IS_WORD_OBJECT(stx,idx) \ - (ASE_STX_TYPE(stx,idx) == ASE_STX_WORD_INDEXED) -#define ASE_STX_IS_BYTE_OBJECT(stx,idx) \ - (ASE_STX_TYPE(stx,idx) == ASE_STX_BYTE_INDEXED) -#define ASE_STX_IS_CHAR_OBJECT(stx,idx) \ - (ASE_STX_TYPE(stx,idx) == ASE_STX_CHAR_INDEXED) - -#define ASE_STX_WORD_OBJECT(stx,idx) \ - ((ase_stx_word_object_t*)ASE_STX_OBJECT(stx,idx)) -#define ASE_STX_BYTE_OBJECT(stx,idx) \ - ((ase_stx_byte_object_t*)ASE_STX_OBJECT(stx,idx)) -#define ASE_STX_CHAR_OBJECT(stx,idx) \ - ((ase_stx_char_object_t*)ASE_STX_OBJECT(stx,idx)) - -/* -#define ASE_STX_WORD_AT(stx,idx,n) \ - (((ase_word_t*)(ASE_STX_OBJECT(stx,idx) + 1))[n]) -#define ASE_STX_BYTE_AT(stx,idx,n) \ - (((ase_byte_t*)(ASE_STX_OBJECT(stx,idx) + 1))[n]) -#define ASE_STX_CHAR_AT(stx,idx,n) \ - (((ase_char_t*)(ASE_STX_OBJECT(stx,idx) + 1))[n]) -*/ -#define ASE_STX_WORD_AT(stx,idx,n) \ - (ASE_STX_WORD_OBJECT(stx,idx)->data[n]) -#define ASE_STX_BYTE_AT(stx,idx,n) \ - (ASE_STX_BYTE_OBJECT(stx,idx)->data[n]) -#define ASE_STX_CHAR_AT(stx,idx,n) \ - (ASE_STX_CHAR_OBJECT(stx,idx)->data[n]) - -#ifdef __cplusplus -extern "C" { -#endif - -ase_stx_t* ase_stx_open (ase_stx_t* stx, ase_word_t capacity); -void ase_stx_close (ase_stx_t* stx); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ase/stx/stx.txt b/ase/stx/stx.txt deleted file mode 100644 index c6e373cd..00000000 --- a/ase/stx/stx.txt +++ /dev/null @@ -1,90 +0,0 @@ -stx(1) xpkit - -NAME - stx - xpkit embeddable smalltalk system - -SYNOPSIS - stx [-f imageFile] MainClass - -DESCRIPTION - The virtual machine executes "MainClass main" on start-up. - - -method 1. -push lookup_class(#MainClass) -> receiver. -send a unary(no argument) message with the selector #main. -return the returned value from main and exits. - -method 2. - take a command parameter -push lookup_class(#MainClass) -> receiver. -push argc as an argument. -push argv as an argument. -send a double-argument message the the selector #main:withArgv:. -return the returned value from #main:withArgv and exits. - - -AUTHOR(S) - Chung, Hyung-Hwan (bacon@piowave.com) is the sole designer and implementer of stx. - -BUG REPORTS - Report bugs to bacon@piowave.com if you find any bugs. but make sure that it is really a bug before you report it. - -COPYRIGHT - Copyright(c) 2005 bacon@piowave.com - -SEE ALSO - xpkit(7) - - --- stack bytecodes -- -0 0000 XXXX push_receiver_variable -1 0001 XXXX push_temporary_location -2 0010 XXXX push_literal_constant -3 0011 XXXX push_literal_variable -4 0100 XXXX store_receiver_variable -5 0101 XXXX store_temporary_location -6 0110 0000 XXXXXXXX push_receiver_variable_extended - 0110 0001 XXXXXXXX push_temporary_location_extended - 0110 0010 XXXXXXXX push_literal_constant_extended - 0110 0011 XXXXXXXX push_literal_variable_extended - 0110 0100 XXXXXXXX store_receiver_variable_extended - 0110 0101 XXXXXXXX store_temporary_location_extended - 0110 0110 unused - 0110 0111 unused - 0110 1000 pop_stack_top - 0110 1001 duplicate_stack_top - 0110 1010 push_active_context - 0110 1011 unused - 0110 1100 unused - 0110 1101 unused - 0110 1110 unused - 0110 1111 unused - --- send bytecodes -- -7 0111 0000 JJJKKKKK send_to_self - 0111 0001 JJJKKKKK send_to_super - 0111 0010 JJJJJJJJ KKKKKKKK send_to_self_extended - 0111 0011 JJJJJJJJ KKKKKKKK send_to_super_extended - - 0111 0100 XXXXXXXX - 0111 0101 XXXXXXXX - 0111 0110 XXXXXXXX - 0111 0111 XXXXXXXX - --- return bytecodes -- - 0111 1000 return receiver - 0111 1001 return_true - 0111 1010 return_false - 0111 1011 return_nil - - 0111 1100 return_from_message - 0111 1101 return_from_block - 0111 1110 - 0111 1111 - --- jump bytecodes -- -8 1000 0XXX jump_forward - 1000 1XXX XXXXXXXX jump_forward - --- primitive -- -F 1111 XXXX XXXXXXXX do_primitive diff --git a/ase/stx/symbol.c b/ase/stx/symbol.c deleted file mode 100644 index e8325631..00000000 --- a/ase/stx/symbol.c +++ /dev/null @@ -1,94 +0,0 @@ -/* - * $Id: symbol.c,v 1.1.1.1 2007/03/28 14:05:28 bacon Exp $ - */ - -#include -#include -#include - -static void __grow_symtab (ase_stx_t* stx) -{ - ase_word_t capa, ncapa, i, j; - ase_word_t* nspace; - - capa = stx->symtab.capacity; - ncapa = capa << 1; - - nspace = (ase_word_t*)ase_malloc(ase_sizeof(ase_word_t) * ncapa); - if (nspace == ASE_NULL) { - /* TODO: handle memory error */ - } - - for (i = 0; i < capa; i++) { - ase_word_t x = stx->symtab.datum[i]; - if (x == stx->nil) continue; - - j = ase_stx_strxhash ( - ASE_STX_DATA(stx,x), ASE_STX_SIZE(stx,x)) % ncapa; - - while (1) { - if (nspace[j] == stx->nil) { - nspace[j] = x; - break; - } - j = (j % ncapa) + 1; - } - } - - stx->symtab.capacity = ncapa; - ase_free (stx->symtab.datum); - stx->symtab.datum = nspace; -} - -ase_word_t ase_stx_new_symbol (ase_stx_t* stx, const ase_char_t* name) -{ - return ase_stx_new_symbolx (stx, name, ase_strlen(name)); -} - -ase_word_t ase_stx_new_symbolx ( - ase_stx_t* stx, const ase_char_t* name, ase_word_t len) -{ - ase_word_t capa, hash, index, size, x; - - capa = stx->symtab.capacity; - size = stx->symtab.size; - - if (capa <= size + 1) { - __grow_symtab (stx); - capa = stx->symtab.capacity; - } - - hash = ase_stx_strxhash(name,len); - index = hash % stx->symtab.capacity; - - while (1) { - x = stx->symtab.datum[index]; - if (x == stx->nil) { - /* insert a new item into an empty slot */ - x = ase_stx_alloc_char_objectx (stx, name, len); - ASE_STX_CLASS(stx,x) = stx->class_symbol; - stx->symtab.datum[index] = x; - stx->symtab.size++; - break; - } - - if (ase_strxncmp(name, len, - ASE_STX_DATA(stx,x), ASE_STX_SIZE(stx,x)) == 0) break; - - index = (index % stx->symtab.capacity) + 1; - } - - return x; -} - -void ase_stx_traverse_symbol_table ( - ase_stx_t* stx, void (*func) (ase_stx_t*,ase_word_t,void*), void* data) -{ - ase_word_t index, x; - - for (index = 0; index < stx->symtab.capacity; index++) { - x = stx->symtab.datum[index]; - if (x != stx->nil) func (stx, x, data); - } -} - diff --git a/ase/stx/symbol.h b/ase/stx/symbol.h deleted file mode 100644 index 0e9255d5..00000000 --- a/ase/stx/symbol.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * $Id: symbol.h,v 1.1.1.1 2007/03/28 14:05:28 bacon Exp $ - */ - -#ifndef _ASE_STX_SYMBOL_H_ -#define _ASE_STX_SYMBOL_H_ - -#include - -#define ASE_STX_SYMLINK_SIZE 2 -#define ASE_STX_SYMLINK_LINK 0 -#define ASE_STX_SYMLINK_SYMBOL 1 - -struct ase_stx_symlink_t -{ - ase_stx_objhdr_t header; - ase_word_t link; - ase_word_t symbol; -}; - -typedef struct ase_stx_symlink_t ase_stx_symlink_t; - -#ifdef __cplusplus -extern "C" { -#endif - -ase_word_t ase_stx_new_symbol_link (ase_stx_t* stx, ase_word_t sym); - -ase_word_t ase_stx_new_symbol ( - ase_stx_t* stx, const ase_char_t* name); -ase_word_t ase_stx_new_symbolx ( - ase_stx_t* stx, const ase_char_t* name, ase_word_t len); -void ase_stx_traverse_symbol_table ( - ase_stx_t* stx, void (*func) (ase_stx_t*,ase_word_t,void*), void* data); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ase/stx/token.c b/ase/stx/token.c deleted file mode 100644 index 34d02b3b..00000000 --- a/ase/stx/token.c +++ /dev/null @@ -1,77 +0,0 @@ -/* - * $Id: token.c,v 1.1.1.1 2007/03/28 14:05:28 bacon Exp $ - */ - -#include -#include - -ase_stx_token_t* ase_stx_token_open ( - ase_stx_token_t* token, ase_word_t capacity) -{ - if (token == ASE_NULL) { - token = (ase_stx_token_t*) - ase_malloc (ase_sizeof(ase_stx_token_t)); - if (token == ASE_NULL) return ASE_NULL; - token->__dynamic = ase_true; - } - else token->__dynamic = ase_false; - - if (ase_stx_name_open(&token->name, capacity) == ASE_NULL) { - if (token->__dynamic) ase_free (token); - return ASE_NULL; - } - - /* - token->ivalue = 0; - token->fvalue = .0; - */ - token->type = ASE_STX_TOKEN_END; - return token; -} - -void ase_stx_token_close (ase_stx_token_t* token) -{ - ase_stx_name_close (&token->name); - if (token->__dynamic) ase_free (token); -} - -int ase_stx_token_addc (ase_stx_token_t* token, ase_cint_t c) -{ - return ase_stx_name_addc (&token->name, c); -} - -int ase_stx_token_adds (ase_stx_token_t* token, const ase_char_t* s) -{ - return ase_stx_name_adds (&token->name, s); -} - -void ase_stx_token_clear (ase_stx_token_t* token) -{ - /* - token->ivalue = 0; - token->fvalue = .0; - */ - - token->type = ASE_STX_TOKEN_END; - ase_stx_name_clear (&token->name); -} - -ase_char_t* ase_stx_token_yield (ase_stx_token_t* token, ase_word_t capacity) -{ - ase_char_t* p; - - p = ase_stx_name_yield (&token->name, capacity); - if (p == ASE_NULL) return ASE_NULL; - - /* - token->ivalue = 0; - token->fvalue = .0; - */ - token->type = ASE_STX_TOKEN_END; - return p; -} - -int ase_stx_token_compare_name (ase_stx_token_t* token, const ase_char_t* str) -{ - return ase_stx_name_compare (&token->name, str); -} diff --git a/ase/stx/token.h b/ase/stx/token.h deleted file mode 100644 index cc9e5c20..00000000 --- a/ase/stx/token.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * $Id: token.h,v 1.1.1.1 2007/03/28 14:05:28 bacon Exp $ - */ - -#ifndef _ASE_STX_TOKEN_H_ -#define _ASE_STX_TOKEN_H_ - -#include -#include - -enum -{ - ASE_STX_TOKEN_END, - ASE_STX_TOKEN_CHARLIT, - ASE_STX_TOKEN_STRLIT, - ASE_STX_TOKEN_SYMLIT, - ASE_STX_TOKEN_NUMLIT, - ASE_STX_TOKEN_IDENT, - ASE_STX_TOKEN_BINARY, - ASE_STX_TOKEN_KEYWORD, - ASE_STX_TOKEN_PRIMITIVE, - ASE_STX_TOKEN_ASSIGN, - ASE_STX_TOKEN_COLON, - ASE_STX_TOKEN_RETURN, - ASE_STX_TOKEN_LBRACKET, - ASE_STX_TOKEN_RBRACKET, - ASE_STX_TOKEN_LPAREN, - ASE_STX_TOKEN_RPAREN, - ASE_STX_TOKEN_APAREN, - ASE_STX_TOKEN_PERIOD, - ASE_STX_TOKEN_SEMICOLON -}; - -struct ase_stx_token_t -{ - int type; - - /* - ase_stx_int_t ivalue; - ase_stx_real_t fvalue; - */ - ase_stx_name_t name; - ase_bool_t __dynamic; -}; - -typedef struct ase_stx_token_t ase_stx_token_t; - -#ifdef __cplusplus -extern "C" { -#endif - -ase_stx_token_t* ase_stx_token_open ( - ase_stx_token_t* token, ase_word_t capacity); -void ase_stx_token_close (ase_stx_token_t* token); - -int ase_stx_token_addc (ase_stx_token_t* token, ase_cint_t c); -int ase_stx_token_adds (ase_stx_token_t* token, const ase_char_t* s); -void ase_stx_token_clear (ase_stx_token_t* token); -ase_char_t* ase_stx_token_yield (ase_stx_token_t* token, ase_word_t capacity); -int ase_stx_token_compare_name (ase_stx_token_t* token, const ase_char_t* str); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ase/test/awk/Awk.java b/ase/test/awk/Awk.java deleted file mode 100644 index 245859e9..00000000 --- a/ase/test/awk/Awk.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * $Id: Awk.java,v 1.1.1.1 2007/03/28 14:05:28 bacon Exp $ - */ - -import java.net.URL; - -public class Awk extends ase.awk.StdAwk -{ - public Awk () throws ase.awk.Exception - { - super (); - - addBuiltinFunction ("sin", 1, 1); - addBuiltinFunction ("cos", 1, 1); - addBuiltinFunction ("tan", 1, 1); - addBuiltinFunction ("srand", 0, 1); - addBuiltinFunction ("rand", 0, 0); - - addBuiltinFunction ("system", 1, 1); - - addBuiltinFunction ("xxx", 1, 10); - //addBuiltinFunction ("xxx", 1, 1); - //deleteBuiltinFunction ("sin"); - //deleteBuiltinFunction ("sin"); - } - - public Object xxx (long runid, Object[] args) - { - System.out.println ("<>"); - for (int i = 0; i < args.length; i++) - { - System.out.print ("ARG #" + i); - System.out.print (": "); - if (args[i] == null) System.out.println ("nil"); - else System.out.println (args[i].toString()); - } - return null; - //return new String ("return value"); - //return new Double (1.234); - //return new Float (1.234); - //return new Integer (1001); - //return new Long (1001); - //return new Short ((short)1001); - } - - protected String[] consoleInputNames () - { - String[] cin = new String[3]; - cin[0] = "c1.txt"; - cin[1] = "c2.txt"; - cin[2] = "c3.txt"; - return cin; - } - - protected String[] consoleOutputNames () - { - String[] cout = new String[1]; - cout[0] = ""; - return cout; -/* - String[] cout = new String[3]; - cout[0] = "c4.txt"; - cout[1] = "c5.txt"; - cout[2] = ""; - return cout; -*/ - } - - protected String[] sourceInputNames () - { - String[] sin = new String[1]; - sin[0] = "c:/projects/ase/test/awk/t.awk"; - return sin; - } - - /* - protected String sourceOutputName () - { - return ""; - } - */ - - public static void main (String[] args) - { - Awk awk = null; - - URL url = ase.awk.Awk.class.getResource ("aseawk_jni.dll"); - if (url == null) url = ase.awk.Awk.class.getResource ("aseawk_jni.so"); - if (url != null) System.load (url.getFile()); - - try - { - awk = new Awk (); - awk.setMaxDepth (Awk.DEPTH_BLOCK_PARSE, 30); - awk.setDebug (true); - //awk.setDebug (false); - - //awk.setOption (awk.getOption() | OPTION_STRBASEONE); - System.out.println ("Option: [" + awk.getOption() + "]"); - - awk.parse (); - - System.out.println ("about to run"); - String[] aaa = new String[3]; - aaa[0] = "abcdefg"; - aaa[1] = "qwerty"; - aaa[2] = "awk is bad"; - awk.run ("main", aaa); - } - catch (ase.awk.Exception e) - { - if (e.getLine() == 0) - { - System.out.println ("ase.awk.Exception - " + e.getMessage()); - } - else - { - System.out.println ( - "ase.awk.Exception at line " + - e.getLine() + " - " + e.getMessage()); - } - } - finally - { - if (awk != null) - { - awk.close (); - awk = null; - } - } - System.out.println ("==== end of awk ===="); - } - -} diff --git a/ase/test/awk/AwkApplet.html b/ase/test/awk/AwkApplet.html deleted file mode 100644 index 1570297b..00000000 --- a/ase/test/awk/AwkApplet.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - diff --git a/ase/test/awk/AwkApplet.java b/ase/test/awk/AwkApplet.java deleted file mode 100644 index eb6a4d9f..00000000 --- a/ase/test/awk/AwkApplet.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * $Id: AwkApplet.java,v 1.1.1.1 2007/03/28 14:05:28 bacon Exp $ - */ - -import java.applet.*; -import java.awt.*; -import java.awt.event.*; -import java.net.URL; - -public class AwkApplet extends Applet -{ - public void init () - { - Button btn_run; - btn_run = new Button ("Run Awk"); - - btn_run.addActionListener (new ActionListener () - { - public void actionPerformed (ActionEvent e) - { - run_awk (); - } - }); - add (btn_run); - } - - public void stop () {} - public void paint (Graphics g) {} - - private void run_awk () - { - Awk awk = null; - - try - { - /* - URL url = ase.awk.Awk.class.getResource ("aseawk_jni.dll"); - if (url == null) url = ase.awk.Awk.class.getResource ("aseawk_jni.so"); - - if (url != null) System.load (url.getFile()); */ - - try - { - System.load ("c:/projects/ase/test/awk/aseawk_jni.dll"); - } - catch (Exception e) - { - System.err.println ("fuck you"); - } - - - awk = new Awk (); - awk.parse (); - awk.run (); - } - catch (ase.awk.Exception e) - { - System.out.println ("ase.awk.Exception - " + e.getMessage()); - } - finally - { - if (awk != null) awk.close (); - } - } -} diff --git a/ase/test/awk/arg.awk b/ase/test/awk/arg.awk deleted file mode 100644 index 01bdf5f0..00000000 --- a/ase/test/awk/arg.awk +++ /dev/null @@ -1,34 +0,0 @@ -BEGIN { - print "ARGC=", ARGC; - for (i in ARGV) - { - print "ARGV[" i "]", ARGV[i]; - } - - print "----------------------"; - print "ARGC=", ARGC; - split ("111 22 333 555 666 777", ARGV); - for (i in ARGV) - { - print "ARGV[" i "]", ARGV[i]; - } - - #for (i = 0 - # i < 20 - # i;;) print "[" i "]"; - #for (i = 0 - # (i < 20) - # i;;) print "[" i "]"; - - #printf 10, 20, 30; - if (ARGC >= 0) printf ("ARGC [%++#10.10i] is positive\n", 10); - if (ARGC >= 0) printf ("ARGC [%++#10.10f] is positive\n", 10); - if (ARGC >= 0) printf ("ARGC [%++#10.10E] is positive\n", 10124.1123); - if (ARGC >= 0) printf ("ARGC [%++#10.10G] is positive\n", 10124.1123); - if (ARGC >= 0) printf ("ARGC [%++#10.10g] is positive\n", 10124.1123); - if (ARGC >= 0) printf ("ARGC [%++#10.10f] is positive\n", 10124.1123); - printf ("[%d], [%f], [%s]\n", 10124.1123, 10124.1123, 10124.1123); - printf ("[%-10c] [% 0*.*d]\n", 65, 45, 48, -1); - - print sprintf ("abc%d %*.*d %c %s %c", 10, 20, 30, 40, "good", "good", 75.34); -} diff --git a/ase/test/awk/arr.awk b/ase/test/awk/arr.awk deleted file mode 100644 index f3b58e93..00000000 --- a/ase/test/awk/arr.awk +++ /dev/null @@ -1,18 +0,0 @@ -BEGIN { - a[1,2,3] = 20; - a[4,5,6] = 30; - - for (i in a) - { - n = split (i, k, SUBSEP); - for (j = 1; j < n; j++) - { - print k[j] - } - } - - if ((1,2,3) in a) - { - print a[1,2,3]; - } -} diff --git a/ase/test/awk/asetestawk.dsp b/ase/test/awk/asetestawk.dsp deleted file mode 100644 index 5f2716f0..00000000 --- a/ase/test/awk/asetestawk.dsp +++ /dev/null @@ -1,102 +0,0 @@ -# Microsoft Developer Studio Project File - Name="asetestawk" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Console Application" 0x0103 - -CFG=asetestawk - Win32 Debug -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "asetestawk.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "asetestawk.mak" CFG="asetestawk - Win32 Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "asetestawk - Win32 Release" (based on "Win32 (x86) Console Application") -!MESSAGE "asetestawk - Win32 Debug" (based on "Win32 (x86) Console Application") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -RSC=rc.exe - -!IF "$(CFG)" == "asetestawk - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "../../release/bin" -# PROP Intermediate_Dir "release" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /MT /W3 /GX /O2 /I "..\..\.." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_UNICODE" /D _WIN32_WINNT=0x0400 /YX /FD /c -# ADD BASE RSC /l 0x409 /d "NDEBUG" -# ADD RSC /l 0x409 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 -# ADD LINK32 asecmn.lib aseawk.lib aseutl.lib user32.lib kernel32.lib /nologo /subsystem:console /machine:I386 /out:"$(OutDir)/aseawk.exe" /libpath:"$(OutDir)\..\lib" - -!ELSEIF "$(CFG)" == "asetestawk - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "../../debug/bin" -# PROP Intermediate_Dir "debug" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c -# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "..\..\.." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D _WIN32_WINNT=0x0400 /FR /YX /FD /GZ /c -# ADD BASE RSC /l 0x409 /d "_DEBUG" -# ADD RSC /l 0x409 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept -# ADD LINK32 asecmn.lib aseawk.lib aseutl.lib user32.lib kernel32.lib /nologo /subsystem:console /debug /machine:I386 /out:"$(OutDir)/aseawk.exe" /pdbtype:sept /libpath:"$(OutDir)\..\lib" - -!ENDIF - -# Begin Target - -# Name "asetestawk - Win32 Release" -# Name "asetestawk - Win32 Debug" -# Begin Group "Source Files" - -# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" -# Begin Source File - -SOURCE=.\awk.c -# End Source File -# End Group -# Begin Group "Header Files" - -# PROP Default_Filter "h;hpp;hxx;hm;inl" -# End Group -# Begin Group "Resource Files" - -# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" -# End Group -# End Target -# End Project diff --git a/ase/test/awk/awk.c b/ase/test/awk/awk.c deleted file mode 100644 index 3e2588bf..00000000 --- a/ase/test/awk/awk.c +++ /dev/null @@ -1,1081 +0,0 @@ -/* - * $Id: awk.c,v 1.1.1.1 2007/03/28 14:05:29 bacon Exp $ - */ - -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include - -#if defined(_WIN32) - #include - #include - #include - #pragma warning (disable: 4996) - #pragma warning (disable: 4296) -#endif - -#if defined(__linux) && defined(_DEBUG) -#include -#endif - -#if defined(_WIN32) && defined(_MSC_VER) && defined(_DEBUG) -#define _CRTDBG_MAP_ALLOC -#include -#endif - -struct awk_src_io -{ - const ase_char_t* input_file; - FILE* input_handle; -}; - -#if defined(_WIN32) -struct mmgr_data_t -{ - HANDLE heap; -}; -#endif - -#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 -#endif - -#ifndef NDEBUG -void ase_assert_abort (void) -{ - abort (); -} - -void ase_assert_printf (const ase_char_t* fmt, ...) -{ - va_list ap; -#ifdef _WIN32 - int n; - ase_char_t buf[1024]; -#endif - - va_start (ap, fmt); -#if defined(_WIN32) - n = _vsntprintf (buf, ASE_COUNTOF(buf), fmt, ap); - if (n < 0) buf[ASE_COUNTOF(buf)-1] = ASE_T('\0'); - - #if defined(_MSC_VER) && (_MSC_VER<1400) - MessageBox (NULL, buf, - ASE_T("Assertion Failure"), MB_OK|MB_ICONERROR); - #else - MessageBox (NULL, buf, - ASE_T("\uB2DD\uAE30\uB9AC \uC870\uB610"), MB_OK|MB_ICONERROR); - #endif -#else - ase_vprintf (fmt, ap); -#endif - va_end (ap); -} -#endif - -static void dprintf (const ase_char_t* fmt, ...) -{ - va_list ap; - va_start (ap, fmt); - ase_vfprintf (stderr, fmt, ap); - va_end (ap); -} - -static void custom_awk_dprintf (void* custom, const ase_char_t* fmt, ...) -{ - va_list ap; - va_start (ap, fmt); - ase_vfprintf (stderr, fmt, ap); - va_end (ap); -} - - -/* custom memory management function */ -static void* custom_awk_malloc (void* custom, ase_size_t n) -{ -#ifdef _WIN32 - return HeapAlloc (((struct mmgr_data_t*)custom)->heap, 0, n); -#else - return malloc (n); -#endif -} - -static void* custom_awk_realloc (void* custom, void* ptr, ase_size_t n) -{ -#ifdef _WIN32 - /* HeapReAlloc behaves differently from realloc */ - if (ptr == NULL) - return HeapAlloc (((struct mmgr_data_t*)custom)->heap, 0, n); - else - return HeapReAlloc (((struct mmgr_data_t*)custom)->heap, 0, ptr, n); -#else - return realloc (ptr, n); -#endif -} - -static void custom_awk_free (void* custom, void* ptr) -{ -#ifdef _WIN32 - HeapFree (((struct mmgr_data_t*)custom)->heap, 0, ptr); -#else - free (ptr); -#endif -} - -/* custom character class functions */ -static ase_bool_t custom_awk_isupper (void* custom, ase_cint_t c) -{ - return ase_isupper (c); -} - -static ase_bool_t custom_awk_islower (void* custom, ase_cint_t c) -{ - return ase_islower (c); -} - -static ase_bool_t custom_awk_isalpha (void* custom, ase_cint_t c) -{ - return ase_isalpha (c); -} - -static ase_bool_t custom_awk_isdigit (void* custom, ase_cint_t c) -{ - return ase_isdigit (c); -} - -static ase_bool_t custom_awk_isxdigit (void* custom, ase_cint_t c) -{ - return ase_isxdigit (c); -} - -static ase_bool_t custom_awk_isalnum (void* custom, ase_cint_t c) -{ - return ase_isalnum (c); -} - -static ase_bool_t custom_awk_isspace (void* custom, ase_cint_t c) -{ - return ase_isspace (c); -} - -static ase_bool_t custom_awk_isprint (void* custom, ase_cint_t c) -{ - return ase_isprint (c); -} - -static ase_bool_t custom_awk_isgraph (void* custom, ase_cint_t c) -{ - return ase_isgraph (c); -} - -static ase_bool_t custom_awk_iscntrl (void* custom, ase_cint_t c) -{ - return ase_iscntrl (c); -} - -static ase_bool_t custom_awk_ispunct (void* custom, ase_cint_t c) -{ - return ase_ispunct (c); -} - -static ase_cint_t custom_awk_toupper (void* custom, ase_cint_t c) -{ - return ase_toupper (c); -} - -static ase_cint_t custom_awk_tolower (void* custom, ase_cint_t c) -{ - return ase_tolower (c); -} - - -/* custom miscellaneous functions */ - -static ase_real_t custom_awk_pow (void* custom, ase_real_t x, ase_real_t y) -{ - return pow (x, y); -} - - -static int custom_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; -} - - -static 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->input_file == ASE_NULL) return 0; - src_io->input_handle = ase_fopen (src_io->input_file, ASE_T("r")); - if (src_io->input_handle == NULL) return -1; - return 1; - } - else if (cmd == ASE_AWK_IO_CLOSE) - { - if (src_io->input_file == ASE_NULL) return 0; - fclose ((FILE*)src_io->input_handle); - return 0; - } - else if (cmd == ASE_AWK_IO_READ) - { - if (size <= 0) return -1; - c = ase_fgetc ((FILE*)src_io->input_handle); - if (c == ASE_CHAR_EOF) return 0; - *data = (ase_char_t)c; - return 1; - } - - return -1; -} - -static ase_ssize_t awk_srcio_out ( - int cmd, void* arg, ase_char_t* data, ase_size_t size) -{ - /*struct awk_src_io* src_io = (struct awk_src_io*)arg;*/ - - if (cmd == ASE_AWK_IO_OPEN) return 1; - else if (cmd == ASE_AWK_IO_CLOSE) - { - fflush (stdout); - return 0; - } - else if (cmd == ASE_AWK_IO_WRITE) - { - int n = ase_fprintf (stdout, ASE_T("%.*s"), size, data); - if (n < 0) return -1; - - return size; - } - - return -1; -} - -static 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; /* TODO: any way to set the error number? */ - - dprintf (ASE_T("opening %s of type %d (pipe)\n"), epa->name, epa->type); - handle = ase_popen (epa->name, mode); - if (handle == NULL) return -1; - epa->handle = (void*)handle; - return 1; - } - - case ASE_AWK_IO_CLOSE: - { - dprintf (ASE_T("closing %s of type (pipe) %d\n"), epa->name, epa->type); - 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; -} - -static 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; /* TODO: any way to set the error number? */ - - dprintf (ASE_T("opening %s of type %d (file)\n"), epa->name, epa->type); - handle = ase_fopen (epa->name, mode); - if (handle == NULL) - { - ase_cstr_t errarg; - - errarg.ptr = epa->name; - errarg.len = ase_strlen(epa->name); - - - ase_awk_setrunerror (epa->run, ASE_AWK_EOPEN, 0, &errarg, 1); - return -1; - } - - epa->handle = (void*)handle; - return 1; - } - - case ASE_AWK_IO_CLOSE: - { - dprintf (ASE_T("closing %s of type %d (file)\n"), epa->name, epa->type); - 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; -} - -static int open_extio_console (ase_awk_extio_t* epa); -static int close_extio_console (ase_awk_extio_t* epa); -static int next_extio_console (ase_awk_extio_t* epa); - -static ase_size_t infile_no = 0; -static const ase_char_t* infiles[1000] = -{ - ASE_T(""), - ASE_NULL -}; - -static 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) - { - return open_extio_console (epa); - } - else if (cmd == ASE_AWK_IO_CLOSE) - { - return close_extio_console (epa); - } - else if (cmd == ASE_AWK_IO_READ) - { - while (ase_fgets (data, size, (FILE*)epa->handle) == ASE_NULL) - { - if (ferror((FILE*)epa->handle)) return -1; - - /* it has reached the end of the current file. - * open the next file if available */ - if (infiles[infile_no] == ASE_NULL) - { - /* no more input console */ - return 0; - } - - if (infiles[infile_no][0] == ASE_T('\0')) - { - if (epa->handle != ASE_NULL && - epa->handle != stdin && - epa->handle != stdout && - epa->handle != stderr) - { - /* TODO: ................................ */ - if (fclose ((FILE*)epa->handle) == EOF) - { - ase_cstr_t errarg; - - errarg.ptr = ASE_T("consolXXXe"); - errarg.len = 7; - - ase_awk_setrunerror (epa->run, ASE_AWK_ECLOSE, 0, &errarg, 1); - return -1; - } - } - - epa->handle = stdin; - } - else - { - FILE* fp = ase_fopen (infiles[infile_no], ASE_T("r")); - if (fp == ASE_NULL) - { - ase_cstr_t errarg; - - errarg.ptr = infiles[infile_no]; - errarg.len = ase_strlen(infiles[infile_no]); - - ase_awk_setrunerror (epa->run, ASE_AWK_EOPEN, 0, &errarg, 1); - return -1; - } - - if (ase_awk_setfilename ( - epa->run, infiles[infile_no], - ase_strlen(infiles[infile_no])) == -1) - { - fclose (fp); - return -1; - } - - if (epa->handle != ASE_NULL && - epa->handle != stdin && - epa->handle != stdout && - epa->handle != stderr) - { - /* TODO: ................................ */ - if (fclose ((FILE*)epa->handle) == EOF) - { - ase_cstr_t errarg; - - errarg.ptr = ASE_T("console"); - errarg.len = 7; - - ase_awk_setrunerror (epa->run, ASE_AWK_ECLOSE, 0, &errarg, 1); - - fclose (fp); - return -1; - } - } - - dprintf (ASE_T("open the next console [%s]\n"), infiles[infile_no]); - epa->handle = fp; - } - - infile_no++; - } - - 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 next_extio_console (epa); - } - - return -1; -} - -static int open_extio_console (ase_awk_extio_t* epa) -{ - /* TODO: OpenConsole in GUI APPLICATION */ - - dprintf (ASE_T("opening console[%s] of type %x\n"), epa->name, epa->type); - - if (epa->mode == ASE_AWK_EXTIO_CONSOLE_READ) - { - if (infiles[infile_no] == ASE_NULL) - { - /* no more input file */ - dprintf (ASE_T("console - no more file\n"));; - return 0; - } - - if (infiles[infile_no][0] == ASE_T('\0')) - { - dprintf (ASE_T(" console(r) - \n")); - epa->handle = stdin; - } - else - { - /* a temporary variable fp is used here not to change - * any fields of epa when the open operation fails */ - FILE* fp = ase_fopen (infiles[infile_no], ASE_T("r")); - if (fp == ASE_NULL) - { - ase_cstr_t errarg; - - errarg.ptr = infiles[infile_no]; - errarg.len = ase_strlen(infiles[infile_no]); - - ase_awk_setrunerror (epa->run, ASE_AWK_EOPEN, 0, &errarg, 1); - return -1; - } - - dprintf (ASE_T(" console(r) - %s\n"), infiles[infile_no]); - if (ase_awk_setfilename ( - epa->run, infiles[infile_no], - ase_strlen(infiles[infile_no])) == -1) - { - fclose (fp); - return -1; - } - - epa->handle = fp; - } - - infile_no++; - return 1; - } - else if (epa->mode == ASE_AWK_EXTIO_CONSOLE_WRITE) - { - dprintf (ASE_T(" console(w) - \n")); - - if (ase_awk_setofilename (epa->run, ASE_T(""), 0) == -1) - { - return -1; - } - - epa->handle = stdout; - return 1; - } - - return -1; -} - -static int close_extio_console (ase_awk_extio_t* epa) -{ - dprintf (ASE_T("closing console of type %x\n"), epa->type); - - if (epa->handle != ASE_NULL && - epa->handle != stdin && - epa->handle != stdout && - epa->handle != stderr) - { - if (fclose ((FILE*)epa->handle) == EOF) - { - ase_cstr_t errarg; - - errarg.ptr = epa->name; - errarg.len = ase_strlen(epa->name); - - ase_awk_setrunerror (epa->run, ASE_AWK_ECLOSE, 0, &errarg, 1); - return -1; - } - } - - return 0; -} - -static int next_extio_console (ase_awk_extio_t* epa) -{ - int n; - FILE* fp = (FILE*)epa->handle; - - dprintf (ASE_T("switching console[%s] of type %x\n"), epa->name, epa->type); - - n = open_extio_console(epa); - if (n == -1) return -1; - - if (n == 0) - { - /* if there is no more file, keep the previous handle */ - return 0; - } - - if (fp != ASE_NULL && fp != stdin && - fp != stdout && fp != stderr) fclose (fp); - - return n; -} - -ase_awk_t* app_awk = NULL; -ase_awk_run_t* app_run = NULL; - -#ifdef _WIN32 -static BOOL WINAPI stop_run (DWORD ctrl_type) -{ - if (ctrl_type == CTRL_C_EVENT || - ctrl_type == CTRL_CLOSE_EVENT) - { - ase_awk_stop (app_run); - return TRUE; - } - - return FALSE; -} -#else -static void stop_run (int sig) -{ - signal (SIGINT, SIG_IGN); - ase_awk_stop (app_run); - signal (SIGINT, stop_run); -} -#endif - -static void on_run_start (ase_awk_run_t* run, void* custom) -{ - app_run = run; - dprintf (ASE_T("[AWK ABOUT TO START]\n")); -} - -static int print_awk_value (ase_awk_pair_t* pair, void* arg) -{ - ase_awk_run_t* run = (ase_awk_run_t*)arg; - dprintf (ASE_T("%s = "), (const ase_char_t*)pair->key); - ase_awk_dprintval (run, (ase_awk_val_t*)pair->val); - dprintf (ASE_T("\n")); - return 0; -} - -static void on_run_statement ( - ase_awk_run_t* run, ase_size_t line, void* custom) -{ - /*dprintf (L"running %d\n", (int)line);*/ -} - -static void on_run_return ( - ase_awk_run_t* run, ase_awk_val_t* ret, void* custom) -{ - dprintf (ASE_T("[RETURN] - ")); - ase_awk_dprintval (run, ret); - dprintf (ASE_T("\n")); - - dprintf (ASE_T("[NAMED VARIABLES]\n")); - ase_awk_map_walk (ase_awk_getrunnamedvarmap(run), print_awk_value, run); - dprintf (ASE_T("[END NAMED VARIABLES]\n")); -} - -static void on_run_end (ase_awk_run_t* run, int errnum, void* custom_data) -{ - if (errnum != ASE_AWK_ENOERR) - { - dprintf (ASE_T("[AWK ENDED WITH AN ERROR]\n")); - ase_printf (ASE_T("RUN ERROR: CODE [%d] LINE [%u] %s\n"), - errnum, - (unsigned int)ase_awk_getrunerrlin(run), - ase_awk_getrunerrmsg(run)); - } - else dprintf (ASE_T("[AWK ENDED SUCCESSFULLY]\n")); - - app_run = NULL; -} - -static void print_usage (const ase_char_t* argv0) -{ - ase_printf (ASE_T("Usage: %s [-m] [-d] [-a argument]* -f source-file [data-file]*\n"), argv0); -} - -static int run_awk (ase_awk_t* awk, - const ase_char_t* mfn, ase_awk_runarg_t* runarg) -{ - ase_awk_runcbs_t runcbs; - ase_awk_runios_t runios; - - runios.pipe = awk_extio_pipe; - runios.file = awk_extio_file; - runios.console = awk_extio_console; - runios.custom_data = ASE_NULL; - - runcbs.on_start = on_run_start; - runcbs.on_statement = on_run_statement; - runcbs.on_return = on_run_return; - runcbs.on_end = on_run_end; - runcbs.custom_data = ASE_NULL; - - if (ase_awk_run (awk, mfn, &runios, &runcbs, runarg, 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)); - - return -1; - } - - return 0; -} - -#if defined(_WIN32) && defined(TEST_THREAD) -typedef struct thr_arg_t thr_arg_t; -struct thr_arg_t -{ - ase_awk_t* awk; - const ase_char_t* mfn; - ase_awk_runarg_t* runarg; -}; - -static unsigned int __stdcall run_awk_thr (void* arg) -{ - int n; - thr_arg_t* x = (thr_arg_t*)arg; - - n = run_awk (x->awk, x->mfn, x->runarg); - - _endthreadex (n); - return 0; -} -#endif - -static int awk_main (int argc, ase_char_t* argv[]) -{ - ase_awk_t* awk; - ase_awk_srcios_t srcios; - ase_awk_prmfns_t prmfns; - struct awk_src_io src_io = { NULL, NULL }; - int opt, i, file_count = 0; -#ifdef _WIN32 - struct mmgr_data_t mmgr_data; -#endif - const ase_char_t* mfn = ASE_NULL; - int mode = 0; - int runarg_count = 0; - ase_awk_runarg_t runarg[128]; - int deparse = 0; - - opt = 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_STRBASEONE | - ASE_AWK_STRIPSPACES | - ASE_AWK_NEXTOFILE; - - if (argc <= 1) - { - print_usage (argv[0]); - return -1; - } - - for (i = 1; i < argc; i++) - { - if (mode == 0) - { - if (ase_strcmp(argv[i], ASE_T("-m")) == 0) - { - mfn = ASE_T("main"); - } - else if (ase_strcmp(argv[i], ASE_T("-d")) == 0) - { - deparse = 1; - } - else if (ase_strcmp(argv[i], ASE_T("-f")) == 0) - { - /* specify source file */ - mode = 1; - } - else if (ase_strcmp(argv[i], ASE_T("-a")) == 0) - { - /* specify arguments */ - mode = 2; - } - else if (argv[i][0] == ASE_T('-')) - { - print_usage (argv[0]); - return -1; - } - else if (file_count < ASE_COUNTOF(infiles)-1) - { - infiles[file_count] = argv[i]; - file_count++; - } - else - { - print_usage (argv[0]); - return -1; - } - } - else if (mode == 1) /* source mode */ - { - if (argv[i][0] == ASE_T('-')) - { - print_usage (argv[0]); - return -1; - } - - if (src_io.input_file != NULL) - { - print_usage (argv[0]); - return -1; - } - - src_io.input_file = argv[i]; - mode = 0; - } - else if (mode == 2) /* argument mode */ - { - if (argv[i][0] == ASE_T('-')) - { - print_usage (argv[0]); - return -1; - } - - if (runarg_count >= ASE_COUNTOF(runarg)-1) - { - print_usage (argv[0]); - return -1; - } - - runarg[runarg_count].ptr = argv[i]; - runarg[runarg_count].len = ase_strlen(argv[i]); - runarg_count++; - mode = 0; - } - } - - infiles[file_count] = ASE_NULL; - runarg[runarg_count].ptr = NULL; - runarg[runarg_count].len = 0; - - if (mode != 0 || src_io.input_file == NULL) - { - print_usage (argv[0]); - return -1; - } - - memset (&prmfns, 0, ASE_SIZEOF(prmfns)); - - prmfns.mmgr.malloc = custom_awk_malloc; - prmfns.mmgr.realloc = custom_awk_realloc; - prmfns.mmgr.free = custom_awk_free; -#ifdef _WIN32 - mmgr_data.heap = HeapCreate (0, 1000000, 1000000); - if (mmgr_data.heap == NULL) - { - ase_printf (ASE_T("Error: cannot create an awk heap\n")); - return -1; - } - - prmfns.mmgr.custom_data = &mmgr_data; -#else - prmfns.mmgr.custom_data = NULL; -#endif - - prmfns.ccls.is_upper = custom_awk_isupper; - prmfns.ccls.is_lower = custom_awk_islower; - prmfns.ccls.is_alpha = custom_awk_isalpha; - prmfns.ccls.is_digit = custom_awk_isdigit; - prmfns.ccls.is_xdigit = custom_awk_isxdigit; - prmfns.ccls.is_alnum = custom_awk_isalnum; - prmfns.ccls.is_space = custom_awk_isspace; - prmfns.ccls.is_print = custom_awk_isprint; - prmfns.ccls.is_graph = custom_awk_isgraph; - prmfns.ccls.is_cntrl = custom_awk_iscntrl; - prmfns.ccls.is_punct = custom_awk_ispunct; - prmfns.ccls.to_upper = custom_awk_toupper; - prmfns.ccls.to_lower = custom_awk_tolower; - prmfns.ccls.custom_data = NULL; - - prmfns.misc.pow = custom_awk_pow; - prmfns.misc.sprintf = custom_awk_sprintf; - prmfns.misc.dprintf = custom_awk_dprintf; - prmfns.misc.custom_data = NULL; - - if ((awk = ase_awk_open(&prmfns, ASE_NULL)) == ASE_NULL) - { -#ifdef _WIN32 - HeapDestroy (mmgr_data.heap); -#endif - ase_printf (ASE_T("ERROR: cannot open awk\n")); - return -1; - } - - app_awk = awk; - - ase_awk_setoption (awk, opt); - - /* - ase_awk_seterrstr (awk, ASE_AWK_EGBLRED, ASE_T("\uC804\uC5ED\uBCC0\uC218 \'%.*s\'\uAC00 \uC7AC\uC815\uC758 \uB418\uC5C8\uC2B5\uB2C8\uB2E4")); - ase_awk_seterrstr (awk, ASE_AWK_EAFNRED, ASE_T("\uD568\uC218 \'%.*s\'\uAC00 \uC7AC\uC815\uC758 \uB418\uC5C8\uC2B5\uB2C8\uB2E4")); - */ - - srcios.in = awk_srcio_in; - srcios.out = deparse? awk_srcio_out: NULL; - srcios.custom_data = &src_io; - - ase_awk_setmaxdepth ( - awk, ASE_AWK_DEPTH_BLOCK_PARSE | ASE_AWK_DEPTH_EXPR_PARSE, 20); - ase_awk_setmaxdepth ( - awk, ASE_AWK_DEPTH_BLOCK_RUN | ASE_AWK_DEPTH_EXPR_RUN, 50); - - 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; - } - -#ifdef _WIN32 - SetConsoleCtrlHandler (stop_run, TRUE); -#else - signal (SIGINT, stop_run); -#endif - -#if defined(_WIN32) && defined(TEST_THREAD) - { - unsigned int tid; - HANDLE thr[5]; - thr_arg_t arg; - int y; - - arg.awk = awk; - arg.mfn = mfn; - arg.runarg = runarg; - - for (y = 0; y < ASE_COUNTOF(thr); y++) - { - thr[y] = (HANDLE)_beginthreadex (NULL, 0, run_awk_thr, &arg, 0, &tid); - if (thr[y] == (HANDLE)0) - { - ase_printf (ASE_T("ERROR: cannot create a thread %d\n"), y); - } - } - - for (y = 0; y < ASE_COUNTOF(thr); y++) - { - if (thr[y]) WaitForSingleObject (thr[y], INFINITE); - } - } -#else - if (run_awk (awk, mfn, runarg) == -1) - { - ase_awk_close (awk); - return -1; - } -#endif - - ase_awk_close (awk); -#ifdef _WIN32 - HeapDestroy (mmgr_data.heap); -#endif - return 0; -} - -int ase_main (int argc, ase_char_t* argv[]) -{ - int n; - -#if defined(__linux) && defined(_DEBUG) - mtrace (); -#endif -/* -#if defined(_WIN32) && defined(_MSC_VER) && defined(_DEBUG) - _CrtSetDbgFlag (_CRTDBG_LEAK_CHECK_DF | _CRTDBG_ALLOC_MEM_DF | _CRTDBG_CHECK_ALWAYS_DF); -#endif -*/ - - n = awk_main (argc, argv); - -#if defined(__linux) && defined(_DEBUG) - muntrace (); -#endif -#if defined(_WIN32) && defined(_DEBUG) - #if defined(_MSC_VER) - _CrtDumpMemoryLeaks (); - #endif - _tprintf (_T("Press ENTER to quit\n")); - getchar (); -#endif - - return n; -} diff --git a/ase/test/awk/comp.awk b/ase/test/awk/comp.awk deleted file mode 100644 index 4c6220e9..00000000 --- a/ase/test/awk/comp.awk +++ /dev/null @@ -1,121 +0,0 @@ -BEGIN { - OFS="\t\t"; - - print "1==1 :", (1 == 1); - print "1==0 :", (1 == 0); - - print "1.0==1 :", (1.0 == 1); - print "1.1==1 :", (1.1 == 1); - - print "1.0!=1 :", (1.0 != 1); - print "1.1!=1 :", (1.1 != 1); - - print "\"abc\" == \"abc\"", ("abc" == "abc"); - print "\"abc\" != \"abc\"", ("abc" != "abc"); - - print "--------------------------"; - print "a == \"\" :", (a == ""); - print "a >= \"\" :", (a >= ""); - print "a <= \"\" :", (a <= ""); - print "a > \"\" :", (a > ""); - print "a < \"\" :", (a < ""); - - print "--------------------------"; - print "a == \" \" :", (a == " "); - print "a >= \" \" :", (a >= " "); - print "a <= \" \" :", (a <= " "); - print "a > \" \" :", (a > " "); - print "a < \" \" :", (a < " "); - - print "--------------------------"; - print "\"\" == a :", ("" == a); - print "\"\" >= a:", ("" >= a); - print "\"\" <= a:", ("" <= a); - print "\"\" > a:", ("" > a); - print "\"\" < a:", ("" < a); - - print "--------------------------"; - print "\" \" == a :", (" " == a); - print "\" \" >= a:", (" " >= a); - print "\" \" <= a:", (" " <= a); - print "\" \" > a:", (" " > a); - print "\" \" < a:", (" " < a); - - print "--------------------------"; - print "10 == \"10\"", (10 == "10"); - print "10 != \"10\"", (10 != "10"); - print "10 >= \"10\"", (10 >= "10"); - print "10 <= \"10\"", (10 <= "10"); - print "10 > \"10\"", (10 > "10"); - print "10 < \"10\"", (10 < "10"); - - print "--------------------------"; - print "10 == \"11\"", (10 == "11"); - print "10 != \"11\"", (10 != "11"); - print "10 >= \"11\"", (10 >= "11"); - print "10 <= \"11\"", (10 <= "11"); - print "10 > \"11\"", (10 > "11"); - print "10 < \"11\"", (10 < "11"); - - print "--------------------------"; - print "11 == \"10\"", (11 == "10"); - print "11 != \"10\"", (11 != "10"); - print "11 >= \"10\"", (11 >= "10"); - print "11 <= \"10\"", (11 <= "10"); - print "11 > \"10\"", (11 > "10"); - print "11 < \"10\"", (11 < "10"); - - print "--------------------------"; - print "010 == \"8\"", (010 == "8"); - print "010 != \"8\"", (010 != "8"); - print "010 >= \"8\"", (010 >= "8"); - print "010 <= \"8\"", (010 <= "8"); - print "010 > \"8\"", (010 > "8"); - print "010 < \"8\"", (010 < "8"); - - print "--------------------------"; - print "10 == \"10.0\"", (10 == "10.0"); - print "10 != \"10.0\"", (10 != "10.0"); - print "10 >= \"10.0\"", (10 >= "10.0"); - print "10 <= \"10.0\"", (10 <= "10.0"); - print "10 > \"10.0\"", (10 > "10.0"); - print "10 < \"10.0\"", (10 < "10.0"); - - #OFMT="abc"; - print "--------------------------"; - print "10.0 == \"10\"", (10.0 == "10"); - print "10.0 != \"10\"", (10.0 != "10"); - print "10.0 >= \"10\"", (10.0 >= "10"); - print "10.0 <= \"10\"", (10.0 <= "10"); - print "10.0 > \"10\"", (10.0 > "10"); - print "10.0 < \"10\"", (10.0 < "10"); - - print "--------------------------"; - print "\"10\" == 10.0", ("10" == 10.0); - print "\"10\" != 10.0", ("10" != 10.0); - print "\"10\" >= 10.0", ("10" >= 10.0); - print "\"10\" <= 10.0", ("10" <= 10.0); - print "\"10\" > 10.0", ("10" > 10.0); - print "\"10\" < 10.0", ("10" < 10.0); - - print "--------------------------"; - print "\"10\" == 10.1", ("10" == 10.1); - print "\"10\" != 10.1", ("10" != 10.1); - print "\"10\" >= 10.1", ("10" >= 10.1); - print "\"10\" <= 10.1", ("10" <= 10.1); - print "\"10\" > 10.1", ("10" > 10.1); - print "\"10\" < 10.1", ("10" < 10.1); - - #a[10] = 2; - #print a == 1; - - print (0.234 + 1.01123); - print 12345678901234567890E20; - print .123; - print +.123; - print -.123; - print .123E-; - print +.123E-; - print -.123E-; - print -.123E- + "123"; -} diff --git a/ase/test/awk/cou-001.awk b/ase/test/awk/cou-001.awk deleted file mode 100644 index 61c997b1..00000000 --- a/ase/test/awk/cou-001.awk +++ /dev/null @@ -1 +0,0 @@ -{ print $1, $3; } # print country name and population diff --git a/ase/test/awk/cou-001.out b/ase/test/awk/cou-001.out deleted file mode 100644 index b3842fbd..00000000 --- a/ase/test/awk/cou-001.out +++ /dev/null @@ -1,15 +0,0 @@ -{ - print $1,$3; -} - -USSR 275 -Canada 25 -China 1032 -USA 237 -Brazil 134 -India 746 -Mexico 78 -France 55 -Japan 120 -Germany 61 -England 56 diff --git a/ase/test/awk/cou-002.awk b/ase/test/awk/cou-002.awk deleted file mode 100644 index dbe8c549..00000000 --- a/ase/test/awk/cou-002.awk +++ /dev/null @@ -1,15 +0,0 @@ -BEGIN { - FS = "\t"; - printf ("%10s %6s %5s %s\n\n", - "COUNTRY", "AREA", "POP", "CONTINENT"); -} - -{ - printf ("%10s %6d %5d %s\n", $1, $2, $3, $4); - area = area + $2; - pop = pop + $3; -} - -END { - printf ("\n%10s %6d %5d\n", "TOTAL", area, pop); -} diff --git a/ase/test/awk/cou-002.out b/ase/test/awk/cou-002.out deleted file mode 100644 index e8e10501..00000000 --- a/ase/test/awk/cou-002.out +++ /dev/null @@ -1,29 +0,0 @@ -BEGIN { - FS = " "; - printf ("%10s %6s %5s %s\n\n","COUNTRY","AREA","POP","CONTINENT"); -} - -{ - printf ("%10s %6d %5d %s\n",$1,$2,$3,$4); - area = (area + $2); - pop = (pop + $3); -} - -END { - printf ("\n%10s %6d %5d\n","TOTAL",area,pop); -} - COUNTRY AREA POP CONTINENT - - USSR 8649 275 Asia - Canada 3852 25 North America - China 3705 1032 Asia - USA 3615 237 North America - Brazil 3286 134 South America - India 1267 746 Asia - Mexico 762 78 North America - France 211 55 Europe - Japan 144 120 Asia - Germany 96 61 Europe - England 94 56 Europe - - TOTAL 25681 2819 diff --git a/ase/test/awk/cou-003.awk b/ase/test/awk/cou-003.awk deleted file mode 100644 index 8ddb4769..00000000 --- a/ase/test/awk/cou-003.awk +++ /dev/null @@ -1 +0,0 @@ -$3/$2 >= 0.5 diff --git a/ase/test/awk/cou-003.out b/ase/test/awk/cou-003.out deleted file mode 100644 index 05417c26..00000000 --- a/ase/test/awk/cou-003.out +++ /dev/null @@ -1,6 +0,0 @@ -(($3 / $2) >= 0.5) - -India 1267 746 Asia -Japan 144 120 Asia -Germany 96 61 Europe -England 94 56 Europe diff --git a/ase/test/awk/cou-004.awk b/ase/test/awk/cou-004.awk deleted file mode 100644 index df559a9f..00000000 --- a/ase/test/awk/cou-004.awk +++ /dev/null @@ -1 +0,0 @@ -$0 >= "M" diff --git a/ase/test/awk/cou-004.out b/ase/test/awk/cou-004.out deleted file mode 100644 index bb237a77..00000000 --- a/ase/test/awk/cou-004.out +++ /dev/null @@ -1,5 +0,0 @@ -($0 >= "M") - -USSR 8649 275 Asia -USA 3615 237 North America -Mexico 762 78 North America diff --git a/ase/test/awk/cou-005.awk b/ase/test/awk/cou-005.awk deleted file mode 100644 index d609c02f..00000000 --- a/ase/test/awk/cou-005.awk +++ /dev/null @@ -1 +0,0 @@ -$1 < $4 diff --git a/ase/test/awk/cou-005.out b/ase/test/awk/cou-005.out deleted file mode 100644 index 345dae8f..00000000 --- a/ase/test/awk/cou-005.out +++ /dev/null @@ -1,6 +0,0 @@ -($1 < $4) - -Canada 3852 25 North America -Brazil 3286 134 South America -Mexico 762 78 North America -England 94 56 Europe diff --git a/ase/test/awk/cou-006.awk b/ase/test/awk/cou-006.awk deleted file mode 100644 index 19ab3b3c..00000000 --- a/ase/test/awk/cou-006.awk +++ /dev/null @@ -1 +0,0 @@ -$2 < $3 diff --git a/ase/test/awk/cou-006.out b/ase/test/awk/cou-006.out deleted file mode 100644 index 7de5b826..00000000 --- a/ase/test/awk/cou-006.out +++ /dev/null @@ -1,5 +0,0 @@ -($2 < $3) - -India 1267 746 Asia -Mexico 762 78 North America -France 211 55 Europe diff --git a/ase/test/awk/cou-007.awk b/ase/test/awk/cou-007.awk deleted file mode 100644 index d583cd82..00000000 --- a/ase/test/awk/cou-007.awk +++ /dev/null @@ -1 +0,0 @@ -/Asia/ diff --git a/ase/test/awk/cou-007.out b/ase/test/awk/cou-007.out deleted file mode 100644 index 5b1f4af7..00000000 --- a/ase/test/awk/cou-007.out +++ /dev/null @@ -1,6 +0,0 @@ -/Asia/ - -USSR 8649 275 Asia -China 3705 1032 Asia -India 1267 746 Asia -Japan 144 120 Asia diff --git a/ase/test/awk/cou-008.awk b/ase/test/awk/cou-008.awk deleted file mode 100644 index 43069847..00000000 --- a/ase/test/awk/cou-008.awk +++ /dev/null @@ -1 +0,0 @@ -$4 ~ /Asia/ diff --git a/ase/test/awk/cou-008.out b/ase/test/awk/cou-008.out deleted file mode 100644 index d681dfc0..00000000 --- a/ase/test/awk/cou-008.out +++ /dev/null @@ -1,6 +0,0 @@ -($4 ~ /Asia/) - -USSR 8649 275 Asia -China 3705 1032 Asia -India 1267 746 Asia -Japan 144 120 Asia diff --git a/ase/test/awk/cou-009.awk b/ase/test/awk/cou-009.awk deleted file mode 100644 index 9a6a6bc6..00000000 --- a/ase/test/awk/cou-009.awk +++ /dev/null @@ -1 +0,0 @@ -$4 !~ /Asia/ diff --git a/ase/test/awk/cou-009.out b/ase/test/awk/cou-009.out deleted file mode 100644 index df78739f..00000000 --- a/ase/test/awk/cou-009.out +++ /dev/null @@ -1,9 +0,0 @@ -($4 !~ /Asia/) - -Canada 3852 25 North America -USA 3615 237 North America -Brazil 3286 134 South America -Mexico 762 78 North America -France 211 55 Europe -Germany 96 61 Europe -England 94 56 Europe diff --git a/ase/test/awk/cou-010.awk b/ase/test/awk/cou-010.awk deleted file mode 100644 index c3651638..00000000 --- a/ase/test/awk/cou-010.awk +++ /dev/null @@ -1 +0,0 @@ -$0 ~ /Asia/ diff --git a/ase/test/awk/cou-010.out b/ase/test/awk/cou-010.out deleted file mode 100644 index 6b66e924..00000000 --- a/ase/test/awk/cou-010.out +++ /dev/null @@ -1,6 +0,0 @@ -($0 ~ /Asia/) - -USSR 8649 275 Asia -China 3705 1032 Asia -India 1267 746 Asia -Japan 144 120 Asia diff --git a/ase/test/awk/cou-011.awk b/ase/test/awk/cou-011.awk deleted file mode 100644 index b354c678..00000000 --- a/ase/test/awk/cou-011.awk +++ /dev/null @@ -1,3 +0,0 @@ -$2 !~ /^[0-9]+$/ - - diff --git a/ase/test/awk/cou-011.out b/ase/test/awk/cou-011.out deleted file mode 100644 index 1f009317..00000000 --- a/ase/test/awk/cou-011.out +++ /dev/null @@ -1,2 +0,0 @@ -($2 !~ /^[0-9]+$/) - diff --git a/ase/test/awk/cou-012.awk b/ase/test/awk/cou-012.awk deleted file mode 100644 index 7147bc42..00000000 --- a/ase/test/awk/cou-012.awk +++ /dev/null @@ -1 +0,0 @@ -$4 == "Asia" && $3 > 500 diff --git a/ase/test/awk/cou-012.out b/ase/test/awk/cou-012.out deleted file mode 100644 index 636c837d..00000000 --- a/ase/test/awk/cou-012.out +++ /dev/null @@ -1,4 +0,0 @@ -(($4 == "Asia") && ($3 > 500)) - -China 3705 1032 Asia -India 1267 746 Asia diff --git a/ase/test/awk/cou-013.awk b/ase/test/awk/cou-013.awk deleted file mode 100644 index 8926c135..00000000 --- a/ase/test/awk/cou-013.awk +++ /dev/null @@ -1 +0,0 @@ -$4 == "Asia" || $4 == "Europe" diff --git a/ase/test/awk/cou-013.out b/ase/test/awk/cou-013.out deleted file mode 100644 index b0f594db..00000000 --- a/ase/test/awk/cou-013.out +++ /dev/null @@ -1,9 +0,0 @@ -(($4 == "Asia") || ($4 == "Europe")) - -USSR 8649 275 Asia -China 3705 1032 Asia -India 1267 746 Asia -France 211 55 Europe -Japan 144 120 Asia -Germany 96 61 Europe -England 94 56 Europe diff --git a/ase/test/awk/cou-014.awk b/ase/test/awk/cou-014.awk deleted file mode 100644 index 84fe7474..00000000 --- a/ase/test/awk/cou-014.awk +++ /dev/null @@ -1 +0,0 @@ -$4 ~ /^(Asia|Europe)$/ diff --git a/ase/test/awk/cou-014.out b/ase/test/awk/cou-014.out deleted file mode 100644 index eae34bfa..00000000 --- a/ase/test/awk/cou-014.out +++ /dev/null @@ -1,9 +0,0 @@ -($4 ~ /^(Asia|Europe)$/) - -USSR 8649 275 Asia -China 3705 1032 Asia -India 1267 746 Asia -France 211 55 Europe -Japan 144 120 Asia -Germany 96 61 Europe -England 94 56 Europe diff --git a/ase/test/awk/cou-015.awk b/ase/test/awk/cou-015.awk deleted file mode 100644 index 8afea30d..00000000 --- a/ase/test/awk/cou-015.awk +++ /dev/null @@ -1 +0,0 @@ -/Asia/ || /Europe/ diff --git a/ase/test/awk/cou-015.out b/ase/test/awk/cou-015.out deleted file mode 100644 index 28616eda..00000000 --- a/ase/test/awk/cou-015.out +++ /dev/null @@ -1,9 +0,0 @@ -(/Asia/ || /Europe/) - -USSR 8649 275 Asia -China 3705 1032 Asia -India 1267 746 Asia -France 211 55 Europe -Japan 144 120 Asia -Germany 96 61 Europe -England 94 56 Europe diff --git a/ase/test/awk/cou-016.awk b/ase/test/awk/cou-016.awk deleted file mode 100644 index b8c94a01..00000000 --- a/ase/test/awk/cou-016.awk +++ /dev/null @@ -1 +0,0 @@ -/Asia|Europe/ diff --git a/ase/test/awk/cou-016.out b/ase/test/awk/cou-016.out deleted file mode 100644 index 68a43190..00000000 --- a/ase/test/awk/cou-016.out +++ /dev/null @@ -1,9 +0,0 @@ -/Asia|Europe/ - -USSR 8649 275 Asia -China 3705 1032 Asia -India 1267 746 Asia -France 211 55 Europe -Japan 144 120 Asia -Germany 96 61 Europe -England 94 56 Europe diff --git a/ase/test/awk/cou-017.awk b/ase/test/awk/cou-017.awk deleted file mode 100644 index bf01d88f..00000000 --- a/ase/test/awk/cou-017.awk +++ /dev/null @@ -1 +0,0 @@ -/Canada/, /USA/ diff --git a/ase/test/awk/cou-017.out b/ase/test/awk/cou-017.out deleted file mode 100644 index 0beca645..00000000 --- a/ase/test/awk/cou-017.out +++ /dev/null @@ -1,5 +0,0 @@ -/Canada/,/USA/ - -Canada 3852 25 North America -China 3705 1032 Asia -USA 3615 237 North America diff --git a/ase/test/awk/cou-018.awk b/ase/test/awk/cou-018.awk deleted file mode 100644 index 851a3d3c..00000000 --- a/ase/test/awk/cou-018.awk +++ /dev/null @@ -1 +0,0 @@ -/Eurpoe/, /Africa/ diff --git a/ase/test/awk/cou-018.out b/ase/test/awk/cou-018.out deleted file mode 100644 index 77442148..00000000 --- a/ase/test/awk/cou-018.out +++ /dev/null @@ -1,2 +0,0 @@ -/Eurpoe/,/Africa/ - diff --git a/ase/test/awk/cou-019.awk b/ase/test/awk/cou-019.awk deleted file mode 100644 index e4f9bdf0..00000000 --- a/ase/test/awk/cou-019.awk +++ /dev/null @@ -1 +0,0 @@ -FNR == 1, FNR == 5 { print FILENAME ": " $0; } diff --git a/ase/test/awk/cou-019.out b/ase/test/awk/cou-019.out deleted file mode 100644 index 90fdcbc4..00000000 --- a/ase/test/awk/cou-019.out +++ /dev/null @@ -1,9 +0,0 @@ -(FNR == 1),(FNR == 5) { - print ((FILENAME ": ") $0); -} - -cou-en.data: USSR 8649 275 Asia -cou-en.data: Canada 3852 25 North America -cou-en.data: China 3705 1032 Asia -cou-en.data: USA 3615 237 North America -cou-en.data: Brazil 3286 134 South America diff --git a/ase/test/awk/cou-020.awk b/ase/test/awk/cou-020.awk deleted file mode 100644 index fb1ac184..00000000 --- a/ase/test/awk/cou-020.awk +++ /dev/null @@ -1 +0,0 @@ -FNR <= 5 { print FILENAME ": " $0; } diff --git a/ase/test/awk/cou-020.out b/ase/test/awk/cou-020.out deleted file mode 100644 index 12deeda3..00000000 --- a/ase/test/awk/cou-020.out +++ /dev/null @@ -1,9 +0,0 @@ -(FNR <= 5) { - print ((FILENAME ": ") $0); -} - -cou-en.data: USSR 8649 275 Asia -cou-en.data: Canada 3852 25 North America -cou-en.data: China 3705 1032 Asia -cou-en.data: USA 3615 237 North America -cou-en.data: Brazil 3286 134 South America diff --git a/ase/test/awk/cou-021.awk b/ase/test/awk/cou-021.awk deleted file mode 100644 index dfcc0b09..00000000 --- a/ase/test/awk/cou-021.awk +++ /dev/null @@ -1 +0,0 @@ -$4 == "Asia" { print $1, 1000 * $2; } diff --git a/ase/test/awk/cou-021.out b/ase/test/awk/cou-021.out deleted file mode 100644 index 7dfe4dad..00000000 --- a/ase/test/awk/cou-021.out +++ /dev/null @@ -1,8 +0,0 @@ -($4 == "Asia") { - print $1,(1000 * $2); -} - -USSR 8649000 -China 3705000 -India 1267000 -Japan 144000 diff --git a/ase/test/awk/cou-022.awk b/ase/test/awk/cou-022.awk deleted file mode 100644 index 7767c865..00000000 --- a/ase/test/awk/cou-022.awk +++ /dev/null @@ -1,6 +0,0 @@ -#BEGIN { FS = "\t"; OFS = "\t"; } -BEGIN { FS = OFS = "\t"; } -$4 == "North America" { $4 = "NA"; } -$4 == "South America" { $4 = "SA"; } - { print; } - diff --git a/ase/test/awk/cou-022.out b/ase/test/awk/cou-022.out deleted file mode 100644 index b415ed26..00000000 --- a/ase/test/awk/cou-022.out +++ /dev/null @@ -1,27 +0,0 @@ -BEGIN { - FS = OFS = " "; -} - -($4 == "North America") { - $4 = "NA"; -} - -($4 == "South America") { - $4 = "SA"; -} - -{ - print; -} - -USSR 8649 275 Asia -Canada 3852 25 NA -China 3705 1032 Asia -USA 3615 237 NA -Brazil 3286 134 SA -India 1267 746 Asia -Mexico 762 78 NA -France 211 55 Europe -Japan 144 120 Asia -Germany 96 61 Europe -England 94 56 Europe diff --git a/ase/test/awk/cou-023.awk b/ase/test/awk/cou-023.awk deleted file mode 100644 index 540b65c6..00000000 --- a/ase/test/awk/cou-023.awk +++ /dev/null @@ -1,2 +0,0 @@ -BEGIN { FS = OFS = "\t"; } - { $5 = 1000 * $3 / $2; print; } diff --git a/ase/test/awk/cou-023.out b/ase/test/awk/cou-023.out deleted file mode 100644 index 853ae1e1..00000000 --- a/ase/test/awk/cou-023.out +++ /dev/null @@ -1,20 +0,0 @@ -BEGIN { - FS = OFS = " "; -} - -{ - $5 = ((1000 * $3) / $2); - print; -} - -USSR 8649 275 Asia 31.7956 -Canada 3852 25 North America 6.49013 -China 3705 1032 Asia 278.543 -USA 3615 237 North America 65.5602 -Brazil 3286 134 South America 40.7791 -India 1267 746 Asia 588.792 -Mexico 762 78 North America 102.362 -France 211 55 Europe 260.664 -Japan 144 120 Asia 833.333 -Germany 96 61 Europe 635.417 -England 94 56 Europe 595.745 diff --git a/ase/test/awk/cou-024.awk b/ase/test/awk/cou-024.awk deleted file mode 100644 index a10bce8f..00000000 --- a/ase/test/awk/cou-024.awk +++ /dev/null @@ -1,4 +0,0 @@ -$4 == "Asia" { pop = pop + $3; n = n + 1; } -END { print "Total population of the", n, - "Asian countries is", pop, "million."; - } diff --git a/ase/test/awk/cou-024.out b/ase/test/awk/cou-024.out deleted file mode 100644 index 98aae883..00000000 --- a/ase/test/awk/cou-024.out +++ /dev/null @@ -1,9 +0,0 @@ -($4 == "Asia") { - pop = (pop + $3); - n = (n + 1); -} - -END { - print "Total population of the",n,"Asian countries is",pop,"million."; -} -Total population of the 4 Asian countries is 2173 million. diff --git a/ase/test/awk/cou-025.awk b/ase/test/awk/cou-025.awk deleted file mode 100644 index a0eb9ca1..00000000 --- a/ase/test/awk/cou-025.awk +++ /dev/null @@ -1,6 +0,0 @@ -/Asia/ { pop["Asia"] += $3; } -/Europe/ { pop["Europe"] += $3; } -END { print "Asian population is", pop["Asia"], "million."; - print "European population is", pop["Europe"], "million."; - } - diff --git a/ase/test/awk/cou-025.out b/ase/test/awk/cou-025.out deleted file mode 100644 index 503ccd18..00000000 --- a/ase/test/awk/cou-025.out +++ /dev/null @@ -1,14 +0,0 @@ -/Asia/ { - pop["Asia"] += $3; -} - -/Europe/ { - pop["Europe"] += $3; -} - -END { - print "Asian population is",pop["Asia"],"million."; - print "European population is",pop["Europe"],"million."; -} -Asian population is 2173 million. -European population is 172 million. diff --git a/ase/test/awk/cou-026.awk b/ase/test/awk/cou-026.awk deleted file mode 100644 index 0597c6d9..00000000 --- a/ase/test/awk/cou-026.awk +++ /dev/null @@ -1,3 +0,0 @@ -BEGIN { FS = "\t"; } - { pop[$4] += $3; } -END { for (name in pop) print name, pop[name]; } diff --git a/ase/test/awk/cou-026.out b/ase/test/awk/cou-026.out deleted file mode 100644 index 6d05a7e1..00000000 --- a/ase/test/awk/cou-026.out +++ /dev/null @@ -1,16 +0,0 @@ -BEGIN { - FS = " "; -} - -{ - pop[$4] += $3; -} - -END { - for (name in pop) - print name,pop[name]; -} -Europe 172 -South America 134 -North America 340 -Asia 2173 diff --git a/ase/test/awk/cou-027.awk b/ase/test/awk/cou-027.awk deleted file mode 100644 index f8464883..00000000 --- a/ase/test/awk/cou-027.awk +++ /dev/null @@ -1,5 +0,0 @@ -BEGIN { FS = "\t"; } - { pop[$4] += $3; } -END { for (c in pop) - printf ("%15s\t%6d\n", c, pop[c]) | "sort -t'\t' +1rn"; - } diff --git a/ase/test/awk/cou-027.out b/ase/test/awk/cou-027.out deleted file mode 100644 index 57a4ae02..00000000 --- a/ase/test/awk/cou-027.out +++ /dev/null @@ -1,16 +0,0 @@ -BEGIN { - FS = " "; -} - -{ - pop[$4] += $3; -} - -END { - for (c in pop) - printf ("%15s %6d\n",c,pop[c]) | "sort -t' ' +1rn"; -} - Asia 2173 - North America 340 - Europe 172 - South America 134 diff --git a/ase/test/awk/cou-en.data b/ase/test/awk/cou-en.data deleted file mode 100644 index e973031b..00000000 --- a/ase/test/awk/cou-en.data +++ /dev/null @@ -1,11 +0,0 @@ -USSR 8649 275 Asia -Canada 3852 25 North America -China 3705 1032 Asia -USA 3615 237 North America -Brazil 3286 134 South America -India 1267 746 Asia -Mexico 762 78 North America -France 211 55 Europe -Japan 144 120 Asia -Germany 96 61 Europe -England 94 56 Europe diff --git a/ase/test/awk/crash01.awk b/ase/test/awk/crash01.awk deleted file mode 100644 index 8906db6f..00000000 --- a/ase/test/awk/crash01.awk +++ /dev/null @@ -1 +0,0 @@ -BEGIN { CONVFMT="%s"; printf ("%s\n", 10.34); } diff --git a/ase/test/awk/crash02.awk b/ase/test/awk/crash02.awk deleted file mode 100644 index ae49a9b0..00000000 --- a/ase/test/awk/crash02.awk +++ /dev/null @@ -1,9 +0,0 @@ -BEGIN { - #CONVFMT="%s"; - #CONVFMT="%*.*s"; - #CONVFMT="%*.*f"; - printf "[[[[[%s]]]]\n", sprintf ("abc %s abc", sprintf ("def %s %s", sprintf ("%s %s %s", "xyz", 1.2342, "xyz"), sprintf ("ttt %s tttt", 123.12))); - - printf "[[[[%s]]]]\n", sprintf ("ttt %s tttt", 123.12); -} - diff --git a/ase/test/awk/crash04.awk b/ase/test/awk/crash04.awk deleted file mode 100644 index 12821825..00000000 --- a/ase/test/awk/crash04.awk +++ /dev/null @@ -1,17 +0,0 @@ -BEGIN { - - {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{ - {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{ - {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{ - {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{ - {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{ - - abc = 20; - }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}} - }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}} - }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}} - }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}} - }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}} - -} - diff --git a/ase/test/awk/crash05.awk b/ase/test/awk/crash05.awk deleted file mode 100644 index f663bc56..00000000 --- a/ase/test/awk/crash05.awk +++ /dev/null @@ -1,5 +0,0 @@ -BEGIN { - a = (((((10+20))))); - b = (((((((((((((((((((10+20))))))))))))))))))); - c = ((((((((((((((((((((((((((((10 + 20)))))))))))))))))))))))))))); -} diff --git a/ase/test/awk/crash08.awk b/ase/test/awk/crash08.awk deleted file mode 100644 index 130cf3c8..00000000 --- a/ase/test/awk/crash08.awk +++ /dev/null @@ -1,23 +0,0 @@ -function a() -{ - print "aaaa"; - a(); -} - -BEGIN { - a = (b = 20); - print a; print b; for(i=j=1; i< 10; i++) print i, j; - - a += b += 20; - print a; print b; for(i=j=1; i< 10; i++) print i, j; - - j = (a < 20)? k = 20: c = 30; - print (a < 20)? k = 20: c = 30; - print "j=" j; - print "k=" k; - print "c=" c; - - a(); -} - - diff --git a/ase/test/awk/descrip.mms b/ase/test/awk/descrip.mms deleted file mode 100644 index 3c7337f9..00000000 --- a/ase/test/awk/descrip.mms +++ /dev/null @@ -1,13 +0,0 @@ -# -# OpenVMS MMS/MMK -# - -objects = awk.obj - -CFLAGS = /include="../../.." -#CFLAGS = /pointer_size=long /include="../../.." - -aseawk.exe : $(objects) - link /executable=aseawk.exe $(objects),[-.-.awk]aseawk/library,[-.-.utl]aseutl/library - -awk.obj depends_on awk.c diff --git a/ase/test/awk/emp-001.awk b/ase/test/awk/emp-001.awk deleted file mode 100644 index 83354291..00000000 --- a/ase/test/awk/emp-001.awk +++ /dev/null @@ -1 +0,0 @@ -$3 > 0 { print $1, $2 * $3; } diff --git a/ase/test/awk/emp-001.out b/ase/test/awk/emp-001.out deleted file mode 100644 index 9d894bb6..00000000 --- a/ase/test/awk/emp-001.out +++ /dev/null @@ -1,8 +0,0 @@ -($3 > 0) { - print $1,($2 * $3); -} - -Kathy 40 -Mark 100 -Mary 121 -Susie 76.5 diff --git a/ase/test/awk/emp-002.awk b/ase/test/awk/emp-002.awk deleted file mode 100644 index 06607ada..00000000 --- a/ase/test/awk/emp-002.awk +++ /dev/null @@ -1 +0,0 @@ -$3 == 0 { print $1; } diff --git a/ase/test/awk/emp-002.out b/ase/test/awk/emp-002.out deleted file mode 100644 index 8f669f7e..00000000 --- a/ase/test/awk/emp-002.out +++ /dev/null @@ -1,6 +0,0 @@ -($3 == 0) { - print $1; -} - -Beth -Dan diff --git a/ase/test/awk/emp-003.awk b/ase/test/awk/emp-003.awk deleted file mode 100644 index fcfbe32c..00000000 --- a/ase/test/awk/emp-003.awk +++ /dev/null @@ -1 +0,0 @@ -{ print NF, $1, $NF; } diff --git a/ase/test/awk/emp-003.out b/ase/test/awk/emp-003.out deleted file mode 100644 index 8c37c7e9..00000000 --- a/ase/test/awk/emp-003.out +++ /dev/null @@ -1,10 +0,0 @@ -{ - print NF,$1,$NF; -} - -3 Beth 0 -3 Dan 0 -3 Kathy 10 -3 Mark 20 -3 Mary 22 -3 Susie 18 diff --git a/ase/test/awk/emp-004.awk b/ase/test/awk/emp-004.awk deleted file mode 100644 index 30bc76fb..00000000 --- a/ase/test/awk/emp-004.awk +++ /dev/null @@ -1 +0,0 @@ -{ print NR, $0; } diff --git a/ase/test/awk/emp-004.out b/ase/test/awk/emp-004.out deleted file mode 100644 index 5bb7e8af..00000000 --- a/ase/test/awk/emp-004.out +++ /dev/null @@ -1,10 +0,0 @@ -{ - print NR,$0; -} - -1 Beth 4.00 0 -2 Dan 3.74 0 -3 Kathy 4.00 10 -4 Mark 5.00 20 -5 Mary 5.50 22 -6 Susie 4.25 18 diff --git a/ase/test/awk/emp-005.awk b/ase/test/awk/emp-005.awk deleted file mode 100644 index 9ed5d9bc..00000000 --- a/ase/test/awk/emp-005.awk +++ /dev/null @@ -1 +0,0 @@ -{ print "total pay for", $1, "is", $2 * $3; } diff --git a/ase/test/awk/emp-005.out b/ase/test/awk/emp-005.out deleted file mode 100644 index fc0c9e81..00000000 --- a/ase/test/awk/emp-005.out +++ /dev/null @@ -1,10 +0,0 @@ -{ - print "total pay for",$1,"is",($2 * $3); -} - -total pay for Beth is 0 -total pay for Dan is 0 -total pay for Kathy is 40 -total pay for Mark is 100 -total pay for Mary is 121 -total pay for Susie is 76.5 diff --git a/ase/test/awk/emp-006.awk b/ase/test/awk/emp-006.awk deleted file mode 100644 index 035b20b5..00000000 --- a/ase/test/awk/emp-006.awk +++ /dev/null @@ -1 +0,0 @@ -{ printf ("total pay for %s is $%.2f\n", $1, $2 * $3); } diff --git a/ase/test/awk/emp-006.out b/ase/test/awk/emp-006.out deleted file mode 100644 index 3ba88ebb..00000000 --- a/ase/test/awk/emp-006.out +++ /dev/null @@ -1,10 +0,0 @@ -{ - printf ("total pay for %s is $%.2f\n",$1,($2 * $3)); -} - -total pay for Beth is $0.00 -total pay for Dan is $0.00 -total pay for Kathy is $40.00 -total pay for Mark is $100.00 -total pay for Mary is $121.00 -total pay for Susie is $76.50 diff --git a/ase/test/awk/emp-007.awk b/ase/test/awk/emp-007.awk deleted file mode 100644 index 4c7a7b63..00000000 --- a/ase/test/awk/emp-007.awk +++ /dev/null @@ -1 +0,0 @@ -{ printf ("%-8s $%6.2f\n", $1, $2 * $3); } diff --git a/ase/test/awk/emp-007.out b/ase/test/awk/emp-007.out deleted file mode 100644 index b0603f79..00000000 --- a/ase/test/awk/emp-007.out +++ /dev/null @@ -1,10 +0,0 @@ -{ - printf ("%-8s $%6.2f\n",$1,($2 * $3)); -} - -Beth $ 0.00 -Dan $ 0.00 -Kathy $ 40.00 -Mark $100.00 -Mary $121.00 -Susie $ 76.50 diff --git a/ase/test/awk/emp-008.awk b/ase/test/awk/emp-008.awk deleted file mode 100644 index 73c4bd78..00000000 --- a/ase/test/awk/emp-008.awk +++ /dev/null @@ -1 +0,0 @@ -$2 >= 5 diff --git a/ase/test/awk/emp-008.out b/ase/test/awk/emp-008.out deleted file mode 100644 index 019e78b7..00000000 --- a/ase/test/awk/emp-008.out +++ /dev/null @@ -1,4 +0,0 @@ -($2 >= 5) - -Mark 5.00 20 -Mary 5.50 22 diff --git a/ase/test/awk/emp-009.awk b/ase/test/awk/emp-009.awk deleted file mode 100644 index a8bd5dff..00000000 --- a/ase/test/awk/emp-009.awk +++ /dev/null @@ -1 +0,0 @@ -$2 * $3 > 50 { printf ("$%.2f for %s\n", $2 * $3, $1); } diff --git a/ase/test/awk/emp-009.out b/ase/test/awk/emp-009.out deleted file mode 100644 index 76deb332..00000000 --- a/ase/test/awk/emp-009.out +++ /dev/null @@ -1,7 +0,0 @@ -(($2 * $3) > 50) { - printf ("$%.2f for %s\n",($2 * $3),$1); -} - -$100.00 for Mark -$121.00 for Mary -$76.50 for Susie diff --git a/ase/test/awk/emp-010.awk b/ase/test/awk/emp-010.awk deleted file mode 100644 index ec5dc961..00000000 --- a/ase/test/awk/emp-010.awk +++ /dev/null @@ -1 +0,0 @@ -$1 == "Susie" diff --git a/ase/test/awk/emp-010.out b/ase/test/awk/emp-010.out deleted file mode 100644 index eaa876ae..00000000 --- a/ase/test/awk/emp-010.out +++ /dev/null @@ -1,3 +0,0 @@ -($1 == "Susie") - -Susie 4.25 18 diff --git a/ase/test/awk/emp-011.awk b/ase/test/awk/emp-011.awk deleted file mode 100644 index a37ed825..00000000 --- a/ase/test/awk/emp-011.awk +++ /dev/null @@ -1 +0,0 @@ -/Susie/ diff --git a/ase/test/awk/emp-011.out b/ase/test/awk/emp-011.out deleted file mode 100644 index c0d44782..00000000 --- a/ase/test/awk/emp-011.out +++ /dev/null @@ -1,3 +0,0 @@ -/Susie/ - -Susie 4.25 18 diff --git a/ase/test/awk/emp-012.awk b/ase/test/awk/emp-012.awk deleted file mode 100644 index c5c84049..00000000 --- a/ase/test/awk/emp-012.awk +++ /dev/null @@ -1 +0,0 @@ -$2 >= 4 || $3 >= 20 diff --git a/ase/test/awk/emp-012.out b/ase/test/awk/emp-012.out deleted file mode 100644 index 73946169..00000000 --- a/ase/test/awk/emp-012.out +++ /dev/null @@ -1,7 +0,0 @@ -(($2 >= 4) || ($3 >= 20)) - -Beth 4.00 0 -Kathy 4.00 10 -Mark 5.00 20 -Mary 5.50 22 -Susie 4.25 18 diff --git a/ase/test/awk/emp-013.awk b/ase/test/awk/emp-013.awk deleted file mode 100644 index 83a08fbd..00000000 --- a/ase/test/awk/emp-013.awk +++ /dev/null @@ -1,2 +0,0 @@ -$2 >= 4 -$3 >= 20 diff --git a/ase/test/awk/emp-013.out b/ase/test/awk/emp-013.out deleted file mode 100644 index 0b69688a..00000000 --- a/ase/test/awk/emp-013.out +++ /dev/null @@ -1,11 +0,0 @@ -($2 >= 4) - -($3 >= 20) - -Beth 4.00 0 -Kathy 4.00 10 -Mark 5.00 20 -Mark 5.00 20 -Mary 5.50 22 -Mary 5.50 22 -Susie 4.25 18 diff --git a/ase/test/awk/emp-014.awk b/ase/test/awk/emp-014.awk deleted file mode 100644 index a210459a..00000000 --- a/ase/test/awk/emp-014.awk +++ /dev/null @@ -1 +0,0 @@ -!($2 < 4 && $3 < 20) diff --git a/ase/test/awk/emp-014.out b/ase/test/awk/emp-014.out deleted file mode 100644 index cde00a5a..00000000 --- a/ase/test/awk/emp-014.out +++ /dev/null @@ -1,7 +0,0 @@ -(!((($2 < 4) && ($3 < 20)))) - -Beth 4.00 0 -Kathy 4.00 10 -Mark 5.00 20 -Mary 5.50 22 -Susie 4.25 18 diff --git a/ase/test/awk/emp-015.awk b/ase/test/awk/emp-015.awk deleted file mode 100644 index 81d81580..00000000 --- a/ase/test/awk/emp-015.awk +++ /dev/null @@ -1,5 +0,0 @@ -NF != 3 { print $0, "number of fields is not equal to 3"; } -$2 < 3.35 { print $0, "rate is below minimum wage"; } -$2 > 10 { print $0, "rate exceeds $10 per hour"; } -$3 < 0 { print $0, "negative hours worked"; } -$3 > 60 { print $0, "too many hours worked"; } diff --git a/ase/test/awk/emp-015.out b/ase/test/awk/emp-015.out deleted file mode 100644 index 3c696f7e..00000000 --- a/ase/test/awk/emp-015.out +++ /dev/null @@ -1,20 +0,0 @@ -(NF != 3) { - print $0,"number of fields is not equal to 3"; -} - -($2 < 3.35) { - print $0,"rate is below minimum wage"; -} - -($2 > 10) { - print $0,"rate exceeds $10 per hour"; -} - -($3 < 0) { - print $0,"negative hours worked"; -} - -($3 > 60) { - print $0,"too many hours worked"; -} - diff --git a/ase/test/awk/emp-016.awk b/ase/test/awk/emp-016.awk deleted file mode 100644 index 22e0700e..00000000 --- a/ase/test/awk/emp-016.awk +++ /dev/null @@ -1,2 +0,0 @@ -BEGIN { print "NAME RATE HOURS"; print ""; } - { print; } diff --git a/ase/test/awk/emp-016.out b/ase/test/awk/emp-016.out deleted file mode 100644 index 46f95c08..00000000 --- a/ase/test/awk/emp-016.out +++ /dev/null @@ -1,17 +0,0 @@ -BEGIN { - print "NAME RATE HOURS"; - print ""; -} - -{ - print; -} - -NAME RATE HOURS - -Beth 4.00 0 -Dan 3.74 0 -Kathy 4.00 10 -Mark 5.00 20 -Mary 5.50 22 -Susie 4.25 18 diff --git a/ase/test/awk/emp-017.awk b/ase/test/awk/emp-017.awk deleted file mode 100644 index 69408a07..00000000 --- a/ase/test/awk/emp-017.awk +++ /dev/null @@ -1,2 +0,0 @@ -$3 > 15 { emp = emp + 1; } -END { print emp, "employees worked more than 15 hours"; } diff --git a/ase/test/awk/emp-017.out b/ase/test/awk/emp-017.out deleted file mode 100644 index e7e5ac24..00000000 --- a/ase/test/awk/emp-017.out +++ /dev/null @@ -1,8 +0,0 @@ -($3 > 15) { - emp = (emp + 1); -} - -END { - print emp,"employees worked more than 15 hours"; -} -3 employees worked more than 15 hours diff --git a/ase/test/awk/emp-018.awk b/ase/test/awk/emp-018.awk deleted file mode 100644 index dd952bb8..00000000 --- a/ase/test/awk/emp-018.awk +++ /dev/null @@ -1 +0,0 @@ -END { print NR, "employees"; } diff --git a/ase/test/awk/emp-018.out b/ase/test/awk/emp-018.out deleted file mode 100644 index fd8fa49f..00000000 --- a/ase/test/awk/emp-018.out +++ /dev/null @@ -1,4 +0,0 @@ -END { - print NR,"employees"; -} -6 employees diff --git a/ase/test/awk/emp-019.awk b/ase/test/awk/emp-019.awk deleted file mode 100644 index 3b63999b..00000000 --- a/ase/test/awk/emp-019.awk +++ /dev/null @@ -1,5 +0,0 @@ - { pay = pay + $2 * $3; } -END { print NR, "employees"; - print "total pay is", pay; - print "average pay is", pay/NR; -} diff --git a/ase/test/awk/emp-019.out b/ase/test/awk/emp-019.out deleted file mode 100644 index 3126ff30..00000000 --- a/ase/test/awk/emp-019.out +++ /dev/null @@ -1,12 +0,0 @@ -{ - pay = (pay + ($2 * $3)); -} - -END { - print NR,"employees"; - print "total pay is",pay; - print "average pay is",(pay / NR); -} -6 employees -total pay is 337.5 -average pay is 56.25 diff --git a/ase/test/awk/emp-020.awk b/ase/test/awk/emp-020.awk deleted file mode 100644 index e0e1b1aa..00000000 --- a/ase/test/awk/emp-020.awk +++ /dev/null @@ -1,2 +0,0 @@ -$2 > maxrate { maxrate = $2; maxemp = $1; } -END { print "highest hourly rage:", maxrate, "for", maxemp; } diff --git a/ase/test/awk/emp-020.out b/ase/test/awk/emp-020.out deleted file mode 100644 index 5f2a54f3..00000000 --- a/ase/test/awk/emp-020.out +++ /dev/null @@ -1,9 +0,0 @@ -($2 > maxrate) { - maxrate = $2; - maxemp = $1; -} - -END { - print "highest hourly rage:",maxrate,"for",maxemp; -} -highest hourly rage: 5.50 for Mary diff --git a/ase/test/awk/emp-021.awk b/ase/test/awk/emp-021.awk deleted file mode 100644 index 6b112dff..00000000 --- a/ase/test/awk/emp-021.awk +++ /dev/null @@ -1,2 +0,0 @@ - { names = names $1 " "; } -END { print names; } diff --git a/ase/test/awk/emp-021.out b/ase/test/awk/emp-021.out deleted file mode 100644 index 676a8bdc..00000000 --- a/ase/test/awk/emp-021.out +++ /dev/null @@ -1,8 +0,0 @@ -{ - names = ((names $1) " "); -} - -END { - print names; -} -Beth Dan Kathy Mark Mary Susie diff --git a/ase/test/awk/emp-022.awk b/ase/test/awk/emp-022.awk deleted file mode 100644 index 414d0979..00000000 --- a/ase/test/awk/emp-022.awk +++ /dev/null @@ -1,2 +0,0 @@ - { last = $0; } -END { print last; } diff --git a/ase/test/awk/emp-022.out b/ase/test/awk/emp-022.out deleted file mode 100644 index 9e0bc46c..00000000 --- a/ase/test/awk/emp-022.out +++ /dev/null @@ -1,8 +0,0 @@ -{ - last = $0; -} - -END { - print last; -} -Susie 4.25 18 diff --git a/ase/test/awk/emp-023.awk b/ase/test/awk/emp-023.awk deleted file mode 100644 index fe25e4f5..00000000 --- a/ase/test/awk/emp-023.awk +++ /dev/null @@ -1 +0,0 @@ -{ print $1, length($1); } diff --git a/ase/test/awk/emp-023.out b/ase/test/awk/emp-023.out deleted file mode 100644 index 0852ccaa..00000000 --- a/ase/test/awk/emp-023.out +++ /dev/null @@ -1,10 +0,0 @@ -{ - print $1,length ($1); -} - -Beth 4 -Dan 3 -Kathy 5 -Mark 4 -Mary 4 -Susie 5 diff --git a/ase/test/awk/emp-024.awk b/ase/test/awk/emp-024.awk deleted file mode 100644 index fb493296..00000000 --- a/ase/test/awk/emp-024.awk +++ /dev/null @@ -1,4 +0,0 @@ - { nc = nc + length($0) + 1; - nw = nw + NF; - } -END { print NR, "lines,", nw, "words,", nc, "characters"; } diff --git a/ase/test/awk/emp-024.out b/ase/test/awk/emp-024.out deleted file mode 100644 index a1af1cfb..00000000 --- a/ase/test/awk/emp-024.out +++ /dev/null @@ -1,9 +0,0 @@ -{ - nc = ((nc + length ($0)) + 1); - nw = (nw + NF); -} - -END { - print NR,"lines,",nw,"words,",nc,"characters"; -} -6 lines, 18 words, 77 characters diff --git a/ase/test/awk/emp-025.awk b/ase/test/awk/emp-025.awk deleted file mode 100644 index 72922285..00000000 --- a/ase/test/awk/emp-025.awk +++ /dev/null @@ -1,7 +0,0 @@ -$2 > 6 { n = n + 1; pay = pay + $2 * $3; } -END { if (n > 0) - print n, "employees, total pay is", pay, - "average pay is", pay/n; - else - print "no employees are paid more than $6/hour"; - } diff --git a/ase/test/awk/emp-025.out b/ase/test/awk/emp-025.out deleted file mode 100644 index 69b10629..00000000 --- a/ase/test/awk/emp-025.out +++ /dev/null @@ -1,12 +0,0 @@ -($2 > 6) { - n = (n + 1); - pay = (pay + ($2 * $3)); -} - -END { - if ((n > 0)) - print n,"employees, total pay is",pay,"average pay is",(pay / n); - else - print "no employees are paid more than $6/hour"; -} -no employees are paid more than $6/hour diff --git a/ase/test/awk/emp-026.awk b/ase/test/awk/emp-026.awk deleted file mode 100644 index 1053f105..00000000 --- a/ase/test/awk/emp-026.awk +++ /dev/null @@ -1,12 +0,0 @@ -{ - line[NR] = $0; -} - -END { - i = NR; - while (i > 0) - { - print line[i]; - i = i - 1; - } -} diff --git a/ase/test/awk/emp-026.out b/ase/test/awk/emp-026.out deleted file mode 100644 index 2ac7bf5a..00000000 --- a/ase/test/awk/emp-026.out +++ /dev/null @@ -1,18 +0,0 @@ -{ - line[NR] = $0; -} - -END { - i = NR; - while ((i > 0)) - { - print line[i]; - i = (i - 1); - } -} -Susie 4.25 18 -Mary 5.50 22 -Mark 5.00 20 -Kathy 4.00 10 -Dan 3.74 0 -Beth 4.00 0 diff --git a/ase/test/awk/emp-027.awk b/ase/test/awk/emp-027.awk deleted file mode 100644 index 56a40f23..00000000 --- a/ase/test/awk/emp-027.awk +++ /dev/null @@ -1,8 +0,0 @@ -{ - line[NR] = $0; -} - -END { - i = NR; - for (i = NR; i > 0; i = i - 1) print line[i]; -} diff --git a/ase/test/awk/emp-027.out b/ase/test/awk/emp-027.out deleted file mode 100644 index a1601e46..00000000 --- a/ase/test/awk/emp-027.out +++ /dev/null @@ -1,15 +0,0 @@ -{ - line[NR] = $0; -} - -END { - i = NR; - for (i = NR; (i > 0); i = (i - 1)) - print line[i]; -} -Susie 4.25 18 -Mary 5.50 22 -Mark 5.00 20 -Kathy 4.00 10 -Dan 3.74 0 -Beth 4.00 0 diff --git a/ase/test/awk/emp-en.data b/ase/test/awk/emp-en.data deleted file mode 100644 index 029863ff..00000000 --- a/ase/test/awk/emp-en.data +++ /dev/null @@ -1,6 +0,0 @@ -Beth 4.00 0 -Dan 3.74 0 -Kathy 4.00 10 -Mark 5.00 20 -Mary 5.50 22 -Susie 4.25 18 diff --git a/ase/test/awk/emp-ko.data b/ase/test/awk/emp-ko.data deleted file mode 100644 index 54f11456..00000000 --- a/ase/test/awk/emp-ko.data +++ /dev/null @@ -1,6 +0,0 @@ -베쓰 4.00 0 -단 3.74 0 -케이티 4.00 10 -마크 5.00 20 -메리 5.50 22 -수지 4.25 18 diff --git a/ase/test/awk/err-001.awk b/ase/test/awk/err-001.awk deleted file mode 100644 index d7800ed57bd78ddbf56db1858c1b2268f853e21b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 10 RcmdN7E-lVX)#qa10ss)}0(<}f diff --git a/ase/test/awk/err-001.out b/ase/test/awk/err-001.out deleted file mode 100644 index 19507db9..00000000 --- a/ase/test/awk/err-001.out +++ /dev/null @@ -1 +0,0 @@ -PARSE ERROR: CODE [30] LINE [2] invalid character '' diff --git a/ase/test/awk/err-002.awk b/ase/test/awk/err-002.awk deleted file mode 100644 index 0518ca92..00000000 --- a/ase/test/awk/err-002.awk +++ /dev/null @@ -1,3 +0,0 @@ -BEGIN { - ARGC = 39; -} diff --git a/ase/test/awk/err-002.out b/ase/test/awk/err-002.out deleted file mode 100644 index eadc4818..00000000 --- a/ase/test/awk/err-002.out +++ /dev/null @@ -1,4 +0,0 @@ -BEGIN { - ARGC = 39; -} - diff --git a/ase/test/awk/err-003.awk b/ase/test/awk/err-003.awk deleted file mode 100644 index b86a5e5b..00000000 --- a/ase/test/awk/err-003.awk +++ /dev/null @@ -1,6 +0,0 @@ -global abc; - -BEGIN { - abc[20] = "abc"; - abc = 10; -} diff --git a/ase/test/awk/err-003.out b/ase/test/awk/err-003.out deleted file mode 100644 index 44b68fe2..00000000 --- a/ase/test/awk/err-003.out +++ /dev/null @@ -1,8 +0,0 @@ -global abc; - -BEGIN { - abc[20] = "abc"; - abc = 10; -} - -RUN ERROR: CODE [94] LINE [5] map 'abc' not assignable with a scalar diff --git a/ase/test/awk/err-004.awk b/ase/test/awk/err-004.awk deleted file mode 100644 index 78a27344..00000000 --- a/ase/test/awk/err-004.awk +++ /dev/null @@ -1,3 +0,0 @@ -BEGIN { - delete ARGC; -} diff --git a/ase/test/awk/err-004.out b/ase/test/awk/err-004.out deleted file mode 100644 index 310c82bf..00000000 --- a/ase/test/awk/err-004.out +++ /dev/null @@ -1,5 +0,0 @@ -BEGIN { - delete ARGC; -} - -RUN ERROR: CODE [86] LINE [2] variable 'ARGC' not deletable diff --git a/ase/test/awk/err-005.awk b/ase/test/awk/err-005.awk deleted file mode 100644 index b6a2ccb9..00000000 --- a/ase/test/awk/err-005.awk +++ /dev/null @@ -1,4 +0,0 @@ -BEGIN { - iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiix = 20; - delete iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiix ; -} diff --git a/ase/test/awk/err-005.out b/ase/test/awk/err-005.out deleted file mode 100644 index 52eec318..00000000 --- a/ase/test/awk/err-005.out +++ /dev/null @@ -1,6 +0,0 @@ -BEGIN { - iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiix = 20; - delete iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiix; -} - -RUN ERROR: CODE [86] LINE [3] variable 'iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii...' not deletable diff --git a/ase/test/awk/err-006.awk b/ase/test/awk/err-006.awk deleted file mode 100644 index e184c15c..00000000 --- a/ase/test/awk/err-006.awk +++ /dev/null @@ -1,3 +0,0 @@ -BEGIN { - helpxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxhelphelp (); -} diff --git a/ase/test/awk/err-006.out b/ase/test/awk/err-006.out deleted file mode 100644 index 1bbe4bd9..00000000 --- a/ase/test/awk/err-006.out +++ /dev/null @@ -1,5 +0,0 @@ -BEGIN { - helpxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxhelphelp (); -} - -RUN ERROR: CODE [84] LINE [2] function 'helpxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxhel...' not found diff --git a/ase/test/awk/err-007.awk b/ase/test/awk/err-007.awk deleted file mode 100644 index 875970ee..00000000 --- a/ase/test/awk/err-007.awk +++ /dev/null @@ -1,4 +0,0 @@ - -function substr () -{ -} diff --git a/ase/test/awk/err-007.out b/ase/test/awk/err-007.out deleted file mode 100644 index 832e41f8..00000000 --- a/ase/test/awk/err-007.out +++ /dev/null @@ -1 +0,0 @@ -PARSE ERROR: CODE [55] LINE [2] built-in function 'substr' redefined diff --git a/ase/test/awk/err-008.awk b/ase/test/awk/err-008.awk deleted file mode 100644 index 36d700f5..00000000 --- a/ase/test/awk/err-008.awk +++ /dev/null @@ -1,6 +0,0 @@ - -BEGIN { - local substr; - substr = 20; -} - diff --git a/ase/test/awk/err-008.out b/ase/test/awk/err-008.out deleted file mode 100644 index 0730f29c..00000000 --- a/ase/test/awk/err-008.out +++ /dev/null @@ -1 +0,0 @@ -PARSE ERROR: CODE [55] LINE [3] built-in function 'substr' redefined diff --git a/ase/test/awk/err-009.awk b/ase/test/awk/err-009.awk deleted file mode 100644 index b90f55fb..00000000 --- a/ase/test/awk/err-009.awk +++ /dev/null @@ -1,19 +0,0 @@ - -func abc () -{ - - local x; - print x = 20; - - { - local abc; - - abc = 30; - print abc; - abc (); - } -} - -BEGIN { - abc (); -} diff --git a/ase/test/awk/err-009.out b/ase/test/awk/err-009.out deleted file mode 100644 index 78591512..00000000 --- a/ase/test/awk/err-009.out +++ /dev/null @@ -1 +0,0 @@ -PARSE ERROR: CODE [56] LINE [9] function 'abc' redefined diff --git a/ase/test/awk/err-010.awk b/ase/test/awk/err-010.awk deleted file mode 100644 index e59a23f3..00000000 --- a/ase/test/awk/err-010.awk +++ /dev/null @@ -1,15 +0,0 @@ - -global abc; - -func abc () -{ - local abc; - - abc = 20; - print abc; - abc (); -} - -BEGIN { - abc (); -} diff --git a/ase/test/awk/err-010.out b/ase/test/awk/err-010.out deleted file mode 100644 index 3d50b139..00000000 --- a/ase/test/awk/err-010.out +++ /dev/null @@ -1 +0,0 @@ -PARSE ERROR: CODE [57] LINE [4] global variable 'abc' redefined diff --git a/ase/test/awk/err-011.awk b/ase/test/awk/err-011.awk deleted file mode 100644 index d8dd77ea..00000000 --- a/ase/test/awk/err-011.awk +++ /dev/null @@ -1,13 +0,0 @@ - -func abc (x) -{ - local x; - - x = 20; - print x; - abc (); -} - -BEGIN { - abc (); -} diff --git a/ase/test/awk/err-011.out b/ase/test/awk/err-011.out deleted file mode 100644 index 1fe5f6be..00000000 --- a/ase/test/awk/err-011.out +++ /dev/null @@ -1 +0,0 @@ -PARSE ERROR: CODE [58] LINE [4] parameter 'x' redefined diff --git a/ase/test/awk/err-012.awk b/ase/test/awk/err-012.awk deleted file mode 100644 index 3382d7ed..00000000 --- a/ase/test/awk/err-012.awk +++ /dev/null @@ -1,14 +0,0 @@ - -func abc () -{ - local j ; - - j = 20; - print j; - abc (); -} - -global abc; -BEGIN { - abc (); -} diff --git a/ase/test/awk/err-012.out b/ase/test/awk/err-012.out deleted file mode 100644 index 8cb73ecf..00000000 --- a/ase/test/awk/err-012.out +++ /dev/null @@ -1 +0,0 @@ -PARSE ERROR: CODE [56] LINE [11] function 'abc' redefined diff --git a/ase/test/awk/err-013.awk b/ase/test/awk/err-013.awk deleted file mode 100644 index 2acc1f7d..00000000 --- a/ase/test/awk/err-013.awk +++ /dev/null @@ -1,3 +0,0 @@ -func abc (abc) -{ -} diff --git a/ase/test/awk/err-013.out b/ase/test/awk/err-013.out deleted file mode 100644 index bd715dfc..00000000 --- a/ase/test/awk/err-013.out +++ /dev/null @@ -1 +0,0 @@ -PARSE ERROR: CODE [56] LINE [1] function 'abc' redefined diff --git a/ase/test/awk/err-014.awk b/ase/test/awk/err-014.awk deleted file mode 100644 index 4a273de7..00000000 --- a/ase/test/awk/err-014.awk +++ /dev/null @@ -1,7 +0,0 @@ -BEGIN { - local a; - - a = 21; - print a > 20? 1 2; -} - diff --git a/ase/test/awk/err-014.out b/ase/test/awk/err-014.out deleted file mode 100644 index f87deed2..00000000 --- a/ase/test/awk/err-014.out +++ /dev/null @@ -1 +0,0 @@ -PARSE ERROR: CODE [42] LINE [5] a colon expected in place of ';' diff --git a/ase/test/awk/err-015.awk b/ase/test/awk/err-015.awk deleted file mode 100644 index 638cba0c..00000000 --- a/ase/test/awk/err-015.awk +++ /dev/null @@ -1,3 +0,0 @@ -BEGIN { - substr = 20; -} diff --git a/ase/test/awk/err-015.out b/ase/test/awk/err-015.out deleted file mode 100644 index ea5ebd12..00000000 --- a/ase/test/awk/err-015.out +++ /dev/null @@ -1 +0,0 @@ -PARSE ERROR: CODE [37] LINE [2] a left parenthesis expected in place of '=' diff --git a/ase/test/awk/err-016.awk b/ase/test/awk/err-016.awk deleted file mode 100644 index 28a3e1a8..00000000 --- a/ase/test/awk/err-016.awk +++ /dev/null @@ -1,5 +0,0 @@ - -BEGIN -{ - print "hello world"; -} diff --git a/ase/test/awk/err-016.out b/ase/test/awk/err-016.out deleted file mode 100644 index 83889449..00000000 --- a/ase/test/awk/err-016.out +++ /dev/null @@ -1 +0,0 @@ -PARSE ERROR: CODE [51] LINE [2] BEGIN not followed by a left bracket on the same line diff --git a/ase/test/awk/err-017.awk b/ase/test/awk/err-017.awk deleted file mode 100644 index 883b72c7..00000000 --- a/ase/test/awk/err-017.awk +++ /dev/null @@ -1 +0,0 @@ -func abc (+) {} diff --git a/ase/test/awk/err-017.out b/ase/test/awk/err-017.out deleted file mode 100644 index 8c10f2ef..00000000 --- a/ase/test/awk/err-017.out +++ /dev/null @@ -1 +0,0 @@ -PARSE ERROR: CODE [62] LINE [1] '+' not a valid parameter name diff --git a/ase/test/awk/err-018.awk b/ase/test/awk/err-018.awk deleted file mode 100644 index 815e9826..00000000 --- a/ase/test/awk/err-018.awk +++ /dev/null @@ -1,2 +0,0 @@ -global + ; - diff --git a/ase/test/awk/err-018.out b/ase/test/awk/err-018.out deleted file mode 100644 index 22349b0c..00000000 --- a/ase/test/awk/err-018.out +++ /dev/null @@ -1 +0,0 @@ -PARSE ERROR: CODE [63] LINE [1] '+' not a valid variable name diff --git a/ase/test/awk/err-019.awk b/ase/test/awk/err-019.awk deleted file mode 100644 index 2e2ab6ae..00000000 --- a/ase/test/awk/err-019.awk +++ /dev/null @@ -1,5 +0,0 @@ -BEGIN { - - local +; - -} diff --git a/ase/test/awk/err-019.out b/ase/test/awk/err-019.out deleted file mode 100644 index 2d89bac0..00000000 --- a/ase/test/awk/err-019.out +++ /dev/null @@ -1 +0,0 @@ -PARSE ERROR: CODE [63] LINE [3] '+' not a valid variable name diff --git a/ase/test/awk/err-020.awk b/ase/test/awk/err-020.awk deleted file mode 100644 index a0ababa4..00000000 --- a/ase/test/awk/err-020.awk +++ /dev/null @@ -1,4 +0,0 @@ -BEGIN { - print abc > "123\0abc"; -} - diff --git a/ase/test/awk/err-020.out b/ase/test/awk/err-020.out deleted file mode 100644 index 813ae97a..00000000 --- a/ase/test/awk/err-020.out +++ /dev/null @@ -1,5 +0,0 @@ -BEGIN { - print abc > "123\0abc"; -} - -RUN ERROR: CODE [109] LINE [2] i/o name containing a null character diff --git a/ase/test/awk/err-021.awk b/ase/test/awk/err-021.awk deleted file mode 100644 index 5f3e5b13..00000000 --- a/ase/test/awk/err-021.awk +++ /dev/null @@ -1,4 +0,0 @@ -BEGIN { - xx = 20; - split ("a b c", xx); -} diff --git a/ase/test/awk/err-021.out b/ase/test/awk/err-021.out deleted file mode 100644 index cf176329..00000000 --- a/ase/test/awk/err-021.out +++ /dev/null @@ -1,6 +0,0 @@ -BEGIN { - xx = 20; - split ("a b c",xx); -} - -RUN ERROR: CODE [95] LINE [3] cannot change a scalar value to a map diff --git a/ase/test/awk/err-en.data b/ase/test/awk/err-en.data deleted file mode 100644 index 43684d80..00000000 --- a/ase/test/awk/err-en.data +++ /dev/null @@ -1,2 +0,0 @@ -data 1 -data 2 diff --git a/ase/test/awk/histsort.awk b/ase/test/awk/histsort.awk deleted file mode 100644 index 2ab2ba7f..00000000 --- a/ase/test/awk/histsort.awk +++ /dev/null @@ -1,8 +0,0 @@ -{ - if (data[$0]++ == 0) lines[++count] = $0; -} - -END { - for (i = 1; i <= count; i++) print lines[i]; -} - diff --git a/ase/test/awk/ite-001.awk b/ase/test/awk/ite-001.awk deleted file mode 100644 index 02f1e014..00000000 --- a/ase/test/awk/ite-001.awk +++ /dev/null @@ -1,7 +0,0 @@ -{ - i = 1; - while (i <= $3) { - printf ("\t%.2f\n", $1*(1+$2)**i); - i = i + 1; - } -} diff --git a/ase/test/awk/ite-002.awk b/ase/test/awk/ite-002.awk deleted file mode 100644 index 17147dff..00000000 --- a/ase/test/awk/ite-002.awk +++ /dev/null @@ -1,4 +0,0 @@ -{ - for (i = 1; i <= $3; i=i+1) - printf ("\t%.2f\n", $1*(1+$2)**i); -} diff --git a/ase/test/awk/makefile.in b/ase/test/awk/makefile.in deleted file mode 100644 index ac1e947e..00000000 --- a/ase/test/awk/makefile.in +++ /dev/null @@ -1,26 +0,0 @@ -# -# $Id: makefile.in,v 1.1.1.1 2007/03/28 14:05:29 bacon Exp $ -# - -CC = @CC@ -CFLAGS = @CFLAGS@ -I@abs_top_builddir@/.. -LDFLAGS = @LDFLAGS@ -L@abs_top_builddir@/@BUILDMODE@/lib -LIBS = @LIBS@ -laseawk -lasecmn -laseutl -lm -MODE = @BUILDMODE@ - -OUT_DIR = ../../$(MODE)/bin - -all: $(OUT_DIR)/aseawk $(OUT_DIR)/miniawk - -$(OUT_DIR)/aseawk: $(OUT_DIR) - $(CC) $(CFLAGS) -o $@ awk.c $(LDFLAGS) $(LIBS) - -$(OUT_DIR)/miniawk: $(OUT_DIR) - $(CC) $(CFLAGS) -o $@ mini.c $(LDFLAGS) $(LIBS) - -$(OUT_DIR): - mkdir -p $(OUT_DIR) - -clean: - rm -rf $(OUT_DIR)/aseawk $(OUT_DIR)/miniawk - diff --git a/ase/test/awk/makefile.lnx.gcc b/ase/test/awk/makefile.lnx.gcc deleted file mode 100644 index fede76bc..00000000 --- a/ase/test/awk/makefile.lnx.gcc +++ /dev/null @@ -1,25 +0,0 @@ -SRCS = awk.c -OBJS = $(SRCS:.c=.o) - -CC = gcc -CFLAGS = -O2 -Wall -D_REENTRANT -D_THREAD_SAFE -fPIC -I../../.. -LDFLAGS = -L../../cmn -L../../awk -L../../utl -LIBS = -lasecmn -laseawk -laseutl -lm - -all: aseawk - -aseawk: $(OBJS) - $(CC) -o $@ awk.o $(LDFLAGS) $(LIBS) - -java: - javac -classpath ../../.. Awk.java AwkApplet.java - -jrun: - java -Xms1m -Xmx2m -classpath ../../.. ase.test.awk.Awk - -clean: - rm -rf *.o *.class aseawk - -.SUFFIXES: .c .o -.c.o: - $(CC) -c $(CFLAGS) $< diff --git a/ase/test/awk/makefile.mac.gcc b/ase/test/awk/makefile.mac.gcc deleted file mode 100644 index d0c3478b..00000000 --- a/ase/test/awk/makefile.mac.gcc +++ /dev/null @@ -1,26 +0,0 @@ -SRCS = awk.c -OBJS = $(SRCS:.c=.o) - -CC = gcc -CFLAGS = -O2 -Wall -D_REENTRANT -D_THREAD_SAFE -I../../.. -LDFLAGS = -L../../cmn -L../../awk -L../../utl -LIBS = -lasecmn -laseawk -laseutl -lm - - -all: aseawk - -aseawk: $(OBJS) - $(CC) -o $@ awk.o $(LDFLAGS) $(LIBS) - -java: - javac -classpath ../../.. Awk.java AwkApplet.java - -jrun: - java -classpath ../../.. ase.test.awk.Awk - -clean: - rm -rf *.o *.class aseawk - -.SUFFIXES: .c .o -.c.o: - $(CC) -c $(CFLAGS) $< diff --git a/ase/test/awk/makefile.msw.bcc b/ase/test/awk/makefile.msw.bcc deleted file mode 100644 index 9dec9ca8..00000000 --- a/ase/test/awk/makefile.msw.bcc +++ /dev/null @@ -1,34 +0,0 @@ - -# ilink32.exe link.exe -# -aa /subsystem:windows -# -ap /subsystem:console -# -ad /subsystem:native -# -# -Tpe -# -Tpd /dll - -CC = bcc32 -LD = ilink32 -CFLAGS = -O2 -WM -WU -RT- -w -I..\..\.. -LDFLAGS = -ap -Tpe -Gn -c -L..\..\awk -L..\..\cmn -L..\..\utl -LIBS = import32.lib cw32mt.lib aseawk.lib asecmn.lib aseutl.lib -STARTUP = c0x32w.obj - -all: aseawk - -aseawk: awk.obj - $(LD) $(LDFLAGS) $(STARTUP) awk.obj,$@.exe,,$(LIBS),, - -java: - javac -classpath ../../.. Awk.java AwkApplet.java - -jrun: - java -Xms1m -Xmx2m -classpath ../../.. ase.test.awk.Awk - -clean: - del $(OBJS) *.obj *.class aseawk.exe - -.SUFFIXES: .c .obj -.c.obj: - $(CC) $(CFLAGS) -c $< - diff --git a/ase/test/awk/makefile.msw.cl b/ase/test/awk/makefile.msw.cl deleted file mode 100644 index c6b218cb..00000000 --- a/ase/test/awk/makefile.msw.cl +++ /dev/null @@ -1,43 +0,0 @@ -CC = cl -CFLAGS = /nologo /MT /W3 /GR- -I..\..\.. -D_WIN32_WINNT=0x0400 -LDFLAGS = /libpath:..\..\cmn /libpath:..\..\awk /libpath:..\..\utl -LIBS = asecmn.lib aseawk.lib aseutl.lib kernel32.lib user32.lib - -!if !defined(CPU) || "$(CPU)" == "" -CPU = $(PROCESSOR_ARCHITECTURE) -!endif - -!if "$(CPU)" == "" -CPU = i386 -!endif - -!if "$(CPU)" == "IA64" || "$(CPU)" == "AMD64" -LIBS = $(LIBS) bufferoverflowu.lib -!endif - -all: aseawk - -aseawk: awk.obj - link /nologo /out:$@.exe $(LDFLAGS) $(LIBS) awk.obj - -mini: mini.obj - link /nologo /out:$@.exe $(LDFLAGS) $(LIBS) mini.obj - -java: - javac -classpath ../../.. Awk.java - javac -classpath ../../.. AwkApplet.java - -jrun: - java -classpath ../../.. ase.test.awk.Awk - -cert: - keytool -genkey -keystore ase.store -alias asecert - keytool -export -keystore ase.store -alias asecert -file ase.cer - -clean: - del $(OBJS) *.obj aseawk.exe mini.exe - -.SUFFIXES: .c .obj -.c.obj: - $(CC) /c $(CFLAGS) $< - diff --git a/ase/test/awk/match.awk b/ase/test/awk/match.awk deleted file mode 100644 index 243b082a..00000000 --- a/ase/test/awk/match.awk +++ /dev/null @@ -1,19 +0,0 @@ -BEGIN { - print match ("hhhheeeo", /e+/); - print RSTART, RLENGTH; - print match ("heeeo", /e/); - print RSTART, RLENGTH; - print match ("heeeo", /t/); - print RSTART, RLENGTH; - - print "--------------------------"; - print match ("hhhheeeo", "e+"); - print RSTART, RLENGTH; - print match ("heeeo", "e"); - print RSTART, RLENGTH; - print match ("heeeo", "t"); - print RSTART, RLENGTH; - print "--------------------------"; -} - - diff --git a/ase/test/awk/mini.c b/ase/test/awk/mini.c deleted file mode 100644 index b4cee9b3..00000000 --- a/ase/test/awk/mini.c +++ /dev/null @@ -1,427 +0,0 @@ -/* - * $Id: mini.c,v 1.1.1.1 2007/03/28 14:05:29 bacon Exp $ - */ - -#include - -#include -#include - -#include -#include -#include - -#include -#include -#include - -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 -#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_STRBASEONE | - 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; -} diff --git a/ase/test/awk/mkjar.bat b/ase/test/awk/mkjar.bat deleted file mode 100644 index 19ab553b..00000000 --- a/ase/test/awk/mkjar.bat +++ /dev/null @@ -1,8 +0,0 @@ -cd ..\..\.. -move ase\test\awk\AwkApplet*.class . -jar cvf AwkApplet.jar *.class ase\test\awk\*.class ase\awk\*.class -move AwkApplet.jar ase\test\awk -cd ase\test\awk - -copy ..\..\awk\aseawk_jni.dll . -jarsigner -keystore ase.store AwkApplet.jar asecert diff --git a/ase/test/awk/negnum.data b/ase/test/awk/negnum.data deleted file mode 100644 index 7b65e93c..00000000 --- a/ase/test/awk/negnum.data +++ /dev/null @@ -1,6 +0,0 @@ -Beth -4.00 0 -Dan 3.74 0 --Kathy 4.00 10 -Mark 5.00 -20 -Mary -5.50 22 -Susie -4.25 -18 diff --git a/ase/test/awk/num.awk b/ase/test/awk/num.awk deleted file mode 100644 index 51ee2d4f..00000000 --- a/ase/test/awk/num.awk +++ /dev/null @@ -1,27 +0,0 @@ -BEGIN { - print 1 + 0; - print 0B11111111 + 0; - print 10 + 0; - print 0x10 + 0; - print 0b00000010 + 0; - print 0b + 0; - print 0x + 0; - - print "-----------------------"; - print +1 + 0; - print +0B11111111 + 0; - print +10 + 0; - print +0x10 + 0; - print +0b00000010 + 0; - print +0b + 0; - print +0x + 0; - - print "-----------------------"; - print -1 + 0; - print -0B11111111 + 0; - print -10 + 0; - print -0x10 + 0; - print -0b00000010 + 0; - print -0b + 0; - print -0x + 0; -} diff --git a/ase/test/awk/pow.awk b/ase/test/awk/pow.awk deleted file mode 100644 index 9778fe0b..00000000 --- a/ase/test/awk/pow.awk +++ /dev/null @@ -1,43 +0,0 @@ -BEGIN { - print 3**2; - print -3**2; - print (-3)**2; - print 3**2**3**2; - print -3**2**-3**2; - print (-3)**2**(-3)**2; - print 3**-2**3**-2;; - print -2 ** 3; - print -2 ** -3; - - print 0 ** 0; - print 0 ** 1; - #print 0 ** -1; - print -1 ** 4; - print -1 ** 5; - - print "-------------------"; - - print 3.0 ** 2; - print 3.0 ** -2; - print -2.0 ** 3; - print -2.0 ** -3; - - print 0.0 ** 0; - print 0.0 ** 1; - #print 0.0 ** -1; - print -1.0 ** 4; - print -1.0 ** 5; - - print -2.12 ** 3; - print 2.12 ** -3; - print -12.12 ** 3; - print 12.12 ** -3; - - print 0.000000001 ** 30; - print 0.000000002 ** 30; - print 0.000000000000000000000000000000000000000000000000000000001 ** 30; - print 0.000000000000000000000000000000000000000000000000000000002 ** 30; - - print "-------------------"; -} - diff --git a/ase/test/awk/regress.sh b/ase/test/awk/regress.sh deleted file mode 100755 index c16b3183..00000000 --- a/ase/test/awk/regress.sh +++ /dev/null @@ -1,140 +0,0 @@ -#!/bin/sh - -run_script_for_init() -{ - script="$1" - data="$2" - output=`echo $script | sed 's/\.awk$/.out/g'` - - ./aseawk -d -f "$script" "$data" > "$output" -} - -run_init() -{ - for script in emp-???.awk - do - run_script_for_init "$script" "emp-en.data" - done - - for script in cou-???.awk - do - run_script_for_init "$script" "cou-en.data" - done - - for script in err-???.awk - do - run_script_for_init "$script" "err-en.data" - done -} - -run_script_for_test() -{ - script="$1" - data="$2" - output=`echo $script | sed 's/\.awk$/.out/g'` - - echo ">> RUNNING $script" - ./aseawk -d -f "$script" "$data" > "$output.$pid" - - #diff -y "$output" "$output.$pid" - diff "$output" "$output.$pid" - if [ $? -ne 0 ] - then - rm -f "$output.$pid" - return 1 - fi - - rm -f "$output.$pid" - return 0 -} - -run_test() -{ - pid=$$ - - for script in emp-???.awk - do - run_script_for_test "$script" "emp-en.data" - if [ $? -ne 0 ] - then - echo "###################################" - echo "PROBLEM(S) DETECTED IN $script.". - echo "###################################" - - echo "Do you want to abort? [y/n]" - read ans - if [ "$ans" = "y" -o "$ans" = "Y" ] - then - return 1 - fi - fi - done - - for script in cou-???.awk - do - run_script_for_test "$script" "cou-en.data" - if [ $? -ne 0 ] - then - echo "###################################" - echo "PROBLEM(S) DETECTED IN $script.". - echo "###################################" - - echo "Do you want to abort? [y/n]" - read ans - if [ "$ans" = "y" -o "$ans" = "Y" ] - then - return 1 - fi - fi - done - - for script in err-???.awk - do - run_script_for_test "$script" "err-en.data" - if [ $? -ne 0 ] - then - echo "###################################" - echo "PROBLEM(S) DETECTED IN $script.". - echo "###################################" - - echo "Do you want to abort? [y/n]" - read ans - if [ "$ans" = "y" -o "$ans" = "Y" ] - then - return 1 - fi - fi - done - - return 0 -} - -#--------# -# main # -#--------# - -if [ ! -x ./aseawk ] -then - echo "Error: cannot locate a relevant awk interpreter" - exit 1; -fi - -if [ $# -ne 1 ] -then - echo "Usage: $0 init" - echo " $0 test" - exit 1 -fi - -if [ "$1" = "init" ] -then - run_init -elif [ "$1" = "test" ] -then - run_test -else - echo "Usage: $0 init" - echo " $0 test" - exit 1 -fi - diff --git a/ase/test/awk/t1.awk b/ase/test/awk/t1.awk deleted file mode 100644 index 9cffc875..00000000 --- a/ase/test/awk/t1.awk +++ /dev/null @@ -1,21 +0,0 @@ -function sum(i, k, y) -{ - y = 0; - for (k = i; k; k = k - 1) - { - y = y + k; - } - - return y; - y = 10; - return y; -} - -BEGIN { - /*s = sum(10000000);*/ - s = sum (100); - print s; - return s; -} - - diff --git a/ase/test/awk/t10.awk b/ase/test/awk/t10.awk deleted file mode 100644 index f562146f..00000000 --- a/ase/test/awk/t10.awk +++ /dev/null @@ -1,22 +0,0 @@ -BEGIN { - print "more"; - //print | "more"; - //print > "echo"; - //print >> "echo"; - - getline x < "abc"; /* open("abc", O_RDONLY|O_LARGEFILE) = 3 */ - //print 10 >> "abc"; /* open("abc", O_WRONLY|O_APPEND|O_CREAT|O_LARGEFILE, 0666) = 4 */ - getline x < "abc"; - //print x; - a = close ("abc"); /* close(4) */ - print "a=" a; - //print "hey" - b = close ("abc"); /* close(3) */ - print "b=" b; - - getline x < "Makefile.cl"; - getline y < "awk.c"; - c = close ("Makefile.cl"); - d = close ("awk.c"); - -} diff --git a/ase/test/awk/t11.awk b/ase/test/awk/t11.awk deleted file mode 100644 index b78f07e4..00000000 --- a/ase/test/awk/t11.awk +++ /dev/null @@ -1,17 +0,0 @@ -BEGIN { - print "this is only a test"; - print; - print 1, 2, (3 >> 10); - print 1, 2, 3 >> 10; - print 3, 4, 5 >> 10; - close (10); - print "-------------" >> 10; - - delete abc; - delete abc["aaaa"] ; - - /* - print 1 > 2 + 3; - print 1 < 2 + 3; - */ -} diff --git a/ase/test/awk/t12.awk b/ase/test/awk/t12.awk deleted file mode 100644 index 53c5a63e..00000000 --- a/ase/test/awk/t12.awk +++ /dev/null @@ -1,38 +0,0 @@ -BEGIN { - /* - print "line 1" >> "1"; - print "line 2" > "1"; - print "line 3" >> "1"; - - print "line 4" >> "2"; - print "line 4" >> "3"; - print "line 4" >> "4"; - - while ((getline x < "abc") > 0) print x; - close ("abc"); - - - print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"; - - getline x < "abc"; - if (x == "a") print "xxxxxxxxxxxxxxxx"; else print x; - */ - - /* - print getline x; - print "[", x, "]"; - print "--------------"; - */ - - if (getline x < "abc" == -1) - { - print "ERRNO = ", ERRNO; - } - - print x > "def"; - #print "fflush(def) = ", fflush ("def"); - print "fflush() = ", fflush (""); - -# print (1 (2 getline j) j); -# print "abc" 1 + 2 3 + 49 2 / 3; -} diff --git a/ase/test/awk/t13.awk b/ase/test/awk/t13.awk deleted file mode 100644 index 45cb240d..00000000 --- a/ase/test/awk/t13.awk +++ /dev/null @@ -1,22 +0,0 @@ -global a; -BEGIN { - local b; - - #a = 20; - #a[1] = 20; - #a[2] = 30; - - /* - b["xxx"] = 20; - b["yyy"] = 30; - b[1] = 30; - b["2"] = 30; - - delete a; - delete b["1"]; - */ - c[1] = 20; - c[1] = "aaa"; - c = 30; -} - diff --git a/ase/test/awk/t14.awk b/ase/test/awk/t14.awk deleted file mode 100644 index b0f3aad9..00000000 --- a/ase/test/awk/t14.awk +++ /dev/null @@ -1,28 +0,0 @@ -global x, y; - -BEGIN { FS="A"; } - -{ - print "NF = " NF; - for (i = 0; i < 10; i++) - { - print $i; - if (i == 3) a = $i; - } - - $1 = 100; - - /*$1 = $2; - $3 = $2; - $2 = $2;*/ - - /*OFS["1234"]=":";*/ - - $20 = 10; - print $0; - print "--------------------"; - print "NF ===>>> " NF; - print "===================="; -} - -END { fflush (); system ("dir /w/p"); print sin(270); } diff --git a/ase/test/awk/t15.awk b/ase/test/awk/t15.awk deleted file mode 100644 index 6765587d..00000000 --- a/ase/test/awk/t15.awk +++ /dev/null @@ -1,16 +0,0 @@ -BEGIN { - local a, b; - - a = 12; - b = "<" a ">"; - - print b; - - print ("\x5C"); - print ("\x5C6_ABCDEGH"); - print ("\xZZ5C6_ABCDEGH"); - print ("\xZZ5C6_AB\u7658&&"); - print "\uC720\uB2C8\uCF54\uB4DC \uD14C\uC2A4\uD2B8"; - print "\UC720\UB2C8\UCF54\UB4DC \UD14C\UC2A4\UD2B8"; -} - diff --git a/ase/test/awk/t16.awk b/ase/test/awk/t16.awk deleted file mode 100644 index d383b877..00000000 --- a/ase/test/awk/t16.awk +++ /dev/null @@ -1 +0,0 @@ -{ /*$0=" "; */ print NF; print "a" $0 "b"; x = $1; } diff --git a/ase/test/awk/t17.awk b/ase/test/awk/t17.awk deleted file mode 100644 index 92fc9831..00000000 --- a/ase/test/awk/t17.awk +++ /dev/null @@ -1,18 +0,0 @@ -/hello[[:space:]]/ { - print $0; - print "INTERNAL LOOP NF=" NF; - for (i = 0; i < NF; i++) - { - print "[" $(i+1) "]"; - } - #getline a; - #print a; - - if (getline > 0) print $0; - print "GETLINE NF=" NF; - for (i = 0; i < NF; i++) - { - print "[" $(i+1) "]"; - } - print "----------------"; -} diff --git a/ase/test/awk/t18.awk b/ase/test/awk/t18.awk deleted file mode 100644 index 1e012fff..00000000 --- a/ase/test/awk/t18.awk +++ /dev/null @@ -1,21 +0,0 @@ -BEGIN { - print "0. FILENAME=", FILENAME, "FNR=", FNR; -} - -/hello/ { - print "1. FILENAME=", FILENAME, "FNR=", FNR; - print "[" $0 "]"; - #nextfile; - print "----------------"; -} - -/hello/ { - print "2. FILENAME=", FILENAME, "FNR=", FNR; - print "[" $0 "]"; - nextfile; - print "----------------"; -} - -END { - print "== END OF PROGRAM =="; -} diff --git a/ase/test/awk/t19.awk b/ase/test/awk/t19.awk deleted file mode 100644 index 836544c1..00000000 --- a/ase/test/awk/t19.awk +++ /dev/null @@ -1,4 +0,0 @@ -//BEGIN { nlines="-0.345"; } - { nlines++; } -END { print nlines; } - diff --git a/ase/test/awk/t2.awk b/ase/test/awk/t2.awk deleted file mode 100644 index 9a74d34c..00000000 --- a/ase/test/awk/t2.awk +++ /dev/null @@ -1,24 +0,0 @@ -global z, x; - -function sum (i) -{ - local k, y; - - y = 0; - for (k = i; k; k = k - 1) - { - y = y + k; - } - - return y; - y = 10; - return y; -} - -END { - /*x = sum (10000000); - */ - x = sum (100); - s = x; - ss = z; -} diff --git a/ase/test/awk/t20.awk b/ase/test/awk/t20.awk deleted file mode 100644 index 41df5047..00000000 --- a/ase/test/awk/t20.awk +++ /dev/null @@ -1,8 +0,0 @@ -//"abc" != "def" { -/a\/b/ { - print $0 ~ /abc/; - print $0 !~ /abc/; - print $0 ~ "abc[[:space:]]"; - print $0 !~ "abc"; - print /abc/; -} diff --git a/ase/test/awk/t21.awk b/ase/test/awk/t21.awk deleted file mode 100644 index 33fe1fd5..00000000 --- a/ase/test/awk/t21.awk +++ /dev/null @@ -1,8 +0,0 @@ -BEGIN { exit 10; } - -{ - print $0; - #print close (""); -} - -END { print "== END OF PROGRAM =="; } diff --git a/ase/test/awk/t22.awk b/ase/test/awk/t22.awk deleted file mode 100644 index defc73ec..00000000 --- a/ase/test/awk/t22.awk +++ /dev/null @@ -1,15 +0,0 @@ -//BEGIN { exit 10; } - -//{ while (1) {if (x == 20) continue; if (a) break; while (10) break; }} -//END { while (1) {if (x == 20) continue; if (a) break; while (10) break; }} - -{ - //return 20; - - print getline abc < ""; - print "[[" abc "]]"; - print close(""); - //exit 20; -} - -END { print "end"; } diff --git a/ase/test/awk/t23.awk b/ase/test/awk/t23.awk deleted file mode 100644 index d3a3c414..00000000 --- a/ase/test/awk/t23.awk +++ /dev/null @@ -1,19 +0,0 @@ -/* -{ - print "ALL ==> " $0; -} - -/1/,/5/ -{ - - print "/1/,/5/ ==> " $0; -} -*/ - - -BEGIN { c["Europe"] = "XXX"; } - -/Europe/, /Africa/ { print $0; } - -//(a = "20") { } -/*"Europe" in c { print $0; }*/ diff --git a/ase/test/awk/t24.awk b/ase/test/awk/t24.awk deleted file mode 100644 index ece42637..00000000 --- a/ase/test/awk/t24.awk +++ /dev/null @@ -1,6 +0,0 @@ -BEGIN { - - a["abc\0\0xxx"] = "abcdefg"; - print a["abc"]; - print a["abc\0\0xxx"]; -} diff --git a/ase/test/awk/t25.awk b/ase/test/awk/t25.awk deleted file mode 100644 index c14c928d..00000000 --- a/ase/test/awk/t25.awk +++ /dev/null @@ -1,13 +0,0 @@ -/Europe/, /Africa/ - - 1 - 2 - 3 % 23 - -/zab/ { print "XXXX"; } - -{ - print /ABC/ ~ /DEF/; -} - -/zzz/ diff --git a/ase/test/awk/t26.awk b/ase/test/awk/t26.awk deleted file mode 100644 index 442d5770..00000000 --- a/ase/test/awk/t26.awk +++ /dev/null @@ -1,13 +0,0 @@ -function call_next () -{ - next; -} - -BEGIN { - #call_next (); -} - -END { - call_next (); -} - diff --git a/ase/test/awk/t27.awk b/ase/test/awk/t27.awk deleted file mode 100644 index f963d63a..00000000 --- a/ase/test/awk/t27.awk +++ /dev/null @@ -1,6 +0,0 @@ -global a, b, c; - -BEGIN { while (1) while(1) while (1) a = 20; } - -END { while (1) while(1) while (1) ; } - diff --git a/ase/test/awk/t28.awk b/ase/test/awk/t28.awk deleted file mode 100644 index 73599250..00000000 --- a/ase/test/awk/t28.awk +++ /dev/null @@ -1,41 +0,0 @@ -#global xyz; - -END { - #local xyz; - - print index ("abc", "abc"); - print index ("abc", "b"); - print index ("abc", "kabc"); - - print "----------------------------"; - print substr ("abc", "abcdefg", 5); - print substr ("abc", -1, 5); - print substr ("abc", 0, 5); - print substr ("abc", 1, 5); - print substr ("abc", 2.829, 5); - print substr ("abc", "3", 5); - print substr ("abc", 4, 5); - - /* - a[1] = 20; - substr (a, 3, 4); - */ - - print tolower ("AbcDEF"); - print toupper ("AbcDEF"); - - arr[0] = "xxx"; - #print split ("abc def abc", arr); - print split ("abc def kkk", j); - print split ("abc def kkk", $0); # error - - #xyz = 20; - #print xyz; - print split ("abc def kkk", ((xyz))); - #for (i in arr) - - for (i in xyz) - { - print i, " ", xyz[i]; - } -} diff --git a/ase/test/awk/t29.awk b/ase/test/awk/t29.awk deleted file mode 100644 index 0e852b8b..00000000 --- a/ase/test/awk/t29.awk +++ /dev/null @@ -1,3 +0,0 @@ -{ print $0; } -//{ gsub ("abc", "&&&&"); print $0; } - diff --git a/ase/test/awk/t3.awk b/ase/test/awk/t3.awk deleted file mode 100644 index eb13d37d..00000000 --- a/ase/test/awk/t3.awk +++ /dev/null @@ -1,25 +0,0 @@ -#global x, j; - -func func1 (x) -{ - c = x["abc"]; - x["abc"] = 123; -} - -BEGIN { - idx="abc"; - x[idx] = 12345; - i = x[idx]; - x["1"] = 1; - x["2"] = 2; - - func1 (x); - k = x[idx]; - return j; - - /* - x["abc"] = 12345; - i = x["abc"]; - return j; - */ -} diff --git a/ase/test/awk/t30.awk b/ase/test/awk/t30.awk deleted file mode 100644 index 4ee22397..00000000 --- a/ase/test/awk/t30.awk +++ /dev/null @@ -1,3 +0,0 @@ -#{ "dir/w/p" | getline; print $0; print "flush(dir/w/p)=", fflush("dir/w/p"); } -#{ print | "grep Asia"; fflush("grep Asia"); } -{ print | "grep Asia"; print "flush(grep Asia)=", fflush("grep Asia"); } diff --git a/ase/test/awk/t31.awk b/ase/test/awk/t31.awk deleted file mode 100644 index a98a5db1..00000000 --- a/ase/test/awk/t31.awk +++ /dev/null @@ -1,2 +0,0 @@ -BEGIN { RS=""; } -{ print $0; } diff --git a/ase/test/awk/t32.awk b/ase/test/awk/t32.awk deleted file mode 100644 index 928de97f..00000000 --- a/ase/test/awk/t32.awk +++ /dev/null @@ -1,2 +0,0 @@ -BEGIN { /*RS = "Asia";*/ /*RS=746;*/ /*RS="";*/ RS=/USA/; } -{ print NR, " ", $0; } diff --git a/ase/test/awk/t33.awk b/ase/test/awk/t33.awk deleted file mode 100644 index 8d711674..00000000 --- a/ase/test/awk/t33.awk +++ /dev/null @@ -1,15 +0,0 @@ -BEGIN { - ARGV[1] = 20; - print "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; - - delete NF; - print "NF[1]=", NF[1]; - - NF[1] = 20; # this line should not be allowed - print "AWK IMPLEMENTATION ERROR: hey... NF[1] = 20 has succeeded in the BEGIN block. your interpreter must be wrong"; - print "NF[1]=", NF[1]; -} - -{ - NF = 30; -} diff --git a/ase/test/awk/t34.awk b/ase/test/awk/t34.awk deleted file mode 100644 index 7e5e5b5c..00000000 --- a/ase/test/awk/t34.awk +++ /dev/null @@ -1 +0,0 @@ -/* unterminated comment diff --git a/ase/test/awk/t35.awk b/ase/test/awk/t35.awk deleted file mode 100644 index b7958ea9..00000000 --- a/ase/test/awk/t35.awk +++ /dev/null @@ -1,4 +0,0 @@ -BEGIN { - print //; - print / /; -} diff --git a/ase/test/awk/t36.awk b/ase/test/awk/t36.awk deleted file mode 100644 index bacdcd8d..00000000 --- a/ase/test/awk/t36.awk +++ /dev/null @@ -1,47 +0,0 @@ -# test cases -# -# input data [] -# result: -# NF=0 -# -# input data [abcdefg] -# NF=2 -# 0 [] -# 1 [bcdefg] -# -# input data [abdefg abcdefg] -# NF=3 -# 0 [] -# 1 [bdefg ] -# 2 [bcdefg] -# -# input data [ abcdefg hij a a] -# NF=4 -# 0 [ ] -# 1 [bcdefg hij ] -# 2 [ ] -# 3 [] -# -# input data [ abcdefg hij a a ] -# NF=4 -# 0 [ ] -# 1 [bcdefg hij ] -# 2 [ ] -# 3 [ ] -# -# input data [aaaaa] -# NF=6 -# 0 [] -# 1 [] -# 2 [] -# 3 [] -# 4 [] -# 5 [] -# - -BEGIN { FS="a"; } -{ - print "NF=" NF; - for (i = 0; i < NF; i++) print i " [" $(i+1) "]"; -} - diff --git a/ase/test/awk/t37.awk b/ase/test/awk/t37.awk deleted file mode 100644 index fb022a8d..00000000 --- a/ase/test/awk/t37.awk +++ /dev/null @@ -1,6 +0,0 @@ -BEGIN { FS=" "; } -{ - print "NF=" NF; - for (i = 0; i < NF; i++) print i " [" $(i+1) "]"; -} - diff --git a/ase/test/awk/t38.awk b/ase/test/awk/t38.awk deleted file mode 100644 index 78ea5c19..00000000 --- a/ase/test/awk/t38.awk +++ /dev/null @@ -1,9 +0,0 @@ - -BEGIN { - split (" a b c d e ", x, ""); - for (j in x) print j "->" x[j]; - print "-------------------"; - split ("a b c d e", x, "b c"); - for (j in x) print j "->" x[j]; - print "-------------------"; -} diff --git a/ase/test/awk/t39.awk b/ase/test/awk/t39.awk deleted file mode 100644 index 805f828f..00000000 --- a/ase/test/awk/t39.awk +++ /dev/null @@ -1,9 +0,0 @@ -BEGIN { - FS="[:[:space:]]+"; - #FS=":+"; -} -{ - print "NF=" NF; - for (i = 0; i < NF; i++) print i " [" $(i+1) "]"; -} - diff --git a/ase/test/awk/t4.awk b/ase/test/awk/t4.awk deleted file mode 100644 index 707c75f7..00000000 --- a/ase/test/awk/t4.awk +++ /dev/null @@ -1,21 +0,0 @@ -function main (arg1, arg2, arg3) -{ - local i, k, c; - - for (i = 0; i < 10; i++) - { - abc[i*2] = i; - } - - k = 20; - - for (i = 0; i < 100; i++) - { - if (i in abc) j[i] = i; - } - - print arg1; - print arg2; - print arg3; - print "end of program"; -} diff --git a/ase/test/awk/t40.awk b/ase/test/awk/t40.awk deleted file mode 100644 index d0fdfddc..00000000 --- a/ase/test/awk/t40.awk +++ /dev/null @@ -1,8 +0,0 @@ -BEGIN { - FS="[a-c]+"; - IGNORECASE=0.1; -} -{ - print "NF=" NF; - for (i = 0; i < NF; i++) print i " [" $(i+1) "]"; -} diff --git a/ase/test/awk/t41.awk b/ase/test/awk/t41.awk deleted file mode 100644 index 6a82e3d1..00000000 --- a/ase/test/awk/t41.awk +++ /dev/null @@ -1,4 +0,0 @@ -BEGIN { IGNORECASE=1; } -$0 == "abc" { - print "[" $0 "]"; -} diff --git a/ase/test/awk/t42.awk b/ase/test/awk/t42.awk deleted file mode 100644 index 259c7bd2..00000000 --- a/ase/test/awk/t42.awk +++ /dev/null @@ -1,13 +0,0 @@ - -BEGIN { - FS=":"; - OFS="::"; -} - -{ - $2=1.23; - NF=4; - print "NF=" NF; - print "[" $10 "]"; - print "$0=[" $0 "]"; -} diff --git a/ase/test/awk/t43.awk b/ase/test/awk/t43.awk deleted file mode 100644 index 6b168030..00000000 --- a/ase/test/awk/t43.awk +++ /dev/null @@ -1,3 +0,0 @@ -#BEGIN { t = "abc"; gsub ("abc", "[&]", t); print t; } -{ gsub ("abc", "ABC"); print $0; } -{ gsub (/ABC/, "XYZ"); print $0; } diff --git a/ase/test/awk/t44.awk b/ase/test/awk/t44.awk deleted file mode 100644 index f5dcb17c..00000000 --- a/ase/test/awk/t44.awk +++ /dev/null @@ -1,3 +0,0 @@ -#BEGIN { t = "abc"; gsub ("abc", "[&]", t); print t; } -{ c=$0; print sub ("abc", "ABC", c); print c; } -{ sub (/ABC/, "XYZ", c); print c; } diff --git a/ase/test/awk/t45.awk b/ase/test/awk/t45.awk deleted file mode 100644 index 17fd5dbc..00000000 --- a/ase/test/awk/t45.awk +++ /dev/null @@ -1 +0,0 @@ -BEGIN { t[1] = "abc"; gsub ("abc", "[&]", t); print t[1]; } diff --git a/ase/test/awk/t46.awk b/ase/test/awk/t46.awk deleted file mode 100644 index 2f4ee02c..00000000 --- a/ase/test/awk/t46.awk +++ /dev/null @@ -1 +0,0 @@ -BEGIN { t = "whoabcabcabcwho"; gsub ("abc", "[\\&][&][\\&]", t); print t; } diff --git a/ase/test/awk/t47.awk b/ase/test/awk/t47.awk deleted file mode 100644 index 15831ab4..00000000 --- a/ase/test/awk/t47.awk +++ /dev/null @@ -1,19 +0,0 @@ -BEGIN { - - a[1] = 20; - a[2] = 40; - a[3,5,6] = 40; - a["abc"] = 20; - - for (i in a) print "a[" i "]=" a[i]; - #SUBSEP=",,,"; - SUBSEP=4.5; - #SUBSEP=555; - - print "------------------------"; - - a[9,x,3] = 40; - for (i in a) print "a[" i "]=" a[i]; -} - - diff --git a/ase/test/awk/t48.awk b/ase/test/awk/t48.awk deleted file mode 100644 index 7ac01c7a..00000000 --- a/ase/test/awk/t48.awk +++ /dev/null @@ -1,3 +0,0 @@ -BEGIN { - print ("xx" in j); -} diff --git a/ase/test/awk/t49.awk b/ase/test/awk/t49.awk deleted file mode 100644 index 6b907471..00000000 --- a/ase/test/awk/t49.awk +++ /dev/null @@ -1,5 +0,0 @@ -BEGIN { OFS=":"; } -{ - print $5 = "abc"; - print $0; -} diff --git a/ase/test/awk/t5.awk b/ase/test/awk/t5.awk deleted file mode 100644 index 120ca533..00000000 --- a/ase/test/awk/t5.awk +++ /dev/null @@ -1,10 +0,0 @@ -BEGIN { - x[1] = 20; - x[2] = 40; - x[3] = 50; - - for (i in x) - { - j[i] = i; - } -} diff --git a/ase/test/awk/t50.awk b/ase/test/awk/t50.awk deleted file mode 100644 index b6258c84..00000000 --- a/ase/test/awk/t50.awk +++ /dev/null @@ -1,6 +0,0 @@ -BEGIN { - two = 2; three = 3; - print (two three) + 4; -} - - diff --git a/ase/test/awk/t6.awk b/ase/test/awk/t6.awk deleted file mode 100644 index 281567d5..00000000 --- a/ase/test/awk/t6.awk +++ /dev/null @@ -1,21 +0,0 @@ -BEGIN { - j = -20; - - for (i = -10; i < 10; i++) - { - if (i == 5) exit; - #if (i == 5) break; - } - - - while (j < 10) - { - if (j == 5) break; - j++; - } -} - -END { - print "i = ", i; - print "j = ", j; -} diff --git a/ase/test/awk/t7.awk b/ase/test/awk/t7.awk deleted file mode 100644 index 8a431564..00000000 --- a/ase/test/awk/t7.awk +++ /dev/null @@ -1,5 +0,0 @@ -BEGIN { i = 20; j = 0; } -{ i++; /*i = i + 1;*/ } -i % 2 { /*j ++;*/ j = j + 1; } -/*"1","2" || "Yes" {}*/ -/*END { i = i + 1234; j = j + 1234; }*/ diff --git a/ase/test/awk/t8.awk b/ase/test/awk/t8.awk deleted file mode 100644 index fd0cbe73..00000000 --- a/ase/test/awk/t8.awk +++ /dev/null @@ -1,2 +0,0 @@ -BEGIN { 10; 20; 30; i = 40; i++; } - diff --git a/ase/test/awk/t9.awk b/ase/test/awk/t9.awk deleted file mode 100644 index bf5b5414..00000000 --- a/ase/test/awk/t9.awk +++ /dev/null @@ -1,25 +0,0 @@ -BEGIN { - while (("xxx /p" | getline var) > 0) ; - while (("dir /w" | getline var) > 0) ; - while ((getline var < "t9.awk") > 0) ; - - zzz = close ("xxx /p"); - /* - while ("ls -l" | getline var) - { - "ls -l" | getline x; - print var; print x; - } - - while (getline < "/etc/passwd") - { - print $0; - } - - while (getline x < "/etc/shadow") - { - print x; - } - */ -} - diff --git a/ase/test/awk/unr-001.awk b/ase/test/awk/unr-001.awk deleted file mode 100644 index 6eb3de07..00000000 --- a/ase/test/awk/unr-001.awk +++ /dev/null @@ -1,6 +0,0 @@ -# use negnum.data -BEGIN { OFS="\t"; } -{ - for (i = 1; i <= NF; i = i + 1) if ($i < 0) $i = -$i; - print; -} diff --git a/ase/test/awk/wordfreq.awk b/ase/test/awk/wordfreq.awk deleted file mode 100644 index 4e922ab3..00000000 --- a/ase/test/awk/wordfreq.awk +++ /dev/null @@ -1,20 +0,0 @@ -# wordfreq.awk --- print list of word frequencies - -{ - $0 = tolower($0); # remove case distinctions - - # remove punctuation - a=0; - gsub(/[^[:alnum:]_[:blank:]]/, " ", $a); - #gsub(/[^[:alnum:]_[:blank:]]/, " "); - - for (i = 1; i <= NF; i++) freq[$i]++; -} -#/[^kkka-bcx-dd-y]|abc|def/ - -END { - for (word in freq) - print word, freq[word]; -} - - diff --git a/ase/test/awk/x.awk b/ase/test/awk/x.awk deleted file mode 100644 index 3861eba6..00000000 --- a/ase/test/awk/x.awk +++ /dev/null @@ -1,31 +0,0 @@ - -#main () -{ - #print (("%f", 1.0)); # syntax error - print ((10) + 20 * 4); - print ((10) + 20 * 4, (20), (30)); - print (10) + 20 * 4, (20), (30); - print (("%f", 1.0) in x); - - print ("%f", 1.0); - #print ("%f", 1.0), 1; # syntax error - print ("%f", 1.0) in x, 1; - print ((((10) + 20))); - print ((10) + 20, 50); -} - -BEGIN { - #print 1 - #| - #"test"; -# */ - - #print 1 | - # 1; - - print .0; - print 10; - - print fflush ("abc"); -} - diff --git a/ase/test/com/AwkExtioConsole.cls b/ase/test/com/AwkExtioConsole.cls deleted file mode 100644 index e50d409a..00000000 --- a/ase/test/com/AwkExtioConsole.cls +++ /dev/null @@ -1,32 +0,0 @@ -VERSION 1.0 CLASS -BEGIN - MultiUse = -1 'True - Persistable = 0 'NotPersistable - DataBindingBehavior = 0 'vbNone - DataSourceBehavior = 0 'vbNone - MTSTransactionMode = 0 'NotAnMTSObject -END -Attribute VB_Name = "AwkExtioConsole" -Attribute VB_GlobalNameSpace = False -Attribute VB_Creatable = True -Attribute VB_PredeclaredId = False -Attribute VB_Exposed = False -Private m_eof As Boolean - -Private Sub Class_Initialize() - m_eof = False - 'MsgBox "AwkExtio Initializeing" -End Sub - -Private Sub Class_Terminate() - 'MsgBox "AwkExtio Terminating..." -End Sub - -Public Property Let EOF(v As Boolean) - m_eof = v -End Property - -Public Property Get EOF() As Boolean - EOF = m_eof -End Property - diff --git a/ase/test/com/AwkForm.frm b/ase/test/com/AwkForm.frm deleted file mode 100644 index c9fdebca..00000000 --- a/ase/test/com/AwkForm.frm +++ /dev/null @@ -1,468 +0,0 @@ -VERSION 5.00 -Begin VB.Form AwkForm - Caption = "ASE COM AWK" - ClientHeight = 7635 - ClientLeft = 60 - ClientTop = 345 - ClientWidth = 10335 - LinkTopic = "AwkForm" - ScaleHeight = 7635 - ScaleWidth = 10335 - StartUpPosition = 3 'Windows Default - Begin VB.ComboBox EntryPoint - Height = 315 - ItemData = "AwkForm.frx":0000 - Left = 1080 - List = "AwkForm.frx":0007 - TabIndex = 9 - Top = 120 - Width = 3495 - End - Begin VB.TextBox ConsoleIn - BeginProperty Font - Name = "Courier New" - Size = 9 - Charset = 0 - Weight = 400 - Underline = 0 'False - Italic = 0 'False - Strikethrough = 0 'False - EndProperty - Height = 2895 - Left = 120 - MultiLine = -1 'True - ScrollBars = 3 'Both - TabIndex = 2 - Top = 3960 - Width = 5055 - End - Begin VB.TextBox SourceIn - BeginProperty Font - Name = "Courier New" - Size = 9 - Charset = 0 - Weight = 400 - Underline = 0 'False - Italic = 0 'False - Strikethrough = 0 'False - EndProperty - Height = 2775 - Left = 120 - MultiLine = -1 'True - ScrollBars = 3 'Both - TabIndex = 0 - Top = 840 - Width = 5055 - End - Begin VB.TextBox SourceOut - BeginProperty Font - Name = "Courier New" - Size = 9 - Charset = 0 - Weight = 400 - Underline = 0 'False - Italic = 0 'False - Strikethrough = 0 'False - EndProperty - Height = 2775 - Left = 5280 - Locked = -1 'True - MultiLine = -1 'True - ScrollBars = 3 'Both - TabIndex = 1 - Top = 840 - Width = 4935 - End - Begin VB.CommandButton Execute - Caption = "Execute" - Height = 375 - Left = 9000 - TabIndex = 5 - Top = 7080 - Width = 1215 - End - Begin VB.TextBox ConsoleOut - BeginProperty Font - Name = "Courier New" - Size = 9 - Charset = 0 - Weight = 400 - Underline = 0 'False - Italic = 0 'False - Strikethrough = 0 'False - EndProperty - Height = 2895 - Left = 5280 - MultiLine = -1 'True - ScrollBars = 3 'Both - TabIndex = 3 - Top = 3960 - Width = 4935 - End - Begin VB.Label Label5 - Caption = "Entry Point:" - Height = 255 - Left = 120 - TabIndex = 10 - Top = 120 - Width = 1455 - End - Begin VB.Label Label4 - Caption = "Console Out" - Height = 255 - Left = 5280 - TabIndex = 8 - Top = 3720 - Width = 3735 - End - Begin VB.Label Label3 - Caption = "Console In" - Height = 255 - Left = 120 - TabIndex = 7 - Top = 3720 - Width = 3735 - End - Begin VB.Label Label2 - Caption = "Source Out" - Height = 255 - Left = 5280 - TabIndex = 6 - Top = 600 - Width = 3735 - End - Begin VB.Label Label1 - Caption = "Source In" - Height = 255 - Left = 120 - TabIndex = 4 - Top = 600 - Width = 2415 - End -End -Attribute VB_Name = "AwkForm" -Attribute VB_GlobalNameSpace = False -Attribute VB_Creatable = False -Attribute VB_PredeclaredId = True -Attribute VB_Exposed = False -Option Explicit -Dim source_first As Boolean -Public WithEvents Awk As ASELib.Awk -Attribute Awk.VB_VarHelpID = -1 - -Private Sub Execute_Click() - - source_first = True - - ConsoleOut.Text = "" - SourceOut.Text = "" - - Set Awk = New ASELib.Awk - - Awk.ExplicitVariable = True - Awk.ImplicitVariable = True - Awk.UseCrlf = True - Awk.IdivOperator = True - Awk.ShiftOperators = True - - Awk.MaxDepthForBlockParse = 20 - Awk.MaxDepthForBlockRun = 30 - Awk.MaxDepthForExprParse = 20 - Awk.MaxDepthForExprRun = 30 - 'Awk.MaxDepthForRexBuild = 10 - 'Awk.MaxDepthForRexMatch = 10 - - Awk.UseLongLong = False - Awk.Debug = True - - If Awk.AddBuiltinFunction("sin", 1, 1) = -1 Then - MsgBox "Cannot add builtin function - " + Awk.ErrorMessage - Exit Sub - End If - If Awk.AddBuiltinFunction("cos", 1, 1) = -1 Then - MsgBox "Cannot add builtin function - " + Awk.ErrorMessage - Exit Sub - End If - Call Awk.AddBuiltinFunction("tan", 1, 1) - Call Awk.AddBuiltinFunction("sqr", 1, 1) - Call Awk.AddBuiltinFunction("trim", 1, 1) - 'Call Awk.DeleteBuiltinFunction("tan") - - If Awk.Parse() = -1 Then - MsgBox "PARSE ERROR [" + Str(Awk.ErrorLine) + "]" + Awk.ErrorMessage - Else - Awk.EntryPoint = Trim(EntryPoint.Text) - If Awk.Run() = -1 Then - MsgBox "RUN ERROR [" + Str(Awk.ErrorLine) + "]" + Awk.ErrorMessage - End If - End If - - Set Awk = Nothing - -End Sub - -Function Awk_OpenSource(ByVal mode As Long) As Long - Awk_OpenSource = 1 -End Function - -Function Awk_CloseSource(ByVal mode As Long) As Long - Awk_CloseSource = 0 -End Function - -Function Awk_ReadSource(ByVal buf As ASELib.Buffer) As Long - If source_first Then - buf.value = SourceIn.Text - Awk_ReadSource = Len(buf.value) - source_first = False - Else - Awk_ReadSource = 0 - End If -End Function - -Function Awk_WriteSource(ByVal buf As ASELib.Buffer) As Long - Dim value As String - Dim l As Integer - - value = buf.value - l = Len(value) - SourceOut.Text = SourceOut.Text + value - Awk_WriteSource = Len(value) -End Function - -Function Awk_OpenExtio(ByVal extio As ASELib.AwkExtio) As Long - Awk_OpenExtio = -1 - - Select Case extio.Type - Case ASELib.AWK_EXTIO_CONSOLE - If extio.mode = ASELib.AWK_EXTIO_CONSOLE_READ Then - extio.Handle = New AwkExtioConsole - With extio.Handle - .EOF = False - End With - Awk_OpenExtio = 1 - ElseIf extio.mode = ASELib.AWK_EXTIO_CONSOLE_WRITE Then - extio.Handle = New AwkExtioConsole - With extio.Handle - .EOF = False - End With - Awk_OpenExtio = 1 - End If - - Case ASELib.AWK_EXTIO_FILE - If extio.mode = ASELib.AWK_EXTIO_FILE_READ Then - extio.Handle = FreeFile - On Error GoTo ErrorTrap - Open extio.name For Input As #extio.Handle - On Error GoTo 0 - Awk_OpenExtio = 1 - ElseIf extio.mode = ASELib.AWK_EXTIO_FILE_WRITE Then - extio.Handle = FreeFile - On Error GoTo ErrorTrap - Open extio.name For Output As #extio.Handle - On Error GoTo 0 - Awk_OpenExtio = 1 - ElseIf extio.mode = ASELib.AWK_EXTIO_FILE_APPEND Then - extio.Handle = FreeFile - On Error GoTo ErrorTrap - Open extio.name For Append As #extio.Handle - On Error GoTo 0 - Awk_OpenExtio = 1 - End If - - Case ASELib.AWK_EXTIO_PIPE - Awk_OpenExtio = -1 - Case ASELib.AWK_EXTIO_COPROC - Awk_OpenExtio = -1 - End Select - - Exit Function - -ErrorTrap: - Exit Function -End Function - -Function Awk_CloseExtio(ByVal extio As ASELib.AwkExtio) As Long - Awk_CloseExtio = -1 - - Select Case extio.Type - Case ASELib.AWK_EXTIO_CONSOLE - If extio.mode = ASELib.AWK_EXTIO_CONSOLE_READ Or _ - extio.mode = ASELib.AWK_EXTIO_CONSOLE_WRITE Then - extio.Handle = Nothing - Awk_CloseExtio = 0 - End If - Case ASELib.AWK_EXTIO_FILE - If extio.mode = ASELib.AWK_EXTIO_FILE_READ Or _ - extio.mode = ASELib.AWK_EXTIO_FILE_WRITE Or _ - extio.mode = ASELib.AWK_EXTIO_FILE_APPEND Then - Close #extio.Handle - Awk_CloseExtio = 0 - End If - Case ASELib.AWK_EXTIO_PIPE - Awk_CloseExtio = -1 - Case ASELib.AWK_EXTIO_COPROC - Awk_CloseExtio = -1 - End Select - -End Function - -Function Awk_ReadExtio(ByVal extio As ASELib.AwkExtio, ByVal buf As ASELib.Buffer) As Long - Awk_ReadExtio = -1 - - Select Case extio.Type - Case ASELib.AWK_EXTIO_CONSOLE - If extio.mode = ASELib.AWK_EXTIO_CONSOLE_READ Then - Awk_ReadExtio = ReadExtioConsole(extio, buf) - End If - - Case ASELib.AWK_EXTIO_FILE - If extio.mode = ASELib.AWK_EXTIO_FILE_READ Then - Awk_ReadExtio = ReadExtioFile(extio, buf) - End If - - Case ASELib.AWK_EXTIO_PIPE - Awk_ReadExtio = -1 - Case ASELib.AWK_EXTIO_COPROC - Awk_ReadExtio = -1 - End Select - -End Function - -Function Awk_WriteExtio(ByVal extio As ASELib.AwkExtio, ByVal buf As ASELib.Buffer) As Long - Awk_WriteExtio = -1 - - Select Case extio.Type - Case ASELib.AWK_EXTIO_CONSOLE - If extio.mode = ASELib.AWK_EXTIO_CONSOLE_WRITE Then - Awk_WriteExtio = WriteExtioConsole(extio, buf) - End If - Case ASELib.AWK_EXTIO_FILE - If extio.mode = ASELib.AWK_EXTIO_FILE_WRITE Or _ - extio.mode = ASELib.AWK_EXTIO_FILE_APPEND Then - Awk_WriteExtio = WriteExtioFile(extio, buf) - End If - Case ASELib.AWK_EXTIO_PIPE - Awk_WriteExtio = -1 - Case ASELib.AWK_EXTIO_COPROC - Awk_WriteExtio = -1 - End Select -End Function - -Function ReadExtioConsole(ByVal extio As ASELib.AwkExtio, ByVal buf As ASELib.Buffer) As Long - Dim value As String - - If Not extio.Handle.EOF Then - value = ConsoleIn.Text - extio.Handle.EOF = True - buf.value = value - ReadExtioConsole = Len(value) - Else - ReadExtioConsole = 0 - End If -End Function - -Function ReadExtioFile(ByVal extio As ASELib.AwkExtio, ByVal buf As ASELib.Buffer) As Long - Dim value As String - - If EOF(extio.Handle) Then - ReadExtioFile = 0 - Exit Function - End If - - On Error GoTo ErrorTrap - Line Input #extio.Handle, value - On Error GoTo 0 - - value = value + vbCrLf - - buf.value = value - ReadExtioFile = Len(buf.value) - Exit Function - -ErrorTrap: - ReadExtioFile = -1 - Exit Function -End Function - -Function WriteExtioConsole(ByVal extio As ASELib.AwkExtio, ByVal buf As ASELib.Buffer) As Long - Dim value As String - - value = buf.value - ConsoleOut.Text = ConsoleOut.Text + value - WriteExtioConsole = Len(value) -End Function - -Function WriteExtioFile(ByVal extio As ASELib.AwkExtio, ByVal buf As ASELib.Buffer) As Long - Dim value As String - - WriteExtioFile = -1 - - value = buf.value - On Error GoTo ErrorTrap - Print #extio.Handle, value; - On Error GoTo 0 - WriteExtioFile = Len(value) - - Exit Function - -ErrorTrap: - Exit Function -End Function - -Function Awk_HandleBuiltinFunction(ByVal name As String, ByVal args As Variant) As Variant - - If name = "sin" Then - If IsNull(args(0)) Then - Awk_HandleBuiltinFunction = Sin(0) - ElseIf IsNumeric(args(0)) Then - Awk_HandleBuiltinFunction = Sin(args(0)) - Else - Awk_HandleBuiltinFunction = Sin(Val(args(0))) - End If - ElseIf name = "cos" Then - If TypeName(args(0)) = "Long" Or TypeName(args(0)) = "Double" Then - Awk_HandleBuiltinFunction = Cos(args(0)) - ElseIf TypeName(args(0)) = "String" Then - Awk_HandleBuiltinFunction = Cos(Val(args(0))) - ElseIf TypeName(args(0)) = "Null" Then - Awk_HandleBuiltinFunction = Cos(0) - End If - ElseIf name = "tan" Then - If TypeName(args(0)) = "Long" Or TypeName(args(0)) = "Double" Then - Awk_HandleBuiltinFunction = Tan(args(0)) - ElseIf TypeName(args(0)) = "String" Then - Awk_HandleBuiltinFunction = Tan(Val(args(0))) - ElseIf TypeName(args(0)) = "Null" Then - Awk_HandleBuiltinFunction = Tan(0) - End If - ElseIf name = "sqr" Then - If IsNull(args(0)) Then - Awk_HandleBuiltinFunction = Sqr(0) - ElseIf IsNumeric(args(0)) Then - Awk_HandleBuiltinFunction = Sqr(args(0)) - Else - Awk_HandleBuiltinFunction = Sqr(Val(args(0))) - End If - ElseIf name = "trim" Then - Awk_HandleBuiltinFunction = Trim(args(0)) - End If - - 'Dim i As Integer - 'Dim xxx As String - - 'MsgBox name - - 'For i = LBound(args) To UBound(args) - ' xxx = xxx & "," & args(i) - 'Next i - - 'MsgBox xxx -End Function - -Private Sub Form_Load() - SourceIn.Text = "" - SourceOut.Text = "" - ConsoleIn.Text = "" - ConsoleOut.Text = "" -End Sub - diff --git a/ase/test/com/AwkForm.frx b/ase/test/com/AwkForm.frx deleted file mode 100644 index 9dd42b079c0b8610de851272b68bc1e88ab4f9fe..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 17 WcmZQ%U}j)sFkob00m9tG%sc=F#R231 diff --git a/ase/test/com/ase.vbp b/ase/test/com/ase.vbp deleted file mode 100644 index 460bda16..00000000 --- a/ase/test/com/ase.vbp +++ /dev/null @@ -1,37 +0,0 @@ -Type=Exe -Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\..\..\WINDOWS\System32\stdole2.tlb#OLE Automation -Reference=*\G{F9C69806-16A1-4162-998A-876B33C470BF}#1.0#0#..\..\debug\ase.dll#ASE Awk 1.0 Type Library -Form=AwkForm.frm -Class=AwkExtioConsole; AwkExtioConsole.cls -IconForm="AwkForm" -Startup="AwkForm" -HelpFile="" -Title="ase" -ExeName32="ase.exe" -Command32="" -Name="ASECOM" -HelpContextID="0" -CompatibleMode="0" -MajorVer=1 -MinorVer=0 -RevisionVer=0 -AutoIncrementVer=0 -ServerSupportFiles=0 -CompilationType=0 -OptimizationType=0 -FavorPentiumPro(tm)=0 -CodeViewDebugInfo=0 -NoAliasing=0 -BoundsCheck=0 -OverflowCheck=0 -FlPointCheck=0 -FDIVCheck=0 -UnroundedFP=0 -StartMode=0 -Unattended=0 -Retained=0 -ThreadPerObject=0 -MaxNumberOfThreads=1 - -[MS Transaction Server] -AutoRefresh=1 diff --git a/ase/test/com/ase.vbw b/ase/test/com/ase.vbw deleted file mode 100644 index a068e5db..00000000 --- a/ase/test/com/ase.vbw +++ /dev/null @@ -1,2 +0,0 @@ -AwkForm = 13, 12, 735, 661, , 22, 22, 753, 640, C -AwkExtioConsole = 0, 0, 547, 460, C diff --git a/ase/test/com/awk.js b/ase/test/com/awk.js deleted file mode 100644 index 0323c738..00000000 --- a/ase/test/com/awk.js +++ /dev/null @@ -1,72 +0,0 @@ -var awk, first, n - -first = true - -function awk_OpenSource (mode) -{ - WScript.echo ("OpenSource - mode:" + mode); - return 1; -} - -function awk_CloseSource (mode) -{ - WScript.echo ("CloseSource - mode:" + mode); - return 0; -} - -function awk_ReadSource (buf) -{ - WScript.echo ("ReadSource - buf: [" + buf.Value + "]"); - if (first) - { - buf.Value = "BEGIN {print 1; print 2;}" - first = false - return buf.Value.length; - } - else return 0; -} - -function awk_WriteSource (buf) -{ - //WScript.echo ("WriteSource - cnt: " + cnt) - WScript.echo (buf.Value); - return buf.Value.length; -} - -function awk_OpenExtio (extio) -{ - WScript.echo ("OpenExtio - type: " + extio.Type + " mode: " + extio.Mode + " name: [" + extio.Name + "]"); - return 1; -} - -function awk_CloseExtio (extio) -{ - WScript.echo ("CloseExtio"); - return 0; -} - -function awk_WriteExtio (extio, buf) -{ - WScript.echo (buf.Value); - return buf.Value.length; -} - -awk = WScript.CreateObject("ASE.Awk"); -WScript.ConnectObject (awk, "awk_"); - - -n = awk.Parse(); -if (n == -1) -{ - WScript.echo ("parse failed"); - WScript.quit (1); -} - -n = awk.Run (); -if (n == -1) -{ - WScript.echo ("run failed"); - WScript.quit (1); -} - - diff --git a/ase/test/com/awk.vbs b/ase/test/com/awk.vbs deleted file mode 100644 index c3a4c077..00000000 --- a/ase/test/com/awk.vbs +++ /dev/null @@ -1,30 +0,0 @@ -dim awk, first - -first = true - -function awk_OpenSource (mode) - WScript.echo ("OpenSource - mode:" & mode) - awk_OpenSource = 1 -end function - -function awk_CloseSource (mode) - WScript.echo ("CloseSource - mode:" & mode) - awk_CloseSource = 0 -end function - -function awk_ReadSource (buf, cnt) - WScript.echo ("ReadSource - cnt: " & cnt) - if first then - buf.Value = "BEGIN {print 1;}" - first = false - awk_ReadSource = len(buf.Value) - else - awk_ReadSource = 0 - end if -end function - -set awk = WScript.CreateObject("ASE.Awk") -call WScript.ConnectObject (awk, "awk_") - -WScript.echo awk.Parse -set awk = nothing diff --git a/ase/test/lsp/asetestlsp.dsp b/ase/test/lsp/asetestlsp.dsp deleted file mode 100644 index 1465de22..00000000 --- a/ase/test/lsp/asetestlsp.dsp +++ /dev/null @@ -1,102 +0,0 @@ -# Microsoft Developer Studio Project File - Name="asetestlsp" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Console Application" 0x0103 - -CFG=asetestlsp - Win32 Debug -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "asetestlsp.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "asetestlsp.mak" CFG="asetestlsp - Win32 Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "asetestlsp - Win32 Release" (based on "Win32 (x86) Console Application") -!MESSAGE "asetestlsp - Win32 Debug" (based on "Win32 (x86) Console Application") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -RSC=rc.exe - -!IF "$(CFG)" == "asetestlsp - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "../../release/bin" -# PROP Intermediate_Dir "release" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /MT /W3 /GX /O2 /I "..\..\.." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_UNICODE" /D _WIN32_WINNT=0x0400 /YX /FD /c -# ADD BASE RSC /l 0x409 /d "NDEBUG" -# ADD RSC /l 0x409 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 -# ADD LINK32 aselsp.lib asecmn.lib aseutl.lib user32.lib kernel32.lib /nologo /subsystem:console /machine:I386 /out:"$(OutDir)/aselsp.exe" /libpath:"$(OutDir)/../lib" - -!ELSEIF "$(CFG)" == "asetestlsp - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "../../debug/bin" -# PROP Intermediate_Dir "debug" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c -# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "..\..\.." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D _WIN32_WINNT=0x0400 /FR /YX /FD /GZ /c -# ADD BASE RSC /l 0x409 /d "_DEBUG" -# ADD RSC /l 0x409 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept -# ADD LINK32 aselsp.lib asecmn.lib aseutl.lib user32.lib kernel32.lib /nologo /subsystem:console /debug /machine:I386 /out:"$(OutDir)/aselsp.exe" /pdbtype:sept /libpath:"$(OutDir)/../lib" - -!ENDIF - -# Begin Target - -# Name "asetestlsp - Win32 Release" -# Name "asetestlsp - Win32 Debug" -# Begin Group "Source Files" - -# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" -# Begin Source File - -SOURCE=.\lsp.c -# End Source File -# End Group -# Begin Group "Header Files" - -# PROP Default_Filter "h;hpp;hxx;hm;inl" -# End Group -# Begin Group "Resource Files" - -# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" -# End Group -# End Target -# End Project diff --git a/ase/test/lsp/descrip.mms b/ase/test/lsp/descrip.mms deleted file mode 100644 index 52184002..00000000 --- a/ase/test/lsp/descrip.mms +++ /dev/null @@ -1,13 +0,0 @@ -# -# OpenVMS MMS/MMK -# - -objects = lsp.obj - -CFLAGS = /include="../../.." -#CFLAGS = /pointer_size=long /include="../../.." - -aselsp.exe : $(objects) - link /executable=aselsp.exe $(objects),[-.-.lsp]aselsp/library - -lsp.obj depends_on lsp.c diff --git a/ase/test/lsp/lsp.c b/ase/test/lsp/lsp.c deleted file mode 100644 index a5361332..00000000 --- a/ase/test/lsp/lsp.c +++ /dev/null @@ -1,398 +0,0 @@ -#include - -#include -#include -#include - -#include -#include - -#ifdef _WIN32 -#include -#include -#endif - -#if defined(_WIN32) && defined(_MSC_VER) && defined(_DEBUG) -#define _CRTDBG_MAP_ALLOC -#include -#endif - -#ifdef __linux -#include -#endif - -#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 -#endif - -#ifndef NDEBUG -void ase_assert_abort (void) -{ - abort (); -} - -void ase_assert_printf (const ase_char_t* fmt, ...) -{ - va_list ap; -#ifdef _WIN32 - int n; - ase_char_t buf[1024]; -#endif - - va_start (ap, fmt); -#if defined(_WIN32) - n = _vsntprintf (buf, ASE_COUNTOF(buf), fmt, ap); - if (n < 0) buf[ASE_COUNTOF(buf)-1] = ASE_T('\0'); - - #if defined(_MSC_VER) && (_MSC_VER<1400) - MessageBox (NULL, buf, - ASE_T("Assertion Failure"), MB_OK|MB_ICONERROR); - #else - MessageBox (NULL, buf, - ASE_T("\uB2DD\uAE30\uB9AC \uC870\uB610"), MB_OK|MB_ICONERROR); - #endif -#else - ase_vprintf (fmt, ap); -#endif - va_end (ap); -} -#endif - - -static ase_ssize_t get_input ( - int cmd, void* arg, ase_char_t* data, ase_size_t size) -{ - switch (cmd) - { - case ASE_LSP_IO_OPEN: - case ASE_LSP_IO_CLOSE: - return 0; - - case ASE_LSP_IO_READ: - { - /* - if (ase_fgets (data, size, stdin) == ASE_NULL) - { - if (ferror(stdin)) return -1; - return 0; - } - return ase_lsp_strlen(data); - */ - - ase_cint_t c; - - if (size <= 0) return -1; - c = ase_fgetc (stdin); - - if (c == ASE_CHAR_EOF) - { - if (ferror(stdin)) return -1; - return 0; - } - - data[0] = c; - return 1; - } - } - - return -1; -} - -static ase_ssize_t put_output ( - int cmd, void* arg, ase_char_t* data, ase_size_t size) -{ - switch (cmd) - { - case ASE_LSP_IO_OPEN: - case ASE_LSP_IO_CLOSE: - return 0; - - case ASE_LSP_IO_WRITE: - { - int n = ase_fprintf ( - stdout, ASE_T("%.*s"), size, data); - if (n < 0) return -1; - - return size; - } - } - - return -1; -} - -#ifdef _WIN32 -typedef struct prmfns_data_t prmfns_data_t; -struct prmfns_data_t -{ - HANDLE heap; -}; -#endif - -static void* custom_lsp_malloc (void* custom, ase_size_t n) -{ -#ifdef _WIN32 - return HeapAlloc (((prmfns_data_t*)custom)->heap, 0, n); -#else - return malloc (n); -#endif -} - -static void* custom_lsp_realloc (void* custom, void* ptr, ase_size_t n) -{ -#ifdef _WIN32 - /* HeapReAlloc behaves differently from realloc */ - if (ptr == NULL) - return HeapAlloc (((prmfns_data_t*)custom)->heap, 0, n); - else - return HeapReAlloc (((prmfns_data_t*)custom)->heap, 0, ptr, n); -#else - return realloc (ptr, n); -#endif -} - -static void custom_lsp_free (void* custom, void* ptr) -{ -#ifdef _WIN32 - HeapFree (((prmfns_data_t*)custom)->heap, 0, ptr); -#else - free (ptr); -#endif -} - -static ase_bool_t custom_lsp_isupper (void* custom, ase_cint_t c) -{ - return ase_isupper (c); -} - -static ase_bool_t custom_lsp_islower (void* custom, ase_cint_t c) -{ - return ase_islower (c); -} - -static ase_bool_t custom_lsp_isalpha (void* custom, ase_cint_t c) -{ - return ase_isalpha (c); -} - -static ase_bool_t custom_lsp_isdigit (void* custom, ase_cint_t c) -{ - return ase_isdigit (c); -} - -static ase_bool_t custom_lsp_isxdigit (void* custom, ase_cint_t c) -{ - return ase_isxdigit (c); -} - -static ase_bool_t custom_lsp_isalnum (void* custom, ase_cint_t c) -{ - return ase_isalnum (c); -} - -static ase_bool_t custom_lsp_isspace (void* custom, ase_cint_t c) -{ - return ase_isspace (c); -} - -static ase_bool_t custom_lsp_isprint (void* custom, ase_cint_t c) -{ - return ase_isprint (c); -} - -static ase_bool_t custom_lsp_isgraph (void* custom, ase_cint_t c) -{ - return ase_isgraph (c); -} - -static ase_bool_t custom_lsp_iscntrl (void* custom, ase_cint_t c) -{ - return ase_iscntrl (c); -} - -static ase_bool_t custom_lsp_ispunct (void* custom, ase_cint_t c) -{ - return ase_ispunct (c); -} - -static ase_cint_t custom_lsp_toupper (void* custom, ase_cint_t c) -{ - return ase_toupper (c); -} - -static ase_cint_t custom_lsp_tolower (void* custom, ase_cint_t c) -{ - return ase_tolower (c); -} - -static int custom_lsp_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; -} - - -static void custom_lsp_dprintf (void* custom, const ase_char_t* fmt, ...) -{ - va_list ap; - va_start (ap, fmt); - ase_vfprintf (stderr, fmt, ap); - va_end (ap); -} - - -int lsp_main (int argc, ase_char_t* argv[]) -{ - ase_lsp_t* lsp; - ase_lsp_obj_t* obj; - int mem, inc; - ase_lsp_prmfns_t prmfns; -#ifdef _WIN32 - prmfns_data_t prmfns_data; -#endif - - mem = 1000; - inc = 1000; - - if (mem <= 0) - { - ase_printf (ASE_T("error: invalid memory size given\n")); - return -1; - } - - memset (&prmfns, 0, sizeof(prmfns)); - - prmfns.mmgr.malloc = custom_lsp_malloc; - prmfns.mmgr.realloc = custom_lsp_realloc; - prmfns.mmgr.free = custom_lsp_free; -#ifdef _WIN32 - prmfns_data.heap = HeapCreate (0, 1000000, 1000000); - if (prmfns_data.heap == NULL) - { - ase_printf (ASE_T("Error: cannot create an lsp heap\n")); - return -1; - } - - prmfns.mmgr.custom_data = &prmfns_data; -#else - prmfns.mmgr.custom_data = ASE_NULL; -#endif - - prmfns.ccls.is_upper = custom_lsp_isupper; - prmfns.ccls.is_lower = custom_lsp_islower; - prmfns.ccls.is_alpha = custom_lsp_isalpha; - prmfns.ccls.is_digit = custom_lsp_isdigit; - prmfns.ccls.is_xdigit = custom_lsp_isxdigit; - prmfns.ccls.is_alnum = custom_lsp_isalnum; - prmfns.ccls.is_space = custom_lsp_isspace; - prmfns.ccls.is_print = custom_lsp_isprint; - prmfns.ccls.is_graph = custom_lsp_isgraph; - prmfns.ccls.is_cntrl = custom_lsp_iscntrl; - prmfns.ccls.is_punct = custom_lsp_ispunct; - prmfns.ccls.to_upper = custom_lsp_toupper; - prmfns.ccls.to_lower = custom_lsp_tolower; - prmfns.ccls.custom_data = ASE_NULL; - - prmfns.misc.sprintf = custom_lsp_sprintf; - prmfns.misc.dprintf = custom_lsp_dprintf; - prmfns.misc.custom_data = ASE_NULL; - - lsp = ase_lsp_open (&prmfns, mem, inc); - if (lsp == ASE_NULL) - { -#ifdef _WIN32 - HeapDestroy (prmfns_data.heap); -#endif - ase_printf (ASE_T("error: cannot create a lsp instance\n")); - return -1; - } - - ase_printf (ASE_T("ASELSP 0.0001\n")); - - ase_lsp_attinput (lsp, get_input, ASE_NULL); - ase_lsp_attoutput (lsp, put_output, ASE_NULL); - - while (1) - { - ase_printf (ASE_T("ASELSP $ ")); - fflush (stdout); - - obj = ase_lsp_read (lsp); - if (obj == ASE_NULL) - { - int errnum; - const ase_char_t* errmsg; - - ase_lsp_geterror (lsp, &errnum, &errmsg); - - if (errnum != ASE_LSP_EEND && - errnum != ASE_LSP_EEXIT) - { - ase_printf ( - ASE_T("error in read: [%d] %s\n"), - errnum, errmsg); - } - - /* TODO: change the following check */ - if (errnum < ASE_LSP_ESYNTAX) break; - continue; - } - - if ((obj = ase_lsp_eval (lsp, obj)) != ASE_NULL) - { - ase_lsp_print (lsp, obj); - ase_printf (ASE_T("\n")); - } - else - { - int errnum; - const ase_char_t* errmsg; - - ase_lsp_geterror (lsp, &errnum, &errmsg); - if (errnum == ASE_LSP_EEXIT) break; - - ase_printf ( - ASE_T("error in eval: [%d] %s\n"), - errnum, errmsg); - } - } - - ase_lsp_close (lsp); - -#ifdef _WIN32 - HeapDestroy (prmfns_data.heap); -#endif - return 0; -} - -int ase_main (int argc, ase_char_t* argv[]) -{ - int n; - -#if defined(__linux) && defined(_DEBUG) - mtrace (); -#endif - - n = lsp_main (argc, argv); - -#if defined(__linux) && defined(_DEBUG) - muntrace (); -#endif -#if defined(_WIN32) && defined(_MSC_VER) && defined(_DEBUG) - _CrtDumpMemoryLeaks (); - wprintf (L"Press ENTER to quit\n"); - getchar (); -#endif - - return n; -} diff --git a/ase/test/lsp/makefile.in b/ase/test/lsp/makefile.in deleted file mode 100644 index 21db428f..00000000 --- a/ase/test/lsp/makefile.in +++ /dev/null @@ -1,23 +0,0 @@ -# -# $Id: makefile.in,v 1.1.1.1 2007/03/28 14:05:30 bacon Exp $ -# - -CC = @CC@ -CFLAGS = @CFLAGS@ -I@abs_top_builddir@/.. -LDFLAGS = @LDFLAGS@ -L@abs_top_builddir@/@BUILDMODE@/lib -LIBS = @LIBS@ -laselsp -lasecmn -laseutl -lm -MODE = @BUILDMODE@ - -OUT_DIR = ../../$(MODE)/bin - -all: $(OUT_DIR)/aselsp - -$(OUT_DIR)/aselsp: $(OUT_DIR) - $(CC) $(CFLAGS) -o $@ lsp.c $(LDFLAGS) $(LIBS) - -$(OUT_DIR): - mkdir -p $(OUT_DIR) - -clean: - rm -rf $(OUT_DIR)/aselsp - diff --git a/ase/test/lsp/makefile.msw.bcc b/ase/test/lsp/makefile.msw.bcc deleted file mode 100644 index 5892cc91..00000000 --- a/ase/test/lsp/makefile.msw.bcc +++ /dev/null @@ -1,19 +0,0 @@ -CC = bcc32 -LD = ilink32 -CFLAGS = -I..\..\.. -LDFLAGS = -L..\..\cmn -L..\..\lsp -L..\..\utl -LIBS = import32.lib cw32mt.lib asecmn.lib aselsp.lib aseutl.lib -STARTUP = c0x32w.obj - -all: aselsp - -aselsp: lsp.obj - $(LD) $(LDFLAGS) $(STARTUP) lsp.obj,$@.exe,,$(LIBS),, - -clean: - del $(OBJS) *.obj $(OUT) - -.SUFFIXES: .c .obj -.c.obj: - $(CC) $(CFLAGS) -c $< - diff --git a/ase/test/lsp/makefile.msw.cl b/ase/test/lsp/makefile.msw.cl deleted file mode 100644 index a70121fb..00000000 --- a/ase/test/lsp/makefile.msw.cl +++ /dev/null @@ -1,17 +0,0 @@ -CC = cl -CFLAGS = /nologo /MT /GX /W3 /GR- /D_WIN32_WINNT=0x0400 -I..\..\.. -LDFLAGS = /libpath:..\..\cmn /libpath:..\..\lsp /libpath:..\..\utl -LIBS = asecmn.lib aselsp.lib aseutl.lib user32.lib - -all: aselsp - -aselsp: lsp.obj - link /nologo /out:$@.exe $(LDFLAGS) $(LIBS) lsp.obj - -clean: - del $(OBJS) *.obj lsp.exe - -.SUFFIXES: .c .obj -.c.obj: - $(CC) /c $(CFLAGS) $< - diff --git a/ase/test/lsp/t1.lsp b/ase/test/lsp/t1.lsp deleted file mode 100644 index cc8873a3..00000000 --- a/ase/test/lsp/t1.lsp +++ /dev/null @@ -1,21 +0,0 @@ -(setq x (lambda (x) (car x))) -((lambda (x) (+ x 99)) (x '(10 20 30))) - -((lambda (x) ((lambda (y) (+ y 1)) x)) 10) -; lisp.... -((lambda (x) ((macro (y) (+ y 1)) x)) 10) - - - - -;;;;;;; -(setq init-rand (macro (seed) (lambda () (setq seed (+ seed 1))))) - -(setq init-rand (lambda (seed) (lambda () (setq seed (+ seed 1))))) -(setq rand (init-rand 1)) -(rand) - -(defun init-rand (seed) (lambda () (setq seed (+ seed 1)))) -(defun rand () (init-rand 1)) -(rand) - diff --git a/ase/test/lsp/t2.lsp b/ase/test/lsp/t2.lsp deleted file mode 100644 index 95e76133..00000000 --- a/ase/test/lsp/t2.lsp +++ /dev/null @@ -1,170 +0,0 @@ -;(setq x (lambda (x) (+ x 20 30 40))) -(defun x(x) (+ x 20 30 40)) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 100) -(x 200) -(x 200) -(x 200) -(x 200) -(x 200) diff --git a/ase/test/lsp/t3.lsp b/ase/test/lsp/t3.lsp deleted file mode 100644 index 0a28bf6a..00000000 --- a/ase/test/lsp/t3.lsp +++ /dev/null @@ -1,8 +0,0 @@ -; test while - -(setq x 10) -(setq y 10) -(while (< x 100) (setq y (+ x y)) (setq x (+ x 1))) -x -y - diff --git a/ase/test/lsp/t4.lsp b/ase/test/lsp/t4.lsp deleted file mode 100644 index ac40a254..00000000 --- a/ase/test/lsp/t4.lsp +++ /dev/null @@ -1,7 +0,0 @@ -;Compute the factorial of N. -(defun factorial (N) - (if (= N 1) - 1 - (* N (factorial (- N 1))))) - -(factorial 10) diff --git a/ase/test/lsp/t5.lsp b/ase/test/lsp/t5.lsp deleted file mode 100644 index 066dbf60..00000000 --- a/ase/test/lsp/t5.lsp +++ /dev/null @@ -1,8 +0,0 @@ -; Compute the N'th Fibonacci number. -(defun fibonacci (N) - ;(if (or (zerop N) (= N 1)) - (if (or (= N 0) (= N 1)) - 1 - (+ (fibonacci (- N 1)) (fibonacci (- N 2))))) - -(fibonacci 5) diff --git a/ase/test/lsp/t6.lsp b/ase/test/lsp/t6.lsp deleted file mode 100644 index a411e278..00000000 --- a/ase/test/lsp/t6.lsp +++ /dev/null @@ -1,9 +0,0 @@ - - -(setq x '(a b c)) -(setq y '(x y z)) -(setcar x y) -(setcar y x) -x -y - diff --git a/ase/test/lsp/t7.lsp b/ase/test/lsp/t7.lsp deleted file mode 100644 index 40a0d15a..00000000 --- a/ase/test/lsp/t7.lsp +++ /dev/null @@ -1,4 +0,0 @@ -(setq a '(1 2 3)) -(cons a (cons a 10)) -(setq xx (cons a (cons a 10))) - diff --git a/ase/test/stx/helper.st b/ase/test/stx/helper.st deleted file mode 100644 index af3cb844..00000000 --- a/ase/test/stx/helper.st +++ /dev/null @@ -1,13 +0,0 @@ -| x | -"print the reverse hierarchy of a class" -x := Class. -[x isNil] whileFalse: [ - Transcript show: x printString; cr. - x := x superclass]. - -| x | -"print the reverse hierarchy of a metaclass" -x := Class class. -[x isNil] whileFalse: [ - Transcript show: x printString; cr. - x := x superclass]. diff --git a/ase/test/stx/makefile.bcc b/ase/test/stx/makefile.bcc deleted file mode 100644 index f4e2a7da..00000000 --- a/ase/test/stx/makefile.bcc +++ /dev/null @@ -1,21 +0,0 @@ -CC = bcc32 -CFLAGS = -I..\..\.. -LDFLAGS = -L..\..\..\xp\bas -L..\..\..\xp\stx -LIBS = import32.lib cw32mt.lib xpbas.lib xpstx.lib -STARTUP = c0x32w.obj - -all: stx parser - -stx: stx.obj - ilink32 $(LDFLAGS) $(STARTUP) stx.obj,stx.exe,,$(LIBS),, - -parser: parser.obj - ilink32 $(LDFLAGS) $(STARTUP) parser.obj,parser.exe,,$(LIBS),, - -clean: - del $(OBJS) *.obj $(OUT) - -.SUFFIXES: .c .obj -.c.obj: - $(CC) $(CFLAGS) -c $< - diff --git a/ase/test/stx/makefile.cl b/ase/test/stx/makefile.cl deleted file mode 100644 index d3659291..00000000 --- a/ase/test/stx/makefile.cl +++ /dev/null @@ -1,20 +0,0 @@ -CC = cl -CFLAGS = /nologo /MT /GX /W3 /GR- /D_WIN32_WINNT=0x0400 -I..\..\.. -LDFLAGS = /libpath:..\..\bas /libpath:..\..\stx -LIBS = xpbas.lib xpstx.lib - -all: stx parser - -stx: stx.obj - link /nologo /out:stx.exe $(LDFLAGS) $(LIBS) stx.obj - -parser: parser.obj - link /nologo /out:parser.exe $(LDFLAGS) $(LIBS) parser.obj - -clean: - del $(OBJS) *.obj stx.exe parser.exe - -.SUFFIXES: .c .obj -.c.obj: - $(CC) /c $(CFLAGS) $< - diff --git a/ase/test/stx/makefile.in b/ase/test/stx/makefile.in deleted file mode 100644 index 2d18d282..00000000 --- a/ase/test/stx/makefile.in +++ /dev/null @@ -1,19 +0,0 @@ -CC = @CC@ -CFLAGS = @CFLAGS@ -I@abs_top_builddir@ -LDFLAGS = @LDFLAGS@ -L@abs_top_builddir@/xp/bas -L@abs_top_builddir@/xp/stx -LIBS = @LIBS@ -lxpstx -lxpbas - -all: stx parser - -stx: stx.o - $(CC) $(LDFLAGS) -o $@.x stx.o $(LIBS) - -parser: parser.o - $(CC) $(LDFLAGS) -o $@.x parser.o $(LIBS) - -clean: - rm -rf *.x *.o - -.SUFFIXES: .c .o -.c.o: - $(CC) $(CFLAGS) -c $< diff --git a/ase/test/stx/makefile.lcc b/ase/test/stx/makefile.lcc deleted file mode 100644 index bf6925b0..00000000 --- a/ase/test/stx/makefile.lcc +++ /dev/null @@ -1,24 +0,0 @@ -CC = lcc -CFLAGS = -I../../.. -A -ansic -libcdll -#LDFLAGS = -L../../../xp/bas -L../../../xp/stx -#LIBS = -lxpstx -lxpbas -#LDFLAGS = -subsystem console -dynamic -s -LDFLAGS = -subsystem console -s -LIBS = ..\..\..\xp\stx\xpstx.lib ..\..\..\xp\bas\xpbas.lib - -all: stx parser - -stx: stx.obj - lcclnk $(LDFLAGS) -o stx.exe stx.obj $(LIBS) - -parser: parser.obj - lcclnk $(LDFLAGS) -o parser.exe parser.obj $(LIBS) - - -clean: - del $(OBJS) *.obj $(OUT) - -.SUFFIXES: .c .obj -.c.obj: - $(CC) $(CFLAGS) -c $< - diff --git a/ase/test/stx/makefile.tcc b/ase/test/stx/makefile.tcc deleted file mode 100644 index f944b475..00000000 --- a/ase/test/stx/makefile.tcc +++ /dev/null @@ -1,19 +0,0 @@ -SRCS = stx.c -OBJS = stx.obj -OUT = stx.exe - -TC = \dos\tc -CC = $(TC)\tcc -CFLAGS = -I..\..\.. -ml -D_DOS -w -LIBS = $(TC)\lib\cl.lib $(TC)\lib\c0l.obj ..\..\..\xp\stx\xpstx.lib - -all: $(OBJS) - $(TC)\tlink $(OBJS),$(OUT),,$(LIBS) - -clean: - del $(OBJS) *.obj $(OUT) - -.SUFFIXES: .c .obj -.c.obj: - $(CC) $(CFLAGS) -c $< - diff --git a/ase/test/stx/parser.c b/ase/test/stx/parser.c deleted file mode 100644 index b142c4bc..00000000 --- a/ase/test/stx/parser.c +++ /dev/null @@ -1,230 +0,0 @@ -#include - -#ifdef _DOS - #include - #define xp_printf printf -#else - #include - #include -#endif - -#include -#include -#include -#include -#include - -#ifdef __linux -#include -#endif - -struct ss_t -{ - const xp_char_t* text; - xp_size_t index; -}; - -typedef struct ss_t ss_t; - -int ss_func (int cmd, void* owner, void* arg) -{ - - if (cmd == XP_STX_PARSER_INPUT_OPEN) { - ss_t* ss = *(ss_t**)owner; - ss->text = (const xp_char_t*)arg; - ss->index = 0; - return 0; - } - else if (cmd == XP_STX_PARSER_INPUT_CLOSE) { - /*ss_t* ss = (ss_t*)owner; */ - return 0; - } - else if (cmd == XP_STX_PARSER_INPUT_CONSUME) { - ss_t* ss = (ss_t*)owner; - xp_cint_t* c = (xp_cint_t*)arg; - if (ss->text[ss->index] == XP_CHAR('\0')) { - *c = XP_CHAR_EOF; - } - else *c = ss->text[ss->index++]; - return 0; - } - else if (cmd == XP_STX_PARSER_INPUT_REWIND) { - return 0; - } - return -1; -} - -struct stdio_t -{ - XP_FILE* stdio; -}; - -typedef struct stdio_t stdio_t; - -int stdio_func (int cmd, void* owner, void* arg) -{ - - if (cmd == XP_STX_PARSER_INPUT_OPEN) { - stdio_t* p = *(stdio_t**)owner; - p->stdio = xp_fopen ((const xp_char_t*)arg, XP_TEXT("r")); - if (p->stdio == XP_NULL) return -1; - return 0; - } - else if (cmd == XP_STX_PARSER_INPUT_CLOSE) { - stdio_t* p = (stdio_t*)owner; - xp_fclose (p->stdio); - return 0; - } - else if (cmd == XP_STX_PARSER_INPUT_CONSUME) { - stdio_t* p = (stdio_t*)owner; - xp_cint_t* c = (xp_cint_t*)arg; - xp_cint_t t = xp_fgetc (p->stdio); - if (t == XP_CHAR_EOF) { - if (xp_ferror (p->stdio)) return -1; - *c = XP_CHAR_EOF; - } - else *c = t; - return 0; - } - else if (cmd == XP_STX_PARSER_INPUT_REWIND) { - return 0; - } - return -1; -} - -int xp_main (int argc, xp_char_t* argv[]) -{ - xp_stx_t stx; - xp_stx_parser_t parser; - -#ifdef __linux - mtrace (); -#endif - -/* -#ifndef _DOS - if (xp_setlocale () == -1) { - printf ("cannot set locale\n"); - return -1; - } -#endif -*/ - - if (argc != 2) { - xp_printf (XP_TEXT("usage: %s class_name\n"), argv[0]); - return -1; - } - - if (xp_stx_open (&stx, 10000) == XP_NULL) { - xp_printf (XP_TEXT("cannot open stx\n")); - return -1; - } - - if (xp_stx_bootstrap(&stx) == -1) { - xp_stx_close (&stx); - xp_printf (XP_TEXT("cannot bootstrap\n")); - return -1; - } - - - if (xp_stx_parser_open(&parser, &stx) == XP_NULL) { - xp_printf (XP_TEXT("cannot open parser\n")); - return -1; - } - - - { - /* - ss_t ss; - parser.input_owner = (void*)&ss; - parser.input_func = ss_func; - xp_stx_parser_parse_method (&parser, 0, - XP_TEXT("isNil\n^true")); - */ - stdio_t stdio; - xp_word_t n = xp_stx_lookup_class (&stx, argv[1]); - xp_word_t m; - - parser.input_owner = (void*)&stdio; - parser.input_func = stdio_func; - - if (n == stx.nil) { - xp_printf (XP_TEXT("Cannot find class - %s\n"), argv[1]); - goto exit_program; - } - - /* compile the method to n's class */ - if (xp_stx_parser_parse_method (&parser, XP_STX_CLASS(&stx,n), - (void*)XP_TEXT("test.st")) == -1) { - xp_printf (XP_TEXT("parser error <%s>\n"), - xp_stx_parser_error_string (&parser)); - } - - if (xp_stx_parser_parse_method (&parser, stx.class_symbol, - (void*)XP_TEXT("test1.st")) == -1) { - xp_printf (XP_TEXT("parser error <%s>\n"), - xp_stx_parser_error_string (&parser)); - } - - if (xp_stx_parser_parse_method (&parser, stx.class_symbol, - (void*)XP_TEXT("test2.st")) == -1) { - xp_printf (XP_TEXT("parser error <%s>\n"), - xp_stx_parser_error_string (&parser)); - } - - if (xp_stx_parser_parse_method (&parser, stx.class_string, - (void*)XP_TEXT("test3.st")) == -1) { - xp_printf (XP_TEXT("parser error <%s>\n"), - xp_stx_parser_error_string (&parser)); - } - - xp_printf (XP_TEXT("\n== Decoded Methods ==\n")); - if (xp_stx_decode(&stx, XP_STX_CLASS(&stx,n)) == -1) { - xp_printf (XP_TEXT("parser error <%s>\n"), - xp_stx_parser_error_string (&parser)); - } - - xp_printf (XP_TEXT("\n== Decoded Methods for Symbol ==\n")); - if (xp_stx_decode(&stx, stx.class_symbol) == -1) { - xp_printf (XP_TEXT("parser error <%s>\n"), - xp_stx_parser_error_string (&parser)); - } - - xp_printf (XP_TEXT("\n== Decoded Methods for String ==\n")); - if (xp_stx_decode(&stx, stx.class_string) == -1) { - xp_printf (XP_TEXT("parser error <%s>\n"), - xp_stx_parser_error_string (&parser)); - } - - xp_printf (XP_TEXT("== Running the main method ==\n")); - m = xp_stx_lookup_method ( - &stx, XP_STX_CLASS(&stx,n), XP_TEXT("main"), xp_false); - if (m == stx.nil) { - xp_printf (XP_TEXT("cannot lookup method main\n")); - } - else { - xp_stx_interp (&stx, n, m); - } - } - -exit_program: - xp_stx_parser_close (&parser); - xp_stx_close (&stx); - xp_printf (XP_TEXT("== End of program ==\n")); - -#ifdef __linux - muntrace (); -#endif - -/* -#ifdef __linux - { - char buf[1000]; - snprintf (buf, sizeof(buf), "ls -l /proc/%u/fd", getpid()); - system (buf); - } -#endif -*/ - return 0; -} - diff --git a/ase/test/stx/stx.c b/ase/test/stx/stx.c deleted file mode 100644 index 276d1c28..00000000 --- a/ase/test/stx/stx.c +++ /dev/null @@ -1,237 +0,0 @@ -#include - -#ifdef _DOS - #include - #define xp_printf printf -#else - #include - #include -#endif - -#include -#include -#include -#include -#include -#include - -void print_symbol_names (xp_stx_t* stx, xp_word_t sym, void* unused) -{ - xp_printf (XP_TEXT("%lu [%s]\n"), (unsigned long)sym, XP_STX_DATA(stx,sym)); -} - -void print_symbol_names_2 (xp_stx_t* stx, xp_word_t idx, void* unused) -{ - xp_word_t key = XP_STX_WORD_AT(stx,idx,XP_STX_ASSOCIATION_KEY); - xp_word_t value = XP_STX_WORD_AT(stx,idx,XP_STX_ASSOCIATION_VALUE); - xp_printf (XP_TEXT("%lu [%s] %lu\n"), - (unsigned long)key, XP_STX_DATA(stx,key), (unsigned long)value); -} - -void print_superclasses (xp_stx_t* stx, const xp_char_t* name) -{ - xp_word_t n; - xp_stx_class_t* obj; - - n = xp_stx_lookup_class (stx, name); - xp_printf (XP_TEXT("Class hierarchy for the class '%s'\n"), name); - - while (n != stx->nil) { - obj = (xp_stx_class_t*)XP_STX_WORD_OBJECT(stx,n); - xp_printf (XP_TEXT("%lu, %s\n"), - (unsigned long)obj->name, - XP_STX_DATA(stx, obj->name)); - n = obj->superclass; - } -} - -void print_metaclass_superclasses (xp_stx_t* stx, const xp_char_t* name) -{ - xp_word_t n, x; - xp_stx_metaclass_t* obj; - xp_stx_class_t* xobj; - - n = xp_stx_lookup_class (stx, name); - n = XP_STX_CLASS(stx,n); - xp_printf (XP_TEXT("Class hierarchy for the metaclass '%s class'\n"), name); - - while (n != stx->nil) { - /*if (n == stx->class_class) break; */ - if (XP_STX_CLASS(stx,n) != stx->class_metaclass) break; - - obj = (xp_stx_metaclass_t*)XP_STX_WORD_OBJECT(stx,n); - x = obj->instance_class; - xobj = (xp_stx_class_t*)XP_STX_WORD_OBJECT(stx,x); - xp_printf (XP_TEXT("%lu, %s class\n"), - (unsigned long)xobj->name, - XP_STX_DATA(stx, xobj->name)); - n = obj->superclass; - } - while (n != stx->nil) { - xobj = (xp_stx_class_t*)XP_STX_WORD_OBJECT(stx,n); - xp_printf (XP_TEXT("%lu, %s\n"), - (unsigned long)xobj->name, - XP_STX_DATA(stx, xobj->name)); - n = xobj->superclass; - } -} - -void print_class_name (xp_stx_t* stx, xp_word_t class, int tabs) -{ - xp_stx_class_t* xobj; - xobj = (xp_stx_class_t*)XP_STX_WORD_OBJECT(stx,class); - - while (tabs-- > 0) xp_printf (XP_TEXT(" ")); - - xp_printf (XP_TEXT("%s [%lu]\n"), - XP_STX_DATA(stx, xobj->name), - (unsigned long)class); -} - -void print_metaclass_name (xp_stx_t* stx, xp_word_t class, int tabs) -{ - xp_stx_metaclass_t* obj; - xp_stx_class_t* xobj; - - obj = (xp_stx_metaclass_t*)XP_STX_WORD_OBJECT(stx,class); - xobj = (xp_stx_class_t*)XP_STX_WORD_OBJECT(stx,obj->instance_class); - - while (tabs-- > 0) xp_printf (XP_TEXT(" ")); - - xp_printf (XP_TEXT("%s class [%lu]\n"), - XP_STX_DATA(stx, xobj->name), - (unsigned long)class); -} - -void print_subclass_names (xp_stx_t* stx, xp_word_t class, int tabs) -{ - xp_stx_class_t* obj; - - obj = (xp_stx_class_t*)XP_STX_WORD_OBJECT(stx,class); - if (obj->header.class == stx->class_metaclass) { - print_metaclass_name (stx, class, tabs); - } - else { - print_class_name (stx, class, tabs); - } - - if (obj->subclasses != stx->nil) { - xp_word_t count = XP_STX_SIZE(stx, obj->subclasses); - while (count-- > 0) { - print_subclass_names (stx, - XP_STX_WORD_AT(stx,obj->subclasses,count), tabs + 1); - } - } -} - -void print_subclasses (xp_stx_t* stx, const xp_char_t* name) -{ - xp_word_t class; - class = xp_stx_lookup_class (stx, name); - xp_printf (XP_TEXT("== NORMAL == \n")); - print_subclass_names (stx, class, 0); - xp_printf (XP_TEXT("== META == \n")); - print_subclass_names (stx, XP_STX_CLASS(stx,class), 0); -} - -int xp_main (int argc, xp_char_t* argv[]) -{ - xp_stx_t stx; - //xp_word_t i; - -#ifndef _DOS - if (xp_setlocale () == -1) { - printf ("cannot set locale\n"); - return -1; - } -#endif - - if (argc != 2) { /* TODO: argument processing */ - xp_printf (XP_TEXT("Usage: %s [-f imageFile] MainClass\n"), argv[0]); - return -1; - } - - if (xp_stx_open (&stx, 10000) == XP_NULL) { - xp_printf (XP_TEXT("cannot open stx\n")); - return -1; - } - - if (xp_stx_bootstrap(&stx) == -1) { - xp_stx_close (&stx); - xp_printf (XP_TEXT("cannot bootstrap\n")); - return -1; - } - - xp_printf (XP_TEXT("stx.nil %lu\n"), (unsigned long)stx.nil); - xp_printf (XP_TEXT("stx.true %lu\n"), (unsigned long)stx.true); - xp_printf (XP_TEXT("stx.false %lu\n"), (unsigned long)stx.false); - xp_printf (XP_TEXT("-------------\n")); - - - xp_printf (XP_TEXT(">> SYMBOL_TABLE (%u/%u symbols/slots) <<\n"), - (unsigned int)stx.symtab.size, (unsigned int)stx.symtab.capacity); - xp_stx_traverse_symbol_table (&stx, print_symbol_names, XP_NULL); - xp_printf (XP_TEXT("-------------\n")); - - xp_stx_dict_traverse (&stx, stx.smalltalk, print_symbol_names_2, XP_NULL); - xp_printf (XP_TEXT("-------------\n")); - - print_superclasses (&stx, XP_TEXT("Array")); - xp_printf (XP_TEXT("-------------\n")); - print_metaclass_superclasses (&stx, XP_TEXT("Array")); - xp_printf (XP_TEXT("-------------\n")); - print_superclasses (&stx, XP_TEXT("False")); - xp_printf (XP_TEXT("-------------\n")); - print_metaclass_superclasses (&stx, XP_TEXT("False")); - xp_printf (XP_TEXT("-------------\n")); - print_superclasses (&stx, XP_TEXT("Metaclass")); - xp_printf (XP_TEXT("-------------\n")); - print_metaclass_superclasses (&stx, XP_TEXT("Metaclass")); - xp_printf (XP_TEXT("-------------\n")); - print_superclasses (&stx, XP_TEXT("Class")); - xp_printf (XP_TEXT("-------------\n")); - print_metaclass_superclasses (&stx, XP_TEXT("Class")); - xp_printf (XP_TEXT("-------------\n")); - - print_subclasses (&stx, XP_TEXT("Object")); - xp_printf (XP_TEXT("-------------\n")); - -#if 0 - { - xp_word_t method_name; - xp_word_t main_class; - xp_word_t method, context; - - method_name = xp_stx_new_symbol (&stx,XP_TEXT("main")); - - main_class = xp_stx_lookup_class (&stx,argv[1]); - if (main_class == stx.nil) { - xp_printf (XP_TEXT("non-existent class: %s\n"), argv[1]); - return -1; - } - - /* - method = xp_stx_alloc_byte_object (&stx,100); - XP_STX_CLASS(&stx,method) = stx.class_method; - */ - method = xp_stx_instantiate (&stx, XP_TEXT("Method")); - - XP_STX_BYTEAT(&stx,method,0) = PUSH_OBJECT; - XP_STX_BYTEAT(&stx,method,1) = main_class; - XP_STX_BYTEAT(&stx,method,2) = SEND_UNARY_MESSAGE; - XP_STX_BYTEAT(&stx,method,3) = method_name; - XP_STX_BYTEAT(&stx,method,4) = HALT; - - /* - context = xp_stx_new_context (&stx, method, stx.nil, stx.nil); - */ - context = xp_stx_instantiate (&stx, XP_TEXT("Context")); - xp_stx_run_context (&stx, context); - } -#endif - - xp_stx_close (&stx); - xp_printf (XP_TEXT("== End of program ==\n")); - return 0; -} - diff --git a/ase/test/stx/test.st b/ase/test/stx/test.st deleted file mode 100644 index d3dbeb00..00000000 --- a/ase/test/stx/test.st +++ /dev/null @@ -1,13 +0,0 @@ -main - | a | - - - "a := 10. - #abc xxx. - #abc xxx: 1. - ^nil " - - a := #abc print: 123 and: 2345. - #abc print: a and: a. - 1234567. - ^nil. diff --git a/ase/test/stx/test1.st b/ase/test/stx/test1.st deleted file mode 100644 index 3a754107..00000000 --- a/ase/test/stx/test1.st +++ /dev/null @@ -1,10 +0,0 @@ -print: a1 and: a2 - | t1 t2 | - - t1 := #abcdefg. - "a1 := 2341 arguments are not assignable" - t2 := a2. - t1 prim2: t2. - super prim2: 999999. - self prim2: 999999. - ^67891. diff --git a/ase/test/stx/test2.st b/ase/test/stx/test2.st deleted file mode 100644 index 47daeb28..00000000 --- a/ase/test/stx/test2.st +++ /dev/null @@ -1,2 +0,0 @@ -prim2: n - diff --git a/ase/test/stx/test3.st b/ase/test/stx/test3.st deleted file mode 100644 index 4f9eb9b0..00000000 --- a/ase/test/stx/test3.st +++ /dev/null @@ -1,2 +0,0 @@ -prim2: n - diff --git a/ase/utl/aseutl.dsp b/ase/utl/aseutl.dsp deleted file mode 100644 index 210582d1..00000000 --- a/ase/utl/aseutl.dsp +++ /dev/null @@ -1,127 +0,0 @@ -# Microsoft Developer Studio Project File - Name="aseutl" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Static Library" 0x0104 - -CFG=aseutl - Win32 Release -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "aseutl.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "aseutl.mak" CFG="aseutl - Win32 Release" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "aseutl - Win32 Release" (based on "Win32 (x86) Static Library") -!MESSAGE "aseutl - Win32 Debug" (based on "Win32 (x86) Static Library") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -RSC=rc.exe - -!IF "$(CFG)" == "aseutl - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "../release/lib" -# PROP Intermediate_Dir "release" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -MTL=midl.exe -# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_UNICODE" /D "_USRDLL" /Yu"stdafx.h" /FD /c -# ADD CPP /nologo /MT /Za /W3 /GX /O2 /I "../.." /D "NDEBUG" /D "WIN32" /D "_UNICODE" /FD /c -# SUBTRACT CPP /YX /Yc /Yu -# ADD BASE RSC /l 0x409 /d "NDEBUG" -# ADD RSC /l 0x409 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LIB32=link.exe -lib -# ADD BASE LIB32 /nologo - -!ELSEIF "$(CFG)" == "aseutl - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "../debug/lib" -# PROP Intermediate_Dir "debug" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -MTL=midl.exe -# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_UNICODE" /D "_USRDLL" /Yu"stdafx.h" /FD /GZ /c -# ADD CPP /nologo /MTd /Za /W3 /Gm /GX /ZI /Od /I "../.." /D "_DEBUG" /D "WIN32" /D "_UNICODE" /FD /GZ /c -# ADD BASE RSC /l 0x409 /d "_DEBUG" -# ADD RSC /l 0x409 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LIB32=link.exe -lib -# ADD BASE LIB32 /nologo - -!ENDIF - -# Begin Target - -# Name "aseutl - Win32 Release" -# Name "aseutl - Win32 Debug" -# Begin Group "Source Files" - -# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" -# Begin Source File - -SOURCE=.\ctype.c -# End Source File -# Begin Source File - -SOURCE=.\main.c -# End Source File -# Begin Source File - -SOURCE=.\stdio.c -# End Source File -# End Group -# Begin Group "Header Files" - -# PROP Default_Filter "h;hpp;hxx;hm;inl" -# Begin Source File - -SOURCE=.\ctype.h -# End Source File -# Begin Source File - -SOURCE=.\main.h -# End Source File -# Begin Source File - -SOURCE=.\stdio.h -# End Source File -# End Group -# Begin Group "Resource Files" - -# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" -# End Group -# End Target -# End Project diff --git a/ase/utl/ctype.c b/ase/utl/ctype.c deleted file mode 100644 index be591c30..00000000 --- a/ase/utl/ctype.c +++ /dev/null @@ -1,150 +0,0 @@ -/* - * $Id: ctype.c,v 1.1.1.1 2007/03/28 14:05:30 bacon Exp $ - */ - -#include - -#if defined(ASE_CHAR_IS_MCHAR) - -#include - -ase_bool_t ase_isupper (ase_cint_t c) -{ - return isupper (c); -} - -ase_bool_t ase_islower (ase_cint_t c) -{ - return islower (c); -} - -ase_bool_t ase_isalpha (ase_cint_t c) -{ - return isalpha (c); -} - -ase_bool_t ase_isdigit (ase_cint_t c) -{ - return isdigit (c); -} - -ase_bool_t ase_isxdigit (ase_cint_t c) -{ - return isxdigit (c); -} - -ase_bool_t ase_isalnum (ase_cint_t c) -{ - return isalnum (c); -} - -ase_bool_t ase_isspace (ase_cint_t c) -{ - return isspace (c); -} - -ase_bool_t ase_isprint (ase_cint_t c) -{ - return isprint (c); -} - -ase_bool_t ase_isgraph (ase_cint_t c) -{ - return isgraph (c); -} - -ase_bool_t ase_iscntrl (ase_cint_t c) -{ - return iscntrl (c); -} - -ase_bool_t ase_ispunct (ase_cint_t c) -{ - return ispunct (c); -} - -ase_cint_t ase_toupper (ase_cint_t c) -{ - return toupper (c); -} - -ase_cint_t ase_tolower (ase_cint_t c) -{ - return tolower (c); -} - -#elif defined(ASE_CHAR_IS_WCHAR) - -#include -#include - -ase_bool_t ase_isupper (ase_cint_t c) -{ - return iswupper (c); -} - -ase_bool_t ase_islower (ase_cint_t c) -{ - return iswlower (c); -} - -ase_bool_t ase_isalpha (ase_cint_t c) -{ - return iswalpha (c); -} - -ase_bool_t ase_isdigit (ase_cint_t c) -{ - return iswdigit (c); -} - -ase_bool_t ase_isxdigit (ase_cint_t c) -{ - return iswxdigit (c); -} - -ase_bool_t ase_isalnum (ase_cint_t c) -{ - return iswalnum (c); -} - -ase_bool_t ase_isspace (ase_cint_t c) -{ - return iswspace (c); -} - -ase_bool_t ase_isprint (ase_cint_t c) -{ - return iswprint (c); -} - -ase_bool_t ase_isgraph (ase_cint_t c) -{ - return iswgraph (c); -} - -ase_bool_t ase_iscntrl (ase_cint_t c) -{ - return iswcntrl (c); -} - -ase_bool_t ase_ispunct (ase_cint_t c) -{ - return iswpunct (c); -} - -ase_cint_t ase_toupper (ase_cint_t c) -{ - return towupper (c); -} - -ase_cint_t ase_tolower (ase_cint_t c) -{ - return towlower (c); -} - -#else - -#error unsupported character type - -#endif diff --git a/ase/utl/ctype.h b/ase/utl/ctype.h deleted file mode 100644 index 8c5fc55a..00000000 --- a/ase/utl/ctype.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * $id$ - */ - -#ifndef _ASE_UTL_CTYPE_H_ -#define _ASE_UTL_CTYPE_H_ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -ase_bool_t ase_isupper (ase_cint_t c); -ase_bool_t ase_islower (ase_cint_t c); -ase_bool_t ase_isalpha (ase_cint_t c); -ase_bool_t ase_isdigit (ase_cint_t c); -ase_bool_t ase_isxdigit (ase_cint_t c); -ase_bool_t ase_isalnum (ase_cint_t c); -ase_bool_t ase_isspace (ase_cint_t c); -ase_bool_t ase_isprint (ase_cint_t c); -ase_bool_t ase_isgraph (ase_cint_t c); -ase_bool_t ase_iscntrl (ase_cint_t c); -ase_bool_t ase_ispunct (ase_cint_t c); - -ase_cint_t ase_toupper (ase_cint_t c); -ase_cint_t ase_tolower (ase_cint_t c); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ase/utl/descrip.mms b/ase/utl/descrip.mms deleted file mode 100644 index 5fd8ca9d..00000000 --- a/ase/utl/descrip.mms +++ /dev/null @@ -1,16 +0,0 @@ -# -# OpenVMS MMS/MMK -# - -objects = main.obj,ctype.obj,stdio.obj - -CFLAGS = /include="../.." -#CFLAGS = /pointer_size=long /include="../.." -LIBRFLAGS = - -aseutl.olb : $(objects) - $(LIBR)/create $(MMS$TARGET) $(objects) - -main.obj depends_on main.c -ctype.obj depends_on ctype.c -stdio.obj depends_on stdio.c diff --git a/ase/utl/main.c b/ase/utl/main.c deleted file mode 100644 index 6aef6d21..00000000 --- a/ase/utl/main.c +++ /dev/null @@ -1,89 +0,0 @@ -/* - * $Id: main.c,v 1.1.1.1 2007/03/28 14:05:30 bacon Exp $ - * - * {License} - */ - -#include -#include -#include -#include -#include - -#if !defined(_WIN32) && defined(ASE_CHAR_IS_MCHAR) - -int main (int argc, char* argv[], char** envp) -{ - setlocale (LC_ALL, ""); - return ase_main (argc, argv, envp); -} - -#elif !defined(_WIN32) && defined(ASE_CHAR_IS_WCHAR) - -#include - -int main (int argc, char* argv[]/*, char** envp*/) -{ - int i, ret; - ase_char_t** v; - - setlocale (LC_ALL, ""); - - v = (ase_char_t**) malloc (argc * ASE_SIZEOF(ase_char_t*)); - if (v == NULL) return -1; - - for (i = 0; i < argc; i++) v[i] = NULL; - for (i = 0; i < argc; i++) - { - ase_size_t n, len, rem; - char* p = argv[i]; - - len = 0; rem = strlen (p); - while (*p != '\0') - { - int x = mblen (p, rem); - if (x == -1) - { - ret = -1; - goto exit_main; - } - if (x == 0) break; - p += x; rem -= x; len++; - } - - #if (defined(vms) || defined(__vms)) && (ASE_SIZEOF_VOID_P >= 8) - v[i] = (ase_char_t*) _malloc32 ((len+1)*ASE_SIZEOF(ase_char_t)); - #else - v[i] = (ase_char_t*) malloc ((len+1)*ASE_SIZEOF(ase_char_t)); - #endif - if (v[i] == NULL) - { - ret = -1; - goto exit_main; - } - - n = mbstowcs (v[i], argv[i], len); - if (n == (size_t)-1) - { - /* error */ - return -1; - } - - if (n == len) v[i][len] = ASE_T('\0'); - } - - /* TODO: envp... */ - ret = ase_main (argc, v, NULL); - -exit_main: - for (i = 0; i < argc; i++) - { - if (v[i] != NULL) free (v[i]); - } - free (v); - - return ret; -} - -#endif - diff --git a/ase/utl/main.h b/ase/utl/main.h deleted file mode 100644 index 43827090..00000000 --- a/ase/utl/main.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * $Id: main.h,v 1.1.1.1 2007/03/28 14:05:30 bacon Exp $ - */ - -#ifndef _ASE_UTL_MAIN_H_ -#define _ASE_UTL_MAIN_H_ - -#include -#include - -#if defined(_WIN32) - - #include - #define ase_main _tmain - -#else - - #ifdef __cplusplus - extern "C" { int ase_main (...); } - #else - extern int ase_main (); - #endif - -#endif - -#endif diff --git a/ase/utl/makefile.in b/ase/utl/makefile.in deleted file mode 100644 index 4ce2f9b9..00000000 --- a/ase/utl/makefile.in +++ /dev/null @@ -1,49 +0,0 @@ -# -# $Id: makefile.in,v 1.1.1.1 2007/03/28 14:05:30 bacon Exp $ -# - -NAME = aseutl - -CC = @CC@ -AR = ar -MAKE = @MAKE@ -RANLIB = @RANLIB@ -CFLAGS = @CFLAGS@ -I@abs_top_builddir@/.. -LDFLAGS = @LDFLAGS@ -LIBS = @LIBS@ -MODE = @BUILDMODE@ - -OUT_DIR = ../$(MODE)/lib -OUT_FILE = $(OUT_DIR)/lib$(NAME).a - -TMP_DIR = $(MODE) - -OBJ_FILES = \ - $(TMP_DIR)/main.o \ - $(TMP_DIR)/ctype.o \ - $(TMP_DIR)/stdio.o - -lib: $(OUT_FILE) - -$(OUT_FILE): $(OBJ_FILES) $(OUT_DIR) - $(AR) cr $(OUT_FILE) $(OBJ_FILES) - if [ "$(RANLIB)" = "ranlib" ]; then ranlib $(OUT_FILE); fi - -$(TMP_DIR)/main.o: $(TMP_DIR) - $(CC) $(CFLAGS) -o $@ -c main.c - -$(TMP_DIR)/ctype.o: $(TMP_DIR) - $(CC) $(CFLAGS) -o $@ -c ctype.c - -$(TMP_DIR)/stdio.o: $(TMP_DIR) - $(CC) $(CFLAGS) -o $@ -c stdio.c - -$(OUT_DIR): - mkdir -p $(OUT_DIR) - -$(TMP_DIR): - mkdir -p $(TMP_DIR) - -clean: - rm -rf $(OUT_FILE) $(OBJ_FILES) - diff --git a/ase/utl/makefile.msw.bcc b/ase/utl/makefile.msw.bcc deleted file mode 100644 index 15423bc2..00000000 --- a/ase/utl/makefile.msw.bcc +++ /dev/null @@ -1,31 +0,0 @@ -OUT = aseutl - -C_SRCS = main.c ctype.c stdio.c -C_OBJS = $(C_SRCS:.c=.obj) - -CC = bcc32 -LD = ilink32 -AR = tlib - -CFLAGS = -O2 -WM -WU -RT- -w -q -I../.. -DNDEBUG - -LDFLAGS = -Tpd -ap -Gn -c -q -STARTUP = c0d32w.obj -LIBS = import32.lib cw32mt.lib -JNI_LIBS = $(LIBS) $(OUT).lib - -all: lib - -lib: $(C_OBJS) - $(AR) $(OUT).lib @&&! -+-$(**: = &^ -+-) -! - -clean: - -del $(OBJS) $(OUT).lib *.obj - -.SUFFIXES: .c .obj -.c.obj: - $(CC) $(CFLAGS) -c $< - diff --git a/ase/utl/makefile.msw.cl b/ase/utl/makefile.msw.cl deleted file mode 100644 index 69ec534e..00000000 --- a/ase/utl/makefile.msw.cl +++ /dev/null @@ -1,23 +0,0 @@ -OUT = aseutl - -C_SRCS = main.c ctype.c stdio.c -C_OBJS = $(C_SRCS:.c=.obj) - -CC = cl -LD = link - -CFLAGS = /nologo /O2 /MT /W3 /GR- /Za -I../.. -DNDEBUG - -all: lib - -lib: $(C_OBJS) - $(LD) /lib @<< -/nologo /out:$(OUT).lib $(C_OBJS) -<< - -clean: - del $(OBJS) $(OUT).lib *.obj - -.SUFFIXES: .c .obj -.c.obj: - $(CC) $(CFLAGS) /c $< diff --git a/ase/utl/stdio.c b/ase/utl/stdio.c deleted file mode 100644 index e5525fa6..00000000 --- a/ase/utl/stdio.c +++ /dev/null @@ -1,366 +0,0 @@ -/* - * $Id: stdio.c,v 1.1.1.1 2007/03/28 14:05:30 bacon Exp $ - * - * {License} - */ - -#include -#include - -#include -#include -#include - -#ifndef PATH_MAX -#define PATH_MAX 2048 -#endif - -#if defined(_WIN32) - -int ase_vsprintf (ase_char_t* buf, size_t size, const ase_char_t* fmt, va_list ap) -{ - int n; - - n = _vsntprintf (buf, size, fmt, ap); - if (n < 0 || (size_t)n >= size) - { - if (size > 0) buf[size-1] = ASE_T('\0'); - n = -1; - } - - return n; -} - -int ase_sprintf (ase_char_t* buf, size_t size, const ase_char_t* fmt, ...) -{ - int n; - va_list ap; - - va_start (ap, fmt); - n = ase_vsprintf (buf, size, fmt, ap); - va_end (ap); - return n; -} - -#else - -static ase_char_t* __adjust_format (const ase_char_t* format); - -int ase_vfprintf (FILE *stream, const ase_char_t* fmt, va_list ap) -{ - int n; - ase_char_t* nf = __adjust_format (fmt); - if (nf == NULL) return -1; - -#ifdef ASE_CHAR_IS_MCHAR - n = vfprintf (stream, nf, ap); -#else - n = vfwprintf (stream, nf, ap); -#endif - free (nf); - return n; -} - -int ase_vprintf (const ase_char_t* fmt, va_list ap) -{ - return ase_vfprintf (stdout, fmt, ap); -} - -int ase_fprintf (FILE* file, const ase_char_t* fmt, ...) -{ - int n; - va_list ap; - - va_start (ap, fmt); - n = ase_vfprintf (file, fmt, ap); - va_end (ap); - return n; -} - -int ase_printf (const ase_char_t* fmt, ...) -{ - int n; - va_list ap; - - va_start (ap, fmt); - n = ase_vprintf (fmt, ap); - va_end (ap); - return n; -} - -int ase_vsprintf (ase_char_t* buf, size_t size, const ase_char_t* fmt, va_list ap) -{ - int n; - ase_char_t* nf = __adjust_format (fmt); - if (nf == NULL) return -1; - -#if defined(ASE_CHAR_IS_MCHAR) - n = vsnprintf (buf, size, nf, ap); -#elif defined(_WIN32) - n = _vsnwprintf (buf, size, nf, ap); -#else - n = vswprintf (buf, size, nf, ap); -#endif - if (n < 0 || (size_t)n >= size) - { - if (size > 0) buf[size-1] = ASE_T('\0'); - n = -1; - } - - free (nf); - return n; -} - -int ase_sprintf (ase_char_t* buf, size_t size, const ase_char_t* fmt, ...) -{ - int n; - va_list ap; - - va_start (ap, fmt); - n = ase_vsprintf (buf, size, fmt, ap); - va_end (ap); - return n; -} - -#define MOD_SHORT 1 -#define MOD_LONG 2 -#define MOD_LONGLONG 3 - -#define ADDC(buf,c) \ - do { \ - if (buf.len >= buf.cap) \ - { \ - ase_char_t* tmp; \ - tmp = (ase_char_t*)realloc ( \ - buf.ptr, sizeof(ase_char_t)*(buf.cap+256+1)); \ - if (tmp == NULL) \ - { \ - free (buf.ptr); \ - return NULL; \ - } \ - buf.ptr = tmp; \ - buf.cap = buf.cap + 256; \ - } \ - buf.ptr[buf.len++] = c; \ - } while (0) - -static ase_char_t* __adjust_format (const ase_char_t* format) -{ - const ase_char_t* fp = format; - int modifier; - ase_char_t ch; - - struct - { - ase_char_t* ptr; - ase_size_t len; - ase_size_t cap; - } buf; - - buf.len = 0; - buf.cap = 256; -#if (defined(vms) || defined(__vms)) && (ASE_SIZEOF_VOID_P >= 8) - buf.ptr = (ase_char_t*) _malloc32 (sizeof(ase_char_t)*(buf.cap+1)); -#else - buf.ptr = (ase_char_t*) malloc (sizeof(ase_char_t)*(buf.cap+1)); -#endif - if (buf.ptr == NULL) return NULL; - - while (*fp != ASE_T('\0')) - { - while (*fp != ASE_T('\0') && *fp != ASE_T('%')) - { - ADDC (buf, *fp++); - } - - if (*fp == ASE_T('\0')) break; - - ch = *fp++; - ADDC (buf, ch); /* add % */ - - ch = *fp++; - - /* flags */ - while (1) - { - if (ch == ASE_T(' ') || ch == ASE_T('+') || - ch == ASE_T('-') || ch == ASE_T('#')) - { - ADDC (buf, ch); - ch = *fp++; - } - else - { - if (ch == ASE_T('0')) - { - ADDC (buf, ch); - ch = *fp++; - } - - break; - } - } - - /* check the width */ - if (ch == ASE_T('*')) - { - ADDC (buf, ch); - ch = *fp++; - } - else - { - while (ase_isdigit(ch)) - { - ADDC (buf, ch); - ch = *fp++; - } - } - - /* precision */ - if (ch == ASE_T('.')) - { - ADDC (buf, ch); - ch = *fp++; - - if (ch == ASE_T('*')) - { - ADDC (buf, ch); - ch = *fp++; - } - else - { - while (ase_isdigit(ch)) - { - ADDC (buf, ch); - ch = *fp++; - } - } - } - - /* modifier */ - for (modifier = 0;;) - { - if (ch == ASE_T('h')) modifier = MOD_SHORT; - else if (ch == ASE_T('l')) - { - modifier = (modifier == MOD_LONG)? MOD_LONGLONG: MOD_LONG; - } - else break; - ch = *fp++; - } - - - /* type */ - if (ch == ASE_T('%')) ADDC (buf, ch); - else if (ch == ASE_T('c') || ch == ASE_T('s')) - { -#if !defined(ASE_CHAR_IS_MCHAR) && !defined(_WIN32) - ADDC (buf, 'l'); -#endif - ADDC (buf, ch); - } - else if (ch == ASE_T('C') || ch == ASE_T('S')) - { -#ifdef _WIN32 - ADDC (buf, ch); -#else - #ifdef ASE_CHAR_IS_MCHAR - ADDC (buf, 'l'); - #endif - ADDC (buf, ase_tolower(ch)); -#endif - } - else if (ch == ASE_T('d') || ch == ASE_T('i') || - ch == ASE_T('o') || ch == ASE_T('u') || - ch == ASE_T('x') || ch == ASE_T('X')) - { - if (modifier == MOD_SHORT) - { - ADDC (buf, 'h'); - } - else if (modifier == MOD_LONG) - { - ADDC (buf, 'l'); - } - else if (modifier == MOD_LONGLONG) - { -#if defined(_WIN32) && !defined(__LCC__) - ADDC (buf, 'I'); - ADDC (buf, '6'); - ADDC (buf, '4'); -#else - ADDC (buf, 'l'); - ADDC (buf, 'l'); -#endif - } - ADDC (buf, ch); - } - else if (ch == ASE_T('\0')) break; - else ADDC (buf, ch); - } - - buf.ptr[buf.len] = ASE_T('\0'); - - return buf.ptr; -} - -#endif - -int ase_dprintf (const ase_char_t* fmt, ...) -{ - int n; - va_list ap; - - va_start (ap, fmt); - n = ase_vfprintf (stderr, fmt, ap); - va_end (ap); - return n; -} - -FILE* ase_fopen (const ase_char_t* path, const ase_char_t* mode) -{ -#if defined(_WIN32) - return _tfopen (path, mode); -#elif defined(ASE_CHAR_IS_MCHAR) - return fopen (path, mode); -#else - - char path_mb[PATH_MAX + 1]; - char mode_mb[32]; - size_t n; - - n = wcstombs (path_mb, path, ASE_COUNTOF(path_mb)); - if (n == (size_t)-1) return NULL; - if (n == ASE_COUNTOF(path_mb)) path_mb[ASE_COUNTOF(path_mb)-1] = '\0'; - - n = wcstombs (mode_mb, mode, ASE_COUNTOF(mode_mb)); - if (n == (size_t)-1) return NULL; - if (n == ASE_COUNTOF(mode_mb)) path_mb[ASE_COUNTOF(mode_mb)-1] = '\0'; - - return fopen (path_mb, mode_mb); -#endif -} - -FILE* ase_popen (const ase_char_t* cmd, const ase_char_t* mode) -{ -#if defined(_WIN32) - return _tpopen (cmd, mode); -#elif defined(ASE_CHAR_IS_MCHAR) - return popen (cmd, mode); -#else - char cmd_mb[PATH_MAX + 1]; - char mode_mb[32]; - size_t n; - - n = wcstombs (cmd_mb, cmd, ASE_COUNTOF(cmd_mb)); - if (n == (size_t)-1) return NULL; - if (n == ASE_COUNTOF(cmd_mb)) cmd_mb[ASE_COUNTOF(cmd_mb)-1] = '\0'; - - n = wcstombs (mode_mb, mode, ASE_COUNTOF(mode_mb)); - if (n == (size_t)-1) return NULL; - if (n == ASE_COUNTOF(mode_mb)) cmd_mb[ASE_COUNTOF(mode_mb)-1] = '\0'; - - return popen (cmd_mb, mode_mb); -#endif -} - diff --git a/ase/utl/stdio.h b/ase/utl/stdio.h deleted file mode 100644 index d7923676..00000000 --- a/ase/utl/stdio.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * $Id: stdio.h,v 1.1.1.1 2007/03/28 14:05:30 bacon Exp $ - */ - -#ifndef _ASE_UTL_STDIO_H_ -#define _ASE_UTL_STDIO_H_ - -#include -#include - -#include -#include -#include - -#if defined(_WIN32) - #include - - #define ase_printf _tprintf - #define ase_vprintf _vtprintf - #define ase_fprintf _ftprintf - #define ase_vfprintf _vftprintf - - #define ase_fgets _fgetts - #define ase_fgetc _fgettc -#elif defined(ASE_CHAR_IS_MCHAR) - #define ase_fgets fgets - #define ase_fgetc fgetc -#else - #define ase_fgets fgetws - #define ase_fgetc fgetwc -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -int ase_vsprintf (ase_char_t* buf, size_t size, const ase_char_t* fmt, va_list ap); -int ase_sprintf (ase_char_t* buf, size_t size, const ase_char_t* fmt, ...); - -#if !defined(WIN32) -int ase_vfprintf (FILE *stream, const ase_char_t* fmt, va_list ap); -int ase_vprintf (const ase_char_t* fmt, va_list ap); -int ase_fprintf (FILE* file, const ase_char_t* fmt, ...); -int ase_printf (const ase_char_t* fmt, ...); -#endif - -int ase_dprintf (const ase_char_t* fmt, ...); -FILE* ase_fopen (const ase_char_t* path, const ase_char_t* mode); -FILE* ase_popen (const ase_char_t* cmd, const ase_char_t* mode); - -#ifdef __cplusplus -} -#endif - -#endif