author | koda |
Wed, 07 Nov 2012 13:31:58 +0000 | |
branch | webgl |
changeset 7975 | 1a8308265fdd |
parent 7969 | 7fcbbd46704a |
child 7979 | a3974abc62d3 |
permissions | -rw-r--r-- |
7965
b518458f83e6
pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff
changeset
|
1 |
module Main( main ) where |
b518458f83e6
pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff
changeset
|
2 |
|
b518458f83e6
pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff
changeset
|
3 |
import System.Console.GetOpt |
b518458f83e6
pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff
changeset
|
4 |
import System.Environment |
b518458f83e6
pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff
changeset
|
5 |
import System.Exit |
b518458f83e6
pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff
changeset
|
6 |
import System.IO |
b518458f83e6
pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff
changeset
|
7 |
import Data.Maybe( fromMaybe ) |
b518458f83e6
pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff
changeset
|
8 |
import Pas2C |
b518458f83e6
pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff
changeset
|
9 |
|
b518458f83e6
pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff
changeset
|
10 |
main = do |
b518458f83e6
pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff
changeset
|
11 |
args <- getArgs |
b518458f83e6
pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff
changeset
|
12 |
if length args == 0 |
b518458f83e6
pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff
changeset
|
13 |
then do |
b518458f83e6
pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff
changeset
|
14 |
name <- getProgName |
b518458f83e6
pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff
changeset
|
15 |
hPutStrLn stderr $ usageInfo header options |
b518458f83e6
pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff
changeset
|
16 |
exitFailure |
b518458f83e6
pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff
changeset
|
17 |
else do |
b518458f83e6
pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff
changeset
|
18 |
case getOpt RequireOrder options args of |
b518458f83e6
pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff
changeset
|
19 |
(flags, [], []) -> |
b518458f83e6
pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff
changeset
|
20 |
if length args == 8 then do |
b518458f83e6
pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff
changeset
|
21 |
pas2C (args !! 1) ((args !! 3)++"/") ((args !! 5)++"/") ((args !! 7)++"/") |
b518458f83e6
pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff
changeset
|
22 |
else do |
b518458f83e6
pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff
changeset
|
23 |
if length args == 6 then do |
b518458f83e6
pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff
changeset
|
24 |
pas2C (args !! 1) ((args !! 3)++"/") ((args !! 5)++"/") "./" |
b518458f83e6
pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff
changeset
|
25 |
else do |
b518458f83e6
pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff
changeset
|
26 |
error $ usageInfo header options |
b518458f83e6
pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff
changeset
|
27 |
(_, nonOpts, []) -> error $ "unrecognized arguments: " ++ unwords nonOpts |
b518458f83e6
pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff
changeset
|
28 |
(_, _, msgs) -> error $ usageInfo header options |
7969
7fcbbd46704a
move pas2c files in their own directory and add a warning about argument order
koda
parents:
7965
diff
changeset
|
29 |
where header = "Freepascal to C conversion! Please use -n -i -o -a options in this order.\n" |
7965
b518458f83e6
pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff
changeset
|
30 |
|
b518458f83e6
pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff
changeset
|
31 |
|
b518458f83e6
pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff
changeset
|
32 |
data Flag = HelpMessage | Name String | Input String | Output String | Alternate String |
b518458f83e6
pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff
changeset
|
33 |
|
b518458f83e6
pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff
changeset
|
34 |
options :: [OptDescr Flag] |
b518458f83e6
pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff
changeset
|
35 |
options = [ |
b518458f83e6
pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff
changeset
|
36 |
Option ['h'] ["help"] (NoArg HelpMessage) "print this help message", |
b518458f83e6
pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff
changeset
|
37 |
Option ['n'] ["name"] (ReqArg Name "MAIN") "name of the main Pascal module", |
b518458f83e6
pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff
changeset
|
38 |
Option ['i'] ["input"] (ReqArg Input "DIR") "input directory, where .pas files will be read", |
b518458f83e6
pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff
changeset
|
39 |
Option ['o'] ["output"] (ReqArg Output "DIR") "output directory, where .c/.h files will be written", |
b518458f83e6
pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff
changeset
|
40 |
Option ['a'] ["alternate"] (ReqArg Alternate "DIR") "alternate input directory, for out of source builds" |
b518458f83e6
pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff
changeset
|
41 |
] |
b518458f83e6
pas2c is now fully parametric with command line options (maybe unC0Rr needs to clean this up a little)
koda
parents:
diff
changeset
|
42 |