4 * Handling the global choices repository
6 * © 1994-1998 Straylight
9 /*----- Licensing note ----------------------------------------------------*
11 * This file is part of Straylight's Steel library.
13 * Steel is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2, or (at your option)
18 * Steel is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with Steel. If not, write to the Free Software Foundation,
25 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
37 static char choices__root[15];
40 * void choices_setName(char *progname)
43 * Sets the name of the application as used by choices. The name is
44 * truncated to 10 characters if necessary. If no name is specified (i.e.
45 * you don't call this routine) then the name of the application (as passed
46 * to wimpt_init) is assumed.
49 void choices_setName(char *progname)
51 memcpy(choices__root,progname,10);
56 * char *choices_name(char *leaf,BOOL writable)
59 * Locates the name of the specified resource. If you want to open a file
60 * for writing, you should set the writable flag. Otherwise, this routine
61 * will try to find the name of a file which already exists.
63 * If you only want to read a file, this routine will first look at
64 * <Choices$Dir>.leaf, and then at <resPrefix>.leaf, and return whichever
65 * is found first. If neither exists, a name is returned as for the
68 * If you want to write a file, then <Choices$Dir>.leaf is returned, unless
69 * Choices$Dir is unset, in which case <resPrefix>.leaf is returned.
71 * resPrefix is the prefix passed to res through res_init or res_setPrefix.
74 char *choices_name(char *leaf,BOOL writable)
76 char *name=buffer_find();
77 char *choices=getenv("Choices$Write");
79 /* --- Ensure choices__root is set up properly --- */
81 if (!choices__root[0])
82 choices_setName(wimpt_programname());
84 /* --- Just find one of the cases -- we're only reading --- */
90 sprintf(name,"Choices:%s.%s",choices__root,leaf);
91 if (res_fileExists(name))
94 strcpy(name,res_name(leaf));
95 if (res_fileExists(name))
99 /* --- Find whichever is more appropriate --- */
105 /* --- To avoid hassle, create the directory here --- */
107 sprintf(name,"CDir %s.%s",choices,choices__root);
110 sprintf(name,"%s.%s.%s",choices,choices__root,leaf);
113 strcpy(name,res_name(leaf));