Prolog "plain"

Admin User, created Jan 13. 2024
         
/**
* Warranty & Liability
* To the extent permitted by applicable law and unless explicitly
* otherwise agreed upon, XLOG Technologies AG makes no warranties
* regarding the provided information. XLOG Technologies AG assumes
* no liability that any problems might be solved with the information
* provided by XLOG Technologies AG.
*
* Rights & License
* All industrial property rights regarding the information - copyright
* and patent rights in particular - are the sole property of XLOG
* Technologies AG. If the company was not the originator of some
* excerpts, XLOG Technologies AG has at least obtained the right to
* reproduce, change and translate the information.
*
* Reproduction is restricted to the whole unaltered document. Reproduction
* of the information is only allowed for non-commercial uses. Selling,
* giving away or letting of the execution of the library is prohibited.
* The library can be distributed as part of your applications and libraries
* for execution provided this comment remains unchanged.
*
* Restrictions
* Only to be distributed with programs that add significant and primary
* functionality to the library. Not to be distributed with additional
* software intended to replace any components of the library.
*
* Trademarks
* Jekejeke is a registered trademark of XLOG Technologies AG.
*/
:- ensure_loaded(library(tester/beautify)).
:- ensure_loaded(library(misc/markup)).
/*************************************************************/
/* Colorize Utility Plain */
/*************************************************************/
/**
* colorizep_file(A, B):
* The predicate succeeds. As side effect it colorizes the Plain
* text A into the file B. An already existing file B is silently
* overwritten.
*/
% colorizep_file(+Atom, +Atom)
colorizep_file(InName, OutName) :-
colorizep_file(InName, OutName, []).
% colorizep_file(+Atom, +Atom, +List)
colorizep_file(InName, OutName, Opts) :-
sys_fancy_opts(Opts, Res),
setup_once_cleanup(
(open(OutName, write, OutStream), dom_output_new(OutStream, DomWriter)),
sys_colorizep_dest(InName, DomWriter, Res),
close(DomWriter)).
% sys_colorizep_dest(+Atom, +Stream, +Term)
sys_colorizep_dest(InName, OutStream, Res) :-
sys_html_header(OutStream, Res),
sys_fancy_begin(OutStream),
setup_once_cleanup(
open(InName, read, InStream),
sys_colorizep_stream(InStream, OutStream),
close(InStream)),
sys_fancy_end(OutStream),
sys_html_footer(OutStream).
% sys_colorizep_stream(+Stream, +Stream)
sys_colorizep_stream(InStream, S) :-
get_atom(InStream, 0'\n, Line),
sys_colorizep_more(Line, InStream, S).
% sys_colorizep_more(+Atom, +Stream, +Stream)
sys_colorizep_more('', _, _) :- !.
sys_colorizep_more(Line, InStream, S) :-
sys_colorizep_line(Line, S),
get_atom(InStream, 0'\n, Line2),
sys_colorizep_rest(Line2, InStream, S).
% sys_colorizep_rest(+Atom, +Stream, +Stream)
sys_colorizep_rest('', _, _) :- !.
sys_colorizep_rest(Line, InStream, S) :-
tag(S, '</div>'),
tag(S, '<div class="ln">'),
sys_colorizep_line(Line, S),
get_atom(InStream, 0'\n, Line2),
sys_colorizep_rest(Line2, InStream, S).
/*************************************************************/
/* Colorize Helper Plain */
/*************************************************************/
% sys_colorizep_line(+Atom, +Stream)
sys_colorizep_line(Line, S) :-
sub_atom(Line, 0, _, 1, Line3),
put_atom(S, Line3).