Unnamed Fossil Project

Check-in [3b588728b9]
Login

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:3b588728b97b1ce860d6eab1a9ce08e35dcb2e43
User & Date: alexey@sudachen.name 2011-08-20 17:55:19
Context
2011-08-24
21:39
updated check-in: dd0eddb4cd user: alexey@sudachen.name tags: trunk
2011-08-20
17:55
updated check-in: 3b588728b9 user: alexey@sudachen.name tags: trunk
2011-08-07
17:41
updated check-in: cf0c3331be user: alexey@sudachen.name tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to bigint.hc.

743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
...
765
766
767
768
769
770
771

772
773
774
775
776
777
778
779
      if ( p )
        {
          if ( *p == '-' ) { bint->sign = -1; ++p; }
          else if ( *p == '+' ) ++p;
          
          for ( ;*p; ++p )
            {
              if ( !isdigit(*p) ) __Raise_Format(YOYO_ERROR_ILLFORMED,("invalid decimal number %s",S));
              bint = Bigint_Mul_Short(bint,10);
              bint = Bigint_Add_Short(bint,*p-'0');
            }
        }
    
    return bint;
  }
................................................................................
    char *p = S;
    
    __Auto_Ptr(bint)
      if ( p )
        {
          for ( ;*p; ++p )
            {

              if ( !isxdigit(*p) || !isxdigit(p[1]) ) __Raise_Format(YOYO_ERROR_ILLFORMED,("invalid hexadecimal number %s",S));
              bint = Bigint_Lshift(bint,8);
              bint->value[0] |= Str_Unhex_Byte(p,0,0);
              ++p;
            }
        }
    
    return bint;







|







 







>
|







743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
...
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
      if ( p )
        {
          if ( *p == '-' ) { bint->sign = -1; ++p; }
          else if ( *p == '+' ) ++p;
          
          for ( ;*p; ++p )
            {
              if ( !Isdigit(*p) ) __Raise_Format(YOYO_ERROR_ILLFORMED,("invalid decimal number %s",S));
              bint = Bigint_Mul_Short(bint,10);
              bint = Bigint_Add_Short(bint,*p-'0');
            }
        }
    
    return bint;
  }
................................................................................
    char *p = S;
    
    __Auto_Ptr(bint)
      if ( p )
        {
          for ( ;*p; ++p )
            {
              if ( !Isxdigit(*p) || !Isxdigit(p[1]) ) 
                __Raise_Format(YOYO_ERROR_ILLFORMED,("invalid hexadecimal number %s",S));
              bint = Bigint_Lshift(bint,8);
              bint->value[0] |= Str_Unhex_Byte(p,0,0);
              ++p;
            }
        }
    
    return bint;

Changes to core.hc.

104
105
106
107
108
109
110






111
112
113
114

115
116
117
118
119
120
121
...
214
215
216
217
218
219
220

221
222
223
224
225
226
227
...
244
245
246
247
248
249
250

251
252
253
254
255
256
257
....
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
#   endif
#   define malloc_size(Ptr) (0)
# else 
#   define malloc_size(Ptr) malloc_usable_size(Ptr)
# endif
#endif







#define iszof(x)     ((int)sizeof(x))
#define iszof_double ((int)sizeof(double))
#define iszof_long   ((int)sizeof(long))
#define iszof_wchar  ((int)sizeof(wchar_t))

#define __Offset_Of(T,Memb) ((longptr_t)(&((T*)0)->Memb))

typedef unsigned char  byte_t;
typedef unsigned short ushort_t;
typedef unsigned int   uint_t;
typedef unsigned long  ulong_t;

................................................................................
    YO_RERAISE_CURRENT_ERROR        = 0x7fff7fff,
    
    YOYO_TRACED_ERROR_GROUP     = YOYO_FATAL_ERROR_GROUP
                                |YOYO_RANGE_ERROR_GROUP
                                |YOYO_SELFCHECK_ERROR_GROUP,
    
    YOYO_ERROR_BASE             = 0x00008000,

    
    YOYO_ERROR_OUT_OF_MEMORY    = YOYO_FATAL_ERROR_GROUP|(YOYO_ERROR_BASE+1),
    YOYO_FATAL_ERROR            = YOYO_FATAL_ERROR_GROUP|(YOYO_ERROR_BASE+2),
    YOYO_ERROR_DYNCO_CORRUPTED  = YOYO_FATAL_ERROR_GROUP|(YOYO_ERROR_BASE+3),
    YOYO_ERROR_METHOD_NOT_FOUND = YOYO_RUNTIME_ERROR_GROUP|(YOYO_ERROR_BASE+4),
    YOYO_ERROR_REQUIRE_FAILED   = YOYO_FATAL_ERROR_GROUP|(YOYO_ERROR_BASE+5),
    YOYO_ERROR_ILLFORMED        = YOYO_ILLFORMED_ERROR_GROUP|(YOYO_ERROR_BASE+6),
................................................................................
    YOYO_ERROR_UNEXPECTED_VALUE = YOYO_FATAL_ERROR_GROUP|(YOYO_ERROR_BASE+23),
    YOYO_ERROR_ALREADY_EXISTS   = YOYO_IO_ERROR_GROUP|(YOYO_ERROR_BASE+24),
    YOYO_ERROR_INCONSISTENT     = YOYO_STORAGE_ERROR_GROUP|(YOYO_ERROR_BASE+25),
    YOYO_ERROR_TO_BIG           = YOYO_STORAGE_ERROR_GROUP|(YOYO_ERROR_BASE+26),
    YOYO_ERROR_ZERODIVIDE       = YOYO_FATAL_ERROR_GROUP|(YOYO_ERROR_BASE+27),
    YOYO_ERROR_LIMIT_REACHED    = YOYO_RUNTIME_ERROR_GROUP|(YOYO_ERROR_BASE+28),
    YOYO_ERROR_UNSUPPORTED      = YOYO_RUNTIME_ERROR_GROUP|(YOYO_ERROR_BASE+29),

  };

#define YOYO_ERROR_IS_USER_ERROR(err) !(err&YOYO_XXXX_ERROR_GROUP)

enum _YOYO_FLAGS
  {
    YO_RAISE_ERROR            = 0x70000000,
................................................................................
char *Yo_Error_Format()
#ifdef _YOYO_CORE_BUILTIN
  {
    int code = Error_Code();
    char *msg = Error_Message();

    if ( YOYO_ERROR_IS_USER_ERROR(code) )
      return Yo_Format(__yoTa("\nerror(%d): %s",0),code,msg);
    else
      return Yo_Format(__yoTa("\nerror(%08x): %s",0),code,msg);
  }
#endif
  ;
  
void Error_Exit(char *pfx)
#ifdef _YOYO_CORE_BUILTIN
  {







>
>
>
>
>
>




>







 







>







 







>







 







|

|







104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
...
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
...
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
....
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
#   endif
#   define malloc_size(Ptr) (0)
# else 
#   define malloc_size(Ptr) malloc_usable_size(Ptr)
# endif
#endif

#define Isspace(x)   isspace((unsigned)(x))
#define Isdigit(x)   isdigit((unsigned)(x))
#define Isxdigit(x)  isxdigit((unsigned)(x))
#define Toupper(x)   toupper((unsigned)(x))
#define Tolower(x)   tolower((unsigned)(x))

#define iszof(x)     ((int)sizeof(x))
#define iszof_double ((int)sizeof(double))
#define iszof_long   ((int)sizeof(long))
#define iszof_wchar  ((int)sizeof(wchar_t))
#define iszof_arr(x) ((int)(sizeof(x)/sizeof(*x)))
#define __Offset_Of(T,Memb) ((longptr_t)(&((T*)0)->Memb))

typedef unsigned char  byte_t;
typedef unsigned short ushort_t;
typedef unsigned int   uint_t;
typedef unsigned long  ulong_t;

................................................................................
    YO_RERAISE_CURRENT_ERROR        = 0x7fff7fff,
    
    YOYO_TRACED_ERROR_GROUP     = YOYO_FATAL_ERROR_GROUP
                                |YOYO_RANGE_ERROR_GROUP
                                |YOYO_SELFCHECK_ERROR_GROUP,
    
    YOYO_ERROR_BASE             = 0x00008000,
    YOYO_ERROR_USER             = YOYO_USER_ERROR_GROUP|0,
    
    YOYO_ERROR_OUT_OF_MEMORY    = YOYO_FATAL_ERROR_GROUP|(YOYO_ERROR_BASE+1),
    YOYO_FATAL_ERROR            = YOYO_FATAL_ERROR_GROUP|(YOYO_ERROR_BASE+2),
    YOYO_ERROR_DYNCO_CORRUPTED  = YOYO_FATAL_ERROR_GROUP|(YOYO_ERROR_BASE+3),
    YOYO_ERROR_METHOD_NOT_FOUND = YOYO_RUNTIME_ERROR_GROUP|(YOYO_ERROR_BASE+4),
    YOYO_ERROR_REQUIRE_FAILED   = YOYO_FATAL_ERROR_GROUP|(YOYO_ERROR_BASE+5),
    YOYO_ERROR_ILLFORMED        = YOYO_ILLFORMED_ERROR_GROUP|(YOYO_ERROR_BASE+6),
................................................................................
    YOYO_ERROR_UNEXPECTED_VALUE = YOYO_FATAL_ERROR_GROUP|(YOYO_ERROR_BASE+23),
    YOYO_ERROR_ALREADY_EXISTS   = YOYO_IO_ERROR_GROUP|(YOYO_ERROR_BASE+24),
    YOYO_ERROR_INCONSISTENT     = YOYO_STORAGE_ERROR_GROUP|(YOYO_ERROR_BASE+25),
    YOYO_ERROR_TO_BIG           = YOYO_STORAGE_ERROR_GROUP|(YOYO_ERROR_BASE+26),
    YOYO_ERROR_ZERODIVIDE       = YOYO_FATAL_ERROR_GROUP|(YOYO_ERROR_BASE+27),
    YOYO_ERROR_LIMIT_REACHED    = YOYO_RUNTIME_ERROR_GROUP|(YOYO_ERROR_BASE+28),
    YOYO_ERROR_UNSUPPORTED      = YOYO_RUNTIME_ERROR_GROUP|(YOYO_ERROR_BASE+29),
    YOYO_ERROR_IO_EOF           = YOYO_IO_ERROR_GROUP|(YOYO_ERROR_BASE+30),
  };

#define YOYO_ERROR_IS_USER_ERROR(err) !(err&YOYO_XXXX_ERROR_GROUP)

enum _YOYO_FLAGS
  {
    YO_RAISE_ERROR            = 0x70000000,
................................................................................
char *Yo_Error_Format()
#ifdef _YOYO_CORE_BUILTIN
  {
    int code = Error_Code();
    char *msg = Error_Message();

    if ( YOYO_ERROR_IS_USER_ERROR(code) )
      return Yo_Format(__yoTa("error(%d): %s",0),code,msg);
    else
      return Yo_Format(__yoTa("error(%08x): %s",0),code,msg);
  }
#endif
  ;
  
void Error_Exit(char *pfx)
#ifdef _YOYO_CORE_BUILTIN
  {

Changes to defpars.hc.

46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
..
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
...
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
...
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
...
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
...
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
...
642
643
644
645
646
647
648






649
650
651
652
653
654
    char *text;
    int lineno;
  } YOYO_DEFPARSE_STATE;

void Def_Parse_Skip_Spaces(YOYO_DEFPARSE_STATE *st)
#ifdef _YOYO_DEFPARS_BUILTIN
  {
    while ( *st->text && Chr_Isspace(*st->text) )
      {
        if ( *st->text == '\n' ) ++st->lineno;
        ++st->text;
      }
  }
#endif
  ;
................................................................................
          }
          
        if ( *st->text == brk ) ++st->text;
      }
    else
      {
        char *q = st->text;
        while ( *st->text && !Chr_Isspace(*st->text) && *st->text != ')' 
              && *st->text != '}' && *st->text != ',' && *st->text != ']' )
          ++st->text;
        __Vector_Append(&out,&len,&capacity,q,st->text-q);
      }
    
    return out;
  }
#endif
................................................................................
        ++st->text;
        if ( st->text[1] == '[' ) /* binary data */
          {
            byte_t b;
            val->dat = Buffer_Init(0);
            Def_Parse_Skip_Spaces(st);
            
            while ( Chr_Isxdigit(*st->text) )
              {
                if ( !Chr_Isxdigit(st->text[1]) )
                  __Raise(YOYO_ERROR_ILLFORMED,
                      __Format("expected hex byte value at line %d",st->lineno));
                
                b = Str_Unhex_Byte(st->text,0,0);
                Buffer_Append(val->dat,&b,1);
                st->text += 2;
                Def_Parse_Skip_Spaces(st);
................................................................................
            val->type = XVALUE_OPT_VALTYPE_BOOL;
            st->text += l;
          }
        else
          __Raise(YOYO_ERROR_ILLFORMED,
              __Format("expected boolean value at line %d",st->lineno));
      }
    else if ( !Chr_Isdigit(*st->text) 
            && ( (*st->text != '.' && *st->text != '-') || !Chr_Isdigit(st->text[1]) ) )
      {
        val->txt = Def_Parse_Get_Literal(st);
        val->type = XVALUE_OPT_VALTYPE_STR;
      }
    else /* number */
      {
        if ( *st->text == '0' )
          {
            ++st->text;
            val->dec = 0;
            
            if ( *st->text == 'x' && Chr_Isxdigit(st->text[1]) ) /* hex value */
              {
                ++st->text;
                do
                  {
                    val->dec = val->dec << 4;
                    STR_UNHEX_HALF_OCTET(st->text,val->dec,0);
                    ++st->text;
                  }
                while ( Chr_Isxdigit(*st->text) );
              }
            else if ( *st->text >= '0' && *st->text <= '7' )
              {
                ++st->text;
                do
                  {
                    val->dec = (val->dec << 3) | (*st->text-'0'); 
                    ++st->text;
                  }
                while ( *st->text >= '0' && *st->text <= '7' );
              }
            else if ( Chr_Isspace(*st->text) )
              {
                ; /* nothing, it's zero value */
              }
            else
              goto invalid_numeric;
              
            val->type = XVALUE_OPT_VALTYPE_INT;
            
          }
        else if ( Chr_Isdigit(*st->text) || *st->text == '.' || *st->text == '-' ) /* decimal or float value */
          {
            int neg = 1;
            int value = 0;
            
            if ( *st->text == '-' ) { neg = -1; ++st->text; }
            
            for ( ; Chr_Isdigit(*st->text); ++st->text )
              value = value * 10 + ( *st->text - '0' );
            
            if ( *st->text == '.' )
              {
                double exp = 1;
                double d = value*neg;
                ++st->text;
                for ( ; Chr_Isdigit(*st->text); ++st->text )
                  {
                    d = d * 10 + ( *st->text - '0' );
                    exp *= 10;
                  }
                val->flt = d/exp;
                val->type = XVALUE_OPT_VALTYPE_FLT;
              }
................................................................................
              {
                val->type = XVALUE_OPT_VALTYPE_INT;
                val->dec = value*neg;
              }
          }

        if ( *st->text 
          && !Chr_Isspace(*st->text) && *st->text != ')' 
          && *st->text != '}' && *st->text != ',' && *st->text != ']' )
      invalid_numeric:
          __Raise(YOYO_ERROR_ILLFORMED,
              __Format("invalid numeric value at line %d",st->lineno));
      }
  }
#endif
................................................................................
    YOYO_XVALUE *xv = Xnode_Value(n,name,1);;
    switch ( val->type )
      {
        case XVALUE_OPT_VALTYPE_INT:
          Xvalue_Set_Int(xv,val->dec);
          break;
        case XVALUE_OPT_VALTYPE_BOOL:
          Xvalue_Set_Int(xv,val->dec);
          break;
        case XVALUE_OPT_VALTYPE_FLT:
          Xvalue_Set_Flt(xv,val->flt);
          break;
        case XVALUE_OPT_VALTYPE_STR:
          Xvalue_Put_Str(xv,__Retain(val->txt));
          break;
................................................................................
  }
#endif
  ;

void Def_Format_File(char *fname, YOYO_XNODE *r, int flags)
#ifdef _YOYO_DEFPARS_BUILTIN
  {






  }
#endif
  ;

#endif /* C_once_750A77B2_260B_4E33_B9EA_15F01DDD61FF */








|







 







|
|







 







|

|







 







|
|











|








|











|









|






|







|







 







|







 







|







 







>
>
>
>
>
>






46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
..
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
...
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
...
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
...
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
...
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
...
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
    char *text;
    int lineno;
  } YOYO_DEFPARSE_STATE;

void Def_Parse_Skip_Spaces(YOYO_DEFPARSE_STATE *st)
#ifdef _YOYO_DEFPARS_BUILTIN
  {
    while ( *st->text && Isspace(*st->text) )
      {
        if ( *st->text == '\n' ) ++st->lineno;
        ++st->text;
      }
  }
#endif
  ;
................................................................................
          }
          
        if ( *st->text == brk ) ++st->text;
      }
    else
      {
        char *q = st->text;
        while ( *st->text && !Isspace(*st->text) && *st->text != ')' 
              && *st->text != '}' && *st->text != ',' && *st->text != ']' && *st->text != '=' )
          ++st->text;
        __Vector_Append(&out,&len,&capacity,q,st->text-q);
      }
    
    return out;
  }
#endif
................................................................................
        ++st->text;
        if ( st->text[1] == '[' ) /* binary data */
          {
            byte_t b;
            val->dat = Buffer_Init(0);
            Def_Parse_Skip_Spaces(st);
            
            while ( Isxdigit(*st->text) )
              {
                if ( !Isxdigit(st->text[1]) )
                  __Raise(YOYO_ERROR_ILLFORMED,
                      __Format("expected hex byte value at line %d",st->lineno));
                
                b = Str_Unhex_Byte(st->text,0,0);
                Buffer_Append(val->dat,&b,1);
                st->text += 2;
                Def_Parse_Skip_Spaces(st);
................................................................................
            val->type = XVALUE_OPT_VALTYPE_BOOL;
            st->text += l;
          }
        else
          __Raise(YOYO_ERROR_ILLFORMED,
              __Format("expected boolean value at line %d",st->lineno));
      }
    else if ( !Isdigit(*st->text) 
            && ( (*st->text != '.' && *st->text != '-') || !Isdigit(st->text[1]) ) )
      {
        val->txt = Def_Parse_Get_Literal(st);
        val->type = XVALUE_OPT_VALTYPE_STR;
      }
    else /* number */
      {
        if ( *st->text == '0' )
          {
            ++st->text;
            val->dec = 0;
            
            if ( *st->text == 'x' && Isxdigit(st->text[1]) ) /* hex value */
              {
                ++st->text;
                do
                  {
                    val->dec = val->dec << 4;
                    STR_UNHEX_HALF_OCTET(st->text,val->dec,0);
                    ++st->text;
                  }
                while ( Isxdigit(*st->text) );
              }
            else if ( *st->text >= '0' && *st->text <= '7' )
              {
                ++st->text;
                do
                  {
                    val->dec = (val->dec << 3) | (*st->text-'0'); 
                    ++st->text;
                  }
                while ( *st->text >= '0' && *st->text <= '7' );
              }
            else if ( Isspace(*st->text) )
              {
                ; /* nothing, it's zero value */
              }
            else
              goto invalid_numeric;
              
            val->type = XVALUE_OPT_VALTYPE_INT;
            
          }
        else if ( Isdigit(*st->text) || *st->text == '.' || *st->text == '-' ) /* decimal or float value */
          {
            int neg = 1;
            int value = 0;
            
            if ( *st->text == '-' ) { neg = -1; ++st->text; }
            
            for ( ; Isdigit(*st->text); ++st->text )
              value = value * 10 + ( *st->text - '0' );
            
            if ( *st->text == '.' )
              {
                double exp = 1;
                double d = value*neg;
                ++st->text;
                for ( ; Isdigit(*st->text); ++st->text )
                  {
                    d = d * 10 + ( *st->text - '0' );
                    exp *= 10;
                  }
                val->flt = d/exp;
                val->type = XVALUE_OPT_VALTYPE_FLT;
              }
................................................................................
              {
                val->type = XVALUE_OPT_VALTYPE_INT;
                val->dec = value*neg;
              }
          }

        if ( *st->text 
          && !Isspace(*st->text) && *st->text != ')' 
          && *st->text != '}' && *st->text != ',' && *st->text != ']' )
      invalid_numeric:
          __Raise(YOYO_ERROR_ILLFORMED,
              __Format("invalid numeric value at line %d",st->lineno));
      }
  }
#endif
................................................................................
    YOYO_XVALUE *xv = Xnode_Value(n,name,1);;
    switch ( val->type )
      {
        case XVALUE_OPT_VALTYPE_INT:
          Xvalue_Set_Int(xv,val->dec);
          break;
        case XVALUE_OPT_VALTYPE_BOOL:
          Xvalue_Set_Bool(xv,val->dec);
          break;
        case XVALUE_OPT_VALTYPE_FLT:
          Xvalue_Set_Flt(xv,val->flt);
          break;
        case XVALUE_OPT_VALTYPE_STR:
          Xvalue_Put_Str(xv,__Retain(val->txt));
          break;
................................................................................
  }
#endif
  ;

void Def_Format_File(char *fname, YOYO_XNODE *r, int flags)
#ifdef _YOYO_DEFPARS_BUILTIN
  {
    __Auto_Release
      {
        YOYO_BUFFER *bf = Buffer_Init(0);
        Def_Format_Into(bf,r,flags);
        Oj_Write_Full(Cfile_Open(fname,"w+P"),bf->at,bf->count);
      }
  }
#endif
  ;

#endif /* C_once_750A77B2_260B_4E33_B9EA_15F01DDD61FF */

Added extra/gif89a.hc.

































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192

/*

(C)2010-2011, Alexéy Sudáchen, alexey@sudachen.name

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Except as contained in this notice, the name of a copyright holder shall not
be used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization of the copyright holder.

*/

#ifndef C_once_E194EBE7_E43F_4305_A75C_3872532B12DB
#define C_once_E194EBE7_E43F_4305_A75C_3872532B12DB

#include "../libyoyo.hc"

enum
  {
    YOYO_RGBA8_PICTURE = __FOUR_CHARS('R','3','8','A'),
    YOYO_RGBAf_PICTURE = __FOUR_CHARS('R','3','f','A'),
  };

typedef struct _YOYO_PICTURE
  {
    int width;
    int height;
    int pitch;
    int weight;
    int format;
    byte_t *pixels;
  } YOYO_PICTURE;

typedef struct _YOYO_RGBA8
  {
    byte_t r;
    byte_t g;
    byte_t b;
    byte_t a;
  } YOYO_RGBA8;

typedef struct _YOYO_RGBAf
  {
    float r;
    float g;
    float b;
    float a;
  } YOYO_RGBAf;

//YOYO_PICTURE *Pict_Convert(YOYO_PICTURE *pict, int format)
//  {
//  }

#ifdef __windoze
HBITMAP Pict_Create_HBITMAP(YOYO_PICTURE *pict)
#ifdef _YOYO_PICTURE_BUILTIN
  {
  }
#endif
  ;
#endif

//YOYO_RGBA8 Pict_Get_RGBA8(YOYO_PICTURE *pic, int x, int y)
//  {
//  }
//
//void Pict_Set_RGBA8(YOYO_PICTURE *pic, int x, int y, YOYO_RGBA8 pix)
//  {
//  }

void Pict_Allocate_Buffer(YOYO_PICTIRE *pict)
  {
    if ( pict->pixels ) 
      __Raise(YOYO_ERROR_ALREADY_EXISTS,"pixel buffer already allocated");
    
    if ( pict->format == YOYO_RGBA8_PICTURE )
      {
        pict->pitch  = sizeof(YOYO_RGBA8)*pict->width;
        pict->wight  = sizeof(YOYO_RGBA8);
      }
    else if ( pict->format == YOYO_RGBAf_PICTURE )
      {
        pict->pitch  = sizeof(YOYO_RGBAf)*pict->width;
        pict->wight  = sizeof(YOYO_RGBAf);
      }
    else
      __Raise(YOYO_ERROR_UNSUPPORTED,"pixel format unsupported");
      
    pict->pixels = __Malloc_Npl(pict->pitch*pict->height);
  }

