Fresh IDE . Check-in [695640ceff]
Not logged in

This repository is a mirror!

The original is located on: https://fresh.flatassembler.net/fossil/repo/fresh
If you want to follow the project, please update your remote-url

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Merged with the latest FreshLibDev.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:695640ceff44c27e8099c65a92d82a4efcda6eb3
User & Date: johnfound 2018-12-05 09:21:38
Context
2018-12-05
11:32
More readable comments. check-in: 17292b7f38 user: johnfound tags: trunk
09:21
Merged with the latest FreshLibDev. check-in: 695640ceff user: johnfound tags: trunk
09:18
Fixed small bug in procedure Exec. check-in: 58b8de14c7 user: johnfound tags: FreshLibDev
08:57
TeX to HTML tool TTH updated to v4.12 check-in: 1d5ab4479e user: johnfound tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to freshlib/data/all.asm.

1
2
3
4
5
6
7

8
9
10
11
12
13
14
15
16
include 'i18n.asm'
include 'arrays.asm'
include 'strlib.asm'
include 'base64.asm'
include 'uconfig.asm'
include 'memstream.asm'
include 'markdown.asm'

include 'hashes.asm'

include 'bitstream.asm'
include 'bytestream.asm'
include 'deflate.asm'

include 'buffergap.asm'
include 'counter_array.asm'
include 'random.asm'







>









1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
include 'i18n.asm'
include 'arrays.asm'
include 'strlib.asm'
include 'base64.asm'
include 'uconfig.asm'
include 'memstream.asm'
include 'markdown.asm'
include 'bbcode.asm'
include 'hashes.asm'

include 'bitstream.asm'
include 'bytestream.asm'
include 'deflate.asm'

include 'buffergap.asm'
include 'counter_array.asm'
include 'random.asm'

Added freshlib/data/bbcode.asm.













































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
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
451
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
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
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
522
523
524
525
526
527
528
529
530
531
532
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
560
561
562
563
564
565
566
567
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
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
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
module "BBCode translator"

iglobal
PHashTable tableBBtags, tpl_func,                      \
        'b',       tagStrong,                          \
        '*',       tagListItem,                        \
        'i',       tagEm,                              \
        'u',       tagUnderlined,                      \
        's',       tagDel,                             \
        'c',       tagInlineCode,                      \
        'url',     tagURL,                             \
        'img',     tagImg,                             \
        'quote',   tagQuote,                           \
        'code',    tagCode,                            \
        'size',    tagSize,                            \
        'color',   tagColor,                           \
        'list',    tagUL,                              \
        'ul',      tagUL,                              \
        'ol',      tagOL,                              \
        'table',   tagTable,                           \
        'tr',      tagTR,                              \
        'th',      tagTH,                              \
        'td',      tagTD,                              \
        'spoiler', tagSpoiler,                         \
        'email',   tagEmail,                           \
        'h1',      tagH1,                              \
        'h2',      tagH2,                              \
        'h3',      tagH3,                              \
        'h4',      tagH4,                              \
        'h5',      tagH5,                              \
        'h6',      tagH6,                              \
        ':)',      emoSmile,                           \
        ':d',      emoLol,                             \
        ':lol:',   emoRofl,                            \
        ';)',      emoWink,                            \
        ':p',      emoTongue,                          \
        ':(',      emoSad,                             \
        ':`(',     emoCry,                             \
        '>:(',     emoAngry
endg

struct TOneTag
  .pOpenP    dd ?       ; Open tag prefix. for example '<img src="'
  .lOpenP    dd ?
  .pOpenS    dd ?       ; Open tag suffix. for example '" alt="'
  .lOpenS    dd ?
  .pClose    dd ?       ; Close tag. for example '" />'
  .lClose    dd ?
  .flags     dd ?       ; encoding flags for this tag. the first byte contain flags for the text between .pOpenP and .pOpenS
                        ; the second byte for the text between .pOpenS and .pClose
ends

; examples:
; [b]:                                  '<b>', 0, '</b>'
; [quote=title]text[/quote]:            '<blockquote><header>', '</header>', '</blockquote>'
; [img]image_url[/img]:                 '<img alt="', '" src="', '" />'
; [code=language][/code]:               '<code class="', '">', '</code>'


struc flex [arg] {
common
  local f1, f2, cnt, sz
  cnt = 0
  sz = 0
  f1 = 1
  f2 equ FALSE
forward
  match any, arg \{
    match `arg, arg \\{ f2 equ TRUE \\}
  \}

  cnt = cnt + 1
  if arg eqtype ''
    virtual at 0
      db arg
      sz = sz + $
    end virtual
  end if

common
  local lbl

  match =txt string, arg \{
    f1 = 0
    lbl text string
    f2 equ FALSE
  \}

  if (sz > 4) | (cnt>1)
    f1 = 0
  end if

  if f1
    . = arg
    .length = 0
  else
    . = lbl
    .length = lbl#\.length
  end if
  match =TRUE, f2 \{ lbl text arg \}
}


struc onetag prefix, suffix, close, flags {
common
  local ..pref, ..suff, ..close
  local ..fpr, ..fsf, ..fcl

  label . dword
if used .
  ..pref flex prefix
  ..suff flex suffix
  ..close flex close

  dd ..pref, ..pref#\.length
  dd ..suff, ..suff#\.length
  dd ..close, ..close#\.length
  dd flags
end if
}

fEmptyAttr    = $00000001        ; empty value of the attribute is acceptable.
fBlockTag     = $00000002        ; This is a block tag. Allows paragraph generation and resets its state.
fDisableTags  = $00000004        ; Disable tag generation inside this block; The only tag that is recongized is the respective closing tag.
fLines        = $00000008        ; the tag can contain text lines.
fInlineTag    = $00000010
fMinimagBlock = $80000000        ; The tags, that are open/close by ;tagname/;end in MiniMagAsm

iglobal
  align 4

  tagStrong       onetag txt '<strong>',                              0,              txt '</strong>',    fInlineTag
  tagEm           onetag txt '<em>',                                  0,              txt '</em>',        fInlineTag
  tagUnderlined   onetag txt '<span class="underlined">',             0,              txt '</span>',      fInlineTag
  tagDel          onetag txt '<del>',                                 0,              txt '</del>',       fInlineTag
  tagInlineCode   onetag txt '<code>',                                0,              txt '</code>',      fInlineTag
  tagCode         onetag txt '<code class="block ',                   txt '">',       txt '</code>',      fBlockTag or fEmptyAttr or fDisableTags or fMinimagBlock
  tagQuote        onetag txt '<blockquote><header>',                  txt '</header>',txt '</blockquote>',fBlockTag or fEmptyAttr or fMinimagBlock
  tagUL           onetag txt '<ul>',                                  0,              txt '</ul>',        fBlockTag or fMinimagBlock
  tagOL           onetag txt '<ol type="',                            txt '">',       txt '</ol>',        fBlockTag or fEmptyAttr or fMinimagBlock
  tagListItem     onetag txt '<li>',                                  0,              txt '</li>',        fBlockTag
  tagTable        onetag txt '<table>',                               0,              txt '</table>',     fBlockTag or fMinimagBlock
  tagTR           onetag txt '<tr>',                                  0,              txt '</tr>',        fBlockTag
  tagTH           onetag txt '<th>',                                  0,              txt '</th>',        fBlockTag
  tagTD           onetag txt '<td>',                                  0,              txt '</td>',        fBlockTag
  tagSpoiler      onetag txt '<details><summary>',                   txt '</summary>',txt '</details>',   fBlockTag or fMinimagBlock
  tagURL          onetag txt '<a href="',                             txt '">',       txt '</a>',         0
  tagImg          onetag txt '<img alt="',                            txt '" src="',  txt '" />',         fBlockTag or fDisableTags
  tagSize         onetag txt '<span style="font-size:',               txt '">',       txt '</span>',      fInlineTag
  tagColor        onetag txt '<span style="color:',                   txt '">',       txt '</span>',      fInlineTag
  tagEmail        onetag txt '<a href="mailto:',                      txt '">',       txt '</a>',         0
  tagH1           onetag txt '<h1>',                                  0,              txt '</h1>',        fBlockTag or fLines
  tagH2           onetag txt '<h2>',                                  0,              txt '</h2>',        fBlockTag or fLines
  tagH3           onetag txt '<h3>',                                  0,              txt '</h3>',        fBlockTag or fLines
  tagH4           onetag txt '<h4>',                                  0,              txt '</h4>',        fBlockTag or fLines
  tagH5           onetag txt '<h5>',                                  0,              txt '</h5>',        fBlockTag or fLines
  tagH6           onetag txt '<h6>',                                  0,              txt '</h6>',        fBlockTag or fLines
  tagPara         onetag txt '<p>',                                   0,              txt '</p>',         fLines
  tagHR           onetag txt '<hr>',                                  0,              0,                  0

  ; Emoticons tags.

  emoSmile        onetag <'<img class="emoticon" src="', EMOTICONS_PATH, 'smile.gif" alt=":)">'>,   0,              0,              0
  emoLol          onetag <'<img class="emoticon" src="', EMOTICONS_PATH, 'lol.gif" alt=":D">'>,     0,              0,              0
  emoRofl         onetag <'<img class="emoticon" src="', EMOTICONS_PATH, 'rofl.gif" alt=":D">'>,    0,              0,              0
  emoWink         onetag <'<img class="emoticon" src="', EMOTICONS_PATH, 'wink.gif" alt=";)">'>,    0,              0,              0
  emoTongue       onetag <'<img class="emoticon" src="', EMOTICONS_PATH, 'tongue.gif" alt=":P">'>,  0,              0,              0
  emoSad          onetag <'<img class="emoticon" src="', EMOTICONS_PATH, 'sad.gif" alt=":(">'>,     0,              0,              0
  emoCry          onetag <'<img class="emoticon" src="', EMOTICONS_PATH, 'cry.gif" alt=":`(">'>,    0,              0,              0
  emoAngry        onetag <'<img class="emoticon" src="', EMOTICONS_PATH, 'angry.gif" alt=">:(">'>,  0,              0,              0

endg

cParagraphTag text "<p>"

;--------------------------------------------------------------
; Converts BB code into HTML. Starts from the position [.from]
; and ends at the end of the text or at first NULL character.
;
; Arguments:
;    .pBBCode - pointer to the TText structure with the BBCode
;               formatted text.
;    .from    - the position where to start.
;
; Returns:
;    edx - The same structure (possibly reallocated) with
;    the translated to html code text.
;

proc TranslateBBCode, .pBBCode, .from
.pStack dd ?
.ofsStart dd ?
.tagType  dd ?
.tagFlags dd ?

.fNewLine dd ?
begin
        pushad

        stdcall CreateArray, 4
        mov     [.pStack], eax

        or      [.fNewLine], -1 ; first new line implicit.
        and     [.tagFlags], 0

        mov     edx, [.pBBCode]

        OutputValue "BBCode TText.GapBegin: ", [edx+TText.GapBegin], 10, -1
        OutputValue "               GapEnd: ", [edx+TText.GapEnd], 10, -1
        OutputValue "               Length: ", [edx+TText.Length], 10, -1
        OutputValue "       Translate from: ", [.from], 10, -1

        mov     ebx, [.from]
        jmp     .loop

.next:
        inc     ebx

.loop:
        mov     ecx, [edx+TText.GapEnd]
        cmp     ebx, [edx+TText.GapBegin]
        cmovb   ecx, [edx+TText.GapBegin]
        sub     ecx, [edx+TText.GapBegin]
        add     ecx, ebx
        cmp     ecx, [edx+TText.Length]
        jae     .end_of_text

        movzx   eax, byte [edx+ecx]

        test    al, al
        jz      .end_of_text

        cmp     al, $0d
        je      .new_line

        cmp     al, $0a
        je      .new_line

        cmp     al, $20
        jbe     .next           ; skip all whitespace

        cmp     al, "["
        je      .start_tag

.continue:
        cmp     [.fNewLine], 1
        mov     [.fNewLine], 0
        ja      .insert_paragraph

; html encoding from here

        test    al, al          ; all values > 127 are unicode and should not be encoded.
        js      .next

        movzx   eax, byte [tbl_html+eax]
        test    al, al
        jz      .del_char
        jns     .next           ; the same as above

        lea     esi, [eax+tbl_html]     ; the address of the replacement string.
        lodsb
        movzx   ecx, al         ; length

; insert the replacement html encoding from esi
        stdcall TextMoveGap, edx, ebx
        stdcall TextSetGapSize, edx, ecx
        inc     [edx+TText.GapEnd]      ; delete the previous char.

        mov     edi, [edx+TText.GapBegin]
        add     edi, edx
        add     [edx+TText.GapBegin], ecx
        add     ebx, ecx

        rep movsb
        jmp     .loop

.del_char:
        stdcall TextMoveGap, edx, ebx
        inc     [edx+TText.GapEnd]      ; delete the current char.
        jmp     .loop

.not_a_tag_pop:

        add     esp, 4

.not_a_tag:

        mov     ebx, [.ofsStart]
        mov     eax, "["
        jmp     .continue

;------------------------------------------------------------------------------------

.new_line:
        inc     ebx

        mov     ecx, [edx+TText.GapEnd]
        cmp     ebx, [edx+TText.GapBegin]
        cmovb   ecx, [edx+TText.GapBegin]
        sub     ecx, [edx+TText.GapBegin]
        add     ecx, ebx
        cmp     ecx, [edx+TText.Length]
        jae     .end_of_text

        inc     [.fNewLine]

        xor     al, byte [edx+ecx]
        cmp     al, $0a xor $0d
        jne     .loop
        jmp     .next   ; skip the next char. it is part of CRLF (or LFCR sequence).

;-----------------------------------------------------------------------------

.insert_paragraph:
        and     [.fNewLine], 0

        test    [.tagFlags], fDisableTags
        jnz     .loop

        stdcall TextMoveGap, edx, ebx
        stdcall TextSetGapSize, edx, 4
        mov     eax, [edx+TText.GapBegin]
        mov     dword [edx+eax], "<p>"
        add     [edx+TText.GapBegin], 3
        add     ebx, 3

        jmp     .loop

;------------------------------------------------------------------------------------

.start_tag:

        xor     ecx, ecx
        mov     [.ofsStart], ebx

.first_non_ws:
        inc     ebx

        mov     esi, [edx+TText.GapEnd]
        cmp     ebx, [edx+TText.GapBegin]
        cmovb   esi, [edx+TText.GapBegin]
        sub     esi, [edx+TText.GapBegin]
        add     esi, ebx
        cmp     esi, [edx+TText.Length]
        jae     .not_a_tag

        mov     al, [edx+esi]

        test    al, al
        jz      .not_a_tag

        cmp     al, ' '
        jbe     .first_non_ws

        mov     edi, ebx        ; the start of the hash name

        cmp     al, "/"
        je      .closing_tag

        test    [.tagFlags], fDisableTags
        jnz     .loop

.hash1:
        cmp     al, "="
        je      .tag_found
        cmp     al, "]"
        je      .tag_found

        mov     ah, al
        and     ah, $40
        shr     ah, 1
        or      al, ah  ; case insensitive hash.

        xor     cl, al
        mov     cl, [ tpl_func + ecx]

        inc     ebx

        mov     esi, [edx+TText.GapEnd]
        cmp     ebx, [edx+TText.GapBegin]
        cmovb   esi, [edx+TText.GapBegin]
        sub     esi, [edx+TText.GapBegin]
        add     esi, ebx
        cmp     esi, [edx+TText.Length]
        jae     .not_a_tag

        mov     al, [edx+esi]
        jmp     .hash1


.tag_found:

        mov     [.tagType], eax ; al = "=" or "]"

        mov     esi, [tableBBtags + sizeof.TPHashItem * ecx + TPHashItem.pKeyname]
        test    esi, esi
        jz      .not_a_tag      ; empty hash table cell.

        push    ecx

        mov     eax, ebx
        sub     eax, edi        ; the length of the tag
        movzx   ecx, byte [esi-1]  ; the length of the string in the hash table.
        cmp     ecx, eax
        jne     .not_a_tag_pop

        lea     eax, [ebx+1]
        stdcall TextMoveGap, edx, eax           ; the gap is after the tag, so, the offset and the position are the same.

        add     edi, edx           ; = pointer to the tag start. (edi contains the offset);
        xchg    esi, edi

.cmp_loop:
        dec     ecx
        js      .equal

        lodsb

        mov     ah, al
        and     ah, $40
        shr     ah, 1
        or      al, ah

        scasb
        je      .cmp_loop
        jmp     .not_a_tag_pop   ; the strings are different, so it is a collision. Ignore.

.equal:
        pop     ecx

; the tag name is the same!

        mov     eax, [tableBBtags + sizeof.TPHashItem * ecx + TPHashItem.Value]
        cmp     [eax+TOneTag.pClose], 0
        je      .stack_ok                       ; no need to push to the stack tags without closing tag.

        push    edx
        stdcall AddArrayItems, [.pStack], 1
        mov     [.pStack], edx
        mov     [eax], ecx      ; the last tag for close.
        pop     edx

.stack_ok:

        mov     edi, ebx   ; edi points one char before the attribute value or to the tag content value, depending on the tag type (with or without attribute).
        add     edi, [edx+TText.GapEnd]
        sub     edi, [edx+TText.GapBegin]

.skip_ws1:
        inc     edi
        cmp     edi, [edx+TText.Length]
        jae     .attr_here                      ; it is an empty attribute actually...

        cmp     byte [edx+edi], 0
        je      .attr_here

        cmp     byte [edx+edi], ' '
        jbe     .skip_ws1

.attr_here:
        add     edi, [edx+TText.GapBegin]
        sub     edi, [edx+TText.GapEnd]

; Here edi contains the position of the first non whitespace character of the attribute.
; Don't forget to increment it accordingly on inserting text before it.

        OutputValue "Open tag with hash=", ecx, 10, -1

        mov     eax, [edx+TText.GapBegin]
        sub     eax, [.ofsStart]

        sub     [edx+TText.GapBegin], eax       ; delete the start of the tag.
        sub     ebx, eax                        ; move ebx back, because of the deleted tag text.
        sub     edi, eax

        mov     eax, [tableBBtags + sizeof.TPHashItem * ecx + TPHashItem.Value]

        push    [eax+TOneTag.flags]
        pop     [.tagFlags]

        test    [.tagFlags], fBlockTag
        jnz     .clear_newline

        cmp     [.fNewLine], 1
        jbe     .copy_tag_prefix

        mov     esi, cParagraphTag
        mov     ecx, cParagraphTag.length
        add     edi, ecx
        call    .copy_tag

.clear_newline:

        and     [.fNewLine], 0

.copy_tag_prefix:
        mov     esi, [eax+TOneTag.pOpenP]
        mov     ecx, [eax+TOneTag.lOpenP]
        add     edi, ecx
        call    .copy_tag

        mov     esi, [eax+TOneTag.pOpenS]
        mov     ecx, [eax+TOneTag.lOpenS]
        test    esi, esi
        jz      .mono_open_tag  ; the open tag consists of only one part, without attributes.

        cmp     byte [.tagType], '='
        je      .process_attribute

        test    [eax+TOneTag.flags], fEmptyAttr         ; if the tag allows empty attribute, simply copy
        jnz     .copy                                   ; the tag suffix without trying to replace the attribute.

; here copy and encode the attribute value:
.process_attribute:
        inc     ebx

        push    esi ecx

        lea     esi, [edi-1]

.attr_loop:
        inc     esi

        mov     eax, esi
        add     eax, [edx+TText.GapEnd]
        sub     eax, [edx+TText.GapBegin]    ; eax = eax + (GapEnd - GapBegin)
        cmp     eax, [edx+TText.Length]
        jae     .end_of_attr2

        movzx   eax, byte [edx+eax]

        test    al, al
        jz      .end_of_attr2

        cmp     al, "]"
        je      .end_of_attr1

        cmp     al, "["
        je      .end_of_attr2

; encode with HTML encoding.

        test    al, al          ; all values > 127 are unicode and should not be encoded.
        js      .store_char

        movzx   eax, byte [tbl_html+eax]
        test    al, al
        jz      .attr_loop
        jns     .store_char     ; it is non-encodable character, just copy it.

        push    esi

        lea     esi, [eax+tbl_html]     ; the address of the replacement string.
        lodsb
        movzx   ecx, al         ; length

        stdcall TextSetGapSize, edx, ecx
        mov     edi, [edx+TText.GapBegin]
        add     edi, edx
        add     [edx+TText.GapBegin], ecx
        add     ebx, ecx
        add     [esp], ecx      ; increase ESI that is in the stack right now.

        rep movsb
        pop     esi
        jmp     .attr_loop

.store_char:
        stdcall TextSetGapSize, edx, 1
        mov     edi, [edx+TText.GapBegin]
        mov     [edx+edi], al
        inc     [edx+TText.GapBegin]
        inc     ebx
        inc     esi
        jmp     .attr_loop


.end_of_attr1:

        inc     esi     ; delete "]"
        dec     ebx

        add     esi, [edx+TText.GapEnd]
        sub     esi, [edx+TText.GapBegin]
        mov     [edx+TText.GapEnd], esi

.end_of_attr2:

        pop     ecx esi

.copy:
        call    .copy_tag
        test    [.tagFlags], fBlockTag
        jz      .next

        mov     [.fNewLine], 2  ; after start of a block tag, the first text starts a paragraph.
        jmp     .next


.mono_open_tag:

        cmp     byte [.tagType], '='
        jne     .next

; search the end of the attribute

        dec     edi
        add     edi, [edx+TText.GapEnd]
        sub     edi, [edx+TText.GapBegin]    ; edi = edi + (GapEnd - GapBegin)

.attr_loop2:
        inc     edi
        cmp     edi, [edx+TText.Length]
        jae     .end_of_attr3

        cmp     byte [edx+edi], 0
        je      .end_of_attr3

        cmp     byte [edx+edi], "]"
        jne     .attr_loop2

        inc     edi

.end_of_attr3:
        mov     [edx+TText.GapEnd], edi
        jmp     .next


.closing_tag:

.hash2:
        inc     ebx

        mov     esi, [edx+TText.GapEnd]
        cmp     ebx, [edx+TText.GapBegin]
        cmovb   esi, [edx+TText.GapBegin]
        sub     esi, [edx+TText.GapBegin]
        add     esi, ebx
        cmp     esi, [edx+TText.Length]
        jae     .not_a_tag

        mov     al, [edx+esi]
        test    al, al
        jz      .not_a_tag

        cmp     al, "]"
        je      .close_here

        mov     ah, al
        and     ah, $40
        shr     ah, 1
        or      al, ah  ; case insensitive hash.

        xor     cl, al
        mov     cl, [ tpl_func + ecx]
        jmp     .hash2

.close_here:

        OutputValue "Closing tag with hash=", ecx, 10, -1

        inc     edi     ; skip "/" char.

        mov     esi, [tableBBtags + sizeof.TPHashItem * ecx + TPHashItem.pKeyname]
        test    esi, esi
        jz      .not_a_tag

        test    [.tagFlags], fDisableTags
        jz      .process_closing

        mov     eax, [tableBBtags + sizeof.TPHashItem * ecx + TPHashItem.Value]
        test    [eax+TOneTag.flags], fDisableTags     ; is this the same tag, that set fDisableTags
        jz      .not_a_tag

.process_closing:
        and     [.tagFlags], 0

        push    ecx

        mov     eax, ebx
        sub     eax, edi        ; the length of the tag
        movzx   ecx, byte [esi-1]  ; the length of the string in the hash table.
        cmp     ecx, eax
        jne     .not_a_tag

        lea     eax, [ebx+1]
        stdcall TextMoveGap, edx, eax           ; the gap is after the tag, so, the offset and the position are the same.

        add     edi, edx        ; the pointer to the tag start.
        xchg    esi, edi

.cmp_loop2:
        dec     ecx
        js      .equal2

        lodsb

        mov     ah, al
        and     ah, $40
        shr     ah, 1
        or      al, ah

        scasb
        je      .cmp_loop2

        pop     ecx
        jmp     .not_a_tag   ; the strings are different, so it is a collision. Ignore.

.equal2:
        pop     ecx

; the tag name is the same!

        mov     eax, [edx+TText.GapBegin]
        sub     eax, [.ofsStart]

        sub     ebx, eax                        ; move ebx back, because of the deleted tag text.
        sub     [edx+TText.GapBegin], eax       ; delete the start of the tag.

        mov     edi, [.pStack]
        mov     eax, [edi+TArray.count]
        test    eax, eax
        jz      .next           ; the stack is empty, so ignore the closing tag!

.close_loop:
        dec     eax
        js      .error_stack

        push    ecx
        mov     esi, [edi+TArray.array + 4*eax]
        mov     esi, [tableBBtags + sizeof.TPHashItem * esi + TPHashItem.Value]
        mov     ecx, [esi+TOneTag.lClose]
        mov     esi, [esi+TOneTag.pClose]
        call    .copy_tag
        pop     ecx

        cmp     ecx, [edi+TArray.array + 4*eax]
        jne     .close_loop

        mov     [edi+TArray.count], eax
        jmp     .next

.error_stack:
        inc     eax
        mov     [edi+TArray.count], eax
        jmp     .next


.end_of_text:
; here, close all open tags and free the stack array.

        stdcall TextMoveGap, edx, ebx

        mov     edi, [.pStack]
        mov     eax, [edi+TArray.count]

.closeall:
        dec     eax
        js      .finish

        mov     esi, [edi+TArray.array + 4*eax]
        mov     esi, [tableBBtags + sizeof.TPHashItem * esi + TPHashItem.Value]

        mov     ecx, [esi+TOneTag.lClose]
        mov     esi, [esi+TOneTag.pClose]
        call    .copy_tag
        jmp     .closeall

.finish:
        stdcall FreeMem, edi

        mov     [esp+4*regEDX], edx
        popad
        return


.copy_tag:
        push    edi
        stdcall TextSetGapSize, edx, ecx

        mov     edi, [edx+TText.GapBegin]
        add     edi, edx
        add     [edx+TText.GapBegin], ecx
        add     ebx, ecx

        rep movsb
        pop     edi
        retn
endp



macro HtmlEntities name, [char, encoding] {
common
  local ..tabl

  label ..tabl byte
  if used name
    label name byte
    db $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
    db $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
    db $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $2a, $2b, $2c, $2d, $2e, $2f
    db $30, $31, $32, $33, $34, $35, $36, $37, $38, $39, $3a, $3b, $3c, $3d, $3e, $3f
    db $40, $41, $42, $43, $44, $45, $46, $47, $48, $49, $4a, $4b, $4c, $4d, $4e, $4f
    db $50, $51, $52, $53, $54, $55, $56, $57, $58, $59, $5a, $5b, $5c, $5d, $5e, $5f
    db $60, $61, $62, $63, $64, $65, $66, $67, $68, $69, $6a, $6b, $6c, $6d, $6e, $6f
    db $70, $71, $72, $73, $74, $75, $76, $77, $78, $79, $7a, $7b, $7c, $7d, $7e, $7f

forward
  local ..offs, ..name, ..len

  if encoding eqtype ''
    ..name db ..len, encoding
    ..len = $ - ..name - 1
    ..offs = ..name - ..tabl
  else
    ..offs = encoding
  end if

  assert ..offs < 256

forward
  local ..char, ..ascii
  virtual at 0
    ..char db char
    load ..ascii byte from ..char
  end virtual
  assert ..ascii < 128
  store byte ..offs at ..tabl + ..ascii

common
  end if
  DispSize "HTML entities table:", $-..tabl
}


iglobal
  HtmlEntities tbl_html,        \
    $09, $0d,                   \
    $0a, $0a,                   \
    $0d, $0d,                   \
    '<', '&lt;',                \
    '>', '&gt;',                \
    '"', '&quot;',              \
    "'", '&apos;',              \
    '&', '&amp;'
endg





endmodule

Changes to freshlib/data/buffergap.asm.

136
137
138
139
140
141
142

143
144


145
146
147
148
149
150
151
...
579
580
581
582
583
584
585
































586
587
588
589
590
591
592
  else
    error "Error! Arguments must be registers!"
    err
  end if
}



; .pText        - pointer to the TText
; .position     - position of the gap in position units.



proc TextMoveGap, .pText, .position
begin
        pushad

;        int3

................................................................................
.finish:
        mov     [esp+4*regEDX], edx
        popad
        return
endp





































proc TextAddText, .pText, .position, .pTextSrc
begin
        pushad








>
|
|
>
>







 







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







136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
...
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
  else
    error "Error! Arguments must be registers!"
    err
  end if
}


; Arguments:
;   .pText        - pointer to the TText
;   .position     - position of the gap in position units.
; Returns:
;   nothing.

proc TextMoveGap, .pText, .position
begin
        pushad

;        int3

................................................................................
.finish:
        mov     [esp+4*regEDX], edx
        popad
        return
endp



proc TextAddBytes, .pText, .position, .pData, .DataLen
begin
        pushad
        mov     edx, [.pText]
        mov     esi, [.pData]

        stdcall TextSetGapSize, edx, [.DataLen]
        jc      .finish

        stdcall TextMoveGap, edx, [.position]

        mov     edi, [edx+TText.GapBegin]
        add     edi, edx
        mov     ebx, [.DataLen]

        mov     ecx, ebx
        shr     ecx, 2
        rep movsd

        mov     ecx, ebx
        and     ecx, 3
        rep movsb

        add     [edx+TText.GapBegin], ebx

.finish:
        mov     [esp+4*regEDX], edx
        popad
        return
endp




proc TextAddText, .pText, .position, .pTextSrc
begin
        pushad

Changes to freshlib/data/markdown.asm.

1
2
3
4
5
6
7
8
..
11
12
13
14
15
16
17
18


19
20
21
22
23
24
25
..
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
...
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
...
668
669
670
671
672
673
674
675
676
677



678
679
680






681

682
683




684
685
686
687
688
689
690
...
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
....
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357

1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395

















1396
1397
1398
1399
1400
1401
1402
....
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
....
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
....
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
....
1601
1602
1603
1604
1605
1606
1607






1608
1609
1610
1611
1612
1613
1614


1615
1616
1617
1618
1619
1620
1621
1622
....
1623
1624
1625
1626
1627
1628
1629




















1630
1631
1632
1633
1634
1635
1636
....
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
....
1843
1844
1845
1846
1847
1848
1849

1850
1851
1852
1853
1854
1855
1856
....
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
module "markdown parser"

struct TMarkdownResults
  .hContent     dd ?
  .hIndex       dd ?
  .hKeywords    dd ?
  .hDescription dd ?
ends
................................................................................
fcloseImage             = 2
fcloseInlineImage       = 3
fcloseObject            = 4


fblkQuote       = 1
fblkTable       = 2




fstateHeader    = $01
fstatePara      = $02
fstateWhite     = $04
fstateBold      = $08
fstateUnderline = $20
fstateStrikeout = $40
................................................................................

fstateTextNow  = $200         ; don't use the second byte for any other flags.
fstateTextPrev = $100

fstateInlineSource    =  $10000
fstateBlockSource     =  $20000
fstateTable           = $100000
fstateSubChapter      = $200000


; Translates some markdown text to HTML
; Arguments:
;     .markdown - pointer or handler of the markdown text.
;     .procFixLink - [proc .ptrLink] procedure that process the link address and returns
;                    handle to the processed link address. if [.procFixLink]=NULL, the links
;                    are inserted as they are in the HTML.
;     .fBacklinks - flag, that defines whether to insert after the headers back links to the
;                   table of contents item.
;     .pResult - pointer to TMarkdownResults structure where the result strings are returned.

;
; Returns:
;   The procedure returns  4 string handles in the TMarkdownResults structure pointed by
;   .pResult argument.

proc TranslateMarkdown2, .markdown, .procFixLink, .fBacklinks, .pResult, .lParam

................................................................................
        lea     esi, [esi+1]

.td_ok:
        or      [.state], fstatePara
        jmp     .process_char

.not_td_open:
        mov     word [edi], '<p'
        lea     edi, [edi+2]
        or      [.state], fstatePara

; is it bullet list?

        cmp     al, '*'
        jne     .close_p_tag

        cmp     byte [esi], ' '
        jne     .close_p_tag

        mov     dword [edi], ' cla'
        mov     dword [edi+4], 'ss="'
        mov     dword [edi+8], 'uli"'
        lea     edi, [edi+12]


        inc     esi
        mov     al, [esi]
        inc     esi


.close_p_tag:
        mov     byte [edi], '>'

        lea     edi, [edi+1]
        jmp     .process_char

.process_inline_code:
        mov     ecx, fstateInlineSource
        mov     ebx, 'code'
        jmp     .ProcessTag



.process_bold:
        mov     ecx, fstateBold
        mov     ebx, 'b'
        jmp     .ProcessTag



.process_italic:
        mov     ecx, fstateItalic
        mov     ebx, 'i'
        jmp     .ProcessTag



.process_underline:
        mov     ecx, fstateUnderline
        mov     ebx, 'u'
        jmp     .ProcessTag



.process_strikeout:
        mov     ecx, fstateStrikeout
        mov     ebx, 's'



; ecx = state mask
; ebx = html tag

.ProcessTag:
        mov     dl, al

        test    [.state], ecx
        jz      .start_tag

; close tag
................................................................................
        je      .normal_char

        or      [.state], ecx

; open tag
        mov     byte [edi], '<'
        lea     edi, [edi+1]

.finish_tag:
        mov     [edi], ebx




.taglen:
        lea     edi, [edi+1]






        shr     ebx, 8

        jnz     .taglen





        mov     byte [edi], '>'
        lea     edi, [edi+1]

        jmp     .scan_line2


.white_space:
................................................................................
        mov     ecx, [.last_header]
        add     ecx, '/h0>'
        mov     [edi], ecx
        lea     edi, [edi+4]

        and     [.state], not (fstateHeader or fstateTextNow)   ; For the paragraph flow, the header loops like empty line.

; after the header end, starts subchapter

        mov     dword [edi], '<div'
        mov     dword [edi+4], ' cla'
        mov     dword [edi+8], 'ss="'
        mov     dword [edi+12], 'chap'
        mov     dword [edi+16], 'ter"'
        mov     byte  [edi+20], '>'
        add     edi, 21

        or      [.state], fstateSubChapter

.crlf:
        test    [.state], fstateTextPrev or fstateTextNow
        jz     @f
        mov     word [edi], $0a0d
        lea     edi, [edi+2]
@@:
        test    al, al
        jnz     .line_start2

        call    .close_subchapter

.finish:
        mov     dword [edi], 0
        stdcall StrCat, [.result], [.pHTML]
        retn


.is_link_begin:
................................................................................
        lea     edi, [edi+9]

        and     [.state], not fstateBlockSource
        jmp     .skip2

;....................................................................

.close_paragraph:
        test    [.state], fstatePara
        jz      .close_para_ok

        call    .close_inlines
        call    .close_all_links

        test    [.state], fstateTable
        jnz     .close_td

        mov     dword [edi], '</p>'
        lea     edi, [edi+4]
        jmp     .close_para_ok

.close_td:
        mov     dword [edi], '</td'
        mov     dword [edi+4], '>'+($0a0d shl 8)
        lea     edi, [edi+7]

.close_para_ok:
        and     [.state], not fstatePara
        retn

;....................................................................

.close_subchapter:

        test    [.state], fstateSubChapter
        jz      .close_subchapter_ok

        mov     dword [edi], '</di'
        mov      word [edi+4], 'v>'
        add     edi, 6

        and     [.state], not fstateSubChapter

.close_subchapter_ok:
        retn

;....................................................................

; closes all open inline tags.

.close_inlines:


        test    [.state], fstateBold
        jz      .bold_ok

        mov     dword [edi], '</b>'
        add     edi, 4

.bold_ok:
        test    [.state], fstateItalic
        jz      .italic_ok

        mov     dword [edi], '</i>'
        add     edi, 4

.italic_ok:
        test    [.state], fstateUnderline
        jz      .underline_ok

        mov     dword [edi], '</u>'
        add     edi, 4

.underline_ok:
        test    [.state], fstateStrikeout
        jz      .strike_ok

        mov     dword [edi], '</s>'
        add     edi, 4

.strike_ok:
        test    [.state], fstateInlineSource
        jz      .inline_source_ok

        mov     dword [edi],   '</co'
        mov     dword [edi+4], 'de>'
        add     edi, 7

.inline_source_ok:
        and     [.state], not (fstateBold or fstateItalic or fstateUnderline or fstateStrikeout or fstateInlineSource)

















        retn


;....................................................................
; horizontal rule element

.horiz_rule:
................................................................................
; table block;
        call    .close_paragraph

        mov     al, fblkTable
        call    .PushBlock

        mov     dword [edi], '<tab'
        mov     dword [edi+4], 'le c'
        mov     dword [edi+8], 'lass'
        mov     dword [edi+12],'="tx'
        mov     dword [edi+16], 't"><'
        mov     dword [edi+20], 'tr>'+($0d shl 24)
        mov     byte  [edi+24], $0a
        lea     edi,  [edi+25]

        or      [.state], fstateTable
        jmp     .skip2


.not_table:
        cmp     dword [esi], ';---'
................................................................................

; block quote
        call    .close_paragraph

        mov     al, fblkQuote
        call    .PushBlock

        mov     dword [edi],    '<div'
        mov     dword [edi+4],  ' cla'
        mov     dword [edi+8],  'ss="'
        mov     dword [edi+12], 'bq">'
        mov     dword [edi+16], '<h1 '
        mov     dword [edi+20], 'clas'
        mov     dword [edi+24], 's="b'
        mov     dword [edi+28], 'q">'
        lea     edi, [edi+31]

        push    esi
        add     esi, 6

        call    .CopyName

        mov     dword [edi],  '</h1'

        mov     byte [edi+4], '>'
        lea     edi, [edi+5]

        pop     esi
        jmp     .skip2


.not_quote:































































        cmp     dword [esi], ';key'
        jne     .not_keywords
        cmp     dword [esi+4], 'word'
        jne     .not_keywords
        cmp     byte [esi+8], 's'
        jne     .not_keywords

................................................................................

.not_desc:
        jmp     .skip2          ; ";" at the begining without keyword is comment. The line is ignored.


.end_block:
        call    .close_paragraph
        call    .close_subchapter
        call    .do_end_block
        jmp     .skip2

.end_all_blocks:
        call    .close_paragraph

.end_all_loop:
................................................................................
        retn

.what_block:
        cmp     eax, fblkQuote
        je      .end_quote
        cmp     eax, fblkTable
        je      .end_table







        clc
        retn

.end_quote:
        mov     dword [edi], '</di'
        mov     word  [edi+4], 'v>'


        lea     edi, [edi+6]
        clc
        retn

.end_table:
        mov     dword [edi], '</tr'
        mov     dword [edi+4], '>'+($0a0d shl 8)
        mov     dword [edi+7], '</ta'
................................................................................
        mov     dword [edi+11],'ble>'
        mov     word  [edi+15], $0a0d
        lea     edi, [edi+17]
        and     [.state], not fstateTable
        clc
        retn





















;....................................................................
.PushBlock:
        push    ecx
        mov     ecx, [.pblock]
        mov     [.blocks+ecx], al
        inc     ecx
        cmp     ecx, 1024
................................................................................
        retn

;....................................................................

; processing header items and building of the table of contents.

.header2:
        call    .close_subchapter
        xor     ecx, ecx

.scan_level2:
        inc     ecx
.scan_space2:
        lea     esi, [esi+1]
        mov     al, [esi]
................................................................................
        call    _NumToStrU
        mov     al, '.'
        stosb
        inc     ebx
        cmp     ebx, [esp]
        jbe     .loop_numbers


        pop     ecx
        jmp     .finID

.main:
        mov     eax, 'main'
        stosd

................................................................................

        mov     esi, edx

.end_cp_name:
        pop     edx ecx
        retn
endp









endmodule
|







 







|
>
>







 







<











>







 







<
<
<
<
<
<

|


|

|
<
<
|
>




>

|
<
>
|




|

>
>



|


>



|

>
>



|

>
>



|

>
>

<
>







 








|
|
>
>
>

<
<
>
>
>
>
>
>
|
>
|

>
>
>
>







 







<
<
<
<
<
<
<
<
<
<
<
<









<
<







 







|
|
|







<
<












<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<



>




|
|





|
|





|
|





|
|





|
|
<



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







 







|
<
<
<
<
<
|







 







|
|
|
|
|
<
<
<
|






|
>
|
|






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







 







<







 







>
>
>
>
>
>





|
|
>
>
|







 







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







 







<







 







>







 







<
<
<
<
<





1
2
3
4
5
6
7
8
..
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
..
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
...
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
...
673
674
675
676
677
678
679
680
681
682
683
684
685
686


687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
...
766
767
768
769
770
771
772












773
774
775
776
777
778
779
780
781


782
783
784
785
786
787
788
....
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326


1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338

















1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376

1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
....
1458
1459
1460
1461
1462
1463
1464
1465





1466
1467
1468
1469
1470
1471
1472
1473
....
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
....
1633
1634
1635
1636
1637
1638
1639

1640
1641
1642
1643
1644
1645
1646
....
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
....
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
....
1819
1820
1821
1822
1823
1824
1825

1826
1827
1828
1829
1830
1831
1832
....
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
....
2006
2007
2008
2009
2010
2011
2012





2013
2014
2015
2016
2017
module "MiniMagAsm markdown dialect parser"

struct TMarkdownResults
  .hContent     dd ?
  .hIndex       dd ?
  .hKeywords    dd ?
  .hDescription dd ?
ends
................................................................................
fcloseImage             = 2
fcloseInlineImage       = 3
fcloseObject            = 4


fblkQuote       = 1
fblkTable       = 2
fblkUList       = 3
fblkOLIst       = 4
fblkSpoiler     = 5

fstateHeader    = $01
fstatePara      = $02
fstateWhite     = $04
fstateBold      = $08
fstateUnderline = $20
fstateStrikeout = $40
................................................................................

fstateTextNow  = $200         ; don't use the second byte for any other flags.
fstateTextPrev = $100

fstateInlineSource    =  $10000
fstateBlockSource     =  $20000
fstateTable           = $100000



; Translates some markdown text to HTML
; Arguments:
;     .markdown - pointer or handler of the markdown text.
;     .procFixLink - [proc .ptrLink] procedure that process the link address and returns
;                    handle to the processed link address. if [.procFixLink]=NULL, the links
;                    are inserted as they are in the HTML.
;     .fBacklinks - flag, that defines whether to insert after the headers back links to the
;                   table of contents item.
;     .pResult - pointer to TMarkdownResults structure where the result strings are returned.
;     .lParam - caller supplied parameter that is passed to procFixLink.
;
; Returns:
;   The procedure returns  4 string handles in the TMarkdownResults structure pointed by
;   .pResult argument.

proc TranslateMarkdown2, .markdown, .procFixLink, .fBacklinks, .pResult, .lParam

................................................................................
        lea     esi, [esi+1]

.td_ok:
        or      [.state], fstatePara
        jmp     .process_char

.not_td_open:






        cmp     al, '*'
        jne     .simple_p_tag

        cmp     byte [esi], ' '
        jne     .simple_p_tag

        mov     dword [edi], '<li>'


        add     edi, 4
        or      [.state], fstatePara

        inc     esi
        mov     al, [esi]
        inc     esi
        jmp     .process_char

.simple_p_tag:

        mov     dword [edi], '<p>'
        add     edi, 3
        jmp     .process_char

.process_inline_code:
        mov     ecx, fstateInlineSource
        mov     ebx, cInlineCodeTag
        jmp     .ProcessTag

cInlineCodeTag text "code"

.process_bold:
        mov     ecx, fstateBold
        mov     ebx, cBoldTag
        jmp     .ProcessTag

cBoldTag text "strong"

.process_italic:
        mov     ecx, fstateItalic
        mov     ebx, cItalicTag
        jmp     .ProcessTag

cItalicTag text "em"

.process_underline:
        mov     ecx, fstateUnderline
        mov     ebx, cUnderlinedTag
        jmp     .ProcessTag

cUnderlinedTag text 'span class="underlined"'

.process_strikeout:
        mov     ecx, fstateStrikeout
        mov     ebx, cStrikedTag

cStrikedTag text "del"

; ecx = state mask

; ebx = pointer to html tag string
.ProcessTag:
        mov     dl, al

        test    [.state], ecx
        jz      .start_tag

; close tag
................................................................................
        je      .normal_char

        or      [.state], ecx

; open tag
        mov     byte [edi], '<'
        lea     edi, [edi+1]

.copy_start:
        mov     al, [ebx]
        inc     ebx
        test    al, al
        jz      .end_tag



        stosb
        jmp     .copy_start


.finish_tag:
        mov     al, [ebx]
        lea     ebx, [ebx+1]
        cmp     al, " "
        jbe     .end_tag

        stosb
        jmp     .finish_tag

.end_tag:
        mov     byte [edi], '>'
        lea     edi, [edi+1]

        jmp     .scan_line2


.white_space:
................................................................................
        mov     ecx, [.last_header]
        add     ecx, '/h0>'
        mov     [edi], ecx
        lea     edi, [edi+4]

        and     [.state], not (fstateHeader or fstateTextNow)   ; For the paragraph flow, the header loops like empty line.













.crlf:
        test    [.state], fstateTextPrev or fstateTextNow
        jz     @f
        mov     word [edi], $0a0d
        lea     edi, [edi+2]
@@:
        test    al, al
        jnz     .line_start2



.finish:
        mov     dword [edi], 0
        stdcall StrCat, [.result], [.pHTML]
        retn


.is_link_begin:
................................................................................
        lea     edi, [edi+9]

        and     [.state], not fstateBlockSource
        jmp     .skip2

;....................................................................

.close_paragraph:       ; the <p> and <li> tags are not closed actually. Only the <td> tags.
;        test    [.state], fstatePara
;        jz      .close_para_ok

        call    .close_inlines
        call    .close_all_links

        test    [.state], fstateTable
        jnz     .close_td



        jmp     .close_para_ok

.close_td:
        mov     dword [edi], '</td'
        mov     dword [edi+4], '>'+($0a0d shl 8)
        lea     edi, [edi+7]

.close_para_ok:
        and     [.state], not fstatePara
        retn

;....................................................................

















; closes all open inline tags.

.close_inlines:
        push    esi

        test    [.state], fstateBold
        jz      .bold_ok

        mov     esi, cBoldTag
        call    .copy_one_close_tag

.bold_ok:
        test    [.state], fstateItalic
        jz      .italic_ok

        mov     esi, cItalicTag
        call    .copy_one_close_tag

.italic_ok:
        test    [.state], fstateUnderline
        jz      .underline_ok

        mov     esi, cUnderlinedTag
        call    .copy_one_close_tag

.underline_ok:
        test    [.state], fstateStrikeout
        jz      .strike_ok

        mov     esi, cStrikedTag
        call    .copy_one_close_tag

.strike_ok:
        test    [.state], fstateInlineSource
        jz      .inline_source_ok

        mov     esi, cInlineCodeTag
        call    .copy_one_close_tag


.inline_source_ok:
        and     [.state], not (fstateBold or fstateItalic or fstateUnderline or fstateStrikeout or fstateInlineSource)
        pop     esi
        retn

.copy_one_close_tag:
        mov     ax, '</'
        stosw

.coct_loop:
        lodsb
        cmp     al, " "
        jbe     .end_coct
        stosb
        jmp     .coct_loop

.end_coct:
        mov     al, '>'
        stosb
        retn


;....................................................................
; horizontal rule element

.horiz_rule:
................................................................................
; table block;
        call    .close_paragraph

        mov     al, fblkTable
        call    .PushBlock

        mov     dword [edi], '<tab'
        mov     dword [edi+4], 'le>'





        add     edi, 7

        or      [.state], fstateTable
        jmp     .skip2


.not_table:
        cmp     dword [esi], ';---'
................................................................................

; block quote
        call    .close_paragraph

        mov     al, fblkQuote
        call    .PushBlock

        mov     dword [edi],    '<blo'
        mov     dword [edi+4],  'ckqu'
        mov     dword [edi+8],  'ote>'
        mov     dword [edi+12], '<hea'
        mov     dword [edi+16], 'der>'



        lea     edi, [edi+20]

        push    esi
        add     esi, 6

        call    .CopyName

        mov     dword [edi],   '</he'
        mov     dword [edi+4], 'ader'
        mov     byte  [edi+8], '>'
        lea     edi, [edi+9]

        pop     esi
        jmp     .skip2


.not_quote:
        cmp     dword [esi], ';uli'
        jne     .not_ulist
        cmp     word [esi+4], 'st'
        jne     .not_ulist

; unnumbered list
        call    .close_paragraph

        mov     al, fblkUList
        call    .PushBlock

        mov     dword [edi], '<ul>'
        add     edi, 4
        jmp     .skip2

.not_ulist:
        cmp     dword [esi], ';oli'
        jne     .not_olist
        cmp     word [esi+4], 'st'
        jne     .not_olist

; numbered list
        call    .close_paragraph

        mov     al, fblkOLIst
        call    .PushBlock

        mov     dword [edi], '<ol>'
        add     edi, 4
        jmp     .skip2

.not_olist:
        cmp     dword [esi],   ';spo'
        jne     .not_spoiler
        cmp     dword [esi+4], 'iler'
        jne     .not_spoiler

; spoiler
        call    .close_paragraph

        mov     al, fblkSpoiler
        call    .PushBlock

        mov     dword [edi],    '<det'    ;<details><summary>Spoiler</summary>
        mov     dword [edi+4],  'ails'
        mov     dword [edi+8],  '><su'
        mov     dword [edi+12], 'mmar'
        mov     word [edi+16],  'y>'
        add     edi, 18

        push    esi
        add     esi, 8
        call    .CopyName

        mov     dword [edi],   '</su'
        mov     dword [edi+4], 'mmar'
        mov     word  [edi+8], 'y>'
        add     edi, 10

        pop     esi
        jmp     .skip2

.not_spoiler:
        cmp     dword [esi], ';key'
        jne     .not_keywords
        cmp     dword [esi+4], 'word'
        jne     .not_keywords
        cmp     byte [esi+8], 's'
        jne     .not_keywords

................................................................................

.not_desc:
        jmp     .skip2          ; ";" at the begining without keyword is comment. The line is ignored.


.end_block:
        call    .close_paragraph

        call    .do_end_block
        jmp     .skip2

.end_all_blocks:
        call    .close_paragraph

.end_all_loop:
................................................................................
        retn

.what_block:
        cmp     eax, fblkQuote
        je      .end_quote
        cmp     eax, fblkTable
        je      .end_table
        cmp     eax, fblkUList
        je      .end_ulist
        cmp     eax, fblkOLIst
        je      .end_olist
        cmp     eax, fblkSpoiler
        je      .end_spoiler

        clc
        retn

.end_quote:
        mov     dword [edi],   '</bl'
        mov     dword [edi+4], 'ockq'
        mov     dword [edi+8], 'uote'
        mov     byte [edi+12], '>'
        lea     edi, [edi+13]
        clc
        retn

.end_table:
        mov     dword [edi], '</tr'
        mov     dword [edi+4], '>'+($0a0d shl 8)
        mov     dword [edi+7], '</ta'
................................................................................
        mov     dword [edi+11],'ble>'
        mov     word  [edi+15], $0a0d
        lea     edi, [edi+17]
        and     [.state], not fstateTable
        clc
        retn

.end_olist:
        mov     dword [edi], '</ol'
        jmp     .end_list

.end_ulist:
        mov     dword [edi], '</ul'
.end_list:
        mov     dword [edi+4], '>' + ($0a0d shl 8)
        add     edi, 7
        clc
        retn

.end_spoiler:
        mov     dword [edi],   '</de'
        mov     dword [edi+4], 'tail'
        mov     word  [edi+8], 's>'
        add     edi, 10
        clc
        retn

;....................................................................
.PushBlock:
        push    ecx
        mov     ecx, [.pblock]
        mov     [.blocks+ecx], al
        inc     ecx
        cmp     ecx, 1024
................................................................................
        retn

;....................................................................

; processing header items and building of the table of contents.

.header2:

        xor     ecx, ecx

.scan_level2:
        inc     ecx
.scan_space2:
        lea     esi, [esi+1]
        mov     al, [esi]
................................................................................
        call    _NumToStrU
        mov     al, '.'
        stosb
        inc     ebx
        cmp     ebx, [esp]
        jbe     .loop_numbers

        dec     edi
        pop     ecx
        jmp     .finID

.main:
        mov     eax, 'main'
        stosd

................................................................................

        mov     esi, edx

.end_cp_name:
        pop     edx ecx
        retn
endp









endmodule

Changes to freshlib/data/strlib.asm.

893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
...
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
; Compares two strings for greater, equal or less.
; Returns eax = 0 if the strings are equal.
;         eax = 1 if .str1 is grater than .str2
;         eax = -1 if .str1 is less than .str2
;***************************************************************************************
proc StrCompSort2, .str1, .str2, .fCaseSensitive
begin
        push    ebx ecx esi edi

        mov     eax, [.str1]
        mov     ecx, [.str2]

        cmp     eax, ecx
        je      .equal

................................................................................
        ja      .greater
        jb      .less

.equal:
        xor     eax, eax

.finish:
        pop     edi esi ecx ebx
        return

.greater:
        mov     eax, 1
        jmp     .finish

.less:







|







 







|







893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
...
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
; Compares two strings for greater, equal or less.
; Returns eax = 0 if the strings are equal.
;         eax = 1 if .str1 is grater than .str2
;         eax = -1 if .str1 is less than .str2
;***************************************************************************************
proc StrCompSort2, .str1, .str2, .fCaseSensitive
begin
        push    ebx ecx edx esi edi

        mov     eax, [.str1]
        mov     ecx, [.str2]

        cmp     eax, ecx
        je      .equal

................................................................................
        ja      .greater
        jb      .less

.equal:
        xor     eax, eax

.finish:
        pop     edi esi edx ecx ebx
        return

.greater:
        mov     eax, 1
        jmp     .finish

.less:

Changes to freshlib/macros/_display.inc.

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
   end if
}

