6 * © 1993-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 res__prefix[40];
41 * void res_init(char *progname)
44 * Sets up res to use a certain path for resources. Mainly for
45 * compatibility with older applications.
48 * char *progname == the program name (sets up path as <progname$Dir>)
51 void res_init(char *progname)
53 sprintf(res__prefix,"<%s$Dir>",progname);
57 * void res_setPrefix(char *prefix)
60 * Sets up a full prefix for resources. This means you can keep resources
61 * in separate directories.
64 * char *prefix == the prefix
67 void res_setPrefix(char *prefix)
69 strcpy(res__prefix,prefix);
73 * BOOL res_fileExists(char *name)
76 * Informs the caller if a given file exists
79 * char *name == the name of the file
82 * TRUE if the file really does exist
85 BOOL res_fileExists(char *name)
96 * BOOL res__trySuffix(char *name)
99 * Tries to find a file with a possible WIMP-style mode suffix (24,23,22
100 * etc.) If it did, it updates the name in the caller's buffer, and
101 * returns TRUE. Otherwise, the name is preserved, and it returns FALSE.
104 static BOOL res__trySuffix(char *name)
108 if (wimpt_getVersion()>=300)
110 end=name+strlen(name);
111 wimpt_noerr(wimp_readsysinfo(2,(int *)&suff));
113 if (res_fileExists(name))
117 if (res_fileExists(name))
123 * char *res__findCountryName(void)
126 * Returns the name of the current country. If the current country is
127 * unknown, try the UK.
130 static char *res__findCountryName(void)
132 char *buffer=buffer_find();
133 int country=_swi(OS_Byte,_inr(0,2)+_return(1),240,0,255);
135 if (_swi(OS_ServiceCall,
136 _inr(1,4)+_out(5)+_return(1),
137 0x43,2,country,buffer,
148 * int res_findname(const char *resname,char *buf)
151 * Returns a full pathname for the resource file as given in the buffer.
152 * This is for compatibility reasons. If I was writing this fresh, I
153 * would return a pointer to an internal static object, but Acorn know
156 * Some new functionality has been added. It will look for files first in
157 * the directory set up using res_init or res_setPrefix, and then in the
158 * 'Resources' subdirectory. If neither is present, then the name returned
159 * is in the main application directory.
161 * Also, under RISC OS 3, it will search for files with mode prefixes, so
162 * you can use multiple sprite files for different resolutions. Isn't this
166 * const char *resname == the leafname of the resource file.
167 * char *buf == where to put the result.
170 * TRUE for compatibility with the Acorn version. What good it does, I
171 * don't know. This is in all a very odd routine indeed.
174 int res_findname(const char *resname,char *buf)
176 sprintf(buf,"%s.Resources.%s",res__prefix,resname);
177 if (res__trySuffix(buf))
180 "%s.Resources.%s.%s",
182 res__findCountryName(),
184 if (res__trySuffix(buf))
187 "%s.Resources.UK.%s",
190 if (res__trySuffix(buf))
192 sprintf(buf,"%s.%s",res__prefix,resname);
193 if (res__trySuffix(buf))
195 sprintf(buf,"%s.%s",res__prefix,resname);
200 * char *res_name(const char *resname)
203 * Translates the name given as for res_findname and returns a pointer to
204 * the translated string
207 char *res_name(const char *resname)
209 char *buffer=buffer_find();
210 res_findname(resname,buffer);
215 * FILE *res_openfile(const char *resname,const char *mode)
218 * Opens a resource file in a given ANSI mode. It does this without the
219 * odd adding on of numbers to the end that the Acorn one does (I hope!)
222 * const char *resname == leafname of file to open
223 * const char *mode == pointer to ANSI mode string
226 * A standard ANSI-type FILE pointer.
229 FILE *res_openfile(const char *resname,const char *mode)
231 return (fopen(res_name(resname),mode));