delint
[AROS.git] / workbench / prefs / Editor / JanoPrefs.c
blob0a8d1608c688b209c38de9ed1829a5a7cde88110
1 /***************************************************************
2 **** JanoPrefs.c: Configuration window for JanoEditor ****
3 **** Free software under GNU license, started on 11/11/2000 ****
4 **** © T.Pierron, C.Guillaume. ****
5 ***************************************************************/
7 #define ASL_V38_NAMES_ONLY
8 #include <intuition/intuition.h>
9 #include <intuition/intuitionbase.h>
10 #include <libraries/gadtools.h>
11 #include <libraries/asl.h>
12 #include <libraries/dos.h>
13 #include <graphics/gfxbase.h>
14 #include <graphics/modeid.h>
16 #include <proto/exec.h>
17 #include <proto/dos.h>
18 #include <proto/graphics.h>
19 #include <proto/intuition.h>
20 #include <proto/gadtools.h>
21 #include <proto/asl.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <stdio.h>
27 #include "Jed.h"
28 #include "JanoPrefs.h"
29 #include "IPC_Prefs.h"
30 #include "Sample.h"
32 #define CATCOMP_NUMBERS
33 #include "strings.h"
34 #define LocaleInfo LocaleInfoTmp /* Avoid redefinition :-( */
35 #include "../../tools/Edit/strings.h"
37 /* Shared libraires we'll need to open */
38 struct IntuitionBase *IntuitionBase = NULL;
39 struct GfxBase *GfxBase = NULL;
40 struct Library *GadToolsBase = NULL;
41 struct Library *AslBase = NULL;
42 struct Library *LocaleBase = NULL;
43 struct Library *DiskfontBase = NULL;
44 struct Library *LayersBase = NULL;
46 struct IntuiMessage *msg, msgbuf;
47 struct NewWindow NewPrefWin =
49 0,0,0,0, 1,1, /* LE,TE,Wid,Hei, Pens */
50 IDCMP_MENUPICK | IDCMP_CLOSEWINDOW | IDCMP_GADGETUP | IDCMP_NEWSIZE | IDCMP_VANILLAKEY,
51 WFLG_CLOSEGADGET | WFLG_NEWLOOKMENUS | WFLG_DEPTHGADGET | WFLG_ACTIVATE | WFLG_SMART_REFRESH |
52 WFLG_DRAGBAR,
53 NULL, /* FirstGadget */
54 NULL, /* CheckMark */
55 NULL, /* Title */
56 NULL, /* Screen */
57 NULL, /* BitMap */
58 100, 50, 0xffff, 0xffff, /* Min & Max size */
59 CUSTOMSCREEN
62 /** Standard GUI ressource **/
63 struct Screen *Scr = NULL; /* Screen where window opens */
64 struct Window *Wnd = NULL; /* Pointer to the opened window */
65 void *Vi = NULL; /* Visual Info for gadget */
66 struct Menu *Menu = NULL; /* Menu of interface */
67 struct TextFont *font; /* Font used for gadgets */
68 struct RastPort RPT; /* Font measurement */
70 STRPTR FSCycTxt[5];
71 UBYTE CB_state[CBS];
73 /* Tag list for various gadget */
74 struct TagItem IntTags[] = { /*{GTIN_Number, 0},*/ {GTST_MaxChars,2}, {TAG_DONE}};
75 struct TagItem SepTags[] = {{GTST_MaxChars, MAX_SPLIT}, {TAG_DONE}};
76 struct TagItem TextFontTags[] = {{GTCY_Labels, (IPTR)FTCycTxt}, {GTCY_Active,0}, {TAG_DONE}};
77 struct TagItem ScrFontTags[] = {{GTCY_Labels, (IPTR)FSCycTxt}, {GTCY_Active,0}, {TAG_DONE}};
78 struct TagItem ScrMdTags[] = {{GTCY_Labels, (IPTR)ScrCycTxt}, {GTCY_Active,0}, {TAG_DONE}};
79 struct TagItem ColorTags[] = {{GTCY_Labels, (IPTR)ColCycTxt}, {GTCY_Active,0}, {TAG_DONE}};
80 struct TagItem MenuTags[] = {{GTMN_FrontPen, 1L}, {TAG_DONE}};
82 struct TagItem *GadTags[] = {IntTags, SepTags, TextFontTags, ScrFontTags, ScrMdTags};
84 /* Tag list for opening the main window */
85 WORD PrefZoom[4];
86 struct TagItem PrefTags[] = {
87 {WA_Zoom,(IPTR)PrefZoom},
88 {WA_NewLookMenus,TRUE},
89 {TAG_DONE}
92 struct NewGadget NG; /* To create the gadgets */
93 struct Gadget *pgads=NULL; /* Gadtool's gadgets */
94 struct Gadget *gads[CBS+CGS];
95 extern PREFS prefs; /* Preference buffer */
96 extern UBYTE Modif[]; /* Buffer for string's gadget */
97 ULONG prefsigbit, msgport; /* Signal bits for asynchronous messages collect */
98 ULONG extended; /* Extended cycle gadgets */
99 UBYTE ConfigFile = TRUE; /* TRUE is a config file is edited */
100 UBYTE ColorIndex = 0; /* Color index to change */
101 UBYTE StrInfo[60]; /* Screen/font description */
102 WORD wid[5]; /* Width of various strings */
104 /*** Display an error message in the window's title ***/
105 static UBYTE *Title = NULL;
106 static ULONG err_time;
107 void ThrowError(struct Window *W, UBYTE *Msg)
109 if( W ) {
110 /* Save old title */
111 if(Title == 0)
112 Title = (W->Flags & WFLG_BACKDROP ? W->WScreen->Title : W->Title);
113 /* If window is backdrop'ed, change screen's title instead of window */
114 if(W->Flags & WFLG_BACKDROP) SetWindowTitles(W,(STRPTR)-1,Msg);
115 else SetWindowTitles(W,Msg,(STRPTR)-1);
117 DisplayBeep(W->WScreen);
118 err_time = 0;
119 /* To be sure that mesage will be disappear one day */
120 ModifyIDCMP(W,W->IDCMPFlags | IDCMP_INTUITICKS);
121 } else puts(Msg);
124 /*** Show messages associated with IoErr() number ***/
125 void ThrowDOSError(struct Window *W, STRPTR Prefix, UBYTE err)
127 static UBYTE Message[100];
129 /* Get standard DOS error message */
130 Fault(err, Prefix, Message, sizeof(Message));
132 ThrowError(W, Message);
135 /*** Reset the old title ***/
136 void StopError(struct Window *W)
138 if(W->Flags & WFLG_BACKDROP) SetWindowTitles(W,(STRPTR)-1,Title);
139 else SetWindowTitles(W,Title,(STRPTR)-1);
140 Title=0;
141 /* INTUITICKS aren't required anymore */
142 ModifyIDCMP(W,W->IDCMPFlags & ~IDCMP_INTUITICKS);
145 /*** Try to open configuration window, return 1 if all's ok ***/
146 BYTE setup_guipref( void )
148 extern UBYTE Path[];
149 WORD width,i;
151 /** Look if window isn't already open, thus just activate it **/
152 if( Wnd ) {
153 ActivateWindow(Wnd);
154 WindowToFront(Wnd);
155 /* Uniconified it, if it is */
156 if(Wnd->Height<=Wnd->BorderTop) ZipWindow(Wnd);
157 ScreenToFront(Scr);
158 return TRUE;
161 /** Visual info pointer **/
162 if(Vi == NULL && !(Vi = (void *) GetVisualInfoA(Scr,NULL))) return 0;
164 /** Init missing strings **/
165 CopyMem(FTCycTxt,FSCycTxt,sizeof(FSCycTxt));
166 CopyMem(FTCycTxt+1,ScrCycTxt+2,sizeof(UBYTE *)*2);
167 FTCycTxt[0]=StrInfo;
168 FSCycTxt[0]=StrInfo+20;
169 ScrCycTxt[0]=StrInfo+40;
170 /** Init temporary rastport, for font measurement **/
171 InitRastPort(&RPT);
172 SetFont(&RPT, font = Scr->RastPort.Font);
174 /** Compute window width and height **/
175 wid[0] = meas_table(MiscTxt);
176 wid[1] = meas_table(ChkTxt);
177 wid[2] = meas_table(OkCanSav)+20;
178 wid[3] = meas_table(FSCycTxt);
179 wid[4] = meas_table(ColCycTxt);
180 width = meas_table(ScrCycTxt);
181 if(wid[3] < width) wid[3] = width;
183 NewPrefWin.Width = wid[0] + wid[3] + wid[1] + 130;
184 NewPrefWin.Height = Scr->BarHeight + font->tf_YSize * 8 + (59 + SAMPLE_HEI);
185 NewPrefWin.LeftEdge = 50;
186 NewPrefWin.TopEdge = 50;
187 NewPrefWin.Screen = Scr;
188 NewPrefWin.Title = (ConfigFile ? Path : PrefMsg[0]);
190 /** Does it fit in the screen ? **/
191 fit_in_screen(&NewPrefWin, Scr);
193 /** Compute the iconified window dimensions: **/
194 PrefZoom[2] = TextLength(&RPT,NewPrefWin.Title,strlen(NewPrefWin.Title))+100;
195 if(prefs.use_pub) PrefZoom[0] = Scr->Width-PrefZoom[2]-15, PrefZoom[1] = 0;
196 else PrefZoom[0] = PrefZoom[1] = 50;
197 PrefZoom[3] = Scr->WBorTop + Scr->Font->ta_YSize + 1;
199 /** Setup inital tags: **/
200 ScrFontTags[1].ti_Data = 0;
201 ScrMdTags[1].ti_Data = 0;
202 TextFontTags[1].ti_Data = 0;
203 extended=0;
205 if( prefs.use_txtfont )
206 font_info(StrInfo, prefs.txtfont),
207 TextFontTags[0].ti_Data = (IPTR) FTCycTxt, extended |= 1;
208 else
209 TextFontTags[0].ti_Data = (IPTR) (FTCycTxt+1);
211 if( prefs.use_scrfont )
212 font_info(StrInfo+20, prefs.scrfont),
213 ScrFontTags[0].ti_Data = (IPTR) FSCycTxt, extended |= 2;
214 else
215 ScrFontTags[0].ti_Data = (IPTR) (FSCycTxt+1);
217 if( prefs.use_pub==1 )
218 scr_info(StrInfo+40,Scr->Width, Scr->Height, Scr->RastPort.BitMap->Depth),
219 ScrMdTags[0].ti_Data = (IPTR) ScrCycTxt, extended |= 4;
220 else {
221 ScrMdTags[0].ti_Data = (IPTR) (ScrCycTxt+1);
222 if(prefs.use_pub!=2) ScrMdTags[1].ti_Data = 1; /* Clone */
224 /* Checkbox states */
225 CopyMem(&prefs.backdrop, CB_state, CBS);
227 /* If it isn't the frontmost screen */
228 if(Scr != IntuitionBase->ActiveScreen) ScreenToFront(Scr);
230 /** Init Menus **/
231 if(NULL == (Menu = (void *) CreateMenusA(newmenu, MenuTags)) ||
232 0 == LayoutMenus(Menu, Vi, GTMN_TextAttr, Scr->Font, TAG_DONE)) return FALSE;
234 /** Try to open the window **/
235 if(( Wnd = (struct Window *) OpenWindowTagList(&NewPrefWin,PrefTags) ))
237 struct Gadget **pg = gads, *gad;
238 pgads = NULL;
239 gad = (struct Gadget *) CreateContext(&pgads);
240 NG.ng_TopEdge = Wnd->BorderTop+5;
241 NG.ng_Width = wid[3]+40;
242 NG.ng_LeftEdge = wid[0]+20;
243 NG.ng_Height = font->tf_YSize+6;
244 NG.ng_Flags = PLACETEXT_LEFT | NG_HIGHLABEL;
245 NG.ng_TextAttr = Scr->Font;
246 NG.ng_VisualInfo = Vi;
248 /* Create left column of gadgets */
249 for(i=0; i<CGS; i++, NG.ng_TopEdge+=NG.ng_Height, *pg++ = gad)
251 WORD kind;
253 NG.ng_GadgetText = MiscTxt[i];
254 NG.ng_GadgetID = i;
255 if (i == 0)
257 kind = INTEGER_KIND;
259 else if (i == 1)
261 kind = STRING_KIND;
263 else
265 kind = CYCLE_KIND;
268 gad = (void *) CreateGadgetA(kind, gad, &NG, GadTags[i]);
269 if(i==0) AddNum (prefs.tabsize, GetSI(gad)->Buffer);
270 if(i==1) CopyMem(prefs.wordssep, GetSI(gad)->Buffer, MAX_SPLIT);
273 /* Create right column of gads */
274 NG.ng_TopEdge = Wnd->BorderTop+5;
275 NG.ng_LeftEdge += NG.ng_Width+20;
276 NG.ng_Width = (NG.ng_Height -= 2);
277 NG.ng_Flags = PLACETEXT_RIGHT;
278 for(; i<CGS+CBS; i++, NG.ng_TopEdge+=NG.ng_Height, *pg++ = gad)
280 NG.ng_GadgetText = ChkTxt[i-CGS];
281 NG.ng_GadgetID = i;
282 gad = (void *) CreateGadget(CHECKBOX_KIND, gad, &NG, GTCB_Checked, CB_state[i-CGS], TAG_DONE);
283 if(i == CGS && prefs.use_pub == 0)
284 gad->Flags |= GFLG_DISABLED;
287 /* Create bottom row of gadgets */
288 NG.ng_TopEdge = Wnd->Height-NG.ng_Height-10;
289 NG.ng_LeftEdge = 10;
290 NG.ng_Width = wid[2];
291 NG.ng_Flags = PLACETEXT_IN;
292 width = (Wnd->Width-20-wid[2]) >> 1;
293 for(; i<UCS+3; i++, NG.ng_LeftEdge+=width)
295 NG.ng_GadgetText = OkCanSav[i-UCS];
296 NG.ng_GadgetID = i;
297 gad = (void *) CreateGadgetA(BUTTON_KIND, gad, &NG, NULL);
300 /* Initiate sample editor to see colors adjustement */
301 init_sample(Wnd, &prefs, NG.ng_TopEdge -= 5 + SAMPLE_HEI);
303 /* Cycle color chooser */
304 NG.ng_TopEdge -= NG.ng_Height+3;
305 NG.ng_Width = wid[4]+40;
306 NG.ng_GadgetText = NULL;
307 NG.ng_GadgetID = i;
308 NG.ng_LeftEdge = 10;
309 gad = (void *) CreateGadgetA(CYCLE_KIND, gad, &NG, ColorTags);
311 /* Palette chooser */
312 NG.ng_Width = Wnd->Width - 10 - (
313 NG.ng_LeftEdge += NG.ng_Width+10);
314 NG.ng_GadgetID = i+1;
315 CreateGadget(PALETTE_KIND,
316 gad,
317 &NG,
318 GTPA_Depth, ((Scr->RastPort.BitMap->Depth > 5) ? 5 : Scr->RastPort.BitMap->Depth),
319 TAG_DONE);
321 /* Add gadgets to window: */
322 CopyMem(Wnd->RPort, &RPT, sizeof(RPT));
323 SetFont(&RPT, prefs.scrfont);
324 render_sample(Wnd, EDIT_ALL);
325 AddGList( Wnd, pgads, -1, -1, NULL);
326 RefreshGList(pgads, Wnd, NULL, -1);
327 SetMenuStrip( Wnd, Menu );
328 GT_RefreshWindow(Wnd, NULL);
330 /* Add window's signal bit: */
331 prefsigbit = 1 << Wnd->UserPort->mp_SigBit;
332 return TRUE;
334 return FALSE;
337 /*** Close the preference window ***/
338 void close_prefwnd( BYTE cmd )
340 if(Wnd != NULL)
342 if( Menu ) ClearMenuStrip(Wnd);
343 CloseWindow(Wnd);
344 prefsigbit=0; Wnd=NULL;
346 if(pgads) {
347 /* Flush content of some gadget that may not be confirmed */
348 prefs.tabsize = atoi(GetSI(gads[0])->Buffer);
349 CopyMem(GetSI(gads[1])->Buffer, prefs.wordssep, MAX_SPLIT);
351 FreeGadgets(pgads); pgads=NULL;
354 if(Menu) FreeMenus(Menu),Menu=NULL;
356 /* Do we need to send modifications to JANO? */
357 if( cmd && !ConfigFile ) send_jano(&prefs, cmd);
360 /*** Handle messages coming from gadgets ***/
361 BYTE handle_pref_gadget(struct Gadget *G)
363 struct TextFont *newfont;
364 static UBYTE useit[]={1,2,0,1};
365 LONG Code;
367 switch( G->GadgetID )
369 case 0: /* Check tabulation: */
370 check_tab( G );
371 break;
372 case 2: /* Changing default text font: */
374 Code = msgbuf.Code; if(extended & 1) Code--;
375 if(Code <= 0)
377 if( !(prefs.use_txtfont = (Code==-1)) )
378 /* User want to use the default text font: */
379 text_to_attr(prefs.txtfont=GfxBase->DefaultFont, &prefs.attrtxt);
380 else
381 if((newfont = get_old_font(FTCycTxt[0])))
382 text_to_attr(prefs.txtfont=newfont, &prefs.attrtxt);
383 else { ThrowError(Wnd, ErrMsg(ERR_LOADFONT)); break; }
384 render_sample(Wnd, EDIT_AREA);
385 break;
386 } else
387 /* User want to change the text font: */
388 if((newfont = change_fonts(&prefs.attrtxt, Wnd, TRUE)))
390 if( prefs.txtfont ) CloseFont(prefs.txtfont);
391 font_info(StrInfo, prefs.txtfont = newfont );
392 TextFontTags[0].ti_Data = (IPTR) FTCycTxt; extended |= 1;
393 prefs.use_txtfont = TRUE;
394 TextFontTags[1].ti_Data = 0;
395 } /* else we must reset the original cycle gadget entry */
396 GT_SetGadgetAttrsA(G, Wnd, NULL, TextFontTags);
397 render_sample(Wnd, EDIT_AREA);
398 break;
399 case 3: /* Changing default screen font */
401 Code = msgbuf.Code; if(extended & 2) Code--;
402 if(Code <= 0)
404 if( !(prefs.use_scrfont = (Code==-1)) )
405 /* User want to use default screen font */
406 text_to_attr(prefs.scrfont=prefs.parent->RastPort.Font, &prefs.attrscr);
407 else
408 if((newfont = get_old_font(FSCycTxt[0])))
409 text_to_attr(prefs.scrfont=newfont, &prefs.attrscr);
410 else { ThrowError(Wnd, ErrMsg(ERR_LOADFONT)); break; }
412 render_sample(Wnd, EDIT_ALL);
413 break;
414 } else
415 /* User want to change the screen font */
416 if((newfont = change_fonts(&prefs.attrscr, Wnd, FALSE)))
418 if( prefs.scrfont ) CloseFont(prefs.scrfont);
419 font_info(StrInfo+20, prefs.scrfont = newfont );
420 ScrFontTags[0].ti_Data = (IPTR) FSCycTxt; extended |= 2;
421 prefs.use_scrfont = TRUE;
422 ScrFontTags[1].ti_Data = 0;
424 GT_SetGadgetAttrsA(G, Wnd, NULL, ScrFontTags);
425 render_sample(Wnd, EDIT_ALL);
426 break;
427 case 4: /* Change screen mode/type */
429 Code = msgbuf.Code; if(extended & 4) Code--;
430 if(Code <= 1)
431 prefs.use_pub = useit[Code+1];
432 else
434 /* User want to use a pubscreen instead of workbench screen: */
435 if((Code = change_screen_mode(wid, prefs.modeid)) != INVALID_ID)
437 prefs.depth = wid[2];
438 prefs.modeid = Code;
439 ScrMdTags[0].ti_Data = (IPTR) ScrCycTxt;
440 ScrMdTags[1].ti_Data = 0;
441 scr_info(StrInfo+40, wid[0], wid[1], wid[2]);
442 prefs.use_pub = TRUE; extended |= 4;
443 } else ScrMdTags[1].ti_Data = useit[ prefs.use_pub+1 ];
444 GT_SetGadgetAttrsA(G, Wnd, NULL, ScrMdTags);
446 /* If user want to use a pubscreen, then disable backdrop checkbox **
447 ** It is not recommended to use a backdrop'ed window on a such scr */
448 if( prefs.use_pub )
449 OnGadget (gads[CGS], Wnd, NULL);
450 else
451 OffGadget (gads[CGS], Wnd, NULL);
452 break;
453 case CGS: case CGS+1: /* Checkbuttons */
454 case CGS+2: case CGS+3:
455 (&prefs.backdrop)[G->GadgetID-CGS] = ((G->Flags & GFLG_SELECTED) == GFLG_SELECTED);
456 break;
457 case UCS: /* Save */
458 close_prefwnd(CMD_SAVPREF);
459 if(ConfigFile) save_prefs(&prefs);
460 return TRUE;
461 case UCS+1: /* Use */
462 close_prefwnd(CMD_NEWPREF); return TRUE;
463 case UCS+2: /* Cancel */
464 close_prefwnd(0); return TRUE;
465 case UCS+3: /* Cycle color */
466 ColorIndex = msgbuf.Code; break;
467 case UCS+4: /* Palette */
468 if((&pen.bg)[ ColorIndex ] != msgbuf.Code)
470 (&pen.bg)[ColorIndex] = msgbuf.Code;
471 (&prefs.pen.bg)[ColorIndex] = -msgbuf.Code - 1;
473 render_sample(Wnd, Modif[ColorIndex] );
476 /* Returns TRUE if window is closed */
477 return FALSE;
480 /*** Keyboard shorcut ***/
481 BYTE handle_pref_kbd( UBYTE Key )
483 switch( Key )
485 case '\t':
486 case 't':
487 case 'T':
488 GetSI(gads[0])->BufferPos = GetSI(gads[0])->MaxChars;
489 ActivateGadget(gads[0], Wnd, NULL); break;
490 case 27: close_prefwnd(0); return TRUE;
491 case 13:
492 case 'u':
493 case 'U': close_prefwnd(CMD_NEWPREF); return TRUE;
494 case 's':
495 case 'S':
496 close_prefwnd(CMD_SAVPREF);
497 if(ConfigFile) save_prefs(&prefs);
498 return TRUE;
499 case 127:
500 if(Wnd->Height > Wnd->BorderTop)
501 ZipWindow(Wnd);
503 return FALSE;
506 /*** Handle newmenu events ***/
507 BYTE handle_pref_menu( ULONG MenuID )
509 switch( MenuID )
511 case 101: load_pref(&prefs); break; /* Load */
512 case 102: save_pref_as(&prefs); break; /* Save as */
513 case 103: close_prefwnd(0); return TRUE;
514 case 201: default_prefs(&prefs); break; /* Default prefs */
515 case 202: restore_config(&prefs); break; /* Last saved */
517 return FALSE;
520 /*** Handle events coming from pref window ***/
521 void handle_pref( void )
523 /* Collect messages posted to the window port: */
524 while(( msg=GT_GetIMsg(Wnd->UserPort) ))
526 /* Copy the entire message into the buffer: */
527 CopyMem(msg, &msgbuf, sizeof(msgbuf));
528 GT_ReplyIMsg( msg );
530 switch( msgbuf.Class )
532 case IDCMP_CLOSEWINDOW: close_prefwnd(CMD_NEWPREF); return;
533 case IDCMP_INTUITICKS:
534 /* An error message which needs to be removed? */
535 if(err_time == 0) err_time = msgbuf.Seconds;
536 if(err_time && msgbuf.Seconds-err_time>4) StopError(Wnd);
537 break;
538 case IDCMP_VANILLAKEY:
539 if( handle_pref_kbd( msgbuf.Code ) ) return;
540 else break;
541 case IDCMP_MENUPICK:
543 struct MenuItem *item = ItemAddress(Menu,msgbuf.Code);
545 if (item)
547 if( handle_pref_menu((IPTR)GTMENUITEM_USERDATA(item))) return;
549 break;
551 case IDCMP_GADGETUP:
552 if( handle_pref_gadget( (struct Gadget *) msgbuf.IAddress) ) return;
553 else break;
554 case IDCMP_NEWSIZE:
555 if( Wnd->Height > SAMPLE_HEI ) render_sample(Wnd, EDIT_ALL);
560 #ifdef DEBUG
561 ULONG amem, bmem;
562 #endif
564 void free_locale(void);
566 /*** Handle events coming from main window: ***/
567 void cleanup(UBYTE *msg, int errcode)
569 free_locale();
570 close_port();
571 free_sample();
572 free_asl();
574 if(Vi) FreeVisualInfo(Vi);
575 if(DiskfontBase) CloseLibrary(DiskfontBase);
576 if(LocaleBase) CloseLibrary(LocaleBase);
577 if(AslBase) CloseLibrary(AslBase);
578 if(GadToolsBase) CloseLibrary(GadToolsBase);
579 if(GfxBase) CloseLibrary((struct Library *)GfxBase);
580 if(IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
581 if(msg) puts(msg);
583 #ifdef DEBUG
584 /* Here can be compared good programs with the others :-) */
585 amem = AvailMem( MEMF_PUBLIC );
586 if(amem < bmem) printf("Possible memory lost of %d bytes\n", bmem-amem);
587 #endif
588 exit(errcode);
591 void prefs_local(void);
593 /*** MAIN LOOP ***/
594 int main(int argc, char *argv[])
596 ULONG sigwait, sigrcvd;
597 #ifdef DEBUG
598 bmem = AvailMem( MEMF_PUBLIC );
599 #endif
600 memset(&prefs,0,sizeof(prefs));
602 /* If preference tool is already running, just quits */
603 if( find_prefs() ) cleanup(0,0);
605 /* Optionnal libraries */
606 AslBase = (struct Library *) OpenLibrary("asl.library", 36);
607 LocaleBase = (struct Library *) OpenLibrary("locale.library", 38);
608 DiskfontBase = (struct Library *) OpenLibrary("diskfont.library", 0);
610 if(LocaleBase) prefs_local(); /* Localize the prog */
612 /* Open the required ROM libraries: */
613 if( (IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 36)) &&
614 (GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 36)) &&
615 (GadToolsBase = (struct Library *) OpenLibrary("gadtools.library", 36)) &&
616 (LayersBase = (struct Library *) OpenLibrary("layers.library", 36)) )
618 if( !(msgport = create_port()) ) cleanup(0, RETURN_FAIL);
620 /* User may want to "edit" a particular file */
621 if(argc > 1) {
622 if( load_prefs(&prefs, argv[1]) ) cleanup(ErrMsg(ERR_LOADFILE), RETURN_FAIL);
623 } else
624 if( find_jano(&prefs) ) ConfigFile = FALSE;
625 else load_prefs(&prefs, NULL);
627 save_config( ConfigFile );
628 if(ConfigFile) Scr = prefs.parent;
630 /* Init interface */
631 if( setup_guipref() )
633 sigwait = msgport | prefsigbit | SIGBREAKF_CTRL_C;
634 for( ;; )
636 sigrcvd = Wait( sigwait );
637 /* From where does the signal comes from? */
638 if(sigrcvd & SIGBREAKF_CTRL_C) break;
640 else if(sigrcvd & msgport) handle_port();
642 else handle_pref();
643 if(Wnd == NULL) break;
645 } else ThrowError(Wnd, ErrMsg(ERR_NOGUI));
646 } else ThrowError(Wnd, ErrMsg(ERR_BADOS));
647 cleanup(0,0);
649 return 0;