1   with Ada.Command_Line;
2   with Ada.Text_IO; use Ada.Text_IO;
3   with STRINGS_PACKAGE; use STRINGS_PACKAGE;
4   with CONFIG; use CONFIG;
5   with WORD_PARAMETERS; use WORD_PARAMETERS;
6   with DEVELOPER_PARAMETERS; use DEVELOPER_PARAMETERS;
7   with WORD_PACKAGE; use WORD_PACKAGE;
8   with PARSE;
9   procedure WORDS is
10      INPUT_LINE  : STRING(1..250) := (others => ' ');
11      ARGUMENTS_START : INTEGER := 1;
12   begin
13      --  The language shift in argumants must take place here
14      --  since later parsing of line ignores non-letter characters
15      CONFIGURATION := DEVELOPER_VERSION;
16
17
18      --The main mode of usage for WORDS is a simple call, followed by screen interaction.
19      if Ada.Command_Line.ARGUMENT_COUNT = 0  then      --  Simple WORDS
20         METHOD := INTERACTIVE;                          --  Interactive
21         SUPPRESS_PREFACE := FALSE;
22         SET_OUTPUT(Ada.TEXT_IO.STANDARD_OUTPUT);
23         INITIALIZE_WORD_PARAMETERS;
24         INITIALIZE_DEVELOPER_PARAMETERS;
25         INITIALIZE_WORD_PACKAGE;
26         PARSE;
27
28      --But there are other, command line options.
29      --WORDS may be called with arguments on the same line,
30      --in a number of different modes.
31      --
32      else
33         SUPPRESS_PREFACE := TRUE;
34         INITIALIZE_WORD_PARAMETERS;
35         INITIALIZE_DEVELOPER_PARAMETERS;
36         INITIALIZE_WORD_PACKAGE;
37
38      --Single parameter, either a simple Latin word or an input file.
39      --WORDS amo
40      --WORDS infile
41      if Ada.Command_Line.ARGUMENT_COUNT = 1  then      --  Input 1 word in-line
42         ONE_ARGUMENT:
43         declare
44            INPUT_NAME  : constant STRING := TRIM(Ada.Command_Line.Argument(1));
45         begin
46            OPEN(INPUT, IN_FILE, INPUT_NAME); --  Try file name, not raises NAME_ERROR
47            METHOD := COMMAND_LINE_FILES;
48            SET_INPUT(INPUT);
49            SET_OUTPUT(Ada.TEXT_IO.STANDARD_OUTPUT);
50            PARSE;          --  No additional arguments, so just go to PARSE now
51            exception                  --  Triggers on INPUT
52               when NAME_ERROR  =>                   --  Raised NAME_ERROR therefore
53                  METHOD := COMMAND_LINE_INPUT;      --  Found word in command line
54         end ONE_ARGUMENT;
55
56      --With two arguments the options are: inputfile and outputfile,
57      --two Latin words, or a language shift to English (Latin being the startup default)
58      --and an English  word (with no part of speech).
59      --WORDS infile outfile
60      --WORDS amo amas
61      --WORDS ^e  love
62      elsif Ada.Command_Line.ARGUMENT_COUNT = 2  then    --  INPUT and OUTPUT files
63         TWO_ARGUMENTS:                                   --  or multiwords in-line
64         declare
65            INPUT_NAME  : constant STRING := TRIM(Ada.Command_Line.Argument(1));
66            OUTPUT_NAME : constant STRING := TRIM(Ada.Command_Line.Argument(2));
67         begin
68           if INPUT_NAME(1) = CHANGE_LANGUAGE_CHARACTER  then
69             if (INPUT_NAME'LENGTH > 1)  then
70                 CHANGE_LANGUAGE(INPUT_NAME(2));
71                 ARGUMENTS_START := 2;
72                 METHOD := COMMAND_LINE_INPUT;      --  Parse the one word
73              end if;
74            else
75               OPEN(INPUT, IN_FILE, INPUT_NAME);
76               CREATE(OUTPUT, OUT_FILE, OUTPUT_NAME);
77               METHOD := COMMAND_LINE_FILES;
78
79               SET_INPUT(INPUT);
80               SET_OUTPUT(OUTPUT);
81
82               SUPPRESS_PREFACE := TRUE;
83               OUTPUT_SCREEN_SIZE := INTEGER'LAST;
84               PARSE;           --  No additional arguments, so just go to PARSE now
85
86               SET_INPUT(Ada.TEXT_IO.STANDARD_INPUT);    --  Clean up
87               SET_OUTPUT(Ada.TEXT_IO.STANDARD_OUTPUT);
88               CLOSE(OUTPUT);
89            end if;
90            exception                  --  Triggers on either INPUT or OUTPUT  !!!
91               when NAME_ERROR  =>
92                  METHOD := COMMAND_LINE_INPUT;            --  Found words in command line
93
94         end TWO_ARGUMENTS;
95
96      --With three arguments there could be three Latin words or a language shift
97      --and and English word and part of speech.
98      --WORDS amo amas amat
99      --WORDS ^e love v
100      elsif Ada.Command_Line.ARGUMENT_COUNT = 3  then    --  INPUT and OUTPUT files
101         THREE_ARGUMENTS:                                   --  or multiwords in-line
102         declare
103            ARG1 : constant STRING := TRIM(Ada.Command_Line.Argument(1));
104            ARG2 : constant STRING := TRIM(Ada.Command_Line.Argument(2));
105            ARG3 : constant STRING := TRIM(Ada.Command_Line.Argument(3));
106         begin
107           if ARG1(1) = CHANGE_LANGUAGE_CHARACTER  then
108             if (ARG1'LENGTH > 1)  then
109                 CHANGE_LANGUAGE(ARG1(2));
110                 ARGUMENTS_START := 2;
111                 METHOD := COMMAND_LINE_INPUT;      --  Parse the one word
112              end if;
113            else
114               METHOD := COMMAND_LINE_INPUT;
115            end if;
116
117         end THREE_ARGUMENTS;
118
119      --More than three arguments must all be Latin words.
120      --WORDS amo amas amat amamus amatis amant
121      else    --  More than three arguments
122
123         METHOD := COMMAND_LINE_INPUT;
124      end if;
125
126
127      if METHOD = COMMAND_LINE_INPUT  then            --  Process words in command line
128         MORE_ARGUMENTS:
129         begin
130  --Ada.TEXT_IO.PUT_LINE("MORE_ARG  ARG_START = " & INTEGER'IMAGE(ARGUMENTS_START));
131           SUPPRESS_PREFACE := TRUE;
132            for I in ARGUMENTS_START..Ada.Command_Line.Argument_Count  loop  --  Assemble input words
133               INPUT_LINE := HEAD(TRIM(INPUT_LINE) & " " & Ada.Command_Line.Argument(I), 250);
134            end loop;
135  --Ada.TEXT_IO.PUT_LINE("To PARSE >" & TRIM(INPUT_LINE));
136            PARSE(TRIM(INPUT_LINE));
137         end MORE_ARGUMENTS;
138      end if;
139      end if;
140
141   end WORDS;
142
143
144
145
146