]> git.8kb.co.uk Git - dataflex/df32func/blob - src/df32/macro.inc
Just pushing the latest copy of my development / staging DataFlex stuff into git...
[dataflex/df32func] / src / df32 / macro.inc
1 //-------------------------------------------------------------------------
2 // macro.inc
3 //      This file contains definitions of DataFlex 3.2 Console Mode macro functions
4 //      to provide some extended command functionality.
5 //
6 // This file is to be included in df32func.mk
7 //
8 // Copyright (c) 2006-2015, glyn@8kb.co.uk
9 // 
10 // df32func/macro.inc
11 //-------------------------------------------------------------------------
12
13 //-------------------------------------------------------------------------
14 // Macro commands
15 //-------------------------------------------------------------------------
16
17
18 // Assertions
19 // ASSERT <true/false evaluation> <assert message> -- provides a similar functionality to c assert.  
20 // 
21 //     if enable_dfassert is defined then evaluations are run and errors are raised
22 //     if enable_dfassert is undefined then assertions are effectively removed at compile time
23 //    
24 //     A failed assertion will raise an error
25 //
26 // Example usage:   
27 //    
28 //     Define enable_dfassert
29 //     ASSERT (1=2) "TEST ASSERT"
30 //
31 #COMMAND ASSERT R
32     #IFDEF ENABLE_DFASSERT
33         #IF (!0=2)
34             #IFTYPE !1 "I"
35                 if (!1 = 0);
36                     error 999999 ("RAISED ASSERTION: '"+string(!2)+"'")
37             #ENDIF
38         #ENDIF
39     #ENDIF
40 #ENDCOMMAND
41
42 // Custom errors
43 //
44 // Used to produce multiline error messages as the error command is 
45 // limited to 40 chars (the original length of ERROR_DESCR in FLEXERRS.DAT)
46 //
47 // Will replace "??" in any message with a variable
48 //
49 // Example usage:
50 //
51 //     custom_error <error_code> <error_message>
52 //     custom_error <error_code> <error_message> <error_message replacement>
53 //     custom_error <error_code> <error_message> <error_detail> <error_detail replacement>
54 //
55 #COMMAND CUSTOM_ERROR R
56     #IF (!0>1)
57         #IFTYPE !1 "I"
58             #IFTYPE !2 "S"
59                 #IF (!0=2)
60                     error !1 !2
61                 #ELSE
62                     #IF (!0=3)
63                         error !1 (replace("??", !2, string(!3)))
64                     #ELSE
65                         #IF (!0=4)
66                             error !1 !2
67                             #IFTYPE !3 "S"
68                                 error !1 ("Detail: "+(replace("??", !3, string(!4))))
69                             #ENDIF
70                         #ENDIF
71                     #ENDIF
72                 #ENDIF
73             #ENDIF
74         #ENDIF
75     #ENDIF        
76 #ENDCOMMAND
77
78 // Ternary command (an operator would be nice)
79 // Behaves similar to perl/c ternary operators E.g. "(evaluation) ? true_var : false_var"
80 //
81 // Example usage:
82 //
83 //     ternary mytable.myboolean "YES" "NO" my_string
84 //     ternary (1=1) "YES" "NO" my_string
85 //
86 // Note that this command form functions just like perl/c and if something like:
87 // "(evaluation) ? true_evaluation : false_evaluation" is written then only the
88 // secondary OR tertiary evaluation will execute dependant on the result of 
89 // the primary evaluation.
90 //
91 // There is also a "ternary" function (math.inc) which can be used in place of an operator, 
92 // however beware that the function works differently; both the secondary AND tertiary
93 // evaluations happen before primary evaluation is tested, rather than being exclusive
94 // (as they should really be) this is a limitation of passing via the function. Thus 
95 // the function is only really useful for variables.
96 //
97 #COMMAND TERNARY R
98     #IF (!0>3)
99         #IFTYPE !1 "I"
100             if (!1 = 1) move !2 to !4
101             else move !3 to !4
102         #ELSE
103             #IFTYPE !1 "S"
104                 if ((lowercase(!1) eq 't') or (lowercase(!1) eq 'true')) move !2 to !4
105                 else move !3 to !4
106             #ELSE
107                 move !3 to !4
108             #ENDIF
109         #ENDIF
110     #ENDIF
111 #ENDCOMMAND