Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #ifndef SPARKLYCHAR_H
- #define SPARKLYCHAR_H
- #define STR_SEARCH_LOOP_SIZE 16384
- #define isnum(a) ( a >= 48 && a <= 57 )
- #define tonum(a) a -= 48;
- #define islow(a) ( a >= 97 && a <= 122 )
- #define isup(a) ( a >= 65 && a <= 90 )
- #define tolow(a) a = 97 + ( a - 65 )
- #define toup(a) a = 65 + ( a - 97 )
- #include "sparklycore.h"
- #if defined SPwindow
- #include <tchar.h>
- #endif
- #include "lz4\lz4.h"
- #include "lzma.h"
- namespace str
- {
- inline unsigned char *decompress(unsigned char *in, unsigned int *outsize)
- {
- unsigned char *c;
- int osize;
- int osize3;
- int omax;
- bool du = 0;
- *outsize = 0;
- unsigned int osize2;
- switch( in[0] )
- {
- case 32:
- {
- osize = (in[4] << 24) | (in[3] << 16) | (in[2] << 8) | (in[1]);
- omax = (in[8] << 24) | (in[7] << 16) | (in[6] << 8) | (in[5]);
- c = new unsigned char[omax];
- osize3 = LZ4_decompress_safe((char *)&in[9], (char *)c, osize, omax);
- *outsize =osize3;
- return c;
- break;
- }
- case 64:
- {
- in[0] = 0;
- du = fp_uncompress( in, &c, &osize2 );
- if( !du ) return 0;
- *outsize = osize2;
- return c;
- break;
- }
- }
- return 0;
- }
- inline unsigned char *compress( int type, unsigned char *in, unsigned int insize, unsigned int *outsize)
- {
- int osize = 0, a;
- unsigned int osize2 = 0;
- unsigned char *c;
- char *b;
- *outsize = 0;
- switch(type)
- {
- case 0:
- {
- c = new unsigned char[insize+9];
- osize = LZ4_compress((char *)in, (char *)&c[9], insize);
- b = (char *)&osize;
- c[0] = 32;
- for( a = 0; a < 4; a++) c[a+1] = b[a];
- b = (char *)&insize;
- for( a = 0; a < 4; a++) c[a+5] = b[a];
- *outsize = osize+9;
- return c;
- break;
- }
- case 1:
- {
- c = fp_compress( in, insize, &osize2, 18 );
- c[0] = 64;
- *outsize = osize2;
- return c;
- break;
- }
- }
- return 0;
- }
- inline int size( char * in )
- {
- int a;
- for( a = 0; a < STR_SEARCH_LOOP_SIZE; a++) { if( !in[a] ) return a; }
- return 0;
- }
- inline int ref( char *in )
- {
- int ref = 0;
- for( int a = 0; a < STR_SEARCH_LOOP_SIZE; a++ ) { if( !in[a] ) break; ref += in[a]; }
- }
- inline int ref( char *in, int isize )
- {
- int ref = 0;
- for( int a = 0; a < isize; a++ ) ref += in[a];
- }
- inline int add( char *in, int ilen, char *what )
- {
- int s = size(in);
- int s2 = size(what);
- int addsize = 0;
- if( s >= ilen ) return s;
- if( s + s2 >= ilen ) addsize = ilen - 1;
- else addsize = s + s2;
- for( int a = s; a < addsize; a++ ) in[a] = what[a - s];
- in[addsize] = 0;
- return addsize;;
- }
- inline int add( char *in, int isize, int ilen, char *what )
- {
- int s2 = size(what);
- int addsize = 0;
- if( isize >= ilen ) return isize;
- if( isize + s2 >= ilen ) addsize = ilen - 1;
- else addsize = isize + s2;
- for( int a = isize; a < addsize; a++ ) in[a] = what[a - isize];
- in[addsize] = 0;
- return addsize;
- }
- inline int add( char *in, int ilen, char *what, int iwhat )
- {
- int s = size(in);
- int addsize = 0;
- if( s >= ilen ) return s;
- if( s + iwhat >= ilen ) addsize = ilen - 1;
- else addsize = s + iwhat;
- for( int a = s; a < addsize; a++ ) in[a] = what[a - s];
- in[addsize] = 0;
- return addsize;
- }
- inline int add( char *in, int isize, int ilen, char *what, int iwhat )
- {
- int addsize = 0;
- if( isize >= ilen ) return isize;
- if( isize + iwhat >= ilen ) addsize = ilen - 1;
- else addsize = isize + iwhat;
- for( int a = isize; a < addsize; a++ ) in[a] = what[a - isize];
- in[addsize] = 0;
- return addsize;
- }
- inline int add( int pos, char *in, int ilen, char *what )
- {
- int s = size(in), a, s2 = size(what);
- if( s >= ilen ) return s;
- if( s + s2 >= ilen ) s += ilen - (s + s2) - 1;
- for( a = s; a >= pos; a-- ) in[a+s2] = in[a];
- for( a = pos; a < pos + s2; a++ ) in[a] = what[a - pos];
- in[s+s2] = 0;
- return s+s2;
- }
- inline int add( int pos, char *in, int ilen, char *what, int iwhat )
- {
- int s = size(in), a;
- if( s >= ilen ) return s;
- if( s + iwhat >= ilen ) s += ilen - (s + iwhat) - 1;
- for( a = s; a >= pos; a-- ) in[a+iwhat] = in[a];
- for( a = pos; a < pos + iwhat; a++ ) in[a] = what[a - pos];
- in[s+iwhat] = 0;
- return s+iwhat;
- }
- inline int set( char *line, int ilen, char *in )
- {
- int s = size(in), a;
- for( a = 0; a < s; a++ ) line[a] = in[a];
- line[s] = 0;
- }
- inline int set( char *line, int ilen, char *in, int iin )
- {
- int a;
- for( a = 0; a < iin; a++ ) line[a] = in[a];
- line[iin] = 0;
- }
- inline int remove( char *line, int start, int end )
- {
- int s = size(line);
- if( end == -1 ) end = s - 1;
- if( end > s ) end = s;
- if( start > end ) start = end - 1;
- int r = (end - start) + 1;
- for( int a = start; a <= s - r; a++ ) line[a] = line[a+r];
- s -= r;
- return s;
- }
- inline int remove( char *line, int iline, int start, int end )
- {
- if( end == -1 ) end = iline - 1;
- if( end > iline ) end = iline;
- if( start > end ) start = end - 1;
- int r = (end - start) + 1;
- for( int a = start; a <= iline - r; a++ ) line[a] = line[a+r];
- iline -= r;
- return iline;
- }
- inline int find( char *line, char *what )
- {
- int a, s = size(what), c = 0, s2 = size(line);
- for( a = 0; a < s2; a++ )
- {
- if( c >= s ) return a - s;
- if( line[a] == what[c] )
- {
- c++;
- continue;
- }
- if( c ) a--;
- c = 0;
- }
- if( c == s ) return a - s;
- return -1;
- }
- inline int find( char *line, char *what, int iwhat )
- {
- int a, c = 0, s2 = size(line);
- for( a = 0; a < s2; a++ )
- {
- if( c >= iwhat ) return a - iwhat;
- if( line[a] == what[c] )
- {
- c++;
- continue;
- }
- if( c ) a--;
- c = 0;
- }
- if( c == iwhat ) return a - iwhat;
- return -1;
- }
- inline int find( char *line, int iline, char *what, int iwhat )
- {
- int a, c = 0;
- for( a = 0; a < iline; a++ )
- {
- if( c >= iwhat ) return a - iwhat;
- if( line[a] == what[c] )
- {
- c++;
- continue;
- }
- if( c ) a--;
- c = 0;
- }
- if( c == iwhat ) return a - iwhat;
- return -1;
- }
- inline int find( int pos, char *line, char *what )
- {
- int a, s = size(what), c = 0, s2 = size(line);
- if( pos >= s2 ) return -1;
- for( a = pos; a < s2; a++ )
- {
- if( c >= s ) return a - s;
- if( line[a] == what[c] )
- {
- c++;
- continue;
- }
- if( c ) a--;
- c = 0;
- }
- if( c == s ) return a - s;
- return -1;
- }
- inline int find( int pos, char *line, char *what, int iwhat )
- {
- int a, c = 0, s2 = size(line);
- if( pos >= s2 ) return -1;
- for( a = pos; a < s2; a++ )
- {
- if( c >= iwhat ) return a - iwhat;
- if( line[a] == what[c] )
- {
- c++;
- continue;
- }
- if( c ) a--;
- c = 0;
- }
- if( c == iwhat ) return a - iwhat;
- return -1;
- }
- inline int find( int pos, char *line, int iline, char *what, int iwhat )
- {
- int a, c = 0;
- if( pos >= iline ) return -1;
- for( a = pos; a < iline; a++ )
- {
- if( c >= iwhat ) return a - iwhat;
- if( line[a] == what[c] )
- {
- c++;
- continue;
- }
- if( c ) a--;
- c = 0;
- }
- if( c == iwhat ) return a - iwhat;
- return -1;
- }
- inline bool replace( char *line, int ilen, char *what, char *with )
- {
- int s1 = size(what);
- int s0 = size(line);
- int i = find( line, s0, what, s1 );
- if( i == -1 ) return 0;
- int s2 = str::size(with);
- remove(line, s0, i, i + s1 - 1);
- add( i, line, ilen, with, s2 );
- return 1;
- }
- inline void trim( char *line, char what )
- {
- int r1e = 0, a, s = size(line);
- for( a = 0; a < s; a++ )
- {
- if( line[a] != what ) break;
- r1e++;
- }
- if( r1e > 0 ) s = remove( line, s, 0, r1e - 1 );
- if( !s ) return;
- int r2s = s;
- for( a = s - 1; a >= 0; a-- )
- {
- if( line[a] != what ) break;
- r2s--;
- }
- if( r2s == s ) return;
- remove( line, s, r2s, s - 1);
- }
- inline void trim( char *line, int iline, char what )
- {
- int r1e = 0, a;
- for( a = 0; a < iline; a++ )
- {
- if( line[a] != what ) break;
- r1e++;
- }
- if( r1e > 0 ) iline = remove( line, iline, 0, r1e - 1 );
- if( !iline ) return;
- int r2s = iline;
- for( a = iline - 1; a >= 0; a-- )
- {
- if( line[a] != what ) break;
- r2s--;
- }
- if( r2s == iline ) return;
- remove( line, iline, r2s, iline - 1);
- }
- inline bool same( char *line, char *line2 )
- {
- int s1 = size(line), s2 = size(line2);
- if( s1 != s2 ) return 0;
- for( int a = 0; a < s1; a++ ) if( line[a] != line2[a] ) return 0;
- return 1;
- }
- inline bool same( char *line, char *line2, int iline2 )
- {
- int s1 = size(line);
- if( s1 != iline2 ) return 0;
- for( int a = 0; a < s1; a++ ) if( line[a] != line2[a] ) return 0;
- return 1;
- }
- inline bool same( char *line, int iline, char *line2, int iline2 )
- {
- if( iline != iline2 ) return 0;
- for( int a = 0; a < iline; a++ ) if( line[a] != line2[a] ) return 0;
- return 1;
- }
- inline bool same2( char *line, char *line2 )
- {
- char low[2];
- int s1 = size(line), s2 = size(line2);
- if( s1 != s2 ) return 0;
- for( int a = 0; a < s1; a++ )
- {
- low[0] = line[a];
- low[1] = line2[a];
- if( isup(low[0]) ) tolow(low[0]);
- if( isup(low[1]) ) tolow(low[1]);
- if( low[0] != low[1] ) return 0;
- }
- return 1;
- }
- inline bool same2( char *line, char *line2, int iline2 )
- {
- char low[2];
- int s1 = size(line);
- if( s1 != iline2 ) return 0;
- for( int a = 0; a < s1; a++ )
- {
- low[0] = line[a];
- low[1] = line2[a];
- if( isup(low[0]) ) tolow(low[0]);
- if( isup(low[1]) ) tolow(low[1]);
- if( low[0] != low[1] ) return 0;
- }
- return 1;
- }
- inline bool same2( char *line, int iline, char *line2, int iline2 )
- {
- char low[2];
- if( iline != iline2 ) return 0;
- for( int a = 0; a < iline; a++ )
- {
- low[0] = line[a];
- low[1] = line2[a];
- if( isup(low[0]) ) tolow(low[0]);
- if( isup(low[1]) ) tolow(low[1]);
- if( low[0] != low[1] ) return 0;
- }
- return 1;
- }
- inline int find2( char *line, char *what )
- {
- int a, s = size(what), c = 0, s2 = size(line);
- char low[2];
- for( a = 0; a < s2; a++ )
- {
- if( c >= s ) return a - s;
- low[0] = line[a];
- low[1] = what[c];
- if( isup(low[0]) ) tolow(low[0]);
- if( isup(low[1]) ) tolow(low[1]);
- if( low[0] == low[1] )
- {
- c++;
- continue;
- }
- if( c ) a--;
- c = 0;
- }
- if( c == s ) return a - s;
- return -1;
- }
- inline int find2( char *line, char *what, int iwhat )
- {
- int a, c = 0, s2 = size(line);
- char low[2];
- for( a = 0; a < s2; a++ )
- {
- if( c >= iwhat ) return a - iwhat;
- low[0] = line[a];
- low[1] = what[c];
- if( isup(low[0]) ) tolow(low[0]);
- if( isup(low[1]) ) tolow(low[1]);
- if( low[0] == low[1] )
- {
- c++;
- continue;
- }
- if( c ) a--;
- c = 0;
- }
- if( c == iwhat ) return a - iwhat;
- return -1;
- }
- inline int find2( char *line, int iline, char *what, int iwhat )
- {
- int a, c = 0;
- char low[2];
- for( a = 0; a < iline; a++ )
- {
- if( c >= iwhat ) return a - iwhat;
- low[0] = line[a];
- low[1] = what[c];
- if( isup(low[0]) ) tolow(low[0]);
- if( isup(low[1]) ) tolow(low[1]);
- if( low[0] == low[1] )
- {
- c++;
- continue;
- }
- if( c ) a--;
- c = 0;
- }
- if( c == iwhat ) return a - iwhat;
- return -1;
- }
- inline int find2( int pos, char *line, char *what )
- {
- int a, s = size(what), c = 0, s2 = size(line);
- if( pos >= s2 ) return -1;
- char low[2];
- for( a = pos; a < s2; a++ )
- {
- if( c >= s ) return a - s;
- low[0] = line[a];
- low[1] = what[c];
- if( isup(low[0]) ) tolow(low[0]);
- if( isup(low[1]) ) tolow(low[1]);
- if( low[0] == low[1] )
- {
- c++;
- continue;
- }
- if( c ) a--;
- c = 0;
- }
- if( c == s ) return a - s;
- return -1;
- }
- inline int find2( int pos, char *line, char *what, int iwhat )
- {
- int a, c = 0, s2 = size(line);
- if( pos >= s2 ) return -1;
- char low[2];
- for( a = pos; a < s2; a++ )
- {
- if( c >= iwhat ) return a - iwhat;
- low[0] = line[a];
- low[1] = what[c];
- if( isup(low[0]) ) tolow(low[0]);
- if( isup(low[1]) ) tolow(low[1]);
- if( low[0] == low[1] )
- {
- c++;
- continue;
- }
- if( c ) a--;
- c = 0;
- }
- if( c == iwhat ) return a - iwhat;
- return -1;
- }
- inline int find2( int pos, char *line, int iline, char *what, int iwhat )
- {
- int a, c = 0;
- if( pos >= iline ) return -1;
- char low[2];
- for( a = pos; a < iline; a++ )
- {
- if( c >= iwhat ) return a - iwhat;
- low[0] = line[a];
- low[1] = what[c];
- if( isup(low[0]) ) tolow(low[0]);
- if( isup(low[1]) ) tolow(low[1]);
- if( low[0] == low[1] )
- {
- c++;
- continue;
- }
- if( c ) a--;
- c = 0;
- }
- if( c == iwhat ) return a - iwhat;
- return -1;
- }
- inline bool breakstr( char *line, char *out, int outsize, char *token )
- {
- int lsize = size(line);
- if( !lsize ) { out[0] = 0; return 0; }
- outsize--;
- int a;
- int tsize = size(token);
- int tpos = find(line, lsize, token, tsize);
- int wsize = 0;
- if( tpos == -1 )
- {
- if( lsize >= outsize ) { wsize = outsize; out[outsize - 1] = 0; }
- else { wsize = lsize; out[wsize] = 0; }
- for( a = 0; a < wsize; a++ ) out[a] = line[a];
- remove( line, lsize, 0, lsize - 1 );
- return 0;
- }
- if( tpos >= outsize ) { wsize = outsize; out[outsize - 1] = 0; }
- else { wsize = tpos; out[wsize] = 0; }
- for( a = 0; a < wsize; a++ ) out[a] = line[a];
- remove( line, lsize, 0, tpos + (tsize - 1) );
- return 1;
- }
- inline bool breakstr( char *line, int from, char *out, int outlen )
- {
- int s = size(line), a;
- if( s >= from ) { out[0] = 0; return 0; }
- if( s - from >= outlen - 1 ) s += ((outlen - 1) - (s - from));
- for( a = from; a < s; a++ ) { out[a - from] = line[a]; }
- line[from] = 0;
- out[s - from] = 0;
- }
- inline void to_low(char *in)
- {
- int a, s = size(in);
- for( a = 0; a < s; a++ ) if( isup(in[a]) ) tolow(in[a]);
- }
- inline void to_up(char *in)
- {
- int a, s = size(in);
- for( a = 0; a < s; a++ ) if( islow(in[a]) ) toup(in[a]);
- }
- inline void to_low(char *in, int isize)
- {
- int a;
- for( a = 0; a < isize; a++ ) if( isup(in[a]) ) tolow(in[a]);
- }
- inline void to_up(char *in, int isize)
- {
- int a;
- for( a = 0; a < isize; a++ ) if( islow(in[a]) ) toup(in[a]);
- }
- inline int get_num(char *in)
- {
- int res = 0, sign = 1, i = 0;
- if (in[0] == '-') { sign = -1; i++; }
- int s = size(in);
- for(; i < s; ++i )
- {
- if( !isnum(in[i]) ) break;
- res = res*10 + in[i] - '0';
- }
- return sign*res;
- }
- inline int get_num(char *in, int isize)
- {
- int res = 0, sign = 1, i = 0;
- if (in[0] == '-') { sign = -1; i++; }
- for(; i < isize; ++i )
- {
- if( !isnum(in[i]) ) break;
- res = res*10 + in[i] - '0';
- }
- return sign*res;
- }
- inline float get_float(char *in)
- {
- int isize = size(in);
- float res = 0.0f, sign = 1.0f; int i = 0;
- if (in[0] == '-') { sign = -1.0f; i++; }
- for(; i < isize; ++i )
- {
- if( !isnum(in[i]) ) break;
- res = res*10.0f + float(in[i] - '0');
- }
- if( in[i] == '.' )
- {
- i++;
- float lres = 0.1f;
- for(; i < isize; ++i )
- {
- if( !isnum(in[i]) ) break;
- res += lres * float(in[i] - '0');
- lres /= 10.0f;
- }
- }
- return sign*res;
- }
- inline float get_float(char *in, int isize)
- {
- float res = 0.0f, sign = 1.0f; int i = 0;
- if (in[0] == '-') { sign = -1.0f; i++; }
- for(; i < isize; ++i )
- {
- if( !isnum(in[i]) ) break;
- res = res*10.0f + float(in[i] - '0');
- }
- if( in[i] == '.' )
- {
- i++;
- float lres = 0.1f;
- for(; i < isize; ++i )
- {
- if( !isnum(in[i]) ) break;
- res += lres * float(in[i] - '0');
- lres /= 10.0f;
- }
- }
- return sign*res;
- }
- inline double get_double(char *in)
- {
- int isize = size(in);
- double res = 0.0, sign = 1.0; int i = 0;
- if (in[0] == '-') { sign = -1.0; i++; }
- for(; i < isize; ++i )
- {
- if( !isnum(in[i]) ) break;
- res = res*10.0 + double(in[i] - '0');
- }
- if( in[i] == '.' )
- {
- i++;
- double lres = 0.1;
- for(; i < isize; ++i )
- {
- if( !isnum(in[i]) ) break;
- res += lres * double(in[i] - '0');
- lres /= 10.0;
- }
- }
- return sign*res;
- }
- inline double get_double(char *in, int isize)
- {
- double res = 0.0, sign = 1.0; int i = 0;
- if (in[0] == '-') { sign = -1.0; i++; }
- for(; i < isize; ++i )
- {
- if( !isnum(in[i]) ) break;
- res = res*10.0 + double(in[i] - '0');
- }
- if( in[i] == '.' )
- {
- i++;
- double lres = 0.1;
- for(; i < isize; ++i )
- {
- if( !isnum(in[i]) ) break;
- res += lres * double(in[i] - '0');
- lres /= 10.0;
- }
- }
- return sign*res;
- }
- inline void reverse(char *in)
- {
- char t = 0, isize = size(in);
- for( int a = 0; a < isize / 2; a++ )
- {
- t = in[a];
- in[a] = in[(isize - 1) - a];
- in[(isize - 1) - a] = t;
- }
- }
- inline void reverse(char *in, int isize)
- {
- char t = 0;
- for( int a = 0; a < isize / 2; a++ )
- {
- t = in[a];
- in[a] = in[(isize - 1) - a];
- in[(isize - 1) - a] = t;
- }
- }
- inline int to_num( char *line, int num )
- {
- int i = 0, base = 10;
- bool isNegative = false;
- if (num == 0)
- {
- line[i++] = '0';
- line[i] = 0;
- return i;
- }
- if (num < 0 && base == 10)
- {
- isNegative = true;
- num = -num;
- }
- while (num != 0)
- {
- int rem = num % base;
- line[i++] = (rem > 9)? (rem-10) + 'a' : rem + '0';
- num = num/base;
- }
- if (isNegative) line[i++] = '-';
- line[i] = 0;
- reverse(line, i);
- return i;
- }
- inline int to_num( char *line, int num, int base )
- {
- int i = 0;
- bool isNegative = false;
- if (num == 0)
- {
- line[i++] = '0';
- line[i] = 0;
- return i;
- }
- if (num < 0 && base == 10)
- {
- isNegative = true;
- num = -num;
- }
- while (num != 0)
- {
- int rem = num % base;
- line[i++] = (rem > 9)? (rem-10) + 'a' : rem + '0';
- num = num/base;
- }
- if (isNegative) line[i++] = '-';
- line[i] = 0;
- reverse(line, i);
- return i;
- }
- inline int to_long( char *line, long num )
- {
- int i = 0; long base = 10;
- bool isNegative = false;
- if (num == 0)
- {
- line[i++] = '0';
- line[i] = 0;
- return i;
- }
- if (num < 0 && base == 10)
- {
- isNegative = true;
- num = -num;
- }
- while (num != 0)
- {
- long rem = num % base;
- line[i++] = (char)((rem > 9)? (rem-10) + 'a' : rem + '0');
- num = num/base;
- }
- if (isNegative) line[i++] = '-';
- line[i] = 0;
- reverse(line, i);
- return i;
- }
- inline int to_longlong( char *line, long long num )
- {
- int i = 0; long long base = 10;
- bool isNegative = false;
- if (num == 0)
- {
- line[i++] = '0';
- line[i] = 0;
- return i;
- }
- if (num < 0 && base == 10)
- {
- isNegative = true;
- num = -num;
- }
- while (num != 0)
- {
- long long rem = num % base;
- line[i++] = (char)((rem > 9)? (rem-10) + 'a' : rem + '0');
- num = num/base;
- }
- if (isNegative) line[i++] = '-';
- line[i] = 0;
- reverse(line, i);
- return i;
- }
- inline int to_long( char *line, long num, long base )
- {
- int i = 0;
- bool isNegative = false;
- if (num == 0)
- {
- line[i++] = '0';
- line[i] = 0;
- return i;
- }
- if (num < 0 && base == 10)
- {
- isNegative = true;
- num = -num;
- }
- while (num != 0)
- {
- long rem = num % base;
- line[i++] = char((rem > 9)? (rem-10) + 'a' : rem + '0');
- num = num/base;
- }
- if (isNegative) line[i++] = '-';
- line[i] = 0;
- reverse(line, i);
- return i;
- }
- inline int to_longlong( char *line, long long num, long long base )
- {
- int i = 0;
- bool isNegative = false;
- if (num == 0)
- {
- line[i++] = '0';
- line[i] = 0;
- return i;
- }
- if (num < 0 && base == 10)
- {
- isNegative = true;
- num = -num;
- }
- while (num != 0)
- {
- long long rem = num % base;
- line[i++] = char((rem > 9)? (rem-10) + 'a' : rem + '0');
- num = num/base;
- }
- if (isNegative) line[i++] = '-';
- line[i] = 0;
- reverse(line, i);
- return i;
- }
- inline int to_float( char *line, float fnum )
- {
- char f1[20] = "", f2[20] = "";
- bool isnegative = 0;
- if( fnum < 0.0f )
- {
- fnum *= -1.0f;
- isnegative = 1;
- }
- int num = (int)fnum;
- int lnum = to_num( f1, num );
- fnum -= (float)num;
- int a, d = 0;
- int rnum = 6 - lnum;
- if( lnum == 1 && f1[0] == '0' ) rnum--;
- int i = 0;
- float add = 0.5f;
- if( rnum == 0 )
- {
- fnum *= 10.0f;
- if( int(fnum) + '0' > '4') f1[lnum - 1]++;
- }
- else
- {
- for( a = 0; a < rnum; a++ ) add /= 10.0f;
- fnum += add;
- }
- for( a = 0; a < rnum; a++ )
- {
- fnum *= 10.0f;
- d = int(fnum);
- f2[i] = '0'+ d;
- fnum -= (float)d;
- i++;
- }
- int l = 0;
- if( isnegative ) { line[l] = '-'; l++; }
- for( a = 0; a < lnum; a++ ) { line[l] = f1[a]; l++; }
- line[l] = '.'; l++;
- for( a = 0; a < i; a++ ) { line[l] = f2[a]; l++; }
- for( a = l - 1; a >= 0; a-- )
- {
- if( line[a] != '.' && line[a] != '0' ) break;
- line[a] = 0;
- l--;
- }
- if( l <= 0 )
- {
- line[0] = '0';
- line[1] = '.';
- line[2] = '0';
- l = 3;
- }
- line[l] = 0;
- return l;
- }
- inline int to_float( char *line, float fnum, int p )
- {
- char f1[20] = "", f2[20] = "";
- bool isnegative = 0;
- if( fnum < 0.0f )
- {
- fnum *= -1.0f;
- isnegative = 1;
- }
- int num = (int)fnum;
- int lnum = to_num( f1, num );
- fnum -= (float)num;
- int a, d = 0;
- int rnum = 6 - lnum;
- if( rnum > p ) rnum = p;
- if( lnum == 1 && f1[0] == '0' ) rnum--;
- int i = 0;
- float add = 0.5f;
- if( rnum == 0 )
- {
- fnum *= 10.0f;
- if( int(fnum) + '0' > '4') f1[lnum - 1]++;
- }
- else
- {
- for( a = 0; a < rnum; a++ ) add /= 10.0f;
- fnum += add;
- }
- for( a = 0; a < rnum; a++ )
- {
- fnum *= 10.0f;
- d = int(fnum);
- f2[i] = '0'+ d;
- fnum -= (float)d;
- i++;
- }
- int l = 0;
- if( isnegative ) { line[l] = '-'; l++; }
- for( a = 0; a < lnum; a++ ) { line[l] = f1[a]; l++; }
- line[l] = '.'; l++;
- for( a = 0; a < i; a++ ) { line[l] = f2[a]; l++; }
- for( a = l - 1; a >= 0; a-- )
- {
- if( line[a] != '.' && line[a] != '0' ) break;
- line[a] = 0;
- l--;
- }
- if( l <= 0 )
- {
- line[0] = '0';
- line[1] = '.';
- line[2] = '0';
- l = 3;
- }
- line[l] = 0;
- return l;
- }
- inline int to_double( char *line, double fnum )
- {
- char f1[20] = "", f2[20] = "";
- bool isnegative = 0;
- if( fnum < 0.0 )
- {
- fnum *= -1.0;
- isnegative = 1;
- }
- int num = (int)fnum;
- int lnum = to_num( f1, num );
- fnum -= (double)num;
- int a, d = 0;
- int rnum = 6 - lnum;
- if( lnum == 1 && f1[0] == '0' ) rnum--;
- int i = 0;
- double add = 0.5;
- if( rnum == 0 )
- {
- fnum *= 10.0;
- if( int(fnum) + '0' > '4') f1[lnum - 1]++;
- }
- else
- {
- for( a = 0; a < rnum; a++ ) add /= 10.0;
- fnum += add;
- }
- for( a = 0; a < rnum; a++ )
- {
- fnum *= 10.0;
- d = int(fnum);
- f2[i] = '0'+ d;
- fnum -= (double)d;
- i++;
- }
- int l = 0;
- if( isnegative ) { line[l] = '-'; l++; }
- for( a = 0; a < lnum; a++ ) { line[l] = f1[a]; l++; }
- line[l] = '.'; l++;
- for( a = 0; a < i; a++ ) { line[l] = f2[a]; l++; }
- for( a = l - 1; a >= 0; a-- )
- {
- if( line[a] != '.' && line[a] != '0' ) break;
- line[a] = 0;
- l--;
- }
- if( l <= 0 )
- {
- line[0] = '0';
- line[1] = '.';
- line[2] = '0';
- l = 3;
- }
- line[l] = 0;
- return l;
- }
- inline int to_double( char *line, double fnum, int p )
- {
- char f1[20] = "", f2[20] = "";
- bool isnegative = 0;
- if( fnum < 0.0 )
- {
- fnum *= -1.0;
- isnegative = 1;
- }
- int num = (int)fnum;
- int lnum = to_num( f1, num );
- fnum -= (double)num;
- int a, d = 0;
- int rnum = 6 - lnum;
- if( rnum > p ) rnum = p;
- if( lnum == 1 && f1[0] == '0' ) rnum--;
- int i = 0;
- double add = 0.5;
- if( rnum == 0 )
- {
- fnum *= 10.0;
- if( int(fnum) + '0' > '4') f1[lnum - 1]++;
- }
- else
- {
- for( a = 0; a < rnum; a++ ) add /= 10.0;
- fnum += add;
- }
- for( a = 0; a < rnum; a++ )
- {
- fnum *= 10.0;
- d = int(fnum);
- f2[i] = '0'+ d;
- fnum -= (double)d;
- i++;
- }
- int l = 0;
- if( isnegative ) { line[l] = '-'; l++; }
- for( a = 0; a < lnum; a++ ) { line[l] = f1[a]; l++; }
- line[l] = '.'; l++;
- for( a = 0; a < i; a++ ) { line[l] = f2[a]; l++; }
- for( a = l - 1; a >= 0; a-- )
- {
- if( line[a] != '.' && line[a] != '0' ) break;
- line[a] = 0;
- l--;
- }
- if( l <= 0 )
- {
- line[0] = '0';
- line[1] = '.';
- line[2] = '0';
- l = 3;
- }
- line[l] = 0;
- return l;
- }
- inline int to_double2( char *line, double fnum )
- {
- char f1[20] = "", f2[20] = "";
- bool isnegative = 0;
- if( fnum < 0.0 )
- {
- fnum *= -1.0;
- isnegative = 1;
- }
- int num = (int)fnum;
- int lnum = to_num( f1, num );
- fnum -= (double)num;
- int a, d = 0;
- int rnum = 6;
- if( lnum == 1 && f1[0] == '0' ) rnum--;
- int i = 0;
- double add = 0.5;
- if( rnum == 0 )
- {
- fnum *= 10.0;
- if( int(fnum) + '0' > '4') f1[lnum - 1]++;
- }
- else
- {
- for( a = 0; a < rnum; a++ ) add /= 10.0;
- fnum += add;
- }
- for( a = 0; a < rnum; a++ )
- {
- fnum *= 10.0;
- d = int(fnum);
- f2[i] = '0'+ d;
- fnum -= (double)d;
- i++;
- }
- int l = 0;
- if( isnegative ) { line[l] = '-'; l++; }
- for( a = 0; a < lnum; a++ ) { line[l] = f1[a]; l++; }
- line[l] = '.'; l++;
- for( a = 0; a < i; a++ ) { line[l] = f2[a]; l++; }
- for( a = l - 1; a >= 0; a-- )
- {
- if( line[a] != '.' && line[a] != '0' ) break;
- line[a] = 0;
- l--;
- }
- if( l <= 0 )
- {
- line[0] = '0';
- line[1] = '.';
- line[2] = '0';
- l = 3;
- }
- line[l] = 0;
- return l;
- }
- inline int to_double2( char *line, double fnum, int dsize )
- {
- char f1[20] = "", f2[20] = "";
- bool isnegative = 0;
- if( fnum < 0.0 )
- {
- fnum *= -1.0;
- isnegative = 1;
- }
- int num = (int)fnum;
- int lnum = to_num( f1, num );
- fnum -= (double)num;
- int a, d = 0;
- int rnum = dsize;
- if( lnum == 1 && f1[0] == '0' ) rnum--;
- int i = 0;
- double add = 0.5;
- if( rnum == 0 )
- {
- fnum *= 10.0;
- if( int(fnum) + '0' > '4') f1[lnum - 1]++;
- }
- else
- {
- for( a = 0; a < rnum; a++ ) add /= 10.0;
- fnum += add;
- }
- for( a = 0; a < rnum; a++ )
- {
- fnum *= 10.0;
- d = int(fnum);
- f2[i] = '0'+ d;
- fnum -= (double)d;
- i++;
- }
- int l = 0;
- if( isnegative ) { line[l] = '-'; l++; }
- for( a = 0; a < lnum; a++ ) { line[l] = f1[a]; l++; }
- line[l] = '.'; l++;
- for( a = 0; a < i; a++ ) { line[l] = f2[a]; l++; }
- for( a = l - 1; a >= 0; a-- )
- {
- if( line[a] != '.' && line[a] != '0' ) break;
- line[a] = 0;
- l--;
- }
- if( l <= 0 )
- {
- line[0] = '0';
- line[1] = '.';
- line[2] = '0';
- l = 3;
- }
- line[l] = 0;
- return l;
- }
- #if defined SPwindow
- inline int wchar_to_char( char *line, int ilen, WCHAR *in )
- {
- int a, s = 0;
- line[ilen - 1] = 0;
- for( a = 0; a < ilen - 1; a++)
- {
- if( !in[a] )
- {
- line[a] = 0;
- break;
- }
- line[a] = (char)in[a];
- }
- return a - 1;
- }
- inline int char_to_wchar( WCHAR *line, int ilen, char *in )
- {
- int a, s = 0;
- char * o = (char *)&line;
- o[(ilen - 1) * 2] = 0;
- o[((ilen - 1) * 2) + 1] = 0;
- int b = 0;
- for( a = 0; a < ilen - 1; a++)
- {
- if( !in[a] )
- {
- o[b] = 0;
- o[b+1] = 0;
- break;
- }
- o[b] = in[a];
- o[b+1] = 0;
- b++;
- }
- return a - 1;
- }
- #endif
- inline int format( char *line, int ilen, char *in, ... )
- {
- va_list args;
- int a = 0, b = 0, c = 0, i;
- va_start(args, in);
- int s = size(in);
- int l = 0;
- char temp[64];
- char *cp;
- for( a = 0; a < s; a++ )
- {
- if( l >= ilen - 1 ) { line[l - 1] = 0; va_end(args); return l; }
- if( in[a] == '%' )
- {
- switch( in[a+1] )
- {
- case 'i':
- i = to_num(temp, va_arg(args, int));
- l = add( line, l, ilen, temp, i);
- a++;
- break;
- case 'd':
- i = to_num(temp, va_arg(args, int));
- l = add( line, l, ilen, temp, i);
- a++;
- break;
- case 'l':
- {
- i = to_longlong(temp, va_arg(args, long long));
- l = add( line, l, ilen, temp, i);
- a++;
- break;
- }
- case 'L':
- {
- i = to_long(temp, va_arg(args, long));
- l = add( line, l, ilen, temp, i);
- a++;
- break;
- }
- case '.':
- {
- if( in[a+3] == 'f' )
- {
- if( in[a + 2] >= '0' && in[a + 2] <= '9' )
- {
- int d = in[a + 2] - '0';
- if( d > 6 ) i = to_double2(temp, va_arg(args, double), d);
- else i = to_double(temp, va_arg(args, double), d);
- l = add( line, l, ilen, temp, i);
- a +=3;
- }
- }
- else if( in[a+3] == 'F' )
- {
- if( in[a + 2] >= '0' && in[a + 2] <= '9' )
- {
- int d = in[a + 2] - '0';
- i = to_double2(temp, va_arg(args, double), d);
- l = add( line, l, ilen, temp, i);
- a +=3;
- }
- }
- else
- {
- if( in[a + 2] >= '0' && in[a + 2] <= '9' )
- {
- if( in[a+3] >= '0' && in[a+3] <= '9' )
- {
- if( in[a+4] == 'f' || in[a+4] == 'F' )
- {
- int d = ( (in[a + 2] - '0') * 10 ) + (in[a + 3] - '0' );
- i = to_double2(temp, va_arg(args, double), d);
- l = add( line, l, ilen, temp, i);
- a +=4;
- }
- }
- }
- }
- break;
- }
- case 'f':
- {
- i = to_double(temp, va_arg(args, double));
- l = add( line, l, ilen, temp, i);
- a++;
- break;
- }
- case 'F':
- {
- i = to_double2(temp, va_arg(args, double));
- l = add( line, l, ilen, temp, i);
- a++;
- break;
- }
- case '%':
- {
- line[l] = '%'; l++;
- a++;
- break;
- }
- case 's':
- {
- l = add( line, l, ilen, va_arg(args, char *));
- a++;
- break;
- }
- case 'S':
- {
- int t = l;
- l = add( line, l, ilen, va_arg(args, char *));
- if( islow(line[l - ( l - t )] )) toup(line[l - ( l - t )] );
- a++;
- break;
- }
- case 'w':
- {
- cp = va_arg(args, char *);
- for( b = 0; b < STR_SEARCH_LOOP_SIZE; b += 2 )
- {
- if( l >= ilen - 1 ) break;
- if( cp[b] == 0 ) break;
- line[l] = cp[b];
- l++;
- }
- line[l] = 0;
- a++;
- break;
- }
- case 'c':
- {
- char o = va_arg(args, char);
- line[l] = o;
- l++;
- a++;
- break;
- }
- case 'C':
- {
- char o = va_arg(args, char);
- line[l] = o;
- if( islow(line[l] )) toup(line[l] );
- l++;
- a++;
- break;
- }
- case 'p':
- {
- void *p = va_arg(args, void *);
- long long v = (long long)p;
- i = to_longlong(temp, v);
- l = add( line, l, ilen, temp, i);
- a++;
- break;
- }
- case 'n':
- {
- i = va_arg(args, int);
- a++;
- break;
- }
- case 'x':
- {
- char *p = va_arg(args, char *);
- l = add( line, l, ilen, "{", 1 );
- for( b = 0; b < 3; b++ )
- {
- i = to_num(temp, (unsigned char)p[b]);
- l = add( line, l, ilen, temp, i);
- l = add( line, l, ilen, "|", 1 );
- }
- i = to_num(temp, (unsigned char)p[b]);
- l = add( line, l, ilen, temp, i);
- l = add( line, l, ilen, "}", 1 );
- a++;
- break;
- }
- case 'b':
- {
- char *p = va_arg(args, char *);
- l = add( line, l, ilen, "{", 1 );
- for( b = 0; b < 4*8; b++ )
- {
- if( p[b/8] & ( 1 << (b % 8) ) ) temp[b] = '1';
- else temp[b] = '0';
- }
- l = add( line, l, ilen, temp, b);
- l = add( line, l, ilen, "}", 1 );
- a++;
- break;
- }
- default:
- {
- int y = 0, m = ( (ilen - 1 ) - l ); char j[10];
- if( m > 8 ) m = 8;
- for( y = 1; y < m; y++ )
- {
- if( in[a + y] >= '0' && in[ a + y ] <= '9' )
- {
- j[y - 1] = in[a + y];
- }
- else
- {
- if( y == 1 ) break;
- else
- {
- j[y - 1] = 0;
- i = get_num( j, y - 1);
- switch( in[y + a] )
- {
- case 'n':
- {
- struct ad1{ char a1; };
- struct ad2{ char a1; char a2; };
- struct ad4{ ad2 a1; ad2 a2; };
- struct ad8{ ad4 a1; ad4 a2; };
- struct ad16{ ad8 a1; ad8 a2; };
- struct ad32{ ad16 a1; ad16 a2; };
- struct ad64{ ad32 a1; ad32 a2; };
- struct ad128{ ad64 a1; ad64 a2; };
- switch(i)
- {
- case 1: va_arg(args, ad1); break;
- case 2: va_arg(args, ad2); break;
- case 4: va_arg(args, ad4); break;
- case 8: va_arg(args, ad8); break;
- case 16: va_arg(args, ad16); break;
- case 32: va_arg(args, ad32); break;
- case 64: va_arg(args, ad64); break;
- case 128: va_arg(args, ad128); break;
- }
- a += y;
- break;
- }
- case 's':
- {
- char *p = va_arg(args, char *);
- int cs = size(p);
- if( i > cs - 1 ) i = cs - 1;
- l = add( line, l, ilen, p, i);
- line[l] = 0;
- a += y;
- break;
- }
- case 'S':
- {
- int t = l;
- char *p = va_arg(args, char *);
- int cs = size(p);
- if( i > cs - 1 ) i = cs - 1;
- l = add( line, l, ilen, p, i);
- line[l] = 0;
- if( islow(line[l - ( l - t )] )) toup(line[l - ( l - t )] );
- a += y;
- break;
- }
- case 'x':
- {
- char *p = va_arg(args, char *);
- l = add( line, l, ilen, "{", 1 );
- for( b = 0; b < i - 1; b++ )
- {
- c = to_num(temp, (unsigned char)p[b]);
- l = add( line, l, ilen, temp, c);
- l = add( line, l, ilen, "|", 1 );
- }
- c = to_num(temp, (unsigned char)p[b]);
- l = add( line, l, ilen, temp, c);
- l = add( line, l, ilen, "}", 1 );
- a += y;
- break;
- }
- case 'b':
- {
- char *p = va_arg(args, char *);
- l = add( line, l, ilen, "{", 1 );
- for( b = 0; b < i*8; b++ )
- {
- if( p[b/8] & ( 1 << (b % 8) ) ) temp[b] = '1';
- else temp[b] = '0';
- }
- l = add( line, l, ilen, temp, b);
- l = add( line, l, ilen, "}", 1 );
- a += y;
- break;
- }
- }
- break;
- }
- }
- }
- }
- }
- }
- else { line[l] = in[a]; l++; line[l] = 0; }
- }
- line[l] = 0;
- va_end(args);
- return l;
- }
- inline int format( va_list args, char *line, int ilen, char *in )
- {
- int a = 0, b = 0, c = 0, i;
- int s = size(in);
- int l = 0;
- char temp[64];
- char *cp;
- for( a = 0; a < s; a++ )
- {
- if( l >= ilen - 1 ) { line[l - 1] = 0; va_end(args); return l; }
- if( in[a] == '%' )
- {
- switch( in[a+1] )
- {
- case 'i':
- i = to_num(temp, va_arg(args, int));
- l = add( line, l, ilen, temp, i);
- a++;
- break;
- case 'd':
- i = to_num(temp, va_arg(args, int));
- l = add( line, l, ilen, temp, i);
- a++;
- break;
- case 'l':
- {
- i = to_longlong(temp, va_arg(args, long long));
- l = add( line, l, ilen, temp, i);
- a++;
- break;
- }
- case 'L':
- {
- i = to_long(temp, va_arg(args, long));
- l = add( line, l, ilen, temp, i);
- a++;
- break;
- }
- case '.':
- {
- if( in[a+3] == 'f' )
- {
- if( in[a + 2] >= '0' && in[a + 2] <= '9' )
- {
- int d = in[a + 2] - '0';
- if( d > 6 ) i = to_double2(temp, va_arg(args, double), d);
- else i = to_double(temp, va_arg(args, double), d);
- l = add( line, l, ilen, temp, i);
- a +=3;
- }
- }
- else if( in[a+3] == 'F' )
- {
- if( in[a + 2] >= '0' && in[a + 2] <= '9' )
- {
- int d = in[a + 2] - '0';
- i = to_double2(temp, va_arg(args, double), d);
- l = add( line, l, ilen, temp, i);
- a +=3;
- }
- }
- else
- {
- if( in[a + 2] >= '0' && in[a + 2] <= '9' )
- {
- if( in[a+3] >= '0' && in[a+3] <= '9' )
- {
- if( in[a+4] == 'f' || in[a+4] == 'F' )
- {
- int d = ( (in[a + 2] - '0') * 10 ) + (in[a + 3] - '0' );
- i = to_double2(temp, va_arg(args, double), d);
- l = add( line, l, ilen, temp, i);
- a +=4;
- }
- }
- }
- }
- break;
- }
- case 'f':
- {
- i = to_double(temp, va_arg(args, double));
- l = add( line, l, ilen, temp, i);
- a++;
- break;
- }
- case 'F':
- {
- i = to_double2(temp, va_arg(args, double));
- l = add( line, l, ilen, temp, i);
- a++;
- break;
- }
- case '%':
- {
- line[l] = '%'; l++;
- a++;
- break;
- }
- case 's':
- {
- l = add( line, l, ilen, va_arg(args, char *));
- a++;
- break;
- }
- case 'S':
- {
- int t = l;
- l = add( line, l, ilen, va_arg(args, char *));
- if( islow(line[l - ( l - t )] )) toup(line[l - ( l - t )] );
- a++;
- break;
- }
- case 'w':
- {
- cp = va_arg(args, char *);
- for( b = 0; b < STR_SEARCH_LOOP_SIZE; b += 2 )
- {
- if( l >= ilen - 1 ) break;
- if( cp[b] == 0 ) break;
- line[l] = cp[b];
- l++;
- }
- line[l] = 0;
- a++;
- break;
- }
- case 'c':
- {
- char o = va_arg(args, char);
- line[l] = o;
- l++;
- a++;
- break;
- }
- case 'C':
- {
- char o = va_arg(args, char);
- line[l] = o;
- if( islow(line[l] )) toup(line[l] );
- l++;
- a++;
- break;
- }
- case 'p':
- {
- void *p = va_arg(args, void *);
- long long v = (long long)p;
- i = to_longlong(temp, v);
- l = add( line, l, ilen, temp, i);
- a++;
- break;
- }
- case 'n':
- {
- i = va_arg(args, int);
- a++;
- break;
- }
- case 'x':
- {
- char *p = va_arg(args, char *);
- l = add( line, l, ilen, "{", 1 );
- for( b = 0; b < 3; b++ )
- {
- i = to_num(temp, (unsigned char)p[b]);
- l = add( line, l, ilen, temp, i);
- l = add( line, l, ilen, "|", 1 );
- }
- i = to_num(temp, (unsigned char)p[b]);
- l = add( line, l, ilen, temp, i);
- l = add( line, l, ilen, "}", 1 );
- a++;
- break;
- }
- case 'b':
- {
- char *p = va_arg(args, char *);
- l = add( line, l, ilen, "{", 1 );
- for( b = 0; b < 4*8; b++ )
- {
- if( p[b/8] & ( 1 << (b % 8) ) ) temp[b] = '1';
- else temp[b] = '0';
- }
- l = add( line, l, ilen, temp, b);
- l = add( line, l, ilen, "}", 1 );
- a++;
- break;
- }
- default:
- {
- int y = 0, m = ( (ilen - 1 ) - l ); char j[10];
- if( m > 8 ) m = 8;
- for( y = 1; y < m; y++ )
- {
- if( in[a + y] >= '0' && in[ a + y ] <= '9' )
- {
- j[y - 1] = in[a + y];
- }
- else
- {
- if( y == 1 ) break;
- else
- {
- j[y - 1] = 0;
- i = get_num( j, y - 1);
- switch( in[y + a] )
- {
- case 'n':
- {
- struct ad1{ char a1; };
- struct ad2{ char a1; char a2; };
- struct ad4{ ad2 a1; ad2 a2; };
- struct ad8{ ad4 a1; ad4 a2; };
- struct ad16{ ad8 a1; ad8 a2; };
- struct ad32{ ad16 a1; ad16 a2; };
- struct ad64{ ad32 a1; ad32 a2; };
- struct ad128{ ad64 a1; ad64 a2; };
- switch(i)
- {
- case 1: va_arg(args, ad1); break;
- case 2: va_arg(args, ad2); break;
- case 4: va_arg(args, ad4); break;
- case 8: va_arg(args, ad8); break;
- case 16: va_arg(args, ad16); break;
- case 32: va_arg(args, ad32); break;
- case 64: va_arg(args, ad64); break;
- case 128: va_arg(args, ad128); break;
- }
- a += y;
- break;
- }
- case 's':
- {
- char *p = va_arg(args, char *);
- int cs = size(p);
- if( i > cs - 1 ) i = cs - 1;
- l = add( line, l, ilen, p, i);
- line[l] = 0;
- a += y;
- break;
- }
- case 'S':
- {
- int t = l;
- char *p = va_arg(args, char *);
- int cs = size(p);
- if( i > cs - 1 ) i = cs - 1;
- l = add( line, l, ilen, p, i);
- line[l] = 0;
- if( islow(line[l - ( l - t )] )) toup(line[l - ( l - t )] );
- a += y;
- break;
- }
- case 'x':
- {
- char *p = va_arg(args, char *);
- l = add( line, l, ilen, "{", 1 );
- for( b = 0; b < i - 1; b++ )
- {
- c = to_num(temp, (unsigned char)p[b]);
- l = add( line, l, ilen, temp, c);
- l = add( line, l, ilen, "|", 1 );
- }
- c = to_num(temp, (unsigned char)p[b]);
- l = add( line, l, ilen, temp, c);
- l = add( line, l, ilen, "}", 1 );
- a += y;
- break;
- }
- case 'b':
- {
- char *p = va_arg(args, char *);
- l = add( line, l, ilen, "{", 1 );
- for( b = 0; b < i*8; b++ )
- {
- if( p[b/8] & ( 1 << (b % 8) ) ) temp[b] = '1';
- else temp[b] = '0';
- }
- l = add( line, l, ilen, temp, b);
- l = add( line, l, ilen, "}", 1 );
- a += y;
- break;
- }
- }
- break;
- }
- }
- }
- }
- }
- }
- else { line[l] = in[a]; l++; line[l] = 0; }
- }
- line[l] = 0;
- va_end(args);
- return l;
- }
- inline unsigned char *encrypt( unsigned char *line, unsigned int size, char *password, int *outsize )
- {
- unsigned int a = 0;
- int b = 0, c = 0;
- int s = 0;
- unsigned char *p = new unsigned char[size+8];
- *outsize = size+8;
- for( a = 6; a < size + 6; a++ ) p[a] = line[a-6];
- unsigned char *n = (unsigned char *)&size;
- size += 4;
- p[0] = n[0]; p[1] = n[1]; p[2] = n[2]; p[3] = n[3];
- p[4] = 'S'; p[5] = 'P';
- p[size+2] = 'P'; p[size+3] = 'S';
- for( a = 0; a < 1024; a++ ) { if( !password[a] ) break; s++; }
- for( a = 0; a < size; a++ )
- {
- if( b >= s )
- {
- if( c >= s ) c = 0;
- b = 0;
- c++;
- }
- p[a+4] += password[c] + password[b];
- b++;
- }
- int pos = 0; unsigned char t = 0; b = 0;
- int newpos = 0;
- for( a = 0; a < size; a++ )
- {
- if( b >= s ) b = 0;
- pos += password[b];
- b++;
- newpos = pos % size;
- t = p[newpos+4];
- p[newpos+4] = p[a+4];
- p[a+4] = t;
- }
- return p;
- }
- inline bool decrypt( unsigned char *line, char *password, unsigned char **out, int *outsize )
- {
- int size = (line[3] << 24) | (line[2] << 16) | (line[1] << 8) | (line[0]);
- if( size < 0 || size > 16777216 )
- {
- *outsize = 0;
- return 0;
- }
- unsigned int a = 0;
- int b = 0, c = 0;
- int s = 0;
- for( a = 0; a < 1024; a++ ) { if( !password[a] ) break; s++; }
- unsigned char *p = new unsigned char[size];
- for( a = 0; a < size; a++ ) p[a] = line[a + 4];
- int pos = 0; unsigned char t = 0; b = 0;
- int newpos = 0;
- for( a = 0; a < size; a++ )
- {
- if( b >= s ) b = 0;
- pos += password[b];
- b++;
- }
- b--;
- if( b == -1 ) b = s - 1;
- int a2;
- for( a2 = size-1; a2 >= 0; a2-- )
- {
- if( b == -1 ) b = s - 1;
- newpos = pos % size;
- t = p[newpos];
- p[newpos] = p[a2];
- p[a2] = t;
- pos -= password[b];
- b--;
- }
- b = 0, c = 0;
- for( a = 0; a < size; a++ )
- {
- if( b >= s )
- {
- if( c >= s ) c = 0;
- b = 0;
- c++;
- }
- p[a] -= password[b] + password[c];
- b++;
- }
- if( p[0] != 'S' || p[1] != 'P' || p[size - 2] != 'P' || p[size - 1] != 'S' ) return 0;
- *outsize = size - 4;
- unsigned char *u = new unsigned char[size-4];
- for( a = 2; a < size - 2; a++ ) u[a-2] = p[a];
- delete [] p;
- *out = u;
- return 1;
- }
- };
- #define vformat(line, ilen, in) { va_list args; va_start(args, in); str::format(args, line, ilen, in); }
- class spchar
- {
- public:
- char *data;
- int size;
- int reserved;
- int reserv_step;
- int fpos;
- bool isbinary;
- spchar(bool binary)
- {
- size = 0;
- reserved = 0;
- reserv_step = 0;
- fpos = 0;
- isbinary = binary;
- }
- void free_reserved()
- {
- char *p;
- if( !reserved ) return;
- if( !size )
- {
- delete [] data;
- reserved = 0;
- return;
- }
- if( isbinary ) p = new char[size];
- else { p = new char[size+1]; p[size] = 0; }
- for( int a = 0; a < size; a++ ) p[a] = data[a];
- delete [] data; data = p;
- reserved = 0;
- }
- bool same( spchar in )
- {
- if( size != in.size ) return 0;
- for( int a = 0; a < size; a++ ) { if( in.data[a] != data[a] ) return 0; }
- return 1;
- }
- void makeroom(int howmuch)
- {
- int newsize = howmuch+size+reserved+reserv_step;
- int a;
- char *p;
- if( size+reserved == howmuch+size+reserved+reserv_step) return;
- if(!isbinary)
- {
- p = new char[newsize + 1];
- p[newsize] = 0;
- }
- else p = new char[newsize];
- for( a = 0; a < size; a++ ) p[a] = data[a];
- if( size || reserved ) delete[] data;
- reserved += howmuch+reserv_step;
- data = p;
- }
- spchar(bool binary, int isize)
- {
- size = 0;
- reserved = 0;
- reserv_step = 1;
- fpos = 0;
- isbinary = binary;
- makeroom(isize);
- }
- int add( char *in )
- {
- int s = str::size(in);
- if( s >= reserved ) makeroom(s);
- for( int a = size; a < size+s; a++ ) data[a] = in[a - size];
- if( !isbinary ) { data[size+s] = 0; reserved -= s; }
- else reserved -= s;
- size += s;
- return size;
- }
- spchar(bool binary, char *in)
- {
- size = 0;
- reserved = size;
- reserv_step = 1;
- fpos = 0;
- isbinary = binary;
- add(in);
- }
- int add( char *in, int isize )
- {
- if( isize >= reserved ) makeroom(isize);
- for( int a = size; a < size+isize; a++ ) data[a] = in[a - size];
- if( !isbinary ) { data[size+isize] = 0; reserved -= isize; }
- else reserved -= isize;
- size += isize;
- return size;
- }
- spchar(bool binary, char *in, int size)
- {
- size = 0;
- reserved = size;
- reserv_step = 1;
- fpos = 0;
- isbinary = binary;
- add(in, size);
- }
- int add( int pos, char *in )
- {
- int s = str::size(in);
- int addsize = 0, empty = 0, a;
- addsize -= reserved;
- addsize += s;
- if( pos >= size ) empty = pos - size;
- addsize += empty;
- if( addsize > 0 ) makeroom( addsize );
- for( a = size; a >= pos; a-- ) data[a+s] = data[a];
- for( a = pos; a < pos + s; a++ ) data[a] = in[a - pos];
- if( empty ) for( a = size; a < pos; a++ ) data[a] = 0;
- size += s + empty;
- if( isbinary ) reserved -= s + empty;
- else
- {
- reserved -= s + empty;
- data[size] = 0;
- }
- return size;
- }
- int add( int pos, char *in, int isize )
- {
- int addsize = 0, empty = 0, a;
- addsize -= reserved;
- addsize += isize;
- if( pos >= size ) empty = pos - size;
- addsize += empty;
- if( addsize > 0 ) makeroom( addsize );
- for( a = size; a >= pos; a-- ) data[a+isize] = data[a];
- for( a = pos; a < pos + isize; a++ ) data[a] = in[a - pos];
- if( empty ) for( a = size; a < pos; a++ ) data[a] = 0;
- size += isize + empty;
- if( isbinary ) reserved -= isize + empty;
- else
- {
- reserved -= isize + empty;
- data[size] = 0;
- }
- return size;
- }
- ~spchar() { if( size || reserved ) delete [] data; }
- void set( char *in )
- {
- if( size || reserved ) { delete [] data; }
- size = 0;
- reserved = 0;
- int s = str::size(in);
- if( isbinary ) { makeroom(s); reserved -= s; }
- else { makeroom(s); reserved -= s; data[s] = 0; }
- for( int a = 0; a < s; a++ ) data[a] = in[a];
- size = s;
- }
- void set( char *in, int isize )
- {
- if( size || reserved ) { delete [] data; }
- size = 0;
- reserved = 0;
- if( isbinary ) { makeroom(isize); reserved -= isize; }
- else { makeroom(isize); reserved -= isize; data[isize] = 0; }
- for( int a = 0; a < isize; a++ ) data[a] = in[a];
- size = isize;
- }
- int remove( int start, int end )
- {
- int r = (end - start) + 1;
- if( r <= 0 || start >= size || end > size) return size;
- reserved += r;
- for( int a = start; a <= size - r; a++ ) data[a] = data[a+r];
- size -= r;
- return size;
- }
- int find( char *what )
- {
- int a, s = str::size(what), c = 0;
- for( a = 0; a < size; a++ )
- {
- if( c >= s ) return a - s;
- if( data[a] == what[c] )
- {
- c++;
- continue;
- }
- if( c ) a--;
- c = 0;
- }
- if( c == s ) return a - s;
- return -1;
- }
- int find( int pos, char *what )
- {
- if( pos >= size ) return -1;
- int a, s = str::size(what), c = 0;
- for( a = pos; a < size; a++ )
- {
- if( c >= s ) return a - s;
- if( data[a] == what[c] )
- {
- c++;
- continue;
- }
- if( c ) a--;
- c = 0;
- }
- if( c == s ) return a - s;
- return -1;
- }
- int find( char *what, int isize )
- {
- int a, c = 0;
- for( a = 0; a < size; a++ )
- {
- if( c >= isize ) return a - isize;
- if( data[a] == what[c] )
- {
- c++;
- continue;
- }
- if( c ) a--;
- c = 0;
- }
- if( c == isize ) return a - isize;
- return -1;
- }
- int find( int pos, char *what, int isize )
- {
- if( pos >= size ) return -1;
- int a, c = 0;
- for( a = pos; a < size; a++ )
- {
- if( c >= isize ) return a - isize;
- if( data[a] == what[c] )
- {
- c++;
- continue;
- }
- if( c ) a--;
- c = 0;
- }
- if( c == isize ) return a - isize;
- return -1;
- }
- int find2( char *what )
- {
- int a, s = str::size(what), c = 0;
- char low[2];
- for( a = 0; a < size; a++ )
- {
- if( c >= s ) return a - s;
- low[0] = data[a];
- low[1] = what[c];
- if( isup(low[0]) ) tolow(low[0]);
- if( isup(low[1]) ) tolow(low[1]);
- if( low[0] == low[1] )
- {
- c++;
- continue;
- }
- if( c ) a--;
- c = 0;
- }
- if( c == s ) return a - s;
- return -1;
- }
- int find2( int pos, char *what )
- {
- if( pos >= size ) return -1;
- int a, s = str::size(what), c = 0;
- char low[2];
- for( a = pos; a < size; a++ )
- {
- if( c >= s ) return a - s;
- low[0] = data[a];
- low[1] = what[c];
- if( isup(low[0]) ) tolow(low[0]);
- if( isup(low[1]) ) tolow(low[1]);
- if( low[0] == low[1] )
- {
- c++;
- continue;
- }
- if( c ) a--;
- c = 0;
- }
- if( c == s ) return a - s;
- return -1;
- }
- int find2( char *what, int isize )
- {
- int a, c = 0;
- char low[2];
- for( a = 0; a < size; a++ )
- {
- if( c >= isize ) return a - isize;
- low[0] = data[a];
- low[1] = what[c];
- if( isup(low[0]) ) tolow(low[0]);
- if( isup(low[1]) ) tolow(low[1]);
- if( low[0] == low[1] )
- {
- c++;
- continue;
- }
- if( c ) a--;
- c = 0;
- }
- if( c == isize ) return a - isize;
- return -1;
- }
- int find2( int pos, char *what, int isize )
- {
- if( pos >= size ) return -1;
- char low[2];
- int a, c = 0;
- for( a = pos; a < size; a++ )
- {
- if( c >= isize ) return a - isize;
- low[0] = data[a];
- low[1] = what[c];
- if( isup(low[0]) ) tolow(low[0]);
- if( isup(low[1]) ) tolow(low[1]);
- if( low[0] == low[1] )
- {
- c++;
- continue;
- }
- if( c ) a--;
- c = 0;
- }
- if( c == isize ) return a - isize;
- return -1;
- }
- int write( void *in, int insize, int count )
- {
- if( !isbinary ) return size;
- int adsize = insize * count;
- if( reserved - adsize <= 0 ) makeroom(adsize);
- for( int a = size; a < size+adsize; a++ ) data[a] = ((char *)in)[a - size];
- size += adsize;
- reserved -= adsize;
- return size;
- }
- int write( int pos, void *in, int insize, int count )
- {
- if( !isbinary ) return size;
- int adsize = insize * count;
- if( reserved - adsize <= 0 ) makeroom(adsize);
- int a;
- for(a = size; a >= pos; a-- ) data[a + adsize - 1] = data[a];
- for(a = pos; a < pos+adsize; a++ ) data[a] = ((char *)in)[a - pos];
- size += adsize;
- reserved -= adsize;
- return size;
- }
- int read( void *out, int outsize, int count )
- {
- if( fpos >= size ) return -1;
- int s = outsize*count;
- for( int a = fpos; a < s; a++ ) ((char *)out)[a - fpos] = data[a];
- fpos += s;
- return fpos;
- }
- bool replace( char *what, char *with )
- {
- if( !size ) return 0;
- int s1 = str::size(what);
- int i = find( what, s1 );
- if( i == -1 ) return 0;
- int s2 = str::size(with);
- remove(i, i + s1 - 1);
- add(i, with, s2);
- return 1;
- }
- bool replace( char *what, int iwhat, char *with, int iwith )
- {
- if( !size ) return 0;
- int i = find( what, iwhat );
- if( i == -1 ) return 0;
- remove(i, i + iwhat - 1);
- add(i, with, iwith);
- return 1;
- }
- void trim()
- {
- free_reserved();
- }
- void trim( char what )
- {
- int r1e = 0, a;
- for( a = 0; a < size; a++ )
- {
- if( data[a] != what ) break;
- r1e++;
- }
- if( r1e > 0 ) remove( 0, r1e - 1 );
- if( !size ) return;
- int r2s = size;
- for( a = size - 1; a >= 0; a-- )
- {
- if( data[a] != what ) break;
- r2s--;
- }
- if( r2s == size ) return;
- remove( r2s, size - 1);
- }
- bool same( char *in)
- {
- int s = str::size(in);
- if( s != size ) return 0;
- for( int a = 0; a < size; a++ ) if( data[a] != in[a] ) return 0;
- return 1;
- }
- bool same( char *in, int isize)
- {
- if( isize != size ) return 0;
- for( int a = 0; a < size; a++ ) if( data[a] != in[a] ) return 0;
- return 1;
- }
- bool same2( char *in )
- {
- char low[2];
- int s = str::size(in);
- if( s != size ) return 0;
- for( int a = 0; a < s; a++ )
- {
- low[0] = data[a];
- low[1] = in[a];
- if( isup(low[0]) ) tolow(low[0]);
- if( isup(low[1]) ) tolow(low[1]);
- if( low[0] != low[1] ) return 0;
- }
- return 1;
- }
- bool same2( char *in, int isize )
- {
- char low[2];
- if( isize != size ) return 0;
- for( int a = 0; a < size; a++ )
- {
- low[0] = data[a];
- low[1] = in[a];
- if( isup(low[0]) ) tolow(low[0]);
- if( isup(low[1]) ) tolow(low[1]);
- if( low[0] != low[1] ) return 0;
- }
- return 1;
- }
- bool breakstr( char *out, int outsize, char *token )
- {
- if( !size ) { out[0] = 0; return 0; }
- int a;
- int tsize = str::size(token);
- int tpos = find(0, token, tsize);
- int wsize = 0;
- if( tpos == -1 )
- {
- if( size >= outsize ) { wsize = outsize; out[outsize - 1] = 0; }
- else { wsize = size; out[wsize] = 0; }
- for( a = 0; a < wsize; a++ ) out[a] = data[a];
- remove( 0, size - 1 );
- return 0;
- }
- if( tpos >= outsize ) { wsize = outsize; out[outsize - 1] = 0; }
- else { wsize = tpos; out[wsize] = 0; }
- for( a = 0; a < wsize; a++ ) out[a] = data[a];
- remove( 0, tpos + (tsize - 1) );
- return 1;
- }
- bool breakstr( int from, char *out, int outlen )
- {
- if( !size || size >= from ) { out[0] = 0; return 0; }
- int a, s = size;
- if( s - from >= outlen - 1 ) s += ((outlen - 1) - (s - from));
- for( a = from; a < s; a++ ) { out[a - from] = data[a]; }
- data[from] = 0;
- size = from;
- out[s - from] = 0;
- }
- void updatesize()
- {
- if( isbinary ) return;
- size = 0;
- for( int a = 0; a < STR_SEARCH_LOOP_SIZE; a++ ) { size++; if( !data[a] ) break; }
- }
- void to_low()
- {
- int a;
- for( a = 0; a < size; a++ ) if( isup(data[a]) ) tolow(data[a]);
- }
- void to_up()
- {
- int a;
- for( a = 0; a < size; a++ ) if( islow(data[a]) ) toup(data[a]);
- }
- int get_num()
- {
- int res = 0, sign = 1, i = 0;
- if (data[0] == '-') { sign = -1; i++; }
- for(; i < size; ++i )
- {
- if( !isnum(data[i]) ) break;
- res = res*10 + data[i] - '0';
- }
- return sign*res;
- }
- float get_float()
- {
- float res = 0.0, sign = 1.0; int i = 0;
- if (data[0] == '-') { sign = -1.0; i++; }
- for(; i < size; ++i )
- {
- if( !isnum(data[i]) ) break;
- res = res*10.0f + float(data[i] - '0');
- }
- if( data[i] == '.' )
- {
- i++;
- float lres = 0.1f;
- for(; i < size; ++i )
- {
- if( !isnum(data[i]) ) break;
- res += lres * float(data[i] - '0');
- lres /= 10.0f;
- }
- }
- return sign*res;
- }
- double get_double()
- {
- double res = 0.0, sign = 1.0; int i = 0;
- if (data[0] == '-') { sign = -1.0; i++; }
- for(; i < size; ++i )
- {
- if( !isnum(data[i]) ) break;
- res = res*10.0 + double(data[i] - '0');
- }
- if( data[i] == '.' )
- {
- i++;
- double lres = 0.1;
- for(; i < size; ++i )
- {
- if( !isnum(data[i]) ) break;
- res += lres * double(data[i] - '0');
- lres /= 10.0;
- }
- }
- return sign*res;
- }
- int ref()
- {
- int r = 0;
- for( int a = size; a < size; a++ ) r += data[a];
- return r;
- }
- void reverse()
- {
- char t = 0;
- for( int a = 0; a < size / 2; a++ )
- {
- t = data[a];
- data[a] = data[(size - 1) - a];
- data[(size - 1) - a] = t;
- }
- }
- void to_num( int in )
- {
- char temp[64]; int s;
- s = str::to_num(temp, in);
- set(temp, s);
- }
- void to_num( int in, int base )
- {
- char temp[64]; int s;
- s = str::to_num(temp, in, base);
- set(temp, s);
- }
- void to_long( long in )
- {
- char temp[64]; int s;
- s = str::to_long(temp, in);
- set(temp, s);
- }
- void to_longlong( long long in )
- {
- char temp[64]; int s;
- s = str::to_longlong(temp, in);
- set(temp, s);
- }
- void to_float( float in )
- {
- char temp[64]; int s;
- s = str::to_float(temp, in);
- set(temp, s);
- }
- void to_float( float in, int p )
- {
- char temp[64]; int s;
- s = str::to_float(temp, in, p);
- set(temp, s);
- }
- void to_double( double in )
- {
- char temp[64]; int s;
- s = str::to_double(temp, in);
- set(temp, s);
- }
- void to_double( double in, int p )
- {
- char temp[64]; int s;
- s = str::to_double(temp, in, p);
- set(temp, s);
- }
- void to_double2( double in, int p )
- {
- char temp[64]; int s;
- s = str::to_double2(temp, in, p);
- set(temp, s);
- }
- #if defined SPwindow
- void to_wchar( WCHAR *out, int ilen )
- {
- str::char_to_wchar(out, ilen, data);
- }
- #endif
- int format( char *in, ... )
- {
- va_list args;
- int a = 0, b = 0, c = 0, i, s = str::size(in);
- va_start(args, in);
- char temp[64];
- char *cp;
- #if defined SPwindow
- WCHAR *wc;
- #endif
- for( a = 0; a < s; a++ )
- {
- cout << "l:" << in[a] << endl;
- if( in[a] == '%' )
- {
- switch( in[a+1] )
- {
- case 'i':
- i = str::to_num(temp, va_arg(args, int));
- add( temp, i);
- a++;
- break;
- case 'd':
- i = str::to_num(temp, va_arg(args, int));
- add( temp, i);
- a++;
- break;
- case 'l':
- {
- i = str::to_longlong(temp, va_arg(args, long long));
- add( temp, i);
- a++;
- break;
- }
- case 'L':
- {
- i = str::to_long(temp, va_arg(args, long));
- add( temp, i);
- a++;
- break;
- }
- case 'f':
- {
- i = str::to_double(temp, va_arg(args, double));
- add( temp, i);
- a++;
- break;
- }
- case 'F':
- {
- i = str::to_double2(temp, va_arg(args, double));
- add( temp, i);
- a++;
- break;
- }
- case '.':
- {
- if( in[a+3] == 'f' )
- {
- if( in[a + 2] >= '0' && in[a + 2] <= '9' )
- {
- int d = in[a + 2] - '0';
- if( d > 6 ) i = str::to_double2(temp, va_arg(args, double), d);
- else i = str::to_double(temp, va_arg(args, double), d);
- add( temp, i);
- a +=3;
- }
- }
- else if( in[a+3] == 'F' )
- {
- if( in[a + 2] >= '0' && in[a + 2] <= '9' )
- {
- int d = in[a + 2] - '0';
- i = str::to_double2(temp, va_arg(args, double), d);
- add( temp, i);
- a +=3;
- }
- }
- else
- {
- if( in[a + 2] >= '0' && in[a + 2] <= '9' )
- {
- if( in[a+3] >= '0' && in[a+3] <= '9' )
- {
- if( in[a+4] == 'f' || in[a+4] == 'F' )
- {
- int d = ( (in[a + 2] - '0') * 10 ) + (in[a + 3] - '0' );
- i = str::to_double2(temp, va_arg(args, double), d);
- add( temp, i);
- a +=4;
- }
- }
- }
- }
- break;
- }
- case '%':
- {
- add("%", 1);
- a++;
- break;
- }
- case 's':
- {
- cp = va_arg(args, char *);
- add( cp);
- a++;
- break;
- }
- case 'S':
- {
- cp = va_arg(args, char *);
- if( islow(cp[0] )) toup(cp[0] );
- add(cp);
- a++;
- break;
- }
- #if defined SPwindow
- case 'w':
- {
- wc = va_arg(args, WCHAR *);
- (*this)+=wc;
- a++;
- break;
- }
- #endif
- case 'c':
- {
- char o = va_arg(args, char);
- add(&o, 1);
- a++;
- break;
- }
- case 'C':
- {
- char o = va_arg(args, char);
- if( islow(o )) toup(o );
- add(&o, 1);
- a++;
- break;
- }
- case 'p':
- {
- void *p = va_arg(args, void *);
- long long v = (long long)p;
- i = str::to_longlong(temp, v);
- add( temp, i);
- a++;
- break;
- }
- case 'n':
- {
- i = va_arg(args, int);
- a++;
- break;
- }
- case 'x':
- {
- char *p = va_arg(args, char *);
- add( "{", 1);
- for( b = 0; b < 3; b++ )
- {
- i = str::to_num(temp, (unsigned char)p[b]);
- add( temp, i);
- add( "|", 1 );
- }
- i = str::to_num(temp, (unsigned char)p[b]);
- add( temp, i);
- add( "}", 1 );
- a++;
- break;
- }
- case 'b':
- {
- char *p = va_arg(args, char *);
- add( "{", 1);
- for( b = 0; b < 4*8; b++ )
- {
- if( p[b/8] & ( 1 << (b % 8) ) ) temp[b] = '1';
- else temp[b] = '0';
- }
- add( temp, i);
- add( "}", 1);
- a++;
- break;
- }
- default:
- {
- int y = 0; char j[10];
- for( y = 1; y < 8; y++ )
- {
- if( in[a + y] >= '0' && in[ a + y ] <= '9' )
- {
- j[y - 1] = in[a + y];
- }
- else
- {
- if( y == 1 ) break;
- else
- {
- j[y - 1] = 0;
- i = str::get_num( j, y - 1);
- switch( in[y + a] )
- {
- case 'n':
- {
- struct ad1{ char a1; };
- struct ad2{ char a1; char a2; };
- struct ad4{ ad2 a1; ad2 a2; };
- struct ad8{ ad4 a1; ad4 a2; };
- struct ad16{ ad8 a1; ad8 a2; };
- struct ad32{ ad16 a1; ad16 a2; };
- struct ad64{ ad32 a1; ad32 a2; };
- struct ad128{ ad64 a1; ad64 a2; };
- switch(i)
- {
- case 1: va_arg(args, ad1); break;
- case 2: va_arg(args, ad2); break;
- case 4: va_arg(args, ad4); break;
- case 8: va_arg(args, ad8); break;
- case 16: va_arg(args, ad16); break;
- case 32: va_arg(args, ad32); break;
- case 64: va_arg(args, ad64); break;
- case 128: va_arg(args, ad128); break;
- }
- a += y;
- break;
- }
- case 's':
- {
- char *p = va_arg(args, char *);
- int cs = str::size(p);
- if( i > cs - 1 ) i = cs - 1;
- add(p, i);
- a += y;
- break;
- }
- case 'S':
- {
- char *p = va_arg(args, char *);
- if( islow(p[0] )) toup(p[0] );
- int cs = str::size(p);
- if( i > cs - 1 ) i = cs - 1;
- add(p, i);
- a += y;
- break;
- }
- case 'x':
- {
- char *p = va_arg(args, char *);
- add( "{", 1 );
- for( b = 0; b < i - 1; b++ )
- {
- c = str::to_num(temp, (unsigned char)p[b]);
- add( temp, c );
- add( "|", 1 );
- }
- c = str::to_num(temp, (unsigned char)p[b]);
- add( temp, c );
- add( "}", 1 );
- a += y;
- break;
- }
- case 'b':
- {
- char *p = va_arg(args, char *);
- add( "}", 1 );
- for( b = 0; b < i*8; b++ )
- {
- if( p[b/8] & ( 1 << (b % 8) ) ) temp[b] = '1';
- else temp[b] = '0';
- }
- add( temp, b );
- add( "}", 1 );
- a += y;
- break;
- }
- }
- break;
- }
- }
- }
- }
- }
- }
- else
- {
- if( reserved <= 1 ) makeroom(16);
- data[size] = in[a];
- size++;
- reserved--;
- data[size + 1] = 0;
- }
- }
- data[size] = 0;
- va_end(args);
- return size;
- }
- #if defined SPwindow
- const spchar &operator=(WCHAR *in)
- {
- if( this->size || this->reserved ) { delete [] this->data; }
- this->size = 0;
- this->reserved = 0;
- int s;
- for( s = 0; s < STR_SEARCH_LOOP_SIZE; s++ ) { if( !in[s] ) break; }
- if( isbinary ) { this->makeroom(s); this->reserved -= s; }
- else { this->makeroom(s); this->reserved -= s; this->data[s] = 0; }
- for( int a = 0; a < s; a++ ) this->data[a] = (char)in[a];
- this->size = s;
- return (*this);
- }
- const spchar &operator+=(WCHAR *in)
- {
- int s = 0;
- for( s = 0; s < STR_SEARCH_LOOP_SIZE; s++ ) { if( !in[s] ) break; }
- char *p = new char[s+1];
- p[s] = 0;
- for( int a = 0; a < s; a++ ) p[a] = (char)in[a];
- this->add(p, s);
- return (*this);
- }
- #endif
- void encrypt( char *password )
- {
- if(!size) return;
- int outsize = 0;
- unsigned char *p = str::encrypt( (unsigned char *)data, (unsigned int)size, password, &outsize);
- delete [] data;
- reserved = 0;
- size = outsize;
- data = (char *)p;
- }
- bool decrypt( char *password )
- {
- if(!size) return 0;
- int outsize = 0; bool r = 0;
- unsigned char *p;
- r = str::decrypt( (unsigned char *)data, password, &p, &outsize);
- if( r == 0 ) return 0;
- delete [] data;
- reserved = 0;
- size = outsize;
- data = (char *)p;
- }
- void readfile(char *filename)
- {
- FILE *f = fopen(filename, "rb");
- if(size || reserved) delete [] data;
- fseek(f, 0, SEEK_END);
- size = ftell(f);
- reserved = 0;
- fseek(f, 0, SEEK_SET);
- data = new char[size];
- fread(data, 1, size, f);
- fclose(f);
- }
- void writefile(char *filename)
- {
- if(!size) return;
- FILE *f = fopen(filename, "wb");
- fwrite(data, 1, size, f);
- fclose(f);
- }
- void resize( int newsize )
- {
- if( newsize > size ) makeroom( size - newsize );
- else
- {
- if( newsize == size ) return;
- data[newsize] = 0;
- reserved += size - newsize;
- size = newsize;
- }
- }
- const spchar &operator+=(int in)
- {
- this->makeroom(in);
- return (*this);
- }
- const spchar &operator+=(char in)
- {
- this->add(&in, 1);
- return (*this);
- }
- const spchar &operator-=(char *in)
- {
- int s = str::size(in);
- int p = this->find(in, s);
- if( p == -1 ) return (*this);
- this->remove( p, p+s-1);
- return (*this);
- }
- const spchar &operator-=(int in)
- {
- if( size - in < 0 ) in = size;
- this->resize( size-in );
- return (*this);
- }
- const spchar &operator=(int in)
- {
- this->resize(in);
- return (*this);
- }
- const spchar &operator++(int )
- {
- this->makeroom(1);
- return (*this);
- }
- const spchar &operator+=(char *in)
- {
- this->add(in);
- return (*this);
- }
- const spchar &operator=(char *in)
- {
- this->set(in);
- return (*this);
- }
- const spchar &operator=(const spchar &in)
- {
- if( this == &in ) return (*this);
- if( this->size || this->reserved ) delete [] this ->data;
- this->size = in.size;
- this->reserved = in.reserved;
- this->reserv_step = in.reserv_step;
- this->fpos = in.fpos;
- this->isbinary = in.isbinary;
- int a;
- if( in.size || in.reserved )
- {
- if( in.isbinary )
- {
- this->data = new char[in.size+in.reserved];
- for( a = 0; a < in.size; a++ ) this->data[a] = in.data[a];
- }
- else
- {
- this->data = new char[in.size+in.reserved+1];
- for( a = 0; a < in.size; a++ ) this->data[a] = in.data[a];
- this->data[in.size] = 0;
- }
- }
- return (*this);
- }
- spchar( spchar &in )
- {
- if( this == &in ) return;
- this->size = in.size;
- this->reserved = in.reserved;
- this->reserv_step = in.reserv_step;
- this->fpos = in.fpos;
- this->isbinary = in.isbinary;
- int a;
- if( in.size || in.reserved )
- {
- if( in.isbinary )
- {
- this->data = new char[in.size+in.reserved];
- for( a = 0; a < in.size; a++ ) this->data[a] = in.data[a];
- }
- else
- {
- this->data = new char[in.size+in.reserved+1];
- for( a = 0; a < in.size; a++ ) this->data[a] = in.data[a];
- this->data[in.size] = 0;
- }
- }
- }
- };
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement