-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathStrings.mac
2704 lines (2075 loc) · 64 KB
/
Strings.mac
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
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
comment ^
;; Text macros collection
;; Written by Four-F (four-f@mail.ru)
;; Last updated 01-September-2004
;; Your improvements, suggestions and bugfixes are welcomed.
;; Tested for compatibility with windows.inc v.1.25e
STRINGA / STRINGW are internal macros. Basically you don't need to use them.
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
: S Y N T A X :
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
MacroName quotedtext [,lebel] [,alignment]
or
MacroName quotedtext [,alignment] [,lebel]
$MacroName(quotedtext [,lebel] [,alignment])
or
$MacroName(quotedtext [,alignment] [,lebel])
----------------------------------------------------------------------------------------------------
- MacroName / $MacroName from the following list:
TA / TW / T
CTA / CTW / CT
$TA / $TW / $T
$CTA / $CTW / $CT
TA0 / TW0 / T0
CTA0 / CTW0 / CT0
$TA0 / $TW0 / $T0
$CTA0 / $CTW0 / $CT0
The interpritation of the macro names is quite simple and based on the following:
T - all macros have 'T' char in its names. It means Text.
C - constant string. String is defined in read-only data section ( .const ).
macros without 'C' in its name define string in read-write data section ( .data ).
A - macro defines ASCII string.
W - macro defines Wide (Unicode) string. The size of each character is 2 bytes.
0 - zero character not 'O'. Defined string is terminated by zero byte (ASCII) or zero word (Unicode).
$ - macro function. Returns offset to defined text.
Each macro has corresponding macro function which name is prepended with '$' character.
All macro functions return offset to defined text.
All macros return nothing.
If macro name doesn't contain neither 'A' nor 'W' character,
its behaviour depends on definition of global variable UNICODE.
If UNICODE is undefined or equal to 0, that macro defines ASCII string.
If UNICODE is defined and doesn't equal to 0, that macro defines Unicode string.
You can define UNICODE global variable two ways:
- in command line to ml.exe
\DUNICODE=1
- in source code
UNICODE = 1
or
UNICODE equ 1
----------------------------------------------------------------------------------------------------
- quotedtext:
The first parameter is "quoted text" you want to define.
It is required and MUST be in quotation marks.
You can use escape characters.
esc. char. code symbol
--------------------------------------------------
\: 21h '!'
\{ 28h '('
\} 29h ')'
\[ 3Ch '<'
\] 3Eh '>'
\= 22h '"'
\- 27h "'"
\\ 5Ch '\'
\* - - ;; To workaround "CopyFile" -> CopyFileA problem
\0 0 zero byte/word
\a 7 alert (BEL)
\b 8 backspace
\t 9 horizontal tabulation
\n 0Dh, 0Ah new line
\l 0Ah line feed
\v 0Bh verticalal tabulation
\f 0Ch formfeed
\r 0Dh carrige return
----------------------------------------------------------------------------------------------------
- lebel, alignment:
The second and third parameters are optional.
It can be either label or alignment.
The macros recognize is it a label or an alignment automatically.
Later you can reference defined text by this label.
Alignment can be immediate value of 1 (byte), 2 (word) or 4 (dword).
By default alignment is:
- 1 for ascii string
- 2 for unicode string
The structure UNICODE_STRING, defined with the following macros is always DWORD alignmented.
COUNTED_UNICODE_STRING / $COUNTED_UNICODE_STRING / CCOUNTED_UNICODE_STRING / $CCOUNTED_UNICODE_STRING
You can set alignment for the string pointed by UNICODE_STRING.Buffer.
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
: E L I M I N A T E D U P L I C A T E S T R I N G S :
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
The following macros try to eliminate duplicate strings. So only a single copy of identical strings
will present in the program image, resulting in smaller programs.
$TA / $CTA / $TW / $CTW / $T / $CT
$TA0 / $CTA0 / $TW0 / $CTW0 / $T0 / $CT0
Every time you define a string using one of the above listed macros the string is stored in database.
If somewhere later in your code you use the very same macro to define the very same string, the macro
will remember its offset from the database instead of defining it second time.
Consider example.
invoke MessageBox, NULL, $CTA0("OK"), $CTA0("Success"), MB_OK
. . .
invoke MessageBox, NULL, $CTA0("OK"), $CTA0("Success"), MB_OK
The above two strings are compiled as if you use this code:
.const
szOK db "OK", 0
szSuccess db "Success", 0
.code
invoke MessageBox, NULL, addr szOK, addr szSuccess, MB_OK
. . .
invoke MessageBox, NULL, addr szOK, addr szSuccess, MB_OK
---
Bear in mind that each macro has its own database. So, for example, $CTA0 searches only
among the strings previously defined with the very same macro!
This optimization works only for unlabeled strings. So, if you explicity pass the label
to the macro it will not serch in database for that string.
Consider example.
invoke MessageBox, NULL, $CTA0("OK"), $CTA0("Success"), MB_OK
. . .
invoke MessageBox, NULL, $CTA0("OK", szOK), $CTA0("Success", szSuccess), MB_OK
The above two strings are compiled as if you use this code:
.const
???1 db "OK", 0
???2 db "Success", 0
szOK db "OK", 0
szSuccess db "Success", 0
.code
invoke MessageBox, NULL, addr ???1, addr ???2, MB_OK
. . .
invoke MessageBox, NULL, addr szOK, addr szSuccess, MB_OK
---
Also remember that if you explicity pass alignment that is greater then the alignment of previously
defined string the macro will use offset to the string from database and warn you with the message:
mov eax, $CTA0("Alignment", 2)
mov eax, $CTA0("Alignment", 4)
C:\masm32\macros\xxx.asm(xxx) : $CTA0 macro WARNING! Alignment is greater then
previous instance of "Alignment".
---
To disable string pooling feature define somewhere in you code before any string macro this line:
DISABLE_STRING_POOLING equ 1
NOTE: The value you specify doesn't matter. It can be any value. So defining it equal to 0 disables
string pooling also. The macros just seek if it defined or not. So, if you want to enable string
pooling back again remove or comment out DISABLE_STRING_POOLING definition.
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
: L I M I T A T I O N S :
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Unicode string can be up to 47 characters long.
Otherwise you'll get assembler error:
: error A2042: statement too complex
Hope I'll fix this later.
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
: K N O W N P R O B L E M S :
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
$CTA0("CopyFile") produce CopyFileA because of:
CopyFile equ <CopyFileA>
Its because of native masm behavior.
You can workaround this placing '\*' somewhere in simbol name like this:
$CTA0("Copy\*File")
'\*' escape sequence expands to hothing. So you will get "CopyFile" instead of "CopyFileA".
Or you can use unrecognizeable character escape sequence. For example, like this:
$CTA0("C\opyFile")
You will get "WARNING!: 'o' : unrecognized character escape sequence" from macro
but 'o' char will be added to string. So you will also get "CopyFile" instead of "CopyFileA".
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
: E X A M P L E S :
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
The most usable macros are: $CTA0, $CTW0, CTA0, CTW0
----------------------------------------------------------------------------------------------------
To define empty string use any zero-terminating macro this way:
mov eax, $TA0()
or
mov eax, $TA0('')
or
mov eax, $TA0("")
DON'T TRY TO DEFINE EMPTY STRINGS WITH NON-ZERO TERMINATING MACROS:
TA / TW / T / CTA / CTW / CT / $TA / $TW / $T / $CTA / $CTW / $CT
::::::::::::::::::::::::::::::::::::::::::::: Ex 1 :::::::::::::::::::::::::::::::::::::::::::::::::
invoke AppendMenu, hMenuPopupFile, MF_STRING, IDM_OPEN, $CTA0("&Open...\tCtrl+O")
Expands to:
.const
??? db "&Open...", 9, "Ctrl+O", 0
.code
invoke AppendMenu, hMenuPopupFile, MF_STRING, IDM_OPEN, offset ???
::::::::::::::::::::::::::::::::::::::::::::: Ex 2 :::::::::::::::::::::::::::::::::::::::::::::::::
TA0 "http://board.win32asmcommunity.net/", szUrl, 4
invoke MessageBox, NULL, offset szUrl, $TA0("Go To", 4), MB_OK
Expands to:
.data
align 4
szUrl db "http://board.win32asmcommunity.net/", 0
align 4
??? db "Go To", 0
.code
invoke MessageBox, NULL, offset szUrl, offset ???, MB_OK
::::::::::::::::::::::::::::::::::::::::::::: Ex 3 :::::::::::::::::::::::::::::::::::::::::::::::::
invoke MessageBox, NULL, $CTA0("\[ Well done\: :-\} \]"), $CTA0("Congratulations"), MB_OK
Expands to:
.const
??1 db "< Well done! :-) >", 0
??2 db "Congratulations", 0
.code
invoke MessageBox, NULL, offset ??1, ??2, MB_OK
::::::::::::::::::::::::::::::::::::::::::::: Ex 4 :::::::::::::::::::::::::::::::::::::::::::::::::
invoke IoCreateDevice, pDriverObject, 0, \
$CCOUNTED_UNICODE_STRING("\\Device\\DevName", g_usDeviceName, 4), \
FILE_DEVICE_UNKNOWN, 0, FALSE, addr g_pDeviceObject
Expands to:
.const
align 4
??? dw "\" ,"D" ,"e" ,"v" ,"i" ,"c" ,"e" ,"\" ,"D" ,"e" ,"v" ,"N" ,"a" ,"m" ,"e" , 0
align 4 ; The UNICODE_STRING structure itself is always DWORD alignmented
g_usDeviceName dw (sizeof ???) - 2 ; UNICODE_STRING.Length
dw (sizeof ???) ; UNICODE_STRING.MaximumLength
dd offset ??? ; UNICODE_STRING.Buffer
.code
invoke IoCreateDevice, pDriverObject, 0, offset g_usDeviceName, \
FILE_DEVICE_UNKNOWN, 0, FALSE, addr g_pDeviceObject
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
: R E A D Y T O C O M P I L E E X A M P L E S :
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::: Ready To Compile Ex 1 :::::::::::::::::::::::::::::::::::::::
.386
.model flat, stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
include \masm32\Macros\Strings.mac
.data
ms MEMORYSTATUS <>
buffer db 100 dup(0)
TA "Percent of memory in use:\t\t%d\n", szFormat
TA "Bytes of physical memory:\t\t%d\n"
TA "Free physical memory bytes:\t\t%d\n"
TA "Bytes of paging file:\t\t%d\n"
TA "Free bytes of paging file:\t\t%d\n"
TA "User bytes of address space:\t\t%d\n"
TA0 "Free user bytes:\t\t\t%d\n"
.code
start:
invoke GlobalMemoryStatus, addr ms
invoke wsprintf, addr buffer, addr szFormat, \
ms.dwMemoryLoad, \
ms.dwTotalPhys, \
ms.dwAvailPhys, \
ms.dwTotalPageFile, \
ms.dwAvailPageFile, \
ms.dwTotalVirtual, \
ms.dwAvailVirtual
invoke MessageBox, NULL, addr buffer, $CTA0("Memory Info"), MB_OK
invoke ExitProcess, 0
end start
:::::::::::::::::::::::::::::::::::::: Ready To Compile Ex 2 :::::::::::::::::::::::::::::::::::::::
.386
.model flat, stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
include \masm32\Macros\Strings.mac
.code
start:
invoke WinHelp, NULL, $CTA0("\\masm32\\help\\masm32.hlp", 4), HELP_CONTENTS, 0
invoke ExitProcess, 0
end start
:::::::::::::::::::::::::::::::::::::: Ready To Compile Ex 3 :::::::::::::::::::::::::::::::::::::::
.386
.model flat, stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
include \masm32\Macros\Strings.mac
.code
start:
invoke MessageBox, NULL, $CTA0("Cool program v1.0\nCopyright © Cool Coder, 2005"), $CTA0("About"), MB_OK
invoke ExitProcess, 0
end start
:::::::::::::::::::::::::::::::::::::: Ready To Compile Ex 4 :::::::::::::::::::::::::::::::::::::::
.386
.model flat, stdcall
option casemap:none
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
include \masm32\Macros\Strings.mac
; under NT define 1
; under w9x define 0
UNICODE = 0
LoadLibraryA proto :DWORD
LoadLibraryW proto :DWORD
IF UNICODE EQ 1
LoadLibrary equ <LoadLibraryW>
ELSE
LoadLibrary equ <LoadLibraryA>
ENDIF
GetProcAddress proto :DWORD, :DWORD
ExitProcess proto :DWORD
MessageBoxA proto :DWORD, :DWORD, :DWORD, :DWORD
MessageBoxW proto :DWORD, :DWORD, :DWORD, :DWORD
IF UNICODE EQ 1
MessageBox equ <MessageBoxW>
ELSE
MessageBox equ <MessageBoxA>
ENDIF
wsprintfA proto C :DWORD, :DWORD, :VARARG
wsprintfW proto C :DWORD, :DWORD, :VARARG
IF UNICODE EQ 1
wsprintf equ <wsprintfW>
ELSE
wsprintf equ <wsprintfA>
ENDIF
proto04 TYPEDEF proto :DWORD, :DWORD, :DWORD, :DWORD
pproto04 TYPEDEF PTR proto04
.data?
pfnMassageBox DWORD ?
hinstUser32 DWORD ?
buffer BYTE 32 dup(?)
.code
start:
invoke LoadLibrary, $CT0("user32.dll", 4)
mov hinstUser32, eax
;; Exported functions names is always ASCII
IF UNICODE EQ 1
invoke GetProcAddress, hinstUser32, $CTA0("MessageBoxW", 4)
ELSE
invoke GetProcAddress, hinstUser32, $CTA0("MessageBoxA", 4)
ENDIF
mov pfnMassageBox, eax
invoke wsprintf, addr buffer, $CT0("%08X"), pfnMassageBox
invoke pproto04 ptr [pfnMassageBox], 0, addr buffer, $CT0("MessageBox", 4), 0
invoke ExitProcess, 0
end start
^
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;;IFDEF UNICODE
;; UNICODE = 1
;;ENDIF
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; T E X T M A C R O S S T A R T
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
SSS_TemporaryString TEXTEQU <>
SSS_NumStringsInConstAnsi = 0
SSS_NumStringsInDataAnsi = 0
SSS_NumStringsInConstUnicode = 0
SSS_NumStringsInDataUnicode = 0
SSS_NumStringsInConstAnsi0 = 0
SSS_NumStringsInDataAnsi0 = 0
SSS_NumStringsInConstUnicode0 = 0
SSS_NumStringsInDataUnicode0 = 0
SSS_ConstAnsi0ZeroString TEXTEQU <>
SSS_DataAnsi0ZeroString TEXTEQU <>
SSS_ConstUnicode0ZeroString TEXTEQU <>
SSS_DataUnicode0ZeroString TEXTEQU <>
SSS_ConstAnsi0ZeroStringAlignment TEXTEQU <0>
SSS_DataAnsi0ZeroStringAlignment TEXTEQU <0>
SSS_ConstUnicode0ZeroStringAlignment TEXTEQU <0>
SSS_DataUnicode0ZeroStringAlignment TEXTEQU <0>
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; STRINGA
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
IFDEF UNICODE
IF UNICODE NE 0
STRING equ STRINGW
ELSE
STRING equ STRINGA
ENDIF
ELSE
STRING equ STRINGA
ENDIF
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
STRINGA MACRO _s_
local txt, str, c, bslash, lq, sc
txt TEXTEQU <>
bslash = 0 ;; backslash reached
lq = 0 ;; leading quotation mark ( "...... )
sc = 0 ;; separating comma ( ...,... )
str SUBSTR <_s_>, 1
% FORC cha, <str>
IF bslash
bslash = 0
IF "&cha" EQ "\"
IF sc
txt CATSTR txt, <,>
sc = 0
ENDIF
IF lq
txt CATSTR txt, <&cha>
ELSE
txt CATSTR txt, <">, <&cha> ;; add ( " )
lq = 1 ;; set flag
ENDIF
ELSE
IF lq
txt CATSTR txt, <"> ;;"
lq = 0
sc = 1
ENDIF
IF sc
txt CATSTR txt, <,>
ENDIF
sc = 1
IF "&cha" EQ "n" ;; \n = CR, LF
txt CATSTR txt, <0Dh,0Ah>
ELSEIF "&cha" EQ "r" ;; \r = CR
txt CATSTR txt, <0Dh>
ELSEIF "&cha" EQ "l" ;; \l = LF
txt CATSTR txt, <0Ah>
ELSEIF "&cha" EQ ":" ;; \: = !
txt CATSTR txt, <21h>
ELSEIF "&cha" EQ "{" ;; \{ = (
txt CATSTR txt, <28h>
ELSEIF "&cha" EQ "}" ;; \} = )
txt CATSTR txt, <29h>
ELSEIF "&cha" EQ "[" ;; \[ = <
txt CATSTR txt, <3Ch>
ELSEIF "&cha" EQ "]" ;; \] = >
txt CATSTR txt, <3Eh>
ELSEIF "&cha" EQ "=" ;; \= = "
txt CATSTR txt, <22h>
ELSEIF "&cha" EQ "-" ;; \- = '
txt CATSTR txt, <27h>
ELSEIF "&cha" EQ "0" ;; \0 = 0
txt CATSTR txt, <0h>
ELSEIF "&cha" EQ "a" ;; \a = BEL
txt CATSTR txt, <7h>
ELSEIF "&cha" EQ "b" ;; \b = BS
txt CATSTR txt, <8h>
ELSEIF "&cha" EQ "t" ;; \t = HT
txt CATSTR txt, <9h>
ELSEIF "&cha" EQ "v" ;; \v = VT
txt CATSTR txt, <0Bh>
ELSEIF "&cha" EQ "f" ;; \f = FF
txt CATSTR txt, <0Ch>
ELSEIF "&cha" EQ "*" ;; \* = *nothing*
;; Add nothing. Workaround against "CreateFile" -> "CreateFileA" problem.
;; See above KNOWN PROBLEMS for details.
sc = 0
ELSE
txt CATSTR txt, <"&cha">
echo WARNING!: '&cha' : unrecognized character escape sequence
;; This also can be used to workaround against "CreateFile" -> "CreateFileA" problem.
;; See above KNOWN PROBLEMS for details.
ENDIF
ENDIF
ELSE
IF "&cha" EQ "\"
bslash = 1
ELSE
IF sc
txt CATSTR txt, <,>
sc = 0
ENDIF
IF lq
txt CATSTR txt, <&cha>
ELSE
txt CATSTR txt, <">, <&cha> ;; add leading ( " )
lq = 1 ;; set flag
ENDIF
ENDIF
ENDIF
ENDM
IF lq
txt CATSTR txt, <"> ;;"
ENDIF
EXITM <txt>
ENDM
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; STRINGW
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
STRINGW MACRO _s_
local txt, str, bslash, lq, sc
txt TEXTEQU <>
bslash = 0 ;; backslash reached
lq = 0 ;; leading quotation mark ( "...... )
sc = 0 ;; separating comma ( ...,... )
str SUBSTR <_s_>, 1
% FORC cha, <str>
IF bslash
bslash = 0
IF "&cha" EQ "\"
IF sc
txt CATSTR txt, <,>
sc = 0
ENDIF
txt CATSTR txt, <"&cha">
sc = 1
ELSE
IF lq
txt CATSTR txt, <"> ;;"
lq = 0
sc = 1
ENDIF
IF sc
txt CATSTR txt, <,>
ENDIF
sc = 1
IF "&cha" EQ "n" ;; \n = CR, LF
txt CATSTR txt, <0Dh,0Ah>
ELSEIF "&cha" EQ "r" ;; \r = CR
txt CATSTR txt, <0Dh>
ELSEIF "&cha" EQ "l" ;; \l = LF
txt CATSTR txt, <0Ah>
ELSEIF "&cha" EQ ":" ;; \: = !
txt CATSTR txt, <21h>
ELSEIF "&cha" EQ "{" ;; \{ = (
txt CATSTR txt, <28h>
ELSEIF "&cha" EQ "}" ;; \} = )
txt CATSTR txt, <29h>
ELSEIF "&cha" EQ "[" ;; \[ = <
txt CATSTR txt, <3Ch>
ELSEIF "&cha" EQ "]" ;; \] = >
txt CATSTR txt, <3Eh>
ELSEIF "&cha" EQ "=" ;; \= = "
txt CATSTR txt, <22h>
ELSEIF "&cha" EQ "-" ;; \- = '
txt CATSTR txt, <27h>
ELSEIF "&cha" EQ "0" ;; \0 = 0
txt CATSTR txt, <0h>
ELSEIF "&cha" EQ "a" ;; \a = BEL
txt CATSTR txt, <7h>
ELSEIF "&cha" EQ "b" ;; \b = BS
txt CATSTR txt, <8h>
ELSEIF "&cha" EQ "t" ;; \t = HT
txt CATSTR txt, <9h>
ELSEIF "&cha" EQ "v" ;; \v = VT
txt CATSTR txt, <0Bh>
ELSEIF "&cha" EQ "f" ;; \f = FF
txt CATSTR txt, <0Ch>
ELSEIF "&cha" EQ "*" ;; \* = *nothing*
;; Add nothing. Workaround against "CreateFile" -> "CreateFileA" problem.
;; See above LIMITATIONS for details.
sc = 0
ELSE
txt CATSTR txt, <"&cha">
echo WARNING!: '&cha' : unrecognized character escape sequence
;; This also can be used to workaround against "CreateFile" -> "CreateFileA" problem.
;; See above LIMITATIONS for details.
ENDIF
ENDIF
ELSE
IF "&cha" EQ "\"
bslash = 1
ELSE
IF sc
txt CATSTR txt, <,>
sc = 0
ENDIF
txt CATSTR txt, <"&cha">
sc = 1
ENDIF
ENDIF
ENDM
EXITM <txt>
ENDM
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; MACROS NOT TERMINATING STRING WITH ZERO
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; TA /CTA / TW / CTW
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
TA MACRO txt, lora, aorl
local d, aln, sn, line
IFNB <txt>
SSS_TemporaryString SUBSTR <txt>, 2, @SizeStr(<txt>) - 2
ELSE
SSS_TemporaryString TEXTEQU <>
ENDIF
aln TEXTEQU <1>
IFNB <lora>
IF (OPATTR (lora)) AND 00000100y ;; immediate value ?
;; yes -> lora is alignment
aln TEXTEQU %lora
ELSE
;; no -> lora is label
d TEXTEQU <lora>
ENDIF
ENDIF
IFNB <aorl>
IF (OPATTR (aorl)) AND 00000100y ;; immediate value ?
;; yes -> aorl is alignment
aln TEXTEQU %aorl
ELSE
;; no -> aorl is label
d TEXTEQU <aorl>
ENDIF
ENDIF
sn TEXTEQU @CurSeg
.data
IF @SizeStr(%SSS_TemporaryString)
ALIGN aln
d db STRINGA(%SSS_TemporaryString)
ELSE
;;ALIGN aln
;;d db 0
;; Do not let define empty string with TA macro
;; because it defines non-zero terminating strings.
;; So, empty non-zero terminating string... What's this for?
line TEXTEQU %@Line
% ECHO @FileCur(line) : TA macro ERROR! To define empty string use TA0
.ERR
ENDIF
@CurSeg ENDS
sn SEGMENT
ENDM
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
CTA MACRO txt, lora, aorl
local d, aln, sn, line
;; remove quotation marks if not empty string
IFNB <txt>
SSS_TemporaryString SUBSTR <txt>, 2, @SizeStr(<txt>) - 2
ELSE
SSS_TemporaryString TEXTEQU <>
ENDIF
aln TEXTEQU <1>
IFNB <lora>
IF (OPATTR (lora)) AND 00000100y ;; immediate value ?
;; yes -> lora is alignment
aln TEXTEQU %lora
ELSE
;; no -> lora is label
d TEXTEQU <lora>
ENDIF
ENDIF
IFNB <aorl>
IF (OPATTR (aorl)) AND 00000100y ;; immediate value ?
;; yes -> aorl is alignment
aln TEXTEQU %aorl
ELSE
;; no -> aorl is label
d TEXTEQU <aorl>
ENDIF
ENDIF
sn TEXTEQU @CurSeg
.const
IF @SizeStr(%SSS_TemporaryString)
ALIGN aln
d db STRINGA(%SSS_TemporaryString)
ELSE
;;ALIGN aln
;;d db 0
;; Do not let define empty string with CTA macro
;; because it defines non-zero terminating strings.
;; So, empty non-zero terminating string... What's this for?
line TEXTEQU %@Line
% ECHO @FileCur(line) : CTA macro ERROR! To define empty string use CTA0
.ERR
ENDIF
@CurSeg ENDS
sn SEGMENT
ENDM
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
TW MACRO txt, lora, aorl
local d, aln, sn, line
;; remove quotation marks if not empty string
IFNB <txt>
SSS_TemporaryString SUBSTR <txt>, 2, @SizeStr(<txt>) - 2
ELSE
SSS_TemporaryString TEXTEQU <>
ENDIF
aln TEXTEQU <2>
IFNB <lora>
IF (OPATTR (lora)) AND 00000100y ;; immediate value ?
;; yes -> lora is alignment
aln TEXTEQU %lora
ELSE
;; no -> lora is label
d TEXTEQU <lora>
ENDIF
ENDIF
IFNB <aorl>
IF (OPATTR (aorl)) AND 00000100y ;; immediate value ?
;; yes -> aorl is alignment
aln TEXTEQU %aorl
ELSE
;; no -> aorl is label
d TEXTEQU <aorl>
ENDIF
ENDIF
IF aln LT 2
line TEXTEQU %@Line
% ECHO @FileCur(line) : TW macro WARNING! Alignment for Unicode string must be at least 2 bytes.
ENDIF
sn TEXTEQU @CurSeg
.data
IF @SizeStr(%SSS_TemporaryString)
ALIGN aln
d dw STRINGW(%SSS_TemporaryString)
ELSE
;;ALIGN aln
;;d dw 0
;; Do not let define empty string with TW macro
;; because it defines non-zero terminating strings.
;; So, empty non-zero terminating string... What's this for?
line TEXTEQU %@Line
% ECHO @FileCur(line) : TW macro ERROR! To define empty string use TW0
.ERR
ENDIF
@CurSeg ENDS
sn SEGMENT
ENDM
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
CTW MACRO txt, lora, aorl
local d, aln, sn, line
;; remove quotation marks if not empty string
IFNB <txt>
SSS_TemporaryString SUBSTR <txt>, 2, @SizeStr(<txt>) - 2
ELSE
SSS_TemporaryString TEXTEQU <>
ENDIF
aln TEXTEQU <2>
IFNB <lora>
IF (OPATTR (lora)) AND 00000100y ;; immediate value ?
;; yes -> lora is alignment
aln TEXTEQU %lora
ELSE
;; no -> lora is label
d TEXTEQU <lora>
ENDIF
ENDIF
IFNB <aorl>
IF (OPATTR (aorl)) AND 00000100y ;; immediate value ?
;; yes -> aorl is alignment
aln TEXTEQU %aorl
ELSE
;; no -> aorl is label
d TEXTEQU <aorl>
ENDIF
ENDIF
IF aln LT 2
line TEXTEQU %@Line
% ECHO @FileCur(line) : CTW macro WARNING! Alignment for Unicode string must be at least 2 bytes.
ENDIF
sn TEXTEQU @CurSeg
.const
IF @SizeStr(%SSS_TemporaryString)
ALIGN aln
d dw STRINGW(%SSS_TemporaryString)
ELSE
;;ALIGN aln
;;d dw 0
;; Do not let define empty string with CTW macro
;; because it defines non-zero terminating strings.
;; So, empty non-zero terminating string... What's this for?
line TEXTEQU %@Line
% ECHO @FileCur(line) : CTW macro ERROR! To define empty string use CTW0
.ERR
ENDIF
@CurSeg ENDS
sn SEGMENT
ENDM
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
T MACRO txt, lora, aorl
IFDEF UNICODE
IF UNICODE NE 0
TW txt, lora, aorl
ELSE
TA txt, lora, aorl
ENDIF
ELSE
TA txt, lora, aorl