ScalpiEditor

Diff
Login

Diff

Differences From Artifact [aba0820de9]:

To Artifact [0fce238300]:


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
        // os
            #define __TargetOs_windows__ 1
            #define __TargetOs_linux__   2
        // memory type
            #define __TargetMemoryType_endiansLittle__  1
            #define __TargetMemoryType_endiansBig__     2
    // time
        #define Scalpi_time_ms_per_s 1000
    // OsNetwork

        #define __OsNetworkTcpSocketConnectResult_error__      -1
        #define __OsNetworkTcpSocketConnectResult_inProgress__  0
        #define __OsNetworkTcpSocketConnectResult_success__     1
        
        #define __OsNetworkTcpSocketStatus_notInit__      -1
        #define __OsNetworkTcpSocketStatus_notOk__         0
        #define __OsNetworkTcpSocketStatus_ok__            1
    // scalpi

        // Scalpi_Logger_writers
            #define Scalpi_Logger_writers_c_out_writer    0
            #define Scalpi_Logger_writers_file_writer     1
            #define Scalpi_Logger_writers_console_writer  2
            #define Scalpi_Logger_writers_terminal_writer 3
        // Scalpi_Console_ansi_input_Key
            // ascii
                #define __Scalpi_Console_ansi_input_Key_ascii_ctrl__     (-'a' + 1)  /* do not use externally */
                #define __Scalpi_Console_ansi_input_Key_ctrl_bs__         8  /* also ctrl_h */
                #define __Scalpi_Console_ansi_input_Key_tab__             9  /* also ctrl_i */
                #define __Scalpi_Console_ansi_input_Key_enter__          13  /* also ctrl_m */
                #define __Scalpi_Console_ansi_input_Key_escape__         27







|

>



<
<
<
<

>
|
|
|
|
|







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
        // os
            #define __TargetOs_windows__ 1
            #define __TargetOs_linux__   2
        // memory type
            #define __TargetMemoryType_endiansLittle__  1
            #define __TargetMemoryType_endiansBig__     2
    // time
        #define __ScalpiTime_msPerS__ 1000
    // OsNetwork
        #define __OsNetworkTcp_maxAllowedListenPort__ 49151
        #define __OsNetworkTcpSocketConnectResult_error__      -1
        #define __OsNetworkTcpSocketConnectResult_inProgress__  0
        #define __OsNetworkTcpSocketConnectResult_success__     1




    // scalpi
        #define __ScalpiTextCharsDecFromU64_lenMax__  __CText_len__("18446744073709551615")
        // __ScalpiLoggerWriters__
            #define __ScalpiLoggerWriter_toFallback__  0
            #define __ScalpiLoggerWriter_toFile__      1
            #define __ScalpiLoggerWriter_toConsole__   2
            #define __ScalpiLoggerWriter_toTerminal__  3
        // Scalpi_Console_ansi_input_Key
            // ascii
                #define __Scalpi_Console_ansi_input_Key_ascii_ctrl__     (-'a' + 1)  /* do not use externally */
                #define __Scalpi_Console_ansi_input_Key_ctrl_bs__         8  /* also ctrl_h */
                #define __Scalpi_Console_ansi_input_Key_tab__             9  /* also ctrl_i */
                #define __Scalpi_Console_ansi_input_Key_enter__          13  /* also ctrl_m */
                #define __Scalpi_Console_ansi_input_Key_escape__         27
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
                    #define __Scalpi_Console_ansi_input_Key_alt_comma__          (',' + __Scalpi_Console_ansi_input_Key_alt__)
                    #define __Scalpi_Console_ansi_input_Key_alt_dot__            ('.' + __Scalpi_Console_ansi_input_Key_alt__)
                    #define __Scalpi_Console_ansi_input_Key_alt_open_bracket__   ('[' + __Scalpi_Console_ansi_input_Key_alt__)
                    #define __Scalpi_Console_ansi_input_Key_alt_close_bracket__  (']' + __Scalpi_Console_ansi_input_Key_alt__)
                    #define __Scalpi_Console_ansi_input_Key_alt_semicolon__      (';' + __Scalpi_Console_ansi_input_Key_alt__)
                    #define __Scalpi_Console_ansi_input_Key_alt_apostrophe__     ('`' + __Scalpi_Console_ansi_input_Key_alt__)
        // websocket
            #define __ScalpiNetworkTcpHttpWebSocketHandShake_encoded___CText_len____ 28
// settings
    // platform
        // #define __target_os__ __TargetOs_
            #ifndef __target_os__
                #ifdef _WIN32
                    #define __target_os__           __TargetOs_windows__
                #elif defined(__linux__)
                    #define __target_os__           __TargetOs_linux__
                #endif
            #endif
            
            #if __target_os__ == __TargetOs_windows__
            #elif __target_os__ == __TargetOs_linux__
            #else
                #error "__target_os__ not implemented"
            #endif
            
        #define __target_memory_type__        __TargetMemoryType_endiansLittle__
        #define __with_network__              0
        #define __OsFilePathLen_max__         1024


    #define __ScalpiTerminalInput_size__  32
    
    // App
        #define __AppEditorLineLen_max__  (1024 * 8)
        #define App_expected_fps          30
