]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gm2/link/pimc/pass/testgetopt.mod
Merge modula-2 front end onto gcc.
[thirdparty/gcc.git] / gcc / testsuite / gm2 / link / pimc / pass / testgetopt.mod
1 MODULE testgetopt ;
2
3 FROM DynamicStrings IMPORT String, InitString, KillString ;
4 FROM StringConvert IMPORT stoc ;
5 FROM StrIO IMPORT WriteString, WriteLn ;
6 FROM StdIO IMPORT Write ;
7 FROM ASCII IMPORT nul ;
8 FROM GetOpt IMPORT GetOpt ;
9 FROM libc IMPORT printf, exit ;
10
11 IMPORT UnixArgs ;
12
13
14 VAR
15 MinRoomLength,
16 MaxRoomLength,
17 MinCorridorLength,
18 MaxCorridorLength,
19 TotalCorridorLength,
20 Seed,
21 MaxX,
22 MaxY : INTEGER ;
23
24 CONST
25 programName = "testgetopt" ;
26
27
28 (*
29 help -
30 *)
31
32 PROCEDURE help (code: INTEGER) ;
33 BEGIN
34 printf ("Usage %s [-a minroomsize] [-b maxroomsize] [-c mincorridorlength] [-d maxcorridorlength] [-e totalcorridorlength] [-h] [-o outputfile] [-s seed] [-x maxx] [-y maxy]\n", programName) ;
35 printf (" -a minroomsize (default is %d)\n", MinRoomLength) ;
36 printf (" -b maxroomsize (default is %d)\n", MaxRoomLength) ;
37 printf (" -c mincorridorsize (default is %d)\n", MinCorridorLength) ;
38 printf (" -d maxcorridorsize (default is %d)\n", MaxCorridorLength) ;
39 printf (" -e totalcorridorlength (default is %d)\n", TotalCorridorLength) ;
40 printf (" -o outputfile (default is stdout)\n") ;
41 printf (" -s seed (default is %d)\n", Seed) ;
42 printf (" -x minx for whole map (default is %d)\n", MaxX) ;
43 printf (" -y maxy for whole map (default is %d)\n", MaxY) ;
44 exit (code)
45 END help ;
46
47
48 (*
49 HandleOptions -
50 *)
51
52 PROCEDURE HandleOptions ;
53 VAR
54 optind,
55 opterr,
56 optopt: INTEGER ;
57 arg,
58 s, l : String ;
59 ch : CHAR ;
60 BEGIN
61 l := InitString (':a:b:c:d:e:o:s:hx:y:') ;
62 s := NIL ;
63 arg := NIL ;
64 ch := GetOpt (UnixArgs.GetArgC (), UnixArgs.GetArgV (), l,
65 arg, optind, opterr, optopt) ;
66 WHILE ch # nul DO
67 CASE ch OF
68
69 'a': MinRoomLength := stoc (arg) |
70 'b': MaxRoomLength := stoc (arg) |
71 'c': MinCorridorLength := stoc (arg) |
72 'd': MaxCorridorLength := stoc (arg) |
73 'e': TotalCorridorLength := stoc (arg) |
74 'h': help (0) |
75 'o': |
76 's': Seed := stoc (arg) |
77 'x': MaxX := stoc (arg) |
78 'y': MaxY := stoc (arg) |
79 '?': printf ("illegal option\n") ; help (1)
80
81 ELSE
82 WriteString ("unrecognised option '-") ; Write (ch) ; WriteString ('"') ; WriteLn ;
83 exit (1)
84 END ;
85 arg := KillString (arg) ;
86 ch := GetOpt (UnixArgs.GetArgC (), UnixArgs.GetArgV (), l,
87 arg, optind, opterr, optopt)
88 END
89 END HandleOptions ;
90
91
92 BEGIN
93 MinRoomLength := 5 ;
94 MaxRoomLength := 10 ;
95 MinCorridorLength := 10 ;
96 MaxCorridorLength := 15 ;
97 TotalCorridorLength := 30 ;
98 Seed := 1 ;
99 MaxX := 30 ;
100 MaxY := 30 ;
101 HandleOptions
102 END testgetopt.