SCD

********************************************************************************
* *
* *
* SNOBOL4 Program to adapt DUKE DDP „beta code“ output *
* to beta code standards *
* (c) B.Meissner, Universitaet der Bundeswehr, Hamburg *
* *
********************************************************************************
-plusops 1
&trim = 1
&anchor = 1
numbers = „0123456789“
ucase = &ucase
lcase = &lcase
htmlcodes = table(1001)
htmlcodes<„rpar“> = „]1“
htmlcodes<„lpar“> = „[1“
htmlcodes<„lt“> = „]2“
htmlcodes<„gt“> = „[2“
html_pat = pos(0) breakx(„&“) . fp len(1) break(„;“) . code „;“
emptypat = pos(0) span(char(32) numbers char(9)) rpos(0)
* REPL(S1,S2,S3) WILL DO A STRING-BY-STRING REPLACEMENT ON S1
* (with the anchored, improved algorithm using BREAKX):
*
DEFINE(‚REPL(S1,S2,S3)C,T,FINDC‘) :(REPL_END)
REPL S2 LEN(1) . C :F(FRETURN)
FINDC = BREAKX(C) . T S2
REPL_1 S1 FINDC = :F(REPL_2)
REPL = REPL T S3 :(REPL_1)
REPL_2 REPL = REPL S1 :(RETURN)
REPL_END
define(„html_code(string)fp,code,c“) :(html_code_end)
html_code
+ string ? html_pat = :f(html_code_return)
c = htmlcodes<code>
c = ident(c) “ &“ code „; “
html_code = html_code
+ fp
+ c :(html_code)
html_code_return
+ html_code = html_code string :(return)
html_code_end
*
*
* DOT_REPLACE replaces the idiosyncratic „.c 12“ etc.
* signs by a kind of coding ahich is more beta code conformant:
*
*
define(„dot_replace(string)ifp,numberer“) :(dot_replace_end)
dot_replace
+ string ? pos(0) breakx(„.“) . fp len(1) „c“ span(char(32))
+ span(numbers) . number = :f(dot_replace_ret)
dot_replace = dot_replace fp
+ dupl(char(32) „?“,number) :(dot_replace)
dot_replace_ret
+ dot_replace = dot_replace string :(return)
dot_replace_end
*
*
* Count() is used to take away leading line numbers
* it determines if a number is by step larger as the last
* counter, and if so, regards the number as the next counter
* (and eventually it will be removed), increasing the counter by step
*
*
counter = 0
define(„count(argument,step)“) :(count_end)
count eq(argument,counter + step) :f(freturn)
counter = counter + step :(return)
count_end
+ system = „Snobol4+“
&ERRLIMIT = 4; SETEXIT(CONTINUE)
system = host()
* Get system type:
&ERRLIMIT = 0
system =
+ ?(system ? breakx(„C“) „CSNOBOL“ )
+ „Linux“
system = ?(system ? breakx(„M“) „Macro SPITBOL“) „Spitbol“
*
* Write stand-alone modules or runtime save files:
*
*
* If MacroSPITBOL is present, we write an execution module:
*
ident(system,“Spitbol“) exit(3,“duke.exe“)
*
* If running under Snobol4+, we open a new output channel and write a save module:
*
ident(system,“Snobol4+“) output(.saveout,16,,“duke.sav“)
ident(system,“Snobol4+“) save(16) :s(end)
*
&ERRLIMIT = 4; SETEXIT(CONTINUE)
parms = &parm
*
* Special command line treatment for SNOBOL4+ (program name as first parameter):
*
parms pos(0) (SPAN(SPACE) | “) break(space) rem . parms
*
* Get parameters for SPITBOL/CSnobol4:
*
parms = host(0)
*
* Reset error limit to zero:
*
&ERRLIMIT = 0
terminal = „DUKE – program to normalize DDP ‚beta code'“
terminal = “ (c) Burkhard Meissner, 2006″
parms pos(0) (span(“ „) | „“) break(“ “ char(9)) . infile
+ span(char(32) char(9)) (break(“ “ char(9) „/-„) | rem) . outfile
+ :f(nofile)
terminal = „Opening files:“
terminal = „In: “ infile
terminal = „Out: “ outfile
*
* Open files. We open the output file in binary mode to continue lines,
* if necessary:
* (1) SNOBOL4 Version:
*
(
+ ident(system,“Linux“)
+ ,
+ ident(system,“Snobol4+“)
+ )
+ :f(test_linux)
* open input file:
input(.in,1, ,infile) :f(nofile)
* open output file:
output(.out,2, ,outfile) :s(program_start)f(nofile)
*
* (2) SPITBOL Version:
*
test_linux
+ ident(system,“Spitbol“) :f(system_error)
setexit(continue)
&errlimit = 2
input(.in,1,infile „[-l1000]“) :f(nofile)
output(.out,2,outfile „[-l1000]“) :f(nofile)
&errlimit = 0
setexit() :(program_start)
program_start
*
again line = in :f(done)
number =
pad =
(
+ ident(line)
+ ,
+ ?(line ? emptypat)
+ ) :s(again)
line pos(0) span(numbers) . number
+ (
+ char(9)
+ |
+ span(char(32))
+ ) . pad
+ = :f(kill_number)
*
*
* We determine, if line counter:
*
*
count(number,5)
+ (
+ ident(pad,char(9))
+ ,
+ ident(size(pad),8 – size(number))
+ ) :s(kill_number)
line = line number pad
kill_number
+ line = dot_replace(line)
line = html_code(line)
line = repl(line,“[[„,“[4″)
line = repl(line,“]]“,“]4″)
line = repl(line,“<„,“[2″)
line = repl(line,“>“,“]2″)
line = repl(line,“[chirho“,“#322″)
line = replace(line,lcase,ucase)
out = line :(again)
system_error
+ terminal = „*** Unknown SNOBOL4 system – aborted ***“
+ :(end)
done terminal = „Finished converting file“ :(end)
nofile
+ terminal = „Usage: DUKE infile outfile“ :(end)
end

HSU

Letzte Änderung: 21. März 2018