// imports
    // libC
        #include <stdarg.h>
        #include <stdbool.h>
        #include <stddef.h>
        #include <stdint.h>
        #include <stdio.h>







|

















|
|
|
>
>
|



|







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
                    #define __Scalpi_Console_ansi_input_Key_alt_comma__          (',' + __Scalpi_Console_ansi_input_Key_alt__)
                    #define __Scalpi_Console_ansi_input_Key_alt_dot__            ('.' + __Scalpi_Console_ansi_input_Key_alt__)
                    #define __Scalpi_Console_ansi_input_Key_alt_open_bracket__   ('[' + __Scalpi_Console_ansi_input_Key_alt__)
                    #define __Scalpi_Console_ansi_input_Key_alt_close_bracket__  (']' + __Scalpi_Console_ansi_input_Key_alt__)
                    #define __Scalpi_Console_ansi_input_Key_alt_semicolon__      (';' + __Scalpi_Console_ansi_input_Key_alt__)
                    #define __Scalpi_Console_ansi_input_Key_alt_apostrophe__     ('`' + __Scalpi_Console_ansi_input_Key_alt__)
        // websocket
            #define __ScalpiNetworkTcpHttpWebSocketHandShake_encoded_len__ 28
// settings
    // platform
        // #define __target_os__ __TargetOs_
            #ifndef __target_os__
                #ifdef _WIN32
                    #define __target_os__           __TargetOs_windows__
                #elif defined(__linux__)
                    #define __target_os__           __TargetOs_linux__
                #endif
            #endif
            
            #if __target_os__ == __TargetOs_windows__
            #elif __target_os__ == __TargetOs_linux__
            #else
                #error "__target_os__ not implemented"
            #endif
            
            #define __target_memory_type__                __TargetMemoryType_endiansLittle__
            #define __with_network__                      0
            #define __OsFilePathLen_max__              1024
            #define __OsNetworkTcp_maxClientCount__       8
            #define __OsNetworkTcpHttp_maxHeaders__      48
        #define __ScalpiTerminalInput_size__  32
    
    // App
        #define __AppEditorLineLen_max__  (1024 * 8)
        #define __App_expectedFps__          30
// imports
    // libC
        #include <stdarg.h>
        #include <stdbool.h>
        #include <stddef.h>
        #include <stdint.h>
        #include <stdio.h>
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
        #include <wchar.h>
        #include <wctype.h>
    
    #if __target_os__ == __TargetOs_windows__
        // posix
            #include <fcntl.h>
        // Windows





            #include <windef.h>
            #include <windows.h>
            #include <winuser.h>
            #include <commctrl.h>
            #include <io.h>
            #include <conio.h>
            
            #ifdef __COMPILED_FROM_ZIG_FILE__
                #define INVALID_HANDLE_VALUE  (HANDLE)0xFFFFFFFF
            #endif
        
        #if __with_network__
            #include <ws2tcpip.h>
            #include <winsock2.h>
        #endif
    #elif __target_os__ == __TargetOs_linux__
        #include <fcntl.h>
        #include <sys/ioctl.h>
        #include <sys/stat.h>
        #include <termios.h>
        #include <unistd.h>
        #include <time.h>
        
        #if __with_network__
            #include <arpa/inet.h>
            #include <netinet/in.h>
            #include <netinet/ip.h>
            #include <sys/socket.h>
        #endif
    #endif
// strings

    #define Scalpi_Text_CharsDecFromU64_MAX_LEN  __CText_len__("18446744073709551615")
    // Scalpi_Console_ansi
        #define Scalpi_Console_ansi_esc                          "\x1B"
        #define __ScalpiConsoleAnsi_control__                      Scalpi_Console_ansi_esc "["
        // clear_output
            #define Scalpi_Console_ansi_output_clear_to_end_line     __ScalpiConsoleAnsi_control__ "0K"
            #define Scalpi_Console_ansi_output_clear_to_start_line   __ScalpiConsoleAnsi_control__ "1K"
            #define Scalpi_Console_ansi_output_clear_line            __ScalpiConsoleAnsi_control__ "2K"







>
>
>
>
>










<
<
<
<
<
















>
|







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
        #include <wchar.h>
        #include <wctype.h>
    
    #if __target_os__ == __TargetOs_windows__
        // posix
            #include <fcntl.h>
        // Windows
            #if __with_network__
                #include <ws2tcpip.h>  // include before windows.h
                #include <winsock2.h>
            #endif
            
            #include <windef.h>
            #include <windows.h>
            #include <winuser.h>
            #include <commctrl.h>
            #include <io.h>
            #include <conio.h>
            
            #ifdef __COMPILED_FROM_ZIG_FILE__
                #define INVALID_HANDLE_VALUE  (HANDLE)0xFFFFFFFF
            #endif





    #elif __target_os__ == __TargetOs_linux__
        #include <fcntl.h>
        #include <sys/ioctl.h>
        #include <sys/stat.h>
        #include <termios.h>
        #include <unistd.h>
        #include <time.h>
        
        #if __with_network__
            #include <arpa/inet.h>
            #include <netinet/in.h>
            #include <netinet/ip.h>
            #include <sys/socket.h>
        #endif
    #endif
// strings
    #define __ScalpiNetworkWsQuery_expected__  "GET /ws"
    #define __ScalpiTextCharsDecFromU64_lenMax__  __CText_len__("18446744073709551615")
    // Scalpi_Console_ansi
        #define Scalpi_Console_ansi_esc                          "\x1B"
        #define __ScalpiConsoleAnsi_control__                      Scalpi_Console_ansi_esc "["
        // clear_output
            #define Scalpi_Console_ansi_output_clear_to_end_line     __ScalpiConsoleAnsi_control__ "0K"
            #define Scalpi_Console_ansi_output_clear_to_start_line   __ScalpiConsoleAnsi_control__ "1K"
            #define Scalpi_Console_ansi_output_clear_line            __ScalpiConsoleAnsi_control__ "2K"
417
418
419
420
421
422
423

424

425





426





427

428
429
430
431
432
433
434
435
436
        #elif __target_os__ == __TargetOs_linux__
            #define __OsFilePath_separator__ "/"
        #else
            #error "not implemented current __target_os__ or not defined. (expected __TargetOs_ value)"
        #endif
// basic types
    // scalpi

        typedef uint8_t* __AlignedPtr__;

        typedef uint64_t __ScalpiConsoleAnsiInputKey__;





        typedef size_t   (*__WriteFnPtr__)      (void* context, const char* bytes, size_t bytes_len);





        typedef void     (*__WriteFnPtrVoid__)  (void* context, const char* bytes, size_t bytes_len);

    // OS
        // # __OsFile__
            #if __target_os__ == __TargetOs_windows__
                typedef HANDLE __OsFileHandle__;
            #elif __target_os__ == __TargetOs_linux__
                typedef int  __OsFileHandle__;
            #else
                #error "not implemented current __target_os__ or not defined. (expected __TargetOs_ value)"
            #endif







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

|







418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
        #elif __target_os__ == __TargetOs_linux__
            #define __OsFilePath_separator__ "/"
        #else
            #error "not implemented current __target_os__ or not defined. (expected __TargetOs_ value)"
        #endif
// basic types
    // scalpi
        // # __ScalpiConsoleAnsiInputKey__
            typedef
                uint64_t
                __ScalpiConsoleAnsiInputKey__
            ;
        // # __WriteFnPtr__
            typedef
                size_t
                (*__WriteFnPtr__)
                (void* context, const char* bytes, size_t bytes_len)
            ;
        // # __WriteFnPtrVoid__
            typedef
                void
                (*__WriteFnPtrVoid__)
                (void* context, const char* bytes, size_t bytes_len)
            ;
    // OS
        // # __OsFileHandle__
            #if __target_os__ == __TargetOs_windows__
                typedef HANDLE __OsFileHandle__;
            #elif __target_os__ == __TargetOs_linux__
                typedef int  __OsFileHandle__;
            #else
                #error "not implemented current __target_os__ or not defined. (expected __TargetOs_ value)"
            #endif
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
            #define __len_and_text__(str)              __CText_len__(str), str
            #define __text_and_len__(str)              str, __CText_len__(str)
            #define __Slice_fromCText__(text)          {.ptr=text, .len=__CText_len__(text)}
    // crypto
        #define Sha1_block_size 64
        #define Sha1_digest_length 20
    // Network
        #define max_allowed_listen_port 49151
        #define PRISOCK "%llx"

        #if __target_os__ == __TargetOs_windows__
            #define WSA_SUCCESS 0
        #elif __target_os__ == __TargetOs_linux__
        #else
            #error "__target_os__ not implemented"
        #endif








<
<
<







493
494
495
496
497
498
499



