-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmisc.pb
87 lines (79 loc) · 2.12 KB
/
misc.pb
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
; Lost Labyrinth VI: Portals
; miscellaneous procedures
; written in PureBasic 4.20 (http://www.purebasic.com)
; created: 12.12.2008 Frank Malota <malota@web.de>
; modified: 21.12.2008 Frank Malota <malota@web.de>
; returns smaller value
Procedure.l min(val1.l, val2.l)
Protected rc.w
rc = val1
If val2 < val1
rc = val2
EndIf
ProcedureReturn rc
EndProcedure
; returns greater value
Procedure.l max(val1.l, val2.l)
Protected rc.w
rc = val1
If val2 > val1
rc = val2
EndIf
ProcedureReturn rc
EndProcedure
; compares two string lists and returns 1 if they contain at least one match
Procedure.b compare_string_lists(string1$, string2$, separator$ = "|")
Protected rc.b = 0, pos.w = 0, part$, rest$
Protected NewList list1$()
Protected NewList list2$()
rest$ = string1$
pos = FindString(rest$, separator$, 1)
While pos > 0
AddElement(list1$())
list1$() = Left(rest$, pos - 1)
rest$ = Mid(rest$, pos + 1)
pos = FindString(rest$, separator$, 1)
Wend
If rest$ <> ""
AddElement(list1$())
list1$() = rest$
EndIf
rest$ = string2$
pos = FindString(rest$, separator$, 1)
While pos > 0
AddElement(list2$())
list2$() = Left(rest$, pos - 1)
rest$ = Mid(rest$, pos + 1)
pos = FindString(rest$, separator$, 1)
Wend
If rest$ <> ""
AddElement(list2$())
list2$() = rest$
EndIf
ResetList(list1$())
While NextElement(list1$()) And rc = 0
ResetList(list2$())
While NextElement(list2$()) And rc = 0
If LCase(list1$()) = LCase(list2$())
rc = 1
EndIf
Wend
Wend
ProcedureReturn rc
EndProcedure
; adds a string to a string list if it is not already included; returns new string list
Procedure.s add_string_list(string_list$, new_string$, separator$ = "|")
If compare_string_lists(string_list$, new_string$, separator$) = 0
If string_list$ <> ""
string_list$ = string_list$ + separator$
EndIf
string_list$ = string_list$ + new_string$
EndIf
ProcedureReturn string_list$
EndProcedure
; IDE Options = PureBasic 4.20 (Windows - x86)
; CursorPosition = 62
; FirstLine = 39
; Folding = -
; EnableXP
; CompileSourceDirectory