From 63e9714b4903452e5d7e651d7865f88b79950b76 Mon Sep 17 00:00:00 2001 From: coderJeff Date: Sat, 11 May 2019 16:13:14 -0400 Subject: [PATCH 01/14] fbdoc: wiki snapshot 2019-05-20 --- doc/manual/cache/CatPgCompOpt.wakka | 4 + doc/manual/cache/CatPgPreProcess.wakka | 2 + doc/manual/cache/CatPgThreading.wakka | 28 +++---- doc/manual/cache/CompilerHistory.wakka | 8 +- doc/manual/cache/CompilerOptWa.wakka | 5 +- doc/manual/cache/CompilerOptWc.wakka | 3 +- doc/manual/cache/CompilerOptWl.wakka | 3 +- doc/manual/cache/CompilerOptnostrip.wakka | 17 +++++ doc/manual/cache/CompilerOptstrip.wakka | 17 +++++ doc/manual/cache/DevBootstrap.wakka | 8 +- doc/manual/cache/GfxScancodes.wakka | 7 +- doc/manual/cache/KeyPgAllocate.wakka | 3 +- doc/manual/cache/KeyPgAny.wakka | 6 +- doc/manual/cache/KeyPgBoolean.wakka | 1 + doc/manual/cache/KeyPgBsave.wakka | 28 ++++++- doc/manual/cache/KeyPgCircle.wakka | 2 + doc/manual/cache/KeyPgCommon.wakka | 2 +- doc/manual/cache/KeyPgInstrrev.wakka | 8 +- doc/manual/cache/KeyPgLinegraphics.wakka | 2 + doc/manual/cache/KeyPgOpNew.wakka | 85 +++++++++++++++++++++- doc/manual/cache/KeyPgOpNewOverload.wakka | 2 +- doc/manual/cache/KeyPgOpPlacementNew.wakka | 2 +- doc/manual/cache/KeyPgOptiondynamic.wakka | 2 +- doc/manual/cache/KeyPgPaint.wakka | 2 + doc/manual/cache/KeyPgPutfileio.wakka | 1 - doc/manual/cache/KeyPgRedim.wakka | 6 +- doc/manual/cache/KeyPgScreencontrol.wakka | 4 +- doc/manual/cache/KeyPgSwap.wakka | 4 + doc/manual/cache/KeyPgWchr.wakka | 6 +- doc/manual/cache/ProPgArrays.wakka | 2 +- doc/manual/cache/ProPgPrimer1.wakka | 2 +- 31 files changed, 220 insertions(+), 52 deletions(-) create mode 100644 doc/manual/cache/CompilerOptnostrip.wakka create mode 100644 doc/manual/cache/CompilerOptstrip.wakka diff --git a/doc/manual/cache/CatPgCompOpt.wakka b/doc/manual/cache/CatPgCompOpt.wakka index 9a09a62586..9102796824 100644 --- a/doc/manual/cache/CatPgCompOpt.wakka +++ b/doc/manual/cache/CatPgCompOpt.wakka @@ -63,6 +63,8 @@ Command line compiler options for the fbc compiler: - Do not show source line where error occurred {{fbdoc item="keyword" value="CompilerOptnoobjinfo|-noobjinfo"}} - Do not read/write compile-time info from/to .o and .a files + {{fbdoc item="keyword" value="CompilerOptnostrip|-nostrip"}} + - Do not strip symbol information from the output file {{fbdoc item="keyword" value="CompilerOpto|-o < name >"}} - Set object file path/name (must be passed after the .bas file) {{fbdoc item="keyword" value="CompilerOptoptimization|-O < level >"}} @@ -93,6 +95,8 @@ Command line compiler options for the fbc compiler: - Display a tree of file names of ""#included"" files {{fbdoc item="keyword" value="CompilerOptstatic|-static"}} - Prefer static libraries over dynamic ones when linking + {{fbdoc item="keyword" value="CompilerOptstrip|-strip"}} + - Omit all symbol information from the output file {{fbdoc item="keyword" value="CompilerOptt|-t < value >"}} - Set stack size in kbytes (default: 1M) {{fbdoc item="keyword" value="CompilerOpttarget|-target < platform >"}} diff --git a/doc/manual/cache/CatPgPreProcess.wakka b/doc/manual/cache/CatPgPreProcess.wakka index a1df8273e1..bf6621754c 100644 --- a/doc/manual/cache/CatPgPreProcess.wakka +++ b/doc/manual/cache/CatPgPreProcess.wakka @@ -78,5 +78,7 @@ Commands that control the preprocessor. =={{fbdoc item="keyword" value="KeyPgMetaLang|'$LANG"}}== Alternate form of the [[KeyPgPplang|#lang]] directive. >>::c:: +{{fbdoc item="see"}} + - [[CatPgDddefines|Intrinsic Defines]] {{fbdoc item="back" value="DocToc|Table of Contents"}} \ No newline at end of file diff --git a/doc/manual/cache/CatPgThreading.wakka b/doc/manual/cache/CatPgThreading.wakka index 7999f88880..89d25ce728 100644 --- a/doc/manual/cache/CatPgThreading.wakka +++ b/doc/manual/cache/CatPgThreading.wakka @@ -6,22 +6,31 @@ Procedures for working with multithreaded applications. **{{anchor name="THREADS|Threads"}}** Procedures that start and wait for threaded procedures. -**{{anchor name="CONDVARS|Conditional Varables"}}** - Procedures that create and signal conditional variables. **{{anchor name="MUTEXES|Mutexes"}}** Procedures that deal with mutexes. +**{{anchor name="CONDVARS|Conditional Varables"}}** + Procedures that create and signal conditional variables. <<{{anchor name="THREADS"}}{{fbdoc item="section" value="Threads"}} =={{fbdoc item="keyword" value="KeyPgThreadCall|THREADCALL"}}== Starts a procedure with parameters in a separate thread of execution. =={{fbdoc item="keyword" value="KeyPgThreadCreate|THREADCREATE"}}== Starts a procedure in a separate thread of execution. - =={{fbdoc item="keyword" value="KeyPgThreadDetach|THREADDETACH"}}== - Releases a thread handle without waiting for the thread to finish. =={{fbdoc item="keyword" value="KeyPgThreadWait|THREADWAIT"}}== Waits for a thread to finish and releases the thread handle. + =={{fbdoc item="keyword" value="KeyPgThreadDetach|THREADDETACH"}}== + Releases a thread handle without waiting for the thread to finish. -{{anchor name="CONDVARS"}}{{fbdoc item="section" value="Conditional Variables"}} +{{anchor name="MUTEXES"}}{{fbdoc item="section" value="Mutexes"}} + =={{fbdoc item="keyword" value="KeyPgMutexCreate|MUTEXCREATE"}}== + Creates a mutex. + =={{fbdoc item="keyword" value="KeyPgMutexLock|MUTEXLOCK"}}== + Acquires a lock on a mutex. + =={{fbdoc item="keyword" value="KeyPgMutexUnlock|MUTEXUNLOCK"}}== + Releases a lock on a mutex. + =={{fbdoc item="keyword" value="KeyPgMutexDestroy|MUTEXDESTROY"}}== + Destroys a mutex that is no longer needed. +<<>>{{anchor name="CONDVARS"}}{{fbdoc item="section" value="Conditional Variables"}} =={{fbdoc item="keyword" value="KeyPgCondCreate|CONDCREATE"}}== Creates a conditional variable. =={{fbdoc item="keyword" value="KeyPgCondWait|CONDWAIT"}}== @@ -32,15 +41,6 @@ Procedures for working with multithreaded applications. Resumes all threaded procedures waiting for a conditional. =={{fbdoc item="keyword" value="KeyPgCondDestroy|CONDDESTROY"}}== Destroys a conditional variable that is no longer needed. -<<>>{{anchor name="MUTEXES"}}{{fbdoc item="section" value="Mutexes"}} - =={{fbdoc item="keyword" value="KeyPgMutexCreate|MUTEXCREATE"}}== - Creates a mutex. - =={{fbdoc item="keyword" value="KeyPgMutexLock|MUTEXLOCK"}}== - Acquires a lock on a mutex. - =={{fbdoc item="keyword" value="KeyPgMutexUnlock|MUTEXUNLOCK"}}== - Releases a lock on a mutex. - =={{fbdoc item="keyword" value="KeyPgMutexDestroy|MUTEXDESTROY"}}== - Destroys a mutex that is no longer needed. >>::c:: {{fbdoc item="target"}} - These procedures are not supported in DOS. diff --git a/doc/manual/cache/CompilerHistory.wakka b/doc/manual/cache/CompilerHistory.wakka index 6c6e613d74..1081fef15b 100644 --- a/doc/manual/cache/CompilerHistory.wakka +++ b/doc/manual/cache/CompilerHistory.wakka @@ -3,18 +3,22 @@ Chronology of the ""FreeBASIC"" project. {{fbdoc item="section" value="Chronology"}} + **2019 February 18** + - ""FreeBASIC"" 1.06.0 release + - Bugfixes + **2016 January 31** - ""FreeBASIC"" 1.05.0 release - Bugfixes **2015 October 1** - ""FreeBASIC"" 1.04.0 release - - new data type "boolean" + - New data type "boolean" - Bugfixes **2014 December 28** - ""FreeBASIC"" 1.01.0 release - - started additionally providing "win32-mingworg" packages + - Started additionally providing "win32-mingworg" packages - Bugfixes **2014 September 24** diff --git a/doc/manual/cache/CompilerOptWa.wakka b/doc/manual/cache/CompilerOptWa.wakka index b5fac6240c..f719a91283 100644 --- a/doc/manual/cache/CompilerOptWa.wakka +++ b/doc/manual/cache/CompilerOptWa.wakka @@ -1,5 +1,5 @@ {{fbdoc item="title" value="Compiler Option: -Wa"}}---- -Pass options to the assembler when using the assembly emitter (-gen gas), the default. +Pass options to the assembler when using the assembly emitter (-gen gas). {{fbdoc item="syntax"}}## **-Wa** < //options// > @@ -9,10 +9,11 @@ Pass options to the assembler when using the assembly emitter (-gen gas), the de Additional options to pass to the assembler. {{fbdoc item="desc"}} - The ##-Wa## compiler option passes additional options to GAS, the assembler. Options must be separated by commas only. + The ##-Wa## compiler option passes additional options to GAS, the assembler. Options must be separated by commas only. The ##-Wa## compiler option may be specified multiple times on the command line. For example: ##fbc -Wa -o,output.o,--verbose## + ##fbc -Wa -o -Wa output.o -Wa --verbose## {{fbdoc item="see"}} - [[CompilerOptgen|Compiler Option: -gen]] diff --git a/doc/manual/cache/CompilerOptWc.wakka b/doc/manual/cache/CompilerOptWc.wakka index 6e02f59b0d..b67b6af2ae 100644 --- a/doc/manual/cache/CompilerOptWc.wakka +++ b/doc/manual/cache/CompilerOptWc.wakka @@ -9,10 +9,11 @@ Pass options to the C compiler when using the C emitter (-gen gcc). Additional options to pass to the C compiler. {{fbdoc item="desc"}} - The ##-Wc## compiler option passes additional options to GCC, the C compiler. Options must be separated by commas only. + The ##-Wc## compiler option passes additional options to GCC, the C compiler. Options must be separated by commas only. The -Wc compiler option may be specified multiple times on the command line. For example: ##fbc -gen gcc -Wc -m32,--verbose,-include,some-header.h## + ##fbc -gen gcc -Wc -m32 -Wc --verbose -Wc -include -Wc some-header.h## {{fbdoc item="see"}} - [[CompilerOptgen|Compiler Option: -gen]] diff --git a/doc/manual/cache/CompilerOptWl.wakka b/doc/manual/cache/CompilerOptWl.wakka index 0dc047958b..d917f3bbb0 100644 --- a/doc/manual/cache/CompilerOptWl.wakka +++ b/doc/manual/cache/CompilerOptWl.wakka @@ -9,10 +9,11 @@ Pass options to linker Additional options to pass to the linker. {{fbdoc item="desc"}} - The ##-Wl## compiler option passes additional options to LD, the linker. Options must be separated by commas only. + The ##-Wl## compiler option passes additional options to LD, the linker. Options must be separated by commas only. The -Wl compiler option may be specified multiple times on the command line. {{fbdoc item="see"}} - [[CompilerOptWa|Compiler Option: -Wa]] + - [[CompilerOptWc|Compiler Option: -Wc]] - [[CompilerCmdLine|Using the Command Line]] {{fbdoc item="back" value="CatPgCompOpt|Compiler Options"}} \ No newline at end of file diff --git a/doc/manual/cache/CompilerOptnostrip.wakka b/doc/manual/cache/CompilerOptnostrip.wakka new file mode 100644 index 0000000000..a27c420651 --- /dev/null +++ b/doc/manual/cache/CompilerOptnostrip.wakka @@ -0,0 +1,17 @@ +{{fbdoc item="title" value="Compiler Option: -nostrip"}}---- +Do not strip symbol information from the output file + +{{fbdoc item="syntax"}}## + **-nostrip** +## +{{fbdoc item="desc"}} + The ##-nostrip## compiler option explicitly prevents fbc from passing the option to strip (remove) all symbols to the linker. Object modules and libraries will retain any symbols present after linking. + +{{fbdoc item="target"}} + - fbc strips all symbols by default on Dos and Windows platforms only + +{{fbdoc item="see"}} + - [[CompilerOptstrip|-strip]] + - [[CompilerCmdLine|Using the Command Line]] + +{{fbdoc item="back" value="CatPgCompOpt|Compiler Options"}} \ No newline at end of file diff --git a/doc/manual/cache/CompilerOptstrip.wakka b/doc/manual/cache/CompilerOptstrip.wakka new file mode 100644 index 0000000000..a8d5f07d2f --- /dev/null +++ b/doc/manual/cache/CompilerOptstrip.wakka @@ -0,0 +1,17 @@ +{{fbdoc item="title" value="Compiler Option: -strip"}}---- +Omit all symbol information from the output file + +{{fbdoc item="syntax"}}## + **-strip** +## +{{fbdoc item="desc"}} + The ##-strip## compiler option passes an option to the linker to strip (remove) all symbols. + +{{fbdoc item="target"}} + - fbc strips all symbols by default on Dos and Windows platforms only + +{{fbdoc item="see"}} + - [[CompilerOptnostrip|-nostrip]] + - [[CompilerCmdLine|Using the Command Line]] + +{{fbdoc item="back" value="CatPgCompOpt|Compiler Options"}} \ No newline at end of file diff --git a/doc/manual/cache/DevBootstrap.wakka b/doc/manual/cache/DevBootstrap.wakka index d88857ac12..d0bfc52587 100644 --- a/doc/manual/cache/DevBootstrap.wakka +++ b/doc/manual/cache/DevBootstrap.wakka @@ -4,13 +4,15 @@ fbc is written in FB itself, so you need a working fbc to build a new fbc. How t {{fbdoc item="section" value="Bootstrapping using the FreeBASIC-x.xx.x-source-bootstrap package (if available)"}} - The ""FreeBASIC-x.xx.x-source-bootstrap"" package contains the FB sources plus precompiled compiler sources, for multiple targets. After extracting, this can be built without requiring an existing fbc: + The ""FreeBASIC-x.xx.x-source-bootstrap"" package contains the FB sources plus precompiled compiler sources, for multiple targets. After extracting, this can be built without requiring an existing fbc (as long as the package contains the precompiled sources for the target system): %%make bootstrap%% - (as long as the package contains the precompiled sources for the target system) + + To create a minimal build of fbc compiler, only building the components needed to recompile the fbc compiler itself: + %%make bootstrap-minimal%% This package can be created by running: %%make bootstrap-dist%% - + {{fbdoc item="section" value="Bootstrapping by creating and using a bootstrap package"}} 1) On a system with a working fbc compiler, create the bootstrap package: diff --git a/doc/manual/cache/GfxScancodes.wakka b/doc/manual/cache/GfxScancodes.wakka index d09fc46b75..b6fc766acc 100644 --- a/doc/manual/cache/GfxScancodes.wakka +++ b/doc/manual/cache/GfxScancodes.wakka @@ -91,11 +91,10 @@ SC_INSERT &h52 SC_DELETE &h53 SC_F11 &h57 SC_F12 &h58 - '' Extra scancodes not compatible with DOS scancodes -SC_LWIN &h7D -SC_RWIN &h7E -SC_MENU &h7F +SC_LWIN &h5B +SC_RWIN &h5C +SC_MENU &h5D %% {{fbdoc item="see"}} diff --git a/doc/manual/cache/KeyPgAllocate.wakka b/doc/manual/cache/KeyPgAllocate.wakka index b76b07e904..ac25a94ef4 100644 --- a/doc/manual/cache/KeyPgAllocate.wakka +++ b/doc/manual/cache/KeyPgAllocate.wakka @@ -60,8 +60,7 @@ Allocates a block of memory from the free store %% Output is: - <<## 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377## - <<::c:: + %% 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377%% It is important to free allocated memory if it's not going to be used anymore. Unused memory that isn't freed is simply wasting memory, and if the address of that memory is somehow overwritten or forgotten, that memory can never be freed. This condition is known as a memory leak, and should be avoided at all costs. Note that leaked memory is always completely freed when the application terminates, either by an "ordinary" exit or crash, so the leak "persists" only as long as the application runs, nevertheless it's a good habit to free any allocated memory inside your application. The following example demonstrates a function with a memory leak, where the address of allocated memory is lost and isn't and can't be freed anymore. If such a function is called frequently, the total amount of memory wasted can add up quickly. diff --git a/doc/manual/cache/KeyPgAny.wakka b/doc/manual/cache/KeyPgAny.wakka index 0a464c32a6..d2a0660d41 100644 --- a/doc/manual/cache/KeyPgAny.wakka +++ b/doc/manual/cache/KeyPgAny.wakka @@ -100,9 +100,9 @@ Dim c(Any, Any, Any) As Integer ' 3-dimensional dynamic array ' etc. ' Further Redims or array accesses must have a matching amount of dimensions -Redim a(0 to 1) As Integer -Redim b(1 to 10, 2 to 5) As Integer -Redim c(0 to 9, 0 to 5, 0 to 1) As Integer +Redim a(0 to 1) +Redim b(1 to 10, 2 to 5) +Redim c(0 to 9, 0 to 5, 0 to 1) %% {{fbdoc item="lang"}} diff --git a/doc/manual/cache/KeyPgBoolean.wakka b/doc/manual/cache/KeyPgBoolean.wakka index e5ff879424..15a8dcf854 100644 --- a/doc/manual/cache/KeyPgBoolean.wakka +++ b/doc/manual/cache/KeyPgBoolean.wakka @@ -33,6 +33,7 @@ Print "boolvar = ", boolvar - New to ""FreeBASIC"" {{fbdoc item="see"}} + - ##[[KeyPgCbool|Cbool]]## - ##[[KeyPgTrue|True]]## - ##[[KeyPgFalse|False]]## diff --git a/doc/manual/cache/KeyPgBsave.wakka b/doc/manual/cache/KeyPgBsave.wakka index d5c3eaed2e..cc2d082951 100644 --- a/doc/manual/cache/KeyPgBsave.wakka +++ b/doc/manual/cache/KeyPgBsave.wakka @@ -54,9 +54,35 @@ CLS LOCATE 13, 15: PRINT "Hello world!" -' Save as BMP +' Save screen as BMP BSAVE "hello.bmp", 0 %% +Save image buffer to bitmap file: +{{fbdoc item="filename" value="examples/manual/gfx/bsave2.bas"}}%%(freebasic) +'set graphics screen 640 x 480 pixels, 32 bit colors +Const W = 640, H = 480 'width & hight +Screenres W, H, 32 +'draw a smiley at screen center +Circle (W \ 2, H \ 2), 180, &h00ffff00, , , , f 'yellow circle +Circle (W \ 2 - 55, H \ 2 - 70), 35, &h00000000, , , 1.5, f 'left eye +Circle (W \ 2 + 55, H \ 2 - 60), 35, &h00000000, , , 1.5, f 'right eye +Circle (W \ 2, H \ 2 + 80), 70, &h00000000, , , 0.4, f 'mouth +'allocate memory for image buffer +Dim As Any Ptr pImageBuffer = Imagecreate(250, 250) +'copy screen section to buffer +Get (W \ 2 - 125, H \ 2 - 125)-step(250 - 1, 250 - 1), pImageBuffer +'save image buffer to file +Dim As String fileName = "Smiley.bmp" +If Bsave(fileName, pImageBuffer) = 0 Then + Print "Saved succesful: " + fileName +Else + Print "Error saving: " + fileName +End If +'free memory for image buffer +Imagedestroy(pImageBuffer) +'keep graphics screen open until key press +Sleep +%% {{fbdoc item="diff"}} - Support for saving more than 64KiB of arbitrary data is new to ""FreeBASIC"". diff --git a/doc/manual/cache/KeyPgCircle.wakka b/doc/manual/cache/KeyPgCircle.wakka index 177520905d..70a32f5166 100644 --- a/doc/manual/cache/KeyPgCircle.wakka +++ b/doc/manual/cache/KeyPgCircle.wakka @@ -48,6 +48,8 @@ Graphics statement to draw an ellipse or a circle ##F## is the fill flag. If you specify this flag, the circle/ellipse will be filled with the selected color. This only takes effect if you are drawing a full circle/ellipse. Custom coordinates system set up by ##[[KeyPgWindow|Window]]## and/or ##[[KeyPgViewgraphics|View (Graphics)]]## affect the drawing operation; clipping set by ##[[KeyPgViewgraphics|View]]## also applies. When ##**Circle**## finishes drawing, the current graphics cursor position is set to the supplied center. + + **Note:** Curves drawn with ##**Circle**## can induce pixels overdrawn at some locations. Thus, the resultant (blended) color of these overdrawn pixels is affected if a transparent color (in conjunction with the ##GFX_ALPHA_PRIMITIVES## option flag) is used. {{fbdoc item="ex"}} {{fbdoc item="filename" value="examples/manual/gfx/circle.bas"}}%%(freebasic) diff --git a/doc/manual/cache/KeyPgCommon.wakka b/doc/manual/cache/KeyPgCommon.wakka index 4fe854a20a..be5c917157 100644 --- a/doc/manual/cache/KeyPgCommon.wakka +++ b/doc/manual/cache/KeyPgCommon.wakka @@ -21,7 +21,7 @@ Declare Sub initme() Common Shared foo() As Double -Redim foo(0 To 2) As Double +Redim foo(0 To 2) initme() diff --git a/doc/manual/cache/KeyPgInstrrev.wakka b/doc/manual/cache/KeyPgInstrrev.wakka index ed10ba52e6..334da30418 100644 --- a/doc/manual/cache/KeyPgInstrrev.wakka +++ b/doc/manual/cache/KeyPgInstrrev.wakka @@ -20,9 +20,13 @@ Locates the last occurrence of a substring or character within a string The position of the last occurrence of ##//substring//## in ##//str//##. {{fbdoc item="desc"}} - Locates the position of the last occurrence of a substring or character within a string. If ##//start//## parameter is not given or is -1, the search begins at the last character. + Locates the position of the last occurrence of a substring or character within a string. If ##//start//## parameter is not given or is less than zero, the search begins at the last character. - Zero (0) is returned if: either ##//substring//## is not found, or either ##//str//## or ##//substring//## are empty strings, or ##//start//## is less than 1 (except for -1), or start is greater than the length of ##//str//##. + Zero (0) is returned if: + - ##//substring//## is not found, or + - either ##//str//## or ##//substring//## is an empty strings, or + - ##//start//## is zero, or + - start is greater than the length of ##//str//##. If the ##**Any**## keyword is specified, ##**Instrrev**## returns the last occurrence of any character in ##//substring//##. diff --git a/doc/manual/cache/KeyPgLinegraphics.wakka b/doc/manual/cache/KeyPgLinegraphics.wakka index 2f1d088041..f83e223f7e 100644 --- a/doc/manual/cache/KeyPgLinegraphics.wakka +++ b/doc/manual/cache/KeyPgLinegraphics.wakka @@ -34,6 +34,8 @@ Draws a line ##//Style//##, if specified, allows styled line drawing; its value is interpreted as a 16-bit bitmask, and ##**Line**## will use it to skip pixel drawing. Starting at ##(//x1//,//y1//)##, the most significant bit of the style mask is checked: if ##1##, the pixel is drawn, if ##0##, it's skipped. This repeats for all the line pixels with the other bits, with the mask being reused when the 16 bits are all checked. When ##**Line**## is used as ##**Line** - (x2, y2)##, a line is drawn from the current cursor position to the ##(//x2//,//y2//)## coordinates specified by ##**Line**##. Alternatively, ##[[KeyPgPoint|Point]]## can be used to get the current cursor position. + + **Note:** Either chained use or boxes drawn with ##**Line**## can induce pixels overdrawn at some locations. Thus, the resultant (blended) color of these overdrawn pixels is affected if a transparent color (in conjunction with the ##GFX_ALPHA_PRIMITIVES## option flag) is used. {{fbdoc item="ex"}} {{fbdoc item="filename" value="examples/manual/gfx/line.bas"}}%%(freebasic) diff --git a/doc/manual/cache/KeyPgOpNew.wakka b/doc/manual/cache/KeyPgOpNew.wakka index a0910ef747..32a0f33460 100644 --- a/doc/manual/cache/KeyPgOpNew.wakka +++ b/doc/manual/cache/KeyPgOpNew.wakka @@ -24,7 +24,7 @@ Operator to dynamically allocate memory and construct data of a specified type. For simple types, like integers, an initial value can be given. For types without constructors, initial values can be specified for each field (either with default initializer at data-field declaration, or with initializer list as in ##**New** //datatype// (**initializers, ..**)## if all type data-fields are numeric primitives only and without any default initializers). For types with at least one constructor, the initialize list (if any) must match an existing constructor. If no initializers are given, the default values for those types will be set. - ##**New[] Expression**## operator is the array-version of the ##**New Expression**## operator and allocates enough memory for the specified number of objects. The default constructor for the type will be used to set the initial values for each item. + ##**New[] Expression**## operator is the (one-dimensional) array-version of the ##**New Expression**## operator and allocates enough memory for the specified number of objects. The default constructor for the type will be used to set the initial values for each item. Objects created with ##**New Expression**## operator must be freed with ##[[KeyPgOpDelete|Delete Statement]]## operator. Object array created with ##**New[] Expression**## operator must be freed with ##**Delete[] Statement**## operator, the array-version of ##[[KeyPgOpDelete|Delete Statement]]## operator. You cannot mix and match the different versions of the operators. @@ -50,6 +50,12 @@ scope ' Create and initialize a "rational" and store its address. dim p as Rational ptr = new Rational(3, 4) + + ' test if null return pointer + if (p = 0) then + print "Error: unable to allocate memory, quitting." + end -1 + end if print p->numerator & "/" & p->denominator @@ -63,6 +69,12 @@ scope ' Allocate memory for 100 integers and store the address of the first one. dim p as integer ptr = new integer[100] + ' test if null return pointer + if (p = 0) then + print "Error: unable to allocate memory, quitting." + end -1 + end if + ' Assign some values to the integers in the array. for i as integer = 0 to 99 p[i] = i @@ -72,7 +84,78 @@ scope delete[] p end scope + +sleep +%% + +{{fbdoc item="filename" value="examples/manual/operator/nested_new.bas"}}%%(freebasic) +'' Example of nested New [] to get a 2-dimentional object array (4*3) + +type UDT + dim as integer N + declare constructor () + declare destructor () +end type + +constructor UDT () + print "Constructor", +end constructor + +destructor UDT () + print "Destructor", +end destructor + +dim as UDT ptr ptr p = new UDT ptr [4] '' New [] allocation for the first dimension: + '' no internal allocation of extra uinteger because + '' allocation of array of pointers (to UDT objects with destructor) +for I as integer = 0 to 3 + p[I] = new UDT [5] '' New [] allocations for the last dimension: + '' internal allocation of an extra uinteger for each New [], + '' because allocation of an array of UDT objects with destructor + print +next I + +for I as integer = 0 to 3 + for J as integer = 0 to 4 + p[I][J].N = I * 10 + J '' assignment of each object array element + next J +next I + +print +for I as integer = 0 to 3 + for J as integer = 0 to 4 + print p[I][J].N, '' display of each object array element + next J + print +next I +print + +for I as integer = 0 to 3 + delete [] p[I] '' Delete [] deallocations for the last dimension + print +next I +delete [] p '' Delete [] deallocation for the first dimension) +print + +sleep %% + + Output example: + %% +Constructor Constructor Constructor Constructor Constructor +Constructor Constructor Constructor Constructor Constructor +Constructor Constructor Constructor Constructor Constructor +Constructor Constructor Constructor Constructor Constructor + + 0 1 2 3 4 + 10 11 12 13 14 + 20 21 22 23 24 + 30 31 32 33 34 + +Destructor Destructor Destructor Destructor Destructor +Destructor Destructor Destructor Destructor Destructor +Destructor Destructor Destructor Destructor Destructor +Destructor Destructor Destructor Destructor Destructor%% {{fbdoc item="lang"}} - Only available in the //[[CompilerOptlang|-lang fb]]// dialect. diff --git a/doc/manual/cache/KeyPgOpNewOverload.wakka b/doc/manual/cache/KeyPgOpNewOverload.wakka index e344036c9f..5ff9195c17 100644 --- a/doc/manual/cache/KeyPgOpNewOverload.wakka +++ b/doc/manual/cache/KeyPgOpNewOverload.wakka @@ -16,7 +16,7 @@ Member operator to overload dynamic memory allocation process part provided by # The member operator ##**New Overload**## overloads the dynamic memory allocation process part provided by the ##[[KeyPgOpNew|New Expression]]## operator when applying to a UDT (User Defined Type). So the user can define its own dynamic memory allocation process part. But after that, the UDT instance construction process part provided by the ##[[KeyPgOpNew|New Expression]]## operator is not modified. - ##**New[] Overload**## operator is the array-version of the ##**New Overload**## operator and overloads the dynamic memory allocation process provided by the ##**New[] Expression**## operator when applying to a UDT (User Defined Type). + ##**New[] Overload**## operator is the (one-dimensional) array-version of the ##**New Overload**## operator and overloads the dynamic memory allocation process provided by the ##**New[] Expression**## operator when applying to a UDT (User Defined Type). Memory allocated with ##**New Overload**## operator must be freed by also defining a ##[[KeyPgOpDeleteOverload|Delete Overload]]## operator. Memory allocated with ##**New[] Overload**## operator must be freed by also defining a ##**Delete[] Overload**## operator, the array-version of ##[[KeyPgOpDeleteOverload|Delete Overload]]## operator. You cannot mix and match the different versions of the operators. diff --git a/doc/manual/cache/KeyPgOpPlacementNew.wakka b/doc/manual/cache/KeyPgOpPlacementNew.wakka index 145d655d04..07e5570225 100644 --- a/doc/manual/cache/KeyPgOpPlacementNew.wakka +++ b/doc/manual/cache/KeyPgOpPlacementNew.wakka @@ -30,7 +30,7 @@ Operator to construct an object at a specified memory address. It is incorrect to call ##[[KeyPgOpDelete|Delete Statement]]## on the address. The proper way is to only call the destructor if one exists (implicitly or explicitly), with syntax as for a member method by using member access operator. See examples below for proper ##**Placement New**## operator usage. - ##**Placement New[]**## operator is the array-version of the ##**Placement New**## operator and constructs the specified number of objects from the specified memory location. The default constructor for the type will be used to set the initial values for each item. + ##**Placement New[]**## operator is the (one-dimensional) array-version of the ##**Placement New**## operator and constructs the specified number of objects from the specified memory location. The default constructor for the type will be used to set the initial values for each item. Specifying an initial value of ##[[KeyPgAny|Any]]##, as in ##**New**(//address//)//datatype// (**Any**)## or ##**New**(//address//)//datatype//[//count//] {**Any**}## will not initialize the data. This is only valid on data types that do not have constructors (otherwise for data types with constructors, syntax of simple pointer conversion, like //Cptr(datatype Ptr, address)//, can be substituted to the invalid use of New...Any). diff --git a/doc/manual/cache/KeyPgOptiondynamic.wakka b/doc/manual/cache/KeyPgOptiondynamic.wakka index c1706c2666..ea5b797234 100644 --- a/doc/manual/cache/KeyPgOptiondynamic.wakka +++ b/doc/manual/cache/KeyPgOptiondynamic.wakka @@ -19,7 +19,7 @@ Option Dynamic Dim bar(99) As Integer ' declares a variable-length array ' ... -ReDim bar(199) As Integer ' resize the array +ReDim bar(199) ' resize the array %% {{fbdoc item="lang"}} - Only available in the //[[CompilerOptlang|-lang fblite]]// and //[[CompilerOptlang|-lang qb]]// dialects. diff --git a/doc/manual/cache/KeyPgPaint.wakka b/doc/manual/cache/KeyPgPaint.wakka index 17be76d303..7a17a748ed 100644 --- a/doc/manual/cache/KeyPgPaint.wakka +++ b/doc/manual/cache/KeyPgPaint.wakka @@ -34,6 +34,8 @@ Fills an area delimited by a border of a specified color ##size = (8 * 8) * 4 = 256## If the passed string is smaller, missing pixels will be 0. If the ##//paint//## argument is omitted, normal filling is performed using the current foreground color set by ##[[KeyPgColor|Color]]##. Flood-filling continues until pixels of the specified border color are found; if ##//border_color//## is omitted, the current background color is assumed. + + **Warning:** If the border is drawn with a transparent color (in conjunction with the ##GFX_ALPHA_PRIMITIVES## option flag) and some pixels are overdrawn on it, the resultant (blended) color of these overdrawn pixels can cause a leak point through which the fill color escapes outside the border. So drawing a border with a transparent color is not recommended. {{fbdoc item="ex"}} {{fbdoc item="filename" value="examples/manual/gfx/paint.bas"}}%%(freebasic) diff --git a/doc/manual/cache/KeyPgPutfileio.wakka b/doc/manual/cache/KeyPgPutfileio.wakka index 1b17442b96..cc19f8b9ce 100644 --- a/doc/manual/cache/KeyPgPutfileio.wakka +++ b/doc/manual/cache/KeyPgPutfileio.wakka @@ -77,7 +77,6 @@ Put #f, 1, buffer() Close #f %% -{{fbdoc item="ex"}} {{fbdoc item="filename" value="examples/manual/fileio/put-buffer.bas"}}%%(freebasic) Dim As Byte Ptr lpBuffer Dim As Integer hFile, Counter, Size diff --git a/doc/manual/cache/KeyPgRedim.wakka b/doc/manual/cache/KeyPgRedim.wakka index 49e7857f8d..059fc099a7 100644 --- a/doc/manual/cache/KeyPgRedim.wakka +++ b/doc/manual/cache/KeyPgRedim.wakka @@ -48,7 +48,7 @@ Next '' Resize a variable-length array with 10 elements '' (the lower bound should be kept the same) -ReDim Preserve array(0 to 9) As Integer +ReDim Preserve array(0 to 9) Print "index", "value" For index As Integer = LBound(array) To UBound(array) @@ -94,7 +94,7 @@ Print '' ReDim Preserve array to have 4*4 elements, preserving the contents '' (only the first upper bound should be changed) -ReDim Preserve array(1 To 4, 1 To 4) As Integer +ReDim Preserve array(1 To 4, 1 To 4) Print "4 * 4:" Print @@ -109,7 +109,7 @@ Print '' ReDim Preserve array to have 2*4 elements, preserving but trancating the contents '' (only the first upper bound should be changed) -ReDim Preserve array(1 To 2, 1 To 4) As Integer +ReDim Preserve array(1 To 2, 1 To 4) Print "2 * 4:" Print diff --git a/doc/manual/cache/KeyPgScreencontrol.wakka b/doc/manual/cache/KeyPgScreencontrol.wakka index a0c99d4042..6017d2d8b6 100644 --- a/doc/manual/cache/KeyPgScreencontrol.wakka +++ b/doc/manual/cache/KeyPgScreencontrol.wakka @@ -123,10 +123,10 @@ Sets or gets internal graphics library settings - (""**"") ##SET_GL_2D_MODE## Sets OpenGL 2D render [IN] ##//param1//##: ##OGL_2D_NONE## No rendering - ##OGL_2D_MANUAL_SYNC## Manual rendering (when ##[[KeyPgFlip|Flip]]##/##[[KeyPgScreencopy|ScreenCopy]]## is called) + ##OGL_2D_MANUAL_SYNC## Manual rendering (when ##[[KeyPgFlip|Flip]]## is called) ##OGL_2D_AUTO_SYNC## Automatic rendering - (""**"") ##SET_GL_SCALE## Apply a zoom factor on OpenGL 2D render (only allowed if OpenGL 2D render mode has yet been activated via ##SET_GL_2D_MODE##) - [IN] ##//param1//## Zoom factor (0: no rendering) + [IN] ##//param1//## zoom factor (0: no rendering) **Other operations** - ##POLL_EVENTS## Cause the library to poll all events, ie to check the system event queue, specifically used for retrieving keyboard and mouse events. This is most useful for ""OpenGL"" code where ##[[KeyPgFlip|Flip]]## is not used, as normally ##[[KeyPgFlip|Flip]]## will cause these events to be polled. diff --git a/doc/manual/cache/KeyPgSwap.wakka b/doc/manual/cache/KeyPgSwap.wakka index fa8f4d1d0c..812cb701d8 100644 --- a/doc/manual/cache/KeyPgSwap.wakka +++ b/doc/manual/cache/KeyPgSwap.wakka @@ -12,6 +12,10 @@ Exchanges the values of two variables {{fbdoc item="desc"}} Swaps the value of two variables, including UDT instances (swaps all data members). + + **Note:** When the data are referenced by a pointer, alone or within a descriptive structure (a UDT, for example), ##**Swap**## only exchanges the values of the pointers or the contents of the descriptive structures without accessing data themselves. + For var-len strings, ##**Swap**## only exchanges the descriptors of the strings rather than reallocate memory for exchange all strings data characters. + For UDTs, ##**Swap**## simply exchanges the contents of the structures, without any operators or methods being called. {{fbdoc item="ex"}} {{fbdoc item="filename" value="examples/manual/memory/swap.bas"}}%%(freebasic) diff --git a/doc/manual/cache/KeyPgWchr.wakka b/doc/manual/cache/KeyPgWchr.wakka index 039601e8fd..8b48d3b2ea 100644 --- a/doc/manual/cache/KeyPgWchr.wakka +++ b/doc/manual/cache/KeyPgWchr.wakka @@ -27,11 +27,9 @@ print "The character represented by the UNICODE code of 934 is: "; WCHR(934) print "Multiple UNICODE characters: "; WCHR(933, 934, 935) %% will produce the output: - -< Date: Mon, 20 May 2019 11:00:09 -0400 Subject: [PATCH 03/14] fbdoc: examples/manual update 2019-05-20 --- examples/manual/array/redim.bas | 2 +- examples/manual/array/redim2d.bas | 4 +- examples/manual/gfx/bsave.bas | 2 +- examples/manual/gfx/bsave2.bas | 31 +++++++++++ examples/manual/misc/any-dynamic-array.bas | 6 +-- examples/manual/module/common1.bas | 2 +- examples/manual/operator/nested_new.bas | 57 +++++++++++++++++++++ examples/manual/operator/new.bas | 14 +++++ examples/manual/proguide/arrays/array3.bas | 2 +- examples/manual/proguide/primer/primer5.bas | 2 +- examples/manual/switches/option-dynamic.bas | 2 +- 11 files changed, 113 insertions(+), 11 deletions(-) create mode 100644 examples/manual/gfx/bsave2.bas create mode 100644 examples/manual/operator/nested_new.bas diff --git a/examples/manual/array/redim.bas b/examples/manual/array/redim.bas index 01431ead23..ea3e98b79b 100644 --- a/examples/manual/array/redim.bas +++ b/examples/manual/array/redim.bas @@ -15,7 +15,7 @@ Next '' Resize a variable-length array with 10 elements '' (the lower bound should be kept the same) -ReDim Preserve array(0 To 9) As Integer +ReDim Preserve array(0 To 9) Print "index", "value" For index As Integer = LBound(array) To UBound(array) diff --git a/examples/manual/array/redim2d.bas b/examples/manual/array/redim2d.bas index 21ba7a9bee..724ab14894 100644 --- a/examples/manual/array/redim2d.bas +++ b/examples/manual/array/redim2d.bas @@ -29,7 +29,7 @@ Print '' ReDim Preserve array to have 4*4 elements, preserving the contents '' (only the first upper bound should be changed) -ReDim Preserve array(1 To 4, 1 To 4) As Integer +ReDim Preserve array(1 To 4, 1 To 4) Print "4 * 4:" Print @@ -44,7 +44,7 @@ Print '' ReDim Preserve array to have 2*4 elements, preserving but trancating the contents '' (only the first upper bound should be changed) -ReDim Preserve array(1 To 2, 1 To 4) As Integer +ReDim Preserve array(1 To 2, 1 To 4) Print "2 * 4:" Print diff --git a/examples/manual/gfx/bsave.bas b/examples/manual/gfx/bsave.bas index 33be56bea2..8e34db0463 100644 --- a/examples/manual/gfx/bsave.bas +++ b/examples/manual/gfx/bsave.bas @@ -15,5 +15,5 @@ Cls Locate 13, 15: Print "Hello world!" -' Save as BMP +' Save screen as BMP BSave "hello.bmp", 0 diff --git a/examples/manual/gfx/bsave2.bas b/examples/manual/gfx/bsave2.bas new file mode 100644 index 0000000000..20b28185b9 --- /dev/null +++ b/examples/manual/gfx/bsave2.bas @@ -0,0 +1,31 @@ +'' examples/manual/gfx/bsave2.bas +'' +'' NOTICE: This file is part of the FreeBASIC Compiler package and can't +'' be included in other distributions without authorization. +'' +'' See Also: https://www.freebasic.net/wiki/wikka.php?wakka=KeyPgBsave +'' -------- + +'set graphics screen 640 x 480 pixels, 32 bit colors +Const W = 640, H = 480 'width & hight +ScreenRes W, H, 32 +'draw a smiley at screen center +Circle (W \ 2, H \ 2), 180, &h00ffff00, , , , f 'yellow circle +Circle (W \ 2 - 55, H \ 2 - 70), 35, &h00000000, , , 1.5, f 'left eye +Circle (W \ 2 + 55, H \ 2 - 60), 35, &h00000000, , , 1.5, f 'right eye +Circle (W \ 2, H \ 2 + 80), 70, &h00000000, , , 0.4, f 'mouth +'allocate memory for image buffer +Dim As Any Ptr pImageBuffer = ImageCreate(250, 250) +'copy screen section to buffer +Get (W \ 2 - 125, H \ 2 - 125)-Step(250 - 1, 250 - 1), pImageBuffer +'save image buffer to file +Dim As String fileName = "Smiley.bmp" +If BSave(fileName, pImageBuffer) = 0 Then + Print "Saved succesful: " + fileName +Else + Print "Error saving: " + fileName +End If +'free memory for image buffer +ImageDestroy(pImageBuffer) +'keep graphics screen open until key press +Sleep diff --git a/examples/manual/misc/any-dynamic-array.bas b/examples/manual/misc/any-dynamic-array.bas index 685df62bef..78a6e65f69 100644 --- a/examples/manual/misc/any-dynamic-array.bas +++ b/examples/manual/misc/any-dynamic-array.bas @@ -12,6 +12,6 @@ Dim c(Any, Any, Any) As Integer ' 3-dimensional dynamic array ' etc. ' Further Redims or array accesses must have a matching amount of dimensions -ReDim a(0 To 1) As Integer -ReDim b(1 To 10, 2 To 5) As Integer -ReDim c(0 To 9, 0 To 5, 0 To 1) As Integer +ReDim a(0 To 1) +ReDim b(1 To 10, 2 To 5) +ReDim c(0 To 9, 0 To 5, 0 To 1) diff --git a/examples/manual/module/common1.bas b/examples/manual/module/common1.bas index 8fe2a39101..6e842ed92e 100644 --- a/examples/manual/module/common1.bas +++ b/examples/manual/module/common1.bas @@ -12,7 +12,7 @@ Declare Sub initme() Common Shared foo() As Double -ReDim foo(0 To 2) As Double +ReDim foo(0 To 2) initme() diff --git a/examples/manual/operator/nested_new.bas b/examples/manual/operator/nested_new.bas new file mode 100644 index 0000000000..9a7d26d3cf --- /dev/null +++ b/examples/manual/operator/nested_new.bas @@ -0,0 +1,57 @@ +'' examples/manual/operator/nested_new.bas +'' +'' NOTICE: This file is part of the FreeBASIC Compiler package and can't +'' be included in other distributions without authorization. +'' +'' See Also: https://www.freebasic.net/wiki/wikka.php?wakka=KeyPgOpNew +'' -------- + +'' Example of nested New [] to get a 2-dimentional object array (4*3) + +Type UDT + Dim As Integer N + Declare Constructor () + Declare Destructor () +End Type + +Constructor UDT () + Print "Constructor", +End Constructor + +Destructor UDT () + Print "Destructor", +End Destructor + +Dim As UDT Ptr Ptr p = New UDT Ptr [4] '' New [] allocation for the first dimension: + '' no internal allocation of extra uinteger because + '' allocation of array of pointers (to UDT objects with destructor) +For I As Integer = 0 To 3 + p[I] = New UDT [5] '' New [] allocations for the last dimension: + '' internal allocation of an extra uinteger for each New [], + '' because allocation of an array of UDT objects with destructor + Print +Next I + +For I As Integer = 0 To 3 + For J As Integer = 0 To 4 + p[I][J].N = I * 10 + J '' assignment of each object array element + Next J +Next I + +Print +For I As Integer = 0 To 3 + For J As Integer = 0 To 4 + Print p[I][J].N, '' display of each object array element + Next J + Print +Next I +Print + +For I As Integer = 0 To 3 + Delete [] p[I] '' Delete [] deallocations for the last dimension + Print +Next I +Delete [] p '' Delete [] deallocation for the first dimension) +Print + +Sleep diff --git a/examples/manual/operator/new.bas b/examples/manual/operator/new.bas index 8d498fb6e4..2f08ea6d88 100644 --- a/examples/manual/operator/new.bas +++ b/examples/manual/operator/new.bas @@ -14,6 +14,12 @@ Scope ' Create and initialize a "rational" and store its address. Dim p As Rational Ptr = New Rational(3, 4) + + ' test if null return pointer + If (p = 0) Then + Print "Error: unable to allocate memory, quitting." + End -1 + End If Print p->numerator & "/" & p->denominator @@ -27,6 +33,12 @@ Scope ' Allocate memory for 100 integers and store the address of the first one. Dim p As Integer Ptr = New Integer[100] + ' test if null return pointer + If (p = 0) Then + Print "Error: unable to allocate memory, quitting." + End -1 + End If + ' Assign some values to the integers in the array. For i As Integer = 0 To 99 p[i] = i @@ -36,3 +48,5 @@ Scope Delete[] p End Scope + +Sleep diff --git a/examples/manual/proguide/arrays/array3.bas b/examples/manual/proguide/arrays/array3.bas index f067f2e57a..c76e743010 100644 --- a/examples/manual/proguide/arrays/array3.bas +++ b/examples/manual/proguide/arrays/array3.bas @@ -14,4 +14,4 @@ Dim flarray(1 To totalSingles) As Single Dim vlarray() As Integer ' Resizes the array to 10 elements. -ReDim vlarray(1 To 10) As Integer +ReDim vlarray(1 To 10) diff --git a/examples/manual/proguide/primer/primer5.bas b/examples/manual/proguide/primer/primer5.bas index f3f7245ec1..61b707cab0 100644 --- a/examples/manual/proguide/primer/primer5.bas +++ b/examples/manual/proguide/primer/primer5.bas @@ -13,5 +13,5 @@ b = 7 c = a + b Print "a = "; a -Print "a = "; b +Print "b = "; b Print "a + b = "; c diff --git a/examples/manual/switches/option-dynamic.bas b/examples/manual/switches/option-dynamic.bas index 6a338f3afa..bac36ee508 100644 --- a/examples/manual/switches/option-dynamic.bas +++ b/examples/manual/switches/option-dynamic.bas @@ -16,4 +16,4 @@ Option Dynamic Dim bar(99) As Integer ' declares a variable-length array ' ... -ReDim bar(199) As Integer ' resize the array +ReDim bar(199) ' resize the array From a8ba803b060af0958a843894f875acfd84f4c16d Mon Sep 17 00:00:00 2001 From: coderJeff Date: Mon, 20 May 2019 12:32:42 -0400 Subject: [PATCH 04/14] fbdoc: internal rename webPage* => page*. - Names are page names. - Same name is used for database, wiki, file, output, etc. --- doc/fbchkdoc/cmd_opts.bas | 24 ++++++++++---------- doc/fbchkdoc/cmd_opts.bi | 6 ++--- doc/fbchkdoc/getpage.bas | 20 ++++++++--------- doc/fbchkdoc/mkimglst.bas | 8 +++---- doc/fbchkdoc/putpage.bas | 10 ++++----- doc/fbchkdoc/rebuild.bas | 6 ++--- doc/fbchkdoc/samps.bas | 46 +++++++++++++++++++-------------------- doc/fbchkdoc/spell.bas | 8 +++---- doc/fbdoc/fbdoc.bas | 34 ++++++++++++++--------------- 9 files changed, 81 insertions(+), 81 deletions(-) diff --git a/doc/fbchkdoc/cmd_opts.bas b/doc/fbchkdoc/cmd_opts.bas index 8935c8021f..de8de968f1 100644 --- a/doc/fbchkdoc/cmd_opts.bas +++ b/doc/fbchkdoc/cmd_opts.bas @@ -156,9 +156,9 @@ sub cmd_opts_init( byval opts_flags as const CMD_OPTS_ENABLE_FLAGS ) app_opt.image_dir = "" '' export: image directory app_opt.manual_dir = "" '' export: manual directory - app_opt.webPageCount = 0 - redim app_opt.webPageList(1 to 1) as string - redim app_opt.webPageComments(1 to 1) as string + app_opt.pageCount = 0 + redim app_opt.pageList(1 to 1) as string + redim app_opt.pageComments(1 to 1) as string if( command(1) = "" ) then app_opt.help = true @@ -188,15 +188,15 @@ sub cmd_opts_unexpected_die( byval i as const integer ) end sub '' -sub cmd_opts_add_webpage( byref pagename as const string, byref cmt as const string ) +sub cmd_opts_add_page( byref pagename as const string, byref cmt as const string ) with app_opt - .webPageCount += 1 - if( .webPageCount > ubound(.webPageList) ) then - redim preserve .webPageList(1 to Ubound(.webPageList) * 2) - redim preserve .webPageComments(1 to Ubound(.webPageComments) * 2) + .pageCount += 1 + if( .pageCount > ubound(.pageList) ) then + redim preserve .pageList(1 to Ubound(.pageList) * 2) + redim preserve .pageComments(1 to Ubound(.pageComments) * 2) end if - .webPageList(.webPageCount) = pagename - .webPageComments(.webPageCount) = cmt + .pageList(.pageCount) = pagename + .pageComments(.pageCount) = cmt end with end sub @@ -375,14 +375,14 @@ function cmd_opts_read( byref i as integer ) as boolean line input #h, x x = ParsePageName( x, cmt ) if( x > "" ) then - cmd_opts_add_webpage( x, cmt ) + cmd_opts_add_page( x, cmt ) end if wend close #h end if end scope else - cmd_opts_add_webpage( command(i), "" ) + cmd_opts_add_page( command(i), "" ) end if else diff --git a/doc/fbchkdoc/cmd_opts.bi b/doc/fbchkdoc/cmd_opts.bi index 35b2968517..f9d28c12e3 100644 --- a/doc/fbchkdoc/cmd_opts.bi +++ b/doc/fbchkdoc/cmd_opts.bi @@ -57,9 +57,9 @@ type CMD_OPTS_GLOBAL image_dir as string manual_dir as string - webPageCount as integer - webPageList(any) as string - webPageComments(any) as string + pageCount as integer + pageList(any) as string + pageComments(any) as string end type diff --git a/doc/fbchkdoc/getpage.bas b/doc/fbchkdoc/getpage.bas index 80a37e4c27..aa181d2cd6 100644 --- a/doc/fbchkdoc/getpage.bas +++ b/doc/fbchkdoc/getpage.bas @@ -81,7 +81,7 @@ cmd_opts_resolve() cmd_opts_check() '' no pages? nothing to do... -if( app_opt.webPageCount = 0 ) then +if( app_opt.pageCount = 0 ) then print "no pages specified." end 1 end if @@ -113,24 +113,24 @@ do nfailedpages = 0 - if( app_opt.webPageCount > 0 ) then + if( app_opt.pageCount > 0 ) then dim as integer i, j dim as string ret - for i = 1 to app_opt.webPageCount - ret = LoadPage( app_opt.webPageList(i), FALSE, TRUE ) + for i = 1 to app_opt.pageCount + ret = LoadPage( app_opt.pageList(i), FALSE, TRUE ) if( ret = "" ) then - print "Failed to load '" & app_opt.webPageList(i) & "'" + print "Failed to load '" & app_opt.pageList(i) & "'" nfailedpages += 1 redim preserve failedpages( 1 to nfailedpages ) - failedpages(nfailedpages) = app_opt.webPageList(i) + failedpages(nfailedpages) = app_opt.pageList(i) end if if( inkey = chr(27) ) then - for j = i + 1 to app_opt.webPageCount + for j = i + 1 to app_opt.pageCount nfailedpages += 1 redim preserve failedpages( 1 to nfailedpages ) - failedpages(nfailedpages) = app_opt.webPageList(j) + failedpages(nfailedpages) = app_opt.pageList(j) next exit for @@ -162,9 +162,9 @@ do case "y" for i = 1 to nfailedpages - app_opt.webPageList(i) = failedpages(i) + app_opt.pageList(i) = failedpages(i) next - app_opt.webPageCount = nfailedpages + app_opt.pageCount = nfailedpages exit do diff --git a/doc/fbchkdoc/mkimglst.bas b/doc/fbchkdoc/mkimglst.bas index e4628fa2fb..e122274e9b 100644 --- a/doc/fbchkdoc/mkimglst.bas +++ b/doc/fbchkdoc/mkimglst.bas @@ -116,7 +116,7 @@ cmd_opts_resolve() cmd_opts_check() '' no pages? nothing to do... -if( app_opt.webPageCount = 0 ) then +if( app_opt.pageCount = 0 ) then print "no pages specified." end 1 end if @@ -135,7 +135,7 @@ if wikicache = NULL then end 1 end if -if( app_opt.webPageCount > 0 ) then +if( app_opt.pageCount > 0 ) then dim as integer i, h, h2 dim as string ret @@ -144,9 +144,9 @@ if( app_opt.webPageCount > 0 ) then h2 = freefile open "imagepages.txt" for output as #h2 - for i = 1 to app_opt.webPageCount + for i = 1 to app_opt.pageCount - sPage = app_opt.webPageList(i) + sPage = app_opt.pageList(i) print "Loading '" + sPage + "':" ; if( wikicache->LoadPage( sPage, sBody ) ) = FALSE then diff --git a/doc/fbchkdoc/putpage.bas b/doc/fbchkdoc/putpage.bas index a4ddf44fe1..cb693ab6cc 100644 --- a/doc/fbchkdoc/putpage.bas +++ b/doc/fbchkdoc/putpage.bas @@ -99,7 +99,7 @@ sNoteDef = "" dim as CWikiCache ptr wikicache = NULL dim as CWikiCon ptr wikicon = NULL -if( app_opt.webPageCount = 0 ) then +if( app_opt.pageCount = 0 ) then print "No pages specified" end if @@ -118,7 +118,7 @@ if wikicon = NULL then end if '' we have web pages? go to work... -if( app_opt.webPageCount > 0 ) then +if( app_opt.pageCount > 0 ) then dim as integer i dim as string ret print "URL: "; app_opt.wiki_url @@ -128,9 +128,9 @@ if( app_opt.webPageCount > 0 ) then print "Certificate: none" end if print "cache: "; app_opt.cache_dir - for i = 1 to app_opt.webPageCount - sPage = app_opt.webPageList(i) - sComment = app_opt.webPageComments(i) + for i = 1 to app_opt.pageCount + sPage = app_opt.pageList(i) + sComment = app_opt.pageComments(i) sBody = "" print "Loading '" + sPage + "': "; if( wikicache->LoadPage( sPage, sBody ) ) = FALSE then diff --git a/doc/fbchkdoc/rebuild.bas b/doc/fbchkdoc/rebuild.bas index 4c81fc881c..61699d971e 100644 --- a/doc/fbchkdoc/rebuild.bas +++ b/doc/fbchkdoc/rebuild.bas @@ -94,7 +94,7 @@ cmd_opts_resolve() cmd_opts_check() '' no pages? nothing to do... -if( app_opt.webPageCount = 0 ) then +if( app_opt.pageCount = 0 ) then print "no pages specified." end 1 end if @@ -106,11 +106,11 @@ dim as CWiki ptr wiki print "cache: "; app_opt.cache_dir -for i = 1 to app_opt.webpagecount +for i = 1 to app_opt.pageCount wiki = new CWiki - sPage = app_opt.webpagelist(i) + sPage = app_opt.pageList(i) f = app_opt.cache_dir + sPage + ".wakka" sBody1 = ReadTextFile( f ) diff --git a/doc/fbchkdoc/samps.bas b/doc/fbchkdoc/samps.bas index 81cea63ec2..dcb3dbd04c 100644 --- a/doc/fbchkdoc/samps.bas +++ b/doc/fbchkdoc/samps.bas @@ -138,8 +138,8 @@ dim shared as string base_dir dim shared as string manual_dir dim shared as string wiki_cache_dir -dim shared as integer webPageCount -dim shared webPageList() as string +dim shared as integer pageCount +dim shared pageList() as string dim shared wikicache as CWikiCache ptr = NULL dim shared opt_force as boolean = false @@ -205,9 +205,9 @@ function cmd_check_proc() as integer dim as buffer b1, b2 dim as string ret - for i = 1 to webPageCount + for i = 1 to pageCount - sPage = webPageList(i) + sPage = pageList(i) if( wikicache->LoadPage( sPage, sBody ) ) = FALSE then logprint "Error while loading '" + sPage + "'" @@ -373,9 +373,9 @@ function cmd_extract_proc() as integer dim as string sPage, sBody, filename dim as string ret - for i = 1 to webPageCount + for i = 1 to pageCount - sPage = webPageList(i) + sPage = pageList(i) if( wikicache->LoadPage( sPage, sBody ) ) = FALSE then logprint "Error loading '" + sPage + "'" @@ -413,9 +413,9 @@ function cmd_update_proc() as integer dim as integer nchanges = 0 dim as string ret - for i = 1 to webPageCount + for i = 1 to pageCount - sPage = webPageList(i) + sPage = pageList(i) if( wikicache->LoadPage( sPage, sBody ) ) = FALSE then logprint "Error while loading '" + sPage + "'" @@ -464,9 +464,9 @@ function cmd_set_fb_proc() as integer dim as string sPage, sBody dim as string ret - for i = 1 to webPageCount + for i = 1 to pageCount - sPage = webPageList(i) + sPage = pageList(i) if( wikicache->LoadPage( sPage, sBody ) ) = FALSE then logprint "Error while loading '" + sPage + "'" @@ -495,9 +495,9 @@ function cmd_getex_proc() as integer dim as string sPage, sBody dim as string ret - for i = 1 to webPageCount + for i = 1 to pageCount - sPage = webPageList(i) + sPage = pageList(i) ' if( lcase( left( spage, 3 )) <> "tut" ) then ' if( lcase( left( spage, 5 )) <> "propg" ) then @@ -900,8 +900,8 @@ end if if( (opt and opt_get_pages) <> 0 ) then - webPageCount = 0 - redim webPageList(1 to 1) as string + pageCount = 0 + redim pageList(1 to 1) as string dim as string cmt i = 2 while command(i) > "" @@ -916,11 +916,11 @@ if( (opt and opt_get_pages) <> 0 ) then line input #h, x x = ParsePageName( x, cmt ) if( x > "" ) then - webPageCount += 1 - if( webPageCount > ubound(webPageList) ) then - redim preserve webPageList(1 to Ubound(webPageList) * 2) + pageCount += 1 + if( pageCount > ubound(pageList) ) then + redim preserve pageList(1 to Ubound(pageList) * 2) end if - webPageList(webPageCount) = x + pageList(pageCount) = x end if wend close #h @@ -934,17 +934,17 @@ if( (opt and opt_get_pages) <> 0 ) then logprint "Unrecognized option '" + command(i) + "'" end select else - webPageCount += 1 - if( webPageCount > ubound(webPageList) ) then - redim preserve webPageList(1 to Ubound(webPageList) * 2) + pageCount += 1 + if( pageCount > ubound(pageList) ) then + redim preserve pageList(1 to Ubound(pageList) * 2) end if - webPageList(webPageCount) = command(i) + pageList(pageCount) = command(i) end if i += 1 wend - if( webPageCount = 0 ) then + if( pageCount = 0 ) then logprint "warning: no pages specified." bAbort = TRUE end if diff --git a/doc/fbchkdoc/spell.bas b/doc/fbchkdoc/spell.bas index 5af516ca79..355568c667 100644 --- a/doc/fbchkdoc/spell.bas +++ b/doc/fbchkdoc/spell.bas @@ -376,7 +376,7 @@ cmd_opts_resolve() cmd_opts_check() '' no pages? nothing to do... -if( app_opt.webPageCount = 0 ) then +if( app_opt.pageCount = 0 ) then print "no pages specified." end 1 end if @@ -393,7 +393,7 @@ if wikicache = NULL then end 1 end if -if( app_opt.webPageCount > 0 ) then +if( app_opt.pageCount > 0 ) then dim as integer i, h, h2 dim as string ret @@ -436,9 +436,9 @@ if( app_opt.webPageCount > 0 ) then '' h = freefile '' open "spellcheck.txt" for output as #h - for i = 1 to app_opt.webPageCount + for i = 1 to app_opt.pageCount - sPage = app_opt.webPageList(i) + sPage = app_opt.pageList(i) CurrentPage = sPage haveTitle = FALSE diff --git a/doc/fbdoc/fbdoc.bas b/doc/fbdoc/fbdoc.bas index 2147cf48f3..6a75aa0fd3 100644 --- a/doc/fbdoc/fbdoc.bas +++ b/doc/fbdoc/fbdoc.bas @@ -85,8 +85,8 @@ end sub dim as string SinglePage = "" dim as integer bSinglePage = FALSE - redim as string webPageList(1 to 10) - dim as integer webPageCount = 0, bWebPages = FALSE + redim as string pageList(1 to 10) + dim as integer pageCount = 0, bPages = FALSE dim as string sTocPage = default_TocPage @@ -145,9 +145,9 @@ end sub i = 1 while( len( command(i) ) > 0 ) - if( bWebPages ) then + if( bPages ) then if left( command(i), 1) = "-" then - bWebPages = FALSE + bPages = FALSE else if left( command(i), 1) = "@" then scope @@ -160,22 +160,22 @@ end sub line input #h, x x = trim(x, any " " + chr(9)) if( x > "" ) then - webPageCount += 1 - if( webPageCount > ubound(webPageList) ) then - redim preserve webPageList(1 to Ubound(webPageList) * 2) + pageCount += 1 + if( pageCount > ubound(pageList) ) then + redim preserve pageList(1 to Ubound(pageList) * 2) end if - webPageList(webPageCount) = x + pageList(pageCount) = x end if wend close #h end if end scope else - webPageCount += 1 - if( webPageCount > ubound(webPageList) ) then - redim preserve webPageList(1 to Ubound(webPageList) * 2) + pageCount += 1 + if( pageCount > ubound(pageList) ) then + redim preserve pageList(1 to Ubound(pageList) * 2) end if - webPageList(webPageCount) = command(i) + pageList(pageCount) = command(i) end if end if end if @@ -188,7 +188,7 @@ end sub end if end if - if(( bWebPages = FALSE ) and ( bSinglePage = FALSE )) then + if(( bPages = FALSE ) and ( bSinglePage = FALSE )) then select case lcase(command(i)) case "-makeini" @@ -214,7 +214,7 @@ end sub case "-texinfo" bEmitFormats or= OUT_TEXINFO case "-getpage" - bWebPages = TRUE + bPages = TRUE case "-makepage" bSinglePage = TRUE case "-noscan" @@ -338,11 +338,11 @@ end sub dim as CPageList ptr paglist, toclist, lnklist - if( webPageCount > 0 ) then + if( pageCount > 0 ) then dim as integer i dim as string ret - for i = 1 to webPageCount - ret = LoadPage( webPageList(i), FALSE, TRUE ) + for i = 1 to pageCount + ret = LoadPage( pageList(i), FALSE, TRUE ) next end 0 end if From 5ec4032fb9b0c28fd0bdb450bf1be4600ce76c5d Mon Sep 17 00:00:00 2001 From: coderJeff Date: Mon, 20 May 2019 14:22:03 -0400 Subject: [PATCH 05/14] fbdoc: rename CWikiCon to CWikiConUrl --- doc/fbchkdoc/getindex.bas | 6 +-- doc/fbchkdoc/putpage.bas | 4 +- .../{CWikiCon.bas => CWikiConUrl.bas} | 43 ++++++++++--------- doc/libfbdoc/{CWikiCon.bi => CWikiConUrl.bi} | 20 ++++----- doc/libfbdoc/fbdoc_loader.bas | 2 +- doc/libfbdoc/fbdoc_loader_web.bas | 8 ++-- doc/libfbdoc/fbdoc_loader_web.bi | 4 +- 7 files changed, 44 insertions(+), 43 deletions(-) rename doc/libfbdoc/{CWikiCon.bas => CWikiConUrl.bas} (93%) rename doc/libfbdoc/{CWikiCon.bi => CWikiConUrl.bi} (88%) diff --git a/doc/fbchkdoc/getindex.bas b/doc/fbchkdoc/getindex.bas index 485759a4e0..07530c502c 100644 --- a/doc/fbchkdoc/getindex.bas +++ b/doc/fbchkdoc/getindex.bas @@ -20,7 +20,7 @@ '' chng: written [jeffm] '' fbdoc headers -#include once "CWikiCon.bi" +#include once "CWikiConUrl.bi" '' fbchkdoc headers #include once "fbchkdoc.bi" @@ -309,9 +309,9 @@ else '' connect to the wiki and get PageIndex as HTML scope - dim as CWikiCon ptr wikicon = NULL + dim as CWikiConUrl ptr wikicon = NULL - wikicon = new CWikiCon( app_opt.wiki_url, app_opt.ca_file ) + wikicon = new CWikiConUrl( app_opt.wiki_url, app_opt.ca_file ) if wikicon = NULL then print "Unable to create connection " + app_opt.wiki_url end 1 diff --git a/doc/fbchkdoc/putpage.bas b/doc/fbchkdoc/putpage.bas index cb693ab6cc..3c76ed0e79 100644 --- a/doc/fbchkdoc/putpage.bas +++ b/doc/fbchkdoc/putpage.bas @@ -97,7 +97,7 @@ sNote = "Auto-update" sNoteDef = "" dim as CWikiCache ptr wikicache = NULL -dim as CWikiCon ptr wikicon = NULL +dim as CWikiConUrl ptr wikicon = NULL if( app_opt.pageCount = 0 ) then print "No pages specified" @@ -110,7 +110,7 @@ if wikicache = NULL then end 1 end if -wikicon = new CWikiCon( app_opt.wiki_url, app_opt.ca_file ) +wikicon = new CWikiConUrl( app_opt.wiki_url, app_opt.ca_file ) if wikicon = NULL then print "Unable to create connection " + app_opt.wiki_url delete wikicache diff --git a/doc/libfbdoc/CWikiCon.bas b/doc/libfbdoc/CWikiConUrl.bas similarity index 93% rename from doc/libfbdoc/CWikiCon.bas rename to doc/libfbdoc/CWikiConUrl.bas index 218c44eb9d..3a43e18e9c 100644 --- a/doc/libfbdoc/CWikiCon.bas +++ b/doc/libfbdoc/CWikiConUrl.bas @@ -16,7 +16,7 @@ '' Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA. -'' CWikiCon +'' CWikiConUrl '' '' chng: apr/2006 written [v1ctor] '' chng: sep/2006 updated [coderJeff] @@ -26,11 +26,11 @@ #include once "CHttp.bi" #include once "CHttpForm.bi" #include once "CHttpStream.bi" -#include once "CWikiCon.bi" +#include once "CWikiConUrl.bi" namespace fb.fbdoc - type CWikiConCtx_ + type CWikiConUrlCtx_ as CHttp ptr http as zstring ptr url as zstring ptr ca_file @@ -53,7 +53,7 @@ namespace fb.fbdoc ''::::: private function build_url _ ( _ - byval ctx as CWikiConCtx ptr, _ + byval ctx as CWikiConUrlCtx ptr, _ byval page as zstring ptr = NULL, _ byval method as zstring ptr = NULL _ ) as string @@ -110,7 +110,7 @@ namespace fb.fbdoc return token end function - function CWikiConCtx.queryCsrfToken( ) as string + function CWikiConUrlCtx.queryCsrfToken( ) as string dim stream as CHttpStream = CHttpStream( http ) if( stream.Receive( build_url( @this, wakka_loginpage ), TRUE, ca_file ) = FALSE ) then return "" @@ -118,7 +118,7 @@ namespace fb.fbdoc return extractCsrfToken( stream.Read() ) end function - function CWikiConCtx.queryCsrfTokenIfNeeded( ) as boolean + function CWikiConUrlCtx.queryCsrfTokenIfNeeded( ) as boolean if( len( csrftoken ) = 0 ) then csrftoken = queryCsrfToken( ) if( len( csrftoken ) = 0 ) then @@ -128,25 +128,25 @@ namespace fb.fbdoc return TRUE end function - sub CWikiConCtx.maybeAddCsrfTokenToForm( byval form as CHttpForm ptr ) + sub CWikiConUrlCtx.maybeAddCsrfTokenToForm( byval form as CHttpForm ptr ) if( len( csrftoken ) > 0 ) then form->Add( "CSRFToken", csrftoken ) end if end sub ''::::: - static sub CWikiCon.GlobalInit() + static sub CWikiConUrl.GlobalInit() CHttp.GlobalInit() end sub ''::::: - constructor CWikiCon _ + constructor CWikiConUrl _ ( _ byval url as zstring ptr, _ byval ca_file as zstring ptr = NULL _ ) - ctx = new CWikiConCtx + ctx = new CWikiConUrlCtx ctx->http = new CHttp ctx->url = allocate( len( *url ) + 1 ) @@ -165,7 +165,7 @@ namespace fb.fbdoc end constructor ''::::: - destructor CWikiCon _ + destructor CWikiConUrl _ ( _ ) @@ -212,11 +212,11 @@ namespace fb.fbdoc end function ''::::: - function CWikiCon.Login _ + function CWikiConUrl.Login _ ( _ byval username as zstring ptr, _ byval password as zstring ptr _ - ) as integer + ) as boolean if( ctx = NULL ) then return FALSE @@ -342,7 +342,7 @@ namespace fb.fbdoc ''::::: private function get_pageid _ ( _ - byval ctx as CWikiConCtx ptr _ + byval ctx as CWikiConUrlCtx ptr _ ) as integer dim as CHttpStream ptr stream @@ -371,13 +371,13 @@ namespace fb.fbdoc end function ''::::: - function CWikiCon.LoadPage _ + function CWikiConUrl.LoadPage _ ( _ byval page as zstring ptr, _ byval israw as integer, _ byval getid as integer, _ byref body as string _ - ) as integer + ) as boolean function = FALSE body = "" @@ -427,11 +427,11 @@ namespace fb.fbdoc end function ''::::: - function CWikiCon.StorePage _ + function CWikiConUrl.StorePage _ ( _ byval body_in as zstring ptr, _ byval note as zstring ptr _ - ) as integer + ) as boolean dim body as string @@ -481,11 +481,11 @@ namespace fb.fbdoc end function ''::::: - function CWikiCon.StoreNewPage _ + function CWikiConUrl.StoreNewPage _ ( _ byval body as zstring ptr, _ byval pagename as zstring ptr _ - ) as integer + ) as boolean if( ctx = NULL ) then return FALSE @@ -523,7 +523,7 @@ namespace fb.fbdoc end function ''::::: - function CWikiCon.GetPageID _ + function CWikiConUrl.GetPageID _ ( _ ) as integer @@ -536,3 +536,4 @@ namespace fb.fbdoc end function end namespace + diff --git a/doc/libfbdoc/CWikiCon.bi b/doc/libfbdoc/CWikiConUrl.bi similarity index 88% rename from doc/libfbdoc/CWikiCon.bi rename to doc/libfbdoc/CWikiConUrl.bi index 9b10760383..aa7e93478e 100644 --- a/doc/libfbdoc/CWikiCon.bi +++ b/doc/libfbdoc/CWikiConUrl.bi @@ -1,5 +1,5 @@ -#ifndef __CWIKICON_BI__ -#define __CWIKICON_BI__ +#ifndef __CWIKICONURL_BI__ +#define __CWIKICONURL_BI__ '' fbdoc - FreeBASIC User's Manual Converter/Generator '' Copyright (C) 2006-2019 The FreeBASIC development team. @@ -23,9 +23,9 @@ namespace fb.fbdoc - type CWikiConCtx as CWikiConCtx_ + type CWikiConUrlCtx as CWikiConUrlCtx_ - type CWikiCon + type CWikiConUrl declare static sub GlobalInit() @@ -43,8 +43,7 @@ namespace fb.fbdoc ( _ byval username as zstring ptr, _ byval password as zstring ptr _ - ) as integer - + ) as boolean declare function LoadPage _ ( _ @@ -52,28 +51,29 @@ namespace fb.fbdoc byval israw as integer, _ byval getid as integer = TRUE, _ byref body as string _ - ) as integer + ) as boolean declare function StorePage _ ( _ byval body as zstring ptr, _ byval note as zstring ptr _ - ) as integer + ) as boolean declare function StoreNewPage _ ( _ byval body as zstring ptr, _ byval pagename as zstring ptr _ - ) as integer + ) as boolean declare function GetPageID _ ( _ ) as integer - ctx as CWikiConCtx ptr + ctx as CWikiConUrlCtx ptr end type end namespace #endif + diff --git a/doc/libfbdoc/fbdoc_loader.bas b/doc/libfbdoc/fbdoc_loader.bas index 239920b0ae..c6580ff9ed 100644 --- a/doc/libfbdoc/fbdoc_loader.bas +++ b/doc/libfbdoc/fbdoc_loader.bas @@ -78,7 +78,7 @@ namespace fb.fbdoc end if if( bLoadPage ) then - dim as CWikiCon ptr wikicon = Connection_Create( ) + dim as CWikiConUrl ptr wikicon = Connection_Create( ) printlog "Loading '" + *sPage + "'" if( wikicon->LoadPage( sPage, TRUE, TRUE, sBody ) <> FALSE ) then if( wikicon->GetPageID() > 0 ) then diff --git a/doc/libfbdoc/fbdoc_loader_web.bas b/doc/libfbdoc/fbdoc_loader_web.bas index c45b1ebaaf..880113711a 100644 --- a/doc/libfbdoc/fbdoc_loader_web.bas +++ b/doc/libfbdoc/fbdoc_loader_web.bas @@ -23,11 +23,11 @@ '' #include once "fbdoc_defs.bi" -#include once "CWikiCon.bi" +#include once "CWikiConUrl.bi" namespace fb.fbdoc - dim shared as CWikiCon ptr wikicon + dim shared as CWikiConUrl ptr wikicon dim shared as string wiki_url dim shared as string ca_file @@ -42,12 +42,12 @@ namespace fb.fbdoc end sub ''::::: - function Connection_Create( ) as CWikiCon Ptr + function Connection_Create( ) as CWikiConUrl Ptr if( wikicon <> NULL ) then return wikicon end if - wikicon = new CWikiCon( wiki_url, ca_file ) + wikicon = new CWikiConUrl( wiki_url, ca_file ) return wikicon diff --git a/doc/libfbdoc/fbdoc_loader_web.bi b/doc/libfbdoc/fbdoc_loader_web.bi index 88f450a647..d85ac69ec1 100644 --- a/doc/libfbdoc/fbdoc_loader_web.bi +++ b/doc/libfbdoc/fbdoc_loader_web.bi @@ -20,12 +20,12 @@ #include once "fbdoc_defs.bi" -#include once "CWikiCon.bi" +#include once "CWikiConUrl.bi" namespace fb.fbdoc declare sub Connection_SetUrl( byval url as zstring ptr, byval certificate as zstring ptr ) - declare function Connection_Create( ) as CWikiCon ptr + declare function Connection_Create( ) as CWikiConUrl ptr declare sub Connection_Destroy( ) end namespace From f93b399bf2a451161a03293b87f511979acd793d Mon Sep 17 00:00:00 2001 From: coderJeff Date: Mon, 20 May 2019 15:17:43 -0400 Subject: [PATCH 06/14] fbdoc: CWikiConUrl extends CWikiCon --- doc/libfbdoc/CWikiCon.bas | 84 +++++++++++++++++++++++++++++++++++++ doc/libfbdoc/CWikiCon.bi | 59 ++++++++++++++++++++++++++ doc/libfbdoc/CWikiConUrl.bi | 4 +- 3 files changed, 145 insertions(+), 2 deletions(-) create mode 100644 doc/libfbdoc/CWikiCon.bas create mode 100644 doc/libfbdoc/CWikiCon.bi diff --git a/doc/libfbdoc/CWikiCon.bas b/doc/libfbdoc/CWikiCon.bas new file mode 100644 index 0000000000..38c7a8e60d --- /dev/null +++ b/doc/libfbdoc/CWikiCon.bas @@ -0,0 +1,84 @@ +'' fbdoc - FreeBASIC User's Manual Converter/Generator +'' Copyright (C) 2006-2019 The FreeBASIC development team. +'' +'' This program is free software; you can redistribute it and/or modify +'' it under the terms of the GNU General Public License as published by +'' the Free Software Foundation; either version 2 of the License, or +'' (at your option) any later version. +'' +'' This program is distributed in the hope that it will be useful, +'' but WITHOUT ANY WARRANTY; without even the implied warranty of +'' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +'' GNU General Public License for more details. +'' +'' You should have received a copy of the GNU General Public License +'' along with this program; if not, write to the Free Software +'' Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA. + + +'' CWikiCon +'' +'' chng: may/2019 written [coderJeff] +'' + +#include once "CWikiCon.bi" + +namespace fb.fbdoc + + ''::::: + constructor CWikiCon _ + ( _ + ) + end constructor + + ''::::: + destructor CWikiCon _ + ( _ + ) + end destructor + + ''::::: + function CWikiCon.LoadPage _ + ( _ + byval page as zstring ptr, _ + byval israw as integer, _ + byval getid as integer, _ + byref body as string _ + ) as boolean + + function = false + + end function + + ''::::: + function CWikiCon.StorePage _ + ( _ + byval sPage as zstring ptr, _ + byval sBody as zstring ptr _ + ) as boolean + + function = false + + end function + + ''::::: + function CWikiCon.StoreNewPage _ + ( _ + byval body as zstring ptr, _ + byval pagename as zstring ptr _ + ) as boolean + + function = false + + end function + + ''::::: + function CWikiCon.GetPageID _ + ( _ + ) as integer + + function = 0 + + end function + +end namespace diff --git a/doc/libfbdoc/CWikiCon.bi b/doc/libfbdoc/CWikiCon.bi new file mode 100644 index 0000000000..ceab722a56 --- /dev/null +++ b/doc/libfbdoc/CWikiCon.bi @@ -0,0 +1,59 @@ +#ifndef __CWIKICON_BI__ +#define __CWIKICON_BI__ + +'' fbdoc - FreeBASIC User's Manual Converter/Generator +'' Copyright (C) 2006-2019 The FreeBASIC development team. +'' +'' This program is free software; you can redistribute it and/or modify +'' it under the terms of the GNU General Public License as published by +'' the Free Software Foundation; either version 2 of the License, or +'' (at your option) any later version. +'' +'' This program is distributed in the hope that it will be useful, +'' but WITHOUT ANY WARRANTY; without even the implied warranty of +'' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +'' GNU General Public License for more details. +'' +'' You should have received a copy of the GNU General Public License +'' along with this program; if not, write to the Free Software +'' Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA. + + +#include once "fbdoc_defs.bi" + +namespace fb.fbdoc + + type CWikiCon extends object + + declare constructor() + declare virtual destructor() + + declare virtual function LoadPage _ + ( _ + byval page as zstring ptr, _ + byval israw as integer, _ + byval getid as integer, _ + byref body as string _ + ) as boolean + + declare virtual function StorePage _ + ( _ + byval sPage as zstring ptr, _ + byval sBody as zstring ptr _ + ) as boolean + + declare virtual function StoreNewPage _ + ( _ + byval body as zstring ptr, _ + byval pagename as zstring ptr _ + ) as boolean + + declare virtual function GetPageID _ + ( _ + ) as integer + + end type + +end namespace + +#endif diff --git a/doc/libfbdoc/CWikiConUrl.bi b/doc/libfbdoc/CWikiConUrl.bi index aa7e93478e..a6c07af7ce 100644 --- a/doc/libfbdoc/CWikiConUrl.bi +++ b/doc/libfbdoc/CWikiConUrl.bi @@ -20,12 +20,13 @@ #include once "fbdoc_defs.bi" +#include once "CWikiCon.bi" namespace fb.fbdoc type CWikiConUrlCtx as CWikiConUrlCtx_ - type CWikiConUrl + type CWikiConUrl extends CWikiCon declare static sub GlobalInit() @@ -76,4 +77,3 @@ namespace fb.fbdoc end namespace #endif - From d4e6b51cf5f82362c542bba4f723560c2048fffe Mon Sep 17 00:00:00 2001 From: coderJeff Date: Mon, 20 May 2019 17:36:54 -0400 Subject: [PATCH 07/14] fbdoc: separate methods for loading a page and the index in CWikiCon.LoadPage() and LoadIndex() --- doc/fbchkdoc/getindex.bas | 2 +- doc/fbchkdoc/putpage.bas | 2 +- doc/libfbdoc/CWikiCon.bas | 21 ++++++++--- doc/libfbdoc/CWikiCon.bi | 14 ++++--- doc/libfbdoc/CWikiConUrl.bas | 70 ++++++++++++++++++++++++----------- doc/libfbdoc/CWikiConUrl.bi | 8 +++- doc/libfbdoc/fbdoc_loader.bas | 2 +- 7 files changed, 82 insertions(+), 37 deletions(-) diff --git a/doc/fbchkdoc/getindex.bas b/doc/fbchkdoc/getindex.bas index 07530c502c..5429ae488e 100644 --- a/doc/fbchkdoc/getindex.bas +++ b/doc/fbchkdoc/getindex.bas @@ -326,7 +326,7 @@ else end if print "Loading '" + sPage + "': "; - if( wikicon->LoadPage( sPage, FALSE, FALSE, sBody ) = FALSE ) then + if( wikicon->LoadIndex( sPage, sBody ) = FALSE ) then print "Error" else print "OK" diff --git a/doc/fbchkdoc/putpage.bas b/doc/fbchkdoc/putpage.bas index 3c76ed0e79..350f5c36ef 100644 --- a/doc/fbchkdoc/putpage.bas +++ b/doc/fbchkdoc/putpage.bas @@ -137,7 +137,7 @@ if( app_opt.pageCount > 0 ) then print "Unable to load" else print "OK" - if( wikicon->LoadPage( sPage, TRUE, TRUE, sBodyOld ) <> FALSE ) then + if( wikicon->LoadPage( sPage, sBodyOld ) <> FALSE ) then if( wikicon->GetPageID() > 0 ) then if( wikicon->Login( app_opt.wiki_username, app_opt.wiki_password ) ) = FALSE then print "Unable to login" diff --git a/doc/libfbdoc/CWikiCon.bas b/doc/libfbdoc/CWikiCon.bas index 38c7a8e60d..366ecbc12d 100644 --- a/doc/libfbdoc/CWikiCon.bas +++ b/doc/libfbdoc/CWikiCon.bas @@ -40,12 +40,23 @@ namespace fb.fbdoc ''::::: function CWikiCon.LoadPage _ ( _ - byval page as zstring ptr, _ - byval israw as integer, _ - byval getid as integer, _ + byval pagename as zstring ptr, _ byref body as string _ ) as boolean + body = "" + function = false + + end function + + ''::::: + function CWikiCon.LoadIndex _ + ( _ + byval pagename as zstring ptr, _ + byref body as string _ + ) as boolean + + body = "" function = false end function @@ -53,8 +64,8 @@ namespace fb.fbdoc ''::::: function CWikiCon.StorePage _ ( _ - byval sPage as zstring ptr, _ - byval sBody as zstring ptr _ + byval body as zstring ptr, _ + byval note as zstring ptr _ ) as boolean function = false diff --git a/doc/libfbdoc/CWikiCon.bi b/doc/libfbdoc/CWikiCon.bi index ceab722a56..d1bfe12726 100644 --- a/doc/libfbdoc/CWikiCon.bi +++ b/doc/libfbdoc/CWikiCon.bi @@ -30,16 +30,20 @@ namespace fb.fbdoc declare virtual function LoadPage _ ( _ - byval page as zstring ptr, _ - byval israw as integer, _ - byval getid as integer, _ + byval pagename as zstring ptr, _ + byref body as string _ + ) as boolean + + declare virtual function LoadIndex _ + ( _ + byval pagename as zstring ptr, _ byref body as string _ ) as boolean declare virtual function StorePage _ ( _ - byval sPage as zstring ptr, _ - byval sBody as zstring ptr _ + byval body as zstring ptr, _ + byval note as zstring ptr _ ) as boolean declare virtual function StoreNewPage _ diff --git a/doc/libfbdoc/CWikiConUrl.bas b/doc/libfbdoc/CWikiConUrl.bas index 3a43e18e9c..9658c8e9fd 100644 --- a/doc/libfbdoc/CWikiConUrl.bas +++ b/doc/libfbdoc/CWikiConUrl.bas @@ -372,10 +372,49 @@ namespace fb.fbdoc ''::::: function CWikiConUrl.LoadPage _ + ( _ + byval pagename as zstring ptr, _ + byref body as string _ + ) as boolean + + function = FALSE + body = "" + + if( ctx = NULL ) then + exit function + end if + + ctx->pageid = -1 + ctx->pagename = reallocate( ctx->pagename, len( *pagename ) + 1 ) + *ctx->pagename = *pagename + + dim as CHttpStream ptr stream + + stream = new CHttpStream( ctx->http ) + if( stream = NULL ) then + exit function + end if + + dim URL as string + URL = build_url( ctx, NULL, @wakka_raw ) + + if( stream->Receive( URL, TRUE, ctx->ca_file ) ) then + body = stream->Read() + remove_http_headers( body ) + end if + + delete stream + + ctx->pageid = get_pageid( ctx ) + + function = TRUE + + end function + + ''::::: + function CWikiConUrl.LoadIndex _ ( _ byval page as zstring ptr, _ - byval israw as integer, _ - byval getid as integer, _ byref body as string _ ) as boolean @@ -397,31 +436,18 @@ namespace fb.fbdoc exit function end if - dim as zstring ptr rawmethod = iif( israw, @wakka_raw, NULL ) - dim URL as string - URL = build_url( ctx, NULL, rawmethod ) + URL = build_url( ctx, NULL, NULL ) if( stream->Receive( URL, TRUE, ctx->ca_file ) ) then body = stream->Read() remove_http_headers( body ) -'' remove_trailing_whitespace( body ) end if delete stream - if( getid ) then - 'if( len( body ) > 0 ) then - ctx->pageid = get_pageid( ctx ) - 'else - ' ctx->pageid = -1 - 'end if - else - ctx->pageid = -1 - end if + ctx->pageid = -1 - ''body += chr( 13, 10 ) - function = TRUE end function @@ -429,11 +455,11 @@ namespace fb.fbdoc ''::::: function CWikiConUrl.StorePage _ ( _ - byval body_in as zstring ptr, _ + byval body as zstring ptr, _ byval note as zstring ptr _ ) as boolean - dim body as string + dim body_out as string if( ctx = NULL ) then return FALSE @@ -452,9 +478,9 @@ namespace fb.fbdoc form->Add( "wakka", *ctx->pagename + wakka_edit ) form->Add( "previous", ctx->pageid ) - body = *body_in -'' remove_trailing_whitespace( body ) - form->Add( "body", body, "text/html" ) + body_out = *body + + form->Add( "body", body_out, "text/html" ) if( note ) then form->Add( "note", *note ) else diff --git a/doc/libfbdoc/CWikiConUrl.bi b/doc/libfbdoc/CWikiConUrl.bi index a6c07af7ce..c70ed75c42 100644 --- a/doc/libfbdoc/CWikiConUrl.bi +++ b/doc/libfbdoc/CWikiConUrl.bi @@ -49,8 +49,12 @@ namespace fb.fbdoc declare function LoadPage _ ( _ byval page as zstring ptr, _ - byval israw as integer, _ - byval getid as integer = TRUE, _ + byref body as string _ + ) as boolean + + declare function LoadIndex _ + ( _ + byval page as zstring ptr, _ byref body as string _ ) as boolean diff --git a/doc/libfbdoc/fbdoc_loader.bas b/doc/libfbdoc/fbdoc_loader.bas index c6580ff9ed..05d4ebcf86 100644 --- a/doc/libfbdoc/fbdoc_loader.bas +++ b/doc/libfbdoc/fbdoc_loader.bas @@ -80,7 +80,7 @@ namespace fb.fbdoc if( bLoadPage ) then dim as CWikiConUrl ptr wikicon = Connection_Create( ) printlog "Loading '" + *sPage + "'" - if( wikicon->LoadPage( sPage, TRUE, TRUE, sBody ) <> FALSE ) then + if( wikicon->LoadPage( sPage, sBody ) <> FALSE ) then if( wikicon->GetPageID() > 0 ) then if( len(sBody) > 0 ) then wikicache->SavePage( sPage, sBody ) From af33899a8b541a2d597d50afbe5dbdf81251e442 Mon Sep 17 00:00:00 2001 From: coderJeff Date: Mon, 20 May 2019 18:31:32 -0400 Subject: [PATCH 08/14] fbdoc: move load index code from getindex tool to CWikiConUrl.LoadIndex() --- doc/fbchkdoc/getindex.bas | 160 ++--------------------------------- doc/libfbdoc/CWikiConUrl.bas | 159 +++++++++++++++++++++++++++++++++- 2 files changed, 163 insertions(+), 156 deletions(-) diff --git a/doc/fbchkdoc/getindex.bas b/doc/fbchkdoc/getindex.bas index 5429ae488e..ef991afa41 100644 --- a/doc/fbchkdoc/getindex.bas +++ b/doc/fbchkdoc/getindex.bas @@ -39,154 +39,8 @@ using fbdoc const def_index_file = hardcoded.default_index_file -'' temporary files -const def_html_file = "PageIndex.html" -const def_text_file = "PageIndex0.txt" - '' -------------------------------------------------------- -'' -sub RemoveHTMLtags _ - ( _ - byref sBody as string _ - ) - - '' remove HTML tags - - dim as string txt, html - dim as integer n, b = 0, j = 1, atag = 0, i - n = len(sBody) - txt = "" - - print "Removing html tags" - while( i <= n ) - - if( lcase(mid( sBody, i, 4 )) = "<" ) then - txt += "<" - i += 4 - elseif( lcase(mid( sBody, i, 4 )) = ">" ) then - txt += ">" - i += 4 - elseif( lcase(mid( sBody, i, 5 )) = "&" ) then - txt += "&" - i += 5 - elseif( lcase(mid( sBody, i, 6 )) = " " ) then - txt += " " - i += 6 - elseif( mid( sBody, i, 4 ) = "All<" and atag = 1 ) then - txt += "All" + crlf + "----" + crlf - i += 3 - elseif( mid( sBody, i, 5 ) = "All <" and atag = 1 ) then - txt += "All " + crlf + "----" + crlf - i += 3 - elseif( lcase(mid( sBody, i, 1 )) = "<" ) then - atag = 0 - b = 1 - j = i + 1 - while( j <= n and b > 0 ) - select case ( mid( sBody, j, 1 )) - case "<" - b += 1 - j += 1 - case ">" - b -= 1 - j += 1 - case chr(34) - j += 1 - while( j <= n ) - select case ( mid( sBody, j, 1 )) - case chr(34) - j += 1 - exit while - case else - j += 1 - end select - wend - case else - j += 1 - end select - wend - - html = mid( sBody, i, j - i ) - select case lcase( html ) - case "
","
" - txt += crlf - case "
","
" - txt += "----" - case else - if left( html, 3 ) = " 2 ) then - for i = 1 to len(x) - select case mid(x,i,1) - case "A" to "Z", "a" to "z", "0" to "9", "_" - case else - exit for - end select - next - if i > 1 then - print #h2, left(x, i - 1) - end if - end if - else - if x = "----" then - b = 1 - end if - end if - wend - close #h2 - close #h1 - - kill def_text_file - -end sub - #ifdef __FB_LINUX__ extern "c" declare function strcasecmp(byval as const zstring ptr, byval as const zstring ptr) as long @@ -330,22 +184,18 @@ else print "Error" else print "OK" - /' - '' DEBUG + print "Writing '" & def_index_file & "'" + dim as integer h = freefile - open def_html_file for output as #h - print #h, sBody + open def_index_file for output as #h + print #h, sBody; close #h - '/ + end if delete wikicon end scope - RemoveHTMLtags( sBody ) - - ExtractPageNames( ) - end if print "Done." diff --git a/doc/libfbdoc/CWikiConUrl.bas b/doc/libfbdoc/CWikiConUrl.bas index 9658c8e9fd..a80abc51d9 100644 --- a/doc/libfbdoc/CWikiConUrl.bas +++ b/doc/libfbdoc/CWikiConUrl.bas @@ -339,6 +339,162 @@ namespace fb.fbdoc end sub + '' + private sub remove_html_tags _ + ( _ + byref sBody as string _ + ) + + '' remove HTML tags from PageIndex + + dim as string txt, html + dim as integer n, b = 0, j = 1, atag = 0, i + n = len(sBody) + txt = "" + + while( i <= n ) + + if( lcase(mid( sBody, i, 4 )) = "<" ) then + txt += "<" + i += 4 + elseif( lcase(mid( sBody, i, 4 )) = ">" ) then + txt += ">" + i += 4 + elseif( lcase(mid( sBody, i, 5 )) = "&" ) then + txt += "&" + i += 5 + elseif( lcase(mid( sBody, i, 6 )) = " " ) then + txt += " " + i += 6 + elseif( mid( sBody, i, 4 ) = "All<" and atag = 1 ) then + txt += "All" + crlf + "----" + crlf + i += 3 + elseif( mid( sBody, i, 5 ) = "All <" and atag = 1 ) then + txt += "All " + crlf + "----" + crlf + i += 3 + elseif( lcase(mid( sBody, i, 1 )) = "<" ) then + atag = 0 + b = 1 + j = i + 1 + while( j <= n and b > 0 ) + select case ( mid( sBody, j, 1 )) + case "<" + b += 1 + j += 1 + case ">" + b -= 1 + j += 1 + case chr(34) + j += 1 + while( j <= n ) + select case ( mid( sBody, j, 1 )) + case chr(34) + j += 1 + exit while + case else + j += 1 + end select + wend + case else + j += 1 + end select + wend + + html = mid( sBody, i, j - i ) + select case lcase( html ) + case "
","
" + txt += crlf + case "
","
" + txt += "----" + case else + if left( html, 3 ) = "
2 ) then + '' find the page name + for i = 1 to len(x) + select case mid( x, i, 1 ) + case "A" to "Z", "a" to "z", "0" to "9", "_" + case else + exit for + end select + next + if i > 1 then + txt &= left(x, i - 1) & nl + end if + end if + else + if x = "----" then + bFirstMark = TRUE + end if + end if + + wend + + sBody = txt + + end sub + ''::::: private function get_pageid _ ( _ @@ -442,6 +598,8 @@ namespace fb.fbdoc if( stream->Receive( URL, TRUE, ctx->ca_file ) ) then body = stream->Read() remove_http_headers( body ) + remove_html_tags( body ) + extract_page_names( body ) end if delete stream @@ -562,4 +720,3 @@ namespace fb.fbdoc end function end namespace - From e128394086dd0c6f6786658eb3bc0c7def8f45ac Mon Sep 17 00:00:00 2001 From: coderJeff Date: Mon, 20 May 2019 19:58:54 -0400 Subject: [PATCH 09/14] fbdoc: add CWikiConDir extends CWikiCon, implements a wiki connection using a directory (like CWikiCache) --- doc/fbchkdoc/getindex.bas | 118 +++++---------- doc/libfbdoc/CWikiConDir.bas | 277 +++++++++++++++++++++++++++++++++++ doc/libfbdoc/CWikiConDir.bi | 75 ++++++++++ 3 files changed, 388 insertions(+), 82 deletions(-) create mode 100644 doc/libfbdoc/CWikiConDir.bas create mode 100644 doc/libfbdoc/CWikiConDir.bi diff --git a/doc/fbchkdoc/getindex.bas b/doc/fbchkdoc/getindex.bas index ef991afa41..433dd078b1 100644 --- a/doc/fbchkdoc/getindex.bas +++ b/doc/fbchkdoc/getindex.bas @@ -21,6 +21,7 @@ '' fbdoc headers #include once "CWikiConUrl.bi" +#include once "CWikiConDir.bi" '' fbchkdoc headers #include once "fbchkdoc.bi" @@ -34,61 +35,9 @@ using fb using fbdoc -#include "crt/stdlib.bi" -#include "crt/string.bi" const def_index_file = hardcoded.default_index_file -'' -------------------------------------------------------- - -#ifdef __FB_LINUX__ -extern "c" - declare function strcasecmp(byval as const zstring ptr, byval as const zstring ptr) as long -end extern -#define _stricmp strcasecmp -#endif - -'' -function cmpPageName cdecl ( byval x as any ptr, byval y as any ptr ) as long - function = _stricmp( *cast(zstring ptr ptr,x), *cast(zstring ptr ptr,y) ) -end function - -'' -sub ScanCacheDir _ - ( _ - byref p as string _ - ) - - dim as string d, pages(1 to 2000) - dim as integer i, h, n = 0 - dim as zstring ptr zpage(1 to 2000) - - d = dir( p & "*.wakka" ) - while( d > "" ) - i = instrrev( d, "." ) - if( i > 0 ) then - d = left( d, i-1 ) - if( len(d) > 0 ) then - n += 1 - pages(n) = d - zpage(n) = strptr(pages(n)) - end if - end if - d = dir( ) - wend - - '' Sort - qsort( @zpage(1), n, sizeof(zstring ptr), procptr(cmpPageName) ) - - h = freefile - open def_index_file for output as #h - for i = 1 to n - print #h, *zpage(i) - next - close #h - -end sub - '' -------------------------------------------------------- '' MAIN '' -------------------------------------------------------- @@ -150,9 +99,19 @@ dim sBody as string sPage = "PageIndex" +dim as CWikiCon ptr wikicon = NULL + +'' connect to the wiki and get PageIndex as HTML + if( blocal ) then - ScanCacheDir( app_opt.cache_dir ) + wikicon = new CWikiConDir( app_opt.cache_dir ) + if wikicon = NULL then + print "Unable to create connection " + app_opt.cache_dir + end 1 + end if + + print "cache: "; app_opt.cache_dir else @@ -161,41 +120,36 @@ else end 1 end if - '' connect to the wiki and get PageIndex as HTML - scope - dim as CWikiConUrl ptr wikicon = NULL - - wikicon = new CWikiConUrl( app_opt.wiki_url, app_opt.ca_file ) - if wikicon = NULL then - print "Unable to create connection " + app_opt.wiki_url - end 1 - end if - - print "URL: "; app_opt.wiki_url + print "URL: "; app_opt.wiki_url - if( app_opt.ca_file > "" ) then - print "Certificate: "; app_opt.ca_file - else - print "Certificate: none" - end if + wikicon = new CWikiConUrl( app_opt.wiki_url, app_opt.ca_file ) + if wikicon = NULL then + print "Unable to create connection " + app_opt.wiki_url + end 1 + end if - print "Loading '" + sPage + "': "; - if( wikicon->LoadIndex( sPage, sBody ) = FALSE ) then - print "Error" - else - print "OK" - print "Writing '" & def_index_file & "'" + if( app_opt.ca_file > "" ) then + print "Certificate: "; app_opt.ca_file + else + print "Certificate: none" + end if - dim as integer h = freefile - open def_index_file for output as #h - print #h, sBody; - close #h +end if - end if +print "Loading '" + sPage + "': "; +if( wikicon->LoadIndex( sPage, sBody ) = FALSE ) then + print "Error" +else + print "OK" + print "Writing '" & def_index_file & "'" - delete wikicon - end scope + dim as integer h = freefile + open def_index_file for output as #h + print #h, sBody; + close #h end if +delete wikicon + print "Done." diff --git a/doc/libfbdoc/CWikiConDir.bas b/doc/libfbdoc/CWikiConDir.bas new file mode 100644 index 0000000000..b9c13f0947 --- /dev/null +++ b/doc/libfbdoc/CWikiConDir.bas @@ -0,0 +1,277 @@ +'' fbdoc - FreeBASIC User's Manual Converter/Generator +'' Copyright (C) 2006-2019 The FreeBASIC development team. +'' +'' This program is free software; you can redistribute it and/or modify +'' it under the terms of the GNU General Public License as published by +'' the Free Software Foundation; either version 2 of the License, or +'' (at your option) any later version. +'' +'' This program is distributed in the hope that it will be useful, +'' but WITHOUT ANY WARRANTY; without even the implied warranty of +'' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +'' GNU General Public License for more details. +'' +'' You should have received a copy of the GNU General Public License +'' along with this program; if not, write to the Free Software +'' Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA. + + +'' CWikiConDir +'' +'' chng: may/2019 written [coderJeff] +'' + +#include once "CWikiConDir.bi" +#include once "file.bi" +#include "crt/stdlib.bi" +#include "crt/string.bi" + +#ifdef __FB_LINUX__ +extern "c" + declare function strcasecmp(byval as const zstring ptr, byval as const zstring ptr) as long +end extern +#define _stricmp strcasecmp +#endif + +namespace fb.fbdoc + + type CWikiConDirCtx_ + as zstring ptr path + as zstring ptr pagename + as integer pageid + end type + + const cache_ext = ".wakka" + + ''::::: + constructor CWikiConDir _ + ( _ + byval path as zstring ptr _ + ) + + ctx = new CWikiConDirCtx + + ctx->path = allocate( len( *path ) + 1 ) + *ctx->path = *path + + ctx->pagename = NULL + ctx->pageid = -1 + + end constructor + + ''::::: + destructor CWikiConDir _ + ( _ + ) + + if( ctx = NULL ) then + exit destructor + end if + + if( ctx->path <> NULL ) then + deallocate( ctx->path ) + ctx->path = NULL + end if + + if( ctx->pagename <> NULL ) then + deallocate( ctx->pagename ) + ctx->pagename = NULL + end if + + delete ctx + + end destructor + + ''::::: + function CWikiConDir.LoadPage _ + ( _ + byval pagename as zstring ptr, _ + byref body as string _ + ) as boolean + + dim sLocalFile as string + dim h as integer + + function = FALSE + body = "" + + if( ctx = NULL ) then + exit function + end if + + ctx->pageid = -1 + ctx->pagename = reallocate( ctx->pagename, len( *pagename ) + 1 ) + *ctx->pagename = *pagename + + sLocalFile = *ctx->path & *ctx->pagename & cache_ext + + if( fileexists( sLocalFile ) ) then + h = freefile + if( open( sLocalFile for binary as #h) = 0 ) then + if( lof(h) > 0 ) then + body = space( lof( h ) ) + get #h,,body + end if + close #h + function = TRUE + end if + end if + + end function + + '' + function cmpPageName cdecl ( byval x as any ptr, byval y as any ptr ) as long + function = _stricmp( *cast(zstring ptr ptr,x), *cast(zstring ptr ptr,y) ) + end function + + ''::::: + private sub scan_cache_dir _ + ( _ + byval path as zstring ptr, _ + byref body as string _ + ) + + dim as integer pagecount = 0 + dim as string d, lst + + d = dir( *path & "*.wakka" ) + while( d > "" ) + dim as integer i = instrrev( d, "." ) + if( i > 0 ) then + d = left( d, i-1 ) + if( len(d) > 0 ) then + pagecount += 1 + lst &= chr(0) & d + end if + end if + d = dir( ) + wend + + if( pagecount > 0 ) then + dim as zstring ptr zpage( 1 to pagecount ) + dim as integer index = 1 + for i as integer = 1 to len( lst ) + if( lst[i] = 0 ) then + zpage(index) = @(lst[i+1]) + index += 1 + end if + next + + '' Sort + qsort( @zpage(1), pagecount, sizeof(zstring ptr), procptr(cmpPageName) ) + + for i as integer = 1 to pagecount + body &= *zpage(i) & nl + next + + else + body = "" + + end if + + end sub + + ''::::: + function CWikiConDir.LoadIndex _ + ( _ + byval page as zstring ptr, _ + byref body as string _ + ) as boolean + + function = FALSE + body = "" + + if( ctx = NULL ) then + exit function + end if + + if( ctx->path = NULL ) then + exit function + end if + + ctx->pageid = -1 + ctx->pagename = reallocate( ctx->pagename, len( *page ) + 1 ) + *ctx->pagename = *page + + scan_cache_dir( *ctx->path, body ) + + function = TRUE + + end function + + ''::::: + function CWikiConDir.StorePage _ + ( _ + byval body as zstring ptr, _ + byval note as zstring ptr _ + ) as boolean + + if( ctx = NULL ) then + return FALSE + end if + + if( body = NULL ) then + return FALSE + end if + + if( len(*body) = 0) then + return FALSE + endif + + if( ctx->pagename = NULL ) then + return FALSE + end if + + dim as integer h + dim as string sLocalFile + + function = FALSE + + sLocalFile = *ctx->path + *ctx->pagename + cache_ext + + if( fileexists( sLocalFile ) ) then + kill sLocalFile + end if + + h = freefile + if( open(sLocalFile for binary as #h) = 0 ) then + put #h,,*body, len(*body) + close #h + function = TRUE + end if + + end function + + ''::::: + function CWikiConDir.StoreNewPage _ + ( _ + byval body as zstring ptr, _ + byval pagename as zstring ptr _ + ) as boolean + + if( ctx = NULL ) then + return FALSE + end if + + ctx->pagename = reallocate( ctx->pagename, len( *pagename ) + 1 ) + *ctx->pagename = *pagename + + return StorePage( body, NULL ) + + end function + + ''::::: + function CWikiConDir.GetPageID _ + ( _ + ) as integer + + if( ctx = NULL ) then + return 0 + end if + + return ctx->pageid + + end function + +end namespace + diff --git a/doc/libfbdoc/CWikiConDir.bi b/doc/libfbdoc/CWikiConDir.bi new file mode 100644 index 0000000000..233051b9d4 --- /dev/null +++ b/doc/libfbdoc/CWikiConDir.bi @@ -0,0 +1,75 @@ +#ifndef __CWIKICONDIR_BI__ +#define __CWIKICONDIR_BI__ + +'' fbdoc - FreeBASIC User's Manual Converter/Generator +'' Copyright (C) 2006-2019 The FreeBASIC development team. +'' +'' This program is free software; you can redistribute it and/or modify +'' it under the terms of the GNU General Public License as published by +'' the Free Software Foundation; either version 2 of the License, or +'' (at your option) any later version. +'' +'' This program is distributed in the hope that it will be useful, +'' but WITHOUT ANY WARRANTY; without even the implied warranty of +'' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +'' GNU General Public License for more details. +'' +'' You should have received a copy of the GNU General Public License +'' along with this program; if not, write to the Free Software +'' Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA. + + +#include once "fbdoc_defs.bi" +#include once "CWikiCon.bi" + +namespace fb.fbdoc + + type CWikiConDirCtx as CWikiConDirCtx_ + + type CWikiConDir extends CWikiCon + + declare constructor _ + ( _ + byval path as zstring ptr = NULL _ + ) + + declare destructor _ + ( _ + ) + + declare function LoadPage _ + ( _ + byval page as zstring ptr, _ + byref body as string _ + ) as boolean + + declare function LoadIndex _ + ( _ + byval page as zstring ptr, _ + byref body as string _ + ) as boolean + + declare function StorePage _ + ( _ + byval body as zstring ptr, _ + byval note as zstring ptr _ + ) as boolean + + declare function StoreNewPage _ + ( _ + byval body as zstring ptr, _ + byval pagename as zstring ptr _ + ) as boolean + + declare function GetPageID _ + ( _ + ) as integer + + ctx as CWikiConDirCtx ptr + + end type + +end namespace + +#endif + From 6c2b1f1678ce04d01b9f45d43fa6fd73b47f433e Mon Sep 17 00:00:00 2001 From: coderJeff Date: Mon, 20 May 2019 22:11:02 -0400 Subject: [PATCH 10/14] fbdoc: CWikiCon code clean-up --- doc/libfbdoc/CWikiConDir.bas | 39 ++++------- doc/libfbdoc/CWikiConDir.bi | 3 +- doc/libfbdoc/CWikiConUrl.bas | 129 ++++++++++++++++------------------- doc/libfbdoc/CWikiConUrl.bi | 2 +- 4 files changed, 71 insertions(+), 102 deletions(-) diff --git a/doc/libfbdoc/CWikiConDir.bas b/doc/libfbdoc/CWikiConDir.bas index b9c13f0947..68b49c6064 100644 --- a/doc/libfbdoc/CWikiConDir.bas +++ b/doc/libfbdoc/CWikiConDir.bas @@ -22,6 +22,7 @@ '' #include once "CWikiConDir.bi" +#include once "fbdoc_string.bi" #include once "file.bi" #include "crt/stdlib.bi" #include "crt/string.bi" @@ -36,7 +37,7 @@ end extern namespace fb.fbdoc type CWikiConDirCtx_ - as zstring ptr path + as zstring ptr path as zstring ptr pagename as integer pageid end type @@ -50,10 +51,7 @@ namespace fb.fbdoc ) ctx = new CWikiConDirCtx - - ctx->path = allocate( len( *path ) + 1 ) - *ctx->path = *path - + ZSet @ctx->path, path ctx->pagename = NULL ctx->pageid = -1 @@ -63,21 +61,12 @@ namespace fb.fbdoc destructor CWikiConDir _ ( _ ) - + if( ctx = NULL ) then exit destructor end if - - if( ctx->path <> NULL ) then - deallocate( ctx->path ) - ctx->path = NULL - end if - - if( ctx->pagename <> NULL ) then - deallocate( ctx->pagename ) - ctx->pagename = NULL - end if - + ZFree @ctx->path + ZFree @ctx->pagename delete ctx end destructor @@ -94,14 +83,13 @@ namespace fb.fbdoc function = FALSE body = "" - + if( ctx = NULL ) then exit function end if + ZSet @ctx->pagename, pagename ctx->pageid = -1 - ctx->pagename = reallocate( ctx->pagename, len( *pagename ) + 1 ) - *ctx->pagename = *pagename sLocalFile = *ctx->path & *ctx->pagename & cache_ext @@ -190,13 +178,12 @@ namespace fb.fbdoc end if ctx->pageid = -1 - ctx->pagename = reallocate( ctx->pagename, len( *page ) + 1 ) - *ctx->pagename = *page + ZSet @ctx->pagename, page scan_cache_dir( *ctx->path, body ) - + function = TRUE - + end function ''::::: @@ -253,8 +240,7 @@ namespace fb.fbdoc return FALSE end if - ctx->pagename = reallocate( ctx->pagename, len( *pagename ) + 1 ) - *ctx->pagename = *pagename + ZSet @ctx->pagename, pagename return StorePage( body, NULL ) @@ -274,4 +260,3 @@ namespace fb.fbdoc end function end namespace - diff --git a/doc/libfbdoc/CWikiConDir.bi b/doc/libfbdoc/CWikiConDir.bi index 233051b9d4..e2e2775b85 100644 --- a/doc/libfbdoc/CWikiConDir.bi +++ b/doc/libfbdoc/CWikiConDir.bi @@ -25,7 +25,7 @@ namespace fb.fbdoc type CWikiConDirCtx as CWikiConDirCtx_ - + type CWikiConDir extends CWikiCon declare constructor _ @@ -72,4 +72,3 @@ namespace fb.fbdoc end namespace #endif - diff --git a/doc/libfbdoc/CWikiConUrl.bas b/doc/libfbdoc/CWikiConUrl.bas index a80abc51d9..0ade7188d6 100644 --- a/doc/libfbdoc/CWikiConUrl.bas +++ b/doc/libfbdoc/CWikiConUrl.bas @@ -27,6 +27,8 @@ #include once "CHttpForm.bi" #include once "CHttpStream.bi" #include once "CWikiConUrl.bi" +#include once "fbdoc_string.bi" +#include once "printlog.bi" namespace fb.fbdoc @@ -59,19 +61,19 @@ namespace fb.fbdoc ) as string dim as string url - + url = *ctx->url + wakka_prefix - + if( page = NULL ) then page = ctx->pagename end if - + url += *page - + if( method <> NULL ) then url += *method end if - + function = url end function @@ -97,13 +99,13 @@ namespace fb.fbdoc var headbegin = instr( htmlpage, CSRFTokenHead ) if( headbegin <= 0 ) then - print "(error: CSRFToken not found)"; + printlog "(error: CSRFToken not found)", TRUE return "" end if var token = mid( htmlpage, headbegin + len( CSRFTokenHead ), CSRFTokenLength ) if( strIsAlphaNumOnly( token ) = FALSE ) then - print "(error: invalid CSRFToken: " + token + ")"; + printlog "(error: invalid CSRFToken: " + token + ")", TRUE return "" end if @@ -146,15 +148,12 @@ namespace fb.fbdoc byval ca_file as zstring ptr = NULL _ ) - ctx = new CWikiConUrlCtx + ctx = new CWikiConUrlCtx ctx->http = new CHttp - ctx->url = allocate( len( *url ) + 1 ) - *ctx->url = *url - + ZSet @ctx->url, url if( ca_file ) then - ctx->ca_file = allocate( len( *ca_file ) + 1 ) - *ctx->ca_file = *ca_file + ZSet @ctx->ca_file, ca_file else ctx->ca_file = NULL end if @@ -168,30 +167,18 @@ namespace fb.fbdoc destructor CWikiConUrl _ ( _ ) - + if( ctx = NULL ) then exit destructor end if - - if( ctx->pagename <> NULL ) then - deallocate( ctx->pagename ) - ctx->pagename = NULL - end if - - if( ctx->ca_file <> NULL ) then - deallocate( ctx->ca_file ) - ctx->ca_file = NULL - end if - - if( ctx->url <> NULL ) then - deallocate( ctx->url ) - ctx->url = NULL - end if + ZFree @ctx->pagename + ZFree @ctx->ca_file + ZFree @ctx->url if( ctx->http <> NULL ) then delete ctx->http ctx->http = NULL - end if + end if delete ctx @@ -202,7 +189,7 @@ namespace fb.fbdoc ( _ byval body as zstring ptr _ ) as integer - + if( len( *body ) = 0 ) then return TRUE end if @@ -217,33 +204,33 @@ namespace fb.fbdoc byval username as zstring ptr, _ byval password as zstring ptr _ ) as boolean - + if( ctx = NULL ) then return FALSE end if - + if( ctx->queryCsrfTokenIfNeeded( ) = FALSE ) then return FALSE end if dim as CHttpForm ptr form - + form = new CHttpForm if( form = NULL ) then return FALSE end if - + form->Add( "action", "login" ) form->Add( "wakka", "UserSettings" ) form->Add( "name", username ) form->Add( "password", password ) form->Add( "submit", "Login" ) ctx->maybeAddCsrfTokenToForm( form ) - + dim as string response = ctx->http->Post( build_url( ctx, wakka_loginpage ), form, ctx->ca_file ) - + function = ( check_iserror( response ) = FALSE ) - + delete form end function @@ -500,25 +487,25 @@ namespace fb.fbdoc ( _ byval ctx as CWikiConUrlCtx ptr _ ) as integer - + dim as CHttpStream ptr stream - + function = -1 - + stream = new CHttpStream( ctx->http ) if( stream = NULL ) then exit function end if - + dim as string body, URL URL = build_url( ctx, NULL, wakka_getid ) - + if( stream->Receive( URL, TRUE, ctx->ca_file ) ) then body = stream->Read() end if delete stream - + if( check_iserror( body ) = FALSE ) then remove_http_headers( body ) function = valint( get_response( body ) ) @@ -535,22 +522,21 @@ namespace fb.fbdoc function = FALSE body = "" - + if( ctx = NULL ) then exit function end if + ZSet @ctx->pagename, pagename ctx->pageid = -1 - ctx->pagename = reallocate( ctx->pagename, len( *pagename ) + 1 ) - *ctx->pagename = *pagename - + dim as CHttpStream ptr stream - + stream = new CHttpStream( ctx->http ) if( stream = NULL ) then exit function end if - + dim URL as string URL = build_url( ctx, NULL, @wakka_raw ) @@ -558,13 +544,13 @@ namespace fb.fbdoc body = stream->Read() remove_http_headers( body ) end if - + delete stream - + ctx->pageid = get_pageid( ctx ) - + function = TRUE - + end function ''::::: @@ -581,9 +567,8 @@ namespace fb.fbdoc exit function end if + ZSet @ctx->pagename, page ctx->pageid = -1 - ctx->pagename = reallocate( ctx->pagename, len( *page ) + 1 ) - *ctx->pagename = *page dim as CHttpStream ptr stream @@ -591,7 +576,7 @@ namespace fb.fbdoc if( stream = NULL ) then exit function end if - + dim URL as string URL = build_url( ctx, NULL, NULL ) @@ -601,13 +586,13 @@ namespace fb.fbdoc remove_html_tags( body ) extract_page_names( body ) end if - + delete stream - + ctx->pageid = -1 function = TRUE - + end function ''::::: @@ -626,9 +611,9 @@ namespace fb.fbdoc if( ctx->pageid <= 0 ) then return FALSE end if - + dim as CHttpForm ptr form - + form = new CHttpForm if( form = NULL ) then return FALSE @@ -657,11 +642,11 @@ namespace fb.fbdoc if( res ) then ctx->pageid = get_pageid( ctx ) end if - + delete form - + function = res - + end function ''::::: @@ -676,7 +661,7 @@ namespace fb.fbdoc end if dim as CHttpForm ptr form - + form = new CHttpForm if( form = NULL ) then return FALSE @@ -688,22 +673,22 @@ namespace fb.fbdoc form->Add( "note", "new page" ) form->Add( "submit", "Store" ) ctx->maybeAddCsrfTokenToForm( form ) - + dim URL as string URL = build_url( ctx, pagename, wakka_edit ) - + dim as string response = ctx->http->Post( URL, form, ctx->ca_file ) - + dim as integer res = ( check_iserror( response ) = FALSE ) if( res ) then ctx->pageid = get_pageid( ctx ) end if - + delete form - + function = res - + end function ''::::: diff --git a/doc/libfbdoc/CWikiConUrl.bi b/doc/libfbdoc/CWikiConUrl.bi index c70ed75c42..1d2600a6da 100644 --- a/doc/libfbdoc/CWikiConUrl.bi +++ b/doc/libfbdoc/CWikiConUrl.bi @@ -25,7 +25,7 @@ namespace fb.fbdoc type CWikiConUrlCtx as CWikiConUrlCtx_ - + type CWikiConUrl extends CWikiCon declare static sub GlobalInit() From 1f8bb7309eff3787634accba7d8786fa88a4332c Mon Sep 17 00:00:00 2001 From: coderJeff Date: Tue, 21 May 2019 07:32:28 -0400 Subject: [PATCH 11/14] fbdoc: CWikiConSql extends CWikiCon --- doc/fbchkdoc/getindex.bas | 28 ++- doc/fbchkdoc/makefile | 5 + doc/libfbdoc/CWikiConSql.bas | 407 +++++++++++++++++++++++++++++++++++ doc/libfbdoc/CWikiConSql.bi | 89 ++++++++ 4 files changed, 526 insertions(+), 3 deletions(-) create mode 100644 doc/libfbdoc/CWikiConSql.bas create mode 100644 doc/libfbdoc/CWikiConSql.bi diff --git a/doc/fbchkdoc/getindex.bas b/doc/fbchkdoc/getindex.bas index 433dd078b1..93da10d56e 100644 --- a/doc/fbchkdoc/getindex.bas +++ b/doc/fbchkdoc/getindex.bas @@ -22,6 +22,7 @@ '' fbdoc headers #include once "CWikiConUrl.bi" #include once "CWikiConDir.bi" +#include once "CWikiConSql.bi" '' fbchkdoc headers #include once "fbchkdoc.bi" @@ -43,7 +44,8 @@ const def_index_file = hardcoded.default_index_file '' -------------------------------------------------------- '' private options -dim as boolean blocal = false '' -local given on command line +dim as boolean bLocal = false '' -local given on command line +dim as boolean bUseSql = false '' -usesql given on command line '' enable url and cache cmd_opts_init( CMD_OPTS_ENABLE_URL or CMD_OPTS_ENABLE_CACHE ) @@ -55,7 +57,11 @@ while( command(i) > "" ) elseif( left( command(i), 1 ) = "-" ) then select case lcase(command(i)) case "-local" - blocal = TRUE + bLocal = TRUE +#if defined(HAVE_MYSQL) + case "-usesql" + bUseSql = TRUE +#endif case else cmd_opts_unrecognized_die( i ) end select @@ -77,6 +83,9 @@ if( app_opt.help ) then print "options:" print " -local use local cache only, don't query server, just" print " read the cache dir to get the list of page names" +#if defined(HAVE_MYSQL) + print " -usesql use MySQL connection to read index" +#endif print print "if -local is specified, then just read the file names from the cache:" print " -web get page names from cache_dir" @@ -103,7 +112,7 @@ dim as CWikiCon ptr wikicon = NULL '' connect to the wiki and get PageIndex as HTML -if( blocal ) then +if( bLocal ) then wikicon = new CWikiConDir( app_opt.cache_dir ) if wikicon = NULL then @@ -113,6 +122,19 @@ if( blocal ) then print "cache: "; app_opt.cache_dir +#if defined(HAVE_MYSQL) +elseif( bUseSql ) then + + '' !!! TODO !!! - load options for host, user, pass, etc + wikicon = new CWikiConSql( "", "", "", "", 0 ) + if wikicon = NULL then + print "Unable to create connection " + app_opt.cache_dir + end 1 + end if + + print "cache: "; app_opt.cache_dir + +#endif else if( len( app_opt.wiki_url ) = 0 ) then diff --git a/doc/fbchkdoc/makefile b/doc/fbchkdoc/makefile index baca92656e..5d63d2fdea 100644 --- a/doc/fbchkdoc/makefile +++ b/doc/fbchkdoc/makefile @@ -59,6 +59,11 @@ DEPS = ../libfbdoc/libfbdoc.a $(HEADERS) FBCFLAGS += -exx -g -i ../libfbdoc FBLFLAGS += -exx -g -p ../libfbdoc -l fbdoc +ifdef HAVE_MYSQL + FBCFLAGS += -d HAVE_MYSQL + FBLFLAGS += -l mysql +endif + ifeq ($(EXEEXT),.exe) FBLFLAGS += -l ws2_32 endif diff --git a/doc/libfbdoc/CWikiConSql.bas b/doc/libfbdoc/CWikiConSql.bas new file mode 100644 index 0000000000..749581507a --- /dev/null +++ b/doc/libfbdoc/CWikiConSql.bas @@ -0,0 +1,407 @@ +'' fbdoc - FreeBASIC User's Manual Converter/Generator +'' Copyright (C) 2006-2019 The FreeBASIC development team. +'' +'' This program is free software; you can redistribute it and/or modify +'' it under the terms of the GNU General Public License as published by +'' the Free Software Foundation; either version 2 of the License, or +'' (at your option) any later version. +'' +'' This program is distributed in the hope that it will be useful, +'' but WITHOUT ANY WARRANTY; without even the implied warranty of +'' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +'' GNU General Public License for more details. +'' +'' You should have received a copy of the GNU General Public License +'' along with this program; if not, write to the Free Software +'' Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA. + + +'' CWikiConSql +'' +'' chng: may/2019 written [coderJeff] +'' + +#include once "CWikiConSql.bi" +#include once "fbdoc_string.bi" +#include once "mysql/mysql.bi" +#include once "printlog.bi" + +namespace fb.fbdoc + + type CMySqlCon + + db as MYSQL ptr + connected as boolean + + declare constructor _ + ( _ + ) + + declare destructor _ + ( _ + ) + + declare function Connect _ + ( _ + byval db_host as zstring ptr, _ + byval db_user as zstring ptr, _ + byval db_pass as zstring ptr, _ + byval db_name as zstring ptr, _ + byval db_port as integer _ + ) as boolean + + declare sub Disconnect _ + ( _ + ) + + end type + + '' + constructor CMySqlCon _ + ( _ + ) + + db = new MYSQL + connected = FALSE + + end constructor + + '' + destructor CMySqlCon _ + ( _ + ) + if( connected ) then + Disconnect() + end if + if( db <> NULL ) then + delete db + end if + + end destructor + + '' + function CMySqlCon.Connect _ + ( _ + byval db_host as zstring ptr, _ + byval db_user as zstring ptr, _ + byval db_pass as zstring ptr, _ + byval db_name as zstring ptr, _ + byval db_port as integer _ + ) as boolean + + function = FALSE + + if( db_host = NULL ) then + exit function + end if + + if( db_user = NULL ) then + exit function + end if + + if( db_pass = NULL ) then + exit function + end if + + if( db_name = NULL ) then + exit function + end if + + printlog "Connecting to database: " + *db_name + " on " + *db_host + ":" + str(db_port) + + if( NULL = mysql_init( db )) then + printlog "Error " + str(mysql_errno(db)) + ": " + *mysql_error(db) + printlog "Unable to initialize mysql" + return FALSE + end if + + exit function + + if( NULL = mysql_real_connect(db, db_host, db_user, db_pass, db_name, db_port, NULL, 0)) then + mysql_close( db ) + printlog "Unable to connect to database" + return FALSE + end if + + if( mysql_select_db( db, db_name ) <> 0 ) then + mysql_close( db ) + printlog "Unable to use database " + *db_name + return FALSE + end if + + connected = TRUE + + function = TRUE + + end function + + '' + sub CMySqlCon.Disconnect _ + ( _ + ) + + if( connected ) then + if( db ) then + mysql_close( db ) + end if + connected = FALSE + end if + + end sub + + + type CWikiConSqlCtx_ + as CMySqlCon ptr db_conn + + as zstring ptr db_host + as zstring ptr db_user + as integer db_port + + as zstring ptr db_pass + as zstring ptr db_name + + as zstring ptr pagename + as integer pageid + end type + + const cache_ext = ".wakka" + + dim shared mysql_is_initialized as boolean = FALSE + + ''::::: + static sub CWikiConSql.GlobalInit() + '' !!! TODO !!! - need updated mysql.bi + '' mysql_server_init( 0, NULL, NULL ) + mysql_is_initialized = TRUE + end sub + + ''::::: + static sub CWikiConSql.GlobalExit() + if( mysql_is_initialized ) then + '' !!! TODO !!! - need updated mysql.bi + '' mysql_server_end() + mysql_is_initialized = FALSE + end if + end sub + + ''::::: + constructor CWikiConSql _ + ( _ + byval db_host as zstring ptr, _ + byval db_user as zstring ptr, _ + byval db_pass as zstring ptr, _ + byval db_name as zstring ptr, _ + byval db_port as integer _ + ) + + ctx = new CWikiConSqlCtx + ctx->db_conn = new CMySqlCon + ZSet @ctx->db_host, db_host + ZSet @ctx->db_user, db_user + ZSet @ctx->db_pass, db_pass + ZSet @ctx->db_name, db_name + ctx->db_port = db_port + ctx->pagename = NULL + ctx->pageid = -1 + + end constructor + + ''::::: + destructor CWikiConSql _ + ( _ + ) + + if( ctx = NULL ) then + exit destructor + end if + ZFree @ctx->db_host + ZFree @ctx->db_user + ZFree @ctx->db_pass + ZFree @ctx->db_name + ZFree @ctx->pagename + if( ctx->db_conn ) then + delete ctx->db_conn + end if + delete ctx + + end destructor + + ''::::: + function CWikiConSql.Connect _ + ( _ + ) as boolean + + function = FALSE + + if( ctx = NULL ) then + exit function + end if + + if( ctx->db_conn = NULL ) then + exit function + end if + + function = ctx->db_conn->Connect( ctx->db_host, ctx->db_user, ctx->db_pass, ctx->db_name, ctx->db_port ) + + end function + + ''::::: + sub CWikiConSql.Disconnect _ + ( _ + ) + + ctx->db_conn->Disconnect() + + end sub + + ''::::: + function CWikiConSql.LoadPage _ + ( _ + byval pagename as zstring ptr, _ + byref body as string _ + ) as boolean + + function = FALSE + body = "" + + if( ctx = NULL ) then + exit function + end if + + if( pagename = NULL ) then + exit function + end if + + ZSet @ctx->pagename, pagename + ctx->pageid = -1 + + scope + dim as string sql + dim as MYSQL_RES ptr res + dim as MYSQL_ROW row + dim as string sName, sBody + + if( Connect() = FALSE ) then + return FALSE + end if + + sql = "SELECT tag, body FROM wikka_pages WHERE ( latest = 'Y' AND tag = '" & *pagename & "' )" + + if( 0 <> mysql_real_query( ctx->db_conn->db, sql, len(sql)) ) then + return FALSE + end if + + res = mysql_use_result( ctx->db_conn->db ) + if( NULL = res ) then + return FALSE + end if + + row = mysql_fetch_row( res ) + if( NULL = row ) then + return FALSE + end if + + body = *row[1] + + mysql_free_result( res ) + + function = TRUE + end scope + + end function + + ''::::: + function CWikiConSql.LoadIndex _ + ( _ + byval page as zstring ptr, _ + byref body as string _ + ) as boolean + + function = FALSE + body = "" + + if( ctx = NULL ) then + exit function + end if + + if( page = NULL ) then + exit function + end if + + ZSet @ctx->pagename, page + ctx->pageid = -1 + + scope + dim as string sql + dim as MYSQL_RES ptr res + dim as MYSQL_ROW row + dim as string sName, sBody + + if( Connect() = FALSE ) then + return FALSE + end if + + sql = "SELECT tag FROM wikka_pages WHERE ( latest = 'Y' )" + + if( 0 <> mysql_real_query( ctx->db_conn->db, sql, len(sql)) ) then + return FALSE + end if + + res = mysql_use_result( ctx->db_conn->db ) + if( NULL = res ) then + return FALSE + end if + + do + row = mysql_fetch_row( res ) + if( NULL = row ) then + exit do + end if + body &= *row[0] & nl + loop + + mysql_free_result( res ) + + function = TRUE + end scope + + function = TRUE + + end function + + ''::::: + function CWikiConSql.StorePage _ + ( _ + byval body as zstring ptr, _ + byval note as zstring ptr _ + ) as boolean + + function = FALSE + + end function + + ''::::: + function CWikiConSql.StoreNewPage _ + ( _ + byval body as zstring ptr, _ + byval pagename as zstring ptr _ + ) as boolean + + function = FALSE + + end function + + ''::::: + function CWikiConSql.GetPageID _ + ( _ + ) as integer + + if( ctx = NULL ) then + return 0 + end if + + return ctx->pageid + + end function + +end namespace diff --git a/doc/libfbdoc/CWikiConSql.bi b/doc/libfbdoc/CWikiConSql.bi new file mode 100644 index 0000000000..30fe9f839e --- /dev/null +++ b/doc/libfbdoc/CWikiConSql.bi @@ -0,0 +1,89 @@ +#ifndef __CWIKICONSQL_BI__ +#define __CWIKICONSQL_BI__ + +'' fbdoc - FreeBASIC User's Manual Converter/Generator +'' Copyright (C) 2006-2019 The FreeBASIC development team. +'' +'' This program is free software; you can redistribute it and/or modify +'' it under the terms of the GNU General Public License as published by +'' the Free Software Foundation; either version 2 of the License, or +'' (at your option) any later version. +'' +'' This program is distributed in the hope that it will be useful, +'' but WITHOUT ANY WARRANTY; without even the implied warranty of +'' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +'' GNU General Public License for more details. +'' +'' You should have received a copy of the GNU General Public License +'' along with this program; if not, write to the Free Software +'' Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA. + + +#include once "fbdoc_defs.bi" +#include once "CWikiCon.bi" + +namespace fb.fbdoc + + type CWikiConSqlCtx as CWikiConSqlCtx_ + + type CWikiConSql extends CWikiCon + + declare static sub GlobalInit() + declare static sub GlobalExit() + + declare constructor _ + ( _ + byval db_host as zstring ptr, _ + byval db_user as zstring ptr, _ + byval db_pass as zstring ptr, _ + byval db_name as zstring ptr, _ + byval db_port as integer _ ) + ) + + declare destructor _ + ( _ + ) + + declare function Connect _ + ( _ + ) as boolean + + declare sub Disconnect _ + ( _ + ) + + declare function LoadPage _ + ( _ + byval page as zstring ptr, _ + byref body as string _ + ) as boolean + + declare function LoadIndex _ + ( _ + byval page as zstring ptr, _ + byref body as string _ + ) as boolean + + declare function StorePage _ + ( _ + byval body as zstring ptr, _ + byval note as zstring ptr _ + ) as boolean + + declare function StoreNewPage _ + ( _ + byval body as zstring ptr, _ + byval pagename as zstring ptr _ + ) as boolean + + declare function GetPageID _ + ( _ + ) as integer + + ctx as CWikiConSqlCtx ptr + + end type + +end namespace + +#endif From cb0c0e414f79f6faec7acd52ed1656e305e6c628 Mon Sep 17 00:00:00 2001 From: coderJeff Date: Tue, 21 May 2019 14:02:45 -0400 Subject: [PATCH 12/14] fbdoc: mysql_init() must allocate MYSQL structure due to mismatched version of mysql/mysql.bi and mysql library --- doc/libfbdoc/CWikiConSql.bas | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/doc/libfbdoc/CWikiConSql.bas b/doc/libfbdoc/CWikiConSql.bas index 749581507a..4fecee6dbd 100644 --- a/doc/libfbdoc/CWikiConSql.bas +++ b/doc/libfbdoc/CWikiConSql.bas @@ -61,7 +61,7 @@ namespace fb.fbdoc ( _ ) - db = new MYSQL + db = NULL connected = FALSE end constructor @@ -73,9 +73,7 @@ namespace fb.fbdoc if( connected ) then Disconnect() end if - if( db <> NULL ) then - delete db - end if + db = NULL end destructor @@ -91,6 +89,10 @@ namespace fb.fbdoc function = FALSE + if( connected = TRUE ) then + return TRUE + end if + if( db_host = NULL ) then exit function end if @@ -109,14 +111,16 @@ namespace fb.fbdoc printlog "Connecting to database: " + *db_name + " on " + *db_host + ":" + str(db_port) - if( NULL = mysql_init( db )) then + '' we must let mysql_init() allocate; mysql/mysql.bi is + '' too out of date to trust the sizeof( MYSQL ) + db = mysql_init( NULL ) + + if( NULL = db ) then printlog "Error " + str(mysql_errno(db)) + ": " + *mysql_error(db) printlog "Unable to initialize mysql" return FALSE end if - exit function - if( NULL = mysql_real_connect(db, db_host, db_user, db_pass, db_name, db_port, NULL, 0)) then mysql_close( db ) printlog "Unable to connect to database" @@ -341,7 +345,7 @@ namespace fb.fbdoc return FALSE end if - sql = "SELECT tag FROM wikka_pages WHERE ( latest = 'Y' )" + sql = "SELECT tag FROM wikka_pages WHERE ( latest = 'Y' ) ORDER BY tag" if( 0 <> mysql_real_query( ctx->db_conn->db, sql, len(sql)) ) then return FALSE From 1daaa136b16ef554382b0b96f1267e5aa73ff1d6 Mon Sep 17 00:00:00 2001 From: coderJeff Date: Tue, 21 May 2019 14:03:44 -0400 Subject: [PATCH 13/14] fbdoc: add options for db_host, db_user, db_pass, db_name, db_port --- doc/fbchkdoc/chkdocs.bas | 3 +- doc/fbchkdoc/cmd_opts.bas | 202 +++++++++++++++++++++++++++++++++++++- doc/fbchkdoc/cmd_opts.bi | 10 +- doc/fbchkdoc/delextra.bas | 3 +- doc/fbchkdoc/getimage.bas | 3 +- doc/fbchkdoc/getindex.bas | 20 +++- doc/fbchkdoc/getpage.bas | 4 +- doc/fbchkdoc/mkimglst.bas | 3 +- doc/fbchkdoc/mkprntoc.bas | 3 +- doc/fbchkdoc/putpage.bas | 3 +- doc/fbchkdoc/readme.txt | 8 +- doc/fbchkdoc/rebuild.bas | 3 +- doc/fbchkdoc/spell.bas | 3 +- 13 files changed, 251 insertions(+), 17 deletions(-) diff --git a/doc/fbchkdoc/chkdocs.bas b/doc/fbchkdoc/chkdocs.bas index d6c350ddc9..30ae553823 100644 --- a/doc/fbchkdoc/chkdocs.bas +++ b/doc/fbchkdoc/chkdocs.bas @@ -2226,7 +2226,8 @@ if( app_opt.help ) then end if cmd_opts_resolve() -cmd_opts_check() +cmd_opts_check_cache() +cmd_opts_check_url() if( (opt and OPT_ALL) = 0 ) then print "No options specified" diff --git a/doc/fbchkdoc/cmd_opts.bas b/doc/fbchkdoc/cmd_opts.bas index de8de968f1..5885eda271 100644 --- a/doc/fbchkdoc/cmd_opts.bas +++ b/doc/fbchkdoc/cmd_opts.bas @@ -55,6 +55,7 @@ type CMD_OPTS_PRIVATE enable_autocache as boolean '' automatically select a cache if none given on the command line enable_pagelist as boolean '' enable reading in a text file with a list of page names enable_manual as boolean '' enable the manual dir option + enable_database as boolean '' enable db_* options print as boolean '' -printopts option on command line @@ -89,6 +90,21 @@ type CMD_OPTS_PRIVATE manual as boolean '' -manual_dir given on command line manual_dir as string '' value of '-manual_dir DIR' given on command line + db_host_is_set as boolean '' -db_host given on command line + db_host as string '' value of '-db_host TEXT' given on command line + + db_user_is_set as boolean '' -db_user given on command line + db_user as string '' value of '-db_user TEXT' given on command line + + db_pass_is_set as boolean '' -db_pass given on command line + db_pass as string '' value of '-db_pass TEXT' given on command line + + db_name_is_set as boolean '' -db_name given on command line + db_name as string '' value of '-db_name TEXT' given on command line + + db_port_is_set as boolean '' -db_port given on command line + db_port as integer '' value of '-db_port NUMBER' given on command line + end type dim shared cmd_opt as CMD_OPTS_PRIVATE @@ -107,6 +123,7 @@ sub cmd_opts_init( byval opts_flags as const CMD_OPTS_ENABLE_FLAGS ) cmd_opt.enable_autocache = cbool( opts_flags and CMD_OPTS_ENABLE_AUTOCACHE ) cmd_opt.enable_pagelist = cbool( opts_flags and CMD_OPTS_ENABLE_PAGELIST ) cmd_opt.enable_manual = cbool( opts_flags and CMD_OPTS_ENABLE_MANUAL ) + cmd_opt.enable_database = cbool( opts_flags and CMD_OPTS_ENABLE_DATABASE ) '' general options @@ -132,6 +149,23 @@ sub cmd_opts_init( byval opts_flags as const CMD_OPTS_ENABLE_FLAGS ) cmd_opt.ca = false '' -certificate given on command line cmd_opt.ca_file = "" '' value of '-certificate FILE' given on command line + '' database options + + cmd_opt.db_host_is_set = false '' -db_host given on command line + cmd_opt.db_host = "" '' value of '-db_host TEXT' given on command line + + cmd_opt.db_user_is_set = false '' -db_user given on command line + cmd_opt.db_user = "" '' value of '-db_user TEXT' given on command line + + cmd_opt.db_pass_is_set = false '' -db_pass given on command line + cmd_opt.db_pass = "" '' value of '-db_pass TEXT' given on command line + + cmd_opt.db_name_is_set = false '' -db_name given on command line + cmd_opt.db_name = "" '' value of '-db_name TEXT' given on command line + + cmd_opt.db_port_is_set = false '' -db_port given on command line + cmd_opt.db_port = 0 '' value of '-db_port NUMBER' given on command line + '' login options cmd_opt.user = false '' -u given on command line @@ -146,6 +180,8 @@ sub cmd_opts_init( byval opts_flags as const CMD_OPTS_ENABLE_FLAGS ) cmd_opt.manual = false '' -manual_dir given on command line cmd_opt.manual_dir = "" '' value of '-manual_dir DIR' given on command line + cmd_opt.db_user_is_set = false + '' resolved options app_opt.wiki_url = "" '' export: resolved wiki url @@ -156,6 +192,12 @@ sub cmd_opts_init( byval opts_flags as const CMD_OPTS_ENABLE_FLAGS ) app_opt.image_dir = "" '' export: image directory app_opt.manual_dir = "" '' export: manual directory + app_opt.db_host = "" '' export: database host name + app_opt.db_user = "" '' export: database user name + app_opt.db_pass = "" '' export: database user password + app_opt.db_name = "" '' export: database name + app_opt.db_port = 0 '' export: database port number + app_opt.pageCount = 0 redim app_opt.pageList(1 to 1) as string redim app_opt.pageComments(1 to 1) as string @@ -350,6 +392,81 @@ function cmd_opts_read( byref i as integer ) as boolean return false end if + case "-db_host" + + if( cmd_opt.enable_database ) then + + if( cmd_opt.db_host_is_set ) then + cmd_opts_duplicate_die( i ) + end if + cmd_opt.db_host_is_set = true + i += 1 + cmd_opt.db_host = command(i) + + else + return false + end if + + case "-db_user" + + if( cmd_opt.enable_database ) then + + if( cmd_opt.db_user_is_set ) then + cmd_opts_duplicate_die( i ) + end if + cmd_opt.db_user_is_set = true + i += 1 + cmd_opt.db_user = command(i) + + else + return false + end if + + case "-db_pass" + + if( cmd_opt.enable_database ) then + + if( cmd_opt.db_pass_is_set ) then + cmd_opts_duplicate_die( i ) + end if + cmd_opt.db_pass_is_set = true + i += 1 + cmd_opt.db_pass = command(i) + + else + return false + end if + + case "-db_name" + + if( cmd_opt.enable_database ) then + + if( cmd_opt.db_name_is_set ) then + cmd_opts_duplicate_die( i ) + end if + cmd_opt.db_name_is_set = true + i += 1 + cmd_opt.db_name = command(i) + + else + return false + end if + + case "-db_port" + + if( cmd_opt.enable_database ) then + + if( cmd_opt.db_port_is_set ) then + cmd_opts_duplicate_die( i ) + end if + cmd_opt.db_port_is_set = true + i += 1 + cmd_opt.db_port = cint( command(i) ) + + else + return false + end if + case "-ini" if( cmd_opt.ini ) then cmd_opts_duplicate_die( i ) @@ -421,6 +538,11 @@ function cmd_opts_resolve() as boolean dim as string dev_pass = "" dim as string def_image_dir = hardcoded.default_image_dir dim as string def_manual_dir = hardcoded.default_manual_dir + dim as string db_host = "" + dim as string db_user = "" + dim as string db_pass = "" + dim as string db_name = "" + dim as integer db_port = 3306 '' -ini FILE on the command line overrides the hardcoded value if( cmd_opt.ini ) then @@ -445,6 +567,11 @@ function cmd_opts_resolve() as boolean dev_pass = opts->Get( "dev_password" ) def_image_dir = opts->Get( "image_dir" ) def_manual_dir = opts->Get( "manual_dir" ) + db_host = opts->Get( "db_host" ) + db_user = opts->Get( "db_user" ) + db_pass = opts->Get( "db_pass" ) + db_name = opts->Get( "db_name" ) + db_port = cint( opts->Get( "db_port" ) ) delete opts elseif( cmd_opt.ini ) then '' if we explicitly gave the -ini FILE option, report the error @@ -513,6 +640,36 @@ function cmd_opts_resolve() as boolean app_opt.manual_dir = def_manual_dir end if + if( cmd_opt.db_host_is_set ) then + app_opt.db_host = cmd_opt.db_host + else + app_opt.db_host = db_host + end if + + if( cmd_opt.db_user_is_set ) then + app_opt.db_user = cmd_opt.db_user + else + app_opt.db_user = db_user + end if + + if( cmd_opt.db_pass_is_set ) then + app_opt.db_pass = cmd_opt.db_pass + else + app_opt.db_pass = db_pass + end if + + if( cmd_opt.db_name_is_set ) then + app_opt.db_name = cmd_opt.db_name + else + app_opt.db_name = db_name + end if + + if( cmd_opt.db_port_is_set ) then + app_opt.db_port = cmd_opt.db_port + else + app_opt.db_port = db_port + end if + if( cmd_opt.print ) then print "ini_file = " & ini_file @@ -537,6 +694,11 @@ function cmd_opts_resolve() as boolean print "wiki_password = " & "*****" print "image_dir = " & app_opt.image_dir print "manual_dir = " & app_opt.manual_dir + print "db_host = " & app_opt.db_host + print "db_user = " & app_opt.db_user + print "db_pass = " & app_opt.db_pass + print "db_name = " & app_opt.db_name + print "db_port = " & app_opt.db_port print end 1 @@ -548,7 +710,7 @@ function cmd_opts_resolve() as boolean end function '' -function cmd_opts_check() as boolean +function cmd_opts_check_cache() as boolean if( cmd_opt.enable_cache ) then '' check that we have the values we need @@ -557,6 +719,13 @@ function cmd_opts_check() as boolean end if end if + function = true + +end function + +'' +function cmd_opts_check_url() as boolean + if( cmd_opt.enable_url ) then if( app_opt.wiki_url = "" ) then cmd_opts_die( "no url specified" ) @@ -567,6 +736,28 @@ function cmd_opts_check() as boolean end function +'' +function cmd_opts_check_database() as boolean + + if( cmd_opt.enable_database ) then + '' check that we have the values we need + if( app_opt.db_host = "" ) then + cmd_opts_die( "no database host specified" ) + elseif( app_opt.db_user = "" ) then + cmd_opts_die( "no database user login name specified" ) + elseif( app_opt.db_pass = "" ) then + cmd_opts_die( "no database user login password specified" ) + elseif( app_opt.db_name = "" ) then + cmd_opts_die( "no database name specified" ) + elseif( app_opt.db_port = 0 ) then + cmd_opts_die( "no database port specified" ) + end if + end if + + function = true + +end function + '' sub cmd_opts_show_help_item _ ( _ @@ -655,5 +846,12 @@ sub cmd_opts_show_help( byref action as const string = "", locations as boolean print " -manual_dir DIR override the manual directory location" end if + if( cmd_opt.enable_database ) then + print " -db_host database host name" + print " -db_user database user login name" + print " -db_pass database user login password" + print " -db_name database name" + print " -db_port database port number" + end if -end sub \ No newline at end of file +end sub diff --git a/doc/fbchkdoc/cmd_opts.bi b/doc/fbchkdoc/cmd_opts.bi index f9d28c12e3..ee2b92530a 100644 --- a/doc/fbchkdoc/cmd_opts.bi +++ b/doc/fbchkdoc/cmd_opts.bi @@ -27,6 +27,7 @@ enum CMD_OPTS_ENABLE_FLAGS CMD_OPTS_ENABLE_IMAGE = 8 CMD_OPTS_ENABLE_PAGELIST = 16 CMD_OPTS_ENABLE_MANUAL = 32 + CMD_OPTS_ENABLE_DATABASE = 64 CMD_OPTS_ENABLE_AUTOCACHE = &h1000 @@ -38,7 +39,9 @@ declare sub cmd_opts_unrecognized_die( byval i as const integer ) declare sub cmd_opts_unexpected_die( byval i as const integer ) declare function cmd_opts_read( byref i as integer ) as boolean declare function cmd_opts_resolve() as boolean -declare function cmd_opts_check() as boolean +declare function cmd_opts_check_cache() as boolean +declare function cmd_opts_check_url() as boolean +declare function cmd_opts_check_database() as boolean declare sub cmd_opts_show_help( byref action as const string = "", byval locations as boolean = true ) declare sub cmd_opts_show_help_item( byref opt_name as const string, byref opt_desc as const string ) @@ -56,6 +59,11 @@ type CMD_OPTS_GLOBAL wiki_password as string image_dir as string manual_dir as string + db_host as string + db_user as string + db_pass as string + db_name as string + db_port as integer pageCount as integer pageList(any) as string diff --git a/doc/fbchkdoc/delextra.bas b/doc/fbchkdoc/delextra.bas index 2763f52a4d..9b5c67df41 100644 --- a/doc/fbchkdoc/delextra.bas +++ b/doc/fbchkdoc/delextra.bas @@ -199,7 +199,8 @@ if( app_opt.help ) then end if cmd_opts_resolve() -cmd_opts_check() +cmd_opts_check_cache() +cmd_opts_check_url() '' -------------------------------------------------------- diff --git a/doc/fbchkdoc/getimage.bas b/doc/fbchkdoc/getimage.bas index 8f725efd29..2d7b73f330 100644 --- a/doc/fbchkdoc/getimage.bas +++ b/doc/fbchkdoc/getimage.bas @@ -165,7 +165,8 @@ if( app_opt.help ) then end if cmd_opts_resolve() -cmd_opts_check() +cmd_opts_check_cache() +cmd_opts_check_url() '' -------------------------------------------------------- diff --git a/doc/fbchkdoc/getindex.bas b/doc/fbchkdoc/getindex.bas index 93da10d56e..ad11588bd3 100644 --- a/doc/fbchkdoc/getindex.bas +++ b/doc/fbchkdoc/getindex.bas @@ -48,7 +48,11 @@ dim as boolean bLocal = false '' -local given on command line dim as boolean bUseSql = false '' -usesql given on command line '' enable url and cache +#if defined(HAVE_MYSQL) +cmd_opts_init( CMD_OPTS_ENABLE_URL or CMD_OPTS_ENABLE_CACHE or CMD_OPTS_ENABLE_DATABASE ) +#else cmd_opts_init( CMD_OPTS_ENABLE_URL or CMD_OPTS_ENABLE_CACHE ) +#endif dim i as integer = 1 while( command(i) > "" ) @@ -99,7 +103,6 @@ if( app_opt.help ) then end if cmd_opts_resolve() -cmd_opts_check() '' -------------------------------------------------------- @@ -114,6 +117,8 @@ dim as CWikiCon ptr wikicon = NULL if( bLocal ) then + cmd_opts_check_cache() + wikicon = new CWikiConDir( app_opt.cache_dir ) if wikicon = NULL then print "Unable to create connection " + app_opt.cache_dir @@ -125,18 +130,25 @@ if( bLocal ) then #if defined(HAVE_MYSQL) elseif( bUseSql ) then - '' !!! TODO !!! - load options for host, user, pass, etc - wikicon = new CWikiConSql( "", "", "", "", 0 ) + cmd_opts_check_database() + + wikicon = new CWikiConSql( app_opt.db_host, app_opt.db_user, app_opt.db_pass, app_opt.db_name, app_opt.db_port ) if wikicon = NULL then print "Unable to create connection " + app_opt.cache_dir end 1 end if - print "cache: "; app_opt.cache_dir + dim as CWikiConSql ptr o = cast( CWikiConSql ptr, wikicon ) + if( o->Connect() = FALSE ) then + print "Error" + end 1 + end if #endif else + cmd_opts_check_url() + if( len( app_opt.wiki_url ) = 0 ) then print "wiki_url not set. use -url, -web, -web+, -dev, or -dev+" end 1 diff --git a/doc/fbchkdoc/getpage.bas b/doc/fbchkdoc/getpage.bas index aa181d2cd6..1f569f62ac 100644 --- a/doc/fbchkdoc/getpage.bas +++ b/doc/fbchkdoc/getpage.bas @@ -78,7 +78,9 @@ if( app_opt.help ) then end if cmd_opts_resolve() -cmd_opts_check() +cmd_opts_check_cache() +cmd_opts_check_url() + '' no pages? nothing to do... if( app_opt.pageCount = 0 ) then diff --git a/doc/fbchkdoc/mkimglst.bas b/doc/fbchkdoc/mkimglst.bas index e122274e9b..f4bad39e6d 100644 --- a/doc/fbchkdoc/mkimglst.bas +++ b/doc/fbchkdoc/mkimglst.bas @@ -113,7 +113,8 @@ if( app_opt.help ) then end if cmd_opts_resolve() -cmd_opts_check() +cmd_opts_check_cache() +cmd_opts_check_url() '' no pages? nothing to do... if( app_opt.pageCount = 0 ) then diff --git a/doc/fbchkdoc/mkprntoc.bas b/doc/fbchkdoc/mkprntoc.bas index 860f4134e0..27ab5427e9 100644 --- a/doc/fbchkdoc/mkprntoc.bas +++ b/doc/fbchkdoc/mkprntoc.bas @@ -320,7 +320,8 @@ if( app_opt.help ) then end if cmd_opts_resolve() -cmd_opts_check() +cmd_opts_check_cache() +cmd_opts_check_url() '' -------------------------------------------------------- diff --git a/doc/fbchkdoc/putpage.bas b/doc/fbchkdoc/putpage.bas index 350f5c36ef..b49a598e99 100644 --- a/doc/fbchkdoc/putpage.bas +++ b/doc/fbchkdoc/putpage.bas @@ -87,7 +87,8 @@ if( app_opt.help ) then end if cmd_opts_resolve() -cmd_opts_check() +cmd_opts_check_cache() +cmd_opts_check_url() '' -------------------------------------------------------- diff --git a/doc/fbchkdoc/readme.txt b/doc/fbchkdoc/readme.txt index 122299876a..b7905ba4c0 100644 --- a/doc/fbchkdoc/readme.txt +++ b/doc/fbchkdoc/readme.txt @@ -143,7 +143,7 @@ the '-ini FILE' command line option to any of the tools. given. Set or override this option from the command line using the '-cache DIR' command line option. - dev_cache_dir + dev_cache_dir like web_cache_dir, excect a duplicate of the off-line server's wiki. This cache directory is selected when the '-dev+' command line option is given. Set or override this option from the command line using @@ -192,6 +192,12 @@ the '-ini FILE' command line option to any of the tools. option is given. Set or override these options with '-u USER -p PASS' command line options. + db_host, db_user, db_pass, db_name, db_port + db_host = database host name + db_user = database user login name + db_pass = database user login password + db_name = name of database to select for use + db_port = port on database host Why all the extra directories and extra wiki, you ask? I have all these extra copies of the wiki because many people have worked very hard to create diff --git a/doc/fbchkdoc/rebuild.bas b/doc/fbchkdoc/rebuild.bas index 61699d971e..a57877ecf5 100644 --- a/doc/fbchkdoc/rebuild.bas +++ b/doc/fbchkdoc/rebuild.bas @@ -91,7 +91,8 @@ if( app_opt.help ) then end if cmd_opts_resolve() -cmd_opts_check() +cmd_opts_check_cache() +cmd_opts_check_url() '' no pages? nothing to do... if( app_opt.pageCount = 0 ) then diff --git a/doc/fbchkdoc/spell.bas b/doc/fbchkdoc/spell.bas index 355568c667..70fe7d9097 100644 --- a/doc/fbchkdoc/spell.bas +++ b/doc/fbchkdoc/spell.bas @@ -373,7 +373,8 @@ if( app_opt.help ) then end if cmd_opts_resolve() -cmd_opts_check() +cmd_opts_check_cache() +cmd_opts_check_url() '' no pages? nothing to do... if( app_opt.pageCount = 0 ) then From 570fa4a065905a8ed1c7a7827603be6e2da483f0 Mon Sep 17 00:00:00 2001 From: coderJeff Date: Tue, 21 May 2019 17:34:15 -0400 Subject: [PATCH 14/14] fbdoc: getpage can use CWikiConSql --- doc/fbchkdoc/getindex.bas | 6 ++- doc/fbchkdoc/getpage.bas | 80 ++++++++++++++++++++++++++----- doc/libfbdoc/CWikiConSql.bas | 5 +- doc/libfbdoc/CWikiConUrl.bas | 5 +- doc/libfbdoc/fbdoc_loader_sql.bas | 2 +- 5 files changed, 78 insertions(+), 20 deletions(-) diff --git a/doc/fbchkdoc/getindex.bas b/doc/fbchkdoc/getindex.bas index ad11588bd3..84cbc05c30 100644 --- a/doc/fbchkdoc/getindex.bas +++ b/doc/fbchkdoc/getindex.bas @@ -22,7 +22,10 @@ '' fbdoc headers #include once "CWikiConUrl.bi" #include once "CWikiConDir.bi" + +#if defined(HAVE_MYSQL) #include once "CWikiConSql.bi" +#endif '' fbchkdoc headers #include once "fbchkdoc.bi" @@ -113,7 +116,7 @@ sPage = "PageIndex" dim as CWikiCon ptr wikicon = NULL -'' connect to the wiki and get PageIndex as HTML +'' connect to the wiki and get PageIndex (list of all pages) if( bLocal ) then @@ -146,7 +149,6 @@ elseif( bUseSql ) then #endif else - cmd_opts_check_url() if( len( app_opt.wiki_url ) = 0 ) then diff --git a/doc/fbchkdoc/getpage.bas b/doc/fbchkdoc/getpage.bas index 1f569f62ac..23ca152d7a 100644 --- a/doc/fbchkdoc/getpage.bas +++ b/doc/fbchkdoc/getpage.bas @@ -24,6 +24,10 @@ #include once "fbdoc_loader.bi" #include once "fbdoc_loader_web.bi" +#if defined(HAVE_MYSQL) +#include once "CWikiConSql.bi" +#endif + '' fbchkdoc headers #include once "fbchkdoc.bi" #include once "funcs.bi" @@ -42,9 +46,14 @@ using fbdoc '' private options dim allow_retry as boolean = true +dim as boolean bUseSql = false '' -usesql given on command line '' enable url and cache +#if defined(HAVE_MYSQL) +cmd_opts_init( CMD_OPTS_ENABLE_URL or CMD_OPTS_ENABLE_CACHE or CMD_OPTS_ENABLE_PAGELIST or CMD_OPTS_ENABLE_DATABASE ) +#else cmd_opts_init( CMD_OPTS_ENABLE_URL or CMD_OPTS_ENABLE_CACHE or CMD_OPTS_ENABLE_PAGELIST ) +#endif dim i as integer = 1 while( command(i) > "" ) @@ -54,6 +63,10 @@ while( command(i) > "" ) select case lcase(command(i)) case "-auto" allow_retry = false +#if defined(HAVE_MYSQL) + case "-usesql" + bUseSql = true +#endif case else cmd_opts_unrecognized_die( i ) end select @@ -73,6 +86,9 @@ if( app_opt.help ) then print " -dev+ get pages from the development server in to dev_cache_dir" print cmd_opts_show_help( "get page from", false ) +#if defined(HAVE_MYSQL) + print " -usesql use MySQL connection to read index" +#endif print end 1 end if @@ -80,7 +96,13 @@ end if cmd_opts_resolve() cmd_opts_check_cache() cmd_opts_check_url() - +if( len( app_opt.wiki_url ) = 0 ) then + print "wiki_url not set. use -url, -web, -web+, -dev, or -dev+" + end 1 +end if +if( bUseSql ) then + cmd_opts_check_database() +end if '' no pages? nothing to do... if( app_opt.pageCount = 0 ) then @@ -96,22 +118,47 @@ redim failedpages(1 to 1) as string '' main loop - has option to retry/list failed pages do + dim as CWikiCon ptr wikicon = NULL + '' Initialize the cache if LocalCache_Create( app_opt.cache_dir, CWikiCache.CACHE_REFRESH_ALL ) = FALSE then print "Unable to use local cache dir " + app_opt.cache_dir end 1 end if - '' Initialize the wiki connection - Connection_SetUrl( app_opt.wiki_url, app_opt.ca_file ) - - print "URL: "; app_opt.wiki_url - if( app_opt.ca_file > "" ) then - print "Certificate: "; app_opt.ca_file + if( bUseSql ) then +#if defined(HAVE_MYSQL) + cmd_opts_check_database() + + wikicon = new CWikiConSql( app_opt.db_host, app_opt.db_user, app_opt.db_pass, app_opt.db_name, app_opt.db_port ) + if wikicon = NULL then + print "Unable to create connection " + app_opt.cache_dir + end 1 + end if + + dim as CWikiConSql ptr o = cast( CWikiConSql ptr, wikicon ) + if( o->Connect() = FALSE ) then + print "Error" + end 1 + end if +#endif else - print "Certificate: none" + print "URL: "; app_opt.wiki_url + + wikicon = new CWikiConUrl( app_opt.wiki_url, app_opt.ca_file ) + if wikicon = NULL then + print "Unable to create connection " + app_opt.wiki_url + end 1 + end if + + if( app_opt.ca_file > "" ) then + print "Certificate: "; app_opt.ca_file + else + print "Certificate: none" + end if + + print "cache: "; app_opt.cache_dir end if - print "cache: "; app_opt.cache_dir nfailedpages = 0 @@ -119,12 +166,20 @@ do dim as integer i, j dim as string ret for i = 1 to app_opt.pageCount - ret = LoadPage( app_opt.pageList(i), FALSE, TRUE ) - if( ret = "" ) then + dim sBody as string = "" + print "Loading '" + app_opt.pageList(i) + "'" + if( wikicon->LoadPage( app_opt.pageList(i), sBody ) = FALSE ) then print "Failed to load '" & app_opt.pageList(i) & "'" nfailedpages += 1 redim preserve failedpages( 1 to nfailedpages ) failedpages(nfailedpages) = app_opt.pageList(i) + else + if( wikicon->GetPageID() > 0 ) then + if( len(sBody) > 0 ) then + dim as CWikiCache ptr wikicache = LocalCache_Get() + wikicache->SavePage( app_opt.pageList(i), sBody ) + end if + end if end if if( inkey = chr(27) ) then @@ -142,7 +197,8 @@ do next end if - Connection_Destroy() + delete wikicon + LocalCache_Destroy() '' Check for failed pages diff --git a/doc/libfbdoc/CWikiConSql.bas b/doc/libfbdoc/CWikiConSql.bas index 4fecee6dbd..344f8414cd 100644 --- a/doc/libfbdoc/CWikiConSql.bas +++ b/doc/libfbdoc/CWikiConSql.bas @@ -289,7 +289,7 @@ namespace fb.fbdoc return FALSE end if - sql = "SELECT tag, body FROM wikka_pages WHERE ( latest = 'Y' AND tag = '" & *pagename & "' )" + sql = "SELECT id, tag, CAST(CONVERT(body USING utf8) AS binary) FROM wikka_pages WHERE ( latest = 'Y' AND tag = '" & *pagename & "' )" if( 0 <> mysql_real_query( ctx->db_conn->db, sql, len(sql)) ) then return FALSE @@ -305,7 +305,8 @@ namespace fb.fbdoc return FALSE end if - body = *row[1] + ctx->pageid = cint( *row[0] ) + body = *row[2] mysql_free_result( res ) diff --git a/doc/libfbdoc/CWikiConUrl.bas b/doc/libfbdoc/CWikiConUrl.bas index 0ade7188d6..5ea7ee2716 100644 --- a/doc/libfbdoc/CWikiConUrl.bas +++ b/doc/libfbdoc/CWikiConUrl.bas @@ -549,7 +549,7 @@ namespace fb.fbdoc ctx->pageid = get_pageid( ctx ) - function = TRUE + function = cbool( ctx->pageid > 0 ) end function @@ -585,14 +585,13 @@ namespace fb.fbdoc remove_http_headers( body ) remove_html_tags( body ) extract_page_names( body ) + function = TRUE end if delete stream ctx->pageid = -1 - function = TRUE - end function ''::::: diff --git a/doc/libfbdoc/fbdoc_loader_sql.bas b/doc/libfbdoc/fbdoc_loader_sql.bas index e73b0bb1db..6f5c39c958 100644 --- a/doc/libfbdoc/fbdoc_loader_sql.bas +++ b/doc/libfbdoc/fbdoc_loader_sql.bas @@ -72,7 +72,7 @@ namespace fb.fbdoc return FALSE end if - sql = "SELECT tag, body FROM wikka_pages WHERE ( latest = 'Y' )" + sql = "SELECT tag, CAST(CONVERT(body USING utf8) AS binary) FROM wikka_pages WHERE ( latest = 'Y' )" if( 0 <> mysql_real_query( @db, sql, len(sql)) ) then printlog "Unable to query wikka_pages"