BlankPage: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
(Replaced content with "{{DISPLAYTITLE:_BlankPage}} The '''_BlankPage''' serves as a skeleton for new Wiki pages. {{PageSyntax}} : _BlankSub {{Parameter|arg1}}[, {{Parameter|arg2}}] : {{Parameter|result%}} = _BlankFunc({{Parameter|arg1}}[, {{Parameter|arg2}}]) {{PageParameters}} * {{Parameter|arg1}} is a mandatory argument * the {{Parameter|arg2}} is optional {{PageDescription}} To use this skeleton click on the '''Edit''' tab above the page, then copy the raw text of this pag...")
Tags: Replaced Manual revert
No edit summary
Tag: Reverted
Line 96: Line 96:


{{PageNavigation}}
{{PageNavigation}}
{{CodeStart}}
{{Text|<nowiki>'+---------------+---------------------------------------------------+</nowiki>|#31C4C4}}
{{Text|<nowiki>'| ###### ###### |    .--. .        .-.                            |</nowiki>|#31C4C4}}
{{Text|<nowiki>'| ##  ## ##  # |    |  )|        (  ) o                        |</nowiki>|#31C4C4}}
{{Text|<nowiki>'| ##  ##  ##    |    |--' |--. .-.  `-.  .  .-...--.--. .-.        |</nowiki>|#31C4C4}}
{{Text|<nowiki>'| ######  ##  |    |  \ |  |(  )(  ) | (  ||  |  |(  )      |</nowiki>|#31C4C4}}
{{Text|<nowiki>'| ##      ##    |    '  `'  `-`-'  `-'-' `-`-`|'  '  `-`-'`-      |</nowiki>|#31C4C4}}
{{Text|<nowiki>'| ##    ##  # |                            ._.'                  |</nowiki>|#31C4C4}}
{{Text|<nowiki>'| ##    ###### |  Sources & Documents placed in the Public Domain. |</nowiki>|#31C4C4}}
{{Text|<nowiki>'+---------------+---------------------------------------------------+</nowiki>|#31C4C4}}
{{Text|<nowiki>'|                                                                  |</nowiki>|#31C4C4}}
{{Text|<nowiki>'| === MakeCARR.bas ===                                              |</nowiki>|#31C4C4}}
{{Text|<nowiki>'|                                                                  |</nowiki>|#31C4C4}}
{{Text|<nowiki>'| == Create a C/C++ array out of the given file, so you can embed  |</nowiki>|#31C4C4}}
{{Text|<nowiki>'| == it in your program and write it back when needed.              |</nowiki>|#31C4C4}}
{{Text|<nowiki>'|                                                                  |</nowiki>|#31C4C4}}
{{Text|<nowiki>'| == Two files are created, the .h file, which contains the array(s)|</nowiki>|#31C4C4}}
{{Text|<nowiki>'| == and some functions, and a respective .bm file which needs to  |</nowiki>|#31C4C4}}
{{Text|<nowiki>'| == be $INCLUDEd with your program and does provide the FUNCTION  |</nowiki>|#31C4C4}}
{{Text|<nowiki>'| == to write back the array(s) into any file. All used functions  |</nowiki>|#31C4C4}}
{{Text|<nowiki>'| == are standard library calls, no API calls are involved, so the  |</nowiki>|#31C4C4}}
{{Text|<nowiki>'| == writeback should work on all QB64 supported platforms.        |</nowiki>|#31C4C4}}
{{Text|<nowiki>'|                                                                  |</nowiki>|#31C4C4}}
{{Text|<nowiki>'| == Make sure to adjust the path for the .h file for your personal |</nowiki>|#31C4C4}}
{{Text|<nowiki>'| == needs in the created .bm files (DECLARE LIBRARY), if required. |</nowiki>|#31C4C4}}
{{Text|<nowiki>'| == You may specify default paths right below this header.        |</nowiki>|#31C4C4}}
{{Text|<nowiki>'|                                                                  |</nowiki>|#31C4C4}}
{{Text|<nowiki>'| == This program needs the 'lzwpacker.bm' file available from the  |</nowiki>|#31C4C4}}
{{Text|<nowiki>'| == Libraries Collection here:                                    |</nowiki>|#31C4C4}}
{{Text|<nowiki>'| ==      http://qb64phoenix.com/forum/forumdisplay.php?fid=23      |</nowiki>|#31C4C4}}
{{Text|<nowiki>'| == as it will try to pack the given file to keep the array(s) as  |</nowiki>|#31C4C4}}
{{Text|<nowiki>'| == small as possible. If compression is successful, then your    |</nowiki>|#31C4C4}}
{{Text|<nowiki>'| == program also must $INCLUDE 'lzwpacker.bm' to be able to unpack |</nowiki>|#31C4C4}}
{{Text|<nowiki>'| == the file data again for write back. MakeCARR.bas is printing  |</nowiki>|#31C4C4}}
{{Text|<nowiki>'| == a reminder message in such a case.                            |</nowiki>|#31C4C4}}
{{Text|<nowiki>'|                                                                  |</nowiki>|#31C4C4}}
{{Text|<nowiki>'+-------------------------------------------------------------------+</nowiki>|#31C4C4}}
{{Text|<nowiki>'| Done by RhoSigma, R.Heyder, provided AS IS, use at your own risk. |</nowiki>|#31C4C4}}
{{Text|<nowiki>'| Find me in the QB64 Forum or mail to support@rhosigma-cw.net for  |</nowiki>|#31C4C4}}
{{Text|<nowiki>'| any questions or suggestions. Thanx for your interest in my work. |</nowiki>|#31C4C4}}
{{Text|<nowiki>'+-------------------------------------------------------------------+</nowiki>|#31C4C4}}
{{Text|<nowiki>'--- if you wish, set any default paths, end with a backslash ---</nowiki>|#31C4C4}}
srcPath$ = {{Text|<nowiki>""</nowiki>|#FFB100}} {{Text|<nowiki>'source path</nowiki>|#31C4C4}}
tarPath$ = {{Text|<nowiki>""</nowiki>|#FFB100}} {{Text|<nowiki>'target path</nowiki>|#31C4C4}}
{{Text|<nowiki>'-----</nowiki>|#31C4C4}}
{{Text|IF|#F0F0F0}} srcPath$ <> {{Text|<nowiki>""</nowiki>|#FFB100}} {{Text|THEN|#F0F0F0}}
    {{Text|COLOR|#F0F0F0}} {{Text|15|#F580B1}}: {{Text|PRINT|#F0F0F0}} {{Text|<nowiki>"Default source path: "</nowiki>|#FFB100}}: {{Text|COLOR|#F0F0F0}} {{Text|7|#F580B1}}: {{Text|PRINT|#F0F0F0}} srcPath$: {{Text|PRINT|#F0F0F0}}
{{Text|END|#F0F0F0}} {{Text|IF|#F0F0F0}}
{{Text|IF|#F0F0F0}} tarPath$ <> {{Text|<nowiki>""</nowiki>|#FFB100}} {{Text|THEN|#F0F0F0}}
    {{Text|COLOR|#F0F0F0}} {{Text|15|#F580B1}}: {{Text|PRINT|#F0F0F0}} {{Text|<nowiki>"Default target path: "</nowiki>|#FFB100}}: {{Text|COLOR|#F0F0F0}} {{Text|7|#F580B1}}: {{Text|PRINT|#F0F0F0}} tarPath$: {{Text|PRINT|#F0F0F0}}
{{Text|END|#F0F0F0}} {{Text|IF|#F0F0F0}}
{{Text|<nowiki>'--- collect inputs (relative paths allowed, based on default paths) ---</nowiki>|#31C4C4}}
source:
{{Text|LINE|#F0F0F0}} {{Text|INPUT|#F0F0F0}} {{Text|<nowiki>"Source Filename: "</nowiki>|#FFB100}}; src$ {{Text|<nowiki>'any file you want to put into a C/C++ array</nowiki>|#31C4C4}}
{{Text|IF|#F0F0F0}} src$ = {{Text|<nowiki>""</nowiki>|#FFB100}} {{Text|GOTO|#F0F0F0}} source
target:
{{Text|LINE|#F0F0F0}} {{Text|INPUT|#F0F0F0}} {{Text|<nowiki>"Target Basename: "</nowiki>|#FFB100}}; tar$ {{Text|<nowiki>'write stuff into this file(s) (.h/.bm is added)</nowiki>|#31C4C4}}
{{Text|IF|#F0F0F0}} tar$ = {{Text|<nowiki>""</nowiki>|#FFB100}} {{Text|GOTO|#F0F0F0}} target
{{Text|<nowiki>'-----</nowiki>|#31C4C4}}
{{Text|ON|#F0F0F0}} {{Text|ERROR|#F0F0F0}} {{Text|GOTO|#F0F0F0}} abort
{{Text|OPEN|#F0F0F0}} {{Text|<nowiki>"I"</nowiki>|#FFB100}}, #1, srcPath$ + src$: {{Text|CLOSE|#F0F0F0}} #1 {{Text|<nowiki>'file exist check</nowiki>|#31C4C4}}
{{Text|OPEN|#F0F0F0}} {{Text|<nowiki>"O"</nowiki>|#FFB100}}, #2, tarPath$ + tar$ + {{Text|<nowiki>".bm"</nowiki>|#FFB100}}: {{Text|CLOSE|#F0F0F0}} #2 {{Text|<nowiki>'path exist check</nowiki>|#31C4C4}}
{{Text|ON|#F0F0F0}} {{Text|ERROR|#F0F0F0}} {{Text|GOTO|#F0F0F0}} {{Text|0|#F580B1}}
{{Text|<nowiki>'--- separate source filename part ---</nowiki>|#31C4C4}}
{{Text|FOR|#F0F0F0}} po% = {{Text|LEN|#F0F0F0}}(src$) {{Text|TO|#F0F0F0}} {{Text|1|#F580B1}} {{Text|STEP|#F0F0F0}} {{Text|-1|#F580B1}}
    {{Text|IF|#F0F0F0}} {{Text|MID$|#F0F0F0}}(src$, po%, {{Text|1|#F580B1}}) = {{Text|<nowiki>"\"</nowiki>|#FFB100}} {{Text|OR|#F0F0F0}} {{Text|MID$|#F0F0F0}}(src$, po%, {{Text|1|#F580B1}}) = {{Text|<nowiki>"/"</nowiki>|#FFB100}} {{Text|THEN|#F0F0F0}}
        srcName$ = {{Text|MID$|#F0F0F0}}(src$, po% + {{Text|1|#F580B1}})
        {{Text|EXIT|#F0F0F0}} {{Text|FOR|#F0F0F0}}
    {{Text|ELSEIF|#F0F0F0}} po% = {{Text|1|#F580B1}} {{Text|THEN|#F0F0F0}}
        srcName$ = src$
    {{Text|END|#F0F0F0}} {{Text|IF|#F0F0F0}}
{{Text|NEXT|#F0F0F0}} po%
{{Text|<nowiki>'--- separate target filename part ---</nowiki>|#31C4C4}}
{{Text|FOR|#F0F0F0}} po% = {{Text|LEN|#F0F0F0}}(tar$) {{Text|TO|#F0F0F0}} {{Text|1|#F580B1}} {{Text|STEP|#F0F0F0}} {{Text|-1|#F580B1}}
    {{Text|IF|#F0F0F0}} {{Text|MID$|#F0F0F0}}(tar$, po%, {{Text|1|#F580B1}}) = {{Text|<nowiki>"\"</nowiki>|#FFB100}} {{Text|OR|#F0F0F0}} {{Text|MID$|#F0F0F0}}(tar$, po%, {{Text|1|#F580B1}}) = {{Text|<nowiki>"/"</nowiki>|#FFB100}} {{Text|THEN|#F0F0F0}}
        tarName$ = {{Text|MID$|#F0F0F0}}(tar$, po% + {{Text|1|#F580B1}})
        {{Text|EXIT|#F0F0F0}} {{Text|FOR|#F0F0F0}}
    {{Text|ELSEIF|#F0F0F0}} po% = {{Text|1|#F580B1}} {{Text|THEN|#F0F0F0}}
        tarName$ = tar$
    {{Text|END|#F0F0F0}} {{Text|IF|#F0F0F0}}
{{Text|NEXT|#F0F0F0}} po%
{{Text|MID$|#F0F0F0}}(tarName$, {{Text|1|#F580B1}}, {{Text|1|#F580B1}}) = {{Text|UCASE$|#F0F0F0}}({{Text|MID$|#F0F0F0}}(tarName$, {{Text|1|#F580B1}}, {{Text|1|#F580B1}})) {{Text|<nowiki>'capitalize 1st letter</nowiki>|#31C4C4}}
{{Text|<nowiki>'---------------------------------------------------------------------</nowiki>|#31C4C4}}
{{Text|<nowiki>' Depending on the source file's size, one or more array(s) are</nowiki>|#31C4C4}}
{{Text|<nowiki>' created. This is because some C/C++ compilers seem to have problems</nowiki>|#31C4C4}}
{{Text|<nowiki>' with arrays with more than 65535 elements. This does not affect the</nowiki>|#31C4C4}}
{{Text|<nowiki>' write back, as the write function will take this behavior into account.</nowiki>|#31C4C4}}
{{Text|<nowiki>'---------------------------------------------------------------------</nowiki>|#31C4C4}}
{{Text|<nowiki>'--- init ---</nowiki>|#31C4C4}}
{{Text|OPEN|#F0F0F0}} {{Text|<nowiki>"B"</nowiki>|#FFB100}}, #1, srcPath$ + src$
filedata$ = {{Text|SPACE$|#F0F0F0}}({{Text|LOF|#F0F0F0}}({{Text|1|#F580B1}}))
{{Text|GET|#F0F0F0}} #1, , filedata$
{{Text|CLOSE|#F0F0F0}} #1
rawdata$ = LzwPack$(filedata$, {{Text|20|#F580B1}})
{{Text|IF|#F0F0F0}} rawdata$ <> {{Text|<nowiki>""</nowiki>|#FFB100}} {{Text|THEN|#F0F0F0}}
    {{Text|OPEN|#F0F0F0}} {{Text|<nowiki>"O"</nowiki>|#FFB100}}, #1, tarPath$ + tar$ + {{Text|<nowiki>".lzw"</nowiki>|#FFB100}}
    {{Text|CLOSE|#F0F0F0}} #1
    {{Text|OPEN|#F0F0F0}} {{Text|<nowiki>"B"</nowiki>|#FFB100}}, #1, tarPath$ + tar$ + {{Text|<nowiki>".lzw"</nowiki>|#FFB100}}
    {{Text|PUT|#F0F0F0}} #1, , rawdata$
    {{Text|CLOSE|#F0F0F0}} #1
    packed% = {{Text|-1|#F580B1}}
    {{Text|OPEN|#F0F0F0}} {{Text|<nowiki>"B"</nowiki>|#FFB100}}, #1, tarPath$ + tar$ + {{Text|<nowiki>".lzw"</nowiki>|#FFB100}}
{{Text|ELSE|#F0F0F0}}
    packed% = {{Text|0|#F580B1}}
    {{Text|OPEN|#F0F0F0}} {{Text|<nowiki>"B"</nowiki>|#FFB100}}, #1, srcPath$ + src$
{{Text|END|#F0F0F0}} {{Text|IF|#F0F0F0}}
fl& = {{Text|LOF|#F0F0F0}}({{Text|1|#F580B1}})
cntL& = {{Text|INT|#F0F0F0}}(fl& / {{Text|32|#F580B1}})
cntV& = {{Text|INT|#F0F0F0}}(cntL& / {{Text|8180|#F580B1}})
cntB& = (fl& - (cntL& * {{Text|32|#F580B1}}))
{{Text|<nowiki>'--- .h include file ---</nowiki>|#31C4C4}}
{{Text|OPEN|#F0F0F0}} {{Text|<nowiki>"O"</nowiki>|#FFB100}}, #2, tarPath$ + tar$ + {{Text|<nowiki>".h"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"// ============================================================"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"// === This file was created with MakeCARR.bas by RhoSigma, ==="</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"// === use it in conjunction with its respective .bm file.  ==="</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"// ============================================================"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>""</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"// --- Array(s) representing the contents of file "</nowiki>|#FFB100}}; srcName$
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"// ---------------------------------------------------------------------"</nowiki>|#FFB100}}
{{Text|<nowiki>'--- read LONGs ---</nowiki>|#31C4C4}}
tmpI$ = {{Text|SPACE$|#F0F0F0}}({{Text|32|#F580B1}})
{{Text|FOR|#F0F0F0}} vc& = {{Text|0|#F580B1}} {{Text|TO|#F0F0F0}} cntV&
    {{Text|IF|#F0F0F0}} vc& = cntV& {{Text|THEN|#F0F0F0}} numL& = (cntL& {{Text|MOD|#F0F0F0}} {{Text|8180|#F580B1}}): {{Text|ELSE|#F0F0F0}} numL& = {{Text|8180|#F580B1}}
    {{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"static const uint32_t "</nowiki>|#FFB100}}; tarName$; {{Text|<nowiki>"L"</nowiki>|#FFB100}}; {{Text|LTRIM$|#F0F0F0}}({{Text|STR$|#F0F0F0}}(vc&)); {{Text|<nowiki>"[] = {"</nowiki>|#FFB100}}
    {{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"    "</nowiki>|#FFB100}}; {{Text|LTRIM$|#F0F0F0}}({{Text|STR$|#F0F0F0}}(numL& * {{Text|8|#F580B1}})); {{Text|<nowiki>","</nowiki>|#FFB100}}
    {{Text|FOR|#F0F0F0}} z& = {{Text|1|#F580B1}} {{Text|TO|#F0F0F0}} numL&
        {{Text|GET|#F0F0F0}} #1, , tmpI$: offI% = {{Text|1|#F580B1}}
        tmpO$ = {{Text|<nowiki>"    "</nowiki>|#FFB100}} + {{Text|STRING$|#F0F0F0}}({{Text|88|#F580B1}}, {{Text|<nowiki>","</nowiki>|#FFB100}}): offO% = {{Text|5|#F580B1}}
        {{Text|DO|#F0F0F0}}
            tmpL& = {{Text|CVL|#F0F0F0}}({{Text|MID$|#F0F0F0}}(tmpI$, offI%, {{Text|4|#F580B1}})): offI% = offI% + {{Text|4|#F580B1}}
            {{Text|MID$|#F0F0F0}}(tmpO$, offO%, {{Text|10|#F580B1}}) = {{Text|<nowiki>"0x"</nowiki>|#FFB100}} + {{Text|RIGHT$|#F0F0F0}}({{Text|<nowiki>"00000000"</nowiki>|#FFB100}} + {{Text|HEX$|#F0F0F0}}(tmpL&), {{Text|8|#F580B1}})
            offO% = offO% + {{Text|11|#F580B1}}
        {{Text|LOOP|#F0F0F0}} {{Text|UNTIL|#F0F0F0}} offO% > {{Text|92|#F580B1}}
        {{Text|IF|#F0F0F0}} z& < numL& {{Text|THEN|#F0F0F0}} {{Text|PRINT|#F0F0F0}} #2, tmpO$: {{Text|ELSE|#F0F0F0}} {{Text|PRINT|#F0F0F0}} #2, {{Text|LEFT$|#F0F0F0}}(tmpO$, {{Text|91|#F580B1}})
    {{Text|NEXT|#F0F0F0}} z&
    {{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"};"</nowiki>|#FFB100}}
    {{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>""</nowiki>|#FFB100}}
{{Text|NEXT|#F0F0F0}} vc&
{{Text|<nowiki>'--- read remaining BYTEs ---</nowiki>|#31C4C4}}
{{Text|IF|#F0F0F0}} cntB& > {{Text|0|#F580B1}} {{Text|THEN|#F0F0F0}}
    {{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"static const uint8_t "</nowiki>|#FFB100}}; tarName$; {{Text|<nowiki>"B[] = {"</nowiki>|#FFB100}}
    {{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"    "</nowiki>|#FFB100}}; {{Text|LTRIM$|#F0F0F0}}({{Text|STR$|#F0F0F0}}(cntB&)); {{Text|<nowiki>","</nowiki>|#FFB100}}
    {{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"    "</nowiki>|#FFB100}};
    {{Text|FOR|#F0F0F0}} x% = {{Text|1|#F580B1}} {{Text|TO|#F0F0F0}} cntB&
        {{Text|GET|#F0F0F0}} #1, , tmpB%%
        {{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"0x"</nowiki>|#FFB100}} + {{Text|RIGHT$|#F0F0F0}}({{Text|<nowiki>"00"</nowiki>|#FFB100}} + {{Text|HEX$|#F0F0F0}}(tmpB%%), {{Text|2|#F580B1}});
        {{Text|IF|#F0F0F0}} x% <> {{Text|16|#F580B1}} {{Text|THEN|#F0F0F0}}
            {{Text|IF|#F0F0F0}} x% <> cntB& {{Text|THEN|#F0F0F0}} {{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>","</nowiki>|#FFB100}};
        {{Text|ELSE|#F0F0F0}}
            {{Text|IF|#F0F0F0}} x% <> cntB& {{Text|THEN|#F0F0F0}}
                {{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>","</nowiki>|#FFB100}}
                {{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"    "</nowiki>|#FFB100}};
            {{Text|END|#F0F0F0}} {{Text|IF|#F0F0F0}}
        {{Text|END|#F0F0F0}} {{Text|IF|#F0F0F0}}
    {{Text|NEXT|#F0F0F0}} x%
    {{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>""</nowiki>|#FFB100}}
    {{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"};"</nowiki>|#FFB100}}
    {{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>""</nowiki>|#FFB100}}
{{Text|END|#F0F0F0}} {{Text|IF|#F0F0F0}}
{{Text|<nowiki>'--- some functions ---</nowiki>|#31C4C4}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"// --- Saved full qualified output path and filename, so we've no troubles"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"// --- when cleaning up, even if the current working folder was changed"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"// --- during program runtime."</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"// ---------------------------------------------------------------------"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"char "</nowiki>|#FFB100}}; tarName$; {{Text|<nowiki>"Name[8192]; // it's a safe size for any current OS"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>""</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"// --- Cleanup function to delete the written file, called by the atexit()"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"// --- handler at program termination time, if requested by user."</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"// ---------------------------------------------------------------------"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"void Kill"</nowiki>|#FFB100}}; tarName$; {{Text|<nowiki>"Data(void)"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"{"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"    remove("</nowiki>|#FFB100}}; tarName$; {{Text|<nowiki>"Name);"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"}"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>""</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"// --- Function to write the array(s) back into a file, will return the"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"// --- full qualified output path and filename on success, otherwise an"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"// --- empty string is returned (access/write errors, file truncated)."</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"// ---------------------------------------------------------------------"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"const char *Write"</nowiki>|#FFB100}}; tarName$; {{Text|<nowiki>"Data(const char *FileName, int16_t AutoClean)"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"{"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"    FILE  *han = NULL; // file handle"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"    int32_t num = NULL; // written elements"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>""</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"    #ifdef QB64_WINDOWS"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"    if (!_fullpath("</nowiki>|#FFB100}}; tarName$; {{Text|<nowiki>"Name, FileName, 8192)) return "</nowiki>|#FFB100}}; {{Text|CHR$|#F0F0F0}}({{Text|34|#F580B1}}); {{Text|CHR$|#F0F0F0}}({{Text|34|#F580B1}}); {{Text|<nowiki>";"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"    #else"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"    if (!realpath(FileName, "</nowiki>|#FFB100}}; tarName$; {{Text|<nowiki>"Name)) return "</nowiki>|#FFB100}}; {{Text|CHR$|#F0F0F0}}({{Text|34|#F580B1}}); {{Text|CHR$|#F0F0F0}}({{Text|34|#F580B1}}); {{Text|<nowiki>";"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"    #endif"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>""</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"    if (!(han = fopen("</nowiki>|#FFB100}}; tarName$; {{Text|<nowiki>"Name, "</nowiki>|#FFB100}}; {{Text|CHR$|#F0F0F0}}({{Text|34|#F580B1}}); {{Text|<nowiki>"wb"</nowiki>|#FFB100}}; {{Text|CHR$|#F0F0F0}}({{Text|34|#F580B1}}); {{Text|<nowiki>"))) return "</nowiki>|#FFB100}}; {{Text|CHR$|#F0F0F0}}({{Text|34|#F580B1}}); {{Text|CHR$|#F0F0F0}}({{Text|34|#F580B1}}); {{Text|<nowiki>";"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"    if (AutoClean) atexit(Kill"</nowiki>|#FFB100}}; tarName$; {{Text|<nowiki>"Data);"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>""</nowiki>|#FFB100}}
{{Text|FOR|#F0F0F0}} vc& = {{Text|0|#F580B1}} {{Text|TO|#F0F0F0}} cntV&
    {{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"    num = fwrite(&"</nowiki>|#FFB100}}; tarName$; {{Text|<nowiki>"L"</nowiki>|#FFB100}}; {{Text|LTRIM$|#F0F0F0}}({{Text|STR$|#F0F0F0}}(vc&)); {{Text|<nowiki>"[1], 4, "</nowiki>|#FFB100}}; tarName$; {{Text|<nowiki>"L"</nowiki>|#FFB100}}; {{Text|LTRIM$|#F0F0F0}}({{Text|STR$|#F0F0F0}}(vc&)); {{Text|<nowiki>"[0], han);"</nowiki>|#FFB100}}
    {{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"    if (num != "</nowiki>|#FFB100}}; tarName$; {{Text|<nowiki>"L"</nowiki>|#FFB100}}; {{Text|LTRIM$|#F0F0F0}}({{Text|STR$|#F0F0F0}}(vc&)); {{Text|<nowiki>"[0]) {fclose(han); return "</nowiki>|#FFB100}}; {{Text|CHR$|#F0F0F0}}({{Text|34|#F580B1}}); {{Text|CHR$|#F0F0F0}}({{Text|34|#F580B1}}); {{Text|<nowiki>";}"</nowiki>|#FFB100}}
    {{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>""</nowiki>|#FFB100}}
{{Text|NEXT|#F0F0F0}} vc&
{{Text|IF|#F0F0F0}} cntB& > {{Text|0|#F580B1}} {{Text|THEN|#F0F0F0}}
    {{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"    num = fwrite(&"</nowiki>|#FFB100}}; tarName$; {{Text|<nowiki>"B[1], 1, "</nowiki>|#FFB100}}; tarName$; {{Text|<nowiki>"B[0], han);"</nowiki>|#FFB100}}
    {{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"    if (num != "</nowiki>|#FFB100}}; tarName$; {{Text|<nowiki>"B[0]) {fclose(han); return "</nowiki>|#FFB100}}; {{Text|CHR$|#F0F0F0}}({{Text|34|#F580B1}}); {{Text|CHR$|#F0F0F0}}({{Text|34|#F580B1}}); {{Text|<nowiki>";}"</nowiki>|#FFB100}}
    {{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>""</nowiki>|#FFB100}}
{{Text|END|#F0F0F0}} {{Text|IF|#F0F0F0}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"    fclose(han);"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"    return "</nowiki>|#FFB100}}; tarName$; {{Text|<nowiki>"Name;"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"}"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>""</nowiki>|#FFB100}}
{{Text|<nowiki>'--- ending ---</nowiki>|#31C4C4}}
{{Text|CLOSE|#F0F0F0}} #2
{{Text|CLOSE|#F0F0F0}} #1
{{Text|<nowiki>'--- .bm include file ---</nowiki>|#31C4C4}}
{{Text|OPEN|#F0F0F0}} {{Text|<nowiki>"O"</nowiki>|#FFB100}}, #2, tarPath$ + tar$ + {{Text|<nowiki>".bm"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"'============================================================"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"'=== This file was created with MakeCARR.bas by RhoSigma, ==="</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"'=== you must $INCLUDE this at the end of your program.  ==="</nowiki>|#FFB100}}
{{Text|IF|#F0F0F0}} packed% {{Text|THEN|#F0F0F0}}
    {{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"'=== ---------------------------------------------------- ==="</nowiki>|#FFB100}}
    {{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"'=== If your program is NOT a GuiTools based application, ==="</nowiki>|#FFB100}}
    {{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"'=== then it must also $INCLUDE: 'lzwpacker.bm' available ==="</nowiki>|#FFB100}}
    {{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"'=== from the Libraries Collection here:                  ==="</nowiki>|#FFB100}}
    {{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"'=== http://qb64phoenix.com/forum/forumdisplay.php?fid=23 ==="</nowiki>|#FFB100}}
{{Text|END|#F0F0F0}} {{Text|IF|#F0F0F0}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"'============================================================"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>""</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"'-----------------"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"'--- Important ---"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"'-----------------"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"' If you need to move around this .bm file and its respective .h file"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"' to fit in your project, then make sure the path in the DECLARE LIBRARY"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"' statement below does match the actual .h file location. It's best to"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"' specify a relative path assuming your QB64 installation folder as root."</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"'---------------------------------------------------------------------"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>""</nowiki>|#FFB100}}
{{Text|<nowiki>'--- writeback function ---</nowiki>|#31C4C4}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"'"</nowiki>|#FFB100}}; {{Text|STRING$|#F0F0F0}}({{Text|LEN|#F0F0F0}}(tarName$) + {{Text|19|#F580B1}}, {{Text|<nowiki>"-"</nowiki>|#FFB100}})
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"'--- Write"</nowiki>|#FFB100}}; tarName$; {{Text|<nowiki>"Array$ ---"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"'"</nowiki>|#FFB100}}; {{Text|STRING$|#F0F0F0}}({{Text|LEN|#F0F0F0}}(tarName$) + {{Text|19|#F580B1}}, {{Text|<nowiki>"-"</nowiki>|#FFB100}})
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"' This function will write the array(s) you've created with MakeCARR.bas"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"' back to disk and so it rebuilds the original file."</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"'"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"' After the writeback call, only use the returned realFile$ to access the"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"' written file. It's the full qualified absolute path and filename, which"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"' is made by expanding your maybe given relative path and an maybe altered"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"' filename (number added) in order to avoid the overwriting of an already"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"' existing file with the same name in the given location. By this means"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"' you'll always have safe access to the file, no matter how your current"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"' working folder changes during runtime."</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"'"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"' If you wish, the written file can automatically be deleted for you when"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"' your program will end, so you don't need to do the cleanup yourself."</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"'----------"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"' SYNTAX:"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"'  realFile$ = Write"</nowiki>|#FFB100}}; tarName$; {{Text|<nowiki>"Array$ (wantFile$, autoDel%)"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"'----------"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"' INPUTS:"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"'  --- wantFile$ ---"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"'    The filename you would like to write the array(s) to, can contain"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"'    a full or relative path."</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"'  --- autoDel% ---"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"'    Shows whether you want the auto cleanup (see description above) at"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"'    the program end or not (-1 = delete file, 0 = don't delete file)."</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"'----------"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"' RESULT:"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"'  --- realFile$ ---"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"'    - On success this is the full qualified path and filename finally"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"'      used after all applied checks, use only this returned filename"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"'      to access the written file."</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"'    - On failure (write/access) this will be an empty string, so you"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"'      should check for this before trying to access/open the file."</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"'---------------------------------------------------------------------"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"FUNCTION Write"</nowiki>|#FFB100}}; tarName$; {{Text|<nowiki>"Array$ (file$, clean%)"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"'--- declare C/C++ function ---"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"DECLARE LIBRARY "</nowiki>|#FFB100}}; {{Text|CHR$|#F0F0F0}}({{Text|34|#F580B1}}); tarPath$; tar$; {{Text|CHR$|#F0F0F0}}({{Text|34|#F580B1}}); {{Text|<nowiki>" 'Do not add .h here !!"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"    FUNCTION Write"</nowiki>|#FFB100}}; tarName$; {{Text|<nowiki>"Data$ (FileName$, BYVAL AutoClean%)"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"END DECLARE"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"'--- option _explicit requirements ---"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"DIM po%, body$, ext$, num%"</nowiki>|#FFB100}};
{{Text|IF|#F0F0F0}} packed% {{Text|THEN|#F0F0F0}} {{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>", real$, ff%, rawdata$, filedata$"</nowiki>|#FFB100}}: {{Text|ELSE|#F0F0F0}} {{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>""</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"'--- separate filename body & extension ---"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"FOR po% = LEN(file$) TO 1 STEP -1"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"    IF MID$(file$, po%, 1) = "</nowiki>|#FFB100}}; {{Text|CHR$|#F0F0F0}}({{Text|34|#F580B1}}); {{Text|<nowiki>"."</nowiki>|#FFB100}}; {{Text|CHR$|#F0F0F0}}({{Text|34|#F580B1}}); {{Text|<nowiki>" THEN"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"        body$ = LEFT$(file$, po% - 1)"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"        ext$ = MID$(file$, po%)"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"        EXIT FOR"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"    ELSEIF MID$(file$, po%, 1) = "</nowiki>|#FFB100}}; {{Text|CHR$|#F0F0F0}}({{Text|34|#F580B1}}); {{Text|<nowiki>"\"</nowiki>|#FFB100}}; {{Text|CHR$|#F0F0F0}}({{Text|34|#F580B1}}); {{Text|<nowiki>" OR MID$(file$, po%, 1) = "</nowiki>|#FFB100}}; {{Text|CHR$|#F0F0F0}}({{Text|34|#F580B1}}); {{Text|<nowiki>"/"</nowiki>|#FFB100}}; {{Text|CHR$|#F0F0F0}}({{Text|34|#F580B1}}); {{Text|<nowiki>" OR po% = 1 THEN"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"        body$ = file$"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"        ext$ = "</nowiki>|#FFB100}}; {{Text|CHR$|#F0F0F0}}({{Text|34|#F580B1}}); {{Text|CHR$|#F0F0F0}}({{Text|34|#F580B1}})
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"        EXIT FOR"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"    END IF"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"NEXT po%"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"'--- avoid overwriting of existing files ---"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"num% = 1"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"WHILE _FILEEXISTS(file$)"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"    file$ = body$ + "</nowiki>|#FFB100}}; {{Text|CHR$|#F0F0F0}}({{Text|34|#F580B1}}); {{Text|<nowiki>"("</nowiki>|#FFB100}}; {{Text|CHR$|#F0F0F0}}({{Text|34|#F580B1}}); {{Text|<nowiki>" + LTRIM$(STR$(num%)) + "</nowiki>|#FFB100}}; {{Text|CHR$|#F0F0F0}}({{Text|34|#F580B1}}); {{Text|<nowiki>")"</nowiki>|#FFB100}}; {{Text|CHR$|#F0F0F0}}({{Text|34|#F580B1}}); {{Text|<nowiki>" + ext$"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"    num% = num% + 1"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"WEND"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"'--- write array & set result ---"</nowiki>|#FFB100}}
{{Text|IF|#F0F0F0}} {{Text|NOT|#F0F0F0}} packed% {{Text|THEN|#F0F0F0}}
    {{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"Write"</nowiki>|#FFB100}}; tarName$; {{Text|<nowiki>"Array$ = Write"</nowiki>|#FFB100}}; tarName$; {{Text|<nowiki>"Data$(file$ + CHR$(0), clean%)"</nowiki>|#FFB100}}
{{Text|ELSE|#F0F0F0}}
    {{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"real$ = Write"</nowiki>|#FFB100}}; tarName$; {{Text|<nowiki>"Data$(file$ + CHR$(0), clean%)"</nowiki>|#FFB100}}
    {{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"IF real$ <> "</nowiki>|#FFB100}}; {{Text|CHR$|#F0F0F0}}({{Text|34|#F580B1}}); {{Text|CHR$|#F0F0F0}}({{Text|34|#F580B1}}); {{Text|<nowiki>" THEN"</nowiki>|#FFB100}}
    {{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"    ff% = FREEFILE"</nowiki>|#FFB100}}
    {{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"    OPEN real$ FOR BINARY AS ff%"</nowiki>|#FFB100}}
    {{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"    rawdata$ = SPACE$(LOF(ff%))"</nowiki>|#FFB100}}
    {{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"    GET #ff%, , rawdata$"</nowiki>|#FFB100}}
    {{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"    filedata$ = LzwUnpack$(rawdata$)"</nowiki>|#FFB100}}
    {{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"    PUT #ff%, 1, filedata$"</nowiki>|#FFB100}}
    {{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"    CLOSE ff%"</nowiki>|#FFB100}}
    {{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"END IF"</nowiki>|#FFB100}}
    {{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"Write"</nowiki>|#FFB100}}; tarName$; {{Text|<nowiki>"Array$ = real$"</nowiki>|#FFB100}}
{{Text|END|#F0F0F0}} {{Text|IF|#F0F0F0}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>"END FUNCTION"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} #2, {{Text|<nowiki>""</nowiki>|#FFB100}}
{{Text|<nowiki>'--- ending ---</nowiki>|#31C4C4}}
{{Text|CLOSE|#F0F0F0}} #2
{{Text|<nowiki>'--- finish message ---</nowiki>|#31C4C4}}
{{Text|COLOR|#F0F0F0}} {{Text|10|#F580B1}}: {{Text|PRINT|#F0F0F0}}: {{Text|PRINT|#F0F0F0}} {{Text|<nowiki>"file successfully processed..."</nowiki>|#FFB100}}
{{Text|COLOR|#F0F0F0}} {{Text|9|#F580B1}}: {{Text|PRINT|#F0F0F0}}: {{Text|PRINT|#F0F0F0}} {{Text|<nowiki>"You must $INCLUDE the created file (target name + .bm extension) at"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} {{Text|<nowiki>"the end of your program and call the function 'Write"</nowiki>|#FFB100}}; tarName$; {{Text|<nowiki>"Array$(...)'"</nowiki>|#FFB100}}
{{Text|PRINT|#F0F0F0}} {{Text|<nowiki>"in an appropriate place to write the file back to disk."</nowiki>|#FFB100}}
{{Text|IF|#F0F0F0}} packed% {{Text|THEN|#F0F0F0}}
    {{Text|COLOR|#F0F0F0}} {{Text|12|#F580B1}}: {{Text|PRINT|#F0F0F0}}: {{Text|PRINT|#F0F0F0}} {{Text|<nowiki>"Your program must also $INCLUDE 'lzwpacker.bm' available from"</nowiki>|#FFB100}}
    {{Text|PRINT|#F0F0F0}} {{Text|<nowiki>"the Libraries Collection here:"</nowiki>|#FFB100}}
    {{Text|PRINT|#F0F0F0}} {{Text|<nowiki>"    http://qb64phoenix.com/forum/forumdisplay.php?fid=23"</nowiki>|#FFB100}}
    {{Text|PRINT|#F0F0F0}} {{Text|<nowiki>"to be able to write back the just processed file."</nowiki>|#FFB100}}
    {{Text|KILL|#F0F0F0}} tarPath$ + tar$ + {{Text|<nowiki>".lzw"</nowiki>|#FFB100}}
{{Text|END|#F0F0F0}} {{Text|IF|#F0F0F0}}
done:
{{Text|COLOR|#F0F0F0}} {{Text|7|#F580B1}}
{{Text|END|#F0F0F0}}
{{Text|<nowiki>'--- error handler ---</nowiki>|#31C4C4}}
abort:
{{Text|COLOR|#F0F0F0}} {{Text|12|#F580B1}}: {{Text|PRINT|#F0F0F0}}: {{Text|PRINT|#F0F0F0}} {{Text|<nowiki>"something is wrong with path/file access, check your inputs and try again..."</nowiki>|#FFB100}}
{{Text|RESUME|#F0F0F0}} done
{{Text|<nowiki>'</nowiki>|#31C4C4}}{{Text|$INCLUDE:|#55FF55}} {{Text|<nowiki>'QB64Library\LZW-Compress\lzwpacker.bm'</nowiki>|#31C4C4}}
{{CodeEnd}}

Revision as of 11:09, 26 February 2023

The _BlankPage serves as a skeleton for new Wiki pages.


Syntax

_BlankSub arg1[, arg2]
result% = _BlankFunc(arg1[, arg2])


Parameters

  • arg1 is a mandatory argument
  • the arg2 is optional


Description

To use this skeleton click on the Edit tab above the page, then copy the raw text of this page and paste it into your new page. Change/remove sections as needed. Use this for italic and this for bold text style. To color your writings use the Text template. It takes either a color name or a #RRGGBB 32bit color, if the color part is omitted it will default to gray.

You can inline simple code one liners like w = _WIDTH

  • an askerisk marks a list point
    • two askerisks will indent the list
      • three askerisks will indent even more
This is a definition list
The first description can follow right after a colon
or in a new line
more descriptions can follow
  • using list bullets with an askerisk
as already seen in the syntax above, you may use desciptions without a defininition too
you may also nest descriptions
but at some point it's cluttering the page so please use it sparingly
This is a nice piece of paper for quotes and similar things. In case of short code snippets you may use the "Cb" (code blue) template to highlight and link keywords to the Wiki pages.

FOR x = 1 TO 5
   PRINT "Hello World!"
NEXT x
END

As you see, this Text block is suitable for preformatted text, but note that the browser is still allowed to wrap too long lines. If you really need your preformatted text to be shown as is, then use a fixed text block instaed, see below.
Use this fixed text block for preformatted text, which is not even allowed to wrap long lines, such as tables etc..
As you see this very long line goes far over the display width, so please limit youself to the available space to not clutter the display too much.

Notes

  • This may be a sub-section for further notes like special behavior, required prerequisites etc.
  • If used/required, then this should always be a sub-section under the Description main section

Errors

  • If used/required, then this also should be a sub-section under the Description main section
  • This is not intended for the regular errors a SUB/FUNCTION could throw, those should be handled in the main description section.
    • Rather use it for subtle things, known mis-behavior, tendency for stack overflows and seg faults etc.


Availability

  • The capability to load from memory was introduced in QB64-PE v3.5.0.


Examples

Example 1
Each example should have a short description.
'Place your code example here
'The "Cl" (code link) template can be used to link keywords to its
'respective Wiki page. Those words will also get highlighted.
COLOR 15,4
PRINT "Hello World!"
This template allows for a short author credit.


The output block is available for the SCREEN 0 background colors 0-7
Inside the output block use the "Ot" (output text) template for coloring
Hello World!


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
'+---------------+---------------------------------------------------+
'| ###### ###### |     .--. .         .-.                            |
'| ##  ## ##   # |     |   )|        (   ) o                         |
'| ##  ##  ##    |     |--' |--. .-.  `-.  .  .-...--.--. .-.        |
'| ######   ##   |     |  \ |  |(   )(   ) | (   ||  |  |(   )       |
'| ##      ##    |     '   `'  `-`-'  `-'-' `-`-`|'  '  `-`-'`-      |
'| ##     ##   # |                            ._.'                   |
'| ##     ###### |  Sources & Documents placed in the Public Domain. |
'+---------------+---------------------------------------------------+
'|                                                                   |
'| === MakeCARR.bas ===                                              |
'|                                                                   |
'| == Create a C/C++ array out of the given file, so you can embed   |
'| == it in your program and write it back when needed.              |
'|                                                                   |
'| == Two files are created, the .h file, which contains the array(s)|
'| == and some functions, and a respective .bm file which needs to   |
'| == be $INCLUDEd with your program and does provide the FUNCTION   |
'| == to write back the array(s) into any file. All used functions   |
'| == are standard library calls, no API calls are involved, so the  |
'| == writeback should work on all QB64 supported platforms.         |
'|                                                                   |
'| == Make sure to adjust the path for the .h file for your personal |
'| == needs in the created .bm files (DECLARE LIBRARY), if required. |
'| == You may specify default paths right below this header.         |
'|                                                                   |
'| == This program needs the 'lzwpacker.bm' file available from the  |
'| == Libraries Collection here:                                     |
'| ==      http://qb64phoenix.com/forum/forumdisplay.php?fid=23      |
'| == as it will try to pack the given file to keep the array(s) as  |
'| == small as possible. If compression is successful, then your     |
'| == program also must $INCLUDE 'lzwpacker.bm' to be able to unpack |
'| == the file data again for write back. MakeCARR.bas is printing   |
'| == a reminder message in such a case.                             |
'|                                                                   |
'+-------------------------------------------------------------------+
'| Done by RhoSigma, R.Heyder, provided AS IS, use at your own risk. |
'| Find me in the QB64 Forum or mail to support@rhosigma-cw.net for  |
'| any questions or suggestions. Thanx for your interest in my work. |
'+-------------------------------------------------------------------+

'--- if you wish, set any default paths, end with a backslash ---
srcPath$ = "" 'source path
tarPath$ = "" 'target path
'-----
IF srcPath$ <> "" THEN
    COLOR 15: PRINT "Default source path: ": COLOR 7: PRINT srcPath$: PRINT
END IF
IF tarPath$ <> "" THEN
    COLOR 15: PRINT "Default target path: ": COLOR 7: PRINT tarPath$: PRINT
END IF

'--- collect inputs (relative paths allowed, based on default paths) ---
source:
LINE INPUT "Source Filename: "; src$ 'any file you want to put into a C/C++ array
IF src$ = "" GOTO source
target:
LINE INPUT "Target Basename: "; tar$ 'write stuff into this file(s) (.h/.bm is added)
IF tar$ = "" GOTO target
'-----
ON ERROR GOTO abort
OPEN "I", #1, srcPath$ + src$: CLOSE #1 'file exist check
OPEN "O", #2, tarPath$ + tar$ + ".bm": CLOSE #2 'path exist check
ON ERROR GOTO 0

'--- separate source filename part ---
FOR po% = LEN(src$) TO 1 STEP -1
    IF MID$(src$, po%, 1) = "\" OR MID$(src$, po%, 1) = "/" THEN
        srcName$ = MID$(src$, po% + 1)
        EXIT FOR
    ELSEIF po% = 1 THEN
        srcName$ = src$
    END IF
NEXT po%
'--- separate target filename part ---
FOR po% = LEN(tar$) TO 1 STEP -1
    IF MID$(tar$, po%, 1) = "\" OR MID$(tar$, po%, 1) = "/" THEN
        tarName$ = MID$(tar$, po% + 1)
        EXIT FOR
    ELSEIF po% = 1 THEN
        tarName$ = tar$
    END IF
NEXT po%
MID$(tarName$, 1, 1) = UCASE$(MID$(tarName$, 1, 1)) 'capitalize 1st letter

'---------------------------------------------------------------------
' Depending on the source file's size, one or more array(s) are
' created. This is because some C/C++ compilers seem to have problems
' with arrays with more than 65535 elements. This does not affect the
' write back, as the write function will take this behavior into account.
'---------------------------------------------------------------------

'--- init ---
OPEN "B", #1, srcPath$ + src$
filedata$ = SPACE$(LOF(1))
GET #1, , filedata$
CLOSE #1
rawdata$ = LzwPack$(filedata$, 20)
IF rawdata$ <> "" THEN
    OPEN "O", #1, tarPath$ + tar$ + ".lzw"
    CLOSE #1
    OPEN "B", #1, tarPath$ + tar$ + ".lzw"
    PUT #1, , rawdata$
    CLOSE #1
    packed% = -1
    OPEN "B", #1, tarPath$ + tar$ + ".lzw"
ELSE
    packed% = 0
    OPEN "B", #1, srcPath$ + src$
END IF
fl& = LOF(1)
cntL& = INT(fl& / 32)
cntV& = INT(cntL& / 8180)
cntB& = (fl& - (cntL& * 32))

'--- .h include file ---
OPEN "O", #2, tarPath$ + tar$ + ".h"
PRINT #2, "// ============================================================"
PRINT #2, "// === This file was created with MakeCARR.bas by RhoSigma, ==="
PRINT #2, "// === use it in conjunction with its respective .bm file.  ==="
PRINT #2, "// ============================================================"
PRINT #2, ""
PRINT #2, "// --- Array(s) representing the contents of file "; srcName$
PRINT #2, "// ---------------------------------------------------------------------"
'--- read LONGs ---
tmpI$ = SPACE$(32)
FOR vc& = 0 TO cntV&
    IF vc& = cntV& THEN numL& = (cntL& MOD 8180): ELSE numL& = 8180
    PRINT #2, "static const uint32_t "; tarName$; "L"; LTRIM$(STR$(vc&)); "[] = {"
    PRINT #2, "    "; LTRIM$(STR$(numL& * 8)); ","
    FOR z& = 1 TO numL&
        GET #1, , tmpI$: offI% = 1
        tmpO$ = "    " + STRING$(88, ","): offO% = 5
        DO
            tmpL& = CVL(MID$(tmpI$, offI%, 4)): offI% = offI% + 4
            MID$(tmpO$, offO%, 10) = "0x" + RIGHT$("00000000" + HEX$(tmpL&), 8)
            offO% = offO% + 11
        LOOP UNTIL offO% > 92
        IF z& < numL& THEN PRINT #2, tmpO$: ELSE PRINT #2, LEFT$(tmpO$, 91)
    NEXT z&
    PRINT #2, "};"
    PRINT #2, ""
NEXT vc&
'--- read remaining BYTEs ---
IF cntB& > 0 THEN
    PRINT #2, "static const uint8_t "; tarName$; "B[] = {"
    PRINT #2, "    "; LTRIM$(STR$(cntB&)); ","
    PRINT #2, "    ";
    FOR x% = 1 TO cntB&
        GET #1, , tmpB%%
        PRINT #2, "0x" + RIGHT$("00" + HEX$(tmpB%%), 2);
        IF x% <> 16 THEN
            IF x% <> cntB& THEN PRINT #2, ",";
        ELSE
            IF x% <> cntB& THEN
                PRINT #2, ","
                PRINT #2, "    ";
            END IF
        END IF
    NEXT x%
    PRINT #2, ""
    PRINT #2, "};"
    PRINT #2, ""
END IF
'--- some functions ---
PRINT #2, "// --- Saved full qualified output path and filename, so we've no troubles"
PRINT #2, "// --- when cleaning up, even if the current working folder was changed"
PRINT #2, "// --- during program runtime."
PRINT #2, "// ---------------------------------------------------------------------"
PRINT #2, "char "; tarName$; "Name[8192]; // it's a safe size for any current OS"
PRINT #2, ""
PRINT #2, "// --- Cleanup function to delete the written file, called by the atexit()"
PRINT #2, "// --- handler at program termination time, if requested by user."
PRINT #2, "// ---------------------------------------------------------------------"
PRINT #2, "void Kill"; tarName$; "Data(void)"
PRINT #2, "{"
PRINT #2, "    remove("; tarName$; "Name);"
PRINT #2, "}"
PRINT #2, ""
PRINT #2, "// --- Function to write the array(s) back into a file, will return the"
PRINT #2, "// --- full qualified output path and filename on success, otherwise an"
PRINT #2, "// --- empty string is returned (access/write errors, file truncated)."
PRINT #2, "// ---------------------------------------------------------------------"
PRINT #2, "const char *Write"; tarName$; "Data(const char *FileName, int16_t AutoClean)"
PRINT #2, "{"
PRINT #2, "    FILE   *han = NULL; // file handle"
PRINT #2, "    int32_t num = NULL; // written elements"
PRINT #2, ""
PRINT #2, "    #ifdef QB64_WINDOWS"
PRINT #2, "    if (!_fullpath("; tarName$; "Name, FileName, 8192)) return "; CHR$(34); CHR$(34); ";"
PRINT #2, "    #else"
PRINT #2, "    if (!realpath(FileName, "; tarName$; "Name)) return "; CHR$(34); CHR$(34); ";"
PRINT #2, "    #endif"
PRINT #2, ""
PRINT #2, "    if (!(han = fopen("; tarName$; "Name, "; CHR$(34); "wb"; CHR$(34); "))) return "; CHR$(34); CHR$(34); ";"
PRINT #2, "    if (AutoClean) atexit(Kill"; tarName$; "Data);"
PRINT #2, ""
FOR vc& = 0 TO cntV&
    PRINT #2, "    num = fwrite(&"; tarName$; "L"; LTRIM$(STR$(vc&)); "[1], 4, "; tarName$; "L"; LTRIM$(STR$(vc&)); "[0], han);"
    PRINT #2, "    if (num != "; tarName$; "L"; LTRIM$(STR$(vc&)); "[0]) {fclose(han); return "; CHR$(34); CHR$(34); ";}"
    PRINT #2, ""
NEXT vc&
IF cntB& > 0 THEN
    PRINT #2, "    num = fwrite(&"; tarName$; "B[1], 1, "; tarName$; "B[0], han);"
    PRINT #2, "    if (num != "; tarName$; "B[0]) {fclose(han); return "; CHR$(34); CHR$(34); ";}"
    PRINT #2, ""
END IF
PRINT #2, "    fclose(han);"
PRINT #2, "    return "; tarName$; "Name;"
PRINT #2, "}"
PRINT #2, ""
'--- ending ---
CLOSE #2
CLOSE #1

'--- .bm include file ---
OPEN "O", #2, tarPath$ + tar$ + ".bm"
PRINT #2, "'============================================================"
PRINT #2, "'=== This file was created with MakeCARR.bas by RhoSigma, ==="
PRINT #2, "'=== you must $INCLUDE this at the end of your program.   ==="
IF packed% THEN
    PRINT #2, "'=== ---------------------------------------------------- ==="
    PRINT #2, "'=== If your program is NOT a GuiTools based application, ==="
    PRINT #2, "'=== then it must also $INCLUDE: 'lzwpacker.bm' available ==="
    PRINT #2, "'=== from the Libraries Collection here:                  ==="
    PRINT #2, "'=== http://qb64phoenix.com/forum/forumdisplay.php?fid=23 ==="
END IF
PRINT #2, "'============================================================"
PRINT #2, ""
PRINT #2, "'-----------------"
PRINT #2, "'--- Important ---"
PRINT #2, "'-----------------"
PRINT #2, "' If you need to move around this .bm file and its respective .h file"
PRINT #2, "' to fit in your project, then make sure the path in the DECLARE LIBRARY"
PRINT #2, "' statement below does match the actual .h file location. It's best to"
PRINT #2, "' specify a relative path assuming your QB64 installation folder as root."
PRINT #2, "'---------------------------------------------------------------------"
PRINT #2, ""
'--- writeback function ---
PRINT #2, "'"; STRING$(LEN(tarName$) + 19, "-")
PRINT #2, "'--- Write"; tarName$; "Array$ ---"
PRINT #2, "'"; STRING$(LEN(tarName$) + 19, "-")
PRINT #2, "' This function will write the array(s) you've created with MakeCARR.bas"
PRINT #2, "' back to disk and so it rebuilds the original file."
PRINT #2, "'"
PRINT #2, "' After the writeback call, only use the returned realFile$ to access the"
PRINT #2, "' written file. It's the full qualified absolute path and filename, which"
PRINT #2, "' is made by expanding your maybe given relative path and an maybe altered"
PRINT #2, "' filename (number added) in order to avoid the overwriting of an already"
PRINT #2, "' existing file with the same name in the given location. By this means"
PRINT #2, "' you'll always have safe access to the file, no matter how your current"
PRINT #2, "' working folder changes during runtime."
PRINT #2, "'"
PRINT #2, "' If you wish, the written file can automatically be deleted for you when"
PRINT #2, "' your program will end, so you don't need to do the cleanup yourself."
PRINT #2, "'----------"
PRINT #2, "' SYNTAX:"
PRINT #2, "'   realFile$ = Write"; tarName$; "Array$ (wantFile$, autoDel%)"
PRINT #2, "'----------"
PRINT #2, "' INPUTS:"
PRINT #2, "'   --- wantFile$ ---"
PRINT #2, "'    The filename you would like to write the array(s) to, can contain"
PRINT #2, "'    a full or relative path."
PRINT #2, "'   --- autoDel% ---"
PRINT #2, "'    Shows whether you want the auto cleanup (see description above) at"
PRINT #2, "'    the program end or not (-1 = delete file, 0 = don't delete file)."
PRINT #2, "'----------"
PRINT #2, "' RESULT:"
PRINT #2, "'   --- realFile$ ---"
PRINT #2, "'    - On success this is the full qualified path and filename finally"
PRINT #2, "'      used after all applied checks, use only this returned filename"
PRINT #2, "'      to access the written file."
PRINT #2, "'    - On failure (write/access) this will be an empty string, so you"
PRINT #2, "'      should check for this before trying to access/open the file."
PRINT #2, "'---------------------------------------------------------------------"
PRINT #2, "FUNCTION Write"; tarName$; "Array$ (file$, clean%)"
PRINT #2, "'--- declare C/C++ function ---"
PRINT #2, "DECLARE LIBRARY "; CHR$(34); tarPath$; tar$; CHR$(34); " 'Do not add .h here !!"
PRINT #2, "    FUNCTION Write"; tarName$; "Data$ (FileName$, BYVAL AutoClean%)"
PRINT #2, "END DECLARE"
PRINT #2, "'--- option _explicit requirements ---"
PRINT #2, "DIM po%, body$, ext$, num%";
IF packed% THEN PRINT #2, ", real$, ff%, rawdata$, filedata$": ELSE PRINT #2, ""
PRINT #2, "'--- separate filename body & extension ---"
PRINT #2, "FOR po% = LEN(file$) TO 1 STEP -1"
PRINT #2, "    IF MID$(file$, po%, 1) = "; CHR$(34); "."; CHR$(34); " THEN"
PRINT #2, "        body$ = LEFT$(file$, po% - 1)"
PRINT #2, "        ext$ = MID$(file$, po%)"
PRINT #2, "        EXIT FOR"
PRINT #2, "    ELSEIF MID$(file$, po%, 1) = "; CHR$(34); "\"; CHR$(34); " OR MID$(file$, po%, 1) = "; CHR$(34); "/"; CHR$(34); " OR po% = 1 THEN"
PRINT #2, "        body$ = file$"
PRINT #2, "        ext$ = "; CHR$(34); CHR$(34)
PRINT #2, "        EXIT FOR"
PRINT #2, "    END IF"
PRINT #2, "NEXT po%"
PRINT #2, "'--- avoid overwriting of existing files ---"
PRINT #2, "num% = 1"
PRINT #2, "WHILE _FILEEXISTS(file$)"
PRINT #2, "    file$ = body$ + "; CHR$(34); "("; CHR$(34); " + LTRIM$(STR$(num%)) + "; CHR$(34); ")"; CHR$(34); " + ext$"
PRINT #2, "    num% = num% + 1"
PRINT #2, "WEND"
PRINT #2, "'--- write array & set result ---"
IF NOT packed% THEN
    PRINT #2, "Write"; tarName$; "Array$ = Write"; tarName$; "Data$(file$ + CHR$(0), clean%)"
ELSE
    PRINT #2, "real$ = Write"; tarName$; "Data$(file$ + CHR$(0), clean%)"
    PRINT #2, "IF real$ <> "; CHR$(34); CHR$(34); " THEN"
    PRINT #2, "    ff% = FREEFILE"
    PRINT #2, "    OPEN real$ FOR BINARY AS ff%"
    PRINT #2, "    rawdata$ = SPACE$(LOF(ff%))"
    PRINT #2, "    GET #ff%, , rawdata$"
    PRINT #2, "    filedata$ = LzwUnpack$(rawdata$)"
    PRINT #2, "    PUT #ff%, 1, filedata$"
    PRINT #2, "    CLOSE ff%"
    PRINT #2, "END IF"
    PRINT #2, "Write"; tarName$; "Array$ = real$"
END IF
PRINT #2, "END FUNCTION"
PRINT #2, ""
'--- ending ---
CLOSE #2

'--- finish message ---
COLOR 10: PRINT: PRINT "file successfully processed..."
COLOR 9: PRINT: PRINT "You must $INCLUDE the created file (target name + .bm extension) at"
PRINT "the end of your program and call the function 'Write"; tarName$; "Array$(...)'"
PRINT "in an appropriate place to write the file back to disk."
IF packed% THEN
    COLOR 12: PRINT: PRINT "Your program must also $INCLUDE 'lzwpacker.bm' available from"
    PRINT "the Libraries Collection here:"
    PRINT "     http://qb64phoenix.com/forum/forumdisplay.php?fid=23"
    PRINT "to be able to write back the just processed file."
    KILL tarPath$ + tar$ + ".lzw"
END IF
done:
COLOR 7
END
'--- error handler ---
abort:
COLOR 12: PRINT: PRINT "something is wrong with path/file access, check your inputs and try again..."
RESUME done

'$INCLUDE: 'QB64Library\LZW-Compress\lzwpacker.bm'