void RMQ(int d[][maxn], int M, int N, int ret[][maxn][LOG][LOG]) { //下标从1开始,M是行,N是列 for (int m = 1; m <= maxn; m++) //需要计算很多次时耗时很大!!!需要预处理 _log[m] = (int) (log(m * 1.0) / log(2.0)); for (int i = 1; i <= M; i++) for (int j = 1; j <= N; j++) ret[i][j][0][0] = d[i][j]; int row = getlog(M), col = getlog(N); for (int R = 0; R <= row; R++) { for (int C = 0; C <= col; C++) { for (int i = 1; i + (1 << R) - 1 <= M; i++) { for (int j = 1; j + (1 << C) - 1 <= N; j++) { if (R == 0 && C == 0) continue; if (R == 0) ret[i][j][R][C] = max(ret[i][j][R][C - 1], ret[i][j + (1 << (C - 1))][R][C - 1]); else if (C == 0) ret[i][j][R][C] = max(ret[i][j][R - 1][C], ret[i + (1 << (R - 1))][j][R - 1][C]); else ret[i][j][R][C] = max(max(ret[i][j][R - 1][C - 1], ret[i + (1 << (R - 1))][j][R - 1][C - 1]), max(ret[i][j + (1 << (C - 1))][R - 1][C - 1], ret[i + (1 << (R - 1))][j + (1 << (C - 1))][R - 1][C - 1]) ); } } } } }
inline int query(int r1, int c1, int r2, int c2, int ret[][maxn][LOG][LOG]) { int R = getlog(r2 - r1 + 1); int C = getlog(c2 - c1 + 1); return max(max(ret[r1][c1][R][C], ret[r2 - (1 << R) + 1][c1][R][C]), max(ret[r1][c2 - (1 << C) + 1][R][C], ret[r2 - (1 << R) + 1][c2 - (1 << C) + 1][R][C]) ); }
primitiveErrorAndLog(void) { char *log; sqInt logLen; sqInt logObj; char *logObjData; sqInt resultObj; logLen = 0; log = getlog((&logLen)); resultObj = instantiateClassindexableSize(classArray(), 2); if (resultObj == 0) { primitiveFailFor(PrimErrNoMemory); return null; } storePointerofObjectwithValue(0, resultObj, integerObjectOf(errorAcorn())); if (logLen > 0) { pushRemappableOop(resultObj); logObj = instantiateClassindexableSize(classString(), logLen); if (failed()) { popRemappableOop(); primitiveFailFor(PrimErrNoMemory); return null; } resultObj = popRemappableOop(); logObjData = arrayValueOf(logObj); memcpy(logObjData, log, logLen); storePointerofObjectwithValue(1, resultObj, logObj); } popthenPush(1, resultObj); if (failed()) { return null; } return null; }
primitiveDisassembleAtInMemory(void) { usqIntptr_t address; void *cpu; sqInt cpuAlien; sqInt instrLenOrErr; sqInt log; sqInt logLen; sqInt logObj; sqInt logObjData; char *memory; sqInt resultObj; logLen = 0; address = (BytesPerOop == 4 ? positive32BitValueOf(stackValue(1)) : positive64BitValueOf(stackValue(1))); success(isWordsOrBytes(stackValue(0))); memory = ((char *) (firstIndexableField(stackValue(0)))); cpuAlien = stackValue(2); if (failed()) { return null; } if (((cpu = ((longAt(cpuAlien + BaseHeaderSize)) > 0 ? (cpuAlien + BaseHeaderSize) + BytesPerOop : longAt((cpuAlien + BaseHeaderSize) + BytesPerOop)))) == 0) { primitiveFailFor(PrimErrBadReceiver); return null; } instrLenOrErr = disassembleForAtInSize(cpu, address, memory, byteSizeOf(((sqInt)(sqIntptr_t)(memory) - BaseHeaderSize))); if (instrLenOrErr < 0) { primitiveFailFor(PrimErrInappropriate); return null; } log = getlog((&logLen)); resultObj = instantiateClassindexableSize(classArray(), 2); if (resultObj == 0) { primitiveFailFor(PrimErrNoMemory); return null; } pushRemappableOop(resultObj); logObj = instantiateClassindexableSize(classString(), logLen); if (failed()) { popRemappableOop(); primitiveFailFor(PrimErrNoMemory); return null; } logObjData = arrayValueOf(logObj); memcpy(logObjData, log, logLen); resultObj = popRemappableOop(); storePointerofObjectwithValue(0, resultObj, integerObjectOf(instrLenOrErr)); storePointerofObjectwithValue(1, resultObj, logObj); if (failed()) { return null; } popthenPush(3, resultObj); return null; }
extern int default_from(message *mp) { char *cp, *lp; cp = getenv("upasname"); lp = getlog(); if(lp == nil) return -1; if(cp && *cp) s_append(mp->sender, cp); else s_append(mp->sender, lp); s_append(mp->date, thedate()); return 0; }
int savelog(char *filename) { FILE *fp; char *log; fp = fopen(filename, "w"); if ( fp == NULL ) { fprintf(stderr, "Can't open file!\n"); return -1; } else { log = getlog(); fprintf(fp, "%s", log); free(log); } return 0; }