500
501
502
503
504
505
506
            #define __len_and_text__(str)              __CText_len__(str), str
            #define __text_and_len__(str)              str, __CText_len__(str)
            #define __Slice_fromCText__(text)          {.ptr=text, .len=__CText_len__(text)}
    // crypto
        #define Sha1_block_size 64
        #define Sha1_digest_length 20
    // Network



        #if __target_os__ == __TargetOs_windows__
            #define WSA_SUCCESS 0
        #elif __target_os__ == __TargetOs_linux__
        #else
            #error "__target_os__ not implemented"
        #endif

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
613
614
615
616
617
618
619
620
621
622
623
624
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
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
                    struct Slice desired;
                    size_t pos;
                };
    // Os
        // system specifics 
            #if __target_os__ == __TargetOs_windows__
            #elif __target_os__ == __TargetOs_linux__

                struct __OsLinux_timespec__ {
                    time_t tv_sec;  /* seconds */
                    long   tv_nsec; /* nanoseconds */
                };
            #else
                #error "__target_os__ not implemented"
            #endif
        // OsConsole

            struct __OsConsoleFlags__ {
                bool inited;
                
                #if __target_os__ == __TargetOs_windows__
                    DWORD input_mode;
                    DWORD output_mode;
                #elif __target_os__ == __TargetOs_linux__
                    struct termios termios;
                #else
                    #error "not implemented current __target_os__ or not defined. (expected __TargetOs_ value)"
                #endif
            };
            

            struct __OsConsoleInput__ {
                __OsConsoleInputHandle__ handle;
                
                #if __target_os__ == __TargetOs_windows__
                #elif __target_os__ == __TargetOs_linux__
                    int fileno;
                #else
                    #error "not implemented current __target_os__ or not defined. (expected __TargetOs_ value)"
                #endif
            };
            
            struct __OsConsoleOutput__ {
                __OsConsoleOutputHandle__  __OsConsoleOutput_handle__;
                #if __target_os__ == __TargetOs_windows__
                #elif __target_os__ == __TargetOs_linux__
                #else
                    #error "not implemented current __target_os__ or not defined. (expected __TargetOs_ value)"
                #endif
            };
        // # __OsHelper__
            struct __OsHelper__ {
                #if __target_os__ == __TargetOs_windows__
                    HINSTANCE instance;
                    void* console_input_handle;
                    __OsConsoleOutputHandle__ console_output_handle;
                    
                    #if __with_network__
                        bool network_inited;
                        WSADATA wsdata;
                    #endif
                #elif __target_os__ == __TargetOs_linux__
                    FILE* console_input_handle;
                    __OsConsoleOutputHandle__ console_output_handle;
                #else
                    #error "not implemented current __target_os__ or not defined. (expected __TargetOs_ value)"
                #endif
            };
    // Scalpi
        // mem

            struct __Scalpi_Writer__ {
                void* context;
                __WriteFnPtr__ write;
            };
            
            struct __ScalpiMemTree__ {
                struct __ScalpiMemTree__*     parent; // todo remove me. use link.list or __ ... 
                struct __ScalpiMemList__      childs;
                struct __ScalpiMemListLink__  link;
                size_t                        count;  // recurse. for get non recurse use childs.count
                size_t                        nested;
            };
        // math
            struct __Scalpi_math_d2_U_Pos__ {
                size_t x;
                size_t y;
            };
        // text
            struct Scalpi_Text_Splitter {
                struct Finder finder;
                bool stop;
                size_t last_pos;
            };
        // # Scalpi_Logger
            struct Scalpi_Logger {
                // write to terminal, console, file or to all together, but no real check "bytes is writen"
                struct __Scalpi_Writer__ writers[4]; // Scalpi_Logger_writers
            };
        // Console
            // __Scalpi_Console_ansi_input_Key_SequenceParser__
                struct __Scalpi_Console_ansi_input_Key_SequenceParser__ {
                    __ScalpiConsoleAnsiInputKey__ sequence;
                    size_t used;
                };







>
|
|
|
|




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

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




















>
|
|
|
|



















|
|