#define Pict_From_Gif89a(Bytes,Count) Pict_From_Gif89a_Specific(Bytes,Count,YOYO_RGBA8_PICTURE)
YOYO_PICTIRE *Pict_From_Gif89a_Specific(void *bytes, int count, int format)
#ifdef _YOYO_GIF89A_BUILTIN
  {
    YOYO_PICTURE *pict = __Object_Dtor(sizeof(YOYO_PICTURE),YOYO_PICTURE_Destruct);
    int i,j;
    int ptx = 6;
    int bgcolor_idx;
    int sizeof_color_table;
    int sizeof_local_table;
    int has_local_colors;
    
    YOYO_RGBA8 color_table[256] = {0};
    YOYO_RGBA8 local_table[256] = {0};
    YOYO_RGBA8 *colors = 0;

    if ( memcmp(bytes,"GIF89a",6) && memcmp(bytes,"GIF87a",6) )
      __Raise(YOYO_ERROR_UNSUPPORTED,"is not GIF image");
    
    pict->format = format;
    pict->width  = Two_To_Unsigned(bytes+ptx); ptx += 2;
    pict->height = Two_To_Unsigned(bytes+ptx); ptx += 2;
    sizeof_color_table = 1<<((*bytes&0x07)+1);
    ++ptx; /* Packed Value */
    bgcolor_idx = bytes[ptx++];
    ++ptx; /* Pixel Aspect Ratio */
    
    for ( i = 0; i < sizeof_color_table; ++i )
      {
        color_table[i].r = bytes[ptx++];
        color_table[i].g = bytes[ptx++];
        color_table[i].b = bytes[ptx++];
      }
      
    if ( *bytes[ptx++] != 0x2c )
      __Raise(YOYO_ERROR_CORRUPTED,"expected image separator");
      
    ptx += 2; /* left */
    ptx += 2; /* top */
    pict->width  = Two_To_Unsigned(bytes+ptx); ptx += 2;
    pict->height = Two_To_Unsigned(bytes+ptx); ptx += 2;
    has_local_colors = *bytes & 0x80;
    ++ptx;
    
    if ( has_local_colors )
      {
        for ( i = 0; i < sizeof_local_table; ++i )
          {
            local_table[i].r = bytes[ptx++];
            local_table[i].g = bytes[ptx++];
            local_table[i].b = bytes[ptx++];
          }
        colors = local_table;
      }
    else
      colors = color_table;
      
    Pict_Allocate_Buffer(pict);
    
    __Gogo /* LZW decoder */
      {
        int mincodelen = bytes[ptx++];
        int codelen = mincodelen;
        int bitsread = 0;
        byte_t *pixel_ptr = pict->pixels;
        
        for (;;)
          {
            /* get n bits */
            int code = 
            
            if ( format == YOYO_RGBA8_PICTURE )
              (YOYO_RGBA8*)pixel_ptr = colors[pixel];
            else
              Pict_Set_Pixel_From_RGBA8(pixel_ptr,colors[pixel],format);
            
            pixel_ptr += pict->weight;
          }
      }
  }
#endif
  ;
#endif /* C_once_E194EBE7_E43F_4305_A75C_3872532B12DB */

Added extra/pictpng.hc.



























































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157

/*

(C)2010-2011, Alexéy Sudáchen, alexey@sudachen.name

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Except as contained in this notice, the name of a copyright holder shall not
be used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization of the copyright holder.

*/

#ifndef C_once_324CA35F_3399_4699_91FD_FC523999882D
#define C_once_324CA35F_3399_4699_91FD_FC523999882D

#include "picture.hc"

#ifdef _YOYO_PICTPNG_BUILTIN
#include <png.h>

static void Pict_From_PNG_Read_Data(png_structp png_ptr, void *dest, png_size_t count)
  {
    byte_t **p = png_ptr->io_ptr;
    if ( *p + count > p[1] ) 
      png_error(png_ptr, "png read error in Pict_From_PNG_Read_Data"); 
    memcpy(dest,*p,count);
    *p += count;
  }

#endif

#define Pict_From_PNG(Bytes,Count) Pict_From_PNG_Specific(Bytes,Count,YOYO_RGBA8_PICTURE)
YOYO_PICTURE *Pict_From_PNG_Specific(void *bytes, int count, int format)
#ifdef _YOYO_PICTPNG_BUILTIN
  {
    YOYO_PICTURE *pict = __Object_Dtor(sizeof(YOYO_PICTURE),YOYO_PICTURE_Destruct);
    pict->format = format;
    
    __Auto_Release
      {
        png_struct* png_ptr;
        png_info*   info_ptr;
        byte_t*     read_ptr[2];
        int         stride;
        byte_t     *row;
        int         jformat;
        int         i;
        
        if ( !png_check_sig(bytes,8) )
          __Raise(YOYO_ERROR_UNSUPPORTED,"is not PNG image");

        png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,0,0,0);
        info_ptr = png_create_info_struct(png_ptr);
        
        if ( !setjmp(png_jmpbuf(png_ptr)) ) 
          {
            int bpp;
            read_ptr[0] = (byte_t*)bytes+8;
            read_ptr[1] = (byte_t*)bytes+(count-8);
            png_set_read_fn(png_ptr,read_ptr,Pict_From_PNG_Read_Data);
            png_set_sig_bytes(png_ptr,8);
            png_read_info(png_ptr,info_ptr);
            png_set_strip_16(png_ptr);
            png_set_packing(png_ptr);
      
            if ( png_ptr->bit_depth < 8 
              || png_ptr->color_type == PNG_COLOR_TYPE_PALETTE
              || png_get_valid(png_ptr,info_ptr,PNG_INFO_tRNS) )
              png_set_expand(png_ptr);
      
            png_read_update_info(png_ptr,info_ptr);
            pict->width  = png_get_image_width(png_ptr,info_ptr);
            pict->height = png_get_image_height(png_ptr,info_ptr);

            if (  png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA )
              bpp = 4;
            else 
              bpp = 3;

            stride = (bpp*pict->width + 7) & ~3;
            jformat = (bpp==4?YOYO_RGBA8_PICTURE:YOYO_RGB8_PICTURE);
            if ( jformat != pict->format )
              row = __Malloc(stride);
          }
        else
          {
            if ( !setjmp(png_jmpbuf(png_ptr)) )
              png_destroy_read_struct(&png_ptr,&info_ptr,0);
            __Raise(YOYO_ERROR_CORRUPTED,"failed to decode PNG info");
          }
          
        Pict_Allocate_Buffer(pict);
        
        if ( !setjmp(png_jmpbuf(png_ptr)) ) 
          {
            for ( i = 0; i < pict->height; ++i )
              {
                if ( jformat != pict->format )
                  {
                    png_read_row(png_ptr,row,0);
                    Pict_Convert_Pixels_Row(
                      row,jformat,
                      pict->pixels+i*pict->pitch, pict->format,
                      pict->width);
                  }
                else
                  png_read_row(png_ptr,pict->pixels+i*pict->pitch,0);
              }
            //png_read_end(png_ptr,info_ptr);
          }
        else
          {
            if ( !setjmp(png_jmpbuf(png_ptr)) )
              png_destroy_read_struct(&png_ptr,&info_ptr,0);
            __Raise(YOYO_ERROR_CORRUPTED,"failed to decode PNG bits");
          }
      }
      
    return pict;
  }
#endif
  ;

#define Pict_From_PNG_File(Filename) Pict_From_PNG_File_Specific(Filename,YOYO_RGBA8_PICTURE)
YOYO_PICTURE *Pict_From_PNG_File_Specific(char *filename, int format)
#ifdef _YOYO_PICTPNG_BUILTIN
  {
    YOYO_PICTURE *pict = 0;
    __Auto_Ptr(pict)
      {
        YOYO_BUFFER *bf = Oj_Read_All(Cfile_Open(filename,"r"));
        pict = Pict_From_PNG_Specific(bf->at,bf->count,format);
      }
    return pict;
  }
#endif
  ;

#endif /* C_once_324CA35F_3399_4699_91FD_FC523999882D */

Added extra/picture.hc.













































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358

/*

(C)2010-2011, Alexéy Sudáchen, alexey@sudachen.name

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Except as contained in this notice, the name of a copyright holder shall not
be used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization of the copyright holder.

*/

#ifndef C_once_E194EBE7_E43F_4305_A75C_3872532B12DB
#define C_once_E194EBE7_E43F_4305_A75C_3872532B12DB

#include "../libyoyo.hc"

enum
  {
    YOYO_RGB8_PICTURE  = __FOUR_CHARS('R',3,'8',0),
    YOYO_RGBA8_PICTURE = __FOUR_CHARS('R',4,'8','A'),
    YOYO_BGR8_PICTURE  = __FOUR_CHARS('B',3,'8',0),
    YOYO_BGRA8_PICTURE = __FOUR_CHARS('B',4,'8','A'),
    YOYO_RGBAf_PICTURE = __FOUR_CHARS('R',16,'f','A'),
  };

typedef struct _YOYO_PICTURE
  {
    int width;
    int height;
    int pitch;
    int weight;
    int format;
    byte_t *pixels;
  } YOYO_PICTURE;

void YOYO_PICTURE_Destruct(YOYO_PICTURE *pict)
#ifdef _YOYO_PICTURE_BUILTIN
  {
    free(pict->pixels);
    __Destruct(pict);
  }
#endif
  ;

typedef struct _YOYO_RGBA8
  {
    byte_t r;
    byte_t g;
    byte_t b;
    byte_t a;
  } YOYO_RGBA8;

typedef struct _YOYO_BGRA8
  {
    byte_t b;
    byte_t g;
    byte_t r;
    byte_t a;
  } YOYO_BGRA8;

typedef struct _YOYO_RGBAf
  {
    float r;
    float g;
    float b;
    float a;
  } YOYO_RGBAf;

typedef struct _YOYO_RGB8
  {
    byte_t r;
    byte_t g;
    byte_t b;
  } YOYO_RGB8;

typedef struct _YOYO_BGR8
  {
    byte_t b;
    byte_t g;
    byte_t r;
  } YOYO_BGR8;

//YOYO_PICTURE *Pict_Convert(YOYO_PICTURE *pict, int format)
//  {
//  }

#ifdef __windoze
HBITMAP Pict_Create_HBITMAP(YOYO_PICTURE *pict)
#ifdef _YOYO_PICTURE_BUILTIN
  {
    struct BI
      {
        BITMAPINFOHEADER ihdr;
        RGBQUAD quad[4];
      } bi = { {0}, {{0xff,0,0,0},{0,0xff,0,0}, {0,0,0xff,0}, {0,0,0,0xff}} };
    HDC dc;
    HBITMAP bmp;
    bi.ihdr.biSize = sizeof(BITMAPINFOHEADER);
    bi.ihdr.biWidth  = pict->width;
    bi.ihdr.biHeight = -pict->height;
    bi.ihdr.biPlanes = 1;
    bi.ihdr.biBitCount = pict->weight*8;
    bi.ihdr.biCompression = BI_BITFIELDS;
    bi.ihdr.biSizeImage = 0;
    if ( (pict->format & 0xff) == 'B' ) 
      {
        RGBQUAD quad[3] = {{0,0,0xff,0},{0,0xff,0,0},{0xff,0,0,0}};
        memcpy(bi.quad,quad,sizeof(quad));
      }
    dc  = GetDC(0);
    bmp = CreateCompatibleBitmap(dc,pict->width,pict->height);
    SetDIBits(dc,bmp,0,pict->height,pict->pixels,(BITMAPINFO*)&bi,DIB_RGB_COLORS);
    ReleaseDC(0,dc);
    return bmp;
  }
#endif
  ;
#endif

