fixed some build file flaws

This commit is contained in:
2022-09-25 02:08:01 +09:00
parent a828f82670
commit 9efdf82b16
204 changed files with 1160 additions and 91 deletions

63
t/Makefile.am Normal file
View File

@ -0,0 +1,63 @@
AUTOMAKE_OPTIONS = nostdinc
CPPFLAGS_COMMON = \
-I$(abs_builddir) \
-I$(abs_builddir)/../lib \
-I$(abs_srcdir) \
-I$(abs_srcdir)/../lib \
-I$(includedir)
CFLAGS_COMMON =
LDFLAGS_COMMON=-L$(abs_builddir)/../lib -L$(libdir)
## place $(LIBM) here as all programs below are C only programs linked
## against the C/C++ hybrid library. Read comments in ../bin/Makefile.am
## for more information.
LIBADD_COMMON = ../lib/libhawk.la $(LIBM)
check_SCRIPTS = h-001.hawk h-002.hawk h-003.hawk h-009.hawk
##noinst_SCRIPTS = $(check_SCRIPTS)
EXTRA_DIST = $(check_SCRIPTS) ensure.inc \
journal-toc.hawk journal-toc.in journal-toc.out journal-toc-html.out \
bibtex-to-html.hawk bibtex-to-html.out
check_PROGRAMS = t-001 t-002 t-003 t-004 t-005 t-006
t_001_SOURCES = t-001.c tap.h
t_001_CPPFLAGS = $(CPPFLAGS_COMMON)
t_002_SOURCES = t-002.c tap.h
t_002_CPPFLAGS = $(CPPFLAGS_COMMON)
t_002_CFLAGS = $(CFLAGS_COMMON)
t_002_LDFLAGS = $(LDFLAGS_COMMON)
t_002_LDADD = $(LIBADD_COMMON)
t_003_SOURCES = t-003.c tap.h
t_003_CPPFLAGS = $(CPPFLAGS_COMMON)
t_003_CFLAGS = $(CFLAGS_COMMON)
t_003_LDFLAGS = $(LDFLAGS_COMMON)
t_003_LDADD = $(LIBADD_COMMON)
t_004_SOURCES = t-004.c tap.h
t_004_CPPFLAGS = $(CPPFLAGS_COMMON)
t_004_CFLAGS = $(CFLAGS_COMMON)
t_004_LDFLAGS = $(LDFLAGS_COMMON)
t_004_LDADD = $(LIBADD_COMMON)
t_005_SOURCES = t-005.c tap.h
t_005_CPPFLAGS = $(CPPFLAGS_COMMON)
t_005_CFLAGS = $(CFLAGS_COMMON)
t_005_LDFLAGS = $(LDFLAGS_COMMON)
t_005_LDADD = $(LIBADD_COMMON)
t_006_SOURCES = t-006.c tap.h
t_006_CPPFLAGS = $(CPPFLAGS_COMMON)
t_006_CFLAGS = $(CFLAGS_COMMON)
t_006_LDFLAGS = $(LDFLAGS_COMMON)
t_006_LDADD = $(LIBADD_COMMON)
LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) $(top_srcdir)/ac/tap-driver.sh
TESTS = $(check_PROGRAMS) $(check_SCRIPTS)
TEST_EXTENSIONS = .hawk
HAWK_LOG_DRIVER = $(LOG_DRIVER)
HAWK_LOG_COMPILER = ../bin/hawk
AM_HAWK_LOG_FLAGS = -vTDIR=${abs_srcdir} --modlibdirs=../lib/.libs:../mod/.libs -f

1239
t/Makefile.in Normal file

File diff suppressed because it is too large Load Diff

546
t/bibtex-to-html.hawk Normal file
View File

