Commit 8a9bdfb0 authored by John van Groningen's avatar John van Groningen
Browse files

add code for non-windows platforms

parent 26359b52
...@@ -3,6 +3,8 @@ module htoclean; ...@@ -3,6 +3,8 @@ module htoclean;
import StdEnv; import StdEnv;
import fclc; import fclc;
/* for windows */
import code from "program_args.o"; import code from "program_args.o";
n_args :: Int; n_args :: Int;
...@@ -15,16 +17,44 @@ program_arg i = code { ...@@ -15,16 +17,44 @@ program_arg i = code {
ccall program_arg "I-S" ccall program_arg "I-S"
} }
DirectorySeparator :== '\\';
/* */
/*
n_args:==GetArgC;
program_arg i:==GetArgvN i;
GetArgC :: Int;
GetArgC = code {
ccall get_argc ":I"
}
GetArgvN :: !Int -> String;
GetArgvN n = code {
ccall get_argv_n "I:S"
}
DirectorySeparator :== '/';
*/
/* for macintosh
DirectorySeparator :== ':';
import mac_file_selector_carbon;
*/
split_path_name_in_file_and_directory_name :: !{#Char} -> (!{#Char},{#Char}); split_path_name_in_file_and_directory_name :: !{#Char} -> (!{#Char},{#Char});
split_path_name_in_file_and_directory_name path_name split_path_name_in_file_and_directory_name path_name
# last_backslash_index = find_last_backslash (size path_name-1); # last_directory_separator_index = find_last_directory_separator (size path_name-1);
with { with {
find_last_backslash n find_last_directory_separator n
| n<0 || path_name.[n]=='\\' | n<0 || path_name.[n]==DirectorySeparator
= n; = n;
= find_last_backslash (n-1); = find_last_directory_separator (n-1);
} }
= (path_name % (0,last_backslash_index),path_name % (last_backslash_index+1,size path_name-1)); = (path_name % (0,last_directory_separator_index),path_name % (last_directory_separator_index+1,size path_name-1));
write_errors [] stdio write_errors [] stdio
= stdio; = stdio;
...@@ -36,27 +66,40 @@ write_errors [HError string line:l] stdio ...@@ -36,27 +66,40 @@ write_errors [HError string line:l] stdio
= write_errors l stdio; = write_errors l stdio;
wait_for_keypress w wait_for_keypress w
/* for windows and mac */
# (stdio,w) = stdio w; # (stdio,w) = stdio w;
stdio = stdio <<< "Press any key to exit"; stdio = stdio <<< "Press any key to exit";
(ok,c,stdio) = freadc stdio; (ok,c,stdio) = freadc stdio;
(ok,w) = fclose stdio w; (ok,w) = fclose stdio w;
= w; = w;
force_file_io file w :== snd (fclose file w);
//force_file_io :: !.File !*World -> World; force_file_io file w = w; //Solaris and Linux
Start w Start w
/* not for macintosh */
# n_arguments=n_args; # n_arguments=n_args;
| n_arguments<>2 | n_arguments<>2
# stderr=fwrites "Usage: htoclean h_file_name\n" stderr; # stderr=fwrites "Usage: htoclean h_file_name\n" stderr;
stderr=fwrites "Generates a .icl and .dcl file for a c header file\n" stderr; stderr=fwrites "Generates a .icl and .dcl file for a c header file\n" stderr;
(ok,w) = fclose stderr w; w = force_file_io stderr w;
= wait_for_keypress w; = wait_for_keypress w;
# path_name = program_arg 1; # path_name = program_arg 1;
(directory_name,file_name) = split_path_name_in_file_and_directory_name path_name; /* */
/* for macintosh
# (stdio_,w) = stdio w;
stdio_ = stdio_ <<< "Select the C header file\n";
w = force_file_io stdio_ w;
(ok,path_name,w) = SelectInputFile w;
*/
# (directory_name,file_name) = split_path_name_in_file_and_directory_name path_name;
h_file_name = if (file_name % (size file_name-2,size file_name-1)==".h") (file_name % (0,size file_name-3)) file_name; h_file_name = if (file_name % (size file_name-2,size file_name-1)==".h") (file_name % (0,size file_name-3)) file_name;
(errors,w) = accFiles (compile_header directory_name h_file_name) w; (errors,w) = accFiles (compile_header directory_name h_file_name) w;
= case errors of { = case errors of {
[] -> w; [] -> w;
_ # (stdio,w) = stdio w; _ # (stdio,w) = stdio w;
stdio = write_errors errors stdio; stdio = write_errors errors stdio;
(ok,w) = fclose stdio w; w = force_file_io stdio w;
-> wait_for_keypress w; -> wait_for_keypress w;
}; };
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment