Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,110 changes: 806 additions & 304 deletions doc/fbchkdoc/chkdocs.bas

Large diffs are not rendered by default.

659 changes: 659 additions & 0 deletions doc/fbchkdoc/cmd_opts.bas

Large diffs are not rendered by default.

68 changes: 68 additions & 0 deletions doc/fbchkdoc/cmd_opts.bi
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#ifndef __FBCHKDOC_CMD_OPTS_BI__
#define __FBCHKDOC_CMD_OPTS_BI__

'' fbchkdoc - FreeBASIC Wiki Management Tools
'' Copyright (C) 2018 Jeffery R. Marshall (coder[at]execulink[dot]com)
''
'' 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.

'' cmd_opts.bas
enum CMD_OPTS_ENABLE_FLAGS
CMD_OPTS_ENABLE_NONE = 0
CMD_OPTS_ENABLE_URL = 1
CMD_OPTS_ENABLE_CACHE = 2
CMD_OPTS_ENABLE_LOGIN = 4
CMD_OPTS_ENABLE_IMAGE = 8
CMD_OPTS_ENABLE_PAGELIST = 16
CMD_OPTS_ENABLE_MANUAL = 32

CMD_OPTS_ENABLE_AUTOCACHE = &h1000

end enum

declare sub cmd_opts_init( byval opts_flags as const CMD_OPTS_ENABLE_FLAGS )
declare sub cmd_opts_die( byref msg as const string )
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 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 )

type CMD_OPTS_GLOBAL

'' command line options
help as boolean
verbose as boolean

''resolved options
wiki_url as string
cache_dir as string
ca_file as string
wiki_username as string
wiki_password as string
image_dir as string
manual_dir as string

webPageCount as integer
webPageList(any) as string
webPageComments(any) as string

end type

extern app_opt as CMD_OPTS_GLOBAL

#endif
183 changes: 118 additions & 65 deletions doc/fbchkdoc/delextra.bas
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,48 @@

'' fbdoc headers
#include once "fbdoc_defs.bi"
#include once "COptions.bi"
#include once "fbdoc_string.bi"
#include once "hash.bi"

'' fbchkdoc headers
#include once "fbchkdoc.bi"
#include once "funcs.bi"
#include once "cmd_opts.bi"

using fb
using fbdoc

dim shared pagehash as HASH
const def_index_file = hardcoded.default_index_file
const def_output_file = "delete.html"
const wakka_extension = "wakka"
const DELETE_ME_SENTINEL = "!!! DELETE ME !!!"

dim shared filehash as HASH

'' --------------------------------------------------------

''
function ReadIndex( byref f as string ) as integer
sub loghtml( byref x as string, byval bNew as integer = FALSE )
dim h as integer = freefile
if( bNew ) then
open def_output_file for output as #h
else
open def_output_file for append as #h
end if
print #h, x
close #h
end sub

''
function ReadIndex( byref f as const string ) as boolean
dim as string x
dim as integer h
h = freefile
dim as integer h = freefile
if( open( f for input access read as #h ) = 0 ) then
while eof(h) = 0
line input #h, x
x = trim(x)
if( len(x) > 0 ) then
pagehash.add( x )
filehash.add( lcase(x) + ".wakka" )
filehash.add( lcase(x) + "." + wakka_extension )
end if
wend
close #h
Expand All @@ -54,108 +71,144 @@ function ReadIndex( byref f as string ) as integer
return FALSE
end function

''
function ShouldRemove _
( _
byref path as const string, _
byref filename as const string, _
byval doscan as const boolean _
) as boolean

if( filehash.test( lcase(filename) ) ) then
if( doscan ) then
dim sBody as string = LoadFileAsString( path + filename )
return left( ucase( ltrim( sBody, any " " & chr(9))), len( DELETE_ME_SENTINEL ) ) = DELETE_ME_SENTINEL
end if
return false
end if

return true

end function

''
sub DeleteExtraFiles _
( _
byref path as string, _
byval isgit as integer, _
byval nodelete as integer _
byref path as const string, _
byval isgit as boolean, _
byval nodelete as boolean, _
byval doscan as boolean, _
byval bHTML as boolean, _
byref wiki_url as const string _
)

dim d as string, i as integer
d = dir( path + "*.wakka" )
if( bHTML ) then
loghtml( "", TRUE )
loghtml( "<html><body>" )
end if

dim d as string = dir( path + "*." + wakka_extension )
while( d > "" )
if( filehash.test( lcase(d) ) = FALSE ) then

if( ShouldRemove( path, d, doscan ) ) then

if( bHTML ) then
dim pagename as string = left( d, len(d) - len("." + wakka_extension) )
loghtml( "<a href=""" + wiki_url + "?wakka=" + pagename + "/delete"">" + pagename + "/delete</a><br>" )
end if

dim n as string = ReplacePathChar( path + d, asc("/") )
if( isgit ) then
print "Removing '" + n + "'"
dim cmd as string = !"git -C \"" & path & !"\" rm \"" + n + !"\""
if( app_opt.verbose ) then
print " SHELL: " & cmd
end if
if( nodelete = FALSE ) then
shell !"git rm \"" + n + !"\""
shell cmd
end if
else
print "Deleting '" + path + d + "'"
if( app_opt.verbose ) then
print " KILL: " & n
end if
if( nodelete = FALSE ) then
kill n
end if
end if
end if

d = dir()
wend

end sub
if( bHTML ) then
loghtml( "" )
loghtml( "</body></html>" )
end if

end sub

'' --------------------------------------------------------
'' MAIN
'' --------------------------------------------------------

dim as string cache_dir, def_cache_dir, web_cache_dir, dev_cache_dir
dim as integer i = 1, isgit = FALSE, nodelete = FALSE

if( command(i) = "" ) then
print "delextra [options]"
print
print " -n only print what would happen but don't"
print " actually delete any files"
print " -git use 'git rm' instead of file system delete"
print
print " -web delete extra files in cache_dir"
print " -web+ delete extra files in web cache_dir"
print " -dev delete extra files in cache_dir"
print " -dev+ delete extra files in dev cache_dir"
end 0
end if
'' private options
dim isgit as boolean = false
dim nodelete as boolean = false
dim doscan as boolean = false
dim bHTML as boolean = false

'' read defaults from the configuration file (if it exists)
scope
dim as COptions ptr opts = new COptions( default_optFile )
if( opts <> NULL ) then
def_cache_dir = opts->Get( "cache_dir", default_CacheDir )
web_cache_dir = opts->Get( "web_cache_dir", default_web_CacheDir )
dev_cache_dir = opts->Get( "dev_cache_dir", default_dev_CacheDir )
delete opts
else
'' print "Warning: unable to load options file '" + default_optFile + "'"
'' end 1
def_cache_dir = default_CacheDir
web_cache_dir = default_web_CacheDir
dev_cache_dir = default_dev_CacheDir
end if
end scope
'' enable cache
cmd_opts_init( CMD_OPTS_ENABLE_URL or CMD_OPTS_ENABLE_CACHE )

dim i as integer = 1
while( command(i) > "" )
if( left(command(i), 1) = "-" ) then
if( cmd_opts_read( i ) ) then
continue while
elseif( left( command(i), 1 ) = "-" ) then
select case lcase(command(i))
case "-web", "-dev"
cache_dir = def_cache_dir
case "-web+"
cache_dir = web_cache_dir
case "-dev+"
cache_dir = dev_cache_dir
case "-scan"
doscan = true
case "-html"
bHTML = true
case "-git"
isgit = TRUE
isgit = true
case "-n"
nodelete = TRUE
nodelete = true
case else
print "Unrecognized option '" + command(i) + "'"
end 1
cmd_opts_unrecognized_die( i )
end select
else
print "Unexpected option '" + command(i) + "'"
end 1
cmd_opts_unexpected_die( i )
end if
i += 1
wend
wend

if( cache_dir = "" ) then
cache_dir = def_cache_dir
if( app_opt.help ) then
print "delextra [options]"
print
print "options:"
cmd_opts_show_help_item( "-n", "only print what would happen but don't actually delete any files" )
cmd_opts_show_help_item( "-scan", "scan page for " + DELETE_ME_SENTINEL )
cmd_opts_show_help_item( "-html", "write '" + def_output_file + "' helper file" )
cmd_opts_show_help_item( "-git", "use 'git rm' instead of file system delete" )
print
cmd_opts_show_help( "delete extra files in" )
print
end 0
end if
print "cache: "; cache_dir

cmd_opts_resolve()
cmd_opts_check()

'' --------------------------------------------------------

print "cache: "; app_opt.cache_dir

print "Reading '" + def_index_file + "' ..."
if( ReadIndex( def_index_file ) = FALSE ) then
print "Unable to read '" + def_index_file + "'"
end 1
end if

DeleteExtraFiles( cache_dir, isgit, nodelete )
DeleteExtraFiles( app_opt.cache_dir, isgit, nodelete, doscan, bHTML, app_opt.wiki_url )
41 changes: 30 additions & 11 deletions doc/fbchkdoc/fbchkdoc.bi
Original file line number Diff line number Diff line change
@@ -1,19 +1,38 @@
#ifndef __FBCHKDOC_FBCHKDOC_BI__
#define __FBCHKDOC_FBCHKDOC_BI__

'' configuration file
const default_optFile = "fbchkdoc.ini"
/'
The hard-coded defaults are the option values used
when:
1) ini file not found, or
2) ini file was found but option not present; and
3) no option was given on the command line

const default_ManualDir = "../manual/"
In otherwords, provide hard-coded defaults to work with
the FreeBASIC development tree, when no other options
are specified in the ini file or on command line.
'/

'' cache dirs
const default_CacheDir = "../manual/cache/"
const default_web_CacheDir = "../manual/cache.web/"
const default_dev_CacheDir = "../manual/cache.dev/"
namespace hardcoded

'' other common defaults
const def_index_file = "PageIndex.txt"
const default_image_dir = "../manual/html/images/"
const default_fb_dir = "../../"
'' configuration file
const default_ini_file = "fbchkdoc.ini"

const default_manual_dir = "../manual/"

'' cache dirs
const default_def_cache_dir = "../manual/cache/"
const default_web_cache_dir = "../manual/cache.web/"
const default_dev_cache_dir = "../manual/cache.dev/"

'' url defaults
const default_web_wiki_url = "https://www.freebasic.net/wiki/wikka.php"

'' other common defaults
const default_index_file = "PageIndex.txt"
const default_image_dir = "../manual/html/images/"
const default_fb_dir = "../../"

end namespace

#endif
2 changes: 1 addition & 1 deletion doc/fbchkdoc/fmtcode.bas
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ function FormatFbCodeLoadKeywords( byref filename as string ) as boolean
'' Load the keywords, this will allow keywords to be cased.

if( filename = "" ) then
filename = default_ManualDir + "templates/default/keywords.lst"
filename = hardcoded.default_manual_dir + "templates/default/keywords.lst"
end if
function = ( fbdoc_loadkeywords( filename ) <> 0 )

Expand Down
Loading