@ -0,0 +1,546 @@
# http://www.netlib.org/bibnet/tools/software/bibtex-to-html.awk
#
### ====================================================================
### @Awk-file{
### author = "Nelson H. F. Beebe",
### version = "1.02",
### date = "05 July 1997",
### time = "12:04:52 MDT",
### filename = "bibtex-to-html.awk",
### address = "Center for Scientific Computing
### Department of Mathematics
### University of Utah
### Salt Lake City, UT 84112
### USA",
### telephone = "+1 801 581 5254",
### FAX = "+1 801 581 4148",
### URL = "http://www.math.utah.edu/~beebe",
### checksum = "08699 482 2173 18348",
### email = "beebe@math.utah.edu (Internet)",
### codetable = "ISO/ASCII",
### keywords = "bibliography, BibTeX, HTML, World-Wide Web,
### WWW",
### supported = "yes",
### docstring = "This program converts BibTeX bibliographies
### to HTML, suitable for viewing on the
### World-Wide Web.
###
### The level of HTML produced is version 3.2,
### adopted 14-Jan-1997, and defined in the SGML
### document type definition (DTD) available at
###
### http://www.w3.org/MarkUp/Wilbur/HTML32.dtd
###
### and documented at
###
### http://www.w3.org/MarkUp/Wilbur/
### http://www.w3.org/TR/REC-html32.html
###
### HTML markup is added to provide hypertext
### links for:
###
### * all URLs in the BibTeX file, both in
### comments, and inside string values;
### * all bibliography entry crossref
### values;
### * all \cite{} references;
### * all @String{name = "value"} names.
###
### In addition, every BibTeX citation label in
### @Entry lines, and every @String name, will
### be marked as an HTML label, allowing
### hypertext links to each from elsewhere in
### the same HTML file, or from other HTML
### files. In particular, every bibliography
### entry can be directly referenced by
### hypertext links from anywhere on the
### Internet.
###
### Each such linkable-name will be displayed
### in bold text to draw attention to the fact
### that it can be directly referenced by a
### suitable URL. In principle, this should be
### an option that WWW browsers provide, but
### none that I have used currently do.
###
### Although no browsers to my knowledge yet
### provide the capability of partial
### downloading of HTML files, the possibility
### has been discussed for future versions of
### the HTTP protocol. Such support would make
### it possible to construct bibliographies in
### electronic documents as links to large
### bibliography database files, without the
### browser having to load the entire database,
### but just individual entries. Since these
### in turn can have URLs that point to other
### electronic sources of the publication, a
### reader could easily follow links from a
### publication to a bibliography and then to
### abstracts and to the complete original
### text. Some journals, such as the Digital
### Technical Journal (electronically accessible
### at http://www.digital.com:80/info/DTJ/home.html),
### already could offer this possibility.
###
### The Web browser user will see material that
### looks just like normal BibTeX entries,
### except that some portions may be
### highlighted to indicate hypertext links.
### However, window cut-and-paste actions will
### recover a BibTeX entry in a form suitable
### for pasting into another BibTeX file,
### without any need for further editing.
###
### This program assumes that the BibTeX
### bibliography is formatted in the style
### produced by bibclean, and that embedded
### URLs and "key = stringname" pairs are coded
### on a single line, so that simple pattern
### matching suffices to recognize text in need
### of additional HTML markup.
###
### Usage:
### nawk -f bibtex-to-html.awk \
### [-v PREFIX=prefix] [-v SUFFIX=suffix] \
### BibTeX-file(s)
###
### An input file with a filename of the form
### abc.xyz is output to a file named
### PREFIXabcSUFFIX. The default PREFIX is
### empty, and the default SUFFIX is ".html".
###
### If no file names are specified on the
### command line, then the PREFIX and SUFFIX
### settings are ignored, and input is read
### from stdin, and output is written to
### stdout, so that the program can be used in
### a UNIX pipeline.
###
### In the current version, no provision is
### made for splitting the output files into
### smaller pieces to speed network file
### transfer. While this would improve browser
### responsiveness over slow network
### connections, it would also significantly
### complicate hypertext link generation for
### this program, and seriously damage browser
### search capability within the bibliography
### file. Perhaps the solution will come in
### (a) browsers' adopting the netscape browser
### practice of displaying data as soon as
### enough to fill a screen is available, and
### (b) faster network connections.
###
### In the TUG bibliography collection at
### ftp://ftp.math.utah.edu/, bibliography
### file sizes range from 3K to 4700K, with an
### average of 370K. These are rather large,
### since typical WWW file sizes need to be
### about 16K or less for good responsiveness.
###
### The checksum field above contains a CRC-16
### checksum as the first value, followed by the
### equivalent of the standard UNIX wc (word
### count) utility output of lines, words, and
### characters. This is produced by Robert
### Solovay's checksum utility.",
### }
### ====================================================================
BEGIN \
{
######################################################################
VERSION = "1.02 [05-Jul-1997]" # <-- NB: Change this with each update!
######################################################################
PROGRAM = "bibtex-to-html"
UNSET_FILENAME = "/dev/unset"
LASTFILENAME = UNSET_FILENAME
_last_input_filename = UNSET_FILENAME
if (SUFFIX == "")
SUFFIX = ".html"
USER = ENVIRON["USER"]
if (USER == "")
USER = ENVIRON["LOGNAME"]
if (USER == "")
USER = "????"
"hostname" | getline HOSTNAME
"date" | getline DATE
# [01-Aug-2019] ypcat no longer available: replace by getent
# ("ypcat passwd | grep '^" USER ":' | awk -F: '{print $5}'") | getline PERSONAL_NAME
("getent passwd " USER " | " ARGV[0] " -F: '{print $5}'") | getline PERSONAL_NAME
if (PERSONAL_NAME == "")
##("grep '^" USER ":' /etc/passwd | awk -F: '{print $5}'") | getline PERSONAL_NAME
("grep '^" USER ":' /etc/passwd | " ARGV[0] " -F: '{print $5}'") | getline PERSONAL_NAME
# NB: " has become &#34; before this pattern is used
CROSSREF_EQUALS_LABEL_PATTERN = "^[ \t]*crossref[ \t]*=[ \t]*&#34;"
# Pattern to match a line like this:
# %%% email = "beebe at math.utah.edu (Internet)",
BIBTEX_EMAIL_PATTERN = "= &#34;[A-Za-z0-9-]+ at [A-Za-z0-9.-]+"
BIBTEX_EMAIL_OFFSET = 7 # was 8 before &quot; became &#34;
BIBTEX_EMAIL_PREFIX = "mailto:"
BIBTEX_EMAIL_SAVE_LABEL = 0
##CITE_PATTERN = "\\\\cite{[^}]+}"
CITE_PATTERN = "\\\\cite\\{[^\\}]+}"
CITE_OFFSET = 6
CITE_PREFIX = ""
CITE_SAVE_LABEL = 1
EMAIL_PATTERN = "[A-Za-z0-9-]+@[A-Za-z0-9.-]+"
EMAIL_OFFSET = 0
EMAIL_PREFIX = "mailto:"
EMAIL_SAVE_LABEL = 0
# See Nelson H. F. Beebe, ``Bibliography prettyprinting
# and syntax checking'', TUGboat 14(3), 222-222, October
# (1993), and 14(4), 395--419, December (1993) for the
# syntax of BibTeX names used here in ENTRY_PATTERN,
# KEY_EQUALS_NAME_PATTERN and STRING_PATTERN.
##ENTRY_PATTERN = "^[ \t]*@[ \t]*[A-Za-z][A-Za-z0-9:.+/'-]*[ \t]*{[A-Za-z][A-Za-z0-9:.+/'-]*,[ \t]*$"
ENTRY_PATTERN = "^[ \t]*@[ \t]*[A-Za-z][A-Za-z0-9:.+/'-]*[ \t]*\\{[A-Za-z][A-Za-z0-9:.+/'-]*,[ \t]*$"
KEY_EQUALS_NAME_PATTERN = "^[ \t]*[A-Za-z][A-Za-z0-9:.+/'-]*[ \t]*=[ \t]*[A-Za-z]"
##STRING_PATTERN = "^@[Ss][Tt][Rr][Ii][Nn][gG]{[A-Za-z][A-Za-z0-9:.+/'-]*"
STRING_PATTERN = "^@[Ss][Tt][Rr][Ii][Nn][gG]\\{[A-Za-z][A-Za-z0-9:.+/'-]*"
STRING_OFFSET = 8
STRING_PREFIX = ""
STRING_SAVE_LABEL = 1
# According to Internet RFC 1614 (May 1994), a URL is
# defined in the document T. Berners-Lee, ``Uniform
# Resource Locators'', March 1993, available at URL
# ftp://info.cern.ch/pub/ietf/url4.ps. Unfortunately,
# that address is no longer valid. However, I was able to
# track down pointers from http://www.w3.org/ to locate a
# suitable description in Internet RFC 1630 (June 1994).
# NB: We additionally disallow & in a URL because it is
# needed in SGML entities "&name;". We also disallow =
# and | because these are commonly used in \path=...= and
# \path|...| strings in BibTeX files. These restrictions
# could be removed if we went to the trouble of first
# encoding these special characters in %xy hexadecimal
# format, but they are rare enough that I am not going to
# do so for now. The worst that will happen from this
# decision is that an occasional URL in a BibTeX file will
# be missing a surrounding anchor.
URL_PATTERN = "[A-Za-z]+://[^ \",&=|]+"
URL_OFFSET = 0
URL_PREFIX = ""
URL_SAVE_LABEL = 0
# [24-May-2016] support for background coloring of block comments
IN_BLOCK_COMMENT = 0
}
# Each line receives identical processing.
{ do_line() }
END \
{
if (LASTFILENAME != UNSET_FILENAME)
end_file(LASTFILENAME)
}
function add_entry(array,value)
{
if (value in array)
array[value] = array[value] " " FNR
else
array[value] = FNR
}
function anchor(s,type,pattern,offset,prefix,save_label, name,rstart,rlength)
{
# Add anchors <A type="....">...</A> around text in s matching
# pattern. A non-zero offset discards that many characters from
# the start of the match, allowing the pattern to contain leading
# context which goes outside the anchored region. The prefix is
# attached to the start of the matched string, inside the value
# quotes in the anchor.
if (match(s,pattern))
{
rstart = RSTART # need private copies of these globals because
rlength = RLENGTH # recursion will change them
rstart += offset # adjust by offset to discard leading
rlength -= offset # context in pattern
name = substr(s,rstart,rlength)
sub(/ +at +/,"@",name) # reduce "user at host" to "user@host"
s = substr(s,1,rstart-1) \
"<A " type "=\"" prefix name "\">" \
((type == "NAME") ? "<STRONG>" : "") \
substr(s,rstart,rlength) \
((type == "NAME") ? "</STRONG>" : "") \
"</A>" \
anchor(substr(s,rstart+rlength),type,pattern,offset,prefix,save)
if (save_label)
{
if (type == "HREF")
add_entry(label_hrefs, name)
else if (type == "NAME")
add_entry(label_names, name)
}
}
return (s)
}
function begin_file( f)
{
f = output_filename(FILENAME)
## NB: If Transitional is eliminated in DOCTYPE, background coloring is lost! Why?
slash_pos = str::rindex(FILENAME, "/");
BASE_FILENAME = (slash_pos > 0)? str::substr(FILENAME, slash_pos + 1): FILENAME;
print "<!-- -*-html-*- -->" > f
print "" > f
## print "<!-- " FILENAME " -->" > f
print "<!-- " BASE_FILENAME " -->" > f
print "<!-- WARNING: Do NOT edit this file. It was converted from -->" > f
print "<!-- BibTeX format to HTML by " PROGRAM " version " VERSION " -->" > f
## print "<!-- on " DATE " -->" > f
## print "<!-- for " PERSONAL_NAME " (" USER "@" HOSTNAME ") -->" > f
print "" > f
print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/1998/REC-html40-19980424/loose.dtd\">" > f
print "" > f
print "" > f
print "<HTML>" > f
print " <HEAD>" > f
print " <META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=iso-8859-1\">"> f
print " <TITLE>" > f
## print " BibTeX bibliography " FILENAME > f
print " BibTeX bibliography " BASE_FILENAME > f
print " </TITLE>" > f
## print " <LINK REV=\"made\" HREF=\"mailto:" USER "@" HOSTNAME "\">" > f
print " <LINK HREF=\"http://www.math.utah.edu/pub/tex/bib/tugbib.css\" TYPE=\"text/css\" REL=\"stylesheet\">" > f
print " </HEAD>" > f
print "" > f
print " <BODY>" > f
print " <DIV ALIGN=\"right\">" > f
print " <A HREF=\"http://validator.w3.org/check/referer\">" > f
print " <IMG ALIGN=\"MIDDLE\" BORDER=\"0\" SRC=\"/images/valid-html40.png\" ALT=\"Valid HTML 4.0!\" HEIGHT=\"31\" WIDTH=\"88\">" > f
print " </A>" > f
print " <A HREF=\"http://jigsaw.w3.org/css-validator/check/referer\">" > f
print " <IMG ALIGN=\"MIDDLE\" BORDER=\"0\" SRC=\"/images/valid-css.gif\" ALT=\"Valid CSS!\" HEIGHT=\"31\" WIDTH=\"88\">" > f
print " </A>" > f
print " </DIV>" > f
print "<PRE>" > f
clear_array(label_names)
clear_array(label_hrefs)
}
function check_for_file_change()
{
if (LASTFILENAME != FILENAME)
{
if (LASTFILENAME != UNSET_FILENAME)
{
end_file(LASTFILENAME)
if (LASTFILENAME != "/dev/stdout")
close (output_filename(LASTFILENAME))
}
LASTFILENAME = FILENAME
begin_file()
}
}
function check_refs( label)
{
for (label in label_hrefs)
{
if (!(label in label_names))
warning("undefined label " label " at line(s) " label_hrefs[label])
}
}
function clear_array(array, key)
{
for (key in array)
delete array[key]
}
function end_file(filename, f)
{
f = output_filename(filename)
print "</PRE>" > f
print " </BODY>" > f
print "</HTML>" > f
check_refs()
}
function do_cite(s, k,n,labels,t)
{
n = split(substr(s,RSTART + CITE_OFFSET,RLENGTH - 1 - CITE_OFFSET),labels,",")
t = substr(s,1,RSTART+CITE_OFFSET-1)
for (k = 1; k <= n; ++k)
{
t = t ((k > 1) ? "," : "") "<A HREF=\"#" labels[k] "\">" labels[k] "</A>"
add_entry(label_hrefs, labels[k])
}
t = t substr(s,RSTART + RLENGTH - 1)
return (t)
}
function do_line( n,name,s)
{
s = protect_SGML_characters($0)
if (match(s,STRING_PATTERN)) # remember name from @String{name = "value"}
{
name = substr(s,RSTART + STRING_OFFSET,RLENGTH - STRING_OFFSET)
string_name[name] = 1
# print "DEBUG 1: name =", name >"/dev/stderr"
}
if (match(s,/^%+[ \t]*email[ \t]*=/)) # special handling because BibTeX does not allow @ in comments
s = anchor(s,"HREF",BIBTEX_EMAIL_PATTERN,BIBTEX_EMAIL_OFFSET,BIBTEX_EMAIL_PREFIX,\
BIBTEX_EMAIL_SAVE_LABEL)
else
s = anchor(s,"HREF",EMAIL_PATTERN,EMAIL_OFFSET,EMAIL_PREFIX,EMAIL_SAVE_LABEL)
s = anchor(s,"HREF",URL_PATTERN,URL_OFFSET,URL_PREFIX,URL_SAVE_LABEL)
s = anchor(s,"NAME",STRING_PATTERN,STRING_OFFSET,STRING_PREFIX,STRING_SAVE_LABEL)
if (match(s,CITE_PATTERN))
s = do_cite(s)
if (match(s,ENTRY_PATTERN)) # then have ``@Entry{label,''
{
n = index(s,"{")
name = substr(s,n+1)
gsub(/^[ \t]*/,"",name) # trim optional leading space
gsub(/,[ \t]*$/,"",name) # trim trailing comma and optional space
# print "DEBUG 2: name =", name >"/dev/stderr"
s = substr(s,1,n) \
"<A NAME=\"" name "\"><STRONG>" name "</STRONG></A>" \
substr(s,n+1+length(name))
add_entry(label_names, name)
}
else if (match(s,KEY_EQUALS_NAME_PATTERN)) # then have ``key = name''
{
name = substr(s,RSTART+RLENGTH-1)
sub(/,?[ \t]*$/,"",name) # trim optional trailing comma and space
# print "DEBUG 3: name =", name >"/dev/stderr"
if (name in string_name) # then we have a definition of this name
{
s = substr(s,1,RSTART+RLENGTH-2) \
"<A HREF=\"#" name "\">" name "</A>" substr(s,RSTART+RLENGTH-1+length(name))
add_entry(label_hrefs, name)
}
}
else if (match(s,CROSSREF_EQUALS_LABEL_PATTERN)) # then have `` crossref = "label"''
{
name = substr(s,RSTART+RLENGTH)
sub(/&#34;,?[ \t]*$/,"",name) # trim trailing quote and optional comma and space
# print "DEBUG 4: name =", name >"/dev/stderr"
s = substr(s,1,RSTART+RLENGTH-1) \
"<A HREF=\"#" name "\">" name "</A>" substr(s,RSTART+RLENGTH+length(name))
add_entry(label_hrefs, name)
}
check_for_file_change()
if ( (s ~ "^%") && !IN_BLOCK_COMMENT)
{
printf("</PRE><PRE CLASS=\"blockcomment\">") > output_filename(FILENAME)
IN_BLOCK_COMMENT = 1
}
else if ( (s !~ "^%") && IN_BLOCK_COMMENT)
{
printf("</PRE><PRE>") > output_filename(FILENAME)
IN_BLOCK_COMMENT = 0
}
print s >output_filename(FILENAME)
}
function output_filename(input_filename)
{
## HAWK - for use in t/h-003.hawk
if (length(T_OUT_NAME) > 0) return T_OUT_NAME;
## END HAWK
if (input_filename != _last_input_filename)
{ # optimization: we cache last function result for speed
_last_input_filename = input_filename
sub(/.[^.]*$/,"",input_filename)
if ((input_filename == "") || (input_filename == "/dev/stdin"))
_last_output_filename = "/dev/stdout"
else
_last_output_filename = PREFIX input_filename SUFFIX
}
return (_last_output_filename)
}
function protect_SGML_characters(s)
{
gsub(/&/,"\\&amp;",s) # NB: this one MUST be first
gsub(/</,"\\&lt;",s)
gsub(/>/,"\\&gt;",s)
## [24-May-2016] with the change from HTML 3.2 to 4.0, we can use &quot; again!
## gsub(/\"/,"\\&#34;",s) # this was &quot; in earlier HTML
# versions, including the HTML 3.2
# draft, but was stupidly eliminated in
# the final HTML 3.2 version: see
# http://www.w3.org/pub/WWW/MarkUp/Wilbur/
# in the section ``What happened to &quot;?''
gsub(/\"/,"\\&quot;",s)
return (s)
}
function warning(message)
{
# print FILENAME ":" FNR ":%%" message >"/dev/stderr"
#
# The only place that we need warning messages above is
# checkrefs(), after the current file has been closed, and a new
# one started, so we need LASTFILENAME instead of FILENAME here,
# and we omit the FNR, since we have no record of it for
# LASTFILENAME.
print LASTFILENAME ":%%" message >"/dev/stderr"
}

27251
t/bibtex-to-html.out Normal file

File diff suppressed because it is too large Load Diff

315
t/h-001.hawk Normal file
View File

@ -0,0 +1,315 @@
@pragma entry main
@pragma implicit off
@include "tap.inc";
function f(a, b, c)
{
return a + b + c;
}
function call_by_ref_1(&a, b, &c)
{
c = "hello, world";
return b * a;
}
function call_by_ref_2(a, &b)
{
b[1] = b[1] * a;
b[2] = "perfect";
return a;
}
function call_by_ref_3(&x)
{
x = "hello world";
}
function main()
{
{
tap_ensure (@b"" !== "", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (@b"" === "", 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (@b"" != "", 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (@b"" == "", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (@b' ' !== ' ', 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (@b' ' === ' ', 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (@b' ' != ' ', 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (@b' ' == ' ', 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((@nil == 'A'), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((@nil != 'A'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((@nil > 'A'), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((@nil < 'A'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((@nil >= 'A'), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((@nil <= 'A'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((@nil == @b'A'), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((@nil != @b'A'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((@nil > @b'A'), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((@nil < @b'A'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((@nil >= @b'A'), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((@nil <= @b'A'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (('A' == @b'A'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (('\u00FF' == @b'\xFF'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (('A' < @b'\xFF'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((@b'A' < @b'\xFF'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (('A' > @b'\xFF'), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((@b'A' > @b'\xFF'), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (('A' < @b'B'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((@b'A' < @b'B'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (('A' > @b'B'), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((@b'A' > @b'B'), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (("10" == 10), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (("10" == 10.00), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (("10.0" == 10), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (("10.00" == 10), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((@b"10" == 10), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((@b"10" == 10.00), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((@b"10.0" == 10), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((@b"10.00" == 10), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((79 < '8'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((79 <= '8'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((79 > '8'), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((79 >= '8'), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((79 == '8'), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((79 != '8'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((99 < '8'), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((99 <= '8'), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((99 > '8'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((99 >= '8'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((99 == '8'), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((99 != '8'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((8 < '8'), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((8 <= '8'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((8 > '8'), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((8 >= '8'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((8 == '8'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((8 != '8'), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((8.00 < '8'), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((8.00 <= '8'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((8.00 > '8'), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((8.00 >= '8'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((8.00 == '8'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((8.00 != '8'), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((79 < @b'8'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((79 <= @b'8'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((79 > @b'8'), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((79 >= @b'8'), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((79 == @b'8'), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((79 != @b'8'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((99 < @b'8'), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((99 <= @b'8'), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((99 > @b'8'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((99 >= @b'8'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((99 == @b'8'), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((99 != @b'8'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((8 < @b'8'), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((8 <= @b'8'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((8 > @b'8'), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((8 >= @b'8'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((8 == @b'8'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((8 != @b'8'), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((8.00 < @b'8'), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((8.00 <= @b'8'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((8.00 > @b'8'), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((8.00 >= @b'8'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((8.00 == @b'8'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((8.00 != @b'8'), 0, @SCRIPTNAME, @SCRIPTLINE);
}
{
@local x, y, z, r;
x = 20;
y = 90;
r = call_by_ref_1(x, y, z);
tap_ensure (r, 1800, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (x, 20, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (y, 90, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (z, "hello, world", @SCRIPTNAME, @SCRIPTLINE);
}
## TODO: add a new special word, @FILENAME, @FILELINE, @LINE <--- which are understood by the parser and swapped to the actual value
## @SCRIPTNAME, @SCRIPTLINE doesn't tell the main file.
{
@local b;
call_by_ref_2(99, b);
tap_ensure (b[1], 0, @SCRIPTNAME, @SCRIPTLINE);
}
{
@local b, r;
b[1] = 1;
r = call_by_ref_2(99, b);
tap_ensure (r, 99, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (b[1], 99, @SCRIPTNAME, @SCRIPTLINE);
}
{
@local b, r;
b[1] = 1;
r = hawk::call("call_by_ref_2", 99, b);
tap_ensure (r, 99, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (length(b), 2, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (b[1], 99, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (b[2], "perfect", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (hawk::call('f', 1, 2, 3), 6, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (hawk::call("f", 1, 2, 3), 6, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (hawk::call(@b'f', 1, 2, 3), 6, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (hawk::call(@b"f", 1, 2, 3), 6, @SCRIPTNAME, @SCRIPTLINE);
}
{
@local a;
a[1] = hawk::array();
a[1][2]=20;
tap_ensure (a[1][2], 20, @SCRIPTNAME, @SCRIPTLINE);
a[1][2]++;
tap_ensure (a[1][2], 21, @SCRIPTNAME, @SCRIPTLINE);
--a[1][2];
tap_ensure (a[1][2], 20, @SCRIPTNAME, @SCRIPTLINE);
}
{
@local a, nil;
a = hawk::array();
a[10] = "good";
a[0][40] = "bye"
a[0][0] = "farewell"
tap_ensure (hawk::typename(a), "array", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (hawk::typename(a[0]), "array", @SCRIPTNAME, @SCRIPTLINE);
call_by_ref_3(a[9]);
tap_ensure (a[10], "good", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[9], "hello world", @SCRIPTNAME, @SCRIPTLINE);
call_by_ref_3(a[10]);
tap_ensure (a[10], "hello world", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[9], "hello world", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[0][40], "bye", @SCRIPTNAME, @SCRIPTLINE);
call_by_ref_3(a[0][40]);
tap_ensure (a[0][40], "hello world", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (length(a[0]), 2, @SCRIPTNAME, @SCRIPTLINE);
delete a[0][40];
tap_ensure (length(a[0]), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[0][0], "farewell", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[0][40], nil, @SCRIPTNAME, @SCRIPTLINE);
#hawk::splice (a[0], 40, 1, @SCRIPTNAME, @SCRIPTLINE);
#tap_ensure (length(a[0]), 40, @SCRIPTNAME, @SCRIPTLINE);
}
{
@local a, i;
a = hawk::array();
tap_ensure (length(a), 0, @SCRIPTNAME, @SCRIPTLINE);
for (i = 0; i < 10; i++) a[i*i]=i;
tap_ensure (length(a), 10, @SCRIPTNAME, @SCRIPTLINE);
delete a[0];
tap_ensure (length(a), 9, @SCRIPTNAME, @SCRIPTLINE);
delete a[81];
tap_ensure (length(a), 8, @SCRIPTNAME, @SCRIPTLINE);
delete a[36];
tap_ensure (length(a), 7, @SCRIPTNAME, @SCRIPTLINE);
for (i = 0; i < 10; i++) delete a[i*i];
tap_ensure (length(a), 0, @SCRIPTNAME, @SCRIPTLINE);
delete a;
tap_ensure (length(a), 0, @SCRIPTNAME, @SCRIPTLINE);
}
{
@local a, b, c;
a = hawk::array();
a[10][20][30] = 20;
b[12][20][30] = 20;
tap_ensure ((10 in a) && (20 in a[10]) && (30 in a[10][20]), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((11 in a) && (20 in a[10]) && (30 in a[10][20]), 0, @SCRIPTNAME, @SCRIPTLINE);
b = hawk::map();
b[10][20][30] = 20;
b[12][20][30] = 20;
tap_ensure ((10 in a) && (20 in a[10]) && (30 in a[10][20]), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((11 in a) && (20 in a[10]) && (30 in a[10][20]), 0, @SCRIPTNAME, @SCRIPTLINE);
c = hawk::map();
c[10,20,30] = "heloo";
tap_ensure (((10,20,30) in c), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (((10,30,30) in c), 0, @SCRIPTNAME, @SCRIPTLINE);
}
{
@local a;
a = hawk::array(1,2,3);
tap_ensure (a[1], 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[2], 2, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[3], 3, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (length(a), 3, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (hawk::typename(a), "array", @SCRIPTNAME, @SCRIPTLINE);
}
{
# concatenation operator
tap_ensure ((@b"hawk" 10) === @b"hawk10", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (("hawk" 10) === "hawk10", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((@b"hawk" "hawk") === @b"hawkhawk", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (("hawk" @b"hawk") === "hawkhawk", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((@b"hawk" '1') === @b"hawk1", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (("hawk" '1') === "hawk1", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (('*' @b"hawk" '1') === "*hawk1", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (('*' "hawk" '1') === "*hawk1", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((@b"hawk" '⚾') === @b"hawk\xe2\x9a\xbe", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (("hawk" '⚾') === "hawk⚾", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((@b"hawk" str::fromcharcode(0x26be)) === @b"hawk\xe2\x9a\xbe", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (("hawk" str::fromcharcode(0x26be)) === "hawk⚾", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((@b"hawk" @b'\xFF') === @b"hawk\xFF", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((str::subchar(@b"\xFF\xFE", 1) str::subchar(@b"\xFF\xFE", 2)) === @b"\xFF\xFE", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((@b"hawk" %% 10) === @b"hawk10", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (("hawk" %% 10) === "hawk10", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((@b"hawk" %% "hawk") === @b"hawkhawk", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (("hawk" %% @b"hawk") === "hawkhawk", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((@b"hawk" %% '1') === @b"hawk1", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (("hawk" %% '1') === "hawk1", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (('*' %% @b"hawk" %% '1') === "*hawk1", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (('*' %% "hawk" %% '1') === "*hawk1", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((@b"hawk" %% '⚾') === @b"hawk\xe2\x9a\xbe", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (("hawk" %% '⚾') === "hawk⚾", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((@b"hawk" %% str::fromcharcode(0x26be)) === @b"hawk\xe2\x9a\xbe", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (("hawk" %% str::fromcharcode(0x26be)) === "hawk⚾", 1, @SCRIPTNAME, @SCRIPTLINE);
}
tap_end ();
}

588
t/h-002.hawk Normal file
View File

@ -0,0 +1,588 @@
@pragma entry main
@pragma implicit off
@include "tap.inc";
function main()
{
## call by reference. change an argument to array in the callee
{
@local ini, foo1, foo2, foo3, foo4;
test1(foo1);
test2(foo2);
test3(foo3);
test4(foo4);
tap_ensure (hawk::typename(foo1), "map", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (hawk::typename(foo2), "map", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (hawk::typename(foo3), "nil", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (hawk::typename(foo4), "nil", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (foo1[1], 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (foo2[1], 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (foo3[1], ini, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (foo4[1], ini, @SCRIPTNAME, @SCRIPTLINE);
}
## gsub
{
@local w, x, y, z, z1, z2;
x = y = "x\\y";
gsub(/\\\\/, "A", x);
gsub("\\\\", "A", y);
tap_ensure (x, "x\\y", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (y, "xAy", @SCRIPTNAME, @SCRIPTLINE);
x = y = "x\\y";
gsub(/\\\\/, 'A', x);
gsub("\\\\", 'A', y);
tap_ensure (x, "x\\y", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (y, "xAy", @SCRIPTNAME, @SCRIPTLINE);
x = y = "x\\\\y";
gsub(/\\\\/, "A", x);
gsub("\\\\", "A", y);
tap_ensure (x, "xAy", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (y, "xAAy", @SCRIPTNAME, @SCRIPTLINE);
x = y = @b"x\\\\y";
gsub(/\\\\/, "A", x);
gsub("\\\\", "A", y);
tap_ensure (x === @b"xAy", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (y === @b"xAAy", 1, @SCRIPTNAME, @SCRIPTLINE);
x = y = @b"x\\\\y";
gsub(/\\\\/, 'A', x);
gsub("\\\\", 'A', y);
tap_ensure (x === @b"xAy", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (y === @b"xAAy", 1, @SCRIPTNAME, @SCRIPTLINE);
x = y = "x\\\\y";
gsub(/\\\\/, @b'A', x);
gsub("\\\\", @b'A', y);
tap_ensure (x === "xAy", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (y === "xAAy", 1, @SCRIPTNAME, @SCRIPTLINE);
x = y = "x\\\\y";
gsub(/\\\\/, @b"A", x);
gsub("\\\\", @b"A", y);
tap_ensure (x === "xAy", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (y === "xAAy", 1, @SCRIPTNAME, @SCRIPTLINE);
x = y = '\\';
gsub(/\\/, @b"A", x);
gsub("\\\\", @b"A", y);
tap_ensure (x === "A", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (y === "A", 1, @SCRIPTNAME, @SCRIPTLINE);
x = y = '\\';
gsub(/\\/, @b'A', x);
gsub("\\\\", @b'A', y);
tap_ensure (x === "A", 1, @SCRIPTNAME, @SCRIPTLINE);
x = y = @b'\\';
gsub(/\\/, @b"A", x);
gsub("\\\\", @b"A", y);
tap_ensure (x === @b"A", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (y === @b"A", 1, @SCRIPTNAME, @SCRIPTLINE);
x = y = @b'\\';
gsub(/\\/, @b'A', x);
gsub("\\\\", @b'A', y);
tap_ensure (x === @b"A", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (y === @b"A", 1, @SCRIPTNAME, @SCRIPTLINE);
}
## gsub - POSIX rule for &, \&, \\&, \\\&
{
@local w, x, y, z, z1, z2, z3;
w = x = y = z = z1 = z2 = "xax";
gsub(/a/, "\&", w); # gsub sees &
gsub(/a/, "\\&", x); # gsub sees \&
gsub(/a/, "\\\&", y); # gsub sees \&
gsub(/a/, "\\\\&", z); # gsub sees \\&
gsub(/a/, "\\\\\&", z1); # gsub sees \\&
gsub(/a/, "\\\\\\&", z2); # gsub sees \\\&
tap_ensure (w, "xax", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (x, "x&x", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (y, "x&x", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (z, "x\\ax", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (z1, "x\\ax", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (z2, "x\\&x", @SCRIPTNAME, @SCRIPTLINE);
w = x = y = z = z1 = z2 = "xaax";
gsub(/a/, "\&", w); # gsub sees &
gsub(/a/, "\\&", x); # gsub sees \&
gsub(/a/, "\\\&", y); # gsub sees \&
gsub(/a/, "\\\\&", z); # gsub sees \\&
gsub(/a/, "\\\\\&", z1); # gsub sees \\&
gsub(/a/, "\\\\\\&", z2); # gsub sees \\\&
tap_ensure (w, "xaax", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (x, "x&&x", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (y, "x&&x", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (z, "x\\a\\ax", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (z1, "x\\a\\ax", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (z2, "x\\&\\&x", @SCRIPTNAME, @SCRIPTLINE);
}
## gsub - POSIX rule for &, \&, \\&, \\\& - express the same test with a raw string literal
{
@local w, x, y, z;
w = x = y = z = "xax";
gsub(/a/, @r"&", w); # gsub sees &
gsub(/a/, @r"\&", x); # gsub sees \&
gsub(/a/, @r"\\&", y); # gsub sees \\&
gsub(/a/, @r"\\\&", z); # gsub sees \\\&
tap_ensure (w, "xax", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (x, "x&x", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (y, @r"x\ax", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (z, @r"x\&x", @SCRIPTNAME, @SCRIPTLINE);
w = x = y = z = "xaax";
gsub(/a/, @r"&", w); # gsub sees &
gsub(/a/, @r"\&", x); # gsub sees \&
gsub(/a/, @r"\\&", y); # gsub sees \\&
gsub(/a/, @r"\\\&", z); # gsub sees \\\&
tap_ensure (w, "xaax", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (x, "x&&x", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (y, @r"x\a\ax", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (z, @r"x\&\&x", @SCRIPTNAME, @SCRIPTLINE);
}
## sub - POSIX rule for &, \&, \\&, \\\& - express the same test with a raw string literal
{
@local w, x, y, z;
w = x = y = z = "xax";
sub(/a/, @r"&", w);
sub(/a/, @r"\&", x);
sub(/a/, @r"\\&", y);
sub(/a/, @r"\\\&", z);
tap_ensure (w, "xax", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (x, "x&x", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (y, @r"x\ax", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (z, @r"x\&x", @SCRIPTNAME, @SCRIPTLINE);
w = x = y = z = "xaax";
sub(/a/, @r"&", w);
sub(/a/, @r"\&", x);
sub(/a/, @r"\\&", y);
sub(/a/, @r"\\\&", z);
tap_ensure (w, "xaax", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (x, "x&ax", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (y, @r"x\aax", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (z, @r"x\&ax", @SCRIPTNAME, @SCRIPTLINE);
}
{
@local pi, e, tmp;
pi = 3.1415927;
tap_ensure (sprintf("%.10d:%.10x", 5, 14), "0000000005:000000000e", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf("cos(%f) = %f", pi/4, cos(pi/4)), "cos(0.785398) = 0.707107", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf("sin(%f) = %f", pi/4, sin(pi/4)), "sin(0.785398) = 0.707107", @SCRIPTNAME, @SCRIPTLINE);
e = exp(1);
tap_ensure (sprintf("e = %f", e), "e = 2.718282", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf("log(e) = %f", log(e)), "log(e) = 1.000000", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf("sqrt(pi ^ 2) = %f", sqrt(pi ^ 2)), "sqrt(pi ^ 2) = 3.141593", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf("atan2(1, 1) = %f", atan2(1, 1)), "atan2(1, 1) = 0.785398", @SCRIPTNAME, @SCRIPTLINE);
tmp = sprintf("%s", "hello");
tap_ensure ((tmp === @b"hello"), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((tmp === "hello"), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((tmp == @b"hello"), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((tmp == "hello"), 1, @SCRIPTNAME, @SCRIPTLINE);
tmp = sprintf("%s", @b"hello");
tap_ensure ((tmp === @b"hello"), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((tmp === "hello"), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((tmp == @b"hello"), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((tmp == "hello"), 1, @SCRIPTNAME, @SCRIPTLINE);
tmp = sprintf(@b"%s", "hello");
tap_ensure ((tmp === @b"hello"), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((tmp === "hello"), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((tmp == @b"hello"), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((tmp == "hello"), 1, @SCRIPTNAME, @SCRIPTLINE);
tmp = sprintf(@b"%s", @b"hello");
tap_ensure ((tmp === @b"hello"), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((tmp === "hello"), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((tmp == @b"hello"), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure ((tmp == "hello"), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf("%0d", 0), "0", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf("%0.d", 0), "", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf("%.d", 0), "", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf("%.*d", 0, 0), "", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf("%.*d", 1, 0), "0", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf("%*d", 0, 0), "0", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf("%*.*d", 0, 0, 0), "", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf("%-*.*d", 0, 0, 0), "", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf("%*.*d", 1, 0, 0), " ", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf("%*.*d", 0, 3, 0), "000", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf("%-*d", 0, 0), "0", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf(@b"%0d", 0), @b"0", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf(@b"%0.d", 0), @b"", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf(@b"%.d", 0), @b"", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf(@b"%.*d", 0, 0), @b"", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf(@b"%.*d", 1, 0), @b"0", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf(@b"%*d", 0, 0), @b"0", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf(@b"%*.*d", 0, 0, 0), @b"", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf(@b"%-*.*d", 0, 0, 0), @b"", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf(@b"%*.*d", 1, 0, 0), @b" ", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf(@b"%*.*d", 0, 3, 0), @b"000", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf(@b"%-*d", 0, 0), @b"0", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf("%5d", 5), " 5", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf("%-5d", 5), "5 ", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf("%*d", 5, 5), " 5", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf("%*d", -5, 5), "5 ", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf("%-*d", 5, 5), "5 ", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf("%-*d", -5, 5), "5 ", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf(@b"%5d", 5), @b" 5", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf(@b"%-5d", 5), @b"5 ", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf(@b"%*d", 5, 5), @b" 5", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf(@b"%*d", -5, 5), @b"5 ", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf(@b"%-*d", 5, 5), @b"5 ", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf("%*sworld", 20, "hello"), " helloworld", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf("%*sworld", -20, "hello"), "hello world", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf("%-*sworld", 20, "hello"), "hello world", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf("%-*sworld", -20, "hello"), "hello world", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf(@b"%*sworld", 20, "hello"), @b" helloworld", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf(@b"%*sworld", -20, "hello"), @b"hello world", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf(@b"%-*sworld", 20, "hello"), @b"hello world", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf(@b"%-*sworld", -20, "hello"), @b"hello world", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf("%0s", "hello"), "hello", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf("%.0s", "hello"), "", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf("%0.0s", "hello"), "", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf("%1.0s", "hello"), " ", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf("%*.*s", 20, 0, "hello"), " ", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf("%*.*s", 20, 2, "hello"), " he", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf(@b"%0s", "hello"), @b"hello", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf(@b"%.0s", "hello"), @b"", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf(@b"%0.0s", "hello"), @b"", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf(@b"%1.0s", "hello"), @b" ", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf(@b"%*.*s", 20, 0, "hello"), @b" ", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf(@b"%*.*s", 20, 2, "hello"), @b" he", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf("%+d %d", 3, 4), "+3 4", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf(@b"%+d %d", 3, 4), @b"+3 4", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf(@b'A') === @b"A", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (sprintf('A') === "A", 1, @SCRIPTNAME, @SCRIPTLINE);
}
{
@local bool, b, c;
tap_ensure ((c === @nil), 1, @SCRIPTNAME, @SCRIPTLINE); ## tap_ensure local variable initialization
bool = ((b = 1) in c);
tap_ensure (bool, 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (b, 1, @SCRIPTNAME, @SCRIPTLINE);
}
{
tap_ensure (substr(1000+"5000", 2) === "000", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (substr(1000+"10000", 2) === "1000", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (substr(1000+"5000", 2) === "000", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (substr("5000" + 1000, 2) === "000", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (substr("10000" + 1000, 2) === "1000", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (substr("5000" + 1000, 2) === "000", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (substr(@b"5000" + 1000, 2) === "000", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (substr(@b"10000" + 1000, 2) === "1000", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (substr(@b"5000" + 1000, 2) === "000", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (substr(@b"5000", 2) === @b"000", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (substr(@b"10000", 2) === @b"0000", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (substr(@b"5000", 2) === @b"000", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (substr(1000+5000, 2) === "000", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (substr(1000+10000, 2) === "1000", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (substr(1000+5000, 2) === "000", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::subchar("abc", -1) === @nil, 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::subchar("abc", 0) === @nil, 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::subchar("abc", 1) === 'a', 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::subchar("abc", 2) === 'b', 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::subchar("abc", 3) === 'c', 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::subchar("abc", 4) === @nil, 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::subchar("☕⛄", -1) === @nil, 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::subchar("☕⛄", 0) === @nil, 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::subchar("☕⛄", 1) === '☕', 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::subchar("☕⛄", 2) === '⛄', 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::subchar("☕⛄", 3) === @nil, 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::subchar("☕⛄", 4) === @nil, 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::subchar(@b"abc", -1) === @nil, 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::subchar(@b"abc", 0) === @nil, 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::subchar(@b"abc", 1) === @b'a', 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::subchar(@b"abc", 2) === @b'b', 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::subchar(@b"abc", 3) === @b'c', 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::subchar(@b"abc", 4) === @nil, 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::subchar('a', 0) === @nil, 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::subchar('a', 1) === 'a', 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::subchar('a', 2) === @nil, 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::subchar(@b'a', 0) === @nil, 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::subchar(@b'a', 1) === @b'a', 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::subchar(@b'a', 2) === @nil, 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::subchar(123, 0) === @nil, 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::subchar(123, 1) === '1', 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::subchar(123, 2) === '2', 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::subchar(123, 3) === '3', 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::subchar(123, 4) === @nil, 1, @SCRIPTNAME, @SCRIPTLINE);
}
{
tap_ensure (str::substr("☕Q⛄", 0) === "☕Q⛄", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::substr("☕Q⛄", 1) === "☕Q⛄", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::substr("☕Q⛄", 2) === "Q⛄", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::substr("☕Q⛄", 3) === "⛄", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::substr("☕Q⛄", 4) === "", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::substr("☕Q⛄", 1, 2) === "☕Q", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::substr("☕Q⛄", 1, 4) === "☕Q⛄", 1, @SCRIPTNAME, @SCRIPTLINE);
###tap_ensure (str::substr("☕Q⛄", -1, 1) === "⛄", 1, @SCRIPTNAME, @SCRIPTLINE); ## not supported yet
tap_ensure (str::substr('☕', 1, 4) === "☕", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::substr(@b"\xAD\xAA\xBB\CC", 2, 2) === @b"\xAA\xBB", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::substr(@b'\xAD', 1, 1) === @b"\xAD", 1, @SCRIPTNAME, @SCRIPTLINE);
}
{
tap_ensure (str::index("☕Q⛄X⛄Z", '⛄'), 3, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::index("☕Q⛄X⛄Z", "⛄"), 3, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::index("☕Q⛄X⛄Z", "Q⛄"), 2, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::rindex("☕Q⛄X⛄Z", '⛄'), 5, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::rindex("☕Q⛄X⛄Z", "⛄"), 5, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::rindex("☕Q⛄X⛄Z", "Q⛄"), 2, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::rindex("☕Q⛄X⛄Z", "Q⛄Q"), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::index(@b"\xFFQ\xABX\xABZ", @b'\xAB'), 3, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::index(@b"\xFFQ\xABX\xABZ", @b"\xAB"), 3, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::index(@b"\xFFQ\xABX\xABZ", @b"Q\xAB"), 2, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::rindex(@b"\xFFQ\xABX\xABZ", @b'\xAB'), 5, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::rindex(@b"\xFFQ\xABX\xABZ", @b"\xAB"), 5, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::rindex(@b"\xFFQ\xABX\xABZ", @b"Q\xAB"), 2, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::rindex(@b"\xFFQ\xABX\xABZ", @b"Q\xABQ"), 0, @SCRIPTNAME, @SCRIPTLINE);
}
{
# split, str::split, str::splita
@local a, str;
tap_ensure (split("Here===Is=Some=====Data", a, "=+"), 4, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[1] === "Here", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[2] === "Is", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[3] === "Some", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[4] === "Data", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (split(@b"Here===Is=Some=====Data", a, @b"=+"), 4, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[1] === @b"Here", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[2] === @b"Is", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[3] === @b"Some", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[4] === @b"Data", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (split(@b"Here===Is=Some=====Data", a, /=+/), 4, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[1] === @b"Here", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[2] === @b"Is", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[3] === @b"Some", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[4] === @b"Data", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (split("[Here] : [Is] : [So\\]me] :[Da:ta]", a, "?:\\[]"), 4, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[1] === "Here", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[2] === "Is", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[3] === "So]me", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[4] === "Da:ta", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (split(@b"[Here] : [Is] : [So\\]me] :[Da:ta]", a, "?:\\[]"), 4, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[1] === @b"Here", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[2] === @b"Is", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[3] === @b"So]me", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[4] === @b"Da:ta", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (split("Here===Is=Some=====Data", a, ""), 23, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (hawk::typename(a), "map", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::splita("Here===Is=Some=====Data", a, ""), 23, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (hawk::typename(a), "array",@SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::split("Here Is Some Data", a, / /), 7, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::split("Here Is Some Data", a, " "), 4, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[1] === "Here", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[2] === "Is", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[3] === "Some", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[4] === "Data", 1, @SCRIPTNAME, @SCRIPTLINE);
str = "a b\t\tc d";
tap_ensure (str::splita(str, a, " "), 4, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[1], "a", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[2], "b", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[3], "c", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[4], "d", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::splita(str, a, / /), 5, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[1], "a", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[2], "", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[3], "", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[4], "b\t\tc", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[5], "d", @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::split('a', a, /a/), 2, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[1] === "", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[2] === "", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::split('a', a, 'a'), 2, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[1] === "", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[2] === "", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::split('a', a, @b'a'), 2, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[1] === "", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[2] === "", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::split(@b'a', a, /a/), 2, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[1] === @b"", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[2] === @b"", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::split(@b'a', a, @b'a'), 2, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[1] === @b"", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (a[2] === @b"", 1, @SCRIPTNAME, @SCRIPTLINE);
}
{
## back reference in a regular expression
tap_ensure (("a2b" ~ /(a)\12b/), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (("aa2b" ~ /(a)\12b/), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (("aaa2b" ~ /(a)\12b/), 1, @SCRIPTNAME, @SCRIPTLINE);
}
{
## character class functions in the str modules
tap_ensure (str::isalnum('a'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::isalpha('a'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::isblank('a'), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::iscntrl('a'), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::isdigit('a'), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::isgraph('a'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::islower('a'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::isprint('a'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::ispunct('a'), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::isspace('a'), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::isupper('a'), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::isxdigit('a'), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::toupper('a') === 'A', 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::tolower('A') === 'a', 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::isalnum("a"), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::isalpha("a"), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::isblank("a"), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::iscntrl("a"), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::isdigit("a"), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::isgraph("a"), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::islower("a"), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::isprint("a"), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::ispunct("a"), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::isspace("a"), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::isupper("a"), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::isxdigit("a"), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::toupper("abc") === "ABC", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::tolower("ABC") === "abc", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::toupper(@b"abc") === @b"ABC", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::tolower(@b"ABC") === @b"abc", 1, @SCRIPTNAME, @SCRIPTLINE);
}
{
tap_ensure (str::tocharcode(@b'\xFF'), 0xFF, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::tocharcode('\u3321'), 0x3321, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::tocharcode(@b'\xFF', 0), @nil, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::tocharcode('\u3321', 0), @nil, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::tocharcode(@b'\xFF', 1), 0xFF, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::tocharcode('\u3321', 1), 0x3321, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::tocharcode(@b'\xFF', 2), @nil, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::tocharcode('\u3321', 2), @nil, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::tocharcode(str::fromcharcode('2')), 2, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::tonum('a', 16), 10, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::fromcharcode(65, 66, 67) === "ABC", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::frombcharcode(65, 66, 67) === @b"ABC", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::trim(" hello world ") === "hello world", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::trim(" hello world ", str::TRIM_PAC_SPACES) === "hello world", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::trim(@b" hello world ") === @b"hello world", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (str::trim(@b" hello world ", str::TRIM_PAC_SPACES) === @b"hello world", 1, @SCRIPTNAME, @SCRIPTLINE);
}
{
@local a, b, c, d;
sys::pack(a, ">hhl", 1, 2, 3);
tap_ensure (a === @b"\x00\x01\x00\x02\x00\x00\x00\x00\x00\x00\x00\x03", 1, @SCRIPTNAME, @SCRIPTLINE);
sys::pack(a, ">ci", @b'*', 0x12131415);
tap_ensure (a === @b"*\x12\x13\x14\x15", 1, @SCRIPTNAME, @SCRIPTLINE);
sys::pack(a, ">ic", 0x12131415, @b"*+-");
tap_ensure (a === @b"\x12\x13\x14\x15*", 1, @SCRIPTNAME, @SCRIPTLINE);
sys::pack(a, "3c", @b"*+-", 't', "pack");
tap_ensure (a === @b"*tp", 1, @SCRIPTNAME, @SCRIPTLINE);
sys::unpack (@b"raymond \x32\x12\x08\x01\x08", "<10sHHb", a, b, c, d);
tap_ensure (a === @b"raymond ", 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (b === 4658, 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (c === 264, 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (d === 8, 1, @SCRIPTNAME, @SCRIPTLINE);
sys::unpack (@b"raymond", "3c", a, b, c);
tap_ensure (a === @b'r' , 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (b === @b'a' , 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (c === @b'y' , 1, @SCRIPTNAME, @SCRIPTLINE);
}
tap_end ();
}
function test1(&foo) { test2(foo) }
function test2(&bar) { bar[1] = 1 }
function test3(foo) { test2(foo) }
function test4(bar) { bar[1] = 1 }

86
t/h-003.hawk Normal file
View File

@ -0,0 +1,86 @@
@pragma entry main
@pragma implicit off
@include "tap.inc";
function are_files_identical(a, b)
{
@local f1, f2, x, y, diff;
f1 = sys::open(a, sys::O_RDONLY);
if (f1 <= -1)
{
printf ("ERROR: unable to open %s\n", a);
return -1;
}
f2 = sys::open(b, sys::O_RDONLY);
if (f2 <= -1)
{
sys::close (a);
printf ("ERROR: unable to open %s\n", b);
return -1;
}
diff = 0;
while (sys::read(f1, x, 1) > 0)
{
if (sys::read(f2, y, 1) <= 0 || x !== y)
{
diff = 1;
break;
}
}
if (sys::read(f2, y, 1) > 0) diff = 1;
sys::close (f2);
sys::close (f1);
return !diff;
}
function run_test (x, more_opts, in_name, set_out_name, out_name)
{
@local cmd, inf, expf, outf, same;
if (hawk::isnil(in_name)) in_name = x;
if (hawk::isnil(out_name)) out_name = x;
inf = sprintf("%s/%s.in", TDIR, in_name);
expf = sprintf("%s/%s.out", TDIR, out_name);
outf = sprintf("/tmp/%s.%d.out", out_name, sys::getpid());
##print TDIR, inf, expf, outf;
if (set_out_name)
{
cmd=sprintf("%s %s -vT_OUT_NAME=%s -f %s/%s.hawk --modlibdirs=%s %s", ARGV[0], more_opts, outf, TDIR, x, hawk::modlibdirs(), inf);
}
else
{
cmd=sprintf("%s %s -f %s/%s.hawk --modlibdirs=%s %s > %s", ARGV[0], more_opts, TDIR, x, hawk::modlibdirs(), inf, outf);
}
##print cmd;
system (cmd);
same = are_files_identical(expf, outf);
if (same <= 0)
{
## don't delete the output file for review.
tap_fail (sprintf("%s[%d] %s - %s and %s differ", @SCRIPTNAME, @SCRIPTLINE, x, expf, outf));
}
else
{
tap_ok (sprintf("%s[%d]", @SCRIPTNAME, @SCRIPTLINE));
sys::unlink (outf);
}
}
function main()
{
run_test ("journal-toc", "", @nil, 0, @nil);
run_test ("journal-toc", "-vHTML=1", "journal-toc", 0, "journal-toc-html");
run_test ("bibtex-to-html", "", "journal-toc", 1, "bibtex-to-html");
tap_end ();
}

36
t/h-009.hawk Normal file
View File

@ -0,0 +1,36 @@
@pragma entry main
@pragma implicit off
@include "tap.inc";
function run_test_001 ()
{
@local tmp, out;
tap_ensure (hawk::function_exists(111), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (hawk::function_exists(1.69), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (hawk::function_exists("111"), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (hawk::function_exists(@b"111"), 0, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (hawk::function_exists("length"), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (hawk::function_exists(@b"length"), 1, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (hawk::call(@b"length", "hawk"), 4, @SCRIPTNAME, @SCRIPTLINE);
tap_ensure (hawk::call("length", @b"hawk"), 4, @SCRIPTNAME, @SCRIPTLINE);
if (hawk::function_exists("sed::str_to_str"))
{
tmp = hawk::call("sed::str_to_str", "s/a/j/g", "aaabbbaaacccaaaddd", out);
tap_ensure (out === "jjjbbbjjjcccjjjddd", 1, @SCRIPTNAME, @SCRIPTLINE);
}
else
{
tap_skip (sprintf("sed::str_to_str() is unavailable - %s[%d]", @SCRIPTNAME, @SCRIPTLINE));
}
}
function main()
{
run_test_001 ();
tap_end ();
}

5089
t/journal-toc-html.out Normal file

File diff suppressed because it is too large Load Diff

993
t/journal-toc.hawk Normal file
View File

@ -0,0 +1,993 @@
# http://www.netlib.org/bibnet/tools/software/journal-toc.awk
#
### ====================================================================
### @Awk-file{
### author = "Nelson H. F. Beebe",
### version = "1.00",
### date = "09 October 1996",
### time = "15:57:06 MDT",
### filename = "journal-toc.awk",
### address = "Center for Scientific Computing
### Department of Mathematics
### University of Utah
### Salt Lake City, UT 84112
### USA",
### telephone = "+1 801 581 5254",
### FAX = "+1 801 581 4148",
### URL = "http://www.math.utah.edu/~beebe",
### checksum = "25092 977 3357 26493",
### email = "beebe@math.utah.edu (Internet)",
### codetable = "ISO/ASCII",
### keywords = "BibTeX, bibliography, HTML, journal table of
### contents",
### supported = "yes",
### docstring = "Create a journal cover table of contents from
### <at>Article{...} entries in a journal BibTeX
### .bib file for checking the bibliography
### database against the actual journal covers.
### The output can be either plain text, or HTML.
###
### Usage:
### bibclean -max-width 0 BibTeX-file(s) | \
### bibsort -byvolume | \
### awk -f journal-toc.awk \
### [-v HTML=nnn] [-v INDENT=nnn] \
### [-v BIBFILEURL=url] >foo.toc
###
### or if the bibliography is already sorted
### by volume,
###
### bibclean -max-width 0 BibTeX-file(s) | \
### awk -f journal-toc.awk \
### [-v HTML=nnn] [-v INDENT=nnn] \
### [-v BIBFILEURL=url] >foo.toc
###
### A non-zero value of the command-line option,
### HTML=nnn, results in HTML output instead of
### the default plain ASCII text (corresponding
### to HTML=0). The
###
### The INDENT=nnn command-line option specifies
### the number of blanks to indent each logical
### level of HTML. The default is INDENT=4.
### INDENT=0 suppresses indentation. The INDENT
### option has no effect when the default HTML=0
### (plain text output) option is in effect.
###
### When HTML output is selected, the
### BIBFILEURL=url command-line option provides a
### way to request hypertext links from table of
### contents page numbers to the complete BibTeX
### entry for the article. These links are
### created by appending a sharp (#) and the
### citation label to the BIBFILEURL value, which
### conforms with the practice of
### bibtex-to-html.awk.
###
### The HTML output form may be useful as a more
### compact representation of journal article
### bibliography data than the original BibTeX
### file provides. Of course, the
### table-of-contents format provides less
### information, and is considerably more
### troublesome for a computer program to parse.
###
### When URL key values are provided, they will
### be used to create hypertext links around
### article titles. This supports journals that
### provide article contents on the World-Wide
### Web.
###
### For parsing simplicity, this program requires
### that BibTeX
###
### key = "value"
###
### and
###
### @String{name = "value"}
###
### specifications be entirely contained on
### single lines, which is readily provided by
### the `bibclean -max-width 0' filter. It also
### requires that bibliography entries begin and
### end at the start of a line, and that
### quotation marks, rather than balanced braces,
### delimit string values. This is a
### conventional format that again can be
### guaranteed by bibclean.
###
### This program requires `new' awk, as described
### in the book
###
### Alfred V. Aho, Brian W. Kernighan, and
### Peter J. Weinberger,
### ``The AWK Programming Language'',
### Addison-Wesley (1988), ISBN
### 0-201-07981-X,
###
### such as provided by programs named (GNU)
### gawk, nawk, and recent AT&T awk.
###
### The checksum field above contains a CRC-16
### checksum as the first value, followed by the
### equivalent of the standard UNIX wc (word
### count) utility output of lines, words, and
### characters. This is produced by Robert
### Solovay's checksum utility.",
### }
### ====================================================================
BEGIN { initialize() }
/^ *@ *[Ss][Tt][Rr][Ii][Nn][Gg] *\{/ { do_String(); next }
/^ *@ *[Pp][Rr][Ee][Aa][Mm][Bb][Ll][Ee]/ { next }
/^ *@ *[Aa][Rr][Tt][Ii][Cc][Ll][Ee]/ { do_Article(); next }
/^ *@/ { do_Other(); next }
/^ *author *= *\"/ { do_author(); next }
/^ *journal *= */ { do_journal(); next }
/^ *volume *= *\"/ { do_volume(); next }
/^ *number *= *\"/ { do_number(); next }
/^ *year *= *\"/ { do_year(); next }
/^ *month *= */ { do_month(); next }
/^ *title *= *\"/ { do_title(); next }
/^ *pages *= *\"/ { do_pages(); next }
/^ *URL *= *\"/ { do_URL(); next }
/^ *} *$/ { if (In_Article) do_end_entry(); next }
END { terminate() }
########################################################################
# NB: The programming conventions for variables in this program are: #
# UPPERCASE global constants and user options #
# Initialuppercase global variables #
# lowercase local variables #
# Any deviation is an error! #
########################################################################
function do_Article()
{
In_Article = 1
Citation_label = $0
sub(/^[^\{]*\{/,"",Citation_label)
sub(/ *, *$/,"",Citation_label)
Author = ""
Title = ""
Journal = ""
Volume = ""
Number = ""
Month = ""
Year = ""
Pages = ""
Url = ""
}
function do_author()
{
Author = TeX_to_HTML(get_value($0))
}
function do_end_entry( k,n,parts)
{
n = split(Author,parts," and ")
if (Last_number != Number)
do_new_issue()
for (k = 1; k < n; ++k)
print_toc_line(parts[k] " and", "", "")
Title_prefix = html_begin_title()
Title_suffix = html_end_title()
if (html_length(Title) <= (MAX_TITLE_CHARS + MIN_LEADERS)) # complete title fits on line
print_toc_line(parts[n], Title, html_begin_pages() Pages html_end_pages())
else # need to split long title over multiple lines
do_long_title(parts[n], Title, html_begin_pages() Pages html_end_pages())
}
function do_journal()
{
if ($0 ~ /[=] *"/) # have journal = "quoted journal name",
Journal = get_value($0)
else # have journal = journal-abbreviation,
{
Journal = get_abbrev($0)
if (Journal in String) # replace abbrev by its expansion
Journal = String[Journal]
}
gsub(/\\-/,"",Journal) # remove discretionary hyphens
}
function do_long_title(author,title,pages, last_title,n)
{
title = trim(title) # discard leading and trailing space
while (length(title) > 0)
{
n = html_breakpoint(title,MAX_TITLE_CHARS+MIN_LEADERS)
last_title = substr(title,1,n)
title = substr(title,n+1)
sub(/^ +/,"",title) # discard any leading space
print_toc_line(author, last_title, (length(title) == 0) ? pages : "")
author = ""
}
}
function do_month( k,n,parts)
{
Month = ($0 ~ /[=] *"/) ? get_value($0) : get_abbrev($0)
gsub(/[\"]/,"",Month)
gsub(/ *# *\\slash *# */," / ",Month)
gsub(/ *# *-+ *# */," / ",Month)
n = split(Month,parts," */ *")
Month = ""
for (k = 1; k <= n; ++k)
Month = Month ((k > 1) ? " / " : "") \
((parts[k] in Month_expansion) ? Month_expansion[parts[k]] : parts[k])
}
function do_new_issue()
{
Last_number = Number
if (HTML)
{
if (Last_volume != Volume)
{
Last_volume = Volume
print_line(prefix(2) "<BR>")
}
html_end_toc()
html_begin_issue()
print_line(prefix(2) Journal "<BR>")
}
else
{
print_line("")
print_line(Journal)
}
print_line(strip_html(vol_no_month_year()))
if (HTML)
{
html_end_issue()
html_toc_entry()
html_begin_toc()
}
else
print_line("")
}
function do_number()
{
Number = get_value($0)
}
function do_Other()
{
In_Article = 0
}
function do_pages()
{
Pages = get_value($0)
sub(/--[?][?]/,"",Pages)
}
function do_String()
{
sub(/^[^\{]*\{/,"",$0) # discard up to and including open brace
sub(/\} *$/,"",$0) # discard from optional whitespace and trailing brace to end of line
String[get_key($0)] = get_value($0)
}
function do_title()
{
Title = TeX_to_HTML(get_value($0))
}
function do_URL( parts)
{
Url = get_value($0)
split(Url,parts,"[,;]") # in case we have multiple URLs
Url = trim(parts[1])
}
function do_volume()
{
Volume = get_value($0)
}
function do_year()
{
Year = get_value($0)
}
function get_abbrev(s)
{ # return abbrev from ``key = abbrev,''
sub(/^[^=]*= */,"",s) # discard text up to start of non-blank value
sub(/ *,? *$/,"",s) # discard trailing optional whitspace, quote,
# optional comma, and optional space
return (s)
}
function get_key(s)
{ # return kay from ``key = "value",''
sub(/^ */,"",s) # discard leading space
sub(/ *=.*$/,"",s) # discard everthing after key
return (s)
}
function get_value(s)
{ # return value from ``key = "value",''
sub(/^[^\"]*\" */,"",s) # discard text up to start of non-blank value
sub(/ *\",? *$/,"",s) # discard trailing optional whitspace, quote,
# optional comma, and optional space
return (s)
}
function html_accents(s)
{
if (index(s,"\\") > 0) # important optimization
{
# Convert common lower-case accented letters according to the
# table on p. 169 of in Peter Flynn's ``The World Wide Web
# Handbook'', International Thomson Computer Press, 1995, ISBN
# 1-85032-205-8. The official table of ISO Latin 1 SGML
# entities used in HTML can be found in the file
# /usr/local/lib/html-check/lib/ISOlat1.sgml (your path
# may differ).
gsub(/\{\\\a}/, "\\&agrave;", s)
gsub(/\{\\'a}/, "\\&aacute;", s)
gsub(/\{\\[\^]a}/,"\\&acirc;", s)
gsub(/\{\\~a}/, "\\&atilde;", s)
##gsub(/\{\\\"a\}/, "\\&auml;", s)
gsub(/\{\\\"\{a\}\}/, "\\&auml;", s)
gsub(/\{\\aa}/, "\\&aring;", s)
gsub(/\{\\ae}/, "\\&aelig;", s)
gsub(/\{\\c\{c\}}/,"\\&ccedil;", s)
gsub(/\{\\\e}/, "\\&egrave;", s)
gsub(/\{\\'e}/, "\\&eacute;", s)
gsub(/\{\\[\^]e}/,"\\&ecirc;", s)
gsub(/\{\\\"e}/, "\\&euml;", s)
gsub(/\{\\\i}/, "\\&igrave;", s)
gsub(/\{\\'i}/, "\\&iacute;", s)
gsub(/\{\\[\^]i}/,"\\&icirc;", s)
gsub(/\{\\\"i}/, "\\&iuml;", s)
# ignore eth and thorn
gsub(/\{\\~n}/, "\\&ntilde;", s)
gsub(/\{\\\o}/, "\\&ograve;", s)
gsub(/\{\\'o}/, "\\&oacute;", s)
gsub(/\{\\[\^]o}/, "\\&ocirc;", s)
gsub(/\{\\~o}/, "\\&otilde;", s)
##gsub(/\{\\\"o}/, "\\&ouml;", s)
gsub(/\{\\\"\{o\}}/, "\\&ouml;", s)
gsub(/\{\\o}/, "\\&oslash;", s)
gsub(/\{\\\u}/, "\\&ugrave;", s)
gsub(/\{\\'u}/, "\\&uacute;", s)
gsub(/\{\\[\^]u}/,"\\&ucirc;", s)
##gsub(/\{\\\"u}/, "\\&uuml;", s)
gsub(/\{\\\"\{u\}\}/, "\\&uuml;", s)
gsub(/\{\\'y}/, "\\&yacute;", s)
gsub(/\{\\\"y}/, "\\&yuml;", s)
# Now do the same for upper-case accents
gsub(/\{\\\A}/, "\\&Agrave;", s)
gsub(/\{\\'A}/, "\\&Aacute;", s)
gsub(/\{\\[\^]A}/, "\\&Acirc;", s)
gsub(/\{\\~A}/, "\\&Atilde;", s)
##gsub(/\{\\\"A}/, "\\&Auml;", s)
gsub(/\{\\\"\{A\}\}/, "\\&Auml;", s)
gsub(/\{\\AA}/, "\\&Aring;", s)
gsub(/\{\\AE}/, "\\&AElig;", s)
gsub(/\{\\c\{C\}}/,"\\&Ccedil;", s)
gsub(/\{\\\e}/, "\\&Egrave;", s)
gsub(/\{\\'E}/, "\\&Eacute;", s)
gsub(/\{\\[\^]E}/, "\\&Ecirc;", s)
gsub(/\{\\\"E}/, "\\&Euml;", s)
gsub(/\{\\\I}/, "\\&Igrave;", s)
gsub(/\{\\'I}/, "\\&Iacute;", s)
gsub(/\{\\[\^]I}/, "\\&Icirc;", s)
gsub(/\{\\\"I}/, "\\&Iuml;", s)
# ignore eth and thorn
gsub(/\{\\~N}/, "\\&Ntilde;", s)
gsub(/\{\\\O}/, "\\&Ograve;", s)
gsub(/\{\\'O}/, "\\&Oacute;", s)
gsub(/\{\\[\^]O}/, "\\&Ocirc;", s)
gsub(/\{\\~O}/, "\\&Otilde;", s)
##gsub(/\{\\\"O}/, "\\&Ouml;", s)
gsub(/\{\\\"\{O\}\}/, "\\&Ouml;", s)
gsub(/\{\\O}/, "\\&Oslash;", s)
gsub(/\{\\\U}/, "\\&Ugrave;", s)
gsub(/\{\\'U}/, "\\&Uacute;", s)
gsub(/\{\\[\^]U}/, "\\&Ucirc;", s)
##gsub(/\{\\\"U}/, "\\&Uuml;", s)
gsub(/\{\\\"\{U\}\}/, "\\&Uuml;", s)
gsub(/\{\\'Y}/, "\\&Yacute;", s)
gsub(/\{\\ss}/, "\\&szlig;", s)
# Others not mentioned in Flynn's book
gsub(/\{\\'\\i}/,"\\&iacute;", s)
gsub(/\{\\'\\j}/,"j", s)
}
return (s)
}
function html_begin_issue()
{
print_line("")
print_line(prefix(2) "<HR>")
print_line("")
print_line(prefix(2) "<H1>")
print_line(prefix(3) "<A NAME=\"" html_label() "\">")
}
function html_begin_pages()
{
return ((HTML && (BIBFILEURL != "")) ? ("<A HREF=\"" BIBFILEURL "#" Citation_label "\">") : "")
}
function html_begin_pre()
{
In_PRE = 1
print_line("<PRE>")
}
function html_begin_title()
{
return ((HTML && (Url != "")) ? ("<A HREF=\"" Url "\">") : "")
}
function html_begin_toc()
{
html_end_toc()
html_begin_pre()
}
function html_body( k)
{
for (k = 1; k <= BodyLines; ++k)
print Body[k]
}
function html_breakpoint(title,maxlength, break_after,k)
{
# Return the largest character position in title AFTER which we
# can break the title across lines, without exceeding maxlength
# visible characters.
if (html_length(title) > maxlength) # then need to split title across lines
{
# In the presence of HTML markup, the initialization of
# k here is complicated, because we need to advance it
# until html_length(title) is at least maxlength,
# without invoking the expensive html_length() function
# too frequently. The need to split the title makes the
# alternative of delayed insertion of HTML markup much
# more complicated.
break_after = 0
for (k = min(maxlength,length(title)); k < length(title); ++k)
{
if (substr(title,k+1,1) == " ")
{ # could break after position k
if (html_length(substr(title,1,k)) <= maxlength)
break_after = k
else # advanced too far, retreat back to last break_after
break
}
}
if (break_after == 0) # no breakpoint found by forward scan
{ # so switch to backward scan
for (k = min(maxlength,length(title)) - 1; \
(k > 0) && (substr(title,k+1,1) != " "); --k)
; # find space at which to break title
if (k < 1) # no break point found
k = length(title) # so must print entire string
}
else
k = break_after
}
else # title fits on one line
k = length(title)
return (k)
}
function html_end_issue()
{
print_line(prefix(3) "</A>")
print_line(prefix(2) "</H1>")
}
function html_end_pages()
{
return ((HTML && (BIBFILEURL != "")) ? "</A>" : "")
}
function html_end_pre()
{
if (In_PRE)
{
print_line("</PRE>")
In_PRE = 0
}
}
function html_end_title()
{
return ((HTML && (Url != "")) ? "</A>" : "")
}
function html_end_toc()
{
html_end_pre()
}
function html_fonts(s, arg,control_word,k,level,n,open_brace)
{
open_brace = index(s,"{")
if (open_brace > 0) # important optimization
{
level = 1
for (k = open_brace + 1; (level != 0) && (k <= length(s)); ++k)
{
if (substr(s,k,1) == "{")
level++
else if (substr(s,k,1) == "}")
level--
}
# {...} is now found at open_brace ... (k-1)
for (control_word in Font_decl_map) # look for {\xxx ...}
{
if (substr(s,open_brace+1,length(control_word)+1) ~ \
("\\" control_word "[^A-Za-z]"))
{
n = open_brace + 1 + length(control_word)
arg = trim(substr(s,n,k - n))
if (Font_decl_map[control_word] == "toupper") # arg -> ARG
arg = toupper(arg)
else if (Font_decl_map[control_word] != "") # arg -> <TAG>arg</TAG>
arg = "<" Font_decl_map[control_word] ">" arg "</" Font_decl_map[control_word] ">"
return (substr(s,1,open_brace-1) arg html_fonts(substr(s,k)))
}
}
for (control_word in Font_cmd_map) # look for \xxx{...}
{
if (substr(s,open_brace - length(control_word),length(control_word)) ~ \
("\\" control_word))
{
n = open_brace + 1
arg = trim(substr(s,n,k - n))
if (Font_cmd_map[control_word] == "toupper") # arg -> ARG
arg = toupper(arg)
else if (Font_cmd_map[control_word] != "") # arg -> <TAG>arg</TAG>
arg = "<" Font_cmd_map[control_word] ">" arg "</" Font_cmd_map[control_word] ">"
n = open_brace - length(control_word) - 1
return (substr(s,1,n) arg html_fonts(substr(s,k)))
}
}
}
return (s)
}
function html_header()
{
USER = ENVIRON["USER"]
if (USER == "")
USER = ENVIRON["LOGNAME"]
if (USER == "")
USER = "????"
"hostname" | getline HOSTNAME
"date" | getline DATE
##("ypcat passwd | grep '^" USER ":' | awk -F: '{print $5}'") | getline PERSONAL_NAME
("getent passwd " USER " | awk -F: '{print $5}'") | getline PERSONAL_NAME
if (PERSONAL_NAME == "")
("grep '^" USER ":' /etc/passwd | awk -F: '{print $5}'") | getline PERSONAL_NAME
print "<!-- WARNING: Do NOT edit this file. It was converted from -->"
print "<!-- BibTeX format to HTML by journal-toc.awk version " VERSION_NUMBER " " VERSION_DATE " -->"
##print "<!-- on " DATE " -->"
##print "<!-- for " PERSONAL_NAME " (" USER "@" HOSTNAME ") -->"
print ""
print ""
print "<!DOCTYPE HTML public \"-//IETF//DTD HTML//EN\">"
print ""
print "<HTML>"
print prefix(1) "<HEAD>"
print prefix(2) "<TITLE>"
print prefix(3) Journal
print prefix(2) "</TITLE>"
##print prefix(2) "<LINK REV=\"made\" HREF=\"mailto:" USER "@" HOSTNAME "\">"
print prefix(1) "</HEAD>"
print ""
print prefix(1) "<BODY>"
}
function html_label( label)
{
label = Volume "(" Number "):" Month ":" Year
gsub(/[^A-Za-z0-9():,;.\/\-]/,"",label)
return (label)
}
function html_length(s)
{ # Return visible length of s, ignoring any HTML markup
if (HTML)
{
gsub(/<\/?[^>]*>/,"",s) # remove SGML tags
gsub(/&[A-Za-z0-9]+;/,"",s) # remove SGML entities
}
return (length(s))
}
function html_toc()
{
print prefix(2) "<H1>"
print prefix(3) "Table of contents for issues of " Journal
print prefix(2) "</H1>"
print HTML_TOC
}
function html_toc_entry()
{
HTML_TOC = HTML_TOC " <A HREF=\"#" html_label() "\">"
HTML_TOC = HTML_TOC vol_no_month_year()
HTML_TOC = HTML_TOC "</A><BR>" "\n"
}
function html_trailer()
{
html_end_pre()
print prefix(1) "</BODY>"
print "</HTML>"
}
function initialize()
{
# NB: Update these when the program changes
VERSION_DATE = "[09-Oct-1996]"
VERSION_NUMBER = "1.00"
HTML = (HTML == "") ? 0 : (0 + HTML)
if (INDENT == "")
INDENT = 4
if (HTML == 0)
INDENT = 0 # indentation suppressed in ASCII mode
LEADERS = " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ."
MAX_TITLE_CHARS = 36 # 36 produces a 79-char output line when there is
# just an initial page number. If this is
# increased, the LEADERS string may need to be
# lengthened.
MIN_LEADERS = 4 # Minimum number of characters from LEADERS
# required when leaders are used. The total
# number of characters that can appear in a
# title line is MAX_TITLE_CHARS + MIN_LEADERS.
# Leaders are omitted when the title length is
# between MAX_TITLE_CHARS and this sum.
MIN_LEADERS_SPACE = " " # must be at least MIN_LEADERS characters long
Month_expansion["jan"] = "January"
Month_expansion["feb"] = "February"
Month_expansion["mar"] = "March"
Month_expansion["apr"] = "April"
Month_expansion["may"] = "May"
Month_expansion["jun"] = "June"
Month_expansion["jul"] = "July"
Month_expansion["aug"] = "August"
Month_expansion["sep"] = "September"
Month_expansion["oct"] = "October"
Month_expansion["nov"] = "November"
Month_expansion["dec"] = "December"
Font_cmd_map["\\emph"] = "EM"
Font_cmd_map["\\textbf"] = "B"
Font_cmd_map["\\textit"] = "I"
Font_cmd_map["\\textmd"] = ""
Font_cmd_map["\\textrm"] = ""
Font_cmd_map["\\textsc"] = "toupper"
Font_cmd_map["\\textsl"] = "I"
Font_cmd_map["\\texttt"] = "t"
Font_cmd_map["\\textup"] = ""
Font_decl_map["\\bf"] = "B"
Font_decl_map["\\em"] = "EM"
Font_decl_map["\\it"] = "I"
Font_decl_map["\\rm"] = ""
Font_decl_map["\\sc"] = "toupper"
Font_decl_map["\\sf"] = ""
Font_decl_map["\\tt"] = "TT"
Font_decl_map["\\itshape"] = "I"
Font_decl_map["\\upshape"] = ""
Font_decl_map["\\slshape"] = "I"
Font_decl_map["\\scshape"] = "toupper"
Font_decl_map["\\mdseries"] = ""
Font_decl_map["\\bfseries"] = "B"
Font_decl_map["\\rmfamily"] = ""
Font_decl_map["\\sffamily"] = ""
Font_decl_map["\\ttfamily"] = "TT"
}
function min(a,b)
{
return (a < b) ? a : b
}
function prefix(level)
{
# Return a prefix of up to 60 blanks
if (In_PRE)
return ("")
else
return (substr(" ", \
1, INDENT * level))
}
function print_line(line)
{
if (HTML) # must buffer in memory so that we can accumulate TOC
Body[++BodyLines] = line
else
print line
}
function print_toc_line(author,title,pages, extra,leaders,n,t)
{
# When we have a multiline title, the hypertext link goes only
# on the first line. A multiline hypertext link looks awful
# because of long underlines under the leading indentation.
if (pages == "") # then no leaders needed in title lines other than last one
t = sprintf("%31s %s%s%s", author, Title_prefix, title, Title_suffix)
else # last title line, with page number
{
n = html_length(title) # potentially expensive
extra = n % 2 # extra space for aligned leader dots
if (n <= MAX_TITLE_CHARS) # then need leaders
leaders = substr(LEADERS, 1, MAX_TITLE_CHARS + MIN_LEADERS - extra - \
min(MAX_TITLE_CHARS,n))
else # title (almost) fills line, so no leaders
leaders = substr(MIN_LEADERS_SPACE,1, \
(MAX_TITLE_CHARS + MIN_LEADERS - extra - n))
t = sprintf("%31s %s%s%s%s%s %4s", \
author, Title_prefix, title, Title_suffix, \
(extra ? " " : ""), leaders, pages)
}
Title_prefix = "" # forget any hypertext
Title_suffix = "" # link material
# Efficency note: an earlier version accumulated the body in a
# single scalar like this: "Body = Body t". Profiling revealed
# this statement as the major hot spot, and the change to array
# storage made the program more than twice as fast. This
# suggests that awk might benefit from an optimization of
# "s = s t" that uses realloc() instead of malloc().
if (HTML)
Body[++BodyLines] = t
else
print t
}
function protect_SGML_characters(s)
{
gsub(/&/,"\\&amp;",s) # NB: this one MUST be first
gsub(/</,"\\&lt;",s)
gsub(/>/,"\\&gt;",s)
gsub(/\"/,"\\&quot;",s)
##gsub(/\"/,"\\&#34;",s)
return (s)
}
function strip_braces(s, k)
{ # strip non-backslashed braces from s and return the result
return (strip_char(strip_char(s,"{"),"}"))
}
function strip_char(s,c, k)
{ # strip non-backslashed instances of c from s, and return the result
k = index(s,c)
if (k > 0) # then found the character
{
if (substr(s,k-1,1) != "\\") # then not backslashed char
s = substr(s,1,k-1) strip_char(substr(s,k+1),c) # so remove it (recursively)
else # preserve backslashed char
s = substr(s,1,k) strip_char(s,k+1,c)
}
return (s)
}
function strip_html(s)
{
gsub(/<\/?[^>]*>/,"",s)
return (s)
}
function terminate()
{
if (HTML)
{
html_end_pre()
HTML = 0 # NB: stop line buffering
html_header()
html_toc()
html_body()
html_trailer()
}
}
function TeX_to_HTML(s, k,n,parts)
{
# First convert the four SGML reserved characters to SGML entities
if (HTML)
{
gsub(/>/, "\\&gt;", s)
gsub(/</, "\\&lt;", s)
##gsub(/"/, "\\&quot;", s)
}
gsub(/[$][$]/,"$$",s) # change display math to triple dollars for split
n = split(s,parts,/[$]/)# split into non-math (odd) and math (even) parts
s = ""
for (k = 1; k <= n; ++k) # unbrace non-math part, leaving math mode intact
s = s ((k > 1) ? "$" : "") \
((k % 2) ? strip_braces(TeX_to_HTML_nonmath(parts[k])) : \
TeX_to_HTML_math(parts[k]))
gsub(/[$][$][$]/,"$$",s) # restore display math
if (HTML)
{
gsub(/"/, "\\&quot;", s)
}
return (s)
}
function TeX_to_HTML_math(s)
{
# Mostly a dummy for now, but HTML 3 could support some math translation
gsub(/\\&/,"\\&amp;",s) # reduce TeX ampersands to SGML entities
return (s)
}
function TeX_to_HTML_nonmath(s)
{
if (index(s,"\\") > 0) # important optimization
{
gsub(/\\slash +/,"/",s) # replace TeX slashes with conventional ones
gsub(/ *\\emdash +/," --- ",s) # replace BibNet emdashes with conventional ones
gsub(/\\%/,"%",s) # reduce TeX percents to conventional ones
gsub(/\\[$]/,"$",s) # reduce TeX dollars to conventional ones
gsub(/\\#/,"#",s) # reduce TeX sharps to conventional ones
if (HTML) # translate TeX markup to HTML
{
gsub(/\\&/,"\\&amp;",s) # reduce TeX ampersands to SGML entities
s = html_accents(s)
s = html_fonts(s)
}
else # plain ASCII text output: discard all TeX markup
{
gsub(/\\\&/, "\\&", s) # reduce TeX ampersands to conventional ones
gsub(/\\[a-z][a-z] +/,"",s) # remove TeX font changes
gsub(/\\[^A-Za-z]/,"",s) # remove remaining TeX control symbols
}
}
return (s)
}
function trim(s)
{
gsub(/^[ \t]+/,"",s)
gsub(/[ \t]+$/,"",s)
return (s)
}
function vol_no_month_year()
{
return ("Volume " wrap(Volume) ", Number " wrap(Number) ", " wrap(Month) ", " wrap(Year))
}
function wrap(value)
{
return (HTML ? ("<STRONG>" value "</STRONG>") : value)
}

27220
t/journal-toc.in Normal file

File diff suppressed because it is too large Load Diff

3705
t/journal-toc.out Normal file

File diff suppressed because it is too large Load Diff

156
t/t-001.c Normal file
View File

@ -0,0 +1,156 @@
/* test endian conversion macros */
#include <hawk-utl.h>
#include <stdio.h>
#include "tap.h"
int main ()
{
no_plan();
{
union {
hawk_uint16_t u16;
hawk_uint8_t arr[2];
} x;
x.arr[0] = 0x11;
x.arr[1] = 0x22;
/*
printf("x.u16 = 0x%04x\n", x.u16);
printf("htole16(x.u16) = 0x%04x\n", hawk_htole16(x.u16));
printf("htobe16(x.u16) = 0x%04x\n", hawk_htobe16(x.u16));
*/
OK (x.u16 != hawk_htole16(x.u16) || x.u16 != hawk_htobe16(x.u16), "u16 endian conversion #0");
OK (x.u16 == hawk_le16toh(hawk_htole16(x.u16)), "u16 endian conversion #1");
OK (x.u16 == hawk_be16toh(hawk_htobe16(x.u16)), "u16 endian conversion #2");
OK (x.u16 == hawk_ntoh16(hawk_hton16(x.u16)), "u16 endian conversion #3");
#define X_CONST (0x1122)
OK (X_CONST != HAWK_CONST_HTOLE16(X_CONST) || X_CONST != HAWK_CONST_HTOBE16(X_CONST), "u16 constant endian conversion #0");
OK (X_CONST == HAWK_CONST_LE16TOH(HAWK_CONST_HTOLE16(X_CONST)), "u16 constant endian conversion #1");
OK (X_CONST == HAWK_CONST_BE16TOH(HAWK_CONST_HTOBE16(X_CONST)), "u16 constant endian conversion #2");
OK (X_CONST == HAWK_CONST_NTOH16(HAWK_CONST_HTON16(X_CONST)), "u16 constant endian conversion #3");
#undef X_CONST
}
{
union {
hawk_uint32_t u32;
hawk_uint8_t arr[4];
} x;
x.arr[0] = 0x11;
x.arr[1] = 0x22;
x.arr[2] = 0x33;
x.arr[3] = 0x44;
/*
printf("x.u32 = 0x%08x\n", (unsigned int)x.u32);
printf("htole32(x.u32) = 0x%08x\n", (unsigned int)hawk_htole32(x.u32));
printf("htobe32(x.u32) = 0x%08x\n", (unsigned int)hawk_htobe32(x.u32));
*/
OK (x.u32 != hawk_htole32(x.u32) || x.u32 != hawk_htobe32(x.u32), "u32 endian conversion #0");
OK (x.u32 == hawk_le32toh(hawk_htole32(x.u32)), "u32 endian conversion #1");
OK (x.u32 == hawk_be32toh(hawk_htobe32(x.u32)), "u32 endian conversion #2");
OK (x.u32 == hawk_ntoh32(hawk_hton32(x.u32)), "u32 endian conversion #3");
#define X_CONST (0x11223344)
OK (X_CONST != HAWK_CONST_HTOLE32(X_CONST) || X_CONST != HAWK_CONST_HTOBE32(X_CONST), "u32 constant endian conversion #0");
OK (X_CONST == HAWK_CONST_LE32TOH(HAWK_CONST_HTOLE32(X_CONST)), "u32 constant endian conversion #1");
OK (X_CONST == HAWK_CONST_BE32TOH(HAWK_CONST_HTOBE32(X_CONST)), "u32 constant endian conversion #2");
OK (X_CONST == HAWK_CONST_NTOH32(HAWK_CONST_HTON32(X_CONST)), "u32 constant endian conversion #3");
#undef X_CONST
}
#if defined(HAWK_HAVE_UINT64_T)
{
union {
hawk_uint64_t u64;
hawk_uint8_t arr[8];
} x;
x.arr[0] = 0x11;
x.arr[1] = 0x22;
x.arr[2] = 0x33;
x.arr[3] = 0x44;
x.arr[4] = 0x55;
x.arr[5] = 0x66;
x.arr[6] = 0x77;
x.arr[7] = 0x88;
/*
printf("x.u64 = 0x%016llx\n", (unsigned long long)x.u64);
printf("htole64(x.u64) = 0x%016llx\n", (unsigned long long)hawk_htole64(x.u64));
printf("htobe64(x.u64) = 0x%016llx\n", (unsigned long long)hawk_htobe64(x.u64));
*/
OK (x.u64 != hawk_htole64(x.u64) || x.u64 != hawk_htobe64(x.u64), "u64 endian conversion #0");
OK (x.u64 == hawk_le64toh(hawk_htole64(x.u64)), "u64 endian conversion #1");
OK (x.u64 == hawk_be64toh(hawk_htobe64(x.u64)), "u64 endian conversion #2");
OK (x.u64 == hawk_ntoh64(hawk_hton64(x.u64)), "u64 endian conversion #3");
#define X_CONST (((hawk_uint64_t)0x11223344 << 32) | (hawk_uint64_t)0x55667788)
OK (X_CONST != HAWK_CONST_HTOLE64(X_CONST) || X_CONST != HAWK_CONST_HTOBE64(X_CONST), "u64 constant endian conversion #0");
OK (X_CONST == HAWK_CONST_LE64TOH(HAWK_CONST_HTOLE64(X_CONST)), "u64 constant endian conversion #1");
OK (X_CONST == HAWK_CONST_BE64TOH(HAWK_CONST_HTOBE64(X_CONST)), "u64 constant endian conversion #2");
OK (X_CONST == HAWK_CONST_NTOH64(HAWK_CONST_HTON64(X_CONST)), "u64 constant endian conversion #3");
#undef X_CONST
}
#endif
#if defined(HAWK_HAVE_UINT128_T)
{
union {
hawk_uint128_t u128;
hawk_uint8_t arr[16];
} x;
hawk_uint128_t tmp;
x.arr[0] = 0x11;
x.arr[1] = 0x22;
x.arr[2] = 0x33;
x.arr[3] = 0x44;
x.arr[4] = 0x55;
x.arr[5] = 0x66;
x.arr[6] = 0x77;
x.arr[7] = 0x88;
x.arr[8] = 0x99;
x.arr[9] = 0xaa;
x.arr[10] = 0xbb;
x.arr[11] = 0xcc;
x.arr[12] = 0xdd;
x.arr[13] = 0xee;
x.arr[14] = 0xff;
x.arr[15] = 0xfa;
/*
printf("x.u128 = 0x%016llx%016llx\n", (unsigned long long)(hawk_uint64_t)(x.u128 >> 64), (unsigned long long)(hawk_uint64_t)(x.u128 >> 0));
tmp = hawk_htole128(x.u128);
printf("htole128(tmp) = 0x%016llx%016llx\n", (unsigned long long)(hawk_uint64_t)(tmp >> 64), (unsigned long long)(hawk_uint64_t)(tmp >> 0));
tmp = hawk_htobe128(x.u128);
printf("htobe128(tmp) = 0x%016llx%016llx\n", (unsigned long long)(hawk_uint64_t)(tmp >> 64), (unsigned long long)(hawk_uint64_t)(tmp >> 0));
*/
OK (x.u128 != hawk_htole128(x.u128) || x.u128 != hawk_htobe128(x.u128), "u128 endian conversion #0");
OK (x.u128 == hawk_le128toh(hawk_htole128(x.u128)), "u128 endian conversion #1");
OK (x.u128 == hawk_be128toh(hawk_htobe128(x.u128)), "u128 endian conversion #2");
OK (x.u128 == hawk_ntoh128(hawk_hton128(x.u128)), "u128 endian conversion #3");
#define X_CONST (((hawk_uint128_t)0x11223344 << 96) | ((hawk_uint128_t)0x55667788 << 64) | ((hawk_uint128_t)0x99aabbcc << 32) | ((hawk_uint128_t)0xddeefffa))
OK (X_CONST != HAWK_CONST_HTOLE128(X_CONST) || X_CONST != HAWK_CONST_HTOBE128(X_CONST), "u128 constant endian conversion #0");
OK (X_CONST == HAWK_CONST_LE128TOH(HAWK_CONST_HTOLE128(X_CONST)), "u128 constant endian conversion #1");
OK (X_CONST == HAWK_CONST_BE128TOH(HAWK_CONST_HTOBE128(X_CONST)), "u128 constant endian conversion #2");
OK (X_CONST == HAWK_CONST_NTOH128(HAWK_CONST_HTON128(X_CONST)), "u128 constant endian conversion #3");
#undef X_CONST
}
#endif
return exit_status();
}

34
t/t-002.c Normal file
View File

@ -0,0 +1,34 @@
/* test bit position functions */
#include <hawk-utl.h>
#include <stdio.h>
#include "tap.h"
int main ()
{
int i, j;
hawk_oow_t v;
no_plan ();
/*printf ("QSE_OOW_BITS => %d, sizeof(hawk_oow_t)=%d\n", (int)HAWK_OOW_BITS, (int)sizeof(hawk_oow_t));*/
for (i = 0; i < HAWK_OOW_BITS; i++)
{
v = ((hawk_oow_t)1 << i);
j = hawk_get_pos_of_msb_set_pow2(v);
/*printf ("msb(pow2) %d %d ==> %llx\n", i, j, (long long int)v);*/
OK (i == j, "msb(pow2) position tester");
}
for (i = 0; i < HAWK_OOW_BITS; i++)
{
v = ((hawk_oow_t)1 << i);
v |= 1;
j = hawk_get_pos_of_msb_set(v);
/*printf ("msb %d %d ==> %llx\n", i, j, (long long int)v);*/
OK (i == j, "msb position tester");
}
return exit_status();
}

77
t/t-003.c Normal file
View File

@ -0,0 +1,77 @@
#include <hawk-fmt.h>
#include <hawk-utl.h>
#include <string.h>
#include <stdio.h>
#include <wchar.h>
#include <locale.h>
#include "tap.h"
static int put_bchars (hawk_fmtout_t* fmtout, const hawk_bch_t* c, hawk_oow_t len)
{
while (len > 0)
{
putchar (*c);
c++;
len--;
}
return 1;
}
static int put_uchars (hawk_fmtout_t* fmtout, const hawk_uch_t* c, hawk_oow_t len)
{
hawk_cmgr_t* cmgr = hawk_get_utf8_cmgr();
hawk_bch_t bcs[HAWK_BCSIZE_MAX];
hawk_oow_t bcslen, i;
while (len > 0)
{
bcslen = cmgr->uctobc(*c, bcs, HAWK_COUNTOF(bcs));
/*putwchar (*c);*/
for (i = 0; i < bcslen; i++) putchar(bcs[i]);
c++;
len--;
}
return 1;
}
static hawk_ooi_t bfmt_out (const hawk_bch_t* fmt, ...)
{
hawk_fmtout_t fmtout;
va_list ap;
int n;
memset (&fmtout, 0, HAWK_SIZEOF(fmtout));
fmtout.putbchars = put_bchars;
fmtout.putuchars = put_uchars;
va_start (ap, fmt);
n = hawk_bfmt_outv (&fmtout, fmt, ap);
va_end (ap);
return (n <= -1)? -1: fmtout.count;
}
int main ()
{
hawk_uch_t x[] = { 'A', L'\uBB33', L'\uBB34', L'\uBB35', 'Q', '\0' };
hawk_ooi_t cnt;
no_plan ();
setlocale (LC_ALL, NULL);
cnt = bfmt_out ("[%s %d %020X %ls %s %w %.*lk]\n", "test", 10, 0x1232, x, "code", x, HAWK_SIZEOF_UCH_T * 3, x);
/* this unit is the number of characters written. but some are written as bch and some other as uch.
* if uch and bch data are mixed, the count returned doesn't really tell how many bytes or characters written */
bfmt_out ("wrote [%ld] units\n", cnt);
#if (HAWK_SIZEOF_UCH_T == 2)
# define EXPECTED_LEN 98
#elif (HAWK_SIZEOF_UCH_T == 4)
# define EXPECTED_LEN 122
#else
# error UNSUPPORTED UCH SIZE
#endif
OK (cnt == EXPECTED_LEN, "bfmt_out test #1");
return exit_status();
}

38
t/t-004.c Normal file
View File

@ -0,0 +1,38 @@
#include <hawk-std.h>
#include <hawk-utl.h>
#include <stdio.h>
#include "tap.h"
int main ()
{
hawk_t* hawk = HAWK_NULL;
hawk_uch_t ufmt1[] = { '%', '0', '5', 'd', ' ', '%', '-', '9', 'h', 's', '\0' };
#if 0
hawk_uch_t ufmt2[] = { '%', '0', '5', 'd', ' ', '%', '-', '9', 'h', 's', ' ', '%','O','\0' };
#endif
no_plan ();
hawk = hawk_openstd(0, HAWK_NULL);
if (!hawk)
{
fprintf (stderr, "Unable to open hawk\n");
return -1;
}
hawk_seterrbfmt (hawk, HAWK_NULL, HAWK_EINVAL, "%d %ld %s %hs", 10, 20L, "hawk", "hawk");
OK (hawk_comp_oocstr_bcstr(hawk_geterrmsg(hawk), "10 20 hawk hawk", 0) == 0, "hawk seterrbfmt #1");
hawk_logbfmt (hawk, HAWK_LOG_STDERR, "[%js]\n", hawk_geterrmsg(hawk));
hawk_seterrufmt (hawk, HAWK_NULL, HAWK_EINVAL, ufmt1, 9923, "hawk");
OK (hawk_comp_oocstr_bcstr(hawk_geterrmsg(hawk), "09923 hawk ", 0) == 0, "hawk seterrufmt #1");
hawk_logbfmt (hawk, HAWK_LOG_STDERR, "[%js]\n", hawk_geterrmsg(hawk));
#if 0
hawk_seterrufmt (hawk, HAWK_NULL, HAWK_EINVAL, ufmt2, 9923, "hawk", HAWK_SMPTR_TO_OOP(0x12345678));
OK (hawk_comp_oocstr_bcstr(hawk_geterrmsg(hawk), "09923 hawk #\\p12345678", 0) == 0, "hawk seterrufmt #1");
hawk_logbfmt (hawk, HAWK_LOG_STDERR, "[%js]\n", hawk_geterrmsg(hawk));
#endif
hawk_close (hawk);
return exit_status();
}

116
t/t-005.c Normal file
View File

@ -0,0 +1,116 @@
#include <hawk-ecs.h>
#include <hawk.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "tap.h"
#define OK_X(test) OK(test, #test)
static void* sys_alloc (hawk_mmgr_t* mmgr, hawk_oow_t size)
{
return malloc(size);
}
static void* sys_realloc (hawk_mmgr_t* mmgr, void* ptr, hawk_oow_t size)
{
return realloc(ptr, size);
}
static void sys_free (hawk_mmgr_t* mmgr, void* ptr)
{
free (ptr);
}
static hawk_mmgr_t sys_mmgr =
{
sys_alloc,
sys_realloc,
sys_free,
HAWK_NULL
};
static void test1 (void)
{
hawk_becs_t* b;
hawk_gem_t g;
g.mmgr = &sys_mmgr;
b = hawk_becs_open(&g, 0, 5);
hawk_becs_cat (b, "hello");
OK_X (hawk_becs_getlen(b) == 5);
hawk_becs_cat (b, "hello again");
OK_X (hawk_becs_getlen(b) == 16);
hawk_becs_del (b, 11, 3);
OK_X (hawk_becs_getlen(b) == 13);
OK_X (HAWK_BECS_CHAR(b, 12) == 'n');
OK_X (HAWK_BECS_CHAR(b, 13) == '\0');
printf ("[%s]\n", HAWK_BECS_PTR(b));
hawk_becs_close (b);
}
static void test2 (void)
{
const hawk_uch_t src[8] = {'a','b','c','d','e','f','g','h'};
const hawk_uch_t sxx[6] = {'0','1','2', '\0'};
hawk_uch_t dst[6] = {'0','1','2','3','4','5'};
hawk_oow_t q, i;
q = hawk_copy_uchars_to_ucstr(dst, HAWK_COUNTOF(dst), src, 7);
OK_X (q == HAWK_COUNTOF(dst) - 1);
OK_X (dst[HAWK_COUNTOF(dst) - 1] == '\0');
for (i = 0; i < q; i++) OK_X (dst[i] == src[i]);
q = hawk_copy_ucstr_to_uchars(dst, HAWK_COUNTOF(dst), sxx);
OK_X (q == 3);
OK_X (dst[q] == src[q]);
for (i = 0; i < q; i++) OK_X (dst[i] == sxx[i]);
}
hawk_bch_t* subst (hawk_bch_t* buf, hawk_oow_t bsz, const hawk_bcs_t* ident, void* ctx)
{
if (hawk_comp_bchars_bcstr(ident->ptr, ident->len, "USER", 0) == 0)
{
return buf + ((buf == HAWK_SUBST_NOBUF)? 3: hawk_copy_bcstr_to_bchars(buf, bsz, "sam"));
}
else if (hawk_comp_bchars_bcstr(ident->ptr, ident->len, "GROUP", 0) == 0)
{
return buf + ((buf == HAWK_SUBST_NOBUF)? 6: hawk_copy_bcstr_to_bchars(buf, bsz, "coders"));
}
return buf;
}
static void test3 (void)
{
hawk_bch_t buf[512], * ptr;
hawk_oow_t n;
n = hawk_subst_for_bcstr_to_bcstr (buf, HAWK_COUNTOF(buf), "user=${USER},group=${GROUP}", subst, HAWK_NULL);
OK_X (n == 21);
OK_X (hawk_count_bcstr(buf) == 21);
OK_X (hawk_comp_bcstr(buf, "user=sam,group=coders", 0) == 0);
n = hawk_subst_for_bcstr_to_bcstr(HAWK_SUBST_NOBUF, 0, "USERNAME=${USER},GROUPNAME=${GROUP}", subst, HAWK_NULL);
OK_X (n == 29);
ptr = malloc(n + 1);
n = hawk_subst_for_bcstr_to_bcstr(ptr, n + 1, "USERNAME=${USER},GROUPNAME=${GROUP}", subst, HAWK_NULL);
OK_X (n == 29);
OK_X (hawk_count_bcstr(ptr) == 29);
OK_X (hawk_comp_bcstr(ptr, "USERNAME=sam,GROUPNAME=coders", 0) == 0);
free (ptr);
}
int main ()
{
no_plan();
test1();
test2();
test3();
return exit_status();
}

136
t/t-006.c Normal file
View File

@ -0,0 +1,136 @@
#include <hawk-utl.h>
#include <stdio.h>
#include "tap.h"
struct
{
hawk_ntime_sec_t s1; /* input x */
hawk_ntime_nsec_t ns1;
hawk_ntime_sec_t s2; /* input y */
hawk_ntime_nsec_t ns2;
hawk_ntime_sec_t add_s; /* expected z after addition */
hawk_ntime_nsec_t add_ns;
hawk_ntime_sec_t sub_s; /* expected z after subtraction */
hawk_ntime_nsec_t sub_ns;
} tab[] =
{
/* 0 */
{ 12345678, HAWK_NSECS_PER_SEC - 1,
0, 10,
12345679, 9,
12345678, HAWK_NSECS_PER_SEC - 11 },
{ 0, 0,
12345678, 10,
12345678, 10,
-12345679, HAWK_NSECS_PER_SEC - 10 },
{ 0, 0,
-12345678, 10,
-12345678, 10,
12345677, HAWK_NSECS_PER_SEC - 10 },
{ HAWK_TYPE_MAX(hawk_ntime_sec_t) - 1, HAWK_NSECS_PER_SEC - 1,
1, 0,
HAWK_TYPE_MAX(hawk_ntime_sec_t), HAWK_NSECS_PER_SEC - 1,
HAWK_TYPE_MAX(hawk_ntime_sec_t) - 2, HAWK_NSECS_PER_SEC - 1 },
{ HAWK_TYPE_MAX(hawk_ntime_sec_t) - 1, HAWK_NSECS_PER_SEC - 1,
1, 1,
HAWK_TYPE_MAX(hawk_ntime_sec_t), HAWK_NSECS_PER_SEC - 1,
HAWK_TYPE_MAX(hawk_ntime_sec_t) - 2, HAWK_NSECS_PER_SEC - 2 },
/* 5 */
{ HAWK_TYPE_MAX(hawk_ntime_sec_t) - 1, HAWK_NSECS_PER_SEC - 1,
1, 2,
HAWK_TYPE_MAX(hawk_ntime_sec_t), HAWK_NSECS_PER_SEC - 1,
HAWK_TYPE_MAX(hawk_ntime_sec_t) - 2, HAWK_NSECS_PER_SEC - 3 },
{ HAWK_TYPE_MAX(hawk_ntime_sec_t), 0,
0, 0,
HAWK_TYPE_MAX(hawk_ntime_sec_t), 0,
HAWK_TYPE_MAX(hawk_ntime_sec_t), 0 },
{ HAWK_TYPE_MIN(hawk_ntime_sec_t), 0,
0, 0,
HAWK_TYPE_MIN(hawk_ntime_sec_t), 0,
HAWK_TYPE_MIN(hawk_ntime_sec_t), 0 },
{ HAWK_TYPE_MIN(hawk_ntime_sec_t) + 1, 0,
1, 2,
HAWK_TYPE_MIN(hawk_ntime_sec_t) + 2, 2,
HAWK_TYPE_MIN(hawk_ntime_sec_t), 0 },
{ HAWK_TYPE_MIN(hawk_ntime_sec_t) + 1, 0,
2, 2,
HAWK_TYPE_MIN(hawk_ntime_sec_t) + 3, 2,
HAWK_TYPE_MIN(hawk_ntime_sec_t), 0 },
/* 10 */
{ HAWK_TYPE_MIN(hawk_ntime_sec_t) + 1, 0,
2, HAWK_NSECS_PER_SEC - 1,
HAWK_TYPE_MIN(hawk_ntime_sec_t) + 3, HAWK_NSECS_PER_SEC - 1,
HAWK_TYPE_MIN(hawk_ntime_sec_t), 0 },
{ 0, 0,
HAWK_TYPE_MIN(hawk_ntime_sec_t), 0,
HAWK_TYPE_MIN(hawk_ntime_sec_t), 0,
HAWK_TYPE_MAX(hawk_ntime_sec_t), HAWK_NSECS_PER_SEC - 1 },
{ HAWK_TYPE_MAX(hawk_ntime_sec_t), 0,
1, 0,
HAWK_TYPE_MAX(hawk_ntime_sec_t), HAWK_NSECS_PER_SEC - 1,
HAWK_TYPE_MAX(hawk_ntime_sec_t) - 1, 0 },
{ HAWK_TYPE_MAX(hawk_ntime_sec_t), 0,
HAWK_TYPE_MIN(hawk_ntime_sec_t), 0,
-1, 0,
HAWK_TYPE_MAX(hawk_ntime_sec_t), HAWK_NSECS_PER_SEC - 1 },
{ HAWK_TYPE_MIN(hawk_ntime_sec_t), 0,
HAWK_TYPE_MAX(hawk_ntime_sec_t), 0,
-1, 0,
HAWK_TYPE_MIN(hawk_ntime_sec_t), 0 },
/* 15 */
{ HAWK_TYPE_MIN(hawk_ntime_sec_t), 0,
HAWK_TYPE_MAX(hawk_ntime_sec_t), HAWK_NSECS_PER_SEC - 1,
-1, HAWK_NSECS_PER_SEC - 1,
HAWK_TYPE_MIN(hawk_ntime_sec_t), 0 }
};
int main ()
{
hawk_ntime_t x, y, z;
int i;
char buf1[64], buf2[64];
no_plan();
for (i = 0; i < HAWK_COUNTOF(tab); i++)
{
sprintf (buf1, "add - index %d", i);
sprintf (buf2, "sub - index %d", i);
x.sec = tab[i].s1;
x.nsec = tab[i].ns1;
y.sec = tab[i].s2;
y.nsec = tab[i].ns2;
hawk_add_ntime (&z, &x, &y);
OK (z.sec == tab[i].add_s, buf1);
OK (z.nsec == tab[i].add_ns, buf1);
hawk_sub_ntime (&z, &x, &y);
OK (z.sec == tab[i].sub_s, buf2);
OK (z.nsec == tab[i].sub_ns, buf2);
}
return exit_status();
}

291
t/tap.h Normal file
View File

@ -0,0 +1,291 @@
/*
** tap4embedded : http://github.com/fperrad/tap4embedded
**
** Copyright (C) 2016-2017 Francois Perrad.
**
** tap4embedded is free software; you can redistribute it and/or modify it
** under the terms of the Artistic License 2.0
*/
#ifndef TAP_H
#define TAP_H
#ifndef TAP_PUTCHAR
#include <stdio.h>
#define TAP_PUTCHAR(c) fputc((c), stdout)
#define TAP_FLUSH() fflush(stdout)
#endif
#ifndef TAP_FLUSH
#define TAP_FLUSH()
#endif
#if defined(__unix__) || defined(_WIN32) || defined(_WIN64)
#include <stdlib.h>
#define TAP_EXIT(n) exit(n)
#else
#define TAP_EXIT(n)
#endif
#if defined(__bool_true_false_are_defined) || defined(__cplusplus)
#define TAP_BOOL bool
#define TAP_TRUE true
#define TAP_FALSE false
#else
#define TAP_BOOL char
#define TAP_TRUE 1
#define TAP_FALSE 0
#endif
#ifdef __cplusplus
extern "C" {
#endif
extern void plan(unsigned int nb);
extern void no_plan(void);
extern void skip_all(const char *reason);
extern void done_testing(unsigned int nb);
extern void bail_out(const char *reason);
extern void ok(const char *file, unsigned int line, TAP_BOOL test, const char *name);
extern void todo(const char *reason, unsigned int count);
extern void skip(const char *reason, unsigned int count);
extern void todo_skip(const char *reason);
extern void skip_rest(const char *reason);
extern void diag (const char *msg);
extern int exit_status (void);
#define OK(test, name) ok(__FILE__, __LINE__, (test), (name))
#define NOK(test, name) ok(__FILE__, __LINE__, !(test), (name))
#define PASS(name) ok(__FILE__, __LINE__, TAP_TRUE, (name))
#define FAIL(name) ok(__FILE__, __LINE__, TAP_FALSE, (name))
#ifndef TAP_NO_IMPL
typedef struct {
unsigned int curr_test;
unsigned int expected_tests;
unsigned int todo_upto;
const char *todo_reason;
TAP_BOOL have_plan;
TAP_BOOL no_plan;
TAP_BOOL have_output_plan;
TAP_BOOL done_testing;
TAP_BOOL is_passing;
} tap_t;
tap_t tap;
void putstr(const char *msg) {
TAP_BOOL need_begin = TAP_FALSE;
for (; *msg != '\0'; msg++) {
if (need_begin) {
TAP_PUTCHAR('#');
TAP_PUTCHAR(' ');
need_begin = TAP_FALSE;
}
TAP_PUTCHAR(*msg);
if (*msg == '\n') {
need_begin = TAP_TRUE;
}
}
}
void putuint (unsigned int n) {
char buf[8 * sizeof(unsigned int) + 1];
char *ptr = &buf[sizeof(buf) - 1];
*ptr = '\0';
do {
char c = '0' + (n % 10u);
--ptr;
*ptr = c;
n /= 10u;
} while (n != 0u);
putstr(ptr);
}
void not_yet_plan(void) {
if (tap.have_plan) {
putstr("You tried to plan twice\n");
TAP_FLUSH();
TAP_EXIT(-1);
}
}
void plan(unsigned int nb) {
not_yet_plan();
putstr("1..");
putuint(nb);
TAP_PUTCHAR('\n');
tap.expected_tests = nb;
tap.have_plan = TAP_TRUE;
tap.have_output_plan = TAP_TRUE;
tap.is_passing = TAP_TRUE;
}
void no_plan(void) {
not_yet_plan();
tap.have_plan = TAP_TRUE;
tap.no_plan = TAP_TRUE;
tap.is_passing = TAP_TRUE;
}
void skip_all(const char *reason) {
not_yet_plan();
putstr("1..0 # SKIP ");
putstr(reason);
TAP_PUTCHAR('\n');
tap.curr_test = 1u;
tap.expected_tests = 1u;
tap.have_plan = TAP_TRUE;
tap.have_output_plan = TAP_TRUE;
tap.is_passing = TAP_TRUE;
TAP_FLUSH();
}
void done_testing(unsigned int nb) {
if (tap.done_testing) {
putstr("done_testing() was already called\n");
}
else {
tap.done_testing = TAP_TRUE;
if ((tap.expected_tests != nb) && (tap.expected_tests != 0u)) {
putstr("# Looks like you planned ");
putuint(tap.expected_tests);
putstr(" tests but ran ");
putuint(nb);
TAP_PUTCHAR('.');
TAP_PUTCHAR('\n');
}
else {
tap.expected_tests = nb;
}
if (! tap.have_output_plan) {
putstr("1..");
putuint(nb);
TAP_PUTCHAR('\n');
tap.have_output_plan = TAP_TRUE;
}
if ((tap.expected_tests != tap.curr_test) || (tap.curr_test == 0u)) {
tap.is_passing = TAP_FALSE;
}
putstr("# Done with tap4embedded.\n");
}
TAP_FLUSH();
}
void bail_out(const char *reason) {
putstr("Bail out!");
if (reason != NULL) {
TAP_PUTCHAR(' ');
TAP_PUTCHAR(' ');
putstr(reason);
}
TAP_PUTCHAR('\n');
TAP_FLUSH();
TAP_EXIT(-1);
}
void need_plan(void) {
if (! tap.have_plan) {
putstr("You tried to run a test without a plan\n");
TAP_FLUSH();
TAP_EXIT(-1);
}
}
void ok(const char *file, unsigned int line, TAP_BOOL test, const char *name) {
need_plan();
++tap.curr_test;
if (! test) {
putstr("not ");
}
putstr("ok ");
putuint(tap.curr_test);
if (name != NULL) {
putstr(" - ");
putstr(name);
}
if ((tap.todo_reason != NULL) && (tap.todo_upto >= tap.curr_test)) {
putstr(" # TODO # ");
putstr(tap.todo_reason);
}
TAP_PUTCHAR('\n');
if (! test) {
putstr("# Failed");
if (tap.todo_upto >= tap.curr_test) {
putstr(" (TODO)");
}
else {
tap.is_passing = TAP_FALSE;
}
putstr(" test (");
putstr(file);
putstr(" at line ");
putuint(line);
putstr(")\n");
}
}
void todo(const char *reason, unsigned int count) {
tap.todo_upto = tap.curr_test + count;
tap.todo_reason = reason;
}
void skip(const char *reason, unsigned int count) {
unsigned int i;
need_plan();
for (i = 0u; i < count; i++) {
++tap.curr_test;
putstr("ok ");
putuint(tap.curr_test);
putstr(" - # skip");
if (reason != NULL) {
TAP_PUTCHAR(' ');
putstr(reason);
}
TAP_PUTCHAR('\n');
}
}
void todo_skip(const char *reason) {
need_plan();
++tap.curr_test;
putstr("not ok ");
putuint(tap.curr_test);
putstr(" - # TODO & SKIP");
if (reason != NULL) {
TAP_PUTCHAR(' ');
putstr(reason);
}
TAP_PUTCHAR('\n');
}
void skip_rest(const char *reason) {
skip(reason, tap.expected_tests - tap.curr_test);
}
void diag (const char *msg) {
TAP_PUTCHAR('#');
TAP_PUTCHAR(' ');
putstr(msg);
TAP_PUTCHAR('\n');
}
int exit_status (void) {
if (! tap.done_testing) {
done_testing(tap.curr_test);
}
#if defined(EXIT_SUCCESS) && defined(EXIT_FAILURE)
return tap.is_passing ? EXIT_SUCCESS : EXIT_FAILURE;
#else
return tap.is_passing ? 0 : -1;
#endif
}
#endif
#ifdef __cplusplus
}
#endif
#endif

38
t/tap.inc Normal file
View File

@ -0,0 +1,38 @@
@global tap;
function tap_end ()
{
printf ("1..%d\n", tap["total"]);
}
function tap_ok (msg)
{
tap["total"]++;
printf ("ok %d - %s\n", tap["total"], msg);
}
function tap_fail (msg)
{
tap["total"]++;
printf ("not ok %d - %s\n", tap["total"], msg);
}
function tap_skip (msg)
{
tap["total"]++;
printf ("ok %d - # skip%s%s\n", tap["total"], (length(msg) > 0? " ": ""), msg);
}
function tap_ensure (a, b, desc, line)
{
@local id;
id = sprintf("%s[%d]", desc, line);
if (a != b) tap_fail (id);
else tap_ok (id);
}
BEGIN {
tap["total"] = 0;
}

193
t/test.txt Normal file
View File

@ -0,0 +1,193 @@
#### TODO: create test cases using the following data
BEGIN { @local abc; abc(); }'
HAWK_ENOTFUN -> ERROR: CODE 97 LINE 1 COLUMN 21 - non-function value in abc
BEGIN { @local x; abc(); }
HAWK_EFUNNF -> ERROR: CODE 96 LINE 1 COLUMN 19 - function 'abc' not found
hawk --implicit=off 'BEGIN { @local x; abc(); }'
HAWK_EFUNNF -> ERROR: CODE 96 LINE 1 COLUMN 19 - function 'abc' not defined ===> same as the above. but it's a parse-time error.
BEGIN { @local x; x=sys::getpid(); delete x;}
HAWK_ENOTDEL -> ERROR: CODE 98 LINE 1 COLUMN 43 - 'x' not deletable
hawk --flexmap=off 'BEGIN { ARGV = 30; }'
HAWK_ENMAPTOSCALAR -> ERROR: CODE 110 LINE 1 COLUMN 10 - not allowed to change a map 'ARGV' to a scalar
hawk --flexmap=off 'BEGIN { @local x; x = 10; x[1] = "hello"; }'
HAWK_ESCALARTOMAP -> ERROR: CODE 108 LINE 1 COLUMN 28 - not allowed to change a scalar 'x' to a map
hawk --flexmap=off 'BEGIN { @local x, y; x[1]=20; ARGC = x; }'
HAWK_ESCALARTOMAP -> ERROR: CODE 108 LINE 1 COLUMN 32 - not allowed to achange a scalar 'ARGC' to a map
hawk --flexmap=off 'BEGIN { ARGC[1] = "hello"; }'
HAWK_ESCALARTOMAP -> ERROR: CODE 108 LINE 1 COLUMN 10 - not allowed to change a scalar 'ARGC' to a map
hawk --flexmap=off 'BEGIN { @local x, y; x[1]=20; CONVFMT = x; }'
HAWK_ESCALARTOMAP -> ERROR: CODE 108 LINE 1 COLUMN 32 - not allowed to change a scalar 'CONVFMT' to a map
hawk --flexmap=on 'BEGIN { @local x, y; x[1]=20; CONVFMT = x; }'
HAWK_ESCALARTOMAP -> ERROR: CODE 108 LINE 1 COLUMN 32 - not allowed to change a scalar 'CONVFMT' to a map
$ hawk --flexmap=off 'BEGIN { @local x, y; x[1] = 10; y[1] = 20; x = y; }'
HAWK_EMAPTOMAP -> ERROR: CODE 108 LINE 1 COLUMN 45 - not allowed to change a map 'x' to another map => x is a local variable
$ hawk --flexmap=off 'BEGIN { @local y; x[1] = 10; y[1] = 20; x = y; }'
HAWK_EMAPTOMAP -> ERROR: CODE 108 LINE 1 COLUMN 42 - jnot allowed to change a map 'x' to another map => x is a global variable
$ hawk --flexmap=off 'function abc(x) { @local j; j[1] = 20; x = j; } BEGIN { @local q; q[1]=20; abc(q); }'
HAWK_EMAPTOMAP -> ERROR: CODE 108 LINE 1 COLUMN 40 - not allowed to change a map 'x' to another map => x is an argument
$ hawk --flexmap=off 'function abc(x) { x = 20; } BEGIN { @local q; q[1]=20; abc(q); }'
HAWK_EMAPTOSCALAR -> ERROR: CODE 107 LINE 1 COLUMN 19 - not allowed to change a map 'x' to a scalar
$ hawk --flexmap=off 'BEGIN { @local y; x[1] = 10; x = 20; }'
HAWK_EMAPTOSCALAR -> ERROR: CODE 107 LINE 1 COLUMN 32 - not allowed to change a map 'x' to a scalar
$ hawk --flexmap=off 'BEGIN { x[1] = 10; x = 20; }'
HAWK_EMAPTOSCALAR -> ERROR: CODE 107 LINE 1 COLUMN 22 - not allowed to change a map 'x' to a scalar
$ hawk --flexmap=off 'BEGIN { x[1] = 10; jx=x; }'
HAWK_EMAPTOMAP -> ERROR: CODE 106 LINE 1 COLUMN 22 - not allowed to assign a map to a variable 'jx'
$ hawk --flexmap=off 'BEGIN { @local x, jx; x[1] = 10; jx=x; }'
HAWK_EMAPTOMAP -> ERROR: CODE 106 LINE 1 COLUMN 36 - not allowed to assign a map to a variable 'jx'
$ hawk --flexmap=off 'function abc(jx) { @local x; x[1]= 20; jx = x; } BEGIN { abc(10); }'
HAWK_EMAPTOMAP -> ERROR: CODE 106 LINE 1 COLUMN 40 - not allowed to assign a map to a variable 'jx'
$ hawk 'BEGIN { print 0192; }'
HAWK_ELXDIG -> ERROR: CODE 32 LINE 1 COLUMN 15 - invalid digit '9'
$ hawk 'BEGIN { +
> }'
HAWK_EEXPRNR -> ERROR: CODE 49 LINE 1 COLUMN 9 - expression not recognized around '+'
$ ~/xxx/bin/hawk '@pragma stack_limit "99"; BEGIN { }'
HAWK_EINTLIT -> ERROR: CODE 45 LINE 1 COLUMN 21 - integer literal expected in place of '99'
$ ~/xxx/bin/hawk --pablock=off '{ print $0; }'
HAWK_EKWFNC -> ERROR: CODE 50 LINE 1 COLUMN 1 - keyword 'function' expected in place of '{'
$ ~/xxx/bin/hawk --pablock=off 'BEGIN { print $0; }'
HAWK_EKWFNC -> ERROR: CODE 50 LINE 1 COLUMN 1 - keyword 'function' expected in place of 'BEGIN'
$ ~/xxx/bin/hawk '@include "a\0b"; function; BEGIN { function=10; }'
HAWK_EIONMNL -> ERROR: CODE 122 LINE 1 COLUMN 10 - invalid I/O name of length 3 containing '\0'
$ ~/xxx/bin/hawk 'function add(a,b) { return a + b; } @global add; BEGIN { add = 10; }'
HAWK_EFUNRED -> ERROR: CODE 59 LINE 1 COLUMN 45 - function 'add' redefined
$ ~/xxx/bin/hawk '@global add; function add(a,b) { return a + b; } BEGIN { add = 10; }'
HAWK_EGBLRED -> ERROR: CODE 60 LINE 1 COLUMN 23 - global variable 'add' redefined
$ ~/xxx/bin/hawk 'BEGIN { @local length; }'
HAWK_EFNCRED -> ERROR: CODE 58 LINE 1 COLUMN 16 - intrinsic function 'length' redefined
$ ~/xxx/bin/hawk '@global length;'
HAWK_EFNCRED -> ERROR: CODE 58 LINE 1 COLUMN 9 - intrinsic function 'length' redefined
$ ~/xxx/bin/hawk 'function length(x) { return 10; }'
HAWK_EFNCRED -> ERROR: CODE 58 LINE 1 COLUMN 10 - intrinsic function 'length' redefined
$ ~/xxx/bin/hawk 'function test(ax) { @local ax; }'
HAWK_EPARRED -> ERROR: CODE 61 LINE 1 COLUMN 28 - parameter 'ax' redefined
$ ~/xxx/bin/hawk 'function test(ax, bx, ax) { return ax * bx; }'
HAWK_EDUPPAR -> ERROR: CODE 63 LINE 1 COLUMN 23 - duplicate parameter name 'ax'
$ ~/xxx/bin/hawk '@global x, y, x; '
HAWK_EDUPGBL -> ERROR: CODE 64 LINE 1 COLUMN 15 - duplicate global variable name 'x'
$ ~/xxx/bin/hawk 'function test(ax, bx) { @local x, y, x; }'
HAWK_EDUPLCL -> ERROR: CODE 65 LINE 1 COLUMN 38 - duplicate local variable name - x
$ ~/xxx/bin/hawk 'function test(ax, bx) { @local ARGC; }'
ERROR: CODE 65 LINE 1 COLUMN 32 - duplicate local variable name - ARGC
$ ~/xxx/bin/hawk '@global 10; '
HAWK_EBADVAR -> ERROR: CODE 67 LINE 1 COLUMN 9 - '10' not a valid variable name
$ ~/xxx/bin/hawk '{ @local 10; }'
HAWK_EBADVAR -> ERROR: CODE 67 LINE 1 COLUMN 10 - '10' not a valid variable name
$ ~/xxx/bin/hawk 'function test(10) {} '
HAWK_EBADPAR -> ERROR: CODE 66 LINE 1 COLUMN 15 - '10' not a valid parameter name
$ ~/xxx/bin/hawk 'BEGIN { print B"abc^Bdef"; }'
HAWK_EMBSCHR -> ERROR: CODE 37 LINE 1 COLUMN 15 - invalid mbs character ''
$ ~/xxx/bin/hawk "BEGIN { print B'abf^Bdef'; }"
HAWK_EMBSCHR -> ERROR: CODE 37 LINE 1 COLUMN 16 - invalid mbs character ''
$ ~/xxx/bin/hawk --implicit=off 'BEGIN { print kcx[10]; }'
HAWK_EUNDEF -> ERROR: CODE 69 LINE 1 COLUMN 16 - undefined identifier 'kcx'
$ ~/xxx/bin/hawk --implicit=off 'BEGIN { print ax; }'
HAWK_EUNDEF -> ERROR: CODE 69 LINE 1 COLUMN 16 - undefined identifier 'ax'
$ ~/xxx/bin/hawk 'function 1.2(a) {}'
HAWK_EFUNNAM -> ERROR: CODE 54 LINE 1 COLUMN 10 - '1.2' not a valid function name
$ ~/xxx/bin/hawk 'function abc(x) print t; }'
HAWK_ELBRACE -> ERROR: CODE 38 LINE 1 COLUMN 17 - left brace expected in place of 'print'
$ ~/xxx/bin/hawk 'function abc(x) { print a[10; }'
HAWK_ERBRACK -> ERROR: CODE 41 LINE 1 COLUMN 29 - right bracket expected in place of ';'
$ ~/xxx/bin/hawk 'function abc x) { print 10; }'
HAWK_ELPAREN -> ERROR: CODE 39 LINE 1 COLUMN 14 - left parenthesis expected in place of 'x'
$ ~/xxx/bin/hawk 'function abc (x) { print (x; }'
HAWK_EPAREN -> ERROR: CODE 40 LINE 1 COLUMN 28 - right parenthesis expected in place of ';'
$ ~/xxx/bin/hawk 'function abc (x { print 10; }'
HAWK_ECOMMA -> ERROR: CODE 42 LINE 1 COLUMN 17 - comma expected in place of '{'
$ ~/xxx/bin/hawk 'function abc (x) { for (i = 10) print i; }'
HAWK_ESCOLON -> ERROR: CODE 43 LINE 1 COLUMN 31 - semicolon expected in place of ')'
$ ~/xxx/bin/hawk 'function abc (x) { print (i? 20, 30); }'
HAWK_ECOLON -> ERROR: CODE 44 LINE 1 COLUMN 32 - colon expected in place of ','
$ ~/xxx/bin/hawk '@includ "xxx.inc"; BEGIN {}'
HAWK_EXKWNR -> ERROR: CODE 88 LINE 1 COLUMN 1 - '@includ' not recognized
$ ~/xxx/bin/hawk 'function abc (x) { do { print x }; }'
HAWK_EKWWHL -> ERROR: CODE 51 LINE 1 COLUMN 34 - keyword 'while' expected in place of ';'
$ ~/xxx/bin/hawk 'function abc (x) { do { print sysxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxtt::xx }; }'
HAWK_ESEGTL -> ERROR: CODE 75 LINE 1 COLUMN 31 - segment 'sysxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxtt' too long
$ ~/xxx/bin/hawk --tolerant=off 'function abc (x) { (1, 2, 3) }'
HAWK_EKWIN -> ERROR: CODE 47 LINE 1 COLUMN 30 - keyword 'in' expected in place of '}'