diff --git a/microemacs/mesingle/meuser/mesingle.emf b/microemacs/mesingle/meuser/mesingle.emf index 996bc5a4..bcca7e35 100644 --- a/microemacs/mesingle/meuser/mesingle.emf +++ b/microemacs/mesingle/meuser/mesingle.emf @@ -10,9 +10,9 @@ ; Notes: If it exists add .about.userpath first to search path so user can copy new & override files into directory ; .about.userpath will have a trailing '/' if the path exists, otherwise it wont ; -!if &set .about.hasssn &seq "D" &stat t &set .about.userpath &stat a &stat a &cat &con &seq $platform "windows" $APPDATA "~/.config" "/jasspa" - set-variable $search-path &spr "%s%s%smacros%s%sspelling%s%s" .about.userpath &set #l0 &con &band $system 0x200 ";" ":" .about.userpath #l0 .about.userpath #l0 $search-path - !iif &set .about.hasssn &seq "R" &stat t &spr "%s%s.emf" .about.userpath $user-name set-variable $user-path .about.userpath +!if &set .about.hasssn &seq "D" &stat t &set .about.userpath &cat &set #l0 &stat a &spr "file:%s/jasspa/" &con &seq $platform "windows" $APPDATA "~/.config" &cat $user-name "/" + set-variable $search-path &spr "%s%s%smacros%s%sspelling%s%s" &set $user-path .about.userpath &set #l1 &con &band $system 0x200 ";" ":" #l0 #l1 #l0 #l1 $search-path + set-variable .about.hasssn &seq "R" &stat t &spr "%s%s.emf" $user-path $user-name !endif execute-file "me" !iif .about.hasssn !return diff --git a/microemacs/src/eextrn.h b/microemacs/src/eextrn.h index e7b773eb..ad06ae28 100755 --- a/microemacs/src/eextrn.h +++ b/microemacs/src/eextrn.h @@ -336,8 +336,8 @@ extern int fnamecmp(meUByte *f1, meUByte *f2); #define gfsERRON_BAD_FILE 2 #define gfsERRON_DIR 4 extern int getFileStats(meUByte *file, int flag, meStat *stats, meUByte *lname); -extern int mePathAddSearchPath(int index, meUByte *path_name, - meUByte *path_base, int isUsrArea, int *gotUserPath); +extern int mePathAddSearchPath(int index, meUByte *path_name, meUByte *path_base, + int isUsrArea, int *gotPaths); #define meFL_CHECKDOT 0x01 #define meFL_USESRCHPATH 0x02 #define meFL_USEPATH 0x04 diff --git a/microemacs/src/file.c b/microemacs/src/file.c index caac2b8d..ec259396 100755 --- a/microemacs/src/file.c +++ b/microemacs/src/file.c @@ -517,27 +517,28 @@ fnamecmp(meUByte *f1, meUByte *f2) #endif } -/* Search the directory and subdirectories for MicroEmacs macro directories - flags - * 0x01 Add the given base path - * 0x02 Add / - * 0x04 Add / - * 0x08 Is program name so check for <...>/bin/ or <...>/bin// and if found check for <...>/macros etc +/* Search the directory and subdirectories for MicroEmacs macro directories, don't get 2 of any path type + * + * Flags: + * 0x01 Add the given base path + * 0x02 Add / + * 0x04 Add / + * 0x08 Is program name so check for <...>/bin/ or <...>/bin// and if found check for <...>/macros etc * - * Old: 1 (add base as user path removed), 2 -> 8 + * gotPaths: 0x01 Spelling, 0x02 Macros, 0x04 Company, 0x08 User-path */ int -mePathAddSearchPath(int index, meUByte *path_name, meUByte *path_base, int flags, int *gotUserPath) +mePathAddSearchPath(int index, meUByte *path_name, meUByte *path_base, int flags, int *gotPathsP) { /* Common sub-directories of JASSPAs MicroEmacs */ static meUByte *subdirs[] = { - (meUByte *) "company", /* Company wide files */ - (meUByte *) "macros", /* Standard distribution macros */ (meUByte *) "spelling", /* Spelling dictionaries */ - NULL + (meUByte *) "macros", /* Standard distribution macros */ + (meUByte *) "company", /* Company wide files */ } ; meUByte cc, *ss, base_name[meBUF_SIZE_MAX]; - int ii, jj, ll; + int ii, jj, ll, mm, gotPaths=*gotPathsP; /* Iterate over all of the paths */ while(*path_base != '\0') @@ -560,7 +561,8 @@ mePathAddSearchPath(int index, meUByte *path_name, meUByte *path_base, int flags if(getFileStats(base_name,0,NULL,NULL) & meIOTYPE_DIRECTORY) { /* If this is the program path, in a /bin/ or /bin/sub-dir/ and /macros exists then add / to the search path */ - if((flags & 8) && (ll > 4) && (!memcmp((ss=base_name+ll-4),"/bin",4) || (((ss=meStrrchr(base_name+4,DIR_CHAR)) != NULL) && !memcmp((ss-=4),"/bin",4)))) + if((flags & 8) && ((gotPaths & 0x0f) != 0x0f) && (ll > 4) && + (!memcmp((ss=base_name+ll-4),"/bin",4) || (((ss=meStrrchr(base_name+4,DIR_CHAR)) != NULL) && !memcmp((ss-=4),"/bin",4)))) { meUByte sp[256]; meStrcpy(sp,++ss); @@ -568,60 +570,57 @@ mePathAddSearchPath(int index, meUByte *path_name, meUByte *path_base, int flags if(!meTestDir(base_name)) { *ss = '\0'; - index = mePathAddSearchPath(index,path_name,base_name,6,gotUserPath); + index = mePathAddSearchPath(index,path_name,base_name,6,&gotPaths); } meStrcpy(ss,sp); } base_name[ll++] = DIR_CHAR; /* check for base_name/$user-name first */ - if((flags & 2) && (meUserName != NULL)) + if((flags & 2) && !(gotPaths & 8) && (meUserName != NULL)) { meStrcpy(base_name+ll,meUserName); if(getFileStats(base_name,0,NULL,NULL) & meIOTYPE_DIRECTORY) { - /* it exists, add it to the front if we haven't got a user - * path yet or to the end otherwise */ + /* it exists, add it to the front as we haven't got a user path yet */ + gotPaths |= 8; jj = ll + meStrlen(meUserName); - if(*gotUserPath == 0) - { - *gotUserPath = 1; - if(index) - { - base_name[jj++] = mePATH_CHAR; - memcpy(base_name+jj,path_name,index); - } - memcpy(path_name,base_name,jj+index); - } - else + if(index) { - if(index) - path_name[index++] = mePATH_CHAR; - memcpy(path_name+index,base_name,jj); + base_name[jj++] = mePATH_CHAR; + memcpy(base_name+jj,path_name,index); } + memcpy(path_name,base_name,jj+index); index += jj; } } - if(flags & 4) + if((flags & 4) && ((gotPaths & 0x07) != 0x07)) { /* Append the search paths if necessary. We construct the standard JASSPA MicroEmacs * paths and then test for the existance of the directory. If the directory exists then * we add it to the search path. We do not add any directories to the search path that * do not exist. */ - for(ii=0 ; (ss=subdirs[ii]) != NULL ; ii++) - { - meStrcpy(base_name+ll,ss); - /* Test the directory for existance, if it does not exist then do not add it as we - * do not want to search any directory unecessarily. */ - if(getFileStats(base_name,0,NULL,NULL) & meIOTYPE_DIRECTORY) + ii = 2; + mm = 4; + do { + if(!(gotPaths & mm)) { - /* it exists, add it */ - if(index) - path_name[index++] = mePATH_CHAR; - jj = ll + meStrlen(ss); - memcpy(path_name+index,base_name,jj); - index += jj; + jj = meStrlen(subdirs[ii]); + memcpy(base_name+ll,subdirs[ii],jj+1); + /* Test the directory for existance, if it does not exist then do not add it as we + * do not want to search any directory unecessarily. */ + if(getFileStats(base_name,0,NULL,NULL) & meIOTYPE_DIRECTORY) + { + /* it exists, add it */ + gotPaths |= mm; + if(index) + path_name[index++] = mePATH_CHAR; + jj += ll; + memcpy(path_name+index,base_name,jj); + index += jj; + } } - } + mm >>= 1; + } while(--ii >= 0); } if(flags & 1) { @@ -633,6 +632,7 @@ mePathAddSearchPath(int index, meUByte *path_name, meUByte *path_base, int flags } } } + *gotPathsP = gotPaths; path_name[index] = '\0'; return index; } diff --git a/microemacs/src/unixterm.c b/microemacs/src/unixterm.c index 868ebe01..040ae112 100755 --- a/microemacs/src/unixterm.c +++ b/microemacs/src/unixterm.c @@ -554,7 +554,7 @@ meSetupPathsAndUser(void) static meUByte lpath[] = _SEARCH_PATH; struct passwd *pwdp; /* Password structure entry */ meUByte *ss, buff[meBUF_SIZE_MAX]; - int ii, ll, gotUserPath; + int ii, ll; if((meUserName == NULL) && ((ss = meGetenv ("MENAME")) != NULL) && (ss[0] != '\0')) @@ -614,9 +614,9 @@ meSetupPathsAndUser(void) } else { - /* construct the search-path */ - /* put the $user-path first */ - if((gotUserPath = (meUserPath != NULL))) + /* construct the search-path, put the $user-path first */ + int gotPaths = (meUserPath != NULL) ? 8:0; + if(gotPaths) { meStrcpy(evalResult,meUserPath); ll = meStrlen(evalResult); @@ -631,15 +631,17 @@ meSetupPathsAndUser(void) (((ss = lpath) != NULL) && (ss[0] != '\0'))) { meStrcpy(buff,ss); - ll = mePathAddSearchPath(ll,evalResult,buff,6,&gotUserPath); + ll = mePathAddSearchPath(ll,evalResult,buff,6,&gotPaths); } - else if(homedir != NULL) + if((homedir != NULL) && (gotPaths != 0x0f)) { - /* look for the ~/.config/jasspa directory */ + /* look for the user's area in ~/.config/jasspa directory - an exception here, if we find macros or spelling here + * still look for it in the program area as this may just contain downloaded help and spelling packages */ + ii = gotPaths; meStrcpy(buff,homedir); meStrcat(buff,".config/jasspa"); - /* as this is the user's area, use this directory as user path (with or without .../<$user-name>/ sub-directory */ - ll = mePathAddSearchPath(ll,evalResult,buff,6,&gotUserPath); + ll = mePathAddSearchPath(ll,evalResult,buff,6,&ii); + gotPaths |= (ii & 0x0c); } /* also check for directories in the same location as the binary */ @@ -648,14 +650,14 @@ meSetupPathsAndUser(void) ii = (((size_t) ss) - ((size_t) meProgName)); meStrncpy(buff,meProgName,ii); buff[ii] = '\0'; - ll = mePathAddSearchPath(ll,evalResult,buff,9,&gotUserPath); + ll = mePathAddSearchPath(ll,evalResult,buff,9,&gotPaths); } #if MEOPT_TFS /* also check for the built-in file system */ - if(tfsdev != NULL) - ll = mePathAddSearchPath(ll,evalResult,(meUByte *) "tfs://",1,&gotUserPath); + if((tfsdev != NULL) && (gotPaths != 0x0f)) + ll = mePathAddSearchPath(ll,evalResult,(meUByte *) "tfs://",1,&gotPaths); #endif - if(!gotUserPath && (homedir != NULL)) + if(!(gotPaths & 8) && (homedir != NULL)) { /* We have not found a user path so set ~/ as the user-path * as this is the best place for macros to write to etc. */ @@ -680,7 +682,7 @@ meSetupPathsAndUser(void) ss = searchPath; #if MEOPT_TFS #if mePATH_CHAR == ':' - /* Special case: if the path starts with tfs: the assume its a tfs path rather than just 'tfs' */ + /* Special case: if the path starts with tfs: then assume its a tfs path rather than just 'tfs' */ /* This is not a good path for the user-path, but this is likely to be a mesingle exe with no session so no files should be written */ if((ss[0] == 't') && (ss[1] == 'f') && (ss[2] == 's') && (ss[3] == ':')) ss += 4; diff --git a/microemacs/src/winterm.c b/microemacs/src/winterm.c index 952b0530..ff793e73 100755 --- a/microemacs/src/winterm.c +++ b/microemacs/src/winterm.c @@ -5506,7 +5506,7 @@ void meSetupPathsAndUser(void) { char *ss, *appData, buff[meBUF_SIZE_MAX], appDataBuff[meBUF_SIZE_MAX]; - int ii, ll, gotUserPath; + int ii, ll; #if (defined CSIDL_APPDATA) LPITEMIDLIST idList; #endif @@ -5570,9 +5570,9 @@ meSetupPathsAndUser(void) } else { - /* construct the search-path */ - /* put the $user-path first */ - if((gotUserPath = (meUserPath != NULL))) + /* construct the search-path, put the $user-path first */ + int gotPaths = (meUserPath != NULL) ? 8:0; + if(gotPaths) { meStrcpy(evalResult,meUserPath); ll = meStrlen(evalResult); @@ -5586,15 +5586,17 @@ meSetupPathsAndUser(void) if(((ss = meGetenv("MEINSTALLPATH")) != NULL) && (ss[0] != '\0')) { strcpy(buff,ss); - ll = mePathAddSearchPath(ll,evalResult,(meUByte *) buff,6,&gotUserPath); + ll = mePathAddSearchPath(ll,evalResult,(meUByte *) buff,6,&gotPaths); } - else if(appData != NULL) + if((appData != NULL) && (gotPaths != 0x0f)) { - /* look for the $APPDATA/jasspa directory */ + /* look for the user's area in $APPDATA/jasspa directory - an exception here, if we find macros or spelling here + * still look for it in the program area as this may just contain downloaded help and spelling packages */ + ii = gotPaths; strcpy(buff,appData); strcat(buff,"/jasspa"); - /* as this is the user's area, use this directory as user path (with or without .../<$user-name>/ sub-directory */ - ll = mePathAddSearchPath(ll,evalResult,(meUByte *) buff,6,&gotUserPath); + ll = mePathAddSearchPath(ll,evalResult,(meUByte *) buff,6,&ii); + gotPaths |= (ii & 0x0c); } /* also check for directories in the same location as the binary */ @@ -5603,14 +5605,14 @@ meSetupPathsAndUser(void) ii = (((size_t) ss) - ((size_t) meProgName)); meStrncpy(buff,meProgName,ii); buff[ii] = '\0'; - ll = mePathAddSearchPath(ll,evalResult,(meUByte *) buff,9,&gotUserPath); + ll = mePathAddSearchPath(ll,evalResult,(meUByte *) buff,9,&gotPaths); } #if MEOPT_TFS /* also check for the built-in file system */ - if(tfsdev != NULL) - ll = mePathAddSearchPath(ll,evalResult,(meUByte *) "tfs://",1,&gotUserPath); + if((tfsdev != NULL) && (gotPaths != 0x0f)) + ll = mePathAddSearchPath(ll,evalResult,(meUByte *) "tfs://",1,&gotPaths); #endif - if(!gotUserPath && (appData != NULL)) + if(!(gotPaths & 8) && (appData != NULL)) { /* We have not found a user path so add the $APPDATA as the user-path * as this is the best place for macros to write to etc. */