4 # Praat script handling configuration page
6 # SpeakGoodChinese: Config.praat loads the code needed for the
7 # settings and the Settings page of SpeakGoodChinese.
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
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.
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.
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
29 ###############################################################
31 # Button Drawing Routines
33 ###############################################################
35 procedure DrawCredits .color$ .x .y .size
38 call adjustFontSizeOnHeight 'defaultFont$' 24 '.lineheight'
39 .currentFontSize = adjustFontSizeOnHeight.newFontSize
40 demo Paint circle... {0.2,0.2,0.8} '.x' '.y' '.size'
42 demo Text special... '.x' centre '.y' half Times '.currentFontSize' 0 i
45 call set_font_size 'defaultFontSize'
48 procedure DrawDeleteList .color$ .x .y .size
56 .displayWordList$ = replace_regex$(wordlistName$, "[_]", " ", 0)
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
67 call set_font_size '.currentFontSize'
68 demo Paint rectangle... White '.leftX' '.rightX' '.botY' '.topY'
70 demo Text... '.x' Centre '.botY' Bottom '.displayWordList$'
73 call set_font_size 'defaultFontSize'
76 procedure DrawManual .color$ .x .y .size
79 call adjustFontSizeOnHeight 'defaultFont$' 24 '.lineheight'
80 .currentFontSize = adjustFontSizeOnHeight.newFontSize
81 demo Paint circle... {0.2,0.2,0.8} '.x' '.y' '.size'
83 demo Text special... '.x' centre '.y' half Times '.currentFontSize' 0 M
86 call set_font_size 'defaultFontSize'
89 procedure DrawSaveAudio .color$ .x .y .size
94 elsif .color$ = "Blue"
95 .color$ = "{0.5,0.5,1}"
99 demo Paint circle... '.color$' '.x' '.y' '.size'
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'
114 # Set the correct button states after redrawing the window
115 procedure setConfigMainPage
116 call Draw_button 'config$' +SaveAudio 'sgc.saveAudioOn'
119 ###############################################################
121 # Button Processing Routines
123 ###############################################################
125 procedure processConfigShuffleLists .clickX .clickY .pressed$
127 .label$ = "ShuffleLists"
128 config.shuffleLists = not config.shuffleLists
129 .displayButton = 2*config.shuffleLists
130 call Draw_button '.table$' '.label$' '.displayButton'
133 procedure processConfigAdaptiveLists .clickX .clickY .pressed$
135 .label$ = "AdaptiveLists"
136 config.adaptiveLists = not config.adaptiveLists
137 .displayButton = 2*config.adaptiveLists
138 call Draw_button '.table$' '.label$' '.displayButton'
141 procedure processConfigUseSoundExample .clickX .clickY .pressed$
143 .label$ = "UseSoundExample"
144 config.useSoundExample = not config.useSoundExample
145 .displayButton = 2*config.useSoundExample
146 call Draw_button '.table$' '.label$' '.displayButton'
149 procedure processConfigSynthesis .tts$ .clickX .clickY .pressed$
151 .label$ = "Synthesis_'.tts$'"
152 if sgc2.synthesizer > 0 or (speakCommandFile$ <> "" and fileReadable(speakCommandFile$))
153 if config.synthesis$ = ""
154 config.synthesis$ = .tts$
157 config.synthesis$ = ""
161 config.synthesis$ = "_DISABLED_"
164 call Draw_button '.table$' '.label$' '.displayButton'
167 procedure processConfigStrict .clickX .clickY .pressed$
170 .tmp = 'config.strict$'
172 if .tmp > sgc.highestLevel
175 config.strict$ = "'.tmp'"
181 # Change TTS for Strict!
183 call Draw_button '.table$' '.label$' '.displayButton'
186 procedure processConfigDisplayPinyin .clickX .clickY .pressed$
188 .label$ = "DisplayPinyin"
189 config.displayPinyin = not config.displayPinyin
190 .displayButton = 2*config.displayPinyin
191 call Draw_button '.table$' '.label$' '.displayButton'
194 procedure processConfigDisplayChar .clickX .clickY .pressed$
196 .label$ = "DisplayChar"
197 config.displayChar = not config.displayChar
198 .displayButton = 2*config.displayChar
199 call Draw_button 'table$' '.label$' '.displayButton'
202 procedure processConfigDisplayTrans .clickX .clickY .pressed$
204 .label$ = "DisplayTrans"
205 config.displayTrans = not config.displayTrans
206 .displayButton = 2*config.displayTrans
207 call Draw_button 'table$' '.label$' '.displayButton'
210 procedure processConfigDisplayNumbers .clickX .clickY .pressed$
212 .label$ = "DisplayNumbers"
213 config.displayNumbers = not config.displayNumbers
214 .displayButton = 2*config.displayNumbers
215 call Draw_button 'table$' '.label$' '.displayButton'
218 procedure processConfigLanguage .language$ .clickX .clickY .pressed$
220 .label$ = "Language_'.language$'"
221 call processLanguageCodes '.table$' '.label$'
224 procedure processConfigShowBackground .clickX .clickY .pressed$
226 .label$ = "ShowBackground"
227 config.showBackground = not config.showBackground
228 .displayButton = 2*config.showBackground
229 call Draw_button 'table$' '.label$' '.displayButton'
232 procedure processConfigInput .input$ .clickX .clickY .pressed$
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
240 procedure processConfigRegister .register .clickX .clickY .pressed$
242 .label$ = "Register_'.register'"
243 call setRegisterFromLabel '.table$' '.label$'
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$'
255 procedure processConfigDeleteWordlist .clickX .clickY .pressed$
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$'
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
269 exit Cannot find delete directive: '.table$' !'.label$'
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
277 # Wait for confirmation
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
285 call Draw_button '.table$' '.label$' 0
286 call Draw_config_page
290 wordlistTag$ = "Wordlist name"
291 procedure processConfigInstallWordlist .clickX .clickY .pressed$
293 .label$ = "InstallWordlist"
294 call Draw_button '.table$' '.label$' 1
296 # Do not use the automatic sgc list option, ask for a wordlist NAME
298 call findLabel '.table$' '.label$'
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)
311 .wordlist_Name$ = '.wordlistButton$'$
313 call install_wordlists_by_name '.wordlist_Name$'
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$'
323 call load_word_list "'localWordlistDir$'" 0
324 call Draw_button '.table$' '.label$' 0
325 call Draw_config_page
328 procedure processConfigOpenWordlist .clickX .clickY .pressed$
330 .label$ = "OpenWordlist"
331 call Draw_button '.table$' '.label$' 1
334 call findLabel '.table$' '.label$'
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
348 procedure processConfigExportWordlist .clickX .clickY .pressed$
350 .label$ = "ExportWordlist"
352 call Draw_button '.table$' '.label$' 1
355 call findLabel '.table$' '.label$'
357 select Table '.table$'
358 .openDialogue$ = Get value... '.row' Helptext
359 call convert_praat_to_latin1 '.openDialogue$'
360 .openDialogue$ = convert_praat_to_latin1.text$
362 .defaultName$= "'wordlist$'_SGC2.tsv"
364 .newWordlistName$ = chooseWriteFile$ (.openDialogue$, .defaultName$)
365 # Ensure the right extension: ".tsv"
366 while .newWordlistName$ <> "" and not endsWith(.newWordlistName$, ".tsv")
367 .newWordlistName$ = .newWordlistName$ + ".tsv"
368 .newWordlistName$ = chooseWriteFile$ (.openDialogue$, .newWordlistName$)
370 if .newWordlistName$ <> ""
371 select sgc.currentWordlist
372 .tmpSaveWordlist = Copy: "SaveWordlist"
373 # Get the table sorted
374 .lessonCol = Get column index: "Lesson"
376 Sort rows... Lesson Pinyin
381 # Remove all words that are deselected
382 .showCol = Get column index: "Show"
384 .numRows = Get number of rows
387 .show$ = Get value: .row, "Show"
388 .sound$ = Get value: .row, "Sound"
391 elsif .sound$ <> "" and .sound$ <> "-" and .sound$ <> "?"
392 # Put path before sound examples
393 # If there is no path, add the current wordlist path
394 if index_regex(.sound$, "^(/|~/|[A-Z]:\\)") <= 0
395 .sound$ = localWordlistDir$+"/"+wordlistName$+"/"+.sound$
396 Set string value: .row, "Sound", .sound$
401 Remove column: "Show"
403 Write to table file... '.newWordlistName$'
407 call Draw_button '.table$' '.label$' 0
408 call Draw_config_page
411 procedure processConfigPerfSummary .clickX .clickY .pressed$
413 .label$ = "PerfSummary"
415 call testLoadTable SummaryToneEvaluation
416 if testLoadTable.table > 0
417 call Draw_button '.table$' '.label$' 1
418 call loadTable SummaryToneEvaluation
419 call write_tabbed_table SummaryToneEvaluation Evaluation_'config.language$'
421 select Table SummaryToneEvaluation
424 call Draw_button '.table$' '.label$' 0
425 call Draw_config_page
429 # Wipe current performance table and initialize a new one
430 procedure processConfigClearSummary .clickX .clickY .pressed$
432 .label$ = "ClearSummary"
434 call Draw_button '.table$' '.label$' 1
436 if not sgc.saveAudioOn
437 select Table '.table$'
438 call findLabel '.table$' !'.label$'
440 .alertText$ = Get value... 'findLabel.row' Text
441 .confirmKey$ = Get value... 'findLabel.row' Key
442 .popupText$ = Get value... 'findLabel.row' Helptext
444 call write_text_popup 'defaultFont$' 14 '.popupText$'
445 call Draw_button '.table$' '.label$' 2
446 alertText$ = .alertText$
447 call Draw_button '.table$' '.label$' 3
450 # Wait for confirmation
452 if demoInput(.confirmKey$)
454 call initialize_toneevaluation_tables
459 call Draw_button '.table$' '.label$' 'sgc.saveAudioOn'
460 call Draw_config_page
464 procedure processConfigListPerf .clickX .clickY .pressed$
467 call Draw_button '.table$' '.label$' 1
469 select sgc2.performanceTable
473 call Draw_button '.table$' '.label$' 0
474 call Draw_config_page
477 procedure processConfigOpenPerf .clickX .clickY .pressed$
480 call Draw_button '.table$' '.label$' 1
482 if not sgc.saveAudioOn
484 call findLabel '.table$' !'.label$'
486 select Table '.table$'
487 .openDialogue$ = Get value... '.row' Helptext
488 call convert_praat_to_latin1 '.openDialogue$'
489 .openDialogue$ = convert_praat_to_latin1.text$
490 if variableExists("eval.performance$")
491 .defaultName$= "'eval.performance$'.tsv"
493 .defaultName$= "Performance.tsv"
495 if sgc.savePerf$ <> ""
496 .defaultName$= sgc.savePerf$
498 .performance_Name$ = chooseReadFile$ (.openDialogue$)
499 while .performance_Name$ <> "" and index_regex(.performance_Name$, "\.(tsv|TSV)$") <= 0
500 .performance_Name$ = chooseReadFile$ (.openDialogue$)
502 if .performance_Name$ <> "" and fileReadable(.performance_Name$)
503 sgc.savePerf$ = .performance_Name$
504 call initialize_toneevaluation_tables
506 # Set SaveAudio directory if it is not currently "in use"
507 if not sgc.saveAudioOn
508 sgc.saveAudio$ = replace_regex$(sgc.savePerf$, "[/\\][^/\\]+$", "", 0)
509 # We are not sure yet that this is actually an audio directory
510 config.audioName$ = ""
515 call Draw_button '.table$' '.label$' 'sgc.saveAudioOn'
516 call Draw_config_page
519 procedure processConfigSavePerf .clickX .clickY .pressed$
522 call Draw_button '.table$' '.label$' 1
524 if not sgc.saveAudioOn
526 call findLabel '.table$' '.label$'
528 select Table '.table$'
529 .openDialogue$ = Get value... '.row' Helptext
530 call convert_praat_to_latin1 '.openDialogue$'
531 .openDialogue$ = convert_praat_to_latin1.text$
532 if variableExists("eval.performance$")
533 .defaultName$= "'eval.performance$'.tsv"
535 .defaultName$= "Performance.tsv"
537 if sgc.savePerf$ <> ""
538 .defaultName$= sgc.savePerf$
540 .performance_Name$ = chooseWriteFile$ (.openDialogue$, .defaultName$)
541 # Ensure the right extension: ".tsv"
542 while .performance_Name$ <> "" and not endsWith(.performance_Name$, ".tsv")
543 .performance_Name$ = .performance_Name$ + ".tsv"
544 .performance_Name$ = chooseWriteFile$ (.openDialogue$, .performance_Name$)
546 if .performance_Name$ <> ""
547 select sgc2.performanceTable
548 Write to table file... '.performance_Name$'
549 sgc.savePerf$ = .performance_Name$
553 call Draw_button '.table$' '.label$' 'sgc.saveAudioOn'
554 call Draw_config_page
557 procedure processConfigManual .clickX .clickY .pressed$
560 call Draw_button '.table$' '.label$' 1
561 if fileReadable("ManPages/SpeakGoodChinese_2.man")
562 Read from file... ManPages/SpeakGoodChinese_2.man
564 Go to manual page... SpeakGoodChinese 2
566 # Wait until the manual is put to the background
568 call Draw_button '.table$' '.label$' 0
570 call Draw_config_page
573 procedure processConfigSaveAudio .clickX .clickY .pressed$
575 .label$ = "SaveAudio"
576 call Draw_button '.table$' '.label$' 1
578 if sgc.saveAudioOn = 0
580 call findLabel '.table$' '.label$'
582 select Table '.table$'
583 .openDialogue$ = Get value... '.row' Helptext
584 call convert_praat_to_latin1 '.openDialogue$'
585 .openDialogue$ = convert_praat_to_latin1.text$
587 sgc.saveAudio$ = chooseDirectory$ (.openDialogue$)
588 if sgc.saveAudio$ <> ""
590 .currentPathName$ = replace_regex$(sgc.saveAudio$, "[^/\\]*[/\\]?$", "", 0)
591 .currentDirName$ = replace$(sgc.saveAudio$, .currentPathName$, "", 0)
594 config.clearSummary = -1
595 config.audioName$ = .currentDirName$
597 # Clear performance table and open/create sgc.savePerf$
598 sgc.savePerf$ = "'sgc.saveAudio$'/'.currentDirName$'.tsv"
599 call initialize_toneevaluation_tables
601 call update_toneevaluation_file
602 if sgc.savePerf$ <> "" and initialiseSGC2.toneevaluation_table$ <> ""
603 select sgc2.performanceTable
604 Write to table file: sgc.savePerf$
607 config.audioName$ = ""
613 config.clearSummary = 0
614 # Store current performance table
615 call update_toneevaluation_file
618 call Draw_button '.table$' '.label$' 'sgc.saveAudioOn'
619 call Draw_config_page
622 ###############################################################
624 # Obligatory button Processing Routines
626 # These MUST be defined
628 ###############################################################
630 procedure processConfigReturn .clickX .clickY .pressed$
633 call Draw_button '.table$' '.label$' 1
634 call write_preferences ""
637 procedure processConfigRefresh .clickX .clickY .pressed$
640 call Draw_config_page
643 procedure processConfigCredits .clickX .clickY .pressed$
646 call Draw_button '.table$' '.label$' 1
647 call write_text_table Credits_'config.language$'
649 call Draw_button '.table$' '.label$' 0
651 call Draw_config_page
654 procedure processConfigHelp .clickX .clickY .pressed$
657 call help_loop '.table$' Draw_config_page
660 ###############################################################
662 # Miscelaneous supporting code
664 ###############################################################
665 procedure install_wordlists_by_name .wordlist_Name$
666 if .wordlist_Name$ <> ""
667 if index_regex(.wordlist_Name$, "(?iwordlist|LICENSE)\.")
668 .wordlist_Name$ = replace_regex$(.wordlist_Name$, "[/\\](?iwordlist|LICENSE)\.([^/\\]+)$", "", 0)
669 elsif index_regex(.wordlist_Name$, "(?i\.(wav|flac|iaf[fc]|mp3))")
670 .wordlist_Name$ = replace_regex$(.wordlist_Name$, "[/\\][^/\\]+$", "", 0)
672 if index_regex(.wordlist_Name$, "[/\\]")
673 .sourceDir$ = left$(.wordlist_Name$, rindex_regex(.wordlist_Name$, "[/\\]") -1)
674 .file$ = right$(.wordlist_Name$, length(.wordlist_Name$) - rindex_regex(.wordlist_Name$, "[/\\]"))
675 call readWordlist "'.sourceDir$'" '.file$'
678 if index(.wordlist_Name$, ".")
681 .extension1$ = ".sgc"
682 .extension2$ = ".Table"
683 .extension3$ = ".txt"
684 .extension4$ = ".tsv"
686 for .e from .start to 5
687 .currentExtension$ = .extension'.e'$
688 call readWordlist "'homeDirectory$'" '.wordlist_Name$''.currentExtension$'
689 call readWordlist "'homeDirectory$'/Downloads" '.wordlist_Name$''.currentExtension$'
690 call readWordlist "'homeDirectory$'/Documents" '.wordlist_Name$''.currentExtension$'
691 call readWordlist "'homeDirectory$'/My Documents/Downloads" '.wordlist_Name$''.currentExtension$'
692 call readWordlist "'homeDirectory$'/My Documents" '.wordlist_Name$''.currentExtension$'
693 call readWordlist "'homeDirectory$'/Desktop" '.wordlist_Name$''.currentExtension$'
694 call readWordlist "'preferencesAppDir$'" '.wordlist_Name$''.currentExtension$'
700 # Word lists: It is a VERY good idea to make sure that word-lists
702 procedure load_word_list .localdir$ .relnumber
704 if sgc.allWordLists > 0
705 select sgc.allWordLists
707 sgc.allWordLists = -1
710 # Remove old word list
712 select sgc.currentWordlist
714 call wipeArea 'wipeWordlistArea$'
716 sgc.currentWordlist = -1
719 # Create Table that will recieve the wordlists and directories
720 sgc.allWordLists = Create Table with column names... AllWordLists 0 Name Directory
721 .sgc.currentWordlistRow = 0
723 # First the global word lists
724 if fileReadable(globalwordlists$) or fileReadable("'globalwordlists$'/directory.txt")
725 Create Strings as directory list... WordList 'globalwordlists$'
726 .numLists = Get number of strings
728 select Strings WordList
729 .currentName$ = Get string... '.i'
730 if .currentName$ <> "directory.txt"
731 select sgc.allWordLists
732 .listExist = Search column: "Name", .currentName$
735 .sgc.currentWordlistRow = Get number of rows
736 Set string value... '.sgc.currentWordlistRow' Name '.currentName$'
737 .currentDirectory$ = globalwordlists$+"/"+.currentName$
738 Set string value... '.sgc.currentWordlistRow' Directory '.currentDirectory$'
742 select Strings WordList
746 # Now the preferences word lists
747 if fileReadable(sgc2wordlists$) or fileReadable("'sgc2wordlists$'/directory.txt")
748 Create Strings as directory list... WordList 'sgc2wordlists$'
749 .numLists = Get number of strings
751 select Strings WordList
752 .currentName$ = Get string... '.i'
753 if .currentName$ <> "directory.txt"
754 select sgc.allWordLists
755 .listExist = Search column: "Name", .currentName$
758 .sgc.currentWordlistRow = Get number of rows
759 Set string value... '.sgc.currentWordlistRow' Name '.currentName$'
760 .currentDirectory$ = sgc2wordlists$+"/"+.currentName$
761 Set string value... '.sgc.currentWordlistRow' Directory '.currentDirectory$'
765 select Strings WordList
769 # End with the word lists in the distribution
770 call CreateCreateWordlists
771 select Table CreateWordlists
772 .numLists = Get number of rows
774 select Table CreateWordlists
775 .currentName$ = Get value... '.i' Name
776 if .currentName$ <> "directory.txt"
777 select sgc.allWordLists
778 .listExist = Search column: "Name", .currentName$
780 .procedureName$ = replace_regex$(.currentName$, "[^\w\-\.]", "_", 0)
781 select sgc.allWordLists
783 .sgc.currentWordlistRow = Get number of rows
784 Set string value... '.sgc.currentWordlistRow' Name '.currentName$'
785 .currentDirectory$ = "*call Create'.procedureName$'"
786 Set string value... '.sgc.currentWordlistRow' Directory '.currentDirectory$'
790 select Table CreateWordlists
793 # Finally, the local word lists
794 if fileReadable(.localdir$) or fileReadable("'.localdir$'/directory.txt")
795 Create Strings as directory list... WordList '.localdir$'
796 .numLists = Get number of strings
798 select Strings WordList
799 .currentName$ = Get string... '.i'
800 if .currentName$ <> "directory.txt"
801 select sgc.allWordLists
802 .listExist = Search column: "Name", .currentName$
805 .sgc.currentWordlistRow = Get number of rows
806 Set string value... '.sgc.currentWordlistRow' Name '.currentName$'
807 .currentDirectory$ = .localdir$+"/"+.currentName$
808 Set string value... '.sgc.currentWordlistRow' Directory '.currentDirectory$'
812 select Strings WordList
816 # Get the position of the current word list
817 select sgc.allWordLists
819 .numLists = Get number of rows
821 if wordlistName$ <> ""
822 select sgc.allWordLists
823 .currentNumber = Search column... Name 'wordlistName$'
826 wordlistNum = .currentNumber + .relnumber
827 if wordlistNum > .numLists
829 elsif wordlistNum < 1 and .numLists > 0
830 wordlistNum = .numLists
832 select sgc.allWordLists
833 wordlistName$ = Get value... 'wordlistNum' Name
834 .dirWordlistName$ = Get value... 'wordlistNum' Directory
835 .dirString$ = replace_regex$(.dirWordlistName$, "[ ]", "&", 0)
837 # Read in full tables
838 if fileReadable("'.dirString$'/wordlist.Table")
839 call readTable '.dirString$'/wordlist.Table
840 if readTable.tableID > 0
841 Rename... 'wordlistName$'
842 # Praat wil change the name if it feels like it
843 wordlist$ = selected$("Table")
844 # Add a Sound column if it is not present
845 .soundIndex = Get column index: "Sound"
847 Append column: "Sound"
853 # Handle (legacy) simple word lists
854 elsif fileReadable("'.dirString$'/wordlist.txt")
855 Create Table with column names... "'wordlistName$'" 0 Pinyin Character Sound Translation
856 wordlist$ = selected$("Table")
857 Read Strings from raw text file... '.dirString$'/wordlist.txt
858 Rename... RawWordList
859 .numWordStrings = Get number of strings
860 for .i to .numWordStrings
861 select Strings RawWordList
865 .currentLine$ = Get string... '.i'
866 # Remove leading whitespace
867 .currentLine$ = replace_regex$(.currentLine$, "^[ \t]+", "", 0)
868 .separatorIndex = index_regex(.currentLine$, "[ \t;\-]")
869 if .separatorIndex <= 0
870 .separatorIndex = length(.currentLine$) + 1
872 .currentPinyin$ = left$(.currentLine$, .separatorIndex-1)
873 .currentLine$ = right$(.currentLine$, length(.currentLine$) - .separatorIndex)
874 # There is more on the line, but we do not know what
875 if length(.currentLine$) > 0
876 while length(.currentLine$) > 0
877 .separatorIndex = index_regex(.currentLine$, "[\t;]")
878 if .separatorIndex <= 0
879 .separatorIndex = length(.currentLine$)+1
881 .currentItem$ = left$(.currentLine$, .separatorIndex-1)
882 .currentLine$ = right$(.currentLine$, length(.currentLine$) - .separatorIndex )
883 if index_regex(.currentItem$, ".(spx|flac|wav|mp3)")
885 .currentFile$ = .currentItem$
886 elsif index_regex(.currentItem$, "[a-zA-Z0-9]") > 0
888 .currentTrans$ = .currentItem$
889 elsif index_regex(.currentItem$, "[^ \t\r\l]") > 0 && index_regex(.currentItem$, "[a-zA-Z0-9\-]") <= 0
891 .currentChar$ = .currentItem$
895 if .currentFile$ = "-"
896 if fileReadable("'.dirString$'/'.currentPinyin$'.spx")
897 .currentFile$ = .currentPinyin$+".spx"
898 elsif fileReadable("'.dirString$'/'.currentPinyin$'.flac")
899 .currentFile$ = .currentPinyin$+".flac"
900 elsif fileReadable("'.dirString$'/'.currentPinyin$'.wav")
901 .currentFile$ = .currentPinyin$+".wav"
902 elsif fileReadable("'.dirString$'/'.currentPinyin$'.mp3")
903 .currentFile$ = .currentPinyin$+".mp3"
906 select Table 'wordlist$'
908 Set string value... '.i' Pinyin '.currentPinyin$'
909 Set string value... '.i' Sound '.currentFile$'
910 Set string value... '.i' Character '.currentChar$'
911 Set string value... '.i' Translation '.currentTrans$'
913 select Strings RawWordList
916 select Table 'wordlist$'
917 elsif fileReadable(.dirString$) or fileReadable("'.dirString$'/directory.txt")
918 Create Table with column names... "'wordlistName$'" 0 Pinyin Sound
919 wordlist$ = selected$("Table")
920 Create Strings as file list... RawWordList '.dirString$'/*
921 .numWordStrings = Get number of strings
923 for .j to .numWordStrings
924 select Strings RawWordList
925 .currentLine$ = Get string... '.j'
926 .currentFile$ = extractWord$(.currentLine$, "")
927 if index_regex(.currentFile$, "\.(spx|flac|wav|mp3)")
928 .currentPinyin$ = left$(.currentFile$, index(.currentFile$, ".")-1)
929 select Table 'wordlist$'
932 Set string value... '.i' Pinyin '.currentPinyin$'
933 Set string value... '.i' Sound '.currentFile$'
936 select Strings RawWordList
939 select Table 'wordlist$'
940 elsif startsWith(.dirString$, "*call ")
941 .callProcedure$ = right$(.dirString$, length(.dirString$)-1)
943 wordlist$ = selected$("Table")
950 # Can this wordlist be deleted?
951 if fileReadable("'sgc2wordlists$'/'wordlistName$'") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.txt") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.Table")
952 config.deleteWordlist = 0
954 config.deleteWordlist = -1
957 # Check first column name and add Character, Translation and Show columns if missing
959 select Table 'wordlist$'
960 # Hack to correct odd behavior of tables with unicode characters
961 .firstColumn$ = Get column label: 1
962 if index_regex(.firstColumn$, "^[^!-~]") > 0
963 .firstColumn$ = replace_regex$(.firstColumn$, "^[^!-~]", "", 0)
964 Set column label (index): 1, .firstColumn$
967 sgc.numberOfWords = Get number of rows
968 .characterColumn = Get column index... Character
969 if not .characterColumn
970 Append column... Character
971 for .i to sgc.numberOfWords
972 Set string value... '.i' Character -
975 .translationColumn = Get column index... Translation
976 if not .translationColumn
977 Append column... Translation
978 for .i to sgc.numberOfWords
979 Set string value... '.i' Translation -
982 .showColumn = Get column index... Show
984 Append column... Show
985 for .i to sgc.numberOfWords
986 Set string value... '.i' Show +
991 # Remove all rows without Pinyin
992 .numRows = Get number of rows
994 .rowNum = .numRows - i + 1
995 .pinyinValue$ = Get value... '.rowNum' Pinyin
996 if not index_regex(.pinyinValue$, "[a-zA-Z0-9]")
997 Remove row... '.rowNum'
1000 sgc.numberOfWords = Get number of rows
1002 # Shuffle words if requested
1003 if config.shuffleLists
1009 #select sgc.allWordLists
1012 # There were no Word Lists
1015 wordlistName$ = wordlistName$+" No Word Lists available"
1017 Create Table with column names... "'wordlistName$'" 0 Pinyin Character Translation Sound
1018 wordlist$ = selected$("Table")
1022 Set string value... '.i' Pinyin ni3hao3
1023 Set string value... '.i' Character 你好
1024 Set string value... '.i' Translation hello
1025 Set string value... '.i' Sound -
1028 Set string value... '.i' Pinyin xie4xie0
1029 Set string value... '.i' Character 谢谢
1030 Set string value... '.i' Translation thanks
1031 Set string value... '.i' Sound -
1034 Set string value... '.i' Pinyin zai4jian4
1035 Set string value... '.i' Character 再见
1036 Set string value... '.i' Translation goodbye
1037 Set string value... '.i' Sound -
1038 sgc.numberOfWords = Get number of rows
1041 select Table 'wordlist$'
1042 sgc.currentWordlist = selected()
1043 call set_window_title 'buttons$' 'wordlistName$'
1046 procedure read_wordlist .wordlistName$ .dirString$
1047 # Read in full tables
1048 if fileReadable("'.dirString$'/wordlist.Table")
1049 call readTable '.dirString$'/wordlist.Table
1050 .wordlistID = selected ()
1052 Rename... '.wordlistName$'
1053 # Praat wil change the name if it feels like it
1054 .wordlist$ = selected$("Table")
1055 # Add a Sound column if it is not present
1056 .soundIndex = Get column index: "Sound"
1058 Append column: "Sound"
1061 goto EMERGENCYEXITWL
1063 # Handle (legacy) simple word lists
1064 elsif fileReadable("'.dirString$'/wordlist.txt")
1065 .wordlistID = Create Table with column names... "'.wordlistName$'" 0 Pinyin Character Sound Translation
1066 .wordlist$ = selected$("Table")
1067 Read Strings from raw text file... '.dirString$'/wordlist.txt
1068 Rename... RawWordList
1069 .numWordStrings = Get number of strings
1070 for .i to .numWordStrings
1071 select Strings RawWordList
1074 .currentTrans$ = "-"
1075 .currentLine$ = Get string... '.i'
1076 # Remove leading whitespace
1077 .currentLine$ = replace_regex$(.currentLine$, "^[ \t]+", "", 0)
1078 .separatorIndex = index_regex(.currentLine$, "[ \t;\-]")
1079 if .separatorIndex <= 0
1080 .separatorIndex = length(.currentLine$) + 1
1082 .currentPinyin$ = left$(.currentLine$, .separatorIndex-1)
1083 .currentLine$ = right$(.currentLine$, length(.currentLine$) - .separatorIndex)
1084 # There is more on the line, but we do not know what
1085 if length(.currentLine$) > 0
1086 while length(.currentLine$) > 0
1087 .separatorIndex = index_regex(.currentLine$, "[\t;]")
1088 if .separatorIndex <= 0
1089 .separatorIndex = length(.currentLine$)+1
1091 .currentItem$ = left$(.currentLine$, .separatorIndex-1)
1092 .currentLine$ = right$(.currentLine$, length(.currentLine$) - .separatorIndex )
1093 if index_regex(.currentItem$, ".(spx|flac|wav|mp3)")
1095 .currentFile$ = .currentItem$
1096 elsif index_regex(.currentItem$, "[a-zA-Z0-9]") > 0
1098 .currentTrans$ = .currentItem$
1099 elsif index_regex(.currentItem$, "[^ \t\r\l]") > 0 && index_regex(.currentItem$, "[a-zA-Z0-9\-]") <= 0
1101 .currentChar$ = .currentItem$
1105 if .currentFile$ = "-"
1106 if fileReadable("'.dirString$'/'.currentPinyin$'.spx")
1107 .currentFile$ = .currentPinyin$+".spx"
1108 elsif fileReadable("'.dirString$'/'.currentPinyin$'.flac")
1109 .currentFile$ = .currentPinyin$+".flac"
1110 elsif fileReadable("'.dirString$'/'.currentPinyin$'.wav")
1111 .currentFile$ = .currentPinyin$+".wav"
1112 elsif fileReadable("'.dirString$'/'.currentPinyin$'.mp3")
1113 .currentFile$ = .currentPinyin$+".mp3"
1118 Set string value... '.i' Pinyin '.currentPinyin$'
1119 Set string value... '.i' Sound '.currentFile$'
1120 Set string value... '.i' Character '.currentChar$'
1121 Set string value... '.i' Translation '.currentTrans$'
1123 select Strings RawWordList
1127 elsif fileReadable(.dirString$) or fileReadable("'.dirString$'/directory.txt")
1128 .wordlistID = Create Table with column names... "'.wordlistName$'" 0 Pinyin Sound
1129 .wordlist$ = selected$("Table")
1130 .tmp = Create Strings as file list... RawWordList '.dirString$'/*
1131 .numWordStrings = Get number of strings
1133 for .j to .numWordStrings
1135 .currentLine$ = Get string... '.j'
1136 .currentFile$ = extractWord$(.currentLine$, "")
1137 if index_regex(.currentFile$, "\.(spx|flac|wav|mp3)")
1138 .currentPinyin$ = left$(.currentFile$, index(.currentFile$, ".")-1)
1139 select sgc.currentWordlist
1142 Set string value... '.i' Pinyin '.currentPinyin$'
1143 Set string value... '.i' Sound '.currentFile$'
1149 select sgc.currentWordlist
1150 elsif startsWith(.dirString$, "*call ")
1151 .callProcedure$ = right$(.dirString$, length(.dirString$)-1)
1153 .wordlistID = selected()
1154 .wordlist$ = selected$("Table")
1157 goto EMERGENCYEXITWL
1160 # Add the path to the file Sound file names
1162 .numRows = Get number of rows
1164 .soundfile$ = Get value: .w, "Sound"
1165 if index_regex(.soundfile$, "[/\\]") <= 0
1166 if index_regex(.dirString$, "[/\\]$")
1167 .soundfile$ = .dirString$+.soundfile$
1168 elsif index_regex(.dirString$, "[\\]")
1169 .soundfile$ = .dirString$+"\\"+.soundfile$
1171 .soundfile$ = .dirString$+"/"+.soundfile$
1173 Set string value: .w, "Sound", .soundfile$
1177 label EMERGENCYEXITWL
1181 procedure merge_into_wordlist .newTableID .lessonPostfix$
1182 select sgc.currentWordlist
1183 .oldLessonColumn = Get column index: "Lesson"
1186 .numRows = Get number of rows
1187 .lessonColumn = Get column index: "Lesson"
1188 .characterColumn = Get column index: "Character"
1189 .soundColumn = Get column index: "Sound"
1190 .translationColumn = Get column index: "Translation"
1194 .currentTrans$ = "-"
1195 .currentLesson$ = "-"
1198 .currentPinyin$ = Get value: .w, "Pinyin"
1200 .currentFile$ = Get value: .w, "Sound"
1202 if .characterColumn > 0
1203 .currentChar$ = Get value: .w, "Character"
1205 if .translationColumn > 0
1206 .currentTrans$ = Get value: .w, "Translation"
1208 if .lessonColumn > 0
1209 .currentLesson$ = Get value: .w, "Lesson"
1211 select sgc.currentWordlist
1213 .n = Get number of rows
1214 Set string value: .n, "Pinyin", .currentPinyin$
1215 Set string value: .n, "Sound", .currentFile$
1216 Set string value: .n, "Character", .currentChar$
1217 Set string value: .n, "Translation", .currentTrans$
1218 if .oldLessonColumn > 0
1219 if .currentLesson$ = "-" or .currentLesson$ = "" or .currentLesson$ = "?"
1220 Set string value: .n, "Lesson", .lessonPostfix$
1222 Set string value: .n, "Lesson", .currentLesson$+" "+.lessonPostfix$
1230 select sgc.currentWordlist
1232 if sgc.currentWord < 0 or sgc.currentWord > sgc.numberOfWords
1233 if config.shuffleLists
1238 while .showCurrent$ = "-" and sgc.currentWord <= sgc.numberOfWords
1239 sgc.currentWord += 1
1240 if sgc.currentWord <= sgc.numberOfWords
1241 .showCurrent$ = Get value... 'sgc.currentWord' Show
1247 procedure previous_word
1249 select sgc.currentWordlist
1251 if sgc.currentWord <= 0
1252 if config.shuffleLists
1255 sgc.currentWord = sgc.numberOfWords + 1
1257 while .showCurrent$ = "-" and sgc.currentWord > 0
1258 sgc.currentWord -= 1
1259 if sgc.currentWord > 0
1260 .showCurrent$ = Get value... 'sgc.currentWord' Show
1266 procedure display_word_list_name
1270 .displayWordList$ = replace_regex$(wordlistName$, "[_]", " ", 0)
1271 call wipeArea 'wipeWordlistArea$'
1272 call adjustFontSizeOnHeight 'defaultFont$' 'defaultFontSize' 5
1273 .currentFontSize = adjustFontSizeOnHeight.newFontSize
1276 demo Text special... '.xtext' Centre '.ytext' Bottom 'defaultFont$' '.currentFontSize' 0 '.displayWordList$'
1279 call set_font_size 'defaultFontSize'
1282 procedure write_word_list
1283 # Write current Pinyin text
1284 call display_text Black
1286 # Write the current word list name
1287 call display_word_list_name
1290 procedure paint_saveAudio_light
1291 select Table 'config$'
1292 .row = Search column... Label SaveAudio
1294 exit Button Table Config does not have a row with label SaveAudio
1297 .leftX = Get value... '.row' LeftX
1298 .rightX = Get value... '.row' RightX
1299 .lowY = Get value... '.row' LowY
1300 .highY = Get value... '.row' HighY
1301 .buttonColor$ = Get value... '.row' Color
1302 # The button text and symbol
1303 .horWC = demo Horizontal mm to wc... 10.0
1304 .verWC = demo Vertical mm to wc... 10.0
1306 .verCoeff = .horWC / .verWC
1311 .centerX = (.leftX + .rightX)/2
1312 .centerY = .lowY + 0.6*(.highY-.lowY)
1313 .radius = min(.verCoeff * (.highY - .lowY ), (.rightX - .leftX))/3
1314 .wipeRadius = 1.1*.radius
1315 call DrawSaveAudio White '.centerX' '.centerY' '.wipeRadius'
1317 if sgc.saveAudioOn and sgc.saveAudio$ <> ""
1318 call DrawSaveAudio "DarkBlue" '.centerX' '.centerY' '.radius'
1323 # Uninstall word lists
1324 procedure removeWordlist .deletedWordlistName$
1326 if fileReadable("'sgc2wordlists$'/'.deletedWordlistName$'") or fileReadable("'sgc2wordlists$'/'.deletedWordlistName$'/wordlist.txt") or fileReadable("'sgc2wordlists$'/'.deletedWordlistName$'/wordlist.Table")
1327 .targetDir$ = "'sgc2wordlists$'/'.deletedWordlistName$'"
1329 if .targetDir$ <> ""
1330 Create Strings as file list... DeleteList '.targetDir$'
1331 .numdeleteFiles = Get number of strings
1332 for .i to .numdeleteFiles
1333 .file$ = Get string... '.i'
1334 deleteFile("'.targetDir$'/'.file$'")
1336 filedelete '.targetDir$'
1337 # Check whether the directory was actually deleted. Make sure this is a valid directory name!
1338 # That is, it does not contain funny characters, nor funny names
1339 if index_regex(.deletedWordlistName$, "[^a-zA-Z0-9_ .\-]") <= 0 and index(.deletedWordlistName$, "..") <= 0 and index_regex(.deletedWordlistName$, "[a-zA-Z]") > 0
1341 nocheck system rmdir "'.targetDir$'" /s /q
1342 elsif fileReadable(.targetDir$)
1343 system bash -rc -- 'rm -r -- "'.targetDir$'"'
1346 # Remove deleted word list
1347 select Strings DeleteList
1348 plus Table 'wordlist$'
1354 # Install word lists
1355 procedure sgc2wordlist .sourceDir$
1356 if startsWith(.sourceDir$, "preferencesDirectory$")
1357 .sourceDir$ = replace$(.sourceDir$, "preferencesDirectory$", preferencesDirectory$)
1360 .targetDirectory$ = "'sgc2wordlists$'"
1361 if fileReadable(.sourceDir$) or fileReadable("'.sourceDir$'/directory.txt")
1362 Create Strings as file list... PackageList '.sourceDir$'/*.sgc
1363 .numFiles = Get number of strings
1365 select Strings PackageList
1366 .file$ = Get string... '.i'
1367 call readWordlist '.sourceDir$' '.file$'
1370 select Strings PackageList
1375 # Debuggin remarks!!!
1376 # fileReadable(<directory>) does not work in Windows
1377 # The file paths / -> \\ must be performed on the filenames in Windows before the system_nocheck is given
1378 # And yet only the 7z decompression has been implemented
1379 windowsUnzipCommand$ = ""
1380 if fileReadable("C:\Program Files\7-Zip\7z.exe")
1381 windowsUnzipCommand$ = """C:\Program Files\7-Zip\7z.exe"" -y e"
1382 windowsUnzipDestDir$ = " -o"
1383 elsif fileReadable("C:\Program Files\WinZip\winzip32.exe")
1384 # !!! Find a way to include the output folder !!!
1385 windowsUnzipCommand$ = "C:\Program Files\WinZip\winzip32.exe"" -min -e -o -j "
1386 windowsUnzipDestDir$ = ""
1388 procedure readWordlist .sourceDir$ .file$
1389 # No use doing anything if the source does not exist
1390 if fileReadable("'.sourceDir$'/'.file$'") or fileReadable("'.sourceDir$'/'.file$'/wordlist.txt") or fileReadable("'.sourceDir$'/'.file$'/wordlist.Table")
1391 # What will be the target wordlist directory?
1392 .targetDirectory$ = "'sgc2wordlists$'"
1393 .dirname$ = left$(.file$, rindex(.file$, ".")-1)
1397 .wordlistDirectory$ = .targetDirectory$+"/"+.dirname$
1398 # Wordlist directory does not exist, neither locally nor in the preferences
1400 .tmpDirs = nocheck Create Strings as directory list... TMPWORDLISTS '.targetDirectory$'/
1401 if .tmpDirs != undefined and .tmpDirs > 0
1402 .numDirs = Get number of strings
1405 .currentString$ = Get string... '.d'
1406 if .currentString$ = .dirname$
1412 if not (.wordListExists or fileReadable(.dirname$) or fileReadable("'.dirname$'/directory.txt") or fileReadable(.wordlistDirectory$) or fileReadable("'.wordlistDirectory$'/directory.txt"))
1414 # Move source to destination
1415 # Use this if you want to allow direct loading of ZIP files. Could lead to problems.
1416 # if index(.file$, ".sgc") or index(.file$, ".zip")
1418 if index(.file$, ".sgc")
1419 if index_regex(.wordlistDirectory$, "[^a-zA-Z0-9_\.\- /~\:]") <= 0 and index_regex(.dirname$, "[^a-zA-Z0-9_\.\- ]") <= 0 and not (windows and windowsUnzipCommand$ = "")
1420 # Create wordlist directory
1421 createDirectory(.wordlistDirectory$)
1423 if macintosh or unix
1424 system bash -rc -- 'unzip -j "'.sourceDir$'/'.file$'" -d "'.wordlistDirectory$'"'
1425 elsif windows and windowsUnzipCommand$ <> ""
1426 .winWordListDirectory$ = replace_regex$(.wordlistDirectory$, "/", "\\", 0)
1427 .winSourceDirectory$ = replace_regex$("'.sourceDir$'\'.file$'", "/", "\\", 0)
1428 system mkdir "'.winWordListDirectory$'" & 'windowsUnzipCommand$' "'.winSourceDirectory$'" 'windowsUnzipDestDir$'"'.winWordListDirectory$'"
1430 elsif (windows and windowsUnzipCommand$ = "")
1431 # Warn to install 7Zip
1432 call get_feedback_text 'config.language$' InstallUnzip
1433 call convert_praat_to_latin1 'get_feedback_text.text$'
1434 .zipText$ = convert_praat_to_latin1.text$
1435 call write_text_popup 'defaultFont$' 14 '.zipText$'
1436 # Wait for confirmation
1438 call Draw_config_page
1440 # Remove if not valid!
1441 if fileReadable("'.wordlistDirectory$'/wordlist.Table") or fileReadable("'.wordlistDirectory$'/wordlist.txt") or fileReadable("'.wordlistDirectory$'/LICENSE.txt")
1442 if fileReadable("'.wordlistDirectory$'/wordlist.Table")
1443 call readTable '.sourceDir$'/'.file$'
1444 if readTable.tableID > 0
1445 select readTable.tableID
1446 # Hack around odd behavior of column index
1448 .firstColumn$ = Get column label: 1
1449 .firstColumn$ = replace_regex$(.firstColumn$, "^[^!-~]", "", 0)
1450 if .firstColumn$ = "Pinyin"
1453 .pinyinCol = Get column index... Pinyin
1456 # No Pinyin in table
1465 # None of wordlist.Table, wordlist.txt, nor LICENSE.txt
1468 ### REALLY DANGEROUS STUFF, SHOULD BE HANDLED BETTER
1470 # Remove newly created directory
1471 if index_regex(.wordlistDirectory$, "[^a-zA-Z0-9_\.\- /~\:]") <= 0 and index_regex(.dirname$, "[^a-zA-Z0-9_\.\- ]") <= 0 and index(.dirname$, "..") <= 0
1472 if macintosh or unix
1473 system bash -rc -- 'rm -r "'.wordlistDirectory$'/"'
1475 system rmdir /Q /S "'.winWordListDirectory$'/"
1479 elsif index_regex(.file$, "\.(Table|txt|tsv)")
1480 # Check whether this is a valid table
1481 call readTable '.sourceDir$'/'.file$'
1482 if readTable.tableID > 0
1483 select readTable.tableID
1484 # Hack around odd behavior of column index
1486 .firstColumn$ = Get column label: 1
1487 .firstColumn$ = replace_regex$(.firstColumn$, "^[^!-~]", "", 0)
1488 if .firstColumn$ = "Pinyin"
1491 .pinyinCol = Get column index... Pinyin
1495 select readTable.tableID
1496 # Create wordlist directory
1497 createDirectory(.wordlistDirectory$)
1499 .extension$ = "Table"
1500 .wordlistFilePath$ = "'.wordlistDirectory$'/wordlist.'.extension$'"
1502 .wordlistFilePath$ = replace_regex$(.wordlistFilePath$, "/", "\\", 0)
1505 select readTable.tableID
1506 Save as tab-separated file: .wordlistFilePath$
1507 if not fileReadable(.wordlistFilePath$)
1511 select readTable.tableID
1514 elsif fileReadable("'.sourceDir$'/'.file$'/wordlist.Table") or fileReadable("'.sourceDir$'/'.file$'/wordlist.txt") or fileReadable("'.sourceDir$'/'.file$'/LICENSE.txt")
1515 # Copy wordlist directory
1516 if index_regex(.file$, "[^a-zA-Z0-9_\.\- ]") <= 0
1518 if macintosh or unix
1519 system bash -rc -- 'cp -r "'.sourceDir$'/'.file$'" "'.wordlistDirectory$'"'
1521 createDirectory(.wordlistDirectory$)
1522 .winWordListDirectory$ = replace_regex$(.wordlistDirectory$, "/", "\\", 0)
1523 .winSourceDirectory$ = replace_regex$("'.sourceDir$'\'.file$'", "/", "\\", 0)
1524 system xcopy "'.winSourceDirectory$'" "'.winWordListDirectory$'" /s /e /q
1529 # Set current word list to read list
1531 wordlistName$ = .dirname$
1534 .label$ = "!NotAWordlist"
1537 call findLabel '.table$' '.label$'
1538 .row = findLabel.row
1539 select Table '.table$'
1540 .helpText$ = Get value... '.row' Helptext
1541 .printablePath$ = "'.sourceDir$'/'.file$'"
1543 .printablePath$ = replace$("'.sourceDir$'\'.file$'", "\", "\bs", 0)
1545 .filetext$ = replace_regex$(.printablePath$, "_", "\\_ ", 0)
1546 call write_text_popup 'defaultFont$' 14 '.helpText$' "'.filetext$'"
1547 # Wait for confirmation