Browse Source

Add ~/.profile.bas to the execute_profile search

Also improved error checking so that a missing $HOME would bypass those
checks. And optimized so it didn't need to hit the environment twice.
tags/v3.20f
Jon Foster 3 years ago
parent
commit
402f974106
1 changed files with 17 additions and 12 deletions
  1. +17
    -12
      bwbasic.c

+ 17
- 12
bwbasic.c View File

@@ -712,25 +712,30 @@ execute_profile (char *FileName)
* script will happen.
*
* 1 to open [profile.bas]
* 2 to open [/home/$USER/profile.bas]
* 3 to open [/etc/profile.bas]
* 2 to open [$HOME/profile.bas]
* 3 to open [$HOME/.profile.bas] - because ChipMaster doesn't like clutter
* 4 to open [/etc/profile.bas]
* */
char pname[1024];
pname[0]=pname[sizeof(pname)-1]=0;
profile = fopen (FileName, "r");
char home[1024]; home[0]=home[sizeof(home)-1]=0;
char pname[1024]; pname[0]=pname[sizeof(pname)-1]=0;
profile = fopen(FileName, "rt");
if(profile == NULL) {
strncpy(pname, getenv("HOME"), sizeof(pname)-1);
if(pname[0]) {
strncat(strcat(pname, "/"), FileName, sizeof(pname)-strlen(pname)-1);
profile = fopen (pname, "r");
strncpy(home, getenv("HOME"), sizeof(home)-1);
if(home[0]) {
snprintf(pname, sizeof(pname)-1, "%s/%s", home, FileName);
profile = fopen (pname, "rt");
}
if(profile == NULL) {
snprintf(pname, sizeof(pname)-1, "%s/.%s", home, FileName);
profile = fopen (pname, "rt");
}
}
if(profile == NULL) {
strncat(strcpy(pname, "/etc/"), FileName, sizeof(pname)-6);
profile = fopen(pname, "r");
snprintf(pname, sizeof(pname)-1, "/etc/%s", FileName);
profile = fopen(pname, "rt");
}
#else
profile = fopen (FileName, "r");
profile = fopen (FileName, "rt");
#endif
/* End 20200806 Patch */



Loading…
Cancel
Save