From: Steven B. <ste...@di...> - 2005-04-25 23:00:13
|
Hello, I spotted a bug and a missed a memory leak in my patch to main.c, so please use this new patch for main.c instead, along with the other patches from my last e-mail. Regards, Steven On 25 Apr 2005, at 22:29, Steven Borley wrote: > Hello, > > I have spotted a problem with the loading of the spice and nutmeg > initialisation file on cygwin. > > In main.c there is some logic to select the the initialisation file. > I believe it goes like this... > > For systems that support getpwuid(): > Load the standard start up file 'spinit' > Then look for '.spiceinit' in the current directory > If not found look for '.spiceinit' in the users home directory > > For systems that do not support getpwuid(): > Load the standard start up file 'spinit' > Then look for 'spice.rc' in the current directory > > The problem with this is that (at least for Cygwin) getpwuid() uses > the /etc/passwd file to determine the users home directory, and for > many Cygwin users this is not set in the /etc/passwd file. > > The attached patch fixes this, but also subtly changes the logic in a > way that I think will be beneficial to others. > > The new logic is as follows: > > For all systems; > Load the standard start up file 'spinit' > Then look for '.spiceinit' in current directory > If this fails look for 'spice.rc' in currect directory > if this fails the check the HOME environment variable > if HOME is set then: > Look for for '.spiceinit' in user's home directory > If this fails look for 'spice.rc' in user's home directory > > The advantage of this is that getpwuid() is not used and getenv() is > used to obtain the user's home directory. I think this is safer and > more portable (I see getenv("HOME") being used elsewhere in ngspice > without issue). > > The second advantage is that spice.rc becomes usable on all systems as > an alternative to .spiceinit, thus there is more consistency between > platforms. > > A possible disadvantage of this is that a .spiceinit file in will > override a spice.rc file and this could be confusing to the user given > that dot files are often invisible on many platforms. I chose not to > give higher priority to the spice.rc file so as to respect the > historic initialisation method, but this is one area I feel unsure > about. It would be easy to modify the new code to reverse or modify > this priority. > > To implement this change I have added a new static function to main.c > called read_initialisation_file() - this is where most of the lower > level work is done, and is where I tried to put all the platform > dependent conditional macros. The logic (as outline above) is not in > this function, but in the body of main() where the original code was. > Hopefully this make the code a little more readable (and hence > maintainable). > > This new code also fixes one small memory leak caused by the use of > asprintf(). > > The header include/defines.h now contains macros for the names of the > initialisation files > and frontend/inp.c and frontend/nutinp.c have been updated to match. > > The remaining changes in main.c and some other files do some simple > tidying and removing of compile warnings. > > Regards, > Steven > > <main.c-diff-2005-04-25-22-14-38.patch><include-diff-2005-04-25-22-16 > -19.patch><frontend-diff-2005-04-25-22-17-03.patch> |