├── .gitattributes ├── LICENSE ├── README.md ├── convert ├── GenerateWinAPIKeywords.uc ├── LoadAll.Bat ├── PBtoCPP.Bat ├── WinAPIKeywords.txt ├── beautify.uc ├── filehandler.uc ├── implicit-convert.uc ├── implicit-dim.uc ├── interactive.uc ├── math.uc ├── old │ ├── filehandler.uc │ └── pbstrings.h ├── pb-to-cpp.uc ├── pbMisc.h ├── pbOS.h ├── pbkeywords.txt ├── pbstrings.h ├── precompile.uc ├── print.uc ├── refactor.uc ├── stdafx.h ├── strings.uc ├── typespecifiers.uc └── win32api.inc └── test ├── SampleCode.Bas ├── SampleCode.cpp └── old ├── AfterBeautify.cpp ├── BeforeBeautify.cpp ├── SamplePBcode.Bas ├── parenth.bas ├── typespecifiers.bas ├── uCalc.bas └── uCalc.cpp /.gitattributes: -------------------------------------------------------------------------------- 1 | * text eol=crlf 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013, Daniel Corbier 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | Redistributions in binary form must reproduce the above copyright notice, this 11 | list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | Neither the name of the {organization} nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | powerbasic-to-cpp 2 | ================= 3 | 4 | Converts PowerBASIC source code to C++ using uCalc Transform. 5 | 6 | If you write programs using PowerBASIC and would like to extend the reach of your software to smartphones and tablets and other operating systems, with platforms like iOS, Mac OS X, Linux, Android, Windows Phone OS, etc, or if you want to have a 64-bit version of your DLL for Windows, then one solution is to convert your code to C++, which can then be re-compiled on these other platforms. You can still continue developing in PowerBASIC, and later perform the auto-conversion of your code to C++ when needed. 7 | 8 | ### How To 9 | 10 | To convert your source code with this tool, do the following: 11 | 1. Download uCalc Transform from http://www.ucalc.com/transform.html 12 | 2. Click the `Download ZIP` button found on this page 13 | 3. Place the file(s) you want to convert in the same directory as the files from this page 14 | 4. Run uCalc Transform, then click on the `C:\> Batch` button 15 | 5. Go to the directory containing your file(s), and type: PBtoCPP.Bat MyFile.Bas 16 | 17 | (where MyFile.Bas is the file you want to convert) 18 | 19 | PBtoCPP.Bat /D to debug (produces intermediate files) 20 | PBtoCPP.Bat /F for faster transform 21 | 22 | This requires version 2.98 or above. 23 | 24 | To load transforms for editing, enter LoadAll.Bat at the command prompt. 25 | 26 | ### Using uCalc Transform 27 | ![uCalc Transform](http://www.ucalc.com/images/pbtocpp.png "uCalc Transform Example") 28 | 29 | Automatically translating source code from one language to another is among the things uCalc Transform (downloadable from http://www.ucalc.com/transform.html ) is designed for. This Open Source project is about constructing the transform file(s) that will tell uCalc Transform how to take PowerBASIC source code as input, and automatically generate equivalent C++ output. 30 | 31 | The process is very simple. A transform file consists of a list of Find/Replace criteria pairs, one of which may look like this: 32 | 33 | The Find part (representing PowerBASIC): 34 | `If {cond} Then {statement%}{nl}` 35 | 36 | The Replace part (representing C++): 37 | `if ({cond}) { {statement} }{nl}` 38 | 39 | ### How to help 40 | 41 | Your help is needed in creating Search/Replace patterns covering as many PowerBASIC statements and constructs as possible. PowerBASIC is close enough to Visual Basic in a number of ways, so VB users can also help. Even C++ users who don't program in any flavor of BASIC can help with C++ parts. On the other hand, if you don't do any C++, there's plenty you can do, such as work on transforms that refactor PowerBASIC code before it is translated to C++. There's a part for everyone. 42 | 43 | Here are various ways you can contribute (choose any combination of these): 44 | 45 | - Test existing patterns, and point out situations where it doesn't work (or confirm that it works in all cases you've tried it). 46 | 47 | - Post test cases that other contributors can test their patterns against to make sure their patterns work as intended. Please post a short snippet of sample PowerBASIC code in one file with a .bas extension, and also, if possible, a similarly named file, but with a .cpp extension representing what the output should look like. 48 | 49 | - Post Find/Replace patterns. The following are suggested guidelines. Feel free to suggest other guidelines that could make the process even easier. 50 | - Use the current version of uCalc Transform to construct your Find/Replace patterns. 51 | - Test it. 52 | - Click where it says: "[Add a description]" in uCalc Transform (on the bottom right of the save button), and identify yourself as the author of that section, along with a summary of what you're contributing. Note: Each individual Find/Replace criteria also includes a Comment property. You may also enter text in a Find box, and remove the checkmark (so it is ignored) to have it serve as a comment for items below. 53 | - Save it and upload it along with the test code you used. 54 | 55 | - Make suggestions, ask questions, cheer the project on, invite others to join, etc. 56 | 57 | -------------------------------------------------------------------------------- /convert/GenerateWinAPIKeywords.uc: -------------------------------------------------------------------------------- 1 | # GenerateWinAPIKeywords.uc - uCalc Transformation file 2 | # This file was saved with uCalc Transform 2.96 on 5/13/2014 9:42:24 AM 3 | # Comment: Parses Win32API.inc to generate keword list (equates, Subs, Functions) 4 | 5 | ExternalKeywords: Exclude, Comment, Selected, ParentChild, FindMode, InputFile, OutputFile, BatchAction, SEND 6 | ExternalKeywords: Highlight, ForeColor, BackColor, FontName, FontSize, FontStyle 7 | ExternalKeywords: FilterEndText, FilterSeparator, FilterSort, FilterSortFunc, FilterStartText, FilterUnique, FilterTally 8 | 9 | FindMode: Replace 10 | 11 | # Definitions 12 | 13 | 14 | # Search Criteria 15 | 16 | Criteria: 0 17 | Enabled: True 18 | Exclude: False 19 | Comment: Parses Win32API.inc to generate keword list (equates, Subs, Functions) 20 | Selected: False 21 | Highlight: False 22 | ForeColor: ControlText 23 | BackColor: Aqua 24 | FontName: 25 | FontSize: 26 | FontStyle: 27 | CaseSensitive: False 28 | QuoteSensitive: False 29 | CodeBlockSensitive: False 30 | FilterEndText: 31 | FilterSeparator: {#10} 32 | FilterSort: True 33 | FilterSortFunc: 34 | FilterStartText: 35 | FilterUnique: True 36 | FilterTally: False 37 | Min: 0 38 | Max: -1 39 | MinSoft: 0 40 | MaxSoft: -1 41 | BatchAction: Filter 42 | InputFile: 43 | OutputFile: 44 | SEND: 45 | StartAfter: 0 46 | StopAfter: -1 47 | SkipOver: False 48 | ParentChild: 0 49 | Pass: 0 50 | PassOnce: True 51 | Precedence: 0 52 | RightToLeft: False 53 | 54 | Criteria: 1 55 | Selected: True 56 | Find: 57 | Replace: {@Var: Includes As Table} 58 | {@Exec: Insert(Includes, "Win32API.inc")} 59 | 60 | Criteria: 2 61 | Comment: Insert content of nested include files 62 | Pass: 1 63 | 64 | Criteria: 3 65 | BackColor: DeepSkyBlue 66 | PassOnce: False 67 | Find: {nl}#include {q}{file}{q} 68 | Replace: ' =============== Include: {file} =============== 69 | {@Eval: 70 | IIf(Index(Includes, "{file}"), 71 | "' Already included", 72 | Insert(Includes, "{file}"); FileText("{file}") 73 | ) 74 | } 75 | ' ============ End of Include: {file} =========== 76 | 77 | Criteria: 4 78 | Comment: Filter out keywords 79 | Pass: 2 80 | 81 | Criteria: 5 82 | Highlight: True 83 | BackColor: Orange 84 | Find: {nl}{ Union | Type | % | $[$] } {name:1} 85 | Replace: {name} 86 | 87 | Criteria: 6 88 | Highlight: True 89 | BackColor: DeepSkyBlue 90 | Find: {nl}Declare { Sub | Function } {name:1} 91 | Replace: {name} 92 | 93 | # End Search 94 | -------------------------------------------------------------------------------- /convert/LoadAll.Bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | REM This loads all the transforms at the same time (each under a separate tab) 3 | REM for easier editing. 4 | 5 | uCalcTransform /i ^ 6 | /TF:Interactive.uc ^ 7 | /TF:precompile.uc ^ 8 | /TF:refactor.uc ^ 9 | /TF:implicit-dim.uc ^ 10 | /TF:typespecifiers.uc ^ 11 | /TF:implicit-convert.uc ^ 12 | /TF:strings.uc ^ 13 | /TF:filehandler.uc ^ 14 | /TF:math.uc ^ 15 | /TF:print.uc ^ 16 | /TF:pb-to-cpp.uc ^ 17 | /TF:beautify.uc ^ 18 | SampleCode.Bas 19 | 20 | -------------------------------------------------------------------------------- /convert/PBtoCPP.Bat: -------------------------------------------------------------------------------- 1 | @ECHO off 2 | SETLOCAL 3 | 4 | IF "%1" == "/?" ( 5 | ECHO To convert a file from PowerBASIC to C++, run this: 6 | ECHO. 7 | ECHO PBtoCPP MyFile.Bas 8 | ECHO. 9 | ECHO ^(Rename MyFile.Bas to your PB input file^) 10 | ECHO This will produce MyFile.cpp as output. 11 | ECHO. 12 | ECHO For debugging purposes run: 13 | ECHO. 14 | ECHO PBtoCPP /D MyFile.Bas 15 | ECHO. 16 | ECHO This preserves a list of intermediate transform files, which can offer 17 | ECHO insight into the transformations performed by each .uc file. 18 | EXIT /B 19 | ) 20 | 21 | IF /I "%1" == "/D" ( 22 | SET DEBUG=True 23 | SHIFT 24 | ) 25 | 26 | IF /I "%1" == "/F" ( 27 | SET FAST=True 28 | SHIFT 29 | ) 30 | 31 | SET FILE=%~n1 32 | 33 | IF /I "%DEBUG%" == "True" ( 34 | REM This option is for debugging 35 | uCalcTransform precompile.uc %1 %FILE%.1.tmp /Q 36 | uCalcTransform refactor.uc %FILE%.1.tmp %FILE%.2.tmp /Q 37 | uCalcTransform implicit-dim.uc %FILE%.2.tmp %FILE%.3.tmp /Q 38 | uCalcTransform typespecifiers.uc %FILE%.3.tmp %FILE%.4.tmp /Q 39 | uCalcTransform implicit-convert.uc %FILE%.4.tmp %FILE%.5.tmp /Q 40 | uCalcTransform strings.uc %FILE%.5.tmp %FILE%.6.tmp /Q 41 | uCalcTransform filehandler.uc %FILE%.6.tmp %FILE%.7.tmp /Q 42 | uCalCTransform math.uc %FILE%.7.tmp %FILE%.8.tmp /Q 43 | uCalCTransform print.uc %FILE%.8.tmp %FILE%.9.tmp /Q 44 | uCalcTransform pb-to-cpp.uc %FILE%.9.tmp %FILE%.10.tmp /Q 45 | uCalcTransform beautify.uc %FILE%.10.tmp %FILE%.cpp /Q 46 | ) ELSE ( 47 | IF /I "%FAST%" == "True" ( 48 | uCalcTransform interactive.uc %1 %FILE%.cpp %2 /q 49 | EXIT /B 50 | ) 51 | 52 | uCalcTransform "precompile.uc|refactor.uc|implicit-dim.uc|typespecifiers.uc|implicit-convert.uc|strings.uc|filehandler.uc|math.uc|print.uc|pb-to-cpp.uc|beautify.uc" %1 %FILE%.cpp %2 /q 53 | ) 54 | -------------------------------------------------------------------------------- /convert/beautify.uc: -------------------------------------------------------------------------------- 1 | # beautify.uc - uCalc Transformation file 2 | # This file was saved with uCalc Transform 2.95 on 4/17/2014 10:43:37 AM 3 | # Comment: Fixes indentation and spacing in C++ source code 4 | 5 | ExternalKeywords: Exclude, Comment, Selected, ParentChild, FindMode, InputFile, OutputFile, BatchAction, SEND 6 | ExternalKeywords: Highlight, ForeColor, BackColor, FontName, FontSize, FontStyle 7 | ExternalKeywords: FilterEndText, FilterSeparator, FilterSort, FilterSortFunc, FilterStartText, FilterUnique, FilterTally 8 | 9 | FindMode: Replace 10 | 11 | # Definitions 12 | 13 | 14 | # Search Criteria 15 | 16 | Criteria: 0 17 | Enabled: True 18 | Exclude: False 19 | Comment: Fixes indentation and spacing in C++ source code 20 | Selected: False 21 | Highlight: False 22 | ForeColor: ControlText 23 | BackColor: Aqua 24 | FontName: 25 | FontSize: 26 | FontStyle: 27 | CaseSensitive: False 28 | QuoteSensitive: True 29 | CodeBlockSensitive: True 30 | FilterEndText: 31 | FilterSeparator: {#10} 32 | FilterSort: False 33 | FilterSortFunc: 34 | FilterStartText: 35 | FilterUnique: False 36 | FilterTally: False 37 | Min: 0 38 | Max: -1 39 | MinSoft: 0 40 | MaxSoft: -1 41 | BatchAction: Transform 42 | InputFile: 43 | OutputFile: 44 | SEND: 45 | StartAfter: 0 46 | StopAfter: -1 47 | SkipOver: False 48 | ParentChild: 0 49 | Pass: 0 50 | PassOnce: True 51 | Precedence: 0 52 | RightToLeft: False 53 | 54 | Criteria: 1 55 | Find: 56 | Replace: {@Define: 57 | Var: Indentation = 0 58 | Const: IndentSize = 3 59 | SyntaxArg: {spc} = [{"[ \n]+"}] 60 | Inline: {indent+} := Indentation += IndentSize 61 | Inline: {indent-} := Indentation -= IndentSize 62 | Inline: {indent} := " " * Indentation 63 | } 64 | {@Eval: Indentation = 0} 65 | {@Token:: //[^`]*` ~~ Properties: ucWhiteSpace} 66 | 67 | Criteria: 2 68 | Comment: Strips all indentation and some spacing 69 | Pass: 1 70 | 71 | Criteria: 3 72 | Find: {comment:"//.*"} 73 | Replace: {comment}` 74 | 75 | Criteria: 4 76 | BackColor: Brown 77 | Find: {"\n"}{" +"} 78 | Replace: {nl} 79 | 80 | Criteria: 5 81 | SkipOver: True 82 | Find: ({code~}) 83 | Replace: [Skip over] 84 | 85 | Criteria: 6 86 | Comment: 87 | Pass: 2 88 | 89 | Criteria: 7 90 | BackColor: RoyalBlue 91 | Find: {spc} "{" {spc} 92 | Replace: { 93 | 94 | Criteria: 8 95 | BackColor: Pink 96 | Find: {spc} "}" 97 | Replace: } 98 | 99 | Criteria: 9 100 | BackColor: Purple 101 | Find: {" *; *"} 102 | Replace: ; 103 | 104 | Criteria: 10 105 | Find: {" *, *"} 106 | Replace: ,{sp} 107 | 108 | Criteria: 11 109 | Comment: Handles semicolons 110 | Pass: 3 111 | 112 | Criteria: 12 113 | Selected: True 114 | BackColor: Green 115 | Find: ({params~}) 116 | Replace: ({@Evaluate: Replace({params}, ";", "; ")}) 117 | 118 | Criteria: 13 119 | BackColor: SandyBrown 120 | Find: ;{char:"[^\n]"} 121 | Replace: ;{nl}{char} 122 | 123 | Criteria: 14 124 | Comment: Preserves comment location if it's after a ";" 125 | Find: ;{" *//"} 126 | Replace: ; // 127 | 128 | Criteria: 15 129 | Comment: Performs indentation 130 | Pass: 4 131 | 132 | Criteria: 16 133 | BackColor: DeepSkyBlue 134 | Find: {nl} 135 | Replace: {nl}{indent} 136 | 137 | Criteria: 17 138 | BackColor: DarkKhaki 139 | Find: "{" [[{" +"}]{comment:"//[^`]*`"}[{nl}]] 140 | Replace: {sp}{{comment: {comment}}{nl}{indent+}{indent} 141 | 142 | Criteria: 18 143 | BackColor: Yellow 144 | Find: "}" [[{" +"}]{comment:"//[^`]*`"}] 145 | Replace: {nl}{indent-}{indent}}{comment: {comment}} 146 | 147 | Criteria: 19 148 | BackColor: Brown 149 | Find: {nl}{type:1}{func:1}([{args+}])"{" 150 | Replace: {nl}{type} {func}({args}){nl}{{indent+}{nl}{indent} 151 | 152 | Criteria: 20 153 | Comment: 154 | Pass: 5 155 | 156 | Criteria: 21 157 | Find: {comment:" *//[^`]*"}` 158 | Replace: {comment} 159 | 160 | # End Search 161 | -------------------------------------------------------------------------------- /convert/filehandler.uc: -------------------------------------------------------------------------------- 1 | # filehandler.uc - uCalc Transformation file 2 | # This file was saved with uCalc Transform 2.96 on 5/16/2014 11:49:59 AM 3 | # Comment: File handler 4 | 5 | ExternalKeywords: Exclude, Comment, Selected, ParentChild, FindMode, InputFile, OutputFile, BatchAction, SEND 6 | ExternalKeywords: Highlight, ForeColor, BackColor, FontName, FontSize, FontStyle 7 | ExternalKeywords: FilterEndText, FilterSeparator, FilterSort, FilterSortFunc, FilterStartText, FilterUnique, FilterTally 8 | 9 | FindMode: Replace 10 | 11 | # Definitions 12 | 13 | 14 | # Search Criteria 15 | 16 | Criteria: 0 17 | Enabled: True 18 | Exclude: False 19 | Comment: File handler 20 | Selected: False 21 | Highlight: True 22 | ForeColor: ControlText 23 | BackColor: Aqua 24 | FontName: 25 | FontSize: 26 | FontStyle: 27 | CaseSensitive: False 28 | QuoteSensitive: True 29 | CodeBlockSensitive: True 30 | FilterEndText: 31 | FilterSeparator: {#10} 32 | FilterSort: False 33 | FilterSortFunc: 34 | FilterStartText: 35 | FilterUnique: False 36 | FilterTally: False 37 | Min: 0 38 | Max: -1 39 | MinSoft: 0 40 | MaxSoft: -1 41 | BatchAction: Transform 42 | InputFile: 43 | OutputFile: 44 | SEND: 45 | StartAfter: 0 46 | StopAfter: -1 47 | SkipOver: False 48 | ParentChild: 0 49 | Pass: 0 50 | PassOnce: True 51 | Precedence: 0 52 | RightToLeft: False 53 | 54 | Criteria: 1 55 | Find: 56 | Replace: {@Var: FreeFileNum} 57 | {@Token:: : ~~ Properties: ucStatementSep } 58 | 59 | Criteria: 2 60 | Comment: 61 | Pass: 1 62 | 63 | Criteria: 3 64 | BackColor: Yellow 65 | SkipOver: True 66 | Find: ' {Comment:".*"} 67 | Replace: [Skip over] 68 | 69 | Criteria: 4 70 | BackColor: DeepSkyBlue 71 | Find: Open {filespec} 72 | { For {{Input: Input}|{Output: Output}|{Append: Append}|{Binary: Binary}|{Random: Random}}|{Default: } } 73 | { Access Read | Access Write | Access Read Write | } 74 | { Lock {{LockRead: Read}|{LockWrite: Write}|{LockBoth: Read Write}|{LockShared: Shared}}|{LockDefault: } } 75 | As [#]{filenum} [Len = {size=128}] 76 | Replace: fstream file_{filenum} (string({filespec}).c_str(), 77 | {Input: ios::in} 78 | {Output: ios::out | ios::trunc} 79 | {Append: ios::out | ios::app} 80 | {Binary: ios::binary | ios::in | ios::out} 81 | {Random: ios::binary | ios::in | ios::out} 82 | {Default: ios::binary | ios::in | ios::out} 83 | ) 84 | 85 | Criteria: 5 86 | BackColor: Lime 87 | Find: Close [#]{filenum} 88 | Replace: file_{filenum}.close() ' PB: Close #{filenum} 89 | 90 | Criteria: 6 91 | BackColor: RoyalBlue 92 | PassOnce: False 93 | Find: Close [#]{file1}, {more} 94 | Replace: Close {file1} 95 | Close {more} 96 | 97 | Criteria: 7 98 | BackColor: Pink 99 | Find: Seek [#] {filenum}, {position} 100 | Replace: file_{filenum}.seekg({position}-1) 101 | file_{filenum}.seekp({position}-1) 102 | 103 | Criteria: 8 104 | Find: Seek([#] {filenum}) 105 | Replace: (int)file_{filenum}.tellg()+1 106 | 107 | Criteria: 9 108 | BackColor: SlateBlue 109 | Find: LOF([#] {filenum}) 110 | Replace: PB_LOF(file_{filenum}) 111 | 112 | Criteria: 10 113 | Find: EOF([#] {filenum}) 114 | Replace: file_{filenum}.eof() 115 | 116 | Criteria: 11 117 | Find: FreeFile 118 | Replace: {@Eval: FreeFileNum += 1; FreeFileNum} 119 | 120 | Criteria: 12 121 | BackColor: Green 122 | Find: Get$ [#] {filenum}, {count}, {StringVar} 123 | Replace: {StringVar}.resize({count}) 124 | file_{filenum}.read(&{StringVar}[0], {count}) 125 | 126 | Criteria: 13 127 | BackColor: SandyBrown 128 | Find: Put$ [#] {filenum}, {text} 129 | Replace: file_{filenum}.write(&{text}[0], {text}.size()) 130 | 131 | Criteria: 14 132 | Find: IsFile({file}) 133 | Replace: PB_ISFILE({file}) 134 | 135 | Criteria: 15 136 | Find: Name {oldname} As {newname} 137 | Replace: PB_NAME({oldname}, {newname}) 138 | 139 | Criteria: 16 140 | BackColor: Gold 141 | Find: EXE.Extn[$] 142 | Replace: PB_EXE_EXTN 143 | 144 | Criteria: 17 145 | Selected: True 146 | BackColor: Silver 147 | Find: EXE.Full[$] 148 | Replace: PB_EXE_FULL() 149 | 150 | Criteria: 18 151 | Find: EXE.Name[$] 152 | Replace: PB_EXE_NAME 153 | 154 | Criteria: 19 155 | BackColor: CornflowerBlue 156 | Find: EXE.Namex[$] 157 | Replace: PB_EXE_NAMEX 158 | 159 | Criteria: 20 160 | Find: EXE.Path[$] 161 | Replace: PB_EXE_PATH 162 | 163 | Criteria: 21 164 | Find: Dir$({mask}) 165 | Replace: PB_DIR({mask}) 166 | 167 | Criteria: 22 168 | Find: Dir$([Next]) 169 | Replace: PB_DIR_NEXT() 170 | 171 | Criteria: 23 172 | Find: Print #{filenum} 173 | Replace: file_{filenum} << endl 174 | 175 | Criteria: 24 176 | Find: Print #{filenum}, {text} 177 | Replace: file_{filenum} << {text} << endl 178 | 179 | Criteria: 25 180 | Find: Print #{filenum}, {text}; 181 | Replace: file_{filenum} << {text} 182 | 183 | Criteria: 26 184 | PassOnce: False 185 | Find: Print #{filenum}, {text}; {MoreText} 186 | Replace: Print #{filenum}, {text} << {MoreText} 187 | 188 | Criteria: 27 189 | Comment: 190 | Pass: 2 191 | 192 | Criteria: 28 193 | BackColor: Yellow 194 | Find: fstream {file} ({args+}) 195 | Replace: {@Evaluate: Replace({@Self}, '{"[ \r\n]+"}', ' ')} 196 | 197 | # End Search 198 | -------------------------------------------------------------------------------- /convert/implicit-convert.uc: -------------------------------------------------------------------------------- 1 | # implicit-convert.uc - uCalc Transformation file 2 | # This file was saved with uCalc Transform 2.98 on 7/11/2014 8:18:09 AM 3 | # Comment: Handles implicit data type conversions 4 | 5 | ExternalKeywords: Exclude, Comment, Selected, ParentChild, FindMode, InputFile, OutputFile, BatchAction, SEND 6 | ExternalKeywords: Highlight, ForeColor, BackColor, FontName, FontSize, FontStyle 7 | ExternalKeywords: FilterEndText, FilterSeparator, FilterSort, FilterSortFunc, FilterStartText, FilterUnique, FilterTally 8 | 9 | # Definitions 10 | 11 | 12 | # Search Criteria 13 | 14 | Criteria: 0 15 | Enabled: True 16 | Exclude: False 17 | Comment: Handles implicit data type conversions 18 | Selected: False 19 | Highlight: True 20 | ForeColor: ControlText 21 | BackColor: Aqua 22 | FontName: 23 | FontSize: 24 | FontStyle: 25 | CaseSensitive: False 26 | QuoteSensitive: False 27 | CodeBlockSensitive: True 28 | FilterEndText: 29 | FilterSeparator: {#10} 30 | FilterSort: False 31 | FilterSortFunc: 32 | FilterStartText: 33 | FilterUnique: False 34 | FilterTally: False 35 | Min: 0 36 | Max: -1 37 | MinSoft: 0 38 | MaxSoft: -1 39 | BatchAction: Transform 40 | InputFile: 41 | OutputFile: 42 | SEND: 43 | StartAfter: 0 44 | StopAfter: -1 45 | SkipOver: False 46 | ParentChild: 0 47 | Pass: 0 48 | PassOnce: True 49 | Precedence: 0 50 | RightToLeft: False 51 | 52 | Criteria: 1 53 | Highlight: False 54 | Find: 55 | Replace: {@Eval: 56 | Dim Size As Table = { 57 | "Byte", 1, "Word", 2, "Integer", 2, "Long", 4, "Dword", 4, 58 | "Single", 4, "Double", 8, "Extended", 10 59 | } 60 | } 61 | {@Define: 62 | Var: Def As String 63 | Var: Args As String 64 | Var: Before As String 65 | Var: After As String 66 | Var: UDT As Table 67 | Var: Size 68 | Var: Final 69 | Var: Variables As Table 70 | SyntaxArgL: {number} = {number:"([0-9]*\.)?[0-9]+(e[-+]?[0-9]+)?"} 71 | } 72 | {@Define:: Token: _.*\n ~~ Properties: ucWhitespace } 73 | 74 | Criteria: 2 75 | Comment: Inserts data type names in front of variabls and functions 76 | Pass: 1 77 | 78 | Criteria: 3 79 | Highlight: False 80 | Find: {nl}[Declare] { Function | Sub } {name~:1} [Alias {alias}] ([{args%}]) [As {ftype:1=void}] 81 | Replace: {@Exec: 82 | Args = Remove("{args}", "{ Optional | ByVal | () | {' *_.*\n *'} }") 83 | Before = Replace(Args, "[ByRef] {arg:1} As {type:1} [Ptr]", "{{arg}%}") 84 | After = Replace(Args, "ByRef {arg:1} As {type:1}", "ByRef({arg} As {type})") 85 | After = Replace(After, "{arg:1} As {type:1} Ptr", "Ptr({arg} As {type})") 86 | After = Replace(After, "{arg:1} As {type:1}", "##{type}({{arg}})") 87 | 88 | Def = "Pass: 1 ~~ Syntax: {name}("+Before+")" 89 | Def += " ::= `{ftype}({name}(" + After + "))" 90 | }{@Define:: {@Eval: Def}}{Self} 91 | 92 | Criteria: 4 93 | Highlight: False 94 | Find: { Global | Local | Static | Dim | , | { ByVal | ByRef } } {var:1}[([{size}])] As {type:1} 95 | Replace: {Self}{@Execute: Insert(Variables, {var}) 96 | }{@Define:: Pass: 1 ~~ Syntax: {var} ::= `{type}({var}) 97 | }{@Define:: Pass: 1 ~~ Syntax: {var}([{i%}]) ::= `{type}({var}({i}))} 98 | 99 | Criteria: 5 100 | Highlight: False 101 | Find: {number} 102 | Replace: {@Eval: IIf(Int({number})=={number}, "`Long({number})", "`Extended({number})")} 103 | 104 | Criteria: 6 105 | Highlight: False 106 | BackColor: RoyalBlue 107 | Find: {q}{text}{q} 108 | Replace: `StringLit({Self}) 109 | 110 | Criteria: 7 111 | Highlight: False 112 | BackColor: Pink 113 | Find: {func: Asc|InStr|Len|UBound|VarPtr|StrPtr|Ceil|Int } ({args%}) 114 | Replace: `Long({func}({args})) 115 | 116 | Criteria: 8 117 | Find: {func: Sin|Cos|Tan|Atn|Exp|Exp2|Exp10|Log|Log2|Log10|Abs } ({args%}) 118 | Replace: `Extended({func}({args})) 119 | 120 | Criteria: 9 121 | Highlight: False 122 | BackColor: SlateBlue 123 | Find: {func: 124 | Mid|Left|Right|Remove|Extract|Space|Hex|Oct|Bin|Dir|Min|Max| 125 | Remain|UCase|LCase|Trim|LTrim|RTrim|Choose|Repeat|Dir|CurDir 126 | }$({args%}) 127 | Replace: `String({func}$({args})) 128 | 129 | Criteria: 10 130 | Find: {nl}${equate:1} 131 | Replace: {Self}{@Define:: Pass: 1 ~~ Syntax: ${equate} ::= `String(${equate})} 132 | 133 | Criteria: 11 134 | Find: {nl}$${equate:1} 135 | Replace: {Self}{@Define:: Pass: 1 ~~ Syntax: $${equate} ::= `WString($${equate})} 136 | 137 | Criteria: 12 138 | Find: {nl}%{equate:1} 139 | Replace: {Self}{@Define:: Pass: 1 ~~ Syntax: %{equate} ::= `Long(%{equate})} 140 | 141 | Criteria: 13 142 | Highlight: False 143 | BackColor: Purple 144 | SkipOver: True 145 | Find: {nl} { Type | Union } 146 | {members+} 147 | End {TypeOrUnion} 148 | Replace: [Skip over] 149 | 150 | Criteria: 14 151 | BackColor: Khaki 152 | SkipOver: True 153 | Find: {nl}{ # | ! | ASM } {etc} {@Note: Skips metastatements, ASM} 154 | Replace: [Skip over] 155 | 156 | Criteria: 15 157 | SkipOver: True 158 | Find: ' {Comment:".*"} 159 | Replace: [Skip over] 160 | 161 | Criteria: 16 162 | Comment: Convert 163 | Pass: 2 164 | 165 | Criteria: 17 166 | BackColor: Violet 167 | PassOnce: False 168 | Find: ##Asciiz(string({arg})) 169 | Replace: `Asciiz({arg}.c_str()) 170 | 171 | Criteria: 18 172 | Find: `StringLit({arg}) 173 | Replace: `String({arg}) 174 | 175 | Criteria: 19 176 | PassOnce: False 177 | Find: `StringLit({arg1})+`StringLit({arg2}) 178 | Replace: `String(string({arg1})+{arg2}) 179 | 180 | Criteria: 20 181 | BackColor: CornflowerBlue 182 | PassOnce: False 183 | Find: `WString({arg1}) + `StringLit({arg2}) 184 | Replace: `WString({arg1}) + `WString(L{arg2}) 185 | 186 | Criteria: 21 187 | Find: Len({other}) 188 | Replace: sizeof({other}) 189 | 190 | Criteria: 22 191 | BackColor: SandyBrown 192 | PassOnce: False 193 | Find: Len(`String({arg})) 194 | Replace: string({arg}).length() 195 | 196 | Criteria: 23 197 | BackColor: Gold 198 | PassOnce: False 199 | Find: Len(`LPCSTR({arg})) 200 | Replace: `Long(strlen({arg})) 201 | 202 | Criteria: 24 203 | PassOnce: False 204 | Find: `{ Extended | Ext } 205 | Replace: `Double 206 | 207 | Criteria: 25 208 | SkipOver: True 209 | Find: ' {Comment:".*"} 210 | Replace: [Skip over] 211 | 212 | Criteria: 26 213 | Comment: Handles ByRef and removes temp characters 214 | Pass: 3 215 | 216 | Criteria: 27 217 | Selected: True 218 | Find: {@Start} 219 | {@Note: 220 | The use of Final is due to a limitation where immediate expansion in 221 | {arg%} expands all passes causing the undesirable change in pass 3 222 | before it is needed. 223 | } 224 | Replace: {@Exec: Final = True} 225 | 226 | Criteria: 28 227 | PassOnce: False 228 | Find: ByRef(##{RequiredType}({arg})) {@If: Final} 229 | Replace: lvalue({RequiredType}({arg})) 230 | 231 | Criteria: 29 232 | PassOnce: False 233 | Find: ByRef(##{RequiredType}(`{ActualType}({scalar:1}[()]))) 234 | {@If: Final == True And Index(Variables, {scalar}) <> 0} 235 | Replace: {scalar} 236 | 237 | Criteria: 30 238 | PassOnce: False 239 | Find: ByRef(##{RequiredType}(`{ActualType}({array:1}({index})))) 240 | {@If: Final == True And Index(Variables, {array}) <> 0} 241 | Replace: {array}({index}) 242 | 243 | Criteria: 31 244 | PassOnce: False 245 | Find: Ptr(##{RequiredType}({arg})) 246 | Replace: ({RequiredType} *)({arg}) 247 | 248 | Criteria: 32 249 | PassOnce: False 250 | Find: { ` | ## }{type:1}({arg}) {@If: Final} 251 | Replace: {arg} 252 | 253 | # End Search 254 | -------------------------------------------------------------------------------- /convert/implicit-dim.uc: -------------------------------------------------------------------------------- 1 | # implicit-dim.uc - uCalc Transformation file 2 | # This file was saved with uCalc Transform 2.96 on 6/4/2014 5:06:03 PM 3 | # Comment: Declares variables (with Dim) that were not explicitely declared before 4 | 5 | ExternalKeywords: Exclude, Comment, Selected, ParentChild, FindMode, InputFile, OutputFile, BatchAction, SEND 6 | ExternalKeywords: Highlight, ForeColor, BackColor, FontName, FontSize, FontStyle 7 | ExternalKeywords: FilterEndText, FilterSeparator, FilterSort, FilterSortFunc, FilterStartText, FilterUnique, FilterTally 8 | 9 | FindMode: Replace 10 | 11 | # Definitions 12 | 13 | 14 | # Search Criteria 15 | 16 | Criteria: 0 17 | Enabled: True 18 | Exclude: False 19 | Comment: Declares variables (with Dim) that were not explicitely declared before 20 | Selected: False 21 | Highlight: False 22 | ForeColor: ControlText 23 | BackColor: Aqua 24 | FontName: 25 | FontSize: 26 | FontStyle: 27 | CaseSensitive: False 28 | QuoteSensitive: True 29 | CodeBlockSensitive: True 30 | FilterEndText: 31 | FilterSeparator: {#10} 32 | FilterSort: False 33 | FilterSortFunc: 34 | FilterStartText: 35 | FilterUnique: False 36 | FilterTally: False 37 | Min: 0 38 | Max: -1 39 | MinSoft: 0 40 | MaxSoft: -1 41 | BatchAction: Transform 42 | InputFile: ImplicitDim.Bas 43 | OutputFile: 44 | SEND: 45 | StartAfter: 0 46 | StopAfter: -1 47 | SkipOver: False 48 | ParentChild: 0 49 | Pass: 0 50 | PassOnce: True 51 | Precedence: 0 52 | RightToLeft: False 53 | 54 | Criteria: 1 55 | Find: {@Note: 56 | 57 | This transform does the following: 58 | 59 | * Declares variables that were not previously declared explicitely 60 | * Comments out user declarations that are from the Windows API 61 | * Ensures that the casing of variables/functions is consistent 62 | with their declarations since C++ is case-sensitive 63 | 64 | } 65 | 66 | Replace: {@Define:: 67 | Token: \x27.* ~~ Properties: ucWhitespace 68 | Token: _[^\n]*\n ~~ Properties: ucWhitespace 69 | } 70 | {@Define: 71 | Var: Globals As Table 72 | Var: ImplicitDim As Table 73 | Var: ExplicitDim As Table 74 | Var: CurrentRoutine As String 75 | Var: Prototype As String 76 | Var: Prototypes As String 77 | Var: ExpIndex As Long 78 | Var: ImpIndex As Long 79 | Var: FuncIndex As Long 80 | Var: GlobalIndex As Long 81 | SyntaxArg: NameAndSpecifier = "[a-z][a-z0-9_]*[$#!?%&]*" 82 | } 83 | {@Exec: 84 | Split(File("PBKeywords.txt")+Chr(13,10)+File("WinAPIKeywords.txt")) 85 | uc_For(x, 1, StringItemCount, 2, Insert(Globals, StringItem(x))) 86 | } 87 | 88 | Criteria: 2 89 | Comment: Teporarily adds Dim keyword in front of args for further parsing 90 | Pass: 1 91 | 92 | Criteria: 3 93 | Selected: True 94 | Find: {nl}{routine: Sub | Function } {etc}([{args}]) [[{exp: Export}] [As {type:1}]] 95 | Replace: {@Eval: 96 | Prototype = {Q}{routine} {etc}({args:Dim {args}}){exp}{type: As {type}}{Q} 97 | Prototypes += "{nl}Declare " + Prototype 98 | "{nl}" + Prototype 99 | } 100 | 101 | Criteria: 4 102 | SkipOver: True 103 | Find: {nl}Function = 104 | Replace: [Skip over] 105 | 106 | Criteria: 5 107 | Comment: Inserts explicitly Dimmed variable names in global or local tables 108 | Pass: 2 109 | 110 | Criteria: 6 111 | PassOnce: False 112 | Find: {@Start} 113 | Replace: ' Prototypes 114 | {@Eval: Prototypes} 115 | ' End of prototypes{nl} 116 | 117 | Criteria: 7 118 | Find: Global{" +"}{variable:NameAndSpecifier} 119 | Replace: {Self}{@Evaluate: Insert(Globals, {variable})} 120 | 121 | Criteria: 8 122 | BackColor: Silver 123 | Find: {nl}{ Macro | Type | Union | % | $[$] | Declare {func:1} } {name:1} 124 | Replace: {Self}{@Evaluate: Insert(Globals, {name})} 125 | 126 | Criteria: 9 127 | BackColor: Lime 128 | Find: {nl}{ Sub | Function }{" +"}{RoutineName:"[a-z0-9_]+"} 129 | Replace: {Self}{@Define: 130 | Var: {RoutineName}ExplicitDim As Table 131 | Var: {RoutineName}ImplicitDim As Table 132 | }{@Eval: SetVar(CurrentRoutine, "{RoutineName}"); Insert(Globals,"{RoutineName}")} 133 | 134 | Criteria: 10 135 | Find: {nl}End { Sub | Function } 136 | Replace: {Self}{@Evaluate: SetVar(CurrentRoutine, "")} 137 | 138 | Criteria: 11 139 | BackColor: Pink 140 | Find: {declare: Dim [[Optional] { ByVal | ByRef }] | Local | Static | Register | fstream } 141 | {" +"}{variable:NameAndSpecifier} 142 | Replace: {Self}{@Eval: Insert(~Eval(CurrentRoutine)ExplicitDim, "{variable}")} 143 | 144 | Criteria: 12 145 | Comment: Temporarily inserts declaration for each individual variable a lines with a list of multiple vars, for easier parsing 146 | BackColor: SlateBlue 147 | PassOnce: False 148 | Find: {declare: Global|Dim|Local|Static|Register} {variable}, 149 | Replace: {declare} {variable} ::: {declare} 150 | 151 | Criteria: 13 152 | Find: {nl}%{equate:1} = {@If: Index(Globals, {equate})} 153 | Replace: {nl} ' {equate} = 154 | 155 | Criteria: 14 156 | Find: {nl}Declare {method: Sub | Function } {name:1} {@If: Index(Globals, {name})} 157 | Replace: {nl} ' Declare {method} {name} 158 | 159 | Criteria: 15 160 | Comment: Places non-Dimmed variable names in separate local tables 161 | Pass: 3 162 | 163 | Criteria: 16 164 | Find: [{eq: %}]{name:NameAndSpecifier} [{IsFunc:" *\("}] 165 | Replace: {eq}{@Eval: 166 | ExpIndex = Index(~Eval(CurrentRoutine)ExplicitDim, "{name}") 167 | ImpIndex = Index(~Eval(CurrentRoutine)ImplicitDim, "{name}") 168 | FuncIndex = Index(Globals, Remove("{name}", "{'[$#!?%&]+'}")) 169 | GlobalIndex = Index(Globals, "{name}") 170 | IIf(ExpIndex+ImpIndex+FuncIndex+GlobalIndex == 0 And "{IsFunc}" == "", 171 | Insert(~Eval(CurrentRoutine)ImplicitDim, "{name}")) 172 | 173 | text = "{name}" 174 | IIf(GlobalIndex, text = ReadKey(Globals, GlobalIndex)) 175 | IIf(ExpIndex, text = ReadKey(~Eval(CurrentRoutine)ExplicitDim, ExpIndex)) 176 | IIf(ImpIndex, text = ReadKey(~Eval(CurrentRoutine)ImplicitDim, ImpIndex)) 177 | text + "{IsFunc}" 178 | } 179 | 180 | Criteria: 17 181 | SkipOver: True 182 | Find: {"[a-z0-9_]+"} {UDT:"\.[a-z0-9_\@\.]+"} 183 | Replace: [Skip over] 184 | 185 | Criteria: 18 186 | SkipOver: True 187 | Find: {"&h[0-9a-f]+"} 188 | Replace: [Skip over] 189 | 190 | Criteria: 19 191 | Find: {"Exe"}.{suffix:1}$ 192 | Replace: Exe.{suffix} 193 | 194 | Criteria: 20 195 | BackColor: Brown 196 | Find: {"\n"}{ Sub | Function }{" +"}{RoutineName:"[a-z0-9_]+"} 197 | Replace: {Self}{@Evaluate: SetVar(CurrentRoutine, {RoutineName})} 198 | 199 | Criteria: 21 200 | Find: {"\n"}End { Sub | Function } 201 | Replace: {Self}{@Evaluate: SetVar(CurrentRoutine, "")} 202 | 203 | Criteria: 22 204 | Comment: Inserts local Dim statements for variables that were not dimmed 205 | Pass: 4 206 | 207 | Criteria: 23 208 | BackColor: Purple 209 | Find: {nl}{ Sub | Function }{" +"}{RoutineName:"[a-z0-9_]+"} {etc} 210 | Replace: {Self} 211 | {@Eval: 212 | Range(1, Count({RoutineName}ImplicitDim), 213 | {Q}" Dim "+ReadKey({RoutineName}ImplicitDim, x)+" ' Implicit"+Chr(10){Q}) 214 | } 215 | 216 | Criteria: 24 217 | Comment: Clean up (temp declaration statements removed) 218 | Pass: 5 219 | 220 | Criteria: 25 221 | BackColor: Violet 222 | Find: ::: {declare:1} 223 | Replace: , 224 | 225 | Criteria: 26 226 | BackColor: CornflowerBlue 227 | Find: (Dim {args}) 228 | Replace: ({@Eval: Replace("{args}", "::: Dim", ",")}) 229 | 230 | Criteria: 27 231 | Find: Dim {nl} 232 | Replace: {Nothing} 233 | 234 | # End Search 235 | -------------------------------------------------------------------------------- /convert/interactive.uc: -------------------------------------------------------------------------------- 1 | # interactive.uc - uCalc Transformation file 2 | # This file was saved with uCalc Transform 2.96 on 5/28/2014 10:50:51 AM 3 | # Comment: Allows you to convert with a click of a button instead of a batch file 4 | 5 | ExternalKeywords: Exclude, Comment, Selected, ParentChild, FindMode, InputFile, OutputFile, BatchAction, SEND 6 | ExternalKeywords: Highlight, ForeColor, BackColor, FontName, FontSize, FontStyle 7 | ExternalKeywords: FilterEndText, FilterSeparator, FilterSort, FilterSortFunc, FilterStartText, FilterUnique, FilterTally 8 | 9 | FindMode: Replace 10 | 11 | # Definitions 12 | 13 | 14 | # Search Criteria 15 | 16 | Criteria: 0 17 | Enabled: True 18 | Exclude: False 19 | Comment: Allows you to convert with a click of a button instead of a batch file 20 | Selected: False 21 | Highlight: False 22 | ForeColor: ControlText 23 | BackColor: Aqua 24 | FontName: 25 | FontSize: 26 | FontStyle: 27 | CaseSensitive: False 28 | QuoteSensitive: True 29 | CodeBlockSensitive: True 30 | FilterEndText: 31 | FilterSeparator: {#10} 32 | FilterSort: False 33 | FilterSortFunc: 34 | FilterStartText: 35 | FilterUnique: False 36 | FilterTally: False 37 | Min: 0 38 | Max: -1 39 | MinSoft: 0 40 | MaxSoft: -1 41 | BatchAction: Transform 42 | InputFile: 43 | OutputFile: 44 | SEND: 45 | StartAfter: 0 46 | StopAfter: -1 47 | SkipOver: False 48 | ParentChild: 0 49 | Pass: 0 50 | PassOnce: True 51 | Precedence: 0 52 | RightToLeft: False 53 | 54 | Criteria: 1 55 | Selected: True 56 | Highlight: True 57 | Find: {AllText} 58 | Replace: {@Evaluate: 59 | Text = Transform({AllText}, "precompile.uc") 60 | Text = Transform(Text, "refactor.uc") 61 | Text = Transform(Text, "implicit-dim.uc") 62 | Text = Transform(Text, "typespecifiers.uc") 63 | Text = Transform(Text, "implicit-convert.uc") 64 | Text = Transform(Text, "strings.uc") 65 | Text = Transform(Text, "filehandler.uc") 66 | Text = Transform(Text, "math.uc") 67 | Text = Transform(Text, "print.uc") 68 | Text = Transform(Text, "pb-to-cpp.uc") 69 | Text = Transform(Text, "beautify.uc") 70 | Text 71 | } 72 | 73 | # End Search 74 | -------------------------------------------------------------------------------- /convert/math.uc: -------------------------------------------------------------------------------- 1 | # math.uc - uCalc Transformation file 2 | # This file was saved with uCalc Transform 2.96 on 6/19/2014 7:45:05 PM 3 | # Comment: Converts math-related code from PowerBASIC to C++ 4 | 5 | ExternalKeywords: Exclude, Comment, Selected, ParentChild, FindMode, InputFile, OutputFile, BatchAction, SEND 6 | ExternalKeywords: Highlight, ForeColor, BackColor, FontName, FontSize, FontStyle 7 | ExternalKeywords: FilterEndText, FilterSeparator, FilterSort, FilterSortFunc, FilterStartText, FilterUnique, FilterTally 8 | 9 | FindMode: Replace 10 | 11 | # Definitions 12 | 13 | 14 | # Search Criteria 15 | 16 | Criteria: 0 17 | Enabled: True 18 | Exclude: False 19 | Comment: Converts math-related code from PowerBASIC to C++ 20 | Selected: False 21 | Highlight: True 22 | ForeColor: ControlText 23 | BackColor: Aqua 24 | FontName: 25 | FontSize: 26 | FontStyle: 27 | CaseSensitive: False 28 | QuoteSensitive: True 29 | CodeBlockSensitive: True 30 | FilterEndText: 31 | FilterSeparator: {#10} 32 | FilterSort: False 33 | FilterSortFunc: 34 | FilterStartText: 35 | FilterUnique: False 36 | FilterTally: False 37 | Min: 0 38 | Max: -1 39 | MinSoft: 0 40 | MaxSoft: -1 41 | BatchAction: Transform 42 | InputFile: 43 | OutputFile: 44 | SEND: 45 | StartAfter: 0 46 | StopAfter: -1 47 | SkipOver: False 48 | ParentChild: 0 49 | Pass: 0 50 | PassOnce: True 51 | Precedence: 0 52 | RightToLeft: False 53 | 54 | Criteria: 1 55 | Find: 56 | Replace: {@Var: Type As String} 57 | {@Note: rand & srand are in , the others in } 58 | {@Note: ToDo: \ eqv imp bin } 59 | 60 | Criteria: 2 61 | Comment: ^ (power) 62 | Pass: 1 63 | 64 | Criteria: 3 65 | SkipOver: True 66 | Find: ' {Comment:".*"} 67 | Replace: [Skip over] 68 | 69 | Criteria: 4 70 | BackColor: Gold 71 | Precedence: 100 72 | Find: {x%} ^ {y%} {@Note: precedence property set to 100} 73 | Replace: pow({x}, {y}) 74 | 75 | Criteria: 5 76 | Precedence: 60 77 | Find: {x%} \ {y%} {@Note: precedence property set to 60} 78 | Replace: _round({x} / {y}) 79 | 80 | Criteria: 6 81 | Precedence: 60 82 | Find: {x%} mod {y%} 83 | Replace: Long({x}) mod {y} 84 | 85 | Criteria: 7 86 | Precedence: 19 87 | Find: {x%} Eqv {y%} 88 | Replace: PB_EQV({x}, {y}) 89 | 90 | Criteria: 8 91 | Precedence: 18 92 | Find: {x%} Imp {y%} 93 | Replace: PB_IMP({x}, {y}) 94 | 95 | Criteria: 9 96 | Precedence: 20 97 | Find: {x%} Xor {y%} 98 | Replace: PB_XOR({x}, {y}) 99 | 100 | Criteria: 10 101 | Precedence: 1 102 | Find: To {etc%} 103 | Replace: To {etc} 104 | 105 | Criteria: 11 106 | Find: If {cond%} Then 107 | Replace: If {cond} Then 108 | 109 | Criteria: 12 110 | Find: {nl} {var:1} = {etc%} 111 | Replace: {nl} {var} = {etc} 112 | 113 | Criteria: 13 114 | Comment: Bitwise AND and OR 115 | Pass: 2 116 | 117 | Criteria: 14 118 | SkipOver: True 119 | Find: ' {Comment:".*"} 120 | Replace: [Skip over] 121 | 122 | Criteria: 15 123 | Comment: Bitwise AND and OR 124 | BackColor: YellowGreen 125 | Find: ({expr}) 126 | Replace: ({@Evaluate: Replace(Replace({expr}, "And", "&"), "Or", "|")}) 127 | 128 | Criteria: 16 129 | Comment: Everything else 130 | Pass: 3 131 | 132 | Criteria: 17 133 | SkipOver: True 134 | Find: ' {Comment:".*"} 135 | Replace: [Skip over] 136 | 137 | Criteria: 18 138 | Find: Mod 139 | Replace: % 140 | 141 | Criteria: 19 142 | BackColor: Yellow 143 | Find: Atn 144 | Replace: atan 145 | 146 | Criteria: 20 147 | BackColor: Lime 148 | Find: Sqr 149 | Replace: sqrt 150 | 151 | Criteria: 21 152 | BackColor: Pink 153 | Find: Cint 154 | Replace: Integer 155 | 156 | Criteria: 22 157 | Find: Int( 158 | Replace: __int64( 159 | 160 | Criteria: 23 161 | BackColor: Red 162 | Find: Incr {var:1} 163 | Replace: {var}++ 164 | 165 | Criteria: 24 166 | BackColor: RoyalBlue 167 | Find: Decr {var:1} 168 | Replace: {var}-- 169 | 170 | Criteria: 25 171 | Comment: Logical (short-circuit) AND 172 | Find: And 173 | Replace: && 174 | 175 | Criteria: 26 176 | Comment: Logical (short-circuit) OR 177 | BackColor: Purple 178 | Find: Or 179 | Replace: || 180 | 181 | Criteria: 27 182 | BackColor: Green 183 | Find: Not 184 | Replace: ~ 185 | 186 | Criteria: 28 187 | Comment: Alternative PB notation 188 | Find: => 189 | Replace: >= 190 | 191 | Criteria: 29 192 | Comment: Alternative PB notation 193 | Selected: True 194 | Find: =< 195 | Replace: <= 196 | 197 | Criteria: 30 198 | SkipOver: True 199 | Find: #{metastatement:1} Not 200 | Replace: [Skip over] 201 | 202 | Criteria: 31 203 | BackColor: Silver 204 | Find: IsTrue {x%} [{stop-: And | Or | Then | : }] 205 | Replace: (({x}) != 0) 206 | 207 | Criteria: 32 208 | BackColor: SandyBrown 209 | Find: IsFalse {x%} [{stop-: And | Or | Then | : }] 210 | Replace: !({x}) 211 | 212 | Criteria: 33 213 | BackColor: Violet 214 | Find: <> 215 | Replace: != 216 | 217 | Criteria: 34 218 | Find: Randomize {number%} 219 | Replace: srand({number}) 220 | 221 | Criteria: 35 222 | Find: Rnd[()] 223 | Replace: (rand() / RAND_MAX) 224 | 225 | Criteria: 36 226 | Find: Rnd({a%}, {b%}) 227 | Replace: (rand() % ({b}) + ({a})) 228 | 229 | Criteria: 37 230 | Find: Shift Right {ivar}, {countexpr%} 231 | Replace: {ivar} = ({ivar} >> {countexpr}) 232 | 233 | Criteria: 38 234 | Find: Shift Left {ivar}, {countexpr%} 235 | Replace: {ivar} = ({ivar} << {countexpr}) 236 | 237 | Criteria: 39 238 | Find: {func: Abs|Sin|Cos|Tan|Exp|Exp2|Log|Log2|Log10|Ceil} 239 | Replace: {@Evaluate: LCase("{func}", "{'.*'}")} 240 | 241 | Criteria: 40 242 | Find: {func: Exp10 | Fix | Frac | Sgn} 243 | Replace: PB_{@Evaluate: UCase("{func}", "{'.*'}")} 244 | 245 | Criteria: 41 246 | PassOnce: False 247 | Find: {func: Min | Max}[{ {int: &} | {str: $} | {dbl: } }] 248 | ({args}) 249 | Replace: PB_{@Evaluate: 250 | Type = "(double)" 251 | IIf("{int}" <> "", Type = "(int)") 252 | IIf("{str}" <> "", Type = "(string)") 253 | UCase("{func}", "{'.*'}") 254 | }{int:_INT}{str:_STR}(ARGCOUNT({@Evaluate: 255 | Tally({args}, ",", Skip("({nest})"))+1}), {@Evaluate: 256 | Type + Replace({args}, ",", ", "+Type, Skip("({nest})"))}) 257 | 258 | Criteria: 42 259 | Find: )() 260 | Replace: ){@Note: 261 | because of problem "between = {etc#%}" in pass 1 262 | & Rnd which leaves a stray () 263 | } 264 | 265 | # End Search 266 | -------------------------------------------------------------------------------- /convert/old/filehandler.uc: -------------------------------------------------------------------------------- 1 | # filehandler.uc - uCalc Transformation file 2 | # This file was saved with uCalc Transform 2.5 on 1/23/2014 5:55:48 PM 3 | # Comment: 4 | 5 | ExternalKeywords: Exclude, Comment, Selected, ParentChild, FindMode, OutputFile, BatchAction, SEND 6 | ExternalKeywords: Highlight, ForeColor, BackColor, FontName, FontSize, FontStyle 7 | ExternalKeywords: FilterEndText, FilterSeparator, FilterSort, FilterSortFunc, FilterStartText, FilterUnique 8 | 9 | FindMode: Replace 10 | 11 | # Definitions 12 | 13 | 14 | # Search Criteria 15 | 16 | Criteria: 0 17 | Enabled: True 18 | Exclude: False 19 | Comment: 20 | Selected: False 21 | Highlight: True 22 | ForeColor: ControlText 23 | BackColor: Aqua 24 | FontName: 25 | FontSize: 26 | FontStyle: 27 | CaseSensitive: False 28 | QuoteSensitive: True 29 | CodeBlockSensitive: True 30 | FilterEndText: 31 | FilterSeparator: {#10} 32 | FilterSort: False 33 | FilterSortFunc: 34 | FilterStartText: 35 | FilterUnique: False 36 | Min: 0 37 | Max: -1 38 | MinSoft: 0 39 | MaxSoft: -1 40 | BatchAction: Transform 41 | OutputFile: 42 | SEND: 43 | StartAfter: 0 44 | StopAfter: -1 45 | SkipOver: False 46 | ParentChild: 0 47 | Pass: 0 48 | PassOnce: True 49 | Precedence: 0 50 | RightToLeft: False 51 | 52 | Criteria: 1 53 | Comment: 54 | Pass: 1 55 | 56 | Criteria: 2 57 | BackColor: Yellow 58 | SkipOver: True 59 | Find: ' {Comment:".*"} 60 | Replace: [Skip over] 61 | 62 | Criteria: 3 63 | BackColor: DeepSkyBlue 64 | Find: {@Start} 65 | Replace: #include 66 | 67 | 68 | Criteria: 4 69 | BackColor: DeepSkyBlue 70 | Find: Open {filespec} 71 | { For {{Input: Input}|{Output: Output}|{Append: Append}|{Binary: Binary}|{Random: Random}}|{Default: } } 72 | { Access Read | Access Write | Access Read Write | } 73 | { Lock {{LockRead: Read}|{LockWrite: Write}|{LockBoth: Read Write}|{LockShared: Shared}}|{LockDefault: } } 74 | As [#]{filenum} [Len = {size=128}] 75 | Replace: ' {Self} 76 | _FileHandle({filenum}) = CreateFile({filespec}, 77 | {Input: GENERIC_READ} 78 | {Output: GENERIC_WRITE} 79 | {Append: GENERIC_WRITE} 80 | {Binary: GENERIC_READ Or GENERIC_WRITE} 81 | {Random: GENERIC_READ Or GENERIC_WRITE} 82 | {Default: GENERIC_READ Or GENERIC_WRITE} 83 | , 84 | {LockRead: FILE_SHARE_WRITE} 85 | {LockWrite: FILE_SHARE_READ} 86 | {LockBoth: 0} 87 | {LockShared: FILE_SHARE_READ Or FILE_SHARE_WRITE} 88 | {LockDefault: 0} 89 | , 0, 90 | {Input: OPEN_EXISTING} 91 | {Output: CREATE_ALWAYS} 92 | {Append: OPEN_ALWAYS} 93 | {Binary: OPEN_ALWAYS} 94 | {Random: OPEN_ALWAYS} 95 | {Default: OPEN_ALWAYS} 96 | , FILE_ATTRIBUTE_NORMAL, 0) 97 | {Append:SetFilePointer(_FileHandle({filenum}), 0, 0, FILE_END){nl}} 98 | 99 | Criteria: 5 100 | BackColor: Lime 101 | Find: Close [#]{filenum} 102 | Replace: ' Close #{filenum} 103 | CloseHandle(_FileHandle({filenum})) 104 | _FileHandle({filenum}) = 0 105 | 106 | 107 | Criteria: 6 108 | BackColor: RoyalBlue 109 | PassOnce: False 110 | Find: Close [#]{file1}, {more} 111 | Replace: Close {file1} 112 | Close {more} 113 | 114 | Criteria: 7 115 | BackColor: Pink 116 | Find: Seek [#] {filenum}, {position} 117 | Replace: SetFilePointer(_FileHandle({filenum}), {position}-1, 0, FILE_BEGIN) 118 | 119 | Criteria: 8 120 | Find: Seek([#] {filenum}) 121 | Replace: SetFilePointer(_FileHandle({filenum}), 0, 0, FILE_CURRENT)+1 122 | 123 | Criteria: 9 124 | BackColor: SlateBlue 125 | Find: LOF({filenum}) 126 | Replace: GetFileSize(_FileHandle({filenum}), 0) 127 | 128 | Criteria: 10 129 | Selected: True 130 | Find: EOF({filenum}) 131 | Replace: IIf(Seek({filenum}) = LOF({filenum})+1, -1, 0) 132 | 133 | Criteria: 11 134 | Comment: 135 | Pass: 2 136 | 137 | Criteria: 12 138 | BackColor: Yellow 139 | Find: CreateFile({arg1}{nl}{args+}) 140 | Replace: {@Eval: Replace('{Self}', '{"[ \n]+"}', ' ')} 141 | 142 | # End Search 143 | -------------------------------------------------------------------------------- /convert/old/pbstrings.h: -------------------------------------------------------------------------------- 1 | // PowerBASIC to C++ converter - Macros for PB strings 2 | // https://github.com/uCalc/powerbasic-to-cpp/tree/master/convert/pbstrings.h 3 | // Contributors: Daniel Corbier 4 | // 5 | // ... 6 | // ... 7 | 8 | #define FULL_STRING string::npos 9 | 10 | #define PB_LEFT(MainStr, n) ((n) == 0 ? "" : \ 11 | (n)>0 ? string(MainStr).substr(0, (n)) \ 12 | : string(MainStr).substr(0, string(MainStr).length()+(n))) 13 | 14 | #define PB_RIGHT(MainStr, n) ((n) == 0 ? "" : \ 15 | (n)>0 ? string(MainStr).substr(string(MainStr).length()-(n), (n)) \ 16 | : string(MainStr).substr(-(n), (n)) 17 | 18 | #define PB_MID(MainStr, Start, Length) string(MainStr).substr(Start-1, Length) 19 | // Help needed here for negative Start & Length 20 | // Turns out there might be a conflict between string::npos and MID(..., ..., -1) (for Left$, Right$ too) 21 | // Negative args were not always a feature in PB 22 | // These extra lines might be removed if nobody cares 23 | 24 | #define PB_MID_REPLACE(MainStr, Start, Length) string(MainStr).replace((Start)-1, Length, MainStr) 25 | 26 | #define PB_INSTR(n, MainStr, MatchStr) ((n) == 0 ? 0 : \ 27 | (n)>0 ? string(MainStr).find(MatchStr, (n)-1)+1 \ 28 | : string(MainStr).rfind(MatchStr, string(MainStr).length()+(n))+1) 29 | 30 | #define PB_INSTR_ANY(n, MainStr, MatchStr) ((n) == 0 ? 0 : \ 31 | (n)>0 ? string(MainStr).find_first_of(MatchStr, (n)-1)+1 \ 32 | : string(MainStr).find_last_of(MatchStr, string(MainStr).length()+(n))+1) 33 | -------------------------------------------------------------------------------- /convert/pb-to-cpp.uc: -------------------------------------------------------------------------------- 1 | # pb-to-cpp.uc - uCalc Transformation file 2 | # This file was saved with uCalc Transform 2.96 on 6/19/2014 7:46:46 PM 3 | # Comment: Converts PB source code to C++; modified by Daniel Corbier 4 | 5 | ExternalKeywords: Exclude, Comment, Selected, ParentChild, FindMode, InputFile, OutputFile, BatchAction, SEND 6 | ExternalKeywords: Highlight, ForeColor, BackColor, FontName, FontSize, FontStyle 7 | ExternalKeywords: FilterEndText, FilterSeparator, FilterSort, FilterSortFunc, FilterStartText, FilterUnique, FilterTally 8 | 9 | FindMode: Replace 10 | 11 | # Definitions 12 | 13 | 14 | # Search Criteria 15 | 16 | Criteria: 0 17 | Enabled: True 18 | Exclude: False 19 | Comment: Converts PB source code to C++; modified by Daniel Corbier 20 | Selected: False 21 | Highlight: False 22 | ForeColor: ControlText 23 | BackColor: Aqua 24 | FontName: 25 | FontSize: 26 | FontStyle: 27 | CaseSensitive: False 28 | QuoteSensitive: True 29 | CodeBlockSensitive: True 30 | FilterEndText: 31 | FilterSeparator: {#10} 32 | FilterSort: False 33 | FilterSortFunc: 34 | FilterStartText: 35 | FilterUnique: False 36 | FilterTally: False 37 | Min: 0 38 | Max: -1 39 | MinSoft: 0 40 | MaxSoft: -1 41 | BatchAction: Transform 42 | InputFile: 43 | OutputFile: 44 | SEND: 45 | StartAfter: 0 46 | StopAfter: -1 47 | SkipOver: False 48 | ParentChild: 0 49 | Pass: 0 50 | PassOnce: True 51 | Precedence: 0 52 | RightToLeft: False 53 | 54 | Criteria: 1 55 | PassOnce: False 56 | Find: 57 | Replace: {@Exec: Dim IsPrototype = 1, Case1, UDT, BitType As String } 58 | {@Define:: Token: \xFF[^\xFF]*\xFF\n ~~ Properties: ucWhiteSpace } 59 | 60 | Criteria: 2 61 | Highlight: True 62 | Find: {@Start} 63 | Replace: ' This file ({@Eval: Extract(ShortName(InputFile), ".")}.cpp) was converted from {@Eval: Extract(ShortName(InputFile), ".")}.Bas 64 | ' with {@Eval: AppName} on {@Eval: TimeStamp("MM/dd/yy")} using the Open Source 65 | ' PowerBASIC to C++ converter found at https://github.com/uCalc/powerbasic-to-cpp 66 | 67 | ' Standard lib headers used by PB to C++ are in sdtafx.h & pre-compiled 68 | #include "stdafx.h" 69 | 70 | using namespace std;{nl}{nl} 71 | 72 | #include "pbOS.h" 73 | #include "pbMisc.h" 74 | #include "pbstrings.h" 75 | 76 | 77 | Criteria: 3 78 | Comment: Renames words that conflict w/ C++ keywords 79 | Pass: 1 80 | 81 | Criteria: 4 82 | Find: { auto|bitand|bitor|bool|break|char|compl|constexpr| 83 | continue|default|delete|explicit|extern|false|float| 84 | friend|inline|mutable|new|nullptr|operator|private| 85 | protected|public|short|signed|struct|template|this| 86 | throw|true|typename|unsigned|virtual|void|volatile } 87 | {@If: {@Self} == LCase({@Self})} 88 | Replace: {Self}_Renamed 89 | 90 | Criteria: 5 91 | SkipOver: True 92 | Find: { { ' | _ } {Comment:".*"} | %TRUE | %FALSE } 93 | Replace: [Skip over] 94 | 95 | Criteria: 6 96 | Comment: Handles long line break (underscore _) 97 | Pass: 2 98 | 99 | Criteria: 7 100 | Highlight: True 101 | PassOnce: False 102 | Find: {nl}{line} _ [{" +"}] [{comment:".+"}]{nl} 103 | 104 | Replace: {nl}{line} {#255}{comment}{#255}{nl} 105 | 106 | Criteria: 8 107 | Highlight: True 108 | SkipOver: True 109 | Find: {"[\(\)]"} {@Note: These are ( and ); must be skipped} 110 | Replace: [Skip over] 111 | 112 | Criteria: 9 113 | Highlight: True 114 | SkipOver: True 115 | Find: ' [{comment:".*"}] 116 | Replace: [Skip over] 117 | 118 | Criteria: 10 119 | Comment: Functions, Subs, = 120 | Pass: 3 121 | 122 | Criteria: 11 123 | Highlight: True 124 | Find: = 125 | Replace: == 126 | 127 | Criteria: 12 128 | Selected: True 129 | SkipOver: True 130 | Find: { + | - | * | / | % | & | ^ | ! | > | < | _ReturnValue }= 131 | Replace: [Skip over] 132 | 133 | Criteria: 13 134 | Highlight: True 135 | SkipOver: True 136 | Find: { {nl} [{ %|$[$] }]|Then|Else|For|: }{var:" *[a-z0-9\@\.\_]+"}[({index})] = 137 | Replace: [Skip over] 138 | 139 | Criteria: 14 140 | Highlight: True 141 | SkipOver: True 142 | Find: { { #If | #ElseIf } Not | ' [{comment:".*"}] } 143 | Replace: [Skip over] 144 | 145 | Criteria: 15 146 | Highlight: True 147 | SkipOver: True 148 | Find: Macro {name}[({params})] = 149 | Replace: [Skip over] 150 | 151 | Criteria: 16 152 | Highlight: True 153 | PassOnce: False 154 | Find: Sub {name:1} [Alias {alias}]([{args}])[{exp: Export}] [{comment:" *'.*"}] {nl} 155 | Replace: {exp:extern "C" __declspec(dllexport)} void {exp:__stdcall }{name}({args}) { {comment} 156 | 157 | Criteria: 17 158 | Highlight: True 159 | BackColor: DarkKhaki 160 | PassOnce: False 161 | Find: Function {name:1} [Alias {alias}]([{args}])[{exp: Export}] As {type}[{comment:" *'.*"}]{nl} 162 | Replace: {exp:extern "C" __declspec(dllexport)} {type} {exp:__stdcall }{name}({args}) { {comment} 163 | {type} _ReturnValue = {type}() 164 | {@Define:: Syntax: {name} = ::= _ReturnValue =} 165 | 166 | Criteria: 18 167 | Highlight: True 168 | PassOnce: False 169 | Find: Function PBMain [()] [As Long] 170 | Replace: Function main() As Long 171 | 172 | Criteria: 19 173 | Highlight: True 174 | PassOnce: False 175 | Find: Declare Function {name:1} [Lib {lib}] [Alias {alias}] 176 | [([{args}])] [{exp: Export}] As {type} 177 | Replace: {exp:extern "C" __declspec(dllexport)}{lib: extern __declspec(dllimport)} {type} {exp:__stdcall }{name}({args}) 178 | 179 | Criteria: 20 180 | Highlight: True 181 | Find: Declare Sub {name:1} [Lib {lib}] [Alias {alias}] 182 | [([{args}])] [{exp: Export}] 183 | Replace: {exp:extern "C" __declspec(dllexport)}{lib: extern __declspec(dllimport)} void {exp:__stdcall }{name}({args}) 184 | 185 | Criteria: 21 186 | Find: {nl}End Function 187 | Replace: {nl}{nl}return _ReturnValue 188 | End Function 189 | 190 | Criteria: 22 191 | Highlight: True 192 | Find: Static 193 | Replace: static dim 194 | 195 | Criteria: 23 196 | Comment: For type member access (temp stage) 197 | Find: {typevar:"@*[a-z_][a-z_0-9@]+\.[a-z_0-9@\.]+"} 198 | Replace: `{typevar}` 199 | 200 | Criteria: 24 201 | Comment: Misc 202 | Pass: 4 203 | 204 | Criteria: 25 205 | Highlight: True 206 | SkipOver: True 207 | Find: // [{comment:".*"}] 208 | Replace: [Skip over] 209 | 210 | Criteria: 26 211 | Highlight: True 212 | Find: ' [{comment:".*"}] 213 | Replace: //{comment} 214 | 215 | Criteria: 27 216 | Highlight: True 217 | BackColor: Green 218 | PassOnce: False 219 | Find: {nl}{ {num: %}|{wstr: $$}|{str: $} }{equate} = {value} 220 | Replace: {nl}const{num: int}{str: string}{wstr: wstring} {equate} = {value} 221 | 222 | Criteria: 28 223 | Highlight: True 224 | BackColor: Green 225 | Find: { % | $[$] }{equate:"[a-z]+"} 226 | Replace: {equate} 227 | 228 | Criteria: 29 229 | Highlight: True 230 | BackColor: SandyBrown 231 | Find: {"&h"} 232 | Replace: 0x 233 | 234 | Criteria: 30 235 | Comment: Single-line IF 236 | Highlight: True 237 | BackColor: Green 238 | PassOnce: False 239 | Find: If {cond} Then {statement} [Else {else}]{nl} 240 | Replace: if ({cond}) {{statement}{nl}}{else: else {{else}{nl}}}{nl} 241 | 242 | Criteria: 31 243 | Comment: Multi-line IF 244 | Highlight: True 245 | PassOnce: False 246 | Find: If {cond} Then [{comment:" *'.*"}] {nl} 247 | Replace: if ({cond}) { {comment}{nl} 248 | 249 | Criteria: 32 250 | Find: {nl}Else 251 | Replace: {nl} } else { 252 | 253 | Criteria: 33 254 | Find: {nl}ElseIf {cond} Then 255 | Replace: {nl} } else if ({cond}) { 256 | 257 | Criteria: 34 258 | Highlight: True 259 | PassOnce: False 260 | Find: For {x} = {start} To {stop} [Step {inc=1}][{comment:" *'.*"}] 261 | Replace: for ({x}={start}; {x}{@Eval: IIF(sgn({inc})>0, '<', '>')}={stop}; {x} += {inc}) { {comment} 262 | 263 | Criteria: 35 264 | Highlight: True 265 | PassOnce: False 266 | Find: {nl}While {cond} [{comment:" *'.*"}] {nl} 267 | Replace: {nl}while ({cond}) { {comment} {nl} 268 | 269 | Criteria: 36 270 | Highlight: True 271 | PassOnce: False 272 | Find: Do { {while: While} | {until: Until} } {cond} [{comment:" *'.*"}]{nl} 273 | Replace: while ({while: {cond}}{until:!({cond})}) { {comment} 274 | 275 | Criteria: 37 276 | Find: { End { Sub|Function|If } | Wend | Next | Loop } 277 | Replace: } 278 | 279 | Criteria: 38 280 | Find: Do{nl} 281 | Replace: do { 282 | 283 | Criteria: 39 284 | Highlight: True 285 | PassOnce: False 286 | Find: Loop { {while: While} | {until: Until} } {cond} [{comment:" *'.*"}] 287 | Replace: } while ({while: {cond}}{until:!({cond})}) {comment} 288 | 289 | Criteria: 40 290 | Find: Select Case [As] [Long | Const | Const$] {expr} {nl} 291 | Replace: { auto CASE_VAR = {expr} 292 | {@Execute: Case1 = 1} 293 | 294 | Criteria: 41 295 | Find: Case [IS] {test%} [:] [' {comment:".*"}] 296 | Replace: {@Evaluate: 297 | IIf(Case1==1, Case1=0; "", "} else") 298 | } if (CASE_VAR == {test}) {{comment: // {comment}} 299 | 300 | Criteria: 42 301 | PassOnce: False 302 | Find: Case [IS] {item}, {more} 303 | Replace: Case {item} || CASE_VAR = {more} 304 | 305 | Criteria: 43 306 | Find: Case Else 307 | Replace: } else { 308 | 309 | Criteria: 44 310 | Find: End Select 311 | Replace: }} 312 | 313 | Criteria: 45 314 | Find: Type {name:1} 315 | Replace: struct {name} { 316 | 317 | Criteria: 46 318 | Find: Union {name:1} 319 | Replace: union {name} { 320 | 321 | Criteria: 47 322 | Find: End { Type | Union } 323 | Replace: }; 324 | 325 | Criteria: 48 326 | Highlight: True 327 | BackColor: Orange 328 | PassOnce: False 329 | Find: { Dim | {member: {nl}}} {var:1} As {type:1} [{ptr: Ptr}] 330 | Replace: {member: {nl}}{type} {ptr:*}{var}{@Eval: 331 | IIf("{member}{ptr}" == "", " = {type}()")}; 332 | 333 | Criteria: 49 334 | Highlight: True 335 | Find: {nl} {bitfield:1} As Bit * {size:1} [In {type%:1}] 336 | Replace: {nl}{@Eval: 337 | IIf("{type}" <> "", SetVar(BitType, "{type}")) 338 | BitType 339 | } {bitfield} : {size}; 340 | 341 | Criteria: 50 342 | Highlight: True 343 | PassOnce: False 344 | Find: Dim {array}([{size}]) As {type} 345 | Replace: std::vector<{type}> {array}{size: ({size}+1, {type}())};{@Define::Pass: 6 ~~ Syntax: {array}({sz}) ::= {array}[{sz}]}{@Define::Pass: 6 ~~ Syntax: {array}() ::= {array}} 346 | 347 | Criteria: 51 348 | Find: Erase {array:1}[()] 349 | Replace: {array}.clear(); 350 | 351 | Criteria: 52 352 | PassOnce: False 353 | Find: ReDim {array}({size}) [As {type}] [{more: , {etc}}] 354 | Replace: {array}.clear(); 355 | {array}.resize({size}+1); {more: {nl} ReDim {etc}} 356 | 357 | Criteria: 53 358 | PassOnce: False 359 | Find: ReDim Preserve {array}({size}) [As {type}] [{more: , {etc}}] 360 | Replace: {array}.resize({size}+1); {more: {nl} ReDim Preserve {etc}} 361 | 362 | Criteria: 54 363 | Find: UBound({array}) 364 | Replace: ({array}.size()-1) 365 | 366 | Criteria: 55 367 | Highlight: True 368 | BackColor: SandyBrown 369 | PassOnce: False 370 | Find: Dim {var1}, {more} 371 | Replace: Dim {var1} 372 | Dim {more} 373 | 374 | Criteria: 56 375 | Highlight: True 376 | BackColor: Gold 377 | PassOnce: False 378 | Find: { Local | Global | Register } 379 | Replace: Dim 380 | 381 | Criteria: 57 382 | Find: `{typevar}.@{last:1}` 383 | Replace: *`{typevar}.{last}` 384 | 385 | Criteria: 58 386 | Highlight: True 387 | BackColor: Silver 388 | Find: VarPtr({var}) 389 | Replace: &{var} 390 | 391 | Criteria: 59 392 | Find: Iterate 393 | Replace: continue 394 | 395 | Criteria: 60 396 | Find: Exit 397 | Replace: break 398 | 399 | Criteria: 61 400 | Highlight: True 401 | Find: Exit Sub 402 | Replace: return 403 | 404 | Criteria: 62 405 | Find: Exit Function 406 | Replace: return _ReturnValue 407 | 408 | Criteria: 63 409 | Highlight: True 410 | BackColor: DeepSkyBlue 411 | PassOnce: False 412 | Find: Function = 413 | Replace: _ReturnValue = 414 | 415 | Criteria: 64 416 | Highlight: True 417 | BackColor: Lime 418 | Find: Long 419 | Replace: int 420 | 421 | Criteria: 65 422 | Highlight: True 423 | BackColor: Red 424 | Find: Single 425 | Replace: float 426 | 427 | Criteria: 66 428 | Find: Double 429 | Replace: double 430 | 431 | Criteria: 67 432 | Highlight: True 433 | Find: Byte 434 | Replace: UCHAR 435 | 436 | Criteria: 68 437 | Highlight: True 438 | Find: Integer 439 | Replace: short 440 | 441 | Criteria: 69 442 | Highlight: True 443 | Find: Word 444 | Replace: USHORT 445 | 446 | Criteria: 70 447 | Highlight: True 448 | Find: Dword 449 | Replace: unsigned 450 | 451 | Criteria: 71 452 | Find: AsciiZ 453 | Replace: LPCSTR 454 | 455 | Criteria: 72 456 | Highlight: True 457 | Find: Quad 458 | Replace: __int64 459 | 460 | Criteria: 73 461 | SkipOver: True 462 | Find: EXTENDED 463 | Replace: [Skip over] 464 | 465 | Criteria: 74 466 | Highlight: True 467 | Find: { Extended | Ext } 468 | Replace: EXTENDED 469 | 470 | Criteria: 75 471 | Highlight: True 472 | BackColor: SlateBlue 473 | PassOnce: False 474 | Find: ByRef {arg} As {type:1} 475 | Replace: {type}& {arg} 476 | 477 | Criteria: 76 478 | PassOnce: False 479 | Find: ByRef {array}() As {type:1} 480 | Replace: std::vector<{type}>& {array}{@Define:: 481 | Syntax: {array}({index}) ::= {array}[{index}] 482 | Syntax: {array}() ::= {array} 483 | } 484 | 485 | Criteria: 77 486 | Highlight: True 487 | BackColor: Pink 488 | PassOnce: False 489 | Find: ByVal {arg} As {type:1} [{ptr: Ptr}] 490 | Replace: {type} {ptr:*}{arg} 491 | 492 | Criteria: 78 493 | Highlight: True 494 | Find: Macro {name} [{params: ({paramlist})}] = {replacement%} 495 | Replace: #define {name}{params} {replacement} 496 | 497 | Criteria: 79 498 | Highlight: True 499 | Find: #ElseIf 500 | Replace: #elif 501 | 502 | Criteria: 80 503 | Find: #{directive: If | Else | EndIf } 504 | Replace: #{@Eval: LCase("{directive}", "{'.*'}")} 505 | 506 | Criteria: 81 507 | Highlight: True 508 | PassOnce: False 509 | Find: [{NOT: Not }] %Def({const}) 510 | Replace: {NOT:!}defined {const} 511 | 512 | Criteria: 82 513 | PassOnce: False 514 | Find: Choose[&]({index}, {choice}) 515 | Replace: IIf({index}, {choice}, 0) 516 | 517 | Criteria: 83 518 | PassOnce: False 519 | Find: Choose$({index}, {choice}) 520 | Replace: IIf({index}, {choice}, "") 521 | 522 | Criteria: 84 523 | PassOnce: False 524 | Find: Choose[{type: $ | & }]({index}, {choice1}, {more}) 525 | Replace: IIf({index}, {choice1}, Choose{type}({index}, {more})) 526 | 527 | Criteria: 85 528 | Find: StdOut {text} { {sameline: ;} | {NewLine: } } 529 | Replace: cout << {text} {NewLine: << endl;} 530 | 531 | Criteria: 86 532 | Find: Sleep {milliseconds} 533 | Replace: PB_SLEEP({milliseconds}) 534 | 535 | Criteria: 87 536 | Find: {keyword:"CV(BYT|DWD|D|E|I|L|Q|S|WRD)"}({string} [, {offset=1}]) 537 | Replace: PB_{@Eval:UCase("{keyword}", "{'.*'}")}({string}, {offset}) 538 | 539 | Criteria: 88 540 | PassOnce: False 541 | Find: Line Input [{prompt: {q}{str}{q} | ${equate:1}}][,] {StrVariable:1} 542 | Replace: {prompt: cout << {prompt};}getline(cin, {StrVariable}); 543 | 544 | Criteria: 89 545 | Find: IIf[$]({cond%}, {this%}, {that%}) 546 | Replace: ({cond} ? {this} : {that}) 547 | 548 | Criteria: 90 549 | Find: PB_ASC({q}{char}{q}, {n:" *[0-9]+"}) 550 | Replace: '{@Eval:Mid("{char}", {n}, 1, ucChar)}' 551 | 552 | Criteria: 91 553 | Find: _char([{char= }]) 554 | Replace: '{char}' 555 | 556 | Criteria: 92 557 | Highlight: True 558 | Find: : 559 | Replace: ;{nl} 560 | 561 | Criteria: 93 562 | SkipOver: True 563 | Find: :: 564 | Replace: [Skip over] 565 | 566 | Criteria: 94 567 | Find: Swap {a}, {b} 568 | Replace: swap({a}, {b}) 569 | 570 | Criteria: 95 571 | Comment: Adds semi-colons to statements, etc 572 | Pass: 5 573 | 574 | Criteria: 96 575 | Find: {@Start} 576 | Replace: {@Define:: Token: [\x7b\x7d\;]} 577 | 578 | Criteria: 97 579 | Find: {nl} {code} [{comment:" *//.*"}] {delim-: {nl}} 580 | Replace: {nl}{code};{comment} 581 | 582 | Criteria: 98 583 | SkipOver: True 584 | Find: {nl} [{code}] { ; | "{" | "}" } [// {".*"}] {delim-: {nl}} 585 | Replace: [Skip over] 586 | 587 | Criteria: 99 588 | SkipOver: True 589 | Find: {nl} { # | // } [{".*"}] 590 | Replace: [Skip over] 591 | 592 | Criteria: 100 593 | Comment: Nested UDTs - 1st pass (gather members) 594 | Pass: 6 595 | 596 | Criteria: 101 597 | Find: {nl} struct {name} "{" {members+} "}"; 598 | Replace: {Self}{@Eval: Dim {name} As String = {Q}{members}{Q}} 599 | 600 | Criteria: 102 601 | Find: {nl} union {name} "{" {members+} "}"; 602 | Replace: {Self}{@Eval: Dim {name} As String = {Q}union{{members}};{Q}} 603 | 604 | Criteria: 103 605 | Comment: Nested UDTs - 2nd pass (insert members) 606 | Pass: 7 607 | 608 | Criteria: 104 609 | Find: {nl} { struct | union } 610 | Replace: {Self}{@Eval: UDT = True} 611 | 612 | Criteria: 105 613 | PassOnce: False 614 | Find: {nl}{nested:1}; {@If: UDT} 615 | Replace: {@Eval: {nested}} 616 | 617 | Criteria: 106 618 | SkipOver: True 619 | Find: {nl}{type:1} {member}; 620 | Replace: [Skip over] 621 | 622 | Criteria: 107 623 | Find: {nl} "}"; 624 | Replace: {Self}{@Eval: UDT = False} 625 | 626 | Criteria: 108 627 | Comment: Adds default values in function prototypes for optional parameters 628 | Pass: 8 629 | 630 | Criteria: 109 631 | PassOnce: False 632 | Find: Optional {type:1}[{ptr: *}]{arg:1} [{more: , [Optional] {etc}}] 633 | Replace: {type} {ptr}{arg} = {@Eval: 634 | IIf("{ptr}" <> "", "NULL", 635 | IIf(InStr("{type}", "{ float|double|EXTENDED }"), "0.0", 636 | IIf(InStr("{type}", "{ UCHAR|short|USHORT|int|unsigned }"), "0", 637 | Chr(34, 34)))) 638 | }{more: , Optional {etc}} 639 | 640 | Criteria: 110 641 | Find: Optional {@If: IsPrototype==0} 642 | Replace: {Nothing} 643 | 644 | Criteria: 111 645 | SkipOver: True 646 | Find: // {Comment:".*"} 647 | Replace: [Skip over] 648 | 649 | Criteria: 112 650 | Find: {nl}// End of prototypes 651 | Replace: {Self}{@Exec: IsPrototype = 0} 652 | 653 | Criteria: 113 654 | Comment: Misc 655 | Pass: 9 656 | 657 | Criteria: 114 658 | SkipOver: True 659 | Find: { // {comment:".*"} | /* {commentB~} */ } 660 | Replace: [Skip over] 661 | 662 | Criteria: 115 663 | Find: {" \xFF\xFF\n"} 664 | Replace: {nl} 665 | 666 | Criteria: 116 667 | Find: {" \xFF"}{comment:"[^\xFF]+"}{"\xFF\n"} 668 | Replace: /* {comment} */{nl} 669 | 670 | Criteria: 117 671 | Find: @ 672 | Replace: * 673 | 674 | Criteria: 118 675 | Highlight: True 676 | Find: @{pointer:1}. 677 | Replace: {pointer}-> 678 | 679 | Criteria: 119 680 | Find: `{@Comment: removes temp char for type member access} 681 | Replace: {Nothing} 682 | 683 | Criteria: 120 684 | Find: std::vector<{type}> {name:1} "["{size}"]" 685 | Replace: std::vector<{type}>{name}({size}) 686 | 687 | Criteria: 121 688 | Find: #IncludeStart {file}.inc 689 | {code+} 690 | #IncludeEnd {etc} 691 | Replace: // #Include "{file}.inc" 692 | 693 | # End Search 694 | -------------------------------------------------------------------------------- /convert/pbMisc.h: -------------------------------------------------------------------------------- 1 | // Miscellaneous 2 | 3 | #define EXTENDED double 4 | 5 | // PB string equates 6 | 7 | const string PB_NUL = "\x00"; 8 | const string PB_BEL = "\a"; 9 | const string PB_BS = "\b"; 10 | const string PB_TAB = "\t"; 11 | const string PB_LF = "\n"; 12 | const string PB_VT = "\v"; 13 | const string PB_FF = "\f"; 14 | const string PB_CR = "\r"; 15 | const string PB_CRLF = "\r\n"; 16 | const string PB_EOF = "\x1A"; 17 | const string PB_ESC = "\x1B"; 18 | const string PB_SPC = " "; 19 | const string PB_DQ = "\""; 20 | const string PB_SQ = "\'"; 21 | const string PB_QCQ = "\",\""; 22 | 23 | // Actual patterns that convert to the following are found in *.uc 24 | 25 | #define PB_CV(keyword, type) inline type keyword(const string& Str, int Offset=1) \ 26 | { type *ret; ret = (type*)(Str.data()+Offset-1); return *ret; } 27 | PB_CV(PB_CVBYT, unsigned char) 28 | PB_CV(PB_CVD, double) 29 | PB_CV(PB_CVDWD, unsigned int) 30 | PB_CV(PB_CVE, EXTENDED) 31 | PB_CV(PB_CVI, short) 32 | PB_CV(PB_CVL, int) 33 | PB_CV(PB_CVQ, long long) 34 | PB_CV(PB_CVS, float) 35 | PB_CV(PB_CVWRD, unsigned short) 36 | 37 | 38 | inline string PB_PEEK_STR(int address, int count) { return string((char *)address, count); } 39 | inline void PB_POKE_STR(int address, const string& data) { memmove((void *)address, data.c_str(), data.length()); } 40 | 41 | inline void PB_NAME(const string& oldname, const string& newname) { rename(oldname.c_str(), newname.c_str()); } 42 | 43 | inline int PB_LOF(fstream& file) { 44 | int size, current_loc; 45 | 46 | current_loc = file.tellg(); 47 | file.seekg(0, file.end); 48 | size = file.tellg(); 49 | file.seekg(0, current_loc); 50 | return size; 51 | } 52 | 53 | // Math 54 | 55 | #define PB_SGN(number) ((number > 0) ? 1 : ((number < 0) ? -1 : 0)) 56 | #define PB_EXP10(number) (10^(number)) 57 | 58 | inline bool PB_XOR(bool x, bool y) { return (x != y || x != y) ? true : false; } 59 | inline int PB_XOR(int x, int y) { return x ^ y | x ^ y; } 60 | inline bool PB_EQV(bool x, bool y) { return (x && y || !x && !y) ? true : false; } 61 | inline int PB_EQV(int x, int y) { return x & y | !x & !y; } 62 | inline bool PB_IMP(bool x, bool y) { return (x == true && y == false) ? false : true; } 63 | inline bool PB_IMP(int x, int y) { return PB_EQV(x, y) | y; } 64 | inline EXTENDED PB_FIX(EXTENDED n) {EXTENDED fix; modf(n, &fix); return fix;} 65 | inline EXTENDED PB_FRAC(EXTENDED n) {EXTENDED ignore; return modf(n, &ignore);} 66 | inline int _round(EXTENDED number) { return (number > 0.0) ? (number + 0.5) : (number - 0.5); } 67 | 68 | #define ARGCOUNT(x) x // ARGCOUNT simply makes the first arg of variadic function stand out 69 | #define GREATER > 70 | #define LESS < 71 | 72 | #define MAXMIN(func, type, compare_op) \ 73 | inline type func(int argCount, ...) { \ 74 | type max, value; \ 75 | va_list args; \ 76 | va_start(args, argCount); \ 77 | max = va_arg(args, type); \ 78 | for(int x = 2; x <= argCount; x++) if((value = va_arg(args, type)) compare_op max) max = value; \ 79 | va_end(args); \ 80 | return max; \ 81 | } 82 | 83 | MAXMIN(PB_MAX, EXTENDED, GREATER) 84 | MAXMIN(PB_MAX_INT, int, GREATER) 85 | MAXMIN(PB_MAX_STR, string, GREATER) 86 | MAXMIN(PB_MIN, EXTENDED, LESS) 87 | MAXMIN(PB_MIN_INT, int, LESS) 88 | MAXMIN(PB_MIN_STR, string, LESS) 89 | 90 | #define PZONE left << setw(14) 91 | 92 | // This template allows rvalues (any expression) where lvalues (a variable) are expected (in ByRef args) 93 | template inline T& lvalue(const T& Arg) { static T ReturnVal; ReturnVal = Arg; return ReturnVal; } 94 | -------------------------------------------------------------------------------- /convert/pbOS.h: -------------------------------------------------------------------------------- 1 | // This file is for handling operating system dependent code that might not be directly 2 | // portable using the same method. 3 | 4 | // The actual transforms that convert to this code are found in *.uc 5 | 6 | #include "windows.h" // For now everything is Windows-specific 7 | 8 | WIN32_FIND_DATA FindFileData; 9 | HANDLE DirHandle = INVALID_HANDLE_VALUE; 10 | 11 | inline string PB_DIR(const string& file) { 12 | DirHandle = FindFirstFile(file.c_str(), &FindFileData); 13 | return (DirHandle == INVALID_HANDLE_VALUE ? "" : FindFileData.cFileName); 14 | } 15 | 16 | inline string PB_DIR_NEXT() { 17 | FindNextFile(DirHandle, &FindFileData); 18 | return (DirHandle == INVALID_HANDLE_VALUE ? "" : FindFileData.cFileName); 19 | } 20 | 21 | inline BOOL PB_ISFILE(const string& FileName) { 22 | DWORD attr = GetFileAttributes(FileName.c_str()); 23 | return (attr != INVALID_FILE_ATTRIBUTES && !(attr & FILE_ATTRIBUTE_DIRECTORY)); 24 | } 25 | 26 | inline string PB_EXE_FULL() { TCHAR fName[MAX_PATH]; GetModuleFileName(NULL, fName, MAX_PATH); return fName; } 27 | #define PB_EXE_NAME PB_EXE_NAMEX.substr(0, PB_EXE_NAMEX.rfind(".")) 28 | #define PB_EXE_NAMEX PB_EXE_FULL().substr(PB_EXE_FULL().rfind("\\")+1) 29 | #define PB_EXE_PATH PB_EXE_FULL().substr(PB_EXE_FULL().rfind("\\")) 30 | #define PB_EXE_EXTN PB_EXE_FULL().substr(PB_EXE_FULL().rfind(".")) 31 | 32 | #define PB_SLEEP(milliseconds) Sleep(milliseconds) 33 | -------------------------------------------------------------------------------- /convert/pbkeywords.txt: -------------------------------------------------------------------------------- 1 | Abs 2 | Accel 3 | Accept 4 | Access 5 | ACode 6 | Add 7 | Addr 8 | Alias 9 | All 10 | And 11 | Any 12 | Append 13 | Arc 14 | Array 15 | ArrayAttr 16 | As 17 | Asc 18 | Ascend 19 | Asciiz 20 | Asciz 21 | Asm 22 | Assign 23 | AssignAccel 24 | At 25 | Atn 26 | Attach 27 | Attrib 28 | Bar 29 | Base 30 | Baud 31 | BDecl 32 | Beep 33 | Begin 34 | Bel 35 | Bgr 36 | Bin 37 | Binary 38 | Bit 39 | Bitmap 40 | Bits 41 | Black 42 | Bloat 43 | Blue 44 | Border 45 | Box 46 | Break 47 | Bs 48 | Button 49 | ByCmd 50 | ByCopy 51 | ByRef 52 | Byte 53 | ByVal 54 | Calc 55 | Call 56 | CallBack 57 | CallStk 58 | CallStkCount 59 | Cancel 60 | Case 61 | Catch 62 | CbCtl 63 | CbCtlMsg 64 | CbHndl 65 | CbLParam 66 | CbMsg 67 | CbWParam 68 | CByt 69 | CCur 70 | CCux 71 | CD 72 | CDbl 73 | CDecl 74 | CDwd 75 | Ceil 76 | Cext 77 | ChDir 78 | ChDrive 79 | Check 80 | Check3State 81 | CheckBox 82 | Choose 83 | Chr 84 | CInt 85 | Class 86 | CleanUp 87 | Clear 88 | Client 89 | CLng 90 | Close 91 | ClsId 92 | CodePtr 93 | Collate 94 | Color 95 | ComboBox 96 | Comm 97 | Command 98 | Compile 99 | Compiler 100 | Con 101 | Connect 102 | Const 103 | Constants 104 | Control 105 | Copy 106 | Cos 107 | CQud 108 | Cr 109 | Create 110 | Created 111 | CrLf 112 | CSet 113 | CSng 114 | CtsFlow 115 | Cur 116 | CurDir 117 | Currency 118 | CurrencyX 119 | Cux 120 | CvByt 121 | CvCur 122 | CvCux 123 | Cvd 124 | CvDwd 125 | Cve 126 | Cvi 127 | Cvl 128 | Cvq 129 | Cvs 130 | CvWrd 131 | CWrd 132 | Cyan 133 | Data 134 | DataCount 135 | Date 136 | DC 137 | Debug 138 | Declarations 139 | Declare 140 | Decr 141 | Def 142 | Default 143 | DefByt 144 | DefCur 145 | DefCux 146 | DefDbl 147 | DefDwd 148 | DefExt 149 | DefInt 150 | DefLng 151 | DefQud 152 | DefSng 153 | DefStr 154 | DefWrd 155 | Delete 156 | Descend 157 | Desktop 158 | Dialog 159 | Dim 160 | Dir 161 | Disable 162 | DiskFree 163 | DiskSize 164 | Dispatch 165 | DispParams 166 | Dll 167 | DllMain 168 | Do 169 | DoEvents 170 | Double 171 | Dq 172 | Draw 173 | DsrFlow 174 | DsrSens 175 | DtrFlow 176 | DtrLine 177 | Dword 178 | Ellipse 179 | Else 180 | ElseIf 181 | Empty 182 | Enable 183 | End 184 | EndIf 185 | Environ 186 | Eof 187 | Eqv 188 | Erase 189 | ErL 190 | Err 191 | Err_BadFileMode 192 | Err_BadFileName 193 | Err_BadFileNameOrNumber 194 | Err_BadRecordNumber 195 | Err_CommError 196 | Err_DeviceIoError 197 | Err_DeviceTimeout 198 | Err_DeviceUnavailable 199 | Err_DiskFull 200 | Err_DiskMediaError 201 | Err_DiskNotReady 202 | Err_DivisionByZero 203 | Err_FarHeapCorrupt 204 | Err_FileAlreadyExists 205 | Err_FileIsOpen 206 | Err_FileNotFound 207 | Err_GlobalMemoryCorrupt 208 | Err_IllegalFunctionCall 209 | Err_InputPastEnd 210 | Err_InternalError 211 | Err_NoError 212 | Err_ObjectError 213 | Err_OutOfMemory 214 | Err_Overflow 215 | Err_PathFileAccessError 216 | Err_PathNotFound 217 | Err_PermissionDenied 218 | Err_RenameAcrossDisks 219 | Err_StringSpaceCorrupt 220 | Err_SubscriptPointerOutOfRange 221 | Err_TooManyFiles 222 | ErrApi 223 | ErrClear 224 | Error 225 | Esc 226 | Exe 227 | Exit 228 | Exp 229 | Exp10 230 | Exp2 231 | Explicit 232 | Export 233 | Ext 234 | Extended 235 | Extract 236 | Ff 237 | Field 238 | FileAttr 239 | FileCopy 240 | FileName 241 | FileScan 242 | Fill 243 | Finally 244 | Fix 245 | Flow 246 | Flush 247 | Focus 248 | Font 249 | For 250 | Format 251 | FormFeed 252 | Frac 253 | Frame 254 | FreeFile 255 | From 256 | FuncName 257 | Function 258 | Get 259 | GetAttr 260 | Global 261 | GoSub 262 | GoTo 263 | Graphic 264 | Gray 265 | Green 266 | Guid 267 | GuidTxt 268 | Handle 269 | Handles 270 | Hex 271 | Hi 272 | HiByt 273 | HiInt 274 | HiWrd 275 | Host 276 | ICase 277 | Icon 278 | IDispatch 279 | Idn 280 | If 281 | IFace 282 | IIf 283 | Image 284 | ImageX 285 | ImgButton 286 | ImgButtonX 287 | Imp 288 | In 289 | Include 290 | Includes 291 | Incr 292 | InOut 293 | Inp 294 | Input 295 | InputBox 296 | Insert 297 | InStr 298 | Int 299 | Integer 300 | Interface 301 | Inv 302 | Is 303 | IsFalse 304 | IsNothing 305 | IsObject 306 | IsTrue 307 | Iterate 308 | IUnknown 309 | Join 310 | Kill 311 | LBound 312 | LCase 313 | Left 314 | Len 315 | Let 316 | Lf 317 | Lib 318 | LibMain 319 | Line 320 | Lines 321 | ListBox 322 | Lo 323 | Load 324 | LoByt 325 | Loc 326 | Local 327 | Lock 328 | Lof 329 | Log 330 | Log10 331 | Log2 332 | LoInt 333 | Long 334 | Loop 335 | LoWrd 336 | LPrint 337 | LSet 338 | LtGray 339 | LTrim 340 | Macro 341 | MacroTemp 342 | Magenta 343 | Main 344 | Mak 345 | MakDwd 346 | MakInt 347 | MakLng 348 | MakPtr 349 | MakWrd 350 | Margin 351 | Mat 352 | Max 353 | MCase 354 | Member 355 | Menu 356 | Mid 357 | Min 358 | Mix 359 | Mix_Blackness 360 | Mix_CopySrc 361 | Mix_MaskNotSrc 362 | Mix_MaskSrc 363 | Mix_MaskSrcNot 364 | Mix_MergeNotSrc 365 | Mix_MergeSrc 366 | Mix_MergeSrcNot 367 | Mix_Nop 368 | Mix_Not 369 | Mix_NotCopySrc 370 | Mix_NotMaskSrc 371 | Mix_NotMergeSrc 372 | Mix_NotXorSrc 373 | Mix_Whiteness 374 | Mix_XorSrc 375 | MkByt 376 | MkCur 377 | MkCux 378 | Mkd 379 | MkDir 380 | MkDwd 381 | Mke 382 | Mki 383 | Mkl 384 | Mkq 385 | Mks 386 | MkWrd 387 | Mod 388 | Modal 389 | Modeless 390 | MousePtr 391 | MsgBox 392 | Name 393 | New 394 | Next 395 | None 396 | Not 397 | Nothing 398 | Notify 399 | Nul 400 | Null 401 | ObjActive 402 | Object 403 | ObjPtr 404 | ObjResult 405 | Oct 406 | Of 407 | Off 408 | On 409 | Open 410 | Opt 411 | Option 412 | Optional 413 | Or 414 | Orientation 415 | Out 416 | Output 417 | Paint 418 | Parity 419 | ParityChar 420 | ParityRepl 421 | ParityType 422 | Parse 423 | ParseCount 424 | Pb_Cc32 425 | Pb_Dll16 426 | Pb_Dll32 427 | Pb_Exe 428 | Pb_Revision 429 | Pb_RevLetter 430 | Pb_Win32 431 | PBForms 432 | PBLibMain 433 | PBMain 434 | PBWin 435 | Peek 436 | Pie 437 | Pixel 438 | Pixels 439 | Pointer 440 | Poke 441 | Polygon 442 | Polyline 443 | PopUp 444 | Port 445 | Pos 446 | Post 447 | PPI 448 | Preserve 449 | Print 450 | Printer 451 | PrinterCount 452 | Private 453 | Profile 454 | ProgId 455 | Ptr 456 | Put 457 | Qcq 458 | Quad 459 | Quality 460 | Qword 461 | Random 462 | Randomize 463 | Read 464 | Records 465 | Recv 466 | Red 467 | ReDim 468 | ReDraw 469 | RegExpr 470 | Register 471 | RegRepl 472 | Rem 473 | Remain 474 | Remove 475 | Render 476 | Repeat 477 | Replace 478 | Reset 479 | Resource 480 | Resume 481 | Retain 482 | Return 483 | RGB 484 | Right 485 | Ring 486 | Rlsd 487 | RmDir 488 | Rnd 489 | Rotate 490 | Round 491 | RSet 492 | RTrim 493 | RtsFlow 494 | RxBuffer 495 | RxQue 496 | Save 497 | SBit 498 | Scale 499 | Scan 500 | ScrollBar 501 | SDecl 502 | Seek 503 | Select 504 | Send 505 | Server 506 | Set 507 | SetAttr 508 | SetEof 509 | Sgn 510 | Shared 511 | Shell 512 | Shift 513 | Show 514 | Signed 515 | Sin 516 | Single 517 | Size 518 | SizeOf 519 | Sleep 520 | Sort 521 | Space 522 | Spc 523 | Sqr 524 | Stack 525 | State 526 | Static 527 | Status 528 | StdCall 529 | StdOut 530 | Step 531 | Stop 532 | Str 533 | StrDelete 534 | Stretch 535 | String 536 | StrInsert 537 | StrPtr 538 | StrReverse 539 | Style 540 | Sub 541 | Suspend 542 | SW_Normal 543 | SW_ShowNormal 544 | Swap 545 | Switch 546 | Tab 547 | TagArray 548 | Tally 549 | Tan 550 | Tcp 551 | TextBox 552 | Then 553 | Thread 554 | ThreadCount 555 | Threaded 556 | ThreadID 557 | Time 558 | TimeOut 559 | Timer 560 | To 561 | Toggle 562 | Tools 563 | Trace 564 | Trim 565 | Trn 566 | Try 567 | TxBuffer 568 | TxQue 569 | Type 570 | UBound 571 | UCase 572 | UCode 573 | Udp 574 | Union 575 | Units 576 | UnLock 577 | Until 578 | User 579 | Using 580 | Val 581 | VarClass_Asc 582 | VarClass_Bit 583 | VarClass_Byt 584 | VarClass_Cur 585 | VarClass_Cux 586 | VarClass_Dbl 587 | VarClass_Dwd 588 | VarClass_Ext 589 | VarClass_Fix 590 | VarClass_Fld 591 | VarClass_Guid 592 | VarClass_IFac 593 | VarClass_Int 594 | VarClass_Lng 595 | VarClass_Qud 596 | VarClass_SBt 597 | VarClass_Sng 598 | VarClass_Str 599 | VarClass_Type 600 | VarClass_Vrnt 601 | VarClass_Wrd 602 | Variant 603 | VariantVT 604 | VarPtr 605 | Verify 606 | Version3 607 | Version4 608 | Version5 609 | Vt 610 | VT_Array 611 | VT_Blob 612 | VT_Blob_Object 613 | VT_Bool 614 | VT_BStr 615 | VT_ByRef 616 | VT_CArray 617 | VT_CF 618 | VT_ClsID 619 | VT_Cy 620 | VT_Date 621 | VT_Dispatch 622 | VT_Empty 623 | VT_Error 624 | VT_FileTime 625 | VT_HResult 626 | VT_I1 627 | VT_I2 628 | VT_I4 629 | VT_I8 630 | VT_Int 631 | VT_LPStr 632 | VT_LPWStr 633 | VT_Null 634 | VT_Ptr 635 | VT_R4 636 | VT_R8 637 | VT_Record 638 | VT_SafeArray 639 | VT_Storage 640 | VT_Stored_Object 641 | VT_Stream 642 | VT_Streamed_Object 643 | VT_UI1 644 | VT_UI2 645 | VT_UI4 646 | VT_UI8 647 | VT_UInt 648 | VT_Unknown 649 | VT_UserDefined 650 | VT_Variant 651 | VT_Vector 652 | VT_Void 653 | Wend 654 | While 655 | White 656 | Width 657 | Window 658 | WinMain 659 | With 660 | Word 661 | Write 662 | WString 663 | XInpFlow 664 | Xor 665 | XOutFlow 666 | XPrint 667 | Yellow 668 | Zer 669 | -------------------------------------------------------------------------------- /convert/pbstrings.h: -------------------------------------------------------------------------------- 1 | // PowerBASIC to C++ converter - Macros for PB strings 2 | // https://github.com/uCalc/powerbasic-to-cpp/tree/master/convert/pbstrings.h 3 | // Contributor(s): Daniel Corbier 4 | 5 | #define PB_DISCARD lvalue(int(0)) 6 | #define PB_DISCARD_STR lvalue(string("")) 7 | 8 | #define FULL_STRING string::npos 9 | 10 | #define PB_LEFT(MainStr, n) ( string(MainStr).substr(0, (n)) ) 11 | 12 | #define PB_RIGHT(MainStr, n) ( string(MainStr).substr(string(MainStr).length()-(n), (n)) ) 13 | 14 | #define PB_MID(MainStr, Start, Length) string(MainStr).substr(Start-1, Length) 15 | 16 | inline void PB_MID_REPLACE(string& MainStr, const string& Txt, int Start, int Length) { MainStr = MainStr.replace((Start)-1, Length, Txt); } 17 | 18 | #define PB_INSTR(n, MainStr, MatchStr) ((n) == 0 ? 0 : \ 19 | (n)>0 ? string(MainStr).find(MatchStr, (n)-1)+1 \ 20 | : string(MainStr).rfind(MatchStr, string(MainStr).length()+(n))+1) 21 | 22 | #define PB_INSTR_ANY(n, MainStr, MatchStr) ((n) == 0 ? 0 : \ 23 | (n)>0 ? string(MainStr).find_first_of(MatchStr, (n)-1)+1 \ 24 | : string(MainStr).find_last_of(MatchStr, string(MainStr).length()+(n))+1) 25 | 26 | inline string PB_UCASE(const string& Str) { std::transform(Str.begin(), Str.end(), Str.begin(), ::toupper); return Str; } 27 | 28 | inline string PB_LCASE(const string& Str) { std::transform(Str.begin(), Str.end(), Str.begin(), ::tolower); return Str; } 29 | 30 | // +++ For now only [L|R]Trim$ with one arg, or with with "ANY" for 2nd arg is impelemented 31 | 32 | #define PB_TRIM_ANY(Str, chars) PB_LTRIM_ANY(PB_RTRIM_ANY(Str, chars), chars) 33 | 34 | inline string PB_LTRIM_ANY(const string& Str, const string& chars) { return Str.substr(Str.find_first_not_of(chars)); } 35 | 36 | inline string PB_RTRIM_ANY(string Str, const string& chars) { Str.erase(Str.find_last_not_of(chars)+1); return Str; } 37 | 38 | inline string PB_EXTRACT(long start, const string& Str, const string& Match) { return Str.substr(0, Str.find(Match, start-1)-1); } 39 | 40 | inline string PB_EXTRACT_ANY(long start, const string& Str, const string& Match) { return Str.substr(0, Str.find_first_of(Match, start-1)-1); } 41 | 42 | inline string PB_REMAIN(long start, const string& Str, const string& Match) { return Str.substr(Str.find(Match, start-1)+Str.length()); } 43 | 44 | inline string PB_REMAIN_ANY(long start, const string& Str, const string& Match) { return Str.substr(Str.find_first_of(Match, start-1)+1); } 45 | 46 | inline void PB_REPLACE(string& Str, const string& Match, const string& NewStr) { 47 | int pos=1; int newpos=0; 48 | while (pos<=Str.length()) { newpos=PB_INSTR(pos, Str, Match)+NewStr.length(); PB_EXTRACT(pos, Str, Match) + NewStr + PB_REMAIN(pos, Str, Match); pos=newpos;} 49 | } 50 | 51 | inline void PB_REPLACE_ANY(string& Str, const string& Match, const string& NewStr) { for(int x=0; x < Match.length(); x++) replace(Str.begin(), Str.end(), Match[x], NewStr[x]); } 52 | 53 | inline string PB_REMOVE(const string& Str, const string& Match) { string Ret = Str; PB_REPLACE(Ret, Match, ""); return Ret; } 54 | 55 | inline string PB_REMOVE_ANY(const string& Str, const string& Match) { 56 | string Ret=Str; for(int x=0; x 0) 62 | Syntax: &{base:"[hbo]"} ::= #{base} 63 | Var: Equates As Table 64 | Var: MetaIF = True 65 | Var: NestedIF As Stack 66 | Var: IsInclude 67 | } 68 | {@Define:: Token: _.*\n ~~ Properties: ucWhiteSpace} 69 | 70 | Criteria: 2 71 | Comment: 72 | Pass: 1 73 | 74 | Criteria: 3 75 | PassOnce: False 76 | Find: {@Start} 77 | Replace: ' These equates may need to be adjusted manually 78 | ' depending on the compiler version used 79 | '%PB_REVISION = &H501 80 | '%PB_REVLETTER = &H20 81 | '%PB_EXE = -1 82 | '%PB_CC32 = -1 83 | %PB_DLL32 = 0 84 | '%PB_WIN32 = 0 85 | %USEMACROS = -1 86 | 87 | 88 | Criteria: 4 89 | BackColor: Purple 90 | Find: { [{nl}]{comment:"'.*"} | {"_[^\n]*\n"} } 91 | {@If: IsInclude} 92 | Replace: {Nothing} 93 | 94 | Criteria: 5 95 | PassOnce: False 96 | Find: {nl}#Include {q}{file}{q} 97 | Replace: #IncludeStart {file} 98 | {@Eval: FileText("{file}")} 99 | #IncludeEnd {file} 100 | {@Exec: IsInclude = True} 101 | 102 | Criteria: 6 103 | Find: {nl}#IncludeEnd 104 | Replace: {Self}{@Exec: IsInclude = False} 105 | 106 | Criteria: 7 107 | Comment: 108 | Pass: 2 109 | 110 | Criteria: 8 111 | BackColor: DarkKhaki 112 | Find: {nl}%{equate} = {value} [{"[?%&]+"}] ['] 113 | 114 | Replace: {Self}{@Exec: 115 | Dim {equate} = ~Eval(Replace(Replace({Q}{value}{Q}, "&", "#"), "{'_.*\n'}", "")) 116 | Insert(Equates, "{equate}") 117 | } 118 | 119 | Criteria: 9 120 | BackColor: Yellow 121 | Find: {nl}{line:".*"} {@If: MetaIF == False} 122 | Replace: {nl}'{line} 123 | 124 | Criteria: 10 125 | BackColor: Yellow 126 | Find: {nl}{" *#If"} {expr} 127 | Replace: {Self}{@Exec: 128 | Push(NestedIF, MetaIF) 129 | IIf({expr}, MetaIF=True, MetaIF=False) 130 | } 131 | 132 | Criteria: 11 133 | BackColor: Brown 134 | Find: {nl}{" *#Else"} 135 | Replace: {Self}{@Execute: MetaIF = -(MetaIF+1)} 136 | 137 | Criteria: 12 138 | BackColor: RoyalBlue 139 | Find: {nl}{" *#ElseIf"} {expr} 140 | Replace: {Self}{@Exec: 141 | IIf(MetaIF==False And {expr}, MetaIF=True, MetaIF=False) 142 | } 143 | 144 | Criteria: 13 145 | Find: {nl}{" *#EndIf"} 146 | Replace: {Self}{@Execute: MetaIF = PopNum(NestedIF)} 147 | 148 | Criteria: 14 149 | Find: 150 | Replace: 151 | 152 | # End Search 153 | -------------------------------------------------------------------------------- /convert/print.uc: -------------------------------------------------------------------------------- 1 | # print.uc - uCalc Transformation file 2 | # This file was saved with uCalc Transform 2.95 on 4/11/2014 3:00:18 PM 3 | # Comment: 4 | 5 | ExternalKeywords: Exclude, Comment, Selected, ParentChild, FindMode, InputFile, OutputFile, BatchAction, SEND 6 | ExternalKeywords: Highlight, ForeColor, BackColor, FontName, FontSize, FontStyle 7 | ExternalKeywords: FilterEndText, FilterSeparator, FilterSort, FilterSortFunc, FilterStartText, FilterUnique, FilterTally 8 | 9 | FindMode: Replace 10 | 11 | # Definitions 12 | 13 | 14 | # Search Criteria 15 | 16 | Criteria: 0 17 | Enabled: True 18 | Exclude: False 19 | Comment: 20 | Selected: False 21 | Highlight: False 22 | ForeColor: ControlText 23 | BackColor: Aqua 24 | FontName: 25 | FontSize: 26 | FontStyle: 27 | CaseSensitive: False 28 | QuoteSensitive: True 29 | CodeBlockSensitive: True 30 | FilterEndText: 31 | FilterSeparator: {#10} 32 | FilterSort: False 33 | FilterSortFunc: 34 | FilterStartText: 35 | FilterUnique: False 36 | FilterTally: False 37 | Min: 0 38 | Max: -1 39 | MinSoft: 0 40 | MaxSoft: -1 41 | BatchAction: Transform 42 | InputFile: 43 | OutputFile: 44 | SEND: 45 | StartAfter: 0 46 | StopAfter: -1 47 | SkipOver: False 48 | ParentChild: 0 49 | Pass: 0 50 | PassOnce: True 51 | Precedence: 0 52 | RightToLeft: False 53 | 54 | Criteria: 1 55 | Highlight: True 56 | BackColor: Yellow 57 | PassOnce: False 58 | Find: 59 | Replace: {@Token:: : ~~ Properties: ucStatementSep } 60 | {@Token:: [\x27_].* ~~ Properties: ucWhiteSpace} 61 | 62 | Criteria: 2 63 | Comment: 64 | Pass: 1 65 | 66 | Criteria: 3 67 | BackColor: Purple 68 | Find: Print 69 | Replace: cout << 70 | 71 | Criteria: 4 72 | PassOnce: False 73 | Find: Print , 74 | Replace: Print "", 75 | 76 | Criteria: 5 77 | BackColor: Green 78 | PassOnce: False 79 | Find: Print {etc},, 80 | Replace: Print {etc}, "", 81 | 82 | Criteria: 6 83 | Comment: Add ENDL to lines that need it 84 | Pass: 2 85 | 86 | Criteria: 7 87 | Selected: True 88 | Highlight: True 89 | BackColor: DarkKhaki 90 | Find: cout << [{data}] 91 | Replace: cout << {data} << endl; 92 | 93 | Criteria: 8 94 | Highlight: True 95 | BackColor: DeepSkyBlue 96 | Find: cout << [{data}] {punc: ; | , }{end: {nl} | : } 97 | Replace: cout << {data} {punc}{end} 98 | 99 | Criteria: 9 100 | Comment: 101 | Pass: 3 102 | 103 | Criteria: 10 104 | Highlight: True 105 | BackColor: Lime 106 | PassOnce: False 107 | Find: cout << {data}, [{more}] 108 | Replace: cout << PZONE << {data}{more: : cout << {more}} 109 | 110 | Criteria: 11 111 | BackColor: SlateBlue 112 | PassOnce: False 113 | Find: cout << {data}; [{more}] 114 | Replace: cout << {data}{more: : cout << {more}} 115 | 116 | Criteria: 12 117 | Comment: Clean up 118 | Pass: 4 119 | 120 | Criteria: 13 121 | Highlight: True 122 | BackColor: RoyalBlue 123 | PassOnce: False 124 | Find: << << 125 | Replace: << 126 | 127 | Criteria: 14 128 | BackColor: SlateBlue 129 | PassOnce: False 130 | Find: cout << {data} : cout << 131 | Replace: cout << {data} << 132 | 133 | # End Search 134 | -------------------------------------------------------------------------------- /convert/refactor.uc: -------------------------------------------------------------------------------- 1 | # refactor.uc - uCalc Transformation file 2 | # This file was saved with uCalc Transform 2.98 on 7/8/2014 5:08:53 PM 3 | # Comment: This rewrites code in more proper PB form 4 | 5 | ExternalKeywords: Exclude, Comment, Selected, ParentChild, FindMode, InputFile, OutputFile, BatchAction, SEND 6 | ExternalKeywords: Highlight, ForeColor, BackColor, FontName, FontSize, FontStyle 7 | ExternalKeywords: FilterEndText, FilterSeparator, FilterSort, FilterSortFunc, FilterStartText, FilterUnique, FilterTally 8 | 9 | # Definitions 10 | 11 | 12 | # Search Criteria 13 | 14 | Criteria: 0 15 | Enabled: True 16 | Exclude: False 17 | Comment: This rewrites code in more proper PB form 18 | Selected: False 19 | Highlight: False 20 | ForeColor: ControlText 21 | BackColor: Aqua 22 | FontName: 23 | FontSize: 24 | FontStyle: 25 | CaseSensitive: False 26 | QuoteSensitive: True 27 | CodeBlockSensitive: True 28 | FilterEndText: 29 | FilterSeparator: {#10} 30 | FilterSort: False 31 | FilterSortFunc: 32 | FilterStartText: 33 | FilterUnique: False 34 | FilterTally: False 35 | Min: 0 36 | Max: -1 37 | MinSoft: 0 38 | MaxSoft: -1 39 | BatchAction: Transform 40 | InputFile: 41 | OutputFile: 42 | SEND: 43 | StartAfter: 0 44 | StopAfter: -1 45 | SkipOver: False 46 | ParentChild: 0 47 | Pass: 0 48 | PassOnce: True 49 | Precedence: 0 50 | RightToLeft: False 51 | 52 | Criteria: 1 53 | BackColor: Khaki 54 | Find: 55 | Replace: {@Define: Var: Args As String} 56 | 57 | Criteria: 2 58 | Comment: Defines comments as whitespace and adds missing quotes 59 | Pass: 1 60 | 61 | Criteria: 3 62 | Find: {@Start} 63 | Replace: {@Define:: 64 | Token: _.*\n ~~ Properties: ucWhiteSpace 65 | Token: \x27.* ~~ Properties: ucWhiteSpace 66 | Token: : ~~ Properties: ucStatementSep 67 | }{nl} 68 | 69 | Criteria: 4 70 | Comment: Adds closing quote for quoted text with missing closing quote 71 | BackColor: DarkKhaki 72 | Find: {QuotedText:"\q[^\q\n]*"}{nl} 73 | Replace: {QuotedText}"{nl} 74 | 75 | Criteria: 5 76 | Comment: Uniform syntax for optional args 77 | Pass: 2 78 | 79 | Criteria: 6 80 | Find: Opt 81 | Replace: Optional 82 | 83 | Criteria: 7 84 | BackColor: Lime 85 | Find: "[", {arg} "]" 86 | Replace: Optional {arg} 87 | 88 | Criteria: 8 89 | Comment: Misc 90 | Pass: 3 91 | 92 | Criteria: 9 93 | Selected: True 94 | Find: [Declare]{ Function|Sub } {name} [Lib {lib}] [Alias {alias}] () 95 | Replace: {@Define:: 96 | {@Eval: "PassOnce ~~ Syntax: {name} ::= {name}()"} 97 | {@Eval: "SkipOver ~~ Syntax: {name} ()"} 98 | }{Self} 99 | 100 | Criteria: 10 101 | Comment: Adds parenthesis around args in function/sub calls that do not have it 102 | BackColor: Lime 103 | Find: [Declare]{ Function|Sub } {name} [Lib {lib}] [Alias {alias}] ({args}) 104 | Replace: {@Evaluate: 105 | Args = Remove({args}, "{ Optional|ByVal|ByRef|As {type:1} [Ptr] | {' *_.*\n *'} | {'[#!@$%&]+'} | () }") 106 | Args = SetSyntaxParams(Args, Args) 107 | }{@Define:: 108 | {@Eval: "PassOnce ~~ Syntax: {name} "+Args+" ::= {name}("+Args+")"} 109 | {@Eval: "SkipOver ~~ Syntax: {name} ({etc})"} 110 | }{Self} 111 | 112 | Criteria: 11 113 | Comment: Adds () As Long to PBMain if missing 114 | Find: Function PBMain [()] [As Long] 115 | Replace: Function PBMain() As Long 116 | 117 | Criteria: 12 118 | PassOnce: False 119 | Find: {dim: Local|Global|Static} 120 | [{etc},] {item:1}[{array1: ()}], {last:1}[{array2: ()}] As {type} 121 | Replace: {dim} {etc: {etc},} {item}{array1} As {type} 122 | {dim} {last}{array2} As {type} 123 | 124 | Criteria: 13 125 | Find: Call {function} [To {var:1}] 126 | Replace: {var: {var} = }{function} 127 | 128 | # End Search 129 | -------------------------------------------------------------------------------- /convert/stdafx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, but 3 | // are changed infrequently 4 | 5 | #pragma once 6 | 7 | #include "targetver.h" 8 | 9 | #include 10 | #include 11 | 12 | // TODO: reference additional headers your program requires here 13 | //#include 14 | #include // Use this for Intel C++, or otherwise 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | // Intel's mathimf.h does not have overload issue that with VC++ has for things like pow() 28 | -------------------------------------------------------------------------------- /convert/strings.uc: -------------------------------------------------------------------------------- 1 | # strings.uc - uCalc Transformation file 2 | # This file was saved with uCalc Transform 2.98 on 7/21/2014 7:25:20 PM 3 | # Comment: Converts string-related code from PowerBASIC to C++ 4 | 5 | ExternalKeywords: Exclude, Comment, Selected, ParentChild, FindMode, InputFile, OutputFile, BatchAction, SEND 6 | ExternalKeywords: Highlight, ForeColor, BackColor, FontName, FontSize, FontStyle 7 | ExternalKeywords: FilterEndText, FilterSeparator, FilterSort, FilterSortFunc, FilterStartText, FilterUnique, FilterTally 8 | 9 | # Definitions 10 | 11 | 12 | # Search Criteria 13 | 14 | Criteria: 0 15 | Enabled: True 16 | Exclude: False 17 | Comment: Converts string-related code from PowerBASIC to C++ 18 | Selected: False 19 | Highlight: True 20 | ForeColor: ControlText 21 | BackColor: Aqua 22 | FontName: 23 | FontSize: 24 | FontStyle: 25 | CaseSensitive: False 26 | QuoteSensitive: True 27 | CodeBlockSensitive: True 28 | FilterEndText: 29 | FilterSeparator: {#10} 30 | FilterSort: False 31 | FilterSortFunc: 32 | FilterStartText: 33 | FilterUnique: False 34 | FilterTally: False 35 | Min: 0 36 | Max: -1 37 | MinSoft: 0 38 | MaxSoft: -1 39 | BatchAction: Transform 40 | InputFile: 41 | OutputFile: 42 | SEND: 43 | StartAfter: 0 44 | StopAfter: -1 45 | SkipOver: False 46 | ParentChild: 0 47 | Pass: 0 48 | PassOnce: True 49 | Precedence: 0 50 | RightToLeft: False 51 | 52 | Criteria: 1 53 | Find: 54 | Replace: {@Token:: : ~~ Properties: ucStatementSep } 55 | 56 | Criteria: 2 57 | Comment: 58 | Pass: 1 59 | 60 | Criteria: 3 61 | SkipOver: True 62 | Find: ' {Comment:".*"} 63 | Replace: [Skip over] 64 | 65 | Criteria: 4 66 | Find: String 67 | Replace: string 68 | 69 | Criteria: 5 70 | Find: WString 71 | Replace: wstring 72 | 73 | Criteria: 6 74 | BackColor: DodgerBlue 75 | PassOnce: False 76 | Find: InStr([{n=1},] {MainStr}, {MatchStr}) 77 | Replace: PB_INSTR({n}, {MainStr}, {MatchStr}) 78 | 79 | Criteria: 7 80 | BackColor: Tomato 81 | PassOnce: False 82 | Find: InStr([{n=1},] {MainStr}, Any {MatchStr}) 83 | Replace: PB_INSTR_ANY({n}, {MainStr}, {MatchStr}) 84 | 85 | Criteria: 8 86 | BackColor: Red 87 | PassOnce: False 88 | Find: Left$({Str}, {n}) 89 | Replace: PB_LEFT({Str}, {n}) 90 | 91 | Criteria: 9 92 | BackColor: Brown 93 | PassOnce: False 94 | Find: Right$({Str}, {n}) 95 | Replace: PB_RIGHT({Str}, {n}) 96 | 97 | Criteria: 10 98 | BackColor: Orange 99 | PassOnce: False 100 | Find: Mid$({Str}, {Start} [, {Length=FULL_STRING}]) 101 | Replace: PB_MID({Str}, {Start}, {Length}) 102 | 103 | Criteria: 11 104 | BackColor: DeepSkyBlue 105 | PassOnce: False 106 | Find: {Sep: {nl} | : | Then | Else } 107 | Mid$({Str}, {Start} [, {Length=FULL_STRING}]) = {Txt%} 108 | Replace: {Sep} PB_MID_REPLACE({Str}, {Txt}, {Start}, {Length}) 109 | 110 | Criteria: 12 111 | BackColor: RoyalBlue 112 | PassOnce: False 113 | Find: Val({Str}) 114 | Replace: stold({Str}) 115 | 116 | Criteria: 13 117 | Find: Space$({count}) 118 | Replace: string({count}, _char( )) 119 | 120 | Criteria: 14 121 | Find: String$({count}, {char}) 122 | Replace: string({count}, {char}) 123 | 124 | Criteria: 15 125 | BackColor: Violet 126 | Find: String$({count}, {q}{char}{q}) 127 | Replace: string({count}, _char({char})) 128 | 129 | Criteria: 16 130 | Find: {function: UCase | LCase | Hex | Oct | Str}$({arg}) 131 | Replace: PB_{@Eval: UCase("{function}", "{'.*'}")}({arg}) 132 | 133 | Criteria: 17 134 | Find: Trim$({Str} [, ANY {chars=" "}]) 135 | Replace: PB_TRIM_ANY({Str}, {chars}) 136 | 137 | Criteria: 18 138 | BackColor: Gold 139 | Find: LTrim$({Str} [, ANY {chars=" "}]) 140 | Replace: PB_LTRIM_ANY({Str}, {chars}) 141 | 142 | Criteria: 19 143 | BackColor: Silver 144 | Find: RTrim$({Str} [, ANY {chars=" "}]) 145 | Replace: PB_RTRIM_ANY({Str}, {chars}) 146 | 147 | Criteria: 20 148 | Find: Extract$([{start=1},] {MainStr}, {MatchStr}) 149 | Replace: PB_EXTRACT({start}, {MainStr}, {MatchStr}) 150 | 151 | Criteria: 21 152 | Find: Extract$([{start=1},] {MainStr}, Any {MatchStr}) 153 | Replace: PB_EXTRACT_ANY({start}, {MainStr}, {MatchStr}) 154 | 155 | Criteria: 22 156 | Find: Remain$([{start=1},] {MainStr}, {MatchStr}) 157 | Replace: PB_REMAIN({start}, {MainStr}, {MatchStr}) 158 | 159 | Criteria: 23 160 | Find: Remain$([{start=1},] {MainStr}, Any {MatchStr}) 161 | Replace: PB_REMAIN_ANY({start}, {MainStr}, {MatchStr}) 162 | 163 | Criteria: 24 164 | Find: Remove$({Str}, {MatchStr}) 165 | Replace: PB_REMOVE({Str}, {MatchStr}) 166 | 167 | Criteria: 25 168 | Find: Remove$({Str}, Any {MatchStr}) 169 | Replace: PB_REMOVE_ANY({Str}, {MatchStr}) 170 | 171 | Criteria: 26 172 | Find: Replace {MatchStr} With {NewStr} In {MainStr} 173 | Replace: PB_REPLACE({MainStr}, {MatchStr}, {NewStr}) 174 | 175 | Criteria: 27 176 | Find: Replace Any {MatchStr} With {NewStr} In {MainStr} 177 | Replace: PB_REPLACE_ANY({MainStr}, {MatchStr}, {NewStr}) 178 | 179 | Criteria: 28 180 | Find: Repeat$({count}, {Str}) 181 | Replace: PB_REPEAT({Str}, {count}) 182 | 183 | Criteria: 29 184 | Find: Asc({Str}[, {pos=1}]) 185 | Replace: PB_ASC({Str}, {pos}) 186 | 187 | Criteria: 30 188 | Find: ${equate: NUL|BEL|BS|TAB|LF|VT|FF|CR|CRLF|EOF|ESC|SPC|DQ|SQ|QCQ } 189 | Replace: PB_{@Eval: UCase("{equate}", "{'.*'}")} 190 | 191 | Criteria: 31 192 | Find: Peek$({args}) 193 | Replace: PB_PEEK_STR((DWord){args}) 194 | 195 | Criteria: 32 196 | Find: Poke$ {address}, {stringexpr} 197 | Replace: PB_POKE_STR((DWord){address}, {stringexpr}) 198 | 199 | Criteria: 33 200 | Find: RegExpr {mask} In {main} [At {start=1}] To {iPos} [, {iLen=PB_DISCARD}] 201 | Replace: PB_REGEXPR({mask}, {main}, {start}, {iPos}, {iLen}) 202 | 203 | Criteria: 34 204 | Find: RegRepl {mask} In {main} With {repl} [At {start=1}] To {ipos}, {newmain} 205 | Replace: PB_REGREPL({start}, {mask}, {main}, {repl}, {ipos}, {newmain}) 206 | 207 | Criteria: 35 208 | Find: Retain$({main}, {match}) 209 | Replace: PB_RETAIN({main}, {match}) 210 | 211 | Criteria: 36 212 | Find: Retain$({main}, Any {match}) 213 | Replace: PB_RETAIN_ANY({main}, {match}) 214 | 215 | Criteria: 37 216 | Find: StrReverse$({main}) 217 | Replace: PB_STRREVERSE({main}) 218 | 219 | Criteria: 38 220 | Find: Verify([{start=1}, ] {main}, {match}) 221 | Replace: PB_VERIFY({start}, {main}, {match}) 222 | 223 | Criteria: 39 224 | Selected: True 225 | Find: Tab$({StrToTab}, {TabStop}) 226 | Replace: PB_TAB({StrToTab}, {TabStop}) 227 | 228 | Criteria: 40 229 | Comment: Doubles backslash to avoid escape 230 | Pass: 2 231 | 232 | Criteria: 41 233 | Find: {q}{text$}{q} 234 | Replace: {q}{@Evaluate: Replace({text}, "\", "\\")}{q} 235 | 236 | # End Search 237 | -------------------------------------------------------------------------------- /convert/typespecifiers.uc: -------------------------------------------------------------------------------- 1 | # typespecifiers.uc - uCalc Transformation file 2 | # This file was saved with uCalc Transform 2.96 on 5/14/2014 11:27:28 AM 3 | # Comment: Replaces data type specifiers with explicit type names 4 | 5 | ExternalKeywords: Exclude, Comment, Selected, ParentChild, FindMode, InputFile, OutputFile, BatchAction, SEND 6 | ExternalKeywords: Highlight, ForeColor, BackColor, FontName, FontSize, FontStyle 7 | ExternalKeywords: FilterEndText, FilterSeparator, FilterSort, FilterSortFunc, FilterStartText, FilterUnique, FilterTally 8 | 9 | FindMode: Replace 10 | 11 | # Definitions 12 | 13 | 14 | # Search Criteria 15 | 16 | Criteria: 0 17 | Enabled: True 18 | Exclude: False 19 | Comment: Replaces data type specifiers with explicit type names 20 | Selected: False 21 | Highlight: False 22 | ForeColor: ControlText 23 | BackColor: Aqua 24 | FontName: 25 | FontSize: 26 | FontStyle: 27 | CaseSensitive: False 28 | QuoteSensitive: True 29 | CodeBlockSensitive: True 30 | FilterEndText: 31 | FilterSeparator: {#10} 32 | FilterSort: False 33 | FilterSortFunc: 34 | FilterStartText: 35 | FilterUnique: False 36 | FilterTally: False 37 | Min: 0 38 | Max: -1 39 | MinSoft: 0 40 | MaxSoft: -1 41 | BatchAction: Transform 42 | InputFile: 43 | OutputFile: 44 | SEND: 45 | StartAfter: 0 46 | StopAfter: -1 47 | SkipOver: False 48 | ParentChild: 0 49 | Pass: 0 50 | PassOnce: True 51 | Precedence: 0 52 | RightToLeft: False 53 | 54 | Criteria: 1 55 | Find: {@Note: 56 | This transform does the following: 57 | 58 | * Adds explicit ByRef to args w/o ByVal or ByRef 59 | * Changes type specifiers to type names in param 60 | definitions and removes them elsewhere 61 | * Adds data type name to params that have neither 62 | an explicit type name or specifier, based on 63 | DefType definitions 64 | 65 | The section to the immediate right defines the 66 | required tables and an array to accomplish this. 67 | 68 | Bug: LCase() and UCase() are re-defined on the right 69 | due to a problem affecting pre-existing LCase/UCase. 70 | That is a temp solution. 71 | } 72 | Replace: {@Define: 73 | LineContinue: " _" 74 | Var: DefTypeInitial(255) As String 75 | Var: Specifier As Table = _ 76 | {"%", "Integer", "&", "Long", "&&", "Quad", _ 77 | "?", "Byte", "??", "Word", "???", "DWORD", _ 78 | "!", "Single", "#", "double", "##", "Extended", _ 79 | "@", "Currency", "@@", "CurrencyX", _ 80 | "$", "string", "$$", "wstring"} 81 | Var: DefType As Table = _ 82 | {"INT", "Integer", "LNG", "Long", "QUD", "Quad", _ 83 | "BYT", "Byte", "WRD", "Word", "DWD", "Dword", _ 84 | "SNG", "Single", "DBL", "Double", "EXT", "Extended", _ 85 | "CUR", "Currency", "CUX", "CurrencyX", "STR", "String"} 86 | Var: dType="(INT|LNG|QUD|BYT|WRD|DWD|SNG|DBL|EXT|CUR|CUX|STR)\b" 87 | Func: Round(x) = Sgn(x)*Int(Abs(x)+0.5) 88 | }{@Define:: Token: \x27.* ~~ Properties: ucWhitespace} 89 | 90 | Criteria: 2 91 | Comment: Handles DefType declarations; also inserts marker for easier parsing 92 | Pass: 1 93 | 94 | Criteria: 3 95 | Comment: Stores the DefType statement associated with character initials 96 | BackColor: Purple 97 | Find: {"Def"}{type:"{@Eval: dType}"} {char} {nl} 98 | Replace: {@Evaluate: 99 | SetVar(DefTypeInitial(Asc(LCase({char}))), ReadStr(DefType, {type})) 100 | SetVar(DefTypeInitial(Asc(UCase({char}))), ReadStr(DefType, {type})) 101 | } 102 | 103 | Criteria: 4 104 | Comment: Changes a DefType range into multiple DefType statements 105 | BackColor: SlateBlue 106 | PassOnce: False 107 | Find: {"Def"}{type:"{@Eval: dType}"} {from}-{to} {nl} 108 | Replace: {@Eval: Range(Asc("{from}"), Asc("{to}"), "'Def{type} '+Chr(x)+Chr(10)")} 109 | 110 | Criteria: 5 111 | Comment: Break DefType statements containing commas into multiple DefStype statements (one per line) 112 | BackColor: Pink 113 | PassOnce: False 114 | Find: {"Def"}{type:"{@Eval: dType}"} {etc}, {more} {nl} 115 | Replace: Def{type} {etc} 116 | Def{type} {more} 117 | 118 | Criteria: 6 119 | Comment: Inserts marker for easier parsing 120 | BackColor: Red 121 | Find: {nl} [ {d: Declare} ] {decl: Sub | Function } {etc} ({args}) 122 | Replace: {nl}{d} {decl} {etc}({@Evaluate: Replace({args}, ",", ", ")}) 123 | 124 | Criteria: 7 125 | SkipOver: True 126 | Find: {nl}Function = 127 | Replace: [Skip over] 128 | 129 | Criteria: 8 130 | Comment: Inserts ByRef to params that have neither ByRef nor ByVal 131 | Pass: 2 132 | 133 | Criteria: 9 134 | Comment: Inserts ByRef in front of params that do not explicitlly have ByVal or ByRef 135 | BackColor: SandyBrown 136 | Find: [{optional: Optional}] {name:1} 137 | Replace: {optional} ByRef {name} 138 | 139 | Criteria: 10 140 | Comment: Skips params that already have ByVal or ByRef 141 | BackColor: Green 142 | SkipOver: True 143 | Find: [Optional] { ByVal | ByRef } 144 | Replace: [Skip over] 145 | 146 | Criteria: 11 147 | Comment: Adds explicit data types to arg or variable declarations (functions also) 148 | Pass: 3 149 | 150 | Criteria: 12 151 | BackColor: RoyalBlue 152 | Find: [Optional] {by: ByVal | ByRef } {name:1} 153 | Replace: {by} {name} As {@Evaluate: DefTypeInitial(Asc({name}))} 154 | 155 | Criteria: 13 156 | Find: [Optional] {by: ByVal | ByRef } {name:1}{spec:"[!?@#$%&]+"} 157 | Replace: {by} {name} As {@Evaluate: ReadStr(Specifier, {spec})} 158 | 159 | Criteria: 14 160 | SkipOver: True 161 | Find: [Optional] {by: ByVal | ByRef } {name:1}[()] As 162 | Replace: [Skip over] 163 | 164 | Criteria: 15 165 | Find: Dim {var:1}{comment:" *'.*"}{nl} 166 | Replace: Dim {var} As {@Evaluate: DefTypeInitial(Asc({var}))}{comment}{nl} 167 | 168 | Criteria: 16 169 | BackColor: Tomato 170 | PassOnce: False 171 | Find: {decl: Dim|Global|Local|Static|Register}{etc}{spec:"[!?@#$%&]+"} 172 | Replace: {decl} {etc} As {@Evaluate: ReadStr(Specifier, {spec})} 173 | 174 | Criteria: 17 175 | Comment: Adds the appropriate type for functions with no explicit type or specifier 176 | BackColor: CornflowerBlue 177 | Find: {nl} [{decl: Declare}] Function {name:1} ([{args%}]) 178 | Replace: {nl}{decl} Function {name}({args}) As {@Evaluate: DefTypeInitial(Asc({name}))} 179 | 180 | Criteria: 18 181 | Comment: Changes function type specifier to data type name 182 | Find: {nl} [{decl: Declare}] Function {name:1}{spec:"[!?@#$%&]+"} ([{args%}]) 183 | Replace: {nl}{decl} Function {name}({args}) As {@Evaluate: ReadStr(Specifier, {spec})} 184 | 185 | Criteria: 19 186 | Comment: Skips functions that already have an explicit type 187 | Selected: True 188 | BackColor: Gold 189 | Find: {nl} [{decl: Declare}] Function {name:1} ([{args%}]) As {type} 190 | Replace: {nl}{decl} Function {name}({args}) As {type} 191 | 192 | Criteria: 20 193 | Find: As {type:1}([{arraysize}]) 194 | Replace: ({arraysize}) As {type} 195 | 196 | Criteria: 21 197 | Comment: Cleans up; removes marker; as well as type specifiers 198 | Pass: 4 199 | 200 | Criteria: 22 201 | Comment: Removes that was inserted in earlier pass 202 | BackColor: SandyBrown 203 | Find: 204 | Replace: {Nothing} 205 | 206 | Criteria: 23 207 | Comment: Removes statement specifiers 208 | BackColor: Violet 209 | Find: {variable:"[a-z][a-z0-9_]*"}{spec:"[!?@#$%&]+"} 210 | Replace: {variable} 211 | 212 | Criteria: 24 213 | SkipOver: True 214 | Find: {@Eval: "{'"+Retain(FileText("PBKeywords.txt"), "{keyword:'.*'}", Delim("\b|"))+"\b'}"} 215 | Replace: [Skip over] 216 | 217 | Criteria: 25 218 | Find: {num:"([0-9]*\.)?[0-9]+(e[-+]?[0-9]+)?"} 219 | { {single: !} | {ext: #[#]} } 220 | 221 | Replace: {num}{@Evaluate: 222 | IIf(Val({num})==Int(Val({num})), ".0") 223 | }{single:F} 224 | 225 | Criteria: 26 226 | Find: {num:"([0-9]*\.)?[0-9]+(e[-+]?[0-9]+)?"} 227 | { {quad: &&}|{long: &}|{dword: ???} } 228 | Replace: {@Eval: Round({num})}{long: }{dword:U}{quad:L} 229 | 230 | Criteria: 27 231 | Find: {num:"&h[0-9a-f]+"}{ {quad: &&}|{long: &}|{dword: ???} } 232 | Replace: {num}{long: }{dword:U}{quad:L} 233 | 234 | Criteria: 28 235 | Find: {text:"\q[^\q]*\q"}$$ 236 | Replace: L{text} 237 | 238 | Criteria: 29 239 | Comment: Accommodates array passed as arg 240 | Pass: 5 241 | 242 | Criteria: 30 243 | Find: As () 244 | Replace: () 245 | 246 | # End Search 247 | -------------------------------------------------------------------------------- /convert/win32api.inc: -------------------------------------------------------------------------------- 1 | ' Stripped version of Win32API.inc for faster testing 2 | ' Eventually should work with the real Win32API.inc 3 | 4 | %SW_SHOWMINIMIZED = 2 5 | Declare Function ShellExecute Lib "SHELL32.DLL" Alias "ShellExecuteA" (ByVal hwnd As Dword, lpOperation As Asciiz, lpFile As Asciiz, lpParameters As Asciiz, lpDirectory As Asciiz, ByVal nShowCmd As Long) As Dword 6 | Declare Function SetCursorPos Lib "USER32.DLL" Alias "SetCursorPos" (ByVal x As Long, ByVal y As Long) As Long 7 | Declare Sub SetLastError Lib "KERNEL32.DLL" Alias "SetLastError" (ByVal dwErrCode As Dword) 8 | -------------------------------------------------------------------------------- /test/SampleCode.Bas: -------------------------------------------------------------------------------- 1 | ' File name: SampleCode.Bas 2 | ' To convert this file to C++ make sure you have uCalc Transform on your PC 3 | ' and *.uc from github.com/uCalc/powerbasic-to-cpp/tree/master/convert 4 | ' Do the following at the Command Prompt: 5 | ' 6 | ' C:\> PBtoCPP.Bat SampleCode.Bas 7 | 8 | DefLng a-z 9 | 10 | %MyEquate = &h100 11 | %Other = &h200 12 | %LongEquate = 12345&& 13 | %HexLongEquate = &h123&& 14 | %EquateWithComment = 123 ' This is a comment 15 | $StrEquate = "Just a test: " 16 | $$WideEquate = "This is a wide string equate"$$ 17 | 18 | Global ProgStatus As Long 19 | Global MyValue!, Label$, ExtVal##, qNum&& 20 | Global gArray() As Long, gArray2!() 21 | 22 | #If %Def(%Other) 23 | ' Something 24 | #ElseIf Not %Def(%abcde) 25 | ' Something else 26 | #Else 27 | ' Etc 28 | #EndIf 29 | 30 | Macro MyMacroNum = 12345 31 | Macro MyMacro(a, b, c) = (a + b * (c)) 32 | 33 | Type pointType 34 | x As Long 35 | y As Long 36 | End Type 37 | 38 | Type TestType 39 | a As Long 40 | b As Long Ptr 41 | c As PointType 42 | d As PointType Ptr 43 | End Type 44 | 45 | Type OtherType 46 | First As Long 47 | Second As Long Ptr 48 | Third As TestType Ptr 49 | End Type 50 | 51 | Type MyBits ' A comment goes here 52 | Year As Bit * 7 In Dword 53 | Month As Bit * 5 54 | DayOfMonth As Bit * 4 55 | DayOfWeek As Bit * 3 56 | Red As Bit * 1 In Byte ' A comment here 57 | Blue As Bit * 1 ' A comment there 58 | Green As Bit * 1 59 | Other As Double 60 | xyz As Extended 61 | End Type 62 | 63 | Union MyUnion 64 | x1 As Long 65 | y1 As Dword 66 | z1 As Single 67 | End Union 68 | 69 | Union OtherUinion ' A comment goes here 70 | xx As Long 71 | yy As Dword 72 | zz As Single 73 | End Union 74 | 75 | Type NestedTypeA 76 | Item1 As Double 77 | PointType 78 | MyUnion 79 | End Type 80 | 81 | Type NestedTypeB 82 | Something As Long 83 | TestType 84 | NestedTypeA 85 | Other As Double 86 | End Type 87 | 88 | Function MyFunc(ByVal x As Long) As Long 89 | Function = x * 2 90 | End Function 91 | 92 | Function MyFunction(ByVal a As Long, ByRef b As Single) As Long 93 | Dim x As Long, y As Long, Test(a+25) As Long 94 | Dim yVar As Long, MyValue& 95 | ' Dim q As Long 96 | ' The commented line above is not translated 97 | 98 | MyFunc(a) 99 | x = MyFunc(b)+1 100 | 101 | If b > 5 Then 102 | For x = 1 To 10 103 | For yVar = 10 To 1 Step -1 104 | If x > y Then Function = a+y 105 | Do While Test(a+5) = yVar 106 | Do Until a+1 = 1234 107 | If y < %MyEquate Then Function = Test(x-y)*10 108 | a = a + 1 109 | Do 110 | b = a * 5 + b 111 | Loop Until b = 300 112 | Loop 113 | Loop 114 | Next 115 | Next 116 | End If 117 | End Function 118 | 119 | Sub MySub(ByVal x As Long, dArray() As Double) 120 | Local y As Long, Test As Single Ptr 121 | Dim Number(10) As Single, Other(x) As Long 122 | Register z As Long 123 | 124 | z = UBound(dArray) 125 | z = UBound(Number) 126 | Test = VarPtr(Number(0)) 127 | 128 | If x = 0 Then ' If Then 129 | ProgStatus = 10 130 | y = x + 1 : z = y+x : Other(x) = x+1 131 | ElseIf x = -1 Then ' Test for ElseIf 132 | While x < 10 133 | y = MyFunction(x, @Test) 134 | Test = VarPtr(MyValue!) 135 | Number(z) = @Test + Other(5+x) 136 | dArray(x) = Number(x) 137 | x = x+1 138 | If @Test < 0 Then Iterate 139 | If @Test = y Then Exit Sub 140 | If @Test = z Then Exit 141 | Wend 142 | ElseIf x = 1 Then 143 | Sleep 2+y 144 | Else ' Test for Else 145 | ProgStatus = 25 146 | If x = 2 Then 147 | y = x * 25 148 | z = y - 7 149 | Else 150 | Other(1) = x+1 151 | End If 152 | End If 153 | 154 | Dim t1 As OtherType, t2 As OtherType Ptr 155 | 156 | t2 = VarPtr(t1) 157 | 158 | i = Len(t1) ' Len(t1) 159 | i = Len(TestType) ' Len(TestType) 160 | i = Len("Test") ' Len("Test") 161 | 162 | i = t1.First 163 | i = t1.@Second 164 | i = t1.Third 165 | i = t1.@Third.a 166 | i = t1.@Third.b 167 | i = t1.@Third.@b 168 | i = t1.@Third.@d.x 169 | 170 | i = @t2.First 171 | i = @t2.@Second 172 | i = @t2.Third 173 | i = @t2.@Third.a 174 | i = @t2.@Third.b 175 | i = @t2.@Third.@b 176 | i = @t2.@Third.@d.x 177 | i = t1.@Second + t1.@Third.b + @t2.First + @t2.@Second + @t2.@Third.a + @t2.@Third.@b + @t2.@Third.@d.x 178 | 179 | Dim NstA As NestedTypeA, NstB As NestedTypeB 180 | 181 | NstA.Item1 = 123 182 | NstA.x = 10 183 | NstA.x1 = 10 184 | NstB.Something = 123 185 | NstB.a = NstB.Something +1 186 | NstB.Item1 = 123.456 187 | NstB.x = NstB.a + NstB.Something 188 | NstB.x1 = 123 189 | NstB.Other = NstB.Item1*2 190 | End Sub 191 | 192 | Sub TestCertainOperators(ByVal x As Long, _ ' This line is broken up using a _ (underscore) 193 | ByVal y As Long, _ This is a commment (even without ') 194 | ByVal z As Long, _ 195 | ByRef OtherVar As Double, _ Everything after _ is a comment 196 | ByVal FinalArg As Single Ptr _ 197 | ) ' Embedded comments after _ are preserved in their original location 198 | 199 | Dim MyArray(10) As Long, MyPoint As PointType, pp As PointType Ptr, n As Long 200 | 201 | For x = 1 To 10 ' Just a test {comment}. 202 | n = y = z ' This works differently in PB than in C++ 203 | MyArray(x) = x*2 204 | If x = 5 Then y = x+5 Else q = 23*2 205 | y = x = z : MyArray(5) = MyArray(n) = MyArray(n+1) 206 | If x = y = z Then y = n = 2 Else y = n = 3 207 | If x = y And x <> 10 Or y = x And x < 25 Then y = x Or y = z 208 | If (x = y And x <> 10 Or y = x And x < 25) Then y = x Or y = z 209 | If (x = y And x <> 10) Or y = x And x < 25 Then y = x Or y = z 210 | If Not(x = y Or x = z) Then x = y + 10 211 | If Not(x = y Or x = z) Then x = y + 10 212 | 213 | If x = 1 Then Erase MyArray() Else Erase MyArray ' Erase with and without optional () in PB 214 | 215 | If abcd <> xyz Then MyPoint.x = y Else MyPoint.x = x 216 | 217 | pp = VarPtr(MyPoint) 218 | MyPoint.x = MyPoint.y+1 219 | n = MyPoint.x = MyPoint.y 220 | @pp.x = @pp.y = @pp.x+1 221 | Next 222 | End Sub 223 | 224 | ' The section below is a test for variables declared implicitely with data type 225 | ' based on Def[Type] declarations or on type specifiers. 226 | 227 | DefByt b 228 | DefInt i 229 | DefStr s 230 | DefQud q 231 | DefSng n-p, x-z 232 | ' Note: DefLng a-z was already defined at the beginning of the code 233 | 234 | ' These globals defined at the top 235 | ' Global MyValue!, Label$, ExtVal##, qNum&& 236 | ' Global gArray() As Long, gArray2!() 237 | 238 | Function TestFunc(a, b, c, i, s, n) 239 | Print MyValue!, Label$, PriceB# 240 | Print 241 | Print 242 | 243 | If c = 123 Then Exit Function 244 | 245 | Label$ = "Missing quote at the end of this line is added by Refactor.uc 246 | Function = b + c 247 | End Function 248 | 249 | Function Report$(LastName$, ByVal x&, ByRef NewPrice#, n, ByVal i, nValue, qValue) 250 | Dim FirstName$, Age?, Total# 251 | Static Index& 252 | 253 | Print LastName$, x&, NewPrice#, n, i, nValue, qValue 254 | Report$ = FirstName$ + LastName$ 255 | End Function 256 | 257 | Function Hello(Txt$) As String 258 | Print txt$ 259 | Function = txt$ + " friend!" 260 | End Function 261 | 262 | Function Bye() 263 | Print "Bye" 264 | End Function 265 | 266 | 267 | ' This section is a test for Subs or Functions that are called as a statement 268 | ' without parentheses. The converter adds them. 269 | 270 | '#Include "Win32API.inc" 271 | %SW_SHOWMINIMIZED = 2 272 | Declare Function ShellExecute Lib "SHELL32.DLL" Alias "ShellExecuteA" (ByVal hwnd As Dword, lpOperation As Asciiz, lpFile As Asciiz, lpParameters As Asciiz, lpDirectory As Asciiz, ByVal nShowCmd As Long) As Dword 273 | Declare Function SetCursorPos Lib "USER32.DLL" Alias "SetCursorPos" (ByVal x As Long, ByVal y As Long) As Long 274 | Declare Sub SetLastError Lib "KERNEL32.DLL" Alias "SetLastError" (ByVal dwErrCode As Dword) 275 | 276 | Sub DoSomething(ByVal Arg1 As Long, ByRef txt$, Number##, Optional ByVal xyz As Dword Ptr) 277 | SetCursorPos 10, Arg1 + 5 278 | If Arg1 = 15 Then SetLastError 123 279 | End Sub 280 | 281 | %True = 1 282 | %False = 0 283 | 284 | Function PBMain() 285 | Dim x As Ext, pi As Ext, MyString$, FileInfo$, MyFile$(50), n As Long, dwTest As Dword, Num$ 286 | Dim mArray(10) As Double 287 | 288 | n = Len(TestType) ' Len(TestType) 289 | n = Len(FileInfo$) ' Len(FileInfo$) 290 | n = Len(MyFile$(n+1)) ' Len(MyFile$(n+1)) 291 | 292 | TestCertainOperators 1, 2.5, i, 4, VarPtr(MyValue!)-16 293 | 294 | DoSomething Len("Test")+5, "Hello " + "world!", Sin(x+1)*pi, VarPtr(x)-4 ' Comment 295 | 296 | DoSomething 10, "abc", 5, 1 : DoSomething 1, "x", 5, 0 ' Etc... 297 | 298 | If x > 1 Then DoSomething(1, "x", 5, 0) ' Parenthesis already here 299 | 300 | MyFunc 5 301 | MySub 10, mArray() 302 | 303 | ReDim gArray(15), gArray2(35) 304 | ReDim Preserve mArray(200) As Double 305 | 306 | ShellExecute 0, "Open", "ReadMe.Txt", $Nul, $Nul, %SW_ShowNormal 307 | ShellExecute 0, "Open", "ReadMe.Txt", $Nul, $Nul, %SW_ShowMinimized 308 | 309 | Line Input MyString$ ' No prompt 310 | Line Input "Please enter some text: " MyString$ ' quoted prompt - no comma 311 | Line Input "Please enter some text: ", MyString$ ' quoted prompt - with comma 312 | Line Input $StrEquate MyString$ ' equate prompt - no comma 313 | Line Input $StrEquate, MyString$ ' equate prompt - with comma 314 | 315 | dwTest = CvDwd(MyString$) 316 | dwTest = CvDwd(MyString$, 3) 317 | 318 | BinFile% = FreeFile 319 | InFile = FreeFile 320 | 321 | ' File handling test 322 | Open "MyBin.Txt" For Binary As #BinFile% 323 | Open "MyInput.Txt" For Input As #InFile 324 | Open "MyOutput.Txt" For Output As #3 325 | Open "MyAppend.Txt" For Append As #4 326 | 327 | i = IsFile("Test.Txt") 328 | i = Lof(#3) 329 | i = Lof(BinFile%) 330 | i = Seek(#BinFile%) 331 | i = Eof(#3) 332 | i = Eof(4) 333 | Seek #BinFile%, i+100 334 | 335 | Get$ #BinFile%, 500, MyString$ 336 | Put$ #BinFile%, MyString$ 337 | 338 | Print #3, CvByt(Num$, n) 339 | Print #3, Cvd(Num$) 340 | Print #3, Cvi(Num$, 4) 341 | Print #3, Cvl(Num$) 342 | Print #3 343 | Print #3, "This is a test" 344 | Print #3, "This is a test"; 345 | Print #3, "Part 1..."; "Part 2" 346 | Print #3, "Part 1..."; "Part 2"; 347 | Print #3, "Part 1..."; "Part 2"; "Part 3" 348 | Close #3 349 | Close 4, #BinFile%, InFile 350 | 351 | FileInfo$ = EXE.Extn$ 352 | FileInfo$ = EXE.Full$ 353 | FileInfo$ = EXE.Name$ 354 | FileInfo$ = EXE.Namex$ 355 | FileInfo$ = EXE.Path$ 356 | 357 | i = IIf(x > 1, Sin(x)+1, Cos(x)-1) * 2 358 | MyString$ = IIf$(x>50, Left$(MyString$, 10), Mid$(MyString$, 25)) 359 | 360 | MyFile$(0) = Dir$("*.Bas") 361 | MyFile$(1) = Dir$() 362 | MyFile$(2) = Dir$(Next) 363 | 364 | MyFile$(0) = Dir$("*.Bas") 365 | While MyFile$(n) <> "" And n < 50 366 | MyFile$(n) = Dir$() 367 | n += 1 368 | Wend 369 | 370 | Name "Temp.Txt" As "Text.Tmp" : Name "Something.Txt" As "Other.Txt" 371 | 372 | Swap MyString$, FileInfo$ 373 | 374 | ' The following should change casing to match that of original def, since C++ is case sensitive 375 | ' For instance if a function is defined as Hello() then occurrences of HELLO() change to Hello() 376 | 377 | Dim UnionTest As MYUNION, OtherItem As POINTType, MixedCasing As Long 378 | I = %myequate + myfunc(123) + MYMACRONUM + Progstatus + IMPLICITVAR(MIXEDcasing) 379 | Call MultiDIM() : Call myexportSUB(10, 20) 380 | CALL PRINTtest 381 | call myfunc(123) to I 382 | BYE() 383 | bye 384 | End Function 385 | 386 | Sub Rename1() 387 | ' Variables etc in your PB code that may conflict with C++ keywords like char, float, etc are renamed 388 | ' Note: Items are renamed only if they are lowercase; otherwise there's no conflict 389 | Dim auto As Long, Break As Long, float As Double, char As Byte, This As Long 390 | 391 | Break = %False 392 | For Auto = 1 To 10 393 | If Auto = 5 Then Break = %True 394 | Float = 1/Auto + Float 395 | char = Asc("A") + Auto 396 | This = Auto * 25 + unsigned + Throw 397 | Next 398 | End Sub 399 | 400 | Sub Rename2() 401 | ' Variables etc in your PB code that may conflict with C++ keywords like char, float, etc are renamed 402 | ' Note: Items are renamed only if they are lowercase; otherwise there's no conflict 403 | Dim auto As Long, break As Long, Float As Double, Char As Byte, This As Long 404 | 405 | Break = %False 406 | For Auto = 1 To 10 407 | If Auto = 5 Then break = %True 408 | Float = 1/Auto + Float 409 | char = Asc("A") + Auto 410 | This = Auto * 25 + Unsigned + throw 411 | Next 412 | End Sub 413 | 414 | ' This section tests transforms found in strings.uc 415 | Function StringTest(MyString$, ByVal OtherString As String) As String 416 | Dim MyText$, i As Long, MyWideStr As WString 417 | Dim Txt As String, x$, y$, z$$ 418 | 419 | z$$ = $$WideEquate + "Test" 420 | 421 | i = InStr(MyString$, "abc") 422 | i = InStr(i+10, MyString$, "xyz")*2 423 | i = InStr(MyString$, Any "aeiou") 424 | i = InStr(i+10, "This is a test", "is") 425 | i = InStr("This is a test", Any "aeiou") 426 | i = Asc(MyText$) 427 | i = Asc(MyText$, 5) 428 | i = Asc("This is a test") 429 | i = Asc("This is a test", 9) 430 | i = Asc("This is a test", 10+i) 431 | i = Asc("A") + 32 432 | i = Asc("Test", 3) 433 | y$ = UCase$(MyString$) + LCase$(MyString$) 434 | x$ = Space$(25) + String$(10, "*") + String$(10, 65) 435 | x$ = Trim$(x$)+LTrim$(x$)+RTrim$(x$)+Trim$(x$, Any ".,! ")+LTrim$(x$, Any ".,! ")+RTrim$(x$, Any ".,! ") 436 | x$ = Repeat$(i+5, "Test") 437 | x$ = Choose$(i, "This", "That", "Other", "Misc") 438 | i = Choose(Rnd(1, 5), 5, 10, 15, 20, 25) 439 | MyText$ = Left$(MyString$, 3) + Mid$(OtherString, 5, 10) + Right$(x$, i+1) 440 | MyText$ = Extract$(MyText$, "::") + Extract$(5+2*i, x$, "::") 441 | MyText$ = Extract$(MyText$, Any ".!?") + Extract$(15, y$, Any ".!?") 442 | MyText$ = Remain$(MyText$, "::") + Remain$(5+2*i, x$, "::") 443 | MyText$ = Remain$(MyText$, Any ".!?") + Remain$(15, y$, Any ".!?") 444 | MyText$ = Remove$(MyText$, "test") + Remove$(MyText$, Any ".!?") 445 | MyText$ = Max$("This", "That", x$, Mid$(x$, 2, 3), y$, "!") 446 | MyText$ = Min$("xyz", Max$(x$, y$), ".") 447 | MyText$ = " Backslash\is\an\escape\char in C++. " 448 | '+++ MyText$ = " Also test for ""nested"" quotes. " + """abc""" + "...\""..." 449 | Replace "abc" With "xyz" In MyText$ 450 | Replace Any "abc" With "xyz" In MyText$ 451 | If Mid$(MyText$, 3, 5) = y$ Then Mid$(MyText$, 20) = "Test" + Str$(i*15) + " " + Str$(10/7, 4) 452 | Mid$(x$, 25, Val(y$)+1) = y$ : Mid$(MyString$, 25, 5) = Mid$(y$, Val(x$), 7) 453 | Mid$(x$, 25) = y$ : Mid$(MyString$, 25) = Mid$(y$, Val(x$)) 454 | i = Val("123 Literal String") + Val("12" + "34") + Val("12" + y$) 455 | i = Verify("This is a test", "abcde") 456 | i = Verify(5, "This is a test", "abcde") 457 | 458 | RegExpr "t..t" In "This and that" To i 459 | RegExpr "t..t" In "This and that" At 5 To i 460 | RegExpr "t..t" In "This and that" At 5 To i, LengthVal 461 | 462 | RegRepl ".." In "This is a Test" with "new" To i, MyText$ 463 | RegRepl ".." In "This is a Test" with "new" At 5 To i, MyText$ 464 | 465 | Poke$ VarPtr(i), "ABCD" : MyText$ = Peek$(VarPtr(i), 2) 466 | If i = 1 Then Exit Function 467 | 468 | If x$ = $Cr Or x$ = $Lf Or x$ = $Nul Then MyText$ = "Line 1" + $CrLf + "Line 2" + $Qcq + "quote"+$Dq +$Tab 469 | MyText$ = Hex$(123) + " " + Oct$(1+2+3) 470 | MyText$ = Retain$("This is a test", "is") 471 | MyText$ = Retain$("This is a test", Any "is") 472 | MyText$ = StrReverse$("This is a test") 473 | ' +++ C++ doesn't seem to have a built-in string stream flag for Binary 474 | End Function 475 | 476 | ' This tests exported subs/functions 477 | Function MyExport Alias "MyExport" (ByVal n As Long) Export As Long 478 | StringTest "abc", "xyz" 479 | End Function 480 | 481 | Sub MyExportSub Alias "MyExportSub" (ByVal a, ByVal b) Export 482 | DoSomething(1, "xyz", 2, a) 483 | 484 | Select Case StringTest("abc", q$) 485 | Case "a", "b", "c" 486 | Print "Test" 487 | Case "x" 488 | Case q$ 489 | Select Case Rnd(1, 10) 490 | Case 1: Print 1+1 491 | Case 2 ' Comment 492 | Print "Do some thing" 493 | Case Else 494 | Print "Whatever" 495 | End Select 496 | End Select 497 | End Sub 498 | 499 | ' Math test 500 | ' If x Mod 2 > Cint(Sqr(x^2 + y^2)) Then Incr q Else Decr q 501 | Function DoMath() As Double 502 | Dim i As Long 503 | If x Mod 2 > CInt(Sqr(x^2 + y^2)) Then Incr q Else Decr q 504 | n = Sqr(x) * Atn(y) + 2 '* x^2 + Tan(x^3-1)^2 505 | n = x^2 + y^2 506 | y = Fix(3.14159) 507 | n = Frac(3.14159) 508 | n = Int(3.14159) + CInt(3.14159) + Exp10(3+2) 509 | n = Max(5.3, 11/2, 17, 4, Min(5, 3.5, -2, 8/7)) 510 | i = Min&(3, -10, 7, -1, Max&(3, 1, 7, -5), 23, 11) 511 | i = Min&(1, 2, Max(5, 6, 7.5)) 512 | i = 10 \ 3 513 | i = 123 eqv 345 514 | If x > 1 Eqv y > 2 Then i = 10 515 | If 123 Xor 456 Then i = 1 516 | If i >= n Or i => y Or n =< 1 Or i <= 1 Then i = 1 ' >= & => as well as <= & =< are synonymous in PB 517 | i = 123 Xor 456 518 | i = 123 Imp 456 519 | 520 | Randomize 1234 521 | y = Rnd + Rnd() + Rnd(1995, 2014) 522 | Shift Right i, 1 523 | Shift Left i, 1 524 | 525 | y = Sgn(-1) + Sgn(5) + Sgn(y) 526 | ' If IsTrue y = x Or IsFalse y > x + 1 Then y = y^2 +++ The ^ operator doesn't convert properly 527 | ' If IsTrue y = x Or IsFalse y > x + 1 And x < 10 Then y = y^2 528 | If IsTrue y = x Or IsFalse y > x + 1 Then y = y+2 529 | If IsTrue y = x Or IsFalse y > x + 1 And x < 10 Then y = y+2 530 | y = IsTrue x 531 | y = Max(3, 10, -2, 15+4, 23) 532 | y = Abs(-1)+Tan(Sin(2.5)+Cos(3.5))+Exp(1)+Exp2(5)+Log(5)+Log2(5)+Log10(5)+Ceil(5) 533 | 534 | MyVar## = -1 + 0 + 1! + 1.2! + 1.5# + 2## + 2.5## + 3& + 3.1& + 3.7& + 4&& + 4.3&& + 5??? 535 | i = &h1A + &h1B& + &h1C&& 536 | 537 | Swap x, y 538 | End Function 539 | 540 | ' Console routines 541 | Function PBConsoleTest() As Long 542 | StdOut "PB Semicolon at the end = No new line. "; 543 | StdOut "No semicolon = New Line at the end." 544 | End Function 545 | 546 | ' Test for the PRINT function 547 | Sub PrintTest() 548 | Print 549 | Print a 550 | Print a, 551 | Print a; 552 | Print a ' My comment 553 | Print a, ' Some comment 554 | Print : Print ' Print 555 | Print : Print : Print : Print 556 | Print a : Print b : Print c : Print d 557 | Print a, : Print b, 558 | Print , a: Print b, : Print c; d, : Print e 559 | Print , a 560 | Print , a, b 561 | Print ,, a, b, 562 | Print ,,,,a 563 | Print ,a,,, 564 | Print ,a,,,"" 565 | Print a; b, c; d, e; f, 566 | Print a; b; c, : Print d 567 | End Sub 568 | 569 | ' Test for implicit variable defs 570 | Function ImplicitVar(ByVal x As Long) 571 | For x = 1 To 10 572 | i = x * 10 573 | text$ = Str$(i+x) 574 | Next 575 | LastNum = x-1 576 | MyValue! = x/i ' Note: MyValue! was defined already as global 577 | OtherValue! = i/x 578 | b1&& = b2& + b3% + b4? + b5?? + b6??? + b7! + B8# + B9## 579 | End Function 580 | 581 | ' Test for optional args (default parameters are set in the prototype section at the top) 582 | Sub OptionalArgs(Optional ByVal a As Long, ByVal b As String, ByVal c#, ByVal d As Long Ptr, ByVal text$) 583 | ' Do things 584 | End Sub 585 | 586 | ' Test for optional args (default parameters are set in the prototype section at the top) 587 | Function OptionalArgs2(ByVal a As Long, Opt ByVal b As String, ByVal c#, ByVal d As Long Ptr) 588 | ' Do things 589 | End Function 590 | 591 | ' Test for optional args (default parameters are set in the prototype section at the top) 592 | Function OptionalArgs3(ByVal a As Long, Opt ByVal b As String, Opt ByVal c#, ByVal d) 593 | ' Do things 594 | End Function 595 | 596 | Global g1(), g2, g3, g4 As Dword 597 | 598 | Sub MultiDim() 599 | Local a, b, c, d As Long Ptr 600 | Static s1, s2(), s3, s4 As String 601 | '+++ Static s1, s2(10), s3, s4 As String 602 | ' Do things 603 | End Sub 604 | 605 | ' PowerBASIC allows you to pass an expression as a function arg even if it's defined ByRef 606 | ' whereas C++ expects the arg to be an lvalue (such as a variable of the exact parameter type). 607 | ' TestByRef() below tests the conversion transform from implicit-convert.uc, which uses the 608 | ' the lvalue() template defined in pbmisc.h. 609 | 610 | Sub TestByRef() 611 | ' Args for TestFunc (defined earlier) are all passed by reference 612 | ' TestFunc(a As Long, b As Byte, c As Long, i As Integer, s As String, n As Single) 613 | 614 | Dim VarLong As Long, VarByte As Byte, VarInt As Integer, VarString As String, VarSingle As Single 615 | 616 | i = TestFunc(VarLong, VarByte, VarLong, VarInt, VarString, VarSingle) 617 | i = TestFunc((VarLong), (VarByte), (VarLong), (VarInt), (VarString), (VarSingle)) 618 | i = TestFunc(VarLong+0, VarByte+0, VarLong+0, VarInt+0, VarString+"", VarSingle+0) 619 | i = TestFunc(1, 2, 3, 4, "Test", 5) 620 | i = TestFunc(Int(1+50/7)-5, 2+1, 3*50\i, 4-8, Left$("Test", 2), 8+3/2) 621 | End Sub 622 | -------------------------------------------------------------------------------- /test/SampleCode.cpp: -------------------------------------------------------------------------------- 1 | // This file (SampleCode.cpp) was converted from SampleCode.Bas 2 | // with uCalc Transform 2.98 on 07/23/14 using the Open Source 3 | // PowerBASIC to C++ converter found at https://github.com/uCalc/powerbasic-to-cpp 4 | 5 | // Standard lib headers used by PB to C++ are in sdtafx.h & pre-compiled 6 | #include "stdafx.h" 7 | 8 | using namespace std; 9 | 10 | 11 | 12 | #include "pbOS.h" 13 | #include "pbMisc.h" 14 | #include "pbstrings.h" 15 | // Prototypes 16 | 17 | int MyFunc(int x); 18 | int MyFunction(int a, float& b); 19 | void MySub(int x, std::vector& dArray); 20 | void TestCertainOperators(int x, /* ' This line is broken up using a _ (underscore) */ 21 | int y, /* This is a commment (even without ') */ 22 | int z, 23 | double& OtherVar, /* Everything after _ is a comment */ 24 | float *FinalArg); 25 | int TestFunc(int& a, UCHAR& b, int& c, short& i, string& s, float& n); 26 | string Report(string& LastName, int x, double& NewPrice, float& n, short i, float& nValue, __int64& qValue); 27 | string Hello(string& txt); 28 | UCHAR Bye(); 29 | void DoSomething(int Arg1, string& txt, EXTENDED& Number, unsigned *xyz = NULL); 30 | // Declare Function PBMain() As Long 31 | void Rename1(); 32 | void Rename2(); 33 | string StringTest(string& MyString, string OtherString); 34 | extern "C" __declspec(dllexport) int __stdcall MyExport(int n); 35 | extern "C" __declspec(dllexport) void __stdcall MyExportSub(int a, UCHAR b); 36 | double DoMath(); 37 | int PBConsoleTest(); 38 | void PrintTest(); 39 | short ImplicitVar(int x); 40 | void OptionalArgs(int a = 0, string b = "", double c = 0.0, int *d = NULL, string text = ""); 41 | float OptionalArgs2(int a, string b = "", double c = 0.0, int *d = NULL); 42 | float OptionalArgs3(int a, string b = "", double c = 0.0, int d = 0); 43 | void MultiDim(); 44 | void TestByRef(); 45 | // End of prototypes 46 | 47 | // These equates may need to be adjusted manually 48 | // depending on the compiler version used 49 | //%PB_REVISION = &H501 50 | //%PB_REVLETTER = &H20 51 | //%PB_EXE = -1 52 | //%PB_CC32 = -1 53 | // PB_DLL32 = 0 54 | //%PB_WIN32 = 0 55 | const int USEMACROS = -1; 56 | // File name: SampleCode.Bas 57 | // To convert this file to C++ make sure you have uCalc Transform on your PC 58 | // and *.uc from github.com/uCalc/powerbasic-to-cpp/tree/master/convert 59 | // Do the following at the Command Prompt: 60 | // 61 | // C:\> PBtoCPP.Bat SampleCode.Bas 62 | 63 | 64 | const int MyEquate = 0x100; 65 | const int Other = 0x200; 66 | const int LongEquate = 12345L; 67 | const int HexLongEquate = 0x123L; 68 | const int EquateWithComment = 123; // This is a comment 69 | const string StrEquate = "Just a test: "; 70 | const wstring WideEquate = L"This is a wide string equate"; 71 | 72 | int ProgStatus = int(); 73 | float MyValue = float(); 74 | string Label = string(); 75 | EXTENDED ExtVal = EXTENDED(); 76 | __int64 qNum = __int64(); 77 | std::vector gArray; 78 | std::vector gArray2; 79 | 80 | #if defined Other 81 | // Something 82 | #elif !defined abcde 83 | //' Something else 84 | #else 85 | // Etc 86 | #endif 87 | 88 | #define MyMacroNum 12345 89 | #define MyMacro(a, b, c) (a + b * (c)) 90 | 91 | struct pointType { 92 | int x; 93 | int y; 94 | }; 95 | 96 | struct TestType { 97 | int a; 98 | int *b; 99 | pointType c; 100 | pointType *d; 101 | }; 102 | 103 | struct OtherType { 104 | int First; 105 | int *Second; 106 | TestType *Third; 107 | }; 108 | 109 | struct MyBits { // A comment goes here 110 | unsigned Year : 7; 111 | unsigned Month : 5; 112 | unsigned DayOfMonth : 4; 113 | unsigned DayOfWeek : 3; 114 | UCHAR Red : 1; // A comment here 115 | UCHAR Blue : 1; // A comment there 116 | UCHAR Green : 1; 117 | double Other; 118 | EXTENDED xyz; 119 | }; 120 | 121 | union MyUnion { 122 | int x1; 123 | unsigned y1; 124 | float z1; 125 | }; 126 | 127 | union OtherUinion { // A comment goes here 128 | int xx; 129 | unsigned yy; 130 | float zz; 131 | }; 132 | 133 | struct NestedTypeA { 134 | double Item1; 135 | int x; 136 | int y; 137 | union { 138 | int x1; 139 | unsigned y1; 140 | float z1; 141 | }; 142 | }; 143 | 144 | struct NestedTypeB { 145 | int Something; 146 | int a; 147 | int *b; 148 | pointType c; 149 | pointType *d; 150 | 151 | double Item1; 152 | int x; 153 | int y; 154 | union { 155 | int x1; 156 | unsigned y1; 157 | float z1; 158 | }; 159 | 160 | double Other; 161 | }; 162 | 163 | int MyFunc(int x) 164 | { 165 | int _ReturnValue = int(); 166 | 167 | _ReturnValue = x * 2; 168 | 169 | return _ReturnValue; 170 | } 171 | 172 | int MyFunction(int a, float& b) 173 | { 174 | int _ReturnValue = int(); 175 | 176 | int x = int(); 177 | int y = int(); 178 | std::vectorTest(a+25+1, int()); 179 | int yVar = int(); 180 | int MyValue = int(); 181 | // Dim q As Long 182 | // The commented line above is not translated 183 | 184 | MyFunc(a); 185 | x = MyFunc(b)+1; 186 | 187 | if (b > 5) { 188 | for (x=1; x<=10; x += 1) { 189 | for (yVar=10; yVar>=1; yVar += -1) { 190 | if (x > y) { 191 | _ReturnValue = a+y; 192 | } 193 | while (Test[a+5] == yVar) { 194 | while (!(a+1 == 1234)) { 195 | if (y < MyEquate) { 196 | _ReturnValue = Test[x-y]*10; 197 | } 198 | a = a + 1; 199 | do { 200 | b = a * 5 + b; 201 | } while (!(b == 300)); 202 | } 203 | } 204 | } 205 | } 206 | } 207 | 208 | return _ReturnValue; 209 | } 210 | 211 | void MySub(int x, std::vector& dArray) 212 | { 213 | short i = short(); // Implicit 214 | 215 | int y = int(); 216 | float *Test; 217 | std::vectorNumber(10+1, float()); 218 | std::vectorOther(x+1, int()); 219 | int z = int(); 220 | 221 | z = (dArray.size()-1); 222 | z = (Number.size()-1); 223 | Test = &Number[0]; 224 | 225 | if (x == 0) { // If Then 226 | ProgStatus = 10; 227 | y = x + 1; 228 | z = y+x; 229 | Other[x] = x+1; 230 | } else if (x == -1) { // Test for ElseIf 231 | while (x < 10) { 232 | y = MyFunction(x, lvalue(float(*Test))); 233 | Test = &MyValue; 234 | Number[z] = *Test + Other[5+x]; 235 | dArray[x] = Number[x]; 236 | x = x+1; 237 | if (*Test < 0) { 238 | continue; 239 | } 240 | if (*Test == y) { 241 | return; 242 | } 243 | if (*Test == z) { 244 | break; 245 | } 246 | } 247 | } else if (x == 1) { 248 | PB_SLEEP(2+y); 249 | } else { // Test for Else 250 | ProgStatus = 25; 251 | if (x == 2) { 252 | y = x * 25; 253 | z = y - 7; 254 | } else { 255 | Other[1] = x+1; 256 | } 257 | } 258 | 259 | OtherType t1 = OtherType(); 260 | OtherType *t2; 261 | 262 | t2 = &t1; 263 | 264 | i = sizeof(t1); // Len(t1) 265 | i = sizeof(TestType); // Len(TestType) 266 | i = string("Test").length(); // Len("Test") 267 | 268 | i = t1.First; 269 | i = *t1.Second; 270 | i = t1.Third; 271 | i = t1.Third->a; 272 | i = t1.Third->b; 273 | i = *t1.Third->b; 274 | i = t1.Third->d->x; 275 | 276 | i = t2->First; 277 | i = *t2->Second; 278 | i = t2->Third; 279 | i = t2->Third->a; 280 | i = t2->Third->b; 281 | i = *t2->Third->b; 282 | i = t2->Third->d->x; 283 | i = *t1.Second + t1.Third->b + t2->First + *t2->Second + t2->Third->a + *t2->Third->b + t2->Third->d->x; 284 | 285 | NestedTypeA NstA = NestedTypeA(); 286 | NestedTypeB NstB = NestedTypeB(); 287 | 288 | NstA.Item1 = 123; 289 | NstA.x = 10; 290 | NstA.x1 = 10; 291 | NstB.Something = 123; 292 | NstB.a = NstB.Something +1; 293 | NstB.Item1 = 123.456; 294 | NstB.x = NstB.a + NstB.Something; 295 | NstB.x1 = 123; 296 | NstB.Other = NstB.Item1*2; 297 | } 298 | 299 | void TestCertainOperators(int x, /* ' This line is broken up using a _ (underscore) */ 300 | int y, /* This is a commment (even without ') */ 301 | int z, 302 | double& OtherVar, /* Everything after _ is a comment */ 303 | float *FinalArg) 304 | { 305 | int abcd = int(); // Implicit 306 | __int64 q = __int64(); // Implicit 307 | float xyz = float(); // Implicit 308 | // Embedded comments after _ are preserved in their original location 309 | 310 | std::vectorMyArray(10+1, int()); 311 | pointType MyPoint = pointType(); 312 | pointType *pp; 313 | int n = int(); 314 | 315 | for (x=1; x<=10; x += 1) { // Just a test {comment}. 316 | n = y == z; // This works differently in PB than in C++ 317 | MyArray[x] = x*2; 318 | if (x == 5) { 319 | y = x+5; 320 | } else { 321 | q = 23*2; 322 | } 323 | y = x == z; 324 | MyArray[5] = MyArray[n] == MyArray[n+1]; 325 | if (x == y == z) { 326 | y = n == 2; 327 | } else { 328 | y = n == 3; 329 | } 330 | if (x == y && x != 10 || y == x && x < 25) { 331 | y = x || y == z; 332 | } 333 | if ((x == y & x != 10 | y == x & x < 25)) { 334 | y = x || y == z; 335 | } 336 | if ((x == y & x != 10) || y == x && x < 25) { 337 | y = x || y == z; 338 | } 339 | if (~(x == y | x == z)) { 340 | x = y + 10; 341 | } 342 | if (~(x == y | x == z)) { 343 | x = y + 10; 344 | } 345 | 346 | if (x == 1) { 347 | MyArray.clear(); 348 | } else { 349 | MyArray.clear(); // Erase with and without optional () in PB 350 | } 351 | 352 | if (abcd != xyz) { 353 | MyPoint.x = y; 354 | } else { 355 | MyPoint.x = x; 356 | } 357 | 358 | pp = &MyPoint; 359 | MyPoint.x = MyPoint.y+1; 360 | n = MyPoint.x == MyPoint.y; 361 | pp->x = pp->y == pp->x+1; 362 | } 363 | } 364 | 365 | // The section below is a test for variables declared implicitely with data type 366 | // based on Def[Type] declarations or on type specifiers. 367 | 368 | 369 | // These globals defined at the top 370 | // Global MyValue!, Label$, ExtVal##, qNum&& 371 | // Global gArray As Long, gArray2!() 372 | 373 | int TestFunc(int& a, UCHAR& b, int& c, short& i, string& s, float& n) 374 | { 375 | int _ReturnValue = int(); 376 | double PriceB = double(); // Implicit 377 | 378 | cout << PZONE << MyValue << PZONE << Label << PriceB << endl; 379 | cout << endl; 380 | cout << endl; 381 | 382 | if (c == 123) { 383 | return _ReturnValue; 384 | } 385 | 386 | Label = "Missing quote at the end of this line is added by Refactor.uc"; 387 | _ReturnValue = b + c; 388 | 389 | return _ReturnValue; 390 | } 391 | 392 | string Report(string& LastName, int x, double& NewPrice, float& n, short i, float& nValue, __int64& qValue) 393 | { 394 | string _ReturnValue = string(); 395 | 396 | string FirstName = string(); 397 | UCHAR Age = UCHAR(); 398 | double Total = double(); 399 | static int Index = int(); 400 | 401 | cout << PZONE << LastName << PZONE << x << PZONE << NewPrice << PZONE << n << PZONE << i << PZONE << nValue << qValue << endl; 402 | _ReturnValue = FirstName + LastName; 403 | 404 | return _ReturnValue; 405 | } 406 | 407 | string Hello(string& Txt) 408 | { 409 | string _ReturnValue = string(); 410 | 411 | cout << Txt << endl; 412 | _ReturnValue = Txt + " friend!"; 413 | 414 | return _ReturnValue; 415 | } 416 | 417 | UCHAR Bye() 418 | { 419 | UCHAR _ReturnValue = UCHAR(); 420 | 421 | cout << "Bye" << endl; 422 | 423 | return _ReturnValue; 424 | } 425 | 426 | 427 | // This section is a test for Subs or Functions that are called as a statement 428 | // without parentheses. The converter adds them. 429 | 430 | //#Include "Win32API.inc" 431 | // SW_SHOWMINIMIZED = 2 432 | // Declare Function ShellExecute Lib "SHELL32.DLL" Alias "ShellExecuteA" (ByVal hwnd As Dword, lpOperation As Asciiz, lpFile As Asciiz, lpParameters As Asciiz, lpDirectory As Asciiz, ByVal nShowCmd As Long) As Dword 433 | // Declare Function SetCursorPos Lib "USER32.DLL" Alias "SetCursorPos" (ByVal x As Long, ByVal y As Long) As Long 434 | // Declare Sub SetLastError Lib "KERNEL32.DLL" Alias "SetLastError" (ByVal dwErrCode As Dword) 435 | 436 | void DoSomething(int Arg1, string& txt, EXTENDED& Number, unsigned *xyz) 437 | { 438 | SetCursorPos(10, Arg1 + 5); 439 | if (Arg1 == 15) { 440 | SetLastError(123); 441 | } 442 | } 443 | 444 | // True = 1 445 | // False = 0 446 | 447 | int main() 448 | { 449 | int _ReturnValue = int(); 450 | short BinFile = short(); // Implicit 451 | short i = short(); // Implicit 452 | short InFile = short(); // Implicit 453 | 454 | EXTENDED x = EXTENDED(); 455 | EXTENDED pi = EXTENDED(); 456 | string MyString = string(); 457 | string FileInfo = string(); 458 | std::vectorMyFile(50+1, string()); 459 | int n = int(); 460 | unsigned dwTest = unsigned(); 461 | string Num = string(); 462 | std::vectormArray(10+1, double()); 463 | 464 | n = sizeof(TestType); // Len(TestType) 465 | n = string(FileInfo).length(); // Len(FileInfo$) 466 | n = string(MyFile[n+1]).length(); // Len(MyFile$(n+1)) 467 | 468 | TestCertainOperators(1, 2.5, i, lvalue(double(4)), (float *)(&MyValue-16)); 469 | 470 | DoSomething(string("Test").length()+5, lvalue(string(string("Hello ")+"world!")), lvalue(EXTENDED(sin(x+1)*pi)), (unsigned *)(&x-4)); // Comment 471 | 472 | DoSomething(10, lvalue(string("abc")), lvalue(EXTENDED(5)), (unsigned *)(1)); 473 | DoSomething(1, lvalue(string("x")), lvalue(EXTENDED(5)), (unsigned *)(0)); // Etc... 474 | 475 | if (x > 1) { 476 | DoSomething(1, lvalue(string("x")), lvalue(EXTENDED(5)), (unsigned *)(0)); // Parenthesis already here 477 | } 478 | 479 | MyFunc(5); 480 | MySub(10, mArray); 481 | 482 | gArray.clear(); 483 | gArray.resize(15+1); 484 | gArray2.clear(); 485 | gArray2.resize(35+1); 486 | mArray.resize(200+1); 487 | 488 | ShellExecute(0, "Open", "ReadMe.Txt", PB_NUL, PB_NUL, SW_SHOWNORMAL); 489 | ShellExecute(0, "Open", "ReadMe.Txt", PB_NUL, PB_NUL, SW_SHOWMINIMIZED); 490 | 491 | getline(cin, MyString); // No prompt 492 | cout << "Please enter some text:"; 493 | getline(cin, MyString); // quoted prompt - no comma 494 | cout << "Please enter some text:"; 495 | getline(cin, MyString); // quoted prompt - with comma 496 | cout << StrEquate; 497 | getline(cin, MyString); // equate prompt - no comma 498 | cout << StrEquate; 499 | getline(cin, MyString); // equate prompt - with comma 500 | 501 | dwTest = PB_CVDWD(MyString, 1); 502 | dwTest = PB_CVDWD(MyString, 3); 503 | 504 | BinFile = 1; 505 | InFile = 2; 506 | 507 | // File handling test 508 | fstream file_BinFile (string("MyBin.Txt").c_str(), ios::binary | ios::in | ios::out); 509 | fstream file_InFile (string("MyInput.Txt").c_str(), ios::in); 510 | fstream file_3 (string("MyOutput.Txt").c_str(), ios::out | ios::trunc); 511 | fstream file_4 (string("MyAppend.Txt").c_str(), ios::out | ios::app); 512 | 513 | i = PB_ISFILE("Test.Txt"); 514 | i = PB_LOF(file_3); 515 | i = PB_LOF(file_BinFile); 516 | i = (int)file_BinFile.tellg()+1; 517 | i = file_3.eof(); 518 | i = file_4.eof(); 519 | file_BinFile.seekg(i+100-1); 520 | file_BinFile.seekp(i+100-1); 521 | 522 | MyString.resize(500); 523 | file_BinFile.read(&MyString[0], 500); 524 | file_BinFile.write(&MyString[0], MyString.size()); 525 | 526 | file_3 << PB_CVBYT(Num, n) << endl; 527 | file_3 << PB_CVD(Num, 1) << endl; 528 | file_3 << PB_CVI(Num, 4) << endl; 529 | file_3 << PB_CVL(Num, 1) << endl; 530 | file_3 << endl; 531 | file_3 << "This is a test" << endl; 532 | file_3 << "This is a test"; 533 | file_3 << "Part 1..." << "Part 2" << endl; 534 | file_3 << "Part 1..." << "Part 2"; 535 | file_3 << "Part 1..." << "Part 2" << "Part 3" << endl; 536 | file_3.close(); // PB: Close #3 537 | file_4.close(); // PB: Close #4 538 | file_BinFile.close(); // PB: Close #BinFile 539 | file_InFile.close(); // PB: Close #InFile 540 | 541 | FileInfo = PB_EXE_EXTN; 542 | FileInfo = PB_EXE_FULL(); 543 | FileInfo = PB_EXE_NAME; 544 | FileInfo = PB_EXE_NAMEX; 545 | FileInfo = PB_EXE_PATH; 546 | 547 | i = (x > 1 ? sin(x)+1 : cos(x)-1) * 2; 548 | MyString = (x>50 ? PB_LEFT(MyString, 10) : PB_MID(MyString, 25, FULL_STRING)); 549 | 550 | MyFile[0] = PB_DIR("*.Bas"); 551 | MyFile[1] = PB_DIR_NEXT(); 552 | MyFile[2] = PB_DIR_NEXT(); 553 | 554 | MyFile[0] = PB_DIR("*.Bas"); 555 | while (MyFile[n] != "" && n < 50) { 556 | MyFile[n] = PB_DIR_NEXT(); 557 | n += 1; 558 | } 559 | 560 | PB_NAME("Temp.Txt", "Text.Tmp"); 561 | PB_NAME("Something.Txt", "Other.Txt"); 562 | 563 | swap(MyString, FileInfo); 564 | 565 | // The following should change casing to match that of original def, since C++ is case sensitive 566 | // For instance if a function is defined as Hello() then occurrences of HELLO() change to Hello() 567 | 568 | MyUnion UnionTest = MyUnion(); 569 | pointType OtherItem = pointType(); 570 | int MixedCasing = int(); 571 | i = MyEquate + MyFunc(123) + MyMacroNum + ProgStatus + ImplicitVar(MixedCasing); 572 | MultiDim(); 573 | MyExportSub(10, 20); 574 | PrintTest; 575 | i = MyFunc(123); 576 | Bye(); 577 | Bye(); 578 | 579 | return _ReturnValue; 580 | } 581 | 582 | void Rename1() 583 | { 584 | int Throw = int(); // Implicit 585 | int unsigned_Renamed = int(); // Implicit 586 | 587 | // Variables etc in your PB code that may conflict with C++ keywords like char, float, etc are renamed 588 | // Note: Items are renamed only if they are lowercase; otherwise there's no conflict 589 | int auto_Renamed = int(); 590 | int Break = int(); 591 | double float_Renamed = double(); 592 | UCHAR char_Renamed = UCHAR(); 593 | int This = int(); 594 | 595 | Break = FALSE; 596 | for (auto_Renamed=1; auto_Renamed<=10; auto_Renamed += 1) { 597 | if (auto_Renamed == 5) { 598 | Break = TRUE; 599 | } 600 | float_Renamed = 1/auto_Renamed + float_Renamed; 601 | char_Renamed = 'A' + auto_Renamed; 602 | This = auto_Renamed * 25 + unsigned_Renamed + Throw; 603 | } 604 | } 605 | 606 | void Rename2() 607 | { 608 | int throw_Renamed = int(); // Implicit 609 | int Unsigned = int(); // Implicit 610 | 611 | // Variables etc in your PB code that may conflict with C++ keywords like char, float, etc are renamed 612 | // Note: Items are renamed only if they are lowercase; otherwise there's no conflict 613 | int auto_Renamed = int(); 614 | int break_Renamed = int(); 615 | double Float = double(); 616 | UCHAR Char = UCHAR(); 617 | int This = int(); 618 | 619 | break_Renamed = FALSE; 620 | for (auto_Renamed=1; auto_Renamed<=10; auto_Renamed += 1) { 621 | if (auto_Renamed == 5) { 622 | break_Renamed = TRUE; 623 | } 624 | Float = 1/auto_Renamed + Float; 625 | Char = 'A' + auto_Renamed; 626 | This = auto_Renamed * 25 + Unsigned + throw_Renamed; 627 | } 628 | } 629 | 630 | // This section tests transforms found in strings.uc 631 | string StringTest(string& MyString, string OtherString) 632 | { 633 | string _ReturnValue = string(); 634 | int LengthVal = int(); // Implicit 635 | 636 | string MyText = string(); 637 | int i = int(); 638 | wstring MyWideStr = wstring(); 639 | string Txt = string(); 640 | string x = string(); 641 | string y = string(); 642 | wstring z = wstring(); 643 | 644 | z = WideEquate + L"Test"; 645 | 646 | i = PB_INSTR(1, MyString, "abc"); 647 | i = PB_INSTR(i+10, MyString, "xyz")*2; 648 | i = PB_INSTR_ANY(1, MyString, "aeiou"); 649 | i = PB_INSTR(i+10, "This is a test", "is"); 650 | i = PB_INSTR_ANY(1, "This is a test", "aeiou"); 651 | i = PB_ASC(MyText, 1); 652 | i = PB_ASC(MyText, 5); 653 | i = 'T'; 654 | i = 'a'; 655 | i = PB_ASC("This is a test", 10+i); 656 | i = 'A' + 32; 657 | i = 's'; 658 | y = PB_UCASE(MyString) + PB_LCASE(MyString); 659 | x = string(25, ' ') + string(10, '*') + string(10, 65); 660 | x = PB_TRIM_ANY(x, " ")+PB_LTRIM_ANY(x, " ")+PB_RTRIM_ANY(x, " ")+PB_TRIM_ANY(x, ".,! ")+PB_LTRIM_ANY(x, ".,! ")+PB_RTRIM_ANY(x, ".,! "); 661 | x = PB_REPEAT("Test", i+5); 662 | x = (i ? "This" : (i ? "That" : (i ? "Other" : (i ? "Misc" : "")))); 663 | i = ((rand() % (5) + (1)) ? 5 : ((rand() % (5) + (1)) ? 10 : ((rand() % (5) + (1)) ? 15 : ((rand() % (5) + (1)) ? 20 : ((rand() % (5) + (1)) ? 25 : 0))))); 664 | MyText = PB_LEFT(MyString, 3) + PB_MID(OtherString, 5, 10) + PB_RIGHT(x, i+1); 665 | MyText = PB_EXTRACT(1, MyText, "::") + PB_EXTRACT(5+2*i, x, "::"); 666 | MyText = PB_EXTRACT_ANY(1, MyText, ".!?") + PB_EXTRACT_ANY(15, y, ".!?"); 667 | MyText = PB_REMAIN(1, MyText, "::") + PB_REMAIN(5+2*i, x, "::"); 668 | MyText = PB_REMAIN_ANY(1, MyText, ".!?") + PB_REMAIN_ANY(15, y, ".!?"); 669 | MyText = PB_REMOVE(MyText, "test") + PB_REMOVE_ANY(MyText, ".!?"); 670 | MyText = PB_MAX_STR(ARGCOUNT(6), (string)"This", (string) "That", (string) x, (string) PB_MID(x, 2, 3), (string) y, (string) "!"); 671 | MyText = PB_MIN_STR(ARGCOUNT(3), (string)"xyz", (string) PB_MAX_STR(ARGCOUNT(2), (string)x, (string) y), (string) "."); 672 | MyText = " Backslash\\is\\an\\escape\\char in C++. "; 673 | //+++ MyText$ = " Also test for ""nested"" quotes. " + """abc""" + "...\\""..." 674 | PB_REPLACE(MyText, "abc", "xyz"); 675 | PB_REPLACE_ANY(MyText, "abc", "xyz"); 676 | if (PB_MID(MyText, 3, 5) == y) { 677 | PB_MID_REPLACE(MyText, "Test" + PB_STR(i*15) + " " + PB_STR(10/7, 4), 20, FULL_STRING); 678 | } 679 | PB_MID_REPLACE(x, y, 25, stold(y) +1); 680 | PB_MID_REPLACE(MyString, PB_MID(y, stold(x), 7), 25, 5); 681 | PB_MID_REPLACE(x, y, 25, FULL_STRING); 682 | PB_MID_REPLACE(MyString, PB_MID(y, stold(x), FULL_STRING), 25, FULL_STRING); 683 | i = stold("123 Literal String") + stold(string("12")+"34") + stold("12" + y); 684 | i = PB_VERIFY(1, "This is a test", "abcde"); 685 | i = PB_VERIFY(5, "This is a test", "abcde"); 686 | 687 | PB_REGEXPR("t..t", "This & that", 1, i, PB_DISCARD); 688 | PB_REGEXPR("t..t", "This & that", 5, i, PB_DISCARD); 689 | PB_REGEXPR("t..t", "This & that", 5, i, LengthVal); 690 | 691 | PB_REGREPL(1, "..", "This is a Test", "new", i, MyText); 692 | PB_REGREPL(5, "..", "This is a Test", "new", i, MyText); 693 | 694 | PB_POKE_STR((unsigned)&i, "ABCD"); 695 | MyText = PB_PEEK_STR((unsigned)&i, 2); 696 | if (i == 1) { 697 | return _ReturnValue; 698 | } 699 | 700 | if (x == PB_CR || x == PB_LF || x == PB_NUL) { 701 | MyText = "Line 1" + PB_CRLF + "Line 2" + PB_QCQ + "quote"+PB_DQ +PB_TAB; 702 | } 703 | MyText = PB_HEX(123) + " " + PB_OCT(1+2+3); 704 | MyText = PB_RETAIN("This is a test", "is"); 705 | MyText = PB_RETAIN_ANY("This is a test", "is"); 706 | MyText = PB_STRREVERSE("This is a test"); 707 | // +++ C++ doesn't seem to have a built-in string stream flag for Binary 708 | 709 | return _ReturnValue; 710 | } 711 | 712 | // This tests exported subs/functions 713 | extern "C" __declspec(dllexport) int __stdcall MyExport(int n) { 714 | int _ReturnValue = int(); 715 | 716 | StringTest(lvalue(string("abc")), "xyz"); 717 | 718 | return _ReturnValue; 719 | } 720 | 721 | extern "C" __declspec(dllexport) void __stdcall MyExportSub(int a, UCHAR b) { 722 | string q = string(); // Implicit 723 | 724 | DoSomething(1, lvalue(string("xyz")), lvalue(EXTENDED(2)), (unsigned *)(a)); 725 | { 726 | auto CASE_VAR = StringTest(lvalue(string("abc")), q); 727 | if (CASE_VAR == "a" || CASE_VAR == "b" || CASE_VAR == "c") { 728 | cout << "Test" << endl; 729 | } else if (CASE_VAR == "x") { 730 | 731 | } else if (CASE_VAR == q) { 732 | { 733 | auto CASE_VAR = (rand() % (10) + (1)); 734 | if (CASE_VAR == 1) { 735 | cout << 1+1 << endl; 736 | } else if (CASE_VAR == 2) { // Comment 737 | cout << "Do some thing" << endl; 738 | } else { 739 | cout << "Whatever" << endl; 740 | } 741 | } 742 | } 743 | } 744 | } 745 | 746 | // Math test 747 | // If x Mod 2 > Cint(Sqr(x^2 + y^2)) Then Incr q Else Decr q 748 | double DoMath() 749 | { 750 | double _ReturnValue = double(); 751 | EXTENDED MyVar = EXTENDED(); // Implicit 752 | float n = float(); // Implicit 753 | __int64 q = __int64(); // Implicit 754 | float x = float(); // Implicit 755 | float y = float(); // Implicit 756 | 757 | int i = int(); 758 | if (int(x) % 2 > short(sqrt(pow(x, 2) + pow(y, 2)))) { 759 | q++; 760 | } else { 761 | q--; 762 | } 763 | n = sqrt(x) * atan(y) + 2; //* x^2 + Tan(x^3-1)^2 764 | n = pow(x, 2) + pow(y, 2); 765 | y = PB_FIX(3.14159); 766 | n = PB_FRAC(3.14159); 767 | n = __int64(3.14159) + short(3.14159) + PB_EXP10(3+2); 768 | n = PB_MAX(ARGCOUNT(5), (double)5.3, (double) 11/2, (double) 17, (double) 4, (double) PB_MIN(ARGCOUNT(4), (double)5, (double) 3.5, (double) -2, (double) 8/7)); 769 | i = PB_MIN_INT(ARGCOUNT(7), (int)3, (int) -10, (int) 7, (int) -1, (int) PB_MAX_INT(ARGCOUNT(4), (int)3, (int) 1, (int) 7, (int) -5), (int) 23, (int) 11); 770 | i = PB_MIN_INT(ARGCOUNT(3), (int)1, (int) 2, (int) PB_MAX(ARGCOUNT(3), (double)5, (double) 6, (double) 7.5)); 771 | i = _round(10 / 3); 772 | i = PB_EQV(123, 345); 773 | if (PB_EQV(x > 1, y > 2)) { 774 | i = 10; 775 | } 776 | if (PB_XOR(123, 456)) { 777 | i = 1; 778 | } 779 | if (i >= n || i >= y || n <= 1 || i <= 1) { 780 | i = 1; // >= & => as well as <= & =< are synonymous in PB 781 | } 782 | i = PB_XOR(123, 456); 783 | i = PB_IMP(123, 456); 784 | 785 | srand(1234); 786 | y = (rand() / RAND_MAX) + (rand() / RAND_MAX) + (rand() % (2014) + (1995)); 787 | i = (i >> 1); 788 | i = (i << 1); 789 | 790 | y = PB_SGN(-1) + PB_SGN(5) + PB_SGN(y); 791 | // If IsTrue y = x Or IsFalse y > x + 1 Then y = y^2 +++ The ^ operator doesn't convert properly 792 | // If IsTrue y = x Or IsFalse y > x + 1 And x < 10 Then y = y^2 793 | if (((y == x) != 0) || !(y > x + 1)) { 794 | y = y+2; 795 | } 796 | if (((y == x) != 0) || !(y > x + 1) && x < 10) { 797 | y = y+2; 798 | } 799 | y = ((x) != 0); 800 | y = PB_MAX(ARGCOUNT(5), (double)3, (double) 10, (double) -2, (double) 15+4, (double) 23); 801 | y = abs(-1)+tan(sin(2.5)+cos(3.5))+exp(1)+exp2(5)+log(5)+log2(5)+log10(5)+ceil(5); 802 | 803 | MyVar = -1 + 0 + 1.0F + 1.2F + 1.5 + 2.0 + 2.5 + 3 + 3 + 4 + 4L + 4L + 5U; 804 | i = 0x1A + 0x1B + 0x1CL; 805 | 806 | swap(x, y); 807 | 808 | return _ReturnValue; 809 | } 810 | 811 | // Console routines 812 | int PBConsoleTest() 813 | { 814 | int _ReturnValue = int(); 815 | 816 | cout << "PB Semicolon at the end = No new line. "; 817 | cout << "No semicolon = New Line at the end." << endl; 818 | 819 | return _ReturnValue; 820 | } 821 | 822 | // Test for the PRINT function 823 | void PrintTest() 824 | { 825 | int a = int(); // Implicit 826 | UCHAR b = UCHAR(); // Implicit 827 | int c = int(); // Implicit 828 | int d = int(); // Implicit 829 | int e = int(); // Implicit 830 | int f = int(); // Implicit 831 | 832 | cout << endl; 833 | cout << a << endl; 834 | cout << PZONE << a; 835 | cout << a; 836 | cout << a << endl; // My comment 837 | cout << PZONE << a; 838 | cout << endl << endl; // Print 839 | cout << endl << endl << endl << endl; 840 | cout << a << endl << b << endl << c << endl << d << endl; 841 | cout << PZONE << a << PZONE << b; 842 | cout << PZONE << "" << a << endl << PZONE << b << c << PZONE << d << e << endl; 843 | cout << PZONE << "" << a << endl; 844 | cout << PZONE << "" << PZONE << a << b << endl; 845 | cout << PZONE << "" << PZONE << "" << PZONE << a << PZONE << b; 846 | cout << PZONE << "" << PZONE << "" << PZONE << "" << PZONE << "" << a << endl; 847 | cout << PZONE << "" << PZONE << a << PZONE << "" << PZONE << ""; 848 | cout << PZONE << "" << PZONE << a << PZONE << "" << PZONE << "" << "" << endl; 849 | cout << a << PZONE << b << c << PZONE << d << e << PZONE << f; 850 | cout << a << b << PZONE << c << d << endl; 851 | } 852 | 853 | // Test for implicit variable defs 854 | short ImplicitVar(int x) 855 | { 856 | short _ReturnValue = short(); 857 | __int64 b1 = __int64(); // Implicit 858 | int b2 = int(); // Implicit 859 | short b3 = short(); // Implicit 860 | UCHAR b4 = UCHAR(); // Implicit 861 | USHORT b5 = USHORT(); // Implicit 862 | unsigned b6 = unsigned(); // Implicit 863 | float b7 = float(); // Implicit 864 | double B8 = double(); // Implicit 865 | EXTENDED B9 = EXTENDED(); // Implicit 866 | short i = short(); // Implicit 867 | int LastNum = int(); // Implicit 868 | float OtherValue = float(); // Implicit 869 | string text = string(); // Implicit 870 | 871 | for (x=1; x<=10; x += 1) { 872 | i = x * 10; 873 | text = PB_STR(i+x); 874 | } 875 | LastNum = x-1; 876 | MyValue = x/i; // Note: MyValue! was defined already as global 877 | OtherValue = i/x; 878 | b1 = b2 + b3 + b4 + b5 + b6 + b7 + B8 + B9; 879 | 880 | return _ReturnValue; 881 | } 882 | 883 | // Test for optional args (default parameters are set in the prototype section at the top) 884 | void OptionalArgs(int a, string b, double c, int *d, string text) 885 | { 886 | // Do things 887 | } 888 | 889 | // Test for optional args (default parameters are set in the prototype section at the top) 890 | float OptionalArgs2(int a, string b, double c, int *d) 891 | { 892 | float _ReturnValue = float(); 893 | 894 | // Do things 895 | 896 | return _ReturnValue; 897 | } 898 | 899 | // Test for optional args (default parameters are set in the prototype section at the top) 900 | float OptionalArgs3(int a, string b, double c, int d) 901 | { 902 | float _ReturnValue = float(); 903 | 904 | // Do things 905 | 906 | return _ReturnValue; 907 | } 908 | 909 | std::vector g1; 910 | unsigned g2 = unsigned(); 911 | unsigned g3 = unsigned(); 912 | unsigned g4 = unsigned(); 913 | 914 | void MultiDim() 915 | { 916 | int *a; 917 | int *b; 918 | int *c; 919 | int *d; 920 | static string s1 = string(); 921 | static std::vector s2; 922 | static string s3 = string(); 923 | static string s4 = string(); 924 | //+++ Static s1, s2[10], s3, s4 As String 925 | // Do things 926 | } 927 | 928 | // PowerBASIC allows you to pass an expression as a function arg even if it's defined ByRef 929 | // whereas C++ expects the arg to be an lvalue (such as a variable of the exact parameter type). 930 | // TestByRef() below tests the conversion transform from implicit-convert.uc, which uses the 931 | // the lvalue() template defined in pbmisc.h. 932 | 933 | void TestByRef() 934 | { 935 | short i = short(); // Implicit 936 | 937 | // Args for TestFunc (defined earlier) are all passed by reference 938 | // TestFunc(a As Long, b As Byte, c As Long, i As Integer, s As String, n As Single) 939 | 940 | int VarLong = int(); 941 | UCHAR VarByte = UCHAR(); 942 | short VarInt = short(); 943 | string VarString = string(); 944 | float VarSingle = float(); 945 | 946 | i = TestFunc(VarLong, VarByte, VarLong, VarInt, VarString, VarSingle); 947 | i = TestFunc(lvalue(int((VarLong))), lvalue(UCHAR((VarByte))), lvalue(int((VarLong))), lvalue(short((VarInt))), lvalue(string((VarString))), lvalue(float((VarSingle)))); 948 | i = TestFunc(lvalue(int(VarLong+0)), lvalue(UCHAR(VarByte+0)), lvalue(int(VarLong+0)), lvalue(short(VarInt+0)), lvalue(string(VarString+"")), lvalue(float(VarSingle+0))); 949 | i = TestFunc(lvalue(int(1)), lvalue(UCHAR(2)), lvalue(int(3)), lvalue(short(4)), lvalue(string("Test")), lvalue(float(5))); 950 | i = TestFunc(lvalue(int(__int64(1+50/7)-5)), lvalue(UCHAR(2+1)), lvalue(int(_round(3*50 / i))), lvalue(short(4-8)), lvalue(string(PB_LEFT("Test", 2))), lvalue(float(8+3/2))); 951 | } 952 | -------------------------------------------------------------------------------- /test/old/AfterBeautify.cpp: -------------------------------------------------------------------------------- 1 | // This is improperly intended code 2 | // Beautify.uc will fix this 3 | 4 | const int MyEquate = 0x100; 5 | const int Other = 0x200; 6 | 7 | long ProgStatus; 8 | 9 | #if defined Other 10 | // Something 11 | #elif !defined abcd 12 | // Something else 13 | #else 14 | // Etc 15 | #endif 16 | 17 | struct point { 18 | long x; 19 | long y; 20 | } 21 | 22 | long MyFunction(long a, float& b) 23 | { 24 | long x; 25 | long y; 26 | long *Test = new long [a+25+1]; 27 | long yVar; 28 | 29 | // Dim q As Long 30 | // I don't want the commented line above to be translated 31 | 32 | MySub(a); 33 | x = MySub(b)+1; 34 | printf("Hello world"); 35 | 36 | if (b > 5) { 37 | for (x=1; x<=10; x += 1) { 38 | for (yVar=10; yVar>=1; yVar += -1) { 39 | if (x > y) { 40 | return a+y; 41 | } 42 | if (y < MyEquate) { 43 | return Test[x-y]*10; 44 | } 45 | } 46 | } 47 | } 48 | 49 | delete[] Test; 50 | } 51 | 52 | void MySub(long x) 53 | { 54 | long y; 55 | long *Test; 56 | float *Number = new float [10+1]; 57 | long *Other = new long [x+1]; 58 | long z; 59 | 60 | ProgStatus = 10; 61 | y = x + 1; 62 | z = y+x; 63 | Other[x] = x+1; 64 | 65 | while (x < 10) { 66 | y = MyFunction(x, 10.5); 67 | Test = &x; 68 | Number[z] = *Test + Other[5+x]; 69 | x = x+1; 70 | } 71 | 72 | if (x > 5) { 73 | y = 10; 74 | z = 5+x; 75 | } else { 76 | y=y+1; 77 | z=x-1; 78 | } 79 | 80 | delete[] Other; 81 | delete[] Other; 82 | } 83 | -------------------------------------------------------------------------------- /test/old/BeforeBeautify.cpp: -------------------------------------------------------------------------------- 1 | // This is improperly intended code 2 | // Beautify.uc will fix this 3 | 4 | const int MyEquate = 0x100; 5 | const int Other = 0x200; 6 | 7 | long ProgStatus; 8 | 9 | #if defined Other 10 | // Something 11 | #elif !defined abcd 12 | // Something else 13 | #else 14 | // Etc 15 | #endif 16 | 17 | struct point { 18 | 19 | long x; 20 | long y; 21 | 22 | } 23 | 24 | long MyFunction(long a, float& b) { 25 | long x; 26 | long y; 27 | long *Test = new long [a+25+1]; 28 | long yVar; 29 | 30 | // Dim q As Long 31 | // I don't want the commented line above to be translated 32 | 33 | MySub(a); 34 | x = MySub(b)+1; printf("Hello world"); 35 | 36 | if (b > 5) { 37 | for (x=1; x<=10; x += 1) { 38 | for (yVar=10; yVar>=1; yVar += -1) { 39 | if (x > y) { return a+y;} 40 | if (y < MyEquate) { return Test[x-y]*10;} 41 | 42 | } 43 | 44 | } 45 | 46 | } 47 | 48 | delete[] Test; 49 | } 50 | 51 | void MySub(long x) { 52 | long y; 53 | long *Test; 54 | float *Number = new float [10+1]; 55 | long *Other = new long [x+1]; 56 | long z; 57 | 58 | ProgStatus = 10; 59 | y = x + 1 ; z = y+x ; Other[x] = x+1; 60 | 61 | while (x < 10) { 62 | y = MyFunction(x, 10.5); 63 | Test = &x; 64 | Number[z] = *Test + Other[5+x]; 65 | x = x+1; 66 | 67 | } 68 | 69 | if (x > 5) { y = 10; z = 5+x; } else {y=y+1; z=x-1;} 70 | 71 | delete[] Other; 72 | delete[] Other; 73 | } 74 | -------------------------------------------------------------------------------- /test/old/SamplePBcode.Bas: -------------------------------------------------------------------------------- 1 | ' This is sample code 2 | ' Note: proper indentation might be handled in a separate transform 3 | 4 | %MyEquate = &h100 5 | %Other = &h200 6 | 7 | Global ProgStatus As Long 8 | 9 | #If %Def(%Other) 10 | ' Something 11 | #ElseIf Not %Def(%abcd) 12 | ' Something else 13 | #Else 14 | ' Etc 15 | #EndIf 16 | 17 | Type point 18 | x As Long 19 | y As Long 20 | End Type 21 | 22 | Type MyBits 23 | Year As Bit * 7 In Dword 24 | Month As Bit * 5 25 | DayOfMonth As Bit * 4 26 | DayOfWeek As Bit * 3 27 | Red As Bit * 1 In Byte 28 | Blue As Bit * 1 29 | Green As Bit * 1 30 | Other As Double 31 | End Type 32 | 33 | Function PBMain() As Long 34 | ' Do things 35 | End Function 36 | 37 | Function MyFunc(ByVal x As Long) As Long 38 | Function = x + 1 39 | End Function 40 | 41 | Function MyFunction(ByVal a As Long, ByRef b As Single) As Long 42 | Dim x As Long, y As Long, Test(a+25) As Long 43 | Dim yVar As Long, MyValue& 44 | ' Dim q As Long 45 | ' Commented line above does not get translated 46 | 47 | MySub(a) 48 | x = MyFunc(b)+1 49 | 50 | If b > 5 Then 51 | For x = 1 To 10 52 | For yVar = 10 To 1 Step -1 53 | If x > y Then Function = a+y 54 | Do While Test(a+5) = yVar 55 | Do Until a+1 = 1234 56 | If y < %MyEquate Then Function = Test(x-y)*10 57 | a = a + 1 58 | Do 59 | b = a * 5 + b 60 | Loop Until b = 300 61 | Loop 62 | Loop 63 | Next 64 | Next 65 | End If 66 | End Function 67 | 68 | Sub MySub(ByVal x As Long) 69 | Local y As Long, Test As Long Ptr 70 | Dim Number(10) As Single, Other(x) As Long 71 | Register z As Long 72 | 73 | ProgStatus = 10 74 | y = x + 1 : z = y+x : Other(x) = x+1 75 | 76 | While x < 10 77 | y = MyFunction(x, 10.5) 78 | Test = VarPtr(x) 79 | Number(z) = @Test + Other(5+x) 80 | x = x+1 81 | Wend 82 | End Sub 83 | 84 | Sub TestCertainOperators(ByVal x As Long, _ ' This line is broken up using a _ (underscore) 85 | ByVal y As Long, _ This is a commment (even without ') 86 | ByVal z As Long, _ 87 | ByRef OtherVar As Double, _ Everything after _ is a comment 88 | ByVal FinalArg As Single Ptr _ 89 | ) 90 | 91 | Dim MyArray(10) As Long, MyPoint As Point, pp As Point Ptr, n As Long 92 | 93 | For x = 1 To 10 94 | n = y = z ' This works differently in PB than in C++ 95 | MyArray(x) = x*2 96 | If x = 5 Then y = x+5 Else y = 23*2 97 | y = x = z : MyArray(5) = MyArray(n) = MyArray(n+1) 98 | If x = y = z Then y = n = 2 Else y = n = 3 99 | If x = y And x <> 10 Or y = x And x < 25 Then y = x Or y = z 100 | If (x = y And x <> 10 Or y = x And x < 25) Then y = x Or y = z 101 | If (x = y And x <> 10) Or y = x And x < 25 Then y = x Or y = z 102 | If Not(x = y Or x = z) Then x = y + 10 103 | If Not(x = y Or x = z) Then x = y + 10 104 | 105 | If x <> y Then MyPoint.x = y Else MyPoint.x = x 106 | 107 | pp = VarPtr(MyPoint) 108 | MyPoint.x = MyPoint.y+1 109 | n = MyPoint.x = MyPoint.y 110 | @pp.x = @pp.y = @pp.x+1 111 | Next 112 | End Sub 113 | -------------------------------------------------------------------------------- /test/old/parenth.bas: -------------------------------------------------------------------------------- 1 | '#Include "Win32API.inc" 2 | Declare Function ShellExecute Lib "SHELL32.DLL" Alias "ShellExecuteA" (ByVal hwnd As Dword, lpOperation As Asciiz, lpFile As Asciiz, lpParameters As Asciiz, lpDirectory As Asciiz, ByVal nShowCmd As Long) As Dword 3 | Declare Function SetCursorPos Lib "USER32.DLL" Alias "SetCursorPos" (ByVal x As Long, ByVal y As Long) As Long 4 | Declare Sub SetLastError Lib "KERNEL32.DLL" Alias "SetLastError" (ByVal dwErrCode As Dword) 5 | 6 | Sub DoSomething(ByVal Arg1 As Long, ByRef txt$, Number##, Optional ByVal xyz As Dword Ptr) 7 | SetCursorPos 10, Arg1 + 5 8 | If Arg1 = 15 Then SetLastError 123 9 | End Sub 10 | 11 | Function PBMain() 12 | Dim x As Ext, pi As Ext 13 | DoSomething Len("Test")+5, "Hello " + "world!", Sin(x+1)*pi, VarPtr(x)-4 ' Comment 14 | 15 | DoSomething 10, "abc", 5, 1 : DoSomething 1, "x", 5, 0 ' Etc... 16 | 17 | If x > 1 Then DoSomething(1, "x", 5, 0) ' Parenthesis already here 18 | 19 | ShellExecute 0, "Open", "ReadMe.Txt", $Nul, $Nul, %SW_ShowNormal 20 | End Function 21 | -------------------------------------------------------------------------------- /test/old/typespecifiers.bas: -------------------------------------------------------------------------------- 1 | DefLng a-z 2 | DefByt b 3 | DefInt i 4 | DefStr s 5 | DefQud q 6 | DefSng n-p, x-z 7 | 8 | Global MyValue!, Label$, Price@, ExtVal##, qNum&& 9 | 10 | Function Test(a, b, c, i, s, n) 11 | Print MyValue!, Label$, Price@ 12 | End Function 13 | 14 | Function Report$(LastName$, ByVal x&, ByRef NewPrice@, n, ByVal i, nValue, qValue) 15 | Dim FirstName$, Age?, Total@ 16 | Static Index& 17 | 18 | Print LastName$, x&, NewPrice@, n, i, nValue, qValue 19 | Report$ = FirstName$ + LastName$ 20 | End Function 21 | 22 | Function Hello(txt$) As String 23 | Print txt$ 24 | Function = txt$ + " friend!" 25 | End Function 26 | 27 | Function Bye() 28 | Print "Bye" 29 | End Function 30 | -------------------------------------------------------------------------------- /test/old/uCalc.bas: -------------------------------------------------------------------------------- 1 | Function MyFunction(ByVal a As Long, ByRef b As Single) As Long 2 | Dim x As Long, y As Long 3 | Dim yVar As Long 4 | 5 | If b > 5 Then 6 | For x = 1 To 10 7 | For yVar = 10 To 1 Step -1 8 | If x > y then Function = a+y 9 | Next 10 | Next 11 | End If 12 | End Function 13 | -------------------------------------------------------------------------------- /test/old/uCalc.cpp: -------------------------------------------------------------------------------- 1 | long MyFunction(long a, float& b) { 2 | long x; 3 | long y; 4 | long yVar; 5 | 6 | if (b > 5) { 7 | for (x=1; x<=10; x += 1) { 8 | for (yVar=10; yVar>=1; x += -1) { 9 | if (x > y) { return a+y; } 10 | } 11 | } 12 | } 13 | } 14 | --------------------------------------------------------------------------------