-
Notifications
You must be signed in to change notification settings - Fork 0
/
support.c
1196 lines (914 loc) · 20.7 KB
/
support.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
/* Miscellaneous support functions
*
* Copyright ©1996-2008 pinc Software. All Rights Reserved.
* Licensed under the terms of the GNU General Public License, version 3.
*/
#include "types.h"
#include "funcs.h"
#include <stdarg.h>
void
Rect32ToRect(struct Rect32 *rect32, struct Rectangle *rect)
{
rect->MinX = max(rect32->MinX,0);
rect->MinY = max(rect32->MinY, 0);
rect->MaxX = min(rect32->MaxX, 32767);
rect->MaxY = min(rect32->MaxY, 32767);
}
void PUBLIC
FreeString(REG(a0, STRPTR t))
{
if (t)
FreePooled(pool, t, strlen(t) + 1);
}
STRPTR PUBLIC
AllocString(REG(a0, CONST_STRPTR source))
{
STRPTR t;
if (!source || !strlen(source))
return NULL;
if ((t = AllocPooled(pool, strlen(source) + 1)) != 0)
strcpy(t, source);
return t;
}
STRPTR PUBLIC
AllocStringLength(REG(a0, STRPTR source), REG(d0, long len))
{
STRPTR t;
if (!source || !strlen(source))
return NULL;
if ((t = AllocPooled(pool, len + 1)) != 0)
strncpy(t, source, len);
return t;
}
void
zstrcpy(STRPTR to, STRPTR from)
{
if (from)
strcpy(to, from);
else
*to = 0;
}
int
zstrnicmp(STRPTR a,STRPTR b,LONG len)
{
return strnicmp(a ? a : (STRPTR)"", b ? b : (STRPTR)"",len);
}
int
zstricmp(STRPTR a,STRPTR b)
{
return stricmp(a ? a : (STRPTR)"", b ? b : (STRPTR)"");
}
int
zstrcmp(STRPTR a,STRPTR b)
{
return strcmp(a ? a : (STRPTR)"", b ? b : (STRPTR)"");
}
void
strdel(STRPTR t,long len)
{
STRPTR s;
for (s = t + len; *s; t++, s++)
*t = *s;
*t = 0;
}
int
cmdcmp(STRPTR *s1, STRPTR *s2)
{
STRPTR c1 = *s1, c2 = *s2;
int cmp;
for (;;c1++,c2++) {
/* TODO: maybe do a cmdlen() before? */
if ((*c1 == '(' || *c1 == ' ' || !*c1) && (*c2 == '(' || *c2 == ' ' || !*c2))
return 0;
if ((cmp = tolower(*c1) - tolower(*c2)) != 0)
return cmp;
}
}
int32
cmdlen(STRPTR t)
{
long i = 0;
if (!t)
return 0;
while (*(t+i) && i < 30 && (*(t+i) == '_' || IsAlNum(loc,*(t+i))))
i++;
return i;
}
void
StringToUpper(STRPTR t)
{
for (;*t;t++)
*t = ToUpper(*t);
}
struct Node *
FindCommand(struct MinList *list,STRPTR name)
{
struct Node *ln;
long i;
if (!name || !list)
return NULL;
i = cmdlen(name);
for (ln = (struct Node *)list->mlh_Head;ln->ln_Succ && (strnicmp(ln->ln_Name,name,i) || IsAlNum(loc,*(ln->ln_Name+i)) || *(ln->ln_Name+i) == '_');ln = ln->ln_Succ);
if (ln != (struct Node *)&list->mlh_Tail)
return ln;
return NULL;
}
struct Node *
FindTag(struct MinList *list, STRPTR t)
{
struct Node *ln;
if (!t || !list)
return NULL;
for (ln = (struct Node *)list->mlh_Head; ln->ln_Succ && stricmp(ln->ln_Name, t); ln = ln->ln_Succ);
if (ln->ln_Succ)
return ln;
return NULL;
}
int32
CountNodes(struct MinList *l)
{
struct Node *n;
long i = 0;
for (n = (struct Node *)l->mlh_Head; n->ln_Succ; n = n->ln_Succ, i++);
return i;
}
struct NumberLink *
FindLink(struct MinList *list, APTR link)
{
struct NumberLink *nl;
foreach (list, nl) {
if (nl->nl_Link == link)
return nl;
}
return NULL;
}
struct MinList *
FindList(struct MinNode *mln)
{
for (; mln->mln_Pred; mln = mln->mln_Pred);
return (struct MinList *)mln;
}
struct Node *
FindListNumber(struct MinList *l, long num)
{
struct Node *n;
long i;
ULONG listend = ~0L;
if (IsListEmpty((struct List *)l))
return NULL;
for (n = (struct Node *)l->mlh_Head, i = 0; i < num && n->ln_Succ; i++, n = n->ln_Succ) {
if (n == (struct Node *)l->mlh_TailPred && listend == -1)
listend = i;
}
if (listend < num)
return NULL;
return n;
}
long
FindListEntry(struct MinList *l, struct MinNode *n)
{
struct MinNode *sn;
long i;
for (sn = l->mlh_Head, i = 0; sn->mln_Succ; sn = sn->mln_Succ, i++) {
if (sn == n)
return i;
}
return -1;
}
void
InsertAt(struct MinList *l, struct Node *n, long pos)
{
struct Node *pn;
long i;
if (pos == -1)
MyAddTail(l, n);
else {
for (pn = (struct Node *)l, i = 0; i < pos && pn->ln_Succ; pn = pn->ln_Succ, i++);
Insert((struct List *)l, n, pn);
}
}
void
MoveTo(struct Node *n, struct MinList *l1, long pos1, struct MinList *l2, long pos2)
{
struct Node *pn;
long i;
if (l1 == l2 && pos1 == pos2)
return;
MyRemove(n);
if (l1 == l2 && pos1 < pos2)
pos2--;
for (pn = (struct Node *)l2, i = 0; i < pos2 && pn->ln_Succ; pn = pn->ln_Succ, i++);
Insert((struct List *)l2, n, pn);
}
void
moveList(struct MinList *from, struct MinList *to)
{
if (!from || IsListEmpty((struct List *)from)) {
if (to)
MyNewList(to);
return;
}
to->mlh_Head = from->mlh_Head;
to->mlh_Tail = NULL;
to->mlh_TailPred = from->mlh_TailPred;
to->mlh_Head->mln_Pred = (struct MinNode *)&to->mlh_Head;
to->mlh_TailPred->mln_Succ = (struct MinNode *)&to->mlh_Tail;
MyNewList(from);
}
void
swapLists(struct MinList *l1, struct MinList *l2)
{
struct MinList list;
moveList(l1, &list);
moveList(l2, l1);
moveList(&list, l2);
}
int32
compareNames(const struct Node **lna, const struct Node **lnb)
{
return StrnCmp(loc, (*lna)->ln_Name, (*lnb)->ln_Name, -1, SC_COLLATE1);
}
void
freeSort(APTR sortBuffer, ULONG len)
{
if (sortBuffer && len)
FreePooled(pool, sortBuffer, len * sizeof(struct Node *));
}
APTR
allocSort(struct MinList *l, ULONG *len)
{
struct Node *ln, **sortBuffer;
ULONG i = 0;
if (IsListEmpty((struct List *)l))
return NULL;
if ((sortBuffer = AllocPooled(pool, (*len = CountNodes(l)) * sizeof(struct Node *))) != 0) {
foreach(l, ln)
*(sortBuffer + i++) = ln;
}
return sortBuffer;
}
void
SortListWith(struct MinList *l, APTR func)
{
struct Node **buffer;
uint32 len, i;
if ((buffer = allocSort(l, &len)) != 0) {
qsort(buffer, len, sizeof(struct Node *), func);
MyNewList(l);
for (i = 0; i < len; i++)
MyAddTail(l, *(buffer + i));
freeSort(buffer, len);
}
}
long
compareType(struct Node **lna, struct Node **lnb)
{
long i;
i = (*lna)->ln_Type-(*lnb)->ln_Type;
if (!i) {
if ((*lna)->ln_Type == FVT_VALUE && !strcmp((*lna)->ln_Name,"0"))
i = -1;
else if ((*lnb)->ln_Type == FVT_VALUE && !strcmp((*lnb)->ln_Name,"0"))
i = 1;
else
i = StrnCmp(loc,(*lna)->ln_Name,(*lnb)->ln_Name,-1,SC_COLLATE1);
}
return i;
}
void
sortList(struct MinList *l)
{
SortListWith(l, compareNames);
}
void
SortTypeList(struct MinList *l)
{
SortListWith(l, compareType);
}
long
GetListWidth(struct MinList *list)
{
struct Node *ln;
long width = 0, w;
for (ln = (struct Node *)list->mlh_Head; ln->ln_Succ; ln = ln->ln_Succ) {
if (width < (w = TLn(ln->ln_Name)))
width = w;
}
return width;
}
double
PrepareConvert(STRPTR *s)
{
char t[64];
double num;
long i;
strcpy(t, *s);
for (i = 0; t[i]; i++) {
// replace commas with points
if (t[i] == ',')
t[i] = '.';
}
num = atof(t);
// Search string backwards for the unit, result in 's'
for (i--;!isdigit(t[i]) && !isspace(t[i]);i--);
*s = t+i+1;
return num;
}
void
ProcentToString(ULONG p,STRPTR t)
{
strcpy(t, ita(p * 100 / 1024.0, -2, ITA_NONE));
strcat(t, "%");
}
double
ConvertDegreeProcent(STRPTR s)
{
double d = PrepareConvert(&s);
if (*s == '%')
d /= 100.0;
else if (*s == '°')
d = (2*PI*d)/360.0;
return d;
}
int32
ConvertTime(STRPTR s)
{
int32 secs = -1L;
double num;
num = fabs(PrepareConvert(&s));
if (s[0] == 'm' || !strncmp(s, GetString(&gLocaleInfo, MSG_MINUTE_UNIT), 3) && (!s[3] || s[3] == ' ' || s[3] == 's'))
secs = (long)(num * 60);
else if (s[0] == 's' || !strncmp(s, GetString(&gLocaleInfo, MSG_SECOND_UNIT), 3) && (!s[3] || s[3] == ' ' || s[3] == 's'))
secs = (long)num;
else if (s[0] == 'h')
secs = (long)(num * 3600);
return secs;
}
struct cnt {STRPTR t;LONG div;};
const struct cnt cntm[] = {{"km",1000000},{"m",1000},{"dm",100},{"cm",10},{NULL,0}};
const struct cnt cnti[] = {{"yd",2592},{"ft",864},{"in",72},{"\"",72},{"pt",1},{NULL,0}};
double
ConvertNumber(STRPTR s, UBYTE targettype)
{
UBYTE type;
double num;
long i;
num = PrepareConvert(&s);
for (type = 0, i = 0; cnti[i].t; i++) {
if (!strcmp(s, cnti[i].t)) {
// If it's an American/English unit, convert to points
num *= cnti[i].div;
type = CNT_POINT;
}
}
if (!type) {
for (type = 0, i = 0; cntm[i].t; i++) {
if (!strcmp(s, cntm[i].t)) {
// If it's a metrical unit, convert to millimeters
num *= cntm[i].div;
type = CNT_MM;
}
}
}
if (!type) {
// Values without a unit are treated as millimeter
type = CNT_MM;
}
if (type == CNT_MM && targettype >= CNT_POINT) {
// metric to American/English conversion
num *= 72 / 25.4;
}
if (type == CNT_POINT && targettype < CNT_POINT) {
// American/English to metric conversion
num *= 25.4 / 72;
}
if (targettype >= CNT_POINT) {
switch (targettype) {
case CNT_INCH:
num /= 72.0;
break;
case CNT_FOOT:
num /= 864.0;
break;
case CNT_YARD:
num /= 2592.0;
break;
}
} else
for (;--targettype; num /= 10.0);
return num;
}
void
WriteChunkString(APTR iff, STRPTR t)
{
UBYTE pad = 0;
if (t)
WriteChunkBytes(iff, t, strlen(t) + 1);
else
WriteChunkBytes(iff, &pad, 1);
}
static void
MakeLocaleStringsA(struct MinList *list, LONG id, va_list args)
{
MyNewList(list);
while (id != TAG_END) {
struct Node *node = AllocPooled(pool, sizeof(struct Node));
if (node == NULL)
break;
node->ln_Name = GetString(&gLocaleInfo, id);
MyAddTail(list, node);
id = va_arg(args, ULONG);
}
}
void
MakeLocaleStrings(struct MinList *list, LONG id, ...)
{
va_list args;
va_start(args, id);
MakeLocaleStringsA(list, id, args);
va_end(args);
}
struct List *
MakeLocaleStringList(LONG id, ...)
{
struct List *list;
va_list args;
if ((list = AllocPooled(pool, sizeof(struct List))) == NULL)
return NULL;
va_start(args, id);
MakeLocaleStringsA((struct MinList *)list, id, args);
va_end(args);
return list;
}
void
FreeStringList(struct List *list)
{
struct Node *node;
if (list == NULL)
return;
while ((node = MyRemHead(list)) != NULL) {
FreePooled(pool, node, sizeof(struct Node));
}
FreePooled(pool, list, sizeof(struct List));
}
static void
MakeStringsA(struct MinList *list, STRPTR string, va_list args)
{
MyNewList(list);
while (string != NULL) {
struct Node *node = AllocPooled(pool, sizeof(struct Node));
if (node == NULL)
break;
node->ln_Name = string;
if (string && !strcmp(string, "-"))
node->ln_Type = POPUP_NO_SELECT_BARLABEL;
MyAddTail(list, node);
string = va_arg(args, STRPTR);
}
}
void
MakeStrings(struct MinList *list, const STRPTR string, ...)
{
va_list args;
va_start(args, string);
MakeStringsA(list, string, args);
va_end(args);
}
struct List *
MakeStringList(const STRPTR string, ...)
{
struct List *list;
va_list args;
if ((list = AllocPooled(pool, sizeof(struct List))) == NULL)
return NULL;
va_start(args, string);
MakeStringsA((struct MinList *)list, string, args);
va_end(args);
return list;
}
uint32
DoClassMethodA(Class *cl,Msg msg)
{
ULONG (ASM *m)(REG(a0, Class *), REG(a2, Object *), REG(a1, Msg));
if (!cl || !msg)
return FALSE;
m = (APTR)cl->cl_Dispatcher.h_Entry;
return (*m)(cl,(Object *)cl,msg);
}
uint32 lvsec,lvmsec;
bool
IsDoubleClick(int16 entry)
{
uint32 sec,msec;
CurrentTime(&sec,&msec);
if (lventry == entry && DoubleClick(lvsec,lvmsec,sec,msec))
return true;
lventry = entry;
CurrentTime(&lvsec,&lvmsec);
return false;
}
struct Node *
HandleLVRawKeys(struct Gadget *lvgad,struct Window *win,struct MinList *list,long items)
{
struct Node *node;
long i;
if (imsg.Code != CURSORUP && imsg.Code != CURSORDOWN)
return NULL;
node = (struct Node *)lvgad->UserData;
if (node && !(imsg.Qualifier & (IEQUALIFIER_SHIFT | IEQUALIFIER_ALT))) {
if ((imsg.Code == CURSORUP) && ((struct Node *)list->mlh_Head != node))
node = node->ln_Pred;
if ((imsg.Code == CURSORDOWN) && ((struct Node *)list->mlh_TailPred != node))
node = node->ln_Succ;
lvgad->UserData = node;
} else if (node && (imsg.Qualifier & IEQUALIFIER_SHIFT)) {
items = (lvgad->Height-4)/items-1;
if (imsg.Code == CURSORUP) {
for (node = (struct Node *)lvgad->UserData;node->ln_Pred && items;node = node->ln_Pred,items--);
if (!node->ln_Pred)
node = (struct Node *)list->mlh_Head;
} else {
for (node = (struct Node *)lvgad->UserData;node->ln_Succ && items;node = node->ln_Succ,items--);
if (!node->ln_Succ)
node = (struct Node *)list->mlh_TailPred;
}
lvgad->UserData = node;
} else if (imsg.Code == CURSORUP || !node)
lvgad->UserData = list->mlh_Head;
else if (imsg.Code == CURSORDOWN)
lvgad->UserData = list->mlh_TailPred;
GT_SetGadgetAttrs(lvgad,win,NULL,GTLV_Selected,i = FindListEntry(list,lvgad->UserData),GTLV_MakeVisible,i,TAG_END);
return lvgad->UserData;
}
uint32
GetCheckBoxFlag(struct Gadget *gad,struct Window *win,ULONG flag)
{
uint32 checked = 0;
GT_GetGadgetAttrs(gad,win,NULL,GTCB_Checked,&checked,TAG_END);
return checked ? flag : 0;
}
int32
WordWrapText(struct List *lh,STRPTR t,long width)
{
struct TextExtent extent;
struct Node *ln;
long fit,len,cols = 0;
len = strlen(t);
while (len > 0) {
fit = TextFit(&scr->RastPort,t,len,&extent,NULL,1,width,fontheight+4);
if ((ln = AllocPooled(pool, sizeof(struct Node))) != 0) {
STRPTR s;
if ((s = strchr(t,'\n')) && s <= t+fit)
fit = s-t-1;
else if (fit < len) {
while(fit && *(t+fit) != ' ')
fit--;
if (!fit) {
while (*(t+fit) && *(t+fit) != ' ')
fit++;
}
}
if ((ln->ln_Name = AllocPooled(pool, fit+1)) != 0)
CopyMem(t,ln->ln_Name,fit);
while (*(t+fit) == ' ' || *(t+fit) == '\n')
fit++;
MyAddTail(lh, ln);
cols++;
}
len -= fit; t += fit;
}
return cols;
}
STRPTR
GetUniqueName(struct MinList *list,STRPTR base)
{
static char t[256];
char *s;
long i;
if (!MyFindName(list,base) || !base || !list)
return(base);
if (strlen(base) > 250) {
ErrorRequest(GetString(&gLocaleInfo, MSG_UNIQUE_NAME_ERR));
return(base);
}
strcpy(t,base);
for(s = t+strlen(t)-1;s > t && isdigit(*s);s--);
if (*s == '-')
s++;
else
s = t+strlen(t)+1;
strcpy(s-1,"-1"); i = 1;
while (MyFindName(list, t))
sprintf(s,"%ld",++i);
return t;
}
void
MakeUniqueName(struct MinList *list, STRPTR *name)
{
STRPTR t;
if ((t = GetUniqueName(list,*name)) != *name) {
FreeString(*name);
*name = AllocString(t);
}
}
void
FreeListItems(struct MinList *list, APTR free)
{
struct MinNode *mln;
while ((mln = (struct MinNode *)MyRemHead(list)) != 0)
((void (*)(struct MinNode *))free)(mln);
}
void
CopyListItems(struct MinList *from, struct MinList *to, APTR copy)
{
struct MinNode *mln,*cmln;
foreach (from,mln) {
if ((cmln = ((struct MinNode * (*)(struct MinNode *))copy)(mln)) != 0)
MyAddTail(to, cmln);
}
}
long SAVEDS
LinkNameSort(struct Link **la, struct Link **lb)
{
return compareNames((const struct Node **)&(*la)->l_Link,(const struct Node **)&(*lb)->l_Link);
}
struct MinNode *
FindLinkCommand(struct MinList *list, STRPTR name)
{
struct Link *l;
STRPTR t;
long i;
if (!name || !list)
return NULL;
i = cmdlen(name);
for(l = (struct Link *)list->mlh_Head; l->l_Node.mln_Succ && (strnicmp(t = ((struct Node *)l->l_Link)->ln_Name,name,i) || IsAlNum(loc,*(t+i)) || *(t+i) == '_');l = (APTR)l->l_Node.mln_Succ);
if (l->l_Node.mln_Succ)
return l->l_Link;
return NULL;
}
struct Link *
FindLinkWithName(struct MinList *list,STRPTR name)
{
struct Link *l;
if (!name)
return NULL;
foreach (list, l) {
if (((struct Node *)l->l_Link)->ln_Name && !strcmp(((struct Node *)l->l_Link)->ln_Name,name))
return l;
}
return NULL;
}
struct MinNode *
FindLinkName(struct MinList *list, STRPTR name)
{
struct Link *l;
if ((l = FindLinkWithName(list, name)) != 0)
return l->l_Link;
return NULL;
}
void
AddLink(struct MinList *list, struct MinNode *node, APTR func)
{
struct Link *l;
if ((l = AllocPooled(pool, sizeof(struct Link))) != 0) {
l->l_Link = node;
l->l_HookFunction = func;
MyAddTail(list, l);
}
}
LONG
GetListNumberOfName(struct MinList *mlh, STRPTR name, BOOL cmd, BOOL link)
{
struct Node *ln;
long len, pos = 0;
STRPTR t;
if (!name)
return ~0L;
if (cmd)
len = cmdlen(name);
foreach (mlh, ln) {
t = link ? ((struct Node *)((struct Link *)ln)->l_Link)->ln_Name : ln->ln_Name;
if (cmd ? !strnicmp(name,t,len) : !stricmp(name,t))
return pos;
pos++;
}
return ~0L;
}
BOOL
AddToNameList(STRPTR buffer, STRPTR t, int *plen, int maxlength)
{
int l, len = *plen;
if (!t)
return TRUE;
if (len && (len + 2 < maxlength-1))
strcpy(buffer+len,", "), len += 2;
l = strlen(t);
if (!len && l > maxlength - 5) {
// write part of first name
*buffer = '"';
#ifdef __amigaos4__
Strlcpy(buffer+1,t,maxlength-5);
#else
stccpy(buffer+1,t,maxlength-5);
#endif
strcpy(buffer+maxlength-5,"...\"");
return FALSE;
}
if (len + l > maxlength - 8) {
// add ellipsis to the end
strcpy(buffer + len, "...");
return FALSE;
}
*(buffer+len) = '"';
strcpy(buffer+len+1,t); len += 1+l;
*(buffer+len) = '"';
*(buffer+len+1) = 0;
*plen = len+1;
return TRUE;
}
struct Library *
IgnOpenClass(STRPTR secondary, STRPTR name, LONG version)
{
struct Library *class;
char path[256];
strcpy(path, CLASSES_PATH); // try the "classes"-directory
AddPart(path, name, 256);
if ((class = OpenLibrary(path, version)) != 0)
return class;
strcpy(path, secondary); // try the secondary-directory
AddPart(path, name, 256);
if ((class = OpenLibrary(path, version)) != 0)
return class;
if ((class = OpenLibrary(name, version)) != 0) // try the name only
return class;
return NULL;
}
#ifdef DEBUG
void KPutChar(char);
void
dumptext(UBYTE *b, int len)
{
int i;
bug(" ");
for (i = 0; i < len; i++) {
if (*b < ' ')
KPutChar('.');
else
KPutChar(*b);
b++;
}
KPutChar('\n');
}