Sub Main()
' Translation from jdrou bash scrip into basic code.
' I have chosen to try a 'direct translation', using as much as possible from jdrou's original code.
'
' Using idea from Warlimont where he manually put trait tags in names. Nice idea!
CmdLine = Command()
CmdLnLen = Len(CmdLine)
If CmdLnLen > 0 Then
leaderfiles_path = ""
leader_file = CmdLine
input_file = leaderfiles_path + leader_file
add_traitcodes_to_name (input_file)
Else
'no arugments found
End If
End Sub
Sub add_traitcodes_to_name(ByVal input_file As String)
trait(0) = "LW"
trait(1) = "DD"
trait(2) = "OD"
trait(3) = "WS"
trait(4) = "TR"
trait(5) = "EN"
trait(6) = "FB"
trait(7) = "PL"
trait(8) = "CO"
trait(9) = "OG"
trait(10) = "SW"
trait(11) = "BR"
trait(12) = "ST"
trait(13) = "SP"
trait(14) = "TB"
trait(15) = "CB"
trait(16) = "NF"
trait(17) = "FD"
tmp_file = input_file + ".tmp"
input_file = input_file + ".csv"
fopen = FreeFile()
Open input_file For Input As #fopen
fwrite = FreeFile()
Open tmp_file For Output As #fwrite
Do While Not EOF(fopen)
Line Input #fopen, input_record
field5 = cut(input_record, ";", 5)
Select Case field5
Case "Traits":
traits_text = "(traits)"
Case "TRAITS":
traits_text = "(traits)"
Case "0":
traits_text = "(N)"
Case Else:
traits = Val(field5)
traits_text = "("
trait_added = 0
n = 17
Do While n >= 0
t = 2 ^ n
If (traits >= t) Then
If (trait_added = 1) Then
traits_text = traits_text + " "
End If
traits = traits - t
traits_text = traits_text + trait(n)
trait_added = 1
End If
n = n - 1
Loop
traits_text = traits_text + ")"
End Select
Print #fwrite, traits_text + input_record
Loop
Close #fopen
Close #fwrite
End Sub
Function cut(ByVal record As String, ByVal delimeter As String, ByVal field_pos As Integer) As String
' A poor excuse for a cut command, but assuming the record from the HOI file is correct, the routine works.
olds = record
Do Until f = field_pos
p = InStr(olds, delimeter)
If p <> 0 Then
news = Left(olds, p - 1)
olds = Mid(olds, p + 1, Len(olds))
cut = news
Else
cut = olds
End If
f = f + 1
Loop
End Function