From 086c8657eb0046fce2acef268becdcb891910711 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Sat, 16 Nov 2024 09:46:06 +1300 Subject: [PATCH] Move the HTML file update loop into REXX And remove dry-run support - not needed --- .github/workflows/build.yml | 2 +- doc/mkdocs.bat | 31 +++--- doc/mkdocs.ksc | 183 ++++++++++++++---------------------- doc/mkdocs.rex | 154 +++++++++++++++++++----------- kermit/k95/ckotio.c | 1 + 5 files changed, 188 insertions(+), 183 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dce0f6ec..26b2518d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -184,7 +184,7 @@ jobs: arch: - x86 - x64 - - x64_arm + #- x64_arm - x64_arm64 toolset: # Note: the 14.0 toolset doesn't really work (just results in 14.4) diff --git a/doc/mkdocs.bat b/doc/mkdocs.bat index 9df3e217..c211b1a2 100644 --- a/doc/mkdocs.bat +++ b/doc/mkdocs.bat @@ -11,7 +11,6 @@ if [%1] == [--help] goto :help REM Defaults: use git dates, build for K95 distribution (not web) with https REM links. set GIT_DATES=true -set DRY_RUN=false set DEV_MODE=false set WEB_MODE=false set HTTPS_MODE=true @@ -21,7 +20,7 @@ for %%I in (%*) do ( rem Value after a switch if defined switch ( - rem Example: /X + rem /O for Output Directory if /i "!switch:~1!"=="O" set "OUT_DIR=%%~I" set "switch=" @@ -32,13 +31,12 @@ for %%I in (%*) do ( echo(%%~I | >NUL findstr "^[-/]" && ( set "switch=%%~I" REM G = no git-file-dates - REM N = dry-run REM D = dev-mode REM W = web-mode REM S = use-https rem Check for a valid switch - for %%x in (G N D W I O) do ( + for %%x in (G D W I O) do ( if /i "!switch:~1!"=="%%x" set "valid=true" ) @@ -54,11 +52,6 @@ for %%I in (%*) do ( set "switch=" ) - if /i "!switch:~1!"=="N" ( - set "DRY_RUN=true" - set "switch=" - ) - if /i "!switch:~1!"=="D" ( set "DEV_MODE=true" set "switch=" @@ -91,7 +84,6 @@ echo libraries must also be built and avaialble. echo. echo Options: echo /G Don't get file dates from git. Timestamps will be wrong. -echo /N Dry run - don't actually do anything echo /D Dev mode - release tag will be "DEV" rather than "BETA.7" or echo nothing, indicating this isn't an final/release version of the echo manual. @@ -122,7 +114,6 @@ if "%OUT_DIR%" == "" set OUT_DIR=%dist_root%\docs\manual\ echo Parameters: echo Git File dates: %GIT_DATES% -echo Dry Run: %DRY_RUN% echo Dev Mode: %DEV_MODE% echo Web Mode: %WEB_MODE% echo HTTPS Mode: %HTTPS_MODE% @@ -153,15 +144,25 @@ k95.exe -Y -# 127 -C "save keymap %manual_dist_dir%default.ksc,exit" > NUL: REM Copy manual to the output directory updating version numbers, etc, as we go REM Parameters are: source-directory destination-directory, git-file-dates dry-run dev-mode web-mode use-https -k95.exe %docs_root%\mkdocs.ksc -Y -d -# 127 = %docs_root%\manual %OUT_DIR% %GIT_DATES% %DRY_RUN% %DEV_MODE% %WEB_MODE% %HTTPS_MODE% +k95.exe %docs_root%\mkdocs.ksc -Y -d -# 127 = %docs_root%\manual %OUT_DIR% %GIT_DATES% %DEV_MODE% %WEB_MODE% %HTTPS_MODE% || goto :failed REM And update modified dates for anything that hasn't changed since the manual REM was added to git -if "%DRY_RUN%" == "true" goto :skipfd -k95.exe -Y -H -# 127 -C ".manual_dir := %manual_dist_dir%,.modtime_file := %mtime_file%,rexx call setdates,exit" -:skipfd +k95.exe -Y -H -# 127 -C ".manual_dir := %manual_dist_dir%,.modtime_file := %mtime_file%,rexx call setdates,exit" || goto :failed echo manual done. +goto :finished + +:failed +echo K95 Manual build failed with exit status: %errorlevel% +popd + +set REGINA_MACROS=%REGINA_MACROS_OLD% +set REGINA_MACROS_OLD= + +exit /B 1 + +:finished popd set REGINA_MACROS=%REGINA_MACROS_OLD% diff --git a/doc/mkdocs.ksc b/doc/mkdocs.ksc index b4f5855c..d1d8bc88 100644 --- a/doc/mkdocs.ksc +++ b/doc/mkdocs.ksc @@ -73,6 +73,8 @@ ; TODO: Add a "prerelease" flag that would add a header to the top of every ; page indicating this documentation is preliminary, etc. +log debug + local ver_maj_min ver_full ver_long_date ver_date ver_date_iso file_last_modified touch_date ; ============================================================================ @@ -108,16 +110,14 @@ if not defined \%2 usage .dest := \Fcontents(\%2) .touch_files := true -.dry_run := false .dev_mode := false .web_mode := 1 .use_https := 1 if defined \%3 .touch_files := \%3 -if defined \%4 .dry_run := \%4 -if defined \%5 .dev_mode := \%5 -if defined \%6 .web_mode := \%6 -if defined \%7 .use_https := \%7 +if defined \%5 .dev_mode := \%4 +if defined \%6 .web_mode := \%5 +if defined \%7 .use_https := \%6 if \m(dev_mode) { .dev_mode = 1 @@ -197,29 +197,6 @@ define date_to_touch_date { } } -; ============================================================================ -; Function to update tags in a single file - -def process_file { - local file_in file_out gitdate git_date - define \%9 - - .file_in := \Freplace(\%1,/,\\) - .file_out := \Freplace(\%2,/,\\) - .gitdate := \%3 - - ; ============================================================================ - ; Get file modified date from git if requested - if = \m(gitdate) 1 { - .git_date := \Fcommand(git log -1 --pretty="format:%ci" \m(file_in) 2> nul) - } - - ; Update the file. This is done in REXX as its easier (regular expressions) - ; and faster. - rexx call mkdocs -} - - ; ============================================================================ ; Process files @@ -232,71 +209,62 @@ if neq "\Fsubstring(\m(dest),\flength(\m(dest)),1)" "/" { .dest := \m(dest)/ } -array declare f +array declare f o -dir /array:f /files \m(src) +; HTML files that need transforming +dir /array:f /files \m(src)/*.html -if = \m(web_mode) 0 { - ; If not in web-mode, build a list of .html files that will need to be - ; renamed to .htm +; Other files that just need copying and maybe touching +dir /array:o /files \m(src)/{*.css,*.gif,*.jpg} - local curdir - array declare g +; Build a list of .html files that need processing - .curdir := \v(directory) - cd \m(src) - dir /array:g /files *.html - cd \m(curdir) +local curdir +array declare g - ; mkdocs.rex will pick up the list of .html files to rename from here. - .html_files := \fjoin(&g[],{,}) -} +.curdir := \v(directory) +cd \m(src) +dir /array:g /files *.html +cd \m(curdir) + +; mkdocs.rex will pick up the list of .html files to rename from here. +.html_files := \fjoin(&g[],{,}) + +echo HTML Files: \m(html_files) mkdir \m(dest) -echo Processing \fdim(&f) files... +echo Processing \fdim(&f) HTML files... +echo Hand over to REXX +rexx call mkdocs +echo Back from REXX -.\%x = 1 -while <= \%x \fdim(&f) { - .idx := \Fsearch(*.{htm,html},\&f[\%x]) +echo Processing \fdim(&o) Other files... - .src_file := \&f[\%x] - .dst_file := \m(dest)\Fbasename(\&f[\%x]) - .src_date := \Fdate(\m(src_file)) +for \%x 1 \fdim(&o) 1 { + ; echo Loop Top iteration \%x of \fdim(&o) - if = \m(idx) 1 { - echo \%x. UPDATE \m(src_file) ---> \m(dst_file) - if \m(dry_run) { - echo process_file \m(src_file) \m(dst_file) \m(touch_files) - } else { - process_file \m(src_file) \m(dst_file) \m(touch_files) - } - } - else { - echo \%x. COPY \m(src_file) ---> \m(dst_file) - - if \m(dry_run) { - echo copy /overwrite:always \m(src_file) \m(dst_file) - } else { - copy /overwrite:always \m(src_file) \m(dst_file) - } - - if = \m(touch_files) 1 { - ; Try with git first, in RFC2822 style: Mon, 19 Aug 2024 19:41:25 +1200 - .touch_date := \Fcommand(git log -1 --pretty="format:%cd" --date=format:%Y:%m:%d:%H:%M:%S \m(src_file) 2> nul) - - ; Convert to the format required by Touch - if = \flength(\m(touch_date)) 0 date_to_touch_date {\m(src_date)} 0 - ;else date_to_touch_date {\m(gitdate)} 1 - - if \m(dry_run) { - echo touch /modtime:\m(touch_date) \m(dst_file) - } else { - touch /modtime:\m(touch_date) \m(dst_file) - } - } - } - increment \%x + .file_in := \&o[\%x] + ; echo file_in \m(file_in) + .file_out := \m(dest)\Fbasename(\&o[\%x]) + ; echo file_out \m(file_out) + .src_date := \Fdate(\m(file_in)) + ; echo src_date \m(src_date) + + echo \%x. COPY \m(file_in) ---> \m(file_out) + + copy /overwrite:always \m(file_in) \m(file_out) + if fail exit 1 + + if = \m(touch_files) 1 { + ; Try with git first, in RFC2822 style: Mon, 19 Aug 2024 19:41:25 +1200 + .touch_date := \Fcommand(git log -1 --pretty="format:%cd" --date=format:%Y:%m:%d:%H:%M:%S \m(file_in) 2> nul) + + ; Convert to the format required by Touch + if = \flength(\m(touch_date)) 0 date_to_touch_date {\m(src_date)} 0 + + touch /modtime:\m(touch_date) \m(file_out) + } } ; TODO: Only do this if the default keymap actually exists @@ -310,40 +278,31 @@ echo Updating default keymap HTML file (default.html) from \m(dest)../../keymaps if = \m(web_mode) 0 { .defhtm := \m(dest)default.htm } -if \m(dry_run) { - echo Generate \m(defhtm) -} else { - fopen /read \%i \m(dest)default.ksc - fopen /write \%o \m(defhtm) - fwrite /line \%o {} - fwrite /line \%o {} - fwrite /line \%o {} - fwrite /line \%o {
}
-    while true {
-        undef line
-        fread /line \%i line
-        if fail break
-        fwrite /line \%o \m(line)
-    }
-    fwrite /line \%o {
} - fwrite /line \%o {} - fclose \%i - fclose \%o - if exist \m(dest)default.ksc del /noask \m(dest)default.ksc + +fopen /read \%i \m(dest)default.ksc +fopen /write \%o \m(defhtm) +fwrite /line \%o {} +fwrite /line \%o {} +fwrite /line \%o {} +fwrite /line \%o {
}
+while true {
+    undef line
+    fread /line \%i line
+    if fail break
+    fwrite /line \%o \m(line)
 }
+fwrite /line \%o {
} +fwrite /line \%o {} +fclose \%i +fclose \%o +if exist \m(dest)default.ksc del /noask \m(dest)default.ksc if = \m(web_mode) 0 { echo Swapping around index.htm - if \m(dry_run) { - echo if exist {\m(dest)kermit95.htm} del /noask {\m(dest)kermit95.htm} - echo ren \m(dest)index.htm \m(dest)kermit95.htm - echo ren \m(dest)docindex.htm \m(dest)index.htm - } - else { - if exist {\m(dest)kermit95.htm} del /noask {\m(dest)kermit95.htm} - ren \m(dest)index.htm \m(dest)kermit95.htm - ren \m(dest)docindex.htm \m(dest)index.htm - } + + if exist {\m(dest)kermit95.htm} del /noask {\m(dest)kermit95.htm} + ren \m(dest)index.htm \m(dest)kermit95.htm + ren \m(dest)docindex.htm \m(dest)index.htm } echo Done diff --git a/doc/mkdocs.rex b/doc/mkdocs.rex index 19ca725f..b3e23d3f 100644 --- a/doc/mkdocs.rex +++ b/doc/mkdocs.rex @@ -49,67 +49,34 @@ if rxFuncQuery("sysloadfuncs") = 1 then do say "RegUtil loaded successfully" end - -/* Get input and output file names. Because the names can contain spaces, - * its easier to just pluck these out of Kermit rather than try and take - * them as arguments. - */ -input_file = CKermit("return \m(file_in)") -output_file = CKermit("return \m(file_out)") -git_date = CKermit("return \m(git_date)") +/* 1 = use 'DEV' as version tag, 0 = don't do that */ dev_mode = CKermit("return \m(dev_mode)") +/* 1 = get file modified times from git, 0 = don't do that */ +touch_files = CKermit("return \m(touch_files)") + /* 1 = use https://kermitproject.org, 0 = use http://kermitproject.org */ use_https = CKermit("return \m(use_https)") /* 1 = generate .html files, 0 = generate .htm files and fix up links */ use_html = CKermit("return \m(web_mode)") +src_dir = CKermit("return \m(src)") +dest_dir = CKermit("return \m(dest)") + /* This is a list of all html files that we'll replacing references to within * files */ html_files. = '' - -if use_html = 0 then do - /* If we're renaming html -> htm, then prepare the list of all html - * files! */ - new_fn= CKermit("return \m(html_files)") - do #=1 until new_fn=='' - parse var new_fn html_files.# ',' new_fn - end - - /* And update the name of *this* file we're processing */ - output_file = changestr(".html",output_file,".htm") +new_fn= CKermit("return \m(html_files)") +do #=1 until new_fn=='' +parse var new_fn html_files.# ',' new_fn end -/* -say "input_file =" input_file -say "output_file =" output_file -say "git date =" git_date -*/ - /* REXX doesn't allow returning stems, get_version_tags will create the tags * stem as a global, and populate it with information about the Kermit version * this script is running under. */ call get_version_tags -/* If Kermit can't supply gits date for this file, then use the existing - * file date: - */ -if length(git_date) = 0 then do - tags.last_update_iso = SysGetFileDateTime(input_file, 'm') - parse var tags.last_update_iso f_date" "f_time -end -else do - tags.last_update_iso = git_date - parse var tags.last_update_iso f_date" "f_time" "f_tz -end - -parse var f_date f_date_y"-"f_date_m"-"f_date_d - -tags.last_update=left(date('W',f_date,'I'),3)" "left(date('M',f_date,'I'),3)" "f_date_d" "f_time" "f_date_y - -tags.last_update_short = f_date_d" "date('M',f_date,'I')" "f_date_y - /* say "Replacement Values" say "------------------" @@ -127,12 +94,6 @@ say " File last update short ($last_update_short$):" tags.last_update_short say "-----" */ -/* Ensure output file doesn't exist */ -rcc = SysFileDelete(output_file) -/* rcc=0: success, rcc=2: doesn't exist */ -if rcc > 2 then say "error deleting output file:" output_file "("rcc")" -if rcc = 1 then say "error deleting output file:" output_file "("rcc")" - /* Flags are: * 'x': use extended regular expressions; * 'c': respect case @@ -145,6 +106,85 @@ if rcc = 1 then say "error deleting output file:" output_file "("rcc")" tagre = ReComp('([^<]*)', 'x') replre = ReComp('\$!([a-z\-]*)\$', 'x') +do j=1 for # + filename = html_files.j + call process_html_file filename +end + +call ReFree tagre +call ReFree replre + +Say "processing done." +return + +process_html_file: +arg filename + +/* Get input and output file names. Because the names can contain spaces, + * its easier to just pluck these out of Kermit rather than try and take + * them as arguments. + */ + +filename = lower(filename) + +input_file = src_dir"/"filename +output_file = dest_dir""filename +say "UPDATE " input_file "--->" output_file + +/* Git prevers the forward slashes, so save a copy of the filename before + * we convert it to a windows-style path */ +git_fn = input_file + +input_file = changestr("/",input_file,"\") +output_file = changestr("/",output_file,"\") + +if use_html = 0 then do + /* And update the name of *this* file we're processing */ + output_file = changestr(".html",output_file,".htm") +end + +/* This is the date from git, if we're asked to do that */ +git_date = '' + +if touch_files = 1 then do + /* The usual REXX commands for running other programs or commands don't work + * here as any system commands are actually handed off to Kermit 95 for + * execution as it is in effect our shell. So we've got to ask K95 to run + * git + */ + git_date = CKermit('return \Fcommand(git log -1 --pretty="format:%ci" "'git_fn'" 2> nul)') +end + +/* +say "input_file =" input_file +say "output_file =" output_file +say "git date =" git_date +*/ + +/* If Kermit can't supply gits date for this file, then use the existing + * file date: + */ +if length(git_date) = 0 then do + tags.last_update_iso = SysGetFileDateTime(input_file, 'm') + parse var tags.last_update_iso f_date" "f_time +end +else do + tags.last_update_iso = git_date + parse var tags.last_update_iso f_date" "f_time" "f_tz +end + +parse var f_date f_date_y"-"f_date_m"-"f_date_d + +tags.last_update=left(date('W',f_date,'I'),3)" "left(date('M',f_date,'I'),3)" "f_date_d" "f_time" "f_date_y + +tags.last_update_short = f_date_d" "date('M',f_date,'I')" "f_date_y + +/* Ensure output file doesn't exist */ +rcc = SysFileDelete(output_file) +/* rcc=0: success, rcc=2: doesn't exist */ +if rcc > 2 then say "error deleting output file:" output_file "("rcc")" +if rcc = 1 then say "error deleting output file:" output_file "("rcc")" + do while lines(input_file) = 1 input_string = linein(input_file) @@ -187,7 +227,7 @@ do while lines(input_file) = 1 /* For debugging say fields.0 'fields' do i = 1 to fields.0 - say i '»'fields.i'«' + say i '�'fields.i'�' end*/ @@ -214,7 +254,7 @@ do while lines(input_file) = 1 /* For debugging say fields.0 'fields' do i = 1 to fields.0 - say i '»'fields.i'«' + say i '�'fields.i'�' end */ @@ -242,8 +282,12 @@ do while lines(input_file) = 1 end -call ReFree tagre -call ReFree replre +/* It is important we close the input and output files, otherwise Regina + * will crash when returning to Kermit 95 as it tries to clean up any unclosed + * files. This appears to be a bug in Regina REXX 3.9.6 at least. + */ +rc = close(input_file) +rc = close(output_file) /* Set file timestamp */ /* @@ -253,7 +297,7 @@ say " f_time:" f_time */ rcc = SysSetFileDateTime(output_file, f_date, f_time) -exit 0 +return get_version_tags: procedure expose tags. /* This sets tags. as a global as procedures aren't allowed to return stems. @@ -272,7 +316,7 @@ get_version_tags: procedure expose tags. /* For debugging: output each of the things found in the herald say fields.0 'fields' do i = 1 to fields.0 - say i '»'fields.i'«' + say i '�'fields.i'�' end*/ tags.ver_num = fields.1 /* $ver$ */ diff --git a/kermit/k95/ckotio.c b/kermit/k95/ckotio.c index 9a71fe8d..f2246d9f 100644 --- a/kermit/k95/ckotio.c +++ b/kermit/k95/ckotio.c @@ -9658,6 +9658,7 @@ os2rexxckcmd( int i ; for ( i = 0 ; i < Argc ; i++ ) { + printf("os2rexxckcmd maclvl=%d, command=%s\n",maclvl, RXSTRPTR(Argv[i])); rc = domac("_rexx_commands",RXSTRPTR(Argv[i]),CF_REXX); debug(F111,"os2rexxckcmd",RXSTRPTR(Argv[i]),rc); delmac("_rexx_commands",0);