import org.python.core.*; import java.text.*; import java.io.*; public class _rl_accel{ public static String version = "0.30"; private static String[] formats = {"#", "#.#", "#.##", "#.###", "#.####", "#.#####", "#.######"}; public static Object fp_str(PyObject[] args){ StringBuffer buffer = new StringBuffer(); if(args.length==1 && args[0] instanceof PySequence){ //iterate through the first element PySequence seq = (PySequence)args[0]; for(int i=0;i1.0) l = (Math.min(Math.max(0,(6-(int)(Math.log(Math.abs(d))/log_e_10))),6)); else l = 6; NumberFormat formatter = new DecimalFormat(formats[l]); num = formatter.format(d); if(num.startsWith("0")&&(num.length()>1)) num = num.substring(1); } buffer.append(num).append(' '); } public static String escapePDF(String text){ int textlen = text.length(); StringBuffer out = new StringBuffer(textlen*4); int i=0; while(i=127){ String buf = Integer.toOctalString((int)c); out.append('\\'); if(buf.length()<3){ if(buf.length()<2) out.append('0'); out.append('0'); } out.append(buf); } else{ if(c=='\\' || c=='(' || c==')') out.append('\\'); out.append(c); } } return out.toString(); } public static String _instanceEscapePDF(String text){ return escapePDF(text); } static long a85_0 = 1; static long a85_1 = 85; static long a85_2 = 7225; static long a85_3 = 614125; static long a85_4 = 52200625; public static String _AsciiBase85Encode(String inData){ int length = inData.length(); int blocks, extra, i, k, lim; long block, res; blocks = length / 4; extra = length % 4; StringBuffer buf = new StringBuffer((blocks+1)*5+3); lim = 4*blocks; for(k=i=0; i0){ block = 0L; for (i=0; i=1){ block -= res*a85_4; res = block/a85_3; buf.append((char)(res+33)); if(extra>=2){ block -= res*a85_3; res = block/a85_2; buf.append((char)(res+33)); if(extra>=3) buf.append((char)((block-res*a85_2)/a85_1+33)); } } } buf.append('~'); buf.append('>'); return buf.toString(); } public static final boolean isWhitespace(int ch){ return (ch == 0 || ch == 9 || ch == 10 || ch == 12 || ch == 13 || ch == 32); } public static String _AsciiBase85Decode(String inData){ ByteArrayOutputStream out = new ByteArrayOutputStream(); int state = 0; int chn[] = new int[5]; int len = inData.length(); for(int k = 0; k 'u') throw new RuntimeException("Illegal character in _AsciiBase85Decode."); chn[state] = ch - '!'; ++state; if(state == 5){ state = 0; int r = 0; for (int j = 0; j < 5; ++j) r = r*85 + chn[j]; out.write((byte)(r>>24)); out.write((byte)(r>>16)); out.write((byte)(r>>8)); out.write((byte)r); } } long r; if(state==1) throw new RuntimeException("Illegal length in _AsciiBase85Decode."); if (state == 2) { r = ((chn[0]*85+ chn[1])*85*85*85 + 0xfffff)&0x0ffffffffL; out.write((byte)(r>>24)); } else if (state == 3) { r = (((chn[0]*85 + chn[1])*85 + chn[2])*85*85+0xffff)&0x0ffffffffL; out.write((byte)(r >> 24)); out.write((byte)(r >> 16)); } else if (state == 4) { r = ((((chn[0]*85 + chn[1])*85 + chn[2])*85 + chn[3])*85+0xff)&0x0ffffffffL; out.write((byte)(r >> 24)); out.write((byte)(r >> 16)); out.write((byte)(r >> 8)); } return out.toString(); } public static int calcChecksum(String data){ int dl = data.length(); int i; long sum = 0L; long n; int leftover; /*full ULONGs*/ for(i=0;(dl-i)>=4;i+=4){ n = ((int)data.charAt(i)) << 24; n += ((int)data.charAt(i+1)) << 16; n += ((int)data.charAt(i+2)) << 8; n += (int)data.charAt(i+3); sum += n; } /*pad with zeros*/ leftover = dl & 3; if(leftover>0){ n = ((int)data.charAt(i)) << 24;; if (leftover>1) n += ((int)data.charAt(i+1)) << 16; if (leftover>2) n += ((int)data.charAt(i+2)) << 8; sum += n; } return (int)sum; } }