YOYO_RGBA8 Pict_Get_RGBA8_Pixel(byte_t *ptr, int format)
#ifdef _YOYO_PICTURE_BUILTIN
  {
    if ( format == YOYO_RGBA8_PICTURE )
      return *(YOYO_RGBA8*)ptr;
    else if ( format == YOYO_RGB8_PICTURE )
      {
        YOYO_RGBA8 rgba;
        rgba.r = ((YOYO_RGB8*)ptr)->r;
        rgba.g = ((YOYO_RGB8*)ptr)->g;
        rgba.b = ((YOYO_RGB8*)ptr)->b;
        rgba.a = 0;
        return rgba;
      }
    else if ( format == YOYO_BGR8_PICTURE )
      {
        YOYO_RGBA8 rgba;
        rgba.r = ((YOYO_BGR8*)ptr)->r;
        rgba.g = ((YOYO_BGR8*)ptr)->g;
        rgba.b = ((YOYO_BGR8*)ptr)->b;
        rgba.a = 0;
        return rgba;
      }
    else if ( format == YOYO_BGRA8_PICTURE )
      {
        YOYO_RGBA8 rgba;
        rgba.r = ((YOYO_BGRA8*)ptr)->r;
        rgba.g = ((YOYO_BGRA8*)ptr)->g;
        rgba.b = ((YOYO_BGRA8*)ptr)->b;
        rgba.a = ((YOYO_BGRA8*)ptr)->a;
        return rgba;
      }
    else if ( format == YOYO_RGBAf_PICTURE )
      {
        YOYO_RGBA8 rgba;
        rgba.r = (byte_t)(Yo_MAX(((YOYO_RGBAf*)ptr)->r + .5f ,1.f) * 255.f);
        rgba.g = (byte_t)(Yo_MAX(((YOYO_RGBAf*)ptr)->g + .5f ,1.f) * 255.f);
        rgba.b = (byte_t)(Yo_MAX(((YOYO_RGBAf*)ptr)->b + .5f ,1.f) * 255.f);
        rgba.a = (byte_t)(Yo_MAX(((YOYO_RGBAf*)ptr)->a + .5f ,1.f) * 255.f);
        return rgba;
      }
    else
      {
        YOYO_RGBA8 rgba = {0};
        __Raise(YOYO_ERROR_UNSUPPORTED,"bad pixel format");
        return rgba;
      }
  }
#endif
  ;

YOYO_RGBA8 Pict_Get_RGBA8(YOYO_PICTURE *pict, int x, int y)
#ifdef _YOYO_PICTURE_BUILTIN
  {
    byte_t *ptr = pict->pixels + (pict->pitch * y + x * pict->weight);
    
    if ( pict->format == YOYO_RGBA8_PICTURE )
      return *(YOYO_RGBA8*)ptr;
    
    return Pict_Get_RGBA8_Pixel(ptr, pict->format);
  }
#endif
  ;

YOYO_RGBAf Pict_Get_RGBAf_Pixel(byte_t *ptr, int format)
#ifdef _YOYO_PICTURE_BUILTIN
  {
    if ( format == YOYO_RGBAf_PICTURE )
      return *(YOYO_RGBAf*)ptr;
    else if ( format == YOYO_RGBA8_PICTURE )
      {
        YOYO_RGBAf rgba;
        rgba.r = (((YOYO_RGBA8*)ptr)->r + .5f) / 255.f;
        rgba.g = (((YOYO_RGBA8*)ptr)->g + .5f) / 255.f;
        rgba.b = (((YOYO_RGBA8*)ptr)->b + .5f) / 255.f;
        rgba.a = (((YOYO_RGBA8*)ptr)->a + .5f) / 255.f;
        return rgba;
      }
    else
      {
        YOYO_RGBA8 tmp = Pict_Get_RGBA8_Pixel(ptr,format);
        YOYO_RGBAf rgba;
        rgba.r = (tmp.r + .5f) / 255.f;
        rgba.g = (tmp.g + .5f) / 255.f;
        rgba.b = (tmp.b + .5f) / 255.f;
        rgba.a = (tmp.a + .5f) / 255.f;
        return rgba;
      }
  }
#endif
  ;

void Pict_Set_RGBA8_Pixel(byte_t *ptr, YOYO_RGBA8 pix, int format)
#ifdef _YOYO_PICTURE_BUILTIN
  {
    if ( format == YOYO_RGBA8_PICTURE )
      *(YOYO_RGBA8*)ptr = pix;
    else if ( format == YOYO_RGB8_PICTURE )
      {
        ((YOYO_RGB8*)ptr)->r = pix.r;
        ((YOYO_RGB8*)ptr)->g = pix.g;
        ((YOYO_RGB8*)ptr)->b = pix.b;
      }
    else if ( format == YOYO_BGRA8_PICTURE )
      {
        ((YOYO_BGRA8*)ptr)->r = pix.r;
        ((YOYO_BGRA8*)ptr)->g = pix.g;
        ((YOYO_BGRA8*)ptr)->b = pix.b;
        ((YOYO_BGRA8*)ptr)->a = pix.a;
      }
    else if ( format == YOYO_BGR8_PICTURE )
      {
        ((YOYO_BGR8*)ptr)->r = pix.r;
        ((YOYO_BGR8*)ptr)->g = pix.g;
        ((YOYO_BGR8*)ptr)->b = pix.b;
      }
    else if ( format == YOYO_RGBAf_PICTURE )
      {
        ((YOYO_RGBAf*)ptr)->r = (pix.r + .5f) / 255.f;
        ((YOYO_RGBAf*)ptr)->g = (pix.g + .5f) / 255.f;
        ((YOYO_RGBAf*)ptr)->b = (pix.b + .5f) / 255.f;
        ((YOYO_RGBAf*)ptr)->a = (pix.a + .5f) / 255.f;
      }
    else
      __Raise(YOYO_ERROR_UNSUPPORTED,"bad pixel format");
  }
#endif
  ;

void Pict_Set_RGBA8(YOYO_PICTURE *pict, int x, int y, YOYO_RGBA8 pix)
#ifdef _YOYO_PICTURE_BUILTIN
  {
    byte_t *ptr = pict->pixels + (pict->pitch * y + x * pict->weight);
    
    if ( pict->format == YOYO_RGBA8_PICTURE )
      *(YOYO_RGBA8*)ptr = pix;
    
    Pict_Set_RGBA8_Pixel(pict->pixels + (pict->pitch * y + x * pict->weight), pix, pict->format);
  }
#endif
  ;

void Pict_Allocate_Buffer(YOYO_PICTURE *pict)
#ifdef _YOYO_PICTURE_BUILTIN
  {
    if ( pict->pixels ) 
      __Raise(YOYO_ERROR_ALREADY_EXISTS,"pixel buffer already exists");
    
    if ( pict->format == YOYO_RGBA8_PICTURE )
      {
        pict->pitch  = sizeof(YOYO_RGBA8)*pict->width;
        pict->weight = sizeof(YOYO_RGBA8);
      }
    else if ( pict->format == YOYO_RGBAf_PICTURE )
      {
        pict->pitch  = sizeof(YOYO_RGBAf)*pict->width;
        pict->weight = sizeof(YOYO_RGBAf);
      }
    else if ( pict->format == YOYO_RGB8_PICTURE )
      {
        pict->pitch  = sizeof(YOYO_RGB8)*pict->width;
        pict->weight = sizeof(YOYO_RGB8);
      }
    else if ( pict->format == YOYO_BGR8_PICTURE )
      {
        pict->pitch  = sizeof(YOYO_BGR8)*pict->width;
        pict->weight = sizeof(YOYO_BGR8);
      }
    else if ( pict->format == YOYO_BGRA8_PICTURE )
      {
        pict->pitch  = sizeof(YOYO_BGRA8)*pict->width;
        pict->weight = sizeof(YOYO_BGRA8);
      }
    else
      __Raise(YOYO_ERROR_UNSUPPORTED,"bad pixel format");
      
    pict->pixels = __Malloc_Npl(pict->pitch*pict->height);
  }
#endif
  ;
  
void Pict_Convert_Pixels_Row(byte_t *src, int src_format, byte_t *dst, int dst_format, int count )
#ifdef _YOYO_PICTURE_BUILTIN
  {
    int i;
    int src_weight = ((src_format >> 8) & 0x0ff);
    int dst_weight = ((dst_format >> 8) & 0x0ff);
    byte_t *src_pixel = src;
    byte_t *dst_pixel = dst;
    if ( src_format == dst_format )
      {
        memcpy(dst,src,count*dst_weight);
      }
    else if ( dst_format  == YOYO_RGBAf_PICTURE )
      for ( i = 0; i < count; ++i )
        {
          *(YOYO_RGBAf*)dst_pixel = Pict_Get_RGBAf_Pixel(src_pixel,src_format);
          src_pixel += src_weight;
          dst_pixel += dst_weight;
        }
    else if ( dst_format  == YOYO_RGBA8_PICTURE )
      for ( i = 0; i < count; ++i )
        {
          *(YOYO_RGBA8*)dst_pixel = Pict_Get_RGBA8_Pixel(src_pixel,src_format);
          src_pixel += src_weight;
          dst_pixel += dst_weight;
        }
    else
      for ( i = 0; i < count; ++i )
        {
          YOYO_RGBA8 tmp = Pict_Get_RGBA8_Pixel(src_pixel,src_format);
          Pict_Set_RGBA8_Pixel(dst_pixel,tmp,dst_format);
          src_pixel += src_weight;
          dst_pixel += dst_weight;
        }
  }
#endif
  ;
  
#endif /* C_once_E194EBE7_E43F_4305_A75C_3872532B12DB */

Changes to file.hc.

50
51
52
53
54
55
56


57
58
59
60
61
62
63

64
65
66
67
68
69
70
71
72


73
74
75
76
77
78
79
80
81
82
83
84
85
86
87

88
89
90
91
92
93
94
...
178
179
180
181
182
183
184
























185
186
187
188
189
190
191
...
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
...
314
315
316
317
318
319
320
321
322
323
324


325
326

327
328
329
330
331
332
333
...
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553



















554
555
556
557
558
559
560
...
573
574
575
576
577
578
579
580










581
582
583
584
585
586
587
...
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
...
829
830
831
832
833
834
835
836




837



838
839


























840
841
842
843
844
845
846
...
909
910
911
912
913
914
915
916























917
918
919
920
921
922
923
...
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
....
1046
1047
1048
1049
1050
1051
1052
























1053
1054
1055
1056
1057
1058
1059
....
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
....
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298


























































































































































1299
1300
# define _YOYO_FILE_EXTERN extern
#endif

char *Path_Basename(char *path)
#ifdef _YOYO_FILE_BUILTIN
  {
    char *ret = path;


    char *p = strrchr(path,'/');
  #ifdef __windoze
    char *p2 = strrchr(path,'\\');
    if ( !p || p < p2 ) p = p2;
  #endif
    if ( p )
      ret = Str_Copy(p+1,-1);

    return ret;
  }
#endif
  ;

char *Path_Dirname(char *path)
#ifdef _YOYO_FILE_BUILTIN
  {
    char *ret = 0;


    char *p = strrchr(path,'/');
  #ifdef __windoze
    char *p2 = strrchr(path,'\\');
    if ( !p || p < p2 ) p = p2;
  #endif
    if ( p )
      {
        if ( p-path > 0 )
          ret = Str_Copy(path,p-path);
        else
        #ifdef __windoze
          ret = Str_Copy("\\",1);
        #else
          ret = Str_Copy("/",1);
        #endif

      }
    return ret;
  }
#endif
  ;

char *Current_Directory()
................................................................................
    if ( p && *p == '.' )
      ret = Str_Copy(p,-1);
    return ret;
  }
#endif
  ;

























char *Path_Fullname(char *path)
#ifdef _YOYO_FILE_BUILTIN
  {
  #ifdef __windoze
    if ( path )
      {
        wchar_t *foo;
................................................................................
        S_IXUSR = _S_IEXEC,
      };
  #endif  
#else
  typedef struct stat _YOYO_stat;
#endif        

YOYO_FILE_STATS *File_Translate_Filestats(_YOYO_stat *fst,YOYO_FILE_STATS *st)
#ifdef _YOYO_FILE_BUILTIN
  {
    if ( !st ) st = Yo_Malloc(sizeof(YOYO_FILE_STATS));
    memset(st,0,sizeof(*st));

    st->f.exists = fst->st_mode?1:0;
    st->f.is_regular   = (fst->st_mode&S_IFMT) == S_IFREG;
    st->f.is_directory = (fst->st_mode&S_IFMT) == S_IFDIR;
  #ifndef __windoze  
    st->f.is_symlink = (fst->st_mode&S_IFMT) == S_IFLNK;    
    st->f.is_unisok  = (fst->st_mode&S_IFMT) == S_IFSOCK;
  #endif  
    st->f.is_writable = (fst->st_mode&S_IWUSR) != 0;
    st->f.is_readable = (fst->st_mode&S_IRUSR) != 0;
    st->f.is_executable = (fst->st_mode&S_IXUSR) != 0;
    st->length = fst->st_size;
    st->ctime  = fst->st_ctime;
    st->mtime  = fst->st_mtime;
    
    return st;
  }
................................................................................
      err = _wstat64(uni_name,&fst);
    #else
      err = _wstat(uni_name,&fst);
    #endif
    Yo_Release(uni_name);
  #else
    err = stat(name,&fst);
  #endif        
    if ( !err || ignorerr )
      File_Translate_Filestats(&fst,st);
    if ( err && !ignorerr )              


      if ( errno != ENOENT && errno != ENOTDIR )
        File_Check_Error("getting stats",0,name,1); 

    return st;
  }
