1 //
2 // aegis - project change supervisor
3 // Copyright (C) 1999, 2003-2008 Peter Miller
4 // Copyright (C) 2007, 2008 Walter Franzini
5 //
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.
10 //
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.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program. If not, see
18 // <http://www.gnu.org/licenses/>.
19 //
20
21 #include <common/ac/stdio.h>
22 #include <common/ac/string.h>
23
24 #include <libaegis/change.h>
25 #include <libaegis/change/env_set.h>
26 #include <common/env.h>
27 #include <common/nstring.h>
28 #include <libaegis/project.h>
29 #include <libaegis/sub.h>
30
31
32 void
change_env_set(change::pointer cp,int with_arch)33 change_env_set(change::pointer cp, int with_arch)
34 {
35 //
36 // Set environment variables based on project_specific attributes,
37 // if specified.
38 //
39 pconf_ty *pconf_data = change_pconf_get(cp, 0);
40 if
41 (
42 pconf_data->project_specific
43 &&
44 !cp->project_specific_setenv_performed_get()
45 )
46 {
47 for (size_t j = 0; j < pconf_data->project_specific->length; ++j)
48 {
49 attributes_ty *ap =
50 pconf_data->project_specific->list[j];
51 if
52 (
53 ap->name
54 &&
55 ap->name->str_length > 7
56 &&
57 0 == strncasecmp(ap->name->str_text, "setenv:", 7)
58 )
59 {
60 const char *name = ap->name->str_text + 7;
61 if (ap->value && ap->value->str_length)
62 {
63 sub_context_ty *scp = sub_context_new();
64 nstring env_value(substitute(scp, cp, ap->value));
65 env_set(name, env_value.c_str());
66 sub_context_delete(scp);
67 }
68 else
69 env_unset(name);
70 }
71 }
72 cp->project_specific_setenv_performed_set();
73 }
74
75 //
76 // Set the LINES and COLS environment variables.
77 //
78 env_set_page();
79
80 //
81 // set the AEGIS_PROJECT environment cariable
82 //
83 env_set("AEGIS_PROJECT", cp->pp->name_get()->str_text);
84
85 //
86 // set the AEGIS_CHANGE environment cariable
87 //
88 if (!cp->bogus)
89 env_setf("AEGIS_CHANGE", "%ld", magic_zero_decode(cp->number));
90 else
91 env_unset("AEGIS_CHANGE");
92
93 //
94 // set the AEGIS_ARCH environment variable
95 //
96 string_ty *s = change_architecture_name(cp, with_arch);
97 if (s)
98 env_set("AEGIS_ARCH", s->str_text);
99 else
100 env_unset("AEGIS_ARCH");
101 }
102