openc3 5.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +18 -0
- data/Guardfile +35 -0
- data/LICENSE.txt +727 -0
- data/README.md +37 -0
- data/Rakefile +131 -0
- data/bin/cstol_converter +1178 -0
- data/bin/openc3cli +531 -0
- data/bin/rubysloc +139 -0
- data/data/config/_array_params.yaml +23 -0
- data/data/config/_id_items.yaml +24 -0
- data/data/config/_id_params.yaml +58 -0
- data/data/config/_interfaces.yaml +214 -0
- data/data/config/_interfaces.yaml.err +1017 -0
- data/data/config/_items.yaml +20 -0
- data/data/config/_params.yaml +60 -0
- data/data/config/cmd_tlm_server.yaml +136 -0
- data/data/config/command.yaml +44 -0
- data/data/config/command_modifiers.yaml +160 -0
- data/data/config/command_telemetry.yaml +3 -0
- data/data/config/interface_modifiers.yaml +104 -0
- data/data/config/item_modifiers.yaml +221 -0
- data/data/config/microservice.yaml +78 -0
- data/data/config/param_item_modifiers.yaml +52 -0
- data/data/config/parameter_modifiers.yaml +200 -0
- data/data/config/plugins.yaml +80 -0
- data/data/config/protocols.yaml +290 -0
- data/data/config/screen.yaml +147 -0
- data/data/config/table_manager.yaml +89 -0
- data/data/config/table_parameter_modifiers.yaml +9 -0
- data/data/config/target.yaml +142 -0
- data/data/config/target_config.yaml +94 -0
- data/data/config/telemetry.yaml +87 -0
- data/data/config/telemetry_modifiers.yaml +159 -0
- data/data/config/tool.yaml +63 -0
- data/data/config/unknown.yaml +3 -0
- data/data/config/widgets.yaml +1505 -0
- data/ext/mkrf_conf.rb +49 -0
- data/ext/openc3/ext/array/array.c +122 -0
- data/ext/openc3/ext/array/extconf.rb +13 -0
- data/ext/openc3/ext/buffered_file/buffered_file.c +198 -0
- data/ext/openc3/ext/buffered_file/extconf.rb +13 -0
- data/ext/openc3/ext/config_parser/config_parser.c +280 -0
- data/ext/openc3/ext/config_parser/extconf.rb +13 -0
- data/ext/openc3/ext/crc/crc.c +351 -0
- data/ext/openc3/ext/crc/extconf.rb +13 -0
- data/ext/openc3/ext/openc3_io/extconf.rb +13 -0
- data/ext/openc3/ext/openc3_io/openc3_io.c +158 -0
- data/ext/openc3/ext/packet/extconf.rb +13 -0
- data/ext/openc3/ext/packet/packet.c +318 -0
- data/ext/openc3/ext/platform/extconf.rb +13 -0
- data/ext/openc3/ext/platform/platform.c +134 -0
- data/ext/openc3/ext/polynomial_conversion/extconf.rb +13 -0
- data/ext/openc3/ext/polynomial_conversion/polynomial_conversion.c +79 -0
- data/ext/openc3/ext/string/extconf.rb +13 -0
- data/ext/openc3/ext/string/string.c +63 -0
- data/ext/openc3/ext/structure/structure.c +1719 -0
- data/ext/openc3/ext/tabbed_plots_config/extconf.rb +13 -0
- data/ext/openc3/ext/tabbed_plots_config/tabbed_plots_config.c +62 -0
- data/ext/openc3/ext/telemetry/extconf.rb +13 -0
- data/ext/openc3/ext/telemetry/telemetry.c +336 -0
- data/lib/cosmos.rb +20 -0
- data/lib/cosmosc2.rb +20 -0
- data/lib/openc3/api/api.rb +39 -0
- data/lib/openc3/api/authorized_api.rb +30 -0
- data/lib/openc3/api/cmd_api.rb +451 -0
- data/lib/openc3/api/config_api.rb +58 -0
- data/lib/openc3/api/interface_api.rb +117 -0
- data/lib/openc3/api/limits_api.rb +375 -0
- data/lib/openc3/api/router_api.rb +117 -0
- data/lib/openc3/api/settings_api.rb +70 -0
- data/lib/openc3/api/target_api.rb +78 -0
- data/lib/openc3/api/tlm_api.rb +455 -0
- data/lib/openc3/bridge/bridge.rb +54 -0
- data/lib/openc3/bridge/bridge_config.rb +167 -0
- data/lib/openc3/bridge/bridge_interface_thread.rb +42 -0
- data/lib/openc3/bridge/bridge_router_thread.rb +42 -0
- data/lib/openc3/ccsds/ccsds_packet.rb +68 -0
- data/lib/openc3/ccsds/ccsds_parser.rb +148 -0
- data/lib/openc3/config/config_parser.rb +549 -0
- data/lib/openc3/config/meta_config_parser.rb +74 -0
- data/lib/openc3/conversions/conversion.rb +70 -0
- data/lib/openc3/conversions/generic_conversion.rb +83 -0
- data/lib/openc3/conversions/packet_time_formatted_conversion.rb +43 -0
- data/lib/openc3/conversions/packet_time_seconds_conversion.rb +43 -0
- data/lib/openc3/conversions/polynomial_conversion.rb +87 -0
- data/lib/openc3/conversions/processor_conversion.rb +70 -0
- data/lib/openc3/conversions/received_count_conversion.rb +38 -0
- data/lib/openc3/conversions/received_time_formatted_conversion.rb +42 -0
- data/lib/openc3/conversions/received_time_seconds_conversion.rb +42 -0
- data/lib/openc3/conversions/segmented_polynomial_conversion.rb +171 -0
- data/lib/openc3/conversions/unix_time_conversion.rb +68 -0
- data/lib/openc3/conversions/unix_time_formatted_conversion.rb +49 -0
- data/lib/openc3/conversions/unix_time_seconds_conversion.rb +49 -0
- data/lib/openc3/conversions.rb +34 -0
- data/lib/openc3/core_ext/array.rb +416 -0
- data/lib/openc3/core_ext/binding.rb +29 -0
- data/lib/openc3/core_ext/class.rb +72 -0
- data/lib/openc3/core_ext/exception.rb +61 -0
- data/lib/openc3/core_ext/file.rb +83 -0
- data/lib/openc3/core_ext/hash.rb +37 -0
- data/lib/openc3/core_ext/io.rb +134 -0
- data/lib/openc3/core_ext/kernel.rb +42 -0
- data/lib/openc3/core_ext/math.rb +128 -0
- data/lib/openc3/core_ext/matrix.rb +156 -0
- data/lib/openc3/core_ext/objectspace.rb +36 -0
- data/lib/openc3/core_ext/openc3_io.rb +57 -0
- data/lib/openc3/core_ext/range.rb +27 -0
- data/lib/openc3/core_ext/socket.rb +38 -0
- data/lib/openc3/core_ext/string.rb +389 -0
- data/lib/openc3/core_ext/stringio.rb +33 -0
- data/lib/openc3/core_ext/time.rb +508 -0
- data/lib/openc3/core_ext.rb +36 -0
- data/lib/openc3/interfaces/interface.rb +498 -0
- data/lib/openc3/interfaces/linc_interface.rb +475 -0
- data/lib/openc3/interfaces/protocols/burst_protocol.rb +192 -0
- data/lib/openc3/interfaces/protocols/crc_protocol.rb +193 -0
- data/lib/openc3/interfaces/protocols/fixed_protocol.rb +155 -0
- data/lib/openc3/interfaces/protocols/ignore_packet_protocol.rb +56 -0
- data/lib/openc3/interfaces/protocols/length_protocol.rb +165 -0
- data/lib/openc3/interfaces/protocols/override_protocol.rb +60 -0
- data/lib/openc3/interfaces/protocols/preidentified_protocol.rb +206 -0
- data/lib/openc3/interfaces/protocols/protocol.rb +82 -0
- data/lib/openc3/interfaces/protocols/template_protocol.rb +261 -0
- data/lib/openc3/interfaces/protocols/terminated_protocol.rb +93 -0
- data/lib/openc3/interfaces/serial_interface.rb +94 -0
- data/lib/openc3/interfaces/simulated_target_interface.rb +168 -0
- data/lib/openc3/interfaces/stream_interface.rb +81 -0
- data/lib/openc3/interfaces/tcpip_client_interface.rb +69 -0
- data/lib/openc3/interfaces/tcpip_server_interface.rb +629 -0
- data/lib/openc3/interfaces/udp_interface.rb +169 -0
- data/lib/openc3/interfaces.rb +44 -0
- data/lib/openc3/io/buffered_file.rb +109 -0
- data/lib/openc3/io/io_multiplexer.rb +80 -0
- data/lib/openc3/io/json_api_object.rb +208 -0
- data/lib/openc3/io/json_drb.rb +335 -0
- data/lib/openc3/io/json_drb_object.rb +114 -0
- data/lib/openc3/io/json_drb_rack.rb +84 -0
- data/lib/openc3/io/json_rpc.rb +420 -0
- data/lib/openc3/io/openc3_snmp.rb +58 -0
- data/lib/openc3/io/posix_serial_driver.rb +156 -0
- data/lib/openc3/io/raw_logger.rb +167 -0
- data/lib/openc3/io/raw_logger_pair.rb +77 -0
- data/lib/openc3/io/serial_driver.rb +105 -0
- data/lib/openc3/io/stderr.rb +43 -0
- data/lib/openc3/io/stdout.rb +43 -0
- data/lib/openc3/io/udp_sockets.rb +194 -0
- data/lib/openc3/io/win32_serial_driver.rb +196 -0
- data/lib/openc3/logs/log_writer.rb +302 -0
- data/lib/openc3/logs/packet_log_constants.rb +62 -0
- data/lib/openc3/logs/packet_log_reader.rb +345 -0
- data/lib/openc3/logs/packet_log_writer.rb +299 -0
- data/lib/openc3/logs/text_log_writer.rb +68 -0
- data/lib/openc3/logs.rb +25 -0
- data/lib/openc3/microservices/cleanup_microservice.rb +68 -0
- data/lib/openc3/microservices/decom_microservice.rb +136 -0
- data/lib/openc3/microservices/interface_microservice.rb +532 -0
- data/lib/openc3/microservices/log_microservice.rb +108 -0
- data/lib/openc3/microservices/microservice.rb +204 -0
- data/lib/openc3/microservices/plugin_microservice.rb +43 -0
- data/lib/openc3/microservices/reaction_microservice.rb +541 -0
- data/lib/openc3/microservices/reducer_microservice.rb +313 -0
- data/lib/openc3/microservices/router_microservice.rb +44 -0
- data/lib/openc3/microservices/text_log_microservice.rb +84 -0
- data/lib/openc3/microservices/timeline_microservice.rb +363 -0
- data/lib/openc3/microservices/trigger_group_microservice.rb +638 -0
- data/lib/openc3/models/activity_model.rb +319 -0
- data/lib/openc3/models/auth_model.rb +65 -0
- data/lib/openc3/models/cvt_model.rb +185 -0
- data/lib/openc3/models/environment_model.rb +58 -0
- data/lib/openc3/models/gem_model.rb +137 -0
- data/lib/openc3/models/info_model.rb +31 -0
- data/lib/openc3/models/interface_model.rb +281 -0
- data/lib/openc3/models/interface_status_model.rb +117 -0
- data/lib/openc3/models/metadata_model.rb +139 -0
- data/lib/openc3/models/metric_model.rb +59 -0
- data/lib/openc3/models/microservice_model.rb +206 -0
- data/lib/openc3/models/microservice_status_model.rb +74 -0
- data/lib/openc3/models/model.rb +204 -0
- data/lib/openc3/models/note_model.rb +122 -0
- data/lib/openc3/models/notification_model.rb +40 -0
- data/lib/openc3/models/ping_model.rb +35 -0
- data/lib/openc3/models/plugin_model.rb +292 -0
- data/lib/openc3/models/process_status_model.rb +76 -0
- data/lib/openc3/models/reaction_model.rb +322 -0
- data/lib/openc3/models/reducer_model.rb +65 -0
- data/lib/openc3/models/router_model.rb +35 -0
- data/lib/openc3/models/router_status_model.rb +27 -0
- data/lib/openc3/models/scope_model.rb +153 -0
- data/lib/openc3/models/settings_model.rb +55 -0
- data/lib/openc3/models/sorted_model.rb +167 -0
- data/lib/openc3/models/target_model.rb +759 -0
- data/lib/openc3/models/timeline_model.rb +154 -0
- data/lib/openc3/models/tool_config_model.rb +38 -0
- data/lib/openc3/models/tool_model.rb +262 -0
- data/lib/openc3/models/trigger_group_model.rb +186 -0
- data/lib/openc3/models/trigger_model.rb +330 -0
- data/lib/openc3/models/widget_model.rb +138 -0
- data/lib/openc3/operators/microservice_operator.rb +128 -0
- data/lib/openc3/operators/operator.rb +277 -0
- data/lib/openc3/packets/binary_accessor.rb +1207 -0
- data/lib/openc3/packets/commands.rb +373 -0
- data/lib/openc3/packets/json_packet.rb +134 -0
- data/lib/openc3/packets/limits.rb +271 -0
- data/lib/openc3/packets/limits_response.rb +53 -0
- data/lib/openc3/packets/packet.rb +1168 -0
- data/lib/openc3/packets/packet_config.rb +625 -0
- data/lib/openc3/packets/packet_item.rb +586 -0
- data/lib/openc3/packets/packet_item_limits.rb +162 -0
- data/lib/openc3/packets/parsers/format_string_parser.rb +65 -0
- data/lib/openc3/packets/parsers/limits_parser.rb +159 -0
- data/lib/openc3/packets/parsers/limits_response_parser.rb +61 -0
- data/lib/openc3/packets/parsers/packet_item_parser.rb +272 -0
- data/lib/openc3/packets/parsers/packet_parser.rb +134 -0
- data/lib/openc3/packets/parsers/processor_parser.rb +73 -0
- data/lib/openc3/packets/parsers/state_parser.rb +127 -0
- data/lib/openc3/packets/parsers/xtce_converter.rb +442 -0
- data/lib/openc3/packets/parsers/xtce_parser.rb +722 -0
- data/lib/openc3/packets/structure.rb +553 -0
- data/lib/openc3/packets/structure_item.rb +365 -0
- data/lib/openc3/packets/telemetry.rb +487 -0
- data/lib/openc3/processors/processor.rb +86 -0
- data/lib/openc3/processors/statistics_processor.rb +82 -0
- data/lib/openc3/processors/watermark_processor.rb +58 -0
- data/lib/openc3/processors.rb +24 -0
- data/lib/openc3/script/api_shared.rb +828 -0
- data/lib/openc3/script/calendar.rb +89 -0
- data/lib/openc3/script/commands.rb +227 -0
- data/lib/openc3/script/exceptions.rb +29 -0
- data/lib/openc3/script/extract.rb +161 -0
- data/lib/openc3/script/limits.rb +60 -0
- data/lib/openc3/script/script.rb +299 -0
- data/lib/openc3/script/script_runner.rb +238 -0
- data/lib/openc3/script/storage.rb +146 -0
- data/lib/openc3/script/suite.rb +542 -0
- data/lib/openc3/script/suite_results.rb +196 -0
- data/lib/openc3/script/suite_runner.rb +217 -0
- data/lib/openc3/script.rb +21 -0
- data/lib/openc3/streams/serial_stream.rb +167 -0
- data/lib/openc3/streams/stream.rb +63 -0
- data/lib/openc3/streams/tcpip_client_stream.rb +116 -0
- data/lib/openc3/streams/tcpip_socket_stream.rb +195 -0
- data/lib/openc3/system/system.rb +127 -0
- data/lib/openc3/system/system_config.rb +411 -0
- data/lib/openc3/system/target.rb +269 -0
- data/lib/openc3/system.rb +24 -0
- data/lib/openc3/tools/cmd_tlm_server/api.rb +20 -0
- data/lib/openc3/tools/cmd_tlm_server/cmd_tlm_server_config.rb +320 -0
- data/lib/openc3/tools/cmd_tlm_server/interface_thread.rb +294 -0
- data/lib/openc3/tools/table_manager/table.rb +77 -0
- data/lib/openc3/tools/table_manager/table_config.rb +273 -0
- data/lib/openc3/tools/table_manager/table_item.rb +90 -0
- data/lib/openc3/tools/table_manager/table_item_parser.rb +66 -0
- data/lib/openc3/tools/table_manager/table_manager_core.rb +333 -0
- data/lib/openc3/tools/table_manager/table_parser.rb +93 -0
- data/lib/openc3/tools/test_runner/test.rb +67 -0
- data/lib/openc3/top_level.rb +595 -0
- data/lib/openc3/topics/autonomic_topic.rb +52 -0
- data/lib/openc3/topics/calendar_topic.rb +44 -0
- data/lib/openc3/topics/command_decom_topic.rb +76 -0
- data/lib/openc3/topics/command_topic.rb +83 -0
- data/lib/openc3/topics/config_topic.rb +68 -0
- data/lib/openc3/topics/interface_topic.rb +73 -0
- data/lib/openc3/topics/limits_event_topic.rb +109 -0
- data/lib/openc3/topics/notifications_topic.rb +28 -0
- data/lib/openc3/topics/router_topic.rb +85 -0
- data/lib/openc3/topics/telemetry_decom_topic.rb +54 -0
- data/lib/openc3/topics/telemetry_topic.rb +36 -0
- data/lib/openc3/topics/timeline_topic.rb +45 -0
- data/lib/openc3/topics/topic.rb +53 -0
- data/lib/openc3/utilities/authentication.rb +141 -0
- data/lib/openc3/utilities/authorization.rb +51 -0
- data/lib/openc3/utilities/crc.rb +278 -0
- data/lib/openc3/utilities/csv.rb +153 -0
- data/lib/openc3/utilities/logger.rb +187 -0
- data/lib/openc3/utilities/message_log.rb +91 -0
- data/lib/openc3/utilities/metric.rb +141 -0
- data/lib/openc3/utilities/process_manager.rb +139 -0
- data/lib/openc3/utilities/quaternion.rb +257 -0
- data/lib/openc3/utilities/ruby_lex_utils.rb +568 -0
- data/lib/openc3/utilities/s3.rb +202 -0
- data/lib/openc3/utilities/s3_autoload.rb +9 -0
- data/lib/openc3/utilities/s3_file_cache.rb +274 -0
- data/lib/openc3/utilities/simulated_target.rb +117 -0
- data/lib/openc3/utilities/sleeper.rb +51 -0
- data/lib/openc3/utilities/store.rb +23 -0
- data/lib/openc3/utilities/store_autoload.rb +237 -0
- data/lib/openc3/utilities/zip.rb +21 -0
- data/lib/openc3/utilities.rb +35 -0
- data/lib/openc3/version.rb +14 -0
- data/lib/openc3/win32/excel.rb +132 -0
- data/lib/openc3/win32/win32.rb +402 -0
- data/lib/openc3/win32/win32_main.rb +333 -0
- data/lib/openc3.rb +49 -0
- data/tasks/gemfile_stats.rake +113 -0
- data/tasks/spec.rake +30 -0
- data/templates/plugin-template/README.md +15 -0
- data/templates/plugin-template/Rakefile +12 -0
- data/templates/plugin-template/plugin.gemspec +23 -0
- data/templates/plugin-template/plugin.txt +9 -0
- data/templates/plugin-template/targets/TARGET/cmd_tlm/cmd.txt +8 -0
- data/templates/plugin-template/targets/TARGET/cmd_tlm/tlm.txt +8 -0
- data/templates/plugin-template/targets/TARGET/lib/target.rb +10 -0
- data/templates/plugin-template/targets/TARGET/procedures/procedure.rb +3 -0
- data/templates/plugin-template/targets/TARGET/screens/status.txt +9 -0
- data/templates/plugin-template/targets/TARGET/target.txt +5 -0
- metadata +849 -0
data/ext/mkrf_conf.rb
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# encoding: ascii-8bit
|
|
2
|
+
|
|
3
|
+
# Copyright 2022 Ball Aerospace & Technologies Corp.
|
|
4
|
+
# All Rights Reserved.
|
|
5
|
+
#
|
|
6
|
+
# This program is free software; you can modify and/or redistribute it
|
|
7
|
+
# under the terms of the GNU Affero General Public License
|
|
8
|
+
# as published by the Free Software Foundation; version 3 with
|
|
9
|
+
# attribution addendums as found in the LICENSE.txt
|
|
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
|
|
14
|
+
# GNU Affero General Public License for more details.
|
|
15
|
+
|
|
16
|
+
# Modified by OpenC3, Inc.
|
|
17
|
+
# All changes Copyright 2022, OpenC3, Inc.
|
|
18
|
+
# All Rights Reserved
|
|
19
|
+
|
|
20
|
+
# This file gems specific to platform
|
|
21
|
+
|
|
22
|
+
require 'rubygems'
|
|
23
|
+
require 'rubygems/command.rb'
|
|
24
|
+
require 'rubygems/dependency_installer.rb'
|
|
25
|
+
|
|
26
|
+
def gem_installed?(name, version = Gem::Requirement.default)
|
|
27
|
+
version = Gem::Requirement.create version unless version.is_a? Gem::Requirement
|
|
28
|
+
Gem::Specification.each.any? { |spec| name == spec.name and version.satisfied_by? spec.version }
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
begin
|
|
32
|
+
Gem::Command.build_args = ARGV
|
|
33
|
+
rescue NoMethodError
|
|
34
|
+
end
|
|
35
|
+
inst = Gem::DependencyInstaller.new
|
|
36
|
+
begin
|
|
37
|
+
if !/mswin|mingw|cygwin/i.match?(RbConfig::CONFIG['target_os'])
|
|
38
|
+
unless gem_installed?("ruby-termios", ">= 0.9")
|
|
39
|
+
STDOUT.puts "Attempting to install ruby-termios... If this fails please manually \"gem install ruby-termios\" and try again."
|
|
40
|
+
inst.install "ruby-termios", ">= 0.9"
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
rescue
|
|
44
|
+
exit(1)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
f = File.open(File.join(File.dirname(__FILE__), "Rakefile"), "w") # create dummy rakefile to indicate success
|
|
48
|
+
f.write("task :default\n")
|
|
49
|
+
f.close
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/*
|
|
2
|
+
# Copyright 2022 Ball Aerospace & Technologies Corp.
|
|
3
|
+
# All Rights Reserved.
|
|
4
|
+
#
|
|
5
|
+
# This program is free software; you can modify and/or redistribute it
|
|
6
|
+
# under the terms of the GNU Affero General Public License
|
|
7
|
+
# as published by the Free Software Foundation; version 3 with
|
|
8
|
+
# attribution addendums as found in the LICENSE.txt
|
|
9
|
+
#
|
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
# GNU Affero General Public License for more details.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/*
|
|
17
|
+
# Modified by OpenC3, Inc.
|
|
18
|
+
# All changes Copyright 2022, OpenC3, Inc.
|
|
19
|
+
# All Rights Reserved
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
#include "ruby.h"
|
|
23
|
+
#include "stdio.h"
|
|
24
|
+
|
|
25
|
+
static ID id_method_greater_than = 0;
|
|
26
|
+
static ID id_method_less_than = 0;
|
|
27
|
+
|
|
28
|
+
/*
|
|
29
|
+
* Returns the maximum value and its index
|
|
30
|
+
*/
|
|
31
|
+
static VALUE max_with_index(VALUE self)
|
|
32
|
+
{
|
|
33
|
+
int index = 0;
|
|
34
|
+
long array_length = RARRAY_LEN(self);
|
|
35
|
+
int maximum_index = 0;
|
|
36
|
+
volatile VALUE value = Qnil;
|
|
37
|
+
volatile VALUE maximum = Qnil;
|
|
38
|
+
volatile VALUE return_value = Qnil;
|
|
39
|
+
|
|
40
|
+
if (array_length > 0)
|
|
41
|
+
{
|
|
42
|
+
maximum = rb_ary_entry(self, 0);
|
|
43
|
+
maximum_index = 0;
|
|
44
|
+
|
|
45
|
+
for (index = 1; index < array_length; index++)
|
|
46
|
+
{
|
|
47
|
+
value = rb_ary_entry(self, index);
|
|
48
|
+
|
|
49
|
+
if (rb_funcall(value, id_method_greater_than, 1, maximum) == Qtrue)
|
|
50
|
+
{
|
|
51
|
+
maximum = value;
|
|
52
|
+
maximum_index = index;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return_value = rb_ary_new2(2);
|
|
58
|
+
rb_ary_push(return_value, maximum);
|
|
59
|
+
if (NIL_P(maximum))
|
|
60
|
+
{
|
|
61
|
+
rb_ary_push(return_value, Qnil);
|
|
62
|
+
}
|
|
63
|
+
else
|
|
64
|
+
{
|
|
65
|
+
rb_ary_push(return_value, INT2FIX(maximum_index));
|
|
66
|
+
}
|
|
67
|
+
return return_value;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/*
|
|
71
|
+
* Returns the minimum value and its index
|
|
72
|
+
*/
|
|
73
|
+
static VALUE min_with_index(VALUE self)
|
|
74
|
+
{
|
|
75
|
+
int index = 0;
|
|
76
|
+
long array_length = RARRAY_LEN(self);
|
|
77
|
+
int minimum_index = 0;
|
|
78
|
+
volatile VALUE value = Qnil;
|
|
79
|
+
volatile VALUE minimum = Qnil;
|
|
80
|
+
volatile VALUE return_value = Qnil;
|
|
81
|
+
|
|
82
|
+
if (array_length > 0)
|
|
83
|
+
{
|
|
84
|
+
minimum = rb_ary_entry(self, 0);
|
|
85
|
+
minimum_index = 0;
|
|
86
|
+
|
|
87
|
+
for (index = 1; index < array_length; index++)
|
|
88
|
+
{
|
|
89
|
+
value = rb_ary_entry(self, index);
|
|
90
|
+
|
|
91
|
+
if (rb_funcall(value, id_method_less_than, 1, minimum) == Qtrue)
|
|
92
|
+
{
|
|
93
|
+
minimum = value;
|
|
94
|
+
minimum_index = index;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return_value = rb_ary_new2(2);
|
|
100
|
+
rb_ary_push(return_value, minimum);
|
|
101
|
+
if (NIL_P(minimum))
|
|
102
|
+
{
|
|
103
|
+
rb_ary_push(return_value, Qnil);
|
|
104
|
+
}
|
|
105
|
+
else
|
|
106
|
+
{
|
|
107
|
+
rb_ary_push(return_value, INT2FIX(minimum_index));
|
|
108
|
+
}
|
|
109
|
+
return return_value;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/*
|
|
113
|
+
* Initialize methods for Array Core Ext
|
|
114
|
+
*/
|
|
115
|
+
void Init_array(void)
|
|
116
|
+
{
|
|
117
|
+
id_method_greater_than = rb_intern(">");
|
|
118
|
+
id_method_less_than = rb_intern("<");
|
|
119
|
+
|
|
120
|
+
rb_define_method(rb_cArray, "max_with_index", max_with_index, 0);
|
|
121
|
+
rb_define_method(rb_cArray, "min_with_index", min_with_index, 0);
|
|
122
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require 'mkmf'
|
|
2
|
+
|
|
3
|
+
unless $CFLAGS.gsub!(/ -O[\dsz]?/, ' -O3')
|
|
4
|
+
$CFLAGS << ' -O3'
|
|
5
|
+
end
|
|
6
|
+
if /gcc/.match?(CONFIG['CC'])
|
|
7
|
+
$CFLAGS << ' -Wall'
|
|
8
|
+
if $DEBUG && !$CFLAGS.gsub!(/ -O[\dsz]?/, ' -O0 -ggdb')
|
|
9
|
+
$CFLAGS << ' -O0 -ggdb'
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
create_makefile 'openc3/ext/array'
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/*
|
|
2
|
+
# Copyright 2022 Ball Aerospace & Technologies Corp.
|
|
3
|
+
# All Rights Reserved.
|
|
4
|
+
#
|
|
5
|
+
# This program is free software; you can modify and/or redistribute it
|
|
6
|
+
# under the terms of the GNU Affero General Public License
|
|
7
|
+
# as published by the Free Software Foundation; version 3 with
|
|
8
|
+
# attribution addendums as found in the LICENSE.txt
|
|
9
|
+
#
|
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
# GNU Affero General Public License for more details.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/*
|
|
17
|
+
# Modified by OpenC3, Inc.
|
|
18
|
+
# All changes Copyright 2022, OpenC3, Inc.
|
|
19
|
+
# All Rights Reserved
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
#include "ruby.h"
|
|
23
|
+
#include "stdio.h"
|
|
24
|
+
|
|
25
|
+
VALUE mOpenC3 = Qnil;
|
|
26
|
+
VALUE cBufferedFile = Qnil;
|
|
27
|
+
static ID id_ivar_buffer = 0;
|
|
28
|
+
static ID id_ivar_buffer_index = 0;
|
|
29
|
+
static ID id_method_clear = 0;
|
|
30
|
+
static ID id_method_slice_bang = 0;
|
|
31
|
+
static ID id_method_to_s = 0;
|
|
32
|
+
static ID id_method_pos = 0;
|
|
33
|
+
static ID id_const_BUFFER_SIZE = 0;
|
|
34
|
+
static ID id_const_ALL_RANGE = 0;
|
|
35
|
+
static VALUE BUFFERED_FILE_SEEK_SET = Qnil;
|
|
36
|
+
static VALUE BUFFERED_FILE_SEEK_CUR = Qnil;
|
|
37
|
+
|
|
38
|
+
#define BUFFER_SIZE (1024 * 16)
|
|
39
|
+
|
|
40
|
+
/* Initialize the BufferedFile. Takes the same args as File */
|
|
41
|
+
static VALUE buffered_file_initialize(int argc, VALUE *argv, VALUE self)
|
|
42
|
+
{
|
|
43
|
+
rb_call_super(argc, argv);
|
|
44
|
+
rb_ivar_set(self, id_ivar_buffer, rb_str_new2(""));
|
|
45
|
+
rb_ivar_set(self, id_ivar_buffer_index, INT2FIX(0));
|
|
46
|
+
return self;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/* Read using an internal buffer to avoid system calls */
|
|
50
|
+
static VALUE buffered_file_read(VALUE self, VALUE arg_length)
|
|
51
|
+
{
|
|
52
|
+
long length = FIX2INT(arg_length);
|
|
53
|
+
volatile VALUE buffer = rb_ivar_get(self, id_ivar_buffer);
|
|
54
|
+
long buffer_length = RSTRING_LEN(buffer);
|
|
55
|
+
long buffer_index = FIX2INT(rb_ivar_get(self, id_ivar_buffer_index));
|
|
56
|
+
volatile VALUE result = Qnil;
|
|
57
|
+
volatile VALUE super_arg = Qnil;
|
|
58
|
+
|
|
59
|
+
if (length <= (buffer_length - buffer_index))
|
|
60
|
+
{
|
|
61
|
+
/* Return part of the buffer without having to go to the OS */
|
|
62
|
+
result = rb_str_substr(buffer, buffer_index, length);
|
|
63
|
+
buffer_index += length;
|
|
64
|
+
rb_ivar_set(self, id_ivar_buffer_index, INT2FIX(buffer_index));
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
else if (length > BUFFER_SIZE)
|
|
68
|
+
{
|
|
69
|
+
/* Reading more than our buffer */
|
|
70
|
+
if (buffer_length > 0)
|
|
71
|
+
{
|
|
72
|
+
if (buffer_index > 0)
|
|
73
|
+
{
|
|
74
|
+
rb_funcall(buffer, id_method_slice_bang, 1, rb_range_new(INT2FIX(0), INT2FIX(buffer_index - 1), Qfalse));
|
|
75
|
+
buffer_length = RSTRING_LEN(buffer);
|
|
76
|
+
buffer_index = 0;
|
|
77
|
+
rb_ivar_set(self, id_ivar_buffer_index, INT2FIX(buffer_index));
|
|
78
|
+
}
|
|
79
|
+
super_arg = INT2FIX(length - buffer_length);
|
|
80
|
+
rb_str_append(buffer, rb_funcall(rb_call_super(1, (VALUE *)&super_arg), id_method_to_s, 0));
|
|
81
|
+
return rb_funcall(buffer, id_method_slice_bang, 1, rb_const_get(cBufferedFile, id_const_ALL_RANGE));
|
|
82
|
+
}
|
|
83
|
+
else
|
|
84
|
+
{
|
|
85
|
+
return rb_call_super(1, &arg_length);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else
|
|
89
|
+
{
|
|
90
|
+
/* Read into the buffer */
|
|
91
|
+
if (buffer_index > 0)
|
|
92
|
+
{
|
|
93
|
+
rb_funcall(buffer, id_method_slice_bang, 1, rb_range_new(INT2FIX(0), INT2FIX(buffer_index - 1), Qfalse));
|
|
94
|
+
buffer_length = RSTRING_LEN(buffer);
|
|
95
|
+
buffer_index = 0;
|
|
96
|
+
rb_ivar_set(self, id_ivar_buffer_index, INT2FIX(buffer_index));
|
|
97
|
+
}
|
|
98
|
+
super_arg = INT2FIX(BUFFER_SIZE - buffer_length);
|
|
99
|
+
rb_str_append(buffer, rb_funcall(rb_call_super(1, (VALUE *)&super_arg), id_method_to_s, 0));
|
|
100
|
+
buffer_length = RSTRING_LEN(buffer);
|
|
101
|
+
if (buffer_length <= 0)
|
|
102
|
+
{
|
|
103
|
+
return Qnil;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (length <= buffer_length)
|
|
107
|
+
{
|
|
108
|
+
result = rb_str_substr(buffer, buffer_index, length);
|
|
109
|
+
buffer_index += length;
|
|
110
|
+
rb_ivar_set(self, id_ivar_buffer_index, INT2FIX(buffer_index));
|
|
111
|
+
return result;
|
|
112
|
+
}
|
|
113
|
+
else
|
|
114
|
+
{
|
|
115
|
+
return rb_funcall(buffer, id_method_slice_bang, 1, rb_const_get(cBufferedFile, id_const_ALL_RANGE));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/* Get the current file position */
|
|
121
|
+
static VALUE buffered_file_pos(VALUE self)
|
|
122
|
+
{
|
|
123
|
+
volatile VALUE parent_pos = rb_call_super(0, NULL);
|
|
124
|
+
long long ll_pos = NUM2LL(parent_pos);
|
|
125
|
+
long buffer_length = RSTRING_LEN(rb_ivar_get(self, id_ivar_buffer));
|
|
126
|
+
long buffer_index = FIX2INT(rb_ivar_get(self, id_ivar_buffer_index));
|
|
127
|
+
return LL2NUM(ll_pos - (long long)(buffer_length - buffer_index));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/* Seek to a given file position */
|
|
131
|
+
static VALUE buffered_file_seek(int argc, VALUE *argv, VALUE self)
|
|
132
|
+
{
|
|
133
|
+
volatile VALUE amount = Qnil;
|
|
134
|
+
volatile VALUE whence = Qnil;
|
|
135
|
+
long buffer_index = 0;
|
|
136
|
+
volatile VALUE super_args[2] = {Qnil, Qnil};
|
|
137
|
+
|
|
138
|
+
switch (argc)
|
|
139
|
+
{
|
|
140
|
+
case 1:
|
|
141
|
+
amount = argv[0];
|
|
142
|
+
whence = BUFFERED_FILE_SEEK_SET;
|
|
143
|
+
break;
|
|
144
|
+
|
|
145
|
+
case 2:
|
|
146
|
+
amount = argv[0];
|
|
147
|
+
whence = argv[1];
|
|
148
|
+
break;
|
|
149
|
+
|
|
150
|
+
default:
|
|
151
|
+
/* Invalid number of arguments given - let super handle */
|
|
152
|
+
return rb_call_super(argc, argv);
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
if (whence == BUFFERED_FILE_SEEK_CUR)
|
|
156
|
+
{
|
|
157
|
+
buffer_index = FIX2INT(rb_ivar_get(self, id_ivar_buffer_index)) + FIX2INT(amount);
|
|
158
|
+
if ((buffer_index >= 0) && (buffer_index < RSTRING_LEN(rb_ivar_get(self, id_ivar_buffer))))
|
|
159
|
+
{
|
|
160
|
+
rb_ivar_set(self, id_ivar_buffer_index, INT2FIX(buffer_index));
|
|
161
|
+
return INT2FIX(0);
|
|
162
|
+
}
|
|
163
|
+
super_args[0] = rb_funcall(self, id_method_pos, 0);
|
|
164
|
+
super_args[1] = BUFFERED_FILE_SEEK_SET;
|
|
165
|
+
rb_call_super(2, (VALUE *)super_args);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
rb_funcall(rb_ivar_get(self, id_ivar_buffer), id_method_clear, 0);
|
|
169
|
+
rb_ivar_set(self, id_ivar_buffer_index, INT2FIX(0));
|
|
170
|
+
return rb_call_super(argc, argv);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/*
|
|
174
|
+
* Initialize methods for BufferedFile
|
|
175
|
+
*/
|
|
176
|
+
void Init_buffered_file(void)
|
|
177
|
+
{
|
|
178
|
+
id_ivar_buffer = rb_intern("@buffer");
|
|
179
|
+
id_ivar_buffer_index = rb_intern("@buffer_index");
|
|
180
|
+
id_method_clear = rb_intern("clear");
|
|
181
|
+
id_method_slice_bang = rb_intern("slice!");
|
|
182
|
+
id_method_to_s = rb_intern("to_s");
|
|
183
|
+
id_method_pos = rb_intern("pos");
|
|
184
|
+
id_const_BUFFER_SIZE = rb_intern("BUFFER_SIZE");
|
|
185
|
+
id_const_ALL_RANGE = rb_intern("ALL_RANGE");
|
|
186
|
+
BUFFERED_FILE_SEEK_SET = rb_const_get(rb_cIO, rb_intern("SEEK_SET"));
|
|
187
|
+
BUFFERED_FILE_SEEK_CUR = rb_const_get(rb_cIO, rb_intern("SEEK_CUR"));
|
|
188
|
+
|
|
189
|
+
mOpenC3 = rb_define_module("OpenC3");
|
|
190
|
+
cBufferedFile = rb_define_class_under(mOpenC3, "BufferedFile", rb_cFile);
|
|
191
|
+
rb_const_set(cBufferedFile, id_const_BUFFER_SIZE, INT2FIX(BUFFER_SIZE));
|
|
192
|
+
rb_const_set(cBufferedFile, id_const_ALL_RANGE, rb_range_new(INT2FIX(0), INT2FIX(-1), Qfalse));
|
|
193
|
+
|
|
194
|
+
rb_define_method(cBufferedFile, "initialize", buffered_file_initialize, -1);
|
|
195
|
+
rb_define_method(cBufferedFile, "read", buffered_file_read, 1);
|
|
196
|
+
rb_define_method(cBufferedFile, "seek", buffered_file_seek, -1);
|
|
197
|
+
rb_define_method(cBufferedFile, "pos", buffered_file_pos, 0);
|
|
198
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require 'mkmf'
|
|
2
|
+
|
|
3
|
+
unless $CFLAGS.gsub!(/ -O[\dsz]?/, ' -O3')
|
|
4
|
+
$CFLAGS << ' -O3'
|
|
5
|
+
end
|
|
6
|
+
if /gcc/.match?(CONFIG['CC'])
|
|
7
|
+
$CFLAGS << ' -Wall'
|
|
8
|
+
if $DEBUG && !$CFLAGS.gsub!(/ -O[\dsz]?/, ' -O0 -ggdb')
|
|
9
|
+
$CFLAGS << ' -O0 -ggdb'
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
create_makefile 'openc3/ext/buffered_file'
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
/*
|
|
2
|
+
# Copyright 2022 Ball Aerospace & Technologies Corp.
|
|
3
|
+
# All Rights Reserved.
|
|
4
|
+
#
|
|
5
|
+
# This program is free software; you can modify and/or redistribute it
|
|
6
|
+
# under the terms of the GNU Affero General Public License
|
|
7
|
+
# as published by the Free Software Foundation; version 3 with
|
|
8
|
+
# attribution addendums as found in the LICENSE.txt
|
|
9
|
+
#
|
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
# GNU Affero General Public License for more details.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/*
|
|
17
|
+
# Modified by OpenC3, Inc.
|
|
18
|
+
# All changes Copyright 2022, OpenC3, Inc.
|
|
19
|
+
# All Rights Reserved
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
#include "ruby.h"
|
|
23
|
+
#include "stdio.h"
|
|
24
|
+
|
|
25
|
+
VALUE mOpenC3;
|
|
26
|
+
VALUE cConfigParser;
|
|
27
|
+
|
|
28
|
+
static ID id_cvar_progress_callback = 0;
|
|
29
|
+
static ID id_ivar_line_number = 0;
|
|
30
|
+
static ID id_ivar_keyword = 0;
|
|
31
|
+
static ID id_ivar_parameters = 0;
|
|
32
|
+
static ID id_ivar_line = 0;
|
|
33
|
+
static ID id_method_readline = 0;
|
|
34
|
+
static ID id_method_close = 0;
|
|
35
|
+
static ID id_method_pos = 0;
|
|
36
|
+
static ID id_method_call = 0;
|
|
37
|
+
static ID id_method_scan = 0;
|
|
38
|
+
static ID id_method_strip = 0;
|
|
39
|
+
static ID id_method_to_s = 0;
|
|
40
|
+
static ID id_method_upcase = 0;
|
|
41
|
+
|
|
42
|
+
/*
|
|
43
|
+
* Removes quotes from the given string if present.
|
|
44
|
+
*
|
|
45
|
+
* "'quoted string'".remove_quotes #=> "quoted string"
|
|
46
|
+
*/
|
|
47
|
+
static VALUE string_remove_quotes(VALUE self)
|
|
48
|
+
{
|
|
49
|
+
long length = RSTRING_LEN(self);
|
|
50
|
+
char *ptr = RSTRING_PTR(self);
|
|
51
|
+
char first_char = 0;
|
|
52
|
+
char last_char = 0;
|
|
53
|
+
|
|
54
|
+
if (length < 2)
|
|
55
|
+
{
|
|
56
|
+
return self;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
first_char = ptr[0];
|
|
60
|
+
if ((first_char != 34) && (first_char != 39))
|
|
61
|
+
{
|
|
62
|
+
return self;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
last_char = ptr[length - 1];
|
|
66
|
+
if (last_char != first_char)
|
|
67
|
+
{
|
|
68
|
+
return self;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return rb_str_new(ptr + 1, length - 2);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/*
|
|
75
|
+
* Method to read a line from the config file.
|
|
76
|
+
* This is a seperate method so that it can be protected.
|
|
77
|
+
*/
|
|
78
|
+
static VALUE config_parser_readline(VALUE io)
|
|
79
|
+
{
|
|
80
|
+
return rb_funcall(io, id_method_readline, 0);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/*
|
|
84
|
+
* Iterates over each line of the io object and yields the keyword and parameters
|
|
85
|
+
*/
|
|
86
|
+
static VALUE parse_loop(VALUE self, VALUE io, VALUE yield_non_keyword_lines, VALUE remove_quotes, VALUE size, VALUE rx)
|
|
87
|
+
{
|
|
88
|
+
int line_number = 0;
|
|
89
|
+
int result = 0;
|
|
90
|
+
long length = 0;
|
|
91
|
+
int index = 0;
|
|
92
|
+
double float_size = NUM2DBL(size);
|
|
93
|
+
volatile VALUE progress_callback = rb_cvar_get(cConfigParser, id_cvar_progress_callback);
|
|
94
|
+
volatile VALUE line = Qnil;
|
|
95
|
+
volatile VALUE data = Qnil;
|
|
96
|
+
volatile VALUE line_continuation = Qfalse;
|
|
97
|
+
volatile VALUE string = Qnil;
|
|
98
|
+
volatile VALUE array = rb_ary_new();
|
|
99
|
+
volatile VALUE first_item = Qnil;
|
|
100
|
+
volatile VALUE ivar_keyword = Qnil;
|
|
101
|
+
volatile VALUE ivar_parameters = rb_ary_new();
|
|
102
|
+
volatile VALUE ivar_line = Qnil;
|
|
103
|
+
|
|
104
|
+
rb_ivar_set(self, id_ivar_line_number, INT2FIX(0));
|
|
105
|
+
rb_ivar_set(self, id_ivar_keyword, ivar_keyword);
|
|
106
|
+
rb_ivar_set(self, id_ivar_parameters, ivar_parameters);
|
|
107
|
+
rb_ivar_set(self, id_ivar_line, ivar_line);
|
|
108
|
+
|
|
109
|
+
while (1)
|
|
110
|
+
{
|
|
111
|
+
line_number += 1;
|
|
112
|
+
rb_ivar_set(self, id_ivar_line_number, INT2FIX(line_number));
|
|
113
|
+
|
|
114
|
+
if (RTEST(progress_callback) && ((line_number % 10) == 0))
|
|
115
|
+
{
|
|
116
|
+
if (float_size > 0.0)
|
|
117
|
+
{
|
|
118
|
+
double float_pos = NUM2DBL(rb_funcall(io, id_method_pos, 0));
|
|
119
|
+
rb_funcall(progress_callback, id_method_call, 1, rb_float_new(float_pos / float_size));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
line = rb_protect(config_parser_readline, io, &result);
|
|
124
|
+
if (result)
|
|
125
|
+
{
|
|
126
|
+
rb_set_errinfo(Qnil);
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
line = rb_funcall(line, id_method_strip, 0);
|
|
130
|
+
data = rb_funcall(line, id_method_scan, 1, rx);
|
|
131
|
+
first_item = rb_funcall(rb_ary_entry(data, 0), id_method_to_s, 0);
|
|
132
|
+
|
|
133
|
+
if (RTEST(line_continuation))
|
|
134
|
+
{
|
|
135
|
+
rb_str_concat(ivar_line, line);
|
|
136
|
+
/* Carry over keyword and parameters */
|
|
137
|
+
}
|
|
138
|
+
else
|
|
139
|
+
{
|
|
140
|
+
ivar_line = line;
|
|
141
|
+
rb_ivar_set(self, id_ivar_line, ivar_line);
|
|
142
|
+
if ((RSTRING_LEN(first_item) == 0) || (RSTRING_PTR(first_item)[0] == '#'))
|
|
143
|
+
{
|
|
144
|
+
ivar_keyword = Qnil;
|
|
145
|
+
}
|
|
146
|
+
else
|
|
147
|
+
{
|
|
148
|
+
ivar_keyword = rb_funcall(first_item, id_method_upcase, 0);
|
|
149
|
+
}
|
|
150
|
+
rb_ivar_set(self, id_ivar_keyword, ivar_keyword);
|
|
151
|
+
ivar_parameters = rb_ary_new();
|
|
152
|
+
rb_ivar_set(self, id_ivar_parameters, ivar_parameters);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/* Ignore comments and blank lines */
|
|
156
|
+
if (ivar_keyword == Qnil)
|
|
157
|
+
{
|
|
158
|
+
if ((RTEST(yield_non_keyword_lines)) && (!(RTEST(line_continuation))))
|
|
159
|
+
{
|
|
160
|
+
rb_ary_clear(array);
|
|
161
|
+
rb_ary_push(array, ivar_keyword);
|
|
162
|
+
rb_ary_push(array, ivar_parameters);
|
|
163
|
+
rb_yield(array);
|
|
164
|
+
}
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (RTEST(line_continuation))
|
|
169
|
+
{
|
|
170
|
+
if (RTEST(remove_quotes))
|
|
171
|
+
{
|
|
172
|
+
rb_ary_push(ivar_parameters, string_remove_quotes(first_item));
|
|
173
|
+
}
|
|
174
|
+
else
|
|
175
|
+
{
|
|
176
|
+
rb_ary_push(ivar_parameters, first_item);
|
|
177
|
+
}
|
|
178
|
+
line_continuation = Qfalse;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
length = RARRAY_LEN(data);
|
|
182
|
+
if (length > 1)
|
|
183
|
+
{
|
|
184
|
+
for (index = 1; index < length; index++)
|
|
185
|
+
{
|
|
186
|
+
string = rb_ary_entry(data, index);
|
|
187
|
+
|
|
188
|
+
/*
|
|
189
|
+
* Don't process trailing comments such as:
|
|
190
|
+
* KEYWORD PARAM #This is a comment
|
|
191
|
+
* But still process Ruby string interpolations such as:
|
|
192
|
+
* KEYWORD PARAM #{var}
|
|
193
|
+
*/
|
|
194
|
+
if ((RSTRING_LEN(string) > 0) && (RSTRING_PTR(string)[0] == '#'))
|
|
195
|
+
{
|
|
196
|
+
if (!((RSTRING_LEN(string) > 1) && (RSTRING_PTR(string)[1] == '{')))
|
|
197
|
+
{
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/*
|
|
203
|
+
* If the string is simply '&' and its the last string then its a line continuation so break the loop
|
|
204
|
+
*/
|
|
205
|
+
if ((RSTRING_LEN(string) == 1) && (RSTRING_PTR(string)[0] == '&') && (index == (length - 1)))
|
|
206
|
+
{
|
|
207
|
+
line_continuation = Qtrue;
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
line_continuation = Qfalse;
|
|
212
|
+
if (RTEST(remove_quotes))
|
|
213
|
+
{
|
|
214
|
+
rb_ary_push(ivar_parameters, string_remove_quotes(string));
|
|
215
|
+
}
|
|
216
|
+
else
|
|
217
|
+
{
|
|
218
|
+
rb_ary_push(ivar_parameters, string);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/*
|
|
224
|
+
* If we detected a line continuation while going through all the
|
|
225
|
+
* strings on the line then we strip off the continuation character and
|
|
226
|
+
* return to the top of the loop to continue processing the line.
|
|
227
|
+
*/
|
|
228
|
+
if (RTEST(line_continuation))
|
|
229
|
+
{
|
|
230
|
+
/* Strip the continuation character */
|
|
231
|
+
if (RSTRING_LEN(ivar_line) >= 1)
|
|
232
|
+
{
|
|
233
|
+
ivar_line = rb_str_new(RSTRING_PTR(ivar_line), RSTRING_LEN(ivar_line) - 1);
|
|
234
|
+
}
|
|
235
|
+
else
|
|
236
|
+
{
|
|
237
|
+
ivar_line = rb_str_new2("");
|
|
238
|
+
}
|
|
239
|
+
rb_ivar_set(self, id_ivar_line, ivar_line);
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
rb_ary_clear(array);
|
|
244
|
+
rb_ary_push(array, ivar_keyword);
|
|
245
|
+
rb_ary_push(array, ivar_parameters);
|
|
246
|
+
rb_yield(array);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (RTEST(progress_callback))
|
|
250
|
+
{
|
|
251
|
+
rb_funcall(progress_callback, id_method_call, 1, rb_float_new(1.0));
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return Qnil;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/*
|
|
258
|
+
* Initialize methods for ConfigParser
|
|
259
|
+
*/
|
|
260
|
+
void Init_config_parser(void)
|
|
261
|
+
{
|
|
262
|
+
id_cvar_progress_callback = rb_intern("@@progress_callback");
|
|
263
|
+
id_ivar_line_number = rb_intern("@line_number");
|
|
264
|
+
id_ivar_keyword = rb_intern("@keyword");
|
|
265
|
+
id_ivar_parameters = rb_intern("@parameters");
|
|
266
|
+
id_ivar_line = rb_intern("@line");
|
|
267
|
+
id_method_readline = rb_intern("readline");
|
|
268
|
+
id_method_close = rb_intern("close");
|
|
269
|
+
id_method_pos = rb_intern("pos");
|
|
270
|
+
id_method_call = rb_intern("call");
|
|
271
|
+
id_method_scan = rb_intern("scan");
|
|
272
|
+
id_method_strip = rb_intern("strip");
|
|
273
|
+
id_method_to_s = rb_intern("to_s");
|
|
274
|
+
id_method_upcase = rb_intern("upcase");
|
|
275
|
+
|
|
276
|
+
mOpenC3 = rb_define_module("OpenC3");
|
|
277
|
+
|
|
278
|
+
cConfigParser = rb_define_class_under(mOpenC3, "ConfigParser", rb_cObject);
|
|
279
|
+
rb_define_method(cConfigParser, "parse_loop", parse_loop, 5);
|
|
280
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require 'mkmf'
|
|
2
|
+
|
|
3
|
+
unless $CFLAGS.gsub!(/ -O[\dsz]?/, ' -O3')
|
|
4
|
+
$CFLAGS << ' -O3'
|
|
5
|
+
end
|
|
6
|
+
if /gcc/.match?(CONFIG['CC'])
|
|
7
|
+
$CFLAGS << ' -Wall'
|
|
8
|
+
if $DEBUG && !$CFLAGS.gsub!(/ -O[\dsz]?/, ' -O0 -ggdb')
|
|
9
|
+
$CFLAGS << ' -O0 -ggdb'
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
create_makefile 'openc3/ext/config_parser'
|