Skip to content
Snippets Groups Projects
Commit c0370d3c authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Allow JS 'user.editor' and '.shell' to be set for non-users (e.g. user #0)

The request from Nightfox and Accession via DOVE-Net was to be able to set
a user's external editor even if there's no user logged-in.

These 2 user class properties in the JS object model were a bit special in
that they *only* wrote to the user database and did not immediately modify
the in-memory copy of the user_t structure, depending on the re-reading of
the user.dat/tab file to re-populate the current user_t structure when needed.
This didn't work if the current user is user #0 (no user).

So, set the current user_t.xedit and user_t.shell accordingly whenever those
JS properties are assigned a value (a string, the appropriate internal code).
parent feb69e18
No related branches found
No related tags found
No related merge requests found
...@@ -574,9 +574,11 @@ static JSBool js_user_set(JSContext *cx, JSObject *obj, jsid id, JSBool strict, ...@@ -574,9 +574,11 @@ static JSBool js_user_set(JSContext *cx, JSObject *obj, jsid id, JSBool strict,
putuserstr(scfg, p->user->number, USER_CURXTRN, str); putuserstr(scfg, p->user->number, USER_CURXTRN, str);
break; break;
case USER_PROP_XEDIT: case USER_PROP_XEDIT:
p->user->xedit = getxeditnum(scfg, str);
putuserstr(scfg, p->user->number, USER_XEDIT, str); putuserstr(scfg, p->user->number, USER_XEDIT, str);
break; break;
case USER_PROP_SHELL: case USER_PROP_SHELL:
p->user->shell = getshellnum(scfg, str);
putuserstr(scfg, p->user->number, USER_SHELL, str); putuserstr(scfg, p->user->number, USER_SHELL, str);
break; break;
case USER_PROP_MISC: case USER_PROP_MISC:
......
...@@ -63,6 +63,8 @@ int getgrpnum_from_name(scfg_t*, const char* name); ...@@ -63,6 +63,8 @@ int getgrpnum_from_name(scfg_t*, const char* name);
int getxtrnsec(scfg_t*, const char* code); int getxtrnsec(scfg_t*, const char* code);
int getgurunum(scfg_t*, const char* code); int getgurunum(scfg_t*, const char* code);
int getchatactset(scfg_t*, const char* name); int getchatactset(scfg_t*, const char* name);
int getxeditnum(scfg_t*, const char* code);
int getshellnum(scfg_t*, const char* code);
DLLEXPORT BOOL is_valid_dirnum(scfg_t*, int); DLLEXPORT BOOL is_valid_dirnum(scfg_t*, int);
DLLEXPORT BOOL is_valid_libnum(scfg_t*, int); DLLEXPORT BOOL is_valid_libnum(scfg_t*, int);
......
...@@ -791,6 +791,30 @@ int getchatactset(scfg_t* cfg, const char* name) ...@@ -791,6 +791,30 @@ int getchatactset(scfg_t* cfg, const char* name)
return i; return i;
} }
// Returns 0 (internal editor) or 1-based external editor index
int getxeditnum(scfg_t* cfg, const char* code)
{
int i;
for(i = 0; i < cfg->total_xedits; ++i) {
if(stricmp(cfg->xedit[i]->code, code) == 0)
return i + 1;
}
return 0;
}
// Returns 0 (first shell) if shell code isn't valid
int getshellnum(scfg_t* cfg, const char* code)
{
int i;
for(i = 0; i < cfg->total_shells; ++i) {
if(stricmp(cfg->shell[i]->code, code) == 0)
return i;
}
return 0;
}
BOOL is_valid_dirnum(scfg_t* cfg, int dirnum) BOOL is_valid_dirnum(scfg_t* cfg, int dirnum)
{ {
return (dirnum >= 0) && (cfg != NULL) && (dirnum < cfg->total_dirs); return (dirnum >= 0) && (cfg != NULL) && (dirnum < cfg->total_dirs);
......
...@@ -419,18 +419,8 @@ int parseuserdat(scfg_t* cfg, char *userdat, user_t *user, char* field[]) ...@@ -419,18 +419,8 @@ int parseuserdat(scfg_t* cfg, char *userdat, user_t *user, char* field[])
user->rows = strtoul(field[USER_ROWS], NULL, 0); user->rows = strtoul(field[USER_ROWS], NULL, 0);
user->cols = strtoul(field[USER_COLS], NULL, 0); user->cols = strtoul(field[USER_COLS], NULL, 0);
for(int i = 0; i < cfg->total_xedits; i++) { user->xedit = getxeditnum(cfg, field[USER_XEDIT]);
if(stricmp(field[USER_XEDIT], cfg->xedit[i]->code) == 0) { user->shell = getshellnum(cfg, field[USER_SHELL]);
user->xedit = i + 1;
break;
}
}
for(int i=0; i < cfg->total_shells; i++) {
if(stricmp(field[USER_SHELL], cfg->shell[i]->code) == 0) {
user->shell = i;
break;
}
}
SAFECOPY(user->tmpext, field[USER_TMPEXT]); SAFECOPY(user->tmpext, field[USER_TMPEXT]);
user->prot = *field[USER_PROT]; user->prot = *field[USER_PROT];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment