minor update. use vfork instead of fork. return the AROS PAGE_SIZE instead of getpage...
[AROS-Contrib.git] / dopus / Config / main7.c
blobcf42d7228b65cde9c9a21a63cdf9b28d69ac5285
1 /*
3 Directory Opus 4
4 Original GPL release version 4.12
5 Copyright 1993-2000 Jonathan Potter
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 All users of Directory Opus 4 (including versions distributed
22 under the GPL) are entitled to upgrade to the latest version of
23 Directory Opus version 5 at a reduced price. Please see
24 http://www.gpsoft.com.au for more information.
26 The release of Directory Opus 4 under the GPL in NO WAY affects
27 the existing commercial status of Directory Opus 5.
31 #include "config.h"
33 struct Gadget busygadget={
34 NULL,
35 0,0,0,0,
36 GFLG_GADGHNONE,0,GTYP_BOOLGADGET,
37 NULL,NULL,NULL,0,NULL,0,NULL};
38 static int oldidcmp,busyflag;
40 void busy()
42 if (!busyflag) {
43 busygadget.TopEdge=Window->BorderTop;
44 busygadget.LeftEdge=Window->BorderLeft;
45 busygadget.Width=Window->Width-Window->BorderLeft-Window->BorderRight;
46 busygadget.Height=Window->Height-Window->BorderTop-Window->BorderBottom;
47 AddGList(Window,&busygadget,0,1,NULL);
48 oldidcmp=Window->IDCMPFlags;
49 ModifyIDCMP(Window,IDCMP_CLOSEWINDOW);
50 Window->Flags|=WFLG_RMBTRAP;
51 SetBusyPointer(Window);
52 busyflag=1;
56 void unbusy()
58 if (busyflag) {
59 RemoveGList(Window,&busygadget,1);
60 ModifyIDCMP(Window,oldidcmp);
61 Window->Flags&=~WFLG_RMBTRAP;
62 ClearPointer(Window);
63 busyflag=0;
67 void dosave(new)
68 int new;
70 char buf[80];
72 busy();
73 if (new) {
74 trysave:
75 makefilebuffer(configname);
76 filereq.flags=DFRF_SAVE;
77 filereq.title=cfg_string[STR_ENTER_CONFIGURATION_FILENAME];
78 filereq.window=Window;
79 if (!(FileRequest(&filereq))) {
80 unbusy();
81 return;
83 strcpy(configname,dirbuf);
84 TackOn(configname,filebuf,256);
85 if (!(stricmp(configname,"DirectoryOpus.DefCFG"))) if (!(strstri(configname,".CFG"))) StrConcat(configname,".CFG",256);
87 fixcstuff(&cstuff);
88 if (!SaveConfig(configname,&cstuff)) {
89 lsprintf(buf,cfg_string[STR_SAVE_FAILED],IoErr());
90 if (request(buf)) goto trysave;
92 else lchanged=changed=0;
93 unbusy();
96 doload(type,def)
97 int type,def;
99 char *path,buf[80],*menulist[6],menuarray[6],**ftypelist,*typearray;
100 struct DOpusRemember *fkey;
101 struct ConfigStuff *newcstuff;
102 struct dopusgadgetbanks *bank,*bank2,*nbank;
103 struct dopusfiletype *ftype,*ntype;
104 struct dopushotkey *fhotkey,*nhotkey,*curhotkey;
105 int a,b,c,freecon=0,ret,m1,m2;
107 busy();
108 fkey=NULL;
109 if (def) {
110 tryload:
111 if (type==CFG_MAINMENU) path=configname;
112 else path=loadnamebuf;
113 makefilebuffer(path);
114 filereq.flags=0;
115 filereq.title=cfg_string[STR_SELECT_CONFIGURATION_TO_LOAD];
116 filereq.window=Window;
117 if (!(FileRequest(&filereq))) {
118 unbusy();
119 return(0);
121 strcpy(loadnamebuf,dirbuf);
122 TackOn(loadnamebuf,filebuf,256);
123 if (!(strstri(loadnamebuf,".CFG"))) StrConcat(loadnamebuf,".CFG",256);
125 if (!(newcstuff=AllocMem(sizeof(struct ConfigStuff),MEMF_CLEAR)) ||
126 !(newcstuff->config=AllocMem(sizeof(struct Config),MEMF_CLEAR))) {
127 if (newcstuff) FreeMem(newcstuff,sizeof(struct ConfigStuff));
128 unbusy();
129 return(0);
131 fixcstuff(&cstuff);
132 if (def) {
133 lchanged=changed=0;
134 SetBusyPointer(Window);
135 if ((a=ReadConfig(loadnamebuf,newcstuff))!=1) {
136 ClearPointer(Window);
137 if (a==ERROR_NOT_CONFIG) strcpy(buf,cfg_string[STR_FILE_NOT_VALID_CONFIGURATION]);
138 else lsprintf(buf,cfg_string[STR_OPEN_FAILED],a);
139 if (request(buf)) goto tryload;
141 else {
142 lchanged=1;
143 ClearPointer(Window);
144 CheckConfig(newcstuff);
147 else {
148 DefaultConfig(newcstuff);
149 lchanged=1;
151 if (lchanged) {
152 ret=1;
153 switch (type) {
154 case CFG_MAINMENU:
155 FreeConfig(&cstuff);
156 CopyMem((char *)newcstuff,(char *)&cstuff,sizeof(struct ConfigStuff));
157 cstuff.config=config;
158 CopyMem((char *)newcstuff->config,(char *)config,sizeof(struct Config));
159 strcpy(configname,loadnamebuf);
160 freecon=1;
161 break;
162 case CFG_OPERATION:
163 CopyMem((char *)&newcstuff->config->copyflags,(char *)&config->copyflags,
164 (offsetof(struct Config,dynamicflags)-offsetof(struct Config,copyflags))+1);
165 config->dateformat=newcstuff->config->dateformat;
166 config->formatflags=newcstuff->config->formatflags;
167 for (a=0;a<2;a++) {
168 config->sortmethod[a]=newcstuff->config->sortmethod[a];
169 config->separatemethod[a]=newcstuff->config->separatemethod[a];
170 CopyMem((char *)newcstuff->config->displaypos[a],(char *)config->displaypos[a],16);
171 CopyMem((UWORD *)newcstuff->config->displaylength[a],(UWORD *)config->displaylength[a],32);
173 freecon=3;
174 break;
175 case CFG_GADGET:
176 if (bank=firstbank) {
177 while (bank->next) bank=bank->next;
179 bank2=newcstuff->firstbank;
180 while (bank2) {
181 if (nbank=(struct dopusgadgetbanks *)
182 getcopy((char *)bank2,sizeof(struct dopusgadgetbanks),NULL)) {
183 nbank->next=NULL;
184 if (bank) bank->next=nbank;
185 else firstbank=nbank;
186 bank=nbank;
187 copygadgets(bank2,bank,NULL);
189 bank2=bank2->next;
191 cstuff.firstbank=firstbank;
192 freecon=3;
193 break;
194 case CFG_MENU:
195 freecon=3;
196 for (a=0;a<6;a++) {
197 menulist[a]=NULL;
198 menuarray[a]=0;
200 for (a=0,b=0;a<5;a++) {
201 if (newcstuff->config->menutit[a][0])
202 menulist[b++]=newcstuff->config->menutit[a];
204 if (!menulist[0] ||
205 !(dolistwindow(cfg_string[STR_SELECT_MENUS_TO_IMPORT],
206 332,40,menulist,DLVF_MULTI|DLVF_HIREC,menuarray,NULL))) {
207 ret=0;
208 break;
210 for (a=0,b=0;a<5;a++) {
211 m1=a*20; m2=(a+1)*20;
212 for (c=m1;c<m2;c++)
213 if (config->menu[c].name && config->menu[c].name[0]) break;
214 if (c==m2) {
215 while (!menuarray[b]) if ((++b)>4) break;
216 if (b>4) break;
217 for (c=m1;c<m2;c++) freenewfunction(&config->menu[c]);
218 CopyMem((char *)&newcstuff->config->menu[b*20],
219 (char *)&config->menu[m1],sizeof(struct dopusfunction)*20);
220 for (c=m1;c<m2;c++) {
221 config->menu[c].name=getcopy(config->menu[c].name,-1,NULL);
222 config->menu[c].function=getcopy(config->menu[c].function,-1,NULL);
224 strcpy(config->menutit[a],newcstuff->config->menutit[b]);
225 ++b;
228 if ((a == 5) && (menuarray[b])) ret=2;
229 break;
230 case CFG_DRIVE:
231 for (a=0;a<DRIVECOUNT;a++) freestring(config->drive[a].function);
232 CopyMem((char *)newcstuff->config->drive,(char *)config->drive,sizeof(struct dopusfunction)*DRIVECOUNT);
233 for (a=0;a<DRIVECOUNT;a++)
234 config->drive[a].function=getcopy(newcstuff->config->drive[a].function,-1,NULL);
235 freecon=3;
236 break;
237 case CFG_FILETYPE:
238 freecon=3;
239 b=0;
240 ftype=newcstuff->firsttype;
241 while (ftype) {
242 b++;
243 ftype=ftype->next;
245 if (!(ftypelist=LAllocRemember(&fkey,(b+1)*4,MEMF_CLEAR)) ||
246 !(typearray=LAllocRemember(&fkey,b+1,MEMF_CLEAR))) break;
247 ftype=newcstuff->firsttype;
248 for (a=0;a<b;a++) {
249 ftypelist[a]=ftype->type;
250 ftype=ftype->next;
252 if (!ftypelist[0] ||
253 !(dolistwindow(cfg_string[STR_SELECT_FILETYPES_TO_IMPORT],
254 332,72,ftypelist,DLVF_MULTI|DLVF_HIREC,typearray,NULL))) {
255 ret=0;
256 break;
258 ftype=newcstuff->firsttype; b=0;
259 while (ftype) {
260 if (typearray[b]) {
261 if (ntype=(struct dopusfiletype *)
262 getcopy((char *)ftype,sizeof(struct dopusfiletype),&typekey)) {
263 ntype->next=NULL;
264 ntype->recognition=getcopy(ftype->recognition,-1,&typekey);
265 ntype->iconpath=getcopy(ftype->iconpath,-1,&typekey);
266 for (a=0;a<FILETYPE_FUNCNUM;a++)
267 ntype->function[a]=getcopy(ftype->function[a],-1,&typekey);
268 addfiletype(ntype);
271 ftype=ftype->next; ++b;
273 cstuff.firsttype=firsttype;
274 break;
275 case CFG_HOTKEYS:
276 freecon=3;
277 b=0;
278 curhotkey=firsthotkey;
279 while (curhotkey && curhotkey->next) curhotkey=curhotkey->next;
280 fhotkey=newcstuff->firsthotkey;
281 while (fhotkey) {
282 b++;
283 fhotkey=fhotkey->next;
285 if (!(ftypelist=LAllocRemember(&fkey,(b+1)*4,MEMF_CLEAR)) ||
286 !(typearray=LAllocRemember(&fkey,b+1,MEMF_CLEAR))) break;
287 fhotkey=newcstuff->firsthotkey;
288 for (a=0;a<b;a++) {
289 ftypelist[a]=fhotkey->name;
290 fhotkey=fhotkey->next;
292 if (!ftypelist[0] ||
293 !(dolistwindow(cfg_string[STR_SELECT_HOTKEYS_TO_IMPORT],
294 332,72,ftypelist,DLVF_MULTI|DLVF_HIREC,typearray,NULL))) {
295 ret=0;
296 break;
298 fhotkey=newcstuff->firsthotkey; b=0;
299 while (fhotkey) {
300 if (typearray[b]) {
301 if (nhotkey=(struct dopushotkey *)
302 getcopy((char *)fhotkey,sizeof(struct dopushotkey),NULL)) {
303 nhotkey->next=NULL;
304 nhotkey->func.function=getcopy(fhotkey->func.function,-1,NULL);
305 if (curhotkey) curhotkey->next=nhotkey;
306 else firsthotkey=nhotkey;
307 curhotkey=nhotkey;
310 fhotkey=fhotkey->next; ++b;
312 cstuff.firsthotkey=firsthotkey;
313 break;
314 case CFG_SCREEN:
315 /*HUX CopyMem((char *)&newcstuff->config->gadgettopcol,
316 (char *)&config->gadgettopcol,
317 offsetof(struct Config,pad4)-offsetof(struct Config,gadgettopcol));*/
318 CopyMem(newcstuff->config->fontsizes,config->fontsizes,NUMFONTS);
319 CopyMem(newcstuff->config->fontbufs,config->fontbufs,NUMFONTS*40);
320 config->sliderbgcol=newcstuff->config->sliderbgcol;
321 config->stringfgcol=newcstuff->config->stringfgcol;
322 config->stringbgcol=newcstuff->config->stringbgcol;
323 config->sliderwidth=newcstuff->config->sliderwidth;
324 config->sliderheight=newcstuff->config->sliderheight;
325 config->stringheight=newcstuff->config->stringheight;
326 config->stringselfgcol=newcstuff->config->stringselfgcol;
327 config->stringselbgcol=newcstuff->config->stringselbgcol;
328 config->generalscreenflags=newcstuff->config->generalscreenflags;
329 CopyMem((char *)newcstuff->config->scrollborders,
330 (char *)config->scrollborders,sizeof(struct Rectangle)*2);
331 CopyMem((char *)newcstuff->config->new_palette,
332 (char *)config->new_palette,sizeof(ULONG)*48);
333 strcpy(config->pubscreen_name,newcstuff->config->pubscreen_name);
334 config->slider_pos=newcstuff->config->slider_pos;
335 freecon=3;
336 break;
337 case CFG_SYSTEM:
338 CopyMem((char *)newcstuff->config->outputcmd,(char *)config->outputcmd,
339 offsetof(struct Config,gadgetrows)-offsetof(struct Config,outputcmd));
340 CopyMem((char *)newcstuff->config->startupscript,(char *)config->startupscript,
341 offsetof(struct Config,pad8)-offsetof(struct Config,startupscript));
342 strcpy(config->uniconscript,newcstuff->config->uniconscript);
343 config->addiconflags=newcstuff->config->addiconflags;
344 strcpy(config->shellstartup,newcstuff->config->shellstartup);
345 strcpy(config->language,newcstuff->config->language);
346 config->loadexternal=newcstuff->config->loadexternal;
347 freecon=3;
348 break;
350 lchanged=changed=0;
352 else {
353 freecon=1;
354 ret=0;
356 if (freecon&2) FreeConfig(newcstuff);
357 if (freecon&1) FreeMem(newcstuff->config,sizeof(struct Config));
358 FreeMem(newcstuff,sizeof(struct ConfigStuff));
359 cstufffix(&cstuff);
360 LFreeRemember(&fkey);
361 unbusy();
362 return(ret);
365 void copyconfigonly(config1,config2)
366 struct Config *config1,*config2;
368 struct newdopusfunction *menubackup;
369 struct dopusfunction *drivebackup;
370 struct DOpusRemember *key;
372 key=NULL;
373 menubackup=(struct newdopusfunction *)
374 getcopy((char *)config2->menu,sizeof(struct dopusfunction)*MENUCOUNT,&key);
375 drivebackup=(struct dopusfunction *)
376 getcopy((char *)config2->drive,sizeof(struct dopusfunction)*DRIVECOUNT,&key);
377 CopyMem((char *)config1,(char *)config2,sizeof(struct Config));
378 if (menubackup) CopyMem((char *)menubackup,(char *)config2->menu,sizeof(struct newdopusfunction)*MENUCOUNT);
379 if (drivebackup) CopyMem((char *)drivebackup,(char *)config2->drive,sizeof(struct dopusfunction)*DRIVECOUNT);
380 LFreeRemember(&key);
383 dolistwindow(title,w,h,items,flags,selarray,item)
384 char *title;
385 int w,h;
386 char **items;
387 int flags;
388 char *selarray;
389 int *item;
391 struct Window *wind;
392 struct DOpusListView *view;
393 ULONG class;
394 UWORD code;
395 int a,gadgetid,all=1,count;
396 char **gadtxt;
398 listlist.w=w;
399 listlist.h=h;
401 if (selarray && flags&DLVF_MULTI) {
402 listokaygad[0].NextGadget=&listokaygad[2];
403 listokaygad[2].NextGadget=&listokaygad[1];
404 gadtxt=listviewgads2;
405 count=3;
407 else {
408 listokaygad[0].NextGadget=&listokaygad[1];
409 gadtxt=listviewgads;
410 count=2;
412 listokaygad[1].NextGadget=NULL;
414 setup_list_window(&requestwin,&listlist,listokaygad,count);
416 listlist.items=items;
417 listlist.selectarray=selarray;
418 listlist.flags=flags;
419 listlist.itemselected=-1;
420 setuplist(&listlist,-1,-1);
422 requestwin.Title=title;
424 if (!(wind=openwindow(&requestwin))) return(0);
426 listlist.window=wind;
427 if (!(AddListView(&listlist,1))) {
428 CloseWindow(wind);
429 return(0);
432 SetAPen(wind->RPort,screen_pens[1].pen);
433 AddGadgets(wind,
434 listokaygad,
435 gadtxt,
436 count,
437 screen_pens[config->gadgettopcol].pen,screen_pens[config->gadgetbotcol].pen,1);
438 busy();
440 FOREVER {
441 Wait(1<<wind->UserPort->mp_SigBit);
442 while (IMsg=(struct IntuiMessage *)GetMsg(wind->UserPort)) {
443 if ((view=ListViewIDCMP(&listlist,IMsg))==(struct DOpusListView *)-1) {
444 class=IMsg->Class; code=IMsg->Code;
445 if (class==IDCMP_GADGETUP || class==IDCMP_GADGETDOWN)
446 gadgetid=((struct Gadget *)IMsg->IAddress)->GadgetID;
447 ReplyMsg((struct Message *)IMsg);
448 if (class==IDCMP_VANILLAKEY) {
449 a=-1;
450 if (code=='\r') a=0;
451 else if (code=='\e') a=1;
452 if (a!=-1) {
453 SelectGadget(wind,&listokaygad[a]);
454 class=GADGETUP; gadgetid=1-a;
457 if (class==IDCMP_GADGETUP) {
458 if (gadgetid<2) {
459 unbusy();
460 RemoveListView(&listlist,1);
461 CloseWindow(wind);
462 return(gadgetid);
464 else if (gadgetid==2 && flags&DLVF_MULTI) {
465 for (a=0;a<listlist.count;a++) selarray[a]=all;
466 RefreshListView(&listlist,1);
467 all=1-all;
471 else if (view) {
472 if (flags&DLVF_MULTI)
473 selarray[view->itemselected]=1-selarray[view->itemselected];
474 else {
475 if (item) *item=view->itemselected;
476 if (!(flags&DLVF_LEAVE)) {
477 unbusy();
478 RemoveListView(&cmdlist,1);
479 CloseWindow(wind);
480 return(1);
488 void copytoclip(func,funclist,functype,flagsel)
489 struct dopusfunction *func;
490 char **funclist,*functype,*flagsel;
492 struct Clip *newclip,*pos;
494 busy();
495 if (newclip=LAllocRemember(&clipkey,sizeof(struct Clip),MEMF_CLEAR)) {
496 newclip->func.function=compilefunclist(funclist,functype,&clipkey);
497 newclip->func.which=getselflags(flagsel);
498 newclip->func.stack=atoi(edit_stackbuf);
499 newclip->func.pri=atoi(edit_prioritybuf);
500 newclip->func.delay=atoi(edit_delaybuf);
501 newclip->func.fpen=func->fpen;
502 newclip->func.bpen=func->bpen;
503 strcpy(newclip->name,edit_namebuf);
504 pos=firstclip;
505 while (pos && pos->next) pos=pos->next;
506 if (pos) pos->next=newclip;
507 else firstclip=newclip;
508 ++clipcount;
510 unbusy();
513 pasteclip(func,funclist,functype,displist,flagsel)
514 struct dopusfunction *func;
515 char **funclist,*functype,**displist,*flagsel;
517 char **cliplist;
518 struct DOpusRemember *key=NULL;
519 struct Clip *clip;
520 int a,b,ret=0;
522 if (!clipcount) return(0);
523 if (!(cliplist=LAllocRemember(&key,(clipcount+1)*4,MEMF_CLEAR))) return(0);
524 busy();
525 clip=firstclip;
526 for (a=0;a<clipcount;a++) {
527 if (!clip) break;
528 if (!(cliplist[a]=LAllocRemember(&key,40,MEMF_CLEAR))) break;
529 strcpy(cliplist[a],clip->name);
530 clip=clip->next;
532 cliplist[a]=NULL;
533 if (dolistwindow(cfg_string[STR_SELECT_FUNCTION_TO_PASTE],
534 212,40,cliplist,DLVF_LEAVE|DLVF_HIREC,NULL,&a)) {
535 clip=firstclip;
536 for (b=0;b<a;b++) if (!(clip=clip->next)) break;
537 if (clip) {
538 erasefunction(func,funclist,displist,flagsel);
539 lsprintf(edit_stackbuf,"%ld",clip->func.stack);
540 lsprintf(edit_prioritybuf,"%ld",clip->func.pri);
541 lsprintf(edit_delaybuf,"%ld",clip->func.delay);
542 strcpy(edit_namebuf,clip->name);
543 func->key=0; func->qual=0;
544 func->fpen=clip->func.fpen; func->bpen=clip->func.bpen;
545 makefunclist(clip->func.function,funclist,functype);
546 for (a=0;a<MAXFUNCS;a++) makedispfunc(funclist[a],functype[a],displist[a]);
547 makeselflags(clip->func.which,flagsel);
548 ret=1;
551 LFreeRemember(&key);
552 unbusy();
553 return(ret);
556 void makefilebuffer(buf)
557 char *buf;
559 char *ptr;
561 strcpy(dirbuf,buf);
562 ptr=BaseName(dirbuf);
563 if (ptr>dirbuf) {
564 strcpy(filebuf,ptr);
565 *ptr=0;
567 else if (CheckExist(dirbuf,NULL)<1) {
568 dirbuf[0]=0;
569 strcpy(filebuf,buf);
573 char *strstri(string,substring)
574 char *string,*substring;
576 int a,len,sublen;
578 len=(strlen(string)-(sublen=strlen(substring)))+1;
579 if (len<1) return(NULL);
581 for (a=0;a<len;a++) {
582 if (LStrnCmpI(&string[a],substring,sublen)==0)
583 return(string+a);
585 return(NULL);