|







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
613
614
615
616
617
618
619
620
621
622
623
624
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
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
                    struct Slice desired;
                    size_t pos;
                };
    // Os
        // system specifics 
            #if __target_os__ == __TargetOs_windows__
            #elif __target_os__ == __TargetOs_linux__
                // # __OsLinux_timespec__
                    struct __OsLinux_timespec__ {
                        time_t tv_sec;  /* seconds */
                        long   tv_nsec; /* nanoseconds */
                    };
            #else
                #error "__target_os__ not implemented"
            #endif
        // OsConsole
            // # __OsConsoleFlags__
                struct __OsConsoleFlags__ {
                    bool inited;
                    
                    #if __target_os__ == __TargetOs_windows__
                        DWORD input_mode;
                        DWORD output_mode;
                    #elif __target_os__ == __TargetOs_linux__
                        struct termios termios;
                    #else
                        #error "not implemented current __target_os__ or not defined. (expected __TargetOs_ value)"
                    #endif
                };
            
            // # __OsConsoleInput__
                struct __OsConsoleInput__ {
                    __OsConsoleInputHandle__ handle;
                    
                    #if __target_os__ == __TargetOs_windows__
                    #elif __target_os__ == __TargetOs_linux__
                        int fileno;
                    #else
                        #error "not implemented current __target_os__ or not defined. (expected __TargetOs_ value)"
                    #endif
                };
            // # __OsConsoleOutput__
                struct __OsConsoleOutput__ {
                    __OsConsoleOutputHandle__  __OsConsoleOutput_handle__;
                    #if __target_os__ == __TargetOs_windows__
                    #elif __target_os__ == __TargetOs_linux__
                    #else
                        #error "not implemented current __target_os__ or not defined. (expected __TargetOs_ value)"
                    #endif
                };
        // # __OsHelper__
            struct __OsHelper__ {
                #if __target_os__ == __TargetOs_windows__
                    HINSTANCE instance;
                    void* console_input_handle;
                    __OsConsoleOutputHandle__ console_output_handle;
                    
                    #if __with_network__
                        bool network_inited;
                        WSADATA wsdata;
                    #endif
                #elif __target_os__ == __TargetOs_linux__
                    FILE* console_input_handle;
                    __OsConsoleOutputHandle__ console_output_handle;
                #else
                    #error "not implemented current __target_os__ or not defined. (expected __TargetOs_ value)"
                #endif
            };
    // Scalpi
        // mem
            // # __ScalpiWriter__
                struct __ScalpiWriter__ {
                    void*          context;
                    __WriteFnPtr__ write;
                };
            
            struct __ScalpiMemTree__ {
                struct __ScalpiMemTree__*     parent; // todo remove me. use link.list or __ ... 
                struct __ScalpiMemList__      childs;
                struct __ScalpiMemListLink__  link;
                size_t                        count;  // recurse. for get non recurse use childs.count
                size_t                        nested;
            };
        // math
            struct __Scalpi_math_d2_U_Pos__ {
                size_t x;
                size_t y;
            };
        // text
            struct Scalpi_Text_Splitter {
                struct Finder finder;
                bool stop;
                size_t last_pos;
            };
        // # __ScalpiLogger__
            struct __ScalpiLogger__ {
                // write to terminal, console, file or to all together, but no real check "bytes is writen"
                struct __ScalpiWriter__ writers[4]; // __ScalpiLoggerWriters__
            };
        // Console
            // __Scalpi_Console_ansi_input_Key_SequenceParser__
                struct __Scalpi_Console_ansi_input_Key_SequenceParser__ {
                    __ScalpiConsoleAnsiInputKey__ sequence;
                    size_t used;
                };
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
                // use __ScalpiTerminalInput_grab__ in loop for get keys
                
                size_t ungrabed;
                char buffer[__ScalpiTerminalInput_size__];
            };
            
            struct __ScalpiTerminal__ {
                struct __ScalpiConsole__*          console;
                struct __OsConsoleFlags__          system_flags;
                struct __ScalpiTerminalInput__     input;
                struct __ScalpiTerminalOutput__    output;
            };
    // crypto
        // Sha1_Streaming
            struct Sha1_Streaming {







|







719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
                // use __ScalpiTerminalInput_grab__ in loop for get keys
                
                size_t ungrabed;
                char buffer[__ScalpiTerminalInput_size__];
            };
            
            struct __ScalpiTerminal__ {
                struct __ScalpiConsole__           *console;
                struct __OsConsoleFlags__          system_flags;
                struct __ScalpiTerminalInput__     input;
                struct __ScalpiTerminalOutput__    output;
            };
    // crypto
        // Sha1_Streaming
            struct Sha1_Streaming {
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
            struct __AppEditorHistoryNote__ {
                __ScalpiConsoleAnsiInputKey__   key;
                struct __ScalpiMemListLink__    link;
            };
        // # App
            struct App {
                struct __OsHelper__    __App_osHelper__;
                struct Scalpi_Logger   logger;
                uint64_t               tick;
            };
// function prototypes
    void __OsFile_truncate__(            __OsFileHandle__ file);
    void   __OsFile_setPos__(            __OsFileHandle__ file, size_t pos);
    bool   __OsMem_alloc__(              uintptr_t *ret_data_addr, size_t size);
    void   __OsMem_free__(               uintptr_t ret_data_addr);







|







797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
            struct __AppEditorHistoryNote__ {
                __ScalpiConsoleAnsiInputKey__   key;
                struct __ScalpiMemListLink__    link;
            };
        // # App
            struct App {
                struct __OsHelper__    __App_osHelper__;
                struct __ScalpiLogger__   logger;
                uint64_t               tick;
            };
// function prototypes
    void __OsFile_truncate__(            __OsFileHandle__ file);
    void   __OsFile_setPos__(            __OsFileHandle__ file, size_t pos);
    bool   __OsMem_alloc__(              uintptr_t *ret_data_addr, size_t size);
    void   __OsMem_free__(               uintptr_t ret_data_addr);
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
                return (a + b - 1) / b;
            }
        // Scalpi_Text_writeU64AsText
            size_t Scalpi_Text_writeU64AsTextToBuffer(char buffer[], uint64_t number, size_t min_width) { // utoa utos
                size_t writed = 0;
                
                // write number to tmp
                char buffer_tmp[Scalpi_Text_CharsDecFromU64_MAX_LEN];
                uintptr_t tmp_ptr = (uintptr_t) &buffer_tmp[0] + Scalpi_Text_CharsDecFromU64_MAX_LEN;
                for (uint64_t num = number; num > 0; num = num / 10) {
                    uint8_t remainder = num % 10;
                    tmp_ptr--;
                    *(char*)tmp_ptr = '0' + (char) remainder;
                }
                const uintptr_t writed_tmp = (uintptr_t) &buffer_tmp[0] + Scalpi_Text_CharsDecFromU64_MAX_LEN - (uintptr_t) tmp_ptr;
                
                // fill zeroes to min_width
                size_t extra_fill = 0;
                if (min_width > writed_tmp) {
                    extra_fill = min_width - writed_tmp;
                    __ScalpiMem_fill__(&buffer[0], '0', extra_fill);
                    writed += extra_fill;
                }
                
                if (writed_tmp > 0) {
                    __ScalpiMem_copy__(&buffer[writed], (char*)tmp_ptr, writed_tmp);
                    writed += writed_tmp;
                }
                return writed;
            }
            
            size_t __ScalpiText_writeU64AsTextToWriteFnVoid__(__WriteFnPtrVoid__ fn_write, void* context, uint64_t number, size_t min_width) {
                char buffer_tmp[Scalpi_Text_CharsDecFromU64_MAX_LEN];
                const size_t writed = Scalpi_Text_writeU64AsTextToBuffer(&buffer_tmp[0], number, min_width);
                fn_write(context, buffer_tmp, writed);
                return writed;
            }
        // ZText - zero ended text 
            // # __ZText_fromBytes__
                void __ZText_fromBytes__(char* buffer, const char bytes[], size_t bytes_len) {
                    // expected buffer_len >= bytes_len + 1
                    
                    __ScalpiMem_copy__(buffer, bytes, bytes_len);
                    buffer[bytes_len] = 0;
                }







