diff --git a/README.md b/README.md index 04347757..0c6a7060 100755 --- a/README.md +++ b/README.md @@ -1,4 +1,24 @@ -**HZNUOJ 是基于 [HUSTOJ](https://github.com/zhblue/hustoj) 改造而来的,遵循GPL协议开源** +## **HZNUOJ 是基于 [HUSTOJ](https://github.com/zhblue/hustoj) 改造而来的,遵循GPL协议开源** + +目录 +-- +[优势](#%E4%BC%98%E5%8A%BF) + +[界面截图](#%E7%95%8C%E9%9D%A2%E6%88%AA%E5%9B%BE) + +[部署指南](#%E9%83%A8%E7%BD%B2%E6%8C%87%E5%8D%97) + +        [基于Docekr部署](#%E4%BD%BF%E7%94%A8docker%E6%8E%A8%E8%8D%90) + +        [基于源码部署](#%E4%BD%BF%E7%94%A8%E6%BA%90%E7%A0%81) + +        [功能配置](#%E5%8A%9F%E8%83%BD%E9%85%8D%E7%BD%AE) + +[使用教程](#%E4%BD%BF%E7%94%A8%E6%95%99%E7%A8%8B) + +[贡献代码/Bug反馈](#%E8%B4%A1%E7%8C%AE%E4%BB%A3%E7%A0%81bug%E5%8F%8D%E9%A6%88) + + # 优势 @@ -48,10 +68,12 @@ #### 自行build -在仓库根目录下: +下载源文件,在仓库根目录下执行build: ```bash -docker build -t hznuoj:latest -f docker/Dockerfile ./ +admin@ubuntu16:~$ git clone https://github.com/wlx65003/HZNUOJ.git +admin@ubuntu16:~$ cd HZNUOJ +admin@ubuntu16:~/HZNUOJ$ sudo docker build -t hznuoj:latest -f docker/Dockerfile ./ ``` 等待build完成即可。 @@ -67,13 +89,13 @@ HZNUOJ的Docker Hub主页:https://hub.docker.com/r/wlx65003/hznuoj ,会持 使用docker pull下载即可,由于HZNUOJ的Judger依赖较多,所以镜像很大,约1.2G,请耐心等待,或者自行寻找科学上网方式。最好还是自己build。 ```bash -docker pull wlx65003/hznuoj +admin@ubuntu16:~$ docker pull wlx65003/hznuoj ``` ### 启动容器 -``` -docker run -it --rm -p 90:80 --privileged hznuoj:latest +```bash +admin@ubuntu16:~$ docker run -it --rm -p 90:80 --privileged hznuoj:latest ``` 其中`-p 90:80`表示把容器的80端口映射到宿主机的90端口,可自行修改,可以直接改成http默认的80端口以省去网址里的端口号。 @@ -87,17 +109,91 @@ docker run -it --rm -p 90:80 --privileged hznuoj:latest ## 使用源码 -0. HZNUOJ目前只在Ubuntu16.04上跑过,在更高版本下判题机可能无法正常运行。 +1. HZNUOJ目前只在Ubuntu16.04上跑过,在更高版本下判题机可能无法正常运行。(**2020年12月已将判题机更新到hustoj的最新版本判题机,Ubuntu18/20都已适配。**) + +2. 下载源码,root权限运行`judger/install/install.sh` , 安装脚本会自动将系统默认更新源换成国内访问速度更快的阿里云更新源。 + 本地登录或者ssh远程登录Ubuntu16系统后,命令行下按顺序执行以下指令: + ```bash + admin@ubuntu16:~$ git clone https://github.com/wlx65003/HZNUOJ.git + admin@ubuntu16:~$ sudo bash HZNUOJ/judger/install/install.sh + ``` + + 在Ubuntu18中安装时,命令行下按顺序执行以下指令: + ```bash + admin@ubuntu18:~$ git clone https://github.com/wlx65003/HZNUOJ.git + admin@ubuntu18:~$ sudo bash HZNUOJ/judger/install/install-ubuntu18.04.sh + ``` + 源码或者还可以直接访问`https://github.com/wlx65003/HZNUOJ` 下载zip包 + +3. 安装完成后访问localhost、服务器IP或相应域名即可。 + +4. 若想在现存的hustoj上使用HZNUOJ,请参看[HZNUOJ常见问题列表/将hustoj升级为HZNUOJ(只迁移web部分,后台的判题机不变)](wiki/maintainer-manual.md), + +5. OJ的默认运行模式为OJ_OI_MODE=0 ACM竞赛模式,若要用于OI信息学奥赛训练,可以在安装前修改`/judger/install/judge.conf`OJ_OI_MODE=1,或在安装后运行/judger/install/**ch_OI_MODE.sh**脚本修改运行模式。 + +## 功能配置 + +### 原理 + +系统分为后台的Core(判题机)和前台的web(网站)两大部分。两个部分相对独立,通过数据库关联。判题机通过轮询数据库提取判题队列,生成判题信息回写数据库,web部分读取数据库显示在网页上。 + +若发现提交代码后无法判题,一直显示pending或者等待,请尝试服务器中运行以下命令重启判题机进程 +```bash +admin@ubuntu16:~$ sudo pkill -9 judged && sudo judged && ps -A | grep judged +若出现类似"xxxx ? 00:00:00 judged"的字样,说明进程重启成功 +``` + +更多原理和说明可参考[hustoj文档大全.pdf](https://github.com/zhblue/hustoj/wiki/hustoj文档大全.pdf)及[HZNUOJ常见问题列表](wiki/maintainer-manual.md) + +### 参数配置 + +Core判题机部分的配置文件为/home/judge/etc/judge.conf,web网站部分的配置文件为/home/judge/HZNUOJ/web/OJ/include/static.php + +详细的配置说明可以参看[HZNUOJ配置手册](wiki/Configuration.md)或者配置文件中的注释。 + +下面把几个可能会用到的功能配置参数说明一下: + +### 比赛模式切换 OJ_OI_MODE + +judge.conf中的OJ_OI_MODE负责标记判题机的判题模式是OI信息学奥赛模式还是ACM大学生程序设计竞赛模式。 + +#### OJ_OI_MODE = 0 +判题模式默认为ACM大学生程序设计竞赛模式,一旦有测试实例出错就停止运行,比赛根据 AC 数量排名。 + +#### OJ_OI_MODE = 1 +判题模式为OI信息学奥赛模式,即使有测试实例出错,它依旧会测试下去,比赛根据数据通过率排名,而不只看 AC 数量;另外会在status.php状态页中显示测试实例的通过率和程序最大运行时间。 + +可运行脚本快速修改或手动修改judge.conf文件 +```bash +执行源码目录下的 `judger/install/ch_OI_MODE.sh` ,按照提示操作即可 +admin@ubuntu16:~$ sudo bash HZNUOJ/judger/install/ch_OI_MODE.sh +``` + +### 判题WrongAnswer信息相关参数,输出模式切换 OJ_FULL_DIFF 和 对比信息查看开关 $OJ_SHOW_DIFF + +judge.conf中的OJ_FULL_DIFF负责标记判题机的错误信息对比说明输出模式,static.php中的$OJ_SHOW_DIFF负责控制用户是否有权限在reinfo.php页看到上述错误信息对比说明。 + +**OJ_FULL_DIFF的修改不会对老的判题WrongAnswer信息产生影响,除非修改后重新判题。** + +#### OJ_FULL_DIFF = 0 +部分输出模式,若有测试实例出错,将出错的各组测试实例数据的输出数据xx.out,以及代码运行结果输出到表`runtimeinfo`,供reinfo.php页调用显示。 + +#### OJ_FULL_DIFF = 1 +全输出模式,若有测试实例出错,将出错的各组测试实例数据的输入xx.in、输出数据xx.out,以及代码运行结果全部输出到表`runtimeinfo`,若将此类reinfo开放给选手,很容易因为in、out文件输入输出数据的泄露而导致恶意刷题,请谨慎使用。 + +#### $OJ_SHOW_DIFF = true +用户可以在reinfo.php页查看判题错误信息的对比说明。 + +#### $OJ_SHOW_DIFF = false +reinfo.php页会被禁止访问,用户不能查看判题错误信息的对比说明。 -1. 下载源码 - `git clone https://github.com/wlx65003/HZNUOJ.git` - 或者直接访问`https://github.com/wlx65003/HZNUOJ` 下载zip包 +### 代码相似度检测开关 OJ_SIM_ENABLE 和 $OJ_SIM -2. 若已安装mysql,请修改`intall.sh` `judge.conf` `/web/OJ/include/db_info.inc.php` 中的相应账户密码信息(默认为root/root)。若还未安装,请确保接下来安装mysql的过程中将用户名和密码都设成root。 +OJ_SIM_ENABLE负责标记判题机是否开启代码相似度检测,$OJ_SIM负责标记web部分的状态页上是否显示代码相似度检测的结果。 -3. 以root权限运行`judger/install/install.sh` , 请确保在目录 `judger/install/` 下 +通过配置judge.conf中的OJ_SIM_ENABLE = 1 和 static.php中的$OJ_SIM = true 开启代码相似度检测,也就是抄袭检查功能,但只针对AC的代码,不检测没通过的代码。 -4. 安装完成后访问localhost即可。 +判题机通过调用第三方应用程序SIM对**AC的提交代码**进行语法分析判读文本相似度,通过检验的代码将由判题机复制进题目数据的 ac 目录成为新的参考样本(基于此,长期开启本功能会占用大量硬盘存储空间)。 # 使用教程 diff --git a/judger/core/judge_client/judge_client.cc b/judger/core/judge_client/judge_client.cc index 799efb06..4d73b6f0 100755 --- a/judger/core/judge_client/judge_client.cc +++ b/judger/core/judge_client/judge_client.cc @@ -1,6 +1,6 @@ // -#define IGNORE_ESOL -// File: main.cc +#define IGNORE_ESOL //ignore the ending space char of lines while comparing +// File: judge_client.cc // Author: sempr // refacted by zhblue /* @@ -45,16 +45,15 @@ //#include #include #include -#include #include #include #include "okcalls.h" -#define STD_MB 1048576 +#define STD_MB 1048576LL #define STD_T_LIM 2 -#define STD_F_LIM (STD_MB << 5) -#define STD_M_LIM (STD_MB << 7) -#define BUFFER_SIZE 5120 +#define STD_F_LIM (STD_MB << 5) //default file size limit 32m ,2^5=32 +#define STD_M_LIM (STD_MB << 7) //default memory limit 128m ,2^7=128 +#define BUFFER_SIZE 4096 //default size of char buffer 5120 bytes #define OJ_WT0 0 #define OJ_WT1 1 @@ -73,12 +72,66 @@ /*copy from ZOJ http://code.google.com/p/zoj/source/browse/trunk/judge_client/client/tracer.cc?spec=svn367&r=367#39 */ +#ifdef __arm__ +struct user_regs_struct { + long uregs[18]; +}; +#define ARM_r7 uregs[7] +#define ARM_ORIG_r0 uregs[17] + +#define REG_SYSCALL ARM_r7 +#endif + +#ifdef __aarch64__ +#define NT_PRSTATUS 1 +#define NT_ARM_SYSTEM_CALL 0x404 +#define ARM_cpsr uregs[16] +#define ARM_pc uregs[15] +#define ARM_lr uregs[14] +#define ARM_sp uregs[13] +#define ARM_ip uregs[12] +#define ARM_fp uregs[11] +#define ARM_r10 uregs[10] +#define ARM_r9 uregs[9] +#define ARM_r8 regs[8] +#define ARM_r7 uregs[7] +#define ARM_r6 uregs[6] +#define ARM_r5 uregs[5] +#define ARM_r4 uregs[4] +#define ARM_r3 uregs[3] +#define ARM_r2 uregs[2] +#define ARM_r1 uregs[1] +#define ARM_r0 uregs[0] +#define ARM_ORIG_r0 uregs[17] +#define PTRACE_GETREGS PTRACE_GETREGSET +#define PTRACE_SETREGS PTRACE_SETREGSET +#define REG_SYSCALL regs[18] + +#endif + +#ifdef __mips__ + typedef unsigned long long uint64_t; + struct user_regs_struct{ + uint64_t uregs[38]; + }; + + + #define REG_V0 2 + #define REG_A0 4 + + #define mips_REG_V0 uregs[REG_V0] + #define REG_SYSCALL mips_REG_V0 + +#endif + #ifdef __i386 #define REG_SYSCALL orig_eax #define REG_RET eax #define REG_ARG0 ebx #define REG_ARG1 ecx -#else +#endif + +#ifdef __x86_64__ #define REG_SYSCALL orig_rax #define REG_RET rax #define REG_ARG0 rdi @@ -87,11 +140,11 @@ #endif static int DEBUG = 0; -static char host_name[BUFFER_SIZE]; -static char user_name[BUFFER_SIZE]; -static char password[BUFFER_SIZE]; -static char db_name[BUFFER_SIZE]; -static char oj_home[BUFFER_SIZE]; +static char host_name[BUFFER_SIZE/10]; +static char user_name[BUFFER_SIZE/10]; +static char password[BUFFER_SIZE/10]; +static char db_name[BUFFER_SIZE/10]; +static char oj_home[BUFFER_SIZE/10]; static char data_list[BUFFER_SIZE][BUFFER_SIZE]; static int data_list_len = 0; @@ -100,36 +153,51 @@ static int max_running; static int sleep_time; static int java_time_bonus = 5; static int java_memory_bonus = 512; -static char java_xms[BUFFER_SIZE]; -static char java_xmx[BUFFER_SIZE]; +static char java_xms[BUFFER_SIZE/10]; +static char java_xmx[BUFFER_SIZE/10]; static int sim_enable = 0; static int oi_mode = 0; static int full_diff = 0; static int use_max_time = 0; - +static int time_limit_to_total= 0; +static int total_time= 0; +static int copy_data= 0; static int http_judge = 0; -static char http_baseurl[BUFFER_SIZE]; +static char http_baseurl[BUFFER_SIZE/10]; + +static char http_username[BUFFER_SIZE/10]; +static char http_password[BUFFER_SIZE/10]; +static int http_download = 1; +static double cpu_compensation = 1.0; -static char http_username[BUFFER_SIZE]; -static char http_password[BUFFER_SIZE]; static int shm_run = 0; static char record_call = 0; static int use_ptrace = 1; static int compile_chroot = 1; static int turbo_mode = 0; - +static int python_free=0; static const char *tbname = "solution"; +int num_of_test = 0; //static int sleep_tmp; + +static int py2=1; // caution: py2=1 means default using py3 + #define ZOJ_COM #ifdef _mysql_h MYSQL *conn; #endif - -static char lang_ext[19][8] = {"c", "cc", "pas", "java", "rb", "sh", "py", - "php", "pl", "cs", "m", "bas", "scm", "c", "cc", "lua", "js", "go", "py"}; +static char jresult[14][4]={"PD","PR","CI","RJ","AC","PE","WA","TLE","MLE","OLE","RE","CE","CO","TR"}; +static char lang_ext[21][8] = {"c", "cc", "pas", "java", "rb", "sh", "py", + "php", "pl", "cs", "m", "bas", "scm", "c", "cc", "lua", "js", "go","sql","f95","m"}; //static char buf[BUFFER_SIZE]; +void print_arm_regs(long long unsigned int *d){ + for(int i=0;i<32;i++){ + printf("[%d]:%lld ",i,d[i]%CALL_ARRAY_SIZE); + } + printf("\n"); +} int data_list_has(char *file) { for (int i = 0; i < data_list_len; i++) @@ -164,9 +232,11 @@ long get_file_size(const char *filename) return (long)f_stat.st_size; } -void write_log(const char *fmt, ...) +void write_log(const char *_fmt, ...) { va_list ap; + char fmt[4096]; + strncpy(fmt, _fmt, 4096); char buffer[4096]; // time_t t = time(NULL); //int l; @@ -177,7 +247,7 @@ void write_log(const char *fmt, ...) fprintf(stderr, "openfile error!\n"); system("pwd"); } - va_start(ap, fmt); + va_start(ap, _fmt); //l = vsprintf(buffer, fmt, ap); fprintf(fp, "%s\n", buffer); @@ -195,13 +265,14 @@ int execute_cmd(const char *fmt, ...) va_start(ap, fmt); vsprintf(cmd, fmt, ap); - printf("%s\n", cmd); + if (DEBUG) printf("%s\n", cmd); ret = system(cmd); va_end(ap); return ret; } -const int call_array_size = 512; +const int call_array_size = CALL_ARRAY_SIZE; +unsigned int call_id = 0; int call_counter[call_array_size] = {0}; static char LANG_NAME[BUFFER_SIZE]; void init_syscalls_limits(int lang) @@ -244,7 +315,7 @@ void init_syscalls_limits(int lang) for (i = 0; i == 0 || LANG_BV[i]; i++) call_counter[LANG_BV[i]] = HOJ_MAX_LIMIT; } - else if (lang == 6 || lang == 18) + else if (lang == 6) { // Python for (i = 0; i == 0 || LANG_YV[i]; i++) call_counter[LANG_YV[i]] = HOJ_MAX_LIMIT; @@ -294,6 +365,28 @@ void init_syscalls_limits(int lang) for (i = 0; i == 0 || LANG_GOV[i]; i++) call_counter[LANG_GOV[i]] = HOJ_MAX_LIMIT; } + else if (lang == 18) + { //SQL(sqlite3) + for (i = 0; i == 0 || LANG_SQLV[i]; i++) + call_counter[LANG_SQLV[i]] = HOJ_MAX_LIMIT; + } + else if (lang == 19) + { //Fortran + for (i = 0; i == 0 || LANG_FV[i]; i++) + call_counter[LANG_FV[i]] = HOJ_MAX_LIMIT; + } + else if (lang == 20 ) + { //Matlab(Octave) + for (i = 0; i == 0 || LANG_MV[i]; i++) + call_counter[LANG_MV[i]] = HOJ_MAX_LIMIT; + } +#ifdef __aarch64__ + if (lang==3)call_counter[220]= 100; + else call_counter[220]= 1; +#else + call_counter[SYS_execve % call_array_size ]= 1; +#endif + printf("SYS_execve:%d\n",SYS_execve % call_array_size ); } int after_equal(char *c) @@ -324,11 +417,18 @@ bool read_buf(char *buf, const char *key, char *value) strcpy(value, buf + after_equal(buf)); trim(value); if (DEBUG) - printf("%s\n", value); + printf("%s=%s\n", key, value); return 1; } return 0; } +void read_double(char *buf, const char *key, double *value) +{ + char buf2[BUFFER_SIZE]; + if (read_buf(buf, key, buf2)) + sscanf(buf2, "%lf", value); +} + void read_int(char *buf, const char *key, int *value) { char buf2[BUFFER_SIZE]; @@ -393,8 +493,13 @@ void init_mysql_conf() read_int(buf, "OJ_USE_PTRACE", &use_ptrace); read_int(buf, "OJ_COMPILE_CHROOT", &compile_chroot); read_int(buf, "OJ_TURBO_MODE", &turbo_mode); + read_double(buf, "OJ_CPU_COMPENSATION", &cpu_compensation); + read_int(buf, "OJ_PYTHON_FREE", &python_free); + read_int(buf, "OJ_COPY_DATA", ©_data); + read_int(buf, "OJ_HTTP_DOWNLOAD", &http_download); + read_int(buf, "OJ_TIME_LIMIT_TO_TOTAL", &time_limit_to_total); } - //fclose(fp); + fclose(fp); } // fclose(fp); @@ -404,10 +509,6 @@ void init_mysql_conf() fscanf(fjobs, "%s", http_username); pclose(fjobs); } - if (strcmp(http_username, "HOSTNAME") == 0) - { - strcpy(http_username, getenv("HOSTNAME")); - } if (turbo_mode == 2) tbname = "solution2"; } @@ -505,26 +606,26 @@ const char *getFileNameFromPath(const char *path) return path; } -void make_diff_out_full(FILE *f1, FILE *f2, int c1, int c2, const char *path) +void make_diff_out_full(FILE *f1, FILE *f2, int c1, int c2, const char *path,const char * infile) { - execute_cmd("echo '========Failed test [%s]========='>>diff.out", getFileNameFromPath(path)); - execute_cmd("echo '------Top 100 lines of input------'>>diff.out"); - execute_cmd("head -100 data.in>>diff.out"); - execute_cmd("echo '------Top 100 lines of standard output-----'>>diff.out"); + execute_cmd("echo '========[%s]========='>>diff.out", getFileNameFromPath(path)); + execute_cmd("echo '------test in top 100 lines------'>>diff.out"); + execute_cmd("head -100 %s >>diff.out",infile); + execute_cmd("echo '------test out top 100 lines-----'>>diff.out"); execute_cmd("head -100 '%s'>>diff.out", path); - execute_cmd("echo '------Top 100 lines of user output-----'>>diff.out"); + execute_cmd("echo '------user out top 100 lines-----'>>diff.out"); execute_cmd("head -100 user.out>>diff.out"); - execute_cmd("echo '------Diff out 200 lines-----'>>diff.out"); - execute_cmd("diff '%s' user.out|head -200>>diff.out", path); + execute_cmd("echo '------diff out 200 lines-----'>>diff.out"); + execute_cmd("diff '%s' user.out -y|head -200>>diff.out", path); execute_cmd("echo '=============================='>>diff.out"); } void make_diff_out_simple(FILE *f1, FILE *f2, int c1, int c2, const char *path) { - execute_cmd("echo '========Failed test [%s]========='>>diff.out", getFileNameFromPath(path)); - execute_cmd("echo '=======Diff out 100 lines====='>>diff.out"); - execute_cmd("diff '%s' user.out|head -100>>diff.out", path); - execute_cmd("echo '=============================='>>diff.out"); + execute_cmd("echo '========[%s]========='>>diff.out", getFileNameFromPath(path)); + execute_cmd("echo 'Expected | Yours'>>diff.out"); + execute_cmd("diff '%s' user.out -y|head -100>>diff.out", path); + execute_cmd("echo '\n=============================='>>diff.out"); } /* @@ -532,7 +633,7 @@ void make_diff_out_simple(FILE *f1, FILE *f2, int c1, int c2, const char *path) * http://code.google.com/p/zoj/source/browse/trunk/judge_client/client/text_checker.cc#25 * */ -int compare_zoj(const char *file1, const char *file2) +int compare_zoj(const char *file1, const char *file2,const char * infile) { int ret = OJ_AC; int c1, c2; @@ -567,7 +668,7 @@ int compare_zoj(const char *file1, const char *file2) } if (c1 != c2) { - // Consecutive non-space characters should be all exactly the same + // Consecutive non-space characters should be all exactly the ifconfig|grep 'inet'|awk -F: '{printf $2}'|awk '{printf $1}'same ret = OJ_WA; goto end; } @@ -595,7 +696,7 @@ int compare_zoj(const char *file1, const char *file2) if (ret == OJ_WA || ret == OJ_PE) { if (full_diff) - make_diff_out_full(f1, f2, c1, c2, file1); + make_diff_out_full(f1, f2, c1, c2, file1,infile); else make_diff_out_simple(f1, f2, c1, c2, file1); } @@ -614,11 +715,11 @@ void delnextline(char s[]) s[--L] = 0; } -int compare(const char *file1, const char *file2) +int compare(const char *file1, const char *file2, const char * infile) { #ifdef ZOJ_COM //compare ported and improved from zoj don't limit file size - return compare_zoj(file1, file2); + return compare_zoj(file1, file2,infile); #endif #ifndef ZOJ_COM //the original compare from the first version of hustoj has file size limit @@ -703,18 +804,20 @@ void _update_solution_mysql(int solution_id, int result, int time, int memory, int sim, int sim_s_id, double pass_rate) { char sql[BUFFER_SIZE]; + char judger[BUFFER_SIZE/10]; + mysql_real_escape_string(conn, judger, http_username, strlen(http_username)); if (oi_mode) { sprintf(sql, - "UPDATE %s SET result=%d,time=%d,memory=%d,pass_rate=%f,judger='%s',judgetime=now() WHERE solution_id=%d LIMIT 1%c", - tbname, result, time, memory, pass_rate, http_username, solution_id, 0); + "UPDATE %s SET result=%d,time=%d,memory=%d,pass_rate=%f,judger='%s',judgetime=now() WHERE solution_id=%d ", + tbname, result, time, memory, pass_rate, judger, solution_id); } else { sprintf(sql, - "UPDATE %s SET result=%d,time=%d,memory=%d,judger='%s',judgetime=now() WHERE solution_id=%d LIMIT 1%c", - tbname, result, time, memory, http_username, solution_id, 0); + "UPDATE %s SET result=%d,time=%d,memory=%d,judger='%s',judgetime=now() WHERE solution_id=%d ", + tbname, result, time, memory,judger, solution_id); } // printf("sql= %s\n",sql); if (mysql_real_query(conn, sql, strlen(sql))) @@ -780,7 +883,7 @@ void _addceinfo_mysql(int solution_id) if (cend - ceinfo > 40000) break; } - cend = 0; + *cend = '\0'; end = sql; strcpy(end, "INSERT INTO compileinfo VALUES("); end += strlen(sql); @@ -846,6 +949,7 @@ void _addceinfo_http(int solution_id) if (cend - ceinfo > 40000) break; } + *cend='\0'; fclose(fp); ceinfo_encode = url_encode(ceinfo); FILE *ce = fopen("ce.post", "we"); @@ -890,7 +994,7 @@ void _addreinfo_mysql(int solution_id, const char *filename) if (rend - reinfo > 40000) break; } - rend = 0; + *rend = '\0'; end = sql; strcpy(end, "INSERT INTO runtimeinfo VALUES("); end += strlen(sql); @@ -923,6 +1027,7 @@ void _addreinfo_http(int solution_id, const char *filename) if (rend - reinfo > 40000) break; } + *rend = '\0'; fclose(fp); reinfo_encode = url_encode(reinfo); FILE *re = fopen("re.post", "we"); @@ -984,7 +1089,7 @@ void _update_user_mysql(char *user_id) { char sql[BUFFER_SIZE]; sprintf(sql, - "UPDATE `users` SET `solved`=(SELECT count(DISTINCT `problem_id`) FROM `solution` WHERE `user_id`=\'%s\' AND `result`=\'4\') WHERE `user_id`=\'%s\'", + "UPDATE `users` SET `solved`=(SELECT count(DISTINCT `problem_id`) FROM `solution` WHERE `user_id`=\'%s\' AND `result`=4) WHERE `user_id`=\'%s\'", user_id, user_id); if (mysql_real_query(conn, sql, strlen(sql))) write_log(mysql_error(conn)); @@ -1019,7 +1124,7 @@ void update_user(char *user_id) } } -void _update_problem_http(int pid) +void _update_problem_http(int pid,int cid) { const char *cmd = " wget --post-data=\"updateproblem=1&pid=%d\" --load-cookies=cookie --save-cookies=cookie --keep-session-cookies -q -O - \"%s/admin/problem_judge.php\""; @@ -1029,56 +1134,119 @@ void _update_problem_http(int pid) } #ifdef _mysql_h -void _update_problem_mysql(int p_id) +void _update_problem_mysql(int p_id,int cid) { char sql[BUFFER_SIZE]; + // if(cid>0){ //HZNUOJ的contest_problem表里面没有c_accepted字段 + // sprintf(sql, + // "UPDATE `contest_problem` SET `c_accepted`=(SELECT count(*) FROM `solution` WHERE `problem_id`=%d AND `result`=4 and contest_id=%d) WHERE `problem_id`=%d and contest_id=%d", + // p_id,cid, p_id,cid); + // printf("sql:[%s]\n",sql); + // if (mysql_real_query(conn, sql, strlen(sql))) + // write_log(mysql_error(conn)); + // } + sprintf(sql, - "UPDATE `problem` SET `accepted`=(SELECT count(*) FROM `solution` WHERE `problem_id`=\'%d\' AND `result`=\'4\') WHERE `problem_id`=\'%d\'", - p_id, p_id); + "UPDATE `problem` SET `accepted`=(SELECT count(*) FROM `solution` WHERE `problem_id`=%d AND `result`=4) WHERE `problem_id`=%d", + p_id, p_id); + printf("sql:[%s]\n",sql); if (mysql_real_query(conn, sql, strlen(sql))) write_log(mysql_error(conn)); + + // if(cid>0){//HZNUOJ的contest_problem表里面没有c_submit字段 + // sprintf(sql, + // "UPDATE `contest_problem` SET `c_submit`=(SELECT count(*) FROM `solution` WHERE `problem_id`=%d AND contest_id=%d) WHERE `problem_id`=%d and contest_id=%d", + // p_id,cid, p_id,cid); + // if (mysql_real_query(conn, sql, strlen(sql))) + // write_log(mysql_error(conn)); + // } + sprintf(sql, - "UPDATE `problem` SET `submit`=(SELECT count(*) FROM `solution` WHERE `problem_id`=\'%d\') WHERE `problem_id`=\'%d\'", - p_id, p_id); + "UPDATE `problem` SET `submit`=(SELECT count(*) FROM `solution` WHERE `problem_id`=%d) WHERE `problem_id`=%d", + p_id, p_id); if (mysql_real_query(conn, sql, strlen(sql))) write_log(mysql_error(conn)); + //动态计算题目分值 start + MYSQL_RES *res; + MYSQL_ROW row; + + // get user numbers + int user_cnt = 1; + sprintf(sql,"SELECT count(*) as num FROM `users` WHERE `solved`>10"); + mysql_real_query(conn, sql, strlen(sql)); + res = mysql_store_result(conn); + row = mysql_fetch_row(res); + if(atoi(row[0])>user_cnt) user_cnt = atoi(row[0]); + + // get AC user numbers + sprintf(sql,"SELECT count(DISTINCT `user_id`) AS num FROM `solution` WHERE `result`=4 AND `problem_id`=\'%d\'", p_id); + mysql_real_query(conn, sql, strlen(sql)); + res = mysql_store_result(conn); + row = mysql_fetch_row(res); + int solved_user = atoi(row[0]); + + // get submit user numbers + sprintf(sql,"SELECT count(DISTINCT `user_id`) AS num FROM `solution` WHERE `problem_id`=\'%d\'", p_id); + mysql_real_query(conn, sql, strlen(sql)); + res = mysql_store_result(conn); + row = mysql_fetch_row(res); + int submit_user = atoi(row[0]); + + if (res != NULL) + { + mysql_free_result(res); // free the memory + res = NULL; + } + + // calculate scores + float scores = 100.0 * (1 - (solved_user + submit_user / 2.0) / user_cnt); + if (scores < 10) scores = 10; + + sprintf(sql, + "UPDATE `problem` SET `solved_user`=\'%d\', `submit_user`=\'%d\',`score`=\'%f\' WHERE `problem_id`=\'%d\'", + solved_user, submit_user, scores, p_id); + if (mysql_real_query(conn, sql, strlen(sql))) + write_log(mysql_error(conn)); + //动态计算题目分值 end } #endif -void update_problem(int pid) +void update_problem(int pid,int cid) { if (http_judge) { - _update_problem_http(pid); + _update_problem_http(pid,cid); } else { #ifdef _mysql_h - _update_problem_mysql(pid); + _update_problem_mysql(pid,cid); #endif } } void umount(char *work_dir) { - execute_cmd("/bin/umount -f %s/proc", work_dir); - execute_cmd("/bin/umount -f %s/dev ", work_dir); - execute_cmd("/bin/umount -f %s/lib ", work_dir); - execute_cmd("/bin/umount -f %s/lib64 ", work_dir); - execute_cmd("/bin/umount -f %s/etc/alternatives ", work_dir); - execute_cmd("/bin/umount -f %s/usr ", work_dir); - execute_cmd("/bin/umount -f %s/bin ", work_dir); - execute_cmd("/bin/umount -f %s/proc ", work_dir); - execute_cmd("/bin/umount -f bin usr lib lib64 etc/alternatives proc dev "); - execute_cmd("/bin/umount -f %s/* ", work_dir); - execute_cmd("/bin/umount -f %s/log/* ", work_dir); - execute_cmd("/bin/umount -f %s/log/etc/alternatives ", work_dir); + execute_cmd("/bin/umount -f %s/proc 2>/dev/null", work_dir); + execute_cmd("/bin/umount -f %s/dev 2>/dev/null", work_dir); + execute_cmd("/bin/umount -f %s/lib 2>/dev/null", work_dir); + execute_cmd("/bin/umount -f %s/lib64 2>/dev/null", work_dir); + execute_cmd("/bin/umount -f %s/etc/alternatives 2>/dev/null", work_dir); + execute_cmd("/bin/umount -f %s/usr 2>/dev/null", work_dir); + execute_cmd("/bin/umount -f %s/bin 2>/dev/null", work_dir); + execute_cmd("/bin/umount -f %s/proc 2>/dev/null", work_dir); + chdir(work_dir); + //execute_cmd("/bin/umount -f bin usr lib lib64 etc/alternatives proc dev 2>/dev/null"); + execute_cmd("/bin/umount -f %s/* 2>/dev/null", work_dir); + execute_cmd("/bin/umount -f %s/log/* 2>/dev/null", work_dir); + execute_cmd("/bin/umount -f %s/log/etc/alternatives 2>/dev/null", work_dir); } int compile(int lang, char *work_dir) { + if( lang == 6 || lang == 16 ) return 0; // python / js don't compile int pid; - const char *CP_C[] = {"gcc", "Main.c", "-o", "Main", "-fno-asm", "-Wall", + const char *CP_C[] = {"gcc", "Main.c", "-o", "Main", "-O2", "-fmax-errors=10", "-Wall", "-lm", "--static", "-std=c99", "-DONLINE_JUDGE", NULL}; - const char *CP_X[] = {"g++", "-fno-asm", "-Wall", + const char *CP_X[] = {"g++", "-fno-asm", "-fmax-errors=10", "-Wall", "-lm", "--static", "-std=c++11", "-DONLINE_JUDGE", "-o", "Main", "Main.cc", NULL}; const char *CP_P[] = {"fpc", "Main.pas", "-Cs32000000", "-Sh", "-O2", "-Co", "-Ct", "-Ci", NULL}; @@ -1086,23 +1254,24 @@ int compile(int lang, char *work_dir) const char *CP_R[] = {"ruby", "-c", "Main.rb", NULL}; const char *CP_B[] = {"chmod", "+rx", "Main.sh", NULL}; - const char *CP_Y2[] = {"python2", "-m", "py_compile", "Main.py", NULL}; - const char *CP_Y3[] = {"python3", "-m", "py_compile", "Main.py", NULL}; + //const char * CP_Y[] = { "python", "-c", + // "import py_compile; py_compile.compile(r'Main.py')", NULL }; const char *CP_PH[] = {"php", "-l", "Main.php", NULL}; const char *CP_PL[] = {"perl", "-c", "Main.pl", NULL}; - const char *CP_CS[] = {"mcs", "-warn:0", "Main.cs", NULL}; + const char *CP_CS[] = {"mcs","-codepage:utf8", "-warn:0", "Main.cs", NULL}; const char *CP_OC[] = {"gcc", "-o", "Main", "Main.m", "-fconstant-string-class=NSConstantString", "-I", "/usr/include/GNUstep/", "-L", "/usr/lib/GNUstep/Libraries/", "-lobjc", "-lgnustep-base", NULL}; const char *CP_BS[] = {"fbc", "-lang", "qb", "Main.bas", NULL}; - const char *CP_CLANG[] = {"clang", "Main.c", "-o", "Main", "-fno-asm", "-Wall", + const char *CP_CLANG[] = {"clang", "Main.c", "-o", "Main", "-ferror-limit=10", "-fno-asm", "-Wall", "-lm", "--static", "-std=c99", "-DONLINE_JUDGE", NULL}; - const char *CP_CLANG_CPP[] = {"clang++", "Main.cc", "-o", "Main", "-fno-asm", "-Wall", + const char *CP_CLANG_CPP[] = {"clang++", "Main.cc", "-o", "Main", "-ferror-limit=10", "-fno-asm", "-Wall", "-lm", "--static", "-std=c++0x", "-DONLINE_JUDGE", NULL}; const char *CP_LUA[] = {"luac", "-o", "Main", "Main.lua", NULL}; //const char * CP_JS[] = { "js24","-c", "Main.js", NULL }; const char *CP_GO[] = {"go", "build", "-o", "Main", "Main.go", NULL}; + const char *CP_FORTRAN[] = {"f95", "-static", "-o", "Main", "Main.f95", NULL}; char javac_buf[7][32]; char *CP_J[7]; @@ -1122,25 +1291,42 @@ int compile(int lang, char *work_dir) if (pid == 0) { struct rlimit LIM; - LIM.rlim_max = 6; - LIM.rlim_cur = 6; + int cpu = 20; + if (lang == 3) + cpu = 30; + LIM.rlim_max = cpu; + LIM.rlim_cur = cpu; setrlimit(RLIMIT_CPU, &LIM); - alarm(6); - LIM.rlim_max = 10 * STD_MB; - LIM.rlim_cur = 10 * STD_MB; + alarm(cpu); + LIM.rlim_max = 100 * STD_MB; + LIM.rlim_cur = 100 * STD_MB; setrlimit(RLIMIT_FSIZE, &LIM); if (lang == 3 || lang == 17) { +#ifdef __mips__ + LIM.rlim_max = STD_MB << 12; + LIM.rlim_cur = STD_MB << 12; +#endif +#ifdef __arm__ LIM.rlim_max = STD_MB << 11; LIM.rlim_cur = STD_MB << 11; +#endif +#ifdef __i386__ + LIM.rlim_max = STD_MB << 11; + LIM.rlim_cur = STD_MB << 11; +#endif +#ifdef __x86_64__ + LIM.rlim_max = STD_MB << 12; + LIM.rlim_cur = STD_MB << 12; +#endif } else { - LIM.rlim_max = STD_MB * 256; - LIM.rlim_cur = STD_MB * 256; + LIM.rlim_max = STD_MB << 11 ; + LIM.rlim_cur = STD_MB << 11; } - setrlimit(RLIMIT_AS, &LIM); + if (lang != 3) setrlimit(RLIMIT_AS, &LIM); if (lang != 2 && lang != 11) { freopen("ce.txt", "w", stderr); @@ -1150,21 +1336,33 @@ int compile(int lang, char *work_dir) { freopen("ce.txt", "w", stdout); } + execute_cmd("/bin/chown judge %s ", work_dir); + execute_cmd("/bin/chmod 750 %s ", work_dir); + if (compile_chroot && lang != 3 && lang != 9 && lang != 6 && lang != 11) { execute_cmd("mkdir -p bin usr lib lib64 etc/alternatives proc tmp dev"); execute_cmd("chown judge *"); execute_cmd("mount -o bind /bin bin"); + execute_cmd("mount -o remount,ro bin"); execute_cmd("mount -o bind /usr usr"); + execute_cmd("mount -o remount,ro usr"); execute_cmd("mount -o bind /lib lib"); -#ifndef __i386 + execute_cmd("mount -o remount,ro lib"); +#ifndef __i386__ execute_cmd("mount -o bind /lib64 lib64"); + execute_cmd("mount -o remount,ro lib64"); #endif execute_cmd("mount -o bind /etc/alternatives etc/alternatives"); - execute_cmd("mount -o bind /proc proc"); - if (lang > 2 && lang != 10 && lang != 13 && lang != 14) - execute_cmd("mount -o bind /dev dev"); - printf("work_dir=%s\n", work_dir); + execute_cmd("mount -o remount,ro etc/alternatives"); + execute_cmd("mount -t proc /proc proc"); + if (lang > 2 && lang != 6 && lang != 10 && lang != 13 && lang != 14 && lang != 17) + { + execute_cmd("mkdir -p bin usr lib lib64 etc/alternatives proc tmp dev"); + //execute_cmd("mount -o bind /dev dev"); + //execute_cmd("mount -o remount,ro dev"); + } + //execute_cmd("mount -o remount,ro proc"); chroot(work_dir); } while (setgid(1536) != 0) @@ -1174,108 +1372,68 @@ int compile(int lang, char *work_dir) while (setresuid(1536, 1536, 1536) != 0) sleep(1); - char **compile_cmd = NULL; - int compile_execvp_res; switch (lang) { case 0: - compile_execvp_res = execvp(CP_C[0], (char *const *)CP_C); - compile_cmd = (char **)CP_C; + execvp(CP_C[0], (char *const *)CP_C); break; case 1: - compile_execvp_res = execvp(CP_X[0], (char *const *)CP_X); - compile_cmd = (char **)CP_X; + execvp(CP_X[0], (char *const *)CP_X); break; case 2: - compile_execvp_res = execvp(CP_P[0], (char *const *)CP_P); - compile_cmd = (char **)CP_P; + execvp(CP_P[0], (char *const *)CP_P); break; case 3: - compile_execvp_res = execvp(CP_J[0], (char *const *)CP_J); - compile_cmd = (char **)CP_J; + execvp(CP_J[0], (char *const *)CP_J); break; case 4: - compile_execvp_res = execvp(CP_R[0], (char *const *)CP_R); - compile_cmd = (char **)CP_R; + execvp(CP_R[0], (char *const *)CP_R); break; case 5: - compile_execvp_res = execvp(CP_B[0], (char *const *)CP_B); - compile_cmd = (char **)CP_B; - break; - case 6: - compile_execvp_res = execvp(CP_Y2[0], (char *const *)CP_Y2); - compile_cmd = (char **)CP_Y2; - break; - case 18: - compile_execvp_res = execvp(CP_Y3[0], (char *const *)CP_Y3); - compile_cmd = (char **)CP_Y3; + execvp(CP_B[0], (char *const *)CP_B); break; + //case 6: + // execvp(CP_Y[0], (char * const *) CP_Y); + // break; case 7: - compile_execvp_res = execvp(CP_PH[0], (char *const *)CP_PH); - compile_cmd = (char **)CP_PH; + execvp(CP_PH[0], (char *const *)CP_PH); break; case 8: - compile_execvp_res = execvp(CP_PL[0], (char *const *)CP_PL); - compile_cmd = (char **)CP_PL; + execvp(CP_PL[0], (char *const *)CP_PL); break; case 9: - compile_execvp_res = execvp(CP_CS[0], (char *const *)CP_CS); - compile_cmd = (char **)CP_CS; + execvp(CP_CS[0], (char *const *)CP_CS); break; case 10: - compile_execvp_res = execvp(CP_OC[0], (char *const *)CP_OC); - compile_cmd = (char **)CP_OC; + execvp(CP_OC[0], (char *const *)CP_OC); break; case 11: - compile_execvp_res = execvp(CP_BS[0], (char *const *)CP_BS); - compile_cmd = (char **)CP_BS; + execvp(CP_BS[0], (char *const *)CP_BS); break; case 13: - compile_execvp_res = execvp(CP_CLANG[0], (char *const *)CP_CLANG); - compile_cmd = (char **)CP_CLANG; + execvp(CP_CLANG[0], (char *const *)CP_CLANG); break; case 14: - compile_execvp_res = execvp(CP_CLANG_CPP[0], (char *const *)CP_CLANG_CPP); - compile_cmd = (char **)CP_CLANG_CPP; + execvp(CP_CLANG_CPP[0], (char *const *)CP_CLANG_CPP); break; case 15: - compile_execvp_res = execvp(CP_LUA[0], (char *const *)CP_LUA); - compile_cmd = (char **)CP_LUA; + execvp(CP_LUA[0], (char *const *)CP_LUA); break; //case 16: - // execvp(CP_JS[0], (char * const *) CP_JS); - // break; + // execvp(CP_JS[0], (char * const *) CP_JS); + // break; case 17: - compile_execvp_res = execvp(CP_GO[0], (char *const *)CP_GO); - compile_cmd = (char **)CP_GO; + execvp(CP_GO[0], (char *const *)CP_GO); + break; + case 19: + execvp(CP_FORTRAN[0], (char *const *)CP_FORTRAN); break; default: printf("nothing to do!\n"); } if (DEBUG) - { - printf("compile end!!!"); - if (compile_cmd != NULL) - { - // print compile cmd in execvp - printf("compile_cmd = "); - for (int i = 0; compile_cmd[i] != NULL; ++i) - { - printf("%s ", compile_cmd[i]); - } - printf("\n"); - - // explain execvp return value - printf("compile_execvp_res=%d\n", compile_execvp_res); - if (compile_execvp_res < 0) - { - fprintf(stdout, "%s\n", explain_execvp(compile_cmd[0], (char *const *)compile_cmd)); - exit(EXIT_FAILURE); - } - } - } - + printf("compile end!\n"); //exit(!system("cat ce.txt")); exit(0); } @@ -1288,8 +1446,8 @@ int compile(int lang, char *work_dir) status = get_file_size("ce.txt"); if (DEBUG) printf("status=%d\n", status); - execute_cmd("/bin/umount -f bin usr lib lib64 etc/alternatives proc dev 2>&1 >/dev/null"); - execute_cmd("/bin/umount -f %s/* 2>&1 >/dev/null", work_dir); + execute_cmd("/bin/umount -f bin usr lib lib64 etc/alternatives proc dev 2>/dev/null"); + execute_cmd("/bin/umount -f %s/* 2>/dev/null", work_dir); umount(work_dir); return status; @@ -1365,20 +1523,23 @@ void _get_solution_mysql(int solution_id, char *work_dir, int lang) solution_id); mysql_real_query(conn, sql, strlen(sql)); res = mysql_store_result(conn); - row = mysql_fetch_row(res); // create the src file - sprintf(src_pth, "Main.%s", lang_ext[lang]); if (DEBUG) printf("Main=%s", src_pth); - FILE *fp_src = fopen(src_pth, "we"); - fprintf(fp_src, "%s", row[0]); if (res != NULL) { - mysql_free_result(res); // free the memory - res = NULL; + row = mysql_fetch_row(res); + if(row != NULL) { + sprintf(src_pth, "Main.%s", lang_ext[lang]); + FILE *fp_src = fopen(src_pth, "we"); + fprintf(fp_src, "%s", row[0]); + mysql_free_result(res); // free the memory + res = NULL; + row = NULL; + fclose(fp_src); + } } - fclose(fp_src); } #endif void _get_solution_http(int solution_id, char *work_dir, int lang) @@ -1400,6 +1561,8 @@ void _get_solution_http(int solution_id, char *work_dir, int lang) } void get_solution(int solution_id, char *work_dir, int lang) { + char src_pth[BUFFER_SIZE]; + sprintf(src_pth, "Main.%s", lang_ext[lang]); if (http_judge) { _get_solution_http(solution_id, work_dir, lang); @@ -1411,6 +1574,10 @@ void get_solution(int solution_id, char *work_dir, int lang) _get_solution_mysql(solution_id, work_dir, lang); #endif } + if(lang == 6 ){ + py2 = execute_cmd("/bin/grep 'python2' %s/Main.py > /dev/null", work_dir); + } + execute_cmd("chown judge %s/%s", work_dir, src_pth); } #ifdef _mysql_h @@ -1418,6 +1585,7 @@ void _get_custominput_mysql(int solution_id, char *work_dir) { char sql[BUFFER_SIZE], src_pth[BUFFER_SIZE]; // get the source code + printf("geting custom input\n"); MYSQL_RES *res; MYSQL_ROW row; sprintf(sql, "SELECT input_text FROM custominput WHERE solution_id=%d", @@ -1436,6 +1604,7 @@ void _get_custominput_mysql(int solution_id, char *work_dir) } if (res != NULL) { + printf("no custom input\n"); mysql_free_result(res); // free the memory res = NULL; } @@ -1472,7 +1641,7 @@ void get_custominput(int solution_id, char *work_dir) #ifdef _mysql_h void _get_solution_info_mysql(int solution_id, int &p_id, char *user_id, - int &lang) + int &lang,int &cid) { MYSQL_RES *res; @@ -1488,14 +1657,14 @@ void _get_solution_info_mysql(int solution_id, int &p_id, char *user_id, //printf("%s\n",sql); mysql_real_query(conn, sql, strlen(sql)); sprintf(sql, - "SELECT problem_id, user_id, language FROM solution2 where solution_id=%d", + "SELECT problem_id, user_id, language,contest_id FROM solution2 where solution_id=%d", solution_id); //printf("%s\n",sql); } else { sprintf(sql, - "SELECT problem_id, user_id, language FROM solution where solution_id=%d", + "SELECT problem_id, user_id, language,contest_id FROM solution where solution_id=%d", solution_id); } //printf("%s\n",sql); @@ -1504,12 +1673,10 @@ void _get_solution_info_mysql(int solution_id, int &p_id, char *user_id, row = mysql_fetch_row(res); p_id = atoi(row[0]); strcpy(user_id, row[1]); - if (DEBUG) - { - printf("sql=%s\n", sql); - printf("lang_raw_str = %s\n", row[2]); - } lang = atoi(row[2]); + if(row[3]==NULL) cid=0; + else cid = atoi(row[3]); + printf("cid:%d\n",cid); if (res != NULL) { mysql_free_result(res); // free the memory @@ -1518,7 +1685,7 @@ void _get_solution_info_mysql(int solution_id, int &p_id, char *user_id, } #endif void _get_solution_info_http(int solution_id, int &p_id, char *user_id, - int &lang) + int &lang,int & cid) { login(); @@ -1529,26 +1696,26 @@ void _get_solution_info_http(int solution_id, int &p_id, char *user_id, fscanf(pout, "%d", &p_id); fscanf(pout, "%s", user_id); fscanf(pout, "%d", &lang); + fscanf(pout, "%d", &cid); pclose(pout); } void get_solution_info(int solution_id, int &p_id, char *user_id, - int &lang) -{ + int &lang,int & cid) { if (http_judge) { - _get_solution_info_http(solution_id, p_id, user_id, lang); + _get_solution_info_http(solution_id, p_id, user_id, lang,cid); } else { #ifdef _mysql_h - _get_solution_info_mysql(solution_id, p_id, user_id, lang); + _get_solution_info_mysql(solution_id, p_id, user_id, lang,cid); #endif } } #ifdef _mysql_h -void _get_problem_info_mysql(int p_id, int &time_lmt, int &mem_lmt, +void _get_problem_info_mysql(int p_id, double &time_lmt, int &mem_lmt, int &isspj) { // get the problem info from Table:problem @@ -1561,7 +1728,7 @@ void _get_problem_info_mysql(int p_id, int &time_lmt, int &mem_lmt, mysql_real_query(conn, sql, strlen(sql)); res = mysql_store_result(conn); row = mysql_fetch_row(res); - time_lmt = atoi(row[0]); + time_lmt = atof(row[0]); mem_lmt = atoi(row[1]); isspj = (row[2][0] == '1'); if (res != NULL) @@ -1571,7 +1738,7 @@ void _get_problem_info_mysql(int p_id, int &time_lmt, int &mem_lmt, } } #endif -void _get_problem_info_http(int p_id, int &time_lmt, int &mem_lmt, +void _get_problem_info_http(int p_id, double &time_lmt, int &mem_lmt, int &isspj) { //login(); @@ -1579,13 +1746,14 @@ void _get_problem_info_http(int p_id, int &time_lmt, int &mem_lmt, const char *cmd = "wget --post-data=\"getprobleminfo=1&pid=%d\" --load-cookies=cookie --save-cookies=cookie --keep-session-cookies -q -O - \"%s/admin/problem_judge.php\""; FILE *pout = read_cmd_output(cmd, p_id, http_baseurl); - fscanf(pout, "%d", &time_lmt); + fscanf(pout, "%lf", &time_lmt); fscanf(pout, "%d", &mem_lmt); fscanf(pout, "%d", &isspj); pclose(pout); + if(DEBUG) printf("time_lmt:%g\n",time_lmt); } -void get_problem_info(int p_id, int &time_lmt, int &mem_lmt, int &isspj) +void get_problem_info(int p_id, double &time_lmt, int &mem_lmt, int &isspj) { if (http_judge) { @@ -1632,10 +1800,10 @@ void prepare_files(char *filename, int namelen, char *infile, int &p_id, strncpy(fname0, filename, namelen); fname0[namelen] = 0; escape(fname, fname0); - printf("%s\n%s\n", fname0, fname); + //printf("%s\n%s\n",fname0,fname); sprintf(infile, "%s/data/%d/%s.in", oj_home, p_id, fname); - execute_cmd("/bin/cp '%s' %s/data.in", infile, work_dir); - execute_cmd("/bin/cp %s/data/%d/*.dic %s/", oj_home, p_id, work_dir); + if(copy_data) execute_cmd("/bin/cp '%s' %s/data.in", infile, work_dir); + execute_cmd("/bin/cp %s/data/%d/*.dic %s/ 2>/dev/null", oj_home, p_id, work_dir); sprintf(outfile, "%s/data/%d/%s.out", oj_home, p_id, fname0); sprintf(userfile, "%s/run%d/user.out", oj_home, runner_id); @@ -1647,16 +1815,40 @@ void copy_shell_runtime(char *work_dir) execute_cmd("/bin/mkdir %s/lib", work_dir); execute_cmd("/bin/mkdir %s/lib64", work_dir); execute_cmd("/bin/mkdir %s/bin", work_dir); +#ifdef __mips__ + execute_cmd("/bin/cp -a /lib/mips64el-linux-gnuabi64/ %s/lib/mips64el-linux-gnuabi64",work_dir); + execute_cmd("mkdir -p %s/lib/mips64el-linux-gnuabi64/",work_dir); + execute_cmd("/bin/cp -a /lib64/ld.so.1 %s/lib64/", work_dir); + execute_cmd("/bin/cp -a /lib/mips64el-linux-gnuabi64/libdl.so.2 %s/lib/mips64el-linux-gnuabi64", work_dir); + execute_cmd("/bin/cp -a /lib/mips64el-linux-gnuabi64/libutil.so.1 %s/lib/mips64el-linux-gnuabi64", work_dir); + execute_cmd("/bin/cp -a /lib/mips64el-linux-gnuabi64/libz.so.1 %s/lib/mips64el-linux-gnuabi64", work_dir); + execute_cmd("/bin/cp -a /lib/mips64el-linux-gnuabi64/libm.so.6 %s/lib/mips64el-linux-gnuabi64", work_dir); + execute_cmd("/bin/cp -a /lib/mips64el-linux-gnuabi64/libc.so.6 %s/lib/mips64el-linux-gnuabi64", work_dir); + execute_cmd("/bin/cp -a /lib/mips64el-linux-gnuabi64/libtinfo.so.5 %s/lib/mips64el-linux-gnuabi64", work_dir); + execute_cmd("/bin/cp -a /lib/mips64el-linux-gnuabi64/ld-2.24.so %s/lib/mips64el-linux-gnuabi64", work_dir); + execute_cmd("/bin/cp -a /lib/mips64el-linux-gnuabi64/libc-2.24.so %s/lib/mips64el-linux-gnuabi64", work_dir); + execute_cmd("/bin/cp -a /lib64/libc.so.6 %s/lib64/", work_dir); + execute_cmd("/bin/cp -a /lib64/libtinfo.so.6 %s/lib64/", work_dir); + execute_cmd("/bin/cp -a /lib64/ld-2.27.so %s/lib64/", work_dir); + execute_cmd("/bin/cp -a /lib64/libc-2.27.so %s/lib64/", work_dir); + execute_cmd("/bin/cp -a /lib64/libdl-2.27.so %s/lib64/", work_dir); + execute_cmd("/bin/cp -a /lib64/libtinfo.so.6.1 %s/lib64/", work_dir); + execute_cmd("cp /lib/mips64el-linux-gnuabi64/libpthread.so.0 %s/lib/mips64el-linux-gnuabi64/",work_dir); + execute_cmd("/bin/cp -a /bin/bash %s/bin/", work_dir); + +#endif #ifdef __i386 execute_cmd("/bin/cp /lib/ld-linux* %s/lib/", work_dir); - execute_cmd("/bin/cp -a /lib/i386-linux-gnu %s/lib/", work_dir); - execute_cmd("/bin/cp -a /usr/lib/i386-linux-gnu %s/lib/", work_dir); + execute_cmd("/bin/cp -a /lib/i386-linux-gnu/ %s/lib/", work_dir); +// execute_cmd("/bin/cp -a /usr/lib/i386-linux-gnu %s/lib/", work_dir); #endif - execute_cmd("/bin/cp -a /lib/x86_64-linux-gnu %s/lib/", work_dir); - execute_cmd("/bin/cp /lib64/* %s/lib64/", work_dir); - // execute_cmd("/bin/cp /lib32 %s/", work_dir); +#ifdef __x86_64__ + execute_cmd("mount -o bind /lib %s/lib", work_dir); + execute_cmd("mount -o bind /lib64 %s/lib64", work_dir); +#endif + // execute_cmd("/bin/cp /lib32 %s/", work_dir); execute_cmd("/bin/cp /bin/busybox %s/bin/", work_dir); execute_cmd("/bin/ln -s /bin/busybox %s/bin/sh", work_dir); execute_cmd("/bin/cp /bin/bash %s/bin/bash", work_dir); @@ -1765,9 +1957,11 @@ void copy_ruby_runtime(char *work_dir) execute_cmd("cp -a /usr/lib/ruby* %s/usr/lib/", work_dir); execute_cmd("cp -a /usr/lib64/ruby* %s/usr/lib64/", work_dir); execute_cmd("cp -a /usr/lib64/libruby* %s/usr/lib64/", work_dir); + execute_cmd("cp -a /usr/bin/ruby* %s/", work_dir); +#ifdef __x86_64__ execute_cmd("/bin/cp -a /usr/lib/x86_64-linux-gnu/libruby* %s/usr/lib/", work_dir); execute_cmd("/bin/cp -a /usr/lib/x86_64-linux-gnu/libgmp* %s/usr/lib/", work_dir); - execute_cmd("cp -a /usr/bin/ruby* %s/", work_dir); +#endif } void copy_guile_runtime(char *work_dir) @@ -1790,10 +1984,12 @@ void copy_guile_runtime(char *work_dir) execute_cmd("/bin/cp /usr/lib/*/libltdl* %s/usr/lib/", work_dir); execute_cmd("/bin/cp /usr/lib/libltdl* %s/usr/lib/", work_dir); execute_cmd("/bin/cp /usr/bin/guile* %s/", work_dir); +#ifdef __x86_64__ execute_cmd("/bin/cp -a /usr/lib/x86_64-linux-gnu/libguile* %s/usr/lib/", work_dir); execute_cmd("/bin/cp -a /usr/lib/x86_64-linux-gnu/libgc* %s/usr/lib/", work_dir); execute_cmd("/bin/cp -a /usr/lib/x86_64-linux-gnu/libffi* %s/usr/lib/", work_dir); execute_cmd("/bin/cp -a /usr/lib/x86_64-linux-gnu/libunistring* %s/usr/lib/", work_dir); +#endif } void copy_python_runtime(char *work_dir) @@ -1805,9 +2001,69 @@ void copy_python_runtime(char *work_dir) execute_cmd("mkdir -p %s/usr/lib", work_dir); execute_cmd("mkdir -p %s/usr/lib64", work_dir); execute_cmd("mkdir -p %s/usr/local/lib", work_dir); - execute_cmd("cp /usr/bin/python* %s/", work_dir); - execute_cmd("cp -a /usr/lib/python* %s/usr/lib/", work_dir); - execute_cmd("cp -a /usr/lib64/python* %s/usr/lib64/", work_dir); + execute_cmd("mkdir -p %s/lib/x86_64-linux-gnu", work_dir); + + // /etc/abrt/plugins/python.conf for Centos7 + execute_cmd("mkdir -p %s/etc/abrt", work_dir); + execute_cmd("mkdir -p %s/etc/abrt/plugins", work_dir); + execute_cmd("cp -a /etc/abrt/plugins/python.conf %s/etc/abrt/plugins/python.conf", work_dir); + + // /usr/share/abrt/conf.d/plugins/python.conf for Centos7 + execute_cmd("mkdir -p %s/usr/share", work_dir); + execute_cmd("mkdir -p %s/usr/share/abrt/", work_dir); + execute_cmd("mkdir -p %s/usr/share/abrt/conf.d", work_dir); + execute_cmd("mkdir -p %s/usr/share/abrt/conf.d/plugins", work_dir); + execute_cmd("cp -a /usr/share/abrt/conf.d/plugins/python.conf %s/usr/share/abrt/conf.d/plugins/python.conf", work_dir); + if(!py2){ + execute_cmd("cp /usr/bin/python2* %s/", work_dir); + execute_cmd("cp -a /usr/lib/python2* %s/usr/lib/", work_dir); + execute_cmd("cp -a /usr/lib64/python2.7 %s/usr/lib64/", work_dir); +#if (defined __mips__) + execute_cmd("cp -a /usr/lib64/python2* %s/usr/lib64/", work_dir); + execute_cmd("mkdir -p %s/usr/local/lib/", work_dir); + execute_cmd("cp -a /usr/local/lib/python2* %s/usr/local/lib/", work_dir); +#endif + }else{ + execute_cmd("cp /usr/bin/python3* %s/", work_dir); + execute_cmd("cp -a /usr/lib/python3* %s/usr/lib/", work_dir); + execute_cmd("cp -a /usr/lib64/python3.6 %s/usr/lib64/", work_dir); +#if (defined __mips__) + execute_cmd("cp -a /usr/lib64/python3* %s/usr/lib64/", work_dir); + execute_cmd("mkdir -p %s/usr/local/lib/", work_dir); + execute_cmd("cp -a /usr/local/lib/python3* %s/usr/local/lib/", work_dir); +#endif + } + execute_cmd("cp /usr/lib/lapack/* %s/usr/lib/liblapack.so.3", work_dir); + execute_cmd("cp /usr/lib/libblas/* %s/usr/lib/libblas.so.3", work_dir); + execute_cmd("cp /usr/lib/x86_64-linux-gnu/libgfortran.so.3 %s/usr/lib/", work_dir); + execute_cmd("cp /usr/lib/x86_64-linux-gnu/libquadmath.so.0 %s/usr/lib", work_dir); + execute_cmd("cp /usr/lib/x86_64-linux-gnu/blas/* %s/usr/lib", work_dir); + execute_cmd("cp /usr/lib/x86_64-linux-gnu/liblapack.so* %s/usr/lib", work_dir); + execute_cmd("cp /usr/lib/x86_64-linux-gnu/libgfortran.so.4 %s/usr/lib", work_dir); +#ifdef __mips__ + execute_cmd("/bin/cp -a /lib64/libpthread.so.0 %s/lib64/", work_dir); + execute_cmd("/bin/cp -a /lib64/libutil.so.1 %s/lib64/", work_dir); + execute_cmd("/bin/cp -a /lib64/libm.so.6 %s/lib64/", work_dir); + execute_cmd("/bin/cp -a /lib64/libc.so.6 %s/lib64/", work_dir); + execute_cmd("/bin/cp -a /lib64/libpthread-2.27.so %s/lib64/", work_dir); + execute_cmd("/bin/cp -a /lib64/libutil-2.27.so %s/lib64/", work_dir); + execute_cmd("/bin/cp -a /lib64/libc-2.27.so %s/lib64/", work_dir); + execute_cmd("/bin/cp -a /lib64/libm-2.27.so %s/lib64/", work_dir); + + +#endif + + /*execute_cmd("/bin/mkdir -p %s/lib/x86_64-linux-gnu", work_dir); + execute_cmd("/bin/cp -a /lib/x86_64-linux-gnu/libpthread* %s/lib/x86_64-linux-gnu/", work_dir); + execute_cmd("/bin/cp -a /lib/x86_64-linux-gnu/libdl.so.2 %s/lib/x86_64-linux-gnu/", work_dir); + execute_cmd("/bin/cp -a /lib/x86_64-linux-gnu/libutil.so.1 %s/lib/x86_64-linux-gnu/", work_dir); + execute_cmd("/bin/cp -a /lib/x86_64-linux-gnu/libexpat.so.1 %s/lib/x86_64-linux-gnu/", work_dir); + execute_cmd("/bin/cp -a /lib/x86_64-linux-gnu/libz.so.1 %s/lib/x86_64-linux-gnu/", work_dir); + execute_cmd("/bin/cp -a /lib/x86_64-linux-gnu/libm.so.6 %s/lib/x86_64-linux-gnu/", work_dir); + */ + //execute_cmd("/bin/cp -a /lib/x86_64-linux-gnu/ %s/lib/x86_64-linux-gnu/", work_dir); + + execute_cmd("cp -a /usr/lib64/libpython* %s/usr/lib64/", work_dir); execute_cmd("cp -a /usr/local/lib/python* %s/usr/local/lib/", work_dir); execute_cmd("cp -a /usr/include/python* %s/usr/include/", work_dir); execute_cmd("cp -a /usr/lib/libpython* %s/usr/lib/", work_dir); @@ -1816,6 +2072,7 @@ void copy_python_runtime(char *work_dir) execute_cmd("/bin/mkdir -p %s/etc", work_dir); execute_cmd("/bin/grep judge /etc/passwd>%s/etc/passwd", work_dir); execute_cmd("/bin/mount -o bind /dev %s/dev", work_dir); + execute_cmd("/bin/mount -o remount,ro %s/dev", work_dir); } void copy_php_runtime(char *work_dir) { @@ -1834,12 +2091,14 @@ void copy_php_runtime(char *work_dir) execute_cmd("/bin/cp /usr/lib/*/libkrb5* %s/usr/lib/", work_dir); execute_cmd("/bin/cp /usr/lib/*/libk5crypto* %s/usr/lib/", work_dir); execute_cmd("/bin/cp /usr/lib/libxml2* %s/usr/lib/", work_dir); +#ifdef __x86_64__ execute_cmd("/bin/cp /usr/lib/x86_64-linux-gnu/libxml2.so* %s/usr/lib/", work_dir); execute_cmd("/bin/cp /usr/lib/x86_64-linux-gnu/libicuuc.so* %s/usr/lib/", work_dir); execute_cmd("/bin/cp /usr/lib/x86_64-linux-gnu/libicudata.so* %s/usr/lib/", work_dir); execute_cmd("/bin/cp /usr/lib/x86_64-linux-gnu/libstdc++.so* %s/usr/lib/", work_dir); execute_cmd("/bin/cp /usr/lib/x86_64-linux-gnu/libssl* %s/usr/lib/", work_dir); execute_cmd("/bin/cp /usr/lib/x86_64-linux-gnu/libcrypto* %s/usr/lib/", work_dir); +#endif execute_cmd("/bin/cp /usr/bin/php* %s/", work_dir); execute_cmd("chmod +rx %s/Main.php", work_dir); } @@ -1884,7 +2143,16 @@ void copy_mono_runtime(char *work_dir) work_dir); execute_cmd("/bin/cp /lib/libpcre* %s/lib/", work_dir); execute_cmd("/bin/cp /lib/ld-linux* %s/lib/", work_dir); +#ifdef __x86_64__ execute_cmd("/bin/cp /lib64/ld-linux* %s/lib64/", work_dir); + execute_cmd("/bin/mkdir -p %s/usr/lib/x86_64-linux-gnu", work_dir); + execute_cmd("/bin/cp /usr/lib/x86_64-linux-gnu/libm.so.6 %s/usr/lib/x86_64-linux-gnu/", work_dir); + execute_cmd("/bin/cp /usr/lib/x86_64-linux-gnu/librt.so.1 %s/usr/lib/x86_64-linux-gnu/", work_dir); + execute_cmd("/bin/cp /usr/lib/x86_64-linux-gnu/libpthread.so.0 %s/usr/lib/x86_64-linux-gnu/", work_dir); + execute_cmd("/bin/cp /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 %s/usr/lib/x86_64-linux-gnu/", work_dir); + execute_cmd("/bin/cp /usr/lib/x86_64-linux-gnu/libc.so.6 %s/usr/lib/x86_64-linux-gnu/", work_dir); + execute_cmd("/bin/cp /lib64/ld-linux-x86-64.so.2 %s/lib64", work_dir); +#endif execute_cmd("/bin/mkdir -p %s/home/judge", work_dir); execute_cmd("/bin/chown judge %s/home/judge", work_dir); execute_cmd("/bin/mkdir -p %s/etc", work_dir); @@ -1898,12 +2166,60 @@ void copy_lua_runtime(char *work_dir) execute_cmd("/bin/mkdir -p %s/usr/local/bin", work_dir); execute_cmd("/bin/cp /usr/bin/lua %s/", work_dir); } +void copy_sql_runtime(char *work_dir) +{ + + copy_shell_runtime(work_dir); + execute_cmd("/bin/cp /usr/bin/sqlite3 %s/", work_dir); +#ifdef __mips__ + execute_cmd("/bin/cp /lib64/libedit.so.0 %s/lib64/", work_dir); + execute_cmd("/bin/cp /lib64/libm.so.6 %s/lib64/", work_dir); + execute_cmd("/bin/cp /lib64/libdl.so.2 %s/lib64/", work_dir); + execute_cmd("/bin/cp /lib64/libz.so.1 %s/lib64/", work_dir); + execute_cmd("/bin/cp /lib64/libpthread.so.0 %s/lib64/", work_dir); + execute_cmd("/bin/cp /lib64/libc.so.6 %s/lib64/", work_dir); + execute_cmd("/bin/cp /lib64/libtinfo.so.6 %s/lib64/", work_dir); +#endif +#ifdef __i386__ + execute_cmd("/bin/cp /usr/lib/i386-linux-gnu/libsqlite3.so.0* %s/lib/", work_dir); + execute_cmd("/bin/cp /lib/i386-linux-gnu/libreadline.so.6* %s/lib/", work_dir); + execute_cmd("/bin/cp /lib/i386-linux-gnu/libc.so.6* %s/lib/", work_dir); + execute_cmd("/bin/cp /lib/i386-linux-gnu/libpthread.so.0 %s/lib/", work_dir); + execute_cmd("/bin/cp /lib/i386-linux-gnu/libdl.so.2* %s/lib/", work_dir); + execute_cmd("/bin/cp /lib/i386-linux-gnu/libtinfo.so.5* %s/lib/", work_dir); + execute_cmd("/bin/cp /lib/i386-linux-gnu/libedit.so.0 %s/lib/", work_dir); + execute_cmd("/bin/cp /lib/i386-linux-gnu/libm.so.6* %s/lib/", work_dir); + execute_cmd("/bin/cp /lib/i386-linux-gnu/libz.so.1 %s/lib/", work_dir); + execute_cmd("/bin/cp /lib/i386-linux-gnu/libtinfo.so.6* %s/lib/", work_dir); +#endif +#ifdef __x86_64__ + execute_cmd("/bin/cp /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 %s/lib/", work_dir); + execute_cmd("/bin/cp /lib/x86_64-linux-gnu/libreadline.so.6 %s/lib64/", work_dir); + execute_cmd("/bin/cp /lib/x86_64-linux-gnu/libc.so.6 %s/lib64/", work_dir); + execute_cmd("/bin/cp /lib/x86_64-linux-gnu/libpthread.so.0 %s/lib64/", work_dir); + execute_cmd("/bin/cp /lib/x86_64-linux-gnu/libdl.so.2 %s/lib64/", work_dir); + execute_cmd("/bin/cp /lib/x86_64-linux-gnu/libtinfo.so.5 %s/lib64/", work_dir); + execute_cmd("/bin/cp /lib/x86_64-linux-gnu/libedit.so.0 %s/lib64/", work_dir); + execute_cmd("/bin/cp /lib/x86_64-linux-gnu/libm.so.6 %s/lib64/", work_dir); + execute_cmd("/bin/cp /lib/x86_64-linux-gnu/libz.so.1 %s/lib64/", work_dir); + execute_cmd("/bin/cp /lib/x86_64-linux-gnu/libtinfo.so.6 %s/lib64/", work_dir); +#endif +} void copy_js_runtime(char *work_dir) { // copy_shell_runtime(work_dir); - execute_cmd("/bin/mkdir -p %s/usr/lib /lib/i386-linux-gnu/", work_dir); + execute_cmd("mkdir -p %s/dev", work_dir); + execute_cmd("/bin/mount -o bind /dev %s/dev", work_dir); + execute_cmd("/bin/mount -o remount,ro %s/dev", work_dir); + execute_cmd("/bin/mkdir -p %s/usr/lib %s/lib/i386-linux-gnu/ %s/lib64/", work_dir, work_dir, work_dir); execute_cmd("/bin/cp /lib/i386-linux-gnu/libz.so.* %s/lib/i386-linux-gnu/", work_dir); + execute_cmd("/bin/cp /usr/lib/i386-linux-gnu/libuv.so.* %s/lib/i386-linux-gnu/", work_dir); + execute_cmd("/bin/cp /usr/lib/i386-linux-gnu/libicui18n.so.* %s/lib/i386-linux-gnu/", work_dir); + execute_cmd("/bin/cp /usr/lib/i386-linux-gnu/libicuuc.so.* %s/lib/i386-linux-gnu/", work_dir); + execute_cmd("/bin/cp /usr/lib/i386-linux-gnu/libicudata.so.* %s/lib/i386-linux-gnu/", work_dir); + execute_cmd("/bin/cp /lib/i386-linux-gnu/libtinfo.so.* %s/lib/i386-linux-gnu/", work_dir); + execute_cmd("/bin/cp /usr/lib/i386-linux-gnu/libcares.so.* %s/lib/i386-linux-gnu/", work_dir); execute_cmd("/bin/cp /usr/lib/libv8.so.* %s/lib/i386-linux-gnu/", work_dir); execute_cmd("/bin/cp /lib/i386-linux-gnu/libssl.so.* %s/lib/i386-linux-gnu/", work_dir); @@ -1915,44 +2231,74 @@ void copy_js_runtime(char *work_dir) execute_cmd("/bin/cp /lib/i386-linux-gnu/libc.so.6 %s/lib/i386-linux-gnu/", work_dir); execute_cmd("/bin/cp /lib/i386-linux-gnu/libm.so.6 %s/lib/i386-linux-gnu/", work_dir); execute_cmd("/bin/cp /lib/i386-linux-gnu/libgcc_s.so.1 %s/lib/i386-linux-gnu/", work_dir); - execute_cmd("/bin/cp /lib/ld-linux.so.* %s/lib/i386-linux-gnu/", work_dir); - - execute_cmd("/bin/mkdir -p %s/usr/lib /lib/x86_64-linux-gnu/", work_dir); - execute_cmd("/bin/cp /lib/x86_64-linux-gnu/libz.so.* %s/lib/x86_64-linux-gnu/", work_dir); - execute_cmd("/bin/cp /usr/lib/x86_64-linux-gnu/libcares.so.* %s/lib/x86_64-linux-gnu/", work_dir); - execute_cmd("/bin/cp /usr/lib/libv8.so.* %s/lib/x86_64-linux-gnu/", work_dir); - execute_cmd("/bin/cp /lib/x86_64-linux-gnu/libssl.so.* %s/lib/x86_64-linux-gnu/", work_dir); - execute_cmd("/bin/cp /lib/x86_64-linux-gnu/libcrypto.so.* %s/lib/x86_64-linux-gnu/", work_dir); - execute_cmd("/bin/cp /lib/x86_64-linux-gnu/libdl.so.* %s/lib/x86_64-linux-gnu/", work_dir); - execute_cmd("/bin/cp /lib/x86_64-linux-gnu/librt.so.* %s/lib/x86_64-linux-gnu/", work_dir); - execute_cmd("/bin/cp /usr/lib/x86_64-linux-gnu/libstdc++.so.* %s/lib/x86_64-linux-gnu/", work_dir); - execute_cmd("/bin/cp /lib/x86_64-linux-gnu/libpthread.so.* %s/lib/x86_64-linux-gnu/", work_dir); - execute_cmd("/bin/cp /lib/x86_64-linux-gnu/libc.so.6 %s/lib/x86_64-linux-gnu/", work_dir); - execute_cmd("/bin/cp /lib/x86_64-linux-gnu/libm.so.6 %s/lib/x86_64-linux-gnu/", work_dir); - execute_cmd("/bin/cp /lib/x86_64-linux-gnu/libgcc_s.so.1 %s/lib/x86_64-linux-gnu/", work_dir); - execute_cmd("/bin/cp /lib64/ld-linux-x86-64.so.2 %s/lib/x86_64-linux-gnu/", work_dir); - execute_cmd("/bin/cp /usr/lib/x86_64-linux-gnu/libcares* %s/usr/lib/", work_dir); - + execute_cmd("/bin/cp /lib/ld-linux.so.* %s/lib/", work_dir); + +#ifdef __x86_64__ + execute_cmd("/bin/mkdir -p %s/usr/lib/x86_64-linux-gnu/ %s/lib/x86_64-linux-gnu/", work_dir, work_dir); + + //execute_cmd("/bin/cp /usr/lib/x86_64-linux-gnu/ %s/usr/lib/x86_64-linux-gnu/", work_dir); + execute_cmd("/bin/cp /usr/lib/libv8.so.* %s/usr/lib/", work_dir); + execute_cmd("/bin/cp /usr/lib/x86_64-linux-gnu/libcares.so.* %s/usr/lib/x86_64-linux-gnu/", work_dir); + execute_cmd("/bin/cp /lib/x86_64-linux-gnu/libz.so.* %s/lib/x86_64-linux-gnu/", work_dir); + execute_cmd("/bin/cp /usr/lib/x86_64-linux-gnu/libuv.so.* %s/lib/x86_64-linux-gnu/", work_dir); + execute_cmd("/bin/cp /lib/x86_64-linux-gnu/librt.so.* %s/lib/x86_64-linux-gnu/", work_dir); + execute_cmd("/bin/cp /lib/x86_64-linux-gnu/libpthread.so.* %s/lib/x86_64-linux-gnu/", work_dir); + execute_cmd("/bin/cp /lib/x86_64-linux-gnu/libdl.so.* %s/lib/x86_64-linux-gnu/", work_dir); + execute_cmd("/bin/cp /lib/x86_64-linux-gnu/libssl.so.* %s/lib/x86_64-linux-gnu/", work_dir); + execute_cmd("/bin/cp /lib/x86_64-linux-gnu/libcrypto.so.* %s/lib/x86_64-linux-gnu/", work_dir); + execute_cmd("/bin/cp /usr/lib/x86_64-linux-gnu/libicui18n.so.* %s/lib/x86_64-linux-gnu/", work_dir); + execute_cmd("/bin/cp /usr/lib/x86_64-linux-gnu/libicuuc.so.* %s/lib/x86_64-linux-gnu/", work_dir); + execute_cmd("/bin/cp /usr/lib/x86_64-linux-gnu/libstdc++.so.* %s/lib/x86_64-linux-gnu/", work_dir); + execute_cmd("/bin/cp /lib/x86_64-linux-gnu/libm.so.* %s/lib/x86_64-linux-gnu/", work_dir); + execute_cmd("/bin/cp /lib/x86_64-linux-gnu/libgcc_s.so.* %s/lib/x86_64-linux-gnu/", work_dir); + execute_cmd("/bin/cp /lib/x86_64-linux-gnu/libc.so.* %s/lib/x86_64-linux-gnu/", work_dir); + execute_cmd("/bin/cp /lib64/ld-linux-x86-64.so.* %s/lib64/", work_dir); + execute_cmd("/bin/cp /usr/lib/x86_64-linux-gnu/libicudata.so.* %s/lib/x86_64-linux-gnu/", work_dir); +#endif execute_cmd("/bin/cp /usr/bin/nodejs %s/", work_dir); } -void run_solution(int &lang, char *work_dir, int &time_lmt, int &usedtime, - int &mem_lmt) +void run_solution(int &lang, char *work_dir, double &time_lmt, int &usedtime, + int &mem_lmt,char * data_file_path) { + char * const envp[]={(char * const )"PYTHONIOENCODING=utf-8", + (char * const )"LANG=zh_CN.UTF-8", + (char * const )"LANGUAGE=zh_CN.UTF-8", + (char * const )"LC_ALL=zh_CN.utf-8",NULL}; nice(19); - int py2 = execute_cmd("/bin/grep 'python2' Main.py"); // now the user is "judger" chdir(work_dir); // open the files - freopen("data.in", "r", stdin); + if(lang==18){ + execute_cmd("/usr/bin/sqlite3 %s/data.db < %s", work_dir,data_file_path); + execute_cmd("/bin/chown judge %s/data.db", work_dir); + freopen("Main.sql", "r", stdin); + }else{ + if(copy_data) + + freopen("data.in", "r", stdin); + else{ + printf("infile: [%s]\n",data_file_path); + freopen(data_file_path,"r",stdin); + } + } + execute_cmd("touch %s/user.out", work_dir); + + if (copy_data){ + execute_cmd("chgrp judge %s/user.out %s/data.in", work_dir,work_dir); + execute_cmd("chmod 740 %s/data.in", work_dir); + } + execute_cmd("chmod 760 %s/user.out", work_dir); freopen("user.out", "w", stdout); freopen("error.out", "a+", stderr); // trace me - if (use_ptrace) - ptrace(PTRACE_TRACEME, 0, NULL, NULL); + ptrace(PTRACE_TRACEME, 0, NULL, NULL); // run me - if (lang != 3) + if ( + lang != 3 && lang != 20 && lang != 9 && !(lang ==6 && python_free ) + ){ + if(DEBUG)printf("Chrooting...\n"); chroot(work_dir); - + } while (setgid(1536) != 0) sleep(1); while (setuid(1536) != 0) @@ -1965,15 +2311,15 @@ void run_solution(int &lang, char *work_dir, int &time_lmt, int &usedtime, // set the limit struct rlimit LIM; // time limit, file limit& memory limit // time limit - if (oi_mode) - LIM.rlim_cur = time_lmt + 1; + if (time_limit_to_total) + LIM.rlim_cur = (time_lmt / cpu_compensation - usedtime / 1000.0f) + 1; else - LIM.rlim_cur = (time_lmt - usedtime / 1000) + 1; + LIM.rlim_cur = time_lmt / cpu_compensation + 1; LIM.rlim_max = LIM.rlim_cur; //if(DEBUG) printf("LIM_CPU=%d",(int)(LIM.rlim_cur)); setrlimit(RLIMIT_CPU, &LIM); alarm(0); - alarm(time_lmt * 10); + alarm( num_of_test * time_lmt / cpu_compensation); // file limit LIM.rlim_max = STD_F_LIM + STD_MB; @@ -1983,16 +2329,16 @@ void run_solution(int &lang, char *work_dir, int &time_lmt, int &usedtime, switch (lang) { case 17: - LIM.rlim_cur = LIM.rlim_max = 280; - break; + case 9: //C# case 3: //java + LIM.rlim_cur = LIM.rlim_max = 880; + break; case 4: //ruby - //case 6: //python2 - //case 18: //python3 - case 9: //C# + case 6: //python case 12: case 16: - LIM.rlim_cur = LIM.rlim_max = 80; + case 20: + LIM.rlim_cur = LIM.rlim_max = 200; break; case 5: //bash LIM.rlim_cur = LIM.rlim_max = 3; @@ -2004,13 +2350,13 @@ void run_solution(int &lang, char *work_dir, int &time_lmt, int &usedtime, setrlimit(RLIMIT_NPROC, &LIM); // set the stack - LIM.rlim_cur = STD_MB << 6; - LIM.rlim_max = STD_MB << 6; + LIM.rlim_cur = STD_MB << 8; + LIM.rlim_max = STD_MB << 8; setrlimit(RLIMIT_STACK, &LIM); // set the memory LIM.rlim_cur = STD_MB * mem_lmt / 2 * 3; LIM.rlim_max = STD_MB * mem_lmt * 2; - if (lang < 3) + if (lang < 3 || lang == 10 || lang == 13 || lang == 14 || lang == 17) setrlimit(RLIMIT_AS, &LIM); switch (lang) @@ -2023,13 +2369,14 @@ void run_solution(int &lang, char *work_dir, int &time_lmt, int &usedtime, case 13: case 14: case 17: - execl("./Main", "./Main", (char *)NULL); + case 19: + execle("./Main", "./Main", (char *)NULL,envp); break; case 3: - sprintf(java_xms, "-Xmx%dM", mem_lmt); + sprintf(java_xmx, "-Xmx%dM", mem_lmt); //sprintf(java_xmx, "-XX:MaxPermSize=%dM", mem_lmt); - execl("/usr/bin/java", "/usr/bin/java", java_xms, java_xmx, + execl("/usr/bin/java", "/usr/bin/java",java_xmx , "-Djava.security.manager", "-Djava.security.policy=./java.policy", "Main", (char *)NULL); break; @@ -2040,11 +2387,19 @@ void run_solution(int &lang, char *work_dir, int &time_lmt, int &usedtime, case 5: //bash execl("/bin/bash", "/bin/bash", "Main.sh", (char *)NULL); break; - case 6: //Python2 - execl("/python2", "/python2", "Main.py", (char *)NULL); - break; - case 18: //Python3 - execl("/python3", "/python3", "Main.py", (char *)NULL); + case 6: //Python + if (!py2) + { if(python_free) + execl("/usr/bin/python2", "/usr/bin/python2", "Main.py", (char *)NULL); + else + execl("/python2", "/python2", "Main.py", (char *)NULL); + } + else + { if(python_free) + execl("/usr/bin/python3", "/usr/bin/python3", "Main.py", (char *)NULL); + else + execle("/python3", "/python3", "Main.py", (char *)NULL, envp); + } break; case 7: //php execl("/php", "/php", "Main.php", (char *)NULL); @@ -2053,17 +2408,23 @@ void run_solution(int &lang, char *work_dir, int &time_lmt, int &usedtime, execl("/perl", "/perl", "Main.pl", (char *)NULL); break; case 9: //Mono C# - execl("/mono", "/mono", "--debug", "Main.exe", (char *)NULL); + execle("/usr/bin/mono", "/usr/bin/mono","--debug", "Main.exe", (char *)NULL,envp); break; case 12: //guile execl("/guile", "/guile", "Main.scm", (char *)NULL); break; - case 15: //lua + case 15: //guile execl("/lua", "/lua", "Main", (char *)NULL); break; case 16: //Node.js execl("/nodejs", "/nodejs", "Main.js", (char *)NULL); break; + case 18: //sqlite3 + execl("/sqlite3", "/sqlite3", "data.db", (char *)NULL); + break; + case 20: //octave + execl("/usr/bin/octave-cli", "/usr/bin/octave-cli", "Main.m", (char *)NULL); + break; } //sleep(1); fflush(stderr); @@ -2133,7 +2494,10 @@ int special_judge(char *oj_home, int problem_id, char *infile, char *outfile, { pid_t pid; - printf("pid=%d\n", problem_id); + if (DEBUG) printf("pid=%d\n", problem_id); + // prevent privileges settings caused spj fail in [issues686] + execute_cmd("chown www-data:judge %s/data/%d/spj %s %s %s", oj_home, problem_id,infile, outfile, userfile); + execute_cmd("chmod 750 %s/data/%d/spj %s %s %s", oj_home, problem_id,infile, outfile, userfile); pid = fork(); int ret = 0; if (pid == 0) @@ -2159,7 +2523,7 @@ int special_judge(char *oj_home, int problem_id, char *infile, char *outfile, LIM.rlim_cur = STD_F_LIM; setrlimit(RLIMIT_FSIZE, &LIM); - ret = execute_cmd("%s/data/%d/spj '%s' '%s' %s", oj_home, problem_id, + ret = execute_cmd("%s/data/%d/spj %s %s %s", oj_home, problem_id, infile, outfile, userfile); if (DEBUG) printf("spj1=%d\n", ret); @@ -2179,7 +2543,7 @@ int special_judge(char *oj_home, int problem_id, char *infile, char *outfile, } return ret; } -void judge_solution(int &ACflg, int &usedtime, int time_lmt, int isspj, +void judge_solution(int &ACflg, int &usedtime, double time_lmt, int isspj, int p_id, char *infile, char *outfile, char *userfile, int &PEflg, int lang, char *work_dir, int &topmemory, int mem_lmt, int solution_id, int num_of_test) @@ -2188,8 +2552,23 @@ void judge_solution(int &ACflg, int &usedtime, int time_lmt, int isspj, int comp_res; if (!oi_mode) num_of_test = 1.0; - if (ACflg == OJ_AC && usedtime > time_lmt * 1000 * (use_max_time ? 1 : num_of_test)) - ACflg = OJ_TL; + + if (ACflg == OJ_AC){ + int real_limit=1000; + if(time_limit_to_total){ // 如果限制总时间 + real_limit=time_lmt*1000; + if(total_time>real_limit) ACflg = OJ_TL; // 总时间超过 + if(usedtime> real_limit) ACflg = OJ_TL; // 单点超过 + }else if(num_of_test>0){ // 如果数据点不为0,且限制单点时间 + real_limit=num_of_test*time_lmt*1000; + //if(total_time>real_limit) ACflg = OJ_TL; //总时间超过测试点数*限制 + if(usedtime> time_lmt*1000) ACflg = OJ_TL; // 单点超过限制 + }else{ //测试数为0 ,这种情况不应该出现,但给出,作为保险。 + real_limit=time_lmt*1000; // fallback + if(usedtime > real_limit) ACflg = OJ_TL; + if(total_time>real_limit) ACflg = OJ_TL; + } + } if (topmemory > mem_lmt * STD_MB) ACflg = OJ_ML; //issues79 // compare @@ -2210,7 +2589,7 @@ void judge_solution(int &ACflg, int &usedtime, int time_lmt, int isspj, } else { - comp_res = compare(outfile, userfile); + comp_res = compare(outfile, userfile,infile); } if (comp_res == OJ_WA) { @@ -2247,10 +2626,10 @@ int get_page_fault_mem(struct rusage &ruse, pid_t &pidApp) } return m_minflt; } -void print_runtimeerror(char *err) +void print_runtimeerror(char* infile,char *err) { FILE *ferr = fopen("error.out", "a+"); - fprintf(ferr, "Runtime Error:%s\n", err); + fprintf(ferr, "%s:%s\n",infile, err); fclose(ferr); } void clean_session(pid_t p) @@ -2264,11 +2643,11 @@ void clean_session(pid_t p) void watch_solution(pid_t pidApp, char *infile, int &ACflg, int isspj, char *userfile, char *outfile, int solution_id, int lang, - int &topmemory, int mem_lmt, int &usedtime, int time_lmt, int &p_id, + int &topmemory, int mem_lmt, int &usedtime, double time_lmt, int &p_id, int &PEflg, char *work_dir) { // parent - int tempmemory; + int tempmemory = 0; if (DEBUG) printf("pid=%d judging %s\n", pidApp, infile); @@ -2276,15 +2655,24 @@ void watch_solution(pid_t pidApp, char *infile, int &ACflg, int isspj, int status, sig, exitcode; struct user_regs_struct reg; struct rusage ruse; - if (topmemory == 0) - topmemory = get_proc_status(pidApp, "VmRSS:") << 10; + int first = true; while (1) { // check the usage - wait4(pidApp, &status, 0, &ruse); + wait4(pidApp, &status, __WALL, &ruse); + if (first) + { // + ptrace(PTRACE_SETOPTIONS, pidApp, NULL, PTRACE_O_TRACESYSGOOD | PTRACE_O_TRACEEXIT + // |PTRACE_O_EXITKILL + // |PTRACE_O_TRACECLONE + // |PTRACE_O_TRACEFORK + // |PTRACE_O_TRACEVFORK + ); + } + //jvm gc ask VM before need,so used kernel page fault times and page size - if (lang == 3 || lang == 7 || lang == 16 || lang == 9 || lang == 17) + if (lang == 3 || lang == 7 || lang == 9 || lang == 13 || lang == 14 || lang == 16 || lang == 17 || lang == 20) { tempmemory = get_page_fault_mem(ruse, pidApp); } @@ -2303,13 +2691,13 @@ void watch_solution(pid_t pidApp, char *infile, int &ACflg, int isspj, ptrace(PTRACE_KILL, pidApp, NULL, NULL); break; } - //sig = status >> 8;/*status >> 8 差不多是EXITCODE*/ + //sig = status >> 8;/*status >> 8 EXITCODE*/ if (WIFEXITED(status)) { break; } - if ((lang < 4 || lang == 9 || lang == 6 || lang == 18) && get_file_size("error.out") && !oi_mode) + if ((lang < 4||lang == 5 || lang == 9) && get_file_size("error.out") && !oi_mode) { ACflg = OJ_RE; //addreinfo(solution_id); @@ -2326,8 +2714,9 @@ void watch_solution(pid_t pidApp, char *infile, int &ACflg, int isspj, exitcode = WEXITSTATUS(status); /*exitcode == 5 waiting for next CPU allocation * ruby using system to run,exit 17 ok - * */ - if ((lang >= 3 && exitcode == 17) || exitcode == 0x05 || exitcode == 0) + * Runtime Error:Unknown signal xxx need be added here + */ + if ((lang >= 3 && exitcode == 17) || exitcode == 0x05 || exitcode == 0 || exitcode == 133) //go on and on ; else @@ -2346,9 +2735,12 @@ void watch_solution(pid_t pidApp, char *infile, int &ACflg, int isspj, case SIGCHLD: case SIGALRM: alarm(0); + if (DEBUG) printf("alarm:%g\n", time_lmt); case SIGKILL: case SIGXCPU: ACflg = OJ_TL; + usedtime = time_lmt * 1000; + if (DEBUG) printf("TLE:%d\n", usedtime); break; case SIGXFSZ: ACflg = OJ_OL; @@ -2356,7 +2748,7 @@ void watch_solution(pid_t pidApp, char *infile, int &ACflg, int isspj, default: ACflg = OJ_RE; } - print_runtimeerror(strsignal(exitcode)); + print_runtimeerror(infile+strlen(oj_home)+5,strsignal(exitcode)); } ptrace(PTRACE_KILL, pidApp, NULL, NULL); @@ -2396,7 +2788,7 @@ void watch_solution(pid_t pidApp, char *infile, int &ACflg, int isspj, default: ACflg = OJ_RE; } - print_runtimeerror(strsignal(sig)); + print_runtimeerror(infile+strlen(oj_home)+5,strsignal(sig)); } break; } @@ -2407,36 +2799,80 @@ void watch_solution(pid_t pidApp, char *infile, int &ACflg, int isspj, */ // check the system calls + if (!use_ptrace){ + ptrace(PTRACE_SYSCALL, pidApp, NULL, NULL); + continue; + + } +#ifdef __mips__ +// if(exitcode!=5&&exitcode!=133){ + //https://github.com/strace/strace/blob/master/linux/mips/syscallent-n32.h#L344 ptrace(PTRACE_GETREGS, pidApp, NULL, ®); - if (call_counter[reg.REG_SYSCALL]) - { - //call_counter[reg.REG_SYSCALL]--; - } - else if (record_call) - { - call_counter[reg.REG_SYSCALL] = 1; + call_id=(unsigned int)reg.REG_SYSCALL; + if( (call_id > 1000 && call_id <5000 )|| (lang == 6 && call_id < 5500) || call_id> 6500){ + // not a valid syscall + ptrace(PTRACE_SYSCALL, pidApp, NULL, NULL); + continue; + }else{ + call_id = call_id % call_array_size; + //printf("call_id:%x\n",call_id); +#endif +#ifdef __arm__ + call_id=ptrace(PTRACE_GETREGS, pidApp, NULL, ®); + call_id = ((unsigned int)reg.REG_SYSCALL) % call_array_size; +#endif +#ifdef __aarch64__ + call_id=ptrace(PTRACE_GETREGS, pidApp, (void *)NT_ARM_SYSTEM_CALL, ®); + print_arm_regs(reg.regs); + printf("return call_id:%d\n",call_id); + call_id = ((unsigned int)reg.REG_SYSCALL) % call_array_size; + printf("regist call_id:%d\n",call_id); +#endif +#ifdef __i386__ + call_id=ptrace(PTRACE_GETREGS, pidApp, NULL, ®); + call_id = ((unsigned int)reg.REG_SYSCALL) % call_array_size; +#endif +#ifdef __x86_64__ + call_id=ptrace(PTRACE_GETREGS, pidApp, NULL, ®); + call_id = ((unsigned int)reg.REG_SYSCALL) % call_array_size; +#endif + + + if (record_call) + { + printf("new call id:%d\n",call_id); + call_counter[call_id]++; + printf("call %d: %d\n",call_id,call_counter[call_id]); + }else if (call_counter[call_id]) + { + call_counter[call_id]--; } else { //do not limit JVM syscall for using different JVM ACflg = OJ_RE; char error[BUFFER_SIZE]; sprintf(error, - "[ERROR] A Not allowed system call: runid:%d CALLID:%ld\n" + "[ERROR] solution_id:%d called a Forbidden system call:%u [%u]\n" " TO FIX THIS , ask admin to add the CALLID into corresponding LANG_XXV[] located at okcalls32/64.h ,\n" "and recompile judge_client. \n" "if you are admin and you don't know what to do ,\n" "chinese explaination can be found on https://zhuanlan.zhihu.com/p/24498599\n", - solution_id, (long)reg.REG_SYSCALL); + solution_id, call_id,(unsigned int)reg.REG_SYSCALL); write_log(error); - print_runtimeerror(error); + print_runtimeerror(infile+strlen(oj_home)+5,error); ptrace(PTRACE_KILL, pidApp, NULL, NULL); } - +#ifdef __mips__ +// } + } +#endif ptrace(PTRACE_SYSCALL, pidApp, NULL, NULL); + first = false; + //usleep(1); } - usedtime += (ruse.ru_utime.tv_sec * 1000 + ruse.ru_utime.tv_usec / 1000); - usedtime += (ruse.ru_stime.tv_sec * 1000 + ruse.ru_stime.tv_usec / 1000); + usedtime += (ruse.ru_utime.tv_sec * 1000 + ruse.ru_utime.tv_usec / 1000) * cpu_compensation; + usedtime += (ruse.ru_stime.tv_sec * 1000 + ruse.ru_stime.tv_usec / 1000) * cpu_compensation; //clean_session(pidApp); } @@ -2446,29 +2882,32 @@ void clean_workdir(char *work_dir) umount(work_dir); if (DEBUG) { - execute_cmd("/bin/rm -rf %s/log/*", work_dir); - execute_cmd("mkdir %s/log/", work_dir); - execute_cmd("/bin/mv %s/* %s/log/", work_dir, work_dir); + execute_cmd("/bin/rm -rf %s/log/* 2>/dev/null", work_dir); + execute_cmd("mkdir %s/log/ 2>/dev/null", work_dir); + execute_cmd("/bin/mv %s/* %s/log/ 2>/dev/null", work_dir, work_dir); } else { - execute_cmd("mkdir %s/log/", work_dir); - execute_cmd("/bin/mv %s/* %s/log/", work_dir, work_dir); - execute_cmd("/bin/rm -rf %s/log/*", work_dir); + execute_cmd("mkdir %s/log/ 2>/dev/null", work_dir); + execute_cmd("/bin/mv %s/* %s/log/ 2>/dev/null", work_dir, work_dir); + execute_cmd("/bin/rm -rf %s/log/* 2>/dev/null", work_dir); } } void init_parameters(int argc, char **argv, int &solution_id, - int &runner_id) + int &runner_id) { if (argc < 3) { - fprintf(stderr, "Usage:%s solution_id runner_id.\n", argv[0]); - fprintf(stderr, "Multi:%s solution_id runner_id judge_base_path.\n", + fprintf(stderr,"HUSTOJ judge_client ver 20201127\n\n"); + fprintf(stderr, "Normal Usage:\n\t%s \n\n", argv[0]); + fprintf(stderr, "Multi OJ with Specific home :\n\t%s [judge_base_path].\n\n", argv[0]); fprintf(stderr, - "Debug:%s solution_id runner_id judge_base_path debug.\n", - argv[0]); + "Debug with Specific home:\n\t%s [judge_base_path] [debug].\n\n", + argv[0]); + fprintf(stderr,"\n\n"); + fprintf(stderr,"Example:\n\tsudo %s 1001 0 /home/judge/ debug \n\n",argv[0]); exit(1); } DEBUG = (argc > 4); @@ -2494,21 +2933,19 @@ int get_sim(int solution_id, int lang, int pid, int &sim_s_id) sprintf(src_pth, "Main.%s", lang_ext[lang]); int sim = execute_cmd("/usr/bin/sim.sh %s %d", src_pth, pid); - if (DEBUG) - printf("sim=%d\n", sim); if (!sim) { - execute_cmd("/bin/mkdir ../data/%d/ac/", pid); + execute_cmd("/bin/mkdir ../data/%d/ac/ 2>/dev/null", pid); - execute_cmd("/bin/cp %s ../data/%d/ac/%d.%s", src_pth, pid, solution_id, + execute_cmd("/bin/cp %s ../data/%d/ac/%d.%s 2>/dev/null", src_pth, pid, solution_id, lang_ext[lang]); //c cpp will if (lang == 0) - execute_cmd("/bin/ln ../data/%d/ac/%d.%s ../data/%d/ac/%d.%s", pid, + execute_cmd("/bin/ln ../data/%d/ac/%d.%s ../data/%d/ac/%d.%s 2>/dev/null", pid, solution_id, lang_ext[lang], pid, solution_id, lang_ext[lang + 1]); if (lang == 1) - execute_cmd("/bin/ln ../data/%d/ac/%d.%s ../data/%d/ac/%d.%s", pid, + execute_cmd("/bin/ln ../data/%d/ac/%d.%s ../data/%d/ac/%d.%s 2>/dev/null", pid, solution_id, lang_ext[lang], pid, solution_id, lang_ext[lang - 1]); } @@ -2531,13 +2968,13 @@ void mk_shm_workdir(char *work_dir) { char shm_path[BUFFER_SIZE]; sprintf(shm_path, "/dev/shm/hustoj/%s", work_dir); - execute_cmd("/bin/mkdir -p %s", shm_path); - execute_cmd("/bin/ln -s %s %s/", shm_path, oj_home); - execute_cmd("/bin/chown judge %s ", shm_path); - execute_cmd("chmod 755 %s ", shm_path); + execute_cmd("/bin/mkdir -p %s 2>/dev/null", shm_path); + execute_cmd("/bin/ln -s %s %s/ 2>/dev/null", shm_path, oj_home); + execute_cmd("/bin/chown judge %s 2>/dev/null", shm_path); + execute_cmd("chmod 755 %s 2>/dev/null", shm_path); //sim need a soft link in shm_dir to work correctly sprintf(shm_path, "/dev/shm/hustoj/%s/", oj_home); - execute_cmd("/bin/ln -s %s/data %s", oj_home, shm_path); + execute_cmd("/bin/ln -s %s/data %s 2>/dev/null", oj_home, shm_path); } int count_in_files(char *dirpath) { @@ -2552,14 +2989,19 @@ int count_in_files(char *dirpath) int get_test_file(char *work_dir, int p_id) { - char filename[BUFFER_SIZE]; + char filename[BUFFER_SIZE/10]; char localfile[BUFFER_SIZE]; + time_t remote_date, local_date; int ret = 0; const char *cmd = - " wget --post-data=\"gettestdatalist=1&pid=%d\" --load-cookies=cookie --save-cookies=cookie --keep-session-cookies -q -O - \"%s/admin/problem_judge.php\""; + " wget --post-data=\"gettestdatalist=1&time=1&pid=%d\" --load-cookies=cookie --save-cookies=cookie --keep-session-cookies -q -O - \"%s/admin/problem_judge.php\""; FILE *fjobs = read_cmd_output(cmd, p_id, http_baseurl); while (fgets(filename, BUFFER_SIZE - 1, fjobs) != NULL) { + + sscanf(filename, "%ld", &remote_date); + if (fgets(filename, BUFFER_SIZE - 1, fjobs) == NULL) + break; sscanf(filename, "%s", filename); if (http_judge && (!data_list_has(filename))) data_list_add(filename); @@ -2567,13 +3009,6 @@ int get_test_file(char *work_dir, int p_id) if (DEBUG) printf("localfile[%s]\n", localfile); - const char *check_file_cmd = - " wget --post-data=\"gettestdatadate=1&filename=%d/%s\" --load-cookies=cookie --save-cookies=cookie --keep-session-cookies -q -O - \"%s/admin/problem_judge.php\""; - FILE *rcop = read_cmd_output(check_file_cmd, p_id, filename, - http_baseurl); - time_t remote_date, local_date; - fscanf(rcop, "%ld", &remote_date); - fclose(rcop); struct stat fst; stat(localfile, &fst); local_date = fst.st_mtime; @@ -2616,23 +3051,23 @@ int get_test_file(char *work_dir, int p_id) } void print_call_array() { - printf("int LANG_%sV[256]={", LANG_NAME); + printf("int LANG_%sV[CALL_ARRAY_SIZE]={", LANG_NAME); int i = 0; for (i = 0; i < call_array_size; i++) { - if (call_counter[i]) + if (call_counter[i]>0) { printf("%d,", i); } } printf("0};\n"); - printf("int LANG_%sC[256]={", LANG_NAME); + printf("int LANG_%sC[CALL_ARRAY_SIZE]={", LANG_NAME); for (i = 0; i < call_array_size; i++) { if (call_counter[i]) { - printf("HOJ_MAX_LIMIT,"); + printf("%d,",call_counter[i]); } } printf("0};\n"); @@ -2645,7 +3080,10 @@ int main(int argc, char **argv) char user_id[BUFFER_SIZE]; int solution_id = 1000; int runner_id = 0; - int p_id, time_lmt, mem_lmt, lang, isspj, sim, sim_s_id, max_case_time = 0; + int p_id, mem_lmt, lang, isspj, sim, sim_s_id, max_case_time = 0,cid=0; + double time_lmt; + char time_space_table[BUFFER_SIZE*100]; + int time_space_index=0; init_parameters(argc, argv, solution_id, runner_id); @@ -2660,20 +3098,19 @@ int main(int argc, char **argv) //set work directory to start running & judging sprintf(work_dir, "%s/run%s/", oj_home, argv[2]); - clean_workdir(work_dir); - if (shm_run) + if (shm_run){ mk_shm_workdir(work_dir); + }else{ + execute_cmd("mkdir %s",work_dir); + } + + clean_workdir(work_dir); chdir(work_dir); if (http_judge) system("/bin/ln -s ../cookie ./"); - get_solution_info(solution_id, p_id, user_id, lang); - - if (DEBUG) - { - printf("lang = %d, lang_name = %s\n", lang, lang_ext[lang]); - } + get_solution_info(solution_id, p_id, user_id, lang,cid); //get the limit if (p_id == 0) @@ -2690,9 +3127,9 @@ int main(int argc, char **argv) get_solution(solution_id, work_dir, lang); - //java is lucky - if (lang >= 3 && lang != 10 && lang != 13 && lang != 14) - { // Clang Clang++ not VM or Script + //java and other VM language are lucky to have the global bonus in judge.conf + if (lang >= 3 && lang != 10 && lang != 13 && lang != 14 && lang != 17) + { //ObjectivC Clang Clang++ Go not VM or Script // the limit for java time_lmt = time_lmt + java_time_bonus; mem_lmt = mem_lmt + java_memory_bonus; @@ -2706,13 +3143,13 @@ int main(int argc, char **argv) } //never bigger than judged set value; - if (time_lmt > 300 || time_lmt < 1) - time_lmt = 300; + if (time_lmt > 300 || time_lmt < 0) + time_lmt = 1; if (mem_lmt > 1024 || mem_lmt < 1) mem_lmt = 1024; if (DEBUG) - printf("time: %d mem: %d\n", time_lmt, mem_lmt); + printf("time: %g mem: %d\n", time_lmt, mem_lmt); // compile // printf("%s\n",cmd); @@ -2727,7 +3164,7 @@ int main(int argc, char **argv) if (!turbo_mode) update_user(user_id); if (!turbo_mode) - update_problem(p_id); + update_problem(p_id,cid); #ifdef _mysql_h if (!http_judge) mysql_close(conn); @@ -2745,16 +3182,16 @@ int main(int argc, char **argv) //exit(0); // run char fullpath[BUFFER_SIZE]; - char infile[BUFFER_SIZE]; - char outfile[BUFFER_SIZE]; - char userfile[BUFFER_SIZE]; + char infile[BUFFER_SIZE/10]; + char outfile[BUFFER_SIZE/10]; + char userfile[BUFFER_SIZE/10]; sprintf(fullpath, "%s/data/%d", oj_home, p_id); // the fullpath of data dir // open DIRs DIR *dp; dirent *dirp; // using http to get remote test data files - if (p_id > 0 && http_judge) + if (p_id > 0 && http_judge && http_download) get_test_file(work_dir, p_id); if (p_id > 0 && (dp = opendir(fullpath)) == NULL) { @@ -2777,14 +3214,14 @@ int main(int argc, char **argv) copy_ruby_runtime(work_dir); if (lang == 5) copy_bash_runtime(work_dir); - if (lang == 6 || lang == 18) + if (lang == 6 && !python_free) copy_python_runtime(work_dir); if (lang == 7) copy_php_runtime(work_dir); if (lang == 8) copy_perl_runtime(work_dir); - if (lang == 9) - copy_mono_runtime(work_dir); +// if (lang == 9) +// copy_mono_runtime(work_dir); if (lang == 10) copy_objc_runtime(work_dir); if (lang == 11) @@ -2795,11 +3232,12 @@ int main(int argc, char **argv) copy_lua_runtime(work_dir); if (lang == 16) copy_js_runtime(work_dir); + if (lang == 18) + copy_sql_runtime(work_dir); // read files and run // read files and run // read files and run double pass_rate = 0.0; - int num_of_test = 0; int finalACflg = ACflg; if (p_id == 0) { //custom input running @@ -2810,19 +3248,16 @@ int main(int argc, char **argv) if (pidApp == 0) { - run_solution(lang, work_dir, time_lmt, usedtime, mem_lmt); + run_solution(lang, work_dir, time_lmt, usedtime, mem_lmt,(char *)"data.in"); } else { watch_solution(pidApp, infile, ACflg, isspj, userfile, outfile, - solution_id, lang, topmemory, mem_lmt, usedtime, time_lmt, - p_id, PEflg, work_dir); - } - if (ACflg == OJ_TL) - { - usedtime = time_lmt * 1000; + solution_id, lang, topmemory, mem_lmt, usedtime, time_lmt, + p_id, PEflg, work_dir); } - if (ACflg == OJ_RE) + if(DEBUG) printf("custom running result:%d PEflg:%d\n",ACflg,PEflg); + if (ACflg == OJ_RE||get_file_size("error.out")>0) { if (DEBUG) printf("add RE info of %d..... \n", solution_id); @@ -2837,6 +3272,16 @@ int main(int argc, char **argv) exit(0); } + for (;(dirp = readdir(dp)) != NULL;) + { + + int namelen = isInFile(dirp->d_name); // check if the file is *.in or not + if (namelen == 0) + continue; + num_of_test++; + } + rewinddir(dp); + for (; (oi_mode || ACflg == OJ_AC || ACflg == OJ_PE) && (dirp = readdir(dp)) != NULL;) { @@ -2844,11 +3289,20 @@ int main(int argc, char **argv) if (namelen == 0) continue; - if (http_judge && (!data_list_has(dirp->d_name))) + if (http_judge && http_download && (!data_list_has(dirp->d_name))) continue; prepare_files(dirp->d_name, namelen, infile, p_id, work_dir, outfile, userfile, runner_id); + if (access(outfile, 0) == -1) + { + //out file does not exist + char error[BUFFER_SIZE]; + sprintf(error, "missing out file %s, report to system administrator!\n", outfile); + print_runtimeerror(infile+strlen(oj_home)+5,error); + ACflg = OJ_RE; + } + init_syscalls_limits(lang); pid_t pidApp = fork(); @@ -2856,26 +3310,29 @@ int main(int argc, char **argv) if (pidApp == 0) { - run_solution(lang, work_dir, time_lmt, usedtime, mem_lmt); + run_solution(lang, work_dir, time_lmt, usedtime, mem_lmt,infile); } else { - num_of_test++; + //num_of_test++; watch_solution(pidApp, infile, ACflg, isspj, userfile, outfile, - solution_id, lang, topmemory, mem_lmt, usedtime, time_lmt, - p_id, PEflg, work_dir); - + solution_id, lang, topmemory, mem_lmt, usedtime, time_lmt, + p_id, PEflg, work_dir); + printf("%s: mem=%d time=%d\n",infile+strlen(oj_home)+5,topmemory,usedtime); + total_time+=usedtime; + printf("time:%d/%d\n",usedtime,total_time); judge_solution(ACflg, usedtime, time_lmt, isspj, p_id, infile, - outfile, userfile, PEflg, lang, work_dir, topmemory, - mem_lmt, solution_id, num_of_test); + outfile, userfile, PEflg, lang, work_dir, topmemory, + mem_lmt, solution_id, num_of_test); + time_space_index+=sprintf(time_space_table+time_space_index,"%s:%s mem=%dk time=%dms\n",infile+strlen(oj_home)+5,jresult[ACflg],topmemory/1024,usedtime); if (use_max_time) { max_case_time = usedtime > max_case_time ? usedtime : max_case_time; - usedtime = 0; } + usedtime = 0; //clean_session(pidApp); } if (oi_mode) @@ -2894,8 +3351,6 @@ int main(int argc, char **argv) } if (ACflg == OJ_AC && PEflg == OJ_PE) ACflg = OJ_PE; - if (DEBUG) - printf("sim_enable = %d\n", sim_enable); if (sim_enable && ACflg == OJ_AC && (!oi_mode || finalACflg == OJ_AC)) { //bash don't supported sim = get_sim(solution_id, lang, p_id, sim_s_id); @@ -2914,9 +3369,13 @@ int main(int argc, char **argv) } if (use_max_time) { + if(DEBUG) printf("use max case time:%d\n",max_case_time); usedtime = max_case_time; + }else{ + if(DEBUG) printf("use total time:%d\n",total_time); + usedtime = total_time; } - if (ACflg == OJ_TL) + if(usedtime > time_lmt * 1000) { usedtime = time_lmt * 1000; } @@ -2929,20 +3388,19 @@ int main(int argc, char **argv) } else { + if(ACflg==OJ_AC) pass_rate=1.0; + else pass_rate=0.0; update_solution(solution_id, ACflg, usedtime, topmemory >> 10, sim, - sim_s_id, 0); - } - if ((oi_mode && finalACflg == OJ_WA) || ACflg == OJ_WA) - { - if (DEBUG) - printf("add diff info of %d..... \n", solution_id); - if (!isspj) - adddiffinfo(solution_id); - } - if (!turbo_mode) - update_user(user_id); - if (!turbo_mode) - update_problem(p_id); + sim_s_id, pass_rate); + } + FILE *df=fopen("diff.out","a"); + fprintf(df,"time_space_table:\n%s\n",time_space_table); + fclose(df); + if(DEBUG) printf("ACflg:%d\n",ACflg); + if(DEBUG) printf("finalACflg:%d\n",finalACflg); + if(ACflg != 10 && finalACflg!= 10 ) adddiffinfo(solution_id); + if(!turbo_mode)update_user(user_id); + if(!turbo_mode)update_problem(p_id,cid); clean_workdir(work_dir); if (DEBUG) diff --git a/judger/core/judge_client/loggedcalls.sh b/judger/core/judge_client/loggedcalls.sh new file mode 100644 index 00000000..7217e79d --- /dev/null +++ b/judger/core/judge_client/loggedcalls.sh @@ -0,0 +1,7 @@ + +CALLS="" +for x in `grep CALLID\: /home/judge/log/client.log|awk -F: '{print $4}'|awk '{print $1}'|sort -nu ` +do + CALLS="$CALLS,$x" +done +echo "int LANG_CV[CALL_ARRAY_SIZE]={0$CALLS,0};" diff --git a/judger/core/judge_client/makefile b/judger/core/judge_client/makefile index d65ef427..8724f3c0 100755 --- a/judger/core/judge_client/makefile +++ b/judger/core/judge_client/makefile @@ -1,3 +1,3 @@ all: judge_client.cc g++ -Wall -c -I/usr/local/mysql/include/mysql -I/usr/include/mysql judge_client.cc - g++ -Wall -o judge_client judge_client.o -L/usr/local/mysql/lib/mysql -L/usr/lib/mysql -L/usr/lib64/mysql -lmysqlclient -lexplain + g++ -Wall -o judge_client judge_client.o -L/usr/local/mysql/lib/mysql -L/usr/lib/mysql -L/usr/lib64/mysql -lmysqlclient diff --git a/judger/core/judge_client/okcalls.h b/judger/core/judge_client/okcalls.h index d45a3aa3..7754ee41 100755 --- a/judger/core/judge_client/okcalls.h +++ b/judger/core/judge_client/okcalls.h @@ -18,8 +18,19 @@ */ #include #define HOJ_MAX_LIMIT -1 +#define CALL_ARRAY_SIZE 512 #ifdef __i386 #include "okcalls32.h" -#else +#endif +#ifdef __x86_64 #include "okcalls64.h" #endif +#ifdef __arm__ + #include "okcalls_arm.h" +#endif +#ifdef __aarch64__ + #include "okcalls_aarch64.h" +#endif +#ifdef __mips__ + #include "okcalls_mips.h" +#endif diff --git a/judger/core/judge_client/okcalls32.h b/judger/core/judge_client/okcalls32.h index c6086414..d306ab54 100755 --- a/judger/core/judge_client/okcalls32.h +++ b/judger/core/judge_client/okcalls32.h @@ -17,15 +17,16 @@ * along with HUSTOJ. if not, see . */ //c & c++ -int LANG_CV[256] = { 85, 8,140, SYS_time, SYS_read, SYS_uname, SYS_write, SYS_open, - SYS_close, SYS_execve, SYS_access, SYS_brk, SYS_munmap, SYS_mprotect, - SYS_mmap2, SYS_fstat64, SYS_set_thread_area, 252, 0 }; +int LANG_CV[CALL_ARRAY_SIZE] = {3,4,8,10,11,33,45,85,122,140,146,192,197,243,252,272,SYS_time, SYS_read, SYS_uname, SYS_write, SYS_open, + SYS_close, SYS_access, SYS_brk, SYS_munmap, SYS_mprotect, + SYS_mmap2, SYS_fstat64, SYS_set_thread_area, 463, 0 }; //pascal -int LANG_PV[256] = { 0,9, 59, 97, 13, 16, 89, 140, 91, 175, 195, 13, SYS_open, SYS_set_thread_area, +int LANG_PV[CALL_ARRAY_SIZE] = { 0,9, 59, 97, 13, 16, 89, 140, 91, 175, 195, 13, SYS_open, SYS_set_thread_area, SYS_brk, SYS_read, SYS_uname, SYS_write, SYS_execve, SYS_ioctl, SYS_readlink, SYS_mmap, SYS_rt_sigaction, SYS_getrlimit, 252, 191, 0 }; //java -int LANG_JV[256] = { 295, SYS_fcntl64, SYS_getdents64, SYS_ugetrlimit, +int LANG_JV[CALL_ARRAY_SIZE] = { 3,6,11,20,33,45,85,91,120,122,125,172,174,175,191,192,195,197,240,243,252,258,295,311 + , SYS_fcntl64, SYS_getdents64, SYS_ugetrlimit, SYS_rt_sigprocmask, SYS_futex, SYS_read, SYS_mmap2, SYS_stat64, SYS_open, SYS_close, SYS_execve, SYS_access, SYS_brk, SYS_readlink, SYS_munmap, SYS_close, SYS_uname, SYS_clone, SYS_uname, SYS_mprotect, @@ -34,7 +35,7 @@ int LANG_JV[256] = { 295, SYS_fcntl64, SYS_getdents64, SYS_ugetrlimit, SYS_set_thread_area, SYS_set_tid_address, SYS_set_robust_list, SYS_exit_group, 0 }; //ruby -int LANG_RV[256] = { 3,4,5,6,11,33,42,45,54,77,78,91,120,122,125,174,175,183,186,191,192, +int LANG_RV[CALL_ARRAY_SIZE] = { 3,4,5,6,11,33,42,45,54,77,78,91,120,122,125,174,175,183,186,191,192, 195,196,197,199,200,201,202,221,240,243,252,258,311, 340, 126, SYS_access, SYS_brk, SYS_close, SYS_execve, SYS_exit_group, SYS_fstat64, SYS_futex, SYS_getegid32, SYS_geteuid32, @@ -43,7 +44,7 @@ int LANG_RV[256] = { 3,4,5,6,11,33,42,45,54,77,78,91,120,122,125,174,175,183,186 SYS_rt_sigprocmask, SYS_set_robust_list, SYS_set_thread_area, SYS_set_tid_address, SYS_uname, SYS_write, 191, 195, 120, 7, 0 }; //bash -int LANG_BV[256] = { 3,4,5,6,11,20,33,45,54,63,64,65,78,116,122,125,140,174,175,183,191,192,195,197,199,200,201,202,221,243,252, +int LANG_BV[CALL_ARRAY_SIZE] = { 3,4,5,6,11,20,33,45,54,63,64,65,78,116,122,125,140,174,175,183,191,192,195,197,199,200,201,202,221,243,252, 7, 120, 42, 158, 117, 60, 39, 102, 191, 183, SYS_access, SYS_brk, SYS_close, SYS_dup2, SYS_execve, SYS_exit_group, SYS_fcntl64, SYS_fstat64, SYS_getegid32, SYS_geteuid32, SYS_getgid32, SYS_getpgrp, @@ -52,11 +53,12 @@ int LANG_BV[256] = { 3,4,5,6,11,20,33,45,54,63,64,65,78,116,122,125,140,174,175, SYS_read, SYS_rt_sigaction, SYS_rt_sigprocmask, SYS_set_thread_area, SYS_stat64, SYS_time, SYS_uname, SYS_write,0 }; //python -int LANG_YV[256]={3,4,5,6,11,33,45,54,59,85,116,122,125,140,174,175,183, - 191,192,195,196,197,199,200,201,202,220,243,252,258, - 311,318,13,41,91,102,186,221,240,295,0}; + +int LANG_YV[CALL_ARRAY_SIZE]={3,4,5,6,11,20,22,33,41,45,54,85,91,116,122,125,140,174,175,183, + 191,192,195,196,197,199,200,201,202,220,221,243,252,258,265,295, + 311,13,41,91,102,186,221,240,295,355,0}; //php -int LANG_PHV[256] = {3,4,5,6,11,13,33,45,54,78,91,122,125,140,174,175,183,191,192,195, +int LANG_PHV[CALL_ARRAY_SIZE] = {3,4,5,6,11,13,33,45,54,78,91,122,125,140,174,175,183,191,192,195, 196,197,240,243,252,258,295,311,146, 158, 117, 60, 39, 102, SYS_access, SYS_brk, SYS_clone, SYS_close, SYS_execve, SYS_exit_group, SYS_fcntl64, SYS_fstat64, SYS_futex, SYS_getcwd, SYS_getdents64, SYS_getrlimit, @@ -66,7 +68,7 @@ int LANG_PHV[256] = {3,4,5,6,11,13,33,45,54,78,91,122,125,140,174,175,183,191,19 SYS_set_thread_area, SYS_set_tid_address, SYS_stat64, SYS_time, SYS_uname, SYS_write, 0 }; //perl -int LANG_PLV[256] = { 78, 158, 117, 60, 39, 102, 191, SYS_access, SYS_brk, +int LANG_PLV[CALL_ARRAY_SIZE] = { 78, 158, 117, 60, 39, 102, 191, SYS_access, SYS_brk, SYS_close, SYS_execve, SYS_exit_group, SYS_fcntl64, SYS_fstat64, SYS_futex, SYS_getegid32, SYS_geteuid32, SYS_getgid32, SYS_getrlimit, SYS_getuid32, SYS_ioctl, SYS__llseek, SYS_mmap2, SYS_mprotect, @@ -74,7 +76,7 @@ int LANG_PLV[256] = { 78, 158, 117, 60, 39, 102, 191, SYS_access, SYS_brk, SYS_rt_sigprocmask, SYS_set_robust_list, SYS_set_thread_area, SYS_set_tid_address, SYS_stat64, SYS_time, SYS_uname, SYS_write, 0 }; //c-sharp -int LANG_CSV[256] = {3,4,5,6,11,13,33,45,54,78,85,91,99,102,120,122,125,140,141,158,174,175, +int LANG_CSV[CALL_ARRAY_SIZE] = {3,4,5,6,11,13,33,45,54,78,85,91,99,102,120,122,125,140,141,158,174,175, 183,186,191,192,195,197,199,221,240,242,243,252,258,265,266,270,295, 311, 11,33,45,192,141, 158, 117, 60, 39, 102, 191, SYS_access, SYS_brk, SYS_chmod, SYS_clock_getres, SYS_clock_gettime, SYS_clone, SYS_close, @@ -89,7 +91,7 @@ int LANG_CSV[256] = {3,4,5,6,11,13,33,45,54,78,85,91,99,102,120,122,125,140,141, SYS_set_tid_address, SYS_sigaltstack, SYS_stat64, SYS_statfs, SYS_tgkill, SYS_time, SYS_uname, SYS_unlink, SYS_write, 0 }; //objective-c -int LANG_OV[256] = {3,221,102, 191, SYS_access, SYS_brk, SYS_close, SYS_execve, +int LANG_OV[CALL_ARRAY_SIZE] = {3,221,102, 191, SYS_access, SYS_brk, SYS_close, SYS_execve, SYS_exit_group, SYS_fstat64, SYS_futex, SYS_getcwd, SYS_geteuid32, SYS_getrlimit, SYS_gettimeofday, SYS_getuid32, SYS__llseek, SYS_lstat64, SYS_mmap2, SYS_mprotect, SYS_munmap, SYS_open, SYS_read, SYS_readlink, @@ -97,14 +99,14 @@ int LANG_OV[256] = {3,221,102, 191, SYS_access, SYS_brk, SYS_close, SYS_execve, SYS_set_thread_area, SYS_set_tid_address, SYS_stat64, SYS_uname, SYS_write, 0 }; //freebasic -int LANG_BASICV[256] = {3,4,5,6,11,33,45,54,91,101,122,125,140,174,175,191,192,195,197,240,243,252,258,311,330 +int LANG_BASICV[CALL_ARRAY_SIZE] = {3,4,5,6,11,33,45,54,91,101,122,125,140,174,175,191,192,195,197,240,243,252,258,311,330 , SYS_access, SYS_brk, SYS_close, SYS_execve, SYS_exit_group, SYS_fstat64, SYS_futex, SYS_getrlimit, SYS_ioctl, SYS_ioperm, SYS_mmap2, SYS_open, SYS_read, SYS_rt_sigaction, SYS_rt_sigprocmask, SYS_set_robust_list, SYS_set_thread_area, SYS_set_tid_address, SYS_stat64, SYS_uname, SYS_write, 0 }; //scheme -int LANG_SV[256] = { 100, 295,59, SYS_fcntl64, SYS_getdents64, SYS_ugetrlimit, +int LANG_SV[CALL_ARRAY_SIZE] = { 100, 295, SYS_fcntl64, SYS_getdents64, SYS_ugetrlimit, SYS_rt_sigprocmask, SYS_futex, SYS_read, SYS_mmap2, SYS_stat64, SYS_open, SYS_close, SYS_execve, SYS_access, SYS_brk, SYS_readlink, SYS_munmap, SYS_close, SYS_uname, SYS_clone, SYS_uname, SYS_mprotect, @@ -113,9 +115,15 @@ int LANG_SV[256] = { 100, 295,59, SYS_fcntl64, SYS_getdents64, SYS_ugetrlimit, SYS_set_thread_area, SYS_set_tid_address, SYS_set_robust_list, SYS_exit_group, 0 }; //lua -int LANG_LUAV[256]={3,4,5,6,11,13,33,45,91,125,174,192,195,197,243,252,330,0}; +int LANG_LUAV[CALL_ARRAY_SIZE]={3,4,5,6,11,13,33,45,91,125,174,192,195,197,243,252,330,0}; //nodejs -int LANG_JSV[256]={3,4,5,6,11,33,45,54,78,85,91,120,122,125,174,175,183,191,192,195,196,197,224,240,243,252,255,256,258,265,311,328,329,331,0}; +int LANG_JSV[CALL_ARRAY_SIZE]={3,4,5,6,11,33,45,54,75,78,85,91,120,122,125,168,174,175,183,191,192,195,196,197,199,200,201,202,224,240,243,252,255,256,258,265,266,311,328,329,331,0}; //go-lang -int LANG_GOV[256]={3,4,11,120,123,174,175,186,192,240,242,252,265,0}; +int LANG_GOV[CALL_ARRAY_SIZE]={3,4,11,120,123,174,175,186,192,240,242,252,265,0}; +//sqlite3 +int LANG_SQLV[CALL_ARRAY_SIZE]={3,4,5,6,11,33,45,54,102,122,125,140,174,175,183,191,192,195,197,199,221,240,243,252,258,311,0}; +//fortran +int LANG_FV[CALL_ARRAY_SIZE]={3,4,11,33,45,85,122,174,197,243,252,0}; +//matlab +int LANG_MV[CALL_ARRAY_SIZE]={3,4,6,11,20,33,45,54,78,85,91,102,122,125,140,146,168,174,175,183,191,192,195,196,197,199,220,221,240,242,243,252,258,295,311,355,0}; diff --git a/judger/core/judge_client/okcalls64.h b/judger/core/judge_client/okcalls64.h index ba26bb8f..5a337dd5 100755 --- a/judger/core/judge_client/okcalls64.h +++ b/judger/core/judge_client/okcalls64.h @@ -17,111 +17,129 @@ * along with HUSTOJ. if not, see . */ //c & c++ -int LANG_CV[256] = {0,1,2,3,4,5,8,9,11,12,20,21,59,63,89,158,231,240, SYS_time, SYS_read, SYS_uname, SYS_write, SYS_open, - SYS_close, SYS_execve, SYS_access, SYS_brk, SYS_munmap, SYS_mprotect, - SYS_mmap, SYS_fstat, SYS_set_thread_area, 252, SYS_arch_prctl, 0 }; +int LANG_CV[CALL_ARRAY_SIZE] = {0,1,2,3,5,8,9,10,11,12,20,21,59,63,89,158,231,292,511, + SYS_read, SYS_write, SYS_mprotect, SYS_munmap, SYS_brk, SYS_arch_prctl, SYS_pread64, SYS_open, SYS_writev, + SYS_time, SYS_futex, SYS_set_thread_area, SYS_access, SYS_clock_gettime, SYS_exit_group, SYS_mq_open, + SYS_ioprio_get, SYS_unshare, SYS_set_robust_list, SYS_splice, SYS_close, SYS_stat, SYS_fstat, SYS_execve, + SYS_uname, SYS_lseek, SYS_readlink, SYS_mmap, SYS_sysinfo, 0 }; //pascal -int LANG_PV[256] = {0,1,2,3,4,9,11,13,16,59,89,97,201,231,SYS_open, SYS_set_thread_area, SYS_brk, SYS_read, - SYS_uname, SYS_write, SYS_execve, SYS_ioctl, SYS_readlink, SYS_mmap, - SYS_rt_sigaction, SYS_getrlimit, 252, 191, 158, 231, SYS_close, - SYS_exit_group, SYS_munmap, SYS_time, 4, 0 }; +int LANG_PV[CALL_ARRAY_SIZE] = { + SYS_read, SYS_write, SYS_mprotect, SYS_munmap, SYS_brk, SYS_rt_sigaction, SYS_arch_prctl, SYS_ioctl, + SYS_pread64, SYS_getxattr, SYS_open, SYS_time, SYS_set_thread_area, SYS_exit_group, SYS_ioprio_get, SYS_close, + SYS_stat, SYS_execve, SYS_uname, SYS_readlink, SYS_mmap, SYS_getrlimit, 0 }; //java -int LANG_JV[256] = { 0,2,3,4,5,9,10,11,12,13,14,21,56,59,89,97,104,158,202,218,231,273,257, - 61, 22, 6, 33, 8, 13, 16, 111, 110, 39, 79, SYS_fcntl, - SYS_getdents64, SYS_getrlimit, SYS_rt_sigprocmask, SYS_futex, SYS_read, - SYS_mmap, SYS_stat, SYS_open, SYS_close, SYS_execve, SYS_access, - SYS_brk, SYS_readlink, SYS_munmap, SYS_close, SYS_uname, SYS_clone, - SYS_uname, SYS_mprotect, SYS_rt_sigaction, SYS_getrlimit, SYS_fstat, - SYS_getuid, SYS_getgid, SYS_geteuid, SYS_getegid, SYS_set_thread_area, - SYS_set_tid_address, SYS_set_robust_list, SYS_exit_group, 158, 0 }; +int LANG_JV[CALL_ARRAY_SIZE] = { + SYS_read, SYS_mprotect, SYS_getuid, SYS_getgid, SYS_geteuid, SYS_getegid, SYS_munmap, SYS_getppid, SYS_getpgrp, + SYS_brk, SYS_rt_sigaction, SYS_rt_sigprocmask, SYS_prctl, SYS_arch_prctl, SYS_ioctl, SYS_pread64, SYS_open, + SYS_futex, SYS_set_thread_area, SYS_access, SYS_getdents64, SYS_set_tid_address, SYS_pipe, SYS_exit_group, + SYS_openat, SYS_set_robust_list, SYS_close, SYS_prlimit64, SYS_dup2, SYS_getpid, SYS_stat, SYS_fstat, SYS_clone, + SYS_execve, SYS_lstat, SYS_wait4, SYS_uname, SYS_fcntl, SYS_getcwd, SYS_lseek, SYS_readlink, SYS_mmap, + SYS_getrlimit, 0 }; //ruby -int LANG_RV[256] = { 0,1,2,3,4,5,6,9,10,12,13,14,16,20,21,22,56,59,72,97,98,107,108,131,158,202,218,228,231,273,293,318 - ,96, 340, 4, 126,79, SYS_access, SYS_arch_prctl, SYS_brk, - SYS_close, SYS_execve, SYS_exit_group, SYS_fstat, SYS_futex, - SYS_getegid, SYS_geteuid, SYS_getgid, SYS_getuid, SYS_getrlimit, - SYS_mmap, SYS_mprotect, SYS_munmap, SYS_open, SYS_read, - SYS_rt_sigaction, SYS_rt_sigprocmask, SYS_set_robust_list, - SYS_set_tid_address, SYS_write, 0 }; +int LANG_RV[CALL_ARRAY_SIZE] = { + SYS_read, SYS_write, SYS_mprotect, SYS_getuid, SYS_getgid, SYS_geteuid, SYS_getegid, SYS_munmap, SYS_brk, + SYS_capset, SYS_rt_sigaction, SYS_sigaltstack, SYS_rt_sigprocmask, SYS_arch_prctl, SYS_ioctl, SYS_pread64, + SYS_open, SYS_futex, SYS_access, SYS_set_tid_address, SYS_pipe, SYS_exit_group, SYS_set_robust_list, SYS_close, + SYS_stat, SYS_fstat, SYS_clone, SYS_execve, SYS_fcntl, SYS_mmap, SYS_gettimeofday, SYS_getrlimit, + SYS_getrusage, 0 }; //bash -int LANG_BV[256] = { 0,1,2,3,4,5,8,9,10,12,13,14,16,21,33,39,59,63,72,79,97,99,102,104,107,108,110,111,158,231, - 96, 22, 61, 56, 42, 41, 79, 158, 117, 60, 39, 102, 191, - 183, SYS_access, SYS_arch_prctl, SYS_brk, SYS_close, SYS_dup2, - SYS_execve, SYS_exit_group, SYS_fcntl, SYS_fstat, SYS_getegid, - SYS_geteuid, SYS_getgid, SYS_getpgrp, SYS_getpid, SYS_getppid, - SYS_getrlimit, SYS_getuid, SYS_ioctl, SYS_lseek, SYS_mmap, SYS_mprotect, - SYS_munmap, SYS_open, SYS_read, SYS_rt_sigaction, SYS_rt_sigprocmask, - SYS_stat, SYS_uname, SYS_write, 14, 0 }; +int LANG_BV[CALL_ARRAY_SIZE] = { + SYS_read, SYS_write, SYS_mprotect, SYS_getuid, SYS_getgid, SYS_geteuid, SYS_getegid, SYS_munmap, SYS_getppid, + SYS_getpgrp, SYS_brk, SYS_rt_sigaction, SYS_rt_sigprocmask, SYS_arch_prctl, SYS_ioctl, SYS_pread64, + SYS_afs_syscall, SYS_getxattr, SYS_open, SYS_access, SYS_pipe, SYS_clock_nanosleep, SYS_exit_group, SYS_openat, + SYS_close, SYS_prlimit64, SYS_dup2, SYS_getpid, SYS_stat, SYS_socket, SYS_connect, SYS_fstat, SYS_clone, + SYS_execve, SYS_exit, SYS_wait4, SYS_uname, SYS_fcntl, SYS_getcwd, SYS_lseek, SYS_mmap, SYS_gettimeofday, + SYS_getrlimit, SYS_sysinfo, 0 }; //python -int LANG_YV[256] = {0,1,2,3,4,5,6,8,9,10,12,13,14,16,20,21,59,78,79,89,97,99,102,104,107,108,158,218,231,273,32,72,131,1,2,3,4,5,6,8,9,10,11,12,13,14,16,21,59,78,79,89,97,102,104,107,108,158,202,218,231,257,273 - ,318, 41, 42, 146, SYS_mremap, 158, 117, 60, 39, 102, 191, - SYS_access, SYS_arch_prctl, SYS_brk, SYS_close, SYS_execve, - SYS_exit_group, SYS_fcntl, SYS_fstat, SYS_futex, SYS_getcwd, - SYS_getdents, SYS_getegid, SYS_geteuid, SYS_getgid, SYS_getrlimit, - SYS_getuid, SYS_ioctl, SYS_lseek, SYS_lstat, SYS_mmap, SYS_mprotect, - SYS_munmap, SYS_open, SYS_read, SYS_readlink, SYS_rt_sigaction, - SYS_rt_sigprocmask, SYS_set_robust_list, SYS_set_tid_address, SYS_stat, - SYS_write, 0 }; +int LANG_YV[CALL_ARRAY_SIZE] = { + SYS_read, SYS_write, SYS_mprotect, SYS_getuid, SYS_getgid, SYS_geteuid, SYS_getegid, SYS_munmap, SYS_brk, + SYS_rt_sigaction, SYS_sigaltstack, SYS_rt_sigprocmask, SYS_sched_get_priority_max, SYS_arch_prctl, SYS_ioctl, + SYS_pread64, SYS_getxattr, SYS_open, SYS_futex, SYS_access, SYS_getdents64, SYS_set_tid_address, SYS_clock_gettime, + SYS_exit_group, SYS_mremap, SYS_openat, SYS_unshare, SYS_set_robust_list, SYS_close, SYS_prlimit64, + 318, SYS_dup, SYS_getpid, SYS_stat, SYS_socket, SYS_connect, SYS_fstat, SYS_execve, SYS_lstat, + SYS_exit, SYS_fcntl, SYS_getdents, SYS_getcwd, SYS_lseek, SYS_readlink, SYS_mmap, SYS_getrlimit, + SYS_sysinfo, 0 }; //php -int LANG_PHV[256] = { 0,1,2,3,4,5,6,8,9,10,11,12,13,14,16,21,28,59,79,97,158,202,218,231,257,273, - 257, 20, 146, 78, 158, 117, 60, 39, 102, 191, SYS_access, - SYS_brk, SYS_clone, SYS_close, SYS_execve, SYS_exit_group, SYS_fcntl, - SYS_fstat, SYS_futex, SYS_getcwd, SYS_getdents64, SYS_getrlimit, - SYS_gettimeofday, SYS_ioctl, SYS_lseek, SYS_lstat, SYS_mmap, - SYS_mprotect, SYS_munmap, SYS_open, SYS_read, SYS_readlink, - SYS_rt_sigaction, SYS_rt_sigprocmask, SYS_set_robust_list, - SYS_set_thread_area, SYS_set_tid_address, SYS_stat, SYS_time, SYS_uname, - SYS_write, 0 }; +int LANG_PHV[CALL_ARRAY_SIZE] = { + SYS_read, SYS_write, SYS_mprotect, SYS_munmap, SYS_brk, SYS_rt_sigaction, SYS_rt_sigprocmask, + SYS_sched_get_priority_max, SYS_arch_prctl, SYS_ioctl, SYS_pread64, SYS_getxattr, SYS_open, SYS_writev, + SYS_time, SYS_futex, SYS_set_thread_area, SYS_access, SYS_getdents64, SYS_set_tid_address, SYS_exit_group, + SYS_openat, SYS_set_robust_list, SYS_close, SYS_getpid, SYS_stat, SYS_fstat, SYS_clone, SYS_execve, SYS_lstat, + SYS_exit, SYS_uname, SYS_fcntl, SYS_getdents, SYS_getcwd, SYS_lseek, SYS_readlink, SYS_mmap, SYS_gettimeofday, + SYS_getrlimit, 0 }; //perl -int LANG_PLV[256] = {0,1,2,3,4,5,8,9,10,12,13,14,16,21,59,72,89,97,102,104,107,108,158,202,218,231,273, - 96, 78, 158, 117, 60, 39, 102, 191, SYS_access, SYS_brk, - SYS_close, SYS_execve, SYS_exit_group, SYS_fcntl, SYS_fstat, SYS_futex, - SYS_getegid, SYS_geteuid, SYS_getgid, SYS_getrlimit, SYS_getuid, - SYS_ioctl, SYS_lseek, SYS_mmap, SYS_mprotect, SYS_munmap, SYS_open, - SYS_read, SYS_readlink, SYS_rt_sigaction, SYS_rt_sigprocmask, - SYS_set_robust_list, SYS_set_thread_area, SYS_set_tid_address, SYS_stat, - SYS_time, SYS_uname, SYS_write, 0 }; +int LANG_PLV[CALL_ARRAY_SIZE] = { + SYS_read, SYS_write, SYS_mprotect, SYS_getuid, SYS_getgid, SYS_geteuid, SYS_getegid, SYS_munmap, SYS_brk, + SYS_rt_sigaction, SYS_rt_sigprocmask, SYS_arch_prctl, SYS_ioctl, SYS_pread64, SYS_getxattr, SYS_open, SYS_time, + SYS_futex, SYS_set_thread_area, SYS_access, SYS_set_tid_address, SYS_exit_group, SYS_set_robust_list, SYS_close, + SYS_getpid, SYS_stat, SYS_fstat, SYS_execve, SYS_exit, SYS_uname, SYS_fcntl, SYS_getdents, SYS_lseek, + SYS_readlink, SYS_mmap, SYS_gettimeofday, SYS_getrlimit, 0 }; //c-sharp -int LANG_CSV[256] = {0,1,2,3,4,5,8,9,10,11,12,13,14,16,21,24,41,42,56,59,63,72,78,79,89,97 - ,102,131,137,158,202,204,218,229,231,234,257,273, 257, 141, 95, 64, 65, 66 - , 83, 24, 42, 41, 158, 117, 60, - 39, 102, 191, SYS_access, SYS_brk, SYS_chmod, SYS_clock_getres, - SYS_clock_gettime, SYS_clone, SYS_close, SYS_execve, SYS_exit_group, - SYS_fcntl, SYS_fstat, SYS_ftruncate, SYS_futex, SYS_getcwd, - SYS_getdents, SYS_geteuid, SYS_getpid, SYS_getppid, SYS_getrlimit, - SYS_gettimeofday, SYS_getuid, SYS_ioctl, SYS_lseek, SYS_lstat, SYS_mmap, - SYS_mprotect, SYS_mremap, SYS_munmap, SYS_open, SYS_read, SYS_readlink, - SYS_rt_sigaction, SYS_rt_sigprocmask, SYS_sched_getaffinity, - SYS_sched_getparam, SYS_sched_get_priority_max, - SYS_sched_get_priority_min, SYS_sched_getscheduler, SYS_set_robust_list, - SYS_set_thread_area, SYS_set_tid_address, SYS_sigaltstack, SYS_stat, - SYS_statfs, SYS_tgkill, SYS_time, SYS_uname, SYS_unlink, SYS_write, 0 }; +int LANG_CSV[CALL_ARRAY_SIZE] = { + SYS_read, SYS_write, SYS_mprotect, SYS_getuid, SYS_geteuid, SYS_munmap, SYS_getppid, SYS_brk, SYS_rt_sigaction, + SYS_sigaltstack, SYS_statfs, SYS_rt_sigprocmask, SYS_setpriority, SYS_sched_getparam, SYS_sched_getscheduler, + SYS_sched_get_priority_max, SYS_sched_get_priority_min, SYS_prctl, SYS_arch_prctl, SYS_ioctl, SYS_pread64, + SYS_getxattr, SYS_open, SYS_time, SYS_futex, SYS_sched_getaffinity, SYS_set_thread_area, SYS_access, + SYS_getdents64, SYS_set_tid_address, SYS_clock_gettime, SYS_clock_getres, SYS_exit_group, SYS_tgkill, + SYS_sched_yield, SYS_mremap, SYS_openat, SYS_set_robust_list, SYS_close, SYS_prlimit64, SYS_getpid, SYS_stat, + SYS_socket, SYS_connect, SYS_fstat, SYS_clone, SYS_execve, SYS_lstat, SYS_exit, SYS_uname, SYS_semget, + SYS_semop, SYS_semctl, SYS_fcntl, SYS_ftruncate, SYS_getdents, SYS_getcwd, SYS_lseek, SYS_mkdir, SYS_unlink, + SYS_readlink, SYS_mmap, SYS_chmod, SYS_umask, SYS_gettimeofday, SYS_getrlimit, 0 }; //objective-c -int LANG_OV[256] = { 0,1,2,3,4,5,9,10,12,21,59,158,231, 102, 191, SYS_access, SYS_brk, SYS_close, - SYS_execve, SYS_exit_group, SYS_fstat, SYS_futex, SYS_getcwd, - SYS_getrlimit, SYS_gettimeofday, SYS_mmap, SYS_mprotect, SYS_munmap, - SYS_open, SYS_read, SYS_readlink, SYS_rt_sigaction, SYS_rt_sigprocmask, - SYS_set_robust_list, SYS_set_thread_area, SYS_set_tid_address, - SYS_uname, SYS_write, 0 }; +int LANG_OV[CALL_ARRAY_SIZE] = { + SYS_read, SYS_write, SYS_mprotect, SYS_getuid, SYS_munmap, SYS_brk, SYS_rt_sigaction, SYS_rt_sigprocmask, + SYS_arch_prctl, SYS_pread64, SYS_getxattr, SYS_open, SYS_futex, SYS_set_thread_area, SYS_access, + SYS_set_tid_address, SYS_exit_group, SYS_set_robust_list, SYS_close, SYS_stat, SYS_fstat, SYS_execve, SYS_uname, + SYS_getcwd, SYS_readlink, SYS_mmap, SYS_gettimeofday, SYS_getrlimit, 0 }; //freebasic -int LANG_BASICV[256] = { 0,1,2,3,4,5,9,10,12,13,14,16,21,59,97,158,173,202,218,231,273, - 101, 54, 122, 175, 174, 240, 311, 258, 243, 6, 197, - 252, 146, 195, 192, 33, 45, 125, 191, SYS_access, SYS_brk, SYS_close, - SYS_execve, SYS_exit_group, SYS_fstat, SYS_futex, SYS_getrlimit, - SYS_ioctl, SYS_ioperm, SYS_mmap, SYS_open, SYS_read, SYS_rt_sigaction, - SYS_rt_sigprocmask, SYS_set_robust_list, SYS_set_thread_area, - SYS_set_tid_address, SYS_stat, SYS_uname, SYS_write, 0 }; +int LANG_BASICV[CALL_ARRAY_SIZE] = { + SYS_read, SYS_write, SYS_mprotect, SYS_ptrace, SYS_brk, SYS_setfsuid, SYS_capget, SYS_rt_sigaction, + SYS_rt_sigprocmask, SYS_sched_get_priority_max, SYS_arch_prctl, SYS_ioctl, SYS_pread64, SYS_ioperm, + SYS_create_module, SYS_init_module, SYS_getxattr, SYS_lgetxattr, SYS_llistxattr, SYS_removexattr, SYS_open, + SYS_futex, SYS_set_thread_area, SYS_access, SYS_set_tid_address, SYS_exit_group, SYS_mq_open, + SYS_mq_timedreceive, SYS_ioprio_get, SYS_mkdirat, SYS_set_robust_list, SYS_close, SYS_process_vm_writev, + SYS_dup2, SYS_stat, SYS_recvfrom, SYS_fstat, SYS_setsockopt, SYS_execve, SYS_lstat, SYS_uname, SYS_mmap, + SYS_getrlimit, 0 }; //scheme -int LANG_SV[256] = { 0,1,2,3,4,5,8,9,10,11,12,13,14,16,21,56,59,72,97,158,202,204,218,228,229,234,273,293,0, - SYS_fcntl, SYS_getdents64, SYS_getrlimit, SYS_rt_sigprocmask, SYS_futex, - SYS_read, SYS_mmap, SYS_stat, SYS_open, SYS_close, SYS_execve, - SYS_access, SYS_brk, SYS_readlink, SYS_munmap, SYS_close, SYS_uname, - SYS_clone, SYS_uname, SYS_mprotect, SYS_rt_sigaction, SYS_getrlimit, - SYS_fstat, SYS_getuid, SYS_getgid, SYS_geteuid, SYS_getegid, - SYS_set_thread_area, SYS_set_tid_address, SYS_set_robust_list, - SYS_exit_group, 158, 0 }; +int LANG_SV[CALL_ARRAY_SIZE] = { + SYS_read, SYS_write, SYS_mprotect, SYS_times, SYS_getuid, SYS_getgid, SYS_geteuid, SYS_getegid, SYS_munmap, + SYS_getppid, SYS_getpgrp, SYS_brk, SYS_rt_sigaction, SYS_rt_sigprocmask, SYS_arch_prctl, SYS_ioctl, SYS_open, + SYS_futex, SYS_set_thread_area, SYS_access, SYS_getdents64, SYS_set_tid_address, SYS_pipe, SYS_select, + SYS_exit_group, SYS_set_robust_list, SYS_close, SYS_dup2, SYS_getpid, SYS_stat, SYS_fstat, SYS_clone, + SYS_execve, SYS_lstat, SYS_wait4, SYS_uname, SYS_fcntl, SYS_getcwd, SYS_lseek, SYS_readlink, SYS_mmap, + SYS_getrlimit, 0 }; //lua -int LANG_LUAV[256]={0,1,2,3,4,5,9,10,11,12,13,21,59,158,231,292,0}; +int LANG_LUAV[CALL_ARRAY_SIZE] = { + SYS_read, SYS_write, SYS_mprotect, SYS_munmap, SYS_brk, SYS_rt_sigaction, SYS_arch_prctl, SYS_pread64, SYS_open, + SYS_access, SYS_exit_group, SYS_dup3, SYS_close, SYS_stat, SYS_fstat, SYS_execve, SYS_mmap, 0 }; //nodejs javascript -int LANG_JSV[256]={0,1,2,3,4,5,6,9,10,11,12,13,14,16,21,56,59,79,89,96,97,158,186,202,218,228,231,232,233,273,290,291,293,0}; +int LANG_JSV[CALL_ARRAY_SIZE] = { + SYS_read, SYS_write, SYS_mprotect, SYS_getuid, SYS_getgid, SYS_geteuid, SYS_getegid, SYS_munmap, SYS_brk, + SYS_rt_sigaction, SYS_rt_sigprocmask, SYS_arch_prctl, SYS_ioctl, SYS_setrlimit, SYS_pread64, SYS_gettid, + SYS_open, SYS_writev, SYS_futex, SYS_access, SYS_set_tid_address, SYS_clock_gettime, SYS_clock_getres, + SYS_exit_group, SYS_epoll_wait, SYS_epoll_ctl, SYS_set_robust_list, SYS_eventfd2, SYS_epoll_create1, SYS_pipe2, + SYS_close, SYS_stat, SYS_fstat, SYS_clone, SYS_execve, SYS_lstat, SYS_poll, SYS_getcwd, SYS_readlink, SYS_mmap, + SYS_gettimeofday, SYS_getrlimit, 0 }; //go-lang -int LANG_GOV[256]={0,1,9,11,13,14,56,59,131,158,186,202,204,231,0}; +int LANG_GOV[CALL_ARRAY_SIZE] = { + SYS_read, SYS_write, SYS_mprotect, SYS_munmap, SYS_rt_sigaction, SYS_sigaltstack, SYS_rt_sigprocmask, + SYS_arch_prctl, SYS_pread64, SYS_gettid, SYS_futex, SYS_sched_getaffinity, SYS_clock_gettime, SYS_exit_group, + SYS_sched_yield, SYS_openat, SYS_readlinkat, SYS_clone, SYS_execve, SYS_fcntl, SYS_mmap, 0 }; +//sqlite3 +int LANG_SQLV[CALL_ARRAY_SIZE] = { + SYS_read, SYS_write, SYS_mprotect, SYS_getuid, SYS_geteuid, SYS_brk, SYS_rt_sigaction, SYS_rt_sigprocmask, + SYS_arch_prctl, SYS_ioctl, SYS_pread64, SYS_open, SYS_futex, SYS_access, SYS_set_tid_address, SYS_exit_group, + SYS_set_robust_list, SYS_close, SYS_stat, SYS_socket, SYS_connect, SYS_fstat, SYS_execve, SYS_semget, SYS_fcntl, + SYS_fsync, SYS_getcwd, SYS_lseek, SYS_unlink, SYS_mmap, SYS_getrlimit, 0 }; +//fortran +int LANG_FV[CALL_ARRAY_SIZE] = { + SYS_read, SYS_write, SYS_mprotect, SYS_brk, SYS_rt_sigaction, SYS_arch_prctl, SYS_pread64, SYS_access, + SYS_exit_group, SYS_fstat, SYS_execve, SYS_uname, SYS_readlink, 0 }; +//octave +int LANG_MV[CALL_ARRAY_SIZE] = { + SYS_read, SYS_write, SYS_mprotect, SYS_getuid, SYS_munmap, SYS_brk, SYS_rt_sigaction, SYS_rt_sigprocmask, + SYS_arch_prctl, SYS_ioctl, SYS_writev, SYS_futex, SYS_sched_getaffinity, SYS_access, SYS_set_tid_address, + SYS_exit_group, SYS_openat, SYS_set_robust_list, SYS_close, SYS_prlimit64, 318, SYS_getpid, SYS_stat, + SYS_socket, SYS_connect, SYS_recvfrom, SYS_shutdown, SYS_fstat, SYS_getpeername, SYS_clone, SYS_execve, + SYS_lstat, SYS_uname, SYS_poll, SYS_fcntl, SYS_getdents, SYS_getcwd, SYS_lseek, SYS_readlink, SYS_mmap, + SYS_gettimeofday, 0 }; diff --git a/judger/core/judge_client/okcalls_aarch64.h b/judger/core/judge_client/okcalls_aarch64.h new file mode 100644 index 00000000..baeddf32 --- /dev/null +++ b/judger/core/judge_client/okcalls_aarch64.h @@ -0,0 +1,56 @@ +/* + * + * + * This file is part of HUSTOJ. + * + * HUSTOJ is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * HUSTOJ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with HUSTOJ. if not, see . + */ +#include +#define HOJ_MAX_LIMIT -1 +//C C++ +int LANG_CV[CALL_ARRAY_SIZE]={48,56,62,63,64,72,78,80,94,104,112,134,135,160,184,200,214,216,220,221,248,152,344,136,120,8,40,232,328,440,424,472,360,24,456,504,296,168,376,382,392,511,280,488,88,312,264,408,0}; +//pascal +int LANG_PV[CALL_ARRAY_SIZE] = {29,63,64,78,94,112,134,163,220,511,0}; +//java +int LANG_JV[CALL_ARRAY_SIZE] ={48,56,57,63,78,79,80,94,96,98,99,112,134,135,163,172,179,214,215,220,222,226,511,0}; +//ruby +int LANG_RV[CALL_ARRAY_SIZE] = {0,0}; +//bash +int LANG_BV[CALL_ARRAY_SIZE]={0,3,4,5,6,19,20,33,45,54,63,64,65,78,122,125,140,174,175,183,191,192,195,197,199,200,201,202,221,248,0}; +//python +int LANG_YV[CALL_ARRAY_SIZE] = {0,3,4,5,6,19,33,41,45,54,85,91,122,125,140,174,175,183,186,191,192,195,196,197,199,200,201,202,217,221,240,248,256,322,338,0}; +//php +int LANG_PHV[CALL_ARRAY_SIZE] = {0,0}; +//perl +int LANG_PLV[CALL_ARRAY_SIZE] = {0,0}; +//c-sharp +int LANG_CSV[CALL_ARRAY_SIZE]={0,3,5,6,19,33,45,122,125,174,175,191,192,195,197,256,338,0}; +//objective-c +int LANG_OV[CALL_ARRAY_SIZE] = {0,0}; +//freebasic +int LANG_BASICV[CALL_ARRAY_SIZE] = {0,0}; +//scheme +int LANG_SV[CALL_ARRAY_SIZE] = {0,0}; +//lua +int LANG_LUAV[CALL_ARRAY_SIZE]={0,0}; +//nodejs +int LANG_JSV[CALL_ARRAY_SIZE]={0,0}; +//go-lang +int LANG_GOV[CALL_ARRAY_SIZE]={0,0}; +//sqlite3 +int LANG_SQLV[CALL_ARRAY_SIZE]={0,0}; +//fortran +int LANG_FV[CALL_ARRAY_SIZE]={0,3,4,5,33,45,85,122,174,197,248,0}; +//matlib +int LANG_MV[CALL_ARRAY_SIZE]={0,2,3,4,5,6,11,19,33,45,54,78,91,122,125,140,174,175,183,191,192,195,197,199,201,217,240,242,248,256,281,283,338,384,0}; diff --git a/judger/core/judge_client/okcalls_arm.h b/judger/core/judge_client/okcalls_arm.h new file mode 100644 index 00000000..0dcd1347 --- /dev/null +++ b/judger/core/judge_client/okcalls_arm.h @@ -0,0 +1,57 @@ +/* + * + * + * This file is part of HUSTOJ. + * + * HUSTOJ is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * HUSTOJ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with HUSTOJ. if not, see . + */ +#include +#define HOJ_MAX_LIMIT -1 +#define LANGV_LENGTH 256 +//C C++ +int LANG_CV[CALL_ARRAY_SIZE]={0,3,4,5,33,45,85,122,192,197,248,0}; +//pascal +int LANG_PV[CALL_ARRAY_SIZE] = {0,3,4,54,85,174,191,248,0}; +//java +int LANG_JV[CALL_ARRAY_SIZE] ={0,3,5,6,11,20,33,45,85,91,120,122,125,140,174,175,191,192,195,197,240,248,256,322,338,0};//{0,2,3,5,6,19,33,45,85,91,120,122,125,174,175,191,192,195,197,240,248,256,322,338,0}; +//ruby +int LANG_RV[CALL_ARRAY_SIZE] = {0,0}; +//bash +int LANG_BV[CALL_ARRAY_SIZE]={0,3,4,5,6,19,20,33,45,54,63,64,65,78,122,125,140,174,175,183,191,192,195,197,199,200,201,202,221,248,0}; +//python +int LANG_YV[CALL_ARRAY_SIZE] = {0,3,4,5,6,19,33,41,45,54,85,91,122,125,140,174,175,183,186,191,192,195,196,197,199,200,201,202,217,221,240,248,256,322,338,0}; +//php +int LANG_PHV[CALL_ARRAY_SIZE] = {0,0}; +//perl +int LANG_PLV[CALL_ARRAY_SIZE] = {0,0}; +//c-sharp +int LANG_CSV[CALL_ARRAY_SIZE]={0,3,5,6,19,33,45,122,125,174,175,191,192,195,197,256,338,0}; +//objective-c +int LANG_OV[CALL_ARRAY_SIZE] = {0,0}; +//freebasic +int LANG_BASICV[CALL_ARRAY_SIZE] = {0,0}; +//scheme +int LANG_SV[CALL_ARRAY_SIZE] = {0,0}; +//lua +int LANG_LUAV[CALL_ARRAY_SIZE]={0,0}; +//nodejs +int LANG_JSV[CALL_ARRAY_SIZE]={0,0}; +//go-lang +int LANG_GOV[CALL_ARRAY_SIZE]={0,0}; +//sqlite3 +int LANG_SQLV[CALL_ARRAY_SIZE]={0,0}; +//fortran +int LANG_FV[CALL_ARRAY_SIZE]={0,3,4,5,33,45,85,122,174,197,248,0}; +//matlib +int LANG_MV[CALL_ARRAY_SIZE]={0,2,3,4,5,6,11,19,33,45,54,78,91,122,125,140,174,175,183,191,192,195,197,199,201,217,240,242,248,256,281,283,338,384,0}; diff --git a/judger/core/judge_client/okcalls_mips.h b/judger/core/judge_client/okcalls_mips.h new file mode 100644 index 00000000..d6be2a63 --- /dev/null +++ b/judger/core/judge_client/okcalls_mips.h @@ -0,0 +1,58 @@ +/* + * + * + * This file is part of HUSTOJ. + * + * HUSTOJ is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * HUSTOJ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with HUSTOJ. if not, see . + */ +#include +#define HOJ_MAX_LIMIT -1 +//C C++ +int LANG_CV[CALL_ARRAY_SIZE]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,34,35,36,37,38,40,41,42,43,46,47,49,50,51,52,54,55,56,59,61,62,63,64,65,66,68,70,71,72,73,74,78,81,82,84,85,89,90,91,92,93,97,100,108,110,122,125,126,146,148,152,163,165,166,167,176,179,180,182,183,184,185,186,194,195,199,215,217,220,222,228,239,257,260,262,272,273,287,288,295,297,319,320,327,328,334,336,362,363,387,390,392,393,397,400,401,403,404,412,452,453,455,467,469,479,481,482,485,486,489,0}; +//pascal +int LANG_PV[CALL_ARRAY_SIZE] = {0,3,4,54,85,174,191,248,0}; +//java +int LANG_JV[CALL_ARRAY_SIZE]={0,2,7,8,9,29,32,33,34,36,40,44,45,46,48,49,66,74,81,85,90,92,95,122,148,156,167,168,185,194,197,199,200,204,205,222,226,232,237,241,263,300,320,326,346,349,352,356,361,363,364,381,382,392,393,394,395,396,397,398,399,400,401,402,403,404,405,406,412,416,423,430,439,447,448,479,482,487,509,510,0}; +//ruby +int LANG_RV[CALL_ARRAY_SIZE] = {0,0}; +//bash +int LANG_BV[CALL_ARRAY_SIZE]={0,3,4,5,6,19,20,33,45,54,63,64,65,78,122,125,140,174,175,183,191,192,195,197,199,200,201,202,221,248,0}; +//python +int LANG_YV[CALL_ARRAY_SIZE]={0,1,2,6,8,11,15,20,21,22,24,30,31,32,36,37,39,40,41,44,48,49,51,54,56,60,61,63,65,68,71,72,73,74,76,81,83,86,87,88,91,92,94,97,98,101,102,109,111,114,115,120,122,124,126,131,133,135,136,140,144,146,147,148,151,155,156,161,162,165,168,171,172,173,177,181,182,183,185,187,191,192,194,197,198,201,208,209,211,212,213,214,215,220,222,228,231,234,238,240,241,242,244,247,251,252,253,255,256,257,260,261,265,266,267,268,273,274,276,278,282,284,285,287,292,293,294,295,298,303,308,309,311,313,316,321,322,329,332,335,337,340,342,343,344,345,346,348,351,352,353,355,356,360,366,371,372,373,377,379,384,385,388,392,393,396,398,401,403,409,413,414,419,422,425,426,427,432,433,435,436,442,443,444,445,446,448,450,451,452,453,454,456,460,461,466,468,471,472,473,474,477,480,481,483,484,485,488,493,494,496,498,499,500,502,503,510,0}; +//int LANG_YV[CALL_ARRAY_SIZE]={0,6,11,22,24,32,65,86,111,122,126,133,135,165,211,222,228,234,238,265,276,287,311,322,329,335,345,377,422,433,435,444,445,477,496,0}; +//php +int LANG_PHV[CALL_ARRAY_SIZE] = {0,0}; +//perl +int LANG_PLV[CALL_ARRAY_SIZE] = {0,0}; +//c-sharp +int LANG_CSV[CALL_ARRAY_SIZE]={0,3,5,6,19,33,45,122,125,174,175,191,192,195,197,256,338,0}; +//objective-c +int LANG_OV[CALL_ARRAY_SIZE] = {0,0}; +//freebasic +int LANG_BASICV[CALL_ARRAY_SIZE] = {0,0}; +//scheme +int LANG_SV[CALL_ARRAY_SIZE] = {0,0}; +//lua +int LANG_LUAV[CALL_ARRAY_SIZE]={0,0}; +//nodejs +int LANG_JSV[CALL_ARRAY_SIZE]={0,0}; +//go-lang +int LANG_GOV[CALL_ARRAY_SIZE]={0,0}; +//sqlite3 +int LANG_SQLV[CALL_ARRAY_SIZE]={0,1,2,3,4,5,6,7,12,13,16,17,18,20,21,22,25,28,32,36,40,41,44,49,51,52,57,64,70,85,90,92,100,119,122,127,148,152,167,168,174,177,197,216,272,320,360,392,393,395,396,397,398,400,401,402,404,405,406,407,408,409,412,430,432,433,459,461,462,465,468,469,477,487,492,497,0}; +//fortran + +int LANG_FV[CALL_ARRAY_SIZE]={0,2,3,4,6,85,122,392,393,397,404,405,412,453,479,0}; +//matlab octave +int LANG_MV[CALL_ARRAY_SIZE]={0,1,2,3,4,5,6,9,8,10,11,12,13,16,17,18,22,24,25,28,32,33,36,40,42,48,55,56,57,60,61,64,66,72,74,76,80,83,85,88,92,96,104,111,112,116,120,122,124,126,128,131,132,133,134,135,136,144,147,148,152,157,160,164,168,169,176,179,184,185,193,200,208,215,216,224,245,248,251,256,257,264,272,279,287,288,296,304,312,315,318,320,323,328,336,337,339,344,347,349,352,368,371,372,376,377,384,385,392,393,394,395,396,397,399,400,401,402,403,404,405,406,407,408,411,412,424,431,432,433,435,436,439,440,443,446,447,448,451,452,453,455,456,462,464,468,469,472,487,488,490,492,496,497,504,510,511,0}; diff --git a/judger/core/judged/judged.cc b/judger/core/judged/judged.cc index 06d5af2b..56819d8e 100755 --- a/judger/core/judged/judged.cc +++ b/judger/core/judged/judged.cc @@ -34,11 +34,15 @@ #include #include #include +#include +#include +#include +#include #define BUFFER_SIZE 1024 #define LOCKFILE "/var/run/judged.pid" #define LOCKMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) -#define STD_MB 1048576 +#define STD_MB 1048576LL #define OJ_WT0 0 #define OJ_WT1 1 @@ -71,6 +75,11 @@ static char http_baseurl[BUFFER_SIZE]; static char http_username[BUFFER_SIZE]; static char http_password[BUFFER_SIZE]; +static int oj_udp = 0; +static char oj_udpserver[BUFFER_SIZE]; +static int oj_udpport=1536; +static int oj_udp_fd; + static int oj_redis = 0; static char oj_redisserver[BUFFER_SIZE]; static int oj_redisport; @@ -89,10 +98,36 @@ static MYSQL_ROW row; static char query[BUFFER_SIZE]; #endif +void wait_udp_msg(int fd) +{ + char buf[BUFFER_SIZE]; //......1024.. + socklen_t len; + int count; + struct sockaddr_in clent_addr; //clent_addr............ + memset(buf, 0, BUFFER_SIZE); + len = sizeof(clent_addr); + count = recvfrom(fd, buf, BUFFER_SIZE, 0, (struct sockaddr*)&clent_addr, &len); //recvfrom............... + if(count == -1) + { + printf("recieve data fail!\n"); + return; + } + printf("udp client:%s\n",buf); //..client...... + memset(buf, 0, BUFFER_SIZE); +// sprintf(buf, "I have recieved %d bytes data!\n", count); //..client +// printf("server:%s\n",buf); //.......... +// sendto(fd, buf, BUFF_LEN, 0, (struct sockaddr*)&clent_addr, len); //.....client......clent_addr..... + +} + void call_for_exit(int s) { - STOP = true; - printf("Stopping judged...\n"); + if(DEBUG){ + STOP = true; + printf("Stopping judged...\n"); + }else{ + printf("HUSTOJ Refusing to stop...\n Please use kill -9 !\n"); + } } void write_log(const char *fmt, ...) @@ -171,6 +206,7 @@ void init_mysql_conf() oj_tot = 1; oj_mod = 0; strcpy(oj_lang_set, "0,1,2,3"); + strcpy(oj_udpserver, "127.0.0.1"); fp = fopen("./etc/judge.conf", "r"); if (fp != NULL) { @@ -193,6 +229,10 @@ void init_mysql_conf() read_buf(buf, "OJ_HTTP_PASSWORD", http_password); read_buf(buf, "OJ_LANG_SET", oj_lang_set); + read_int(buf, "OJ_UDP_ENABLE", &oj_udp); + read_buf(buf, "OJ_UDP_SERVER", oj_udpserver); + read_int(buf, "OJ_UDP_PORT", &oj_udpport); + read_int(buf, "OJ_REDISENABLE", &oj_redis); read_buf(buf, "OJ_REDISSERVER", oj_redisserver); read_int(buf, "OJ_REDISPORT", &oj_redisport); @@ -201,12 +241,18 @@ void init_mysql_conf() read_int(buf, "OJ_TURBO_MODE", &turbo_mode); } #ifdef _mysql_h + if (oj_tot==1){ + sprintf(query, + "SELECT solution_id FROM solution WHERE language in (%s) and result<2 ORDER BY solution_id limit %d", + oj_lang_set, 2 *max_running ); + }else{ sprintf(query, "SELECT solution_id FROM solution WHERE language in (%s) and result<2 and MOD(solution_id,%d)=%d ORDER BY result ASC,solution_id ASC limit %d", oj_lang_set, oj_tot, oj_mod, max_running * 2); + } #endif sleep_tmp = sleep_time; - // fclose(fp); + fclose(fp); } } @@ -218,15 +264,32 @@ void run_client(int runid, int clientid) LIM.rlim_cur = 800; setrlimit(RLIMIT_CPU, &LIM); - LIM.rlim_max = 180 * STD_MB; - LIM.rlim_cur = 180 * STD_MB; + LIM.rlim_max = 800 * STD_MB; + LIM.rlim_cur = 800 * STD_MB; setrlimit(RLIMIT_FSIZE, &LIM); - +#ifdef __mips__ + LIM.rlim_max = STD_MB << 12; + LIM.rlim_cur = STD_MB << 12; +#endif +#ifdef __arm__ LIM.rlim_max = STD_MB << 11; LIM.rlim_cur = STD_MB << 11; +#endif +#ifdef __aarch64__ + LIM.rlim_max = STD_MB << 15; + LIM.rlim_cur = STD_MB << 15; +#endif +#ifdef __i386 + LIM.rlim_max = STD_MB << 11; + LIM.rlim_cur = STD_MB << 11; +#endif +#ifdef __x86_64__ + LIM.rlim_max = STD_MB << 15; + LIM.rlim_cur = STD_MB << 15; +#endif setrlimit(RLIMIT_AS, &LIM); - LIM.rlim_cur = LIM.rlim_max = 200; + LIM.rlim_cur = LIM.rlim_max = 800* max_running; setrlimit(RLIMIT_NPROC, &LIM); //buf[0]=clientid+'0'; buf[1]=0; @@ -236,13 +299,17 @@ void run_client(int runid, int clientid) //write_log("sid=%s\tclient=%s\toj_home=%s\n",runidstr,buf,oj_home); //sprintf(err,"%s/run%d/error.out",oj_home,clientid); //freopen(err,"a+",stderr); + char * const envp[]={(char * const )"PYTHONIOENCODING=utf-8", + (char * const )"LANG=zh_CN.UTF-8", + (char * const )"LANGUAGE=zh_CN.UTF-8", + (char * const )"LC_ALL=zh_CN.UTF-8",NULL}; - if (!DEBUG) + //if (!DEBUG) execl("/usr/bin/judge_client", "/usr/bin/judge_client", runidstr, buf, oj_home, (char *)NULL); - else - execl("/usr/bin/judge_client", "/usr/bin/judge_client", runidstr, buf, - oj_home, "debug", (char *)NULL); + //else + // execl("/usr/bin/judge_client", "/usr/bin/judge_client", runidstr, buf, + // oj_home, "debug", (char *) NULL); //exit(0); } @@ -283,12 +350,12 @@ int init_mysql() } else { - return 0; + return executesql("set names utf8"); } } else { - return executesql("set names utf8"); + return executesql("commit"); } } #endif @@ -490,13 +557,13 @@ bool check_out(int solution_id, int result) #endif } } + static int workcnt = 0; int work() { // char buf[1024]; - static int retcnt = 0; + int retcnt = 0; int i = 0; static pid_t ID[100]; - static int workcnt = 0; int runid = 0; int jobs[max_running * 2 + 1]; pid_t tmp_pid = 0; @@ -504,6 +571,8 @@ int work() //for(i=0;i= max_running) { // if no more client can running - tmp_pid = waitpid(-1, NULL, 0); // wait 4 one child exit + tmp_pid = waitpid(-1, NULL, WNOHANG); // wait 4 one child exit + if (DEBUG) printf("try get one tmp_pid=%d\n",tmp_pid); for (i = 0; i < max_running; i++) { // get the client id if (ID[i] == tmp_pid) @@ -549,19 +617,30 @@ int work() if (ID[i] == 0) { if (DEBUG) + { + write_log("Judging solution %d", runid); write_log("<<=sid=%d===clientid=%d==>>\n", runid, i); + } run_client(runid, i); // if the process is the son, run it + workcnt--; exit(0); } } else { - ID[i] = 0; + // ID[i] = 0; + if(DEBUG){ + if(workcnt 0) - { + while ((tmp_pid = waitpid(-1, NULL, WNOHANG)) > 0) { for (i = 0; i < max_running; i++) { // get the client id if (ID[i] == tmp_pid) @@ -668,7 +747,7 @@ int daemon_init(void) void turbo_mode2() { #ifdef _mysql_h - if (turbo_mode == 2) + if(turbo_mode == 2) { char sql[BUFFER_SIZE]; sprintf(sql, " CALL `sync_result`();"); @@ -679,6 +758,7 @@ void turbo_mode2() } int main(int argc, char **argv) { + int oj_udp_ret=0; DEBUG = (argc > 2); ONCE = (argc > 3); if (argc > 1) @@ -705,13 +785,34 @@ int main(int argc, char **argv) #ifdef _mysql_h init_mysql_conf(); // set the database info #endif + if(oj_udp){ + oj_udp_fd = socket(AF_INET, SOCK_DGRAM, 0); + if(oj_udp_fd<0) + printf("udp fd open failed! \n"); + struct sockaddr_in ser_addr; + memset(&ser_addr, 0, sizeof(ser_addr)); + ser_addr.sin_family = AF_INET; + ser_addr.sin_addr.s_addr = inet_addr(oj_udpserver); + ser_addr.sin_port = htons(oj_udpport); + struct timeval timeOut; + timeOut.tv_sec = sleep_time; //..5s.. + timeOut.tv_usec = 0; + if (setsockopt(oj_udp_fd, SOL_SOCKET, SO_RCVTIMEO, &timeOut, sizeof(timeOut)) < 0) + { + printf("time out setting failed\n"); + } + oj_udp_ret=bind(oj_udp_fd, (struct sockaddr*)&ser_addr, sizeof(ser_addr)); + if(oj_udp_ret<0) + printf("udp fd open failed! \n"); + } signal(SIGQUIT, call_for_exit); - signal(SIGKILL, call_for_exit); + signal(SIGINT, call_for_exit); signal(SIGTERM, call_for_exit); int j = 1; int n = 0; - while (1) - { // start to run + while (!STOP) + { // start to run until call for exit + n=0; while (j && (http_judge #ifdef _mysql_h || !init_mysql() @@ -733,7 +834,17 @@ int main(int argc, char **argv) turbo_mode2(); if (ONCE) break; + if(n==0){ + printf("workcnt:%d\n",workcnt); + if(oj_udp&&oj_udp_ret==0){ + if(STOP) return 1; + wait_udp_msg(oj_udp_fd); + if(DEBUG) printf("udp job ... \n"); + }else{ sleep(sleep_time); + if(DEBUG) printf("sleeping ... %ds \n",sleep_time); + } + } j = 1; } return 0; diff --git a/judger/core/make.sh b/judger/core/make.sh index ac45dff3..77d58bb3 100755 --- a/judger/core/make.sh +++ b/judger/core/make.sh @@ -7,11 +7,12 @@ cd ../judge_client make chmod +x judge_client cp judge_client /usr/bin -cd ../sim/sim_2_77 +cd ../sim/sim_3_01 make fresh make exes chmod +x sim* cp sim_c.exe /usr/bin/sim_c +cp sim_c++.exe /usr/bin/sim_cc cp sim_java.exe /usr/bin/sim_java cp sim_pasc.exe /usr/bin/sim_pas cp sim_text.exe /usr/bin/sim_text @@ -19,5 +20,5 @@ cp sim_lisp.exe /usr/bin/sim_scm cd .. cp sim.sh /usr/bin chmod +x /usr/bin/sim.sh -rm /usr/bin/sim_cc /usr/bin/sim_rb /usr/bin/sim_sh -ln -s /usr/bin/sim_c /usr/bin/sim_cc +ln -fs /usr/bin/sim_c /usr/bin/sim_cc 2>&1 > /dev/null +echo "done!" diff --git a/judger/core/sim/sim_2_77/Answers b/judger/core/sim/sim_2_77/Answers deleted file mode 100755 index 407413fa..00000000 --- a/judger/core/sim/sim_2_77/Answers +++ /dev/null @@ -1,57 +0,0 @@ - The software and text similarity tester SIM - -SIM tests lexical similarity in texts in C, Java, Pascal, Modula-2, Lisp, -Miranda, and natural language. It is used - -- to detect potentially duplicated code fragments in large software projects, - in program text but also in shell scripts and documentation; -- to detect plagiarism in software projects, educational and otherwise. - -SIM is available through ftp. The directory - - ftp.cs.vu.nl:pub/dick/similarity_tester - -contains the sources (in C) and the MSDOS .EXEs. - -The software similarity tester is very efficient and allows us to compare -this year's students' work with that collected from many past years (much to -the dismay of some, mostly non-CS, students). Students are told in advance -that their work is going to be compared, but some are non-believers ... - -The output of the similarity tester can be processed by a number of shell -scripts by Matty Huntjens. These shell scripts take sim output and produce -lists of suspect submissions, histograms and the like. -The present version of these scripts is very much geared to the local situation -at the Vrije Universiteit, though; they are low on portability. -Matty Huntjens' email address is matty@cs.vu.nl. - -We are not afraid that students would try to tune their work to the -similarity tester. We reckon if they can do that they can also do the -exercise. - -Since this piece of handicraft does not qualify as research, there are no -international papers on it. A paper, titled `Detecting copied submissions in -computer science lab work', was published in a local (i.e. Dutch) computer -science journal: - -%A Dick Grune -%A Matty Huntjens -%T Het detecteren van kopie\(:en bij informatica-practica -%J Informatie (in Dutch) -%V 31 -%N 11 -%D Nov 1989 -%P 864-867 - -The ftp directory contains a terse technical report about the internal -working of the program. - - Dick Grune - Vrije Universiteit - de Boelelaan 1081 - 1081 HV Amsterdam - the Netherlands - dick@cs.vu.nl - +31 20 444 7744 ----------------------------------------------------------------- -With infinitely many exceptions, what you do makes no difference. diff --git a/judger/core/sim/sim_2_77/ForEachFile.c b/judger/core/sim/sim_2_77/ForEachFile.c deleted file mode 100755 index 7e35fad5..00000000 --- a/judger/core/sim/sim_2_77/ForEachFile.c +++ /dev/null @@ -1,259 +0,0 @@ -/* This file is part of the auxiliaries library. - Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: ForEachFile.c,v 1.17 2013-05-12 09:58:34 Gebruiker Exp $ -*/ - -#include -#include -#include -#include -#include - -#include "ForEachFile.h" - -/*Library module source prelude */ -#undef _FOREACHFILE_CODE_ -#ifndef lint -#define _FOREACHFILE_CODE_ -#endif -#ifdef LIB -#define _FOREACHFILE_CODE_ -#endif - -#ifdef _FOREACHFILE_CODE_ - -/* Library module source code */ - -struct ino_link { /* to detect loop in file system */ - struct ino_link *next; - long il_ino; - long il_device; -}; - -static void do_FEF( - Fchar *fn, - void (*proc)(const Fchar *, const char *, const struct stat *), - int dev, - struct ino_link *inop, - Fchar separator, - int max_depth -); - -static Fchar -get_separator(const Fchar *fn) { -#ifndef MSDOS - (void)(fn); /* use fn */ - return '/'; -#else - /* under MSDOS, conform to user's use, or use '\' */ - Fchar sep = 0; - - while (*fn) { - if (*fn == '/' || *fn == '\\') { - if (sep == 0) { - sep = *fn; - } - else - if (sep != *fn) return 0; /* bad mixed use */ - } - fn++; - } - return (sep ? sep : '\\'); -#endif -} - -static void -clean_name(Fchar *fn, Fchar sep) { - Fchar *f1 = fn; - Fchar *f2 = fn; - - /* remove multiple separators */ - while (*f1) { - if (*f1 == sep && *(f1+1) == sep) { - f1++; - } else { - *f2++ = *f1++; - } - } - *f2 = '\0'; - - /* remove a trailing separator */ - if (f2-1 > fn && *(f2-1) == sep) { - *(f2-1) = '\0'; - } -} - -static void -do_ForEachFile( - const Fchar *fn, - void (*proc)(const Fchar *, const char *, const struct stat *), - int max_depth -) { - Fchar fname[MAX_FILE_NAME_LENGTH]; - Fchar separator; - - Fnamecpy(fname, (!fn || !*fn) ? str2Fname(".") : fn); - separator = get_separator(fname); - if (!separator) { - (*proc)(fname, "both / and \\ used as separators", 0); - return; - } - - clean_name(fname, separator); - do_FEF(fname, proc, -1, (struct ino_link *)0, separator, max_depth); -} - -static int in_ino_list(const struct ino_link *inop, const struct stat *st); -static void link_ino_list( - struct ino_link *inop, - struct ino_link *ninop, - const struct stat *st -); - -void -ForEachFile( - const Fchar *fn, - void (*proc)(const Fchar *, const char *, const struct stat *) -) { - do_ForEachFile(fn, proc, -1); /* infinitely deep */ -} - -void -ForEachLocalFile( - const Fchar *fn, - void (*proc)(const Fchar *, const char *, const struct stat *) -) { - do_ForEachFile(fn, proc, 1); /* one level deep */ -} - -#ifdef S_IFLNK /* system with symbolic links */ -#define LSTAT lstat -#else /* S_IFLNK */ -#define LSTAT Stat -#endif /* S_IFLNK */ - -static void -do_FEF( - Fchar *fn, - void (*proc)(const Fchar *, const char *, const struct stat *), - int dev, - struct ino_link *inop, - Fchar separator, - int max_depth -) { - struct stat fs; - Dir_t *dir; - - if (proc == 0) return; /* just make sure */ - - if (LSTAT(fn, &fs) < 0) { - (*proc)(fn, strerror(errno), &fs); - return; - } - - /* report on file fn */ - (*proc)(fn, (char*)0, &fs); - - if (max_depth == 0) return; - if ((fs.st_mode & S_IFMT) != S_IFDIR) return; - -#ifdef S_IFLNK - /* don't follow links */ - if ((fs.st_mode & S_IFMT) == S_IFLNK) return; -#endif - - /* treat directory */ - if (dev < 0) { - /* no device known yet */ - dev = fs.st_dev; - } - if (fs.st_dev != dev) { - return; - } - - dir = Opendir(fn); - if (dir == 0) { - (*proc)(fn, "directory not readable", &fs); - } - else { - /* scan new directory */ - int fnl = Fnamelen(fn); - Dirent_t *dent; - struct ino_link ino; - - /* worry about loops in the file system */ - if (in_ino_list(inop, &fs)) { - (*proc)(fn, "loop in file system", &fs); - Closedir(dir); - return; - } - link_ino_list(inop, &ino, &fs); - - /* shape up the directory name */ - if (fn[fnl-1] != separator) { - /* append separator */ - fn[fnl++] = separator; - fn[fnl] = '\0'; - } - - /* descend */ - while ((dent = Readdir(dir)) != (Dirent_t *)0) { - if ( Fnamecmp(dent->d_name, str2Fname(".")) == 0 - || Fnamecmp(dent->d_name, str2Fname("..")) == 0 - ) continue; - - if (Fnamecmp(dent->d_name, str2Fname("")) == 0) { - (*proc)(fn, - "directory contains empty file name", - &fs - ); - continue; - } - - /* append name */ - Fnamecat(fn, dent->d_name); - do_FEF(fn, proc, dev, &ino, separator, max_depth-1); - /* remove name again*/ - fn[fnl] = '\0'; - } - Closedir(dir); - } -} - -static int -in_ino_list(const struct ino_link *inop, const struct stat *st) { - while (inop) { -#ifdef UNIX - if ( inop->il_ino == st->st_ino - && inop->il_device == st->st_dev - ) return 1; -#else -#ifdef lint - st = st; -#endif -#endif - inop = inop->next; - } - return 0; -} - -static void -link_ino_list( - struct ino_link *inop, struct ino_link *ninop, const struct stat *st -) { - ninop->next = inop; - ninop->il_ino = st->st_ino; - ninop->il_device = st->st_dev; -} - -/* End library module source code */ -#endif /* _FOREACHFILE_CODE_ */ - -#ifdef lint -static void -satisfy_lint(void *x) { - ForEachFile(0, 0); - ForEachLocalFile(0, 0); - satisfy_lint(x); -} -#endif /* lint */ diff --git a/judger/core/sim/sim_2_77/ForEachFile.h b/judger/core/sim/sim_2_77/ForEachFile.h deleted file mode 100755 index 197b1f91..00000000 --- a/judger/core/sim/sim_2_77/ForEachFile.h +++ /dev/null @@ -1,41 +0,0 @@ -/* This file is part of the auxiliaries library. - Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: ForEachFile.h,v 1.8 2013-05-12 09:58:34 Gebruiker Exp $ -*/ - -#ifndef _FOREACHFILE_H_ -#define _FOREACHFILE_H_ - -#include "fname.h" -#include -#include - -/**** -* ForEachFile(const Fchar *fn, void (*proc)(...): - each file reachable from fn is passed to the procedure proc, which is - declared as: - - void proc(const Fchar *fn, const char *msg, const struct stat *fs): - the file fn is reached; if msg != NULL, an error prevails the text of - which is *msg; otherwise fs points to the stat buffer for fn. - -* ForEachLocalFile() restricts itself to the directory fn and its local - contents. - -* MAX_FILE_NAME_LENGTH is the maximum length of the file name fn, including - directories. -****/ - -/* Public entries */ -#define MAX_FILE_NAME_LENGTH 1024 /* maximum file name length */ - -extern void ForEachFile( - const Fchar *fn, - void (*proc)(const Fchar *fn, const char *msg, const struct stat *fs) -); -extern void ForEachLocalFile( - const Fchar *fn, - void (*proc)(const Fchar *fn, const char *msg, const struct stat *fs) -); - -#endif /* _FOREACHFILE_H_ */ diff --git a/judger/core/sim/sim_2_77/Malloc.c b/judger/core/sim/sim_2_77/Malloc.c deleted file mode 100755 index 1495620e..00000000 --- a/judger/core/sim/sim_2_77/Malloc.c +++ /dev/null @@ -1,388 +0,0 @@ -/* This file is part of the memory management and leak detector MALLOC. - Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: Malloc.c,v 1.15 2014-01-27 11:22:39 Gebruiker Exp $ -*/ - -#include -#include -#include -#include - -#include "any_int.h" -#include "Malloc.h" - -/*Library module source prelude */ -#undef _MALLOC_CODE_ -#ifndef lint -#define _MALLOC_CODE_ -#endif -#ifdef LIB -#define _MALLOC_CODE_ -#endif - -#ifdef _MALLOC_CODE_ - -/* Library module source code */ - -#undef new -#define new use_my_new /* don't call Malloc in Malloc.c */ -#define my_new(type) ((type *)malloc(sizeof (type))) - -/* All output goes through designated files, so we block printf, etc. */ -#undef printf -#define printf use_fprintf -#undef putchar -#define putchar use_fprintf - -static void -fprintloc(FILE *f, const char *fname, int l_nmb) { - fprintf(f, "\"%s\", line %d: ", fname, l_nmb); -} - -static void -out_of_memory(const char *fname, int l_nmb, size_t size) { - fprintloc(stderr, fname, l_nmb); - fprintf(stderr, "Out of memory, requested size = %s bytes\n", - any_uint2string(size, 0)); - exit(1); -} - -#if defined MEMLEAK || defined MEMCLOBBER -/* Both need almost the same information: MEMLEAK obviously needs a list of - all blocks still allocated, but MEMCLOBBER needs the same list to find - the size of a block given to Free(), in order to clobber it. - MEMCLOBBER does not need total, balance and max, but finecombing them out - would be too much. -*/ - -static vlong_uint total = 0; -static vlong_uint balance = 0; -static vlong_uint max = 0; - -struct record { - struct record *next; - const char *addr; - size_t size; - const char *fname; - int l_nmb; -}; - -#define HASH_SIZE 16381 /* largest prime under 2^16 */ -static struct record *record_hash[HASH_SIZE]; -#define chain_start(x) record_hash[((unsigned int)(x)%HASH_SIZE)] - -static void -record_alloc(char *addr, size_t size, const char *fname, int l_nmb) { - struct record *new; - struct record **r_hook = &chain_start(addr); - - if (addr == 0) return; - - new = my_new(struct record); - new->addr = addr; - new->size = size; - new->fname = fname; /* no need to copy fname */ - new->l_nmb = l_nmb; - new->next = *r_hook; - *r_hook = new; - - total += size; - balance += size; - if (balance > max) { - max = balance; - } -} - - -static struct record ** -record_pointer_for_address(const char *addr) { - struct record **rp = &chain_start(addr); - - while (*rp) { - if ((*rp)->addr == addr) break; - rp = &(*rp)->next; - } - - return rp; -} - -static size_t -record_free(char *addr) { - struct record **oldp = record_pointer_for_address(addr); - struct record *old = *oldp; - - if (old == 0) return (size_t) -1; - - *oldp = old->next;/* this loses the struct record; is that a problem? */ - balance -= old->size; - - return old->size; -} - -#endif /* defined MEMLEAK || defined MEMCLOBBER */ - -void -MemClobber(void *p, size_t size) { - unsigned char *s = (unsigned char *)p; - size_t i; - - for (i = 0; i < size; i++) { - s[i] = 0125; /* 0101 0101 */ - } -} - -#ifdef MEMLEAK - -struct entry { - struct entry *next; - const char *fname; - int l_nmb; - unsigned int n_blocks; - int var_size; /* all blocks have the same size or not */ - size_t size; /* !var_size: the one size; var_size: sum of sizes */ -}; - -static struct entry * -compacted_leaks(void) { - struct entry *res = 0; - int i; - - for (i = 0; i < HASH_SIZE; i++) { - struct record *r = record_hash[i]; - - while (r) { - struct entry *e = res; - - /* try to find an entry for this location */ - while (e) { - if ( e->fname == r->fname - && e->l_nmb == r->l_nmb - ) break; - e = e->next; - } - - if (e) { /* update the entry */ - if (e->var_size) { - e->size += r->size; - } - else if (e->size != r->size) { - /* switch to var_size */ - e->var_size = 1; - e->size = - e->n_blocks*e->size + r->size; - } - e->n_blocks++; - } - else { /* create a new entry */ - e = my_new(struct entry); - e->fname = r->fname; - e->l_nmb = r->l_nmb; - e->n_blocks = 1; - e->var_size = 0; - e->size = r->size; - - e->next = res; - res = e; - } - - r = r->next; - } - } - - return res; -} - -static int -number_of_leaks(const struct entry *e) { - int res = 0; - - while (e != 0) { - res++; - e = e->next; - } - - return res; -} - -static void -report_actual_leaks(FILE *f) { - const struct entry *e = compacted_leaks(); - int n_leaks = number_of_leaks(e); - - if (n_leaks == 0) return; - - fprintf(f, "There %s %d case%s of unreclaimed memory:\n", - (n_leaks == 1 ? "was" : "were"), - n_leaks, - (n_leaks == 1 ? "" : "s") - ); - - while (e) { - fprintloc(f, e->fname, e->l_nmb); - fprintf(f, "left allocated: %d block%s of size ", - e->n_blocks, (e->n_blocks == 1 ? "" : "s") - ); - if (e->var_size) { - /* e->size is the sum of the sizes */ - fprintf(f, "%s on average", - any_uint2string( - (e->size+e->n_blocks/2) / e->n_blocks, - 0 - )); - if (e->n_blocks > 1) { - fprintf(f, " = %s", - any_uint2string(e->size, 0)); - } - } - else { - /* e->size is the single size */ - fprintf(f, "%s", any_uint2string(e->size, 0)); - if (e->n_blocks > 1) { - vlong_uint all = e->size*e->n_blocks; - fprintf(f, " = %s", any_uint2string(all, 0)); - } - } - fprintf(f, "\n"); - - e = e->next; - } -} - -void -ReportMemoryLeaks(FILE *f) { - if (f == 0) f = stderr; - report_actual_leaks(f); - - fprintf(f, "Total memory allocated = %s", any_uint2string(total, 0)); - fprintf(f, ", maximum allocated = %s", any_uint2string(max, 0)); - fprintf(f, ", garbage left = %s", any_uint2string(balance, 0)); - fprintf(f, "\n"); -} - -#else /* no MEMLEAK */ - -/*ARGSUSED*/ -void -ReportMemoryLeaks(FILE *f) { -} - -#endif /* MEMLEAK */ - -void * -_leak_malloc(int chk, size_t size, const char *fname, int l_nmb) { - void *res = malloc(size); - - if (chk && res == 0) { - out_of_memory(fname, l_nmb, size); - /*NOTREACHED*/ - } - -#if defined MEMLEAK || defined MEMCLOBBER - record_alloc(res, size, fname, l_nmb); - -#ifdef MEMCLOBBER - MemClobber((char *)res, size); -#endif /* MEMCLOBBER */ -#endif /* MEMLEAK || MEMCLOBBER */ - - return res; -} - -void * -_leak_calloc(int chk, size_t n, size_t size, const char *fname, int l_nmb) { - void *res = calloc(n, size); - - if (chk && res == 0) { - out_of_memory(fname, l_nmb, n*size); - /*NOTREACHED*/ - } - -#if defined MEMLEAK || defined MEMCLOBBER - record_alloc(res, n*size, fname, l_nmb); -#endif /* MEMLEAK || MEMCLOBBER */ - - return res; -} - -void * -_leak_realloc(int chk, void *addr, size_t size, const char *fname, int l_nmb) { - void *res; -#if defined MEMLEAK || defined MEMCLOBBER - size_t old_size = record_free(addr); - - /* we report first, because the realloc() below may cause a crash */ - if ( /* we are not reallocating address 0, which is allowed */ - addr != 0 - && /* the address was never handed out before */ - old_size == (size_t) -1 - ) { - fprintloc(stderr, fname, l_nmb); - fprintf(stderr, ">>>> unallocated block reallocated <<<<\n"); - } -#endif - - res = realloc(addr, size); - if (chk && res == 0) { - out_of_memory(fname, l_nmb, size); - /*NOTREACHED*/ - } - -#if defined MEMLEAK || defined MEMCLOBBER - record_alloc(res, size, fname, l_nmb); -#endif /* MEMLEAK || MEMCLOBBER */ - -#ifdef MEMCLOBBER - if (old_size > 0 && size > old_size) { - MemClobber(((char *)res)+old_size, size-old_size); - } -#endif /* MEMCLOBBER */ - - return res; -} - -/* ARGSUSED */ -void -_leak_free(void *addr, const char *fname, int l_nmb) { -#if defined MEMLEAK || defined MEMCLOBBER - size_t old_size = record_free(addr); - - /* we report first, because the free() below may cause a crash */ - if (old_size == (size_t) -1) { - fprintloc(stderr, fname, l_nmb); - fprintf(stderr, ">>>> unallocated block freed "); - fprintf(stderr, "or multiple free of allocated block <<<<\n"); - } - else { -#ifdef MEMCLOBBER - MemClobber((char *)addr, old_size); -#endif /* MEMCLOBBER */ - } -#endif /* MEMLEAK || MEMCLOBBER */ - free(addr); -} - -char * -_new_string(const char *s, const char *fname, int l_nmb) { - return strcpy((char *)(_leak_malloc(1, strlen(s)+1, fname, l_nmb)), s); -} - -/* End library module source code */ -#endif /* _MALLOC_CODE_ */ - -#ifdef lint -static void -satisfy_lint(void *x) { - void *v; - - v = _leak_malloc(0, 0, 0, 0); - v = _leak_calloc(0, 0, 0, 0, 0); - v = _leak_realloc(0, 0, 0, 0, 0); - _leak_free(x, 0, 0); - - ReportMemoryLeaks(0); - MemClobber(v, 0); - - v = _new_string(0, 0, 0); - satisfy_lint(v); -} -#endif /* lint */ diff --git a/judger/core/sim/sim_2_77/Malloc.h b/judger/core/sim/sim_2_77/Malloc.h deleted file mode 100755 index dd717630..00000000 --- a/judger/core/sim/sim_2_77/Malloc.h +++ /dev/null @@ -1,103 +0,0 @@ -/* This file is part of the memory management and leak detector MALLOC. - Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: Malloc.h,v 1.8 2013-05-12 09:58:34 Gebruiker Exp $ -*/ - -#ifndef _MALLOC_H_ -#define _MALLOC_H_ - -#include - -/***** -The files Malloc.[ch] provide several functionalities: - -- checking for "out of memory": to simplify programming -- allocating memory using new(type) " " " " -- detecting memory leaks: to obtain cleaner programs -- clobbering freshly allocated memory: to obtain safer programs - -The module defines several sets of routines: - -1. void *Malloc(size_t s) - void *Calloc(size_t n, size_t s) - void *Realloc(void *p, size_t s) - void Free(void *p) - -2. void *TryMalloc(size_t s) - void *TryCalloc(size_t n, size_t s) - void *TryRealloc(void *p, size_t s) - -3. T *new(T) - char *new_string(const char *s) - -4. void ReportMemoryLeaks(FILE *f) - void MemClobber(void *p, size_t size) - -* The members of the first set act like their Unix counterparts, except that - they never return NULL; upon out-of-memory an error message is given on - standard error, showing the file name and the line number of the call. Since - in almost all cases there is nothing more intelligent to do, this is almost - always adequate, and makes for simpler and safer programming. - - In those rare cases that the program *can* continue when out of memory, the - routines in the second set can be used; they act exactly like their Unix - counterparts. - - Note that automatic out-of-memory detection is active, regardless of the - -DMEM... flags described below. - -* A call of new(T), with T any type, yields a pointer of type T* to a block - of type T, allocated using Malloc(). - A call of new_string(s), with s a string, yields a pointer to a copy of s, - allocated using Malloc(); it is equivalent to strdup() except that it uses - Malloc(). - -* Normally, a call of ReportMemoryLeaks() does nothing, but when Malloc.c is - compiled with -DMEMLEAK, it produces a compacted list of allocated but not - yet freed blocks on the stream f, with information about where they were - allocated. - This is useful to get insight into memory use and abuse. - -* When Malloc.c is compiled with -DMEMCLOBBER, it clobbers all newly allocated - memory from Malloc() and Realloc() just after allocation, and all freed - memory just before freeing it. An area is clobbered by overwriting it with - a wacky bit pattern. This is done in the hope that improper use of memory - will cause some evident error somewhere. - - The routine that performs the clobbering, MemClobber(void *p, size_t size), - is available regardless of the -DMEMCLOBBER compilation option. It can be - used to create comparison patterns. - -* Compiled with any of the -DMEM... flags, Malloc will also produce run-time - error messages for multiple Free()s of the same block, and Realloc()s on - not-allocated blocks. It then allows the program to continue. - -* The system consumes hardly any time and is fast enough to be kept active all - the time. -*****/ - -/* Private entries */ -extern void *_leak_malloc(int chk, size_t size, const char *fname, int l_nmb); -extern void *_leak_calloc(int chk, size_t n, size_t size, const char *fname, int l_nmb); -extern void *_leak_realloc(int chk, void *addr, size_t size, const char *fname, int l_nmb); -extern void _leak_free(void *addr, const char *fname, int l_nmb); - -extern char *_new_string(const char *s, const char *fname, int l_nmb); - -/* Public entries */ -#define Malloc(s) (_leak_malloc(1, (s), __FILE__, __LINE__)) -#define Calloc(n,s) (_leak_calloc(1, (n), (s), __FILE__, __LINE__)) -#define Realloc(p,s) (_leak_realloc(1, (void *)(p), (s), __FILE__, __LINE__)) -#define Free(p) (_leak_free((void *)(p), __FILE__, __LINE__)) - -#define TryMalloc(s) (_leak_malloc(0, (s), __FILE__, __LINE__)) -#define TryCalloc(n,s) (_leak_calloc(0, (n), (s), __FILE__, __LINE__)) -#define TryRealloc(p,s) (_leak_realloc(0, (void *)(p), (s), __FILE__, __LINE__)) - -#define new(type) ((type *)Malloc(sizeof (type))) -#define new_string(s) (_new_string((s), __FILE__, __LINE__)) - -extern void ReportMemoryLeaks(FILE *f); -extern void MemClobber(void *p, size_t size); - -#endif /* _MALLOC_H_ */ diff --git a/judger/core/sim/sim_2_77/ToDo b/judger/core/sim/sim_2_77/ToDo deleted file mode 100755 index 9345f22a..00000000 --- a/judger/core/sim/sim_2_77/ToDo +++ /dev/null @@ -1,49 +0,0 @@ -- in hash.c, some size_t -> uint64_t? for a 64-bit hash code? - -- min_run_string, thresh.. = clean up sim.[ch] - -- get rid of the nl_buff mechanism (2012!) - -- report runs as '... matching text only ...' (proper name for Retrieve_Runs()) - -? plug memory leaks (and still report memory usage with -M!) - -- unify idf2token() in *lang.l - -- db_ not protected by #ifdef but by compilation to void ???? - -Done ================================================================ - -+ register - removed - -+ Run hashing OK: average chain length = 1.5, for sim-ing the sources of MCD2 -+ Idf hashing OK: smooth distribution when sim-ing the sources of MCD2 - -+ use two-byte tokens to obtain better resolution for sim_text and on -F option - and UTF-8 (Johnson, Benjamin (US - Chicago)) - -+ different defaults per program - -+ cleaning up sim.c & names - -+ Microsoft comment (// ... unescaped \n) - -+ emails 2009-2011 (A = I answered, R= they replied) -+AR Marcus Brinkmann, separate letters -+AR Scott Kuhl, percentages -+AR Yaroslav Halchenko, identifying non-existent lines -+A Rumen Stefanov, UTF-8 -+A Jonathan Martin, UTF-8 -+AR UTF-8 (Johnson, Benjamin (US - Chicago)) - -+ better structure between X.h and X.c - -+ clean-up language.h and its sub-class algollike.h - -+ warning in README to correct for non-MSDOS - -Rejected ================================================================ - -X remove Miranda -X Mon Apr 11 13:23:41 1994: sim_orca -X Thu May 13 23:02:46 1993: sim ook voor C++ en Ada diff --git a/judger/core/sim/sim_2_77/VERSION b/judger/core/sim/sim_2_77/VERSION deleted file mode 100755 index ace7c390..00000000 --- a/judger/core/sim/sim_2_77/VERSION +++ /dev/null @@ -1 +0,0 @@ -2.77 diff --git a/judger/core/sim/sim_2_77/add_run.c b/judger/core/sim/sim_2_77/add_run.c deleted file mode 100755 index b9e84c58..00000000 --- a/judger/core/sim/sim_2_77/add_run.c +++ /dev/null @@ -1,76 +0,0 @@ -/* This file is part of the software similarity tester SIM. - Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: add_run.c,v 2.13 2013-04-28 16:30:39 Gebruiker Exp $ -*/ - -#include "sim.h" -#include "debug.par" -#include "text.h" -#include "runs.h" -#include "percentages.h" -#include "Malloc.h" -#include "options.h" -#include "error.h" -#include "add_run.h" - -static void set_chunk( - struct chunk *, - struct text *, - size_t, - size_t -); - -static void set_pos( - struct position *, - int, - struct text *, - size_t -); - -void -add_run(struct text *txt0, size_t i0, - struct text *txt1, size_t i1, - size_t size -) { - /* Adds the run of given size to our collection. - */ - struct run *r = new(struct run); - - set_chunk(&r->rn_chunk0, txt0, i0 - txt0->tx_start, size); - set_chunk(&r->rn_chunk1, txt1, i1 - txt1->tx_start, size); - r->rn_size = size; - -#ifdef DB_RUN - db_run_info("Added", r, 0); -#endif /* DB_RUN */ - - if (is_set_option('p')) { - add_to_percentages(r); - } - else { - add_to_runs(r); - } -} - -static void -set_chunk(struct chunk *cnk, struct text *txt, - size_t start, size_t size -) { - /* Fill the chunk *cnk with info about the piece of text - in txt starting at start extending over size tokens. - */ - cnk->ch_text = txt; - set_pos(&cnk->ch_first, 0, txt, start); - set_pos(&cnk->ch_last, 1, txt, start + size - 1); -} - -static void -set_pos(struct position *pos, int type, struct text *txt, size_t start) { - /* Fill a single struct position */ - pos->ps_next = txt->tx_pos; - txt->tx_pos = pos; - - pos->ps_type = type; - pos->ps_tk_cnt = start; - pos->ps_nl_cnt = (size_t) -1; /* uninitialized */ -} diff --git a/judger/core/sim/sim_2_77/aiso.bdy b/judger/core/sim/sim_2_77/aiso.bdy deleted file mode 100755 index 90ebec1b..00000000 --- a/judger/core/sim/sim_2_77/aiso.bdy +++ /dev/null @@ -1,190 +0,0 @@ -/* This file is part of the module Arbitrary-In Sorted-Out (AISO). - Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: aiso.bdy,v 1.4 2012-05-08 08:43:56 Gebruiker Exp $ -*/ - -/* -Description: - This is the body of a module that builds an arbitrary-in - sorted-out data structure, to be used as a heap, a priority queue, - etc. - See aiso.spc for further information. -*/ - -#include -#include - -#include "Malloc.h" - -static struct aiso_node *root; /* root of tree */ -#ifdef AISO_ITER -static struct aiso_node *list; /* start of linked list */ -#endif /* AISO_ITER */ - -/* the policy */ -static uint64_t aiso_size = 0; -static uint64_t acc_mark = 1; - -#define add_entry() (aiso_size++) -#define rem_entry() (aiso_size--) -#define reset_access() (acc_mark = 1) -#define count_access() (acc_mark <<= 1) -#define must_rotate() (acc_mark > aiso_size) - -int -InsertAiso(AISO_TYPE v) { - struct aiso_node *new_node; - struct aiso_node **hook = &root; -#ifdef AISO_ITER - struct aiso_node **prev = &list; -#endif /* AISO_ITER */ - - new_node = (struct aiso_node *)TryMalloc(sizeof (struct aiso_node)); - if (!new_node) { - /* avoid modifying the tree */ - return 0; - } - - while (*hook) { - struct aiso_node *an = *hook; - - count_access(); - if (AISO_BEFORE(v, an->an_value)) { - /* head left */ - if (!an->an_left || !must_rotate()) { - /* standard action */ - hook = &an->an_left; - } - else { - /* change (l A r) B (C) into (l) A (r B C) */ - struct aiso_node *anl = an->an_left; - - an->an_left = anl->an_right; - anl->an_right = an; - *hook = anl; - reset_access(); - } - } - else { - /* head right */ - if (!an->an_right || !must_rotate()) { - /* standard action */ - hook = &an->an_right; - } - else { - /* change (A) B (l C r) into (A B l) C (r) */ - struct aiso_node *anr = an->an_right; - - an->an_right = anr->an_left; - anr->an_left = an; - *hook = anr; - reset_access(); - } -#ifdef AISO_ITER - prev = &an->an_next; -#endif /* AISO_ITER */ - } - } - - new_node->an_left = 0; - new_node->an_right = 0; -#ifdef AISO_ITER - new_node->an_next = *prev; - *prev = new_node; -#endif /* AISO_ITER */ - new_node->an_value = v; - *hook = new_node; - add_entry(); - return 1; -} - -#ifdef AISO_EXTR - -int -ExtractAiso(AISO_TYPE *vp) { - struct aiso_node **hook = &root; - struct aiso_node *an; - - if (!root) return 0; - - while ((an = *hook), an->an_left) { - /* head left */ - count_access(); - if (!must_rotate()) { - /* standard action */ - hook = &an->an_left; - } - else { - /* change (l A r) B (C) into (l) A (r B C) */ - struct aiso_node *anl = an->an_left; - - an->an_left = anl->an_right; - anl->an_right = an; - *hook = anl; - reset_access(); - } - } - /* found the first */ - *vp = an->an_value; - *hook = an->an_right; -#ifdef AISO_ITER - list = an->an_next; -#endif /* AISO_ITER */ - Free((void *)an); - rem_entry(); - return 1; -} - -#endif /* AISO_EXTR */ - -#ifdef AISO_ITER - -void -OpenIter(AisoIter *ip) { - *ip = list; -} - -int -GetAisoItem(AisoIter *ip, AISO_TYPE *vp) { - struct aiso_node *an = *ip; - - if (!an) return 0; - - *vp = an->an_value; - *ip = an->an_next; - return 1; -} - -void -CloseIter(AisoIter *ip) { - *ip = 0; -} - -#endif /* AISO_ITER */ - -#ifdef AISO_DEBUG /* requires AISO_FORMAT */ - -static void -pr_inf(int level, char ch, struct aiso_node *an) { - int i; - - if (!an) return; - - pr_inf(level+1, '/', an->an_right); - for (i = 0; i < level; i++) { - printf(" "); - } - printf("%c", ch); - printf(AISO_FORMAT, an->an_value); - printf("\n"); - pr_inf(level+1, '\\', an->an_left); -} - -void -pr_tree(void) { - pr_inf(0, '-', root); - printf("================\n"); -} - -#endif /* AISO_DEBUG */ - diff --git a/judger/core/sim/sim_2_77/aiso.spc b/judger/core/sim/sim_2_77/aiso.spc deleted file mode 100755 index ac4acec6..00000000 --- a/judger/core/sim/sim_2_77/aiso.spc +++ /dev/null @@ -1,99 +0,0 @@ -/* This file is part of the module Arbitrary-In Sorted-Out (AISO). - Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: aiso.spc,v 1.2 2008/02/05 16:48:42 dick Exp $ -*/ - -/* -Description: - This is the specification of a module that builds an arbitrary-in - sorted-out data structure, to be used as a heap, a priority queue, - etc. - Elements can be inserted, the first element extracted and the set - scanned at any moment. - The module is not generic, in that only one copy of it can be - instantiated per program. - -Instantiation: - The module is instantiated as follows. - Create a file X.h, where X is arbitrary, which contains at least: - - - a definition of AISO_TYPE, the type of the object to be stored - - a possible definition of AISO_EXTR; see below - - a possible definition of AISO_ITER; see below - - #include "aiso.spc" - - This file X.h is to be included in all files that use the aiso - package. - - Create a file X.c which contains at least: - - - #include "X.h" - - a definition of a routine - int AISO_BEFORE(AISO_TYPE v, AISO_TYPE w) - which yields non-zero if v is to be sorted before w - - #include "aiso.bdy" - - This file X.c compiles into the module object. - -Specification: - The module always supplies: - int InsertAiso(AISO_TYPE value) - inserts value in its proper place; fails if out of memory - - If AISO_EXTR is defined, the module will also supply: - int ExtractAiso(AISO_TYPE *value) - yields the first value in the aiso and removes it; - fails if empty - - If AISO_ITER is defined, the module also supplies a type AisoIter - which declares an iterator, i.e., a structure that records a position - in the ordered set, plus routines for manipulating the iterator, thus - enabling the user to scan the ordered set. The iterator should be - declared as: - AisoIter iter; - and is manipulated by the following commands: - - OpenIter(AisoIter *iter) - opens the iterator for scanning the existing set in order - - int GetAisoItem(AisoIter *iter, AISO_TYPE *value) - yields the next value in the iterator; fails if exhausted - - CloseIter(AisoIter *iter) - closes the iterator - - For the use of AISO_DEBUG see aiso.bdy. - -Implementation: - The AISO implementation is based on a self-adjusting binary tree. - Degenerate behaviour of the tree is avoided by shaking the tree - every 'ln aiso_size' node accesses. This guarantees ln aiso_size - behaviour in the long run, though it is possible for a single - operation to take aiso_size node accesses. - - The iterator is implemented as an additional linear linked list - through the tree. This is simpler than and at least as efficient as - clever tree-wiring. -*/ - -struct aiso_node { - struct aiso_node *an_left; - struct aiso_node *an_right; -#ifdef AISO_ITER - struct aiso_node *an_next; -#endif /* AISO_ITER */ - AISO_TYPE an_value; -}; - -extern int InsertAiso(AISO_TYPE value); -#ifdef AISO_EXTR -extern int ExtractAiso(AISO_TYPE *value); -#endif /* AISO_EXTR */ - -#ifdef AISO_ITER -typedef struct aiso_node *AisoIter; -extern void OpenIter(AisoIter *iter); -extern int GetAisoItem(AisoIter *iter, AISO_TYPE *value); -extern void CloseIter(AisoIter *iter); -#endif /* AISO_ITER */ - diff --git a/judger/core/sim/sim_2_77/clang.c b/judger/core/sim/sim_2_77/clang.c deleted file mode 100644 index 947d4397..00000000 --- a/judger/core/sim/sim_2_77/clang.c +++ /dev/null @@ -1,2200 +0,0 @@ - -#line 3 "" - -#define YY_INT_ALIGNED short int - -/* A lexical scanner generated by flex */ - -#define FLEX_SCANNER -#define YY_FLEX_MAJOR_VERSION 2 -#define YY_FLEX_MINOR_VERSION 6 -#define YY_FLEX_SUBMINOR_VERSION 0 -#if YY_FLEX_SUBMINOR_VERSION > 0 -#define FLEX_BETA -#endif - -/* First, we deal with platform-specific or compiler-specific issues. */ - -/* begin standard C headers. */ -#include -#include -#include -#include - -/* end standard C headers. */ - -/* flex integer type definitions */ - -#ifndef FLEXINT_H -#define FLEXINT_H - -/* C99 systems have . Non-C99 systems may or may not. */ - -#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L - -/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, - * if you want the limit (max/min) macros for int types. - */ -#ifndef __STDC_LIMIT_MACROS -#define __STDC_LIMIT_MACROS 1 -#endif - -#include -typedef int8_t flex_int8_t; -typedef uint8_t flex_uint8_t; -typedef int16_t flex_int16_t; -typedef uint16_t flex_uint16_t; -typedef int32_t flex_int32_t; -typedef uint32_t flex_uint32_t; -#else -typedef signed char flex_int8_t; -typedef short int flex_int16_t; -typedef int flex_int32_t; -typedef unsigned char flex_uint8_t; -typedef unsigned short int flex_uint16_t; -typedef unsigned int flex_uint32_t; - -/* Limits of integral types. */ -#ifndef INT8_MIN -#define INT8_MIN (-128) -#endif -#ifndef INT16_MIN -#define INT16_MIN (-32767-1) -#endif -#ifndef INT32_MIN -#define INT32_MIN (-2147483647-1) -#endif -#ifndef INT8_MAX -#define INT8_MAX (127) -#endif -#ifndef INT16_MAX -#define INT16_MAX (32767) -#endif -#ifndef INT32_MAX -#define INT32_MAX (2147483647) -#endif -#ifndef UINT8_MAX -#define UINT8_MAX (255U) -#endif -#ifndef UINT16_MAX -#define UINT16_MAX (65535U) -#endif -#ifndef UINT32_MAX -#define UINT32_MAX (4294967295U) -#endif - -#endif /* ! C99 */ - -#endif /* ! FLEXINT_H */ - -#ifdef __cplusplus - -/* The "const" storage-class-modifier is valid. */ -#define YY_USE_CONST - -#else /* ! __cplusplus */ - -/* C99 requires __STDC__ to be defined as 1. */ -#if defined (__STDC__) - -#define YY_USE_CONST - -#endif /* defined (__STDC__) */ -#endif /* ! __cplusplus */ - -#ifdef YY_USE_CONST -#define yyconst const -#else -#define yyconst -#endif - -/* Returned upon end-of-file. */ -#define YY_NULL 0 - -/* Promotes a possibly negative, possibly signed char to an unsigned - * integer for use as an array index. If the signed char is negative, - * we want to instead treat it as an 8-bit unsigned char, hence the - * double cast. - */ -#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) - -/* Enter a start condition. This macro really ought to take a parameter, - * but we do it the disgusting crufty way forced on us by the ()-less - * definition of BEGIN. - */ -#define BEGIN (yy_start) = 1 + 2 * - -/* Translate the current start state into a value that can be later handed - * to BEGIN to return to the state. The YYSTATE alias is for lex - * compatibility. - */ -#define YY_START (((yy_start) - 1) / 2) -#define YYSTATE YY_START - -/* Action number for EOF rule of a given start state. */ -#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) - -/* Special action meaning "start processing a new file". */ -#define YY_NEW_FILE yyrestart(yyin ) - -#define YY_END_OF_BUFFER_CHAR 0 - -/* Size of default input buffer. */ -#ifndef YY_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k. - * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. - * Ditto for the __ia64__ case accordingly. - */ -#define YY_BUF_SIZE 32768 -#else -#define YY_BUF_SIZE 16384 -#endif /* __ia64__ */ -#endif - -/* The state buf must be large enough to hold one state per character in the main buffer. - */ -#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) - -#ifndef YY_TYPEDEF_YY_BUFFER_STATE -#define YY_TYPEDEF_YY_BUFFER_STATE -typedef struct yy_buffer_state *YY_BUFFER_STATE; -#endif - -#ifndef YY_TYPEDEF_YY_SIZE_T -#define YY_TYPEDEF_YY_SIZE_T -typedef size_t yy_size_t; -#endif - -extern yy_size_t yyleng; - -extern FILE *yyin, *yyout; - -#define EOB_ACT_CONTINUE_SCAN 0 -#define EOB_ACT_END_OF_FILE 1 -#define EOB_ACT_LAST_MATCH 2 - - #define YY_LESS_LINENO(n) - #define YY_LINENO_REWIND_TO(ptr) - -/* Return all but the first "n" matched characters back to the input stream. */ -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - *yy_cp = (yy_hold_char); \ - YY_RESTORE_YY_MORE_OFFSET \ - (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ - YY_DO_BEFORE_ACTION; /* set up yytext again */ \ - } \ - while ( 0 ) - -#define unput(c) yyunput( c, (yytext_ptr) ) - -#ifndef YY_STRUCT_YY_BUFFER_STATE -#define YY_STRUCT_YY_BUFFER_STATE -struct yy_buffer_state - { - FILE *yy_input_file; - - char *yy_ch_buf; /* input buffer */ - char *yy_buf_pos; /* current position in input buffer */ - - /* Size of input buffer in bytes, not including room for EOB - * characters. - */ - yy_size_t yy_buf_size; - - /* Number of characters read into yy_ch_buf, not including EOB - * characters. - */ - int yy_n_chars; - - /* Whether we "own" the buffer - i.e., we know we created it, - * and can realloc() it to grow it, and should free() it to - * delete it. - */ - int yy_is_our_buffer; - - /* Whether this is an "interactive" input source; if so, and - * if we're using stdio for input, then we want to use getc() - * instead of fread(), to make sure we stop fetching input after - * each newline. - */ - int yy_is_interactive; - - /* Whether we're considered to be at the beginning of a line. - * If so, '^' rules will be active on the next match, otherwise - * not. - */ - int yy_at_bol; - - int yy_bs_lineno; /**< The line count. */ - int yy_bs_column; /**< The column count. */ - - /* Whether to try to fill the input buffer when we reach the - * end of it. - */ - int yy_fill_buffer; - - int yy_buffer_status; - -#define YY_BUFFER_NEW 0 -#define YY_BUFFER_NORMAL 1 - /* When an EOF's been seen but there's still some text to process - * then we mark the buffer as YY_EOF_PENDING, to indicate that we - * shouldn't try reading from the input source any more. We might - * still have a bunch of tokens to match, though, because of - * possible backing-up. - * - * When we actually see the EOF, we change the status to "new" - * (via yyrestart()), so that the user can continue scanning by - * just pointing yyin at a new input file. - */ -#define YY_BUFFER_EOF_PENDING 2 - - }; -#endif /* !YY_STRUCT_YY_BUFFER_STATE */ - -/* Stack of input buffers. */ -static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ -static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ -static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ - -/* We provide macros for accessing buffer states in case in the - * future we want to put the buffer states in a more general - * "scanner state". - * - * Returns the top of the stack, or NULL. - */ -#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ - ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ - : NULL) - -/* Same as previous macro, but useful when we know that the buffer stack is not - * NULL or when we need an lvalue. For internal use only. - */ -#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] - -/* yy_hold_char holds the character lost when yytext is formed. */ -static char yy_hold_char; -static int yy_n_chars; /* number of characters read into yy_ch_buf */ -yy_size_t yyleng; - -/* Points to current character in buffer. */ -static char *yy_c_buf_p = (char *) 0; -static int yy_init = 0; /* whether we need to initialize */ -static int yy_start = 0; /* start state number */ - -/* Flag which is used to allow yywrap()'s to do buffer switches - * instead of setting up a fresh yyin. A bit of a hack ... - */ -static int yy_did_buffer_switch_on_eof; - -void yyrestart (FILE *input_file ); -void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ); -YY_BUFFER_STATE yy_create_buffer (FILE *file,int size ); -void yy_delete_buffer (YY_BUFFER_STATE b ); -void yy_flush_buffer (YY_BUFFER_STATE b ); -void yypush_buffer_state (YY_BUFFER_STATE new_buffer ); -void yypop_buffer_state (void ); - -static void yyensure_buffer_stack (void ); -static void yy_load_buffer_state (void ); -static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file ); - -#define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER ) - -YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ); -YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ); -YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,yy_size_t len ); - -void *yyalloc (yy_size_t ); -void *yyrealloc (void *,yy_size_t ); -void yyfree (void * ); - -#define yy_new_buffer yy_create_buffer - -#define yy_set_interactive(is_interactive) \ - { \ - if ( ! YY_CURRENT_BUFFER ){ \ - yyensure_buffer_stack (); \ - YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer(yyin,YY_BUF_SIZE ); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ - } - -#define yy_set_bol(at_bol) \ - { \ - if ( ! YY_CURRENT_BUFFER ){\ - yyensure_buffer_stack (); \ - YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer(yyin,YY_BUF_SIZE ); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ - } - -#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) - -/* Begin user sect3 */ - -#define yywrap() (/*CONSTCOND*/1) -#define YY_SKIP_YYWRAP - -typedef unsigned char YY_CHAR; - -FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0; - -typedef int yy_state_type; - -extern int yylineno; - -int yylineno = 1; - -extern char *yytext; -#ifdef yytext_ptr -#undef yytext_ptr -#endif -#define yytext_ptr yytext - -static yy_state_type yy_get_previous_state (void ); -static yy_state_type yy_try_NUL_trans (yy_state_type current_state ); -static int yy_get_next_buffer (void ); -#if defined(__GNUC__) && __GNUC__ >= 3 -__attribute__((__noreturn__)) -#endif -static void yy_fatal_error (yyconst char msg[] ); - -/* Done after the current pattern has been matched and before the - * corresponding action - sets up yytext. - */ -#define YY_DO_BEFORE_ACTION \ - (yytext_ptr) = yy_bp; \ - yyleng = (size_t) (yy_cp - yy_bp); \ - (yy_hold_char) = *yy_cp; \ - *yy_cp = '\0'; \ - (yy_c_buf_p) = yy_cp; - -#define YY_NUM_RULES 19 -#define YY_END_OF_BUFFER 20 -/* This struct is not used in this scanner, - but its presence is necessary. */ -struct yy_trans_info - { - flex_int32_t yy_verify; - flex_int32_t yy_nxt; - }; -static yyconst flex_int16_t yy_accept[93] = - { 0, - 0, 0, 0, 0, 20, 18, 16, 15, 16, 17, - 17, 17, 17, 11, 11, 14, 11, 13, 17, 2, - 2, 4, 2, 2, 2, 2, 3, 2, 2, 2, - 2, 2, 2, 2, 0, 7, 0, 0, 0, 1, - 6, 11, 11, 0, 12, 11, 13, 11, 0, 10, - 10, 2, 2, 2, 2, 2, 2, 5, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 8, - 6, 10, 10, 2, 2, 2, 2, 10, 2, 10, - 2, 10, 2, 10, 2, 9, 2, 9, 9, 2, - 2, 0 - - } ; - -static yyconst YY_CHAR yy_ec[256] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, - 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 4, 5, 6, 7, 5, 5, 5, 8, 9, - 5, 10, 5, 5, 5, 5, 11, 12, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 5, 14, 5, - 5, 5, 5, 5, 15, 15, 15, 15, 15, 15, - 16, 16, 16, 16, 16, 17, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 5, 18, 5, 5, 19, 5, 15, 15, 20, 21, - - 22, 15, 16, 16, 23, 16, 16, 24, 16, 25, - 16, 16, 16, 16, 16, 16, 26, 16, 16, 27, - 16, 16, 5, 5, 5, 5, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1 - } ; - -static yyconst YY_CHAR yy_meta[28] = - { 0, - 1, 2, 3, 2, 1, 1, 1, 4, 5, 6, - 1, 7, 7, 1, 8, 9, 8, 1, 10, 8, - 8, 8, 9, 8, 9, 9, 8 - } ; - -static yyconst flex_uint16_t yy_base[106] = - { 0, - 0, 298, 27, 297, 298, 385, 385, 385, 385, 385, - 49, 270, 46, 41, 42, 385, 61, 278, 87, 0, - 0, 385, 0, 0, 54, 53, 266, 82, 99, 223, - 0, 126, 142, 166, 84, 385, 0, 86, 215, 385, - 0, 0, 385, 79, 385, 0, 194, 187, 95, 0, - 151, 0, 95, 0, 159, 90, 155, 385, 151, 133, - 0, 98, 0, 0, 0, 0, 0, 193, 133, 385, - 0, 0, 136, 0, 126, 0, 109, 100, 93, 83, - 81, 85, 74, 57, 53, 220, 247, 0, 0, 52, - 0, 385, 274, 284, 288, 292, 301, 310, 320, 330, - - 340, 344, 354, 364, 374 - } ; - -static yyconst flex_int16_t yy_def[106] = - { 0, - 92, 1, 92, 3, 92, 92, 92, 92, 92, 92, - 93, 94, 92, 95, 95, 92, 92, 96, 97, 98, - 98, 92, 98, 98, 99, 100, 92, 98, 98, 29, - 98, 92, 32, 92, 93, 92, 93, 94, 94, 92, - 101, 15, 92, 15, 92, 17, 96, 96, 97, 102, - 102, 98, 99, 98, 99, 100, 100, 92, 103, 29, - 98, 29, 98, 32, 33, 33, 34, 92, 68, 92, - 101, 102, 102, 98, 103, 68, 68, 102, 68, 102, - 68, 102, 68, 102, 68, 92, 92, 104, 86, 105, - 87, 0, 92, 92, 92, 92, 92, 92, 92, 92, - - 92, 92, 92, 92, 92 - } ; - -static yyconst flex_uint16_t yy_nxt[413] = - { 0, - 6, 7, 8, 9, 10, 11, 10, 12, 10, 10, - 13, 14, 15, 16, 17, 18, 18, 10, 10, 17, - 17, 17, 18, 18, 18, 18, 18, 20, 21, 22, - 23, 24, 25, 24, 26, 24, 27, 28, 29, 30, - 31, 32, 33, 33, 24, 24, 32, 32, 32, 33, - 33, 33, 33, 33, 36, 40, 41, 43, 43, 54, - 52, 88, 38, 35, 43, 43, 37, 44, 92, 45, - 57, 55, 46, 46, 87, 46, 47, 48, 86, 47, - 46, 46, 46, 47, 48, 47, 47, 47, 49, 36, - 49, 40, 59, 70, 85, 92, 49, 74, 49, 38, - - 54, 37, 92, 39, 35, 84, 83, 57, 82, 51, - 60, 60, 55, 60, 52, 61, 81, 51, 60, 60, - 60, 52, 61, 80, 52, 62, 52, 52, 79, 52, - 52, 52, 52, 52, 63, 71, 52, 64, 64, 52, - 64, 65, 66, 52, 65, 64, 64, 64, 65, 66, - 65, 65, 65, 65, 65, 78, 65, 77, 65, 52, - 71, 65, 65, 65, 38, 65, 52, 67, 35, 67, - 52, 52, 52, 52, 52, 73, 52, 52, 52, 52, - 68, 68, 68, 52, 52, 68, 68, 68, 69, 68, - 68, 68, 68, 52, 52, 45, 52, 52, 52, 52, - - 52, 52, 45, 52, 76, 76, 52, 76, 76, 76, - 52, 76, 76, 76, 76, 76, 76, 76, 76, 76, - 88, 88, 38, 88, 88, 88, 88, 88, 88, 88, - 88, 89, 89, 88, 89, 89, 89, 88, 89, 89, - 89, 89, 89, 89, 89, 89, 89, 90, 90, 52, - 90, 90, 90, 90, 90, 90, 88, 90, 91, 91, - 90, 91, 91, 91, 90, 91, 91, 91, 91, 91, - 91, 91, 91, 91, 35, 35, 58, 35, 35, 35, - 35, 35, 35, 35, 38, 38, 45, 39, 38, 38, - 38, 38, 38, 38, 42, 42, 47, 92, 47, 47, - - 47, 47, 50, 34, 19, 92, 92, 92, 50, 50, - 52, 52, 92, 52, 52, 92, 52, 52, 52, 52, - 53, 53, 92, 53, 53, 53, 53, 53, 53, 53, - 56, 56, 92, 56, 56, 56, 56, 56, 56, 56, - 71, 71, 92, 71, 71, 71, 71, 71, 71, 71, - 72, 72, 72, 72, 75, 75, 92, 75, 75, 75, - 75, 75, 75, 75, 88, 88, 92, 88, 88, 88, - 88, 88, 88, 88, 90, 90, 92, 90, 90, 90, - 90, 90, 90, 90, 5, 92, 92, 92, 92, 92, - 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, - - 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, - 92, 92 - } ; - -static yyconst flex_int16_t yy_chk[413] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 11, 13, 13, 14, 15, 25, - 26, 90, 26, 25, 14, 15, 11, 14, 15, 17, - 26, 25, 17, 17, 85, 17, 17, 17, 84, 17, - 17, 17, 17, 17, 17, 17, 17, 17, 19, 35, - 19, 28, 28, 38, 83, 44, 49, 56, 49, 56, - - 53, 35, 44, 38, 53, 82, 81, 56, 80, 19, - 29, 29, 53, 29, 62, 29, 79, 49, 29, 29, - 29, 62, 29, 78, 62, 29, 32, 32, 77, 32, - 32, 32, 32, 32, 32, 75, 32, 32, 32, 32, - 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, - 32, 32, 32, 33, 33, 73, 33, 69, 33, 60, - 59, 33, 33, 33, 57, 33, 34, 34, 55, 34, - 34, 34, 34, 34, 34, 51, 34, 34, 34, 34, - 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, - 34, 34, 34, 68, 68, 48, 68, 68, 68, 68, - - 68, 68, 47, 68, 68, 68, 68, 68, 68, 68, - 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, - 86, 86, 39, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 87, 87, 30, - 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, - 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, - 87, 87, 87, 87, 93, 93, 27, 93, 93, 93, - 93, 93, 93, 93, 94, 94, 18, 12, 94, 94, - 94, 94, 94, 94, 95, 95, 96, 5, 96, 96, - - 96, 96, 97, 4, 2, 0, 0, 0, 97, 97, - 98, 98, 0, 98, 98, 0, 98, 98, 98, 98, - 99, 99, 0, 99, 99, 99, 99, 99, 99, 99, - 100, 100, 0, 100, 100, 100, 100, 100, 100, 100, - 101, 101, 0, 101, 101, 101, 101, 101, 101, 101, - 102, 102, 102, 102, 103, 103, 0, 103, 103, 103, - 103, 103, 103, 103, 104, 104, 0, 104, 104, 104, - 104, 104, 104, 104, 105, 105, 0, 105, 105, 105, - 105, 105, 105, 105, 92, 92, 92, 92, 92, 92, - 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, - - 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, - 92, 92 - } ; - -static yy_state_type yy_last_accepting_state; -static char *yy_last_accepting_cpos; - -extern int yy_flex_debug; -int yy_flex_debug = 0; - -/* The intent behind this definition is that it'll catch - * any uses of REJECT which flex missed. - */ -#define REJECT reject_used_but_not_detected -#define yymore() yymore_used_but_not_detected -#define YY_MORE_ADJ 0 -#define YY_RESTORE_YY_MORE_OFFSET -char *yytext; -#line 1 "clang.l" -#line 2 "clang.l" -/* This file is part of the software similarity tester SIM. - Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: clang.l,v 2.20 2013-04-28 16:30:40 Gebruiker Exp $ -*/ - -/* - C language front end for the similarity tester. - Author: Dick Grune -*/ - -#include "options.h" -#include "token.h" -#include "language.h" -#include "algollike.h" -#include "idf.h" -#include "lex.h" -#include "lang.h" - -/* General language front end data */ -Token lex_token; -size_t lex_nl_cnt; -size_t lex_tk_cnt; -size_t lex_non_ascii_cnt; - -/* Language-dependent data */ - -/* Data for module idf */ - -static const struct idf ppcmd[] = { - {"define", META('d')}, - {"else", META('e')}, - {"endif", META('E')}, - {"if", META('i')}, - {"ifdef", META('I')}, - {"ifndef", META('x')}, - {"include", MTCT('I')}, - {"line", META('l')}, - {"undef", META('u')} -}; - -static const struct idf reserved[] = { - {"auto", NORM('a')}, - {"break", NORM('b')}, - {"case", NORM('c')}, - {"char", NORM('C')}, - {"continue", CTRL('C')}, - {"default", NORM('d')}, - {"do", NORM('D')}, - {"double", CTRL('D')}, - {"else", NORM('e')}, - {"enum", NORM('E')}, - {"extern", CTRL('E')}, - {"float", NORM('f')}, - {"for", NORM('F')}, - {"goto", NORM('g')}, - {"if", NORM('i')}, - {"int", NORM('I')}, - {"long", NORM('l')}, - {"register", No_Token}, - {"return", NORM('r')}, - {"short", NORM('s')}, - {"sizeof", NORM('S')}, - {"static", CTRL('S')}, - {"struct", META('s')}, - {"switch", META('S')}, - {"typedef", NORM('t')}, - {"union", NORM('u')}, - {"unsigned", NORM('U')}, - {"void", No_Token}, - {"while", NORM('w')} -}; - -/* Special treatment of identifiers */ - -static Token -idf2token(int hashing) { - Token tk; - - tk = idf_in_list(yytext, reserved, sizeof reserved, IDF); - if (Token_EQ(tk, IDF) && hashing) { - /* return a one-Token hash code */ - tk = idf_hashed(yytext); - } - return tk; -} - -/* Token sets for module algollike */ -static const Token Non_Finals[] = { - IDF, /* identifier */ - NORM('{'), - NORM('('), - NORM('a'), /* auto */ - NORM('b'), /* break */ - NORM('c'), /* case */ - NORM('C'), /* char */ - CTRL('C'), /* continue */ - NORM('d'), /* default */ - NORM('D'), /* do */ - CTRL('D'), /* double */ - NORM('E'), /* enum */ - CTRL('E'), /* extern */ - NORM('f'), /* float */ - NORM('F'), /* for */ - NORM('g'), /* goto */ - NORM('i'), /* if */ - NORM('I'), /* int */ - NORM('l'), /* long */ - NORM('r'), /* return */ - NORM('s'), /* short */ - CTRL('S'), /* static */ - META('s'), /* struct */ - META('S'), /* switch */ - NORM('t'), /* typedef */ - NORM('u'), /* union */ - NORM('U'), /* unsigned */ - NORM('w'), /* while */ - No_Token -}; - -static const Token Non_Initials[] = { - NORM(')'), - NORM('}'), - NORM(';'), - No_Token -}; - -static const Token Openers[] = { - NORM('{'), - NORM('('), - NORM('['), - No_Token -}; - -static const Token Closers[] = { - NORM('}'), - NORM(')'), - NORM(']'), - No_Token -}; - -/* Language-dependent code */ - -void -Init_Language(void) { - Init_Algol_Language(Non_Finals, Non_Initials, Openers, Closers); -} - - -int -May_Be_Start_Of_Run(Token ch) { - return May_Be_Start_Of_Algol_Run(ch); -} - -size_t -Best_Run_Size(const Token *str, size_t size) { - return Best_Algol_Run_Size(str, size); -} - - -#line 752 "" - -#define INITIAL 0 -#define Comment 1 - -#ifndef YY_NO_UNISTD_H -/* Special case for "unistd.h", since it is non-ANSI. We include it way - * down here because we want the user's section 1 to have been scanned first. - * The user has a chance to override it with an option. - */ -#include -#endif - -#ifndef YY_EXTRA_TYPE -#define YY_EXTRA_TYPE void * -#endif - -static int yy_init_globals (void ); - -/* Accessor methods to globals. - These are made visible to non-reentrant scanners for convenience. */ - -int yylex_destroy (void ); - -int yyget_debug (void ); - -void yyset_debug (int debug_flag ); - -YY_EXTRA_TYPE yyget_extra (void ); - -void yyset_extra (YY_EXTRA_TYPE user_defined ); - -FILE *yyget_in (void ); - -void yyset_in (FILE * _in_str ); - -FILE *yyget_out (void ); - -void yyset_out (FILE * _out_str ); - -yy_size_t yyget_leng (void ); - -char *yyget_text (void ); - -int yyget_lineno (void ); - -void yyset_lineno (int _line_number ); - -/* Macros after this point can all be overridden by user definitions in - * section 1. - */ - -#ifndef YY_SKIP_YYWRAP -#ifdef __cplusplus -extern "C" int yywrap (void ); -#else -extern int yywrap (void ); -#endif -#endif - -#ifndef YY_NO_UNPUT - - static void yyunput (int c,char *buf_ptr ); - -#endif - -#ifndef yytext_ptr -static void yy_flex_strncpy (char *,yyconst char *,int ); -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * ); -#endif - -#ifndef YY_NO_INPUT - -#ifdef __cplusplus -static int yyinput (void ); -#else -static int input (void ); -#endif - -#endif - -/* Amount of stuff to slurp up with each read. */ -#ifndef YY_READ_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k */ -#define YY_READ_BUF_SIZE 16384 -#else -#define YY_READ_BUF_SIZE 8192 -#endif /* __ia64__ */ -#endif - -/* Copy whatever the last rule matched to the standard output. */ -#ifndef ECHO -/* This used to be an fputs(), but since the string might contain NUL's, - * we now use fwrite(). - */ -#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0) -#endif - -/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, - * is returned in "result". - */ -#ifndef YY_INPUT -#define YY_INPUT(buf,result,max_size) \ - if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ - { \ - int c = '*'; \ - size_t n; \ - for ( n = 0; n < max_size && \ - (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ - buf[n] = (char) c; \ - if ( c == '\n' ) \ - buf[n++] = (char) c; \ - if ( c == EOF && ferror( yyin ) ) \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - result = n; \ - } \ - else \ - { \ - errno=0; \ - while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \ - { \ - if( errno != EINTR) \ - { \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - break; \ - } \ - errno=0; \ - clearerr(yyin); \ - } \ - }\ -\ - -#endif - -/* No semi-colon after return; correct usage is to write "yyterminate();" - - * we don't want an extra ';' after the "return" because that will cause - * some compilers to complain about unreachable statements. - */ -#ifndef yyterminate -#define yyterminate() return YY_NULL -#endif - -/* Number of entries by which start-condition stack grows. */ -#ifndef YY_START_STACK_INCR -#define YY_START_STACK_INCR 25 -#endif - -/* Report a fatal error. */ -#ifndef YY_FATAL_ERROR -#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) -#endif - -/* end tables serialization structures and prototypes */ - -/* Default declaration of generated scanner - a define so the user can - * easily add parameters. - */ -#ifndef YY_DECL -#define YY_DECL_IS_OURS 1 - -extern int yylex (void); - -#define YY_DECL int yylex (void) -#endif /* !YY_DECL */ - -/* Code executed at the beginning of each rule, after yytext and yyleng - * have been set up. - */ -#ifndef YY_USER_ACTION -#define YY_USER_ACTION -#endif - -/* Code executed at the end of each rule. */ -#ifndef YY_BREAK -#define YY_BREAK /*LINTED*/break; -#endif - -#define YY_RULE_SETUP \ - if ( yyleng > 0 ) \ - YY_CURRENT_BUFFER_LVALUE->yy_at_bol = \ - (yytext[yyleng - 1] == '\n'); \ - YY_USER_ACTION - -/** The main scanner function which does all the work. - */ -YY_DECL -{ - yy_state_type yy_current_state; - char *yy_cp, *yy_bp; - int yy_act; - - if ( !(yy_init) ) - { - (yy_init) = 1; - -#ifdef YY_USER_INIT - YY_USER_INIT; -#endif - - if ( ! (yy_start) ) - (yy_start) = 1; /* first start state */ - - if ( ! yyin ) - yyin = stdin; - - if ( ! yyout ) - yyout = stdout; - - if ( ! YY_CURRENT_BUFFER ) { - yyensure_buffer_stack (); - YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer(yyin,YY_BUF_SIZE ); - } - - yy_load_buffer_state( ); - } - - { -#line 184 "clang.l" - - -#line 977 "" - - while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ - { - yy_cp = (yy_c_buf_p); - - /* Support of yytext. */ - *yy_cp = (yy_hold_char); - - /* yy_bp points to the position in yy_ch_buf of the start of - * the current run. - */ - yy_bp = yy_cp; - - yy_current_state = (yy_start); - yy_current_state += YY_AT_BOL(); -yy_match: - do - { - YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 93 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - ++yy_cp; - } - while ( yy_base[yy_current_state] != 385 ); - -yy_find_action: - yy_act = yy_accept[yy_current_state]; - if ( yy_act == 0 ) - { /* have to back up */ - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - yy_act = yy_accept[yy_current_state]; - } - - YY_DO_BEFORE_ACTION; - -do_action: /* This label is used only to access EOF actions. */ - - switch ( yy_act ) - { /* beginning of action switch */ - case 0: /* must back up */ - /* undo the effects of YY_DO_BEFORE_ACTION */ - *yy_cp = (yy_hold_char); - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - goto yy_find_action; - -case 1: -YY_RULE_SETUP -#line 186 "clang.l" -{ - /* We do not have one single pattern to match a comment - (although one can be written), for two reasons. - The matched string might overflow lex-internal buffers - like yysbuf and yytext; and the pattern would be very - complicated and impair maintainability. - So we break up the string into safe chunks and keep - track of where we are in a start condition . - */ - BEGIN Comment; - } - YY_BREAK -case 2: -YY_RULE_SETUP -#line 198 "clang.l" -{ /* safe comment chunk */ - } - YY_BREAK -case 3: -YY_RULE_SETUP -#line 201 "clang.l" -{ /* unsafe char, read one by one */ - } - YY_BREAK -case 4: -/* rule 4 can match eol */ -YY_RULE_SETUP -#line 204 "clang.l" -{ /* to break up long comments */ - return_eol(); - } - YY_BREAK -case 5: -YY_RULE_SETUP -#line 208 "clang.l" -{ /* end-of-comment */ - BEGIN INITIAL; - } - YY_BREAK -case 6: -YY_RULE_SETUP -#line 212 "clang.l" -{ /* ignore */ - } - YY_BREAK -case 7: -YY_RULE_SETUP -#line 215 "clang.l" -{ /* strings */ - return_ch('"'); - } - YY_BREAK -case 8: -YY_RULE_SETUP -#line 219 "clang.l" -{ /* characters */ - return_ch('\''); - } - YY_BREAK -case 9: -YY_RULE_SETUP -#line 223 "clang.l" -{ /* ignore #include lines */ - } - YY_BREAK -case 10: -YY_RULE_SETUP -#line 226 "clang.l" -{ /* a preprocessor line */ - char *idf = yytext+1; - - /* skip layout in front of preprocessor identifier */ - while (*idf == ' ' || *idf == '\t') { - idf++; - } - return_tk(idf_in_list(idf, ppcmd, sizeof ppcmd, NORM('#'))); - } - YY_BREAK -case 11: -YY_RULE_SETUP -#line 236 "clang.l" -{ /* numeral, passed as an identifier */ - return_tk(IDF); - } - YY_BREAK -case 12: -*yy_cp = (yy_hold_char); /* undo effects of setting up yytext */ -(yy_c_buf_p) = yy_cp -= 1; -YY_DO_BEFORE_ACTION; /* set up yytext again */ -YY_RULE_SETUP -#line 240 "clang.l" -{ /* identifier in front of ( */ - Token tk; - - tk = idf2token(is_set_option('F')); - if (!Token_EQ(tk, No_Token)) return_tk(tk); - } - YY_BREAK -case 13: -YY_RULE_SETUP -#line 247 "clang.l" -{ /* identifier */ - Token tk; - - tk = idf2token(0 /* no hashing */); - if (!Token_EQ(tk, No_Token)) return_tk(tk); - } - YY_BREAK -case 14: -YY_RULE_SETUP -#line 254 "clang.l" -{ /* semicolon, conditionally ignored */ - if (is_set_option('f')) return_ch(yytext[0]); - } - YY_BREAK -case 15: -/* rule 15 can match eol */ -YY_RULE_SETUP -#line 258 "clang.l" -{ /* count newlines */ - return_eol(); - } - YY_BREAK -case 16: -YY_RULE_SETUP -#line 262 "clang.l" -{ /* ignore layout */ - } - YY_BREAK -case 17: -YY_RULE_SETUP -#line 265 "clang.l" -{ /* copy other text */ - return_ch(yytext[0]); - } - YY_BREAK -case 18: -YY_RULE_SETUP -#line 269 "clang.l" -{ /* count non-ASCII chars */ - lex_non_ascii_cnt++; - } - YY_BREAK -case 19: -YY_RULE_SETUP -#line 273 "clang.l" -ECHO; - YY_BREAK -#line 1186 "" -case YY_STATE_EOF(INITIAL): -case YY_STATE_EOF(Comment): - yyterminate(); - - case YY_END_OF_BUFFER: - { - /* Amount of text matched not including the EOB char. */ - int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; - - /* Undo the effects of YY_DO_BEFORE_ACTION. */ - *yy_cp = (yy_hold_char); - YY_RESTORE_YY_MORE_OFFSET - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) - { - /* We're scanning a new file or input source. It's - * possible that this happened because the user - * just pointed yyin at a new source and called - * yylex(). If so, then we have to assure - * consistency between YY_CURRENT_BUFFER and our - * globals. Here is the right place to do so, because - * this is the first action (other than possibly a - * back-up) that will match for the new input source. - */ - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; - } - - /* Note that here we test for yy_c_buf_p "<=" to the position - * of the first EOB in the buffer, since yy_c_buf_p will - * already have been incremented past the NUL character - * (since all states make transitions on EOB to the - * end-of-buffer state). Contrast this with the test - * in input(). - */ - if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) - { /* This was really a NUL. */ - yy_state_type yy_next_state; - - (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( ); - - /* Okay, we're now positioned to make the NUL - * transition. We couldn't have - * yy_get_previous_state() go ahead and do it - * for us because it doesn't know how to deal - * with the possibility of jamming (and we don't - * want to build jamming into it because then it - * will run more slowly). - */ - - yy_next_state = yy_try_NUL_trans( yy_current_state ); - - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - - if ( yy_next_state ) - { - /* Consume the NUL. */ - yy_cp = ++(yy_c_buf_p); - yy_current_state = yy_next_state; - goto yy_match; - } - - else - { - yy_cp = (yy_c_buf_p); - goto yy_find_action; - } - } - - else switch ( yy_get_next_buffer( ) ) - { - case EOB_ACT_END_OF_FILE: - { - (yy_did_buffer_switch_on_eof) = 0; - - if ( yywrap( ) ) - { - /* Note: because we've taken care in - * yy_get_next_buffer() to have set up - * yytext, we can now set up - * yy_c_buf_p so that if some total - * hoser (like flex itself) wants to - * call the scanner after we return the - * YY_NULL, it'll still work - another - * YY_NULL will get returned. - */ - (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; - - yy_act = YY_STATE_EOF(YY_START); - goto do_action; - } - - else - { - if ( ! (yy_did_buffer_switch_on_eof) ) - YY_NEW_FILE; - } - break; - } - - case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = - (yytext_ptr) + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( ); - - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - goto yy_match; - - case EOB_ACT_LAST_MATCH: - (yy_c_buf_p) = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; - - yy_current_state = yy_get_previous_state( ); - - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - goto yy_find_action; - } - break; - } - - default: - YY_FATAL_ERROR( - "fatal flex scanner internal error--no action found" ); - } /* end of action switch */ - } /* end of scanning one token */ - } /* end of user's declarations */ -} /* end of yylex */ - -/* yy_get_next_buffer - try to read in a new buffer - * - * Returns a code representing an action: - * EOB_ACT_LAST_MATCH - - * EOB_ACT_CONTINUE_SCAN - continue scanning from current position - * EOB_ACT_END_OF_FILE - end of file - */ -static int yy_get_next_buffer (void) -{ - char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; - char *source = (yytext_ptr); - yy_size_t number_to_move, i; - int ret_val; - - if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) - YY_FATAL_ERROR( - "fatal flex scanner internal error--end of buffer missed" ); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) - { /* Don't try to fill the buffer, so this is an EOF. */ - if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) - { - /* We matched a single character, the EOB, so - * treat this as a final EOF. - */ - return EOB_ACT_END_OF_FILE; - } - - else - { - /* We matched some text prior to the EOB, first - * process it. - */ - return EOB_ACT_LAST_MATCH; - } - } - - /* Try to read more data. */ - - /* First move last chars to start of buffer. */ - number_to_move = (yy_size_t) ((yy_c_buf_p) - (yytext_ptr)) - 1; - - for ( i = 0; i < number_to_move; ++i ) - *(dest++) = *(source++); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) - /* don't do the read, it's not guaranteed to return an EOF, - * just force an EOF - */ - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; - - else - { - yy_size_t num_to_read = - YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; - - while ( num_to_read <= 0 ) - { /* Not enough room in the buffer - grow it. */ - - /* just a shorter name for the current buffer */ - YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; - - int yy_c_buf_p_offset = - (int) ((yy_c_buf_p) - b->yy_ch_buf); - - if ( b->yy_is_our_buffer ) - { - yy_size_t new_size = b->yy_buf_size * 2; - - if ( new_size <= 0 ) - b->yy_buf_size += b->yy_buf_size / 8; - else - b->yy_buf_size *= 2; - - b->yy_ch_buf = (char *) - /* Include room in for 2 EOB chars. */ - yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ); - } - else - /* Can't grow it, we don't own it. */ - b->yy_ch_buf = 0; - - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( - "fatal error - scanner input buffer overflow" ); - - (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; - - num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - - number_to_move - 1; - - } - - if ( num_to_read > YY_READ_BUF_SIZE ) - num_to_read = YY_READ_BUF_SIZE; - - /* Read in more data. */ - YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), - (yy_n_chars), num_to_read ); - - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - if ( (yy_n_chars) == 0 ) - { - if ( number_to_move == YY_MORE_ADJ ) - { - ret_val = EOB_ACT_END_OF_FILE; - yyrestart(yyin ); - } - - else - { - ret_val = EOB_ACT_LAST_MATCH; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = - YY_BUFFER_EOF_PENDING; - } - } - - else - ret_val = EOB_ACT_CONTINUE_SCAN; - - if ((int) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { - /* Extend the array by 50%, plus the number we really need. */ - int new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ); - if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); - } - - (yy_n_chars) += number_to_move; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; - - (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; - - return ret_val; -} - -/* yy_get_previous_state - get the state just before the EOB char was reached */ - - static yy_state_type yy_get_previous_state (void) -{ - yy_state_type yy_current_state; - char *yy_cp; - - yy_current_state = (yy_start); - yy_current_state += YY_AT_BOL(); - - for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) - { - YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 93 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - } - - return yy_current_state; -} - -/* yy_try_NUL_trans - try to make a transition on the NUL character - * - * synopsis - * next_state = yy_try_NUL_trans( current_state ); - */ - static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) -{ - int yy_is_jam; - char *yy_cp = (yy_c_buf_p); - - YY_CHAR yy_c = 1; - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 93 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - yy_is_jam = (yy_current_state == 92); - - return yy_is_jam ? 0 : yy_current_state; -} - -#ifndef YY_NO_UNPUT - - static void yyunput (int c, char * yy_bp ) -{ - char *yy_cp; - - yy_cp = (yy_c_buf_p); - - /* undo effects of setting up yytext */ - *yy_cp = (yy_hold_char); - - if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) - { /* need to shift things up to make room */ - /* +2 for EOB chars. */ - yy_size_t number_to_move = (yy_n_chars) + 2; - char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ - YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; - char *source = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; - - while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) - *--dest = *--source; - - yy_cp += (int) (dest - source); - yy_bp += (int) (dest - source); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size; - - if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) - YY_FATAL_ERROR( "flex scanner push-back overflow" ); - } - - *--yy_cp = (char) c; - - (yytext_ptr) = yy_bp; - (yy_hold_char) = *yy_cp; - (yy_c_buf_p) = yy_cp; -} - -#endif - -#ifndef YY_NO_INPUT -#ifdef __cplusplus - static int yyinput (void) -#else - static int input (void) -#endif - -{ - int c; - - *(yy_c_buf_p) = (yy_hold_char); - - if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) - { - /* yy_c_buf_p now points to the character we want to return. - * If this occurs *before* the EOB characters, then it's a - * valid NUL; if not, then we've hit the end of the buffer. - */ - if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) - /* This was really a NUL. */ - *(yy_c_buf_p) = '\0'; - - else - { /* need more input */ - yy_size_t offset = (yy_c_buf_p) - (yytext_ptr); - ++(yy_c_buf_p); - - switch ( yy_get_next_buffer( ) ) - { - case EOB_ACT_LAST_MATCH: - /* This happens because yy_g_n_b() - * sees that we've accumulated a - * token and flags that we need to - * try matching the token before - * proceeding. But for input(), - * there's no matching to consider. - * So convert the EOB_ACT_LAST_MATCH - * to EOB_ACT_END_OF_FILE. - */ - - /* Reset buffer status. */ - yyrestart(yyin ); - - /*FALLTHROUGH*/ - - case EOB_ACT_END_OF_FILE: - { - if ( yywrap( ) ) - return EOF; - - if ( ! (yy_did_buffer_switch_on_eof) ) - YY_NEW_FILE; -#ifdef __cplusplus - return yyinput(); -#else - return input(); -#endif - } - - case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = (yytext_ptr) + offset; - break; - } - } - } - - c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ - *(yy_c_buf_p) = '\0'; /* preserve yytext */ - (yy_hold_char) = *++(yy_c_buf_p); - - YY_CURRENT_BUFFER_LVALUE->yy_at_bol = (c == '\n'); - - return c; -} -#endif /* ifndef YY_NO_INPUT */ - -/** Immediately switch to a different input stream. - * @param input_file A readable stream. - * - * @note This function does not reset the start condition to @c INITIAL . - */ - void yyrestart (FILE * input_file ) -{ - - if ( ! YY_CURRENT_BUFFER ){ - yyensure_buffer_stack (); - YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer(yyin,YY_BUF_SIZE ); - } - - yy_init_buffer(YY_CURRENT_BUFFER,input_file ); - yy_load_buffer_state( ); -} - -/** Switch to a different input buffer. - * @param new_buffer The new input buffer. - * - */ - void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) -{ - - /* TODO. We should be able to replace this entire function body - * with - * yypop_buffer_state(); - * yypush_buffer_state(new_buffer); - */ - yyensure_buffer_stack (); - if ( YY_CURRENT_BUFFER == new_buffer ) - return; - - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - YY_CURRENT_BUFFER_LVALUE = new_buffer; - yy_load_buffer_state( ); - - /* We don't actually know whether we did this switch during - * EOF (yywrap()) processing, but the only time this flag - * is looked at is after yywrap() is called, so it's safe - * to go ahead and always set it. - */ - (yy_did_buffer_switch_on_eof) = 1; -} - -static void yy_load_buffer_state (void) -{ - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; - yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; - (yy_hold_char) = *(yy_c_buf_p); -} - -/** Allocate and initialize an input buffer state. - * @param file A readable stream. - * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. - * - * @return the allocated buffer state. - */ - YY_BUFFER_STATE yy_create_buffer (FILE * file, int size ) -{ - YY_BUFFER_STATE b; - - b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - - b->yy_buf_size = (yy_size_t)size; - - /* yy_ch_buf has to be 2 characters longer than the size given because - * we need to put in 2 end-of-buffer characters. - */ - b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 ); - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - - b->yy_is_our_buffer = 1; - - yy_init_buffer(b,file ); - - return b; -} - -/** Destroy the buffer. - * @param b a buffer created with yy_create_buffer() - * - */ - void yy_delete_buffer (YY_BUFFER_STATE b ) -{ - - if ( ! b ) - return; - - if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ - YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; - - if ( b->yy_is_our_buffer ) - yyfree((void *) b->yy_ch_buf ); - - yyfree((void *) b ); -} - -/* Initializes or reinitializes a buffer. - * This function is sometimes called more than once on the same buffer, - * such as during a yyrestart() or at EOF. - */ - static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file ) - -{ - int oerrno = errno; - - yy_flush_buffer(b ); - - b->yy_input_file = file; - b->yy_fill_buffer = 1; - - /* If b is the current buffer, then yy_init_buffer was _probably_ - * called from yyrestart() or through yy_get_next_buffer. - * In that case, we don't want to reset the lineno or column. - */ - if (b != YY_CURRENT_BUFFER){ - b->yy_bs_lineno = 1; - b->yy_bs_column = 0; - } - - b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; - - errno = oerrno; -} - -/** Discard all buffered characters. On the next scan, YY_INPUT will be called. - * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. - * - */ - void yy_flush_buffer (YY_BUFFER_STATE b ) -{ - if ( ! b ) - return; - - b->yy_n_chars = 0; - - /* We always need two end-of-buffer characters. The first causes - * a transition to the end-of-buffer state. The second causes - * a jam in that state. - */ - b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; - b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; - - b->yy_buf_pos = &b->yy_ch_buf[0]; - - b->yy_at_bol = 1; - b->yy_buffer_status = YY_BUFFER_NEW; - - if ( b == YY_CURRENT_BUFFER ) - yy_load_buffer_state( ); -} - -/** Pushes the new state onto the stack. The new state becomes - * the current state. This function will allocate the stack - * if necessary. - * @param new_buffer The new state. - * - */ -void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) -{ - if (new_buffer == NULL) - return; - - yyensure_buffer_stack(); - - /* This block is copied from yy_switch_to_buffer. */ - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - /* Only push if top exists. Otherwise, replace top. */ - if (YY_CURRENT_BUFFER) - (yy_buffer_stack_top)++; - YY_CURRENT_BUFFER_LVALUE = new_buffer; - - /* copied from yy_switch_to_buffer. */ - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; -} - -/** Removes and deletes the top of the stack, if present. - * The next element becomes the new top. - * - */ -void yypop_buffer_state (void) -{ - if (!YY_CURRENT_BUFFER) - return; - - yy_delete_buffer(YY_CURRENT_BUFFER ); - YY_CURRENT_BUFFER_LVALUE = NULL; - if ((yy_buffer_stack_top) > 0) - --(yy_buffer_stack_top); - - if (YY_CURRENT_BUFFER) { - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; - } -} - -/* Allocates the stack if it does not exist. - * Guarantees space for at least one push. - */ -static void yyensure_buffer_stack (void) -{ - yy_size_t num_to_alloc; - - if (!(yy_buffer_stack)) { - - /* First allocation is just for 2 elements, since we don't know if this - * scanner will even need a stack. We use 2 instead of 1 to avoid an - * immediate realloc on the next call. - */ - num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ - (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc - (num_to_alloc * sizeof(struct yy_buffer_state*) - ); - if ( ! (yy_buffer_stack) ) - YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); - - memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); - - (yy_buffer_stack_max) = num_to_alloc; - (yy_buffer_stack_top) = 0; - return; - } - - if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ - - /* Increase the buffer to prepare for a possible push. */ - yy_size_t grow_size = 8 /* arbitrary grow size */; - - num_to_alloc = (yy_buffer_stack_max) + grow_size; - (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc - ((yy_buffer_stack), - num_to_alloc * sizeof(struct yy_buffer_state*) - ); - if ( ! (yy_buffer_stack) ) - YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); - - /* zero only the new slots.*/ - memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); - (yy_buffer_stack_max) = num_to_alloc; - } -} - -/** Setup the input buffer state to scan directly from a user-specified character buffer. - * @param base the character buffer - * @param size the size in bytes of the character buffer - * - * @return the newly allocated buffer state object. - */ -YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) -{ - YY_BUFFER_STATE b; - - if ( size < 2 || - base[size-2] != YY_END_OF_BUFFER_CHAR || - base[size-1] != YY_END_OF_BUFFER_CHAR ) - /* They forgot to leave room for the EOB's. */ - return 0; - - b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); - - b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ - b->yy_buf_pos = b->yy_ch_buf = base; - b->yy_is_our_buffer = 0; - b->yy_input_file = 0; - b->yy_n_chars = b->yy_buf_size; - b->yy_is_interactive = 0; - b->yy_at_bol = 1; - b->yy_fill_buffer = 0; - b->yy_buffer_status = YY_BUFFER_NEW; - - yy_switch_to_buffer(b ); - - return b; -} - -/** Setup the input buffer state to scan a string. The next call to yylex() will - * scan from a @e copy of @a str. - * @param yystr a NUL-terminated string to scan - * - * @return the newly allocated buffer state object. - * @note If you want to scan bytes that may contain NUL values, then use - * yy_scan_bytes() instead. - */ -YY_BUFFER_STATE yy_scan_string (yyconst char * yystr ) -{ - - return yy_scan_bytes(yystr,strlen(yystr) ); -} - -/** Setup the input buffer state to scan the given bytes. The next call to yylex() will - * scan from a @e copy of @a bytes. - * @param yybytes the byte buffer to scan - * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. - * - * @return the newly allocated buffer state object. - */ -YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len ) -{ - YY_BUFFER_STATE b; - char *buf; - yy_size_t n; - yy_size_t i; - - /* Get memory for full buffer, including space for trailing EOB's. */ - n = _yybytes_len + 2; - buf = (char *) yyalloc(n ); - if ( ! buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); - - for ( i = 0; i < _yybytes_len; ++i ) - buf[i] = yybytes[i]; - - buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; - - b = yy_scan_buffer(buf,n ); - if ( ! b ) - YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); - - /* It's okay to grow etc. this buffer, and we should throw it - * away when we're done. - */ - b->yy_is_our_buffer = 1; - - return b; -} - -#ifndef YY_EXIT_FAILURE -#define YY_EXIT_FAILURE 2 -#endif - -static void yy_fatal_error (yyconst char* msg ) -{ - (void) fprintf( stderr, "%s\n", msg ); - exit( YY_EXIT_FAILURE ); -} - -/* Redefine yyless() so it works in section 3 code. */ - -#undef yyless -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - yytext[yyleng] = (yy_hold_char); \ - (yy_c_buf_p) = yytext + yyless_macro_arg; \ - (yy_hold_char) = *(yy_c_buf_p); \ - *(yy_c_buf_p) = '\0'; \ - yyleng = yyless_macro_arg; \ - } \ - while ( 0 ) - -/* Accessor methods (get/set functions) to struct members. */ - -/** Get the current line number. - * - */ -int yyget_lineno (void) -{ - - return yylineno; -} - -/** Get the input stream. - * - */ -FILE *yyget_in (void) -{ - return yyin; -} - -/** Get the output stream. - * - */ -FILE *yyget_out (void) -{ - return yyout; -} - -/** Get the length of the current token. - * - */ -yy_size_t yyget_leng (void) -{ - return yyleng; -} - -/** Get the current token. - * - */ - -char *yyget_text (void) -{ - return yytext; -} - -/** Set the current line number. - * @param _line_number line number - * - */ -void yyset_lineno (int _line_number ) -{ - - yylineno = _line_number; -} - -/** Set the input stream. This does not discard the current - * input buffer. - * @param _in_str A readable stream. - * - * @see yy_switch_to_buffer - */ -void yyset_in (FILE * _in_str ) -{ - yyin = _in_str ; -} - -void yyset_out (FILE * _out_str ) -{ - yyout = _out_str ; -} - -int yyget_debug (void) -{ - return yy_flex_debug; -} - -void yyset_debug (int _bdebug ) -{ - yy_flex_debug = _bdebug ; -} - -static int yy_init_globals (void) -{ - /* Initialization is the same as for the non-reentrant scanner. - * This function is called from yylex_destroy(), so don't allocate here. - */ - - (yy_buffer_stack) = 0; - (yy_buffer_stack_top) = 0; - (yy_buffer_stack_max) = 0; - (yy_c_buf_p) = (char *) 0; - (yy_init) = 0; - (yy_start) = 0; - -/* Defined in main.c */ -#ifdef YY_STDINIT - yyin = stdin; - yyout = stdout; -#else - yyin = (FILE *) 0; - yyout = (FILE *) 0; -#endif - - /* For future reference: Set errno on error, since we are called by - * yylex_init() - */ - return 0; -} - -/* yylex_destroy is for both reentrant and non-reentrant scanners. */ -int yylex_destroy (void) -{ - - /* Pop the buffer stack, destroying each element. */ - while(YY_CURRENT_BUFFER){ - yy_delete_buffer(YY_CURRENT_BUFFER ); - YY_CURRENT_BUFFER_LVALUE = NULL; - yypop_buffer_state(); - } - - /* Destroy the stack itself. */ - yyfree((yy_buffer_stack) ); - (yy_buffer_stack) = NULL; - - /* Reset the globals. This is important in a non-reentrant scanner so the next time - * yylex() is called, initialization will occur. */ - yy_init_globals( ); - - return 0; -} - -/* - * Internal utility routines. - */ - -#ifndef yytext_ptr -static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) -{ - - int i; - for ( i = 0; i < n; ++i ) - s1[i] = s2[i]; -} -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * s ) -{ - int n; - for ( n = 0; s[n]; ++n ) - ; - - return n; -} -#endif - -void *yyalloc (yy_size_t size ) -{ - return (void *) malloc( size ); -} - -void *yyrealloc (void * ptr, yy_size_t size ) -{ - - /* The cast to (char *) in the following accommodates both - * implementations that use char* generic pointers, and those - * that use void* generic pointers. It works with the latter - * because both ANSI C and C++ allow castless assignment from - * any pointer type to void*, and deal with argument conversions - * as though doing an assignment. - */ - return (void *) realloc( (char *) ptr, size ); -} - -void yyfree (void * ptr ) -{ - free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ -} - -#define YYTABLES_NAME "yytables" - -#line 273 "clang.l" - - - -/* More language-dependent code */ - -void -yystart(void) { - BEGIN INITIAL; -} - diff --git a/judger/core/sim/sim_2_77/compare.c b/judger/core/sim/sim_2_77/compare.c deleted file mode 100755 index 3beb14cd..00000000 --- a/judger/core/sim/sim_2_77/compare.c +++ /dev/null @@ -1,201 +0,0 @@ -/* This file is part of the software similarity tester SIM. - Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: compare.c,v 2.17 2013-04-28 16:30:40 Gebruiker Exp $ -*/ - -#include "sim.h" -#include "text.h" -#include "token.h" -#include "tokenarray.h" -#include "hash.h" -#include "language.h" -#include "options.h" -#include "add_run.h" -#include "compare.h" -#include "debug.par" - -static void compare_one_text(int, int, int); -static size_t lcs( - struct text *, size_t, struct text **, size_t *, - size_t, size_t -); - -/* The overall structure of the routine Compare_Files() is: - - for all new files - for all texts it must be compared to - for all positions in the new file - for all positions in the text - for ever increasing sizes - try to match and keep the best -*/ - -void -Compare_Files(void) { - int n; - - for ( /* all new texts */ - n = 0; n < Number_Of_New_Texts; n++ - ) { - int first = - ( /* if compare to old only */ - is_set_option('S') - ? Number_Of_New_Texts + 1 - : /* else if do not compare to self */ - is_set_option('s') - ? n + 1 - /* else */ - : n - ); - - if (is_set_option('e')) { - /* from first to Number_Of_Texts in steps */ - int m; - - for (m = first; m < Number_Of_Texts; m++) { - compare_one_text(n, m, m+1); - } - } - else { - /* from first to Number_Of_Texts in one action */ - if (first < Number_Of_Texts) { - compare_one_text(n, first, Number_Of_Texts); - } - } - } -} - -static void -compare_one_text( - int n, /* text to be compared */ - int first, /* first text to be compared to */ - int limit /* first text not to be compared to */ -) { - size_t i_first = Text[first].tx_start; - size_t i_limit = Text[limit-1].tx_limit; - struct text *txt0 = &Text[n]; - size_t i0 = txt0->tx_start; - - while ( /* there may be a useful substring */ - i0 + Min_Run_Size <= txt0->tx_limit - ) { - /* see if there really is one */ - struct text *txt_best; - size_t i_best; - size_t size_best = - lcs(txt0, i0, &txt_best, &i_best, i_first, i_limit); - - if (size_best) { - /* good run found; enter it */ - add_run(txt0, i0, txt_best, i_best, size_best); - /* and skip it */ - i0 += size_best; - } - else { - /* we try our luck at the next token */ - i0++; - } - } -} - -static size_t -lcs( struct text *txt0, /* input: starting position */ - size_t i0, - struct text **tbp, /* output: position of best run */ - size_t *ibp, - size_t i_first, /* no comparison before this pos. */ - size_t i_limit /* no comparison after this pos. */ -) { - /* Finds the longest common substring (not subsequence) in: - txt0, starting precisely at i0 and - the text from i_first to i_limit-1. - Writes the position in tbp and ibp and returns the size. - Returns 0 if no common substring is found. - */ - struct text *txt1 = txt0; - size_t i1 = i0; - size_t size_best = 0; - - while ( /* there is a next opportunity */ - (i1 = Forward_Reference(i1)) - && /* it is still in range */ - i1 < i_limit - ) { - size_t min_size= (size_best ? size_best+1 : Min_Run_Size); - - if (i1 < i_first) { /* not in range */ - continue; - } - - /* bump txt1; we may have to skip a text or two */ - while (i1 >= txt1->tx_limit) { - txt1++; - } - - /* are we looking at something better than we have got? */ - { /* comparing backwards */ - size_t j0 = i0 + min_size - 1; - size_t j1 = i1 + min_size - 1; - if ( /* j0 still inside txt0 */ - j0 < txt0->tx_limit - && /* j1 still inside txt1 */ - j1 < txt1->tx_limit - && /* j0 and j1 don't overlap */ - j0 + min_size <= j1 - ) { - /* there is room enough for a match */ - size_t cnt = min_size; - - /* text matches for at least min_size tokens? */ - while ( cnt - && Token_EQ(Token_Array[j0], - Token_Array[j1]) - ) { - cnt--, j0--, j1--; - } - if (cnt) continue; /* forget it */ - } - else continue; /* forget it */ - } - - /* yes, we are; how long can we make it? */ - size_t new_size = min_size; - { /* extending forwards */ - size_t j0 = i0 + min_size; - size_t j1 = i1 + min_size; - - while ( /* j0 still inside txt0 */ - j0 < txt0->tx_limit - && /* j1 still inside txt1 */ - j1 < txt1->tx_limit - && /* j0 and j1 don't overlap */ - j0 + new_size < j1 - && /* tokens are the same */ - Token_EQ(Token_Array[j0], Token_Array[j1]) - ) { - j0++, j1++, new_size++; - } - } - - /* offer the run to the Language Department which may - reject it or may cut its tail - */ - new_size = ( May_Be_Start_Of_Run(Token_Array[i0]) - ? Best_Run_Size(&Token_Array[i0], new_size) - : 0 - ); - - if ( /* we still have something acceptable */ - new_size >= Min_Run_Size - && /* it is better still than what we had */ - new_size > size_best - ) { - /* record it */ - *tbp = txt1; - *ibp = i1; - size_best = new_size; - } - } - - return size_best; -} diff --git a/judger/core/sim/sim_2_77/debug.h b/judger/core/sim/sim_2_77/debug.h deleted file mode 100755 index d1ff87b9..00000000 --- a/judger/core/sim/sim_2_77/debug.h +++ /dev/null @@ -1,35 +0,0 @@ -/* This file is part of the debugging module DEBUG. - Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: debug.h,v 1.7 2013-05-12 09:58:34 Gebruiker Exp $ -*/ - -#ifndef _DEBUG_H_ -#define _DEBUG_H_ - -/**** -The module DEBUG defines one routine, - - extern void wr_info(const char *s, int b, int v); - -which, when compiled with a -DDEBUG option, writes the string s, a space -character, the value v in base b, and a newline to standard error output (file -descriptor 2), without interfering with other program activities. - -The following values for b are accepted: - b = 0: the string s only - b = 8: octal - b = 16: hex - b = 128: char - otherwise: decimal - -This allows debugging info to be obtained in the presence of sudden crashes -and other nefarious program activity. - -Compiled without the -DDEBUG option wr_info does nothing. This allows easy -switching off of the debugging feature by recompiling debug.c. -****/ - -/* Public entries */ -extern void wr_info(const char *s, int b, int v); - -#endif /* _DEBUG_H_ */ diff --git a/judger/core/sim/sim_2_77/error.c b/judger/core/sim/sim_2_77/error.c deleted file mode 100755 index 207cf273..00000000 --- a/judger/core/sim/sim_2_77/error.c +++ /dev/null @@ -1,21 +0,0 @@ -/* This file is part of the software similarity tester SIM. - Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: error.c,v 2.6 2012-06-05 09:58:52 Gebruiker Exp $ -*/ - -#include -#include - -#include "sim.h" -#include "error.h" - -void -fatal(const char *msg) { -#ifdef lint - /* prevent non-use messages */ - min_run_string = 0; - threshold_string = 0; -#endif - fprintf(stderr, "%s: %s\n", progname, msg); - exit(1); -} diff --git a/judger/core/sim/sim_2_77/error.h b/judger/core/sim/sim_2_77/error.h deleted file mode 100755 index 5c6c54c4..00000000 --- a/judger/core/sim/sim_2_77/error.h +++ /dev/null @@ -1,6 +0,0 @@ -/* This file is part of the software similarity tester SIM. - Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: error.h,v 1.3 1998/02/03 14:28:23 dick Exp $ -*/ - -extern void fatal(const char *msg); diff --git a/judger/core/sim/sim_2_77/hash.c b/judger/core/sim/sim_2_77/hash.c deleted file mode 100755 index dc51169d..00000000 --- a/judger/core/sim/sim_2_77/hash.c +++ /dev/null @@ -1,466 +0,0 @@ -/* This file is part of the software similarity tester SIM. - Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: hash.c,v 2.23 2014-01-27 20:50:50 Gebruiker Exp $ -*/ - -/* Text is compared by comparing every substring to all substrings - to the right of it; this process is in essence quadratic. However, - only substrings of length at least 'Min_Run_Size' are of interest, - which gives us the possibility to speed up this process by using - a hash table. - - For every position in the text, we construct an index which gives - the next position in the text at which a run of Min_Run_Size tokens - starts that has the same hash code, as calculated by hash1(). If - there is no such run, the index is 0. These forward references are - kept in the array forward_reference[]. - - To construct this array, we use a hash table last_index[] whose size - is a prime and which is about 8 times smaller than the text array. - The hash table last_index[] is set up such that last_index[i] is the - index of the latest token with hash_code i, or 0 if there is none. - This results in hash chains of an average length of 8. See - Make_Forward_References(). - - If there is not enough room for a hash table of the proper size - (which can be considerable) the hashing is not efficient any more. - In that case, the forward reference table is scanned a second time, - eliminating from any chain all references to runs that do not hash to - the same value under a second hash function, hash2(). For the UNIX - manuals this reduced the number of matches from 91.9% to 1.9% (of - which 0.06% was genuine). -*/ - -#include -#include - -#include "system.par" -#include "debug.par" -#include "sim.h" -#include "text.h" -#include "Malloc.h" -#include "error.h" -#include "any_int.h" -#include "token.h" -#include "language.h" -#include "token.h" -#include "tokenarray.h" -#include "options.h" -#include "hash.h" - - /* MAIN ENTRIES */ -static size_t *forward_reference; /* to be filled by Malloc() */ -static size_t n_forward_references; - -static void make_forward_references_hash1(void); -static void make_forward_references_hash2(void); - -#ifdef DB_FORW_REF -static void db_forward_references(const char *); -static void make_forward_references_hash3(void); -#endif - -void -Make_Forward_References(void) { - /* Constructs the forward references table. - */ - - n_forward_references = Text_Length(); - forward_reference = - (size_t *)Calloc( - n_forward_references, sizeof (size_t) - ); - make_forward_references_hash1(); - make_forward_references_hash2(); -#ifdef DB_FORW_REF - make_forward_references_hash3(); -#endif -} - -size_t -Forward_Reference(size_t i) { - if (i == 0 || i >= n_forward_references) { - fatal("internal error, bad forward reference"); - } - return forward_reference[i]; -} - -void -Free_Forward_References(void) { - Free((char *)forward_reference); -} - - /* HASHING */ -/* - We want a hash function whose time cost does not depend on - Min_Run_Size, which is a problem since the size of the object - we derive the hash value from IS equal to Min_Run_Size! - Therefore we base the hash function on a sample of at most - N_SAMPLES tokens from the input string; this works just - as well in practice. -*/ - -#define N_SAMPLES 24 -#define OPERATION ^ - -/* An alternative algorithm; does not seem to make any difference. -#define N_SAMPLES 23 -#define OPERATION + -*/ - -/* Another algorithm; not yet tested -#define N_SAMPLES 24 -#define OPERATION + 613 * -*/ - -static size_t *last_index; -static size_t hash_table_size; -/* positions where the N_SAMPLES samples can be found: */ -static size_t sample_pos[N_SAMPLES]; - -/* The prime numbers of the form 4 * i + 3 for some i, all greater - than twice the previous one and smaller than 2^40 (for now). -*/ -static const uint64_t prime[] = { -#if 0 - 3, - 7, - 19, - 43, - 103, - 211, - 431, - 863, - 1747, - 3499, - 7019, -#endif - 14051, - 28111, - 56239, - 112507, - 225023, - 450067, - 900139, - 1800311, - 3600659, - 7201351, - 14402743, - 28805519, - 57611039, - 115222091, - 230444239, - 460888499, - 921777067, - 1843554151, - UINT64_C (3687108307), - UINT64_C (7374216631), - UINT64_C (14748433279), - UINT64_C (29496866579), - UINT64_C (58993733159), - UINT64_C (117987466379), - UINT64_C (235974932759), - UINT64_C (471949865531), - UINT64_C (943899731087) - /* 2^40= 1099511627776 */ -}; - -static void -init_hash_table(void) { - int n; - - /* find the ideal hash table size */ - n = 0; - while (prime[n] < Text_Length()) { - n++; - /* this will always terminate, if prime[] is large enough */ - } - - /* see if we can allocate that much space, and if not, step down */ - last_index = 0; - while (!last_index && n >= 0) { - hash_table_size = prime[n]; - last_index = (size_t *) - TryCalloc(hash_table_size, sizeof (size_t)); - n--; - } - if (!last_index) { - fatal("out of memory"); - } - - /* find sample positions */ - for (n = 0; n < N_SAMPLES; n++) { - /* straigh-line approximation; uninituitive as usual */ - sample_pos[n] = ( - (2 * n * (Min_Run_Size - 1) + (N_SAMPLES - 1)) - / (2 * (N_SAMPLES - 1)) - ); - } -} - -static size_t hash1(const Token *); - -static void -make_forward_references_hash1(void) { - int n; - - init_hash_table(); - - /* set up the forward references using the last_index hash table */ - for (n = 0; n < Number_Of_Texts; n++) { - struct text *txt = &Text[n]; - size_t j; - - for ( /* all pos'ns in txt except the last Min_Run_Size-1 */ - j = txt->tx_start; /* >= 1 */ - j + Min_Run_Size - 1 < txt->tx_limit; - j++ - ) { - if (May_Be_Start_Of_Run(Token_Array[j])) { - size_t h = hash1(&Token_Array[j]); - - if (last_index[h]) { - forward_reference[last_index[h]] = j; - } - last_index[h] = j; - } - } - } - Free((char *)last_index); - -#ifdef DB_FORW_REF - db_forward_references("first hashing"); -#endif /* DB_FORW_REF */ -} - -static size_t -hash1(const Token *p) { - /* hash1(p) returns the hash code of Min_Run_Size - tokens starting at p; caller guarantees that there - are at least Min_Run_Size tokens. - */ - uint64_t h_val; - int n; - - h_val = 0; - for (n = 0; n < N_SAMPLES; n++) { - h_val = (h_val << 2) OPERATION Token2int(p[sample_pos[n]]); - if (h_val & (1ULL<<63)) { - h_val ^= (1ULL<<63|1); - } - } - -#ifdef DB_HASH - /* reduce h_val to the type yielded by hash1(), and print the - result in a responsible way - */ - size_t h = (size_t) (h_val % hash_table_size); - fprintf(Debug_File, "hash1 = %s\n", any_uint2string(h, 0)); -#endif /* DB_HASH */ - - return (size_t) (h_val % hash_table_size); -} - -static size_t hash2(const Token *); - -static void -make_forward_references_hash2(void) { - size_t i; - - /* Clean out spurious matches, by a quadratic algorithm. - Note that we do not want to eliminate overlapping - sequences in this stage, since we might be removing the - wrong copy. - */ - for (i = 0; i+Min_Run_Size < Text_Length(); i++) { - size_t j = i; - size_t h2 = hash2(&Token_Array[i]); - - /* Find the first token sequence in the chain - with same secondary hash code. - */ - while ( /* there is still a forward reference */ - (j = forward_reference[j]) - && /* its hash code does not match */ - hash2(&Token_Array[j]) != h2 - ) { - /* continue searching */ - } - /* short-circuit forward reference to it, or to zero */ - forward_reference[i] = j; - } - -#ifdef DB_FORW_REF - db_forward_references("second hashing"); -#endif /* DB_FORW_REF */ -} - -static size_t -hash2(const Token *p) { - /* A simple-minded hashing for the secondary sweep; - sample first, middle, and last token, and on 64-bit systems - also two tokens from in between these. - */ - int pos_last_sample = N_SAMPLES - 1; - uint64_t h_val = 0; - h_val ^= ((uint64_t)Token2int(p[sample_pos[0]])) << 0; - h_val ^= ((uint64_t)Token2int(p[sample_pos[pos_last_sample]])) << 16; - h_val ^= ((uint64_t)Token2int(p[sample_pos[pos_last_sample/2]])) << 24; - h_val ^= ((uint64_t)Token2int(p[sample_pos[pos_last_sample*1/4]]))<<32; - h_val ^= ((uint64_t)Token2int(p[sample_pos[pos_last_sample*3/4]]))<<48; - /* the last two are ignored on a 32-bit system */ - h_val *= 2147483647; - h_val &= 017777777777; - -#ifdef DB_HASH - /* reduce h_val to the type yielded by hash2(), and print the - result in a responsible way - */ - size_t h = (size_t)h_val; - fprintf(Debug_File, "hash2 = %s\n", any_uint2string(h, 0)); -#endif /* DB_HASH */ - - return (size_t)h_val; -} - -#ifdef DB_FORW_REF - -static int hash3(const Token *, const Token *); - -static void -db_print_forward_references(void) { - size_t n; - size_t *printed_at = - (size_t *)Calloc(Text_Length(), sizeof (size_t)); - - for (n = 1; n < Text_Length(); n++) { - size_t fw = forward_reference[n]; - if (fw == 0) continue; - fprintf(Debug_File, "FWR[%s]:", any_uint2string(n, 0)); - if (printed_at[fw]) { - fprintf(Debug_File, " see %s", - any_uint2string(printed_at[fw], 0)); - } - else { - while (fw) { - fprintf(Debug_File, " %s", - any_uint2string(fw, 0)); - printed_at[fw] = n; - fw = forward_reference[fw]; - } - } - fprintf(Debug_File, "\n"); - } - Free((void *)printed_at); -} - -static void -make_forward_references_hash3(void) { - size_t i; - - /* Do a third hash to check up on the previous two */ - - /* This time we use a genuine compare */ - for (i = 0; i+Min_Run_Size < Text_Length(); i++) { - size_t j = i; - - while ( /* there is still a forward reference */ - (j = forward_reference[j]) - && /* its hash code does not match */ - !hash3(&Token_Array[i], &Token_Array[j]) - ) { - /* continue searching */ - } - /* short-circuit forward reference to it, or to zero */ - forward_reference[i] = j; - } - - db_forward_references("third hashing"); -} - -static int -hash3(const Token *p, const Token *q) { - /* a full comparison for the tertiary sweep */ - size_t n; - - for (n = 0; n < Min_Run_Size; n++) { - if (!Token_EQ(p[n], q[n])) return 0; - } - return 1; -} - -static size_t -db_frw_chain(size_t n, char *crossed_out) { - if (forward_reference[n] == 0) { - fprintf(Debug_File, - ">>>> db_frw_chain() forward_reference[n] == 0 <<<<\n" - ); - return 0; - } - - size_t n_entries = 0; - size_t fw; - - for (fw = n; fw; fw = forward_reference[fw]) { - if (crossed_out[fw]) { - fprintf(Debug_File, - ">>>> error: forward references cross <<<<\n" - ); - } - n_entries++; - crossed_out[fw] = 1; - } - fprintf(Debug_File, "chain_start = %s, n_entries = %s\n", - any_uint2string(n, 0), any_uint2string(n_entries, 0)); - - /* return chain length */ - return n_entries - 1; -} - -static void -db_forward_references(const char *msg) { - size_t n; - size_t n_frw_chains = 0; /* number of forward ref. chains */ - size_t tot_frwc_len = 0; - char *crossed_out; - - fprintf(Debug_File, "\n\n**** DB_FORWARD_REFERENCES, %s ****\n", msg); - fprintf(Debug_File, "hash_table_size = %s\n", - any_uint2string(hash_table_size, 0)); - fprintf(Debug_File, "N_SAMPLES = %d\n", N_SAMPLES); - - crossed_out = (char *)Calloc(Text_Length(), sizeof (char)); - - /* Each forward_reference[n] starts in principle a new - chain, and these chains never touch each other. - We check this property by marking the positions in each - chain in an array; if we meet a marked entry while - following a chain, it must have been on an earlier chain - and we have an error. - We also determine the lengths of the chains, for statistics. - */ - if (forward_reference[0]) { - fprintf(Debug_File, - ">>>> forward_reference[0] is not zero <<<<\n" - ); - } - for (n = 1; n < Text_Length(); n++) { - if (forward_reference[n] && !crossed_out[n]) { - /* start of a new chain */ - n_frw_chains++; - tot_frwc_len += db_frw_chain(n, crossed_out); - } - } - db_print_forward_references(); - - Free((char *)crossed_out); - - fprintf(Debug_File, - "text length = %s, # forward chains = %s, total frw chain length = %s\n\n", - any_uint2string(Text_Length(), 0), - any_uint2string(n_frw_chains, 0), - any_uint2string(tot_frwc_len, 0) - ); -} - -#endif /* DB_FORW_REF */ diff --git a/judger/core/sim/sim_2_77/javalang.c b/judger/core/sim/sim_2_77/javalang.c deleted file mode 100644 index ce3723c8..00000000 --- a/judger/core/sim/sim_2_77/javalang.c +++ /dev/null @@ -1,2191 +0,0 @@ - -#line 3 "" - -#define YY_INT_ALIGNED short int - -/* A lexical scanner generated by flex */ - -#define FLEX_SCANNER -#define YY_FLEX_MAJOR_VERSION 2 -#define YY_FLEX_MINOR_VERSION 6 -#define YY_FLEX_SUBMINOR_VERSION 0 -#if YY_FLEX_SUBMINOR_VERSION > 0 -#define FLEX_BETA -#endif - -/* First, we deal with platform-specific or compiler-specific issues. */ - -/* begin standard C headers. */ -#include -#include -#include -#include - -/* end standard C headers. */ - -/* flex integer type definitions */ - -#ifndef FLEXINT_H -#define FLEXINT_H - -/* C99 systems have . Non-C99 systems may or may not. */ - -#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L - -/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, - * if you want the limit (max/min) macros for int types. - */ -#ifndef __STDC_LIMIT_MACROS -#define __STDC_LIMIT_MACROS 1 -#endif - -#include -typedef int8_t flex_int8_t; -typedef uint8_t flex_uint8_t; -typedef int16_t flex_int16_t; -typedef uint16_t flex_uint16_t; -typedef int32_t flex_int32_t; -typedef uint32_t flex_uint32_t; -#else -typedef signed char flex_int8_t; -typedef short int flex_int16_t; -typedef int flex_int32_t; -typedef unsigned char flex_uint8_t; -typedef unsigned short int flex_uint16_t; -typedef unsigned int flex_uint32_t; - -/* Limits of integral types. */ -#ifndef INT8_MIN -#define INT8_MIN (-128) -#endif -#ifndef INT16_MIN -#define INT16_MIN (-32767-1) -#endif -#ifndef INT32_MIN -#define INT32_MIN (-2147483647-1) -#endif -#ifndef INT8_MAX -#define INT8_MAX (127) -#endif -#ifndef INT16_MAX -#define INT16_MAX (32767) -#endif -#ifndef INT32_MAX -#define INT32_MAX (2147483647) -#endif -#ifndef UINT8_MAX -#define UINT8_MAX (255U) -#endif -#ifndef UINT16_MAX -#define UINT16_MAX (65535U) -#endif -#ifndef UINT32_MAX -#define UINT32_MAX (4294967295U) -#endif - -#endif /* ! C99 */ - -#endif /* ! FLEXINT_H */ - -#ifdef __cplusplus - -/* The "const" storage-class-modifier is valid. */ -#define YY_USE_CONST - -#else /* ! __cplusplus */ - -/* C99 requires __STDC__ to be defined as 1. */ -#if defined (__STDC__) - -#define YY_USE_CONST - -#endif /* defined (__STDC__) */ -#endif /* ! __cplusplus */ - -#ifdef YY_USE_CONST -#define yyconst const -#else -#define yyconst -#endif - -/* Returned upon end-of-file. */ -#define YY_NULL 0 - -/* Promotes a possibly negative, possibly signed char to an unsigned - * integer for use as an array index. If the signed char is negative, - * we want to instead treat it as an 8-bit unsigned char, hence the - * double cast. - */ -#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) - -/* Enter a start condition. This macro really ought to take a parameter, - * but we do it the disgusting crufty way forced on us by the ()-less - * definition of BEGIN. - */ -#define BEGIN (yy_start) = 1 + 2 * - -/* Translate the current start state into a value that can be later handed - * to BEGIN to return to the state. The YYSTATE alias is for lex - * compatibility. - */ -#define YY_START (((yy_start) - 1) / 2) -#define YYSTATE YY_START - -/* Action number for EOF rule of a given start state. */ -#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) - -/* Special action meaning "start processing a new file". */ -#define YY_NEW_FILE yyrestart(yyin ) - -#define YY_END_OF_BUFFER_CHAR 0 - -/* Size of default input buffer. */ -#ifndef YY_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k. - * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. - * Ditto for the __ia64__ case accordingly. - */ -#define YY_BUF_SIZE 32768 -#else -#define YY_BUF_SIZE 16384 -#endif /* __ia64__ */ -#endif - -/* The state buf must be large enough to hold one state per character in the main buffer. - */ -#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) - -#ifndef YY_TYPEDEF_YY_BUFFER_STATE -#define YY_TYPEDEF_YY_BUFFER_STATE -typedef struct yy_buffer_state *YY_BUFFER_STATE; -#endif - -#ifndef YY_TYPEDEF_YY_SIZE_T -#define YY_TYPEDEF_YY_SIZE_T -typedef size_t yy_size_t; -#endif - -extern yy_size_t yyleng; - -extern FILE *yyin, *yyout; - -#define EOB_ACT_CONTINUE_SCAN 0 -#define EOB_ACT_END_OF_FILE 1 -#define EOB_ACT_LAST_MATCH 2 - - #define YY_LESS_LINENO(n) - #define YY_LINENO_REWIND_TO(ptr) - -/* Return all but the first "n" matched characters back to the input stream. */ -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - *yy_cp = (yy_hold_char); \ - YY_RESTORE_YY_MORE_OFFSET \ - (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ - YY_DO_BEFORE_ACTION; /* set up yytext again */ \ - } \ - while ( 0 ) - -#define unput(c) yyunput( c, (yytext_ptr) ) - -#ifndef YY_STRUCT_YY_BUFFER_STATE -#define YY_STRUCT_YY_BUFFER_STATE -struct yy_buffer_state - { - FILE *yy_input_file; - - char *yy_ch_buf; /* input buffer */ - char *yy_buf_pos; /* current position in input buffer */ - - /* Size of input buffer in bytes, not including room for EOB - * characters. - */ - yy_size_t yy_buf_size; - - /* Number of characters read into yy_ch_buf, not including EOB - * characters. - */ - int yy_n_chars; - - /* Whether we "own" the buffer - i.e., we know we created it, - * and can realloc() it to grow it, and should free() it to - * delete it. - */ - int yy_is_our_buffer; - - /* Whether this is an "interactive" input source; if so, and - * if we're using stdio for input, then we want to use getc() - * instead of fread(), to make sure we stop fetching input after - * each newline. - */ - int yy_is_interactive; - - /* Whether we're considered to be at the beginning of a line. - * If so, '^' rules will be active on the next match, otherwise - * not. - */ - int yy_at_bol; - - int yy_bs_lineno; /**< The line count. */ - int yy_bs_column; /**< The column count. */ - - /* Whether to try to fill the input buffer when we reach the - * end of it. - */ - int yy_fill_buffer; - - int yy_buffer_status; - -#define YY_BUFFER_NEW 0 -#define YY_BUFFER_NORMAL 1 - /* When an EOF's been seen but there's still some text to process - * then we mark the buffer as YY_EOF_PENDING, to indicate that we - * shouldn't try reading from the input source any more. We might - * still have a bunch of tokens to match, though, because of - * possible backing-up. - * - * When we actually see the EOF, we change the status to "new" - * (via yyrestart()), so that the user can continue scanning by - * just pointing yyin at a new input file. - */ -#define YY_BUFFER_EOF_PENDING 2 - - }; -#endif /* !YY_STRUCT_YY_BUFFER_STATE */ - -/* Stack of input buffers. */ -static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ -static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ -static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ - -/* We provide macros for accessing buffer states in case in the - * future we want to put the buffer states in a more general - * "scanner state". - * - * Returns the top of the stack, or NULL. - */ -#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ - ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ - : NULL) - -/* Same as previous macro, but useful when we know that the buffer stack is not - * NULL or when we need an lvalue. For internal use only. - */ -#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] - -/* yy_hold_char holds the character lost when yytext is formed. */ -static char yy_hold_char; -static int yy_n_chars; /* number of characters read into yy_ch_buf */ -yy_size_t yyleng; - -/* Points to current character in buffer. */ -static char *yy_c_buf_p = (char *) 0; -static int yy_init = 0; /* whether we need to initialize */ -static int yy_start = 0; /* start state number */ - -/* Flag which is used to allow yywrap()'s to do buffer switches - * instead of setting up a fresh yyin. A bit of a hack ... - */ -static int yy_did_buffer_switch_on_eof; - -void yyrestart (FILE *input_file ); -void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ); -YY_BUFFER_STATE yy_create_buffer (FILE *file,int size ); -void yy_delete_buffer (YY_BUFFER_STATE b ); -void yy_flush_buffer (YY_BUFFER_STATE b ); -void yypush_buffer_state (YY_BUFFER_STATE new_buffer ); -void yypop_buffer_state (void ); - -static void yyensure_buffer_stack (void ); -static void yy_load_buffer_state (void ); -static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file ); - -#define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER ) - -YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ); -YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ); -YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,yy_size_t len ); - -void *yyalloc (yy_size_t ); -void *yyrealloc (void *,yy_size_t ); -void yyfree (void * ); - -#define yy_new_buffer yy_create_buffer - -#define yy_set_interactive(is_interactive) \ - { \ - if ( ! YY_CURRENT_BUFFER ){ \ - yyensure_buffer_stack (); \ - YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer(yyin,YY_BUF_SIZE ); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ - } - -#define yy_set_bol(at_bol) \ - { \ - if ( ! YY_CURRENT_BUFFER ){\ - yyensure_buffer_stack (); \ - YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer(yyin,YY_BUF_SIZE ); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ - } - -#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) - -/* Begin user sect3 */ - -#define yywrap() (/*CONSTCOND*/1) -#define YY_SKIP_YYWRAP - -typedef unsigned char YY_CHAR; - -FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0; - -typedef int yy_state_type; - -extern int yylineno; - -int yylineno = 1; - -extern char *yytext; -#ifdef yytext_ptr -#undef yytext_ptr -#endif -#define yytext_ptr yytext - -static yy_state_type yy_get_previous_state (void ); -static yy_state_type yy_try_NUL_trans (yy_state_type current_state ); -static int yy_get_next_buffer (void ); -#if defined(__GNUC__) && __GNUC__ >= 3 -__attribute__((__noreturn__)) -#endif -static void yy_fatal_error (yyconst char msg[] ); - -/* Done after the current pattern has been matched and before the - * corresponding action - sets up yytext. - */ -#define YY_DO_BEFORE_ACTION \ - (yytext_ptr) = yy_bp; \ - yyleng = (size_t) (yy_cp - yy_bp); \ - (yy_hold_char) = *yy_cp; \ - *yy_cp = '\0'; \ - (yy_c_buf_p) = yy_cp; - -#define YY_NUM_RULES 18 -#define YY_END_OF_BUFFER 19 -/* This struct is not used in this scanner, - but its presence is necessary. */ -struct yy_trans_info - { - flex_int32_t yy_verify; - flex_int32_t yy_nxt; - }; -static yyconst flex_int16_t yy_accept[106] = - { 0, - 0, 0, 0, 0, 19, 17, 15, 14, 15, 16, - 16, 16, 16, 9, 9, 13, 9, 12, 12, 2, - 2, 4, 2, 2, 2, 2, 3, 2, 2, 2, - 2, 2, 2, 2, 0, 7, 0, 0, 0, 1, - 0, 9, 9, 0, 11, 9, 12, 9, 12, 2, - 2, 2, 2, 2, 2, 5, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 0, 8, 0, 0, 6, - 12, 2, 2, 2, 2, 2, 0, 0, 12, 2, - 2, 2, 0, 0, 12, 2, 2, 2, 0, 0, - 12, 2, 2, 2, 0, 0, 0, 2, 2, 2, - - 0, 10, 2, 2, 0 - } ; - -static yyconst YY_CHAR yy_ec[256] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, - 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 4, 5, 6, 5, 5, 5, 5, 7, 8, - 5, 9, 5, 5, 5, 5, 10, 11, 12, 12, - 12, 12, 12, 12, 12, 12, 12, 5, 13, 5, - 5, 5, 5, 5, 14, 14, 14, 14, 14, 14, - 15, 15, 15, 15, 15, 16, 15, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, - 5, 17, 5, 5, 18, 5, 14, 14, 14, 14, - - 14, 14, 15, 15, 19, 15, 15, 20, 21, 15, - 22, 23, 15, 24, 15, 25, 26, 15, 15, 27, - 15, 15, 5, 5, 5, 5, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1 - } ; - -static yyconst YY_CHAR yy_meta[28] = - { 0, - 1, 1, 2, 1, 1, 1, 3, 4, 5, 1, - 4, 4, 1, 4, 4, 4, 1, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4 - } ; - -static yyconst flex_uint16_t yy_base[116] = - { 0, - 0, 0, 27, 0, 220, 334, 334, 334, 334, 334, - 49, 192, 47, 56, 179, 334, 76, 195, 50, 0, - 0, 334, 0, 0, 56, 52, 191, 54, 86, 171, - 0, 113, 130, 176, 68, 334, 169, 72, 68, 334, - 183, 0, 334, 66, 334, 143, 177, 175, 78, 0, - 99, 0, 73, 86, 134, 334, 101, 153, 0, 150, - 0, 0, 0, 0, 156, 159, 334, 170, 166, 334, - 144, 182, 0, 193, 144, 146, 205, 216, 83, 178, - 201, 143, 228, 239, 150, 224, 243, 124, 252, 263, - 170, 248, 267, 107, 139, 105, 135, 271, 275, 205, - - 68, 334, 228, 0, 334, 289, 294, 56, 299, 303, - 308, 313, 318, 323, 328 - } ; - -static yyconst flex_int16_t yy_def[116] = - { 0, - 105, 1, 105, 3, 105, 105, 105, 105, 105, 105, - 106, 107, 105, 105, 14, 105, 108, 108, 108, 109, - 109, 105, 109, 109, 110, 111, 105, 109, 109, 29, - 109, 105, 32, 33, 106, 105, 106, 107, 107, 105, - 112, 15, 105, 105, 105, 108, 108, 108, 108, 109, - 110, 109, 110, 111, 111, 105, 113, 29, 109, 109, - 109, 32, 33, 33, 33, 106, 105, 107, 112, 105, - 108, 110, 109, 111, 113, 33, 106, 107, 108, 72, - 74, 33, 106, 107, 108, 72, 74, 33, 106, 107, - 108, 72, 74, 33, 106, 107, 114, 72, 74, 115, - - 114, 105, 115, 109, 0, 105, 105, 105, 105, 105, - 105, 105, 105, 105, 105 - } ; - -static yyconst flex_uint16_t yy_nxt[362] = - { 0, - 6, 7, 8, 9, 10, 11, 12, 10, 10, 13, - 14, 15, 16, 17, 18, 18, 10, 10, 19, 18, - 18, 18, 18, 18, 18, 18, 18, 20, 21, 22, - 23, 24, 25, 26, 24, 27, 28, 29, 30, 31, - 32, 33, 33, 24, 24, 34, 33, 33, 33, 33, - 33, 33, 33, 33, 36, 40, 41, 45, 50, 47, - 38, 52, 40, 57, 35, 37, 42, 42, 55, 42, - 49, 43, 53, 36, 38, 43, 42, 42, 67, 42, - 102, 35, 44, 45, 37, 45, 46, 46, 39, 46, - 45, 48, 73, 68, 38, 48, 58, 58, 72, 58, - - 71, 59, 55, 70, 52, 59, 85, 35, 100, 69, - 100, 67, 60, 50, 50, 53, 50, 50, 50, 50, - 61, 39, 50, 62, 62, 50, 62, 63, 64, 50, - 63, 63, 64, 63, 63, 63, 63, 63, 63, 63, - 63, 63, 38, 63, 36, 63, 70, 102, 94, 63, - 45, 45, 69, 46, 46, 37, 46, 45, 48, 74, - 58, 58, 48, 58, 36, 79, 88, 82, 70, 77, - 77, 97, 77, 97, 91, 37, 67, 45, 76, 50, - 78, 78, 45, 78, 45, 70, 39, 52, 86, 86, - 35, 86, 80, 80, 66, 80, 65, 50, 53, 73, - - 56, 38, 45, 81, 81, 105, 81, 101, 39, 55, - 36, 87, 87, 101, 87, 83, 83, 104, 83, 105, - 105, 37, 67, 105, 105, 105, 84, 84, 105, 84, - 101, 105, 39, 36, 92, 92, 101, 92, 89, 89, - 104, 89, 105, 105, 37, 67, 105, 105, 105, 90, - 90, 105, 90, 93, 93, 39, 93, 36, 98, 98, - 105, 98, 95, 95, 105, 95, 105, 105, 37, 67, - 105, 105, 105, 96, 96, 105, 96, 99, 99, 39, - 99, 51, 51, 105, 51, 54, 54, 105, 54, 35, - 105, 35, 35, 35, 38, 105, 105, 38, 38, 50, - - 105, 50, 50, 51, 105, 51, 51, 51, 54, 105, - 54, 54, 54, 69, 69, 69, 69, 69, 75, 75, - 75, 75, 75, 101, 101, 101, 101, 101, 103, 103, - 103, 103, 103, 5, 105, 105, 105, 105, 105, 105, - 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, - 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, - 105 - } ; - -static yyconst flex_int16_t yy_chk[362] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 11, 13, 13, 19, 26, 108, - 26, 25, 28, 28, 25, 11, 14, 14, 26, 14, - 19, 14, 25, 35, 39, 14, 44, 44, 38, 44, - 101, 53, 14, 17, 35, 49, 17, 17, 38, 17, - 79, 17, 54, 39, 54, 17, 29, 29, 53, 29, - - 49, 29, 54, 57, 51, 29, 79, 51, 94, 57, - 94, 96, 29, 32, 32, 51, 32, 32, 32, 32, - 32, 96, 32, 32, 32, 32, 32, 32, 32, 32, - 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, - 33, 33, 55, 33, 95, 33, 75, 97, 88, 33, - 46, 71, 75, 46, 46, 95, 46, 85, 46, 55, - 60, 60, 46, 60, 66, 71, 82, 76, 69, 66, - 66, 91, 66, 91, 85, 66, 68, 91, 65, 58, - 68, 68, 48, 68, 47, 41, 68, 72, 80, 80, - 72, 80, 72, 72, 37, 72, 34, 30, 72, 74, - - 27, 74, 18, 74, 74, 15, 74, 100, 12, 74, - 77, 81, 81, 100, 81, 77, 77, 100, 77, 5, - 0, 77, 78, 0, 0, 0, 78, 78, 0, 78, - 103, 0, 78, 83, 86, 86, 103, 86, 83, 83, - 103, 83, 0, 0, 83, 84, 0, 0, 0, 84, - 84, 0, 84, 87, 87, 84, 87, 89, 92, 92, - 0, 92, 89, 89, 0, 89, 0, 0, 89, 90, - 0, 0, 0, 90, 90, 0, 90, 93, 93, 90, - 93, 98, 98, 0, 98, 99, 99, 0, 99, 106, - 0, 106, 106, 106, 107, 0, 0, 107, 107, 109, - - 0, 109, 109, 110, 0, 110, 110, 110, 111, 0, - 111, 111, 111, 112, 112, 112, 112, 112, 113, 113, - 113, 113, 113, 114, 114, 114, 114, 114, 115, 115, - 115, 115, 115, 105, 105, 105, 105, 105, 105, 105, - 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, - 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, - 105 - } ; - -static yy_state_type yy_last_accepting_state; -static char *yy_last_accepting_cpos; - -extern int yy_flex_debug; -int yy_flex_debug = 0; - -/* The intent behind this definition is that it'll catch - * any uses of REJECT which flex missed. - */ -#define REJECT reject_used_but_not_detected -#define yymore() yymore_used_but_not_detected -#define YY_MORE_ADJ 0 -#define YY_RESTORE_YY_MORE_OFFSET -char *yytext; -#line 1 "javalang.l" -#line 2 "javalang.l" -/* This file is part of the software similarity tester SIM. - Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: javalang.l,v 1.14 2013-04-28 16:30:41 Gebruiker Exp $ -*/ - -/* - Java language front end for the similarity tester. - Author: Dick Grune -*/ - -#include "options.h" -#include "token.h" -#include "language.h" -#include "algollike.h" -#include "idf.h" -#include "lex.h" -#include "lang.h" - -/* General language front end data */ -Token lex_token; -size_t lex_nl_cnt; -size_t lex_tk_cnt; -size_t lex_non_ascii_cnt; - -/* Language-dependent data */ - -static const struct idf reserved[] = { - {"abstract", NORM('a')}, - {"boolean", NORM('b')}, - {"break", NORM('B')}, - {"byte", CTRL('B')}, - {"case", NORM('c')}, - {"catch", NORM('C')}, - {"char", CTRL('C')}, - {"class", META('c')}, - {"continue", META('C')}, - {"default", NORM('d')}, - {"do", NORM('D')}, - {"double", CTRL('D')}, - {"else", NORM('e')}, - {"extends", NORM('E')}, - {"false", NORM('g')}, /* Boolean literal */ - {"final", NORM('f')}, - {"finally", NORM('F')}, - {"float", CTRL('F')}, - {"for", META('f')}, - {"if", NORM('i')}, - {"implements", NORM('I')}, - {"import", CTRL('I')}, - {"instanceof", META('i')}, - {"int", META('I')}, - {"interface", MTCT('I')}, - {"long", NORM('l')}, - {"native", NORM('n')}, - {"new", NORM('N')}, - {"null", CTRL('N')}, /* null literal */ - {"package", NORM('p')}, - {"private", NORM('P')}, - {"protected", CTRL('P')}, - {"public", META('p')}, - {"return", NORM('r')}, - {"short", NORM('s')}, - {"static", NORM('S')}, - {"super", CTRL('S')}, - {"switch", META('s')}, - {"synchronized",META('S')}, - {"this", NORM('t')}, - {"throw", NORM('T')}, - {"throws", CTRL('T')}, - {"true", META('t')}, /* Boolean literal */ - {"void", NORM('v')}, - {"volatile", NORM('V')}, - {"while", NORM('w')} -}; - -/* Special treatment of identifiers */ - -static Token -idf2token(int hashing) { - Token tk; - - tk = idf_in_list(yytext, reserved, sizeof reserved, IDF); - if (Token_EQ(tk, IDF) && hashing) { - /* return a one-Token hash code */ - tk = idf_hashed(yytext); - } - return tk; -} - -/* Token sets for module algollike */ -const Token Non_Finals[] = { - IDF, /* identifier */ - NORM('{'), - NORM('('), - NORM('a'), /* abstract */ - NORM('b'), /* boolean */ - NORM('B'), /* break */ - CTRL('B'), /* byte */ - NORM('c'), /* case */ - NORM('C'), /* catch */ - CTRL('C'), /* char */ - META('c'), /* class */ - META('C'), /* continue */ - NORM('d'), /* default */ - NORM('D'), /* do */ - CTRL('D'), /* double */ - NORM('e'), /* else */ - NORM('E'), /* extends */ - NORM('f'), /* final */ - NORM('F'), /* finally */ - CTRL('F'), /* float */ - META('f'), /* for */ - NORM('i'), /* if */ - NORM('I'), /* implements */ - CTRL('I'), /* import */ - META('i'), /* instanceof */ - META('I'), /* int */ - MTCT('I'), /* interface */ - NORM('l'), /* long */ - NORM('n'), /* native */ - NORM('N'), /* new */ - NORM('p'), /* package */ - NORM('P'), /* private */ - CTRL('P'), /* protected */ - META('p'), /* public */ - NORM('r'), /* return */ - NORM('s'), /* short */ - NORM('S'), /* static */ - CTRL('S'), /* super */ - META('s'), /* switch */ - META('S'), /* synchronized */ - NORM('T'), /* throw */ - CTRL('T'), /* throws */ - NORM('v'), /* void */ - NORM('V'), /* volatile */ - NORM('w'), /* while */ - No_Token -}; -const Token Non_Initials[] = { - NORM(')'), - NORM('}'), - NORM(';'), - No_Token -}; -const Token Openers[] = { - NORM('{'), - NORM('('), - NORM('['), - No_Token -}; -const Token Closers[] = { - NORM('}'), - NORM(')'), - NORM(']'), - No_Token -}; - -/* Language-dependent code */ - -void -Init_Language(void) { - Init_Algol_Language(Non_Finals, Non_Initials, Openers, Closers); -} - - -int -May_Be_Start_Of_Run(Token ch) { - return May_Be_Start_Of_Algol_Run(ch); -} - -size_t -Best_Run_Size(const Token *str, size_t size) { - return Best_Algol_Run_Size(str, size); -} - - -#line 760 "" - -#define INITIAL 0 -#define Comment 1 - -#ifndef YY_NO_UNISTD_H -/* Special case for "unistd.h", since it is non-ANSI. We include it way - * down here because we want the user's section 1 to have been scanned first. - * The user has a chance to override it with an option. - */ -#include -#endif - -#ifndef YY_EXTRA_TYPE -#define YY_EXTRA_TYPE void * -#endif - -static int yy_init_globals (void ); - -/* Accessor methods to globals. - These are made visible to non-reentrant scanners for convenience. */ - -int yylex_destroy (void ); - -int yyget_debug (void ); - -void yyset_debug (int debug_flag ); - -YY_EXTRA_TYPE yyget_extra (void ); - -void yyset_extra (YY_EXTRA_TYPE user_defined ); - -FILE *yyget_in (void ); - -void yyset_in (FILE * _in_str ); - -FILE *yyget_out (void ); - -void yyset_out (FILE * _out_str ); - -yy_size_t yyget_leng (void ); - -char *yyget_text (void ); - -int yyget_lineno (void ); - -void yyset_lineno (int _line_number ); - -/* Macros after this point can all be overridden by user definitions in - * section 1. - */ - -#ifndef YY_SKIP_YYWRAP -#ifdef __cplusplus -extern "C" int yywrap (void ); -#else -extern int yywrap (void ); -#endif -#endif - -#ifndef YY_NO_UNPUT - - static void yyunput (int c,char *buf_ptr ); - -#endif - -#ifndef yytext_ptr -static void yy_flex_strncpy (char *,yyconst char *,int ); -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * ); -#endif - -#ifndef YY_NO_INPUT - -#ifdef __cplusplus -static int yyinput (void ); -#else -static int input (void ); -#endif - -#endif - -/* Amount of stuff to slurp up with each read. */ -#ifndef YY_READ_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k */ -#define YY_READ_BUF_SIZE 16384 -#else -#define YY_READ_BUF_SIZE 8192 -#endif /* __ia64__ */ -#endif - -/* Copy whatever the last rule matched to the standard output. */ -#ifndef ECHO -/* This used to be an fputs(), but since the string might contain NUL's, - * we now use fwrite(). - */ -#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0) -#endif - -/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, - * is returned in "result". - */ -#ifndef YY_INPUT -#define YY_INPUT(buf,result,max_size) \ - if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ - { \ - int c = '*'; \ - size_t n; \ - for ( n = 0; n < max_size && \ - (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ - buf[n] = (char) c; \ - if ( c == '\n' ) \ - buf[n++] = (char) c; \ - if ( c == EOF && ferror( yyin ) ) \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - result = n; \ - } \ - else \ - { \ - errno=0; \ - while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \ - { \ - if( errno != EINTR) \ - { \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - break; \ - } \ - errno=0; \ - clearerr(yyin); \ - } \ - }\ -\ - -#endif - -/* No semi-colon after return; correct usage is to write "yyterminate();" - - * we don't want an extra ';' after the "return" because that will cause - * some compilers to complain about unreachable statements. - */ -#ifndef yyterminate -#define yyterminate() return YY_NULL -#endif - -/* Number of entries by which start-condition stack grows. */ -#ifndef YY_START_STACK_INCR -#define YY_START_STACK_INCR 25 -#endif - -/* Report a fatal error. */ -#ifndef YY_FATAL_ERROR -#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) -#endif - -/* end tables serialization structures and prototypes */ - -/* Default declaration of generated scanner - a define so the user can - * easily add parameters. - */ -#ifndef YY_DECL -#define YY_DECL_IS_OURS 1 - -extern int yylex (void); - -#define YY_DECL int yylex (void) -#endif /* !YY_DECL */ - -/* Code executed at the beginning of each rule, after yytext and yyleng - * have been set up. - */ -#ifndef YY_USER_ACTION -#define YY_USER_ACTION -#endif - -/* Code executed at the end of each rule. */ -#ifndef YY_BREAK -#define YY_BREAK /*LINTED*/break; -#endif - -#define YY_RULE_SETUP \ - YY_USER_ACTION - -/** The main scanner function which does all the work. - */ -YY_DECL -{ - yy_state_type yy_current_state; - char *yy_cp, *yy_bp; - int yy_act; - - if ( !(yy_init) ) - { - (yy_init) = 1; - -#ifdef YY_USER_INIT - YY_USER_INIT; -#endif - - if ( ! (yy_start) ) - (yy_start) = 1; /* first start state */ - - if ( ! yyin ) - yyin = stdin; - - if ( ! yyout ) - yyout = stdout; - - if ( ! YY_CURRENT_BUFFER ) { - yyensure_buffer_stack (); - YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer(yyin,YY_BUF_SIZE ); - } - - yy_load_buffer_state( ); - } - - { -#line 202 "javalang.l" - - -#line 982 "" - - while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ - { - yy_cp = (yy_c_buf_p); - - /* Support of yytext. */ - *yy_cp = (yy_hold_char); - - /* yy_bp points to the position in yy_ch_buf of the start of - * the current run. - */ - yy_bp = yy_cp; - - yy_current_state = (yy_start); -yy_match: - do - { - YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 106 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - ++yy_cp; - } - while ( yy_base[yy_current_state] != 334 ); - -yy_find_action: - yy_act = yy_accept[yy_current_state]; - if ( yy_act == 0 ) - { /* have to back up */ - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - yy_act = yy_accept[yy_current_state]; - } - - YY_DO_BEFORE_ACTION; - -do_action: /* This label is used only to access EOF actions. */ - - switch ( yy_act ) - { /* beginning of action switch */ - case 0: /* must back up */ - /* undo the effects of YY_DO_BEFORE_ACTION */ - *yy_cp = (yy_hold_char); - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - goto yy_find_action; - -case 1: -YY_RULE_SETUP -#line 204 "javalang.l" -{ - /* We do not have one single pattern to match a comment - (although one can be written), for two reasons. - The matched string might overflow lex-internal buffers - like yysbuf and yytext; and the pattern would be very - complicated and overtax lex. - So we break up the string into safe chunks and keep - track of where we are in a start condition . - */ - BEGIN Comment; - } - YY_BREAK -case 2: -YY_RULE_SETUP -#line 216 "javalang.l" -{ /* safe comment chunk */ - } - YY_BREAK -case 3: -YY_RULE_SETUP -#line 219 "javalang.l" -{ /* unsafe char, read one by one */ - } - YY_BREAK -case 4: -/* rule 4 can match eol */ -YY_RULE_SETUP -#line 222 "javalang.l" -{ /* to break up long comments */ - return_eol(); - } - YY_BREAK -case 5: -YY_RULE_SETUP -#line 226 "javalang.l" -{ /* end-of-comment */ - BEGIN INITIAL; - } - YY_BREAK -case 6: -/* rule 6 can match eol */ -YY_RULE_SETUP -#line 230 "javalang.l" -{ /* single-line comment */ - return_eol(); - } - YY_BREAK -case 7: -YY_RULE_SETUP -#line 234 "javalang.l" -{ /* strings */ - return_ch('"'); - } - YY_BREAK -case 8: -YY_RULE_SETUP -#line 238 "javalang.l" -{ /* characters */ - return_ch('\''); - } - YY_BREAK -case 9: -YY_RULE_SETUP -#line 242 "javalang.l" -{ /* numeral, passed as an identifier */ - return_tk(IDF); - } - YY_BREAK -case 10: -/* rule 10 can match eol */ -YY_RULE_SETUP -#line 246 "javalang.l" -{ /* import statement; ignore */ - } - YY_BREAK -case 11: -*yy_cp = (yy_hold_char); /* undo effects of setting up yytext */ -(yy_c_buf_p) = yy_cp -= 1; -YY_DO_BEFORE_ACTION; /* set up yytext again */ -YY_RULE_SETUP -#line 249 "javalang.l" -{ /* identifier in front of ( */ - Token tk; - - tk = idf2token(is_set_option('F')); - if (!Token_EQ(tk, No_Token)) return_tk(tk); - } - YY_BREAK -case 12: -YY_RULE_SETUP -#line 256 "javalang.l" -{ /* identifier */ - Token tk; - - tk = idf2token(0 /* no hashing */); - if (!Token_EQ(tk, No_Token)) return_tk(tk); - } - YY_BREAK -case 13: -YY_RULE_SETUP -#line 263 "javalang.l" -{ /* semicolon, conditionally ignored */ - if (is_set_option('f')) return_ch(yytext[0]); - } - YY_BREAK -case 14: -/* rule 14 can match eol */ -YY_RULE_SETUP -#line 267 "javalang.l" -{ /* count newlines */ - return_eol(); - } - YY_BREAK -case 15: -YY_RULE_SETUP -#line 271 "javalang.l" -{ /* ignore layout */ - } - YY_BREAK -case 16: -YY_RULE_SETUP -#line 274 "javalang.l" -{ /* copy other text */ - return_ch(yytext[0]); - } - YY_BREAK -case 17: -YY_RULE_SETUP -#line 278 "javalang.l" -{ /* count non-ASCII chars */ - lex_non_ascii_cnt++; - } - YY_BREAK -case 18: -YY_RULE_SETUP -#line 282 "javalang.l" -ECHO; - YY_BREAK -#line 1180 "" -case YY_STATE_EOF(INITIAL): -case YY_STATE_EOF(Comment): - yyterminate(); - - case YY_END_OF_BUFFER: - { - /* Amount of text matched not including the EOB char. */ - int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; - - /* Undo the effects of YY_DO_BEFORE_ACTION. */ - *yy_cp = (yy_hold_char); - YY_RESTORE_YY_MORE_OFFSET - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) - { - /* We're scanning a new file or input source. It's - * possible that this happened because the user - * just pointed yyin at a new source and called - * yylex(). If so, then we have to assure - * consistency between YY_CURRENT_BUFFER and our - * globals. Here is the right place to do so, because - * this is the first action (other than possibly a - * back-up) that will match for the new input source. - */ - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; - } - - /* Note that here we test for yy_c_buf_p "<=" to the position - * of the first EOB in the buffer, since yy_c_buf_p will - * already have been incremented past the NUL character - * (since all states make transitions on EOB to the - * end-of-buffer state). Contrast this with the test - * in input(). - */ - if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) - { /* This was really a NUL. */ - yy_state_type yy_next_state; - - (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( ); - - /* Okay, we're now positioned to make the NUL - * transition. We couldn't have - * yy_get_previous_state() go ahead and do it - * for us because it doesn't know how to deal - * with the possibility of jamming (and we don't - * want to build jamming into it because then it - * will run more slowly). - */ - - yy_next_state = yy_try_NUL_trans( yy_current_state ); - - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - - if ( yy_next_state ) - { - /* Consume the NUL. */ - yy_cp = ++(yy_c_buf_p); - yy_current_state = yy_next_state; - goto yy_match; - } - - else - { - yy_cp = (yy_c_buf_p); - goto yy_find_action; - } - } - - else switch ( yy_get_next_buffer( ) ) - { - case EOB_ACT_END_OF_FILE: - { - (yy_did_buffer_switch_on_eof) = 0; - - if ( yywrap( ) ) - { - /* Note: because we've taken care in - * yy_get_next_buffer() to have set up - * yytext, we can now set up - * yy_c_buf_p so that if some total - * hoser (like flex itself) wants to - * call the scanner after we return the - * YY_NULL, it'll still work - another - * YY_NULL will get returned. - */ - (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; - - yy_act = YY_STATE_EOF(YY_START); - goto do_action; - } - - else - { - if ( ! (yy_did_buffer_switch_on_eof) ) - YY_NEW_FILE; - } - break; - } - - case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = - (yytext_ptr) + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( ); - - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - goto yy_match; - - case EOB_ACT_LAST_MATCH: - (yy_c_buf_p) = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; - - yy_current_state = yy_get_previous_state( ); - - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - goto yy_find_action; - } - break; - } - - default: - YY_FATAL_ERROR( - "fatal flex scanner internal error--no action found" ); - } /* end of action switch */ - } /* end of scanning one token */ - } /* end of user's declarations */ -} /* end of yylex */ - -/* yy_get_next_buffer - try to read in a new buffer - * - * Returns a code representing an action: - * EOB_ACT_LAST_MATCH - - * EOB_ACT_CONTINUE_SCAN - continue scanning from current position - * EOB_ACT_END_OF_FILE - end of file - */ -static int yy_get_next_buffer (void) -{ - char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; - char *source = (yytext_ptr); - yy_size_t number_to_move, i; - int ret_val; - - if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) - YY_FATAL_ERROR( - "fatal flex scanner internal error--end of buffer missed" ); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) - { /* Don't try to fill the buffer, so this is an EOF. */ - if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) - { - /* We matched a single character, the EOB, so - * treat this as a final EOF. - */ - return EOB_ACT_END_OF_FILE; - } - - else - { - /* We matched some text prior to the EOB, first - * process it. - */ - return EOB_ACT_LAST_MATCH; - } - } - - /* Try to read more data. */ - - /* First move last chars to start of buffer. */ - number_to_move = (yy_size_t) ((yy_c_buf_p) - (yytext_ptr)) - 1; - - for ( i = 0; i < number_to_move; ++i ) - *(dest++) = *(source++); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) - /* don't do the read, it's not guaranteed to return an EOF, - * just force an EOF - */ - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; - - else - { - yy_size_t num_to_read = - YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; - - while ( num_to_read <= 0 ) - { /* Not enough room in the buffer - grow it. */ - - /* just a shorter name for the current buffer */ - YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; - - int yy_c_buf_p_offset = - (int) ((yy_c_buf_p) - b->yy_ch_buf); - - if ( b->yy_is_our_buffer ) - { - yy_size_t new_size = b->yy_buf_size * 2; - - if ( new_size <= 0 ) - b->yy_buf_size += b->yy_buf_size / 8; - else - b->yy_buf_size *= 2; - - b->yy_ch_buf = (char *) - /* Include room in for 2 EOB chars. */ - yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ); - } - else - /* Can't grow it, we don't own it. */ - b->yy_ch_buf = 0; - - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( - "fatal error - scanner input buffer overflow" ); - - (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; - - num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - - number_to_move - 1; - - } - - if ( num_to_read > YY_READ_BUF_SIZE ) - num_to_read = YY_READ_BUF_SIZE; - - /* Read in more data. */ - YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), - (yy_n_chars), num_to_read ); - - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - if ( (yy_n_chars) == 0 ) - { - if ( number_to_move == YY_MORE_ADJ ) - { - ret_val = EOB_ACT_END_OF_FILE; - yyrestart(yyin ); - } - - else - { - ret_val = EOB_ACT_LAST_MATCH; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = - YY_BUFFER_EOF_PENDING; - } - } - - else - ret_val = EOB_ACT_CONTINUE_SCAN; - - if ((int) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { - /* Extend the array by 50%, plus the number we really need. */ - int new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ); - if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); - } - - (yy_n_chars) += number_to_move; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; - - (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; - - return ret_val; -} - -/* yy_get_previous_state - get the state just before the EOB char was reached */ - - static yy_state_type yy_get_previous_state (void) -{ - yy_state_type yy_current_state; - char *yy_cp; - - yy_current_state = (yy_start); - - for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) - { - YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 106 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - } - - return yy_current_state; -} - -/* yy_try_NUL_trans - try to make a transition on the NUL character - * - * synopsis - * next_state = yy_try_NUL_trans( current_state ); - */ - static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) -{ - int yy_is_jam; - char *yy_cp = (yy_c_buf_p); - - YY_CHAR yy_c = 1; - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 106 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - yy_is_jam = (yy_current_state == 105); - - return yy_is_jam ? 0 : yy_current_state; -} - -#ifndef YY_NO_UNPUT - - static void yyunput (int c, char * yy_bp ) -{ - char *yy_cp; - - yy_cp = (yy_c_buf_p); - - /* undo effects of setting up yytext */ - *yy_cp = (yy_hold_char); - - if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) - { /* need to shift things up to make room */ - /* +2 for EOB chars. */ - yy_size_t number_to_move = (yy_n_chars) + 2; - char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ - YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; - char *source = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; - - while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) - *--dest = *--source; - - yy_cp += (int) (dest - source); - yy_bp += (int) (dest - source); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size; - - if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) - YY_FATAL_ERROR( "flex scanner push-back overflow" ); - } - - *--yy_cp = (char) c; - - (yytext_ptr) = yy_bp; - (yy_hold_char) = *yy_cp; - (yy_c_buf_p) = yy_cp; -} - -#endif - -#ifndef YY_NO_INPUT -#ifdef __cplusplus - static int yyinput (void) -#else - static int input (void) -#endif - -{ - int c; - - *(yy_c_buf_p) = (yy_hold_char); - - if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) - { - /* yy_c_buf_p now points to the character we want to return. - * If this occurs *before* the EOB characters, then it's a - * valid NUL; if not, then we've hit the end of the buffer. - */ - if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) - /* This was really a NUL. */ - *(yy_c_buf_p) = '\0'; - - else - { /* need more input */ - yy_size_t offset = (yy_c_buf_p) - (yytext_ptr); - ++(yy_c_buf_p); - - switch ( yy_get_next_buffer( ) ) - { - case EOB_ACT_LAST_MATCH: - /* This happens because yy_g_n_b() - * sees that we've accumulated a - * token and flags that we need to - * try matching the token before - * proceeding. But for input(), - * there's no matching to consider. - * So convert the EOB_ACT_LAST_MATCH - * to EOB_ACT_END_OF_FILE. - */ - - /* Reset buffer status. */ - yyrestart(yyin ); - - /*FALLTHROUGH*/ - - case EOB_ACT_END_OF_FILE: - { - if ( yywrap( ) ) - return EOF; - - if ( ! (yy_did_buffer_switch_on_eof) ) - YY_NEW_FILE; -#ifdef __cplusplus - return yyinput(); -#else - return input(); -#endif - } - - case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = (yytext_ptr) + offset; - break; - } - } - } - - c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ - *(yy_c_buf_p) = '\0'; /* preserve yytext */ - (yy_hold_char) = *++(yy_c_buf_p); - - return c; -} -#endif /* ifndef YY_NO_INPUT */ - -/** Immediately switch to a different input stream. - * @param input_file A readable stream. - * - * @note This function does not reset the start condition to @c INITIAL . - */ - void yyrestart (FILE * input_file ) -{ - - if ( ! YY_CURRENT_BUFFER ){ - yyensure_buffer_stack (); - YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer(yyin,YY_BUF_SIZE ); - } - - yy_init_buffer(YY_CURRENT_BUFFER,input_file ); - yy_load_buffer_state( ); -} - -/** Switch to a different input buffer. - * @param new_buffer The new input buffer. - * - */ - void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) -{ - - /* TODO. We should be able to replace this entire function body - * with - * yypop_buffer_state(); - * yypush_buffer_state(new_buffer); - */ - yyensure_buffer_stack (); - if ( YY_CURRENT_BUFFER == new_buffer ) - return; - - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - YY_CURRENT_BUFFER_LVALUE = new_buffer; - yy_load_buffer_state( ); - - /* We don't actually know whether we did this switch during - * EOF (yywrap()) processing, but the only time this flag - * is looked at is after yywrap() is called, so it's safe - * to go ahead and always set it. - */ - (yy_did_buffer_switch_on_eof) = 1; -} - -static void yy_load_buffer_state (void) -{ - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; - yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; - (yy_hold_char) = *(yy_c_buf_p); -} - -/** Allocate and initialize an input buffer state. - * @param file A readable stream. - * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. - * - * @return the allocated buffer state. - */ - YY_BUFFER_STATE yy_create_buffer (FILE * file, int size ) -{ - YY_BUFFER_STATE b; - - b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - - b->yy_buf_size = (yy_size_t)size; - - /* yy_ch_buf has to be 2 characters longer than the size given because - * we need to put in 2 end-of-buffer characters. - */ - b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 ); - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - - b->yy_is_our_buffer = 1; - - yy_init_buffer(b,file ); - - return b; -} - -/** Destroy the buffer. - * @param b a buffer created with yy_create_buffer() - * - */ - void yy_delete_buffer (YY_BUFFER_STATE b ) -{ - - if ( ! b ) - return; - - if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ - YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; - - if ( b->yy_is_our_buffer ) - yyfree((void *) b->yy_ch_buf ); - - yyfree((void *) b ); -} - -/* Initializes or reinitializes a buffer. - * This function is sometimes called more than once on the same buffer, - * such as during a yyrestart() or at EOF. - */ - static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file ) - -{ - int oerrno = errno; - - yy_flush_buffer(b ); - - b->yy_input_file = file; - b->yy_fill_buffer = 1; - - /* If b is the current buffer, then yy_init_buffer was _probably_ - * called from yyrestart() or through yy_get_next_buffer. - * In that case, we don't want to reset the lineno or column. - */ - if (b != YY_CURRENT_BUFFER){ - b->yy_bs_lineno = 1; - b->yy_bs_column = 0; - } - - b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; - - errno = oerrno; -} - -/** Discard all buffered characters. On the next scan, YY_INPUT will be called. - * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. - * - */ - void yy_flush_buffer (YY_BUFFER_STATE b ) -{ - if ( ! b ) - return; - - b->yy_n_chars = 0; - - /* We always need two end-of-buffer characters. The first causes - * a transition to the end-of-buffer state. The second causes - * a jam in that state. - */ - b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; - b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; - - b->yy_buf_pos = &b->yy_ch_buf[0]; - - b->yy_at_bol = 1; - b->yy_buffer_status = YY_BUFFER_NEW; - - if ( b == YY_CURRENT_BUFFER ) - yy_load_buffer_state( ); -} - -/** Pushes the new state onto the stack. The new state becomes - * the current state. This function will allocate the stack - * if necessary. - * @param new_buffer The new state. - * - */ -void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) -{ - if (new_buffer == NULL) - return; - - yyensure_buffer_stack(); - - /* This block is copied from yy_switch_to_buffer. */ - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - /* Only push if top exists. Otherwise, replace top. */ - if (YY_CURRENT_BUFFER) - (yy_buffer_stack_top)++; - YY_CURRENT_BUFFER_LVALUE = new_buffer; - - /* copied from yy_switch_to_buffer. */ - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; -} - -/** Removes and deletes the top of the stack, if present. - * The next element becomes the new top. - * - */ -void yypop_buffer_state (void) -{ - if (!YY_CURRENT_BUFFER) - return; - - yy_delete_buffer(YY_CURRENT_BUFFER ); - YY_CURRENT_BUFFER_LVALUE = NULL; - if ((yy_buffer_stack_top) > 0) - --(yy_buffer_stack_top); - - if (YY_CURRENT_BUFFER) { - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; - } -} - -/* Allocates the stack if it does not exist. - * Guarantees space for at least one push. - */ -static void yyensure_buffer_stack (void) -{ - yy_size_t num_to_alloc; - - if (!(yy_buffer_stack)) { - - /* First allocation is just for 2 elements, since we don't know if this - * scanner will even need a stack. We use 2 instead of 1 to avoid an - * immediate realloc on the next call. - */ - num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ - (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc - (num_to_alloc * sizeof(struct yy_buffer_state*) - ); - if ( ! (yy_buffer_stack) ) - YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); - - memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); - - (yy_buffer_stack_max) = num_to_alloc; - (yy_buffer_stack_top) = 0; - return; - } - - if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ - - /* Increase the buffer to prepare for a possible push. */ - yy_size_t grow_size = 8 /* arbitrary grow size */; - - num_to_alloc = (yy_buffer_stack_max) + grow_size; - (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc - ((yy_buffer_stack), - num_to_alloc * sizeof(struct yy_buffer_state*) - ); - if ( ! (yy_buffer_stack) ) - YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); - - /* zero only the new slots.*/ - memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); - (yy_buffer_stack_max) = num_to_alloc; - } -} - -/** Setup the input buffer state to scan directly from a user-specified character buffer. - * @param base the character buffer - * @param size the size in bytes of the character buffer - * - * @return the newly allocated buffer state object. - */ -YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) -{ - YY_BUFFER_STATE b; - - if ( size < 2 || - base[size-2] != YY_END_OF_BUFFER_CHAR || - base[size-1] != YY_END_OF_BUFFER_CHAR ) - /* They forgot to leave room for the EOB's. */ - return 0; - - b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); - - b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ - b->yy_buf_pos = b->yy_ch_buf = base; - b->yy_is_our_buffer = 0; - b->yy_input_file = 0; - b->yy_n_chars = b->yy_buf_size; - b->yy_is_interactive = 0; - b->yy_at_bol = 1; - b->yy_fill_buffer = 0; - b->yy_buffer_status = YY_BUFFER_NEW; - - yy_switch_to_buffer(b ); - - return b; -} - -/** Setup the input buffer state to scan a string. The next call to yylex() will - * scan from a @e copy of @a str. - * @param yystr a NUL-terminated string to scan - * - * @return the newly allocated buffer state object. - * @note If you want to scan bytes that may contain NUL values, then use - * yy_scan_bytes() instead. - */ -YY_BUFFER_STATE yy_scan_string (yyconst char * yystr ) -{ - - return yy_scan_bytes(yystr,strlen(yystr) ); -} - -/** Setup the input buffer state to scan the given bytes. The next call to yylex() will - * scan from a @e copy of @a bytes. - * @param yybytes the byte buffer to scan - * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. - * - * @return the newly allocated buffer state object. - */ -YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len ) -{ - YY_BUFFER_STATE b; - char *buf; - yy_size_t n; - yy_size_t i; - - /* Get memory for full buffer, including space for trailing EOB's. */ - n = _yybytes_len + 2; - buf = (char *) yyalloc(n ); - if ( ! buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); - - for ( i = 0; i < _yybytes_len; ++i ) - buf[i] = yybytes[i]; - - buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; - - b = yy_scan_buffer(buf,n ); - if ( ! b ) - YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); - - /* It's okay to grow etc. this buffer, and we should throw it - * away when we're done. - */ - b->yy_is_our_buffer = 1; - - return b; -} - -#ifndef YY_EXIT_FAILURE -#define YY_EXIT_FAILURE 2 -#endif - -static void yy_fatal_error (yyconst char* msg ) -{ - (void) fprintf( stderr, "%s\n", msg ); - exit( YY_EXIT_FAILURE ); -} - -/* Redefine yyless() so it works in section 3 code. */ - -#undef yyless -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - yytext[yyleng] = (yy_hold_char); \ - (yy_c_buf_p) = yytext + yyless_macro_arg; \ - (yy_hold_char) = *(yy_c_buf_p); \ - *(yy_c_buf_p) = '\0'; \ - yyleng = yyless_macro_arg; \ - } \ - while ( 0 ) - -/* Accessor methods (get/set functions) to struct members. */ - -/** Get the current line number. - * - */ -int yyget_lineno (void) -{ - - return yylineno; -} - -/** Get the input stream. - * - */ -FILE *yyget_in (void) -{ - return yyin; -} - -/** Get the output stream. - * - */ -FILE *yyget_out (void) -{ - return yyout; -} - -/** Get the length of the current token. - * - */ -yy_size_t yyget_leng (void) -{ - return yyleng; -} - -/** Get the current token. - * - */ - -char *yyget_text (void) -{ - return yytext; -} - -/** Set the current line number. - * @param _line_number line number - * - */ -void yyset_lineno (int _line_number ) -{ - - yylineno = _line_number; -} - -/** Set the input stream. This does not discard the current - * input buffer. - * @param _in_str A readable stream. - * - * @see yy_switch_to_buffer - */ -void yyset_in (FILE * _in_str ) -{ - yyin = _in_str ; -} - -void yyset_out (FILE * _out_str ) -{ - yyout = _out_str ; -} - -int yyget_debug (void) -{ - return yy_flex_debug; -} - -void yyset_debug (int _bdebug ) -{ - yy_flex_debug = _bdebug ; -} - -static int yy_init_globals (void) -{ - /* Initialization is the same as for the non-reentrant scanner. - * This function is called from yylex_destroy(), so don't allocate here. - */ - - (yy_buffer_stack) = 0; - (yy_buffer_stack_top) = 0; - (yy_buffer_stack_max) = 0; - (yy_c_buf_p) = (char *) 0; - (yy_init) = 0; - (yy_start) = 0; - -/* Defined in main.c */ -#ifdef YY_STDINIT - yyin = stdin; - yyout = stdout; -#else - yyin = (FILE *) 0; - yyout = (FILE *) 0; -#endif - - /* For future reference: Set errno on error, since we are called by - * yylex_init() - */ - return 0; -} - -/* yylex_destroy is for both reentrant and non-reentrant scanners. */ -int yylex_destroy (void) -{ - - /* Pop the buffer stack, destroying each element. */ - while(YY_CURRENT_BUFFER){ - yy_delete_buffer(YY_CURRENT_BUFFER ); - YY_CURRENT_BUFFER_LVALUE = NULL; - yypop_buffer_state(); - } - - /* Destroy the stack itself. */ - yyfree((yy_buffer_stack) ); - (yy_buffer_stack) = NULL; - - /* Reset the globals. This is important in a non-reentrant scanner so the next time - * yylex() is called, initialization will occur. */ - yy_init_globals( ); - - return 0; -} - -/* - * Internal utility routines. - */ - -#ifndef yytext_ptr -static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) -{ - - int i; - for ( i = 0; i < n; ++i ) - s1[i] = s2[i]; -} -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * s ) -{ - int n; - for ( n = 0; s[n]; ++n ) - ; - - return n; -} -#endif - -void *yyalloc (yy_size_t size ) -{ - return (void *) malloc( size ); -} - -void *yyrealloc (void * ptr, yy_size_t size ) -{ - - /* The cast to (char *) in the following accommodates both - * implementations that use char* generic pointers, and those - * that use void* generic pointers. It works with the latter - * because both ANSI C and C++ allow castless assignment from - * any pointer type to void*, and deal with argument conversions - * as though doing an assignment. - */ - return (void *) realloc( (char *) ptr, size ); -} - -void yyfree (void * ptr ) -{ - free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ -} - -#define YYTABLES_NAME "yytables" - -#line 282 "javalang.l" - - - -/* More language-dependent code */ - -void -yystart(void) { - BEGIN INITIAL; -} - diff --git a/judger/core/sim/sim_2_77/lisplang.c b/judger/core/sim/sim_2_77/lisplang.c deleted file mode 100644 index 0b3edee0..00000000 --- a/judger/core/sim/sim_2_77/lisplang.c +++ /dev/null @@ -1,1927 +0,0 @@ - -#line 3 "" - -#define YY_INT_ALIGNED short int - -/* A lexical scanner generated by flex */ - -#define FLEX_SCANNER -#define YY_FLEX_MAJOR_VERSION 2 -#define YY_FLEX_MINOR_VERSION 6 -#define YY_FLEX_SUBMINOR_VERSION 0 -#if YY_FLEX_SUBMINOR_VERSION > 0 -#define FLEX_BETA -#endif - -/* First, we deal with platform-specific or compiler-specific issues. */ - -/* begin standard C headers. */ -#include -#include -#include -#include - -/* end standard C headers. */ - -/* flex integer type definitions */ - -#ifndef FLEXINT_H -#define FLEXINT_H - -/* C99 systems have . Non-C99 systems may or may not. */ - -#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L - -/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, - * if you want the limit (max/min) macros for int types. - */ -#ifndef __STDC_LIMIT_MACROS -#define __STDC_LIMIT_MACROS 1 -#endif - -#include -typedef int8_t flex_int8_t; -typedef uint8_t flex_uint8_t; -typedef int16_t flex_int16_t; -typedef uint16_t flex_uint16_t; -typedef int32_t flex_int32_t; -typedef uint32_t flex_uint32_t; -#else -typedef signed char flex_int8_t; -typedef short int flex_int16_t; -typedef int flex_int32_t; -typedef unsigned char flex_uint8_t; -typedef unsigned short int flex_uint16_t; -typedef unsigned int flex_uint32_t; - -/* Limits of integral types. */ -#ifndef INT8_MIN -#define INT8_MIN (-128) -#endif -#ifndef INT16_MIN -#define INT16_MIN (-32767-1) -#endif -#ifndef INT32_MIN -#define INT32_MIN (-2147483647-1) -#endif -#ifndef INT8_MAX -#define INT8_MAX (127) -#endif -#ifndef INT16_MAX -#define INT16_MAX (32767) -#endif -#ifndef INT32_MAX -#define INT32_MAX (2147483647) -#endif -#ifndef UINT8_MAX -#define UINT8_MAX (255U) -#endif -#ifndef UINT16_MAX -#define UINT16_MAX (65535U) -#endif -#ifndef UINT32_MAX -#define UINT32_MAX (4294967295U) -#endif - -#endif /* ! C99 */ - -#endif /* ! FLEXINT_H */ - -#ifdef __cplusplus - -/* The "const" storage-class-modifier is valid. */ -#define YY_USE_CONST - -#else /* ! __cplusplus */ - -/* C99 requires __STDC__ to be defined as 1. */ -#if defined (__STDC__) - -#define YY_USE_CONST - -#endif /* defined (__STDC__) */ -#endif /* ! __cplusplus */ - -#ifdef YY_USE_CONST -#define yyconst const -#else -#define yyconst -#endif - -/* Returned upon end-of-file. */ -#define YY_NULL 0 - -/* Promotes a possibly negative, possibly signed char to an unsigned - * integer for use as an array index. If the signed char is negative, - * we want to instead treat it as an 8-bit unsigned char, hence the - * double cast. - */ -#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) - -/* Enter a start condition. This macro really ought to take a parameter, - * but we do it the disgusting crufty way forced on us by the ()-less - * definition of BEGIN. - */ -#define BEGIN (yy_start) = 1 + 2 * - -/* Translate the current start state into a value that can be later handed - * to BEGIN to return to the state. The YYSTATE alias is for lex - * compatibility. - */ -#define YY_START (((yy_start) - 1) / 2) -#define YYSTATE YY_START - -/* Action number for EOF rule of a given start state. */ -#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) - -/* Special action meaning "start processing a new file". */ -#define YY_NEW_FILE yyrestart(yyin ) - -#define YY_END_OF_BUFFER_CHAR 0 - -/* Size of default input buffer. */ -#ifndef YY_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k. - * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. - * Ditto for the __ia64__ case accordingly. - */ -#define YY_BUF_SIZE 32768 -#else -#define YY_BUF_SIZE 16384 -#endif /* __ia64__ */ -#endif - -/* The state buf must be large enough to hold one state per character in the main buffer. - */ -#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) - -#ifndef YY_TYPEDEF_YY_BUFFER_STATE -#define YY_TYPEDEF_YY_BUFFER_STATE -typedef struct yy_buffer_state *YY_BUFFER_STATE; -#endif - -#ifndef YY_TYPEDEF_YY_SIZE_T -#define YY_TYPEDEF_YY_SIZE_T -typedef size_t yy_size_t; -#endif - -extern yy_size_t yyleng; - -extern FILE *yyin, *yyout; - -#define EOB_ACT_CONTINUE_SCAN 0 -#define EOB_ACT_END_OF_FILE 1 -#define EOB_ACT_LAST_MATCH 2 - - #define YY_LESS_LINENO(n) - #define YY_LINENO_REWIND_TO(ptr) - -/* Return all but the first "n" matched characters back to the input stream. */ -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - *yy_cp = (yy_hold_char); \ - YY_RESTORE_YY_MORE_OFFSET \ - (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ - YY_DO_BEFORE_ACTION; /* set up yytext again */ \ - } \ - while ( 0 ) - -#define unput(c) yyunput( c, (yytext_ptr) ) - -#ifndef YY_STRUCT_YY_BUFFER_STATE -#define YY_STRUCT_YY_BUFFER_STATE -struct yy_buffer_state - { - FILE *yy_input_file; - - char *yy_ch_buf; /* input buffer */ - char *yy_buf_pos; /* current position in input buffer */ - - /* Size of input buffer in bytes, not including room for EOB - * characters. - */ - yy_size_t yy_buf_size; - - /* Number of characters read into yy_ch_buf, not including EOB - * characters. - */ - int yy_n_chars; - - /* Whether we "own" the buffer - i.e., we know we created it, - * and can realloc() it to grow it, and should free() it to - * delete it. - */ - int yy_is_our_buffer; - - /* Whether this is an "interactive" input source; if so, and - * if we're using stdio for input, then we want to use getc() - * instead of fread(), to make sure we stop fetching input after - * each newline. - */ - int yy_is_interactive; - - /* Whether we're considered to be at the beginning of a line. - * If so, '^' rules will be active on the next match, otherwise - * not. - */ - int yy_at_bol; - - int yy_bs_lineno; /**< The line count. */ - int yy_bs_column; /**< The column count. */ - - /* Whether to try to fill the input buffer when we reach the - * end of it. - */ - int yy_fill_buffer; - - int yy_buffer_status; - -#define YY_BUFFER_NEW 0 -#define YY_BUFFER_NORMAL 1 - /* When an EOF's been seen but there's still some text to process - * then we mark the buffer as YY_EOF_PENDING, to indicate that we - * shouldn't try reading from the input source any more. We might - * still have a bunch of tokens to match, though, because of - * possible backing-up. - * - * When we actually see the EOF, we change the status to "new" - * (via yyrestart()), so that the user can continue scanning by - * just pointing yyin at a new input file. - */ -#define YY_BUFFER_EOF_PENDING 2 - - }; -#endif /* !YY_STRUCT_YY_BUFFER_STATE */ - -/* Stack of input buffers. */ -static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ -static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ -static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ - -/* We provide macros for accessing buffer states in case in the - * future we want to put the buffer states in a more general - * "scanner state". - * - * Returns the top of the stack, or NULL. - */ -#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ - ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ - : NULL) - -/* Same as previous macro, but useful when we know that the buffer stack is not - * NULL or when we need an lvalue. For internal use only. - */ -#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] - -/* yy_hold_char holds the character lost when yytext is formed. */ -static char yy_hold_char; -static int yy_n_chars; /* number of characters read into yy_ch_buf */ -yy_size_t yyleng; - -/* Points to current character in buffer. */ -static char *yy_c_buf_p = (char *) 0; -static int yy_init = 0; /* whether we need to initialize */ -static int yy_start = 0; /* start state number */ - -/* Flag which is used to allow yywrap()'s to do buffer switches - * instead of setting up a fresh yyin. A bit of a hack ... - */ -static int yy_did_buffer_switch_on_eof; - -void yyrestart (FILE *input_file ); -void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ); -YY_BUFFER_STATE yy_create_buffer (FILE *file,int size ); -void yy_delete_buffer (YY_BUFFER_STATE b ); -void yy_flush_buffer (YY_BUFFER_STATE b ); -void yypush_buffer_state (YY_BUFFER_STATE new_buffer ); -void yypop_buffer_state (void ); - -static void yyensure_buffer_stack (void ); -static void yy_load_buffer_state (void ); -static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file ); - -#define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER ) - -YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ); -YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ); -YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,yy_size_t len ); - -void *yyalloc (yy_size_t ); -void *yyrealloc (void *,yy_size_t ); -void yyfree (void * ); - -#define yy_new_buffer yy_create_buffer - -#define yy_set_interactive(is_interactive) \ - { \ - if ( ! YY_CURRENT_BUFFER ){ \ - yyensure_buffer_stack (); \ - YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer(yyin,YY_BUF_SIZE ); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ - } - -#define yy_set_bol(at_bol) \ - { \ - if ( ! YY_CURRENT_BUFFER ){\ - yyensure_buffer_stack (); \ - YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer(yyin,YY_BUF_SIZE ); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ - } - -#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) - -/* Begin user sect3 */ - -#define yywrap() (/*CONSTCOND*/1) -#define YY_SKIP_YYWRAP - -typedef unsigned char YY_CHAR; - -FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0; - -typedef int yy_state_type; - -extern int yylineno; - -int yylineno = 1; - -extern char *yytext; -#ifdef yytext_ptr -#undef yytext_ptr -#endif -#define yytext_ptr yytext - -static yy_state_type yy_get_previous_state (void ); -static yy_state_type yy_try_NUL_trans (yy_state_type current_state ); -static int yy_get_next_buffer (void ); -#if defined(__GNUC__) && __GNUC__ >= 3 -__attribute__((__noreturn__)) -#endif -static void yy_fatal_error (yyconst char msg[] ); - -/* Done after the current pattern has been matched and before the - * corresponding action - sets up yytext. - */ -#define YY_DO_BEFORE_ACTION \ - (yytext_ptr) = yy_bp; \ - yyleng = (size_t) (yy_cp - yy_bp); \ - (yy_hold_char) = *yy_cp; \ - *yy_cp = '\0'; \ - (yy_c_buf_p) = yy_cp; - -#define YY_NUM_RULES 8 -#define YY_END_OF_BUFFER 9 -/* This struct is not used in this scanner, - but its presence is necessary. */ -struct yy_trans_info - { - flex_int32_t yy_verify; - flex_int32_t yy_nxt; - }; -static yyconst flex_int16_t yy_accept[32] = - { 0, - 0, 0, 0, 0, 9, 7, 5, 4, 5, 3, - 6, 6, 3, 3, 6, 3, 3, 0, 2, 0, - 0, 1, 3, 3, 3, 3, 0, 3, 3, 3, - 0 - } ; - -static yyconst YY_CHAR yy_ec[256] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, - 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 4, 5, 6, 5, 5, 5, 5, 7, 7, - 7, 5, 5, 5, 5, 7, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 8, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 7, 9, 7, 5, 5, 5, 5, 5, 5, 5, - - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 10, 5, 5, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1 - } ; - -static yyconst YY_CHAR yy_meta[11] = - { 0, - 1, 1, 2, 1, 3, 1, 1, 3, 3, 1 - } ; - -static yyconst flex_uint16_t yy_base[38] = - { 0, - 0, 0, 0, 0, 24, 72, 72, 72, 72, 14, - 5, 72, 12, 17, 9, 9, 22, 26, 72, 0, - 13, 72, 33, 40, 0, 0, 3, 72, 0, 47, - 72, 9, 56, 59, 62, 65, 68 - } ; - -static yyconst flex_int16_t yy_def[38] = - { 0, - 31, 1, 1, 1, 31, 31, 31, 31, 31, 32, - 33, 31, 34, 35, 36, 32, 35, 33, 31, 33, - 34, 31, 34, 37, 16, 17, 36, 31, 23, 37, - 0, 31, 31, 31, 31, 31, 31 - } ; - -static yyconst flex_uint16_t yy_nxt[83] = - { 0, - 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 19, 16, 28, 20, 22, 22, 23, 17, 28, 23, - 24, 25, 17, 31, 25, 26, 25, 31, 31, 25, - 26, 19, 31, 31, 20, 22, 31, 23, 31, 31, - 23, 24, 22, 31, 29, 31, 31, 29, 30, 22, - 31, 29, 31, 31, 29, 30, 18, 31, 18, 21, - 21, 21, 16, 31, 16, 27, 31, 27, 23, 23, - 23, 5, 31, 31, 31, 31, 31, 31, 31, 31, - 31, 31 - } ; - -static yyconst flex_int16_t yy_chk[83] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 11, 32, 27, 11, 13, 21, 13, 16, 15, 13, - 13, 14, 10, 5, 14, 14, 17, 0, 0, 17, - 17, 18, 0, 0, 18, 23, 0, 23, 0, 0, - 23, 23, 24, 0, 24, 0, 0, 24, 24, 30, - 0, 30, 0, 0, 30, 30, 33, 0, 33, 34, - 34, 34, 35, 0, 35, 36, 0, 36, 37, 37, - 37, 31, 31, 31, 31, 31, 31, 31, 31, 31, - 31, 31 - } ; - -static yy_state_type yy_last_accepting_state; -static char *yy_last_accepting_cpos; - -extern int yy_flex_debug; -int yy_flex_debug = 0; - -/* The intent behind this definition is that it'll catch - * any uses of REJECT which flex missed. - */ -#define REJECT reject_used_but_not_detected -#define yymore() yymore_used_but_not_detected -#define YY_MORE_ADJ 0 -#define YY_RESTORE_YY_MORE_OFFSET -char *yytext; -#line 1 "lisplang.l" -#line 2 "lisplang.l" -/* This file is part of the software similarity tester SIM. - Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: lisplang.l,v 2.17 2013-04-28 16:30:41 Gebruiker Exp $ -*/ - -/* - LISP language front end for the similarity tester. - Author: Gertjan Akkerman - Date: Thu, 9 Apr 87 11:15:23 MDT -*/ - -#include "token.h" -#include "language.h" -#include "algollike.h" -#include "lex.h" -#include "lang.h" - -/* General language front end data */ -Token lex_token; -size_t lex_nl_cnt; -size_t lex_tk_cnt; -size_t lex_non_ascii_cnt; - -/* Language-dependent data */ -#include "idf.h" - -static const struct idf reserved[] = { - {"append", NORM('a')}, - {"append1", NORM('b')}, - {"atom", NORM('t')}, - {"car", NORM('h')}, - {"cdr", NORM('t')}, - {"cond", NORM('c')}, - {"cons", NORM('s')}, - {"defun", NORM('u')}, - {"do", NORM('d')}, - {"eq", NORM('e')}, - {"equal", NORM('e')}, /* See eq */ - {"for", NORM('f')}, - {"if", NORM('i')}, - {"list", NORM('l')}, - {"nconc", NORM('n')}, - {"rplaca", NORM('A')}, - {"rplacd", NORM('D')} -}; - -/* Token sets for module algollike */ -const Token Non_Finals[] = { - NORM('('), - NORM('['), - No_Token -}; -const Token Non_Initials[] = { - NORM(')'), - NORM(']'), - No_Token -}; -const Token Openers[] = { - NORM('('), - NORM('['), - No_Token -}; -const Token Closers[] = { - NORM(')'), - NORM(']'), - No_Token -}; - -/* Language-dependent code */ - -void -Init_Language(void) { - Init_Algol_Language(Non_Finals, Non_Initials, Openers, Closers); -} - - -int -May_Be_Start_Of_Run(Token ch) { - return May_Be_Start_Of_Algol_Run(ch); -} - -size_t -Best_Run_Size(const Token *str, size_t size) { - return Best_Algol_Run_Size(str, size); -} - - -#line 581 "" - -#define INITIAL 0 -#define Comment 1 - -#ifndef YY_NO_UNISTD_H -/* Special case for "unistd.h", since it is non-ANSI. We include it way - * down here because we want the user's section 1 to have been scanned first. - * The user has a chance to override it with an option. - */ -#include -#endif - -#ifndef YY_EXTRA_TYPE -#define YY_EXTRA_TYPE void * -#endif - -static int yy_init_globals (void ); - -/* Accessor methods to globals. - These are made visible to non-reentrant scanners for convenience. */ - -int yylex_destroy (void ); - -int yyget_debug (void ); - -void yyset_debug (int debug_flag ); - -YY_EXTRA_TYPE yyget_extra (void ); - -void yyset_extra (YY_EXTRA_TYPE user_defined ); - -FILE *yyget_in (void ); - -void yyset_in (FILE * _in_str ); - -FILE *yyget_out (void ); - -void yyset_out (FILE * _out_str ); - -yy_size_t yyget_leng (void ); - -char *yyget_text (void ); - -int yyget_lineno (void ); - -void yyset_lineno (int _line_number ); - -/* Macros after this point can all be overridden by user definitions in - * section 1. - */ - -#ifndef YY_SKIP_YYWRAP -#ifdef __cplusplus -extern "C" int yywrap (void ); -#else -extern int yywrap (void ); -#endif -#endif - -#ifndef YY_NO_UNPUT - - static void yyunput (int c,char *buf_ptr ); - -#endif - -#ifndef yytext_ptr -static void yy_flex_strncpy (char *,yyconst char *,int ); -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * ); -#endif - -#ifndef YY_NO_INPUT - -#ifdef __cplusplus -static int yyinput (void ); -#else -static int input (void ); -#endif - -#endif - -/* Amount of stuff to slurp up with each read. */ -#ifndef YY_READ_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k */ -#define YY_READ_BUF_SIZE 16384 -#else -#define YY_READ_BUF_SIZE 8192 -#endif /* __ia64__ */ -#endif - -/* Copy whatever the last rule matched to the standard output. */ -#ifndef ECHO -/* This used to be an fputs(), but since the string might contain NUL's, - * we now use fwrite(). - */ -#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0) -#endif - -/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, - * is returned in "result". - */ -#ifndef YY_INPUT -#define YY_INPUT(buf,result,max_size) \ - if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ - { \ - int c = '*'; \ - size_t n; \ - for ( n = 0; n < max_size && \ - (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ - buf[n] = (char) c; \ - if ( c == '\n' ) \ - buf[n++] = (char) c; \ - if ( c == EOF && ferror( yyin ) ) \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - result = n; \ - } \ - else \ - { \ - errno=0; \ - while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \ - { \ - if( errno != EINTR) \ - { \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - break; \ - } \ - errno=0; \ - clearerr(yyin); \ - } \ - }\ -\ - -#endif - -/* No semi-colon after return; correct usage is to write "yyterminate();" - - * we don't want an extra ';' after the "return" because that will cause - * some compilers to complain about unreachable statements. - */ -#ifndef yyterminate -#define yyterminate() return YY_NULL -#endif - -/* Number of entries by which start-condition stack grows. */ -#ifndef YY_START_STACK_INCR -#define YY_START_STACK_INCR 25 -#endif - -/* Report a fatal error. */ -#ifndef YY_FATAL_ERROR -#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) -#endif - -/* end tables serialization structures and prototypes */ - -/* Default declaration of generated scanner - a define so the user can - * easily add parameters. - */ -#ifndef YY_DECL -#define YY_DECL_IS_OURS 1 - -extern int yylex (void); - -#define YY_DECL int yylex (void) -#endif /* !YY_DECL */ - -/* Code executed at the beginning of each rule, after yytext and yyleng - * have been set up. - */ -#ifndef YY_USER_ACTION -#define YY_USER_ACTION -#endif - -/* Code executed at the end of each rule. */ -#ifndef YY_BREAK -#define YY_BREAK /*LINTED*/break; -#endif - -#define YY_RULE_SETUP \ - YY_USER_ACTION - -/** The main scanner function which does all the work. - */ -YY_DECL -{ - yy_state_type yy_current_state; - char *yy_cp, *yy_bp; - int yy_act; - - if ( !(yy_init) ) - { - (yy_init) = 1; - -#ifdef YY_USER_INIT - YY_USER_INIT; -#endif - - if ( ! (yy_start) ) - (yy_start) = 1; /* first start state */ - - if ( ! yyin ) - yyin = stdin; - - if ( ! yyout ) - yyout = stdout; - - if ( ! YY_CURRENT_BUFFER ) { - yyensure_buffer_stack (); - YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer(yyin,YY_BUF_SIZE ); - } - - yy_load_buffer_state( ); - } - - { -#line 107 "lisplang.l" - - -#line 803 "" - - while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ - { - yy_cp = (yy_c_buf_p); - - /* Support of yytext. */ - *yy_cp = (yy_hold_char); - - /* yy_bp points to the position in yy_ch_buf of the start of - * the current run. - */ - yy_bp = yy_cp; - - yy_current_state = (yy_start); -yy_match: - do - { - YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 32 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - ++yy_cp; - } - while ( yy_base[yy_current_state] != 72 ); - -yy_find_action: - yy_act = yy_accept[yy_current_state]; - if ( yy_act == 0 ) - { /* have to back up */ - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - yy_act = yy_accept[yy_current_state]; - } - - YY_DO_BEFORE_ACTION; - -do_action: /* This label is used only to access EOF actions. */ - - switch ( yy_act ) - { /* beginning of action switch */ - case 0: /* must back up */ - /* undo the effects of YY_DO_BEFORE_ACTION */ - *yy_cp = (yy_hold_char); - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - goto yy_find_action; - -case 1: -*yy_cp = (yy_hold_char); /* undo effects of setting up yytext */ -(yy_c_buf_p) = yy_cp -= 1; -YY_DO_BEFORE_ACTION; /* set up yytext again */ -YY_RULE_SETUP -#line 109 "lisplang.l" -{ /* comment */ - } - YY_BREAK -case 2: -YY_RULE_SETUP -#line 112 "lisplang.l" -{ /* strings */ - return_ch('"'); - } - YY_BREAK -case 3: -YY_RULE_SETUP -#line 116 "lisplang.l" -{ /* identifier */ - return_tk(idf_in_list(yytext, reserved, sizeof reserved, IDF)); - } - YY_BREAK -case 4: -/* rule 4 can match eol */ -YY_RULE_SETUP -#line 120 "lisplang.l" -{ /* count newlines */ - return_eol(); - } - YY_BREAK -case 5: -YY_RULE_SETUP -#line 124 "lisplang.l" -{ /* ignore layout */ - } - YY_BREAK -case 6: -YY_RULE_SETUP -#line 127 "lisplang.l" -{ /* copy other text */ - return_ch(yytext[0]); - } - YY_BREAK -case 7: -YY_RULE_SETUP -#line 131 "lisplang.l" -{ /* count non-ASCII chars */ - lex_non_ascii_cnt++; - } - YY_BREAK -case 8: -YY_RULE_SETUP -#line 135 "lisplang.l" -ECHO; - YY_BREAK -#line 916 "" -case YY_STATE_EOF(INITIAL): -case YY_STATE_EOF(Comment): - yyterminate(); - - case YY_END_OF_BUFFER: - { - /* Amount of text matched not including the EOB char. */ - int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; - - /* Undo the effects of YY_DO_BEFORE_ACTION. */ - *yy_cp = (yy_hold_char); - YY_RESTORE_YY_MORE_OFFSET - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) - { - /* We're scanning a new file or input source. It's - * possible that this happened because the user - * just pointed yyin at a new source and called - * yylex(). If so, then we have to assure - * consistency between YY_CURRENT_BUFFER and our - * globals. Here is the right place to do so, because - * this is the first action (other than possibly a - * back-up) that will match for the new input source. - */ - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; - } - - /* Note that here we test for yy_c_buf_p "<=" to the position - * of the first EOB in the buffer, since yy_c_buf_p will - * already have been incremented past the NUL character - * (since all states make transitions on EOB to the - * end-of-buffer state). Contrast this with the test - * in input(). - */ - if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) - { /* This was really a NUL. */ - yy_state_type yy_next_state; - - (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( ); - - /* Okay, we're now positioned to make the NUL - * transition. We couldn't have - * yy_get_previous_state() go ahead and do it - * for us because it doesn't know how to deal - * with the possibility of jamming (and we don't - * want to build jamming into it because then it - * will run more slowly). - */ - - yy_next_state = yy_try_NUL_trans( yy_current_state ); - - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - - if ( yy_next_state ) - { - /* Consume the NUL. */ - yy_cp = ++(yy_c_buf_p); - yy_current_state = yy_next_state; - goto yy_match; - } - - else - { - yy_cp = (yy_c_buf_p); - goto yy_find_action; - } - } - - else switch ( yy_get_next_buffer( ) ) - { - case EOB_ACT_END_OF_FILE: - { - (yy_did_buffer_switch_on_eof) = 0; - - if ( yywrap( ) ) - { - /* Note: because we've taken care in - * yy_get_next_buffer() to have set up - * yytext, we can now set up - * yy_c_buf_p so that if some total - * hoser (like flex itself) wants to - * call the scanner after we return the - * YY_NULL, it'll still work - another - * YY_NULL will get returned. - */ - (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; - - yy_act = YY_STATE_EOF(YY_START); - goto do_action; - } - - else - { - if ( ! (yy_did_buffer_switch_on_eof) ) - YY_NEW_FILE; - } - break; - } - - case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = - (yytext_ptr) + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( ); - - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - goto yy_match; - - case EOB_ACT_LAST_MATCH: - (yy_c_buf_p) = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; - - yy_current_state = yy_get_previous_state( ); - - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - goto yy_find_action; - } - break; - } - - default: - YY_FATAL_ERROR( - "fatal flex scanner internal error--no action found" ); - } /* end of action switch */ - } /* end of scanning one token */ - } /* end of user's declarations */ -} /* end of yylex */ - -/* yy_get_next_buffer - try to read in a new buffer - * - * Returns a code representing an action: - * EOB_ACT_LAST_MATCH - - * EOB_ACT_CONTINUE_SCAN - continue scanning from current position - * EOB_ACT_END_OF_FILE - end of file - */ -static int yy_get_next_buffer (void) -{ - char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; - char *source = (yytext_ptr); - yy_size_t number_to_move, i; - int ret_val; - - if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) - YY_FATAL_ERROR( - "fatal flex scanner internal error--end of buffer missed" ); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) - { /* Don't try to fill the buffer, so this is an EOF. */ - if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) - { - /* We matched a single character, the EOB, so - * treat this as a final EOF. - */ - return EOB_ACT_END_OF_FILE; - } - - else - { - /* We matched some text prior to the EOB, first - * process it. - */ - return EOB_ACT_LAST_MATCH; - } - } - - /* Try to read more data. */ - - /* First move last chars to start of buffer. */ - number_to_move = (yy_size_t) ((yy_c_buf_p) - (yytext_ptr)) - 1; - - for ( i = 0; i < number_to_move; ++i ) - *(dest++) = *(source++); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) - /* don't do the read, it's not guaranteed to return an EOF, - * just force an EOF - */ - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; - - else - { - yy_size_t num_to_read = - YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; - - while ( num_to_read <= 0 ) - { /* Not enough room in the buffer - grow it. */ - - /* just a shorter name for the current buffer */ - YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; - - int yy_c_buf_p_offset = - (int) ((yy_c_buf_p) - b->yy_ch_buf); - - if ( b->yy_is_our_buffer ) - { - yy_size_t new_size = b->yy_buf_size * 2; - - if ( new_size <= 0 ) - b->yy_buf_size += b->yy_buf_size / 8; - else - b->yy_buf_size *= 2; - - b->yy_ch_buf = (char *) - /* Include room in for 2 EOB chars. */ - yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ); - } - else - /* Can't grow it, we don't own it. */ - b->yy_ch_buf = 0; - - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( - "fatal error - scanner input buffer overflow" ); - - (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; - - num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - - number_to_move - 1; - - } - - if ( num_to_read > YY_READ_BUF_SIZE ) - num_to_read = YY_READ_BUF_SIZE; - - /* Read in more data. */ - YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), - (yy_n_chars), num_to_read ); - - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - if ( (yy_n_chars) == 0 ) - { - if ( number_to_move == YY_MORE_ADJ ) - { - ret_val = EOB_ACT_END_OF_FILE; - yyrestart(yyin ); - } - - else - { - ret_val = EOB_ACT_LAST_MATCH; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = - YY_BUFFER_EOF_PENDING; - } - } - - else - ret_val = EOB_ACT_CONTINUE_SCAN; - - if ((int) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { - /* Extend the array by 50%, plus the number we really need. */ - int new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ); - if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); - } - - (yy_n_chars) += number_to_move; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; - - (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; - - return ret_val; -} - -/* yy_get_previous_state - get the state just before the EOB char was reached */ - - static yy_state_type yy_get_previous_state (void) -{ - yy_state_type yy_current_state; - char *yy_cp; - - yy_current_state = (yy_start); - - for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) - { - YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 32 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - } - - return yy_current_state; -} - -/* yy_try_NUL_trans - try to make a transition on the NUL character - * - * synopsis - * next_state = yy_try_NUL_trans( current_state ); - */ - static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) -{ - int yy_is_jam; - char *yy_cp = (yy_c_buf_p); - - YY_CHAR yy_c = 1; - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 32 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - yy_is_jam = (yy_current_state == 31); - - return yy_is_jam ? 0 : yy_current_state; -} - -#ifndef YY_NO_UNPUT - - static void yyunput (int c, char * yy_bp ) -{ - char *yy_cp; - - yy_cp = (yy_c_buf_p); - - /* undo effects of setting up yytext */ - *yy_cp = (yy_hold_char); - - if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) - { /* need to shift things up to make room */ - /* +2 for EOB chars. */ - yy_size_t number_to_move = (yy_n_chars) + 2; - char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ - YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; - char *source = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; - - while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) - *--dest = *--source; - - yy_cp += (int) (dest - source); - yy_bp += (int) (dest - source); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size; - - if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) - YY_FATAL_ERROR( "flex scanner push-back overflow" ); - } - - *--yy_cp = (char) c; - - (yytext_ptr) = yy_bp; - (yy_hold_char) = *yy_cp; - (yy_c_buf_p) = yy_cp; -} - -#endif - -#ifndef YY_NO_INPUT -#ifdef __cplusplus - static int yyinput (void) -#else - static int input (void) -#endif - -{ - int c; - - *(yy_c_buf_p) = (yy_hold_char); - - if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) - { - /* yy_c_buf_p now points to the character we want to return. - * If this occurs *before* the EOB characters, then it's a - * valid NUL; if not, then we've hit the end of the buffer. - */ - if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) - /* This was really a NUL. */ - *(yy_c_buf_p) = '\0'; - - else - { /* need more input */ - yy_size_t offset = (yy_c_buf_p) - (yytext_ptr); - ++(yy_c_buf_p); - - switch ( yy_get_next_buffer( ) ) - { - case EOB_ACT_LAST_MATCH: - /* This happens because yy_g_n_b() - * sees that we've accumulated a - * token and flags that we need to - * try matching the token before - * proceeding. But for input(), - * there's no matching to consider. - * So convert the EOB_ACT_LAST_MATCH - * to EOB_ACT_END_OF_FILE. - */ - - /* Reset buffer status. */ - yyrestart(yyin ); - - /*FALLTHROUGH*/ - - case EOB_ACT_END_OF_FILE: - { - if ( yywrap( ) ) - return EOF; - - if ( ! (yy_did_buffer_switch_on_eof) ) - YY_NEW_FILE; -#ifdef __cplusplus - return yyinput(); -#else - return input(); -#endif - } - - case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = (yytext_ptr) + offset; - break; - } - } - } - - c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ - *(yy_c_buf_p) = '\0'; /* preserve yytext */ - (yy_hold_char) = *++(yy_c_buf_p); - - return c; -} -#endif /* ifndef YY_NO_INPUT */ - -/** Immediately switch to a different input stream. - * @param input_file A readable stream. - * - * @note This function does not reset the start condition to @c INITIAL . - */ - void yyrestart (FILE * input_file ) -{ - - if ( ! YY_CURRENT_BUFFER ){ - yyensure_buffer_stack (); - YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer(yyin,YY_BUF_SIZE ); - } - - yy_init_buffer(YY_CURRENT_BUFFER,input_file ); - yy_load_buffer_state( ); -} - -/** Switch to a different input buffer. - * @param new_buffer The new input buffer. - * - */ - void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) -{ - - /* TODO. We should be able to replace this entire function body - * with - * yypop_buffer_state(); - * yypush_buffer_state(new_buffer); - */ - yyensure_buffer_stack (); - if ( YY_CURRENT_BUFFER == new_buffer ) - return; - - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - YY_CURRENT_BUFFER_LVALUE = new_buffer; - yy_load_buffer_state( ); - - /* We don't actually know whether we did this switch during - * EOF (yywrap()) processing, but the only time this flag - * is looked at is after yywrap() is called, so it's safe - * to go ahead and always set it. - */ - (yy_did_buffer_switch_on_eof) = 1; -} - -static void yy_load_buffer_state (void) -{ - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; - yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; - (yy_hold_char) = *(yy_c_buf_p); -} - -/** Allocate and initialize an input buffer state. - * @param file A readable stream. - * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. - * - * @return the allocated buffer state. - */ - YY_BUFFER_STATE yy_create_buffer (FILE * file, int size ) -{ - YY_BUFFER_STATE b; - - b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - - b->yy_buf_size = (yy_size_t)size; - - /* yy_ch_buf has to be 2 characters longer than the size given because - * we need to put in 2 end-of-buffer characters. - */ - b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 ); - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - - b->yy_is_our_buffer = 1; - - yy_init_buffer(b,file ); - - return b; -} - -/** Destroy the buffer. - * @param b a buffer created with yy_create_buffer() - * - */ - void yy_delete_buffer (YY_BUFFER_STATE b ) -{ - - if ( ! b ) - return; - - if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ - YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; - - if ( b->yy_is_our_buffer ) - yyfree((void *) b->yy_ch_buf ); - - yyfree((void *) b ); -} - -/* Initializes or reinitializes a buffer. - * This function is sometimes called more than once on the same buffer, - * such as during a yyrestart() or at EOF. - */ - static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file ) - -{ - int oerrno = errno; - - yy_flush_buffer(b ); - - b->yy_input_file = file; - b->yy_fill_buffer = 1; - - /* If b is the current buffer, then yy_init_buffer was _probably_ - * called from yyrestart() or through yy_get_next_buffer. - * In that case, we don't want to reset the lineno or column. - */ - if (b != YY_CURRENT_BUFFER){ - b->yy_bs_lineno = 1; - b->yy_bs_column = 0; - } - - b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; - - errno = oerrno; -} - -/** Discard all buffered characters. On the next scan, YY_INPUT will be called. - * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. - * - */ - void yy_flush_buffer (YY_BUFFER_STATE b ) -{ - if ( ! b ) - return; - - b->yy_n_chars = 0; - - /* We always need two end-of-buffer characters. The first causes - * a transition to the end-of-buffer state. The second causes - * a jam in that state. - */ - b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; - b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; - - b->yy_buf_pos = &b->yy_ch_buf[0]; - - b->yy_at_bol = 1; - b->yy_buffer_status = YY_BUFFER_NEW; - - if ( b == YY_CURRENT_BUFFER ) - yy_load_buffer_state( ); -} - -/** Pushes the new state onto the stack. The new state becomes - * the current state. This function will allocate the stack - * if necessary. - * @param new_buffer The new state. - * - */ -void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) -{ - if (new_buffer == NULL) - return; - - yyensure_buffer_stack(); - - /* This block is copied from yy_switch_to_buffer. */ - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - /* Only push if top exists. Otherwise, replace top. */ - if (YY_CURRENT_BUFFER) - (yy_buffer_stack_top)++; - YY_CURRENT_BUFFER_LVALUE = new_buffer; - - /* copied from yy_switch_to_buffer. */ - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; -} - -/** Removes and deletes the top of the stack, if present. - * The next element becomes the new top. - * - */ -void yypop_buffer_state (void) -{ - if (!YY_CURRENT_BUFFER) - return; - - yy_delete_buffer(YY_CURRENT_BUFFER ); - YY_CURRENT_BUFFER_LVALUE = NULL; - if ((yy_buffer_stack_top) > 0) - --(yy_buffer_stack_top); - - if (YY_CURRENT_BUFFER) { - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; - } -} - -/* Allocates the stack if it does not exist. - * Guarantees space for at least one push. - */ -static void yyensure_buffer_stack (void) -{ - yy_size_t num_to_alloc; - - if (!(yy_buffer_stack)) { - - /* First allocation is just for 2 elements, since we don't know if this - * scanner will even need a stack. We use 2 instead of 1 to avoid an - * immediate realloc on the next call. - */ - num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ - (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc - (num_to_alloc * sizeof(struct yy_buffer_state*) - ); - if ( ! (yy_buffer_stack) ) - YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); - - memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); - - (yy_buffer_stack_max) = num_to_alloc; - (yy_buffer_stack_top) = 0; - return; - } - - if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ - - /* Increase the buffer to prepare for a possible push. */ - yy_size_t grow_size = 8 /* arbitrary grow size */; - - num_to_alloc = (yy_buffer_stack_max) + grow_size; - (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc - ((yy_buffer_stack), - num_to_alloc * sizeof(struct yy_buffer_state*) - ); - if ( ! (yy_buffer_stack) ) - YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); - - /* zero only the new slots.*/ - memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); - (yy_buffer_stack_max) = num_to_alloc; - } -} - -/** Setup the input buffer state to scan directly from a user-specified character buffer. - * @param base the character buffer - * @param size the size in bytes of the character buffer - * - * @return the newly allocated buffer state object. - */ -YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) -{ - YY_BUFFER_STATE b; - - if ( size < 2 || - base[size-2] != YY_END_OF_BUFFER_CHAR || - base[size-1] != YY_END_OF_BUFFER_CHAR ) - /* They forgot to leave room for the EOB's. */ - return 0; - - b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); - - b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ - b->yy_buf_pos = b->yy_ch_buf = base; - b->yy_is_our_buffer = 0; - b->yy_input_file = 0; - b->yy_n_chars = b->yy_buf_size; - b->yy_is_interactive = 0; - b->yy_at_bol = 1; - b->yy_fill_buffer = 0; - b->yy_buffer_status = YY_BUFFER_NEW; - - yy_switch_to_buffer(b ); - - return b; -} - -/** Setup the input buffer state to scan a string. The next call to yylex() will - * scan from a @e copy of @a str. - * @param yystr a NUL-terminated string to scan - * - * @return the newly allocated buffer state object. - * @note If you want to scan bytes that may contain NUL values, then use - * yy_scan_bytes() instead. - */ -YY_BUFFER_STATE yy_scan_string (yyconst char * yystr ) -{ - - return yy_scan_bytes(yystr,strlen(yystr) ); -} - -/** Setup the input buffer state to scan the given bytes. The next call to yylex() will - * scan from a @e copy of @a bytes. - * @param yybytes the byte buffer to scan - * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. - * - * @return the newly allocated buffer state object. - */ -YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len ) -{ - YY_BUFFER_STATE b; - char *buf; - yy_size_t n; - yy_size_t i; - - /* Get memory for full buffer, including space for trailing EOB's. */ - n = _yybytes_len + 2; - buf = (char *) yyalloc(n ); - if ( ! buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); - - for ( i = 0; i < _yybytes_len; ++i ) - buf[i] = yybytes[i]; - - buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; - - b = yy_scan_buffer(buf,n ); - if ( ! b ) - YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); - - /* It's okay to grow etc. this buffer, and we should throw it - * away when we're done. - */ - b->yy_is_our_buffer = 1; - - return b; -} - -#ifndef YY_EXIT_FAILURE -#define YY_EXIT_FAILURE 2 -#endif - -static void yy_fatal_error (yyconst char* msg ) -{ - (void) fprintf( stderr, "%s\n", msg ); - exit( YY_EXIT_FAILURE ); -} - -/* Redefine yyless() so it works in section 3 code. */ - -#undef yyless -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - yytext[yyleng] = (yy_hold_char); \ - (yy_c_buf_p) = yytext + yyless_macro_arg; \ - (yy_hold_char) = *(yy_c_buf_p); \ - *(yy_c_buf_p) = '\0'; \ - yyleng = yyless_macro_arg; \ - } \ - while ( 0 ) - -/* Accessor methods (get/set functions) to struct members. */ - -/** Get the current line number. - * - */ -int yyget_lineno (void) -{ - - return yylineno; -} - -/** Get the input stream. - * - */ -FILE *yyget_in (void) -{ - return yyin; -} - -/** Get the output stream. - * - */ -FILE *yyget_out (void) -{ - return yyout; -} - -/** Get the length of the current token. - * - */ -yy_size_t yyget_leng (void) -{ - return yyleng; -} - -/** Get the current token. - * - */ - -char *yyget_text (void) -{ - return yytext; -} - -/** Set the current line number. - * @param _line_number line number - * - */ -void yyset_lineno (int _line_number ) -{ - - yylineno = _line_number; -} - -/** Set the input stream. This does not discard the current - * input buffer. - * @param _in_str A readable stream. - * - * @see yy_switch_to_buffer - */ -void yyset_in (FILE * _in_str ) -{ - yyin = _in_str ; -} - -void yyset_out (FILE * _out_str ) -{ - yyout = _out_str ; -} - -int yyget_debug (void) -{ - return yy_flex_debug; -} - -void yyset_debug (int _bdebug ) -{ - yy_flex_debug = _bdebug ; -} - -static int yy_init_globals (void) -{ - /* Initialization is the same as for the non-reentrant scanner. - * This function is called from yylex_destroy(), so don't allocate here. - */ - - (yy_buffer_stack) = 0; - (yy_buffer_stack_top) = 0; - (yy_buffer_stack_max) = 0; - (yy_c_buf_p) = (char *) 0; - (yy_init) = 0; - (yy_start) = 0; - -/* Defined in main.c */ -#ifdef YY_STDINIT - yyin = stdin; - yyout = stdout; -#else - yyin = (FILE *) 0; - yyout = (FILE *) 0; -#endif - - /* For future reference: Set errno on error, since we are called by - * yylex_init() - */ - return 0; -} - -/* yylex_destroy is for both reentrant and non-reentrant scanners. */ -int yylex_destroy (void) -{ - - /* Pop the buffer stack, destroying each element. */ - while(YY_CURRENT_BUFFER){ - yy_delete_buffer(YY_CURRENT_BUFFER ); - YY_CURRENT_BUFFER_LVALUE = NULL; - yypop_buffer_state(); - } - - /* Destroy the stack itself. */ - yyfree((yy_buffer_stack) ); - (yy_buffer_stack) = NULL; - - /* Reset the globals. This is important in a non-reentrant scanner so the next time - * yylex() is called, initialization will occur. */ - yy_init_globals( ); - - return 0; -} - -/* - * Internal utility routines. - */ - -#ifndef yytext_ptr -static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) -{ - - int i; - for ( i = 0; i < n; ++i ) - s1[i] = s2[i]; -} -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * s ) -{ - int n; - for ( n = 0; s[n]; ++n ) - ; - - return n; -} -#endif - -void *yyalloc (yy_size_t size ) -{ - return (void *) malloc( size ); -} - -void *yyrealloc (void * ptr, yy_size_t size ) -{ - - /* The cast to (char *) in the following accommodates both - * implementations that use char* generic pointers, and those - * that use void* generic pointers. It works with the latter - * because both ANSI C and C++ allow castless assignment from - * any pointer type to void*, and deal with argument conversions - * as though doing an assignment. - */ - return (void *) realloc( (char *) ptr, size ); -} - -void yyfree (void * ptr ) -{ - free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ -} - -#define YYTABLES_NAME "yytables" - -#line 135 "lisplang.l" - - - -/* More language-dependent code */ - -void -yystart(void) { - BEGIN INITIAL; -} - diff --git a/judger/core/sim/sim_2_77/m2lang.c b/judger/core/sim/sim_2_77/m2lang.c deleted file mode 100644 index 18580b66..00000000 --- a/judger/core/sim/sim_2_77/m2lang.c +++ /dev/null @@ -1,2216 +0,0 @@ - -#line 3 "" - -#define YY_INT_ALIGNED short int - -/* A lexical scanner generated by flex */ - -#define FLEX_SCANNER -#define YY_FLEX_MAJOR_VERSION 2 -#define YY_FLEX_MINOR_VERSION 6 -#define YY_FLEX_SUBMINOR_VERSION 0 -#if YY_FLEX_SUBMINOR_VERSION > 0 -#define FLEX_BETA -#endif - -/* First, we deal with platform-specific or compiler-specific issues. */ - -/* begin standard C headers. */ -#include -#include -#include -#include - -/* end standard C headers. */ - -/* flex integer type definitions */ - -#ifndef FLEXINT_H -#define FLEXINT_H - -/* C99 systems have . Non-C99 systems may or may not. */ - -#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L - -/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, - * if you want the limit (max/min) macros for int types. - */ -#ifndef __STDC_LIMIT_MACROS -#define __STDC_LIMIT_MACROS 1 -#endif - -#include -typedef int8_t flex_int8_t; -typedef uint8_t flex_uint8_t; -typedef int16_t flex_int16_t; -typedef uint16_t flex_uint16_t; -typedef int32_t flex_int32_t; -typedef uint32_t flex_uint32_t; -#else -typedef signed char flex_int8_t; -typedef short int flex_int16_t; -typedef int flex_int32_t; -typedef unsigned char flex_uint8_t; -typedef unsigned short int flex_uint16_t; -typedef unsigned int flex_uint32_t; - -/* Limits of integral types. */ -#ifndef INT8_MIN -#define INT8_MIN (-128) -#endif -#ifndef INT16_MIN -#define INT16_MIN (-32767-1) -#endif -#ifndef INT32_MIN -#define INT32_MIN (-2147483647-1) -#endif -#ifndef INT8_MAX -#define INT8_MAX (127) -#endif -#ifndef INT16_MAX -#define INT16_MAX (32767) -#endif -#ifndef INT32_MAX -#define INT32_MAX (2147483647) -#endif -#ifndef UINT8_MAX -#define UINT8_MAX (255U) -#endif -#ifndef UINT16_MAX -#define UINT16_MAX (65535U) -#endif -#ifndef UINT32_MAX -#define UINT32_MAX (4294967295U) -#endif - -#endif /* ! C99 */ - -#endif /* ! FLEXINT_H */ - -#ifdef __cplusplus - -/* The "const" storage-class-modifier is valid. */ -#define YY_USE_CONST - -#else /* ! __cplusplus */ - -/* C99 requires __STDC__ to be defined as 1. */ -#if defined (__STDC__) - -#define YY_USE_CONST - -#endif /* defined (__STDC__) */ -#endif /* ! __cplusplus */ - -#ifdef YY_USE_CONST -#define yyconst const -#else -#define yyconst -#endif - -/* Returned upon end-of-file. */ -#define YY_NULL 0 - -/* Promotes a possibly negative, possibly signed char to an unsigned - * integer for use as an array index. If the signed char is negative, - * we want to instead treat it as an 8-bit unsigned char, hence the - * double cast. - */ -#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) - -/* Enter a start condition. This macro really ought to take a parameter, - * but we do it the disgusting crufty way forced on us by the ()-less - * definition of BEGIN. - */ -#define BEGIN (yy_start) = 1 + 2 * - -/* Translate the current start state into a value that can be later handed - * to BEGIN to return to the state. The YYSTATE alias is for lex - * compatibility. - */ -#define YY_START (((yy_start) - 1) / 2) -#define YYSTATE YY_START - -/* Action number for EOF rule of a given start state. */ -#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) - -/* Special action meaning "start processing a new file". */ -#define YY_NEW_FILE yyrestart(yyin ) - -#define YY_END_OF_BUFFER_CHAR 0 - -/* Size of default input buffer. */ -#ifndef YY_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k. - * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. - * Ditto for the __ia64__ case accordingly. - */ -#define YY_BUF_SIZE 32768 -#else -#define YY_BUF_SIZE 16384 -#endif /* __ia64__ */ -#endif - -/* The state buf must be large enough to hold one state per character in the main buffer. - */ -#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) - -#ifndef YY_TYPEDEF_YY_BUFFER_STATE -#define YY_TYPEDEF_YY_BUFFER_STATE -typedef struct yy_buffer_state *YY_BUFFER_STATE; -#endif - -#ifndef YY_TYPEDEF_YY_SIZE_T -#define YY_TYPEDEF_YY_SIZE_T -typedef size_t yy_size_t; -#endif - -extern yy_size_t yyleng; - -extern FILE *yyin, *yyout; - -#define EOB_ACT_CONTINUE_SCAN 0 -#define EOB_ACT_END_OF_FILE 1 -#define EOB_ACT_LAST_MATCH 2 - - #define YY_LESS_LINENO(n) - #define YY_LINENO_REWIND_TO(ptr) - -/* Return all but the first "n" matched characters back to the input stream. */ -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - *yy_cp = (yy_hold_char); \ - YY_RESTORE_YY_MORE_OFFSET \ - (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ - YY_DO_BEFORE_ACTION; /* set up yytext again */ \ - } \ - while ( 0 ) - -#define unput(c) yyunput( c, (yytext_ptr) ) - -#ifndef YY_STRUCT_YY_BUFFER_STATE -#define YY_STRUCT_YY_BUFFER_STATE -struct yy_buffer_state - { - FILE *yy_input_file; - - char *yy_ch_buf; /* input buffer */ - char *yy_buf_pos; /* current position in input buffer */ - - /* Size of input buffer in bytes, not including room for EOB - * characters. - */ - yy_size_t yy_buf_size; - - /* Number of characters read into yy_ch_buf, not including EOB - * characters. - */ - int yy_n_chars; - - /* Whether we "own" the buffer - i.e., we know we created it, - * and can realloc() it to grow it, and should free() it to - * delete it. - */ - int yy_is_our_buffer; - - /* Whether this is an "interactive" input source; if so, and - * if we're using stdio for input, then we want to use getc() - * instead of fread(), to make sure we stop fetching input after - * each newline. - */ - int yy_is_interactive; - - /* Whether we're considered to be at the beginning of a line. - * If so, '^' rules will be active on the next match, otherwise - * not. - */ - int yy_at_bol; - - int yy_bs_lineno; /**< The line count. */ - int yy_bs_column; /**< The column count. */ - - /* Whether to try to fill the input buffer when we reach the - * end of it. - */ - int yy_fill_buffer; - - int yy_buffer_status; - -#define YY_BUFFER_NEW 0 -#define YY_BUFFER_NORMAL 1 - /* When an EOF's been seen but there's still some text to process - * then we mark the buffer as YY_EOF_PENDING, to indicate that we - * shouldn't try reading from the input source any more. We might - * still have a bunch of tokens to match, though, because of - * possible backing-up. - * - * When we actually see the EOF, we change the status to "new" - * (via yyrestart()), so that the user can continue scanning by - * just pointing yyin at a new input file. - */ -#define YY_BUFFER_EOF_PENDING 2 - - }; -#endif /* !YY_STRUCT_YY_BUFFER_STATE */ - -/* Stack of input buffers. */ -static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ -static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ -static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ - -/* We provide macros for accessing buffer states in case in the - * future we want to put the buffer states in a more general - * "scanner state". - * - * Returns the top of the stack, or NULL. - */ -#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ - ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ - : NULL) - -/* Same as previous macro, but useful when we know that the buffer stack is not - * NULL or when we need an lvalue. For internal use only. - */ -#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] - -/* yy_hold_char holds the character lost when yytext is formed. */ -static char yy_hold_char; -static int yy_n_chars; /* number of characters read into yy_ch_buf */ -yy_size_t yyleng; - -/* Points to current character in buffer. */ -static char *yy_c_buf_p = (char *) 0; -static int yy_init = 0; /* whether we need to initialize */ -static int yy_start = 0; /* start state number */ - -/* Flag which is used to allow yywrap()'s to do buffer switches - * instead of setting up a fresh yyin. A bit of a hack ... - */ -static int yy_did_buffer_switch_on_eof; - -void yyrestart (FILE *input_file ); -void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ); -YY_BUFFER_STATE yy_create_buffer (FILE *file,int size ); -void yy_delete_buffer (YY_BUFFER_STATE b ); -void yy_flush_buffer (YY_BUFFER_STATE b ); -void yypush_buffer_state (YY_BUFFER_STATE new_buffer ); -void yypop_buffer_state (void ); - -static void yyensure_buffer_stack (void ); -static void yy_load_buffer_state (void ); -static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file ); - -#define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER ) - -YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ); -YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ); -YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,yy_size_t len ); - -void *yyalloc (yy_size_t ); -void *yyrealloc (void *,yy_size_t ); -void yyfree (void * ); - -#define yy_new_buffer yy_create_buffer - -#define yy_set_interactive(is_interactive) \ - { \ - if ( ! YY_CURRENT_BUFFER ){ \ - yyensure_buffer_stack (); \ - YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer(yyin,YY_BUF_SIZE ); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ - } - -#define yy_set_bol(at_bol) \ - { \ - if ( ! YY_CURRENT_BUFFER ){\ - yyensure_buffer_stack (); \ - YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer(yyin,YY_BUF_SIZE ); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ - } - -#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) - -/* Begin user sect3 */ - -#define yywrap() (/*CONSTCOND*/1) -#define YY_SKIP_YYWRAP - -typedef unsigned char YY_CHAR; - -FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0; - -typedef int yy_state_type; - -extern int yylineno; - -int yylineno = 1; - -extern char *yytext; -#ifdef yytext_ptr -#undef yytext_ptr -#endif -#define yytext_ptr yytext - -static yy_state_type yy_get_previous_state (void ); -static yy_state_type yy_try_NUL_trans (yy_state_type current_state ); -static int yy_get_next_buffer (void ); -#if defined(__GNUC__) && __GNUC__ >= 3 -__attribute__((__noreturn__)) -#endif -static void yy_fatal_error (yyconst char msg[] ); - -/* Done after the current pattern has been matched and before the - * corresponding action - sets up yytext. - */ -#define YY_DO_BEFORE_ACTION \ - (yytext_ptr) = yy_bp; \ - yyleng = (size_t) (yy_cp - yy_bp); \ - (yy_hold_char) = *yy_cp; \ - *yy_cp = '\0'; \ - (yy_c_buf_p) = yy_cp; - -#define YY_NUM_RULES 18 -#define YY_END_OF_BUFFER 19 -/* This struct is not used in this scanner, - but its presence is necessary. */ -struct yy_trans_info - { - flex_int32_t yy_verify; - flex_int32_t yy_nxt; - }; -static yyconst flex_int16_t yy_accept[79] = - { 0, - 0, 0, 0, 0, 19, 17, 15, 14, 15, 16, - 16, 16, 16, 8, 13, 16, 8, 8, 11, 2, - 2, 4, 2, 2, 2, 2, 2, 3, 2, 2, - 2, 2, 2, 2, 0, 6, 0, 0, 7, 0, - 1, 8, 8, 12, 10, 8, 11, 8, 11, 2, - 2, 2, 2, 2, 2, 2, 5, 2, 2, 2, - 2, 2, 2, 2, 2, 11, 2, 0, 9, 2, - 2, 9, 9, 2, 2, 9, 2, 0 - } ; - -static yyconst YY_CHAR yy_ec[256] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, - 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 4, 5, 6, 5, 5, 5, 5, 7, 8, - 9, 10, 5, 5, 5, 5, 5, 11, 11, 11, - 11, 11, 11, 11, 11, 11, 11, 5, 12, 13, - 5, 14, 5, 5, 15, 16, 17, 18, 19, 15, - 20, 21, 20, 20, 20, 20, 20, 22, 20, 20, - 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, - 5, 23, 5, 5, 24, 5, 15, 15, 15, 15, - - 15, 15, 20, 20, 20, 20, 20, 20, 20, 20, - 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, - 20, 20, 5, 5, 5, 5, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1 - } ; - -static yyconst YY_CHAR yy_meta[25] = - { 0, - 1, 2, 3, 2, 1, 1, 1, 4, 1, 5, - 6, 1, 1, 1, 7, 7, 7, 7, 7, 7, - 7, 7, 1, 6 - } ; - -static yyconst flex_uint16_t yy_base[89] = - { 0, - 0, 0, 24, 0, 122, 285, 285, 285, 285, 285, - 43, 44, 103, 57, 285, 97, 71, 86, 97, 0, - 0, 285, 0, 0, 46, 47, 89, 89, 85, 0, - 80, 99, 63, 113, 54, 285, 0, 48, 285, 0, - 285, 0, 285, 285, 285, 0, 75, 73, 45, 0, - 74, 0, 55, 102, 0, 54, 285, 0, 0, 0, - 0, 0, 0, 0, 44, 133, 156, 57, 50, 177, - 189, 0, 42, 203, 0, 0, 0, 285, 227, 234, - 238, 245, 252, 259, 265, 271, 275, 277 - } ; - -static yyconst flex_int16_t yy_def[89] = - { 0, - 78, 1, 78, 3, 78, 78, 78, 78, 78, 78, - 79, 80, 78, 78, 78, 78, 78, 17, 81, 82, - 82, 78, 82, 82, 83, 84, 82, 78, 82, 82, - 82, 82, 32, 32, 79, 78, 79, 80, 78, 80, - 78, 14, 78, 78, 78, 17, 81, 81, 81, 82, - 83, 82, 83, 84, 82, 84, 78, 29, 82, 82, - 82, 32, 34, 34, 34, 85, 34, 86, 87, 82, - 34, 88, 87, 82, 71, 88, 74, 0, 78, 78, - 78, 78, 78, 78, 78, 78, 78, 78 - } ; - -static yyconst flex_uint16_t yy_nxt[310] = - { 0, - 6, 7, 8, 9, 10, 11, 12, 13, 10, 10, - 14, 15, 16, 10, 17, 17, 17, 17, 18, 19, - 19, 19, 10, 10, 20, 21, 22, 23, 24, 25, - 26, 27, 24, 28, 29, 30, 31, 24, 32, 32, - 32, 32, 33, 34, 34, 34, 24, 24, 36, 45, - 39, 52, 45, 55, 39, 35, 38, 45, 68, 36, - 68, 67, 66, 38, 35, 37, 40, 42, 53, 56, - 40, 42, 42, 42, 42, 42, 37, 43, 45, 52, - 45, 46, 45, 35, 65, 46, 46, 46, 46, 46, - 47, 48, 47, 60, 47, 58, 53, 57, 41, 58, - - 58, 58, 58, 58, 45, 59, 61, 49, 55, 62, - 44, 38, 41, 62, 62, 62, 62, 62, 63, 64, - 63, 78, 63, 63, 56, 78, 78, 63, 63, 63, - 63, 63, 78, 63, 68, 78, 68, 78, 78, 78, - 45, 78, 78, 47, 78, 78, 78, 78, 78, 78, - 78, 78, 78, 78, 78, 78, 47, 70, 78, 70, - 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, - 71, 71, 71, 71, 71, 71, 71, 71, 70, 78, - 70, 78, 78, 78, 78, 78, 78, 78, 78, 78, - 78, 74, 74, 74, 74, 74, 74, 74, 74, 75, - - 78, 78, 78, 75, 75, 75, 75, 75, 75, 75, - 75, 78, 75, 77, 78, 78, 78, 77, 77, 77, - 77, 77, 77, 77, 77, 78, 77, 35, 35, 78, - 35, 35, 35, 35, 38, 38, 78, 38, 38, 38, - 38, 47, 78, 47, 47, 50, 50, 78, 50, 78, - 50, 50, 51, 51, 78, 51, 51, 51, 51, 54, - 54, 78, 54, 54, 54, 54, 69, 78, 69, 78, - 69, 69, 72, 78, 78, 78, 78, 72, 73, 78, - 73, 73, 76, 76, 5, 78, 78, 78, 78, 78, - 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, - - 78, 78, 78, 78, 78, 78, 78, 78, 78 - } ; - -static yyconst flex_int16_t yy_chk[310] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 11, 73, - 12, 25, 49, 26, 38, 25, 26, 69, 68, 35, - 68, 65, 49, 56, 53, 11, 12, 14, 25, 26, - 38, 14, 14, 14, 14, 14, 35, 14, 17, 51, - 48, 17, 47, 51, 33, 17, 17, 17, 17, 17, - 17, 17, 17, 31, 17, 29, 51, 28, 27, 29, - - 29, 29, 29, 29, 19, 29, 32, 18, 54, 32, - 16, 54, 13, 32, 32, 32, 32, 32, 32, 32, - 32, 5, 32, 34, 54, 0, 0, 34, 34, 34, - 34, 34, 0, 34, 66, 0, 66, 0, 0, 0, - 66, 0, 0, 66, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 66, 67, 0, 67, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 67, 67, 67, 67, 67, 67, 67, 67, 70, 0, - 70, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 70, 70, 70, 70, 70, 70, 70, 70, 71, - - 0, 0, 0, 71, 71, 71, 71, 71, 71, 71, - 71, 0, 71, 74, 0, 0, 0, 74, 74, 74, - 74, 74, 74, 74, 74, 0, 74, 79, 79, 0, - 79, 79, 79, 79, 80, 80, 0, 80, 80, 80, - 80, 81, 0, 81, 81, 82, 82, 0, 82, 0, - 82, 82, 83, 83, 0, 83, 83, 83, 83, 84, - 84, 0, 84, 84, 84, 84, 85, 0, 85, 0, - 85, 85, 86, 0, 0, 0, 0, 86, 87, 0, - 87, 87, 88, 88, 78, 78, 78, 78, 78, 78, - 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, - - 78, 78, 78, 78, 78, 78, 78, 78, 78 - } ; - -static yy_state_type yy_last_accepting_state; -static char *yy_last_accepting_cpos; - -extern int yy_flex_debug; -int yy_flex_debug = 0; - -/* The intent behind this definition is that it'll catch - * any uses of REJECT which flex missed. - */ -#define REJECT reject_used_but_not_detected -#define yymore() yymore_used_but_not_detected -#define YY_MORE_ADJ 0 -#define YY_RESTORE_YY_MORE_OFFSET -char *yytext; -#line 1 "m2lang.l" -#line 2 "m2lang.l" -/* This file is part of the software similarity tester SIM. - Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: m2lang.l,v 2.19 2013-04-28 16:30:41 Gebruiker Exp $ -*/ - -/* - Modula-2 language front end for the similarity tester. - Author: Dick Grune -*/ - -#include "options.h" -#include "token.h" -#include "language.h" -#include "algollike.h" -#include "idf.h" -#include "lex.h" -#include "lang.h" - -/* General language front end data */ -Token lex_token; -size_t lex_nl_cnt; -size_t lex_tk_cnt; -size_t lex_non_ascii_cnt; - -/* Language-dependent data */ - -/* Most Modula-2 programs start with a number of IMPORTs that look - very similar from program to program. These are skipped by ignoring - the reserved words IMPLEMENTATION, DEFINITION, MODULE, IMPORT - and FROM, having a flag skip_imports, and start reacting only - at the first non-ignored reserved word. - - Also, the nesting comments require a state variable. -*/ - -/* Additional state variables, set in yystart() */ -static int skip_imports; -static int comment_level; - -/* Data for module idf */ - -static const struct idf reserved[] = { - {"AND", NORM('&')}, - {"ARRAY", NORM('A')}, - {"BEGIN", NORM('{')}, - {"BY", NORM('B')}, - {"CASE", NORM('c')}, - {"CONST", NORM('C')}, - {"DEFINITION", No_Token}, - {"DIV", NORM('/')}, - {"DO", NORM('D')}, - {"ELSE", NORM('e')}, - {"ELSIF", NORM('e')}, - {"END", NORM('}')}, - {"EXIT", NORM('E')}, - {"EXPORT", CTRL('E')}, - {"FOR", NORM('F')}, - {"FROM", No_Token}, - {"IF", NORM('i')}, - {"IMPLEMENTATION", No_Token}, - {"IMPORT", No_Token}, - {"IN", NORM('I')}, - {"LOOP", NORM('l')}, - {"MOD", NORM('%')}, - {"MODULE", No_Token}, - {"NOT", NORM('~')}, - {"OF", No_Token}, - {"OR", NORM('O')}, - {"POINTER", NORM('p')}, - {"PROCEDURE", NORM('P')}, - {"QUALIFIED", NORM('q')}, - {"RECORD", NORM('r')}, - {"REPEAT", NORM('R')}, - {"RETURN", CTRL('r')}, - {"SET", NORM('s')}, - {"THEN", No_Token}, - {"TO", NORM('t')}, - {"TYPE", NORM('T')}, - {"UNTIL", NORM('u')}, - {"VAR", NORM('v')}, - {"WHILE", NORM('w')}, - {"WITH", NORM('W')}, -}; - -static const struct idf standard[] = { - {"ABS", META('a')}, - {"ADDRESS", META('A')}, - {"ALLOCATE", MTCT('A')}, - {"BITSET", META('b')}, - {"BOOLEAN", META('B')}, - {"CAP", META('c')}, - {"CARDINAL", META('C')}, - {"CHAR", MTCT('C')}, - {"CHR", META('x')}, - {"DEALLOCATE", META('d')}, - {"DEC", META('D')}, - {"EXCL", META('e')}, - {"FALSE", META('f')}, - {"FLOAT", META('F')}, - {"HALT", META('h')}, - {"HIGH", META('H')}, - {"INC", META('i')}, - {"INCL", META('I')}, - {"INTEGER", MTCT('I')}, - {"LONGCARD", META('L')}, - {"LONGINT", META('L')}, - {"LONGREAL", META('L')}, - {"MAX", META('m')}, - {"MIN", META('M')}, - {"NEWPROCESS", META('n')}, - {"NIL", META('N')}, - {"ODD", META('o')}, - {"ORD", META('O')}, - {"PROC", META('p')}, - {"REAL", META('r')}, - {"SIZE", META('s')}, - {"SYSTEM", META('S')}, - {"TRANSFER", META('t')}, - {"TRUE", META('T')}, - {"TRUNC", MTCT('T')}, - {"VAL", META('v')}, - {"WORD", META('w')} -}; - -/* Special treatment of identifiers */ - -static Token -idf2token(int hashing) { - Token tk; - - /* the token can be on two lists, reserved and standard */ - tk = idf_in_list(yytext, reserved, sizeof reserved, IDF); - - /* is it one of the keywords to be ignored? */ - if (Token_EQ(tk, No_Token)) return tk; - - /* The statement below is a significant comment - on the value of state variables. - */ - if (!Token_EQ(tk, IDF)) { - /* reserved word, stop the skipping */ - skip_imports = 0; - } - else { - /* it is an identifier but not a reserved word */ - if (skip_imports) { - /* skip it */ - tk = 0; - } - else { - /* look further */ - tk = idf_in_list(yytext, standard, sizeof standard, IDF); - if (Token_EQ(tk, IDF) && hashing) { - /* return a one-Token hash code */ - tk = idf_hashed(yytext); - } - } - } - return tk; -} - -/* Token sets for module algollike */ -const Token Non_Finals[] = { - IDF, /* identifier */ - NORM('{'), /* also BEGIN */ - NORM('('), - NORM('['), - NORM('A'), /* ARRAY */ - NORM('c'), /* CASE */ - NORM('C'), /* CONST */ - NORM('E'), /* EXIT */ - NORM('F'), /* FOR */ - NORM('i'), /* IF */ - NORM('l'), /* LOOP */ - NORM('p'), /* POINTER */ - NORM('P'), /* PROCEDURE */ - NORM('r'), /* RECORD */ - NORM('R'), /* REPEAT */ - CTRL('R'), /* RETURN */ - NORM('s'), /* SET */ - NORM('T'), /* TYPE */ - NORM('v'), /* VAR */ - NORM('w'), /* WHILE */ - NORM('W'), /* WITH */ - No_Token -}; -const Token Non_Initials[] = { - NORM('}'), - NORM(')'), - NORM(']'), - NORM(';'), - No_Token -}; -const Token Openers[] = { - NORM('{'), - NORM('('), - NORM('['), - No_Token -}; -const Token Closers[] = { - NORM('}'), - NORM(')'), - NORM(']'), - No_Token -}; - -/* Language-dependent code */ - -void -Init_Language(void) { - Init_Algol_Language(Non_Finals, Non_Initials, Openers, Closers); -} - - -int -May_Be_Start_Of_Run(Token ch) { - return May_Be_Start_Of_Algol_Run(ch); -} - -size_t -Best_Run_Size(const Token *str, size_t size) { - return Best_Algol_Run_Size(str, size); -} - - -#line 785 "" - -#define INITIAL 0 -#define Comment 1 - -#ifndef YY_NO_UNISTD_H -/* Special case for "unistd.h", since it is non-ANSI. We include it way - * down here because we want the user's section 1 to have been scanned first. - * The user has a chance to override it with an option. - */ -#include -#endif - -#ifndef YY_EXTRA_TYPE -#define YY_EXTRA_TYPE void * -#endif - -static int yy_init_globals (void ); - -/* Accessor methods to globals. - These are made visible to non-reentrant scanners for convenience. */ - -int yylex_destroy (void ); - -int yyget_debug (void ); - -void yyset_debug (int debug_flag ); - -YY_EXTRA_TYPE yyget_extra (void ); - -void yyset_extra (YY_EXTRA_TYPE user_defined ); - -FILE *yyget_in (void ); - -void yyset_in (FILE * _in_str ); - -FILE *yyget_out (void ); - -void yyset_out (FILE * _out_str ); - -yy_size_t yyget_leng (void ); - -char *yyget_text (void ); - -int yyget_lineno (void ); - -void yyset_lineno (int _line_number ); - -/* Macros after this point can all be overridden by user definitions in - * section 1. - */ - -#ifndef YY_SKIP_YYWRAP -#ifdef __cplusplus -extern "C" int yywrap (void ); -#else -extern int yywrap (void ); -#endif -#endif - -#ifndef YY_NO_UNPUT - - static void yyunput (int c,char *buf_ptr ); - -#endif - -#ifndef yytext_ptr -static void yy_flex_strncpy (char *,yyconst char *,int ); -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * ); -#endif - -#ifndef YY_NO_INPUT - -#ifdef __cplusplus -static int yyinput (void ); -#else -static int input (void ); -#endif - -#endif - -/* Amount of stuff to slurp up with each read. */ -#ifndef YY_READ_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k */ -#define YY_READ_BUF_SIZE 16384 -#else -#define YY_READ_BUF_SIZE 8192 -#endif /* __ia64__ */ -#endif - -/* Copy whatever the last rule matched to the standard output. */ -#ifndef ECHO -/* This used to be an fputs(), but since the string might contain NUL's, - * we now use fwrite(). - */ -#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0) -#endif - -/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, - * is returned in "result". - */ -#ifndef YY_INPUT -#define YY_INPUT(buf,result,max_size) \ - if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ - { \ - int c = '*'; \ - size_t n; \ - for ( n = 0; n < max_size && \ - (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ - buf[n] = (char) c; \ - if ( c == '\n' ) \ - buf[n++] = (char) c; \ - if ( c == EOF && ferror( yyin ) ) \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - result = n; \ - } \ - else \ - { \ - errno=0; \ - while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \ - { \ - if( errno != EINTR) \ - { \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - break; \ - } \ - errno=0; \ - clearerr(yyin); \ - } \ - }\ -\ - -#endif - -/* No semi-colon after return; correct usage is to write "yyterminate();" - - * we don't want an extra ';' after the "return" because that will cause - * some compilers to complain about unreachable statements. - */ -#ifndef yyterminate -#define yyterminate() return YY_NULL -#endif - -/* Number of entries by which start-condition stack grows. */ -#ifndef YY_START_STACK_INCR -#define YY_START_STACK_INCR 25 -#endif - -/* Report a fatal error. */ -#ifndef YY_FATAL_ERROR -#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) -#endif - -/* end tables serialization structures and prototypes */ - -/* Default declaration of generated scanner - a define so the user can - * easily add parameters. - */ -#ifndef YY_DECL -#define YY_DECL_IS_OURS 1 - -extern int yylex (void); - -#define YY_DECL int yylex (void) -#endif /* !YY_DECL */ - -/* Code executed at the beginning of each rule, after yytext and yyleng - * have been set up. - */ -#ifndef YY_USER_ACTION -#define YY_USER_ACTION -#endif - -/* Code executed at the end of each rule. */ -#ifndef YY_BREAK -#define YY_BREAK /*LINTED*/break; -#endif - -#define YY_RULE_SETUP \ - YY_USER_ACTION - -/** The main scanner function which does all the work. - */ -YY_DECL -{ - yy_state_type yy_current_state; - char *yy_cp, *yy_bp; - int yy_act; - - if ( !(yy_init) ) - { - (yy_init) = 1; - -#ifdef YY_USER_INIT - YY_USER_INIT; -#endif - - if ( ! (yy_start) ) - (yy_start) = 1; /* first start state */ - - if ( ! yyin ) - yyin = stdin; - - if ( ! yyout ) - yyout = stdout; - - if ( ! YY_CURRENT_BUFFER ) { - yyensure_buffer_stack (); - YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer(yyin,YY_BUF_SIZE ); - } - - yy_load_buffer_state( ); - } - - { -#line 247 "m2lang.l" - - -#line 1007 "" - - while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ - { - yy_cp = (yy_c_buf_p); - - /* Support of yytext. */ - *yy_cp = (yy_hold_char); - - /* yy_bp points to the position in yy_ch_buf of the start of - * the current run. - */ - yy_bp = yy_cp; - - yy_current_state = (yy_start); -yy_match: - do - { - YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 79 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - ++yy_cp; - } - while ( yy_base[yy_current_state] != 285 ); - -yy_find_action: - yy_act = yy_accept[yy_current_state]; - if ( yy_act == 0 ) - { /* have to back up */ - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - yy_act = yy_accept[yy_current_state]; - } - - YY_DO_BEFORE_ACTION; - -do_action: /* This label is used only to access EOF actions. */ - - switch ( yy_act ) - { /* beginning of action switch */ - case 0: /* must back up */ - /* undo the effects of YY_DO_BEFORE_ACTION */ - *yy_cp = (yy_hold_char); - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - goto yy_find_action; - -case 1: -YY_RULE_SETUP -#line 249 "m2lang.l" -{ /* See clang.l */ - /* Lex itself is incapable of handling Modula-2's - nested comments. So let's help it a bit. - */ - if (comment_level == 0) { - BEGIN Comment; - } - comment_level++; - } - YY_BREAK -case 2: -YY_RULE_SETUP -#line 259 "m2lang.l" -{ /* safe comment chunk */ - } - YY_BREAK -case 3: -YY_RULE_SETUP -#line 262 "m2lang.l" -{ /* unsafe char, read one by one */ - } - YY_BREAK -case 4: -/* rule 4 can match eol */ -YY_RULE_SETUP -#line 265 "m2lang.l" -{ /* to break up long comments */ - return_eol(); - } - YY_BREAK -case 5: -YY_RULE_SETUP -#line 269 "m2lang.l" -{ /* end-of-comment */ - comment_level--; - if (comment_level == 0) { - BEGIN INITIAL; - } - } - YY_BREAK -case 6: -YY_RULE_SETUP -#line 276 "m2lang.l" -{ /* quoted strings */ - return_ch('"'); - } - YY_BREAK -case 7: -YY_RULE_SETUP -#line 280 "m2lang.l" -{ /* apostrophed strings */ - return_ch('"'); - } - YY_BREAK -case 8: -YY_RULE_SETUP -#line 284 "m2lang.l" -{ /* numeral, passed as an identifier */ - return_tk(IDF); - } - YY_BREAK -case 9: -YY_RULE_SETUP -#line 288 "m2lang.l" -{ /* ignore identifier after END */ - Token tk = - idf_in_list("END", reserved, sizeof reserved, No_Token); - if (!Token_EQ(tk, No_Token)) return_tk(tk); - } - YY_BREAK -case 10: -*yy_cp = (yy_hold_char); /* undo effects of setting up yytext */ -(yy_c_buf_p) = yy_cp -= 1; -YY_DO_BEFORE_ACTION; /* set up yytext again */ -YY_RULE_SETUP -#line 294 "m2lang.l" -{ /* identifier in front of ( */ - Token tk = idf2token(is_set_option('F')/* hashing option */); - if (!Token_EQ(tk, No_Token)) return_tk(tk); - } - YY_BREAK -case 11: -YY_RULE_SETUP -#line 299 "m2lang.l" -{ /* identifier */ - Token tk = idf2token(0 /* no hashing */); - if (!Token_EQ(tk, No_Token)) return_tk(tk); - } - YY_BREAK -case 12: -YY_RULE_SETUP -#line 304 "m2lang.l" -{ /* <>, special equivalence */ - return_ch('#'); - } - YY_BREAK -case 13: -YY_RULE_SETUP -#line 308 "m2lang.l" -{ /* semicolon, conditionally ignored */ - if (is_set_option('f')) return_ch(yytext[0]); - } - YY_BREAK -case 14: -/* rule 14 can match eol */ -YY_RULE_SETUP -#line 312 "m2lang.l" -{ /* count newlines */ - return_eol(); - } - YY_BREAK -case 15: -YY_RULE_SETUP -#line 316 "m2lang.l" -{ /* ignore layout */ - } - YY_BREAK -case 16: -YY_RULE_SETUP -#line 319 "m2lang.l" -{ /* copy other text */ - if (!skip_imports) return_ch(yytext[0]); - } - YY_BREAK -case 17: -YY_RULE_SETUP -#line 323 "m2lang.l" -{ /* count non-ASCII chars */ - lex_non_ascii_cnt++; - } - YY_BREAK -case 18: -YY_RULE_SETUP -#line 327 "m2lang.l" -ECHO; - YY_BREAK -#line 1203 "" -case YY_STATE_EOF(INITIAL): -case YY_STATE_EOF(Comment): - yyterminate(); - - case YY_END_OF_BUFFER: - { - /* Amount of text matched not including the EOB char. */ - int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; - - /* Undo the effects of YY_DO_BEFORE_ACTION. */ - *yy_cp = (yy_hold_char); - YY_RESTORE_YY_MORE_OFFSET - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) - { - /* We're scanning a new file or input source. It's - * possible that this happened because the user - * just pointed yyin at a new source and called - * yylex(). If so, then we have to assure - * consistency between YY_CURRENT_BUFFER and our - * globals. Here is the right place to do so, because - * this is the first action (other than possibly a - * back-up) that will match for the new input source. - */ - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; - } - - /* Note that here we test for yy_c_buf_p "<=" to the position - * of the first EOB in the buffer, since yy_c_buf_p will - * already have been incremented past the NUL character - * (since all states make transitions on EOB to the - * end-of-buffer state). Contrast this with the test - * in input(). - */ - if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) - { /* This was really a NUL. */ - yy_state_type yy_next_state; - - (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( ); - - /* Okay, we're now positioned to make the NUL - * transition. We couldn't have - * yy_get_previous_state() go ahead and do it - * for us because it doesn't know how to deal - * with the possibility of jamming (and we don't - * want to build jamming into it because then it - * will run more slowly). - */ - - yy_next_state = yy_try_NUL_trans( yy_current_state ); - - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - - if ( yy_next_state ) - { - /* Consume the NUL. */ - yy_cp = ++(yy_c_buf_p); - yy_current_state = yy_next_state; - goto yy_match; - } - - else - { - yy_cp = (yy_c_buf_p); - goto yy_find_action; - } - } - - else switch ( yy_get_next_buffer( ) ) - { - case EOB_ACT_END_OF_FILE: - { - (yy_did_buffer_switch_on_eof) = 0; - - if ( yywrap( ) ) - { - /* Note: because we've taken care in - * yy_get_next_buffer() to have set up - * yytext, we can now set up - * yy_c_buf_p so that if some total - * hoser (like flex itself) wants to - * call the scanner after we return the - * YY_NULL, it'll still work - another - * YY_NULL will get returned. - */ - (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; - - yy_act = YY_STATE_EOF(YY_START); - goto do_action; - } - - else - { - if ( ! (yy_did_buffer_switch_on_eof) ) - YY_NEW_FILE; - } - break; - } - - case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = - (yytext_ptr) + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( ); - - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - goto yy_match; - - case EOB_ACT_LAST_MATCH: - (yy_c_buf_p) = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; - - yy_current_state = yy_get_previous_state( ); - - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - goto yy_find_action; - } - break; - } - - default: - YY_FATAL_ERROR( - "fatal flex scanner internal error--no action found" ); - } /* end of action switch */ - } /* end of scanning one token */ - } /* end of user's declarations */ -} /* end of yylex */ - -/* yy_get_next_buffer - try to read in a new buffer - * - * Returns a code representing an action: - * EOB_ACT_LAST_MATCH - - * EOB_ACT_CONTINUE_SCAN - continue scanning from current position - * EOB_ACT_END_OF_FILE - end of file - */ -static int yy_get_next_buffer (void) -{ - char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; - char *source = (yytext_ptr); - yy_size_t number_to_move, i; - int ret_val; - - if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) - YY_FATAL_ERROR( - "fatal flex scanner internal error--end of buffer missed" ); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) - { /* Don't try to fill the buffer, so this is an EOF. */ - if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) - { - /* We matched a single character, the EOB, so - * treat this as a final EOF. - */ - return EOB_ACT_END_OF_FILE; - } - - else - { - /* We matched some text prior to the EOB, first - * process it. - */ - return EOB_ACT_LAST_MATCH; - } - } - - /* Try to read more data. */ - - /* First move last chars to start of buffer. */ - number_to_move = (yy_size_t) ((yy_c_buf_p) - (yytext_ptr)) - 1; - - for ( i = 0; i < number_to_move; ++i ) - *(dest++) = *(source++); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) - /* don't do the read, it's not guaranteed to return an EOF, - * just force an EOF - */ - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; - - else - { - yy_size_t num_to_read = - YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; - - while ( num_to_read <= 0 ) - { /* Not enough room in the buffer - grow it. */ - - /* just a shorter name for the current buffer */ - YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; - - int yy_c_buf_p_offset = - (int) ((yy_c_buf_p) - b->yy_ch_buf); - - if ( b->yy_is_our_buffer ) - { - yy_size_t new_size = b->yy_buf_size * 2; - - if ( new_size <= 0 ) - b->yy_buf_size += b->yy_buf_size / 8; - else - b->yy_buf_size *= 2; - - b->yy_ch_buf = (char *) - /* Include room in for 2 EOB chars. */ - yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ); - } - else - /* Can't grow it, we don't own it. */ - b->yy_ch_buf = 0; - - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( - "fatal error - scanner input buffer overflow" ); - - (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; - - num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - - number_to_move - 1; - - } - - if ( num_to_read > YY_READ_BUF_SIZE ) - num_to_read = YY_READ_BUF_SIZE; - - /* Read in more data. */ - YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), - (yy_n_chars), num_to_read ); - - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - if ( (yy_n_chars) == 0 ) - { - if ( number_to_move == YY_MORE_ADJ ) - { - ret_val = EOB_ACT_END_OF_FILE; - yyrestart(yyin ); - } - - else - { - ret_val = EOB_ACT_LAST_MATCH; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = - YY_BUFFER_EOF_PENDING; - } - } - - else - ret_val = EOB_ACT_CONTINUE_SCAN; - - if ((int) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { - /* Extend the array by 50%, plus the number we really need. */ - int new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ); - if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); - } - - (yy_n_chars) += number_to_move; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; - - (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; - - return ret_val; -} - -/* yy_get_previous_state - get the state just before the EOB char was reached */ - - static yy_state_type yy_get_previous_state (void) -{ - yy_state_type yy_current_state; - char *yy_cp; - - yy_current_state = (yy_start); - - for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) - { - YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 79 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - } - - return yy_current_state; -} - -/* yy_try_NUL_trans - try to make a transition on the NUL character - * - * synopsis - * next_state = yy_try_NUL_trans( current_state ); - */ - static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) -{ - int yy_is_jam; - char *yy_cp = (yy_c_buf_p); - - YY_CHAR yy_c = 1; - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 79 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - yy_is_jam = (yy_current_state == 78); - - return yy_is_jam ? 0 : yy_current_state; -} - -#ifndef YY_NO_UNPUT - - static void yyunput (int c, char * yy_bp ) -{ - char *yy_cp; - - yy_cp = (yy_c_buf_p); - - /* undo effects of setting up yytext */ - *yy_cp = (yy_hold_char); - - if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) - { /* need to shift things up to make room */ - /* +2 for EOB chars. */ - yy_size_t number_to_move = (yy_n_chars) + 2; - char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ - YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; - char *source = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; - - while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) - *--dest = *--source; - - yy_cp += (int) (dest - source); - yy_bp += (int) (dest - source); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size; - - if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) - YY_FATAL_ERROR( "flex scanner push-back overflow" ); - } - - *--yy_cp = (char) c; - - (yytext_ptr) = yy_bp; - (yy_hold_char) = *yy_cp; - (yy_c_buf_p) = yy_cp; -} - -#endif - -#ifndef YY_NO_INPUT -#ifdef __cplusplus - static int yyinput (void) -#else - static int input (void) -#endif - -{ - int c; - - *(yy_c_buf_p) = (yy_hold_char); - - if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) - { - /* yy_c_buf_p now points to the character we want to return. - * If this occurs *before* the EOB characters, then it's a - * valid NUL; if not, then we've hit the end of the buffer. - */ - if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) - /* This was really a NUL. */ - *(yy_c_buf_p) = '\0'; - - else - { /* need more input */ - yy_size_t offset = (yy_c_buf_p) - (yytext_ptr); - ++(yy_c_buf_p); - - switch ( yy_get_next_buffer( ) ) - { - case EOB_ACT_LAST_MATCH: - /* This happens because yy_g_n_b() - * sees that we've accumulated a - * token and flags that we need to - * try matching the token before - * proceeding. But for input(), - * there's no matching to consider. - * So convert the EOB_ACT_LAST_MATCH - * to EOB_ACT_END_OF_FILE. - */ - - /* Reset buffer status. */ - yyrestart(yyin ); - - /*FALLTHROUGH*/ - - case EOB_ACT_END_OF_FILE: - { - if ( yywrap( ) ) - return EOF; - - if ( ! (yy_did_buffer_switch_on_eof) ) - YY_NEW_FILE; -#ifdef __cplusplus - return yyinput(); -#else - return input(); -#endif - } - - case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = (yytext_ptr) + offset; - break; - } - } - } - - c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ - *(yy_c_buf_p) = '\0'; /* preserve yytext */ - (yy_hold_char) = *++(yy_c_buf_p); - - return c; -} -#endif /* ifndef YY_NO_INPUT */ - -/** Immediately switch to a different input stream. - * @param input_file A readable stream. - * - * @note This function does not reset the start condition to @c INITIAL . - */ - void yyrestart (FILE * input_file ) -{ - - if ( ! YY_CURRENT_BUFFER ){ - yyensure_buffer_stack (); - YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer(yyin,YY_BUF_SIZE ); - } - - yy_init_buffer(YY_CURRENT_BUFFER,input_file ); - yy_load_buffer_state( ); -} - -/** Switch to a different input buffer. - * @param new_buffer The new input buffer. - * - */ - void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) -{ - - /* TODO. We should be able to replace this entire function body - * with - * yypop_buffer_state(); - * yypush_buffer_state(new_buffer); - */ - yyensure_buffer_stack (); - if ( YY_CURRENT_BUFFER == new_buffer ) - return; - - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - YY_CURRENT_BUFFER_LVALUE = new_buffer; - yy_load_buffer_state( ); - - /* We don't actually know whether we did this switch during - * EOF (yywrap()) processing, but the only time this flag - * is looked at is after yywrap() is called, so it's safe - * to go ahead and always set it. - */ - (yy_did_buffer_switch_on_eof) = 1; -} - -static void yy_load_buffer_state (void) -{ - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; - yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; - (yy_hold_char) = *(yy_c_buf_p); -} - -/** Allocate and initialize an input buffer state. - * @param file A readable stream. - * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. - * - * @return the allocated buffer state. - */ - YY_BUFFER_STATE yy_create_buffer (FILE * file, int size ) -{ - YY_BUFFER_STATE b; - - b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - - b->yy_buf_size = (yy_size_t)size; - - /* yy_ch_buf has to be 2 characters longer than the size given because - * we need to put in 2 end-of-buffer characters. - */ - b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 ); - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - - b->yy_is_our_buffer = 1; - - yy_init_buffer(b,file ); - - return b; -} - -/** Destroy the buffer. - * @param b a buffer created with yy_create_buffer() - * - */ - void yy_delete_buffer (YY_BUFFER_STATE b ) -{ - - if ( ! b ) - return; - - if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ - YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; - - if ( b->yy_is_our_buffer ) - yyfree((void *) b->yy_ch_buf ); - - yyfree((void *) b ); -} - -/* Initializes or reinitializes a buffer. - * This function is sometimes called more than once on the same buffer, - * such as during a yyrestart() or at EOF. - */ - static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file ) - -{ - int oerrno = errno; - - yy_flush_buffer(b ); - - b->yy_input_file = file; - b->yy_fill_buffer = 1; - - /* If b is the current buffer, then yy_init_buffer was _probably_ - * called from yyrestart() or through yy_get_next_buffer. - * In that case, we don't want to reset the lineno or column. - */ - if (b != YY_CURRENT_BUFFER){ - b->yy_bs_lineno = 1; - b->yy_bs_column = 0; - } - - b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; - - errno = oerrno; -} - -/** Discard all buffered characters. On the next scan, YY_INPUT will be called. - * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. - * - */ - void yy_flush_buffer (YY_BUFFER_STATE b ) -{ - if ( ! b ) - return; - - b->yy_n_chars = 0; - - /* We always need two end-of-buffer characters. The first causes - * a transition to the end-of-buffer state. The second causes - * a jam in that state. - */ - b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; - b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; - - b->yy_buf_pos = &b->yy_ch_buf[0]; - - b->yy_at_bol = 1; - b->yy_buffer_status = YY_BUFFER_NEW; - - if ( b == YY_CURRENT_BUFFER ) - yy_load_buffer_state( ); -} - -/** Pushes the new state onto the stack. The new state becomes - * the current state. This function will allocate the stack - * if necessary. - * @param new_buffer The new state. - * - */ -void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) -{ - if (new_buffer == NULL) - return; - - yyensure_buffer_stack(); - - /* This block is copied from yy_switch_to_buffer. */ - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - /* Only push if top exists. Otherwise, replace top. */ - if (YY_CURRENT_BUFFER) - (yy_buffer_stack_top)++; - YY_CURRENT_BUFFER_LVALUE = new_buffer; - - /* copied from yy_switch_to_buffer. */ - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; -} - -/** Removes and deletes the top of the stack, if present. - * The next element becomes the new top. - * - */ -void yypop_buffer_state (void) -{ - if (!YY_CURRENT_BUFFER) - return; - - yy_delete_buffer(YY_CURRENT_BUFFER ); - YY_CURRENT_BUFFER_LVALUE = NULL; - if ((yy_buffer_stack_top) > 0) - --(yy_buffer_stack_top); - - if (YY_CURRENT_BUFFER) { - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; - } -} - -/* Allocates the stack if it does not exist. - * Guarantees space for at least one push. - */ -static void yyensure_buffer_stack (void) -{ - yy_size_t num_to_alloc; - - if (!(yy_buffer_stack)) { - - /* First allocation is just for 2 elements, since we don't know if this - * scanner will even need a stack. We use 2 instead of 1 to avoid an - * immediate realloc on the next call. - */ - num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ - (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc - (num_to_alloc * sizeof(struct yy_buffer_state*) - ); - if ( ! (yy_buffer_stack) ) - YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); - - memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); - - (yy_buffer_stack_max) = num_to_alloc; - (yy_buffer_stack_top) = 0; - return; - } - - if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ - - /* Increase the buffer to prepare for a possible push. */ - yy_size_t grow_size = 8 /* arbitrary grow size */; - - num_to_alloc = (yy_buffer_stack_max) + grow_size; - (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc - ((yy_buffer_stack), - num_to_alloc * sizeof(struct yy_buffer_state*) - ); - if ( ! (yy_buffer_stack) ) - YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); - - /* zero only the new slots.*/ - memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); - (yy_buffer_stack_max) = num_to_alloc; - } -} - -/** Setup the input buffer state to scan directly from a user-specified character buffer. - * @param base the character buffer - * @param size the size in bytes of the character buffer - * - * @return the newly allocated buffer state object. - */ -YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) -{ - YY_BUFFER_STATE b; - - if ( size < 2 || - base[size-2] != YY_END_OF_BUFFER_CHAR || - base[size-1] != YY_END_OF_BUFFER_CHAR ) - /* They forgot to leave room for the EOB's. */ - return 0; - - b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); - - b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ - b->yy_buf_pos = b->yy_ch_buf = base; - b->yy_is_our_buffer = 0; - b->yy_input_file = 0; - b->yy_n_chars = b->yy_buf_size; - b->yy_is_interactive = 0; - b->yy_at_bol = 1; - b->yy_fill_buffer = 0; - b->yy_buffer_status = YY_BUFFER_NEW; - - yy_switch_to_buffer(b ); - - return b; -} - -/** Setup the input buffer state to scan a string. The next call to yylex() will - * scan from a @e copy of @a str. - * @param yystr a NUL-terminated string to scan - * - * @return the newly allocated buffer state object. - * @note If you want to scan bytes that may contain NUL values, then use - * yy_scan_bytes() instead. - */ -YY_BUFFER_STATE yy_scan_string (yyconst char * yystr ) -{ - - return yy_scan_bytes(yystr,strlen(yystr) ); -} - -/** Setup the input buffer state to scan the given bytes. The next call to yylex() will - * scan from a @e copy of @a bytes. - * @param yybytes the byte buffer to scan - * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. - * - * @return the newly allocated buffer state object. - */ -YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len ) -{ - YY_BUFFER_STATE b; - char *buf; - yy_size_t n; - yy_size_t i; - - /* Get memory for full buffer, including space for trailing EOB's. */ - n = _yybytes_len + 2; - buf = (char *) yyalloc(n ); - if ( ! buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); - - for ( i = 0; i < _yybytes_len; ++i ) - buf[i] = yybytes[i]; - - buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; - - b = yy_scan_buffer(buf,n ); - if ( ! b ) - YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); - - /* It's okay to grow etc. this buffer, and we should throw it - * away when we're done. - */ - b->yy_is_our_buffer = 1; - - return b; -} - -#ifndef YY_EXIT_FAILURE -#define YY_EXIT_FAILURE 2 -#endif - -static void yy_fatal_error (yyconst char* msg ) -{ - (void) fprintf( stderr, "%s\n", msg ); - exit( YY_EXIT_FAILURE ); -} - -/* Redefine yyless() so it works in section 3 code. */ - -#undef yyless -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - yytext[yyleng] = (yy_hold_char); \ - (yy_c_buf_p) = yytext + yyless_macro_arg; \ - (yy_hold_char) = *(yy_c_buf_p); \ - *(yy_c_buf_p) = '\0'; \ - yyleng = yyless_macro_arg; \ - } \ - while ( 0 ) - -/* Accessor methods (get/set functions) to struct members. */ - -/** Get the current line number. - * - */ -int yyget_lineno (void) -{ - - return yylineno; -} - -/** Get the input stream. - * - */ -FILE *yyget_in (void) -{ - return yyin; -} - -/** Get the output stream. - * - */ -FILE *yyget_out (void) -{ - return yyout; -} - -/** Get the length of the current token. - * - */ -yy_size_t yyget_leng (void) -{ - return yyleng; -} - -/** Get the current token. - * - */ - -char *yyget_text (void) -{ - return yytext; -} - -/** Set the current line number. - * @param _line_number line number - * - */ -void yyset_lineno (int _line_number ) -{ - - yylineno = _line_number; -} - -/** Set the input stream. This does not discard the current - * input buffer. - * @param _in_str A readable stream. - * - * @see yy_switch_to_buffer - */ -void yyset_in (FILE * _in_str ) -{ - yyin = _in_str ; -} - -void yyset_out (FILE * _out_str ) -{ - yyout = _out_str ; -} - -int yyget_debug (void) -{ - return yy_flex_debug; -} - -void yyset_debug (int _bdebug ) -{ - yy_flex_debug = _bdebug ; -} - -static int yy_init_globals (void) -{ - /* Initialization is the same as for the non-reentrant scanner. - * This function is called from yylex_destroy(), so don't allocate here. - */ - - (yy_buffer_stack) = 0; - (yy_buffer_stack_top) = 0; - (yy_buffer_stack_max) = 0; - (yy_c_buf_p) = (char *) 0; - (yy_init) = 0; - (yy_start) = 0; - -/* Defined in main.c */ -#ifdef YY_STDINIT - yyin = stdin; - yyout = stdout; -#else - yyin = (FILE *) 0; - yyout = (FILE *) 0; -#endif - - /* For future reference: Set errno on error, since we are called by - * yylex_init() - */ - return 0; -} - -/* yylex_destroy is for both reentrant and non-reentrant scanners. */ -int yylex_destroy (void) -{ - - /* Pop the buffer stack, destroying each element. */ - while(YY_CURRENT_BUFFER){ - yy_delete_buffer(YY_CURRENT_BUFFER ); - YY_CURRENT_BUFFER_LVALUE = NULL; - yypop_buffer_state(); - } - - /* Destroy the stack itself. */ - yyfree((yy_buffer_stack) ); - (yy_buffer_stack) = NULL; - - /* Reset the globals. This is important in a non-reentrant scanner so the next time - * yylex() is called, initialization will occur. */ - yy_init_globals( ); - - return 0; -} - -/* - * Internal utility routines. - */ - -#ifndef yytext_ptr -static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) -{ - - int i; - for ( i = 0; i < n; ++i ) - s1[i] = s2[i]; -} -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * s ) -{ - int n; - for ( n = 0; s[n]; ++n ) - ; - - return n; -} -#endif - -void *yyalloc (yy_size_t size ) -{ - return (void *) malloc( size ); -} - -void *yyrealloc (void * ptr, yy_size_t size ) -{ - - /* The cast to (char *) in the following accommodates both - * implementations that use char* generic pointers, and those - * that use void* generic pointers. It works with the latter - * because both ANSI C and C++ allow castless assignment from - * any pointer type to void*, and deal with argument conversions - * as though doing an assignment. - */ - return (void *) realloc( (char *) ptr, size ); -} - -void yyfree (void * ptr ) -{ - free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ -} - -#define YYTABLES_NAME "yytables" - -#line 327 "m2lang.l" - - - -/* More language-dependent code */ - -void -yystart(void) { - skip_imports = 1; - comment_level = 0; - BEGIN INITIAL; -} - diff --git a/judger/core/sim/sim_2_77/miralang.c b/judger/core/sim/sim_2_77/miralang.c deleted file mode 100644 index 83e23174..00000000 --- a/judger/core/sim/sim_2_77/miralang.c +++ /dev/null @@ -1,1957 +0,0 @@ - -#line 3 "" - -#define YY_INT_ALIGNED short int - -/* A lexical scanner generated by flex */ - -#define FLEX_SCANNER -#define YY_FLEX_MAJOR_VERSION 2 -#define YY_FLEX_MINOR_VERSION 6 -#define YY_FLEX_SUBMINOR_VERSION 0 -#if YY_FLEX_SUBMINOR_VERSION > 0 -#define FLEX_BETA -#endif - -/* First, we deal with platform-specific or compiler-specific issues. */ - -/* begin standard C headers. */ -#include -#include -#include -#include - -/* end standard C headers. */ - -/* flex integer type definitions */ - -#ifndef FLEXINT_H -#define FLEXINT_H - -/* C99 systems have . Non-C99 systems may or may not. */ - -#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L - -/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, - * if you want the limit (max/min) macros for int types. - */ -#ifndef __STDC_LIMIT_MACROS -#define __STDC_LIMIT_MACROS 1 -#endif - -#include -typedef int8_t flex_int8_t; -typedef uint8_t flex_uint8_t; -typedef int16_t flex_int16_t; -typedef uint16_t flex_uint16_t; -typedef int32_t flex_int32_t; -typedef uint32_t flex_uint32_t; -#else -typedef signed char flex_int8_t; -typedef short int flex_int16_t; -typedef int flex_int32_t; -typedef unsigned char flex_uint8_t; -typedef unsigned short int flex_uint16_t; -typedef unsigned int flex_uint32_t; - -/* Limits of integral types. */ -#ifndef INT8_MIN -#define INT8_MIN (-128) -#endif -#ifndef INT16_MIN -#define INT16_MIN (-32767-1) -#endif -#ifndef INT32_MIN -#define INT32_MIN (-2147483647-1) -#endif -#ifndef INT8_MAX -#define INT8_MAX (127) -#endif -#ifndef INT16_MAX -#define INT16_MAX (32767) -#endif -#ifndef INT32_MAX -#define INT32_MAX (2147483647) -#endif -#ifndef UINT8_MAX -#define UINT8_MAX (255U) -#endif -#ifndef UINT16_MAX -#define UINT16_MAX (65535U) -#endif -#ifndef UINT32_MAX -#define UINT32_MAX (4294967295U) -#endif - -#endif /* ! C99 */ - -#endif /* ! FLEXINT_H */ - -#ifdef __cplusplus - -/* The "const" storage-class-modifier is valid. */ -#define YY_USE_CONST - -#else /* ! __cplusplus */ - -/* C99 requires __STDC__ to be defined as 1. */ -#if defined (__STDC__) - -#define YY_USE_CONST - -#endif /* defined (__STDC__) */ -#endif /* ! __cplusplus */ - -#ifdef YY_USE_CONST -#define yyconst const -#else -#define yyconst -#endif - -/* Returned upon end-of-file. */ -#define YY_NULL 0 - -/* Promotes a possibly negative, possibly signed char to an unsigned - * integer for use as an array index. If the signed char is negative, - * we want to instead treat it as an 8-bit unsigned char, hence the - * double cast. - */ -#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) - -/* Enter a start condition. This macro really ought to take a parameter, - * but we do it the disgusting crufty way forced on us by the ()-less - * definition of BEGIN. - */ -#define BEGIN (yy_start) = 1 + 2 * - -/* Translate the current start state into a value that can be later handed - * to BEGIN to return to the state. The YYSTATE alias is for lex - * compatibility. - */ -#define YY_START (((yy_start) - 1) / 2) -#define YYSTATE YY_START - -/* Action number for EOF rule of a given start state. */ -#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) - -/* Special action meaning "start processing a new file". */ -#define YY_NEW_FILE yyrestart(yyin ) - -#define YY_END_OF_BUFFER_CHAR 0 - -/* Size of default input buffer. */ -#ifndef YY_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k. - * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. - * Ditto for the __ia64__ case accordingly. - */ -#define YY_BUF_SIZE 32768 -#else -#define YY_BUF_SIZE 16384 -#endif /* __ia64__ */ -#endif - -/* The state buf must be large enough to hold one state per character in the main buffer. - */ -#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) - -#ifndef YY_TYPEDEF_YY_BUFFER_STATE -#define YY_TYPEDEF_YY_BUFFER_STATE -typedef struct yy_buffer_state *YY_BUFFER_STATE; -#endif - -#ifndef YY_TYPEDEF_YY_SIZE_T -#define YY_TYPEDEF_YY_SIZE_T -typedef size_t yy_size_t; -#endif - -extern yy_size_t yyleng; - -extern FILE *yyin, *yyout; - -#define EOB_ACT_CONTINUE_SCAN 0 -#define EOB_ACT_END_OF_FILE 1 -#define EOB_ACT_LAST_MATCH 2 - - #define YY_LESS_LINENO(n) - #define YY_LINENO_REWIND_TO(ptr) - -/* Return all but the first "n" matched characters back to the input stream. */ -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - *yy_cp = (yy_hold_char); \ - YY_RESTORE_YY_MORE_OFFSET \ - (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ - YY_DO_BEFORE_ACTION; /* set up yytext again */ \ - } \ - while ( 0 ) - -#define unput(c) yyunput( c, (yytext_ptr) ) - -#ifndef YY_STRUCT_YY_BUFFER_STATE -#define YY_STRUCT_YY_BUFFER_STATE -struct yy_buffer_state - { - FILE *yy_input_file; - - char *yy_ch_buf; /* input buffer */ - char *yy_buf_pos; /* current position in input buffer */ - - /* Size of input buffer in bytes, not including room for EOB - * characters. - */ - yy_size_t yy_buf_size; - - /* Number of characters read into yy_ch_buf, not including EOB - * characters. - */ - int yy_n_chars; - - /* Whether we "own" the buffer - i.e., we know we created it, - * and can realloc() it to grow it, and should free() it to - * delete it. - */ - int yy_is_our_buffer; - - /* Whether this is an "interactive" input source; if so, and - * if we're using stdio for input, then we want to use getc() - * instead of fread(), to make sure we stop fetching input after - * each newline. - */ - int yy_is_interactive; - - /* Whether we're considered to be at the beginning of a line. - * If so, '^' rules will be active on the next match, otherwise - * not. - */ - int yy_at_bol; - - int yy_bs_lineno; /**< The line count. */ - int yy_bs_column; /**< The column count. */ - - /* Whether to try to fill the input buffer when we reach the - * end of it. - */ - int yy_fill_buffer; - - int yy_buffer_status; - -#define YY_BUFFER_NEW 0 -#define YY_BUFFER_NORMAL 1 - /* When an EOF's been seen but there's still some text to process - * then we mark the buffer as YY_EOF_PENDING, to indicate that we - * shouldn't try reading from the input source any more. We might - * still have a bunch of tokens to match, though, because of - * possible backing-up. - * - * When we actually see the EOF, we change the status to "new" - * (via yyrestart()), so that the user can continue scanning by - * just pointing yyin at a new input file. - */ -#define YY_BUFFER_EOF_PENDING 2 - - }; -#endif /* !YY_STRUCT_YY_BUFFER_STATE */ - -/* Stack of input buffers. */ -static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ -static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ -static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ - -/* We provide macros for accessing buffer states in case in the - * future we want to put the buffer states in a more general - * "scanner state". - * - * Returns the top of the stack, or NULL. - */ -#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ - ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ - : NULL) - -/* Same as previous macro, but useful when we know that the buffer stack is not - * NULL or when we need an lvalue. For internal use only. - */ -#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] - -/* yy_hold_char holds the character lost when yytext is formed. */ -static char yy_hold_char; -static int yy_n_chars; /* number of characters read into yy_ch_buf */ -yy_size_t yyleng; - -/* Points to current character in buffer. */ -static char *yy_c_buf_p = (char *) 0; -static int yy_init = 0; /* whether we need to initialize */ -static int yy_start = 0; /* start state number */ - -/* Flag which is used to allow yywrap()'s to do buffer switches - * instead of setting up a fresh yyin. A bit of a hack ... - */ -static int yy_did_buffer_switch_on_eof; - -void yyrestart (FILE *input_file ); -void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ); -YY_BUFFER_STATE yy_create_buffer (FILE *file,int size ); -void yy_delete_buffer (YY_BUFFER_STATE b ); -void yy_flush_buffer (YY_BUFFER_STATE b ); -void yypush_buffer_state (YY_BUFFER_STATE new_buffer ); -void yypop_buffer_state (void ); - -static void yyensure_buffer_stack (void ); -static void yy_load_buffer_state (void ); -static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file ); - -#define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER ) - -YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ); -YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ); -YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,yy_size_t len ); - -void *yyalloc (yy_size_t ); -void *yyrealloc (void *,yy_size_t ); -void yyfree (void * ); - -#define yy_new_buffer yy_create_buffer - -#define yy_set_interactive(is_interactive) \ - { \ - if ( ! YY_CURRENT_BUFFER ){ \ - yyensure_buffer_stack (); \ - YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer(yyin,YY_BUF_SIZE ); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ - } - -#define yy_set_bol(at_bol) \ - { \ - if ( ! YY_CURRENT_BUFFER ){\ - yyensure_buffer_stack (); \ - YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer(yyin,YY_BUF_SIZE ); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ - } - -#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) - -/* Begin user sect3 */ - -#define yywrap() (/*CONSTCOND*/1) -#define YY_SKIP_YYWRAP - -typedef unsigned char YY_CHAR; - -FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0; - -typedef int yy_state_type; - -extern int yylineno; - -int yylineno = 1; - -extern char *yytext; -#ifdef yytext_ptr -#undef yytext_ptr -#endif -#define yytext_ptr yytext - -static yy_state_type yy_get_previous_state (void ); -static yy_state_type yy_try_NUL_trans (yy_state_type current_state ); -static int yy_get_next_buffer (void ); -#if defined(__GNUC__) && __GNUC__ >= 3 -__attribute__((__noreturn__)) -#endif -static void yy_fatal_error (yyconst char msg[] ); - -/* Done after the current pattern has been matched and before the - * corresponding action - sets up yytext. - */ -#define YY_DO_BEFORE_ACTION \ - (yytext_ptr) = yy_bp; \ - yyleng = (size_t) (yy_cp - yy_bp); \ - (yy_hold_char) = *yy_cp; \ - *yy_cp = '\0'; \ - (yy_c_buf_p) = yy_cp; - -#define YY_NUM_RULES 11 -#define YY_END_OF_BUFFER 12 -/* This struct is not used in this scanner, - but its presence is necessary. */ -struct yy_trans_info - { - flex_int32_t yy_verify; - flex_int32_t yy_nxt; - }; -static yyconst flex_int16_t yy_accept[41] = - { 0, - 0, 0, 0, 0, 12, 10, 8, 7, 8, 9, - 9, 9, 9, 6, 9, 0, 2, 0, 0, 0, - 0, 0, 6, 0, 0, 3, 0, 1, 0, 0, - 0, 0, 0, 0, 0, 5, 4, 5, 4, 0 - } ; - -static yyconst YY_CHAR yy_ec[256] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, - 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 4, 5, 6, 5, 5, 7, 5, 8, 5, - 5, 5, 5, 5, 5, 5, 5, 9, 9, 9, - 9, 9, 9, 9, 9, 9, 9, 5, 5, 5, - 5, 5, 5, 5, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, - 5, 11, 5, 5, 9, 5, 10, 10, 12, 13, - - 14, 10, 10, 10, 15, 10, 10, 16, 10, 17, - 10, 10, 10, 18, 19, 20, 21, 10, 10, 10, - 10, 10, 5, 22, 5, 5, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1 - } ; - -static yyconst YY_CHAR yy_meta[23] = - { 0, - 1, 1, 2, 1, 1, 1, 1, 3, 4, 4, - 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 1 - } ; - -static yyconst flex_uint16_t yy_base[47] = - { 0, - 0, 0, 0, 0, 68, 69, 69, 69, 69, 69, - 17, 22, 56, 0, 44, 19, 69, 0, 25, 48, - 56, 28, 0, 60, 20, 69, 57, 69, 40, 33, - 21, 20, 22, 14, 19, 0, 0, 0, 0, 69, - 40, 44, 46, 50, 54, 58 - } ; - -static yyconst flex_int16_t yy_def[47] = - { 0, - 40, 1, 1, 1, 40, 40, 40, 40, 40, 40, - 41, 40, 42, 43, 40, 41, 40, 41, 40, 40, - 40, 42, 43, 44, 40, 40, 44, 40, 40, 40, - 40, 40, 40, 40, 40, 45, 46, 45, 46, 0, - 40, 40, 40, 40, 40, 40 - } ; - -static yyconst flex_uint16_t yy_nxt[92] = - { 0, - 6, 7, 8, 9, 10, 11, 12, 13, 10, 14, - 10, 14, 14, 14, 14, 14, 14, 14, 14, 14, - 14, 15, 17, 19, 17, 19, 19, 18, 19, 18, - 40, 29, 37, 36, 35, 21, 20, 34, 30, 20, - 16, 33, 16, 16, 21, 21, 32, 21, 23, 23, - 27, 27, 27, 27, 38, 31, 38, 38, 39, 28, - 39, 39, 28, 26, 25, 24, 22, 40, 5, 40, - 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, - 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, - 40 - - } ; - -static yyconst flex_int16_t yy_chk[92] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 11, 12, 16, 12, 19, 11, 19, 16, - 22, 25, 35, 34, 33, 22, 12, 32, 25, 19, - 41, 31, 41, 41, 42, 42, 30, 42, 43, 43, - 44, 44, 44, 44, 45, 29, 45, 45, 46, 27, - 46, 46, 24, 21, 20, 15, 13, 5, 40, 40, - 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, - 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, - 40 - - } ; - -static yy_state_type yy_last_accepting_state; -static char *yy_last_accepting_cpos; - -extern int yy_flex_debug; -int yy_flex_debug = 0; - -/* The intent behind this definition is that it'll catch - * any uses of REJECT which flex missed. - */ -#define REJECT reject_used_but_not_detected -#define yymore() yymore_used_but_not_detected -#define YY_MORE_ADJ 0 -#define YY_RESTORE_YY_MORE_OFFSET -char *yytext; -#line 1 "miralang.l" -#line 2 "miralang.l" -/* This file is part of the software similarity tester SIM. - Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: miralang.l,v 1.11 2013-04-28 16:30:41 Gebruiker Exp $ -*/ - -/* - Miranda language front end for the similarity tester. - Author: Emma Norling (ejn@cs.mu.oz.au) - Date: Nov 1998 -*/ - -#include "token.h" -#include "language.h" -#include "algollike.h" -#include "lex.h" -#include "lang.h" - -/* General language front end data */ -Token lex_token; -size_t lex_nl_cnt; -size_t lex_tk_cnt; -size_t lex_non_ascii_cnt; - -/* Language-dependent data */ -#include "idf.h" - -static const struct idf reserved[] = { - {"abstype", NORM('a')}, - {"bool", NORM('b')}, - {"char", NORM('c')}, - {"const", META('c')}, - {"div", NORM('d')}, - {"False", NORM('F')}, - {"if", NORM('i')}, - {"mod", NORM('m')}, - {"num", NORM('n')}, - {"otherwise", NORM('o')}, - {"readvals", NORM('r')}, - {"show", NORM('s')}, - {"sys_message", META('s')}, - {"True", NORM('T')}, - {"type", NORM('t')}, - {"where", NORM('w')}, - {"with", META('w')} -}; - -/* Token sets for module algollike */ -const Token Non_Finals[] = { - NORM('('), - NORM('['), - NORM('='), - No_Token -}; -const Token Non_Initials[] = { - NORM(')'), - NORM(']'), - No_Token -}; -const Token Openers[] = { - NORM('('), - NORM('['), - NORM('='), - No_Token -}; -const Token Closers[] = { - NORM(')'), - NORM(']'), - No_Token -}; - -/* Language-dependent code */ - -void -Init_Language(void) { - Init_Algol_Language(Non_Finals, Non_Initials, Openers, Closers); -} - - -int -May_Be_Start_Of_Run(Token ch) { - return May_Be_Start_Of_Algol_Run(ch); -} - -size_t -Best_Run_Size(const Token *str, size_t size) { - return Best_Algol_Run_Size(str, size); -} - - -#line 591 "" - -#define INITIAL 0 -#define Comment 1 - -#ifndef YY_NO_UNISTD_H -/* Special case for "unistd.h", since it is non-ANSI. We include it way - * down here because we want the user's section 1 to have been scanned first. - * The user has a chance to override it with an option. - */ -#include -#endif - -#ifndef YY_EXTRA_TYPE -#define YY_EXTRA_TYPE void * -#endif - -static int yy_init_globals (void ); - -/* Accessor methods to globals. - These are made visible to non-reentrant scanners for convenience. */ - -int yylex_destroy (void ); - -int yyget_debug (void ); - -void yyset_debug (int debug_flag ); - -YY_EXTRA_TYPE yyget_extra (void ); - -void yyset_extra (YY_EXTRA_TYPE user_defined ); - -FILE *yyget_in (void ); - -void yyset_in (FILE * _in_str ); - -FILE *yyget_out (void ); - -void yyset_out (FILE * _out_str ); - -yy_size_t yyget_leng (void ); - -char *yyget_text (void ); - -int yyget_lineno (void ); - -void yyset_lineno (int _line_number ); - -/* Macros after this point can all be overridden by user definitions in - * section 1. - */ - -#ifndef YY_SKIP_YYWRAP -#ifdef __cplusplus -extern "C" int yywrap (void ); -#else -extern int yywrap (void ); -#endif -#endif - -#ifndef YY_NO_UNPUT - - static void yyunput (int c,char *buf_ptr ); - -#endif - -#ifndef yytext_ptr -static void yy_flex_strncpy (char *,yyconst char *,int ); -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * ); -#endif - -#ifndef YY_NO_INPUT - -#ifdef __cplusplus -static int yyinput (void ); -#else -static int input (void ); -#endif - -#endif - -/* Amount of stuff to slurp up with each read. */ -#ifndef YY_READ_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k */ -#define YY_READ_BUF_SIZE 16384 -#else -#define YY_READ_BUF_SIZE 8192 -#endif /* __ia64__ */ -#endif - -/* Copy whatever the last rule matched to the standard output. */ -#ifndef ECHO -/* This used to be an fputs(), but since the string might contain NUL's, - * we now use fwrite(). - */ -#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0) -#endif - -/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, - * is returned in "result". - */ -#ifndef YY_INPUT -#define YY_INPUT(buf,result,max_size) \ - if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ - { \ - int c = '*'; \ - size_t n; \ - for ( n = 0; n < max_size && \ - (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ - buf[n] = (char) c; \ - if ( c == '\n' ) \ - buf[n++] = (char) c; \ - if ( c == EOF && ferror( yyin ) ) \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - result = n; \ - } \ - else \ - { \ - errno=0; \ - while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \ - { \ - if( errno != EINTR) \ - { \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - break; \ - } \ - errno=0; \ - clearerr(yyin); \ - } \ - }\ -\ - -#endif - -/* No semi-colon after return; correct usage is to write "yyterminate();" - - * we don't want an extra ';' after the "return" because that will cause - * some compilers to complain about unreachable statements. - */ -#ifndef yyterminate -#define yyterminate() return YY_NULL -#endif - -/* Number of entries by which start-condition stack grows. */ -#ifndef YY_START_STACK_INCR -#define YY_START_STACK_INCR 25 -#endif - -/* Report a fatal error. */ -#ifndef YY_FATAL_ERROR -#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) -#endif - -/* end tables serialization structures and prototypes */ - -/* Default declaration of generated scanner - a define so the user can - * easily add parameters. - */ -#ifndef YY_DECL -#define YY_DECL_IS_OURS 1 - -extern int yylex (void); - -#define YY_DECL int yylex (void) -#endif /* !YY_DECL */ - -/* Code executed at the beginning of each rule, after yytext and yyleng - * have been set up. - */ -#ifndef YY_USER_ACTION -#define YY_USER_ACTION -#endif - -/* Code executed at the end of each rule. */ -#ifndef YY_BREAK -#define YY_BREAK /*LINTED*/break; -#endif - -#define YY_RULE_SETUP \ - YY_USER_ACTION - -/** The main scanner function which does all the work. - */ -YY_DECL -{ - yy_state_type yy_current_state; - char *yy_cp, *yy_bp; - int yy_act; - - if ( !(yy_init) ) - { - (yy_init) = 1; - -#ifdef YY_USER_INIT - YY_USER_INIT; -#endif - - if ( ! (yy_start) ) - (yy_start) = 1; /* first start state */ - - if ( ! yyin ) - yyin = stdin; - - if ( ! yyout ) - yyout = stdout; - - if ( ! YY_CURRENT_BUFFER ) { - yyensure_buffer_stack (); - YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer(yyin,YY_BUF_SIZE ); - } - - yy_load_buffer_state( ); - } - - { -#line 105 "miralang.l" - - -#line 813 "" - - while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ - { - yy_cp = (yy_c_buf_p); - - /* Support of yytext. */ - *yy_cp = (yy_hold_char); - - /* yy_bp points to the position in yy_ch_buf of the start of - * the current run. - */ - yy_bp = yy_cp; - - yy_current_state = (yy_start); -yy_match: - do - { - YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 41 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - ++yy_cp; - } - while ( yy_base[yy_current_state] != 69 ); - -yy_find_action: - yy_act = yy_accept[yy_current_state]; - if ( yy_act == 0 ) - { /* have to back up */ - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - yy_act = yy_accept[yy_current_state]; - } - - YY_DO_BEFORE_ACTION; - -do_action: /* This label is used only to access EOF actions. */ - - switch ( yy_act ) - { /* beginning of action switch */ - case 0: /* must back up */ - /* undo the effects of YY_DO_BEFORE_ACTION */ - *yy_cp = (yy_hold_char); - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - goto yy_find_action; - -case 1: -*yy_cp = (yy_hold_char); /* undo effects of setting up yytext */ -(yy_c_buf_p) = yy_cp -= 1; -YY_DO_BEFORE_ACTION; /* set up yytext again */ -YY_RULE_SETUP -#line 107 "miralang.l" -{ /* comment */ - } - YY_BREAK -case 2: -YY_RULE_SETUP -#line 110 "miralang.l" -{ /* strings */ - return_ch('"'); - } - YY_BREAK -case 3: -/* rule 3 can match eol */ -YY_RULE_SETUP -#line 114 "miralang.l" -{ /* characters */ - return_ch('\''); - } - YY_BREAK -case 4: -YY_RULE_SETUP -#line 118 "miralang.l" -{ /* skip %include line */ - } - YY_BREAK -case 5: -YY_RULE_SETUP -#line 121 "miralang.l" -{ /* skip %insert line */ - } - YY_BREAK -case 6: -YY_RULE_SETUP -#line 124 "miralang.l" -{ /* identifier */ - return_tk(idf_in_list(yytext, reserved, sizeof reserved, IDF)); - } - YY_BREAK -case 7: -/* rule 7 can match eol */ -YY_RULE_SETUP -#line 128 "miralang.l" -{ /* count newlines */ - return_eol(); - } - YY_BREAK -case 8: -YY_RULE_SETUP -#line 132 "miralang.l" -{ /* ignore layout */ - } - YY_BREAK -case 9: -YY_RULE_SETUP -#line 135 "miralang.l" -{ /* copy other text */ - return_ch(yytext[0]); - } - YY_BREAK -case 10: -YY_RULE_SETUP -#line 139 "miralang.l" -{ /* count non-ASCII chars */ - lex_non_ascii_cnt++; - } - YY_BREAK -case 11: -YY_RULE_SETUP -#line 143 "miralang.l" -ECHO; - YY_BREAK -#line 946 "" -case YY_STATE_EOF(INITIAL): -case YY_STATE_EOF(Comment): - yyterminate(); - - case YY_END_OF_BUFFER: - { - /* Amount of text matched not including the EOB char. */ - int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; - - /* Undo the effects of YY_DO_BEFORE_ACTION. */ - *yy_cp = (yy_hold_char); - YY_RESTORE_YY_MORE_OFFSET - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) - { - /* We're scanning a new file or input source. It's - * possible that this happened because the user - * just pointed yyin at a new source and called - * yylex(). If so, then we have to assure - * consistency between YY_CURRENT_BUFFER and our - * globals. Here is the right place to do so, because - * this is the first action (other than possibly a - * back-up) that will match for the new input source. - */ - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; - } - - /* Note that here we test for yy_c_buf_p "<=" to the position - * of the first EOB in the buffer, since yy_c_buf_p will - * already have been incremented past the NUL character - * (since all states make transitions on EOB to the - * end-of-buffer state). Contrast this with the test - * in input(). - */ - if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) - { /* This was really a NUL. */ - yy_state_type yy_next_state; - - (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( ); - - /* Okay, we're now positioned to make the NUL - * transition. We couldn't have - * yy_get_previous_state() go ahead and do it - * for us because it doesn't know how to deal - * with the possibility of jamming (and we don't - * want to build jamming into it because then it - * will run more slowly). - */ - - yy_next_state = yy_try_NUL_trans( yy_current_state ); - - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - - if ( yy_next_state ) - { - /* Consume the NUL. */ - yy_cp = ++(yy_c_buf_p); - yy_current_state = yy_next_state; - goto yy_match; - } - - else - { - yy_cp = (yy_c_buf_p); - goto yy_find_action; - } - } - - else switch ( yy_get_next_buffer( ) ) - { - case EOB_ACT_END_OF_FILE: - { - (yy_did_buffer_switch_on_eof) = 0; - - if ( yywrap( ) ) - { - /* Note: because we've taken care in - * yy_get_next_buffer() to have set up - * yytext, we can now set up - * yy_c_buf_p so that if some total - * hoser (like flex itself) wants to - * call the scanner after we return the - * YY_NULL, it'll still work - another - * YY_NULL will get returned. - */ - (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; - - yy_act = YY_STATE_EOF(YY_START); - goto do_action; - } - - else - { - if ( ! (yy_did_buffer_switch_on_eof) ) - YY_NEW_FILE; - } - break; - } - - case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = - (yytext_ptr) + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( ); - - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - goto yy_match; - - case EOB_ACT_LAST_MATCH: - (yy_c_buf_p) = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; - - yy_current_state = yy_get_previous_state( ); - - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - goto yy_find_action; - } - break; - } - - default: - YY_FATAL_ERROR( - "fatal flex scanner internal error--no action found" ); - } /* end of action switch */ - } /* end of scanning one token */ - } /* end of user's declarations */ -} /* end of yylex */ - -/* yy_get_next_buffer - try to read in a new buffer - * - * Returns a code representing an action: - * EOB_ACT_LAST_MATCH - - * EOB_ACT_CONTINUE_SCAN - continue scanning from current position - * EOB_ACT_END_OF_FILE - end of file - */ -static int yy_get_next_buffer (void) -{ - char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; - char *source = (yytext_ptr); - yy_size_t number_to_move, i; - int ret_val; - - if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) - YY_FATAL_ERROR( - "fatal flex scanner internal error--end of buffer missed" ); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) - { /* Don't try to fill the buffer, so this is an EOF. */ - if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) - { - /* We matched a single character, the EOB, so - * treat this as a final EOF. - */ - return EOB_ACT_END_OF_FILE; - } - - else - { - /* We matched some text prior to the EOB, first - * process it. - */ - return EOB_ACT_LAST_MATCH; - } - } - - /* Try to read more data. */ - - /* First move last chars to start of buffer. */ - number_to_move = (yy_size_t) ((yy_c_buf_p) - (yytext_ptr)) - 1; - - for ( i = 0; i < number_to_move; ++i ) - *(dest++) = *(source++); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) - /* don't do the read, it's not guaranteed to return an EOF, - * just force an EOF - */ - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; - - else - { - yy_size_t num_to_read = - YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; - - while ( num_to_read <= 0 ) - { /* Not enough room in the buffer - grow it. */ - - /* just a shorter name for the current buffer */ - YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; - - int yy_c_buf_p_offset = - (int) ((yy_c_buf_p) - b->yy_ch_buf); - - if ( b->yy_is_our_buffer ) - { - yy_size_t new_size = b->yy_buf_size * 2; - - if ( new_size <= 0 ) - b->yy_buf_size += b->yy_buf_size / 8; - else - b->yy_buf_size *= 2; - - b->yy_ch_buf = (char *) - /* Include room in for 2 EOB chars. */ - yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ); - } - else - /* Can't grow it, we don't own it. */ - b->yy_ch_buf = 0; - - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( - "fatal error - scanner input buffer overflow" ); - - (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; - - num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - - number_to_move - 1; - - } - - if ( num_to_read > YY_READ_BUF_SIZE ) - num_to_read = YY_READ_BUF_SIZE; - - /* Read in more data. */ - YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), - (yy_n_chars), num_to_read ); - - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - if ( (yy_n_chars) == 0 ) - { - if ( number_to_move == YY_MORE_ADJ ) - { - ret_val = EOB_ACT_END_OF_FILE; - yyrestart(yyin ); - } - - else - { - ret_val = EOB_ACT_LAST_MATCH; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = - YY_BUFFER_EOF_PENDING; - } - } - - else - ret_val = EOB_ACT_CONTINUE_SCAN; - - if ((int) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { - /* Extend the array by 50%, plus the number we really need. */ - int new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ); - if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); - } - - (yy_n_chars) += number_to_move; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; - - (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; - - return ret_val; -} - -/* yy_get_previous_state - get the state just before the EOB char was reached */ - - static yy_state_type yy_get_previous_state (void) -{ - yy_state_type yy_current_state; - char *yy_cp; - - yy_current_state = (yy_start); - - for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) - { - YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 41 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - } - - return yy_current_state; -} - -/* yy_try_NUL_trans - try to make a transition on the NUL character - * - * synopsis - * next_state = yy_try_NUL_trans( current_state ); - */ - static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) -{ - int yy_is_jam; - char *yy_cp = (yy_c_buf_p); - - YY_CHAR yy_c = 1; - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 41 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - yy_is_jam = (yy_current_state == 40); - - return yy_is_jam ? 0 : yy_current_state; -} - -#ifndef YY_NO_UNPUT - - static void yyunput (int c, char * yy_bp ) -{ - char *yy_cp; - - yy_cp = (yy_c_buf_p); - - /* undo effects of setting up yytext */ - *yy_cp = (yy_hold_char); - - if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) - { /* need to shift things up to make room */ - /* +2 for EOB chars. */ - yy_size_t number_to_move = (yy_n_chars) + 2; - char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ - YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; - char *source = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; - - while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) - *--dest = *--source; - - yy_cp += (int) (dest - source); - yy_bp += (int) (dest - source); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size; - - if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) - YY_FATAL_ERROR( "flex scanner push-back overflow" ); - } - - *--yy_cp = (char) c; - - (yytext_ptr) = yy_bp; - (yy_hold_char) = *yy_cp; - (yy_c_buf_p) = yy_cp; -} - -#endif - -#ifndef YY_NO_INPUT -#ifdef __cplusplus - static int yyinput (void) -#else - static int input (void) -#endif - -{ - int c; - - *(yy_c_buf_p) = (yy_hold_char); - - if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) - { - /* yy_c_buf_p now points to the character we want to return. - * If this occurs *before* the EOB characters, then it's a - * valid NUL; if not, then we've hit the end of the buffer. - */ - if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) - /* This was really a NUL. */ - *(yy_c_buf_p) = '\0'; - - else - { /* need more input */ - yy_size_t offset = (yy_c_buf_p) - (yytext_ptr); - ++(yy_c_buf_p); - - switch ( yy_get_next_buffer( ) ) - { - case EOB_ACT_LAST_MATCH: - /* This happens because yy_g_n_b() - * sees that we've accumulated a - * token and flags that we need to - * try matching the token before - * proceeding. But for input(), - * there's no matching to consider. - * So convert the EOB_ACT_LAST_MATCH - * to EOB_ACT_END_OF_FILE. - */ - - /* Reset buffer status. */ - yyrestart(yyin ); - - /*FALLTHROUGH*/ - - case EOB_ACT_END_OF_FILE: - { - if ( yywrap( ) ) - return EOF; - - if ( ! (yy_did_buffer_switch_on_eof) ) - YY_NEW_FILE; -#ifdef __cplusplus - return yyinput(); -#else - return input(); -#endif - } - - case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = (yytext_ptr) + offset; - break; - } - } - } - - c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ - *(yy_c_buf_p) = '\0'; /* preserve yytext */ - (yy_hold_char) = *++(yy_c_buf_p); - - return c; -} -#endif /* ifndef YY_NO_INPUT */ - -/** Immediately switch to a different input stream. - * @param input_file A readable stream. - * - * @note This function does not reset the start condition to @c INITIAL . - */ - void yyrestart (FILE * input_file ) -{ - - if ( ! YY_CURRENT_BUFFER ){ - yyensure_buffer_stack (); - YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer(yyin,YY_BUF_SIZE ); - } - - yy_init_buffer(YY_CURRENT_BUFFER,input_file ); - yy_load_buffer_state( ); -} - -/** Switch to a different input buffer. - * @param new_buffer The new input buffer. - * - */ - void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) -{ - - /* TODO. We should be able to replace this entire function body - * with - * yypop_buffer_state(); - * yypush_buffer_state(new_buffer); - */ - yyensure_buffer_stack (); - if ( YY_CURRENT_BUFFER == new_buffer ) - return; - - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - YY_CURRENT_BUFFER_LVALUE = new_buffer; - yy_load_buffer_state( ); - - /* We don't actually know whether we did this switch during - * EOF (yywrap()) processing, but the only time this flag - * is looked at is after yywrap() is called, so it's safe - * to go ahead and always set it. - */ - (yy_did_buffer_switch_on_eof) = 1; -} - -static void yy_load_buffer_state (void) -{ - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; - yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; - (yy_hold_char) = *(yy_c_buf_p); -} - -/** Allocate and initialize an input buffer state. - * @param file A readable stream. - * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. - * - * @return the allocated buffer state. - */ - YY_BUFFER_STATE yy_create_buffer (FILE * file, int size ) -{ - YY_BUFFER_STATE b; - - b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - - b->yy_buf_size = (yy_size_t)size; - - /* yy_ch_buf has to be 2 characters longer than the size given because - * we need to put in 2 end-of-buffer characters. - */ - b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 ); - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - - b->yy_is_our_buffer = 1; - - yy_init_buffer(b,file ); - - return b; -} - -/** Destroy the buffer. - * @param b a buffer created with yy_create_buffer() - * - */ - void yy_delete_buffer (YY_BUFFER_STATE b ) -{ - - if ( ! b ) - return; - - if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ - YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; - - if ( b->yy_is_our_buffer ) - yyfree((void *) b->yy_ch_buf ); - - yyfree((void *) b ); -} - -/* Initializes or reinitializes a buffer. - * This function is sometimes called more than once on the same buffer, - * such as during a yyrestart() or at EOF. - */ - static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file ) - -{ - int oerrno = errno; - - yy_flush_buffer(b ); - - b->yy_input_file = file; - b->yy_fill_buffer = 1; - - /* If b is the current buffer, then yy_init_buffer was _probably_ - * called from yyrestart() or through yy_get_next_buffer. - * In that case, we don't want to reset the lineno or column. - */ - if (b != YY_CURRENT_BUFFER){ - b->yy_bs_lineno = 1; - b->yy_bs_column = 0; - } - - b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; - - errno = oerrno; -} - -/** Discard all buffered characters. On the next scan, YY_INPUT will be called. - * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. - * - */ - void yy_flush_buffer (YY_BUFFER_STATE b ) -{ - if ( ! b ) - return; - - b->yy_n_chars = 0; - - /* We always need two end-of-buffer characters. The first causes - * a transition to the end-of-buffer state. The second causes - * a jam in that state. - */ - b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; - b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; - - b->yy_buf_pos = &b->yy_ch_buf[0]; - - b->yy_at_bol = 1; - b->yy_buffer_status = YY_BUFFER_NEW; - - if ( b == YY_CURRENT_BUFFER ) - yy_load_buffer_state( ); -} - -/** Pushes the new state onto the stack. The new state becomes - * the current state. This function will allocate the stack - * if necessary. - * @param new_buffer The new state. - * - */ -void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) -{ - if (new_buffer == NULL) - return; - - yyensure_buffer_stack(); - - /* This block is copied from yy_switch_to_buffer. */ - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - /* Only push if top exists. Otherwise, replace top. */ - if (YY_CURRENT_BUFFER) - (yy_buffer_stack_top)++; - YY_CURRENT_BUFFER_LVALUE = new_buffer; - - /* copied from yy_switch_to_buffer. */ - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; -} - -/** Removes and deletes the top of the stack, if present. - * The next element becomes the new top. - * - */ -void yypop_buffer_state (void) -{ - if (!YY_CURRENT_BUFFER) - return; - - yy_delete_buffer(YY_CURRENT_BUFFER ); - YY_CURRENT_BUFFER_LVALUE = NULL; - if ((yy_buffer_stack_top) > 0) - --(yy_buffer_stack_top); - - if (YY_CURRENT_BUFFER) { - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; - } -} - -/* Allocates the stack if it does not exist. - * Guarantees space for at least one push. - */ -static void yyensure_buffer_stack (void) -{ - yy_size_t num_to_alloc; - - if (!(yy_buffer_stack)) { - - /* First allocation is just for 2 elements, since we don't know if this - * scanner will even need a stack. We use 2 instead of 1 to avoid an - * immediate realloc on the next call. - */ - num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ - (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc - (num_to_alloc * sizeof(struct yy_buffer_state*) - ); - if ( ! (yy_buffer_stack) ) - YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); - - memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); - - (yy_buffer_stack_max) = num_to_alloc; - (yy_buffer_stack_top) = 0; - return; - } - - if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ - - /* Increase the buffer to prepare for a possible push. */ - yy_size_t grow_size = 8 /* arbitrary grow size */; - - num_to_alloc = (yy_buffer_stack_max) + grow_size; - (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc - ((yy_buffer_stack), - num_to_alloc * sizeof(struct yy_buffer_state*) - ); - if ( ! (yy_buffer_stack) ) - YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); - - /* zero only the new slots.*/ - memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); - (yy_buffer_stack_max) = num_to_alloc; - } -} - -/** Setup the input buffer state to scan directly from a user-specified character buffer. - * @param base the character buffer - * @param size the size in bytes of the character buffer - * - * @return the newly allocated buffer state object. - */ -YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) -{ - YY_BUFFER_STATE b; - - if ( size < 2 || - base[size-2] != YY_END_OF_BUFFER_CHAR || - base[size-1] != YY_END_OF_BUFFER_CHAR ) - /* They forgot to leave room for the EOB's. */ - return 0; - - b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); - - b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ - b->yy_buf_pos = b->yy_ch_buf = base; - b->yy_is_our_buffer = 0; - b->yy_input_file = 0; - b->yy_n_chars = b->yy_buf_size; - b->yy_is_interactive = 0; - b->yy_at_bol = 1; - b->yy_fill_buffer = 0; - b->yy_buffer_status = YY_BUFFER_NEW; - - yy_switch_to_buffer(b ); - - return b; -} - -/** Setup the input buffer state to scan a string. The next call to yylex() will - * scan from a @e copy of @a str. - * @param yystr a NUL-terminated string to scan - * - * @return the newly allocated buffer state object. - * @note If you want to scan bytes that may contain NUL values, then use - * yy_scan_bytes() instead. - */ -YY_BUFFER_STATE yy_scan_string (yyconst char * yystr ) -{ - - return yy_scan_bytes(yystr,strlen(yystr) ); -} - -/** Setup the input buffer state to scan the given bytes. The next call to yylex() will - * scan from a @e copy of @a bytes. - * @param yybytes the byte buffer to scan - * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. - * - * @return the newly allocated buffer state object. - */ -YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len ) -{ - YY_BUFFER_STATE b; - char *buf; - yy_size_t n; - yy_size_t i; - - /* Get memory for full buffer, including space for trailing EOB's. */ - n = _yybytes_len + 2; - buf = (char *) yyalloc(n ); - if ( ! buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); - - for ( i = 0; i < _yybytes_len; ++i ) - buf[i] = yybytes[i]; - - buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; - - b = yy_scan_buffer(buf,n ); - if ( ! b ) - YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); - - /* It's okay to grow etc. this buffer, and we should throw it - * away when we're done. - */ - b->yy_is_our_buffer = 1; - - return b; -} - -#ifndef YY_EXIT_FAILURE -#define YY_EXIT_FAILURE 2 -#endif - -static void yy_fatal_error (yyconst char* msg ) -{ - (void) fprintf( stderr, "%s\n", msg ); - exit( YY_EXIT_FAILURE ); -} - -/* Redefine yyless() so it works in section 3 code. */ - -#undef yyless -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - yytext[yyleng] = (yy_hold_char); \ - (yy_c_buf_p) = yytext + yyless_macro_arg; \ - (yy_hold_char) = *(yy_c_buf_p); \ - *(yy_c_buf_p) = '\0'; \ - yyleng = yyless_macro_arg; \ - } \ - while ( 0 ) - -/* Accessor methods (get/set functions) to struct members. */ - -/** Get the current line number. - * - */ -int yyget_lineno (void) -{ - - return yylineno; -} - -/** Get the input stream. - * - */ -FILE *yyget_in (void) -{ - return yyin; -} - -/** Get the output stream. - * - */ -FILE *yyget_out (void) -{ - return yyout; -} - -/** Get the length of the current token. - * - */ -yy_size_t yyget_leng (void) -{ - return yyleng; -} - -/** Get the current token. - * - */ - -char *yyget_text (void) -{ - return yytext; -} - -/** Set the current line number. - * @param _line_number line number - * - */ -void yyset_lineno (int _line_number ) -{ - - yylineno = _line_number; -} - -/** Set the input stream. This does not discard the current - * input buffer. - * @param _in_str A readable stream. - * - * @see yy_switch_to_buffer - */ -void yyset_in (FILE * _in_str ) -{ - yyin = _in_str ; -} - -void yyset_out (FILE * _out_str ) -{ - yyout = _out_str ; -} - -int yyget_debug (void) -{ - return yy_flex_debug; -} - -void yyset_debug (int _bdebug ) -{ - yy_flex_debug = _bdebug ; -} - -static int yy_init_globals (void) -{ - /* Initialization is the same as for the non-reentrant scanner. - * This function is called from yylex_destroy(), so don't allocate here. - */ - - (yy_buffer_stack) = 0; - (yy_buffer_stack_top) = 0; - (yy_buffer_stack_max) = 0; - (yy_c_buf_p) = (char *) 0; - (yy_init) = 0; - (yy_start) = 0; - -/* Defined in main.c */ -#ifdef YY_STDINIT - yyin = stdin; - yyout = stdout; -#else - yyin = (FILE *) 0; - yyout = (FILE *) 0; -#endif - - /* For future reference: Set errno on error, since we are called by - * yylex_init() - */ - return 0; -} - -/* yylex_destroy is for both reentrant and non-reentrant scanners. */ -int yylex_destroy (void) -{ - - /* Pop the buffer stack, destroying each element. */ - while(YY_CURRENT_BUFFER){ - yy_delete_buffer(YY_CURRENT_BUFFER ); - YY_CURRENT_BUFFER_LVALUE = NULL; - yypop_buffer_state(); - } - - /* Destroy the stack itself. */ - yyfree((yy_buffer_stack) ); - (yy_buffer_stack) = NULL; - - /* Reset the globals. This is important in a non-reentrant scanner so the next time - * yylex() is called, initialization will occur. */ - yy_init_globals( ); - - return 0; -} - -/* - * Internal utility routines. - */ - -#ifndef yytext_ptr -static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) -{ - - int i; - for ( i = 0; i < n; ++i ) - s1[i] = s2[i]; -} -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * s ) -{ - int n; - for ( n = 0; s[n]; ++n ) - ; - - return n; -} -#endif - -void *yyalloc (yy_size_t size ) -{ - return (void *) malloc( size ); -} - -void *yyrealloc (void * ptr, yy_size_t size ) -{ - - /* The cast to (char *) in the following accommodates both - * implementations that use char* generic pointers, and those - * that use void* generic pointers. It works with the latter - * because both ANSI C and C++ allow castless assignment from - * any pointer type to void*, and deal with argument conversions - * as though doing an assignment. - */ - return (void *) realloc( (char *) ptr, size ); -} - -void yyfree (void * ptr ) -{ - free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ -} - -#define YYTABLES_NAME "yytables" - -#line 143 "miralang.l" - - - -/* More language-dependent code */ - -void -yystart(void) { - BEGIN INITIAL; -} - diff --git a/judger/core/sim/sim_2_77/options.c b/judger/core/sim/sim_2_77/options.c deleted file mode 100755 index 1e186ecd..00000000 --- a/judger/core/sim/sim_2_77/options.c +++ /dev/null @@ -1,136 +0,0 @@ -/* This file is part of the software similarity tester SIM. - Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: options.c,v 1.10 2012-05-13 09:05:49 Gebruiker Exp $ -*/ - -#include -#include - -#include "options.h" - -static char options[128]; - -static void bad_option( - const char *progname, const struct option *optlist, char *msg, int c -); -static int opt_value( - const char *progname, const struct option *op, - const char *arg, const char *argv[] -); - -static int do_arg( - const char *progname, const struct option *optlist, - const char *arg, const char *argv[] -); - -int -do_options( - const char *progname, const struct option *optlist, - int argc, const char *argv[] -) { - int skips = 0; - - while (argc > 0 && argv[0][0] == '-' && argv[0][1] != '\0') { - int consumed = do_arg(progname, optlist, &argv[0][1], argv); - - argc -= consumed, argv += consumed, skips += consumed; - } - - return skips; -} - -void -set_option(char ch) { - options[(int)ch]++; -} - -int -is_set_option(int ch) { - return options[ch]; -} - -static int -do_arg( - const char *progname, const struct option *optlist, - const char *arg, const char *argv[] -) { - int consumed = 0; - - while (*arg) { - /* treat argument character */ - char opc = *arg++; - const struct option *op; - - for (op = optlist; op->op_char; op++) { - if (opc == op->op_char) { - set_option(opc); - if (op->op_indicator != ' ') { - consumed = opt_value( - progname, op, arg, argv - ); - } - break; - } - } - if (!op->op_char) { - bad_option(progname, optlist, - "*option -%c unknown", opc - ); - /*NOTREACHED*/ - } - if (consumed) break; - } - if (!consumed) { - consumed = 1; - } - - return consumed; -} - -static int -opt_value( - const char *progname, const struct option *op, - const char *arg, const char *argv[] -) { - /* locate the option value */ - if (*arg) { - /* argument is continuation of option */ - *op->op_stringp = arg; - return 1; - } - else - if (argv[1]) { - /* argument follows option */ - *op->op_stringp = argv[1]; - return 2; - } - else { - bad_option(progname, (struct option *)0, - " option -%c requires another argument", - op->op_char - ); - return 0; - /*NOTREACHED*/ - } -} - -static void -bad_option( - const char *progname, const struct option *optlist, char *msg, int c -) { - fprintf(stderr, "%s: ", progname); - fprintf(stderr, &msg[1], c); - fprintf(stderr, "\n"); - - if (msg[0] != ' ') { - const struct option *op; - - fprintf(stderr, "Possible options are:\n"); - for (op = optlist; op->op_char; op++) { - fprintf(stderr, "\t-%c%c\t%s\n", - op->op_char, op->op_indicator, op->op_text - ); - } - } - exit(1); -} diff --git a/judger/core/sim/sim_2_77/pascallang.c b/judger/core/sim/sim_2_77/pascallang.c deleted file mode 100644 index 457e3222..00000000 --- a/judger/core/sim/sim_2_77/pascallang.c +++ /dev/null @@ -1,2153 +0,0 @@ - -#line 3 "" - -#define YY_INT_ALIGNED short int - -/* A lexical scanner generated by flex */ - -#define FLEX_SCANNER -#define YY_FLEX_MAJOR_VERSION 2 -#define YY_FLEX_MINOR_VERSION 6 -#define YY_FLEX_SUBMINOR_VERSION 0 -#if YY_FLEX_SUBMINOR_VERSION > 0 -#define FLEX_BETA -#endif - -/* First, we deal with platform-specific or compiler-specific issues. */ - -/* begin standard C headers. */ -#include -#include -#include -#include - -/* end standard C headers. */ - -/* flex integer type definitions */ - -#ifndef FLEXINT_H -#define FLEXINT_H - -/* C99 systems have . Non-C99 systems may or may not. */ - -#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L - -/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, - * if you want the limit (max/min) macros for int types. - */ -#ifndef __STDC_LIMIT_MACROS -#define __STDC_LIMIT_MACROS 1 -#endif - -#include -typedef int8_t flex_int8_t; -typedef uint8_t flex_uint8_t; -typedef int16_t flex_int16_t; -typedef uint16_t flex_uint16_t; -typedef int32_t flex_int32_t; -typedef uint32_t flex_uint32_t; -#else -typedef signed char flex_int8_t; -typedef short int flex_int16_t; -typedef int flex_int32_t; -typedef unsigned char flex_uint8_t; -typedef unsigned short int flex_uint16_t; -typedef unsigned int flex_uint32_t; - -/* Limits of integral types. */ -#ifndef INT8_MIN -#define INT8_MIN (-128) -#endif -#ifndef INT16_MIN -#define INT16_MIN (-32767-1) -#endif -#ifndef INT32_MIN -#define INT32_MIN (-2147483647-1) -#endif -#ifndef INT8_MAX -#define INT8_MAX (127) -#endif -#ifndef INT16_MAX -#define INT16_MAX (32767) -#endif -#ifndef INT32_MAX -#define INT32_MAX (2147483647) -#endif -#ifndef UINT8_MAX -#define UINT8_MAX (255U) -#endif -#ifndef UINT16_MAX -#define UINT16_MAX (65535U) -#endif -#ifndef UINT32_MAX -#define UINT32_MAX (4294967295U) -#endif - -#endif /* ! C99 */ - -#endif /* ! FLEXINT_H */ - -#ifdef __cplusplus - -/* The "const" storage-class-modifier is valid. */ -#define YY_USE_CONST - -#else /* ! __cplusplus */ - -/* C99 requires __STDC__ to be defined as 1. */ -#if defined (__STDC__) - -#define YY_USE_CONST - -#endif /* defined (__STDC__) */ -#endif /* ! __cplusplus */ - -#ifdef YY_USE_CONST -#define yyconst const -#else -#define yyconst -#endif - -/* Returned upon end-of-file. */ -#define YY_NULL 0 - -/* Promotes a possibly negative, possibly signed char to an unsigned - * integer for use as an array index. If the signed char is negative, - * we want to instead treat it as an 8-bit unsigned char, hence the - * double cast. - */ -#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) - -/* Enter a start condition. This macro really ought to take a parameter, - * but we do it the disgusting crufty way forced on us by the ()-less - * definition of BEGIN. - */ -#define BEGIN (yy_start) = 1 + 2 * - -/* Translate the current start state into a value that can be later handed - * to BEGIN to return to the state. The YYSTATE alias is for lex - * compatibility. - */ -#define YY_START (((yy_start) - 1) / 2) -#define YYSTATE YY_START - -/* Action number for EOF rule of a given start state. */ -#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) - -/* Special action meaning "start processing a new file". */ -#define YY_NEW_FILE yyrestart(yyin ) - -#define YY_END_OF_BUFFER_CHAR 0 - -/* Size of default input buffer. */ -#ifndef YY_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k. - * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. - * Ditto for the __ia64__ case accordingly. - */ -#define YY_BUF_SIZE 32768 -#else -#define YY_BUF_SIZE 16384 -#endif /* __ia64__ */ -#endif - -/* The state buf must be large enough to hold one state per character in the main buffer. - */ -#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) - -#ifndef YY_TYPEDEF_YY_BUFFER_STATE -#define YY_TYPEDEF_YY_BUFFER_STATE -typedef struct yy_buffer_state *YY_BUFFER_STATE; -#endif - -#ifndef YY_TYPEDEF_YY_SIZE_T -#define YY_TYPEDEF_YY_SIZE_T -typedef size_t yy_size_t; -#endif - -extern yy_size_t yyleng; - -extern FILE *yyin, *yyout; - -#define EOB_ACT_CONTINUE_SCAN 0 -#define EOB_ACT_END_OF_FILE 1 -#define EOB_ACT_LAST_MATCH 2 - - #define YY_LESS_LINENO(n) - #define YY_LINENO_REWIND_TO(ptr) - -/* Return all but the first "n" matched characters back to the input stream. */ -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - *yy_cp = (yy_hold_char); \ - YY_RESTORE_YY_MORE_OFFSET \ - (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ - YY_DO_BEFORE_ACTION; /* set up yytext again */ \ - } \ - while ( 0 ) - -#define unput(c) yyunput( c, (yytext_ptr) ) - -#ifndef YY_STRUCT_YY_BUFFER_STATE -#define YY_STRUCT_YY_BUFFER_STATE -struct yy_buffer_state - { - FILE *yy_input_file; - - char *yy_ch_buf; /* input buffer */ - char *yy_buf_pos; /* current position in input buffer */ - - /* Size of input buffer in bytes, not including room for EOB - * characters. - */ - yy_size_t yy_buf_size; - - /* Number of characters read into yy_ch_buf, not including EOB - * characters. - */ - int yy_n_chars; - - /* Whether we "own" the buffer - i.e., we know we created it, - * and can realloc() it to grow it, and should free() it to - * delete it. - */ - int yy_is_our_buffer; - - /* Whether this is an "interactive" input source; if so, and - * if we're using stdio for input, then we want to use getc() - * instead of fread(), to make sure we stop fetching input after - * each newline. - */ - int yy_is_interactive; - - /* Whether we're considered to be at the beginning of a line. - * If so, '^' rules will be active on the next match, otherwise - * not. - */ - int yy_at_bol; - - int yy_bs_lineno; /**< The line count. */ - int yy_bs_column; /**< The column count. */ - - /* Whether to try to fill the input buffer when we reach the - * end of it. - */ - int yy_fill_buffer; - - int yy_buffer_status; - -#define YY_BUFFER_NEW 0 -#define YY_BUFFER_NORMAL 1 - /* When an EOF's been seen but there's still some text to process - * then we mark the buffer as YY_EOF_PENDING, to indicate that we - * shouldn't try reading from the input source any more. We might - * still have a bunch of tokens to match, though, because of - * possible backing-up. - * - * When we actually see the EOF, we change the status to "new" - * (via yyrestart()), so that the user can continue scanning by - * just pointing yyin at a new input file. - */ -#define YY_BUFFER_EOF_PENDING 2 - - }; -#endif /* !YY_STRUCT_YY_BUFFER_STATE */ - -/* Stack of input buffers. */ -static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ -static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ -static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ - -/* We provide macros for accessing buffer states in case in the - * future we want to put the buffer states in a more general - * "scanner state". - * - * Returns the top of the stack, or NULL. - */ -#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ - ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ - : NULL) - -/* Same as previous macro, but useful when we know that the buffer stack is not - * NULL or when we need an lvalue. For internal use only. - */ -#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] - -/* yy_hold_char holds the character lost when yytext is formed. */ -static char yy_hold_char; -static int yy_n_chars; /* number of characters read into yy_ch_buf */ -yy_size_t yyleng; - -/* Points to current character in buffer. */ -static char *yy_c_buf_p = (char *) 0; -static int yy_init = 0; /* whether we need to initialize */ -static int yy_start = 0; /* start state number */ - -/* Flag which is used to allow yywrap()'s to do buffer switches - * instead of setting up a fresh yyin. A bit of a hack ... - */ -static int yy_did_buffer_switch_on_eof; - -void yyrestart (FILE *input_file ); -void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ); -YY_BUFFER_STATE yy_create_buffer (FILE *file,int size ); -void yy_delete_buffer (YY_BUFFER_STATE b ); -void yy_flush_buffer (YY_BUFFER_STATE b ); -void yypush_buffer_state (YY_BUFFER_STATE new_buffer ); -void yypop_buffer_state (void ); - -static void yyensure_buffer_stack (void ); -static void yy_load_buffer_state (void ); -static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file ); - -#define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER ) - -YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ); -YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ); -YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,yy_size_t len ); - -void *yyalloc (yy_size_t ); -void *yyrealloc (void *,yy_size_t ); -void yyfree (void * ); - -#define yy_new_buffer yy_create_buffer - -#define yy_set_interactive(is_interactive) \ - { \ - if ( ! YY_CURRENT_BUFFER ){ \ - yyensure_buffer_stack (); \ - YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer(yyin,YY_BUF_SIZE ); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ - } - -#define yy_set_bol(at_bol) \ - { \ - if ( ! YY_CURRENT_BUFFER ){\ - yyensure_buffer_stack (); \ - YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer(yyin,YY_BUF_SIZE ); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ - } - -#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) - -/* Begin user sect3 */ - -#define yywrap() (/*CONSTCOND*/1) -#define YY_SKIP_YYWRAP - -typedef unsigned char YY_CHAR; - -FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0; - -typedef int yy_state_type; - -extern int yylineno; - -int yylineno = 1; - -extern char *yytext; -#ifdef yytext_ptr -#undef yytext_ptr -#endif -#define yytext_ptr yytext - -static yy_state_type yy_get_previous_state (void ); -static yy_state_type yy_try_NUL_trans (yy_state_type current_state ); -static int yy_get_next_buffer (void ); -#if defined(__GNUC__) && __GNUC__ >= 3 -__attribute__((__noreturn__)) -#endif -static void yy_fatal_error (yyconst char msg[] ); - -/* Done after the current pattern has been matched and before the - * corresponding action - sets up yytext. - */ -#define YY_DO_BEFORE_ACTION \ - (yytext_ptr) = yy_bp; \ - yyleng = (size_t) (yy_cp - yy_bp); \ - (yy_hold_char) = *yy_cp; \ - *yy_cp = '\0'; \ - (yy_c_buf_p) = yy_cp; - -#define YY_NUM_RULES 17 -#define YY_END_OF_BUFFER 18 -/* This struct is not used in this scanner, - but its presence is necessary. */ -struct yy_trans_info - { - flex_int32_t yy_verify; - flex_int32_t yy_nxt; - }; -static yyconst flex_int16_t yy_accept[72] = - { 0, - 0, 0, 0, 0, 18, 16, 14, 13, 14, 15, - 15, 15, 9, 12, 11, 1, 15, 2, 2, 4, - 2, 2, 2, 2, 3, 2, 2, 2, 1, 5, - 2, 0, 6, 0, 1, 9, 10, 11, 0, 8, - 8, 2, 2, 2, 2, 5, 2, 2, 2, 2, - 2, 2, 8, 8, 2, 2, 8, 2, 8, 2, - 8, 2, 8, 2, 7, 2, 7, 7, 2, 2, - 0 - } ; - -static yyconst YY_CHAR yy_ec[256] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, - 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 4, 5, 5, 6, 5, 5, 5, 7, 8, - 9, 10, 5, 5, 5, 5, 5, 11, 11, 11, - 11, 11, 11, 11, 11, 11, 11, 5, 12, 5, - 5, 5, 5, 5, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, - 5, 14, 5, 5, 15, 5, 13, 13, 16, 17, - - 18, 13, 13, 13, 19, 13, 13, 20, 13, 21, - 13, 13, 13, 13, 13, 13, 22, 13, 13, 13, - 13, 13, 23, 5, 24, 5, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1 - } ; - -static yyconst YY_CHAR yy_meta[25] = - { 0, - 1, 2, 3, 2, 1, 1, 1, 4, 1, 5, - 6, 1, 7, 1, 6, 7, 7, 7, 7, 7, - 7, 7, 1, 5 - } ; - -static yyconst flex_uint16_t yy_base[78] = - { 0, - 0, 104, 24, 89, 88, 265, 265, 265, 265, 265, - 42, 74, 72, 265, 74, 265, 48, 0, 0, 265, - 0, 0, 61, 71, 71, 68, 0, 85, 0, 265, - 107, 44, 265, 0, 265, 67, 265, 69, 51, 0, - 55, 0, 123, 0, 49, 265, 63, 0, 0, 0, - 137, 51, 0, 53, 0, 50, 45, 44, 41, 40, - 44, 43, 39, 36, 159, 183, 197, 0, 209, 0, - 265, 231, 235, 241, 248, 255, 257 - } ; - -static yyconst flex_int16_t yy_def[78] = - { 0, - 71, 1, 71, 3, 71, 71, 71, 71, 71, 71, - 72, 71, 71, 71, 73, 71, 74, 75, 75, 71, - 75, 75, 76, 75, 71, 75, 75, 71, 75, 71, - 75, 72, 71, 72, 71, 71, 71, 73, 74, 77, - 77, 75, 76, 75, 76, 71, 75, 75, 28, 31, - 75, 51, 77, 77, 51, 51, 77, 51, 77, 51, - 77, 51, 77, 51, 71, 71, 65, 65, 66, 66, - 0, 71, 71, 71, 71, 71, 71 - } ; - -static yyconst flex_uint16_t yy_nxt[290] = - { 0, - 6, 7, 8, 9, 10, 10, 11, 12, 10, 10, - 13, 14, 15, 10, 10, 15, 15, 15, 15, 15, - 15, 15, 16, 10, 18, 19, 20, 21, 22, 22, - 23, 24, 22, 25, 26, 27, 28, 22, 22, 28, - 28, 28, 28, 28, 28, 28, 29, 30, 33, 39, - 33, 39, 39, 66, 39, 34, 65, 34, 32, 64, - 63, 62, 61, 60, 59, 58, 41, 44, 57, 41, - 32, 56, 32, 47, 45, 54, 37, 36, 47, 46, - 35, 37, 36, 35, 32, 42, 42, 71, 42, 42, - 42, 42, 48, 42, 31, 49, 42, 49, 42, 49, - - 49, 49, 49, 49, 49, 49, 49, 42, 50, 17, - 50, 71, 71, 71, 71, 71, 71, 71, 71, 51, - 71, 71, 51, 51, 51, 52, 51, 51, 51, 44, - 71, 71, 32, 71, 71, 71, 45, 71, 71, 71, - 71, 71, 71, 71, 71, 71, 32, 55, 71, 55, - 71, 55, 55, 55, 55, 55, 55, 55, 55, 67, - 67, 71, 67, 67, 67, 67, 67, 67, 67, 68, - 67, 68, 67, 68, 68, 68, 68, 68, 68, 68, - 68, 67, 67, 69, 69, 71, 69, 69, 69, 69, - 69, 69, 67, 70, 69, 70, 69, 70, 70, 70, - - 70, 70, 70, 70, 70, 69, 67, 67, 71, 67, - 71, 67, 67, 67, 67, 67, 67, 67, 67, 69, - 71, 69, 71, 69, 69, 69, 69, 69, 69, 69, - 69, 32, 32, 71, 32, 32, 32, 32, 38, 71, - 38, 38, 40, 71, 71, 71, 71, 40, 42, 42, - 71, 42, 71, 42, 42, 43, 43, 71, 43, 43, - 43, 43, 53, 53, 5, 71, 71, 71, 71, 71, - 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, - 71, 71, 71, 71, 71, 71, 71, 71, 71 - } ; - -static yyconst flex_int16_t yy_chk[290] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 11, 17, - 32, 17, 39, 64, 39, 11, 63, 32, 45, 62, - 61, 60, 59, 58, 57, 56, 17, 23, 54, 39, - 23, 52, 45, 47, 23, 41, 38, 36, 26, 25, - 24, 15, 13, 12, 23, 28, 28, 5, 28, 28, - 28, 28, 28, 28, 4, 28, 28, 28, 28, 28, - - 28, 28, 28, 28, 28, 28, 28, 28, 31, 2, - 31, 0, 0, 0, 0, 0, 0, 0, 0, 31, - 0, 0, 31, 31, 31, 31, 31, 31, 31, 43, - 0, 0, 43, 0, 0, 0, 43, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 43, 51, 0, 51, - 0, 51, 51, 51, 51, 51, 51, 51, 51, 65, - 65, 0, 65, 65, 65, 65, 65, 65, 65, 65, - 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, - 65, 65, 65, 66, 66, 0, 66, 66, 66, 66, - 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, - - 66, 66, 66, 66, 66, 66, 66, 67, 0, 67, - 0, 67, 67, 67, 67, 67, 67, 67, 67, 69, - 0, 69, 0, 69, 69, 69, 69, 69, 69, 69, - 69, 72, 72, 0, 72, 72, 72, 72, 73, 0, - 73, 73, 74, 0, 0, 0, 0, 74, 75, 75, - 0, 75, 0, 75, 75, 76, 76, 0, 76, 76, - 76, 76, 77, 77, 71, 71, 71, 71, 71, 71, - 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, - 71, 71, 71, 71, 71, 71, 71, 71, 71 - } ; - -static yy_state_type yy_last_accepting_state; -static char *yy_last_accepting_cpos; - -extern int yy_flex_debug; -int yy_flex_debug = 0; - -/* The intent behind this definition is that it'll catch - * any uses of REJECT which flex missed. - */ -#define REJECT reject_used_but_not_detected -#define yymore() yymore_used_but_not_detected -#define YY_MORE_ADJ 0 -#define YY_RESTORE_YY_MORE_OFFSET -char *yytext; -#line 1 "pascallang.l" -#line 2 "pascallang.l" -/* This file is part of the software similarity tester SIM. - Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: pascallang.l,v 2.19 2013-04-28 16:30:42 Gebruiker Exp $ -*/ - -/* - PASCAL language front end for the similarity tester. - Author: Maarten van der Meulen - Date: May 1986 -*/ - -#include "options.h" -#include "token.h" -#include "language.h" -#include "algollike.h" -#include "idf.h" -#include "lex.h" -#include "lang.h" - -/* General language front end data */ -Token lex_token; -size_t lex_nl_cnt; -size_t lex_tk_cnt; -size_t lex_non_ascii_cnt; - -/* Language-dependent data */ - -/* Data for module idf */ - -static const struct idf ppcmd[] = { - {"define", META('d')}, - {"else", META('e')}, - {"endif", META('E')}, - {"if", META('i')}, - {"ifdef", META('I')}, - {"ifndef", META('x')}, - {"include", MTCT('I')}, - {"line", META('l')}, - {"undef", META('u')} -}; - -static const struct idf reserved[] = { - {"and", NORM('&')}, - {"array", NORM('A')}, - {"begin", NORM('{')}, - {"case", NORM('c')}, - {"const", NORM('C')}, - {"div", NORM('/')}, - {"do", NORM('D')}, - {"downto", NORM('d')}, - {"else", NORM('e')}, - {"end", NORM('}')}, - {"extern", CTRL('E')}, - {"file", NORM('F')}, - {"for", NORM('f')}, - {"function", NORM('p')}, /* Equal to procedure */ - {"goto", NORM('g')}, - {"if", NORM('i')}, - {"in", NORM('I')}, - {"label", NORM('l')}, - {"mod", NORM('%')}, - {"nil", NORM('n')}, - {"not", NORM('!')}, - {"of", No_Token}, - {"or", NORM('|')}, - {"packed", NORM('P')}, - {"procedure", NORM('p')}, - {"program", No_Token}, - {"record", NORM('r')}, - {"repeat", NORM('R')}, - {"set", NORM('s')}, - {"then", No_Token}, - {"to", NORM('t')}, - {"type", NORM('T')}, - {"until", NORM('u')}, - {"var", NORM('v')}, - {"while", NORM('w')}, - {"with", NORM('W')} -}; - -/* Special treatment of identifiers */ - -static void -lower_case(char *str) { - /* Turns upper case into lower case, since Pascal does not - distinguish between them. - */ - char *s; - - for (s = str; *s; s++) { - if ('A' <= *s && *s <= 'Z') { - *s += (-'A' + 'a'); - } - } -} - -static Token -idf2token(int hashing) { - Token tk; - - lower_case(yytext); - tk = idf_in_list(yytext, reserved, sizeof reserved, IDF); - if (Token_EQ(tk, IDF) && hashing) { - /* return a one-Token hash code */ - tk = idf_hashed(yytext); - } - return tk; -} - -/* Token sets for module algollike */ -const Token Non_Finals[] = { - IDF, /* identifier */ - NORM('{'), /* also begin */ - NORM('('), - NORM('['), - NORM('A'), /* array */ - NORM('c'), /* case */ - NORM('C'), /* const */ - NORM('/'), /* div */ - CTRL('E'), /* extern */ - NORM('F'), /* file */ - NORM('f'), /* for */ - NORM('g'), /* goto */ - NORM('i'), /* if */ - NORM('l'), /* label */ - NORM('P'), /* packed */ - NORM('p'), /* procedure/function */ - NORM('r'), /* record */ - NORM('R'), /* repeat */ - NORM('s'), /* set */ - NORM('T'), /* type */ - NORM('v'), /* var */ - NORM('w'), /* while */ - NORM('W'), /* with */ - No_Token -}; -const Token Non_Initials[] = { - NORM(')'), - NORM('}'), - NORM(';'), - No_Token -}; -const Token Openers[] = { - NORM('{'), - NORM('('), - NORM('['), - No_Token -}; -const Token Closers[] = { - NORM('}'), - NORM(')'), - NORM(']'), - No_Token -}; - -/* Language-dependent code */ - -void -Init_Language(void) { - Init_Algol_Language(Non_Finals, Non_Initials, Openers, Closers); -} - - -int -May_Be_Start_Of_Run(Token ch) { - return May_Be_Start_Of_Algol_Run(ch); -} - -size_t -Best_Run_Size(const Token *str, size_t size) { - return Best_Algol_Run_Size(str, size); -} - - -#line 726 "" - -#define INITIAL 0 -#define Comment 1 - -#ifndef YY_NO_UNISTD_H -/* Special case for "unistd.h", since it is non-ANSI. We include it way - * down here because we want the user's section 1 to have been scanned first. - * The user has a chance to override it with an option. - */ -#include -#endif - -#ifndef YY_EXTRA_TYPE -#define YY_EXTRA_TYPE void * -#endif - -static int yy_init_globals (void ); - -/* Accessor methods to globals. - These are made visible to non-reentrant scanners for convenience. */ - -int yylex_destroy (void ); - -int yyget_debug (void ); - -void yyset_debug (int debug_flag ); - -YY_EXTRA_TYPE yyget_extra (void ); - -void yyset_extra (YY_EXTRA_TYPE user_defined ); - -FILE *yyget_in (void ); - -void yyset_in (FILE * _in_str ); - -FILE *yyget_out (void ); - -void yyset_out (FILE * _out_str ); - -yy_size_t yyget_leng (void ); - -char *yyget_text (void ); - -int yyget_lineno (void ); - -void yyset_lineno (int _line_number ); - -/* Macros after this point can all be overridden by user definitions in - * section 1. - */ - -#ifndef YY_SKIP_YYWRAP -#ifdef __cplusplus -extern "C" int yywrap (void ); -#else -extern int yywrap (void ); -#endif -#endif - -#ifndef YY_NO_UNPUT - - static void yyunput (int c,char *buf_ptr ); - -#endif - -#ifndef yytext_ptr -static void yy_flex_strncpy (char *,yyconst char *,int ); -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * ); -#endif - -#ifndef YY_NO_INPUT - -#ifdef __cplusplus -static int yyinput (void ); -#else -static int input (void ); -#endif - -#endif - -/* Amount of stuff to slurp up with each read. */ -#ifndef YY_READ_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k */ -#define YY_READ_BUF_SIZE 16384 -#else -#define YY_READ_BUF_SIZE 8192 -#endif /* __ia64__ */ -#endif - -/* Copy whatever the last rule matched to the standard output. */ -#ifndef ECHO -/* This used to be an fputs(), but since the string might contain NUL's, - * we now use fwrite(). - */ -#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0) -#endif - -/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, - * is returned in "result". - */ -#ifndef YY_INPUT -#define YY_INPUT(buf,result,max_size) \ - if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ - { \ - int c = '*'; \ - size_t n; \ - for ( n = 0; n < max_size && \ - (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ - buf[n] = (char) c; \ - if ( c == '\n' ) \ - buf[n++] = (char) c; \ - if ( c == EOF && ferror( yyin ) ) \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - result = n; \ - } \ - else \ - { \ - errno=0; \ - while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \ - { \ - if( errno != EINTR) \ - { \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - break; \ - } \ - errno=0; \ - clearerr(yyin); \ - } \ - }\ -\ - -#endif - -/* No semi-colon after return; correct usage is to write "yyterminate();" - - * we don't want an extra ';' after the "return" because that will cause - * some compilers to complain about unreachable statements. - */ -#ifndef yyterminate -#define yyterminate() return YY_NULL -#endif - -/* Number of entries by which start-condition stack grows. */ -#ifndef YY_START_STACK_INCR -#define YY_START_STACK_INCR 25 -#endif - -/* Report a fatal error. */ -#ifndef YY_FATAL_ERROR -#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) -#endif - -/* end tables serialization structures and prototypes */ - -/* Default declaration of generated scanner - a define so the user can - * easily add parameters. - */ -#ifndef YY_DECL -#define YY_DECL_IS_OURS 1 - -extern int yylex (void); - -#define YY_DECL int yylex (void) -#endif /* !YY_DECL */ - -/* Code executed at the beginning of each rule, after yytext and yyleng - * have been set up. - */ -#ifndef YY_USER_ACTION -#define YY_USER_ACTION -#endif - -/* Code executed at the end of each rule. */ -#ifndef YY_BREAK -#define YY_BREAK /*LINTED*/break; -#endif - -#define YY_RULE_SETUP \ - if ( yyleng > 0 ) \ - YY_CURRENT_BUFFER_LVALUE->yy_at_bol = \ - (yytext[yyleng - 1] == '\n'); \ - YY_USER_ACTION - -/** The main scanner function which does all the work. - */ -YY_DECL -{ - yy_state_type yy_current_state; - char *yy_cp, *yy_bp; - int yy_act; - - if ( !(yy_init) ) - { - (yy_init) = 1; - -#ifdef YY_USER_INIT - YY_USER_INIT; -#endif - - if ( ! (yy_start) ) - (yy_start) = 1; /* first start state */ - - if ( ! yyin ) - yyin = stdin; - - if ( ! yyout ) - yyout = stdout; - - if ( ! YY_CURRENT_BUFFER ) { - yyensure_buffer_stack (); - YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer(yyin,YY_BUF_SIZE ); - } - - yy_load_buffer_state( ); - } - - { -#line 195 "pascallang.l" - - -#line 951 "" - - while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ - { - yy_cp = (yy_c_buf_p); - - /* Support of yytext. */ - *yy_cp = (yy_hold_char); - - /* yy_bp points to the position in yy_ch_buf of the start of - * the current run. - */ - yy_bp = yy_cp; - - yy_current_state = (yy_start); - yy_current_state += YY_AT_BOL(); -yy_match: - do - { - YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 72 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - ++yy_cp; - } - while ( yy_base[yy_current_state] != 265 ); - -yy_find_action: - yy_act = yy_accept[yy_current_state]; - if ( yy_act == 0 ) - { /* have to back up */ - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - yy_act = yy_accept[yy_current_state]; - } - - YY_DO_BEFORE_ACTION; - -do_action: /* This label is used only to access EOF actions. */ - - switch ( yy_act ) - { /* beginning of action switch */ - case 0: /* must back up */ - /* undo the effects of YY_DO_BEFORE_ACTION */ - *yy_cp = (yy_hold_char); - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - goto yy_find_action; - -case 1: -YY_RULE_SETUP -#line 197 "pascallang.l" -{ /* See clang.l */ - BEGIN Comment; - } - YY_BREAK -case 2: -YY_RULE_SETUP -#line 201 "pascallang.l" -{ /* safe comment chunk */ - } - YY_BREAK -case 3: -YY_RULE_SETUP -#line 204 "pascallang.l" -{ /* unsafe char, read one by one */ - } - YY_BREAK -case 4: -/* rule 4 can match eol */ -YY_RULE_SETUP -#line 207 "pascallang.l" -{ /* to break up long comments */ - return_eol(); - } - YY_BREAK -case 5: -YY_RULE_SETUP -#line 211 "pascallang.l" -{ /* end-of-comment */ - BEGIN INITIAL; - } - YY_BREAK -case 6: -YY_RULE_SETUP -#line 215 "pascallang.l" -{ /* character strings */ - return_ch('"'); - } - YY_BREAK -case 7: -YY_RULE_SETUP -#line 219 "pascallang.l" -{ /* ignore #include lines */ - } - YY_BREAK -case 8: -YY_RULE_SETUP -#line 222 "pascallang.l" -{ /* a preprocessor line */ - char *idf = yytext+1; - - /* skip layout in front of preprocessor identifier */ - while (*idf == ' ' || *idf == '\t') { - idf++; - } - return_tk(idf_in_list(idf, ppcmd, sizeof ppcmd, NORM('#'))); - } - YY_BREAK -case 9: -YY_RULE_SETUP -#line 232 "pascallang.l" -{ /* numeral, passed as an identifier */ - return_tk(IDF); - } - YY_BREAK -case 10: -*yy_cp = (yy_hold_char); /* undo effects of setting up yytext */ -(yy_c_buf_p) = yy_cp -= 1; -YY_DO_BEFORE_ACTION; /* set up yytext again */ -YY_RULE_SETUP -#line 236 "pascallang.l" -{ /* identifier in front of ( */ - Token tk; - - tk = idf2token(is_set_option('F')); - if (!Token_EQ(tk, No_Token)) return_tk(tk); - } - YY_BREAK -case 11: -YY_RULE_SETUP -#line 243 "pascallang.l" -{ /* identifier */ - Token tk; - - tk = idf2token(0 /* no hashing */); - if (!Token_EQ(tk, No_Token)) return_tk(tk); - } - YY_BREAK -case 12: -YY_RULE_SETUP -#line 250 "pascallang.l" -{ /* semicolon, conditionally ignored */ - if (is_set_option('f')) return_ch(yytext[0]); - } - YY_BREAK -case 13: -/* rule 13 can match eol */ -YY_RULE_SETUP -#line 254 "pascallang.l" -{ /* count newlines */ - return_eol(); - } - YY_BREAK -case 14: -YY_RULE_SETUP -#line 258 "pascallang.l" -{ /* ignore layout */ - } - YY_BREAK -case 15: -YY_RULE_SETUP -#line 261 "pascallang.l" -{ /* copy other text */ - return_ch(yytext[0]); - } - YY_BREAK -case 16: -YY_RULE_SETUP -#line 265 "pascallang.l" -{ /* count non-ASCII chars */ - lex_non_ascii_cnt++; - } - YY_BREAK -case 17: -YY_RULE_SETUP -#line 269 "pascallang.l" -ECHO; - YY_BREAK -#line 1139 "" -case YY_STATE_EOF(INITIAL): -case YY_STATE_EOF(Comment): - yyterminate(); - - case YY_END_OF_BUFFER: - { - /* Amount of text matched not including the EOB char. */ - int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; - - /* Undo the effects of YY_DO_BEFORE_ACTION. */ - *yy_cp = (yy_hold_char); - YY_RESTORE_YY_MORE_OFFSET - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) - { - /* We're scanning a new file or input source. It's - * possible that this happened because the user - * just pointed yyin at a new source and called - * yylex(). If so, then we have to assure - * consistency between YY_CURRENT_BUFFER and our - * globals. Here is the right place to do so, because - * this is the first action (other than possibly a - * back-up) that will match for the new input source. - */ - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; - } - - /* Note that here we test for yy_c_buf_p "<=" to the position - * of the first EOB in the buffer, since yy_c_buf_p will - * already have been incremented past the NUL character - * (since all states make transitions on EOB to the - * end-of-buffer state). Contrast this with the test - * in input(). - */ - if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) - { /* This was really a NUL. */ - yy_state_type yy_next_state; - - (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( ); - - /* Okay, we're now positioned to make the NUL - * transition. We couldn't have - * yy_get_previous_state() go ahead and do it - * for us because it doesn't know how to deal - * with the possibility of jamming (and we don't - * want to build jamming into it because then it - * will run more slowly). - */ - - yy_next_state = yy_try_NUL_trans( yy_current_state ); - - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - - if ( yy_next_state ) - { - /* Consume the NUL. */ - yy_cp = ++(yy_c_buf_p); - yy_current_state = yy_next_state; - goto yy_match; - } - - else - { - yy_cp = (yy_c_buf_p); - goto yy_find_action; - } - } - - else switch ( yy_get_next_buffer( ) ) - { - case EOB_ACT_END_OF_FILE: - { - (yy_did_buffer_switch_on_eof) = 0; - - if ( yywrap( ) ) - { - /* Note: because we've taken care in - * yy_get_next_buffer() to have set up - * yytext, we can now set up - * yy_c_buf_p so that if some total - * hoser (like flex itself) wants to - * call the scanner after we return the - * YY_NULL, it'll still work - another - * YY_NULL will get returned. - */ - (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; - - yy_act = YY_STATE_EOF(YY_START); - goto do_action; - } - - else - { - if ( ! (yy_did_buffer_switch_on_eof) ) - YY_NEW_FILE; - } - break; - } - - case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = - (yytext_ptr) + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( ); - - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - goto yy_match; - - case EOB_ACT_LAST_MATCH: - (yy_c_buf_p) = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; - - yy_current_state = yy_get_previous_state( ); - - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - goto yy_find_action; - } - break; - } - - default: - YY_FATAL_ERROR( - "fatal flex scanner internal error--no action found" ); - } /* end of action switch */ - } /* end of scanning one token */ - } /* end of user's declarations */ -} /* end of yylex */ - -/* yy_get_next_buffer - try to read in a new buffer - * - * Returns a code representing an action: - * EOB_ACT_LAST_MATCH - - * EOB_ACT_CONTINUE_SCAN - continue scanning from current position - * EOB_ACT_END_OF_FILE - end of file - */ -static int yy_get_next_buffer (void) -{ - char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; - char *source = (yytext_ptr); - yy_size_t number_to_move, i; - int ret_val; - - if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) - YY_FATAL_ERROR( - "fatal flex scanner internal error--end of buffer missed" ); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) - { /* Don't try to fill the buffer, so this is an EOF. */ - if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) - { - /* We matched a single character, the EOB, so - * treat this as a final EOF. - */ - return EOB_ACT_END_OF_FILE; - } - - else - { - /* We matched some text prior to the EOB, first - * process it. - */ - return EOB_ACT_LAST_MATCH; - } - } - - /* Try to read more data. */ - - /* First move last chars to start of buffer. */ - number_to_move = (yy_size_t) ((yy_c_buf_p) - (yytext_ptr)) - 1; - - for ( i = 0; i < number_to_move; ++i ) - *(dest++) = *(source++); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) - /* don't do the read, it's not guaranteed to return an EOF, - * just force an EOF - */ - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; - - else - { - yy_size_t num_to_read = - YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; - - while ( num_to_read <= 0 ) - { /* Not enough room in the buffer - grow it. */ - - /* just a shorter name for the current buffer */ - YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; - - int yy_c_buf_p_offset = - (int) ((yy_c_buf_p) - b->yy_ch_buf); - - if ( b->yy_is_our_buffer ) - { - yy_size_t new_size = b->yy_buf_size * 2; - - if ( new_size <= 0 ) - b->yy_buf_size += b->yy_buf_size / 8; - else - b->yy_buf_size *= 2; - - b->yy_ch_buf = (char *) - /* Include room in for 2 EOB chars. */ - yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ); - } - else - /* Can't grow it, we don't own it. */ - b->yy_ch_buf = 0; - - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( - "fatal error - scanner input buffer overflow" ); - - (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; - - num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - - number_to_move - 1; - - } - - if ( num_to_read > YY_READ_BUF_SIZE ) - num_to_read = YY_READ_BUF_SIZE; - - /* Read in more data. */ - YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), - (yy_n_chars), num_to_read ); - - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - if ( (yy_n_chars) == 0 ) - { - if ( number_to_move == YY_MORE_ADJ ) - { - ret_val = EOB_ACT_END_OF_FILE; - yyrestart(yyin ); - } - - else - { - ret_val = EOB_ACT_LAST_MATCH; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = - YY_BUFFER_EOF_PENDING; - } - } - - else - ret_val = EOB_ACT_CONTINUE_SCAN; - - if ((int) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { - /* Extend the array by 50%, plus the number we really need. */ - int new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ); - if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); - } - - (yy_n_chars) += number_to_move; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; - - (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; - - return ret_val; -} - -/* yy_get_previous_state - get the state just before the EOB char was reached */ - - static yy_state_type yy_get_previous_state (void) -{ - yy_state_type yy_current_state; - char *yy_cp; - - yy_current_state = (yy_start); - yy_current_state += YY_AT_BOL(); - - for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) - { - YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 72 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - } - - return yy_current_state; -} - -/* yy_try_NUL_trans - try to make a transition on the NUL character - * - * synopsis - * next_state = yy_try_NUL_trans( current_state ); - */ - static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) -{ - int yy_is_jam; - char *yy_cp = (yy_c_buf_p); - - YY_CHAR yy_c = 1; - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 72 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - yy_is_jam = (yy_current_state == 71); - - return yy_is_jam ? 0 : yy_current_state; -} - -#ifndef YY_NO_UNPUT - - static void yyunput (int c, char * yy_bp ) -{ - char *yy_cp; - - yy_cp = (yy_c_buf_p); - - /* undo effects of setting up yytext */ - *yy_cp = (yy_hold_char); - - if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) - { /* need to shift things up to make room */ - /* +2 for EOB chars. */ - yy_size_t number_to_move = (yy_n_chars) + 2; - char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ - YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; - char *source = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; - - while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) - *--dest = *--source; - - yy_cp += (int) (dest - source); - yy_bp += (int) (dest - source); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size; - - if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) - YY_FATAL_ERROR( "flex scanner push-back overflow" ); - } - - *--yy_cp = (char) c; - - (yytext_ptr) = yy_bp; - (yy_hold_char) = *yy_cp; - (yy_c_buf_p) = yy_cp; -} - -#endif - -#ifndef YY_NO_INPUT -#ifdef __cplusplus - static int yyinput (void) -#else - static int input (void) -#endif - -{ - int c; - - *(yy_c_buf_p) = (yy_hold_char); - - if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) - { - /* yy_c_buf_p now points to the character we want to return. - * If this occurs *before* the EOB characters, then it's a - * valid NUL; if not, then we've hit the end of the buffer. - */ - if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) - /* This was really a NUL. */ - *(yy_c_buf_p) = '\0'; - - else - { /* need more input */ - yy_size_t offset = (yy_c_buf_p) - (yytext_ptr); - ++(yy_c_buf_p); - - switch ( yy_get_next_buffer( ) ) - { - case EOB_ACT_LAST_MATCH: - /* This happens because yy_g_n_b() - * sees that we've accumulated a - * token and flags that we need to - * try matching the token before - * proceeding. But for input(), - * there's no matching to consider. - * So convert the EOB_ACT_LAST_MATCH - * to EOB_ACT_END_OF_FILE. - */ - - /* Reset buffer status. */ - yyrestart(yyin ); - - /*FALLTHROUGH*/ - - case EOB_ACT_END_OF_FILE: - { - if ( yywrap( ) ) - return EOF; - - if ( ! (yy_did_buffer_switch_on_eof) ) - YY_NEW_FILE; -#ifdef __cplusplus - return yyinput(); -#else - return input(); -#endif - } - - case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = (yytext_ptr) + offset; - break; - } - } - } - - c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ - *(yy_c_buf_p) = '\0'; /* preserve yytext */ - (yy_hold_char) = *++(yy_c_buf_p); - - YY_CURRENT_BUFFER_LVALUE->yy_at_bol = (c == '\n'); - - return c; -} -#endif /* ifndef YY_NO_INPUT */ - -/** Immediately switch to a different input stream. - * @param input_file A readable stream. - * - * @note This function does not reset the start condition to @c INITIAL . - */ - void yyrestart (FILE * input_file ) -{ - - if ( ! YY_CURRENT_BUFFER ){ - yyensure_buffer_stack (); - YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer(yyin,YY_BUF_SIZE ); - } - - yy_init_buffer(YY_CURRENT_BUFFER,input_file ); - yy_load_buffer_state( ); -} - -/** Switch to a different input buffer. - * @param new_buffer The new input buffer. - * - */ - void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) -{ - - /* TODO. We should be able to replace this entire function body - * with - * yypop_buffer_state(); - * yypush_buffer_state(new_buffer); - */ - yyensure_buffer_stack (); - if ( YY_CURRENT_BUFFER == new_buffer ) - return; - - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - YY_CURRENT_BUFFER_LVALUE = new_buffer; - yy_load_buffer_state( ); - - /* We don't actually know whether we did this switch during - * EOF (yywrap()) processing, but the only time this flag - * is looked at is after yywrap() is called, so it's safe - * to go ahead and always set it. - */ - (yy_did_buffer_switch_on_eof) = 1; -} - -static void yy_load_buffer_state (void) -{ - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; - yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; - (yy_hold_char) = *(yy_c_buf_p); -} - -/** Allocate and initialize an input buffer state. - * @param file A readable stream. - * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. - * - * @return the allocated buffer state. - */ - YY_BUFFER_STATE yy_create_buffer (FILE * file, int size ) -{ - YY_BUFFER_STATE b; - - b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - - b->yy_buf_size = (yy_size_t)size; - - /* yy_ch_buf has to be 2 characters longer than the size given because - * we need to put in 2 end-of-buffer characters. - */ - b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 ); - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - - b->yy_is_our_buffer = 1; - - yy_init_buffer(b,file ); - - return b; -} - -/** Destroy the buffer. - * @param b a buffer created with yy_create_buffer() - * - */ - void yy_delete_buffer (YY_BUFFER_STATE b ) -{ - - if ( ! b ) - return; - - if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ - YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; - - if ( b->yy_is_our_buffer ) - yyfree((void *) b->yy_ch_buf ); - - yyfree((void *) b ); -} - -/* Initializes or reinitializes a buffer. - * This function is sometimes called more than once on the same buffer, - * such as during a yyrestart() or at EOF. - */ - static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file ) - -{ - int oerrno = errno; - - yy_flush_buffer(b ); - - b->yy_input_file = file; - b->yy_fill_buffer = 1; - - /* If b is the current buffer, then yy_init_buffer was _probably_ - * called from yyrestart() or through yy_get_next_buffer. - * In that case, we don't want to reset the lineno or column. - */ - if (b != YY_CURRENT_BUFFER){ - b->yy_bs_lineno = 1; - b->yy_bs_column = 0; - } - - b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; - - errno = oerrno; -} - -/** Discard all buffered characters. On the next scan, YY_INPUT will be called. - * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. - * - */ - void yy_flush_buffer (YY_BUFFER_STATE b ) -{ - if ( ! b ) - return; - - b->yy_n_chars = 0; - - /* We always need two end-of-buffer characters. The first causes - * a transition to the end-of-buffer state. The second causes - * a jam in that state. - */ - b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; - b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; - - b->yy_buf_pos = &b->yy_ch_buf[0]; - - b->yy_at_bol = 1; - b->yy_buffer_status = YY_BUFFER_NEW; - - if ( b == YY_CURRENT_BUFFER ) - yy_load_buffer_state( ); -} - -/** Pushes the new state onto the stack. The new state becomes - * the current state. This function will allocate the stack - * if necessary. - * @param new_buffer The new state. - * - */ -void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) -{ - if (new_buffer == NULL) - return; - - yyensure_buffer_stack(); - - /* This block is copied from yy_switch_to_buffer. */ - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - /* Only push if top exists. Otherwise, replace top. */ - if (YY_CURRENT_BUFFER) - (yy_buffer_stack_top)++; - YY_CURRENT_BUFFER_LVALUE = new_buffer; - - /* copied from yy_switch_to_buffer. */ - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; -} - -/** Removes and deletes the top of the stack, if present. - * The next element becomes the new top. - * - */ -void yypop_buffer_state (void) -{ - if (!YY_CURRENT_BUFFER) - return; - - yy_delete_buffer(YY_CURRENT_BUFFER ); - YY_CURRENT_BUFFER_LVALUE = NULL; - if ((yy_buffer_stack_top) > 0) - --(yy_buffer_stack_top); - - if (YY_CURRENT_BUFFER) { - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; - } -} - -/* Allocates the stack if it does not exist. - * Guarantees space for at least one push. - */ -static void yyensure_buffer_stack (void) -{ - yy_size_t num_to_alloc; - - if (!(yy_buffer_stack)) { - - /* First allocation is just for 2 elements, since we don't know if this - * scanner will even need a stack. We use 2 instead of 1 to avoid an - * immediate realloc on the next call. - */ - num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ - (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc - (num_to_alloc * sizeof(struct yy_buffer_state*) - ); - if ( ! (yy_buffer_stack) ) - YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); - - memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); - - (yy_buffer_stack_max) = num_to_alloc; - (yy_buffer_stack_top) = 0; - return; - } - - if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ - - /* Increase the buffer to prepare for a possible push. */ - yy_size_t grow_size = 8 /* arbitrary grow size */; - - num_to_alloc = (yy_buffer_stack_max) + grow_size; - (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc - ((yy_buffer_stack), - num_to_alloc * sizeof(struct yy_buffer_state*) - ); - if ( ! (yy_buffer_stack) ) - YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); - - /* zero only the new slots.*/ - memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); - (yy_buffer_stack_max) = num_to_alloc; - } -} - -/** Setup the input buffer state to scan directly from a user-specified character buffer. - * @param base the character buffer - * @param size the size in bytes of the character buffer - * - * @return the newly allocated buffer state object. - */ -YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) -{ - YY_BUFFER_STATE b; - - if ( size < 2 || - base[size-2] != YY_END_OF_BUFFER_CHAR || - base[size-1] != YY_END_OF_BUFFER_CHAR ) - /* They forgot to leave room for the EOB's. */ - return 0; - - b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); - - b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ - b->yy_buf_pos = b->yy_ch_buf = base; - b->yy_is_our_buffer = 0; - b->yy_input_file = 0; - b->yy_n_chars = b->yy_buf_size; - b->yy_is_interactive = 0; - b->yy_at_bol = 1; - b->yy_fill_buffer = 0; - b->yy_buffer_status = YY_BUFFER_NEW; - - yy_switch_to_buffer(b ); - - return b; -} - -/** Setup the input buffer state to scan a string. The next call to yylex() will - * scan from a @e copy of @a str. - * @param yystr a NUL-terminated string to scan - * - * @return the newly allocated buffer state object. - * @note If you want to scan bytes that may contain NUL values, then use - * yy_scan_bytes() instead. - */ -YY_BUFFER_STATE yy_scan_string (yyconst char * yystr ) -{ - - return yy_scan_bytes(yystr,strlen(yystr) ); -} - -/** Setup the input buffer state to scan the given bytes. The next call to yylex() will - * scan from a @e copy of @a bytes. - * @param yybytes the byte buffer to scan - * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. - * - * @return the newly allocated buffer state object. - */ -YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len ) -{ - YY_BUFFER_STATE b; - char *buf; - yy_size_t n; - yy_size_t i; - - /* Get memory for full buffer, including space for trailing EOB's. */ - n = _yybytes_len + 2; - buf = (char *) yyalloc(n ); - if ( ! buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); - - for ( i = 0; i < _yybytes_len; ++i ) - buf[i] = yybytes[i]; - - buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; - - b = yy_scan_buffer(buf,n ); - if ( ! b ) - YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); - - /* It's okay to grow etc. this buffer, and we should throw it - * away when we're done. - */ - b->yy_is_our_buffer = 1; - - return b; -} - -#ifndef YY_EXIT_FAILURE -#define YY_EXIT_FAILURE 2 -#endif - -static void yy_fatal_error (yyconst char* msg ) -{ - (void) fprintf( stderr, "%s\n", msg ); - exit( YY_EXIT_FAILURE ); -} - -/* Redefine yyless() so it works in section 3 code. */ - -#undef yyless -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - yytext[yyleng] = (yy_hold_char); \ - (yy_c_buf_p) = yytext + yyless_macro_arg; \ - (yy_hold_char) = *(yy_c_buf_p); \ - *(yy_c_buf_p) = '\0'; \ - yyleng = yyless_macro_arg; \ - } \ - while ( 0 ) - -/* Accessor methods (get/set functions) to struct members. */ - -/** Get the current line number. - * - */ -int yyget_lineno (void) -{ - - return yylineno; -} - -/** Get the input stream. - * - */ -FILE *yyget_in (void) -{ - return yyin; -} - -/** Get the output stream. - * - */ -FILE *yyget_out (void) -{ - return yyout; -} - -/** Get the length of the current token. - * - */ -yy_size_t yyget_leng (void) -{ - return yyleng; -} - -/** Get the current token. - * - */ - -char *yyget_text (void) -{ - return yytext; -} - -/** Set the current line number. - * @param _line_number line number - * - */ -void yyset_lineno (int _line_number ) -{ - - yylineno = _line_number; -} - -/** Set the input stream. This does not discard the current - * input buffer. - * @param _in_str A readable stream. - * - * @see yy_switch_to_buffer - */ -void yyset_in (FILE * _in_str ) -{ - yyin = _in_str ; -} - -void yyset_out (FILE * _out_str ) -{ - yyout = _out_str ; -} - -int yyget_debug (void) -{ - return yy_flex_debug; -} - -void yyset_debug (int _bdebug ) -{ - yy_flex_debug = _bdebug ; -} - -static int yy_init_globals (void) -{ - /* Initialization is the same as for the non-reentrant scanner. - * This function is called from yylex_destroy(), so don't allocate here. - */ - - (yy_buffer_stack) = 0; - (yy_buffer_stack_top) = 0; - (yy_buffer_stack_max) = 0; - (yy_c_buf_p) = (char *) 0; - (yy_init) = 0; - (yy_start) = 0; - -/* Defined in main.c */ -#ifdef YY_STDINIT - yyin = stdin; - yyout = stdout; -#else - yyin = (FILE *) 0; - yyout = (FILE *) 0; -#endif - - /* For future reference: Set errno on error, since we are called by - * yylex_init() - */ - return 0; -} - -/* yylex_destroy is for both reentrant and non-reentrant scanners. */ -int yylex_destroy (void) -{ - - /* Pop the buffer stack, destroying each element. */ - while(YY_CURRENT_BUFFER){ - yy_delete_buffer(YY_CURRENT_BUFFER ); - YY_CURRENT_BUFFER_LVALUE = NULL; - yypop_buffer_state(); - } - - /* Destroy the stack itself. */ - yyfree((yy_buffer_stack) ); - (yy_buffer_stack) = NULL; - - /* Reset the globals. This is important in a non-reentrant scanner so the next time - * yylex() is called, initialization will occur. */ - yy_init_globals( ); - - return 0; -} - -/* - * Internal utility routines. - */ - -#ifndef yytext_ptr -static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) -{ - - int i; - for ( i = 0; i < n; ++i ) - s1[i] = s2[i]; -} -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * s ) -{ - int n; - for ( n = 0; s[n]; ++n ) - ; - - return n; -} -#endif - -void *yyalloc (yy_size_t size ) -{ - return (void *) malloc( size ); -} - -void *yyrealloc (void * ptr, yy_size_t size ) -{ - - /* The cast to (char *) in the following accommodates both - * implementations that use char* generic pointers, and those - * that use void* generic pointers. It works with the latter - * because both ANSI C and C++ allow castless assignment from - * any pointer type to void*, and deal with argument conversions - * as though doing an assignment. - */ - return (void *) realloc( (char *) ptr, size ); -} - -void yyfree (void * ptr ) -{ - free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ -} - -#define YYTABLES_NAME "yytables" - -#line 269 "pascallang.l" - - - -/* More language-dependent code */ - -void -yystart(void) { - BEGIN INITIAL; -} - diff --git a/judger/core/sim/sim_2_77/percentages.c b/judger/core/sim/sim_2_77/percentages.c deleted file mode 100755 index a4886ca2..00000000 --- a/judger/core/sim/sim_2_77/percentages.c +++ /dev/null @@ -1,140 +0,0 @@ -/* This file is part of the software similarity tester SIM. - Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: percentages.c,v 1.14 2013-04-28 16:30:42 Gebruiker Exp $ -*/ - -#include - -#include "sim.h" -#include "text.h" -#include "runs.h" -#include "options.h" -#include "Malloc.h" -#include "error.h" -#include "percentages.h" - -/* To compute percentages fairly, the input files are read twice. This - makes it impossible to use the struct text-s from the presented run as - identifications of the files, since their order differs between the first - and the second scan. Specific entries from the struct text-s - are stored instead. -*/ - -struct match { - struct match *ma_next; - const char *ma_fname0; - const char *ma_fname1; - size_t ma_size; /* # tokens of file 0 found in file 1 */ - size_t ma_size0; /* # tokens in file 0 */ -}; - -static struct match *match_start; /* to be allocated by new() */ - -void -add_to_percentages(struct run *r) { - struct match **match_hook = &match_start; - - /* percentages are only meaningful between different files */ - if (r->rn_chunk0.ch_text == r->rn_chunk1.ch_text) return; - - /* look (text0, text1) combination up in match list */ - while (*match_hook) { - struct match *m = *match_hook; - - if ( m->ma_fname0 == r->rn_chunk0.ch_text->tx_fname - && m->ma_fname1 == r->rn_chunk1.ch_text->tx_fname - ) { - /* found it; now update it */ - m->ma_size += r->rn_size; - return; - } - match_hook = &m->ma_next; - } - - { /* it's not there; make a new entry */ - struct match *m = *match_hook = new(struct match); - struct text *text0 = r->rn_chunk0.ch_text; - struct text *text1 = r->rn_chunk1.ch_text; - - m->ma_next = 0; - m->ma_fname0 = text0->tx_fname; - m->ma_fname1 = text1->tx_fname; - m->ma_size = r->rn_size; - m->ma_size0 = text0->tx_limit - text0->tx_start; - } -} - -static float -match_percentage(struct match *m) { - return (((float)m->ma_size)/((float)m->ma_size0)); -} - -/* - We want the sorting order - all contributors of the file with the highest percentage - all contributors of the file with the next lower percentage - etc. - but this order cannot be specified by a single SORT_BEFORE(). - So we sort for percentage, and then reorder during printing. -*/ - -/* instantiate sort_match_list(struct match **listhook) */ -#define SORT_STRUCT match -#define SORT_NAME sort_match_list -#define SORT_BEFORE(p1,p2) (match_percentage(p1) > match_percentage(p2)) -#define SORT_NEXT ma_next -#include "sortlist.bdy" - -static void -print_perc_info(struct match *m) { - int mp = (int)(match_percentage(m)*100.0); - - if (mp > 100) { - /* this may result from overlapping matches */ - mp = 100; - } - if (mp >= Threshold_Percentage) { - fprintf(Output_File, - "%s consists for %d %% of %s material\n", - m->ma_fname0, mp, m->ma_fname1 - ); - } -} - -static void -print_and_remove_perc_info_for_top_file(struct match **m_hook) { - struct match *m = *m_hook; - const char *fname = m->ma_fname0; - - print_perc_info(m); - *m_hook = m->ma_next; - Free(m); - - while ((m = *m_hook)) { - if (m->ma_fname0 == fname) { - if (is_set_option('P')) { - print_perc_info(m); - } - /* remove the struct */ - *m_hook = m->ma_next; - Free(m); - } else { - /* skip the struct */ - m_hook = &m->ma_next; - continue; - } - } -} - -static void -print_percentages(void) { - while (match_start) { - print_and_remove_perc_info_for_top_file(&match_start); - } -} - -void -Show_Percentages(void) { - sort_match_list(&match_start); - print_percentages(); -} diff --git a/judger/core/sim/sim_2_77/percentages.h b/judger/core/sim/sim_2_77/percentages.h deleted file mode 100755 index 9612233d..00000000 --- a/judger/core/sim/sim_2_77/percentages.h +++ /dev/null @@ -1,7 +0,0 @@ -/* This file is part of the software similarity tester SIM. - Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: percentages.h,v 1.4 2012-06-05 09:58:54 Gebruiker Exp $ -*/ - -extern void add_to_percentages(struct run *r); -extern void Show_Percentages(void); diff --git a/judger/core/sim/sim_2_77/runs.c b/judger/core/sim/sim_2_77/runs.c deleted file mode 100755 index f8850cd4..00000000 --- a/judger/core/sim/sim_2_77/runs.c +++ /dev/null @@ -1,60 +0,0 @@ -/* This file is part of the software similarity tester SIM. - Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: runs.c,v 1.7 2014-01-26 21:52:59 Gebruiker Exp $ -*/ - -#include "sim.h" -#include "text.h" -#include "runs.h" -#include "debug.par" - -#define AISO_BEFORE(r0,r1) ((r0)->rn_size > (r1)->rn_size) - -#include "aiso.bdy" - -static int aiso_overflow; - -void -add_to_runs(struct run *r) { - if (InsertAiso(r)) return; - - if (!aiso_overflow) { - fprintf(stderr, ">>>> Memory overflow: too many runs found\n"); - aiso_overflow = 1; - } -} - -#ifdef DB_RUN - -void -db_run_info(const char *msg, const struct run *run, int lines_too) { - const struct chunk *cnk0 = &run->rn_chunk0; - const struct chunk *cnk1 = &run->rn_chunk1; - - if (msg) { - fprintf(Debug_File, "%s: ", msg); - } - fprintf(Debug_File, "File %s / file %s:\n", - cnk0->ch_text->tx_fname, cnk1->ch_text->tx_fname - ); - fprintf(Debug_File, "from %s %s/%s to %s/%s:", token_name, - size_t2string(cnk0->ch_first.ps_tk_cnt), - size_t2string(cnk1->ch_first.ps_tk_cnt), - size_t2string(cnk0->ch_last.ps_tk_cnt), - size_t2string(cnk1->ch_last.ps_tk_cnt) - ); - if (lines_too) { - fprintf(Debug_File, " from lines %s/%s to %s/%s:", - size_t2string(cnk0->ch_first.ps_nl_cnt), - size_t2string(cnk1->ch_first.ps_nl_cnt), - size_t2string(cnk0->ch_last.ps_nl_cnt), - size_t2string(cnk1->ch_last.ps_nl_cnt) - ); - } - fprintf(Debug_File, " %s %s%s\n", - size_t2string(run->rn_size), - token_name, (run->rn_size == 1 ? "" : "s") - ); -} - -#endif /* DB_RUN */ diff --git a/judger/core/sim/sim_2_77/settings.par b/judger/core/sim/sim_2_77/settings.par deleted file mode 100755 index c81b9024..00000000 --- a/judger/core/sim/sim_2_77/settings.par +++ /dev/null @@ -1,8 +0,0 @@ -/* This file is part of the software similarity tester SIM. - Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: settings.par,v 1.2 2012-06-05 14:58:39 Gebruiker Exp $ -*/ - -#define DEFAULT_MIN_RUN_SIZE 24 /* default minimum run size */ - -#define DEFAULT_PAGE_WIDTH 80 /* default page width */ diff --git a/judger/core/sim/sim_2_77/sim.1 b/judger/core/sim/sim_2_77/sim.1 deleted file mode 100755 index 72987aed..00000000 --- a/judger/core/sim/sim_2_77/sim.1 +++ /dev/null @@ -1,295 +0,0 @@ -.\" This file is part of the software similarity tester SIM. -.\" Written by Dick Grune, Vrije Universiteit, Amsterdam. -.\" $Id: sim.1,v 2.22 2012-11-28 20:49:52 Gebruiker Exp $ -.\" -.TH SIM 1 2012/05/02 -.SH NAME -sim \- find similarities in C, Java, Pascal, Modula-2, Lisp, Miranda, or text files -.SH SYNOPSIS -.B sim_c -[ -.B \-[defFiMnpPRsST] -.B \-r -.I N -.B \-t -.I N -.B \-w -.I N -.B \-o -.I F -] -file ... [ -.B / -[ file ... ] ] -.br -.B sim_c -\&... -.br -.B sim_java -\&... -.br -.B sim_pasc -\&... -.br -.B sim_m2 -\&... -.br -.B sim_lisp -\&... -.br -.B sim_mira -\&... -.br -.B sim_text -\&... -.br -.SH DESCRIPTION -.I Sim_c -reads the C files -.I file ... -and looks for segments of text that are similar; two segments of program text -are similar if they only differ in layout, comment, identifiers and -the contents of numbers, strings and characters. -If any runs of sufficient length -are found, they are reported on standard output; the number of significant -tokens in the run is given between square brackets. -.PP -.I Sim_java -does the same for Java, -.I sim_pasc -for Pascal, -.I sim_m2 -for Modula-2, -.I sim_mira -for Miranda, -and -.I sim_lisp -for Lisp. -.I Sim_text -works on arbitrary text; it is occasionally useful on shell scripts. -.PP -The program can be used for finding copied pieces of code in -purportedly unrelated programs (with -.B \-s -or -.BR \-S ), -or for finding accidentally duplicated code in larger projects (with -.BR \-f ). -.PP -If a -.B / -is present between the input files, the latter are divided into a group of -"new" files (before the -.BR / ) -and a group of "old" files; if there is no -.BR / , -all files are "new". -Old files are never compared to each other. -.PP -Since the similarity tester reads the files several times, it cannot read from -standard input. -.PP -There are the following options: -.TP -.B \-d -The output is in a diff(1)-like format instead of the default -2-column format. -.TP -.B \-e -Each file is compared to each file in isolation; this will find all -similarities between all texts involved, regardless of duplicates. -.TP -.B \-f -Runs are restricted to segments with balancing parentheses, to isolate -potential routine bodies (not in text). -.TP -.B \-F -The names of routines in calls are required to match exactly -(not in text). -.TP -.B \-i -The names of the files to be compared are read from standard input, including -a possible -.BR / ; -the file names must be one to a line. -This option allows a very large number of file names to be specified; -it differs from the @ facility provided by some compilers in that it handles -file names only, and does not recognize option arguments. -.TP -.B \-M -Memory usage information is displayed on standard error output. -.TP -.B \-n -Similarities found are only summarized, not displayed. -.TP -.B "\-o F" -The output is written to the file named -.IR F . -.TP -.B \-p -The output is given in similarity percentages; see below; implies \fB\-e\fP -and \fB\-s\fP. -.TP -.B \-P -As -.B \-p -but more extensive; implies \fB\-e\fP and \fB\-s\fP. -.TP -.B "\-r N" -The minimum run length is set to -.I N -units; the default is 24 tokens, except in -.IR sim_text , -where it is 8 words. -.TP -.B \-R -Directories in the input list are entered recursively, and all files they -contain are involved in the comparison. -.TP -.B \-s -The contents of a file are not compared to itself (\-s for "not self"). -.TP -.B \-S -The contents of the new files are compared to the old files only \- not -between themselves. -.TP -.B "\-t N" -In combination with the -.B \-p -option, sets the threshold (in percents) below which similarities will not be -reported; the default is 1, except in -.IR sim_text , -where it is 20. -.TP -.B \-T -A more terse and uniform form of output is produced, which may be more -suitable for postprocessing. -.TP -.B "\-w N" -The page width used is set to -.I N -columns; the default is 80. -.TP -.B "\-\-" -(A secret option, which prints the input as the similarity checker sees it, -and then stops.) -.PP -The -.B \-p -option results in lines of the form -.nf -.ft C - F consists for x % of G material -.ft P -.fi -meaning that \fCx\fP % of \fCF\fP's text can also be found in \fCG\fP. -Note that this relation is not symmetric; it is in fact quite possible for one -file to consist for 100 % of text from another file, while the other file -consists for only 1 % of text of the first file, if their lengths differ -enough. -Each file is reported only once in the position of the \&\fCF\fP in the above -line. -This simplifies the identification of a set of files -.IR "A[1] ... A[n]" , -where the concatenation of these files is also present. -This restriction can be lifted by using the -.B \-P -option instead. -A threshold can be set using the -.B \-t -option; this option is ignored under \fB\-P\fP. -Note that the granularity of the recognized text is still governed by the -.B \-r -option or its default. -.PP -.I Sim_text -accepts s p a c e d t e x t as normal text. -.PP -The program can handle UNICODE file names under Windows. -This is relevant only under the -.B \-R -option, since there is no way to give UNICODE file names from the command line. -.PP -Care has been taken to keep all internal processes linear in the length of the -input, with the exception of the matching process which is almost linear, -using a hash table; various other tables are used for speed-up. -If, however, there is not enough memory for the tables, they are discarded in -order of unimportance, under which conditions the algorithms revert to their -quadratic nature. -.SH EXAMPLES -The call -.nf -.ft C - sim_c *.c -.ft P -.fi -highlights duplicate code in the directory. -(It is useful to remove generated files first.) -A call -.nf -.ft C - sim_c -f -F *.c -.ft P -.fi -can pinpoint them further. -.PP -A call -.nf -.ft C - sim_text -e -p -s new/* / old/* -.ft P -.fi -compares each file in \fCnew/*\fP to each subsequent file in \fCnew/*\fP and -\fCold/*\fP, and if any pair has more that 20% in common, that fact is -reported. -Usually a similarity of 30% or more is significant; lower than 20% is probably -coincidence; and in between is doubtful. -.PP -A call -.nf -.ft C - sim_text -e -n -s -r100 new/* / old/* -.ft P -.fi -compares the same files, and reports large common segments. -Both approaches are good for plagiarism detection. -.SH LIMITATIONS -Repetitive input is the bane of similarity checking. -If we have a file containing 4 copies of similar text, -.nf - A1 A2 A3 A4 -.fi -where the numbers serve only to distinguish the similar copies, -there are 7 similarities: A1=A2, A1=A3, A1=A4, A2=A3, A2=A4, A3=A4, and -A1A2=A3A4, even discarding the overlapping A1A2A3=A2A3A4. -Of these, only 3 are meaningful: A1=A2, A2=A3, and A3=A4. -And for a table with 20 lines similar to each other, not unusual in a program, -there are 715 similarities, of which at most 19 are meaningful. -Reporting all 715 of them is clearly unacceptable. -.PP -To remedy this, finding the similarities is performed as follows: -For each position in the text, the largest segment is found, of which a -non-overlapping copy occurs in the text following it. -That segment and its copy are reported and scanning resumes at the position -just after the segment. -For the above example this results in the similarities A1A2=A3A4 and A3=A4, -which is quite satisfactory, and for N similar segments roughly \fIlog N\fP -messages are given. -.PP -A drawback of this heuristic is that the output is sensitive to the -order of the input files. -If we have two files -.nf - file1 = A1, file2 = A2A3 -.fi -then the order "file1 file2" gives "A1=A2, A2=A3" and -"file2 file1" gives "A2=A3, A3=A1"; but both reports convey the same -information. -.SH BUGS -Since it uses -.I lex(1) -on some systems, it may crash on any weird construction that overflows -.IR lex 's -internal buffers. -.SH AUTHOR -Dick Grune, Vrije Universiteit, Amsterdam; dick@dickgrune.com. diff --git a/judger/core/sim/sim_2_77/sim.c b/judger/core/sim/sim_2_77/sim.c deleted file mode 100755 index 846b8c9a..00000000 --- a/judger/core/sim/sim_2_77/sim.c +++ /dev/null @@ -1,218 +0,0 @@ -/* This file is part of the software similarity tester SIM. - Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: sim.c,v 2.37 2014-01-27 20:50:51 Gebruiker Exp $ -*/ - -#include -#include -#include - -#include "system.par" -#include "settings.par" -#include "sim.h" -#include "options.h" -#include "newargs.h" -#include "token.h" -#include "language.h" -#include "error.h" -#include "text.h" -#include "runs.h" -#include "hash.h" -#include "compare.h" -#include "pass1.h" -#include "pass2.h" -#include "pass3.h" -#include "percentages.h" -#include "stream.h" -#include "lang.h" - -#include "Malloc.h" -#include "any_int.h" - - /* PARAMETERS */ -/* command-line parameters */ -int Min_Run_Size = DEFAULT_MIN_RUN_SIZE; -int Page_Width = DEFAULT_PAGE_WIDTH; -int Threshold_Percentage = 1; /* minimum percentage to show */ -FILE *Output_File; -FILE *Debug_File; - -/* and their string values, for language files that define their own parameters -*/ -const char *token_name = "token"; -const char *min_run_string; -const char *threshold_string; - -const char *progname; /* for error reporting */ - -static const char *page_width_string; -static const char *output_name; /* for reporting */ - -static const struct option optlist[] = { - {'r', "minimum run size", 'N', &min_run_string}, - {'w', "page width", 'N', &page_width_string}, - {'f', "function-like forms only", ' ', 0}, - {'F', "keep function identifiers in tact", ' ', 0}, - {'d', "use diff format for output", ' ', 0}, - {'T', "terse output", ' ', 0}, - {'n', "display headings only", ' ', 0}, - {'p', "use percentage format for output", ' ', 0}, - {'P', "use percentage format, showing all combinations", ' ', 0}, - {'t', "threshold level of percentage to show", 'N', &threshold_string}, - {'e', "compare each file to each file separately", ' ', 0}, - {'s', "do not compare a file to itself", ' ', 0}, - {'S', "compare new files to old files only", ' ', 0}, - {'R', "recurse into subdirectories", ' ', 0}, - {'i', "read arguments (file names) from standard input", ' ', 0}, - {'o', "write output to file F", 'F', &output_name}, - {'M', "show memory usage info", ' ', 0}, - {'-', "lexical scan output only", ' ', 0}, - {0, 0, 0, 0} -}; - - /* SERVICE ROUTINES */ -int -is_new_old_separator(const char *s) { - return strcmp(s, "/") == 0; -} - -const char * -size_t2string(size_t s) { - return any_uint2string(s, 0); -} - - /* PROGRAM */ -static void -read_and_compare_files(int argc, const char **argv, int round) { - Read_Input_Files(argc, argv, round); - Make_Forward_References(); - Compare_Files(); - Free_Forward_References(); -} - -static void -reverse_new_input_files(int argc, const char *argv[]) { - int txt_first = 0; - int txt_last; - - /* find the end of the new files */ - for (txt_last = 0; txt_last < argc; txt_last++) { - if (is_new_old_separator(argv[txt_last])) break; - } - txt_last--; - - /* swap the names from the outer sides on */ - while (txt_first < txt_last) { - const char *tmp = argv[txt_first]; - argv[txt_first] = argv[txt_last]; - argv[txt_last] = tmp; - txt_first++, txt_last--; - } -} - -int -main(int argc, const char *argv[]) { - - /* Save program name */ - progname = argv[0]; - argv++, argc--; /* and skip it */ - - /* Set the default output and debug streams */ - Output_File = stdout; - Debug_File = stdout; - - /* Get command line options */ - { int nop = do_options(progname, optlist, argc, argv); - argc -= nop, argv += nop; /* and skip them */ - } - - /* Treat the value options */ - if (min_run_string) { - Min_Run_Size = atoi(min_run_string); - if (Min_Run_Size == 0) - fatal("bad or zero run size; form is: -r N"); - } - if (page_width_string) { - Page_Width = atoi(page_width_string); - if (Page_Width == 0) - fatal("bad or zero page width; form is: -w N"); - } - if (threshold_string) { - Threshold_Percentage = atoi(threshold_string); - if ((Threshold_Percentage > 100) || (Threshold_Percentage <= 0)) - fatal("threshold must be between 1 and 100"); - } - if (output_name) { - Output_File = fopen(output_name, "w"); - if (Output_File == 0) { - char *msg = (char *)Malloc(strlen(output_name) + 100); - - sprintf(msg, "cannot open output file `%s'", - output_name); - fatal(msg); - /*NOTREACHED*/ - } - } - - if (is_set_option('P')) { - Threshold_Percentage = 1; - set_option('p'); - } - - if (is_set_option('p')) { - set_option('e'); - set_option('s'); - } - - /* Treat the input-determining options */ - if (is_set_option('i')) { - /* read input file names from standard input */ - if (argc != 0) - fatal("-i option conflicts with file arguments"); - get_new_std_input_args(&argc, &argv); - } - if (is_set_option('R')) { - get_new_recursive_args(&argc, &argv); - } - /* (argc, argv) now represents new_file* [ / old_file*] */ - - /* Here the real work starts */ - Init_Language(); - - if (is_set_option('-')) { - /* Just the lexical scan */ - while (argv[0]) { - const char *arg = argv[0]; - if (!is_new_old_separator(arg)) { - Print_Stream(arg); - } - argv++; - } - } - else if (is_set_option('p')) { - /* Show percentages */ - /* To compute the percentages fairly, the input files are read - twice, once in command line order, and once with the new - files in reverse order. - */ - read_and_compare_files(argc, argv, 1); - reverse_new_input_files(argc, argv); - read_and_compare_files(argc, argv, 2); - Show_Percentages(); - } else { - /* Show runs */ - read_and_compare_files(argc, argv, 1); - Retrieve_Runs(); - Show_Runs(); - } - - if (is_set_option('M')) { - /* It is not trivial to plug the leaks, because data structures - point to each other, and have to be freed in the proper - order. But it is not impossible either. To do, perhaps. - */ - ReportMemoryLeaks(stderr); - } - - return 0; -} diff --git a/judger/core/sim/sim_2_77/sim.pdf b/judger/core/sim/sim_2_77/sim.pdf deleted file mode 100755 index e71db337..00000000 Binary files a/judger/core/sim/sim_2_77/sim.pdf and /dev/null differ diff --git a/judger/core/sim/sim_2_77/sortlist.bdy b/judger/core/sim/sim_2_77/sortlist.bdy deleted file mode 100755 index dff1cfb9..00000000 --- a/judger/core/sim/sim_2_77/sortlist.bdy +++ /dev/null @@ -1,57 +0,0 @@ -/* - Module: Sort Linked Lists - Author: dick@cs.vu.nl (Dick Grune @ Vrije Universiteit, Amsterdam) - Version: Tue Sep 17 17:32:33 1991 - -Description: - This is the implementation part of a generic routine that sorts - linked lists. - -Instantiation: - See sortlist.spc -*/ - -#ifndef _SORT_EXTERN_DEFINED -static -#endif -void -SORT_NAME(struct SORT_STRUCT **lh) { - /* I've never known that sorting a linked list was this - complicated; what am I missing? - */ - register struct SORT_STRUCT **listhook = lh; - - while (*listhook) { - /* 0. the list is not empty -> there must be a smallest one */ - register struct SORT_STRUCT **hsmall; - - /* 1. find (the pointer to) the smallest element */ - { - register struct SORT_STRUCT **hook = listhook; - - /* assume initially that first element is smallest */ - hsmall = hook; - while (*hook) { - if (SORT_BEFORE(*hook, *hsmall)) { - /* revise opinion */ - hsmall = hook; - } - hook = &(*hook)->SORT_NEXT; - } - } - - /* 2. move the smallest element to front */ - { - register struct SORT_STRUCT *smallest = *hsmall; - - /* remove it from the chain */ - *hsmall = smallest->SORT_NEXT; - /* and insert it before the first element */ - smallest->SORT_NEXT = *listhook; - *listhook = smallest; - } - - /* 3. skip over smallest element */ - listhook = &(*listhook)->SORT_NEXT; - } -} diff --git a/judger/core/sim/sim_2_77/textlang.c b/judger/core/sim/sim_2_77/textlang.c deleted file mode 100644 index f7536229..00000000 --- a/judger/core/sim/sim_2_77/textlang.c +++ /dev/null @@ -1,1851 +0,0 @@ - -#line 3 "" - -#define YY_INT_ALIGNED short int - -/* A lexical scanner generated by flex */ - -#define FLEX_SCANNER -#define YY_FLEX_MAJOR_VERSION 2 -#define YY_FLEX_MINOR_VERSION 6 -#define YY_FLEX_SUBMINOR_VERSION 0 -#if YY_FLEX_SUBMINOR_VERSION > 0 -#define FLEX_BETA -#endif - -/* First, we deal with platform-specific or compiler-specific issues. */ - -/* begin standard C headers. */ -#include -#include -#include -#include - -/* end standard C headers. */ - -/* flex integer type definitions */ - -#ifndef FLEXINT_H -#define FLEXINT_H - -/* C99 systems have . Non-C99 systems may or may not. */ - -#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L - -/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, - * if you want the limit (max/min) macros for int types. - */ -#ifndef __STDC_LIMIT_MACROS -#define __STDC_LIMIT_MACROS 1 -#endif - -#include -typedef int8_t flex_int8_t; -typedef uint8_t flex_uint8_t; -typedef int16_t flex_int16_t; -typedef uint16_t flex_uint16_t; -typedef int32_t flex_int32_t; -typedef uint32_t flex_uint32_t; -#else -typedef signed char flex_int8_t; -typedef short int flex_int16_t; -typedef int flex_int32_t; -typedef unsigned char flex_uint8_t; -typedef unsigned short int flex_uint16_t; -typedef unsigned int flex_uint32_t; - -/* Limits of integral types. */ -#ifndef INT8_MIN -#define INT8_MIN (-128) -#endif -#ifndef INT16_MIN -#define INT16_MIN (-32767-1) -#endif -#ifndef INT32_MIN -#define INT32_MIN (-2147483647-1) -#endif -#ifndef INT8_MAX -#define INT8_MAX (127) -#endif -#ifndef INT16_MAX -#define INT16_MAX (32767) -#endif -#ifndef INT32_MAX -#define INT32_MAX (2147483647) -#endif -#ifndef UINT8_MAX -#define UINT8_MAX (255U) -#endif -#ifndef UINT16_MAX -#define UINT16_MAX (65535U) -#endif -#ifndef UINT32_MAX -#define UINT32_MAX (4294967295U) -#endif - -#endif /* ! C99 */ - -#endif /* ! FLEXINT_H */ - -#ifdef __cplusplus - -/* The "const" storage-class-modifier is valid. */ -#define YY_USE_CONST - -#else /* ! __cplusplus */ - -/* C99 requires __STDC__ to be defined as 1. */ -#if defined (__STDC__) - -#define YY_USE_CONST - -#endif /* defined (__STDC__) */ -#endif /* ! __cplusplus */ - -#ifdef YY_USE_CONST -#define yyconst const -#else -#define yyconst -#endif - -/* Returned upon end-of-file. */ -#define YY_NULL 0 - -/* Promotes a possibly negative, possibly signed char to an unsigned - * integer for use as an array index. If the signed char is negative, - * we want to instead treat it as an 8-bit unsigned char, hence the - * double cast. - */ -#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) - -/* Enter a start condition. This macro really ought to take a parameter, - * but we do it the disgusting crufty way forced on us by the ()-less - * definition of BEGIN. - */ -#define BEGIN (yy_start) = 1 + 2 * - -/* Translate the current start state into a value that can be later handed - * to BEGIN to return to the state. The YYSTATE alias is for lex - * compatibility. - */ -#define YY_START (((yy_start) - 1) / 2) -#define YYSTATE YY_START - -/* Action number for EOF rule of a given start state. */ -#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) - -/* Special action meaning "start processing a new file". */ -#define YY_NEW_FILE yyrestart(yyin ) - -#define YY_END_OF_BUFFER_CHAR 0 - -/* Size of default input buffer. */ -#ifndef YY_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k. - * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. - * Ditto for the __ia64__ case accordingly. - */ -#define YY_BUF_SIZE 32768 -#else -#define YY_BUF_SIZE 16384 -#endif /* __ia64__ */ -#endif - -/* The state buf must be large enough to hold one state per character in the main buffer. - */ -#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) - -#ifndef YY_TYPEDEF_YY_BUFFER_STATE -#define YY_TYPEDEF_YY_BUFFER_STATE -typedef struct yy_buffer_state *YY_BUFFER_STATE; -#endif - -#ifndef YY_TYPEDEF_YY_SIZE_T -#define YY_TYPEDEF_YY_SIZE_T -typedef size_t yy_size_t; -#endif - -extern yy_size_t yyleng; - -extern FILE *yyin, *yyout; - -#define EOB_ACT_CONTINUE_SCAN 0 -#define EOB_ACT_END_OF_FILE 1 -#define EOB_ACT_LAST_MATCH 2 - - #define YY_LESS_LINENO(n) - #define YY_LINENO_REWIND_TO(ptr) - -/* Return all but the first "n" matched characters back to the input stream. */ -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - *yy_cp = (yy_hold_char); \ - YY_RESTORE_YY_MORE_OFFSET \ - (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ - YY_DO_BEFORE_ACTION; /* set up yytext again */ \ - } \ - while ( 0 ) - -#define unput(c) yyunput( c, (yytext_ptr) ) - -#ifndef YY_STRUCT_YY_BUFFER_STATE -#define YY_STRUCT_YY_BUFFER_STATE -struct yy_buffer_state - { - FILE *yy_input_file; - - char *yy_ch_buf; /* input buffer */ - char *yy_buf_pos; /* current position in input buffer */ - - /* Size of input buffer in bytes, not including room for EOB - * characters. - */ - yy_size_t yy_buf_size; - - /* Number of characters read into yy_ch_buf, not including EOB - * characters. - */ - int yy_n_chars; - - /* Whether we "own" the buffer - i.e., we know we created it, - * and can realloc() it to grow it, and should free() it to - * delete it. - */ - int yy_is_our_buffer; - - /* Whether this is an "interactive" input source; if so, and - * if we're using stdio for input, then we want to use getc() - * instead of fread(), to make sure we stop fetching input after - * each newline. - */ - int yy_is_interactive; - - /* Whether we're considered to be at the beginning of a line. - * If so, '^' rules will be active on the next match, otherwise - * not. - */ - int yy_at_bol; - - int yy_bs_lineno; /**< The line count. */ - int yy_bs_column; /**< The column count. */ - - /* Whether to try to fill the input buffer when we reach the - * end of it. - */ - int yy_fill_buffer; - - int yy_buffer_status; - -#define YY_BUFFER_NEW 0 -#define YY_BUFFER_NORMAL 1 - /* When an EOF's been seen but there's still some text to process - * then we mark the buffer as YY_EOF_PENDING, to indicate that we - * shouldn't try reading from the input source any more. We might - * still have a bunch of tokens to match, though, because of - * possible backing-up. - * - * When we actually see the EOF, we change the status to "new" - * (via yyrestart()), so that the user can continue scanning by - * just pointing yyin at a new input file. - */ -#define YY_BUFFER_EOF_PENDING 2 - - }; -#endif /* !YY_STRUCT_YY_BUFFER_STATE */ - -/* Stack of input buffers. */ -static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ -static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ -static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ - -/* We provide macros for accessing buffer states in case in the - * future we want to put the buffer states in a more general - * "scanner state". - * - * Returns the top of the stack, or NULL. - */ -#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ - ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ - : NULL) - -/* Same as previous macro, but useful when we know that the buffer stack is not - * NULL or when we need an lvalue. For internal use only. - */ -#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] - -/* yy_hold_char holds the character lost when yytext is formed. */ -static char yy_hold_char; -static int yy_n_chars; /* number of characters read into yy_ch_buf */ -yy_size_t yyleng; - -/* Points to current character in buffer. */ -static char *yy_c_buf_p = (char *) 0; -static int yy_init = 0; /* whether we need to initialize */ -static int yy_start = 0; /* start state number */ - -/* Flag which is used to allow yywrap()'s to do buffer switches - * instead of setting up a fresh yyin. A bit of a hack ... - */ -static int yy_did_buffer_switch_on_eof; - -void yyrestart (FILE *input_file ); -void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ); -YY_BUFFER_STATE yy_create_buffer (FILE *file,int size ); -void yy_delete_buffer (YY_BUFFER_STATE b ); -void yy_flush_buffer (YY_BUFFER_STATE b ); -void yypush_buffer_state (YY_BUFFER_STATE new_buffer ); -void yypop_buffer_state (void ); - -static void yyensure_buffer_stack (void ); -static void yy_load_buffer_state (void ); -static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file ); - -#define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER ) - -YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ); -YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ); -YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,yy_size_t len ); - -void *yyalloc (yy_size_t ); -void *yyrealloc (void *,yy_size_t ); -void yyfree (void * ); - -#define yy_new_buffer yy_create_buffer - -#define yy_set_interactive(is_interactive) \ - { \ - if ( ! YY_CURRENT_BUFFER ){ \ - yyensure_buffer_stack (); \ - YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer(yyin,YY_BUF_SIZE ); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ - } - -#define yy_set_bol(at_bol) \ - { \ - if ( ! YY_CURRENT_BUFFER ){\ - yyensure_buffer_stack (); \ - YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer(yyin,YY_BUF_SIZE ); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ - } - -#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) - -/* Begin user sect3 */ - -#define yywrap() (/*CONSTCOND*/1) -#define YY_SKIP_YYWRAP - -typedef unsigned char YY_CHAR; - -FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0; - -typedef int yy_state_type; - -extern int yylineno; - -int yylineno = 1; - -extern char *yytext; -#ifdef yytext_ptr -#undef yytext_ptr -#endif -#define yytext_ptr yytext - -static yy_state_type yy_get_previous_state (void ); -static yy_state_type yy_try_NUL_trans (yy_state_type current_state ); -static int yy_get_next_buffer (void ); -#if defined(__GNUC__) && __GNUC__ >= 3 -__attribute__((__noreturn__)) -#endif -static void yy_fatal_error (yyconst char msg[] ); - -/* Done after the current pattern has been matched and before the - * corresponding action - sets up yytext. - */ -#define YY_DO_BEFORE_ACTION \ - (yytext_ptr) = yy_bp; \ - yyleng = (size_t) (yy_cp - yy_bp); \ - (yy_hold_char) = *yy_cp; \ - *yy_cp = '\0'; \ - (yy_c_buf_p) = yy_cp; - -#define YY_NUM_RULES 5 -#define YY_END_OF_BUFFER 6 -/* This struct is not used in this scanner, - but its presence is necessary. */ -struct yy_trans_info - { - flex_int32_t yy_verify; - flex_int32_t yy_nxt; - }; -static yyconst flex_int16_t yy_accept[13] = - { 0, - 0, 0, 6, 4, 3, 1, 0, 1, 0, 2, - 2, 0 - } ; - -static yyconst YY_CHAR yy_ec[256] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 4, 1, 1, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 1, 1, 1, - 1, 1, 1, 1, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 1, 1, 1, 1, 1, 1, 4, 4, 4, 4, - - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 1, 1, 1, 1, 1, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4 - } ; - -static yyconst YY_CHAR yy_meta[5] = - { 0, - 1, 1, 1, 2 - } ; - -static yyconst flex_uint16_t yy_base[16] = - { 0, - 0, 0, 11, 12, 12, 2, 0, 0, 7, 12, - 0, 12, 7, 6, 6 - } ; - -static yyconst flex_int16_t yy_def[16] = - { 0, - 12, 1, 12, 12, 12, 12, 13, 14, 15, 12, - 13, 0, 12, 12, 12 - } ; - -static yyconst flex_uint16_t yy_nxt[17] = - { 0, - 4, 5, 4, 6, 7, 8, 10, 8, 9, 11, - 12, 3, 12, 12, 12, 12 - } ; - -static yyconst flex_int16_t yy_chk[17] = - { 0, - 1, 1, 1, 1, 6, 6, 15, 14, 13, 9, - 3, 12, 12, 12, 12, 12 - } ; - -static yy_state_type yy_last_accepting_state; -static char *yy_last_accepting_cpos; - -extern int yy_flex_debug; -int yy_flex_debug = 0; - -/* The intent behind this definition is that it'll catch - * any uses of REJECT which flex missed. - */ -#define REJECT reject_used_but_not_detected -#define yymore() yymore_used_but_not_detected -#define YY_MORE_ADJ 0 -#define YY_RESTORE_YY_MORE_OFFSET -char *yytext; -#line 1 "textlang.l" -#line 2 "textlang.l" -/* This file is part of the software similarity tester SIM. - Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: textlang.l,v 1.14 2013-04-28 16:30:43 Gebruiker Exp $ -*/ - -/* - Text front end for the similarity tester. -*/ - -#include "sim.h" -#include "token.h" -#include "idf.h" - -#include "lex.h" -#include "lang.h" -#include "language.h" - -/* General language front end data */ -Token lex_token; -size_t lex_nl_cnt; -size_t lex_tk_cnt; -size_t lex_non_ascii_cnt; - -/* Language-dependent code */ - -void -Init_Language(void) { - token_name = "word"; - if (!min_run_string) { - Min_Run_Size = 8; - } - if (!threshold_string) { - Threshold_Percentage = 20; - } -} - -/*ARGSUSED*/ -int -May_Be_Start_Of_Run(Token tk) { - /* any token is acceptable */ - return 1; -} - -/*ARGSUSED*/ -size_t -Best_Run_Size(const Token *str, size_t size) { - /* any run size is acceptable */ - return size; -} - -#line 524 "" - -#define INITIAL 0 - -#ifndef YY_NO_UNISTD_H -/* Special case for "unistd.h", since it is non-ANSI. We include it way - * down here because we want the user's section 1 to have been scanned first. - * The user has a chance to override it with an option. - */ -#include -#endif - -#ifndef YY_EXTRA_TYPE -#define YY_EXTRA_TYPE void * -#endif - -static int yy_init_globals (void ); - -/* Accessor methods to globals. - These are made visible to non-reentrant scanners for convenience. */ - -int yylex_destroy (void ); - -int yyget_debug (void ); - -void yyset_debug (int debug_flag ); - -YY_EXTRA_TYPE yyget_extra (void ); - -void yyset_extra (YY_EXTRA_TYPE user_defined ); - -FILE *yyget_in (void ); - -void yyset_in (FILE * _in_str ); - -FILE *yyget_out (void ); - -void yyset_out (FILE * _out_str ); - -yy_size_t yyget_leng (void ); - -char *yyget_text (void ); - -int yyget_lineno (void ); - -void yyset_lineno (int _line_number ); - -/* Macros after this point can all be overridden by user definitions in - * section 1. - */ - -#ifndef YY_SKIP_YYWRAP -#ifdef __cplusplus -extern "C" int yywrap (void ); -#else -extern int yywrap (void ); -#endif -#endif - -#ifndef YY_NO_UNPUT - - static void yyunput (int c,char *buf_ptr ); - -#endif - -#ifndef yytext_ptr -static void yy_flex_strncpy (char *,yyconst char *,int ); -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * ); -#endif - -#ifndef YY_NO_INPUT - -#ifdef __cplusplus -static int yyinput (void ); -#else -static int input (void ); -#endif - -#endif - -/* Amount of stuff to slurp up with each read. */ -#ifndef YY_READ_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k */ -#define YY_READ_BUF_SIZE 16384 -#else -#define YY_READ_BUF_SIZE 8192 -#endif /* __ia64__ */ -#endif - -/* Copy whatever the last rule matched to the standard output. */ -#ifndef ECHO -/* This used to be an fputs(), but since the string might contain NUL's, - * we now use fwrite(). - */ -#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0) -#endif - -/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, - * is returned in "result". - */ -#ifndef YY_INPUT -#define YY_INPUT(buf,result,max_size) \ - if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ - { \ - int c = '*'; \ - size_t n; \ - for ( n = 0; n < max_size && \ - (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ - buf[n] = (char) c; \ - if ( c == '\n' ) \ - buf[n++] = (char) c; \ - if ( c == EOF && ferror( yyin ) ) \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - result = n; \ - } \ - else \ - { \ - errno=0; \ - while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \ - { \ - if( errno != EINTR) \ - { \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - break; \ - } \ - errno=0; \ - clearerr(yyin); \ - } \ - }\ -\ - -#endif - -/* No semi-colon after return; correct usage is to write "yyterminate();" - - * we don't want an extra ';' after the "return" because that will cause - * some compilers to complain about unreachable statements. - */ -#ifndef yyterminate -#define yyterminate() return YY_NULL -#endif - -/* Number of entries by which start-condition stack grows. */ -#ifndef YY_START_STACK_INCR -#define YY_START_STACK_INCR 25 -#endif - -/* Report a fatal error. */ -#ifndef YY_FATAL_ERROR -#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) -#endif - -/* end tables serialization structures and prototypes */ - -/* Default declaration of generated scanner - a define so the user can - * easily add parameters. - */ -#ifndef YY_DECL -#define YY_DECL_IS_OURS 1 - -extern int yylex (void); - -#define YY_DECL int yylex (void) -#endif /* !YY_DECL */ - -/* Code executed at the beginning of each rule, after yytext and yyleng - * have been set up. - */ -#ifndef YY_USER_ACTION -#define YY_USER_ACTION -#endif - -/* Code executed at the end of each rule. */ -#ifndef YY_BREAK -#define YY_BREAK /*LINTED*/break; -#endif - -#define YY_RULE_SETUP \ - YY_USER_ACTION - -/** The main scanner function which does all the work. - */ -YY_DECL -{ - yy_state_type yy_current_state; - char *yy_cp, *yy_bp; - int yy_act; - - if ( !(yy_init) ) - { - (yy_init) = 1; - -#ifdef YY_USER_INIT - YY_USER_INIT; -#endif - - if ( ! (yy_start) ) - (yy_start) = 1; /* first start state */ - - if ( ! yyin ) - yyin = stdin; - - if ( ! yyout ) - yyout = stdout; - - if ( ! YY_CURRENT_BUFFER ) { - yyensure_buffer_stack (); - YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer(yyin,YY_BUF_SIZE ); - } - - yy_load_buffer_state( ); - } - - { -#line 63 "textlang.l" - - -#line 745 "" - - while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ - { - yy_cp = (yy_c_buf_p); - - /* Support of yytext. */ - *yy_cp = (yy_hold_char); - - /* yy_bp points to the position in yy_ch_buf of the start of - * the current run. - */ - yy_bp = yy_cp; - - yy_current_state = (yy_start); -yy_match: - do - { - YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 13 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - ++yy_cp; - } - while ( yy_base[yy_current_state] != 12 ); - -yy_find_action: - yy_act = yy_accept[yy_current_state]; - if ( yy_act == 0 ) - { /* have to back up */ - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - yy_act = yy_accept[yy_current_state]; - } - - YY_DO_BEFORE_ACTION; - -do_action: /* This label is used only to access EOF actions. */ - - switch ( yy_act ) - { /* beginning of action switch */ - case 0: /* must back up */ - /* undo the effects of YY_DO_BEFORE_ACTION */ - *yy_cp = (yy_hold_char); - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - goto yy_find_action; - -case 1: -YY_RULE_SETUP -#line 65 "textlang.l" -{ - return_tk(idf_hashed(yytext)); - } - YY_BREAK -case 2: -/* rule 2 can match eol */ -*yy_cp = (yy_hold_char); /* undo effects of setting up yytext */ -YY_LINENO_REWIND_TO(yy_cp - 1); -(yy_c_buf_p) = yy_cp -= 1; -YY_DO_BEFORE_ACTION; /* set up yytext again */ -YY_RULE_SETUP -#line 69 "textlang.l" -{ - /* the / operator works at the top level only */ - return_tk(idf_hashed(yytext)); - } - YY_BREAK -case 3: -/* rule 3 can match eol */ -YY_RULE_SETUP -#line 75 "textlang.l" -{ /* count newlines */ - return_eol(); - } - YY_BREAK -case 4: -YY_RULE_SETUP -#line 79 "textlang.l" -{ /* ignore the rest */ - } - YY_BREAK -case 5: -YY_RULE_SETUP -#line 82 "textlang.l" -ECHO; - YY_BREAK -#line 841 "" -case YY_STATE_EOF(INITIAL): - yyterminate(); - - case YY_END_OF_BUFFER: - { - /* Amount of text matched not including the EOB char. */ - int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; - - /* Undo the effects of YY_DO_BEFORE_ACTION. */ - *yy_cp = (yy_hold_char); - YY_RESTORE_YY_MORE_OFFSET - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) - { - /* We're scanning a new file or input source. It's - * possible that this happened because the user - * just pointed yyin at a new source and called - * yylex(). If so, then we have to assure - * consistency between YY_CURRENT_BUFFER and our - * globals. Here is the right place to do so, because - * this is the first action (other than possibly a - * back-up) that will match for the new input source. - */ - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; - } - - /* Note that here we test for yy_c_buf_p "<=" to the position - * of the first EOB in the buffer, since yy_c_buf_p will - * already have been incremented past the NUL character - * (since all states make transitions on EOB to the - * end-of-buffer state). Contrast this with the test - * in input(). - */ - if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) - { /* This was really a NUL. */ - yy_state_type yy_next_state; - - (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( ); - - /* Okay, we're now positioned to make the NUL - * transition. We couldn't have - * yy_get_previous_state() go ahead and do it - * for us because it doesn't know how to deal - * with the possibility of jamming (and we don't - * want to build jamming into it because then it - * will run more slowly). - */ - - yy_next_state = yy_try_NUL_trans( yy_current_state ); - - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - - if ( yy_next_state ) - { - /* Consume the NUL. */ - yy_cp = ++(yy_c_buf_p); - yy_current_state = yy_next_state; - goto yy_match; - } - - else - { - yy_cp = (yy_c_buf_p); - goto yy_find_action; - } - } - - else switch ( yy_get_next_buffer( ) ) - { - case EOB_ACT_END_OF_FILE: - { - (yy_did_buffer_switch_on_eof) = 0; - - if ( yywrap( ) ) - { - /* Note: because we've taken care in - * yy_get_next_buffer() to have set up - * yytext, we can now set up - * yy_c_buf_p so that if some total - * hoser (like flex itself) wants to - * call the scanner after we return the - * YY_NULL, it'll still work - another - * YY_NULL will get returned. - */ - (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; - - yy_act = YY_STATE_EOF(YY_START); - goto do_action; - } - - else - { - if ( ! (yy_did_buffer_switch_on_eof) ) - YY_NEW_FILE; - } - break; - } - - case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = - (yytext_ptr) + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( ); - - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - goto yy_match; - - case EOB_ACT_LAST_MATCH: - (yy_c_buf_p) = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; - - yy_current_state = yy_get_previous_state( ); - - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - goto yy_find_action; - } - break; - } - - default: - YY_FATAL_ERROR( - "fatal flex scanner internal error--no action found" ); - } /* end of action switch */ - } /* end of scanning one token */ - } /* end of user's declarations */ -} /* end of yylex */ - -/* yy_get_next_buffer - try to read in a new buffer - * - * Returns a code representing an action: - * EOB_ACT_LAST_MATCH - - * EOB_ACT_CONTINUE_SCAN - continue scanning from current position - * EOB_ACT_END_OF_FILE - end of file - */ -static int yy_get_next_buffer (void) -{ - char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; - char *source = (yytext_ptr); - yy_size_t number_to_move, i; - int ret_val; - - if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) - YY_FATAL_ERROR( - "fatal flex scanner internal error--end of buffer missed" ); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) - { /* Don't try to fill the buffer, so this is an EOF. */ - if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) - { - /* We matched a single character, the EOB, so - * treat this as a final EOF. - */ - return EOB_ACT_END_OF_FILE; - } - - else - { - /* We matched some text prior to the EOB, first - * process it. - */ - return EOB_ACT_LAST_MATCH; - } - } - - /* Try to read more data. */ - - /* First move last chars to start of buffer. */ - number_to_move = (yy_size_t) ((yy_c_buf_p) - (yytext_ptr)) - 1; - - for ( i = 0; i < number_to_move; ++i ) - *(dest++) = *(source++); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) - /* don't do the read, it's not guaranteed to return an EOF, - * just force an EOF - */ - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; - - else - { - yy_size_t num_to_read = - YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; - - while ( num_to_read <= 0 ) - { /* Not enough room in the buffer - grow it. */ - - /* just a shorter name for the current buffer */ - YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; - - int yy_c_buf_p_offset = - (int) ((yy_c_buf_p) - b->yy_ch_buf); - - if ( b->yy_is_our_buffer ) - { - yy_size_t new_size = b->yy_buf_size * 2; - - if ( new_size <= 0 ) - b->yy_buf_size += b->yy_buf_size / 8; - else - b->yy_buf_size *= 2; - - b->yy_ch_buf = (char *) - /* Include room in for 2 EOB chars. */ - yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ); - } - else - /* Can't grow it, we don't own it. */ - b->yy_ch_buf = 0; - - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( - "fatal error - scanner input buffer overflow" ); - - (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; - - num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - - number_to_move - 1; - - } - - if ( num_to_read > YY_READ_BUF_SIZE ) - num_to_read = YY_READ_BUF_SIZE; - - /* Read in more data. */ - YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), - (yy_n_chars), num_to_read ); - - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - if ( (yy_n_chars) == 0 ) - { - if ( number_to_move == YY_MORE_ADJ ) - { - ret_val = EOB_ACT_END_OF_FILE; - yyrestart(yyin ); - } - - else - { - ret_val = EOB_ACT_LAST_MATCH; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = - YY_BUFFER_EOF_PENDING; - } - } - - else - ret_val = EOB_ACT_CONTINUE_SCAN; - - if ((int) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { - /* Extend the array by 50%, plus the number we really need. */ - int new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ); - if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); - } - - (yy_n_chars) += number_to_move; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; - - (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; - - return ret_val; -} - -/* yy_get_previous_state - get the state just before the EOB char was reached */ - - static yy_state_type yy_get_previous_state (void) -{ - yy_state_type yy_current_state; - char *yy_cp; - - yy_current_state = (yy_start); - - for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) - { - YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 13 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - } - - return yy_current_state; -} - -/* yy_try_NUL_trans - try to make a transition on the NUL character - * - * synopsis - * next_state = yy_try_NUL_trans( current_state ); - */ - static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) -{ - int yy_is_jam; - char *yy_cp = (yy_c_buf_p); - - YY_CHAR yy_c = 1; - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 13 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - yy_is_jam = (yy_current_state == 12); - - return yy_is_jam ? 0 : yy_current_state; -} - -#ifndef YY_NO_UNPUT - - static void yyunput (int c, char * yy_bp ) -{ - char *yy_cp; - - yy_cp = (yy_c_buf_p); - - /* undo effects of setting up yytext */ - *yy_cp = (yy_hold_char); - - if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) - { /* need to shift things up to make room */ - /* +2 for EOB chars. */ - yy_size_t number_to_move = (yy_n_chars) + 2; - char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ - YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; - char *source = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; - - while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) - *--dest = *--source; - - yy_cp += (int) (dest - source); - yy_bp += (int) (dest - source); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size; - - if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) - YY_FATAL_ERROR( "flex scanner push-back overflow" ); - } - - *--yy_cp = (char) c; - - (yytext_ptr) = yy_bp; - (yy_hold_char) = *yy_cp; - (yy_c_buf_p) = yy_cp; -} - -#endif - -#ifndef YY_NO_INPUT -#ifdef __cplusplus - static int yyinput (void) -#else - static int input (void) -#endif - -{ - int c; - - *(yy_c_buf_p) = (yy_hold_char); - - if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) - { - /* yy_c_buf_p now points to the character we want to return. - * If this occurs *before* the EOB characters, then it's a - * valid NUL; if not, then we've hit the end of the buffer. - */ - if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) - /* This was really a NUL. */ - *(yy_c_buf_p) = '\0'; - - else - { /* need more input */ - yy_size_t offset = (yy_c_buf_p) - (yytext_ptr); - ++(yy_c_buf_p); - - switch ( yy_get_next_buffer( ) ) - { - case EOB_ACT_LAST_MATCH: - /* This happens because yy_g_n_b() - * sees that we've accumulated a - * token and flags that we need to - * try matching the token before - * proceeding. But for input(), - * there's no matching to consider. - * So convert the EOB_ACT_LAST_MATCH - * to EOB_ACT_END_OF_FILE. - */ - - /* Reset buffer status. */ - yyrestart(yyin ); - - /*FALLTHROUGH*/ - - case EOB_ACT_END_OF_FILE: - { - if ( yywrap( ) ) - return EOF; - - if ( ! (yy_did_buffer_switch_on_eof) ) - YY_NEW_FILE; -#ifdef __cplusplus - return yyinput(); -#else - return input(); -#endif - } - - case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = (yytext_ptr) + offset; - break; - } - } - } - - c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ - *(yy_c_buf_p) = '\0'; /* preserve yytext */ - (yy_hold_char) = *++(yy_c_buf_p); - - return c; -} -#endif /* ifndef YY_NO_INPUT */ - -/** Immediately switch to a different input stream. - * @param input_file A readable stream. - * - * @note This function does not reset the start condition to @c INITIAL . - */ - void yyrestart (FILE * input_file ) -{ - - if ( ! YY_CURRENT_BUFFER ){ - yyensure_buffer_stack (); - YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer(yyin,YY_BUF_SIZE ); - } - - yy_init_buffer(YY_CURRENT_BUFFER,input_file ); - yy_load_buffer_state( ); -} - -/** Switch to a different input buffer. - * @param new_buffer The new input buffer. - * - */ - void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) -{ - - /* TODO. We should be able to replace this entire function body - * with - * yypop_buffer_state(); - * yypush_buffer_state(new_buffer); - */ - yyensure_buffer_stack (); - if ( YY_CURRENT_BUFFER == new_buffer ) - return; - - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - YY_CURRENT_BUFFER_LVALUE = new_buffer; - yy_load_buffer_state( ); - - /* We don't actually know whether we did this switch during - * EOF (yywrap()) processing, but the only time this flag - * is looked at is after yywrap() is called, so it's safe - * to go ahead and always set it. - */ - (yy_did_buffer_switch_on_eof) = 1; -} - -static void yy_load_buffer_state (void) -{ - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; - yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; - (yy_hold_char) = *(yy_c_buf_p); -} - -/** Allocate and initialize an input buffer state. - * @param file A readable stream. - * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. - * - * @return the allocated buffer state. - */ - YY_BUFFER_STATE yy_create_buffer (FILE * file, int size ) -{ - YY_BUFFER_STATE b; - - b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - - b->yy_buf_size = (yy_size_t)size; - - /* yy_ch_buf has to be 2 characters longer than the size given because - * we need to put in 2 end-of-buffer characters. - */ - b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 ); - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - - b->yy_is_our_buffer = 1; - - yy_init_buffer(b,file ); - - return b; -} - -/** Destroy the buffer. - * @param b a buffer created with yy_create_buffer() - * - */ - void yy_delete_buffer (YY_BUFFER_STATE b ) -{ - - if ( ! b ) - return; - - if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ - YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; - - if ( b->yy_is_our_buffer ) - yyfree((void *) b->yy_ch_buf ); - - yyfree((void *) b ); -} - -/* Initializes or reinitializes a buffer. - * This function is sometimes called more than once on the same buffer, - * such as during a yyrestart() or at EOF. - */ - static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file ) - -{ - int oerrno = errno; - - yy_flush_buffer(b ); - - b->yy_input_file = file; - b->yy_fill_buffer = 1; - - /* If b is the current buffer, then yy_init_buffer was _probably_ - * called from yyrestart() or through yy_get_next_buffer. - * In that case, we don't want to reset the lineno or column. - */ - if (b != YY_CURRENT_BUFFER){ - b->yy_bs_lineno = 1; - b->yy_bs_column = 0; - } - - b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; - - errno = oerrno; -} - -/** Discard all buffered characters. On the next scan, YY_INPUT will be called. - * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. - * - */ - void yy_flush_buffer (YY_BUFFER_STATE b ) -{ - if ( ! b ) - return; - - b->yy_n_chars = 0; - - /* We always need two end-of-buffer characters. The first causes - * a transition to the end-of-buffer state. The second causes - * a jam in that state. - */ - b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; - b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; - - b->yy_buf_pos = &b->yy_ch_buf[0]; - - b->yy_at_bol = 1; - b->yy_buffer_status = YY_BUFFER_NEW; - - if ( b == YY_CURRENT_BUFFER ) - yy_load_buffer_state( ); -} - -/** Pushes the new state onto the stack. The new state becomes - * the current state. This function will allocate the stack - * if necessary. - * @param new_buffer The new state. - * - */ -void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) -{ - if (new_buffer == NULL) - return; - - yyensure_buffer_stack(); - - /* This block is copied from yy_switch_to_buffer. */ - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - /* Only push if top exists. Otherwise, replace top. */ - if (YY_CURRENT_BUFFER) - (yy_buffer_stack_top)++; - YY_CURRENT_BUFFER_LVALUE = new_buffer; - - /* copied from yy_switch_to_buffer. */ - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; -} - -/** Removes and deletes the top of the stack, if present. - * The next element becomes the new top. - * - */ -void yypop_buffer_state (void) -{ - if (!YY_CURRENT_BUFFER) - return; - - yy_delete_buffer(YY_CURRENT_BUFFER ); - YY_CURRENT_BUFFER_LVALUE = NULL; - if ((yy_buffer_stack_top) > 0) - --(yy_buffer_stack_top); - - if (YY_CURRENT_BUFFER) { - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; - } -} - -/* Allocates the stack if it does not exist. - * Guarantees space for at least one push. - */ -static void yyensure_buffer_stack (void) -{ - yy_size_t num_to_alloc; - - if (!(yy_buffer_stack)) { - - /* First allocation is just for 2 elements, since we don't know if this - * scanner will even need a stack. We use 2 instead of 1 to avoid an - * immediate realloc on the next call. - */ - num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ - (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc - (num_to_alloc * sizeof(struct yy_buffer_state*) - ); - if ( ! (yy_buffer_stack) ) - YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); - - memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); - - (yy_buffer_stack_max) = num_to_alloc; - (yy_buffer_stack_top) = 0; - return; - } - - if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ - - /* Increase the buffer to prepare for a possible push. */ - yy_size_t grow_size = 8 /* arbitrary grow size */; - - num_to_alloc = (yy_buffer_stack_max) + grow_size; - (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc - ((yy_buffer_stack), - num_to_alloc * sizeof(struct yy_buffer_state*) - ); - if ( ! (yy_buffer_stack) ) - YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); - - /* zero only the new slots.*/ - memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); - (yy_buffer_stack_max) = num_to_alloc; - } -} - -/** Setup the input buffer state to scan directly from a user-specified character buffer. - * @param base the character buffer - * @param size the size in bytes of the character buffer - * - * @return the newly allocated buffer state object. - */ -YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) -{ - YY_BUFFER_STATE b; - - if ( size < 2 || - base[size-2] != YY_END_OF_BUFFER_CHAR || - base[size-1] != YY_END_OF_BUFFER_CHAR ) - /* They forgot to leave room for the EOB's. */ - return 0; - - b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); - - b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ - b->yy_buf_pos = b->yy_ch_buf = base; - b->yy_is_our_buffer = 0; - b->yy_input_file = 0; - b->yy_n_chars = b->yy_buf_size; - b->yy_is_interactive = 0; - b->yy_at_bol = 1; - b->yy_fill_buffer = 0; - b->yy_buffer_status = YY_BUFFER_NEW; - - yy_switch_to_buffer(b ); - - return b; -} - -/** Setup the input buffer state to scan a string. The next call to yylex() will - * scan from a @e copy of @a str. - * @param yystr a NUL-terminated string to scan - * - * @return the newly allocated buffer state object. - * @note If you want to scan bytes that may contain NUL values, then use - * yy_scan_bytes() instead. - */ -YY_BUFFER_STATE yy_scan_string (yyconst char * yystr ) -{ - - return yy_scan_bytes(yystr,strlen(yystr) ); -} - -/** Setup the input buffer state to scan the given bytes. The next call to yylex() will - * scan from a @e copy of @a bytes. - * @param yybytes the byte buffer to scan - * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. - * - * @return the newly allocated buffer state object. - */ -YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len ) -{ - YY_BUFFER_STATE b; - char *buf; - yy_size_t n; - yy_size_t i; - - /* Get memory for full buffer, including space for trailing EOB's. */ - n = _yybytes_len + 2; - buf = (char *) yyalloc(n ); - if ( ! buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); - - for ( i = 0; i < _yybytes_len; ++i ) - buf[i] = yybytes[i]; - - buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; - - b = yy_scan_buffer(buf,n ); - if ( ! b ) - YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); - - /* It's okay to grow etc. this buffer, and we should throw it - * away when we're done. - */ - b->yy_is_our_buffer = 1; - - return b; -} - -#ifndef YY_EXIT_FAILURE -#define YY_EXIT_FAILURE 2 -#endif - -static void yy_fatal_error (yyconst char* msg ) -{ - (void) fprintf( stderr, "%s\n", msg ); - exit( YY_EXIT_FAILURE ); -} - -/* Redefine yyless() so it works in section 3 code. */ - -#undef yyless -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - yytext[yyleng] = (yy_hold_char); \ - (yy_c_buf_p) = yytext + yyless_macro_arg; \ - (yy_hold_char) = *(yy_c_buf_p); \ - *(yy_c_buf_p) = '\0'; \ - yyleng = yyless_macro_arg; \ - } \ - while ( 0 ) - -/* Accessor methods (get/set functions) to struct members. */ - -/** Get the current line number. - * - */ -int yyget_lineno (void) -{ - - return yylineno; -} - -/** Get the input stream. - * - */ -FILE *yyget_in (void) -{ - return yyin; -} - -/** Get the output stream. - * - */ -FILE *yyget_out (void) -{ - return yyout; -} - -/** Get the length of the current token. - * - */ -yy_size_t yyget_leng (void) -{ - return yyleng; -} - -/** Get the current token. - * - */ - -char *yyget_text (void) -{ - return yytext; -} - -/** Set the current line number. - * @param _line_number line number - * - */ -void yyset_lineno (int _line_number ) -{ - - yylineno = _line_number; -} - -/** Set the input stream. This does not discard the current - * input buffer. - * @param _in_str A readable stream. - * - * @see yy_switch_to_buffer - */ -void yyset_in (FILE * _in_str ) -{ - yyin = _in_str ; -} - -void yyset_out (FILE * _out_str ) -{ - yyout = _out_str ; -} - -int yyget_debug (void) -{ - return yy_flex_debug; -} - -void yyset_debug (int _bdebug ) -{ - yy_flex_debug = _bdebug ; -} - -static int yy_init_globals (void) -{ - /* Initialization is the same as for the non-reentrant scanner. - * This function is called from yylex_destroy(), so don't allocate here. - */ - - (yy_buffer_stack) = 0; - (yy_buffer_stack_top) = 0; - (yy_buffer_stack_max) = 0; - (yy_c_buf_p) = (char *) 0; - (yy_init) = 0; - (yy_start) = 0; - -/* Defined in main.c */ -#ifdef YY_STDINIT - yyin = stdin; - yyout = stdout; -#else - yyin = (FILE *) 0; - yyout = (FILE *) 0; -#endif - - /* For future reference: Set errno on error, since we are called by - * yylex_init() - */ - return 0; -} - -/* yylex_destroy is for both reentrant and non-reentrant scanners. */ -int yylex_destroy (void) -{ - - /* Pop the buffer stack, destroying each element. */ - while(YY_CURRENT_BUFFER){ - yy_delete_buffer(YY_CURRENT_BUFFER ); - YY_CURRENT_BUFFER_LVALUE = NULL; - yypop_buffer_state(); - } - - /* Destroy the stack itself. */ - yyfree((yy_buffer_stack) ); - (yy_buffer_stack) = NULL; - - /* Reset the globals. This is important in a non-reentrant scanner so the next time - * yylex() is called, initialization will occur. */ - yy_init_globals( ); - - return 0; -} - -/* - * Internal utility routines. - */ - -#ifndef yytext_ptr -static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) -{ - - int i; - for ( i = 0; i < n; ++i ) - s1[i] = s2[i]; -} -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * s ) -{ - int n; - for ( n = 0; s[n]; ++n ) - ; - - return n; -} -#endif - -void *yyalloc (yy_size_t size ) -{ - return (void *) malloc( size ); -} - -void *yyrealloc (void * ptr, yy_size_t size ) -{ - - /* The cast to (char *) in the following accommodates both - * implementations that use char* generic pointers, and those - * that use void* generic pointers. It works with the latter - * because both ANSI C and C++ allow castless assignment from - * any pointer type to void*, and deal with argument conversions - * as though doing an assignment. - */ - return (void *) realloc( (char *) ptr, size ); -} - -void yyfree (void * ptr ) -{ - free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ -} - -#define YYTABLES_NAME "yytables" - -#line 82 "textlang.l" - - - -/* More language-dependent code */ - -void -yystart(void) { - BEGIN INITIAL; -} - diff --git a/judger/core/sim/sim_2_77/ChangeLog b/judger/core/sim/sim_3_01/ChangeLog old mode 100755 new mode 100644 similarity index 90% rename from judger/core/sim/sim_2_77/ChangeLog rename to judger/core/sim/sim_3_01/ChangeLog index e1805dcd..e3444d76 --- a/judger/core/sim/sim_2_77/ChangeLog +++ b/judger/core/sim/sim_3_01/ChangeLog @@ -1,3 +1,73 @@ +2017-03-19 Dick Grune + + * c++lang.l contributed by Evin Murphy (evin.murphy@ucdconnect.ie). + +2016-08-07 Dick Grune + + * compare.c (lcs): Finding the text into which i1 points was done by + linear search. Replaced by binary search. This resulted in no direct + improvement but should be beneficial for very large numbers of files. + +2016-08-05 Dick Grune + + * hash.c (make_forward_references_perfect): This routine now + constructs perfect forward references. This allows the comparison code + in compare.c (lcs) to skip the first Min_Run_Size tokens when + comparing two chunks. This yields about 8% speed-up. + +2016-08-03 Dick Grune + + * hash.c (make_forward_references_using_hash): A lot of work was being + done to compute the hash value of a run, using sampling etc. A new + scheme was implemented in which the hash value consists of all tokens + in the run, each circularly left-shifted over a distance proportional + to its position in the run. This value can be computed incrementally + in constant time, by removing the oldest and adding the newest token + at each position. + Care had to be taken not to produce negative values for entities of + type size_t. + For moderately large comparisons (~ 10M tokens) this yields an + over-all speed-up of about 20%. + +2016-05-29 Dick Grune + + * pass3.c: Surprisingly, very large runs of the program can get out of + memory far into the computation, in spite of the fact that sim + allocates almost all its memory while reading the input. However, the + found runs of text are collected using Mallocked memory, for producing + sorted output. In many cases one would rather have unsorted output + than no output at all. Decided to implement the -u option, for + unsorted output, thus not using any additional memory. + +2016-05-13 Dick Grune + + * compare.c (lcs): the -X option works. It uses the linear algorithm + to compare a file F to two segments of the text: the segment from the + start of the text to the start of F, and from the end of F to the end + of the text. Runs found are then reported in percentages. + +2016-05-06 Dick Grune + + * compare.c: The results of the analysis in + Similarity_Percentage_Computation.tex have been implemented, and under + the -p option percentages are now computed consistently. In + particular, the files in the directory Contributors/Debora_Weber-Wulff/ + yield the same relative percentages independent of the order they are + entered in; see Pfubar_shuffle and Pslash_shuffle. Note: both parts of + Pslash_shuffle were shuffled independently. + +2016-04-10 Dick Grune + + * runs.c: aiso (arbitrary in sorted out) package replaced by an + instantiation of the package sortlist. + +2014-02-17 Dick Grune + + * sim.c (is_new_old_separator): MinGW sometimes (?) interprets the / + as a command-line argument as a reference to the MinGW tree, which + makes the / unusable as a separator. Even escaping it ("/") does not + help. Added the | as a separator. + 2014-01-26 Dick Grune * %z from Marcus Brinkmann implemented by a routine size_t2string. @@ -682,5 +752,5 @@ # This file is part of the software similarity tester SIM. # Written by Dick Grune, Vrije Universiteit, Amsterdam. -# $Id: ChangeLog,v 2.24 2014-01-26 21:52:58 Gebruiker Exp $ +# $Id: ChangeLog,v 2.33 2017-03-19 09:30:37 dick Exp $ # diff --git a/judger/core/sim/sim_3_01/ForEachFile.c b/judger/core/sim/sim_3_01/ForEachFile.c new file mode 100644 index 00000000..73a0edf5 --- /dev/null +++ b/judger/core/sim/sim_3_01/ForEachFile.c @@ -0,0 +1,166 @@ +/* This file is part of the auxiliaries library. + Written by Dick Grune, Vrije Universiteit, Amsterdam. + $Id: ForEachFile.c,v 1.23 2016-02-22 08:20:42 Gebruiker Exp $ +*/ + +#include +#include +#include +#include +#include + +#include "ForEachFile.h" + +/* Library module source prelude */ +#undef _FOREACHFILE_CODE_ +#ifndef lint +#define _FOREACHFILE_CODE_ +#endif +#ifdef LIB +#define _FOREACHFILE_CODE_ +#endif + +#ifdef _FOREACHFILE_CODE_ + +/* Library module source code */ + + /* TREE SCANNING */ +#ifdef S_IFLNK /* system with symbolic links */ +#define LSTAT lstat +#else /* S_IFLNK */ +#define LSTAT Stat +#endif /* S_IFLNK */ + +int +is_dirstat(const struct stat *fs) { + if (!fs) return 0; + return ((fs->st_mode & S_IFMT) == S_IFDIR); +} + +int +is_Dirname(const Fchar *Fn) { + if (!Fn) return 0; + struct stat stb; + if (LSTAT(Fn, &stb) < 0) return 0; + return ((stb.st_mode & S_IFMT) == S_IFDIR); +} + +int +is_Admin_Dirname(const Fchar *Fn) { + if (!Fn) return 0; + return Fnamecmp(Fn, str2Fname(".")) == 0 + || Fnamecmp(Fn, str2Fname("..")) == 0; +} + +static void do_dir( + Fchar *Fn, + int (*proc)(const Fchar *, const char *, const struct stat *) +); + +static void +do_name(Fchar *Fn, + int (*proc)(const Fchar *, const char *, const struct stat *), + int top_level +) { + /* examine Fn */ + struct stat fs; + if (LSTAT(Fn, &fs) < 0) { + (void)(*proc)(Fn, strerror(errno), 0); + return; + } + + /* report on Fn and get possible return code */ + int rc = (*proc)(Fn, (char*)0, &fs); + + if (!is_dirstat(&fs)) return; + + /* Fn is a directory, so rc may be meaningful */ + if (!top_level) if (!rc) return; + +#ifdef S_IFLNK + /* don't follow links */ + if ((fs.st_mode & S_IFMT) == S_IFLNK) return; +#endif + + do_dir(Fn, proc); +} + +static void +do_dir( + Fchar *Fn, + int (*proc)(const Fchar *, const char *, const struct stat *) +) { + + /* treat directory */ + Dir_t *dir = Opendir(Fn); + if (dir == 0) { + (void)(*proc)(Fn, "directory not readable", 0); + return; + } + + /* scan new directory */ + + /* append separator */ + int Fn_len = Fnamelen(Fn); + Fn[Fn_len++] = '/'; + Fn[Fn_len] = '\0'; + + /* descend */ + Dirent_t *dent; + while ((dent = Readdir(dir)) != (Dirent_t *)0) { + const Fchar *d_name = dent->d_name; + if (is_Admin_Dirname(d_name)) continue; + + /* append name */ + Fnamecat(Fn, d_name); + do_name(Fn, proc, 0); + /* remove appended name*/ + Fn[Fn_len] = '\0'; + } + /* remove appended separator*/ + Fn[--Fn_len] = '\0'; + Closedir(dir); +} + +static MSDOS_sep = (Fchar)'\\'; +static UNIX_sep = (Fchar)'/'; + +static void +clean_name(Fchar *Fn) { + /* remove a trailing separator */ + int Fn_len = Fnamelen(Fn); + if (Fn_len > 1 && (Fn[Fn_len-1] == MSDOS_sep || Fn[Fn_len-1] == UNIX_sep)) { + Fn[Fn_len-1] = '\0'; + } +} + + /* THE ENTRIES */ +void +ForEachFile( + const Fchar *Fname, + int (*proc)(const Fchar *, const char *, const struct stat *) +) { + if (!Fname || !Fname[0] || !proc) return; /* just to make sure */ + + /* get Fn */ + Fchar Fn[MAX_FILE_NAME_LENGTH]; + Fnamecpy(Fn, Fname); + clean_name(Fn); + + /* top level */ + do_name(Fn, proc, 1); +} + +/* End library module source code */ +#endif /* _FOREACHFILE_CODE_ */ + +#ifdef lint +static void +satisfy_lint(void *x) { + (void)is_dirstat(0); + (void)is_Dirname(0); + (void)is_Admin_Dirname(0); + ForEachFile(0, 0); + satisfy_lint(x); +} +#endif /* lint */ diff --git a/judger/core/sim/sim_3_01/ForEachFile.h b/judger/core/sim/sim_3_01/ForEachFile.h new file mode 100644 index 00000000..e94740ad --- /dev/null +++ b/judger/core/sim/sim_3_01/ForEachFile.h @@ -0,0 +1,52 @@ +/* This file is part of the auxiliaries library. + Written by Dick Grune, Vrije Universiteit, Amsterdam. + $Id: ForEachFile.h,v 1.14 2017-01-22 14:49:59 Gebruiker Exp $ +*/ + +#ifndef _FOREACHFILE_H_ +#define _FOREACHFILE_H_ + +#include "fname.h" +#include +#include + +/**** +* ForEachFile(const Fchar *Fn, int (*proc)(...): + Each file or directory reachable from Fn is passed to the procedure proc(), + which is declared as: + + int proc(const Fchar *Fn, const char *msg, const struct stat *fs): + the file or directory Fn has been reached; + if msg != NULL, an error prevails the text of which is *msg; + otherwise fs points to the stat buffer for Fn. + + If Fn is a file or the argument of ForEachFile(), the return value of + proc() is ignored; if it is a directory but not the argument of + ForEachFile() and the return value is 0, the directory is not visited + further, and files and directories in it are not reported. + + Basically if proc() always returns 1, all reachable files are reported; + if it always returns 0, only the local files and directories are + reported. But finer control is possible. + +* proc() is not called with the directory names "." or ".." unless it is the + first argument to ForEachFile(). + +* MAX_FILE_NAME_LENGTH is the maximum length of the file name Fn, including + directories. +****/ + +/* Public entries */ +#define MAX_FILE_NAME_LENGTH 1024 /* maximum file name length */ + +extern void ForEachFile( + const Fchar *Fname, + int (*proc)(const Fchar *, const char *, const struct stat *) +); + +/* avoid awkward dir test */ +extern int is_dirstat(const struct stat *fs); +extern int is_Dirname(const Fchar *Fn); +extern int is_Admin_Dirname(const Fchar *Fn); /* !=0 for "." and ".." */ + +#endif /* _FOREACHFILE_H_ */ diff --git a/judger/core/sim/sim_3_01/Korean1.txt b/judger/core/sim/sim_3_01/Korean1.txt new file mode 100644 index 00000000..f8c6c7e0 --- /dev/null +++ b/judger/core/sim/sim_3_01/Korean1.txt @@ -0,0 +1,17 @@ +Lee + +노인은 신체적, 정신적. 경제적으로 의존성이 높은 +취약계층이며 만성 퇴행성 질환의 유병률이 높고, 장 +기적인 치료 및 요양보호와 포괄적인 보건의료 서비 +스의 수요가 높은 집단이다(Sunwoo, 2008). +2009년 통계청에 따르면 우리나라 전체 인구 가운 +데 65세 이상 인구는 10.7%로 고령화 사회이며, 건강 +심사 평가원의 2010년 상반기 진료비 통계지표에서 + +노인 인구의 진료비는 2009년 상반기 대비 15.5% 증 +가 했고, 전체 진료비의 31.4%를 차지하여, 노인 의 +료비의 비중이 매우 높은 것을 알 수 있다.(Health +Insurance Review & Assessment Service, 2010) ©≠𒌩우리 +나라에서 노인 부양은 핵가족화와 여성의 사회 활동 +참여가 증가하고 가정에서 노인을 돌볼 수 없어 장기 +요양 기관에서 간호와 관리를 하게 되는 경향이 증가 diff --git a/judger/core/sim/sim_3_01/Korean2.txt b/judger/core/sim/sim_3_01/Korean2.txt new file mode 100644 index 00000000..273b34ef --- /dev/null +++ b/judger/core/sim/sim_3_01/Korean2.txt @@ -0,0 +1,15 @@ +노인 인구의 진료비는 2009년 상반기 대비 15.5% 증 +가 했고, 전체 진료비의 31.4%를 차지하여, 노인 의 +료비의 비중이 매우 높은 것을 알 수 있다.(Health +Insurance Review & Assessment Service, 2010) ©≠𒌩우리 +나라에서 노인 부양은 핵가족화와 여성의 사회 활동 +참여가 증가하고 가정에서 노인을 돌볼 수 없어 장기 +요양 기관에서 간호와 관리를 하게 되는 경향이 증가 + +노인은 신체적, 정신적. 경제적으로 의존성이 높은 +취약계층이며 만성 퇴행성 질환의 유병률이 높고, 장 +기적인 치료 및 요양보호와 포괄적인 보건의료 서비 +스의 수요가 높은 집단이다(Sunwoo, 2008). +2009년 통계청에 따르면 우리나라 전체 인구 가운 +데 65세 이상 인구는 10.7%로 고령화 사회이며, 건강 +심사 평가원의 2010년 상반기 진료비 통계지표에서 diff --git a/judger/core/sim/sim_2_77/LICENSE.txt b/judger/core/sim/sim_3_01/LICENSE.txt old mode 100755 new mode 100644 similarity index 100% rename from judger/core/sim/sim_2_77/LICENSE.txt rename to judger/core/sim/sim_3_01/LICENSE.txt diff --git a/judger/core/sim/sim_2_77/Makefile b/judger/core/sim/sim_3_01/Makefile old mode 100755 new mode 100644 similarity index 62% rename from judger/core/sim/sim_2_77/Makefile rename to judger/core/sim/sim_3_01/Makefile index c9aeab64..e8d3cdab --- a/judger/core/sim/sim_2_77/Makefile +++ b/judger/core/sim/sim_3_01/Makefile @@ -1,8 +1,9 @@ # This file is part of the software similarity tester SIM. # Written by Dick Grune, Vrije Universiteit, Amsterdam. -# $Id: Makefile,v 2.58 2014-01-27 20:50:50 Gebruiker Exp $ +# $Id: Makefile,v 2.97 2017-03-19 09:49:29 dick Exp $ # +VERSION="-DVERSION=\"3.0.1 of 2017-08-15\"" # E N T R Y P O I N T S @@ -14,8 +15,11 @@ help: @echo 'exes: create executables in MSDOS' @echo 'install: install all binaries' @echo '' + @echo 'view_man: view sim.pdf' @echo 'lint: lint sim sources' @echo 'simsim: run sim_c on the sim sources' + @echo 'view_SPC: view the percentage computation document' + @echo 'chklat: do a LaTeX check on the .tex documents' @echo '' @echo 'fresh: remove created files' @@ -27,7 +31,7 @@ help: # =============== including ../lib/sysidf.mk here # This file is part of the auxiliary libraries. # Written by Dick Grune, dick@dickgrune.com -# $Id: sysidf.mk,v 1.16 2014-01-25 21:29:34 Gebruiker Exp $ +# $Id: sysidf.mk,v 1.18 2016-04-22 15:11:58 dick Exp $ # ################################################################ @@ -37,56 +41,47 @@ SYSTEM = UNIX SUBSYSTEM = SOLARIS # Locations -DIR = /home/dick +DIR = /usr BINDIR = $(DIR)/bin.`$(DIR)/bin/arch` MAN1DIR = $(DIR)/man/man1 # Commands COPY = cp -p -EXE = # +EXE = .exe# LEX = flex LN = ln ZIP = zip -o -################################################################ -# For MSDOS + MinGW - -#SYSTEM = MSDOS -#SUBSYSTEM = MinGW - -# Locations -#DIR = C:/BIN -#BINDIR = C:/BIN -#MAN1DIR = C:/BIN - -# Commands (cp required, since xcopy cannot handle forward slashes) -COPY = cp -p -EXE = .exe -LEX = flex -LN = ln -ZIP = zip -o - -################################################################ -# General, compiling: +############################################################### +# General, C compilation: CC = gcc -D$(SYSTEM) -D$(SUBSYSTEM) LINT = lint -ansi -D$(SYSTEM) -D$(SUBSYSTEM) LINTFLAGS = -xh -# General, manual: +# General, text: +LATEX = pdflatex +SHOW_PDF = evince +SHOW_PDF = acroread +SHOW_PDF = pdfview +GROFF = groff -man +GROFF = man2pdf + .SUFFIXES: .1 .3 .pdf .1.pdf: - man2pdf $< + $(GROFF) $< .3.pdf: - man2pdf $< + $(GROFF) $< # =============== end of ../lib/sysidf.mk -# Compiler Options -MEMORY = -DMEMLEAK -DMEMCLOBBER -CFLAGS = $(MEMORY) -O4 +# Compiling +MEMORY = -DMEMCHECK -DMEMCLOBBER +CFLAGS = $(VERSION) $(MEMORY) -O4 LIBFLAGS = # LINTFLAGS = $(MEMORY) -h# -X +LOADFLAGS = -s# # strip symbol table +LOADER = $(CC) $(LOADFLAGS) # Debugging CFLAGS += -DDEBUG @@ -96,83 +91,113 @@ DEBUG_H = debug.h # T E S T P A R A M E T E R S -# percentage test -TEST_LANG = c -TEST_OPT = -p -TEST_INP = *.l +# Rumen Stevanov test +TEST_LANG = text +TEST_OPT = -pPae -r4 -O -t4 +TEST_INP = Contributors/Rumen_Stefanov/new/*.txt -# text test +# slash test TEST_LANG = text -TEST_OPT = -r 5 -TEST_INP = test_seplet +TEST_OPT = -r24 -M clang.c pascallang.c "|" textlang.c +TEST_INP = -# Rumen Stevanov test +# spaced word test TEST_LANG = text -TEST_OPT = -p -TEST_INP = Rumen_Stefanov/new/*.txt +TEST_OPT = -r 5 +TEST_INP = testfiles/test_seplet -# Kuhl test 1 +# -i option test TEST_LANG = c -TEST_OPT = -p -TEST_INP = Kuhl/simc1.c Kuhl/simc2.c +TEST_OPT = -f -r 20 -R -i $@ @@ -227,18 +248,36 @@ SIM_C_CFS = $(SIM_CFS) $(ALG_CFS) $(CLANG_CFS) SIM_C_OBJ = $(SIM_OBJ) $(ALG_OBJ) $(CLANG_OBJ) sim_c$(EXE): $(SIM_C_OBJ) - $(CC) $(SIM_C_OBJ) -o $@ + $(LOADER) $(SIM_C_OBJ) -o $@ SIM_GRB += clang.c sim_c $(BINDIR)/sim_c$(EXE): sim_c$(EXE) $(COPY) sim_c$(EXE) $@ +# The C++ Language module: # C++ +C++LANG_CFS = c++lang.c +C++LANG_OBJ = c++lang.o +C++LANG_SRC = c++lang.l + +c++lang.c: c++lang.l + $(LEX) -t c++lang.l >$@ + +SIM_C++_CFS = $(SIM_CFS) $(ALG_CFS) $(C++LANG_CFS) +SIM_C++_OBJ = $(SIM_OBJ) $(ALG_OBJ) $(C++LANG_OBJ) + +sim_c++$(EXE): $(SIM_C++_OBJ) + $(LOADER) $(SIM_C++_OBJ) -o $@ + +SIM_GRB += c++lang.c sim_c++ + +$(BINDIR)/sim_c++$(EXE): sim_c++$(EXE) + $(COPY) sim_c++$(EXE) $@ + # The Java Language module: # Java JAVALANG_CFS = javalang.c JAVALANG_OBJ = javalang.o JAVALANG_SRC = javalang.l -JAVALANG_FLS = $(JAVALANG_SRC) javalang.c: javalang.l $(LEX) -t javalang.l >$@ @@ -247,7 +286,7 @@ SIM_JAVA_CFS = $(SIM_CFS) $(ALG_CFS) $(JAVALANG_CFS) SIM_JAVA_OBJ = $(SIM_OBJ) $(ALG_OBJ) $(JAVALANG_OBJ) sim_java$(EXE): $(SIM_JAVA_OBJ) - $(CC) $(SIM_JAVA_OBJ) -o $@ + $(LOADER) $(SIM_JAVA_OBJ) -o $@ SIM_GRB += javalang.c sim_java @@ -258,7 +297,6 @@ $(BINDIR)/sim_java$(EXE): sim_java$(EXE) PASCLANG_CFS = pascallang.c PASCLANG_OBJ = pascallang.o PASCLANG_SRC = pascallang.l -PASCLANG_FLS = $(PASCLANG_SRC) pascallang.c: pascallang.l $(LEX) -t pascallang.l >pascallang.c @@ -267,7 +305,7 @@ SIM_PASC_CFS = $(SIM_CFS) $(ALG_CFS) $(PASCLANG_CFS) SIM_PASC_OBJ = $(SIM_OBJ) $(ALG_OBJ) $(PASCLANG_OBJ) sim_pasc$(EXE): $(SIM_PASC_OBJ) - $(CC) $(SIM_PASC_OBJ) -o $@ + $(LOADER) $(SIM_PASC_OBJ) -o $@ SIM_GRB += pascallang.c sim_pasc @@ -278,7 +316,6 @@ $(BINDIR)/sim_pasc$(EXE): sim_pasc$(EXE) M2LANG_CFS = m2lang.c M2LANG_OBJ = m2lang.o M2LANG_SRC = m2lang.l -M2LANG_FLS = $(M2LANG_SRC) m2lang.c: m2lang.l $(LEX) -t m2lang.l >$@ @@ -287,7 +324,7 @@ SIM_M2_CFS = $(SIM_CFS) $(ALG_CFS) $(M2LANG_CFS) SIM_M2_OBJ = $(SIM_OBJ) $(ALG_OBJ) $(M2LANG_OBJ) sim_m2$(EXE): $(SIM_M2_OBJ) - $(CC) $(SIM_M2_OBJ) -o $@ + $(LOADER) $(SIM_M2_OBJ) -o $@ SIM_GRB += m2lang.c sim_m2 @@ -298,7 +335,6 @@ $(BINDIR)/sim_m2$(EXE): sim_m2$(EXE) LISPLANG_CFS = lisplang.c LISPLANG_OBJ = lisplang.o LISPLANG_SRC = lisplang.l -LISPLANG_FLS = $(LISPLANG_SRC) lisplang.c: lisplang.l $(LEX) -t lisplang.l >$@ @@ -307,7 +343,7 @@ SIM_LISP_CFS = $(SIM_CFS) $(ALG_CFS) $(LISPLANG_CFS) SIM_LISP_OBJ = $(SIM_OBJ) $(ALG_OBJ) $(LISPLANG_OBJ) sim_lisp$(EXE): $(SIM_LISP_OBJ) - $(CC) $(SIM_LISP_OBJ) -o $@ + $(LOADER) $(SIM_LISP_OBJ) -o $@ SIM_GRB += lisplang.c sim_lisp @@ -318,7 +354,6 @@ $(BINDIR)/sim_lisp$(EXE): sim_lisp$(EXE) MIRALANG_CFS = miralang.c MIRALANG_OBJ = miralang.o MIRALANG_SRC = miralang.l -MIRALANG_FLS = $(MIRALANG_SRC) miralang.c: miralang.l $(LEX) -t miralang.l >$@ @@ -327,7 +362,7 @@ SIM_MIRA_CFS = $(SIM_CFS) $(ALG_CFS) $(MIRALANG_CFS) SIM_MIRA_OBJ = $(SIM_OBJ) $(ALG_OBJ) $(MIRALANG_OBJ) sim_mira$(EXE): $(SIM_MIRA_OBJ) - $(CC) $(SIM_MIRA_OBJ) -o $@ + $(LOADER) $(SIM_MIRA_OBJ) -o $@ SIM_GRB += miralang.c sim_mira @@ -338,7 +373,6 @@ $(BINDIR)/sim_mira$(EXE): sim_mira$(EXE) TEXTLANG_CFS = textlang.c TEXTLANG_OBJ = textlang.o TEXTLANG_SRC = textlang.l -TEXTLANG_FLS = $(TEXTLANG_SRC) textlang.c: textlang.l $(LEX) -t textlang.l >$@ @@ -347,7 +381,7 @@ SIM_TEXT_CFS = $(SIM_CFS) $(TEXTLANG_CFS) SIM_TEXT_OBJ = $(SIM_OBJ) $(TEXTLANG_OBJ) sim_text$(EXE): $(SIM_TEXT_OBJ) - $(CC) $(SIM_TEXT_OBJ) -o $@ + $(LOADER) $(SIM_TEXT_OBJ) -o $@ SIM_GRB += textlang.c sim_text @@ -365,23 +399,34 @@ $(BINDIR)/sim_text$(EXE): sim_text$(EXE) - - - # T E S T S # Some simple tests: +.PHONY: sim.res percentages.res + sim.res: sim_$(TEST_LANG)$(EXE) $(TEST_INP) ./sim_$(TEST_LANG)$(EXE) $(TEST_OPT) $(TEST_INP) -stream.res: sim_$(TEST_LANG)$(EXE) $(TEST_INP) +stream.res: sim_$(TEST_LANG)$(EXE) ./sim_$(TEST_LANG)$(EXE) -- $(TEST_OPT) $(TEST_INP) >$@ wc $@ $(TEST_INP) +TEST_GRB = stream.res -percentages.res:sim_$(TEST_LANG)$(EXE) $(TEST_INP) - ./sim_$(TEST_LANG)$(EXE) -p $(TEST_OPT) $(TEST_INP) +PERC_TEST_EXE = sim_text$(EXE) +PERC_TEST_FILES = foo_100 foo_150 +PERC_TEST_EXE = sim_c$(EXE) +PERC_TEST_FILES = pascallang.l clang.l javalang.l +percentages.res:$(PERC_TEST_EXE) $(PERC_TEST_FILES) + @echo '' + ./$(PERC_TEST_EXE) -T -p $(PERC_TEST_FILES) + @echo '' + ./$(PERC_TEST_EXE) -T -pa $(PERC_TEST_FILES) + @echo '' + ./$(PERC_TEST_EXE) -T -pae $(PERC_TEST_FILES) + +version.res: sim_$(TEST_LANG)$(EXE) + ./sim_$(TEST_LANG)$(EXE) -v -TEST_GRB = stream.res # More simple tests, using the C version only: simsim: sim_c$(EXE) $(SIM_CFS) $(ALG_CFS) @@ -394,26 +439,30 @@ lint: $(SIM_SRC) $(ALG_SRC) $(ABS_CFS) # O T H E R E N T R I E S -# Sets of files: general, modules, main programs, languages -CFS = $(SIM_CFS) $(ALG_CFS) \ - $(CLANG_CFS) $(JAVALANG_CFS) $(PASCLANG_CFS) $(M2LANG_CFS) \ - $(LISPLANG_CFS) $(MIRALANG_CFS) $(TEXTLANG_CFS) -OBJ = $(SIM_OBJ) $(ALG_OBJ) \ - $(CLANG_OBJ) $(JAVALANG_OBJ) $(PASCLANG_OBJ) $(M2LANG_OBJ) \ - $(LISPLANG_OBJ) $(MIRALANG_OBJ) $(TEXTLANG_OBJ) -SRC = $(SIM_SRC) $(ALG_SRC) \ - $(CLANG_SRC) $(JAVALANG_SRC) $(PASCLANG_SRC) $(M2LANG_SRC) \ - $(LISPLANG_SRC) $(MIRALANG_SRC) $(TEXTLANG_SRC) -FLS = $(SIM_FLS) $(ALG_FLS) \ - $(CLANG_FLS) $(JAVALANG_FLS) $(PASCLANG_FLS) $(M2LANG_FLS) \ - $(LISPLANG_FLS) $(MIRALANG_FLS) $(TEXTLANG_FLS) \ - sysidf.mk sysidf.msdos sysidf.unix -DOC = README sim.1 sim.txt sim.html ChangeLog Answers TechnReport +# Documentation + +view_man: sim.pdf + $(SHOW_PDF) sim.pdf + +%.pdf: %.tex + $(LATEX) $< || log2errmsg <$*.log + $(LATEX) $< + $(LATEX) $< + +SPC = Similarity_Percentage_Computation +view_SPC: $(SPC).pdf + $(SHOW_PDF) $(SPC).pdf +DOCS += $(SPC).pdf + +# LaTeX checker +chklat: + chklat *.tex # Installation install_all: install # just a synonym install: $(MAN1DIR)/sim.1 \ $(BINDIR)/sim_c$(EXE) \ + $(BINDIR)/sim_c++$(EXE) \ $(BINDIR)/sim_java$(EXE) \ $(BINDIR)/sim_pasc$(EXE) \ $(BINDIR)/sim_m2$(EXE) \ @@ -426,11 +475,13 @@ $(MAN1DIR)/sim.1: sim.1 # Clean-up + .PHONY: clean fresh clean: -rm -f *.o -rm -f $(SIM_GRB) -rm -f $(TEST_GRB) + -rm -f *.aux *.log *.out -rm -f a.out a.exe sim.txt core mon.out fresh: clean @@ -441,51 +492,53 @@ fresh: clean # DO NOT DELETE THIS LINE -- make depend depends on it. ForEachFile.o: ForEachFile.c ForEachFile.h fname.h Malloc.o: Malloc.c any_int.h Malloc.h -add_run.o: add_run.c sim.h debug.par text.h runs.h aiso.spc percentages.h \ - Malloc.h options.h error.h add_run.h -algollike.o: algollike.c options.h error.h token.h algollike.h +add_run.o: add_run.c sim.h text.h runs.h percentages.h options.h \ + add_run.h +algollike.o: algollike.c sim.h options.h token.h algollike.h +any_int.o: any_int.c any_int.h +c++lang.o: c++lang.c options.h token.h language.h algollike.h idf.h lex.h \ + lang.h clang.o: clang.c options.h token.h language.h algollike.h idf.h lex.h \ lang.h compare.o: compare.c sim.h text.h token.h tokenarray.h hash.h language.h \ options.h add_run.h compare.h debug.par count_sim_dup.o: count_sim_dup.c debug.o: debug.c debug.h -error.o: error.c sim.h error.h fname.o: fname.c fname.h -hash.o: hash.c system.par debug.par sim.h text.h Malloc.h error.h \ - any_int.h token.h language.h tokenarray.h options.h hash.h +hash.o: hash.c system.par debug.par sim.h text.h Malloc.h any_int.h \ + token.h language.h tokenarray.h options.h hash.h idf.o: idf.c system.par token.h idf.h javalang.o: javalang.c options.h token.h language.h algollike.h idf.h \ lex.h lang.h -lang.o: lang.c token.h lang.h +lang.o: lang.c token.h language.h algollike.h idf.h lex.h lang.h language.o: language.c token.h language.h lex.o: lex.c lex.h lisplang.o: lisplang.c token.h language.h algollike.h lex.h lang.h idf.h +m.o: m.c m2lang.o: m2lang.c options.h token.h language.h algollike.h idf.h lex.h \ lang.h miralang.o: miralang.c token.h language.h algollike.h lex.h lang.h idf.h -newargs.o: newargs.c sim.h ForEachFile.h fname.h Malloc.h error.h \ - newargs.h -options.o: options.c options.h +newargs.o: newargs.c sim.h ForEachFile.h fname.h Malloc.h newargs.h +options.o: options.c sim.h token.h language.h options.h pascallang.o: pascallang.c options.h token.h language.h algollike.h idf.h \ lex.h lang.h pass1.o: pass1.c debug.par sim.h text.h token.h tokenarray.h lang.h \ - error.h options.h pass1.h + options.h pass1.h pass2.o: pass2.c debug.par sim.h token.h text.h lang.h pass2.h \ sortlist.bdy -pass3.o: pass3.c system.par debug.par sim.h text.h token.h runs.h \ - aiso.spc Malloc.h error.h options.h pass3.h percentages.h -percentages.o: percentages.c sim.h text.h runs.h aiso.spc options.h \ - Malloc.h error.h percentages.h sortlist.bdy -runs.o: runs.c sim.h text.h runs.h aiso.spc debug.par aiso.bdy Malloc.h +pass3.o: pass3.c system.par settings.par debug.par sim.h text.h token.h \ + runs.h options.h pass3.h percentages.h +percentages.o: percentages.c debug.par sim.h text.h options.h Malloc.h \ + percentages.h sortlist.bdy +runs.o: runs.c sim.h text.h runs.h Malloc.h debug.par sortlist.bdy sim.o: sim.c system.par settings.par sim.h options.h newargs.h token.h \ - language.h error.h text.h runs.h aiso.spc hash.h compare.h pass1.h \ - pass2.h pass3.h percentages.h stream.h lang.h Malloc.h any_int.h + tokenarray.h language.h text.h runs.h hash.h compare.h pass1.h pass2.h \ + pass3.h percentages.h stream.h lang.h Malloc.h any_int.h stream.o: stream.c system.par sim.h options.h token.h lang.h stream.h t.o: t.c text.o: text.c debug.par sim.h token.h stream.h lang.h Malloc.h options.h \ - error.h text.h + text.h textlang.o: textlang.c sim.h token.h idf.h lex.h lang.h language.h token.o: token.c token.h -tokenarray.o: tokenarray.c error.h Malloc.h token.h lang.h tokenarray.h -any_int.o: any_int.c any_int.h +tokenarray.o: tokenarray.c sim.h Malloc.h token.h lang.h tokenarray.h +utf8test.o: utf8test.c diff --git a/judger/core/sim/sim_3_01/Malloc.c b/judger/core/sim/sim_3_01/Malloc.c new file mode 100644 index 00000000..50186473 --- /dev/null +++ b/judger/core/sim/sim_3_01/Malloc.c @@ -0,0 +1,417 @@ +/* This file is part of the checked memory manager MALLOC. + Written by Dick Grune, Vrije Universiteit, Amsterdam. + $Id: Malloc.c,v 1.24 2017-01-24 19:46:57 Gebruiker Exp $ +*/ + +#include +#include +#include +#include + +#include "any_int.h" +#include "Malloc.h" +/* make malloc.h available */ +#undef malloc +#undef calloc +#undef realloc +#undef free + + +/*Library module source prelude */ +#undef _MALLOC_CODE_ +#ifndef lint +#define _MALLOC_CODE_ +#endif +#ifdef LIB +#define _MALLOC_CODE_ +#endif + +#ifdef _MALLOC_CODE_ + +/* Library module source code */ + +#undef new +#define new use_my_new /* don't call Malloc in Malloc.c */ +#define my_new(type) ((type *)malloc(sizeof (type))) + +/* All output goes through designated files, so we block printf, etc. */ +#undef printf +#define printf use_fprintf +#undef putchar +#define putchar use_fprintf + +static size_t restricted_balance = 0; /* to simulate out-of-memory */ + +static void +fprintloc(FILE *out, const char *fname, int l_nmb) { + fprintf(out, "\"%s\", line %d: ", fname, l_nmb); +} + +void +_out_of_memory(const char *msg, const char *fname, int l_nmb, size_t size) { + fprintloc(stderr, fname, l_nmb); + fprintf(stderr, "OUT OF MEMORY"); + if (msg) { + fprintf(stderr, ": %s", msg); + } + if (size != 0) { + fprintf(stderr, ", requested size = %s bytes", + any_uint2string(size, 0)); + } + fprintf(stderr, "\n"); + fflush(stderr); + ReportMemoryStatus(stderr); + exit(1); +} + + + /* ADMINISTRATION */ +static vlong_uint total = 0; +static vlong_uint balance = 0; +static vlong_uint max = 0; + +struct alloc { /* corresponds to an allocated block */ + struct alloc *next; + const char *addr; + size_t size; + const char *fname; + int l_nmb; +}; + +#define HASH_SIZE 16381 /* largest prime under 2^16 */ +static struct alloc *alloc_bucket[HASH_SIZE]; +#define alloc_bucket_for(x) alloc_bucket[((unsigned int)(x)%HASH_SIZE)] + +static void +register_alloc(char *addr, size_t size, const char *fname, int l_nmb) { + /* registers the allocation of a block in the administration */ + struct alloc *new; + struct alloc **al_hook = &alloc_bucket_for(addr); + + if (addr == 0) return; + + new = my_new(struct alloc); + new->addr = addr; + new->size = size; + new->fname = fname; /* no need to copy fname */ + new->l_nmb = l_nmb; + new->next = *al_hook; + *al_hook = new; + + total += size; + balance += size; + if (balance > max) { + max = balance; + } +} + + +static struct alloc ** +pointer_to_alloc_for(const char *addr) { + struct alloc **al_hook = &alloc_bucket_for(addr); + + while (*al_hook) { + if ((*al_hook)->addr == addr) break; + al_hook = &(*al_hook)->next; + } + + return al_hook; +} + +static size_t +register_free(char *addr) { + /* registers the freeing of a block */ + struct alloc **old_p = pointer_to_alloc_for(addr); + struct alloc *old = *old_p; + + if (old == 0) return (size_t) -1; + size_t old_size = old->size; + + *old_p = old->next; + free((void *)old); + + balance -= old_size; + return old_size; +} + +void +MemClobber(void *p, size_t size) { + unsigned char *s = (unsigned char *)p; + size_t i; + + for (i = 0; i < size; i++) { + s[i] = 0125; /* 0101 0101 */ + } +} + + /* MEMORY STATUS */ +struct call { /* summarizes all the allocations at a call in the program */ + struct call *next; + const char *fname; + int l_nmb; + unsigned int n_blocks; + int var_size; /* all blocks have the same size or not */ + size_t size; /* !var_size: the one size; var_size: sum of sizes */ +}; + +static struct call * +compacted_calls(void) { + struct call *list_of_calls = 0; + int i; + + for (i = 0; i < HASH_SIZE; i++) { + struct alloc *al = alloc_bucket[i]; + + while (al) { + struct call *cl = list_of_calls; + + /* try to find a call entry for this program location */ + while (cl) { + if ( cl->fname == al->fname + && cl->l_nmb == al->l_nmb + ) break; + cl = cl->next; + } + + if (cl) { + /* this is known call; update */ + if (cl->var_size) { + cl->size += al->size; + } + else if (cl->size != al->size) { + /* switch to var_size */ + cl->var_size = 1; + cl->size = + cl->n_blocks*cl->size + al->size; + } + cl->n_blocks++; + } + else { /* this is a new call */ + cl = my_new(struct call); + cl->fname = al->fname; + cl->l_nmb = al->l_nmb; + cl->n_blocks = 1; + cl->var_size = 0; + cl->size = al->size; + + /* prepend to list_of_calls */ + cl->next = list_of_calls; + list_of_calls = cl; + } + + al = al->next; + } + } + + return list_of_calls; +} + +static int +number_of_calls(const struct call *cl) { + int res = 0; + + while (cl != 0) { + res++; + cl = cl->next; + } + + return res; +} + +static void +report_actual_call(FILE *out, const struct call *cl) { + fprintloc(out, cl->fname, cl->l_nmb); + fprintf(out, "still allocated: %d block%s of size ", + cl->n_blocks, (cl->n_blocks == 1 ? "" : "s") + ); + if (cl->var_size) { + /* cl->size is the sum of the sizes */ + size_t av = (cl->size+cl->n_blocks/2) / cl->n_blocks; + fprintf(out, "%s on average", any_uint2string(av, 0)); + if (cl->n_blocks > 1) { + fprintf(out, " = %s", any_uint2string(cl->size, 0)); + } + } + else { + /* cl->size is the single size */ + fprintf(out, "%s", any_uint2string(cl->size, 0)); + if (cl->n_blocks > 1) { + vlong_uint all = cl->size*cl->n_blocks; + fprintf(out, " = %s", any_uint2string(all, 0)); + } + } + fprintf(out, "\n"); +} + +static void +report_actual_calls(FILE *out) { + const struct call *cl = compacted_calls(); /* allocates cl */ + int n_calls = number_of_calls(cl); + + if (n_calls == 0) return; + + fprintf(out, "There %s %d call position%s with unreclaimed memory:\n", + (n_calls == 1 ? "is" : "are"), + n_calls, + (n_calls == 1 ? "" : "s") + ); + + while (cl) { + report_actual_call(out, cl); + struct call *next_cl = cl->next; + free((void *)cl); /* frees cl */ + cl = next_cl; + } +} + +void +ReportMemoryStatus(FILE *out) { + if (out == 0) out = stderr; + report_actual_calls(out); + + fprintf(out, "Total memory allocated = %s", any_uint2string(total, 0)); + fprintf(out, ", max. allocated = %s", any_uint2string(max, 0)); + fprintf(out, ", still allocated = %s", any_uint2string(balance, 0)); + fprintf(out, "\n"); + fflush(out); +} + + /* MALLOC */ +void * +_mreg_malloc(int chk, size_t size, const char *fname, int l_nmb) { + void *res; + + if (restricted_balance && balance + size > restricted_balance) { + res = 0; + } else { + res = malloc(size); + } + + if (res == 0) { + if (chk) { + _out_of_memory(0, fname, l_nmb, size); + /*NOTREACHED*/ + } + return res; + } + + register_alloc(res, size, fname, l_nmb); + +#ifdef MEMCLOBBER + MemClobber((char *)res, size); +#endif /* MEMCLOBBER */ + + return res; +} + +void * +_mreg_calloc(int chk, size_t n, size_t size, const char *fname, int l_nmb) { + void *res; + + if (restricted_balance && balance + n*size > restricted_balance) { + res = 0; + } else { + res = calloc(n, size); + } + + if (res == 0) { + if (chk) { + _out_of_memory(0, fname, l_nmb, n*size); + /*NOTREACHED*/ + } + return res; + } + + register_alloc(res, n*size, fname, l_nmb); + + return res; +} + +void * +_mreg_realloc(int chk, void *addr, size_t size, const char *fname, int l_nmb) { + void *res; + size_t old_size = register_free(addr); + + /* we report first, because the realloc() below may cause a crash */ + if ( /* we are not reallocating address 0, which is allowed */ + addr != 0 + && /* the address was never handed out before */ + old_size == (size_t) -1 + ) { + fprintloc(stderr, fname, l_nmb); + fprintf(stderr, ">>>> unallocated block reallocated <<<<\n"); + fflush(stderr); + } + + if (restricted_balance && balance + size > restricted_balance) { + res = 0; + } else { + res = realloc(addr, size); + } + + if (res == 0) { + if (chk) { + _out_of_memory(0, fname, l_nmb, size); + /*NOTREACHED*/ + } + return res; + } + + register_alloc(res, size, fname, l_nmb); + +#ifdef MEMCLOBBER + if (old_size > 0 && size > old_size) { + MemClobber(((char *)res)+old_size, size-old_size); + } +#endif /* MEMCLOBBER */ + + return res; +} + +/* ARGSUSED */ +void +_mreg_free(void *addr, const char *fname, int l_nmb) { + size_t old_size = register_free(addr); + + /* we report first, because the free() below may cause a crash */ + if (old_size == (size_t) -1) { + fprintloc(stderr, fname, l_nmb); + fprintf(stderr, ">>>> unallocated block freed "); + fprintf(stderr, "or multiple free of allocated block <<<<\n"); + fflush(stderr); + } + else { +#ifdef MEMCLOBBER + MemClobber((char *)addr, old_size); +#endif /* MEMCLOBBER */ + } + free(addr); +} + +char * +_new_string(int chk, const char *s, const char *fname, int l_nmb) { + return strcpy((char *)(_mreg_malloc(chk, strlen(s)+1, fname, l_nmb)), + s); +} + +/* End library module source code */ +#endif /* _MALLOC_CODE_ */ + +#ifdef lint +static void +satisfy_lint(void *x) { + void *v; + + v = _mreg_malloc(0, 0, 0, 0); + v = _mreg_calloc(0, 0, 0, 0, 0); + v = _mreg_realloc(0, 0, 0, 0, 0); + _mreg_free(x, 0, 0); + + OutOfMemoryExit(0); + ReportMemoryStatus(0); + MemClobber(v, 0); + + v = _new_string(0, 0, 0, 0); + satisfy_lint(v); +} +#endif /* lint */ diff --git a/judger/core/sim/sim_3_01/Malloc.h b/judger/core/sim/sim_3_01/Malloc.h new file mode 100644 index 00000000..5a34f7c3 --- /dev/null +++ b/judger/core/sim/sim_3_01/Malloc.h @@ -0,0 +1,120 @@ +/* This file is part of the checked memory manager MALLOC. + Written by Dick Grune, Vrije Universiteit, Amsterdam. + $Id: Malloc.h,v 1.14 2017-01-23 13:30:23 Gebruiker Exp $ +*/ + +#ifndef _MALLOC_H_ +#define _MALLOC_H_ + +/***** +The files Malloc.[ch] provide several functionalities: + +- checking for "out of memory": to simplify programming +- allocating memory using a routine new(type): " " " " +- clobbering freshly allocated memory: to obtain safer programs +- checking for freeing of unallocated blocks: " " " " +- reporting on memory usage: to obtain cleaner programs +- detecting memory leaks: " " " " + +The module defines several sets of routines: + +1. void *Malloc(size_t s) + void *Calloc(size_t n, size_t s) + void *Realloc(void *p, size_t s) + void Free(void *p) + + These routines act like checking versions of their Unix counterparts, + except that they never return NULL; upon out-of-memory an error message + is given on standard error, showing the file name and the line number + of the call. + Since in almost all cases there is nothing more intelligent to do, this + is almost always adequate, and makes for simpler and safer programming. + +2. void *TryMalloc(size_t s) + void *TryCalloc(size_t n, size_t s) + void *TryRealloc(void *p, size_t s) + void OutOfMemoryExit(const char *msg) + + In those rare cases that the program *can* continue when out of memory, the + Try... routines can be used; they act exactly like those in group 1, + except that they return NULL when out of memory. + A call of OutOfMemoryExit(msg) gives an out-of-memory error message, + displaying the message msg and some memory usage information, and + terminating the program. + +3. T *new(T) + T *try_new(T) + char *new_string(const char *s) + + A call of new(T), with T any type, yields a pointer of type T* to a block + of type T, allocated using Malloc(). A call of try_new(T) does the same + but returns NULL when out of memory. + A call of new_string(s), with s a string, yields a pointer to a copy of s, + allocated using Malloc(); it is equivalent to strdup() except that it uses + Malloc(). A call of try_new_string(s) does the same but returns NULL when + out of memory. + +4. void ReportMemoryStatus(FILE *f) + + Produces a compacted list of allocated but not yet freed blocks on the + stream f, with information about where they were allocated. + This is useful to get insight into memory use and abuse. + +5. void MemClobber(void *p, size_t size) + + When Malloc.c is compiled with -DMEMCLOBBER, it clobbers all newly allocated + memory from Malloc() and Realloc() just after allocation, and all freed + memory just before freeing it. An area is clobbered by overwriting it with + a wacky bit pattern. This is done in the hope that improper use of memory + will cause some evident error somewhere. + + The routine that performs the clobbering, MemClobber(void *p, size_t size), + is available regardless of the -DMEMCLOBBER compilation option. It can be + used to create comparison patterns. + +Notes: +* Compiled with any of the -DMEM... flags, Malloc will also produce run-time + error messages for multiple Free()s of the same block, and Realloc()s on + not-allocated blocks. It then allows the program to continue. + +* The system consumes hardly any time and is fast enough to be kept active + at all times. +*****/ + +/* Blocking malloc.h */ +#define malloc(s) you_are_using_the_Malloc_package_so_use_Malloc +#define calloc(n,s) you_are_using_the_Malloc_package_so_use_Calloc +#define realloc(p,s) you_are_using_the_Malloc_package_so_use_Realloc +#define free(p) you_are_using_the_Malloc_package_so_use_Free + + +/* Private entries */ +extern void *_mreg_malloc(int chk, size_t size, const char *fname, int l_nmb); +extern void *_mreg_calloc(int chk, size_t n, size_t size, const char *fname, int l_nmb); +extern void *_mreg_realloc(int chk, void *addr, size_t size, const char *fname, int l_nmb); +extern void _mreg_free(void *addr, const char *fname, int l_nmb); +extern void _out_of_memory( + const char *msg, const char *fname, int l_nmb, size_t size); + +extern char *_new_string(int chk, const char *s, const char *fname, int l_nmb); + +/* Public entries */ +#define Malloc(s) (_mreg_malloc(1, (s), __FILE__, __LINE__)) +#define Calloc(n,s) (_mreg_calloc(1, (n), (s), __FILE__, __LINE__)) +#define Realloc(p,s) (_mreg_realloc(1, (void *)(p), (s), __FILE__, __LINE__)) +#define Free(p) (_mreg_free((void *)(p), __FILE__, __LINE__)) + +#define TryMalloc(s) (_mreg_malloc(0, (s), __FILE__, __LINE__)) +#define TryCalloc(n,s) (_mreg_calloc(0, (n), (s), __FILE__, __LINE__)) +#define TryRealloc(p,s) (_mreg_realloc(0, (void *)(p), (s), __FILE__, __LINE__)) +#define OutOfMemoryExit(s) _out_of_memory((s), __FILE__, __LINE__, 0) + +#define new(type) ((type *)Malloc(sizeof (type))) +#define try_new(type) ((type *)TryMalloc(sizeof (type))) +#define new_string(s) (_new_string(1, (s), __FILE__, __LINE__)) +#define try_new_string(s)(_new_string(0, (s), __FILE__, __LINE__)) + +extern void ReportMemoryStatus(FILE *f); +extern void MemClobber(void *p, size_t size); + +#endif /* _MALLOC_H_ */ diff --git a/judger/core/sim/sim_2_77/README b/judger/core/sim/sim_3_01/README old mode 100755 new mode 100644 similarity index 57% rename from judger/core/sim/sim_2_77/README rename to judger/core/sim/sim_3_01/README index d233ec29..c062fe60 --- a/judger/core/sim/sim_2_77/README +++ b/judger/core/sim/sim_3_01/README @@ -1,29 +1,27 @@ # This file is part of the software similarity tester SIM. # Written by Dick Grune, Vrije Universiteit, Amsterdam. -# $Id: README,v 2.14 2014-01-26 13:51:27 Gebruiker Exp $ +# $Id: README,v 2.18 2017-03-19 09:42:55 dick Exp $ These programs test for similar or equal stretches in one or more program or text files and can be used to detect common code or plagiarism. See sim.pdf. -Checkers are available for C, Java, Pascal, Modula-2, Lisp, Miranda and +Checkers are available for C, C++, Java, Pascal, Modula-2, Lisp, Miranda and natural language text. ->>>> NEW, Jan 27, 2014: +>>>> NEW, March 2017: + - C++ testing added + +>>>> NEW, May 2016: + - better percentage computation + +>>>> NEW, Jan 2014: - 64-bit compatible - works also on 32-bit machines with software 64-bit emulator - ->>>> NEW, June 6, 2012: - - greatly improved percentage computation - - increased resolution, reducing false positives in sim_text - - // comments in C recognized - - characters 0200-0377 accepted in sim_text - - s p a c e d w o r d s recognized in sim_text - - UNICODE file names accepted - - manual page in PDF + - accepts | as new-old separator ==== To install on any system with gcc, flex, cp, ln, echo, rm, and wc, or their equivalents, for example UNIX/Linux or MSDOS+MinGW: -Unpack the archive sim_2_*.zip +Unpack the archive sim_3_*.zip To compile and test, edit the Makefile to fit the local situation, and call: @@ -37,16 +35,16 @@ and call make install -To change the default run size or the page width, adjust the file settings.par -and recompile. +To change defaults, adjust the file settings.par and recompile. ==== To install on MSDOS, if you don't have a C compiler, the archive -sim_exe_2_*.zip contains: +sim_exe_3_*.zip contains: - SIM_C.EXE similarity tester for C + SIM_C.EXE similarity tester for C + SIM_C++.EXE similarity tester for C++ SIM_JAVA.EXE similarity tester for Java SIM_PASC.EXE similarity tester for Pascal - SIM_M2.EXE similarity tester for Modula-2 + SIM_M2.EXE similarity tester for Modula-2 SIM_LISP.EXE similarity tester for Lisp SIM_MIRA.EXE similarity tester for Miranda SIM_TEXT.EXE similarity tester for text @@ -54,18 +52,11 @@ sim_exe_2_*.zip contains: ==== To extend: To add another language L, write a file Llang.l along the lines of clang.l -and the other *lang.l files, extend the Makefile and recompile. +or the other *lang.l files, extend the Makefile and recompile. All knowledge about a given language L is located in Llang.l; the rest of -the programs expect each token to be a 16-bit character. - -Available at present: - clang.l javalang.l pascallang.l m2lang.llisplang.l miralang.l textlang.l +the program expects each token to be a 16-bit character. Dick Grune - Vrije Universiteit - de Boelelaan 1081 - 1081 HV Amsterdam - the Netherlands email: dick@dickgrune.com http://www.dickgrune.com diff --git a/judger/core/sim/sim_3_01/Similarity_Percentage_Computation.tex b/judger/core/sim/sim_3_01/Similarity_Percentage_Computation.tex new file mode 100644 index 00000000..1e7b692a --- /dev/null +++ b/judger/core/sim/sim_3_01/Similarity_Percentage_Computation.tex @@ -0,0 +1,477 @@ +% This file is part of the software similarity tester SIM. +% Written by Dick Grune, dick@dickgrune.com +% $Id: Similarity_Percentage_Computation.tex,v 2.5 2016-05-27 08:04:29 dick Exp $ +% + +\batchmode + +\documentclass[a4paper,fleqn]{article} + +\newcommand{\mytitle}{Similarity Percentage Computation in SIM} +\newcommand{\myshorttitle}{SPC} + +\title{\mytitle} +\author{Dick Grune \\ +dick@dickgrune.com} +\date{May 18, 2016} + +\renewcommand{\sim}[0]{{\it sim}} +\newcommand{\Sim}[0]{{\it Sim}} + +\newcommand{\bd}[1]{\textbf{#1}} +\newcommand{\cw}[1]{\texttt{#1}} +\newcommand{\Bs}[0]{\ensuremath{\backslash}} +\newcommand{\OK}{\ding{52}} +\newcommand{\KO}{\ding{56}} + +\newcommand{\ignore}[1]{} + +\begin{document} + +\maketitle + +\section{Introduction} + +The similarity testing facility of {\sim} has been working satisfactorily +since its inception in 1986, but the computation of similarity percentages, +introduced in 2001, has been a continuous source of headache. + +There seem to be two reasons for this. The first is that there is no clear +definition of the notion ``similarity percentage''. +The second is that all +attempts to obtain similarity percentages have resulted in nonsensical results +(often percentages far exceeding 100\%), or have required quadratic time, or +sometimes both. Quadratic time requirements are unacceptable because they +make {\sim} unsuitable for large-scale text comparisons like +plagiarism detection, one of {\sim}'s largest application areas. + +\section{The Definition of ``Similarity Percentage''} + +Normally {\sim} supplies the information +\begin{quote} +Files $F_1$ and $F_2$ have matches +$(T_{1,1}, T_{1,2})$, $(T_{2,1}, T_{2,2}), ..., (T_{k,1}, T_{k,2})$ +\end{quote} +where the text segments $T$-s in the matches have the form $(F, p, l)$, +designating the text in file $F$, starting at position $p$ with length $l$, +if we view a file as an array of tokens. +The matches have the following properties (assuming a minimum run length of 1): +\begin{itemize} +\item +For any match $((F_1, p_1, l_1), (F_2, p_2, l_2))$ we have $l_1 = l_2$ and +$F_1[p_1..p_1+l_1] = F_2[p_2..p_2+l_2]$ (i.e. a match matches equal segments). +\item +For each token $F_1[a]$ for which there is a token $F_2[b]$ such that +$F_1[a]=F_2[b]$, there is a match $((F_1, p_1, l_1), (F_2, p_2, l_2))$ such +that $p_1 \leq a < p_1+l_1$ and $p_2 \leq b < p_2+l_2$ +(i.e. if two files have a token in common, it is present in a match). +\item +The segments $T_{1,1}$, $T_{2,1}, ..., T_{k,1}$ do not overlap. (This does not +apply to $T_{1,2}$, $T_{2,2}, ..., T_{k,2}$.) +\item +If there is a match $((F_1, p_1, l_1), (F_2, p_2, l_2))$ there are no matches +$((F_1, p_1 + l_1, ...), (F_2, ..., ...))$ or +$((F_1, p_1-l, l), (F_2, ..., ...))$ (i.e. no match could be extended on either +end, i.e. each match is maximal in length). +\end{itemize} +This information is well-defined and unambiguous. +It is produced by {\sim} in almost linear time. + +Unfortunately this information does not reasonably extend to something like +\begin{quote} +Files $F_1$ and $F_2$ have $N$\% material in common. +\end{quote} +One is tempted to conclude that $F_1$ and $F_2$ have material of length +$l_1 + l_2$ +... + $l_k$ in common, but $l_1 + l_2$ +... + $l_k$ can easily be +larger than $F_1$ or $F_2$, resulting in similarities of over 100\%. +This can, f.e., happen when $F_1=BB$ and $F_2=B$, where $B$ is a block of text +with length $l_B$. +Then the matches found between the two files are +$((F_1, 0, l_B), (F_2, 0, l_B))$ and $((F_1, l_B, l_B), (F_2, 0, l_B))$. +So the two files have a common length of $l_B+l_B = 2l_B$, which gives $F_2$ +(with length $l_B$) a similarity percentage of 200\%. + +A more fundamental approach to similarity is needed. +The fullest and clearest representation of what an $N$-token file $F_1$ and an +$M$-token file $F_2$ have in common is an $N{\times}M$ Boolean correlation +matrix $C$ with $C[n,m]=True$ if $F_1[n]=F_2[m]$ and $C[n,m]=False$ elsewhere. + +Suppose $F_1$=\cw{"a b c d e f g h i j"} (length = 10) and +$F_2$=\cw{"f g h v w x y z a b c d e"} (length = 13). +Then the correlation matrix $C$ is + +\newlength{\pluswidth} +\settowidth{\pluswidth}{$~+$} +\begin{tabular}{lc*{13}{p{\pluswidth}@{}}} + & & & & & & & \multicolumn{2}{c}{$F_2$} \\ + & &f&g&h&v&w&x&y&z&a&b&c&d&e\\ + &a& & & & & & & & &+& & & & \\ + &b& & & & & & & & & &+& & & \\ + &c& & & & & & & & & & &+& & \\ + &d& & & & & & & & & & & &+& \\ +$F_1$ &e& & & & & & & & & & & & &+\\ + &f&+& & & & & & & & & & & & \\ + &g& &+& & & & & & & & & & & \\ + &h& & &+& & & & & & & & & & \\ + &i& & & & & & & & & & & & & \\ + &j& & & & & & & & & & & & & \\ +\end{tabular} + +If we project the pluses onto the top and left axes, we get an indication of +how much material $F_1$ can be found in $F_2$ and vice versa: + +\begin{tabular}{lcc*{13}{p{\pluswidth}@{}}} + & & & & & & & & \multicolumn{2}{c}{$F_2$} \\ + & & &f&g&h&v&w&x&y&z&a&b&c&d&e\\ + & & &*&*&*& & & & & &*&*&*&*&*\\ + &a&*& & & & & & & & &+& & & & \\ + &b&*& & & & & & & & & &+& & & \\ + &c&*& & & & & & & & & & &+& & \\ + &d&*& & & & & & & & & & & &+& \\ +$F_1$ &e&*& & & & & & & & & & & & &+\\ + &f&*&+& & & & & & & & & & & & \\ + &g&*& &+& & & & & & & & & & & \\ + &h&*& & &+& & & & & & & & & & \\ + &i& & & & & & & & & & & & & & \\ + &j& & & & & & & & & & & & & & \\ +\end{tabular} + +\noindent +From this representation we see that +\begin{quote} +$F_1$ consists for 8/10 = 80.0\% of $F_2$ material \\ +$F_2$ consists for 8/13 = 61.5\% of $F_1$ material \\ +\end{quote} +It is this information that {\sim} tries -- and frequently fails -- to +provide. + +\section{The Comparison Machine} + +To see how this information can be obtained by {\sim} +or why it cannot, we have to have a closer look at {\sim}'s comparison machine. + +{\Sim} cannot use the $N{\times}M$ matrix. Its size is quadratic in the +number of tokens in the combined files to be compared, which would restrict +the total number of tokens to 100.000 at the utmost. Instead it uses a linear +array of tokens, with some additional data, as follows. + +\subsection{The Algorithm} + +The comparison machine (the routine \cw{lcs()} in \cw{compare.c}) uses two +indexes into $T$: \cw{i0} and \cw{i1}. +The index \cw{i0} steps through the array, and for each position the +index \cw{i1} is used to hunt for the match +$((F_1, i_0, l), (F_2, i_1, l))$ with largest $l$ and $i_0 < i_1$. + +The skeleton algorithm is + +\small% +\begin{verbatim} + i0 := 0; + WHILE i0 < end_of_text + i1 := 0; + WHILE i1 < end_of_text + IF T[i0] = T[i1] + find longest match starting from(i0, i1) + IF longer than previous longest match starting from(i0) + store as longest match starting from(i0) + i1 := i1 + 1 + IF there is a longest match starting from(i0) + i0 := i0 + length of longest match starting from(i0) + ELSE + i0 := i0 + 1 +\end{verbatim}% +\normalsize% +\noindent +In short, the inner loop finds long matches; the outer loop finds the +longest of these long matches. + +Suppose we have two files $F_1 = $\cw{"abcdefabc"} and +$F_2 = $\cw{"fabcdef"}; the algorithm then identifies the matches +\begin{quote} +$((F_1,0,6), (F_2,1,6))$ (matching \cw{"abcdef"}), \\ +$((F_1,6,3), (F_2,1,3))$ (matching \cw{"abc"}). +\end{quote} +If the files had been offered in the reverse order, the matches would have +been +\begin{quote} +$((F_2,0,4), (F_1,5,4))$ (matching \cw{"fabc"}), \\ +$((F_2,4,3), (F_1,3,3))$ (matching \cw{"def"}), +\end{quote} +which shows that the results of the comparison algorithm are sensitive to the +order in which the files are presented. + +\subsection{Details of the Increments} + +Even after finding a match in the inner loop, \cw{i1} should only be +incremented by 1, since right after a good match a better match may be found. +Suppose $F_1$=\cw{"aaabcd"} and $F_2$=\cw{"aaaabcd"}. +With \cw{i0=0} and \cw{i1=7} (just at the beginning of $F_2$) we find the +match +\begin{quote} +$((F_1,0,3), (F_2,0,3))$ (matching \cw{"aaa"}), +\end{quote} +but with \cw{i1=8} we find +\begin{quote} +$((F_1,0,6), (F_2,1,6))$ (matching \cw{"aaabcd"}), +\end{quote} +which is a better match starting at \cw{i0=0}. + +When a longest match is found in the outer loop, \cw{i0} must be increased by +the length of that match, to avoid repetitive matches. +Suppose we have one file $F$=\cw{"aaaaaaaa"}. +Then the first match will be +\begin{quote} +$((F,0,4), (F,4,4))$ (matching \cw{"aaaa"}). +\end{quote} +When we increase \cw{i0} in steps of 1, the rest of the matches will be +\begin{quote} +$((F,1,3), (F,4,3))$ (matching \cw{"aaa"}), \\ +$((F,2,3), (F,5,3))$ (matching \cw{"aaa"}), \\ +$((F,3,2), (F,5,2))$ (matching \cw{"aa"}), \\ +$((F,4,2), (F,6,2))$ (matching \cw{"aa"}), \\ +$((F,5,1), (F,6,1))$ (matching \cw{"a"}), \\ +$((F,6,1), (F,7,1))$ (matching \cw{"a"}), +\end{quote} +for a total of $O(N)$ matches, many of them repeating +earlier information. + +If, however, we increase \cw{i0} by the length of the match found, the rest of +the matches are +\begin{quote} +$((F,4,2), (F,6,2))$ (matching \cw{"aa"}), \\ +$((F,6,1), (F,7,1))$ (matching \cw{"a"}), +\end{quote} +for a total of $O(\log N)$ matches, all informative. + +The actual algorithm has many other features: establishing a minimum match +length, options for avoiding to compare a file to itself, etc. +There is one important optimization, concerned with incrementing \cw{i1}. +Incrementing \cw{i1} by 1 makes the algorithm quadratic in the number of +tokens, which is unacceptable. +We have seen, however, that sometimes increasing by 1 is necessary. +The problem is heuristically solved by having +an array \cw{Forward\_Reference[]}, which for each position in the token array +gives the index of the nearest larger position in the token array where +matching text of at least the minimum required length can be found. +This array is constructed in linear time by a prescan, +using hashing extensively. +Rather than incrementing \cw{i1} by 1 when looking for the next match, \cw{i1} +is set to \cw{Forward\_Reference[i1]}. + +In principle using this forward references array does not take away the +quadratic component, but it multiplies it by $\phi$, the density of the +similarities. +And since we usually have $\phi \ll 1$, this optimization makes {\sim} +usable. +The linear component of course remains. + +\section{Problems and their Causes} + +The arrangement described above is not directly suitable for percentage +computation, for three reasons. + +\begin{enumerate} +\item +The contents of $F_k$ are explained in terms of matches with files +$F_{k+1}, ..., F_n$; matches from $F_1, ..., F_{k-1}$ are not noticed. +\item +Not all matches in $F_{k+1}, ..., F_n$ are noticed. +\item +Only a single match for a block at a given position in $F_k$ is reported; +other lesser matches or equal matches further on are not noticed. +\end{enumerate} +Each of these problems will now be considered in turn. + +\subsection{Ignoring Earlier Files} + +Earlier files are ignored because the \cw{Forward\_Reference} array is exactly +that, it references forward. Normally this is not a problem, since any +similarities between $F_k$ and an earlier $F_p$ (with +$ 1 \leq p \leq {k-1}$) will be have been noted when $F_p$ was analyzed. + +One may be tempted to try to deduce the contribution of a file $F_p$ +($ 1 \leq p \leq {k-1}$) to $F_k$ from matches of the form +$((F_p,,),(F_k,,))$, +but that is not possible. +Suppose $F_p=BaBBc$ and $F_k=aBc$, where $B$ is a block of text of size $l_B$. +The algorithm provides us with the matches +\begin{quote} +$((F_p,0,l_B),(F_k,1,l_B))$ (matching $B$),\\ +$((F_p,l_B,1+l_B),(F_k,0,1+l_B))$ (matching $aB$),\\ +$((F_p,l_B+1+l_B,l_B+1),(F_k,1,l_B+1))$ (matching $Bc$) +\end{quote} +Note that in none of the matches the text in $F_p$ overlaps. + +These matches are perfect for determining the $N$ in the statement +``$F_p$ consists for $N$\% of $F_k$ material'': +$N = (l_B+1+l_B+l_B+1) / (l_B+1+l_B+l_B+1) = (3l_B+2) / (3l_B+2) = 100\%$. +But if we rely on these matches to compute the $N$ in the statement +``$F_k$ consists for $N$\% of $F_p$ material'', we arrive at the conclusion +that $N = (l_B+1+l_B+l_B+1) / (l_B+2) = (3l_B+2) / (l_B+2) \approx 300\%$. +It is clear that this is caused by the overlap of the matches in $F_k$, but +this example makes it equally clear that it would be very difficult to +disentangle such overlaps in the general case. + +\subsection{Selectively Ignoring Later Files} + +When there are a number of files, say four, each containing somewhere an +identical block of text $B$, say $F_1=abBcd,F_2=efgB,F_3=Bhi,F_4=jklBmno$ +(where $a..o$ are letters not occurring in $B$) +{\sim} produces the following three matches +\begin{quote} +$((F_1,2,l_B),(F_2,3,l_B))$, \\ +$((F_2,3,l_B),(F_3,0,l_B))$, \\ +$((F_3,0,l_B),(F_4,3,l_B))$ +\end{quote} +producing a linear number of matches, which is very desirable for most +applications. +But it means that the matches +\begin{quote} +$((F_1,2,l_B),(F_3,0,l_B))$, \\ +$((F_1,2,l_B),(F_4,3,l_B))$, \\ +$((F_2,3,l_B),(F_4,3,l_B))$ +\end{quote} +are missed. +So percentages between $F_1$ and $F_2$, $F_2$ and $F_3$, and $F_3$ and $F_4$ +could possibly be derived from these matches, but those between +$F_1$ and $F_2$, $F_1$ and $F_4$, and $F_2$ and $F_4$ cannot. + +As we have noted before, the output of {\sim} is sensitive to the order in +which the files are presented. + +\subsection{Ignoring Lesser Matches} + +Given the three files $F_1=abBcd,F_2=efgB,F_3=bBhi$, +{\sim} produces the following two matches +\begin{quote} +$((F_1,1,l_B+1),(F_3,0,l_B+1))$, (matching $bB$) \\ +$((F_2,3,l_B),(F_3,1,l_B))$, (matching $B$) +\end{quote} +but the lesser match $((F_1,2,l_B),(F_2,3,l_B))$, relating $F_1$ to $F_2$, is +missed. +This is acceptable in similarity testing since the $B$ in $F_2$ is caught by +$((F_2,3,l_B),(F_3,1,l_B))$, but for similarity percentage computation we need +all matches. + +\section{Solutions} + +\subsection{Accessing Earlier Files} + +There are at least two ways to obtain both matches of the form +$((F_p,,),(F_q,,))$ \emph{and} of the form $((F_q,,),(F_p,,))$ with $p < q$: +modifying the order in which the files are processed, and modifying the +forward reference system. + +\subsubsection{Modifying the File Order} + +Running the entire program again with the order of the files reversed will +provide the missing $((F_q,,),(F_p,,))$, at the expense of doubling the +running time. + +\subsubsection{Modifying the Forward Referencing System} + +Each forward reference chain is particular to a specific string $S$ of text, +with $|S|$ the minimum required match length. +The chain starts from the first occurrence of $S$ in the text array, then +leads to one or more subsequent occurrences of $S$, and ends in a NULL pointer +at the last occurrence of $S$ in the text array. +When at a position in $F_p$ we start using the forward reference chain for say +$S$, we can reach only positions in $F_q$ with $q > p$ (not $ q \ge p$, +since when computing percentages a file is not compared to itself). + +Now suppose the chain, rather than terminating with a NULL pointer at the last +occurrence of $S$, looped back to its beginning. +Then when working on $F_p$ we do not stop at the last occurrence of $S$ in the +text array while hunting for $S$ +but continue at the first occurrence of $S$ in the text array, from where we +may access files $F_q$ with $ q < p $. +This statistically doubles the length of the chain, doubling the work of the +comparison machine; but the effort in the preparation of the text array is not +doubled, as it would be if the program were run twice. + +A circular list is an awkward data structure and requires careful programming. +During construction of a forward reference chain it can easily be made to loop, +by remembering where it started and then rather than terminating it with a NULL +pointer end it with a pointer to the starting point. +When using the chain, following it must stop when we reach the position from +which we started (which is certainly on the chain). + +So the problem of how to access earlier files can be solved at the expense of +roughly doubling the run time. + +\subsection{Full Coverage of Later Files} + +The problem is caused by the original algorithm hunting for the largest match +in the rest of the files, whereas for percentage computation it should look +for any match in each of the other files separately. + +The possibility of comparing each file with each other file separately has +already been provided by the \bd{-e} option. +Again this results in a quadratic time requirement, and again we invoke the +low density of actual matches to reduce the weight of the problem. + +The original algorithm produces the matches in a left-to-right largest match +order, to minimize the number of matches; for the percentage computation we +just want them all. +Since the nature and number of matches depends on the order in which they +are identified, one might wonder if the left-to-right largest match order may +cause problems to percentage computation. +Suppose $F_p$=\cw{"abcdxe"} and $F_q$=\cw{"abcdxxe"}, with a required +minimum run length of 2. +The matches found are +\begin{verbatim} + abcdxe abcdxxe + abcdx abcdx + e e +\end{verbatim} +with the result that $F_q$ consists for $5/7 = 71.4\%$ out of $F_p$ material. +The match \cw{e} is ignored because it does not have the required minimum +length. +If the files were compared in the reverse order the following matches would be +obtained +\begin{verbatim} + abcdxxe abcdxe + abcdx abcdx + xe xe +\end{verbatim} +and $F_q$ would consist for $(5+2)/7 = 100\%$ of $F_p$ material + +Considerations: +\begin{itemize} +\item +The example is contrived and hinges on there being a minimum required length +and on multiply overlapping patterns. +No examples seem to exist without these ingredients. +\item +Multiply overlapping patterns do occur in practice, f.e. in lists of +identifiers or numbers, but these are usually not very informative and of +little interest. +\item +The algorithm for finding the maximum similarity percentage may conceivably +require exhaustive search and be exponential. +\end{itemize} +It seems reasonable to ignore this problem for the moment, and use the normal +{\sim} matching algorithm in comparing one file to one file\footnote{% +The problem did show up in test runs, manifesting itself by minor differences +in the percentages depending on the order of the input files, but went away +when the run length was set to 1.}. + +\subsection{Lesser Matches} + +Since lesser matches can only occur when three or more files are involved, +using the \cw{-e} option solves this problem too, since it restricts all +comparisons to two files only. + +\section{Conclusion} + +Using circular forward reference chains and the \cw{-e}-option, correct +similarity percentages can be obtained; the algorithm has a moderate quadratic +component though. + +A compromise can be obtained by omitting the \cw{-e} option, which is the +greatest source of quadratic behaviour, and use circular forward reference +chains only. This makes the algorithm almost linear again, but will +underreport percentages. + +\end{document} diff --git a/judger/core/sim/sim_2_77/TechnReport b/judger/core/sim/sim_3_01/TechnReport old mode 100755 new mode 100644 similarity index 100% rename from judger/core/sim/sim_2_77/TechnReport rename to judger/core/sim/sim_3_01/TechnReport diff --git a/judger/core/sim/sim_3_01/ToDo b/judger/core/sim/sim_3_01/ToDo new file mode 100644 index 00000000..05760029 --- /dev/null +++ b/judger/core/sim/sim_3_01/ToDo @@ -0,0 +1,83 @@ +- tx_pos is a pig. struct texts are in principle immutable objects, except that + lists of positions are attached to it. These lists (and that is the root of + the problem )are accessed from two points, one in pass2 to fill in NL + positions and in pass3 to report them. This makes it impossible to write + const struct text in most places. Maybe there should be a superstruct + struct super_text { + const struct *st_text; + struct position *st_pos; + } + Not elegant either. + +- some size_t are sizes, others are positions, indexes + +- start,limit -> start,length + +- Bool.h + +- report runs as '... ...' (proper name for Retrieve_Runs()) + +- unify idf2token() in *lang.l + +- get rid of static forward references to routines; occurrences: + egr static *.c | grep "(" + 1 compare.c + 7 hash.c + 2 pass1.c + 4 pass2.c + 12 pass3.c + 1 stream.c + 3 text.c + +- lex_nl_cnt counts from 1; this requires small, complicating adjustments + +Done ================================================================ + ++ command line parameter consistency + ++ make sim_text case-indifferent? + ++ sortlist.bdy by split-merge + ++ get rid of the nl_buff mechanism. No, use 16 bits line length. + ++ in hash.c, size_t -> uint64_t? No, unit32_t is just as good. + ++ / misinterpreted by shell; | alternative + ++ register - removed + ++ Run hashing OK: average chain length = 1.5, for sim-ing the sources of MCD2 ++ Idf hashing OK: smooth distribution when sim-ing the sources of MCD2 + ++ use two-byte tokens to obtain better resolution for sim_text and on -F option + and UTF-8 (Johnson, Benjamin (US - Chicago)) + ++ different defaults per program + ++ cleaning up sim.c & names + ++ Microsoft comment (// ... unescaped \n) + ++ emails 2009-2011 (A = I answered, R= they replied) ++AR Marcus Brinkmann, separate letters ++AR Scott Kuhl, percentages ++AR Yaroslav Halchenko, identifying non-existent lines ++A Rumen Stefanov, UTF-8 ++A Jonathan Martin, UTF-8 ++AR UTF-8 (Johnson, Benjamin (US - Chicago)) + ++ better structure between X.h and X.c + ++ clean-up language.h and its sub-class algollike.h + ++ warning in README to correct for non-MSDOS + +Rejected ================================================================ + +X remove Miranda +X Mon Apr 11 13:23:41 1994: sim_orca +X Thu May 13 23:02:46 1993: sim ook voor C++ en Ada + +X db_ not protected by #ifdef but by compilation to a call to an (empty) routine + 1. not conspicuous enough in the code; 2. impairs efficiency diff --git a/judger/core/sim/sim_3_01/VERSION b/judger/core/sim/sim_3_01/VERSION new file mode 100644 index 00000000..9f55b2cc --- /dev/null +++ b/judger/core/sim/sim_3_01/VERSION @@ -0,0 +1 @@ +3.0 diff --git a/judger/core/sim/sim_3_01/add_run.c b/judger/core/sim/sim_3_01/add_run.c new file mode 100644 index 00000000..cfe6265e --- /dev/null +++ b/judger/core/sim/sim_3_01/add_run.c @@ -0,0 +1,25 @@ +/* This file is part of the software similarity tester SIM. + Written by Dick Grune, Vrije Universiteit, Amsterdam. + $Id: add_run.c,v 2.18 2016-06-12 13:00:04 dick Exp $ +*/ + +#include "sim.h" +#include "text.h" +#include "runs.h" +#include "percentages.h" +#include "options.h" +#include "add_run.h" + +/* Sends the run info to add_to_percentages or to add_to_runs. */ +void +add_run(struct text *txt0, size_t i0, + struct text *txt1, size_t i1, + size_t size +) { + if (is_set_option('p')) { + add_to_percentages(txt0, txt1, size); + } + else { + add_to_runs(txt0, i0, txt1, i1, size); + } +} diff --git a/judger/core/sim/sim_2_77/add_run.h b/judger/core/sim/sim_3_01/add_run.h old mode 100755 new mode 100644 similarity index 79% rename from judger/core/sim/sim_2_77/add_run.h rename to judger/core/sim/sim_3_01/add_run.h index 75e1d250..681785fe --- a/judger/core/sim/sim_2_77/add_run.h +++ b/judger/core/sim/sim_3_01/add_run.h @@ -1,6 +1,6 @@ /* This file is part of the software similarity tester SIM. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: add_run.h,v 1.4 2013-04-28 16:30:39 Gebruiker Exp $ + $Id: add_run.h,v 1.5 2016-04-10 09:11:11 dick Exp $ */ /* Interface between front-end and back-end: all information about @@ -8,6 +8,9 @@ each identified by their struct text and the position of the common segment in Token_Array[], and the number of tokens in the common segment. + + The routine add_run() constructs a run with the given properties and + adds it to 'runs.[ch]' or 'percentages.[ch]'. */ extern void add_run( diff --git a/judger/core/sim/sim_2_77/algollike.c b/judger/core/sim/sim_3_01/algollike.c old mode 100755 new mode 100644 similarity index 97% rename from judger/core/sim/sim_2_77/algollike.c rename to judger/core/sim/sim_3_01/algollike.c index 6cfcb586..8aaf8cd5 --- a/judger/core/sim/sim_2_77/algollike.c +++ b/judger/core/sim/sim_3_01/algollike.c @@ -1,10 +1,10 @@ /* This file is part of the software similarity tester SIM. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: algollike.c,v 2.10 2013-04-28 16:30:40 Gebruiker Exp $ + $Id: algollike.c,v 2.11 2016-05-13 19:00:51 dick Exp $ */ +#include "sim.h" #include "options.h" -#include "error.h" #include "token.h" #include "algollike.h" diff --git a/judger/core/sim/sim_2_77/algollike.h b/judger/core/sim/sim_3_01/algollike.h old mode 100755 new mode 100644 similarity index 95% rename from judger/core/sim/sim_2_77/algollike.h rename to judger/core/sim/sim_3_01/algollike.h index 28b855b3..d3ceb6e2 --- a/judger/core/sim/sim_2_77/algollike.h +++ b/judger/core/sim/sim_3_01/algollike.h @@ -1,6 +1,6 @@ /* This file is part of the software similarity tester SIM. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: algollike.h,v 1.7 2013-04-28 16:30:40 Gebruiker Exp $ + $Id: algollike.h,v 1.7 2013-04-28 16:30:40 dick Exp $ */ /* The class Algollike is a subclass of Language. It implements diff --git a/judger/core/sim/sim_2_77/any_int.c b/judger/core/sim/sim_3_01/any_int.c old mode 100755 new mode 100644 similarity index 88% rename from judger/core/sim/sim_2_77/any_int.c rename to judger/core/sim/sim_3_01/any_int.c index de59e69b..b4d0c7b3 --- a/judger/core/sim/sim_2_77/any_int.c +++ b/judger/core/sim/sim_3_01/any_int.c @@ -1,6 +1,6 @@ /* This file is part of the module ANY_INT. - Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: any_int.c,v 1.2 2014-01-27 20:13:40 Gebruiker Exp $ + Written by Dick Grune, dick@dickgrune.com + $Id: any_int.c,v 1.4 2017-01-22 14:50:00 Gebruiker Exp $ */ #include "any_int.h" @@ -40,16 +40,19 @@ int2string(vlong_uint val, int neg, int size) { if (size < 0 || size > MAX_ANY_UINT_DIGITS) size = 0; do { /* one decimal character, the first always */ - *--res = "0123456789ABCDEF"[val % 10], size--; + *--res = "0123456789ABCDEF"[val % 10]; + size--; val = val / 10; } while (val > 0); if (neg) { - *--res = '-', size--; + *--res = '-'; + size--; } while (size > 0) { /* fill up to size */ - *--res = ' ', size--; + *--res = ' '; + size--; } return res; diff --git a/judger/core/sim/sim_2_77/any_int.h b/judger/core/sim/sim_3_01/any_int.h old mode 100755 new mode 100644 similarity index 72% rename from judger/core/sim/sim_2_77/any_int.h rename to judger/core/sim/sim_3_01/any_int.h index db1d4d88..e84f99a8 --- a/judger/core/sim/sim_2_77/any_int.h +++ b/judger/core/sim/sim_3_01/any_int.h @@ -1,10 +1,10 @@ /* This file is part of the module ANY_INT. - Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: any_int.h,v 1.1 2014-01-27 11:22:40 Gebruiker Exp $ + Written by Dick Grune, dick@dickgrune.com + $Id: any_int.h,v 1.4 2017-01-22 14:50:00 Gebruiker Exp $ */ -#ifndef _ANY_UINT_H_ -#define _ANY_UINT_H_ +#ifndef _ANY_INT_H_ +#define _ANY_INT_H_ /* Printing size_t and very long ints. @@ -15,9 +15,10 @@ but this is not portable since not all compilers know it. These problems are solved by introducing the type vlong_[u]int (see below), - defined as the largest [unsigned] int type on the system, and routines to - convert these to string. The resulting string is transient, but up to - N_INDEPENDENT_CALLS calls can be used simultaneously. + defined as the largest [unsigned] machine int type on the system, + and routines to convert these to string. + The resulting string is transient, but up to N_INDEPENDENT_CALLS calls + can be used simultaneously. Since the value is passed to the conversion routines as a typed parameter the C compiler does the conversion (actually widening) for you. @@ -31,4 +32,4 @@ typedef unsigned long long int vlong_uint; /* largest uint in the system */ extern const char *any_int2string(vlong_int val, int size); extern const char *any_uint2string(vlong_uint val, int size); -#endif /* _ANY_UINT_H_ */ +#endif /* _ANY_INT_H_ */ diff --git a/judger/core/sim/sim_3_01/c++lang.l b/judger/core/sim/sim_3_01/c++lang.l new file mode 100644 index 00000000..fef0f864 --- /dev/null +++ b/judger/core/sim/sim_3_01/c++lang.l @@ -0,0 +1,370 @@ +%{ +/* This file is part of the software similarity tester SIM. + Written by Dick Grune, Vrije Universiteit, Amsterdam. + $Id: c++lang.l,v 2.2 2017-03-19 09:23:19 dick Exp $ +*/ + +/* + C++ language front end for the similarity tester. + Based on C language front end written by Dick Grune + Author: Dick Grune + Modified by: Evin Murphy, UCD Dublin, Ireland +*/ + +#include "options.h" +#include "token.h" +#include "language.h" +#include "algollike.h" +#include "idf.h" +#include "lex.h" +#include "lang.h" + +/* General language front end data */ +Token lex_token; +size_t lex_nl_cnt; +size_t lex_tk_cnt; +size_t lex_non_ascii_cnt; + +/* Language-dependent data */ + +/* Data for module idf */ + +static const struct idf ppcmd[] = { + {"define", META('d')}, + {"elif", META('e')}, + {"else", META('E')}, + {"endif", META('n')}, + {"error", META('r')}, + {"if", META('i')}, + {"ifdef", META('I')}, + {"ifndef", META('x')}, + {"include", MTCT('I')}, + {"line", META('l')}, + {"pragma", META('p')}, + {"undef", META('u')} +}; + +static const struct idf reserved[] = { + {"and", NORM('a')}, + {"and_eq", NORM('A')}, + {"asm", CTRL('A')}, + {"auto", META('a')}, + {"bitand", NORM('b')}, + {"bitor", NORM('B')}, + {"bool", CTRL('B')}, + {"break", META('b')}, + {"case", NORM('c')}, + {"char", NORM('C')}, + {"class", CTRL('C')}, + {"const", META('c')}, + {"const_cast", META('C')}, + {"continue", MTCT('C')}, + {"default", NORM('d')}, + {"delete", NORM('D')}, + {"do", CTRL('D')}, + {"double", META('D')}, + {"dynamic_cast", MTCT('D')}, + {"else", NORM('e')}, + {"enum", NORM('E')}, + {"explicit",CTRL('E')}, + {"extern", MTCT('E')}, + {"false", NORM('f')}, + {"float", NORM('F')}, + {"for", CTRL('F')}, + {"friend", META('f')}, + {"goto", NORM('g')}, + {"if", NORM('i')}, + {"inline", NORM('I')}, + {"int", CTRL('I')}, + {"long", NORM('l')}, + {"mutable", NORM('m')}, + {"namespace", NORM('n')}, + {"new", NORM('N')}, + {"not", CTRL('N')}, + {"not_eq", META('N')}, + {"operator", NORM('o')}, + {"or", NORM('O')}, + {"or_eq", CTRL('O')}, + {"private", NORM('p')}, + {"protected", NORM('P')}, + {"public", CTRL('P')}, + {"register", No_Token}, + {"reinterpret_cast", NORM('r')}, + {"return", NORM('R')}, + {"short", NORM('s')}, + {"signed", NORM('S')}, + {"sizeof", CTRL('S')}, + {"static", META('s')}, + {"static_cast", META('S')}, + {"struct", MTCT('S')}, + {"switch", META('w')}, + {"template", NORM('t')}, + {"this", NORM('T')}, + {"throw", CTRL('T')}, + {"true", META('t')}, + {"try", META('T')}, + {"typedef", MTCT('T')}, + {"typeid", NORM('y')}, + {"typename", NORM('z')}, + {"union", NORM('u')}, + {"unsigned", NORM('U')}, + {"using", CTRL('U')}, + {"virtual", NORM('v')}, + {"void", NORM('V')}, + {"while", NORM('w')}, + {"xor", NORM('x')}, + {"xor_eq", NORM('X')} +}; + +/* Special treatment of identifiers */ + +static Token +idf2token(int hashing) { + Token tk; + + tk = idf_in_list(yytext, reserved, sizeof reserved, IDF); + if (Token_EQ(tk, IDF) && hashing) { + /* return a one-Token hash code */ + tk = idf_hashed(yytext); + } + return tk; +} + +/* Token sets for module algollike */ +static const Token Non_Finals[] = { + IDF, /* identifier */ + NORM('{'), + NORM('('), + NORM('a'), /* and */ + NORM('A'), /* and_eq */ + CTRL('A'), /* asm */ + META('a'), /* auto */ + NORM('b'), /* bitand */ + NORM('B'), /* bitor */ + CTRL('B'), /* bool */ + META('b'), /* break */ + NORM('c'), /* case */ + NORM('C'), /* char */ + CTRL('C'), /* class */ + META('c'), /* const */ + META('C'), /* const_cast */ + MTCT('C'), /* continue */ + NORM('d'), /* default */ + NORM('D'), /* delete */ + CTRL('D'), /* do */ + META('D'), /* double */ + MTCT('D'), /* dynamic_cast */ + NORM('e'), /* else */ + NORM('E'), /* enum */ + CTRL('E'), /* explicit */ + MTCT('E'), /* extern */ + NORM('F'), /* float */ + CTRL('F'), /* for */ + META('f'), /* friend */ + NORM('g'), /* goto */ + NORM('i'), /* if */ + NORM('I'), /* inline */ + CTRL('I'), /* int */ + NORM('l'), /* long */ + NORM('m'), /* mutable */ + NORM('n'), /* namespace */ + NORM('N'), /* new */ + CTRL('N'), /* not */ + META('N'), /* not_eq */ + NORM('o'), /* operator */ + NORM('O'), /* or */ + CTRL('O'), /* or_eq */ + NORM('p'), /* private */ + NORM('P'), /* protected */ + CTRL('P'), /* public */ + NORM('r'), /* reinterpret_cast */ + NORM('R'), /* return */ + NORM('s'), /* short */ + NORM('S'), /* signed */ + CTRL('S'), /* sizeof */ + META('s'), /* static */ + META('S'), /* static_cast */ + MTCT('S'), /* struct */ + META('w'), /* switch */ + NORM('t'), /* template */ + CTRL('T'), /* throw */ + META('T'), /* try */ + MTCT('T'), /* typedef */ + NORM('y'), /* typeid */ + NORM('z'), /* typename */ + NORM('u'), /* union */ + NORM('U'), /* unsigned */ + CTRL('U'), /* using */ + NORM('v'), /* virtual */ + NORM('V'), /* volatile */ + CTRL('V'), /* void */ + NORM('w'), /* while */ + NORM('x'), /* xor */ + NORM('X'), /* xor_eq */ + No_Token +}; + +static const Token Non_Initials[] = { + NORM(')'), + NORM('}'), + NORM(';'), + No_Token +}; + +static const Token Openers[] = { + NORM('{'), + NORM('('), + NORM('['), + No_Token +}; + +static const Token Closers[] = { + NORM('}'), + NORM(')'), + NORM(']'), + No_Token +}; + +/* Language-dependent code */ + +const char *Subject = "C++ programs"; + +void +Init_Language(void) { + Init_Algol_Language(Non_Finals, Non_Initials, Openers, Closers); +} + + +int +May_Be_Start_Of_Run(Token ch) { + return May_Be_Start_Of_Algol_Run(ch); +} + +size_t +Best_Run_Size(const Token *str, size_t size) { + return Best_Algol_Run_Size(str, size); +} + +%} + +%option noyywrap + +%Start Comment + +Layout ([ \t\r\f]) +ASCII95 ([\040-\176]) + +Digit ([0-9a-fA-F]) + +UniCode (\\u{Digit}{Digit}{Digit}{Digit}) +AnyQuoted ((\\.)|{UniCode}) +StrChar ([^\"\n\\]|{AnyQuoted}) +ChrChar ([^\'\n\\]|{AnyQuoted}) + +StartComment ("/*") +EndComment ("*/") +SafeComChar ([^*\n]) +UnsafeComChar ("*") + +SingleLineCom ("//".*) + +Idf ([A-Za-z][A-Za-z0-9_]*) + +%% + +{StartComment} { + /* We do not have one single pattern to match a comment + (although one can be written), for two reasons. + The matched string might overflow lex-internal buffers + like yysbuf and yytext; and the pattern would be very + complicated and impair maintainability. + So we break up the string into safe chunks and keep + track of where we are in a start condition . + */ + BEGIN Comment; + } + +{SafeComChar}+ { /* safe comment chunk */ + } + +{UnsafeComChar} { /* unsafe char, read one by one */ + } + +"\n" { /* to break up long comments */ + return_eol(); + } + +{EndComment} { /* end-of-comment */ + BEGIN INITIAL; + } + +{SingleLineCom}"\n" { /* single-line comment */ + return_eol(); + } + +\"{StrChar}*\" { /* strings */ + return_ch('"'); + } + +\'{ChrChar}+\' { /* characters */ + return_ch('\''); + } + +^#{Layout}*include.* { /* ignore #include lines */ + } + +^#{Layout}*{Idf} { /* a preprocessor line */ + char *idf = yytext+1; + + /* skip layout in front of preprocessor identifier */ + while (*idf == ' ' || *idf == '\t') { + idf++; + } + return_tk(idf_in_list(idf, ppcmd, sizeof ppcmd, NORM('#'))); + } + +(0x)?{Digit}+("l"|"L")? { /* numeral, passed as an identifier */ + return_tk(IDF); + } + +{Idf}/"(" { /* identifier in front of ( */ + Token tk; + + tk = idf2token(is_set_option('F')); + if (!Token_EQ(tk, No_Token)) return_tk(tk); + } + +{Idf} { /* identifier */ + Token tk; + + tk = idf2token(0 /* no hashing */); + if (!Token_EQ(tk, No_Token)) return_tk(tk); + } + +\; { /* semicolon, conditionally ignored */ + if (is_set_option('f')) return_ch(yytext[0]); + } + +\n { /* count newlines */ + return_eol(); + } + +{Layout} { /* ignore layout */ + } + +{ASCII95} { /* copy other text */ + return_ch(yytext[0]); + } + +. { /* count non-ASCII chars */ + lex_non_ascii_cnt++; + } + +%% + +/* More language-dependent code */ + +void +yystart(void) { + BEGIN INITIAL; +} diff --git a/judger/core/sim/sim_2_77/clang.l b/judger/core/sim/sim_3_01/clang.l old mode 100755 new mode 100644 similarity index 96% rename from judger/core/sim/sim_2_77/clang.l rename to judger/core/sim/sim_3_01/clang.l index f45323aa..0437ed2d --- a/judger/core/sim/sim_2_77/clang.l +++ b/judger/core/sim/sim_3_01/clang.l @@ -1,7 +1,7 @@ %{ /* This file is part of the software similarity tester SIM. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: clang.l,v 2.20 2013-04-28 16:30:40 Gebruiker Exp $ + $Id: clang.l,v 2.22 2017-03-19 09:23:19 dick Exp $ */ /* @@ -141,6 +141,8 @@ static const Token Closers[] = { /* Language-dependent code */ +const char *Subject = "C programs"; + void Init_Language(void) { Init_Algol_Language(Non_Finals, Non_Initials, Openers, Closers); @@ -164,11 +166,11 @@ Best_Run_Size(const Token *str, size_t size) { %Start Comment Layout ([ \t\r\f]) -ASCII95 ([- !"#$%&'()*+,./0-9:;<=>?@A-Z\[\\\]^_`a-z{|}~]) +ASCII95 ([\040-\176]) AnyQuoted (\\.) -StrChar ([^"\n\\]|{AnyQuoted}) -ChrChar ([^'\n\\]|{AnyQuoted}) +StrChar ([^\"\n\\]|{AnyQuoted}) +ChrChar ([^\'\n\\]|{AnyQuoted}) StartComment ("/*") EndComment ("*/") diff --git a/judger/core/sim/sim_3_01/compare.c b/judger/core/sim/sim_3_01/compare.c new file mode 100644 index 00000000..d0d14ae4 --- /dev/null +++ b/judger/core/sim/sim_3_01/compare.c @@ -0,0 +1,406 @@ +/* This file is part of the software similarity tester SIM. + Written by Dick Grune, Vrije Universiteit, Amsterdam. + $Id: compare.c,v 2.38 2016-08-07 15:24:17 dick Exp $ +*/ + +#include "sim.h" +#include "text.h" +#include "token.h" +#include "tokenarray.h" +#include "hash.h" +#include "language.h" +#include "options.h" +#include "add_run.h" +#include "compare.h" +#include "debug.par" + +/* The overall structure of the routine Compare_Files() is: + + for all new files + for all texts it must be compared to + for all positions in the new file + for all positions in the text + for ever increasing sizes + try to match and keep the best +*/ + + /* LOCAL VARIABLES */ +static size_t beginning_of_text; +static size_t beginning_of_old_text; +static size_t end_of_text; + + /* RANGE HANDLING */ +struct range { + size_t rg_start; + size_t rg_limit; + int rg_sticky; +}; + +static int +in_range(size_t i, const struct range *rg) { + if (rg->rg_start <= rg->rg_limit) { + /* one single range */ + return (rg->rg_start <= i && i < rg->rg_limit); + } else { + /* looped-around range */ + return (rg->rg_start <= i && i < end_of_text + || beginning_of_text <= i && i < rg->rg_limit); + } +} + +static int +is_empty_range(const struct range *rg) { + return rg->rg_start == rg->rg_limit; +} + + /* COMPARE FILES */ +static void compare_one_text(int n, struct range *rg); +static void compare_one_on_one(int n, int m, struct range *rg); +static size_t lcs( + struct text *txt0, size_t i0, struct range *rg, + struct text **tx_bp, size_t *i_bp +); + +void +Compare_Files(void) { + int n; + + for ( /* all new texts */ + n = 0; n < Number_of_New_Texts; n++ + ) { + struct range range; + + /* construct default range */ + beginning_of_text = Text[0].tx_start; + beginning_of_old_text = Text[Number_of_New_Texts-1].tx_limit; + end_of_text = Text[Number_of_Texts-1].tx_limit; + range.rg_start = Text[n].tx_start + 1; + range.rg_limit = end_of_text; + range.rg_sticky = 0; + + /* update range for options */ + if (is_set_option('a')) { + /* all text */ + range.rg_start = Text[n].tx_start + 1; + range.rg_limit = Text[n].tx_start; + range.rg_sticky = 1; + } + + if (is_set_option('S')) { + /* old text only */ + range.rg_start = beginning_of_old_text; + range.rg_limit = end_of_text; + range.rg_sticky = 0; + } + + if (is_set_option('s')) { + if ( /* n in range */ + range.rg_start == Text[n].tx_start + 1 + ) { /* take it out */ + range.rg_start = Text[n].tx_limit; + range.rg_sticky = 0; + } + } + + if (is_empty_range(&range)) continue; + + /* compare the files */ + if (is_set_option('e')) { + /* over the range in steps of one */ + int m; + + for (m = n; m < Number_of_Texts; m++) { + compare_one_on_one(n, m, &range); + } + for (m = 0; m < n; m++) { + compare_one_on_one(n, m, &range); + } + } + else { + /* the whole range in one action */ + compare_one_text(n, &range); + } + } +} + +static void +compare_one_on_one( + int n, /* index of text to be compared */ + int m, /* index of text to be compared to */ + struct range *rg /* pointer to search range */ +) { + const struct text *txt1 = &Text[m]; + if (!in_range(txt1->tx_start+1, rg)) return; + + /* construct private range consisting of Text[m] */ + struct range range_m; + range_m.rg_start = txt1->tx_start; + range_m.rg_limit = txt1->tx_limit; + range_m.rg_sticky = 0; + + /* compare Text[n] and Text[m] */ + compare_one_text(n, &range_m); +} + +static void +compare_one_text( + int n, /* index of text to be compared */ + struct range *rg /* pointer to search range */ +) { + struct text *txt0 = &Text[n]; + size_t i0 = txt0->tx_start; + +#ifdef DB_COMP + fprintf(Debug_File, "compare_one_text(%s", txt0->tx_fname); + fprintf(Debug_File, + ", i0 = %d, rg_start = %d, rg_limit = %d, sticky = %d)\n", + i0, rg->rg_start, rg->rg_limit, rg->rg_sticky); +#endif + + while ( /* there is room for a run */ + i0 + Min_Run_Size <= txt0->tx_limit + ) { + if (!May_Be_Start_Of_Run(Token_Array[i0])) { + /* no point in looking; try the next token */ + i0++; + } else { + /* see if there really is a run */ + struct text *txt_run; + size_t i_run; + size_t run_size = + lcs(txt0, i0, rg, &txt_run, &i_run); + + if (run_size) { + /* run found; enter it */ +#ifdef DB_COMP + fprintf(Debug_File, + "add_run(%s, %d, %s, %d, %d)\n", + txt0->tx_fname, i0, + txt_run->tx_fname, i_run, run_size); +#endif + add_run(txt0, i0, txt_run, i_run, run_size); + /* and skip it */ + i0 += run_size; + } + else { + /* we try our luck at the next token */ + i0++; + } + } + if (rg->rg_sticky) { + /* drag rg->rg_start along */ + rg->rg_start = i0 - 1; + } + } +} + +#ifdef DB_COMP_2 +static void +fprint_tokens(FILE *o, size_t p0, size_t p1) { + fprintf(o, "\n \""); + while (p0 < p1) { + fprintf(o, " %3d", Token_Array[p0]); + p0++; + } + fprintf(o, "\""); +} +#endif + +static size_t +first_forward_ref_for(size_t i0, const struct range *rg) { + size_t res = Forward_Reference(i0, i0); + while (res && !in_range(res, rg)) { + res = Forward_Reference(res, i0); + } + return res; +} + +static size_t +lcs( struct text *txt0, /* text to be compared */ + size_t i0, /* starting pos. in txt0 */ + struct range *rg, /* search range */ + /* two output parameters, set if return value > 0: */ + struct text **tx_bp, /* output, text of best run */ + size_t *i_bp /* starting pos. in text of best run */ +) { + /* Finds the longest common substring (not subsequence) in: + txt0, starting precisely at i0 and + all the text in the search range rg. + Writes the position in tx_bp and i_bp and returns the size. + Returns 0 if no common substring is found. + */ + size_t i1; + size_t size_best = 0; + + if (!(txt0->tx_start <= i0 && i0 < txt0->tx_limit)) + fatal("i0 not inside txt0"); + +#ifdef DB_COMP + fprintf(Debug_File, + "lcs(i0 = %d, rg_start = %d, rg_limit = %d), FWR[i0] = %d, ffr[i0] = %d\n", + i0, rg->rg_start, rg->rg_limit, + Forward_Reference(i0, i0), + first_forward_ref_for(i0, rg) + ); +#endif + + for ( i1 = first_forward_ref_for(i0, rg); + i1 && in_range(i1, rg); + i1 = Forward_Reference(i1, i0) + ) { + /* i1 is always on the forward reference chain of i0 */ + + /* Find the text txt1 into which i1 points. */ +#if 0 + struct text *txt1 = txt0; + while (i1 < txt1->tx_start) { + txt1--; + } + while (i1 >= txt1->tx_limit) { + txt1++; + } +#else + struct text *txt1; + { struct text *txt_b = &Text[0]; + struct text *txt_e = &Text[Number_of_Texts-1]; + while (txt_b != txt_e) { + struct text *txt_m = txt_b + (txt_e-txt_b) / 2; + if (i1 < txt_m->tx_limit) { + txt_e = txt_m; + } else { + txt_b = txt_m + 1; + } + } + txt1 = txt_b; + } +#endif + if (!(txt1->tx_start <= i1 && i1 < txt1->tx_limit)) + fatal("i1 not inside txt1"); + + + + +#ifdef DB_COMP + fprintf(Debug_File, "for i1: %s, i0=%d,%s, i1=%d\n", + txt0->tx_fname, i0, txt1->tx_fname, i1); +#endif + + size_t better_size = (size_best ? size_best+1 : Min_Run_Size); + + /* Are we looking at something better than we have got? */ + { /* we compare backwards from the end of + a putative better match starting at i1 + */ + size_t j0 = i0 + better_size - 1; + size_t j1 = i1 + better_size - 1; +#ifdef DB_COMP + fprintf(Debug_File, "init: j0 = %d, j1 = %d\n", j0, j1); +#endif + /* would there be room for a better match? */ + if ( /* j0 still inside txt0 */ + j0 < txt0->tx_limit + && /* j1 still inside txt1 */ + j1 < txt1->tx_limit + && /* better 0 and better 1 don't overlap */ + (j0 < i1 || j1 < i0) + ) { + /* yes, there is room enough for a match */ + + /* see if the text matches for at least + better_size tokens + */ + /* since we have perfect forward references and + chack backwards, we do not have to check the + last Min_Run_Size tokens: + */ + size_t cnt = better_size - Min_Run_Size; + +#ifdef DB_COMP + fprintf(Debug_File, + "init verification: cnt = %d", cnt); +#ifdef DB_COMP_2 + /* we don't want this all the time under + DB_COMP, but we want it linted + */ + fprint_tokens(Debug_File, i0, i0+better_size); + fprint_tokens(Debug_File, i1, i1+better_size); +#endif + fprintf(Debug_File, "\n"); +#endif + while ( cnt + && Token_EQ(Token_Array[j0], + Token_Array[j1]) + ) { + cnt--, j0--, j1--; + } +#ifdef DB_COMP + fprintf(Debug_File, + "end verification: cnt = %d\n", cnt); +#endif + if (cnt) { + /* not all tokens matched, + so forget it */ + continue; + } + } else { + /* no, there is not enough room for a better + match, so forget it */ + continue; + } + } + + /* Yes, we are looking at a better match; + how long can we make it? + */ + size_t new_size = better_size; + { /* extending forwards */ + size_t j0 = i0 + better_size; + size_t j1 = i1 + better_size; + + while ( /* j0 still inside txt0 */ + j0 < txt0->tx_limit + && /* j1 still inside txt1 */ + j1 < txt1->tx_limit + && /* j0 and j1 don't overlap */ + (j0 < i1 || j1 < i0) + && /* tokens are the same */ + Token_EQ(Token_Array[j0], Token_Array[j1]) + ) { + j0++, j1++, new_size++; + } + } +#ifdef DB_COMP + fprintf(Debug_File, + "end forward extension: new_size = %d\n", new_size); +#endif + + /* Offer the run to the Language Department which may + reject it or may cut its tail. + */ + new_size = Best_Run_Size(&Token_Array[i0], new_size); + + if ( /* we still have an acceptable run */ + new_size >= Min_Run_Size + && /* it is still better than what we had */ + new_size > size_best + ) { + /* record it */ +#ifdef DB_COMP + fprintf(Debug_File, + "possible run: %s, %d, %s, %d, %d\n", + txt0->tx_fname, i0, + txt1->tx_fname, i1, new_size); +#endif + *tx_bp = txt1; + *i_bp = i1; + size_best = new_size; + } + /* and see if it can be improved with a different i1 */ + } +#ifdef DB_COMP + fprintf(Debug_File, "lcs out, size_best = %d\n", + size_best); +#endif + + return size_best; +} diff --git a/judger/core/sim/sim_2_77/compare.h b/judger/core/sim/sim_3_01/compare.h old mode 100755 new mode 100644 similarity index 71% rename from judger/core/sim/sim_2_77/compare.h rename to judger/core/sim/sim_3_01/compare.h index 1ed7e637..ce78b89c --- a/judger/core/sim/sim_2_77/compare.h +++ b/judger/core/sim/sim_3_01/compare.h @@ -1,10 +1,10 @@ /* This file is part of the software similarity tester SIM. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: compare.h,v 1.3 2012-05-16 07:56:05 Gebruiker Exp $ + $Id: compare.h,v 1.4 2016-04-10 11:19:47 dick Exp $ */ /* Compares each new text to the appropriate texts. - Stores the runs found in the AISO heap. + Stores the runs found by passing them to add_run(). Runs contain references to positions in the input files. */ diff --git a/judger/core/sim/sim_2_77/debug.c b/judger/core/sim/sim_3_01/debug.c old mode 100755 new mode 100644 similarity index 78% rename from judger/core/sim/sim_2_77/debug.c rename to judger/core/sim/sim_3_01/debug.c index ebcff977..ad7afa3c --- a/judger/core/sim/sim_2_77/debug.c +++ b/judger/core/sim/sim_3_01/debug.c @@ -1,6 +1,6 @@ /* This file is part of the debugging module DEBUG. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: debug.c,v 1.6 2013-05-12 09:58:34 Gebruiker Exp $ + $Id: debug.c,v 1.7 2014-09-25 06:58:25 Gebruiker Exp $ */ #include @@ -45,7 +45,7 @@ wr_str(const char *s) { } void -wr_info(const char *s, int b, int v) { +wr_info(const char *s, int v) { /* print the string */ if (s) { int cnt = 0; @@ -84,29 +84,12 @@ wr_info(const char *s, int b, int v) { } /* print the value */ - if (b != 0) { - wr_char(' '); - if (v < 0) { - wr_char('-'); - v = -v; - } - switch (b) { - case 8: - wr_char('0'); - wr_num(b, v); - break; - default: - wr_num(10, v); - break; - case 16: - wr_char('#'); - wr_num(b, v); - break; - case 128: - wr_char(v); - break; - } + wr_char(' '); + if (v < 0) { + wr_char('-'); + v = -v; } + wr_num(10, v); wr_char('\n'); } @@ -115,7 +98,7 @@ wr_info(const char *s, int b, int v) { /*ARGSUSED*/ void -wr_info(const char *s, int b, int v) { +wr_info(const char *s, int v) { } #endif /* DEBUG */ @@ -126,7 +109,7 @@ wr_info(const char *s, int b, int v) { #ifdef lint static void satisfy_lint(void *x) { - wr_info((char *)x, 0, 0); + wr_info((char *)x, 0); satisfy_lint(x); } #endif /* lint */ diff --git a/judger/core/sim/sim_3_01/debug.h b/judger/core/sim/sim_3_01/debug.h new file mode 100644 index 00000000..5d1c74f5 --- /dev/null +++ b/judger/core/sim/sim_3_01/debug.h @@ -0,0 +1,28 @@ +/* This file is part of the debugging module DEBUG. + Written by Dick Grune, Vrije Universiteit, Amsterdam. + $Id: debug.h,v 1.9 2014-09-25 06:58:26 Gebruiker Exp $ +*/ + +#ifndef _DEBUG_H_ +#define _DEBUG_H_ + +/**** +The module DEBUG defines one routine, + + extern void wr_info(const char *str, int val); + +which, when compiled with a -DDEBUG option, writes the string str, a space +character, the value val in decimal, and a newline to standard error output +(file descriptor 2), without interfering with other program activities. + +This allows debugging info to be obtained in the presence of sudden crashes +and other nefarious program activity. + +Compiled without the -DDEBUG option wr_info does nothing. This allows easy +switching off of the debugging feature by recompiling debug.c. +****/ + +/* Public entries */ +extern void wr_info(const char *s, int v); + +#endif /* _DEBUG_H_ */ diff --git a/judger/core/sim/sim_2_77/debug.par b/judger/core/sim/sim_3_01/debug.par old mode 100755 new mode 100644 similarity index 52% rename from judger/core/sim/sim_2_77/debug.par rename to judger/core/sim/sim_3_01/debug.par index db02e6ab..9c1dbc0f --- a/judger/core/sim/sim_2_77/debug.par +++ b/judger/core/sim/sim_3_01/debug.par @@ -1,23 +1,29 @@ /* This file is part of the software similarity tester SIM. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: debug.par,v 1.6 2014-01-26 13:51:27 Gebruiker Exp $ + $Id: debug.par,v 1.14 2016-07-29 20:41:32 dick Exp $ */ -#undef DB_ALL - #undef DB_HASH /* print hash value info */ -#undef DB_FORW_REF /* print & check forward references */ +#undef DB_FORW_REF /* check forward references */ +#undef DB_FORW_REF_PRINT /* also print forward references */ +#undef DB_COMP /* print comparison activity */ +#undef DB_COMP_2 /* include token comparison */ #undef DB_TEXT /* print all text parts */ #undef DB_POS /* print positions in files */ #undef DB_NL_BUFF /* print the newline count buffer */ #undef DB_RUN /* print all run activity */ +#undef DB_PERC /* print the percentage match list */ -#if defined(lint) || defined(DB_ALL) +#if defined(lint) #define DB_HASH #define DB_FORW_REF +#define DB_FORW_REF_PRINT +#define DB_COMP +#define DB_COMP_2 #define DB_TEXT #define DB_POS #define DB_NL_BUFF #define DB_RUN +#define DB_PERC #endif diff --git a/judger/core/sim/sim_2_77/fname.c b/judger/core/sim/sim_3_01/fname.c old mode 100755 new mode 100644 similarity index 94% rename from judger/core/sim/sim_2_77/fname.c rename to judger/core/sim/sim_3_01/fname.c index f6e93c95..4ce12b57 --- a/judger/core/sim/sim_2_77/fname.c +++ b/judger/core/sim/sim_3_01/fname.c @@ -1,15 +1,17 @@ /* This file is part of the auxiliaries library. - Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: fname.c,v 1.6 2013-05-12 13:21:24 Gebruiker Exp $ + Written by Dick Grune, dick@dickgrune.com + $Id: fname.c,v 1.8 2017-01-22 14:50:00 Gebruiker Exp $ */ /* Support for UNICODE file names in Windows */ /* Two data types are involved in UNICODE file names in Windows: - UTF16 strings, the file names as stored by Windows, and - UTF8 strings, the names as they are displayed and stored. + + UTF16 strings, the file names as stored by Windows, and + UTF8 strings, the names as they are displayed and stored. + The conversion between these two proceeds through CodePoints, - the 'real' vales of the characters, of which UTF16 strings and + the 'real' values of the characters, of which UTF16 strings and UTF8 strings are the compressed representations. The module consists of two levels: a set of static routines @@ -324,3 +326,11 @@ Fopen(const Fchar *fn, const char *rb) { /* stream is still char* */ /* End library module source code */ #endif /* _FNAME_CODE_ */ + +#ifdef lint +static void +satisfy_lint(void *x) { + /* lint cannot handle Fchar complications */ + satisfy_lint(x); +} +#endif /* lint */ diff --git a/judger/core/sim/sim_2_77/fname.h b/judger/core/sim/sim_3_01/fname.h old mode 100755 new mode 100644 similarity index 91% rename from judger/core/sim/sim_2_77/fname.h rename to judger/core/sim/sim_3_01/fname.h index 8c5984d2..d30bdef4 --- a/judger/core/sim/sim_2_77/fname.h +++ b/judger/core/sim/sim_3_01/fname.h @@ -1,6 +1,6 @@ /* This file is part of the auxiliaries library. - Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: fname.h,v 1.11 2013-05-12 13:21:24 Gebruiker Exp $ + Written by Dick Grune, dick@dickgrune.com + $Id: fname.h,v 1.13 2017-01-22 14:50:00 Gebruiker Exp $ */ /* Support for UNICODE file names */ @@ -39,7 +39,9 @@ DIR by Dir_t, and struct dirent by Dirent_t. Compiling and correcting using the above replacements until there are no - more errors or warnings will then yield an UTF-16 compatible program. + more errors or warnings will then yield an UTF-16 compatible program, as + far as the input is concerned. Output is done in UTF-8; there seems to be + no way to do output in UFT-16. For details about UTF-16 see fname.c. */ @@ -48,7 +50,7 @@ #define _FNAME_H_ /* lint cannot handle the weird code Windows throws at it, so even under - Windows we clain to have UTF8 + Windows we claim to have UTF8 */ #ifdef MSDOS #define IS_UTF_16 diff --git a/judger/core/sim/sim_3_01/hash.c b/judger/core/sim/sim_3_01/hash.c new file mode 100644 index 00000000..8aba1d87 --- /dev/null +++ b/judger/core/sim/sim_3_01/hash.c @@ -0,0 +1,434 @@ +/* This file is part of the software similarity tester SIM. + Written by Dick Grune, Vrije Universiteit, Amsterdam. + $Id: hash.c,v 2.39 2017-02-04 16:58:54 dick Exp $ +*/ + +/* Text is compared by comparing every substring to all substrings + to the right of it; this process is in essence quadratic. However, + only substrings of length at least 'Min_Run_Size' are of interest, + which gives us the possibility to speed up this process by using + a hash table. + + For every position p in the text, we construct an index table entry + forward_reference[p] which gives the next position in the text + at which a run of Min_Run_Size tokens starts that has the same + hash code, as calculated by hash1(). If there is no such run, + the index is 0. + + To construct this array, we use a hash table latest_index[] whose size + is a prime and which is about the same size as the text array. + The hash table latest_index[] is set up such that latest_index[i] is the + index of the latest token with hash_code i, or 0 if there is none. + See Make_Forward_References(). + + The forward references produced this way are not perfect, due to hashing + coincidences. A second sweep (make_forward_references_perfect()) makes + them perfect by doing a full comparison on Min_Run_Size tokens. + For the LaTeX sources of our book Modern Compiler Design, 2nd Ed. this + reduced the total forward chain length from 103555 to 345, as + determined by db_forward_reference_check(). + + The forward references can be checked with db_forward_reference_check(), + which also collects statistics. +*/ + +#include +#include + +#include "system.par" +#include "debug.par" +#include "sim.h" +#include "text.h" +#include "Malloc.h" +#include "any_int.h" +#include "token.h" +#include "language.h" +#include "token.h" +#include "tokenarray.h" +#include "options.h" +#include "hash.h" + + /* MAIN ENTRIES */ +static size_t *forward_reference; /* to be filled by Malloc() */ +static size_t n_forward_references; + +static void make_forward_references_using_hash(void); +static void make_forward_references_perfect(void); +static void make_chains_circular(void); + +#ifdef DB_FORW_REF +static void db_forward_reference_check(const char *); +static void db_print_forward_references(void); +#endif /* DB_FORW_REF */ + +void +Make_Forward_References(void) { + /* Constructs the forward references table. + */ + n_forward_references = Token_Array_Length(); + forward_reference = + (size_t *)Calloc(n_forward_references, sizeof (size_t)); + make_forward_references_using_hash(); + make_forward_references_perfect(); + if (is_set_option('a')) { + make_chains_circular(); + } +#ifdef DB_FORW_REF_PRINT + db_print_forward_references(); +#endif /* DB_FORW_REF_PRINT */ +} + +size_t +Forward_Reference(size_t i, size_t i0) { + if (i == 0 || i >= n_forward_references) { + fatal("internal error, bad forward reference"); + } + size_t new_i = forward_reference[i]; + size_t res = new_i == 0 || new_i == i0 /*circular*/ ? 0 : new_i; + return res; +} + +void +Free_Forward_References(void) { + Free(forward_reference); +} + + /* HASHING */ +static size_t *latest_index; +static size_t latest_index_table_size; + +/* The prime numbers of the form 4 * i + 3 for some i, all greater + than twice the previous one and smaller than 2^40 (for now). +*/ +static const uint64_t prime[] = { +#if 0 + 3, + 7, + 19, + 43, + 103, + 211, + 431, + 863, + 1747, + 3499, + 7019, +#endif + 14051, + 28111, + 56239, + 112507, + 225023, + 450067, + 900139, + 1800311, + 3600659, + 7201351, + 14402743, + 28805519, + 57611039, + 115222091, + 230444239, + 460888499, + 921777067, + 1843554151, + UINT64_C (3687108307), + UINT64_C (7374216631), + UINT64_C (14748433279), + UINT64_C (29496866579), + UINT64_C (58993733159), + UINT64_C (117987466379), + UINT64_C (235974932759), + UINT64_C (471949865531), + UINT64_C (943899731087) + /* 2^40= 1099511627776 */ +}; + +static void +init_hash_table(void) { + int n; + + /* find the ideal hash table size */ + n = 0; + while (prime[n] < Token_Array_Length()) { + n++; + /* this will always terminate, if prime[] is large enough */ + } + + /* see if we can allocate that much space, and if not, step down */ + latest_index = 0; + while ( /* we have not yet obtained our array */ + !latest_index + && /* and there is still a (prime) size left to try */ + n >= 0 + ) { + latest_index_table_size = prime[n]; + latest_index = (size_t *) + TryCalloc(latest_index_table_size, sizeof (size_t)); + n--; + } + if (!latest_index) { + fatal("out of memory: no room for hash table"); + } +} + +static void +make_forward_references_using_hash(void) { + int n; + + init_hash_table(); + + /* Set up the forward references using the latest_index[] hash table. */ + for (n = 0; n < Number_of_Texts; n++) { + const struct text *txt = &Text[n]; + size_t j; + uint32_t hash = 0; + +#define Left_Circular_32(i, s) (((i) << (s)) | ((i) >> (32-(s)))) +#define SHIFT (5) + + for (j = txt->tx_start; j < txt->tx_limit; j++) { + if ( /* we have a complete hash value */ + j - txt->tx_start >= Min_Run_Size + ) { /* remove the oldest token */ + Token oldest_token = + Token_Array[j - Min_Run_Size]; + int oldest_shift = + ((Min_Run_Size-1) * SHIFT) % 32; + hash ^= + Left_Circular_32(oldest_token, oldest_shift); + } + /* Circular left shift */ + hash = Left_Circular_32(hash, SHIFT); + /* Add new token */ + hash ^= Token_Array[j]; + + /* If have we assembled a complete hash value now, + the corresponding run would start at + j - (Min_Run_Size - 1). For it to be valid it + should start at or after txt->tx_start, so we would + like to write the test + j - (Min_Run_Size - 1) >= txt->tx_start. However, + the type of this computation is size_t, which is + unsigned, and j - (Min_Run_Size - 1) may be negative, + so we code instead: + */ + if (j - txt->tx_start < (Min_Run_Size - 1)) { + /* no */ + continue; + } + + /* We now have the complete hash value for a run ending + at j and can safely compute j - (Min_Run_Size - 1). + */ + size_t run_start = j - (Min_Run_Size - 1); + + /* Can the run be useful? */ + if (!May_Be_Start_Of_Run(Token_Array[run_start])) + continue; /* no*/ + + /* the hash value is used here for an index */ + size_t h = hash % latest_index_table_size; + + if (latest_index[h]) { + forward_reference[latest_index[h]] = run_start; + } + /*latest_index[h] = j;*/ + latest_index[h] = run_start; + } + } + + Free(latest_index); + +#ifdef DB_FORW_REF + db_forward_reference_check("first hashing"); +#endif /* DB_FORW_REF */ +} + +static void +make_chains_circular(void) { + size_t i; + + /* Make the chains circular, by a slightly quadratic algorithm. */ + for (i = 0; i+Min_Run_Size < Token_Array_Length(); i++) { + if (!forward_reference[i]) continue; + size_t j = i; + while (forward_reference[j]) { + size_t j1 = forward_reference[j]; + if (j1 < j) break; /* has already been treated */ + j = j1; + } + if (forward_reference[j] == 0 && j != i) { + /* tie it back to the beginning of the chain */ + forward_reference[j] = i; + } + } +} + +static int +is_eq_min_run(const Token *p, const Token *q) { + /* a full comparison for the tertiary sweep */ + size_t n; + + for (n = 0; n < Min_Run_Size; n++) { + if (!Token_EQ(p[n], q[n])) return 0; + } + return 1; +} + +static void +make_forward_references_perfect(void) { + size_t i; + + /* Simulate a perfect hash by doing a full comparison + over Min_Run_Size, for gathering statistics. + */ + + for (i = 0; i+Min_Run_Size < Token_Array_Length(); i++) { + size_t j = i; + + while ( /* there is still a forward reference */ + (j = forward_reference[j]) + && /* it does not match over Min_Run_Size */ + !is_eq_min_run(&Token_Array[i], &Token_Array[j]) + ) { + /* continue searching */ + } + /* short-circuit forward reference to it, or to zero */ + forward_reference[i] = j; + } + /* now we have perfect forward references */ + +#ifdef DB_FORW_REF + db_forward_reference_check("full Min_Run_Size comparison"); +#endif /* DB_FORW_REF */ +} + +#ifdef DB_FORW_REF + +static void +db_print_forward_references(void) { + /* also determines the lengths of the chains, for statistics */ + size_t n; + size_t n_frw_chains = 0; + size_t tot_frwc_len = 0; + size_t *print_loc_of = + (size_t *)Calloc(Token_Array_Length(), sizeof (size_t)); + size_t *number_of_chains_of_length = + (size_t *)Calloc(Token_Array_Length(), sizeof (size_t)); + + /* print the references */ + for (n = 1; n < Token_Array_Length(); n++) { + size_t fw = forward_reference[n]; + if (fw == 0) continue; + + /* we have a chain */ + fprintf(Debug_File, "FWR[%s]:", any_uint2string(n, 0)); + + /* is it old? */ + if (print_loc_of[n]) { + fprintf(Debug_File, " see %s\n", + any_uint2string(print_loc_of[n], 0)); + continue; + } + + /* no, we have the beginning of a new chain */ + size_t count = 0; + do { + count++; + fprintf(Debug_File, " %s", + any_uint2string(fw, 0)); + print_loc_of[fw] = n; + fw = forward_reference[fw]; + } while(fw && fw != n); /* continuing and not circular */ + if (fw) { /* circular */ + fprintf(Debug_File, " C"); + count++; + } + n_frw_chains++; + tot_frwc_len += count; + number_of_chains_of_length[count]++; + fprintf(Debug_File, "\n"); + } + + /* print the chain lengths */ + for (n = 1; n < Token_Array_Length(); n++) { + if (number_of_chains_of_length[n]) { + fprintf(Debug_File, "length[%d]:\t%d\n", + n, number_of_chains_of_length[n]); + } + } + + fprintf(Debug_File, + "text length = %s, # forward chains = %s, av. frw chain length = %.2f\n\n", + any_uint2string(Token_Array_Length(), 0), + any_uint2string(n_frw_chains, 0), + (n_frw_chains ? 1.0 * tot_frwc_len / n_frw_chains : 0.0) + ); + + Free(number_of_chains_of_length); + Free(print_loc_of); +} + +static void +db_frw_chain(size_t n, char *crossed_out) { + if (forward_reference[n] == 0) { + fprintf(Debug_File, + ">>>> db_frw_chain() forward_reference[n] == 0 <<<<\n" + ); + return; + } + + size_t n_entries = 0; + size_t fw; + + for (fw = n; fw; fw = forward_reference[fw]) { + if (crossed_out[fw]) { + fprintf(Debug_File, + ">>>> error: forward references cross <<<<\n" + ); + } + n_entries++; + crossed_out[fw] = 1; + } +#ifdef DB_FORW_REF_PRINT + fprintf(Debug_File, "chain_start = %s, n_entries = %s\n", + any_uint2string(n, 0), any_uint2string(n_entries, 0)); +#endif /* DB_FORW_REF_PRINT */ +} + +static void +db_forward_reference_check(const char *msg) { + /* Each forward_reference[n] starts in principle a new + chain, and these chains never touch each other. + We check this property by marking the positions in each + chain in an array; if we meet a marked entry while + following a chain, it must have been on an earlier chain + and we have an error. + */ + size_t n; + char *crossed_out = (char *)Calloc(Token_Array_Length(), sizeof (char)); + + fprintf(Debug_File, "\n\n**** DB_FORWARD_REFERENCES, %s ****\n", msg); + fprintf(Debug_File, "latest_index_table_size = %s\n", + any_uint2string(latest_index_table_size, 0)); + + if (forward_reference[0]) { + fprintf(Debug_File, + ">>>> forward_reference[0] is not zero <<<<\n" + ); + } + for (n = 1; n < Token_Array_Length(); n++) { + if (forward_reference[n] && !crossed_out[n]) { + /* start of a new chain */ + db_frw_chain(n, crossed_out); + } + } +#ifdef DB_FORW_REF_PRINT + db_print_forward_references(); +#endif /* DB_FORW_REF_PRINT */ + + Free(crossed_out); +} + +#endif /* DB_FORW_REF */ diff --git a/judger/core/sim/sim_2_77/hash.h b/judger/core/sim/sim_3_01/hash.h old mode 100755 new mode 100644 similarity index 69% rename from judger/core/sim/sim_2_77/hash.h rename to judger/core/sim/sim_3_01/hash.h index e85cf0f6..155d15b2 --- a/judger/core/sim/sim_2_77/hash.h +++ b/judger/core/sim/sim_3_01/hash.h @@ -1,6 +1,6 @@ /* This file is part of the software similarity tester SIM. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: hash.h,v 1.4 2013-04-28 16:30:40 Gebruiker Exp $ + $Id: hash.h,v 1.5 2016-04-27 12:59:11 dick Exp $ */ /* Creating and consulting forward_reference[], used to speed up @@ -9,4 +9,5 @@ extern void Make_Forward_References(void); extern void Free_Forward_References(void); -extern size_t Forward_Reference(size_t i); +/* with circularity check: */ +extern size_t Forward_Reference(size_t i, size_t i0); diff --git a/judger/core/sim/sim_2_77/idf.c b/judger/core/sim/sim_3_01/idf.c old mode 100755 new mode 100644 similarity index 86% rename from judger/core/sim/sim_2_77/idf.c rename to judger/core/sim/sim_3_01/idf.c index 6d20131a..9f892afa --- a/judger/core/sim/sim_2_77/idf.c +++ b/judger/core/sim/sim_3_01/idf.c @@ -1,6 +1,6 @@ /* This file is part of the software similarity tester SIM. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: idf.c,v 2.17 2013-04-28 16:30:40 Gebruiker Exp $ + $Id: idf.c,v 2.19 2015-01-17 10:20:40 dick Exp $ */ #include @@ -45,6 +45,7 @@ idf_hashed(const char *str) { while (*str) { int ch = *str++ & 0377; + /* ignore spaces in spaced words */ if (ch == ' ') continue; /* -1 <= h <= 2^31-1 */ @@ -73,3 +74,14 @@ idf_hashed(const char *str) { return int2Token(h); /* this avoids the regular tokens and End_Of_Line */ } + +void +lower_case(char *str) { + char *s; + + for (s = str; *s; s++) { + if ('A' <= *s && *s <= 'Z') { + *s += (-'A' + 'a'); + } + } +} diff --git a/judger/core/sim/sim_2_77/idf.h b/judger/core/sim/sim_3_01/idf.h old mode 100755 new mode 100644 similarity index 79% rename from judger/core/sim/sim_2_77/idf.h rename to judger/core/sim/sim_3_01/idf.h index 380e34b8..6080a15f --- a/judger/core/sim/sim_2_77/idf.h +++ b/judger/core/sim/sim_3_01/idf.h @@ -1,10 +1,15 @@ /* This file is part of the software similarity tester SIM. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: idf.h,v 2.11 2013-04-28 16:30:40 Gebruiker Exp $ + $Id: idf.h,v 2.13 2016-07-31 18:55:44 dick Exp $ */ /* Idf module: - Token idf_in_list(char *str, struct idf l[], sizeof l, Token dflt); + Token idf_in_list( + const char *str, + const struct idf list[], + size_t listsize, + Token default_token + ); looks up a keyword in a list of keywords l, represented as an array of struct idf, and returns its translation as a token; dflt is returned if the keyword is not found. @@ -27,3 +32,4 @@ extern Token idf_in_list( Token default_token ); extern Token idf_hashed(const char *str); +extern void lower_case(char *str); diff --git a/judger/core/sim/sim_2_77/javalang.l b/judger/core/sim/sim_3_01/javalang.l old mode 100755 new mode 100644 similarity index 96% rename from judger/core/sim/sim_2_77/javalang.l rename to judger/core/sim/sim_3_01/javalang.l index d8c96d2c..3e7884e2 --- a/judger/core/sim/sim_2_77/javalang.l +++ b/judger/core/sim/sim_3_01/javalang.l @@ -1,7 +1,7 @@ %{ /* This file is part of the software similarity tester SIM. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: javalang.l,v 1.14 2013-04-28 16:30:41 Gebruiker Exp $ + $Id: javalang.l,v 1.16 2017-03-19 09:23:19 dick Exp $ */ /* @@ -158,6 +158,8 @@ const Token Closers[] = { /* Language-dependent code */ +const char *Subject = "Java programs"; + void Init_Language(void) { Init_Algol_Language(Non_Finals, Non_Initials, Openers, Closers); @@ -181,14 +183,14 @@ Best_Run_Size(const Token *str, size_t size) { %Start Comment Layout ([ \t\r\f]) -ASCII95 ([- !"#$%&'()*+,./0-9:;<=>?@A-Z\[\\\]^_`a-z{|}~]) +ASCII95 ([\040-\176]) Digit ([0-9a-fA-F]) UniCode (\\u{Digit}{Digit}{Digit}{Digit}) AnyQuoted ((\\.)|{UniCode}) -StrChar ([^"\n\\]|{AnyQuoted}) -ChrChar ([^'\n\\]|{AnyQuoted}) +StrChar ([^\"\n\\]|{AnyQuoted}) +ChrChar ([^\'\n\\]|{AnyQuoted}) StartComment ("/*") EndComment ("*/") diff --git a/judger/core/sim/sim_2_77/lang.c b/judger/core/sim/sim_3_01/lang.c old mode 100755 new mode 100644 similarity index 91% rename from judger/core/sim/sim_2_77/lang.c rename to judger/core/sim/sim_3_01/lang.c index bfc5bd8b..cd104fd1 --- a/judger/core/sim/sim_2_77/lang.c +++ b/judger/core/sim/sim_3_01/lang.c @@ -1,6 +1,6 @@ /* This file is part of the software similarity tester SIM. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: lang.c,v 2.8 2014-01-27 20:50:51 Gebruiker Exp $ + $Id: lang.c,v 2.9 2016-05-13 19:00:52 dick Exp $ */ /* @@ -30,6 +30,7 @@ yylex(void) { (void)Best_Algol_Run_Size(0, 0); (void)idf_in_list(0, 0, 0, 0); (void)idf_hashed(0); + (void)lower_case(0); #endif return 0; } diff --git a/judger/core/sim/sim_2_77/lang.h b/judger/core/sim/sim_3_01/lang.h old mode 100755 new mode 100644 similarity index 64% rename from judger/core/sim/sim_2_77/lang.h rename to judger/core/sim/sim_3_01/lang.h index a7642b56..a277433c --- a/judger/core/sim/sim_2_77/lang.h +++ b/judger/core/sim/sim_3_01/lang.h @@ -1,6 +1,6 @@ /* This file is part of the software similarity tester SIM. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: lang.h,v 1.8 2013-04-28 16:30:41 Gebruiker Exp $ + $Id: lang.h,v 1.9 2016-04-27 19:09:48 dick Exp $ */ /* @@ -11,11 +11,12 @@ */ /* - The abstract module 'lang' provides access to the lowest-level - token routines and data. - The actual implementation derives from one of the *lang.l files. + The abstract module 'lang' declares the names that provide access to + the lowest-level token routines and data. + The corresponding definitions must be provided by the *lang.l file. - There is a dummy implementation lang.c. + There is a dummy implementation lang.c, to satisfy the module + consistency checker check-ch. */ extern FILE *yyin; diff --git a/judger/core/sim/sim_2_77/language.c b/judger/core/sim/sim_3_01/language.c old mode 100755 new mode 100644 similarity index 68% rename from judger/core/sim/sim_2_77/language.c rename to judger/core/sim/sim_3_01/language.c index efbe698d..6559e46b --- a/judger/core/sim/sim_2_77/language.c +++ b/judger/core/sim/sim_3_01/language.c @@ -1,11 +1,13 @@ /* This file is part of the software similarity tester SIM. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: language.c,v 2.3 2013-04-28 16:30:41 Gebruiker Exp $ + $Id: language.c,v 2.4 2016-08-05 15:31:19 dick Exp $ */ /* - This is a dummy implementation of the abstract class 'language'. - The actual implementation is provided by one of the *lang.l files. + This is a dummy implementation of the abstract class 'language', so + there will not be a language.o file. + The actual implementation is provided by Xlang.o deriving through + Xlang.c from the pertinent Xlang.l file. */ #include @@ -14,6 +16,8 @@ #include "token.h" #include "language.h" +const char *Subject; + void Init_Language(void) { abort(); diff --git a/judger/core/sim/sim_2_77/language.h b/judger/core/sim/sim_3_01/language.h old mode 100755 new mode 100644 similarity index 55% rename from judger/core/sim/sim_2_77/language.h rename to judger/core/sim/sim_3_01/language.h index b95616f6..065a8488 --- a/judger/core/sim/sim_2_77/language.h +++ b/judger/core/sim/sim_3_01/language.h @@ -1,6 +1,6 @@ /* This file is part of the software similarity tester SIM. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: language.h,v 1.8 2013-04-28 16:30:41 Gebruiker Exp $ + $Id: language.h,v 1.9 2016-04-27 19:09:48 dick Exp $ */ /* @@ -11,15 +11,16 @@ */ /* - The abstract class 'language' defines the routines Init_Language(), - May_Be_Start_Of_Run() and Best_Run_Size(), which describe some - properties of the language. - These routines are provided by the *lang.l files. + The abstract class 'language' declares the names that give access to + the properties of the language. + The corresponding definitions must be provided by the *lang.l file. - There is a dummy implementation language.c. + There is a dummy implementation language.c, to satisfy the module + consistency checker check-ch. */ +extern const char *Subject; extern void Init_Language(void); extern int May_Be_Start_Of_Run(Token ch); extern size_t Best_Run_Size(const Token *str, size_t size); diff --git a/judger/core/sim/sim_2_77/lex.c b/judger/core/sim/sim_3_01/lex.c old mode 100755 new mode 100644 similarity index 79% rename from judger/core/sim/sim_2_77/lex.c rename to judger/core/sim/sim_3_01/lex.c index f53acca5..e5050462 --- a/judger/core/sim/sim_2_77/lex.c +++ b/judger/core/sim/sim_3_01/lex.c @@ -1,6 +1,6 @@ /* This file is part of the software similarity tester SIM. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: lex.c,v 1.9 2012-06-08 16:04:28 Gebruiker Exp $ + $Id: lex.c,v 1.9 2012-06-08 16:04:28 dick Exp $ */ /* The service macros for the *lang.l files do not require code */ diff --git a/judger/core/sim/sim_2_77/lex.h b/judger/core/sim/sim_3_01/lex.h old mode 100755 new mode 100644 similarity index 87% rename from judger/core/sim/sim_2_77/lex.h rename to judger/core/sim/sim_3_01/lex.h index c986f56a..035f6692 --- a/judger/core/sim/sim_2_77/lex.h +++ b/judger/core/sim/sim_3_01/lex.h @@ -1,6 +1,6 @@ /* This file is part of the software similarity tester SIM. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: lex.h,v 2.12 2012-09-30 11:55:19 Gebruiker Exp $ + $Id: lex.h,v 2.12 2012-09-30 11:55:19 dick Exp $ */ /* Macros for the *lang.l files */ diff --git a/judger/core/sim/sim_2_77/lisplang.l b/judger/core/sim/sim_3_01/lisplang.l old mode 100755 new mode 100644 similarity index 92% rename from judger/core/sim/sim_2_77/lisplang.l rename to judger/core/sim/sim_3_01/lisplang.l index b487f14f..f466d739 --- a/judger/core/sim/sim_2_77/lisplang.l +++ b/judger/core/sim/sim_3_01/lisplang.l @@ -1,7 +1,7 @@ %{ /* This file is part of the software similarity tester SIM. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: lisplang.l,v 2.17 2013-04-28 16:30:41 Gebruiker Exp $ + $Id: lisplang.l,v 2.19 2017-03-19 09:23:19 dick Exp $ */ /* @@ -69,6 +69,8 @@ const Token Closers[] = { /* Language-dependent code */ +const char *Subject = "Lisp programs"; + void Init_Language(void) { Init_Algol_Language(Non_Finals, Non_Initials, Openers, Closers); @@ -92,11 +94,11 @@ Best_Run_Size(const Token *str, size_t size) { %Start Comment Layout ([ \t\r\f]) -ASCII95 ([- !"#$%&'()*+,./0-9:;<=>?@A-Z\[\\\]^_`a-z{|}~]) +ASCII95 ([\040-\176]) AnyQuoted (\\.) -StrChar ([^"\n\\]|{AnyQuoted}) -ChrChar ([^'\\]|{AnyQuoted}) +StrChar ([^\"\n\\]|{AnyQuoted}) +ChrChar ([^\'\\]|{AnyQuoted}) IdfChar ([-!#$%&*+,/0-9:;<=>?@A-Z\\^_`a-z{}~]) diff --git a/judger/core/sim/sim_2_77/m2lang.l b/judger/core/sim/sim_3_01/m2lang.l old mode 100755 new mode 100644 similarity index 97% rename from judger/core/sim/sim_2_77/m2lang.l rename to judger/core/sim/sim_3_01/m2lang.l index 03eb1e1b..aaef484d --- a/judger/core/sim/sim_2_77/m2lang.l +++ b/judger/core/sim/sim_3_01/m2lang.l @@ -1,7 +1,7 @@ %{ /* This file is part of the software similarity tester SIM. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: m2lang.l,v 2.19 2013-04-28 16:30:41 Gebruiker Exp $ + $Id: m2lang.l,v 2.21 2017-03-19 09:23:19 dick Exp $ */ /* @@ -207,6 +207,8 @@ const Token Closers[] = { /* Language-dependent code */ +const char *Subject = "Modula-2 programs"; + void Init_Language(void) { Init_Algol_Language(Non_Finals, Non_Initials, Openers, Closers); @@ -230,11 +232,11 @@ Best_Run_Size(const Token *str, size_t size) { %Start Comment Layout ([ \t\r\f]) -ASCII95 ([- !"#$%&'()*+,./0-9:;<=>?@A-Z\[\\\]^_`a-z{|}~]) +ASCII95 ([\040-\176]) AnyQuoted (\\.) -QuStrChar ([^"\n\\]|{AnyQuoted}) -ApoStrChar ([^'\n\\]|{AnyQuoted}) +QuStrChar ([^\"\n\\]|{AnyQuoted}) +ApoStrChar ([^\'\n\\]|{AnyQuoted}) StartComment ("(*") EndComment ("*)") diff --git a/judger/core/sim/sim_2_77/miralang.l b/judger/core/sim/sim_3_01/miralang.l old mode 100755 new mode 100644 similarity index 91% rename from judger/core/sim/sim_2_77/miralang.l rename to judger/core/sim/sim_3_01/miralang.l index 524fd836..b92d5a5b --- a/judger/core/sim/sim_2_77/miralang.l +++ b/judger/core/sim/sim_3_01/miralang.l @@ -1,7 +1,7 @@ %{ /* This file is part of the software similarity tester SIM. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: miralang.l,v 1.11 2013-04-28 16:30:41 Gebruiker Exp $ + $Id: miralang.l,v 1.13 2017-03-19 09:23:20 dick Exp $ */ /* @@ -71,6 +71,8 @@ const Token Closers[] = { /* Language-dependent code */ +const char *Subject = "Miranda programs"; + void Init_Language(void) { Init_Algol_Language(Non_Finals, Non_Initials, Openers, Closers); @@ -94,13 +96,13 @@ Best_Run_Size(const Token *str, size_t size) { %Start Comment Layout ([ \t\r\f]) -ASCII95 ([- !"#$%&'()*+,./0-9:;<=>?@A-Z\[\\\]^_`a-z{|}~]) +ASCII95 ([\040-\176]) AnyQuoted (\\.) -StrChar ([^"\n\\]|{AnyQuoted}) -ChrChar ([^'\\]|{AnyQuoted}) +StrChar ([^\"\n\\]|{AnyQuoted}) +ChrChar ([^\'\\]|{AnyQuoted}) -Idf ([A-Za-z][A-Za-z0-9_']*) +Idf ([A-Za-z][A-Za-z0-9_\']*) %% diff --git a/judger/core/sim/sim_2_77/newargs.c b/judger/core/sim/sim_3_01/newargs.c old mode 100755 new mode 100644 similarity index 96% rename from judger/core/sim/sim_2_77/newargs.c rename to judger/core/sim/sim_3_01/newargs.c index 87d5eba0..566c9d31 --- a/judger/core/sim/sim_2_77/newargs.c +++ b/judger/core/sim/sim_3_01/newargs.c @@ -1,6 +1,6 @@ /* This file is part of the software similarity tester SIM. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: newargs.c,v 2.9 2013-04-28 16:30:41 Gebruiker Exp $ + $Id: newargs.c,v 2.11 2016-05-13 19:00:52 dick Exp $ */ #include @@ -8,7 +8,6 @@ #include "sim.h" #include "ForEachFile.h" #include "Malloc.h" -#include "error.h" #include "newargs.h" #define ARGS_INCR 1024 @@ -118,11 +117,11 @@ get_new_std_input_args(int *argcp, const char **argvp[]) { *argcp = argc, *argvp = argv; } -static void +static int register_file(const Fchar *fn, const char *msg, const struct stat *fs) { if (msg) { fprintf(stderr, "could not handle file %s: %s\n", fn, msg); - return; + return 0; } if ( /* it is a non-empty regular file */ @@ -130,6 +129,7 @@ register_file(const Fchar *fn, const char *msg, const struct stat *fs) { ) { add_string_to_args(fn); } + return 1; } static char * diff --git a/judger/core/sim/sim_2_77/newargs.h b/judger/core/sim/sim_3_01/newargs.h old mode 100755 new mode 100644 similarity index 81% rename from judger/core/sim/sim_2_77/newargs.h rename to judger/core/sim/sim_3_01/newargs.h index 917c2779..1cf944c5 --- a/judger/core/sim/sim_2_77/newargs.h +++ b/judger/core/sim/sim_3_01/newargs.h @@ -1,6 +1,6 @@ /* This file is part of the software similarity tester SIM. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: newargs.h,v 2.4 2012-05-16 07:56:06 Gebruiker Exp $ + $Id: newargs.h,v 2.4 2012-05-16 07:56:06 dick Exp $ */ extern void get_new_std_input_args(int *argcp, char const **argvp[]); diff --git a/judger/core/sim/sim_2_77/option-i.inp b/judger/core/sim/sim_3_01/option-i.inp old mode 100755 new mode 100644 similarity index 100% rename from judger/core/sim/sim_2_77/option-i.inp rename to judger/core/sim/sim_3_01/option-i.inp diff --git a/judger/core/sim/sim_3_01/options.c b/judger/core/sim/sim_3_01/options.c new file mode 100644 index 00000000..6e27c119 --- /dev/null +++ b/judger/core/sim/sim_3_01/options.c @@ -0,0 +1,214 @@ +/* This file is part of the software similarity tester SIM. + Written by Dick Grune, Vrije Universiteit, Amsterdam. + $Id: options.c,v 1.20 2017-03-19 09:30:37 dick Exp $ +*/ + +#include +#include + +#include "sim.h" +#include "token.h" +#include "language.h" +#include "options.h" + +static char options[128]; + +static void bad_option_exit( + const char *progname, const struct option *optlist, + char *msg, int c +); +static int opt_value( + const char *progname, const struct option *op, + const char *arg, const char *argv[] +); + +static int do_arg( + const char *progname, const struct option *optlist, + const char *arg, const char *argv[] +); + +int +do_options( + const char *progname, const struct option *optlist, + int argc, const char *argv[] +) { + int skips = 0; + + while (argc > 0 && argv[0][0] == '-') { + int consumed = do_arg(progname, optlist, &argv[0][1], argv); + + argc -= consumed, argv += consumed, skips += consumed; + } + + return skips; +} + +void +set_option(char ch) { + options[(int)ch]++; +} + +int +is_set_option(int ch) { + return options[ch]; +} + +static int +do_arg( + const char *progname, const struct option *optlist, + const char *arg, const char *argv[] +) { + int consumed = 0; + + while (*arg) { + /* treat argument character */ + char opc = *arg++; + const struct option *op; + + for (op = optlist; op->op_char; op++) { + if (opc == op->op_char) { + set_option(opc); + if (op->op_type != None) { + consumed = opt_value( + progname, op, arg, argv + ); + } + break; + } + } + if (!op->op_char) { + bad_option_exit(progname, optlist, + "option -%c unknown", opc + ); + /*NOTREACHED*/ + } + if (consumed) break; + } + if (!consumed) { + consumed = 1; + } + + return consumed; +} + +static int +opt_value( + const char *progname, const struct option *op, + const char *arg, const char *argv[] +) { + /* get the string and the number of args consumed */ + const char *string; + int consumed; + if (*arg) { + string = arg, consumed = 1; + } + else if (argv[1]) { + string = argv[1], consumed = 2; + } else { + string = 0, consumed = 0; + } + if (!string || !*string) { + bad_option_exit(progname, (struct option *)0, + "option -%c requires another argument", op->op_char + ); + /*NOTREACHED*/ + } + + switch (op->op_type) { + case Number: + *(int *)op->op_value = atoi(string); + break; + case String: + *(const char **)op->op_value = string; + break; + } + + return consumed; +} + +void +allow_at_most_one_option_out_of(const char *opts) { + const char *first; + for (first = opts; *first; first++) { + const char *second; + for (second = first + 1; *second; second++) { + if (is_set_option(*first) &&is_set_option(*second)) { + char msg[256]; + sprintf(msg, + "options -%c and -%c are incompatible", + *first, *second + ); + fatal(msg); + } + } + } +} + +static void +bad_option_exit( + const char *progname, const struct option *optlist, char *msg, int c +) { + fprintf(stderr, "%s: ", progname); + fprintf(stderr, msg, c); + fprintf(stderr, "\n"); + + fprintf(stderr, "Possible options are:\n"); + const struct option *op; + for (op = optlist; op->op_char; op++) { + if (op->op_char == ' ') { + fprintf(stderr, "\n\t\t%s\n", op->op_text); + } else { + fprintf(stderr, "\t-%c%c\t%s\n", + op->op_char, + ( op->op_type == Number ? 'N' : + op->op_type == String ? 'F' : + ' ' + ), + op->op_text + ); + } + } + exit(1); +} + +static int +is_essential_option(char op_char) { + if (op_char == 'r') return 1; + if (op_char == 'w') return 1; + if (is_set_option('p') && op_char == 't') return 1; + return 0; +} + +void +print_options(const char *progname, const struct option *optlist) { + const struct option *op; + + if (!is_set_option('T')) { + fprintf(stdout, "%s (%s)\n", progname, Version); + fprintf(stdout, "Subject: %s\n", Subject); + } + fprintf(stdout, "Option settings:"); + if (!is_set_option('T')) fprintf(stdout, "\n"); + for (op = optlist; op->op_char; op++) { + if ( is_set_option(op->op_char) + || is_essential_option(op->op_char) + ) { + fprintf(stdout, " -%c", op->op_char); + switch (op->op_type) { + case None: break; + case Number: + fprintf(stdout, "%d", + *(int *)op->op_value); + break; + case String: + fprintf(stdout, " %s", + *(const char **)op->op_value); + break; + } + if (!is_set_option('T')) { + fprintf(stdout, " (%s)\n", op->op_text); + } + } + } + if (is_set_option('T')) fprintf(stdout, "\n"); +} diff --git a/judger/core/sim/sim_2_77/options.h b/judger/core/sim/sim_3_01/options.h old mode 100755 new mode 100644 similarity index 55% rename from judger/core/sim/sim_2_77/options.h rename to judger/core/sim/sim_3_01/options.h index 83af25f9..5fb6f637 --- a/judger/core/sim/sim_2_77/options.h +++ b/judger/core/sim/sim_3_01/options.h @@ -1,16 +1,17 @@ /* This file is part of the software similarity tester SIM. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: options.h,v 1.8 2012-05-13 09:05:49 Gebruiker Exp $ + $Id: options.h,v 1.12 2016-06-12 13:00:04 dick Exp $ */ /* Setting and consulting command line options */ +enum Value_Type {None, Number, String}; struct option { char op_char; /* char as in call */ - char *op_text; /* explanatory text */ - char op_indicator; /* type indicator, N = int, F = file name */ - const char **op_stringp;/* string value to be picked up */ + char *op_text; /* explanatory text */ + enum Value_Type op_type; + void *op_value; }; extern void set_option(char ch); @@ -19,3 +20,5 @@ extern int do_options( const char *progname, const struct option *optlist, int argc, const char *argv[] ); +extern void allow_at_most_one_option_out_of(const char *opts); +extern void print_options(const char *progname, const struct option *optlist); diff --git a/judger/core/sim/sim_2_77/pascallang.l b/judger/core/sim/sim_3_01/pascallang.l old mode 100755 new mode 100644 similarity index 92% rename from judger/core/sim/sim_2_77/pascallang.l rename to judger/core/sim/sim_3_01/pascallang.l index d1384f0c..7ca32a02 --- a/judger/core/sim/sim_2_77/pascallang.l +++ b/judger/core/sim/sim_3_01/pascallang.l @@ -1,7 +1,7 @@ %{ /* This file is part of the software similarity tester SIM. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: pascallang.l,v 2.19 2013-04-28 16:30:42 Gebruiker Exp $ + $Id: pascallang.l,v 2.22 2017-03-19 09:23:20 dick Exp $ */ /* @@ -81,25 +81,11 @@ static const struct idf reserved[] = { /* Special treatment of identifiers */ -static void -lower_case(char *str) { - /* Turns upper case into lower case, since Pascal does not - distinguish between them. - */ - char *s; - - for (s = str; *s; s++) { - if ('A' <= *s && *s <= 'Z') { - *s += (-'A' + 'a'); - } - } -} - static Token idf2token(int hashing) { Token tk; - lower_case(yytext); + lower_case(yytext); /* Pascal is case-insensitive */ tk = idf_in_list(yytext, reserved, sizeof reserved, IDF); if (Token_EQ(tk, IDF) && hashing) { /* return a one-Token hash code */ @@ -156,6 +142,8 @@ const Token Closers[] = { /* Language-dependent code */ +const char *Subject = "Pascal programs"; + void Init_Language(void) { Init_Algol_Language(Non_Finals, Non_Initials, Openers, Closers); @@ -179,10 +167,10 @@ Best_Run_Size(const Token *str, size_t size) { %Start Comment Layout ([ \t\r\f]) -ASCII95 ([- !"#$%&'()*+,./0-9:;<=>?@A-Z\[\\\]^_`a-z{|}~]) +ASCII95 ([\040-\176]) AnyQuoted (\\.) -StrChar ([^'\n\\]|{AnyQuoted}) +StrChar ([^\'\n\\]|{AnyQuoted}) StartComment ("{"|"(*") EndComment ("}"|"*)") diff --git a/judger/core/sim/sim_2_77/pass1.c b/judger/core/sim/sim_3_01/pass1.c old mode 100755 new mode 100644 similarity index 57% rename from judger/core/sim/sim_2_77/pass1.c rename to judger/core/sim/sim_3_01/pass1.c index 6d14caa8..4f063d07 --- a/judger/core/sim/sim_2_77/pass1.c +++ b/judger/core/sim/sim_3_01/pass1.c @@ -1,6 +1,6 @@ /* This file is part of the software similarity tester SIM. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: pass1.c,v 2.24 2014-01-26 21:52:59 Gebruiker Exp $ + $Id: pass1.c,v 2.35 2016-07-29 12:50:02 dick Exp $ */ #include @@ -12,7 +12,6 @@ #include "token.h" #include "tokenarray.h" #include "lang.h" -#include "error.h" #include "options.h" #include "pass1.h" @@ -23,60 +22,82 @@ static void db_print_text(const struct text *); static void fprint_count(FILE *f, size_t cnt, const char *); void -Read_Input_Files(int argc, const char *argv[], int round) { +Read_Input_Files(int argc, const char *argv[]) { int n; Init_Text(argc); Init_Token_Array(); - /* Assume all texts to be new */ - Number_Of_New_Texts = Number_Of_Texts; + /* Initially assume all texts to be new */ + Number_of_New_Texts = Number_of_Texts; /* Read the files */ - for (n = 0; n < Number_Of_Texts; n++) { + for (n = 0; n < Number_of_Texts; n++) { const char *fname = argv[n]; struct text *txt = &Text[n]; - if (round == 1 && !is_set_option('T')) { + if (!is_set_option('T')) { fprintf(Output_File, "File %s: ", fname); } txt->tx_fname = fname; txt->tx_pos = 0; - txt->tx_start = - txt->tx_limit = Text_Length(); + txt->tx_start = Token_Array_Length(); + txt->tx_limit = Token_Array_Length(); + if (is_new_old_separator(fname)) { - if (round == 1 && !is_set_option('T')) { - fprintf(Output_File, "separator\n"); + if (!is_set_option('T')) { + fprintf(Output_File, "new/old separator\n"); } - Number_Of_New_Texts = n; + if (Number_of_New_Texts == Number_of_Texts) { + Number_of_New_Texts = n; + } else fatal("more than one new/old separator"); } else { - if (!Open_Text(First, txt)) { - if (round == 1 && !is_set_option('T')) { - fprintf(Output_File, - ">>>> cannot open <<<< "); + int file_opened = 0; + if (Open_Text(First_Pass, txt)) { + file_opened = 1; + } else { + /* print a warning */ + if (is_set_option('T')) { + /* the file name has not yet been + printed; print it now + */ + fprintf(Output_File, "File %s: ", + fname); } + fprintf(Output_File, + ">>>> cannot open <<<<\n"); /* the file has still been opened with a null file for uniformity */ } - while (Next_Text_Token_Obtained(First)) { + while (Next_Text_Token_Obtained()) { if (!Token_EQ(lex_token, End_Of_Line)) { Store_Token(lex_token); } } - Close_Text(First, txt); - txt->tx_limit = Text_Length(); + Close_Text(First_Pass, txt); + txt->tx_limit = Token_Array_Length(); + txt->tx_EOL_terminated = + Token_EQ(lex_token, End_Of_Line); /* report */ - if (round == 1 && !is_set_option('T')) { + if (file_opened && !is_set_option('T')) { fprint_count(Output_File, txt->tx_limit - txt->tx_start, - token_name + Token_Name ); fprintf(Output_File, ", "); - fprint_count(Output_File, lex_nl_cnt-1, "line"); + fprint_count(Output_File, + lex_nl_cnt - 1 + + (!txt->tx_EOL_terminated ? 1 : 0), + "line" + ); + if (!txt->tx_EOL_terminated) { + fprintf(Output_File, + " (not NL-terminated)"); + } if (lex_non_ascii_cnt) { fprintf(Output_File, ", "); fprint_count(Output_File, @@ -95,12 +116,19 @@ Read_Input_Files(int argc, const char *argv[], int round) { } /* report total */ - if (round == 1 && !is_set_option('T')) { - fprintf(Output_File, "Total: "); - fprint_count(Output_File, Text_Length() - 1, token_name); - fprintf(Output_File, "\n\n"); - fflush(Output_File); - } + int sep_present = (Number_of_Texts != Number_of_New_Texts); + fprintf(Output_File, "Total input: "); + fprint_count(Output_File, + (!sep_present ? Number_of_Texts : Number_of_Texts - 1), + "file" + ); + fprintf(Output_File, " (%d new, %d old), ", + Number_of_New_Texts, + (!sep_present ? 0 : Number_of_Texts - Number_of_New_Texts - 1) + ); + fprint_count(Output_File, Token_Array_Length() - 1, Token_Name); + fprintf(Output_File, "\n\n"); + fflush(Output_File); } static void @@ -123,7 +151,7 @@ db_print_text(const struct text *txt) { fprintf(Debug_File, "File \"%s\", %s %ss, ", txt->tx_fname, size_t2string(txt->tx_limit - txt->tx_start), - token_name + Token_Name ); fprintf(Debug_File, "txt->tx_start = %s, txt->tx_limit = %s\n", size_t2string(txt->tx_start), diff --git a/judger/core/sim/sim_2_77/pass1.h b/judger/core/sim/sim_3_01/pass1.h old mode 100755 new mode 100644 similarity index 65% rename from judger/core/sim/sim_2_77/pass1.h rename to judger/core/sim/sim_3_01/pass1.h index 385a91fe..07acb4b5 --- a/judger/core/sim/sim_2_77/pass1.h +++ b/judger/core/sim/sim_3_01/pass1.h @@ -1,9 +1,9 @@ /* This file is part of the software similarity tester SIM. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: pass1.h,v 1.7 2012-05-16 07:56:06 Gebruiker Exp $ + $Id: pass1.h,v 1.8 2015-05-04 19:49:11 dick Exp $ */ /* Reads the input files; stores the tokens in Token Token_Array[] and the input file descriptions in struct text text[]. */ -extern void Read_Input_Files(int argc, const char *argv[], int round); +extern void Read_Input_Files(int argc, const char *argv[]); diff --git a/judger/core/sim/sim_2_77/pass2.c b/judger/core/sim/sim_3_01/pass2.c old mode 100755 new mode 100644 similarity index 84% rename from judger/core/sim/sim_2_77/pass2.c rename to judger/core/sim/sim_3_01/pass2.c index c54134de..8c6fe878 --- a/judger/core/sim/sim_2_77/pass2.c +++ b/judger/core/sim/sim_3_01/pass2.c @@ -1,6 +1,6 @@ /* This file is part of the software similarity tester SIM. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: pass2.c,v 2.21 2013-04-28 16:30:42 Gebruiker Exp $ + $Id: pass2.c,v 2.24 2016-05-13 19:00:53 dick Exp $ */ #include @@ -12,20 +12,18 @@ #include "lang.h" #include "pass2.h" -#undef DB_POS #ifdef DB_POS static void db_print_pos_list(const char *, const struct text *); static void db_print_lex(const char *); #endif static void pass2_txt(struct text *txt); -static int next_eol_obtained(void); void Retrieve_Runs(void) { int n; - for (n = 0; n < Number_Of_Texts; n++) { + for (n = 0; n < Number_of_Texts; n++) { pass2_txt(&Text[n]); } } @@ -47,7 +45,7 @@ pass2_txt(struct text *txt) { return; /* Open_Text() initializes lex_nl_cnt and lex_tk_cnt */ - if (!Open_Text(Second, txt)) { + if (!Open_Text(Second_Pass, txt)) { fprintf(stderr, ">>>> File %s disappeared <<<<\n", txt->tx_fname ); @@ -82,17 +80,22 @@ pass2_txt(struct text *txt) { /* we scan the pos list and the file in parallel */ /* find the corresponding line */ - while (pos->ps_tk_cnt >= lex_tk_cnt) { /* was >= ZZ */ + while (pos->ps_tk_cnt >= lex_tk_cnt) { /* pos does not refer to this line, try the next */ /* shift the administration */ old_nl_cnt = lex_nl_cnt; /* and get the next eol position */ - if (!next_eol_obtained()) { - /* ouch! not enough lines! */ - fprintf(stderr, ">>>> File %s modified <<<<\n", - txt->tx_fname - ); + if (!Next_Text_EOL_Obtained()) { + /* reached end of file without obtaining EOL */ + if (!txt->tx_EOL_terminated) { + /* that's OK then */ + } else { + fprintf(stderr, + ">>>> File %s modified <<<<\n", + txt->tx_fname + ); + } break; } #ifdef DB_POS @@ -118,17 +121,9 @@ pass2_txt(struct text *txt) { #endif /* DB_POS */ /* Flush the flex buffers; it's easier than using YY_BUFFER_STATE. */ - while (Next_Text_Token_Obtained(Second)); + while (Next_Text_EOL_Obtained()); - Close_Text(Second, txt); -} - -static int -next_eol_obtained(void) { - while (Next_Text_Token_Obtained(Second)) { - if (Token_EQ(lex_token, End_Of_Line)) return 1; - } - return 0; + Close_Text(Second_Pass, txt); } #ifdef DB_POS @@ -137,7 +132,7 @@ static void db_print_pos(const struct position *pos) { fprintf(Debug_File, "pos type = %s; %s count = %u", (pos->ps_type == 0 ? "first" : " last"), - token_name, + Token_Name, pos->ps_tk_cnt ); fprintf(Debug_File, ", line # = "); diff --git a/judger/core/sim/sim_2_77/pass2.h b/judger/core/sim/sim_3_01/pass2.h old mode 100755 new mode 100644 similarity index 81% rename from judger/core/sim/sim_2_77/pass2.h rename to judger/core/sim/sim_3_01/pass2.h index 3a737add..30415e9c --- a/judger/core/sim/sim_2_77/pass2.h +++ b/judger/core/sim/sim_3_01/pass2.h @@ -1,6 +1,6 @@ /* This file is part of the software similarity tester SIM. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: pass2.h,v 1.3 2012-06-05 09:58:53 Gebruiker Exp $ + $Id: pass2.h,v 1.3 2012-06-05 09:58:53 dick Exp $ */ /* Determines for each position that is part of a run, at which diff --git a/judger/core/sim/sim_2_77/pass3.c b/judger/core/sim/sim_3_01/pass3.c old mode 100755 new mode 100644 similarity index 58% rename from judger/core/sim/sim_2_77/pass3.c rename to judger/core/sim/sim_3_01/pass3.c index 258d65c5..30d10a47 --- a/judger/core/sim/sim_2_77/pass3.c +++ b/judger/core/sim/sim_3_01/pass3.c @@ -1,19 +1,18 @@ /* This file is part of the software similarity tester SIM. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: pass3.c,v 2.22 2014-01-26 21:52:59 Gebruiker Exp $ + $Id: pass3.c,v 2.31 2016-07-31 18:55:44 dick Exp $ */ #include #include #include "system.par" +#include "settings.par" #include "debug.par" #include "sim.h" #include "text.h" #include "token.h" #include "runs.h" -#include "Malloc.h" -#include "error.h" #include "options.h" #include "pass3.h" #include "percentages.h" @@ -23,49 +22,60 @@ static void db_run(const struct run *); #endif +/* Positioning of UTF-8 characters must be done with a finer grain than just + 10 Courier characters to the inch. On the other hand we do not know the + exact width of each UNICODE character, so whatever we do is an approximation. + We use a granularity of 1 pt and a font size of 10 pts. + + Since C does not have type-checked integer subtypes, we put the the fact + that they handle UTF-8 chars in the variable and routine names to avoid + errors. +*/ +typedef int pts; +#define FONT_SIZE (10) + static FILE *open_chunk(const struct chunk *); -static void fill_line(FILE *, char []); -static void clear_line(char []); +static void print_char(char); +static void print_spaces(int); +static pts print_UTF8_line(FILE *); +static pts print_UTF8_char(int ch, FILE *); +static void print_UTF8_spaces(pts); static void show_run(const struct run *); -static void show_2C_line(const char [], const char []); static void show_1C_line(FILE *, const char *); -static int pr_head(const struct chunk *); -static int prs(const char *); -static int pru(size_t); -static int unslen(size_t); +static int print_header(const struct chunk *); +static int print_string(const char *); +static int print_size_t(size_t); +static int length_size_t(size_t); static int max_line_length; /* Actual maximum line length */ -static char *line0; /* by Malloc() */ -static char *line1; +static pts max_line_length_UTF8; void Show_Runs(void) { - AisoIter iter; - struct run *run; - #ifdef DB_RUN fprintf(Debug_File, "Starting Show_Runs()\n"); #endif /* DB_RUN */ - max_line_length = Page_Width / 2 - 2; - line0 = Malloc((size_t)(max_line_length + 1) * sizeof (char)); - line1 = Malloc((size_t)(max_line_length + 1) * sizeof (char)); + const struct run *run = /*ZZ*/ + (is_set_option('u') ? unsorted_runs() : sorted_runs()); - OpenIter(&iter); - while (GetAisoItem(&iter, &run)) { + while (run) { #ifdef DB_RUN db_run(run); #endif /* DB_RUN */ show_run(run); - fprintf(Output_File, "\n"); + print_char('\n'); + fflush(Output_File); + run = run->rn_next; } - CloseIter(&iter); - Free(line0); line0 = 0; - Free(line1); line1 = 0; + discard_runs(); } static void show_run(const struct run *run) { + max_line_length = Page_Width / 2 - 1; + max_line_length_UTF8 = max_line_length * FONT_SIZE; + /* The animals came in two by two ... */ const struct chunk *cnk0 = &run->rn_chunk0; const struct chunk *cnk1 = &run->rn_chunk1; @@ -78,24 +88,19 @@ show_run(const struct run *run) { if (!is_set_option('d')) { /* no assumptions about the lengths of the file names! */ size_t size = run->rn_size; - int pos = 0; - - pos += pr_head(cnk0); - while (pos < max_line_length + 1) { - pos += prs(" "); - } - pos += prs("|"); - pos += pr_head(cnk1); - while (pos < 2*max_line_length - unslen(size)) { - pos += prs(" "); - } + int pos = print_header(cnk0); + print_spaces(max_line_length - pos); + print_char('|'); + pos = print_header(cnk1); + print_spaces(max_line_length - pos - length_size_t(size) - 2); fprintf(Output_File, "[%s]\n", size_t2string(size)); } else { - (void)pr_head(cnk0); - fprintf(Output_File, "\n"); - (void)pr_head(cnk1); - fprintf(Output_File, "\n"); + /* diff-like format */ + (void)print_header(cnk0); + print_char('\n'); + (void)print_header(cnk1); + print_char('\n'); } /* stop if that suffices */ @@ -108,31 +113,28 @@ show_run(const struct run *run) { /* display the chunks in the required format */ if (!is_set_option('d')) { - /* fill 2-column lines and print them */ + /* print 2-column format */ while (nl_cnt0 != 0 || nl_cnt1 != 0) { + int pos_UTF8 = 0; if (nl_cnt0) { - fill_line(f0, line0); + pos_UTF8 = print_UTF8_line(f0); nl_cnt0--; } - else { - clear_line(line0); - } + print_UTF8_spaces(max_line_length_UTF8 - pos_UTF8); + print_char('|'); if (nl_cnt1) { - fill_line(f1, line1); + (void)print_UTF8_line(f1); nl_cnt1--; } - else { - clear_line(line1); - } - show_2C_line(line0, line1); + print_char('\n'); } } else { - /* display the lines in a diff(1)-like format */ + /* display the chunks in a diff(1)-like format */ while (nl_cnt0--) { show_1C_line(f0, "<"); } - fprintf(Output_File, "---\n"); + (void)print_string("---\n"); while (nl_cnt1--) { show_1C_line(f1, ">"); } @@ -144,31 +146,31 @@ show_run(const struct run *run) { } static int -pr_head(const struct chunk *cnk) { +print_header(const struct chunk *cnk) { int pos = 0; - pos += prs(cnk->ch_text->tx_fname); - pos += prs(": line "); - pos += pru(cnk->ch_first.ps_nl_cnt); - pos += prs("-"); - pos += pru(cnk->ch_last.ps_nl_cnt - 1); + pos += print_string(cnk->ch_text->tx_fname); + pos += print_string(": line "); + pos += print_size_t(cnk->ch_first.ps_nl_cnt); + pos += print_string("-"); + pos += print_size_t(cnk->ch_last.ps_nl_cnt - 1); return pos; } static int -prs(const char *str) { +print_string(const char *str) { fprintf(Output_File, "%s", str); return (int) strlen(str); } static int -pru(size_t u) { +print_size_t(size_t u) { fprintf(Output_File, "%s", size_t2string(u)); - return unslen(u); + return length_size_t(u); } static int -unslen(size_t u) { +length_size_t(size_t u) { int res = 1; while (u > 9) { @@ -206,14 +208,13 @@ open_chunk(const struct chunk *cnk) { return f; } -static void -fill_line(FILE *f, char ln[]) { - /* Reads one line from f and puts it in condensed form in ln. - */ - int indent = 0, lpos = 0; +static pts +print_UTF8_line(FILE *f) { + /* Reads one line from f and prints it in condensed form. */ + int indent = 0, pos_UTF8 = 0; int ch; - /* condense and skip initial blank */ + /* condense initial blanks */ while ((ch = getc(f)), ch == ' ' || ch == '\t') { if (ch == '\t') { indent = 8; @@ -223,52 +224,66 @@ fill_line(FILE *f, char ln[]) { } if (indent == 8) { /* every eight blanks give one blank */ - if (lpos < max_line_length) { - ln[lpos++] = ' '; + if (pos_UTF8 < max_line_length_UTF8) { + pos_UTF8 += print_UTF8_char(' ', 0); } indent = 0; } } - /* store the rest */ + /* print the rest */ while (ch >= 0 && ch != '\n') { if (ch == '\t') { /* replace tabs by blanks */ ch = ' '; } - if (lpos < max_line_length) { - ln[lpos++] = (char) ch; + if (pos_UTF8 < max_line_length_UTF8) { + pos_UTF8 += print_UTF8_char(ch, f); } ch = getc(f); } - ln[lpos] = '\0'; /* always room for this one */ + return pos_UTF8; } static void -clear_line(char ln[]) { - /* a simple null byte will suffice */ - ln[0] = '\0'; +print_char(char ch) { + fprintf(Output_File, "%c", ch); } static void -show_2C_line(const char ln0[], const char ln1[]) { - /* displays the contents of the two lines in a two-column - format - */ - int i; - - for (i = 0; i < max_line_length && ln0[i] != '\0'; i++) { - fputc(ln0[i], Output_File); +print_spaces(int n) { + while (n > 0) { + print_char(' '), --n; } - for (; i < max_line_length; i++) { - fputc(' ', Output_File); +} + +static pts +print_UTF8_char(int ch, FILE *f) { + int pos_UTF8 = FONT_SIZE; + fprintf(Output_File, "%c", ch); + if (ch < 192) return pos_UTF8; + + while (ch & 0x40) { + int ch1 = getc(f); + fprintf(Output_File, "%c", ch1); + if ((ch1 & 0xC0) != 0x80) { + /* bad UTF-8 */ + return pos_UTF8; /* no recovery */ + } + pos_UTF8 += 4; + /* ^ Stupid heuristic: the longer the UTF sequence, the bigger + the character. Rough, but the best we can reasonably do. + */ + ch <<= 1; } - fprintf(Output_File, " |"); + return pos_UTF8; +} - for (i = 0; i < max_line_length && ln1[i] != '\0'; i++) { - fputc(ln1[i], Output_File); +static void +print_UTF8_spaces(pts n) { + while (n > 0) { + print_char(' '), n -= FONT_SIZE; } - fprintf(Output_File, "\n"); } static void @@ -277,11 +292,11 @@ show_1C_line(FILE *f, const char *marker) { */ int ch; - fprintf(Output_File, "%s", marker); + fprintf(Output_File, "%s ", marker); while ((ch = getc(f)), ch > 0 && ch != '\n') { - fputc(ch, Output_File); + print_char(ch); } - fputc('\n', Output_File); + print_char('\n'); } #ifdef DB_RUN diff --git a/judger/core/sim/sim_2_77/pass3.h b/judger/core/sim/sim_3_01/pass3.h old mode 100755 new mode 100644 similarity index 76% rename from judger/core/sim/sim_2_77/pass3.h rename to judger/core/sim/sim_3_01/pass3.h index 5e5f998e..8303f5c0 --- a/judger/core/sim/sim_2_77/pass3.h +++ b/judger/core/sim/sim_3_01/pass3.h @@ -1,6 +1,6 @@ /* This file is part of the software similarity tester SIM. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: pass3.h,v 1.3 2012-06-05 09:58:53 Gebruiker Exp $ + $Id: pass3.h,v 1.3 2012-06-05 09:58:53 dick Exp $ */ /* Print the contents of runs */ diff --git a/judger/core/sim/sim_3_01/percentages.c b/judger/core/sim/sim_3_01/percentages.c new file mode 100644 index 00000000..d8bb21df --- /dev/null +++ b/judger/core/sim/sim_3_01/percentages.c @@ -0,0 +1,263 @@ +/* This file is part of the software similarity tester SIM. + Written by Dick Grune, Vrije Universiteit, Amsterdam. + $Id: percentages.c,v 1.31 2016-07-31 18:55:44 dick Exp $ +*/ + +#include + +#include "debug.par" +#include "sim.h" +#include "text.h" +#include "options.h" +#include "Malloc.h" +#include "percentages.h" + +struct match { + struct match *ma_next; + const char *ma_fname0; + const char *ma_fname1; + size_t ma_size; /* # tokens of file 0 found in file 1 */ + size_t ma_size0; /* # tokens in file 0 */ +}; + +static struct match *match_list = 0; /* to be allocated by new() */ + +static void +do_add_to_percentages( + int rec_level, const struct text *txt0, const struct text *txt1, + size_t size); +static void print_perc_info(const struct match *m); + +#ifdef DB_PERC +static void db_print_match(const struct match *ma); +static void db_print_match_list(const char *msg); +#endif + +void +add_to_percentages( + const struct text *txt0, const struct text *txt1, size_t size +) { + /* percentages are only meaningful between different files */ + if (txt0 == txt1) return; + do_add_to_percentages(0, txt0, txt1, size); +} + +/* The important point to notice is that when a certain combination of two + texts turns up as a run, all runs with that combination will follow + immediately, and once a different combination has appeared the first one + will never return. +*/ + +static void +print_and_remove_match_list(void) { + while (match_list) { + struct match *m = match_list; + match_list = m->ma_next; + + print_perc_info(m); + Free(m); + } +} + +static void +do_add_to_percentages( + int rec_level, const struct text *txt0, const struct text *txt1, size_t size +) { + +#ifdef DB_PERC + fprintf(Debug_File, "do_add: %s, %s, %d\n", + txt0->tx_fname, + txt1->tx_fname, + size); +#endif + + /* look up the (txt0, txt1) combination in the match list */ + struct match *m = match_list; + while (m) { + if ( m->ma_fname0 == txt0->tx_fname + && m->ma_fname1 == txt1->tx_fname + ) { + /* found it; now update it */ + m->ma_size += size; +#ifdef DB_PERC + fprintf(Debug_File, "match updated:\n"); + db_print_match(m); +#endif + return; + } + m = m->ma_next; + } + + { /* it's not there; create a new entry, but tread carefully */ + m = try_new(struct match); + if (m == 0) { + /* Normally this should not happen. Freeing the + forward_reference[] and the last_index[] tables + should free ample memory to store the administration + of the runs found. But the tables are linear in the + input length and the number of runs is more or less + quadratic, so for massive comparisons the runs may + overtake the tables. + We then free memory by flushing collected results, + sacrificing the sorting. + */ + /* try to recover */ + if (rec_level > 0) { + /* but only one chance, to prevent looping */ + OutOfMemoryExit(0); + /*NOTREACHED*/ + } + static int message_given; + if (!message_given) { + fprintf(Output_File, + ">>>> OUTPUT NOT SORTED <<<<\n"); + message_given = 1; + } + print_and_remove_match_list(); + /* and try again */ + do_add_to_percentages(1, txt0, txt1, size); + return; + } + + m->ma_next = match_list; + match_list = m; + + m->ma_fname0 = txt0->tx_fname; + m->ma_fname1 = txt1->tx_fname; + m->ma_size = size; + m->ma_size0 = txt0->tx_limit - txt0->tx_start; +#ifdef DB_PERC + fprintf(Debug_File, "match created:\n"); + db_print_match(m); +#endif /* DB_PERC */ + } + + if (is_set_option('u')) { + /* Print the file/file combination as soon as it is finished. + It can only be found to be finished when the next pair is + found. Then a new struct match is created, on top of the + old one. So we check for the existence of a second match + and then print and release it. + We agree that this is a trick. + */ + if (match_list->ma_next) { + print_perc_info(match_list->ma_next); + Free(match_list->ma_next); + match_list->ma_next = 0; + } + } +} + + /* PRINTING */ +/* We want the sorting order + all contributors of the file with the highest percentage + all contributors of the file with the next lower percentage + etc. + but this order cannot be specified by a single SORT_BEFORE(). + So we sort for percentage, and then reorder during printing. +*/ + +/* instantiate sort_match_list(struct match **listhook) */ +static float +match_percentage(const struct match *m) { + return (((float)m->ma_size)/((float)m->ma_size0)); +} +#define SORT_STRUCT match +#define SORT_NAME sort_match_list +#define SORT_BEFORE(p1,p2) (match_percentage(p1) > match_percentage(p2)) +#define SORT_NEXT ma_next +#include "sortlist.bdy" + +#ifdef DB_PERC +static void +db_print_match(const struct match *ma) { + fprintf(Debug_File, "%s < %s, %d/%d=%3.2f%%\n", + ma->ma_fname0, ma->ma_fname1, + ma->ma_size, ma->ma_size0, + match_percentage(ma)*100.0 + ); +} + +static void +db_print_match_list(const char *msg) { + fprintf(Debug_File, "\n\n**** DB_PERCENTAGES %s ****\n", msg); + const struct match *ma; + + for (ma = match_list; ma; ma = ma->ma_next) { + db_print_match(ma); + } + fprintf(Debug_File, "\n"); +} +#endif /* DB_PERC */ + +static void +print_perc_info(const struct match *m) { + int mp = (int)(match_percentage(m)*100.0 + 0.5 /* rounding */); + + if (mp >= Threshold_Percentage) { + fprintf(Output_File, + "%s consists for %d %% of %s material\n", + m->ma_fname0, mp, m->ma_fname1 + ); + fflush(Output_File); + } +} + +static void +print_and_remove_perc_info_for_top_file(struct match **m_hook) { + struct match *m = *m_hook; + const char *fname = m->ma_fname0; + + print_perc_info(m); /* always print main contributor */ + *m_hook = m->ma_next; + Free(m); + + /* This is a horrible piece of code that should be rewritten. + It works only because initially m_hook points to match_list, + so removing entries with the same file name updates match_list, + whereas as soon as another file name is met, m_hook starts pointing + to the next field in the previous link, + so removing entries with the same file name just removes the entry. + Sneaky. + */ + while ((m = *m_hook)) { + if (m->ma_fname0 == fname) { + /* print subsequent contributors only if not + suppressed by -P + */ + if (!is_set_option('P')) { + print_perc_info(m); + } + /* remove the struct */ + *m_hook = m->ma_next; + Free(m); + } else { + /* skip the struct */ + m_hook = &m->ma_next; + } + } +} + +static void +print_percentages(void) { +#ifdef DB_PERC + db_print_match_list("before listing match_list"); +#endif /* DB_PERC */ + + /* destroys the match list while printing */ + while (match_list) { + print_and_remove_perc_info_for_top_file(&match_list); + } +} + +void +Show_Percentages(void) { +#ifdef DB_PERC + db_print_match_list("before sort"); +#endif /* DB_PERC */ + sort_match_list(&match_list); +#ifdef DB_PERC + db_print_match_list("after sort"); +#endif /* DB_PERC */ + print_percentages(); +} diff --git a/judger/core/sim/sim_3_01/percentages.h b/judger/core/sim/sim_3_01/percentages.h new file mode 100644 index 00000000..1a9adee8 --- /dev/null +++ b/judger/core/sim/sim_3_01/percentages.h @@ -0,0 +1,8 @@ +/* This file is part of the software similarity tester SIM. + Written by Dick Grune, Vrije Universiteit, Amsterdam. + $Id: percentages.h,v 1.6 2016-07-31 18:55:44 dick Exp $ +*/ + +extern void add_to_percentages( + const struct text *txt0, const struct text *txt1, size_t size); +extern void Show_Percentages(void); diff --git a/judger/core/sim/sim_3_01/runs.c b/judger/core/sim/sim_3_01/runs.c new file mode 100644 index 00000000..a6837d7a --- /dev/null +++ b/judger/core/sim/sim_3_01/runs.c @@ -0,0 +1,144 @@ +/* This file is part of the software similarity tester SIM. + Written by Dick Grune, Vrije Universiteit, Amsterdam. + $Id: runs.c,v 1.17 2016-07-31 18:55:44 dick Exp $ +*/ + +#include "sim.h" +#include "text.h" +#include "runs.h" +#include "Malloc.h" +#include "debug.par" + +static struct run *runs; +static void set_chunk( + struct chunk *cnk, struct text *txt, size_t start, size_t size); +static void set_pos( + struct position *pos, int type, struct text *txt, size_t start); + +void +add_to_runs( + struct text *txt0, size_t i0, struct text *txt1, size_t i1, + size_t size +) { + struct run *r = new(struct run); + /* This should always succeed, since releasing the forward_reference[] + and the last_index[] tables will have freed large amounts of memory, + and massive comparisons as in percentage.c are not reasonable and + quite useless here, due to the enormous amount of output to be + expected. + */ + + set_chunk(&r->rn_chunk0, txt0, i0 - txt0->tx_start, size); + set_chunk(&r->rn_chunk1, txt1, i1 - txt1->tx_start, size); + r->rn_size = size; + +#ifdef DB_RUN + fprintf(Debug_File, "add_to_runs: %s, %s, %d\n", + r->rn_chunk0.ch_text->tx_fname, + r->rn_chunk1.ch_text->tx_fname, + r->rn_size); +#endif + r->rn_next = runs; + runs = r; +} + +static void +set_chunk(struct chunk *cnk, struct text *txt, + size_t start, size_t size +) { + /* Fill the chunk *cnk with info about the piece of text + in txt starting at start extending over size tokens. + */ + cnk->ch_text = txt; + set_pos(&cnk->ch_first, 0, txt, start); + set_pos(&cnk->ch_last, 1, txt, start + size - 1); +} + +static void +set_pos(struct position *pos, int type, struct text *txt, size_t start) { + /* Fill a single struct position */ + pos->ps_next = txt->tx_pos; + txt->tx_pos = pos; + + pos->ps_type = type; + pos->ps_tk_cnt = start; + pos->ps_nl_cnt = (size_t) -1; /* uninitialized */ +} + +/* instantiate sort_run_list(struct run **listhook) */ +#define SORT_STRUCT run +#define SORT_NAME sort_run_list +#define SORT_BEFORE(r0,r1) ((r0)->rn_size > (r1)->rn_size) +#define SORT_NEXT rn_next +#include "sortlist.bdy" + +static void +reverse_runs(struct run **r_p) { + struct run *r = *r_p; + struct run *res = 0; + + while (r) { + struct run *top = r; + r = top->rn_next; + top->rn_next = res; + res = top; + } + *r_p = res; +} + +struct run * +unsorted_runs(void) { + reverse_runs(&runs); + return runs; +} + +struct run * +sorted_runs(void) { + reverse_runs(&runs); + sort_run_list(&runs); + return runs; +} + +void +discard_runs(void) { + while (runs) { + struct run *r = runs; + runs = r->rn_next; + Free(r); + } +} + +#ifdef DB_RUN + +void +db_run_info(const char *msg, const struct run *run, int lines_too) { + const struct chunk *cnk0 = &run->rn_chunk0; + const struct chunk *cnk1 = &run->rn_chunk1; + + if (msg) { + fprintf(Debug_File, "%s: ", msg); + } + fprintf(Debug_File, "\"%s\" / \"%s\":\n", + cnk0->ch_text->tx_fname, cnk1->ch_text->tx_fname + ); + fprintf(Debug_File, "from %s %s/%s to %s/%s:", Token_Name, + size_t2string(cnk0->ch_first.ps_tk_cnt), + size_t2string(cnk1->ch_first.ps_tk_cnt), + size_t2string(cnk0->ch_last.ps_tk_cnt), + size_t2string(cnk1->ch_last.ps_tk_cnt) + ); + if (lines_too) { + fprintf(Debug_File, " from lines %s/%s to %s/%s:", + size_t2string(cnk0->ch_first.ps_nl_cnt), + size_t2string(cnk1->ch_first.ps_nl_cnt), + size_t2string(cnk0->ch_last.ps_nl_cnt), + size_t2string(cnk1->ch_last.ps_nl_cnt) + ); + } + fprintf(Debug_File, " %s %s%s\n", + size_t2string(run->rn_size), + Token_Name, (run->rn_size == 1 ? "" : "s") + ); +} + +#endif /* DB_RUN */ diff --git a/judger/core/sim/sim_2_77/runs.h b/judger/core/sim/sim_3_01/runs.h old mode 100755 new mode 100644 similarity index 72% rename from judger/core/sim/sim_2_77/runs.h rename to judger/core/sim/sim_3_01/runs.h index 3400aad8..2825fd2d --- a/judger/core/sim/sim_2_77/runs.h +++ b/judger/core/sim/sim_3_01/runs.h @@ -1,6 +1,6 @@ /* This file is part of the software similarity tester SIM. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: runs.h,v 1.7 2013-04-28 16:30:42 Gebruiker Exp $ + $Id: runs.h,v 1.13 2016-07-31 18:55:44 dick Exp $ */ /* Although all other segments of data in this program are described by @@ -13,24 +13,25 @@ */ struct chunk { - /* a chunk of text in various representations */ - struct text *ch_text; /* pointer to the file */ + /* a chunk of text */ + const struct text *ch_text; /* pointer to the file */ struct position ch_first; /* first in chunk */ struct position ch_last; /* last in chunk */ }; struct run { /* a 'run' of coincident tokens */ + struct run *rn_next; struct chunk rn_chunk0; /* chunk in left file */ struct chunk rn_chunk1; /* chunk in right file */ size_t rn_size; }; -#define AISO_TYPE struct run * -#define AISO_ITER - -#include "aiso.spc" - -extern void add_to_runs(struct run *r); +extern void add_to_runs( + struct text *txt0, size_t i0, struct text *txt1, size_t i1, + size_t size); +extern struct run *sorted_runs(void); +extern struct run *unsorted_runs(void); +extern void discard_runs(void); #ifdef DB_RUN extern void db_run_info(const char *msg, const struct run *run, int lines_too); diff --git a/judger/core/sim/sim_3_01/settings.par b/judger/core/sim/sim_3_01/settings.par new file mode 100644 index 00000000..a8428018 --- /dev/null +++ b/judger/core/sim/sim_3_01/settings.par @@ -0,0 +1,8 @@ +/* This file is part of the software similarity tester SIM. + Written by Dick Grune, Vrije Universiteit, Amsterdam. + $Id: settings.par,v 1.6 2016-06-08 09:30:15 dick Exp $ +*/ + +#define DEFAULT_MIN_RUN_SIZE (24) + +#define DEFAULT_PAGE_WIDTH (80) diff --git a/judger/core/sim/sim_3_01/sim.1 b/judger/core/sim/sim_3_01/sim.1 new file mode 100644 index 00000000..bae733df --- /dev/null +++ b/judger/core/sim/sim_3_01/sim.1 @@ -0,0 +1,678 @@ +.\" This file is part of the software similarity tester SIM. +.\" Written by Dick Grune, Vrije Universiteit, Amsterdam. +.\" $Id: sim.1,v 2.40 2017-03-19 09:30:38 dick Exp $ +.\" +.TH SIM 1 2016/08/01 +.SH NAME +sim \- find similarities in C, Java, Pascal, Modula-2, Lisp, Miranda, or text files +.SH SYNOPSIS +.B sim_c +[ +.B \-[adefFiMnOpPRsSTuv] +.B \-r +.I N +.B \-t +.I N +.B \-w +.I N +.B \-o +.I F +] +file ... [ [ +.B / +.B | +] file ... ] +.br +.B sim_c++ +\&... +.br +.B sim_java +\&... +.br +.B sim_pasc +\&... +.br +.B sim_m2 +\&... +.br +.B sim_lisp +\&... +.br +.B sim_mira +\&... +.br +.B sim_text +\&... +.br +.SH DESCRIPTION +.I Sim_c +reads the C files +.I file ... +and looks for segments of text that are similar; two segments of program text +are similar if they only differ in layout, comment, identifiers, and +the contents of numbers, strings and characters. +If any runs of sufficient length +are found, they are reported on standard output; the number of significant +tokens in the run is given between square brackets. +.PP +.I Sim_c++ +does the same for C++, +.I sim_java +for Java, +.I sim_pasc +for Pascal, +.I sim_m2 +for Modula-2, +.I sim_mira +for Miranda, +and +.I sim_lisp +for Lisp. +.I Sim_text +works on arbitrary text and it is occasionally useful on shell scripts. +.PP +The program can be used for finding copied pieces of code in +purportedly unrelated programs (with +.B \-s +or +.BR \-S ), +or for finding accidentally duplicated code in larger projects (with +.B \-f +or +.BR \-F ). +.PP +If a separator +.B / +or +.B | +is present in the list of input files, the files are divided into a group of +"new" files (before the +.BR / +or +.BR | ) +and a group of "old" files; if there is no +.BR / +or +.BR | , +all files are "new". +Old files are never compared to other files. +See also the description of the +.B \-s +and +.B \-S +options below. +.PP +Since the similarity tester needs file names to pinpoint the similarities, it +cannot read from standard input. +.PP +The similarity tester takes ASCII or UTF-8 text as input, and produces a +sorted list of runs in text form (default or with the +.B -d +or +.B -n +options) or in percentage form (with the +.B -p +option). +Input in other formats, e.g. +.I .pdf +or +.I .doc +needs to be converted to ASCII or UTF-8 by preprocessing. +Aggregated similarity results can be obtained by doing postprocessing on the +output. +.PP +There are the following options: +.TP +.B \-d +The output is in a diff(1)-like format instead of the default +2-column format. +Recommended for text in languages with non-Latin alphabets. +.TP +.B \-e +Each file is compared to each file in isolation. This will find all +similarities between all texts involved, regardless of repetitive text, +but may be slow for large numbers of files. +See also `Calculating Percentages' below. +.TP +.B \-f +Runs are restricted to segments with balancing parentheses, to isolate +potential routine bodies (not in +.IR sim_text ). +.TP +.B \-F +The names of routines in calls are required to match exactly +(not in +.IR sim_text ). +.TP +.B \-i +The names of the files to be compared are read from standard input, including +a possible separator +.BR / +or +.BR | ; +the file names must be one to a line. +This option allows a very large number of file names to be specified; +it differs from the \fC@\fP facility provided by some compilers in that it +handles file names only, and does not recognize option arguments. +.TP +.B \-M +Memory usage information is displayed on standard error output. +.TP +.B \-n +Similarities found are summarized by file name, position and size, rather than +displayed in full. +.TP +.B "\-o F" +The output is written to the file named +.IR F . +.TP +.B \-O +The option settings used are shown at the beginning of the output. +.TP +.B \-p +The output is given in similarity percentages; see `Calculating Percentages' +below; implies \fB\-s\fP. +.TP +.B \-P +When reporting percentages, only the main contributor for each file is shown. +.TP +.B "\-r N" +The minimum run length is set to +.I N +units; the default is 24 tokens, except in +.IR sim_text , +where it is 8 words. +.TP +.B \-R +Directories in the input list are entered recursively, and all files they +contain are involved in the comparison. +.TP +.B \-s +The contents of a file are not compared to itself (\-s for "not self"). +.TP +.B \-S +The contents of the new files are compared to the old files only \- not +between themselves. +.TP +.B "\-t N" +In combination with the +.B \-p +option, sets the threshold (in percents) below which similarities will not be +reported; the default is 1, except in +.IR sim_text , +where it is 20. +.TP +.B \-T +Suppresses the printing of information about the input files. +.TP +.B \-u +The output is not buffered and not sorted (only when reporting percentages). +.TP +.B \-v +Prints the version number and compilation date on standard output, then stops. +.TP +.B "\-w N" +The page width used is set to +.I N +columns; the default is 80. +.TP +.B "\-\-" +(A secret option, which prints the input as the similarity checker sees it, +and then stops.) +.PP +The +.B \-p +option results in lines of the form +.nf +.ft C + F consists for x % of G material +.ft P +.fi +meaning that \fCx\fP % of \fCF\fP's text can also be found in \fCG\fP. +Note that this relation is not symmetric; it is quite possible for one +file to consist for 100 % of text from another file, while the other file +consists for only 1 % of text of the first file, if their lengths differ +enough. +The +.B \-P +(capital P) option shows the main contributor for each file only. +This simplifies the identification of a set of files \fCA[1] ... A[n]\fP, +where the concatenation of these files is also present. +A threshold can be set using the +.B \-t +option. +Note that the granularity of the recognized text is still governed by the +.B \-r +option or its default. +.PP +The +.B \-r +option controls the number of "units" that constitute a run. +For the programs that compare programming language code, a unit is a lexical +token in the pertinent language; comment and standard preamble material (file +inclusion, etc.) is ignored and all strings are considered equal. +For +.I sim_text +a unit is a "word" which is defined as any sequence of one or more letters, +digits, or characters over 127 (177 octal), to accommodate full UNICODE (UTF-8). +.PP +The programs can handle UNICODE (UTF-16) file names under Windows. +This is relevant only under the +.B \-R +option, since there is no way to supply UNICODE file names from the command +line. +.PP +.I Sim_text +accepts s p a c e d t e x t as normal text. +.PP +Once +.I sim +has read, stored and preprocessed the input, it will no longer run out of +memory. +If memory is short it will change automatically to unbuffered, unsorted +output (while isuuing a warning message). +.SH WHAT IS COMPARED TO WHAT +The default operation cycle of +.I sim +starts at the beginning of the first input file or at a point +.I X +in a file +.I F +among the new files, i.e. those before the new/old separator, if present. +.I Sim +then finds the longest segment +.I S +such that +1) +.I S +is equal to the segment starting at +.IR X ; +2) +.I S +is situated somewhere between position +.I X +in +.I F +and the end of all files; +3) +.I S +does not overlap with the segment starting at +.IR X . +If the segment is at least of minimum run size, it is recorded, and the cycle +starts again just after the segment at +.IR X ; +otherwise it starts again at +.IR X+1 . +.PP +So if the tokens at +.I X +read \fCabcabcadefabdabcz\fP, the cycle finds +.I S +to be the \fCabc\fP just before the end; \fCabda\fP at position 4 would be +longer but overlaps. +The cycle then starts at position 4, and will find another match with the +\fCabc\fP near the end. +Finally the third \fCab\fP be matched with the fourth \fCab\fP just before the +\fCcz\fP. +This way best matches for the text in a file are found in material +to the right of it, until the end of all files. +The results are asymmetric: given files +.IR F1 , +.IR F2 , +.IR F3 , +.IR F4 , +no matches for +.I F3 +are reported from +.I F1 +or +.IR F2 , +for example. +As explained below under "Limitations", this avoids duplicate reports of +similarity and helps to keep +.I sim +fast. +.PP +The area that is searched by +.I sim's +cycle is called the +.IR range . +The default range (running from the file under observation to the end of all +files) is excellent for finding similarities in program files, +and, when doing percentages, for getting an impression of which files are +related to which files, but sometimes more control is needed. +.PP +The +.B \-a +option includes +.I all +text in the range by not stopping the search at the end of the files but +rather looping back to the beginning of the files and continuing to the point +where the search started. +Now matches are also found in files before the present one and the results are +symmetric: given files +.IR F1 , +.IR F2 , +.IR F3 , +.IR F4 , +matches for +.I F3 +will also be reported from +.I F1 +or +.IR F2 , +if present. +But matches may be reported twice, once for file +.I Fa +versus file +.IR Fb , +and once for file +.I Fb +versus file +.IR Fa . +The +.B \-a +option allows a more accurate determination of similarity percentages. +.PP +The +.B \-a +option is the only way to obtain symmetrical results, with information +about both \fIF1\fP vs. \fIF2\fP and \fIF2\fP vs. \fIF1\fP. +.PP +The +.B \-S +option removes the new files from the range, so files are only compared to the +old files. +.PP +The +.B \-s +option removes the file itself from the range, so a file will not be compared +to itself. This is the default when reporting percentages. +.PP +In normal operation the whole range is searched as one unit. The +.B \-e +option divides up the range into the separate files, and causes +.I sim +to compare a file to each of the other files separately. +This produces the most detailed information when reporting text similarities, +and the best possible results when reporting similarity percentages, but can +be quite slow. +.SS A Tabular Representation +Input files are divided into two groups, new and old. +In the absence of control options +.I sim +compares the files thus (for 4 new files and 6 old ones): +.ne 16 +.nf +.ft C + n e w / o l d <- second file + 1 2 3 4 / 5 6 7 8 9 10 + |------------/------------ + n 1 | c c c c / c c c c c c + e 2 | c c c / c c c c c c + w 3 | c c / c c c c c c + 4 | c / c c c c c c + first / / / / / / / / / / / / / + file -> 5 | / + o 6 | / + l 7 | / + d 8 | / + 9 | / + 10 | / +.ft P +.fi +where a \fCc\fP indicates that the first file is compared to the second file, +and the \fC/\fP represents the demarcation between new and old files. +The comparison range of the first files is clearly visible. +.PP +Using the +.B \-a +option extends this to +.ne 16 +.nf +.ft C + n e w / o l d <- second file + 1 2 3 4 / 5 6 7 8 9 10 + |------------/------------ + n 1 | c c c c / c c c c c c + e 2 | c c c c / c c c c c c + w 3 | c c c c / c c c c c c + 4 | c c c c / c c c c c c + first / / / / / / / / / / / / / + file -> 5 | / + o 6 | / + l 7 | / + d 8 | / + 9 | / + 10 | / +.ft P +.fi +.PP +Using the +.B \-S +option instead reduces this to +.ne 16 +.nf +.ft C + n e w / o l d <- second file + 1 2 3 4 / 5 6 7 8 9 10 + |------------/------------ + n 1 | / c c c c c c + e 2 | / c c c c c c + w 3 | / c c c c c c + 4 | / c c c c c c + first / / / / / / / / / / / / / + file -> 5 | / + o 6 | / + l 7 | / + d 8 | / + 9 | / + 10 | / +.ft P +.fi +.PP +Finally, using the +.B \-s +option changes the default ranges to +.ne 16 +.nf +.ft C + n e w / o l d <- second file + 1 2 3 4 / 5 6 7 8 9 10 + |------------/------------ + n 1 | c c c / c c c c c c + e 2 | c c / c c c c c c + w 3 | c / c c c c c c + 4 | / c c c c c c + first / / / / / / / / / / / / / + file -> 5 | / + o 6 | / + l 7 | / + d 8 | / + 9 | / + 10 | / +.ft P +.fi +and the +.BR \-a -extended +ranges to +.ne 16 +.nf +.ft C + n e w / o l d <- second file + 1 2 3 4 / 5 6 7 8 9 10 + |------------/------------ + n 1 | c c c / c c c c c c + e 2 | c c c / c c c c c c + w 3 | c c c / c c c c c c + 4 | c c c / c c c c c c + first / / / / / / / / / / / / / + file -> 5 | / + o 6 | / + l 7 | / + d 8 | / + 9 | / + 10 | / +.ft P +.fi +.SH LIMITATIONS +Repetitive input is the bane of similarity checking. +If we have a file containing 4 copies of identical text, +.nf +.ft C + A1 A2 A3 A4 +.ft P +.fi +where the numbers serve only to distinguish the identical copies, +there are 7 non-overlapping identities: \fCA1=A2\fP, \fCA1=A3\fP, \fCA1=A4\fP, +\fCA2=A3\fP, \fCA2=A4\fP, \fCA3=A4\fP, and \fCA1A2=A3A4\fP. +Of these, only 3 are meaningful: \fCA1=A2\fP, \fCA2=A3\fP, and \fCA3=A4\fP. +And for a table with 20 lines identical to each other, not unusual in a +program text, there are 715 non-overlapping identities, of which at most 19 +are meaningful. +Reporting all 715 of them is clearly unacceptable. +.PP +This is remedied by +.I sim's +search cycle: +for each position in the text, the largest segment is found of which a +non-overlapping copy occurs in the text following it. +That segment and its copy are then reported and scanning resumes at the +position just after the segment. +For the above example this results in the two identities \fCA1A2=A3A4\fP and +\fCA3=A4\fP, which is quite satisfactory, and for \fIN\fP identical segments +roughly \fI2 log N\fP messages are given. +.PP +This also works out well when the four identical segments are in different +files: +,ne 4 +.nf +.ft C + File1: A1 + File2: A2 + File3: A3 + File4: A4 +.ft P +.fi +Now combined segments like \fCA1A2\fP do not occur, and the algorithm finds +the runs \fCA1=A2\fP, \fCA2=A3\fP, and \fCA3=A4\fP, for a total of \fIN-1\fP +runs, all informative. +.SS Calculating Percentages +The above approach is unsuitable for obtaining the exact percentage of a +file's content that can be found in another file, although indicative results +can be obtained. +Obtaining exact percentages requires comparing each file pair in isolation; +this is what the \fB\-ae\fP options do. +Under the \fB\-ae\fP options a segment \fCFile3:A3\fP, recognized in +\fCFile4\fP, will again be recognized in \fCFile1\fP and \fCFile2\fP. +In the example above it produces the runs +.ne 12 +.nf +.ft C + File1:A1=File2:A2 + File1:A1=File3:A3 + File1:A1=File4:A4 + File2:A2=File3:A3 + File2:A2=File4:A4 + File2:A2=File1:A1 + File3:A3=File4:A4 + File3:A3=File1:A1 + File3:A3=File2:A2 + File4:A4=File1:A1 + File4:A4=File2:A2 + File4:A4=File3:A3 +.ft P +.fi +for a total of \fIN(N-1)\fP runs. +.PP +When the +.B \-e +option is used alone. +.I sim +will find the following runs: +.ne 6 +.nf +.ft C + File1:A1=File2:A2 + File1:A1=File3:A3 + File1:A1=File4:A4 + File2:A2=File3:A3 + File2:A2=File4:A4 + File3:A3=File4:A4 +.ft P +.fi +for a total of \fI\(12N(N-1)\fP runs, thus missing half the percentage +contributions; in fact, \fCFile4\fP is found to have 0% in common with the +other files. +.PP +If, however, the +.B \-a +option is used alone. +.I sim +finds the following runs: +.ne 4 +.nf +.ft C + File1:A1=File2:A2 + File2:A2=File3:A3 + File3:A3=File4:A4 + File4:A4=File1:A1 +.ft P +.fi +for a total of \fIN\fP runs. This setting misses many of the percentage +contributions, but finds something for every file. +.SH TIME AND SPACE REQUIREMENTS +Care has been taken to keep the time requirements of all internal processes +(almost) linear in the lengths of the input files, by using various tables. +.PP +The time requirements are quadratic in the number of files. +This means that, for example, one 64 MB file processes much faster than 8000 8 +kB files. +.PP +The program requires 6 bytes of memory for each token in the input; 2 +bytes per newline (not when doing percentages); and 80 bytes for each +run found. +.SH EXAMPLES +The call +.nf +.ft C + sim_c *.c +.ft P +.fi +highlights duplicate C code in the directory. +(It is useful to remove generated files first.) +A call of +.nf +.ft C + sim_c -f -F *.c +.ft P +.fi +can pinpoint the duplicate code further. +.PP +A call +.nf +.ft C + sim_text -peu -S new/* "|" old/* +.ft P +.fi +compares each file in \fCnew/*\fP to each file in \fCold/*\fP, and if any pair +has more that 20% in common, that fact is reported. +Usually a similarity of 30% or more is significant; lower than 20% is probably +coincidence; and in between is doubtful. +.PP +The \fCu\fP in \fC-peu\fP causes the output to be unbuffered (and unsorted), so +if the program is stopped for running out of time, any results already found +are not lost. +.PP +For large data sets, using \fC-pu\fP rather than \fC-peu\fP may do the job much +more quickly, but less accurately. +.PP +The \fC|\fP can be used as a separator instead of \fC/\fP on systems where the +\fC/\fP as a command-line parameter gets mangled by the command interpreter. +.PP +These calls are good for plagiarism detection. +.SH BUGS +Unbuffered, unsorted output is not available for text output, only for +percentage output. +.SH AUTHOR +Dick Grune, Vrije Universiteit, Amsterdam; dick@dickgrune.com. diff --git a/judger/core/sim/sim_3_01/sim.c b/judger/core/sim/sim_3_01/sim.c new file mode 100644 index 00000000..6387fbb6 --- /dev/null +++ b/judger/core/sim/sim_3_01/sim.c @@ -0,0 +1,253 @@ +/* This file is part of the software similarity tester SIM. + Written by Dick Grune, Vrije Universiteit, Amsterdam. + $Id: sim.c,v 2.69 2017-03-19 09:30:38 dick Exp $ +*/ + +#include +#include +#include + +#include "system.par" +#include "settings.par" +#include "sim.h" +#include "options.h" +#include "newargs.h" +#include "token.h" +#include "tokenarray.h" +#include "language.h" +#include "text.h" +#include "runs.h" +#include "hash.h" +#include "compare.h" +#include "pass1.h" +#include "pass2.h" +#include "pass3.h" +#include "percentages.h" +#include "stream.h" +#include "lang.h" + +#include "Malloc.h" +#include "any_int.h" + +const char *Version; + + /* PARAMETERS */ +/* Command-line parameters, with defaults */ +int Min_Run_Size = DEFAULT_MIN_RUN_SIZE; +int Page_Width = DEFAULT_PAGE_WIDTH; +int Threshold_Percentage = 1; +FILE *Output_File; +FILE *Debug_File; + +/* Language-specific parameters; may be changed in Init_Language() */ +const char *Token_Name = "token"; + +static const char *progname; /* for error reporting */ +static const char *output_name; /* for redirecting the output */ + +static const struct option optlist[] = { + {'r', "set minimum run size to N", Number, &Min_Run_Size}, + + {' ', "output runs as text (default)", None, 0}, + {'d', "output in a diff-like format", None, 0}, + {'n', "suppress the text of the runs", None, 0}, + {'T', "suppress reporting the input files", None, 0}, + {'p', "output similarity in percentages", None, 0}, + {'P', "main contributing file to percentages only", None, 0}, + {'t', "threshold level of percentages", Number, &Threshold_Percentage}, + + {'e', "compare each file to each file separately", None, 0}, + + {' ', "compare a file to files after it only (default)", None, 0}, + {'a', "compare to all files", None, 0}, + {'S', "compare to old files only", None, 0}, + {'s', "do not compare a file to itself", None, 0}, + + {' ', "sorted output, most significant first (default)", None, 0}, + {'u', "unbuffered, unsorted output", None, 0}, + + {' ', "miscellaneous options:", None, 0}, + {'f', "function-like forms only", None, 0}, + {'F', "keep function identifiers in tact", None, 0}, + {'R', "recurse into subdirectories", None, 0}, + {'i', "read arguments (file names) from standard input", None, 0}, + {'o', "write output to file F", String, &output_name}, + {'w', "set page width to N", Number, &Page_Width}, + {'O', "show command line options at start-up", None, 0}, + {'M', "show memory usage info at close-down", None, 0}, + {'v', "show version number and compilation date", None, 0}, + {'-', "lexical scan output only", None, 0}, + {0, 0, 0, 0} +}; + + /* SERVICE ROUTINES */ +int +is_new_old_separator(const char *s) { + if (strcmp(s, "/") == 0) return 1; + if (strcmp(s, "|") == 0) return 1; + return 0; +} + +const char * +size_t2string(size_t s) { + return any_uint2string(s, 0); +} + +void +fatal(const char *msg) { + fprintf(stderr, "%s: %s\n", progname, msg); + exit(1); +} + + /* PROGRAM */ + +#ifdef ARG_TEST +static void +show_args(const char *msg, int argc, const char *argv[]) { + fprintf(stdout, "%s: ", msg); + + int i; + for (i = 0; i < argc; i++) { + fprintf(stdout, "arg[%d] = %s; ", i, argv[i]); + } + fprintf(stdout, "\n"); +} +#endif /* ARG_TEST */ + +int +main(int argc, const char *argv[]) { + + /* The value of Version derives from the macro VERSION in the + Makefile if present. If not, a build time stamp is created. + */ + char version[40]; +#ifdef VERSION + sprintf(version, "Version %s", VERSION); +#else + sprintf(version, "Build %s, %s", __DATE__, __TIME__); +#endif + Version = version; + + /* Save program name */ + progname = argv[0]; + argv++, argc--; /* and skip it */ + + /* Set the default output and debug streams */ + Output_File = stdout; + Debug_File = stdout; + Threshold_Percentage = 1; + + /* Options, default string values given above */ + + /* override from language file */ + Init_Language(); + + /* override from command line */ + { int n_op = do_options(progname, optlist, argc, argv); + argc -= n_op, argv += n_op; /* and skip them */ + } + + /* Check options compatibility */ + allow_at_most_one_option_out_of("dnp"); /* alternative output formats */ + allow_at_most_one_option_out_of("aS"); /* alternative ranges */ + allow_at_most_one_option_out_of("sS"); /* self is outside old files */ + + if (is_set_option('t')) { + /* threshold means percentages */ + if (!is_set_option('p')) + fatal("option -t requires -p"); + } + if (is_set_option('P')) { + if (!is_set_option('p')) + fatal("option -P requires -p"); + } + /* ZZ + if (is_set_option('u')) { + if (!is_set_option('p')) + fatal("option -u available with -p only"); + } + */ + + /* Treat the simple options */ + if (is_set_option('v')) { + fprintf(stdout, "%s\n", Version); + return 0; + } + + if (is_set_option('p')) { + set_option('s'); + } + + /* Check the value options */ + if (Min_Run_Size <= 0) + fatal("bad run size"); + if (Page_Width <= 0) + fatal("bad page width"); + + if (is_set_option('p')) { + if ((Threshold_Percentage > 100) || (Threshold_Percentage <= 0)) + fatal("threshold must be between 1 and 100"); + } + + if (output_name) { + Output_File = fopen(output_name, "w"); + if (Output_File == 0) { + char *msg = (char *)Malloc(strlen(output_name) + 100); + + sprintf(msg, "cannot open output file `%s'", + output_name); + fatal(msg); + /*NOTREACHED*/ + } + } + + /* Treat the input-determining options */ + if (is_set_option('i')) { + /* read input file names from standard input */ + if (argc != 0) + fatal("-i option conflicts with file arguments"); + get_new_std_input_args(&argc, &argv); + } + if (is_set_option('R')) { + get_new_recursive_args(&argc, &argv); + } + /* (argc, argv) now represents new_file* [ / old_file*] */ + + /* Optionally show command line options */ + if (is_set_option('O')) { + print_options(progname, optlist); + } + + /* Here the real work starts */ + + if (is_set_option('-')) { + /* Just the lexical scan */ + while (argv[0]) { + const char *arg = argv[0]; + if (!is_new_old_separator(arg)) { + Print_Stream(arg); + } + argv++; + } + } + else { /* The works */ + Read_Input_Files(argc, argv); + Make_Forward_References(); + Compare_Files(); + Free_Forward_References(); + if (is_set_option('p')) { + Show_Percentages(); + } else { + Retrieve_Runs(); + Show_Runs(); + } + } + + Free_Text(); + Free_Token_Array(); + if (is_set_option('M')) { + ReportMemoryStatus(stderr); + } + + return 0; +} diff --git a/judger/core/sim/sim_2_77/sim.h b/judger/core/sim/sim_3_01/sim.h old mode 100755 new mode 100644 similarity index 61% rename from judger/core/sim/sim_2_77/sim.h rename to judger/core/sim/sim_3_01/sim.h index 4105134b..8a30b070 --- a/judger/core/sim/sim_2_77/sim.h +++ b/judger/core/sim/sim_3_01/sim.h @@ -1,25 +1,24 @@ /* This file is part of the software similarity tester SIM. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: sim.h,v 2.17 2014-01-26 21:52:59 Gebruiker Exp $ + $Id: sim.h,v 2.22 2016-05-29 15:23:16 dick Exp $ */ #include +extern const char *Version; + extern int Min_Run_Size; extern int Page_Width; extern FILE *Output_File; extern FILE *Debug_File; -extern const char *token_name; /* possibly modified in *lang.l */ -extern int Threshold_Percentage; /* threshold percentage */ - -extern const char *progname; /* for error reporting */ - -extern const char *min_run_string; -extern const char *threshold_string; +extern const char *Token_Name; /* possibly modified in *lang.l */ +extern int Threshold_Percentage; +/* Service routines */ extern int is_new_old_separator(const char *s); extern const char *size_t2string(size_t s); +extern void fatal(const char *msg); /* All output goes through designated files, so we block printf, etc. */ #undef printf diff --git a/judger/core/sim/sim_3_01/sim.pdf b/judger/core/sim/sim_3_01/sim.pdf new file mode 100644 index 00000000..60b87069 Binary files /dev/null and b/judger/core/sim/sim_3_01/sim.pdf differ diff --git a/judger/core/sim/sim_3_01/sortlist.bdy b/judger/core/sim/sim_3_01/sortlist.bdy new file mode 100644 index 00000000..927a0605 --- /dev/null +++ b/judger/core/sim/sim_3_01/sortlist.bdy @@ -0,0 +1,64 @@ +/* + Module: Sort Linked Lists + Author: dick@dickgrune.com (Dick Grune, Amstelveen) + Version: 2015-01-18 + +Description: + This is the implementation part of a generic routine that sorts + linked lists. + +Instantiation: + See sortlist.spc +*/ + +#ifndef _SORT_EXTERN_DEFINED +static +#endif +void +SORT_NAME(struct SORT_STRUCT **l_hook) { + /* by split-sort-merge */ + struct SORT_STRUCT *lst = *l_hook; + if (lst == 0) return; /* the empty list is sorted */ + if (lst->SORT_NEXT == 0) return; /* a 1-element list is sorted */ + + /* There are at least two elements; split them into two sublists. */ + struct SORT_STRUCT *q0 = 0, *q1 = 0; /* starts of the sublists */ + struct SORT_STRUCT **q_hook[2]; /* append hooks for the lists */ + q_hook[0] = &q0, q_hook[1] = &q1; + int q_cnt = 0; /* pertinemt sublist pointer */ + + while (lst) { + /* Detach the head element */ + struct SORT_STRUCT *l = lst; + lst = lst->SORT_NEXT; + l->SORT_NEXT = 0; + + /* and append it to the pertinent sublist. */ + *q_hook[q_cnt] = l; + q_hook[q_cnt] = &l->SORT_NEXT; + q_cnt = 1 - q_cnt; /* switch pertinent sublist */ + } + + /* Sort recursively. */ + SORT_NAME(&q0); + SORT_NAME(&q1); + + /* Merge. */ + *l_hook = 0; + while (q0 || q1) { + /* determine the list with the smallest head element */ + struct SORT_STRUCT **h_hook = ( + q0 == 0 ? &q1 : + q1 == 0 ? &q0 : + SORT_BEFORE((q0), (q1)) ? &q0 : &q1 + ); + /* detach head element */ + struct SORT_STRUCT *l = *h_hook; + *h_hook = (*h_hook)->SORT_NEXT; + l->SORT_NEXT = 0; + + /* append l to l_hook */ + *l_hook = l; + l_hook = &l->SORT_NEXT; + } +} diff --git a/judger/core/sim/sim_2_77/sortlist.spc b/judger/core/sim/sim_3_01/sortlist.spc old mode 100755 new mode 100644 similarity index 62% rename from judger/core/sim/sim_2_77/sortlist.spc rename to judger/core/sim/sim_3_01/sortlist.spc index 10de53ad..a4a950b3 --- a/judger/core/sim/sim_2_77/sortlist.spc +++ b/judger/core/sim/sim_3_01/sortlist.spc @@ -1,64 +1,63 @@ /* Module: Sort Linked Lists Author: dick@cs.vu.nl (Dick Grune @ Vrije Universiteit, Amsterdam) - Version: Tue Sep 17 17:32:33 1991 + Version: 2015-01-18 Description: This is the specification part of a generic routine that sorts linked lists. The elements in the list are structs, each of which carries a pointer to the next element. +Specification: + The module supplies: + - a routine void SORT_NAME(struct SORT_STRUCT **listhook) + where 'listhook' is a pointer to the location that holds the + pointer to the list to be sorted. Upon return, the list will + be sorted, and the pointer updated. + The routine will be defined static when instantiated inline. + Instantiation, inline: For each struct list type T, specify: - a definition of SORT_STRUCT, the struct name of the linked - structs + structs; - a definition of SORT_NAME, the name of the resulting sort - routine + routine; - a definition of a routine int SORT_BEFORE( struct SORT_STRUCT *v, struct SORT_STRUCT *w ) - which yields non-zero if v is to be sorted before w + or a definition + #define SORT_BEFORE((v,w) + which yields non-zero if v is to be sorted before w; - a definition of a field selector SORT_NEXT which names the - field that points to the next struct SORT_STRUCT in the list + field that points to the next struct SORT_STRUCT in the list. - #include "sortlist.bdy" Instantiation, separate: - For each struct list type T, create a file sortT.h which contains at + For each struct list type T, create a file sort_T.h which contains at least: - a definition of SORT_STRUCT, the struct name of the linked - structs + structs; - a definition of SORT_NAME, the name of the resulting sort - routine + routine; - #include "sortlist.spc" - This file sortT.h is to be included in all files that use the routine + This file sort_T.h is to be included in all files that use the routine SORT_NAME. - For each struct list type T, create a file sortT.c which contains at + For each struct list type T, create a file sort_T.c which contains at least: - - #include "sortT.h" - - a definition of a routine - int SORT_BEFORE( - struct SORT_STRUCT *v, struct SORT_STRUCT *w - ) - which yields non-zero if v is to be sorted before w + - #include "sort_T.h" + - a definition of a routine or definition SORT_BEFORE as + described above; - a definition of a field selector SORT_NEXT which names the - field that points to the next struct SORT_STRUCT in the list + field that points to the next struct SORT_STRUCT in the list; - #include "sortlist.bdy" - This file sortT.c compiles into the module object for SORT_STRUCT. - -Specification: - The module supplies: - - void SORT_NAME(struct SORT_STRUCT **listhook) - where 'listhook' is a pointer to the location that holds the - pointer to the list to be sorted. Upon return, the list will - be sorted, and the pointer updated. - The routine will be defined static when instantiated inline. + This file sort_T.c compiles into the module object for SORT_STRUCT. Implementation: - Linear insert sort:-(. + Recursive split-sort-merge. */ extern void SORT_NAME(struct SORT_STRUCT **); diff --git a/judger/core/sim/sim_2_77/stream.c b/judger/core/sim/sim_3_01/stream.c old mode 100755 new mode 100644 similarity index 68% rename from judger/core/sim/sim_2_77/stream.c rename to judger/core/sim/sim_3_01/stream.c index 89bdad90..c3e67c0c --- a/judger/core/sim/sim_2_77/stream.c +++ b/judger/core/sim/sim_3_01/stream.c @@ -1,6 +1,6 @@ /* This file is part of the software similarity tester SIM. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: stream.c,v 2.12 2014-01-26 21:52:59 Gebruiker Exp $ + $Id: stream.c,v 2.14 2016-05-13 19:00:54 dick Exp $ */ #include @@ -65,28 +65,27 @@ Print_Stream(const char *fname) { return; } - if (!is_set_option('T')) { - fprintf(Output_File, - " showing token stream:\nnl_cnt, tk_cnt: %ss", - token_name - ); + fprintf(Output_File, " showing the %s stream\n", Token_Name); - lex_token = End_Of_Line; - do { - if (Token_EQ(lex_token, End_Of_Line)) { - fprintf(Output_File, "\n%s,%s:", - size_t2string(lex_nl_cnt), - size_t2string(lex_tk_cnt) - ); - } - else { - fprintf(Output_File, " "); - fprint_token(Output_File, lex_token); - } - } while (Next_Stream_Token_Obtained()); + lex_token = End_Of_Line; + do { + if (Token_EQ(lex_token, End_Of_Line)) { + fprintf(Output_File, + "line # = %s, %s # = %s:\n", + size_t2string(lex_nl_cnt), + Token_Name, + size_t2string(lex_tk_cnt) + ); + } + else { + extern char *yytext; + fprintf(Output_File, " %s -> ", yytext); + fprint_token(Output_File, lex_token); + fprintf(Output_File, "\n"); + } + } while (Next_Stream_Token_Obtained()); - fprintf(Output_File, "\n"); - } + fprintf(Output_File, "\n"); Close_Stream(); } diff --git a/judger/core/sim/sim_2_77/stream.h b/judger/core/sim/sim_3_01/stream.h old mode 100755 new mode 100644 similarity index 87% rename from judger/core/sim/sim_2_77/stream.h rename to judger/core/sim/sim_3_01/stream.h index 9011797a..903cae2e --- a/judger/core/sim/sim_2_77/stream.h +++ b/judger/core/sim/sim_3_01/stream.h @@ -1,6 +1,6 @@ /* This file is part of the software similarity tester SIM. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: stream.h,v 2.7 2012-06-08 16:04:30 Gebruiker Exp $ + $Id: stream.h,v 2.7 2012-06-08 16:04:30 dick Exp $ */ /* diff --git a/judger/core/sim/sim_2_77/system.par b/judger/core/sim/sim_3_01/system.par old mode 100755 new mode 100644 similarity index 86% rename from judger/core/sim/sim_2_77/system.par rename to judger/core/sim/sim_3_01/system.par index a9954619..94f55941 --- a/judger/core/sim/sim_2_77/system.par +++ b/judger/core/sim/sim_3_01/system.par @@ -1,6 +1,6 @@ /* This file is part of the software similarity tester SIM. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: system.par,v 1.3 2014-01-26 13:51:27 Gebruiker Exp $ + $Id: system.par,v 1.3 2014-01-26 13:51:27 dick Exp $ */ /* Operating-system dependent data */ diff --git a/judger/core/sim/sim_2_77/text.c b/judger/core/sim/sim_3_01/text.c old mode 100755 new mode 100644 similarity index 70% rename from judger/core/sim/sim_2_77/text.c rename to judger/core/sim/sim_3_01/text.c index 858133fd..6bebf868 --- a/judger/core/sim/sim_2_77/text.c +++ b/judger/core/sim/sim_3_01/text.c @@ -1,9 +1,10 @@ /* This file is part of the software similarity tester SIM. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: text.c,v 1.14 2014-01-26 21:52:59 Gebruiker Exp $ + $Id: text.c,v 1.23 2016-08-03 19:14:04 dick Exp $ */ #include +#include #include "debug.par" #include "sim.h" @@ -12,14 +13,13 @@ #include "lang.h" #include "Malloc.h" #include "options.h" -#include "error.h" #include "text.h" struct text *Text; /* to be filled in by Malloc() */ -int Number_Of_Texts; /* number of text files */ -int Number_Of_New_Texts; /* number of new text files */ +int Number_of_Texts; +int Number_of_New_Texts; -typedef unsigned char nl_tk_diff_t; +typedef unsigned short nl_tk_diff_t; struct newline { nl_tk_diff_t nl_tk_diff; /* token position difference */ @@ -48,9 +48,9 @@ Init_Text(int nfiles) { Free(Text); Text = 0; } - Number_Of_Texts = nfiles; + Number_of_Texts = nfiles; Text = (struct text *) - Malloc((size_t)(Number_Of_Texts*sizeof (struct text))); + Malloc((size_t)(Number_of_Texts*sizeof (struct text))); init_nl_buff(); } @@ -58,14 +58,14 @@ Init_Text(int nfiles) { int Open_Text(enum Pass pass, struct text *txt) { switch (pass) { - case First: + case First_Pass: last_tk_cnt = 0; if (nl_buff) { txt->tx_nl_start = nl_free; } break; - case Second: + case Second_Pass: last_tk_cnt = 0; if (nl_buff) { nl_next = txt->tx_nl_start; @@ -82,50 +82,41 @@ Open_Text(enum Pass pass, struct text *txt) { } int -Next_Text_Token_Obtained(enum Pass pass) { - int ok = 0; /* gcc does not understand enum Pass */ - - switch (pass) { - case First: - ok = Next_Stream_Token_Obtained(); - if (Token_EQ(lex_token, End_Of_Line)) { - store_newline(); - last_tk_cnt = lex_tk_cnt; - } - break; - - case Second: - /* get newline info from the buffer or from the file itself */ - if (nl_buff) { - if (nl_next == nl_limit) { - ok = 0; - } - else { - struct newline *nl = &nl_buff[nl_next++]; +Next_Text_Token_Obtained(void) { + if (!Next_Stream_Token_Obtained()) return 0; + if (Token_EQ(lex_token, End_Of_Line)) { + store_newline(); + last_tk_cnt = lex_tk_cnt; + } + return 1; +} - lex_nl_cnt = ++last_nl_cnt; - lex_tk_cnt = (last_tk_cnt += nl->nl_tk_diff); - lex_token = End_Of_Line; - ok = 1; - } - } - else { - while ( (ok = Next_Stream_Token_Obtained()) - && !Token_EQ(lex_token, End_Of_Line) - ) { - /* skip */ - } +int +Next_Text_EOL_Obtained(void) { + /* get newline info from the buffer or from the file itself */ + if (nl_buff) { + if (nl_next == nl_limit) return 0; + + struct newline *nl = &nl_buff[nl_next++]; + lex_nl_cnt = ++last_nl_cnt; + lex_tk_cnt = (last_tk_cnt += nl->nl_tk_diff); + lex_token = End_Of_Line; + return 1; + } else { + int ok; + while ( (ok = Next_Stream_Token_Obtained()) + && !Token_EQ(lex_token, End_Of_Line) + ) { + /* skip */ } - break; + return ok; } - - return ok; } void Close_Text(enum Pass pass, struct text *txt) { switch (pass) { - case First: + case First_Pass: if (nl_buff) { if (last_tk_cnt != lex_tk_cnt) { /* there were tokens after the last newline */ @@ -134,12 +125,22 @@ Close_Text(enum Pass pass, struct text *txt) { txt->tx_nl_limit = nl_free; } break; - case Second: + case Second_Pass: break; } Close_Stream(); } +void +Free_Text(void) { + if (nl_buff) { + Free(nl_buff); nl_buff = 0; + } + if (Text) { + Free(Text); Text = 0; + } +} + /* NEWLINE CACHING */ /* To speed up pass2 which is interested in token positions at line ends, @@ -150,16 +151,20 @@ Close_Text(enum Pass pass, struct text *txt) { The recording of token position differences at End_Of_Line is optional, and is switched off if - - there is not room enough for the newline buffer. - - a difference would not fit in the field in the struct. + - there is not room enough for the newline buffer; + - a difference would not fit in the field in the struct; + - we are reporting percentages. Switching off is done by freeing the buffer and setting nl_buff to 0. Anybody using nl_buff should therefore test for nl_buff being zero. */ -static void abandon_nl_buff(void); +static void abandon_nl_buff(const char *); static void init_nl_buff(void) { + /* if we are doing percentages, we don't need the nl_buff mechanism */ + if (is_set_option('p')) return; + /* Allocate the newline buffer, if possible */ nl_size = 0 + NL_START; nl_buff = (struct newline *)TryMalloc(sizeof (struct newline)*nl_size); @@ -174,8 +179,7 @@ store_newline(void) { /* allocated array is full; try to increase its size */ size_t new_size = nl_size + nl_size/2; if (new_size < nl_free) { - /* out of address space */ - abandon_nl_buff(); + abandon_nl_buff("out of address space"); return; } @@ -185,8 +189,7 @@ store_newline(void) { ); if (!new_buff) { - /* we failed */ - abandon_nl_buff(); + abandon_nl_buff("out of memry"); return; } nl_buff = new_buff, nl_size = new_size; @@ -199,16 +202,19 @@ store_newline(void) { nl->nl_tk_diff = (nl_tk_diff_t) tk_diff; if (nl->nl_tk_diff != tk_diff) { - /* tk_diff does not fit in nl_tk_diff */ - abandon_nl_buff(); + abandon_nl_buff("tk_diff does not fit in nl_tk_diff"); } } } -static void -abandon_nl_buff(void) { +static void /*ARGSUSED*/ +abandon_nl_buff(const char *msg) { +#undef DB_BUFF +#ifdef DB_BUFF + fprintf(Debug_File, "abandon_nl_buff, %s\n", msg); +#endif /* DB_BUFF */ if (nl_buff) { - Free((char *)nl_buff); + Free(nl_buff); nl_buff = 0; } } diff --git a/judger/core/sim/sim_2_77/text.h b/judger/core/sim/sim_3_01/text.h old mode 100755 new mode 100644 similarity index 64% rename from judger/core/sim/sim_2_77/text.h rename to judger/core/sim/sim_3_01/text.h index 8963be54..4cc67ba0 --- a/judger/core/sim/sim_2_77/text.h +++ b/judger/core/sim/sim_3_01/text.h @@ -1,6 +1,6 @@ /* This file is part of the software similarity tester SIM. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: text.h,v 1.5 2013-04-28 16:30:43 Gebruiker Exp $ + $Id: text.h,v 1.9 2016-07-28 07:00:48 dick Exp $ */ /* Implements the access to the lexical scanner. @@ -9,16 +9,21 @@ information only. */ +/* The input files are called "texts" */ + struct text { const char *tx_fname; /* the file name */ + size_t tx_start; /* index of first token in Token_Array[] + belonging to the text */ + size_t tx_limit; /* index of first position in Token_Array[] + not belonging to the text */ + size_t tx_nl_start; /* possibly newline pointer for pass2 */ + size_t tx_nl_limit; + int tx_EOL_terminated; /* Boolean */ struct position *tx_pos;/* list of positions in this file that are part of a chunk; sorted and updated by Pass 2 */ - size_t tx_start; /* positions in Token_Array[] for the text */ - size_t tx_limit; - size_t tx_nl_start; /* possibly newline pointer for pass2 */ - size_t tx_nl_limit; }; struct position { @@ -33,14 +38,19 @@ struct position { }; extern struct text *Text; /* Text[], one for each input file */ -extern int Number_Of_Texts; /* number of text files */ -extern int Number_Of_New_Texts; /* number of new text files */ +extern int Number_of_Texts; /* number of text files; + this includes the new/old separator + if present; actually a design flaw ZZ + */ +extern int Number_of_New_Texts; /* number of new text files */ extern void Init_Text(int nfiles); -enum Pass {First, Second}; +enum Pass {First_Pass, Second_Pass}; extern int Open_Text(enum Pass pass, struct text *txt); -extern int Next_Text_Token_Obtained(enum Pass pass); +extern int Next_Text_Token_Obtained(void); +extern int Next_Text_EOL_Obtained(void); extern void Close_Text(enum Pass pass, struct text *txt); +extern void Free_Text(void); #ifdef DB_NL_BUFF extern void db_print_nl_buff(size_t start, size_t limit); diff --git a/judger/core/sim/sim_2_77/textlang.l b/judger/core/sim/sim_3_01/textlang.l old mode 100755 new mode 100644 similarity index 68% rename from judger/core/sim/sim_2_77/textlang.l rename to judger/core/sim/sim_3_01/textlang.l index 4939a9d0..8b6dc395 --- a/judger/core/sim/sim_2_77/textlang.l +++ b/judger/core/sim/sim_3_01/textlang.l @@ -1,7 +1,7 @@ %{ /* This file is part of the software similarity tester SIM. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: textlang.l,v 1.14 2013-04-28 16:30:43 Gebruiker Exp $ + $Id: textlang.l,v 1.21 2016-05-13 19:00:55 dick Exp $ */ /* @@ -24,15 +24,14 @@ size_t lex_non_ascii_cnt; /* Language-dependent code */ +const char *Subject = "text"; + void Init_Language(void) { - token_name = "word"; - if (!min_run_string) { - Min_Run_Size = 8; - } - if (!threshold_string) { - Threshold_Percentage = 20; - } + if (is_set_option('f') || is_set_option('F')) + fatal("options -f or -F not applicable in sim_text"); + Token_Name = "word"; + Threshold_Percentage = 20; } /*ARGSUSED*/ @@ -49,26 +48,33 @@ Best_Run_Size(const Token *str, size_t size) { return size; } +static Token +word2token(char *word) { + /* ignore case */ + lower_case(word); + return idf_hashed(word); +} + %} %option noyywrap -WordElem ([-a-zA-Z0-9\200-\377]) +WordElem ([a-zA-Z0-9\200-\377]) TightWord ({WordElem}+) -NonWordElem ([^-a-zA-Z0-9\200-\377]) +NonWordElem ([^a-zA-Z0-9\200-\377]) LooseElem ({WordElem}(" ")) SpacedWord ({LooseElem}+{WordElem}) %% {TightWord} { - return_tk(idf_hashed(yytext)); + return_tk(word2token(yytext)); } {SpacedWord}/{NonWordElem} { /* the / operator works at the top level only */ - return_tk(idf_hashed(yytext)); + return_tk(word2token(yytext)); } diff --git a/judger/core/sim/sim_2_77/token.c b/judger/core/sim/sim_3_01/token.c old mode 100755 new mode 100644 similarity index 88% rename from judger/core/sim/sim_2_77/token.c rename to judger/core/sim/sim_3_01/token.c index 56122a0b..6b0bfd00 --- a/judger/core/sim/sim_2_77/token.c +++ b/judger/core/sim/sim_3_01/token.c @@ -1,6 +1,6 @@ /* This file is part of the software similarity tester SIM. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: token.c,v 2.12 2013-04-28 16:30:43 Gebruiker Exp $ + $Id: token.c,v 2.13 2016-05-01 09:52:55 dick Exp $ */ /* @@ -95,24 +95,6 @@ fprint_token(FILE *ofile, const Token tk) { fprintf(ofile, "!0x%04x!", tki); } - - -#ifdef XXXX - int ch = tki & 0177; - int meta = tki & 0200; - - if (' ' <= ch && ch <= '~') { - fprintf(ofile, "%c%c", (meta ? '#' : ' '), ch); - } - else { - fprintf(ofile, "%c%c", - (meta ? '$' : '^'), - (ch == 0177 ? '?' : ch + '@') - ); - } -#endif - - int Token_EQ(const Token t1, const Token t2) { /* to make sure Token_EQ is indeed called with two Token parameters */ diff --git a/judger/core/sim/sim_2_77/token.h b/judger/core/sim/sim_3_01/token.h old mode 100755 new mode 100644 similarity index 96% rename from judger/core/sim/sim_2_77/token.h rename to judger/core/sim/sim_3_01/token.h index a9f63dfe..39d3bbb6 --- a/judger/core/sim/sim_2_77/token.h +++ b/judger/core/sim/sim_3_01/token.h @@ -1,6 +1,6 @@ /* This file is part of the software similarity tester SIM. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: token.h,v 2.12 2012-06-08 16:04:30 Gebruiker Exp $ + $Id: token.h,v 2.13 2017-02-04 16:58:54 dick Exp $ */ /* @@ -38,7 +38,7 @@ #ifndef _TOKEN_H #define _TOKEN_H -#ifdef lint +#ifdef lint_test /* For security we want to distinguish tokens from integers. Lint is not good at this, so for checking we use a pointer to a weird data type */ @@ -46,7 +46,7 @@ struct for_lint_only {int i;}; typedef struct for_lint_only *Token; #else /* if normal */ typedef unsigned short Token; -#endif /* lint/normal */ +#endif /* lint_test/normal */ #define N_TOKENS (1<<16) #define N_REGULAR_TOKENS (1<<9) diff --git a/judger/core/sim/sim_2_77/tokenarray.c b/judger/core/sim/sim_3_01/tokenarray.c old mode 100755 new mode 100644 similarity index 75% rename from judger/core/sim/sim_2_77/tokenarray.c rename to judger/core/sim/sim_3_01/tokenarray.c index d8dc736b..c922f197 --- a/judger/core/sim/sim_2_77/tokenarray.c +++ b/judger/core/sim/sim_3_01/tokenarray.c @@ -1,15 +1,18 @@ /* This file is part of the software similarity tester SIM. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: tokenarray.c,v 1.15 2013-04-30 20:12:39 Gebruiker Exp $ + $Id: tokenarray.c,v 1.22 2016-05-29 15:26:50 dick Exp $ */ -#include "error.h" +#include +#include + +#include "sim.h" #include "Malloc.h" #include "token.h" #include "lang.h" #include "tokenarray.h" -#define TK_START 16384 /* initial token array size */ +#define Initial_Token_Array_Size 16384 Token *Token_Array; /* to be filled by Malloc() */ static size_t tk_size; /* size of Token_Array[] */ @@ -18,7 +21,7 @@ static size_t tk_free; /* next free position in Token_Array[]*/ void Init_Token_Array(void) { if (Token_Array) Free(Token_Array); - tk_size = TK_START; + tk_size = Initial_Token_Array_Size; Token_Array = (Token *)Malloc(sizeof (Token) * tk_size); tk_free = 1; /* don't use position 0 */ } @@ -38,7 +41,7 @@ Store_Token(Token tk) { if (!new_array) { /* we failed */ - fatal("out of memory"); + fatal("out of memory: too much text"); } Token_Array = new_array, tk_size = new_size; } @@ -47,7 +50,14 @@ Store_Token(Token tk) { Token_Array[tk_free++] = tk; } +void +Free_Token_Array(void) { + if (Token_Array) { + Free(Token_Array); Token_Array = 0; + } +} + size_t -Text_Length(void) { +Token_Array_Length(void) { return tk_free; } diff --git a/judger/core/sim/sim_2_77/tokenarray.h b/judger/core/sim/sim_3_01/tokenarray.h old mode 100755 new mode 100644 similarity index 60% rename from judger/core/sim/sim_2_77/tokenarray.h rename to judger/core/sim/sim_3_01/tokenarray.h index 7b78bbf7..dacd172b --- a/judger/core/sim/sim_2_77/tokenarray.h +++ b/judger/core/sim/sim_3_01/tokenarray.h @@ -1,11 +1,13 @@ /* This file is part of the software similarity tester SIM. Written by Dick Grune, Vrije Universiteit, Amsterdam. - $Id: tokenarray.h,v 1.5 2013-04-28 16:30:43 Gebruiker Exp $ + $Id: tokenarray.h,v 1.7 2016-04-30 18:53:33 dick Exp $ */ /* Interface for the token storage */ extern void Init_Token_Array(void); extern void Store_Token(Token tk); -extern size_t Text_Length(void); /* also first free token position */ +extern void Free_Token_Array(void); +extern size_t Token_Array_Length(void); /* also first free token position */ + extern Token *Token_Array; diff --git a/judger/core/sim/sim_3_01/utf8test.c b/judger/core/sim/sim_3_01/utf8test.c new file mode 100644 index 00000000..1793d5e6 --- /dev/null +++ b/judger/core/sim/sim_3_01/utf8test.c @@ -0,0 +1,13 @@ +#include + +main() { + int 가; + printf("Insurance Review & Assessment Service, 2010) ©≠𒌩우리", __TIMESTAMP__); + printf("나라에서 노인 부양은 핵가족화와 여성의 사회 활동", sizeof (unsigned short int)); + printf("참여가 증가하고 가정에서 노인을 돌볼 수 없어 장기", sizeof (unsigned int)); + printf("요양 기관에서 간호와 관리를 하게 되는 경향이 증가", sizeof (unsigned long int)); + printf("unsigned long long int %u\n", sizeof (unsigned long long int)); + + printf("%llu\n", (unsigned long long int)400LLU); + return 0; +} diff --git a/judger/install/ans2out b/judger/install/ans2out new file mode 100644 index 00000000..957d0014 --- /dev/null +++ b/judger/install/ans2out @@ -0,0 +1,3 @@ +#!/bin/bash +cd $1 +for i in *.ans;do mv $i `basename -s .ans $i`.out; done; diff --git a/judger/install/ch_OI_MODE.sh b/judger/install/ch_OI_MODE.sh new file mode 100644 index 00000000..c391692c --- /dev/null +++ b/judger/install/ch_OI_MODE.sh @@ -0,0 +1,19 @@ +#!/bin/bash +printf "Input OJ Run Mode(OI mode input 1, ACM mode input 0):" +read mode +pkill -9 judged +if test $[mode] -eq 0 +then + sed -i "s/OJ_OI_MODE=1/OJ_OI_MODE=0/g" /home/judge/etc/judge.conf +else if test $[mode] -eq 1 + then + sed -i "s/OJ_OI_MODE=0/OJ_OI_MODE=1/g" /home/judge/etc/judge.conf + fi +fi +if test $[mode] -ne 0 && test $[mode] -ne 1 +then + printf "Please input 0 or 1 !\n" +else + judged + printf "Well Done! OJ_OI_MODE=$[mode] \n" +fi diff --git a/judger/install/db.sql b/judger/install/db.sql index 6b0f8a4c..c78413dc 100755 --- a/judger/install/db.sql +++ b/judger/install/db.sql @@ -1,28 +1,8 @@ --- MySQL dump 10.13 Distrib 5.7.25, for Linux (x86_64) --- --- Host: localhost Database: jol --- ------------------------------------------------------ --- Server version 5.7.25-0ubuntu0.16.04.2 - -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; -/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; -/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!40101 SET NAMES utf8 */; -/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; -/*!40103 SET TIME_ZONE='+00:00' */; -/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; -/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; -/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; -/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; - --- --- Table structure for table `compileinfo` --- -CREATE Database jol; +set names utf8 ; +create database if not exists jol ; use jol; -DROP TABLE IF EXISTS `contest_discuss`; -CREATE TABLE `contest_discuss` ( +CREATE TABLE IF NOT EXISTS `contest_discuss` ( `id` int(11) NOT NULL AUTO_INCREMENT, `user_id` varchar(255) NOT NULL DEFAULT '', `contest_id` int(11) NOT NULL, @@ -32,46 +12,28 @@ CREATE TABLE `contest_discuss` ( `in_date` datetime DEFAULT NULL, `reply_date` datetime DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8; +) ENGINE=MyISAM DEFAULT CHARSET=utf8; -DROP TABLE IF EXISTS `printer_code`; -CREATE TABLE `printer_code` ( +CREATE TABLE IF NOT EXISTS `printer_code` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `user_id` char(20) NOT NULL, + `user_id` char(48) NOT NULL, `contest_id` int(11) NOT NULL, `code` text NOT NULL, `in_date` datetime DEFAULT NULL, `status` int(11) DEFAULT '0', PRIMARY KEY (`id`) -) ENGINE=MyISAM AUTO_INCREMENT=22 DEFAULT CHARSET=utf8; +) ENGINE=MyISAM DEFAULT CHARSET=utf8; -DROP TABLE IF EXISTS `compileinfo`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `compileinfo` ( +CREATE TABLE IF NOT EXISTS `compileinfo` ( `solution_id` int(11) NOT NULL DEFAULT '0', `error` text, PRIMARY KEY (`solution_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; --- --- Dumping data for table `compileinfo` --- +INSERT INTO `compileinfo` (`solution_id`, `error`) VALUES +(1004, 'Main.c:1:10: fatal error: iostream: No such file or directory\n #include \r\n ^~~~~~~~~~\ncompilation terminated.\n'); -LOCK TABLES `compileinfo` WRITE; -/*!40000 ALTER TABLE `compileinfo` DISABLE KEYS */; -/*!40000 ALTER TABLE `compileinfo` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `contest` --- - -DROP TABLE IF EXISTS `contest`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `contest` ( +CREATE TABLE IF NOT EXISTS `contest` ( `contest_id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(255) DEFAULT NULL, `start_time` datetime DEFAULT NULL, @@ -90,55 +52,25 @@ CREATE TABLE `contest` ( `first_prize` int(11) DEFAULT '0', `second_prize` int(11) DEFAULT '0', `third_prize` int(11) DEFAULT '0', - `practice` tinyint(4) DEFAULT NULL, + `practice` tinyint(4) DEFAULT '0', + `isTop` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`contest_id`), KEY `contest_id` (`contest_id`,`defunct`,`private`,`defunct_TA`,`open_source`) USING BTREE, KEY `running_contest` (`start_time`,`end_time`,`practice`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `contest` --- - -LOCK TABLES `contest` WRITE; -/*!40000 ALTER TABLE `contest` DISABLE KEYS */; -/*!40000 ALTER TABLE `contest` ENABLE KEYS */; -UNLOCK TABLES; +) ENGINE=MyISAM AUTO_INCREMENT=1001 DEFAULT CHARSET=utf8; --- --- Table structure for table `contest_excluded_user` --- +INSERT INTO `contest` (`contest_id`, `title`, `start_time`, `end_time`, `defunct`, `description`, `private`, `langmask`, `password`, `user_id`, `user_limit`, `defunct_TA`, `open_source`, `lock_time`, `unlock`, `first_prize`, `second_prize`, `third_prize`, `practice`) VALUES +(1000, '竞赛测试数据', '2020-06-28 09:00:00', '2020-06-28 21:00:00', 'N', '', 0, 67, '', 'admin', 'N', 'N', 'N', 0, 1, 1, 3, 5, 0); -DROP TABLE IF EXISTS `contest_excluded_user`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `contest_excluded_user` ( +CREATE TABLE IF NOT EXISTS `contest_excluded_user` ( `index` int(11) NOT NULL AUTO_INCREMENT, `contest_id` int(11) DEFAULT NULL, `user_id` varchar(255) DEFAULT NULL, PRIMARY KEY (`index`), KEY `contest_id` (`contest_id`,`user_id`) USING BTREE -) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `contest_excluded_user` --- - -LOCK TABLES `contest_excluded_user` WRITE; -/*!40000 ALTER TABLE `contest_excluded_user` DISABLE KEYS */; -/*!40000 ALTER TABLE `contest_excluded_user` ENABLE KEYS */; -UNLOCK TABLES; +) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; --- --- Table structure for table `contest_problem` --- - -DROP TABLE IF EXISTS `contest_problem`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `contest_problem` ( +CREATE TABLE IF NOT EXISTS `contest_problem` ( `index` int(11) NOT NULL AUTO_INCREMENT, `problem_id` int(11) NOT NULL DEFAULT '0', `contest_id` int(11) NOT NULL, @@ -148,154 +80,56 @@ CREATE TABLE `contest_problem` ( PRIMARY KEY (`index`), KEY `contest_id` (`contest_id`) USING BTREE, KEY `problem_id` (`problem_id`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `contest_problem` --- - -LOCK TABLES `contest_problem` WRITE; -/*!40000 ALTER TABLE `contest_problem` DISABLE KEYS */; -/*!40000 ALTER TABLE `contest_problem` ENABLE KEYS */; -UNLOCK TABLES; +) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; --- --- Table structure for table `custominput` --- +INSERT INTO `contest_problem` (`index`, `problem_id`, `contest_id`, `title`, `num`, `score`) VALUES +(1, 1000, 1000, '', 0, 100); -DROP TABLE IF EXISTS `custominput`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `custominput` ( +CREATE TABLE IF NOT EXISTS `custominput` ( `solution_id` int(11) NOT NULL DEFAULT '0', `input_text` text, PRIMARY KEY (`solution_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `custominput` --- - -LOCK TABLES `custominput` WRITE; -/*!40000 ALTER TABLE `custominput` DISABLE KEYS */; -/*!40000 ALTER TABLE `custominput` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `faq_codes` --- -DROP TABLE IF EXISTS `faq_codes`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `faq_codes` ( +CREATE TABLE IF NOT EXISTS `faq_codes` ( `language` varchar(255) CHARACTER SET utf8 NOT NULL, `language_show` varchar(255) CHARACTER SET utf8 DEFAULT NULL, `code` varchar(10000) CHARACTER SET utf8 DEFAULT NULL, PRIMARY KEY (`language`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `faq_codes` --- +) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; -LOCK TABLES `faq_codes` WRITE; -/*!40000 ALTER TABLE `faq_codes` DISABLE KEYS */; INSERT INTO `faq_codes` VALUES ('bash','Bash','#!/bin/bash\r\n \r\nread -a arr\r\n#echo ${#arr[@]}\r\nwhile [ ${#arr[@]} -eq 2 ]\r\ndo\r\nsum=$((${arr[0]}+${arr[1]}))\r\necho \"$sum\"\r\nread -a arr\r\ndone'),('c','C','#include \r\nint main()\r\n{\r\n int a, b;\r\n while(scanf(\"%d%d\", &a, &b) != EOF)\r\n printf(\"%d\\n\", a + b);\r\n}'),('cpp','C++','#include \r\nusing namespace std;\r\nint main()\r\n{\r\n int a, b;\r\n while(cin>> a >> b)\r\n cout << a + b << endl;\r\n return 0;\r\n}'),('csharp','C#','using System;\r\nusing System.Linq;\r\n \r\nnamespace ConsoleApplication\r\n{\r\n public class Program\r\n {\r\n private static void Main()\r\n {\r\n string line;\r\n while((line = Console.ReadLine()) != null)\r\n {\r\n Console.WriteLine(line.Split().Select(int.Parse).Sum());\r\n }\r\n }\r\n }\r\n}'),('java','Java','//package main\r\n//注意不要添加包名称,否则会报错。\r\n \r\nimport java.io.*;\r\nimport java.util.*;\r\nclass Test {\r\n}\r\npublic class Main\r\n{\r\n public static void main(String args[])\r\n {\r\n Scanner cin = new Scanner(System.in);\r\n int a, b;\r\n while(cin.hasNextInt())\r\n {\r\n a = cin.nextInt();\r\n b = cin.nextInt();\r\n System.out.println(a + b);\r\n }\r\n }\r\n}'),('lua','Lua','local count = 0\r\nfunction string.split(str, delimiter)\r\n if str==nil or str==\'\' or delimiter==nil then\r\n return nil\r\n end\r\n \r\n local result = {}\r\n for match in (str..delimiter):gmatch(\"(.-)\"..delimiter) do\r\n table.insert(result, match)\r\n end\r\n return result\r\nend\r\nwhile true do\r\n local line = io.read()\r\n if line == nil or line == \"\" then break end\r\n local tb = string.split(line, \" \")\r\n local sum = 0\r\n for i=1, #tb do\r\n local a = tonumber(tb[i])\r\n sum = sum+a\r\n end\r\n if count>0 then\r\n io.write(\"\\n\")\r\n end\r\n io.write(string.format(\"%d\", sum))\r\n count = count+1\r\nend'),('pascal','Pascal','program p1001(Input,Output);\r\nvar\r\na,b:Integer;\r\nbegin\r\n while not eof(Input) do\r\n begin\r\n Readln(a,b);\r\n Writeln(a+b);\r\n end;\r\nend.'),('perl','Perl','while (defined(my $line = )) {\r\n $line =~ s/\\s+$//;\r\n my @tokens = split(/ +/, $line);\r\n my $a = $tokens[0];\r\n my $b = $tokens[1];\r\n printf(\"%d\\n\", $a + $b);\r\n}'),('php','PHP','< ?php\r\nfunction solveMeFirst($a,$b){\r\n return $a + $b;\r\n}\r\n$handle = fopen (\"php://stdin\",\"r\");\r\n$s = fgets($handle);\r\nwhile ($s != \"\") {\r\n $a = explode(\" \", $s);\r\n $sum = solveMeFirst((int)$a[0],(int)$a[1]);\r\n print ($sum);\r\n print (\"\\n\");\r\n $s = fgets($handle);\r\n}\r\nfclose($handle);\r\n?>'),('python','Python2','#!/usr/bin/env python \r\n# coding=utf-8 \r\n# Python使用的是2.7,缩进可以使用tab、4个空格或2个空格,但是只能任选其中一种,不能多种混用\r\nwhile 1:\r\n a=[] \r\n s = raw_input()\r\n # raw_input()里面不要有任何提示信息\r\n if s != \"\":\r\n for x in s.split(): \r\n a.append(int(x)) \r\n \r\n print sum(a)\r\n else:\r\n break'),('ruby','Ruby','a=gets\r\nwhile a != nil && a != \"\" && a != \"\\r\" && a != \"\\n\" do\r\n arr = a.split(\" \")\r\n sum = 0\r\n arr.each_with_index do |value, index|\r\n sum = sum + value.to_i\r\n end\r\n puts sum.to_s\r\n a=gets\r\nend'); -/*!40000 ALTER TABLE `faq_codes` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `faqs` --- -DROP TABLE IF EXISTS `faqs`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `faqs` ( +CREATE TABLE IF NOT EXISTS `faqs` ( `index` int(11) NOT NULL AUTO_INCREMENT, `content` text, PRIMARY KEY (`index`) -) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; -/*!40101 SET character_set_client = @saved_cs_client */; +) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; --- --- Dumping data for table `faqs` --- - -LOCK TABLES `faqs` WRITE; -/*!40000 ALTER TABLE `faqs` DISABLE KEYS */; -INSERT INTO `faqs` VALUES (1,'## 环境参数\r\n\r\n系统运行于[Ubuntu 14.04](http://www.ubuntu.com/)\r\n对应的编译器和编译选项如下:\r\n\r\n| 语言 | 编译器版本 | 编译选项 |\r\n| :----: | :---------------: | :--------------------------------------: |\r\n| C | gcc 4.8.4 | gcc Main.c -o Main -fno-asm -O2 -Wall -lm --static -std=c99 -DONLINE_JUDGE |\r\n| C++ | g++ 4.8.4 | g++ Main.cc -o Main -fno-asm -O2 -Wall -lm --static -std=c++11 -DONLINE_JUDGE |\r\n| Pascal | Free Pascal 2.6.2 | fpc Main.pas -oMain -O1 -Co -Cr -Ct -Ci |\r\n| Java | openjdk 1.7.0_79 | javac -J-Xms32m -J-Xmx256m Main.java (Languages except C/C++ has 2 more seconds and 128M more memory when running and judging.) |\r\n| Ruby | 1.9.3 | |\r\n| Bash | 4.3.11 | |\r\n| Python2 | 2.7.6 | |\r\n| Python3 | 3.4.3 | |\r\n| PHP | 7.0 | |\r\n| Perl | perl 5 version 18 | |\r\n| C# | mono 3.2.8 | |\r\n| Lua | 5.2.3 | |\r\n\r\n## 例题示范\r\n\r\n你的程序应该从标准输入 `stdin(\'Standard Input\')`获取输出 并将结果输出到标准输出 `stdout(\'Standard Output\')`.例如,在C语言可以使用 `scanf` ,在C++可以使用`cin` 进行输入;在C使用`printf` ,在C++使用`cout`进行输出. 用户程序不允许直接读写文件, 如果这样做可能会判为运行时错误 \"Runtime Error\"。\r\n详见[1000](/OJ/problem.php?id=1000)题hint中各种语言的参考答案。\r\n\r\n## 测评结果释义\r\n\r\n| 评测结果 | 缩写 | 含义 |\r\n| --------------------- | ---- | :--------------------------------------- |\r\n| Pending | PD | 您的提交正排队等待评测。 |\r\n| Pending Rejudge | PR | 因为数据更新或其他原因,系统将重新判你的答案。 |\r\n| Compiling | CP | 您提交的代码正在被编译。 |\r\n| Running & Judging | RN | 您的程序正在运行。 |\r\n| Judging | JG | 我们 正在检查您程序的输出是否正确。 |\r\n| Accepted | AC | 恭喜!您的程序通过了所有数据! |\r\n| Presentation Error | PE | 您的程序输出有格式问题,请检查是否多了或者少了空格 (\' \')、制表符(\'\\t\')或者换行符(\'\\n\') |\r\n| Wrong Answer | WA | 您的程序输出结果错误。 |\r\n| Runtime Error | RE | 您的程序在运行时发生错误。 |\r\n| Time Limit Exceeded | TLE | 您的程序运行的时间已经超出了题目的时间限制。 |\r\n| Memory Limit Exceeded | MLE | 您的程序运行的内存已经超出了题目的内存限制。 |\r\n| Output Limit Exceeded | OLE | 您的程序输出内容太多,超过了这个题目的输出限制。(一般输出超过答案2倍时会触发,强制终止程序,防止恶意输出对硬盘造成压力) |\r\n| Compile Error | CE | 您的程序语法出现问题,编译器无法编译。 |\r\n| System Error | SE | 评判系统内部出现错误 ,我们会尽快处理。 |\r\n| Out Of Contest Time | OCT | 考试已经结束,不再评测提交。 |\r\n\r\n## 常见编译问题\r\n\r\n有的时候你的程序在本地能编译通过,但提交OJ后却显示编译错误。\r\n\r\n这多见于C/C++,一般是因为你本地用的是VS,VS的编译器是MS-VC++,而OJ用的是G++,这两个编译器的标准略有不同,G++更符合标准,下面列出一些常见的导致CE原因:\r\n\r\n* `main` 函数必须返回`int`, ` void main()` 的函数声明会报编译错误。\r\n* `itoa` 不是ansi标准函数.\r\n* `__int64` 不是ANSI标准定义,只能在VC使用, 但是可以使用`long long`声明64位整数。\r\n\r\n如果你使用JAVA语言,请注意类名一定要是`Main`, 否则也会返回CE。\r\n\r\n## 比赛相关\r\n\r\n### 比赛的类型\r\n\r\n目前HZNUOJ有四种类型的比赛:\r\n\r\n* practice,练习赛,只是简单的把题目归个类做做练习,相应题目不会从problemset中隐藏,且通过后可以立即进入题目的status里查看别人的代码。\r\n* public,公开的比赛,任何人均可进入参加。\r\n* password,设有密码保护的比赛,只有输入正确密码才能进入。\r\n* special,特殊比赛,只有使用专门发放的账号才能进入。\r\n\r\n### 比赛赛制\r\n\r\nHZNUOJ所有类型的比赛均为ACM/ICPC赛制。\r\n\r\n每场比赛设有若干道题目,比赛开始后,参赛者需在时限内去解决这些题目。\r\n\r\n每场比赛都设有实时榜单,榜单排名规则也与ACM/ICPC相同。\r\n\r\n### ACM/ICPC排名规则\r\n\r\n每题耗时:Accepted的那一刻距离比赛开始的时间。\r\n\r\n总罚时:所有AC了的题的(耗时+错误次数*20min)的和。\r\n\r\n排名时,AC题数优先,题数相同时按罚时排序。 \r\n\r\n有些比较正式的比赛设有封榜机制,即比赛最后一段时间内的提交结果将隐藏(除了自己都不可见),榜单也会停止更新,新的提交会显示为灰色,留作最后滚榜用。\r\n\r\n#### 滚榜机制介绍\r\n\r\n滚榜是ACM/ICPC系列比赛中一个十分具有特色的机制。\r\n\r\n在正规ACM/ICPC系列比赛中,比赛最后一个小时的提交结果是隐藏的,只有选手本人能看到,在榜单上会显示成代表未知的灰色,以增加比赛紧张气氛。\r\n\r\n然后在颁奖会上,将从榜单最后一名开始,一个个揭晓灰色的未知提交,一旦揭晓的结果为通过,这个人的排名就会上升,否则这个人的排名确定,开始揭晓下一个人,以此类推。这样一来,可以从后往前一个个确定最终排名,一旦名次达到获奖名次内,可以直接进行颁奖。整个过程惊险刺激,是整个比赛的亮点所在。\r\n\r\n## 题目相关\r\n\r\nHZNUOJ的所有题目均在ProblemSet 中,每个题目都有一个唯一的数字编号,称为Problem ID。\r\n\r\n每当你AC了一道题,你就有权限查看这题所有的提交代码,借鉴参考大神们的写法,从而更上一层楼。\r\n\r\n比赛的所有题目,都是从ProblemSet中选出来的,是它的子集。\r\n\r\n当一道题被选入某个非practice模式的比赛中之后,为公平起见,它会在ProblemSet中被隐藏掉,在比赛结束后恢复。\r\n\r\n一般如果题目突然不见了,可能就是这个原因,当然也有可能是因为其他原因而被管理员手动隐藏了。\r\n\r\n当然,一般比赛的题都是新出的,比赛结束后才第一次在ProblemSet中露面。\r\n\r\n选入比赛中的题目,在比赛界面中,会隐藏掉原来的Problem ID,取而代之的是A, B, C...的代号。在比赛结束后,会在标题旁边显示真正的Problem ID,可以点击前往ProblemSet补题。\r\n\r\n## 积分规则\r\n\r\nHZNUOJ的ProblemSet中设有一个榜单,积分和等级的计算规则如下。\r\n\r\n等级由实力(Strength)决定,当实力达到一定值后自然会升级,而实力又从刷题中来,每道题后面均标有分数(Scores),代表AC这道题之后能提升多少实力。一般来说,越少人做的题目,分数越高,一起刷题的人越多,每道题的分数也越高。需要说明的是,用户的实力值是会根据大环境动态变化的(其实是因为分数在动态变化),如果你AC的题目被更多人AC出来了,你的实力值会下降,另外一方面,OJ内有更多强者涌入的时候,你的实力值也会提升。所以,想要快速升级,那就多刷题,刷难题!\r\n\r\n等级划分与小说《斗破苍穹》一致,自低向高分别为斗之气、斗者、斗师、大斗师、斗灵、斗王、斗皇、斗宗、斗尊、斗圣、斗帝,除斗帝外,每一阶又分不同等级,阶数越高,升级越困难。除此之外,每一阶还有不同的代表颜色,该阶等级越高,颜色越深。\r\n\r\n'); -/*!40000 ALTER TABLE `faqs` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `hit_log` --- +INSERT INTO `faqs` VALUES (1,'## 环境参数\r\n\r\n系统运行于[Ubuntu 16+](http://www.ubuntu.com/)\r\n对应的编译器和编译选项如下(系统可能升级编译器版本,这里仅供参考):\r\n\r\n| 语言 | 编译器版本 | 编译选项 |\r\n| :----: | :---------------: | :--------------------------------------: |\r\n| C | gcc 4.8.4 | gcc Main.c -o Main -fno-asm -O2 -Wall -lm --static -std=c99 -DONLINE_JUDGE |\r\n| C++ | g++ 4.8.4 | g++ Main.cc -o Main -fno-asm -O2 -Wall -lm --static -std=c++11 -DONLINE_JUDGE |\r\n| Pascal | Free Pascal 2.6.2 | fpc Main.pas -oMain -O1 -Co -Cr -Ct -Ci |\r\n| Java | openjdk 1.7.0_79 | javac -J-Xms32m -J-Xmx256m Main.java (Languages except C/C++ 2 more seconds and 512M more memory when running and judging.) |\r\n| Ruby | 1.9.3 | |\r\n| Bash | 4.3.11 | |\r\n| Python2 | 2.7.6 | |\r\n| Python3 | 3.4.3 | |\r\n| PHP | 7.0 | |\r\n| Perl | perl 5 version 18 | |\r\n| C# | mono 3.2.8 | |\r\n| Lua | 5.2.3 | |\r\n\r\n## 例题示范\r\n\r\n你的程序应该从标准输入 `stdin(\'Standard Input\')`获取输出 并将结果输出到标准输出 `stdout(\'Standard Output\')`.例如,在C语言可以使用 `scanf` ,在C++可以使用`cin` 进行输入;在C使用`printf` ,在C++使用`cout`进行输出. 用户程序不允许直接读写文件, 如果这样做可能会判为运行时错误 \"Runtime Error\"。\r\n详见[1000](/OJ/problem.php?id=1000)题hint中各种语言的参考答案。\r\n\r\n## 测评结果释义\r\n\r\n| 评测结果 | 缩写 | 含义 |\r\n| --------------------- | ---- | :--------------------------------------- |\r\n| Pending | PD | 您的提交正排队等待评测。 |\r\n| Pending Rejudge | PR | 因为数据更新或其他原因,系统将重新判你的答案。 |\r\n| Compiling | CP | 您提交的代码正在被编译。 |\r\n| Running & Judging | RN | 您的程序正在运行。 |\r\n| Judging | JG | 我们 正在检查您程序的输出是否正确。 |\r\n| Accepted | AC | 恭喜!您的程序通过了所有数据! |\r\n| Presentation Error | PE | 您的程序输出有格式问题,请检查是否多了或者少了空格 (\' \')、制表符(\'\\t\')或者换行符(\'\\n\') |\r\n| Wrong Answer | WA | 您的程序输出结果错误。 |\r\n| Runtime Error | RE | 您的程序在运行时发生错误。 |\r\n| Time Limit Exceeded | TLE | 您的程序运行的时间已经超出了题目的时间限制。 |\r\n| Memory Limit Exceeded | MLE | 您的程序运行的内存已经超出了题目的内存限制。 |\r\n| Output Limit Exceeded | OLE | 您的程序输出内容太多,超过了这个题目的输出限制。(一般输出超过答案2倍时会触发,强制终止程序,防止恶意输出对硬盘造成压力) |\r\n| Compile Error | CE | 您的程序语法出现问题,编译器无法编译。 |\r\n| System Error | SE | 评判系统内部出现错误 ,我们会尽快处理。 |\r\n| Out Of Contest Time | OCT | 考试已经结束,不再评测提交。 |\r\n\r\n## 常见编译问题\r\n\r\n有的时候你的程序在本地能编译通过,但提交OJ后却显示编译错误。\r\n\r\n这多见于C/C++,一般是因为你本地用的是VS,VS的编译器是MS-VC++,而OJ用的是G++,这两个编译器的标准略有不同,G++更符合标准,下面列出一些常见的导致CE原因:\r\n\r\n* `main` 函数必须返回`int`, ` void main()` 的函数声明会报编译错误。\r\n* `itoa` 不是ansi标准函数.\r\n* `__int64` 不是ANSI标准定义,只能在VC使用, 但是可以使用`long long`声明64位整数。\r\n\r\n如果你使用JAVA语言,请注意类名一定要是`Main`, 否则也会返回CE。\r\n\r\n## 比赛相关\r\n\r\n### 比赛的类型\r\n\r\n目前HZNUOJ有四种类型的比赛:\r\n\r\n* practice,练习赛,只是简单的把题目归个类做做练习,相应题目不会从problemset中隐藏,且通过后可以立即进入题目的status里查看别人的代码。\r\n* public,公开的比赛,任何人均可进入参加。\r\n* password,设有密码保护的比赛,只有输入正确密码才能进入。\r\n* special,特殊比赛,只有使用专门发放的账号才能进入。\r\n\r\n### 比赛赛制\r\n\r\nHZNUOJ所有类型的比赛均为ACM/ICPC赛制。\r\n\r\n每场比赛设有若干道题目,比赛开始后,参赛者需在时限内去解决这些题目。\r\n\r\n每场比赛都设有实时榜单,榜单排名规则也与ACM/ICPC相同。\r\n\r\n### ACM/ICPC排名规则\r\n\r\n每题耗时:Accepted的那一刻距离比赛开始的时间。\r\n\r\n总罚时:所有AC了的题的(耗时+错误次数*20min)的和。\r\n\r\n排名时,AC题数优先,题数相同时按罚时排序。 \r\n\r\n有些比较正式的比赛设有封榜机制,即比赛最后一段时间内的提交结果将隐藏(除了自己都不可见),榜单也会停止更新,新的提交会显示为灰色,留作最后滚榜用。\r\n\r\n#### 滚榜机制介绍\r\n\r\n滚榜是ACM/ICPC系列比赛中一个十分具有特色的机制。\r\n\r\n在正规ACM/ICPC系列比赛中,比赛最后一个小时的提交结果是隐藏的,只有选手本人能看到,在榜单上会显示成代表未知的灰色,以增加比赛紧张气氛。\r\n\r\n然后在颁奖会上,将从榜单最后一名开始,一个个揭晓灰色的未知提交,一旦揭晓的结果为通过,这个人的排名就会上升,否则这个人的排名确定,开始揭晓下一个人,以此类推。这样一来,可以从后往前一个个确定最终排名,一旦名次达到获奖名次内,可以直接进行颁奖。整个过程惊险刺激,是整个比赛的亮点所在。\r\n\r\n## 题目相关\r\n\r\nHZNUOJ的所有题目均在ProblemSet 中,每个题目都有一个唯一的数字编号,称为Problem ID。\r\n\r\n每当你AC了一道题,你就有权限查看这题所有的提交代码,借鉴参考大神们的写法,从而更上一层楼。\r\n\r\n比赛的所有题目,都是从ProblemSet中选出来的,是它的子集。\r\n\r\n当一道题被选入某个非practice模式的比赛中之后,为公平起见,它会在ProblemSet中被隐藏掉,在比赛结束后恢复。\r\n\r\n一般如果题目突然不见了,可能就是这个原因,当然也有可能是因为其他原因而被管理员手动隐藏了。\r\n\r\n当然,一般比赛的题都是新出的,比赛结束后才第一次在ProblemSet中露面。\r\n\r\n选入比赛中的题目,在比赛界面中,会隐藏掉原来的Problem ID,取而代之的是A, B, C...的代号。在比赛结束后,会在标题旁边显示真正的Problem ID,可以点击前往ProblemSet补题。\r\n\r\n## 积分规则\r\n\r\nHZNUOJ的ProblemSet中设有一个榜单,积分和等级的计算规则如下。\r\n\r\n等级由实力(Strength)决定,当实力达到一定值后自然会升级,而实力又从刷题中来,每道题后面均标有分数(Scores),代表AC这道题之后能提升多少实力。一般来说,越少人做的题目,分数越高,一起刷题的人越多,每道题的分数也越高。需要说明的是,用户的实力值是会根据大环境动态变化的(其实是因为分数在动态变化),如果你AC的题目被更多人AC出来了,你的实力值会下降,另外一方面,OJ内有更多强者涌入的时候,你的实力值也会提升。所以,想要快速升级,那就多刷题,刷难题!\r\n\r\n等级划分与小说《斗破苍穹》一致,自低向高分别为斗之气、斗者、斗师、大斗师、斗灵、斗王、斗皇、斗宗、斗尊、斗圣、斗帝,除斗帝外,每一阶又分不同等级,阶数越高,升级越困难。除此之外,每一阶还有不同的代表颜色,该阶等级越高,颜色越深。\r\n\r\n'); -DROP TABLE IF EXISTS `hit_log`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `hit_log` ( +CREATE TABLE IF NOT EXISTS `hit_log` ( `index` int(11) NOT NULL AUTO_INCREMENT, - `ip` varchar(20) DEFAULT NULL, + `ip` varchar(46) DEFAULT NULL, `path` text, `time` datetime DEFAULT NULL, `user_id` text, PRIMARY KEY (`index`), KEY `time` (`time`), KEY `ip` (`ip`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `hit_log` --- - -LOCK TABLES `hit_log` WRITE; -/*!40000 ALTER TABLE `hit_log` DISABLE KEYS */; -/*!40000 ALTER TABLE `hit_log` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `loginlog` --- +) ENGINE=MyISAM DEFAULT CHARSET=utf8; -DROP TABLE IF EXISTS `loginlog`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `loginlog` ( +CREATE TABLE IF NOT EXISTS `loginlog` ( `index` int(11) NOT NULL AUTO_INCREMENT, `user_id` varchar(20) NOT NULL DEFAULT '', `password` varchar(40) DEFAULT NULL, - `ip` varchar(100) DEFAULT NULL, + `ip` varchar(46) DEFAULT NULL, `time` datetime DEFAULT NULL, PRIMARY KEY (`index`), KEY `user_time_index` (`user_id`,`time`) -) ENGINE=MyISAM AUTO_INCREMENT=7 DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `loginlog` --- - -LOCK TABLES `loginlog` WRITE; -/*!40000 ALTER TABLE `loginlog` DISABLE KEYS */; -INSERT INTO `loginlog` VALUES (1,'admin','No Saved','127.0.0.1','2019-03-12 17:29:20'),(2,'admin','No Saved','127.0.0.1','2019-03-12 17:29:39'),(3,'admin','No Saved','127.0.0.1','2019-03-12 17:33:27'),(4,'admin','No Saved','127.0.0.1','2019-03-12 17:38:04'),(5,'admin','No Saved','127.0.0.1','2019-03-12 17:39:13'),(6,'admin','No Saved','127.0.0.1','2019-03-13 15:32:27'); -/*!40000 ALTER TABLE `loginlog` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `mail` --- +) ENGINE=MyISAM DEFAULT CHARSET=utf8; -DROP TABLE IF EXISTS `mail`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `mail` ( +CREATE TABLE IF NOT EXISTS `mail` ( `mail_id` int(11) NOT NULL AUTO_INCREMENT, `to_user` varchar(48) NOT NULL DEFAULT '' COMMENT 'user_id', `from_user` varchar(48) NOT NULL DEFAULT '' COMMENT 'user_id', @@ -308,25 +142,8 @@ CREATE TABLE `mail` ( PRIMARY KEY (`mail_id`), KEY `uid` (`to_user`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `mail` --- - -LOCK TABLES `mail` WRITE; -/*!40000 ALTER TABLE `mail` DISABLE KEYS */; -/*!40000 ALTER TABLE `mail` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `message` --- -DROP TABLE IF EXISTS `message`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `message` ( +CREATE TABLE IF NOT EXISTS `message` ( `message_id` int(11) NOT NULL AUTO_INCREMENT, `problem_id` int(11) NOT NULL DEFAULT '0', `parent_id` int(11) NOT NULL DEFAULT '0', @@ -340,25 +157,8 @@ CREATE TABLE `message` ( `defunct` char(1) NOT NULL DEFAULT 'N', PRIMARY KEY (`message_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `message` --- -LOCK TABLES `message` WRITE; -/*!40000 ALTER TABLE `message` DISABLE KEYS */; -/*!40000 ALTER TABLE `message` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `news` --- - -DROP TABLE IF EXISTS `news`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `news` ( +CREATE TABLE IF NOT EXISTS `news` ( `news_id` int(11) NOT NULL AUTO_INCREMENT, `user_id` varchar(48) NOT NULL DEFAULT '' COMMENT 'user_id', `title` varchar(200) NOT NULL DEFAULT '', @@ -368,27 +168,10 @@ CREATE TABLE `news` ( `defunct` char(1) NOT NULL DEFAULT 'N', PRIMARY KEY (`news_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `news` --- - -LOCK TABLES `news` WRITE; -/*!40000 ALTER TABLE `news` DISABLE KEYS */; -/*!40000 ALTER TABLE `news` ENABLE KEYS */; -UNLOCK TABLES; --- --- Table structure for table `online` --- - -DROP TABLE IF EXISTS `online`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `online` ( +CREATE TABLE IF NOT EXISTS `online` ( `hash` varchar(32) COLLATE utf8_unicode_ci NOT NULL, - `ip` varchar(20) CHARACTER SET utf8 NOT NULL DEFAULT '', + `ip` varchar(46) CHARACTER SET utf8 NOT NULL DEFAULT '', `ua` varchar(255) CHARACTER SET utf8 NOT NULL DEFAULT '', `refer` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `lastmove` int(10) NOT NULL, @@ -397,50 +180,17 @@ CREATE TABLE `online` ( PRIMARY KEY (`hash`), UNIQUE KEY `hash` (`hash`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `online` --- - -LOCK TABLES `online` WRITE; -/*!40000 ALTER TABLE `online` DISABLE KEYS */; -/*!40000 ALTER TABLE `online` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `privilege` --- -DROP TABLE IF EXISTS `privilege`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `privilege` ( +CREATE TABLE IF NOT EXISTS `privilege` ( `index` int(11) NOT NULL AUTO_INCREMENT, - `user_id` char(20) NOT NULL DEFAULT '', + `user_id` char(48) NOT NULL DEFAULT '', `rightstr` char(30) NOT NULL DEFAULT '', PRIMARY KEY (`index`) ) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `privilege` --- -LOCK TABLES `privilege` WRITE; -/*!40000 ALTER TABLE `privilege` DISABLE KEYS */; INSERT INTO `privilege` VALUES (1,'admin','root'); -/*!40000 ALTER TABLE `privilege` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `privilege_distribution` --- -DROP TABLE IF EXISTS `privilege_distribution`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `privilege_distribution` ( +CREATE TABLE IF NOT EXISTS `privilege_distribution` ( `group_name` varchar(255) CHARACTER SET utf8 NOT NULL DEFAULT '', `enter_admin_page` tinyint(4) DEFAULT NULL, `edit_default_problem` tinyint(4) DEFAULT NULL, @@ -463,51 +213,19 @@ CREATE TABLE `privilege_distribution` ( `upload_files` tinyint(4) DEFAULT NULL, `watch_solution_video` tinyint(4) DEFAULT NULL, PRIMARY KEY (`group_name`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=COMPACT; -/*!40101 SET character_set_client = @saved_cs_client */; +) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT; --- --- Dumping data for table `privilege_distribution` --- - -LOCK TABLES `privilege_distribution` WRITE; -/*!40000 ALTER TABLE `privilege_distribution` DISABLE KEYS */; INSERT INTO `privilege_distribution` VALUES ('administrator',1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1),('exam_user',1,0,1,0,1,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0),('hznu_viewer',1,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0),('root',1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),('source_browser',1,0,1,0,0,1,0,0,0,0,0,0,1,1,1,1,1,1,0,0),('teacher',1,1,1,0,1,1,0,1,0,0,0,1,1,1,1,1,1,1,1,1),('teacher_assistant',1,1,1,0,1,0,0,0,0,0,0,1,1,1,1,1,1,0,1,0); -/*!40000 ALTER TABLE `privilege_distribution` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `privilege_groups` --- -DROP TABLE IF EXISTS `privilege_groups`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `privilege_groups` ( +CREATE TABLE IF NOT EXISTS `privilege_groups` ( `group_order` int(11) NOT NULL DEFAULT '0', `group_name` varchar(255) CHARACTER SET utf8 DEFAULT NULL, PRIMARY KEY (`group_order`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=COMPACT; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `privilege_groups` --- +) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT; -LOCK TABLES `privilege_groups` WRITE; -/*!40000 ALTER TABLE `privilege_groups` DISABLE KEYS */; INSERT INTO `privilege_groups` VALUES (0,'root'),(1,'administrator'),(2,'teacher'),(3,'teacher_assistant'),(4,'source_browser'),(5,'hznu_viewer'),(6,'exam_user'); -/*!40000 ALTER TABLE `privilege_groups` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `problem` --- -DROP TABLE IF EXISTS `problem`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `problem` ( +CREATE TABLE IF NOT EXISTS `problem` ( `problem_id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(200) NOT NULL DEFAULT '', `description` text, @@ -534,29 +252,13 @@ CREATE TABLE `problem` ( `problemset` varchar(255) DEFAULT NULL, PRIMARY KEY (`problem_id`), UNIQUE KEY `problem_id` (`problem_id`) USING BTREE, - KEY `spj` (`problemset`,`defunct`,`spj`,`problem_id`) USING BTREE, KEY `score` (`score`,`accepted`) ) ENGINE=MyISAM AUTO_INCREMENT=1001 DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `problem` --- - -LOCK TABLES `problem` WRITE; -/*!40000 ALTER TABLE `problem` DISABLE KEYS */; -INSERT INTO `problem` VALUES (1000,'A+B','1','1','1',NULL,NULL,'0','','','','2019-03-13 16:10:36',1,256,'Y',1,1,0,NULL,100.00,NULL,NULL,NULL,'default'); -/*!40000 ALTER TABLE `problem` ENABLE KEYS */; -UNLOCK TABLES; --- --- Table structure for table `problem_samples` --- +INSERT INTO `problem` (`problem_id`, `title`, `description`, `input`, `output`, `sample_input`, `sample_output`, `spj`, `hint`, `author`, `source`, `in_date`, `time_limit`, `memory_limit`, `defunct`, `accepted`, `submit`, `solved_user`, `submit_user`, `score`, `tag1`, `tag2`, `tag3`, `problemset`) VALUES +(1000, 'A+B', '

\n Calculate a+b\n

', '

\n Two integer a,b (0<=a,b<=10)\n

', '

\n Output a+b\n

', NULL, NULL, '0', '

\n Q: Where are the input and the output? A: Your program shall always read input from stdin (Standard Input) and write output to stdout (Standard Output). For example, you can use \"scanf\" in C or \"cin\" in C++ to read from stdin, and use \"printf\" in C or \"cout\" in C++ to write to stdout. You shall not output any extra data to standard output other than that required by the problem, otherwise you will get a \"Wrong Answer\". User programs are not allowed to open and read from/write to files. You will get a \"Runtime Error\" or a \"Wrong Answer\" if you try to do so. Here is a sample solution for problem 1000 using C++/G++:\n

\n
#include <iostream>\nusing namespace std;\nint main(){\n    int a, b, sum;\n    cin >> a >> b;\n	sum = a + b;\n    cout << sum;\n    return 0;\n}
\n

\n It\"s important that the return type of main() must be int when you use G++/GCC,or you may get compile error. Here is a sample solution for problem 1000 using C/GCC:\n

\n
#include <stdio.h>\nint main()\n{\n    int a, b, sum;\n    scanf(\"%d%d\", &a, &b);\n	sum = a + b;\n    printf(\"%d\\n\", sum);\n    return 0;\n}
\n

\n Here is a sample solution for problem 1000 using PASCAL:\n

\n
program p1000(Input,Output); \nvar \n  a,b:Integer; \nbegin \n   Readln(a,b); \n   Writeln(a+b); \nend.
\n

\n Here is a sample solution for problem 1000 using JAVA: Now java compiler is jdk 1.5, next is program for 1000\n

\n
import java.io.*;\nimport java.util.*;\npublic class Main\n{\n    public static void main(String args[]) throws Exception\n    {\n        Scanner cin=new Scanner(System.in);\n        int a=cin.nextInt();int b=cin.nextInt();\n        System.out.println(a+b);\n    }\n}
\n

\n Old program for jdk 1.4\n

\n
import java.io.*;\nimport java.util.*;\npublic class Main\n{\n    public static void main (String args[]) throws Exception\n    {\n        BufferedReader stdin = \n            new BufferedReader(\n                new InputStreamReader(System.in));\n        String line = stdin.readLine();\n        StringTokenizer st = new StringTokenizer(line);\n        int a = Integer.parseInt(st.nextToken());\n        int b = Integer.parseInt(st.nextToken());\n        System.out.println(a+b);\n    }\n}
', '', '基础操作题', '2019-03-13 16:10:36', 1, 256, 'N', 3, 4, 0, NULL, '100.00', NULL, NULL, NULL, 'default'); -DROP TABLE IF EXISTS `problem_samples`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `problem_samples` ( +CREATE TABLE IF NOT EXISTS `problem_samples` ( `problem_id` int(11) NOT NULL, `sample_id` int(11) NOT NULL DEFAULT '0', `input` text CHARACTER SET utf8, @@ -564,168 +266,72 @@ CREATE TABLE `problem_samples` ( `show_after` int(11) DEFAULT '0', PRIMARY KEY (`problem_id`,`sample_id`), KEY `problem_id` (`problem_id`,`sample_id`) USING BTREE -) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `problem_samples` --- +) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; -LOCK TABLES `problem_samples` WRITE; -/*!40000 ALTER TABLE `problem_samples` DISABLE KEYS */; INSERT INTO `problem_samples` VALUES (1000,0,'1 2','3',0); -/*!40000 ALTER TABLE `problem_samples` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `problemset` --- -DROP TABLE IF EXISTS `problemset`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `problemset` ( - `index` int(11) NOT NULL, +CREATE TABLE IF NOT EXISTS `problemset` ( + `index` int(11) NOT NULL AUTO_INCREMENT, `set_name` varchar(255) CHARACTER SET utf8 NOT NULL DEFAULT '', `set_name_show` varchar(255) CHARACTER SET utf8 NOT NULL, + `access_level` tinyint NOT NULL DEFAULT 0, PRIMARY KEY (`index`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=COMPACT; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `problemset` --- +) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT AUTO_INCREMENT=2; -LOCK TABLES `problemset` WRITE; -/*!40000 ALTER TABLE `problemset` DISABLE KEYS */; -INSERT INTO `problemset` VALUES (1,'default','DEFAULT'); -/*!40000 ALTER TABLE `problemset` ENABLE KEYS */; -UNLOCK TABLES; +INSERT INTO `problemset` VALUES (1,'default','DEFAULT', 0); --- --- Table structure for table `reply` --- - -DROP TABLE IF EXISTS `reply`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `reply` ( +CREATE TABLE IF NOT EXISTS `reply` ( `rid` int(11) NOT NULL AUTO_INCREMENT, `author_id` varchar(48) NOT NULL DEFAULT '' COMMENT 'user_id', `time` datetime NOT NULL, `content` text NOT NULL, `topic_id` int(11) NOT NULL, `status` int(2) NOT NULL DEFAULT '0', - `ip` varchar(30) NOT NULL, + `ip` varchar(46) NOT NULL, PRIMARY KEY (`rid`), KEY `author_id` (`author_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `reply` --- - -LOCK TABLES `reply` WRITE; -/*!40000 ALTER TABLE `reply` DISABLE KEYS */; -/*!40000 ALTER TABLE `reply` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `runtimeinfo` --- -DROP TABLE IF EXISTS `runtimeinfo`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `runtimeinfo` ( +CREATE TABLE IF NOT EXISTS `runtimeinfo` ( `solution_id` int(11) NOT NULL DEFAULT '0', `error` text, PRIMARY KEY (`solution_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `runtimeinfo` --- - -LOCK TABLES `runtimeinfo` WRITE; -/*!40000 ALTER TABLE `runtimeinfo` DISABLE KEYS */; -/*!40000 ALTER TABLE `runtimeinfo` ENABLE KEYS */; -UNLOCK TABLES; --- --- Table structure for table `sim` --- +INSERT INTO `runtimeinfo` (`solution_id`, `error`) VALUES +(1005, '========Failed test [test0.out]=========\n=======Diff out 100 lines=====\n1c1\n< 16\n---\n> 3\n\\ No newline at end of file\n==============================\n========Failed test [test1.out]=========\n=======Diff out 100 lines=====\n1c1\n< 15\n---\n> 3\n\\ No newline at end of file\n==============================\n========Failed test [test2.out]=========\n=======Diff out 100 lines=====\n1c1\n< 0\n---\n> 3\n\\ No newline at end of file\n==============================\n'); -DROP TABLE IF EXISTS `sim`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `sim` ( +CREATE TABLE IF NOT EXISTS `sim` ( `s_id` int(11) NOT NULL, `sim_s_id` int(11) DEFAULT NULL, `sim` int(11) DEFAULT NULL, PRIMARY KEY (`s_id`), KEY `Index_sim_id` (`sim_s_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `sim` --- - -LOCK TABLES `sim` WRITE; -/*!40000 ALTER TABLE `sim` DISABLE KEYS */; -/*!40000 ALTER TABLE `sim` ENABLE KEYS */; -UNLOCK TABLES; --- --- Table structure for table `slide` --- - -DROP TABLE IF EXISTS `slide`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `slide` ( +CREATE TABLE IF NOT EXISTS `slide` ( `img_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `url` varchar(200) NOT NULL, `defunct` char(1) DEFAULT NULL, PRIMARY KEY (`img_id`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `slide` --- - -LOCK TABLES `slide` WRITE; -/*!40000 ALTER TABLE `slide` DISABLE KEYS */; -/*!40000 ALTER TABLE `slide` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `solution` --- +) ENGINE=MyISAM DEFAULT CHARSET=utf8; -DROP TABLE IF EXISTS `solution`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `solution` ( +CREATE TABLE IF NOT EXISTS `solution` ( `solution_id` int(11) NOT NULL AUTO_INCREMENT, `problem_id` int(11) DEFAULT '0', - `user_id` char(20) NOT NULL, + `user_id` char(48) NOT NULL, `time` int(11) NOT NULL DEFAULT '0', `memory` int(11) NOT NULL DEFAULT '0', `in_date` datetime NOT NULL, `result` smallint(6) NOT NULL DEFAULT '0', `language` tinyint(4) NOT NULL DEFAULT '0', - `ip` char(15) NOT NULL, + `ip` char(46) NOT NULL, `contest_id` int(11) DEFAULT NULL, `valid` tinyint(4) NOT NULL DEFAULT '1', `num` tinyint(4) NOT NULL DEFAULT '-1', `code_length` int(11) NOT NULL DEFAULT '0', `judgetime` datetime DEFAULT NULL, - `pass_rate` decimal(2,2) unsigned NOT NULL DEFAULT '0.00', + `pass_rate` decimal(3,2) unsigned NOT NULL DEFAULT '0.00', `judger` char(16) NOT NULL DEFAULT 'LOCAL', PRIMARY KEY (`solution_id`), KEY `pid` (`problem_id`), @@ -733,140 +339,59 @@ CREATE TABLE `solution` ( KEY `in_date` (`in_date`) USING BTREE, KEY `uid` (`user_id`,`result`) USING BTREE, KEY `cid` (`contest_id`,`result`,`num`) USING BTREE -) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `solution` --- - -LOCK TABLES `solution` WRITE; -/*!40000 ALTER TABLE `solution` DISABLE KEYS */; -INSERT INTO `solution` VALUES (1,1000,'admin',0,1120,'2019-03-13 16:10:55',4,1,'127.0.0.1',NULL,1,-1,75,'2019-03-13 16:10:56',0.00,'172.17.0.1'); -/*!40000 ALTER TABLE `solution` ENABLE KEYS */; -UNLOCK TABLES; +) ENGINE=MyISAM AUTO_INCREMENT=1006 DEFAULT CHARSET=utf8; --- --- Table structure for table `solution_video_watch_log` --- +INSERT INTO `solution` (`solution_id`, `problem_id`, `user_id`, `time`, `memory`, `in_date`, `result`, `language`, `ip`, `contest_id`, `valid`, `num`, `code_length`, `judgetime`, `pass_rate`, `judger`) VALUES +(1001, 1000, 'admin', 0, 1120, '2019-03-13 16:10:55', 4, 0, '127.0.0.1', NULL, 1, -1, 124, '2019-03-13 16:10:56', '0.00', '172.17.0.1'), +(1002, 1000, 'admin', 0, 2020, '2019-03-13 16:10:56', 4, 1, '127.0.0.1', NULL, 1, -1, 135, '2019-03-13 16:10:57', '0.00', '172.17.0.1'), +(1003, 1000, 'admin', 0, 2084, '2020-06-28 09:46:45', 4, 1, '127.0.0.1', 1000, 1, 0, 147, '2020-06-28 09:46:45', '1.00', '172.17.0.1'), +(1004, 1000, 'admin', 0, 0, '2020-06-28 09:47:08', 11, 0, '127.0.0.1', 1000, 1, 0, 147, '2020-06-28 09:47:09', '0.00', '172.17.0.1'), +(1005, 1000, 'admin', 0, 2020, '2020-06-28 17:11:11', 6, 1, '127.0.0.1', 1000, 1, 0, 137, '2020-06-28 17:11:13', '0.25', '172.17.0.1'); -DROP TABLE IF EXISTS `solution_video_watch_log`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `solution_video_watch_log` ( +CREATE TABLE IF NOT EXISTS `solution_video_watch_log` ( `index` int(11) NOT NULL AUTO_INCREMENT, `video_id` int(11) NOT NULL, `user_id` varchar(255) CHARACTER SET utf8 DEFAULT NULL, `time` datetime DEFAULT NULL, PRIMARY KEY (`index`), KEY `video_id` (`video_id`) USING BTREE -) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `solution_video_watch_log` --- - -LOCK TABLES `solution_video_watch_log` WRITE; -/*!40000 ALTER TABLE `solution_video_watch_log` DISABLE KEYS */; -/*!40000 ALTER TABLE `solution_video_watch_log` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `source_code` --- +) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; -DROP TABLE IF EXISTS `source_code`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `source_code` ( +CREATE TABLE IF NOT EXISTS `source_code` ( `solution_id` int(11) NOT NULL, `source` text NOT NULL, PRIMARY KEY (`solution_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `source_code` --- -LOCK TABLES `source_code` WRITE; -/*!40000 ALTER TABLE `source_code` DISABLE KEYS */; -INSERT INTO `source_code` VALUES (1,'#include \r\nint main(){\r\n puts(\"3\");\r\n return 0;\r\n}'); -/*!40000 ALTER TABLE `source_code` ENABLE KEYS */; -UNLOCK TABLES; +INSERT INTO `source_code` (`solution_id`, `source`) VALUES +(1001, '#include \nvoid main()\n{\n int a, b, sum;\n scanf(\"%d%d\", &a, &b);\n sum = a + b;\n printf(\"%d\", sum);\n}\n '), +(1002, '#include \nusing namespace std;\nint main(){\n int a, b, sum;\n cin >> a >> b;\n sum = a + b;\n cout << sum;\n return 0;\n}\n'), +(1003, '#include \r\nusing namespace std;\r\nint main(){\r\n int a,b;\r\n cin >> a >> b;\r\n cout << a+b << endl;\r\n return 0;\r\n}'), +(1004, '#include \r\nusing namespace std;\r\nint main(){\r\n int a,b;\r\n cin >> a >> b;\r\n cout << a+b << endl;\r\n return 0;\r\n}'), +(1005, '#include \r\nusing namespace std;\r\nint main(){\r\n int a,b;\r\n cin >> a >> b;\r\n cout << 3;\r\n return 0;\r\n}'); --- --- Table structure for table `source_code_user` --- - -DROP TABLE IF EXISTS `source_code_user`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `source_code_user` ( +CREATE TABLE IF NOT EXISTS `source_code_user` ( `solution_id` int(11) NOT NULL, `source` text NOT NULL, PRIMARY KEY (`solution_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `source_code_user` --- - -LOCK TABLES `source_code_user` WRITE; -/*!40000 ALTER TABLE `source_code_user` DISABLE KEYS */; -INSERT INTO `source_code_user` VALUES (1,'#include \r\nint main(){\r\n puts(\"3\");\r\n return 0;\r\n}'); -/*!40000 ALTER TABLE `source_code_user` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Temporary table structure for view `squid` --- -DROP TABLE IF EXISTS `squid`; -/*!50001 DROP VIEW IF EXISTS `squid`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE VIEW `squid` AS SELECT - 1 AS `user_id`, - 1 AS `password`, - 1 AS `solved`*/; -SET character_set_client = @saved_cs_client; - --- --- Table structure for table `tag` --- +INSERT INTO `source_code_user` (`solution_id`, `source`) VALUES +(1001, '#include \nvoid main()\n{\n int a, b, sum;\n scanf(\"%d%d\", &a, &b);\n sum = a + b;\n printf(\"%d\", sum);\n}\n '), +(1002, '#include \nusing namespace std;\nint main(){\n int a, b, sum;\n cin >> a >> b;\n sum = a + b;\n cout << sum;\n return 0;\n}\n'), +(1003, '#include \r\nusing namespace std;\r\nint main(){\r\n int a,b;\r\n cin >> a >> b;\r\n cout << a+b << endl;\r\n return 0;\r\n}'), +(1004, '#include \r\nusing namespace std;\r\nint main(){\r\n int a,b;\r\n cin >> a >> b;\r\n cout << a+b << endl;\r\n return 0;\r\n}'), +(1005, '#include \r\nusing namespace std;\r\nint main(){\r\n int a,b;\r\n cin >> a >> b;\r\n cout << 3;\r\n return 0;\r\n}'); -DROP TABLE IF EXISTS `tag`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `tag` ( +CREATE TABLE IF NOT EXISTS `tag` ( `index` int(11) NOT NULL AUTO_INCREMENT, `problem_id` int(10) unsigned zerofill NOT NULL, `user_id` varchar(100) CHARACTER SET utf8 NOT NULL, `tag` varchar(100) CHARACTER SET utf8 NOT NULL, PRIMARY KEY (`index`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `tag` --- - -LOCK TABLES `tag` WRITE; -/*!40000 ALTER TABLE `tag` DISABLE KEYS */; -/*!40000 ALTER TABLE `tag` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `team` --- +) ENGINE=MyISAM DEFAULT CHARSET=utf8; -DROP TABLE IF EXISTS `team`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `team` ( +CREATE TABLE IF NOT EXISTS `team` ( `user_id` varchar(30) NOT NULL, `prefix` varchar(30) DEFAULT NULL, `NO` int(10) DEFAULT NULL, @@ -881,28 +406,11 @@ CREATE TABLE `team` ( `school` varchar(100) DEFAULT NULL, `accesstime` datetime DEFAULT NULL, `reg_time` datetime DEFAULT NULL, - `ip` varchar(20) DEFAULT NULL, + `ip` varchar(46) DEFAULT NULL, PRIMARY KEY (`contest_id`,`user_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `team` --- - -LOCK TABLES `team` WRITE; -/*!40000 ALTER TABLE `team` DISABLE KEYS */; -/*!40000 ALTER TABLE `team` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `topic` --- -DROP TABLE IF EXISTS `topic`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `topic` ( +CREATE TABLE IF NOT EXISTS `topic` ( `tid` int(11) NOT NULL AUTO_INCREMENT, `title` varbinary(60) NOT NULL, `status` int(2) NOT NULL DEFAULT '0', @@ -913,32 +421,15 @@ CREATE TABLE `topic` ( PRIMARY KEY (`tid`), KEY `cid` (`cid`,`pid`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; --- --- Dumping data for table `topic` --- - -LOCK TABLES `topic` WRITE; -/*!40000 ALTER TABLE `topic` DISABLE KEYS */; -/*!40000 ALTER TABLE `topic` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `users` --- - -DROP TABLE IF EXISTS `users`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `users` ( +CREATE TABLE IF NOT EXISTS `users` ( `user_id` varchar(48) NOT NULL DEFAULT '' COMMENT 'user_id', `stu_id` varchar(20) DEFAULT NULL, `email` varchar(100) DEFAULT NULL, `submit` int(11) DEFAULT '0', `solved` int(11) DEFAULT '0', `defunct` char(1) NOT NULL DEFAULT 'N', - `ip` varchar(20) NOT NULL DEFAULT '', + `ip` varchar(46) NOT NULL DEFAULT '', `accesstime` datetime DEFAULT NULL, `volume` int(11) NOT NULL DEFAULT '1', `volume_c` int(11) DEFAULT NULL, @@ -960,28 +451,13 @@ CREATE TABLE `users` ( `like` int(9) DEFAULT '0', `dislike` int(9) DEFAULT '0', `tag` varchar(250) DEFAULT NULL, + `access_level` tinyint NOT NULL DEFAULT 0, PRIMARY KEY (`user_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `users` --- -LOCK TABLES `users` WRITE; -/*!40000 ALTER TABLE `users` DISABLE KEYS */; -INSERT INTO `users` VALUES ('admin','','temp@temp.com',1,1,'N','::1','2019-03-12 16:34:09',1,NULL,1,'YQn1zuOVuWzSNcU5WwkMauvCGw00YzNl','2019-03-12 16:34:09','','admin','','其它','斗之气五段',100.00,'#b6b6b6',NULL,NULL,NULL,NULL,NULL,0,0,NULL); -/*!40000 ALTER TABLE `users` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `users_cache` --- +INSERT INTO `users` VALUES ('admin','','temp@temp.com',1,1,'N','::1','2019-03-12 16:34:09',1,NULL,1,'YQn1zuOVuWzSNcU5WwkMauvCGw00YzNl','2019-03-12 16:34:09','','admin','','其它','斗之气五段',100.00,'#b6b6b6',NULL,NULL,NULL,NULL,NULL,0,0,NULL,0); -DROP TABLE IF EXISTS `users_cache`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `users_cache` ( +CREATE TABLE IF NOT EXISTS `users_cache` ( `user_id` varchar(48) NOT NULL, `class` varchar(15) CHARACTER SET utf8 NOT NULL, `AC_day` int(10) unsigned zerofill DEFAULT NULL, @@ -989,27 +465,11 @@ CREATE TABLE `users_cache` ( `activity` int(10) unsigned zerofill DEFAULT NULL, `total_score` decimal(10,2) unsigned zerofill DEFAULT NULL, PRIMARY KEY (`user_id`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `users_cache` --- +) ENGINE=MyISAM DEFAULT CHARSET=utf8; -LOCK TABLES `users_cache` WRITE; -/*!40000 ALTER TABLE `users_cache` DISABLE KEYS */; INSERT INTO `users_cache` VALUES ('admin','',0000000001,0000000001,NULL,NULL); -/*!40000 ALTER TABLE `users_cache` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `users_cache_array` --- -DROP TABLE IF EXISTS `users_cache_array`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `users_cache_array` ( +CREATE TABLE IF NOT EXISTS `users_cache_array` ( `index` int(11) NOT NULL AUTO_INCREMENT, `user_id` varchar(48) NOT NULL, `type` varchar(15) NOT NULL, @@ -1017,70 +477,69 @@ CREATE TABLE `users_cache_array` ( `value_int` int(10) unsigned zerofill NOT NULL, `value_double` decimal(10,2) unsigned zerofill DEFAULT NULL, PRIMARY KEY (`index`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `users_cache_array` --- - -LOCK TABLES `users_cache_array` WRITE; -/*!40000 ALTER TABLE `users_cache_array` DISABLE KEYS */; -/*!40000 ALTER TABLE `users_cache_array` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Final view structure for view `squid` --- - -/*!50001 DROP VIEW IF EXISTS `squid`*/; -/*!50001 SET @saved_cs_client = @@character_set_client */; -/*!50001 SET @saved_cs_results = @@character_set_results */; -/*!50001 SET @saved_col_connection = @@collation_connection */; -/*!50001 SET character_set_client = utf8 */; -/*!50001 SET character_set_results = utf8 */; -/*!50001 SET collation_connection = utf8_general_ci */; -/*!50001 CREATE ALGORITHM=UNDEFINED */ -/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `squid` AS select `users`.`user_id` AS `user_id`,`users`.`password` AS `password`,`users`.`solved` AS `solved` from `users` where ((`users`.`solved` > pow(2,(minute(now()) / 8))) or `users`.`user_id` in (select `privilege`.`user_id` AS `user_id` from `privilege` where (`privilege`.`rightstr` = 'source_browser'))) */; -/*!50001 SET character_set_client = @saved_cs_client */; -/*!50001 SET character_set_results = @saved_cs_results */; -/*!50001 SET collation_connection = @saved_col_connection */; -/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; - -/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; -/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; -/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; -/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; -/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; +) ENGINE=MyISAM DEFAULT CHARSET=utf8; --- Dump completed on 2019-03-13 17:03:43 --- ---------------------------- --- Table structure for `class_list` --- ---------------------------- -DROP TABLE IF EXISTS `class_list`; -CREATE TABLE `class_list` ( +CREATE TABLE IF NOT EXISTS `class_list` ( `class_name` varchar(100) NOT NULL, `enrollment_year` smallint(4) NOT NULL, PRIMARY KEY (`class_name`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; --- ---------------------------- --- Records of class_list --- ---------------------------- + INSERT INTO `class_list` VALUES ('其它', '0'); --- ---------------------------- --- Table structure for `reg_code` --- ---------------------------- -CREATE TABLE `reg_code` ( +CREATE TABLE IF NOT EXISTS `reg_code` ( `class_name` varchar(100) NOT NULL, `reg_code` varchar(100) NOT NULL, `remain_num` smallint(4) NOT NULL, PRIMARY KEY (`class_name`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +INSERT INTO `reg_code` VALUES ('其它', '', '0'); + +CREATE TABLE IF NOT EXISTS `course` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `section` varchar(255) NOT NULL, + `order` int(11) NOT NULL DEFAULT '10000', + `parent_id` int(11) NOT NULL DEFAULT '0', + `isProblem` tinyint(1) NOT NULL DEFAULT '0', + PRIMARY KEY (`id`) +) ENGINE=MyISAM AUTO_INCREMENT=12 DEFAULT CHARSET=utf8; -- ---------------------------- --- Records of reg_code +-- Records of course -- ---------------------------- -INSERT INTO `reg_code` VALUES ('其它', '', '0'); \ No newline at end of file +INSERT INTO `course` VALUES ('1', '入门篇', '0', '0', '0'); +INSERT INTO `course` VALUES ('2', '九阴真经', '1', '0', '0'); +INSERT INTO `course` VALUES ('3', '九阳神功', '2', '0', '0'); +INSERT INTO `course` VALUES ('4', '葵花宝典', '3', '0', '0'); +INSERT INTO `course` VALUES ('5', '辟邪剑谱', '4', '0', '0'); +INSERT INTO `course` VALUES ('6', '平台操作题', '0', '1', '0'); +INSERT INTO `course` VALUES ('7', '输出题入门', '1', '1', '0'); +INSERT INTO `course` VALUES ('8', '计算题入门', '2', '1', '0'); +INSERT INTO `course` VALUES ('9', '分支结构入门', '3', '1', '0'); +INSERT INTO `course` VALUES ('10', '循环结构入门', '4', '1', '0'); +INSERT INTO `course` VALUES ('11', '1000', '0', '6', '1'); + +-- 添加触发器,防止同一用户类似代码提交第二遍时被认定为抄袭 +delimiter // +drop trigger if exists simfilter// +create trigger simfilter +before insert on sim +for each row +begin + declare new_user_id varchar(64); + declare old_user_id varchar(64); + select user_id from solution where solution_id=new.s_id into new_user_id; + select user_id from solution where solution_id=new.sim_s_id into old_user_id; + if old_user_id=new_user_id then + set new.s_id=0; + end if; +end;// +delimiter ; + +-- +-- Final view structure for view `squid` +-- + +DROP VIEW IF EXISTS `squid`; +CREATE VIEW `squid` AS select `users`.`user_id` AS `user_id`,`users`.`password` AS `password`,`users`.`solved` AS `solved` from `users` +where ((`users`.`solved` > pow(2,(minute(now()) / 8))) or `users`.`user_id` in (select `privilege`.`user_id` AS `user_id` from `privilege` where (`privilege`.`rightstr` = 'source_browser'))); diff --git a/judger/install/hustoj b/judger/install/hustoj new file mode 100644 index 00000000..2d024962 --- /dev/null +++ b/judger/install/hustoj @@ -0,0 +1,69 @@ +#!/bin/bash +# +### BEGIN INIT INFO +# Provides: hustoj +# Required-Start: $remote_fs $syslog +# Required-Stop: $remote_fs $syslog +# Should-Start: $network $time +# Should-Stop: $network $time +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Start and stop the hustoj database server daemon +# Description: Controls the main MySQL database server daemon "hustojd" +# and its wrapper script "judged". +### END INIT INFO +# +set -e +set -u +${DEBIAN_SCRIPT_DEBUG:+ set -v -x} + +test -x /usr/bin/judged || exit 0 + +. /lib/lsb/init-functions + +SELF=$(cd $(dirname $0); pwd -P)/$(basename $0) +CONF=/home/judge/etc/judge.conf + +# Safeguard (relative paths, core dumps..) +cd / +umask 077 + +# hustojadmin likes to read /root/.my.cnf. This is usually not what I want +# as many admins e.g. only store a password without a username there and +# so break my scripts. +export HOME=/home/judge + +## Checks if there is a server running and if so if it is accessible. +# +# check_dead also fails if there is a lost hustojd in the process list +# +# main() +# + +case "${1:-''}" in + 'start') + # Start daemon + export LANG=zh_CN.UTF-8 + /usr/bin/judged + ;; + 'stop') + pkill -9 judged + ;; + 'restart'|'reload'|'force-reload') + pkill -9 judged + sleep 3 + /usr/bin/judged + ;; + 'status') + ps aux|grep judged + ;; + + *) + echo "Usage: $SELF start|stop|restart|reload|force-reload|status" + exit 1 + ;; +esac + +# Some success paths end up returning non-zero so exit 0 explicitly. See +# bug #739846. +exit 0 diff --git a/judger/install/hustoj2HZNUOJ-ubuntu16+.sh b/judger/install/hustoj2HZNUOJ-ubuntu16+.sh new file mode 100644 index 00000000..ebdf14fd --- /dev/null +++ b/judger/install/hustoj2HZNUOJ-ubuntu16+.sh @@ -0,0 +1,142 @@ +#!/bin/bash +reset +echo "" +echo " ██ ██ ████████ ████ ██ ██ ██ ███████ ██" +echo "░██ ░██░░░░░░██ ░██░██ ░██░██ ░██ ██░░░░░██ ░██" +echo "░██ ░██ ██ ░██░░██ ░██░██ ░██ ██ ░░██ ░██" +echo "░██████████ ██ ░██ ░░██ ░██░██ ░██░██ ░██ ░██" +echo "░██░░░░░░██ ██ ░██ ░░██░██░██ ░██░██ ░██ ░██" +echo "░██ ░██ ██ ░██ ░░████░██ ░██░░██ ██ ██ ░██" +echo "░██ ░██ ████████░██ ░░███░░███████ ░░███████ ░░█████ " +echo "░░ ░░ ░░░░░░░░ ░░ ░░░ ░░░░░░░ ░░░░░░░ ░░░░░ " +echo "" +WEBBASE=/home/judge/src/web/ +DBUSER=`cat /etc/mysql/debian.cnf |grep user|head -1|awk '{print $3}'` +DBPASS=`cat /etc/mysql/debian.cnf |grep password|head -1|awk '{print $3}'` +echo "Backup hustoj's webpage to /home/judge/webbackup." +mkdir -p /home/judge/webbackup +mv -f $WEBBASE /home/judge/webbackup/ +echo "Copy HZNUOJ's web/OJ Dir to hustoj." +cd ../.. +cp -R web/OJ/. $WEBBASE +echo "Restore hustoj's upload Dir." +cp -R /home/judge/webbackup/web/upload/ $WEBBASE +chown -R www-data $WEBBASE +sed -i "s/DB_USER=\"root\"/DB_USER=\"$DBUSER\"/g" $WEBBASE/include/static.php +sed -i "s/DB_PASS=\"root\"/DB_PASS=\"$DBPASS\"/g" $WEBBASE/include/static.php +sed -i "s/OJ_HOME=\"\/OJ\/\"/OJ_HOME=\".\/\"/g" $WEBBASE/include/static.php +cd ./judger/install +echo "Update Datebase from hustoj to HZNUOJ, please wait." +mysql -h localhost -u$DBUSER -p$DBPASS < hustoj2HZNUOJ.sql +echo "" +echo "OJ Configuration:" +echo "" +printf "1-Please input OJ's name, press Enter for default name(argument:\$OJ_NAME): " +read ojname +if test "$ojname" != "" +then + sed -i "s/OJ_NAME=\"HZNUOJ\"/OJ_NAME=\"$ojname\"/g" $WEBBASE/include/static.php +fi +echo "" +echo "2-Please select the UI language.(argument:\$OJ_LANG)" +echo " 1) Chinese" +echo " 2) English" +temp=0 +while test $temp != 1 -a $temp != 2 +do + printf "#? " + read temp +done +if test $temp = 1 +then + sed -i "s/OJ_LANG=\"en\"/OJ_LANG=\"cn\"/g" $WEBBASE/include/static.php +else + sed -i "s/OJ_LANG=\"cn\"/OJ_LANG=\"en\"/g" $WEBBASE/include/static.php +fi +echo "" +echo "3-Please select running mode.(argument:OJ_OI_MODE)" +echo " 1) OI Mode (Middle school)" +echo " 2) ACM Mode (University)" +temp=0 +while test $temp != 1 -a $temp != 2 +do + printf "#? " + read temp +done +if test $temp = 1 +then + sed -i "s/OJ_OI_MODE=0/OJ_OI_MODE=1/g" /home/judge/etc/judge.conf +else + sed -i "s/OJ_OI_MODE=1/OJ_OI_MODE=0/g" /home/judge/etc/judge.conf +fi +echo "" +echo "4-Please select trun on/off the code share mode.(argument:\$OJ_AUTO_SHARE)" +echo " 1) Trun on (All of users are able to view all submissions after solving this problem.)" +echo " 2) Trun off (Only administrators are able to view all submissions.)" +temp=0 +while test $temp != 1 -a $temp != 2 +do + printf "#? " + read temp +done +if test $temp = 2 +then + sed -i "s/OJ_AUTO_SHARE=true/OJ_AUTO_SHARE=false/g" $WEBBASE/include/static.php +else + sed -i "s/OJ_AUTO_SHARE=false/OJ_AUTO_SHARE=true/g" $WEBBASE/include/static.php +fi +echo "" +echo "5-Please select trun on/off show the WA/CE information in reinfo/ceinfo page.(argument:\$OJ_SHOW_DIFF)" +echo "1) Trun on (All of users are able to view the WA/CE information of their own code.)" +echo "2) Trun off (Only administrators are able to view the WA/CE information.)" +temp=0 +while test $temp != 1 -a $temp != 2 +do + printf "#? " + read temp +done +if test $temp = 2 +then + sed -i "s/OJ_SHOW_DIFF=true/OJ_SHOW_DIFF=false/g" $WEBBASE/include/static.php +else + sed -i "s/OJ_SHOW_DIFF=false/OJ_SHOW_DIFF=true/g" $WEBBASE/include/static.php +fi +echo "" +echo "6-Please select trun on/off source code similarity detection.(argument:\$OJ_SIM, OJ_SIM_ENABLE)" +echo "1) Trun on" +echo "2) Trun off" +temp=0 +while test $temp != 1 -a $temp != 2 +do + printf "#? " + read temp +done +if test $temp = 2 +then + sed -i "s/OJ_SIM=true/OJ_SIM=false/g" $WEBBASE/include/static.php + sed -i "s/OJ_SIM_ENABLE=1/OJ_SIM_ENABLE=0/g" /home/judge/etc/judge.conf +else + sed -i "s/OJ_SIM=false/OJ_SIM=true/g" $WEBBASE/include/static.php + sed -i "s/OJ_SIM_ENABLE=0/OJ_SIM_ENABLE=1/g" /home/judge/etc/judge.conf +fi +echo "" +echo "7-Please select trun on/off show the contest's solution in status page.(argument:\$OJ_show_contestSolutionInStatus)" +echo "1) Trun on (contest's solution will be show in status page and contest-status page.)" +echo "2) Trun off (contest's solution will be show in contest-status page only.)" +temp=0 +while test $temp != 1 -a $temp != 2 +do + printf "#? " + read temp +done +if test $temp = 1 +then + sed -i "s/OJ_show_contestSolutionInStatus=false/OJ_show_contestSolutionInStatus=true/g" $WEBBASE/include/static.php +else + sed -i "s/OJ_show_contestSolutionInStatus=true/OJ_show_contestSolutionInStatus=false/g" $WEBBASE/include/static.php +fi +echo "The update have successfully completed!" +echo "" +echo "Remember your database account for OJ:" +echo "username:$DBUSER" +echo "password:$DBPASS" diff --git a/judger/install/hustoj2HZNUOJ.sql b/judger/install/hustoj2HZNUOJ.sql new file mode 100644 index 00000000..5fae3073 --- /dev/null +++ b/judger/install/hustoj2HZNUOJ.sql @@ -0,0 +1,449 @@ +set names utf8; +alter database jol character set utf8; +use jol; + +CREATE TABLE `course` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `section` varchar(255) NOT NULL, + `order` int(11) NOT NULL DEFAULT '10000', + `parent_id` int(11) NOT NULL DEFAULT '0', + `isProblem` tinyint(1) NOT NULL DEFAULT '0', + PRIMARY KEY (`id`) +) ENGINE=MyISAM AUTO_INCREMENT=12 DEFAULT CHARSET=utf8; +-- ---------------------------- +-- Records of course +-- ---------------------------- +INSERT INTO `course` VALUES ('1', '入门篇', '0', '0', '0'); +INSERT INTO `course` VALUES ('2', '九阴真经', '1', '0', '0'); +INSERT INTO `course` VALUES ('3', '九阳神功', '2', '0', '0'); +INSERT INTO `course` VALUES ('4', '葵花宝典', '3', '0', '0'); +INSERT INTO `course` VALUES ('5', '辟邪剑谱', '4', '0', '0'); +INSERT INTO `course` VALUES ('6', '平台操作题', '0', '1', '0'); +INSERT INTO `course` VALUES ('7', '输出题入门', '1', '1', '0'); +INSERT INTO `course` VALUES ('8', '计算题入门', '2', '1', '0'); +INSERT INTO `course` VALUES ('9', '分支结构入门', '3', '1', '0'); +INSERT INTO `course` VALUES ('10', '循环结构入门', '4', '1', '0'); +INSERT INTO `course` VALUES ('11', '1000', '0', '6', '1'); + +CREATE TABLE `class_list` ( + `class_name` varchar(100) NOT NULL, + `enrollment_year` smallint(4) NOT NULL, + PRIMARY KEY (`class_name`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; +INSERT INTO `class_list` VALUES ('其它', '0'); + +CREATE TABLE `contest_discuss` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `user_id` varchar(255) NOT NULL DEFAULT '', + `contest_id` int(11) NOT NULL, + `problem_id` int(11) DEFAULT NULL, + `content` text, + `reply` text, + `in_date` datetime DEFAULT NULL, + `reply_date` datetime DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +CREATE TABLE `contest_excluded_user` ( + `index` int(11) NOT NULL AUTO_INCREMENT, + `contest_id` int(11) DEFAULT NULL, + `user_id` varchar(255) DEFAULT NULL, + PRIMARY KEY (`index`), + KEY `contest_id` (`contest_id`,`user_id`) USING BTREE +) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; + +CREATE TABLE `faq_codes` ( + `language` varchar(255) CHARACTER SET utf8 NOT NULL, + `language_show` varchar(255) CHARACTER SET utf8 DEFAULT NULL, + `code` varchar(10000) CHARACTER SET utf8 DEFAULT NULL, + PRIMARY KEY (`language`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; +INSERT INTO `faq_codes` VALUES ('bash','Bash','#!/bin/bash\r\n \r\nread -a arr\r\n#echo ${#arr[@]}\r\nwhile [ ${#arr[@]} -eq 2 ]\r\ndo\r\nsum=$((${arr[0]}+${arr[1]}))\r\necho \"$sum\"\r\nread -a arr\r\ndone'),('c','C','#include \r\nint main()\r\n{\r\n int a, b;\r\n while(scanf(\"%d%d\", &a, &b) != EOF)\r\n printf(\"%d\\n\", a + b);\r\n}'),('cpp','C++','#include \r\nusing namespace std;\r\nint main()\r\n{\r\n int a, b;\r\n while(cin>> a >> b)\r\n cout << a + b << endl;\r\n return 0;\r\n}'),('csharp','C#','using System;\r\nusing System.Linq;\r\n \r\nnamespace ConsoleApplication\r\n{\r\n public class Program\r\n {\r\n private static void Main()\r\n {\r\n string line;\r\n while((line = Console.ReadLine()) != null)\r\n {\r\n Console.WriteLine(line.Split().Select(int.Parse).Sum());\r\n }\r\n }\r\n }\r\n}'),('java','Java','//package main\r\n//注意不要添加包名称,否则会报错。\r\n \r\nimport java.io.*;\r\nimport java.util.*;\r\nclass Test {\r\n}\r\npublic class Main\r\n{\r\n public static void main(String args[])\r\n {\r\n Scanner cin = new Scanner(System.in);\r\n int a, b;\r\n while(cin.hasNextInt())\r\n {\r\n a = cin.nextInt();\r\n b = cin.nextInt();\r\n System.out.println(a + b);\r\n }\r\n }\r\n}'),('lua','Lua','local count = 0\r\nfunction string.split(str, delimiter)\r\n if str==nil or str==\'\' or delimiter==nil then\r\n return nil\r\n end\r\n \r\n local result = {}\r\n for match in (str..delimiter):gmatch(\"(.-)\"..delimiter) do\r\n table.insert(result, match)\r\n end\r\n return result\r\nend\r\nwhile true do\r\n local line = io.read()\r\n if line == nil or line == \"\" then break end\r\n local tb = string.split(line, \" \")\r\n local sum = 0\r\n for i=1, #tb do\r\n local a = tonumber(tb[i])\r\n sum = sum+a\r\n end\r\n if count>0 then\r\n io.write(\"\\n\")\r\n end\r\n io.write(string.format(\"%d\", sum))\r\n count = count+1\r\nend'),('pascal','Pascal','program p1001(Input,Output);\r\nvar\r\na,b:Integer;\r\nbegin\r\n while not eof(Input) do\r\n begin\r\n Readln(a,b);\r\n Writeln(a+b);\r\n end;\r\nend.'),('perl','Perl','while (defined(my $line = )) {\r\n $line =~ s/\\s+$//;\r\n my @tokens = split(/ +/, $line);\r\n my $a = $tokens[0];\r\n my $b = $tokens[1];\r\n printf(\"%d\\n\", $a + $b);\r\n}'),('php','PHP','< ?php\r\nfunction solveMeFirst($a,$b){\r\n return $a + $b;\r\n}\r\n$handle = fopen (\"php://stdin\",\"r\");\r\n$s = fgets($handle);\r\nwhile ($s != \"\") {\r\n $a = explode(\" \", $s);\r\n $sum = solveMeFirst((int)$a[0],(int)$a[1]);\r\n print ($sum);\r\n print (\"\\n\");\r\n $s = fgets($handle);\r\n}\r\nfclose($handle);\r\n?>'),('python','Python2','#!/usr/bin/env python \r\n# coding=utf-8 \r\n# Python使用的是2.7,缩进可以使用tab、4个空格或2个空格,但是只能任选其中一种,不能多种混用\r\nwhile 1:\r\n a=[] \r\n s = raw_input()\r\n # raw_input()里面不要有任何提示信息\r\n if s != \"\":\r\n for x in s.split(): \r\n a.append(int(x)) \r\n \r\n print sum(a)\r\n else:\r\n break'),('ruby','Ruby','a=gets\r\nwhile a != nil && a != \"\" && a != \"\\r\" && a != \"\\n\" do\r\n arr = a.split(\" \")\r\n sum = 0\r\n arr.each_with_index do |value, index|\r\n sum = sum + value.to_i\r\n end\r\n puts sum.to_s\r\n a=gets\r\nend'); + +CREATE TABLE `faqs` ( + `index` int(11) NOT NULL AUTO_INCREMENT, + `content` text, + PRIMARY KEY (`index`) +) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; +INSERT INTO `faqs` VALUES (1,'## 环境参数\r\n\r\n系统运行于[Ubuntu 14.04](http://www.ubuntu.com/)\r\n对应的编译器和编译选项如下:\r\n\r\n| 语言 | 编译器版本 | 编译选项 |\r\n| :----: | :---------------: | :--------------------------------------: |\r\n| C | gcc 4.8.4 | gcc Main.c -o Main -fno-asm -O2 -Wall -lm --static -std=c99 -DONLINE_JUDGE |\r\n| C++ | g++ 4.8.4 | g++ Main.cc -o Main -fno-asm -O2 -Wall -lm --static -std=c++11 -DONLINE_JUDGE |\r\n| Pascal | Free Pascal 2.6.2 | fpc Main.pas -oMain -O1 -Co -Cr -Ct -Ci |\r\n| Java | openjdk 1.7.0_79 | javac -J-Xms32m -J-Xmx256m Main.java (Languages except C/C++ has 2 more seconds and 128M more memory when running and judging.) |\r\n| Ruby | 1.9.3 | |\r\n| Bash | 4.3.11 | |\r\n| Python2 | 2.7.6 | |\r\n| Python3 | 3.4.3 | |\r\n| PHP | 7.0 | |\r\n| Perl | perl 5 version 18 | |\r\n| C# | mono 3.2.8 | |\r\n| Lua | 5.2.3 | |\r\n\r\n## 例题示范\r\n\r\n你的程序应该从标准输入 `stdin(\'Standard Input\')`获取输出 并将结果输出到标准输出 `stdout(\'Standard Output\')`.例如,在C语言可以使用 `scanf` ,在C++可以使用`cin` 进行输入;在C使用`printf` ,在C++使用`cout`进行输出. 用户程序不允许直接读写文件, 如果这样做可能会判为运行时错误 \"Runtime Error\"。\r\n详见[1000](/OJ/problem.php?id=1000)题hint中各种语言的参考答案。\r\n\r\n## 测评结果释义\r\n\r\n| 评测结果 | 缩写 | 含义 |\r\n| --------------------- | ---- | :--------------------------------------- |\r\n| Pending | PD | 您的提交正排队等待评测。 |\r\n| Pending Rejudge | PR | 因为数据更新或其他原因,系统将重新判你的答案。 |\r\n| Compiling | CP | 您提交的代码正在被编译。 |\r\n| Running & Judging | RN | 您的程序正在运行。 |\r\n| Judging | JG | 我们 正在检查您程序的输出是否正确。 |\r\n| Accepted | AC | 恭喜!您的程序通过了所有数据! |\r\n| Presentation Error | PE | 您的程序输出有格式问题,请检查是否多了或者少了空格 (\' \')、制表符(\'\\t\')或者换行符(\'\\n\') |\r\n| Wrong Answer | WA | 您的程序输出结果错误。 |\r\n| Runtime Error | RE | 您的程序在运行时发生错误。 |\r\n| Time Limit Exceeded | TLE | 您的程序运行的时间已经超出了题目的时间限制。 |\r\n| Memory Limit Exceeded | MLE | 您的程序运行的内存已经超出了题目的内存限制。 |\r\n| Output Limit Exceeded | OLE | 您的程序输出内容太多,超过了这个题目的输出限制。(一般输出超过答案2倍时会触发,强制终止程序,防止恶意输出对硬盘造成压力) |\r\n| Compile Error | CE | 您的程序语法出现问题,编译器无法编译。 |\r\n| System Error | SE | 评判系统内部出现错误 ,我们会尽快处理。 |\r\n| Out Of Contest Time | OCT | 考试已经结束,不再评测提交。 |\r\n\r\n## 常见编译问题\r\n\r\n有的时候你的程序在本地能编译通过,但提交OJ后却显示编译错误。\r\n\r\n这多见于C/C++,一般是因为你本地用的是VS,VS的编译器是MS-VC++,而OJ用的是G++,这两个编译器的标准略有不同,G++更符合标准,下面列出一些常见的导致CE原因:\r\n\r\n* `main` 函数必须返回`int`, ` void main()` 的函数声明会报编译错误。\r\n* `itoa` 不是ansi标准函数.\r\n* `__int64` 不是ANSI标准定义,只能在VC使用, 但是可以使用`long long`声明64位整数。\r\n\r\n如果你使用JAVA语言,请注意类名一定要是`Main`, 否则也会返回CE。\r\n\r\n## 比赛相关\r\n\r\n### 比赛的类型\r\n\r\n目前HZNUOJ有四种类型的比赛:\r\n\r\n* practice,练习赛,只是简单的把题目归个类做做练习,相应题目不会从problemset中隐藏,且通过后可以立即进入题目的status里查看别人的代码。\r\n* public,公开的比赛,任何人均可进入参加。\r\n* password,设有密码保护的比赛,只有输入正确密码才能进入。\r\n* special,特殊比赛,只有使用专门发放的账号才能进入。\r\n\r\n### 比赛赛制\r\n\r\nHZNUOJ所有类型的比赛均为ACM/ICPC赛制。\r\n\r\n每场比赛设有若干道题目,比赛开始后,参赛者需在时限内去解决这些题目。\r\n\r\n每场比赛都设有实时榜单,榜单排名规则也与ACM/ICPC相同。\r\n\r\n### ACM/ICPC排名规则\r\n\r\n每题耗时:Accepted的那一刻距离比赛开始的时间。\r\n\r\n总罚时:所有AC了的题的(耗时+错误次数*20min)的和。\r\n\r\n排名时,AC题数优先,题数相同时按罚时排序。 \r\n\r\n有些比较正式的比赛设有封榜机制,即比赛最后一段时间内的提交结果将隐藏(除了自己都不可见),榜单也会停止更新,新的提交会显示为灰色,留作最后滚榜用。\r\n\r\n#### 滚榜机制介绍\r\n\r\n滚榜是ACM/ICPC系列比赛中一个十分具有特色的机制。\r\n\r\n在正规ACM/ICPC系列比赛中,比赛最后一个小时的提交结果是隐藏的,只有选手本人能看到,在榜单上会显示成代表未知的灰色,以增加比赛紧张气氛。\r\n\r\n然后在颁奖会上,将从榜单最后一名开始,一个个揭晓灰色的未知提交,一旦揭晓的结果为通过,这个人的排名就会上升,否则这个人的排名确定,开始揭晓下一个人,以此类推。这样一来,可以从后往前一个个确定最终排名,一旦名次达到获奖名次内,可以直接进行颁奖。整个过程惊险刺激,是整个比赛的亮点所在。\r\n\r\n## 题目相关\r\n\r\nHZNUOJ的所有题目均在ProblemSet 中,每个题目都有一个唯一的数字编号,称为Problem ID。\r\n\r\n每当你AC了一道题,你就有权限查看这题所有的提交代码,借鉴参考大神们的写法,从而更上一层楼。\r\n\r\n比赛的所有题目,都是从ProblemSet中选出来的,是它的子集。\r\n\r\n当一道题被选入某个非practice模式的比赛中之后,为公平起见,它会在ProblemSet中被隐藏掉,在比赛结束后恢复。\r\n\r\n一般如果题目突然不见了,可能就是这个原因,当然也有可能是因为其他原因而被管理员手动隐藏了。\r\n\r\n当然,一般比赛的题都是新出的,比赛结束后才第一次在ProblemSet中露面。\r\n\r\n选入比赛中的题目,在比赛界面中,会隐藏掉原来的Problem ID,取而代之的是A, B, C...的代号。在比赛结束后,会在标题旁边显示真正的Problem ID,可以点击前往ProblemSet补题。\r\n\r\n## 积分规则\r\n\r\nHZNUOJ的ProblemSet中设有一个榜单,积分和等级的计算规则如下。\r\n\r\n等级由实力(Strength)决定,当实力达到一定值后自然会升级,而实力又从刷题中来,每道题后面均标有分数(Scores),代表AC这道题之后能提升多少实力。一般来说,越少人做的题目,分数越高,一起刷题的人越多,每道题的分数也越高。需要说明的是,用户的实力值是会根据大环境动态变化的(其实是因为分数在动态变化),如果你AC的题目被更多人AC出来了,你的实力值会下降,另外一方面,OJ内有更多强者涌入的时候,你的实力值也会提升。所以,想要快速升级,那就多刷题,刷难题!\r\n\r\n等级划分与小说《斗破苍穹》一致,自低向高分别为斗之气、斗者、斗师、大斗师、斗灵、斗王、斗皇、斗宗、斗尊、斗圣、斗帝,除斗帝外,每一阶又分不同等级,阶数越高,升级越困难。除此之外,每一阶还有不同的代表颜色,该阶等级越高,颜色越深。\r\n\r\n'); + +CREATE TABLE `hit_log` ( + `index` int(11) NOT NULL AUTO_INCREMENT, + `ip` varchar(46) DEFAULT NULL, + `path` text, + `time` datetime DEFAULT NULL, + `user_id` text, + PRIMARY KEY (`index`), + KEY `time` (`time`), + KEY `ip` (`ip`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +CREATE TABLE `printer_code` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `user_id` char(20) NOT NULL, + `contest_id` int(11) NOT NULL, + `code` text NOT NULL, + `in_date` datetime DEFAULT NULL, + `status` int(11) DEFAULT '0', + PRIMARY KEY (`id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +CREATE TABLE `privilege_distribution` ( + `group_name` varchar(255) CHARACTER SET utf8 NOT NULL DEFAULT '', + `enter_admin_page` tinyint(4) DEFAULT NULL, + `edit_default_problem` tinyint(4) DEFAULT NULL, + `rejudge` tinyint(4) DEFAULT NULL, + `edit_news` tinyint(4) DEFAULT NULL, + `edit_contest` tinyint(4) DEFAULT NULL, + `download_ranklist` tinyint(4) DEFAULT NULL, + `generate_team` tinyint(4) DEFAULT NULL, + `edit_user_profile` tinyint(4) DEFAULT NULL, + `edit_privilege_group` tinyint(4) DEFAULT NULL, + `edit_privilege_distribution` tinyint(4) DEFAULT NULL, + `inner_function` tinyint(4) DEFAULT NULL, + `see_hidden_default_problem` tinyint(4) DEFAULT NULL, + `see_hidden_user_info` tinyint(4) DEFAULT NULL, + `see_wa_info_out_of_contest` tinyint(4) DEFAULT NULL, + `see_wa_info_in_contest` tinyint(4) DEFAULT NULL, + `see_source_out_of_contest` tinyint(4) DEFAULT NULL, + `see_source_in_contest` tinyint(4) DEFAULT NULL, + `see_compare` tinyint(4) DEFAULT NULL, + `upload_files` tinyint(4) DEFAULT NULL, + `watch_solution_video` tinyint(4) DEFAULT NULL, + PRIMARY KEY (`group_name`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT; +INSERT INTO `privilege_distribution` VALUES ('administrator',1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1),('exam_user',1,0,1,0,1,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0),('hznu_viewer',1,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0),('root',1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),('source_browser',1,0,1,0,0,1,0,0,0,0,0,0,1,1,1,1,1,1,0,0),('teacher',1,1,1,0,1,1,0,1,0,0,0,1,1,1,1,1,1,1,1,1),('teacher_assistant',1,1,1,0,1,0,0,0,0,0,0,1,1,1,1,1,1,0,1,0); + +CREATE TABLE `privilege_groups` ( + `group_order` int(11) NOT NULL DEFAULT '0', + `group_name` varchar(255) CHARACTER SET utf8 DEFAULT NULL, + PRIMARY KEY (`group_order`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT; +INSERT INTO `privilege_groups` VALUES (0,'root'),(1,'administrator'),(2,'teacher'),(3,'teacher_assistant'),(4,'source_browser'),(5,'hznu_viewer'),(6,'exam_user'); +-- DROP TABLE IF EXISTS `problem_samples`; +CREATE TABLE `problem_samples` ( + `problem_id` int(11) NOT NULL, + `sample_id` int(11) NOT NULL DEFAULT '0', + `input` text CHARACTER SET utf8, + `output` text CHARACTER SET utf8, + `show_after` int(11) DEFAULT '0', + PRIMARY KEY (`problem_id`,`sample_id`), + KEY `problem_id` (`problem_id`,`sample_id`) USING BTREE +) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; + +CREATE TABLE `problemset` ( + `index` int(11) NOT NULL AUTO_INCREMENT, + `set_name` varchar(255) CHARACTER SET utf8 NOT NULL DEFAULT '', + `set_name_show` varchar(255) CHARACTER SET utf8 NOT NULL, + `access_level` tinyint NOT NULL DEFAULT 0, + PRIMARY KEY (`index`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT AUTO_INCREMENT=2; +INSERT INTO `problemset` VALUES (1,'default','DEFAULT',0); + +CREATE TABLE `reg_code` ( + `class_name` varchar(100) NOT NULL, + `reg_code` varchar(100) NOT NULL, + `remain_num` smallint(4) NOT NULL, + PRIMARY KEY (`class_name`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; +INSERT INTO `reg_code` VALUES ('其它', '', '0'); + +CREATE TABLE `slide` ( + `img_id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `url` varchar(200) NOT NULL, + `defunct` char(1) DEFAULT NULL, + PRIMARY KEY (`img_id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +CREATE TABLE `solution_video_watch_log` ( + `index` int(11) NOT NULL AUTO_INCREMENT, + `video_id` int(11) NOT NULL, + `user_id` varchar(255) CHARACTER SET utf8 DEFAULT NULL, + `time` datetime DEFAULT NULL, + PRIMARY KEY (`index`), + KEY `video_id` (`video_id`) USING BTREE +) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; + +CREATE TABLE `tag` ( + `index` int(11) NOT NULL AUTO_INCREMENT, + `problem_id` int(10) unsigned zerofill NOT NULL, + `user_id` varchar(100) CHARACTER SET utf8 NOT NULL, + `tag` varchar(100) CHARACTER SET utf8 NOT NULL, + PRIMARY KEY (`index`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +CREATE TABLE `team` ( + `user_id` varchar(30) NOT NULL, + `prefix` varchar(30) DEFAULT NULL, + `NO` int(10) DEFAULT NULL, + `password` varchar(32) NOT NULL, + `nick` varchar(100) NOT NULL, + `contest_id` int(13) NOT NULL, + `stu_id` varchar(255) DEFAULT NULL, + `institute` varchar(255) DEFAULT NULL, + `class` varchar(30) DEFAULT NULL, + `real_name` varchar(255) DEFAULT NULL, + `seat` varchar(255) DEFAULT NULL, + `school` varchar(100) DEFAULT NULL, + `accesstime` datetime DEFAULT NULL, + `reg_time` datetime DEFAULT NULL, + `ip` varchar(46) DEFAULT NULL, + PRIMARY KEY (`contest_id`,`user_id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +CREATE TABLE `users_cache` ( + `user_id` varchar(48) NOT NULL, + `class` varchar(15) CHARACTER SET utf8 NOT NULL, + `AC_day` int(10) unsigned zerofill DEFAULT NULL, + `sub_day` int(10) unsigned zerofill DEFAULT NULL, + `activity` int(10) unsigned zerofill DEFAULT NULL, + `total_score` decimal(10,2) unsigned zerofill DEFAULT NULL, + PRIMARY KEY (`user_id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; +INSERT INTO `users_cache` VALUES ('admin','',0000000001,0000000001,NULL,NULL); + +CREATE TABLE `users_cache_array` ( + `index` int(11) NOT NULL AUTO_INCREMENT, + `user_id` varchar(48) NOT NULL, + `type` varchar(15) NOT NULL, + `week` int(9) unsigned zerofill DEFAULT NULL, + `value_int` int(10) unsigned zerofill NOT NULL, + `value_double` decimal(10,2) unsigned zerofill DEFAULT NULL, + PRIMARY KEY (`index`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +ALTER TABLE `contest` ADD COLUMN `user_limit` char(1) NOT NULL DEFAULT 'N'; +ALTER TABLE `contest` ADD COLUMN `defunct_TA` char(1) NOT NULL DEFAULT 'N'; +ALTER TABLE `contest` ADD COLUMN `open_source` char(1) NOT NULL DEFAULT 'N'; +ALTER TABLE `contest` ADD COLUMN `lock_time` int(11) DEFAULT NULL; +ALTER TABLE `contest` ADD COLUMN `unlock` tinyint(4) DEFAULT '1'; +ALTER TABLE `contest` ADD COLUMN `first_prize` int(11) DEFAULT '0'; +ALTER TABLE `contest` ADD COLUMN `second_prize` int(11) DEFAULT '0'; +ALTER TABLE `contest` ADD COLUMN `third_prize` int(11) DEFAULT '0'; +ALTER TABLE `contest` ADD COLUMN `practice` tinyint(4) DEFAULT '0'; +ALTER TABLE `contest` ADD COLUMN `isTop` tinyint(1) NOT NULL DEFAULT '0'; +ALTER TABLE `contest` ADD INDEX `contest_id` (`contest_id`,`defunct`,`private`,`defunct_TA`,`open_source`) USING BTREE; +ALTER TABLE `contest` ADD INDEX `running_contest` (`start_time`,`end_time`,`practice`); +UPDATE `contest` SET `first_prize`=1,`second_prize`=3,`third_prize`=5; +-- 老版的hustoj没有user_id字段,新版有 +DROP PROCEDURE IF EXISTS AddUser_id; +delimiter // +create procedure AddUser_id() +begin + SELECT count(*) INTO @cnt FROM information_schema.columns WHERE `TABLE_SCHEMA` ='jol' AND `TABLE_NAME` = 'contest' AND `COLUMN_NAME` = 'user_id'; + IF @cnt=0 THEN + ALTER TABLE `contest` ADD COLUMN `user_id` VARCHAR(48) NOT NULL DEFAULT 'admin' AFTER `password`; + END IF; +end; // +delimiter ; +call AddUser_id(); +drop procedure AddUser_id; +-- 写入比赛创建人 start 针对老版的hustoj +DROP PROCEDURE IF EXISTS updateContestCreator; +delimiter // +create procedure updateContestCreator() +begin + DECLARE cid int(11); + DECLARE userid char(48); + DECLARE done INT DEFAULT 0; + DECLARE cur CURSOR FOR SELECT contest_id,p.user_id FROM contest LEFT JOIN (SELECT * FROM privilege WHERE rightstr LIKE 'm%') p ON CONCAT('m',contest_id)=rightstr ORDER BY contest_id; + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1; + IF @cnt=0 THEN + OPEN cur; + FETCH NEXT FROM cur INTO cid, userid; + while(done<>1) do + UPDATE contest SET user_id=userid WHERE contest_id=cid; + FETCH NEXT FROM cur INTO cid, userid; + end while; + close cur; + END IF; +end;// +delimiter ; +call updateContestCreator(); +DROP PROCEDURE updateContestCreator; +-- 写入比赛创建人 end +-- 更新比赛的语言掩码,和hustoj的掩码每位都相反 start +DROP PROCEDURE IF EXISTS transLangmask; +delimiter // +create procedure transLangmask() +begin + DECLARE cid int(11); + DECLARE mask int(10); + DECLARE masklen int(10); + DECLARE done int DEFAULT 0; + DECLARE i int; + DECLARE cur CURSOR FOR SELECT contest_id,langmask FROM contest WHERE langmask<>262143 ORDER BY contest_id; + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1; + UPDATE contest SET langmask=262143 WHERE langmask=0; + OPEN cur; + FETCH NEXT FROM cur INTO cid, mask; + while(done<>1) do + SET masklen=length(bin(mask)); + SET i=0; + while(i1) do + UPDATE problem SET author=userid WHERE problem_id=pid; + FETCH NEXT FROM cur INTO pid, userid; + end while; + close cur; +end;// +delimiter ; +call updateAuthor(); +DROP PROCEDURE updateAuthor; +-- 命题人更新 end + +-- 转移题目中样例数据到表`problem_samples` start +DROP PROCEDURE IF EXISTS updateSamples; +delimiter // +create procedure updateSamples() +begin + DECLARE pid int(11); + DECLARE s_input text; + DECLARE s_output text; + DECLARE done INT DEFAULT 0; + DECLARE cur CURSOR FOR SELECT problem_id,sample_input,sample_output FROM problem ORDER BY problem_id; + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1; + OPEN cur; + FETCH NEXT FROM cur INTO pid, s_input, s_output; + while(done<>1) do + INSERT INTO problem_samples(problem_id,`input`,`output`) VALUES(pid, s_input, s_output); + FETCH NEXT FROM cur INTO pid, s_input, s_output; + end while; + close cur; +end;// +delimiter ; +call updateSamples(); +DROP PROCEDURE updateSamples; +-- 转移题目中样例数据到表`problem_samples` end + +DROP PROCEDURE IF EXISTS Add_sim_idx; +delimiter // +create procedure Add_sim_idx() +begin + SELECT count(*) INTO @cnt FROM information_schema.statistics WHERE `TABLE_SCHEMA` ='jol' AND table_name='sim' AND index_name='Index_sim_id' ; + IF @cnt=0 THEN + ALTER TABLE `sim` ADD INDEX `Index_sim_id` (`sim_s_id`); + END IF; +end;// +delimiter ; +call Add_sim_idx(); +DROP PROCEDURE Add_sim_idx; + +-- 老版的hustoj没有nick字段,新版有 +DROP PROCEDURE IF EXISTS AddNick; +delimiter // +create procedure AddNick() +begin + SELECT count(*) INTO @cnt FROM information_schema.columns WHERE `TABLE_SCHEMA` ='jol' AND `TABLE_NAME` = 'solution' AND `COLUMN_NAME` = 'nick'; + IF @cnt=0 THEN + ALTER TABLE `solution` ADD COLUMN `nick` char(20) NOT NULL DEFAULT '' AFTER `user_id`; + END IF; +end; // +delimiter ; +call AddNick(); +drop procedure AddNick; + +ALTER TABLE `solution` ADD INDEX `in_date` (`in_date`) USING BTREE; +ALTER TABLE `users` MODIFY COLUMN `ip` varchar(46) NOT NULL DEFAULT ''; +ALTER TABLE `users` ADD COLUMN `stu_id` varchar(20) DEFAULT NULL AFTER `user_id`; +ALTER TABLE `users` ADD COLUMN `volume_c` int(11) DEFAULT NULL AFTER `volume`; +ALTER TABLE `users` ADD COLUMN `real_name` varchar(100) DEFAULT NULL AFTER `reg_time`; +ALTER TABLE `users` ADD COLUMN `class` varchar(127) DEFAULT NULL; +ALTER TABLE `users` ADD COLUMN `level` varchar(20) DEFAULT NULL; +ALTER TABLE `users` ADD COLUMN `strength` double(10,2) DEFAULT NULL; +ALTER TABLE `users` ADD COLUMN `color` varchar(20) DEFAULT NULL; +ALTER TABLE `users` ADD COLUMN `ZJU` int(9) unsigned DEFAULT NULL; +ALTER TABLE `users` ADD COLUMN `HDU` int(9) unsigned DEFAULT NULL; +ALTER TABLE `users` ADD COLUMN `PKU` int(9) unsigned DEFAULT NULL; +ALTER TABLE `users` ADD COLUMN `UVA` int(9) unsigned DEFAULT NULL; +ALTER TABLE `users` ADD COLUMN `CF` int(9) DEFAULT NULL; +ALTER TABLE `users` ADD COLUMN `like` int(9) DEFAULT '0'; +ALTER TABLE `users` ADD COLUMN `dislike` int(9) DEFAULT '0'; +ALTER TABLE `users` ADD COLUMN `tag` varchar(250) DEFAULT NULL; +ALTER TABLE `users` ADD COLUMN `access_level` tinyint NOT NULL DEFAULT 0; +UPDATE `users` SET `class`='其它'; + +-- 老版的hustoj没有表`share_code`,新版有 +CREATE TABLE IF NOT EXISTS `share_code` ( + `share_id` int(11) NOT NULL AUTO_INCREMENT, + `user_id` varchar(48) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `title` varchar(32) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `share_code` text COLLATE utf8mb4_unicode_ci, + `language` varchar(32) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `share_time` datetime DEFAULT NULL, + PRIMARY KEY (`share_id`) +) ENGINE=MyISAM AUTO_INCREMENT=1000 DEFAULT CHARSET=utf8; +ALTER TABLE `reply` MODIFY COLUMN `ip` varchar(46) DEFAULT NULL; +ALTER TABLE `online` MODIFY COLUMN `ip` varchar(46) CHARACTER SET utf8 NOT NULL DEFAULT ''; \ No newline at end of file diff --git a/judger/install/install-interactive.sh b/judger/install/install-interactive.sh deleted file mode 100755 index db504a89..00000000 --- a/judger/install/install-interactive.sh +++ /dev/null @@ -1,104 +0,0 @@ -#!/bin/bash -#before install check DB setting in -# judge.conf -# hustoj-read-only/web/include/db_info.inc.php -# and down here -#and run this with root - -#CENTOS/REDHAT/FEDORA WEBBASE=/var/www/html APACHEUSER=apache -WEBBASE=/var/www/html -APACHEUSER=www-data -DBUSER=root -DBPASS=root - -printf "Input Database(MySQL) Username:" -read tmp -if test -n "$tmp" -then - DBUSER="$tmp" -fi -printf "Input Database(MySQL) Password:" -read tmp -if test -n "$tmp" -then - DBPASS="$tmp" -fi - -#try install tools -if uname -a|grep 'Ubuntu\|Debian' -then -sudo apt-get install make flex g++ clang libmysql++-dev php5 apache2 mysql-server php5-mysql php5-gd php5-cli mono-gmcs subversion -sudo /etc/init.d/mysql start -HTTP_START="sudo /etc/init.d/apache2 restart" - -else -sudo yum -y update -sudo yum -y install php httpd php-mysql mysql-server php-xml php-gd gcc-c++ mysql-devel php-mbstring glibc-static flex -sudo /etc/init.d/mysqld start -WEBBASE=/var/www/html -APACHEUSER=apache -HTTP_START="sudo /etc/init.d/httpd restart" -echo "/usr/bin/judged" > judged -fi - -sudo svn checkout https://github.com/zhblue/hustoj/trunk/trunk hustoj-read-only - -#create user and homedir -sudo /usr/sbin/useradd -m -u 1536 judge - - - -#compile and install the core -cd hustoj-read-only/core/ -sudo ./make.sh -cd ../.. -#install web and db -sudo cp -R hustoj-read-only/web $WEBBASE/JudgeOnline -sudo chmod -R 771 $WEBBASE/JudgeOnline -sudo chown -R $APACHEUSER $WEBBASE/JudgeOnline -sudo mysql -h localhost -u$DBUSER -p$DBPASS < db.sql - -#create work dir set default conf -sudo mkdir /home/judge -sudo mkdir /home/judge/etc -sudo mkdir /home/judge/data -sudo mkdir /home/judge/log -sudo mkdir /home/judge/run0 -sudo mkdir /home/judge/run1 -sudo mkdir /home/judge/run2 -sudo mkdir /home/judge/run3 -sudo cp java0.policy judge.conf /home/judge/etc -sudo chown -R judge /home/judge -sudo chgrp -R $APACHEUSER /home/judge/data -sudo chgrp -R root /home/judge/etc /home/judge/run? -sudo chmod 775 /home/judge /home/judge/data /home/judge/etc /home/judge/run? -#update database account -SED_CMD="s/OJ_USER_NAME=root/OJ_USER_NAME=$DBUSER/g" -SED_CMD2="s/OJ_PASSWORD=root/OJ_PASSWORD=$DBPASS/g" -sed $SED_CMD judge.conf|sed $SED_CMD2 >/home/judge/etc/judge.conf - -SED_CMD="s/DB_USER=\\\"root\\\"/DB_USER=\\\"$DBUSER\\\"/g" -SED_CMD2="s/DB_PASS=\\\"root\\\"/DB_PASS=\\\"$DBPASS\\\"/g" - -sed $SED_CMD hustoj-read-only/web/include/db_info.inc.php|sed $SED_CMD2 >$WEBBASE/JudgeOnline/include/db_info.inc.php - - -#boot up judged -sudo cp judged /etc/init.d/judged -sudo chmod +x /etc/init.d/judged -sudo ln -s /etc/init.d/judged /etc/rc3.d/S93judged -sudo ln -s /etc/init.d/judged /etc/rc2.d/S93judged -sudo /etc/init.d/judged start - -$HTTP_START - -if uname -a | grep 'Ubuntu\|Debian' -then - echo "Debian is better :P" -else - chcon -R -t httpd_sys_content_t /home/judge/ - chcon -R -t httpd_sys_content_t /var/www/html/ -fi - -echo "Browse http://127.0.0.1/JudgeOnline to check if the installation is working" - diff --git a/judger/install/install-ubuntu18.04.sh b/judger/install/install-ubuntu18.04.sh new file mode 100644 index 00000000..cbe467f3 --- /dev/null +++ b/judger/install/install-ubuntu18.04.sh @@ -0,0 +1,296 @@ +#!/bin/bash +echo "" +echo " ██ ██ ████████ ████ ██ ██ ██ ███████ ██" +echo "░██ ░██░░░░░░██ ░██░██ ░██░██ ░██ ██░░░░░██ ░██" +echo "░██ ░██ ██ ░██░░██ ░██░██ ░██ ██ ░░██ ░██" +echo "░██████████ ██ ░██ ░░██ ░██░██ ░██░██ ░██ ░██" +echo "░██░░░░░░██ ██ ░██ ░░██░██░██ ░██░██ ░██ ░██" +echo "░██ ░██ ██ ░██ ░░████░██ ░██░░██ ██ ██ ░██" +echo "░██ ░██ ████████░██ ░░███░░███████ ░░███████ ░░█████ " +echo "░░ ░░ ░░░░░░░░ ░░ ░░░ ░░░░░░░ ░░░░░░░ ░░░░░ " +echo "" +#update-sources-ubuntu +sed -i 's/http\:\/\/il.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/us.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/cn.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/fr.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/in.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/np.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/fi.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/th.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/ru.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/md.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/ch.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/se.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/no.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/nl.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/am.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/dk.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/is.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/ua.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/ge.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/nz.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/cr.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/hk.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/gb.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/us-east-1.ec2.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/cz.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/id.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/es.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/my.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/us-west-2.ec2.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/za.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/sk.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/ph.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/hr.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/us-east-1a.clouds.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/eu-west-2.ec2.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/gl.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/jp.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/jo.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/pt.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/security.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +apt-get update +for pkg in "net-tools make flex g++ clang libmysqlclient-dev libmysql++-dev php-fpm nginx mysql-server php-mysql php-common php-gd php-zip fp-compiler openjdk-11-jdk mono-devel php-mbstring php-xml php-curl php-intl php-xmlrpc php-soap subversion" +do + while ! apt-get install -y $pkg + do + echo "Network fail, retry... you might want to change another apt source for install" + done +done +reset +echo "" +echo " ██ ██ ████████ ████ ██ ██ ██ ███████ ██" +echo "░██ ░██░░░░░░██ ░██░██ ░██░██ ░██ ██░░░░░██ ░██" +echo "░██ ░██ ██ ░██░░██ ░██░██ ░██ ██ ░░██ ░██" +echo "░██████████ ██ ░██ ░░██ ░██░██ ░██░██ ░██ ░██" +echo "░██░░░░░░██ ██ ░██ ░░██░██░██ ░██░██ ░██ ░██" +echo "░██ ░██ ██ ░██ ░░████░██ ░██░░██ ██ ██ ░██" +echo "░██ ░██ ████████░██ ░░███░░███████ ░░███████ ░░█████ " +echo "░░ ░░ ░░░░░░░░ ░░ ░░░ ░░░░░░░ ░░░░░░░ ░░░░░ " +echo "" +/usr/sbin/useradd -m -u 1536 judge +cp -R HZNUOJ /home/judge/ +cd /home/judge/ + +USER=`cat /etc/mysql/debian.cnf |grep user|head -1|awk '{print $3}'` +PASSWORD=`cat /etc/mysql/debian.cnf |grep password|head -1|awk '{print $3}'` +CPU=`grep "cpu cores" /proc/cpuinfo |head -1|awk '{print $4}'` + +mkdir etc data log backup +mkdir -p /home/judge/HZNUOJ/web/OJ/upload + +cp HZNUOJ/judger/install/java0.policy /home/judge/etc +cp HZNUOJ/judger/install/judge.conf /home/judge/etc +chmod +x HZNUOJ/judger/install/ans2out +chmod +x HZNUOJ/judger/install/hustoj + +mkdir run0 run1 run2 run3 +chown judge run0 run1 run2 run3 +sed -i "s/OJ_USER_NAME=root/OJ_USER_NAME=$USER/g" etc/judge.conf +sed -i "s/OJ_PASSWORD=root/OJ_PASSWORD=$PASSWORD/g" etc/judge.conf +sed -i "s/OJ_COMPILE_CHROOT=1/OJ_COMPILE_CHROOT=0/g" etc/judge.conf +sed -i "s/OJ_RUNNING=1/OJ_RUNNING=$CPU/g" etc/judge.conf + +chmod 700 backup +chmod 700 etc/judge.conf + +sed -i "s/DB_USER[[:space:]]*=[[:space:]]*\"root\"/DB_USER=\"$USER\"/g" HZNUOJ/web/OJ/include/static.php +sed -i "s/DB_PASS[[:space:]]*=[[:space:]]*\"root\"/DB_PASS=\"$PASSWORD\"/g" HZNUOJ/web/OJ/include/static.php + +mkdir -p /home/judge/data/1000 +pushd /home/judge/data/1000 + echo "1 2" > sample0.in + echo "3" > sample0.out + echo "6 10" > test0.in + echo "16" > test0.out + echo "6 9" > test1.in + echo "15" > test1.out + echo "0 0" > test2.in + echo "0" > test2.out +popd +chmod 700 HZNUOJ/web/OJ/include/static.php +chown -R www-data HZNUOJ/web/ +chown www-data HZNUOJ/web/OJ/upload data +if grep "client_max_body_size" /etc/nginx/nginx.conf ; then + echo "client_max_body_size already added" ; +else + sed -i "s:include /etc/nginx/mime.types;:client_max_body_size 80m;\n\tinclude /etc/nginx/mime.types;:g" /etc/nginx/nginx.conf +fi + +mysql -h localhost -u$USER -p$PASSWORD < HZNUOJ/judger/install/db.sql + +if grep "added by hustoj" /etc/nginx/sites-enabled/default ; then + echo "default site modified!" +else + echo "modify the default site" + sed -i "s#root /var/www/html;#root /home/judge/HZNUOJ/web/OJ;#g" /etc/nginx/sites-enabled/default + sed -i "s:index index.html:index index.php:g" /etc/nginx/sites-enabled/default + sed -i "s:#location ~ \\\.php\\$:location ~ \\\.php\\$:g" /etc/nginx/sites-enabled/default + sed -i "s:#\tinclude snippets:\tinclude snippets:g" /etc/nginx/sites-enabled/default + sed -i "s|#\tfastcgi_pass unix|\tfastcgi_pass unix|g" /etc/nginx/sites-enabled/default + sed -i "s:}#added by hustoj::g" /etc/nginx/sites-enabled/default + sed -i "s:php7.0:php7.2:g" /etc/nginx/sites-enabled/default + sed -i "s|# deny access to .htaccess files|}#added by hustoj\n\n\n\t# deny access to .htaccess files|g" /etc/nginx/sites-enabled/default +fi +/etc/init.d/nginx restart +sed -i "s/post_max_size = 8M/post_max_size = 80M/g" /etc/php/7.2/fpm/php.ini +sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 80M/g" /etc/php/7.2/fpm/php.ini +sed -i 's/;request_terminate_timeout = 0/request_terminate_timeout = 128/g' `find /etc/php -name www.conf` +sed -i 's/pm.max_children = 5/pm.max_children = 200/g' `find /etc/php -name www.conf` + +COMPENSATION=`grep 'mips' /proc/cpuinfo|head -1|awk -F: '{printf("%.2f",$2/5000)}'` +sed -i "s/OJ_CPU_COMPENSATION=1.0/OJ_CPU_COMPENSATION=$COMPENSATION/g" etc/judge.conf + +/etc/init.d/php7.2-fpm restart +service php7.2-fpm restart + +cd HZNUOJ/judger/core +chmod +x ./make.sh +./make.sh +if grep "/usr/bin/judged" /etc/rc.local ; then + echo "auto start judged added!" +else + sed -i "s/exit 0//g" /etc/rc.local + echo "/usr/bin/judged" >> /etc/rc.local + echo "exit 0" >> /etc/rc.local + echo "add auto start judged." +fi + +ln -s /usr/bin/mcs /usr/bin/gmcs + +/usr/bin/judged +cp /home/judge/HZNUOJ/judger/install/hustoj /etc/init.d/hustoj +update-rc.d hustoj defaults +systemctl enable hustoj +systemctl enable nginx +systemctl enable mysql +systemctl enable php7.2-fpm +systemctl enable judged + +mkdir /var/log/hustoj/ +chown www-data -R /var/log/hustoj/ + +reset +echo "" +echo " ██ ██ ████████ ████ ██ ██ ██ ███████ ██" +echo "░██ ░██░░░░░░██ ░██░██ ░██░██ ░██ ██░░░░░██ ░██" +echo "░██ ░██ ██ ░██░░██ ░██░██ ░██ ██ ░░██ ░██" +echo "░██████████ ██ ░██ ░░██ ░██░██ ░██░██ ░██ ░██" +echo "░██░░░░░░██ ██ ░██ ░░██░██░██ ░██░██ ░██ ░██" +echo "░██ ░██ ██ ░██ ░░████░██ ░██░░██ ██ ██ ░██" +echo "░██ ░██ ████████░██ ░░███░░███████ ░░███████ ░░█████ " +echo "░░ ░░ ░░░░░░░░ ░░ ░░░ ░░░░░░░ ░░░░░░░ ░░░░░ " +echo "" +echo "OJ Configuration:" +echo "" +printf "1-Please input OJ's name, press Enter for default name(argument:\$OJ_NAME): " +read ojname +if test "$ojname" != "" +then + sed -i "s/OJ_NAME=\"HZNUOJ\"/OJ_NAME=\"$ojname\"/g" /home/judge/HZNUOJ/web/OJ/include/static.php +fi +echo "" +echo "2-Please select the UI language.(argument:\$OJ_LANG)" +echo " 1) Chinese" +echo " 2) English" +temp=0 +while test $temp != 1 -a $temp != 2 +do + printf "#? " + read temp +done +if test $temp = 1 +then + sed -i "s/OJ_LANG=\"en\"/OJ_LANG=\"cn\"/g" /home/judge/HZNUOJ/web/OJ/include/static.php +else + sed -i "s/OJ_LANG=\"cn\"/OJ_LANG=\"en\"/g" /home/judge/HZNUOJ/web/OJ/include/static.php +fi +echo "" +echo "3-Please select running mode.(argument:OJ_OI_MODE)" +echo " 1) OI Mode (Middle school)" +echo " 2) ACM Mode (University)" +temp=0 +while test $temp != 1 -a $temp != 2 +do + printf "#? " + read temp +done +if test $temp = 1 +then + sed -i "s/OJ_OI_MODE=0/OJ_OI_MODE=1/g" /home/judge/etc/judge.conf +else + sed -i "s/OJ_OI_MODE=1/OJ_OI_MODE=0/g" /home/judge/etc/judge.conf +fi +echo "" +echo "4-Please select trun on/off the code share mode.(argument:\$OJ_AUTO_SHARE)" +echo " 1) Trun on (All of users are able to view all submissions after solving this problem.)" +echo " 2) Trun off (Only administrators are able to view all submissions.)" +temp=0 +while test $temp != 1 -a $temp != 2 +do + printf "#? " + read temp +done +if test $temp = 2 +then + sed -i "s/OJ_AUTO_SHARE=true/OJ_AUTO_SHARE=false/g" /home/judge/HZNUOJ/web/OJ/include/static.php +else + sed -i "s/OJ_AUTO_SHARE=false/OJ_AUTO_SHARE=true/g" /home/judge/HZNUOJ/web/OJ/include/static.php +fi +echo "" +echo "5-Please select trun on/off show the WA/CE information in reinfo/ceinfo page.(argument:\$OJ_SHOW_DIFF)" +echo "1) Trun on (All of users are able to view the WA/CE information of their own code.)" +echo "2) Trun off (Only administrators are able to view the WA/CE information.)" +temp=0 +while test $temp != 1 -a $temp != 2 +do + printf "#? " + read temp +done +if test $temp = 2 +then + sed -i "s/OJ_SHOW_DIFF=true/OJ_SHOW_DIFF=false/g" /home/judge/HZNUOJ/web/OJ/include/static.php +else + sed -i "s/OJ_SHOW_DIFF=false/OJ_SHOW_DIFF=true/g" /home/judge/HZNUOJ/web/OJ/include/static.php +fi +echo "" +echo "6-Please select trun on/off source code similarity detection.(argument:\$OJ_SIM, OJ_SIM_ENABLE)" +echo "1) Trun on" +echo "2) Trun off" +temp=0 +while test $temp != 1 -a $temp != 2 +do + printf "#? " + read temp +done +if test $temp = 2 +then + sed -i "s/OJ_SIM=true/OJ_SIM=false/g" /home/judge/HZNUOJ/web/OJ/include/static.php + sed -i "s/OJ_SIM_ENABLE=1/OJ_SIM_ENABLE=0/g" /home/judge/etc/judge.conf +else + sed -i "s/OJ_SIM=false/OJ_SIM=true/g" /home/judge/HZNUOJ/web/OJ/include/static.php + sed -i "s/OJ_SIM_ENABLE=0/OJ_SIM_ENABLE=1/g" /home/judge/etc/judge.conf +fi +echo "" +echo "7-Please select trun on/off show the contest's solution in status page.(argument:\$OJ_show_contestSolutionInStatus)" +echo "1) Trun on (contest's solution will be show in status page and contest-status page.)" +echo "2) Trun off (contest's solution will be show in contest-status page only.)" +temp=0 +while test $temp != 1 -a $temp != 2 +do + printf "#? " + read temp +done +if test $temp = 1 +then + sed -i "s/OJ_show_contestSolutionInStatus=false/OJ_show_contestSolutionInStatus=true/g" /home/judge/HZNUOJ/web/OJ/include/static.php +else + sed -i "s/OJ_show_contestSolutionInStatus=true/OJ_show_contestSolutionInStatus=false/g" /home/judge/HZNUOJ/web/OJ/include/static.php +fi +echo "" +echo "Install HZNUOJ successfully!" +echo "Remember your database account for HZNUOJ:" +echo "username:$USER" +echo "password:$PASSWORD" diff --git a/judger/install/install.sh b/judger/install/install.sh index 17e5fd4b..b0c62aa0 100755 --- a/judger/install/install.sh +++ b/judger/install/install.sh @@ -1,72 +1,290 @@ #!/bin/bash -set -e -x -#before install check DB setting in -# judge.conf -# hustoj-read-only/web/include/db_info.inc.php -# and down here -#and run this with root - -#CENTOS/REDHAT/FEDORA WEBBASE=/var/www/html APACHEUSER=apache -WEBBASE=/var/www/ -APACHEUSER=www-data -DBUSER=root -DBPASS=root - - -#try install tools -deps="make flex g++ clang libmysql++-dev php7.0 apache2 mysql-server libapache2-mod-php7.0 php7.0-mysql php7.0-mbstring php7.0-gd php7.0-cli php-xml mono-mcs subversion libexplain-dev" +echo "" +echo " ██ ██ ████████ ████ ██ ██ ██ ███████ ██" +echo "░██ ░██░░░░░░██ ░██░██ ░██░██ ░██ ██░░░░░██ ░██" +echo "░██ ░██ ██ ░██░░██ ░██░██ ░██ ██ ░░██ ░██" +echo "░██████████ ██ ░██ ░░██ ░██░██ ░██░██ ░██ ░██" +echo "░██░░░░░░██ ██ ░██ ░░██░██░██ ░██░██ ░██ ░██" +echo "░██ ░██ ██ ░██ ░░████░██ ░██░░██ ██ ██ ░██" +echo "░██ ░██ ████████░██ ░░███░░███████ ░░███████ ░░█████ " +echo "░░ ░░ ░░░░░░░░ ░░ ░░░ ░░░░░░░ ░░░░░░░ ░░░░░ " +echo "" +#update-sources-ubuntu +sed -i 's/http\:\/\/il.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/us.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/cn.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/fr.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/in.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/np.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/fi.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/th.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/ru.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/md.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/ch.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/se.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/no.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/nl.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/am.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/dk.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/is.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/ua.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/ge.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/nz.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/cr.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/hk.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/gb.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/us-east-1.ec2.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/cz.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/id.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/es.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/my.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/us-west-2.ec2.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/za.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/sk.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/ph.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/hr.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/us-east-1a.clouds.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/eu-west-2.ec2.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/gl.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/jp.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/jo.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/pt.archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/archive.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list +sed -i 's/http\:\/\/security.ubuntu.com/https\:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list apt-get update -apt-get -y install $deps -apt-get purge -y --auto-remove $buildDeps -apt-get clean +#try install tools +echo 'mysql-server-5.5 mysql-server/root_password password ""' | sudo debconf-set-selections +echo 'mysql-server-5.5 mysql-server/root_password_again password ""' | sudo debconf-set-selections +apt-get install -y make flex g++ clang libmysqlclient-dev libmysql++-dev php-fpm nginx mysql-server php-mysql php-common php-gd php-zip fp-compiler openjdk-8-jdk mono-devel php-mbstring php-xml php-curl php-intl php-xmlrpc php-soap subversion php-xml-parser +reset +echo "" +echo " ██ ██ ████████ ████ ██ ██ ██ ███████ ██" +echo "░██ ░██░░░░░░██ ░██░██ ░██░██ ░██ ██░░░░░██ ░██" +echo "░██ ░██ ██ ░██░░██ ░██░██ ░██ ██ ░░██ ░██" +echo "░██████████ ██ ░██ ░░██ ░██░██ ░██░██ ░██ ░██" +echo "░██░░░░░░██ ██ ░██ ░░██░██░██ ░██░██ ░██ ░██" +echo "░██ ░██ ██ ░██ ░░████░██ ░██░░██ ██ ██ ░██" +echo "░██ ░██ ████████░██ ░░███░░███████ ░░███████ ░░█████ " +echo "░░ ░░ ░░░░░░░░ ░░ ░░░ ░░░░░░░ ░░░░░░░ ░░░░░ " +echo "" +/usr/sbin/useradd -m -u 1536 judge +cp -R HZNUOJ /home/judge/ +cd /home/judge/ +USER=`cat /etc/mysql/debian.cnf |grep user|head -1|awk '{print $3}'` +PASSWORD=`cat /etc/mysql/debian.cnf |grep password|head -1|awk '{print $3}'` +CPU=`grep "cpu cores" /proc/cpuinfo |head -1|awk '{print $4}'` -/etc/init.d/mysql start +mkdir etc data log backup +mkdir -p /home/judge/HZNUOJ/web/OJ/upload -#set up database -mysql -uroot -proot < db.sql +cp HZNUOJ/judger/install/java0.policy /home/judge/etc +cp HZNUOJ/judger/install/judge.conf /home/judge/etc +chmod +x HZNUOJ/judger/install/ans2out -#create user and homedir -/usr/sbin/useradd -m -u 1536 judge +mkdir run0 run1 run2 run3 +chown judge run0 run1 run2 run3 +sed -i "s/OJ_USER_NAME=root/OJ_USER_NAME=$USER/g" etc/judge.conf +sed -i "s/OJ_PASSWORD=root/OJ_PASSWORD=$PASSWORD/g" etc/judge.conf +sed -i "s/OJ_COMPILE_CHROOT=1/OJ_COMPILE_CHROOT=0/g" etc/judge.conf +sed -i "s/OJ_RUNNING=1/OJ_RUNNING=$CPU/g" etc/judge.conf -#compile and install the core -cd ../core/ -bash ./make.sh -cd ../../.. +chmod 700 backup +chmod 700 etc/judge.conf -#install web and db -rm -R $WEBBASE -cp -R HZNUOJ $WEBBASE +sed -i "s/DB_USER[[:space:]]*=[[:space:]]*\"root\"/DB_USER=\"$USER\"/g" HZNUOJ/web/OJ/include/static.php +sed -i "s/DB_PASS[[:space:]]*=[[:space:]]*\"root\"/DB_PASS=\"$PASSWORD\"/g" HZNUOJ/web/OJ/include/static.php -#create work dir set default conf -mkdir -p /home/judge -mkdir -p /home/judge/etc - -#make data for problem 1000 mkdir -p /home/judge/data/1000 pushd /home/judge/data/1000 echo "1 2" > sample0.in echo "3" > sample0.out + echo "6 10" > test0.in + echo "16" > test0.out + echo "6 9" > test1.in + echo "15" > test1.out + echo "0 0" > test2.in + echo "0" > test2.out popd +chmod 700 HZNUOJ/web/OJ/include/static.php +chown -R www-data HZNUOJ/web/ +chown www-data HZNUOJ/web/OJ/upload data +if grep "client_max_body_size" /etc/nginx/nginx.conf ; then + echo "client_max_body_size already added" ; +else + sed -i "s:include /etc/nginx/mime.types;:client_max_body_size 80m;\n\tinclude /etc/nginx/mime.types;:g" /etc/nginx/nginx.conf +fi + +mysql -h localhost -u$USER -p$PASSWORD < HZNUOJ/judger/install/db.sql + +if grep "added by hustoj" /etc/nginx/sites-enabled/default ; then + echo "default site modified!" +else + echo "modify the default site" + sed -i "s#root /var/www/html;#root /home/judge/HZNUOJ/web/OJ;#g" /etc/nginx/sites-enabled/default + sed -i "s:index index.html:index index.php:g" /etc/nginx/sites-enabled/default + sed -i "s:#location ~ \\\.php\\$:location ~ \\\.php\\$:g" /etc/nginx/sites-enabled/default + sed -i "s:#\tinclude snippets:\tinclude snippets:g" /etc/nginx/sites-enabled/default + sed -i "s|#\tfastcgi_pass unix|\tfastcgi_pass unix|g" /etc/nginx/sites-enabled/default + sed -i "s:}#added by hustoj::g" /etc/nginx/sites-enabled/default + if [ -f "/run/php/php7.2-fpm.sock" ]; then + sed -i "s:php7.0:php7.2:g" /etc/nginx/sites-enabled/default + fi + sed -i "s|# deny access to .htaccess files|}#added by hustoj\n\n\n\t# deny access to .htaccess files|g" /etc/nginx/sites-enabled/default +fi +/etc/init.d/nginx restart +sed -i "s/post_max_size = 8M/post_max_size = 80M/g" /etc/php/7.0/fpm/php.ini +sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 80M/g" /etc/php/7.0/fpm/php.ini +sed -i 's/;request_terminate_timeout = 0/request_terminate_timeout = 128/g' `find /etc/php -name www.conf` +sed -i 's/pm.max_children = 5/pm.max_children = 200/g' `find /etc/php -name www.conf` + +COMPENSATION=`grep 'mips' /proc/cpuinfo|head -1|awk -F: '{printf("%.2f",$2/5000)}'` +sed -i "s/OJ_CPU_COMPENSATION=1.0/OJ_CPU_COMPENSATION=$COMPENSATION/g" etc/judge.conf + +/etc/init.d/php7.0-fpm restart +service php7.0-fpm restart + +cd HZNUOJ/judger/core +chmod +x ./make.sh +./make.sh +if grep "/usr/bin/judged" /etc/rc.local ; then + echo "auto start judged added!" +else + sed -i "s/exit 0//g" /etc/rc.local + echo "/usr/bin/judged" >> /etc/rc.local + echo "exit 0" >> /etc/rc.local + echo "add auto start judged." +fi + +ln -s /usr/bin/mcs /usr/bin/gmcs -mkdir -p /home/judge/log -mkdir -p /home/judge/run0 -mkdir -p /home/judge/run1 -mkdir -p /home/judge/run2 -mkdir -p /home/judge/run3 -cd HZNUOJ/judger/install -cp java0.policy judge.conf /home/judge/etc -chown -R judge /home/judge -chgrp -R $APACHEUSER /home/judge/data -chgrp -R root /home/judge/etc /home/judge/run? -chmod 775 -R /home/judge /home/judge/data /home/judge/etc /home/judge/run? +/usr/bin/judged +systemctl enable nginx +systemctl enable mysql +systemctl enable php7.0-fpm +systemctl enable judged -#boot up judged -cp judged /etc/init.d/judged -chmod +x /etc/init.d/judged -ln -s /etc/init.d/judged /etc/rc3.d/S93judged -ln -s /etc/init.d/judged /etc/rc2.d/S93judged +mkdir /var/log/hustoj/ +chown www-data -R /var/log/hustoj/ -judged -# change apache server root to /var/www/web -sed -i -e 's/\/var\/www\/html/\/var\/www\/web/g' /etc/apache2/sites-available/000-default.conf -/etc/init.d/apache2 restart +reset +echo "" +echo " ██ ██ ████████ ████ ██ ██ ██ ███████ ██" +echo "░██ ░██░░░░░░██ ░██░██ ░██░██ ░██ ██░░░░░██ ░██" +echo "░██ ░██ ██ ░██░░██ ░██░██ ░██ ██ ░░██ ░██" +echo "░██████████ ██ ░██ ░░██ ░██░██ ░██░██ ░██ ░██" +echo "░██░░░░░░██ ██ ░██ ░░██░██░██ ░██░██ ░██ ░██" +echo "░██ ░██ ██ ░██ ░░████░██ ░██░░██ ██ ██ ░██" +echo "░██ ░██ ████████░██ ░░███░░███████ ░░███████ ░░█████ " +echo "░░ ░░ ░░░░░░░░ ░░ ░░░ ░░░░░░░ ░░░░░░░ ░░░░░ " +echo "" +echo "OJ Configuration:" +echo "" +printf "1-Please input OJ's name, press Enter for default name(argument:\$OJ_NAME): " +read ojname +if test "$ojname" != "" +then + sed -i "s/OJ_NAME=\"HZNUOJ\"/OJ_NAME=\"$ojname\"/g" /home/judge/HZNUOJ/web/OJ/include/static.php +fi +echo "" +echo "2-Please select the UI language.(argument:\$OJ_LANG)" +echo " 1) Chinese" +echo " 2) English" +temp=0 +while test $temp != 1 -a $temp != 2 +do + printf "#? " + read temp +done +if test $temp = 1 +then + sed -i "s/OJ_LANG=\"en\"/OJ_LANG=\"cn\"/g" /home/judge/HZNUOJ/web/OJ/include/static.php +else + sed -i "s/OJ_LANG=\"cn\"/OJ_LANG=\"en\"/g" /home/judge/HZNUOJ/web/OJ/include/static.php +fi +echo "" +echo "3-Please select running mode.(argument:OJ_OI_MODE)" +echo " 1) OI Mode (Middle school)" +echo " 2) ACM Mode (University)" +temp=0 +while test $temp != 1 -a $temp != 2 +do + printf "#? " + read temp +done +if test $temp = 1 +then + sed -i "s/OJ_OI_MODE=0/OJ_OI_MODE=1/g" /home/judge/etc/judge.conf +else + sed -i "s/OJ_OI_MODE=1/OJ_OI_MODE=0/g" /home/judge/etc/judge.conf +fi +echo "" +echo "4-Please select trun on/off the code share mode.(argument:\$OJ_AUTO_SHARE)" +echo " 1) Trun on (All of users are able to view all submissions after solving this problem.)" +echo " 2) Trun off (Only administrators are able to view all submissions.)" +temp=0 +while test $temp != 1 -a $temp != 2 +do + printf "#? " + read temp +done +if test $temp = 2 +then + sed -i "s/OJ_AUTO_SHARE=true/OJ_AUTO_SHARE=false/g" /home/judge/HZNUOJ/web/OJ/include/static.php +else + sed -i "s/OJ_AUTO_SHARE=false/OJ_AUTO_SHARE=true/g" /home/judge/HZNUOJ/web/OJ/include/static.php +fi +echo "" +echo "5-Please select trun on/off show the WA/CE information in reinfo/ceinfo page.(argument:\$OJ_SHOW_DIFF)" +echo "1) Trun on (All of users are able to view the WA/CE information of their own code.)" +echo "2) Trun off (Only administrators are able to view the WA/CE information.)" +temp=0 +while test $temp != 1 -a $temp != 2 +do + printf "#? " + read temp +done +if test $temp = 2 +then + sed -i "s/OJ_SHOW_DIFF=true/OJ_SHOW_DIFF=false/g" /home/judge/HZNUOJ/web/OJ/include/static.php +else + sed -i "s/OJ_SHOW_DIFF=false/OJ_SHOW_DIFF=true/g" /home/judge/HZNUOJ/web/OJ/include/static.php +fi +echo "" +echo "6-Please select trun on/off source code similarity detection.(argument:\$OJ_SIM, OJ_SIM_ENABLE)" +echo "1) Trun on" +echo "2) Trun off" +temp=0 +while test $temp != 1 -a $temp != 2 +do + printf "#? " + read temp +done +if test $temp = 2 +then + sed -i "s/OJ_SIM=true/OJ_SIM=false/g" /home/judge/HZNUOJ/web/OJ/include/static.php + sed -i "s/OJ_SIM_ENABLE=1/OJ_SIM_ENABLE=0/g" /home/judge/etc/judge.conf +else + sed -i "s/OJ_SIM=false/OJ_SIM=true/g" /home/judge/HZNUOJ/web/OJ/include/static.php + sed -i "s/OJ_SIM_ENABLE=0/OJ_SIM_ENABLE=1/g" /home/judge/etc/judge.conf +fi +echo "" +echo "7-Please select trun on/off show the contest's solution in status page.(argument:\$OJ_show_contestSolutionInStatus)" +echo "1) Trun on (contest's solution will be show in status page and contest-status page.)" +echo "2) Trun off (contest's solution will be show in contest-status page only.)" +temp=0 +while test $temp != 1 -a $temp != 2 +do + printf "#? " + read temp +done +if test $temp = 1 +then + sed -i "s/OJ_show_contestSolutionInStatus=false/OJ_show_contestSolutionInStatus=true/g" /home/judge/HZNUOJ/web/OJ/include/static.php +else + sed -i "s/OJ_show_contestSolutionInStatus=true/OJ_show_contestSolutionInStatus=false/g" /home/judge/HZNUOJ/web/OJ/include/static.php +fi +echo "" +echo "Install HZNUOJ successfully!" +echo "Remember your database account for HZNUOJ:" +echo "username:$USER" +echo "password:$PASSWORD" diff --git a/judger/install/java0.policy b/judger/install/java0.policy index 9bad19c1..6e5a33ac 100755 --- a/judger/install/java0.policy +++ b/judger/install/java0.policy @@ -1,5 +1,5 @@ grant { - permission java.io.FilePermission "./*", "read"; - permission java.io.FilePermission "./*", "write"; + permission java.io.FilePermission "./-", "read,write"; + permission java.io.FilePermission "/usr/lib/jvm", "read"; }; diff --git a/judger/install/judge.conf b/judger/install/judge.conf index 2b9b24ef..449b8acc 100755 --- a/judger/install/judge.conf +++ b/judger/install/judge.conf @@ -1,30 +1,61 @@ +#Database Config OJ_HOST_NAME=127.0.0.1 OJ_USER_NAME=root OJ_PASSWORD=root OJ_DB_NAME=jol OJ_PORT_NUMBER=3306 -OJ_RUNNING=2 +#CPU cores Config +OJ_RUNNING=1 +#Query Interval/UDP timeout OJ_SLEEP_TIME=1 +#Multi-Judger Task Divider OJ_TOTAL=1 OJ_MOD=0 +#Java and Other VM language bonus OJ_JAVA_TIME_BONUS=2 OJ_JAVA_MEMORY_BONUS=64 +#JVM Compiler Settings OJ_JAVA_XMS=-Xms64M OJ_JAVA_XMX=-Xmx128M -OJ_SIM_ENABLE=0 +#Similarity Tester from Dick Grune +OJ_SIM_ENABLE=1 +#Using HTTP for distributed judgers OJ_HTTP_JUDGE=0 OJ_HTTP_BASEURL=http://127.0.0.1/JudgeOnline -OJ_HTTP_USERNAME=IP +OJ_HTTP_USERNAME=admin OJ_HTTP_PASSWORD=admin +OJ_HTTP_DOWNLOAD=1 +#Using Redis for solutions queue OJ_REDISENABLE=0 OJ_REDISSERVER=127.0.0.1 OJ_REDISPORT=6379 OJ_REDISAUTH=123456 OJ_REDISQNAME=hustoj +#Judge all test data even solution fails OJ_OI_MODE=0 -OJ_FULL_DIFF=1 +#Output all of the runtime error information +OJ_FULL_DIFF=0 +#Using /dev/shm as working directory OJ_SHM_RUN=1 +#Using the longest case of test as final time OJ_USE_MAX_TIME=1 -OJ_LANG_SET=0,1,2,3,4,5,6,7,8,9,12,13,14,15,17,18 +#Judge TLE by total time +OJ_TIME_LIMIT_TO_TOTAL=0 +#Judge only listed languages +OJ_LANG_SET=0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19 +#Using Chroot to prevent compile time attack (#include) OJ_COMPILE_CHROOT=1 -OJ_TURBO_MODE=0 \ No newline at end of file +#Jump some middle status update for faster judge +OJ_TURBO_MODE=0 +#Bigger setting Slow down time on fast CPU, smaller setting Speed up time on slow CPU +OJ_CPU_COMPENSATION=1.0 +#Using UDP for submission notification +OJ_UDP_ENABLE=1 +OJ_UDP_SERVER=127.0.0.1 +OJ_UDP_PORT=1536 +#Let Python Free +OJ_PYTHON_FREE=0 +#allow NOIP using data.in as input file +OJ_COPY_DATA=0 + + diff --git a/judger/install/judged b/judger/install/judged index b3992016..20fd6dfc 100755 --- a/judger/install/judged +++ b/judger/install/judged @@ -18,12 +18,17 @@ # Do NOT "set -e" # PATH should only include /usr/* if it runs after the mountnfs.sh script + +export LANG="zh_CN.UTF-8" +export LANGUAGE="zh_CN:zh" +export PATH="/home/judge/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games" + PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin DESC="Judge Service of HUST Online Judge" NAME=judged DAEMON=/usr/bin/$NAME DAEMON_ARGS="" -PIDFILE=/var/run/$NAME.pid +PIDFILE=/home/judge/etc/judge.pid SCRIPTNAME=/etc/init.d/$NAME # Exit if the package is not installed @@ -73,7 +78,7 @@ do_stop() # 1 if daemon was already stopped # 2 if daemon could not be stopped # other if a failure occurred - start-stop-daemon --stop --retry=10 --pidfile $PIDFILE --name $NAME + kill -9 `cat $PIDFILE` RETVAL="$?" [ "$RETVAL" = 2 ] && return 2 # Wait for children to finish too if this is a daemon that forks diff --git a/judger/install/update.sql b/judger/install/update.sql new file mode 100644 index 00000000..6d72532b --- /dev/null +++ b/judger/install/update.sql @@ -0,0 +1,75 @@ +-- ---------------------------- +-- 2020/3/30 DATABASE update by lixun2015 +-- ---------------------------- +set names utf8; +use jol; +ALTER TABLE `contest` ADD COLUMN `user_id` VARCHAR(48) NOT NULL DEFAULT 'admin' AFTER `password`; +ALTER TABLE `contest` ADD COLUMN `isTop` tinyint(1) NOT NULL DEFAULT 0 AFTER `practice`; +ALTER TABLE `solution` MODIFY COLUMN `pass_rate` DECIMAL(3,2) UNSIGNED NOT NULL DEFAULT '0.00'; +ALTER TABLE `printer_code` MODIFY COLUMN `user_id` CHAR(48) NOT NULL; +ALTER TABLE `privilege` MODIFY COLUMN `user_id` CHAR(48) NOT NULL; +ALTER TABLE `solution` MODIFY COLUMN `user_id` CHAR(48) NOT NULL; +ALTER TABLE `problemset` MODIFY COLUMN `index` int(11) NOT NULL AUTO_INCREMENT FIRST ; +ALTER TABLE `problemset` ADD COLUMN `access_level` tinyint NOT NULL DEFAULT 0; +ALTER TABLE `hit_log` MODIFY COLUMN `ip` varchar(46) DEFAULT NULL; +ALTER TABLE `loginlog` MODIFY COLUMN `ip` varchar(46) DEFAULT NULL; +ALTER TABLE `online` MODIFY COLUMN `ip` varchar(46) CHARACTER SET utf8 NOT NULL DEFAULT ''; +ALTER TABLE `reply` MODIFY COLUMN `ip` varchar(46) DEFAULT NULL; +ALTER TABLE `solution` MODIFY COLUMN `ip` char(46) NOT NULL; +ALTER TABLE `team` MODIFY COLUMN `ip` varchar(46) DEFAULT NULL; +ALTER TABLE `users` MODIFY COLUMN `ip` varchar(46) NOT NULL DEFAULT ''; +ALTER TABLE `users` ADD COLUMN `access_level` tinyint NOT NULL DEFAULT 0; +-- Dump completed on 2019-03-13 17:03:43 +-- ---------------------------- +-- Table structure for `class_list` +-- ---------------------------- +CREATE TABLE `class_list` ( + `class_name` varchar(100) NOT NULL, + `enrollment_year` smallint(4) NOT NULL, + PRIMARY KEY (`class_name`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; +-- ---------------------------- +-- Dumping data for table class_list +-- ---------------------------- +INSERT INTO `class_list` VALUES ('其它', '0'); + +-- ---------------------------- +-- Table structure for `reg_code` +-- ---------------------------- +CREATE TABLE `reg_code` ( + `class_name` varchar(100) NOT NULL, + `reg_code` varchar(100) NOT NULL, + `remain_num` smallint(4) NOT NULL, + PRIMARY KEY (`class_name`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; +-- ---------------------------- +-- Dumping data for table reg_code +-- ---------------------------- +INSERT INTO `reg_code` VALUES ('其它', '', '0'); + +-- ---------------------------- +-- Table structure for `course` +-- ---------------------------- +CREATE TABLE `course` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `section` varchar(255) NOT NULL, + `order` int(11) NOT NULL DEFAULT '10000', + `parent_id` int(11) NOT NULL DEFAULT '0', + `isProblem` tinyint(1) NOT NULL DEFAULT '0', + PRIMARY KEY (`id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; +-- ---------------------------- +-- Records of course +-- ---------------------------- +INSERT INTO `course` VALUES ('1', '入门篇', '0', '0', '0'); +INSERT INTO `course` VALUES ('2', '九阴真经', '1', '0', '0'); +INSERT INTO `course` VALUES ('3', '九阳神功', '2', '0', '0'); +INSERT INTO `course` VALUES ('4', '葵花宝典', '3', '0', '0'); +INSERT INTO `course` VALUES ('5', '辟邪剑谱', '4', '0', '0'); +INSERT INTO `course` VALUES ('6', '平台操作题', '0', '1', '0'); +INSERT INTO `course` VALUES ('7', '输出题入门', '1', '1', '0'); +INSERT INTO `course` VALUES ('8', '计算题入门', '2', '1', '0'); +INSERT INTO `course` VALUES ('9', '分支结构入门', '3', '1', '0'); +INSERT INTO `course` VALUES ('10', '循环结构入门', '4', '1', '0'); +INSERT INTO `course` VALUES ('11', '1000', '0', '6', '1'); + diff --git a/judger/install/upgrade_core.sh b/judger/install/upgrade_core.sh new file mode 100644 index 00000000..5be6e784 --- /dev/null +++ b/judger/install/upgrade_core.sh @@ -0,0 +1,14 @@ +#!/bin/bash +printf "Upgrade Core? Input 'y' to continue:" +read confirm +if test $confirm = "y" +then + set -e -x + pkill -9 judged + cd ../core/ + bash ./make.sh + judged + ps -A | grep judged +else + printf "Nothing have been changed." +fi diff --git a/web/OJ/admin-tools/cal_scores.php b/web/OJ/admin-tools/cal_scores.php index d44c5e3b..24d408cc 100755 --- a/web/OJ/admin-tools/cal_scores.php +++ b/web/OJ/admin-tools/cal_scores.php @@ -201,5 +201,5 @@ classList: - + diff --git a/web/OJ/admin-tools/solution-static.php b/web/OJ/admin-tools/solution-static.php index ddeb9b25..a5891ac6 100755 --- a/web/OJ/admin-tools/solution-static.php +++ b/web/OJ/admin-tools/solution-static.php @@ -11,8 +11,8 @@
- - + + query($sql); diff --git a/web/OJ/admin-tools/updateRank2.php b/web/OJ/admin-tools/updateRank2.php index 52170f91..92d9c23c 100755 --- a/web/OJ/admin-tools/updateRank2.php +++ b/web/OJ/admin-tools/updateRank2.php @@ -12,16 +12,18 @@ 10"; $result = $mysqli->query($sql) or die($mysqli->error); if($result) $user_cnt_divisor = $result->num_rows; else $user_cnt_divisor = 1; -echo $user_cnt_divisor."
"; +if(!$silent) echo $user_cnt_divisor."
"; // 获取用户总量 $sql = "SELECT user_id FROM users"; @@ -34,7 +36,7 @@ $user_info[$i] = $result_user->fetch_object(); } $result_user->free(); -echo $user_cnt."
"; +if(!$silent) echo $user_cnt."
"; // 获取hznuoj分数 for ($i=0; $i<$user_cnt; $i++) { @@ -91,10 +93,15 @@ // 更新用户信息 $sql="UPDATE users SET solved=".$AC.",submit=".$Submit.",level='".$level."',strength=".$strength.",color='".$color."' WHERE user_id='".$user_mysql."'"; $result=$mysqli->query($sql); - echo "
$sql
"; + if(!$silent) echo "
$sql
"; } - +if($silent){ + echo ""; + exit(0); +} echo "update rank successfully!"; ?> diff --git a/web/OJ/admin-tools/updateScores.php b/web/OJ/admin-tools/updateScores.php deleted file mode 100755 index cd715ba2..00000000 --- a/web/OJ/admin-tools/updateScores.php +++ /dev/null @@ -1,50 +0,0 @@ -10"; -$result_user = $mysqli->query($sql) or die($mysqli->error); -$row = $result_user->fetch_object(); -$user_cnt = $row->num; -$result_user->free(); -//echo $user_cnt; - -// get all problem id -$sql = "SELECT problem_id FROM problem"; -$result_prob = $mysqli->query($sql) or die($mysqli->error); -if ($result_prob) $prob_cnt = $result_prob->num_rows; -else $prob_cnt = 0; - -for ($i = 0; $i < $prob_cnt; $i++) { - $row_prob = $result_prob->fetch_object(); - $prob_id = $row_prob->problem_id; - - // get AC and submit numbers - $sql = "SELECT solved_user, submit_user FROM problem WHERE problem_id=" . $prob_id; - $result = $mysqli->query($sql) or die($mysqli->error); - $row = $result->fetch_object(); - $solved = $row->solved_user; - $submit = $row->submit_user; - - // calculate scores - $scores = 100.0 * (1 - ($solved + $submit / 2.0) / $user_cnt); - if ($scores < 10) $scores = 10; - //echo $user_cnt." ".$prob_id.":".$solved." ".$submit." ".$scores."
"; - // update scores - $sql = "UPDATE problem SET scores=" . $scores . " WHERE problem_id=" . $prob_id; - $mysqli->query($sql) or die($mysqli->error); - - echo $prob_id . ":" . $scores . "
"; - - $result->free(); -} -$result_prob->free(); - -echo "update scores successfully!"; diff --git a/web/OJ/admin/admin-bar.php b/web/OJ/admin/admin-bar.php deleted file mode 100755 index 8d285216..00000000 --- a/web/OJ/admin/admin-bar.php +++ /dev/null @@ -1,8 +0,0 @@ - diff --git a/web/OJ/admin/admin-footer.php b/web/OJ/admin/admin-footer.php index 9fbb25b2..b36376c0 100755 --- a/web/OJ/admin/admin-footer.php +++ b/web/OJ/admin/admin-footer.php @@ -1,19 +1,21 @@ - + - + - - - + + + +"; ?> - - \ No newline at end of file diff --git a/web/OJ/admin/admin-header.php b/web/OJ/admin/admin-header.php index eccaee92..d94ea7fd 100755 --- a/web/OJ/admin/admin-header.php +++ b/web/OJ/admin/admin-header.php @@ -7,6 +7,16 @@ ?> + @@ -16,20 +26,19 @@ - - + "> + - - + + Premission Denied! Please Log in!"; + echo "

Premission Denied! Please Log in!

"; exit(0); } $can_see_problem=false; @@ -50,26 +59,31 @@ }