fixed a few minor bugs

This commit is contained in:
hyung-hwan 2009-06-27 07:05:19 +00:00
parent 06d3d78abf
commit e337e01d46
105 changed files with 164 additions and 703 deletions

View File

@ -1,52 +0,0 @@
#
# $Id: asm.awk,v 1.4 2007/09/27 11:33:45 bacon Exp $
#
# Taken from the book "The AWK Programming Language"
# aseawk++ -si asm.awk -a asm.s -nostripspaces -baseone
#
BEGIN {
srcfile = ARGV[1];
ARGV[1] = "";
tempfile = "asm.temp";
n = split("const get put ld st add sub jpos jz j halt", x);
for (i = 1; i <= n; i++) op[x[i]] = i - 1;
# PASS 1
FS = "[ \t]+";
while (getline <srcfile > 0) {
sub (/#.*/, "");
symtab[$1] = nextmem;
if ($2 != "") {
print $2 "\t" $3 >tempfile;
nextmem++;
}
}
close (tempfile);
# PASS 2
nextmem = 0;
while (getline <tempfile > 0) {
if ($2 !~ /^[0-9]*$/) $2 = symtab[$2];
mem[nextmem++] = 1000 * op[$1] + $2;
}
# INTERPRETER
for (pc = 0; pc >= 0; ) {
addr = mem[pc] % 1000;
code = int(mem[pc++] / 1000);
if (code == op["get"]) { if (getline acc <= 0) acc = 0; }
else if (code == op["put"]) { print acc; }
else if (code == op["st"]) { mem[addr] = acc; }
else if (code == op["ld"]) { acc = mem[addr]; }
else if (code == op["add"]) { acc += mem[addr]; }
else if (code == op["sub"]) { acc -= mem[addr]; }
else if (code == op["jpos"]) { if (acc > 0) pc = addr; }
else if (code == op["jz"]) { if (acc == 0) pc = addr; }
else if (code == op["j"]) { pc = addr; }
else if (code == op["halt"]) { pc = -1; }
else { pc = -1; }
}
}

View File

@ -1,15 +0,0 @@
{
print $1,$3;
}
USSR 275
Canada 25
China 1032
USA 237
Brazil 134
India 746
Mexico 78
France 55
Japan 120
Germany 61
England 56

View File

@ -1,29 +0,0 @@
BEGIN {
FS = " ";
printf ("%10s %6s %5s %s\n\n","COUNTRY","AREA","POP","CONTINENT");
}
{
printf ("%10s %6d %5d %s\n",$1,$2,$3,$4);
area = (area + $2);
pop = (pop + $3);
}
END {
printf ("\n%10s %6d %5d\n","TOTAL",area,pop);
}
COUNTRY AREA POP CONTINENT
USSR 8649 275 Asia
Canada 3852 25 North America
China 3705 1032 Asia
USA 3615 237 North America
Brazil 3286 134 South America
India 1267 746 Asia
Mexico 762 78 North America
France 211 55 Europe
Japan 144 120 Asia
Germany 96 61 Europe
England 94 56 Europe
TOTAL 25681 2819

View File

@ -1,6 +0,0 @@
(($3 / $2) >= 0.5)
India 1267 746 Asia
Japan 144 120 Asia
Germany 96 61 Europe
England 94 56 Europe

View File

@ -1,5 +0,0 @@
($0 >= "M")
USSR 8649 275 Asia
USA 3615 237 North America
Mexico 762 78 North America

View File

@ -1,6 +0,0 @@
($1 < $4)
Canada 3852 25 North America
Brazil 3286 134 South America
Mexico 762 78 North America
England 94 56 Europe

View File

@ -1,5 +0,0 @@
($2 < $3)
India 1267 746 Asia
Mexico 762 78 North America
France 211 55 Europe

View File

@ -1,6 +0,0 @@
/Asia/
USSR 8649 275 Asia
China 3705 1032 Asia
India 1267 746 Asia
Japan 144 120 Asia

View File

@ -1,6 +0,0 @@
($4 ~ /Asia/)
USSR 8649 275 Asia
China 3705 1032 Asia
India 1267 746 Asia
Japan 144 120 Asia

View File

@ -1,9 +0,0 @@
($4 !~ /Asia/)
Canada 3852 25 North America
USA 3615 237 North America
Brazil 3286 134 South America
Mexico 762 78 North America
France 211 55 Europe
Germany 96 61 Europe
England 94 56 Europe

View File

@ -1,6 +0,0 @@
($0 ~ /Asia/)
USSR 8649 275 Asia
China 3705 1032 Asia
India 1267 746 Asia
Japan 144 120 Asia

View File

@ -1,2 +0,0 @@
($2 !~ /^[0-9]+$/)

View File

@ -1,4 +0,0 @@
(($4 == "Asia") && ($3 > 500))
China 3705 1032 Asia
India 1267 746 Asia

View File

@ -1,9 +0,0 @@
(($4 == "Asia") || ($4 == "Europe"))
USSR 8649 275 Asia
China 3705 1032 Asia
India 1267 746 Asia
France 211 55 Europe
Japan 144 120 Asia
Germany 96 61 Europe
England 94 56 Europe

View File

@ -1,9 +0,0 @@
($4 ~ /^(Asia|Europe)$/)
USSR 8649 275 Asia
China 3705 1032 Asia
India 1267 746 Asia
France 211 55 Europe
Japan 144 120 Asia
Germany 96 61 Europe
England 94 56 Europe

View File

@ -1,9 +0,0 @@
(/Asia/ || /Europe/)
USSR 8649 275 Asia
China 3705 1032 Asia
India 1267 746 Asia
France 211 55 Europe
Japan 144 120 Asia
Germany 96 61 Europe
England 94 56 Europe

View File

@ -1,9 +0,0 @@
/Asia|Europe/
USSR 8649 275 Asia
China 3705 1032 Asia
India 1267 746 Asia
France 211 55 Europe
Japan 144 120 Asia
Germany 96 61 Europe
England 94 56 Europe

View File

@ -1,5 +0,0 @@
/Canada/,/USA/
Canada 3852 25 North America
China 3705 1032 Asia
USA 3615 237 North America

View File

@ -1,2 +0,0 @@
/Eurpoe/,/Africa/

View File

@ -1,9 +0,0 @@
(FNR == 1),(FNR == 5) {
print ((FILENAME ": ") $0);
}
cou-en.data: USSR 8649 275 Asia
cou-en.data: Canada 3852 25 North America
cou-en.data: China 3705 1032 Asia
cou-en.data: USA 3615 237 North America
cou-en.data: Brazil 3286 134 South America

View File

@ -1,9 +0,0 @@
(FNR <= 5) {
print ((FILENAME ": ") $0);
}
cou-en.data: USSR 8649 275 Asia
cou-en.data: Canada 3852 25 North America
cou-en.data: China 3705 1032 Asia
cou-en.data: USA 3615 237 North America
cou-en.data: Brazil 3286 134 South America

View File

@ -1,8 +0,0 @@
($4 == "Asia") {
print $1,(1000 * $2);
}
USSR 8649000
China 3705000
India 1267000
Japan 144000

View File

@ -1,27 +0,0 @@
BEGIN {
FS = OFS = " ";
}
($4 == "North America") {
$4 = "NA";
}
($4 == "South America") {
$4 = "SA";
}
{
print;
}
USSR 8649 275 Asia
Canada 3852 25 NA
China 3705 1032 Asia
USA 3615 237 NA
Brazil 3286 134 SA
India 1267 746 Asia
Mexico 762 78 NA
France 211 55 Europe
Japan 144 120 Asia
Germany 96 61 Europe
England 94 56 Europe

View File

@ -1,20 +0,0 @@
BEGIN {
FS = OFS = " ";
}
{
$5 = ((1000 * $3) / $2);
print;
}
USSR 8649 275 Asia 31.7956
Canada 3852 25 North America 6.49013
China 3705 1032 Asia 278.543
USA 3615 237 North America 65.5602
Brazil 3286 134 South America 40.7791
India 1267 746 Asia 588.792
Mexico 762 78 North America 102.362
France 211 55 Europe 260.664
Japan 144 120 Asia 833.333
Germany 96 61 Europe 635.417
England 94 56 Europe 595.745

View File

@ -1,9 +0,0 @@
($4 == "Asia") {
pop = (pop + $3);
n = (n + 1);
}
END {
print "Total population of the",n,"Asian countries is",pop,"million.";
}
Total population of the 4 Asian countries is 2173 million.

View File

@ -1,14 +0,0 @@
/Asia/ {
pop["Asia"] += $3;
}
/Europe/ {
pop["Europe"] += $3;
}
END {
print "Asian population is",pop["Asia"],"million.";
print "European population is",pop["Europe"],"million.";
}
Asian population is 2173 million.
European population is 172 million.

View File

@ -1,16 +0,0 @@
BEGIN {
FS = " ";
}
{
pop[$4] += $3;
}
END {
for (name in pop)
print name,pop[name];
}
Europe 172
South America 134
North America 340
Asia 2173

View File

@ -1,18 +0,0 @@
BEGIN {
FS = " ";
}
{
pop[$4] += $3;
}
END {
for (c in pop)
printf ("%15s %6d\n",c,pop[c]) | "sort -t' ' -k2 -rn";
close ("sort -t' ' -k2 -rn");
sleep (1);
}
Asia 2173
North America 340
Europe 172
South America 134

View File

@ -1,8 +0,0 @@
($3 > 0) {
print $1,($2 * $3);
}
Kathy 40
Mark 100
Mary 121
Susie 76.5

View File

@ -1,6 +0,0 @@
($3 == 0) {
print $1;
}
Beth
Dan

View File

@ -1,10 +0,0 @@
{
print NF,$1,$NF;
}
3 Beth 0
3 Dan 0
3 Kathy 10
3 Mark 20
3 Mary 22
3 Susie 18

View File

@ -1,10 +0,0 @@
{
print NR,$0;
}
1 Beth 4.00 0
2 Dan 3.74 0
3 Kathy 4.00 10
4 Mark 5.00 20
5 Mary 5.50 22
6 Susie 4.25 18

View File

@ -1,10 +0,0 @@
{
print "total pay for",$1,"is",($2 * $3);
}
total pay for Beth is 0
total pay for Dan is 0
total pay for Kathy is 40
total pay for Mark is 100
total pay for Mary is 121
total pay for Susie is 76.5

View File

@ -1,10 +0,0 @@
{
printf ("total pay for %s is $%.2f\n",$1,($2 * $3));
}
total pay for Beth is $0.00
total pay for Dan is $0.00
total pay for Kathy is $40.00
total pay for Mark is $100.00
total pay for Mary is $121.00
total pay for Susie is $76.50

View File

@ -1,10 +0,0 @@
{
printf ("%-8s $%6.2f\n",$1,($2 * $3));
}
Beth $ 0.00
Dan $ 0.00
Kathy $ 40.00
Mark $100.00
Mary $121.00
Susie $ 76.50

View File

@ -1,4 +0,0 @@
($2 >= 5)
Mark 5.00 20
Mary 5.50 22

View File

@ -1,7 +0,0 @@
(($2 * $3) > 50) {
printf ("$%.2f for %s\n",($2 * $3),$1);
}
$100.00 for Mark
$121.00 for Mary
$76.50 for Susie

View File

@ -1,3 +0,0 @@
($1 == "Susie")
Susie 4.25 18

View File

@ -1,3 +0,0 @@
/Susie/
Susie 4.25 18

View File

@ -1,7 +0,0 @@
(($2 >= 4) || ($3 >= 20))
Beth 4.00 0
Kathy 4.00 10
Mark 5.00 20
Mary 5.50 22
Susie 4.25 18

View File

@ -1,11 +0,0 @@
($2 >= 4)
($3 >= 20)
Beth 4.00 0
Kathy 4.00 10
Mark 5.00 20
Mark 5.00 20
Mary 5.50 22
Mary 5.50 22
Susie 4.25 18

View File

@ -1,7 +0,0 @@
(!((($2 < 4) && ($3 < 20))))
Beth 4.00 0
Kathy 4.00 10
Mark 5.00 20
Mary 5.50 22
Susie 4.25 18

View File

@ -1,20 +0,0 @@
(NF != 3) {
print $0,"number of fields is not equal to 3";
}
($2 < 3.35) {
print $0,"rate is below minimum wage";
}
($2 > 10) {
print $0,"rate exceeds $10 per hour";
}
($3 < 0) {
print $0,"negative hours worked";
}
($3 > 60) {
print $0,"too many hours worked";
}

View File

@ -1,17 +0,0 @@
BEGIN {
print "NAME RATE HOURS";
print "";
}
{
print;
}
NAME RATE HOURS
Beth 4.00 0
Dan 3.74 0
Kathy 4.00 10
Mark 5.00 20
Mary 5.50 22
Susie 4.25 18

View File

@ -1,8 +0,0 @@
($3 > 15) {
emp = (emp + 1);
}
END {
print emp,"employees worked more than 15 hours";
}
3 employees worked more than 15 hours

View File

@ -1,4 +0,0 @@
END {
print NR,"employees";
}
6 employees

View File

@ -1,12 +0,0 @@
{
pay = (pay + ($2 * $3));
}
END {
print NR,"employees";
print "total pay is",pay;
print "average pay is",(pay / NR);
}
6 employees
total pay is 337.5
average pay is 56.25

View File

@ -1,9 +0,0 @@
($2 > maxrate) {
maxrate = $2;
maxemp = $1;
}
END {
print "highest hourly rage:",maxrate,"for",maxemp;
}
highest hourly rage: 5.50 for Mary

View File

@ -1,8 +0,0 @@
{
names = ((names $1) " ");
}
END {
print names;
}
Beth Dan Kathy Mark Mary Susie

View File

@ -1,8 +0,0 @@
{
last = $0;
}
END {
print last;
}
Susie 4.25 18

View File

@ -1,10 +0,0 @@
{
print $1,length ($1);
}
Beth 4
Dan 3
Kathy 5
Mark 4
Mary 4
Susie 5

View File

@ -1,9 +0,0 @@
{
nc = ((nc + length ($0)) + 1);
nw = (nw + NF);
}
END {
print NR,"lines,",nw,"words,",nc,"characters";
}
6 lines, 18 words, 77 characters

View File

@ -1,12 +0,0 @@
($2 > 6) {
n = (n + 1);
pay = (pay + ($2 * $3));
}
END {
if ((n > 0))
print n,"employees, total pay is",pay,"average pay is",(pay / n);
else
print "no employees are paid more than $6/hour";
}
no employees are paid more than $6/hour

View File

@ -1,18 +0,0 @@
{
line[NR] = $0;
}
END {
i = NR;
while ((i > 0))
{
print line[i];
i = (i - 1);
}
}
Susie 4.25 18
Mary 5.50 22
Mark 5.00 20
Kathy 4.00 10
Dan 3.74 0
Beth 4.00 0

View File

@ -1,15 +0,0 @@
{
line[NR] = $0;
}
END {
i = NR;
for (i = NR; (i > 0); i = (i - 1))
print line[i];
}
Susie 4.25 18
Mary 5.50 22
Mark 5.00 20
Kathy 4.00 10
Dan 3.74 0
Beth 4.00 0

View File

@ -1,6 +0,0 @@
베쓰 4.00 0
단 3.74 0
케이티 4.00 10
마크 5.00 20
메리 5.50 22
수지 4.25 18

View File

@ -1 +0,0 @@
Main-Class: QseAwk

View File

@ -1,8 +0,0 @@
cd ..\..\..
move ase\cmd\awk\AwkApplet*.class .
jar cvf AwkApplet.jar *.class ase\cmd\awk\*.class ase\awk\*.class
move AwkApplet.jar ase\cmd\awk
cd ase\cmd\awk
copy ..\..\awk\aseawk_jni.dll .
jarsigner -keystore ase.store AwkApplet.jar asecert

View File

@ -1,20 +0,0 @@
# wordfreq.awk --- print list of word frequencies
{
$0 = tolower($0); # remove case distinctions
# remove punctuation
a=0;
gsub(/[^[:alnum:]_[:blank:]]/, " ", $a);
#gsub(/[^[:alnum:]_[:blank:]]/, " ");
for (i = 1; i <= NF; i++) freq[$i]++;
}
#/[^kkka-bcx-dd-y]|abc|def/
END {
for (word in freq)
print word, freq[word];
}

View File

@ -1,5 +1,5 @@
/* /*
* $Id: Awk.hpp 212 2009-06-25 07:39:27Z hyunghwan.chung $ * $Id: Awk.hpp 213 2009-06-26 13:05:19Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
@ -509,8 +509,8 @@ public:
ERR_FNCUSER = QSE_AWK_EFNCUSER, ERR_FNCUSER = QSE_AWK_EFNCUSER,
ERR_FNCIMPL = QSE_AWK_EFNCIMPL, ERR_FNCIMPL = QSE_AWK_EFNCIMPL,
ERR_IOUSER = QSE_AWK_EIOUSER, ERR_IOUSER = QSE_AWK_EIOUSER,
ERR_IONONE = QSE_AWK_EIONONE,
ERR_IOIMPL = QSE_AWK_EIOIMPL, ERR_IOIMPL = QSE_AWK_EIOIMPL,
ERR_IONMNF = QSE_AWK_EIONMNF,
ERR_IONMEM = QSE_AWK_EIONMEM, ERR_IONMEM = QSE_AWK_EIONMEM,
ERR_IONMNL = QSE_AWK_EIONMNL, ERR_IONMNL = QSE_AWK_EIONMNL,
ERR_FMTARG = QSE_AWK_EFMTARG, ERR_FMTARG = QSE_AWK_EFMTARG,

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk.h 212 2009-06-25 07:39:27Z hyunghwan.chung $ * $Id: awk.h 213 2009-06-26 13:05:19Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
@ -655,8 +655,8 @@ enum qse_awk_errnum_t
QSE_AWK_EFNCUSER, /* wrong intrinsic function implementation */ QSE_AWK_EFNCUSER, /* wrong intrinsic function implementation */
QSE_AWK_EFNCIMPL, /* intrinsic function handler failed */ QSE_AWK_EFNCIMPL, /* intrinsic function handler failed */
QSE_AWK_EIOUSER, /* wrong user io handler implementation */ QSE_AWK_EIOUSER, /* wrong user io handler implementation */
QSE_AWK_EIONONE, /* no such io name found */
QSE_AWK_EIOIMPL, /* i/o callback returned an error */ QSE_AWK_EIOIMPL, /* i/o callback returned an error */
QSE_AWK_EIONMNF, /* no such io name found */
QSE_AWK_EIONMEM, /* i/o name empty */ QSE_AWK_EIONMEM, /* i/o name empty */
QSE_AWK_EIONMNL, /* i/o name contains '\0' */ QSE_AWK_EIONMNL, /* i/o name contains '\0' */
QSE_AWK_EFMTARG, /* arguments to format string not sufficient */ QSE_AWK_EFMTARG, /* arguments to format string not sufficient */

View File

@ -1,5 +1,5 @@
/* /*
* $Id: err.c 212 2009-06-25 07:39:27Z hyunghwan.chung $ * $Id: err.c 213 2009-06-26 13:05:19Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
@ -39,7 +39,7 @@ const qse_char_t* qse_awk_dflerrstr (qse_awk_t* awk, qse_awk_errnum_t errnum)
QSE_T("file or data too big"), QSE_T("file or data too big"),
QSE_T("system too busy"), QSE_T("system too busy"),
QSE_T("is a directory"), QSE_T("is a directory"),
QSE_T("i/o error"), QSE_T("IO error"),
QSE_T("cannot open '${0}'"), QSE_T("cannot open '${0}'"),
QSE_T("cannot read '${0}'"), QSE_T("cannot read '${0}'"),
@ -143,10 +143,10 @@ const qse_char_t* qse_awk_dflerrstr (qse_awk_t* awk, qse_awk_errnum_t errnum)
QSE_T("wrong implementation of intrinsic function handler"), QSE_T("wrong implementation of intrinsic function handler"),
QSE_T("intrinsic function handler returned an error"), QSE_T("intrinsic function handler returned an error"),
QSE_T("wrong implementation of user-defined io handler"), QSE_T("wrong implementation of user-defined io handler"),
QSE_T("no such io name found"), QSE_T("IO handler returned an error"),
QSE_T("i/o handler returned an error"), QSE_T("no such IO name found"),
QSE_T("i/o name empty"), QSE_T("IO name empty"),
QSE_T("i/o name '${0}' containing a null character"), QSE_T("IO name '${0}' containing a null character"),
QSE_T("not sufficient arguments to formatting sequence"), QSE_T("not sufficient arguments to formatting sequence"),
QSE_T("recursion detected in format conversion"), QSE_T("recursion detected in format conversion"),
QSE_T("invalid character in CONVFMT"), QSE_T("invalid character in CONVFMT"),

View File

@ -1,5 +1,5 @@
/* /*
* $Id: fnc.c 211 2009-06-24 09:50:10Z hyunghwan.chung $ * $Id: fnc.c 213 2009-06-26 13:05:19Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
@ -282,7 +282,7 @@ static int fnc_close (
n = qse_awk_rtx_closeio (run, name); n = qse_awk_rtx_closeio (run, name);
/* /*
if (n == -1 && run->errinf.num != QSE_AWK_EIONONE) if (n == -1 && run->errinf.num != QSE_AWK_EIONMNF)
{ {
if (a0->type != QSE_AWK_VAL_STR) if (a0->type != QSE_AWK_VAL_STR)
QSE_AWK_FREE (run->awk, name); QSE_AWK_FREE (run->awk, name);
@ -316,13 +316,13 @@ static int flush_io (
{ {
/* /*
if (run->errinf.num == QSE_AWK_EIOIMPL) n = -1; if (run->errinf.num == QSE_AWK_EIOIMPL) n = -1;
else if (run->errinf.num == QSE_AWK_EIONONE) else if (run->errinf.num == QSE_AWK_EIONMNF)
{ {
if (n != 0) n = -2; if (n != 0) n = -2;
} }
else n = -99; else n = -99;
*/ */
if (run->errinf.num == QSE_AWK_EIONONE) if (run->errinf.num == QSE_AWK_EIONMNF)
{ {
if (n != 0) n = -2; if (n != 0) n = -2;
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: parse.c 212 2009-06-25 07:39:27Z hyunghwan.chung $ * $Id: parse.c 213 2009-06-26 13:05:19Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
@ -3039,11 +3039,15 @@ static qse_awk_nde_t* parse_primary (qse_awk_t* awk, qse_size_t line)
{ {
qse_awk_nde_t* tmp; qse_awk_nde_t* tmp;
do
{
if (get_token(awk) <= -1) if (get_token(awk) <= -1)
{ {
qse_awk_clrpt (awk, nde); qse_awk_clrpt (awk, nde);
return QSE_NULL; return QSE_NULL;
} }
}
while (MATCH(awk,TOKEN_NEWLINE));
tmp = parse_expression (awk, awk->token.line); tmp = parse_expression (awk, awk->token.line);
if (tmp == QSE_NULL) if (tmp == QSE_NULL)
@ -4635,7 +4639,8 @@ static int get_token (qse_awk_t* awk)
} }
else if (c == QSE_T('\n')) else if (c == QSE_T('\n'))
{ {
ADD_TOKEN_CHAR (awk, QSE_T('\n')); /*ADD_TOKEN_CHAR (awk, QSE_T('\n'));*/
ADD_TOKEN_STR (awk, QSE_T("<NL>"), 4);
SET_TOKEN_TYPE (awk, TOKEN_NEWLINE); SET_TOKEN_TYPE (awk, TOKEN_NEWLINE);
GET_CHAR (awk); GET_CHAR (awk);
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: rio.c 207 2009-06-22 13:01:28Z hyunghwan.chung $ * $Id: rio.c 213 2009-06-26 13:05:19Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
@ -634,7 +634,7 @@ int qse_awk_rtx_flushio (
if (ok) return 0; if (ok) return 0;
/* there is no corresponding rio for name */ /* there is no corresponding rio for name */
qse_awk_rtx_seterrnum (run, QSE_AWK_EIONONE); qse_awk_rtx_seterrnum (run, QSE_AWK_EIONMNF);
return -1; return -1;
} }
@ -844,7 +844,7 @@ int qse_awk_rtx_closio_read (
} }
/* the name given is not found */ /* the name given is not found */
qse_awk_rtx_seterrnum (run, QSE_AWK_EIONONE); qse_awk_rtx_seterrnum (run, QSE_AWK_EIONMNF);
return -1; return -1;
} }
@ -903,7 +903,7 @@ int qse_awk_rtx_closio_write (
p = p->next; p = p->next;
} }
qse_awk_rtx_seterrnum (run, QSE_AWK_EIONONE); qse_awk_rtx_seterrnum (run, QSE_AWK_EIONMNF);
return -1; return -1;
} }
@ -945,7 +945,7 @@ int qse_awk_rtx_closeio (qse_awk_rtx_t* run, const qse_char_t* name)
p = p->next; p = p->next;
} }
qse_awk_rtx_seterrnum (run, QSE_AWK_EIONONE); qse_awk_rtx_seterrnum (run, QSE_AWK_EIONMNF);
return -1; return -1;
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: run.c 210 2009-06-24 08:29:33Z hyunghwan.chung $ * $Id: run.c 213 2009-06-26 13:05:19Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
@ -2934,6 +2934,9 @@ static int run_print (qse_awk_rtx_t* run, qse_awk_nde_print_t* nde)
return -1; return -1;
} }
/* unlike printf, flushio() is not needed here as print
* inserts <NL> that triggers auto-flush */
if (out != QSE_NULL) QSE_AWK_FREE (run->awk, out); if (out != QSE_NULL) QSE_AWK_FREE (run->awk, out);
/*skip_write:*/ /*skip_write:*/
@ -3069,10 +3072,13 @@ static int run_printf (qse_awk_rtx_t* run, qse_awk_nde_print_t* nde)
} }
qse_awk_rtx_refdownval (run, v); qse_awk_rtx_refdownval (run, v);
if (out != QSE_NULL) QSE_AWK_FREE (run->awk, out);
/*skip_write:*/ /*skip_write:*/
return qse_awk_rtx_flushio (run, nde->out_type, dst); n = qse_awk_rtx_flushio (run, nde->out_type, dst);
if (out != QSE_NULL) QSE_AWK_FREE (run->awk, out);
return n;
} }
static int output_formatted ( static int output_formatted (
@ -4045,7 +4051,7 @@ static int __cmp_int_str (
qse_awk_rtx_valtostr_out_t out; qse_awk_rtx_valtostr_out_t out;
int n; int n;
if (rtx->awk->option & QSE_AWK_NCMPONSTR) if (rtx->awk->option & QSE_AWK_NCMPONSTR || right->nstr > 0)
{ {
qse_long_t ll; qse_long_t ll;
qse_real_t rr; qse_real_t rr;
@ -4131,7 +4137,7 @@ static int __cmp_real_str (
qse_awk_rtx_valtostr_out_t out; qse_awk_rtx_valtostr_out_t out;
int n; int n;
if (rtx->awk->option & QSE_AWK_NCMPONSTR) if (rtx->awk->option & QSE_AWK_NCMPONSTR || right->nstr > 0)
{ {
const qse_char_t* end; const qse_char_t* end;
qse_real_t rr; qse_real_t rr;

View File

@ -1,14 +0,0 @@
ld zero # initialize sum to zero
st sum
loop get # read a number
jz done # no more input if number is zero
add sum # add in accumulated sum
st sum # store new value back in sum
j loop # go back and read another number
done ld sum # print sum
put
halt
zero const 0
sum const

View File

@ -1,6 +0,0 @@
Beth 4.00 0
Dan 3.74 0
Kathy 4.00 10
Mark 5.00 20
Mary 5.50 22
Susie 4.25 18

View File

@ -0,0 +1,56 @@
#.H1 indent.awk
#.H2 Synopsis
#.P gawk -f indent.awk file.sh
#.H2 Download
#.P Download from <a href="http://lawker.googlecode.com/svn/fridge/lib/awk/indent.awk">LAWKER</a>
#.h2 Description
#.P
# This is part of Phil's AWK tutorial at
#<a href="http://www.bolthole.com/AWK.html">http://www.bolthole.com/AWK.html</a>.
# This program adjusts the indentation level based on which keywords are
# found in each line it encounters.
#.h2 Code
#.H3 doindent
#.PRE
function doindent(){
tmpindent=indent;
if(indent<0){
print "ERROR; indent level == " indent
}
while(tmpindent >0){
printf(" ");
tmpindent-=1;
}
}
#./PRE
#.H3 Out-denting
#.PRE
$1 == "done" { indent -=1; }
$1 == "fi" { indent -=1; }
$0 ~ /^}$/ { if(indent!=0) indent-=1; }
#./PRE
#.H3 Worker
#.P
# This is the 'default' action, that actually prints a line out.
# This gets called AS WELL AS any other matching clause, in the
# order they appear in this program.
# An "if" match is run AFTER we run this clause.
# A "done" match is run BEFORE we run this clause.
#.PRE
{
doindent();
print $0;
}
#./PRE
#.H3 In-denting
#.PRE
$0 ~ /if.*;[ ]*then/ { indent+=1; }
$0 ~ /for.*;[ ]*do/ { indent+=1; }
$0 ~ /while.*;[ ]*do/ { indent+=1; }
$1 == "then" { indent+=1; }
$1 == "do" { indent+=1; }
$0 ~ /^{$/ { indent+=1; }
#./PRE
#.H2 Author
#.P Philip Brown phil@bolthole.com

Some files were not shown because too many files have changed in this diff Show More