Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Changes In Branch autosetup-0.7.1 Excluding Merge-Ins
This is equivalent to a diff from 02349c875d to 5eb2953921
|
2024-07-22
| ||
| 23:44 | Upgrade autosetup to upstream version 0.7.1+. Tested on 3 Linux variants with no regressions. check-in: 370c263964 user: stephan tags: trunk | |
| 23:40 | Explicit checkin of autosetup/autosetup-test-tclsh, which the previous checkin again curiously overlooked. Possibly a bug in libfossil's handling of exec-bit-only changes. Closed-Leaf check-in: 5eb2953921 user: stephan tags: autosetup-0.7.1 | |
| 23:39 | Explicit checkin of autosetup/autosetup-test-tclsh, which the previous checkin curiously overlooked. check-in: 5354f5a2d6 user: stephan tags: autosetup-0.7.1 | |
| 23:30 | Upgrade autosetup from 0.6.9 to 0.7.1+. Seems to work but need to try it on more systems before merging. check-in: dacbf76c8a user: stephan tags: autosetup-0.7.1 | |
|
2024-07-12
| ||
| 17:50 | Enable OpenSSL to use the Windows certificate store. check-in: 6fc64abe34 user: florian tags: trunk | |
|
2024-07-09
| ||
| 17:30 | Use the chat-timeline-user setting when formatting results for chat searches. check-in: 02349c875d user: dan tags: trunk | |
| 15:20 | Use the long date format for all messages in the chat search dialog, not just those that match the current query. check-in: 2a3a32edea user: dan tags: trunk | |
Changes to autosetup/README.autosetup.
|
| | | | 1 2 3 4 5 6 7 8 9 10 11 | README.autosetup created by autosetup v0.7.1+ This is the autosetup directory for a local install of autosetup. It contains autosetup, support files and loadable modules. *.tcl files in this directory are optional modules which can be loaded with the 'use' directive. *.auto files in this directory are auto-loaded. For more information, see https://msteveb.github.io/autosetup/ |
Changes to autosetup/autosetup.
1 2 3 4 5 6 7 8 | #!/bin/sh # Copyright (c) 2006-2011 WorkWare Systems http://www.workware.net.au/ # All rights reserved # vim:se syntax=tcl: # \ dir=`dirname "$0"`; exec "`$dir/autosetup-find-tclsh`" "$0" "$@" # Note that the version has a trailing + on unreleased versions | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#!/bin/sh
# Copyright (c) 2006-2011 WorkWare Systems http://www.workware.net.au/
# All rights reserved
# vim:se syntax=tcl:
# \
dir=`dirname "$0"`; exec "`$dir/autosetup-find-tclsh`" "$0" "$@"
# Note that the version has a trailing + on unreleased versions
set autosetup(version) 0.7.1+
# Can be set to 1 to debug early-init problems
set autosetup(debug) [expr {"--debug" in $argv}]
##################################################################
#
# Main flow of control, option handling
|
| ︙ | ︙ | |||
89 90 91 92 93 94 95 |
# At the is point we don't know what is a valid option
# We simply parse anything that looks like an option
set autosetup(getopt) [getopt argv]
#"=Core Options:"
options-add {
| | | | | | 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# At the is point we don't know what is a valid option
# We simply parse anything that looks like an option
set autosetup(getopt) [getopt argv]
#"=Core Options:"
options-add {
help:=all => "display help and options. Optional: module name, such as --help=system"
licence license => "display the autosetup license"
version => "display the version of autosetup"
ref:=text manual:=text
reference:=text => "display the autosetup command reference. 'text', 'wiki', 'asciidoc' or 'markdown'"
debug => "display debugging output as autosetup runs"
install:=. => "install autosetup to the current or given directory"
}
if {$autosetup(installed)} {
# hidden options so we can produce a nice error
options-add {
sysinstall:path
}
} else {
|
| ︙ | ︙ | |||
200 201 202 203 204 205 206 |
} else {
user-error "Unexpected parameter: $arg"
}
}
autosetup_add_dep $autosetup(autodef)
| | | < < | < | | | > > | 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
} else {
user-error "Unexpected parameter: $arg"
}
}
autosetup_add_dep $autosetup(autodef)
# Add $argv to CONFIGURE_OPTS
define-append-argv CONFIGURE_OPTS {*}$autosetup(argv)
# Set up AUTOREMAKE to reconfigure with the same args
define-append-argv AUTOREMAKE {*}$autosetup(exe) {*}$autosetup(argv)
# Log how we were invoked
configlog "Invoked as: [getenv WRAPPER $::argv0] [quote-argv $autosetup(argv)]"
configlog "Tclsh: [info nameofexecutable]"
# Load auto.def as module "auto.def"
autosetup_load_module auto.def source $autosetup(autodef)
# Could warn here if options {} was not specified
show-notices
if {$autosetup(debug)} {
msg-result "Writing all defines to config.log"
configlog "================ defines ======================"
foreach n [lsort [array names define]] {
configlog "define $n $define($n)"
}
}
exit 0
}
# @section Option Handling
# @opt-bool ?-nodefault? option ...
#
# Check each of the named, boolean options and if any have been explicitly enabled
# or disabled by the user, return 1 or 0 accordingly.
#
# If the option was specified more than once, the last value wins.
|
| ︙ | ︙ | |||
338 339 340 341 342 343 344 |
set result [lindex [dict get $::autosetup(optset) $opt] end]
}
}
if {![info exists result]} {
# No user-specified value. Has options-defaults been set?
foreach opt $names {
| | | | 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 |
set result [lindex [dict get $::autosetup(optset) $opt] end]
}
}
if {![info exists result]} {
# No user-specified value. Has options-defaults been set?
foreach opt $names {
if {[dict exists $::autosetup(optdefault) $opt]} {
set result [dict get $autosetup(optdefault) $opt]
}
}
}
if {[info exists result]} {
set value $result
if {$retopt} {
|
| ︙ | ︙ | |||
371 372 373 374 375 376 377 | } } } # Parse the option definition in $opts and update # ::autosetup(setoptions) and ::autosetup(optionhelp) appropriately # | | | < | 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 |
}
}
}
# Parse the option definition in $opts and update
# ::autosetup(setoptions) and ::autosetup(optionhelp) appropriately
#
proc options-add {opts} {
global autosetup
# First weed out comment lines
set realopts {}
foreach line [split $opts \n] {
if {![string match "#*" [string trimleft $line]]} {
append realopts $line \n
}
}
set opts $realopts
for {set i 0} {$i < [llength $opts]} {incr i} {
set opt [lindex $opts $i]
if {[string match =* $opt]} {
# This is a special heading
lappend autosetup(optionhelp) [list $opt $autosetup(module)]
continue
}
unset -nocomplain defaultvalue equal value
#puts "i=$i, opt=$opt"
regexp {^([^:=]*)(:)?(=)?(.*)$} $opt -> name colon equal value
if {$name in $autosetup(options)} {
|
| ︙ | ︙ | |||
449 450 451 452 453 454 455 |
dict set autosetup(optset) $name $setvalue
#puts "Found boolean option --$name=$setvalue"
}
} else {
# String option.
lappend autosetup(options) $name
| | | | | | | 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 |
dict set autosetup(optset) $name $setvalue
#puts "Found boolean option --$name=$setvalue"
}
} else {
# String option.
lappend autosetup(options) $name
if {$equal ne "="} {
# Was the option given as "name:value=default"?
# If so, set $value to the display name and $defaultvalue to the default
# (This is the preferred way to set a default value for a string option)
if {[regexp {^([^=]+)=(.*)$} $value -> value defaultvalue]} {
dict set autosetup(optdefault) $name $defaultvalue
}
}
# Maybe override the default value
if {[dict exists $autosetup(options-defaults) $name]} {
# A default was specified with options-defaults, so use it
set defaultvalue [dict get $autosetup(options-defaults) $name]
dict set autosetup(optdefault) $name $defaultvalue
} elseif {![info exists defaultvalue]} {
# No default value was given by value=default or options-defaults
# so use the value as the default when the plain option with no
# value is given (.e.g. just --opt instead of --opt=value)
set defaultvalue $value
}
if {$equal eq "="} {
# String option with optional value
set opthelp "--$name?=$value?"
} else {
|
| ︙ | ︙ | |||
505 506 507 508 509 510 511 |
# Now create the help for this option if appropriate
if {[lindex $opts $i+1] eq "=>"} {
set desc [lindex $opts $i+2]
if {[info exists defaultvalue]} {
set desc [string map [list @default@ $defaultvalue] $desc]
}
| < < < < < | | < < < < | < < < < < < < < | 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 |
# Now create the help for this option if appropriate
if {[lindex $opts $i+1] eq "=>"} {
set desc [lindex $opts $i+2]
if {[info exists defaultvalue]} {
set desc [string map [list @default@ $defaultvalue] $desc]
}
# A multi-line description
lappend autosetup(optionhelp) [list $opthelp $autosetup(module) $desc]
incr i 2
}
}
}
# @module-options optionlist
#
# Deprecated. Simply use 'options' from within a module.
proc module-options {opts} {
options $opts
}
proc max {a b} {
expr {$a > $b ? $a : $b}
}
proc options-wrap-desc {text length firstprefix nextprefix initial} {
|
| ︙ | ︙ | |||
562 563 564 565 566 567 568 |
set space " "
}
if {$len} {
puts ""
}
}
| > > | > | > > > > | | > > > > > > > > > > | | | > > > > | > | | | < | > > | | | | | > | 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 |
set space " "
}
if {$len} {
puts ""
}
}
# Display options (from $autosetup(optionhelp)) for modules that match
# glob pattern $what
proc options-show {what} {
set local 0
# Determine the max option width
set max 0
foreach help $::autosetup(optionhelp) {
lassign $help opt module desc
if {![string match $what $module]} {
continue
}
if {[string match =* $opt] || [string match \n* $desc]} {
continue
}
set max [max $max [string length $opt]]
}
set indent [string repeat " " [expr {$max+4}]]
set cols [getenv COLUMNS 80]
catch {
lassign [exec stty size] rows cols
}
incr cols -1
# Now output
foreach help $::autosetup(optionhelp) {
lassign $help opt module desc
if {![string match $what $module]} {
continue
}
if {$local == 0 && $module eq "auto.def"} {
puts "Local Options:"
incr local
}
if {[string match =* $opt]} {
# Output a special heading line"
puts [string range $opt 1 end]
continue
}
puts -nonewline " [format %-${max}s $opt]"
if {[string match \n* $desc]} {
# Output a pre-formatted help description as-is
puts $desc
} else {
options-wrap-desc [string trim $desc] $cols " " $indent [expr {$max+2}]
}
}
}
# @options optionspec
#
# Specifies configuration-time options which may be selected by the user
# and checked with 'opt-str' and 'opt-bool'. '$optionspec' contains a series
# of options specifications separated by newlines, as follows:
#
# A boolean option is of the form:
#
## name[=0|1] => "Description of this boolean option"
#
# The default is 'name=0', meaning that the option is disabled by default.
# If 'name=1' is used to make the option enabled by default, the description should reflect
# that with text like "Disable support for ...".
#
# An argument option (one which takes a parameter) is of one of the following forms:
#
## name:value => "Description of this option"
## name:value=default => "Description of this option with a default value"
## name:=value => "Description of this option with an optional value"
#
# If the 'name:value' form is used, the value must be provided with the option (as '--name=myvalue').
# If the 'name:value=default' form is used, the option has the given default value even if not
# specified by the user.
# If the 'name:=value' form is used, the value is optional and the given value is used
# if it is not provided.
#
# The description may contain '@default@', in which case it will be replaced with the default
# value for the option (taking into account defaults specified with 'options-defaults'.
#
# Undocumented options are also supported by omitting the '=> description'.
# These options are not displayed with '--help' and can be useful for internal options or as aliases.
#
# For example, '--disable-lfs' is an alias for '--disable=largefile':
#
## lfs=1 largefile=1 => "Disable large file support"
#
proc options {optlist} {
global autosetup
options-add $optlist
if {$autosetup(showhelp)} {
# If --help, stop now to show help
return -code break
}
if {$autosetup(module) eq "auto.def"} {
# Check for invalid options
if {[opt-bool option-checking]} {
foreach o [dict keys $::autosetup(getopt)] {
if {$o ni $::autosetup(options)} {
user-error "Unknown option --$o"
}
}
}
}
}
# @options-defaults dictionary
#
|
| ︙ | ︙ | |||
675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 |
if {[catch {exec-with-stderr sh $::autosetup(dir)/autosetup-config.sub $alias} alias]} {
user-error $alias
}
}
return $alias
}
# @define name ?value=1?
#
# Defines the named variable to the given value.
# These (name, value) pairs represent the results of the configuration check
# and are available to be subsequently checked, modified and substituted.
#
proc define {name {value 1}} {
set ::define($name) $value
#dputs "$name <= $value"
}
# @undefine name
#
# Undefine the named variable.
#
proc undefine {name} {
unset -nocomplain ::define($name)
#dputs "$name <= <undef>"
}
# @define-append name value ...
#
# Appends the given value(s) to the given "defined" variable.
# If the variable is not defined or empty, it is set to '$value'.
# Otherwise the value is appended, separated by a space.
# Any extra values are similarly appended.
| > > > > > > > > > > > > > > > > > > > > > > > > > > > | < < < < < < < < | < > > > > > > > > > > > > > > > > > > > > > | 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 |
if {[catch {exec-with-stderr sh $::autosetup(dir)/autosetup-config.sub $alias} alias]} {
user-error $alias
}
}
return $alias
}
# @section Variable Definitions (defines)
# @define name ?value=1?
#
# Defines the named variable to the given value.
# These (name, value) pairs represent the results of the configuration check
# and are available to be subsequently checked, modified and substituted.
#
proc define {name {value 1}} {
set ::define($name) $value
#dputs "$name <= $value"
}
# @define-push {name ...} script
#
# Save the values of the given defines, evaluation the script, then restore.
# For example, to avoid updating AS_FLAGS and AS_CXXFLAGS:
## define-push {AS_CFLAGS AS_CXXFLAGS} {
## cc-check-flags -Wno-error
## }
proc define-push {names script} {
array set unset {}
foreach name $names {
if {[is-defined $name]} {
set save($name) [get-define $name]
} else {
set unset($name) 1
}
}
uplevel 1 $script
array set ::define [array get save]
foreach name [array names unset] {
unset -nocomplain ::define($name)
}
}
# @undefine name
#
# Undefine the named variable.
#
proc undefine {name} {
unset -nocomplain ::define($name)
#dputs "$name <= <undef>"
}
# @define-append name value ...
#
# Appends the given value(s) to the given "defined" variable.
# If the variable is not defined or empty, it is set to '$value'.
# Otherwise the value is appended, separated by a space.
# Any extra values are similarly appended.
#
# Note that define-append is not designed to add values containing spaces.
# If values may contain spaces, consider define-append-argv instead.
#
proc define-append {name args} {
if {[get-define $name ""] ne ""} {
foreach arg $args {
if {$arg eq ""} {
continue
}
append ::define($name) " " $arg
}
} else {
set ::define($name) [join $args]
}
#dputs "$name += [join $args] => $::define($name)"
}
# @define-append-argv name value ...
#
# Similar to define-append except designed to construct shell command
# lines, including correct handling of parameters with spaces.
#
# Each non-empty value is quoted if necessary and then appended to the given variable
# if it does not already exist.
#
proc define-append-argv {name args} {
set seen {}
set new {}
foreach val [list {*}[get-define $name ""] {*}$args] {
if {$val ne {} && ![dict exists $seen $val]} {
lappend new [quote-if-needed $val]
dict set seen $val 1
}
}
set ::define($name) [join $new " "]
#dputs "$name += [join $args] => $::define($name)"
}
# @get-define name ?default=0?
#
# Returns the current value of the "defined" variable, or '$default'
# if not set.
#
proc get-define {name {default 0}} {
|
| ︙ | ︙ | |||
771 772 773 774 775 776 777 778 779 780 781 782 783 784 |
# This is suitable for use with 'dict', 'array set' or 'foreach'
# and allows for arbitrary processing of the defined variables.
#
proc all-defines {} {
array get ::define
}
# @get-env name default
#
# If '$name' was specified on the command line, return it.
# Otherwise if '$name' was set in the environment, return it.
# Otherwise return '$default'.
#
| > | 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 |
# This is suitable for use with 'dict', 'array set' or 'foreach'
# and allows for arbitrary processing of the defined variables.
#
proc all-defines {} {
array get ::define
}
# @section Environment/Helpers
# @get-env name default
#
# If '$name' was specified on the command line, return it.
# Otherwise if '$name' was set in the environment, return it.
# Otherwise return '$default'.
#
|
| ︙ | ︙ | |||
853 854 855 856 857 858 859 860 861 862 863 864 865 866 |
foreach p $list {
if {$p ne ""} {
lappend result $p
}
}
return $result
}
# @find-executable-path name
#
# Searches the path for an executable with the given name.
# Note that the name may include some parameters, e.g. 'cc -mbig-endian',
# in which case the parameters are ignored.
# The full path to the executable if found, or "" if not found.
| > > | 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 |
foreach p $list {
if {$p ne ""} {
lappend result $p
}
}
return $result
}
# @section Paths, Searching
# @find-executable-path name
#
# Searches the path for an executable with the given name.
# Note that the name may include some parameters, e.g. 'cc -mbig-endian',
# in which case the parameters are ignored.
# The full path to the executable if found, or "" if not found.
|
| ︙ | ︙ | |||
922 923 924 925 926 927 928 929 930 931 932 933 934 935 |
user-error "failed to find: [join $args]"
} else {
user-error "failed to find one of: [join $args]"
}
}
return ""
}
# @configlog msg
#
# Writes the given message to the configuration log, 'config.log'.
#
proc configlog {msg} {
if {![info exists ::autosetup(logfh)]} {
| > > | 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 |
user-error "failed to find: [join $args]"
} else {
user-error "failed to find one of: [join $args]"
}
}
return ""
}
# @section Logging, Messages and Errors
# @configlog msg
#
# Writes the given message to the configuration log, 'config.log'.
#
proc configlog {msg} {
if {![info exists ::autosetup(logfh)]} {
|
| ︙ | ︙ | |||
1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 |
# Add filename as a dependency to rerun autosetup
# The name will be normalised (converted to a full path)
#
proc autosetup_add_dep {filename} {
lappend ::autosetup(deps) [file-normalize $filename]
}
##################################################################
#
# Library module support
#
# @use module ...
| > > | 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 |
# Add filename as a dependency to rerun autosetup
# The name will be normalised (converted to a full path)
#
proc autosetup_add_dep {filename} {
lappend ::autosetup(deps) [file-normalize $filename]
}
# @section Modules Support
##################################################################
#
# Library module support
#
# @use module ...
|
| ︙ | ︙ | |||
1169 1170 1171 1172 1173 1174 1175 1176 |
lappend dirs $autosetup(srcdir)/autosetup
}
foreach m $args {
if {[info exists libmodule($m)]} {
continue
}
set libmodule($m) 1
if {[info exists modsource(${m}.tcl)]} {
| > | | | | > > > > | > > | 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 |
lappend dirs $autosetup(srcdir)/autosetup
}
foreach m $args {
if {[info exists libmodule($m)]} {
continue
}
set libmodule($m) 1
if {[info exists modsource(${m}.tcl)]} {
autosetup_load_module $m eval $modsource(${m}.tcl)
} else {
set locs [list ${m}.tcl ${m}/init.tcl]
set found 0
foreach dir $dirs {
foreach loc $locs {
set source $dir/$loc
if {[file exists $source]} {
incr found
break
}
}
if {$found} {
break
}
}
if {$found} {
# For the convenience of the "use" source, point to the directory
# it is being loaded from
set ::usedir [file dirname $source]
autosetup_load_module $m source $source
autosetup_add_dep $source
} else {
autosetup-error "use: No such module: $m"
}
}
}
}
proc autosetup_load_auto_modules {} {
global autosetup modsource
# First load any embedded auto modules
foreach mod [array names modsource *.auto] {
autosetup_load_module $mod eval $modsource($mod)
}
# Now any external auto modules
foreach file [glob -nocomplain $autosetup(libdir)/*.auto $autosetup(libdir)/*/*.auto] {
autosetup_load_module [file tail $file] source $file
}
}
# Load module source in the global scope by executing the given command
proc autosetup_load_module {module args} {
global autosetup
set prev $autosetup(module)
set autosetup(module) $module
if {[catch [list uplevel #0 $args] msg opts] ni {0 2 3}} {
autosetup-full-error [error-dump $msg $opts $::autosetup(debug)]
}
set autosetup(module) $prev
}
# Initial settings
set autosetup(exe) $::argv0
set autosetup(istcl) 1
set autosetup(start) [clock millis]
set autosetup(installed) 0
set autosetup(sysinstall) 0
set autosetup(msg-checking) 0
set autosetup(msg-quiet) 0
set autosetup(inittypes) {}
set autosetup(module) autosetup
# Embedded modules are inserted below here
set autosetup(installed) 1
set autosetup(sysinstall) 0
# ----- @module asciidoc-formatting.tcl -----
set modsource(asciidoc-formatting.tcl) {
|
| ︙ | ︙ | |||
1430 1431 1432 1433 1434 1435 1436 |
# Module which provides usage, help and the command reference
proc autosetup_help {what} {
use_pager
puts "Usage: [file tail $::autosetup(exe)] \[options\] \[settings\]\n"
puts "This is [autosetup_version], a build environment \"autoconfigurator\""
| | | > | < | > > > < > < | < < | | < > | 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 |
# Module which provides usage, help and the command reference
proc autosetup_help {what} {
use_pager
puts "Usage: [file tail $::autosetup(exe)] \[options\] \[settings\]\n"
puts "This is [autosetup_version], a build environment \"autoconfigurator\""
puts "See the documentation online at https://msteveb.github.io/autosetup/\n"
if {$what in {all local}} {
# Need to load auto.def now
if {[file exists $::autosetup(autodef)]} {
# Load auto.def as module "auto.def"
autosetup_load_module auto.def source $::autosetup(autodef)
}
if {$what eq "all"} {
set what *
} else {
set what auto.def
}
} else {
use $what
puts "Options for module $what:"
}
options-show $what
exit 0
}
proc autosetup_show_license {} {
global modsource autosetup
use_pager
|
| ︙ | ︙ | |||
1503 1504 1505 1506 1507 1508 1509 |
}
title "[autosetup_version] -- Command Reference"
section {Introduction}
p {
| | > | 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 |
}
title "[autosetup_version] -- Command Reference"
section {Introduction}
p {
See https://msteveb.github.io/autosetup/ for the online documentation for 'autosetup'.
This documentation can also be accessed locally with `autosetup --ref`.
}
p {
'autosetup' provides a number of built-in commands which
are documented below. These may be used from 'auto.def' to test
for features, define variables, create files from templates and
other similar actions.
|
| ︙ | ︙ | |||
1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 |
foreach file $files {
set modulename [file rootname [file tail $file]]
set current _core_
set f [open $file]
while {![eof $f]} {
set line [gets $f]
# Find embedded module names
if {[regexp {^#.*@module ([^ ]*)} $line -> modulename]} {
continue
}
# Find lines starting with "# @*" and continuing through the remaining comment lines
if {![regexp {^# @(.*)} $line -> cmd]} {
continue
}
# Synopsis or command?
if {$cmd eq "synopsis:"} {
set current $modulename
lappend doc($current) [list section "Module: $modulename"]
| > > > > > | | 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 |
foreach file $files {
set modulename [file rootname [file tail $file]]
set current _core_
set f [open $file]
while {![eof $f]} {
set line [gets $f]
if {[regexp {^#.*@section (.*)$} $line -> section]} {
lappend doc($current) [list section $section]
continue
}
# Find embedded module names
if {[regexp {^#.*@module ([^ ]*)} $line -> modulename]} {
continue
}
# Find lines starting with "# @*" and continuing through the remaining comment lines
if {![regexp {^# @(.*)} $line -> cmd]} {
continue
}
# Synopsis or command?
if {$cmd eq "synopsis:"} {
set current $modulename
lappend doc($current) [list section "Module: $modulename"]
} else {
lappend doc($current) [list subsection $cmd]
}
set lines {}
set type p
# Now the description
|
| ︙ | ︙ | |||
1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 |
{#!/bin/sh
WRAPPER="$0"; export WRAPPER; "autosetup" "$@"
}
} else {
writefile configure \
{#!/bin/sh
dir="`dirname "$0"`/autosetup"
WRAPPER="$0"; export WRAPPER; exec "`"$dir/autosetup-find-tclsh"`" "$dir/autosetup" "$@"
}
}
catch {exec chmod 755 configure}
}
# Append the contents of $file to filehandle $f
| > | 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 |
{#!/bin/sh
WRAPPER="$0"; export WRAPPER; "autosetup" "$@"
}
} else {
writefile configure \
{#!/bin/sh
dir="`dirname "$0"`/autosetup"
#@@INITCHECK@@#
WRAPPER="$0"; export WRAPPER; exec "`"$dir/autosetup-find-tclsh"`" "$dir/autosetup" "$@"
}
}
catch {exec chmod 755 configure}
}
# Append the contents of $file to filehandle $f
|
| ︙ | ︙ | |||
1907 1908 1909 1910 1911 1912 1913 |
append readme {
*.tcl files in this directory are optional modules which
can be loaded with the 'use' directive.
*.auto files in this directory are auto-loaded.
| | | 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 |
append readme {
*.tcl files in this directory are optional modules which
can be loaded with the 'use' directive.
*.auto files in this directory are auto-loaded.
For more information, see https://msteveb.github.io/autosetup/
}
dputs "install: autosetup/README.autosetup"
writefile $target $readme
}
}
# ----- @module markdown-formatting.tcl -----
|
| ︙ | ︙ | |||
2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 |
return [lindex $args 0]
}
return -code error "environment variable \"$name\" does not exist"
}
proc isatty? {channel} {
dict exists [fconfigure $channel] -xchar
}
} else {
if {$autosetup(iswin)} {
# On Windows, backslash convert all environment variables
# (Assume that Tcl does this for us)
proc getenv {name args} {
string map {\\ /} [env $name {*}$args]
}
| > > > > > > > > > > > > > | 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 |
return [lindex $args 0]
}
return -code error "environment variable \"$name\" does not exist"
}
proc isatty? {channel} {
dict exists [fconfigure $channel] -xchar
}
# Jim-compatible stacktrace using info frame
proc stacktrace {} {
set stacktrace {}
# 2 to skip the current frame
for {set i 2} {$i < [info frame]} {incr i} {
set frame [info frame -$i]
if {[dict exists $frame file]} {
# We don't need proc, so use ""
lappend stacktrace "" [dict get $frame file] [dict get $frame line]
}
}
return $stacktrace
}
} else {
if {$autosetup(iswin)} {
# On Windows, backslash convert all environment variables
# (Assume that Tcl does this for us)
proc getenv {name args} {
string map {\\ /} [env $name {*}$args]
}
|
| ︙ | ︙ | |||
2094 2095 2096 2097 2098 2099 2100 |
# This is designed to be called for incorrect usage in auto.def, via autosetup-error
#
proc error-location {msg} {
if {$::autosetup(debug)} {
return -code error $msg
}
# Search back through the stack trace for the first error in a .def file
| < < < | < < | | | | 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 |
# This is designed to be called for incorrect usage in auto.def, via autosetup-error
#
proc error-location {msg} {
if {$::autosetup(debug)} {
return -code error $msg
}
# Search back through the stack trace for the first error in a .def file
foreach {p f l} [stacktrace] {
if {[string match *.def $f]} {
return "[relative-path $f]:$l: Error: $msg"
}
#puts "Skipping $f:$l"
}
return $msg
}
# If everything is working properly, the only errors which occur
# should be generated in user code (e.g. auto.def).
# By default, we only want to show the error location in user code.
|
| ︙ | ︙ | |||
2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 |
# ----- @module util.tcl -----
set modsource(util.tcl) {
# Copyright (c) 2012 WorkWare Systems http://www.workware.net.au/
# All rights reserved
# Module which contains miscellaneous utility functions
# @compare-versions version1 version2
#
# Versions are of the form 'a.b.c' (may be any number of numeric components)
#
# Compares the two versions and returns:
## -1 if v1 < v2
| > > | 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 |
# ----- @module util.tcl -----
set modsource(util.tcl) {
# Copyright (c) 2012 WorkWare Systems http://www.workware.net.au/
# All rights reserved
# Module which contains miscellaneous utility functions
# @section Utilities
# @compare-versions version1 version2
#
# Versions are of the form 'a.b.c' (may be any number of numeric components)
#
# Compares the two versions and returns:
## -1 if v1 < v2
|
| ︙ | ︙ |
Changes to autosetup/autosetup-config.guess.
1 2 | #! /bin/sh # Attempt to guess a canonical system name. | | > > | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | #! /bin/sh # Attempt to guess a canonical system name. # Copyright 1992-2021 Free Software Foundation, Inc. # shellcheck disable=SC2006,SC2268 # see below for rationale timestamp='2021-06-03' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, but |
| ︙ | ︙ | |||
23 24 25 26 27 28 29 |
# the same distribution terms that you use for the rest of that
# program. This Exception is an additional permission under section 7
# of the GNU General Public License, version 3 ("GPLv3").
#
# Originally written by Per Bothner; maintained since 2000 by Ben Elliston.
#
# You can get the latest version of this script from:
| | > > > > > > > > | | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# the same distribution terms that you use for the rest of that
# program. This Exception is an additional permission under section 7
# of the GNU General Public License, version 3 ("GPLv3").
#
# Originally written by Per Bothner; maintained since 2000 by Ben Elliston.
#
# You can get the latest version of this script from:
# https://git.savannah.gnu.org/cgit/config.git/plain/config.guess
#
# Please send patches to <config-patches@gnu.org>.
# The "shellcheck disable" line above the timestamp inhibits complaints
# about features and limitations of the classic Bourne shell that were
# superseded or lifted in POSIX. However, this script identifies a wide
# variety of pre-POSIX systems that do not have POSIX shells at all, and
# even some reasonably current systems (Solaris 10 as case-in-point) still
# have a pre-POSIX /bin/sh.
me=`echo "$0" | sed -e 's,.*/,,'`
usage="\
Usage: $0 [OPTION]
Output the configuration name of the system \`$me' is run on.
Options:
-h, --help print this help, then exit
-t, --time-stamp print date of last modification, then exit
-v, --version print version number, then exit
Report bugs and patches to <config-patches@gnu.org>."
version="\
GNU config.guess ($timestamp)
Originally written by Per Bothner.
Copyright 1992-2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
help="
Try \`$me --help' for more information."
|
| ︙ | ︙ | |||
80 81 82 83 84 85 86 | done if test $# != 0; then echo "$me: too many arguments$help" >&2 exit 1 fi | | > > > > > | < < > > | > | | | | | < | | | | | > | | | | | | | | | | > | | | < < | | > > > > > | > | > | > | | < | > > > > > > | < | | | > | | | | | | | | | | > > > | > | | | | | | | | | > > > | | | | | | > > > | | | | > > | | 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
done
if test $# != 0; then
echo "$me: too many arguments$help" >&2
exit 1
fi
# Just in case it came from the environment.
GUESS=
# CC_FOR_BUILD -- compiler used by this script. Note that the use of a
# compiler to aid in system detection is discouraged as it requires
# temporary files to be created and, as you can see below, it is a
# headache to deal with in a portable fashion.
# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still
# use `HOST_CC' if defined, but it is deprecated.
# Portable tmp directory creation inspired by the Autoconf team.
tmp=
# shellcheck disable=SC2172
trap 'test -z "$tmp" || rm -fr "$tmp"' 0 1 2 13 15
set_cc_for_build() {
# prevent multiple calls if $tmp is already set
test "$tmp" && return 0
: "${TMPDIR=/tmp}"
# shellcheck disable=SC2039,SC3028
{ tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
{ test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir "$tmp" 2>/dev/null) ; } ||
{ tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir "$tmp" 2>/dev/null) && echo "Warning: creating insecure temp directory" >&2 ; } ||
{ echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; }
dummy=$tmp/dummy
case ${CC_FOR_BUILD-},${HOST_CC-},${CC-} in
,,) echo "int x;" > "$dummy.c"
for driver in cc gcc c89 c99 ; do
if ($driver -c -o "$dummy.o" "$dummy.c") >/dev/null 2>&1 ; then
CC_FOR_BUILD=$driver
break
fi
done
if test x"$CC_FOR_BUILD" = x ; then
CC_FOR_BUILD=no_compiler_found
fi
;;
,,*) CC_FOR_BUILD=$CC ;;
,*,*) CC_FOR_BUILD=$HOST_CC ;;
esac
}
# This is needed to find uname on a Pyramid OSx when run in the BSD universe.
# (ghazi@noc.rutgers.edu 1994-08-24)
if test -f /.attbin/uname ; then
PATH=$PATH:/.attbin ; export PATH
fi
UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown
UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown
UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown
UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown
case $UNAME_SYSTEM in
Linux|GNU|GNU/*)
LIBC=unknown
set_cc_for_build
cat <<-EOF > "$dummy.c"
#include <features.h>
#if defined(__UCLIBC__)
LIBC=uclibc
#elif defined(__dietlibc__)
LIBC=dietlibc
#elif defined(__GLIBC__)
LIBC=gnu
#else
#include <stdarg.h>
/* First heuristic to detect musl libc. */
#ifdef __DEFINED_va_list
LIBC=musl
#endif
#endif
EOF
cc_set_libc=`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^LIBC' | sed 's, ,,g'`
eval "$cc_set_libc"
# Second heuristic to detect musl libc.
if [ "$LIBC" = unknown ] &&
command -v ldd >/dev/null &&
ldd --version 2>&1 | grep -q ^musl; then
LIBC=musl
fi
# If the system lacks a compiler, then just pick glibc.
# We could probably try harder.
if [ "$LIBC" = unknown ]; then
LIBC=gnu
fi
;;
esac
# Note: order is significant - the case branches are not exclusive.
case $UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION in
*:NetBSD:*:*)
# NetBSD (nbsd) targets should (where applicable) match one or
# more of the tuples: *-*-netbsdelf*, *-*-netbsdaout*,
# *-*-netbsdecoff* and *-*-netbsd*. For targets that recently
# switched to ELF, *-*-netbsd* would select the old
# object file format. This provides both forward
# compatibility and a consistent mechanism for selecting the
# object file format.
#
# Note: NetBSD doesn't particularly care about the vendor
# portion of the name. We always set it to "unknown".
UNAME_MACHINE_ARCH=`(uname -p 2>/dev/null || \
/sbin/sysctl -n hw.machine_arch 2>/dev/null || \
/usr/sbin/sysctl -n hw.machine_arch 2>/dev/null || \
echo unknown)`
case $UNAME_MACHINE_ARCH in
aarch64eb) machine=aarch64_be-unknown ;;
armeb) machine=armeb-unknown ;;
arm*) machine=arm-unknown ;;
sh3el) machine=shl-unknown ;;
sh3eb) machine=sh-unknown ;;
sh5el) machine=sh5le-unknown ;;
earmv*)
arch=`echo "$UNAME_MACHINE_ARCH" | sed -e 's,^e\(armv[0-9]\).*$,\1,'`
endian=`echo "$UNAME_MACHINE_ARCH" | sed -ne 's,^.*\(eb\)$,\1,p'`
machine=${arch}${endian}-unknown
;;
*) machine=$UNAME_MACHINE_ARCH-unknown ;;
esac
# The Operating System including object format, if it has switched
# to ELF recently (or will in the future) and ABI.
case $UNAME_MACHINE_ARCH in
earm*)
os=netbsdelf
;;
arm*|i386|m68k|ns32k|sh3*|sparc|vax)
set_cc_for_build
if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \
| grep -q __ELF__
then
# Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout).
# Return netbsd for either. FIX?
os=netbsd
else
os=netbsdelf
fi
;;
*)
os=netbsd
;;
esac
# Determine ABI tags.
case $UNAME_MACHINE_ARCH in
earm*)
expr='s/^earmv[0-9]/-eabi/;s/eb$//'
abi=`echo "$UNAME_MACHINE_ARCH" | sed -e "$expr"`
;;
esac
# The OS release
# Debian GNU/NetBSD machines have a different userland, and
# thus, need a distinct triplet. However, they do not need
# kernel version information, so it can be replaced with a
# suitable tag, in the style of linux-gnu.
case $UNAME_VERSION in
Debian*)
release='-gnu'
;;
*)
release=`echo "$UNAME_RELEASE" | sed -e 's/[-_].*//' | cut -d. -f1,2`
;;
esac
# Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM:
# contains redundant information, the shorter form:
# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used.
GUESS=$machine-${os}${release}${abi-}
;;
*:Bitrig:*:*)
UNAME_MACHINE_ARCH=`arch | sed 's/Bitrig.//'`
GUESS=$UNAME_MACHINE_ARCH-unknown-bitrig$UNAME_RELEASE
;;
*:OpenBSD:*:*)
UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'`
GUESS=$UNAME_MACHINE_ARCH-unknown-openbsd$UNAME_RELEASE
;;
*:SecBSD:*:*)
UNAME_MACHINE_ARCH=`arch | sed 's/SecBSD.//'`
GUESS=$UNAME_MACHINE_ARCH-unknown-secbsd$UNAME_RELEASE
;;
*:LibertyBSD:*:*)
UNAME_MACHINE_ARCH=`arch | sed 's/^.*BSD\.//'`
GUESS=$UNAME_MACHINE_ARCH-unknown-libertybsd$UNAME_RELEASE
;;
*:MidnightBSD:*:*)
GUESS=$UNAME_MACHINE-unknown-midnightbsd$UNAME_RELEASE
;;
*:ekkoBSD:*:*)
GUESS=$UNAME_MACHINE-unknown-ekkobsd$UNAME_RELEASE
;;
*:SolidBSD:*:*)
GUESS=$UNAME_MACHINE-unknown-solidbsd$UNAME_RELEASE
;;
*:OS108:*:*)
GUESS=$UNAME_MACHINE-unknown-os108_$UNAME_RELEASE
;;
macppc:MirBSD:*:*)
GUESS=powerpc-unknown-mirbsd$UNAME_RELEASE
;;
*:MirBSD:*:*)
GUESS=$UNAME_MACHINE-unknown-mirbsd$UNAME_RELEASE
;;
*:Sortix:*:*)
GUESS=$UNAME_MACHINE-unknown-sortix
;;
*:Twizzler:*:*)
GUESS=$UNAME_MACHINE-unknown-twizzler
;;
*:Redox:*:*)
GUESS=$UNAME_MACHINE-unknown-redox
;;
mips:OSF1:*.*)
GUESS=mips-dec-osf1
;;
alpha:OSF1:*:*)
# Reset EXIT trap before exiting to avoid spurious non-zero exit code.
trap '' 0
case $UNAME_RELEASE in
*4.0)
UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'`
;;
*5.*)
UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'`
;;
esac
# According to Compaq, /usr/sbin/psrinfo has been available on
# OSF/1 and Tru64 systems produced since 1995. I hope that
# covers most systems running today. This code pipes the CPU
# types through head -n 1, so we only detect the type of CPU 0.
ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1`
case $ALPHA_CPU_TYPE in
"EV4 (21064)")
UNAME_MACHINE=alpha ;;
"EV4.5 (21064)")
UNAME_MACHINE=alpha ;;
"LCA4 (21066/21068)")
UNAME_MACHINE=alpha ;;
"EV5 (21164)")
|
| ︙ | ︙ | |||
322 323 324 325 326 327 328 | UNAME_MACHINE=alphaev79 ;; esac # A Pn.n version is a patched version. # A Vn.n version is a released version. # A Tn.n version is a released field test version. # A Xn.n version is an unreleased experimental baselevel. # 1.2 uses "1.2" for uname -r. | | | < < | | | | | | | | | | | | | | | | | | | | | < | < > | | | | | | | > | > | | > | | > | | | | | | > | | > | | | > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 |
UNAME_MACHINE=alphaev79 ;;
esac
# A Pn.n version is a patched version.
# A Vn.n version is a released version.
# A Tn.n version is a released field test version.
# A Xn.n version is an unreleased experimental baselevel.
# 1.2 uses "1.2" for uname -r.
OSF_REL=`echo "$UNAME_RELEASE" | sed -e 's/^[PVTX]//' | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`
GUESS=$UNAME_MACHINE-dec-osf$OSF_REL
;;
Amiga*:UNIX_System_V:4.0:*)
GUESS=m68k-unknown-sysv4
;;
*:[Aa]miga[Oo][Ss]:*:*)
GUESS=$UNAME_MACHINE-unknown-amigaos
;;
*:[Mm]orph[Oo][Ss]:*:*)
GUESS=$UNAME_MACHINE-unknown-morphos
;;
*:OS/390:*:*)
GUESS=i370-ibm-openedition
;;
*:z/VM:*:*)
GUESS=s390-ibm-zvmoe
;;
*:OS400:*:*)
GUESS=powerpc-ibm-os400
;;
arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
GUESS=arm-acorn-riscix$UNAME_RELEASE
;;
arm*:riscos:*:*|arm*:RISCOS:*:*)
GUESS=arm-unknown-riscos
;;
SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*)
GUESS=hppa1.1-hitachi-hiuxmpp
;;
Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*)
# akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE.
case `(/bin/universe) 2>/dev/null` in
att) GUESS=pyramid-pyramid-sysv3 ;;
*) GUESS=pyramid-pyramid-bsd ;;
esac
;;
NILE*:*:*:dcosx)
GUESS=pyramid-pyramid-svr4
;;
DRS?6000:unix:4.0:6*)
GUESS=sparc-icl-nx6
;;
DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*)
case `/usr/bin/uname -p` in
sparc) GUESS=sparc-icl-nx7 ;;
esac
;;
s390x:SunOS:*:*)
SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'`
GUESS=$UNAME_MACHINE-ibm-solaris2$SUN_REL
;;
sun4H:SunOS:5.*:*)
SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'`
GUESS=sparc-hal-solaris2$SUN_REL
;;
sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*)
SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'`
GUESS=sparc-sun-solaris2$SUN_REL
;;
i86pc:AuroraUX:5.*:* | i86xen:AuroraUX:5.*:*)
GUESS=i386-pc-auroraux$UNAME_RELEASE
;;
i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*)
set_cc_for_build
SUN_ARCH=i386
# If there is a compiler, see if it is configured for 64-bit objects.
# Note that the Sun cc does not turn __LP64__ into 1 like gcc does.
# This test works for both compilers.
if test "$CC_FOR_BUILD" != no_compiler_found; then
if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \
(CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \
grep IS_64BIT_ARCH >/dev/null
then
SUN_ARCH=x86_64
fi
fi
SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'`
GUESS=$SUN_ARCH-pc-solaris2$SUN_REL
;;
sun4*:SunOS:6*:*)
# According to config.sub, this is the proper way to canonicalize
# SunOS6. Hard to guess exactly what SunOS6 will be like, but
# it's likely to be more like Solaris than SunOS4.
SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'`
GUESS=sparc-sun-solaris3$SUN_REL
;;
sun4*:SunOS:*:*)
case `/usr/bin/arch -k` in
Series*|S4*)
UNAME_RELEASE=`uname -v`
;;
esac
# Japanese Language versions have a version number like `4.1.3-JL'.
SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/-/_/'`
GUESS=sparc-sun-sunos$SUN_REL
;;
sun3*:SunOS:*:*)
GUESS=m68k-sun-sunos$UNAME_RELEASE
;;
sun*:*:4.2BSD:*)
UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null`
test "x$UNAME_RELEASE" = x && UNAME_RELEASE=3
case `/bin/arch` in
sun3)
GUESS=m68k-sun-sunos$UNAME_RELEASE
;;
sun4)
GUESS=sparc-sun-sunos$UNAME_RELEASE
;;
esac
;;
aushp:SunOS:*:*)
GUESS=sparc-auspex-sunos$UNAME_RELEASE
;;
# The situation for MiNT is a little confusing. The machine name
# can be virtually everything (everything which is not
# "atarist" or "atariste" at least should have a processor
# > m68000). The system name ranges from "MiNT" over "FreeMiNT"
# to the lowercase version "mint" (or "freemint"). Finally
# the system name "TOS" denotes a system which is actually not
# MiNT. But MiNT is downward compatible to TOS, so this should
# be no problem.
atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*)
GUESS=m68k-atari-mint$UNAME_RELEASE
;;
atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*)
GUESS=m68k-atari-mint$UNAME_RELEASE
;;
*falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*)
GUESS=m68k-atari-mint$UNAME_RELEASE
;;
milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*)
GUESS=m68k-milan-mint$UNAME_RELEASE
;;
hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*)
GUESS=m68k-hades-mint$UNAME_RELEASE
;;
*:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*)
GUESS=m68k-unknown-mint$UNAME_RELEASE
;;
m68k:machten:*:*)
GUESS=m68k-apple-machten$UNAME_RELEASE
;;
powerpc:machten:*:*)
GUESS=powerpc-apple-machten$UNAME_RELEASE
;;
RISC*:Mach:*:*)
GUESS=mips-dec-mach_bsd4.3
;;
RISC*:ULTRIX:*:*)
GUESS=mips-dec-ultrix$UNAME_RELEASE
;;
VAX*:ULTRIX*:*:*)
GUESS=vax-dec-ultrix$UNAME_RELEASE
;;
2020:CLIX:*:* | 2430:CLIX:*:*)
GUESS=clipper-intergraph-clix$UNAME_RELEASE
;;
mips:*:*:UMIPS | mips:*:*:RISCos)
set_cc_for_build
sed 's/^ //' << EOF > "$dummy.c"
#ifdef __cplusplus
#include <stdio.h> /* for printf() prototype */
int main (int argc, char *argv[]) {
#else
int main (argc, argv) int argc; char *argv[]; {
#endif
|
| ︙ | ︙ | |||
504 505 506 507 508 509 510 |
exit (-1);
}
EOF
$CC_FOR_BUILD -o "$dummy" "$dummy.c" &&
dummyarg=`echo "$UNAME_RELEASE" | sed -n 's/\([0-9]*\).*/\1/p'` &&
SYSTEM_NAME=`"$dummy" "$dummyarg"` &&
{ echo "$SYSTEM_NAME"; exit; }
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 |
exit (-1);
}
EOF
$CC_FOR_BUILD -o "$dummy" "$dummy.c" &&
dummyarg=`echo "$UNAME_RELEASE" | sed -n 's/\([0-9]*\).*/\1/p'` &&
SYSTEM_NAME=`"$dummy" "$dummyarg"` &&
{ echo "$SYSTEM_NAME"; exit; }
GUESS=mips-mips-riscos$UNAME_RELEASE
;;
Motorola:PowerMAX_OS:*:*)
GUESS=powerpc-motorola-powermax
;;
Motorola:*:4.3:PL8-*)
GUESS=powerpc-harris-powermax
;;
Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*)
GUESS=powerpc-harris-powermax
;;
Night_Hawk:Power_UNIX:*:*)
GUESS=powerpc-harris-powerunix
;;
m88k:CX/UX:7*:*)
GUESS=m88k-harris-cxux7
;;
m88k:*:4*:R4*)
GUESS=m88k-motorola-sysv4
;;
m88k:*:3*:R3*)
GUESS=m88k-motorola-sysv3
;;
AViiON:dgux:*:*)
# DG/UX returns AViiON for all architectures
UNAME_PROCESSOR=`/usr/bin/uname -p`
if test "$UNAME_PROCESSOR" = mc88100 || test "$UNAME_PROCESSOR" = mc88110
then
if test "$TARGET_BINARY_INTERFACE"x = m88kdguxelfx || \
test "$TARGET_BINARY_INTERFACE"x = x
then
GUESS=m88k-dg-dgux$UNAME_RELEASE
else
GUESS=m88k-dg-dguxbcs$UNAME_RELEASE
fi
else
GUESS=i586-dg-dgux$UNAME_RELEASE
fi
;;
M88*:DolphinOS:*:*) # DolphinOS (SVR3)
GUESS=m88k-dolphin-sysv3
;;
M88*:*:R3*:*)
# Delta 88k system running SVR3
GUESS=m88k-motorola-sysv3
;;
XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3)
GUESS=m88k-tektronix-sysv3
;;
Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD)
GUESS=m68k-tektronix-bsd
;;
*:IRIX*:*:*)
IRIX_REL=`echo "$UNAME_RELEASE" | sed -e 's/-/_/g'`
GUESS=mips-sgi-irix$IRIX_REL
;;
????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX.
GUESS=romp-ibm-aix # uname -m gives an 8 hex-code CPU id
;; # Note that: echo "'`uname -s`'" gives 'AIX '
i*86:AIX:*:*)
GUESS=i386-ibm-aix
;;
ia64:AIX:*:*)
if test -x /usr/bin/oslevel ; then
IBM_REV=`/usr/bin/oslevel`
else
IBM_REV=$UNAME_VERSION.$UNAME_RELEASE
fi
GUESS=$UNAME_MACHINE-ibm-aix$IBM_REV
;;
*:AIX:2:3)
if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then
set_cc_for_build
sed 's/^ //' << EOF > "$dummy.c"
#include <sys/systemcfg.h>
main()
{
if (!__power_pc())
exit(1);
puts("powerpc-ibm-aix3.2.5");
exit(0);
}
EOF
if $CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=`"$dummy"`
then
GUESS=$SYSTEM_NAME
else
GUESS=rs6000-ibm-aix3.2.5
fi
elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then
GUESS=rs6000-ibm-aix3.2.4
else
GUESS=rs6000-ibm-aix3.2
fi
;;
*:AIX:*:[4567])
IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`
if /usr/sbin/lsattr -El "$IBM_CPU_ID" | grep ' POWER' >/dev/null 2>&1; then
IBM_ARCH=rs6000
else
IBM_ARCH=powerpc
fi
if test -x /usr/bin/lslpp ; then
IBM_REV=`/usr/bin/lslpp -Lqc bos.rte.libc | \
awk -F: '{ print $3 }' | sed s/[0-9]*$/0/`
else
IBM_REV=$UNAME_VERSION.$UNAME_RELEASE
fi
GUESS=$IBM_ARCH-ibm-aix$IBM_REV
;;
*:AIX:*:*)
GUESS=rs6000-ibm-aix
;;
ibmrt:4.4BSD:*|romp-ibm:4.4BSD:*)
GUESS=romp-ibm-bsd4.4
;;
ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and
GUESS=romp-ibm-bsd$UNAME_RELEASE # 4.3 with uname added to
;; # report: romp-ibm BSD 4.3
*:BOSX:*:*)
GUESS=rs6000-bull-bosx
;;
DPX/2?00:B.O.S.:*:*)
GUESS=m68k-bull-sysv3
;;
9000/[34]??:4.3bsd:1.*:*)
GUESS=m68k-hp-bsd
;;
hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*)
GUESS=m68k-hp-bsd4.4
;;
9000/[34678]??:HP-UX:*:*)
HPUX_REV=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*.[0B]*//'`
case $UNAME_MACHINE in
9000/31?) HP_ARCH=m68000 ;;
9000/[34]??) HP_ARCH=m68k ;;
9000/[678][0-9][0-9])
if test -x /usr/bin/getconf; then
sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null`
sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`
case $sc_cpu_version in
523) HP_ARCH=hppa1.0 ;; # CPU_PA_RISC1_0
528) HP_ARCH=hppa1.1 ;; # CPU_PA_RISC1_1
532) # CPU_PA_RISC2_0
case $sc_kernel_bits in
32) HP_ARCH=hppa2.0n ;;
64) HP_ARCH=hppa2.0w ;;
'') HP_ARCH=hppa2.0 ;; # HP-UX 10.20
esac ;;
esac
fi
if test "$HP_ARCH" = ""; then
set_cc_for_build
sed 's/^ //' << EOF > "$dummy.c"
#define _HPUX_SOURCE
#include <stdlib.h>
#include <unistd.h>
int main ()
|
| ︙ | ︙ | |||
694 695 696 697 698 699 700 | exit (0); } EOF (CCOPTS="" $CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null) && HP_ARCH=`"$dummy"` test -z "$HP_ARCH" && HP_ARCH=hppa fi ;; esac | | | | | | | | | | 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 |
exit (0);
}
EOF
(CCOPTS="" $CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null) && HP_ARCH=`"$dummy"`
test -z "$HP_ARCH" && HP_ARCH=hppa
fi ;;
esac
if test "$HP_ARCH" = hppa2.0w
then
set_cc_for_build
# hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating
# 32-bit code. hppa64-hp-hpux* has the same kernel and a compiler
# generating 64-bit code. GNU and HP use different nomenclature:
#
# $ CC_FOR_BUILD=cc ./config.guess
# => hppa2.0w-hp-hpux11.23
# $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess
# => hppa64-hp-hpux11.23
if echo __LP64__ | (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) |
grep -q __LP64__
then
HP_ARCH=hppa2.0w
else
HP_ARCH=hppa64
fi
fi
GUESS=$HP_ARCH-hp-hpux$HPUX_REV
;;
ia64:HP-UX:*:*)
HPUX_REV=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*.[0B]*//'`
GUESS=ia64-hp-hpux$HPUX_REV
;;
3050*:HI-UX:*:*)
set_cc_for_build
sed 's/^ //' << EOF > "$dummy.c"
#include <unistd.h>
int
main ()
{
long cpu = sysconf (_SC_CPU_VERSION);
/* The order matters, because CPU_IS_HP_MC68K erroneously returns
|
| ︙ | ︙ | |||
750 751 752 753 754 755 756 |
puts ("m68k-hitachi-hiuxwe2");
else puts ("unknown-hitachi-hiuxwe2");
exit (0);
}
EOF
$CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=`"$dummy"` &&
{ echo "$SYSTEM_NAME"; exit; }
| | | | | | | | | | | | | | | | | | | | | | | | | | | | > | | > | | > | | > | | > | | | | | | | | | > > > > > > > > | > > > > > | | | > | | | | | | | | | | | | | | | | | | | | | | > | | | > > | | > > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > > > | | | | | > > | | > > > > > > > > > > > > > > > > > > > > > > > > > > < > < > | | > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > > > > > > > > > > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 |
puts ("m68k-hitachi-hiuxwe2");
else puts ("unknown-hitachi-hiuxwe2");
exit (0);
}
EOF
$CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=`"$dummy"` &&
{ echo "$SYSTEM_NAME"; exit; }
GUESS=unknown-hitachi-hiuxwe2
;;
9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:*)
GUESS=hppa1.1-hp-bsd
;;
9000/8??:4.3bsd:*:*)
GUESS=hppa1.0-hp-bsd
;;
*9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*)
GUESS=hppa1.0-hp-mpeix
;;
hp7??:OSF1:*:* | hp8?[79]:OSF1:*:*)
GUESS=hppa1.1-hp-osf
;;
hp8??:OSF1:*:*)
GUESS=hppa1.0-hp-osf
;;
i*86:OSF1:*:*)
if test -x /usr/sbin/sysversion ; then
GUESS=$UNAME_MACHINE-unknown-osf1mk
else
GUESS=$UNAME_MACHINE-unknown-osf1
fi
;;
parisc*:Lites*:*:*)
GUESS=hppa1.1-hp-lites
;;
C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*)
GUESS=c1-convex-bsd
;;
C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*)
if getsysinfo -f scalar_acc
then echo c32-convex-bsd
else echo c2-convex-bsd
fi
exit ;;
C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*)
GUESS=c34-convex-bsd
;;
C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*)
GUESS=c38-convex-bsd
;;
C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*)
GUESS=c4-convex-bsd
;;
CRAY*Y-MP:*:*:*)
CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'`
GUESS=ymp-cray-unicos$CRAY_REL
;;
CRAY*[A-Z]90:*:*:*)
echo "$UNAME_MACHINE"-cray-unicos"$UNAME_RELEASE" \
| sed -e 's/CRAY.*\([A-Z]90\)/\1/' \
-e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \
-e 's/\.[^.]*$/.X/'
exit ;;
CRAY*TS:*:*:*)
CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'`
GUESS=t90-cray-unicos$CRAY_REL
;;
CRAY*T3E:*:*:*)
CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'`
GUESS=alphaev5-cray-unicosmk$CRAY_REL
;;
CRAY*SV1:*:*:*)
CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'`
GUESS=sv1-cray-unicos$CRAY_REL
;;
*:UNICOS/mp:*:*)
CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'`
GUESS=craynv-cray-unicosmp$CRAY_REL
;;
F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*)
FUJITSU_PROC=`uname -m | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`
FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'`
FUJITSU_REL=`echo "$UNAME_RELEASE" | sed -e 's/ /_/'`
GUESS=${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}
;;
5000:UNIX_System_V:4.*:*)
FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'`
FUJITSU_REL=`echo "$UNAME_RELEASE" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/ /_/'`
GUESS=sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}
;;
i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*)
GUESS=$UNAME_MACHINE-pc-bsdi$UNAME_RELEASE
;;
sparc*:BSD/OS:*:*)
GUESS=sparc-unknown-bsdi$UNAME_RELEASE
;;
*:BSD/OS:*:*)
GUESS=$UNAME_MACHINE-unknown-bsdi$UNAME_RELEASE
;;
arm:FreeBSD:*:*)
UNAME_PROCESSOR=`uname -p`
set_cc_for_build
if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \
| grep -q __ARM_PCS_VFP
then
FREEBSD_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'`
GUESS=$UNAME_PROCESSOR-unknown-freebsd$FREEBSD_REL-gnueabi
else
FREEBSD_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'`
GUESS=$UNAME_PROCESSOR-unknown-freebsd$FREEBSD_REL-gnueabihf
fi
;;
*:FreeBSD:*:*)
UNAME_PROCESSOR=`/usr/bin/uname -p`
case $UNAME_PROCESSOR in
amd64)
UNAME_PROCESSOR=x86_64 ;;
i386)
UNAME_PROCESSOR=i586 ;;
esac
FREEBSD_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'`
GUESS=$UNAME_PROCESSOR-unknown-freebsd$FREEBSD_REL
;;
i*:CYGWIN*:*)
GUESS=$UNAME_MACHINE-pc-cygwin
;;
*:MINGW64*:*)
GUESS=$UNAME_MACHINE-pc-mingw64
;;
*:MINGW*:*)
GUESS=$UNAME_MACHINE-pc-mingw32
;;
*:MSYS*:*)
GUESS=$UNAME_MACHINE-pc-msys
;;
i*:PW*:*)
GUESS=$UNAME_MACHINE-pc-pw32
;;
*:Interix*:*)
case $UNAME_MACHINE in
x86)
GUESS=i586-pc-interix$UNAME_RELEASE
;;
authenticamd | genuineintel | EM64T)
GUESS=x86_64-unknown-interix$UNAME_RELEASE
;;
IA64)
GUESS=ia64-unknown-interix$UNAME_RELEASE
;;
esac ;;
i*:UWIN*:*)
GUESS=$UNAME_MACHINE-pc-uwin
;;
amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*)
GUESS=x86_64-pc-cygwin
;;
prep*:SunOS:5.*:*)
SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'`
GUESS=powerpcle-unknown-solaris2$SUN_REL
;;
*:GNU:*:*)
# the GNU system
GNU_ARCH=`echo "$UNAME_MACHINE" | sed -e 's,[-/].*$,,'`
GNU_REL=`echo "$UNAME_RELEASE" | sed -e 's,/.*$,,'`
GUESS=$GNU_ARCH-unknown-$LIBC$GNU_REL
;;
*:GNU/*:*:*)
# other systems with GNU libc and userland
GNU_SYS=`echo "$UNAME_SYSTEM" | sed 's,^[^/]*/,,' | tr "[:upper:]" "[:lower:]"`
GNU_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'`
GUESS=$UNAME_MACHINE-unknown-$GNU_SYS$GNU_REL-$LIBC
;;
*:Minix:*:*)
GUESS=$UNAME_MACHINE-unknown-minix
;;
aarch64:Linux:*:*)
GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
;;
aarch64_be:Linux:*:*)
UNAME_MACHINE=aarch64_be
GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
;;
alpha:Linux:*:*)
case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' /proc/cpuinfo 2>/dev/null` in
EV5) UNAME_MACHINE=alphaev5 ;;
EV56) UNAME_MACHINE=alphaev56 ;;
PCA56) UNAME_MACHINE=alphapca56 ;;
PCA57) UNAME_MACHINE=alphapca56 ;;
EV6) UNAME_MACHINE=alphaev6 ;;
EV67) UNAME_MACHINE=alphaev67 ;;
EV68*) UNAME_MACHINE=alphaev68 ;;
esac
objdump --private-headers /bin/sh | grep -q ld.so.1
if test "$?" = 0 ; then LIBC=gnulibc1 ; fi
GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
;;
arc:Linux:*:* | arceb:Linux:*:* | arc32:Linux:*:* | arc64:Linux:*:*)
GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
;;
arm*:Linux:*:*)
set_cc_for_build
if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \
| grep -q __ARM_EABI__
then
GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
else
if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \
| grep -q __ARM_PCS_VFP
then
GUESS=$UNAME_MACHINE-unknown-linux-${LIBC}eabi
else
GUESS=$UNAME_MACHINE-unknown-linux-${LIBC}eabihf
fi
fi
;;
avr32*:Linux:*:*)
GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
;;
cris:Linux:*:*)
GUESS=$UNAME_MACHINE-axis-linux-$LIBC
;;
crisv32:Linux:*:*)
GUESS=$UNAME_MACHINE-axis-linux-$LIBC
;;
e2k:Linux:*:*)
GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
;;
frv:Linux:*:*)
GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
;;
hexagon:Linux:*:*)
GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
;;
i*86:Linux:*:*)
GUESS=$UNAME_MACHINE-pc-linux-$LIBC
;;
ia64:Linux:*:*)
GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
;;
k1om:Linux:*:*)
GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
;;
loongarch32:Linux:*:* | loongarch64:Linux:*:* | loongarchx32:Linux:*:*)
GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
;;
m32r*:Linux:*:*)
GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
;;
m68*:Linux:*:*)
GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
;;
mips:Linux:*:* | mips64:Linux:*:*)
set_cc_for_build
IS_GLIBC=0
test x"${LIBC}" = xgnu && IS_GLIBC=1
sed 's/^ //' << EOF > "$dummy.c"
#undef CPU
#undef mips
#undef mipsel
#undef mips64
#undef mips64el
#if ${IS_GLIBC} && defined(_ABI64)
LIBCABI=gnuabi64
#else
#if ${IS_GLIBC} && defined(_ABIN32)
LIBCABI=gnuabin32
#else
LIBCABI=${LIBC}
#endif
#endif
#if ${IS_GLIBC} && defined(__mips64) && defined(__mips_isa_rev) && __mips_isa_rev>=6
CPU=mipsisa64r6
#else
#if ${IS_GLIBC} && !defined(__mips64) && defined(__mips_isa_rev) && __mips_isa_rev>=6
CPU=mipsisa32r6
#else
#if defined(__mips64)
CPU=mips64
#else
CPU=mips
#endif
#endif
#endif
#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
MIPS_ENDIAN=el
#else
#if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
MIPS_ENDIAN=
#else
MIPS_ENDIAN=
#endif
#endif
EOF
cc_set_vars=`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^CPU\|^MIPS_ENDIAN\|^LIBCABI'`
eval "$cc_set_vars"
test "x$CPU" != x && { echo "$CPU${MIPS_ENDIAN}-unknown-linux-$LIBCABI"; exit; }
;;
mips64el:Linux:*:*)
GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
;;
openrisc*:Linux:*:*)
GUESS=or1k-unknown-linux-$LIBC
;;
or32:Linux:*:* | or1k*:Linux:*:*)
GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
;;
padre:Linux:*:*)
GUESS=sparc-unknown-linux-$LIBC
;;
parisc64:Linux:*:* | hppa64:Linux:*:*)
GUESS=hppa64-unknown-linux-$LIBC
;;
parisc:Linux:*:* | hppa:Linux:*:*)
# Look for CPU level
case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in
PA7*) GUESS=hppa1.1-unknown-linux-$LIBC ;;
PA8*) GUESS=hppa2.0-unknown-linux-$LIBC ;;
*) GUESS=hppa-unknown-linux-$LIBC ;;
esac
;;
ppc64:Linux:*:*)
GUESS=powerpc64-unknown-linux-$LIBC
;;
ppc:Linux:*:*)
GUESS=powerpc-unknown-linux-$LIBC
;;
ppc64le:Linux:*:*)
GUESS=powerpc64le-unknown-linux-$LIBC
;;
ppcle:Linux:*:*)
GUESS=powerpcle-unknown-linux-$LIBC
;;
riscv32:Linux:*:* | riscv32be:Linux:*:* | riscv64:Linux:*:* | riscv64be:Linux:*:*)
GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
;;
s390:Linux:*:* | s390x:Linux:*:*)
GUESS=$UNAME_MACHINE-ibm-linux-$LIBC
;;
sh64*:Linux:*:*)
GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
;;
sh*:Linux:*:*)
GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
;;
sparc:Linux:*:* | sparc64:Linux:*:*)
GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
;;
tile*:Linux:*:*)
GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
;;
vax:Linux:*:*)
GUESS=$UNAME_MACHINE-dec-linux-$LIBC
;;
x86_64:Linux:*:*)
set_cc_for_build
LIBCABI=$LIBC
if test "$CC_FOR_BUILD" != no_compiler_found; then
if (echo '#ifdef __ILP32__'; echo IS_X32; echo '#endif') | \
(CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \
grep IS_X32 >/dev/null
then
LIBCABI=${LIBC}x32
fi
fi
GUESS=$UNAME_MACHINE-pc-linux-$LIBCABI
;;
xtensa*:Linux:*:*)
GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
;;
i*86:DYNIX/ptx:4*:*)
# ptx 4.0 does uname -s correctly, with DYNIX/ptx in there.
# earlier versions are messed up and put the nodename in both
# sysname and nodename.
GUESS=i386-sequent-sysv4
;;
i*86:UNIX_SV:4.2MP:2.*)
# Unixware is an offshoot of SVR4, but it has its own version
# number series starting with 2...
# I am not positive that other SVR4 systems won't match this,
# I just have to hope. -- rms.
# Use sysv4.2uw... so that sysv4* matches it.
GUESS=$UNAME_MACHINE-pc-sysv4.2uw$UNAME_VERSION
;;
i*86:OS/2:*:*)
# If we were able to find `uname', then EMX Unix compatibility
# is probably installed.
GUESS=$UNAME_MACHINE-pc-os2-emx
;;
i*86:XTS-300:*:STOP)
GUESS=$UNAME_MACHINE-unknown-stop
;;
i*86:atheos:*:*)
GUESS=$UNAME_MACHINE-unknown-atheos
;;
i*86:syllable:*:*)
GUESS=$UNAME_MACHINE-pc-syllable
;;
i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.[02]*:*)
GUESS=i386-unknown-lynxos$UNAME_RELEASE
;;
i*86:*DOS:*:*)
GUESS=$UNAME_MACHINE-pc-msdosdjgpp
;;
i*86:*:4.*:*)
UNAME_REL=`echo "$UNAME_RELEASE" | sed 's/\/MP$//'`
if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then
GUESS=$UNAME_MACHINE-univel-sysv$UNAME_REL
else
GUESS=$UNAME_MACHINE-pc-sysv$UNAME_REL
fi
;;
i*86:*:5:[678]*)
# UnixWare 7.x, OpenUNIX and OpenServer 6.
case `/bin/uname -X | grep "^Machine"` in
*486*) UNAME_MACHINE=i486 ;;
*Pentium) UNAME_MACHINE=i586 ;;
*Pent*|*Celeron) UNAME_MACHINE=i686 ;;
esac
GUESS=$UNAME_MACHINE-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION}
;;
i*86:*:3.2:*)
if test -f /usr/options/cb.name; then
UNAME_REL=`sed -n 's/.*Version //p' </usr/options/cb.name`
GUESS=$UNAME_MACHINE-pc-isc$UNAME_REL
elif /bin/uname -X 2>/dev/null >/dev/null ; then
UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')`
(/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486
(/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \
&& UNAME_MACHINE=i586
(/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \
&& UNAME_MACHINE=i686
(/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \
&& UNAME_MACHINE=i686
GUESS=$UNAME_MACHINE-pc-sco$UNAME_REL
else
GUESS=$UNAME_MACHINE-pc-sysv32
fi
;;
pc:*:*:*)
# Left here for compatibility:
# uname -m prints for DJGPP always 'pc', but it prints nothing about
# the processor, so we play safe by assuming i586.
# Note: whatever this is, it MUST be the same as what config.sub
# prints for the "djgpp" host, or else GDB configure will decide that
# this is a cross-build.
GUESS=i586-pc-msdosdjgpp
;;
Intel:Mach:3*:*)
GUESS=i386-pc-mach3
;;
paragon:*:*:*)
GUESS=i860-intel-osf1
;;
i860:*:4.*:*) # i860-SVR4
if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then
GUESS=i860-stardent-sysv$UNAME_RELEASE # Stardent Vistra i860-SVR4
else # Add other i860-SVR4 vendors below as they are discovered.
GUESS=i860-unknown-sysv$UNAME_RELEASE # Unknown i860-SVR4
fi
;;
mini*:CTIX:SYS*5:*)
# "miniframe"
GUESS=m68010-convergent-sysv
;;
mc68k:UNIX:SYSTEM5:3.51m)
GUESS=m68k-convergent-sysv
;;
M680?0:D-NIX:5.3:*)
GUESS=m68k-diab-dnix
;;
M68*:*:R3V[5678]*:*)
test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;;
3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0)
OS_REL=''
test -r /etc/.relid \
&& OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
|
| ︙ | ︙ | |||
1172 1173 1174 1175 1176 1177 1178 |
/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
&& { echo i486-ncr-sysv4.3"$OS_REL"; exit; }
/bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
&& { echo i586-ncr-sysv4.3"$OS_REL"; exit; }
/bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \
&& { echo i586-ncr-sysv4.3"$OS_REL"; exit; } ;;
m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*)
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > > > | < | | > > > > > > > > > < | | | | | | | | | | | | | | | | < | < < < < < | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > | | | | | | | | > | | | | | | | | | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | | > > > > > > > > | 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 |
/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
&& { echo i486-ncr-sysv4.3"$OS_REL"; exit; }
/bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
&& { echo i586-ncr-sysv4.3"$OS_REL"; exit; }
/bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \
&& { echo i586-ncr-sysv4.3"$OS_REL"; exit; } ;;
m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*)
GUESS=m68k-unknown-lynxos$UNAME_RELEASE
;;
mc68030:UNIX_System_V:4.*:*)
GUESS=m68k-atari-sysv4
;;
TSUNAMI:LynxOS:2.*:*)
GUESS=sparc-unknown-lynxos$UNAME_RELEASE
;;
rs6000:LynxOS:2.*:*)
GUESS=rs6000-unknown-lynxos$UNAME_RELEASE
;;
PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.[02]*:*)
GUESS=powerpc-unknown-lynxos$UNAME_RELEASE
;;
SM[BE]S:UNIX_SV:*:*)
GUESS=mips-dde-sysv$UNAME_RELEASE
;;
RM*:ReliantUNIX-*:*:*)
GUESS=mips-sni-sysv4
;;
RM*:SINIX-*:*:*)
GUESS=mips-sni-sysv4
;;
*:SINIX-*:*:*)
if uname -p 2>/dev/null >/dev/null ; then
UNAME_MACHINE=`(uname -p) 2>/dev/null`
GUESS=$UNAME_MACHINE-sni-sysv4
else
GUESS=ns32k-sni-sysv
fi
;;
PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort
# says <Richard.M.Bartel@ccMail.Census.GOV>
GUESS=i586-unisys-sysv4
;;
*:UNIX_System_V:4*:FTX*)
# From Gerald Hewes <hewes@openmarket.com>.
# How about differentiating between stratus architectures? -djm
GUESS=hppa1.1-stratus-sysv4
;;
*:*:*:FTX*)
# From seanf@swdc.stratus.com.
GUESS=i860-stratus-sysv4
;;
i*86:VOS:*:*)
# From Paul.Green@stratus.com.
GUESS=$UNAME_MACHINE-stratus-vos
;;
*:VOS:*:*)
# From Paul.Green@stratus.com.
GUESS=hppa1.1-stratus-vos
;;
mc68*:A/UX:*:*)
GUESS=m68k-apple-aux$UNAME_RELEASE
;;
news*:NEWS-OS:6*:*)
GUESS=mips-sony-newsos6
;;
R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*)
if test -d /usr/nec; then
GUESS=mips-nec-sysv$UNAME_RELEASE
else
GUESS=mips-unknown-sysv$UNAME_RELEASE
fi
;;
BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only.
GUESS=powerpc-be-beos
;;
BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only.
GUESS=powerpc-apple-beos
;;
BePC:BeOS:*:*) # BeOS running on Intel PC compatible.
GUESS=i586-pc-beos
;;
BePC:Haiku:*:*) # Haiku running on Intel PC compatible.
GUESS=i586-pc-haiku
;;
x86_64:Haiku:*:*)
GUESS=x86_64-unknown-haiku
;;
SX-4:SUPER-UX:*:*)
GUESS=sx4-nec-superux$UNAME_RELEASE
;;
SX-5:SUPER-UX:*:*)
GUESS=sx5-nec-superux$UNAME_RELEASE
;;
SX-6:SUPER-UX:*:*)
GUESS=sx6-nec-superux$UNAME_RELEASE
;;
SX-7:SUPER-UX:*:*)
GUESS=sx7-nec-superux$UNAME_RELEASE
;;
SX-8:SUPER-UX:*:*)
GUESS=sx8-nec-superux$UNAME_RELEASE
;;
SX-8R:SUPER-UX:*:*)
GUESS=sx8r-nec-superux$UNAME_RELEASE
;;
SX-ACE:SUPER-UX:*:*)
GUESS=sxace-nec-superux$UNAME_RELEASE
;;
Power*:Rhapsody:*:*)
GUESS=powerpc-apple-rhapsody$UNAME_RELEASE
;;
*:Rhapsody:*:*)
GUESS=$UNAME_MACHINE-apple-rhapsody$UNAME_RELEASE
;;
arm64:Darwin:*:*)
GUESS=aarch64-apple-darwin$UNAME_RELEASE
;;
*:Darwin:*:*)
UNAME_PROCESSOR=`uname -p`
case $UNAME_PROCESSOR in
unknown) UNAME_PROCESSOR=powerpc ;;
esac
if command -v xcode-select > /dev/null 2> /dev/null && \
! xcode-select --print-path > /dev/null 2> /dev/null ; then
# Avoid executing cc if there is no toolchain installed as
# cc will be a stub that puts up a graphical alert
# prompting the user to install developer tools.
CC_FOR_BUILD=no_compiler_found
else
set_cc_for_build
fi
if test "$CC_FOR_BUILD" != no_compiler_found; then
if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \
(CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \
grep IS_64BIT_ARCH >/dev/null
then
case $UNAME_PROCESSOR in
i386) UNAME_PROCESSOR=x86_64 ;;
powerpc) UNAME_PROCESSOR=powerpc64 ;;
esac
fi
# On 10.4-10.6 one might compile for PowerPC via gcc -arch ppc
if (echo '#ifdef __POWERPC__'; echo IS_PPC; echo '#endif') | \
(CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \
grep IS_PPC >/dev/null
then
UNAME_PROCESSOR=powerpc
fi
elif test "$UNAME_PROCESSOR" = i386 ; then
# uname -m returns i386 or x86_64
UNAME_PROCESSOR=$UNAME_MACHINE
fi
GUESS=$UNAME_PROCESSOR-apple-darwin$UNAME_RELEASE
;;
*:procnto*:*:* | *:QNX:[0123456789]*:*)
UNAME_PROCESSOR=`uname -p`
if test "$UNAME_PROCESSOR" = x86; then
UNAME_PROCESSOR=i386
UNAME_MACHINE=pc
fi
GUESS=$UNAME_PROCESSOR-$UNAME_MACHINE-nto-qnx$UNAME_RELEASE
;;
*:QNX:*:4*)
GUESS=i386-pc-qnx
;;
NEO-*:NONSTOP_KERNEL:*:*)
GUESS=neo-tandem-nsk$UNAME_RELEASE
;;
NSE-*:NONSTOP_KERNEL:*:*)
GUESS=nse-tandem-nsk$UNAME_RELEASE
;;
NSR-*:NONSTOP_KERNEL:*:*)
GUESS=nsr-tandem-nsk$UNAME_RELEASE
;;
NSV-*:NONSTOP_KERNEL:*:*)
GUESS=nsv-tandem-nsk$UNAME_RELEASE
;;
NSX-*:NONSTOP_KERNEL:*:*)
GUESS=nsx-tandem-nsk$UNAME_RELEASE
;;
*:NonStop-UX:*:*)
GUESS=mips-compaq-nonstopux
;;
BS2000:POSIX*:*:*)
GUESS=bs2000-siemens-sysv
;;
DS/*:UNIX_System_V:*:*)
GUESS=$UNAME_MACHINE-$UNAME_SYSTEM-$UNAME_RELEASE
;;
*:Plan9:*:*)
# "uname -m" is not consistent, so use $cputype instead. 386
# is converted to i386 for consistency with other x86
# operating systems.
if test "${cputype-}" = 386; then
UNAME_MACHINE=i386
elif test "x${cputype-}" != x; then
UNAME_MACHINE=$cputype
fi
GUESS=$UNAME_MACHINE-unknown-plan9
;;
*:TOPS-10:*:*)
GUESS=pdp10-unknown-tops10
;;
*:TENEX:*:*)
GUESS=pdp10-unknown-tenex
;;
KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*)
GUESS=pdp10-dec-tops20
;;
XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*)
GUESS=pdp10-xkl-tops20
;;
*:TOPS-20:*:*)
GUESS=pdp10-unknown-tops20
;;
*:ITS:*:*)
GUESS=pdp10-unknown-its
;;
SEI:*:*:SEIUX)
GUESS=mips-sei-seiux$UNAME_RELEASE
;;
*:DragonFly:*:*)
DRAGONFLY_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'`
GUESS=$UNAME_MACHINE-unknown-dragonfly$DRAGONFLY_REL
;;
*:*VMS:*:*)
UNAME_MACHINE=`(uname -p) 2>/dev/null`
case $UNAME_MACHINE in
A*) GUESS=alpha-dec-vms ;;
I*) GUESS=ia64-dec-vms ;;
V*) GUESS=vax-dec-vms ;;
esac ;;
*:XENIX:*:SysV)
GUESS=i386-pc-xenix
;;
i*86:skyos:*:*)
SKYOS_REL=`echo "$UNAME_RELEASE" | sed -e 's/ .*$//'`
GUESS=$UNAME_MACHINE-pc-skyos$SKYOS_REL
;;
i*86:rdos:*:*)
GUESS=$UNAME_MACHINE-pc-rdos
;;
*:AROS:*:*)
GUESS=$UNAME_MACHINE-unknown-aros
;;
x86_64:VMkernel:*:*)
GUESS=$UNAME_MACHINE-unknown-esx
;;
amd64:Isilon\ OneFS:*:*)
GUESS=x86_64-unknown-onefs
;;
*:Unleashed:*:*)
GUESS=$UNAME_MACHINE-unknown-unleashed$UNAME_RELEASE
;;
esac
# Do we have a guess based on uname results?
if test "x$GUESS" != x; then
echo "$GUESS"
exit
fi
# No uname command or uname output not recognized.
set_cc_for_build
cat > "$dummy.c" <<EOF
#ifdef _SEQUENT_
#include <sys/types.h>
#include <sys/utsname.h>
#endif
#if defined(ultrix) || defined(_ultrix) || defined(__ultrix) || defined(__ultrix__)
#if defined (vax) || defined (__vax) || defined (__vax__) || defined(mips) || defined(__mips) || defined(__mips__) || defined(MIPS) || defined(__MIPS__)
#include <signal.h>
#if defined(_SIZE_T_) || defined(SIGLOST)
#include <sys/utsname.h>
#endif
#endif
#endif
main ()
{
#if defined (sony)
#if defined (MIPSEB)
/* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed,
I don't know.... */
printf ("mips-sony-bsd\n"); exit (0);
#else
#include <sys/param.h>
printf ("m68k-sony-newsos%s\n",
#ifdef NEWSOS4
"4"
#else
""
#endif
); exit (0);
#endif
#endif
#if defined (NeXT)
#if !defined (__ARCHITECTURE__)
#define __ARCHITECTURE__ "m68k"
#endif
int version;
version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`;
if (version < 4)
printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version);
else
printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version);
exit (0);
#endif
#if defined (MULTIMAX) || defined (n16)
#if defined (UMAXV)
printf ("ns32k-encore-sysv\n"); exit (0);
#else
#if defined (CMU)
printf ("ns32k-encore-mach\n"); exit (0);
#else
printf ("ns32k-encore-bsd\n"); exit (0);
#endif
#endif
#endif
#if defined (__386BSD__)
printf ("i386-pc-bsd\n"); exit (0);
#endif
#if defined (sequent)
#if defined (i386)
printf ("i386-sequent-dynix\n"); exit (0);
#endif
#if defined (ns32000)
printf ("ns32k-sequent-dynix\n"); exit (0);
#endif
#endif
#if defined (_SEQUENT_)
struct utsname un;
uname(&un);
if (strncmp(un.version, "V2", 2) == 0) {
printf ("i386-sequent-ptx2\n"); exit (0);
}
if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */
printf ("i386-sequent-ptx1\n"); exit (0);
}
printf ("i386-sequent-ptx\n"); exit (0);
#endif
#if defined (vax)
#if !defined (ultrix)
#include <sys/param.h>
#if defined (BSD)
#if BSD == 43
printf ("vax-dec-bsd4.3\n"); exit (0);
#else
#if BSD == 199006
printf ("vax-dec-bsd4.3reno\n"); exit (0);
#else
printf ("vax-dec-bsd\n"); exit (0);
#endif
#endif
#else
printf ("vax-dec-bsd\n"); exit (0);
#endif
#else
#if defined(_SIZE_T_) || defined(SIGLOST)
struct utsname un;
uname (&un);
printf ("vax-dec-ultrix%s\n", un.release); exit (0);
#else
printf ("vax-dec-ultrix\n"); exit (0);
#endif
#endif
#endif
#if defined(ultrix) || defined(_ultrix) || defined(__ultrix) || defined(__ultrix__)
#if defined(mips) || defined(__mips) || defined(__mips__) || defined(MIPS) || defined(__MIPS__)
#if defined(_SIZE_T_) || defined(SIGLOST)
struct utsname *un;
uname (&un);
printf ("mips-dec-ultrix%s\n", un.release); exit (0);
#else
printf ("mips-dec-ultrix\n"); exit (0);
#endif
#endif
#endif
#if defined (alliant) && defined (i860)
printf ("i860-alliant-bsd\n"); exit (0);
#endif
exit (1);
}
EOF
$CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null && SYSTEM_NAME=`"$dummy"` &&
{ echo "$SYSTEM_NAME"; exit; }
# Apollos put the system type in the environment.
test -d /usr/apollo && { echo "$ISP-apollo-$SYSTYPE"; exit; }
echo "$0: unable to guess system type" >&2
case $UNAME_MACHINE:$UNAME_SYSTEM in
mips:Linux | mips64:Linux)
# If we got here on MIPS GNU/Linux, output extra information.
cat >&2 <<EOF
NOTE: MIPS GNU/Linux systems require a C compiler to fully recognize
the system type. Please install a C compiler and try again.
EOF
;;
esac
cat >&2 <<EOF
This script (version $timestamp), has failed to recognize the
operating system you are using. If your script is old, overwrite *all*
copies of config.guess and config.sub with the latest versions from:
https://git.savannah.gnu.org/cgit/config.git/plain/config.guess
and
https://git.savannah.gnu.org/cgit/config.git/plain/config.sub
EOF
our_year=`echo $timestamp | sed 's,-.*,,'`
thisyear=`date +%Y`
# shellcheck disable=SC2003
script_age=`expr "$thisyear" - "$our_year"`
if test "$script_age" -lt 3 ; then
cat >&2 <<EOF
If $0 has already been updated, send the following data and any
information you think might be pertinent to config-patches@gnu.org to
provide the necessary information to handle your system.
config.guess timestamp = $timestamp
|
| ︙ | ︙ | |||
1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 | /usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null` UNAME_MACHINE = "$UNAME_MACHINE" UNAME_RELEASE = "$UNAME_RELEASE" UNAME_SYSTEM = "$UNAME_SYSTEM" UNAME_VERSION = "$UNAME_VERSION" EOF exit 1 # Local variables: # eval: (add-hook 'before-save-hook 'time-stamp) # time-stamp-start: "timestamp='" # time-stamp-format: "%:y-%02m-%02d" # time-stamp-end: "'" # End: | > | 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 | /usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null` UNAME_MACHINE = "$UNAME_MACHINE" UNAME_RELEASE = "$UNAME_RELEASE" UNAME_SYSTEM = "$UNAME_SYSTEM" UNAME_VERSION = "$UNAME_VERSION" EOF fi exit 1 # Local variables: # eval: (add-hook 'before-save-hook 'time-stamp) # time-stamp-start: "timestamp='" # time-stamp-format: "%:y-%02m-%02d" # time-stamp-end: "'" # End: |
Changes to autosetup/autosetup-config.sub.
1 2 | #! /bin/sh # Configuration validation subroutine script. | | > > | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | #! /bin/sh # Configuration validation subroutine script. # Copyright 1992-2021 Free Software Foundation, Inc. # shellcheck disable=SC2006,SC2268 # see below for rationale timestamp='2021-07-03' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, but |
| ︙ | ︙ | |||
29 30 31 32 33 34 35 | # # Configuration subroutine to validate and canonicalize a configuration type. # Supply the specified configuration type as an argument. # If it is invalid, we print an error message on stderr and exit with code 1. # Otherwise, we print the canonical config type on stdout and succeed. # You can get the latest version of this script from: | | > > > > > > > | | 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | # # Configuration subroutine to validate and canonicalize a configuration type. # Supply the specified configuration type as an argument. # If it is invalid, we print an error message on stderr and exit with code 1. # Otherwise, we print the canonical config type on stdout and succeed. # You can get the latest version of this script from: # https://git.savannah.gnu.org/cgit/config.git/plain/config.sub # This file is supposed to be the same for all GNU packages # and recognize all the CPU types, system types and aliases # that are meaningful with *any* GNU software. # Each package is responsible for reporting which valid configurations # it does not support. The user should be able to distinguish # a failure to support a valid configuration from a meaningless # configuration. # The goal of this file is to map all the various variations of a given # machine specification into a single specification in the form: # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM # or in some cases, the newer four-part form: # CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM # It is wrong to echo any other type of specification. # The "shellcheck disable" line above the timestamp inhibits complaints # about features and limitations of the classic Bourne shell that were # superseded or lifted in POSIX. However, this script identifies a wide # variety of pre-POSIX systems that do not have POSIX shells at all, and # even some reasonably current systems (Solaris 10 as case-in-point) still # have a pre-POSIX /bin/sh. me=`echo "$0" | sed -e 's,.*/,,'` usage="\ Usage: $0 [OPTION] CPU-MFR-OPSYS or ALIAS Canonicalize a configuration name. Options: -h, --help print this help, then exit -t, --time-stamp print date of last modification, then exit -v, --version print version number, then exit Report bugs and patches to <config-patches@gnu.org>." version="\ GNU config.sub ($timestamp) Copyright 1992-2021 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." help=" Try \`$me --help' for more information." |
| ︙ | ︙ | |||
85 86 87 88 89 90 91 |
--help | --h* | -h )
echo "$usage"; exit ;;
-- ) # Stop option processing
shift; break ;;
- ) # Use stdin as input.
break ;;
-* )
| | > > > > > | > > > > > > > > > > > | > | | | < | | | > | < | | > | > > > > > > > > > > > > > > > > > > > | > | > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > | | > > > | | > | | > > | < < | > > > > > > > | > | < > > | < < < < < < > | | > > | > | > > > > | > > > > > | | > > > > > > > > > > > > > > > > > > > > | > | > > | > | > > > > | > > | | > > > > > > > > > > > > > | > > | > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > | > > | > | | > | > > > > > > | > | > > > > | > | > > > > | > > > > > > > > > > | > > > > > > > > > | | > | | > | > > | > | | > | > > | > | > > > > > > > > > | > > > > > > > > | > > > > > > > > > > | > | > > > > > | < > > > | > | > > > > | < | > | > > > > | > > > > > | > > > > > > > > > > | > | > > > > > > | > > | > | > > > > | > > > > > | > > | > | > > | > > | > | > > > > | | > | > > > > > > > > | > | | | > > > > > > > > > > > > > | | > > > > > > | > > > > > > > > > > > > > > > | | > > > > > > > > > > > > | | > | > > | > > > | | > > > > > > > > > > > > > > > > > > > > | | | | | > > | | | < | > | < > | > > > > > > > | > > > > > > > | < > > > | > > > | > > > > > > > | | > > | > > > | > > > > | > | < > > > > > > > | < < | > > > | | < | > | | | | > > > > > > > | > | > > > > | > > > | < | > > > > > > > > > > > > > > | > > > > > > > > > | > > > | > > > | > > | > > > > | > > > > > > > > > > > | > > > > | < | > > > > > > > > > | | > > | > > > > > > > > > | | | | < | > > > > > > > > > > > | < | < < > > | > > > > | | | | > > | > > > | < > > | < | | < > > > > > > > > > > > > > > > > > | > > > > > > | > | > | > | > > | > > | > > > > > > | > > > > | < < | < < < > | | < < < < < | < | < < | < | > < | > | < < > | > | > > > > > | | < < < < < < < | < < < < < < < < < > > | < < < < < < | | | | | | | | | | > | < | | < < < < < < < < < < < < > | < < < | > > | < > | < | > | | > | < < < < < | < < < < < > | < < > > > > > | < | < < < < | > < < < | | | | < > > | | | < < < | < | < < < | < < < < < < | < | < < > | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | | < < < < | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | < < < < < < < < < < < < < < < < < < | < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | < < | | < < | < < < < < < < < < < < | | | < | | < | | > | > | < < < > | < > | < < < | < < < | | | | | | < | | | < < < < < < > | < | < < < | < < < < < | | < < < | > | < | < > | < < < | > | | > | > | < < > < < | > < | | | < < < < | | | < < < > | | < | | < | < < < < | < < < < < < | > | > | > | > | | < < < < < | < < < < < < | < < < | < < < < < < | < < < < < < | < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | < < > > | < < < | > > > | | < > > > | < < | | < > | | < < > > > > | > > | > | < < < < > | < < < < | < | < < | > > | < > > > > | > > > > | | < > | > > > | | < > | | | < > | | | < < < < < < < < < < < < < | < < < < < | < < < < < < | < < < < < < < < < > < < | < < < | < < | < < < < < < | < < | < | < < < > | < | < < < | < | < < | < < > > > | < < < < < < < > | | < | > | | < > | | | < > | | | < < | < < > | | < < > | | < | < < | < < | < < < < < < < | < < < < | < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | | | > > | | | | | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | | > > > | | | | | | < < < | | < < | < > > > | | < > | | < > | | < > | | < > | | < < < < > | < < > > | | > | < | < < < | < < > | | | | > | | > | < > > | < < | | | | | | | < < < < < < | | | | | | | | | | | | | | | | | | | | < < < | | | | | | | | | | | | < < < | | | | | | | | < < < | | | | | | < < < < < < < < < < > > > | | | | | > | | | > > > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | < | | | | | | | | | | | | | > > > | | > > > | | | | | | | | < | | 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 |
--help | --h* | -h )
echo "$usage"; exit ;;
-- ) # Stop option processing
shift; break ;;
- ) # Use stdin as input.
break ;;
-* )
echo "$me: invalid option $1$help" >&2
exit 1 ;;
*local*)
# First pass through any local machine types.
echo "$1"
exit ;;
* )
break ;;
esac
done
case $# in
0) echo "$me: missing argument$help" >&2
exit 1;;
1) ;;
*) echo "$me: too many arguments$help" >&2
exit 1;;
esac
# Split fields of configuration type
# shellcheck disable=SC2162
IFS="-" read field1 field2 field3 field4 <<EOF
$1
EOF
# Separate into logical components for further validation
case $1 in
*-*-*-*-*)
echo Invalid configuration \`"$1"\': more than four components >&2
exit 1
;;
*-*-*-*)
basic_machine=$field1-$field2
basic_os=$field3-$field4
;;
*-*-*)
# Ambiguous whether COMPANY is present, or skipped and KERNEL-OS is two
# parts
maybe_os=$field2-$field3
case $maybe_os in
nto-qnx* | linux-* | uclinux-uclibc* \
| uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* \
| netbsd*-eabi* | kopensolaris*-gnu* | cloudabi*-eabi* \
| storm-chaos* | os2-emx* | rtmk-nova*)
basic_machine=$field1
basic_os=$maybe_os
;;
android-linux)
basic_machine=$field1-unknown
basic_os=linux-android
;;
*)
basic_machine=$field1-$field2
basic_os=$field3
;;
esac
;;
*-*)
# A lone config we happen to match not fitting any pattern
case $field1-$field2 in
decstation-3100)
basic_machine=mips-dec
basic_os=
;;
*-*)
# Second component is usually, but not always the OS
case $field2 in
# Prevent following clause from handling this valid os
sun*os*)
basic_machine=$field1
basic_os=$field2
;;
# Manufacturers
dec* | mips* | sequent* | encore* | pc533* | sgi* | sony* \
| att* | 7300* | 3300* | delta* | motorola* | sun[234]* \
| unicom* | ibm* | next | hp | isi* | apollo | altos* \
| convergent* | ncr* | news | 32* | 3600* | 3100* \
| hitachi* | c[123]* | convex* | sun | crds | omron* | dg \
| ultra | tti* | harris | dolphin | highlevel | gould \
| cbm | ns | masscomp | apple | axis | knuth | cray \
| microblaze* | sim | cisco \
| oki | wec | wrs | winbond)
basic_machine=$field1-$field2
basic_os=
;;
*)
basic_machine=$field1
basic_os=$field2
;;
esac
;;
esac
;;
*)
# Convert single-component short-hands not valid as part of
# multi-component configurations.
case $field1 in
386bsd)
basic_machine=i386-pc
basic_os=bsd
;;
a29khif)
basic_machine=a29k-amd
basic_os=udi
;;
adobe68k)
basic_machine=m68010-adobe
basic_os=scout
;;
alliant)
basic_machine=fx80-alliant
basic_os=
;;
altos | altos3068)
basic_machine=m68k-altos
basic_os=
;;
am29k)
basic_machine=a29k-none
basic_os=bsd
;;
amdahl)
basic_machine=580-amdahl
basic_os=sysv
;;
amiga)
basic_machine=m68k-unknown
basic_os=
;;
amigaos | amigados)
basic_machine=m68k-unknown
basic_os=amigaos
;;
amigaunix | amix)
basic_machine=m68k-unknown
basic_os=sysv4
;;
apollo68)
basic_machine=m68k-apollo
basic_os=sysv
;;
apollo68bsd)
basic_machine=m68k-apollo
basic_os=bsd
;;
aros)
basic_machine=i386-pc
basic_os=aros
;;
aux)
basic_machine=m68k-apple
basic_os=aux
;;
balance)
basic_machine=ns32k-sequent
basic_os=dynix
;;
blackfin)
basic_machine=bfin-unknown
basic_os=linux
;;
cegcc)
basic_machine=arm-unknown
basic_os=cegcc
;;
convex-c1)
basic_machine=c1-convex
basic_os=bsd
;;
convex-c2)
basic_machine=c2-convex
basic_os=bsd
;;
convex-c32)
basic_machine=c32-convex
basic_os=bsd
;;
convex-c34)
basic_machine=c34-convex
basic_os=bsd
;;
convex-c38)
basic_machine=c38-convex
basic_os=bsd
;;
cray)
basic_machine=j90-cray
basic_os=unicos
;;
crds | unos)
basic_machine=m68k-crds
basic_os=
;;
da30)
basic_machine=m68k-da30
basic_os=
;;
decstation | pmax | pmin | dec3100 | decstatn)
basic_machine=mips-dec
basic_os=
;;
delta88)
basic_machine=m88k-motorola
basic_os=sysv3
;;
dicos)
basic_machine=i686-pc
basic_os=dicos
;;
djgpp)
basic_machine=i586-pc
basic_os=msdosdjgpp
;;
ebmon29k)
basic_machine=a29k-amd
basic_os=ebmon
;;
es1800 | OSE68k | ose68k | ose | OSE)
basic_machine=m68k-ericsson
basic_os=ose
;;
gmicro)
basic_machine=tron-gmicro
basic_os=sysv
;;
go32)
basic_machine=i386-pc
basic_os=go32
;;
h8300hms)
basic_machine=h8300-hitachi
basic_os=hms
;;
h8300xray)
basic_machine=h8300-hitachi
basic_os=xray
;;
h8500hms)
basic_machine=h8500-hitachi
basic_os=hms
;;
harris)
basic_machine=m88k-harris
basic_os=sysv3
;;
hp300 | hp300hpux)
basic_machine=m68k-hp
basic_os=hpux
;;
hp300bsd)
basic_machine=m68k-hp
basic_os=bsd
;;
hppaosf)
basic_machine=hppa1.1-hp
basic_os=osf
;;
hppro)
basic_machine=hppa1.1-hp
basic_os=proelf
;;
i386mach)
basic_machine=i386-mach
basic_os=mach
;;
isi68 | isi)
basic_machine=m68k-isi
basic_os=sysv
;;
m68knommu)
basic_machine=m68k-unknown
basic_os=linux
;;
magnum | m3230)
basic_machine=mips-mips
basic_os=sysv
;;
merlin)
basic_machine=ns32k-utek
basic_os=sysv
;;
mingw64)
basic_machine=x86_64-pc
basic_os=mingw64
;;
mingw32)
basic_machine=i686-pc
basic_os=mingw32
;;
mingw32ce)
basic_machine=arm-unknown
basic_os=mingw32ce
;;
monitor)
basic_machine=m68k-rom68k
basic_os=coff
;;
morphos)
basic_machine=powerpc-unknown
basic_os=morphos
;;
moxiebox)
basic_machine=moxie-unknown
basic_os=moxiebox
;;
msdos)
basic_machine=i386-pc
basic_os=msdos
;;
msys)
basic_machine=i686-pc
basic_os=msys
;;
mvs)
basic_machine=i370-ibm
basic_os=mvs
;;
nacl)
basic_machine=le32-unknown
basic_os=nacl
;;
ncr3000)
basic_machine=i486-ncr
basic_os=sysv4
;;
netbsd386)
basic_machine=i386-pc
basic_os=netbsd
;;
netwinder)
basic_machine=armv4l-rebel
basic_os=linux
;;
news | news700 | news800 | news900)
basic_machine=m68k-sony
basic_os=newsos
;;
news1000)
basic_machine=m68030-sony
basic_os=newsos
;;
necv70)
basic_machine=v70-nec
basic_os=sysv
;;
nh3000)
basic_machine=m68k-harris
basic_os=cxux
;;
nh[45]000)
basic_machine=m88k-harris
basic_os=cxux
;;
nindy960)
basic_machine=i960-intel
basic_os=nindy
;;
mon960)
basic_machine=i960-intel
basic_os=mon960
;;
nonstopux)
basic_machine=mips-compaq
basic_os=nonstopux
;;
os400)
basic_machine=powerpc-ibm
basic_os=os400
;;
OSE68000 | ose68000)
basic_machine=m68000-ericsson
basic_os=ose
;;
os68k)
basic_machine=m68k-none
basic_os=os68k
;;
paragon)
basic_machine=i860-intel
basic_os=osf
;;
parisc)
basic_machine=hppa-unknown
basic_os=linux
;;
psp)
basic_machine=mipsallegrexel-sony
basic_os=psp
;;
pw32)
basic_machine=i586-unknown
basic_os=pw32
;;
rdos | rdos64)
basic_machine=x86_64-pc
basic_os=rdos
;;
rdos32)
basic_machine=i386-pc
basic_os=rdos
;;
rom68k)
basic_machine=m68k-rom68k
basic_os=coff
;;
sa29200)
basic_machine=a29k-amd
basic_os=udi
;;
sei)
basic_machine=mips-sei
basic_os=seiux
;;
sequent)
basic_machine=i386-sequent
basic_os=
;;
sps7)
basic_machine=m68k-bull
basic_os=sysv2
;;
st2000)
basic_machine=m68k-tandem
basic_os=
;;
stratus)
basic_machine=i860-stratus
basic_os=sysv4
;;
sun2)
basic_machine=m68000-sun
basic_os=
;;
sun2os3)
basic_machine=m68000-sun
basic_os=sunos3
;;
sun2os4)
basic_machine=m68000-sun
basic_os=sunos4
;;
sun3)
basic_machine=m68k-sun
basic_os=
;;
sun3os3)
basic_machine=m68k-sun
basic_os=sunos3
;;
sun3os4)
basic_machine=m68k-sun
basic_os=sunos4
;;
sun4)
basic_machine=sparc-sun
basic_os=
;;
sun4os3)
basic_machine=sparc-sun
basic_os=sunos3
;;
sun4os4)
basic_machine=sparc-sun
basic_os=sunos4
;;
sun4sol2)
basic_machine=sparc-sun
basic_os=solaris2
;;
sun386 | sun386i | roadrunner)
basic_machine=i386-sun
basic_os=
;;
sv1)
basic_machine=sv1-cray
basic_os=unicos
;;
symmetry)
basic_machine=i386-sequent
basic_os=dynix
;;
t3e)
basic_machine=alphaev5-cray
basic_os=unicos
;;
t90)
basic_machine=t90-cray
basic_os=unicos
;;
toad1)
basic_machine=pdp10-xkl
basic_os=tops20
;;
tpf)
basic_machine=s390x-ibm
basic_os=tpf
;;
udi29k)
basic_machine=a29k-amd
basic_os=udi
;;
ultra3)
basic_machine=a29k-nyu
basic_os=sym1
;;
v810 | necv810)
basic_machine=v810-nec
basic_os=none
;;
vaxv)
basic_machine=vax-dec
basic_os=sysv
;;
vms)
basic_machine=vax-dec
basic_os=vms
;;
vsta)
basic_machine=i386-pc
basic_os=vsta
;;
vxworks960)
basic_machine=i960-wrs
basic_os=vxworks
;;
vxworks68)
basic_machine=m68k-wrs
basic_os=vxworks
;;
vxworks29k)
basic_machine=a29k-wrs
basic_os=vxworks
;;
xbox)
basic_machine=i686-pc
basic_os=mingw32
;;
ymp)
basic_machine=ymp-cray
basic_os=unicos
;;
*)
basic_machine=$1
basic_os=
;;
esac
;;
esac
# Decode 1-component or ad-hoc basic machines
case $basic_machine in
# Here we handle the default manufacturer of certain CPU types. It is in
# some cases the only manufacturer, in others, it is the most popular.
w89k)
cpu=hppa1.1
vendor=winbond
;;
op50n)
cpu=hppa1.1
vendor=oki
;;
op60c)
cpu=hppa1.1
vendor=oki
;;
ibm*)
cpu=i370
vendor=ibm
;;
orion105)
cpu=clipper
vendor=highlevel
;;
mac | mpw | mac-mpw)
cpu=m68k
vendor=apple
;;
pmac | pmac-mpw)
cpu=powerpc
vendor=apple
;;
# Recognize the various machine names and aliases which stand
# for a CPU type and a company and sometimes even an OS.
3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc)
cpu=m68000
vendor=att
;;
3b*)
cpu=we32k
vendor=att
;;
bluegene*)
cpu=powerpc
vendor=ibm
basic_os=cnk
;;
decsystem10* | dec10*)
cpu=pdp10
vendor=dec
basic_os=tops10
;;
decsystem20* | dec20*)
cpu=pdp10
vendor=dec
basic_os=tops20
;;
delta | 3300 | motorola-3300 | motorola-delta \
| 3300-motorola | delta-motorola)
cpu=m68k
vendor=motorola
;;
dpx2*)
cpu=m68k
vendor=bull
basic_os=sysv3
;;
encore | umax | mmax)
cpu=ns32k
vendor=encore
;;
elxsi)
cpu=elxsi
vendor=elxsi
basic_os=${basic_os:-bsd}
;;
fx2800)
cpu=i860
vendor=alliant
;;
genix)
cpu=ns32k
vendor=ns
;;
h3050r* | hiux*)
cpu=hppa1.1
vendor=hitachi
basic_os=hiuxwe2
;;
hp3k9[0-9][0-9] | hp9[0-9][0-9])
cpu=hppa1.0
vendor=hp
;;
hp9k2[0-9][0-9] | hp9k31[0-9])
cpu=m68000
vendor=hp
;;
hp9k3[2-9][0-9])
cpu=m68k
vendor=hp
;;
hp9k6[0-9][0-9] | hp6[0-9][0-9])
cpu=hppa1.0
vendor=hp
;;
hp9k7[0-79][0-9] | hp7[0-79][0-9])
cpu=hppa1.1
vendor=hp
;;
hp9k78[0-9] | hp78[0-9])
# FIXME: really hppa2.0-hp
cpu=hppa1.1
vendor=hp
;;
hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893)
# FIXME: really hppa2.0-hp
cpu=hppa1.1
vendor=hp
;;
hp9k8[0-9][13679] | hp8[0-9][13679])
cpu=hppa1.1
vendor=hp
;;
hp9k8[0-9][0-9] | hp8[0-9][0-9])
cpu=hppa1.0
vendor=hp
;;
i*86v32)
cpu=`echo "$1" | sed -e 's/86.*/86/'`
vendor=pc
basic_os=sysv32
;;
i*86v4*)
cpu=`echo "$1" | sed -e 's/86.*/86/'`
vendor=pc
basic_os=sysv4
;;
i*86v)
cpu=`echo "$1" | sed -e 's/86.*/86/'`
vendor=pc
basic_os=sysv
;;
i*86sol2)
cpu=`echo "$1" | sed -e 's/86.*/86/'`
vendor=pc
basic_os=solaris2
;;
j90 | j90-cray)
cpu=j90
vendor=cray
basic_os=${basic_os:-unicos}
;;
iris | iris4d)
cpu=mips
vendor=sgi
case $basic_os in
irix*)
;;
*)
basic_os=irix4
;;
esac
;;
miniframe)
cpu=m68000
vendor=convergent
;;
*mint | mint[0-9]* | *MiNT | *MiNT[0-9]*)
cpu=m68k
vendor=atari
basic_os=mint
;;
news-3600 | risc-news)
cpu=mips
vendor=sony
basic_os=newsos
;;
next | m*-next)
cpu=m68k
vendor=next
case $basic_os in
openstep*)
;;
nextstep*)
;;
ns2*)
basic_os=nextstep2
;;
*)
basic_os=nextstep3
;;
esac
;;
np1)
cpu=np1
vendor=gould
;;
op50n-* | op60c-*)
cpu=hppa1.1
vendor=oki
basic_os=proelf
;;
pa-hitachi)
cpu=hppa1.1
vendor=hitachi
basic_os=hiuxwe2
;;
pbd)
cpu=sparc
vendor=tti
;;
pbb)
cpu=m68k
vendor=tti
;;
pc532)
cpu=ns32k
vendor=pc532
;;
pn)
cpu=pn
vendor=gould
;;
power)
cpu=power
vendor=ibm
;;
ps2)
cpu=i386
vendor=ibm
;;
rm[46]00)
cpu=mips
vendor=siemens
;;
rtpc | rtpc-*)
cpu=romp
vendor=ibm
;;
sde)
cpu=mipsisa32
vendor=sde
basic_os=${basic_os:-elf}
;;
simso-wrs)
cpu=sparclite
vendor=wrs
basic_os=vxworks
;;
tower | tower-32)
cpu=m68k
vendor=ncr
;;
vpp*|vx|vx-*)
cpu=f301
vendor=fujitsu
;;
w65)
cpu=w65
vendor=wdc
;;
w89k-*)
cpu=hppa1.1
vendor=winbond
basic_os=proelf
;;
none)
cpu=none
vendor=none
;;
leon|leon[3-9])
cpu=sparc
vendor=$basic_machine
;;
leon-*|leon[3-9]-*)
cpu=sparc
vendor=`echo "$basic_machine" | sed 's/-.*//'`
;;
*-*)
# shellcheck disable=SC2162
IFS="-" read cpu vendor <<EOF
$basic_machine
EOF
;;
# We use `pc' rather than `unknown'
# because (1) that's what they normally are, and
# (2) the word "unknown" tends to confuse beginning users.
i*86 | x86_64)
cpu=$basic_machine
vendor=pc
;;
# These rules are duplicated from below for sake of the special case above;
# i.e. things that normalized to x86 arches should also default to "pc"
pc98)
cpu=i386
vendor=pc
;;
x64 | amd64)
cpu=x86_64
vendor=pc
;;
# Recognize the basic CPU types without company name.
*)
cpu=$basic_machine
vendor=unknown
;;
esac
unset -v basic_machine
# Decode basic machines in the full and proper CPU-Company form.
case $cpu-$vendor in
# Here we handle the default manufacturer of certain CPU types in canonical form. It is in
# some cases the only manufacturer, in others, it is the most popular.
craynv-unknown)
vendor=cray
basic_os=${basic_os:-unicosmp}
;;
c90-unknown | c90-cray)
vendor=cray
basic_os=${Basic_os:-unicos}
;;
fx80-unknown)
vendor=alliant
;;
romp-unknown)
vendor=ibm
;;
mmix-unknown)
vendor=knuth
;;
microblaze-unknown | microblazeel-unknown)
vendor=xilinx
;;
rs6000-unknown)
vendor=ibm
;;
vax-unknown)
vendor=dec
;;
pdp11-unknown)
vendor=dec
;;
we32k-unknown)
vendor=att
;;
cydra-unknown)
vendor=cydrome
;;
i370-ibm*)
vendor=ibm
;;
orion-unknown)
vendor=highlevel
;;
xps-unknown | xps100-unknown)
cpu=xps100
vendor=honeywell
;;
# Here we normalize CPU types with a missing or matching vendor
dpx20-unknown | dpx20-bull)
cpu=rs6000
vendor=bull
basic_os=${basic_os:-bosx}
;;
# Here we normalize CPU types irrespective of the vendor
amd64-*)
cpu=x86_64
;;
blackfin-*)
cpu=bfin
basic_os=linux
;;
c54x-*)
cpu=tic54x
;;
c55x-*)
cpu=tic55x
;;
c6x-*)
cpu=tic6x
;;
e500v[12]-*)
cpu=powerpc
basic_os=${basic_os}"spe"
;;
mips3*-*)
cpu=mips64
;;
ms1-*)
cpu=mt
;;
m68knommu-*)
cpu=m68k
basic_os=linux
;;
m9s12z-* | m68hcs12z-* | hcs12z-* | s12z-*)
cpu=s12z
;;
openrisc-*)
cpu=or32
;;
parisc-*)
cpu=hppa
basic_os=linux
;;
pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*)
cpu=i586
;;
pentiumpro-* | p6-* | 6x86-* | athlon-* | athalon_*-*)
cpu=i686
;;
pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*)
cpu=i686
;;
pentium4-*)
cpu=i786
;;
pc98-*)
cpu=i386
;;
ppc-* | ppcbe-*)
cpu=powerpc
;;
ppcle-* | powerpclittle-*)
cpu=powerpcle
;;
ppc64-*)
cpu=powerpc64
;;
ppc64le-* | powerpc64little-*)
cpu=powerpc64le
;;
sb1-*)
cpu=mipsisa64sb1
;;
sb1el-*)
cpu=mipsisa64sb1el
;;
sh5e[lb]-*)
cpu=`echo "$cpu" | sed 's/^\(sh.\)e\(.\)$/\1\2e/'`
;;
spur-*)
cpu=spur
;;
strongarm-* | thumb-*)
cpu=arm
;;
tx39-*)
cpu=mipstx39
;;
tx39el-*)
cpu=mipstx39el
;;
x64-*)
cpu=x86_64
;;
xscale-* | xscalee[bl]-*)
cpu=`echo "$cpu" | sed 's/^xscale/arm/'`
;;
arm64-*)
cpu=aarch64
;;
# Recognize the canonical CPU Types that limit and/or modify the
# company names they are paired with.
cr16-*)
basic_os=${basic_os:-elf}
;;
crisv32-* | etraxfs*-*)
cpu=crisv32
vendor=axis
;;
cris-* | etrax*-*)
cpu=cris
vendor=axis
;;
crx-*)
basic_os=${basic_os:-elf}
;;
neo-tandem)
cpu=neo
vendor=tandem
;;
nse-tandem)
cpu=nse
vendor=tandem
;;
nsr-tandem)
cpu=nsr
vendor=tandem
;;
nsv-tandem)
cpu=nsv
vendor=tandem
;;
nsx-tandem)
cpu=nsx
vendor=tandem
;;
mipsallegrexel-sony)
cpu=mipsallegrexel
vendor=sony
;;
tile*-*)
basic_os=${basic_os:-linux-gnu}
;;
*)
# Recognize the canonical CPU types that are allowed with any
# company name.
case $cpu in
1750a | 580 \
| a29k \
| aarch64 | aarch64_be \
| abacus \
| alpha | alphaev[4-8] | alphaev56 | alphaev6[78] \
| alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] \
| alphapca5[67] | alpha64pca5[67] \
| am33_2.0 \
| amdgcn \
| arc | arceb | arc32 | arc64 \
| arm | arm[lb]e | arme[lb] | armv* \
| avr | avr32 \
| asmjs \
| ba \
| be32 | be64 \
| bfin | bpf | bs2000 \
| c[123]* | c30 | [cjt]90 | c4x \
| c8051 | clipper | craynv | csky | cydra \
| d10v | d30v | dlx | dsp16xx \
| e2k | elxsi | epiphany \
| f30[01] | f700 | fido | fr30 | frv | ft32 | fx80 \
| h8300 | h8500 \
| hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
| hexagon \
| i370 | i*86 | i860 | i960 | ia16 | ia64 \
| ip2k | iq2000 \
| k1om \
| le32 | le64 \
| lm32 \
| loongarch32 | loongarch64 | loongarchx32 \
| m32c | m32r | m32rle \
| m5200 | m68000 | m680[012346]0 | m68360 | m683?2 | m68k \
| m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x \
| m88110 | m88k | maxq | mb | mcore | mep | metag \
| microblaze | microblazeel \
| mips | mipsbe | mipseb | mipsel | mipsle \
| mips16 \
| mips64 | mips64eb | mips64el \
| mips64octeon | mips64octeonel \
| mips64orion | mips64orionel \
| mips64r5900 | mips64r5900el \
| mips64vr | mips64vrel \
| mips64vr4100 | mips64vr4100el \
| mips64vr4300 | mips64vr4300el \
| mips64vr5000 | mips64vr5000el \
| mips64vr5900 | mips64vr5900el \
| mipsisa32 | mipsisa32el \
| mipsisa32r2 | mipsisa32r2el \
| mipsisa32r3 | mipsisa32r3el \
| mipsisa32r5 | mipsisa32r5el \
| mipsisa32r6 | mipsisa32r6el \
| mipsisa64 | mipsisa64el \
| mipsisa64r2 | mipsisa64r2el \
| mipsisa64r3 | mipsisa64r3el \
| mipsisa64r5 | mipsisa64r5el \
| mipsisa64r6 | mipsisa64r6el \
| mipsisa64sb1 | mipsisa64sb1el \
| mipsisa64sr71k | mipsisa64sr71kel \
| mipsr5900 | mipsr5900el \
| mipstx39 | mipstx39el \
| mmix \
| mn10200 | mn10300 \
| moxie \
| mt \
| msp430 \
| nds32 | nds32le | nds32be \
| nfp \
| nios | nios2 | nios2eb | nios2el \
| none | np1 | ns16k | ns32k | nvptx \
| open8 \
| or1k* \
| or32 \
| orion \
| picochip \
| pdp10 | pdp11 | pj | pjl | pn | power \
| powerpc | powerpc64 | powerpc64le | powerpcle | powerpcspe \
| pru \
| pyramid \
| riscv | riscv32 | riscv32be | riscv64 | riscv64be \
| rl78 | romp | rs6000 | rx \
| s390 | s390x \
| score \
| sh | shl \
| sh[1234] | sh[24]a | sh[24]ae[lb] | sh[23]e | she[lb] | sh[lb]e \
| sh[1234]e[lb] | sh[12345][lb]e | sh[23]ele | sh64 | sh64le \
| sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet \
| sparclite \
| sparcv8 | sparcv9 | sparcv9b | sparcv9v | sv1 | sx* \
| spu \
| tahoe \
| thumbv7* \
| tic30 | tic4x | tic54x | tic55x | tic6x | tic80 \
| tron \
| ubicom32 \
| v70 | v850 | v850e | v850e1 | v850es | v850e2 | v850e2v3 \
| vax \
| visium \
| w65 \
| wasm32 | wasm64 \
| we32k \
| x86 | x86_64 | xc16x | xgate | xps100 \
| xstormy16 | xtensa* \
| ymp \
| z8k | z80)
;;
*)
echo Invalid configuration \`"$1"\': machine \`"$cpu-$vendor"\' not recognized 1>&2
exit 1
;;
esac
;;
esac
# Here we canonicalize certain aliases for manufacturers.
case $vendor in
digital*)
vendor=dec
;;
commodore*)
vendor=cbm
;;
*)
;;
esac
# Decode manufacturer-specific aliases for certain operating systems.
if test x$basic_os != x
then
# First recognize some ad-hoc caes, or perhaps split kernel-os, or else just
# set os.
case $basic_os in
gnu/linux*)
kernel=linux
os=`echo "$basic_os" | sed -e 's|gnu/linux|gnu|'`
;;
os2-emx)
kernel=os2
os=`echo "$basic_os" | sed -e 's|os2-emx|emx|'`
;;
nto-qnx*)
kernel=nto
os=`echo "$basic_os" | sed -e 's|nto-qnx|qnx|'`
;;
*-*)
# shellcheck disable=SC2162
IFS="-" read kernel os <<EOF
$basic_os
EOF
;;
# Default OS when just kernel was specified
nto*)
kernel=nto
os=`echo "$basic_os" | sed -e 's|nto|qnx|'`
;;
linux*)
kernel=linux
os=`echo "$basic_os" | sed -e 's|linux|gnu|'`
;;
*)
kernel=
os=$basic_os
;;
esac
# Now, normalize the OS (knowing we just have one component, it's not a kernel,
# etc.)
case $os in
# First match some system type aliases that might get confused
# with valid system types.
# solaris* is a basic system type, with this one exception.
auroraux)
os=auroraux
;;
bluegene*)
os=cnk
;;
solaris1 | solaris1.*)
os=`echo "$os" | sed -e 's|solaris1|sunos4|'`
;;
solaris)
os=solaris2
;;
unixware*)
os=sysv4.2uw
;;
# es1800 is here to avoid being matched by es* (a different OS)
es1800*)
os=ose
;;
# Some version numbers need modification
chorusos*)
os=chorusos
;;
isc)
os=isc2.2
;;
sco6)
os=sco5v6
;;
sco5)
os=sco3.2v5
;;
sco4)
os=sco3.2v4
;;
sco3.2.[4-9]*)
os=`echo "$os" | sed -e 's/sco3.2./sco3.2v/'`
;;
sco*v* | scout)
# Don't match below
;;
sco*)
os=sco3.2v2
;;
psos*)
os=psos
;;
qnx*)
os=qnx
;;
hiux*)
os=hiuxwe2
;;
lynx*178)
os=lynxos178
;;
lynx*5)
os=lynxos5
;;
lynxos*)
# don't get caught up in next wildcard
;;
lynx*)
os=lynxos
;;
mac[0-9]*)
os=`echo "$os" | sed -e 's|mac|macos|'`
;;
opened*)
os=openedition
;;
os400*)
os=os400
;;
sunos5*)
os=`echo "$os" | sed -e 's|sunos5|solaris2|'`
;;
sunos6*)
os=`echo "$os" | sed -e 's|sunos6|solaris3|'`
;;
wince*)
os=wince
;;
utek*)
os=bsd
;;
dynix*)
os=bsd
;;
acis*)
os=aos
;;
atheos*)
os=atheos
;;
syllable*)
os=syllable
;;
386bsd)
os=bsd
;;
ctix* | uts*)
os=sysv
;;
nova*)
os=rtmk-nova
;;
ns2)
os=nextstep2
;;
# Preserve the version number of sinix5.
sinix5.*)
os=`echo "$os" | sed -e 's|sinix|sysv|'`
;;
sinix*)
os=sysv4
;;
tpf*)
os=tpf
;;
triton*)
os=sysv3
;;
oss*)
os=sysv3
;;
svr4*)
os=sysv4
;;
svr3)
os=sysv3
;;
sysvr4)
os=sysv4
;;
ose*)
os=ose
;;
*mint | mint[0-9]* | *MiNT | MiNT[0-9]*)
os=mint
;;
dicos*)
os=dicos
;;
pikeos*)
# Until real need of OS specific support for
# particular features comes up, bare metal
# configurations are quite functional.
case $cpu in
arm*)
os=eabi
;;
*)
os=elf
;;
esac
;;
*)
# No normalization, but not necessarily accepted, that comes below.
;;
esac
else
# Here we handle the default operating systems that come with various machines.
# The value should be what the vendor currently ships out the door with their
# machine or put another way, the most popular os provided with the machine.
# Note that if you're going to try to match "-MANUFACTURER" here (say,
# "-sun"), then you have to tell the case statement up towards the top
# that MANUFACTURER isn't an operating system. Otherwise, code above
# will signal an error saying that MANUFACTURER isn't an operating
# system, and we'll never get to this point.
kernel=
case $cpu-$vendor in
score-*)
os=elf
;;
spu-*)
os=elf
;;
*-acorn)
os=riscix1.2
;;
arm*-rebel)
kernel=linux
os=gnu
;;
arm*-semi)
os=aout
;;
c4x-* | tic4x-*)
os=coff
;;
c8051-*)
os=elf
;;
clipper-intergraph)
os=clix
;;
hexagon-*)
os=elf
;;
tic54x-*)
os=coff
;;
tic55x-*)
os=coff
;;
tic6x-*)
os=coff
;;
# This must come before the *-dec entry.
pdp10-*)
os=tops20
;;
pdp11-*)
os=none
;;
*-dec | vax-*)
os=ultrix4.2
;;
m68*-apollo)
os=domain
;;
i386-sun)
os=sunos4.0.2
;;
m68000-sun)
os=sunos3
;;
m68*-cisco)
os=aout
;;
mep-*)
os=elf
;;
mips*-cisco)
os=elf
;;
mips*-*)
os=elf
;;
or32-*)
os=coff
;;
*-tti) # must be before sparc entry or we get the wrong os.
os=sysv3
;;
sparc-* | *-sun)
os=sunos4.1.1
;;
pru-*)
os=elf
;;
*-be)
os=beos
;;
*-ibm)
os=aix
;;
*-knuth)
os=mmixware
;;
*-wec)
os=proelf
;;
*-winbond)
os=proelf
;;
*-oki)
os=proelf
;;
*-hp)
os=hpux
;;
*-hitachi)
os=hiux
;;
i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent)
os=sysv
;;
*-cbm)
os=amigaos
;;
*-dg)
os=dgux
;;
*-dolphin)
os=sysv3
;;
m68k-ccur)
os=rtu
;;
m88k-omron*)
os=luna
;;
*-next)
os=nextstep
;;
*-sequent)
os=ptx
;;
*-crds)
os=unos
;;
*-ns)
os=genix
;;
i370-*)
os=mvs
;;
*-gould)
os=sysv
;;
*-highlevel)
os=bsd
;;
*-encore)
os=bsd
;;
*-sgi)
os=irix
;;
*-siemens)
os=sysv4
;;
*-masscomp)
os=rtu
;;
f30[01]-fujitsu | f700-fujitsu)
os=uxpv
;;
*-rom68k)
os=coff
;;
*-*bug)
os=coff
;;
*-apple)
os=macos
;;
*-atari*)
os=mint
;;
*-wrs)
os=vxworks
;;
*)
os=none
;;
esac
fi
# Now, validate our (potentially fixed-up) OS.
case $os in
# Sometimes we do "kernel-libc", so those need to count as OSes.
musl* | newlib* | uclibc*)
;;
# Likewise for "kernel-abi"
eabi* | gnueabi*)
;;
# VxWorks passes extra cpu info in the 4th filed.
simlinux | simwindows | spe)
;;
# Now accept the basic system types.
# The portable systems comes first.
# Each alternative MUST end in a * to match a version number.
gnu* | android* | bsd* | mach* | minix* | genix* | ultrix* | irix* \
| *vms* | esix* | aix* | cnk* | sunos | sunos[34]* \
| hpux* | unos* | osf* | luna* | dgux* | auroraux* | solaris* \
| sym* | plan9* | psp* | sim* | xray* | os68k* | v88r* \
| hiux* | abug | nacl* | netware* | windows* \
| os9* | macos* | osx* | ios* \
| mpw* | magic* | mmixware* | mon960* | lnews* \
| amigaos* | amigados* | msdos* | newsos* | unicos* | aof* \
| aos* | aros* | cloudabi* | sortix* | twizzler* \
| nindy* | vxsim* | vxworks* | ebmon* | hms* | mvs* \
| clix* | riscos* | uniplus* | iris* | isc* | rtu* | xenix* \
| mirbsd* | netbsd* | dicos* | openedition* | ose* \
| bitrig* | openbsd* | secbsd* | solidbsd* | libertybsd* | os108* \
| ekkobsd* | freebsd* | riscix* | lynxos* | os400* \
| bosx* | nextstep* | cxux* | aout* | elf* | oabi* \
| ptx* | coff* | ecoff* | winnt* | domain* | vsta* \
| udi* | lites* | ieee* | go32* | aux* | hcos* \
| chorusrdb* | cegcc* | glidix* | serenity* \
| cygwin* | msys* | pe* | moss* | proelf* | rtems* \
| midipix* | mingw32* | mingw64* | mint* \
| uxpv* | beos* | mpeix* | udk* | moxiebox* \
| interix* | uwin* | mks* | rhapsody* | darwin* \
| openstep* | oskit* | conix* | pw32* | nonstopux* \
| storm-chaos* | tops10* | tenex* | tops20* | its* \
| os2* | vos* | palmos* | uclinux* | nucleus* | morphos* \
| scout* | superux* | sysv* | rtmk* | tpf* | windiss* \
| powermax* | dnix* | nx6 | nx7 | sei* | dragonfly* \
| skyos* | haiku* | rdos* | toppers* | drops* | es* \
| onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \
| midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \
| nsk* | powerunix* | genode* | zvmoe* | qnx* | emx*)
;;
# This one is extra strict with allowed versions
sco3.2v2 | sco3.2v[4-9]* | sco5v6*)
# Don't forget version if it is 3.2v4 or newer.
;;
none)
;;
*)
echo Invalid configuration \`"$1"\': OS \`"$os"\' not recognized 1>&2
exit 1
;;
esac
# As a final step for OS-related things, validate the OS-kernel combination
# (given a valid OS), if there is a kernel.
case $kernel-$os in
linux-gnu* | linux-dietlibc* | linux-android* | linux-newlib* | linux-musl* | linux-uclibc* )
;;
uclinux-uclibc* )
;;
-dietlibc* | -newlib* | -musl* | -uclibc* )
# These are just libc implementations, not actual OSes, and thus
# require a kernel.
echo "Invalid configuration \`$1': libc \`$os' needs explicit kernel." 1>&2
exit 1
;;
kfreebsd*-gnu* | kopensolaris*-gnu*)
;;
vxworks-simlinux | vxworks-simwindows | vxworks-spe)
;;
nto-qnx*)
;;
os2-emx)
;;
*-eabi* | *-gnueabi*)
;;
-*)
# Blank kernel with real OS is always fine.
;;
*-*)
echo "Invalid configuration \`$1': Kernel \`$kernel' not known to work with OS \`$os'." 1>&2
exit 1
;;
esac
# Here we handle the case where we know the os, and the CPU type, but not the
# manufacturer. We pick the logical manufacturer.
case $vendor in
unknown)
case $cpu-$os in
*-riscix*)
vendor=acorn
;;
*-sunos*)
vendor=sun
;;
*-cnk* | *-aix*)
vendor=ibm
;;
*-beos*)
vendor=be
;;
*-hpux*)
vendor=hp
;;
*-mpeix*)
vendor=hp
;;
*-hiux*)
vendor=hitachi
;;
*-unos*)
vendor=crds
;;
*-dgux*)
vendor=dg
;;
*-luna*)
vendor=omron
;;
*-genix*)
vendor=ns
;;
*-clix*)
vendor=intergraph
;;
*-mvs* | *-opened*)
vendor=ibm
;;
*-os400*)
vendor=ibm
;;
s390-* | s390x-*)
vendor=ibm
;;
*-ptx*)
vendor=sequent
;;
*-tpf*)
vendor=ibm
;;
*-vxsim* | *-vxworks* | *-windiss*)
vendor=wrs
;;
*-aux*)
vendor=apple
;;
*-hms*)
vendor=hitachi
;;
*-mpw* | *-macos*)
vendor=apple
;;
*-*mint | *-mint[0-9]* | *-*MiNT | *-MiNT[0-9]*)
vendor=atari
;;
*-vos*)
vendor=stratus
;;
esac
;;
esac
echo "$cpu-$vendor-${kernel:+$kernel-}$os"
exit
# Local variables:
# eval: (add-hook 'before-save-hook 'time-stamp)
# time-stamp-start: "timestamp='"
# time-stamp-format: "%:y-%02m-%02d"
# time-stamp-end: "'"
# End:
|
Changes to autosetup/autosetup-find-tclsh.
1 2 | #!/bin/sh # Looks for a suitable tclsh or jimsh in the PATH | | | > | < < | | | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#!/bin/sh
# Looks for a suitable tclsh or jimsh in the PATH
# If not found, builds a bootstrap jimsh in current dir from source
# Prefer $autosetup_tclsh if is set in the environment (unless ./jimsh0 works)
# If an argument is given, use that as the test instead of autosetup-test-tclsh
d="`dirname "$0"`"
for tclsh in ./jimsh0 $autosetup_tclsh jimsh tclsh tclsh8.5 tclsh8.6 tclsh8.7; do
{ $tclsh "$d/${1-autosetup-test-tclsh}"; } 2>/dev/null && exit 0
done
echo 1>&2 "No installed jimsh or tclsh, building local bootstrap jimsh0"
for cc in ${CC_FOR_BUILD:-cc} gcc; do
{ $cc -o jimsh0 "$d/jimsh0.c"; } 2>/dev/null || continue
./jimsh0 "$d/${1-autosetup-test-tclsh}" && exit 0
done
echo 1>&2 "No working C compiler found. Tried ${CC_FOR_BUILD:-cc} and gcc."
echo false
|
Changes to autosetup/cc-db.tcl.
1 2 3 4 5 6 7 8 9 10 | # Copyright (c) 2011 WorkWare Systems http://www.workware.net.au/ # All rights reserved # @synopsis: # # The 'cc-db' module provides a knowledge-base of system idiosyncrasies. # In general, this module can always be included. use cc | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# Copyright (c) 2011 WorkWare Systems http://www.workware.net.au/
# All rights reserved
# @synopsis:
#
# The 'cc-db' module provides a knowledge-base of system idiosyncrasies.
# In general, this module can always be included.
use cc
options {}
# openbsd needs sys/types.h to detect some system headers
cc-include-needs sys/socket.h sys/types.h
cc-include-needs netinet/in.h sys/types.h
|
Changes to autosetup/cc-lib.tcl.
1 2 3 4 5 6 7 8 9 | # Copyright (c) 2011 WorkWare Systems http://www.workware.net.au/ # All rights reserved # @synopsis: # # Provides a library of common tests on top of the 'cc' module. use cc | < < | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | # Copyright (c) 2011 WorkWare Systems http://www.workware.net.au/ # All rights reserved # @synopsis: # # Provides a library of common tests on top of the 'cc' module. use cc # @cc-check-lfs # # The equivalent of the 'AC_SYS_LARGEFILE' macro. # # defines 'HAVE_LFS' if LFS is available, # and defines '_FILE_OFFSET_BITS=64' if necessary # |
| ︙ | ︙ | |||
76 77 78 79 80 81 82 | return $rc } # @cc-check-flags flag ?...? # # Checks whether the given C/C++ compiler flags can be used. Defines feature # names prefixed with 'HAVE_CFLAG' and 'HAVE_CXXFLAG' respectively, and | | | 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
return $rc
}
# @cc-check-flags flag ?...?
#
# Checks whether the given C/C++ compiler flags can be used. Defines feature
# names prefixed with 'HAVE_CFLAG' and 'HAVE_CXXFLAG' respectively, and
# appends working flags to '-cflags' and 'AS_CFLAGS' or 'AS_CXXFLAGS'.
proc cc-check-flags {args} {
set result 1
array set opts [cc-get-settings]
switch -exact -- $opts(-lang) {
c++ {
set lang C++
set prefix CXXFLAG
|
| ︙ | ︙ | |||
99 100 101 102 103 104 105 |
}
foreach flag $args {
msg-checking "Checking whether the $lang compiler accepts $flag..."
if {[cctest -cflags $flag]} {
msg-result yes
define-feature $prefix$flag
cc-with [list -cflags [list $flag]]
| | | | | 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
}
foreach flag $args {
msg-checking "Checking whether the $lang compiler accepts $flag..."
if {[cctest -cflags $flag]} {
msg-result yes
define-feature $prefix$flag
cc-with [list -cflags [list $flag]]
define-append AS_${prefix}S $flag
} else {
msg-result no
set result 0
}
}
return $result
}
# @cc-check-standards ver ?...?
#
# Checks whether the C/C++ compiler accepts one of the specified '-std=$ver'
# options, and appends the first working one to '-cflags' and 'AS_CFLAGS' or
# 'AS_CXXFLAGS'.
proc cc-check-standards {args} {
array set opts [cc-get-settings]
foreach std $args {
if {[cc-check-flags -std=$std]} {
return $std
}
}
|
| ︙ | ︙ |
Changes to autosetup/cc-shared.tcl.
| ︙ | ︙ | |||
16 17 18 19 20 21 22 | ## SHOBJ_LDFLAGS Flags to use linking a shared object, undefined symbols allowed ## SHOBJ_LDFLAGS_R - as above, but all symbols must be resolved ## SH_LINKRPATH Format for setting the rpath when linking an executable, %s = path ## SH_LINKFLAGS Flags to use linking an executable which will load shared objects ## LD_LIBRARY_PATH Environment variable which specifies path to shared libraries ## STRIPLIBFLAGS Arguments to strip a dynamic library | | | 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
## SHOBJ_LDFLAGS Flags to use linking a shared object, undefined symbols allowed
## SHOBJ_LDFLAGS_R - as above, but all symbols must be resolved
## SH_LINKRPATH Format for setting the rpath when linking an executable, %s = path
## SH_LINKFLAGS Flags to use linking an executable which will load shared objects
## LD_LIBRARY_PATH Environment variable which specifies path to shared libraries
## STRIPLIBFLAGS Arguments to strip a dynamic library
options {}
# Defaults: gcc on unix
define SHOBJ_CFLAGS -fPIC
define SHOBJ_LDFLAGS -shared
define SH_CFLAGS -fPIC
define SH_LDFLAGS -shared
define SH_LINKFLAGS -rdynamic
|
| ︙ | ︙ |
Changes to autosetup/cc.tcl.
| ︙ | ︙ | |||
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | # # The following environment variables are used if set: # ## CC - C compiler ## CXX - C++ compiler ## CPP - C preprocessor ## CCACHE - Set to "none" to disable automatic use of ccache ## CFLAGS - Additional C compiler flags ## CXXFLAGS - Additional C++ compiler flags ## LDFLAGS - Additional compiler flags during linking ## LIBS - Additional libraries to use (for all tests) ## CROSS - Tool prefix for cross compilation # # The following variables are defined from the corresponding # environment variables if set. # | > > < < | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
#
# The following environment variables are used if set:
#
## CC - C compiler
## CXX - C++ compiler
## CPP - C preprocessor
## CCACHE - Set to "none" to disable automatic use of ccache
## CPPFLAGS - Additional C preprocessor compiler flags (C and C++), before CFLAGS, CXXFLAGS
## CFLAGS - Additional C compiler flags
## CXXFLAGS - Additional C++ compiler flags
## LDFLAGS - Additional compiler flags during linking
## LINKFLAGS - ?How is this different from LDFLAGS?
## LIBS - Additional libraries to use (for all tests)
## CROSS - Tool prefix for cross compilation
#
# The following variables are defined from the corresponding
# environment variables if set.
#
## CC_FOR_BUILD
## LD
use system
options {}
# Checks for the existence of the given function by linking
#
proc cctest_function {function} {
cctest -link 1 -declare "extern void $function\(void);" -code "$function\();"
}
|
| ︙ | ︙ | |||
260 261 262 263 264 265 266 |
#
# It is an error if the executable is not found.
#
proc cc-check-tools {args} {
foreach tool $args {
set TOOL [string toupper $tool]
set exe [get-env $TOOL [get-define cross]$tool]
| | | | 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
#
# It is an error if the executable is not found.
#
proc cc-check-tools {args} {
foreach tool $args {
set TOOL [string toupper $tool]
set exe [get-env $TOOL [get-define cross]$tool]
if {[find-executable $exe]} {
define $TOOL $exe
continue
}
if {[find-executable $tool]} {
msg-result "Warning: Failed to find $exe, falling back to $tool which may be incorrect"
define $TOOL $tool
continue
}
user-error "Failed to find $exe"
}
}
|
| ︙ | ︙ | |||
414 415 416 417 418 419 420 421 422 423 424 425 426 427 |
#
## cc-with {-libs {-lc -lm}} {
## cc-with {-libs -ldl} {
## cctest -libs -lsocket ...
## # libs will be in this order: -lsocket -ldl -lc -lm
## }
## }
proc cc-with {settings args} {
if {[llength $args] == 0} {
cc-add-settings $settings
} elseif {[llength $args] > 1} {
autosetup-error "usage: cc-with settings ?script?"
} else {
set save [cc-add-settings $settings]
| > > > > > > > | 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 |
#
## cc-with {-libs {-lc -lm}} {
## cc-with {-libs -ldl} {
## cctest -libs -lsocket ...
## # libs will be in this order: -lsocket -ldl -lc -lm
## }
## }
#
# If you wish to invoke something like cc-check-flags but not have -cflags updated,
# use the following idiom:
#
## cc-with {} {
## cc-check-flags ...
## }
proc cc-with {settings args} {
if {[llength $args] == 0} {
cc-add-settings $settings
} elseif {[llength $args] > 1} {
autosetup-error "usage: cc-with settings ?script?"
} else {
set save [cc-add-settings $settings]
|
| ︙ | ︙ | |||
451 452 453 454 455 456 457 | ## -source code Compile a complete program. Ignore -includes, -declare and -code ## -sourcefile file Shorthand for -source [readfile [get-define srcdir]/$file] ## -nooutput 1 Treat any compiler output (e.g. a warning) as an error # # Unless '-source' or '-sourcefile' is specified, the C program looks like: # ## #include <firstinclude> /* same for remaining includes in the list */ | < < > > > > > > > > > > | 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 |
## -source code Compile a complete program. Ignore -includes, -declare and -code
## -sourcefile file Shorthand for -source [readfile [get-define srcdir]/$file]
## -nooutput 1 Treat any compiler output (e.g. a warning) as an error
#
# Unless '-source' or '-sourcefile' is specified, the C program looks like:
#
## #include <firstinclude> /* same for remaining includes in the list */
## declare-code /* any code in -declare, verbatim */
## int main(void) {
## code /* any code in -code, verbatim */
## return 0;
## }
#
# And the command line looks like:
#
## CC -cflags CFLAGS CPPFLAGS conftest.c -o conftest.o
## CXX -cflags CXXFLAGS CPPFLAGS conftest.cpp -o conftest.o
#
# And if linking:
#
## CC LDFLAGS -cflags CFLAGS conftest.c -o conftest -libs LIBS
## CXX LDFLAGS -cflags CXXFLAGS conftest.c -o conftest -libs LIBS
#
# Any failures are recorded in 'config.log'
#
proc cctest {args} {
set tmp conftest__
# Easiest way to merge in the settings
cc-with $args {
|
| ︙ | ︙ | |||
504 505 506 507 508 509 510 |
# Build the command line
set cmdline {}
lappend cmdline {*}[get-define CCACHE]
switch -exact -- $opts(-lang) {
c++ {
set src conftest__.cpp
| | > | > > | | | | 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 |
# Build the command line
set cmdline {}
lappend cmdline {*}[get-define CCACHE]
switch -exact -- $opts(-lang) {
c++ {
set src conftest__.cpp
lappend cmdline {*}[get-define CXX]
set cflags [get-define CXXFLAGS]
}
c {
set src conftest__.c
lappend cmdline {*}[get-define CC]
set cflags [get-define CFLAGS]
}
default {
autosetup-error "cctest called with unknown language: $opts(-lang)"
}
}
if {$opts(-link)} {
lappend cmdline {*}[get-define LDFLAGS]
} else {
lappend cflags {*}[get-define CPPFLAGS]
set tmp conftest__.o
lappend cmdline -c
}
lappend cmdline {*}$opts(-cflags) {*}[get-define cc-default-debug ""] {*}$cflags
lappend cmdline $src -o $tmp
if {$opts(-link)} {
lappend cmdline {*}$opts(-libs) {*}[get-define LIBS]
}
# At this point we have the complete command line and the
# complete source to be compiled. Get the result from cache if
# we can
if {[info exists ::cc_cache($cmdline,$lines)]} {
msg-checking "(cached) "
|
| ︙ | ︙ | |||
656 657 658 659 660 661 662 | } } } return "" } # Initialise some values from the environment or commandline or default settings | | | | > > > > > | | | | 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 |
}
}
}
return ""
}
# Initialise some values from the environment or commandline or default settings
foreach i {LDFLAGS LIBS CPPFLAGS LINKFLAGS CFLAGS} {
lassign $i var default
define $var [get-env $var $default]
}
if {[env-is-set CC]} {
# Set by the user, so don't try anything else
set try [list [get-env CC ""]]
} else {
# Try some reasonable options
set try [list [get-define cross]cc [get-define cross]gcc]
}
define CC [find-an-executable {*}$try]
if {[get-define CC] eq ""} {
user-error "Could not find a C compiler. Tried: [join $try ", "]"
}
define CPP [get-env CPP "[get-define CC] -E"]
# XXX: Could avoid looking for a C++ compiler until requested
# If CXX isn't found, it is set to the empty string.
if {[env-is-set CXX]} {
define CXX [find-an-executable -required [get-env CXX ""]]
} else {
define CXX [find-an-executable [get-define cross]c++ [get-define cross]g++]
}
# CXXFLAGS default to CFLAGS if not specified
define CXXFLAGS [get-env CXXFLAGS [get-define CFLAGS]]
# May need a CC_FOR_BUILD, so look for one
define CC_FOR_BUILD [find-an-executable [get-env CC_FOR_BUILD ""] cc gcc false]
if {[get-define CC] eq ""} {
user-error "Could not find a C compiler. Tried: [join $try ", "]"
}
# These start empty and never come from the user or environment
define AS_CFLAGS ""
define AS_CPPFLAGS ""
define AS_CXXFLAGS ""
define CCACHE [find-an-executable [get-env CCACHE ccache]]
# If any of these are set in the environment, propagate them to the AUTOREMAKE commandline
foreach i {CC CXX CCACHE CPP CFLAGS CXXFLAGS CXXFLAGS LDFLAGS LIBS CROSS CPPFLAGS LINKFLAGS CC_FOR_BUILD LD} {
if {[env-is-set $i]} {
# Note: If the variable is set on the command line, get-env will return that value
# so the command line will continue to override the environment
define-append-argv AUTOREMAKE $i=[get-env $i ""]
}
}
# Initial cctest settings
cc-store-settings {-cflags {} -includes {} -declare {} -link 0 -lang c -libs {} -code {} -nooutput 0}
set autosetup(cc-include-deps) {}
msg-result "C compiler...[get-define CCACHE] [get-define CC] [get-define CFLAGS] [get-define CPPFLAGS]"
if {[get-define CXX] ne "false"} {
msg-result "C++ compiler...[get-define CCACHE] [get-define CXX] [get-define CXXFLAGS] [get-define CPPFLAGS]"
}
msg-result "Build C compiler...[get-define CC_FOR_BUILD]"
# On Darwin, we prefer to use -g0 to avoid creating .dSYM directories
# but some compilers may not support it, so test here.
switch -glob -- [get-define host] {
*-*-darwin* {
|
| ︙ | ︙ |
Changes to autosetup/jimsh0.c.
| ︙ | ︙ | |||
8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #define jim_ext_bootstrap #define jim_ext_aio #define jim_ext_readdir #define jim_ext_regexp #define jim_ext_file #define jim_ext_glob #define jim_ext_exec #define jim_ext_clock #define jim_ext_array #define jim_ext_stdlib #define jim_ext_tclcompat #if defined(_MSC_VER) #define TCL_PLATFORM_OS "windows" #define TCL_PLATFORM_PLATFORM "windows" | > | 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #define jim_ext_bootstrap #define jim_ext_aio #define jim_ext_readdir #define jim_ext_regexp #define jim_ext_file #define jim_ext_glob #define jim_ext_exec #define jim_ext_posix #define jim_ext_clock #define jim_ext_array #define jim_ext_stdlib #define jim_ext_tclcompat #if defined(_MSC_VER) #define TCL_PLATFORM_OS "windows" #define TCL_PLATFORM_PLATFORM "windows" |
| ︙ | ︙ | |||
45 46 47 48 49 50 51 | #define TCL_PLATFORM_PATH_SEPARATOR ":" #ifdef _MINIX #define vfork fork #define _POSIX_SOURCE #else #define _GNU_SOURCE #endif | | > > | | 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
#define TCL_PLATFORM_PATH_SEPARATOR ":"
#ifdef _MINIX
#define vfork fork
#define _POSIX_SOURCE
#else
#define _GNU_SOURCE
#endif
#define HAVE_FORK
#define HAVE_WAITPID
#define HAVE_ISATTY
#define HAVE_MKSTEMP
#define HAVE_LINK
#define HAVE_SYS_TIME_H
#define HAVE_DIRENT_H
#define HAVE_UNISTD_H
#define HAVE_UMASK
#define HAVE_PIPE
#define _FILE_OFFSET_BITS 64
#endif
#define JIM_VERSION 82
#ifndef JIM_WIN32COMPAT_H
#define JIM_WIN32COMPAT_H
#ifdef __cplusplus
extern "C" {
|
| ︙ | ︙ | |||
182 183 184 185 186 187 188 |
#ifdef __cplusplus
extern "C" {
#endif
#include <time.h>
#include <limits.h>
| < | 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
#ifdef __cplusplus
extern "C" {
#endif
#include <time.h>
#include <limits.h>
#include <stdlib.h>
#include <stdarg.h>
#ifndef HAVE_NO_AUTOCONF
#endif
|
| ︙ | ︙ | |||
221 222 223 224 225 226 227 228 229 230 231 232 233 234 | # define strtoull strtoul # endif #endif #define UCHAR(c) ((unsigned char)(c)) #define JIM_OK 0 #define JIM_ERR 1 #define JIM_RETURN 2 #define JIM_BREAK 3 #define JIM_CONTINUE 4 #define JIM_SIGNAL 5 #define JIM_EXIT 6 | > > > | 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | # define strtoull strtoul # endif #endif #define UCHAR(c) ((unsigned char)(c)) #define JIM_ABI_VERSION 101 #define JIM_OK 0 #define JIM_ERR 1 #define JIM_RETURN 2 #define JIM_BREAK 3 #define JIM_CONTINUE 4 #define JIM_SIGNAL 5 #define JIM_EXIT 6 |
| ︙ | ︙ | |||
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | #define JIM_PRIV_FLAG_SHIFT 20 #define JIM_NONE 0 #define JIM_ERRMSG 1 #define JIM_ENUM_ABBREV 2 #define JIM_UNSHARED 4 #define JIM_MUSTEXIST 8 #define JIM_SUBST_NOVAR 1 #define JIM_SUBST_NOCMD 2 #define JIM_SUBST_NOESC 4 #define JIM_SUBST_FLAG 128 #define JIM_CASESENS 0 #define JIM_NOCASE 1 #define JIM_PATH_LEN 1024 #define JIM_NOTUSED(V) ((void) V) | > > | 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | #define JIM_PRIV_FLAG_SHIFT 20 #define JIM_NONE 0 #define JIM_ERRMSG 1 #define JIM_ENUM_ABBREV 2 #define JIM_UNSHARED 4 #define JIM_MUSTEXIST 8 #define JIM_NORESULT 16 #define JIM_SUBST_NOVAR 1 #define JIM_SUBST_NOCMD 2 #define JIM_SUBST_NOESC 4 #define JIM_SUBST_FLAG 128 #define JIM_CASESENS 0 #define JIM_NOCASE 1 #define JIM_OPT_END 2 #define JIM_PATH_LEN 1024 #define JIM_NOTUSED(V) ((void) V) |
| ︙ | ︙ | |||
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
#define Jim_SetHashVal(ht, entry, _val_) do { \
if ((ht)->type->valDup) \
(entry)->u.val = (ht)->type->valDup((ht)->privdata, (_val_)); \
else \
(entry)->u.val = (_val_); \
} while(0)
#define Jim_FreeEntryKey(ht, entry) \
if ((ht)->type->keyDestructor) \
(ht)->type->keyDestructor((ht)->privdata, (entry)->key)
#define Jim_SetHashKey(ht, entry, _key_) do { \
if ((ht)->type->keyDup) \
(entry)->key = (ht)->type->keyDup((ht)->privdata, (_key_)); \
else \
(entry)->key = (void *)(_key_); \
} while(0)
#define Jim_CompareHashKeys(ht, key1, key2) \
(((ht)->type->keyCompare) ? \
(ht)->type->keyCompare((ht)->privdata, (key1), (key2)) : \
(key1) == (key2))
#define Jim_HashKey(ht, key) ((ht)->type->hashFunction(key) + (ht)->uniq)
#define Jim_GetHashEntryKey(he) ((he)->key)
#define Jim_GetHashEntryVal(he) ((he)->u.val)
#define Jim_GetHashTableCollisions(ht) ((ht)->collisions)
#define Jim_GetHashTableSize(ht) ((ht)->size)
#define Jim_GetHashTableUsed(ht) ((ht)->used)
typedef struct Jim_Obj {
char *bytes;
| > > > | 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 |
#define Jim_SetHashVal(ht, entry, _val_) do { \
if ((ht)->type->valDup) \
(entry)->u.val = (ht)->type->valDup((ht)->privdata, (_val_)); \
else \
(entry)->u.val = (_val_); \
} while(0)
#define Jim_SetHashIntVal(ht, entry, _val_) (entry)->u.intval = (_val_)
#define Jim_FreeEntryKey(ht, entry) \
if ((ht)->type->keyDestructor) \
(ht)->type->keyDestructor((ht)->privdata, (entry)->key)
#define Jim_SetHashKey(ht, entry, _key_) do { \
if ((ht)->type->keyDup) \
(entry)->key = (ht)->type->keyDup((ht)->privdata, (_key_)); \
else \
(entry)->key = (void *)(_key_); \
} while(0)
#define Jim_CompareHashKeys(ht, key1, key2) \
(((ht)->type->keyCompare) ? \
(ht)->type->keyCompare((ht)->privdata, (key1), (key2)) : \
(key1) == (key2))
#define Jim_HashKey(ht, key) ((ht)->type->hashFunction(key) + (ht)->uniq)
#define Jim_GetHashEntryKey(he) ((he)->key)
#define Jim_GetHashEntryVal(he) ((he)->u.val)
#define Jim_GetHashEntryIntVal(he) ((he)->u.intval)
#define Jim_GetHashTableCollisions(ht) ((ht)->collisions)
#define Jim_GetHashTableSize(ht) ((ht)->size)
#define Jim_GetHashTableUsed(ht) ((ht)->used)
typedef struct Jim_Obj {
char *bytes;
|
| ︙ | ︙ | |||
373 374 375 376 377 378 379 |
struct {
void *ptr;
int int1;
int int2;
} ptrIntValue;
struct {
| | > > | 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 |
struct {
void *ptr;
int int1;
int int2;
} ptrIntValue;
struct {
struct Jim_VarVal *vv;
unsigned long callFrameId;
int global;
} varValue;
struct {
struct Jim_Obj *nsObj;
struct Jim_Cmd *cmdPtr;
unsigned long procEpoch;
} cmdValue;
struct {
struct Jim_Obj **ele;
int len;
int maxLen;
} listValue;
struct Jim_Dict *dictValue;
struct {
int maxLength;
int charLength;
} strValue;
struct {
|
| ︙ | ︙ | |||
475 476 477 478 479 480 481 |
struct Jim_CallFrame *parent;
Jim_Obj *const *argv;
int argc;
Jim_Obj *procArgsObjPtr;
Jim_Obj *procBodyObjPtr;
struct Jim_CallFrame *next;
Jim_Obj *nsObj;
| | | > | > > > > > > > > > > > > | | > > > > > > > > > > > > > | 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 |
struct Jim_CallFrame *parent;
Jim_Obj *const *argv;
int argc;
Jim_Obj *procArgsObjPtr;
Jim_Obj *procBodyObjPtr;
struct Jim_CallFrame *next;
Jim_Obj *nsObj;
Jim_Obj *unused_fileNameObj;
int unused_line;
Jim_Stack *localCommands;
struct Jim_Obj *tailcallObj;
struct Jim_Cmd *tailcallCmd;
} Jim_CallFrame;
typedef struct Jim_EvalFrame {
Jim_CallFrame *framePtr;
int level;
int procLevel;
struct Jim_Cmd *cmd;
struct Jim_EvalFrame *parent;
Jim_Obj *const *argv;
int argc;
Jim_Obj *scriptObj;
} Jim_EvalFrame;
typedef struct Jim_VarVal {
Jim_Obj *objPtr;
struct Jim_CallFrame *linkFramePtr;
int refCount;
} Jim_VarVal;
typedef int Jim_CmdProc(struct Jim_Interp *interp, int argc,
Jim_Obj *const *argv);
typedef void Jim_DelCmdProc(struct Jim_Interp *interp, void *privData);
typedef struct Jim_Dict {
struct JimDictHashEntry {
int offset;
unsigned hash;
} *ht;
unsigned int size;
unsigned int sizemask;
unsigned int uniq;
Jim_Obj **table;
int len;
int maxLen;
unsigned int dummy;
} Jim_Dict;
typedef struct Jim_Cmd {
int inUse;
int isproc;
struct Jim_Cmd *prevCmd;
Jim_Obj *cmdNameObj;
union {
struct {
Jim_CmdProc *cmdProc;
Jim_DelCmdProc *delProc;
void *privData;
} native;
|
| ︙ | ︙ | |||
532 533 534 535 536 537 538 |
typedef struct Jim_PrngState {
unsigned char sbox[256];
unsigned int i, j;
} Jim_PrngState;
typedef struct Jim_Interp {
Jim_Obj *result;
| | | | | 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 |
typedef struct Jim_PrngState {
unsigned char sbox[256];
unsigned int i, j;
} Jim_PrngState;
typedef struct Jim_Interp {
Jim_Obj *result;
int unused_errorLine;
Jim_Obj *currentFilenameObj;
int unused_addStackTrace;
int maxCallFrameDepth;
int maxEvalDepth;
int evalDepth;
int returnCode;
int returnLevel;
int exitCode;
long id;
|
| ︙ | ︙ | |||
556 557 558 559 560 561 562 563 564 |
of procedures names lookup caching
may no longer be valid. */
unsigned long callFrameEpoch; /* Incremented every time a new
callframe is created. This id is used for the
'ID' field contained in the Jim_CallFrame
structure. */
int local;
Jim_Obj *liveList;
Jim_Obj *freeList;
| > > | > > > > | > > > > < | 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 |
of procedures names lookup caching
may no longer be valid. */
unsigned long callFrameEpoch; /* Incremented every time a new
callframe is created. This id is used for the
'ID' field contained in the Jim_CallFrame
structure. */
int local;
int quitting;
int safeexpr;
Jim_Obj *liveList;
Jim_Obj *freeList;
Jim_Obj *unused_currentScriptObj;
Jim_EvalFrame topEvalFrame;
Jim_EvalFrame *evalFrame;
int procLevel;
Jim_Obj * const *unused_argv;
Jim_Obj *nullScriptObj;
Jim_Obj *emptyObj;
Jim_Obj *trueObj;
Jim_Obj *falseObj;
unsigned long referenceNextId;
struct Jim_HashTable references;
unsigned long lastCollectId; /* reference max Id of the last GC
execution. It's set to ~0 while the collection
is running as sentinel to avoid to recursive
calls via the [collect] command inside
finalizers. */
jim_wide lastCollectTime;
Jim_Obj *stackTrace;
Jim_Obj *errorProc;
Jim_Obj *unknown;
Jim_Obj *defer;
Jim_Obj *traceCmdObj;
int unknown_called;
int errorFlag;
void *cmdPrivData; /* Used to pass the private data pointer to
a command. It is set to what the user specified
via Jim_CreateCommand(). */
Jim_Cmd *oldCmdCache;
int oldCmdCacheSize;
struct Jim_CallFrame *freeFramesList;
struct Jim_HashTable assocData;
Jim_PrngState *prngState;
struct Jim_HashTable packages;
Jim_Stack *loadHandles;
} Jim_Interp;
#define Jim_SetResultString(i,s,l) Jim_SetResult(i, Jim_NewStringObj(i,s,l))
#define Jim_SetResultInt(i,intval) Jim_SetResult(i, Jim_NewIntObj(i,intval))
#define Jim_SetResultBool(i,b) Jim_SetResultInt(i, b)
#define Jim_SetEmptyResult(i) Jim_SetResult(i, (i)->emptyObj)
#define Jim_GetResult(i) ((i)->result)
#define Jim_CmdPrivData(i) ((i)->cmdPrivData)
|
| ︙ | ︙ | |||
619 620 621 622 623 624 625 |
char tag[JIM_REFERENCE_TAGLEN+1];
} Jim_Reference;
#define Jim_NewEmptyStringObj(i) Jim_NewStringObj(i, "", 0)
#define Jim_FreeHashTableIterator(iter) Jim_Free(iter)
| | | | | > > > > > > > > > > > > > | 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 |
char tag[JIM_REFERENCE_TAGLEN+1];
} Jim_Reference;
#define Jim_NewEmptyStringObj(i) Jim_NewStringObj(i, "", 0)
#define Jim_FreeHashTableIterator(iter) Jim_Free(iter)
#define JIM_EXPORT extern
JIM_EXPORT void *(*Jim_Allocator)(void *ptr, size_t size);
#define Jim_Free(P) Jim_Allocator((P), 0)
#define Jim_Realloc(P, S) Jim_Allocator((P), (S))
#define Jim_Alloc(S) Jim_Allocator(NULL, (S))
JIM_EXPORT char * Jim_StrDup (const char *s);
JIM_EXPORT char *Jim_StrDupLen(const char *s, int l);
JIM_EXPORT char **Jim_GetEnviron(void);
JIM_EXPORT void Jim_SetEnviron(char **env);
JIM_EXPORT int Jim_MakeTempFile(Jim_Interp *interp, const char *filename_template, int unlink_file);
#ifndef CLOCK_REALTIME
# define CLOCK_REALTIME 0
#endif
#ifndef CLOCK_MONOTONIC
# define CLOCK_MONOTONIC 1
#endif
#ifndef CLOCK_MONOTONIC_RAW
# define CLOCK_MONOTONIC_RAW CLOCK_MONOTONIC
#endif
JIM_EXPORT jim_wide Jim_GetTimeUsec(unsigned type);
JIM_EXPORT int Jim_Eval(Jim_Interp *interp, const char *script);
JIM_EXPORT int Jim_EvalSource(Jim_Interp *interp, const char *filename, int lineno, const char *script);
|
| ︙ | ︙ | |||
678 679 680 681 682 683 684 |
JIM_EXPORT int Jim_ReplaceHashEntry (Jim_HashTable *ht,
const void *key, void *val);
JIM_EXPORT int Jim_DeleteHashEntry (Jim_HashTable *ht,
const void *key);
JIM_EXPORT int Jim_FreeHashTable (Jim_HashTable *ht);
JIM_EXPORT Jim_HashEntry * Jim_FindHashEntry (Jim_HashTable *ht,
const void *key);
| < | 738 739 740 741 742 743 744 745 746 747 748 749 750 751 |
JIM_EXPORT int Jim_ReplaceHashEntry (Jim_HashTable *ht,
const void *key, void *val);
JIM_EXPORT int Jim_DeleteHashEntry (Jim_HashTable *ht,
const void *key);
JIM_EXPORT int Jim_FreeHashTable (Jim_HashTable *ht);
JIM_EXPORT Jim_HashEntry * Jim_FindHashEntry (Jim_HashTable *ht,
const void *key);
JIM_EXPORT Jim_HashTableIterator *Jim_GetHashTableIterator
(Jim_HashTable *ht);
JIM_EXPORT Jim_HashEntry * Jim_NextHashEntry
(Jim_HashTableIterator *iter);
JIM_EXPORT Jim_Obj * Jim_NewObj (Jim_Interp *interp);
|
| ︙ | ︙ | |||
722 723 724 725 726 727 728 |
Jim_Obj *fmtObjPtr, int objc, Jim_Obj *const *objv);
JIM_EXPORT Jim_Obj * Jim_ScanString (Jim_Interp *interp, Jim_Obj *strObjPtr,
Jim_Obj *fmtObjPtr, int flags);
JIM_EXPORT int Jim_CompareStringImmediate (Jim_Interp *interp,
Jim_Obj *objPtr, const char *str);
JIM_EXPORT int Jim_StringCompareObj(Jim_Interp *interp, Jim_Obj *firstObjPtr,
Jim_Obj *secondObjPtr, int nocase);
| < < | 781 782 783 784 785 786 787 788 789 790 791 792 793 794 |
Jim_Obj *fmtObjPtr, int objc, Jim_Obj *const *objv);
JIM_EXPORT Jim_Obj * Jim_ScanString (Jim_Interp *interp, Jim_Obj *strObjPtr,
Jim_Obj *fmtObjPtr, int flags);
JIM_EXPORT int Jim_CompareStringImmediate (Jim_Interp *interp,
Jim_Obj *objPtr, const char *str);
JIM_EXPORT int Jim_StringCompareObj(Jim_Interp *interp, Jim_Obj *firstObjPtr,
Jim_Obj *secondObjPtr, int nocase);
JIM_EXPORT int Jim_Utf8Length(Jim_Interp *interp, Jim_Obj *objPtr);
JIM_EXPORT Jim_Obj * Jim_NewReference (Jim_Interp *interp,
Jim_Obj *objPtr, Jim_Obj *tagPtr, Jim_Obj *cmdNamePtr);
JIM_EXPORT Jim_Reference * Jim_GetReference (Jim_Interp *interp,
Jim_Obj *objPtr);
|
| ︙ | ︙ | |||
747 748 749 750 751 752 753 |
JIM_EXPORT void Jim_RegisterCoreCommands (Jim_Interp *interp);
JIM_EXPORT int Jim_CreateCommand (Jim_Interp *interp,
const char *cmdName, Jim_CmdProc *cmdProc, void *privData,
Jim_DelCmdProc *delProc);
JIM_EXPORT int Jim_DeleteCommand (Jim_Interp *interp,
| | | | 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 |
JIM_EXPORT void Jim_RegisterCoreCommands (Jim_Interp *interp);
JIM_EXPORT int Jim_CreateCommand (Jim_Interp *interp,
const char *cmdName, Jim_CmdProc *cmdProc, void *privData,
Jim_DelCmdProc *delProc);
JIM_EXPORT int Jim_DeleteCommand (Jim_Interp *interp,
Jim_Obj *cmdNameObj);
JIM_EXPORT int Jim_RenameCommand (Jim_Interp *interp,
Jim_Obj *oldNameObj, Jim_Obj *newNameObj);
JIM_EXPORT Jim_Cmd * Jim_GetCommand (Jim_Interp *interp,
Jim_Obj *objPtr, int flags);
JIM_EXPORT int Jim_SetVariable (Jim_Interp *interp,
Jim_Obj *nameObjPtr, Jim_Obj *valObjPtr);
JIM_EXPORT int Jim_SetVariableStr (Jim_Interp *interp,
const char *name, Jim_Obj *objPtr);
JIM_EXPORT int Jim_SetGlobalVariableStr (Jim_Interp *interp,
|
| ︙ | ︙ | |||
820 821 822 823 824 825 826 |
Jim_Obj *keyPtr, Jim_Obj **objPtrPtr, int flags);
JIM_EXPORT int Jim_DictKeysVector (Jim_Interp *interp,
Jim_Obj *dictPtr, Jim_Obj *const *keyv, int keyc,
Jim_Obj **objPtrPtr, int flags);
JIM_EXPORT int Jim_SetDictKeysVector (Jim_Interp *interp,
Jim_Obj *varNamePtr, Jim_Obj *const *keyv, int keyc,
Jim_Obj *newObjPtr, int flags);
| | | | 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 |
Jim_Obj *keyPtr, Jim_Obj **objPtrPtr, int flags);
JIM_EXPORT int Jim_DictKeysVector (Jim_Interp *interp,
Jim_Obj *dictPtr, Jim_Obj *const *keyv, int keyc,
Jim_Obj **objPtrPtr, int flags);
JIM_EXPORT int Jim_SetDictKeysVector (Jim_Interp *interp,
Jim_Obj *varNamePtr, Jim_Obj *const *keyv, int keyc,
Jim_Obj *newObjPtr, int flags);
JIM_EXPORT Jim_Obj **Jim_DictPairs(Jim_Interp *interp,
Jim_Obj *dictPtr, int *len);
JIM_EXPORT int Jim_DictAddElement(Jim_Interp *interp, Jim_Obj *objPtr,
Jim_Obj *keyObjPtr, Jim_Obj *valueObjPtr);
#define JIM_DICTMATCH_KEYS 0x0001
#define JIM_DICTMATCH_VALUES 0x002
JIM_EXPORT int Jim_DictMatchTypes(Jim_Interp *interp, Jim_Obj *objPtr, Jim_Obj *patternObj, int match_type, int return_types);
|
| ︙ | ︙ | |||
849 850 851 852 853 854 855 856 857 858 859 860 861 862 |
JIM_EXPORT int Jim_GetBoolean(Jim_Interp *interp, Jim_Obj *objPtr,
int *booleanPtr);
JIM_EXPORT int Jim_GetWide (Jim_Interp *interp, Jim_Obj *objPtr,
jim_wide *widePtr);
JIM_EXPORT int Jim_GetLong (Jim_Interp *interp, Jim_Obj *objPtr,
long *longPtr);
#define Jim_NewWideObj Jim_NewIntObj
JIM_EXPORT Jim_Obj * Jim_NewIntObj (Jim_Interp *interp,
jim_wide wideValue);
| > > | 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 |
JIM_EXPORT int Jim_GetBoolean(Jim_Interp *interp, Jim_Obj *objPtr,
int *booleanPtr);
JIM_EXPORT int Jim_GetWide (Jim_Interp *interp, Jim_Obj *objPtr,
jim_wide *widePtr);
JIM_EXPORT int Jim_GetWideExpr(Jim_Interp *interp, Jim_Obj *objPtr,
jim_wide *widePtr);
JIM_EXPORT int Jim_GetLong (Jim_Interp *interp, Jim_Obj *objPtr,
long *longPtr);
#define Jim_NewWideObj Jim_NewIntObj
JIM_EXPORT Jim_Obj * Jim_NewIntObj (Jim_Interp *interp,
jim_wide wideValue);
|
| ︙ | ︙ | |||
881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 |
typedef void (Jim_InterpDeleteProc)(Jim_Interp *interp, void *data);
JIM_EXPORT void * Jim_GetAssocData(Jim_Interp *interp, const char *key);
JIM_EXPORT int Jim_SetAssocData(Jim_Interp *interp, const char *key,
Jim_InterpDeleteProc *delProc, void *data);
JIM_EXPORT int Jim_DeleteAssocData(Jim_Interp *interp, const char *key);
JIM_EXPORT int Jim_PackageProvide (Jim_Interp *interp,
const char *name, const char *ver, int flags);
JIM_EXPORT int Jim_PackageRequire (Jim_Interp *interp,
const char *name, int flags);
JIM_EXPORT void Jim_MakeErrorMessage (Jim_Interp *interp);
JIM_EXPORT int Jim_InteractivePrompt (Jim_Interp *interp);
JIM_EXPORT void Jim_HistoryLoad(const char *filename);
JIM_EXPORT void Jim_HistorySave(const char *filename);
JIM_EXPORT char *Jim_HistoryGetline(Jim_Interp *interp, const char *prompt);
| > > > > > | > > > > | | 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 |
typedef void (Jim_InterpDeleteProc)(Jim_Interp *interp, void *data);
JIM_EXPORT void * Jim_GetAssocData(Jim_Interp *interp, const char *key);
JIM_EXPORT int Jim_SetAssocData(Jim_Interp *interp, const char *key,
Jim_InterpDeleteProc *delProc, void *data);
JIM_EXPORT int Jim_DeleteAssocData(Jim_Interp *interp, const char *key);
JIM_EXPORT int Jim_CheckAbiVersion(Jim_Interp *interp, int abi_version);
JIM_EXPORT int Jim_PackageProvide (Jim_Interp *interp,
const char *name, const char *ver, int flags);
JIM_EXPORT int Jim_PackageRequire (Jim_Interp *interp,
const char *name, int flags);
#define Jim_PackageProvideCheck(INTERP, NAME) \
if (Jim_CheckAbiVersion(INTERP, JIM_ABI_VERSION) == JIM_ERR || Jim_PackageProvide(INTERP, NAME, "1.0", JIM_ERRMSG)) \
return JIM_ERR
JIM_EXPORT void Jim_MakeErrorMessage (Jim_Interp *interp);
JIM_EXPORT int Jim_InteractivePrompt (Jim_Interp *interp);
JIM_EXPORT void Jim_HistoryLoad(const char *filename);
JIM_EXPORT void Jim_HistorySave(const char *filename);
JIM_EXPORT char *Jim_HistoryGetline(Jim_Interp *interp, const char *prompt);
JIM_EXPORT void Jim_HistorySetCompletion(Jim_Interp *interp, Jim_Obj *completionCommandObj);
JIM_EXPORT void Jim_HistorySetHints(Jim_Interp *interp, Jim_Obj *hintsCommandObj);
JIM_EXPORT void Jim_HistoryAdd(const char *line);
JIM_EXPORT void Jim_HistoryShow(void);
JIM_EXPORT void Jim_HistorySetMaxLen(int length);
JIM_EXPORT int Jim_HistoryGetMaxLen(void);
JIM_EXPORT int Jim_InitStaticExtensions(Jim_Interp *interp);
JIM_EXPORT int Jim_StringToWide(const char *str, jim_wide *widePtr, int base);
JIM_EXPORT int Jim_IsBigEndian(void);
#define Jim_CheckSignal(i) ((i)->signal_level && (i)->sigmask)
JIM_EXPORT void Jim_SignalSetIgnored(jim_wide mask);
JIM_EXPORT int Jim_LoadLibrary(Jim_Interp *interp, const char *pathName);
JIM_EXPORT void Jim_FreeLoadHandles(Jim_Interp *interp);
JIM_EXPORT int Jim_AioFilehandle(Jim_Interp *interp, Jim_Obj *command);
JIM_EXPORT int Jim_IsDict(Jim_Obj *objPtr);
JIM_EXPORT int Jim_IsList(Jim_Obj *objPtr);
#ifdef __cplusplus
}
|
| ︙ | ︙ | |||
950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 | const char *args; jim_subcmd_function *function; short minargs; short maxargs; unsigned short flags; } jim_subcmd_type; const jim_subcmd_type * Jim_ParseSubCmd(Jim_Interp *interp, const jim_subcmd_type *command_table, int argc, Jim_Obj *const *argv); int Jim_SubCmdProc(Jim_Interp *interp, int argc, Jim_Obj *const *argv); int Jim_CallSubCmd(Jim_Interp *interp, const jim_subcmd_type *ct, int argc, Jim_Obj *const *argv); #ifdef __cplusplus } #endif #endif #ifndef JIMREGEXP_H | > > > > > | 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 |
const char *args;
jim_subcmd_function *function;
short minargs;
short maxargs;
unsigned short flags;
} jim_subcmd_type;
#define JIM_DEF_SUBCMD(name, args, minargs, maxargs) { name, args, NULL, minargs, maxargs }
#define JIM_DEF_SUBCMD_HIDDEN(name, args, minargs, maxargs) { name, args, NULL, minargs, maxargs, JIM_MODFLAG_HIDDEN }
const jim_subcmd_type *
Jim_ParseSubCmd(Jim_Interp *interp, const jim_subcmd_type *command_table, int argc, Jim_Obj *const *argv);
int Jim_SubCmdProc(Jim_Interp *interp, int argc, Jim_Obj *const *argv);
int Jim_CallSubCmd(Jim_Interp *interp, const jim_subcmd_type *ct, int argc, Jim_Obj *const *argv);
void Jim_SubCmdArgError(Jim_Interp *interp, const jim_subcmd_type *ct, Jim_Obj *subcmd);
#ifdef __cplusplus
}
#endif
#endif
#ifndef JIMREGEXP_H
|
| ︙ | ︙ | |||
1032 1033 1034 1035 1036 1037 1038 | REG_ERR_UNMATCHED_BRACES, REG_ERR_BAD_COUNT, REG_ERR_JUNK_ON_END, REG_ERR_OPERAND_COULD_BE_EMPTY, REG_ERR_NESTED_COUNT, REG_ERR_INTERNAL, REG_ERR_COUNT_FOLLOWS_NOTHING, | | > | | | | | 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 | REG_ERR_UNMATCHED_BRACES, REG_ERR_BAD_COUNT, REG_ERR_JUNK_ON_END, REG_ERR_OPERAND_COULD_BE_EMPTY, REG_ERR_NESTED_COUNT, REG_ERR_INTERNAL, REG_ERR_COUNT_FOLLOWS_NOTHING, REG_ERR_INVALID_ESCAPE, REG_ERR_CORRUPTED, REG_ERR_NULL_CHAR, REG_ERR_UNMATCHED_BRACKET, REG_ERR_NUM }; int jim_regcomp(regex_t *preg, const char *regex, int cflags); int jim_regexec(regex_t *preg, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags); size_t jim_regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size); void jim_regfree(regex_t *preg); #ifdef __cplusplus } #endif #endif #ifndef JIM_SIGNAL_H |
| ︙ | ︙ | |||
1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 |
#endif
#ifndef JIMIOCOMPAT_H
#define JIMIOCOMPAT_H
#include <stdio.h>
#include <errno.h>
void Jim_SetResultErrno(Jim_Interp *interp, const char *msg);
int Jim_OpenForWrite(const char *filename, int append);
int Jim_OpenForRead(const char *filename);
#if defined(__MINGW32__)
#ifndef STRICT
#define STRICT
#endif
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <fcntl.h>
#include <io.h>
#include <process.h>
| > | < < | > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | | | < | | | > | | | > > > > > > > > < | > | < > | 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 |
#endif
#ifndef JIMIOCOMPAT_H
#define JIMIOCOMPAT_H
#include <stdio.h>
#include <errno.h>
#include <sys/stat.h>
void Jim_SetResultErrno(Jim_Interp *interp, const char *msg);
int Jim_OpenForWrite(const char *filename, int append);
int Jim_OpenForRead(const char *filename);
#if defined(__MINGW32__)
#ifndef STRICT
#define STRICT
#endif
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <fcntl.h>
#include <io.h>
#include <process.h>
typedef HANDLE phandle_t;
#define JIM_BAD_PHANDLE INVALID_HANDLE_VALUE
#define WIFEXITED(STATUS) (((STATUS) & 0xff00) == 0)
#define WEXITSTATUS(STATUS) ((STATUS) & 0x00ff)
#define WIFSIGNALED(STATUS) (((STATUS) & 0xff00) != 0)
#define WTERMSIG(STATUS) (((STATUS) >> 8) & 0xff)
#define WNOHANG 1
int Jim_Errno(void);
long waitpid(phandle_t phandle, int *status, int nohang);
phandle_t JimWaitPid(long processid, int *status, int nohang);
long JimProcessPid(phandle_t phandle);
#define HAVE_PIPE
#define pipe(P) _pipe((P), 0, O_NOINHERIT)
typedef struct __stat64 jim_stat_t;
#define Jim_Stat _stat64
#define Jim_FileStat _fstat64
#define Jim_Lseek _lseeki64
#else
#if defined(HAVE_STAT64)
typedef struct stat64 jim_stat_t;
#define Jim_Stat stat64
#if defined(HAVE_FSTAT64)
#define Jim_FileStat fstat64
#endif
#if defined(HAVE_LSTAT64)
#define Jim_LinkStat lstat64
#endif
#else
typedef struct stat jim_stat_t;
#define Jim_Stat stat
#if defined(HAVE_FSTAT)
#define Jim_FileStat fstat
#endif
#if defined(HAVE_LSTAT)
#define Jim_LinkStat lstat
#endif
#endif
#if defined(HAVE_LSEEK64)
#define Jim_Lseek lseek64
#else
#define Jim_Lseek lseek
#endif
#if defined(HAVE_UNISTD_H)
#include <unistd.h>
#include <fcntl.h>
#include <sys/wait.h>
typedef int phandle_t;
#define Jim_Errno() errno
#define JIM_BAD_PHANDLE -1
#define JimProcessPid(PIDTYPE) (PIDTYPE)
#define JimWaitPid waitpid
#ifndef HAVE_EXECVPE
#define execvpe(ARG0, ARGV, ENV) execvp(ARG0, ARGV)
#endif
#endif
#endif
#ifndef O_TEXT
#define O_TEXT 0
#endif
int Jim_FileStoreStatData(Jim_Interp *interp, Jim_Obj *varName, const jim_stat_t *sb);
#endif
int Jim_bootstrapInit(Jim_Interp *interp)
{
if (Jim_PackageProvide(interp, "bootstrap", "1.0", JIM_ERRMSG))
return JIM_ERR;
return Jim_EvalSource(interp, "bootstrap.tcl", 1,
"\n"
"proc package {cmd args} {\n"
" if {$cmd eq \"require\"} {\n"
" foreach path $::auto_path {\n"
" lassign $args pkg\n"
" set pkgpath $path/$pkg.tcl\n"
" if {$path eq \".\"} {\n"
" set pkgpath $pkg.tcl\n"
" }\n"
" if {[file exists $pkgpath]} {\n"
" tailcall uplevel #0 [list source $pkgpath]\n"
" }\n"
" }\n"
" }\n"
"}\n"
"set tcl_platform(bootstrap) 1\n"
);
}
int Jim_initjimshInit(Jim_Interp *interp)
{
if (Jim_PackageProvide(interp, "initjimsh", "1.0", JIM_ERRMSG))
return JIM_ERR;
|
| ︙ | ︙ | |||
1197 1198 1199 1200 1201 1202 1203 |
"}\n"
"\n"
"if {$tcl_platform(platform) eq \"windows\"} {\n"
" set jim::argv0 [string map {\\\\ /} $jim::argv0]\n"
"}\n"
"\n"
"\n"
| | | 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 |
"}\n"
"\n"
"if {$tcl_platform(platform) eq \"windows\"} {\n"
" set jim::argv0 [string map {\\\\ /} $jim::argv0]\n"
"}\n"
"\n"
"\n"
"set tcl::autocomplete_commands {array clock debug dict file history info namespace package signal socket string tcl::prefix zlib}\n"
"\n"
"\n"
"\n"
"proc tcl::autocomplete {prefix} {\n"
" if {[set space [string first \" \" $prefix]] != -1} {\n"
" set cmd [string range $prefix 0 $space-1]\n"
" if {$cmd in $::tcl::autocomplete_commands || [info channel $cmd] ne \"\"} {\n"
|
| ︙ | ︙ | |||
1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 |
" if {[string match \"* *\" $p]} {\n"
" continue\n"
" }\n"
" function $p\n"
" }]\n"
"}\n"
"\n"
"_jimsh_init\n"
);
}
int Jim_globInit(Jim_Interp *interp)
{
if (Jim_PackageProvide(interp, "glob", "1.0", JIM_ERRMSG))
return JIM_ERR;
| > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 |
" if {[string match \"* *\" $p]} {\n"
" continue\n"
" }\n"
" function $p\n"
" }]\n"
"}\n"
"\n"
"\n"
"set tcl::stdhint_commands {array clock debug dict file history info namespace package signal string zlib}\n"
"\n"
"set tcl::stdhint_cols {\n"
" none {0}\n"
" black {30}\n"
" red {31}\n"
" green {32}\n"
" yellow {33}\n"
" blue {34}\n"
" purple {35}\n"
" cyan {36}\n"
" normal {37}\n"
" grey {30 1}\n"
" gray {30 1}\n"
" lred {31 1}\n"
" lgreen {32 1}\n"
" lyellow {33 1}\n"
" lblue {34 1}\n"
" lpurple {35 1}\n"
" lcyan {36 1}\n"
" white {37 1}\n"
"}\n"
"\n"
"\n"
"set tcl::stdhint_col $tcl::stdhint_cols(lcyan)\n"
"\n"
"\n"
"proc tcl::stdhint {string} {\n"
" set result \"\"\n"
" if {[llength $string] >= 2} {\n"
" lassign $string cmd arg\n"
" if {$cmd in $::tcl::stdhint_commands || [info channel $cmd] ne \"\"} {\n"
" catch {\n"
" set help [$cmd -help $arg]\n"
" if {[string match \"Usage: $cmd *\" $help]} {\n"
" set n [llength $string]\n"
" set subcmd [lindex $help $n]\n"
" incr n\n"
" set hint [join [lrange $help $n end]]\n"
" set prefix \"\"\n"
" if {![string match \"* \" $string]} {\n"
" if {$n == 3 && $subcmd ne $arg} {\n"
"\n"
" set prefix \"[string range $subcmd [string length $arg] end] \"\n"
" } else {\n"
" set prefix \" \"\n"
" }\n"
" }\n"
" set result [list $prefix$hint {*}$::tcl::stdhint_col]\n"
" }\n"
" }\n"
" }\n"
" }\n"
" return $result\n"
"}\n"
"\n"
"_jimsh_init\n"
);
}
int Jim_globInit(Jim_Interp *interp)
{
if (Jim_PackageProvide(interp, "glob", "1.0", JIM_ERRMSG))
return JIM_ERR;
|
| ︙ | ︙ | |||
1478 1479 1480 1481 1482 1483 1484 |
"\n"
"\n"
"proc function {value} {\n"
" return $value\n"
"}\n"
"\n"
"\n"
| < < < < < < < < < < < < > | < < | | < | | > > > > > > > > | > < < | | 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 |
"\n"
"\n"
"proc function {value} {\n"
" return $value\n"
"}\n"
"\n"
"\n"
"proc stackdump {stacktrace} {\n"
" set lines {}\n"
" lappend lines \"Traceback (most recent call last):\"\n"
" foreach {cmd l f p} [lreverse $stacktrace] {\n"
" set line {}\n"
" if {$f ne \"\"} {\n"
" append line \" File \\\"$f\\\", line $l\"\n"
" }\n"
" if {$p ne \"\"} {\n"
" append line \", in $p\"\n"
" }\n"
" if {$line ne \"\"} {\n"
" lappend lines $line\n"
" if {$cmd ne \"\"} {\n"
" set nl [string first \\n $cmd 1]\n"
" if {$nl >= 0} {\n"
" set cmd [string range $cmd 0 $nl-1]...\n"
" }\n"
" lappend lines \" $cmd\"\n"
" }\n"
" }\n"
" }\n"
" if {[llength $lines] > 1} {\n"
" return [join $lines \\n]\n"
" }\n"
"}\n"
"\n"
"\n"
"\n"
"proc defer {script} {\n"
" upvar jim::defer v\n"
" lappend v $script\n"
"}\n"
"\n"
"\n"
"\n"
"proc errorInfo {msg {stacktrace \"\"}} {\n"
" if {$stacktrace eq \"\"} {\n"
"\n"
" set stacktrace [info stacktrace]\n"
" }\n"
" lassign $stacktrace p f l cmd\n"
" if {$f ne \"\"} {\n"
" set result \"$f:$l: Error: \"\n"
" }\n"
" append result \"$msg\\n\"\n"
" append result [stackdump $stacktrace]\n"
"\n"
"\n"
|
| ︙ | ︙ | |||
1639 1640 1641 1642 1643 1644 1645 | "\n" "\n" "\n" "\n" "set env [env]\n" "\n" "\n" | | | 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 |
"\n"
"\n"
"\n"
"\n"
"set env [env]\n"
"\n"
"\n"
"if {[exists -command stdout]} {\n"
"\n"
" foreach p {gets flush close eof seek tell} {\n"
" proc $p {chan args} {p} {\n"
" tailcall $chan $p {*}$args\n"
" }\n"
" }\n"
" unset p\n"
|
| ︙ | ︙ | |||
1813 1814 1815 1816 1817 1818 1819 | " return \"\"\n" " }\n" " return $pids\n" "}\n" "\n" "\n" "\n" | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < > > > > > > > < < > | | < | | | | > > > > > > > > > > > > | > > > > | > > > | > > > > > > > > > > > > > > > | < < | | > < < < > > | | | | | < | > > > > > > > > | | < > | > | < | < < | > | < | | > < | > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | | 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 |
" return \"\"\n"
" }\n"
" return $pids\n"
"}\n"
"\n"
"\n"
"\n"
"proc throw {code {msg \"\"}} {\n"
" return -code $code $msg\n"
"}\n"
"\n"
"\n"
"proc {file delete force} {path} {\n"
" foreach e [readdir $path] {\n"
" file delete -force $path/$e\n"
" }\n"
" file delete $path\n"
"}\n"
);
}
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <assert.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#include <sys/stat.h>
#endif
#ifdef HAVE_UTIL_H
#include <util.h>
#endif
#ifdef HAVE_PTY_H
#include <pty.h>
#endif
#if defined(HAVE_SYS_SOCKET_H) && defined(HAVE_SELECT) && defined(HAVE_NETINET_IN_H) && defined(HAVE_NETDB_H) && defined(HAVE_ARPA_INET_H)
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <netdb.h>
#ifdef HAVE_SYS_UN_H
#include <sys/un.h>
#endif
#define HAVE_SOCKETS
#elif defined (__MINGW32__)
#endif
#if defined(JIM_SSL)
#include <openssl/ssl.h>
#include <openssl/err.h>
#endif
#ifdef HAVE_TERMIOS_H
#endif
#define AIO_CMD_LEN 32
#define AIO_BUF_LEN 256
#define AIO_WBUF_FULL_SIZE (64 * 1024)
#define AIO_KEEPOPEN 1
#define AIO_NODELETE 2
#define AIO_EOF 4
#define AIO_WBUF_NONE 8
#define AIO_NONBLOCK 16
enum wbuftype {
WBUF_OPT_NONE,
WBUF_OPT_LINE,
WBUF_OPT_FULL,
};
#if defined(JIM_IPV6)
#define IPV6 1
#else
#define IPV6 0
#ifndef PF_INET6
#define PF_INET6 0
#endif
#endif
#if defined(HAVE_SYS_UN_H) && defined(PF_UNIX)
#define UNIX_SOCKETS 1
#else
#define UNIX_SOCKETS 0
#endif
#ifndef MAXPATHLEN
#define MAXPATHLEN JIM_PATH_LEN
#endif
static int JimReadableTimeout(int fd, long ms)
{
#ifdef HAVE_SELECT
int retval;
struct timeval tv;
fd_set rfds;
FD_ZERO(&rfds);
FD_SET(fd, &rfds);
tv.tv_sec = ms / 1000;
tv.tv_usec = (ms % 1000) * 1000;
retval = select(fd + 1, &rfds, NULL, NULL, ms == 0 ? NULL : &tv);
if (retval > 0) {
return JIM_OK;
}
return JIM_ERR;
#else
return JIM_OK;
#endif
}
struct AioFile;
typedef struct {
int (*writer)(struct AioFile *af, const char *buf, int len);
int (*reader)(struct AioFile *af, char *buf, int len, int pending);
int (*error)(const struct AioFile *af);
const char *(*strerror)(struct AioFile *af);
int (*verify)(struct AioFile *af);
} JimAioFopsType;
typedef struct AioFile
{
Jim_Obj *filename;
int wbuft;
int flags;
long timeout;
int fd;
int addr_family;
void *ssl;
const JimAioFopsType *fops;
Jim_Obj *readbuf;
Jim_Obj *writebuf;
} AioFile;
static int stdio_writer(struct AioFile *af, const char *buf, int len)
{
return write(af->fd, buf, len);
}
static int stdio_reader(struct AioFile *af, char *buf, int len, int nb)
{
if (nb || af->timeout == 0 || JimReadableTimeout(af->fd, af->timeout) == JIM_OK) {
int ret;
errno = 0;
ret = read(af->fd, buf, len);
if (ret <= 0 && errno != EAGAIN && errno != EINTR) {
af->flags |= AIO_EOF;
}
return ret;
}
errno = ETIMEDOUT;
return -1;
}
static int stdio_error(const AioFile *af)
{
if (af->flags & AIO_EOF) {
return JIM_OK;
}
switch (errno) {
case EAGAIN:
case EINTR:
case ETIMEDOUT:
#ifdef ECONNRESET
case ECONNRESET:
#endif
#ifdef ECONNABORTED
case ECONNABORTED:
#endif
return JIM_OK;
default:
return JIM_ERR;
}
}
static const char *stdio_strerror(struct AioFile *af)
{
return strerror(errno);
}
static const JimAioFopsType stdio_fops = {
stdio_writer,
stdio_reader,
stdio_error,
stdio_strerror,
NULL,
};
static void aio_set_nonblocking(AioFile *af, int nb)
{
#ifdef O_NDELAY
int old = !!(af->flags & AIO_NONBLOCK);
if (old != nb) {
int fmode = fcntl(af->fd, F_GETFL);
if (nb) {
fmode |= O_NDELAY;
af->flags |= AIO_NONBLOCK;
}
else {
fmode &= ~O_NDELAY;
af->flags &= ~AIO_NONBLOCK;
}
(void)fcntl(af->fd, F_SETFL, fmode);
}
#endif
}
static int aio_start_nonblocking(AioFile *af)
{
int old = !!(af->flags & AIO_NONBLOCK);
if (af->timeout) {
aio_set_nonblocking(af, 1);
}
return old;
}
static int JimAioSubCmdProc(Jim_Interp *interp, int argc, Jim_Obj *const *argv);
static AioFile *JimMakeChannel(Jim_Interp *interp, int fd, Jim_Obj *filename,
const char *hdlfmt, int family, int flags);
static const char *JimAioErrorString(AioFile *af)
{
if (af && af->fops)
return af->fops->strerror(af);
|
| ︙ | ︙ | |||
2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 |
if (name) {
Jim_SetResultFormatted(interp, "%#s: %s", name, JimAioErrorString(af));
}
else {
Jim_SetResultString(interp, JimAioErrorString(af), -1);
}
}
static int JimCheckStreamError(Jim_Interp *interp, AioFile *af)
{
| > > > > > > > | | | | > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | > > > < < > > > > > > > > > > > > > | > > | | < | < > > | | | | | | | > > > | < < < < < < | < < > | > | | < < < | < < | | | < < < | > | | | | | | | | | > > > > | | < < < < < < < < < < < < | | > > | < < < > | > > > > > > > > > > > > > > > > > > > > > > > | > | > > | > | > | > > | | | > > > > > > > > | > > > > > > > | > > | > > > | > | | < < | | < | | > | | > | < > | > | | > > > | > > > > > > > > > | > > | > > | > | > > | > | > > > > > > | > > > | | | < < < < < | > > | | | < < > > > > > | | | | > | > > > > > > | > > | | | > > > > | | 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 |
if (name) {
Jim_SetResultFormatted(interp, "%#s: %s", name, JimAioErrorString(af));
}
else {
Jim_SetResultString(interp, JimAioErrorString(af), -1);
}
}
static int aio_eof(AioFile *af)
{
return af->flags & AIO_EOF;
}
static int JimCheckStreamError(Jim_Interp *interp, AioFile *af)
{
int ret = 0;
if (!aio_eof(af)) {
ret = af->fops->error(af);
if (ret) {
JimAioSetError(interp, af->filename);
}
}
return ret;
}
static void aio_consume(Jim_Obj *objPtr, int n)
{
assert(objPtr->bytes);
assert(n <= objPtr->length);
memmove(objPtr->bytes, objPtr->bytes + n, objPtr->length - n + 1);
objPtr->length -= n;
}
static int aio_autoflush(Jim_Interp *interp, void *clientData, int mask);
static int aio_flush(Jim_Interp *interp, AioFile *af)
{
int len;
const char *pt = Jim_GetString(af->writebuf, &len);
if (len) {
int ret = af->fops->writer(af, pt, len);
if (ret > 0) {
aio_consume(af->writebuf, ret);
}
if (ret < 0) {
return JimCheckStreamError(interp, af);
}
if (Jim_Length(af->writebuf)) {
#ifdef jim_ext_eventloop
void *handler = Jim_FindFileHandler(interp, af->fd, JIM_EVENT_WRITABLE);
if (handler == NULL) {
Jim_CreateFileHandler(interp, af->fd, JIM_EVENT_WRITABLE, aio_autoflush, af, NULL);
return JIM_OK;
}
else if (handler == af) {
return JIM_OK;
}
#endif
Jim_SetResultString(interp, "send buffer is full", -1);
return JIM_ERR;
}
}
return JIM_OK;
}
static int aio_autoflush(Jim_Interp *interp, void *clientData, int mask)
{
AioFile *af = clientData;
aio_flush(interp, af);
if (Jim_Length(af->writebuf) == 0) {
return -1;
}
return 0;
}
static int aio_read_len(Jim_Interp *interp, AioFile *af, int nb, char *buf, size_t buflen, int neededLen)
{
if (!af->readbuf) {
af->readbuf = Jim_NewStringObj(interp, NULL, 0);
}
if (neededLen >= 0) {
neededLen -= Jim_Length(af->readbuf);
if (neededLen <= 0) {
return JIM_OK;
}
}
while (neededLen && !aio_eof(af)) {
int retval;
int readlen;
if (neededLen == -1) {
readlen = AIO_BUF_LEN;
}
else {
readlen = (neededLen > AIO_BUF_LEN ? AIO_BUF_LEN : neededLen);
}
retval = af->fops->reader(af, buf, readlen, nb);
if (retval > 0) {
Jim_AppendString(interp, af->readbuf, buf, retval);
if (neededLen != -1) {
neededLen -= retval;
}
continue;
}
if (JimCheckStreamError(interp, af)) {
return JIM_ERR;
}
if (nb || af->timeout) {
return JIM_OK;
}
}
return JIM_OK;
}
static Jim_Obj *aio_read_consume(Jim_Interp *interp, AioFile *af, int neededLen)
{
Jim_Obj *objPtr = NULL;
if (neededLen < 0 || af->readbuf == NULL || Jim_Length(af->readbuf) <= neededLen) {
objPtr = af->readbuf;
af->readbuf = NULL;
}
else if (af->readbuf) {
int len;
const char *pt = Jim_GetString(af->readbuf, &len);
objPtr = Jim_NewStringObj(interp, pt, neededLen);
aio_consume(af->readbuf, neededLen);
}
return objPtr;
}
static void JimAioDelProc(Jim_Interp *interp, void *privData)
{
AioFile *af = privData;
JIM_NOTUSED(interp);
aio_flush(interp, af);
Jim_DecrRefCount(interp, af->writebuf);
#if UNIX_SOCKETS
if (af->addr_family == PF_UNIX && (af->flags & AIO_NODELETE) == 0) {
Jim_Obj *filenameObj = aio_sockname(interp, af->fd);
if (filenameObj) {
if (Jim_Length(filenameObj)) {
remove(Jim_String(filenameObj));
}
Jim_FreeNewObj(interp, filenameObj);
}
}
#endif
Jim_DecrRefCount(interp, af->filename);
#ifdef jim_ext_eventloop
Jim_DeleteFileHandler(interp, af->fd, JIM_EVENT_READABLE | JIM_EVENT_WRITABLE | JIM_EVENT_EXCEPTION);
#endif
#if defined(JIM_SSL)
if (af->ssl != NULL) {
SSL_free(af->ssl);
}
#endif
if (!(af->flags & AIO_KEEPOPEN)) {
close(af->fd);
}
if (af->readbuf) {
Jim_FreeNewObj(interp, af->readbuf);
}
Jim_Free(af);
}
static int aio_cmd_read(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
AioFile *af = Jim_CmdPrivData(interp);
int nonewline = 0;
jim_wide neededLen = -1;
static const char * const options[] = { "-pending", "-nonewline", NULL };
enum { OPT_PENDING, OPT_NONEWLINE };
int option;
int nb;
Jim_Obj *objPtr;
char buf[AIO_BUF_LEN];
if (argc) {
if (*Jim_String(argv[0]) == '-') {
if (Jim_GetEnum(interp, argv[0], options, &option, NULL, JIM_ERRMSG) != JIM_OK) {
return JIM_ERR;
}
switch (option) {
case OPT_PENDING:
break;
case OPT_NONEWLINE:
nonewline++;
break;
}
}
else {
if (Jim_GetWide(interp, argv[0], &neededLen) != JIM_OK)
return JIM_ERR;
if (neededLen < 0) {
Jim_SetResultString(interp, "invalid parameter: negative len", -1);
return JIM_ERR;
}
}
argc--;
argv++;
}
if (argc) {
return -1;
}
nb = aio_start_nonblocking(af);
if (aio_read_len(interp, af, nb, buf, sizeof(buf), neededLen) != JIM_OK) {
aio_set_nonblocking(af, nb);
return JIM_ERR;
}
objPtr = aio_read_consume(interp, af, neededLen);
aio_set_nonblocking(af, nb);
if (objPtr) {
if (nonewline) {
int len;
const char *s = Jim_GetString(objPtr, &len);
if (len > 0 && s[len - 1] == '\n') {
objPtr->length--;
objPtr->bytes[objPtr->length] = '\0';
}
}
Jim_SetResult(interp, objPtr);
}
else {
Jim_SetEmptyResult(interp);
}
return JIM_OK;
}
int Jim_AioFilehandle(Jim_Interp *interp, Jim_Obj *command)
{
Jim_Cmd *cmdPtr = Jim_GetCommand(interp, command, JIM_ERRMSG);
if (cmdPtr && !cmdPtr->isproc && cmdPtr->u.native.cmdProc == JimAioSubCmdProc) {
return ((AioFile *) cmdPtr->u.native.privData)->fd;
}
Jim_SetResultFormatted(interp, "Not a filehandle: \"%#s\"", command);
return -1;
}
static int aio_cmd_getfd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
AioFile *af = Jim_CmdPrivData(interp);
aio_flush(interp, af);
Jim_SetResultInt(interp, af->fd);
return JIM_OK;
}
static int aio_cmd_copy(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
AioFile *af = Jim_CmdPrivData(interp);
jim_wide count = 0;
jim_wide maxlen = JIM_WIDE_MAX;
char buf[AIO_BUF_LEN];
char *bufp = buf;
int buflen = sizeof(buf);
int ok = 1;
Jim_Obj *objv[4];
if (argc == 2) {
if (Jim_GetWide(interp, argv[1], &maxlen) != JIM_OK) {
return JIM_ERR;
}
}
objv[0] = argv[0];
objv[1] = Jim_NewStringObj(interp, "flush", -1);
if (Jim_EvalObjVector(interp, 2, objv) != JIM_OK) {
Jim_SetResultFormatted(interp, "Not a filehandle: \"%#s\"", argv[0]);
return JIM_ERR;
}
objv[0] = argv[0];
objv[1] = Jim_NewStringObj(interp, "puts", -1);
objv[2] = Jim_NewStringObj(interp, "-nonewline", -1);
Jim_IncrRefCount(objv[1]);
Jim_IncrRefCount(objv[2]);
while (count < maxlen) {
jim_wide len = maxlen - count;
if (len > buflen) {
len = buflen;
}
if (aio_read_len(interp, af, 0, bufp, buflen, len) != JIM_OK) {
ok = 0;
break;
}
objv[3] = aio_read_consume(interp, af, len);
count += Jim_Length(objv[3]);
if (Jim_EvalObjVector(interp, 4, objv) != JIM_OK) {
ok = 0;
break;
}
if (aio_eof(af)) {
break;
}
if (count >= 16384 && bufp == buf) {
buflen = 65536;
bufp = Jim_Alloc(buflen);
}
}
if (bufp != buf) {
Jim_Free(bufp);
}
Jim_DecrRefCount(interp, objv[1]);
Jim_DecrRefCount(interp, objv[2]);
if (!ok) {
return JIM_ERR;
}
Jim_SetResultInt(interp, count);
return JIM_OK;
}
static int aio_cmd_gets(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
AioFile *af = Jim_CmdPrivData(interp);
char buf[AIO_BUF_LEN];
Jim_Obj *objPtr = NULL;
int len;
int nb;
char *nl = NULL;
int offset = 0;
errno = 0;
nb = aio_start_nonblocking(af);
if (!af->readbuf) {
af->readbuf = Jim_NewStringObj(interp, NULL, 0);
}
while (!aio_eof(af)) {
const char *pt = Jim_GetString(af->readbuf, &len);
nl = memchr(pt + offset, '\n', len - offset);
if (nl) {
objPtr = Jim_NewStringObj(interp, pt, nl - pt);
aio_consume(af->readbuf, nl - pt + 1);
break;
}
offset = len;
len = af->fops->reader(af, buf, AIO_BUF_LEN, nb);
if (len <= 0) {
if (nb || af->timeout) {
break;
}
}
else {
Jim_AppendString(interp, af->readbuf, buf, len);
}
}
aio_set_nonblocking(af, nb);
if (!nl && aio_eof(af)) {
objPtr = af->readbuf;
af->readbuf = NULL;
}
else if (!objPtr) {
objPtr = Jim_NewStringObj(interp, NULL, 0);
}
if (argc) {
if (Jim_SetVariable(interp, argv[0], objPtr) != JIM_OK) {
Jim_FreeNewObj(interp, objPtr);
return JIM_ERR;
}
len = Jim_Length(objPtr);
if (!nl && len == 0) {
len = -1;
}
Jim_SetResultInt(interp, len);
}
else {
Jim_SetResult(interp, objPtr);
}
return JIM_OK;
}
static int aio_cmd_puts(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
AioFile *af = Jim_CmdPrivData(interp);
int wlen;
const char *wdata;
Jim_Obj *strObj;
int wnow = 0;
int nl = 1;
if (argc == 2) {
if (!Jim_CompareStringImmediate(interp, argv[0], "-nonewline")) {
return -1;
}
strObj = argv[1];
nl = 0;
}
else {
strObj = argv[0];
}
Jim_AppendObj(interp, af->writebuf, strObj);
if (nl) {
Jim_AppendString(interp, af->writebuf, "\n", 1);
}
wdata = Jim_GetString(af->writebuf, &wlen);
switch (af->wbuft) {
case WBUF_OPT_NONE:
wnow = 1;
break;
case WBUF_OPT_LINE:
if (nl || memchr(wdata, '\n', wlen) != NULL) {
wnow = 1;
}
break;
case WBUF_OPT_FULL:
if (wlen >= AIO_WBUF_FULL_SIZE) {
wnow = 1;
}
break;
}
if (wnow) {
return aio_flush(interp, af);
}
return JIM_OK;
}
static int aio_cmd_isatty(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
#ifdef HAVE_ISATTY
AioFile *af = Jim_CmdPrivData(interp);
Jim_SetResultInt(interp, isatty(af->fd));
#else
Jim_SetResultInt(interp, 0);
#endif
return JIM_OK;
}
static int aio_cmd_flush(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
AioFile *af = Jim_CmdPrivData(interp);
return aio_flush(interp, af);
}
static int aio_cmd_eof(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
AioFile *af = Jim_CmdPrivData(interp);
Jim_SetResultInt(interp, !!aio_eof(af));
return JIM_OK;
}
static int aio_cmd_close(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
AioFile *af = Jim_CmdPrivData(interp);
if (argc == 3) {
int option = -1;
#if defined(HAVE_SOCKETS)
static const char * const options[] = { "r", "w", "-nodelete", NULL };
enum { OPT_R, OPT_W, OPT_NODELETE };
if (Jim_GetEnum(interp, argv[2], options, &option, NULL, JIM_ERRMSG) != JIM_OK) {
return JIM_ERR;
}
#endif
switch (option) {
#if defined(HAVE_SHUTDOWN)
case OPT_R:
case OPT_W:
if (shutdown(af->fd, option == OPT_R ? SHUT_RD : SHUT_WR) == 0) {
return JIM_OK;
}
JimAioSetError(interp, NULL);
return JIM_ERR;
#endif
#if UNIX_SOCKETS
case OPT_NODELETE:
if (af->addr_family == PF_UNIX) {
af->flags |= AIO_NODELETE;
break;
}
#endif
default:
Jim_SetResultString(interp, "not supported", -1);
return JIM_ERR;
}
}
af->flags &= ~AIO_KEEPOPEN;
return Jim_DeleteCommand(interp, argv[0]);
}
static int aio_cmd_seek(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
AioFile *af = Jim_CmdPrivData(interp);
int orig = SEEK_SET;
jim_wide offset;
|
| ︙ | ︙ | |||
2395 2396 2397 2398 2399 2400 2401 |
else {
return -1;
}
}
if (Jim_GetWide(interp, argv[0], &offset) != JIM_OK) {
return JIM_ERR;
}
| > > > > | > > > > > | < < < < < | < | < < | | > > | > > > | | < < < | | | | | | | < > | | | | < < | | > > > > > > < < < < < < < < < < < < < < < | > | | < | | < | | < < < < < < < < | | | > > > > > > > > > > > > > > | | 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 |
else {
return -1;
}
}
if (Jim_GetWide(interp, argv[0], &offset) != JIM_OK) {
return JIM_ERR;
}
if (orig != SEEK_CUR || offset != 0) {
aio_flush(interp, af);
}
if (Jim_Lseek(af->fd, offset, orig) == -1) {
JimAioSetError(interp, af->filename);
return JIM_ERR;
}
if (af->readbuf) {
Jim_FreeNewObj(interp, af->readbuf);
af->readbuf = NULL;
}
af->flags &= ~AIO_EOF;
return JIM_OK;
}
static int aio_cmd_tell(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
AioFile *af = Jim_CmdPrivData(interp);
Jim_SetResultInt(interp, Jim_Lseek(af->fd, 0, SEEK_CUR));
return JIM_OK;
}
static int aio_cmd_filename(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
AioFile *af = Jim_CmdPrivData(interp);
Jim_SetResult(interp, af->filename);
return JIM_OK;
}
#ifdef O_NDELAY
static int aio_cmd_ndelay(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
AioFile *af = Jim_CmdPrivData(interp);
if (argc) {
long nb;
if (Jim_GetLong(interp, argv[0], &nb) != JIM_OK) {
return JIM_ERR;
}
aio_set_nonblocking(af, nb);
}
Jim_SetResultInt(interp, (af->flags & AIO_NONBLOCK) ? 1 : 0);
return JIM_OK;
}
#endif
#ifdef HAVE_FSYNC
static int aio_cmd_sync(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
AioFile *af = Jim_CmdPrivData(interp);
if (aio_flush(interp, af) != JIM_OK) {
return JIM_ERR;
}
fsync(af->fd);
return JIM_OK;
}
#endif
static int aio_cmd_buffering(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
AioFile *af = Jim_CmdPrivData(interp);
static const char * const options[] = {
"none",
"line",
"full",
NULL
};
if (Jim_GetEnum(interp, argv[0], options, &af->wbuft, NULL, JIM_ERRMSG) != JIM_OK) {
return JIM_ERR;
}
if (af->wbuft == WBUF_OPT_NONE) {
return aio_flush(interp, af);
}
return JIM_OK;
}
static int aio_cmd_timeout(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
#ifdef HAVE_SELECT
AioFile *af = Jim_CmdPrivData(interp);
if (argc == 1) {
if (Jim_GetLong(interp, argv[0], &af->timeout) != JIM_OK) {
return JIM_ERR;
}
}
Jim_SetResultInt(interp, af->timeout);
return JIM_OK;
#else
Jim_SetResultString(interp, "timeout not supported", -1);
return JIM_ERR;
#endif
}
#ifdef jim_ext_eventloop
static int aio_eventinfo(Jim_Interp *interp, AioFile * af, unsigned mask,
int argc, Jim_Obj * const *argv)
{
if (argc == 0) {
Jim_Obj *objPtr = Jim_FindFileHandler(interp, af->fd, mask);
if (objPtr) {
Jim_SetResult(interp, objPtr);
}
return JIM_OK;
}
Jim_DeleteFileHandler(interp, af->fd, mask);
if (Jim_Length(argv[0])) {
Jim_CreateScriptFileHandler(interp, af->fd, mask, argv[0]);
}
return JIM_OK;
}
static int aio_cmd_readable(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
AioFile *af = Jim_CmdPrivData(interp);
return aio_eventinfo(interp, af, JIM_EVENT_READABLE, argc, argv);
}
static int aio_cmd_writable(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
AioFile *af = Jim_CmdPrivData(interp);
return aio_eventinfo(interp, af, JIM_EVENT_WRITABLE, argc, argv);
}
static int aio_cmd_onexception(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
AioFile *af = Jim_CmdPrivData(interp);
return aio_eventinfo(interp, af, JIM_EVENT_EXCEPTION, argc, argv);
}
#endif
#if defined(jim_ext_file) && defined(Jim_FileStat)
static int aio_cmd_stat(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
jim_stat_t sb;
AioFile *af = Jim_CmdPrivData(interp);
if (Jim_FileStat(af->fd, &sb) == -1) {
JimAioSetError(interp, NULL);
return JIM_ERR;
}
return Jim_FileStoreStatData(interp, argc == 0 ? NULL : argv[0], &sb);
}
#endif
static const jim_subcmd_type aio_command_table[] = {
{ "read",
"?-nonewline|len?",
aio_cmd_read,
0,
2,
},
{ "copyto",
"handle ?size?",
|
| ︙ | ︙ | |||
2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 |
{ "buffering",
"none|line|full",
aio_cmd_buffering,
1,
1,
},
#ifdef jim_ext_eventloop
{ "readable",
"?readable-script?",
aio_cmd_readable,
0,
1,
| > > > > > > > > > | 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 |
{ "buffering",
"none|line|full",
aio_cmd_buffering,
1,
1,
},
#if defined(jim_ext_file) && defined(Jim_FileStat)
{ "stat",
"?var?",
aio_cmd_stat,
0,
1,
},
#endif
#ifdef jim_ext_eventloop
{ "readable",
"?readable-script?",
aio_cmd_readable,
0,
1,
|
| ︙ | ︙ | |||
2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 |
},
{ "onexception",
"?exception-script?",
aio_cmd_onexception,
0,
1,
},
#endif
{ NULL }
};
static int JimAioSubCmdProc(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
return Jim_CallSubCmd(interp, Jim_ParseSubCmd(interp, aio_command_table, argc, argv), argc, argv);
}
static int JimAioOpenCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
| > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > | | | < > | | > | | > | > > > > > > > > > > > > > > | > | | | | < < < < < | < < < < < < | < < < < < < < < < < < < < < < < < < < | > > > > > > > > > > > > > > | > | | | > | | | | | | | < < < < < < | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 |
},
{ "onexception",
"?exception-script?",
aio_cmd_onexception,
0,
1,
},
{ "timeout",
"?ms?",
aio_cmd_timeout,
0,
1,
},
#endif
{ NULL }
};
static int JimAioSubCmdProc(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
return Jim_CallSubCmd(interp, Jim_ParseSubCmd(interp, aio_command_table, argc, argv), argc, argv);
}
static int parse_posix_open_mode(Jim_Interp *interp, Jim_Obj *modeObj)
{
int i;
int flags = 0;
#ifndef O_NOCTTY
#define O_NOCTTY 0
#endif
static const char * const modetypes[] = {
"RDONLY", "WRONLY", "RDWR", "APPEND", "BINARY", "CREAT", "EXCL", "NOCTTY", "TRUNC", NULL
};
static const int modeflags[] = {
O_RDONLY, O_WRONLY, O_RDWR, O_APPEND, 0, O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC,
};
for (i = 0; i < Jim_ListLength(interp, modeObj); i++) {
int opt;
Jim_Obj *objPtr = Jim_ListGetIndex(interp, modeObj, i);
if (Jim_GetEnum(interp, objPtr, modetypes, &opt, "access mode", JIM_ERRMSG) != JIM_OK) {
return -1;
}
flags |= modeflags[opt];
}
return flags;
}
static int parse_open_mode(Jim_Interp *interp, Jim_Obj *filenameObj, Jim_Obj *modeObj)
{
int flags;
const char *mode = Jim_String(modeObj);
if (*mode == 'R' || *mode == 'W') {
return parse_posix_open_mode(interp, modeObj);
}
if (*mode == 'r') {
flags = O_RDONLY;
}
else if (*mode == 'w') {
flags = O_WRONLY | O_CREAT | O_TRUNC;
}
else if (*mode == 'a') {
flags = O_WRONLY | O_CREAT | O_APPEND;
}
else {
Jim_SetResultFormatted(interp, "%s: invalid open mode '%s'", Jim_String(filenameObj), mode);
return -1;
}
mode++;
if (*mode == 'b') {
#ifdef O_BINARY
flags |= O_BINARY;
#endif
mode++;
}
if (*mode == 't') {
#ifdef O_TEXT
flags |= O_TEXT;
#endif
mode++;
}
if (*mode == '+') {
mode++;
flags &= ~(O_RDONLY | O_WRONLY);
flags |= O_RDWR;
}
if (*mode == 'x') {
mode++;
#ifdef O_EXCL
flags |= O_EXCL;
#endif
}
if (*mode == 'F') {
mode++;
#ifdef O_LARGEFILE
flags |= O_LARGEFILE;
#endif
}
if (*mode == 'e') {
mode++;
}
return flags;
}
static int JimAioOpenCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
int openflags;
const char *filename;
int fd = -1;
int n = 0;
int flags = 0;
if (argc > 2 && Jim_CompareStringImmediate(interp, argv[2], "-noclose")) {
flags = AIO_KEEPOPEN;
n++;
}
if (argc < 2 || argc > 3 + n) {
Jim_WrongNumArgs(interp, 1, argv, "filename ?-noclose? ?mode?");
return JIM_ERR;
}
filename = Jim_String(argv[1]);
#ifdef jim_ext_tclcompat
{
if (*filename == '|') {
Jim_Obj *evalObj[3];
int i = 0;
evalObj[i++] = Jim_NewStringObj(interp, "::popen", -1);
evalObj[i++] = Jim_NewStringObj(interp, filename + 1, -1);
if (argc == 3 + n) {
evalObj[i++] = argv[2 + n];
}
return Jim_EvalObjVector(interp, i, evalObj);
}
}
#endif
if (argc == 3 + n) {
openflags = parse_open_mode(interp, argv[1], argv[2 + n]);
if (openflags == -1) {
return JIM_ERR;
}
}
else {
openflags = O_RDONLY;
}
fd = open(filename, openflags, 0666);
if (fd < 0) {
JimAioSetError(interp, argv[1]);
return JIM_ERR;
}
return JimMakeChannel(interp, fd, argv[1], "aio.handle%ld", 0, flags) ? JIM_OK : JIM_ERR;
}
static AioFile *JimMakeChannel(Jim_Interp *interp, int fd, Jim_Obj *filename,
const char *hdlfmt, int family, int flags)
{
AioFile *af;
char buf[AIO_CMD_LEN];
Jim_Obj *cmdname;
snprintf(buf, sizeof(buf), hdlfmt, Jim_GetId(interp));
cmdname = Jim_NewStringObj(interp, buf, -1);
if (!filename) {
filename = cmdname;
}
Jim_IncrRefCount(filename);
af = Jim_Alloc(sizeof(*af));
memset(af, 0, sizeof(*af));
af->filename = filename;
af->fd = fd;
af->addr_family = family;
af->fops = &stdio_fops;
af->ssl = NULL;
if (flags & AIO_WBUF_NONE) {
af->wbuft = WBUF_OPT_NONE;
}
else {
#ifdef HAVE_ISATTY
af->wbuft = isatty(af->fd) ? WBUF_OPT_LINE : WBUF_OPT_FULL;
#else
af->wbuft = WBUF_OPT_FULL;
#endif
}
#ifdef FD_CLOEXEC
if ((flags & AIO_KEEPOPEN) == 0) {
(void)fcntl(af->fd, F_SETFD, FD_CLOEXEC);
}
#endif
aio_set_nonblocking(af, !!(flags & AIO_NONBLOCK));
af->flags |= flags;
af->writebuf = Jim_NewStringObj(interp, NULL, 0);
Jim_IncrRefCount(af->writebuf);
Jim_CreateCommand(interp, buf, JimAioSubCmdProc, af, JimAioDelProc);
Jim_SetResult(interp, Jim_MakeGlobalNamespaceName(interp, cmdname));
return af;
}
#if defined(HAVE_PIPE) || (defined(HAVE_SOCKETPAIR) && UNIX_SOCKETS) || defined(HAVE_OPENPTY)
static int JimMakeChannelPair(Jim_Interp *interp, int p[2], Jim_Obj *filename,
const char *hdlfmt, int family, int flags)
{
if (JimMakeChannel(interp, p[0], filename, hdlfmt, family, flags)) {
Jim_Obj *objPtr = Jim_NewListObj(interp, NULL, 0);
Jim_ListAppendElement(interp, objPtr, Jim_GetResult(interp));
if (JimMakeChannel(interp, p[1], filename, hdlfmt, family, flags)) {
Jim_ListAppendElement(interp, objPtr, Jim_GetResult(interp));
Jim_SetResult(interp, objPtr);
return JIM_OK;
}
}
close(p[0]);
close(p[1]);
JimAioSetError(interp, NULL);
return JIM_ERR;
}
#endif
#ifdef HAVE_PIPE
static int JimCreatePipe(Jim_Interp *interp, Jim_Obj *filenameObj, int flags)
{
int p[2];
if (pipe(p) != 0) {
JimAioSetError(interp, NULL);
return JIM_ERR;
}
return JimMakeChannelPair(interp, p, filenameObj, "aio.pipe%ld", 0, flags);
}
static int JimAioPipeCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
if (argc != 1) {
Jim_WrongNumArgs(interp, 1, argv, "");
return JIM_ERR;
}
return JimCreatePipe(interp, argv[0], 0);
}
#endif
#ifdef HAVE_OPENPTY
static int JimAioOpenPtyCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
int p[2];
char path[MAXPATHLEN];
if (argc != 1) {
Jim_WrongNumArgs(interp, 1, argv, "");
return JIM_ERR;
}
if (openpty(&p[0], &p[1], path, NULL, NULL) != 0) {
JimAioSetError(interp, NULL);
return JIM_ERR;
}
return JimMakeChannelPair(interp, p, Jim_NewStringObj(interp, path, -1), "aio.pty%ld", 0, 0);
return JimMakeChannelPair(interp, p, Jim_NewStringObj(interp, path, -1), "aio.pty%ld", 0, 0);
}
#endif
int Jim_aioInit(Jim_Interp *interp)
{
|
| ︙ | ︙ | |||
2866 2867 2868 2869 2870 2871 2872 |
Jim_CreateCommand(interp, "socket", JimAioSockCommand, NULL, NULL);
#endif
#ifdef HAVE_PIPE
Jim_CreateCommand(interp, "pipe", JimAioPipeCommand, NULL, NULL);
#endif
| | | | | 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 |
Jim_CreateCommand(interp, "socket", JimAioSockCommand, NULL, NULL);
#endif
#ifdef HAVE_PIPE
Jim_CreateCommand(interp, "pipe", JimAioPipeCommand, NULL, NULL);
#endif
JimMakeChannel(interp, fileno(stdin), NULL, "stdin", 0, AIO_KEEPOPEN);
JimMakeChannel(interp, fileno(stdout), NULL, "stdout", 0, AIO_KEEPOPEN);
JimMakeChannel(interp, fileno(stderr), NULL, "stderr", 0, AIO_KEEPOPEN | AIO_WBUF_NONE);
return JIM_OK;
}
#include <errno.h>
#include <stdio.h>
#include <string.h>
|
| ︙ | ︙ | |||
2930 2931 2932 2933 2934 2935 2936 |
return JIM_OK;
}
}
int Jim_readdirInit(Jim_Interp *interp)
{
| | < < > > > > | | 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 |
return JIM_OK;
}
}
int Jim_readdirInit(Jim_Interp *interp)
{
Jim_PackageProvideCheck(interp, "readdir");
Jim_CreateCommand(interp, "readdir", Jim_ReaddirCmd, NULL, NULL);
return JIM_OK;
}
#include <stdlib.h>
#include <string.h>
#if defined(JIM_REGEXP)
#else
#include <regex.h>
#define jim_regcomp regcomp
#define jim_regexec regexec
#define jim_regerror regerror
#define jim_regfree regfree
#endif
static void FreeRegexpInternalRep(Jim_Interp *interp, Jim_Obj *objPtr)
{
jim_regfree(objPtr->internalRep.ptrIntValue.ptr);
Jim_Free(objPtr->internalRep.ptrIntValue.ptr);
}
static const Jim_ObjType regexpObjType = {
"regexp",
FreeRegexpInternalRep,
NULL,
|
| ︙ | ︙ | |||
2978 2979 2980 2981 2982 2983 2984 |
pattern = Jim_String(objPtr);
compre = Jim_Alloc(sizeof(regex_t));
| | | | | 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 |
pattern = Jim_String(objPtr);
compre = Jim_Alloc(sizeof(regex_t));
if ((ret = jim_regcomp(compre, pattern, REG_EXTENDED | flags)) != 0) {
char buf[100];
jim_regerror(ret, compre, buf, sizeof(buf));
Jim_SetResultFormatted(interp, "couldn't compile regular expression pattern: %s", buf);
jim_regfree(compre);
Jim_Free(compre);
return NULL;
}
Jim_FreeIntRep(interp, objPtr);
objPtr->typePtr = ®expObjType;
|
| ︙ | ︙ | |||
3108 3109 3110 3111 3112 3113 3114 |
if (offset < 0) {
offset += source_len + 1;
}
if (offset > source_len) {
source_str += source_len;
}
else if (offset > 0) {
| | | | | 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 |
if (offset < 0) {
offset += source_len + 1;
}
if (offset > source_len) {
source_str += source_len;
}
else if (offset > 0) {
source_str += utf8_index(source_str, offset);
}
eflags |= REG_NOTBOL;
}
if (opt_inline) {
resultListObj = Jim_NewListObj(interp, NULL, 0);
}
next_match:
match = jim_regexec(regex, source_str, num_vars + 1, pmatch, eflags);
if (match >= REG_BADPAT) {
char buf[100];
jim_regerror(match, regex, buf, sizeof(buf));
Jim_SetResultFormatted(interp, "error while matching pattern: %s", buf);
result = JIM_ERR;
goto done;
}
if (match == REG_NOMATCH) {
goto done;
|
| ︙ | ︙ | |||
3158 3159 3160 3161 3162 3163 3164 |
if (pmatch[j].rm_so == -1) {
if (opt_indices) {
Jim_ListAppendElement(interp, resultObj, Jim_NewIntObj(interp, -1));
Jim_ListAppendElement(interp, resultObj, Jim_NewIntObj(interp, -1));
}
}
else {
| | | > | < | < | | | 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 |
if (pmatch[j].rm_so == -1) {
if (opt_indices) {
Jim_ListAppendElement(interp, resultObj, Jim_NewIntObj(interp, -1));
Jim_ListAppendElement(interp, resultObj, Jim_NewIntObj(interp, -1));
}
}
else {
if (opt_indices) {
int so = utf8_strlen(source_str, pmatch[j].rm_so);
int eo = utf8_strlen(source_str, pmatch[j].rm_eo);
Jim_ListAppendElement(interp, resultObj, Jim_NewIntObj(interp, offset + so));
Jim_ListAppendElement(interp, resultObj, Jim_NewIntObj(interp, offset + eo - 1));
}
else {
Jim_AppendString(interp, resultObj, source_str + pmatch[j].rm_so, pmatch[j].rm_eo - pmatch[j].rm_so);
}
}
if (opt_inline) {
Jim_ListAppendElement(interp, resultListObj, resultObj);
}
else {
result = Jim_SetVariable(interp, argv[i], resultObj);
if (result != JIM_OK) {
Jim_FreeObj(interp, resultObj);
break;
}
}
}
try_next_match:
if (opt_all && (pattern[0] != '^' || (regcomp_flags & REG_NEWLINE)) && *source_str) {
if (pmatch[0].rm_eo) {
offset += utf8_strlen(source_str, pmatch[0].rm_eo);
source_str += pmatch[0].rm_eo;
}
else {
source_str++;
offset++;
}
if (*source_str) {
|
| ︙ | ︙ | |||
3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 |
offset = source_len;
}
else if (offset < 0) {
offset = 0;
}
}
Jim_AppendString(interp, resultObj, source_str, offset);
n = source_len - offset;
p = source_str + offset;
do {
| > > | | | 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 |
offset = source_len;
}
else if (offset < 0) {
offset = 0;
}
}
offset = utf8_index(source_str, offset);
Jim_AppendString(interp, resultObj, source_str, offset);
n = source_len - offset;
p = source_str + offset;
do {
int match = jim_regexec(regex, p, MAX_SUB_MATCHES, pmatch, regexec_flags);
if (match >= REG_BADPAT) {
char buf[100];
jim_regerror(match, regex, buf, sizeof(buf));
Jim_SetResultFormatted(interp, "error while matching pattern: %s", buf);
return JIM_ERR;
}
if (match == REG_NOMATCH) {
break;
}
|
| ︙ | ︙ | |||
3394 3395 3396 3397 3398 3399 3400 |
if (pattern[0] == '\0' && n) {
Jim_AppendString(interp, resultObj, p, 1);
p++;
n--;
}
| > > > > > | > > | 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 |
if (pattern[0] == '\0' && n) {
Jim_AppendString(interp, resultObj, p, 1);
p++;
n--;
}
if (pmatch[0].rm_eo == pmatch[0].rm_so) {
regexec_flags = REG_NOTBOL;
}
else {
regexec_flags = 0;
}
} while (n);
Jim_AppendString(interp, resultObj, p, -1);
if (argc - i == 4) {
result = Jim_SetVariable(interp, varname, resultObj);
|
| ︙ | ︙ | |||
3420 3421 3422 3423 3424 3425 3426 |
}
return result;
}
int Jim_regexpInit(Jim_Interp *interp)
{
| | < < < > > > > > > > > > > > > > > > > > > | 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 |
}
return result;
}
int Jim_regexpInit(Jim_Interp *interp)
{
Jim_PackageProvideCheck(interp, "regexp");
Jim_CreateCommand(interp, "regexp", Jim_RegexpCmd, NULL, NULL);
Jim_CreateCommand(interp, "regsub", Jim_RegsubCmd, NULL, NULL);
return JIM_OK;
}
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#ifdef HAVE_UTIMES
#include <sys/time.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#elif defined(_MSC_VER)
#include <direct.h>
#define F_OK 0
#define W_OK 2
#define R_OK 4
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#endif
# ifndef MAXPATHLEN
# ifdef PATH_MAX
# define MAXPATHLEN PATH_MAX
# else
# define MAXPATHLEN JIM_PATH_LEN
# endif
# endif
#if defined(__MINGW32__) || defined(__MSYS__) || defined(_MSC_VER)
#define ISWINDOWS 1
#undef HAVE_SYMLINK
#else
#define ISWINDOWS 0
#endif
#if defined(HAVE_STRUCT_STAT_ST_MTIMESPEC)
#define STAT_MTIME_US(STAT) ((STAT).st_mtimespec.tv_sec * 1000000ll + (STAT).st_mtimespec.tv_nsec / 1000)
#elif defined(HAVE_STRUCT_STAT_ST_MTIM)
#define STAT_MTIME_US(STAT) ((STAT).st_mtim.tv_sec * 1000000ll + (STAT).st_mtim.tv_nsec / 1000)
#endif
static void JimFixPath(char *path)
{
if (ISWINDOWS) {
char *p = path;
while ((p = strchr(p, '\\')) != NULL) {
*p++ = '/';
}
}
}
static const char *JimGetFileType(int mode)
{
if (S_ISREG(mode)) {
return "file";
}
else if (S_ISDIR(mode)) {
|
| ︙ | ︙ | |||
3510 3511 3512 3513 3514 3515 3516 |
static void AppendStatElement(Jim_Interp *interp, Jim_Obj *listObj, const char *key, jim_wide value)
{
Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, key, -1));
Jim_ListAppendElement(interp, listObj, Jim_NewIntObj(interp, value));
}
| | | 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 |
static void AppendStatElement(Jim_Interp *interp, Jim_Obj *listObj, const char *key, jim_wide value)
{
Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, key, -1));
Jim_ListAppendElement(interp, listObj, Jim_NewIntObj(interp, value));
}
int Jim_FileStoreStatData(Jim_Interp *interp, Jim_Obj *varName, const jim_stat_t *sb)
{
Jim_Obj *listObj = Jim_NewListObj(interp, NULL, 0);
AppendStatElement(interp, listObj, "dev", sb->st_dev);
AppendStatElement(interp, listObj, "ino", sb->st_ino);
AppendStatElement(interp, listObj, "mode", sb->st_mode);
|
| ︙ | ︙ | |||
3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 |
}
Jim_SetResult(interp, listObj);
return JIM_OK;
}
static int file_cmd_dirname(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
| > > > > > > > > > > > > > > > > > > > > > > > > > > | | | > | > | > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > | | > > > > > > > > > > > > > > > > < | | > < | | | < < < < < | 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 |
}
Jim_SetResult(interp, listObj);
return JIM_OK;
}
static int JimPathLenNoTrailingSlashes(const char *path, int len)
{
int i;
for (i = len; i > 1 && path[i - 1] == '/'; i--) {
if (ISWINDOWS && path[i - 2] == ':') {
break;
}
}
return i;
}
static Jim_Obj *JimStripTrailingSlashes(Jim_Interp *interp, Jim_Obj *objPtr)
{
int len = Jim_Length(objPtr);
const char *path = Jim_String(objPtr);
int i = JimPathLenNoTrailingSlashes(path, len);
if (i != len) {
objPtr = Jim_NewStringObj(interp, path, i);
}
Jim_IncrRefCount(objPtr);
return objPtr;
}
static int file_cmd_dirname(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_Obj *objPtr = JimStripTrailingSlashes(interp, argv[0]);
const char *path = Jim_String(objPtr);
const char *p = strrchr(path, '/');
if (!p) {
Jim_SetResultString(interp, ".", -1);
}
else if (p[1] == 0) {
Jim_SetResult(interp, objPtr);
}
else if (p == path) {
Jim_SetResultString(interp, "/", -1);
}
else if (ISWINDOWS && p[-1] == ':') {
Jim_SetResultString(interp, path, p - path + 1);
}
else {
int len = JimPathLenNoTrailingSlashes(path, p - path);
Jim_SetResultString(interp, path, len);
}
Jim_DecrRefCount(interp, objPtr);
return JIM_OK;
}
static int file_cmd_split(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_Obj *listObj = Jim_NewListObj(interp, NULL, 0);
const char *path = Jim_String(argv[0]);
if (*path == '/') {
Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, "/", 1));
}
while (1) {
while (*path == '/') {
path++;
}
if (*path) {
const char *pt = strchr(path, '/');
if (pt) {
Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, path, pt - path));
path = pt;
continue;
}
Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, path, -1));
}
break;
}
Jim_SetResult(interp, listObj);
return JIM_OK;
}
static int file_cmd_rootname(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
const char *path = Jim_String(argv[0]);
const char *lastSlash = strrchr(path, '/');
const char *p = strrchr(path, '.');
if (p == NULL || (lastSlash != NULL && lastSlash > p)) {
Jim_SetResult(interp, argv[0]);
}
else {
Jim_SetResultString(interp, path, p - path);
}
return JIM_OK;
}
static int file_cmd_extension(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_Obj *objPtr = JimStripTrailingSlashes(interp, argv[0]);
const char *path = Jim_String(objPtr);
const char *lastSlash = strrchr(path, '/');
const char *p = strrchr(path, '.');
if (p == NULL || (lastSlash != NULL && lastSlash >= p)) {
p = "";
}
Jim_SetResultString(interp, p, -1);
Jim_DecrRefCount(interp, objPtr);
return JIM_OK;
}
static int file_cmd_tail(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_Obj *objPtr = JimStripTrailingSlashes(interp, argv[0]);
const char *path = Jim_String(objPtr);
const char *lastSlash = strrchr(path, '/');
if (lastSlash) {
Jim_SetResultString(interp, lastSlash + 1, -1);
}
else {
Jim_SetResult(interp, objPtr);
}
Jim_DecrRefCount(interp, objPtr);
return JIM_OK;
}
#ifndef HAVE_RESTRICT
#define restrict
#endif
static char *JimRealPath(const char *restrict path, char *restrict resolved_path, size_t len)
{
#if defined(HAVE__FULLPATH)
return _fullpath(resolved_path, path, len);
#elif defined(HAVE_REALPATH)
return realpath(path, resolved_path);
#else
return NULL;
#endif
}
static int file_cmd_normalize(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
const char *path = Jim_String(argv[0]);
char *newname = Jim_Alloc(MAXPATHLEN);
if (JimRealPath(path, newname, MAXPATHLEN)) {
JimFixPath(newname);
Jim_SetResult(interp, Jim_NewStringObjNoAlloc(interp, newname, -1));
return JIM_OK;
}
Jim_Free(newname);
Jim_SetResultFormatted(interp, "can't normalize \"%#s\": %s", argv[0], strerror(errno));
return JIM_ERR;
}
static int file_cmd_join(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
int i;
char *newname = Jim_Alloc(MAXPATHLEN + 1);
char *last = newname;
|
| ︙ | ︙ | |||
3753 3754 3755 3756 3757 3758 3759 |
}
static int file_cmd_delete(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
int force = Jim_CompareStringImmediate(interp, argv[0], "-force");
if (force || Jim_CompareStringImmediate(interp, argv[0], "--")) {
| | | | 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 |
}
static int file_cmd_delete(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
int force = Jim_CompareStringImmediate(interp, argv[0], "-force");
if (force || Jim_CompareStringImmediate(interp, argv[0], "--")) {
argc--;
argv++;
}
while (argc--) {
const char *path = Jim_String(argv[0]);
if (unlink(path) == -1 && errno != ENOENT) {
if (rmdir(path) == -1) {
|
| ︙ | ︙ | |||
3811 3812 3813 3814 3815 3816 3817 |
}
if (errno == ENOENT) {
continue;
}
if (errno == EEXIST) {
| | | | 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 |
}
if (errno == ENOENT) {
continue;
}
if (errno == EEXIST) {
jim_stat_t sb;
if (Jim_Stat(path, &sb) == 0 && S_ISDIR(sb.st_mode)) {
return 0;
}
errno = EEXIST;
}
break;
|
| ︙ | ︙ | |||
3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 |
dest = Jim_String(argv[1]);
if (!force && access(dest, F_OK) == 0) {
Jim_SetResultFormatted(interp, "error renaming \"%#s\" to \"%#s\": target exists", argv[0],
argv[1]);
return JIM_ERR;
}
if (rename(source, dest) != 0) {
Jim_SetResultFormatted(interp, "error renaming \"%#s\" to \"%#s\": %s", argv[0], argv[1],
strerror(errno));
return JIM_ERR;
}
return JIM_OK;
| > > > > > | 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 |
dest = Jim_String(argv[1]);
if (!force && access(dest, F_OK) == 0) {
Jim_SetResultFormatted(interp, "error renaming \"%#s\" to \"%#s\": target exists", argv[0],
argv[1]);
return JIM_ERR;
}
#if ISWINDOWS
if (access(dest, F_OK) == 0) {
remove(dest);
}
#endif
if (rename(source, dest) != 0) {
Jim_SetResultFormatted(interp, "error renaming \"%#s\" to \"%#s\": %s", argv[0], argv[1],
strerror(errno));
return JIM_ERR;
}
return JIM_OK;
|
| ︙ | ︙ | |||
3925 3926 3927 3928 3929 3930 3931 |
return JIM_ERR;
}
return JIM_OK;
}
#endif
| | | | | | | | 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 |
return JIM_ERR;
}
return JIM_OK;
}
#endif
static int file_stat(Jim_Interp *interp, Jim_Obj *filename, jim_stat_t *sb)
{
const char *path = Jim_String(filename);
if (Jim_Stat(path, sb) == -1) {
Jim_SetResultFormatted(interp, "could not read \"%#s\": %s", filename, strerror(errno));
return JIM_ERR;
}
return JIM_OK;
}
#ifdef Jim_LinkStat
static int file_lstat(Jim_Interp *interp, Jim_Obj *filename, jim_stat_t *sb)
{
const char *path = Jim_String(filename);
if (Jim_LinkStat(path, sb) == -1) {
Jim_SetResultFormatted(interp, "could not read \"%#s\": %s", filename, strerror(errno));
return JIM_ERR;
}
return JIM_OK;
}
#else
#define file_lstat file_stat
#endif
static int file_cmd_atime(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
jim_stat_t sb;
if (file_stat(interp, argv[0], &sb) != JIM_OK) {
return JIM_ERR;
}
Jim_SetResultInt(interp, sb.st_atime);
return JIM_OK;
}
|
| ︙ | ︙ | |||
3983 3984 3985 3986 3987 3988 3989 |
Jim_SetResultString(interp, "Not implemented", -1);
return JIM_ERR;
#endif
}
static int file_cmd_mtime(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
| | | | 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 |
Jim_SetResultString(interp, "Not implemented", -1);
return JIM_ERR;
#endif
}
static int file_cmd_mtime(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
jim_stat_t sb;
if (argc == 2) {
jim_wide secs;
if (Jim_GetWide(interp, argv[1], &secs) != JIM_OK) {
return JIM_ERR;
}
return JimSetFileTimes(interp, Jim_String(argv[0]), secs * 1000000);
}
if (file_stat(interp, argv[0], &sb) != JIM_OK) {
return JIM_ERR;
}
Jim_SetResultInt(interp, sb.st_mtime);
return JIM_OK;
}
#ifdef STAT_MTIME_US
static int file_cmd_mtimeus(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
jim_stat_t sb;
if (argc == 2) {
jim_wide us;
if (Jim_GetWide(interp, argv[1], &us) != JIM_OK) {
return JIM_ERR;
}
return JimSetFileTimes(interp, Jim_String(argv[0]), us);
|
| ︙ | ︙ | |||
4026 4027 4028 4029 4030 4031 4032 |
static int file_cmd_copy(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
return Jim_EvalPrefix(interp, "file copy", argc, argv);
}
static int file_cmd_size(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
| | | | | | | | | | | | | 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 |
static int file_cmd_copy(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
return Jim_EvalPrefix(interp, "file copy", argc, argv);
}
static int file_cmd_size(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
jim_stat_t sb;
if (file_stat(interp, argv[0], &sb) != JIM_OK) {
return JIM_ERR;
}
Jim_SetResultInt(interp, sb.st_size);
return JIM_OK;
}
static int file_cmd_isdirectory(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
jim_stat_t sb;
int ret = 0;
if (file_stat(interp, argv[0], &sb) == JIM_OK) {
ret = S_ISDIR(sb.st_mode);
}
Jim_SetResultInt(interp, ret);
return JIM_OK;
}
static int file_cmd_isfile(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
jim_stat_t sb;
int ret = 0;
if (file_stat(interp, argv[0], &sb) == JIM_OK) {
ret = S_ISREG(sb.st_mode);
}
Jim_SetResultInt(interp, ret);
return JIM_OK;
}
#ifdef HAVE_GETEUID
static int file_cmd_owned(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
jim_stat_t sb;
int ret = 0;
if (file_stat(interp, argv[0], &sb) == JIM_OK) {
ret = (geteuid() == sb.st_uid);
}
Jim_SetResultInt(interp, ret);
return JIM_OK;
}
#endif
#if defined(HAVE_READLINK)
static int file_cmd_readlink(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
const char *path = Jim_String(argv[0]);
char *linkValue = Jim_Alloc(MAXPATHLEN + 1);
int linkLength = readlink(path, linkValue, MAXPATHLEN);
if (linkLength == -1) {
Jim_Free(linkValue);
Jim_SetResultFormatted(interp, "could not read link \"%#s\": %s", argv[0], strerror(errno));
return JIM_ERR;
}
linkValue[linkLength] = 0;
Jim_SetResult(interp, Jim_NewStringObjNoAlloc(interp, linkValue, linkLength));
return JIM_OK;
}
#endif
static int file_cmd_type(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
jim_stat_t sb;
if (file_lstat(interp, argv[0], &sb) != JIM_OK) {
return JIM_ERR;
}
Jim_SetResultString(interp, JimGetFileType((int)sb.st_mode), -1);
return JIM_OK;
}
#ifdef Jim_LinkStat
static int file_cmd_lstat(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
jim_stat_t sb;
if (file_lstat(interp, argv[0], &sb) != JIM_OK) {
return JIM_ERR;
}
return Jim_FileStoreStatData(interp, argc == 2 ? argv[1] : NULL, &sb);
}
#else
#define file_cmd_lstat file_cmd_stat
#endif
static int file_cmd_stat(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
jim_stat_t sb;
if (file_stat(interp, argv[0], &sb) != JIM_OK) {
return JIM_ERR;
}
return Jim_FileStoreStatData(interp, argc == 2 ? argv[1] : NULL, &sb);
}
static const jim_subcmd_type file_command_table[] = {
{ "atime",
"name",
file_cmd_atime,
1,
|
| ︙ | ︙ | |||
4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 |
},
{ "tail",
"name",
file_cmd_tail,
1,
1,
},
{ "normalize",
"name",
file_cmd_normalize,
1,
1,
| > > > > > > > | 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 |
},
{ "tail",
"name",
file_cmd_tail,
1,
1,
},
{ "split",
"name",
file_cmd_split,
1,
1,
},
{ "normalize",
"name",
file_cmd_normalize,
1,
1,
|
| ︙ | ︙ | |||
4358 4359 4360 4361 4362 4363 4364 |
char *cwd = Jim_Alloc(MAXPATHLEN);
if (getcwd(cwd, MAXPATHLEN) == NULL) {
Jim_SetResultString(interp, "Failed to get pwd", -1);
Jim_Free(cwd);
return JIM_ERR;
}
| < | < < < < < < | < < < < < | | 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 |
char *cwd = Jim_Alloc(MAXPATHLEN);
if (getcwd(cwd, MAXPATHLEN) == NULL) {
Jim_SetResultString(interp, "Failed to get pwd", -1);
Jim_Free(cwd);
return JIM_ERR;
}
JimFixPath(cwd);
Jim_SetResultString(interp, cwd, -1);
Jim_Free(cwd);
return JIM_OK;
}
int Jim_fileInit(Jim_Interp *interp)
{
Jim_PackageProvideCheck(interp, "file");
Jim_CreateCommand(interp, "file", Jim_SubCmdProc, (void *)file_command_table, NULL);
Jim_CreateCommand(interp, "pwd", Jim_PwdCmd, NULL, NULL);
Jim_CreateCommand(interp, "cd", Jim_CdCmd, NULL, NULL);
return JIM_OK;
}
#include <string.h>
#include <ctype.h>
#if (!(defined(HAVE_VFORK) || defined(HAVE_FORK)) || !defined(HAVE_WAITPID)) && !defined(__MINGW32__)
static int Jim_ExecCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_Obj *cmdlineObj = Jim_NewEmptyStringObj(interp);
int i, j;
int rc;
|
| ︙ | ︙ | |||
4438 4439 4440 4441 4442 4443 4444 |
}
return JIM_OK;
}
int Jim_execInit(Jim_Interp *interp)
{
| | < < | | | | < < < < < | | | | 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 |
}
return JIM_OK;
}
int Jim_execInit(Jim_Interp *interp)
{
Jim_PackageProvideCheck(interp, "exec");
Jim_CreateCommand(interp, "exec", Jim_ExecCmd, NULL, NULL);
return JIM_OK;
}
#else
#include <errno.h>
#include <signal.h>
#include <sys/stat.h>
struct WaitInfoTable;
static char **JimOriginalEnviron(void);
static char **JimSaveEnv(char **env);
static void JimRestoreEnv(char **env);
static int JimCreatePipeline(Jim_Interp *interp, int argc, Jim_Obj *const *argv,
phandle_t **pidArrayPtr, int *inPipePtr, int *outPipePtr, int *errFilePtr);
static void JimDetachPids(struct WaitInfoTable *table, int numPids, const phandle_t *pidPtr);
static int JimCleanupChildren(Jim_Interp *interp, int numPids, phandle_t *pidPtr, Jim_Obj *errStrObj);
static int Jim_WaitCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv);
#if defined(__MINGW32__)
static phandle_t JimStartWinProcess(Jim_Interp *interp, char **argv, char **env, int inputId, int outputId, int errorId);
#endif
static void Jim_RemoveTrailingNewline(Jim_Obj *objPtr)
{
int len;
const char *s = Jim_GetString(objPtr, &len);
if (len > 0 && s[len - 1] == '\n') {
objPtr->length--;
objPtr->bytes[objPtr->length] = '\0';
}
}
static int JimAppendStreamToString(Jim_Interp *interp, int fd, Jim_Obj *strObj)
{
char buf[256];
int ret = 0;
while (1) {
int retval = read(fd, buf, sizeof(buf));
if (retval > 0) {
ret = 1;
Jim_AppendString(interp, strObj, buf, retval);
}
if (retval <= 0) {
break;
}
}
close(fd);
return ret;
}
static char **JimBuildEnv(Jim_Interp *interp)
{
int i;
int size;
|
| ︙ | ︙ | |||
4556 4557 4558 4559 4560 4561 4562 |
static void JimFreeEnv(char **env, char **original_environ)
{
if (env != original_environ) {
Jim_Free(env);
}
}
| | | | | | 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 |
static void JimFreeEnv(char **env, char **original_environ)
{
if (env != original_environ) {
Jim_Free(env);
}
}
static Jim_Obj *JimMakeErrorCode(Jim_Interp *interp, long pid, int waitStatus, Jim_Obj *errStrObj)
{
Jim_Obj *errorCode = Jim_NewListObj(interp, NULL, 0);
if (pid <= 0) {
Jim_ListAppendElement(interp, errorCode, Jim_NewStringObj(interp, "NONE", -1));
Jim_ListAppendElement(interp, errorCode, Jim_NewIntObj(interp, pid));
Jim_ListAppendElement(interp, errorCode, Jim_NewIntObj(interp, -1));
}
else if (WIFEXITED(waitStatus)) {
Jim_ListAppendElement(interp, errorCode, Jim_NewStringObj(interp, "CHILDSTATUS", -1));
Jim_ListAppendElement(interp, errorCode, Jim_NewIntObj(interp, pid));
Jim_ListAppendElement(interp, errorCode, Jim_NewIntObj(interp, WEXITSTATUS(waitStatus)));
}
else {
const char *type;
const char *action;
const char *signame;
|
| ︙ | ︙ | |||
4592 4593 4594 4595 4596 4597 4598 |
Jim_ListAppendElement(interp, errorCode, Jim_NewStringObj(interp, type, -1));
if (errStrObj) {
Jim_AppendStrings(interp, errStrObj, "child ", action, " by signal ", Jim_SignalId(WTERMSIG(waitStatus)), "\n", NULL);
}
| | | | | 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 |
Jim_ListAppendElement(interp, errorCode, Jim_NewStringObj(interp, type, -1));
if (errStrObj) {
Jim_AppendStrings(interp, errStrObj, "child ", action, " by signal ", Jim_SignalId(WTERMSIG(waitStatus)), "\n", NULL);
}
Jim_ListAppendElement(interp, errorCode, Jim_NewIntObj(interp, pid));
Jim_ListAppendElement(interp, errorCode, Jim_NewStringObj(interp, signame, -1));
}
return errorCode;
}
static int JimCheckWaitStatus(Jim_Interp *interp, long pid, int waitStatus, Jim_Obj *errStrObj)
{
if (WIFEXITED(waitStatus) && WEXITSTATUS(waitStatus) == 0) {
return JIM_OK;
}
Jim_SetGlobalVariableStr(interp, "errorCode", JimMakeErrorCode(interp, pid, waitStatus, errStrObj));
return JIM_ERR;
}
struct WaitInfo
{
phandle_t phandle;
int status;
int flags;
};
struct WaitInfoTable {
struct WaitInfo *info;
|
| ︙ | ︙ | |||
4649 4650 4651 4652 4653 4654 4655 |
table->info = NULL;
table->size = table->used = 0;
table->refcount = 1;
return table;
}
| | | | | | 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 |
table->info = NULL;
table->size = table->used = 0;
table->refcount = 1;
return table;
}
static int JimWaitRemove(struct WaitInfoTable *table, phandle_t phandle)
{
int i;
for (i = 0; i < table->used; i++) {
if (phandle == table->info[i].phandle) {
if (i != table->used - 1) {
table->info[i] = table->info[table->used - 1];
}
table->used--;
return 0;
}
}
return -1;
}
static int Jim_ExecCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
int outputId;
int errorId;
phandle_t *pidPtr;
int numPids, result;
int child_siginfo = 1;
Jim_Obj *childErrObj;
Jim_Obj *errStrObj;
struct WaitInfoTable *table = Jim_CmdPrivData(interp);
if (argc > 1 && Jim_CompareStringImmediate(interp, argv[argc - 1], "&")) {
Jim_Obj *listObj;
int i;
argc--;
numPids = JimCreatePipeline(interp, argc - 1, argv + 1, &pidPtr, NULL, NULL, NULL);
if (numPids < 0) {
return JIM_ERR;
}
listObj = Jim_NewListObj(interp, NULL, 0);
for (i = 0; i < numPids; i++) {
Jim_ListAppendElement(interp, listObj, Jim_NewIntObj(interp, JimProcessPid(pidPtr[i])));
}
Jim_SetResult(interp, listObj);
JimDetachPids(table, numPids, pidPtr);
Jim_Free(pidPtr);
return JIM_OK;
}
|
| ︙ | ︙ | |||
4726 4727 4728 4729 4730 4731 4732 |
if (JimCleanupChildren(interp, numPids, pidPtr, childErrObj) != JIM_OK) {
result = JIM_ERR;
}
if (errorId != -1) {
int ret;
| | | 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 |
if (JimCleanupChildren(interp, numPids, pidPtr, childErrObj) != JIM_OK) {
result = JIM_ERR;
}
if (errorId != -1) {
int ret;
Jim_Lseek(errorId, 0, SEEK_SET);
ret = JimAppendStreamToString(interp, errorId, errStrObj);
if (ret < 0) {
Jim_SetResultErrno(interp, "error reading from error pipe");
result = JIM_ERR;
}
else if (ret > 0) {
|
| ︙ | ︙ | |||
4753 4754 4755 4756 4757 4758 4759 |
Jim_SetResult(interp, errStrObj);
return result;
}
| | | | < | | | | 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 |
Jim_SetResult(interp, errStrObj);
return result;
}
static long JimWaitForProcess(struct WaitInfoTable *table, phandle_t phandle, int *statusPtr)
{
if (JimWaitRemove(table, phandle) == 0) {
return waitpid(phandle, statusPtr, 0);
}
return -1;
}
static void JimDetachPids(struct WaitInfoTable *table, int numPids, const phandle_t *pidPtr)
{
int j;
for (j = 0; j < numPids; j++) {
int i;
for (i = 0; i < table->used; i++) {
if (pidPtr[j] == table->info[i].phandle) {
table->info[i].flags |= WI_DETACHED;
break;
}
}
}
}
|
| ︙ | ︙ | |||
4812 4813 4814 4815 4816 4817 4818 |
}
waitPtr = table->info;
dest = 0;
for (count = table->used; count > 0; waitPtr++, count--) {
if (waitPtr->flags & WI_DETACHED) {
int status;
| | | < | > | > | > > > > > > > > | | | | | 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 |
}
waitPtr = table->info;
dest = 0;
for (count = table->used; count > 0; waitPtr++, count--) {
if (waitPtr->flags & WI_DETACHED) {
int status;
long pid = waitpid(waitPtr->phandle, &status, WNOHANG);
if (pid > 0) {
table->used--;
continue;
}
}
if (waitPtr != &table->info[dest]) {
table->info[dest] = *waitPtr;
}
dest++;
}
}
static int Jim_WaitCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
struct WaitInfoTable *table = Jim_CmdPrivData(interp);
int nohang = 0;
long pid;
phandle_t phandle;
int status;
Jim_Obj *errCodeObj;
if (argc == 1) {
JimReapDetachedPids(table);
return JIM_OK;
}
if (argc > 1 && Jim_CompareStringImmediate(interp, argv[1], "-nohang")) {
nohang = 1;
}
if (argc != nohang + 2) {
Jim_WrongNumArgs(interp, 1, argv, "?-nohang? ?pid?");
return JIM_ERR;
}
if (Jim_GetLong(interp, argv[nohang + 1], &pid) != JIM_OK) {
return JIM_ERR;
}
phandle = JimWaitPid(pid, &status, nohang ? WNOHANG : 0);
if (phandle == JIM_BAD_PHANDLE) {
pid = -1;
}
#ifndef __MINGW32__
else if (pid < 0) {
pid = phandle;
}
#endif
errCodeObj = JimMakeErrorCode(interp, pid, status, NULL);
if (phandle != JIM_BAD_PHANDLE && (WIFEXITED(status) || WIFSIGNALED(status))) {
JimWaitRemove(table, phandle);
}
Jim_SetResult(interp, errCodeObj);
return JIM_OK;
}
static int Jim_PidCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
if (argc != 1) {
Jim_WrongNumArgs(interp, 1, argv, "");
return JIM_ERR;
}
Jim_SetResultInt(interp, (jim_wide)getpid());
return JIM_OK;
}
static int
JimCreatePipeline(Jim_Interp *interp, int argc, Jim_Obj *const *argv, phandle_t **pidArrayPtr,
int *inPipePtr, int *outPipePtr, int *errFilePtr)
{
phandle_t *pidPtr = NULL; /* Points to alloc-ed array holding all
* the pids of child processes. */
int numPids = 0; /* Actual number of processes that exist
* at *pidPtr right now. */
int cmdCount; /* Count of number of distinct commands
* found in argc/argv. */
const char *input = NULL; /* Describes input for pipeline, depending
* on "inputFile". NULL means take input
|
| ︙ | ︙ | |||
4923 4924 4925 4926 4927 4928 4929 |
int errorId = -1;
int lastOutputId = -1;
int pipeIds[2];
int firstArg, lastArg; /* Indexes of first and last arguments in
* current command. */
int lastBar;
int i;
| | | | 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 |
int errorId = -1;
int lastOutputId = -1;
int pipeIds[2];
int firstArg, lastArg; /* Indexes of first and last arguments in
* current command. */
int lastBar;
int i;
phandle_t phandle;
char **save_environ;
#if defined(HAVE_EXECVPE) && !defined(__MINGW32__)
char **child_environ;
#endif
struct WaitInfoTable *table = Jim_CmdPrivData(interp);
char **arg_array = Jim_Alloc(sizeof(*arg_array) * (argc + 1));
int arg_count = 0;
|
| ︙ | ︙ | |||
5051 5052 5053 5054 5055 5056 5057 |
goto error;
}
if (write(inputId, input, input_len) != input_len) {
Jim_SetResultErrno(interp, "couldn't write temp file");
close(inputId);
goto error;
}
| | | 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 |
goto error;
}
if (write(inputId, input, input_len) != input_len) {
Jim_SetResultErrno(interp, "couldn't write temp file");
close(inputId);
goto error;
}
Jim_Lseek(inputId, 0L, SEEK_SET);
}
else if (inputFile == FILE_HANDLE) {
int fd = JimGetChannelFd(interp, input);
if (fd < 0) {
goto error;
}
|
| ︙ | ︙ | |||
5143 5144 5145 5146 5147 5148 5149 |
goto error;
}
*errFilePtr = dup(errorId);
}
pidPtr = Jim_Alloc(cmdCount * sizeof(*pidPtr));
| < < < | 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 |
goto error;
}
*errFilePtr = dup(errorId);
}
pidPtr = Jim_Alloc(cmdCount * sizeof(*pidPtr));
for (firstArg = 0; firstArg < arg_count; numPids++, firstArg = lastArg + 1) {
int pipe_dup_err = 0;
int origErrorId = errorId;
for (lastArg = firstArg; lastArg < arg_count; lastArg++) {
if (strcmp(arg_array[lastArg], "|") == 0) {
break;
|
| ︙ | ︙ | |||
5187 5188 5189 5190 5191 5192 5193 |
if (pipe_dup_err) {
errorId = outputId;
}
#ifdef __MINGW32__
| | | > > > | > > > | | | | | | | < < < | 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 |
if (pipe_dup_err) {
errorId = outputId;
}
#ifdef __MINGW32__
phandle = JimStartWinProcess(interp, &arg_array[firstArg], save_environ, inputId, outputId, errorId);
if (phandle == JIM_BAD_PHANDLE) {
Jim_SetResultFormatted(interp, "couldn't exec \"%s\"", arg_array[firstArg]);
goto error;
}
#else
i = strlen(arg_array[firstArg]);
#ifdef HAVE_EXECVPE
child_environ = Jim_GetEnviron();
#endif
#ifdef HAVE_VFORK
phandle = vfork();
#else
phandle = fork();
#endif
if (phandle < 0) {
Jim_SetResultErrno(interp, "couldn't fork child process");
goto error;
}
if (phandle == 0) {
if (inputId != -1 && inputId != fileno(stdin)) {
dup2(inputId, fileno(stdin));
close(inputId);
}
if (outputId != -1 && outputId != fileno(stdout)) {
dup2(outputId, fileno(stdout));
if (outputId != errorId) {
close(outputId);
}
}
if (errorId != -1 && errorId != fileno(stderr)) {
dup2(errorId, fileno(stderr));
close(errorId);
}
if (outPipePtr && *outPipePtr != -1) {
close(*outPipePtr);
}
if (errFilePtr && *errFilePtr != -1) {
close(*errFilePtr);
}
if (pipeIds[0] != -1) {
close(pipeIds[0]);
}
if (lastOutputId != -1) {
close(lastOutputId);
}
execvpe(arg_array[firstArg], &arg_array[firstArg], child_environ);
if (write(fileno(stderr), "couldn't exec \"", 15) &&
write(fileno(stderr), arg_array[firstArg], i) &&
write(fileno(stderr), "\"\n", 2)) {
}
|
| ︙ | ︙ | |||
5260 5261 5262 5263 5264 5265 5266 |
if (table->used == table->size) {
table->size += WAIT_TABLE_GROW_BY;
table->info = Jim_Realloc(table->info, table->size * sizeof(*table->info));
}
| | | | 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 |
if (table->used == table->size) {
table->size += WAIT_TABLE_GROW_BY;
table->info = Jim_Realloc(table->info, table->size * sizeof(*table->info));
}
table->info[table->used].phandle = phandle;
table->info[table->used].flags = 0;
table->used++;
pidPtr[numPids] = phandle;
errorId = origErrorId;
if (inputId != -1) {
close(inputId);
|
| ︙ | ︙ | |||
5320 5321 5322 5323 5324 5325 5326 |
close(pipeIds[0]);
}
if (pipeIds[1] != -1) {
close(pipeIds[1]);
}
if (pidPtr != NULL) {
for (i = 0; i < numPids; i++) {
| | | | > | < < < < < > | 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 |
close(pipeIds[0]);
}
if (pipeIds[1] != -1) {
close(pipeIds[1]);
}
if (pidPtr != NULL) {
for (i = 0; i < numPids; i++) {
if (pidPtr[i] != JIM_BAD_PHANDLE) {
JimDetachPids(table, 1, &pidPtr[i]);
}
}
Jim_Free(pidPtr);
}
numPids = -1;
goto cleanup;
}
static int JimCleanupChildren(Jim_Interp *interp, int numPids, phandle_t *pidPtr, Jim_Obj *errStrObj)
{
struct WaitInfoTable *table = Jim_CmdPrivData(interp);
int result = JIM_OK;
int i;
for (i = 0; i < numPids; i++) {
int waitStatus = 0;
long pid = JimWaitForProcess(table, pidPtr[i], &waitStatus);
if (pid > 0) {
if (JimCheckWaitStatus(interp, pid, waitStatus, errStrObj) != JIM_OK) {
result = JIM_ERR;
}
}
}
Jim_Free(pidPtr);
return result;
}
int Jim_execInit(Jim_Interp *interp)
{
struct WaitInfoTable *waitinfo;
Jim_PackageProvideCheck(interp, "exec");
waitinfo = JimAllocWaitInfoTable();
Jim_CreateCommand(interp, "exec", Jim_ExecCmd, waitinfo, JimFreeWaitInfoTable);
waitinfo->refcount++;
Jim_CreateCommand(interp, "wait", Jim_WaitCommand, waitinfo, JimFreeWaitInfoTable);
Jim_CreateCommand(interp, "pid", Jim_PidCommand, 0, 0);
|
| ︙ | ︙ | |||
5481 5482 5483 5484 5485 5486 5487 |
if (quote) {
Jim_AppendString(interp, strObj, "\"", 1);
}
}
return strObj;
}
| | | | | 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 |
if (quote) {
Jim_AppendString(interp, strObj, "\"", 1);
}
}
return strObj;
}
static phandle_t
JimStartWinProcess(Jim_Interp *interp, char **argv, char **env, int inputId, int outputId, int errorId)
{
STARTUPINFO startInfo;
PROCESS_INFORMATION procInfo;
HANDLE hProcess;
char execPath[MAX_PATH];
phandle_t phandle = INVALID_HANDLE_VALUE;
Jim_Obj *cmdLineObj;
char *winenv;
if (JimWinFindExecutable(argv[0], execPath) < 0) {
return phandle;
}
argv[0] = execPath;
hProcess = GetCurrentProcess();
cmdLineObj = JimWinBuildCommandLine(interp, argv);
|
| ︙ | ︙ | |||
5556 5557 5558 5559 5560 5561 5562 |
goto end;
}
WaitForInputIdle(procInfo.hProcess, 5000);
CloseHandle(procInfo.hThread);
| | | | 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 |
goto end;
}
WaitForInputIdle(procInfo.hProcess, 5000);
CloseHandle(procInfo.hThread);
phandle = procInfo.hProcess;
end:
Jim_FreeNewObj(interp, cmdLineObj);
if (startInfo.hStdInput != INVALID_HANDLE_VALUE) {
CloseHandle(startInfo.hStdInput);
}
if (startInfo.hStdOutput != INVALID_HANDLE_VALUE) {
CloseHandle(startInfo.hStdOutput);
}
if (startInfo.hStdError != INVALID_HANDLE_VALUE) {
CloseHandle(startInfo.hStdError);
}
return phandle;
}
#else
static char **JimOriginalEnviron(void)
{
return Jim_GetEnviron();
|
| ︙ | ︙ | |||
5595 5596 5597 5598 5599 5600 5601 |
JimFreeEnv(Jim_GetEnviron(), env);
Jim_SetEnviron(env);
}
#endif
#endif
| < < < < < < < < < < < < | 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 |
JimFreeEnv(Jim_GetEnviron(), env);
Jim_SetEnviron(env);
}
#endif
#endif
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
#ifdef HAVE_SYS_TIME_H
|
| ︙ | ︙ | |||
5730 5731 5732 5733 5734 5735 5736 |
return JIM_OK;
}
#endif
static int clock_cmd_seconds(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
| | > | > > > > < < < < | < < < < < | < | | 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 |
return JIM_OK;
}
#endif
static int clock_cmd_seconds(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_SetResultInt(interp, Jim_GetTimeUsec(CLOCK_REALTIME) / 1000000);
return JIM_OK;
}
static int clock_cmd_clicks(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_SetResultInt(interp, Jim_GetTimeUsec(CLOCK_MONOTONIC_RAW));
return JIM_OK;
}
static int clock_cmd_micros(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_SetResultInt(interp, Jim_GetTimeUsec(CLOCK_REALTIME));
return JIM_OK;
}
static int clock_cmd_millis(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_SetResultInt(interp, Jim_GetTimeUsec(CLOCK_REALTIME) / 1000);
return JIM_OK;
}
static const jim_subcmd_type clock_command_table[] = {
{ "clicks",
NULL,
clock_cmd_clicks,
0,
0,
},
{ "format",
"seconds ?-format string? ?-gmt boolean?",
clock_cmd_format,
|
| ︙ | ︙ | |||
5807 5808 5809 5810 5811 5812 5813 |
},
{ NULL }
};
int Jim_clockInit(Jim_Interp *interp)
{
| | < < | 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 |
},
{ NULL }
};
int Jim_clockInit(Jim_Interp *interp)
{
Jim_PackageProvideCheck(interp, "clock");
Jim_CreateCommand(interp, "clock", Jim_SubCmdProc, (void *)clock_command_table, NULL);
return JIM_OK;
}
#include <limits.h>
#include <stdlib.h>
#include <string.h>
|
| ︙ | ︙ | |||
5884 5885 5886 5887 5888 5889 5890 |
objPtr = Jim_GetVariable(interp, argv[0], JIM_NONE);
if (objPtr == NULL) {
return JIM_OK;
}
| | > < | 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 |
objPtr = Jim_GetVariable(interp, argv[0], JIM_NONE);
if (objPtr == NULL) {
return JIM_OK;
}
dictValuesObj = Jim_DictPairs(interp, objPtr, &len);
if (dictValuesObj == NULL) {
Jim_SetResultString(interp, "", -1);
return JIM_OK;
}
resultObj = Jim_NewDictObj(interp, NULL, 0);
for (i = 0; i < len; i += 2) {
if (!Jim_StringMatchObj(interp, argv[1], dictValuesObj[i], 0)) {
Jim_DictAddElement(interp, resultObj, dictValuesObj[i], dictValuesObj[i + 1]);
}
}
Jim_SetVariable(interp, argv[0], resultObj);
return JIM_OK;
}
static int array_cmd_size(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
|
| ︙ | ︙ | |||
6029 6030 6031 6032 6033 6034 6035 |
},
{ NULL
}
};
int Jim_arrayInit(Jim_Interp *interp)
{
| | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > | > > > < < < | | 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 |
},
{ NULL
}
};
int Jim_arrayInit(Jim_Interp *interp)
{
Jim_PackageProvideCheck(interp, "array");
Jim_CreateCommand(interp, "array", Jim_SubCmdProc, (void *)array_command_table, NULL);
return JIM_OK;
}
#include <sys/types.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#ifdef HAVE_SYS_SYSINFO_H
#include <sys/sysinfo.h>
#endif
static void Jim_PosixSetError(Jim_Interp *interp)
{
Jim_SetResultString(interp, strerror(errno), -1);
}
#if defined(HAVE_FORK)
static int Jim_PosixForkCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
pid_t pid;
JIM_NOTUSED(argv);
if (argc != 1) {
Jim_WrongNumArgs(interp, 1, argv, "");
return JIM_ERR;
}
if ((pid = fork()) == -1) {
Jim_PosixSetError(interp);
return JIM_ERR;
}
Jim_SetResultInt(interp, (jim_wide) pid);
return JIM_OK;
}
#endif
int Jim_posixInit(Jim_Interp *interp)
{
Jim_PackageProvideCheck(interp, "posix");
#ifdef HAVE_FORK
Jim_CreateCommand(interp, "os.fork", Jim_PosixForkCommand, NULL, NULL);
#endif
return JIM_OK;
}
int Jim_InitStaticExtensions(Jim_Interp *interp)
{
extern int Jim_bootstrapInit(Jim_Interp *);
extern int Jim_aioInit(Jim_Interp *);
extern int Jim_readdirInit(Jim_Interp *);
extern int Jim_regexpInit(Jim_Interp *);
extern int Jim_fileInit(Jim_Interp *);
extern int Jim_globInit(Jim_Interp *);
extern int Jim_execInit(Jim_Interp *);
extern int Jim_posixInit(Jim_Interp *);
extern int Jim_clockInit(Jim_Interp *);
extern int Jim_arrayInit(Jim_Interp *);
extern int Jim_stdlibInit(Jim_Interp *);
extern int Jim_tclcompatInit(Jim_Interp *);
Jim_bootstrapInit(interp);
Jim_aioInit(interp);
Jim_readdirInit(interp);
Jim_regexpInit(interp);
Jim_fileInit(interp);
Jim_globInit(interp);
Jim_execInit(interp);
Jim_posixInit(interp);
Jim_clockInit(interp);
Jim_arrayInit(interp);
Jim_stdlibInit(interp);
Jim_tclcompatInit(interp);
return JIM_OK;
}
#define JIM_OPTIMIZATION
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <ctype.h>
#include <limits.h>
#include <assert.h>
#include <errno.h>
#include <time.h>
#include <setjmp.h>
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#ifdef HAVE_EXECINFO_H
#include <execinfo.h>
#endif
#ifdef HAVE_CRT_EXTERNS_H
#include <crt_externs.h>
#endif
|
| ︙ | ︙ | |||
6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 |
static void JimPanicDump(int fail_condition, const char *fmt, ...);
#define JimPanic(X) JimPanicDump X
#else
#define JimPanic(X)
#endif
#ifdef JIM_OPTIMIZATION
#define JIM_IF_OPTIM(X) X
#else
#define JIM_IF_OPTIM(X)
#endif
static char JimEmptyStringRep[] = "";
static void JimFreeCallFrame(Jim_Interp *interp, Jim_CallFrame *cf, int action);
static int ListSetIndex(Jim_Interp *interp, Jim_Obj *listPtr, int listindex, Jim_Obj *newObjPtr,
int flags);
static int JimDeleteLocalProcs(Jim_Interp *interp, Jim_Stack *localCommands);
static Jim_Obj *JimExpandDictSugar(Jim_Interp *interp, Jim_Obj *objPtr);
static void SetDictSubstFromAny(Jim_Interp *interp, Jim_Obj *objPtr);
| > > > < < > > > > > > > > > > > > > > > > > > | > > | | > > | > > | > | < > | 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 |
static void JimPanicDump(int fail_condition, const char *fmt, ...);
#define JimPanic(X) JimPanicDump X
#else
#define JimPanic(X)
#endif
#ifdef JIM_OPTIMIZATION
static int JimIsWide(Jim_Obj *objPtr);
#define JIM_IF_OPTIM(X) X
#else
#define JIM_IF_OPTIM(X)
#endif
static char JimEmptyStringRep[] = "";
static void JimFreeCallFrame(Jim_Interp *interp, Jim_CallFrame *cf, int action);
static int ListSetIndex(Jim_Interp *interp, Jim_Obj *listPtr, int listindex, Jim_Obj *newObjPtr,
int flags);
static int Jim_ListIndices(Jim_Interp *interp, Jim_Obj *listPtr, Jim_Obj *const *indexv, int indexc,
Jim_Obj **resultObj, int flags);
static int JimDeleteLocalProcs(Jim_Interp *interp, Jim_Stack *localCommands);
static Jim_Obj *JimExpandDictSugar(Jim_Interp *interp, Jim_Obj *objPtr);
static void SetDictSubstFromAny(Jim_Interp *interp, Jim_Obj *objPtr);
static void JimSetFailedEnumResult(Jim_Interp *interp, const char *arg, const char *badtype,
const char *prefix, const char *const *tablePtr, const char *name);
static int JimCallProcedure(Jim_Interp *interp, Jim_Cmd *cmd, int argc, Jim_Obj *const *argv);
static int JimGetWideNoErr(Jim_Interp *interp, Jim_Obj *objPtr, jim_wide * widePtr);
static int JimSign(jim_wide w);
static void JimPrngSeed(Jim_Interp *interp, unsigned char *seed, int seedLen);
static void JimRandomBytes(Jim_Interp *interp, void *dest, unsigned int len);
static int JimSetNewVariable(Jim_HashTable *ht, Jim_Obj *nameObjPtr, Jim_VarVal *vv);
static Jim_VarVal *JimFindVariable(Jim_HashTable *ht, Jim_Obj *nameObjPtr);
static void JimSetErrorStack(Jim_Interp *interp);
static int SetVariableFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr);
#define JIM_DICT_SUGAR 100
#define JimWideValue(objPtr) (objPtr)->internalRep.wideValue
#define JimObjTypeName(O) ((O)->typePtr ? (O)->typePtr->name : "none")
static int utf8_tounicode_case(const char *s, int *uc, int upper)
{
int l = utf8_tounicode(s, uc);
if (upper) {
*uc = utf8_upper(*uc);
}
return l;
}
static Jim_Obj *JimPushInterpObjImpl(Jim_Obj **iop, Jim_Obj *no)
{
Jim_Obj *io = *iop;
Jim_IncrRefCount(no);
*iop = no;
return io;
}
#define JimPushInterpObj(IO, NO) JimPushInterpObjImpl(&(IO), NO)
#define JimPopInterpObj(I, IO, SO) do { Jim_DecrRefCount(I, IO); IO = SO; } while (0)
#define JIM_CHARSET_SCAN 2
#define JIM_CHARSET_GLOB 0
static const char *JimCharsetMatch(const char *pattern, int plen, int c, int flags)
{
int not = 0;
int pchar;
int match = 0;
int nocase = 0;
int n;
if (flags & JIM_NOCASE) {
nocase++;
c = utf8_upper(c);
}
if (flags & JIM_CHARSET_SCAN) {
if (*pattern == '^') {
not++;
pattern++;
plen--;
}
if (*pattern == ']') {
goto first;
}
}
while (plen && *pattern != ']') {
if (pattern[0] == '\\') {
first:
n = utf8_tounicode_case(pattern, &pchar, nocase);
pattern += n;
plen -= n;
}
else {
int start;
int end;
n = utf8_tounicode_case(pattern, &start, nocase);
pattern += n;
plen -= n;
if (pattern[0] == '-' && plen > 1) {
n = 1 + utf8_tounicode_case(pattern + 1, &end, nocase);
pattern += n;
plen -= n;
if ((c >= start && c <= end) || (c >= end && c <= start)) {
match = 1;
}
continue;
}
|
| ︙ | ︙ | |||
6240 6241 6242 6243 6244 6245 6246 |
}
return match ? pattern : NULL;
}
| | > > | | > > | | | | > > | > > | > > | | > | > > > | > > | > > | | > | | | < < | < < | < < | < < < | < < | | < | | | | 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 |
}
return match ? pattern : NULL;
}
static int JimGlobMatch(const char *pattern, int plen, const char *string, int slen, int nocase)
{
int c;
int pchar;
int n;
const char *p;
while (plen) {
switch (pattern[0]) {
case '*':
while (pattern[1] == '*' && plen) {
pattern++;
plen--;
}
pattern++;
plen--;
if (!plen) {
return 1;
}
while (slen) {
if (JimGlobMatch(pattern, plen, string, slen, nocase))
return 1;
n = utf8_tounicode(string, &c);
string += n;
slen -= n;
}
return 0;
case '?':
n = utf8_tounicode(string, &c);
string += n;
slen -= n;
break;
case '[': {
n = utf8_tounicode(string, &c);
string += n;
slen -= n;
p = JimCharsetMatch(pattern + 1, plen - 1, c, nocase ? JIM_NOCASE : 0);
if (!p) {
return 0;
}
plen -= p - pattern;
pattern = p;
if (!plen) {
continue;
}
break;
}
case '\\':
if (pattern[1]) {
pattern++;
plen--;
}
default:
n = utf8_tounicode_case(string, &c, nocase);
string += n;
slen -= n;
utf8_tounicode_case(pattern, &pchar, nocase);
if (pchar != c) {
return 0;
}
break;
}
n = utf8_tounicode_case(pattern, &pchar, nocase);
pattern += n;
plen -= n;
if (!slen) {
while (*pattern == '*' && plen) {
pattern++;
plen--;
}
break;
}
}
if (!plen && !slen) {
return 1;
}
return 0;
}
static int JimStringCompareUtf8(const char *s1, int l1, const char *s2, int l2, int nocase)
{
int minlen = l1;
if (l2 < l1) {
minlen = l2;
}
while (minlen) {
int c1, c2;
s1 += utf8_tounicode_case(s1, &c1, nocase);
s2 += utf8_tounicode_case(s2, &c2, nocase);
if (c1 != c2) {
return JimSign(c1 - c2);
}
minlen--;
}
if (l1 < l2) {
return -1;
}
if (l1 > l2) {
return 1;
}
return 0;
}
static int JimStringFirst(const char *s1, int l1, const char *s2, int l2, int idx)
{
int i;
|
| ︙ | ︙ | |||
6414 6415 6416 6417 6418 6419 6420 |
return JIM_OK;
}
static int JimNumberBase(const char *str, int *base, int *sign)
{
int i = 0;
| | | 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 |
return JIM_OK;
}
static int JimNumberBase(const char *str, int *base, int *sign)
{
int i = 0;
*base = 0;
while (isspace(UCHAR(str[i]))) {
i++;
}
if (str[i] == '-') {
*sign = -1;
|
| ︙ | ︙ | |||
6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 |
}
switch (str[i + 1]) {
case 'x': case 'X': *base = 16; break;
case 'o': case 'O': *base = 8; break;
case 'b': case 'B': *base = 2; break;
default: return 0;
}
i += 2;
if (str[i] != '-' && str[i] != '+' && !isspace(UCHAR(str[i]))) {
return i;
}
| > | | | | 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 |
}
switch (str[i + 1]) {
case 'x': case 'X': *base = 16; break;
case 'o': case 'O': *base = 8; break;
case 'b': case 'B': *base = 2; break;
case 'd': case 'D': *base = 10; break;
default: return 0;
}
i += 2;
if (str[i] != '-' && str[i] != '+' && !isspace(UCHAR(str[i]))) {
return i;
}
*base = 0;
return 0;
}
static long jim_strtol(const char *str, char **endptr)
{
int sign;
int base;
int i = JimNumberBase(str, &base, &sign);
if (base != 0) {
long value = strtol(str + i, endptr, base);
if (endptr == NULL || *endptr != str + i) {
return value * sign;
}
}
return strtol(str, endptr, 10);
}
static jim_wide jim_strtoull(const char *str, char **endptr)
{
#ifdef HAVE_LONG_LONG
int sign;
int base;
int i = JimNumberBase(str, &base, &sign);
if (base != 0) {
jim_wide value = strtoull(str + i, endptr, base);
if (endptr == NULL || *endptr != str + i) {
return value * sign;
}
}
|
| ︙ | ︙ | |||
6561 6562 6563 6564 6565 6566 6567 |
va_start(ap, fmt);
fprintf(stderr, "\nJIM INTERPRETER PANIC: ");
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n\n");
va_end(ap);
| | | > > | | > > | < < > | | | < | | < | | > | < > > | > | > > > > > > | > | | > > > > > | 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 |
va_start(ap, fmt);
fprintf(stderr, "\nJIM INTERPRETER PANIC: ");
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n\n");
va_end(ap);
#if defined(HAVE_BACKTRACE)
{
void *array[40];
int size, i;
char **strings;
size = backtrace(array, 40);
strings = backtrace_symbols(array, size);
for (i = 0; i < size; i++)
fprintf(stderr, "[backtrace] %s\n", strings[i]);
fprintf(stderr, "[backtrace] Include the above lines and the output\n");
fprintf(stderr, "[backtrace] of 'nm <executable>' in the bug report.\n");
}
#endif
exit(1);
}
#endif
void *JimDefaultAllocator(void *ptr, size_t size)
{
if (size == 0) {
free(ptr);
return NULL;
}
else if (ptr) {
return realloc(ptr, size);
}
else {
return malloc(size);
}
}
void *(*Jim_Allocator)(void *ptr, size_t size) = JimDefaultAllocator;
char *Jim_StrDup(const char *s)
{
return Jim_StrDupLen(s, strlen(s));
}
char *Jim_StrDupLen(const char *s, int l)
{
char *copy = Jim_Alloc(l + 1);
memcpy(copy, s, l);
copy[l] = 0;
return copy;
}
jim_wide Jim_GetTimeUsec(unsigned type)
{
long long now;
struct timeval tv;
#if defined(HAVE_CLOCK_GETTIME)
struct timespec ts;
if (clock_gettime(type, &ts) == 0) {
now = ts.tv_sec * 1000000LL + ts.tv_nsec / 1000;
}
else
#endif
{
gettimeofday(&tv, NULL);
now = tv.tv_sec * 1000000LL + tv.tv_usec;
}
return now;
}
static void JimExpandHashTableIfNeeded(Jim_HashTable *ht);
static unsigned int JimHashTableNextPower(unsigned int size);
static Jim_HashEntry *JimInsertHashEntry(Jim_HashTable *ht, const void *key, int replace);
|
| ︙ | ︙ | |||
6640 6641 6642 6643 6644 6645 6646 |
key += (key << 3);
key ^= (key >> 6);
key += ~(key << 11);
key ^= (key >> 16);
return key;
}
| > | | | | | < | > | | 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 |
key += (key << 3);
key ^= (key >> 6);
key += ~(key << 11);
key ^= (key >> 16);
return key;
}
unsigned int Jim_GenHashFunction(const unsigned char *string, int length)
{
unsigned result = 0;
string += length;
while (length--) {
result += (result << 3) + (unsigned char)(*--string);
}
return result;
}
static void JimResetHashTable(Jim_HashTable *ht)
{
ht->table = NULL;
ht->size = 0;
|
| ︙ | ︙ | |||
6683 6684 6685 6686 6687 6688 6689 |
{
JimResetHashTable(ht);
ht->type = type;
ht->privdata = privDataPtr;
return JIM_OK;
}
| < < < < < < < < < | 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 |
{
JimResetHashTable(ht);
ht->type = type;
ht->privdata = privDataPtr;
return JIM_OK;
}
void Jim_ExpandHashTable(Jim_HashTable *ht, unsigned int size)
{
Jim_HashTable n;
unsigned int realsize = JimHashTableNextPower(size), i;
if (size <= ht->used)
|
| ︙ | ︙ | |||
6740 6741 6742 6743 6744 6745 6746 |
assert(ht->used == 0);
Jim_Free(ht->table);
*ht = n;
}
| < < < | | 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 |
assert(ht->used == 0);
Jim_Free(ht->table);
*ht = n;
}
int Jim_AddHashEntry(Jim_HashTable *ht, const void *key, void *val)
{
Jim_HashEntry *entry = JimInsertHashEntry(ht, key, 0);;
if (entry == NULL)
return JIM_ERR;
Jim_SetHashKey(ht, entry, key);
Jim_SetHashVal(ht, entry, val);
return JIM_OK;
|
| ︙ | ︙ | |||
6784 6785 6786 6787 6788 6789 6790 |
Jim_SetHashVal(ht, entry, val);
existed = 0;
}
return existed;
}
| < < < < | < | > | < | | | | | | > | | | < | | | | | < | > | > | | < > > > > > > | 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538 7539 7540 7541 7542 7543 7544 7545 7546 7547 7548 7549 7550 7551 7552 7553 7554 |
Jim_SetHashVal(ht, entry, val);
existed = 0;
}
return existed;
}
int Jim_DeleteHashEntry(Jim_HashTable *ht, const void *key)
{
if (ht->used) {
unsigned int h = Jim_HashKey(ht, key) & ht->sizemask;
Jim_HashEntry *prevHe = NULL;
Jim_HashEntry *he = ht->table[h];
while (he) {
if (Jim_CompareHashKeys(ht, key, he->key)) {
if (prevHe)
prevHe->next = he->next;
else
ht->table[h] = he->next;
ht->used--;
Jim_FreeEntryKey(ht, he);
Jim_FreeEntryVal(ht, he);
Jim_Free(he);
return JIM_OK;
}
prevHe = he;
he = he->next;
}
}
return JIM_ERR;
}
void Jim_ClearHashTable(Jim_HashTable *ht)
{
unsigned int i;
for (i = 0; ht->used > 0; i++) {
Jim_HashEntry *he, *nextHe;
he = ht->table[i];
while (he) {
nextHe = he->next;
Jim_FreeEntryKey(ht, he);
Jim_FreeEntryVal(ht, he);
Jim_Free(he);
ht->used--;
he = nextHe;
}
ht->table[i] = NULL;
}
}
int Jim_FreeHashTable(Jim_HashTable *ht)
{
Jim_ClearHashTable(ht);
Jim_Free(ht->table);
JimResetHashTable(ht);
return JIM_OK;
}
|
| ︙ | ︙ | |||
7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 |
{
while (1) {
if (!pc->len) {
pc->tstart = pc->p;
pc->tend = pc->p - 1;
pc->tline = pc->linenr;
pc->tt = JIM_TT_EOL;
pc->eof = 1;
return JIM_OK;
}
switch (*(pc->p)) {
case '\\':
if (*(pc->p + 1) == '\n' && !pc->inquote) {
return JimParseSep(pc);
| > > > | 7844 7845 7846 7847 7848 7849 7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 |
{
while (1) {
if (!pc->len) {
pc->tstart = pc->p;
pc->tend = pc->p - 1;
pc->tline = pc->linenr;
pc->tt = JIM_TT_EOL;
if (pc->inquote) {
pc->missing.ch = '"';
}
pc->eof = 1;
return JIM_OK;
}
switch (*(pc->p)) {
case '\\':
if (*(pc->p + 1) == '\n' && !pc->inquote) {
return JimParseSep(pc);
|
| ︙ | ︙ | |||
7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 |
return;
}
break;
case '"':
if (startofword) {
JimParseSubQuote(pc);
continue;
}
break;
case '{':
JimParseSubBrace(pc);
startofword = 0;
| > > > | 8061 8062 8063 8064 8065 8066 8067 8068 8069 8070 8071 8072 8073 8074 8075 8076 8077 |
return;
}
break;
case '"':
if (startofword) {
JimParseSubQuote(pc);
if (pc->missing.ch == '"') {
return;
}
continue;
}
break;
case '{':
JimParseSubBrace(pc);
startofword = 0;
|
| ︙ | ︙ | |||
8303 8304 8305 8306 8307 8308 8309 |
return Alen == Blen && memcmp(sA, sB, Alen) == 0;
}
}
int Jim_StringMatchObj(Jim_Interp *interp, Jim_Obj *patternObjPtr, Jim_Obj *objPtr, int nocase)
{
| > | > > < < < < < < < < < < < < < > | | | | 9015 9016 9017 9018 9019 9020 9021 9022 9023 9024 9025 9026 9027 9028 9029 9030 9031 9032 9033 9034 9035 9036 9037 9038 9039 9040 9041 9042 9043 9044 9045 9046 |
return Alen == Blen && memcmp(sA, sB, Alen) == 0;
}
}
int Jim_StringMatchObj(Jim_Interp *interp, Jim_Obj *patternObjPtr, Jim_Obj *objPtr, int nocase)
{
int plen, slen;
const char *pattern = Jim_GetString(patternObjPtr, &plen);
const char *string = Jim_GetString(objPtr, &slen);
return JimGlobMatch(pattern, plen, string, slen, nocase);
}
int Jim_StringCompareObj(Jim_Interp *interp, Jim_Obj *firstObjPtr, Jim_Obj *secondObjPtr, int nocase)
{
const char *s1 = Jim_String(firstObjPtr);
int l1 = Jim_Utf8Length(interp, firstObjPtr);
const char *s2 = Jim_String(secondObjPtr);
int l2 = Jim_Utf8Length(interp, secondObjPtr);
return JimStringCompareUtf8(s1, l1, s2, l2, nocase);
}
static int JimRelToAbsIndex(int len, int idx)
{
if (idx < 0 && idx > -INT_MAX)
return len + idx;
return idx;
}
static void JimRelToAbsRange(int len, int *firstPtr, int *lastPtr, int *rangeLenPtr)
{
int rangeLen;
|
| ︙ | ︙ | |||
8847 8848 8849 8850 8851 8852 8853 |
static void DupScriptInternalRep(Jim_Interp *interp, Jim_Obj *srcPtr, Jim_Obj *dupPtr);
static const Jim_ObjType scriptObjType = {
"script",
FreeScriptInternalRep,
DupScriptInternalRep,
NULL,
| | | 9550 9551 9552 9553 9554 9555 9556 9557 9558 9559 9560 9561 9562 9563 9564 |
static void DupScriptInternalRep(Jim_Interp *interp, Jim_Obj *srcPtr, Jim_Obj *dupPtr);
static const Jim_ObjType scriptObjType = {
"script",
FreeScriptInternalRep,
DupScriptInternalRep,
NULL,
JIM_TYPE_NONE,
};
typedef struct ScriptToken
{
Jim_Obj *objPtr;
int type;
} ScriptToken;
|
| ︙ | ︙ | |||
9221 9222 9223 9224 9225 9226 9227 |
Jim_FreeIntRep(interp, objPtr);
Jim_SetIntRepPtr(objPtr, script);
objPtr->typePtr = &scriptObjType;
}
| < < | < | | | > > | > | > | | 9924 9925 9926 9927 9928 9929 9930 9931 9932 9933 9934 9935 9936 9937 9938 9939 9940 9941 9942 9943 9944 9945 9946 9947 9948 9949 9950 9951 9952 9953 9954 9955 9956 9957 9958 9959 9960 9961 9962 9963 |
Jim_FreeIntRep(interp, objPtr);
Jim_SetIntRepPtr(objPtr, script);
objPtr->typePtr = &scriptObjType;
}
static ScriptObj *JimGetScript(Jim_Interp *interp, Jim_Obj *objPtr)
{
if (objPtr == interp->emptyObj) {
objPtr = interp->nullScriptObj;
}
if (objPtr->typePtr != &scriptObjType || ((struct ScriptObj *)Jim_GetIntRepPtr(objPtr))->substFlags) {
JimSetScriptFromAny(interp, objPtr);
}
return (ScriptObj *)Jim_GetIntRepPtr(objPtr);
}
void Jim_InterpIncrProcEpoch(Jim_Interp *interp)
{
interp->procEpoch++;
while (interp->oldCmdCache) {
Jim_Cmd *next = interp->oldCmdCache->prevCmd;
Jim_Free(interp->oldCmdCache);
interp->oldCmdCache = next;
}
interp->oldCmdCacheSize = 0;
}
static void JimIncrCmdRefCount(Jim_Cmd *cmdPtr)
{
cmdPtr->inUse++;
}
static void JimDecrCmdRefCount(Jim_Interp *interp, Jim_Cmd *cmdPtr)
|
| ︙ | ︙ | |||
9274 9275 9276 9277 9278 9279 9280 |
cmdPtr->u.native.delProc(interp, cmdPtr->u.native.privData);
}
}
if (cmdPtr->prevCmd) {
JimDecrCmdRefCount(interp, cmdPtr->prevCmd);
}
| > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > | > > > > > | | < > | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | | | < < < < < < < < < < < < < < < < < < > > > > | < | < < < < < | > > > | | < | < < < | | < | < | < < | < | | < < | | | > | | < < < < < | | | > | < | < | < | < | > | | > | > > > > > > > > | | < | | < | < < < < < < < < | | | < < < < < < | < < < < < < < < < < < < < < | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > | > | > | > > | 9978 9979 9980 9981 9982 9983 9984 9985 9986 9987 9988 9989 9990 9991 9992 9993 9994 9995 9996 9997 9998 9999 10000 10001 10002 10003 10004 10005 10006 10007 10008 10009 10010 10011 10012 10013 10014 10015 10016 10017 10018 10019 10020 10021 10022 10023 10024 10025 10026 10027 10028 10029 10030 10031 10032 10033 10034 10035 10036 10037 10038 10039 10040 10041 10042 10043 10044 10045 10046 10047 10048 10049 10050 10051 10052 10053 10054 10055 10056 10057 10058 10059 10060 10061 10062 10063 10064 10065 10066 10067 10068 10069 10070 10071 10072 10073 10074 10075 10076 10077 10078 10079 10080 10081 10082 10083 10084 10085 10086 10087 10088 10089 10090 10091 10092 10093 10094 10095 10096 10097 10098 10099 10100 10101 10102 10103 10104 10105 10106 10107 10108 10109 10110 10111 10112 10113 10114 10115 10116 10117 10118 10119 10120 10121 10122 10123 10124 10125 10126 10127 10128 10129 10130 10131 10132 10133 10134 10135 10136 10137 10138 10139 10140 10141 10142 10143 10144 10145 10146 10147 10148 10149 10150 10151 10152 10153 10154 10155 10156 10157 10158 10159 10160 10161 10162 10163 10164 10165 10166 10167 10168 10169 10170 10171 10172 10173 10174 10175 10176 10177 10178 10179 10180 10181 10182 10183 10184 10185 10186 10187 10188 10189 10190 10191 10192 10193 10194 10195 10196 10197 10198 10199 10200 10201 10202 10203 10204 10205 10206 10207 10208 10209 10210 10211 10212 10213 10214 10215 10216 10217 10218 10219 10220 10221 10222 10223 10224 10225 10226 10227 10228 10229 10230 10231 10232 10233 10234 10235 10236 10237 10238 10239 10240 10241 10242 10243 10244 10245 10246 10247 10248 10249 10250 10251 10252 10253 10254 10255 10256 10257 10258 10259 10260 10261 10262 10263 10264 10265 10266 10267 10268 10269 10270 10271 10272 10273 10274 10275 10276 10277 10278 10279 10280 10281 10282 10283 10284 10285 10286 10287 10288 10289 10290 10291 10292 10293 10294 10295 10296 10297 10298 10299 10300 10301 10302 10303 10304 10305 10306 10307 10308 10309 10310 10311 10312 10313 10314 10315 10316 10317 10318 10319 10320 10321 10322 10323 10324 10325 10326 10327 10328 10329 10330 10331 10332 10333 10334 10335 10336 10337 10338 10339 10340 10341 10342 10343 10344 10345 10346 10347 10348 10349 10350 10351 10352 10353 10354 10355 10356 10357 10358 10359 10360 10361 10362 10363 10364 10365 10366 |
cmdPtr->u.native.delProc(interp, cmdPtr->u.native.privData);
}
}
if (cmdPtr->prevCmd) {
JimDecrCmdRefCount(interp, cmdPtr->prevCmd);
}
cmdPtr->prevCmd = interp->oldCmdCache;
interp->oldCmdCache = cmdPtr;
if (!interp->quitting && ++interp->oldCmdCacheSize >= 1000) {
Jim_InterpIncrProcEpoch(interp);
}
}
}
static void JimIncrVarRef(Jim_VarVal *vv)
{
vv->refCount++;
}
static void JimDecrVarRef(Jim_Interp *interp, Jim_VarVal *vv)
{
assert(vv->refCount > 0);
if (--vv->refCount == 0) {
if (vv->objPtr) {
Jim_DecrRefCount(interp, vv->objPtr);
}
Jim_Free(vv);
}
}
static void JimVariablesHTValDestructor(void *interp, void *val)
{
JimDecrVarRef(interp, val);
}
static unsigned int JimObjectHTHashFunction(const void *key)
{
Jim_Obj *keyObj = (Jim_Obj *)key;
int length;
const char *string;
#ifdef JIM_OPTIMIZATION
if (JimIsWide(keyObj) && keyObj->bytes == NULL) {
jim_wide objValue = JimWideValue(keyObj);
if (objValue > INT_MIN && objValue < INT_MAX) {
unsigned result = 0;
unsigned value = (unsigned)objValue;
if (objValue < 0) {
value = (unsigned)-objValue;
}
do {
result += (result << 3) + (value % 10 + '0');
value /= 10;
} while (value);
if (objValue < 0) {
result += (result << 3) + '-';
}
return result;
}
}
#endif
string = Jim_GetString(keyObj, &length);
return Jim_GenHashFunction((const unsigned char *)string, length);
}
static int JimObjectHTKeyCompare(void *privdata, const void *key1, const void *key2)
{
return Jim_StringEqObj((Jim_Obj *)key1, (Jim_Obj *)key2);
}
static void *JimObjectHTKeyValDup(void *privdata, const void *val)
{
Jim_IncrRefCount((Jim_Obj *)val);
return (void *)val;
}
static void JimObjectHTKeyValDestructor(void *interp, void *val)
{
Jim_DecrRefCount(interp, (Jim_Obj *)val);
}
static void *JimVariablesHTValDup(void *privdata, const void *val)
{
JimIncrVarRef((Jim_VarVal *)val);
return (void *)val;
}
static const Jim_HashTableType JimVariablesHashTableType = {
JimObjectHTHashFunction,
JimObjectHTKeyValDup,
JimVariablesHTValDup,
JimObjectHTKeyCompare,
JimObjectHTKeyValDestructor,
JimVariablesHTValDestructor
};
static const char *Jim_GetStringNoQualifier(Jim_Obj *objPtr, int *length)
{
int len;
const char *str = Jim_GetString(objPtr, &len);
if (len >= 2 && str[0] == ':' && str[1] == ':') {
while (len && *str == ':') {
len--;
str++;
}
}
*length = len;
return str;
}
static unsigned int JimCommandsHT_HashFunction(const void *key)
{
int len;
const char *str = Jim_GetStringNoQualifier((Jim_Obj *)key, &len);
return Jim_GenHashFunction((const unsigned char *)str, len);
}
static int JimCommandsHT_KeyCompare(void *privdata, const void *key1, const void *key2)
{
int len1, len2;
const char *str1 = Jim_GetStringNoQualifier((Jim_Obj *)key1, &len1);
const char *str2 = Jim_GetStringNoQualifier((Jim_Obj *)key2, &len2);
return len1 == len2 && memcmp(str1, str2, len1) == 0;
}
static void JimCommandsHT_ValDestructor(void *interp, void *val)
{
JimDecrCmdRefCount(interp, val);
}
static const Jim_HashTableType JimCommandsHashTableType = {
JimCommandsHT_HashFunction,
JimObjectHTKeyValDup,
NULL,
JimCommandsHT_KeyCompare,
JimObjectHTKeyValDestructor,
JimCommandsHT_ValDestructor
};
Jim_Obj *Jim_MakeGlobalNamespaceName(Jim_Interp *interp, Jim_Obj *nameObjPtr)
{
#ifdef jim_ext_namespace
Jim_Obj *resultObj;
const char *name = Jim_String(nameObjPtr);
if (name[0] == ':' && name[1] == ':') {
return nameObjPtr;
}
Jim_IncrRefCount(nameObjPtr);
resultObj = Jim_NewStringObj(interp, "::", -1);
Jim_AppendObj(interp, resultObj, nameObjPtr);
Jim_DecrRefCount(interp, nameObjPtr);
return resultObj;
#else
return nameObjPtr;
#endif
}
static Jim_Obj *JimQualifyName(Jim_Interp *interp, Jim_Obj *objPtr)
{
#ifdef jim_ext_namespace
if (Jim_Length(interp->framePtr->nsObj)) {
int len;
const char *name = Jim_GetString(objPtr, &len);
if (len < 2 || name[0] != ':' || name[1] != ':') {
objPtr = Jim_DuplicateObj(interp, interp->framePtr->nsObj);
Jim_AppendStrings(interp, objPtr, "::", name, NULL);
}
}
#endif
Jim_IncrRefCount(objPtr);
return objPtr;
}
static void JimCreateCommand(Jim_Interp *interp, Jim_Obj *nameObjPtr, Jim_Cmd *cmd)
{
JimPanic((nameObjPtr->refCount == 0, "JimCreateCommand called with zero ref count name"));
if (interp->local) {
Jim_HashEntry *he = Jim_FindHashEntry(&interp->commands, nameObjPtr);
if (he) {
cmd->prevCmd = Jim_GetHashEntryVal(he);
Jim_SetHashVal(&interp->commands, he, cmd);
Jim_InterpIncrProcEpoch(interp);
return;
}
}
Jim_ReplaceHashEntry(&interp->commands, nameObjPtr, cmd);
}
int Jim_CreateCommandObj(Jim_Interp *interp, Jim_Obj *cmdNameObj,
Jim_CmdProc *cmdProc, void *privData, Jim_DelCmdProc *delProc)
{
Jim_Cmd *cmdPtr = Jim_Alloc(sizeof(*cmdPtr));
memset(cmdPtr, 0, sizeof(*cmdPtr));
cmdPtr->inUse = 1;
cmdPtr->u.native.delProc = delProc;
cmdPtr->u.native.cmdProc = cmdProc;
cmdPtr->u.native.privData = privData;
Jim_IncrRefCount(cmdNameObj);
JimCreateCommand(interp, cmdNameObj, cmdPtr);
Jim_DecrRefCount(interp, cmdNameObj);
return JIM_OK;
}
int Jim_CreateCommand(Jim_Interp *interp, const char *cmdNameStr,
Jim_CmdProc *cmdProc, void *privData, Jim_DelCmdProc *delProc)
{
return Jim_CreateCommandObj(interp, Jim_NewStringObj(interp, cmdNameStr, -1), cmdProc, privData, delProc);
}
static int JimCreateProcedureStatics(Jim_Interp *interp, Jim_Cmd *cmdPtr, Jim_Obj *staticsListObjPtr)
{
int len, i;
len = Jim_ListLength(interp, staticsListObjPtr);
if (len == 0) {
return JIM_OK;
}
cmdPtr->u.proc.staticVars = Jim_Alloc(sizeof(Jim_HashTable));
Jim_InitHashTable(cmdPtr->u.proc.staticVars, &JimVariablesHashTableType, interp);
for (i = 0; i < len; i++) {
Jim_Obj *initObjPtr = NULL;
Jim_Obj *nameObjPtr;
Jim_VarVal *vv = NULL;
Jim_Obj *objPtr = Jim_ListGetIndex(interp, staticsListObjPtr, i);
int subLen = Jim_ListLength(interp, objPtr);
int byref = 0;
if (subLen != 1 && subLen != 2) {
Jim_SetResultFormatted(interp, "too many fields in static specifier \"%#s\"",
objPtr);
return JIM_ERR;
}
nameObjPtr = Jim_ListGetIndex(interp, objPtr, 0);
if (subLen == 1) {
int len;
const char *pt = Jim_GetString(nameObjPtr, &len);
if (*pt == '&') {
nameObjPtr = Jim_NewStringObj(interp, pt + 1, len - 1);
byref = 1;
}
}
Jim_IncrRefCount(nameObjPtr);
if (subLen == 1) {
switch (SetVariableFromAny(interp, nameObjPtr)) {
case JIM_DICT_SUGAR:
if (byref) {
Jim_SetResultFormatted(interp, "Can't link to array element \"%#s\"", nameObjPtr);
}
else {
Jim_SetResultFormatted(interp, "Can't initialise array element \"%#s\"", nameObjPtr);
}
Jim_DecrRefCount(interp, nameObjPtr);
return JIM_ERR;
case JIM_OK:
if (byref) {
vv = nameObjPtr->internalRep.varValue.vv;
}
else {
initObjPtr = Jim_GetVariable(interp, nameObjPtr, JIM_NONE);
}
break;
case JIM_ERR:
Jim_SetResultFormatted(interp,
"variable for initialization of static \"%#s\" not found in the local context",
nameObjPtr);
Jim_DecrRefCount(interp, nameObjPtr);
return JIM_ERR;
}
}
else {
initObjPtr = Jim_ListGetIndex(interp, objPtr, 1);
}
if (vv == NULL) {
vv = Jim_Alloc(sizeof(*vv));
vv->objPtr = initObjPtr;
Jim_IncrRefCount(vv->objPtr);
vv->linkFramePtr = NULL;
vv->refCount = 0;
}
if (JimSetNewVariable(cmdPtr->u.proc.staticVars, nameObjPtr, vv) != JIM_OK) {
Jim_SetResultFormatted(interp,
"static variable name \"%#s\" duplicated in statics list", nameObjPtr);
JimIncrVarRef(vv);
JimDecrVarRef(interp, vv);
Jim_DecrRefCount(interp, nameObjPtr);
return JIM_ERR;
}
Jim_DecrRefCount(interp, nameObjPtr);
}
return JIM_OK;
}
#ifdef jim_ext_namespace
static const char *Jim_memrchr(const char *p, int c, int len)
{
int i;
for (i = len; i > 0; i--) {
if (p[i] == c) {
return p + i;
}
}
return NULL;
}
#endif
static void JimUpdateProcNamespace(Jim_Interp *interp, Jim_Cmd *cmdPtr, Jim_Obj *nameObjPtr)
{
#ifdef jim_ext_namespace
if (cmdPtr->isproc) {
int len;
const char *cmdname = Jim_GetStringNoQualifier(nameObjPtr, &len);
const char *pt = Jim_memrchr(cmdname, ':', len);
if (pt && pt != cmdname && pt[-1] == ':') {
pt++;
Jim_DecrRefCount(interp, cmdPtr->u.proc.nsObj);
cmdPtr->u.proc.nsObj = Jim_NewStringObj(interp, cmdname, pt - cmdname - 2);
Jim_IncrRefCount(cmdPtr->u.proc.nsObj);
Jim_Obj *tempObj = Jim_NewStringObj(interp, pt, len - (pt - cmdname));
if (Jim_FindHashEntry(&interp->commands, tempObj)) {
Jim_InterpIncrProcEpoch(interp);
}
Jim_FreeNewObj(interp, tempObj);
}
}
#endif
}
static Jim_Cmd *JimCreateProcedureCmd(Jim_Interp *interp, Jim_Obj *argListObjPtr,
Jim_Obj *staticsListObjPtr, Jim_Obj *bodyObjPtr, Jim_Obj *nsObj)
{
Jim_Cmd *cmdPtr;
int argListLen;
int i;
argListLen = Jim_ListLength(interp, argListObjPtr);
cmdPtr = Jim_Alloc(sizeof(*cmdPtr) + sizeof(struct Jim_ProcArg) * argListLen);
assert(cmdPtr);
memset(cmdPtr, 0, sizeof(*cmdPtr));
cmdPtr->inUse = 1;
cmdPtr->isproc = 1;
cmdPtr->u.proc.argListObjPtr = argListObjPtr;
cmdPtr->u.proc.argListLen = argListLen;
cmdPtr->u.proc.bodyObjPtr = bodyObjPtr;
cmdPtr->u.proc.argsPos = -1;
|
| ︙ | ︙ | |||
9583 9584 9585 9586 9587 9588 9589 |
cmdPtr->u.proc.arglist[i].nameObjPtr = nameObjPtr;
cmdPtr->u.proc.arglist[i].defaultObjPtr = defaultObjPtr;
}
return cmdPtr;
}
| | | | | | < < < | < | < < < < | | > > | | | | | | < > > > > > | | | | | | | | | | > | 10428 10429 10430 10431 10432 10433 10434 10435 10436 10437 10438 10439 10440 10441 10442 10443 10444 10445 10446 10447 10448 10449 10450 10451 10452 10453 10454 10455 10456 10457 10458 10459 10460 10461 10462 10463 10464 10465 10466 10467 10468 10469 10470 10471 10472 10473 10474 10475 10476 10477 10478 10479 10480 10481 10482 10483 10484 10485 10486 10487 10488 10489 10490 10491 10492 10493 10494 10495 10496 10497 10498 10499 10500 10501 10502 |
cmdPtr->u.proc.arglist[i].nameObjPtr = nameObjPtr;
cmdPtr->u.proc.arglist[i].defaultObjPtr = defaultObjPtr;
}
return cmdPtr;
}
int Jim_DeleteCommand(Jim_Interp *interp, Jim_Obj *nameObj)
{
int ret = JIM_OK;
nameObj = JimQualifyName(interp, nameObj);
if (Jim_DeleteHashEntry(&interp->commands, nameObj) == JIM_ERR) {
Jim_SetResultFormatted(interp, "can't delete \"%#s\": command doesn't exist", nameObj);
ret = JIM_ERR;
}
Jim_DecrRefCount(interp, nameObj);
return ret;
}
int Jim_RenameCommand(Jim_Interp *interp, Jim_Obj *oldNameObj, Jim_Obj *newNameObj)
{
int ret = JIM_ERR;
Jim_HashEntry *he;
Jim_Cmd *cmdPtr;
if (Jim_Length(newNameObj) == 0) {
return Jim_DeleteCommand(interp, oldNameObj);
}
oldNameObj = JimQualifyName(interp, oldNameObj);
newNameObj = JimQualifyName(interp, newNameObj);
he = Jim_FindHashEntry(&interp->commands, oldNameObj);
if (he == NULL) {
Jim_SetResultFormatted(interp, "can't rename \"%#s\": command doesn't exist", oldNameObj);
}
else if (Jim_FindHashEntry(&interp->commands, newNameObj)) {
Jim_SetResultFormatted(interp, "can't rename to \"%#s\": command already exists", newNameObj);
}
else {
cmdPtr = Jim_GetHashEntryVal(he);
if (cmdPtr->prevCmd) {
Jim_SetResultFormatted(interp, "can't rename local command \"%#s\"", oldNameObj);
}
else {
JimIncrCmdRefCount(cmdPtr);
JimUpdateProcNamespace(interp, cmdPtr, newNameObj);
Jim_AddHashEntry(&interp->commands, newNameObj, cmdPtr);
Jim_DeleteHashEntry(&interp->commands, oldNameObj);
Jim_InterpIncrProcEpoch(interp);
ret = JIM_OK;
}
}
Jim_DecrRefCount(interp, oldNameObj);
Jim_DecrRefCount(interp, newNameObj);
return ret;
}
static void FreeCommandInternalRep(Jim_Interp *interp, Jim_Obj *objPtr)
{
|
| ︙ | ︙ | |||
9674 9675 9676 9677 9678 9679 9680 |
JIM_TYPE_REFERENCES,
};
Jim_Cmd *Jim_GetCommand(Jim_Interp *interp, Jim_Obj *objPtr, int flags)
{
Jim_Cmd *cmd;
| | | | | | | > | | < < < < < | < < < | < < < | < < < < > < < < > > < < | < < < < < < < < < < < < < < < < < < < > < < < < | > > > > > > | > > > | < < < | < | | | < | > > > > > > > > > > > > > > > > > > > | > | | | > | | > > > < | | < | | < | < < < | | | | | | | 10518 10519 10520 10521 10522 10523 10524 10525 10526 10527 10528 10529 10530 10531 10532 10533 10534 10535 10536 10537 10538 10539 10540 10541 10542 10543 10544 10545 10546 10547 10548 10549 10550 10551 10552 10553 10554 10555 10556 10557 10558 10559 10560 10561 10562 10563 10564 10565 10566 10567 10568 10569 10570 10571 10572 10573 10574 10575 10576 10577 10578 10579 10580 10581 10582 10583 10584 10585 10586 10587 10588 10589 10590 10591 10592 10593 10594 10595 10596 10597 10598 10599 10600 10601 10602 10603 10604 10605 10606 10607 10608 10609 10610 10611 10612 10613 10614 10615 10616 10617 10618 10619 10620 10621 10622 10623 10624 10625 10626 10627 10628 10629 10630 10631 10632 10633 10634 10635 10636 10637 10638 10639 10640 10641 10642 10643 10644 10645 10646 10647 10648 10649 10650 10651 10652 10653 10654 10655 10656 10657 10658 10659 10660 10661 10662 10663 10664 10665 10666 10667 10668 10669 10670 10671 10672 10673 10674 10675 10676 10677 10678 10679 10680 10681 10682 10683 10684 10685 10686 10687 10688 10689 10690 10691 10692 10693 10694 10695 10696 10697 10698 10699 10700 10701 10702 10703 10704 10705 10706 10707 10708 10709 10710 10711 10712 10713 10714 10715 10716 10717 10718 10719 10720 10721 10722 10723 10724 10725 10726 10727 10728 10729 10730 10731 10732 10733 10734 10735 10736 10737 10738 |
JIM_TYPE_REFERENCES,
};
Jim_Cmd *Jim_GetCommand(Jim_Interp *interp, Jim_Obj *objPtr, int flags)
{
Jim_Cmd *cmd;
if (objPtr->typePtr == &commandObjType
&& objPtr->internalRep.cmdValue.procEpoch == interp->procEpoch
#ifdef jim_ext_namespace
&& Jim_StringEqObj(objPtr->internalRep.cmdValue.nsObj, interp->framePtr->nsObj)
#endif
&& objPtr->internalRep.cmdValue.cmdPtr->inUse) {
cmd = objPtr->internalRep.cmdValue.cmdPtr;
}
else {
Jim_Obj *qualifiedNameObj = JimQualifyName(interp, objPtr);
Jim_HashEntry *he = Jim_FindHashEntry(&interp->commands, qualifiedNameObj);
#ifdef jim_ext_namespace
if (he == NULL && Jim_Length(interp->framePtr->nsObj)) {
he = Jim_FindHashEntry(&interp->commands, objPtr);
}
#endif
if (he == NULL) {
if (flags & JIM_ERRMSG) {
Jim_SetResultFormatted(interp, "invalid command name \"%#s\"", objPtr);
}
Jim_DecrRefCount(interp, qualifiedNameObj);
return NULL;
}
cmd = Jim_GetHashEntryVal(he);
cmd->cmdNameObj = Jim_GetHashEntryKey(he);
Jim_FreeIntRep(interp, objPtr);
objPtr->typePtr = &commandObjType;
objPtr->internalRep.cmdValue.procEpoch = interp->procEpoch;
objPtr->internalRep.cmdValue.cmdPtr = cmd;
objPtr->internalRep.cmdValue.nsObj = interp->framePtr->nsObj;
Jim_IncrRefCount(interp->framePtr->nsObj);
Jim_DecrRefCount(interp, qualifiedNameObj);
}
while (cmd->u.proc.upcall) {
cmd = cmd->prevCmd;
}
return cmd;
}
static const Jim_ObjType variableObjType = {
"variable",
NULL,
NULL,
NULL,
JIM_TYPE_REFERENCES,
};
static int SetVariableFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr)
{
const char *varName;
Jim_CallFrame *framePtr;
int global;
int len;
Jim_VarVal *vv;
if (objPtr->typePtr == &variableObjType) {
framePtr = objPtr->internalRep.varValue.global ? interp->topFramePtr : interp->framePtr;
if (objPtr->internalRep.varValue.callFrameId == framePtr->id) {
return JIM_OK;
}
}
else if (objPtr->typePtr == &dictSubstObjType) {
return JIM_DICT_SUGAR;
}
varName = Jim_GetString(objPtr, &len);
if (len && varName[len - 1] == ')' && strchr(varName, '(') != NULL) {
return JIM_DICT_SUGAR;
}
if (varName[0] == ':' && varName[1] == ':') {
while (*varName == ':') {
varName++;
len--;
}
global = 1;
framePtr = interp->topFramePtr;
Jim_Obj *tempObj = Jim_NewStringObj(interp, varName, len);
vv = JimFindVariable(&framePtr->vars, tempObj);
Jim_FreeNewObj(interp, tempObj);
}
else {
global = 0;
framePtr = interp->framePtr;
vv = JimFindVariable(&framePtr->vars, objPtr);
if (vv == NULL && framePtr->staticVars) {
vv = JimFindVariable(framePtr->staticVars, objPtr);
}
}
if (vv == NULL) {
return JIM_ERR;
}
Jim_FreeIntRep(interp, objPtr);
objPtr->typePtr = &variableObjType;
objPtr->internalRep.varValue.callFrameId = framePtr->id;
objPtr->internalRep.varValue.vv = vv;
objPtr->internalRep.varValue.global = global;
return JIM_OK;
}
static int JimDictSugarSet(Jim_Interp *interp, Jim_Obj *ObjPtr, Jim_Obj *valObjPtr);
static Jim_Obj *JimDictSugarGet(Jim_Interp *interp, Jim_Obj *ObjPtr, int flags);
static int JimSetNewVariable(Jim_HashTable *ht, Jim_Obj *nameObjPtr, Jim_VarVal *vv)
{
return Jim_AddHashEntry(ht, nameObjPtr, vv);
}
static Jim_VarVal *JimFindVariable(Jim_HashTable *ht, Jim_Obj *nameObjPtr)
{
Jim_HashEntry *he = Jim_FindHashEntry(ht, nameObjPtr);
if (he) {
return (Jim_VarVal *)Jim_GetHashEntryVal(he);
}
return NULL;
}
static int JimUnsetVariable(Jim_HashTable *ht, Jim_Obj *nameObjPtr)
{
return Jim_DeleteHashEntry(ht, nameObjPtr);
}
static Jim_VarVal *JimCreateVariable(Jim_Interp *interp, Jim_Obj *nameObjPtr, Jim_Obj *valObjPtr)
{
const char *name;
Jim_CallFrame *framePtr;
int global;
int len;
Jim_VarVal *vv = Jim_Alloc(sizeof(*vv));
vv->objPtr = valObjPtr;
Jim_IncrRefCount(valObjPtr);
vv->linkFramePtr = NULL;
vv->refCount = 0;
name = Jim_GetString(nameObjPtr, &len);
if (name[0] == ':' && name[1] == ':') {
while (*name == ':') {
name++;
len--;
}
framePtr = interp->topFramePtr;
global = 1;
JimSetNewVariable(&framePtr->vars, Jim_NewStringObj(interp, name, len), vv);
}
else {
framePtr = interp->framePtr;
global = 0;
JimSetNewVariable(&framePtr->vars, nameObjPtr, vv);
}
Jim_FreeIntRep(interp, nameObjPtr);
nameObjPtr->typePtr = &variableObjType;
nameObjPtr->internalRep.varValue.callFrameId = framePtr->id;
nameObjPtr->internalRep.varValue.vv = vv;
nameObjPtr->internalRep.varValue.global = global;
return vv;
}
int Jim_SetVariable(Jim_Interp *interp, Jim_Obj *nameObjPtr, Jim_Obj *valObjPtr)
{
int err;
Jim_VarVal *vv;
switch (SetVariableFromAny(interp, nameObjPtr)) {
case JIM_DICT_SUGAR:
return JimDictSugarSet(interp, nameObjPtr, valObjPtr);
case JIM_ERR:
JimCreateVariable(interp, nameObjPtr, valObjPtr);
break;
case JIM_OK:
vv = nameObjPtr->internalRep.varValue.vv;
if (vv->linkFramePtr == NULL) {
Jim_IncrRefCount(valObjPtr);
Jim_DecrRefCount(interp, vv->objPtr);
vv->objPtr = valObjPtr;
}
else {
Jim_CallFrame *savedCallFrame;
savedCallFrame = interp->framePtr;
interp->framePtr = vv->linkFramePtr;
err = Jim_SetVariable(interp, vv->objPtr, valObjPtr);
interp->framePtr = savedCallFrame;
if (err != JIM_OK)
return err;
}
}
return JIM_OK;
}
|
| ︙ | ︙ | |||
9947 9948 9949 9950 9951 9952 9953 |
int Jim_SetVariableLink(Jim_Interp *interp, Jim_Obj *nameObjPtr,
Jim_Obj *targetNameObjPtr, Jim_CallFrame *targetCallFrame)
{
const char *varName;
const char *targetName;
Jim_CallFrame *framePtr;
| | > > | | | | | > > | | > > | | | | | | > > > | | | | | | 10775 10776 10777 10778 10779 10780 10781 10782 10783 10784 10785 10786 10787 10788 10789 10790 10791 10792 10793 10794 10795 10796 10797 10798 10799 10800 10801 10802 10803 10804 10805 10806 10807 10808 10809 10810 10811 10812 10813 10814 10815 10816 10817 10818 10819 10820 10821 10822 10823 10824 10825 10826 10827 10828 10829 10830 10831 10832 10833 10834 10835 10836 10837 10838 10839 10840 10841 10842 10843 10844 10845 10846 10847 10848 10849 10850 10851 10852 10853 10854 10855 10856 10857 10858 10859 10860 10861 10862 10863 10864 10865 10866 10867 10868 10869 10870 10871 10872 10873 10874 10875 10876 10877 10878 10879 10880 10881 10882 10883 10884 10885 10886 10887 10888 10889 10890 10891 10892 10893 10894 10895 |
int Jim_SetVariableLink(Jim_Interp *interp, Jim_Obj *nameObjPtr,
Jim_Obj *targetNameObjPtr, Jim_CallFrame *targetCallFrame)
{
const char *varName;
const char *targetName;
Jim_CallFrame *framePtr;
Jim_VarVal *vv;
int len;
int varnamelen;
switch (SetVariableFromAny(interp, nameObjPtr)) {
case JIM_DICT_SUGAR:
Jim_SetResultFormatted(interp, "bad variable name \"%#s\": upvar won't create a scalar variable that looks like an array element", nameObjPtr);
return JIM_ERR;
case JIM_OK:
vv = nameObjPtr->internalRep.varValue.vv;
if (vv->linkFramePtr == NULL) {
Jim_SetResultFormatted(interp, "variable \"%#s\" already exists", nameObjPtr);
return JIM_ERR;
}
vv->linkFramePtr = NULL;
break;
}
varName = Jim_GetString(nameObjPtr, &varnamelen);
if (varName[0] == ':' && varName[1] == ':') {
while (*varName == ':') {
varName++;
varnamelen--;
}
framePtr = interp->topFramePtr;
}
else {
framePtr = interp->framePtr;
}
targetName = Jim_GetString(targetNameObjPtr, &len);
if (targetName[0] == ':' && targetName[1] == ':') {
while (*targetName == ':') {
targetName++;
len--;
}
targetNameObjPtr = Jim_NewStringObj(interp, targetName, len);
targetCallFrame = interp->topFramePtr;
}
Jim_IncrRefCount(targetNameObjPtr);
if (framePtr->level < targetCallFrame->level) {
Jim_SetResultFormatted(interp,
"bad variable name \"%#s\": upvar won't create namespace variable that refers to procedure variable",
nameObjPtr);
Jim_DecrRefCount(interp, targetNameObjPtr);
return JIM_ERR;
}
if (framePtr == targetCallFrame) {
Jim_Obj *objPtr = targetNameObjPtr;
while (1) {
if (Jim_Length(objPtr) == varnamelen && memcmp(Jim_String(objPtr), varName, varnamelen) == 0) {
Jim_SetResultString(interp, "can't upvar from variable to itself", -1);
Jim_DecrRefCount(interp, targetNameObjPtr);
return JIM_ERR;
}
if (SetVariableFromAny(interp, objPtr) != JIM_OK)
break;
vv = objPtr->internalRep.varValue.vv;
if (vv->linkFramePtr != targetCallFrame)
break;
objPtr = vv->objPtr;
}
}
Jim_SetVariable(interp, nameObjPtr, targetNameObjPtr);
nameObjPtr->internalRep.varValue.vv->linkFramePtr = targetCallFrame;
Jim_DecrRefCount(interp, targetNameObjPtr);
return JIM_OK;
}
Jim_Obj *Jim_GetVariable(Jim_Interp *interp, Jim_Obj *nameObjPtr, int flags)
{
if (interp->safeexpr) {
return nameObjPtr;
}
switch (SetVariableFromAny(interp, nameObjPtr)) {
case JIM_OK:{
Jim_VarVal *vv = nameObjPtr->internalRep.varValue.vv;
if (vv->linkFramePtr == NULL) {
return vv->objPtr;
}
else {
Jim_Obj *objPtr;
Jim_CallFrame *savedCallFrame = interp->framePtr;
interp->framePtr = vv->linkFramePtr;
objPtr = Jim_GetVariable(interp, vv->objPtr, flags);
interp->framePtr = savedCallFrame;
if (objPtr) {
return objPtr;
}
}
}
|
| ︙ | ︙ | |||
10103 10104 10105 10106 10107 10108 10109 |
interp->framePtr = savedFramePtr;
return objPtr;
}
int Jim_UnsetVariable(Jim_Interp *interp, Jim_Obj *nameObjPtr, int flags)
{
| | | | | | < > > > | > > > > > > < | 10940 10941 10942 10943 10944 10945 10946 10947 10948 10949 10950 10951 10952 10953 10954 10955 10956 10957 10958 10959 10960 10961 10962 10963 10964 10965 10966 10967 10968 10969 10970 10971 10972 10973 10974 10975 10976 10977 10978 10979 10980 10981 10982 10983 10984 10985 10986 10987 10988 10989 10990 |
interp->framePtr = savedFramePtr;
return objPtr;
}
int Jim_UnsetVariable(Jim_Interp *interp, Jim_Obj *nameObjPtr, int flags)
{
Jim_VarVal *vv;
int retval;
Jim_CallFrame *framePtr;
retval = SetVariableFromAny(interp, nameObjPtr);
if (retval == JIM_DICT_SUGAR) {
return JimDictSugarSet(interp, nameObjPtr, NULL);
}
else if (retval == JIM_OK) {
vv = nameObjPtr->internalRep.varValue.vv;
if (vv->linkFramePtr) {
framePtr = interp->framePtr;
interp->framePtr = vv->linkFramePtr;
retval = Jim_UnsetVariable(interp, vv->objPtr, JIM_NONE);
interp->framePtr = framePtr;
}
else {
if (nameObjPtr->internalRep.varValue.global) {
int len;
const char *name = Jim_GetString(nameObjPtr, &len);
while (*name == ':') {
name++;
len--;
}
framePtr = interp->topFramePtr;
Jim_Obj *tempObj = Jim_NewStringObj(interp, name, len);
retval = JimUnsetVariable(&framePtr->vars, tempObj);
Jim_FreeNewObj(interp, tempObj);
}
else {
framePtr = interp->framePtr;
retval = JimUnsetVariable(&framePtr->vars, nameObjPtr);
}
if (retval == JIM_OK) {
framePtr->id = interp->callFrameEpoch++;
}
}
}
if (retval != JIM_OK && (flags & JIM_ERRMSG)) {
|
| ︙ | ︙ | |||
10288 10289 10290 10291 10292 10293 10294 10295 10296 10297 10298 10299 10300 10301 10302 10303 10304 10305 10306 10307 10308 10309 10310 10311 |
}
}
static Jim_Obj *JimExpandDictSugar(Jim_Interp *interp, Jim_Obj *objPtr)
{
Jim_Obj *resObjPtr = NULL;
Jim_Obj *substKeyObjPtr = NULL;
SetDictSubstFromAny(interp, objPtr);
if (Jim_SubstObj(interp, objPtr->internalRep.dictSubstValue.indexObjPtr,
&substKeyObjPtr, JIM_NONE)
!= JIM_OK) {
return NULL;
}
Jim_IncrRefCount(substKeyObjPtr);
resObjPtr =
JimDictExpandArrayVariable(interp, objPtr->internalRep.dictSubstValue.varNameObjPtr,
substKeyObjPtr, 0);
Jim_DecrRefCount(interp, substKeyObjPtr);
return resObjPtr;
}
| > > > > < < < < < < < < | 11132 11133 11134 11135 11136 11137 11138 11139 11140 11141 11142 11143 11144 11145 11146 11147 11148 11149 11150 11151 11152 11153 11154 11155 11156 11157 11158 11159 11160 11161 11162 11163 11164 11165 11166 |
}
}
static Jim_Obj *JimExpandDictSugar(Jim_Interp *interp, Jim_Obj *objPtr)
{
Jim_Obj *resObjPtr = NULL;
Jim_Obj *substKeyObjPtr = NULL;
if (interp->safeexpr) {
return objPtr;
}
SetDictSubstFromAny(interp, objPtr);
if (Jim_SubstObj(interp, objPtr->internalRep.dictSubstValue.indexObjPtr,
&substKeyObjPtr, JIM_NONE)
!= JIM_OK) {
return NULL;
}
Jim_IncrRefCount(substKeyObjPtr);
resObjPtr =
JimDictExpandArrayVariable(interp, objPtr->internalRep.dictSubstValue.varNameObjPtr,
substKeyObjPtr, 0);
Jim_DecrRefCount(interp, substKeyObjPtr);
return resObjPtr;
}
static Jim_CallFrame *JimCreateCallFrame(Jim_Interp *interp, Jim_CallFrame *parent, Jim_Obj *nsObj)
{
Jim_CallFrame *cf;
if (interp->freeFramesList) {
cf = interp->freeFramesList;
|
| ︙ | ︙ | |||
10355 10356 10357 10358 10359 10360 10361 |
static int JimDeleteLocalProcs(Jim_Interp *interp, Jim_Stack *localCommands)
{
if (localCommands) {
Jim_Obj *cmdNameObj;
while ((cmdNameObj = Jim_StackPop(localCommands)) != NULL) {
| < < < < < | < | < < | < | | 11195 11196 11197 11198 11199 11200 11201 11202 11203 11204 11205 11206 11207 11208 11209 11210 11211 11212 11213 11214 11215 11216 11217 11218 11219 11220 11221 11222 11223 11224 11225 11226 11227 11228 11229 11230 11231 11232 11233 11234 11235 11236 11237 11238 11239 11240 11241 11242 11243 |
static int JimDeleteLocalProcs(Jim_Interp *interp, Jim_Stack *localCommands)
{
if (localCommands) {
Jim_Obj *cmdNameObj;
while ((cmdNameObj = Jim_StackPop(localCommands)) != NULL) {
Jim_HashTable *ht = &interp->commands;
Jim_HashEntry *he = Jim_FindHashEntry(ht, cmdNameObj);
if (he) {
Jim_Cmd *cmd = Jim_GetHashEntryVal(he);
if (cmd->prevCmd) {
Jim_Cmd *prevCmd = cmd->prevCmd;
cmd->prevCmd = NULL;
JimDecrCmdRefCount(interp, cmd);
Jim_SetHashVal(ht, he, prevCmd);
}
else {
Jim_DeleteHashEntry(ht, cmdNameObj);
}
}
Jim_DecrRefCount(interp, cmdNameObj);
}
Jim_FreeStack(localCommands);
Jim_Free(localCommands);
}
return JIM_OK;
}
static int JimInvokeDefer(Jim_Interp *interp, int retcode)
{
Jim_Obj *objPtr;
if (JimFindVariable(&interp->framePtr->vars, interp->defer) == NULL) {
return retcode;
}
objPtr = Jim_GetVariable(interp, interp->defer, JIM_NONE);
if (objPtr) {
int ret = JIM_OK;
int i;
int listLen = Jim_ListLength(interp, objPtr);
Jim_Obj *resultObjPtr;
|
| ︙ | ︙ | |||
10450 10451 10452 10453 10454 10455 10456 |
Jim_DecrRefCount(interp, cf->procArgsObjPtr);
if (cf->procBodyObjPtr)
Jim_DecrRefCount(interp, cf->procBodyObjPtr);
Jim_DecrRefCount(interp, cf->nsObj);
if (action == JIM_FCF_FULL || cf->vars.size != JIM_HT_INITIAL_SIZE)
Jim_FreeHashTable(&cf->vars);
else {
| < < | < < < < < < < < < < < < < < < | 11281 11282 11283 11284 11285 11286 11287 11288 11289 11290 11291 11292 11293 11294 11295 |
Jim_DecrRefCount(interp, cf->procArgsObjPtr);
if (cf->procBodyObjPtr)
Jim_DecrRefCount(interp, cf->procBodyObjPtr);
Jim_DecrRefCount(interp, cf->nsObj);
if (action == JIM_FCF_FULL || cf->vars.size != JIM_HT_INITIAL_SIZE)
Jim_FreeHashTable(&cf->vars);
else {
Jim_ClearHashTable(&cf->vars);
}
cf->next = interp->freeFramesList;
interp->freeFramesList = cf;
}
|
| ︙ | ︙ | |||
10494 10495 10496 10497 10498 10499 10500 |
{
Jim_Interp *i = Jim_Alloc(sizeof(*i));
memset(i, 0, sizeof(*i));
i->maxCallFrameDepth = JIM_MAX_CALLFRAME_DEPTH;
i->maxEvalDepth = JIM_MAX_EVAL_DEPTH;
| | < > | > | < | > > > > > | | | > > > > > > > | 11308 11309 11310 11311 11312 11313 11314 11315 11316 11317 11318 11319 11320 11321 11322 11323 11324 11325 11326 11327 11328 11329 11330 11331 11332 11333 11334 11335 11336 11337 11338 11339 11340 11341 11342 11343 11344 11345 11346 11347 11348 11349 11350 11351 11352 11353 11354 11355 11356 11357 11358 11359 11360 11361 11362 11363 11364 11365 11366 11367 11368 11369 11370 11371 11372 11373 11374 11375 11376 11377 11378 11379 11380 11381 11382 11383 11384 11385 11386 11387 11388 11389 11390 11391 11392 11393 11394 11395 11396 11397 11398 11399 11400 11401 11402 11403 11404 11405 11406 11407 11408 11409 11410 |
{
Jim_Interp *i = Jim_Alloc(sizeof(*i));
memset(i, 0, sizeof(*i));
i->maxCallFrameDepth = JIM_MAX_CALLFRAME_DEPTH;
i->maxEvalDepth = JIM_MAX_EVAL_DEPTH;
i->lastCollectTime = Jim_GetTimeUsec(CLOCK_MONOTONIC_RAW);
Jim_InitHashTable(&i->commands, &JimCommandsHashTableType, i);
#ifdef JIM_REFERENCES
Jim_InitHashTable(&i->references, &JimReferencesHashTableType, i);
#endif
Jim_InitHashTable(&i->assocData, &JimAssocDataHashTableType, i);
Jim_InitHashTable(&i->packages, &JimPackageHashTableType, NULL);
i->emptyObj = Jim_NewEmptyStringObj(i);
i->trueObj = Jim_NewIntObj(i, 1);
i->falseObj = Jim_NewIntObj(i, 0);
i->framePtr = i->topFramePtr = JimCreateCallFrame(i, NULL, i->emptyObj);
i->result = i->emptyObj;
i->stackTrace = Jim_NewListObj(i, NULL, 0);
i->unknown = Jim_NewStringObj(i, "unknown", -1);
i->defer = Jim_NewStringObj(i, "jim::defer", -1);
i->errorProc = i->emptyObj;
i->nullScriptObj = Jim_NewEmptyStringObj(i);
i->evalFrame = &i->topEvalFrame;
i->currentFilenameObj = Jim_NewEmptyStringObj(i);
Jim_IncrRefCount(i->emptyObj);
Jim_IncrRefCount(i->result);
Jim_IncrRefCount(i->stackTrace);
Jim_IncrRefCount(i->unknown);
Jim_IncrRefCount(i->defer);
Jim_IncrRefCount(i->nullScriptObj);
Jim_IncrRefCount(i->errorProc);
Jim_IncrRefCount(i->trueObj);
Jim_IncrRefCount(i->falseObj);
Jim_IncrRefCount(i->currentFilenameObj);
Jim_SetVariableStrWithStr(i, JIM_LIBPATH, TCL_LIBRARY);
Jim_SetVariableStrWithStr(i, JIM_INTERACTIVE, "0");
Jim_SetVariableStrWithStr(i, "tcl_platform(engine)", "Jim");
Jim_SetVariableStrWithStr(i, "tcl_platform(os)", TCL_PLATFORM_OS);
Jim_SetVariableStrWithStr(i, "tcl_platform(platform)", TCL_PLATFORM_PLATFORM);
Jim_SetVariableStrWithStr(i, "tcl_platform(pathSeparator)", TCL_PLATFORM_PATH_SEPARATOR);
Jim_SetVariableStrWithStr(i, "tcl_platform(byteOrder)", Jim_IsBigEndian() ? "bigEndian" : "littleEndian");
Jim_SetVariableStrWithStr(i, "tcl_platform(threaded)", "0");
Jim_SetVariableStrWithStr(i, "tcl_platform(bootstrap)", "0");
Jim_SetVariableStr(i, "tcl_platform(pointerSize)", Jim_NewIntObj(i, sizeof(void *)));
Jim_SetVariableStr(i, "tcl_platform(wordSize)", Jim_NewIntObj(i, sizeof(jim_wide)));
Jim_SetVariableStr(i, "tcl_platform(stackFormat)", Jim_NewIntObj(i, 4));
return i;
}
void Jim_FreeInterp(Jim_Interp *i)
{
Jim_CallFrame *cf, *cfx;
Jim_Obj *objPtr, *nextObjPtr;
i->quitting = 1;
for (cf = i->framePtr; cf; cf = cfx) {
JimInvokeDefer(i, JIM_OK);
cfx = cf->parent;
JimFreeCallFrame(i, cf, JIM_FCF_FULL);
}
Jim_DecrRefCount(i, i->emptyObj);
Jim_DecrRefCount(i, i->trueObj);
Jim_DecrRefCount(i, i->falseObj);
Jim_DecrRefCount(i, i->result);
Jim_DecrRefCount(i, i->stackTrace);
Jim_DecrRefCount(i, i->errorProc);
Jim_DecrRefCount(i, i->unknown);
Jim_DecrRefCount(i, i->defer);
Jim_DecrRefCount(i, i->nullScriptObj);
Jim_DecrRefCount(i, i->currentFilenameObj);
Jim_InterpIncrProcEpoch(i);
Jim_FreeHashTable(&i->commands);
#ifdef JIM_REFERENCES
Jim_FreeHashTable(&i->references);
#endif
Jim_FreeHashTable(&i->packages);
Jim_Free(i->prngState);
Jim_FreeHashTable(&i->assocData);
if (i->traceCmdObj) {
Jim_DecrRefCount(i, i->traceCmdObj);
}
#ifdef JIM_MAINTAINER
if (i->liveList != NULL) {
objPtr = i->liveList;
printf("\n-------------------------------------\n");
printf("Objects still in the free list:\n");
|
| ︙ | ︙ | |||
10669 10670 10671 10672 10673 10674 10675 |
}
}
Jim_SetResultFormatted(interp, "bad level \"%s\"", str);
return NULL;
}
| | < < | < | | | | > | > > | | > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > | > > > > > | > > > > > | > > > > < < | < < < < | < < | < < < < < < | < < | < < | < | | | < | | | < < < | < < | < < < | < < < < < < < | 11495 11496 11497 11498 11499 11500 11501 11502 11503 11504 11505 11506 11507 11508 11509 11510 11511 11512 11513 11514 11515 11516 11517 11518 11519 11520 11521 11522 11523 11524 11525 11526 11527 11528 11529 11530 11531 11532 11533 11534 11535 11536 11537 11538 11539 11540 11541 11542 11543 11544 11545 11546 11547 11548 11549 11550 11551 11552 11553 11554 11555 11556 11557 11558 11559 11560 11561 11562 11563 11564 11565 11566 11567 11568 11569 11570 11571 11572 11573 11574 11575 11576 11577 11578 11579 11580 11581 11582 11583 11584 11585 11586 11587 11588 11589 11590 11591 11592 11593 11594 11595 11596 11597 11598 11599 11600 11601 11602 11603 11604 11605 11606 11607 11608 11609 11610 11611 11612 11613 |
}
}
Jim_SetResultFormatted(interp, "bad level \"%s\"", str);
return NULL;
}
static Jim_CallFrame *JimGetCallFrameByInteger(Jim_Interp *interp, long level)
{
Jim_CallFrame *framePtr;
if (level == 0) {
return interp->framePtr;
}
if (level < 0) {
level = interp->framePtr->level + level;
}
if (level > 0) {
for (framePtr = interp->framePtr; framePtr; framePtr = framePtr->parent) {
if (framePtr->level == level) {
return framePtr;
}
}
}
return NULL;
}
static Jim_EvalFrame *JimGetEvalFrameByProcLevel(Jim_Interp *interp, int proclevel)
{
Jim_EvalFrame *evalFrame;
if (proclevel == 0) {
return interp->evalFrame;
}
if (proclevel < 0) {
proclevel = interp->procLevel + proclevel;
}
if (proclevel >= 0) {
for (evalFrame = interp->evalFrame; evalFrame; evalFrame = evalFrame->parent) {
if (evalFrame->procLevel == proclevel) {
return evalFrame;
}
}
}
return NULL;
}
static Jim_Obj *JimProcForEvalFrame(Jim_Interp *interp, Jim_EvalFrame *frame)
{
if (frame == interp->evalFrame || (frame->cmd && frame->cmd->cmdNameObj)) {
Jim_EvalFrame *e;
for (e = frame->parent; e; e = e->parent) {
if (e->cmd && e->cmd->isproc && e->cmd->cmdNameObj) {
break;
}
}
if (e && e->cmd && e->cmd->cmdNameObj) {
return e->cmd->cmdNameObj;
}
}
return NULL;
}
static void JimAddStackFrame(Jim_Interp *interp, Jim_EvalFrame *frame, Jim_Obj *listObj)
{
Jim_Obj *procNameObj = JimProcForEvalFrame(interp, frame);
Jim_Obj *fileNameObj = interp->emptyObj;
int linenr = 1;
if (frame->scriptObj) {
ScriptObj *script = JimGetScript(interp, frame->scriptObj);
fileNameObj = script->fileNameObj;
linenr = script->linenr;
}
Jim_ListAppendElement(interp, listObj, procNameObj ? procNameObj : interp->emptyObj);
Jim_ListAppendElement(interp, listObj, fileNameObj);
Jim_ListAppendElement(interp, listObj, Jim_NewIntObj(interp, linenr));
Jim_ListAppendElement(interp, listObj, Jim_NewListObj(interp, frame->argv, frame->argc));
}
static void JimSetStackTrace(Jim_Interp *interp, Jim_Obj *stackTraceObj)
{
Jim_IncrRefCount(stackTraceObj);
Jim_DecrRefCount(interp, interp->stackTrace);
interp->stackTrace = stackTraceObj;
interp->errorFlag = 1;
}
static void JimSetErrorStack(Jim_Interp *interp)
{
if (!interp->errorFlag) {
int i;
Jim_Obj *stackTrace = Jim_NewListObj(interp, NULL, 0);
for (i = 0; i <= interp->procLevel; i++) {
Jim_EvalFrame *frame = JimGetEvalFrameByProcLevel(interp, -i);
if (frame) {
JimAddStackFrame(interp, frame, stackTrace);
}
}
JimSetStackTrace(interp, stackTrace);
}
}
int Jim_SetAssocData(Jim_Interp *interp, const char *key, Jim_InterpDeleteProc * delProc,
void *data)
{
AssocDataValue *assocEntryPtr = (AssocDataValue *) Jim_Alloc(sizeof(AssocDataValue));
|
| ︙ | ︙ | |||
10895 10896 10897 10898 10899 10900 10901 10902 10903 10904 10905 10906 10907 10908 |
{
if (objPtr->typePtr != &intObjType && SetIntFromAny(interp, objPtr, JIM_ERRMSG) == JIM_ERR)
return JIM_ERR;
*widePtr = JimWideValue(objPtr);
return JIM_OK;
}
static int JimGetWideNoErr(Jim_Interp *interp, Jim_Obj *objPtr, jim_wide * widePtr)
{
if (objPtr->typePtr != &intObjType && SetIntFromAny(interp, objPtr, JIM_NONE) == JIM_ERR)
return JIM_ERR;
*widePtr = JimWideValue(objPtr);
return JIM_OK;
| > > > > > > > > > > > > > > > > > > > > > > > > > > | 11734 11735 11736 11737 11738 11739 11740 11741 11742 11743 11744 11745 11746 11747 11748 11749 11750 11751 11752 11753 11754 11755 11756 11757 11758 11759 11760 11761 11762 11763 11764 11765 11766 11767 11768 11769 11770 11771 11772 11773 |
{
if (objPtr->typePtr != &intObjType && SetIntFromAny(interp, objPtr, JIM_ERRMSG) == JIM_ERR)
return JIM_ERR;
*widePtr = JimWideValue(objPtr);
return JIM_OK;
}
int Jim_GetWideExpr(Jim_Interp *interp, Jim_Obj *objPtr, jim_wide * widePtr)
{
int ret = JIM_OK;
if (objPtr->typePtr == &sourceObjType || objPtr->typePtr == NULL) {
SetIntFromAny(interp, objPtr, 0);
}
if (objPtr->typePtr == &intObjType) {
*widePtr = JimWideValue(objPtr);
}
else {
JimPanic((interp->safeexpr, "interp->safeexpr is set"));
interp->safeexpr++;
ret = Jim_EvalExpression(interp, objPtr);
interp->safeexpr--;
if (ret == JIM_OK) {
ret = Jim_GetWide(interp, Jim_GetResult(interp), widePtr);
}
if (ret != JIM_OK) {
Jim_SetResultFormatted(interp, "expected integer expression but got \"%#s\"", objPtr);
}
}
return ret;
}
static int JimGetWideNoErr(Jim_Interp *interp, Jim_Obj *objPtr, jim_wide * widePtr)
{
if (objPtr->typePtr != &intObjType && SetIntFromAny(interp, objPtr, JIM_NONE) == JIM_ERR)
return JIM_ERR;
*widePtr = JimWideValue(objPtr);
return JIM_OK;
|
| ︙ | ︙ | |||
10941 10942 10943 10944 10945 10946 10947 |
"double",
NULL,
NULL,
UpdateStringOfDouble,
JIM_TYPE_NONE,
};
| | | | 11806 11807 11808 11809 11810 11811 11812 11813 11814 11815 11816 11817 11818 11819 11820 11821 11822 11823 11824 |
"double",
NULL,
NULL,
UpdateStringOfDouble,
JIM_TYPE_NONE,
};
#if !HAVE_DECL_ISNAN
#undef isnan
#define isnan(X) ((X) != (X))
#endif
#if !HAVE_DECL_ISINF
#undef isinf
#define isinf(X) (1.0 / (X) == 0.0)
#endif
static void UpdateStringOfDouble(struct Jim_Obj *objPtr)
{
double value = objPtr->internalRep.doubleValue;
|
| ︙ | ︙ | |||
11076 11077 11078 11079 11080 11081 11082 11083 |
int Jim_GetBoolean(Jim_Interp *interp, Jim_Obj *objPtr, int * booleanPtr)
{
if (objPtr->typePtr != &intObjType && SetBooleanFromAny(interp, objPtr, JIM_ERRMSG) == JIM_ERR)
return JIM_ERR;
*booleanPtr = (int) JimWideValue(objPtr);
return JIM_OK;
}
| < < | > | | | | > > | | | | < > | < < < > | | 11941 11942 11943 11944 11945 11946 11947 11948 11949 11950 11951 11952 11953 11954 11955 11956 11957 11958 11959 11960 11961 11962 11963 11964 11965 11966 11967 11968 11969 11970 11971 11972 11973 11974 11975 11976 11977 11978 11979 11980 11981 |
int Jim_GetBoolean(Jim_Interp *interp, Jim_Obj *objPtr, int * booleanPtr)
{
if (objPtr->typePtr != &intObjType && SetBooleanFromAny(interp, objPtr, JIM_ERRMSG) == JIM_ERR)
return JIM_ERR;
*booleanPtr = (int) JimWideValue(objPtr);
return JIM_OK;
}
static const char * const jim_true_false_strings[8] = {
"1", "true", "yes", "on",
"0", "false", "no", "off"
};
static const int jim_true_false_lens[8] = {
1, 4, 3, 2,
1, 5, 2, 3,
};
static int SetBooleanFromAny(Jim_Interp *interp, Jim_Obj *objPtr, int flags)
{
int index = Jim_FindByName(Jim_String(objPtr), jim_true_false_strings,
sizeof(jim_true_false_strings) / sizeof(*jim_true_false_strings));
if (index < 0) {
if (flags & JIM_ERRMSG) {
Jim_SetResultFormatted(interp, "expected boolean but got \"%#s\"", objPtr);
}
return JIM_ERR;
}
Jim_FreeIntRep(interp, objPtr);
objPtr->typePtr = &intObjType;
objPtr->internalRep.wideValue = index < 4 ? 1 : 0;
return JIM_OK;
}
static void ListInsertElements(Jim_Obj *listPtr, int idx, int elemc, Jim_Obj *const *elemVec);
static void ListAppendElement(Jim_Obj *listPtr, Jim_Obj *objPtr);
static void FreeListInternalRep(Jim_Interp *interp, Jim_Obj *objPtr);
static void DupListInternalRep(Jim_Interp *interp, Jim_Obj *srcPtr, Jim_Obj *dupPtr);
|
| ︙ | ︙ | |||
11402 11403 11404 11405 11406 11407 11408 11409 11410 |
int strLen;
Jim_Obj *fileNameObj;
int linenr;
if (objPtr->typePtr == &listObjType) {
return JIM_OK;
}
if (Jim_IsDict(objPtr) && objPtr->bytes == NULL) {
| > < < < | < < < | < < | | | > > > > > | 12266 12267 12268 12269 12270 12271 12272 12273 12274 12275 12276 12277 12278 12279 12280 12281 12282 12283 12284 12285 12286 12287 12288 12289 12290 12291 12292 12293 12294 12295 |
int strLen;
Jim_Obj *fileNameObj;
int linenr;
if (objPtr->typePtr == &listObjType) {
return JIM_OK;
}
if (Jim_IsDict(objPtr) && objPtr->bytes == NULL) {
Jim_Dict *dict = objPtr->internalRep.dictValue;
objPtr->typePtr = &listObjType;
objPtr->internalRep.listValue.len = dict->len;
objPtr->internalRep.listValue.maxLen = dict->maxLen;
objPtr->internalRep.listValue.ele = dict->table;
Jim_Free(dict->ht);
Jim_Free(dict);
return JIM_OK;
}
if (objPtr->typePtr == &sourceObjType) {
fileNameObj = objPtr->internalRep.sourceValue.fileNameObj;
linenr = objPtr->internalRep.sourceValue.lineNumber;
|
| ︙ | ︙ | |||
11511 11512 11513 11514 11515 11516 11517 |
JIM_LSORT_ASCII,
JIM_LSORT_NOCASE,
JIM_LSORT_INTEGER,
JIM_LSORT_REAL,
JIM_LSORT_COMMAND
} type;
int order;
| | | | | | 12373 12374 12375 12376 12377 12378 12379 12380 12381 12382 12383 12384 12385 12386 12387 12388 12389 12390 12391 12392 12393 12394 12395 12396 12397 12398 12399 12400 |
JIM_LSORT_ASCII,
JIM_LSORT_NOCASE,
JIM_LSORT_INTEGER,
JIM_LSORT_REAL,
JIM_LSORT_COMMAND
} type;
int order;
Jim_Obj **indexv;
int indexc;
int unique;
int (*subfn)(Jim_Obj **, Jim_Obj **);
};
static struct lsort_info *sort_info;
static int ListSortIndexHelper(Jim_Obj **lhsObj, Jim_Obj **rhsObj)
{
Jim_Obj *lObj, *rObj;
if (Jim_ListIndices(sort_info->interp, *lhsObj, sort_info->indexv, sort_info->indexc, &lObj, JIM_ERRMSG) != JIM_OK ||
Jim_ListIndices(sort_info->interp, *rhsObj, sort_info->indexv, sort_info->indexc, &rObj, JIM_ERRMSG) != JIM_OK) {
longjmp(sort_info->jmpbuf, JIM_ERR);
}
return sort_info->subfn(&lObj, &rObj);
}
static int ListSortString(Jim_Obj **lhsObj, Jim_Obj **rhsObj)
|
| ︙ | ︙ | |||
11661 11662 11663 11664 11665 11666 11667 |
break;
default:
fn = NULL;
JimPanic((1, "ListSort called with invalid sort type"));
return -1;
}
| | > > > > > > > > > > > > > > > > < | < | < < < | < < | 12523 12524 12525 12526 12527 12528 12529 12530 12531 12532 12533 12534 12535 12536 12537 12538 12539 12540 12541 12542 12543 12544 12545 12546 12547 12548 12549 12550 12551 12552 12553 12554 12555 12556 12557 12558 12559 12560 12561 12562 12563 12564 12565 12566 12567 12568 12569 12570 12571 12572 12573 12574 12575 12576 12577 12578 12579 12580 12581 12582 12583 12584 12585 |
break;
default:
fn = NULL;
JimPanic((1, "ListSort called with invalid sort type"));
return -1;
}
if (info->indexc) {
info->subfn = fn;
fn = ListSortIndexHelper;
}
if ((rc = setjmp(info->jmpbuf)) == 0) {
qsort(vector, len, sizeof(Jim_Obj *), (qsort_comparator *) fn);
if (info->unique && len > 1) {
ListRemoveDuplicates(listObjPtr, fn);
}
Jim_InvalidateStringRep(listObjPtr);
}
sort_info = prev_info;
return rc;
}
static void ListEnsureLength(Jim_Obj *listPtr, int idx)
{
assert(idx >= 0);
if (idx >= listPtr->internalRep.listValue.maxLen) {
if (idx < 4) {
idx = 4;
}
listPtr->internalRep.listValue.ele = Jim_Realloc(listPtr->internalRep.listValue.ele,
sizeof(Jim_Obj *) * idx);
listPtr->internalRep.listValue.maxLen = idx;
}
}
static void ListInsertElements(Jim_Obj *listPtr, int idx, int elemc, Jim_Obj *const *elemVec)
{
int currentLen = listPtr->internalRep.listValue.len;
int requiredLen = currentLen + elemc;
int i;
Jim_Obj **point;
if (requiredLen > listPtr->internalRep.listValue.maxLen) {
if (currentLen) {
requiredLen *= 2;
}
ListEnsureLength(listPtr, requiredLen);
}
if (idx < 0) {
idx = currentLen;
}
point = listPtr->internalRep.listValue.ele + idx;
memmove(point + elemc, point, (currentLen - idx) * sizeof(Jim_Obj *));
for (i = 0; i < elemc; ++i) {
|
| ︙ | ︙ | |||
11784 11785 11786 11787 11788 11789 11790 11791 11792 11793 11794 11795 11796 11797 |
if (flags & JIM_ERRMSG) {
Jim_SetResultString(interp, "list index out of range", -1);
}
return JIM_ERR;
}
return JIM_OK;
}
static int ListSetIndex(Jim_Interp *interp, Jim_Obj *listPtr, int idx,
Jim_Obj *newObjPtr, int flags)
{
SetListFromAny(interp, listPtr);
if ((idx >= 0 && idx >= listPtr->internalRep.listValue.len) ||
(idx < 0 && (-idx - 1) >= listPtr->internalRep.listValue.len)) {
| > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 12655 12656 12657 12658 12659 12660 12661 12662 12663 12664 12665 12666 12667 12668 12669 12670 12671 12672 12673 12674 12675 12676 12677 12678 12679 12680 12681 12682 12683 12684 12685 12686 12687 12688 12689 12690 12691 12692 12693 12694 12695 12696 12697 12698 12699 12700 12701 12702 12703 12704 12705 12706 12707 12708 12709 |
if (flags & JIM_ERRMSG) {
Jim_SetResultString(interp, "list index out of range", -1);
}
return JIM_ERR;
}
return JIM_OK;
}
static int Jim_ListIndices(Jim_Interp *interp, Jim_Obj *listPtr,
Jim_Obj *const *indexv, int indexc, Jim_Obj **resultObj, int flags)
{
int i;
int static_idxes[5];
int *idxes = static_idxes;
int ret = JIM_OK;
if (indexc > sizeof(static_idxes) / sizeof(*static_idxes)) {
idxes = Jim_Alloc(indexc * sizeof(*idxes));
}
for (i = 0; i < indexc; i++) {
ret = Jim_GetIndex(interp, indexv[i], &idxes[i]);
if (ret != JIM_OK) {
goto err;
}
}
for (i = 0; i < indexc; i++) {
Jim_Obj *objPtr = Jim_ListGetIndex(interp, listPtr, idxes[i]);
if (!objPtr) {
if (flags & JIM_ERRMSG) {
if (idxes[i] < 0 || idxes[i] > Jim_ListLength(interp, listPtr)) {
Jim_SetResultFormatted(interp, "index \"%#s\" out of range", indexv[i]);
}
else {
Jim_SetResultFormatted(interp, "element %#s missing from sublist \"%#s\"", indexv[i], listPtr);
}
}
return -1;
}
listPtr = objPtr;
}
*resultObj = listPtr;
err:
if (idxes != static_idxes)
Jim_Free(idxes);
return ret;
}
static int ListSetIndex(Jim_Interp *interp, Jim_Obj *listPtr, int idx,
Jim_Obj *newObjPtr, int flags)
{
SetListFromAny(interp, listPtr);
if ((idx >= 0 && idx >= listPtr->internalRep.listValue.len) ||
(idx < 0 && (-idx - 1) >= listPtr->internalRep.listValue.len)) {
|
| ︙ | ︙ | |||
11819 11820 11821 11822 11823 11824 11825 |
return JIM_ERR;
if ((shared = Jim_IsShared(objPtr)))
varObjPtr = objPtr = Jim_DuplicateObj(interp, objPtr);
for (i = 0; i < indexc - 1; i++) {
listObjPtr = objPtr;
if (Jim_GetIndex(interp, indexv[i], &idx) != JIM_OK)
goto err;
| > | > > | 12731 12732 12733 12734 12735 12736 12737 12738 12739 12740 12741 12742 12743 12744 12745 12746 12747 12748 |
return JIM_ERR;
if ((shared = Jim_IsShared(objPtr)))
varObjPtr = objPtr = Jim_DuplicateObj(interp, objPtr);
for (i = 0; i < indexc - 1; i++) {
listObjPtr = objPtr;
if (Jim_GetIndex(interp, indexv[i], &idx) != JIM_OK)
goto err;
objPtr = Jim_ListGetIndex(interp, listObjPtr, idx);
if (objPtr == NULL) {
Jim_SetResultFormatted(interp, "index \"%#s\" out of range", indexv[i]);
goto err;
}
if (Jim_IsShared(objPtr)) {
objPtr = Jim_DuplicateObj(interp, objPtr);
ListSetIndex(interp, listObjPtr, idx, objPtr, JIM_NONE);
}
Jim_InvalidateStringRep(listObjPtr);
|
| ︙ | ︙ | |||
11946 11947 11948 11949 11950 11951 11952 | static void FreeDictInternalRep(Jim_Interp *interp, Jim_Obj *objPtr); static void DupDictInternalRep(Jim_Interp *interp, Jim_Obj *srcPtr, Jim_Obj *dupPtr); static void UpdateStringOfDict(struct Jim_Obj *objPtr); static int SetDictFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr); | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | > > | | > | | > > > > > > > > > > > > > > > > > > > > > > > > > | > | > > > > | > > | > > > | > > > | > > > > > > | > | > | > > > | | < > | | > > | > > > > > | > > | > > | | > > | > > > > > > > > > > > > > | > > > > > > | > > > > | > > > > > > > > > > > > | > > > > | > > > | > < < | < | | | < | | | > | | > | | | < > < | | > > | > > | | > > | > | > > > > | > > > > > | | | > > > | > > > > > > > > > > > | | > > > | > > > > > > > > > > > > > > > > > > > > > > > > > | > | 12861 12862 12863 12864 12865 12866 12867 12868 12869 12870 12871 12872 12873 12874 12875 12876 12877 12878 12879 12880 12881 12882 12883 12884 12885 12886 12887 12888 12889 12890 12891 12892 12893 12894 12895 12896 12897 12898 12899 12900 12901 12902 12903 12904 12905 12906 12907 12908 12909 12910 12911 12912 12913 12914 12915 12916 12917 12918 12919 12920 12921 12922 12923 12924 12925 12926 12927 12928 12929 12930 12931 12932 12933 12934 12935 12936 12937 12938 12939 12940 12941 12942 12943 12944 12945 12946 12947 12948 12949 12950 12951 12952 12953 12954 12955 12956 12957 12958 12959 12960 12961 12962 12963 12964 12965 12966 12967 12968 12969 12970 12971 12972 12973 12974 12975 12976 12977 12978 12979 12980 12981 12982 12983 12984 12985 12986 12987 12988 12989 12990 12991 12992 12993 12994 12995 12996 12997 12998 12999 13000 13001 13002 13003 13004 13005 13006 13007 13008 13009 13010 13011 13012 13013 13014 13015 13016 13017 13018 13019 13020 13021 13022 13023 13024 13025 13026 13027 13028 13029 13030 13031 13032 13033 13034 13035 13036 13037 13038 13039 13040 13041 13042 13043 13044 13045 13046 13047 13048 13049 13050 13051 13052 13053 13054 13055 13056 13057 13058 13059 13060 13061 13062 13063 13064 13065 13066 13067 13068 13069 13070 13071 13072 13073 13074 13075 13076 13077 13078 13079 13080 13081 13082 13083 13084 13085 13086 13087 13088 13089 13090 13091 13092 13093 13094 13095 13096 13097 13098 13099 13100 13101 13102 13103 13104 13105 13106 13107 13108 13109 13110 13111 13112 13113 13114 13115 13116 13117 13118 13119 13120 13121 13122 13123 13124 13125 13126 13127 13128 13129 13130 13131 13132 13133 13134 13135 13136 13137 13138 13139 13140 13141 13142 13143 13144 13145 13146 13147 13148 13149 13150 13151 13152 13153 13154 13155 13156 13157 13158 13159 13160 13161 13162 13163 |
static void FreeDictInternalRep(Jim_Interp *interp, Jim_Obj *objPtr);
static void DupDictInternalRep(Jim_Interp *interp, Jim_Obj *srcPtr, Jim_Obj *dupPtr);
static void UpdateStringOfDict(struct Jim_Obj *objPtr);
static int SetDictFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr);
static const Jim_ObjType dictObjType = {
"dict",
FreeDictInternalRep,
DupDictInternalRep,
UpdateStringOfDict,
JIM_TYPE_NONE,
};
static void JimFreeDict(Jim_Interp *interp, Jim_Dict *dict)
{
int i;
for (i = 0; i < dict->len; i++) {
Jim_DecrRefCount(interp, dict->table[i]);
}
Jim_Free(dict->table);
Jim_Free(dict->ht);
Jim_Free(dict);
}
enum {
DICT_HASH_FIND = -1,
DICT_HASH_REMOVE = -2,
DICT_HASH_ADD = -3,
};
static int JimDictHashFind(Jim_Dict *dict, Jim_Obj *keyObjPtr, int op_tvoffset)
{
unsigned h = (JimObjectHTHashFunction(keyObjPtr) + dict->uniq);
unsigned idx = h & dict->sizemask;
int tvoffset = 0;
unsigned peturb = h;
unsigned first_removed = ~0;
if (dict->len) {
while ((tvoffset = dict->ht[idx].offset)) {
if (tvoffset == -1) {
if (first_removed == ~0) {
first_removed = idx;
}
}
else if (dict->ht[idx].hash == h) {
if (Jim_StringEqObj(keyObjPtr, dict->table[tvoffset - 1])) {
break;
}
}
peturb >>= 5;
idx = (5 * idx + 1 + peturb) & dict->sizemask;
}
}
switch (op_tvoffset) {
case DICT_HASH_FIND:
break;
case DICT_HASH_REMOVE:
if (tvoffset) {
dict->ht[idx].offset = -1;
dict->dummy++;
}
break;
case DICT_HASH_ADD:
if (tvoffset == 0) {
if (first_removed != ~0) {
idx = first_removed;
dict->dummy--;
}
dict->ht[idx].offset = dict->len + 1;
dict->ht[idx].hash = h;
}
break;
default:
assert(tvoffset);
dict->ht[idx].offset = op_tvoffset;
break;
}
return tvoffset;
}
static void JimDictExpandHashTable(Jim_Dict *dict, unsigned int size)
{
int i;
struct JimDictHashEntry *prevht = dict->ht;
int prevsize = dict->size;
dict->size = JimHashTableNextPower(size);
dict->sizemask = dict->size - 1;
dict->ht = Jim_Alloc(dict->size * sizeof(*dict->ht));
memset(dict->ht, 0, dict->size * sizeof(*dict->ht));
for (i = 0; i < prevsize; i++) {
if (prevht[i].offset > 0) {
unsigned h = prevht[i].hash;
unsigned idx = h & dict->sizemask;
unsigned peturb = h;
while (dict->ht[idx].offset) {
peturb >>= 5;
idx = (5 * idx + 1 + peturb) & dict->sizemask;
}
dict->ht[idx].offset = prevht[i].offset;
dict->ht[idx].hash = h;
}
}
Jim_Free(prevht);
}
static int JimDictAdd(Jim_Dict *dict, Jim_Obj *keyObjPtr)
{
if (dict->size <= dict->len + dict->dummy) {
JimDictExpandHashTable(dict, dict->size ? dict->size * 2 : 8);
}
return JimDictHashFind(dict, keyObjPtr, DICT_HASH_ADD);
}
static Jim_Dict *JimDictNew(Jim_Interp *interp, int table_size, int ht_size)
{
Jim_Dict *dict = Jim_Alloc(sizeof(*dict));
memset(dict, 0, sizeof(*dict));
if (ht_size) {
JimDictExpandHashTable(dict, ht_size);
}
if (table_size) {
dict->table = Jim_Alloc(table_size * sizeof(*dict->table));
dict->maxLen = table_size;
}
#ifdef JIM_RANDOMISE_HASH
dict->uniq = (rand() ^ time(NULL) ^ clock());
#endif
return dict;
}
static void FreeDictInternalRep(Jim_Interp *interp, Jim_Obj *objPtr)
{
JimFreeDict(interp, objPtr->internalRep.dictValue);
}
static void DupDictInternalRep(Jim_Interp *interp, Jim_Obj *srcPtr, Jim_Obj *dupPtr)
{
Jim_Dict *oldDict = srcPtr->internalRep.dictValue;
int i;
Jim_Dict *newDict = JimDictNew(interp, oldDict->maxLen, oldDict->size);
for (i = 0; i < oldDict->len; i++) {
newDict->table[i] = oldDict->table[i];
Jim_IncrRefCount(newDict->table[i]);
}
newDict->len = oldDict->len;
newDict->uniq = oldDict->uniq;
memcpy(newDict->ht, oldDict->ht, sizeof(*oldDict->ht) * oldDict->size);
dupPtr->internalRep.dictValue = newDict;
dupPtr->typePtr = &dictObjType;
}
static void UpdateStringOfDict(struct Jim_Obj *objPtr)
{
JimMakeListStringRep(objPtr, objPtr->internalRep.dictValue->table, objPtr->internalRep.dictValue->len);
}
static int SetDictFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr)
{
int listlen;
if (objPtr->typePtr == &dictObjType) {
return JIM_OK;
}
if (Jim_IsList(objPtr) && Jim_IsShared(objPtr)) {
Jim_String(objPtr);
}
listlen = Jim_ListLength(interp, objPtr);
if (listlen % 2) {
Jim_SetResultString(interp, "missing value to go with key", -1);
return JIM_ERR;
}
else {
Jim_Dict *dict = JimDictNew(interp, 0, listlen);
int i;
dict->table = objPtr->internalRep.listValue.ele;
dict->maxLen = objPtr->internalRep.listValue.maxLen;
for (i = 0; i < listlen; i += 2) {
int tvoffset = JimDictAdd(dict, dict->table[i]);
if (tvoffset) {
Jim_DecrRefCount(interp, dict->table[tvoffset]);
dict->table[tvoffset] = dict->table[i + 1];
Jim_DecrRefCount(interp, dict->table[i]);
}
else {
if (dict->len != i) {
dict->table[dict->len++] = dict->table[i];
dict->table[dict->len++] = dict->table[i + 1];
}
else {
dict->len += 2;
}
}
}
objPtr->typePtr = &dictObjType;
objPtr->internalRep.dictValue = dict;
return JIM_OK;
}
}
static int DictAddElement(Jim_Interp *interp, Jim_Obj *objPtr,
Jim_Obj *keyObjPtr, Jim_Obj *valueObjPtr)
{
Jim_Dict *dict = objPtr->internalRep.dictValue;
if (valueObjPtr == NULL) {
int tvoffset = JimDictHashFind(dict, keyObjPtr, DICT_HASH_REMOVE);
if (tvoffset) {
Jim_DecrRefCount(interp, dict->table[tvoffset - 1]);
Jim_DecrRefCount(interp, dict->table[tvoffset]);
dict->len -= 2;
if (tvoffset != dict->len + 1) {
dict->table[tvoffset - 1] = dict->table[dict->len];
dict->table[tvoffset] = dict->table[dict->len + 1];
JimDictHashFind(dict, dict->table[tvoffset - 1], tvoffset);
}
return JIM_OK;
}
return JIM_ERR;
}
else {
int tvoffset = JimDictAdd(dict, keyObjPtr);
if (tvoffset) {
Jim_IncrRefCount(valueObjPtr);
Jim_DecrRefCount(interp, dict->table[tvoffset]);
dict->table[tvoffset] = valueObjPtr;
}
else {
if (dict->maxLen == dict->len) {
if (dict->maxLen < 4) {
dict->maxLen = 4;
}
else {
dict->maxLen *= 2;
}
dict->table = Jim_Realloc(dict->table, dict->maxLen * sizeof(*dict->table));
}
Jim_IncrRefCount(keyObjPtr);
Jim_IncrRefCount(valueObjPtr);
dict->table[dict->len++] = keyObjPtr;
dict->table[dict->len++] = valueObjPtr;
}
return JIM_OK;
}
}
int Jim_DictAddElement(Jim_Interp *interp, Jim_Obj *objPtr,
Jim_Obj *keyObjPtr, Jim_Obj *valueObjPtr)
{
JimPanic((Jim_IsShared(objPtr), "Jim_DictAddElement called with shared object"));
if (SetDictFromAny(interp, objPtr) != JIM_OK) {
|
| ︙ | ︙ | |||
12126 12127 12128 12129 12130 12131 12132 |
int i;
JimPanic((len % 2, "Jim_NewDictObj() 'len' argument must be even"));
objPtr = Jim_NewObj(interp);
objPtr->typePtr = &dictObjType;
objPtr->bytes = NULL;
| | | | | | | > < | | | | | | < | > > | > | | | | > > > | | > > | | 13173 13174 13175 13176 13177 13178 13179 13180 13181 13182 13183 13184 13185 13186 13187 13188 13189 13190 13191 13192 13193 13194 13195 13196 13197 13198 13199 13200 13201 13202 13203 13204 13205 13206 13207 13208 13209 13210 13211 13212 13213 13214 13215 13216 13217 13218 13219 13220 13221 13222 13223 13224 13225 13226 13227 13228 13229 13230 13231 13232 13233 |
int i;
JimPanic((len % 2, "Jim_NewDictObj() 'len' argument must be even"));
objPtr = Jim_NewObj(interp);
objPtr->typePtr = &dictObjType;
objPtr->bytes = NULL;
objPtr->internalRep.dictValue = JimDictNew(interp, len, len);
for (i = 0; i < len; i += 2)
DictAddElement(interp, objPtr, elements[i], elements[i + 1]);
return objPtr;
}
int Jim_DictKey(Jim_Interp *interp, Jim_Obj *dictPtr, Jim_Obj *keyPtr,
Jim_Obj **objPtrPtr, int flags)
{
int tvoffset;
Jim_Dict *dict;
if (SetDictFromAny(interp, dictPtr) != JIM_OK) {
return -1;
}
dict = dictPtr->internalRep.dictValue;
tvoffset = JimDictHashFind(dict, keyPtr, DICT_HASH_FIND);
if (tvoffset == 0) {
if (flags & JIM_ERRMSG) {
Jim_SetResultFormatted(interp, "key \"%#s\" not known in dictionary", keyPtr);
}
return JIM_ERR;
}
*objPtrPtr = dict->table[tvoffset];
return JIM_OK;
}
Jim_Obj **Jim_DictPairs(Jim_Interp *interp, Jim_Obj *dictPtr, int *len)
{
if (Jim_IsList(dictPtr)) {
Jim_Obj **table;
JimListGetElements(interp, dictPtr, len, &table);
if (*len % 2 == 0) {
return table;
}
}
if (SetDictFromAny(interp, dictPtr) != JIM_OK) {
*len = 1;
return NULL;
}
*len = dictPtr->internalRep.dictValue->len;
return dictPtr->internalRep.dictValue->table;
}
int Jim_DictKeysVector(Jim_Interp *interp, Jim_Obj *dictPtr,
Jim_Obj *const *keyv, int keyc, Jim_Obj **objPtrPtr, int flags)
{
int i;
|
| ︙ | ︙ | |||
12252 12253 12254 12255 12256 12257 12258 |
}
Jim_InvalidateStringRep(objPtr);
Jim_InvalidateStringRep(varObjPtr);
if (Jim_SetVariable(interp, varNamePtr, varObjPtr) != JIM_OK) {
goto err;
}
| > > | > | 13306 13307 13308 13309 13310 13311 13312 13313 13314 13315 13316 13317 13318 13319 13320 13321 13322 13323 |
}
Jim_InvalidateStringRep(objPtr);
Jim_InvalidateStringRep(varObjPtr);
if (Jim_SetVariable(interp, varNamePtr, varObjPtr) != JIM_OK) {
goto err;
}
if (!(flags & JIM_NORESULT)) {
Jim_SetResult(interp, varObjPtr);
}
return JIM_OK;
err:
if (shared) {
Jim_FreeNewObj(interp, varObjPtr);
}
return JIM_ERR;
}
|
| ︙ | ︙ | |||
12279 12280 12281 12282 12283 12284 12285 |
static void UpdateStringOfIndex(struct Jim_Obj *objPtr)
{
if (objPtr->internalRep.intValue == -1) {
JimSetStringBytes(objPtr, "end");
}
else {
char buf[JIM_INTEGER_SPACE + 1];
| | > | > | > > > > > | | > | > < > | < | | < < | < > > | < < < < < < < | 13336 13337 13338 13339 13340 13341 13342 13343 13344 13345 13346 13347 13348 13349 13350 13351 13352 13353 13354 13355 13356 13357 13358 13359 13360 13361 13362 13363 13364 13365 13366 13367 13368 13369 13370 13371 13372 13373 13374 13375 13376 13377 13378 13379 13380 13381 13382 13383 13384 13385 13386 13387 13388 13389 13390 13391 13392 13393 13394 13395 13396 13397 13398 13399 13400 13401 |
static void UpdateStringOfIndex(struct Jim_Obj *objPtr)
{
if (objPtr->internalRep.intValue == -1) {
JimSetStringBytes(objPtr, "end");
}
else {
char buf[JIM_INTEGER_SPACE + 1];
if (objPtr->internalRep.intValue >= 0 || objPtr->internalRep.intValue == -INT_MAX) {
sprintf(buf, "%d", objPtr->internalRep.intValue);
}
else {
sprintf(buf, "end%d", objPtr->internalRep.intValue + 1);
}
JimSetStringBytes(objPtr, buf);
}
}
static int SetIndexFromAny(Jim_Interp *interp, Jim_Obj *objPtr)
{
jim_wide idx;
int end = 0;
const char *str;
Jim_Obj *exprObj = objPtr;
JimPanic((objPtr->refCount == 0, "SetIndexFromAny() called with zero refcount object"));
str = Jim_String(objPtr);
if (strncmp(str, "end", 3) == 0) {
end = 1;
str += 3;
idx = 0;
switch (*str) {
case '\0':
exprObj = NULL;
break;
case '-':
case '+':
exprObj = Jim_NewStringObj(interp, str, -1);
break;
default:
goto badindex;
}
}
if (exprObj) {
int ret;
Jim_IncrRefCount(exprObj);
ret = Jim_GetWideExpr(interp, exprObj, &idx);
Jim_DecrRefCount(interp, exprObj);
if (ret != JIM_OK) {
goto badindex;
}
}
if (end) {
if (idx > 0) {
idx = INT_MAX;
}
else {
idx--;
|
| ︙ | ︙ | |||
12352 12353 12354 12355 12356 12357 12358 |
Jim_FreeIntRep(interp, objPtr);
objPtr->typePtr = &indexObjType;
objPtr->internalRep.intValue = idx;
return JIM_OK;
badindex:
Jim_SetResultFormatted(interp,
| | | 13409 13410 13411 13412 13413 13414 13415 13416 13417 13418 13419 13420 13421 13422 13423 |
Jim_FreeIntRep(interp, objPtr);
objPtr->typePtr = &indexObjType;
objPtr->internalRep.intValue = idx;
return JIM_OK;
badindex:
Jim_SetResultFormatted(interp,
"bad index \"%#s\": must be intexpr or end?[+-]intexpr?", objPtr);
return JIM_ERR;
}
int Jim_GetIndex(Jim_Interp *interp, Jim_Obj *objPtr, int *indexPtr)
{
if (objPtr->typePtr == &intObjType) {
|
| ︙ | ︙ | |||
12477 12478 12479 12480 12481 12482 12483 12484 12485 12486 12487 12488 12489 12490 |
JIM_EXPROP_POW,
JIM_EXPROP_STREQ,
JIM_EXPROP_STRNE,
JIM_EXPROP_STRIN,
JIM_EXPROP_STRNI,
JIM_EXPROP_NOT,
JIM_EXPROP_BITNOT,
JIM_EXPROP_UNARYMINUS,
JIM_EXPROP_UNARYPLUS,
| > > > > | 13534 13535 13536 13537 13538 13539 13540 13541 13542 13543 13544 13545 13546 13547 13548 13549 13550 13551 |
JIM_EXPROP_POW,
JIM_EXPROP_STREQ,
JIM_EXPROP_STRNE,
JIM_EXPROP_STRIN,
JIM_EXPROP_STRNI,
JIM_EXPROP_STRLT,
JIM_EXPROP_STRGT,
JIM_EXPROP_STRLE,
JIM_EXPROP_STRGE,
JIM_EXPROP_NOT,
JIM_EXPROP_BITNOT,
JIM_EXPROP_UNARYMINUS,
JIM_EXPROP_UNARYPLUS,
|
| ︙ | ︙ | |||
12542 12543 12544 12545 12546 12547 12548 |
static int JimExprGetTerm(Jim_Interp *interp, struct JimExprNode *node, Jim_Obj **objPtrPtr);
static int JimExprGetTermBoolean(Jim_Interp *interp, struct JimExprNode *node);
static int JimExprEvalTermNode(Jim_Interp *interp, struct JimExprNode *node);
static int JimExprOpNumUnary(Jim_Interp *interp, struct JimExprNode *node)
{
int intresult = 1;
| | | 13603 13604 13605 13606 13607 13608 13609 13610 13611 13612 13613 13614 13615 13616 13617 |
static int JimExprGetTerm(Jim_Interp *interp, struct JimExprNode *node, Jim_Obj **objPtrPtr);
static int JimExprGetTermBoolean(Jim_Interp *interp, struct JimExprNode *node);
static int JimExprEvalTermNode(Jim_Interp *interp, struct JimExprNode *node);
static int JimExprOpNumUnary(Jim_Interp *interp, struct JimExprNode *node)
{
int intresult = 1;
int rc, bA = 0;
double dA, dC = 0;
jim_wide wA, wC = 0;
Jim_Obj *A;
if ((rc = JimExprGetTerm(interp, node->left, &A)) != JIM_OK) {
return rc;
}
|
| ︙ | ︙ | |||
12609 12610 12611 12612 12613 12614 12615 12616 12617 12618 12619 12620 12621 12622 12623 12624 12625 12626 12627 12628 12629 12630 12631 12632 12633 12634 12635 |
case JIM_EXPROP_NOT:
wC = !dA;
break;
default:
abort();
}
}
if (rc == JIM_OK) {
if (intresult) {
Jim_SetResultInt(interp, wC);
}
else {
Jim_SetResult(interp, Jim_NewDoubleObj(interp, dC));
}
}
Jim_DecrRefCount(interp, A);
return rc;
}
static double JimRandDouble(Jim_Interp *interp)
{
unsigned long x;
JimRandomBytes(interp, &x, sizeof(x));
| > > > > > > > > > | | 13670 13671 13672 13673 13674 13675 13676 13677 13678 13679 13680 13681 13682 13683 13684 13685 13686 13687 13688 13689 13690 13691 13692 13693 13694 13695 13696 13697 13698 13699 13700 13701 13702 13703 13704 13705 13706 13707 13708 13709 13710 13711 13712 13713 |
case JIM_EXPROP_NOT:
wC = !dA;
break;
default:
abort();
}
}
else if ((rc = Jim_GetBoolean(interp, A, &bA)) == JIM_OK) {
switch (node->type) {
case JIM_EXPROP_NOT:
wC = !bA;
break;
default:
abort();
}
}
if (rc == JIM_OK) {
if (intresult) {
Jim_SetResultInt(interp, wC);
}
else {
Jim_SetResult(interp, Jim_NewDoubleObj(interp, dC));
}
}
Jim_DecrRefCount(interp, A);
return rc;
}
static double JimRandDouble(Jim_Interp *interp)
{
unsigned long x;
JimRandomBytes(interp, &x, sizeof(x));
return (double)x / (double)~0UL;
}
static int JimExprOpIntUnary(Jim_Interp *interp, struct JimExprNode *node)
{
jim_wide wA;
Jim_Obj *A;
int rc;
|
| ︙ | ︙ | |||
13038 13039 13040 13041 13042 13043 13044 |
static int JimExprOpStrBin(Jim_Interp *interp, struct JimExprNode *node)
{
Jim_Obj *A, *B;
jim_wide wC;
| | > > > > > > > > > > > > > > > | 14108 14109 14110 14111 14112 14113 14114 14115 14116 14117 14118 14119 14120 14121 14122 14123 14124 14125 14126 14127 14128 14129 14130 14131 14132 14133 14134 14135 14136 14137 14138 14139 14140 14141 14142 14143 14144 14145 14146 14147 14148 14149 14150 14151 14152 14153 |
static int JimExprOpStrBin(Jim_Interp *interp, struct JimExprNode *node)
{
Jim_Obj *A, *B;
jim_wide wC;
int comp, rc;
if ((rc = JimExprGetTerm(interp, node->left, &A)) != JIM_OK) {
return rc;
}
if ((rc = JimExprGetTerm(interp, node->right, &B)) != JIM_OK) {
Jim_DecrRefCount(interp, A);
return rc;
}
switch (node->type) {
case JIM_EXPROP_STREQ:
case JIM_EXPROP_STRNE:
wC = Jim_StringEqObj(A, B);
if (node->type == JIM_EXPROP_STRNE) {
wC = !wC;
}
break;
case JIM_EXPROP_STRLT:
case JIM_EXPROP_STRGT:
case JIM_EXPROP_STRLE:
case JIM_EXPROP_STRGE:
comp = Jim_StringCompareObj(interp, A, B, 0);
if (node->type == JIM_EXPROP_STRLT) {
wC = comp == -1;
} else if (node->type == JIM_EXPROP_STRGT) {
wC = comp == 1;
} else if (node->type == JIM_EXPROP_STRLE) {
wC = comp == -1 || comp == 0;
} else {
wC = comp == 0 || comp == 1;
}
break;
case JIM_EXPROP_STRIN:
wC = JimSearchList(interp, B, A);
break;
case JIM_EXPROP_STRNI:
wC = !JimSearchList(interp, B, A);
break;
|
| ︙ | ︙ | |||
13194 13195 13196 13197 13198 13199 13200 13201 13202 13203 13204 13205 13206 13207 |
OPRINIT_ATTR("**", 120, 2, JimExprOpBin, OP_RIGHT_ASSOC),
OPRINIT("eq", 60, 2, JimExprOpStrBin),
OPRINIT("ne", 60, 2, JimExprOpStrBin),
OPRINIT("in", 55, 2, JimExprOpStrBin),
OPRINIT("ni", 55, 2, JimExprOpStrBin),
OPRINIT_ATTR("!", 150, 1, JimExprOpNumUnary, OP_RIGHT_ASSOC),
OPRINIT_ATTR("~", 150, 1, JimExprOpIntUnary, OP_RIGHT_ASSOC),
OPRINIT_ATTR(" -", 150, 1, JimExprOpNumUnary, OP_RIGHT_ASSOC),
OPRINIT_ATTR(" +", 150, 1, JimExprOpNumUnary, OP_RIGHT_ASSOC),
| > > > > > | 14279 14280 14281 14282 14283 14284 14285 14286 14287 14288 14289 14290 14291 14292 14293 14294 14295 14296 14297 |
OPRINIT_ATTR("**", 120, 2, JimExprOpBin, OP_RIGHT_ASSOC),
OPRINIT("eq", 60, 2, JimExprOpStrBin),
OPRINIT("ne", 60, 2, JimExprOpStrBin),
OPRINIT("in", 55, 2, JimExprOpStrBin),
OPRINIT("ni", 55, 2, JimExprOpStrBin),
OPRINIT("lt", 75, 2, JimExprOpStrBin),
OPRINIT("gt", 75, 2, JimExprOpStrBin),
OPRINIT("le", 75, 2, JimExprOpStrBin),
OPRINIT("ge", 75, 2, JimExprOpStrBin),
OPRINIT_ATTR("!", 150, 1, JimExprOpNumUnary, OP_RIGHT_ASSOC),
OPRINIT_ATTR("~", 150, 1, JimExprOpIntUnary, OP_RIGHT_ASSOC),
OPRINIT_ATTR(" -", 150, 1, JimExprOpNumUnary, OP_RIGHT_ASSOC),
OPRINIT_ATTR(" +", 150, 1, JimExprOpNumUnary, OP_RIGHT_ASSOC),
|
| ︙ | ︙ | |||
13240 13241 13242 13243 13244 13245 13246 13247 |
#undef OPRINIT_ATTR
#define JIM_EXPR_OPERATORS_NUM \
(sizeof(Jim_ExprOperators)/sizeof(struct Jim_ExprOperator))
static int JimParseExpression(struct JimParserCtx *pc)
{
| > | | | | | | > > > > > > > > | 14330 14331 14332 14333 14334 14335 14336 14337 14338 14339 14340 14341 14342 14343 14344 14345 14346 14347 14348 14349 14350 14351 14352 14353 14354 14355 14356 14357 14358 14359 |
#undef OPRINIT_ATTR
#define JIM_EXPR_OPERATORS_NUM \
(sizeof(Jim_ExprOperators)/sizeof(struct Jim_ExprOperator))
static int JimParseExpression(struct JimParserCtx *pc)
{
while (1) {
while (isspace(UCHAR(*pc->p)) || (*(pc->p) == '\\' && *(pc->p + 1) == '\n')) {
if (*pc->p == '\n') {
pc->linenr++;
}
pc->p++;
pc->len--;
}
if (*pc->p == '#') {
JimParseComment(pc);
continue;
}
break;
}
pc->tline = pc->linenr;
pc->tstart = pc->p;
if (pc->len == 0) {
|
| ︙ | ︙ | |||
13370 13371 13372 13373 13374 13375 13376 |
}
}
return JIM_ERR;
}
static int JimParseExprBoolean(struct JimParserCtx *pc)
{
| < < | < < < | < | | | 14469 14470 14471 14472 14473 14474 14475 14476 14477 14478 14479 14480 14481 14482 14483 14484 14485 14486 14487 |
}
}
return JIM_ERR;
}
static int JimParseExprBoolean(struct JimParserCtx *pc)
{
int i;
for (i = 0; i < sizeof(jim_true_false_strings) / sizeof(*jim_true_false_strings); i++) {
if (strncmp(pc->p, jim_true_false_strings[i], jim_true_false_lens[i]) == 0) {
pc->p += jim_true_false_lens[i];
pc->len -= jim_true_false_lens[i];
pc->tend = pc->p - 1;
pc->tt = JIM_TT_EXPR_BOOLEAN;
return JIM_OK;
}
}
return JIM_ERR;
}
|
| ︙ | ︙ | |||
13477 13478 13479 13480 13481 13482 13483 |
static int SetExprFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr);
static const Jim_ObjType exprObjType = {
"expression",
FreeExprInternalRep,
DupExprInternalRep,
NULL,
| | | 14570 14571 14572 14573 14574 14575 14576 14577 14578 14579 14580 14581 14582 14583 14584 |
static int SetExprFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr);
static const Jim_ObjType exprObjType = {
"expression",
FreeExprInternalRep,
DupExprInternalRep,
NULL,
JIM_TYPE_NONE,
};
struct ExprTree
{
struct JimExprNode *expr;
struct JimExprNode *nodes;
|
| ︙ | ︙ | |||
13569 13570 13571 13572 13573 13574 13575 | } #endif #define EXPR_UNTIL_CLOSE 0x0001 #define EXPR_FUNC_ARGS 0x0002 #define EXPR_TERNARY 0x0004 | | < | 14662 14663 14664 14665 14666 14667 14668 14669 14670 14671 14672 14673 14674 14675 14676 |
}
#endif
#define EXPR_UNTIL_CLOSE 0x0001
#define EXPR_FUNC_ARGS 0x0002
#define EXPR_TERNARY 0x0004
static int ExprTreeBuildTree(Jim_Interp *interp, struct ExprBuilder *builder, int precedence, int flags, int exp_numterms) {
int rc;
struct JimExprNode *node;
int exp_stacklen = builder->stack.len + exp_numterms;
if (builder->level++ > 200) {
Jim_SetResultString(interp, "Expression too complex", -1);
|
| ︙ | ︙ | |||
13824 13825 13826 13827 13828 13829 13830 |
builder.parencount = 0;
builder.level = 0;
builder.token = builder.first_token = tokenlist->list;
builder.exprObjPtr = exprObjPtr;
builder.fileNameObj = fileNameObj;
| | | 14916 14917 14918 14919 14920 14921 14922 14923 14924 14925 14926 14927 14928 14929 14930 |
builder.parencount = 0;
builder.level = 0;
builder.token = builder.first_token = tokenlist->list;
builder.exprObjPtr = exprObjPtr;
builder.fileNameObj = fileNameObj;
builder.nodes = Jim_Alloc(sizeof(struct JimExprNode) * (tokenlist->count - 1));
memset(builder.nodes, 0, sizeof(struct JimExprNode) * (tokenlist->count - 1));
builder.next = builder.nodes;
Jim_InitStack(&builder.stack);
rc = ExprTreeBuildTree(interp, &builder, 0, 0, 1);
if (rc == JIM_OK) {
|
| ︙ | ︙ | |||
14002 14003 14004 14005 14006 14007 14008 14009 14010 14011 14012 14013 14014 14015 14016 14017 14018 14019 14020 14021 14022 |
if (objPtr) {
Jim_SetResult(interp, objPtr);
return JIM_OK;
}
return JIM_ERR;
case JIM_TT_ESC:
if (Jim_SubstObj(interp, node->objPtr, &objPtr, JIM_NONE) == JIM_OK) {
Jim_SetResult(interp, objPtr);
return JIM_OK;
}
return JIM_ERR;
case JIM_TT_CMD:
return Jim_EvalObj(interp, node->objPtr);
default:
return JIM_ERR;
}
}
| > > > > > > | 15094 15095 15096 15097 15098 15099 15100 15101 15102 15103 15104 15105 15106 15107 15108 15109 15110 15111 15112 15113 15114 15115 15116 15117 15118 15119 15120 |
if (objPtr) {
Jim_SetResult(interp, objPtr);
return JIM_OK;
}
return JIM_ERR;
case JIM_TT_ESC:
if (interp->safeexpr) {
return JIM_ERR;
}
if (Jim_SubstObj(interp, node->objPtr, &objPtr, JIM_NONE) == JIM_OK) {
Jim_SetResult(interp, objPtr);
return JIM_OK;
}
return JIM_ERR;
case JIM_TT_CMD:
if (interp->safeexpr) {
return JIM_ERR;
}
return Jim_EvalObj(interp, node->objPtr);
default:
return JIM_ERR;
}
}
|
| ︙ | ︙ | |||
14041 14042 14043 14044 14045 14046 14047 14048 14049 |
}
int Jim_EvalExpression(Jim_Interp *interp, Jim_Obj *exprObjPtr)
{
struct ExprTree *expr;
int retcode = JIM_OK;
expr = JimGetExpression(interp, exprObjPtr);
if (!expr) {
| > | > < > | | | 15139 15140 15141 15142 15143 15144 15145 15146 15147 15148 15149 15150 15151 15152 15153 15154 15155 15156 15157 15158 15159 15160 15161 15162 15163 15164 15165 15166 15167 15168 15169 15170 15171 15172 15173 15174 15175 15176 15177 15178 15179 15180 |
}
int Jim_EvalExpression(Jim_Interp *interp, Jim_Obj *exprObjPtr)
{
struct ExprTree *expr;
int retcode = JIM_OK;
Jim_IncrRefCount(exprObjPtr);
expr = JimGetExpression(interp, exprObjPtr);
if (!expr) {
retcode = JIM_ERR;
goto done;
}
#ifdef JIM_OPTIMIZATION
if (!interp->safeexpr) {
Jim_Obj *objPtr;
switch (expr->len) {
case 1:
objPtr = JimExprIntValOrVar(interp, expr->expr);
if (objPtr) {
Jim_SetResult(interp, objPtr);
goto done;
}
break;
case 2:
if (expr->expr->type == JIM_EXPROP_NOT) {
objPtr = JimExprIntValOrVar(interp, expr->expr->left);
if (objPtr && JimIsWide(objPtr)) {
Jim_SetResult(interp, JimWideValue(objPtr) ? interp->falseObj : interp->trueObj);
goto done;
}
}
break;
case 3:
objPtr = JimExprIntValOrVar(interp, expr->expr->left);
if (objPtr && JimIsWide(objPtr)) {
|
| ︙ | ︙ | |||
14102 14103 14104 14105 14106 14107 14108 |
case JIM_EXPROP_NUMNE:
cmpRes = wideValueA != wideValueB;
break;
default:
goto noopt;
}
Jim_SetResult(interp, cmpRes ? interp->trueObj : interp->falseObj);
| | | > > > > > > | 15202 15203 15204 15205 15206 15207 15208 15209 15210 15211 15212 15213 15214 15215 15216 15217 15218 15219 15220 15221 15222 15223 15224 15225 15226 15227 15228 15229 15230 15231 15232 15233 15234 15235 15236 |
case JIM_EXPROP_NUMNE:
cmpRes = wideValueA != wideValueB;
break;
default:
goto noopt;
}
Jim_SetResult(interp, cmpRes ? interp->trueObj : interp->falseObj);
goto done;
}
}
break;
}
}
noopt:
#endif
expr->inUse++;
retcode = JimExprEvalTermNode(interp, expr->expr);
Jim_FreeIntRep(interp, exprObjPtr);
exprObjPtr->typePtr = &exprObjType;
Jim_SetIntRepPtr(exprObjPtr, expr);
done:
Jim_DecrRefCount(interp, exprObjPtr);
return retcode;
}
int Jim_GetBoolFromExpr(Jim_Interp *interp, Jim_Obj *exprObjPtr, int *boolPtr)
{
int retcode = Jim_EvalExpression(interp, exprObjPtr);
|
| ︙ | ︙ | |||
14403 14404 14405 14406 14407 14408 14409 |
int c;
int n;
if (!sdescr && isspace(UCHAR(*str)))
break;
n = utf8_tounicode(str, &c);
| | | | | | > | | | | | | | 15509 15510 15511 15512 15513 15514 15515 15516 15517 15518 15519 15520 15521 15522 15523 15524 15525 15526 15527 15528 15529 15530 15531 15532 15533 15534 15535 15536 15537 15538 15539 15540 15541 15542 15543 15544 15545 15546 15547 15548 15549 15550 15551 15552 15553 15554 15555 15556 15557 15558 15559 15560 15561 15562 15563 15564 15565 15566 15567 15568 15569 15570 15571 15572 15573 15574 15575 15576 15577 15578 15579 15580 15581 15582 15583 15584 15585 15586 15587 15588 |
int c;
int n;
if (!sdescr && isspace(UCHAR(*str)))
break;
n = utf8_tounicode(str, &c);
if (sdescr && !JimCharsetMatch(sdescr, strlen(sdescr), c, JIM_CHARSET_SCAN))
break;
while (n--)
*p++ = *str++;
}
*p = 0;
return Jim_NewStringObjNoAlloc(interp, buffer, p - buffer);
}
static int ScanOneEntry(Jim_Interp *interp, const char *str, int pos, int str_bytelen,
ScanFmtStringObj * fmtObj, long idx, Jim_Obj **valObjPtr)
{
const char *tok;
const ScanFmtPartDescr *descr = &fmtObj->descr[idx];
size_t scanned = 0;
size_t anchor = pos;
int i;
Jim_Obj *tmpObj = NULL;
*valObjPtr = 0;
if (descr->prefix) {
for (i = 0; pos < str_bytelen && descr->prefix[i]; ++i) {
if (isspace(UCHAR(descr->prefix[i])))
while (pos < str_bytelen && isspace(UCHAR(str[pos])))
++pos;
else if (descr->prefix[i] != str[pos])
break;
else
++pos;
}
if (pos >= str_bytelen) {
return -1;
}
else if (descr->prefix[i] != 0)
return 0;
}
if (descr->type != 'c' && descr->type != '[' && descr->type != 'n')
while (isspace(UCHAR(str[pos])))
++pos;
scanned = pos - anchor;
if (descr->type == 'n') {
*valObjPtr = Jim_NewIntObj(interp, anchor + scanned);
}
else if (pos >= str_bytelen) {
return -1;
}
else if (descr->type == 'c') {
int c;
scanned += utf8_tounicode(&str[pos], &c);
*valObjPtr = Jim_NewIntObj(interp, c);
return scanned;
}
else {
if (descr->width > 0) {
size_t sLen = utf8_strlen(&str[pos], str_bytelen - pos);
size_t tLen = descr->width > sLen ? sLen : descr->width;
tmpObj = Jim_NewStringObjUtf8(interp, str + pos, tLen);
tok = tmpObj->bytes;
}
else {
|
| ︙ | ︙ | |||
14546 14547 14548 14549 14550 14551 14552 |
Jim_Obj *Jim_ScanString(Jim_Interp *interp, Jim_Obj *strObjPtr, Jim_Obj *fmtObjPtr, int flags)
{
size_t i, pos;
int scanned = 1;
const char *str = Jim_String(strObjPtr);
| | | 15653 15654 15655 15656 15657 15658 15659 15660 15661 15662 15663 15664 15665 15666 15667 |
Jim_Obj *Jim_ScanString(Jim_Interp *interp, Jim_Obj *strObjPtr, Jim_Obj *fmtObjPtr, int flags)
{
size_t i, pos;
int scanned = 1;
const char *str = Jim_String(strObjPtr);
int str_bytelen = Jim_Length(strObjPtr);
Jim_Obj *resultList = 0;
Jim_Obj **resultVec = 0;
int resultc;
Jim_Obj *emptyStr = 0;
ScanFmtStringObj *fmtObj;
|
| ︙ | ︙ | |||
14583 14584 14585 14586 14587 14588 14589 |
Jim_Obj *value = 0;
if (descr->type == 0)
continue;
if (scanned > 0)
| | | 15690 15691 15692 15693 15694 15695 15696 15697 15698 15699 15700 15701 15702 15703 15704 |
Jim_Obj *value = 0;
if (descr->type == 0)
continue;
if (scanned > 0)
scanned = ScanOneEntry(interp, str, pos, str_bytelen, fmtObj, i, &value);
if (scanned == -1 && i == 0)
goto eof;
pos += scanned;
|
| ︙ | ︙ | |||
14705 14706 14707 14708 14709 14710 14711 |
Jim_Obj *intObjPtr;
if (argc != 2 && argc != 3) {
Jim_WrongNumArgs(interp, 1, argv, "varName ?increment?");
return JIM_ERR;
}
if (argc == 3) {
| | | 15812 15813 15814 15815 15816 15817 15818 15819 15820 15821 15822 15823 15824 15825 15826 |
Jim_Obj *intObjPtr;
if (argc != 2 && argc != 3) {
Jim_WrongNumArgs(interp, 1, argv, "varName ?increment?");
return JIM_ERR;
}
if (argc == 3) {
if (Jim_GetWideExpr(interp, argv[2], &increment) != JIM_OK)
return JIM_ERR;
}
intObjPtr = Jim_GetVariable(interp, argv[1], JIM_UNSHARED);
if (!intObjPtr) {
wideValue = 0;
}
|
| ︙ | ︙ | |||
14741 14742 14743 14744 14745 14746 14747 14748 14749 14750 14751 14752 14753 14754 |
return JIM_OK;
}
#define JIM_EVAL_SARGV_LEN 8
#define JIM_EVAL_SINTV_LEN 8
static int JimUnknown(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
int retcode;
if (interp->unknown_called > 50) {
return JIM_ERR;
| > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 15848 15849 15850 15851 15852 15853 15854 15855 15856 15857 15858 15859 15860 15861 15862 15863 15864 15865 15866 15867 15868 15869 15870 15871 15872 15873 15874 15875 15876 15877 15878 15879 15880 15881 15882 15883 15884 15885 15886 15887 15888 15889 15890 15891 15892 15893 15894 15895 15896 15897 15898 15899 15900 |
return JIM_OK;
}
#define JIM_EVAL_SARGV_LEN 8
#define JIM_EVAL_SINTV_LEN 8
static int JimTraceCallback(Jim_Interp *interp, const char *type, int argc, Jim_Obj *const *argv)
{
JimPanic((interp->traceCmdObj == NULL, "xtrace invoked with no object"));
int ret;
Jim_Obj *nargv[7];
Jim_Obj *traceCmdObj = interp->traceCmdObj;
Jim_Obj *resultObj = Jim_GetResult(interp);
ScriptObj *script = JimGetScript(interp, interp->evalFrame->scriptObj);
nargv[0] = traceCmdObj;
nargv[1] = Jim_NewStringObj(interp, type, -1);
nargv[2] = script->fileNameObj;
nargv[3] = Jim_NewIntObj(interp, script->linenr);
nargv[4] = resultObj;
nargv[5] = argv[0];
nargv[6] = Jim_NewListObj(interp, argv + 1, argc - 1);
interp->traceCmdObj = NULL;
Jim_IncrRefCount(resultObj);
ret = Jim_EvalObjVector(interp, 7, nargv);
Jim_DecrRefCount(interp, resultObj);
if (ret == JIM_OK || ret == JIM_RETURN) {
interp->traceCmdObj = traceCmdObj;
Jim_SetEmptyResult(interp);
ret = JIM_OK;
}
else {
Jim_DecrRefCount(interp, traceCmdObj);
}
return ret;
}
static int JimUnknown(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
int retcode;
if (interp->unknown_called > 50) {
return JIM_ERR;
|
| ︙ | ︙ | |||
14762 14763 14764 14765 14766 14767 14768 14769 14770 14771 14772 14773 14774 14775 14776 14777 14778 14779 14780 14781 14782 14783 14784 |
interp->unknown_called++;
retcode = Jim_EvalObjPrefix(interp, interp->unknown, argc, argv);
interp->unknown_called--;
return retcode;
}
static int JimInvokeCommand(Jim_Interp *interp, int objc, Jim_Obj *const *objv)
{
int retcode;
Jim_Cmd *cmdPtr;
void *prevPrivData;
#if 0
printf("invoke");
int j;
for (j = 0; j < objc; j++) {
printf(" '%s'", Jim_String(objv[j]));
}
printf("\n");
#endif
| > > > > > > > > > > > > > > > > > > > > > > > > > > > > < < < < < < | | | | | < > > > > > > > > | | | | | | | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < > | > > > > > > | | < | < | < < | < < < | | 15908 15909 15910 15911 15912 15913 15914 15915 15916 15917 15918 15919 15920 15921 15922 15923 15924 15925 15926 15927 15928 15929 15930 15931 15932 15933 15934 15935 15936 15937 15938 15939 15940 15941 15942 15943 15944 15945 15946 15947 15948 15949 15950 15951 15952 15953 15954 15955 15956 15957 15958 15959 15960 15961 15962 15963 15964 15965 15966 15967 15968 15969 15970 15971 15972 15973 15974 15975 15976 15977 15978 15979 15980 15981 15982 15983 15984 15985 15986 15987 15988 15989 15990 15991 15992 15993 15994 15995 15996 15997 15998 15999 16000 16001 16002 16003 16004 16005 16006 16007 16008 16009 16010 16011 16012 16013 16014 16015 16016 16017 16018 16019 16020 16021 16022 16023 16024 16025 16026 16027 16028 16029 16030 16031 16032 16033 16034 16035 16036 16037 16038 16039 16040 16041 16042 16043 16044 16045 16046 16047 16048 16049 16050 16051 16052 16053 16054 16055 16056 16057 16058 16059 16060 16061 16062 16063 16064 16065 16066 16067 16068 16069 16070 16071 16072 16073 16074 16075 16076 16077 16078 16079 16080 16081 16082 16083 16084 16085 16086 16087 16088 16089 16090 16091 16092 16093 16094 16095 16096 16097 16098 16099 16100 16101 16102 16103 16104 16105 16106 16107 16108 16109 16110 16111 16112 16113 16114 16115 16116 16117 16118 16119 16120 16121 16122 16123 16124 |
interp->unknown_called++;
retcode = Jim_EvalObjPrefix(interp, interp->unknown, argc, argv);
interp->unknown_called--;
return retcode;
}
static void JimPushEvalFrame(Jim_Interp *interp, Jim_EvalFrame *frame, Jim_Obj *scriptObj)
{
memset(frame, 0, sizeof(*frame));
frame->parent = interp->evalFrame;
frame->level = frame->parent->level + 1;
frame->procLevel = interp->procLevel;
frame->framePtr = interp->framePtr;
if (scriptObj) {
frame->scriptObj = scriptObj;
}
else {
frame->scriptObj = frame->parent->scriptObj;
}
interp->evalFrame = frame;
#if 0
if (frame->scriptObj) {
printf("script: %.*s\n", 20, Jim_String(frame->scriptObj));
}
#endif
}
static void JimPopEvalFrame(Jim_Interp *interp)
{
interp->evalFrame = interp->evalFrame->parent;
}
static int JimInvokeCommand(Jim_Interp *interp, int objc, Jim_Obj *const *objv)
{
int retcode;
Jim_Cmd *cmdPtr;
void *prevPrivData;
Jim_Obj *tailcallObj = NULL;
#if 0
printf("invoke");
int j;
for (j = 0; j < objc; j++) {
printf(" '%s'", Jim_String(objv[j]));
}
printf("\n");
#endif
cmdPtr = Jim_GetCommand(interp, objv[0], JIM_ERRMSG);
if (cmdPtr == NULL) {
return JimUnknown(interp, objc, objv);
}
JimIncrCmdRefCount(cmdPtr);
if (interp->evalDepth == interp->maxEvalDepth) {
Jim_SetResultString(interp, "Infinite eval recursion", -1);
retcode = JIM_ERR;
goto out;
}
interp->evalDepth++;
prevPrivData = interp->cmdPrivData;
tailcall:
interp->evalFrame->argc = objc;
interp->evalFrame->argv = objv;
interp->evalFrame->cmd = cmdPtr;
if (!interp->traceCmdObj ||
(retcode = JimTraceCallback(interp, "cmd", objc, objv)) == JIM_OK) {
Jim_SetEmptyResult(interp);
if (cmdPtr->isproc) {
retcode = JimCallProcedure(interp, cmdPtr, objc, objv);
}
else {
interp->cmdPrivData = cmdPtr->u.native.privData;
retcode = cmdPtr->u.native.cmdProc(interp, objc, objv);
}
if (retcode == JIM_ERR) {
JimSetErrorStack(interp);
}
}
if (tailcallObj) {
Jim_DecrRefCount(interp, tailcallObj);
tailcallObj = NULL;
}
interp->evalFrame->argc = 0;
interp->evalFrame->argv = NULL;
if (retcode == JIM_EVAL && interp->framePtr->tailcallObj) {
JimDecrCmdRefCount(interp, cmdPtr);
cmdPtr = interp->framePtr->tailcallCmd;
interp->framePtr->tailcallCmd = NULL;
tailcallObj = interp->framePtr->tailcallObj;
interp->framePtr->tailcallObj = NULL;
objc = tailcallObj->internalRep.listValue.len;
objv = tailcallObj->internalRep.listValue.ele;
goto tailcall;
}
interp->cmdPrivData = prevPrivData;
interp->evalDepth--;
out:
JimDecrCmdRefCount(interp, cmdPtr);
if (retcode == JIM_ERR) {
JimSetErrorStack(interp);
}
if (interp->framePtr->tailcallObj) {
JimDecrCmdRefCount(interp, interp->framePtr->tailcallCmd);
Jim_DecrRefCount(interp, interp->framePtr->tailcallObj);
interp->framePtr->tailcallCmd = NULL;
interp->framePtr->tailcallObj = NULL;
}
return retcode;
}
int Jim_EvalObjVector(Jim_Interp *interp, int objc, Jim_Obj *const *objv)
{
int i, retcode;
Jim_EvalFrame frame;
for (i = 0; i < objc; i++)
Jim_IncrRefCount(objv[i]);
JimPushEvalFrame(interp, &frame, NULL);
retcode = JimInvokeCommand(interp, objc, objv);
JimPopEvalFrame(interp);
for (i = 0; i < objc; i++)
Jim_DecrRefCount(interp, objv[i]);
return retcode;
}
int Jim_EvalObjPrefix(Jim_Interp *interp, Jim_Obj *prefix, int objc, Jim_Obj *const *objv)
{
int ret;
Jim_Obj **nargv = Jim_Alloc((objc + 1) * sizeof(*nargv));
nargv[0] = prefix;
memcpy(&nargv[1], &objv[0], sizeof(nargv[0]) * objc);
ret = Jim_EvalObjVector(interp, objc + 1, nargv);
Jim_Free(nargv);
return ret;
}
static int JimSubstOneToken(Jim_Interp *interp, const ScriptToken *token, Jim_Obj **objPtrPtr)
{
Jim_Obj *objPtr;
int ret = JIM_ERR;
switch (token->type) {
case JIM_TT_STR:
case JIM_TT_ESC:
objPtr = token->objPtr;
break;
case JIM_TT_VAR:
objPtr = Jim_GetVariable(interp, token->objPtr, JIM_ERRMSG);
break;
case JIM_TT_DICTSUGAR:
objPtr = JimExpandDictSugar(interp, token->objPtr);
break;
case JIM_TT_EXPRSUGAR:
ret = Jim_EvalExpression(interp, token->objPtr);
if (ret == JIM_OK) {
objPtr = Jim_GetResult(interp);
}
else {
objPtr = NULL;
}
break;
case JIM_TT_CMD:
ret = Jim_EvalObj(interp, token->objPtr);
if (ret == JIM_OK || ret == JIM_RETURN) {
objPtr = interp->result;
} else {
objPtr = NULL;
}
break;
default:
JimPanic((1,
"default token type (%d) reached " "in Jim_SubstObj().", token->type));
objPtr = NULL;
break;
}
if (objPtr) {
*objPtrPtr = objPtr;
return JIM_OK;
}
return ret;
}
static Jim_Obj *JimInterpolateTokens(Jim_Interp *interp, const ScriptToken * token, int tokens, int flags)
{
int totlen = 0, i;
Jim_Obj **intv;
Jim_Obj *sintv[JIM_EVAL_SINTV_LEN];
|
| ︙ | ︙ | |||
15016 15017 15018 15019 15020 15021 15022 15023 15024 15025 15026 15027 15028 15029 15030 15031 15032 15033 15034 15035 15036 15037 15038 15039 15040 15041 15042 15043 15044 15045 15046 15047 15048 |
return objPtr;
}
static int JimEvalObjList(Jim_Interp *interp, Jim_Obj *listPtr)
{
int retcode = JIM_OK;
JimPanic((Jim_IsList(listPtr) == 0, "JimEvalObjList() invoked on non-list."));
if (listPtr->internalRep.listValue.len) {
Jim_IncrRefCount(listPtr);
retcode = JimInvokeCommand(interp,
listPtr->internalRep.listValue.len,
listPtr->internalRep.listValue.ele);
Jim_DecrRefCount(interp, listPtr);
}
return retcode;
}
int Jim_EvalObjList(Jim_Interp *interp, Jim_Obj *listPtr)
{
SetListFromAny(interp, listPtr);
return JimEvalObjList(interp, listPtr);
}
int Jim_EvalObj(Jim_Interp *interp, Jim_Obj *scriptObjPtr)
{
int i;
ScriptObj *script;
ScriptToken *token;
int retcode = JIM_OK;
Jim_Obj *sargv[JIM_EVAL_SARGV_LEN], **argv = NULL;
| > > > > > > | | > | 16205 16206 16207 16208 16209 16210 16211 16212 16213 16214 16215 16216 16217 16218 16219 16220 16221 16222 16223 16224 16225 16226 16227 16228 16229 16230 16231 16232 16233 16234 16235 16236 16237 16238 16239 16240 16241 16242 16243 16244 16245 16246 16247 16248 16249 16250 16251 16252 16253 16254 16255 16256 16257 16258 16259 16260 |
return objPtr;
}
static int JimEvalObjList(Jim_Interp *interp, Jim_Obj *listPtr)
{
int retcode = JIM_OK;
Jim_EvalFrame frame;
JimPanic((Jim_IsList(listPtr) == 0, "JimEvalObjList() invoked on non-list."));
JimPushEvalFrame(interp, &frame, NULL);
if (listPtr->internalRep.listValue.len) {
Jim_IncrRefCount(listPtr);
retcode = JimInvokeCommand(interp,
listPtr->internalRep.listValue.len,
listPtr->internalRep.listValue.ele);
Jim_DecrRefCount(interp, listPtr);
}
JimPopEvalFrame(interp);
return retcode;
}
int Jim_EvalObjList(Jim_Interp *interp, Jim_Obj *listPtr)
{
SetListFromAny(interp, listPtr);
return JimEvalObjList(interp, listPtr);
}
int Jim_EvalObj(Jim_Interp *interp, Jim_Obj *scriptObjPtr)
{
int i;
ScriptObj *script;
ScriptToken *token;
int retcode = JIM_OK;
Jim_Obj *sargv[JIM_EVAL_SARGV_LEN], **argv = NULL;
Jim_EvalFrame frame;
if (Jim_IsList(scriptObjPtr) && scriptObjPtr->bytes == NULL) {
return JimEvalObjList(interp, scriptObjPtr);
}
Jim_IncrRefCount(scriptObjPtr);
script = JimGetScript(interp, scriptObjPtr);
if (JimParseCheckMissing(interp, script->missing) == JIM_ERR) {
JimSetErrorStack(interp);
Jim_DecrRefCount(interp, scriptObjPtr);
return JIM_ERR;
}
Jim_SetEmptyResult(interp);
token = script->token;
|
| ︙ | ︙ | |||
15084 15085 15086 15087 15088 15089 15090 15091 |
return JIM_OK;
}
}
#endif
script->inUse++;
| > < < | 16280 16281 16282 16283 16284 16285 16286 16287 16288 16289 16290 16291 16292 16293 16294 16295 |
return JIM_OK;
}
}
#endif
script->inUse++;
JimPushEvalFrame(interp, &frame, scriptObjPtr);
interp->errorFlag = 0;
argv = sargv;
for (i = 0; i < script->len && retcode == JIM_OK; ) {
int argc;
int j;
|
| ︙ | ︙ | |||
15130 15131 15132 15133 15134 15135 15136 |
case JIM_TT_STR:
wordObjPtr = token[i].objPtr;
break;
case JIM_TT_VAR:
wordObjPtr = Jim_GetVariable(interp, token[i].objPtr, JIM_ERRMSG);
break;
case JIM_TT_EXPRSUGAR:
| > > > > > | > | 16325 16326 16327 16328 16329 16330 16331 16332 16333 16334 16335 16336 16337 16338 16339 16340 16341 16342 16343 16344 16345 |
case JIM_TT_STR:
wordObjPtr = token[i].objPtr;
break;
case JIM_TT_VAR:
wordObjPtr = Jim_GetVariable(interp, token[i].objPtr, JIM_ERRMSG);
break;
case JIM_TT_EXPRSUGAR:
retcode = Jim_EvalExpression(interp, token[i].objPtr);
if (retcode == JIM_OK) {
wordObjPtr = Jim_GetResult(interp);
}
else {
wordObjPtr = NULL;
}
break;
case JIM_TT_DICTSUGAR:
wordObjPtr = JimExpandDictSugar(interp, token[i].objPtr);
break;
case JIM_TT_CMD:
retcode = Jim_EvalObj(interp, token[i].objPtr);
if (retcode == JIM_OK) {
|
| ︙ | ︙ | |||
15217 15218 15219 15220 15221 15222 15223 |
Jim_Free(argv);
argv = sargv;
}
}
if (retcode == JIM_ERR) {
| | < | < < < < < | 16418 16419 16420 16421 16422 16423 16424 16425 16426 16427 16428 16429 16430 16431 16432 16433 16434 16435 |
Jim_Free(argv);
argv = sargv;
}
}
if (retcode == JIM_ERR) {
JimSetErrorStack(interp);
}
JimPopEvalFrame(interp);
Jim_FreeIntRep(interp, scriptObjPtr);
scriptObjPtr->typePtr = &scriptObjType;
Jim_SetIntRepPtr(scriptObjPtr, script);
Jim_DecrRefCount(interp, scriptObjPtr);
return retcode;
|
| ︙ | ︙ | |||
15283 15284 15285 15286 15287 15288 15289 |
Jim_AppendString(interp, argmsg, "?", 1);
Jim_AppendObj(interp, argmsg, cmd->u.proc.arglist[i].defaultObjPtr);
Jim_AppendString(interp, argmsg, " ...?", -1);
}
else {
| | | 16478 16479 16480 16481 16482 16483 16484 16485 16486 16487 16488 16489 16490 16491 16492 |
Jim_AppendString(interp, argmsg, "?", 1);
Jim_AppendObj(interp, argmsg, cmd->u.proc.arglist[i].defaultObjPtr);
Jim_AppendString(interp, argmsg, " ...?", -1);
}
else {
Jim_AppendString(interp, argmsg, "?arg ...?", -1);
}
}
else {
if (cmd->u.proc.arglist[i].defaultObjPtr) {
Jim_AppendString(interp, argmsg, "?", 1);
Jim_AppendObj(interp, argmsg, cmd->u.proc.arglist[i].nameObjPtr);
Jim_AppendString(interp, argmsg, "?", 1);
|
| ︙ | ︙ | |||
15312 15313 15314 15315 15316 15317 15318 |
int Jim_EvalNamespace(Jim_Interp *interp, Jim_Obj *scriptObj, Jim_Obj *nsObj)
{
Jim_CallFrame *callFramePtr;
int retcode;
callFramePtr = JimCreateCallFrame(interp, interp->framePtr, nsObj);
| | | < < | 16507 16508 16509 16510 16511 16512 16513 16514 16515 16516 16517 16518 16519 16520 16521 16522 16523 16524 16525 |
int Jim_EvalNamespace(Jim_Interp *interp, Jim_Obj *scriptObj, Jim_Obj *nsObj)
{
Jim_CallFrame *callFramePtr;
int retcode;
callFramePtr = JimCreateCallFrame(interp, interp->framePtr, nsObj);
callFramePtr->argv = interp->evalFrame->argv;
callFramePtr->argc = interp->evalFrame->argc;
callFramePtr->procArgsObjPtr = NULL;
callFramePtr->procBodyObjPtr = scriptObj;
callFramePtr->staticVars = NULL;
Jim_IncrRefCount(scriptObj);
interp->framePtr = callFramePtr;
if (interp->framePtr->level == interp->maxCallFrameDepth) {
Jim_SetResultString(interp, "Too many nested calls. Infinite recursion?", -1);
retcode = JIM_ERR;
|
| ︙ | ︙ | |||
15344 15345 15346 15347 15348 15349 15350 |
}
#endif
static int JimCallProcedure(Jim_Interp *interp, Jim_Cmd *cmd, int argc, Jim_Obj *const *argv)
{
Jim_CallFrame *callFramePtr;
int i, d, retcode, optargs;
| < | 16537 16538 16539 16540 16541 16542 16543 16544 16545 16546 16547 16548 16549 16550 |
}
#endif
static int JimCallProcedure(Jim_Interp *interp, Jim_Cmd *cmd, int argc, Jim_Obj *const *argv)
{
Jim_CallFrame *callFramePtr;
int i, d, retcode, optargs;
if (argc - 1 < cmd->u.proc.reqArity ||
(cmd->u.proc.argsPos < 0 && argc - 1 > cmd->u.proc.reqArity + cmd->u.proc.optArity)) {
JimSetProcWrongArgs(interp, argv[0], cmd);
return JIM_ERR;
}
|
| ︙ | ︙ | |||
15372 15373 15374 15375 15376 15377 15378 |
callFramePtr = JimCreateCallFrame(interp, interp->framePtr, cmd->u.proc.nsObj);
callFramePtr->argv = argv;
callFramePtr->argc = argc;
callFramePtr->procArgsObjPtr = cmd->u.proc.argListObjPtr;
callFramePtr->procBodyObjPtr = cmd->u.proc.bodyObjPtr;
callFramePtr->staticVars = cmd->u.proc.staticVars;
| | < < < | 16564 16565 16566 16567 16568 16569 16570 16571 16572 16573 16574 16575 16576 16577 16578 |
callFramePtr = JimCreateCallFrame(interp, interp->framePtr, cmd->u.proc.nsObj);
callFramePtr->argv = argv;
callFramePtr->argc = argc;
callFramePtr->procArgsObjPtr = cmd->u.proc.argListObjPtr;
callFramePtr->procBodyObjPtr = cmd->u.proc.bodyObjPtr;
callFramePtr->staticVars = cmd->u.proc.staticVars;
interp->procLevel++;
Jim_IncrRefCount(cmd->u.proc.argListObjPtr);
Jim_IncrRefCount(cmd->u.proc.bodyObjPtr);
interp->framePtr = callFramePtr;
optargs = (argc - 1 - cmd->u.proc.reqArity);
|
| ︙ | ︙ | |||
15423 15424 15425 15426 15427 15428 15429 15430 |
retcode = Jim_SetVariable(interp, nameObjPtr, cmd->u.proc.arglist[d].defaultObjPtr);
}
if (retcode != JIM_OK) {
goto badargset;
}
}
| > > | > < < < < < < < < < < < < < < < < < < < < < < < < | < < < < < < < | < < < | < < < < < < | 16612 16613 16614 16615 16616 16617 16618 16619 16620 16621 16622 16623 16624 16625 16626 16627 16628 16629 16630 16631 16632 16633 16634 16635 16636 16637 16638 16639 16640 16641 16642 16643 16644 16645 16646 16647 16648 16649 16650 16651 16652 16653 16654 16655 16656 16657 16658 16659 16660 16661 16662 |
retcode = Jim_SetVariable(interp, nameObjPtr, cmd->u.proc.arglist[d].defaultObjPtr);
}
if (retcode != JIM_OK) {
goto badargset;
}
}
if (interp->traceCmdObj == NULL ||
(retcode = JimTraceCallback(interp, "proc", argc, argv)) == JIM_OK) {
retcode = Jim_EvalObj(interp, cmd->u.proc.bodyObjPtr);
}
badargset:
retcode = JimInvokeDefer(interp, retcode);
interp->framePtr = interp->framePtr->parent;
JimFreeCallFrame(interp, callFramePtr, JIM_FCF_REUSE);
if (retcode == JIM_RETURN) {
if (--interp->returnLevel <= 0) {
retcode = interp->returnCode;
interp->returnCode = JIM_OK;
interp->returnLevel = 0;
}
}
interp->procLevel--;
return retcode;
}
int Jim_EvalSource(Jim_Interp *interp, const char *filename, int lineno, const char *script)
{
int retval;
Jim_Obj *scriptObjPtr;
scriptObjPtr = Jim_NewStringObj(interp, script, -1);
Jim_IncrRefCount(scriptObjPtr);
if (filename) {
JimSetSourceInfo(interp, scriptObjPtr, Jim_NewStringObj(interp, filename, -1), lineno);
}
retval = Jim_EvalObj(interp, scriptObjPtr);
Jim_DecrRefCount(interp, scriptObjPtr);
return retval;
}
int Jim_Eval(Jim_Interp *interp, const char *script)
{
return Jim_EvalObj(interp, Jim_NewStringObj(interp, script, -1));
|
| ︙ | ︙ | |||
15533 15534 15535 15536 15537 15538 15539 |
interp->framePtr = savedFramePtr;
return retval;
}
#include <sys/stat.h>
| | > | < < < < | | | > | > > > | > > > | | > > > | | > > | > > > | > > < < | | < < | > > < < < < < < < < | 16685 16686 16687 16688 16689 16690 16691 16692 16693 16694 16695 16696 16697 16698 16699 16700 16701 16702 16703 16704 16705 16706 16707 16708 16709 16710 16711 16712 16713 16714 16715 16716 16717 16718 16719 16720 16721 16722 16723 16724 16725 16726 16727 16728 16729 16730 16731 16732 16733 16734 16735 16736 16737 16738 16739 16740 16741 16742 16743 16744 16745 16746 16747 16748 16749 16750 16751 16752 16753 16754 16755 16756 16757 |
interp->framePtr = savedFramePtr;
return retval;
}
#include <sys/stat.h>
static Jim_Obj *JimReadTextFile(Jim_Interp *interp, const char *filename)
{
jim_stat_t sb;
int fd;
char *buf;
int readlen;
if (Jim_Stat(filename, &sb) == -1 || (fd = open(filename, O_RDONLY | O_TEXT, 0666)) < 0) {
Jim_SetResultFormatted(interp, "couldn't read file \"%s\": %s", filename, strerror(errno));
return NULL;
}
buf = Jim_Alloc(sb.st_size + 1);
readlen = read(fd, buf, sb.st_size);
close(fd);
if (readlen < 0) {
Jim_Free(buf);
Jim_SetResultFormatted(interp, "failed to load file \"%s\": %s", filename, strerror(errno));
return NULL;
}
else {
Jim_Obj *objPtr;
buf[readlen] = 0;
objPtr = Jim_NewStringObjNoAlloc(interp, buf, readlen);
return objPtr;
}
}
int Jim_EvalFile(Jim_Interp *interp, const char *filename)
{
Jim_Obj *filenameObj;
Jim_Obj *oldFilenameObj;
Jim_Obj *scriptObjPtr;
int retcode;
scriptObjPtr = JimReadTextFile(interp, filename);
if (!scriptObjPtr) {
return JIM_ERR;
}
filenameObj = Jim_NewStringObj(interp, filename, -1);
JimSetSourceInfo(interp, scriptObjPtr, filenameObj, 1);
oldFilenameObj = JimPushInterpObj(interp->currentFilenameObj, filenameObj);
retcode = Jim_EvalObj(interp, scriptObjPtr);
JimPopInterpObj(interp, interp->currentFilenameObj, oldFilenameObj);
if (retcode == JIM_RETURN) {
if (--interp->returnLevel <= 0) {
retcode = interp->returnCode;
interp->returnCode = JIM_OK;
interp->returnLevel = 0;
}
}
return retcode;
}
static void JimParseSubst(struct JimParserCtx *pc, int flags)
{
pc->tstart = pc->p;
|
| ︙ | ︙ | |||
15694 15695 15696 15697 15698 15699 15700 |
if (objPtr->typePtr != &scriptObjType || ((ScriptObj *)Jim_GetIntRepPtr(objPtr))->substFlags != flags)
SetSubstFromAny(interp, objPtr, flags);
return (ScriptObj *) Jim_GetIntRepPtr(objPtr);
}
int Jim_SubstObj(Jim_Interp *interp, Jim_Obj *substObjPtr, Jim_Obj **resObjPtrPtr, int flags)
{
| > > > > | | 16850 16851 16852 16853 16854 16855 16856 16857 16858 16859 16860 16861 16862 16863 16864 16865 16866 16867 16868 |
if (objPtr->typePtr != &scriptObjType || ((ScriptObj *)Jim_GetIntRepPtr(objPtr))->substFlags != flags)
SetSubstFromAny(interp, objPtr, flags);
return (ScriptObj *) Jim_GetIntRepPtr(objPtr);
}
int Jim_SubstObj(Jim_Interp *interp, Jim_Obj *substObjPtr, Jim_Obj **resObjPtrPtr, int flags)
{
ScriptObj *script;
JimPanic((substObjPtr->refCount == 0, "Jim_SubstObj() called with zero refcount object"));
script = Jim_GetSubst(interp, substObjPtr, flags);
Jim_IncrRefCount(substObjPtr);
script->inUse++;
*resObjPtrPtr = JimInterpolateTokens(interp, script->token, script->len, flags);
script->inUse--;
|
| ︙ | ︙ | |||
15729 15730 15731 15732 15733 15734 15735 |
objPtr = Jim_ListJoin(interp, listObjPtr, " ", 1);
Jim_DecrRefCount(interp, listObjPtr);
Jim_SetResultFormatted(interp, "wrong # args: should be \"%#s\"", objPtr);
}
typedef void JimHashtableIteratorCallbackType(Jim_Interp *interp, Jim_Obj *listObjPtr,
| | | | > < | < > | | < < | | > > > > > > > > > > > > > | | < | > | > | | | > | | | > | > | > | | > | > > | > | > | | | < | | | | | > > | > > | | > > > > > > > | > > > > > > | > > > > > | | | > > > > > | | | > > > | 16889 16890 16891 16892 16893 16894 16895 16896 16897 16898 16899 16900 16901 16902 16903 16904 16905 16906 16907 16908 16909 16910 16911 16912 16913 16914 16915 16916 16917 16918 16919 16920 16921 16922 16923 16924 16925 16926 16927 16928 16929 16930 16931 16932 16933 16934 16935 16936 16937 16938 16939 16940 16941 16942 16943 16944 16945 16946 16947 16948 16949 16950 16951 16952 16953 16954 16955 16956 16957 16958 16959 16960 16961 16962 16963 16964 16965 16966 16967 16968 16969 16970 16971 16972 16973 16974 16975 16976 16977 16978 16979 16980 16981 16982 16983 16984 16985 16986 16987 16988 16989 16990 16991 16992 16993 16994 16995 16996 16997 16998 16999 17000 17001 17002 17003 17004 17005 17006 17007 17008 17009 17010 17011 17012 17013 17014 17015 17016 17017 17018 17019 17020 17021 17022 17023 17024 17025 17026 17027 17028 17029 17030 17031 17032 17033 17034 17035 17036 17037 17038 17039 17040 17041 17042 17043 17044 17045 17046 17047 17048 17049 17050 17051 17052 17053 17054 17055 17056 17057 17058 17059 17060 17061 17062 17063 17064 17065 17066 17067 17068 17069 17070 17071 17072 |
objPtr = Jim_ListJoin(interp, listObjPtr, " ", 1);
Jim_DecrRefCount(interp, listObjPtr);
Jim_SetResultFormatted(interp, "wrong # args: should be \"%#s\"", objPtr);
}
typedef void JimHashtableIteratorCallbackType(Jim_Interp *interp, Jim_Obj *listObjPtr,
Jim_Obj *keyObjPtr, void *value, Jim_Obj *patternObjPtr, int type);
#define JimTrivialMatch(pattern) (strpbrk((pattern), "*[?\\") == NULL)
static Jim_Obj *JimHashtablePatternMatch(Jim_Interp *interp, Jim_HashTable *ht, Jim_Obj *patternObjPtr,
JimHashtableIteratorCallbackType *callback, int type)
{
Jim_HashEntry *he;
Jim_Obj *listObjPtr = Jim_NewListObj(interp, NULL, 0);
if (patternObjPtr && JimTrivialMatch(Jim_String(patternObjPtr))) {
he = Jim_FindHashEntry(ht, patternObjPtr);
if (he) {
callback(interp, listObjPtr, Jim_GetHashEntryKey(he), Jim_GetHashEntryVal(he),
patternObjPtr, type);
}
}
else {
Jim_HashTableIterator htiter;
JimInitHashTableIterator(ht, &htiter);
while ((he = Jim_NextHashEntry(&htiter)) != NULL) {
callback(interp, listObjPtr, Jim_GetHashEntryKey(he), Jim_GetHashEntryVal(he),
patternObjPtr, type);
}
}
return listObjPtr;
}
#define JIM_CMDLIST_COMMANDS 0
#define JIM_CMDLIST_PROCS 1
#define JIM_CMDLIST_CHANNELS 2
static void JimCommandMatch(Jim_Interp *interp, Jim_Obj *listObjPtr,
Jim_Obj *keyObj, void *value, Jim_Obj *patternObj, int type)
{
Jim_Cmd *cmdPtr = (Jim_Cmd *)value;
if (type == JIM_CMDLIST_PROCS && !cmdPtr->isproc) {
return;
}
Jim_IncrRefCount(keyObj);
if (type != JIM_CMDLIST_CHANNELS || Jim_AioFilehandle(interp, keyObj) >= 0) {
int match = 1;
if (patternObj) {
int plen, slen;
const char *pattern = Jim_GetStringNoQualifier(patternObj, &plen);
const char *str = Jim_GetStringNoQualifier(keyObj, &slen);
#ifdef JIM_NO_INTROSPECTION
match = (JimStringCompareUtf8(pattern, plen, str, slen, 0) == 0);
#else
match = JimGlobMatch(pattern, plen, str, slen, 0);
#endif
}
if (match) {
Jim_ListAppendElement(interp, listObjPtr, keyObj);
}
}
Jim_DecrRefCount(interp, keyObj);
}
static Jim_Obj *JimCommandsList(Jim_Interp *interp, Jim_Obj *patternObjPtr, int type)
{
return JimHashtablePatternMatch(interp, &interp->commands, patternObjPtr, JimCommandMatch, type);
}
#define JIM_VARLIST_GLOBALS 0
#define JIM_VARLIST_LOCALS 1
#define JIM_VARLIST_VARS 2
#define JIM_VARLIST_MASK 0x000f
#define JIM_VARLIST_VALUES 0x1000
static void JimVariablesMatch(Jim_Interp *interp, Jim_Obj *listObjPtr,
Jim_Obj *keyObj, void *value, Jim_Obj *patternObj, int type)
{
Jim_VarVal *vv = (Jim_VarVal *)value;
if ((type & JIM_VARLIST_MASK) != JIM_VARLIST_LOCALS || vv->linkFramePtr == NULL) {
if (patternObj == NULL || Jim_StringMatchObj(interp, patternObj, keyObj, 0)) {
Jim_ListAppendElement(interp, listObjPtr, keyObj);
if (type & JIM_VARLIST_VALUES) {
Jim_ListAppendElement(interp, listObjPtr, vv->objPtr);
}
}
}
}
static Jim_Obj *JimVariablesList(Jim_Interp *interp, Jim_Obj *patternObjPtr, int mode)
{
if (mode == JIM_VARLIST_LOCALS && interp->framePtr == interp->topFramePtr) {
return interp->emptyObj;
}
else {
Jim_CallFrame *framePtr = (mode == JIM_VARLIST_GLOBALS) ? interp->topFramePtr : interp->framePtr;
return JimHashtablePatternMatch(interp, &framePtr->vars, patternObjPtr, JimVariablesMatch,
mode);
}
}
static int JimInfoLevel(Jim_Interp *interp, Jim_Obj *levelObjPtr, Jim_Obj **objPtrPtr)
{
long level;
if (Jim_GetLong(interp, levelObjPtr, &level) == JIM_OK) {
Jim_CallFrame *targetCallFrame = JimGetCallFrameByInteger(interp, level);
if (targetCallFrame && targetCallFrame != interp->topFramePtr) {
#ifdef JIM_NO_INTROSPECTION
*objPtrPtr = Jim_NewListObj(interp, targetCallFrame->argv, 1);
#else
*objPtrPtr = Jim_NewListObj(interp, targetCallFrame->argv, targetCallFrame->argc);
#endif
return JIM_OK;
}
}
Jim_SetResultFormatted(interp, "bad level \"%#s\"", levelObjPtr);
return JIM_ERR;
}
static int JimInfoFrame(Jim_Interp *interp, Jim_Obj *levelObjPtr, Jim_Obj **objPtrPtr)
{
long level;
if (Jim_GetLong(interp, levelObjPtr, &level) == JIM_OK) {
Jim_EvalFrame *frame = JimGetEvalFrameByProcLevel(interp, level);
if (frame) {
Jim_Obj *listObj = Jim_NewListObj(interp, NULL, 0);
Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, "type", -1));
Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, "source", -1));
if (frame->scriptObj) {
ScriptObj *script = JimGetScript(interp, frame->scriptObj);
Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, "line", -1));
Jim_ListAppendElement(interp, listObj, Jim_NewIntObj(interp, script->linenr));
Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, "file", -1));
Jim_ListAppendElement(interp, listObj, script->fileNameObj);
}
#ifndef JIM_NO_INTROSPECTION
{
Jim_Obj *cmdObj = Jim_NewListObj(interp, frame->argv, frame->argc);
Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, "cmd", -1));
Jim_ListAppendElement(interp, listObj, cmdObj);
}
#endif
{
Jim_Obj *procNameObj = JimProcForEvalFrame(interp, frame);
if (procNameObj) {
Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, "proc", -1));
Jim_ListAppendElement(interp, listObj, procNameObj);
}
}
Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, "level", -1));
Jim_ListAppendElement(interp, listObj, Jim_NewIntObj(interp, interp->framePtr->level - frame->framePtr->level));
*objPtrPtr = listObj;
return JIM_OK;
}
}
Jim_SetResultFormatted(interp, "bad level \"%#s\"", levelObjPtr);
return JIM_ERR;
}
static int Jim_PutsCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
if (argc != 2 && argc != 3) {
Jim_WrongNumArgs(interp, 1, argv, "?-nonewline? string");
return JIM_ERR;
|
| ︙ | ︙ | |||
16054 16055 16056 16057 16058 16059 16060 16061 16062 16063 16064 16065 16066 16067 16068 16069 16070 16071 16072 16073 |
while (i < argc) {
if (Jim_UnsetVariable(interp, argv[i], complain ? JIM_ERRMSG : JIM_NONE) != JIM_OK
&& complain) {
return JIM_ERR;
}
i++;
}
return JIM_OK;
}
static int Jim_WhileCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
if (argc != 3) {
Jim_WrongNumArgs(interp, 1, argv, "condition body");
return JIM_ERR;
}
while (1) {
| > > > > > > > > > > > > | > > > < < > | 17264 17265 17266 17267 17268 17269 17270 17271 17272 17273 17274 17275 17276 17277 17278 17279 17280 17281 17282 17283 17284 17285 17286 17287 17288 17289 17290 17291 17292 17293 17294 17295 17296 17297 17298 17299 17300 17301 17302 17303 17304 17305 17306 17307 17308 17309 17310 17311 17312 17313 17314 17315 17316 17317 17318 17319 17320 17321 17322 17323 17324 17325 17326 17327 17328 17329 17330 17331 17332 17333 17334 |
while (i < argc) {
if (Jim_UnsetVariable(interp, argv[i], complain ? JIM_ERRMSG : JIM_NONE) != JIM_OK
&& complain) {
return JIM_ERR;
}
i++;
}
Jim_SetEmptyResult(interp);
return JIM_OK;
}
static int JimCheckLoopRetcode(Jim_Interp *interp, int retval)
{
if (retval == JIM_BREAK || retval == JIM_CONTINUE) {
if (--interp->returnLevel > 0) {
return 1;
}
}
return 0;
}
static int Jim_WhileCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
if (argc != 3) {
Jim_WrongNumArgs(interp, 1, argv, "condition body");
return JIM_ERR;
}
while (1) {
int boolean = 0, retval;
if ((retval = Jim_GetBoolFromExpr(interp, argv[1], &boolean)) != JIM_OK)
return retval;
if (!boolean)
break;
if ((retval = Jim_EvalObj(interp, argv[2])) != JIM_OK) {
if (JimCheckLoopRetcode(interp, retval)) {
return retval;
}
switch (retval) {
case JIM_BREAK:
goto out;
case JIM_CONTINUE:
continue;
default:
return retval;
}
}
}
out:
Jim_SetEmptyResult(interp);
return JIM_OK;
}
static int Jim_ForCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
int retval;
int boolean = 1;
int immediate = 0;
Jim_Obj *varNamePtr = NULL;
Jim_Obj *stopVarNamePtr = NULL;
if (argc != 5) {
Jim_WrongNumArgs(interp, 1, argv, "start test next body");
return JIM_ERR;
}
|
| ︙ | ︙ | |||
16164 16165 16166 16167 16168 16169 16170 |
if (!Jim_StringEqObj(incrScript->token[2].objPtr, expr->expr->left->objPtr)) {
goto evalstart;
}
if (expr->expr->right->type == JIM_TT_EXPR_INT) {
| | | 17388 17389 17390 17391 17392 17393 17394 17395 17396 17397 17398 17399 17400 17401 17402 |
if (!Jim_StringEqObj(incrScript->token[2].objPtr, expr->expr->left->objPtr)) {
goto evalstart;
}
if (expr->expr->right->type == JIM_TT_EXPR_INT) {
if (Jim_GetWideExpr(interp, expr->expr->right->objPtr, &stop) == JIM_ERR) {
goto evalstart;
}
}
else {
stopVarNamePtr = expr->expr->right->objPtr;
Jim_IncrRefCount(stopVarNamePtr);
|
| ︙ | ︙ | |||
16203 16204 16205 16206 16207 16208 16209 16210 16211 16212 16213 16214 16215 16216 |
if (currentVal >= stop + cmpOffset) {
break;
}
retval = Jim_EvalObj(interp, argv[4]);
if (retval == JIM_OK || retval == JIM_CONTINUE) {
retval = JIM_OK;
objPtr = Jim_GetVariable(interp, varNamePtr, JIM_ERRMSG);
if (objPtr == NULL) {
| > > > > | 17427 17428 17429 17430 17431 17432 17433 17434 17435 17436 17437 17438 17439 17440 17441 17442 17443 17444 |
if (currentVal >= stop + cmpOffset) {
break;
}
retval = Jim_EvalObj(interp, argv[4]);
if (JimCheckLoopRetcode(interp, retval)) {
immediate++;
goto out;
}
if (retval == JIM_OK || retval == JIM_CONTINUE) {
retval = JIM_OK;
objPtr = Jim_GetVariable(interp, varNamePtr, JIM_ERRMSG);
if (objPtr == NULL) {
|
| ︙ | ︙ | |||
16239 16240 16241 16242 16243 16244 16245 16246 16247 16248 16249 16250 16251 16252 16253 16254 16255 16256 16257 16258 16259 16260 |
retval = Jim_EvalObj(interp, argv[4]);
if (retval == JIM_OK || retval == JIM_CONTINUE) {
JIM_IF_OPTIM(evalnext:)
retval = Jim_EvalObj(interp, argv[3]);
if (retval == JIM_OK || retval == JIM_CONTINUE) {
JIM_IF_OPTIM(testcond:)
retval = Jim_GetBoolFromExpr(interp, argv[2], &boolean);
}
}
}
JIM_IF_OPTIM(out:)
if (stopVarNamePtr) {
Jim_DecrRefCount(interp, stopVarNamePtr);
}
if (varNamePtr) {
Jim_DecrRefCount(interp, varNamePtr);
}
| > > > > > | | | > | | | > | > > | > > | > > > > | | > > > | 17467 17468 17469 17470 17471 17472 17473 17474 17475 17476 17477 17478 17479 17480 17481 17482 17483 17484 17485 17486 17487 17488 17489 17490 17491 17492 17493 17494 17495 17496 17497 17498 17499 17500 17501 17502 17503 17504 17505 17506 17507 17508 17509 17510 17511 17512 17513 17514 17515 17516 17517 17518 17519 17520 17521 17522 17523 17524 17525 17526 17527 17528 17529 17530 17531 17532 17533 17534 17535 17536 17537 17538 17539 17540 17541 17542 17543 17544 17545 17546 |
retval = Jim_EvalObj(interp, argv[4]);
if (retval == JIM_OK || retval == JIM_CONTINUE) {
JIM_IF_OPTIM(evalnext:)
retval = Jim_EvalObj(interp, argv[3]);
if (JimCheckLoopRetcode(interp, retval)) {
immediate++;
goto out;
}
if (retval == JIM_OK || retval == JIM_CONTINUE) {
JIM_IF_OPTIM(testcond:)
retval = Jim_GetBoolFromExpr(interp, argv[2], &boolean);
}
}
}
JIM_IF_OPTIM(out:)
if (stopVarNamePtr) {
Jim_DecrRefCount(interp, stopVarNamePtr);
}
if (varNamePtr) {
Jim_DecrRefCount(interp, varNamePtr);
}
if (!immediate) {
if (retval == JIM_CONTINUE || retval == JIM_BREAK || retval == JIM_OK) {
Jim_SetEmptyResult(interp);
return JIM_OK;
}
}
return retval;
}
static int Jim_LoopCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
int retval;
jim_wide i;
jim_wide limit;
jim_wide incr = 1;
Jim_Obj *bodyObjPtr;
if (argc < 4 || argc > 6) {
Jim_WrongNumArgs(interp, 1, argv, "var ?first? limit ?incr? body");
return JIM_ERR;
}
retval = Jim_GetWideExpr(interp, argv[2], &i);
if (argc > 4 && retval == JIM_OK) {
retval = Jim_GetWideExpr(interp, argv[3], &limit);
}
if (argc > 5 && retval == JIM_OK) {
Jim_GetWideExpr(interp, argv[4], &incr);
}
if (retval != JIM_OK) {
return retval;
}
if (argc == 4) {
limit = i;
i = 0;
}
bodyObjPtr = argv[argc - 1];
retval = Jim_SetVariable(interp, argv[1], Jim_NewIntObj(interp, i));
while (((i < limit && incr > 0) || (i > limit && incr < 0)) && retval == JIM_OK) {
retval = Jim_EvalObj(interp, bodyObjPtr);
if (JimCheckLoopRetcode(interp, retval)) {
return retval;
}
if (retval == JIM_OK || retval == JIM_CONTINUE) {
Jim_Obj *objPtr = Jim_GetVariable(interp, argv[1], JIM_ERRMSG);
retval = JIM_OK;
i += incr;
|
| ︙ | ︙ | |||
16427 16428 16429 16430 16431 16432 16433 |
result = Jim_SetVariable(interp, varName, valObj);
Jim_DecrRefCount(interp, valObj);
if (result != JIM_OK) {
goto err;
}
}
}
| | > > > > | 17673 17674 17675 17676 17677 17678 17679 17680 17681 17682 17683 17684 17685 17686 17687 17688 17689 17690 17691 |
result = Jim_SetVariable(interp, varName, valObj);
Jim_DecrRefCount(interp, valObj);
if (result != JIM_OK) {
goto err;
}
}
}
result = Jim_EvalObj(interp, script);
if (JimCheckLoopRetcode(interp, result)) {
goto err;
}
switch (result) {
case JIM_OK:
if (doMap) {
Jim_ListAppendElement(interp, resultObj, interp->result);
}
break;
case JIM_CONTINUE:
break;
|
| ︙ | ︙ | |||
16548 16549 16550 16551 16552 16553 16554 |
}
err:
Jim_WrongNumArgs(interp, 1, argv, "condition ?then? trueBody ?elseif ...? ?else? falseBody");
return JIM_ERR;
}
| < | | | > > > > | 17798 17799 17800 17801 17802 17803 17804 17805 17806 17807 17808 17809 17810 17811 17812 17813 17814 17815 17816 17817 17818 17819 17820 17821 17822 17823 17824 17825 17826 17827 17828 17829 17830 17831 17832 17833 17834 17835 17836 17837 17838 17839 17840 17841 17842 17843 17844 |
}
err:
Jim_WrongNumArgs(interp, 1, argv, "condition ?then? trueBody ?elseif ...? ?else? falseBody");
return JIM_ERR;
}
int Jim_CommandMatchObj(Jim_Interp *interp, Jim_Obj *commandObj, Jim_Obj *patternObj,
Jim_Obj *stringObj, int flags)
{
Jim_Obj *parms[5];
int argc = 0;
long eq;
int rc;
parms[argc++] = commandObj;
if (flags & JIM_NOCASE) {
parms[argc++] = Jim_NewStringObj(interp, "-nocase", -1);
}
if (flags & JIM_OPT_END) {
parms[argc++] = Jim_NewStringObj(interp, "--", -1);
}
parms[argc++] = patternObj;
parms[argc++] = stringObj;
rc = Jim_EvalObjVector(interp, argc, parms);
if (rc != JIM_OK || Jim_GetLong(interp, Jim_GetResult(interp), &eq) != JIM_OK) {
eq = -rc;
}
return eq;
}
static int Jim_SwitchCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
enum { SWITCH_EXACT, SWITCH_GLOB, SWITCH_RE, SWITCH_CMD };
int matchOpt = SWITCH_EXACT, opt = 1, patCount, i;
int match_flags = 0;
Jim_Obj *command = NULL, *scriptObj = NULL, *strObj;
Jim_Obj **caseList;
if (argc < 3) {
wrongnumargs:
Jim_WrongNumArgs(interp, 1, argv, "?options? string "
"pattern body ... ?default body? or " "{pattern body ?pattern body ...?}");
|
| ︙ | ︙ | |||
16600 16601 16602 16603 16604 16605 16606 |
++opt;
break;
}
else if (strncmp(option, "-exact", 2) == 0)
matchOpt = SWITCH_EXACT;
else if (strncmp(option, "-glob", 2) == 0)
matchOpt = SWITCH_GLOB;
| | > > | 17853 17854 17855 17856 17857 17858 17859 17860 17861 17862 17863 17864 17865 17866 17867 17868 17869 17870 |
++opt;
break;
}
else if (strncmp(option, "-exact", 2) == 0)
matchOpt = SWITCH_EXACT;
else if (strncmp(option, "-glob", 2) == 0)
matchOpt = SWITCH_GLOB;
else if (strncmp(option, "-regexp", 2) == 0) {
matchOpt = SWITCH_RE;
match_flags |= JIM_OPT_END;
}
else if (strncmp(option, "-command", 2) == 0) {
matchOpt = SWITCH_CMD;
if ((argc - opt) < 2)
goto wrongnumargs;
command = argv[++opt];
}
else {
|
| ︙ | ︙ | |||
16644 16645 16646 16647 16648 16649 16650 |
if (Jim_StringMatchObj(interp, patObj, strObj, 0))
scriptObj = caseList[i + 1];
break;
case SWITCH_RE:
command = Jim_NewStringObj(interp, "regexp", -1);
case SWITCH_CMD:{
| | | 17899 17900 17901 17902 17903 17904 17905 17906 17907 17908 17909 17910 17911 17912 17913 |
if (Jim_StringMatchObj(interp, patObj, strObj, 0))
scriptObj = caseList[i + 1];
break;
case SWITCH_RE:
command = Jim_NewStringObj(interp, "regexp", -1);
case SWITCH_CMD:{
int rc = Jim_CommandMatchObj(interp, command, patObj, strObj, match_flags);
if (argc - opt == 1) {
JimListGetElements(interp, argv[opt], &patCount, &caseList);
}
if (rc < 0) {
return -rc;
|
| ︙ | ︙ | |||
16689 16690 16691 16692 16693 16694 16695 |
Jim_SetResult(interp, listObjPtr);
return JIM_OK;
}
static int Jim_LindexCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
| | | < < < < < | < | < | < | < | > | < < < | | | < > > > | | > > > > < > > > > > > > > > > > > > > > > > > > > > > > > > > > > < | > > > > > > > | | > > > > > > > > > > > > > > > > > > > > > | | | < | < < < < < < | > > > > > > > > > > > > | > > > > > > > | 17944 17945 17946 17947 17948 17949 17950 17951 17952 17953 17954 17955 17956 17957 17958 17959 17960 17961 17962 17963 17964 17965 17966 17967 17968 17969 17970 17971 17972 17973 17974 17975 17976 17977 17978 17979 17980 17981 17982 17983 17984 17985 17986 17987 17988 17989 17990 17991 17992 17993 17994 17995 17996 17997 17998 17999 18000 18001 18002 18003 18004 18005 18006 18007 18008 18009 18010 18011 18012 18013 18014 18015 18016 18017 18018 18019 18020 18021 18022 18023 18024 18025 18026 18027 18028 18029 18030 18031 18032 18033 18034 18035 18036 18037 18038 18039 18040 18041 18042 18043 18044 18045 18046 18047 18048 18049 18050 18051 18052 18053 18054 18055 18056 18057 18058 18059 18060 18061 18062 18063 18064 18065 18066 18067 18068 18069 18070 18071 18072 18073 18074 18075 18076 18077 18078 18079 18080 18081 18082 18083 18084 18085 18086 18087 18088 18089 18090 18091 18092 18093 18094 18095 18096 18097 18098 18099 18100 18101 18102 18103 18104 18105 18106 18107 18108 18109 18110 18111 18112 18113 18114 18115 18116 18117 18118 18119 18120 18121 18122 18123 18124 18125 18126 18127 18128 18129 18130 18131 18132 18133 18134 18135 18136 18137 18138 18139 18140 18141 18142 18143 18144 18145 18146 18147 18148 18149 18150 18151 18152 18153 18154 18155 18156 18157 18158 18159 18160 18161 18162 18163 18164 18165 18166 18167 18168 18169 18170 18171 18172 18173 18174 18175 18176 18177 18178 18179 18180 18181 18182 18183 18184 18185 18186 18187 18188 18189 18190 18191 18192 18193 18194 18195 18196 18197 18198 18199 18200 18201 18202 18203 18204 18205 18206 18207 |
Jim_SetResult(interp, listObjPtr);
return JIM_OK;
}
static int Jim_LindexCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_Obj *objPtr;
int ret;
if (argc < 2) {
Jim_WrongNumArgs(interp, 1, argv, "list ?index ...?");
return JIM_ERR;
}
ret = Jim_ListIndices(interp, argv[1], argv + 2, argc - 2, &objPtr, JIM_NONE);
if (ret < 0) {
ret = JIM_OK;
Jim_SetEmptyResult(interp);
}
else if (ret == JIM_OK) {
Jim_SetResult(interp, objPtr);
}
return ret;
}
static int Jim_LlengthCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
if (argc != 2) {
Jim_WrongNumArgs(interp, 1, argv, "list");
return JIM_ERR;
}
Jim_SetResultInt(interp, Jim_ListLength(interp, argv[1]));
return JIM_OK;
}
static int Jim_LsearchCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
static const char * const options[] = {
"-bool", "-not", "-nocase", "-exact", "-glob", "-regexp", "-all", "-inline", "-command",
"-stride", "-index", NULL
};
enum
{ OPT_BOOL, OPT_NOT, OPT_NOCASE, OPT_EXACT, OPT_GLOB, OPT_REGEXP, OPT_ALL, OPT_INLINE,
OPT_COMMAND, OPT_STRIDE, OPT_INDEX };
int i;
int opt_bool = 0;
int opt_not = 0;
int opt_all = 0;
int opt_inline = 0;
int opt_match = OPT_EXACT;
int listlen;
int rc = JIM_OK;
Jim_Obj *listObjPtr = NULL;
Jim_Obj *commandObj = NULL;
Jim_Obj *indexObj = NULL;
int match_flags = 0;
long stride = 1;
if (argc < 3) {
wrongargs:
Jim_WrongNumArgs(interp, 1, argv,
"?-exact|-glob|-regexp|-command 'command'? ?-bool|-inline? ?-not? ?-nocase? ?-all? ?-stride len? ?-index val? list value");
return JIM_ERR;
}
for (i = 1; i < argc - 2; i++) {
int option;
if (Jim_GetEnum(interp, argv[i], options, &option, NULL, JIM_ERRMSG) != JIM_OK) {
return JIM_ERR;
}
switch (option) {
case OPT_BOOL:
opt_bool = 1;
opt_inline = 0;
break;
case OPT_NOT:
opt_not = 1;
break;
case OPT_NOCASE:
match_flags |= JIM_NOCASE;
break;
case OPT_INLINE:
opt_inline = 1;
opt_bool = 0;
break;
case OPT_ALL:
opt_all = 1;
break;
case OPT_REGEXP:
opt_match = option;
match_flags |= JIM_OPT_END;
break;
case OPT_COMMAND:
if (i >= argc - 2) {
goto wrongargs;
}
commandObj = argv[++i];
case OPT_EXACT:
case OPT_GLOB:
opt_match = option;
break;
case OPT_INDEX:
if (i >= argc - 2) {
goto wrongargs;
}
indexObj = argv[++i];
break;
case OPT_STRIDE:
if (i >= argc - 2) {
goto wrongargs;
}
if (Jim_GetLong(interp, argv[++i], &stride) != JIM_OK) {
return JIM_ERR;
}
if (stride < 1) {
Jim_SetResultString(interp, "stride length must be at least 1", -1);
return JIM_ERR;
}
break;
}
}
argc -= i;
if (argc < 2) {
goto wrongargs;
}
argv += i;
listlen = Jim_ListLength(interp, argv[0]);
if (listlen % stride) {
Jim_SetResultString(interp, "list size must be a multiple of the stride length", -1);
return JIM_ERR;
}
if (opt_all) {
listObjPtr = Jim_NewListObj(interp, NULL, 0);
}
if (opt_match == OPT_REGEXP) {
commandObj = Jim_NewStringObj(interp, "regexp", -1);
}
if (commandObj) {
Jim_IncrRefCount(commandObj);
}
for (i = 0; i < listlen; i += stride) {
int eq = 0;
Jim_Obj *searchListObj;
Jim_Obj *objPtr;
int offset;
if (indexObj) {
int indexlen = Jim_ListLength(interp, indexObj);
if (stride == 1) {
searchListObj = Jim_ListGetIndex(interp, argv[0], i);
}
else {
searchListObj = Jim_NewListObj(interp, argv[0]->internalRep.listValue.ele + i, stride);
}
Jim_IncrRefCount(searchListObj);
rc = Jim_ListIndices(interp, searchListObj, indexObj->internalRep.listValue.ele, indexlen, &objPtr, JIM_ERRMSG);
if (rc != JIM_OK) {
Jim_DecrRefCount(interp, searchListObj);
rc = JIM_ERR;
goto done;
}
offset = 0;
}
else {
searchListObj = argv[0];
offset = i;
objPtr = Jim_ListGetIndex(interp, searchListObj, i);
Jim_IncrRefCount(searchListObj);
}
switch (opt_match) {
case OPT_EXACT:
eq = Jim_StringCompareObj(interp, argv[1], objPtr, match_flags) == 0;
break;
case OPT_GLOB:
eq = Jim_StringMatchObj(interp, argv[1], objPtr, match_flags);
break;
case OPT_REGEXP:
case OPT_COMMAND:
eq = Jim_CommandMatchObj(interp, commandObj, argv[1], objPtr, match_flags);
if (eq < 0) {
Jim_DecrRefCount(interp, searchListObj);
rc = JIM_ERR;
goto done;
}
break;
}
if ((!opt_bool && eq == !opt_not) || (opt_bool && (eq || opt_all))) {
Jim_Obj *resultObj;
if (opt_bool) {
resultObj = Jim_NewIntObj(interp, eq ^ opt_not);
}
else if (!opt_inline) {
resultObj = Jim_NewIntObj(interp, i);
}
else if (stride == 1) {
resultObj = objPtr;
}
else if (opt_all) {
ListInsertElements(listObjPtr, -1, stride,
searchListObj->internalRep.listValue.ele + offset);
resultObj = NULL;
}
else {
resultObj = Jim_NewListObj(interp, searchListObj->internalRep.listValue.ele + offset, stride);
}
if (opt_all) {
if (stride == 1) {
Jim_ListAppendElement(interp, listObjPtr, resultObj);
}
}
else {
Jim_SetResult(interp, resultObj);
Jim_DecrRefCount(interp, searchListObj);
goto done;
}
}
Jim_DecrRefCount(interp, searchListObj);
}
if (opt_all) {
Jim_SetResult(interp, listObjPtr);
listObjPtr = NULL;
}
else {
if (opt_bool) {
Jim_SetResultBool(interp, opt_not);
}
else if (!opt_inline) {
Jim_SetResultInt(interp, -1);
}
}
done:
if (listObjPtr) {
Jim_FreeNewObj(interp, listObjPtr);
}
if (commandObj) {
Jim_DecrRefCount(interp, commandObj);
}
return rc;
}
|
| ︙ | ︙ | |||
16991 16992 16993 16994 16995 16996 16997 |
return JIM_OK;
}
static int Jim_LsetCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
if (argc < 3) {
| | | > | | > > > > | | 18307 18308 18309 18310 18311 18312 18313 18314 18315 18316 18317 18318 18319 18320 18321 18322 18323 18324 18325 18326 18327 18328 18329 18330 18331 18332 18333 18334 18335 18336 18337 18338 18339 18340 18341 18342 18343 18344 18345 18346 18347 18348 18349 18350 18351 18352 18353 18354 18355 18356 18357 18358 18359 18360 18361 |
return JIM_OK;
}
static int Jim_LsetCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
if (argc < 3) {
Jim_WrongNumArgs(interp, 1, argv, "listVar ?index ...? value");
return JIM_ERR;
}
else if (argc == 3) {
if (Jim_SetVariable(interp, argv[1], argv[2]) != JIM_OK)
return JIM_ERR;
Jim_SetResult(interp, argv[2]);
return JIM_OK;
}
return Jim_ListSetIndex(interp, argv[1], argv + 2, argc - 3, argv[argc - 1]);
}
static int Jim_LsortCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const argv[])
{
static const char * const options[] = {
"-ascii", "-nocase", "-increasing", "-decreasing", "-command", "-integer", "-real", "-index", "-unique",
"-stride", NULL
};
enum {
OPT_ASCII, OPT_NOCASE, OPT_INCREASING, OPT_DECREASING, OPT_COMMAND, OPT_INTEGER, OPT_REAL, OPT_INDEX, OPT_UNIQUE,
OPT_STRIDE
};
Jim_Obj *resObj;
int i;
int retCode;
int shared;
long stride = 1;
struct lsort_info info;
if (argc < 2) {
wrongargs:
Jim_WrongNumArgs(interp, 1, argv, "?options? list");
return JIM_ERR;
}
info.type = JIM_LSORT_ASCII;
info.order = 1;
info.indexc = 0;
info.unique = 0;
info.command = NULL;
info.interp = interp;
for (i = 1; i < (argc - 1); i++) {
int option;
|
| ︙ | ︙ | |||
17067 17068 17069 17070 17071 17072 17073 17074 17075 17076 17077 17078 17079 |
if (i >= (argc - 2)) {
Jim_SetResultString(interp, "\"-command\" option must be followed by comparison command", -1);
return JIM_ERR;
}
info.type = JIM_LSORT_COMMAND;
info.command = argv[i + 1];
i++;
break;
case OPT_INDEX:
if (i >= (argc - 2)) {
Jim_SetResultString(interp, "\"-index\" option must be followed by list index", -1);
return JIM_ERR;
}
| > > > > > > > > > > > > > | | > < > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | > | | | | | | > | 18388 18389 18390 18391 18392 18393 18394 18395 18396 18397 18398 18399 18400 18401 18402 18403 18404 18405 18406 18407 18408 18409 18410 18411 18412 18413 18414 18415 18416 18417 18418 18419 18420 18421 18422 18423 18424 18425 18426 18427 18428 18429 18430 18431 18432 18433 18434 18435 18436 18437 18438 18439 18440 18441 18442 18443 18444 18445 18446 18447 18448 18449 18450 18451 18452 18453 18454 18455 18456 18457 18458 18459 18460 18461 18462 18463 18464 18465 18466 18467 18468 |
if (i >= (argc - 2)) {
Jim_SetResultString(interp, "\"-command\" option must be followed by comparison command", -1);
return JIM_ERR;
}
info.type = JIM_LSORT_COMMAND;
info.command = argv[i + 1];
i++;
break;
case OPT_STRIDE:
if (i >= argc - 2) {
goto wrongargs;
}
if (Jim_GetLong(interp, argv[++i], &stride) != JIM_OK) {
return JIM_ERR;
}
if (stride < 2) {
Jim_SetResultString(interp, "stride length must be at least 2", -1);
return JIM_ERR;
}
break;
case OPT_INDEX:
if (i >= (argc - 2)) {
badindex:
Jim_SetResultString(interp, "\"-index\" option must be followed by list index", -1);
return JIM_ERR;
}
JimListGetElements(interp, argv[i + 1], &info.indexc, &info.indexv);
if (info.indexc == 0) {
goto badindex;
}
i++;
break;
}
}
resObj = argv[argc - 1];
if (stride > 1) {
Jim_Obj *tmpListObj;
Jim_Obj **elements;
int listlen;
int i;
JimListGetElements(interp, resObj, &listlen, &elements);
if (listlen % stride) {
Jim_SetResultString(interp, "list size must be a multiple of the stride length", -1);
return JIM_ERR;
}
tmpListObj = Jim_NewListObj(interp, NULL, 0);
Jim_IncrRefCount(tmpListObj);
for (i = 0; i < listlen; i += stride) {
Jim_ListAppendElement(interp, tmpListObj, Jim_NewListObj(interp, elements + i, stride));
}
retCode = ListSortElements(interp, tmpListObj, &info);
if (retCode == JIM_OK) {
resObj = Jim_NewListObj(interp, NULL, 0);
for (i = 0; i < listlen; i += stride) {
Jim_ListAppendList(interp, resObj, Jim_ListGetIndex(interp, tmpListObj, i / stride));
}
Jim_SetResult(interp, resObj);
}
Jim_DecrRefCount(interp, tmpListObj);
}
else {
if ((shared = Jim_IsShared(resObj))) {
resObj = Jim_DuplicateObj(interp, resObj);
}
retCode = ListSortElements(interp, resObj, &info);
if (retCode == JIM_OK) {
Jim_SetResult(interp, resObj);
}
else if (shared) {
Jim_FreeNewObj(interp, resObj);
}
}
return retCode;
}
static int Jim_AppendCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
|
| ︙ | ︙ | |||
17137 17138 17139 17140 17141 17142 17143 |
}
Jim_SetResult(interp, stringObjPtr);
return JIM_OK;
}
| < < < < < < < < < < < | 18502 18503 18504 18505 18506 18507 18508 18509 18510 18511 18512 18513 18514 18515 18516 18517 18518 18519 18520 18521 18522 18523 18524 18525 18526 18527 18528 18529 18530 18531 18532 18533 |
}
Jim_SetResult(interp, stringObjPtr);
return JIM_OK;
}
static int Jim_EvalCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
int rc;
if (argc < 2) {
Jim_WrongNumArgs(interp, 1, argv, "arg ?arg ...?");
return JIM_ERR;
}
if (argc == 2) {
rc = Jim_EvalObj(interp, argv[1]);
}
else {
rc = Jim_EvalObj(interp, Jim_ConcatObj(interp, argc - 1, argv + 1));
}
return rc;
}
static int Jim_UplevelCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
if (argc >= 2) {
|
| ︙ | ︙ | |||
17222 17223 17224 17225 17226 17227 17228 17229 17230 17231 17232 17233 17234 17235 17236 17237 17238 17239 17240 |
static int Jim_ExprCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
int retcode;
if (argc == 2) {
retcode = Jim_EvalExpression(interp, argv[1]);
}
else if (argc > 2) {
Jim_Obj *objPtr;
objPtr = Jim_ConcatObj(interp, argc - 1, argv + 1);
Jim_IncrRefCount(objPtr);
retcode = Jim_EvalExpression(interp, objPtr);
Jim_DecrRefCount(interp, objPtr);
}
else {
Jim_WrongNumArgs(interp, 1, argv, "expression ?...?");
return JIM_ERR;
}
| > > > > > > | | > > > > > > | > > > > > > > > > > < < | < < > > > > > > > > > > > | | | | > > > | > > > > > > > > > > > > > | 18576 18577 18578 18579 18580 18581 18582 18583 18584 18585 18586 18587 18588 18589 18590 18591 18592 18593 18594 18595 18596 18597 18598 18599 18600 18601 18602 18603 18604 18605 18606 18607 18608 18609 18610 18611 18612 18613 18614 18615 18616 18617 18618 18619 18620 18621 18622 18623 18624 18625 18626 18627 18628 18629 18630 18631 18632 18633 18634 18635 18636 18637 18638 18639 18640 18641 18642 18643 18644 18645 18646 18647 18648 18649 18650 18651 18652 18653 18654 18655 18656 18657 18658 18659 18660 18661 18662 18663 18664 18665 18666 18667 18668 18669 |
static int Jim_ExprCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
int retcode;
if (argc == 2) {
retcode = Jim_EvalExpression(interp, argv[1]);
}
#ifndef JIM_COMPAT
else {
Jim_WrongNumArgs(interp, 1, argv, "expression");
retcode = JIM_ERR;
}
#else
else if (argc > 2) {
Jim_Obj *objPtr;
objPtr = Jim_ConcatObj(interp, argc - 1, argv + 1);
Jim_IncrRefCount(objPtr);
retcode = Jim_EvalExpression(interp, objPtr);
Jim_DecrRefCount(interp, objPtr);
}
else {
Jim_WrongNumArgs(interp, 1, argv, "expression ?...?");
return JIM_ERR;
}
#endif
return retcode;
}
static int JimBreakContinueHelper(Jim_Interp *interp, int argc, Jim_Obj *const *argv, int retcode)
{
if (argc != 1 && argc != 2) {
Jim_WrongNumArgs(interp, 1, argv, "?level?");
return JIM_ERR;
}
if (argc == 2) {
long level;
int ret = Jim_GetLong(interp, argv[1], &level);
if (ret != JIM_OK) {
return ret;
}
interp->returnLevel = level;
}
return retcode;
}
static int Jim_BreakCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
return JimBreakContinueHelper(interp, argc, argv, JIM_BREAK);
}
static int Jim_ContinueCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
return JimBreakContinueHelper(interp, argc, argv, JIM_CONTINUE);
}
static int Jim_StacktraceCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_Obj *listObj;
int i;
jim_wide skip = 0;
jim_wide last = 0;
if (argc > 1) {
if (Jim_GetWideExpr(interp, argv[1], &skip) != JIM_OK) {
return JIM_ERR;
}
}
if (argc > 2) {
if (Jim_GetWideExpr(interp, argv[2], &last) != JIM_OK) {
return JIM_ERR;
}
}
listObj = Jim_NewListObj(interp, NULL, 0);
for (i = skip; i <= interp->procLevel; i++) {
Jim_EvalFrame *frame = JimGetEvalFrameByProcLevel(interp, -i);
if (frame->procLevel < last) {
break;
}
JimAddStackFrame(interp, frame, listObj);
}
Jim_SetResult(interp, listObj);
return JIM_OK;
}
static int Jim_ReturnCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
int i;
Jim_Obj *stackTraceObj = NULL;
|
| ︙ | ︙ | |||
17310 17311 17312 17313 17314 17315 17316 |
}
interp->returnCode = returnCode;
interp->returnLevel = level;
if (i == argc - 1) {
Jim_SetResult(interp, argv[i]);
}
| | | 18709 18710 18711 18712 18713 18714 18715 18716 18717 18718 18719 18720 18721 18722 18723 |
}
interp->returnCode = returnCode;
interp->returnLevel = level;
if (i == argc - 1) {
Jim_SetResult(interp, argv[i]);
}
return level == 0 ? returnCode : JIM_RETURN;
}
static int Jim_TailcallCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
if (interp->framePtr->level == 0) {
Jim_SetResultString(interp, "tailcall can only be called from a proc or lambda", -1);
|
| ︙ | ︙ | |||
17368 17369 17370 17371 17372 17373 17374 |
Jim_Obj *prefixListObj = privData;
Jim_DecrRefCount(interp, prefixListObj);
}
static int Jim_AliasCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_Obj *prefixListObj;
| < < < < < < < | < < < < < | < | | | < > > > > > > > > > > > > > > > > > > > > > | 18767 18768 18769 18770 18771 18772 18773 18774 18775 18776 18777 18778 18779 18780 18781 18782 18783 18784 18785 18786 18787 18788 18789 18790 18791 18792 18793 18794 18795 18796 18797 18798 18799 18800 18801 18802 18803 18804 18805 18806 18807 18808 18809 18810 18811 18812 18813 18814 18815 18816 18817 18818 18819 18820 18821 18822 18823 18824 18825 18826 18827 18828 18829 18830 18831 18832 18833 18834 18835 18836 18837 18838 18839 18840 18841 18842 18843 18844 18845 18846 18847 |
Jim_Obj *prefixListObj = privData;
Jim_DecrRefCount(interp, prefixListObj);
}
static int Jim_AliasCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_Obj *prefixListObj;
if (argc < 3) {
Jim_WrongNumArgs(interp, 1, argv, "newname command ?args ...?");
return JIM_ERR;
}
prefixListObj = Jim_NewListObj(interp, argv + 2, argc - 2);
Jim_IncrRefCount(prefixListObj);
Jim_SetResult(interp, argv[1]);
return Jim_CreateCommandObj(interp, argv[1], JimAliasCmd, prefixListObj, JimAliasCmdDelete);
}
static int Jim_ProcCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_Cmd *cmd;
if (argc != 4 && argc != 5) {
Jim_WrongNumArgs(interp, 1, argv, "name arglist ?statics? body");
return JIM_ERR;
}
if (argc == 4) {
cmd = JimCreateProcedureCmd(interp, argv[2], NULL, argv[3], NULL);
}
else {
cmd = JimCreateProcedureCmd(interp, argv[2], argv[3], argv[4], NULL);
}
if (cmd) {
Jim_Obj *nameObjPtr = JimQualifyName(interp, argv[1]);
JimCreateCommand(interp, nameObjPtr, cmd);
JimUpdateProcNamespace(interp, cmd, nameObjPtr);
Jim_DecrRefCount(interp, nameObjPtr);
Jim_SetResult(interp, argv[1]);
return JIM_OK;
}
return JIM_ERR;
}
static int Jim_XtraceCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
if (argc != 2) {
Jim_WrongNumArgs(interp, 1, argv, "callback");
return JIM_ERR;
}
if (interp->traceCmdObj) {
Jim_DecrRefCount(interp, interp->traceCmdObj);
interp->traceCmdObj = NULL;
}
if (Jim_Length(argv[1])) {
interp->traceCmdObj = argv[1];
Jim_IncrRefCount(interp->traceCmdObj);
}
return JIM_OK;
}
static int Jim_LocalCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
int retcode;
if (argc < 2) {
Jim_WrongNumArgs(interp, 1, argv, "cmd ?args ...?");
|
| ︙ | ︙ | |||
17516 17517 17518 17519 17520 17521 17522 |
Jim_SetResultFormatted(interp, "can't interpret \"%#s\" as a lambda expression", argv[1]);
return JIM_ERR;
}
if (len == 3) {
#ifdef jim_ext_namespace
| | | 18922 18923 18924 18925 18926 18927 18928 18929 18930 18931 18932 18933 18934 18935 18936 |
Jim_SetResultFormatted(interp, "can't interpret \"%#s\" as a lambda expression", argv[1]);
return JIM_ERR;
}
if (len == 3) {
#ifdef jim_ext_namespace
nsObj = Jim_ListGetIndex(interp, argv[1], 2);
#else
Jim_SetResultString(interp, "namespaces not enabled", -1);
return JIM_ERR;
#endif
}
argListObjPtr = Jim_ListGetIndex(interp, argv[1], 0);
bodyObjPtr = Jim_ListGetIndex(interp, argv[1], 1);
|
| ︙ | ︙ | |||
17639 17640 17641 17642 17643 17644 17645 |
eachObjPtr = Jim_ListGetIndex(interp, mapListObjPtr, i);
k = Jim_String(eachObjPtr);
kl = Jim_Utf8Length(interp, eachObjPtr);
if (strLen >= kl && kl) {
int rc;
| | | 19045 19046 19047 19048 19049 19050 19051 19052 19053 19054 19055 19056 19057 19058 19059 |
eachObjPtr = Jim_ListGetIndex(interp, mapListObjPtr, i);
k = Jim_String(eachObjPtr);
kl = Jim_Utf8Length(interp, eachObjPtr);
if (strLen >= kl && kl) {
int rc;
rc = JimStringCompareUtf8(str, kl, k, kl, nocase);
if (rc == 0) {
if (noMatchStart) {
Jim_AppendString(interp, resultObjPtr, noMatchStart, str - noMatchStart);
noMatchStart = NULL;
}
Jim_AppendObj(interp, resultObjPtr, Jim_ListGetIndex(interp, mapListObjPtr, i + 1));
str += utf8_index(str, kl);
|
| ︙ | ︙ | |||
17672 17673 17674 17675 17676 17677 17678 |
static int Jim_StringCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
int len;
int opt_case = 1;
int option;
| | < < | > | > | > | > > > > > > > > > | > > > > > > > > | > > > | > > > | < | > > > > | > > > > > > > > > > > > > | | < > | > > | | < < | | | | < < < < < | | 19078 19079 19080 19081 19082 19083 19084 19085 19086 19087 19088 19089 19090 19091 19092 19093 19094 19095 19096 19097 19098 19099 19100 19101 19102 19103 19104 19105 19106 19107 19108 19109 19110 19111 19112 19113 19114 19115 19116 19117 19118 19119 19120 19121 19122 19123 19124 19125 19126 19127 19128 19129 19130 19131 19132 19133 19134 19135 19136 19137 19138 19139 19140 19141 19142 19143 19144 19145 19146 19147 19148 19149 19150 19151 19152 19153 19154 19155 19156 19157 19158 19159 19160 19161 19162 19163 19164 19165 19166 |
static int Jim_StringCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
int len;
int opt_case = 1;
int option;
static const char * const nocase_options[] = {
"-nocase", NULL
};
static const char * const nocase_length_options[] = {
"-nocase", "-length", NULL
};
enum {
OPT_BYTELENGTH,
OPT_BYTERANGE,
OPT_CAT,
OPT_COMPARE,
OPT_EQUAL,
OPT_FIRST,
OPT_INDEX,
OPT_IS,
OPT_LAST,
OPT_LENGTH,
OPT_MAP,
OPT_MATCH,
OPT_RANGE,
OPT_REPEAT,
OPT_REPLACE,
OPT_REVERSE,
OPT_TOLOWER,
OPT_TOTITLE,
OPT_TOUPPER,
OPT_TRIM,
OPT_TRIMLEFT,
OPT_TRIMRIGHT,
OPT_COUNT
};
static const jim_subcmd_type cmds[OPT_COUNT + 1] = {
JIM_DEF_SUBCMD("bytelength", "string", 1, 1),
JIM_DEF_SUBCMD("byterange", "string first last", 3, 3),
JIM_DEF_SUBCMD("cat", "?...?", 0, -1),
JIM_DEF_SUBCMD("compare", "?-nocase? ?-length int? string1 string2", 2, 5),
JIM_DEF_SUBCMD("equal", "?-nocase? ?-length int? string1 string2", 2, 5),
JIM_DEF_SUBCMD("first", "subString string ?index?", 2, 3),
JIM_DEF_SUBCMD("index", "string index", 2, 2),
JIM_DEF_SUBCMD("is", "class ?-strict? str", 2, 3),
JIM_DEF_SUBCMD("last", "subString string ?index?", 2, 3),
JIM_DEF_SUBCMD("length","string", 1, 1),
JIM_DEF_SUBCMD("map", "?-nocase? mapList string", 2, 3),
JIM_DEF_SUBCMD("match", "?-nocase? pattern string", 2, 3),
JIM_DEF_SUBCMD("range", "string first last", 3, 3),
JIM_DEF_SUBCMD("repeat", "string count", 2, 2),
JIM_DEF_SUBCMD("replace", "string first last ?string?", 3, 4),
JIM_DEF_SUBCMD("reverse", "string", 1, 1),
JIM_DEF_SUBCMD("tolower", "string", 1, 1),
JIM_DEF_SUBCMD("totitle", "string", 1, 1),
JIM_DEF_SUBCMD("toupper", "string", 1, 1),
JIM_DEF_SUBCMD("trim", "string ?trimchars?", 1, 2),
JIM_DEF_SUBCMD("trimleft", "string ?trimchars?", 1, 2),
JIM_DEF_SUBCMD("trimright", "string ?trimchars?", 1, 2),
{ }
};
const jim_subcmd_type *ct = Jim_ParseSubCmd(interp, cmds, argc, argv);
if (!ct) {
return JIM_ERR;
}
if (ct->function) {
return ct->function(interp, argc, argv);
}
option = ct - cmds;
switch (option) {
case OPT_LENGTH:
Jim_SetResultInt(interp, Jim_Utf8Length(interp, argv[2]));
return JIM_OK;
case OPT_BYTELENGTH:
Jim_SetResultInt(interp, Jim_Length(argv[2]));
return JIM_OK;
case OPT_CAT:{
Jim_Obj *objPtr;
if (argc == 3) {
objPtr = argv[2];
|
| ︙ | ︙ | |||
17745 17746 17747 17748 17749 17750 17751 |
int n = argc - 4;
int i = 2;
while (n > 0) {
int subopt;
if (Jim_GetEnum(interp, argv[i++], nocase_length_options, &subopt, NULL,
JIM_ENUM_ABBREV) != JIM_OK) {
badcompareargs:
| | | 19186 19187 19188 19189 19190 19191 19192 19193 19194 19195 19196 19197 19198 19199 19200 |
int n = argc - 4;
int i = 2;
while (n > 0) {
int subopt;
if (Jim_GetEnum(interp, argv[i++], nocase_length_options, &subopt, NULL,
JIM_ENUM_ABBREV) != JIM_OK) {
badcompareargs:
Jim_SubCmdArgError(interp, ct, argv[0]);
return JIM_ERR;
}
if (subopt == 0) {
opt_case = 0;
n--;
}
|
| ︙ | ︙ | |||
17773 17774 17775 17776 17777 17778 17779 17780 |
}
argv += argc - 2;
if (opt_length < 0 && option != OPT_COMPARE && opt_case) {
Jim_SetResultBool(interp, Jim_StringEqObj(argv[0], argv[1]));
}
else {
if (opt_length >= 0) {
| > > > > > | | < | > | > > | 19214 19215 19216 19217 19218 19219 19220 19221 19222 19223 19224 19225 19226 19227 19228 19229 19230 19231 19232 19233 19234 19235 19236 19237 19238 19239 19240 |
}
argv += argc - 2;
if (opt_length < 0 && option != OPT_COMPARE && opt_case) {
Jim_SetResultBool(interp, Jim_StringEqObj(argv[0], argv[1]));
}
else {
const char *s1 = Jim_String(argv[0]);
int l1 = Jim_Utf8Length(interp, argv[0]);
const char *s2 = Jim_String(argv[1]);
int l2 = Jim_Utf8Length(interp, argv[1]);
if (opt_length >= 0) {
if (l1 > opt_length) {
l1 = opt_length;
}
if (l2 > opt_length) {
l2 = opt_length;
}
}
n = JimStringCompareUtf8(s1, l1, s2, l2, !opt_case);
Jim_SetResultInt(interp, option == OPT_COMPARE ? n : n == 0);
}
return JIM_OK;
}
case OPT_MATCH:
if (argc != 4 &&
|
| ︙ | ︙ | |||
17820 17821 17822 17823 17824 17825 17826 |
if (objPtr == NULL) {
return JIM_ERR;
}
Jim_SetResult(interp, objPtr);
return JIM_OK;
}
| | < | | < < < | > | < | > | < < < < < < < < | < < < < | < < < < < > < < < < < | < < < < < > > > < < < | < < | < < < < < | | < > | | < | < < < < < < < < > | < > | < | | > | < | < < | | > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > | > > > > > > > > > > > > > | | > > > > > > > > > > > > > > > | 19268 19269 19270 19271 19272 19273 19274 19275 19276 19277 19278 19279 19280 19281 19282 19283 19284 19285 19286 19287 19288 19289 19290 19291 19292 19293 19294 19295 19296 19297 19298 19299 19300 19301 19302 19303 19304 19305 19306 19307 19308 19309 19310 19311 19312 19313 19314 19315 19316 19317 19318 19319 19320 19321 19322 19323 19324 19325 19326 19327 19328 19329 19330 19331 19332 19333 19334 19335 19336 19337 19338 19339 19340 19341 19342 19343 19344 19345 19346 19347 19348 19349 19350 19351 19352 19353 19354 19355 19356 19357 19358 19359 19360 19361 19362 19363 19364 19365 19366 19367 19368 19369 19370 19371 19372 19373 19374 19375 19376 19377 19378 19379 19380 19381 19382 19383 19384 19385 19386 19387 19388 19389 19390 19391 19392 19393 19394 19395 19396 19397 19398 19399 19400 19401 19402 19403 19404 19405 19406 19407 19408 19409 19410 19411 19412 19413 19414 19415 19416 19417 19418 19419 19420 19421 19422 19423 19424 19425 19426 19427 19428 19429 19430 19431 19432 19433 19434 19435 19436 19437 19438 19439 19440 19441 19442 19443 19444 19445 19446 19447 19448 19449 19450 19451 19452 19453 19454 19455 19456 19457 19458 19459 19460 19461 19462 19463 19464 19465 19466 19467 19468 19469 19470 19471 19472 19473 19474 19475 19476 19477 19478 19479 19480 19481 19482 19483 19484 19485 19486 19487 19488 19489 19490 19491 19492 19493 19494 19495 19496 19497 19498 19499 19500 19501 19502 19503 19504 19505 19506 19507 19508 19509 19510 19511 19512 19513 19514 19515 19516 19517 19518 19519 19520 19521 19522 19523 19524 19525 19526 19527 19528 19529 19530 19531 19532 19533 19534 19535 19536 19537 19538 19539 19540 19541 19542 19543 19544 19545 19546 19547 19548 19549 19550 19551 19552 19553 19554 19555 19556 19557 19558 19559 19560 19561 19562 19563 19564 19565 19566 19567 19568 19569 19570 19571 19572 19573 19574 19575 19576 19577 19578 19579 19580 19581 19582 19583 19584 19585 19586 19587 19588 19589 19590 19591 19592 19593 19594 19595 19596 19597 |
if (objPtr == NULL) {
return JIM_ERR;
}
Jim_SetResult(interp, objPtr);
return JIM_OK;
}
case OPT_RANGE:{
Jim_Obj *objPtr = Jim_StringRangeObj(interp, argv[2], argv[3], argv[4]);
if (objPtr == NULL) {
return JIM_ERR;
}
Jim_SetResult(interp, objPtr);
return JIM_OK;
}
case OPT_BYTERANGE:{
Jim_Obj *objPtr = Jim_StringByteRangeObj(interp, argv[2], argv[3], argv[4]);
if (objPtr == NULL) {
return JIM_ERR;
}
Jim_SetResult(interp, objPtr);
return JIM_OK;
}
case OPT_REPLACE:{
Jim_Obj *objPtr = JimStringReplaceObj(interp, argv[2], argv[3], argv[4], argc == 6 ? argv[5] : NULL);
if (objPtr == NULL) {
return JIM_ERR;
}
Jim_SetResult(interp, objPtr);
return JIM_OK;
}
case OPT_REPEAT:{
Jim_Obj *objPtr;
jim_wide count;
if (Jim_GetWideExpr(interp, argv[3], &count) != JIM_OK) {
return JIM_ERR;
}
objPtr = Jim_NewStringObj(interp, "", 0);
if (count > 0) {
while (count--) {
Jim_AppendObj(interp, objPtr, argv[2]);
}
}
Jim_SetResult(interp, objPtr);
return JIM_OK;
}
case OPT_REVERSE:{
char *buf, *p;
const char *str;
int i;
str = Jim_GetString(argv[2], &len);
buf = Jim_Alloc(len + 1);
assert(buf);
p = buf + len;
*p = 0;
for (i = 0; i < len; ) {
int c;
int l = utf8_tounicode(str, &c);
memcpy(p - l, str, l);
p -= l;
i += l;
str += l;
}
Jim_SetResult(interp, Jim_NewStringObjNoAlloc(interp, buf, len));
return JIM_OK;
}
case OPT_INDEX:{
int idx;
const char *str;
if (Jim_GetIndex(interp, argv[3], &idx) != JIM_OK) {
return JIM_ERR;
}
str = Jim_String(argv[2]);
len = Jim_Utf8Length(interp, argv[2]);
idx = JimRelToAbsIndex(len, idx);
if (idx < 0 || idx >= len || str == NULL) {
Jim_SetResultString(interp, "", 0);
}
else if (len == Jim_Length(argv[2])) {
Jim_SetResultString(interp, str + idx, 1);
}
else {
int c;
int i = utf8_index(str, idx);
Jim_SetResultString(interp, str + i, utf8_tounicode(str + i, &c));
}
return JIM_OK;
}
case OPT_FIRST:
case OPT_LAST:{
int idx = 0, l1, l2;
const char *s1, *s2;
s1 = Jim_String(argv[2]);
s2 = Jim_String(argv[3]);
l1 = Jim_Utf8Length(interp, argv[2]);
l2 = Jim_Utf8Length(interp, argv[3]);
if (argc == 5) {
if (Jim_GetIndex(interp, argv[4], &idx) != JIM_OK) {
return JIM_ERR;
}
idx = JimRelToAbsIndex(l2, idx);
if (idx < 0) {
idx = 0;
}
}
else if (option == OPT_LAST) {
idx = l2;
}
if (option == OPT_FIRST) {
Jim_SetResultInt(interp, JimStringFirst(s1, l1, s2, l2, idx));
}
else {
#ifdef JIM_UTF8
Jim_SetResultInt(interp, JimStringLastUtf8(s1, l1, s2, idx));
#else
Jim_SetResultInt(interp, JimStringLast(s1, l1, s2, idx));
#endif
}
return JIM_OK;
}
case OPT_TRIM:
Jim_SetResult(interp, JimStringTrim(interp, argv[2], argc == 4 ? argv[3] : NULL));
return JIM_OK;
case OPT_TRIMLEFT:
Jim_SetResult(interp, JimStringTrimLeft(interp, argv[2], argc == 4 ? argv[3] : NULL));
return JIM_OK;
case OPT_TRIMRIGHT:{
Jim_SetResult(interp, JimStringTrimRight(interp, argv[2], argc == 4 ? argv[3] : NULL));
return JIM_OK;
}
case OPT_TOLOWER:
Jim_SetResult(interp, JimStringToLower(interp, argv[2]));
return JIM_OK;
case OPT_TOUPPER:
Jim_SetResult(interp, JimStringToUpper(interp, argv[2]));
return JIM_OK;
case OPT_TOTITLE:
Jim_SetResult(interp, JimStringToTitle(interp, argv[2]));
return JIM_OK;
case OPT_IS:
if (argc == 5 && !Jim_CompareStringImmediate(interp, argv[3], "-strict")) {
Jim_SubCmdArgError(interp, ct, argv[0]);
return JIM_ERR;
}
return JimStringIs(interp, argv[argc - 1], argv[2], argc == 5);
}
return JIM_OK;
}
static int Jim_TimeCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
long i, count = 1;
jim_wide start, elapsed;
if (argc < 2) {
Jim_WrongNumArgs(interp, 1, argv, "script ?count?");
return JIM_ERR;
}
if (argc == 3) {
if (Jim_GetLong(interp, argv[2], &count) != JIM_OK)
return JIM_ERR;
}
if (count < 0)
return JIM_OK;
i = count;
start = Jim_GetTimeUsec(CLOCK_MONOTONIC_RAW);
while (i-- > 0) {
int retval;
retval = Jim_EvalObj(interp, argv[1]);
if (retval != JIM_OK) {
return retval;
}
}
elapsed = Jim_GetTimeUsec(CLOCK_MONOTONIC_RAW) - start;
if (elapsed < count * 10) {
Jim_SetResult(interp, Jim_NewDoubleObj(interp, elapsed * 1.0 / count));
}
else {
Jim_SetResultInt(interp, count == 0 ? 0 : elapsed / count);
}
Jim_AppendString(interp, Jim_GetResult(interp)," microseconds per iteration", -1);
return JIM_OK;
}
static int Jim_TimeRateCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
long us = 0;
jim_wide start, delta, overhead;
Jim_Obj *objPtr;
double us_per_iter;
int count;
int n;
if (argc < 2) {
Jim_WrongNumArgs(interp, 1, argv, "script ?milliseconds?");
return JIM_ERR;
}
if (argc == 3) {
if (Jim_GetLong(interp, argv[2], &us) != JIM_OK)
return JIM_ERR;
us *= 1000;
}
if (us < 1) {
us = 1000 * 1000;
}
start = Jim_GetTimeUsec(CLOCK_MONOTONIC_RAW);
count = 0;
do {
int retval = Jim_EvalObj(interp, argv[1]);
delta = Jim_GetTimeUsec(CLOCK_MONOTONIC_RAW) - start;
if (retval != JIM_OK) {
return retval;
}
count++;
} while (delta < us);
start = Jim_GetTimeUsec(CLOCK_MONOTONIC_RAW);
n = 0;
do {
int retval = Jim_EvalObj(interp, interp->nullScriptObj);
overhead = Jim_GetTimeUsec(CLOCK_MONOTONIC_RAW) - start;
if (retval != JIM_OK) {
return retval;
}
n++;
} while (n < count);
delta -= overhead;
us_per_iter = (double)delta / count;
objPtr = Jim_NewListObj(interp, NULL, 0);
Jim_ListAppendElement(interp, objPtr, Jim_NewStringObj(interp, "us_per_iter", -1));
Jim_ListAppendElement(interp, objPtr, Jim_NewDoubleObj(interp, us_per_iter));
Jim_ListAppendElement(interp, objPtr, Jim_NewStringObj(interp, "iters_per_sec", -1));
Jim_ListAppendElement(interp, objPtr, Jim_NewDoubleObj(interp, 1e6 / us_per_iter));
Jim_ListAppendElement(interp, objPtr, Jim_NewStringObj(interp, "count", -1));
Jim_ListAppendElement(interp, objPtr, Jim_NewIntObj(interp, count));
Jim_ListAppendElement(interp, objPtr, Jim_NewStringObj(interp, "elapsed_us", -1));
Jim_ListAppendElement(interp, objPtr, Jim_NewIntObj(interp, delta));
Jim_SetResult(interp, objPtr);
return JIM_OK;
}
static int Jim_ExitCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
long exitCode = 0;
if (argc > 2) {
Jim_WrongNumArgs(interp, 1, argv, "?exitCode?");
return JIM_ERR;
}
if (argc == 2) {
if (Jim_GetLong(interp, argv[1], &exitCode) != JIM_OK)
return JIM_ERR;
Jim_SetResult(interp, argv[1]);
}
interp->exitCode = exitCode;
return JIM_EXIT;
}
static int JimMatchReturnCodes(Jim_Interp *interp, Jim_Obj *retcodeListObj, int rc)
{
int len = Jim_ListLength(interp, retcodeListObj);
int i;
for (i = 0; i < len; i++) {
int returncode;
if (Jim_GetReturnCode(interp, Jim_ListGetIndex(interp, retcodeListObj, i), &returncode) != JIM_OK) {
return JIM_ERR;
}
if (rc == returncode) {
return JIM_OK;
}
}
return -1;
}
static int JimCatchTryHelper(Jim_Interp *interp, int istry, int argc, Jim_Obj *const *argv)
{
static const char * const wrongargs_catchtry[2] = {
"?-?no?code ... --? script ?resultVarName? ?optionVarName?",
"?-?no?code ... --? script ?on|trap codes vars script? ... ?finally script?"
};
int exitCode = 0;
int i;
int sig = 0;
int ok;
Jim_Obj *finallyScriptObj = NULL;
Jim_Obj *msgVarObj = NULL;
Jim_Obj *optsVarObj = NULL;
Jim_Obj *handlerScriptObj = NULL;
Jim_Obj *errorCodeObj;
int idx;
jim_wide ignore_mask = (1 << JIM_EXIT) | (1 << JIM_EVAL) | (1 << JIM_SIGNAL);
static const int max_ignore_code = sizeof(ignore_mask) * 8;
JimPanic((istry != 0 && istry != 1, "wrong args to JimCatchTryHelper"));
Jim_SetGlobalVariableStr(interp, "errorCode", Jim_NewStringObj(interp, "NONE", -1));
for (i = 1; i < argc - 1; i++) {
const char *arg = Jim_String(argv[i]);
jim_wide option;
int ignore;
|
| ︙ | ︙ | |||
18127 18128 18129 18130 18131 18132 18133 |
ignore_mask |= ((jim_wide)1 << option);
}
else {
ignore_mask &= (~((jim_wide)1 << option));
}
}
| | > | | | < < | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | > | < > > | | | | | | | | < | | | < | | | | | | > > > > | > | | > | > > > > > > > > > > > > | | > > > > > > > > > > > > > > < < < < | < | > > | | > | | | | | | | | | > | | < < < < < < < > | | < < < < < < < < < < < < < < < < < < < < < < < < < < < | 19628 19629 19630 19631 19632 19633 19634 19635 19636 19637 19638 19639 19640 19641 19642 19643 19644 19645 19646 19647 19648 19649 19650 19651 19652 19653 19654 19655 19656 19657 19658 19659 19660 19661 19662 19663 19664 19665 19666 19667 19668 19669 19670 19671 19672 19673 19674 19675 19676 19677 19678 19679 19680 19681 19682 19683 19684 19685 19686 19687 19688 19689 19690 19691 19692 19693 19694 19695 19696 19697 19698 19699 19700 19701 19702 19703 19704 19705 19706 19707 19708 19709 19710 19711 19712 19713 19714 19715 19716 19717 19718 19719 19720 19721 19722 19723 19724 19725 19726 19727 19728 19729 19730 19731 19732 19733 19734 19735 19736 19737 19738 19739 19740 19741 19742 19743 19744 19745 19746 19747 19748 19749 19750 19751 19752 19753 19754 19755 19756 19757 19758 19759 19760 19761 19762 19763 19764 19765 19766 19767 19768 19769 19770 19771 19772 19773 19774 19775 19776 19777 19778 19779 19780 19781 19782 19783 19784 19785 19786 19787 19788 19789 19790 19791 19792 19793 19794 19795 19796 19797 19798 19799 19800 19801 19802 19803 19804 19805 19806 19807 19808 19809 19810 19811 19812 19813 19814 19815 19816 19817 19818 19819 19820 19821 19822 19823 19824 19825 19826 19827 19828 19829 19830 19831 19832 19833 19834 19835 19836 19837 19838 19839 19840 19841 19842 19843 19844 19845 19846 19847 19848 19849 19850 19851 19852 19853 19854 19855 19856 19857 19858 19859 19860 19861 19862 19863 19864 19865 19866 19867 19868 19869 19870 19871 19872 19873 19874 19875 19876 19877 19878 19879 19880 19881 19882 19883 19884 19885 19886 19887 19888 19889 19890 19891 19892 19893 19894 19895 19896 19897 19898 19899 19900 19901 19902 19903 19904 19905 19906 19907 19908 19909 19910 19911 19912 19913 19914 19915 19916 19917 19918 19919 19920 19921 19922 |
ignore_mask |= ((jim_wide)1 << option);
}
else {
ignore_mask &= (~((jim_wide)1 << option));
}
}
idx = i;
if (argc - idx < 1) {
wrongargs:
Jim_WrongNumArgs(interp, 1, argv, wrongargs_catchtry[istry]);
return JIM_ERR;
}
if ((ignore_mask & (1 << JIM_SIGNAL)) == 0) {
sig++;
}
interp->signal_level += sig;
if (Jim_CheckSignal(interp)) {
exitCode = JIM_SIGNAL;
}
else {
exitCode = Jim_EvalObj(interp, argv[idx]);
interp->errorFlag = 0;
}
interp->signal_level -= sig;
errorCodeObj = Jim_GetGlobalVariableStr(interp, "errorCode", JIM_NONE);
idx++;
if (istry) {
while (idx < argc) {
int option;
int ret;
static const char * const try_options[] = { "on", "trap", "finally", NULL };
enum { TRY_ON, TRY_TRAP, TRY_FINALLY, };
if (Jim_GetEnum(interp, argv[idx], try_options, &option, "handler", JIM_ERRMSG) != JIM_OK) {
return JIM_ERR;
}
switch (option) {
case TRY_ON:
case TRY_TRAP:
if (idx + 4 > argc) {
goto wrongargs;
}
if (option == TRY_ON) {
ret = JimMatchReturnCodes(interp, argv[idx + 1], exitCode);
if (ret > JIM_OK) {
goto wrongargs;
}
}
else if (errorCodeObj) {
int len = Jim_ListLength(interp, argv[idx + 1]);
int i;
ret = JIM_OK;
for (i = 0; i < len; i++) {
Jim_Obj *matchObj = Jim_ListGetIndex(interp, argv[idx + 1], i);
Jim_Obj *objPtr = Jim_ListGetIndex(interp, errorCodeObj, i);
if (Jim_StringCompareObj(interp, matchObj, objPtr, 0) != 0) {
ret = -1;
break;
}
}
}
else {
ret = -1;
}
if (ret == JIM_OK && handlerScriptObj == NULL) {
msgVarObj = Jim_ListGetIndex(interp, argv[idx + 2], 0);
optsVarObj = Jim_ListGetIndex(interp, argv[idx + 2], 1);
handlerScriptObj = argv[idx + 3];
}
idx += 4;
break;
case TRY_FINALLY:
if (idx + 2 != argc) {
goto wrongargs;
}
finallyScriptObj = argv[idx + 1];
idx += 2;
break;
}
}
}
else {
if (argc - idx >= 1) {
msgVarObj = argv[idx];
idx++;
if (argc - idx >= 1) {
optsVarObj = argv[idx];
idx++;
}
}
}
if (exitCode >= 0 && exitCode < max_ignore_code && (((unsigned jim_wide)1 << exitCode) & ignore_mask)) {
if (finallyScriptObj) {
Jim_EvalObj(interp, finallyScriptObj);
}
return exitCode;
}
if (sig && exitCode == JIM_SIGNAL) {
if (interp->signal_set_result) {
interp->signal_set_result(interp, interp->sigmask);
}
else if (!istry) {
Jim_SetResultInt(interp, interp->sigmask);
}
interp->sigmask = 0;
}
ok = 1;
if (msgVarObj && Jim_Length(msgVarObj)) {
if (Jim_SetVariable(interp, msgVarObj, Jim_GetResult(interp)) != JIM_OK) {
ok = 0;
}
}
if (ok && optsVarObj && Jim_Length(optsVarObj)) {
Jim_Obj *optListObj = Jim_NewListObj(interp, NULL, 0);
Jim_ListAppendElement(interp, optListObj, Jim_NewStringObj(interp, "-code", -1));
Jim_ListAppendElement(interp, optListObj,
Jim_NewIntObj(interp, exitCode == JIM_RETURN ? interp->returnCode : exitCode));
Jim_ListAppendElement(interp, optListObj, Jim_NewStringObj(interp, "-level", -1));
Jim_ListAppendElement(interp, optListObj, Jim_NewIntObj(interp, interp->returnLevel));
if (exitCode == JIM_ERR) {
Jim_ListAppendElement(interp, optListObj, Jim_NewStringObj(interp, "-errorinfo",
-1));
Jim_ListAppendElement(interp, optListObj, interp->stackTrace);
if (errorCodeObj) {
Jim_ListAppendElement(interp, optListObj, Jim_NewStringObj(interp, "-errorcode", -1));
Jim_ListAppendElement(interp, optListObj, errorCodeObj);
}
}
if (Jim_SetVariable(interp, optsVarObj, optListObj) != JIM_OK) {
ok = 0;
}
}
if (ok && handlerScriptObj) {
exitCode = Jim_EvalObj(interp, handlerScriptObj);
}
if (finallyScriptObj) {
Jim_Obj *prevResultObj = Jim_GetResult(interp);
Jim_IncrRefCount(prevResultObj);
int ret = Jim_EvalObj(interp, finallyScriptObj);
if (ret == JIM_OK) {
Jim_SetResult(interp, prevResultObj);
}
else {
exitCode = ret;
}
Jim_DecrRefCount(interp, prevResultObj);
}
if (!istry) {
Jim_SetResultInt(interp, exitCode);
exitCode = JIM_OK;
}
return exitCode;
}
static int Jim_CatchCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
return JimCatchTryHelper(interp, 0, argc, argv);
}
static int Jim_TryCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
return JimCatchTryHelper(interp, 1, argc, argv);
}
static int Jim_RenameCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
if (argc != 3) {
Jim_WrongNumArgs(interp, 1, argv, "oldName newName");
return JIM_ERR;
}
return Jim_RenameCommand(interp, argv[1], argv[2]);
}
#define JIM_DICTMATCH_KEYS 0x0001
#define JIM_DICTMATCH_VALUES 0x002
int Jim_DictMatchTypes(Jim_Interp *interp, Jim_Obj *objPtr, Jim_Obj *patternObj, int match_type, int return_types)
{
Jim_Obj *listObjPtr;
Jim_Dict *dict;
int i;
if (SetDictFromAny(interp, objPtr) != JIM_OK) {
return JIM_ERR;
}
dict = objPtr->internalRep.dictValue;
listObjPtr = Jim_NewListObj(interp, NULL, 0);
for (i = 0; i < dict->len; i += 2 ) {
Jim_Obj *keyObj = dict->table[i];
Jim_Obj *valObj = dict->table[i + 1];
if (patternObj) {
Jim_Obj *matchObj = (match_type == JIM_DICTMATCH_KEYS) ? keyObj : valObj;
if (!Jim_StringMatchObj(interp, patternObj, matchObj, 0)) {
continue;
}
}
if (return_types & JIM_DICTMATCH_KEYS) {
Jim_ListAppendElement(interp, listObjPtr, keyObj);
}
if (return_types & JIM_DICTMATCH_VALUES) {
Jim_ListAppendElement(interp, listObjPtr, valObj);
}
}
Jim_SetResult(interp, listObjPtr);
return JIM_OK;
}
int Jim_DictSize(Jim_Interp *interp, Jim_Obj *objPtr)
{
if (SetDictFromAny(interp, objPtr) != JIM_OK) {
return -1;
}
return objPtr->internalRep.dictValue->len / 2;
}
Jim_Obj *Jim_DictMerge(Jim_Interp *interp, int objc, Jim_Obj *const *objv)
{
Jim_Obj *objPtr = Jim_NewDictObj(interp, NULL, 0);
int i;
JimPanic((objc == 0, "Jim_DictMerge called with objc=0"));
for (i = 0; i < objc; i++) {
Jim_Obj **table;
int tablelen;
int j;
table = Jim_DictPairs(interp, objv[i], &tablelen);
if (tablelen && !table) {
Jim_FreeNewObj(interp, objPtr);
return NULL;
}
for (j = 0; j < tablelen; j += 2) {
DictAddElement(interp, objPtr, table[j], table[j + 1]);
}
}
return objPtr;
}
int Jim_DictInfo(Jim_Interp *interp, Jim_Obj *objPtr)
{
char buffer[100];
Jim_Obj *output;
Jim_Dict *dict;
if (SetDictFromAny(interp, objPtr) != JIM_OK) {
return JIM_ERR;
}
dict = objPtr->internalRep.dictValue;
snprintf(buffer, sizeof(buffer), "%d entries in table, %d buckets", dict->len, dict->size);
output = Jim_NewStringObj(interp, buffer, -1);
Jim_SetResult(interp, output);
return JIM_OK;
}
static int Jim_EvalEnsemble(Jim_Interp *interp, const char *basecmd, const char *subcmd, int argc, Jim_Obj *const *argv)
{
Jim_Obj *prefixObj = Jim_NewStringObj(interp, basecmd, -1);
|
| ︙ | ︙ | |||
18364 18365 18366 18367 18368 18369 18370 |
dictObj = Jim_GetVariable(interp, dictVarName, JIM_ERRMSG);
if (dictObj == NULL || Jim_DictKeysVector(interp, dictObj, keyv, keyc, &objPtr, JIM_ERRMSG) != JIM_OK) {
return JIM_ERR;
}
| | > < > > | | | > < < | < < < < < | < | > > > > > > > > > | > > > > > > > | > > > > > > > | > > > > > > > > > > > > > > > > > > | < > < | > | < < < < | > > | | > | | | < | > | | | > > > > | < < < < | < < < < < < < < | < < < < < < < < < < < < < < < > > > | < < | | | > | > | 19938 19939 19940 19941 19942 19943 19944 19945 19946 19947 19948 19949 19950 19951 19952 19953 19954 19955 19956 19957 19958 19959 19960 19961 19962 19963 19964 19965 19966 19967 19968 19969 19970 19971 19972 19973 19974 19975 19976 19977 19978 19979 19980 19981 19982 19983 19984 19985 19986 19987 19988 19989 19990 19991 19992 19993 19994 19995 19996 19997 19998 19999 20000 20001 20002 20003 20004 20005 20006 20007 20008 20009 20010 20011 20012 20013 20014 20015 20016 20017 20018 20019 20020 20021 20022 20023 20024 20025 20026 20027 20028 20029 20030 20031 20032 20033 20034 20035 20036 20037 20038 20039 20040 20041 20042 20043 20044 20045 20046 20047 20048 20049 20050 20051 20052 20053 20054 20055 20056 20057 20058 20059 20060 20061 20062 20063 20064 20065 20066 20067 20068 20069 20070 20071 20072 20073 20074 20075 20076 20077 20078 20079 20080 20081 20082 20083 20084 20085 20086 20087 20088 20089 20090 20091 20092 20093 20094 20095 20096 20097 20098 20099 20100 20101 20102 20103 20104 20105 20106 20107 20108 20109 20110 20111 20112 20113 20114 20115 20116 20117 20118 20119 20120 20121 20122 20123 20124 20125 20126 20127 20128 20129 20130 20131 20132 20133 20134 20135 20136 20137 20138 |
dictObj = Jim_GetVariable(interp, dictVarName, JIM_ERRMSG);
if (dictObj == NULL || Jim_DictKeysVector(interp, dictObj, keyv, keyc, &objPtr, JIM_ERRMSG) != JIM_OK) {
return JIM_ERR;
}
dictValues = Jim_DictPairs(interp, objPtr, &len);
if (len && dictValues == NULL) {
return JIM_ERR;
}
for (i = 0; i < len; i += 2) {
if (Jim_SetVariable(interp, dictValues[i], dictValues[i + 1]) == JIM_ERR) {
return JIM_ERR;
}
}
if (Jim_Length(scriptObj)) {
ret = Jim_EvalObj(interp, scriptObj);
if (ret == JIM_OK && Jim_GetVariable(interp, dictVarName, 0) != NULL) {
Jim_Obj **newkeyv = Jim_Alloc(sizeof(*newkeyv) * (keyc + 1));
for (i = 0; i < keyc; i++) {
newkeyv[i] = keyv[i];
}
for (i = 0; i < len; i += 2) {
if (Jim_StringCompareObj(interp, dictVarName, dictValues[i], 0) != 0) {
objPtr = Jim_GetVariable(interp, dictValues[i], 0);
newkeyv[keyc] = dictValues[i];
Jim_SetDictKeysVector(interp, dictVarName, newkeyv, keyc + 1, objPtr, JIM_NORESULT);
}
}
Jim_Free(newkeyv);
}
}
return ret;
}
static int Jim_DictCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_Obj *objPtr;
int types = JIM_DICTMATCH_KEYS;
enum {
OPT_CREATE,
OPT_GET,
OPT_GETDEF,
OPT_GETWITHDEFAULT,
OPT_SET,
OPT_UNSET,
OPT_EXISTS,
OPT_KEYS,
OPT_SIZE,
OPT_INFO,
OPT_MERGE,
OPT_WITH,
OPT_APPEND,
OPT_LAPPEND,
OPT_INCR,
OPT_REMOVE,
OPT_VALUES,
OPT_FOR,
OPT_REPLACE,
OPT_UPDATE,
OPT_COUNT
};
static const jim_subcmd_type cmds[OPT_COUNT + 1] = {
JIM_DEF_SUBCMD("create", "?key value ...?", 0, -2),
JIM_DEF_SUBCMD("get", "dictionary ?key ...?", 1, -1),
JIM_DEF_SUBCMD_HIDDEN("getdef", "dictionary ?key ...? key default", 3, -1),
JIM_DEF_SUBCMD("getwithdefault", "dictionary ?key ...? key default", 3, -1),
JIM_DEF_SUBCMD("set", "varName key ?key ...? value", 3, -1),
JIM_DEF_SUBCMD("unset", "varName key ?key ...?", 2, -1),
JIM_DEF_SUBCMD("exists", "dictionary key ?key ...?", 2, -1),
JIM_DEF_SUBCMD("keys", "dictionary ?pattern?", 1, 2),
JIM_DEF_SUBCMD("size", "dictionary", 1, 1),
JIM_DEF_SUBCMD("info", "dictionary", 1, 1),
JIM_DEF_SUBCMD("merge", "?...?", 0, -1),
JIM_DEF_SUBCMD("with", "dictVar ?key ...? script", 2, -1),
JIM_DEF_SUBCMD("append", "varName key ?value ...?", 2, -1),
JIM_DEF_SUBCMD("lappend", "varName key ?value ...?", 2, -1),
JIM_DEF_SUBCMD("incr", "varName key ?increment?", 2, 3),
JIM_DEF_SUBCMD("remove", "dictionary ?key ...?", 1, -1),
JIM_DEF_SUBCMD("values", "dictionary ?pattern?", 1, 2),
JIM_DEF_SUBCMD("for", "vars dictionary script", 3, 3),
JIM_DEF_SUBCMD("replace", "dictionary ?key value ...?", 1, -1),
JIM_DEF_SUBCMD("update", "varName ?arg ...? script", 2, -1),
{ }
};
const jim_subcmd_type *ct = Jim_ParseSubCmd(interp, cmds, argc, argv);
if (!ct) {
return JIM_ERR;
}
if (ct->function) {
return ct->function(interp, argc, argv);
}
switch (ct - cmds) {
case OPT_GET:
if (Jim_DictKeysVector(interp, argv[2], argv + 3, argc - 3, &objPtr,
JIM_ERRMSG) != JIM_OK) {
return JIM_ERR;
}
Jim_SetResult(interp, objPtr);
return JIM_OK;
case OPT_GETDEF:
case OPT_GETWITHDEFAULT:{
int rc = Jim_DictKeysVector(interp, argv[2], argv + 3, argc - 4, &objPtr, JIM_ERRMSG);
if (rc == -1) {
return JIM_ERR;
}
if (rc == JIM_ERR) {
Jim_SetResult(interp, argv[argc - 1]);
}
else {
Jim_SetResult(interp, objPtr);
}
return JIM_OK;
}
case OPT_SET:
return Jim_SetDictKeysVector(interp, argv[2], argv + 3, argc - 4, argv[argc - 1], JIM_ERRMSG);
case OPT_EXISTS:{
int rc = Jim_DictKeysVector(interp, argv[2], argv + 3, argc - 3, &objPtr, JIM_NONE);
if (rc < 0) {
return JIM_ERR;
}
Jim_SetResultBool(interp, rc == JIM_OK);
return JIM_OK;
}
case OPT_UNSET:
if (Jim_SetDictKeysVector(interp, argv[2], argv + 3, argc - 3, NULL, JIM_NONE) != JIM_OK) {
return JIM_ERR;
}
return JIM_OK;
case OPT_VALUES:
types = JIM_DICTMATCH_VALUES;
case OPT_KEYS:
return Jim_DictMatchTypes(interp, argv[2], argc == 4 ? argv[3] : NULL, types, types);
case OPT_SIZE:
if (Jim_DictSize(interp, argv[2]) < 0) {
return JIM_ERR;
}
Jim_SetResultInt(interp, Jim_DictSize(interp, argv[2]));
return JIM_OK;
case OPT_MERGE:
if (argc == 2) {
return JIM_OK;
}
objPtr = Jim_DictMerge(interp, argc - 2, argv + 2);
if (objPtr == NULL) {
return JIM_ERR;
}
Jim_SetResult(interp, objPtr);
return JIM_OK;
case OPT_CREATE:
objPtr = Jim_NewDictObj(interp, argv + 2, argc - 2);
Jim_SetResult(interp, objPtr);
return JIM_OK;
case OPT_INFO:
return Jim_DictInfo(interp, argv[2]);
case OPT_WITH:
return JimDictWith(interp, argv[2], argv + 3, argc - 4, argv[argc - 1]);
case OPT_UPDATE:
if (argc < 6 || argc % 2) {
argc = 2;
}
default:
return Jim_EvalEnsemble(interp, "dict", Jim_String(argv[1]), argc - 2, argv + 2);
}
}
static int Jim_SubstCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
static const char * const options[] = {
"-nobackslashes", "-nocommands", "-novariables", NULL
|
| ︙ | ︙ | |||
18580 18581 18582 18583 18584 18585 18586 18587 18588 18589 |
if (Jim_SubstObj(interp, argv[argc - 1], &objPtr, flags) != JIM_OK) {
return JIM_ERR;
}
Jim_SetResult(interp, objPtr);
return JIM_OK;
}
static int Jim_InfoCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
| > > > > > > > > > < | < < < < < | > > > | > > > | > | > > > > > > | > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > | | < > | | > | < < < < | < < < < | 20169 20170 20171 20172 20173 20174 20175 20176 20177 20178 20179 20180 20181 20182 20183 20184 20185 20186 20187 20188 20189 20190 20191 20192 20193 20194 20195 20196 20197 20198 20199 20200 20201 20202 20203 20204 20205 20206 20207 20208 20209 20210 20211 20212 20213 20214 20215 20216 20217 20218 20219 20220 20221 20222 20223 20224 20225 20226 20227 20228 20229 20230 20231 20232 20233 20234 20235 20236 20237 20238 20239 20240 20241 20242 20243 20244 20245 20246 20247 20248 20249 20250 20251 20252 20253 20254 20255 20256 20257 20258 20259 20260 20261 20262 20263 20264 20265 20266 20267 20268 20269 20270 20271 20272 20273 20274 20275 20276 20277 20278 20279 20280 |
if (Jim_SubstObj(interp, argv[argc - 1], &objPtr, flags) != JIM_OK) {
return JIM_ERR;
}
Jim_SetResult(interp, objPtr);
return JIM_OK;
}
#ifdef jim_ext_namespace
static int JimIsGlobalNamespace(Jim_Obj *objPtr)
{
int len;
const char *str = Jim_GetString(objPtr, &len);
return len >= 2 && str[0] == ':' && str[1] == ':';
}
#endif
static int Jim_InfoCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_Obj *objPtr;
int mode = 0;
enum {
INFO_ALIAS,
INFO_ARGS,
INFO_BODY,
INFO_CHANNELS,
INFO_COMMANDS,
INFO_COMPLETE,
INFO_EXISTS,
INFO_FRAME,
INFO_GLOBALS,
INFO_HOSTNAME,
INFO_LEVEL,
INFO_LOCALS,
INFO_NAMEOFEXECUTABLE,
INFO_PATCHLEVEL,
INFO_PROCS,
INFO_REFERENCES,
INFO_RETURNCODES,
INFO_SCRIPT,
INFO_SOURCE,
INFO_STACKTRACE,
INFO_STATICS,
INFO_VARS,
INFO_VERSION,
INFO_COUNT
};
static const jim_subcmd_type cmds[INFO_COUNT + 1] = {
JIM_DEF_SUBCMD("alias", "command", 1, 1),
JIM_DEF_SUBCMD("args", "procname", 1, 1),
JIM_DEF_SUBCMD("body", "procname", 1, 1),
JIM_DEF_SUBCMD("channels", "?pattern?", 0, 1),
JIM_DEF_SUBCMD("commands", "?pattern?", 0, 1),
JIM_DEF_SUBCMD("complete", "script ?missing?", 1, 2),
JIM_DEF_SUBCMD("exists", "varName", 1, 1),
JIM_DEF_SUBCMD("frame", "?levelNum?", 0, 1),
JIM_DEF_SUBCMD("globals", "?pattern?", 0, 1),
JIM_DEF_SUBCMD("hostname", NULL, 0, 0),
JIM_DEF_SUBCMD("level", "?levelNum?", 0, 1),
JIM_DEF_SUBCMD("locals", "?pattern?", 0, 1),
JIM_DEF_SUBCMD("nameofexecutable", NULL, 0, 0),
JIM_DEF_SUBCMD("patchlevel", NULL, 0, 0),
JIM_DEF_SUBCMD("procs", "?pattern?", 0, 1),
JIM_DEF_SUBCMD("references", NULL, 0, 0),
JIM_DEF_SUBCMD("returncodes", "?code?", 0, 1),
JIM_DEF_SUBCMD("script", "?filename?", 0, 1),
JIM_DEF_SUBCMD("source", "source ?filename line?", 1, 3),
JIM_DEF_SUBCMD("stacktrace", NULL, 0, 0),
JIM_DEF_SUBCMD("statics", "procname", 1, 1),
JIM_DEF_SUBCMD("vars", "?pattern?", 0, 1),
JIM_DEF_SUBCMD("version", NULL, 0, 0),
{ }
};
const jim_subcmd_type *ct;
#ifdef jim_ext_namespace
int nons = 0;
if (argc > 2 && Jim_CompareStringImmediate(interp, argv[1], "-nons")) {
argc--;
argv++;
nons = 1;
}
#endif
ct = Jim_ParseSubCmd(interp, cmds, argc, argv);
if (!ct) {
return JIM_ERR;
}
if (ct->function) {
return ct->function(interp, argc, argv);
}
int option = ct - cmds;
switch (option) {
case INFO_EXISTS:
Jim_SetResultBool(interp, Jim_GetVariable(interp, argv[2], 0) != NULL);
return JIM_OK;
case INFO_ALIAS:{
Jim_Cmd *cmdPtr;
if ((cmdPtr = Jim_GetCommand(interp, argv[2], JIM_ERRMSG)) == NULL) {
return JIM_ERR;
}
if (cmdPtr->isproc || cmdPtr->u.native.cmdProc != JimAliasCmd) {
Jim_SetResultFormatted(interp, "command \"%#s\" is not an alias", argv[2]);
return JIM_ERR;
}
|
| ︙ | ︙ | |||
18659 18660 18661 18662 18663 18664 18665 |
#endif
case INFO_PROCS:
mode++;
case INFO_COMMANDS:
| < < < < | | < < < < | | | > | < > | | | | | 20290 20291 20292 20293 20294 20295 20296 20297 20298 20299 20300 20301 20302 20303 20304 20305 20306 20307 20308 20309 20310 20311 20312 20313 20314 20315 20316 20317 20318 20319 20320 20321 20322 20323 20324 20325 20326 20327 20328 20329 20330 20331 20332 20333 20334 20335 20336 20337 20338 20339 20340 20341 20342 20343 20344 20345 20346 20347 |
#endif
case INFO_PROCS:
mode++;
case INFO_COMMANDS:
#ifdef jim_ext_namespace
if (!nons) {
if (Jim_Length(interp->framePtr->nsObj) || (argc == 3 && JimIsGlobalNamespace(argv[2]))) {
return Jim_EvalPrefix(interp, "namespace info", argc - 1, argv + 1);
}
}
#endif
Jim_SetResult(interp, JimCommandsList(interp, (argc == 3) ? argv[2] : NULL, mode));
return JIM_OK;
case INFO_VARS:
mode++;
case INFO_LOCALS:
mode++;
case INFO_GLOBALS:
#ifdef jim_ext_namespace
if (!nons) {
if (Jim_Length(interp->framePtr->nsObj) || (argc == 3 && JimIsGlobalNamespace(argv[2]))) {
return Jim_EvalPrefix(interp, "namespace info", argc - 1, argv + 1);
}
}
#endif
Jim_SetResult(interp, JimVariablesList(interp, argc == 3 ? argv[2] : NULL, mode));
return JIM_OK;
case INFO_SCRIPT:
if (argc == 3) {
Jim_IncrRefCount(argv[2]);
Jim_DecrRefCount(interp, interp->currentFilenameObj);
interp->currentFilenameObj = argv[2];
}
Jim_SetResult(interp, interp->currentFilenameObj);
return JIM_OK;
case INFO_SOURCE:{
jim_wide line;
Jim_Obj *resObjPtr;
Jim_Obj *fileNameObj;
if (argc == 4) {
Jim_SubCmdArgError(interp, ct, argv[0]);
return JIM_ERR;
}
if (argc == 5) {
if (Jim_GetWide(interp, argv[4], &line) != JIM_OK) {
return JIM_ERR;
}
resObjPtr = Jim_NewStringObj(interp, Jim_String(argv[2]), Jim_Length(argv[2]));
|
| ︙ | ︙ | |||
18738 18739 18740 18741 18742 18743 18744 |
line = 1;
}
resObjPtr = Jim_NewListObj(interp, NULL, 0);
Jim_ListAppendElement(interp, resObjPtr, fileNameObj);
Jim_ListAppendElement(interp, resObjPtr, Jim_NewIntObj(interp, line));
}
Jim_SetResult(interp, resObjPtr);
| | | < | < | < | | | | | | > > | > > > | | | | > > | < < < < | > > > > > > | | | < < < < < > < | 20362 20363 20364 20365 20366 20367 20368 20369 20370 20371 20372 20373 20374 20375 20376 20377 20378 20379 20380 20381 20382 20383 20384 20385 20386 20387 20388 20389 20390 20391 20392 20393 20394 20395 20396 20397 20398 20399 20400 20401 20402 20403 20404 20405 20406 20407 20408 20409 20410 20411 20412 20413 20414 20415 20416 20417 20418 20419 20420 20421 20422 20423 20424 20425 20426 20427 20428 20429 20430 20431 20432 20433 20434 20435 20436 20437 20438 20439 20440 20441 20442 20443 20444 20445 20446 20447 20448 20449 20450 20451 20452 20453 20454 20455 20456 20457 20458 20459 |
line = 1;
}
resObjPtr = Jim_NewListObj(interp, NULL, 0);
Jim_ListAppendElement(interp, resObjPtr, fileNameObj);
Jim_ListAppendElement(interp, resObjPtr, Jim_NewIntObj(interp, line));
}
Jim_SetResult(interp, resObjPtr);
return JIM_OK;
}
case INFO_STACKTRACE:
Jim_SetResult(interp, interp->stackTrace);
return JIM_OK;
case INFO_LEVEL:
if (argc == 2) {
Jim_SetResultInt(interp, interp->framePtr->level);
}
else {
if (JimInfoLevel(interp, argv[2], &objPtr) != JIM_OK) {
return JIM_ERR;
}
Jim_SetResult(interp, objPtr);
}
return JIM_OK;
case INFO_FRAME:
if (argc == 2) {
Jim_SetResultInt(interp, interp->procLevel + 1);
}
else {
if (JimInfoFrame(interp, argv[2], &objPtr) != JIM_OK) {
return JIM_ERR;
}
Jim_SetResult(interp, objPtr);
}
return JIM_OK;
case INFO_BODY:
case INFO_STATICS:
case INFO_ARGS:{
Jim_Cmd *cmdPtr;
if ((cmdPtr = Jim_GetCommand(interp, argv[2], JIM_ERRMSG)) == NULL) {
return JIM_ERR;
}
if (!cmdPtr->isproc) {
Jim_SetResultFormatted(interp, "command \"%#s\" is not a procedure", argv[2]);
return JIM_ERR;
}
switch (option) {
#ifdef JIM_NO_INTROSPECTION
default:
Jim_SetResultString(interp, "unsupported", -1);
return JIM_ERR;
#else
case INFO_BODY:
Jim_SetResult(interp, cmdPtr->u.proc.bodyObjPtr);
break;
case INFO_ARGS:
Jim_SetResult(interp, cmdPtr->u.proc.argListObjPtr);
break;
#endif
case INFO_STATICS:
if (cmdPtr->u.proc.staticVars) {
Jim_SetResult(interp, JimHashtablePatternMatch(interp, cmdPtr->u.proc.staticVars,
NULL, JimVariablesMatch, JIM_VARLIST_LOCALS | JIM_VARLIST_VALUES));
}
break;
}
return JIM_OK;
}
case INFO_VERSION:
case INFO_PATCHLEVEL:{
char buf[(JIM_INTEGER_SPACE * 2) + 1];
sprintf(buf, "%d.%d", JIM_VERSION / 100, JIM_VERSION % 100);
Jim_SetResultString(interp, buf, -1);
return JIM_OK;
}
case INFO_COMPLETE: {
char missing;
Jim_SetResultBool(interp, Jim_ScriptIsComplete(interp, argv[2], &missing));
if (missing != ' ' && argc == 4) {
Jim_SetVariable(interp, argv[3], Jim_NewStringObj(interp, &missing, 1));
}
return JIM_OK;
}
case INFO_HOSTNAME:
return Jim_Eval(interp, "os.gethostname");
case INFO_NAMEOFEXECUTABLE:
|
| ︙ | ︙ | |||
18858 18859 18860 18861 18862 18863 18864 |
if (*name == '?') {
Jim_SetResultInt(interp, code);
}
else {
Jim_SetResultString(interp, name, -1);
}
}
| < < | < < > > < | 20483 20484 20485 20486 20487 20488 20489 20490 20491 20492 20493 20494 20495 20496 20497 20498 20499 20500 20501 20502 20503 20504 20505 20506 20507 |
if (*name == '?') {
Jim_SetResultInt(interp, code);
}
else {
Jim_SetResultString(interp, name, -1);
}
}
return JIM_OK;
case INFO_REFERENCES:
#ifdef JIM_REFERENCES
return JimInfoReferences(interp, argc, argv);
#else
Jim_SetResultString(interp, "not supported", -1);
return JIM_ERR;
#endif
default:
abort();
}
}
static int Jim_ExistsCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_Obj *objPtr;
int result = 0;
|
| ︙ | ︙ | |||
19143 19144 19145 19146 19147 19148 19149 |
return JIM_ERR;
}
Jim_SetResult(interp, argv[1]);
if (argc == 3) {
JimSetStackTrace(interp, argv[2]);
return JIM_ERR;
}
| < | 20765 20766 20767 20768 20769 20770 20771 20772 20773 20774 20775 20776 20777 20778 |
return JIM_ERR;
}
Jim_SetResult(interp, argv[1]);
if (argc == 3) {
JimSetStackTrace(interp, argv[2]);
return JIM_ERR;
}
return JIM_ERR;
}
static int Jim_LrangeCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_Obj *objPtr;
|
| ︙ | ︙ | |||
19166 19167 19168 19169 19170 19171 19172 |
return JIM_OK;
}
static int Jim_LrepeatCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_Obj *objPtr;
| | | < > | > | | 20787 20788 20789 20790 20791 20792 20793 20794 20795 20796 20797 20798 20799 20800 20801 20802 20803 20804 20805 20806 20807 20808 20809 20810 20811 20812 20813 20814 20815 20816 20817 |
return JIM_OK;
}
static int Jim_LrepeatCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_Obj *objPtr;
jim_wide count;
if (argc < 2 || Jim_GetWideExpr(interp, argv[1], &count) != JIM_OK || count < 0) {
Jim_WrongNumArgs(interp, 1, argv, "count ?value ...?");
return JIM_ERR;
}
if (count == 0 || argc == 2) {
Jim_SetEmptyResult(interp);
return JIM_OK;
}
argc -= 2;
argv += 2;
objPtr = Jim_NewListObj(interp, NULL, 0);
ListEnsureLength(objPtr, argc * count);
while (count--) {
ListInsertElements(objPtr, -1, argc, argv);
}
Jim_SetResult(interp, objPtr);
return JIM_OK;
}
|
| ︙ | ︙ | |||
19241 19242 19243 19244 19245 19246 19247 |
}
}
Jim_SetResult(interp, listObjPtr);
return JIM_OK;
}
| | | 20863 20864 20865 20866 20867 20868 20869 20870 20871 20872 20873 20874 20875 20876 20877 |
}
}
Jim_SetResult(interp, listObjPtr);
return JIM_OK;
}
if (argc > 3) {
Jim_WrongNumArgs(interp, 1, argv, "varName ?default?");
return JIM_ERR;
}
key = Jim_String(argv[1]);
val = getenv(key);
if (val == NULL) {
if (argc < 3) {
|
| ︙ | ︙ | |||
19284 19285 19286 19287 19288 19289 19290 |
int len;
if (argc != 2) {
Jim_WrongNumArgs(interp, 1, argv, "list");
return JIM_ERR;
}
JimListGetElements(interp, argv[1], &len, &ele);
| < > > | 20906 20907 20908 20909 20910 20911 20912 20913 20914 20915 20916 20917 20918 20919 20920 20921 20922 |
int len;
if (argc != 2) {
Jim_WrongNumArgs(interp, 1, argv, "list");
return JIM_ERR;
}
JimListGetElements(interp, argv[1], &len, &ele);
revObjPtr = Jim_NewListObj(interp, NULL, 0);
ListEnsureLength(revObjPtr, len);
len--;
while (len >= 0)
ListAppendElement(revObjPtr, ele[len--]);
Jim_SetResult(interp, revObjPtr);
return JIM_OK;
}
static int JimRangeLen(jim_wide start, jim_wide end, jim_wide step)
|
| ︙ | ︙ | |||
19327 19328 19329 19330 19331 19332 19333 |
Jim_Obj *objPtr;
if (argc < 2 || argc > 4) {
Jim_WrongNumArgs(interp, 1, argv, "?start? end ?step?");
return JIM_ERR;
}
if (argc == 2) {
| | | | | > | | | | 20950 20951 20952 20953 20954 20955 20956 20957 20958 20959 20960 20961 20962 20963 20964 20965 20966 20967 20968 20969 20970 20971 20972 20973 20974 20975 20976 20977 20978 20979 20980 20981 20982 20983 20984 20985 20986 20987 20988 20989 20990 20991 20992 20993 20994 20995 20996 20997 20998 20999 21000 21001 21002 |
Jim_Obj *objPtr;
if (argc < 2 || argc > 4) {
Jim_WrongNumArgs(interp, 1, argv, "?start? end ?step?");
return JIM_ERR;
}
if (argc == 2) {
if (Jim_GetWideExpr(interp, argv[1], &end) != JIM_OK)
return JIM_ERR;
}
else {
if (Jim_GetWideExpr(interp, argv[1], &start) != JIM_OK ||
Jim_GetWideExpr(interp, argv[2], &end) != JIM_OK)
return JIM_ERR;
if (argc == 4 && Jim_GetWideExpr(interp, argv[3], &step) != JIM_OK)
return JIM_ERR;
}
if ((len = JimRangeLen(start, end, step)) == -1) {
Jim_SetResultString(interp, "Invalid (infinite?) range specified", -1);
return JIM_ERR;
}
objPtr = Jim_NewListObj(interp, NULL, 0);
ListEnsureLength(objPtr, len);
for (i = 0; i < len; i++)
ListAppendElement(objPtr, Jim_NewIntObj(interp, start + i * step));
Jim_SetResult(interp, objPtr);
return JIM_OK;
}
static int Jim_RandCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
jim_wide min = 0, max = 0, len, maxMul;
if (argc < 1 || argc > 3) {
Jim_WrongNumArgs(interp, 1, argv, "?min? max");
return JIM_ERR;
}
if (argc == 1) {
max = JIM_WIDE_MAX;
} else if (argc == 2) {
if (Jim_GetWideExpr(interp, argv[1], &max) != JIM_OK)
return JIM_ERR;
} else if (argc == 3) {
if (Jim_GetWideExpr(interp, argv[1], &min) != JIM_OK ||
Jim_GetWideExpr(interp, argv[2], &max) != JIM_OK)
return JIM_ERR;
}
len = max-min;
if (len < 0) {
Jim_SetResultString(interp, "Invalid arguments (max < min)", -1);
return JIM_ERR;
}
|
| ︙ | ︙ | |||
19415 19416 19417 19418 19419 19420 19421 |
{"lsearch", Jim_LsearchCoreCommand},
{"llength", Jim_LlengthCoreCommand},
{"lappend", Jim_LappendCoreCommand},
{"linsert", Jim_LinsertCoreCommand},
{"lreplace", Jim_LreplaceCoreCommand},
{"lsort", Jim_LsortCoreCommand},
{"append", Jim_AppendCoreCommand},
| < > > > | 21039 21040 21041 21042 21043 21044 21045 21046 21047 21048 21049 21050 21051 21052 21053 21054 21055 21056 21057 21058 21059 21060 21061 21062 21063 21064 21065 21066 21067 21068 21069 |
{"lsearch", Jim_LsearchCoreCommand},
{"llength", Jim_LlengthCoreCommand},
{"lappend", Jim_LappendCoreCommand},
{"linsert", Jim_LinsertCoreCommand},
{"lreplace", Jim_LreplaceCoreCommand},
{"lsort", Jim_LsortCoreCommand},
{"append", Jim_AppendCoreCommand},
{"eval", Jim_EvalCoreCommand},
{"uplevel", Jim_UplevelCoreCommand},
{"expr", Jim_ExprCoreCommand},
{"break", Jim_BreakCoreCommand},
{"continue", Jim_ContinueCoreCommand},
{"proc", Jim_ProcCoreCommand},
{"xtrace", Jim_XtraceCoreCommand},
{"concat", Jim_ConcatCoreCommand},
{"return", Jim_ReturnCoreCommand},
{"upvar", Jim_UpvarCoreCommand},
{"global", Jim_GlobalCoreCommand},
{"string", Jim_StringCoreCommand},
{"time", Jim_TimeCoreCommand},
{"timerate", Jim_TimeRateCoreCommand},
{"exit", Jim_ExitCoreCommand},
{"catch", Jim_CatchCoreCommand},
{"try", Jim_TryCoreCommand},
#ifdef JIM_REFERENCES
{"ref", Jim_RefCoreCommand},
{"getref", Jim_GetrefCoreCommand},
{"setref", Jim_SetrefCoreCommand},
{"finalize", Jim_FinalizeCoreCommand},
{"collect", Jim_CollectCoreCommand},
#endif
|
| ︙ | ︙ | |||
19458 19459 19460 19461 19462 19463 19464 19465 19466 19467 19468 19469 19470 19471 |
{"lreverse", Jim_LreverseCoreCommand},
{"range", Jim_RangeCoreCommand},
{"rand", Jim_RandCoreCommand},
{"tailcall", Jim_TailcallCoreCommand},
{"local", Jim_LocalCoreCommand},
{"upcall", Jim_UpcallCoreCommand},
{"apply", Jim_ApplyCoreCommand},
{NULL, NULL},
};
void Jim_RegisterCoreCommands(Jim_Interp *interp)
{
int i = 0;
| > | 21084 21085 21086 21087 21088 21089 21090 21091 21092 21093 21094 21095 21096 21097 21098 |
{"lreverse", Jim_LreverseCoreCommand},
{"range", Jim_RangeCoreCommand},
{"rand", Jim_RandCoreCommand},
{"tailcall", Jim_TailcallCoreCommand},
{"local", Jim_LocalCoreCommand},
{"upcall", Jim_UpcallCoreCommand},
{"apply", Jim_ApplyCoreCommand},
{"stacktrace", Jim_StacktraceCoreCommand},
{NULL, NULL},
};
void Jim_RegisterCoreCommands(Jim_Interp *interp)
{
int i = 0;
|
| ︙ | ︙ | |||
19685 19686 19687 19688 19689 19690 19691 19692 19693 19694 19695 19696 19697 19698 19699 |
Jim_SetResult(interp, Jim_NewStringObjNoAlloc(interp, buf, len));
for (i = 0; i < nobjparam; i++) {
Jim_DecrRefCount(interp, objparam[i]);
}
}
#ifndef jim_ext_package
int Jim_PackageProvide(Jim_Interp *interp, const char *name, const char *ver, int flags)
{
return JIM_OK;
}
#endif
#ifndef jim_ext_aio
| > > > > > > > > > | < | | | > > > > > | | > > | > > > > | | | | | | > | 21312 21313 21314 21315 21316 21317 21318 21319 21320 21321 21322 21323 21324 21325 21326 21327 21328 21329 21330 21331 21332 21333 21334 21335 21336 21337 21338 21339 21340 21341 21342 21343 21344 21345 21346 21347 21348 21349 21350 21351 21352 21353 21354 21355 21356 21357 21358 21359 21360 21361 21362 21363 21364 21365 21366 21367 21368 21369 21370 21371 21372 21373 21374 21375 21376 21377 21378 21379 21380 21381 21382 21383 21384 21385 21386 21387 21388 21389 21390 21391 21392 21393 21394 21395 21396 21397 21398 21399 21400 21401 21402 21403 21404 21405 21406 21407 21408 21409 21410 21411 21412 21413 21414 21415 21416 21417 21418 21419 21420 21421 21422 21423 21424 21425 21426 21427 21428 21429 21430 21431 21432 21433 21434 21435 21436 |
Jim_SetResult(interp, Jim_NewStringObjNoAlloc(interp, buf, len));
for (i = 0; i < nobjparam; i++) {
Jim_DecrRefCount(interp, objparam[i]);
}
}
int Jim_CheckAbiVersion(Jim_Interp *interp, int abi_version)
{
if (abi_version != JIM_ABI_VERSION) {
Jim_SetResultString(interp, "ABI version mismatch", -1);
return JIM_ERR;
}
return JIM_OK;
}
#ifndef jim_ext_package
int Jim_PackageProvide(Jim_Interp *interp, const char *name, const char *ver, int flags)
{
return JIM_OK;
}
#endif
#ifndef jim_ext_aio
int Jim_AioFilehandle(Jim_Interp *interp, Jim_Obj *fhObj)
{
return -1;
}
#endif
#include <stdio.h>
#include <string.h>
static int subcmd_null(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
return JIM_OK;
}
static const jim_subcmd_type dummy_subcmd = {
"dummy", NULL, subcmd_null, 0, 0, JIM_MODFLAG_HIDDEN
};
static Jim_Obj *subcmd_cmd_list(Jim_Interp *interp, const jim_subcmd_type * ct, const char *sep)
{
Jim_Obj *listObj = Jim_NewListObj(interp, NULL, 0);
Jim_Obj *sortCmd[2];
for (; ct->cmd; ct++) {
if (!(ct->flags & JIM_MODFLAG_HIDDEN)) {
Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, ct->cmd, -1));
}
}
sortCmd[0] = Jim_NewStringObj(interp, "lsort", -1);
sortCmd[1] = listObj;
if (Jim_EvalObjVector(interp, 2, sortCmd) == JIM_OK) {
return Jim_ListJoin(interp, Jim_GetResult(interp), sep, strlen(sep));
}
return Jim_GetResult(interp);
}
static void bad_subcmd(Jim_Interp *interp, const jim_subcmd_type * command_table, const char *type,
Jim_Obj *cmd, Jim_Obj *subcmd)
{
Jim_SetResultFormatted(interp, "%#s, %s command \"%#s\": should be %#s", cmd, type,
subcmd, subcmd_cmd_list(interp, command_table, ", "));
}
static void show_cmd_usage(Jim_Interp *interp, const jim_subcmd_type * command_table, int argc,
Jim_Obj *const *argv)
{
Jim_SetResultFormatted(interp, "Usage: \"%#s command ... \", where command is one of: %#s",
argv[0], subcmd_cmd_list(interp, command_table, ", "));
}
static void add_cmd_usage(Jim_Interp *interp, const jim_subcmd_type * ct, Jim_Obj *cmd)
{
if (cmd) {
Jim_AppendStrings(interp, Jim_GetResult(interp), Jim_String(cmd), " ", NULL);
}
Jim_AppendStrings(interp, Jim_GetResult(interp), ct->cmd, NULL);
if (ct->args && *ct->args) {
Jim_AppendStrings(interp, Jim_GetResult(interp), " ", ct->args, NULL);
}
}
void Jim_SubCmdArgError(Jim_Interp *interp, const jim_subcmd_type * ct, Jim_Obj *subcmd)
{
Jim_SetResultString(interp, "wrong # args: should be \"", -1);
add_cmd_usage(interp, ct, subcmd);
Jim_AppendStrings(interp, Jim_GetResult(interp), "\"", NULL);
}
static const Jim_ObjType subcmdLookupObjType = {
"subcmd-lookup",
NULL,
NULL,
NULL,
JIM_TYPE_REFERENCES
};
const jim_subcmd_type *Jim_ParseSubCmd(Jim_Interp *interp, const jim_subcmd_type * command_table,
int argc, Jim_Obj *const *argv)
{
const jim_subcmd_type *ct;
const jim_subcmd_type *partial = 0;
int cmdlen;
Jim_Obj *cmd;
const char *cmdstr;
int help = 0;
int argsok = 1;
if (argc < 2) {
Jim_SetResultFormatted(interp, "wrong # args: should be \"%#s command ...\"\n"
"Use \"%#s -help ?command?\" for help", argv[0], argv[0]);
return 0;
}
|
| ︙ | ︙ | |||
19808 19809 19810 19811 19812 19813 19814 |
cmd = argv[2];
}
if (Jim_CompareStringImmediate(interp, cmd, "-commands")) {
| < < | | 21455 21456 21457 21458 21459 21460 21461 21462 21463 21464 21465 21466 21467 21468 21469 |
cmd = argv[2];
}
if (Jim_CompareStringImmediate(interp, cmd, "-commands")) {
Jim_SetResult(interp, subcmd_cmd_list(interp, command_table, " "));
return &dummy_subcmd;
}
cmdstr = Jim_GetString(cmd, &cmdlen);
for (ct = command_table; ct->cmd; ct++) {
if (Jim_CompareStringImmediate(interp, cmd, ct->cmd)) {
|
| ︙ | ︙ | |||
19868 19869 19870 19871 19872 19873 19874 |
Jim_FreeIntRep(interp, cmd);
cmd->typePtr = &subcmdLookupObjType;
cmd->internalRep.ptrIntValue.ptr = (void *)command_table;
cmd->internalRep.ptrIntValue.int1 = ct - command_table;
found:
| > | > > > > > > > > > > | 21513 21514 21515 21516 21517 21518 21519 21520 21521 21522 21523 21524 21525 21526 21527 21528 21529 21530 21531 21532 21533 21534 21535 21536 21537 21538 |
Jim_FreeIntRep(interp, cmd);
cmd->typePtr = &subcmdLookupObjType;
cmd->internalRep.ptrIntValue.ptr = (void *)command_table;
cmd->internalRep.ptrIntValue.int1 = ct - command_table;
found:
if (argc - 2 < ct->minargs) {
argsok = 0;
}
else if (ct->maxargs >= 0 && argc - 2 > ct->maxargs) {
argsok = 0;
}
else if (ct->maxargs < -1 && (argc - 2) % -ct->maxargs != 0) {
argsok = 0;
}
if (!argsok) {
Jim_SetResultString(interp, "wrong # args: should be \"", -1);
add_cmd_usage(interp, ct, argv[0]);
Jim_AppendStrings(interp, Jim_GetResult(interp), "\"", NULL);
return 0;
}
|
| ︙ | ︙ | |||
19893 19894 19895 19896 19897 19898 19899 |
if (ct->flags & JIM_MODFLAG_FULLARGV) {
ret = ct->function(interp, argc, argv);
}
else {
ret = ct->function(interp, argc - 2, argv + 2);
}
if (ret < 0) {
| | | 21549 21550 21551 21552 21553 21554 21555 21556 21557 21558 21559 21560 21561 21562 21563 |
if (ct->flags & JIM_MODFLAG_FULLARGV) {
ret = ct->function(interp, argc, argv);
}
else {
ret = ct->function(interp, argc - 2, argv + 2);
}
if (ret < 0) {
Jim_SubCmdArgError(interp, ct, argv[0]);
ret = JIM_ERR;
}
}
return ret;
}
int Jim_SubCmdProc(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
|
| ︙ | ︙ | |||
19944 19945 19946 19947 19948 19949 19950 19951 19952 19953 19954 19955 19956 19957 |
*p = 0x80 | (uc & 0x3f);
return 4;
}
}
#include <ctype.h>
#include <string.h>
#define JIM_INTEGER_SPACE 24
#define MAX_FLOAT_WIDTH 320
Jim_Obj *Jim_FormatString(Jim_Interp *interp, Jim_Obj *fmtObjPtr, int objc, Jim_Obj *const *objv)
{
| > | 21600 21601 21602 21603 21604 21605 21606 21607 21608 21609 21610 21611 21612 21613 21614 |
*p = 0x80 | (uc & 0x3f);
return 4;
}
}
#include <ctype.h>
#include <string.h>
#include <stdio.h>
#define JIM_INTEGER_SPACE 24
#define MAX_FLOAT_WIDTH 320
Jim_Obj *Jim_FormatString(Jim_Interp *interp, Jim_Obj *fmtObjPtr, int objc, Jim_Obj *const *objv)
{
|
| ︙ | ︙ | |||
20190 20191 20192 20193 20194 20195 20196 |
num_buffer_size = length + 1;
num_buffer = Jim_Realloc(num_buffer, num_buffer_size);
}
j = 0;
for (i = length; i > 0; ) {
i--;
| | | 21847 21848 21849 21850 21851 21852 21853 21854 21855 21856 21857 21858 21859 21860 21861 |
num_buffer_size = length + 1;
num_buffer = Jim_Realloc(num_buffer, num_buffer_size);
}
j = 0;
for (i = length; i > 0; ) {
i--;
if (w & ((unsigned jim_wide)1 << i)) {
num_buffer[j++] = '1';
}
else if (j || i == 0) {
num_buffer[j++] = '0';
}
}
num_buffer[j] = 0;
|
| ︙ | ︙ | |||
20426 20427 20428 20429 20430 20431 20432 |
int n = 0;
while (*seq++) {
n++;
}
return n;
}
| | | 22083 22084 22085 22086 22087 22088 22089 22090 22091 22092 22093 22094 22095 22096 22097 |
int n = 0;
while (*seq++) {
n++;
}
return n;
}
int jim_regcomp(regex_t *preg, const char *exp, int cflags)
{
int scan;
int longest;
unsigned len;
int flags;
#ifdef DEBUG
|
| ︙ | ︙ | |||
20841 20842 20843 20844 20845 20846 20847 |
if (*pattern == ']' || *pattern == '-') {
reg_addrange(preg, *pattern, *pattern);
pattern++;
}
| | > > > > > | 22498 22499 22500 22501 22502 22503 22504 22505 22506 22507 22508 22509 22510 22511 22512 22513 22514 22515 22516 22517 22518 22519 22520 22521 22522 22523 22524 22525 22526 22527 |
if (*pattern == ']' || *pattern == '-') {
reg_addrange(preg, *pattern, *pattern);
pattern++;
}
while (*pattern != ']') {
int start;
int end;
enum {
CC_ALPHA, CC_ALNUM, CC_SPACE, CC_BLANK, CC_UPPER, CC_LOWER,
CC_DIGIT, CC_XDIGIT, CC_CNTRL, CC_GRAPH, CC_PRINT, CC_PUNCT,
CC_NUM
};
int cc;
if (!*pattern) {
preg->err = REG_ERR_UNMATCHED_BRACKET;
return 0;
}
pattern += reg_utf8_tounicode_case(pattern, &start, nocase);
if (start == '\\') {
switch (*pattern) {
case 's':
pattern++;
|
| ︙ | ︙ | |||
20876 20877 20878 20879 20880 20881 20882 20883 20884 20885 20886 20887 20888 20889 20890 20891 20892 20893 20894 20895 20896 20897 20898 20899 20900 20901 20902 20903 20904 20905 20906 20907 20908 20909 20910 20911 20912 20913 20914 |
goto cc_switch;
}
pattern += reg_decode_escape(pattern, &start);
if (start == 0) {
preg->err = REG_ERR_NULL_CHAR;
return 0;
}
}
if (pattern[0] == '-' && pattern[1] && pattern[1] != ']') {
pattern += utf8_tounicode(pattern, &end);
pattern += reg_utf8_tounicode_case(pattern, &end, nocase);
if (end == '\\') {
pattern += reg_decode_escape(pattern, &end);
if (end == 0) {
preg->err = REG_ERR_NULL_CHAR;
return 0;
}
}
reg_addrange(preg, start, end);
continue;
}
if (start == '[' && pattern[0] == ':') {
static const char *character_class[] = {
":alpha:", ":alnum:", ":space:", ":blank:", ":upper:", ":lower:",
":digit:", ":xdigit:", ":cntrl:", ":graph:", ":print:", ":punct:",
};
for (cc = 0; cc < CC_NUM; cc++) {
n = strlen(character_class[cc]);
if (strncmp(pattern, character_class[cc], n) == 0) {
pattern += n + 1;
break;
}
}
if (cc != CC_NUM) {
cc_switch:
| > > > > > > > > > > > > | 22538 22539 22540 22541 22542 22543 22544 22545 22546 22547 22548 22549 22550 22551 22552 22553 22554 22555 22556 22557 22558 22559 22560 22561 22562 22563 22564 22565 22566 22567 22568 22569 22570 22571 22572 22573 22574 22575 22576 22577 22578 22579 22580 22581 22582 22583 22584 22585 22586 22587 22588 |
goto cc_switch;
}
pattern += reg_decode_escape(pattern, &start);
if (start == 0) {
preg->err = REG_ERR_NULL_CHAR;
return 0;
}
if (start == '\\' && *pattern == 0) {
preg->err = REG_ERR_INVALID_ESCAPE;
return 0;
}
}
if (pattern[0] == '-' && pattern[1] && pattern[1] != ']') {
pattern += utf8_tounicode(pattern, &end);
pattern += reg_utf8_tounicode_case(pattern, &end, nocase);
if (end == '\\') {
pattern += reg_decode_escape(pattern, &end);
if (end == 0) {
preg->err = REG_ERR_NULL_CHAR;
return 0;
}
if (end == '\\' && *pattern == 0) {
preg->err = REG_ERR_INVALID_ESCAPE;
return 0;
}
}
reg_addrange(preg, start, end);
continue;
}
if (start == '[' && pattern[0] == ':') {
static const char *character_class[] = {
":alpha:", ":alnum:", ":space:", ":blank:", ":upper:", ":lower:",
":digit:", ":xdigit:", ":cntrl:", ":graph:", ":print:", ":punct:",
};
for (cc = 0; cc < CC_NUM; cc++) {
n = strlen(character_class[cc]);
if (strncmp(pattern, character_class[cc], n) == 0) {
if (pattern[n] != ']') {
preg->err = REG_ERR_UNMATCHED_BRACKET;
return 0;
}
pattern += n + 1;
break;
}
}
if (cc != CC_NUM) {
cc_switch:
|
| ︙ | ︙ | |||
20991 20992 20993 20994 20995 20996 20997 |
case '{':
preg->err = REG_ERR_COUNT_FOLLOWS_NOTHING;
return 0;
case '\\':
ch = *preg->regparse++;
switch (ch) {
case '\0':
| | | 22665 22666 22667 22668 22669 22670 22671 22672 22673 22674 22675 22676 22677 22678 22679 |
case '{':
preg->err = REG_ERR_COUNT_FOLLOWS_NOTHING;
return 0;
case '\\':
ch = *preg->regparse++;
switch (ch) {
case '\0':
preg->err = REG_ERR_INVALID_ESCAPE;
return 0;
case 'A':
ret = regnode(preg, BOLX);
break;
case 'Z':
ret = regnode(preg, EOLX);
break;
|
| ︙ | ︙ | |||
21178 21179 21180 21181 21182 21183 21184 | } static int regtry(regex_t *preg, const char *string ); static int regmatch(regex_t *preg, int prog); static int regrepeat(regex_t *preg, int p, int max); | | | 22852 22853 22854 22855 22856 22857 22858 22859 22860 22861 22862 22863 22864 22865 22866 |
}
static int regtry(regex_t *preg, const char *string );
static int regmatch(regex_t *preg, int prog);
static int regrepeat(regex_t *preg, int p, int max);
int jim_regexec(regex_t *preg, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags)
{
const char *s;
int scan;
if (preg == NULL || preg->program == NULL || string == NULL) {
return REG_ERR_NULL_ARGUMENT;
|
| ︙ | ︙ | |||
21519 21520 21521 21522 21523 21524 21525 |
(isalnum(UCHAR(preg->reginput[-1])) || preg->reginput[-1] == '_'))
return(0);
break;
case WORDZ:
if (preg->reginput > preg->regbol) {
| | | 23193 23194 23195 23196 23197 23198 23199 23200 23201 23202 23203 23204 23205 23206 23207 |
(isalnum(UCHAR(preg->reginput[-1])) || preg->reginput[-1] == '_'))
return(0);
break;
case WORDZ:
if (preg->reginput > preg->regbol) {
if (reg_iseol(preg, c) || !(isalnum(UCHAR(c)) || c == '_')) {
c = preg->reginput[-1];
if (isalnum(UCHAR(c)) || c == '_') {
break;
}
}
}
|
| ︙ | ︙ | |||
21615 21616 21617 21618 21619 21620 21621 21622 21623 21624 21625 21626 21627 21628 |
int no = OP(preg, scan) - CLOSE;
if (no < preg->nmatch && preg->pmatch[no].rm_eo == -1) {
preg->pmatch[no].rm_eo = save - preg->start;
}
}
return(1);
}
return(0);
}
return REG_ERR_INTERNAL;
}
scan = next;
}
| > > | 23289 23290 23291 23292 23293 23294 23295 23296 23297 23298 23299 23300 23301 23302 23303 23304 |
int no = OP(preg, scan) - CLOSE;
if (no < preg->nmatch && preg->pmatch[no].rm_eo == -1) {
preg->pmatch[no].rm_eo = save - preg->start;
}
}
return(1);
}
preg->reginput = save;
return(0);
}
return REG_ERR_INTERNAL;
}
scan = next;
}
|
| ︙ | ︙ | |||
21638 21639 21640 21641 21642 21643 21644 |
int ch;
int n;
scan = preg->reginput;
opnd = OPERAND(p);
switch (OP(preg, p)) {
case ANY:
| < | | 23314 23315 23316 23317 23318 23319 23320 23321 23322 23323 23324 23325 23326 23327 23328 23329 23330 |
int ch;
int n;
scan = preg->reginput;
opnd = OPERAND(p);
switch (OP(preg, p)) {
case ANY:
while (!reg_iseol(preg, *scan) && count < max) {
count++;
scan += utf8_charlen(*scan);
}
break;
case EXACTLY:
while (count < max) {
n = reg_utf8_tounicode_case(scan, &ch, preg->cflags & REG_ICASE);
if (preg->program[opnd] != ch) {
break;
|
| ︙ | ︙ | |||
21722 21723 21724 21725 21726 21727 21728 | return s - p; } } return 2; } | | | > | | 23397 23398 23399 23400 23401 23402 23403 23404 23405 23406 23407 23408 23409 23410 23411 23412 23413 23414 23415 23416 23417 23418 23419 23420 23421 23422 23423 23424 23425 23426 23427 23428 23429 23430 23431 23432 23433 23434 23435 23436 23437 23438 23439 23440 23441 23442 23443 23444 23445 23446 23447 |
return s - p;
}
}
return 2;
}
size_t jim_regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)
{
static const char *error_strings[] = {
"success",
"no match",
"bad pattern",
"null argument",
"unknown error",
"too big",
"out of memory",
"too many ()",
"parentheses () not balanced",
"braces {} not balanced",
"invalid repetition count(s)",
"extra characters",
"*+ of empty atom",
"nested count",
"internal error",
"count follows nothing",
"invalid escape \\ sequence",
"corrupted program",
"contains null char",
"brackets [] not balanced",
};
const char *err;
if (errcode < 0 || errcode >= REG_ERR_NUM) {
err = "Bad error code";
}
else {
err = error_strings[errcode];
}
return snprintf(errbuf, errbuf_size, "%s", err);
}
void jim_regfree(regex_t *preg)
{
free(preg->program);
}
#endif
#include <string.h>
|
| ︙ | ︙ | |||
21854 21855 21856 21857 21858 21859 21860 |
case ERROR_PIPE_BUSY: return EAGAIN;
case ERROR_PIPE_NOT_CONNECTED: return EPIPE;
case ERROR_DIRECTORY: return ENOTDIR;
}
return EINVAL;
}
| > > > > > > > > | > > > > > > > > > > > > > > > > | | | > > | | 23530 23531 23532 23533 23534 23535 23536 23537 23538 23539 23540 23541 23542 23543 23544 23545 23546 23547 23548 23549 23550 23551 23552 23553 23554 23555 23556 23557 23558 23559 23560 23561 23562 23563 23564 23565 23566 23567 23568 23569 23570 23571 23572 23573 23574 23575 23576 23577 23578 23579 |
case ERROR_PIPE_BUSY: return EAGAIN;
case ERROR_PIPE_NOT_CONNECTED: return EPIPE;
case ERROR_DIRECTORY: return ENOTDIR;
}
return EINVAL;
}
long JimProcessPid(phandle_t pid)
{
if (pid == INVALID_HANDLE_VALUE) {
return -1;
}
return GetProcessId(pid);
}
phandle_t JimWaitPid(long pid, int *status, int nohang)
{
if (pid > 0) {
HANDLE h = OpenProcess(PROCESS_QUERY_INFORMATION | SYNCHRONIZE, FALSE, pid);
if (h) {
long pid = waitpid(h, status, nohang);
CloseHandle(h);
if (pid > 0) {
return h;
}
}
}
return JIM_BAD_PHANDLE;
}
long waitpid(phandle_t phandle, int *status, int nohang)
{
long pid;
DWORD ret = WaitForSingleObject(phandle, nohang ? 0 : INFINITE);
if (ret == WAIT_TIMEOUT || ret == WAIT_FAILED) {
return -1;
}
GetExitCodeProcess(phandle, &ret);
*status = ret;
pid = GetProcessId(phandle);
CloseHandle(phandle);
return pid;
}
int Jim_MakeTempFile(Jim_Interp *interp, const char *filename_template, int unlink_file)
{
char name[MAX_PATH];
HANDLE handle;
|
| ︙ | ︙ | |||
21885 21886 21887 21888 21889 21890 21891 |
NULL);
if (handle == INVALID_HANDLE_VALUE) {
goto error;
}
Jim_SetResultString(interp, name, -1);
| | | 23587 23588 23589 23590 23591 23592 23593 23594 23595 23596 23597 23598 23599 23600 23601 |
NULL);
if (handle == INVALID_HANDLE_VALUE) {
goto error;
}
Jim_SetResultString(interp, name, -1);
return _open_osfhandle((intptr_t)handle, _O_RDWR | _O_TEXT);
error:
Jim_SetResultErrno(interp, name);
DeleteFile(name);
return -1;
}
|
| ︙ | ︙ | |||
22123 22124 22125 22126 22127 22128 22129 22130 22131 22132 22133 22134 22135 22136 22137 22138 22139 22140 22141 22142 22143 22144 22145 22146 22147 22148 22149 22150 22151 |
}
snprintf(buf, sizeof(buf), "%d", sig);
return buf;
}
#ifndef JIM_BOOTSTRAP_LIB_ONLY
#include <errno.h>
#include <string.h>
#ifdef USE_LINENOISE
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#include "linenoise.h"
#else
#define MAX_LINE_LEN 512
#endif
#ifdef USE_LINENOISE
static void JimCompletionCallback(const char *prefix, linenoiseCompletions *comp, void *userdata);
static const char completion_callback_assoc_key[] = "interactive-completion";
#endif
char *Jim_HistoryGetline(Jim_Interp *interp, const char *prompt)
{
#ifdef USE_LINENOISE
| > > > > > > > > > > > | | > > > > > > | | | 23825 23826 23827 23828 23829 23830 23831 23832 23833 23834 23835 23836 23837 23838 23839 23840 23841 23842 23843 23844 23845 23846 23847 23848 23849 23850 23851 23852 23853 23854 23855 23856 23857 23858 23859 23860 23861 23862 23863 23864 23865 23866 23867 23868 23869 23870 23871 23872 23873 23874 23875 23876 23877 23878 23879 23880 23881 23882 23883 23884 23885 23886 23887 23888 23889 23890 23891 23892 23893 23894 23895 23896 23897 23898 23899 23900 23901 23902 |
}
snprintf(buf, sizeof(buf), "%d", sig);
return buf;
}
#ifndef JIM_BOOTSTRAP_LIB_ONLY
#include <errno.h>
#include <string.h>
#include <stdio.h>
#ifdef USE_LINENOISE
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#include "linenoise.h"
#else
#define MAX_LINE_LEN 512
#endif
#ifdef USE_LINENOISE
struct JimCompletionInfo {
Jim_Interp *interp;
Jim_Obj *completion_command;
Jim_Obj *hints_command;
};
static struct JimCompletionInfo *JimGetCompletionInfo(Jim_Interp *interp);
static void JimCompletionCallback(const char *prefix, linenoiseCompletions *comp, void *userdata);
static const char completion_callback_assoc_key[] = "interactive-completion";
static char *JimHintsCallback(const char *prefix, int *color, int *bold, void *userdata);
static void JimFreeHintsCallback(void *hint, void *userdata);
#endif
char *Jim_HistoryGetline(Jim_Interp *interp, const char *prompt)
{
#ifdef USE_LINENOISE
struct JimCompletionInfo *compinfo = JimGetCompletionInfo(interp);
char *result;
Jim_Obj *objPtr;
long mlmode = 0;
if (compinfo->completion_command) {
linenoiseSetCompletionCallback(JimCompletionCallback, compinfo);
}
if (compinfo->hints_command) {
linenoiseSetHintsCallback(JimHintsCallback, compinfo);
linenoiseSetFreeHintsCallback(JimFreeHintsCallback);
}
objPtr = Jim_GetVariableStr(interp, "history::multiline", JIM_NONE);
if (objPtr && Jim_GetLong(interp, objPtr, &mlmode) == JIM_NONE) {
linenoiseSetMultiLine(mlmode);
}
result = linenoise(prompt);
linenoiseSetCompletionCallback(NULL, NULL);
linenoiseSetHintsCallback(NULL, NULL);
linenoiseSetFreeHintsCallback(NULL);
return result;
#else
int len;
char *line = Jim_Alloc(MAX_LINE_LEN);
fputs(prompt, stdout);
fflush(stdout);
if (fgets(line, MAX_LINE_LEN, stdin) == NULL) {
Jim_Free(line);
return NULL;
}
len = strlen(line);
if (len && line[len - 1] == '\n') {
line[len - 1] = '\0';
}
return line;
|
| ︙ | ︙ | |||
22222 22223 22224 22225 22226 22227 22228 22229 |
char **history = linenoiseHistory(&len);
for (i = 0; i < len; i++) {
printf("%4d %s\n", i + 1, history[i]);
}
#endif
}
#ifdef USE_LINENOISE
| > > > > > | | > > > | < > | > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > | > > | | > > | | > | | > > > | | | > > > | > > | 23941 23942 23943 23944 23945 23946 23947 23948 23949 23950 23951 23952 23953 23954 23955 23956 23957 23958 23959 23960 23961 23962 23963 23964 23965 23966 23967 23968 23969 23970 23971 23972 23973 23974 23975 23976 23977 23978 23979 23980 23981 23982 23983 23984 23985 23986 23987 23988 23989 23990 23991 23992 23993 23994 23995 23996 23997 23998 23999 24000 24001 24002 24003 24004 24005 24006 24007 24008 24009 24010 24011 24012 24013 24014 24015 24016 24017 24018 24019 24020 24021 24022 24023 24024 24025 24026 24027 24028 24029 24030 24031 24032 24033 24034 24035 24036 24037 24038 24039 24040 24041 24042 24043 24044 24045 24046 24047 24048 24049 24050 24051 24052 24053 24054 24055 24056 24057 24058 24059 24060 24061 24062 24063 24064 24065 24066 24067 24068 24069 24070 24071 24072 24073 24074 24075 24076 24077 24078 24079 24080 24081 24082 24083 24084 24085 24086 24087 24088 24089 24090 24091 24092 24093 24094 24095 24096 24097 24098 24099 24100 24101 24102 24103 24104 24105 24106 24107 |
char **history = linenoiseHistory(&len);
for (i = 0; i < len; i++) {
printf("%4d %s\n", i + 1, history[i]);
}
#endif
}
void Jim_HistorySetMaxLen(int length)
{
#ifdef USE_LINENOISE
linenoiseHistorySetMaxLen(length);
#endif
}
int Jim_HistoryGetMaxLen(void)
{
#ifdef USE_LINENOISE
return linenoiseHistoryGetMaxLen();
#endif
return 0;
}
#ifdef USE_LINENOISE
static void JimCompletionCallback(const char *prefix, linenoiseCompletions *comp, void *userdata)
{
struct JimCompletionInfo *info = (struct JimCompletionInfo *)userdata;
Jim_Obj *objv[2];
int ret;
objv[0] = info->completion_command;
objv[1] = Jim_NewStringObj(info->interp, prefix, -1);
ret = Jim_EvalObjVector(info->interp, 2, objv);
if (ret == JIM_OK) {
int i;
Jim_Obj *listObj = Jim_GetResult(info->interp);
int len = Jim_ListLength(info->interp, listObj);
for (i = 0; i < len; i++) {
linenoiseAddCompletion(comp, Jim_String(Jim_ListGetIndex(info->interp, listObj, i)));
}
}
}
static char *JimHintsCallback(const char *prefix, int *color, int *bold, void *userdata)
{
struct JimCompletionInfo *info = (struct JimCompletionInfo *)userdata;
Jim_Obj *objv[2];
int ret;
char *result = NULL;
objv[0] = info->hints_command;
objv[1] = Jim_NewStringObj(info->interp, prefix, -1);
ret = Jim_EvalObjVector(info->interp, 2, objv);
if (ret == JIM_OK) {
Jim_Obj *listObj = Jim_GetResult(info->interp);
Jim_IncrRefCount(listObj);
int len = Jim_ListLength(info->interp, listObj);
if (len >= 1) {
long x;
result = Jim_StrDup(Jim_String(Jim_ListGetIndex(info->interp, listObj, 0)));
if (len >= 2 && Jim_GetLong(info->interp, Jim_ListGetIndex(info->interp, listObj, 1), &x) == JIM_OK) {
*color = x;
}
if (len >= 3 && Jim_GetLong(info->interp, Jim_ListGetIndex(info->interp, listObj, 2), &x) == JIM_OK) {
*bold = x;
}
}
Jim_DecrRefCount(info->interp, listObj);
}
return result;
}
static void JimFreeHintsCallback(void *hint, void *userdata)
{
Jim_Free(hint);
}
static void JimHistoryFreeCompletion(Jim_Interp *interp, void *data)
{
struct JimCompletionInfo *compinfo = data;
if (compinfo->completion_command) {
Jim_DecrRefCount(interp, compinfo->completion_command);
}
if (compinfo->hints_command) {
Jim_DecrRefCount(interp, compinfo->hints_command);
}
Jim_Free(compinfo);
}
static struct JimCompletionInfo *JimGetCompletionInfo(Jim_Interp *interp)
{
struct JimCompletionInfo *compinfo = Jim_GetAssocData(interp, completion_callback_assoc_key);
if (compinfo == NULL) {
compinfo = Jim_Alloc(sizeof(*compinfo));
compinfo->interp = interp;
compinfo->completion_command = NULL;
compinfo->hints_command = NULL;
Jim_SetAssocData(interp, completion_callback_assoc_key, JimHistoryFreeCompletion, compinfo);
}
return compinfo;
}
#endif
void Jim_HistorySetCompletion(Jim_Interp *interp, Jim_Obj *completionCommandObj)
{
#ifdef USE_LINENOISE
struct JimCompletionInfo *compinfo = JimGetCompletionInfo(interp);
if (completionCommandObj) {
Jim_IncrRefCount(completionCommandObj);
}
if (compinfo->completion_command) {
Jim_DecrRefCount(interp, compinfo->completion_command);
}
compinfo->completion_command = completionCommandObj;
#endif
}
void Jim_HistorySetHints(Jim_Interp *interp, Jim_Obj *hintsCommandObj)
{
#ifdef USE_LINENOISE
struct JimCompletionInfo *compinfo = JimGetCompletionInfo(interp);
if (hintsCommandObj) {
Jim_IncrRefCount(hintsCommandObj);
}
if (compinfo->hints_command) {
Jim_DecrRefCount(interp, compinfo->hints_command);
}
compinfo->hints_command = hintsCommandObj;
#endif
}
int Jim_InteractivePrompt(Jim_Interp *interp)
{
int retcode = JIM_OK;
char *history_file = NULL;
#ifdef USE_LINENOISE
const char *home;
home = getenv("HOME");
if (home && isatty(STDIN_FILENO)) {
int history_len = strlen(home) + sizeof("/.jim_history");
history_file = Jim_Alloc(history_len);
snprintf(history_file, history_len, "%s/.jim_history", home);
Jim_HistoryLoad(history_file);
}
Jim_HistorySetCompletion(interp, Jim_NewStringObj(interp, "tcl::autocomplete", -1));
Jim_HistorySetHints(interp, Jim_NewStringObj(interp, "tcl::stdhint", -1));
#endif
printf("Welcome to Jim version %d.%d\n",
JIM_VERSION / 100, JIM_VERSION % 100);
Jim_SetVariableStrWithStr(interp, JIM_INTERACTIVE, "1");
while (1) {
|
| ︙ | ︙ | |||
22342 22343 22344 22345 22346 22347 22348 |
goto out;
}
if (Jim_Length(scriptObjPtr) != 0) {
Jim_AppendString(interp, scriptObjPtr, "\n", 1);
}
Jim_AppendString(interp, scriptObjPtr, line, -1);
| | | 24140 24141 24142 24143 24144 24145 24146 24147 24148 24149 24150 24151 24152 24153 24154 |
goto out;
}
if (Jim_Length(scriptObjPtr) != 0) {
Jim_AppendString(interp, scriptObjPtr, "\n", 1);
}
Jim_AppendString(interp, scriptObjPtr, line, -1);
Jim_Free(line);
if (Jim_ScriptIsComplete(interp, scriptObjPtr, &state))
break;
snprintf(prompt, sizeof(prompt), "%c> ", state);
}
#ifdef USE_LINENOISE
if (strcmp(Jim_String(scriptObjPtr), "h") == 0) {
|
| ︙ | ︙ | |||
22372 22373 22374 22375 22376 22377 22378 |
break;
}
if (retcode == JIM_ERR) {
Jim_MakeErrorMessage(interp);
}
result = Jim_GetString(Jim_GetResult(interp), &reslen);
if (reslen) {
| > | > > | 24170 24171 24172 24173 24174 24175 24176 24177 24178 24179 24180 24181 24182 24183 24184 24185 24186 24187 |
break;
}
if (retcode == JIM_ERR) {
Jim_MakeErrorMessage(interp);
}
result = Jim_GetString(Jim_GetResult(interp), &reslen);
if (reslen) {
if (fwrite(result, reslen, 1, stdout) == 0) {
}
putchar('\n');
}
}
out:
Jim_Free(history_file);
return retcode;
}
|
| ︙ | ︙ | |||
22474 22475 22476 22477 22478 22479 22480 |
else {
if (argc > 2 && strcmp(argv[1], "-e") == 0) {
JimSetArgv(interp, argc - 3, argv + 3);
retcode = Jim_Eval(interp, argv[2]);
if (retcode != JIM_ERR) {
| > | > > > > | 24275 24276 24277 24278 24279 24280 24281 24282 24283 24284 24285 24286 24287 24288 24289 24290 24291 24292 24293 24294 |
else {
if (argc > 2 && strcmp(argv[1], "-e") == 0) {
JimSetArgv(interp, argc - 3, argv + 3);
retcode = Jim_Eval(interp, argv[2]);
if (retcode != JIM_ERR) {
int len;
const char *msg = Jim_GetString(Jim_GetResult(interp), &len);
if (fwrite(msg, len, 1, stdout) == 0) {
}
putchar('\n');
}
}
else {
Jim_SetVariableStr(interp, "argv0", Jim_NewStringObj(interp, argv[1], -1));
JimSetArgv(interp, argc - 2, argv + 2);
if (strcmp(argv[1], "-") == 0) {
retcode = Jim_Eval(interp, "eval [info source [stdin read] stdin 1]");
|
| ︙ | ︙ |
Changes to autosetup/pkg-config.tcl.
| ︙ | ︙ | |||
11 12 13 14 15 16 17 | # If the C compiler doesn't support '-print-sysroot', the path can be supplied # by the '--sysroot' option or by defining 'SYSROOT'. # # 'PKG_CONFIG' may be set to use an alternative to 'pkg-config'. use cc | | | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# If the C compiler doesn't support '-print-sysroot', the path can be supplied
# by the '--sysroot' option or by defining 'SYSROOT'.
#
# 'PKG_CONFIG' may be set to use an alternative to 'pkg-config'.
use cc
options {
sysroot:dir => "Override compiler sysroot for pkg-config search path"
}
# @pkg-config-init ?required?
#
# Initialises the 'pkg-config' system. Unless '$required' is set to 0,
# it is a fatal error if a usable 'pkg-config' is not found .
|
| ︙ | ︙ | |||
49 50 51 52 53 54 55 |
set found 1
if {[opt-str sysroot o]} {
define SYSROOT [file-normalize $o]
msg-result "Using specified sysroot [get-define SYSROOT]"
} elseif {[get-define build] ne [get-define host]} {
| | > > > > | 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
set found 1
if {[opt-str sysroot o]} {
define SYSROOT [file-normalize $o]
msg-result "Using specified sysroot [get-define SYSROOT]"
} elseif {[get-define build] ne [get-define host]} {
if {[catch {exec-with-stderr {*}[get-define CC] -print-sysroot} result errinfo] == 0} {
# Use the compiler sysroot, if there is one
define SYSROOT $result
msg-result "Found compiler sysroot $result"
} else {
configlog "[get-define CC] -print-sysroot: $result"
set msg "pkg-config: Cross compiling, but no compiler sysroot and no --sysroot supplied"
if {$required} {
user-error $msg
} else {
msg-result $msg
}
set found 0
}
}
if {[is-defined SYSROOT]} {
set sysroot [get-define SYSROOT]
# XXX: It's possible that these should be set only when invoking pkg-config
global env
set env(PKG_CONFIG_DIR) ""
# Supposedly setting PKG_CONFIG_LIBDIR means that PKG_CONFIG_PATH is ignored,
# but it doesn't seem to work that way in practice
set env(PKG_CONFIG_PATH) ""
# Do we need to try /usr/local as well or instead?
set env(PKG_CONFIG_LIBDIR) $sysroot/usr/lib/pkgconfig:$sysroot/usr/share/pkgconfig
set env(PKG_CONFIG_SYSROOT_DIR) $sysroot
}
}
define HAVE_PKG_CONFIG $found
return $found
|
| ︙ | ︙ | |||
104 105 106 107 108 109 110 |
msg-checking "Checking for $module $args..."
if {!$ok} {
msg-result "no pkg-config"
return 0
}
| > > | > > > > > > > > > > | | | | > > > > > > > > > > > > > > > > > | 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
msg-checking "Checking for $module $args..."
if {!$ok} {
msg-result "no pkg-config"
return 0
}
set pkgconfig [get-define PKG_CONFIG]
set ret [catch {exec $pkgconfig --modversion "$module $args"} version]
configlog "$pkgconfig --modversion $module $args: $version"
if {$ret} {
msg-result "not found"
return 0
}
# Sometimes --modversion succeeds but because of dependencies it isn't usable
# This seems to show up with --cflags
set ret [catch {exec $pkgconfig --cflags $module} cflags]
if {$ret} {
msg-result "unusable ($version - see config.log)"
configlog "$pkgconfig --cflags $module"
configlog $cflags
return 0
}
msg-result $version
set prefix [feature-define-name $module PKG_]
define HAVE_${prefix}
define ${prefix}_VERSION $version
define ${prefix}_CFLAGS $cflags
define ${prefix}_LIBS [exec $pkgconfig --libs-only-l $module]
define ${prefix}_LDFLAGS [exec $pkgconfig --libs-only-L $module]
return 1
}
# @pkg-config-get module setting
#
# Convenience access to the results of 'pkg-config'.
#
# For example, '[pkg-config-get pango CFLAGS]' returns
# the value of 'PKG_PANGO_CFLAGS', or '""' if not defined.
proc pkg-config-get {module name} {
set prefix [feature-define-name $module PKG_]
get-define ${prefix}_${name} ""
}
# @pkg-config-get-var module variable
#
# Return the value of the given variable from the given pkg-config module.
# The module must already have been successfully detected with pkg-config.
# e.g.
#
## if {[pkg-config harfbuzz >= 2.5]} {
## define harfbuzz_libdir [pkg-config-get-var harfbuzz libdir]
## }
#
# Returns the empty string if the variable isn't defined.
proc pkg-config-get-var {module variable} {
set pkgconfig [get-define PKG_CONFIG]
set prefix [feature-define-name $module HAVE_PKG_]
exec $pkgconfig $module --variable $variable
}
|
Changes to autosetup/system.tcl.
| ︙ | ︙ | |||
15 16 17 18 19 20 21 | ## sysconfdir ## sharedstatedir ## localstatedir ## infodir ## mandir ## includedir # | | | | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
## sysconfdir
## sharedstatedir
## localstatedir
## infodir
## mandir
## includedir
#
# If '--prefix' is not supplied, it defaults to '/usr/local' unless 'options-defaults { prefix ... }' is used *before*
# including the 'system' module.
if {[is-defined defaultprefix]} {
user-notice "Note: defaultprefix is deprecated. Use options-defaults to set default options"
options-defaults [list prefix [get-define defaultprefix]]
}
options {
host:host-alias => {a complete or partial cpu-vendor-opsys for the system where
the application will run (defaults to the same value as --build)}
build:build-alias => {a complete or partial cpu-vendor-opsys for the system
where the application will be built (defaults to the
result of running config.guess)}
prefix:dir=/usr/local => {the target directory for the build (default: '@default@')}
|
| ︙ | ︙ | |||
48 49 50 51 52 53 54 | sysconfdir: sharedstatedir: localstatedir: runstatedir: maintainer-mode=0 dependency-tracking=0 silent-rules=0 | < > > > > | 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
sysconfdir:
sharedstatedir:
localstatedir:
runstatedir:
maintainer-mode=0
dependency-tracking=0
silent-rules=0
program-prefix:
program-suffix:
program-transform-name:
}
# @check-feature name { script }
#
# defines feature '$name' to the return value of '$script',
# which should be 1 if found or 0 if not found.
#
# e.g. the following will define 'HAVE_CONST' to 0 or 1.
|
| ︙ | ︙ | |||
202 203 204 205 206 207 208 |
if {[llength $condstack] == 0} {
user-notice "$infile:$linenum: Error: @endif missing @if"
}
lpop condstack
}
}
continue
| > > > > > | > | < < < < | 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
if {[llength $condstack] == 0} {
user-notice "$infile:$linenum: Error: @endif missing @if"
}
lpop condstack
}
}
continue
}
# Only continue if the stack contains all "true"
if {"0" in $condstack} {
continue
}
if {[regexp {^@include\s+(.*)} $line -> filearg]} {
set incfile [string map $mapping $filearg]
if {[file exists $incfile]} {
lappend ::autosetup(deps) [file-normalize $incfile]
lappend result {*}[include-file $incfile $mapping]
} else {
user-error "$infile:$linenum: Include file $incfile is missing"
}
continue
}
if {[regexp {^@define\s+(\w+)\s+(.*)} $line -> var val]} {
define $var $val
continue
}
lappend result $line
}
return $result
}
|
| ︙ | ︙ |
Changes to autosetup/tmake.auto.
| ︙ | ︙ | |||
45 46 47 48 49 50 51 52 53 54 55 |
# Not configured, so don't process subdirs
AutoSubDirs off
# And don't process this file any further
ifconfig false
}
}
if {![file exists build.spec]} {
puts "Note: I don't see build.spec. Try running: tmake --genie"
}
}
| > > > > > > > > > > > > > > > > > > | 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# Not configured, so don't process subdirs
AutoSubDirs off
# And don't process this file any further
ifconfig false
}
}
set configure [readfile configure]
# XXX Do we need also need to support a system install of tmake?
if {[string first {#@TMAKEUPDATED@} $configure] < 0} {
if {[regsub {#@@INITCHECK@@#} $configure \
{test -z "$TMAKE" -a -x "$dir/tmake" \&\& exec "$dir/tmake" --force --configure "$@"; #@TMAKEUPDATED@} configure]} {
writefile configure $configure\n
exec chmod +x configure
puts "Updated configure to invoke local tmake."
if {![file exec autosetup/tmake]} {
puts "Warning: autosetup/tmake is missing."
puts " Install it with: tmake --install=autosetup"
}
} else {
puts "Warning: configure isn't created by a recent autosetup, not updating."
}
} else {
puts "I see configure for tmake already exists."
}
if {![file exists build.spec]} {
puts "Note: I don't see build.spec. Try running: tmake --genie"
}
}
|
Changes to autosetup/tmake.tcl.
1 2 3 4 5 6 7 8 9 10 11 12 13 | # Copyright (c) 2011 WorkWare Systems http://www.workware.net.au/ # All rights reserved # @synopsis: # # The 'tmake' module makes it easy to support the tmake build system. # # The following variables are set: # ## CONFIGURED - to indicate that the project is configured use system | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# Copyright (c) 2011 WorkWare Systems http://www.workware.net.au/
# All rights reserved
# @synopsis:
#
# The 'tmake' module makes it easy to support the tmake build system.
#
# The following variables are set:
#
## CONFIGURED - to indicate that the project is configured
use system
options {}
define CONFIGURED
# @make-tmake-settings outfile patterns ...
#
# Examines all defined variables which match the given patterns (defaults to '*')
# and writes a tmake-compatible .conf file defining those variables.
|
| ︙ | ︙ |
Changes to configure.
1 2 3 | #!/bin/sh dir="`dirname "$0"`/autosetup" WRAPPER="$0"; export WRAPPER; exec "`"$dir/autosetup-find-tclsh"`" "$dir/autosetup" "$@" | > | 1 2 3 4 | #!/bin/sh dir="`dirname "$0"`/autosetup" #@@INITCHECK@@# WRAPPER="$0"; export WRAPPER; exec "`"$dir/autosetup-find-tclsh"`" "$dir/autosetup" "$@" |