#endif
  ;

YOYO_FILE_STATS *File_Get_Stats_Reuse(char *name, YOYO_FILE_STATS **stp)
#ifdef _YOYO_FILE_BUILTIN
................................................................................
        ,__Yo_FILE__,__LINE__);
    return 1;
  }
#endif
  ;

_YOYO_FILE_EXTERN char Oj_Close_OjMID[] _YOYO_FILE_BUILTIN_CODE( = "close/@"); 
void Oj_Close(void *f) _YOYO_FILE_BUILTIN_CODE(
  { ((void(*)(void*))Yo_Find_Method_Of(&f,Oj_Close_OjMID,YO_RAISE_ERROR))
        (f); });

void Cfile_Close(YOYO_CFILE *f)
#ifdef _YOYO_FILE_BUILTIN
  {
    if ( f->fd )
      {
        fclose(f->fd);
        f->fd = 0;
      }



















  }
#endif
  ;

_YOYO_FILE_EXTERN char Oj_Flush_OjMID[] _YOYO_FILE_BUILTIN_CODE( = "flush/@"); 
void Oj_Flush(void *f) _YOYO_FILE_BUILTIN_CODE(
  { ((void(*)(void*))Yo_Find_Method_Of(&f,Oj_Flush_OjMID,YO_RAISE_ERROR))
................................................................................
  ;

void Cfile_Destruct(YOYO_CFILE *f)
#ifdef _YOYO_FILE_BUILTIN
  {
    Cfile_Close(f);
    free(f->name);
    Yo_Object_Destruct(f);










  }
#endif
  ;

YOYO_FILE_STATS *Cfile_Stats(YOYO_CFILE *f,YOYO_FILE_STATS *st)
#ifdef _YOYO_FILE_BUILTIN
  {
................................................................................
          err = _fstat(fileno(f->fd),&fst);
        #endif
      #else
        err = fstat(fileno(f->fd),&fst);
      #endif        
        if ( err )
          File_Check_Error("getting stats",f->fd,f->name,0); 
        return File_Translate_Filestats(&fst,st);
      }
    return 0;
  };
#endif
  ;

_YOYO_FILE_EXTERN char Oj_Eof_OjMID[] _YOYO_FILE_BUILTIN_CODE( = "eof/@"); 
................................................................................
      }
    return 0;
  }
#endif
  ;

_YOYO_FILE_EXTERN char Oj_Read_All_OjMID[] _YOYO_FILE_BUILTIN_CODE( = "readall/@"); 
YOYO_BUFFER *Oj_Read_All(void *f) _YOYO_FILE_BUILTIN_CODE(




  { return 



      ((void *(*)(void*))Yo_Find_Method_Of(&f,Oj_Read_All_OjMID,YO_RAISE_ERROR))
        (f); });



























YOYO_BUFFER *Cfile_Read_All(YOYO_CFILE *f)
#ifdef _YOYO_FILE_BUILTIN
  {
    if ( Raise_If_Cfile_Is_Not_Opened(f) )
      {
        void *L;
................................................................................
        {Oj_Available_OjMID,   Cfile_Available},
        {Oj_Eof_OjMID,         Cfile_Eof},
        {Oj_Flush_OjMID,       Cfile_Flush},
        {0}};
    YOYO_CFILE *f = Yo_Object(sizeof(YOYO_CFILE),funcs);
    f->fd = fd;
    f->shared = share;
    f->name = name?Str_Copy_Npl(name,-1):"<file>";























    return f;
  }
#endif
  ;

enum _YOYO_FILE_ACCESS_FLAGS
  {
................................................................................
    File_Get_Stats(path,&st,0);

    if ( (access & YOYO_FILE_CREATE_PATH) && !st.f.exists )
      Create_Required_Dirs(path);
      
    if ( st.f.exists )
      if (st.f.is_directory )
        Yo_Raise(YOYO_ERROR_IO,
          Yo_Format("file '%s' is directory",path),__Yo_FILE__,__LINE__);
      else if ( (access & YOYO_FILE_CREATE_MASK) == YOYO_FILE_CREATENEW  )
        Yo_Raise(YOYO_ERROR_IO,
          Yo_Format("file '%s' already exists",path),__Yo_FILE__,__LINE__);
      else if ( (access & YOYO_FILE_CREATE_MASK) == YOYO_FILE_CREATEALWAYS )
        File_Unlink(path,0);
      else;
    else if ( (access & YOYO_FILE_CREATE_MASK) == YOYO_FILE_OPENEXISTS )
      Yo_Raise(YOYO_ERROR_DOESNT_EXIST,
        Yo_Format("file '%s' does not exist",path),__Yo_FILE__,__LINE__);
  }
#endif
  ;

uint_t File_Access_From_Str(char *S)
#ifdef _YOYO_FILE_BUILTIN
  {
................................................................................
    #endif
        f = Cfile_Object(f,name,0);
        
    return f;
  }
#endif
  ;

























void *Cfile_Open(char *name, char *access)
#ifdef _YOYO_FILE_BUILTIN
  {
    void *f = 0;
    __Auto_Ptr(f)
      {
................................................................................

void __Pfd_Lock_In(int *pfd) 
#ifdef _YOYO_FILE_BUILTIN
  {
    STRICT_REQUIRE(pfd);
    
    if ( flock(*pfd,LOCK_EX) )
      __Raise(YOYO_ERROR_IO,"failed to lock file");
  }
#endif
  ;

void __Pfd_Lock_Out(int *pfd) 
#ifdef _YOYO_FILE_BUILTIN
  {
................................................................................
          File_Unlink(old_name,0);
        }
    else if ( err < 0 )
      {
        File_Check_Error("rename",0,old_name,1); 
      }
  }
#endif
  ;



























































































































































#endif /* C_once_E9479D04_5D69_4A1A_944F_0C99A852DC0B */








>
>
|
|
|
|
|
|
|
>









>
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|





|



|
|

|
|







 







|

|

>
>
|
|
>







 







|
|


|







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|
>
>
>
>
>
>
>
>
>
>







 







|







 







|
>
>
>
>
|
>
>
>
|
<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







<
|

<
|




|
<







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







 










>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
...
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
...
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
...
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
...
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
...
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
...
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
...
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907

908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
....
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
....
1067
1068
1069
1070
1071
1072
1073

1074
1075

1076
1077
1078
1079
1080
1081

1082
1083
1084
1085
1086
1087
1088
....
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
....
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
....
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
# define _YOYO_FILE_EXTERN extern
#endif

char *Path_Basename(char *path)
#ifdef _YOYO_FILE_BUILTIN
  {
    char *ret = path;
    if ( path )
      {
        char *p = strrchr(path,'/');
      #ifdef __windoze
        char *p2 = strrchr(path,'\\');
        if ( !p || p < p2 ) p = p2;
      #endif
        if ( p )
          ret = Str_Copy(p+1,-1);
      }
    return ret;
  }
#endif
  ;

char *Path_Dirname(char *path)
#ifdef _YOYO_FILE_BUILTIN
  {
    char *ret = 0;
    if ( path )
      {
        char *p = strrchr(path,'/');
      #ifdef __windoze
        char *p2 = strrchr(path,'\\');
        if ( !p || p < p2 ) p = p2;
      #endif
        if ( p )
          {
            if ( p-path > 0 )
              ret = Str_Copy(path,p-path);
            else
            #ifdef __windoze
              ret = Str_Copy("\\",1);
            #else
              ret = Str_Copy("/",1);
            #endif
          }
      }
    return ret;
  }
#endif
  ;

char *Current_Directory()
................................................................................
    if ( p && *p == '.' )
      ret = Str_Copy(p,-1);
    return ret;
  }
#endif
  ;

char *Path_Unsuffix(char *path)
#ifdef _YOYO_FILE_BUILTIN
  {
    char *ret = 0;
    char *p = strrchr(path,'.');
    if ( p )
      {
        char *p1 = strrchr(path,'/');
        if ( p1 && p1 > p ) p = p1;
      #ifdef __windoze
        __Gogo 
          {
            char *p2 = strrchr(path,'\\');
            if ( p2 && p2 > p ) p = p2;
          }
      #endif
      }
    if ( p && *p == '.' )
      ret = Str_Copy(path,p-path);
    return ret;
  }
#endif
  ;
  
char *Path_Fullname(char *path)
#ifdef _YOYO_FILE_BUILTIN
  {
  #ifdef __windoze
    if ( path )
      {
        wchar_t *foo;
................................................................................
        S_IXUSR = _S_IEXEC,
      };
  #endif  
#else
  typedef struct stat _YOYO_stat;
#endif        

YOYO_FILE_STATS *File_Translate_Filestats(_YOYO_stat *fst,YOYO_FILE_STATS *st,int exists)
#ifdef _YOYO_FILE_BUILTIN
  {
    if ( !st ) st = Yo_Malloc(sizeof(YOYO_FILE_STATS));
    memset(st,0,sizeof(*st));

    st->f.exists       = exists;
    st->f.is_regular   = (fst->st_mode&S_IFMT) == S_IFREG;
    st->f.is_directory = (fst->st_mode&S_IFMT) == S_IFDIR;
  #ifndef __windoze  
    st->f.is_symlink   = (fst->st_mode&S_IFMT) == S_IFLNK;    
    st->f.is_unisok    = (fst->st_mode&S_IFMT) == S_IFSOCK;
  #endif  
    st->f.is_writable  = (fst->st_mode&S_IWUSR) != 0;
    st->f.is_readable  = (fst->st_mode&S_IRUSR) != 0;
    st->f.is_executable = (fst->st_mode&S_IXUSR) != 0;
    st->length = fst->st_size;
    st->ctime  = fst->st_ctime;
    st->mtime  = fst->st_mtime;
    
    return st;
  }
................................................................................
      err = _wstat64(uni_name,&fst);
    #else
      err = _wstat(uni_name,&fst);
    #endif
    Yo_Release(uni_name);
  #else
    err = stat(name,&fst);
  #endif
    if ( !err || ignorerr )
      File_Translate_Filestats(&fst,st,!err);
    if ( err && !ignorerr )              
      {
        if ( st ) memset(st,0,sizeof(*st));
        if ( errno != ENOENT && errno != ENOTDIR )
          File_Check_Error("getting stats",0,name,1); 
      }
    return st;
  }
#endif
  ;

YOYO_FILE_STATS *File_Get_Stats_Reuse(char *name, YOYO_FILE_STATS **stp)
#ifdef _YOYO_FILE_BUILTIN
................................................................................
        ,__Yo_FILE__,__LINE__);
    return 1;
  }
#endif
  ;

_YOYO_FILE_EXTERN char Oj_Close_OjMID[] _YOYO_FILE_BUILTIN_CODE( = "close/@"); 
int Oj_Close(void *f) _YOYO_FILE_BUILTIN_CODE(
  { return ((int(*)(void*))Yo_Find_Method_Of(&f,Oj_Close_OjMID,YO_RAISE_ERROR))
        (f); });

int Cfile_Close(YOYO_CFILE *f)
#ifdef _YOYO_FILE_BUILTIN
  {
    if ( f->fd )
      {
        fclose(f->fd);
        f->fd = 0;
      }
    return 0;
  }
#endif
  ;

int Pfile_Close(YOYO_CFILE *f)
#ifdef _YOYO_FILE_BUILTIN
  {
    int ret = 0;
    if ( f->fd )
      {
      #ifdef __windoze
        ret = _pclose(f->fd);
      #else
        ret = pclose(f->fd);
      #endif
        f->fd = 0;
      }
    return ret;
  }
#endif
  ;

_YOYO_FILE_EXTERN char Oj_Flush_OjMID[] _YOYO_FILE_BUILTIN_CODE( = "flush/@"); 
void Oj_Flush(void *f) _YOYO_FILE_BUILTIN_CODE(
  { ((void(*)(void*))Yo_Find_Method_Of(&f,Oj_Flush_OjMID,YO_RAISE_ERROR))
................................................................................
  ;

void Cfile_Destruct(YOYO_CFILE *f)
#ifdef _YOYO_FILE_BUILTIN
  {
    Cfile_Close(f);
    free(f->name);
    __Destruct(f);
  }
#endif
  ;

void Pfile_Destruct(YOYO_CFILE *f)
#ifdef _YOYO_FILE_BUILTIN
  {
    Pfile_Close(f);
    free(f->name);
    __Destruct(f);
  }
#endif
  ;

YOYO_FILE_STATS *Cfile_Stats(YOYO_CFILE *f,YOYO_FILE_STATS *st)
#ifdef _YOYO_FILE_BUILTIN
  {
................................................................................
          err = _fstat(fileno(f->fd),&fst);
        #endif
      #else
        err = fstat(fileno(f->fd),&fst);
      #endif        
        if ( err )
          File_Check_Error("getting stats",f->fd,f->name,0); 
        return File_Translate_Filestats(&fst,st,!err);
      }
    return 0;
  };
#endif
  ;

_YOYO_FILE_EXTERN char Oj_Eof_OjMID[] _YOYO_FILE_BUILTIN_CODE( = "eof/@"); 
................................................................................
      }
    return 0;
  }
