Worked on adding wordlists to current wordlist
[sgc2.git] / Config.praat
blob65b9cf0037c0729ab2e801c76bbca340a37410d7
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 DrawSaveAudio .color$ .x .y .size
90     .size /= 2
91         .y += .size
92     if .color$ = "White"
93         .color$ = "White"
94     elsif .color$ = "Blue"
95         .color$ = "{0.5,0.5,1}"
96     else
97         .color$ = "Blue"
98     endif
99     demo Paint circle... '.color$' '.x' '.y' '.size'
100 endproc
102 ###############################################################
104 # Obligatory button Drawing Routines
106 # These MUST be defined
108 ###############################################################
110 procedure DrawReturn .color$ .x .y .size
111     call DrawConfig '.color$' '.x' '.y' '.size'
112 endproc
114 # Set the correct button states after redrawing the window
115 procedure setConfigMainPage
116     call Draw_button 'config$' +SaveAudio 'sgc.saveAudioOn'
117 endproc
119 ###############################################################
121 # Button Processing Routines
123 ###############################################################
125 procedure processConfigShuffleLists .clickX .clickY .pressed$
126         .table$ = "Config"
127         .label$ = "ShuffleLists"
128         config.shuffleLists = not config.shuffleLists
129         .displayButton = 2*config.shuffleLists
130     call Draw_button '.table$' '.label$' '.displayButton'
131 endproc
133 procedure processConfigAdaptiveLists .clickX .clickY .pressed$
134         .table$ = "Config"
135         .label$ = "AdaptiveLists"
136         config.adaptiveLists = not config.adaptiveLists
137         .displayButton = 2*config.adaptiveLists
138     call Draw_button '.table$' '.label$' '.displayButton'
139 endproc
141 procedure processConfigUseSoundExample .clickX .clickY .pressed$
142         .table$ = "Config"
143         .label$ = "UseSoundExample"
144         config.useSoundExample = not config.useSoundExample
145         .displayButton = 2*config.useSoundExample
146     call Draw_button '.table$' '.label$' '.displayButton'
147 endproc
148         
149 procedure processConfigSynthesis .tts$ .clickX .clickY .pressed$
150         .table$ = "Config"
151         .label$ = "Synthesis_'.tts$'"
152         if sgc2.synthesizer > 0 or (speakCommandFile$ <> "" and fileReadable(speakCommandFile$))
153                 if config.synthesis$ = ""
154                         config.synthesis$ = .tts$
155                         .displayButton = 2
156                 else
157                         config.synthesis$ = ""
158                         .displayButton = 0
159                 endif
160         else
161                 config.synthesis$ = "_DISABLED_"
162                 .displayButton = -1
163         endif
164     call Draw_button '.table$' '.label$' '.displayButton'
165 endproc
166         
167 procedure processConfigStrict .clickX .clickY .pressed$
168         .table$ = "Config"
169         .label$ = "Strict"
170         .tmp = 'config.strict$'
171         .tmp += 1
172         if .tmp > sgc.highestLevel
173                 .tmp = 0
174         endif
175         config.strict$ = "'.tmp'"
176         if .tmp > 0
177                 .displayButton = 2
178         else
179                 .displayButton = 0
180         endif
181         # Change TTS for Strict!
182         call set_up_TTS
183     call Draw_button '.table$' '.label$' '.displayButton'
184 endproc
186 procedure processConfigDisplayPinyin .clickX .clickY .pressed$
187         .table$ = "Config"
188         .label$ = "DisplayPinyin"
189         config.displayPinyin = not config.displayPinyin
190         .displayButton = 2*config.displayPinyin
191     call Draw_button '.table$' '.label$' '.displayButton'
192 endproc
193                 
194 procedure processConfigDisplayChar .clickX .clickY .pressed$
195         .table$ = "Config"
196         .label$ = "DisplayChar"
197         config.displayChar = not config.displayChar
198         .displayButton = 2*config.displayChar
199     call Draw_button 'table$' '.label$' '.displayButton'
200 endproc
202 procedure processConfigDisplayTrans .clickX .clickY .pressed$
203         .table$ = "Config"
204         .label$ = "DisplayTrans"
205         config.displayTrans = not config.displayTrans
206         .displayButton = 2*config.displayTrans
207     call Draw_button 'table$' '.label$' '.displayButton'
208 endproc
210 procedure processConfigDisplayNumbers .clickX .clickY .pressed$
211         .table$ = "Config"
212         .label$ = "DisplayNumbers"
213         config.displayNumbers = not config.displayNumbers
214         .displayButton = 2*config.displayNumbers
215     call Draw_button 'table$' '.label$' '.displayButton'
216 endproc
218 procedure processConfigLanguage .language$ .clickX .clickY .pressed$
219         .table$ = "Config"
220         .label$ = "Language_'.language$'"
221         call processLanguageCodes '.table$' '.label$'
222 endproc
223         
224 procedure processConfigShowBackground .clickX .clickY .pressed$
225         .table$ = "Config"
226         .label$ = "ShowBackground"
227         config.showBackground = not config.showBackground
228         .displayButton = 2*config.showBackground
229     call Draw_button 'table$' '.label$' '.displayButton'
230 endproc
232 procedure processConfigInput .input$ .clickX .clickY .pressed$
233         .table$ = "Config"
234         .label$ = "Input_'.input$'"
235     call Draw_button '.table$' Input_'config.input$' 0
236         config.input$ = .input$
237     call Draw_button '.table$' Input_'config.input$' 2
238 endproc
240 procedure processConfigRegister .register .clickX .clickY .pressed$
241         .table$ = "Config"
242         .label$ = "Register_'.register'"
243         call setRegisterFromLabel '.table$' '.label$'
244 endproc
245         
246 procedure setRegisterFromLabel .table$ .label$
247     call Draw_button '.table$' Register_'config.register' 0
248     call Draw_button '.table$' '.label$' 2
249     # Someone might have to use more than 3 chars for the config.register code
250     .numChars = length(.label$) - length("Register_")
251         .registerText$ = right$(.label$, .numChars)
252         config.register = '.registerText$'
253 endproc
255 procedure processConfigDeleteWordlist .clickX .clickY .pressed$
256         .table$ = "Config"
257         .label$ = "DeleteWordlist"
259     # Do not process undeletable word lists, only those stored in the 
260     # preferencesDirectory$ can be deleted
261     if fileReadable("'sgc2wordlists$'/'wordlistName$'") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.txt") or     fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.Table")
262                 call findLabel '.table$' !'.label$'
263                 if findLabel.row > 0
264                 select Table '.table$'
265                 .alertText$ = Get value... 'findLabel.row' Text
266                 .confirmKey$ = Get value... 'findLabel.row' Key
267                 .popupText$ = Get value... 'findLabel.row' Helptext
268         else
269             exit Cannot find delete directive: '.table$' !'.label$'
270         endif
271         call write_text_popup 'defaultFont$' 14 '.popupText$'
272         call Draw_button '.table$' '.label$' 2
273         alertText$ = .alertText$
274         call Draw_button '.table$' '.label$' 3
275         alertText$ = ""
276         
277                 # Wait for confirmation
278                 demoWaitForInput()
279         if demoInput(.confirmKey$)
280                 .deleteWordListDir$ = wordlistName$
281                 call load_word_list "'localWordlistDir$'" 1
282                 call removeWordlist '.deleteWordListDir$'
283                         call load_word_list "'localWordlistDir$'" 0
284         endif
285                 call Draw_button '.table$' '.label$' 0
286                 call Draw_config_page
287     endif
288 endproc
290 wordlistTag$ = "Wordlist name"        
291 procedure processConfigInstallWordlist .clickX .clickY .pressed$
292         .table$ = "Config"
293         .label$ = "InstallWordlist"
294     call Draw_button '.table$' '.label$' 1
295         if windows
296                 # Do not use the automatic sgc list option, ask for a wordlist NAME
297                 # Get help text
298                 call findLabel '.table$' '.label$'
299                 .row = findLabel.row
300                 select Table '.table$'
301                 .openDialogue$ = Get value... '.row' Helptext
302                 call convert_praat_to_latin1 '.openDialogue$'
303                 .openDialogue$ = convert_praat_to_latin1.text$
304                 .wordlistButton$ = replace$(wordlistTag$, " ", "_", 0)
305                 .wordlistButton$ = replace_regex$(.wordlistButton$, "^.", "\l&", 0)
306                 beginPause(.openDialogue$)
307                         sentence (wordlistTag$, "")
308                 clicked = endPause ("Cancel", "Open", 2, 1)
309                 .wordlist_Name$ = ""
310                 if clicked = 2
311                         .wordlist_Name$ = '.wordlistButton$'$
312                 endif
313                 call install_wordlists_by_name '.wordlist_Name$'
314         else
315         call sgc2wordlist 'homeDirectory$'
316         call sgc2wordlist 'homeDirectory$'/Downloads
317         call sgc2wordlist 'homeDirectory$'/Documents
318         call sgc2wordlist 'homeDirectory$'/My Documents
319         call sgc2wordlist 'homeDirectory$'/My Documents/Downloads
320         call sgc2wordlist 'homeDirectory$'/Desktop
321         call sgc2wordlist 'preferencesAppDir$'
322         endif
323         call load_word_list "'localWordlistDir$'" 0
324     call Draw_button '.table$' '.label$' 0
325         call Draw_config_page
326 endproc
328 procedure processConfigOpenWordlist .clickX .clickY .pressed$
329         .table$ = "Config"
330         .label$ = "OpenWordlist"
331     call Draw_button '.table$' '.label$' 1
333         # Get help text
334         call findLabel '.table$' '.label$'
335         .row = findLabel.row
336         select Table '.table$'
337         .openDialogue$ = Get value... '.row' Helptext
338         call convert_praat_to_latin1 '.openDialogue$'
339         .openDialogue$ = convert_praat_to_latin1.text$
341         .wordlist_Name$ = chooseReadFile$ (.openDialogue$)
342         call install_wordlists_by_name '.wordlist_Name$'
343         call load_word_list "'localWordlistDir$'" 0
344     call Draw_button '.table$' '.label$' 0
345         call Draw_config_page
346 endproc
348 # Select the words to practise. This is quite a complex piece of code
349 procedure processConfigSelectWords .clickX .clickY .pressed$
350         .table$ = "Config"
351         .label$ = "SelectWords"
352     call Draw_button '.table$' '.label$' 1
354         # Get help text
355         call findLabel '.table$' '.label$'
356         .row = findLabel.row
357         select Table '.table$'
358         .helpText$ = Get value... '.row' Helptext
359         call convert_praat_to_latin1 '.helpText$'
360         .helpText$ = convert_praat_to_latin1.text$
361    
362     # Implement Cancel
363     select sgc.currentWordlist
364     .tmpOriginalWordlist = Copy: "Original_'wordlist$'"
366     
367     # Set current word
368         select sgc.currentWordlist
369         sgc.numberOfWords = Get number of rows
370     .currentWord = sgc.currentWord
371     if .currentWord <= 0 or .currentWord > sgc.numberOfWords or config.shuffleLists
372                 .currentWord = 1
373         endif
374     
375         # The texts
376         call get_feedback_text 'config.language$' Part
377         call convert_praat_to_latin1 'get_feedback_text.text$'
378         .partText$ = convert_praat_to_latin1.text$
379         call get_feedback_text 'config.language$' Tones
380         call convert_praat_to_latin1 'get_feedback_text.text$'
381         .toneText$ = convert_praat_to_latin1.text$
382         call get_feedback_text 'config.language$' Cancel
383         call convert_praat_to_latin1 'get_feedback_text.text$'
384         .cancelText$ = convert_praat_to_latin1.text$
385         call get_feedback_text 'config.language$' Clear
386         call convert_praat_to_latin1 'get_feedback_text.text$'
387         .clearText$ = convert_praat_to_latin1.text$
388         call get_feedback_text 'config.language$' All
389         call convert_praat_to_latin1 'get_feedback_text.text$'
390         .allText$ = convert_praat_to_latin1.text$
391         call get_feedback_text 'config.language$' Previous
392         call convert_praat_to_latin1 'get_feedback_text.text$'
393         .prevWord$ = convert_praat_to_latin1.text$
394         call get_feedback_text 'config.language$' Next
395         call convert_praat_to_latin1 'get_feedback_text.text$'
396         .nextWord$ = convert_praat_to_latin1.text$
397         call get_feedback_text 'config.language$' Continue
398         call convert_praat_to_latin1 'get_feedback_text.text$'
399         .continueText$ = convert_praat_to_latin1.text$
400         call get_feedback_text 'config.language$' Show
401         call convert_praat_to_latin1 'get_feedback_text.text$'
402         .showText$ = convert_praat_to_latin1.text$
404         .pinyinText$ = "Pinyin"
405         .characterText$ = "Character"
406         
407         # Get lesson names
408         select sgc.currentWordlist
409         .lessonCol = Get column index: "Lesson"
410         .lessonList$ = tab$
411         .numLessons = 0
412         # All shown keeps track whether all words are shown
413         # If so, selecting a lesson is preceded by a Clear All
414         .allShown = 0
415         # Sort words for consistent selection interface
416         if config.shuffleLists
417                 # Allow subdivision in lessons
418                 if .lessonCol > 0
419                         Sort rows... Lesson Pinyin
420                 else
421                         Sort rows... Pinyin
422                 endif
423         endif           
424         if .lessonCol > 0
425                 for .i to sgc.numberOfWords
426                         .currentLesson$ = Get value: .i, "Lesson"
427                         if .currentLesson$ <> "" and .currentLesson$ <> "-" and index_regex(.lessonList$, "\t'.currentLesson$'\t") <= 0
428                                 .lessonList$ = .lessonList$ + .currentLesson$ + tab$
429                                 .numLessons += 1
430                                 .lessonName$['.numLessons'] = .currentLesson$
431                         endif
432                         .shown$ = Get value: .i, "Show"
433                         if .shown$ = "-"
434                                 .allShown = 0
435                         endif
436                 endfor
437         endif
438         
439         clicked = -1
440         .numWordsPerScreen = 15
441         while clicked <> 6 and clicked <> 1
442                 .lessonSelected = -1
443                 .toneSelected = -1
444                 .firstShown = -1
445                 
446                 select sgc.currentWordlist
447                 .lessonCol = Get column index: "Lesson"
448                 # Sort words for consistent selection interface
449         if config.shuffleLists
450                         # Allow subdivision in lessons
451                         if .lessonCol > 0
452                                 Sort rows... Lesson Pinyin
453                         else
454                                 Sort rows... Pinyin
455                         endif
456         endif           
457                 .max = .numWordsPerScreen - 1
458                 if .currentWord + .max > sgc.numberOfWords
459                         .max = sgc.numberOfWords - .currentWord
460                 endif
461                 for .i from 0 to .numWordsPerScreen - 1
462                         if .i <= .max
463                                 .currentPinyin$ = Get value: .currentWord+.i, "Pinyin"
464                                 if index_regex(.currentPinyin$, "[0-9]") <= 0
465                                         call pinyin2numbers '.currentPinyin$'
466                                         .currentPinyin$ = replace_regex$(pinyin2numbers.intermediatePinyin$, ".+", "\l&", 0)
467                                         .currentPinyin$ = replace_regex$(.currentPinyin$, "[^a-zA-Z0-9]", "", 0)
468                                 endif
469                                 .pinyin$[.i] = .currentPinyin$
471                                 .character$[.i] = Get value: .currentWord+.i, "Character"
472                                 .lessonNum$[.i] = ""
473                                 if .lessonCol > 0
474                                         .lessonNum$[.i] = Get value: .currentWord+.i, "Lesson"
475                                         .lessonNum$[.i] = " : " + .lessonNum$[.i]
476                                 endif
477                                 .showText$[.i] = .pinyin$['.i']
478                                 if .character$['.i'] <> "-"
479                                         .showText$[.i] = .pinyin$['.i']+" ("+.character$['.i']+.lessonNum$['.i']+")"
480                                 elsif .lessonNum$['.i'] <> ""
481                                         .showText$[.i] = .pinyin$['.i']+" ( -"+.lessonNum$['.i']+")"
482                                 endif
483                                 .showValueText$[.i] = Get value: .currentWord+.i, "Show"
484                                 if .showValueText$[.i] = "-"
485                                         .showValue[.i] = 0
486                                 else
487                                         .showValue[.i] = 1
488                                 endif
489                                 .showVariable$[.i] = .pinyin$[.i]
490                                 .tmp$ = .showVariable$[.i]
491                                 '.tmp$' = .showValue[.i]
492                         else
493                                 .showText$[.i] = "-"
494                                 .showValue[.i] = 0
495                         endif
496                 endfor
498                 # The user text input window (beginPause .... endPause)
499                 beginPause(.helpText$)
500                         boolean (.showText$[0], .showValue[0])
501                         boolean (.showText$[1], .showValue[1])
502                         boolean (.showText$[2], .showValue[2])
503                         boolean (.showText$[3], .showValue[3])
504                         boolean (.showText$[4], .showValue[4])
505                         boolean (.showText$[5], .showValue[5])
506                         boolean (.showText$[6], .showValue[6])
507                         boolean (.showText$[7], .showValue[7])
508                         boolean (.showText$[8], .showValue[8])
509                         boolean (.showText$[9], .showValue[9])
510                         boolean (.showText$[10], .showValue[10])
511                         boolean (.showText$[11], .showValue[11])
512                         boolean (.showText$[12], .showValue[12])
513                         boolean (.showText$[13], .showValue[13])
514                         boolean (.showText$[14], .showValue[14])
515                         if .numLessons > 0
516                                 optionMenu: .partText$, 1
517                                         option: "---"
518                                         .j = 0
519                                         for .j to .numLessons
520                                                 option: .lessonName$['.j']
521                                         endfor
522                         endif
523                         optionMenu: .toneText$, 1
524                                 option: "---"
525                                 option: "0"
526                                 option: "1"
527                                 option: "2"
528                                 option: "3"
529                                 option: "4"
530                 clicked = endPause ("'.cancelText$'", "'.clearText$'", "'.allText$'", "'.prevWord$'", "'.nextWord$'", "'.continueText$'", 6, 1)
531                 
532                 if clicked = 2
533                         for .i to sgc.numberOfWords
534                                 Set string value: .i, "Show", "-"
535                         endfor
536                         .allShown = 0
537                 elsif clicked = 3
538                         for .i to sgc.numberOfWords
539                                 Set string value: .i, "Show", "+"
540                         endfor
541                         .allShown = 1
542                 elsif clicked != 1
543                         # Get selected Part BEFORE we do anything else
544                         if .numLessons > 0
545                                 .tmp$ = replace_regex$(.partText$, "^(.)", "\l\1", 0)
546                                 .lessonSelected = '.tmp$' - 1
547                         endif
548                         if .lessonSelected > 0
549                                 .allShown = 1
550                                 .firstShown = -1
551                                 select sgc.currentWordlist
552                                 for .i to sgc.numberOfWords
553                                         # Keep track of whether all are shown
554                                         .shown$ = Get value: .i, "Show"
555                                         if .shown$ = "-"
556                                                 .allShown = 0
557                                         endif
558                                 endfor
559                                 for .i to sgc.numberOfWords
560                                         # Lessons
561                                         .currentLesson$ = Get value: .i, "Lesson"
562                                         if .currentLesson$ = .lessonName$['.lessonSelected']
563                                                 Set string value: .i, "Show", "+"
564                                         elsif .allShown = 1
565                                                 Set string value: .i, "Show", "-"
566                                         endif
567                                 endfor
568                                 for .i to sgc.numberOfWords
569                                         # Keep track of whether all are shown
570                                         .shown$ = Get value: .i, "Show"
571                                         if .firstShown <=0 and .shown$ <> "-"
572                                                 .firstShown = .i
573                                         endif
574                                 endfor
575                         else
576                                 for .i from 0 to .max
577                                         .tmp$ = .showVariable$['.i']
578                                         .showValue['.i'] = '.tmp$'
579                                         .showWord$['.i'] = "-"
580                                         if .showValue['.i'] <> 0
581                                                 .showWord$['.i'] = "+"
582                                         endif
583                                         Set string value: .currentWord+.i, "Show", .showWord$['.i']
584                                 endfor
585                         endif
586                         .tmp$ = replace_regex$(.toneText$, "^(.)", "\l\1", 0)
587                         .toneSelected = '.tmp$' - 2
588                         if .toneSelected >= 0
589                                 select sgc.currentWordlist
590                                 for .i to sgc.numberOfWords
591                                         .currentPinyin$ = Get value: .i, "Pinyin"
592                                         if index_regex(.currentPinyin$, "[0-9]") <= 0
593                                                 call pinyin2numbers '.currentPinyin$'
594                                                 .currentPinyin$ = replace_regex$(pinyin2numbers.intermediatePinyin$, ".+", "\l&", 0)
595                                                 .currentPinyin$ = replace_regex$(.currentPinyin$, "[^a-zA-Z0-9]", "", 0)
596                                         endif
597                                         .tmp$ = Get value: .i, "Show"
598                                         if .tmp$ <> "-" and index(.currentPinyin$, "'.toneSelected'") > 0
599                                                 Set string value: .i, "Show", "+"
600                                         else
601                                                 Set string value: .i, "Show", "-"
602                                                 .allShown = 0
603                                         endif
604                                 endfor
605                         endif
606                         
607                         if clicked = 4
608                                 if .firstShown > 0
609                                         .currentWord = (.firstShown div .numWordsPerScreen) * .numWordsPerScreen + 1
610                                 elsif .toneSelected < 0
611                                         .currentWord -= .numWordsPerScreen
612                                 endif
613                                 if .currentWord <= 0
614                                         .currentWord = (sgc.numberOfWords div .numWordsPerScreen) * .numWordsPerScreen + 1
615                                 endif
616                         elsif clicked = 5
617                                 if .firstShown > 0
618                                         .currentWord = (.firstShown div .numWordsPerScreen) * .numWordsPerScreen + 1
619                                 elsif .toneSelected < 0
620                                         .currentWord += .numWordsPerScreen
621                                 endif
622                                 if .currentWord > sgc.numberOfWords
623                                         .currentWord = 1
624                                 endif
625                         endif
626                 endif
627                 # Reset and go to the first selected word (can shuffle list)
628                 if clicked = 6
629                         sgc.currentWord = -1
630                         call next_word
631                 endif
632         endwhile
633         
634     # Implement Cancel
635     if clicked = 1
636                 select sgc.currentWordlist
637                 Remove
638                 select .tmpOriginalWordlist
639                 Copy: wordlist$
640         endif
641         select .tmpOriginalWordlist
642         Remove
643     call Draw_button '.table$' '.label$' 0
644 endproc
646 procedure processConfigPerfSummary .clickX .clickY .pressed$
647         .table$ = "Config"
648         .label$ = "PerfSummary"
649         
650         call testLoadTable SummaryToneEvaluation
651         if testLoadTable.table > 0
652                 call Draw_button '.table$' '.label$' 1
653                 call loadTable SummaryToneEvaluation
654                 call write_tabbed_table SummaryToneEvaluation Evaluation_'config.language$'
655                 demoWaitForInput()
656                 select Table SummaryToneEvaluation
657                 Remove
659                 call Draw_button '.table$' '.label$' 0
660                 call Draw_config_page
661         endif
662 endproc
664 # Wipe current performance table and initialize a new one
665 procedure processConfigClearSummary .clickX .clickY .pressed$
666         .table$ = "Config"
667         .label$ = "ClearSummary"
668         
669     call Draw_button '.table$' '.label$' 1
670         
671         if not sgc.saveAudioOn
672                 select Table '.table$'
673                 call findLabel '.table$' !'.label$'
674                 if findLabel.row > 0
675                         .alertText$ = Get value... 'findLabel.row' Text
676                         .confirmKey$ = Get value... 'findLabel.row' Key
677                         .popupText$ = Get value... 'findLabel.row' Helptext
678                         
679                 call write_text_popup 'defaultFont$' 14 '.popupText$'
680                 call Draw_button '.table$' '.label$' 2
681                 alertText$ = .alertText$
682                 call Draw_button '.table$' '.label$' 3
683                 alertText$ = ""
684                 
685                         # Wait for confirmation
686                         demoWaitForInput()
687                 if demoInput(.confirmKey$)
688                                 sgc.savePerf$ = ""
689                                 call initialize_toneevaluation_tables
690                         endif
691                 endif
692         endif
693         
694     call Draw_button '.table$' '.label$' 'sgc.saveAudioOn'
695         call Draw_config_page
696         
697 endproc
699 procedure processConfigListPerf .clickX .clickY .pressed$
700         .table$ = "Config"
701         .label$ = "ListPerf"
702     call Draw_button '.table$' '.label$' 1
703         
704         select sgc2.performanceTable
705         View & Edit
706         demoWaitForInput()
707         
708     call Draw_button '.table$' '.label$' 0
709         call Draw_config_page
710 endproc
712 procedure processConfigOpenPerf .clickX .clickY .pressed$
713         .table$ = "Config"
714         .label$ = "OpenPerf"
715     call Draw_button '.table$' '.label$' 1
716         
717         if not sgc.saveAudioOn 
718                 # Get help text
719                 call findLabel '.table$' !'.label$'
720                 .row = findLabel.row
721                 select Table '.table$'
722                 .openDialogue$ = Get value... '.row' Helptext
723                 call convert_praat_to_latin1 '.openDialogue$'
724                 .openDialogue$ = convert_praat_to_latin1.text$
725                 if variableExists("eval.performance$")
726                         .defaultName$= "'eval.performance$'.tsv"
727                 else
728                         .defaultName$= "Performance.tsv"
729                 endif
730                 if sgc.savePerf$ <> ""
731                         .defaultName$= sgc.savePerf$
732                 endif
733                 .performance_Name$ = chooseReadFile$ (.openDialogue$)
734                 while .performance_Name$ <> "" and index_regex(.performance_Name$, "\.(tsv|TSV)$") <= 0
735                         .performance_Name$ = chooseReadFile$ (.openDialogue$)                   
736                 endwhile
737                 if .performance_Name$ <> "" and fileReadable(.performance_Name$)
738                         sgc.savePerf$ = .performance_Name$
739                         call initialize_toneevaluation_tables
740                         
741                         # Set SaveAudio directory if it is not currently "in use"
742                         if not sgc.saveAudioOn
743                                 sgc.saveAudio$ = replace_regex$(sgc.savePerf$, "[/\\][^/\\]+$", "", 0)
744                                 # We are not sure yet that this is actually an audio directory
745                                 config.audioName$ = ""
746                         endif
747                 endif
748         endif
749         
750     call Draw_button '.table$' '.label$' 'sgc.saveAudioOn'
751         call Draw_config_page
752 endproc
754 procedure processConfigSavePerf .clickX .clickY .pressed$
755         .table$ = "Config"
756         .label$ = "SavePerf"
757     call Draw_button '.table$' '.label$' 1
758         
759         if not sgc.saveAudioOn 
760                 # Get help text
761                 call findLabel '.table$' '.label$'
762                 .row = findLabel.row
763                 select Table '.table$'
764                 .openDialogue$ = Get value... '.row' Helptext
765                 call convert_praat_to_latin1 '.openDialogue$'
766                 .openDialogue$ = convert_praat_to_latin1.text$
767                 if variableExists("eval.performance$")
768                         .defaultName$= "'eval.performance$'.tsv"
769                 else
770                         .defaultName$= "Performance.tsv"
771                 endif
772                 if sgc.savePerf$ <> ""
773                         .defaultName$= sgc.savePerf$
774                 endif
775                 .performance_Name$ = chooseWriteFile$ (.openDialogue$, .defaultName$)
776                 # Ensure the right extension: ".tsv"
777                 while .performance_Name$ <> "" and not endsWith(.performance_Name$, ".tsv")
778                         .performance_Name$ = .performance_Name$ + ".tsv"
779                         .performance_Name$ = chooseWriteFile$ (.openDialogue$, .performance_Name$)
780                 endwhile
781                 if .performance_Name$ <> ""
782                         select sgc2.performanceTable
783                         Write to table file... '.performance_Name$'
784                         sgc.savePerf$ = .performance_Name$
785                 endif
786         endif
787         
788     call Draw_button '.table$' '.label$' 'sgc.saveAudioOn'
789         call Draw_config_page
790 endproc
792 procedure processConfigManual .clickX .clickY .pressed$
793         .table$ = "Config"
794         .label$ = "Manual"
795         call Draw_button '.table$' '.label$' 1
796         if fileReadable("ManPages/SpeakGoodChinese_2.man")
797                 Read from file... ManPages/SpeakGoodChinese_2.man
798         else
799                 Go to manual page... SpeakGoodChinese 2
800         endif
801         # Wait until the manual is put to the background
802         demoWaitForInput()
803     call Draw_button '.table$' '.label$' 0
804     demo Erase all
805     call Draw_config_page
806 endproc
808 procedure processConfigSaveAudio .clickX .clickY .pressed$
809         .table$ = "Config"
810         .label$ = "SaveAudio"
811     call Draw_button '.table$' '.label$' 1
812         
813         if sgc.saveAudioOn = 0
814                 # Get help text
815                 call findLabel '.table$' '.label$'
816                 .row = findLabel.row
817                 select Table '.table$'
818                 .openDialogue$ = Get value... '.row' Helptext
819                 call convert_praat_to_latin1 '.openDialogue$'
820                 .openDialogue$ = convert_praat_to_latin1.text$
821                 .defaultName$= ""
822                 sgc.saveAudio$ = chooseDirectory$ (.openDialogue$)
823                 if sgc.saveAudio$ <> ""
824                         sgc.saveAudioOn = 1
825                         .currentPathName$ = replace_regex$(sgc.saveAudio$, "[^/\\]*[/\\]?$", "", 0)
826                         .currentDirName$ = replace$(sgc.saveAudio$, .currentPathName$, "", 0)
827                         config.savePerf = -1
828                         config.openPerf = -1
829                         config.clearSummary = -1
830                         config.audioName$ = .currentDirName$
832                         # Clear performance table and open/create sgc.savePerf$
833                         sgc.savePerf$ = "'sgc.saveAudio$'/'.currentDirName$'.tsv"
834                         call initialize_toneevaluation_tables
835                         # Write empty table
836                         call update_toneevaluation_file
837                         if sgc.savePerf$ <> "" and initialiseSGC2.toneevaluation_table$ <> ""
838                                 select sgc2.performanceTable
839                                 Write to table file: sgc.savePerf$
840                         endif
841                 else
842                         config.audioName$ = ""
843                 endif
844         else
845                 sgc.saveAudioOn = 0
846                 config.savePerf = 0
847                 config.openPerf = 0
848                 config.clearSummary = 0
849                 # Store current performance table
850                 call update_toneevaluation_file
851         endif
852         
853     call Draw_button '.table$' '.label$' 'sgc.saveAudioOn'
854         call Draw_config_page
855 endproc
857 ###############################################################
859 # Obligatory button Processing Routines
861 # These MUST be defined
863 ###############################################################
865 procedure processConfigReturn .clickX .clickY .pressed$
866         .table$ = "Config"
867         .label$ = "Return"
868         call Draw_button '.table$' '.label$' 1
869         call write_preferences ""
870 endproc
872 procedure processConfigRefresh .clickX .clickY .pressed$
873         .table$ = "Config"
874         .label$ = "Refresh"
875         call Draw_config_page
876 endproc
878 procedure processConfigCredits .clickX .clickY .pressed$
879         .table$ = "Config"
880         .label$ = "Credits"
881         call Draw_button '.table$' '.label$' 1
882         call write_text_table Credits_'config.language$'
883         demoWaitForInput()
884     call Draw_button '.table$' '.label$' 0
885     demo Erase all
886     call Draw_config_page
887 endproc
889 procedure processConfigHelp .clickX .clickY .pressed$
890         .table$ = "Config"
891         .label$ = "Help"
892         call help_loop  '.table$' Draw_config_page
893 endproc
895 ###############################################################
897 # Miscelaneous supporting code
899 ###############################################################
900 procedure install_wordlists_by_name .wordlist_Name$
901         if .wordlist_Name$ <> ""
902                 if index_regex(.wordlist_Name$, "(?iwordlist|LICENSE)\.")
903                         .wordlist_Name$ = replace_regex$(.wordlist_Name$, "[/\\](?iwordlist|LICENSE)\.([^/\\]+)$", "", 0)
904                 elsif index_regex(.wordlist_Name$, "(?i\.(wav|flac|iaf[fc]|mp3))")
905                         .wordlist_Name$ = replace_regex$(.wordlist_Name$, "[/\\][^/\\]+$", "", 0)
906                 endif
907                 if index_regex(.wordlist_Name$, "[/\\]")
908                         .sourceDir$ = left$(.wordlist_Name$, rindex_regex(.wordlist_Name$, "[/\\]") -1)
909                         .file$ = right$(.wordlist_Name$, length(.wordlist_Name$) - rindex_regex(.wordlist_Name$, "[/\\]"))
910                         call readWordlist "'.sourceDir$'" '.file$'
911                 else
912                         .start = 1
913                         if index(.wordlist_Name$, ".")
914                                 .start = 4
915                         endif
916                         .extension1$ = ".sgc"
917                         .extension2$ = ".Table"
918                         .extension3$ = ".txt"
919                         .extension4$ = ".tsv"
920                         .extension5$ = ""
921                         for .e from .start to 5
922                                 .currentExtension$ = .extension'.e'$
923                         call readWordlist "'homeDirectory$'" '.wordlist_Name$''.currentExtension$'
924                         call readWordlist "'homeDirectory$'/Downloads" '.wordlist_Name$''.currentExtension$'
925                         call readWordlist "'homeDirectory$'/Documents" '.wordlist_Name$''.currentExtension$'
926                         call readWordlist "'homeDirectory$'/My Documents/Downloads" '.wordlist_Name$''.currentExtension$'
927                         call readWordlist "'homeDirectory$'/My Documents" '.wordlist_Name$''.currentExtension$'
928                         call readWordlist "'homeDirectory$'/Desktop" '.wordlist_Name$''.currentExtension$'
929                         call readWordlist "'preferencesAppDir$'" '.wordlist_Name$''.currentExtension$'
930                         endfor
931                 endif
932         endif
933 endproc
935 # Word lists: It is a VERY good idea to make sure that word-lists
936 # have unique names.
937 procedure load_word_list .localdir$ .relnumber
938         call clean_up_sound
939         if sgc.allWordLists > 0
940                 select sgc.allWordLists
941                 Remove
942                 sgc.allWordLists = -1
943         endif
944     
945     # Remove old word list
946     if wordlist$ <> ""
947                 select sgc.currentWordlist
948                 Remove
949                 call wipeArea 'wipeWordlistArea$'
950                 wordlist$ = ""
951                 sgc.currentWordlist = -1
952     endif
953     
954         # Create Table that will recieve the wordlists and directories
955         sgc.allWordLists = Create Table with column names... AllWordLists 0 Name Directory
956         .sgc.currentWordlistRow = 0
957         
958         # First the global word lists
959         if fileReadable(globalwordlists$) or fileReadable("'globalwordlists$'/directory.txt")
960         Create Strings as directory list... WordList 'globalwordlists$'
961         .numLists = Get number of strings
962         for .i to .numLists
963             select Strings WordList
964             .currentName$ = Get string... '.i'
965                         if .currentName$ <> "directory.txt"
966                                 select sgc.allWordLists
967                                 .listExist = Search column: "Name", .currentName$
968                                 if not .listExist
969                                         Append row
970                                         .sgc.currentWordlistRow = Get number of rows
971                                         Set string value... '.sgc.currentWordlistRow' Name '.currentName$'
972                                 .currentDirectory$ = globalwordlists$+"/"+.currentName$
973                                         Set string value... '.sgc.currentWordlistRow' Directory '.currentDirectory$'
974                                 endif
975                         endif
976         endfor
977         select Strings WordList
978         Remove
979         endif
980         
981         # Now the preferences word lists
982         if fileReadable(sgc2wordlists$) or fileReadable("'sgc2wordlists$'/directory.txt")
983         Create Strings as directory list... WordList 'sgc2wordlists$'
984         .numLists = Get number of strings
985         for .i to .numLists
986                         select Strings WordList
987             .currentName$ = Get string... '.i'
988                         if .currentName$ <> "directory.txt"
989                                 select sgc.allWordLists
990                                 .listExist = Search column: "Name", .currentName$
991                                 if not .listExist
992                                         Append row
993                                         .sgc.currentWordlistRow = Get number of rows
994                                         Set string value... '.sgc.currentWordlistRow' Name '.currentName$'
995                                 .currentDirectory$ = sgc2wordlists$+"/"+.currentName$
996                                         Set string value... '.sgc.currentWordlistRow' Directory '.currentDirectory$'
997                                 endif
998                         endif
999         endfor
1000         select Strings WordList
1001         Remove
1002         endif
1004         # End with the word lists in the distribution
1005         call CreateCreateWordlists
1006         select Table CreateWordlists
1007     .numLists = Get number of rows
1008         for .i to .numLists
1009                 select Table CreateWordlists
1010                 .currentName$ = Get value... '.i' Name
1011                 if .currentName$ <> "directory.txt"
1012                         select sgc.allWordLists
1013                         .listExist = Search column: "Name", .currentName$
1014                         if not .listExist
1015                                 .procedureName$ = replace_regex$(.currentName$, "[^\w\-\.]", "_", 0)
1016                                 select sgc.allWordLists
1017                                 Append row
1018                                 .sgc.currentWordlistRow = Get number of rows
1019                                 Set string value... '.sgc.currentWordlistRow' Name '.currentName$'
1020                                 .currentDirectory$ = "*call Create'.procedureName$'"
1021                                 Set string value... '.sgc.currentWordlistRow' Directory '.currentDirectory$'
1022                         endif
1023                 endif
1024         endfor
1025         select Table CreateWordlists
1026         Remove
1027         
1028         # Finally, the local word lists
1029         if fileReadable(.localdir$) or fileReadable("'.localdir$'/directory.txt")
1030         Create Strings as directory list... WordList '.localdir$'
1031         .numLists = Get number of strings
1032         for .i to .numLists
1033             select Strings WordList
1034             .currentName$ = Get string... '.i'
1035                         if .currentName$ <> "directory.txt"
1036                                 select sgc.allWordLists
1037                                 .listExist = Search column: "Name", .currentName$
1038                                 if not .listExist
1039                                         Append row
1040                                         .sgc.currentWordlistRow = Get number of rows
1041                                         Set string value... '.sgc.currentWordlistRow' Name '.currentName$'
1042                                 .currentDirectory$ = .localdir$+"/"+.currentName$
1043                                         Set string value... '.sgc.currentWordlistRow' Directory '.currentDirectory$'
1044                                 endif
1045                         endif
1046         endfor
1047         select Strings WordList
1048         Remove
1049     endif
1051         # Get the position of the current word list
1052         select sgc.allWordLists
1053         .currentNumber = 1
1054     .numLists = Get number of rows
1056         if wordlistName$ <> ""
1057                 select sgc.allWordLists
1058                 .currentNumber = Search column... Name 'wordlistName$'
1059         endif
1061     wordlistNum = .currentNumber + .relnumber
1062     if wordlistNum > .numLists
1063         wordlistNum = 1
1064         elsif wordlistNum < 1 and .numLists > 0
1065                 wordlistNum = .numLists
1066     endif
1067     select sgc.allWordLists
1068     wordlistName$ = Get value... 'wordlistNum' Name
1069         .dirWordlistName$ = Get value... 'wordlistNum' Directory
1070     .dirString$ = replace_regex$(.dirWordlistName$, "[ ]", "&", 0)
1071         
1072         # Read in full tables
1073         if fileReadable("'.dirString$'/wordlist.Table")
1074                 call readTable '.dirString$'/wordlist.Table
1075         if readTable.tableID > 0
1076                         Rename... 'wordlistName$'
1077                         # Praat wil change the name if it feels like it
1078                         wordlist$ = selected$("Table")
1079                         # Add a Sound column if it is not present
1080                         .soundIndex = Get column index: "Sound"
1081                         if .soundIndex <= 0
1082                                 Append column: "Sound"
1083                         endif
1084                 else
1085                         .numLists = 0
1086                         goto EMERGENCYEXIT
1087                 endif
1088         # Handle (legacy) simple word lists
1089         elsif fileReadable("'.dirString$'/wordlist.txt")
1090                 Create Table with column names... "'wordlistName$'" 0 Pinyin Character Sound Translation
1091         wordlist$ = selected$("Table")
1092                 Read Strings from raw text file... '.dirString$'/wordlist.txt
1093                 Rename... RawWordList
1094                 .numWordStrings = Get number of strings
1095                 for .i to .numWordStrings
1096                         select Strings RawWordList
1097                         .currentFile$ = "-"
1098                         .currentChar$ = "-"
1099                         .currentTrans$ = "-"
1100                         .currentLine$ = Get string... '.i'
1101                         # Remove leading whitespace
1102                         .currentLine$ = replace_regex$(.currentLine$, "^[ \t]+", "", 0)
1103                         .separatorIndex = index_regex(.currentLine$, "[ \t;\-]")
1104                         if .separatorIndex <= 0
1105                                 .separatorIndex = length(.currentLine$) + 1
1106                         endif
1107                         .currentPinyin$ = left$(.currentLine$, .separatorIndex-1)
1108                         .currentLine$ = right$(.currentLine$, length(.currentLine$) - .separatorIndex)
1109                         # There is more on the line, but we do not know what
1110                         if length(.currentLine$) > 0
1111                                 while length(.currentLine$) > 0
1112                                         .separatorIndex = index_regex(.currentLine$, "[\t;]")
1113                                         if .separatorIndex <= 0
1114                                                 .separatorIndex = length(.currentLine$)+1
1115                                         endif
1116                                         .currentItem$ = left$(.currentLine$, .separatorIndex-1)
1117                                         .currentLine$ = right$(.currentLine$, length(.currentLine$) - .separatorIndex )
1118                                         if index_regex(.currentItem$, ".(spx|flac|wav|mp3)")
1119                                                 # Audio
1120                                                 .currentFile$ = .currentItem$
1121                                         elsif index_regex(.currentItem$, "[a-zA-Z0-9]") > 0
1122                                                 # Translation
1123                                                 .currentTrans$ = .currentItem$
1124                                         elsif index_regex(.currentItem$, "[^ \t\r\l]") > 0 && index_regex(.currentItem$, "[a-zA-Z0-9\-]") <= 0
1125                                                 # Characters
1126                                                 .currentChar$ = .currentItem$
1127                                         endif
1128                                 endwhile
1129                         endif
1130                         if .currentFile$ = "-"
1131                                 if fileReadable("'.dirString$'/'.currentPinyin$'.spx")
1132                                         .currentFile$ = .currentPinyin$+".spx"
1133                                 elsif fileReadable("'.dirString$'/'.currentPinyin$'.flac")
1134                                         .currentFile$ = .currentPinyin$+".flac"
1135                                 elsif fileReadable("'.dirString$'/'.currentPinyin$'.wav")
1136                                         .currentFile$ = .currentPinyin$+".wav"
1137                                 elsif fileReadable("'.dirString$'/'.currentPinyin$'.mp3")
1138                                         .currentFile$ = .currentPinyin$+".mp3"
1139                                 endif
1140                         endif
1141                         select Table 'wordlist$'
1142                         Append row
1143                         Set string value... '.i' Pinyin '.currentPinyin$'
1144                         Set string value... '.i' Sound '.currentFile$'
1145                         Set string value... '.i' Character '.currentChar$'
1146                         Set string value... '.i' Translation '.currentTrans$'
1147                 endfor
1148                 select Strings RawWordList
1149                 Remove
1150                 
1151                 select Table 'wordlist$'
1152         elsif fileReadable(.dirString$) or fileReadable("'.dirString$'/directory.txt")
1153                 Create Table with column names... "'wordlistName$'" 0 Pinyin Sound
1154         wordlist$ = selected$("Table")
1155                 Create Strings as file list... RawWordList '.dirString$'/*
1156                 .numWordStrings = Get number of strings
1157                 .i = 0
1158                 for .j to .numWordStrings
1159                         select Strings RawWordList
1160                         .currentLine$ = Get string... '.j'
1161                         .currentFile$ = extractWord$(.currentLine$, "")
1162                         if index_regex(.currentFile$, "\.(spx|flac|wav|mp3)")
1163                                 .currentPinyin$ = left$(.currentFile$, index(.currentFile$, ".")-1)
1164                                 select Table 'wordlist$'
1165                                 Append row
1166                                 .i += 1
1167                                 Set string value... '.i' Pinyin '.currentPinyin$'
1168                                 Set string value... '.i' Sound '.currentFile$'
1169                         endif
1170                 endfor
1171                 select Strings RawWordList
1172                 Remove
1173                 
1174                 select Table 'wordlist$'
1175         elsif startsWith(.dirString$, "*call ")
1176                 .callProcedure$ = right$(.dirString$, length(.dirString$)-1)
1177                 '.callProcedure$'
1178                 wordlist$ = selected$("Table")
1179         else
1180                 # Nothing, get out
1181                 .numLists = 0
1182                 goto EMERGENCYEXIT
1183         endif
1185         # Can this wordlist be deleted?
1186         if fileReadable("'sgc2wordlists$'/'wordlistName$'") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.txt") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.Table")
1187                 config.deleteWordlist = 0
1188         else
1189                 config.deleteWordlist = -1              
1190         endif
1192         # Check first column name and add Character, Translation and Show columns if missing
1193         if wordlist$ <> ""
1194                 select Table 'wordlist$'
1195                 # Hack to correct odd behavior of tables with unicode characters
1196                 .firstColumn$ = Get column label: 1
1197                 if index_regex(.firstColumn$, "^[^!-~]") > 0
1198                         .firstColumn$ = replace_regex$(.firstColumn$, "^[^!-~]", "", 0)
1199                         Set column label (index): 1, .firstColumn$
1200                 endif
1201                 
1202         sgc.numberOfWords = Get number of rows
1203                 .characterColumn = Get column index... Character
1204                 if not .characterColumn
1205                         Append column... Character
1206                         for .i to sgc.numberOfWords
1207                                 Set string value... '.i' Character -
1208                         endfor
1209                 endif
1210                 .translationColumn = Get column index... Translation
1211                 if not .translationColumn
1212                         Append column... Translation
1213                         for .i to sgc.numberOfWords
1214                                 Set string value... '.i' Translation -
1215                         endfor
1216                 endif
1217                 .showColumn = Get column index... Show
1218                 if not .showColumn
1219                         Append column... Show
1220                         for .i to sgc.numberOfWords
1221                                 Set string value... '.i' Show +
1222                         endfor
1223                 endif
1224         endif
1225         
1226         # Remove all rows without Pinyin
1227         .numRows = Get number of rows
1228         for i to .numRows
1229                 .rowNum = .numRows - i + 1
1230                 .pinyinValue$ = Get value... '.rowNum' Pinyin
1231                 if not index_regex(.pinyinValue$, "[a-zA-Z0-9]")
1232                         Remove row... '.rowNum'
1233                 endif
1234         endfor
1235         sgc.numberOfWords = Get number of rows
1236         
1237         # Shuffle words if requested
1238     if config.shuffleLists
1239         Randomize rows
1240     endif
1242         # Clean up
1243         label EMERGENCYEXIT
1244     #select sgc.allWordLists
1245     #Remove
1246         
1247     # There were no Word Lists
1248     label NOWORDLISTS
1249     if .numLists <= 0
1250         wordlistName$ = wordlistName$+" No Word Lists available"
1251         wordlistNum = 1
1252                 Create Table with column names... "'wordlistName$'" 0 Pinyin Character Translation Sound
1253         wordlist$ = selected$("Table")
1254         .i = 0
1255                 Append row
1256                 .i += 1
1257                 Set string value... '.i' Pinyin ni3hao3
1258                 Set string value... '.i' Character 你好
1259                 Set string value... '.i' Translation hello
1260                 Set string value... '.i' Sound -
1261                 Append row
1262                 .i += 1
1263                 Set string value... '.i' Pinyin xie4xie0
1264                 Set string value... '.i' Character 谢谢
1265                 Set string value... '.i' Translation thanks
1266                 Set string value... '.i' Sound -
1267                 Append row
1268                 .i += 1
1269                 Set string value... '.i' Pinyin zai4jian4
1270                 Set string value... '.i' Character 再见
1271                 Set string value... '.i' Translation goodbye
1272                 Set string value... '.i' Sound -
1273         sgc.numberOfWords = Get number of rows
1274     endif
1275         
1276         select Table 'wordlist$'
1277         sgc.currentWordlist = selected()
1278         call set_window_title 'buttons$' 'wordlistName$'
1279 endproc
1281 procedure read_wordlist .wordlistName$ .dirString$
1282         # Read in full tables
1283         if fileReadable("'.dirString$'/wordlist.Table")
1284                 call readTable '.dirString$'/wordlist.Table
1285                 .wordlistID = selected ()
1286         if .wordlistID > 0
1287                         Rename... '.wordlistName$'
1288                         # Praat wil change the name if it feels like it
1289                         .wordlist$ = selected$("Table")
1290                         # Add a Sound column if it is not present
1291                         .soundIndex = Get column index: "Sound"
1292                         if .soundIndex <= 0
1293                                 Append column: "Sound"
1294                         endif
1295                 else
1296                         goto EMERGENCYEXITWL
1297                 endif
1298         # Handle (legacy) simple word lists
1299         elsif fileReadable("'.dirString$'/wordlist.txt")
1300                 .wordlistID = Create Table with column names... "'.wordlistName$'" 0 Pinyin Character Sound Translation
1301                 .wordlist$ = selected$("Table")
1302                 Read Strings from raw text file... '.dirString$'/wordlist.txt
1303                 Rename... RawWordList
1304                 .numWordStrings = Get number of strings
1305                 for .i to .numWordStrings
1306                         select Strings RawWordList
1307                         .currentFile$ = "-"
1308                         .currentChar$ = "-"
1309                         .currentTrans$ = "-"
1310                         .currentLine$ = Get string... '.i'
1311                         # Remove leading whitespace
1312                         .currentLine$ = replace_regex$(.currentLine$, "^[ \t]+", "", 0)
1313                         .separatorIndex = index_regex(.currentLine$, "[ \t;\-]")
1314                         if .separatorIndex <= 0
1315                                 .separatorIndex = length(.currentLine$) + 1
1316                         endif
1317                         .currentPinyin$ = left$(.currentLine$, .separatorIndex-1)
1318                         .currentLine$ = right$(.currentLine$, length(.currentLine$) - .separatorIndex)
1319                         # There is more on the line, but we do not know what
1320                         if length(.currentLine$) > 0
1321                                 while length(.currentLine$) > 0
1322                                         .separatorIndex = index_regex(.currentLine$, "[\t;]")
1323                                         if .separatorIndex <= 0
1324                                                 .separatorIndex = length(.currentLine$)+1
1325                                         endif
1326                                         .currentItem$ = left$(.currentLine$, .separatorIndex-1)
1327                                         .currentLine$ = right$(.currentLine$, length(.currentLine$) - .separatorIndex )
1328                                         if index_regex(.currentItem$, ".(spx|flac|wav|mp3)")
1329                                                 # Audio
1330                                                 .currentFile$ = .currentItem$
1331                                         elsif index_regex(.currentItem$, "[a-zA-Z0-9]") > 0
1332                                                 # Translation
1333                                                 .currentTrans$ = .currentItem$
1334                                         elsif index_regex(.currentItem$, "[^ \t\r\l]") > 0 && index_regex(.currentItem$, "[a-zA-Z0-9\-]") <= 0
1335                                                 # Characters
1336                                                 .currentChar$ = .currentItem$
1337                                         endif
1338                                 endwhile
1339                         endif
1340                         if .currentFile$ = "-"
1341                                 if fileReadable("'.dirString$'/'.currentPinyin$'.spx")
1342                                         .currentFile$ = .currentPinyin$+".spx"
1343                                 elsif fileReadable("'.dirString$'/'.currentPinyin$'.flac")
1344                                         .currentFile$ = .currentPinyin$+".flac"
1345                                 elsif fileReadable("'.dirString$'/'.currentPinyin$'.wav")
1346                                         .currentFile$ = .currentPinyin$+".wav"
1347                                 elsif fileReadable("'.dirString$'/'.currentPinyin$'.mp3")
1348                                         .currentFile$ = .currentPinyin$+".mp3"
1349                                 endif
1350                         endif
1351                         select .wordlistID
1352                         Append row
1353                         Set string value... '.i' Pinyin '.currentPinyin$'
1354                         Set string value... '.i' Sound '.currentFile$'
1355                         Set string value... '.i' Character '.currentChar$'
1356                         Set string value... '.i' Translation '.currentTrans$'
1357                 endfor
1358                 select Strings RawWordList
1359                 Remove
1360                 
1361                 select .wordlistID
1362         elsif fileReadable(.dirString$) or fileReadable("'.dirString$'/directory.txt")
1363                 .wordlistID = Create Table with column names... "'.wordlistName$'" 0 Pinyin Sound
1364         .wordlist$ = selected$("Table")
1365                 .tmp = Create Strings as file list... RawWordList '.dirString$'/*
1366                 .numWordStrings = Get number of strings
1367                 .i = 0
1368                 for .j to .numWordStrings
1369                         select .tmp
1370                         .currentLine$ = Get string... '.j'
1371                         .currentFile$ = extractWord$(.currentLine$, "")
1372                         if index_regex(.currentFile$, "\.(spx|flac|wav|mp3)")
1373                                 .currentPinyin$ = left$(.currentFile$, index(.currentFile$, ".")-1)
1374                                 select sgc.currentWordlist
1375                                 Append row
1376                                 .i += 1
1377                                 Set string value... '.i' Pinyin '.currentPinyin$'
1378                                 Set string value... '.i' Sound '.currentFile$'
1379                         endif
1380                 endfor
1381                 select .tmp
1382                 Remove
1383                 
1384                 select sgc.currentWordlist
1385         elsif startsWith(.dirString$, "*call ")
1386                 .callProcedure$ = right$(.dirString$, length(.dirString$)-1)
1387                 '.callProcedure$'
1388                 .wordlistID = selected()
1389                 .wordlist$ = selected$("Table")
1390         else
1391                 # Nothing, get out
1392                 goto EMERGENCYEXITWL
1393         endif
1394         
1395         # Add the path to the file Sound file names
1396         select .wordlistID
1397         .numRows = Get number of rows
1398         for .w to .numRows
1399                 .soundfile$ = Get value: .w, "Sound"
1400                 if index_regex(.soundfile$, "[/\\]") <= 0
1401                         if index_regex(.dirString$, "[/\\]$")
1402                                 .soundfile$ = .dirString$+.soundfile$
1403                         elsif index_regex(.dirString$, "[\\]")
1404                                 .soundfile$ = .dirString$+"\\"+.soundfile$
1405                         else
1406                                 .soundfile$ = .dirString$+"/"+.soundfile$
1407                         endif
1408                         Set string value: .w, "Sound", .soundfile$ 
1409                 endif
1410         endfor
1411         
1412         label EMERGENCYEXITWL
1414 endproc
1416 procedure merge_into_wordlist .newTableID .lessonPostfix$
1417         select sgc.currentWordlist
1418         .oldLessonColumn = Get column index: "Lesson"
1420         select .newTableID
1421         .numRows = Get number of rows
1422         .lessonColumn = Get column index: "Lesson"
1423         .characterColumn = Get column index: "Character"
1424         .soundColumn = Get column index: "Sound"
1425         .translationColumn = Get column index: "Translation"
1426         for .w to .numRows
1427                 .currentFile$ = "-"
1428                 .currentChar$ = "-"
1429                 .currentTrans$ = "-"
1430                 .currentLesson$ = "-"
1431                 
1432                 select .newTableID
1433                 .currentPinyin$ = Get value: .w, "Pinyin"
1434                 if .soundColumn > 0
1435                         .currentFile$ = Get value: .w, "Sound"
1436                 endif
1437                 if .characterColumn > 0
1438                         .currentChar$ = Get value: .w, "Character"
1439                 endif
1440                 if .translationColumn > 0
1441                         .currentTrans$ = Get value: .w, "Translation"
1442                 endif
1443                 if .lessonColumn > 0
1444                         .currentLesson$ = Get value: .w, "Lesson"
1445                 endif
1446                 select sgc.currentWordlist
1447                 Append row
1448                 .n = Get number of rows
1449                 Set string value: .n, "Pinyin", .currentPinyin$
1450                 Set string value: .n, "Sound", .currentFile$
1451                 Set string value: .n, "Character", .currentChar$
1452                 Set string value: .n, "Translation", .currentTrans$
1453                 if .oldLessonColumn > 0
1454                         if .currentLesson$ = "-" or .currentLesson$ = "" or .currentLesson$ = "?"
1455                                 Set string value: .n, "Lesson", .lessonPostfix$
1456                         else
1457                                 Set string value: .n, "Lesson", .currentLesson$+" "+.lessonPostfix$
1458                         endif
1459                 endif
1460         endfor
1461 endproc
1463 procedure next_word
1464         if wordlist$ <> ""
1465                 select sgc.currentWordlist
1466                 .showCurrent$ = "-"
1467                 if sgc.currentWord < 0 or sgc.currentWord > sgc.numberOfWords
1468                 if config.shuffleLists
1469                             Randomize rows
1470                 endif
1471                         sgc.currentWord = 0
1472                 endif
1473                 while .showCurrent$ = "-" and sgc.currentWord <= sgc.numberOfWords
1474                         sgc.currentWord += 1
1475                         if sgc.currentWord <= sgc.numberOfWords
1476                                 .showCurrent$ = Get value... 'sgc.currentWord' Show
1477                         endif
1478                 endwhile
1479         endif
1480 endproc
1482 procedure previous_word
1483         if wordlist$ <> ""
1484                 select sgc.currentWordlist
1485                 .showCurrent$ = "-"
1486                 if sgc.currentWord <= 0
1487                 if config.shuffleLists
1488                             Randomize rows
1489                 endif
1490                         sgc.currentWord = sgc.numberOfWords + 1
1491                 endif
1492                 while .showCurrent$ = "-" and sgc.currentWord > 0
1493                         sgc.currentWord -= 1
1494                         if sgc.currentWord > 0
1495                                 .showCurrent$ = Get value... 'sgc.currentWord' Show
1496                         endif
1497                 endwhile
1498         endif
1499 endproc
1501 procedure display_word_list_name
1502     .xtext = 50
1503     .ytext = 12
1504    call reset_viewport
1505     .displayWordList$ = replace_regex$(wordlistName$, "[_]", " ", 0)
1506     call wipeArea 'wipeWordlistArea$'
1507         call adjustFontSizeOnHeight 'defaultFont$' 'defaultFontSize' 5
1508         .currentFontSize = adjustFontSizeOnHeight.newFontSize
1510     demo Blue
1511         demo Text special... '.xtext' Centre '.ytext' Bottom 'defaultFont$' '.currentFontSize' 0 '.displayWordList$'
1512     demo Black
1513         demoShow()
1514         call set_font_size 'defaultFontSize'
1515 endproc
1517 procedure write_word_list
1518         # Write current Pinyin text
1519         call display_text Black
1520         
1521         # Write the current word list name
1522         call display_word_list_name
1523 endproc
1525 procedure paint_saveAudio_light
1526     select Table 'config$'
1527     .row = Search column... Label SaveAudio
1528         if .row < 1
1529                 exit Button Table Config does not have a row with label SaveAudio
1530         endif
1531         # Get button values
1532     .leftX = Get value... '.row' LeftX
1533     .rightX = Get value... '.row' RightX
1534     .lowY = Get value... '.row' LowY
1535     .highY = Get value... '.row' HighY
1536     .buttonColor$ = Get value... '.row' Color
1537     # The button text and symbol
1538         .horWC = demo Horizontal mm to wc... 10.0
1539         .verWC = demo Vertical mm to wc... 10.0
1540         if .verWC > 0
1541                 .verCoeff = .horWC / .verWC
1542         else
1543                 .verCoeff = 1
1544         endif
1546     .centerX = (.leftX + .rightX)/2
1547     .centerY = .lowY + 0.6*(.highY-.lowY)
1548     .radius = min(.verCoeff * (.highY - .lowY ), (.rightX - .leftX))/3
1549     .wipeRadius = 1.1*.radius
1550     call DrawSaveAudio White '.centerX' '.centerY' '.wipeRadius'
1552     if sgc.saveAudioOn and sgc.saveAudio$ <> ""
1553                 call DrawSaveAudio "DarkBlue" '.centerX' '.centerY' '.radius'
1554     endif
1555     demoShow()
1556 endproc
1558 # Uninstall word lists
1559 procedure removeWordlist .deletedWordlistName$
1560     .targetDir$ = ""
1561     if fileReadable("'sgc2wordlists$'/'.deletedWordlistName$'") or fileReadable("'sgc2wordlists$'/'.deletedWordlistName$'/wordlist.txt") or fileReadable("'sgc2wordlists$'/'.deletedWordlistName$'/wordlist.Table")
1562         .targetDir$ = "'sgc2wordlists$'/'.deletedWordlistName$'"
1563     endif
1564         if .targetDir$ <> ""
1565         Create Strings as file list... DeleteList '.targetDir$'
1566         .numdeleteFiles = Get number of strings
1567         for .i to .numdeleteFiles
1568                 .file$ = Get string... '.i'
1569                 deleteFile("'.targetDir$'/'.file$'")
1570         endfor
1571         filedelete '.targetDir$'
1572         # Check whether the directory was actually deleted. Make sure this is a valid directory name!
1573         # That is, it does not contain funny characters, nor funny names
1574         if index_regex(.deletedWordlistName$, "[^a-zA-Z0-9_ .\-]") <= 0 and index(.deletedWordlistName$, "..") <= 0 and index_regex(.deletedWordlistName$, "[a-zA-Z]") > 0
1575                         if windows
1576                                 nocheck system rmdir "'.targetDir$'" /s /q
1577                         elsif fileReadable(.targetDir$)
1578                                 system bash -rc -- 'rm -r -- "'.targetDir$'"'
1579                         endif
1580                 endif
1581                 # Remove deleted word list
1582                 select Strings DeleteList
1583                 plus Table 'wordlist$'
1584                 Remove
1585                 wordlist$ = ""
1586         endif
1587 endproc
1589 # Install word lists
1590 procedure sgc2wordlist .sourceDir$
1591         if startsWith(.sourceDir$, "preferencesDirectory$")
1592                 .sourceDir$ = replace$(.sourceDir$, "preferencesDirectory$", preferencesDirectory$)
1593         endif
1595         .targetDirectory$ = "'sgc2wordlists$'"
1596         if  fileReadable(.sourceDir$) or fileReadable("'.sourceDir$'/directory.txt")
1597                 Create Strings as file list... PackageList '.sourceDir$'/*.sgc
1598                 .numFiles = Get number of strings
1599                 for .i to .numFiles
1600                         select Strings PackageList
1601                         .file$ = Get string... '.i'
1602                         call readWordlist '.sourceDir$' '.file$'
1603                 endfor
1605                 select Strings PackageList
1606                 Remove
1607         endif
1608 endproc
1610 # Debuggin remarks!!!
1611 # fileReadable(<directory>) does not work in Windows
1612 # The file paths / -> \\ must be performed on the filenames in Windows before the system_nocheck is given
1613 # And yet only the 7z decompression has been implemented
1614 windowsUnzipCommand$ = ""
1615 if fileReadable("C:\Program Files\7-Zip\7z.exe")
1616         windowsUnzipCommand$ = """C:\Program Files\7-Zip\7z.exe"" -y e"
1617         windowsUnzipDestDir$ = " -o"
1618 elsif fileReadable("C:\Program Files\WinZip\winzip32.exe")
1619         # !!! Find a way to include the output folder !!!
1620         windowsUnzipCommand$ = "C:\Program Files\WinZip\winzip32.exe"" -min -e -o -j "
1621         windowsUnzipDestDir$ = ""
1622 endif
1623 procedure readWordlist .sourceDir$ .file$
1624         # No use doing anything if the source does not exist
1625         if fileReadable("'.sourceDir$'/'.file$'") or fileReadable("'.sourceDir$'/'.file$'/wordlist.txt") or fileReadable("'.sourceDir$'/'.file$'/wordlist.Table")
1626                 # What will be the target wordlist directory?
1627                 .targetDirectory$ = "'sgc2wordlists$'"
1628                 .dirname$ = left$(.file$, rindex(.file$, ".")-1)
1629                 if .dirname$ = ""
1630                         .dirname$ = .file$
1631                 endif
1632                 .wordlistDirectory$ = .targetDirectory$+"/"+.dirname$
1633                 # Wordlist directory does not exist, neither locally nor in the preferences
1634                 .wordListExists = 0
1635                 .tmpDirs = nocheck Create Strings as directory list... TMPWORDLISTS '.targetDirectory$'/
1636                 if .tmpDirs != undefined and .tmpDirs > 0
1637                         .numDirs = Get number of strings
1638                         for .d to .numDirs
1639                                 select .tmpDirs
1640                                 .currentString$ = Get string... '.d'
1641                                 if .currentString$ = .dirname$
1642                                         .wordListExists = 1
1643                                 endif
1644                         endfor
1645                         Remove
1646                 endif
1647                 if not (.wordListExists or fileReadable(.dirname$) or fileReadable("'.dirname$'/directory.txt") or fileReadable(.wordlistDirectory$) or fileReadable("'.wordlistDirectory$'/directory.txt"))
1648                         .wasWordList = 0
1649                         # Move source to destination
1650                         # Use this if you want to allow direct loading of ZIP files. Could lead to problems.
1651                         # if index(.file$, ".sgc") or index(.file$, ".zip")
1652                         # 
1653                         if index(.file$, ".sgc")
1654                                 if index_regex(.wordlistDirectory$, "[^a-zA-Z0-9_\.\- /~\:]") <= 0 and index_regex(.dirname$, "[^a-zA-Z0-9_\.\- ]") <= 0 and not (windows and windowsUnzipCommand$ = "")
1655                                         # Create wordlist directory
1656                                         createDirectory(.wordlistDirectory$)
1657                                         .wasWordList = 1
1658                                         if macintosh or unix
1659                                                 system bash -rc -- 'unzip -j "'.sourceDir$'/'.file$'" -d "'.wordlistDirectory$'"'
1660                                         elsif windows and windowsUnzipCommand$ <> ""
1661                                                 .winWordListDirectory$ = replace_regex$(.wordlistDirectory$, "/", "\\", 0)
1662                                                 .winSourceDirectory$ = replace_regex$("'.sourceDir$'\'.file$'", "/", "\\", 0)
1663                                                 system mkdir "'.winWordListDirectory$'" & 'windowsUnzipCommand$' "'.winSourceDirectory$'" 'windowsUnzipDestDir$'"'.winWordListDirectory$'"
1664                                         endif
1665                                 elsif (windows and windowsUnzipCommand$ = "")
1666                                         # Warn to install 7Zip
1667                                         call get_feedback_text 'config.language$' InstallUnzip
1668                                         call convert_praat_to_latin1 'get_feedback_text.text$'
1669                                         .zipText$ = convert_praat_to_latin1.text$
1670                                         call write_text_popup 'defaultFont$' 14 '.zipText$'
1671                                         # Wait for confirmation
1672                                         demoWaitForInput()
1673                                         call Draw_config_page
1674                                 endif
1675                                 # Remove if not valid!
1676                                 if fileReadable("'.wordlistDirectory$'/wordlist.Table") or fileReadable("'.wordlistDirectory$'/wordlist.txt") or fileReadable("'.wordlistDirectory$'/LICENSE.txt")
1677                                         if fileReadable("'.wordlistDirectory$'/wordlist.Table")
1678                                                 call readTable '.sourceDir$'/'.file$'
1679                                                 if readTable.tableID > 0
1680                                                         select readTable.tableID
1681                                                         # Hack around odd behavior of column index
1682                                                         .pinyinCol = 0
1683                                                         .firstColumn$ = Get column label: 1
1684                                                         .firstColumn$ = replace_regex$(.firstColumn$, "^[^!-~]", "", 0)
1685                                                         if .firstColumn$ = "Pinyin"
1686                                                                 .pinyinCol = 1
1687                                                         else
1688                                                                 .pinyinCol = Get column index... Pinyin
1689                                                         endif
1690                                                         Remove
1691                                                         # No Pinyin in table
1692                                                         if .pinyinCol <= 0
1693                                                                 .wasWordList = 0
1694                                                         endif
1695                                                 else
1696                                                         .wasWordList = 0
1697                                                 endif
1698                                         endif
1699                                 else
1700                                         # None of wordlist.Table, wordlist.txt, nor LICENSE.txt
1701                                         .wasWordList = 0
1702                                 endif
1703                                 ### REALLY DANGEROUS STUFF, SHOULD BE HANDLED BETTER
1704                                 if .wasWordList = 0
1705                                         # Remove newly created directory
1706                                         if index_regex(.wordlistDirectory$, "[^a-zA-Z0-9_\.\- /~\:]") <= 0 and index_regex(.dirname$, "[^a-zA-Z0-9_\.\- ]") <= 0 and index(.dirname$, "..") <= 0
1707                                                 if macintosh or unix
1708                                                         system bash -rc -- 'rm -r "'.wordlistDirectory$'/"'
1709                                                 elsif windows
1710                                                         system rmdir /Q /S "'.winWordListDirectory$'/"
1711                                                 endif
1712                                         endif
1713                                 endif
1714                         elsif index_regex(.file$, "\.(Table|txt|tsv)")
1715                                 # Check whether this is a valid table
1716                                 call readTable '.sourceDir$'/'.file$'
1717                                 if readTable.tableID > 0
1718                                         select readTable.tableID
1719                                         # Hack around odd behavior of column index
1720                                         .pinyinCol = 0
1721                                         .firstColumn$ = Get column label: 1
1722                                         .firstColumn$ = replace_regex$(.firstColumn$, "^[^!-~]", "", 0)
1723                                         if .firstColumn$ = "Pinyin"
1724                                                 .pinyinCol = 1
1725                                         else
1726                                                 .pinyinCol = Get column index... Pinyin
1727                                         endif
1728                                         
1729                                         if .pinyinCol > 0
1730                                                 select readTable.tableID
1731                                                 # Create wordlist directory
1732                                                 createDirectory(.wordlistDirectory$)
1733                                                 .wasWordList = 1
1734                                                 .extension$ = "Table"
1735                                                 .wordlistFilePath$ = "'.wordlistDirectory$'/wordlist.'.extension$'"
1736                                                 if windows
1737                                                         .wordlistFilePath$ = replace_regex$(.wordlistFilePath$, "/", "\\", 0)
1738                                                 endif
1739                                                 # Save
1740                                                 select readTable.tableID
1741                                                 Save as tab-separated file: .wordlistFilePath$
1742                                                 if not fileReadable(.wordlistFilePath$)
1743                                                         .wasWordList = 0
1744                                                 endif
1745                                         endif
1746                                         select readTable.tableID
1747                                         Remove
1748                                 endif
1749                         elsif fileReadable("'.sourceDir$'/'.file$'/wordlist.Table") or fileReadable("'.sourceDir$'/'.file$'/wordlist.txt") or fileReadable("'.sourceDir$'/'.file$'/LICENSE.txt")
1750                                 # Copy wordlist directory
1751                                 if index_regex(.file$, "[^a-zA-Z0-9_\.\- ]") <= 0
1752                                         .wasWordList = 1
1753                                         if macintosh or unix
1754                                                 system bash -rc -- 'cp -r "'.sourceDir$'/'.file$'" "'.wordlistDirectory$'"'
1755                                         elsif windows
1756                                                 createDirectory(.wordlistDirectory$)
1757                                                 .winWordListDirectory$ = replace_regex$(.wordlistDirectory$, "/", "\\", 0)
1758                                                 .winSourceDirectory$ = replace_regex$("'.sourceDir$'\'.file$'", "/", "\\", 0)
1759                                                 system xcopy "'.winSourceDirectory$'" "'.winWordListDirectory$'" /s /e /q
1760                                         endif
1761                                 endif
1762                         endif
1763                         
1764                         # Set current word list to read list
1765                         if .wasWordList
1766                                 wordlistName$ = .dirname$
1767                         else
1768                                 .table$ = "Config"
1769                                 .label$ = "!NotAWordlist"
1771                                 # Get help text
1772                                 call findLabel '.table$' '.label$'
1773                                 .row = findLabel.row
1774                                 select Table '.table$'
1775                                 .helpText$ = Get value... '.row' Helptext
1776                                 .printablePath$ = "'.sourceDir$'/'.file$'"
1777                                 if windows
1778                                         .printablePath$ = replace$("'.sourceDir$'\'.file$'", "\", "\bs", 0)
1779                                 endif
1780                                 .filetext$ = replace_regex$(.printablePath$, "_", "\\_ ", 0)
1781                         call write_text_popup 'defaultFont$' 14 '.helpText$' "'.filetext$'"
1782                                 # Wait for confirmation
1783                                 demoWaitForInput()
1784                         endif
1785                 endif
1786         endif
1787 endproc