Skip to content

Commit

Permalink
updates for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
TeamSPoon committed Dec 28, 2024
1 parent f22b6b9 commit 5e45ace
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion prolog/metta_lang/metta_interp.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions prolog/metta_lang/metta_loader.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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, !.
Expand Down
14 changes: 14 additions & 0 deletions prolog/metta_lang/metta_parser.pl
Original file line number Diff line number Diff line change
Expand Up @@ -551,13 +551,27 @@
% 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
close(Out), % Close the stream
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.
%
Expand Down

0 comments on commit 5e45ace

Please sign in to comment.