Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / prefs / icontrol / main.c
blob90745920aa8548f797a41ccbf1b521e3cbf160a4
1 /*
2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 /*********************************************************************************************/
8 #include "global.h"
9 #include "version.h"
11 #include <libraries/coolimages.h>
12 #include <aros/debug.h>
14 #include <zune/clock.h>
15 #include <zune/calendar.h>
17 #include <stdlib.h> /* for exit() */
18 #include <stdio.h>
19 #include <string.h>
21 /*********************************************************************************************/
23 #define ARG_TEMPLATE "FROM,EDIT/S,USE/S,SAVE/S,PUBSCREEN/K"
25 #define ARG_FROM 0
26 #define ARG_EDIT 1
27 #define ARG_USE 2
28 #define ARG_SAVE 3
29 #define ARG_PUBSCREEN 4
31 #define NUM_ARGS 5
33 #define RETURNID_USE 1
34 #define RETURNID_SAVE 2
36 /*********************************************************************************************/
38 static struct libinfo
40 APTR var;
41 STRPTR name;
42 WORD version;
43 BOOL required;
45 libtable[] =
47 {&IntuitionBase , "intuition.library" , 39, TRUE },
48 {&GfxBase , "graphics.library" , 40, TRUE }, /* 40, because of WriteChunkyPixels */
49 {&UtilityBase , "utility.library" , 39, TRUE },
50 {&IFFParseBase , "iffparse.library" , 39, TRUE },
51 {&MUIMasterBase , "muimaster.library" , 0 , TRUE },
52 {NULL }
55 /*********************************************************************************************/
57 static struct RDArgs *myargs;
58 static IPTR args[NUM_ARGS];
60 /*********************************************************************************************/
62 static void CloseLibs(void);
63 static void FreeArguments(void);
66 /*********************************************************************************************/
68 WORD ShowMessage(STRPTR title, STRPTR text, STRPTR gadtext)
70 struct EasyStruct es;
72 es.es_StructSize = sizeof(es);
73 es.es_Flags = 0;
74 es.es_Title = title;
75 es.es_TextFormat = text;
76 es.es_GadgetFormat = gadtext;
78 return EasyRequestArgs(NULL, &es, NULL, NULL);
81 /*********************************************************************************************/
83 void Cleanup(STRPTR msg)
85 if (msg)
87 if (IntuitionBase && !((struct Process *)FindTask(NULL))->pr_CLI)
89 ShowMessage("IControl", msg, MSG(MSG_OK));
91 else
93 printf("IControl: %s\n", msg);
97 KillGUI();
99 FreeArguments();
100 CloseLibs();
101 CleanupLocale();
103 exit(prog_exitcode);
107 /*********************************************************************************************/
109 static void OpenLibs(void)
111 struct libinfo *li;
113 for(li = libtable; li->var; li++)
115 if (!((*(struct Library **)li->var) = OpenLibrary(li->name, li->version)))
117 if (li->required)
119 sprintf(s, MSG(MSG_CANT_OPEN_LIB), li->name, li->version);
120 Cleanup(s);
127 /*********************************************************************************************/
129 static void CloseLibs(void)
131 struct libinfo *li;
133 for(li = libtable; li->var; li++)
135 if (*(struct Library **)li->var) CloseLibrary((*(struct Library **)li->var));
139 /*********************************************************************************************/
141 static void GetArguments(void)
143 if (!(myargs = ReadArgs(ARG_TEMPLATE, args, NULL)))
145 Fault(IoErr(), 0, s, 256);
146 Cleanup(s);
149 if (!args[ARG_FROM]) args[ARG_FROM] = (IPTR)CONFIGNAME_ENV;
152 /*********************************************************************************************/
154 static void FreeArguments(void)
156 if (myargs) FreeArgs(myargs);
159 /*********************************************************************************************/
173 static void HandleAll(void)
175 ULONG sigs = 0;
176 LONG returnid;
178 set (wnd, MUIA_Window_Open, TRUE);
180 for(;;)
182 returnid = (LONG) DoMethod(app, MUIM_Application_NewInput, (IPTR) &sigs);
184 if ((returnid == MUIV_Application_ReturnID_Quit) ||
185 (returnid == RETURNID_SAVE) || (returnid == RETURNID_USE)) break;
187 if (sigs)
189 sigs = Wait(sigs | SIGBREAKF_CTRL_C);
190 if (sigs & SIGBREAKF_CTRL_C) break;
196 /*********************************************************************************************/
198 int main(void)
200 InitLocale("System/Prefs/IControl.catalog", 1);
201 InitMenus();
202 OpenLibs();
203 GetArguments();
204 InitPrefs((STRPTR)args[ARG_FROM], (args[ARG_USE] ? TRUE : FALSE), (args[ARG_SAVE] ? TRUE : FALSE));
206 MakeGUI();
207 HandleAll();
208 Cleanup(NULL);
210 return 0;
213 /*********************************************************************************************/