|
| 1 | +{============================================================================== |
| 2 | + _____ _ ___ _ ™ |
| 3 | + |_ _(_)_ _ _ _| _ \__ _ ___ __ __ _| | |
| 4 | + | | | | ' \ || | _/ _` (_-</ _/ _` | | |
| 5 | + |_| |_|_||_\_, |_| \__,_/__/\__\__,_|_| |
| 6 | + |__/ Pascal in your Pocket! |
| 7 | +
|
| 8 | + Copyright © 2025-present tinyBigGAMES™ LLC |
| 9 | + All Rights Reserved. |
| 10 | +
|
| 11 | + https://github.com/tinyBigGAMES/TinyPascal |
| 12 | +
|
| 13 | + BSD 3-Clause License |
| 14 | +
|
| 15 | + Copyright (c) 2025-present, tinyBigGAMES LLC |
| 16 | +
|
| 17 | + Redistribution and use in source and binary forms, with or without |
| 18 | + modification, are permitted provided that the following conditions are met: |
| 19 | +
|
| 20 | + 1. Redistributions of source code must retain the above copyright notice, this |
| 21 | + list of conditions and the following disclaimer. |
| 22 | +
|
| 23 | + 2. Redistributions in binary form must reproduce the above copyright notice, |
| 24 | + this list of conditions and the following disclaimer in the documentation |
| 25 | + and/or other materials provided with the distribution. |
| 26 | +
|
| 27 | + 3. Neither the name of the copyright holder nor the names of its |
| 28 | + contributors may be used to endorse or promote products derived from |
| 29 | + this software without specific prior written permission. |
| 30 | +
|
| 31 | + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 32 | + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 33 | + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 34 | + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| 35 | + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 36 | + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 37 | + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 38 | + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 39 | + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 40 | + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 41 | +==============================================================================} |
| 42 | + |
| 43 | +unit TinyPascal.Common; |
| 44 | + |
| 45 | +{$I TinyPascal.Defines.inc} |
| 46 | + |
| 47 | +interface |
| 48 | + |
| 49 | +uses |
| 50 | + System.SysUtils; |
| 51 | + |
| 52 | +// Debug output control - no global variables exposed |
| 53 | +procedure SetDebugOutput(const AEnabled: Boolean); |
| 54 | +function GetDebugOutput(): Boolean; |
| 55 | + |
| 56 | +// Debug output routines - automatically check enabled state |
| 57 | +procedure DebugWriteLn(const AMessage: string); overload; |
| 58 | +procedure DebugWrite(const AMessage: string); |
| 59 | +procedure DebugWriteLn(const AFormat: string; const AArgs: array of const); overload; |
| 60 | + |
| 61 | +implementation |
| 62 | + |
| 63 | +var |
| 64 | + LDebugEnabled: Boolean = True; // Private to unit - default enabled for development |
| 65 | + |
| 66 | +{ Debug Control Functions } |
| 67 | + |
| 68 | +procedure SetDebugOutput(const AEnabled: Boolean); |
| 69 | +begin |
| 70 | + LDebugEnabled := AEnabled; |
| 71 | +end; |
| 72 | + |
| 73 | +function GetDebugOutput(): Boolean; |
| 74 | +begin |
| 75 | + Result := LDebugEnabled; |
| 76 | +end; |
| 77 | + |
| 78 | +{ Debug Output Functions } |
| 79 | + |
| 80 | +procedure DebugWriteLn(const AMessage: string); |
| 81 | +begin |
| 82 | + if not LDebugEnabled then Exit; // Early exit for performance |
| 83 | + WriteLn(AMessage); |
| 84 | +end; |
| 85 | + |
| 86 | +procedure DebugWrite(const AMessage: string); |
| 87 | +begin |
| 88 | + if not LDebugEnabled then Exit; // Early exit for performance |
| 89 | + Write(AMessage); |
| 90 | +end; |
| 91 | + |
| 92 | +procedure DebugWriteLn(const AFormat: string; const AArgs: array of const); |
| 93 | +begin |
| 94 | + if not LDebugEnabled then Exit; // Early exit for performance |
| 95 | + WriteLn(Format(AFormat, AArgs)); |
| 96 | +end; |
| 97 | + |
| 98 | +end. |
0 commit comments