-
Notifications
You must be signed in to change notification settings - Fork 4
/
applik.c
1875 lines (1457 loc) · 43.7 KB
/
applik.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Teradesk. Copyright (c) 1993 - 2002 W. Klaren,
* 2002 - 2003 H. Robbers,
* 2003 - 2013 Dj. Vukovic
*
* This file is part of Teradesk.
*
* Teradesk is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Teradesk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Teradesk; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307 USA
*/
#include <library.h>
#include <xdialog.h>
#include <mintbind.h>
#include "resource.h"
#include "desk.h"
#include "error.h"
#include "startprg.h"
#include "xfilesys.h"
#include "file.h"
#include "events.h"
#include "config.h"
#include "prgtype.h"
#include "font.h"
#include "window.h"
#include "copy.h"
#include "dir.h"
#include "lists.h"
#include "slider.h"
#include "filetype.h"
#include "applik.h"
#include "open.h"
#include "va.h"
#include "icon.h"
APPLINFO awork; /* work area for editing */
APPLINFO *applikations; /* list of installed apps data */
_WORD naap; /* number of apps assigned to a filetype */
static char const defcml[] = "%f"; /* default command line for programs */
static SNAME prevcall; /* name of the last started ttp */
static bool nodocs = FALSE; /* to copy documenttypes when copying apps */
/*
* Find an application specified by its name among installed ones;
* Comparison is made upon full path+name, and an exact match is required,
* contrary to routine find_lsitem in lists.c which works upon the short name
* (part of the LSTYPE/FTYPE/ICONTYPE/PRGRYPE) and allows wildcards.
* Return NULL if appliaction not found.
* Name matching is NOT case sensitive.
*/
static LSTYPE *find_appl(LSTYPE **llist, const char *program, _WORD *pos)
{
APPLINFO **list = (APPLINFO **) llist;
APPLINFO *h = *list;
if (pos)
*pos = -1; /* allow NULL when position not needed */
if (program)
{
while (h)
{
if (pos)
(*pos)++;
if ((stricmp(program, h->name) == 0))
return (LSTYPE *) h;
h = h->next;
}
}
return NULL;
}
/*
* Remove an app definition, its command line and list of documentypes;
* This code operates in a way similar to general "lsrem" routine in
* lists.c, except that it deallocates name, commandline and documenttypes
* as well.
* Note: beware of recursive calls: lsrem_all-->rem_appl-->lsrem_all-->lsrem
*/
static void rem_appl(LSTYPE **llist, LSTYPE *item)
{
APPLINFO **list = (APPLINFO **) llist;
APPLINFO *appl = (APPLINFO *) item;
APPLINFO *f = *list; /* pointer to first, then current item in the list */
APPLINFO *prev = NULL; /* pointer to previous item in the list */
/* Search for a pointer match */
while (f && (f != appl))
{
prev = f;
f = f->next;
}
/* If match found, remove that item from the list */
if (f)
{
if (prev == NULL)
*list = f->next;
else
prev->next = f->next;
/* Deallocate strings pointed to from this structure */
free(f->name);
free(f->cmdline);
free(f->localenv);
/* Remove associated documenttypes */
lsrem_all_one((LSTYPE **) (&(f->filetypes))); /* deallocate list of documenttypes */
free(f);
}
}
/*
* Copy an application definition from one location to another;
* Space for both has to be already allocated (size of APPLINFO);
* for name, commandline, environment and documenttypes, memory is allocated.
* This routine actually copies the list of associated filetypes,
* as well as the other strings (i.e. it doesn't just copy pointers).
* If 'nodocs' is true, documenttypes, command line and environment
* are not copied.
* Note: NULL pointers are checked for in strdup() and returned
*/
static void copy_app(LSTYPE *lt, LSTYPE *ls)
{
APPLINFO *t = (APPLINFO *) lt;
APPLINFO *s = (APPLINFO *) ls;
copy_prgtype((LSTYPE *) t, (LSTYPE *) s);
t->name = strdup(s->name);
t->fkey = s->fkey;
t->cmdline = NULL;
t->localenv = NULL;
t->filetypes = NULL;
if (nodocs)
return;
/* Note: If lsadd() fails, cmdline and localenv will remain orphaned */
if (t->name)
{
t->cmdline = strdup(s->cmdline);
t->localenv = strdup(s->localenv);
copy_all((LSTYPE **) (&(t->filetypes)), (LSTYPE **) (&(s->filetypes)), sizeof(FTYPE), copy_ftype);
}
}
/*
* Find (or create!) information about an application in a list;
* input: filename
* output: APPLINFO data structure
* if filetype has not been defined, default values are set
*/
static void appinfo_info(LSTYPE **llist, /* list of installed apps */
const char *name, /* full name for shich to search */
_WORD dummy, /* currently not used */
LSTYPE *work /* output information */
)
{
APPLINFO **list = (APPLINFO **) llist;
APPLINFO *appl = (APPLINFO *) work;
APPLINFO *a;
(void) dummy;
/* Is this application already installed ? */
a = (APPLINFO *) find_appl((LSTYPE **) list, name, NULL); /* HR 120803 allow NULL when pos not needed */
if (a)
{
/* Yes, use its data */
copy_app((LSTYPE *) appl, (LSTYPE *) a);
} else
{
/*
* Not found, set default program type according to name.
* This routine also initiates the value of ->flags
*/
prg_info((LSTYPE **) & prgtypes, name, 0, (LSTYPE *) appl);
/* Pass the name, if given; otherwise set an empty string */
appl->name = strdup((name) ? name : empty);
/*
* Create default command line and environment;
* set no documenttypes and F-key
*/
appl->cmdline = strdup(defcml);
appl->localenv = strdup(empty);
appl->filetypes = NULL;
appl->fkey = 0;
appl->flags &=
~(AT_EDIT | AT_AUTO | AT_SHUT | AT_VIDE | AT_SRCH | AT_FFMT | AT_VIEW | AT_COMP | AT_CONS | AT_RBXT);
}
}
/*
* Check duplicate application assignment; this routine differs
* from check_dup in lists.c in that the full app path+name is compared.
*/
static bool check_dup_app(APPLINFO **list, APPLINFO *appl, _WORD pos)
{
APPLINFO *f = *list; /* pointer to current item in the list */
_WORD i = 0; /* item counter */
while (f)
{
if (i != pos)
{
if (strcmp(f->name, appl->name) == 0)
{
alert_printf(1, AFILEDEF, f->shname);
return FALSE;
}
}
i++;
f = f->next;
}
return TRUE;
}
/*
* Put into dialog field the F-key assigned to application
*/
static void set_fkey(_WORD fkey)
{
char *applfkey = applikation[APFKEY].ob_spec.tedinfo->te_ptext;
if (fkey) /* assigned */
itoa(fkey, applfkey, 10); /* convert integer to string */
else
*applfkey = 0; /* empty string */
}
/*
* Reset F-key "fkey" assigned to any of the installed applications
*/
static void unset_fkey(APPLINFO **list, _WORD fkey)
{
APPLINFO *f = *list;
while (f)
{
if (f->fkey == fkey)
f->fkey = 0;
f = f->next;
}
}
/*
* Check if a function key has already been assigned to another application.
* Return TRUE if it is OK to set F-key now
*/
static bool check_fkey(APPLINFO **list, _WORD fkey, _WORD pos)
{
APPLINFO *f = *list; /* pointer to current item in the list */
_WORD i; /* item counter */
if (fkey != 0)
{
i = 0;
while (f)
{
if ((i != pos) && (f->fkey == fkey))
{
/* Some other app is associated with this key */
if (alert_printf(2, ADUPFLG, f->shname) == 1)
return TRUE;
else
return FALSE;
}
i++;
f = f->next;
}
}
return TRUE;
}
/*
* Check if a special application is already marked with "flag" at a position
* other than "pos". If it is, an alert appears asking for confirmation
* to change the settings.
* Use pos=-1 to check if it is marked at all (no alert appears then).
* Return FALSE if an application is already marked.
* Return TRUE if it is OK to mark an application with this flag.
* Note: bit flags can be combined.
*/
static bool check_specapp(APPLINFO **list, _WORD flag, _WORD pos)
{
APPLINFO *f = *list;
_WORD button = 0, i = 0;
while (f)
{
if ((i != pos) && ((f->flags & flag) != 0))
{
if (pos != -1)
button = alert_printf(2, ADUPFLG, f->shname);
if (button != 1)
return FALSE;
}
i++;
f = f->next;
}
return TRUE;
}
/*
* Reset special-app flags specified in "flags"
* for all applications in the list
*/
static void unset_specapp(APPLINFO **list, _WORD flags)
{
APPLINFO *app = *list;
while (app)
{
app->flags &= ~flags;
app = app->next;
}
}
/*
* Update information about an installed application
*/
void app_update(wd_upd_type type, const char *fname1, const char *fname2)
{
APPLINFO *info;
if ((info = (APPLINFO *) find_appl((LSTYPE **) & applikations, fname1, NULL)) != NULL) /* allow NULL when pos not needed */
{
if (type == WD_UPD_DELETED)
rem_appl((LSTYPE **) & applikations, (LSTYPE *) info);
if (type == WD_UPD_MOVED)
{
char *h = strdup(fname2);
if (h)
{
free(info->name);
info->name = h;
}
}
}
}
/*
* Create a "short" name of an application; it will be used for informational
* purposes in dialogs opened to edit documenttypes and application type, and
* in some alerts. "dest" must be allocated beforehand and be at least a SNAME
*/
void log_shortname(char *dest, const char *appname)
{
*dest = 0;
if (appname)
#if _MINT_
cramped_name(fn_get_name(appname), dest, sizeof(SNAME));
#else
strcpy(dest, fn_get_name(appname)); /* safe in single-TOS */
#endif
}
/*
* app_dialog: edit setup of a single application.
* Edited data is manipulated and returned in *appl;
* if operation is canceled, entry values in *appl should be unchanged;
* **applist serves for checking against duplicates, etc.
*/
static bool app_dialog(LSTYPE **llist, /* list to check for duplicates in */
_WORD pos, /* position of item in the list */
LSTYPE *item, /* edited data */
_WORD use /* use of this dialog (add/edit) */
)
{
APPLINFO **applist = (APPLINFO **) llist;
APPLINFO *appl = (APPLINFO *) item;
XDINFO info; /* info structure for the dialog */
FTYPE *list; /* working copy of the list of filetypes */
FTYPE*newlist; /* first same at list, then maybe changed in ft_dialog */
VLNAME thisname; /* name of the current application */
VLNAME thispath; /* path of the current application */
char *newenv; /* pointer to the changed text */
char *newcmd; /* pointer to the changed text */
char *newpath; /* pointer to the changed text */
_WORD i; /* local counter */
_WORD startob; /* start object for editing */
_WORD title; /* rsc index of dialog title string */
_WORD button; /* code of pressed button */
_WORD button2; /* for a subdialog */
_WORD fkey; /* code of associated F-key */
bool status = FALSE;
bool qquit = FALSE; /* true when ok to exit loop */
static const char ord[] = { ISEDIT, ISAUTO, ISSHUT, ISVIDE, ISSRCH, ISFRMT, ISVIEW, ISCOMP, ISRBXT };
list = NULL;
newenv = NULL;
newcmd = NULL;
newpath = NULL;
*thispath = 0;
*thisname = 0;
/*
* Set dialog title(s); create copy of filetypes list if needed
* i.e. if application setup is edited, copy list of filetypes to temporary;
* If application is added, there is nothing to copy
*/
if (use & LS_EDIT)
{
title = DTEDTAPP;
startob = APCMLINE;
copy_all((LSTYPE **) (&list), (LSTYPE **) (&appl->filetypes), sizeof(FTYPE), copy_ftype);
} else
{
title = (use & LS_WSEL) ? DTINSAPP : DTADDAPP; /* Install or edit - set title */
startob = APPATH;
list = appl->filetypes;
}
newlist = list;
rsc_title(applikation, APDTITLE, title);
/*
* Copy application name, path, command line and environment to dialog fields;
* as application name is stored as path+name it has to be split-up
* in order to display path separately
*/
if (*(appl->name))
{
int error = x_checkname(appl->name, NULL);
xform_error(error);
if (!error)
split_path(thispath, thisname, appl->name);
}
cv_fntoform(applikation, APNAME, thisname); /* xd_init_shift() inside */
cv_fntoform(applikation, APPATH, thispath);
strsncpy(envline, appl->localenv, sizeof(VLNAME));
xd_init_shift(&applikation[APLENV], envline);
strsncpy(cmdline, appl->cmdline, sizeof(VLNAME));
xd_init_shift(&applikation[APCMLINE], cmdline);
/* Display alerts if strings were too long */
if (strlen(appl->cmdline) > XD_MAX_SCRLED || (strlen(appl->localenv) > XD_MAX_SCRLED))
alert_iprint(TCMDTLNG);
/* Put F-key value, if any, into the dialog */
set_fkey(appl->fkey);
/* Open the dialog for editing application setup */
if (chk_xd_open(applikation, &info) >= 0)
{
while (!qquit)
{
/* Get button code */
button = xd_form_do(&info, startob);
/* Get new application path and name from the dialog */
cv_formtofn(thispath, applikation, APPATH);
cv_formtofn(thisname, applikation, APNAME);
/* Create "short" name of this application */
log_shortname(appl->shname, thisname);
/* Do something appropriate for the button pressed */
switch (button)
{
case SETUSE:
/*
* Set special use of this application;
* Adjust limit value of i in two loops below
* to be equal to number of checkboxes in the
* 'Special Use' dialog (currently 8).
* Dimension of ord[] above must be changed appropriately.
*/
for (i = 0; i < 9; i++)
set_opt(specapp, appl->flags, AT_EDIT << i, ord[i]);
button2 = chk_xd_dialog(specapp, ROOT);
if (button2 == SPECOK)
{
for (i = 0; i < 9; i++)
get_opt(specapp, &(appl->flags), AT_EDIT << i, (_WORD) ord[i]);
}
break;
case APPFTYPE:
/*
* Set associated document types;
* must recreate dialog title afterwards because the same
* dialog is used
*/
ft_dialog((const char *) (appl->shname), &newlist, (LS_DOCT | (use & LS_SELA)));
rsc_title(setmask, DTSMASK, title);
break;
case APPPTYPE:
/*
* Define application execution parameters (program type)
* note: default values have already been set
*/
prgtype_dialog(NULL, SHRT_MAX, (LSTYPE *) appl, LS_APPL | LS_EDIT);
break;
case APOK:
/*
* Changes are accepted, do everything needed to exit dialog
* First, check for duplicate app installation
*/
if (!check_dup_app(applist, appl, pos))
break;
/* Then, check for duplicate F-key assignment */
fkey = atoi(applikation[APFKEY].ob_spec.tedinfo->te_ptext);
if (!check_fkey(applist, fkey, pos))
break;
/* Check for duplicate spec. application assignment */
if (!check_specapp
(applist, (appl->flags & (AT_EDIT | AT_SRCH | AT_FFMT | AT_VIEW | AT_COMP | AT_CONS | AT_RBXT)),
pos))
break;
/*
* Build full application name again,
* because it might have been changed by editing.
* Use "thispath" and "thisname" as they are not needed anymore.
* Note that actual file is NOT renamed, just
* the entry in the applications list, but a check is made
* if a file with the new name exists (it must exist)
*/
if (*thispath == 0 || *thisname == 0)
{
alert_iprint(MFNEMPTY); /* can not be empty! */
break;
}
if (make_path(thispath, thispath, thisname) != 0)
{
alert_iprint(TPTHTLNG);
break;
}
/* Does this application file exist at all ? */
if (!x_exist(thispath, EX_FILE))
{
alert_printf(1, APRGNFND, appl->shname);
break;
}
/*
* If application path+name have been changed,
* allocate a new one
*/
if (strcmp(thispath, appl->name) != 0)
{
if ((newpath = strdup(thispath)) != NULL)
{
free(appl->name);
appl->name = newpath;
} else
{
goto exit2;
}
}
/*
* If command line string has been changed (only then),
* allocate a new one
*/
if ((strcmp(cmdline, appl->cmdline) != 0))
{
if ((newcmd = strdup(cmdline)) != NULL)
{
free(appl->cmdline);
appl->cmdline = newcmd;
} else
{
goto exit2;
}
}
/* Same for local environment */
strip_name(envline, envline);
if ((strcmp(envline, appl->localenv) != 0))
{
if ((newenv = strdup(envline)) != NULL)
{
free(appl->localenv);
appl->localenv = newenv;
} else
{
goto exit2;
}
}
/*
* How about documenttypes? If there has been a change in
* address, point to new list, clear old one; otherwise
* clear the copy. Note: currently there is no check
* whether the same documenttype has been assigned to another
* application, it is only checked (in ft_dialog) whether
* there are duplicate documenttypes set for this application.
* Anyway, it is possible to assign one documenttype to
* several applications.
*/
if (newlist != list)
{
/*
* There have been changes in ft_dialog
* (known because list address has changed)
* remove original list, accept newlist, the
* one pointed to by "list" has been destroyed
* in ft_dialog
*/
lsrem_all_one((LSTYPE **) (&appl->filetypes));
appl->filetypes = newlist;
} else
{
/* there has been no changes, destroy copy of list */
lsrem_all_one((LSTYPE **) (&list));
}
/* Set also the f-key. (remove all other assignments of this key) */
unset_fkey(applist, fkey);
appl->fkey = fkey;
/* Reset special app flags from other applications */
unset_specapp(applist,
(appl->
flags & (AT_EDIT | AT_SRCH | AT_FFMT | AT_VIEW | AT_COMP | AT_CONS | AT_RBXT)));
qquit = TRUE;
status = TRUE;
break;
default:
exit2:
/* Anything else, like exit without OK */
/* Copy of documenttype list has to be destroyed */
lsrem_all_one((LSTYPE **) (&newlist));
qquit = TRUE;
break;
}
/* Set all buttons to normal state */
xd_change(&info, button, OS_NORMAL, qquit == FALSE ? 1 : 0);
}
/* Close the dialog and exit */
xd_close(&info);
}
return status;
}
/*
* Use these list-specific functions to manipulate applications lists:
*/
static LS_FUNC aplist_func = {
copy_app, /* lscopy */
rem_appl, /* lsrem */
appinfo_info, /* lsitem */
find_appl, /* lsfinditem */
app_dialog /* ls_dialog */
};
/*
* Handle installing, editing, selecting and removing applications.
* If "Install Applicaton" menu is selected without any program file being
* selected in a dir window, a dialog is shown with a list of installed
* applications, and options to add, remove or edit them, for which
* another dialog is opened.
* If installation is to be done upon an applicaton selected in a dir window,
* a dialog opens for directly setting application parameters.
*/
void app_install(_WORD use, APPLINFO **applist)
{
_WORD title, theuse = use | LS_APPL;
/* Set dialog title */
if (use & LS_SELA)
{
title = DTSELAPP;
rsc_title(setmask, FTTEXT, TAPP);
setmask[FILETYPE].ob_flags &= ~(OF_EDITABLE | OF_HIDETREE);
obj_unhide(setmask[FTTEXT]);
if (selitem)
cv_fntoform(setmask, FILETYPE, (*applist)->shname);
else
*(setmask[FILETYPE].ob_spec.tedinfo->te_ptext) = 0;
} else
{
title = DTINSAPP;
}
rsc_title(setmask, DTSMASK, title);
/*
* Edit applications list: add/delete/change...
* Accepting or canceling changes is handled within list_edit,
* so there is nothing to do after that
*/
list_edit(&aplist_func, (LSTYPE **) applist, 1, sizeof(APPLINFO), (LSTYPE *) & awork, theuse);
rsc_title(setmask, FTTEXT, TAPP);
obj_hide(setmask[FILETYPE]);
obj_hide(setmask[FTTEXT]);
}
/*
* Find installed application which is specified for "file" filetype.
* Return pointer to information block for that app.
* If more than one application us specified for the filetype,
* the listbox dialog is opened so that the application can be selected.
*/
APPLINFO *app_find(const char *file, bool dial)
{
APPLINFO *h = applikations, *d = NULL; /* temporary list of assigned apps */
FTYPE *t; /* list of documenttypes */
naap = 0; /* number of assigned apps */
selitem = NULL; /* nothing found yet */
nodocs = TRUE; /* do not copy documenttypes */
/* Find all applications associated with this filetype; form a list */
while (h)
{
t = h->filetypes;
while (t)
{
/*
* Match name pattern; for network objects allow only
* applications assigned for network objects
* Or better not. It would reduce flexibility!
*/
if (cmp_wildcard(file, t->filetype) /* && (!x_netob(file) || x_netob(t->filetype)) */ )
{
if (lsadd_end((LSTYPE **) & d, sizeof(awork), (LSTYPE *) h, copy_app) == NULL)
goto nomore;
naap++;
break; /* stop scanning documenttypes for this app */
}
t = t->next;
}
h = h->next;
}
nomore:;
selitem = (LSTYPE *) d;
/* If more than one app found, open the dialog, but disable editing */
if (naap > 1 && dial)
{
obj_disable(setmask[FTADD]);
obj_disable(setmask[FTDELETE]);
obj_disable(setmask[FTCHANGE]);
app_install(LS_SELA, &d); /* returns pointer to selected app in selitem */
obj_enable(setmask[FTADD]);
obj_enable(setmask[FTDELETE]);
obj_enable(setmask[FTCHANGE]);
}
/* Now find (by name) the selected application in the original list */
if (selitem)
selitem = find_appl((LSTYPE **) & applikations, ((APPLINFO *) selitem)->name, NULL);
/* Remove temporary list of applications */
lsrem_all((LSTYPE **) & d, rem_appl);
nodocs = FALSE;
return (APPLINFO *) selitem;
}
/*
* Find the (short) name of the first application associated with a filename
*/
char *app_find_name(const char *fname, bool full)
{
APPLINFO *theapp;
theapp = app_find(fname, (full) ? TRUE : FALSE);
if (theapp)
return full ? theapp->name : theapp->shname;
return NULL;
}
/*
* Find installed application for which is specified the "fkey" function key;
* Return pointer to information block for that app
*/
APPLINFO *find_fkey(_WORD fkey)
{
APPLINFO *h = applikations;
while (h)
{
if (h->fkey == fkey)
return h;
h = h->next;
}
return NULL;
}
/*
* Copy a command line to another destination (allocate space) and
* change all quotes to the specified character. Actual command is copied
* to index #1 of destination; location #0 is a placeholder
* for commandline length.
* Note: 3 bytes are added in strlenq()
*/
static char *requote_cmd(const char *cmd)
{
char *fb;
char *q = malloc_chk(strlenq(cmd));
if (q)
{
*q = '*';
strcpyrq(q + 1, cmd, '"', &fb);
}
return q;
}
/*
* Build a command line from the format string and the selected objects.
* Commad line variables understood: %f (fullname), %n (name), %p (path)
* Return pointer to an allocated space containing the complete command line,
* including length placeholder in the first byte. Arguments in this
* command line are separated by blanks.
* Note: parameter 'sellist' is locally modified.
*/
static char *app_build_cml(const char *format, /* (Template for) the command lint */
WINDOW *w, /* Window where the selection is made */
_WORD *sellist, /* List of selected items */
_WORD n /* Number of selected items */
)
{
char *d; /* pointer to a position in 'build' */
char *build; /* buffer for building the command name */
char *realname; /* name to be used- either item name or link target */
char *qformat; /* requoted command line */
char h; /* pointer to a character in command format */
char hh; /* lowercase of the above */
char *tmp = NULL; /* pointer to a temporary storage */
_WORD i; /* item counter */
_WORD error; /* anything */
_WORD mes; /* message identification */
build = NULL;
realname = NULL;
error = -1;
/* Convert any quotes in the command line to double quotes */
if ((qformat = requote_cmd(format)) != NULL)
{
const char *c = qformat; /* pointer to a position in qformat */
size_t ml; /* needed buffer length for the command line */