Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | updated |
---|---|
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: | 3497207bc26c3cb64571209acf074787627ed743 |
User & Date: | alexey@sudachen.name 2011-10-17 15:03:31 |
Context
2011-11-07
| ||
00:37 | removed 'extra' directory check-in: 91394f2a1f user: alexey@sudachen.name tags: trunk | |
2011-10-17
| ||
15:03 | updated check-in: 3497207bc2 user: alexey@sudachen.name tags: trunk | |
2011-10-06
| ||
08:01 | updated check-in: d61fab19de user: alexey@sudachen.name tags: trunk | |
Changes
Changes to cipher.hc.
31 31 #define C_once_1F19AF84_9BBE_46CC_87A4_8252243D7219 32 32 33 33 #ifdef _LIBYOYO 34 34 #define _YOYO_CIPHER_BUILTIN 35 35 #endif 36 36 37 37 #include "yoyo.hc" 38 +#include "md5.hc" 39 +#include "sha2.hc" 38 40 39 41 #ifdef _YOYO_CIPHER_BUILTIN 40 42 # define _YOYO_CIPHER_BUILTIN_CODE(Code) Code 41 43 # define _YOYO_CIPHER_EXTERN 42 44 #else 43 45 # define _YOYO_CIPHER_BUILTIN_CODE(Code) 44 46 # define _YOYO_CIPHER_EXTERN extern ................................................................................ 65 67 { ((void(*)(void*,void*))Yo_Find_Method_Of(cipher,Oj_Decrypt16_OjMID,YO_RAISE_ERROR)) 66 68 (cipher,block16); }); 67 69 68 70 void _Oj_Check_Buffer_Size_N_Alignment_8(int S_len) 69 71 #ifdef _YOYO_CIPHER_BUILTIN 70 72 { 71 73 if ( S_len < 8 ) 72 - Yo_Raise(YOYO_ERROR_NO_ENOUGH,"data buffer to small",__Yo_FILE__,__LINE__); 74 + __Raise(YOYO_ERROR_NO_ENOUGH,__yoTa("data buffer to small",0)); 73 75 74 76 if ( S_len % 8 ) 75 - Yo_Raise(YOYO_ERROR_UNALIGNED,"data buffer should be aligned to 8 bytes",__Yo_FILE__,__LINE__); 77 + __Raise(YOYO_ERROR_UNALIGNED,__yoTa("size of data buffer should be aligned to 8 bytes",0)); 78 + } 79 +#endif 80 + ; 81 + 82 +void _Oj_Check_Buffer_Size_N_Alignment_16(int S_len) 83 +#ifdef _YOYO_CIPHER_BUILTIN 84 + { 85 + if ( S_len < 16 ) 86 + __Raise(YOYO_ERROR_NO_ENOUGH,__yoTa("data buffer to small",0)); 87 + 88 + if ( S_len % 16 ) 89 + __Raise(YOYO_ERROR_UNALIGNED,__yoTa("size of data buffer should be aligned to 16 bytes",0)); 90 + } 91 +#endif 92 + ; 93 + 94 +void _Oj_Encrypt_Decrypt_ECB_8(void *cipher, void (*f8)(void*,void*), void *S, int S_len) 95 +#ifdef _YOYO_CIPHER_BUILTIN 96 + { 97 + int i; 98 + 99 + _Oj_Check_Buffer_Size_N_Alignment_8(S_len); 100 + 101 + for ( i = 0; i < S_len/8; ++i ) 102 + { 103 + byte_t *p = (byte_t*)S+i*8; 104 + f8(cipher,p); 105 + } 106 + } 107 +#endif 108 + ; 109 + 110 +void _Oj_Encrypt_Decrypt_ECB_16(void *cipher, void (*f16)(void*,void*), void *S, int S_len) 111 +#ifdef _YOYO_CIPHER_BUILTIN 112 + { 113 + int i; 114 + 115 + _Oj_Check_Buffer_Size_N_Alignment_16(S_len); 116 + 117 + for ( i = 0; i < S_len/16; ++i ) 118 + { 119 + byte_t *p = (byte_t*)S+i*16; 120 + f16(cipher,p); 121 + } 76 122 } 77 123 #endif 78 124 ; 79 125 80 126 void Oj_Encrypt_ECB(void *cipher, void *S, int S_len) 81 127 #ifdef _YOYO_CIPHER_BUILTIN 82 128 { 83 129 int i; 84 - void (*encrypt8)(void*,void*) = Yo_Find_Method_Of(&cipher,Oj_Encrypt8_OjMID,YO_RAISE_ERROR); 130 + void (*f)(void*,void*) = Yo_Find_Method_Of(&cipher,Oj_Encrypt8_OjMID,0); 85 131 86 - _Oj_Check_Buffer_Size_N_Alignment_8(S_len); 87 - 88 - for ( i = 0; i < S_len/8; ++i ) 89 - { 90 - byte_t *p = (byte_t*)S+i*8; 91 - encrypt8(cipher,p); 92 - } 93 - } 94 -#endif 95 - ; 96 - 97 -void Oj_Encrypt_CBC(void *cipher, void *S, int S_len, void *old8_) 98 -#ifdef _YOYO_CIPHER_BUILTIN 99 - { 100 - int i,j; 101 - byte_t *old8 = old8_; 102 - void (*encrypt8)(void*,void*) = Yo_Find_Method_Of(&cipher,Oj_Encrypt8_OjMID,YO_RAISE_ERROR); 103 - 104 - _Oj_Check_Buffer_Size_N_Alignment_8(S_len); 105 - 106 - for ( i = 0; i < S_len/8; ++i ) 107 - { 108 - byte_t *p = (byte_t*)S+i*8; 109 - if ( old8 ) 110 - for ( j = 0; j < 8; ++j ) 111 - p[j] ^= old8[j]; 112 - encrypt8(cipher,p); 113 - old8 = p; 114 - } 115 - 116 - if ( old8_ ) 117 - memcpy(old8_,old8,8); 132 + if ( f ) 133 + _Oj_Encrypt_Decrypt_ECB_8(cipher,f,S,S_len); 134 + else if ( 0 != (f = Yo_Find_Method_Of(&cipher,Oj_Encrypt16_OjMID,0)) ) 135 + _Oj_Encrypt_Decrypt_ECB_16(cipher,f,S,S_len); 136 + else 137 + __Raise(YOYO_ERROR_METHOD_NOT_FOUND, 138 + __yoTa("cipher does not contain Oj_Encrypt8_OjMID or Oj_Encrypt16_OjMID mothod",0)); 118 139 } 119 140 #endif 120 141 ; 121 142 122 143 void Oj_Decrypt_ECB(void *cipher, void *S, int S_len) 123 144 #ifdef _YOYO_CIPHER_BUILTIN 124 145 { 125 146 int i; 126 - void (*decrypt8)(void*,void*) = Yo_Find_Method_Of(&cipher,Oj_Decrypt8_OjMID,YO_RAISE_ERROR); 147 + void (*f)(void*,void*) = Yo_Find_Method_Of(&cipher,Oj_Decrypt8_OjMID,0); 148 + 149 + if ( f ) 150 + _Oj_Encrypt_Decrypt_ECB_8(cipher,f,S,S_len); 151 + else if ( 0 != (f = Yo_Find_Method_Of(&cipher,Oj_Decrypt16_OjMID,0)) ) 152 + _Oj_Encrypt_Decrypt_ECB_16(cipher,f,S,S_len); 153 + else 154 + __Raise(YOYO_ERROR_METHOD_NOT_FOUND, 155 + __yoTa("cipher does not contain Oj_Decrypt8_OjMID or Oj_Decrypt16_OjMID mothod",0)); 156 + } 157 +#endif 158 + ; 159 + 160 +quad_t _Oj_Encrypt_Decrypt_XEX_8(void *cipher, void (*f8)(void*,void*), void (*xex)(void*,void*), void *S, int S_len, quad_t st) 161 +#ifdef _YOYO_CIPHER_BUILTIN 162 + { 163 + int i,j, n = xex?8:16; 164 + byte_t q16[16] = {0}; 127 165 128 166 _Oj_Check_Buffer_Size_N_Alignment_8(S_len); 129 - 167 + 130 168 for ( i = 0; i < S_len/8; ++i ) 131 169 { 132 170 byte_t *p = (byte_t*)S+i*8; 133 - decrypt8(cipher,p); 171 + ++st; 172 + Quad_To_Eight(st,q16); 173 + 174 + if ( xex ) 175 + xex(cipher,q16); 176 + else 177 + Md5_Digest(q16,8,q16); 178 + 179 + for ( j = 0; j < n; ++j ) 180 + p[j%8] ^= q16[j]; 181 + f8(cipher,p); 182 + for ( j = 0; j < n; ++j ) 183 + p[j%8] ^= q16[j]; 184 + } 185 + 186 + return st; 187 + } 188 +#endif 189 + ; 190 + 191 +quad_t _Oj_Encrypt_Decrypt_XEX_16(void *cipher, void (*f16)(void*,void*), void (*xex)(void*,void*), void *S, int S_len, quad_t st) 192 +#ifdef _YOYO_CIPHER_BUILTIN 193 + { 194 + int i,j, n = xex?16:32; 195 + byte_t q32[32] = {0}; 196 + 197 + _Oj_Check_Buffer_Size_N_Alignment_16(S_len); 198 + 199 + for ( i = 0; i < S_len/16; ++i ) 200 + { 201 + byte_t *p = (byte_t*)S+i*16; 202 + ++st; 203 + Quad_To_Eight(st,q32); 204 + ++st; 205 + Quad_To_Eight(st,q32+8); 206 + 207 + if ( xex ) 208 + xex(cipher,q32); 209 + else 210 + Sha2_Digest(q32,16,q32); 211 + 212 + for ( j = 0; j < n; ++j ) 213 + p[j%16] ^= q32[j]; 214 + f16(cipher,p); 215 + for ( j = 0; j < n; ++j ) 216 + p[j%16] ^= q32[j]; 217 + } 218 + 219 + return st; 220 + } 221 +#endif 222 + ; 223 + 224 +quad_t Oj_Encrypt_XEX(void *cipher, void *S, int S_len, quad_t st) 225 +#ifdef _YOYO_CIPHER_BUILTIN 226 + { 227 + void (*encrypt)(void*,void*) = Yo_Find_Method_Of(&cipher,Oj_Encrypt8_OjMID,0); 228 + if ( encrypt ) 229 + return _Oj_Encrypt_Decrypt_XEX_8(cipher,encrypt,encrypt,S,S_len,st); 230 + else if ( 0 != (encrypt = Yo_Find_Method_Of(&cipher,Oj_Encrypt16_OjMID,0)) ) 231 + return _Oj_Encrypt_Decrypt_XEX_16(cipher,encrypt,encrypt,S,S_len,st); 232 + else 233 + __Raise(YOYO_ERROR_METHOD_NOT_FOUND, 234 + __yoTa("cipher does not contain Oj_Encrypt8_OjMID or Oj_Encrypt16_OjMID mothod",0)); 235 + return 0; 236 + } 237 +#endif 238 + ; 239 + 240 +quad_t Oj_Decrypt_XEX(void *cipher, void *S, int S_len, quad_t st) 241 +#ifdef _YOYO_CIPHER_BUILTIN 242 + { 243 + void (*encrypt)(void*,void*) = Yo_Find_Method_Of(&cipher,Oj_Encrypt8_OjMID,0); 244 + void (*decrypt)(void*,void*); 245 + if ( encrypt ) 246 + { 247 + decrypt = Yo_Find_Method_Of(&cipher,Oj_Decrypt8_OjMID,YO_RAISE_ERROR); 248 + return _Oj_Encrypt_Decrypt_XEX_8(cipher,decrypt,encrypt,S,S_len,st); 249 + } 250 + else if ( 0 != (encrypt = Yo_Find_Method_Of(&cipher,Oj_Encrypt16_OjMID,0)) ) 251 + { 252 + decrypt = Yo_Find_Method_Of(&cipher,Oj_Decrypt16_OjMID,YO_RAISE_ERROR); 253 + return _Oj_Encrypt_Decrypt_XEX_16(cipher,decrypt,encrypt,S,S_len,st); 134 254 } 255 + else 256 + __Raise(YOYO_ERROR_METHOD_NOT_FOUND, 257 + __yoTa("cipher does not contain Oj_Encrypt8_OjMID or Oj_Encrypt16_OjMID mothod",0)); 258 + return 0; 259 + } 260 +#endif 261 + ; 262 + 263 +quad_t Oj_Encrypt_XEX_MDSH(void *cipher, void *S, int S_len, quad_t st) 264 +#ifdef _YOYO_CIPHER_BUILTIN 265 + { 266 + void (*f)(void*,void*) = Yo_Find_Method_Of(&cipher,Oj_Encrypt8_OjMID,0); 267 + if ( f ) 268 + return _Oj_Encrypt_Decrypt_XEX_8(cipher,f,0,S,S_len,st); 269 + else if ( 0 != (f = Yo_Find_Method_Of(&cipher,Oj_Encrypt16_OjMID,0)) ) 270 + return _Oj_Encrypt_Decrypt_XEX_16(cipher,f,0,S,S_len,st); 271 + else 272 + __Raise(YOYO_ERROR_METHOD_NOT_FOUND, 273 + __yoTa("cipher does not contain Oj_Encrypt8_OjMID or Oj_Encrypt16_OjMID mothod",0)); 274 + return 0; 135 275 } 136 276 #endif 137 277 ; 138 278 139 -void Oj_Decrypt_CBC(void *cipher, void *S, int S_len, void *old8) 279 +quad_t Oj_Decrypt_XEX_MDSH(void *cipher, void *S, int S_len, quad_t st) 140 280 #ifdef _YOYO_CIPHER_BUILTIN 141 281 { 142 - int i,j; 143 - void (*decrypt8)(void*,void*) = Yo_Find_Method_Of(&cipher,Oj_Decrypt8_OjMID,YO_RAISE_ERROR); 144 - 145 - _Oj_Check_Buffer_Size_N_Alignment_8(S_len); 146 - 147 - if ( !old8 ) old8 = alloca(8); 148 - 149 - for ( i = 0; i < S_len/8; ++i ) 150 - { 151 - byte_t bf[8]; 152 - byte_t *p = (byte_t*)S+i*8; 153 - memcpy(bf,p,8); 154 - decrypt8(cipher,p); 155 - for ( j = 0; j < 8; ++j ) 156 - p[j] ^= ((byte_t*)old8)[j]; 157 - memcpy(old8,bf,8); 158 - } 282 + void (*f)(void*,void*) = Yo_Find_Method_Of(&cipher,Oj_Decrypt8_OjMID,0); 283 + if ( f ) 284 + return _Oj_Encrypt_Decrypt_XEX_8(cipher,f,0,S,S_len,st); 285 + else if ( 0 != (f = Yo_Find_Method_Of(&cipher,Oj_Decrypt16_OjMID,0)) ) 286 + return _Oj_Encrypt_Decrypt_XEX_16(cipher,f,0,S,S_len,st); 287 + else 288 + __Raise(YOYO_ERROR_METHOD_NOT_FOUND, 289 + __yoTa("cipher does not contain Oj_Decrypt8_OjMID or Oj_Decrypt16_OjMID mothod",0)); 290 + return 0; 159 291 } 160 292 #endif 161 293 ; 162 294 163 295 #endif /* C_once_1F19AF84_9BBE_46CC_87A4_8252243D7219 */ 164 296
Changes to datetime.hc.
34 34 #define _YOYO_DATETIME_BUILTIN 35 35 #endif 36 36 37 37 #include "yoyo.hc" 38 38 39 39 typedef quad_t datetime_t; 40 40 41 +#define Get_Curr_Datetime() Current_Gmt_Datetime() 42 +#define Get_Posix_Datetime(Dt) Timet_Of_Datetime(Dt) 43 +#define Get_Gmtime_Datetime(T) Gmtime_Datetime(T) 44 +#define Get_System_Useconds() System_Useconds() 45 +#define Get_System_Millis() (Get_System_Useconds()/1000) 46 + 47 +#define System_Millis() (System_Useconds()/1000) 48 +quad_t System_Useconds() 49 +#ifdef _YOYO_DATETIME_BUILTIN 50 + { 51 + #ifdef __windoze 52 + SYSTEMTIME systime = {0}; 53 + FILETIME ftime; 54 + quad_t Q; 55 + GetSystemTime(&systime); 56 + SystemTimeToFileTime(&systime,&ftime); 57 + Q = ((quad_t)ftime.dwHighDateTime << 32) + (quad_t)ftime.dwLowDateTime; 58 + Q -= 116444736000000000LL; /* posix epoche */ 59 + return Q/10; 60 + #else 61 + struct timeval tv = {0}; 62 + gettimeofday(&tv,0); 63 + return ( (quad_t)tv.tv_sec * 1000*1000 + (quad_t)tv.tv_usec ); 64 + #endif 65 + } 66 +#endif 67 + ; 68 + 41 69 uint_t Get_Mclocks() 42 70 #ifdef _YOYO_DATETIME_BUILTIN 43 71 { 44 72 double c = clock(); 45 73 return (uint_t)((c/CLOCKS_PER_SEC)*1000); 46 74 } 47 -#endif 48 - ; 49 - 50 -uint_t Get_Curr_Date() 51 -#ifdef _YOYO_DATETIME_BUILTIN 52 - { 53 - time_t t; 54 - struct tm *tm; 55 - time(&t); 56 - tm = gmtime(&t); 57 - return (((uint_t)tm->tm_year+1900)<<16)|((uint_t)(tm->tm_mon+1)<<8)|tm->tm_mday; 58 - } 59 -#endif 60 - ; 61 - 62 -uint_t Get_Curr_Time() 63 -#ifdef _YOYO_DATETIME_BUILTIN 64 - { 65 - uint_t msec; 66 - time_t t; 67 - struct tm *tm; 68 - time(&t); 69 - msec = Get_Mclocks(); 70 - tm = gmtime(&t); 71 - return ((uint_t)tm->tm_hour<<24)|((uint_t)tm->tm_min<<16)|((uint_t)tm->tm_sec<<8)|((msec/10)%100); 72 - } 73 75 #endif 74 76 ; 75 77 76 78 double Get_Sclocks() 77 79 #ifdef _YOYO_DATETIME_BUILTIN 78 80 { 79 81 double c = clock(); 80 82 return c/CLOCKS_PER_SEC; 81 83 } 82 84 #endif 83 85 ; 84 86 85 -quad_t Get_Gmtime_Datetime(time_t t) 87 +quad_t Tm_To_Datetime(struct tm *tm,int msec) 86 88 #ifdef _YOYO_DATETIME_BUILTIN 87 89 { 88 - uint_t msec,dt,mt; 89 - struct tm *tm; 90 - tm = gmtime(&t); 91 - msec = Get_Mclocks(); 92 - dt = (((uint_t)tm->tm_year+1900)<<16)|(((uint_t)tm->tm_mon+1)<<8)|tm->tm_mday; 93 - mt = ((uint_t)tm->tm_hour<<24)|(uint_t)(tm->tm_min<<16)|((uint_t)tm->tm_sec<<8)|((msec/10)%100); 90 + uint_t dt = (((uint_t)tm->tm_year+1900)<<16)|(((uint_t)tm->tm_mon+1)<<8)|tm->tm_mday; 91 + uint_t mt = ((uint_t)tm->tm_hour<<24)|(uint_t)(tm->tm_min<<16)|((uint_t)tm->tm_sec<<8)|((msec/10)%100); 94 92 return ((quad_t)dt << 32)|(quad_t)mt; 95 93 } 96 94 #endif 97 95 ; 98 96 99 -quad_t Get_Curr_Datetime() 97 +#define Gmtime_Datetime(T) _Gmtime_Datetime(T,0) 98 +quad_t _Gmtime_Datetime(time_t t, int ms) 99 +#ifdef _YOYO_DATETIME_BUILTIN 100 + { 101 + struct tm *tm; 102 + tm = gmtime(&t); 103 + return Tm_To_Datetime(tm,ms); 104 + } 105 +#endif 106 + ; 107 + 108 +#define Local_Datetime(T) _Local_Datetime(T,0) 109 +quad_t _Local_Datetime(time_t t, int ms) 110 +#ifdef _YOYO_DATETIME_BUILTIN 111 + { 112 + struct tm *tm; 113 + tm = localtime(&t); 114 + return Tm_To_Datetime(tm,ms); 115 + } 116 +#endif 117 + ; 118 + 119 +quad_t Current_Gmt_Datetime() 120 +#ifdef _YOYO_DATETIME_BUILTIN 121 + { 122 + quad_t usec = Get_System_Useconds(); 123 + return _Gmtime_Datetime((time_t)(usec/1000000),(int)((usec/1000)%1000)); 124 + } 125 +#endif 126 + ; 127 + 128 +quad_t Current_Local_Datetime() 100 129 #ifdef _YOYO_DATETIME_BUILTIN 101 130 { 102 - time_t t; 103 - time(&t); 104 - return Get_Gmtime_Datetime(t); 131 + quad_t usec = Get_System_Useconds(); 132 + return _Local_Datetime((time_t)(usec/1000000),(int)((usec/1000)%1000)); 105 133 } 106 134 #endif 107 135 ; 108 136 109 137 #define Dt_Hour(Dt) ((int)((Dt)>>24)&0x0ff) 110 138 #define Dt_Min(Dt) ((int)((Dt)>>16)&0x0ff) 111 139 #define Dt_Sec(Dt) ((int)((Dt)>> 8)&0x0ff) ................................................................................ 119 147 { 120 148 uint_t dt = ((year%0x0ffff)<<16)|((month%13)<<8)|(day%32); 121 149 uint_t mt = ((hour%24)<<24)|((minute%60)<<16)|((segundo%60)<<8); 122 150 return ((quad_t)dt << 32)|(quad_t)mt; 123 151 } 124 152 #endif 125 153 ; 126 - 127 -time_t Get_Posix_Datetime(quad_t dtime) 154 + 155 +time_t Timet_Of_Datetime(quad_t dtime) 128 156 #ifdef _YOYO_DATETIME_BUILTIN 129 157 { 130 158 struct tm tm; 131 159 memset(&tm,0,sizeof(tm)); 132 160 tm.tm_year = Dt_Year(dtime)-1900; 133 161 tm.tm_mon = Dt_Mon(dtime)-1; 134 162 tm.tm_mday = Dt_Mday(dtime); ................................................................................ 135 163 tm.tm_hour = Dt_Hour(dtime); 136 164 tm.tm_min = Dt_Min(dtime); 137 165 return mktime(&tm); 138 166 } 139 167 #endif 140 168 ; 141 169 142 -#define Get_System_Millis() (Get_System_Useconds()/1000) 143 -quad_t Get_System_Useconds() 144 -#ifdef _YOYO_DATETIME_BUILTIN 145 - { 146 - #ifdef __windoze 147 - SYSTEMTIME systime = {0}; 148 - FILETIME ftime; 149 - quad_t Q; 150 - GetSystemTime(&systime); 151 - SystemTimeToFileTime(&systime,&ftime); 152 - Q = ((quad_t)ftime.dwHighDateTime << 32) + (quad_t)ftime.dwLowDateTime; 153 - return Q/10; 154 - #else 155 - struct timeval tv = {0}; 156 - gettimeofday(&tv,0); 157 - return ( (quad_t)tv.tv_sec * 1000*1000 + (quad_t)tv.tv_usec ); 158 - #endif 159 - } 160 -#endif 161 - ; 162 - 163 170 #ifdef __windoze 164 171 void Timet_To_Filetime(time_t t, FILETIME *pft) 165 172 # ifdef _YOYO_DATETIME_BUILTIN 166 173 { 167 174 quad_t ll = (quad_t)t * 10000000 + 116444736000000000LL; 168 175 pft->dwLowDateTime = (DWORD)ll; 169 176 pft->dwHighDateTime = (DWORD)(ll >> 32);
Changes to defpars.hc.
113 113 } 114 114 115 115 return out; 116 116 } 117 117 #endif 118 118 ; 119 119 120 + 121 +char *Def_Parse_Get_Node_Literal(YOYO_DEFPARSE_STATE *st) 122 +#ifdef _YOYO_DEFPARS_BUILTIN 123 + { 124 + if ( *st->text == '"' || *st->text == '\'' ) 125 + return Def_Parse_Get_Literal(st); 126 + else 127 + { 128 + int capacity = 127; 129 + int len = 0; 130 + char *out = 0; 131 + char *q = st->text; 132 + while ( *st->text && *st->text != ')' ) 133 + ++st->text; 134 + __Vector_Append(&out,&len,&capacity,q,st->text-q); 135 + return out; 136 + } 137 + } 138 +#endif 139 + ; 140 + 120 141 typedef struct 121 142 { 122 143 int type; 123 144 union 124 145 { 125 146 YOYO_ARRAY *arr; 126 147 YOYO_BUFFER *dat; ................................................................................ 384 405 Def_Parse_Skip_Spaces(st); 385 406 386 407 if ( *st->text == '(' ) 387 408 { 388 409 char *dflt; 389 410 ++st->text; 390 411 Def_Parse_Skip_Spaces(st); 391 - dflt = Def_Parse_Get_Literal(st); 412 + dflt = Def_Parse_Get_Node_Literal(st); 392 413 Def_Parse_Skip_Spaces(st); 393 414 if ( *st->text != ')' ) 394 415 __Raise(YOYO_ERROR_ILLFORMED,__Format("expected ')' at line %d",st->lineno)); 395 416 ++st->text; 396 417 Def_Parse_Skip_Spaces(st); 397 418 398 419 nn = Xnode_Append(n,name);
Changes to file.hc.
50 50 # define _YOYO_FILE_BUILTIN_CODE(Code) Code 51 51 # define _YOYO_FILE_EXTERN 52 52 #else 53 53 # define _YOYO_FILE_BUILTIN_CODE(Code) 54 54 # define _YOYO_FILE_EXTERN extern 55 55 #endif 56 56 57 +void File_Check_Error(char *op, FILE *f, char *fname, int look_to_errno) 58 +#ifdef _YOYO_FILE_BUILTIN 59 + { 60 + int err = 0; 61 + char *errS = 0; 62 + 63 + if ( look_to_errno ) 64 + { 65 + if ( (err = errno) ) 66 + errS = strerror(err); 67 + } 68 + else if ( f && !feof(f) && ( err = ferror(f) ) ) 69 + { 70 + errS = strerror(err); 71 + clearerr(f); 72 + } 73 + 74 + if (err) 75 + __Raise_Format(YOYO_ERROR_IO,("%s failed on file '%s': %s",op,fname,errS)); 76 + } 77 +#endif 78 + ; 79 + 80 +#define Raise_If_File_Error(Op,Fname) File_Check_Error(Op,0,Fname,1) 81 + 57 82 char *Path_Basename(char *path) 58 83 #ifdef _YOYO_FILE_BUILTIN 59 84 { 60 85 char *ret = path; 61 86 if ( path ) 62 87 { 63 88 char *p = strrchr(path,'/'); ................................................................................ 117 142 #endif 118 143 } 119 144 return ptr; 120 145 } 121 146 #endif 122 147 ; 123 148 149 +void Change_Directory(char *dirname) 150 +#ifdef _YOYO_FILE_BUILTIN 151 + { 152 + __Auto_Release 153 + { 154 + int err; 155 + #ifdef __windoze 156 + wchar_t *tmp = Str_Utf8_To_Unicode(dirname); 157 + err = _wchdir(tmp); 158 + #else 159 + err = chdir(dirname); 160 + #endif 161 + if ( err == - 1 ) 162 + Raise_If_File_Error("chdir",dirname); 163 + } 164 + } 165 +#endif 166 + ; 167 + 124 168 char *Path_Unique_Name(char *dirname,char *pfx, char *sfx) 125 169 #ifdef _YOYO_FILE_BUILTIN 126 170 { 127 171 #ifdef __windoze 128 172 char DELIMITER[] = "\\"; 129 173 #else 130 174 char DELIMITER[] = "/"; ................................................................................ 242 286 } 243 287 #endif 244 288 return Str_Copy(path,-1); 245 289 } 246 290 #endif 247 291 ; 248 292 249 -void File_Check_Error(char *op, FILE *f, char *fname, int look_to_errno) 250 -#ifdef _YOYO_FILE_BUILTIN 251 - { 252 - int err = 0; 253 - char *errS = 0; 254 - 255 - if ( look_to_errno ) 256 - { 257 - if ( (err = errno) ) 258 - errS = strerror(err); 259 - } 260 - else if ( f && !feof(f) && ( err = ferror(f) ) ) 261 - { 262 - errS = strerror(err); 263 - clearerr(f); 264 - } 265 - 266 - if (err) 267 - Yo_Raise(YOYO_ERROR_IO, 268 - Yo_Format("%s failed on file '%s': %s",op,fname,errS), 269 - __FILE__,__LINE__); 270 - } 271 -#endif 272 - ; 273 - 274 -#define Raise_If_File_Error(Op,Fname) File_Check_Error(Op,0,Fname,1) 275 - 276 293 typedef struct _YOYO_FILE_STATS 277 294 { 278 295 time_t ctime; 279 296 time_t mtime; 280 297 quad_t length; 281 298 282 299 struct { ................................................................................ 398 415 _YOYO_FILE_BUILTIN_CODE({YOYO_FILE_STATS st={0}; return File_Get_Stats(name,&st,0)->f.is_directory;}); 399 416 int File_Is_Writable(char *name) 400 417 _YOYO_FILE_BUILTIN_CODE({YOYO_FILE_STATS st={0}; return File_Get_Stats(name,&st,0)->f.is_writable;}); 401 418 int File_Is_Readable(char *name) 402 419 _YOYO_FILE_BUILTIN_CODE({YOYO_FILE_STATS st={0}; return File_Get_Stats(name,&st,0)->f.is_readable;}); 403 420 int File_Is_Executable(char *name) 404 421 _YOYO_FILE_BUILTIN_CODE({YOYO_FILE_STATS st={0}; return File_Get_Stats(name,&st,0)->f.is_executable;}); 422 + 423 +void Delete_Directory(char *name) 424 +#ifdef _YOYO_FILE_BUILTIN 425 + { 426 + YOYO_FILE_STATS st; 427 + if ( File_Get_Stats(name,&st,1)->f.is_directory ) 428 + { 429 + #ifdef __windoze 430 + if ( _wrmdir(Str_Utf8_To_Unicode(name)) < 0 ) 431 + #else 432 + if ( rmdir(name) < 0 ) 433 + #endif 434 + File_Check_Error("rmdir",0,name,1); 435 + } 436 + } 437 +#endif 438 + ; 405 439 406 440 void Create_Directory(char *name) 407 441 #ifdef _YOYO_FILE_BUILTIN 408 442 { 409 443 YOYO_FILE_STATS st; 410 444 if ( !File_Get_Stats(name,&st,1)->f.is_directory ) 411 445 { ................................................................................ 522 556 if ( st.f.exists ) 523 557 { 524 558 if ( st.f.is_directory && force ) 525 559 { 526 560 YOYO_ARRAY *L = File_List_Directory(name,0); 527 561 for ( i = 0; i < L->count; ++i ) 528 562 File_Unlink(Path_Join(name,L->at[i]),force); 563 + Delete_Directory(name); 529 564 } 530 565 else 531 566 err = 532 567 #ifdef __windoze 533 568 _wunlink(Str_Utf8_To_Unicode(name)); 534 569 #else 535 570 unlink(name);
Changes to prog.hc.
247 247 if ( flags & PROG_EXIT_ON_ERROR ) 248 248 Error_Print_N_Exit(Yo__basename(argv[0]),-1); 249 249 } 250 250 return rt; 251 251 } 252 252 #endif 253 253 ; 254 + 255 +YOYO_ARRAY *Prog_Argc_Argv(char *input) 256 +#ifdef _YOYO_PROG_BUILTIN 257 + { 258 + YOYO_ARRAY *argv = Array_Pchars(); 259 + 260 + __Auto_Release 261 + { 262 + int argc; 263 + char *arg; 264 + char *copybuf; 265 + int dquote = 0; 266 + int lquote = 0; 267 + 268 + if ( input ) 269 + { 270 + copybuf = __Malloc(strlen(input) + 1); 271 + for ( ; *input ; ) 272 + { 273 + while ( ' ' == *input || '\t' == *input ) ++input; 274 + 275 + arg = copybuf; 276 + while ( *input ) 277 + { 278 + if ( (*input == ' ' || *input == '\t' ) && !dquote && !lquote ) 279 + break; 280 + else 281 + { 282 + if (0) ; 283 + else if (dquote) 284 + { 285 + if (*input == '"') 286 + { 287 + if ( input[1] == '"' ) 288 + *arg++ = *input++; 289 + dquote = 0; 290 + } 291 + else *arg++ = *input; 292 + } 293 + else if (lquote) 294 + { 295 + if (*input == '>') lquote = 0; 296 + *arg++ = *input; 297 + } 298 + else // !dquote && !lquote 299 + { 300 + if (0) ; 301 + else if (*input == '"') dquote = 1; 302 + else 303 + { 304 + if (*input == '<') lquote = 1; 305 + *arg++ = *input; 306 + } 307 + } 308 + input++; 309 + } 310 + } 311 + *arg = 0; 312 + 313 + Array_Push(argv,Str_Copy_Npl(copybuf,-1)); 314 + 315 + while ( *input && (' ' == *input || '\t' == *input) ) ++input; 316 + } 317 + } 318 + 319 + argc = argv->count; 320 + Array_Push(argv,0); 321 + argv->count = argc; 322 + } 323 + 324 + return argv; 325 + } 326 +#endif 327 + ; 328 + 329 +#ifdef __windoze 330 +int Prog_Init_Windoze(char *patt, unsigned flags) 331 +#ifdef _YOYO_PROG_BUILTIN 332 + { 333 + int rt; 334 + 335 + __Auto_Release 336 + { 337 + YOYO_ARRAY *argv = Prog_Argc_Argv(Str_Unicode_To_Utf8(GetCommandLineW())); 338 + rt = Prog_Init(argv->count,(char**)argv->at,patt,flags); 339 + } 340 + 341 + return rt; 342 + } 343 +#endif 344 + ; 345 +#endif 254 346 255 347 int Prog_Arguments_Count() 256 348 #ifdef _YOYO_PROG_BUILTIN 257 349 { 258 350 return Array_Count(Prog_Data_Args); 259 351 } 260 352 #endif
Changes to string.hc.
45 45 46 46 /* caseinsensitive strcmp, returns 0 if equal */ 47 47 #define Str_Ansi_Equal_Nocase(Cs,Ct) (!strcmp_I(Cs,Ct)) 48 48 int strcmp_I(char *cs, char *ct) 49 49 #ifdef _YOYO_STRING_BUILTIN 50 50 { 51 51 int q = 0; 52 - do 52 + if ( cs && ct ) do 53 53 { 54 54 q = Toupper(*cs) - Toupper(*ct++); 55 55 } 56 56 while ( *cs++ && !q ); 57 57 return q; 58 58 } 59 59 #endif ................................................................................ 60 60 ; 61 61 62 62 #define Str_Unicode_Compare_Nocase(Cs,Ct) wcscmp_I(Cs,Ct) 63 63 int wcscmp_I(wchar_t *cs, wchar_t *ct) 64 64 #ifdef _YOYO_STRING_BUILTIN 65 65 { 66 66 int q = 0; 67 - do 67 + if ( cs && ct ) do 68 68 { 69 69 q = towupper(*cs) - towupper(*ct++); 70 70 } 71 71 while ( *cs++ && !q ); 72 72 return q; 73 73 } 74 74 #endif ................................................................................ 75 75 ; 76 76 77 77 /* caseinsensitive strncmp, returns 0 if equal */ 78 78 int strncmp_I(char *cs, char *ct, int l) 79 79 #ifdef _YOYO_STRING_BUILTIN 80 80 { 81 81 int q = 0; 82 - if ( l ) do 82 + if ( l && cs && ct ) do 83 83 { 84 84 q = Toupper(*cs) - Toupper(*ct++); 85 85 } 86 86 while ( *cs++ && !q && --l ); 87 87 return q; 88 88 } 89 89 #endif 90 90 ; 91 91 92 92 int wcsncmp_I(wchar_t *cs, wchar_t *ct, int l) 93 93 #ifdef _YOYO_STRING_BUILTIN 94 94 { 95 95 int q = 0; 96 - if ( l ) do 96 + if ( l && cs && ct ) do 97 97 { 98 98 q = towupper(*cs) - towupper(*ct++); 99 99 } 100 100 while ( *cs++ && !q && --l ); 101 101 return q; 102 102 } 103 103 #endif ................................................................................ 383 383 ; 384 384 385 385 _YOYO_STRING_EXTERN byte_t Str_6bit_Decoding_Table[] /* 64 */ 386 386 #ifdef _YOYO_STRING_BUILTIN 387 387 = { 388 388 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 389 389 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 390 - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 390 + 255,255,255,255,255,255,255,255,255,255,255,255,255,63, 255,255, 391 391 0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,255,255,255,255,255,255, 392 - 63 ,36 ,37 ,38 ,39 ,40 ,41 ,42 ,43 ,44 ,45 ,46 ,47 ,48 ,49 ,50 , 392 + 255,36 ,37 ,38 ,39 ,40 ,41 ,42 ,43 ,44 ,45 ,46 ,47 ,48 ,49 ,50 , 393 393 51 ,52 ,53 ,54 ,55 ,56 ,57 ,58 ,59 ,60 ,61 ,255,255,255,255,62 , 394 394 255,10 ,11 ,12 ,13 ,14 ,15 ,16 ,17 ,18 ,19 ,20 ,21 ,22 ,23 ,24 , 395 395 25 ,26 ,27 ,28 ,29 ,30 ,31 ,32 ,33 ,34 ,35 ,255,255,255,255,255, 396 396 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 397 397 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 398 398 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 399 399 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
Changes to winlpc.hc.
51 51 HANDLE handle; 52 52 void *tag; 53 53 int waitable; 54 54 } YOYO_LPCPORT; 55 55 56 56 #define Lpc_Is_Connected(Port) ((Port)->handle != 0) 57 57 58 -long Lpc_Create_Port(YOYO_LPCPORT *port, char *name, int waitable, int maxsize) 58 +long Lpc_Create_Port(YOYO_LPCPORT *port, char *name, int waitable) 59 59 #ifdef _YOYO_WINLPC_BUILTIN 60 60 { 61 61 long ntst; 62 62 OBJECT_ATTRIBUTES oa; 63 63 UNICODE_STRING us_name; 64 64 wchar_t wname[256]; 65 65 ................................................................................ 68 68 Str_Utf8_To_Unicode_Convert(name,wname,256); 69 69 RtlInitUnicodeString(&us_name, wname); 70 70 InitializeObjectAttributes(&oa, &us_name, 0, 0, 0); 71 71 72 72 port->waitable = waitable; 73 73 74 74 if ( waitable ) 75 - ntst = NtCreateWaitablePort(&port->handle, &oa, 100, maxsize, 0); 75 + ntst = NtCreateWaitablePort(&port->handle, &oa, WINLPC_MAX_DATA_LENGTH, WINLPC_MAX_DATA_LENGTH, 0); 76 76 else 77 - ntst = NtCreatePort(&port->handle, &oa, 100, maxsize, 0); 77 + ntst = NtCreatePort(&port->handle, &oa, WINLPC_MAX_DATA_LENGTH, WINLPC_MAX_DATA_LENGTH, 0); 78 78 79 79 return ntst; 80 80 } 81 81 #endif 82 82 ; 83 83 84 84 long Lpc_Connect_Port(
Changes to xdata.hc.
205 205 switch (val->opt&XVALUE_OPT_VALTYPE_MASK) 206 206 { 207 207 case XVALUE_OPT_VALTYPE_INT: 208 208 return val->dec; 209 209 case XVALUE_OPT_VALTYPE_FLT: 210 210 return (long)val->flt; 211 211 case XVALUE_OPT_VALTYPE_STR: 212 - return Str_To_Int(val->txt); 212 + return Str_To_Int_Dflt(val->txt,dfltval); 213 213 case XVALUE_OPT_VALTYPE_LIT: 214 - return Str_To_Int((char*)&val->down); 214 + return Str_To_Int_Dflt((char*)&val->down,dfltval); 215 215 case XVALUE_OPT_VALTYPE_NONE: 216 216 return 0; 217 217 case XVALUE_OPT_VALTYPE_BOOL: 218 218 return val->bval; 219 219 default: 220 220 __Raise(YOYO_ERROR_UNEXPECTED_VALUE,0); 221 221 } ................................................................................ 231 231 switch (val->opt&XVALUE_OPT_VALTYPE_MASK) 232 232 { 233 233 case XVALUE_OPT_VALTYPE_INT: 234 234 return (double)val->dec; 235 235 case XVALUE_OPT_VALTYPE_FLT: 236 236 return val->flt; 237 237 case XVALUE_OPT_VALTYPE_STR: 238 - return Str_To_Flt(val->txt); 238 + return Str_To_Flt_Dflt(val->txt,dfltval); 239 239 case XVALUE_OPT_VALTYPE_LIT: 240 - return Str_To_Flt((char*)&val->down); 240 + return Str_To_Flt_Dflt((char*)&val->down,dfltval); 241 241 case XVALUE_OPT_VALTYPE_NONE: 242 242 return 0; 243 243 default: 244 244 __Raise(YOYO_ERROR_UNEXPECTED_VALUE,0); 245 245 } 246 246 return dfltval; 247 247 } ................................................................................ 257 257 case XVALUE_OPT_VALTYPE_INT: 258 258 return val->dec?1:0; 259 259 case XVALUE_OPT_VALTYPE_BOOL: 260 260 return val->bval; 261 261 case XVALUE_OPT_VALTYPE_FLT: 262 262 return val->flt?1:0; 263 263 case XVALUE_OPT_VALTYPE_STR: 264 - return Str_To_Bool(val->txt); 264 + return Str_To_Bool_Dflt(val->txt,dfltval); 265 265 case XVALUE_OPT_VALTYPE_LIT: 266 - return Str_To_Bool((char*)&val->down); 266 + return Str_To_Bool_Dflt((char*)&val->down,dfltval); 267 267 case XVALUE_OPT_VALTYPE_NONE: 268 268 return 0; 269 269 default: 270 270 __Raise(YOYO_ERROR_UNEXPECTED_VALUE,0); 271 271 } 272 272 return dfltval; 273 273 }
Changes to yoyo.hc.
371 371 #ifdef _STRICT 372 372 # define STRICT_REQUIRE(Expr) REQUIRE(Expr) 373 373 # define STRICT_CHECK(Expr) (Expr) 374 374 #else 375 375 # define STRICT_REQUIRE(Expr) ((void)0) 376 376 # define STRICT_CHECK(Expr) (1) 377 377 #endif /* _STRICT */ 378 + 379 +#if defined __i386 || defined __x86_64 380 +#define Eight_To_Quad(Eight) (*(quad_t*)(Eight)) 381 +#else 382 +quad_t Eight_To_Quad(void *b) 383 +#ifdef _YOYO_CORE_BUILTIN 384 + { 385 + uint_t q0,q1; 386 + q0 = (unsigned int)((unsigned char*)b)[0] 387 + | ((unsigned int)((unsigned char*)b)[1] << 8) 388 + | ((unsigned int)((unsigned char*)b)[2] << 16) 389 + | ((unsigned int)((unsigned char*)b)[3] << 24); 390 + b = (char*b)+4; 391 + q1 = (unsigned int)((unsigned char*)b)[0] 392 + | ((unsigned int)((unsigned char*)b)[1] << 8) 393 + | ((unsigned int)((unsigned char*)b)[2] << 16) 394 + | ((unsigned int)((unsigned char*)b)[3] << 24); 395 + return (quad_t)q0 | ((quad_t)q1 << 32); 396 + } 397 +#endif 398 + ; 399 +#endif 400 + 401 +#if defined __i386 || defined __x86_64 402 +#define Quad_To_Eight(Q,Eight) ((*(quad_t*)(Eight)) = (Q)) 403 +#else 404 +void Quad_To_Eight(quad_t q, void *b) 405 +#ifdef _YOYO_CORE_BUILTIN 406 + { 407 + byte_t *p = b; 408 + p[0] = (byte_t)q; 409 + p[1] = (byte_t)(q>>8); 410 + p[2] = (byte_t)(q>>16); 411 + p[3] = (byte_t)(q>>24); 412 + p[4] = (byte_t)(q>>32); 413 + p[5] = (byte_t)(q>>40); 414 + p[6] = (byte_t)(q>>48); 415 + p[7] = (byte_t)(q>>56); 416 + } 417 +#endif 418 + ; 419 +#endif 378 420 379 421 #if defined __i386 || defined __x86_64 380 422 #define Four_To_Unsigned(Four) (*(uint_t*)(Four)) 381 423 #else 382 424 uint_t Four_To_Unsigned(void *b) 383 425 #ifdef _YOYO_CORE_BUILTIN 384 426 { ................................................................................ 1414 1456 Yo_Fatal(YOYO_FATAL_ERROR,__yoTa("trying to pop unexistent lock",0),__Yo_FILE__,__LINE__); 1415 1457 } 1416 1458 } 1417 1459 } 1418 1460 #endif 1419 1461 ; 1420 1462 1463 +char *Yo_Btrace(void); 1464 + 1421 1465 #ifdef _YOYO_CORE_BUILTIN 1422 1466 void _Yo_Raise(int err,char *msg,char *filename,int lineno) 1423 1467 { 1424 1468 YOYO_C_SUPPORT_INFO *nfo = Yo_Tls_Get(Yo_Csup_Nfo_Tls); 1425 1469 STRICT_REQUIRE( !nfo || nfo->jb_top < nfo->jb_count ); 1426 1470 1427 1471 if ( err == YO_RERAISE_CURRENT_ERROR && (!nfo || !nfo->err.code) ) ................................................................................ 1448 1492 locks[i].unlock(locks[i].cs); 1449 1493 1450 1494 Yo_Unwind_Scope(0,nfo->jb[nfo->jb_top].auto_top); 1451 1495 1452 1496 --nfo->jb_top; 1453 1497 STRICT_REQUIRE(nfo->jb_top >= -1); 1454 1498 1499 + #ifdef _TRACEXPT 1500 + StdErr_Print_Nl(Yo_Btrace()); 1501 + #endif 1455 1502 longjmp(nfo->jb[nfo->jb_top+1].b,err?err:-1); 1456 1503 } 1457 1504 else 1458 1505 { 1459 1506 if ( err != YO_RERAISE_CURRENT_ERROR ) 1460 1507 Yo_Fatal(err,msg,filename,lineno); 1461 1508 else