#endif
  ;

_YOYO_FILE_EXTERN char Oj_Read_All_OjMID[] _YOYO_FILE_BUILTIN_CODE( = "readall/@"); 
YOYO_BUFFER *Oj_Read_All(void *f)
#ifdef _YOYO_FILE_BUILTIN
  {
    void *(*readall)(void*) = Yo_Find_Method_Of(&f,Oj_Read_All_OjMID,0);
    if ( readall )
      return readall(f);
    else
      {
        quad_t (*available)(void*) = Yo_Find_Method_Of(&f,Oj_Available_OjMID,0);
        int (*read)(void*,void*,int,int) = Yo_Find_Method_Of(&f,Oj_Read_OjMID,YO_RAISE_ERROR);

        void *L;
        if ( available )
          {
            quad_t len = available(f);
            if ( len > INT_MAX )
              __Raise(YOYO_ERROR_IO,"file to big to be read in one pass");
            L = Buffer_Init((int)len);
            if ( len )
              read(f,Buffer_Begin(L),(int)len,(int)len);
          }
        else
          {
            int (*eof)(void*) = Yo_Find_Method_Of(&f,Oj_Eof_OjMID,YO_RAISE_ERROR);
            L = Buffer_Init(0);
            while ( !eof(f) )
              {
                byte_t local[1024];
                int q  = read(f,local,sizeof(local),0);
                if ( q > 0 ) Buffer_Append(L,local,q);
              }
          }
        return L;
      }
  }
#endif
  ;

YOYO_BUFFER *Cfile_Read_All(YOYO_CFILE *f)
#ifdef _YOYO_FILE_BUILTIN
  {
    if ( Raise_If_Cfile_Is_Not_Opened(f) )
      {
        void *L;
................................................................................
        {Oj_Available_OjMID,   Cfile_Available},
        {Oj_Eof_OjMID,         Cfile_Eof},
        {Oj_Flush_OjMID,       Cfile_Flush},
        {0}};
    YOYO_CFILE *f = Yo_Object(sizeof(YOYO_CFILE),funcs);
    f->fd = fd;
    f->shared = share;
    f->name = name?Str_Copy_Npl(name,-1):__yoTa("<file>",0);
    return f;
  }
#endif
  ;

YOYO_CFILE *Pfile_Object(FILE *fd, char *cmd, int share)
#ifdef _YOYO_FILE_BUILTIN
  {
    static YOYO_FUNCTABLE funcs[] = 
      { {0},
        {Oj_Destruct_OjMID,    Pfile_Destruct},
        {Oj_Close_OjMID,       Pfile_Close},
        {Oj_Read_OjMID,        Cfile_Read},
        {Oj_Write_OjMID,       Cfile_Write},
        {Oj_Read_Line_OjMID,   Cfile_Read_Line},
        {Oj_Write_Line_OjMID,  Cfile_Write_Line},
        {Oj_Eof_OjMID,         Cfile_Eof},
        {Oj_Flush_OjMID,       Cfile_Flush},
        {0}};
    YOYO_CFILE *f = Yo_Object(sizeof(YOYO_CFILE),funcs);
    f->fd = fd;
    f->shared = share;
    f->name = cmd?Str_Copy_Npl(cmd,-1):__yoTa("<command>",0);
    return f;
  }
#endif
  ;

enum _YOYO_FILE_ACCESS_FLAGS
  {
................................................................................
    File_Get_Stats(path,&st,0);

    if ( (access & YOYO_FILE_CREATE_PATH) && !st.f.exists )
      Create_Required_Dirs(path);
      
    if ( st.f.exists )
      if (st.f.is_directory )

        __Raise_Format(YOYO_ERROR_IO,("file '%s' is directory",path));
      else if ( (access & YOYO_FILE_CREATE_MASK) == YOYO_FILE_CREATENEW  )

        __Raise_Format(YOYO_ERROR_IO,("file '%s' already exists",path));
      else if ( (access & YOYO_FILE_CREATE_MASK) == YOYO_FILE_CREATEALWAYS )
        File_Unlink(path,0);
      else;
    else if ( (access & YOYO_FILE_CREATE_MASK) == YOYO_FILE_OPENEXISTS )
      __Raise_Format(YOYO_ERROR_DOESNT_EXIST,("file '%s' does not exist",path));

  }
#endif
  ;

uint_t File_Access_From_Str(char *S)
#ifdef _YOYO_FILE_BUILTIN
  {
................................................................................
    #endif
        f = Cfile_Object(f,name,0);
        
    return f;
  }
#endif
  ;

void *Pfile_Open(char *command, char *access)
#ifdef _YOYO_FILE_BUILTIN
  {
    void *f = 0;
    #ifdef __windoze
      int text = 0, i;
      wchar_t ac[9] = {0};
      for ( i = 0; access[i] && i < sizeof(ac)-1; ++i )
        {
          if ( access[i] == 't' ) text = 1;
          if ( access[i] == 'b' ) text = 2;
          ac[i] = access[i];
        }
      if ( !text && i < sizeof(ac)-1 ) ac[i] = 'b'; 
      if ( 0 != (f = _wpopen(Str_Utf8_To_Unicode(command),ac)) )
    #else
      if ( 0 != (f = popen(command,access)) )
    #endif
        f = Pfile_Object(f,command,0);
    return f;
  }
#endif
  ;

