Initial commit
[amiga/OpenBoopsi.git] / common / OpenClass.c
1 struct ClassLibrary *OpenClass(CONST_STRPTR name, CONST_STRPTR prefix, ULONG version)
2
3 /* Open named class. Look both in current and images/ directory
4  */
5 {
6         static struct EasyStruct OpenClassES =
7         {
8                 sizeof(struct EasyStruct),
9                 0,
10                 versiontag + 6,
11                 "Couldn't open %s version %ld or greater",
12                 "Ok"
13         };
14
15         struct ClassLibrary *classbase;
16         char buf[256];
17         int i;
18
19
20         if (!(classbase = (struct ClassLibrary *)OpenLibrary(name, version)))
21         {
22                 /* We can't use AddPart() here because we didn't open dos.library */
23
24                 /* Copy the prefix in the buffer */
25                 for (i = 0; buf[i] = prefix[i]; i++);
26
27                 /* Insert trailing character if missing */
28                 if(buf[i] != '/')
29                         buf[++i] = '/';
30
31                 /* Append the name */
32                 while (buf[i++] = *name++);
33
34                 /* Try again */
35                 classbase = (struct ClassLibrary *)OpenLibrary(buf, version);
36
37                 if (!classbase)
38                 {
39                         /* Report an error */
40                         EasyRequest(NULL, &OpenClassES, NULL, buf, version);
41                 }
42         }
43         return classbase;
44 }