|
|


|


|

















|




|







1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
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
                return (a + b - 1) / b;
            }
        // Scalpi_Text_writeU64AsText
            size_t Scalpi_Text_writeU64AsTextToBuffer(char buffer[], uint64_t number, size_t min_width) { // utoa utos
                size_t writed = 0;
                
                // write number to tmp
                char buffer_tmp[__ScalpiTextCharsDecFromU64_lenMax__];
                uintptr_t tmp_ptr = (uintptr_t) &buffer_tmp[0] + __ScalpiTextCharsDecFromU64_lenMax__;
                for (uint64_t num = number; num > 0; num = num / 10) {
                    uint8_t remainder = num % 10;
                    tmp_ptr-=1;
                    *(char*)tmp_ptr = '0' + (char) remainder;
                }
                const uintptr_t writed_tmp = (uintptr_t) &buffer_tmp[0] + __ScalpiTextCharsDecFromU64_lenMax__ - (uintptr_t) tmp_ptr;
                
                // fill zeroes to min_width
                size_t extra_fill = 0;
                if (min_width > writed_tmp) {
                    extra_fill = min_width - writed_tmp;
                    __ScalpiMem_fill__(&buffer[0], '0', extra_fill);
                    writed += extra_fill;
                }
                
                if (writed_tmp > 0) {
                    __ScalpiMem_copy__(&buffer[writed], (char*)tmp_ptr, writed_tmp);
                    writed += writed_tmp;
                }
                return writed;
            }
            
            size_t __ScalpiText_writeU64AsTextToWriteFnVoid__(__WriteFnPtrVoid__ fn_write, void* context, uint64_t number, size_t min_width) {
                char buffer_tmp[__ScalpiTextCharsDecFromU64_lenMax__];
                const size_t writed = Scalpi_Text_writeU64AsTextToBuffer(&buffer_tmp[0], number, min_width);
                fn_write(context, buffer_tmp, writed);
                return writed;
            }
        // ZText - zero ended text
            // # __ZText_fromBytes__
                void __ZText_fromBytes__(char* buffer, const char bytes[], size_t bytes_len) {
                    // expected buffer_len >= bytes_len + 1
                    
                    __ScalpiMem_copy__(buffer, bytes, bytes_len);
                    buffer[bytes_len] = 0;
                }
1182
1183
1184
1185
1186
1187
1188
1189

