*** empty log message ***

This commit is contained in:
hyung-hwan 2006-11-19 07:45:46 +00:00
parent 635912a61b
commit b96d5d93f4
29 changed files with 308 additions and 30 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.c,v 1.116 2006-11-18 15:36:57 bacon Exp $
* $Id: awk.c,v 1.117 2006-11-19 07:45:46 bacon Exp $
*/
#include <ase/awk/awk.h>
@ -17,31 +17,17 @@
#if defined(_WIN32)
#include <windows.h>
#include <tchar.h>
#include <limits.h>
#include <assert.h>
#ifndef PATH_MAX
#define ASE_PATH_MAX 4096
#else
#define ASE_PATH_MAX PATH_MAX
#endif
#define xp_printf _tprintf
#define xp_assert assert
#pragma warning (disable: 4996)
#elif defined(__MSDOS__)
#include <limits.h>
#include <assert.h>
#include <ctype.h>
#include <stdlib.h>
#ifndef PATH_MAX
#define ASE_PATH_MAX 4096
#else
#define ASE_PATH_MAX PATH_MAX
#endif
#define xp_printf printf
#define xp_assert assert
#else

8
ase/test/awk/emp-001.out Normal file
View File

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

6
ase/test/awk/emp-002.out Normal file
View File

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

10
ase/test/awk/emp-003.out Normal file
View File

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

10
ase/test/awk/emp-004.out Normal file
View File

@ -0,0 +1,10 @@
{
print __global10,$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

10
ase/test/awk/emp-005.out Normal file
View File

@ -0,0 +1,10 @@
{
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

10
ase/test/awk/emp-006.out Normal file
View File

@ -0,0 +1,10 @@
{
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

10
ase/test/awk/emp-007.out Normal file
View File

@ -0,0 +1,10 @@
{
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

4
ase/test/awk/emp-008.out Normal file
View File

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

7
ase/test/awk/emp-009.out Normal file
View File

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

3
ase/test/awk/emp-010.out Normal file
View File

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

3
ase/test/awk/emp-011.out Normal file
View File

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

7
ase/test/awk/emp-012.out Normal file
View File

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

11
ase/test/awk/emp-013.out Normal file
View File

@ -0,0 +1,11 @@
($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

7
ase/test/awk/emp-014.out Normal file
View File

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

20
ase/test/awk/emp-015.out Normal file
View File

@ -0,0 +1,20 @@
(__global9 != 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";
}

17
ase/test/awk/emp-016.out Normal file
View File

@ -0,0 +1,17 @@
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

8
ase/test/awk/emp-017.out Normal file
View File

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

4
ase/test/awk/emp-018.out Normal file
View File

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

12
ase/test/awk/emp-019.out Normal file
View File

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

9
ase/test/awk/emp-020.out Normal file
View File

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

8
ase/test/awk/emp-021.out Normal file
View File

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

8
ase/test/awk/emp-022.out Normal file
View File

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

10
ase/test/awk/emp-023.out Normal file
View File

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

9
ase/test/awk/emp-024.out Normal file
View File

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

12
ase/test/awk/emp-025.out Normal file
View File

@ -0,0 +1,12 @@
($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

18
ase/test/awk/emp-026.out Normal file
View File

@ -0,0 +1,18 @@
{
line[__global10] = $0;
}
END {
i = __global10;
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

15
ase/test/awk/emp-027.out Normal file
View File

@ -0,0 +1,15 @@
{
line[__global10] = $0;
}
END {
i = __global10;
for (i = __global10; (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,21 +1,57 @@
#!/bin/sh
pid=$$
init()
{
for script in emp-???.awk
do
output=`echo $script | sed 's/\.awk$/.out/g'`
./awk $script emp-en.data > "$output"
done
}
for script in emp???.awk
do
output=`echo $script | sed 's/\.awk$/.out/g'`
./awk $script emp-en.data > "$output.$pid"
test()
{
pid=$$
for script in emp-???.awk
do
output=`echo $script | sed 's/\.awk$/.out/g'`
./awk $script emp-en.data > "$output.$pid"
diff $output "$output.$pid"
if [ $? -ne 0 ]
then
echo "###################################"
echo "PROBLEM(S) DETECTED IN $script.".
echo "###################################"
rm -f "$output.$pid"
break
fi
diff $output "$output.$pid"
if [ $? -ne 0 ]
then
echo "###################################"
echo "PROBLEM(S) DETECTED IN $script.".
echo "###################################"
rm -f "$output.$pid"
break
fi
done
}
#--------#
# main #
#--------#
if [ $# -ne 1 ]
then
echo "Usage: $0 init"
echo " $0 test"
exit 1
fi
if [ "$1" = "init" ]
then
init
elif [ "$1" = "test" ]
then
test
else
echo "Usage: $0 init"
echo " $0 test"
exit 1
fi
rm -f "$output.$pid"
done