aboutsummaryrefslogtreecommitdiff
path: root/BUG3/text_tools.udo
diff options
context:
space:
mode:
authorRichard Knight <q@1bpm.net>2021-10-29 22:32:21 +0100
committerRichard Knight <q@1bpm.net>2021-10-29 22:32:21 +0100
commitc4b96cdd87738e9f0cba695904d2d484b4335e7f (patch)
tree111cf121905aa3d7a317bd96b5e7db0f2a8aac6e /BUG3/text_tools.udo
downloadcsd-unfixedbugs1-c4b96cdd87738e9f0cba695904d2d484b4335e7f.tar.gz
csd-unfixedbugs1-c4b96cdd87738e9f0cba695904d2d484b4335e7f.tar.bz2
csd-unfixedbugs1-c4b96cdd87738e9f0cba695904d2d484b4335e7f.zip
initial
Diffstat (limited to 'BUG3/text_tools.udo')
-rw-r--r--BUG3/text_tools.udo185
1 files changed, 185 insertions, 0 deletions
diff --git a/BUG3/text_tools.udo b/BUG3/text_tools.udo
new file mode 100644
index 0000000..63cc2a8
--- /dev/null
+++ b/BUG3/text_tools.udo
@@ -0,0 +1,185 @@
+#ifndef UDO_TEXTTOOLS
+#define UDO_TEXTTOOLS ##
+
+opcode notify, 0, S
+ Stext xin
+ Snew = "\n"
+ iwidth = 60
+ index = 0
+ while (index < iwidth) do
+ Snew = strcat(Snew, "*");
+ index += 1
+ od
+ prints strcat(strcat(Snew, "\n"), strcat(Stext, "\n\n"))
+endop
+
+
+#ifndef BUG_VERSION
+#define BUG_VERSION #-1#
+ notify("No BUG_VERSION specified: must match directive file")
+ exitnow
+#end
+
+opcode gettextindex, i, S
+ Sname xin
+ ifinalindex = -1
+ index = 0
+ while (index < lenarray(gSequenced)) do
+ if (strcmp(gSequenced[index], Sname) == 0) then
+ ifinalindex = index
+ igoto complete
+ endif
+ index += 1
+ od
+
+complete:
+ xout ifinalindex
+endop
+
+
+opcode stripnewline, S, S
+ Sline xin
+ index = strindex(Sline, "\n")
+ if (index != -1) then
+ Sline = strsub(Sline, 0, index)
+ endif
+ xout Sline
+endop
+
+opcode parserowitems, i, Siii
+ Sline, ix1, ix2, imode xin ; mode 0 = count, 1 = write sections, 2 = write chords
+ inum = 0
+ while (strlen(Sline) > 0) do
+ icomma = strindex(Sline, ",")
+ Stemp = strsub(Sline, 0, icomma)
+ icomma = (icomma == -1) ? 0 : icomma
+ Sline = strsub(Sline, icomma + 1)
+ if (imode == 1) then
+ tabw_i strtod(Stemp), inum, gisectiondata[ix1][ix2]
+ elseif (imode == 2) then
+ tabw_i strtod(Stemp), inum, gichordgroups[ix1][ix2]
+ endif
+ inum += 1
+ od
+ xout inum
+endop
+
+
+
+
+opcode getparameter, i, iii
+ ipos, idataindex, iparameter xin
+ xout tab_i(ipos, gisectiondata[idataindex][iparameter])
+endop
+
+/*
+opcode getparameter, i, iiii
+ isection, instrindex, iparameter, ipos xin
+ isectiondataindex = gisections[isection][instrindex]
+ ifn = gisectiondata[isectiondataindex][iparameter]
+ xout tab_i(ipos, ifn)
+endop
+*/
+opcode getparameterfn, i, iii
+ isection, instrindex, iparameter xin
+ isectiondataindex = gisections[isection][instrindex]
+ xout gisectiondata[isectiondataindex][iparameter]
+endop
+
+opcode getparameterfns, i[], ii
+ isection, instrindex xin
+ isectiondataindex = gisections[isection][instrindex]
+ xout getrow(gisectiondata, isectiondataindex)
+endop
+
+opcode parserow, 0, Siii
+ Sline, ix1, ix2, imode xin ; mode 1 = section patterns , 2 = chords
+ isize = parserowitems(Sline, ix1, ix2, 0)
+ if (imode == 1) then
+ gisectiondata[ix1][ix2] ftgen 0, 0, -isize, -7, 0
+ elseif (imode == 2) then
+ gichordgroups[ix1][ix2] ftgen 0, 0, -isize, -7, 0
+ endif
+ isize = parserowitems(Sline, ix1, ix2, imode)
+endop
+
+
+
+opcode parsetext, 0, S
+ Sfile xin
+ iparameter = -1
+ isection = -1
+ ichordnum = -1
+ isectiondataindex = -1
+ imode = -1
+read:
+ Sline, ilinenum readfi Sfile
+ Sline = stripnewline(Sline)
+ if (strlen(Sline) > 0) then
+ Sfirstchar = strsub(Sline, 0, 1)
+ if (strcmp(Sfirstchar, ";") == 0) then ; comment
+ ; no action
+ elseif (strcmp(Sfirstchar, "v") == 0) then ; version
+ imode = 0
+ iversion = strtod(strsub(Sline, 2))
+ if (iversion != $BUG_VERSION) then
+ notify(sprintf("Incompatible directive file version: got %.2f , expected %.2f", iversion, $BUG_VERSION))
+ exitnow
+ endif
+ elseif (strcmp(Sfirstchar, "s") == 0) then ; section
+ imode = 1
+ icomma = strindex(Sline, ",")
+ isectionnum = strtod(strsub(Sline, 2, icomma))
+ Sub = strsub(Sline, icomma+1)
+ icomma = strindex(Sub, ",")
+ isectionlength = strtod(strsub(Sub, 0, icomma))
+ ichordgroup = strtod(strsub(Sub, icomma+1))
+ gisectionchords[isectionnum] = ichordgroup
+ tabw_i isectionlength, isectionnum, gisectionlengths
+
+ elseif (strcmp(Sfirstchar, "b") == 0) then ; bpm
+ imode = -1
+ gitempo = strtod(strsub(Sline, 2))
+
+ elseif (strcmp(Sfirstchar, "c") == 0) then ; chord group
+ imode = 3
+ ichordgroup = strtod(strsub(Sline, 2))
+ ichordnum = 0
+
+ elseif (strcmp(Sfirstchar, "i") == 0) then ; pattern
+ imode = 4
+ iparameter = 0
+
+ icomma = strindex(Sline, ",")
+ instrindex = gettextindex(strsub(Sline, 2, icomma))
+ Sub = strsub(Sline, icomma+1)
+ icomma2 = strindex(Sub, ",")
+ isection = strtod(strsub(Sub, 0, icomma2))
+ if (icomma2 != -1) then ; repeat or null section
+ irepeatsection = strtod(strsub(Sub, icomma2+1))
+ if (irepeatsection == -1) then
+ inewsection = -1
+ else
+ inewsection = gisections[irepeatsection][instrindex]
+ endif
+ gisections[isection][instrindex] = inewsection
+ else
+ isectiondataindex += 1
+ gisections[isection][instrindex] = isectiondataindex
+ endif
+ elseif (imode == 3) then ; chords
+ parserow(Sline, ichordgroup, ichordnum, 2)
+ ichordnum += 1
+
+ elseif (imode == 4) then
+ parserow(Sline, isectiondataindex, iparameter, 1)
+ iparameter += 1
+ endif
+ endif
+ if (ilinenum != -1) igoto read
+endop
+
+
+
+#end
+