1 ///////////////////////////////////////////////////////////////////////////////
4 // LSIIT - ULP - CNRS - INRIA - FRANCE //
6 // This program is free software: you can redistribute it and/or modify //
7 // it under the terms of the GNU General Public License as published by //
8 // the Free Software Foundation, either version 3 of the License, or //
9 // (at your option) any later version. //
11 // This program is distributed in the hope that it will be useful, //
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
14 // GNU General Public License for more details. //
16 // You should have received a copy of the GNU General Public License //
17 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
19 // http://isaacproject.u-strasbg.fr/ //
20 ///////////////////////////////////////////////////////////////////////////////
24 + name := INSTALL_LISAAC;
26 - comment := "Configure the system file and the PATH";
28 - external := `#include <unistd.h>`;
32 - parent_object:OBJECT <- OBJECT;
37 // Independance File System
40 - open_read n:ABSTRACT_STRING :POINTER <-
41 ( + buf:NATIVE_ARRAY[CHARACTER];
43 buf := string_tmp.to_external;
44 `fopen((char*)@buf,"rb")`:(POINTER)
47 - open_write n:ABSTRACT_STRING :POINTER <-
48 ( + buf:NATIVE_ARRAY[CHARACTER];
50 buf := string_tmp.to_external;
51 `fopen((char*)@buf,"wb")`:(POINTER)
54 - read f:POINTER in buf:STRING size sz:INTEGER :INTEGER <-
55 ( + ptr:NATIVE_ARRAY[CHARACTER];
57 ptr := buf.to_external;
58 result := `fread((void *)(@ptr),(size_t)(1), (size_t)(@sz),(FILE*)(@f))`:(INTEGER);
59 buf.from_external ptr;
63 - write f:POINTER with buf:STRING size sz:INTEGER :INTEGER <-
64 ( + ptr:NATIVE_ARRAY[CHARACTER];
66 ptr := buf.to_external;
67 result := `fwrite((void *)(@ptr),(size_t)(1), (size_t)(@sz),(FILE*)(@f))`:(INTEGER);
71 - close p:POINTER <- `fclose((FILE*)(@p))`;
73 - file_size p:POINTER :INTEGER <-
75 `fseek((FILE*)(@p),0,SEEK_END)`;
76 result := `ftell((FILE *)@p)`:INTEGER;
77 `fseek((FILE*)(@p),0,SEEK_SET)`;
81 - make_file new_path:STRING :BOOLEAN <-
82 ( + p:NATIVE_ARRAY[CHARACTER];
86 p := new_path.to_external;
87 stream := `fopen((char*)@p,"w+b")`:POINTER;
88 (result := (stream != NULL)).if {
98 - error st:ABSTRACT_STRING <-
102 die_with_code exit_failure_code;
105 - step_count:INTEGER;
106 - step_max :INTEGER := 10;
108 - title str:STRING_CONSTANT <-
110 step_count := step_count + 1;
118 1.to (str.count + 11) do { j:INTEGER;
124 - question str:ABSTRACT_STRING :CHARACTER <-
125 ( + result:CHARACTER;
129 {(result != 'y') && {result != 'n'}}.while_do {
130 result := IO.read_character;
135 - update file:ABSTRACT_STRING idf id:STRING_CONSTANT
136 with new_text:ABSTRACT_STRING confirmation conf:BOOLEAN <-
138 + old_buffer,input:STRING;
145 std_file := open_read file;
146 (std_file != NULL).if {
148 size_file := file_size std_file;
149 input := STRING.create (size_file + new_text.count);
150 read std_file in input size size_file;
153 index := input.first_substring_index id;
155 // Update configuration.
156 old_buffer := STRING.create 200;
157 1.to (new_text.occurrences '\n') do { j:INTEGER;
158 {input.item index != '\n'}.while_do {
159 old_buffer.add_last (input.item index);
162 old_buffer.add_last (input.item index);
165 (old_buffer == new_text).if {
166 "' file has no need to change. Current version is:\n".print;
168 "' file has been updated. Old value is:\n".print;
170 " New value is:\n".print;
173 "' file has been updated with:\n".print;
174 index := input.upper + 1;
177 // Append configuration.
178 input.insert_string new_text to index;
181 "' file has been created with:\n".print;
184 (! make_file file).if {
185 error "Not create file!";
189 ((! conf) || {question " Confirmation ?" = 'y'}).if {
193 std_file := open_write file;
194 (std_file = NULL).if {
195 error "Not open file (Write protection) !";
197 write std_file with input size (input.count);
206 - path_current:STRING;
209 - system :STRING_CONSTANT;
212 // Constant for environment variable & path.
215 - system_unix_bash:STRING_CONSTANT := "Unix - bash";
216 - system_unix_tcsh:STRING_CONSTANT := "Unix - tcsh";
217 - system_unix_zsh :STRING_CONSTANT := "Unix - zsh";
218 - system_unix_bsd :STRING_CONSTANT := "Unix - BSD or Mac";
219 - system_windows :STRING_CONSTANT := "Windows - DOS";
220 - system_unknown :STRING_CONSTANT := "Unknown";
222 - file_bashrc :STRING_CONSTANT := "/.bashrc";
223 - file_cshrc :STRING_CONSTANT := "/.cshrc";
224 - file_zshenv :STRING_CONSTANT := "/.zshenv";
225 - file_profile :STRING_CONSTANT := "/.profile";
226 - file_autoexec :STRING_CONSTANT := "C:\\autoexec.bat";
227 - file_msdos_sys:STRING_CONSTANT := "C:\\msdos.sys";
229 - comment_windows :STRING_CONSTANT := "\r\nREM **** LISAAC COMPILER ****\r\n";
230 - comment_unix :STRING_CONSTANT := "\n# **** LISAAC COMPILER ****\n";
232 - path_bash :STRING_CONSTANT := "export PATH=";
233 - path_tcsh :STRING_CONSTANT := "set path=(";
234 - path_windows:STRING_CONSTANT := "set path=";
236 - path_bash_next :STRING_CONSTANT := "/bin:$PATH\n\n";
237 - path_tcsh_next :STRING_CONSTANT := "/bin $path)\n\n";
238 - path_windows_next:STRING_CONSTANT := "\\bin;%path%\r\n\r\n";
241 // Detect system and install environment variables.
244 - install_variable <-
245 ( + std_file :POINTER;
248 + comment :STRING_CONSTANT;
249 + path :STRING_CONSTANT;
250 + path_next :STRING_CONSTANT;
257 file := STRING.create_from_string path_home;
258 (shell.is_empty).if {
259 " Error : SHELL environment variable is empty !\n".print;
260 system := system_unknown;
261 }.elseif {shell.has_substring "bash"} then {
263 file.append file_bashrc;
264 system := system_unix_bash;
265 comment := comment_unix;
267 path_next := path_bash_next;
268 }.elseif {shell.has_substring "tcsh"} then {
270 file.append file_cshrc;
271 system := system_unix_tcsh;
272 comment := comment_unix;
274 path_next := path_tcsh_next;
275 }.elseif {shell.has_substring "zsh"} then {
277 file.append file_zshenv;
278 system := system_unix_zsh;
279 comment := comment_unix;
281 path_next := path_bash_next;
284 " Shell not recognized: ".print;
287 system := system_unknown;
291 std_file := open_read file_msdos_sys;
292 (std_file != NULL).if {
295 file := STRING.create_from_string file_autoexec;
296 system := system_windows;
297 comment := comment_windows;
298 path := path_windows;
299 path_next := path_windows_next;
302 system := system_unknown;
306 " System detect: ".print;
309 (system != system_unknown).if {
310 (system = system_windows).if {
311 update "path.li" idf " + target" with " + target := WINDOWS;\n" confirmation FALSE;
312 "\n Note: Use `mingw' for Windows.\n".print;
314 update "path.li" idf " + target" with " + target := UNIX;\n" confirmation FALSE;
316 "\n Search path for `libX11.a' : (please wait...)\n".print;
317 ENVIRONMENT.execute_command "find /usr/lib/ -name \"libX11.a\" 2> /dev/null > xlib_path.txt";
318 std_file := open_read "xlib_path.txt";
319 len := file_size std_file;
321 " Error : `libX11.a' not found !\n\n".print;
323 new_text := STRING.create len;
324 read std_file in new_text size len;
325 new_text.remove_last 10;
326 new_text.prepend " + path_lib_x11 := \"";
327 new_text.append "\";\n";
328 update "path.li" idf " + path_lib_x11" with new_text confirmation FALSE;
331 ENVIRONMENT.execute_command "rm -f xlib_path.txt";
337 // Installation environment variable
340 title "Installation of environment variables.";
342 (system = system_unknown).if {
344 " Auto-install fail !\n\
345 \ You have to change your environment variables as following: \n\
348 "\\bin;%path%\n\n".print;
350 // Creation environment variables.
351 new_text := STRING.create_from_string comment;
352 new_text.append path;
353 new_text.append path_current;
354 new_text.append path_next;
355 update file idf comment with new_text confirmation TRUE;
359 // Installation Library path
362 title "Installation of Lisaac library path.";
363 new_text := STRING.create_from_string path_current;
364 (system = system_windows).if {
365 // (new_text.item 2 = ':').if {
366 // new_text.remove_first 2;
368 new_text.replace_all '\\' with '/';
370 new_text.prepend "#define LISAAC_DIRECTORY \"";
371 new_text.append "\"\n";
372 update "bin/path.h" idf "#define LISAAC_DIRECTORY" with new_text confirmation FALSE;
374 update "src/path.h" idf "#define LISAAC_DIRECTORY" with new_text confirmation FALSE;
379 // Install for Emacs.
382 - lisaac_mode_comment :STRING_CONSTANT := ";; **** LISAAC MODE ****";
383 - lisaac_mode_path :STRING_CONSTANT := "\n(setq load-path (cons \"";
384 - lisaac_mode_path_end:STRING_CONSTANT := "/editor/emacs/\" load-path))\n";
385 - lisaac_mode :STRING_CONSTANT :=
386 "(add-to-list 'auto-mode-alist '(\"\\\\.li\\\\'\" . lisaac-mode))\n\
387 \(autoload 'lisaac-mode \"lisaac-mode\" \"Major mode for Lisaac Programs\" t)\n\n";
389 - lisaac_vim:STRING_CONSTANT :=
391 \filetype plugin on \n\
392 \filetype indent on \n\
393 \au BufNewFile,BufRead *.li setf lisaac\n";
397 + file_name, new_text:STRING;
399 char := question " Do you want to install the `lisaac-mode' for Emacs editor ?";
401 " Not install `lisaac-mode' for Emacs editor.\n\n".print;
403 file_name := STRING.create 100;
404 (path_home = NULL).if {
407 file_name.copy path_home;
409 file_name.append "/.emacs";
410 new_text := STRING.create_from_string lisaac_mode_comment;
411 new_text.append lisaac_mode_path;
412 new_text.append path_current;
413 (system = system_windows).if {
414 new_text.replace_all '\\' with '/';
416 new_text.append lisaac_mode_path_end;
417 new_text.append lisaac_mode;
418 update file_name idf lisaac_mode_comment with new_text confirmation TRUE;
425 (system = system_windows).if {
426 " Sorry, not Kate editor for windows.\n\n".print;
428 char := question " Do you want to install the `lisaac_v2.xml' for Kate editor ?";
430 " Not install `lisaac_v2.xml' for Kate editor.\n\n".print;
432 ENVIRONMENT.execute_command "mkdir -p ~/.kde/share/apps/katepart/syntax";
433 string_tmp.copy "cp -f editor/kate/lisaac_v2.xml ~/.kde/share/apps/katepart/syntax/.";
437 (ENVIRONMENT.execute_command string_tmp != 0).if {
438 "\n Sorry, auto-install fail !\n\
439 \ You can to read the `editor/kate/README' file.\n".print;
452 // TODO: Fix this since gvim exists on windows system
453 (system = system_windows).if {
454 " Sorry, not Vim editor for windows.\n\n".print;
456 char := question " Do you want to install the Lisaac support for Vim editor ?";
458 " Not install `lisaac.vim' for Vim editor.\n\n".print;
460 ENVIRONMENT.execute_command "mkdir -p ~/.vim/syntax";
461 ENVIRONMENT.execute_command "mkdir -p ~/.vim/indent";
462 ENVIRONMENT.execute_command "mkdir -p ~/.vim/backup";
463 ENVIRONMENT.execute_command "mkdir -p ~/.vim/temp";
465 // Syntax hilightning support
466 string_tmp.copy "cp -f editor/vim/syntax/lisaac.vim ~/.vim/syntax/";
470 (ENVIRONMENT.execute_command string_tmp != 0).if {
471 "\n Sorry, auto-install fail !\n\
472 \ You can read the `editor/vim/install_vim_plugin.sh' file.\n".print;
477 // Syntax indentation support
478 string_tmp.copy "cp -f editor/vim/indent/lisaac.vim ~/.vim/indent/";
482 (ENVIRONMENT.execute_command string_tmp != 0).if {
483 "\n Sorry, auto-install fail !\n\
484 \ You can read the `editor/vim/install_vim_plugin.sh' file.\n".print;
489 // Install ~/.vimrc file
491 "\n It is recommanded to install the default vimrc file provided by the \n\
492 \ lisaac installer. \n\n\
493 \ If you choose not doing this action, your vimrc will only be updated \n\
494 \ Do you want to install the default config provided by lisaac installer ?";
496 file_name := STRING.create 100;
497 (path_home = NULL).if {
500 file_name.copy path_home;
502 file_name.append "/.vimrc";
503 update file_name idf lisaac_vim with lisaac_vim confirmation TRUE;
505 string_tmp.copy "cp -f editor/vim/vimrc ~/.vimrc";
509 (ENVIRONMENT.execute_command string_tmp != 0).if {
510 "\n Sorry, auto-install fail !\n\
511 \ You can read the `editor/vim/install_vim_plugin.sh' file.\n".print;
525 - compile_file n:STRING_CONSTANT <-
527 string_tmp.copy "gcc -O2 bin/";
529 string_tmp.append ".c -o bin/";
531 " Execute command `".print;
533 "' (please wait ...)\n".print;
534 (ENVIRONMENT.execute_command string_tmp != 0).if {
535 " Auto-install fail !\n\
536 \ You want to compile a `bin/".print;
550 char := question " Do you want to build a HTML librarie documentation ?";
552 " Not install librarie documentation.\n\n".print;
555 (system = system_windows).if {
556 string_tmp.copy "bin\\shorter -r -f html lib -o lib_html";
558 string_tmp.copy "bin/shorter -r -f html lib -o lib_html";
563 ENVIRONMENT.execute_command string_tmp;
564 " OK, you found this documentation in `lib_html/index.html'\n".print;
569 - string_tmp:STRING := STRING.create 256;
574 ( + cwd:NATIVE_ARRAY[CHARACTER];
576 "\t\t================================\n\
577 \\t\t= Auto-Install Lisaac Compiler =\n\
578 \\t\t================================\n\n".print;
580 cwd := string_tmp.to_external;
582 string_tmp.from_external cwd;
584 path_current := STRING.create (string_tmp.count);
585 path_current.copy string_tmp;
586 path_home := ENVIRONMENT.get_environment_variable "HOME";
587 shell := ENVIRONMENT.get_environment_variable "SHELL";
589 title "Detection system.";
592 title "Installation of `lisaac-mode' for Emacs.";
595 title "Installation of `lisaac_v2.xml' for Kate.";
598 title "Installation of `lisaac.vim' for Vim.";
601 title "Compilation of Lisaac compiler.";
602 compile_file "lisaac";
604 title "Compilation of Shorter tool.";
605 compile_file "shorter";
607 title "Build a librarie documentation.";
610 title "Welcome to the Lisaac World !";
612 " Installation successfull. \n\
613 \ Run `lisaac' to compile. \n\n\
614 \ Note: You'll have to reboot or reloaded environnement \n\
615 \ to acknowledge the changes. \n\
616 \ Note: For bash users, doing a `source ~/.bashrc' should \n\
617 \ do the job.\n".print;