/* * choices.c * * Handling the global choices repository * * © 1994-1998 Straylight */ /*----- Licensing note ----------------------------------------------------* * * This file is part of Straylight's Steel library. * * Steel is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * Steel is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Steel. If not, write to the Free Software Foundation, * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include "res.h" #include "wimpt.h" #include "buffer.h" #include "choices.h" static char choices__root[15]; /* * void choices_setName(char *progname) * * Use * Sets the name of the application as used by choices. The name is * truncated to 10 characters if necessary. If no name is specified (i.e. * you don't call this routine) then the name of the application (as passed * to wimpt_init) is assumed. */ void choices_setName(char *progname) { memcpy(choices__root,progname,10); choices__root[10]=0; } /* * char *choices_name(char *leaf,BOOL writable) * * Use * Locates the name of the specified resource. If you want to open a file * for writing, you should set the writable flag. Otherwise, this routine * will try to find the name of a file which already exists. * * If you only want to read a file, this routine will first look at * .leaf, and then at .leaf, and return whichever * is found first. If neither exists, a name is returned as for the * writable case. * * If you want to write a file, then .leaf is returned, unless * Choices$Dir is unset, in which case .leaf is returned. * * resPrefix is the prefix passed to res through res_init or res_setPrefix. */ char *choices_name(char *leaf,BOOL writable) { char *name=buffer_find(); char *choices=getenv("Choices$Write"); /* --- Ensure choices__root is set up properly --- */ if (!choices__root[0]) choices_setName(wimpt_programname()); /* --- Just find one of the cases -- we're only reading --- */ if (!writable) { if (choices) { sprintf(name,"Choices:%s.%s",choices__root,leaf); if (res_fileExists(name)) return (name); } strcpy(name,res_name(leaf)); if (res_fileExists(name)) return (name); } /* --- Find whichever is more appropriate --- */ if (choices) { if (writable) { /* --- To avoid hassle, create the directory here --- */ sprintf(name,"CDir %s.%s",choices,choices__root); os_cli(name); } sprintf(name,"%s.%s.%s",choices,choices__root,leaf); } else strcpy(name,res_name(leaf)); return (name); }