/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 1990-2011 AT&T Intellectual Property *4* and is licensed under the *5* Eclipse Public License, Version 1.0 *6* by AT&T Intellectual Property *7* *8* A copy of the License is available at *9* http://www.eclipse.org/org/documents/epl-v10.html *10* (with md5 checksum b35adb5213ca9657e911e9befb180842) *11* *12* Information and Software Systems Research *13* AT&T Research *14* Florham Park NJ *15* *16* Glenn Fowler <[email protected]> *17* *18***********************************************************************/19#pragma prototyped20/*21* Glenn Fowler22* at&t Research23*24* coshell export var set/unset25*/2627#include "colib.h"2829/*30* set or unset coshell export variable31*/3233int34coexport(Coshell_t* co, const char* name, const char* value)35{36Coexport_t* ex;37char* v;3839if (!co->export)40{41if (!(co->exdisc = vmnewof(co->vm, 0, Dtdisc_t, 1, 0)))42return -1;43co->exdisc->link = offsetof(Coexport_t, link);44co->exdisc->key = offsetof(Coexport_t, name);45co->exdisc->size = 0;46if (!(co->export = dtnew(co->vm, co->exdisc, Dtset)))47{48vmfree(co->vm, co->exdisc);49return -1;50}51}52if (!(ex = (Coexport_t*)dtmatch(co->export, name)))53{54if (!value)55return 0;56if (!(ex = vmnewof(co->vm, 0, Coexport_t, 1, strlen(name))))57return -1;58strcpy(ex->name, name);59dtinsert(co->export, ex);60}61if (ex->value)62{63vmfree(co->vm, ex->value);64ex->value = 0;65}66if (value)67{68if (!(v = vmstrdup(co->vm, value)))69return -1;70ex->value = v;71}72else73{74dtdelete(co->export, ex);75vmfree(co->vm, ex);76}77co->init.sync = 1;78return 0;79}808182