macro disp [arg] { _disp arg }


macro DispSize Text, Sz {
  local size, suffix
  size = Sz;
  if defined options.ShowSizes & options.ShowSizes
    if ~(defined options.SkipZeroSizes & options.SkipZeroSizes & Sz=0)
      if Text eqtype "A"
        disp 3,"Sizeof [", Text, "] is: "
      else
        disp 3,"Sizeof [", `Text, "] is: "
      end if

      suffix = 'bytes'
      if Sz>10000
        size = size / 1024
        disp <size,10>, 'K',$0d,$0a
      else
        disp <size,10>, ' bytes.',$0d,$0a
      end if
    end if
  end if
}







|









<









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
   end if
}

macro disp [arg] { _disp arg }


macro DispSize Text, Sz {
  local size
  size = Sz;
  if defined options.ShowSizes & options.ShowSizes
    if ~(defined options.SkipZeroSizes & options.SkipZeroSizes & Sz=0)
      if Text eqtype "A"
        disp 3,"Sizeof [", Text, "] is: "
      else
        disp 3,"Sizeof [", `Text, "] is: "
      end if


      if Sz>10000
        size = size / 1024
        disp <size,10>, 'K',$0d,$0a
      else
        disp <size,10>, ' bytes.',$0d,$0a
      end if
    end if
  end if
}

