/* * 初始化素数信息, 其中bound表示大致估计的需要判断素数的一个范围 */ void initPrime(long bound) { FILE *fin = fopen(FILENAME, "rb"); FILE *fout; long i, j, k, length; long len, num; printf("Initializing New Prime_List...\n"); if (fin == NULL) { /* 若文件不存在, 则创建一个新的 */ createPrime(bound); } else { /* 否则从文件中读取信息 */ fscanf(fin, "%ld", &length); /* 开辟数组空间 */ len = (bound % bits == 0? bound / bits : bound / bits + 1); NEWLIST(len); /* * 从文件中读取信息 * 这里出现两种情况: * 1. 文件中的信息大于给定的上限, 只需要读取即可 * 2. 文件给出的信息小于上线, 除了需要读取文件信息外, 还需要将对未给出的信息进行初始化判断 */ for (i = 0; i < SMALL(length,len); i++) { fscanf(fin, "%ld", &primeList[i]); } fclose(fin); list_len = length; /* 若文件给出信息不足, 则继续进行初始化判断 */ if (len > length) { for (;i < len; i++) { for (j = 0; j < bits; j++) { num = i * bits + j; if (!checkPrime(num)) SETLIST(num); } } /* 将新的信息写入文件 */ fout = fopen("prime.dat", "wb"); fprintf(fout, "%ld\n", len); for (i = 0; i < len; i++) { fprintf(fout, "%ld\n", primeList[i]); } fclose(fout); list_len = len; } } printf("Initializing DONE\n"); return; }
#include "global.h" #include "gtabs.h" #include "structs.h" #include "frame.h" #include <stdio.h> /*char firstalloc[NBPG] = { 'x' }; /* first thing allocated in file */ lispval lispsys[SIGNIF]; /* lisp data used by system */ lispval gftab[GFTABLEN]; /* global function table for interpreter */ lispval gctab[GCTABLEN] = /* global constant table for interpreter */ {nil,0,SMALL(-1),SMALL(0),SMALL(1),SMALL(2),SMALL(3),SMALL(4)}; /* Port definitions *****************************************************/ FILE *piport, /* standard input port */ *poport, /* standard output port */ *errport, /* port for error messages */ *rdrport, /* temporary port for readr */ *proport; /* port for protocal */ int lineleng = 80; /* line length desired */ int rlevel; /* used to indicate depth of recursion in reader. No longer really necessary */ char keybin = FALSE; /* logical flag: using keyboard */ char protflag = FALSE; /* logical flag: want protocall */ char rbktf; /* logical flag: ] mode */