Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1754640
  • 博文数量: 787
  • 博客积分: 10000
  • 博客等级: 上将
  • 技术积分: 5015
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-22 15:17
文章分类

全部博文(787)

文章存档

2008年(787)

我的朋友

分类:

2008-10-09 10:28:47

--------------------------------------------------------------------
[005目录结构]
--------------------------------------------------------------------
.
|-- book-2008-08-24
|-- install.sh
|-- judge.sh
|-- readme
`-- sample.sh

0 directories, 5 files

--------------------------------------------------------------------
[./readme]
--------------------------------------------------------------------
程序功能:
类似于JudgeOnline的程序本地测试工具

安装方法:
./install.sh

使用说明:
1.sample.sh
(1)
首次运行sample.sh
生成
input/
output/
standard/
tmp/
提示异常退出不用理会
(2)
测试数据放于input/中,测试数据文件后缀为.in
即使不用输入数据的程序也应放入一个新建文件,后缀为.in
(3)
标准源程序编译后,生成a.out
将a.out放在standard/
(4)
运行sample.sh即可生成对应测试数据的结果于output/
供judge.sh使用
2.judge.sh
(1)
先确认运行了sample.sh,已经配置好标准数据环境
(2)
运行judge.sh source_file_name
即可查看程序运行结果是否正确,是否符合标准答案

注意:
本程序目前只支持c,c++和pascal源代码


--------------------------------------------------------------------
[./judge.sh]
--------------------------------------------------------------------
#!/bin/sh
#程序名称:JudgeOnline本地练习版
#联系方式:babyaries@126.com
#查看程序运行时间: /usr/bin/time -f "time(s):%e memory(kb):%t" judge.sh main.c

e_param_error=65
info="程序异常退出!"
infile=
filenum=0

process_gcc()
{
    gcc "$1"
    if [ $? -ne 0 ] ; then
    echo "源代码"$1"语法错误"
    echo "$info"
    exit 1
    fi
}

process_fpc()
{
    fpc -oa.out "$1"
    if [ $? -ne 0 ] ; then
    echo "源代码"$1"语法错误"
    echo "$info"
    exit 1
    fi
}

compare()
{
    for name in input/*
    do
    if [ -f "$name" ] ; then
        case "$name" in
        *.in)
            get_filename "$name"
            output
            judge
            filenum=$(($filenum+1))
            ;;
        esac
    fi
    done
}

get_filename()
{
    infile=${1##*/};
    infile=${infile%%.*}
}

output()
{
    /usr/bin/time -f "time(s):%e memory(kb):%t" ./a.out < input/"$infile".in > tmp/"$infile".out
}

judge()
{
    diff output/"$infile".out tmp/"$infile".out
    if [ $? -ne 0 ] ; then
    echo "$infile.in输出的数据和标准答案不符"
    exit 1
    fi
}

param_error()
{
    echo "usage: ./`basename "$0"` source_file_name"
    exit $e_param_error
}

if [ $# != 1 ] ; then
    param_error
fi

if [ ! -e "$1" ] ; then
    echo "$1 不存在"
    echo "$info"
    exit 1
fi

if [ ! -f "$1" ] ; then
    echo "$1 不是正规文件"
    echo "$info"
    exit 1
fi

case "$1" in
    *.c)
    process_gcc "$1"
    compare
    ;;
    *.cpp)
    process_gcc "$1"
    compare
    ;;
    *.pas)
    process_fpc "$1"
    compare
    ;;
    *)
    echo "$1 文件后缀不为c,cpp或pas"
    echo "$info"
    ;;
esac
if [ $filenum -eq 0 ] ; then
    echo "input文件夹内不存在标准数据文件"
    echo "$info"
fi
echo "答案正确!"
exit 0

--------------------------------------------------------------------
[./install.sh]
--------------------------------------------------------------------
#!/bin/sh
#程序名称:JudgeOnline本地练习版
#联系方式:babyaries@126.com

info="安装文件缺失,安装过程中断!"
name="JudgeOnline本地练习版"
installdir="/usr/local/bin/"

if [ ! -e sample.sh ] ; then
    echo "$info"
    exit 1
fi
if [ ! -e judge.sh ] ; then
    echo "$info"
    exit 1
fi

chmod +x sample.sh
chmod +x judge.sh
cp sample.sh "$installdir"
cp judge.sh "$installdir"

echo "$name安装成功!"
exit 0

--------------------------------------------------------------------
[./sample.sh]
--------------------------------------------------------------------
#!/bin/sh
#程序名称:JudgeOnline本地练习版
#联系方式:babyaries@126.com

#若不用get_filename() 去除最大匹配前缀要考虑用string=

checkfile=
infile=
filenum=0
info="目录结构不完整,程序中断!"

get_filename()
{
    infile=${1##*/}
    infile=${infile%%.*}
}

output()
{
    ./standard/a.out < input/"$infile".in > output/"$infile".out
}

echo "检查目录结构的完整性"
for checkfile in input output standard tmp
do
    if [ ! -e "$checkfile" ] ; then
        mkdir "$checkfile"
    fi
done
for checkfile in standard/a.out
do
    if [ ! -e "$checkfile" ] ; then
    echo "$info"
    exit 1
    fi
done
echo "目录结构检查完毕"

echo "开始制作judge.sh所需的标准数据文件"
for name in input/*
do
    if [ -f "$name" ] ; then
    case "$name" in
        *.in)
        get_filename "$name"
        output
        filenum=$(($filenum+1))
        ;;
    esac
    fi
done
echo "$filenum个标准数据文件制作完成!"
exit 0

--------------------next---------------------

阅读(494) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~