void *Cfile_Open(char *name, char *access)
#ifdef _YOYO_FILE_BUILTIN
  {
    void *f = 0;
    __Auto_Ptr(f)
      {
................................................................................

void __Pfd_Lock_In(int *pfd) 
#ifdef _YOYO_FILE_BUILTIN
  {
    STRICT_REQUIRE(pfd);
    
    if ( flock(*pfd,LOCK_EX) )
      __Raise_Format(YOYO_ERROR_IO,("failed to lock fd %d: %s",*pfd,strerror(errno)));
  }
#endif
  ;

void __Pfd_Lock_Out(int *pfd) 
#ifdef _YOYO_FILE_BUILTIN
  {
................................................................................
          File_Unlink(old_name,0);
        }
    else if ( err < 0 )
      {
        File_Check_Error("rename",0,old_name,1); 
      }
  }
#endif
  ;

typedef struct _YOYO_BUFFER_FILE
  {
    YOYO_BUFFER *bf;
    int offs;
  } YOYO_BUFFER_FILE;

void YOYO_BUFFER_FILE_Destruct(YOYO_BUFFER_FILE *file)
#ifdef _YOYO_FILE_BUILTIN
  {
    __Unrefe(file->bf);
    __Destruct(file);
  }
#endif
  ;

int Buffer_File_Close(YOYO_BUFFER_FILE *file)
#ifdef _YOYO_FILE_BUILTIN
  {
    return 0;
  }
#endif
  ;

int Buffer_File_Read(YOYO_BUFFER_FILE *f, void *buf, int count, int min_count)
#ifdef _YOYO_FILE_BUILTIN
  {
    if ( min_count < 0 ) min_count = count;
    if ( f->offs + min_count > f->bf->count )
      __Raise(YOYO_ERROR_IO_EOF,"end of file");
    count = Yo_MIN(f->bf->count-f->offs,count);
    memcpy(buf,f->bf->at+f->offs,count);
    f->offs += count;
    return count;
  }
#endif
  ;

int Buffer_File_Write(YOYO_BUFFER_FILE *f, void *buf, int count, int min_count)
#ifdef _YOYO_FILE_BUILTIN
  {
    if (f->bf->count < f->offs + count )
      Buffer_Resize(f->bf,f->offs + count);
    memcpy(f->bf->at+f->offs,buf,count);
    f->offs += count;
    return count;
  }
#endif
  ;

quad_t Buffer_File_Length(YOYO_BUFFER_FILE *f)
#ifdef _YOYO_FILE_BUILTIN
  {
    return f->bf->count;
  }
#endif
  ;

quad_t Buffer_File_Available(YOYO_BUFFER_FILE *f)
#ifdef _YOYO_FILE_BUILTIN
  {
    if ( f->offs >= f->bf->count )
      return 0;
    return f->bf->count - f->offs;
  }
#endif
  ;

int Buffer_File_Eof(YOYO_BUFFER_FILE *f)
#ifdef _YOYO_FILE_BUILTIN
  {
    if ( f->offs >= f->bf->count )
      return 1;
    return 0;
  }
#endif
  ;

quad_t Buffer_File_Seek(YOYO_BUFFER_FILE *f, quad_t pos, int whence)
#ifdef _YOYO_FILE_BUILTIN
  {
    quad_t old = f->offs;
    if ( whence == SEEK_SET )
      f->offs = pos;
    else if ( whence == SEEK_CUR )
      f->offs += pos;
    else if ( whence == SEEK_END )
      f->offs = f->bf->count + pos;
    if ( f->offs < 0 ) 
      {
        f->offs = 0;
        __Raise(YOYO_ERROR_IO,"negative file offset");
      }
    return old;
  }
#endif
  ;
  
quad_t Buffer_File_Tell(YOYO_BUFFER_FILE *f)
#ifdef _YOYO_FILE_BUILTIN
  {
    return f->offs;
  }
#endif
  ;

void *Buffer_As_File(YOYO_BUFFER *bf)
#ifdef _YOYO_FILE_BUILTIN
  {
    static YOYO_FUNCTABLE funcs[] = 
      { {0},
        {Oj_Destruct_OjMID,    YOYO_BUFFER_FILE_Destruct},
        {Oj_Close_OjMID,       Buffer_File_Close},
        {Oj_Read_OjMID,        Buffer_File_Read},
        {Oj_Write_OjMID,       Buffer_File_Write},
        {Oj_Available_OjMID,   Buffer_File_Available},
        {Oj_Eof_OjMID,         Buffer_File_Eof},
        {Oj_Length_OjMID,      Buffer_File_Length},
        {Oj_Seek_OjMID,        Buffer_File_Seek},
        {Oj_Tell_OjMID,        Buffer_File_Tell},
        {0}
      };
    YOYO_BUFFER_FILE *file = __Object(sizeof(YOYO_BUFFER_FILE),funcs);
    file->bf = __Refe(bf);
    return file;
  }
#endif
  ;

void Oj_Print(void *foj, char *S)
#ifdef _YOYO_FILE_BUILTIN
  {
    int S_len = S?strlen(S):0;
    if ( S_len )
      Oj_Write_Full(foj,S,S_len);
  }
#endif
  ;

void Oj_Printf(void *foj, char *fmt, ...)
#ifdef _YOYO_FILE_BUILTIN
  {
    __Auto_Release
      {
        va_list va;
        char *text;
        va_start(va,fmt);
        text = __Pool(Yo_Format_(fmt,va));
        va_end(va);
        Oj_Print(foj,text);
      }
  }
#endif
  ;

#endif /* C_once_E9479D04_5D69_4A1A_944F_0C99A852DC0B */

Changes to logout.hc.

110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
  {
    if ( level <= YOYO_Log_Level )
      __Xchg_Interlock
        {        
          int log_fd = YOYO_Log_Fd >= 0 ? YOYO_Log_Fd : fileno(stderr);
          char mark[80] = {0};
          int len = strlen(text);
          if ( YOYO_Log_Opt | YOYO_LOG_DATESTAMP )
            {
              clock_t t = clock();
              if ( t - YOYO_Log_Clock > CLOCKS_PER_SEC )
                {
                  YOYO_Log_Clock = t;
                  sprintf(mark, "%%clocks%% %.3f\n",(double)YOYO_Log_Clock/CLOCKS_PER_SEC);
                  Write_Out(YOYO_Log_Fd,mark,strlen(mark));







|







110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
  {
    if ( level <= YOYO_Log_Level )
      __Xchg_Interlock
        {        
          int log_fd = YOYO_Log_Fd >= 0 ? YOYO_Log_Fd : fileno(stderr);
          char mark[80] = {0};
          int len = strlen(text);
          if ( YOYO_Log_Opt & YOYO_LOG_DATESTAMP )
            {
              clock_t t = clock();
              if ( t - YOYO_Log_Clock > CLOCKS_PER_SEC )
                {
                  YOYO_Log_Clock = t;
                  sprintf(mark, "%%clocks%% %.3f\n",(double)YOYO_Log_Clock/CLOCKS_PER_SEC);
                  Write_Out(YOYO_Log_Fd,mark,strlen(mark));

Changes to prog.hc.

219
220
221
222
223
224
225








226
227

228
229
230
231
232
233
234
235
236
237
    int rt = 0;
    __Auto_Release __Try_Except
      {
        setlocale(LC_NUMERIC,"C");
        setlocale(LC_TIME,"C");
        Prog_Parse_Command_Line(argc,argv,patt,flags);
      #ifdef __windoze








      #else
        Prog_Nam_S = __Retain(Path_Fullname(argv[0]));

        Prog_Dir_S = __Retain(Path_Dirname(Prog_Nam_S));
        REQUIRE(Prog_Dir_S != 0);
      #endif
        rt = 1;
        atexit(Prog_Clear_At_Exit);
      }
    __Except
      {
        if ( flags & PROG_EXIT_ON_ERROR )
          Error_Print_N_Exit(Yo__basename(argv[0]),-1);







>
>
>
>
>
>
>
>


>


<







219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238

239
240
241
242
243
244
245
    int rt = 0;
    __Auto_Release __Try_Except
      {
        setlocale(LC_NUMERIC,"C");
        setlocale(LC_TIME,"C");
        Prog_Parse_Command_Line(argc,argv,patt,flags);
      #ifdef __windoze
        __Gogo
          {
            int L = 256;
            wchar_t *buf = __Malloc((256+1)*sizeof(wchar_t));
            GetModuleFileNameW(0,buf,L);
            Prog_Nam_S = Str_Unicode_To_Utf8_Npl(buf);
            printf("appname: %d, %s\n",L,Prog_Nam_S);
          }
      #else
        Prog_Nam_S = __Retain(Path_Fullname(argv[0]));
      #endif
        Prog_Dir_S = __Retain(Path_Dirname(Prog_Nam_S));
        REQUIRE(Prog_Dir_S != 0);

        rt = 1;
        atexit(Prog_Clear_At_Exit);
      }
    __Except
      {
        if ( flags & PROG_EXIT_ON_ERROR )
          Error_Print_N_Exit(Yo__basename(argv[0]),-1);

Changes to random.hc.

169
170
171
172
173
174
175

176
177
178
179
180
181
182
183
184
185
186
187

188













189
190
        }

    return r;
  }
#endif
  ;


ulong_t Get_Random(unsigned min, unsigned max)
#ifdef _YOYO_RANDOM_BUILTIN
  {
    ulong_t r;
    int k = sizeof(r)*8/2;
    STRICT_REQUIRE(max > min);
    r = ((Random_Bits(k)*(max-min))>>k) + min;
    STRICT_REQUIRE(r >= min && r < max);
    return r;
  }
#endif
  ;

  













#endif /* C_once_FF657866_8205_4CAE_9D01_65B8583E9D19 */








>












>
|
>
>
>
>
>
>
>
>
>
>
>
>
>


169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
        }

    return r;
  }
#endif
  ;

#if 0
ulong_t Get_Random(unsigned min, unsigned max)
#ifdef _YOYO_RANDOM_BUILTIN
  {
    ulong_t r;
    int k = sizeof(r)*8/2;
    STRICT_REQUIRE(max > min);
    r = ((Random_Bits(k)*(max-min))>>k) + min;
    STRICT_REQUIRE(r >= min && r < max);
    return r;
  }
#endif
  ;
#endif

uint_t Get_Random(uint_t min, uint_t max)
#ifdef _YOYO_RANDOM_BUILTIN
  {
    uint_t r;
    uint_t dif = max - min;
    STRICT_REQUIRE(max > min);
    r = (uint_t)(((uquad_t)Random_Bits(32)*dif) >> 32) + min;
    STRICT_REQUIRE(r >= min && r < max);
    return r;
  }
#endif
  ;

#endif /* C_once_FF657866_8205_4CAE_9D01_65B8583E9D19 */

Changes to string.hc.

42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
..
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
...
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
...
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
...
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
...
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
...
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517


518
519
520
521
522
523
524
...
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553


554
555
556
557
558
559
560
....
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435

1436
1437
1438
1439
1440
1441
1442
1443
1444
1445



















































1446
1447
/* caseinsensitive strcmp, returns 0 if equal */
int strcmp_I(char *cs, char *ct)
#ifdef _YOYO_STRING_BUILTIN
  {
    int q = 0;
    do 
      {
        q = toupper((byte_t)*cs) - toupper((byte_t)*ct++);
      }
    while ( *cs++ && !q );
    return q;
  }
#endif
  ;

................................................................................
/* caseinsensitive strncmp, returns 0 if equal */
int strncmp_I(char *cs, char *ct, int l)
#ifdef _YOYO_STRING_BUILTIN
  {
    int q = 0;
    if ( l ) do 
      {
        q = toupper((byte_t)*cs) - toupper((byte_t)*ct++);
      }
    while ( *cs++ && !q && --l );
    return q;
  }    
#endif
  ;

................................................................................
#define Str_Trim_Copy(Str,Len) __Pool(Str_Trim_Copy_Npl(Str,Len))
char *Str_Trim_Copy_Npl(char *S, int L)
#ifdef _YOYO_STRING_BUILTIN
  {
    if ( L < 0 ) L = S?strlen(S):0;
    if ( L && S )
      {
        while ( *S && isspace(*S) ) { ++S; --L; }
        while ( L && isspace(S[L-1]) ) --L;
      }
    return Str_Copy_Npl(S,L);
  }
#endif
  ;

#define Str_Unicode_Copy(Str,Len) Yo_Pool(Str_Unicode_Copy_Npl(Str,Len))
................................................................................
      memcpy(p,S,L*sizeof(wchar_t));
    p[L] = 0;
    return p;
  }
#endif
  ;

#define Chr_Isspace(C) isspace((byte_t)(C))

char *Str_Split_Once_Into(char *S,char *delims,void *arr)
#ifdef _YOYO_STRING_BUILTIN
  {
    if ( delims )
      {
        char *d;
        int j = 0;
................................................................................
      l:
        Array_Push(arr,Str_Copy_Npl(S,j));
        return S[j] ? S+(j+1) : 0;
      }
    else // split by spaces
      {
        char *p = S, *q;
        while ( *p && Chr_Isspace(*p) ) ++p;
        q = p;
        while ( *q && !Chr_Isspace(*q) ) ++q;
        Array_Push(arr,Str_Copy_Npl(p,q-p));
        while ( *q && Chr_Isspace(*q) ) ++q;
        return *q ? q : 0;
      }
  }
#endif
  ;

void *Str_Split_Once(char *S,char *delims)
................................................................................
      }
    
    return 0;
  }
#endif
  ;

#define Chr_Isxdigit(C) isxdigit((byte_t)(C))
#define Chr_Isdigit(C)  isdigit((byte_t)(C))

int Str_Urldecode_Char(char **S)
#ifdef _YOYO_STRING_BUILTIN
  {
    int r = 0;
    if ( *S ) 
      {
        if ( **S == '+' ) 
          {
            r = ' ';
            ++*S;
          }
        else if ( **S == '%' && Chr_Isxdigit((*S)[1]) && Chr_Isxdigit((*S)[2]) )
          {
            STR_UNHEX_HALF_OCTET((*S)+1,r,4);
            STR_UNHEX_HALF_OCTET((*S)+2,r,0);
            *S += 3;
          }
        else 
          r = *(*S)++;
................................................................................
    int i;
    for ( i = 0; i < 4; ++i )
      Str_Hex_Byte((byte_t)(val>>(i*8)),0,out+i*2);
  }
#endif
  ;

void Unsigned_To_Hex2(uint_t val,char *out)
#ifdef _YOYO_STRING_BUILTIN
  {
    int i;
    for ( i = 0; i < 2; ++i )
      Str_Hex_Byte((byte_t)(val>>(i*8)),0,out+i*2);
  }
#endif
  ;



uquad_t Hex16_To_Quad(char *S)
#ifdef _YOYO_STRING_BUILTIN
  {
    uint_t ret = 0;
    int i;
    for ( i = 0; i < 8; ++i )
................................................................................
    for ( i = 0; i < 4; ++i )
      ret |= ( (uint_t)Str_Unhex_Byte(S+i*2,0,0) << (i*8) );
    return ret;
  }
#endif
  ;

uint_t Hex2_To_Unsigned(char *S)
#ifdef _YOYO_STRING_BUILTIN
  {
    uint_t ret = 0;
    int i;
    for ( i = 0; i < 2; ++i )
      ret |= ( (uint_t)Str_Unhex_Byte(S+i*2,0,0) << (i*8) );
    return ret;
  }
#endif
  ;



_YOYO_STRING_EXTERN char Utf8_Char_Length[] 
#ifdef _YOYO_STRING_BUILTIN
  = {
    /* Map UTF-8 encoded prefix byte to sequence length.  zero means
       illegal prefix.  see RFC 2279 for details */
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
................................................................................
  
wchar_t *Str_Unicode_Transform_Npl(wchar_t *S, int L, wchar_t (*transform)(wchar_t))
#ifdef _YOYO_STRING_BUILTIN  
  {
    int i;
    wchar_t *ret;
    if ( L < 0 ) L = S?wcslen(S):0;
    ret = __Malloc_Npl(L*sizeof(wchar_t)+1);
    for ( i = 0; i < L; ++i )
      ret[i] = transform(S[i]);

    return ret;
  }
#endif
  ;

#define Str_Unicode_Upper(S,L) ((wchar_t*)__Pool(Str_Unicode_Upper_Npl(S,L)))
#define Str_Unicode_Upper_Npl(S,L) Str_Unicode_Transform_Npl(S,L,towupper)
#define Str_Unicode_Lower(S,L) ((wchar_t*)__Pool(Str_Unicode_Lower_Npl(S,L)))
#define Str_Unicode_Lower_Npl(S,L) Str_Unicode_Transform_Npl(S,L,towlower)




















































#endif /* C_once_0ED387CD_668B_44C3_9D91_A6336A2F5F48 */








|







 







|







 







|
|







 







<
<







 







|

|

|







 







<
<
<











|







 







|








>
>







 







|










>
>







 







|


>






|

|

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
..
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
...
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
...
128
129
130
131
132
133
134


135
136
137
138
139
140
141
...
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
...
452
453
454
455
456
457
458



459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
...
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
...
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
....
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
/* caseinsensitive strcmp, returns 0 if equal */
int strcmp_I(char *cs, char *ct)
#ifdef _YOYO_STRING_BUILTIN
  {
    int q = 0;
    do 
      {
        q = Toupper(*cs) - Toupper(*ct++);
      }
    while ( *cs++ && !q );
    return q;
  }
#endif
  ;

................................................................................
/* caseinsensitive strncmp, returns 0 if equal */
int strncmp_I(char *cs, char *ct, int l)
#ifdef _YOYO_STRING_BUILTIN
  {
    int q = 0;
    if ( l ) do 
      {
        q = Toupper(*cs) - Toupper(*ct++);
      }
    while ( *cs++ && !q && --l );
    return q;
  }    
#endif
  ;

................................................................................
#define Str_Trim_Copy(Str,Len) __Pool(Str_Trim_Copy_Npl(Str,Len))
char *Str_Trim_Copy_Npl(char *S, int L)
#ifdef _YOYO_STRING_BUILTIN
  {
    if ( L < 0 ) L = S?strlen(S):0;
    if ( L && S )
      {
        while ( *S && Isspace(*S) ) { ++S; --L; }
        while ( L && Isspace(S[L-1]) ) --L;
      }
    return Str_Copy_Npl(S,L);
  }
#endif
  ;

#define Str_Unicode_Copy(Str,Len) Yo_Pool(Str_Unicode_Copy_Npl(Str,Len))
................................................................................
      memcpy(p,S,L*sizeof(wchar_t));
    p[L] = 0;
    return p;
  }
#endif
  ;



char *Str_Split_Once_Into(char *S,char *delims,void *arr)
#ifdef _YOYO_STRING_BUILTIN
  {
    if ( delims )
      {
        char *d;
        int j = 0;
................................................................................
      l:
        Array_Push(arr,Str_Copy_Npl(S,j));
        return S[j] ? S+(j+1) : 0;
      }
    else // split by spaces
      {
        char *p = S, *q;
        while ( *p && Isspace(*p) ) ++p;
        q = p;
        while ( *q && !Isspace(*q) ) ++q;
        Array_Push(arr,Str_Copy_Npl(p,q-p));
        while ( *q && Isspace(*q) ) ++q;
        return *q ? q : 0;
      }
  }
#endif
  ;

void *Str_Split_Once(char *S,char *delims)
................................................................................
      }
    
    return 0;
  }
#endif
  ;




int Str_Urldecode_Char(char **S)
#ifdef _YOYO_STRING_BUILTIN
  {
    int r = 0;
    if ( *S ) 
      {
        if ( **S == '+' ) 
          {
            r = ' ';
            ++*S;
          }
        else if ( **S == '%' && Isxdigit((*S)[1]) && Isxdigit((*S)[2]) )
          {
            STR_UNHEX_HALF_OCTET((*S)+1,r,4);
            STR_UNHEX_HALF_OCTET((*S)+2,r,0);
            *S += 3;
          }
        else 
          r = *(*S)++;
................................................................................
    int i;
    for ( i = 0; i < 4; ++i )
      Str_Hex_Byte((byte_t)(val>>(i*8)),0,out+i*2);
  }
#endif
  ;

void Unsigned_To_Hex4(uint_t val,char *out)
#ifdef _YOYO_STRING_BUILTIN
  {
    int i;
    for ( i = 0; i < 2; ++i )
      Str_Hex_Byte((byte_t)(val>>(i*8)),0,out+i*2);
  }
#endif
  ;

#define Unsigned_To_Hex2(Val,Out) Str_Hex_Byte((byte_t)(Val),0,Out)

uquad_t Hex16_To_Quad(char *S)
#ifdef _YOYO_STRING_BUILTIN
  {
    uint_t ret = 0;
    int i;
    for ( i = 0; i < 8; ++i )
................................................................................
    for ( i = 0; i < 4; ++i )
      ret |= ( (uint_t)Str_Unhex_Byte(S+i*2,0,0) << (i*8) );
    return ret;
  }
#endif
  ;

uint_t Hex4_To_Unsigned(char *S)
#ifdef _YOYO_STRING_BUILTIN
  {
    uint_t ret = 0;
    int i;
    for ( i = 0; i < 2; ++i )
      ret |= ( (uint_t)Str_Unhex_Byte(S+i*2,0,0) << (i*8) );
    return ret;
  }
#endif
  ;

#define Hex2_To_Unsigned(S) ( (uint_t)Str_Unhex_Byte(S,0,0) )

_YOYO_STRING_EXTERN char Utf8_Char_Length[] 
#ifdef _YOYO_STRING_BUILTIN
  = {
    /* Map UTF-8 encoded prefix byte to sequence length.  zero means
       illegal prefix.  see RFC 2279 for details */
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
................................................................................
  
wchar_t *Str_Unicode_Transform_Npl(wchar_t *S, int L, wchar_t (*transform)(wchar_t))
#ifdef _YOYO_STRING_BUILTIN  
  {
    int i;
    wchar_t *ret;
    if ( L < 0 ) L = S?wcslen(S):0;
    ret = __Malloc_Npl((L+1)*sizeof(wchar_t));
    for ( i = 0; i < L; ++i )
      ret[i] = transform(S[i]);
    ret[i] = 0;
    return ret;
  }
#endif
  ;

#define Str_Unicode_Upper(S,L) ((wchar_t*)__Pool(Str_Unicode_Upper_Npl(S,L)))
#define Str_Unicode_Upper_Npl(S,L) Str_Unicode_Transform_Npl(S,L,(void*)towupper)
#define Str_Unicode_Lower(S,L) ((wchar_t*)__Pool(Str_Unicode_Lower_Npl(S,L)))
#define Str_Unicode_Lower_Npl(S,L) Str_Unicode_Transform_Npl(S,L,(void*)towlower)

char *Str_Ansi_Transform_Npl(char *S, int L, char (*transform)(char))
#ifdef _YOYO_STRING_BUILTIN  
  {
    int i;
    char *ret;
    if ( L < 0 ) L = S?strlen(S):0;
    ret = __Malloc_Npl(L+1);
    for ( i = 0; i < L; ++i )
      ret[i] = transform(S[i]);
    ret[i] = 0;
    return ret;
  }
#endif
  ;

#define Str_Ansi_Upper(S,L) ((char*)__Pool(Str_Ansi_Upper_Npl(S,L)))
#define Str_Ansi_Upper_Npl(S,L) Str_Ansi_Transform_Npl(S,L,(void*)toupper)
#define Str_Ansi_Lower(S,L) ((char*)__Pool(Str_Ansi_Lower_Npl(S,L)))
#define Str_Ansi_Lower_Npl(S,L) Str_Ansi_Transform_Npl(S,L,(void*)tolower)

char *Str_Safe_Oneline_Quote(char *S)
#ifdef _YOYO_STRING_BUILTIN  
  {
    int S_len = S? strlen(S):0;
    int R_count = 0;
    int R_capacity = S_len+1;
    char *R = 0;

    if ( S )
      for ( ; *S; ++S )
        {
          if ( 0 ) ;
          else if ( *S == '\n' ) R_count += __Elm_Append_Npl(&R,R_count,"~n",2,1,&R_capacity);
          else if ( *S == '\r' ) R_count += __Elm_Append_Npl(&R,R_count,"~r",2,1,&R_capacity);
          else if ( *S == '|' )  R_count += __Elm_Append_Npl(&R,R_count,"~!",2,1,&R_capacity);
          else if ( *S == '&' )  R_count += __Elm_Append_Npl(&R,R_count,"~a",2,1,&R_capacity);
          else if ( *S == ';' )  R_count += __Elm_Append_Npl(&R,R_count,"~:",2,1,&R_capacity);
          else if ( *S < 30 ) 
            {
              char b[2];
              Unsigned_To_Hex2(*S,b);
              R_count += __Elm_Append_Npl(&R,R_count,b,2,1,&R_capacity);
            }
          else R_count += __Elm_Append_Npl(&R,R_count,S,1,1,&R_capacity);
        }
        
    return __Pool(R);
  }
#endif
  ;

#endif /* C_once_0ED387CD_668B_44C3_9D91_A6336A2F5F48 */

Added tests/pngshow.c.





























































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78

#include <libyoyo.hc>
#include <extra/pictpng.hc>

HBITMAP bmp;

LRESULT __stdcall Window_Proc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
  {
    if ( uMsg == WM_PAINT )
      {
        HBITMAP old;
        BITMAP bmpi;
        RECT rect;
        HDC dc,pdc;
        PAINTSTRUCT pst;
        
        pdc = BeginPaint(hwnd,&pst);
        GetObject(bmp,sizeof(BITMAP),&bmpi);
        GetClientRect(hwnd,&rect);
        
        dc = CreateCompatibleDC(pdc);
        old = SelectObject(dc,bmp);
        StretchBlt(pdc,0,0,rect.right,rect.bottom,
                   dc,0,0,bmpi.bmWidth,bmpi.bmHeight,
                   SRCCOPY);
        SelectObject(dc,old);
        DeleteDC(dc);
      }
    else
      return DefWindowProc(hwnd,uMsg,wParam,lParam);
  }
  
int main(int argc, char **argv)
  {
    RECT rect = {0};
    HWND hwnd;
    MSG  msg = {0};
    WNDCLASS wc = {0};
    YOYO_PICTURE *pict;
    int style  = WS_BORDER|WS_VISIBLE|WS_CAPTION;
    int ex_style = 0;
    
    Prog_Init(argc,argv,"?|h,l",PROG_EXIT_ON_ERROR);
    
    wc.lpszClassName = "PNG test class";
    wc.lpfnWndProc   = (WNDPROC)Window_Proc;
    wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    wc.style = CS_HREDRAW|CS_VREDRAW;
    wc.hCursor = LoadCursor(0,IDC_ARROW);
    RegisterClassA(&wc);
    
    pict = Pict_From_PNG_File("test.png");
    bmp = Pict_Create_HBITMAP(pict);
    printf("bmp %p\n",bmp);
    
    rect.bottom = pict->height;
    rect.right = pict->width;
    AdjustWindowRectEx(&rect,style,0,ex_style);
    hwnd = CreateWindowEx(
            ex_style,
            "PNG test class",
            "PNG test class",
            style,
            rect.left,rect.top,
            rect.right-rect.left,rect.bottom-rect.top,
            0,0,0,0);
  
    while ( GetMessage(&msg,hwnd,0,0) )
      {
        if ( msg.message == WM_QUIT )
          break;
        else
          {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
          }
      }
  }

Added tests/random.c.







































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67


#include <libyoyo.hc>

int main(int argc, char **argv)
  {
    enum { STATS_RANGE = 7000 };
    enum { STATS_LINES = 15 };
    enum { STAT_COLUMNS = 70 };
    int range, count, i, j;
    uquad_t result_max = 0;
    static uquad_t stats[STATS_RANGE] = {0};
    static uquad_t result[STAT_COLUMNS] = {0};
    
    Prog_Init(argc,argv,"?|h,l",PROG_EXIT_ON_ERROR);

    if ( !Prog_Arguments_Count() )
      {
        puts("usage: ./random <range>");
        exit(-1);
      }

    range = Prog_Argument_Int(0);
    
    
    count = range * 100;
    for ( i = 0; i < count; ++i )
      {
        uquad_t rnd = Get_Random(0,range);
        ++stats[ (rnd * STATS_RANGE) / range ];
      }
    
    for ( i = 0; i < STATS_RANGE; ++i )
      {
        result[i*STAT_COLUMNS/STATS_RANGE] += stats[i];
      }
      
    for ( i = 0; i < STAT_COLUMNS; ++i )
      {
        result_max = Yo_MAX(result_max,result[i]);
      }
      
    for ( i = 0; i < STAT_COLUMNS; ++i )
      {
        result[i] = ( result[i] * STATS_LINES *2 ) / result_max;
      }

    printf("range: %d, max: %lld, stats count: %d\n",range,result_max,STATS_RANGE);

    for ( j = STATS_LINES ; j > 0; --j )
      {
        for ( i = 0; i < STAT_COLUMNS; ++i )
          {
            if ( result[i]/2 < j ) putchar(' ');
            else if ( result[i]/2 > j ) putchar('+');
            else
              {
                if ( result[i] % 2 ) putchar('#');
                else putchar('=');
              }
          }
        putchar('\n');
      }

    return 0;
  }

Added tests/test.png.

cannot compute difference between binary files

Changes to xdata.hc.

1287
1288
1289
1290
1291
1292
1293














1294
1295
1296
1297
1298
1299
1300
*/
char *Xnode_Query_Str_Bf(YOYO_BUFFER *bf, YOYO_XNODE *n, char *query)
#ifdef _YOYO_XDATA_BUILTIN
  {
    YOYO_XVALUE *value = Xnode_Query_Value(n,query);
    return Xvalue_Str_Bf(value,bf);
  }














#endif
  ;

char *Xnode_Query_Str_Copy(YOYO_XNODE *n, char *query)
#ifdef _YOYO_XDATA_BUILTIN
  {
    YOYO_XVALUE *value;







>
>
>
>
>
>
>
>
>
>
>
>
>
>







1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
*/
char *Xnode_Query_Str_Bf(YOYO_BUFFER *bf, YOYO_XNODE *n, char *query)
#ifdef _YOYO_XDATA_BUILTIN
  {
    YOYO_XVALUE *value = Xnode_Query_Value(n,query);
    return Xvalue_Str_Bf(value,bf);
  }
#endif
  ;

char *Xnode_Query_Str_Dflt(YOYO_XNODE *n, char *query, char *dflt)
#ifdef _YOYO_XDATA_BUILTIN
  {
    YOYO_XVALUE *value;
    
    value = Xnode_Query_Value(n,query);
    if ( value )
      return Xvalue_Get_Str(value,dflt);
      
    return dflt;
  }
#endif
  ;

char *Xnode_Query_Str_Copy(YOYO_XNODE *n, char *query)
#ifdef _YOYO_XDATA_BUILTIN
  {
    YOYO_XVALUE *value;