1190
1191
1192
1193
1194
1195
1196
                    const size_t len = __ZText_countLen__(data);
                    __ScalpiMem_copy__(buffer, data, len);
                    return len;
                }
            // # __ZText_writeToWriteFn__
                size_t __ZText_writeToWriteFn__(__WriteFnPtr__ fn_write, void* context, const char text[]) {
                    const size_t len = __ZText_countLen__(text);
                    return fn_write(context, text, len);

                }
    // Os
        // mem
            // # __OsMem_alloc__
                bool __OsMem_alloc__( // TODO use real system alloc?
                    uintptr_t  *ret,
                    size_t     size







|
>







1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
                    const size_t len = __ZText_countLen__(data);
                    __ScalpiMem_copy__(buffer, data, len);
                    return len;
                }
            // # __ZText_writeToWriteFn__
                size_t __ZText_writeToWriteFn__(__WriteFnPtr__ fn_write, void* context, const char text[]) {
                    const size_t len = __ZText_countLen__(text);
                    fn_write(context, text, len);
                    return len;
                }
    // Os
        // mem
            // # __OsMem_alloc__
                bool __OsMem_alloc__( // TODO use real system alloc?
                    uintptr_t  *ret,
                    size_t     size
2121
2122
2123
2124
2125
2126
2127







2128
2129
2130
2131
2132
2133
2134
                                size_t delta = indent - new_indent;
                                __Buffer_removeIndent__(buffer, buffer_used, delta);
                            }
                        }
                    return ok;
                }
        // File







            // FileComplete 
                // # __ScalpiFileComplete_clear__
                    bool __ScalpiFileComplete_clear__(
                        const char*  file_name, 
                        size_t       file_name_len
                    ) {
                        bool ok = true;







>
>
>
>
>
>
>







2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
                                size_t delta = indent - new_indent;
                                __Buffer_removeIndent__(buffer, buffer_used, delta);
                            }
                        }
                    return ok;
                }
        // File
            // # __File_clear__
                void __ScalpiFile_clear__(
                    __OsFileHandle__ file
                ) {
                    __OsFile_setPos__(file, 0);
                    __OsFile_truncate__(file);
                }
            // FileComplete 
                // # __ScalpiFileComplete_clear__
                    bool __ScalpiFileComplete_clear__(
                        const char*  file_name, 
                        size_t       file_name_len
                    ) {
                        bool ok = true;
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
                    size_t ci = 0; // cyclical iterator
                    for (size_t pos = 0; pos < dest_len; pos++) {
                        dest[pos] = a[pos] ^ b[ci];
                        ci += 1;
                        if (ci == b_len) ci = 0;
                    }
                }
        // Scalpi_Logger
            void Scalpi_Logger_init (struct Scalpi_Logger* t) {
                for (int i = 0; i < __arrayLen__(t->writers); i++) {
                    struct __Scalpi_Writer__* w = &t->writers[i];
                    w->context = 0;
                    w->write = 0;
                }
            }
            
            void __ScalpiLogger_writeToSelf__(struct Scalpi_Logger* t, const char bytes[], size_t len) {
                for (size_t i = 0; i < __arrayLen__(t->writers); i++) {
                    struct __Scalpi_Writer__* w = &t->writers[i];
                    if (w->write) {
                        size_t writed = w->write(w->context, bytes, len);
                    }
                }
            }
        // __ScalpiTerminalOutput_CursorPos__
            void __ScalpiTerminalOutputCursorPos_init__(__ScalpiTerminalOutput_CursorPos__ *cursor_pos) {







|
|

|





|

|







2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
                    size_t ci = 0; // cyclical iterator
                    for (size_t pos = 0; pos < dest_len; pos++) {
                        dest[pos] = a[pos] ^ b[ci];
                        ci += 1;
                        if (ci == b_len) ci = 0;
                    }
                }
        // __ScalpiLogger__
            void __ScalpiLogger_init__ (struct __ScalpiLogger__* t) {
                for (int i = 0; i < __arrayLen__(t->writers); i++) {
                    struct __ScalpiWriter__* w = &t->writers[i];
                    w->context = 0;
                    w->write = 0;
                }
            }
            
            void __ScalpiLogger_writeToSelf__(struct __ScalpiLogger__* t, const char bytes[], size_t len) {
                for (size_t i = 0; i < __arrayLen__(t->writers); i++) {
                    struct __ScalpiWriter__* w = &t->writers[i];
                    if (w->write) {
                        size_t writed = w->write(w->context, bytes, len);
                    }
                }
            }
        // __ScalpiTerminalOutput_CursorPos__
            void __ScalpiTerminalOutputCursorPos_init__(__ScalpiTerminalOutput_CursorPos__ *cursor_pos) {
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
                }
            // # __AppEditorHistoryNote_alloc__
                bool __AppEditorHistoryNote_alloc__(
                    struct __AppEditorHistoryNote__  **ptr
                ) {
                    return __AlignedPtr_allocAny__( ptr, __alignOf__(struct __AppEditorHistoryNote__), sizeof(struct __AppEditorHistoryNote__) );
                }
        // # App_init
            bool App_init(struct App* t) {
                bool ok = true;
                    Scalpi_Logger_init(&t->logger); // preinit console output for debug
                    
                    if (__OsHelper_init__(&t->__App_osHelper__)) {
                        t->tick = __os_getTick__();
                        
                        if (!ok) __OsHelper_deinit__(&t->__App_osHelper__);
                    } else {
                        ok = false;
                        printf("%d app.os_helper not inited\r\n", __LINE__);
                    }
                    
                return ok;
            }
        // # App_deinit
            void App_deinit(struct App* app) {
                __OsHelper_deinit__(&app->__App_osHelper__);
            }
        // # App_process
            bool App_process(struct App* t) {
                bool ok = true;
                    __OsHelper_process__(&t->__App_osHelper__);
                return ok;
            }
        // # App_waitToNextFrame
            void App_waitToNextFrame(struct App* t) {
                uint64_t expected_frame_end_time = t->tick + Scalpi_time_ms_per_s / App_expected_fps;
                uint64_t resulting_frame_end_time = __os_getTick__();
                if (resulting_frame_end_time > expected_frame_end_time + 120) {
                    uint64_t delta = resulting_frame_end_time - expected_frame_end_time;
                    printf("%d \t  hitch detection: %zu delta: %zu ms \r\n", __LINE__, t->tick, delta);
                }
                uint64_t delay_sleep = 1;
                if (resulting_frame_end_time < expected_frame_end_time) {







|
|

|












|
|


|
|




|
|
|







2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
                }
            // # __AppEditorHistoryNote_alloc__
                bool __AppEditorHistoryNote_alloc__(
                    struct __AppEditorHistoryNote__  **ptr
                ) {
                    return __AlignedPtr_allocAny__( ptr, __alignOf__(struct __AppEditorHistoryNote__), sizeof(struct __AppEditorHistoryNote__) );
                }
        // # __App_init__
            bool __App_init__(struct App* t) {
                bool ok = true;
                    __ScalpiLogger_init__(&t->logger); // preinit console output for debug
                    
                    if (__OsHelper_init__(&t->__App_osHelper__)) {
                        t->tick = __os_getTick__();
                        
                        if (!ok) __OsHelper_deinit__(&t->__App_osHelper__);
                    } else {
                        ok = false;
                        printf("%d app.os_helper not inited\r\n", __LINE__);
                    }
                    
                return ok;
            }
        // # __App_deinit__
            void __App_deinit__(struct App* app) {
                __OsHelper_deinit__(&app->__App_osHelper__);
            }
        // # __App_process__
            bool __App_process__(struct App* t) {
                bool ok = true;
                    __OsHelper_process__(&t->__App_osHelper__);
                return ok;
            }
        // # __App_waitToNextFrame__
            void __App_waitToNextFrame__(struct App* t) {
                uint64_t expected_frame_end_time = t->tick + __ScalpiTime_msPerS__ / __App_expectedFps__;
                uint64_t resulting_frame_end_time = __os_getTick__();
                if (resulting_frame_end_time > expected_frame_end_time + 120) {
                    uint64_t delta = resulting_frame_end_time - expected_frame_end_time;
                    printf("%d \t  hitch detection: %zu delta: %zu ms \r\n", __LINE__, t->tick, delta);
                }
                uint64_t delay_sleep = 1;
                if (resulting_frame_end_time < expected_frame_end_time) {
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360

2361
2362
2363
2364
2365
2366
2367
2368
            return true;
        }
        
        bool real_main(int args_len, char** args_ptr) {
            bool ok = true;
                if (tests()) {
                    printf("%d success tests \r\n", __LINE__);
                    if (false and App_init(&global_app)) {
                        while(true) {
                            if (!App_process(&global_app)) break;
                            App_waitToNextFrame(&global_app);
                        }
                        App_deinit(&global_app);
                        return true;
                    } else {

                        printf("%d fail: App_init\r\n", __LINE__);
                    } 
                } else {
                    ok = false;
                    printf("%d fail tests \r\n", __LINE__);
                }
            return ok;
        }







|

|
|

|
<

>
|







2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381

2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
            return true;
        }
        
        bool real_main(int args_len, char** args_ptr) {
            bool ok = true;
                if (tests()) {
                    printf("%d success tests \r\n", __LINE__);
                    if (false and __App_init__(&global_app)) {
                        while(true) {
                            if (!__App_process__(&global_app)) break;
                            __App_waitToNextFrame__(&global_app);
                        }
                        __App_deinit__(&global_app);

                    } else {
                        ok = false;
                        printf("%d fail: __App_init__\r\n", __LINE__);
                    } 
                } else {
                    ok = false;
                    printf("%d fail tests \r\n", __LINE__);
                }
            return ok;
        }