Skip to main content

getsparam

Function getsparam 

Source
pub fn getsparam(name: &str) -> Option<String>
Expand description

Port of getsparam(char *s) from Src/params.c:3076.

C body:

char *getsparam(char *s) {
    struct value vbuf;
    Value v = getvalue(&vbuf, &s, 0);
    if (!v) return NULL;
    return getstrvalue(v);
}

getvalue (params.c:2173) builds a Value for the parameter, dispatching through Param.gsu->getfn for special parameters. getstrvalue (params.c:2335) extracts the scalar form: for PM_INTEGER calls pm->gsu.i->getfn(pm) and convbase’s the result; for PM_SCALAR calls pm->gsu.s->getfn(pm); for PM_ARRAY joins the elements.

Sole funnel. Every scalar parameter read in zshrs routes through this fn — subst.rs parameter expansion AND fusevm_bridge::expand_param both call getsparam. The dispatch chain lives in exactly one place, mirroring C’s “every read goes through getsparam” architecture.

Lookup order (mirrors C’s getvaluegetstrvalue cascade):

  1. GSU dispatch via lookup_special_var — special parameters route through their getfn callback (uidgetfn / randomgetfn / usernamegetfn / etc.). Same role as C’s Param.gsu->getfn virtual dispatch.
  2. Local variablevariables[name]. C reads pm->u.str for PM_SCALAR; here we hold the scalar in the variables HashMap.
  3. Environment fallbackstd::env::var(name). C imports env vars into the param table at startup so they go through the same dispatch as everything else; zshrs reads from the OS env on miss to match.
  4. Array → scalararrays[name].join(" "). Mirrors C’s PM_ARRAY case in getstrvalue (params.c:2358) which joins via sepjoin(ss, NULL, 1).

Returns None only if all four paths miss (parameter genuinely unset).