Added show word option
[sgc2.git] / Config.praat
blob70f60cbc5f35e8cbec8de011ee0fa98c31d4abbd
2 # SpeakGoodChinese 2.0
3
4 # Praat script handling configuration page
6 #     SpeakGoodChinese: Config.praat loads the code needed for the 
7 #     settings and the Settings page of SpeakGoodChinese.
8 #     
9 #     Copyright (C) 2007-2010  R.J.J.H. van Son and 2010 the Netherlands Cancer Institute
10 #     The SpeakGoodChinese team are:
11 #     Guangqin Chen, Zhonyan Chen, Stefan de Koning, Eveline van Hagen, 
12 #     Rob van Son, Dennis Vierkant, David Weenink
13
14 #     This program is free software; you can redistribute it and/or modify
15 #     it under the terms of the GNU General Public License as published by
16 #     the Free Software Foundation; either version 2 of the License, or
17 #     (at your option) any later version.
18
19 #     This program is distributed in the hope that it will be useful,
20 #     but WITHOUT ANY WARRANTY; without even the implied warranty of
21 #     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 #     GNU General Public License for more details.
23
24 #     You should have received a copy of the GNU General Public License
25 #     along with this program; if not, write to the Free Software
26 #     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
27
29 ###############################################################
31 # Button Drawing Routines
33 ###############################################################
35 procedure DrawCredits .color$ .x .y .size
36         .size *= 0.71
37         .lineheight = 2*.size
38         call adjustFontSizeOnHeight 'defaultFont$' 24 '.lineheight'
39         .currentFontSize = adjustFontSizeOnHeight.newFontSize
40     demo Paint circle... {0.2,0.2,0.8} '.x' '.y' '.size'
41         demo Colour... White
42         demo Text special... '.x' centre '.y' half Times '.currentFontSize' 0 i
43         demoShow()
44         demo Colour... Black
45         call set_font_size 'defaultFontSize'    
46 endproc
48 procedure DrawDeleteList .color$ .x .y .size
49     .y += 2*.size
50     .leftX = .x - 10
51     .rightX = .x + 10
52     .botY = .y+1
53     .topY = .botY + 5
54         call set_font_size 12
55     demo Red
56     .displayWordList$ = replace_regex$(wordlistName$, "[_]", " ", 0)
58         # Adapt wide of text
59         .maxWidth = (.rightX - .leftX)
60     .currentFontSize = defaultFontSize
61         call adjustFontSizeOnWidth 'defaultFont$' '.currentFontSize' '.maxWidth' '.displayWordList$'
62         .currentFontSize = adjustFontSizeOnWidth.newFontSize
63         if adjustFontSizeOnWidth.diff > 0
64                 .rightX += adjustFontSizeOnWidth.diff/2
65                 .leftX -= adjustFontSizeOnWidth.diff/2
66         endif
67         call set_font_size '.currentFontSize'
68     demo Paint rectangle... White '.leftX' '.rightX' '.botY' '.topY'
70         demo Text... '.x' Centre '.botY' Bottom '.displayWordList$'
71     demo Black
72         demoShow()
73         call set_font_size 'defaultFontSize'
74 endproc
76 procedure DrawManual .color$ .x .y .size
77         .size *= 0.71
78         .lineheight = 2*.size
79         call adjustFontSizeOnHeight 'defaultFont$' 24 '.lineheight'
80         .currentFontSize = adjustFontSizeOnHeight.newFontSize
81     demo Paint circle... {0.2,0.2,0.8} '.x' '.y' '.size'
82         demo Colour... White
83         demo Text special... '.x' centre '.y' half Times '.currentFontSize' 0 M
84         demoShow()
85         demo Colour... Black
86         call set_font_size 'defaultFontSize'    
87 endproc
89 procedure DrawLogging .color$ .x .y .size
90     .size /= 2
91         .y += .size
92     if .color$ = "Blue"
93         .color$ = "{0.5,0.5,1}"
94      else
95         .color$ = "Blue"
96      endif
97     demo Paint circle... '.color$' '.x' '.y' '.size'
98 endproc
100 ###############################################################
102 # Obligatory button Drawing Routines
104 # These MUST be defined
106 ###############################################################
108 procedure DrawReturn .color$ .x .y .size
109     call DrawConfig '.color$' '.x' '.y' '.size'
110 endproc
112 # Set the correct button states after redrawing the window
113 procedure setConfigMainPage
114         call testLoadTable SummaryToneEvaluation
115         if testLoadTable.table <= 0
116                 call Draw_button 'config$' PerfSummary 1
117         endif
118     # Handle logging buttons with forced button draw
119     if fileReadable("'preferencesLogDir$'/logPerformance.txt")
120         call Draw_button 'config$' +!Logging 'config.logPerformance'
121     endif
122 endproc
124 ###############################################################
126 # Button Processing Routines
128 ###############################################################
130 procedure processConfigShuffleLists .clickX .clickY .pressed$
131         .table$ = "Config"
132         .label$ = "ShuffleLists"
133         config.shuffleLists = not config.shuffleLists
134         .displayButton = 2*config.shuffleLists
135     call Draw_button '.table$' '.label$' '.displayButton'
136 endproc
138 procedure processConfigUseSoundExample .clickX .clickY .pressed$
139         .table$ = "Config"
140         .label$ = "UseSoundExample"
141         config.useSoundExample = not config.useSoundExample
142         .displayButton = 2*config.useSoundExample
143     call Draw_button '.table$' '.label$' '.displayButton'
144 endproc
145         
146 procedure processConfigSynthesis .tts$ .clickX .clickY .pressed$
147         .table$ = "Config"
148         .label$ = "Synthesis_'.tts$'"
149         if sgc2.synthesizer > 0 or (speakCommandFile$ <> "" and fileReadable(speakCommandFile$))
150                 if config.synthesis$ = ""
151                         config.synthesis$ = .tts$
152                         .displayButton = 2
153                 else
154                         config.synthesis$ = ""
155                         .displayButton = 0
156                 endif
157         else
158                 config.synthesis$ = "_DISABLED_"
159                 .displayButton = -1
160         endif
161     call Draw_button '.table$' '.label$' '.displayButton'
162 endproc
163         
164 procedure processConfigStrict .clickX .clickY .pressed$
165         .table$ = "Config"
166         .label$ = "Strict"
167         config.strict = not config.strict
168         if config.strict > 0
169                 .displayButton = 2
170         else
171                 .displayButton = 0
172         endif
173         # Change TTS for Strict!
174         call set_up_TTS
175     call Draw_button '.table$' '.label$' '.displayButton'
176 endproc
178 procedure processConfigDisplayPinyin .clickX .clickY .pressed$
179         .table$ = "Config"
180         .label$ = "DisplayPinyin"
181         config.displayPinyin = not config.displayPinyin
182         .displayButton = 2*config.displayPinyin
183     call Draw_button '.table$' '.label$' '.displayButton'
184 endproc
185                 
186 procedure processConfigDisplayChar .clickX .clickY .pressed$
187         .table$ = "Config"
188         .label$ = "DisplayChar"
189         config.displayChar = not config.displayChar
190         .displayButton = 2*config.displayChar
191     call Draw_button 'table$' '.label$' '.displayButton'
192 endproc
194 procedure processConfigDisplayTrans .clickX .clickY .pressed$
195         .table$ = "Config"
196         .label$ = "DisplayTrans"
197         config.displayTrans = not config.displayTrans
198         .displayButton = 2*config.displayTrans
199     call Draw_button 'table$' '.label$' '.displayButton'
200 endproc
202 procedure processConfigDisplayNumbers .clickX .clickY .pressed$
203         .table$ = "Config"
204         .label$ = "DisplayNumbers"
205         config.displayNumbers = not config.displayNumbers
206         .displayButton = 2*config.displayNumbers
207     call Draw_button 'table$' '.label$' '.displayButton'
208 endproc
210 procedure processConfigLanguage .language$ .clickX .clickY .pressed$
211         .table$ = "Config"
212         .label$ = "Language_'.language$'"
213         call processLanguageCodes '.table$' '.label$'
214 endproc
215         
216 procedure processConfigShowBackground .clickX .clickY .pressed$
217         .table$ = "Config"
218         .label$ = "ShowBackground"
219         config.showBackground = not config.showBackground
220         .displayButton = 2*config.showBackground
221     call Draw_button 'table$' '.label$' '.displayButton'
222 endproc
224 procedure processConfigInput .input$ .clickX .clickY .pressed$
225         .table$ = "Config"
226         .label$ = "Input_'.input$'"
227     call Draw_button '.table$' Input_'config.input$' 0
228         config.input$ = .input$
229     call Draw_button '.table$' Input_'config.input$' 2
230 endproc
232 procedure processConfigRegister .register .clickX .clickY .pressed$
233         .table$ = "Config"
234         .label$ = "Register_'.register'"
235         call setRegisterFromLabel '.table$' '.label$'
236 endproc
237         
238 procedure setRegisterFromLabel .table$ .label$
239     call Draw_button '.table$' Register_'config.register' 0
240     call Draw_button '.table$' '.label$' 2
241     # Someone might have to use more than 3 chars for the config.register code
242     .numChars = length(.label$) - length("Register_")
243         .registerText$ = right$(.label$, .numChars)
244         config.register = '.registerText$'
245 endproc
247 procedure processConfigDeleteWordlist .clickX .clickY .pressed$
248         .table$ = "Config"
249         .label$ = "DeleteWordlist"
251     # Do not process undeletable word lists, only those stored in the 
252     # preferencesDirectory$ can be deleted
253     if fileReadable("'sgc2wordlists$'/'wordlistName$'") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.txt") or     fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.Table")
254                 call findLabel '.table$' !'.label$'
255                 if findLabel.row > 0
256                 select Table '.table$'
257                 .alertText$ = Get value... 'findLabel.row' Text
258                 .confirmKey$ = Get value... 'findLabel.row' Key
259                 .popupText$ = Get value... 'findLabel.row' Helptext
260         else
261             exit Cannot find delete directive: '.table$' !'.label$'
262         endif
263         call write_text_popup 'defaultFont$' 14 '.popupText$'
264         call Draw_button '.table$' '.label$' 2
265         alertText$ = .alertText$
266         call Draw_button '.table$' '.label$' 3
267         alertText$ = ""
268         
269                 # Wait for confirmation
270                 demoWaitForInput()
271         if demoInput(.confirmKey$)
272                 .deleteWordListDir$ = wordlistName$
273                 call load_word_list "'localWordlistDir$'" 1
274                 call removeWordlist '.deleteWordListDir$'
275                         call load_word_list "'localWordlistDir$'" 0
276         endif
277                 call Draw_button '.table$' '.label$' 0
278                 call Draw_config_page
279     endif
280 endproc
282 wordlistTag$ = "Wordlist name"        
283 procedure processConfigInstallWordlist .clickX .clickY .pressed$
284         .table$ = "Config"
285         .label$ = "InstallWordlist"
286     call Draw_button '.table$' '.label$' 1
287         if windows
288                 # Do not use the automatic sgc list option, ask for a wordlist NAME
289                 # Get help text
290                 call findLabel '.table$' '.label$'
291                 .row = findLabel.row
292                 select Table '.table$'
293                 .openDialogue$ = Get value... '.row' Helptext
294                 call convert_praat_to_latin1 '.openDialogue$'
295                 .openDialogue$ = convert_praat_to_latin1.text$
296                 .wordlistButton$ = replace$(wordlistTag$, " ", "_", 0)
297                 .wordlistButton$ = replace_regex$(.wordlistButton$, "^.", "\l&", 0)
298                 beginPause(.openDialogue$)
299                         sentence (wordlistTag$, "")
300                 clicked = endPause ("Cancel", "Open", 2)
301                 .wordlist_Name$ = ""
302                 if clicked = 2
303                         .wordlist_Name$ = '.wordlistButton$'$
304                 endif
305                 call install_wordlists_by_name '.wordlist_Name$'
306         else
307         call sgc2wordlist 'homeDirectory$'
308         call sgc2wordlist 'homeDirectory$'/Downloads
309         call sgc2wordlist 'homeDirectory$'/Documents
310         call sgc2wordlist 'homeDirectory$'/My Documents
311         call sgc2wordlist 'homeDirectory$'/My Documents/Downloads
312         call sgc2wordlist 'homeDirectory$'/Desktop
313         call sgc2wordlist 'preferencesAppDir$'
314         endif
315         call load_word_list "'localWordlistDir$'" 0
316     call Draw_button '.table$' '.label$' 0
317         call Draw_config_page
318 endproc
320 procedure processConfigOpenWordlist .clickX .clickY .pressed$
321         .table$ = "Config"
322         .label$ = "OpenWordlist"
323     call Draw_button '.table$' '.label$' 1
325         # Get help text
326         call findLabel '.table$' '.label$'
327         .row = findLabel.row
328         select Table '.table$'
329         .openDialogue$ = Get value... '.row' Helptext
330         call convert_praat_to_latin1 '.openDialogue$'
331         .openDialogue$ = convert_praat_to_latin1.text$
333         .wordlist_Name$ = chooseReadFile$ (.openDialogue$)
334         call install_wordlists_by_name '.wordlist_Name$'
335         call load_word_list "'localWordlistDir$'" 0
336     call Draw_button '.table$' '.label$' 0
337         call Draw_config_page
338 endproc
340 procedure processConfigSelectWords .clickX .clickY .pressed$
341         .table$ = "Config"
342         .label$ = "SelectWords"
343     call Draw_button '.table$' '.label$' 1
344     
345         select Table 'wordlist$'
346         te.numberOfWords = Get number of rows
347     .currentWord = te.currentWord
348     if .currentWord <= 0 or .currentWord > te.numberOfWords
349                 .currentWord = 1
350         endif
351     
352         # The texts
353         .helpText$ = "HELPTEXT"
354         .clearText$ = "Clear"
355         .allText$ = "All"
356         .prevWord$ = "Previous"
357         .nextWord$ = "Next"
358         .continueText$ = "Continue"
360         .pinyinText$ = "Pinyin"
361         .characterText$ = "Character"
362         .showText$ = "Show"
363         
364         clicked = -1
365         while clicked <> 5
366                 select Table 'wordlist$'
367                 .pinyin$ = Get value: .currentWord, "Pinyin"
368                 .character$ = Get value: .currentWord, "Character"
369                 .showValueText$ = Get value: .currentWord, "Show"
370                 if .showValueText$ = "-"
371                         .showValue = 0
372                 else
373                         .showValue = 1
374                 endif
375                 .showVariable$ = replace_regex$(.showText$, ".+", "\l&", 0)
376                 '.showVariable$' = .showValue
378                 # The user text input window (beginPause .... endPause)
379                 beginPause(.helpText$)
380                         text (.pinyinText$, .pinyin$)
381                         text (.characterText$, .character$)
382                         boolean (.showText$, .showValue)
383                 clicked = endPause ("'.clearText$'", "'.allText$'", "'.prevText$'", "'.nextText$'", "'.continueText$'", 5, 5)
384                 if clicked = 1
385                         for .i to te.numberOfWords
386                                 Set string value: .i, "Show", "-"
387                         endfor
388                 elsif clicked = 2
389                         for .i to te.numberOfWords
390                                 Set string value: .i, "Show", "+"
391                         endfor
392                 else
393                         .showValue = '.showVariable$'
394                         .showWord$ = "-"
395                         if .showValue <> 0
396                                 .showWord$ = "+"
397                         endif
399                         Set string value: .currentWord, "Show", .showWord$
400                         if clicked = 3
401                                 .currentWord -= 1
402                                 if .currentWord <= 0
403                                         .currentWord = te.numberOfWords
404                                 endif
405                         elsif clicked = 4
406                                 .currentWord += 1
407                                 if .currentWord > te.numberOfWords
408                                         .currentWord = 1
409                                 endif
410                         endif
411                 endif
412         endwhile
413     
414     call Draw_button '.table$' '.label$' 0
415 endproc
417 procedure processConfigPerfSummary .clickX .clickY .pressed$
418         .table$ = "Config"
419         .label$ = "PerfSummary"
420         
421         call testLoadTable SummaryToneEvaluation
422         if testLoadTable.table > 0
423                 call Draw_button '.table$' '.label$' 1
424                 call loadTable SummaryToneEvaluation
425                 call write_tabbed_table SummaryToneEvaluation Evaluation_'config.language$'
426                 demoWaitForInput()
427                 select Table SummaryToneEvaluation
428                 Remove
430                 call Draw_button '.table$' '.label$' 0
431                 call Draw_config_page
432         endif
433 endproc
435 procedure processConfigListPerf .clickX .clickY .pressed$
436         .table$ = "Config"
437         .label$ = "ListPerf"
438     call Draw_button '.table$' '.label$' 1
439         
440         call write_tabbed_table 'initialiseSGC2.toneevaluation_table$' Evaluation_'config.language$'
441         demoWaitForInput()
442         
443     call Draw_button '.table$' '.label$' 0
444         call Draw_config_page
445 endproc
447 procedure processConfigSavePerf .clickX .clickY .pressed$
448         .table$ = "Config"
449         .label$ = "SavePerf"
450     call Draw_button '.table$' '.label$' 1
451         
452         # Get help text
453         call findLabel '.table$' '.label$'
454         .row = findLabel.row
455         select Table '.table$'
456         .openDialogue$ = Get value... '.row' Helptext
457         call convert_praat_to_latin1 '.openDialogue$'
458         .openDialogue$ = convert_praat_to_latin1.text$
460         .wordlist_Name$ = chooseWriteFile$ (.openDialogue$, "Performance.Table")
461         if .wordlist_Name$ <> ""
462                 select Table 'initialiseSGC2.toneevaluation_table$'
463                 Write to table file... '.wordlist_Name$'
464         endif
465         
466     call Draw_button '.table$' '.label$' 0
467         call Draw_config_page
468 endproc
470 procedure processConfigManual .clickX .clickY .pressed$
471         .table$ = "Config"
472         .label$ = "Manual"
473         call Draw_button '.table$' '.label$' 1
474         if fileReadable("ManPages/SpeakGoodChinese_2.man")
475                 Read from file... ManPages/SpeakGoodChinese_2.man
476         else
477                 Go to manual page... SpeakGoodChinese 2
478         endif
479         # Wait until the manual is put to the background
480         demoWaitForInput()
481     call Draw_button '.table$' '.label$' 0
482     demo Erase all
483     call Draw_config_page
484 endproc
486 ###############################################################
488 # Obligatory button Processing Routines
490 # These MUST be defined
492 ###############################################################
494 procedure processConfigReturn .clickX .clickY .pressed$
495         .table$ = "Config"
496         .label$ = "Return"
497         call Draw_button '.table$' '.label$' 1
498         call write_preferences ""
499 endproc
501 procedure processConfigRefresh .clickX .clickY .pressed$
502         .table$ = "Config"
503         .label$ = "Refresh"
504         call Draw_config_page
505 endproc
507 procedure processConfigCredits .clickX .clickY .pressed$
508         .table$ = "Config"
509         .label$ = "Credits"
510         call Draw_button '.table$' '.label$' 1
511         call write_text_table Credits_'config.language$'
512         demoWaitForInput()
513     call Draw_button '.table$' '.label$' 0
514     demo Erase all
515     call Draw_config_page
516 endproc
518 procedure processConfigHelp .clickX .clickY .pressed$
519         .table$ = "Config"
520         .label$ = "Help"
521         call help_loop  '.table$' Draw_config_page
522 endproc
524 ###############################################################
526 # Miscelaneous supporting code
528 ###############################################################
529 procedure install_wordlists_by_name .wordlist_Name$
530         if .wordlist_Name$ <> ""
531                 if index(.wordlist_Name$, "wordlist.")
532                         .wordlist_Name$ = replace_regex$(.wordlist_Name$, "[/\\]wordlist\.([^/\\]+)$", "", 0)
533                 elsif index_regex(.wordlist_Name$, "(?i\.(wav|flac|iaf[fc]|mp3))")
534                         .wordlist_Name$ = replace_regex$(.wordlist_Name$, "[/\\][^/\\]+$", "", 0)
535                 endif
536                 if index_regex(.wordlist_Name$, "[/\\]")
537                         .sourceDir$ = left$(.wordlist_Name$, rindex_regex(.wordlist_Name$, "[/\\]") -1)
538                         .file$ = right$(.wordlist_Name$, length(.wordlist_Name$) - rindex_regex(.wordlist_Name$, "[/\\]"))
539                         call readWordlist "'.sourceDir$'" '.file$'
540                 else
541                         .start = 1
542                         if index(.wordlist_Name$, ".")
543                                 .start = 4
544                         endif
545                         .extension1$ = ".sgc"
546                         .extension2$ = ".Table"
547                         .extension3$ = ".txt"
548                         .extension4$ = ".tsv"
549                         .extension5$ = ""
550                         for .e from .start to 5
551                                 .currentExtension$ = .extension'.e'$
552                         call readWordlist "'homeDirectory$'" '.wordlist_Name$''.currentExtension$'
553                         call readWordlist "'homeDirectory$'/Downloads" '.wordlist_Name$''.currentExtension$'
554                         call readWordlist "'homeDirectory$'/Documents" '.wordlist_Name$''.currentExtension$'
555                         call readWordlist "'homeDirectory$'/My Documents/Downloads" '.wordlist_Name$''.currentExtension$'
556                         call readWordlist "'homeDirectory$'/My Documents" '.wordlist_Name$''.currentExtension$'
557                         call readWordlist "'homeDirectory$'/Desktop" '.wordlist_Name$''.currentExtension$'
558                         call readWordlist "'preferencesAppDir$'" '.wordlist_Name$''.currentExtension$'
559                         endfor
560                 endif
561         endif
562 endproc
564 # Word lists: It is a VERY good idea to make sure that word-lists
565 # have unique names.
566 procedure load_word_list .localdir$ .relnumber
567         call clean_up_sound
568     
569     # Remove old word list
570     if wordlist$ <> ""
571                 select Table 'wordlist$'
572                 Remove
573                 call wipeArea 'wipeWordlistArea$'
574                 wordlist$ = ""
575     endif
576     
577         # Create Table that will recieve the wordlists and directories
578         Create Table with column names... AllWordLists 0 Name Directory
579         .te.currentWordlistRow = 0
580         
581         # First the global word lists
582         if fileReadable(globalwordlists$) or fileReadable("'globalwordlists$'/directory.txt")
583         Create Strings as directory list... WordList 'globalwordlists$'
584         .numLists = Get number of strings
585         for .i to .numLists
586             select Strings WordList
587             .currentName$ = Get string... '.i'
588                         if .currentName$ <> "directory.txt"
589                                 select Table AllWordLists
590                                 .listExist = Search column: "Name", .currentName$
591                                 if not .listExist
592                                         Append row
593                                         .te.currentWordlistRow = Get number of rows
594                                         Set string value... '.te.currentWordlistRow' Name '.currentName$'
595                                 .currentDirectory$ = globalwordlists$+"/"+.currentName$
596                                         Set string value... '.te.currentWordlistRow' Directory '.currentDirectory$'
597                                 endif
598                         endif
599         endfor
600         select Strings WordList
601         Remove
602         endif
603         
604         # Now the preferences word lists
605         if fileReadable(sgc2wordlists$) or fileReadable("'sgc2wordlists$'/directory.txt")
606         Create Strings as directory list... WordList 'sgc2wordlists$'
607         .numLists = Get number of strings
608         for .i to .numLists
609                         select Strings WordList
610             .currentName$ = Get string... '.i'
611                         if .currentName$ <> "directory.txt"
612                                 select Table AllWordLists
613                                 .listExist = Search column: "Name", .currentName$
614                                 if not .listExist
615                                         Append row
616                                         .te.currentWordlistRow = Get number of rows
617                                         Set string value... '.te.currentWordlistRow' Name '.currentName$'
618                                 .currentDirectory$ = sgc2wordlists$+"/"+.currentName$
619                                         Set string value... '.te.currentWordlistRow' Directory '.currentDirectory$'
620                                 endif
621                         endif
622         endfor
623         select Strings WordList
624         Remove
625         endif
627         # End with the word lists in the distribution
628         call CreateCreateWordlists
629         select Table CreateWordlists
630     .numLists = Get number of rows
631         for .i to .numLists
632                 select Table CreateWordlists
633                 .currentName$ = Get value... '.i' Name
634                 if .currentName$ <> "directory.txt"
635                         select Table AllWordLists
636                         .listExist = Search column: "Name", .currentName$
637                         if not .listExist
638                                 .procedureName$ = replace_regex$(.currentName$, "[^\w\-\.]", "_", 0)
639                                 select Table AllWordLists
640                                 Append row
641                                 .te.currentWordlistRow = Get number of rows
642                                 Set string value... '.te.currentWordlistRow' Name '.currentName$'
643                                 .currentDirectory$ = "*call Create'.procedureName$'"
644                                 Set string value... '.te.currentWordlistRow' Directory '.currentDirectory$'
645                         endif
646                 endif
647         endfor
648         select Table CreateWordlists
649         Remove
650         
651         # Finally, the local word lists
652         if fileReadable(.localdir$) or fileReadable("'.localdir$'/directory.txt")
653         Create Strings as directory list... WordList '.localdir$'
654         .numLists = Get number of strings
655         for .i to .numLists
656             select Strings WordList
657             .currentName$ = Get string... '.i'
658                         if .currentName$ <> "directory.txt"
659                                 select Table AllWordLists
660                                 .listExist = Search column: "Name", .currentName$
661                                 if not .listExist
662                                         Append row
663                                         .te.currentWordlistRow = Get number of rows
664                                         Set string value... '.te.currentWordlistRow' Name '.currentName$'
665                                 .currentDirectory$ = .localdir$+"/"+.currentName$
666                                         Set string value... '.te.currentWordlistRow' Directory '.currentDirectory$'
667                                 endif
668                         endif
669         endfor
670         select Strings WordList
671         Remove
672     endif
674         # Get the position of the current word list
675         select Table AllWordLists
676         .currentNumber = 1
677     .numLists = Get number of rows
679         if wordlistName$ <> ""
680                 select Table AllWordLists
681                 .currentNumber = Search column... Name 'wordlistName$'
682         endif
684     wordlistNum = .currentNumber + .relnumber
685     if wordlistNum > .numLists
686         wordlistNum = 1
687         elsif wordlistNum < 1 and .numLists > 0
688                 wordlistNum = .numLists
689     endif
690     select Table AllWordLists
691     wordlistName$ = Get value... 'wordlistNum' Name
692         .dirWordlistName$ = Get value... 'wordlistNum' Directory
693     .dirString$ = replace_regex$(.dirWordlistName$, "[ ]", "&", 0)
694         
695         # Read in full tables
696         if fileReadable("'.dirString$'/wordlist.Table")
697                 call readTable '.dirString$'/wordlist.Table
698         if readTable.tableID > 0
699                         Rename... 'wordlistName$'
700                         # Praat wil change the name if it feels like it
701                         wordlist$ = selected$("Table")
702                         # Add a Sound column if it is not present
703                         .soundIndex = Get column index: "Sound"
704                         if .soundIndex <= 0
705                                 Append column: "Sound"
706                         endif
707                 else
708                         .numLists = 0
709                         goto EMERGENCYEXIT
710                 endif
711         # Handle (legacy) simple word lists
712         elsif fileReadable("'.dirString$'/wordlist.txt")
713                 Create Table with column names... "'wordlistName$'" 0 Pinyin Character Sound Translation
714         wordlist$ = selected$("Table")
715                 Read Strings from raw text file... '.dirString$'/wordlist.txt
716                 Rename... RawWordList
717                 .numWordStrings = Get number of strings
718                 for .i to .numWordStrings
719                         select Strings RawWordList
720                         .currentFile$ = "-"
721                         .currentChar$ = "-"
722                         .currentTrans$ = "-"
723                         .currentLine$ = Get string... '.i'
724                         # Remove leading whitespace
725                         .currentLine$ = replace_regex$(.currentLine$, "^[ \t]+", "", 0)
726                         .separatorIndex = index_regex(.currentLine$, "[ \t;\-]")
727                         if .separatorIndex <= 0
728                                 .separatorIndex = length(.currentLine$) + 1
729                         endif
730                         .currentPinyin$ = left$(.currentLine$, .separatorIndex-1)
731                         .currentLine$ = right$(.currentLine$, length(.currentLine$) - .separatorIndex)
732                         # There is more on the line, but we do not know what
733                         if length(.currentLine$) > 0
734                                 while length(.currentLine$) > 0
735                                         .separatorIndex = index_regex(.currentLine$, "[\t;]")
736                                         if .separatorIndex <= 0
737                                                 .separatorIndex = length(.currentLine$)+1
738                                         endif
739                                         .currentItem$ = left$(.currentLine$, .separatorIndex-1)
740                                         .currentLine$ = right$(.currentLine$, length(.currentLine$) - .separatorIndex )
741                                         if index_regex(.currentItem$, ".(spx|flac|wav|mp3)")
742                                                 # Audio
743                                                 .currentFile$ = .currentItem$
744                                         elsif index_regex(.currentItem$, "[a-zA-Z0-9]") > 0
745                                                 # Translation
746                                                 .currentTrans$ = .currentItem$
747                                         elsif index_regex(.currentItem$, "[^ \t\r\l]") > 0 && index_regex(.currentItem$, "[a-zA-Z0-9\-]") <= 0
748                                                 # Characters
749                                                 .currentChar$ = .currentItem$
750                                         endif
751                                 endwhile
752                         endif
753                         if .currentFile$ = "-"
754                                 if fileReadable("'.dirString$'/'.currentPinyin$'.spx")
755                                         .currentFile$ = .currentPinyin$+".spx"
756                                 elsif fileReadable("'.dirString$'/'.currentPinyin$'.flac")
757                                         .currentFile$ = .currentPinyin$+".flac"
758                                 elsif fileReadable("'.dirString$'/'.currentPinyin$'.wav")
759                                         .currentFile$ = .currentPinyin$+".wav"
760                                 elsif fileReadable("'.dirString$'/'.currentPinyin$'.mp3")
761                                         .currentFile$ = .currentPinyin$+".mp3"
762                                 endif
763                         endif
764                         select Table 'wordlist$'
765                         Append row
766                         Set string value... '.i' Pinyin '.currentPinyin$'
767                         Set string value... '.i' Sound '.currentFile$'
768                         Set string value... '.i' Character '.currentChar$'
769                         Set string value... '.i' Translation '.currentTrans$'
770                 endfor
771                 select Strings RawWordList
772                 Remove
773                 
774                 select Table 'wordlist$'
775         elsif fileReadable(.dirString$) or fileReadable("'.dirString$'/directory.txt")
776                 Create Table with column names... "'wordlistName$'" 0 Pinyin Sound
777         wordlist$ = selected$("Table")
778                 Create Strings as file list... RawWordList '.dirString$'/*
779                 .numWordStrings = Get number of strings
780                 .i = 0
781                 for .j to .numWordStrings
782                         select Strings RawWordList
783                         .currentLine$ = Get string... '.j'
784                         .currentFile$ = extractWord$(.currentLine$, "")
785                         if index_regex(.currentFile$, "\.(spx|flac|wav|mp3)")
786                                 .currentPinyin$ = left$(.currentFile$, index(.currentFile$, ".")-1)
787                                 select Table 'wordlist$'
788                                 Append row
789                                 .i += 1
790                                 Set string value... '.i' Pinyin '.currentPinyin$'
791                                 Set string value... '.i' Sound '.currentFile$'
792                         endif
793                 endfor
794                 select Strings RawWordList
795                 Remove
796                 
797                 select Table 'wordlist$'
798         elsif startsWith(.dirString$, "*call ")
799                 .callProcedure$ = right$(.dirString$, length(.dirString$)-1)
800                 '.callProcedure$'
801                 wordlist$ = selected$("Table")
802         else
803                 # Nothing, get out
804                 .numLists = 0
805                 goto EMERGENCYEXIT              
806         endif
808         # Can this wordlist be deleted?
809         if fileReadable("'sgc2wordlists$'/'wordlistName$'") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.txt") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.Table")
810                 config.deleteWordlist = 0
811         else
812                 config.deleteWordlist = -1              
813         endif
815         # Check first column name and add Character, Translation and Show columns if missing
816         if wordlist$ <> ""
817                 select Table 'wordlist$'
818                 # HAck to correct odd behavior of tables with unicode characters
819                 .firstColumn$ = Get column label: 1
820                 if index_regex(.firstColumn$, "^[^!-~]") > 0
821                         .firstColumn$ = replace_regex$(.firstColumn$, "^[^!-~]", "", 0)
822                         Set column label (index): 1, .firstColumn$
823                 endif
824                 
825         te.numberOfWords = Get number of rows
826                 .characterColumn = Get column index... Character
827                 if not .characterColumn
828                         Append column... Character
829                         for .i to te.numberOfWords
830                                 Set string value... '.i' Character -
831                         endfor
832                 endif
833                 .translationColumn = Get column index... Translation
834                 if not .translationColumn
835                         Append column... Translation
836                         for .i to te.numberOfWords
837                                 Set string value... '.i' Translation -
838                         endfor
839                 endif
840                 .showColumn = Get column index... Show
841                 if not .showColumn
842                         Append column... Show
843                         for .i to te.numberOfWords
844                                 Set string value... '.i' Show +
845                         endfor
846                 endif
847         endif
848         
849         # Remove all rows without Pinyin
850         .numRows = Get number of rows
851         for i to .numRows
852                 .rowNum = .numRows - i + 1
853                 .pinyinValue$ = Get value... '.rowNum' Pinyin
854                 if not index_regex(.pinyinValue$, "[a-zA-Z0-9]")
855                         Remove row... '.rowNum'
856                 endif
857         endfor
858         te.numberOfWords = Get number of rows
859         
860         # Shuffle words if requested
861     if config.shuffleLists
862         Randomize rows
863     endif
865         # Clean up
866         label EMERGENCYEXIT
867     select Table AllWordLists
868     Remove
869         
870     # There were no Word Lists
871     label NOWORDLISTS
872     if .numLists <= 0
873         wordlistName$ = wordlistName$+" No Word Lists available"
874         wordlistNum = 1
875                 Create Table with column names... "'wordlistName$'" 0 Pinyin Character Translation Sound
876         wordlist$ = selected$("Table")
877         .i = 0
878                 Append row
879                 .i += 1
880                 Set string value... '.i' Pinyin ni3hao3
881                 Set string value... '.i' Character 你好
882                 Set string value... '.i' Translation hello
883                 Set string value... '.i' Sound -
884                 Append row
885                 .i += 1
886                 Set string value... '.i' Pinyin xie4xie0
887                 Set string value... '.i' Character 谢谢
888                 Set string value... '.i' Translation thanks
889                 Set string value... '.i' Sound -
890                 Append row
891                 .i += 1
892                 Set string value... '.i' Pinyin zai4jian4
893                 Set string value... '.i' Character 再见
894                 Set string value... '.i' Translation goodbye
895                 Set string value... '.i' Sound -
896         te.numberOfWords = Get number of rows
897     endif
899         call set_window_title 'buttons$' 'wordlistName$'
900 endproc
902 procedure next_word
903         if wordlist$ <> ""
904                 select Table 'wordlist$'
905                 .showCurrent$ = "-"
906                 if te.currentWord < 0 or te.currentWord > te.numberOfWords
907                         te.currentWord = 0
908                 endif
909                 while .showCurrent$ = "-" and te.currentWord <= te.numberOfWords
910                         te.currentWord += 1
911                         if te.currentWord <= te.numberOfWords
912                                 .showCurrent$ = Get value... 'te.currentWord' Show
913                         endif
914                 endwhile
915         endif
916 endproc
918 procedure previous_word
919         if wordlist$ <> ""
920                 select Table 'wordlist$'
921                 .showCurrent$ = "-"
922                 if te.currentWord <= 0
923                         te.currentWord = te.numberOfWords + 1
924                 endif
925                 while .showCurrent$ = "-" and te.currentWord > 0
926                         te.currentWord -= 1
927                         if te.currentWord > 0
928                                 .showCurrent$ = Get value... 'te.currentWord' Show
929                         endif
930                 endwhile
931         endif
932 endproc
934 procedure display_word_list_name
935     .xtext = 50
936     .ytext = 12
937    call reset_viewport
938     .displayWordList$ = replace_regex$(wordlistName$, "[_]", " ", 0)
939     call wipeArea 'wipeWordlistArea$'
940         call adjustFontSizeOnHeight 'defaultFont$' 'defaultFontSize' 5
941         .currentFontSize = adjustFontSizeOnHeight.newFontSize
943     demo Blue
944         demo Text special... '.xtext' Centre '.ytext' Bottom Helvetica '.currentFontSize' 0 '.displayWordList$'
945     demo Black
946         demoShow()
947         call set_font_size 'defaultFontSize'
948 endproc
950 procedure write_word_list
951         # Write current Pinyin text
952         call display_text Black
953         
954         # Write the current word list name
955         call display_word_list_name
956 endproc
958 procedure start_logging
959         if fileReadable("'preferencesLogDir$'/logPerformance.txt")
960                 .logDirectory$ < 'preferencesLogDir$'/logPerformance.txt
961                 .logDirectory$ = extractWord$(.logDirectory$, "")
962                 if .logDirectory$ = "" or not (fileReadable(.logDirectory$) or  fileReadable("'.logDirectory$'/directory.txt")
963                         .logDirectory$ = "'preferencesLogDir$'"
964                 endif
965                 currentLogDirectory$ = "'.logDirectory$'/log'logtimeStamp$'"
966                 createDirectory(currentLogDirectory$)
967                 if not fileReadable("'currentLogDirectory$'/wordlist.Table")
968                         .headerLine$ = "Pinyin'tab$'Character'tab$'Sound'newline$'"
969                         .headerLine$ > 'currentLogDirectory$'/wordlist.Table
970                 endif
971                         # Flip switch
972                         config.logPerformance = 1
973         endif
974 endproc
976 procedure log_command .logtext$
977         if logging
978                 fileappend "'currentLogDirectory$'/logFile.txt" '.logtext$''newline$'
979         endif
980 endproc
982 procedure log_performance .recordedSound$ .register .proficiency .pinyin$ .choice$
983         # Log files
984         .currentDate$ = date$()
985         .timeStamp$ = replace_regex$(.currentDate$, "[^a-zA-Z0-9\-_]", "-", 0)
986         .choiceText$ = replace_regex$(.choice$, "[^a-zA-Z0-9\-_]", "-", 0)
988         if config.logPerformance and fileReadable("'preferencesLogDir$'/logPerformance.txt")
989            .outfilename$ = .pinyin$+"_"+.choice$+"_'.register'_"+.timeStamp$+".wav"
990            .logtext$ = "# #+.pinyin$+tab$+.choice$+tab$+"'.register'Hz"+tab$+.currentDate$+tab$+.outfilename$+newline$
991        # Plain log text
992            fileappend 'currentLogDirectory$'/logFile.txt '.logtext$'
993            
994        # A wordlist.Table
995        fileappend 'currentLogDirectory$'/wordlist.Table '.pinyin$''tab$''.choice$''tab$''.outfilename$''newline$'
996        # The recorded sound
997            select Sound 'recordedSound$'
998            Write to WAV file... 'currentLogDirectory$'/'.outfilename$'
999         endif
1000 endproc
1002 procedure paint_logging_light
1003     select Table Config
1004     .row = Search column... Label !Logging
1005         if .row < 1
1006                 exit Button Table Config does not have a row with label !Logging
1007         endif
1008         # Get button values
1009     .leftX = Get value... '.row' LeftX
1010     .rightX = Get value... '.row' RightX
1011     .lowY = Get value... '.row' LowY
1012     .highY = Get value... '.row' HighY
1013     .buttonColor$ = Get value... '.row' Color
1014     .centerX = (.leftX + .rightX)/2
1015     .centerY = (.lowY + .highY)/2
1016     .radius = (.highY - .lowY )/(4*2)
1017     .wipeRadius = 1.1*.radius
1018     if config.logPerformance and fileReadable("'preferencesLogDir$'/logPerformance.txt")
1019         demo Paint circle... White '.centerX' '.centerY' '.wipeRadius'
1020         demo Paint circle... '.buttonColor$' '.centerX' '.centerY' '.radius'
1021         demoShow()
1022     else
1023         demo Paint circle... White '.centerX' '.centerY' '.wipeRadius'
1024         demoShow()
1025     endif
1026 endproc
1028 # Uninstall word lists
1029 procedure removeWordlist .deletedWordlistName$
1030     .targetDir$ = ""
1031     if fileReadable("'sgc2wordlists$'/'.deletedWordlistName$'") or fileReadable("'sgc2wordlists$'/'.deletedWordlistName$'/wordlist.txt") or fileReadable("'sgc2wordlists$'/'.deletedWordlistName$'/wordlist.Table")
1032         .targetDir$ = "'sgc2wordlists$'/'.deletedWordlistName$'"
1033     endif
1034         if .targetDir$ <> ""
1035         Create Strings as file list... DeleteList '.targetDir$'
1036         .numdeleteFiles = Get number of strings
1037         for .i to .numdeleteFiles
1038                 .file$ = Get string... '.i'
1039                 deleteFile("'.targetDir$'/'.file$'")
1040         endfor
1041         filedelete '.targetDir$'
1042         # Check whether the directory was actually deleted. Make sure this is a valid directory name!
1043         # That is, it does not contain funny characters, nor funny names
1044         if index_regex(.deletedWordlistName$, "[^a-zA-Z0-9_ .\-]") <= 0 and index(.deletedWordlistName$, "..") <= 0 and index_regex(.deletedWordlistName$, "[a-zA-Z]") > 0
1045                         if windows
1046                                 nocheck system rmdir "'.targetDir$'" /s /q
1047                         elsif fileReadable(.targetDir$)
1048                                 system bash -rc -- 'rm -r -- "'.targetDir$'"'
1049                         endif
1050                 endif
1051                 # Remove deleted word list
1052                 select Strings DeleteList
1053                 plus Table 'wordlist$'
1054                 Remove
1055                 wordlist$ = ""
1056         endif
1057 endproc
1059 # Install word lists
1060 procedure sgc2wordlist .sourceDir$
1061         if startsWith(.sourceDir$, "preferencesDirectory$")
1062                 .sourceDir$ = replace$(.sourceDir$, "preferencesDirectory$", preferencesDirectory$)
1063         endif
1065         .targetDirectory$ = "'sgc2wordlists$'"
1066         if  fileReadable(.sourceDir$) or fileReadable("'.sourceDir$'/directory.txt")
1067                 Create Strings as file list... PackageList '.sourceDir$'/*.sgc
1068                 .numFiles = Get number of strings
1069                 for .i to .numFiles
1070                         select Strings PackageList
1071                         .file$ = Get string... '.i'
1072                         call readWordlist '.sourceDir$' '.file$'
1073                 endfor
1075                 select Strings PackageList
1076                 Remove
1077         endif
1078 endproc
1080 # Debuggin remarks!!!
1081 # fileReadable(<directory>) does not work in Windows
1082 # The file paths / -> \\ must be performed on the filenames in Windows before the system_nocheck is given
1083 # And yet only the 7z decompression has been implemented
1084 windowsUnzipCommand$ = ""
1085 if fileReadable("C:\Program Files\7-Zip\7z.exe")
1086         windowsUnzipCommand$ = """C:\Program Files\7-Zip\7z.exe"" e"
1087 endif
1088 procedure readWordlist .sourceDir$ .file$
1089         # No use doing anything if the source does not exist
1090         if fileReadable("'.sourceDir$'/'.file$'") or fileReadable("'.sourceDir$'/'.file$'/wordlist.txt") or fileReadable("'.sourceDir$'/'.file$'/wordlist.Table")
1091                 # What will be the target wordlist directory?
1092                 .targetDirectory$ = "'sgc2wordlists$'"
1093                 .dirname$ = left$(.file$, rindex(.file$, ".")-1)
1094                 if .dirname$ = ""
1095                         .dirname$ = .file$
1096                 endif
1097                 .wordlistDirectory$ = .targetDirectory$+"/"+.dirname$
1098                 # Wordlist directory does not exist, neither locally nor in the preferences
1099                 .wordListExists = 0
1100                 .tmpDirs = nocheck Create Strings as directory list... TMPWORDLISTS '.targetDirectory$'/
1101                 if .tmpDirs != undefined and .tmpDirs > 0
1102                         .numDirs = Get number of strings
1103                         for .d to .numDirs
1104                                 select .tmpDirs
1105                                 .currentString$ = Get string... '.d'
1106                                 if .currentString$ = .dirname$
1107                                         .wordListExists = 1
1108                                 endif
1109                         endfor
1110                         Remove
1111                 endif
1112                 if not (.wordListExists or fileReadable(.dirname$) or fileReadable("'.dirname$'/directory.txt") or fileReadable(.wordlistDirectory$) or fileReadable("'.wordlistDirectory$'/directory.txt"))
1113                         .wasWordList = 0
1114                         # Move source to destination
1115                         if index(.file$, ".sgc") or index(.file$, ".zip")
1116                                 if index_regex(.wordlistDirectory$, "[^a-zA-Z0-9_\.\- /~\:]") <= 0 and index_regex(.dirname$, "[^a-zA-Z0-9_\.\- ]") <= 0 and not (windows and windowsUnzipCommand$ = "")
1117                                         # Create wordlist directory
1118                                         createDirectory(.wordlistDirectory$)
1119                                         .wasWordList = 1
1120                                         if macintosh or unix
1121                                                 system bash -rc -- 'cp "'.sourceDir$'/'.file$'" "'.wordlistDirectory$'/"'
1122                                                 system cd ''.wordlistDirectory$'';bash -rc -- 'unzip "'.file$'"'
1123                                         elsif windows and windowsUnzipCommand$ <> ""
1124                                                 .winWordListDirectory$ = replace_regex$(.wordlistDirectory$, "/", "\\", 0)
1125                                                 .winSourceDirectory$ = replace_regex$("'.sourceDir$'\'.file$'", "/", "\\", 0)
1126                                                 system copy "'.winSourceDirectory$'" "'.winWordListDirectory$'" /Y
1127                                                 system chdir /d "'.winWordListDirectory$'" && 'windowsUnzipCommand$' "'.file$'"
1128                                         endif
1129                                 endif
1130                                 deleteFile("'.wordlistDirectory$'/'.file$'")
1131                                 # Remove if not valid!
1132                                 if fileReadable("'.wordlistDirectory$'/wordlist.Table") or fileReadable("'.wordlistDirectory$'/wordlist.txt") or fileReadable("'.wordlistDirectory$'/LICENSE.txt")
1133                                         if fileReadable("'.wordlistDirectory$'/wordlist.Table")
1134                                                 call readTable '.sourceDir$'/'.file$'
1135                                                 if readTable.tableID > 0
1136                                                         select readTable.tableID
1137                                                         # Hack around odd behavior of column index
1138                                                         .pinyinCol = 0
1139                                                         .firstColumn$ = Get column label: 1
1140                                                         .firstColumn$ = replace_regex$(.firstColumn$, "^[^!-~]", "", 0)
1141                                                         if .firstColumn$ = "Pinyin"
1142                                                                 .pinyinCol = 1
1143                                                         else
1144                                                                 .pinyinCol = Get column index... Pinyin
1145                                                         endif
1146                                                         Remove
1147                                                         # No Pinyin in table
1148                                                         if .pinyinCol <= 0
1149                                                                 .wasWordList = 0
1150                                                         endif
1151                                                 else
1152                                                         .wasWordList = 0
1153                                                 endif
1154                                         endif
1155                                 else
1156                                         # None of wordlist.Table, wordlist.txt, nor LICENSE.txt
1157                                         .wasWordList = 0
1158                                 endif
1159                                 ### REALLY DANGEROUS STUFF, SHOULD BE HANDLED BETTER
1160                                 if .wasWordList = 0
1161                                         # Remove newly created directory
1162                                         if index_regex(.wordlistDirectory$, "[^a-zA-Z0-9_\.\- /~\:]") <= 0 and index_regex(.dirname$, "[^a-zA-Z0-9_\.\- ]") <= 0 and index(.dirname$, "..") <= 0
1163                                                 if macintosh or unix
1164                                                         system bash -rc -- 'rm -r "'.wordlistDirectory$'/"'
1165                                                 elsif windows
1166                                                         system rmdir /Q /S "'.winWordListDirectory$'/"
1167                                                 endif
1168                                         endif
1169                                 endif
1170                         elsif index_regex(.file$, "\.(Table|txt|tsv)")
1171                                 # Check whether this is a valid table
1172                                 call readTable '.sourceDir$'/'.file$'
1173                                 if readTable.tableID > 0
1174                                         select readTable.tableID
1175                                         # Hack around odd behavior of column index
1176                                         .pinyinCol = 0
1177                                         .firstColumn$ = Get column label: 1
1178                                         .firstColumn$ = replace_regex$(.firstColumn$, "^[^!-~]", "", 0)
1179                                         if .firstColumn$ = "Pinyin"
1180                                                 .pinyinCol = 1
1181                                         else
1182                                                 .pinyinCol = Get column index... Pinyin
1183                                         endif
1184                                         Remove
1185                                         
1186                                         if .pinyinCol > 0
1187                                                 # Create wordlist directory
1188                                                 createDirectory(.wordlistDirectory$)
1189                                                 .wasWordList = 1
1190                                                 .extension$ = replace_regex$(.file$, "^.+\.(Table|txt|tsv)$", "\1", 0)
1191                                                 if .extension$ = "tsv"
1192                                                         .extension$ = "Table"
1193                                                 endif
1194                                                 if macintosh or unix
1195                                                         system bash -rc -- 'cp "'.sourceDir$'/'.file$'" "'.wordlistDirectory$'/wordlist.'.extension$'"'
1196                                                 elsif windows
1197                                                         .winWordListDirectory$ = replace_regex$(.wordlistDirectory$, "/", "\\", 0)
1198                                                         .winSourceDirectory$ = replace_regex$("'.sourceDir$'\'.file$'", "/", "\\", 0)
1199                                                         system copy "'.winSourceDirectory$'" "'.winWordListDirectory$'\wordlist.'.extension$'" /q
1200                                                 endif
1201                                         endif
1202                                 endif
1203                         elsif fileReadable("'.sourceDir$'/'.file$'/wordlist.Table") or fileReadable("'.sourceDir$'/'.file$'/wordlist.txt") or fileReadable("'.sourceDir$'/'.file$'/LICENSE.txt")
1204                                 # Copy wordlist directory
1205                                 if index_regex(.file$, "[^a-zA-Z0-9_\.\- ]") <= 0
1206                                         .wasWordList = 1
1207                                         if macintosh or unix
1208                                                 system bash -rc -- 'cp -r "'.sourceDir$'/'.file$'" "'.wordlistDirectory$'"'
1209                                         elsif windows
1210                                                 createDirectory(.wordlistDirectory$)
1211                                                 .winWordListDirectory$ = replace_regex$(.wordlistDirectory$, "/", "\\", 0)
1212                                                 .winSourceDirectory$ = replace_regex$("'.sourceDir$'\'.file$'", "/", "\\", 0)
1213                                                 system xcopy "'.winSourceDirectory$'" "'.winWordListDirectory$'" /s /e /q
1214                                         endif
1215                                 endif
1216                         endif
1217                         
1218                         # Set current word list to read list
1219                         if .wasWordList
1220                                 wordlistName$ = .dirname$
1221                         else
1222                                 .table$ = "Config"
1223                                 .label$ = "!NotAWordlist"
1225                                 # Get help text
1226                                 call findLabel '.table$' '.label$'
1227                                 .row = findLabel.row
1228                                 select Table '.table$'
1229                                 .helpText$ = Get value... '.row' Helptext
1230                                 .filetext$ = replace_regex$("'.sourceDir$'/'.file$'", "_", "\\_ ", 0)
1231                         call write_text_popup 'defaultFont$' 14 '.helpText$' "'.filetext$'"
1232                                 # Wait for confirmation
1233                                 demoWaitForInput()
1234                         endif
1235                 endif
1236         endif
1237 endproc