OK, not that different from previous version, but a bit cleaner.
May I commit?

- Qian

--- a/src/interp/util.lisp
+++ b/src/interp/util.lisp
@@ -107,8 +107,17 @@
 ;;; Sets up the system to use the {\bf FRICAS} shell variable if we can
 ;;; and default to the {\bf \$spadroot} variable (which was the value
 ;;; of the {\bf FRICAS} shell variable at build time) if we can't.
+;;; Use the parent directory of FRICASsys binary as fallback.
 (defun initroot (&optional (newroot nil))
-  (reroot (or (|getEnv| "FRICAS") newroot $spadroot
+  (reroot (or (|getEnv| "FRICAS") newroot
+              (if (|fricas_probe_file| $spadroot) $spadroot)
+              (let ((bin-parent-dir
+                     (concatenate 'string
+ (directory-namestring (car (|getCLArgs|)))
+                                  "/../")))
+ (if (|fricas_probe_file| (concatenate 'string bin-parent-dir + "algebra/interp.daase"))
+                    bin-parent-dir))
               (error "setenv FRICAS or (setq $spadroot)"))))

 ;;; Gnu Common Lisp (GCL) (at least 2.6.[78]) requires some changes

On 3/18/21 9:51 AM, Waldek Hebisch wrote:
On Wed, Mar 17, 2021 at 10:45:52PM +0800, Qian Yun wrote:


On 3/17/21 10:15 PM, Waldek Hebisch wrote:
On Tue, Mar 16, 2021 at 08:55:02PM +0800, Qian Yun wrote:
The patch is here, discussions are welcome.  If my idea is accepted,
I can refine the patch a bit more.

It uses "argv[0]" to determine the path of "FRICASsys" binary,
not very reliable, but portable.

So the logic is to use env var "FRICAS" first if it exists,
then use "newroot" if it is passed as function argument,
then use "$spadroot" which is build time value, use if it still exists,
then use the parent directory of "FRICASsys", if it contains
"algebra/compress.daase".

In general that is very reasonable.  I would probably look
at "algebra/interp.daase" as it is more fundamental.  I am
not sure if we always have "argv[0]" (more precisely, if
setting argv[0] to null is merely perverse or illegal).

OK, I'll try to generate a proper patch utilizing this idea.
argv[0] can be modified, that is unfortunate, but it is most
portable, because it is from C, unlike "$0" from shell.
Anyway, I'll check existence of "algebra/interp.daase" before use,
for both "$FRICAS", "$spadroot", and "argv[0]".

IMO, if FRICAS variable is set we should respect it, that is
do not try any fallback.


--
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/fricas-devel/b870b913-bd90-039d-f0f8-92015a7d8b68%40gmail.com.

Reply via email to