3 * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
4 * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29 for (env
= env_list
.next
; env
!= &env_list
; env
= env
->next
)
30 printf ("%s=%s\n", env
->name
, env
->value
);
33 env_t
*env_find (char *name
)
39 for (env
= env_list
.next
; env
!= &env_list
; env
= env
->next
) {
40 if (!strcmp (env
->name
, name
))
47 unsigned int env_set (char *name
, char *value
)
49 env_t
*env
= env_find (name
);
54 strcpy (env
->value
, value
);
59 char *env_get (char *name
)
61 env_t
*env
= env_find (name
);
69 unsigned int env_create (char *name
, char *value
)
71 /* first check length of name and value */
72 if (strlen (name
) >= DEFAULT_MAX_NAMELENGTH
||
73 strlen (value
) >= DEFAULT_MAX_VALUELENGTH
)
76 /* env name havent to exists */
77 if (env_find (name
) != 0)
80 /* alloc and init context */
81 env_t
*env
= (env_t
*) kmalloc (sizeof (env_t
));
86 strcpy (env
->name
, name
);
87 strcpy (env
->value
, value
);
90 env
->next
= &env_list
;
91 env
->prev
= env_list
.prev
;
92 env
->prev
->next
= env
;
93 env
->next
->prev
= env
;
95 DPRINT (DBG_CORE
| DBG_ENV
, "env_create () -> %s=%s", name
, value
);
100 /* install all default env */
103 env_create ("PWD", "/");
104 env_create ("HOME", "/");
105 env_create ("USER", "N/A");
106 env_create ("LANGUAGE", "en");
108 /* Keyboard layout */
109 if (keyboard_getlayout ("us"))
110 env_create ("KBD", "us");
111 if (keyboard_getlayout ("cz"))
112 env_create ("KBD", "cz");
115 unsigned int init_env ()
117 env_list
.next
= &env_list
;
118 env_list
.prev
= &env_list
;
120 // set default env values
121 env_list
.name
[0] = '\0';
122 env_list
.value
[0] = '\0';