1#create output and tst files from .g files in the tst/gap directory. 2#Executing this file is NOT necessary for the installation of the package "forms" (including the documentation) 3 4#Performing these steps, files will be written in the tst directory of the 5#forms package tree. Under UNIX-like operating systems, you need sufficient 6#permissions to do. Executing this is NOT necessary for the installation of the 7#package "forms". This file is based on the generate_examples_files.g in the /forms/examples directory. 8 9#to make sure tjere is no confusing with linebreaks, it seems better to have all input (in the .g files) 10#in one (long) line. 11 12#Messy things happen when you do it, so don't try this at home kids! 13 14#create workspace with packages 15LoadPackage("forms"); 16SaveWorkspace("forms.ws"); 17quit; 18 19#restart gap now. 20 21#initialize filenames 22 23#initialisations to create .tst files from .g files in tst directory. Output will be in outputdir. 24 25files := ["test_forms1", "test_forms2", "test_forms3", "test_forms4", "test_forms5", 26 "test_forms6","test_forms7", "test_forms8", "test_forms9", "test_forms10", 27 "test_forms11", "test_recog", "test_forms12", "test_forms13", "test_forms14", 28 "test_forms15", "test_forms16" ]; 29 30#initialize directorynames 31#sourcedir = dir where .g files are located : ".../pkg/forms/tst/gap" 32#preambledir = directory where 'preamble_sws.g is found' : ".../pkg/forms/examples" 33#outputdir = directory to write '.out' files: ".../pkg/forms/examples/output" 34 35homedir := DirectoryCurrent(); 36sourcedir := DirectoriesPackageLibrary("forms","tst/gap")[1]; 37preambledir := DirectoriesPackageLibrary("forms","examples/")[1]; 38outputdir := DirectoriesPackageLibrary("forms","tst/output")[1]; 39paths := JoinStringsWithSeparator(GAPInfo.RootPaths{[2,3]},";"); 40args := JoinStringsWithSeparator(["-l",paths," -L forms.ws"," -o 4G"]," "); 41args := ["-l",paths,"-L","forms.ws","-o","4G"]; 42extension := ".out\";"; 43cmddir := "dir \:\= DirectoriesPackageLibrary\(\"forms\"\,\"tst\/output\"\)\[1\]\;"; 44 45#name of script to start gap version, might be different on your computer 46gapstart := "gap4r8"; 47gap := Filename(Directory("/usr/bin/"),gapstart); 48 49#create .out files using the saved workspace 50#IMPORTANT: here we suppose that the script to start up our favorite version of 51#GAP is called 'gap4r4', and is located in '/usr/bin'. Change the code if this is not true! 52#you certainly now the name of the script, since you started gap. To find the 53#dir, just issue in the gap session that is running: 54 55#Exec("which gap4r4"); #for UNIX 56 57for filename in files do 58 Print("Now converting file: ", filename, "\n"); 59 stream := InputOutputLocalProcess( homedir, gap, args); 60 #cmd := Concatenation("file := \"",filename,".out\";"); 61 cmd := Concatenation("file := \"",filename,extension); 62 WriteLine(stream,cmd); 63 #cmd := "dir \:\= DirectoriesPackageLibrary\(\"forms\"\,\"examples\/output\"\)\[1\]\;"; 64 WriteLine(stream,cmddir); 65 preamble := Filename(preambledir,"preamble_sws.g"); 66 preamble_stream := InputTextFile(preamble); 67 cmds := ReadAll(preamble_stream); 68 WriteLine(stream,cmds); 69 repeat 70 str := ReadLine(stream); 71 until str = "true\n"; 72 inputfile := Filename(sourcedir,Concatenation(filename,".g")); 73 input_stream := InputTextFile(inputfile); 74 cmd := ReadLine(input_stream); 75 while cmd <> fail do 76 WriteAll(stream,cmd); 77 cmd := ReadLine(input_stream); 78 ReadAll(stream); 79 od; 80 repeat until ReadAll(stream)=fail; #new since oct 2015. 81od; 82 83#create .tst files 84#the nested ifs together with the SizeScreen make sure that input lines (plural), 85#are written back in the tst file as one (long) input line. 86includedir := DirectoriesPackageLibrary("forms","tst")[1]; 87for filename in files do 88 i := Filename(outputdir,Concatenation(filename,".out")); 89 o := Filename(includedir,Concatenation(filename,".tst")); 90 PrintTo(o,""); 91 input_stream := InputTextFile(i); 92 ReadLine(input_stream); #reads first line which is a line with a # 93 #ReadLine(input_stream); 94 AppendTo(o,Concatenation("gap> START_TEST(\"Forms: ",filename,".tst\");\n")); 95 line := ReadLine(input_stream); 96 while line <> "gap> quit;\n" do 97 if Length(line) > 3 then 98 if line{[1..4]} = "gap>" then 99 RemoveCharacters(line,"\n"); 100 line := Concatenation(line,"\n"); 101 fi; 102 fi; 103 SizeScreen([500,24]); 104 AppendTo(o,line); 105 SizeScreen([80,24]); 106 line := ReadLine(input_stream); 107 od; 108 AppendTo(o,Concatenation("gap> STOP_TEST(\"",filename,".tst\", 10000 );\n")); 109od; 110 111#now write testall.g file. 112 113o := Filename(includedir,"testall.g"); 114tstdir := DirectoriesPackageLibrary("forms","tst")[1]; 115part1 := Filename(tstdir,"template_part1.g"); 116input_stream := InputTextFile(part1); 117PrintTo(o,ReadAll(input_stream)); 118 119AppendTo(o,"testfiles := [\n"); 120for i in [1..Length(files)-1] do 121 filename := Concatenation(files[i],".tst"); 122 AppendTo(o,Concatenation("\"",filename,"\",\n")); 123od; 124filename := Concatenation(files[Length(files)],".tst"); 125AppendTo(o,Concatenation("\"",filename,"\"\n];\n\n")); 126 127part2 := Filename(tstdir,"template_part2.g"); 128input_stream := InputTextFile(part2); 129AppendTo(o,ReadAll(input_stream)); 130