#set, #setenv, #unset, #unsetenv
With #set, and its variant #setenv, you can set environment variables. You can then reference these environment variables in subsequent preprocessor directives, such as #exec, #include, #verbatim, and #echo. (Note that legal environment variable names begin with a letter, followed by any sequence of letters, digits, and/or _ (underscore).)
For example, at pikt.org, we use PIKT as a content management system (CMS) for our web pages. In the file doc_ref_files.cfg, for each web page, we set various environment variables, such as:
#set cat = "Reference" #set title = "PIKT Reference" #set descr = "Overview; Config Files; Preprocessing; Programs; Pikt Script Language; Miscellany" #set keywords = "pikt reference" ... #include <files/pikt/doc_page_top_files.cfg> ...In the #include file, doc_page_top_files.cfg, we reference those environment variables by means of the #echo directive:
=doctype <html> <head> #echo "<title>$title</title>" =meta_content_language =meta_content_type #echo "=meta_description($descr)" #echo "=meta_keywords($keywords)" =meta_author(=pikt_author) =meta_copyright(=pikt_license((c))) //=meta_copyright(=pikt_copyright) #ifdef homepage =meta_noodp #endifdef =css_style </head> ...In any of the config files, if you use
#set foo = "bar"or the variant
#setenv foo "bar"you could access the value of the $foo environment variable in a subsequent preprocessor directive.
If you don't specify a value, as in
#set foothe environment variable is implicitly set to 1. So the previous #set directive is equivalent to
#set foo = "1"and
#setenv foo "1"#unset and #unsetenv undo the effects of the #set and #setenv directives. So
#unset fooor
#unsetenv fooleaves the environment variable $foo undefined.
You may set (or unset) environment variables in this way to #include (or not) files (i.e., processes cat'ing the file(s)), or to access environment variable values using the #echo command, to pass parameters to processes embedded within preprocessor directives (e.g., #include [<proc>], or #exec [<proc], or to do some other clever thing.
For example, if you do this in one of your config files
#set foo #include <files/this_files.cfg> #unset fooyou could have in this_files.cfg
#include [test $foo && /bin/cat /pikt/lib/configs/files/that_files.cfg]or perhaps #include the output of some process
#include [/usr/local/bin/bar.pl]where bar.pl references the $foo environment variable, for example with
if ($ENV{foo}) { ... }Together with the piktc -|+ E (un)set environment variable option, #set, #setenv, #unset, #unsetenv and the other preprocessor directives make a very powerful combination.
For some examples, refer to the Samples and Developer's Notes pages.
prev page | 1st page | next page |