wxMaxima-developers / wxmaxima

A gui for the computer algebra system Maxima built with wxWidgets
https://wxMaxima-developers.github.io/wxmaxima/
Other
471 stars 98 forks source link

PWD of the maxima process seems to be no more set #356

Closed gunterkoenigsmann closed 9 years ago

gunterkoenigsmann commented 9 years ago

Both my linux build from the git trunk and the windows builds from https://maxima.sourceforge.net show the same behavior:

When I use maxima's load() command to load a .mac file from the current directory or when i save data using a construct like

stream:openw("Test.txt")$
printf(stream,"Hello World!")$
close(stream)$

the data is no more read from the directory the .wxmx file is in I have opened with wxmaxima. Maxima seems to search in the directory wxmaxima was started in instead.

In earlier days the maxima process was started in the directory the .wxmx file was opened from which made maxima read data from here. Interestingly the C code of wxMaxima still contains the following command that should set maxima's pwd:

SendMaxima(wxT(":lisp-quiet (xchdir (tofiledir \"") + filename.GetFullPath() + wxT("\"))"));

How do I debug the communication between maxima an wxMaxima? Seems like something surreal is happening - and playback() doesn't show what maxima and wxmaxima communicate before the control is passed to the user.

Kind regards,

Gunter.

peterpall commented 9 years ago

Ok: The first step was easy using wireshark: wxMaxima issues an

:lisp-quiet (xchdir(tofiledir "/home/gunter/tmp"))

The command tofiledir is provided by wxmathml.lisp:

(defun tofiledir (file)
  (let ((path (pathname file)))
    (namestring (make-pathname :device (pathname-device path) :directory
(pathname-directory path)))))

When I issue the following line: %i1 :lisp (xchdir (tofiledir "/home/gunter/tex/test.wxmx")) maxima prints out a 0. If I issue %i2 :lisp (truename ".") directly afterwards I get /home/gunter/, not the expected value /home/gunter/tex/. So I suspect the pwd of maxima hasn't changed even if xchdir was issued.

Did ask the maxima Mailing list if any of the Lisp wizards there has any idea why.

gunterkoenigsmann commented 9 years ago

Leo Butler did tell me what is the problem:

Well, I think the issue is this: in unix, a child process doesn't need to know its pwd, that is actually something the parent needs to know. So, you can tell the parent to change the pwd without noticing you did so yourself. It seems xchdir does this. Here is a way to do both:

(defun $cd (dir)
 (let ((dir (cond ((pathnamep dir) dir)
                  ((stringp dir) (make-pathname :directory #+gcl (list dir) #-gcl dir))
                  (t (error "cd(dir): dir must be a string or pathname.")))))
       (and (xchdir dir) (setf *default-pathname-defaults* dir) (namestring dir))))

http://www.lispworks.com/documentation/lw50/CLHS/Body/v_defaul.htm

Will commit a patch in a few minutes.

gunterkoenigsmann commented 9 years ago

Pull rrequest #360 resolves this issue.