srecord 1.65.0
 
Loading...
Searching...
No Matches
tool.h
Go to the documentation of this file.
1//
2// srecord - manipulate eprom load files
3// Copyright (C) 1998-2014 Peter Miller
4// Copyright (C) 2014 Scott Finneran
5//
6// This program is free software; you can redistribute it and/or modify
7// it under the terms of the GNU Lesser General Public License as published by
8// the Free Software Foundation; either version 3 of the License, or (at
9// your option) any later version.
10//
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14// General Public License for more details.
15//
16// You should have received a copy of the GNU Lesser General Public License
17// along with this program. If not, see <http://www.gnu.org/licenses/>.
18//
19
20#ifndef SRECORD_ARGLEX_TOOL_H
21#define SRECORD_ARGLEX_TOOL_H
22
23#include <srecord/arglex.h>
24#include <srecord/defcon.h>
25#include <srecord/endian.h>
26#include <srecord/input.h>
27#include <srecord/output.h>
28
29
30namespace srecord
31{
32
33class interval; // forward
34
35/**
36 * The srecord::arglex_tool is used to parse command line with srec-specific
37 * arguments.
38 */
40 public arglex
41{
42public:
43 enum
44 {
209 };
210
211 /**
212 * The destructor.
213 */
214 virtual ~arglex_tool();
215
216 /**
217 * The constructor. Pass the argc and argv as given to main;
218 * there is not need to change the values at all.
219 */
220 arglex_tool(int argc, char **argv);
221
222 /**
223 * The get_input method is used to parse an input specification
224 * (filename, file format, filters, everything) from the
225 * command line.
226 *
227 * If the parse is unsuccessful (is not present on command
228 * line) a fatal error will be issued and the method call will
229 * not return.
230 */
232
233 /**
234 * The get_output method is used to parse an output specification
235 * (filename and file format) from the command line.
236 *
237 * If the parse is unsuccessful (is not present on command
238 * line) a fatal error will be issued and the method call will
239 * not return.
240 */
242
243 /**
244 * The get_number method is used to parse a numeric value from the
245 * command line.
246 */
247 unsigned long get_number(const char *caption);
248
249 /**
250 * The get_number method is used to parse a numeric value
251 * from the command line, and check it agains a specified range.
252 *
253 * @param caption
254 * for the error message, if necessary
255 * @param min
256 * The minimum acceptable value (inclusive)
257 * @param max
258 * The maximum acceptable value (inclusive)
259 */
260 unsigned long get_number(const char *caption, long min, long max);
261
262 /**
263 * The can_get_number method is used to determine if it is possible
264 * to parse a number from the next token on the command line.
265 */
266 bool can_get_number(void) const;
267
268 /**
269 * The get_interval method is used to parse an interval
270 * set form the command line. It consists of as many
271 * get_interval_inner()s as possible.
272 *
273 * Used by the get_input method to parse the address intervals used
274 * by various filters. It is the lowest precedence level, and
275 * handsles set union (the implicit operator) and set difference
276 * (the - operator).
277 *
278 * If the parse is unsuccessful (is not present on command
279 * line) a fatal error will be issued and the method call will
280 * not return.
281 */
282 interval get_interval(const char *err_msg_caption);
283
284 /**
285 * The get_interval_small method may be used to parse an interval
286 * set form the command line. It checks that the interval is
287 * <=1GB, and errors if it is not, with a --big override. Commonly
288 * used to sanity check things like --fill.
289 */
290 interval get_interval_small(const char *err_msg_caption);
291
292 /**
293 * The get_string method may be used to get a string from the
294 * command line, or issue a fatal error if one is not available.
295 *
296 * @param caption
297 * The text for the error message.
298 */
299 std::string get_string(const char *caption);
300
301 // See base class for documentation.
303
304 defcon_t get_redundant_bytes(void) const { return redundant_bytes; }
305 defcon_t get_contradictory_bytes(void) const { return contradictory_bytes; }
306
307private:
308 /**
309 * The get_interval_factor method is used to parse a single
310 * interval from the command line (usually, a pair of number
311 * representing the [lower, upper) bounds, but it could be
312 * -over or -within, too).
313 *
314 * This method parses the highest precedence operators in the range
315 * parsing.
316 *
317 * This method should only every be called by the get_interval_term
318 * method.
319 *
320 * If the parse is unsuccessful (is not present on command
321 * line) a fatal error will be issued and the method call will
322 * not return.
323 */
324 interval get_interval_factor(const char *err_msg_caption);
325
326 /**
327 * The get_interval_term method is used to parse set-intersection
328 * precedence intervals from the command line. This method parses
329 * the middle precedence operators in the range parsing.
330 *
331 * This method should only every be called by the get_interval_term
332 * method.
333 *
334 * If the parse is unsuccessful (is not present on command
335 * line) a fatal error will be issued and the method call will
336 * not return.
337 */
338 interval get_interval_term(const char *err_msg_caption);
339
340 /**
341 * The get_address method is used to parse an address from the
342 * command line.
343 *
344 * If the parse is unsuccessful (is not present on command
345 * line) a fatal error will be issued and the method call will
346 * not return.
347 */
348 void get_address(const char *err_msg_caption, unsigned long &addr);
349
350 /**
351 * The get_address_and_nbytes method is used to parse an address
352 * and a byte count from the command line.
353 *
354 * If the parse is unsuccessful (is not present on command
355 * line) a fatal error will be issued and the method call will
356 * not return.
357 */
358 void get_address_and_nbytes(const char *err_msg_caption,
359 unsigned long &addr, int &nbytes);
360
361 /**
362 * The get_address_nbytes_width method is used to parse an address
363 * a byte count and a width from the command line.
364 *
365 * If the parse is unsuccessful (is not present on command
366 * line) a fatal error will be issued and the method call will
367 * not return.
368 */
369 void get_address_nbytes_width(const char *err_msg_caption,
370 unsigned long &addr, int &nbytes, int &width);
371
372 /**
373 * The stdin_used instance variable is used to remember whether
374 * or not the standard input has been used by a filter, yet.
375 * Only one use of the standard input may be made; the second
376 * use will result in a fatal error.
377 */
378 bool stdin_used;
379
380 /**
381 * The stdout_used instance variable is used to remember whether
382 * or not the standard output has been used by a filter, yet.
383 * Only one use of the standard output may be made; the second
384 * use will result in a fatal error.
385 */
386 bool stdout_used;
387
388 /**
389 * The issue_sequence_warnings instance variable is used to
390 * remember whether or not to issue data sequence warnings when
391 * data records are not in strictly ascending address order.
392 *
393 * Negative means not set from the command line, zero means diabled
394 * from the command line, positive means enabled on the command
395 * line.
396 */
397 int issue_sequence_warnings;
398
399 /**
400 * The get_simple_input method is used to parse an input filename
401 * or generator from the command line. It shall only be used by
402 * the #get_input method.
403 *
404 * If the parse is unsuccessful (is not present on command
405 * line) a fatal error will be issued and the method call will
406 * not return.
407 */
408 input::pointer get_simple_input();
409
410 /**
411 * The get_endian_by_token method is sued to obtain the endian-ness
412 * of a given token. This is for when there are big-endian and
413 * little-endian variants of filters and file formats.
414 *
415 * @param tok
416 * the noken the endien-ness is required for.
417 */
418 endian_t get_endian_by_token(int tok) const;
419
420 /**
421 * The get_endian_by_token method is sued to obtain the endian-ness
422 * of the current token.
423 */
425 get_endian_by_token(void)
426 const
427 {
428 return get_endian_by_token(token_cur());
429 }
430
431 /**
432 * The get_inclusive_by_token method is used to determine whether
433 * or not a token is inclusive (e.g. token_length_be) or exclusive
434 * (e.g. token_exclusive_length_be).
435 *
436 * @param tok
437 * The token to examine.
438 */
439 bool get_inclusive_by_token(int tok) const;
440
441 /**
442 * The get_inclusive_by_token method is used to determine whether
443 * or not the current token is inclusive or exclusive.
444 */
445 bool
446 get_inclusive_by_token(void)
447 const
448 {
449 return get_inclusive_by_token(token_cur());
450 }
451
452 /**
453 * The redundant_bytes instance variable is used to remember what
454 * to do when faced with multiple identical byte values for a
455 * memory address.
456 */
457 defcon_t redundant_bytes;
458
459 /**
460 * The vontradivtory_bytes instance variable is used to remember what
461 * to do when faced with multiple different byte values for a
462 * memory address.
463 */
464 defcon_t contradictory_bytes;
465
466 /**
467 * The default constructor. Do not use.
468 */
469 arglex_tool();
470
471 /**
472 * The copy constructor. Do not use.
473 */
474 arglex_tool(const arglex_tool &);
475
476 /**
477 * The assignment operator. Do not use.
478 */
479 arglex_tool &operator=(const arglex_tool &);
480};
481
482};
483
484// vim: set ts=8 sw=4 et :
485#endif // SRECORD_ARGLEX_TOOL_H
interval get_interval(const char *err_msg_caption)
The get_interval method is used to parse an interval set form the command line.
void default_command_line_processing(void)
The default_command_line_processing method is used to process command line arguments not handled by t...
interval get_interval_small(const char *err_msg_caption)
The get_interval_small method may be used to parse an interval set form the command line.
virtual ~arglex_tool()
The destructor.
bool can_get_number(void) const
The can_get_number method is used to determine if it is possible to parse a number from the next toke...
unsigned long get_number(const char *caption)
The get_number method is used to parse a numeric value from the command line.
std::string get_string(const char *caption)
The get_string method may be used to get a string from the command line, or issue a fatal error if on...
@ token_exclusive_minimum
Definition tool.h:99
@ token_contradictory_bytes
Definition tool.h:75
@ token_exclusive_maximum
Definition tool.h:96
@ token_crc16_least_to_most
Definition tool.h:83
@ token_crc16_most_to_least
Definition tool.h:84
@ token_sequence_warnings_disable
Definition tool.h:172
@ token_crc16_augment_not
Definition tool.h:78
@ token_checksum_be_bitnot
Definition tool.h:64
@ token_sequence_warnings_enable
Definition tool.h:173
@ token_checksum_le_positive
Definition tool.h:69
@ token_checksum_be_positive
Definition tool.h:66
@ token_exclusive_length_le
Definition tool.h:95
@ token_lattice_memory_initialization_format
Definition tool.h:120
@ token_exclusive_maximum_be
Definition tool.h:97
@ token_exclusive_minimum_le
Definition tool.h:101
@ token_checksum_le_bitnot
Definition tool.h:67
@ token_xilinx_coefficient_file
Definition tool.h:206
@ token_style_hexadecimal_not
Definition tool.h:189
@ token_checksum_le_negative
Definition tool.h:68
@ token_checksum_be_negative
Definition tool.h:65
@ token_exclusive_length_be
Definition tool.h:94
@ token_exclusive_minimum_be
Definition tool.h:100
@ token_memory_initialization_file
Definition tool.h:135
@ token_exclusive_maximum_le
Definition tool.h:98
input::pointer get_input(void)
The get_input method is used to parse an input specification (filename, file format,...
defcon_t get_contradictory_bytes(void) const
Definition tool.h:305
output::pointer get_output(void)
The get_output method is used to parse an output specification (filename and file format) from the co...
defcon_t get_redundant_bytes(void) const
Definition tool.h:304
arglex_tool(int argc, char **argv)
The constructor.
unsigned long get_number(const char *caption, long min, long max)
The get_number method is used to parse a numeric value from the command line, and check it agains a s...
int token_cur() const
The token_cur method is used to get the type of the current token.
Definition arglex.h:238
arglex()
The default constructor.
std::shared_ptr< input > pointer
Definition input.h:41
The interval class is used to represent a set of integer values, usually composed of runs of adjacent...
Definition interval.h:36
std::shared_ptr< output > pointer
Definition output.h:41
defcon_t
Definition defcon.h:26
endian_t
Definition endian.h:27