english version "1.0" identify "xyz" #: Copyright (c) 2003-2006 by Wayne C. Gramlich. #, All rights reserved. module steps_gen #: This procedure implements code for explicity stepping a machine tool. import address character command_parse command_types float format in_stream integer logical memory out_stream steps string system unsigned vector unix_system unix_termios define options #: Command line options record file_names vector[string] #: File names trace_bytes logical #: -B => trace bytes trace_comment logical #: -C => trace G code comments trace_g logical #: -G => trace G codes io_file string #: -i => I/O file out_file string #: -o => output file port logical #: -p => Output to communications port repeat logical #: -R => Repeat first block forever summary logical #: -S => print out summary trace_time logical #: -T => trace time generate allocate, erase, print procedure main takes system system returns unsigned #: This is the main program. debug_stream :@= system.error_out_stream error_stream :@= system.error_out_stream standard_out_stream :@= system.standard_out_stream standard_in_stream :@= system.standard_in_stream command_parse :@= create@command_parse[options]("steps") option_logical@(command_parse, '-B', 'Trace bytes', trace_bytes_set@options) option_logical@(command_parse, '-C', 'Trace G codes comments', trace_comment_set@options) option_logical@(command_parse, '-G', 'Trace G codes', trace_g_set@options) option_argument_optional@(command_parse, '-i', 'Generate I/O file for PIC simulator', io_file_set@options) option_logical@(command_parse, '-p', 'Open Communications Port', port_set@options) option_argument_optional@(command_parse, '-o out_file', 'Generate output file', out_file_set@options) option_logical@(command_parse, '-R', 'Repeat 1st block forever', repeat_set@options) option_logical@(command_parse, '-S', 'Output Summary', summary_set@options) option_logical@(command_parse, '-T', 'Trace time', trace_time_set@options) arguments_optional@(command_parse, '...', 'Files to read in', file_names_set@options) options :@= parse@(command_parse, system.arguments, error_stream, true, true) # Sweep through the file names and verify that they all end in ".cnc": file_names :@= options.file_names size :@= file_names.size if size = 0 put@('No ".cnc" files specified!\n\', error_stream) return 1 cnc_streams :@= allocate@vector[in_stream]() errors :@= 0 index :@= 0 loop while index < size file_name :@= file_names[index] file_name_size :@= file_name.size if file_name = "-" append@(cnc_streams, standard_in_stream) else_if file_name_size >= 4 && sub_string_equal@(file_name, file_name_size - 4, 4, ".cnc", 0, 4)) cnc_stream :@= open_read@in_stream(file_name) if cnc_stream == ?? format@format1[string](error_stream, 'Could not open %ds% for reading\n\', file_name) errors :+= 1 else append@(cnc_streams, cnc_stream) else format@format1[string](error_stream, '%ds% does not have a suffix of ".cnc" (or is "-")\n\', file_name) errors :+= 1 index :+= 1 if errors != 0 return 1 # Verify that the output file name has the correct suffix: out_file :@= options.out_file out_file_size :@= out_file.size steps_stream:: out_stream := ?? if out_file = "-" # Output to standard output: steps_stream := standard_out_stream else_if out_file_size > 6 && sub_string_equal@(out_file, out_file_size - 6, 6, ".steps", 0, 6) steps_stream := open@out_stream(out_file) if steps_stream == ?? format@format1[string](error_stream, 'Could not open %ds% for writing\n\', out_file) return 1 else_if out_file != "" # Bad steps output file: format@format1[string](error_stream, '"-o %s%" does not specify a suffix of ".steps" (or "-")\n\', out_file) # Process -i option io_file :@= options.io_file io_stream:: out_stream := ?? if io_file != "" io_file_size :@= io_file.size if io_file_size >= 3 && sub_string_equal@(io_file, io_file_size - 3, 3, ".io", 0, 3) io_stream := open@out_stream(io_file) if io_stream == ?? format@format1[string](debug_stream, 'Could not open "-i %s%" for writing\n\', io_file) return 1 else format@format1[string](debug_stream, "The file name %ds% does not end with a suffix of '.io'\n\", io_file) return 1 # Create the steps object: steps :@= create@steps(steps_stream, io_stream, options.trace_g, options.trace_comment, options.summary, options.port, options.trace_time, options.trace_bytes, options.repeat, false) # Now iterate over the .cnc files: size := cnc_streams.size index := 0 loop while index < size cnc_stream :@= cnc_streams[index] loop while cnc_process@(steps, cnc_stream, false, false) !== ?? if cnc_stream !== standard_in_stream close@(cnc_stream) index :+= 1 # Close the various output streams: close@(steps) if steps_stream !== ?? flush@(steps_stream) if steps_stream !== standard_out_stream close@(steps_stream) if io_stream !== ?? flush@(io_stream) return 0