Changes to freshlib/macros/_globals.inc.

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
      rb size
  \}
  match U, UGlobals \{
    U
  \}
}


; Safe fallback of the strings data macros.

;macro __InitStringsEngine {
;  local r,v,c
;  c equ 0
;
;  struc text [val] \{
;    \common
;      if ~val eqtype 1
;      virtual at 0
;    \forward
;        db val
;    \common
;      .length = $
;      end virtual
;      end if
;    rept 1 x:c+1 \\{
;      c equ x
;      r\\#x equ .
;      v\\#x equ val
;    \\}
;  \}
;
;  macro __IncludeAllStrings \{
;    \common
;    \local ..start, len, i, j, f, ch1, ch2
;    label ..start byte
;    if defined options.ShowSizes and options.ShowSizes
;      disp 3, 'String data address: $', <..start, 16>, 13
;      disp 3, 'String count: ', <c, 10>, 13
;    end if
;
;    rept c x \\{
;      if used r\\#x
;        if ~v\\#x eqtype 1
;          r\\#x db v\\#x, 0
;        else
;          label r\\#x byte at v\\#x
;        end if
;      end if
;    \\}
;  \}
;}


macro __InitStringEngine {
local ..hashtable, ..strbase, strlist

  virtual at 0
    ..hashtable::
         dd 65536 dup ($ffffffff)







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







61
62
63
64
65
66
67













































68
69
70
71
72
73
74
      rb size
  \}
  match U, UGlobals \{
    U
  \}
}















































