From 5e45ace891d7faa7e488f22d844914287cb6f0b2 Mon Sep 17 00:00:00 2001 From: logicmoo Date: Fri, 27 Dec 2024 17:05:10 -0800 Subject: [PATCH] updates for windows --- prolog/metta_lang/metta_interp.pl | 3 ++- prolog/metta_lang/metta_loader.pl | 2 ++ prolog/metta_lang/metta_parser.pl | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/prolog/metta_lang/metta_interp.pl b/prolog/metta_lang/metta_interp.pl index 43471b63286..cc08e6ec319 100755 --- a/prolog/metta_lang/metta_interp.pl +++ b/prolog/metta_lang/metta_interp.pl @@ -891,7 +891,7 @@ len_or_unbound(ParamTypes,PrologArity). add_prolog_code(_KB,AssertZIfNew):- - fbug(writeln(AssertZIfNew)), + %fbug(assertz_if_new(AssertZIfNew)), assertz_if_new(AssertZIfNew). gen_interp_stubs(KB,Symb,Def):- ignore((is_list(Def), @@ -2121,6 +2121,7 @@ :- abolish(fbug/1). fbug(_):- is_compatio,!. +fbug(_):- \+ option_value('log','true'),!. fbug(Info):- real_notrace(in_cmt(color_g_mesg('#2f2f2f',write_src(Info)))). example0(_):- fail. example1(a). example1(_):- fail. diff --git a/prolog/metta_lang/metta_loader.pl b/prolog/metta_lang/metta_loader.pl index 60d7d5395ea..893235a848b 100755 --- a/prolog/metta_lang/metta_loader.pl +++ b/prolog/metta_lang/metta_loader.pl @@ -3640,6 +3640,8 @@ % This predicate checks if stubs have already been generated, and if not, it iterates over % symbols defined in the core library to create interpreter stubs for each. % + +%generate_interpreter_stubs :- !. %currently disabled generate_interpreter_stubs :- % Avoid generating stubs multiple times. did_generate_interpreter_stubs, !. diff --git a/prolog/metta_lang/metta_parser.pl b/prolog/metta_lang/metta_parser.pl index 2dae77f8111..9a46b1a1763 100644 --- a/prolog/metta_lang/metta_parser.pl +++ b/prolog/metta_lang/metta_parser.pl @@ -551,6 +551,14 @@ % Uses the Bash `wc -l` command to count the number of lines in the specified file. % @arg FileName The name of the file to count lines in. % @arg LineCount The number of lines in the file. + +% First clause: Windows (using a manual line-counting approach). +count_lines_in_file(FileName, LineCount) :- is_win64, !, % Succeeds if we're on 64-bit Windows + open(FileName, read, Stream), + read_count_lines(Stream, 0, LineCount), + close(Stream). + +% Second clause: Unix-like systems (using 'wc -l'). count_lines_in_file(FileName, LineCount) :- process_create(path(wc), ['-l', FileName], [stdout(pipe(Out))]), read_line_to_string(Out, Result), % Read the output from the `wc -l` command @@ -558,6 +566,12 @@ split_string(Result, " ", "", [LineStr|_]), % Extract the line count number_string(LineCount, LineStr). % Convert the string to an integer +% Helper predicate to read lines from a stream until EOF, incrementing a counter. +read_count_lines(Stream, FinalCount, FinalCount) :- at_end_of_stream(Stream), !. % Stop if we've hit the end of the file +read_count_lines(Stream, CurrentCount, FinalCount) :- + read_line_to_codes(Stream, _), % Read one line (ignore its content here) + NextCount is CurrentCount + 1, + read_count_lines(Stream, NextCount, FinalCount). %! report_file_progress(+FileName:atom, +InStream:stream, +TotalLines:int, +StartTime:float) is det. %