7fd59977 |
1 | -- File: IFSelect_SessionPilot.cdl |
2 | -- Created: Tue Jul 27 12:26:12 1993 |
3 | -- Author: Christian CAILLET |
4 | -- <cky@meteox> |
5 | ---Copyright: Matra Datavision 1993 |
6 | |
7 | |
8 | class SessionPilot from IFSelect inherits Activator |
9 | |
10 | ---Purpose : A SessionPilot is intended to make easier the use of a |
11 | -- WorkSession. It receives commands, under alphanumeric form, |
12 | -- then calls a library of Activators to interprete and run them. |
13 | -- |
14 | -- Then, WorkSession just records data required to work : |
15 | -- Rules for Selection, Dispatch ... ; File Data (InterfaceModel |
16 | -- and results of Evaluations and Transfer as required). |
17 | -- SessionPilot records and works with alphanumeric commands and |
18 | -- their results (under a very simple form). It calls a list of |
19 | -- Activators to perform the actions. |
20 | -- |
21 | -- A Command can have several forms : |
22 | -- - classic execution, to list, evaluate, or enrich the session |
23 | -- - command which creates a new item (a Selection for instance) |
24 | -- such a command should not add it to the session, but make it |
25 | -- recorded by the Pilot (method RecordItem). The Pilot will |
26 | -- add the item in the session, with no name |
27 | -- -> such a command may be called : |
28 | -- - directly, it will add an item with no name |
29 | -- - by command xset, in the following form : |
30 | -- xset name command ... calls the command and adds the item |
31 | -- to the session under the specified name (if not yet known) |
32 | -- |
33 | -- Thus, to a specific Norm or way of working, only Activators |
34 | -- change. A specific Initialisation can be done by starting |
35 | -- with a specific set of commands. |
36 | -- |
37 | -- In addition, SessionPilot is a sub-type of Activator, to |
38 | -- recognize some built-in commands : exit/x, help/?, control of |
39 | -- command line, and commands xstep xset ... See method Do |
40 | -- |
41 | -- At least, empty lines and comment lines (beginning by '#') |
42 | -- are skipped (comment lines are display if read from file) |
43 | |
44 | uses CString, OStream, Transient, AsciiString from TCollection, |
45 | Array1OfAsciiString, SequenceOfAsciiString, Array1OfInteger, |
46 | SequenceOfInteger, SequenceOfTransient, |
47 | WorkSession, WorkLibrary, ReturnStatus, -- Activator |
48 | Selection, Dispatch, Modifier, SignCounter, PrintCount |
49 | |
50 | is |
51 | |
52 | Create (prompt : CString = "") returns mutable SessionPilot; |
53 | ---Purpose : Creates an empty SessionPilot, with a prompt which will be |
54 | -- displayed on querying commands. If not precised (""), this |
55 | -- prompt is set to "Test-XSTEP>" |
56 | |
57 | Session (me) returns mutable WorkSession; |
58 | ---Purpose : Returns the WorkSession which is worked on |
59 | |
60 | Library (me) returns mutable WorkLibrary; |
61 | ---Purpose : Returns the WorKlibrary (Null if not set). WorkLibrary is used |
62 | -- to Read and Write Files, according to the Norm |
63 | |
64 | RecordMode (me) returns Boolean; |
65 | ---Purpose : Returns the Record Mode for Commands. Default is False. |
66 | |
67 | SetSession (me : mutable; WS : mutable WorkSession); |
68 | ---Purpose : Sets a WorkSession to be worked on |
69 | |
70 | SetLibrary (me : mutable; WL : mutable WorkLibrary); |
71 | ---Purpose : Sets a WorkLibrary |
72 | |
73 | SetRecordMode (me : mutable; mode : Boolean); |
74 | ---Purpose : Changes the RecordMode. |
75 | |
76 | SetCommandLine (me : mutable; command : AsciiString from TCollection); |
77 | ---Purpose : Sets the value of the Command Line to be interpreted |
78 | -- Also prepares the interpretation (splitting by blanks) |
79 | |
80 | CommandLine (me) returns AsciiString from TCollection; |
81 | ---Purpose : Returns the Command Line to be interpreted |
82 | ---C++ : return const & |
83 | |
84 | CommandPart (me; numarg : Integer = 0) returns CString; |
85 | ---Purpose : Returns the part of the command line which begins at argument |
86 | -- <numarg> between 0 and NbWords-1 (by default, all the line) |
87 | -- Empty string if out of range |
88 | |
89 | NbWords (me) returns Integer; |
90 | ---Purpose : Returns the count of words of the Command Line, separated by |
91 | -- blanks : 0 if empty, one if a command without args, else it |
92 | -- gives the count of args minus one. |
93 | -- Warning : limited to 10 (command title + 9 args) |
94 | |
95 | Word (me; num : Integer) returns AsciiString from TCollection; |
96 | ---Purpose : Returns a word given its rank in the Command Line. Begins at 0 |
97 | -- which is the Command Title, 1 is the 1st arg., etc... |
98 | ---C++ : return const & |
99 | |
100 | Arg (me; num : Integer) returns CString; |
101 | ---Purpose : Returns a word given its rank, as a CString. |
102 | -- As for Word, begins at 0 (the command name), etc... |
103 | |
104 | RemoveWord (me : mutable; num : Integer) returns Boolean; |
105 | ---Purpose : Removes a word given its rank. Returns True if Done, False if |
106 | -- <num> is out of range |
107 | |
108 | NbCommands (me) returns Integer; |
109 | ---Purpose : Returns the count of recorded Commands |
110 | |
111 | Command (me; num : Integer) returns AsciiString from TCollection; |
112 | ---Purpose : Returns a recorded Command, given its rank (from 1) |
113 | ---C++ : return const & |
114 | |
115 | RecordItem (me : mutable; item : any Transient) returns ReturnStatus; |
116 | ---Purpose : Allows to associate a Transient Value with the last execution |
117 | -- as a partial result |
118 | -- Returns RetDone if item is not Null, RetFail if item is Null |
119 | -- Remark : it is nullified for each Perform |
120 | |
121 | RecordedItem (me) returns any Transient; |
122 | ---Purpose : Returns the Transient Object which was recorded with the |
123 | -- current Line Command. If none was, returns a Null Handle |
124 | |
125 | Clear (me : mutable); |
126 | ---Purpose : Clears the recorded informations (commands, objects) |
127 | |
128 | -- -- Execution -- -- |
129 | |
130 | ReadScript (me : mutable; file : CString = "") returns ReturnStatus; |
131 | ---Purpose : Reads commands from a Script File, named <file>. By default |
132 | -- (file = ""), reads from standard input with a prompt |
133 | -- Else (reading from a file), the read commands are displayed |
134 | -- onto standard output. Allows nested reads. Reading is stopped |
135 | -- either by command x or exit, or by reaching end of file |
136 | -- Return Value follows the rules of Do : RetEnd for normal end, |
137 | -- RetFail if script could not be opened |
138 | |
139 | Perform (me : mutable) returns ReturnStatus; |
140 | ---Purpose : Executes the Command, itself (for built-in commands, which |
141 | -- have priority) or by using the list of Activators. |
142 | -- The value returned is : RetVoid if nothing done (void command) |
143 | -- RetDone if execution OK, RetEnd if END OF SESSION, RetError if |
144 | -- command unknown or incorrect, RetFail if error on execution |
145 | -- If execution is OK and RecordMode is set, this Command Line is |
146 | -- recorded to the list (see below). |
147 | |
148 | ExecuteAlias (me : mutable; aliasname : AsciiString from TCollection) |
149 | returns ReturnStatus; |
150 | ---Purpose : Executes the Commands, except that the command name (word 0) |
151 | -- is aliased. The rest of the command line is unchanged |
152 | -- If <alias> is empty, Executes with no change |
153 | -- |
154 | -- Error status is returned if the alias is unknown as command |
155 | |
156 | Execute (me : mutable; command : AsciiString from TCollection) |
157 | returns ReturnStatus; |
158 | ---Purpose : Sets the Command then tries to execute it. Return value : |
159 | -- same as for Perform |
160 | |
161 | ExecuteCounter (me : mutable; counter : mutable SignCounter; |
162 | numword : Integer; mode : PrintCount = IFSelect_CountByItem) |
163 | returns ReturnStatus; |
164 | ---Purpose : Executes a Counter in a general way |
165 | -- If <numword> is greater than count of command words, it counts |
166 | -- all the model. Else it considers the word <numword> as the |
167 | -- identifier of a Selection |
168 | -- <mode> gives the mode of printing results, default is |
169 | -- CountByItem |
170 | |
171 | Number(me; val : CString) returns Integer; |
172 | ---Purpose : Interprets a string value as an entity number : |
173 | -- if it gives an integer, returns its value |
174 | -- else, considers it as ENtityLabel (preferably case sensitive) |
175 | -- in case of failure, returns 0 |
176 | |
177 | Do (me : mutable; number : Integer; session : mutable SessionPilot) |
178 | returns ReturnStatus; |
179 | ---Purpose : Processes specific commands, which are : |
180 | -- x or exit for end of session |
181 | -- ? or help for help messages |
182 | -- xcommand to control command lines (Record Mode, List, Clear, |
183 | -- File Output ...) |
184 | -- xsource to execute a command file (no nesting allowed), |
185 | -- in case of error, source is stopped and keyword recovers |
186 | -- xstep is a simple prefix (useful in a wider environment, to |
187 | -- avoid conflicts on command names) |
188 | -- xset control commands which create items with names |
189 | |
190 | Help (me; number : Integer) returns CString; |
191 | ---Purpose : Help for specific commands (apart from general command help) |
192 | |
193 | fields |
194 | |
195 | thesession : WorkSession; |
196 | theprompt : AsciiString from TCollection; |
197 | thecommand : AsciiString from TCollection; |
198 | thenbwords : Integer; |
199 | thewords : Array1OfAsciiString; |
200 | thewordeb : Array1OfInteger; |
201 | therecord : Boolean; |
202 | |
203 | thenumrec : Integer; |
204 | theobjrec : Transient; |
205 | thecomlist : SequenceOfAsciiString; |
206 | |
207 | end SessionPilot; |