[PATCH] fix ")summary" ")copyright" on windows

21 views
Skip to first unread message

Qian Yun

unread,
Dec 8, 2023, 7:59:17 PM12/8/23
to fricas-devel
The code uses "cat" to display text file, which is usually not available
on windows.

Luckily writing a lisp version to display text file is not hard.

- Qian

diff --git a/src/interp/i-syscmd.boot b/src/interp/i-syscmd.boot
index f7a20a2d..cd737039 100644
--- a/src/interp/i-syscmd.boot
+++ b/src/interp/i-syscmd.boot
@@ -704,9 +704,9 @@ withAsharpCmd args ==
--% )copyright -- display copyright notice

summary l ==
- OBEY STRCONC ('"cat ", $spadroot, '"/lib/summary")
+ print_text_file STRCONC($spadroot, '"/lib/summary")
copyright () ==
- OBEY STRCONC ('"cat ", $spadroot, '"/lib/copyright")
+ print_text_file STRCONC($spadroot, '"/lib/copyright")

--% )credits -- display credit list

diff --git a/src/interp/util.lisp b/src/interp/util.lisp
index 400a2b94..29f7e5d1 100644
--- a/src/interp/util.lisp
+++ b/src/interp/util.lisp
@@ -383,3 +383,10 @@ After this function is called the image is clean
and can be saved.
(|setIOindex| (- |$IOindex| 3))
)
)
+
+(defun |print_text_file| (filename)
+ (with-open-file (s filename :direction :input :if-does-not-exist nil)
+ (if s
+ (do ((l (read-line s nil) (read-line s nil)))
+ ((null l) nil)
+ (write-line l)))))

Waldek Hebisch

unread,
Dec 9, 2023, 9:25:27 PM12/9/23
to fricas...@googlegroups.com
On Sat, Dec 09, 2023 at 08:59:13AM +0800, Qian Yun wrote:
> The code uses "cat" to display text file, which is usually not available
> on windows.
>
> Luckily writing a lisp version to display text file is not hard.

Having our own replacement for "cat" is reasonable. However,
why do not you do this in Boot?
> --
> You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to fricas-devel...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/fricas-devel/993b9851-837f-48a8-920f-dbd27e5ef5f8%40gmail.com.

--
Waldek Hebisch

Qian Yun

unread,
Dec 9, 2023, 9:29:05 PM12/9/23
to fricas...@googlegroups.com
"with-open-file" is hard to express in Boot, right?

To use "open" directly, there's risk when IO error happens,
file handler are not properly "close".

- Qian

Waldek Hebisch

unread,
Dec 9, 2023, 9:51:07 PM12/9/23
to fricas...@googlegroups.com
On Sun, Dec 10, 2023 at 10:29:01AM +0800, Qian Yun wrote:
> "with-open-file" is hard to express in Boot, right?
>
> To use "open" directly, there's risk when IO error happens,
> file handler are not properly "close".

We have 'handle_input_file' which is a wrapper around
'with-open-file'. Since there is no macros in Boot,
'handle_input_file' takes a function as an argument.

--
Waldek Hebisch

Qian Yun

unread,
Dec 9, 2023, 10:25:42 PM12/9/23
to fricas...@googlegroups.com
print_text_stream stream ==
if stream then
while (str := read_line stream) repeat
WRITE_-LINE str

print_text_file filename ==
handle_input_file(filename, function print_text_stream, [])

====

Shall we use "WRITE_-LINE" or define "|write_line|" or use
"SAY" or "PRINC"?

And is there a better place to put it other than i-syscmd.boot?

- Qian

Waldek Hebisch

unread,
Dec 10, 2023, 6:52:04 AM12/10/23
to fricas...@googlegroups.com
On Sun, Dec 10, 2023 at 11:25:38AM +0800, Qian Yun wrote:
> print_text_stream stream ==
> if stream then
> while (str := read_line stream) repeat
> WRITE_-LINE str
>
> print_text_file filename ==
> handle_input_file(filename, function print_text_stream, [])
>
> ====
>
> Shall we use "WRITE_-LINE" or define "|write_line|" or use
> "SAY" or "PRINC"?

AFAICS "SAY" will do right thing.
>
> And is there a better place to put it other than i-syscmd.boot?

"i-syscmd.boot" is natural place.

--
Waldek Hebisch
Reply all
Reply to author
Forward
0 new messages