]> gitweb.factorcode.org Git - factor.git/blob - basis/environment/environment-docs.factor
Switch to https urls
[factor.git] / basis / environment / environment-docs.factor
1 ! Copyright (C) 2008 Doug Coleman.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: assocs help.markup help.syntax io.streams.string
4 libc sequences strings ;
5 IN: environment
6
7 HELP: (os-envs)
8 { $values
9     { "seq" sequence } }
10 { $description "Returns a sequence of key/value pairs from the operating system." }
11 { $notes "In most cases, use " { $link os-envs } " instead." } ;
12
13 HELP: (set-os-envs)
14 { $values
15     { "seq" sequence } }
16 { $description "Low-level word for replacing the current set of environment variables." }
17 { $notes "In most cases, use " { $link set-os-envs } " instead." } ;
18
19
20 HELP: os-env
21 { $values { "key" string } { "value" string } }
22 { $description "Looks up the value of a shell environment variable." }
23 { $examples
24     "This is an operating system-specific feature. On Unix, you can do:"
25     { $unchecked-example
26         "USING: environment io ;"
27         "\"USER\" os-env print"
28         "jane"
29     }
30 } ;
31
32 HELP: change-os-env
33 { $values { "key" string } { "quot" { $quotation ( old -- new ) } } }
34 { $description "Applies a quotation to change the value stored in an environment variable." }
35 { $examples
36     "This is an operating system-specific feature. On Unix, you can do:"
37     { $unchecked-example
38         "USING: environment io ;"
39         "\"USER\" os-env print"
40         "\"USER\" [ \"-doe\" append ] change-os-env"
41         "\"USER\" os-env print"
42         "jane\njane-doe"
43     }
44 }
45 { $side-effects "key" } ;
46
47 HELP: os-envs
48 { $values { "assoc" "an association mapping strings to strings" } }
49 { $description "Outputs the current set of environment variables." }
50 { $notes
51     "Names and values of environment variables are operating system-specific."
52 } ;
53
54 HELP: set-os-envs
55 { $values { "assoc" "an association mapping strings to strings" } }
56 { $description "Replaces the current set of environment variables." }
57 { $warning "Leaks memory on Unix. If your program calls this function repeatedly, call " { $link set-os-envs-pointer } " with a malloced pointer and manage your memory instead." }
58 { $notes
59     "Names and values of environment variables are operating system-specific. Windows NT allows values up to 32766 characters in length."
60 } ;
61
62 HELP: set-os-envs-pointer
63 { $values { "malloc" "a pointer to memory from the heap obtained through " { $link malloc } " or similar" } }
64 { $description "Set then " { $snippet "environ" } " pointer. Factor must retain a pointer to this memory until exiting the program." }
65 { $notes
66     "Names and values of environment variables are operating system-specific."
67 } ;
68
69 HELP: set-os-env
70 { $values { "value" string } { "key" string } }
71 { $description "Set an environment variable." }
72 { $notes
73     "Names and values of environment variables are operating system-specific."
74 } ;
75
76 HELP: unset-os-env
77 { $values { "key" string } }
78 { $description "Unset an environment variable." }
79 { $notes
80     "Names and values of environment variables are operating system-specific."
81 } ;
82
83 HELP: with-os-env
84 { $values { "value" string } { "key" string } { "quot" "quotation" } }
85 { $description "Calls a quotation with the " { $snippet "key" } " environment variable set to " { $snippet "value" } ", resetting the environment variable afterwards to its previous value." } ;
86
87 { os-env os-envs set-os-env unset-os-env set-os-envs set-os-envs-pointer change-os-env with-os-env } related-words
88
89
90 ARTICLE: "environment" "Environment variables"
91 "The " { $vocab-link "environment" } " vocabulary interfaces to the platform-dependent mechanism for setting environment variables." $nl
92 "Reading environment variables:"
93 { $subsections
94     os-env
95     os-envs
96 }
97 "Writing environment variables:"
98 { $subsections
99     set-os-env
100     unset-os-env
101     set-os-envs
102     change-os-env
103 }
104 "Leak-free setting of all environment variables on Unix:"
105 { $subsections
106     set-os-envs-pointer
107
108 } ;
109
110 ABOUT: "environment"