Imported Debian patch 0.13.1-3
[pkg-lisaac.git] / install_lisaac.li
blob5227d0a6da6262bebf156dd574f94f43ab21c53b
1 ///////////////////////////////////////////////////////////////////////////////
2 //                            Lisaac Installer                               //
3 //                                                                           //
4 //                   LSIIT - ULP - CNRS - INRIA - FRANCE                     //
5 //                                                                           //
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.                                     //
10 //                                                                           //
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.                            //
15 //                                                                           //
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/>.   //
18 //                                                                           //
19 //                     http://isaacproject.u-strasbg.fr/                     //
20 ///////////////////////////////////////////////////////////////////////////////
22 Section Header
23   
24   + name     := INSTALL_LISAAC;
26   - comment  := "Configure the system file and the PATH";
27   
28   - external := `#include <unistd.h>`;
29   
30 Section Inherit
31   
32   - parent_object:OBJECT <- OBJECT;
33   
34 Section Private  
35   
36   //
37   // Independance File System 
38   //
39   
40   - open_read n:ABSTRACT_STRING :POINTER <- 
41   ( + buf:NATIVE_ARRAY[CHARACTER];
42     string_tmp.copy n;
43     buf := string_tmp.to_external;
44     `fopen((char*)@buf,"rb")`:(POINTER)    
45   );
47   - open_write n:ABSTRACT_STRING :POINTER <- 
48   ( + buf:NATIVE_ARRAY[CHARACTER];
49     string_tmp.copy n;
50     buf := string_tmp.to_external;
51     `fopen((char*)@buf,"wb")`:(POINTER)
52   );
53   
54   - read f:POINTER in buf:STRING size sz:INTEGER :INTEGER <-   
55   ( + ptr:NATIVE_ARRAY[CHARACTER];
56     + result:INTEGER;
57     ptr := buf.to_external;    
58     result := `fread((void *)(@ptr),(size_t)(1), (size_t)(@sz),(FILE*)(@f))`:(INTEGER);
59     buf.from_external ptr;
60     result
61   );
63   - write f:POINTER with buf:STRING size sz:INTEGER :INTEGER <-   
64   ( + ptr:NATIVE_ARRAY[CHARACTER];
65     + result:INTEGER;
66     ptr := buf.to_external;    
67     result := `fwrite((void *)(@ptr),(size_t)(1), (size_t)(@sz),(FILE*)(@f))`:(INTEGER);
68     result
69   );
70   
71   - close p:POINTER <- `fclose((FILE*)(@p))`;
72   
73   - file_size p:POINTER :INTEGER <-
74   ( + result:INTEGER;
75     `fseek((FILE*)(@p),0,SEEK_END)`;
76     result := `ftell((FILE *)@p)`:INTEGER;
77     `fseek((FILE*)(@p),0,SEEK_SET)`;
78     result
79   );
81   - make_file new_path:STRING :BOOLEAN <-
82   ( + p:NATIVE_ARRAY[CHARACTER];
83     + stream:POINTER;
84     + result:BOOLEAN;
85     
86     p := new_path.to_external;
87     stream := `fopen((char*)@p,"w+b")`:POINTER;
88     (result := (stream != NULL)).if {
89       close stream; 
90     };
91     result
92   );
93   
94   //
95   //
96   //
97   
98   - error st:ABSTRACT_STRING <-
99   (
100     "Error: ".print;
101     st.print;
102     die_with_code exit_failure_code;
103   );
104   
105   - step_count:INTEGER;  
106   - step_max  :INTEGER := 10;
107   
108   - title str:STRING_CONSTANT <-
109   (
110     step_count := step_count + 1;
111     "Step ".print;
112     step_count.print;
113     '/'.print;
114     step_max.print;
115     " : ".print;
116     str.print;
117     '\n'.print;
118     1.to (str.count + 11) do { j:INTEGER;
119       "=".print;
120     };
121     '\n'.print;
122   );    
123   
124   - question str:ABSTRACT_STRING :CHARACTER <-
125   ( + result:CHARACTER;
126     
127     str.print;
128     " (y/n) ".print;
129     {(result != 'y') && {result != 'n'}}.while_do {
130       result := IO.read_character;
131     };
132     result
133   );
134   
135   - update file:ABSTRACT_STRING idf id:STRING_CONSTANT 
136   with new_text:ABSTRACT_STRING confirmation conf:BOOLEAN <-
137   ( + index:INTEGER;
138     + old_buffer,input:STRING;
139     + std_file:POINTER;
140     + size_file:INTEGER;
141     
142     "  A `".print;
143     file.print;
144     
145     std_file := open_read file;
146     (std_file != NULL).if {    
147       // Update file.
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;
151       close std_file; 
152       //    
153       index := input.first_substring_index id;      
154       (index != 0).if {
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);
160             input.remove index;
161           };
162           old_buffer.add_last (input.item index);
163           input.remove index;
164         };
165         (old_buffer == new_text).if {
166           "' file has no need to change. Current version is:\n".print;
167         } else {
168           "' file has been updated. Old value is:\n".print;
169           old_buffer.print;
170           "  New value is:\n".print;
171         };
172       } else {
173         "' file has been updated with:\n".print;                
174         index := input.upper + 1;
175       };
176       new_text.print;
177       // Append configuration.      
178       input.insert_string new_text to index; 
179     } else {
180       // Creation file.
181       "' file has been created with:\n".print; 
182       new_text.print;      
183       input := new_text;
184       (! make_file file).if {
185         error "Not create file!";
186       };
187     };    
188     
189     ((! conf) || {question "  Confirmation ?" = 'y'}).if {            
190       (conf).if { 
191         '\n'.print; 
192       };
193       std_file := open_write file;
194       (std_file = NULL).if {
195         error "Not open file (Write protection) !";
196       };
197       write std_file with input size (input.count);
198       close std_file;
199     };
200   );
201   
202   //
203   // Global variable.
204   //
205   
206   - path_current:STRING;
207   - path_home   :STRING;
208   - shell       :STRING;
209   - system      :STRING_CONSTANT;
210   
211   //
212   // Constant for environment variable & path.
213   //
214   
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";
221   
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";
228   
229   - comment_windows :STRING_CONSTANT := "\r\nREM **** LISAAC COMPILER ****\r\n";
230   - comment_unix    :STRING_CONSTANT := "\n# **** LISAAC COMPILER ****\n";
231   
232   - path_bash   :STRING_CONSTANT := "export PATH=";
233   - path_tcsh   :STRING_CONSTANT := "set path=(";
234   - path_windows:STRING_CONSTANT := "set path=";
235   
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";
239     
240   //
241   // Detect system and install environment variables.
242   //
243   
244   - install_variable <-
245   ( + std_file  :POINTER;
246     + new_text  :STRING;
247     + file      :STRING;    
248     + comment   :STRING_CONSTANT;
249     + path      :STRING_CONSTANT;
250     + path_next :STRING_CONSTANT;
251     + len       :INTEGER;
252                 
253     //
254     // Detect system
255     //    
256     (shell != NULL).if {
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 {
262         // Unix - bash
263         file.append file_bashrc;
264         system    := system_unix_bash;
265         comment   := comment_unix;      
266         path      := path_bash;
267         path_next := path_bash_next;
268       }.elseif {shell.has_substring "tcsh"} then {
269         // Unix - tcsh
270         file.append file_cshrc;
271         system    := system_unix_tcsh;
272         comment   := comment_unix; 
273         path      := path_tcsh;
274         path_next := path_tcsh_next;
275       }.elseif {shell.has_substring "zsh"} then {
276         // Unix - zsh
277         file.append file_zshenv;
278         system    := system_unix_zsh;
279         comment   := comment_unix;
280         path      := path_bash;
281         path_next := path_bash_next;
282       } else {
283         // Unknown
284         "  Shell not recognized: ".print;
285         shell.print;
286         '\n'.print;        
287         system := system_unknown;
288       };
289     } else {
290       // On other shell
291       std_file := open_read file_msdos_sys;
292       (std_file != NULL).if {
293         // Windows
294         close std_file;
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;
300       } else {
301         // Unknown
302         system := system_unknown;
303       };  
304     };        
305     
306     "  System detect: ".print;
307     system.print;
308     '\n'.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; 
313       } else {
314         update "path.li" idf "  + target" with "  + target := UNIX;\n" confirmation FALSE;
315         //
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;
320         (len = 0).if {
321           " Error : `libX11.a' not found !\n\n".print;
322         } else {
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;
329         };
330         close std_file;
331         ENVIRONMENT.execute_command "rm -f xlib_path.txt";
332       };      
333     };
334     '\n'.print;    
335         
336     //
337     // Installation environment variable
338     //
339         
340     title "Installation of environment variables.";
341     
342     (system = system_unknown).if {
343       // Fail.
344       "  Auto-install fail !\n\
345       \  You have to change your environment variables as following: \n\
346       \    set path=".print;
347       path_current.print;
348       "\\bin;%path%\n\n".print;
349     } else {
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;
356     };
357     
358     //
359     // Installation Library path
360     //
361         
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;
367       //      };
368       new_text.replace_all '\\' with '/';
369     };
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;
373     '\n'.print;
374     update "src/path.h" idf "#define LISAAC_DIRECTORY" with new_text confirmation FALSE;
375     '\n'.print;
376   );
377   
378   //
379   // Install for Emacs.
380   //
381   
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";
388     
389   - lisaac_vim:STRING_CONSTANT :=
390   "\nsyntax on                           \n\
391   \filetype plugin on                    \n\
392   \filetype indent on                    \n\
393   \au BufNewFile,BufRead *.li setf lisaac\n";
394     
395   - install_emacs <-
396   ( + char:CHARACTER;
397     + file_name, new_text:STRING;
398     
399     char := question "  Do you want to install the `lisaac-mode' for Emacs editor ?";
400     (char = 'n').if {
401       "  Not install `lisaac-mode' for Emacs editor.\n\n".print;
402     } else {
403       file_name := STRING.create 100;
404       (path_home = NULL).if {
405         file_name.copy "C:";
406       } else {
407         file_name.copy path_home;
408       };
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 '/';
415       };
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;
419     };
420   );
422   - install_kate <-
423   ( + char:CHARACTER;
424     
425     (system = system_windows).if {
426       "  Sorry, not Kate editor for windows.\n\n".print;
427     } else {
428       char := question "  Do you want to install the `lisaac_v2.xml' for Kate editor ?";
429       (char = 'n').if {
430         "  Not install `lisaac_v2.xml' for Kate editor.\n\n".print;
431       } else {
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/.";
434         "  `".print;
435         string_tmp.print;
436         "'\t".print;
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;
440         } else {
441           "OK.\n".print;  
442         };      
443       };
444       '\n'.print;
445     };
446   );
448   - install_vim <-
449   ( + char:CHARACTER;
450     + file_name:STRING;
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;
455     } else {
456       char := question "  Do you want to install the Lisaac support for Vim editor ?"; 
457       (char = 'n').if {
458         "  Not install `lisaac.vim' for Vim editor.\n\n".print;
459       } else {
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"; 
464         
465         // Syntax hilightning support
466         string_tmp.copy "cp -f editor/vim/syntax/lisaac.vim ~/.vim/syntax/";
467         "  `".print;
468         string_tmp.print;
469         "'\t".print;
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;
473         } else {
474           "OK.\n".print;  
475         };
477         // Syntax indentation support
478         string_tmp.copy "cp -f editor/vim/indent/lisaac.vim ~/.vim/indent/";
479         "  `".print;
480         string_tmp.print;
481         "'\t".print;
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;
485         } else {
486           "OK.\n".print;  
487         };
489         // Install ~/.vimrc file
490         char := question
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 ?";        
495         (char = 'n').if {
496           file_name := STRING.create 100;
497           (path_home = NULL).if {
498             file_name.copy "C:";
499           } else {
500             file_name.copy path_home;
501           };
502           file_name.append "/.vimrc";   
503           update file_name idf lisaac_vim with lisaac_vim confirmation TRUE;
504         } else {
505           string_tmp.copy "cp -f editor/vim/vimrc ~/.vimrc";
506           "  `".print;
507           string_tmp.print;
508           "'\t".print;
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;
512           } else {
513             "OK.\n".print;  
514           };
515         };
516       };
517       '\n'.print;
518     };
519   );
520   
521   //
522   // Install Compiler
523   //
524   
525   - compile_file n:STRING_CONSTANT <-
526   (         
527     string_tmp.copy "gcc -O2 bin/";
528     string_tmp.append n;
529     string_tmp.append ".c -o bin/";
530     string_tmp.append n;
531     "  Execute command `".print;
532     string_tmp.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;
537       n.print;
538       ".c' file.\n".print;
539     };
540     '\n'.print;
541   );    
542   
543   //
544   // Build lib doc.
545   //
546   
547   - build_lib <-
548   ( + char:CHARACTER;
549         
550     char := question "  Do you want to build a HTML librarie documentation ?";
551     (char = 'n').if {
552       "  Not install librarie documentation.\n\n".print;
553     } else {      
554       string_tmp.clear;
555       (system = system_windows).if {
556         string_tmp.copy "bin\\shorter -r -f html lib -o lib_html";
557       } else {
558         string_tmp.copy "bin/shorter -r -f html lib -o lib_html";
559       };      
560       "  Execute: `".print;
561       string_tmp.print;
562       "'\n".print;
563       ENVIRONMENT.execute_command string_tmp;           
564       "  OK, you found this documentation in `lib_html/index.html'\n".print;  
565     };
566     '\n'.print;
567   );
568   
569   - string_tmp:STRING := STRING.create 256;
570   
571 Section Public
572   
573   - main <-
574   ( + cwd:NATIVE_ARRAY[CHARACTER];
575     
576     "\t\t================================\n\
577     \\t\t= Auto-Install Lisaac Compiler =\n\ 
578     \\t\t================================\n\n".print;
579     string_tmp.clear;
580     cwd := string_tmp.to_external;
581     `getcwd(@cwd,255)`;
582     string_tmp.from_external cwd;
583     
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";
588         
589     title "Detection system.";
590     install_variable;
592     title "Installation of `lisaac-mode' for Emacs.";
593     install_emacs;      
595     title "Installation of `lisaac_v2.xml' for Kate.";
596     install_kate;      
598     title "Installation of `lisaac.vim' for Vim.";
599     install_vim;      
600     
601     title "Compilation of Lisaac compiler."; 
602     compile_file "lisaac";
603     
604     title "Compilation of Shorter tool."; 
605     compile_file "shorter";
607     title "Build a librarie documentation."; 
608     build_lib;
609         
610     title "Welcome to the Lisaac World !";
611     
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;
618   );