BRL-CAD
Loading...
Searching...
No Matches
env.h
Go to the documentation of this file.
1/* E N V . H
2 * BRL-CAD
3 *
4 * Copyright (c) 2007-2025 United States Government as represented by
5 * the U.S. Army Research Laboratory.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * version 2.1 as published by the Free Software Foundation.
10 *
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this file; see the file named COPYING for more
18 * information.
19 */
20
21#ifndef BU_ENV_H
22#define BU_ENV_H
23
24#include "common.h"
25
26#include "bu/defines.h"
27#include "bu/ptbl.h"
28
30
31/** @addtogroup bu_env
32 *
33 * @brief
34 * Platform-independent methods for interacting with the parent operating
35 * system environment.
36 *
37 */
38/** @{ */
39/** @file bu/env.h */
40
41BU_EXPORT extern int bu_setenv(const char *name, const char *value, int overwrite);
42
43
44/* Specific types of machine memory information that may be requested */
45#define BU_MEM_ALL 0
46#define BU_MEM_AVAIL 1
47#define BU_MEM_PAGE_SIZE 2
48
49/**
50 * Report system memory sizes.
51 *
52 * Returns -1 on error and the size of the requested memory type on
53 * success. Optionally if sz is non-NULL, the size of the requested
54 * memory type will be set to it.
55 */
56BU_EXPORT extern ssize_t bu_mem(int type, size_t *sz);
57
58
59/**
60 * Select an editor.
61 *
62 * Returns a string naming an editor to be used. If an option is needed for
63 * invoking the editor, it is supplied via the editor_opt output.
64 *
65 * When 0 is supplied to the etype parameter, all editors will be considered
66 * when using libbu's internal editors list. To restrict the set searched to
67 * console editors, set etype to 1. For only GUI editors, set etype to 2.
68 *
69 * The general pattern for trying to locate an editor using inputs (either
70 * internal or user supplied is:
71 *
72 * 1. If the input is a full, valid path it will be used as-is.
73 * 2. Otherwise, the BRL-CAD's binaries will be checked for a bundled copy.
74 * 3. Otherwise, bu_which will attempt to find the full path.
75 *
76 * The highest priority source for editors to try are the BRLCAD_EDITOR_GUI
77 * (for graphical editors) and BRLCAD_EDITOR_CONSOLE for console editors. If
78 * those are unset or don't satisfy the criteria, the VISUAL (2nd priority) or
79 * EDITOR (3rd priority) environment variables are checked next. If any of
80 * those variables are set and identify a valid edtior per current criteria
81 * they take priority over both libbu's internal list and a user supplied list.
82 *
83 * If the environment variables don't pan out, the next priority is any user
84 * supplied options via the check_for_editors array. As with the env
85 * variables, an attempt will be made to respect the etype setting.
86 *
87 * If the optional check_for_editors array is provided, libbu will first
88 * attempt to use the contents of that array to find an editor. The main
89 * purpose of check_for_editors is to allow applications to define their own
90 * preferred precedence order in case there are specific advantages to using
91 * some editors over others. It is also useful if an app wishes to list some
92 * specialized editor not part of the normal listings, although users should
93 * note that the etype modal checks will not be useful when such editors are
94 * supplied. If an application wishes to use ONLY a check_for_editors list and
95 * not fall back on libbu's internal list if it fails, they should assign the
96 * last entry of check_for_editors to be NULL to signal libbu to stop looking
97 * for an editor there:
98 *
99 * int check_for_cnt = 3; const char *check_for_editors[3] = {"editor1", "editor2", NULL};
100 *
101 * To allow libbu to continue on if all check_for_editors entries fail,
102 * don't terminate with a NULL:
103 *
104 * int check_for_cnt = 2; const char *check_for_editors[3] = {"editor1", "editor2"};
105 *
106 * In the latter case, if none of those inputs result in an editor being
107 * returned, libbu will attempt to use its own internal lists to search. We
108 * are deliberately NOT documenting the libbu's internal editor list as public
109 * API, nor do we make any guarantees about what precedence any editor that IS
110 * on the list will take relative to other editors. What editors are popular
111 * in various environments can change over time, and the purpose of this
112 * function is to provide *some* editor, rather than locking in any particular
113 * precedence. check_for_editors should be used if an app needs more
114 * guaranteed stability in lookup behaviors.
115 *
116 * If etype != 0, bu_editor will attempt to validate any candidate returns
117 * against its own internal list of GUI and console editors to avoid returning
118 * an editor that is incompatible with the specified environment. There are no
119 * strong guarantees offered for this checking - libbu's knowledge of editors
120 * is not comprehensive and specification strings for editors may break the
121 * matching being used internally. In a case where libbu CAN'T make a definite
122 * categorization (a user supplied custom editor, for example) the default
123 * behavior will be to pass through the result as successful. This is
124 * obviously not foolproof, but in various common cases libbu will avoid
125 * returning (for example) nano from an EDITOR setting when a GUI editor type
126 * was requested.
127 *
128 * Caller should NOT free the main string return from bu_editor or the contents
129 * of the editor_opts bu_ptbl. The caller has ownership of the editor_opts
130 * bu_ptbl container however, so they ARE responsible for for freeing the table
131 * itself once use of editor_opts is complete.
132 */
133BU_EXPORT const char *bu_editor(struct bu_ptbl *editor_opts, int etype, int check_for_cnt, const char **check_for_editors);
134
135/** @} */
136
138
139#endif /* BU_ENV_H */
140
141/*
142 * Local Variables:
143 * tab-width: 8
144 * mode: C
145 * indent-tabs-mode: t
146 * c-file-style: "stroustrup"
147 * End:
148 * ex: shiftwidth=4 tabstop=8
149 */
Definition dvec.h:74
Header file for the BRL-CAD common definitions.
ssize_t bu_mem(int type, size_t *sz)
const char * bu_editor(struct bu_ptbl *editor_opts, int etype, int check_for_cnt, const char **check_for_editors)
int bu_setenv(const char *name, const char *value, int overwrite)
Definition ptbl.h:53