macro __InitStringEngine {
local ..hashtable, ..strbase, strlist

  virtual at 0
    ..hashtable::
         dd 65536 dup ($ffffffff)

Added freshlib/macros/_minihash.inc.





























































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
; Pearsons hash function table:

struct TPHashItem
  .pKeyname    dd ?     ; pointer to the key name. on [.pKeyname-1] is 1 byte key length.
  .Value       dd ?     ; user defined value of the hash table cell.
ends

;
; Builds static Pearsons hash table.
; The table contains 256 elements of TPHashItem (in total 2048 bytes)
;
; Arguments:
;   table - the lable of the hash table.
;   Pfunc - table of 256 random (or not random) bytes - values of the Pearsons hash function.
;   key   - string that to be hashed. Pointer to this string is placed in the .pKeyname field of
;           the respective record of the hash table. The hash of the key is computed case insensitive.
;   value - user data. Placed in the .Value field of the respective TPHashItem element.
;
; Notice, that the table does not resolve hash collisions. If collision happens, the compilation ends
; with error. The conflict can be resolved in two ways - changing the hash function in order to
; avoid collisions, or changing the key that causes collision.
;
macro PHashTable table, Pfunc, [key, value] {
common
if used table
  local ..error
  ..error = 0

  if defined options.ShowHashes & options.ShowHashes
    disp 3, 'Hash table "', `table, '"', 9
  end if

  table dd 256 dup(0,0)

forward
local ..keynm, ..len, ..hash, ..char, ..prev

          db ..len
  ..keynm db key
  ..len = $ - ..keynm
         db 0

  if value
    ..hash = 0
    repeat ..len
      load ..char byte from ..keynm + % - 1
      if ..char and $40
        ..char = ..char or $20
      end if
      ..hash = ..hash xor ..char
      load ..hash byte from Pfunc + ..hash
      store byte ..char at ..keynm + % - 1
    end repeat

    if defined options.ShowHashes & options.ShowHashes
      disp 3,'Keyword hash : ', <..hash, 10>, ' on "', key, '"', 10
    end if

    load ..prev dword from table + ..hash * 8

    if ..prev = 0
      store dword ..keynm at table + ..hash * 8
      store dword value at table + ..hash * 8 + 4
    else
      disp 2,'Hash collision: ', <..hash, 10>, ' on "', key, '"', 10
      ..error = 1
    end if
  end if

common
  if defined options.ShowHashes & options.ShowHashes
    disp 6, '---', 13
  end if
  assert ~..error

  end if
}

;
; Computes the Pearsons hash in the same way as PHashTable macro.
; Useful for defining constants with the hash value of some key.
;
; usage:
;   MyHashConst phash PFUNK, "my_string"
;
struc phash Pfunc, key {
local ..keynm, ..len, ..hash, ..char

  virtual at 0
    ..keynm::
      db key
    ..len = $
  end virtual

  ..hash = 0
  repeat ..len
    load ..char byte from ..keynm:(% - 1)
    if ..char and $40
      ..char = ..char or $20
    end if
    ..hash = ..hash xor ..char
    load ..hash byte from Pfunc + ..hash
  end repeat

  if defined options.ShowHashes & options.ShowHashes
    disp 3,'Keyword hash : ', <..hash, 10>, ' on "', key, '"', 10
  end if

  . = ..hash
}

Changes to freshlib/macros/allmacros.inc.

18
19
20
21
22
23
24

25
26
include '_struct.inc'
include '_display.inc'
include '_itext.inc'
include '_globals.inc'
include '_datamacros.inc'
include '_dispatch.inc'
include '_realobjects.inc'


include '%TargetOS%/allmacros.inc'







>


18
19
20
21
22
23
24
25
26
27
include '_struct.inc'
include '_display.inc'
include '_itext.inc'
include '_globals.inc'
include '_datamacros.inc'
include '_dispatch.inc'
include '_realobjects.inc'
include '_minihash.inc'

include '%TargetOS%/allmacros.inc'

Changes to freshlib/system/Linux/_process_posix.asm.

38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

body FreeThreadID
begin
        return
endp



body Exec
begin
;sys_forkd
        return
endp



; MUTEX functions
;_________________________________________________________________________________________


;struct TMutex







<
<
<
<
<
<
<







38
39
40
41
42
43
44







45
46
47
48
49
50
51

body FreeThreadID
begin
        return
endp











; MUTEX functions
;_________________________________________________________________________________________


;struct TMutex

Changes to freshlib/system/Linux/files.asm.

597
598
599
600
601
602
603




























604
605
606
607
608
609
610
        return

.exists:
        clc
        popad
        return
endp

































flushInput = 0
flushOutput = 1







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







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
        return

.exists:
        clc
        popad
        return
endp




body CreatePipe
.hRead  dd ?
.hWrite dd ?
begin
        push    ebx

        mov     eax, sys_pipe
        lea     ebx, [.hRead]
        int     $80
        neg     eax
        jnz     .err

        clc
        mov     eax, [.hRead]
        mov     edx, [.hWrite]
        pop     ebx
        return

.err:
        stc
        pop     ebx
        return
endp






flushInput = 0
flushOutput = 1

Changes to freshlib/system/Linux/process.asm.

41
42
43
44
45
46
47





48
49
50
51
52
53
54
...
224
225
226
227
228
229
230










231
232
233
234
235
236
237
238






















239
240
241
242
243
244
245
...
267
268
269
270
271
272
273




274


275









































































































































































276
277
278
279
280
281
282

        DebugMsg "Switch to 3GB address space."

        mov     eax, sys_personality
        mov     ebx, PER_LINUX32_3GB
        int     $80






; and restart the process

        mov     eax, [esp+4]          ; argument count
        mov     ebx, [esp+8]          ; the first argument is the name of the program.
        lea     ecx, [esp+8]          ; the arguments list.
        lea     edx, [ecx+4*eax+4]    ; the environment list.

................................................................................
        popad
        return
endp



if used __ExceptionHandler











__ExceptionHandler:

        lea     esi, [esp+8]    ; the start of sig_context structure.

        stdcall FileOpenAccess, "fault.txt", faCreateAlways or faWriteOnly
        mov     ebx, eax























        mov     eax, [esi+sig_context.eip]

        stdcall NumToStr, eax, ntsHex or ntsUnsigned or ntsFixedWidth + 8
        stdcall FileWriteString, ebx, eax
        stdcall FileWriteString, ebx, <txt 13, 10, 13, 10>

        lea     ebp, [esi+sig_context.ebp]
................................................................................
        retn


end if


























































































































































































match =LinuxThreads, LinuxThreads {







>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>








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







 







>
>
>
>

>
>

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







41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
...
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
...
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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
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
451
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
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494

        DebugMsg "Switch to 3GB address space."

        mov     eax, sys_personality
        mov     ebx, PER_LINUX32_3GB
        int     $80

        OutputValue "sys_personality return EAX:", eax, 10, -1

        test    eax, eax
        js      .finish         ; error set personality; try this way...???

; and restart the process

        mov     eax, [esp+4]          ; argument count
        mov     ebx, [esp+8]          ; the first argument is the name of the program.
        lea     ecx, [esp+8]          ; the arguments list.
        lea     edx, [ecx+4*eax+4]    ; the environment list.

................................................................................
        popad
        return
endp



if used __ExceptionHandler

__reg_names db  'eax', sig_context.eax
            db  'ebx', sig_context.ebx
            db  'ecx', sig_context.ecx
            db  'edx', sig_context.edx
            db  'esi', sig_context.esi
            db  'edi', sig_context.edi
            db  'ebp', sig_context.ebp
            db  'esp', sig_context.esp
            dd  0

__ExceptionHandler:

        lea     esi, [esp+8]    ; the start of sig_context structure.

        stdcall FileOpenAccess, "fault.txt", faCreateAlways or faWriteOnly
        mov     ebx, eax

; Write the registers to the file:

        mov     edi, __reg_names

.reg_loop:
        cmp     byte [edi], 0
        je      .dump_stack

        stdcall FileWrite, ebx, edi, 3
        stdcall FileWrite, ebx, txt " = ", 3

        movzx   eax, byte [edi+3]
        stdcall NumToStr, [esi + eax], ntsHex or ntsUnsigned or ntsFixedWidth + 8
        stdcall FileWriteString, ebx, eax
        stdcall FileWriteString, ebx, <txt 13, 10>
        add     edi, 4
        jmp     .reg_loop

; Write the stack backtrace to the file:

.dump_stack:
        stdcall FileWriteString, ebx, <txt 13, 10>
        mov     eax, [esi+sig_context.eip]

        stdcall NumToStr, eax, ntsHex or ntsUnsigned or ntsFixedWidth + 8
        stdcall FileWriteString, ebx, eax
        stdcall FileWriteString, ebx, <txt 13, 10, 13, 10>

        lea     ebp, [esi+sig_context.ebp]
................................................................................
        retn


end if



body Exec2
.pArgs dd ?
begin
        pushad

        stdcall StrSplitArg, [.hCommand]
        mov     [.pArgs], eax

        mov     eax, sys_fork
        int     $80

        test    eax, eax
        jnz     .parent         ; this is the parent process

; here is the child.

        DebugMsg "Child process here!"

        mov     eax, sys_dup2
        mov     ebx, [.hStdIn]
        xor     ecx, ecx
        int     $80

        mov     eax, sys_dup2
        mov     ebx, [.hStdOut]
        inc     ecx
        int     $80

        mov     eax, sys_dup2
        mov     ebx, [.hStdErr]
        inc     ecx
        int     $80

        mov     ecx, [.pArgs]
        mov     ebx, [ecx]                      ; the first argument is the executable name.

        mov     edx, [_ptrEnvironment]
        mov     eax, [edx]                      ; argument count
        lea     edx, [edx + 4*eax + 8]          ; +4 for argc and +4 for the termination 0; edx points to the env table here.

        mov     eax, sys_execve
        int     $80

        OutputValue "Error Exec2: ", eax, 10, -1

        stc
        mov     [esp+4*regEAX], eax
        popad
        return

.parent:
        stdcall FreeMem, [.pArgs]
        bt      eax, 31
        mov     [esp+4*regEAX], eax
        popad
        return
endp



body WaitProcessExit
begin
        pushad
        mov     eax, sys_waitpid
        mov     ebx, [.ProcessID]
        xor     ecx, ecx
        xor     edx, edx
        int     $80
        clc
        popad
        return
endp



; Splits the string on spaces and forms one-memory-block area that contains, zero terminated
; array of pointers to every part of the string.
; The spaces inside double or single quotes are ignored.
;
; The format of the memory block is the same as used in the sys_execve system function.

proc StrSplitArg, .hCommand
begin
        pushad

if defined StrLib & StrLib
        stdcall StrPtr, [.hCommand]
        mov     esi, eax
        mov     ebx, eax
else
        mov     esi, [.hCommand]
        mov     ebx, esi
end if
        xor     ecx, ecx
        xor     edx, edx

; find the maximal possible count of the arguments (edx)
; and the length of the string.

.loop1:
        lodsb
        test    al, al
        jz      .endstr1
        inc     ecx
        cmp     al, ' '
        jne     .loop1
        inc     edx
        jmp     .loop1

.endstr1:
        mov     esi, ebx

        add     edx, 3
        lea     edx, [4*edx + ecx]
        add     edx, 3
        and     edx, $fffffffc

        stdcall GetMem, edx
        mov     ebx, eax

        sub     edx, ecx
        sub     edx, 4
        and     edx, $fffffffc

        lea     edi, [ebx+edx]
        rep movsb

        mov     edi, ebx
        lea     esi, [ebx+edx]  ; start of the string.

.search_loop:
        mov     [edi], esi
        add     edi, 4

.loop_to_space:
        lodsb
        test    al, al
        jz      .end_of_string

        cmp     al, '"'
        je      .skip_quoted

        cmp     al, "'"
        je      .skip_quoted

        cmp     al, ' '
        jne     .next

        cmp     ah, ' '
        je      .loop_to_space

        mov     byte [esi-1], 0
        jmp     .search_loop

.next:
        mov     ah, al
        jmp     .loop_to_space


.skip_quoted:
        mov     ah, al

.loop_quote:
        lodsb
        test    al, al
        jz      .end_of_string

        cmp     al, ah
        jne     .loop_quote
        jmp     .loop_to_space


.end_of_string:
        mov     [esp+4*regEAX], ebx
        popad
        return
endp






match =LinuxThreads, LinuxThreads {

Changes to freshlib/system/Win32/process.asm.

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
        pop     edx ecx eax
        return
endp




body Exec
.startup STARTUPINFO
.process PROCESS_INFORMATION
begin
        push    ecx esi edi

        stdcall utf8ToWideChar, [.hCommand]
        mov     esi, eax
................................................................................

        lea     edi, [.startup]
        mov     ecx, (sizeof.STARTUPINFO + sizeof.PROCESS_INFORMATION)/4
        xor     eax, eax
        rep     stosd

        mov     [.startup.cb], sizeof.STARTUPINFO








        lea     ecx, [.startup]
        lea     edx, [.process]
        invoke  CreateProcessW, 0, esi, 0, 0, FALSE, NORMAL_PRIORITY_CLASS, 0, 0, ecx, edx
        stdcall FreeMem, esi
        test    eax, eax
        jz      .error

        mov     eax, [.process.hProcess]
        mov     edx, [.process.hThread]








|







 







>
>
>
>
>
>
>



|







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
        pop     edx ecx eax
        return
endp




body Exec2
.startup STARTUPINFO
.process PROCESS_INFORMATION
begin
        push    ecx esi edi

        stdcall utf8ToWideChar, [.hCommand]
        mov     esi, eax
................................................................................

        lea     edi, [.startup]
        mov     ecx, (sizeof.STARTUPINFO + sizeof.PROCESS_INFORMATION)/4
        xor     eax, eax
        rep     stosd

        mov     [.startup.cb], sizeof.STARTUPINFO
        mov     [.startup.dwFlags], STARTF_USESTDHANDLES
        mov     eax, [.hStdIn]
        mov     ecx, [.hStdOut]
        mov     edx, [.hStdErr]
        mov     [.startup.hStdInput], eax
        mov     [.startup.hStdOutput], ecx
        mov     [.startup.hStdError], edx

        lea     ecx, [.startup]
        lea     edx, [.process]
        invoke  CreateProcessW, 0, esi, 0, 0, TRUE, NORMAL_PRIORITY_CLASS, 0, 0, ecx, edx
        stdcall FreeMem, esi
        test    eax, eax
        jz      .error

        mov     eax, [.process.hProcess]
        mov     edx, [.process.hThread]

Changes to freshlib/system/files.asm.

79
80
81
82
83
84
85




86
87
88
89
90
91
92

interface GetFileInfo, .hFile, .ptrFileInfo

interface FileExists, .hFileName

interface CreateDirectory, .DirName







;--------------------------------------
; if CF = 0, eax is handle to the file.
; if CF = 1, eax is error code.
;--------------------------------------
proc FileOpen, .filename







>
>
>
>







79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96

interface GetFileInfo, .hFile, .ptrFileInfo

interface FileExists, .hFileName

interface CreateDirectory, .DirName


; returns the read handle in eax and write handle in edx

interface CreatePipe


;--------------------------------------
; if CF = 0, eax is handle to the file.
; if CF = 1, eax is error code.
;--------------------------------------
proc FileOpen, .filename

Changes to freshlib/system/process.asm.

27
28
29
30
31
32
33
34



35
36
37
38
39
40
41
..
43
44
45
46
47
48
49













50
51
52
53
54
55
56
57
58
59
60
61


interface ThreadCreate, .ptrFunction, .ptrArguments

interface FreeThreadID, .ThreadID


interface Exec, .hCommand




interface FreeProcessID, .ProcessID

interface WaitProcessExit, .ProcessID, .timeout



................................................................................

interface WaitForMutex, .ptrMutex, .timeout

interface MutexRelease, .ptrMutex

interface MutexDestroy, .ptrMutex















include '%TargetOS%/process.asm'


if used ThreadCreate
  options.Threads = 1
else
  options.Threads = 0
end if


endmodule







|
>
>
>







 







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










<

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
..
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


interface ThreadCreate, .ptrFunction, .ptrArguments

interface FreeThreadID, .ThreadID


; Executes the command .hCommand, gets the STDIN from [.hStdIn] file handle,
; Outputs the STDOUT to [.hStdOut] file handle and STDERR to [.hStdErr] handle.

interface Exec2, .hCommand, .hStdIn, .hStdOut, .hStdErr

interface FreeProcessID, .ProcessID

interface WaitProcessExit, .ProcessID, .timeout



................................................................................

interface WaitForMutex, .ptrMutex, .timeout

interface MutexRelease, .ptrMutex

interface MutexDestroy, .ptrMutex


; Simple wrapper on Exec2;
; See Exec2

proc Exec, .hCommand
begin
        stdcall Exec2, [.hCommand], [STDIN], [STDOUT], [STDERR]
        return
endp





include '%TargetOS%/process.asm'


if used ThreadCreate
  options.Threads = 1
else
  options.Threads = 0
end if


endmodule

Added freshlib/test_code/TestBBCode/angry.gif.

cannot compute difference between binary files

Added freshlib/test_code/TestBBCode/anon.svg.





>
>
1
2
<?xml version="1.0" encoding="UTF-8"?>
<svg width="36" height="36" version="1.1" viewBox="0 0 20.135672 20.135672" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"><g id="Anonym__x2F__Guy_Fawkes" transform="scale(.0703)"><path d="m169 34.6c2.69 1.96 8.78 1.77 12.3-2.43 1.98-2.38 19.1-20.3 43.1-20.3 30.8 0 42.3 10.3 42.3 10.3-11-19.8-34.6-22.2-41.5-22.2-33.5 0-52.6 16-57.6 22.7-4.98 6.77-1.02 10.1 1.43 11.9zm94.9 54.9c-4.3 0-4.48 7.02-4.48 8.95-2e-3 12.6-7.11 24.9-13.4 31.3-18.2 18.6-47.9 2.26-47.9 2.26-5.02-2.03 0.445 3 0.445 3 2.86 2.96 11 12.1 27.1 14.1-0.743 0.786-20 20.9-20 20.9h-17.9l-17.9-26.8c-4.76 6.29-8.95 8.95-17.9 8.95-4.91 0-10.5-0.84-14.4-5.17-3.68-4.07-3.5-9.43-3.5-12.7-0.018-13.4 0-47.6 0-53.7v-15.4c0-7.83-8.79-15-8.79-15-10.4-7.16-17.8 8.97-17.8 8.97l-0.114 0.087c-8.58-3.12-17.7-5.02-27.2-5.02-11.7 0-25.4 1.28-35.6 5.8v-6.25c0-64.1 69.2-22.1 78.9-18.6 9.09 3.23 7.25-7.22 5.67-8.96-21.8-24.1-58.9-26.1-58.9-26.1-50.7 0-52.5 49.6-52.5 71.6v46.5c0 56.8 72.4 154 117 162-0.218 0.104 4.78 1.28 6.79 2.74 0.078 0.053 0.209 0 0.28 0.044 2.59 2.16 5.85 3.59 9.51 3.59 3.56 0 6.69-1.38 9.22-3.41 0 0 3.16-1.83 7.81-3.32 5.31-1.41 14.4-6.93 20.1-11.5 22.9-18.4 46.1-46.9 62.2-87.9 0 0 2.16-9.66-0.612-10.2-2.46-0.499-4.1 0.035-10.8 12-25.4 45.7-60.7 76.6-78.7 77.5v-35.8c11.4-1.76 31.7-10.8 45.5-23.3 8.95-8.14-7.11-6.28-9.68-5.24-11 4.42-13.2 10.6-44.7 10.6-30.1 0-48.1-12.7-53.7-17.9h35.8l17.9-17.9 17.9 17.9h35.8l32.6-38.6c27.3-2.42 30.2-34.1 30.2-37.4v-13.4c0-2.11-0.072-8.95-4.48-8.95zm-165 118c24 15.1 36.5 15 44.3 16.2v35.8c-42.4-10.8-44.8-41.5-44.3-52zm14.2-93.9c-6.68 29.5-40.1 29.5-40.1 29.5-19.8 0-28.3-10.2-28.3-37v-39.8c10.2 4.53 23.9 8.38 35.6 8.38 10.3 0 20.2-2.13 29.4-5.76 0.026 0 0.051 9e-3 0.051 9e-3 3.38 0 5.27 2.65 5.27 2.65s5.52 9.08-1.92 42zm63.8-49.2c11.9 6.39 25.1 10.3 39.2 10.3 14.1 0 27.4-3.92 39.3-10.3-11.9-6.39-25.1-10.3-39.3-10.3-14.1 0-27.3 3.92-39.2 10.3z" clip-rule="evenodd" fill="#3f3f3f" fill-rule="evenodd"/></g></svg>

Added freshlib/test_code/TestBBCode/bbcode.asm.































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
; _______________________________________________________________________________________
;|                                                                                       |
;| ..:: Fresh IDE ::..  template project.                                                |
;|_______________________________________________________________________________________|
;
;  Description: FreshLib portable console application.
;
;  Target OS: Any, supported by FreshLib
;
;  Dependencies: FreshLib
;
;  Notes:
;_________________________________________________________________________________________

include "%lib%/freshlib.inc"

@BinaryType console, compact

options.DebugMode = 0
options.ShowSizes = 1

EMOTICONS_PATH equ './'
include "%lib%/freshlib.asm"

include "hash_function.asm"


FILE_READ_CHUNK = 4096

rb 237

start:
        InitializeAll

        or      ecx, -1
        shr     ecx, 3
.hot:
        dec     ecx
        jnz     .hot

        stdcall TextCreate, sizeof.TText
        mov     edx, eax

.read_loop:
        stdcall TextMoveGap, edx, -1
        stdcall TextSetGapSize, edx, FILE_READ_CHUNK
        mov     eax, [edx+TText.GapBegin]
        add     eax, edx

        stdcall FileRead, [STDIN], eax, FILE_READ_CHUNK
        jc      .translate

        test    eax, eax
        jz      .translate

        add     [edx+TText.GapBegin], eax
        jmp     .read_loop

.translate:

        stdcall GetFineTimestamp
        push    eax

        stdcall TranslateBBCode, edx, 0

        stdcall GetFineTimestamp
        pop     ecx
        sub     eax, ecx

        stdcall NumToStr, eax, ntsDec or ntsUnsigned
        push    eax eax

        stdcall FileWriteString, [STDERR], 'TranslateBBCode time: '
        stdcall FileWriteString, [STDERR] ; from the stack
        stdcall StrDel ; from the stack
        stdcall FileWriteString, [STDERR], <txt ' us', 13, 10>


        stdcall TextCompact, edx

;        stdcall FileWrite, [STDOUT], cPrefix, cPrefix.length
;        stdcall FileWriteString, [STDOUT], edx

.finish:
        push    eax
        FinalizeAll
        stdcall TerminateAll ; from the stack

iglobal
  cPrefix file "prefix.tpl"
  .length = $ - cPrefix
          dd 0
endg


Added freshlib/test_code/TestBBCode/bbcode.fpr.

cannot compute difference between binary files

Added freshlib/test_code/TestBBCode/cry.gif.

cannot compute difference between binary files

Added freshlib/test_code/TestBBCode/hash_function.asm.











































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
iglobal
if used tpl_func
tpl_func:
          db 148,  24,  71,  46, 179,   0, 106, 157,  70,   1, 102, 126, 120, 134, 151, 183
          db  47, 103,  92, 201,  62, 156,  13,  10, 254, 218, 248,  28,  85, 185, 245, 112
          db 236, 237, 150,  37, 172,  63, 203, 198, 116, 196,  25, 107, 239,  44,  15, 175
          db  38, 161, 140,  98,  33,  79,  99, 133,   2,  59, 174, 115,  69, 188,  51,  36
          db 229, 143, 231,  84,  22,  78,  89, 166, 104, 145,  34, 225, 180,  12, 230, 205
          db  97,  39,  49, 190, 182, 202,  17, 219, 176, 170,  80,  74,  73, 194,  41,  26
          db 243, 142,  60, 131, 244, 249, 119,  61, 138,  16,  77,  54, 210,  23,  29, 147
          db 204, 110, 130,  93, 213, 223, 146, 216, 123, 247,  90, 124,  75, 135,  57, 128
          db 226,  50, 224, 127, 139, 152, 193, 101, 207, 122,   9,  58, 184, 250,  96,  67
          db 241, 109,  87, 168, 187, 167, 240, 171, 233, 155, 173, 215,  43, 227, 160,   5
          db 246, 129,  20,  14, 100, 209, 137, 169,  68,  40,  42, 165, 121, 113, 200,  95
          db 189, 251,  82,  72, 154, 235, 195, 136, 186,  55, 212,  35,  32, 253,  66, 132
          db 214,  88, 192,   4,  31,  65, 114, 211,  19,  83,  21,   3,   6, 177,  76, 255
          db 252, 199, 141,  56, 105,  11, 117, 163, 220,  27, 222, 234, 178,  52,  64, 221
          db  18, 232, 164,  53, 206, 153, 118,  48, 158, 162, 159, 191, 242, 125, 144,  94
          db 108,  91, 197, 111,  30,   7,  81, 181, 149,  45, 217, 208,  86, 238,   8, 228
end if
endg

Added freshlib/test_code/TestBBCode/lol.gif.

cannot compute difference between binary files

Added freshlib/test_code/TestBBCode/prefix.tpl.





























































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>BBCode translator test page.</title>
  <style>
    body {font-family: sans-serif;}
    h1, h2, h3, h4, h5, h6 {margin: 1rem 0 1rem 0;}:
    h1 {font-size: 2em}
    h2 {font-size: 1.8em}
    h3 {font-size: 1.6em}
    h4 {font-size: 1.4em}
    h5 {font-size: 1.2em}
    h6 {font-size: 1em}
    code {display: inline; font-size: 14px;}
    code.block {display: block; white-space: pre; background: #e0ffff; color: #000080; border-left: 8px solid #008080; padding: 1em 1ch; margin: 1em 2ch; }
    code.asm {background: black; color:lime; }
    table {border: 1px solid red;}
    td, th {border: 1px solid red; padding: 1em 2ch; }
    blockquote { border: 2px solid green; padding: 1em 2ch; }
    header {background-color: yellow; padding: 0 2ch; }
    img {display: block; margin: 1em auto; text-align: center;}
    img.emoticon { display: inline; margin: 0 4px; }
    p {color: green;}
    a.back::after {content: "^";}
    span.underlined {text-decoration: underline;}
  </style>

<body>

Added freshlib/test_code/TestBBCode/readme.txt.









>
>
>
>
1
2
3
4
This project is the code of a parser for BBCode and the test cases.
Later this code should be merged in FreshLib and used in AsmBB forum engine
This way, two different markup languages will be allowed simultaneously.

Added freshlib/test_code/TestBBCode/rofl.gif.

cannot compute difference between binary files

Added freshlib/test_code/TestBBCode/sad.gif.

cannot compute difference between binary files

Added freshlib/test_code/TestBBCode/smile.gif.

cannot compute difference between binary files

Added freshlib/test_code/TestBBCode/test.bbcode.



















































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
[h1]Header 1[/h1]

[h2]Header 2[/h2]

[h3]Header 3[/h3]

[h4]Header 4[/h4]

[h5]Header 5[/h5]

[h6]Header 6[/h6]

<script>alert('Hi!')</script> << This ""MUST"" be escaped & the tags will be displayed.

[b]This paragraph should be formatted with <strong></strong> tags.[/b]

[i]This paragraph should be formatted with <em></em> tags.[/i]

[u]This paragraph should be formatted with <span class="underlined"></span> tags.[/u]

[s]This paragraph should be formatted with <del></del> tags.[/s]

[c]This paragraph should be formatted with <code></code> tags and monospaced font.[/c]

[url="><span style="color: red">]This is a XSS test. It should [b]NOT[/b] be colored in red![/url]

[url=https://board.asm32.info]This is a link <a href=""></a>[/url]

[url]https://board.asm32.info[/url]

A little bit strange, but valid:

[img=anon.svg[/img]

Standard image definition:

[img]anon.svg[/img]

An image with alt text:

[img=Anonymous user picture]anon.svg[/img]

Missing image alt text displayed and properly encoded:

[img=>>>>>>Anonymous user picture<<<<<<<]someimage.svg[/img]


[quote]Block quote
with paragraphs.

Another paragraph.
And it is multiline
paragraph actually.

[/quote]

[quote=Author name]<<Block quote with author name.>>[/quote]

This is multiline paragraph
and should be formatted as such.
All text should be grouped in one text block.

[quote=Anonymous]
<<Block quote with author name. and nested block quote with formatting>>
[quote=johnfound]
Here is my [b]super asm[/b] code!
[code=asm]
        stdcall LoadBinaryFile, "prefix.tpl"
        jc      .prefix_ok
        push    eax
        stdcall FileWrite, [STDOUT], eax, ecx
        pop     eax
.prefix_ok:
[/code]
[/quote]

Your [i]code[/i] [b]sucks![/b]

[/quote]




[code]
This is a block of code formatted with <code></code> tags.

        [b]This tag should not be formatted[/b], because in [code] tag.

        stdcall LoadBinaryFile, "prefix.tpl"
        jc      .prefix_ok
        push    eax
        stdcall FileWrite, [STDOUT], eax, ecx
        pop     eax
.prefix_ok:
[/code]

[code=asm]
This is a block of code formatted with <code class="asm"></code> tags.
        stdcall LoadBinaryFile, "prefix.tpl"
        jc      .prefix_ok
        push    eax
        stdcall FileWrite, [STDOUT], eax, ecx
        pop     eax
.prefix_ok:

[/code]

[size=48px]Text [color=#ff00ff]with[/color] different size.[/size]

[color=#ff00ff]Text with different color.[/color]

Unordered list 1:

[list]
[*] Item 1
[*] Item 2

[*] Item 3
[/list]

Unordered list 2:

[ul]
[*] Item 1
[*] Item 2
[*] Item 3
Item 3 as well!

Not an item?

[/ul]

Nested ordered lists:

[ol]
[*] Item 1
[*] Item 2 has subitems.
  [ol=a]
     [*] Item 1

     [*] Item 2
     [*] Item 3
     [*] Item 4
   [/ol]

[*] Item 3

[/ol]


[table]
   [tr]
      [td] 1 [/td]
      [td] 2 [/td]
      [td] 3 [/td]
   [/tr]
   [tr]
      [td] 4 [/td]
      [td] 5 [/td]
      [td] 6 [/td]
   [/tr]
   [tr]
      [td] 7 [/td]
      [td] 8 [/td]
      [td] 9 [/td]
   [/tr]
[/table]

[:)] [:D] [:lol:] [;)] [:P] [:(] [:`(] [>:(]


[email]email@email.com[/email]

[email=email@email.com]My email[/email]

[spoiler]
  Vader is Luke's father!
[/spoiler]


[b][i][u]Multi tags[/u][/i][/b]

[b][i][u]Wrong multi tags[/i][/b][/u]

[/asdf]<test for bad closing tag.>

[/<script>alert('hi!')</script>]XSS test for invalid closing tags!

[<script>alert('hi!')</script>=<script>alert('hi!')</script>]XSS test for invalid tags!


[b=some extra attribute ignore!]<<Not needed attributes should be simply deleted/ignored, but the text should be properly formatted>>[/b]

Not finished tag:

[[[[[[[[[b=<script>alert('Hi!')</script>


The following is a not finished tag at the end of the file:

[<script>alert('Hi!')</script>

Added freshlib/test_code/TestBBCode/tongue.gif.

cannot compute difference between binary files

Added freshlib/test_code/TestBBCode/wink.gif.

cannot compute difference between binary files

Added freshlib/test_code/TestGapBuffers.asm.





























































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
; _______________________________________________________________________________________
;|                                                                                       |
;| ..:: Fresh IDE ::..  template project.                                                |
;|_______________________________________________________________________________________|
;
;  Description: FreshLib portable console application.
;
;  Target OS: Any, supported by FreshLib
;
;  Dependencies: FreshLib
;
;  Notes:
;_________________________________________________________________________________________

include "%lib%/freshlib.inc"

@BinaryType console, compact

include "%lib%/freshlib.asm"

start:
        InitializeAll

        stdcall TextCreate, sizeof.TText
        mov     edx, eax

        stdcall TextAddString, edx, 0, "This is test"
        stdcall TextAddString, edx, 8, "simply a small, simple but reliable "

        stdcall TextMoveGap, edx, -100000
        stdcall TextMoveGap, edx, +100000

        stdcall TextMoveGap, edx, 4
        sub     [edx+TText.GapBegin], 4

        stdcall TextAddString, edx, 0, txt "Katakana"

        stdcall TextMoveGap, edx, -1
        sub     [edx+TText.GapBegin], 4

        stdcall TextAddString, edx, [edx+TText.GapBegin], "alphabet."

;        int3
        stdcall TextCompact, edx

        push    eax

        stdcall FileWrite, [STDERR], edx, eax
        stdcall FileWriteString, [STDERR], <txt "<<<<<<<", 13, 10, "Text length: ">

        pop     eax
        stdcall NumToStr, eax, ntsDec or ntsUnsigned

        stdcall FileWriteString, [STDERR], eax
        stdcall FileWriteString, [STDERR], <txt 13, 10>

        stdcall NumToStr, [edx+TText.GapEnd], ntsDec
        push    eax

        stdcall NumToStr, [edx+TText.GapBegin], ntsDec
        push    eax

        stdcall NumToStr, [edx+TText.Length], ntsDec
        push    eax

        stdcall FileWriteString, [STDERR], "TText length: "
        stdcall FileWriteString, [STDERR] ; from the stack

        stdcall FileWriteString, [STDERR], <txt 13, 10, "Gap begin: ">
        stdcall FileWriteString, [STDERR] ; from the stack

        stdcall FileWriteString, [STDERR], <txt 13, 10, "Gap end: ">
        stdcall FileWriteString, [STDERR] ; from the stack

        stdcall FileWriteString, [STDERR], <txt 13, 10>

        FinalizeAll
        stdcall TerminateAll, 0

Added freshlib/test_code/TestGapBuffers.fpr.

cannot compute difference between binary files

Changes to freshlib/test_code/TestMarkdown/TestMarkdown.asm.

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
include "%lib%/freshlib.asm"


uglobal
  Result TMarkdownResults
endg








start:
        InitializeAll

; place your code here.

        stdcall ReadTheInputSlow

        stdcall TranslateMarkdown, edi, 0, 0, Result



        stdcall FileWriteString, [STDOUT], [Result.hContent]


        FinalizeAll
        stdcall TerminateAll, 0









>
>
>
>
>









|

>
>







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
include "%lib%/freshlib.asm"


uglobal
  Result TMarkdownResults
endg

iglobal
  cHeader file "../TestBBCode/prefix.tpl"
          dd 0
endg



start:
        InitializeAll

; place your code here.

        stdcall ReadTheInputSlow

        stdcall TranslateMarkdown2, edi, 0, TRUE, Result, 0

        stdcall FileWriteString, [STDOUT], cHeader
        stdcall FileWriteString, [STDOUT], [Result.hIndex]
        stdcall FileWriteString, [STDOUT], [Result.hContent]


        FinalizeAll
        stdcall TerminateAll, 0


Changes to freshlib/test_code/TestMarkdown/TestMarkdown.fpr.

cannot compute difference between binary files

Deleted freshlib/test_code/TestMarkdown/image.png.

cannot compute difference between binary files

Changes to freshlib/test_code/TestMarkdown/test.markdown.

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
# Header 1

This is a test file for the markdown parser.


## Header 1.1

Here are some image:

           [!img1][Some alt text]

           [!image.png]

And here, some object:

        [$128x48:test.swf][With inline address.]

        [$Flash1][This is simple demonstration of Fresh IDE power.]

        [$Flash2][Broken link processing]

        [$test.swf][There should be no size, but the animation should appear.]

        [$x480test.swf][Broken3]

## Header 1.2












Another paragraph.






















Some more text to test the sub-chapters.

### Header 1.2.1


















































































[$Flash1] 64x48:test.swf
[$Flash2] 64:test.swf
[!img1] image.png







|

|


|

|



|

|
|
|
|
|
|
|
|
|
|
|

|

>
>
>
>
>
>
>
>
>
>
>


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


<
>

>

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




|







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
# Test of the MiniMagAsm markup.

This is a test file for the MiniMagAsm kind of markdown parser.


## Header 1

Here are some images:

           [!img1][Some alt text]

           [!../TestBBCode/anon.svg]

;And here, some object:
;
;        [$128x48:test.swf][With inline address.]
;
;        [$Flash1][This is simple demonstration of Fresh IDE power.]
;
;        [$Flash2][Broken link processing]
;
;        [$test.swf][There should be no size, but the animation should appear.]
;
;        [$x480test.swf][Broken3]

## Code block without syntax specified

;begin
        stdcall LoadBinaryFile, "prefix.tpl"
        jc      .prefix_ok
        push    eax
        stdcall FileWrite, [STDOUT], eax, ecx
        pop     eax
.prefix_ok:

;end


Another paragraph.

;quote Anonymous
<<Block quote with author name. and nested block quote with formatting>>
;quote johnfound
Here is my *super asm* code! (Code block with language specified.)

;begin asm
        stdcall LoadBinaryFile, "prefix.tpl"
        jc      .prefix_ok
        push    eax
        stdcall FileWrite, [STDOUT], eax, ecx
        pop     eax
.prefix_ok:

;end

;end

Your /code/ *sucks!*

;end

Some more text to test the sub-chapters.


### Bold and italic.

Another chapter.

   *This is bold*

   /This is italic/

#### Level 4

;ulist
* List item 1

* List item 2

* List item 3
;end

;olist
* List item 1

* List item 2
;ulist
* Subitem 1

* Subitem 2

* Subitem 3
;end

* List item 3
;end

##### Level 5

Table formatting:

;table
1

2

3

;-------------------

4

5

6

;---------------------

7

8

9

;end

###### Level 6

  The maximal level of H tags.

;spoiler Spoiler
  Vader is Luke's father!
;end


### Underlined and Strikethrough.

  _This is underlined_

  -Deleted text-

### One more header.

 This is inline `code formatting`, displayed with monospaced font.


[$Flash1] 64x48:test.swf
[$Flash2] 64:test.swf
[!img1] ../TestBBCode/anon.svg







Changes to freshlib/test_code/TestPThreads.asm.

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
..
49
50
51
52
53
54
55
56
57
58
;
;  Notes:
;_________________________________________________________________________________________

include "%lib%/freshlib.inc"

@BinaryType console



include "%lib%/freshlib.asm"


; include your includes here.

iglobal
  Stop dd 0
endg

start:
        InitializeAll











        stdcall ThreadCreate, TestThread, 0

.wait:
        stdcall Sleep, 100
        cmp     [Stop], 0
        je      .wait



        FinalizeAll
        stdcall TerminateAll, 0


proc TestThread, .arg
begin
        mov     esi, esp
................................................................................
        loop    .touch

        mov     [Stop], 1
        mov     esp, esi
        cret
endp


@AllImportEmbeded       ; or @AllImportSection
@AllDataEmbeded         ; or @AllDataSection








>
>

>










>
>
>
>
>
>
>
>
>
>







>
>







 







<
<
<
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
..
64
65
66
67
68
69
70



;
;  Notes:
;_________________________________________________________________________________________

include "%lib%/freshlib.inc"

@BinaryType console

options.DebugMode = 0

include "%lib%/freshlib.asm"


; include your includes here.

iglobal
  Stop dd 0
endg

start:
        InitializeAll


        stdcall FileOpenAccess, "./TestPThreads.asm", faReadOnly
        mov     ebx, eax

        stdcall FileOpenAccess, "./out.txt", faWriteOnly or faCreateAlways
        mov     edi, eax

        stdcall Exec2, '/usr/bin/grep "stdcall Exec2"', ebx, edi, edi   ; Runs in WINE as well, but will not in the original Windows.
        jmp     .finish

        stdcall ThreadCreate, TestThread, 0

.wait:
        stdcall Sleep, 100
        cmp     [Stop], 0
        je      .wait


.finish:
        FinalizeAll
        stdcall TerminateAll, 0


proc TestThread, .arg
begin
        mov     esi, esp
................................................................................
        loop    .touch

        mov     [Stop], 1
        mov     esp, esi
        cret
endp




Changes to freshlib/test_code/TestPThreads.fpr.

cannot compute difference between binary files

Changes to source/help.asm.

641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
        jc      .finish

        mov     ebx, eax

        stdcall StrCharCat, ebx, ' '
        stdcall StrCat, ebx, [.hURL]

        stdcall Exec, ebx
        jc      .finish2

        stdcall FreeProcessID, eax
        stdcall FreeThreadID, edx
        clc

.finish2:







|







641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
        jc      .finish

        mov     ebx, eax

        stdcall StrCharCat, ebx, ' '
        stdcall StrCat, ebx, [.hURL]

        stdcall Exec2, ebx, [STDIN], [STDOUT], [STDERR]
        jc      .finish2

        stdcall FreeProcessID, eax
        stdcall FreeThreadID, edx
        clc

.finish2: