1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
<pre>
<font color="#0000ff">// Copyright (c) 2003 David Muse</font>
<font color="#0000ff">// See the file COPYING for more information</font>
<font color="#a020f0">#include </font><font color="#ff00ff"><rudiments/environment.h></font>
<font color="#a020f0">#include </font><font color="#ff00ff"><stdio.h></font>
<font color="#a020f0">#ifdef RUDIMENTS_NAMESPACE</font>
<font color="#a52a2a"><b>using</b></font> <font color="#2e8b57"><b>namespace</b></font> rudiments;
<font color="#a020f0">#endif</font>
<font color="#2e8b57"><b>int</b></font> main(<font color="#2e8b57"><b>int</b></font> argc, <font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> **argv) {
<font color="#0000ff">// print the environment variable "TEST"</font>
printf(<font color="#ff00ff">"TEST=</font><font color="#6a5acd">%s</font><font color="#6a5acd">\n</font><font color="#ff00ff">"</font>,environment::getValue(<font color="#ff00ff">"TEST"</font>));
<font color="#0000ff">// set the value of "TEST" to "value"</font>
<font color="#a52a2a"><b>if</b></font> (environment::setValue(<font color="#ff00ff">"TEST"</font>,<font color="#ff00ff">"value"</font>)) {
printf(<font color="#ff00ff">"TEST=</font><font color="#6a5acd">%s</font><font color="#6a5acd">\n</font><font color="#ff00ff">"</font>,environment::getValue(<font color="#ff00ff">"TEST"</font>));
} <font color="#a52a2a"><b>else</b></font> {
printf(<font color="#ff00ff">"setValue() failed</font><font color="#6a5acd">\n</font><font color="#ff00ff">"</font>);
}
<font color="#0000ff">// set the value of "TEST" to "newvalue"</font>
<font color="#a52a2a"><b>if</b></font> (environment::setValue(<font color="#ff00ff">"TEST"</font>,<font color="#ff00ff">"newvalue"</font>)) {
printf(<font color="#ff00ff">"TEST=</font><font color="#6a5acd">%s</font><font color="#6a5acd">\n</font><font color="#ff00ff">"</font>,environment::getValue(<font color="#ff00ff">"TEST"</font>));
} <font color="#a52a2a"><b>else</b></font> {
printf(<font color="#ff00ff">"setValue() failed</font><font color="#6a5acd">\n</font><font color="#ff00ff">"</font>);
}
<font color="#0000ff">// remove "TEST" from the environment</font>
environment::remove(<font color="#ff00ff">"TEST"</font>);
<font color="#0000ff">// print the (non-existent) environment variable "TEST"</font>
printf(<font color="#ff00ff">"TEST=</font><font color="#6a5acd">%s</font><font color="#6a5acd">\n</font><font color="#ff00ff">"</font>,environment::getValue(<font color="#ff00ff">"TEST"</font>));
printf(<font color="#ff00ff">"</font><font color="#6a5acd">\n\n</font><font color="#ff00ff">"</font>);
environment::print();
printf(<font color="#ff00ff">"</font><font color="#6a5acd">\n\n</font><font color="#ff00ff">"</font>);
environment::clear();
printf(<font color="#ff00ff">"</font><font color="#6a5acd">\n\n</font><font color="#ff00ff">clear?</font><font color="#6a5acd">\n</font><font color="#ff00ff">"</font>);
environment::print();
}
</pre>
|