Fossil SCM

Upgrade autosetup from 0.6.9 to 0.7.1+. Seems to work but need to try it on more systems before merging.

stephan 2024-07-22 23:30 UTC trunk
Commit dacbf76c8a571525319a07410834a48b563de9f9892dcee75a29caf978b696f1
--- autosetup/README.autosetup
+++ autosetup/README.autosetup
@@ -1,11 +1,11 @@
1
-README.autosetup created by autosetup v0.6.9
1
+README.autosetup created by autosetup v0.7.1+
22
33
This is the autosetup directory for a local install of autosetup.
44
It contains autosetup, support files and loadable modules.
55
66
*.tcl files in this directory are optional modules which
77
can be loaded with the 'use' directive.
88
99
*.auto files in this directory are auto-loaded.
1010
11
-For more information, see http://msteveb.github.com/autosetup/
11
+For more information, see https://msteveb.github.io/autosetup/
1212
--- autosetup/README.autosetup
+++ autosetup/README.autosetup
@@ -1,11 +1,11 @@
1 README.autosetup created by autosetup v0.6.9
2
3 This is the autosetup directory for a local install of autosetup.
4 It contains autosetup, support files and loadable modules.
5
6 *.tcl files in this directory are optional modules which
7 can be loaded with the 'use' directive.
8
9 *.auto files in this directory are auto-loaded.
10
11 For more information, see http://msteveb.github.com/autosetup/
12
--- autosetup/README.autosetup
+++ autosetup/README.autosetup
@@ -1,11 +1,11 @@
1 README.autosetup created by autosetup v0.7.1+
2
3 This is the autosetup directory for a local install of autosetup.
4 It contains autosetup, support files and loadable modules.
5
6 *.tcl files in this directory are optional modules which
7 can be loaded with the 'use' directive.
8
9 *.auto files in this directory are auto-loaded.
10
11 For more information, see https://msteveb.github.io/autosetup/
12
+184 -109
--- autosetup/autosetup
+++ autosetup/autosetup
@@ -4,11 +4,11 @@
44
# vim:se syntax=tcl:
55
# \
66
dir=`dirname "$0"`; exec "`$dir/autosetup-find-tclsh`" "$0" "$@"
77
88
# Note that the version has a trailing + on unreleased versions
9
-set autosetup(version) 0.6.9
9
+set autosetup(version) 0.7.1+
1010
1111
# Can be set to 1 to debug early-init problems
1212
set autosetup(debug) [expr {"--debug" in $argv}]
1313
1414
##################################################################
@@ -91,17 +91,17 @@
9191
# We simply parse anything that looks like an option
9292
set autosetup(getopt) [getopt argv]
9393
9494
#"=Core Options:"
9595
options-add {
96
- help:=local => "display help and options. Optionally specify a module name, such as --help=system"
96
+ help:=all => "display help and options. Optional: module name, such as --help=system"
9797
licence license => "display the autosetup license"
98
- version => "display the version of autosetup"
98
+ version => "display the version of autosetup"
9999
ref:=text manual:=text
100100
reference:=text => "display the autosetup command reference. 'text', 'wiki', 'asciidoc' or 'markdown'"
101
- debug => "display debugging output as autosetup runs"
102
- install:=. => "install autosetup to the current or given directory"
101
+ debug => "display debugging output as autosetup runs"
102
+ install:=. => "install autosetup to the current or given directory"
103103
}
104104
if {$autosetup(installed)} {
105105
# hidden options so we can produce a nice error
106106
options-add {
107107
sysinstall:path
@@ -202,24 +202,21 @@
202202
}
203203
}
204204
205205
autosetup_add_dep $autosetup(autodef)
206206
207
- define CONFIGURE_OPTS ""
208
- foreach arg $autosetup(argv) {
209
- define-append CONFIGURE_OPTS [quote-if-needed $arg]
210
- }
211
- define AUTOREMAKE [file-normalize $autosetup(exe)]
212
- define-append AUTOREMAKE [get-define CONFIGURE_OPTS]
213
-
207
+ # Add $argv to CONFIGURE_OPTS
208
+ define-append-argv CONFIGURE_OPTS {*}$autosetup(argv)
209
+ # Set up AUTOREMAKE to reconfigure with the same args
210
+ define-append-argv AUTOREMAKE {*}$autosetup(exe) {*}$autosetup(argv)
214211
215212
# Log how we were invoked
216213
configlog "Invoked as: [getenv WRAPPER $::argv0] [quote-argv $autosetup(argv)]"
217214
configlog "Tclsh: [info nameofexecutable]"
218215
219
- # Note that auto.def is *not* loaded in the global scope
220
- source $autosetup(autodef)
216
+ # Load auto.def as module "auto.def"
217
+ autosetup_load_module auto.def source $autosetup(autodef)
221218
222219
# Could warn here if options {} was not specified
223220
224221
show-notices
225222
@@ -231,10 +228,12 @@
231228
}
232229
}
233230
234231
exit 0
235232
}
233
+
234
+# @section Option Handling
236235
237236
# @opt-bool ?-nodefault? option ...
238237
#
239238
# Check each of the named, boolean options and if any have been explicitly enabled
240239
# or disabled by the user, return 1 or 0 accordingly.
@@ -340,12 +339,12 @@
340339
}
341340
342341
if {![info exists result]} {
343342
# No user-specified value. Has options-defaults been set?
344343
foreach opt $names {
345
- if {[dict exists $::autosetup(options-defaults) $opt]} {
346
- set result [dict get $autosetup(options-defaults) $opt]
344
+ if {[dict exists $::autosetup(optdefault) $opt]} {
345
+ set result [dict get $autosetup(optdefault) $opt]
347346
}
348347
}
349348
}
350349
351350
if {[info exists result]} {
@@ -373,11 +372,11 @@
373372
}
374373
375374
# Parse the option definition in $opts and update
376375
# ::autosetup(setoptions) and ::autosetup(optionhelp) appropriately
377376
#
378
-proc options-add {opts {header ""}} {
377
+proc options-add {opts} {
379378
global autosetup
380379
381380
# First weed out comment lines
382381
set realopts {}
383382
foreach line [split $opts \n] {
@@ -389,12 +388,11 @@
389388
390389
for {set i 0} {$i < [llength $opts]} {incr i} {
391390
set opt [lindex $opts $i]
392391
if {[string match =* $opt]} {
393392
# This is a special heading
394
- lappend autosetup(optionhelp) $opt ""
395
- set header {}
393
+ lappend autosetup(optionhelp) [list $opt $autosetup(module)]
396394
continue
397395
}
398396
unset -nocomplain defaultvalue equal value
399397
400398
#puts "i=$i, opt=$opt"
@@ -451,12 +449,12 @@
451449
}
452450
} else {
453451
# String option.
454452
lappend autosetup(options) $name
455453
456
- if {$colon eq ":"} {
457
- # Was ":name=default" given?
454
+ if {$equal ne "="} {
455
+ # Was the option given as "name:value=default"?
458456
# If so, set $value to the display name and $defaultvalue to the default
459457
# (This is the preferred way to set a default value for a string option)
460458
if {[regexp {^([^=]+)=(.*)$} $value -> value defaultvalue]} {
461459
dict set autosetup(optdefault) $name $defaultvalue
462460
}
@@ -466,13 +464,13 @@
466464
if {[dict exists $autosetup(options-defaults) $name]} {
467465
# A default was specified with options-defaults, so use it
468466
set defaultvalue [dict get $autosetup(options-defaults) $name]
469467
dict set autosetup(optdefault) $name $defaultvalue
470468
} elseif {![info exists defaultvalue]} {
471
- # For backward compatibility, if ":name" was given, use name as both
472
- # the display text and the default value, but only if the user
473
- # specified the option without the value
469
+ # No default value was given by value=default or options-defaults
470
+ # so use the value as the default when the plain option with no
471
+ # value is given (.e.g. just --opt instead of --opt=value)
474472
set defaultvalue $value
475473
}
476474
477475
if {$equal eq "="} {
478476
# String option with optional value
@@ -507,39 +505,22 @@
507505
if {[lindex $opts $i+1] eq "=>"} {
508506
set desc [lindex $opts $i+2]
509507
if {[info exists defaultvalue]} {
510508
set desc [string map [list @default@ $defaultvalue] $desc]
511509
}
512
- #string match \n* $desc
513
- if {$header ne ""} {
514
- lappend autosetup(optionhelp) $header ""
515
- set header ""
516
- }
517510
# A multi-line description
518
- lappend autosetup(optionhelp) $opthelp $desc
511
+ lappend autosetup(optionhelp) [list $opthelp $autosetup(module) $desc]
519512
incr i 2
520513
}
521514
}
522515
}
523516
524517
# @module-options optionlist
525518
#
526
-# Like 'options', but used within a module.
519
+# Deprecated. Simply use 'options' from within a module.
527520
proc module-options {opts} {
528
- set header ""
529
- if {$::autosetup(showhelp) > 1 && [llength $opts]} {
530
- set header "Module Options:"
531
- }
532
- options-add $opts $header
533
-
534
- if {$::autosetup(showhelp)} {
535
- # Ensure that the module isn't executed on --help
536
- # We are running under eval or source, so use break
537
- # to prevent further execution
538
- #return -code break -level 2
539
- return -code break
540
- }
521
+ options $opts
541522
}
542523
543524
proc max {a b} {
544525
expr {$a > $b ? $a : $b}
545526
}
@@ -564,36 +545,53 @@
564545
if {$len} {
565546
puts ""
566547
}
567548
}
568549
569
-proc options-show {} {
550
+# Display options (from $autosetup(optionhelp)) for modules that match
551
+# glob pattern $what
552
+proc options-show {what} {
553
+ set local 0
570554
# Determine the max option width
571555
set max 0
572
- foreach {opt desc} $::autosetup(optionhelp) {
556
+ foreach help $::autosetup(optionhelp) {
557
+ lassign $help opt module desc
558
+ if {![string match $what $module]} {
559
+ continue
560
+ }
573561
if {[string match =* $opt] || [string match \n* $desc]} {
574562
continue
575563
}
576564
set max [max $max [string length $opt]]
577565
}
578
- set indent [string repeat " " [expr $max+4]]
566
+ set indent [string repeat " " [expr {$max+4}]]
579567
set cols [getenv COLUMNS 80]
580568
catch {
581569
lassign [exec stty size] rows cols
582570
}
583571
incr cols -1
584572
# Now output
585
- foreach {opt desc} $::autosetup(optionhelp) {
573
+ foreach help $::autosetup(optionhelp) {
574
+ lassign $help opt module desc
575
+ if {![string match $what $module]} {
576
+ continue
577
+ }
578
+ if {$local == 0 && $module eq "auto.def"} {
579
+ puts "Local Options:"
580
+ incr local
581
+ }
586582
if {[string match =* $opt]} {
583
+ # Output a special heading line"
587584
puts [string range $opt 1 end]
588585
continue
589586
}
590587
puts -nonewline " [format %-${max}s $opt]"
591588
if {[string match \n* $desc]} {
589
+ # Output a pre-formatted help description as-is
592590
puts $desc
593591
} else {
594
- options-wrap-desc [string trim $desc] $cols " " $indent [expr $max + 2]
592
+ options-wrap-desc [string trim $desc] $cols " " $indent [expr {$max+2}]
595593
}
596594
}
597595
}
598596
599597
# @options optionspec
@@ -608,16 +606,20 @@
608606
#
609607
# The default is 'name=0', meaning that the option is disabled by default.
610608
# If 'name=1' is used to make the option enabled by default, the description should reflect
611609
# that with text like "Disable support for ...".
612610
#
613
-# An argument option (one which takes a parameter) is of the form:
611
+# An argument option (one which takes a parameter) is of one of the following forms:
614612
#
615
-## name:[=]value => "Description of this option"
613
+## name:value => "Description of this option"
614
+## name:value=default => "Description of this option with a default value"
615
+## name:=value => "Description of this option with an optional value"
616616
#
617617
# If the 'name:value' form is used, the value must be provided with the option (as '--name=myvalue').
618
-# If the 'name:=value' form is used, the value is optional and the given value is used as the default
618
+# If the 'name:value=default' form is used, the option has the given default value even if not
619
+# specified by the user.
620
+# If the 'name:=value' form is used, the value is optional and the given value is used
619621
# if it is not provided.
620622
#
621623
# The description may contain '@default@', in which case it will be replaced with the default
622624
# value for the option (taking into account defaults specified with 'options-defaults'.
623625
#
@@ -627,23 +629,26 @@
627629
# For example, '--disable-lfs' is an alias for '--disable=largefile':
628630
#
629631
## lfs=1 largefile=1 => "Disable large file support"
630632
#
631633
proc options {optlist} {
632
- # Allow options as a list or args
633
- options-add $optlist "Local Options:"
634
+ global autosetup
634635
635
- if {$::autosetup(showhelp)} {
636
- options-show
637
- exit 0
636
+ options-add $optlist
637
+
638
+ if {$autosetup(showhelp)} {
639
+ # If --help, stop now to show help
640
+ return -code break
638641
}
639642
640
- # Check for invalid options
641
- if {[opt-bool option-checking]} {
642
- foreach o [dict keys $::autosetup(getopt)] {
643
- if {$o ni $::autosetup(options)} {
644
- user-error "Unknown option --$o"
643
+ if {$autosetup(module) eq "auto.def"} {
644
+ # Check for invalid options
645
+ if {[opt-bool option-checking]} {
646
+ foreach o [dict keys $::autosetup(getopt)] {
647
+ if {$o ni $::autosetup(options)} {
648
+ user-error "Unknown option --$o"
649
+ }
645650
}
646651
}
647652
}
648653
}
649654
@@ -677,10 +682,12 @@
677682
}
678683
}
679684
return $alias
680685
}
681686
687
+# @section Variable Definitions (defines)
688
+
682689
# @define name ?value=1?
683690
#
684691
# Defines the named variable to the given value.
685692
# These (name, value) pairs represent the results of the configuration check
686693
# and are available to be subsequently checked, modified and substituted.
@@ -687,10 +694,33 @@
687694
#
688695
proc define {name {value 1}} {
689696
set ::define($name) $value
690697
#dputs "$name <= $value"
691698
}
699
+
700
+# @define-push {name ...} script
701
+#
702
+# Save the values of the given defines, evaluation the script, then restore.
703
+# For example, to avoid updating AS_FLAGS and AS_CXXFLAGS:
704
+## define-push {AS_CFLAGS AS_CXXFLAGS} {
705
+## cc-check-flags -Wno-error
706
+## }
707
+proc define-push {names script} {
708
+ array set unset {}
709
+ foreach name $names {
710
+ if {[is-defined $name]} {
711
+ set save($name) [get-define $name]
712
+ } else {
713
+ set unset($name) 1
714
+ }
715
+ }
716
+ uplevel 1 $script
717
+ array set ::define [array get save]
718
+ foreach name [array names unset] {
719
+ unset -nocomplain ::define($name)
720
+ }
721
+}
692722
693723
# @undefine name
694724
#
695725
# Undefine the named variable.
696726
#
@@ -703,34 +733,48 @@
703733
#
704734
# Appends the given value(s) to the given "defined" variable.
705735
# If the variable is not defined or empty, it is set to '$value'.
706736
# Otherwise the value is appended, separated by a space.
707737
# Any extra values are similarly appended.
708
-# If any value is already contained in the variable (as a substring) it is omitted.
738
+#
739
+# Note that define-append is not designed to add values containing spaces.
740
+# If values may contain spaces, consider define-append-argv instead.
709741
#
710742
proc define-append {name args} {
711743
if {[get-define $name ""] ne ""} {
712
- # Avoid duplicates
713744
foreach arg $args {
714745
if {$arg eq ""} {
715746
continue
716747
}
717
- set found 0
718
- foreach str [split $::define($name) " "] {
719
- if {$str eq $arg} {
720
- incr found
721
- }
722
- }
723
- if {!$found} {
724
- append ::define($name) " " $arg
725
- }
748
+ append ::define($name) " " $arg
726749
}
727750
} else {
728751
set ::define($name) [join $args]
729752
}
730753
#dputs "$name += [join $args] => $::define($name)"
731754
}
755
+
756
+# @define-append-argv name value ...
757
+#
758
+# Similar to define-append except designed to construct shell command
759
+# lines, including correct handling of parameters with spaces.
760
+#
761
+# Each non-empty value is quoted if necessary and then appended to the given variable
762
+# if it does not already exist.
763
+#
764
+proc define-append-argv {name args} {
765
+ set seen {}
766
+ set new {}
767
+ foreach val [list {*}[get-define $name ""] {*}$args] {
768
+ if {$val ne {} && ![dict exists $seen $val]} {
769
+ lappend new [quote-if-needed $val]
770
+ dict set seen $val 1
771
+ }
772
+ }
773
+ set ::define($name) [join $new " "]
774
+ #dputs "$name += [join $args] => $::define($name)"
775
+}
732776
733777
# @get-define name ?default=0?
734778
#
735779
# Returns the current value of the "defined" variable, or '$default'
736780
# if not set.
@@ -773,10 +817,11 @@
773817
#
774818
proc all-defines {} {
775819
array get ::define
776820
}
777821
822
+# @section Environment/Helpers
778823
779824
# @get-env name default
780825
#
781826
# If '$name' was specified on the command line, return it.
782827
# Otherwise if '$name' was set in the environment, return it.
@@ -855,10 +900,12 @@
855900
lappend result $p
856901
}
857902
}
858903
return $result
859904
}
905
+
906
+# @section Paths, Searching
860907
861908
# @find-executable-path name
862909
#
863910
# Searches the path for an executable with the given name.
864911
# Note that the name may include some parameters, e.g. 'cc -mbig-endian',
@@ -924,10 +971,12 @@
924971
user-error "failed to find one of: [join $args]"
925972
}
926973
}
927974
return ""
928975
}
976
+
977
+# @section Logging, Messages and Errors
929978
930979
# @configlog msg
931980
#
932981
# Writes the given message to the configuration log, 'config.log'.
933982
#
@@ -1141,10 +1190,12 @@
11411190
# The name will be normalised (converted to a full path)
11421191
#
11431192
proc autosetup_add_dep {filename} {
11441193
lappend ::autosetup(deps) [file-normalize $filename]
11451194
}
1195
+
1196
+# @section Modules Support
11461197
11471198
##################################################################
11481199
#
11491200
# Library module support
11501201
#
@@ -1171,12 +1222,13 @@
11711222
foreach m $args {
11721223
if {[info exists libmodule($m)]} {
11731224
continue
11741225
}
11751226
set libmodule($m) 1
1227
+
11761228
if {[info exists modsource(${m}.tcl)]} {
1177
- automf_load eval $modsource(${m}.tcl)
1229
+ autosetup_load_module $m eval $modsource(${m}.tcl)
11781230
} else {
11791231
set locs [list ${m}.tcl ${m}/init.tcl]
11801232
set found 0
11811233
foreach dir $dirs {
11821234
foreach loc $locs {
@@ -1192,11 +1244,11 @@
11921244
}
11931245
if {$found} {
11941246
# For the convenience of the "use" source, point to the directory
11951247
# it is being loaded from
11961248
set ::usedir [file dirname $source]
1197
- automf_load source $source
1249
+ autosetup_load_module $m source $source
11981250
autosetup_add_dep $source
11991251
} else {
12001252
autosetup-error "use: No such module: $m"
12011253
}
12021254
}
@@ -1205,23 +1257,28 @@
12051257
12061258
proc autosetup_load_auto_modules {} {
12071259
global autosetup modsource
12081260
# First load any embedded auto modules
12091261
foreach mod [array names modsource *.auto] {
1210
- automf_load eval $modsource($mod)
1262
+ autosetup_load_module $mod eval $modsource($mod)
12111263
}
12121264
# Now any external auto modules
12131265
foreach file [glob -nocomplain $autosetup(libdir)/*.auto $autosetup(libdir)/*/*.auto] {
1214
- automf_load source $file
1266
+ autosetup_load_module [file tail $file] source $file
12151267
}
12161268
}
12171269
12181270
# Load module source in the global scope by executing the given command
1219
-proc automf_load {args} {
1271
+proc autosetup_load_module {module args} {
1272
+ global autosetup
1273
+ set prev $autosetup(module)
1274
+ set autosetup(module) $module
1275
+
12201276
if {[catch [list uplevel #0 $args] msg opts] ni {0 2 3}} {
12211277
autosetup-full-error [error-dump $msg $opts $::autosetup(debug)]
12221278
}
1279
+ set autosetup(module) $prev
12231280
}
12241281
12251282
# Initial settings
12261283
set autosetup(exe) $::argv0
12271284
set autosetup(istcl) 1
@@ -1229,10 +1286,11 @@
12291286
set autosetup(installed) 0
12301287
set autosetup(sysinstall) 0
12311288
set autosetup(msg-checking) 0
12321289
set autosetup(msg-quiet) 0
12331290
set autosetup(inittypes) {}
1291
+set autosetup(module) autosetup
12341292
12351293
# Embedded modules are inserted below here
12361294
set autosetup(installed) 1
12371295
set autosetup(sysinstall) 0
12381296
# ----- @module asciidoc-formatting.tcl -----
@@ -1432,28 +1490,28 @@
14321490
proc autosetup_help {what} {
14331491
use_pager
14341492
14351493
puts "Usage: [file tail $::autosetup(exe)] \[options\] \[settings\]\n"
14361494
puts "This is [autosetup_version], a build environment \"autoconfigurator\""
1437
- puts "See the documentation online at http://msteveb.github.com/autosetup/\n"
1438
-
1439
- if {$what eq "local"} {
1440
- if {[file exists $::autosetup(autodef)]} {
1441
- # This relies on auto.def having a call to 'options'
1442
- # which will display options and quit
1443
- source $::autosetup(autodef)
1444
- } else {
1445
- options-show
1446
- }
1447
- } else {
1448
- incr ::autosetup(showhelp)
1449
- if {[catch {use $what}]} {
1450
- user-error "Unknown module: $what"
1451
- } else {
1452
- options-show
1453
- }
1454
- }
1495
+ puts "See the documentation online at https://msteveb.github.io/autosetup/\n"
1496
+
1497
+ if {$what in {all local}} {
1498
+ # Need to load auto.def now
1499
+ if {[file exists $::autosetup(autodef)]} {
1500
+ # Load auto.def as module "auto.def"
1501
+ autosetup_load_module auto.def source $::autosetup(autodef)
1502
+ }
1503
+ if {$what eq "all"} {
1504
+ set what *
1505
+ } else {
1506
+ set what auto.def
1507
+ }
1508
+ } else {
1509
+ use $what
1510
+ puts "Options for module $what:"
1511
+ }
1512
+ options-show $what
14551513
exit 0
14561514
}
14571515
14581516
proc autosetup_show_license {} {
14591517
global modsource autosetup
@@ -1505,11 +1563,12 @@
15051563
title "[autosetup_version] -- Command Reference"
15061564
15071565
section {Introduction}
15081566
15091567
p {
1510
- See http://msteveb.github.com/autosetup/ for the online documentation for 'autosetup'
1568
+ See https://msteveb.github.io/autosetup/ for the online documentation for 'autosetup'.
1569
+ This documentation can also be accessed locally with `autosetup --ref`.
15111570
}
15121571
15131572
p {
15141573
'autosetup' provides a number of built-in commands which
15151574
are documented below. These may be used from 'auto.def' to test
@@ -1568,10 +1627,15 @@
15681627
set modulename [file rootname [file tail $file]]
15691628
set current _core_
15701629
set f [open $file]
15711630
while {![eof $f]} {
15721631
set line [gets $f]
1632
+
1633
+ if {[regexp {^#.*@section (.*)$} $line -> section]} {
1634
+ lappend doc($current) [list section $section]
1635
+ continue
1636
+ }
15731637
15741638
# Find embedded module names
15751639
if {[regexp {^#.*@module ([^ ]*)} $line -> modulename]} {
15761640
continue
15771641
}
@@ -1583,11 +1647,11 @@
15831647
15841648
# Synopsis or command?
15851649
if {$cmd eq "synopsis:"} {
15861650
set current $modulename
15871651
lappend doc($current) [list section "Module: $modulename"]
1588
- } else {
1652
+ } else {
15891653
lappend doc($current) [list subsection $cmd]
15901654
}
15911655
15921656
set lines {}
15931657
set type p
@@ -1863,10 +1927,11 @@
18631927
}
18641928
} else {
18651929
writefile configure \
18661930
{#!/bin/sh
18671931
dir="`dirname "$0"`/autosetup"
1932
+#@@INITCHECK@@#
18681933
WRAPPER="$0"; export WRAPPER; exec "`"$dir/autosetup-find-tclsh"`" "$dir/autosetup" "$@"
18691934
}
18701935
}
18711936
catch {exec chmod 755 configure}
18721937
}
@@ -1909,11 +1974,11 @@
19091974
*.tcl files in this directory are optional modules which
19101975
can be loaded with the 'use' directive.
19111976
19121977
*.auto files in this directory are auto-loaded.
19131978
1914
-For more information, see http://msteveb.github.com/autosetup/
1979
+For more information, see https://msteveb.github.io/autosetup/
19151980
}
19161981
dputs "install: autosetup/README.autosetup"
19171982
writefile $target $readme
19181983
}
19191984
}
@@ -2043,10 +2108,23 @@
20432108
return -code error "environment variable \"$name\" does not exist"
20442109
}
20452110
proc isatty? {channel} {
20462111
dict exists [fconfigure $channel] -xchar
20472112
}
2113
+ # Jim-compatible stacktrace using info frame
2114
+ proc stacktrace {} {
2115
+ set stacktrace {}
2116
+ # 2 to skip the current frame
2117
+ for {set i 2} {$i < [info frame]} {incr i} {
2118
+ set frame [info frame -$i]
2119
+ if {[dict exists $frame file]} {
2120
+ # We don't need proc, so use ""
2121
+ lappend stacktrace "" [dict get $frame file] [dict get $frame line]
2122
+ }
2123
+ }
2124
+ return $stacktrace
2125
+ }
20482126
} else {
20492127
if {$autosetup(iswin)} {
20502128
# On Windows, backslash convert all environment variables
20512129
# (Assume that Tcl does this for us)
20522130
proc getenv {name args} {
@@ -2096,20 +2174,15 @@
20962174
proc error-location {msg} {
20972175
if {$::autosetup(debug)} {
20982176
return -code error $msg
20992177
}
21002178
# Search back through the stack trace for the first error in a .def file
2101
- for {set i 1} {$i < [info level]} {incr i} {
2102
- if {$::autosetup(istcl)} {
2103
- array set info [info frame -$i]
2104
- } else {
2105
- lassign [info frame -$i] info(caller) info(file) info(line)
2106
- }
2107
- if {[string match *.def $info(file)]} {
2108
- return "[relative-path $info(file)]:$info(line): Error: $msg"
2109
- }
2110
- #puts "Skipping $info(file):$info(line)"
2179
+ foreach {p f l} [stacktrace] {
2180
+ if {[string match *.def $f]} {
2181
+ return "[relative-path $f]:$l: Error: $msg"
2182
+ }
2183
+ #puts "Skipping $f:$l"
21112184
}
21122185
return $msg
21132186
}
21142187
21152188
# If everything is working properly, the only errors which occur
@@ -2298,10 +2371,12 @@
22982371
set modsource(util.tcl) {
22992372
# Copyright (c) 2012 WorkWare Systems http://www.workware.net.au/
23002373
# All rights reserved
23012374
23022375
# Module which contains miscellaneous utility functions
2376
+
2377
+# @section Utilities
23032378
23042379
# @compare-versions version1 version2
23052380
#
23062381
# Versions are of the form 'a.b.c' (may be any number of numeric components)
23072382
#
23082383
--- autosetup/autosetup
+++ autosetup/autosetup
@@ -4,11 +4,11 @@
4 # vim:se syntax=tcl:
5 # \
6 dir=`dirname "$0"`; exec "`$dir/autosetup-find-tclsh`" "$0" "$@"
7
8 # Note that the version has a trailing + on unreleased versions
9 set autosetup(version) 0.6.9
10
11 # Can be set to 1 to debug early-init problems
12 set autosetup(debug) [expr {"--debug" in $argv}]
13
14 ##################################################################
@@ -91,17 +91,17 @@
91 # We simply parse anything that looks like an option
92 set autosetup(getopt) [getopt argv]
93
94 #"=Core Options:"
95 options-add {
96 help:=local => "display help and options. Optionally specify a module name, such as --help=system"
97 licence license => "display the autosetup license"
98 version => "display the version of autosetup"
99 ref:=text manual:=text
100 reference:=text => "display the autosetup command reference. 'text', 'wiki', 'asciidoc' or 'markdown'"
101 debug => "display debugging output as autosetup runs"
102 install:=. => "install autosetup to the current or given directory"
103 }
104 if {$autosetup(installed)} {
105 # hidden options so we can produce a nice error
106 options-add {
107 sysinstall:path
@@ -202,24 +202,21 @@
202 }
203 }
204
205 autosetup_add_dep $autosetup(autodef)
206
207 define CONFIGURE_OPTS ""
208 foreach arg $autosetup(argv) {
209 define-append CONFIGURE_OPTS [quote-if-needed $arg]
210 }
211 define AUTOREMAKE [file-normalize $autosetup(exe)]
212 define-append AUTOREMAKE [get-define CONFIGURE_OPTS]
213
214
215 # Log how we were invoked
216 configlog "Invoked as: [getenv WRAPPER $::argv0] [quote-argv $autosetup(argv)]"
217 configlog "Tclsh: [info nameofexecutable]"
218
219 # Note that auto.def is *not* loaded in the global scope
220 source $autosetup(autodef)
221
222 # Could warn here if options {} was not specified
223
224 show-notices
225
@@ -231,10 +228,12 @@
231 }
232 }
233
234 exit 0
235 }
 
 
236
237 # @opt-bool ?-nodefault? option ...
238 #
239 # Check each of the named, boolean options and if any have been explicitly enabled
240 # or disabled by the user, return 1 or 0 accordingly.
@@ -340,12 +339,12 @@
340 }
341
342 if {![info exists result]} {
343 # No user-specified value. Has options-defaults been set?
344 foreach opt $names {
345 if {[dict exists $::autosetup(options-defaults) $opt]} {
346 set result [dict get $autosetup(options-defaults) $opt]
347 }
348 }
349 }
350
351 if {[info exists result]} {
@@ -373,11 +372,11 @@
373 }
374
375 # Parse the option definition in $opts and update
376 # ::autosetup(setoptions) and ::autosetup(optionhelp) appropriately
377 #
378 proc options-add {opts {header ""}} {
379 global autosetup
380
381 # First weed out comment lines
382 set realopts {}
383 foreach line [split $opts \n] {
@@ -389,12 +388,11 @@
389
390 for {set i 0} {$i < [llength $opts]} {incr i} {
391 set opt [lindex $opts $i]
392 if {[string match =* $opt]} {
393 # This is a special heading
394 lappend autosetup(optionhelp) $opt ""
395 set header {}
396 continue
397 }
398 unset -nocomplain defaultvalue equal value
399
400 #puts "i=$i, opt=$opt"
@@ -451,12 +449,12 @@
451 }
452 } else {
453 # String option.
454 lappend autosetup(options) $name
455
456 if {$colon eq ":"} {
457 # Was ":name=default" given?
458 # If so, set $value to the display name and $defaultvalue to the default
459 # (This is the preferred way to set a default value for a string option)
460 if {[regexp {^([^=]+)=(.*)$} $value -> value defaultvalue]} {
461 dict set autosetup(optdefault) $name $defaultvalue
462 }
@@ -466,13 +464,13 @@
466 if {[dict exists $autosetup(options-defaults) $name]} {
467 # A default was specified with options-defaults, so use it
468 set defaultvalue [dict get $autosetup(options-defaults) $name]
469 dict set autosetup(optdefault) $name $defaultvalue
470 } elseif {![info exists defaultvalue]} {
471 # For backward compatibility, if ":name" was given, use name as both
472 # the display text and the default value, but only if the user
473 # specified the option without the value
474 set defaultvalue $value
475 }
476
477 if {$equal eq "="} {
478 # String option with optional value
@@ -507,39 +505,22 @@
507 if {[lindex $opts $i+1] eq "=>"} {
508 set desc [lindex $opts $i+2]
509 if {[info exists defaultvalue]} {
510 set desc [string map [list @default@ $defaultvalue] $desc]
511 }
512 #string match \n* $desc
513 if {$header ne ""} {
514 lappend autosetup(optionhelp) $header ""
515 set header ""
516 }
517 # A multi-line description
518 lappend autosetup(optionhelp) $opthelp $desc
519 incr i 2
520 }
521 }
522 }
523
524 # @module-options optionlist
525 #
526 # Like 'options', but used within a module.
527 proc module-options {opts} {
528 set header ""
529 if {$::autosetup(showhelp) > 1 && [llength $opts]} {
530 set header "Module Options:"
531 }
532 options-add $opts $header
533
534 if {$::autosetup(showhelp)} {
535 # Ensure that the module isn't executed on --help
536 # We are running under eval or source, so use break
537 # to prevent further execution
538 #return -code break -level 2
539 return -code break
540 }
541 }
542
543 proc max {a b} {
544 expr {$a > $b ? $a : $b}
545 }
@@ -564,36 +545,53 @@
564 if {$len} {
565 puts ""
566 }
567 }
568
569 proc options-show {} {
 
 
 
570 # Determine the max option width
571 set max 0
572 foreach {opt desc} $::autosetup(optionhelp) {
 
 
 
 
573 if {[string match =* $opt] || [string match \n* $desc]} {
574 continue
575 }
576 set max [max $max [string length $opt]]
577 }
578 set indent [string repeat " " [expr $max+4]]
579 set cols [getenv COLUMNS 80]
580 catch {
581 lassign [exec stty size] rows cols
582 }
583 incr cols -1
584 # Now output
585 foreach {opt desc} $::autosetup(optionhelp) {
 
 
 
 
 
 
 
 
586 if {[string match =* $opt]} {
 
587 puts [string range $opt 1 end]
588 continue
589 }
590 puts -nonewline " [format %-${max}s $opt]"
591 if {[string match \n* $desc]} {
 
592 puts $desc
593 } else {
594 options-wrap-desc [string trim $desc] $cols " " $indent [expr $max + 2]
595 }
596 }
597 }
598
599 # @options optionspec
@@ -608,16 +606,20 @@
608 #
609 # The default is 'name=0', meaning that the option is disabled by default.
610 # If 'name=1' is used to make the option enabled by default, the description should reflect
611 # that with text like "Disable support for ...".
612 #
613 # An argument option (one which takes a parameter) is of the form:
614 #
615 ## name:[=]value => "Description of this option"
 
 
616 #
617 # If the 'name:value' form is used, the value must be provided with the option (as '--name=myvalue').
618 # If the 'name:=value' form is used, the value is optional and the given value is used as the default
 
 
619 # if it is not provided.
620 #
621 # The description may contain '@default@', in which case it will be replaced with the default
622 # value for the option (taking into account defaults specified with 'options-defaults'.
623 #
@@ -627,23 +629,26 @@
627 # For example, '--disable-lfs' is an alias for '--disable=largefile':
628 #
629 ## lfs=1 largefile=1 => "Disable large file support"
630 #
631 proc options {optlist} {
632 # Allow options as a list or args
633 options-add $optlist "Local Options:"
634
635 if {$::autosetup(showhelp)} {
636 options-show
637 exit 0
 
 
638 }
639
640 # Check for invalid options
641 if {[opt-bool option-checking]} {
642 foreach o [dict keys $::autosetup(getopt)] {
643 if {$o ni $::autosetup(options)} {
644 user-error "Unknown option --$o"
 
 
645 }
646 }
647 }
648 }
649
@@ -677,10 +682,12 @@
677 }
678 }
679 return $alias
680 }
681
 
 
682 # @define name ?value=1?
683 #
684 # Defines the named variable to the given value.
685 # These (name, value) pairs represent the results of the configuration check
686 # and are available to be subsequently checked, modified and substituted.
@@ -687,10 +694,33 @@
687 #
688 proc define {name {value 1}} {
689 set ::define($name) $value
690 #dputs "$name <= $value"
691 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
692
693 # @undefine name
694 #
695 # Undefine the named variable.
696 #
@@ -703,34 +733,48 @@
703 #
704 # Appends the given value(s) to the given "defined" variable.
705 # If the variable is not defined or empty, it is set to '$value'.
706 # Otherwise the value is appended, separated by a space.
707 # Any extra values are similarly appended.
708 # If any value is already contained in the variable (as a substring) it is omitted.
 
 
709 #
710 proc define-append {name args} {
711 if {[get-define $name ""] ne ""} {
712 # Avoid duplicates
713 foreach arg $args {
714 if {$arg eq ""} {
715 continue
716 }
717 set found 0
718 foreach str [split $::define($name) " "] {
719 if {$str eq $arg} {
720 incr found
721 }
722 }
723 if {!$found} {
724 append ::define($name) " " $arg
725 }
726 }
727 } else {
728 set ::define($name) [join $args]
729 }
730 #dputs "$name += [join $args] => $::define($name)"
731 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
732
733 # @get-define name ?default=0?
734 #
735 # Returns the current value of the "defined" variable, or '$default'
736 # if not set.
@@ -773,10 +817,11 @@
773 #
774 proc all-defines {} {
775 array get ::define
776 }
777
 
778
779 # @get-env name default
780 #
781 # If '$name' was specified on the command line, return it.
782 # Otherwise if '$name' was set in the environment, return it.
@@ -855,10 +900,12 @@
855 lappend result $p
856 }
857 }
858 return $result
859 }
 
 
860
861 # @find-executable-path name
862 #
863 # Searches the path for an executable with the given name.
864 # Note that the name may include some parameters, e.g. 'cc -mbig-endian',
@@ -924,10 +971,12 @@
924 user-error "failed to find one of: [join $args]"
925 }
926 }
927 return ""
928 }
 
 
929
930 # @configlog msg
931 #
932 # Writes the given message to the configuration log, 'config.log'.
933 #
@@ -1141,10 +1190,12 @@
1141 # The name will be normalised (converted to a full path)
1142 #
1143 proc autosetup_add_dep {filename} {
1144 lappend ::autosetup(deps) [file-normalize $filename]
1145 }
 
 
1146
1147 ##################################################################
1148 #
1149 # Library module support
1150 #
@@ -1171,12 +1222,13 @@
1171 foreach m $args {
1172 if {[info exists libmodule($m)]} {
1173 continue
1174 }
1175 set libmodule($m) 1
 
1176 if {[info exists modsource(${m}.tcl)]} {
1177 automf_load eval $modsource(${m}.tcl)
1178 } else {
1179 set locs [list ${m}.tcl ${m}/init.tcl]
1180 set found 0
1181 foreach dir $dirs {
1182 foreach loc $locs {
@@ -1192,11 +1244,11 @@
1192 }
1193 if {$found} {
1194 # For the convenience of the "use" source, point to the directory
1195 # it is being loaded from
1196 set ::usedir [file dirname $source]
1197 automf_load source $source
1198 autosetup_add_dep $source
1199 } else {
1200 autosetup-error "use: No such module: $m"
1201 }
1202 }
@@ -1205,23 +1257,28 @@
1205
1206 proc autosetup_load_auto_modules {} {
1207 global autosetup modsource
1208 # First load any embedded auto modules
1209 foreach mod [array names modsource *.auto] {
1210 automf_load eval $modsource($mod)
1211 }
1212 # Now any external auto modules
1213 foreach file [glob -nocomplain $autosetup(libdir)/*.auto $autosetup(libdir)/*/*.auto] {
1214 automf_load source $file
1215 }
1216 }
1217
1218 # Load module source in the global scope by executing the given command
1219 proc automf_load {args} {
 
 
 
 
1220 if {[catch [list uplevel #0 $args] msg opts] ni {0 2 3}} {
1221 autosetup-full-error [error-dump $msg $opts $::autosetup(debug)]
1222 }
 
1223 }
1224
1225 # Initial settings
1226 set autosetup(exe) $::argv0
1227 set autosetup(istcl) 1
@@ -1229,10 +1286,11 @@
1229 set autosetup(installed) 0
1230 set autosetup(sysinstall) 0
1231 set autosetup(msg-checking) 0
1232 set autosetup(msg-quiet) 0
1233 set autosetup(inittypes) {}
 
1234
1235 # Embedded modules are inserted below here
1236 set autosetup(installed) 1
1237 set autosetup(sysinstall) 0
1238 # ----- @module asciidoc-formatting.tcl -----
@@ -1432,28 +1490,28 @@
1432 proc autosetup_help {what} {
1433 use_pager
1434
1435 puts "Usage: [file tail $::autosetup(exe)] \[options\] \[settings\]\n"
1436 puts "This is [autosetup_version], a build environment \"autoconfigurator\""
1437 puts "See the documentation online at http://msteveb.github.com/autosetup/\n"
1438
1439 if {$what eq "local"} {
1440 if {[file exists $::autosetup(autodef)]} {
1441 # This relies on auto.def having a call to 'options'
1442 # which will display options and quit
1443 source $::autosetup(autodef)
1444 } else {
1445 options-show
1446 }
1447 } else {
1448 incr ::autosetup(showhelp)
1449 if {[catch {use $what}]} {
1450 user-error "Unknown module: $what"
1451 } else {
1452 options-show
1453 }
1454 }
1455 exit 0
1456 }
1457
1458 proc autosetup_show_license {} {
1459 global modsource autosetup
@@ -1505,11 +1563,12 @@
1505 title "[autosetup_version] -- Command Reference"
1506
1507 section {Introduction}
1508
1509 p {
1510 See http://msteveb.github.com/autosetup/ for the online documentation for 'autosetup'
 
1511 }
1512
1513 p {
1514 'autosetup' provides a number of built-in commands which
1515 are documented below. These may be used from 'auto.def' to test
@@ -1568,10 +1627,15 @@
1568 set modulename [file rootname [file tail $file]]
1569 set current _core_
1570 set f [open $file]
1571 while {![eof $f]} {
1572 set line [gets $f]
 
 
 
 
 
1573
1574 # Find embedded module names
1575 if {[regexp {^#.*@module ([^ ]*)} $line -> modulename]} {
1576 continue
1577 }
@@ -1583,11 +1647,11 @@
1583
1584 # Synopsis or command?
1585 if {$cmd eq "synopsis:"} {
1586 set current $modulename
1587 lappend doc($current) [list section "Module: $modulename"]
1588 } else {
1589 lappend doc($current) [list subsection $cmd]
1590 }
1591
1592 set lines {}
1593 set type p
@@ -1863,10 +1927,11 @@
1863 }
1864 } else {
1865 writefile configure \
1866 {#!/bin/sh
1867 dir="`dirname "$0"`/autosetup"
 
1868 WRAPPER="$0"; export WRAPPER; exec "`"$dir/autosetup-find-tclsh"`" "$dir/autosetup" "$@"
1869 }
1870 }
1871 catch {exec chmod 755 configure}
1872 }
@@ -1909,11 +1974,11 @@
1909 *.tcl files in this directory are optional modules which
1910 can be loaded with the 'use' directive.
1911
1912 *.auto files in this directory are auto-loaded.
1913
1914 For more information, see http://msteveb.github.com/autosetup/
1915 }
1916 dputs "install: autosetup/README.autosetup"
1917 writefile $target $readme
1918 }
1919 }
@@ -2043,10 +2108,23 @@
2043 return -code error "environment variable \"$name\" does not exist"
2044 }
2045 proc isatty? {channel} {
2046 dict exists [fconfigure $channel] -xchar
2047 }
 
 
 
 
 
 
 
 
 
 
 
 
 
2048 } else {
2049 if {$autosetup(iswin)} {
2050 # On Windows, backslash convert all environment variables
2051 # (Assume that Tcl does this for us)
2052 proc getenv {name args} {
@@ -2096,20 +2174,15 @@
2096 proc error-location {msg} {
2097 if {$::autosetup(debug)} {
2098 return -code error $msg
2099 }
2100 # Search back through the stack trace for the first error in a .def file
2101 for {set i 1} {$i < [info level]} {incr i} {
2102 if {$::autosetup(istcl)} {
2103 array set info [info frame -$i]
2104 } else {
2105 lassign [info frame -$i] info(caller) info(file) info(line)
2106 }
2107 if {[string match *.def $info(file)]} {
2108 return "[relative-path $info(file)]:$info(line): Error: $msg"
2109 }
2110 #puts "Skipping $info(file):$info(line)"
2111 }
2112 return $msg
2113 }
2114
2115 # If everything is working properly, the only errors which occur
@@ -2298,10 +2371,12 @@
2298 set modsource(util.tcl) {
2299 # Copyright (c) 2012 WorkWare Systems http://www.workware.net.au/
2300 # All rights reserved
2301
2302 # Module which contains miscellaneous utility functions
 
 
2303
2304 # @compare-versions version1 version2
2305 #
2306 # Versions are of the form 'a.b.c' (may be any number of numeric components)
2307 #
2308
--- autosetup/autosetup
+++ autosetup/autosetup
@@ -4,11 +4,11 @@
4 # vim:se syntax=tcl:
5 # \
6 dir=`dirname "$0"`; exec "`$dir/autosetup-find-tclsh`" "$0" "$@"
7
8 # Note that the version has a trailing + on unreleased versions
9 set autosetup(version) 0.7.1+
10
11 # Can be set to 1 to debug early-init problems
12 set autosetup(debug) [expr {"--debug" in $argv}]
13
14 ##################################################################
@@ -91,17 +91,17 @@
91 # We simply parse anything that looks like an option
92 set autosetup(getopt) [getopt argv]
93
94 #"=Core Options:"
95 options-add {
96 help:=all => "display help and options. Optional: module name, such as --help=system"
97 licence license => "display the autosetup license"
98 version => "display the version of autosetup"
99 ref:=text manual:=text
100 reference:=text => "display the autosetup command reference. 'text', 'wiki', 'asciidoc' or 'markdown'"
101 debug => "display debugging output as autosetup runs"
102 install:=. => "install autosetup to the current or given directory"
103 }
104 if {$autosetup(installed)} {
105 # hidden options so we can produce a nice error
106 options-add {
107 sysinstall:path
@@ -202,24 +202,21 @@
202 }
203 }
204
205 autosetup_add_dep $autosetup(autodef)
206
207 # Add $argv to CONFIGURE_OPTS
208 define-append-argv CONFIGURE_OPTS {*}$autosetup(argv)
209 # Set up AUTOREMAKE to reconfigure with the same args
210 define-append-argv AUTOREMAKE {*}$autosetup(exe) {*}$autosetup(argv)
 
 
 
211
212 # Log how we were invoked
213 configlog "Invoked as: [getenv WRAPPER $::argv0] [quote-argv $autosetup(argv)]"
214 configlog "Tclsh: [info nameofexecutable]"
215
216 # Load auto.def as module "auto.def"
217 autosetup_load_module auto.def source $autosetup(autodef)
218
219 # Could warn here if options {} was not specified
220
221 show-notices
222
@@ -231,10 +228,12 @@
228 }
229 }
230
231 exit 0
232 }
233
234 # @section Option Handling
235
236 # @opt-bool ?-nodefault? option ...
237 #
238 # Check each of the named, boolean options and if any have been explicitly enabled
239 # or disabled by the user, return 1 or 0 accordingly.
@@ -340,12 +339,12 @@
339 }
340
341 if {![info exists result]} {
342 # No user-specified value. Has options-defaults been set?
343 foreach opt $names {
344 if {[dict exists $::autosetup(optdefault) $opt]} {
345 set result [dict get $autosetup(optdefault) $opt]
346 }
347 }
348 }
349
350 if {[info exists result]} {
@@ -373,11 +372,11 @@
372 }
373
374 # Parse the option definition in $opts and update
375 # ::autosetup(setoptions) and ::autosetup(optionhelp) appropriately
376 #
377 proc options-add {opts} {
378 global autosetup
379
380 # First weed out comment lines
381 set realopts {}
382 foreach line [split $opts \n] {
@@ -389,12 +388,11 @@
388
389 for {set i 0} {$i < [llength $opts]} {incr i} {
390 set opt [lindex $opts $i]
391 if {[string match =* $opt]} {
392 # This is a special heading
393 lappend autosetup(optionhelp) [list $opt $autosetup(module)]
 
394 continue
395 }
396 unset -nocomplain defaultvalue equal value
397
398 #puts "i=$i, opt=$opt"
@@ -451,12 +449,12 @@
449 }
450 } else {
451 # String option.
452 lappend autosetup(options) $name
453
454 if {$equal ne "="} {
455 # Was the option given as "name:value=default"?
456 # If so, set $value to the display name and $defaultvalue to the default
457 # (This is the preferred way to set a default value for a string option)
458 if {[regexp {^([^=]+)=(.*)$} $value -> value defaultvalue]} {
459 dict set autosetup(optdefault) $name $defaultvalue
460 }
@@ -466,13 +464,13 @@
464 if {[dict exists $autosetup(options-defaults) $name]} {
465 # A default was specified with options-defaults, so use it
466 set defaultvalue [dict get $autosetup(options-defaults) $name]
467 dict set autosetup(optdefault) $name $defaultvalue
468 } elseif {![info exists defaultvalue]} {
469 # No default value was given by value=default or options-defaults
470 # so use the value as the default when the plain option with no
471 # value is given (.e.g. just --opt instead of --opt=value)
472 set defaultvalue $value
473 }
474
475 if {$equal eq "="} {
476 # String option with optional value
@@ -507,39 +505,22 @@
505 if {[lindex $opts $i+1] eq "=>"} {
506 set desc [lindex $opts $i+2]
507 if {[info exists defaultvalue]} {
508 set desc [string map [list @default@ $defaultvalue] $desc]
509 }
 
 
 
 
 
510 # A multi-line description
511 lappend autosetup(optionhelp) [list $opthelp $autosetup(module) $desc]
512 incr i 2
513 }
514 }
515 }
516
517 # @module-options optionlist
518 #
519 # Deprecated. Simply use 'options' from within a module.
520 proc module-options {opts} {
521 options $opts
 
 
 
 
 
 
 
 
 
 
 
 
522 }
523
524 proc max {a b} {
525 expr {$a > $b ? $a : $b}
526 }
@@ -564,36 +545,53 @@
545 if {$len} {
546 puts ""
547 }
548 }
549
550 # Display options (from $autosetup(optionhelp)) for modules that match
551 # glob pattern $what
552 proc options-show {what} {
553 set local 0
554 # Determine the max option width
555 set max 0
556 foreach help $::autosetup(optionhelp) {
557 lassign $help opt module desc
558 if {![string match $what $module]} {
559 continue
560 }
561 if {[string match =* $opt] || [string match \n* $desc]} {
562 continue
563 }
564 set max [max $max [string length $opt]]
565 }
566 set indent [string repeat " " [expr {$max+4}]]
567 set cols [getenv COLUMNS 80]
568 catch {
569 lassign [exec stty size] rows cols
570 }
571 incr cols -1
572 # Now output
573 foreach help $::autosetup(optionhelp) {
574 lassign $help opt module desc
575 if {![string match $what $module]} {
576 continue
577 }
578 if {$local == 0 && $module eq "auto.def"} {
579 puts "Local Options:"
580 incr local
581 }
582 if {[string match =* $opt]} {
583 # Output a special heading line"
584 puts [string range $opt 1 end]
585 continue
586 }
587 puts -nonewline " [format %-${max}s $opt]"
588 if {[string match \n* $desc]} {
589 # Output a pre-formatted help description as-is
590 puts $desc
591 } else {
592 options-wrap-desc [string trim $desc] $cols " " $indent [expr {$max+2}]
593 }
594 }
595 }
596
597 # @options optionspec
@@ -608,16 +606,20 @@
606 #
607 # The default is 'name=0', meaning that the option is disabled by default.
608 # If 'name=1' is used to make the option enabled by default, the description should reflect
609 # that with text like "Disable support for ...".
610 #
611 # An argument option (one which takes a parameter) is of one of the following forms:
612 #
613 ## name:value => "Description of this option"
614 ## name:value=default => "Description of this option with a default value"
615 ## name:=value => "Description of this option with an optional value"
616 #
617 # If the 'name:value' form is used, the value must be provided with the option (as '--name=myvalue').
618 # If the 'name:value=default' form is used, the option has the given default value even if not
619 # specified by the user.
620 # If the 'name:=value' form is used, the value is optional and the given value is used
621 # if it is not provided.
622 #
623 # The description may contain '@default@', in which case it will be replaced with the default
624 # value for the option (taking into account defaults specified with 'options-defaults'.
625 #
@@ -627,23 +629,26 @@
629 # For example, '--disable-lfs' is an alias for '--disable=largefile':
630 #
631 ## lfs=1 largefile=1 => "Disable large file support"
632 #
633 proc options {optlist} {
634 global autosetup
 
635
636 options-add $optlist
637
638 if {$autosetup(showhelp)} {
639 # If --help, stop now to show help
640 return -code break
641 }
642
643 if {$autosetup(module) eq "auto.def"} {
644 # Check for invalid options
645 if {[opt-bool option-checking]} {
646 foreach o [dict keys $::autosetup(getopt)] {
647 if {$o ni $::autosetup(options)} {
648 user-error "Unknown option --$o"
649 }
650 }
651 }
652 }
653 }
654
@@ -677,10 +682,12 @@
682 }
683 }
684 return $alias
685 }
686
687 # @section Variable Definitions (defines)
688
689 # @define name ?value=1?
690 #
691 # Defines the named variable to the given value.
692 # These (name, value) pairs represent the results of the configuration check
693 # and are available to be subsequently checked, modified and substituted.
@@ -687,10 +694,33 @@
694 #
695 proc define {name {value 1}} {
696 set ::define($name) $value
697 #dputs "$name <= $value"
698 }
699
700 # @define-push {name ...} script
701 #
702 # Save the values of the given defines, evaluation the script, then restore.
703 # For example, to avoid updating AS_FLAGS and AS_CXXFLAGS:
704 ## define-push {AS_CFLAGS AS_CXXFLAGS} {
705 ## cc-check-flags -Wno-error
706 ## }
707 proc define-push {names script} {
708 array set unset {}
709 foreach name $names {
710 if {[is-defined $name]} {
711 set save($name) [get-define $name]
712 } else {
713 set unset($name) 1
714 }
715 }
716 uplevel 1 $script
717 array set ::define [array get save]
718 foreach name [array names unset] {
719 unset -nocomplain ::define($name)
720 }
721 }
722
723 # @undefine name
724 #
725 # Undefine the named variable.
726 #
@@ -703,34 +733,48 @@
733 #
734 # Appends the given value(s) to the given "defined" variable.
735 # If the variable is not defined or empty, it is set to '$value'.
736 # Otherwise the value is appended, separated by a space.
737 # Any extra values are similarly appended.
738 #
739 # Note that define-append is not designed to add values containing spaces.
740 # If values may contain spaces, consider define-append-argv instead.
741 #
742 proc define-append {name args} {
743 if {[get-define $name ""] ne ""} {
 
744 foreach arg $args {
745 if {$arg eq ""} {
746 continue
747 }
748 append ::define($name) " " $arg
 
 
 
 
 
 
 
 
749 }
750 } else {
751 set ::define($name) [join $args]
752 }
753 #dputs "$name += [join $args] => $::define($name)"
754 }
755
756 # @define-append-argv name value ...
757 #
758 # Similar to define-append except designed to construct shell command
759 # lines, including correct handling of parameters with spaces.
760 #
761 # Each non-empty value is quoted if necessary and then appended to the given variable
762 # if it does not already exist.
763 #
764 proc define-append-argv {name args} {
765 set seen {}
766 set new {}
767 foreach val [list {*}[get-define $name ""] {*}$args] {
768 if {$val ne {} && ![dict exists $seen $val]} {
769 lappend new [quote-if-needed $val]
770 dict set seen $val 1
771 }
772 }
773 set ::define($name) [join $new " "]
774 #dputs "$name += [join $args] => $::define($name)"
775 }
776
777 # @get-define name ?default=0?
778 #
779 # Returns the current value of the "defined" variable, or '$default'
780 # if not set.
@@ -773,10 +817,11 @@
817 #
818 proc all-defines {} {
819 array get ::define
820 }
821
822 # @section Environment/Helpers
823
824 # @get-env name default
825 #
826 # If '$name' was specified on the command line, return it.
827 # Otherwise if '$name' was set in the environment, return it.
@@ -855,10 +900,12 @@
900 lappend result $p
901 }
902 }
903 return $result
904 }
905
906 # @section Paths, Searching
907
908 # @find-executable-path name
909 #
910 # Searches the path for an executable with the given name.
911 # Note that the name may include some parameters, e.g. 'cc -mbig-endian',
@@ -924,10 +971,12 @@
971 user-error "failed to find one of: [join $args]"
972 }
973 }
974 return ""
975 }
976
977 # @section Logging, Messages and Errors
978
979 # @configlog msg
980 #
981 # Writes the given message to the configuration log, 'config.log'.
982 #
@@ -1141,10 +1190,12 @@
1190 # The name will be normalised (converted to a full path)
1191 #
1192 proc autosetup_add_dep {filename} {
1193 lappend ::autosetup(deps) [file-normalize $filename]
1194 }
1195
1196 # @section Modules Support
1197
1198 ##################################################################
1199 #
1200 # Library module support
1201 #
@@ -1171,12 +1222,13 @@
1222 foreach m $args {
1223 if {[info exists libmodule($m)]} {
1224 continue
1225 }
1226 set libmodule($m) 1
1227
1228 if {[info exists modsource(${m}.tcl)]} {
1229 autosetup_load_module $m eval $modsource(${m}.tcl)
1230 } else {
1231 set locs [list ${m}.tcl ${m}/init.tcl]
1232 set found 0
1233 foreach dir $dirs {
1234 foreach loc $locs {
@@ -1192,11 +1244,11 @@
1244 }
1245 if {$found} {
1246 # For the convenience of the "use" source, point to the directory
1247 # it is being loaded from
1248 set ::usedir [file dirname $source]
1249 autosetup_load_module $m source $source
1250 autosetup_add_dep $source
1251 } else {
1252 autosetup-error "use: No such module: $m"
1253 }
1254 }
@@ -1205,23 +1257,28 @@
1257
1258 proc autosetup_load_auto_modules {} {
1259 global autosetup modsource
1260 # First load any embedded auto modules
1261 foreach mod [array names modsource *.auto] {
1262 autosetup_load_module $mod eval $modsource($mod)
1263 }
1264 # Now any external auto modules
1265 foreach file [glob -nocomplain $autosetup(libdir)/*.auto $autosetup(libdir)/*/*.auto] {
1266 autosetup_load_module [file tail $file] source $file
1267 }
1268 }
1269
1270 # Load module source in the global scope by executing the given command
1271 proc autosetup_load_module {module args} {
1272 global autosetup
1273 set prev $autosetup(module)
1274 set autosetup(module) $module
1275
1276 if {[catch [list uplevel #0 $args] msg opts] ni {0 2 3}} {
1277 autosetup-full-error [error-dump $msg $opts $::autosetup(debug)]
1278 }
1279 set autosetup(module) $prev
1280 }
1281
1282 # Initial settings
1283 set autosetup(exe) $::argv0
1284 set autosetup(istcl) 1
@@ -1229,10 +1286,11 @@
1286 set autosetup(installed) 0
1287 set autosetup(sysinstall) 0
1288 set autosetup(msg-checking) 0
1289 set autosetup(msg-quiet) 0
1290 set autosetup(inittypes) {}
1291 set autosetup(module) autosetup
1292
1293 # Embedded modules are inserted below here
1294 set autosetup(installed) 1
1295 set autosetup(sysinstall) 0
1296 # ----- @module asciidoc-formatting.tcl -----
@@ -1432,28 +1490,28 @@
1490 proc autosetup_help {what} {
1491 use_pager
1492
1493 puts "Usage: [file tail $::autosetup(exe)] \[options\] \[settings\]\n"
1494 puts "This is [autosetup_version], a build environment \"autoconfigurator\""
1495 puts "See the documentation online at https://msteveb.github.io/autosetup/\n"
1496
1497 if {$what in {all local}} {
1498 # Need to load auto.def now
1499 if {[file exists $::autosetup(autodef)]} {
1500 # Load auto.def as module "auto.def"
1501 autosetup_load_module auto.def source $::autosetup(autodef)
1502 }
1503 if {$what eq "all"} {
1504 set what *
1505 } else {
1506 set what auto.def
1507 }
1508 } else {
1509 use $what
1510 puts "Options for module $what:"
1511 }
1512 options-show $what
1513 exit 0
1514 }
1515
1516 proc autosetup_show_license {} {
1517 global modsource autosetup
@@ -1505,11 +1563,12 @@
1563 title "[autosetup_version] -- Command Reference"
1564
1565 section {Introduction}
1566
1567 p {
1568 See https://msteveb.github.io/autosetup/ for the online documentation for 'autosetup'.
1569 This documentation can also be accessed locally with `autosetup --ref`.
1570 }
1571
1572 p {
1573 'autosetup' provides a number of built-in commands which
1574 are documented below. These may be used from 'auto.def' to test
@@ -1568,10 +1627,15 @@
1627 set modulename [file rootname [file tail $file]]
1628 set current _core_
1629 set f [open $file]
1630 while {![eof $f]} {
1631 set line [gets $f]
1632
1633 if {[regexp {^#.*@section (.*)$} $line -> section]} {
1634 lappend doc($current) [list section $section]
1635 continue
1636 }
1637
1638 # Find embedded module names
1639 if {[regexp {^#.*@module ([^ ]*)} $line -> modulename]} {
1640 continue
1641 }
@@ -1583,11 +1647,11 @@
1647
1648 # Synopsis or command?
1649 if {$cmd eq "synopsis:"} {
1650 set current $modulename
1651 lappend doc($current) [list section "Module: $modulename"]
1652 } else {
1653 lappend doc($current) [list subsection $cmd]
1654 }
1655
1656 set lines {}
1657 set type p
@@ -1863,10 +1927,11 @@
1927 }
1928 } else {
1929 writefile configure \
1930 {#!/bin/sh
1931 dir="`dirname "$0"`/autosetup"
1932 #@@INITCHECK@@#
1933 WRAPPER="$0"; export WRAPPER; exec "`"$dir/autosetup-find-tclsh"`" "$dir/autosetup" "$@"
1934 }
1935 }
1936 catch {exec chmod 755 configure}
1937 }
@@ -1909,11 +1974,11 @@
1974 *.tcl files in this directory are optional modules which
1975 can be loaded with the 'use' directive.
1976
1977 *.auto files in this directory are auto-loaded.
1978
1979 For more information, see https://msteveb.github.io/autosetup/
1980 }
1981 dputs "install: autosetup/README.autosetup"
1982 writefile $target $readme
1983 }
1984 }
@@ -2043,10 +2108,23 @@
2108 return -code error "environment variable \"$name\" does not exist"
2109 }
2110 proc isatty? {channel} {
2111 dict exists [fconfigure $channel] -xchar
2112 }
2113 # Jim-compatible stacktrace using info frame
2114 proc stacktrace {} {
2115 set stacktrace {}
2116 # 2 to skip the current frame
2117 for {set i 2} {$i < [info frame]} {incr i} {
2118 set frame [info frame -$i]
2119 if {[dict exists $frame file]} {
2120 # We don't need proc, so use ""
2121 lappend stacktrace "" [dict get $frame file] [dict get $frame line]
2122 }
2123 }
2124 return $stacktrace
2125 }
2126 } else {
2127 if {$autosetup(iswin)} {
2128 # On Windows, backslash convert all environment variables
2129 # (Assume that Tcl does this for us)
2130 proc getenv {name args} {
@@ -2096,20 +2174,15 @@
2174 proc error-location {msg} {
2175 if {$::autosetup(debug)} {
2176 return -code error $msg
2177 }
2178 # Search back through the stack trace for the first error in a .def file
2179 foreach {p f l} [stacktrace] {
2180 if {[string match *.def $f]} {
2181 return "[relative-path $f]:$l: Error: $msg"
2182 }
2183 #puts "Skipping $f:$l"
 
 
 
 
 
2184 }
2185 return $msg
2186 }
2187
2188 # If everything is working properly, the only errors which occur
@@ -2298,10 +2371,12 @@
2371 set modsource(util.tcl) {
2372 # Copyright (c) 2012 WorkWare Systems http://www.workware.net.au/
2373 # All rights reserved
2374
2375 # Module which contains miscellaneous utility functions
2376
2377 # @section Utilities
2378
2379 # @compare-versions version1 version2
2380 #
2381 # Versions are of the form 'a.b.c' (may be any number of numeric components)
2382 #
2383
--- autosetup/autosetup-config.guess
+++ autosetup/autosetup-config.guess
@@ -1,10 +1,12 @@
11
#! /bin/sh
22
# Attempt to guess a canonical system name.
3
-# Copyright 1992-2018 Free Software Foundation, Inc.
3
+# Copyright 1992-2021 Free Software Foundation, Inc.
44
5
-timestamp='2018-03-08'
5
+# shellcheck disable=SC2006,SC2268 # see below for rationale
6
+
7
+timestamp='2021-06-03'
68
79
# This file is free software; you can redistribute it and/or modify it
810
# under the terms of the GNU General Public License as published by
911
# the Free Software Foundation; either version 3 of the License, or
1012
# (at your option) any later version.
@@ -25,14 +27,22 @@
2527
# of the GNU General Public License, version 3 ("GPLv3").
2628
#
2729
# Originally written by Per Bothner; maintained since 2000 by Ben Elliston.
2830
#
2931
# You can get the latest version of this script from:
30
-# https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess
32
+# https://git.savannah.gnu.org/cgit/config.git/plain/config.guess
3133
#
3234
# Please send patches to <[email protected]>.
3335
36
+
37
+# The "shellcheck disable" line above the timestamp inhibits complaints
38
+# about features and limitations of the classic Bourne shell that were
39
+# superseded or lifted in POSIX. However, this script identifies a wide
40
+# variety of pre-POSIX systems that do not have POSIX shells at all, and
41
+# even some reasonably current systems (Solaris 10 as case-in-point) still
42
+# have a pre-POSIX /bin/sh.
43
+
3444
3545
me=`echo "$0" | sed -e 's,.*/,,'`
3646
3747
usage="\
3848
Usage: $0 [OPTION]
@@ -48,11 +58,11 @@
4858
4959
version="\
5060
GNU config.guess ($timestamp)
5161
5262
Originally written by Per Bothner.
53
-Copyright 1992-2018 Free Software Foundation, Inc.
63
+Copyright 1992-2021 Free Software Foundation, Inc.
5464
5565
This is free software; see the source for copying conditions. There is NO
5666
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
5767
5868
help="
@@ -82,11 +92,12 @@
8292
if test $# != 0; then
8393
echo "$me: too many arguments$help" >&2
8494
exit 1
8595
fi
8696
87
-trap 'exit 1' 1 2 15
97
+# Just in case it came from the environment.
98
+GUESS=
8899
89100
# CC_FOR_BUILD -- compiler used by this script. Note that the use of a
90101
# compiler to aid in system detection is discouraged as it requires
91102
# temporary files to be created and, as you can see below, it is a
92103
# headache to deal with in a portable fashion.
@@ -94,77 +105,94 @@
94105
# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still
95106
# use `HOST_CC' if defined, but it is deprecated.
96107
97108
# Portable tmp directory creation inspired by the Autoconf team.
98109
99
-set_cc_for_build='
100
-trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ;
101
-trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ;
102
-: ${TMPDIR=/tmp} ;
103
- { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
104
- { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } ||
105
- { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } ||
106
- { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ;
107
-dummy=$tmp/dummy ;
108
-tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ;
109
-case $CC_FOR_BUILD,$HOST_CC,$CC in
110
- ,,) echo "int x;" > "$dummy.c" ;
111
- for c in cc gcc c89 c99 ; do
112
- if ($c -c -o "$dummy.o" "$dummy.c") >/dev/null 2>&1 ; then
113
- CC_FOR_BUILD="$c"; break ;
114
- fi ;
115
- done ;
116
- if test x"$CC_FOR_BUILD" = x ; then
117
- CC_FOR_BUILD=no_compiler_found ;
118
- fi
119
- ;;
120
- ,,*) CC_FOR_BUILD=$CC ;;
121
- ,*,*) CC_FOR_BUILD=$HOST_CC ;;
122
-esac ; set_cc_for_build= ;'
110
+tmp=
111
+# shellcheck disable=SC2172
112
+trap 'test -z "$tmp" || rm -fr "$tmp"' 0 1 2 13 15
113
+
114
+set_cc_for_build() {
115
+ # prevent multiple calls if $tmp is already set
116
+ test "$tmp" && return 0
117
+ : "${TMPDIR=/tmp}"
118
+ # shellcheck disable=SC2039,SC3028
119
+ { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
120
+ { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir "$tmp" 2>/dev/null) ; } ||
121
+ { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir "$tmp" 2>/dev/null) && echo "Warning: creating insecure temp directory" >&2 ; } ||
122
+ { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; }
123
+ dummy=$tmp/dummy
124
+ case ${CC_FOR_BUILD-},${HOST_CC-},${CC-} in
125
+ ,,) echo "int x;" > "$dummy.c"
126
+ for driver in cc gcc c89 c99 ; do
127
+ if ($driver -c -o "$dummy.o" "$dummy.c") >/dev/null 2>&1 ; then
128
+ CC_FOR_BUILD=$driver
129
+ break
130
+ fi
131
+ done
132
+ if test x"$CC_FOR_BUILD" = x ; then
133
+ CC_FOR_BUILD=no_compiler_found
134
+ fi
135
+ ;;
136
+ ,,*) CC_FOR_BUILD=$CC ;;
137
+ ,*,*) CC_FOR_BUILD=$HOST_CC ;;
138
+ esac
139
+}
123140
124141
# This is needed to find uname on a Pyramid OSx when run in the BSD universe.
125142
# ([email protected] 1994-08-24)
126
-if (test -f /.attbin/uname) >/dev/null 2>&1 ; then
143
+if test -f /.attbin/uname ; then
127144
PATH=$PATH:/.attbin ; export PATH
128145
fi
129146
130147
UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown
131148
UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown
132
-UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown
149
+UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown
133150
UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown
134151
135
-case "$UNAME_SYSTEM" in
152
+case $UNAME_SYSTEM in
136153
Linux|GNU|GNU/*)
137
- # If the system lacks a compiler, then just pick glibc.
138
- # We could probably try harder.
139
- LIBC=gnu
154
+ LIBC=unknown
140155
141
- eval "$set_cc_for_build"
156
+ set_cc_for_build
142157
cat <<-EOF > "$dummy.c"
143158
#include <features.h>
144159
#if defined(__UCLIBC__)
145160
LIBC=uclibc
146161
#elif defined(__dietlibc__)
147162
LIBC=dietlibc
148
- #else
163
+ #elif defined(__GLIBC__)
149164
LIBC=gnu
165
+ #else
166
+ #include <stdarg.h>
167
+ /* First heuristic to detect musl libc. */
168
+ #ifdef __DEFINED_va_list
169
+ LIBC=musl
170
+ #endif
150171
#endif
151172
EOF
152
- eval "`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^LIBC' | sed 's, ,,g'`"
173
+ cc_set_libc=`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^LIBC' | sed 's, ,,g'`
174
+ eval "$cc_set_libc"
175
+
176
+ # Second heuristic to detect musl libc.
177
+ if [ "$LIBC" = unknown ] &&
178
+ command -v ldd >/dev/null &&
179
+ ldd --version 2>&1 | grep -q ^musl; then
180
+ LIBC=musl
181
+ fi
153182
154
- # If ldd exists, use it to detect musl libc.
155
- if command -v ldd >/dev/null && \
156
- ldd --version 2>&1 | grep -q ^musl
157
- then
158
- LIBC=musl
183
+ # If the system lacks a compiler, then just pick glibc.
184
+ # We could probably try harder.
185
+ if [ "$LIBC" = unknown ]; then
186
+ LIBC=gnu
159187
fi
160188
;;
161189
esac
162190
163191
# Note: order is significant - the case branches are not exclusive.
164192
165
-case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in
193
+case $UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION in
166194
*:NetBSD:*:*)
167195
# NetBSD (nbsd) targets should (where applicable) match one or
168196
# more of the tuples: *-*-netbsdelf*, *-*-netbsdaout*,
169197
# *-*-netbsdecoff* and *-*-netbsd*. For targets that recently
170198
# switched to ELF, *-*-netbsd* would select the old
@@ -172,36 +200,36 @@
172200
# compatibility and a consistent mechanism for selecting the
173201
# object file format.
174202
#
175203
# Note: NetBSD doesn't particularly care about the vendor
176204
# portion of the name. We always set it to "unknown".
177
- sysctl="sysctl -n hw.machine_arch"
178205
UNAME_MACHINE_ARCH=`(uname -p 2>/dev/null || \
179
- "/sbin/$sysctl" 2>/dev/null || \
180
- "/usr/sbin/$sysctl" 2>/dev/null || \
206
+ /sbin/sysctl -n hw.machine_arch 2>/dev/null || \
207
+ /usr/sbin/sysctl -n hw.machine_arch 2>/dev/null || \
181208
echo unknown)`
182
- case "$UNAME_MACHINE_ARCH" in
209
+ case $UNAME_MACHINE_ARCH in
210
+ aarch64eb) machine=aarch64_be-unknown ;;
183211
armeb) machine=armeb-unknown ;;
184212
arm*) machine=arm-unknown ;;
185213
sh3el) machine=shl-unknown ;;
186214
sh3eb) machine=sh-unknown ;;
187215
sh5el) machine=sh5le-unknown ;;
188216
earmv*)
189217
arch=`echo "$UNAME_MACHINE_ARCH" | sed -e 's,^e\(armv[0-9]\).*$,\1,'`
190218
endian=`echo "$UNAME_MACHINE_ARCH" | sed -ne 's,^.*\(eb\)$,\1,p'`
191
- machine="${arch}${endian}"-unknown
219
+ machine=${arch}${endian}-unknown
192220
;;
193
- *) machine="$UNAME_MACHINE_ARCH"-unknown ;;
221
+ *) machine=$UNAME_MACHINE_ARCH-unknown ;;
194222
esac
195223
# The Operating System including object format, if it has switched
196224
# to ELF recently (or will in the future) and ABI.
197
- case "$UNAME_MACHINE_ARCH" in
225
+ case $UNAME_MACHINE_ARCH in
198226
earm*)
199227
os=netbsdelf
200228
;;
201229
arm*|i386|m68k|ns32k|sh3*|sparc|vax)
202
- eval "$set_cc_for_build"
230
+ set_cc_for_build
203231
if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \
204232
| grep -q __ELF__
205233
then
206234
# Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout).
207235
# Return netbsd for either. FIX?
@@ -213,11 +241,11 @@
213241
*)
214242
os=netbsd
215243
;;
216244
esac
217245
# Determine ABI tags.
218
- case "$UNAME_MACHINE_ARCH" in
246
+ case $UNAME_MACHINE_ARCH in
219247
earm*)
220248
expr='s/^earmv[0-9]/-eabi/;s/eb$//'
221249
abi=`echo "$UNAME_MACHINE_ARCH" | sed -e "$expr"`
222250
;;
223251
esac
@@ -224,11 +252,11 @@
224252
# The OS release
225253
# Debian GNU/NetBSD machines have a different userland, and
226254
# thus, need a distinct triplet. However, they do not need
227255
# kernel version information, so it can be replaced with a
228256
# suitable tag, in the style of linux-gnu.
229
- case "$UNAME_VERSION" in
257
+ case $UNAME_VERSION in
230258
Debian*)
231259
release='-gnu'
232260
;;
233261
*)
234262
release=`echo "$UNAME_RELEASE" | sed -e 's/[-_].*//' | cut -d. -f1,2`
@@ -235,49 +263,61 @@
235263
;;
236264
esac
237265
# Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM:
238266
# contains redundant information, the shorter form:
239267
# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used.
240
- echo "$machine-${os}${release}${abi}"
241
- exit ;;
268
+ GUESS=$machine-${os}${release}${abi-}
269
+ ;;
242270
*:Bitrig:*:*)
243271
UNAME_MACHINE_ARCH=`arch | sed 's/Bitrig.//'`
244
- echo "$UNAME_MACHINE_ARCH"-unknown-bitrig"$UNAME_RELEASE"
245
- exit ;;
272
+ GUESS=$UNAME_MACHINE_ARCH-unknown-bitrig$UNAME_RELEASE
273
+ ;;
246274
*:OpenBSD:*:*)
247275
UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'`
248
- echo "$UNAME_MACHINE_ARCH"-unknown-openbsd"$UNAME_RELEASE"
249
- exit ;;
276
+ GUESS=$UNAME_MACHINE_ARCH-unknown-openbsd$UNAME_RELEASE
277
+ ;;
278
+ *:SecBSD:*:*)
279
+ UNAME_MACHINE_ARCH=`arch | sed 's/SecBSD.//'`
280
+ GUESS=$UNAME_MACHINE_ARCH-unknown-secbsd$UNAME_RELEASE
281
+ ;;
250282
*:LibertyBSD:*:*)
251283
UNAME_MACHINE_ARCH=`arch | sed 's/^.*BSD\.//'`
252
- echo "$UNAME_MACHINE_ARCH"-unknown-libertybsd"$UNAME_RELEASE"
253
- exit ;;
284
+ GUESS=$UNAME_MACHINE_ARCH-unknown-libertybsd$UNAME_RELEASE
285
+ ;;
254286
*:MidnightBSD:*:*)
255
- echo "$UNAME_MACHINE"-unknown-midnightbsd"$UNAME_RELEASE"
256
- exit ;;
287
+ GUESS=$UNAME_MACHINE-unknown-midnightbsd$UNAME_RELEASE
288
+ ;;
257289
*:ekkoBSD:*:*)
258
- echo "$UNAME_MACHINE"-unknown-ekkobsd"$UNAME_RELEASE"
259
- exit ;;
290
+ GUESS=$UNAME_MACHINE-unknown-ekkobsd$UNAME_RELEASE
291
+ ;;
260292
*:SolidBSD:*:*)
261
- echo "$UNAME_MACHINE"-unknown-solidbsd"$UNAME_RELEASE"
262
- exit ;;
293
+ GUESS=$UNAME_MACHINE-unknown-solidbsd$UNAME_RELEASE
294
+ ;;
295
+ *:OS108:*:*)
296
+ GUESS=$UNAME_MACHINE-unknown-os108_$UNAME_RELEASE
297
+ ;;
263298
macppc:MirBSD:*:*)
264
- echo powerpc-unknown-mirbsd"$UNAME_RELEASE"
265
- exit ;;
299
+ GUESS=powerpc-unknown-mirbsd$UNAME_RELEASE
300
+ ;;
266301
*:MirBSD:*:*)
267
- echo "$UNAME_MACHINE"-unknown-mirbsd"$UNAME_RELEASE"
268
- exit ;;
302
+ GUESS=$UNAME_MACHINE-unknown-mirbsd$UNAME_RELEASE
303
+ ;;
269304
*:Sortix:*:*)
270
- echo "$UNAME_MACHINE"-unknown-sortix
271
- exit ;;
305
+ GUESS=$UNAME_MACHINE-unknown-sortix
306
+ ;;
307
+ *:Twizzler:*:*)
308
+ GUESS=$UNAME_MACHINE-unknown-twizzler
309
+ ;;
272310
*:Redox:*:*)
273
- echo "$UNAME_MACHINE"-unknown-redox
274
- exit ;;
311
+ GUESS=$UNAME_MACHINE-unknown-redox
312
+ ;;
275313
mips:OSF1:*.*)
276
- echo mips-dec-osf1
277
- exit ;;
314
+ GUESS=mips-dec-osf1
315
+ ;;
278316
alpha:OSF1:*:*)
317
+ # Reset EXIT trap before exiting to avoid spurious non-zero exit code.
318
+ trap '' 0
279319
case $UNAME_RELEASE in
280320
*4.0)
281321
UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'`
282322
;;
283323
*5.*)
@@ -287,11 +327,11 @@
287327
# According to Compaq, /usr/sbin/psrinfo has been available on
288328
# OSF/1 and Tru64 systems produced since 1995. I hope that
289329
# covers most systems running today. This code pipes the CPU
290330
# types through head -n 1, so we only detect the type of CPU 0.
291331
ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1`
292
- case "$ALPHA_CPU_TYPE" in
332
+ case $ALPHA_CPU_TYPE in
293333
"EV4 (21064)")
294334
UNAME_MACHINE=alpha ;;
295335
"EV4.5 (21064)")
296336
UNAME_MACHINE=alpha ;;
297337
"LCA4 (21066/21068)")
@@ -324,167 +364,171 @@
324364
# A Pn.n version is a patched version.
325365
# A Vn.n version is a released version.
326366
# A Tn.n version is a released field test version.
327367
# A Xn.n version is an unreleased experimental baselevel.
328368
# 1.2 uses "1.2" for uname -r.
329
- echo "$UNAME_MACHINE"-dec-osf"`echo "$UNAME_RELEASE" | sed -e 's/^[PVTX]//' | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`"
330
- # Reset EXIT trap before exiting to avoid spurious non-zero exit code.
331
- exitcode=$?
332
- trap '' 0
333
- exit $exitcode ;;
369
+ OSF_REL=`echo "$UNAME_RELEASE" | sed -e 's/^[PVTX]//' | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`
370
+ GUESS=$UNAME_MACHINE-dec-osf$OSF_REL
371
+ ;;
334372
Amiga*:UNIX_System_V:4.0:*)
335
- echo m68k-unknown-sysv4
336
- exit ;;
373
+ GUESS=m68k-unknown-sysv4
374
+ ;;
337375
*:[Aa]miga[Oo][Ss]:*:*)
338
- echo "$UNAME_MACHINE"-unknown-amigaos
339
- exit ;;
376
+ GUESS=$UNAME_MACHINE-unknown-amigaos
377
+ ;;
340378
*:[Mm]orph[Oo][Ss]:*:*)
341
- echo "$UNAME_MACHINE"-unknown-morphos
342
- exit ;;
379
+ GUESS=$UNAME_MACHINE-unknown-morphos
380
+ ;;
343381
*:OS/390:*:*)
344
- echo i370-ibm-openedition
345
- exit ;;
382
+ GUESS=i370-ibm-openedition
383
+ ;;
346384
*:z/VM:*:*)
347
- echo s390-ibm-zvmoe
348
- exit ;;
385
+ GUESS=s390-ibm-zvmoe
386
+ ;;
349387
*:OS400:*:*)
350
- echo powerpc-ibm-os400
351
- exit ;;
388
+ GUESS=powerpc-ibm-os400
389
+ ;;
352390
arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
353
- echo arm-acorn-riscix"$UNAME_RELEASE"
354
- exit ;;
391
+ GUESS=arm-acorn-riscix$UNAME_RELEASE
392
+ ;;
355393
arm*:riscos:*:*|arm*:RISCOS:*:*)
356
- echo arm-unknown-riscos
357
- exit ;;
394
+ GUESS=arm-unknown-riscos
395
+ ;;
358396
SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*)
359
- echo hppa1.1-hitachi-hiuxmpp
360
- exit ;;
397
+ GUESS=hppa1.1-hitachi-hiuxmpp
398
+ ;;
361399
Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*)
362400
# [email protected] (Earle F. Ake) contributed MIS and NILE.
363
- if test "`(/bin/universe) 2>/dev/null`" = att ; then
364
- echo pyramid-pyramid-sysv3
365
- else
366
- echo pyramid-pyramid-bsd
367
- fi
368
- exit ;;
401
+ case `(/bin/universe) 2>/dev/null` in
402
+ att) GUESS=pyramid-pyramid-sysv3 ;;
403
+ *) GUESS=pyramid-pyramid-bsd ;;
404
+ esac
405
+ ;;
369406
NILE*:*:*:dcosx)
370
- echo pyramid-pyramid-svr4
371
- exit ;;
407
+ GUESS=pyramid-pyramid-svr4
408
+ ;;
372409
DRS?6000:unix:4.0:6*)
373
- echo sparc-icl-nx6
374
- exit ;;
410
+ GUESS=sparc-icl-nx6
411
+ ;;
375412
DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*)
376413
case `/usr/bin/uname -p` in
377
- sparc) echo sparc-icl-nx7; exit ;;
378
- esac ;;
414
+ sparc) GUESS=sparc-icl-nx7 ;;
415
+ esac
416
+ ;;
379417
s390x:SunOS:*:*)
380
- echo "$UNAME_MACHINE"-ibm-solaris2"`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'`"
381
- exit ;;
418
+ SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'`
419
+ GUESS=$UNAME_MACHINE-ibm-solaris2$SUN_REL
420
+ ;;
382421
sun4H:SunOS:5.*:*)
383
- echo sparc-hal-solaris2"`echo "$UNAME_RELEASE"|sed -e 's/[^.]*//'`"
384
- exit ;;
422
+ SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'`
423
+ GUESS=sparc-hal-solaris2$SUN_REL
424
+ ;;
385425
sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*)
386
- echo sparc-sun-solaris2"`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'`"
387
- exit ;;
426
+ SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'`
427
+ GUESS=sparc-sun-solaris2$SUN_REL
428
+ ;;
388429
i86pc:AuroraUX:5.*:* | i86xen:AuroraUX:5.*:*)
389
- echo i386-pc-auroraux"$UNAME_RELEASE"
390
- exit ;;
430
+ GUESS=i386-pc-auroraux$UNAME_RELEASE
431
+ ;;
391432
i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*)
392
- eval "$set_cc_for_build"
433
+ set_cc_for_build
393434
SUN_ARCH=i386
394435
# If there is a compiler, see if it is configured for 64-bit objects.
395436
# Note that the Sun cc does not turn __LP64__ into 1 like gcc does.
396437
# This test works for both compilers.
397
- if [ "$CC_FOR_BUILD" != no_compiler_found ]; then
438
+ if test "$CC_FOR_BUILD" != no_compiler_found; then
398439
if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \
399440
(CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \
400441
grep IS_64BIT_ARCH >/dev/null
401442
then
402443
SUN_ARCH=x86_64
403444
fi
404445
fi
405
- echo "$SUN_ARCH"-pc-solaris2"`echo "$UNAME_RELEASE"|sed -e 's/[^.]*//'`"
406
- exit ;;
446
+ SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'`
447
+ GUESS=$SUN_ARCH-pc-solaris2$SUN_REL
448
+ ;;
407449
sun4*:SunOS:6*:*)
408450
# According to config.sub, this is the proper way to canonicalize
409451
# SunOS6. Hard to guess exactly what SunOS6 will be like, but
410452
# it's likely to be more like Solaris than SunOS4.
411
- echo sparc-sun-solaris3"`echo "$UNAME_RELEASE"|sed -e 's/[^.]*//'`"
412
- exit ;;
453
+ SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'`
454
+ GUESS=sparc-sun-solaris3$SUN_REL
455
+ ;;
413456
sun4*:SunOS:*:*)
414
- case "`/usr/bin/arch -k`" in
457
+ case `/usr/bin/arch -k` in
415458
Series*|S4*)
416459
UNAME_RELEASE=`uname -v`
417460
;;
418461
esac
419462
# Japanese Language versions have a version number like `4.1.3-JL'.
420
- echo sparc-sun-sunos"`echo "$UNAME_RELEASE"|sed -e 's/-/_/'`"
421
- exit ;;
463
+ SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/-/_/'`
464
+ GUESS=sparc-sun-sunos$SUN_REL
465
+ ;;
422466
sun3*:SunOS:*:*)
423
- echo m68k-sun-sunos"$UNAME_RELEASE"
424
- exit ;;
467
+ GUESS=m68k-sun-sunos$UNAME_RELEASE
468
+ ;;
425469
sun*:*:4.2BSD:*)
426470
UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null`
427471
test "x$UNAME_RELEASE" = x && UNAME_RELEASE=3
428
- case "`/bin/arch`" in
472
+ case `/bin/arch` in
429473
sun3)
430
- echo m68k-sun-sunos"$UNAME_RELEASE"
474
+ GUESS=m68k-sun-sunos$UNAME_RELEASE
431475
;;
432476
sun4)
433
- echo sparc-sun-sunos"$UNAME_RELEASE"
477
+ GUESS=sparc-sun-sunos$UNAME_RELEASE
434478
;;
435479
esac
436
- exit ;;
480
+ ;;
437481
aushp:SunOS:*:*)
438
- echo sparc-auspex-sunos"$UNAME_RELEASE"
439
- exit ;;
482
+ GUESS=sparc-auspex-sunos$UNAME_RELEASE
483
+ ;;
440484
# The situation for MiNT is a little confusing. The machine name
441485
# can be virtually everything (everything which is not
442486
# "atarist" or "atariste" at least should have a processor
443487
# > m68000). The system name ranges from "MiNT" over "FreeMiNT"
444488
# to the lowercase version "mint" (or "freemint"). Finally
445489
# the system name "TOS" denotes a system which is actually not
446490
# MiNT. But MiNT is downward compatible to TOS, so this should
447491
# be no problem.
448492
atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*)
449
- echo m68k-atari-mint"$UNAME_RELEASE"
450
- exit ;;
493
+ GUESS=m68k-atari-mint$UNAME_RELEASE
494
+ ;;
451495
atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*)
452
- echo m68k-atari-mint"$UNAME_RELEASE"
453
- exit ;;
496
+ GUESS=m68k-atari-mint$UNAME_RELEASE
497
+ ;;
454498
*falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*)
455
- echo m68k-atari-mint"$UNAME_RELEASE"
456
- exit ;;
499
+ GUESS=m68k-atari-mint$UNAME_RELEASE
500
+ ;;
457501
milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*)
458
- echo m68k-milan-mint"$UNAME_RELEASE"
459
- exit ;;
502
+ GUESS=m68k-milan-mint$UNAME_RELEASE
503
+ ;;
460504
hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*)
461
- echo m68k-hades-mint"$UNAME_RELEASE"
462
- exit ;;
505
+ GUESS=m68k-hades-mint$UNAME_RELEASE
506
+ ;;
463507
*:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*)
464
- echo m68k-unknown-mint"$UNAME_RELEASE"
465
- exit ;;
508
+ GUESS=m68k-unknown-mint$UNAME_RELEASE
509
+ ;;
466510
m68k:machten:*:*)
467
- echo m68k-apple-machten"$UNAME_RELEASE"
468
- exit ;;
511
+ GUESS=m68k-apple-machten$UNAME_RELEASE
512
+ ;;
469513
powerpc:machten:*:*)
470
- echo powerpc-apple-machten"$UNAME_RELEASE"
471
- exit ;;
514
+ GUESS=powerpc-apple-machten$UNAME_RELEASE
515
+ ;;
472516
RISC*:Mach:*:*)
473
- echo mips-dec-mach_bsd4.3
474
- exit ;;
517
+ GUESS=mips-dec-mach_bsd4.3
518
+ ;;
475519
RISC*:ULTRIX:*:*)
476
- echo mips-dec-ultrix"$UNAME_RELEASE"
477
- exit ;;
520
+ GUESS=mips-dec-ultrix$UNAME_RELEASE
521
+ ;;
478522
VAX*:ULTRIX*:*:*)
479
- echo vax-dec-ultrix"$UNAME_RELEASE"
480
- exit ;;
523
+ GUESS=vax-dec-ultrix$UNAME_RELEASE
524
+ ;;
481525
2020:CLIX:*:* | 2430:CLIX:*:*)
482
- echo clipper-intergraph-clix"$UNAME_RELEASE"
483
- exit ;;
526
+ GUESS=clipper-intergraph-clix$UNAME_RELEASE
527
+ ;;
484528
mips:*:*:UMIPS | mips:*:*:RISCos)
485
- eval "$set_cc_for_build"
529
+ set_cc_for_build
486530
sed 's/^ //' << EOF > "$dummy.c"
487531
#ifdef __cplusplus
488532
#include <stdio.h> /* for printf() prototype */
489533
int main (int argc, char *argv[]) {
490534
#else
@@ -506,82 +550,83 @@
506550
EOF
507551
$CC_FOR_BUILD -o "$dummy" "$dummy.c" &&
508552
dummyarg=`echo "$UNAME_RELEASE" | sed -n 's/\([0-9]*\).*/\1/p'` &&
509553
SYSTEM_NAME=`"$dummy" "$dummyarg"` &&
510554
{ echo "$SYSTEM_NAME"; exit; }
511
- echo mips-mips-riscos"$UNAME_RELEASE"
512
- exit ;;
555
+ GUESS=mips-mips-riscos$UNAME_RELEASE
556
+ ;;
513557
Motorola:PowerMAX_OS:*:*)
514
- echo powerpc-motorola-powermax
515
- exit ;;
558
+ GUESS=powerpc-motorola-powermax
559
+ ;;
516560
Motorola:*:4.3:PL8-*)
517
- echo powerpc-harris-powermax
518
- exit ;;
561
+ GUESS=powerpc-harris-powermax
562
+ ;;
519563
Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*)
520
- echo powerpc-harris-powermax
521
- exit ;;
564
+ GUESS=powerpc-harris-powermax
565
+ ;;
522566
Night_Hawk:Power_UNIX:*:*)
523
- echo powerpc-harris-powerunix
524
- exit ;;
567
+ GUESS=powerpc-harris-powerunix
568
+ ;;
525569
m88k:CX/UX:7*:*)
526
- echo m88k-harris-cxux7
527
- exit ;;
570
+ GUESS=m88k-harris-cxux7
571
+ ;;
528572
m88k:*:4*:R4*)
529
- echo m88k-motorola-sysv4
530
- exit ;;
573
+ GUESS=m88k-motorola-sysv4
574
+ ;;
531575
m88k:*:3*:R3*)
532
- echo m88k-motorola-sysv3
533
- exit ;;
576
+ GUESS=m88k-motorola-sysv3
577
+ ;;
534578
AViiON:dgux:*:*)
535579
# DG/UX returns AViiON for all architectures
536580
UNAME_PROCESSOR=`/usr/bin/uname -p`
537
- if [ "$UNAME_PROCESSOR" = mc88100 ] || [ "$UNAME_PROCESSOR" = mc88110 ]
538
- then
539
- if [ "$TARGET_BINARY_INTERFACE"x = m88kdguxelfx ] || \
540
- [ "$TARGET_BINARY_INTERFACE"x = x ]
541
- then
542
- echo m88k-dg-dgux"$UNAME_RELEASE"
543
- else
544
- echo m88k-dg-dguxbcs"$UNAME_RELEASE"
545
- fi
546
- else
547
- echo i586-dg-dgux"$UNAME_RELEASE"
548
- fi
549
- exit ;;
550
- M88*:DolphinOS:*:*) # DolphinOS (SVR3)
551
- echo m88k-dolphin-sysv3
552
- exit ;;
581
+ if test "$UNAME_PROCESSOR" = mc88100 || test "$UNAME_PROCESSOR" = mc88110
582
+ then
583
+ if test "$TARGET_BINARY_INTERFACE"x = m88kdguxelfx || \
584
+ test "$TARGET_BINARY_INTERFACE"x = x
585
+ then
586
+ GUESS=m88k-dg-dgux$UNAME_RELEASE
587
+ else
588
+ GUESS=m88k-dg-dguxbcs$UNAME_RELEASE
589
+ fi
590
+ else
591
+ GUESS=i586-dg-dgux$UNAME_RELEASE
592
+ fi
593
+ ;;
594
+ M88*:DolphinOS:*:*) # DolphinOS (SVR3)
595
+ GUESS=m88k-dolphin-sysv3
596
+ ;;
553597
M88*:*:R3*:*)
554598
# Delta 88k system running SVR3
555
- echo m88k-motorola-sysv3
556
- exit ;;
599
+ GUESS=m88k-motorola-sysv3
600
+ ;;
557601
XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3)
558
- echo m88k-tektronix-sysv3
559
- exit ;;
602
+ GUESS=m88k-tektronix-sysv3
603
+ ;;
560604
Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD)
561
- echo m68k-tektronix-bsd
562
- exit ;;
605
+ GUESS=m68k-tektronix-bsd
606
+ ;;
563607
*:IRIX*:*:*)
564
- echo mips-sgi-irix"`echo "$UNAME_RELEASE"|sed -e 's/-/_/g'`"
565
- exit ;;
608
+ IRIX_REL=`echo "$UNAME_RELEASE" | sed -e 's/-/_/g'`
609
+ GUESS=mips-sgi-irix$IRIX_REL
610
+ ;;
566611
????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX.
567
- echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id
568
- exit ;; # Note that: echo "'`uname -s`'" gives 'AIX '
612
+ GUESS=romp-ibm-aix # uname -m gives an 8 hex-code CPU id
613
+ ;; # Note that: echo "'`uname -s`'" gives 'AIX '
569614
i*86:AIX:*:*)
570
- echo i386-ibm-aix
571
- exit ;;
615
+ GUESS=i386-ibm-aix
616
+ ;;
572617
ia64:AIX:*:*)
573
- if [ -x /usr/bin/oslevel ] ; then
618
+ if test -x /usr/bin/oslevel ; then
574619
IBM_REV=`/usr/bin/oslevel`
575620
else
576
- IBM_REV="$UNAME_VERSION.$UNAME_RELEASE"
621
+ IBM_REV=$UNAME_VERSION.$UNAME_RELEASE
577622
fi
578
- echo "$UNAME_MACHINE"-ibm-aix"$IBM_REV"
579
- exit ;;
623
+ GUESS=$UNAME_MACHINE-ibm-aix$IBM_REV
624
+ ;;
580625
*:AIX:2:3)
581626
if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then
582
- eval "$set_cc_for_build"
627
+ set_cc_for_build
583628
sed 's/^ //' << EOF > "$dummy.c"
584629
#include <sys/systemcfg.h>
585630
586631
main()
587632
{
@@ -591,78 +636,78 @@
591636
exit(0);
592637
}
593638
EOF
594639
if $CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=`"$dummy"`
595640
then
596
- echo "$SYSTEM_NAME"
641
+ GUESS=$SYSTEM_NAME
597642
else
598
- echo rs6000-ibm-aix3.2.5
643
+ GUESS=rs6000-ibm-aix3.2.5
599644
fi
600645
elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then
601
- echo rs6000-ibm-aix3.2.4
646
+ GUESS=rs6000-ibm-aix3.2.4
602647
else
603
- echo rs6000-ibm-aix3.2
648
+ GUESS=rs6000-ibm-aix3.2
604649
fi
605
- exit ;;
650
+ ;;
606651
*:AIX:*:[4567])
607652
IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`
608653
if /usr/sbin/lsattr -El "$IBM_CPU_ID" | grep ' POWER' >/dev/null 2>&1; then
609654
IBM_ARCH=rs6000
610655
else
611656
IBM_ARCH=powerpc
612657
fi
613
- if [ -x /usr/bin/lslpp ] ; then
614
- IBM_REV=`/usr/bin/lslpp -Lqc bos.rte.libc |
658
+ if test -x /usr/bin/lslpp ; then
659
+ IBM_REV=`/usr/bin/lslpp -Lqc bos.rte.libc | \
615660
awk -F: '{ print $3 }' | sed s/[0-9]*$/0/`
616661
else
617
- IBM_REV="$UNAME_VERSION.$UNAME_RELEASE"
662
+ IBM_REV=$UNAME_VERSION.$UNAME_RELEASE
618663
fi
619
- echo "$IBM_ARCH"-ibm-aix"$IBM_REV"
620
- exit ;;
664
+ GUESS=$IBM_ARCH-ibm-aix$IBM_REV
665
+ ;;
621666
*:AIX:*:*)
622
- echo rs6000-ibm-aix
623
- exit ;;
667
+ GUESS=rs6000-ibm-aix
668
+ ;;
624669
ibmrt:4.4BSD:*|romp-ibm:4.4BSD:*)
625
- echo romp-ibm-bsd4.4
626
- exit ;;
670
+ GUESS=romp-ibm-bsd4.4
671
+ ;;
627672
ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and
628
- echo romp-ibm-bsd"$UNAME_RELEASE" # 4.3 with uname added to
629
- exit ;; # report: romp-ibm BSD 4.3
673
+ GUESS=romp-ibm-bsd$UNAME_RELEASE # 4.3 with uname added to
674
+ ;; # report: romp-ibm BSD 4.3
630675
*:BOSX:*:*)
631
- echo rs6000-bull-bosx
632
- exit ;;
676
+ GUESS=rs6000-bull-bosx
677
+ ;;
633678
DPX/2?00:B.O.S.:*:*)
634
- echo m68k-bull-sysv3
635
- exit ;;
679
+ GUESS=m68k-bull-sysv3
680
+ ;;
636681
9000/[34]??:4.3bsd:1.*:*)
637
- echo m68k-hp-bsd
638
- exit ;;
682
+ GUESS=m68k-hp-bsd
683
+ ;;
639684
hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*)
640
- echo m68k-hp-bsd4.4
641
- exit ;;
685
+ GUESS=m68k-hp-bsd4.4
686
+ ;;
642687
9000/[34678]??:HP-UX:*:*)
643
- HPUX_REV=`echo "$UNAME_RELEASE"|sed -e 's/[^.]*.[0B]*//'`
644
- case "$UNAME_MACHINE" in
688
+ HPUX_REV=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*.[0B]*//'`
689
+ case $UNAME_MACHINE in
645690
9000/31?) HP_ARCH=m68000 ;;
646691
9000/[34]??) HP_ARCH=m68k ;;
647692
9000/[678][0-9][0-9])
648
- if [ -x /usr/bin/getconf ]; then
693
+ if test -x /usr/bin/getconf; then
649694
sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null`
650695
sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`
651
- case "$sc_cpu_version" in
696
+ case $sc_cpu_version in
652697
523) HP_ARCH=hppa1.0 ;; # CPU_PA_RISC1_0
653698
528) HP_ARCH=hppa1.1 ;; # CPU_PA_RISC1_1
654699
532) # CPU_PA_RISC2_0
655
- case "$sc_kernel_bits" in
700
+ case $sc_kernel_bits in
656701
32) HP_ARCH=hppa2.0n ;;
657702
64) HP_ARCH=hppa2.0w ;;
658703
'') HP_ARCH=hppa2.0 ;; # HP-UX 10.20
659704
esac ;;
660705
esac
661706
fi
662
- if [ "$HP_ARCH" = "" ]; then
663
- eval "$set_cc_for_build"
707
+ if test "$HP_ARCH" = ""; then
708
+ set_cc_for_build
664709
sed 's/^ //' << EOF > "$dummy.c"
665710
666711
#define _HPUX_SOURCE
667712
#include <stdlib.h>
668713
#include <unistd.h>
@@ -696,13 +741,13 @@
696741
EOF
697742
(CCOPTS="" $CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null) && HP_ARCH=`"$dummy"`
698743
test -z "$HP_ARCH" && HP_ARCH=hppa
699744
fi ;;
700745
esac
701
- if [ "$HP_ARCH" = hppa2.0w ]
746
+ if test "$HP_ARCH" = hppa2.0w
702747
then
703
- eval "$set_cc_for_build"
748
+ set_cc_for_build
704749
705750
# hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating
706751
# 32-bit code. hppa64-hp-hpux* has the same kernel and a compiler
707752
# generating 64-bit code. GNU and HP use different nomenclature:
708753
#
@@ -717,18 +762,18 @@
717762
HP_ARCH=hppa2.0w
718763
else
719764
HP_ARCH=hppa64
720765
fi
721766
fi
722
- echo "$HP_ARCH"-hp-hpux"$HPUX_REV"
723
- exit ;;
767
+ GUESS=$HP_ARCH-hp-hpux$HPUX_REV
768
+ ;;
724769
ia64:HP-UX:*:*)
725
- HPUX_REV=`echo "$UNAME_RELEASE"|sed -e 's/[^.]*.[0B]*//'`
726
- echo ia64-hp-hpux"$HPUX_REV"
727
- exit ;;
770
+ HPUX_REV=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*.[0B]*//'`
771
+ GUESS=ia64-hp-hpux$HPUX_REV
772
+ ;;
728773
3050*:HI-UX:*:*)
729
- eval "$set_cc_for_build"
774
+ set_cc_for_build
730775
sed 's/^ //' << EOF > "$dummy.c"
731776
#include <unistd.h>
732777
int
733778
main ()
734779
{
@@ -752,162 +797,186 @@
752797
exit (0);
753798
}
754799
EOF
755800
$CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=`"$dummy"` &&
756801
{ echo "$SYSTEM_NAME"; exit; }
757
- echo unknown-hitachi-hiuxwe2
758
- exit ;;
802
+ GUESS=unknown-hitachi-hiuxwe2
803
+ ;;
759804
9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:*)
760
- echo hppa1.1-hp-bsd
761
- exit ;;
805
+ GUESS=hppa1.1-hp-bsd
806
+ ;;
762807
9000/8??:4.3bsd:*:*)
763
- echo hppa1.0-hp-bsd
764
- exit ;;
808
+ GUESS=hppa1.0-hp-bsd
809
+ ;;
765810
*9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*)
766
- echo hppa1.0-hp-mpeix
767
- exit ;;
811
+ GUESS=hppa1.0-hp-mpeix
812
+ ;;
768813
hp7??:OSF1:*:* | hp8?[79]:OSF1:*:*)
769
- echo hppa1.1-hp-osf
770
- exit ;;
814
+ GUESS=hppa1.1-hp-osf
815
+ ;;
771816
hp8??:OSF1:*:*)
772
- echo hppa1.0-hp-osf
773
- exit ;;
817
+ GUESS=hppa1.0-hp-osf
818
+ ;;
774819
i*86:OSF1:*:*)
775
- if [ -x /usr/sbin/sysversion ] ; then
776
- echo "$UNAME_MACHINE"-unknown-osf1mk
820
+ if test -x /usr/sbin/sysversion ; then
821
+ GUESS=$UNAME_MACHINE-unknown-osf1mk
777822
else
778
- echo "$UNAME_MACHINE"-unknown-osf1
823
+ GUESS=$UNAME_MACHINE-unknown-osf1
779824
fi
780
- exit ;;
825
+ ;;
781826
parisc*:Lites*:*:*)
782
- echo hppa1.1-hp-lites
783
- exit ;;
827
+ GUESS=hppa1.1-hp-lites
828
+ ;;
784829
C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*)
785
- echo c1-convex-bsd
786
- exit ;;
830
+ GUESS=c1-convex-bsd
831
+ ;;
787832
C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*)
788833
if getsysinfo -f scalar_acc
789834
then echo c32-convex-bsd
790835
else echo c2-convex-bsd
791836
fi
792837
exit ;;
793838
C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*)
794
- echo c34-convex-bsd
795
- exit ;;
839
+ GUESS=c34-convex-bsd
840
+ ;;
796841
C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*)
797
- echo c38-convex-bsd
798
- exit ;;
842
+ GUESS=c38-convex-bsd
843
+ ;;
799844
C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*)
800
- echo c4-convex-bsd
801
- exit ;;
845
+ GUESS=c4-convex-bsd
846
+ ;;
802847
CRAY*Y-MP:*:*:*)
803
- echo ymp-cray-unicos"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'
804
- exit ;;
848
+ CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'`
849
+ GUESS=ymp-cray-unicos$CRAY_REL
850
+ ;;
805851
CRAY*[A-Z]90:*:*:*)
806852
echo "$UNAME_MACHINE"-cray-unicos"$UNAME_RELEASE" \
807853
| sed -e 's/CRAY.*\([A-Z]90\)/\1/' \
808854
-e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \
809855
-e 's/\.[^.]*$/.X/'
810856
exit ;;
811857
CRAY*TS:*:*:*)
812
- echo t90-cray-unicos"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'
813
- exit ;;
858
+ CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'`
859
+ GUESS=t90-cray-unicos$CRAY_REL
860
+ ;;
814861
CRAY*T3E:*:*:*)
815
- echo alphaev5-cray-unicosmk"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'
816
- exit ;;
862
+ CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'`
863
+ GUESS=alphaev5-cray-unicosmk$CRAY_REL
864
+ ;;
817865
CRAY*SV1:*:*:*)
818
- echo sv1-cray-unicos"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'
819
- exit ;;
866
+ CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'`
867
+ GUESS=sv1-cray-unicos$CRAY_REL
868
+ ;;
820869
*:UNICOS/mp:*:*)
821
- echo craynv-cray-unicosmp"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'
822
- exit ;;
870
+ CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'`
871
+ GUESS=craynv-cray-unicosmp$CRAY_REL
872
+ ;;
823873
F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*)
824874
FUJITSU_PROC=`uname -m | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`
825875
FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'`
826876
FUJITSU_REL=`echo "$UNAME_RELEASE" | sed -e 's/ /_/'`
827
- echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
828
- exit ;;
877
+ GUESS=${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}
878
+ ;;
829879
5000:UNIX_System_V:4.*:*)
830880
FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'`
831881
FUJITSU_REL=`echo "$UNAME_RELEASE" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/ /_/'`
832
- echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
833
- exit ;;
882
+ GUESS=sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}
883
+ ;;
834884
i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*)
835
- echo "$UNAME_MACHINE"-pc-bsdi"$UNAME_RELEASE"
836
- exit ;;
885
+ GUESS=$UNAME_MACHINE-pc-bsdi$UNAME_RELEASE
886
+ ;;
837887
sparc*:BSD/OS:*:*)
838
- echo sparc-unknown-bsdi"$UNAME_RELEASE"
839
- exit ;;
888
+ GUESS=sparc-unknown-bsdi$UNAME_RELEASE
889
+ ;;
840890
*:BSD/OS:*:*)
841
- echo "$UNAME_MACHINE"-unknown-bsdi"$UNAME_RELEASE"
842
- exit ;;
891
+ GUESS=$UNAME_MACHINE-unknown-bsdi$UNAME_RELEASE
892
+ ;;
893
+ arm:FreeBSD:*:*)
894
+ UNAME_PROCESSOR=`uname -p`
895
+ set_cc_for_build
896
+ if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \
897
+ | grep -q __ARM_PCS_VFP
898
+ then
899
+ FREEBSD_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'`
900
+ GUESS=$UNAME_PROCESSOR-unknown-freebsd$FREEBSD_REL-gnueabi
901
+ else
902
+ FREEBSD_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'`
903
+ GUESS=$UNAME_PROCESSOR-unknown-freebsd$FREEBSD_REL-gnueabihf
904
+ fi
905
+ ;;
843906
*:FreeBSD:*:*)
844907
UNAME_PROCESSOR=`/usr/bin/uname -p`
845
- case "$UNAME_PROCESSOR" in
908
+ case $UNAME_PROCESSOR in
846909
amd64)
847910
UNAME_PROCESSOR=x86_64 ;;
848911
i386)
849912
UNAME_PROCESSOR=i586 ;;
850913
esac
851
- echo "$UNAME_PROCESSOR"-unknown-freebsd"`echo "$UNAME_RELEASE"|sed -e 's/[-(].*//'`"
852
- exit ;;
914
+ FREEBSD_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'`
915
+ GUESS=$UNAME_PROCESSOR-unknown-freebsd$FREEBSD_REL
916
+ ;;
853917
i*:CYGWIN*:*)
854
- echo "$UNAME_MACHINE"-pc-cygwin
855
- exit ;;
918
+ GUESS=$UNAME_MACHINE-pc-cygwin
919
+ ;;
856920
*:MINGW64*:*)
857
- echo "$UNAME_MACHINE"-pc-mingw64
858
- exit ;;
921
+ GUESS=$UNAME_MACHINE-pc-mingw64
922
+ ;;
859923
*:MINGW*:*)
860
- echo "$UNAME_MACHINE"-pc-mingw32
861
- exit ;;
924
+ GUESS=$UNAME_MACHINE-pc-mingw32
925
+ ;;
862926
*:MSYS*:*)
863
- echo "$UNAME_MACHINE"-pc-msys
864
- exit ;;
927
+ GUESS=$UNAME_MACHINE-pc-msys
928
+ ;;
865929
i*:PW*:*)
866
- echo "$UNAME_MACHINE"-pc-pw32
867
- exit ;;
930
+ GUESS=$UNAME_MACHINE-pc-pw32
931
+ ;;
868932
*:Interix*:*)
869
- case "$UNAME_MACHINE" in
933
+ case $UNAME_MACHINE in
870934
x86)
871
- echo i586-pc-interix"$UNAME_RELEASE"
872
- exit ;;
935
+ GUESS=i586-pc-interix$UNAME_RELEASE
936
+ ;;
873937
authenticamd | genuineintel | EM64T)
874
- echo x86_64-unknown-interix"$UNAME_RELEASE"
875
- exit ;;
938
+ GUESS=x86_64-unknown-interix$UNAME_RELEASE
939
+ ;;
876940
IA64)
877
- echo ia64-unknown-interix"$UNAME_RELEASE"
878
- exit ;;
941
+ GUESS=ia64-unknown-interix$UNAME_RELEASE
942
+ ;;
879943
esac ;;
880944
i*:UWIN*:*)
881
- echo "$UNAME_MACHINE"-pc-uwin
882
- exit ;;
945
+ GUESS=$UNAME_MACHINE-pc-uwin
946
+ ;;
883947
amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*)
884
- echo x86_64-unknown-cygwin
885
- exit ;;
948
+ GUESS=x86_64-pc-cygwin
949
+ ;;
886950
prep*:SunOS:5.*:*)
887
- echo powerpcle-unknown-solaris2"`echo "$UNAME_RELEASE"|sed -e 's/[^.]*//'`"
888
- exit ;;
951
+ SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'`
952
+ GUESS=powerpcle-unknown-solaris2$SUN_REL
953
+ ;;
889954
*:GNU:*:*)
890955
# the GNU system
891
- echo "`echo "$UNAME_MACHINE"|sed -e 's,[-/].*$,,'`-unknown-$LIBC`echo "$UNAME_RELEASE"|sed -e 's,/.*$,,'`"
892
- exit ;;
956
+ GNU_ARCH=`echo "$UNAME_MACHINE" | sed -e 's,[-/].*$,,'`
957
+ GNU_REL=`echo "$UNAME_RELEASE" | sed -e 's,/.*$,,'`
958
+ GUESS=$GNU_ARCH-unknown-$LIBC$GNU_REL
959
+ ;;
893960
*:GNU/*:*:*)
894961
# other systems with GNU libc and userland
895
- echo "$UNAME_MACHINE-unknown-`echo "$UNAME_SYSTEM" | sed 's,^[^/]*/,,' | tr "[:upper:]" "[:lower:]"``echo "$UNAME_RELEASE"|sed -e 's/[-(].*//'`-$LIBC"
896
- exit ;;
897
- i*86:Minix:*:*)
898
- echo "$UNAME_MACHINE"-pc-minix
899
- exit ;;
962
+ GNU_SYS=`echo "$UNAME_SYSTEM" | sed 's,^[^/]*/,,' | tr "[:upper:]" "[:lower:]"`
963
+ GNU_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'`
964
+ GUESS=$UNAME_MACHINE-unknown-$GNU_SYS$GNU_REL-$LIBC
965
+ ;;
966
+ *:Minix:*:*)
967
+ GUESS=$UNAME_MACHINE-unknown-minix
968
+ ;;
900969
aarch64:Linux:*:*)
901
- echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
902
- exit ;;
970
+ GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
971
+ ;;
903972
aarch64_be:Linux:*:*)
904973
UNAME_MACHINE=aarch64_be
905
- echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
906
- exit ;;
974
+ GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
975
+ ;;
907976
alpha:Linux:*:*)
908
- case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in
977
+ case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' /proc/cpuinfo 2>/dev/null` in
909978
EV5) UNAME_MACHINE=alphaev5 ;;
910979
EV56) UNAME_MACHINE=alphaev56 ;;
911980
PCA56) UNAME_MACHINE=alphapca56 ;;
912981
PCA57) UNAME_MACHINE=alphapca56 ;;
913982
EV6) UNAME_MACHINE=alphaev6 ;;
@@ -914,246 +983,288 @@
914983
EV67) UNAME_MACHINE=alphaev67 ;;
915984
EV68*) UNAME_MACHINE=alphaev68 ;;
916985
esac
917986
objdump --private-headers /bin/sh | grep -q ld.so.1
918987
if test "$?" = 0 ; then LIBC=gnulibc1 ; fi
919
- echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
920
- exit ;;
921
- arc:Linux:*:* | arceb:Linux:*:*)
922
- echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
923
- exit ;;
988
+ GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
989
+ ;;
990
+ arc:Linux:*:* | arceb:Linux:*:* | arc32:Linux:*:* | arc64:Linux:*:*)
991
+ GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
992
+ ;;
924993
arm*:Linux:*:*)
925
- eval "$set_cc_for_build"
994
+ set_cc_for_build
926995
if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \
927996
| grep -q __ARM_EABI__
928997
then
929
- echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
998
+ GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
930999
else
9311000
if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \
9321001
| grep -q __ARM_PCS_VFP
9331002
then
934
- echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"eabi
1003
+ GUESS=$UNAME_MACHINE-unknown-linux-${LIBC}eabi
9351004
else
936
- echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"eabihf
1005
+ GUESS=$UNAME_MACHINE-unknown-linux-${LIBC}eabihf
9371006
fi
9381007
fi
939
- exit ;;
1008
+ ;;
9401009
avr32*:Linux:*:*)
941
- echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
942
- exit ;;
1010
+ GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
1011
+ ;;
9431012
cris:Linux:*:*)
944
- echo "$UNAME_MACHINE"-axis-linux-"$LIBC"
945
- exit ;;
1013
+ GUESS=$UNAME_MACHINE-axis-linux-$LIBC
1014
+ ;;
9461015
crisv32:Linux:*:*)
947
- echo "$UNAME_MACHINE"-axis-linux-"$LIBC"
948
- exit ;;
1016
+ GUESS=$UNAME_MACHINE-axis-linux-$LIBC
1017
+ ;;
9491018
e2k:Linux:*:*)
950
- echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
951
- exit ;;
1019
+ GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
1020
+ ;;
9521021
frv:Linux:*:*)
953
- echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
954
- exit ;;
1022
+ GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
1023
+ ;;
9551024
hexagon:Linux:*:*)
956
- echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
957
- exit ;;
1025
+ GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
1026
+ ;;
9581027
i*86:Linux:*:*)
959
- echo "$UNAME_MACHINE"-pc-linux-"$LIBC"
960
- exit ;;
1028
+ GUESS=$UNAME_MACHINE-pc-linux-$LIBC
1029
+ ;;
9611030
ia64:Linux:*:*)
962
- echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
963
- exit ;;
1031
+ GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
1032
+ ;;
9641033
k1om:Linux:*:*)
965
- echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
966
- exit ;;
1034
+ GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
1035
+ ;;
1036
+ loongarch32:Linux:*:* | loongarch64:Linux:*:* | loongarchx32:Linux:*:*)
1037
+ GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
1038
+ ;;
9671039
m32r*:Linux:*:*)
968
- echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
969
- exit ;;
1040
+ GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
1041
+ ;;
9701042
m68*:Linux:*:*)
971
- echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
972
- exit ;;
1043
+ GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
1044
+ ;;
9731045
mips:Linux:*:* | mips64:Linux:*:*)
974
- eval "$set_cc_for_build"
1046
+ set_cc_for_build
1047
+ IS_GLIBC=0
1048
+ test x"${LIBC}" = xgnu && IS_GLIBC=1
9751049
sed 's/^ //' << EOF > "$dummy.c"
9761050
#undef CPU
977
- #undef ${UNAME_MACHINE}
978
- #undef ${UNAME_MACHINE}el
1051
+ #undef mips
1052
+ #undef mipsel
1053
+ #undef mips64
1054
+ #undef mips64el
1055
+ #if ${IS_GLIBC} && defined(_ABI64)
1056
+ LIBCABI=gnuabi64
1057
+ #else
1058
+ #if ${IS_GLIBC} && defined(_ABIN32)
1059
+ LIBCABI=gnuabin32
1060
+ #else
1061
+ LIBCABI=${LIBC}
1062
+ #endif
1063
+ #endif
1064
+
1065
+ #if ${IS_GLIBC} && defined(__mips64) && defined(__mips_isa_rev) && __mips_isa_rev>=6
1066
+ CPU=mipsisa64r6
1067
+ #else
1068
+ #if ${IS_GLIBC} && !defined(__mips64) && defined(__mips_isa_rev) && __mips_isa_rev>=6
1069
+ CPU=mipsisa32r6
1070
+ #else
1071
+ #if defined(__mips64)
1072
+ CPU=mips64
1073
+ #else
1074
+ CPU=mips
1075
+ #endif
1076
+ #endif
1077
+ #endif
1078
+
9791079
#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
980
- CPU=${UNAME_MACHINE}el
1080
+ MIPS_ENDIAN=el
9811081
#else
9821082
#if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
983
- CPU=${UNAME_MACHINE}
1083
+ MIPS_ENDIAN=
9841084
#else
985
- CPU=
1085
+ MIPS_ENDIAN=
9861086
#endif
9871087
#endif
9881088
EOF
989
- eval "`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^CPU'`"
990
- test "x$CPU" != x && { echo "$CPU-unknown-linux-$LIBC"; exit; }
1089
+ cc_set_vars=`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^CPU\|^MIPS_ENDIAN\|^LIBCABI'`
1090
+ eval "$cc_set_vars"
1091
+ test "x$CPU" != x && { echo "$CPU${MIPS_ENDIAN}-unknown-linux-$LIBCABI"; exit; }
9911092
;;
9921093
mips64el:Linux:*:*)
993
- echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
994
- exit ;;
1094
+ GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
1095
+ ;;
9951096
openrisc*:Linux:*:*)
996
- echo or1k-unknown-linux-"$LIBC"
997
- exit ;;
1097
+ GUESS=or1k-unknown-linux-$LIBC
1098
+ ;;
9981099
or32:Linux:*:* | or1k*:Linux:*:*)
999
- echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
1000
- exit ;;
1100
+ GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
1101
+ ;;
10011102
padre:Linux:*:*)
1002
- echo sparc-unknown-linux-"$LIBC"
1003
- exit ;;
1103
+ GUESS=sparc-unknown-linux-$LIBC
1104
+ ;;
10041105
parisc64:Linux:*:* | hppa64:Linux:*:*)
1005
- echo hppa64-unknown-linux-"$LIBC"
1006
- exit ;;
1106
+ GUESS=hppa64-unknown-linux-$LIBC
1107
+ ;;
10071108
parisc:Linux:*:* | hppa:Linux:*:*)
10081109
# Look for CPU level
10091110
case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in
1010
- PA7*) echo hppa1.1-unknown-linux-"$LIBC" ;;
1011
- PA8*) echo hppa2.0-unknown-linux-"$LIBC" ;;
1012
- *) echo hppa-unknown-linux-"$LIBC" ;;
1111
+ PA7*) GUESS=hppa1.1-unknown-linux-$LIBC ;;
1112
+ PA8*) GUESS=hppa2.0-unknown-linux-$LIBC ;;
1113
+ *) GUESS=hppa-unknown-linux-$LIBC ;;
10131114
esac
1014
- exit ;;
1115
+ ;;
10151116
ppc64:Linux:*:*)
1016
- echo powerpc64-unknown-linux-"$LIBC"
1017
- exit ;;
1117
+ GUESS=powerpc64-unknown-linux-$LIBC
1118
+ ;;
10181119
ppc:Linux:*:*)
1019
- echo powerpc-unknown-linux-"$LIBC"
1020
- exit ;;
1120
+ GUESS=powerpc-unknown-linux-$LIBC
1121
+ ;;
10211122
ppc64le:Linux:*:*)
1022
- echo powerpc64le-unknown-linux-"$LIBC"
1023
- exit ;;
1123
+ GUESS=powerpc64le-unknown-linux-$LIBC
1124
+ ;;
10241125
ppcle:Linux:*:*)
1025
- echo powerpcle-unknown-linux-"$LIBC"
1026
- exit ;;
1027
- riscv32:Linux:*:* | riscv64:Linux:*:*)
1028
- echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
1029
- exit ;;
1126
+ GUESS=powerpcle-unknown-linux-$LIBC
1127
+ ;;
1128
+ riscv32:Linux:*:* | riscv32be:Linux:*:* | riscv64:Linux:*:* | riscv64be:Linux:*:*)
1129
+ GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
1130
+ ;;
10301131
s390:Linux:*:* | s390x:Linux:*:*)
1031
- echo "$UNAME_MACHINE"-ibm-linux-"$LIBC"
1032
- exit ;;
1132
+ GUESS=$UNAME_MACHINE-ibm-linux-$LIBC
1133
+ ;;
10331134
sh64*:Linux:*:*)
1034
- echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
1035
- exit ;;
1135
+ GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
1136
+ ;;
10361137
sh*:Linux:*:*)
1037
- echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
1038
- exit ;;
1138
+ GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
1139
+ ;;
10391140
sparc:Linux:*:* | sparc64:Linux:*:*)
1040
- echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
1041
- exit ;;
1141
+ GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
1142
+ ;;
10421143
tile*:Linux:*:*)
1043
- echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
1044
- exit ;;
1144
+ GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
1145
+ ;;
10451146
vax:Linux:*:*)
1046
- echo "$UNAME_MACHINE"-dec-linux-"$LIBC"
1047
- exit ;;
1147
+ GUESS=$UNAME_MACHINE-dec-linux-$LIBC
1148
+ ;;
10481149
x86_64:Linux:*:*)
1049
- echo "$UNAME_MACHINE"-pc-linux-"$LIBC"
1050
- exit ;;
1150
+ set_cc_for_build
1151
+ LIBCABI=$LIBC
1152
+ if test "$CC_FOR_BUILD" != no_compiler_found; then
1153
+ if (echo '#ifdef __ILP32__'; echo IS_X32; echo '#endif') | \
1154
+ (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \
1155
+ grep IS_X32 >/dev/null
1156
+ then
1157
+ LIBCABI=${LIBC}x32
1158
+ fi
1159
+ fi
1160
+ GUESS=$UNAME_MACHINE-pc-linux-$LIBCABI
1161
+ ;;
10511162
xtensa*:Linux:*:*)
1052
- echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
1053
- exit ;;
1163
+ GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
1164
+ ;;
10541165
i*86:DYNIX/ptx:4*:*)
10551166
# ptx 4.0 does uname -s correctly, with DYNIX/ptx in there.
10561167
# earlier versions are messed up and put the nodename in both
10571168
# sysname and nodename.
1058
- echo i386-sequent-sysv4
1059
- exit ;;
1169
+ GUESS=i386-sequent-sysv4
1170
+ ;;
10601171
i*86:UNIX_SV:4.2MP:2.*)
10611172
# Unixware is an offshoot of SVR4, but it has its own version
10621173
# number series starting with 2...
10631174
# I am not positive that other SVR4 systems won't match this,
10641175
# I just have to hope. -- rms.
10651176
# Use sysv4.2uw... so that sysv4* matches it.
1066
- echo "$UNAME_MACHINE"-pc-sysv4.2uw"$UNAME_VERSION"
1067
- exit ;;
1177
+ GUESS=$UNAME_MACHINE-pc-sysv4.2uw$UNAME_VERSION
1178
+ ;;
10681179
i*86:OS/2:*:*)
10691180
# If we were able to find `uname', then EMX Unix compatibility
10701181
# is probably installed.
1071
- echo "$UNAME_MACHINE"-pc-os2-emx
1072
- exit ;;
1182
+ GUESS=$UNAME_MACHINE-pc-os2-emx
1183
+ ;;
10731184
i*86:XTS-300:*:STOP)
1074
- echo "$UNAME_MACHINE"-unknown-stop
1075
- exit ;;
1185
+ GUESS=$UNAME_MACHINE-unknown-stop
1186
+ ;;
10761187
i*86:atheos:*:*)
1077
- echo "$UNAME_MACHINE"-unknown-atheos
1078
- exit ;;
1188
+ GUESS=$UNAME_MACHINE-unknown-atheos
1189
+ ;;
10791190
i*86:syllable:*:*)
1080
- echo "$UNAME_MACHINE"-pc-syllable
1081
- exit ;;
1191
+ GUESS=$UNAME_MACHINE-pc-syllable
1192
+ ;;
10821193
i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.[02]*:*)
1083
- echo i386-unknown-lynxos"$UNAME_RELEASE"
1084
- exit ;;
1194
+ GUESS=i386-unknown-lynxos$UNAME_RELEASE
1195
+ ;;
10851196
i*86:*DOS:*:*)
1086
- echo "$UNAME_MACHINE"-pc-msdosdjgpp
1087
- exit ;;
1197
+ GUESS=$UNAME_MACHINE-pc-msdosdjgpp
1198
+ ;;
10881199
i*86:*:4.*:*)
10891200
UNAME_REL=`echo "$UNAME_RELEASE" | sed 's/\/MP$//'`
10901201
if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then
1091
- echo "$UNAME_MACHINE"-univel-sysv"$UNAME_REL"
1202
+ GUESS=$UNAME_MACHINE-univel-sysv$UNAME_REL
10921203
else
1093
- echo "$UNAME_MACHINE"-pc-sysv"$UNAME_REL"
1204
+ GUESS=$UNAME_MACHINE-pc-sysv$UNAME_REL
10941205
fi
1095
- exit ;;
1206
+ ;;
10961207
i*86:*:5:[678]*)
10971208
# UnixWare 7.x, OpenUNIX and OpenServer 6.
10981209
case `/bin/uname -X | grep "^Machine"` in
10991210
*486*) UNAME_MACHINE=i486 ;;
11001211
*Pentium) UNAME_MACHINE=i586 ;;
11011212
*Pent*|*Celeron) UNAME_MACHINE=i686 ;;
11021213
esac
1103
- echo "$UNAME_MACHINE-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}{$UNAME_VERSION}"
1104
- exit ;;
1214
+ GUESS=$UNAME_MACHINE-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION}
1215
+ ;;
11051216
i*86:*:3.2:*)
11061217
if test -f /usr/options/cb.name; then
11071218
UNAME_REL=`sed -n 's/.*Version //p' </usr/options/cb.name`
1108
- echo "$UNAME_MACHINE"-pc-isc"$UNAME_REL"
1219
+ GUESS=$UNAME_MACHINE-pc-isc$UNAME_REL
11091220
elif /bin/uname -X 2>/dev/null >/dev/null ; then
11101221
UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')`
11111222
(/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486
11121223
(/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \
11131224
&& UNAME_MACHINE=i586
11141225
(/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \
11151226
&& UNAME_MACHINE=i686
11161227
(/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \
11171228
&& UNAME_MACHINE=i686
1118
- echo "$UNAME_MACHINE"-pc-sco"$UNAME_REL"
1229
+ GUESS=$UNAME_MACHINE-pc-sco$UNAME_REL
11191230
else
1120
- echo "$UNAME_MACHINE"-pc-sysv32
1231
+ GUESS=$UNAME_MACHINE-pc-sysv32
11211232
fi
1122
- exit ;;
1233
+ ;;
11231234
pc:*:*:*)
11241235
# Left here for compatibility:
11251236
# uname -m prints for DJGPP always 'pc', but it prints nothing about
11261237
# the processor, so we play safe by assuming i586.
11271238
# Note: whatever this is, it MUST be the same as what config.sub
11281239
# prints for the "djgpp" host, or else GDB configure will decide that
11291240
# this is a cross-build.
1130
- echo i586-pc-msdosdjgpp
1131
- exit ;;
1241
+ GUESS=i586-pc-msdosdjgpp
1242
+ ;;
11321243
Intel:Mach:3*:*)
1133
- echo i386-pc-mach3
1134
- exit ;;
1244
+ GUESS=i386-pc-mach3
1245
+ ;;
11351246
paragon:*:*:*)
1136
- echo i860-intel-osf1
1137
- exit ;;
1247
+ GUESS=i860-intel-osf1
1248
+ ;;
11381249
i860:*:4.*:*) # i860-SVR4
11391250
if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then
1140
- echo i860-stardent-sysv"$UNAME_RELEASE" # Stardent Vistra i860-SVR4
1251
+ GUESS=i860-stardent-sysv$UNAME_RELEASE # Stardent Vistra i860-SVR4
11411252
else # Add other i860-SVR4 vendors below as they are discovered.
1142
- echo i860-unknown-sysv"$UNAME_RELEASE" # Unknown i860-SVR4
1253
+ GUESS=i860-unknown-sysv$UNAME_RELEASE # Unknown i860-SVR4
11431254
fi
1144
- exit ;;
1255
+ ;;
11451256
mini*:CTIX:SYS*5:*)
11461257
# "miniframe"
1147
- echo m68010-convergent-sysv
1148
- exit ;;
1258
+ GUESS=m68010-convergent-sysv
1259
+ ;;
11491260
mc68k:UNIX:SYSTEM5:3.51m)
1150
- echo m68k-convergent-sysv
1151
- exit ;;
1261
+ GUESS=m68k-convergent-sysv
1262
+ ;;
11521263
M680?0:D-NIX:5.3:*)
1153
- echo m68k-diab-dnix
1154
- exit ;;
1264
+ GUESS=m68k-diab-dnix
1265
+ ;;
11551266
M68*:*:R3V[5678]*:*)
11561267
test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;;
11571268
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)
11581269
OS_REL=''
11591270
test -r /etc/.relid \
@@ -1174,253 +1285,405 @@
11741285
/bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
11751286
&& { echo i586-ncr-sysv4.3"$OS_REL"; exit; }
11761287
/bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \
11771288
&& { echo i586-ncr-sysv4.3"$OS_REL"; exit; } ;;
11781289
m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*)
1179
- echo m68k-unknown-lynxos"$UNAME_RELEASE"
1180
- exit ;;
1290
+ GUESS=m68k-unknown-lynxos$UNAME_RELEASE
1291
+ ;;
11811292
mc68030:UNIX_System_V:4.*:*)
1182
- echo m68k-atari-sysv4
1183
- exit ;;
1293
+ GUESS=m68k-atari-sysv4
1294
+ ;;
11841295
TSUNAMI:LynxOS:2.*:*)
1185
- echo sparc-unknown-lynxos"$UNAME_RELEASE"
1186
- exit ;;
1296
+ GUESS=sparc-unknown-lynxos$UNAME_RELEASE
1297
+ ;;
11871298
rs6000:LynxOS:2.*:*)
1188
- echo rs6000-unknown-lynxos"$UNAME_RELEASE"
1189
- exit ;;
1299
+ GUESS=rs6000-unknown-lynxos$UNAME_RELEASE
1300
+ ;;
11901301
PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.[02]*:*)
1191
- echo powerpc-unknown-lynxos"$UNAME_RELEASE"
1192
- exit ;;
1302
+ GUESS=powerpc-unknown-lynxos$UNAME_RELEASE
1303
+ ;;
11931304
SM[BE]S:UNIX_SV:*:*)
1194
- echo mips-dde-sysv"$UNAME_RELEASE"
1195
- exit ;;
1305
+ GUESS=mips-dde-sysv$UNAME_RELEASE
1306
+ ;;
11961307
RM*:ReliantUNIX-*:*:*)
1197
- echo mips-sni-sysv4
1198
- exit ;;
1308
+ GUESS=mips-sni-sysv4
1309
+ ;;
11991310
RM*:SINIX-*:*:*)
1200
- echo mips-sni-sysv4
1201
- exit ;;
1311
+ GUESS=mips-sni-sysv4
1312
+ ;;
12021313
*:SINIX-*:*:*)
12031314
if uname -p 2>/dev/null >/dev/null ; then
12041315
UNAME_MACHINE=`(uname -p) 2>/dev/null`
1205
- echo "$UNAME_MACHINE"-sni-sysv4
1316
+ GUESS=$UNAME_MACHINE-sni-sysv4
12061317
else
1207
- echo ns32k-sni-sysv
1318
+ GUESS=ns32k-sni-sysv
12081319
fi
1209
- exit ;;
1320
+ ;;
12101321
PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort
12111322
# says <[email protected]>
1212
- echo i586-unisys-sysv4
1213
- exit ;;
1323
+ GUESS=i586-unisys-sysv4
1324
+ ;;
12141325
*:UNIX_System_V:4*:FTX*)
12151326
# From Gerald Hewes <[email protected]>.
12161327
# How about differentiating between stratus architectures? -djm
1217
- echo hppa1.1-stratus-sysv4
1218
- exit ;;
1328
+ GUESS=hppa1.1-stratus-sysv4
1329
+ ;;
12191330
*:*:*:FTX*)
12201331
# From [email protected].
1221
- echo i860-stratus-sysv4
1222
- exit ;;
1332
+ GUESS=i860-stratus-sysv4
1333
+ ;;
12231334
i*86:VOS:*:*)
12241335
# From [email protected].
1225
- echo "$UNAME_MACHINE"-stratus-vos
1226
- exit ;;
1336
+ GUESS=$UNAME_MACHINE-stratus-vos
1337
+ ;;
12271338
*:VOS:*:*)
12281339
# From [email protected].
1229
- echo hppa1.1-stratus-vos
1230
- exit ;;
1340
+ GUESS=hppa1.1-stratus-vos
1341
+ ;;
12311342
mc68*:A/UX:*:*)
1232
- echo m68k-apple-aux"$UNAME_RELEASE"
1233
- exit ;;
1343
+ GUESS=m68k-apple-aux$UNAME_RELEASE
1344
+ ;;
12341345
news*:NEWS-OS:6*:*)
1235
- echo mips-sony-newsos6
1236
- exit ;;
1346
+ GUESS=mips-sony-newsos6
1347
+ ;;
12371348
R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*)
1238
- if [ -d /usr/nec ]; then
1239
- echo mips-nec-sysv"$UNAME_RELEASE"
1349
+ if test -d /usr/nec; then
1350
+ GUESS=mips-nec-sysv$UNAME_RELEASE
12401351
else
1241
- echo mips-unknown-sysv"$UNAME_RELEASE"
1352
+ GUESS=mips-unknown-sysv$UNAME_RELEASE
12421353
fi
1243
- exit ;;
1354
+ ;;
12441355
BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only.
1245
- echo powerpc-be-beos
1246
- exit ;;
1356
+ GUESS=powerpc-be-beos
1357
+ ;;
12471358
BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only.
1248
- echo powerpc-apple-beos
1249
- exit ;;
1359
+ GUESS=powerpc-apple-beos
1360
+ ;;
12501361
BePC:BeOS:*:*) # BeOS running on Intel PC compatible.
1251
- echo i586-pc-beos
1252
- exit ;;
1362
+ GUESS=i586-pc-beos
1363
+ ;;
12531364
BePC:Haiku:*:*) # Haiku running on Intel PC compatible.
1254
- echo i586-pc-haiku
1255
- exit ;;
1365
+ GUESS=i586-pc-haiku
1366
+ ;;
12561367
x86_64:Haiku:*:*)
1257
- echo x86_64-unknown-haiku
1258
- exit ;;
1368
+ GUESS=x86_64-unknown-haiku
1369
+ ;;
12591370
SX-4:SUPER-UX:*:*)
1260
- echo sx4-nec-superux"$UNAME_RELEASE"
1261
- exit ;;
1371
+ GUESS=sx4-nec-superux$UNAME_RELEASE
1372
+ ;;
12621373
SX-5:SUPER-UX:*:*)
1263
- echo sx5-nec-superux"$UNAME_RELEASE"
1264
- exit ;;
1374
+ GUESS=sx5-nec-superux$UNAME_RELEASE
1375
+ ;;
12651376
SX-6:SUPER-UX:*:*)
1266
- echo sx6-nec-superux"$UNAME_RELEASE"
1267
- exit ;;
1377
+ GUESS=sx6-nec-superux$UNAME_RELEASE
1378
+ ;;
12681379
SX-7:SUPER-UX:*:*)
1269
- echo sx7-nec-superux"$UNAME_RELEASE"
1270
- exit ;;
1380
+ GUESS=sx7-nec-superux$UNAME_RELEASE
1381
+ ;;
12711382
SX-8:SUPER-UX:*:*)
1272
- echo sx8-nec-superux"$UNAME_RELEASE"
1273
- exit ;;
1383
+ GUESS=sx8-nec-superux$UNAME_RELEASE
1384
+ ;;
12741385
SX-8R:SUPER-UX:*:*)
1275
- echo sx8r-nec-superux"$UNAME_RELEASE"
1276
- exit ;;
1386
+ GUESS=sx8r-nec-superux$UNAME_RELEASE
1387
+ ;;
12771388
SX-ACE:SUPER-UX:*:*)
1278
- echo sxace-nec-superux"$UNAME_RELEASE"
1279
- exit ;;
1389
+ GUESS=sxace-nec-superux$UNAME_RELEASE
1390
+ ;;
12801391
Power*:Rhapsody:*:*)
1281
- echo powerpc-apple-rhapsody"$UNAME_RELEASE"
1282
- exit ;;
1392
+ GUESS=powerpc-apple-rhapsody$UNAME_RELEASE
1393
+ ;;
12831394
*:Rhapsody:*:*)
1284
- echo "$UNAME_MACHINE"-apple-rhapsody"$UNAME_RELEASE"
1285
- exit ;;
1395
+ GUESS=$UNAME_MACHINE-apple-rhapsody$UNAME_RELEASE
1396
+ ;;
1397
+ arm64:Darwin:*:*)
1398
+ GUESS=aarch64-apple-darwin$UNAME_RELEASE
1399
+ ;;
12861400
*:Darwin:*:*)
1287
- UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown
1288
- eval "$set_cc_for_build"
1289
- if test "$UNAME_PROCESSOR" = unknown ; then
1290
- UNAME_PROCESSOR=powerpc
1291
- fi
1292
- if test "`echo "$UNAME_RELEASE" | sed -e 's/\..*//'`" -le 10 ; then
1293
- if [ "$CC_FOR_BUILD" != no_compiler_found ]; then
1294
- if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \
1295
- (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \
1296
- grep IS_64BIT_ARCH >/dev/null
1297
- then
1298
- case $UNAME_PROCESSOR in
1299
- i386) UNAME_PROCESSOR=x86_64 ;;
1300
- powerpc) UNAME_PROCESSOR=powerpc64 ;;
1301
- esac
1302
- fi
1303
- # On 10.4-10.6 one might compile for PowerPC via gcc -arch ppc
1304
- if (echo '#ifdef __POWERPC__'; echo IS_PPC; echo '#endif') | \
1305
- (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \
1306
- grep IS_PPC >/dev/null
1307
- then
1308
- UNAME_PROCESSOR=powerpc
1309
- fi
1401
+ UNAME_PROCESSOR=`uname -p`
1402
+ case $UNAME_PROCESSOR in
1403
+ unknown) UNAME_PROCESSOR=powerpc ;;
1404
+ esac
1405
+ if command -v xcode-select > /dev/null 2> /dev/null && \
1406
+ ! xcode-select --print-path > /dev/null 2> /dev/null ; then
1407
+ # Avoid executing cc if there is no toolchain installed as
1408
+ # cc will be a stub that puts up a graphical alert
1409
+ # prompting the user to install developer tools.
1410
+ CC_FOR_BUILD=no_compiler_found
1411
+ else
1412
+ set_cc_for_build
1413
+ fi
1414
+ if test "$CC_FOR_BUILD" != no_compiler_found; then
1415
+ if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \
1416
+ (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \
1417
+ grep IS_64BIT_ARCH >/dev/null
1418
+ then
1419
+ case $UNAME_PROCESSOR in
1420
+ i386) UNAME_PROCESSOR=x86_64 ;;
1421
+ powerpc) UNAME_PROCESSOR=powerpc64 ;;
1422
+ esac
1423
+ fi
1424
+ # On 10.4-10.6 one might compile for PowerPC via gcc -arch ppc
1425
+ if (echo '#ifdef __POWERPC__'; echo IS_PPC; echo '#endif') | \
1426
+ (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \
1427
+ grep IS_PPC >/dev/null
1428
+ then
1429
+ UNAME_PROCESSOR=powerpc
13101430
fi
13111431
elif test "$UNAME_PROCESSOR" = i386 ; then
1312
- # Avoid executing cc on OS X 10.9, as it ships with a stub
1313
- # that puts up a graphical alert prompting to install
1314
- # developer tools. Any system running Mac OS X 10.7 or
1315
- # later (Darwin 11 and later) is required to have a 64-bit
1316
- # processor. This is not true of the ARM version of Darwin
1317
- # that Apple uses in portable devices.
1318
- UNAME_PROCESSOR=x86_64
1432
+ # uname -m returns i386 or x86_64
1433
+ UNAME_PROCESSOR=$UNAME_MACHINE
13191434
fi
1320
- echo "$UNAME_PROCESSOR"-apple-darwin"$UNAME_RELEASE"
1321
- exit ;;
1435
+ GUESS=$UNAME_PROCESSOR-apple-darwin$UNAME_RELEASE
1436
+ ;;
13221437
*:procnto*:*:* | *:QNX:[0123456789]*:*)
13231438
UNAME_PROCESSOR=`uname -p`
13241439
if test "$UNAME_PROCESSOR" = x86; then
13251440
UNAME_PROCESSOR=i386
13261441
UNAME_MACHINE=pc
13271442
fi
1328
- echo "$UNAME_PROCESSOR"-"$UNAME_MACHINE"-nto-qnx"$UNAME_RELEASE"
1329
- exit ;;
1443
+ GUESS=$UNAME_PROCESSOR-$UNAME_MACHINE-nto-qnx$UNAME_RELEASE
1444
+ ;;
13301445
*:QNX:*:4*)
1331
- echo i386-pc-qnx
1332
- exit ;;
1446
+ GUESS=i386-pc-qnx
1447
+ ;;
13331448
NEO-*:NONSTOP_KERNEL:*:*)
1334
- echo neo-tandem-nsk"$UNAME_RELEASE"
1335
- exit ;;
1449
+ GUESS=neo-tandem-nsk$UNAME_RELEASE
1450
+ ;;
13361451
NSE-*:NONSTOP_KERNEL:*:*)
1337
- echo nse-tandem-nsk"$UNAME_RELEASE"
1338
- exit ;;
1452
+ GUESS=nse-tandem-nsk$UNAME_RELEASE
1453
+ ;;
13391454
NSR-*:NONSTOP_KERNEL:*:*)
1340
- echo nsr-tandem-nsk"$UNAME_RELEASE"
1341
- exit ;;
1455
+ GUESS=nsr-tandem-nsk$UNAME_RELEASE
1456
+ ;;
13421457
NSV-*:NONSTOP_KERNEL:*:*)
1343
- echo nsv-tandem-nsk"$UNAME_RELEASE"
1344
- exit ;;
1458
+ GUESS=nsv-tandem-nsk$UNAME_RELEASE
1459
+ ;;
13451460
NSX-*:NONSTOP_KERNEL:*:*)
1346
- echo nsx-tandem-nsk"$UNAME_RELEASE"
1347
- exit ;;
1461
+ GUESS=nsx-tandem-nsk$UNAME_RELEASE
1462
+ ;;
13481463
*:NonStop-UX:*:*)
1349
- echo mips-compaq-nonstopux
1350
- exit ;;
1464
+ GUESS=mips-compaq-nonstopux
1465
+ ;;
13511466
BS2000:POSIX*:*:*)
1352
- echo bs2000-siemens-sysv
1353
- exit ;;
1467
+ GUESS=bs2000-siemens-sysv
1468
+ ;;
13541469
DS/*:UNIX_System_V:*:*)
1355
- echo "$UNAME_MACHINE"-"$UNAME_SYSTEM"-"$UNAME_RELEASE"
1356
- exit ;;
1470
+ GUESS=$UNAME_MACHINE-$UNAME_SYSTEM-$UNAME_RELEASE
1471
+ ;;
13571472
*:Plan9:*:*)
13581473
# "uname -m" is not consistent, so use $cputype instead. 386
13591474
# is converted to i386 for consistency with other x86
13601475
# operating systems.
1361
- if test "$cputype" = 386; then
1476
+ if test "${cputype-}" = 386; then
13621477
UNAME_MACHINE=i386
1363
- else
1364
- UNAME_MACHINE="$cputype"
1478
+ elif test "x${cputype-}" != x; then
1479
+ UNAME_MACHINE=$cputype
13651480
fi
1366
- echo "$UNAME_MACHINE"-unknown-plan9
1367
- exit ;;
1481
+ GUESS=$UNAME_MACHINE-unknown-plan9
1482
+ ;;
13681483
*:TOPS-10:*:*)
1369
- echo pdp10-unknown-tops10
1370
- exit ;;
1484
+ GUESS=pdp10-unknown-tops10
1485
+ ;;
13711486
*:TENEX:*:*)
1372
- echo pdp10-unknown-tenex
1373
- exit ;;
1487
+ GUESS=pdp10-unknown-tenex
1488
+ ;;
13741489
KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*)
1375
- echo pdp10-dec-tops20
1376
- exit ;;
1490
+ GUESS=pdp10-dec-tops20
1491
+ ;;
13771492
XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*)
1378
- echo pdp10-xkl-tops20
1379
- exit ;;
1493
+ GUESS=pdp10-xkl-tops20
1494
+ ;;
13801495
*:TOPS-20:*:*)
1381
- echo pdp10-unknown-tops20
1382
- exit ;;
1496
+ GUESS=pdp10-unknown-tops20
1497
+ ;;
13831498
*:ITS:*:*)
1384
- echo pdp10-unknown-its
1385
- exit ;;
1499
+ GUESS=pdp10-unknown-its
1500
+ ;;
13861501
SEI:*:*:SEIUX)
1387
- echo mips-sei-seiux"$UNAME_RELEASE"
1388
- exit ;;
1502
+ GUESS=mips-sei-seiux$UNAME_RELEASE
1503
+ ;;
13891504
*:DragonFly:*:*)
1390
- echo "$UNAME_MACHINE"-unknown-dragonfly"`echo "$UNAME_RELEASE"|sed -e 's/[-(].*//'`"
1391
- exit ;;
1505
+ DRAGONFLY_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'`
1506
+ GUESS=$UNAME_MACHINE-unknown-dragonfly$DRAGONFLY_REL
1507
+ ;;
13921508
*:*VMS:*:*)
13931509
UNAME_MACHINE=`(uname -p) 2>/dev/null`
1394
- case "$UNAME_MACHINE" in
1395
- A*) echo alpha-dec-vms ; exit ;;
1396
- I*) echo ia64-dec-vms ; exit ;;
1397
- V*) echo vax-dec-vms ; exit ;;
1510
+ case $UNAME_MACHINE in
1511
+ A*) GUESS=alpha-dec-vms ;;
1512
+ I*) GUESS=ia64-dec-vms ;;
1513
+ V*) GUESS=vax-dec-vms ;;
13981514
esac ;;
13991515
*:XENIX:*:SysV)
1400
- echo i386-pc-xenix
1401
- exit ;;
1516
+ GUESS=i386-pc-xenix
1517
+ ;;
14021518
i*86:skyos:*:*)
1403
- echo "$UNAME_MACHINE"-pc-skyos"`echo "$UNAME_RELEASE" | sed -e 's/ .*$//'`"
1404
- exit ;;
1519
+ SKYOS_REL=`echo "$UNAME_RELEASE" | sed -e 's/ .*$//'`
1520
+ GUESS=$UNAME_MACHINE-pc-skyos$SKYOS_REL
1521
+ ;;
14051522
i*86:rdos:*:*)
1406
- echo "$UNAME_MACHINE"-pc-rdos
1407
- exit ;;
1408
- i*86:AROS:*:*)
1409
- echo "$UNAME_MACHINE"-pc-aros
1410
- exit ;;
1523
+ GUESS=$UNAME_MACHINE-pc-rdos
1524
+ ;;
1525
+ *:AROS:*:*)
1526
+ GUESS=$UNAME_MACHINE-unknown-aros
1527
+ ;;
14111528
x86_64:VMkernel:*:*)
1412
- echo "$UNAME_MACHINE"-unknown-esx
1413
- exit ;;
1529
+ GUESS=$UNAME_MACHINE-unknown-esx
1530
+ ;;
14141531
amd64:Isilon\ OneFS:*:*)
1415
- echo x86_64-unknown-onefs
1416
- exit ;;
1532
+ GUESS=x86_64-unknown-onefs
1533
+ ;;
1534
+ *:Unleashed:*:*)
1535
+ GUESS=$UNAME_MACHINE-unknown-unleashed$UNAME_RELEASE
1536
+ ;;
14171537
esac
14181538
1539
+# Do we have a guess based on uname results?
1540
+if test "x$GUESS" != x; then
1541
+ echo "$GUESS"
1542
+ exit
1543
+fi
1544
+
1545
+# No uname command or uname output not recognized.
1546
+set_cc_for_build
1547
+cat > "$dummy.c" <<EOF
1548
+#ifdef _SEQUENT_
1549
+#include <sys/types.h>
1550
+#include <sys/utsname.h>
1551
+#endif
1552
+#if defined(ultrix) || defined(_ultrix) || defined(__ultrix) || defined(__ultrix__)
1553
+#if defined (vax) || defined (__vax) || defined (__vax__) || defined(mips) || defined(__mips) || defined(__mips__) || defined(MIPS) || defined(__MIPS__)
1554
+#include <signal.h>
1555
+#if defined(_SIZE_T_) || defined(SIGLOST)
1556
+#include <sys/utsname.h>
1557
+#endif
1558
+#endif
1559
+#endif
1560
+main ()
1561
+{
1562
+#if defined (sony)
1563
+#if defined (MIPSEB)
1564
+ /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed,
1565
+ I don't know.... */
1566
+ printf ("mips-sony-bsd\n"); exit (0);
1567
+#else
1568
+#include <sys/param.h>
1569
+ printf ("m68k-sony-newsos%s\n",
1570
+#ifdef NEWSOS4
1571
+ "4"
1572
+#else
1573
+ ""
1574
+#endif
1575
+ ); exit (0);
1576
+#endif
1577
+#endif
1578
+
1579
+#if defined (NeXT)
1580
+#if !defined (__ARCHITECTURE__)
1581
+#define __ARCHITECTURE__ "m68k"
1582
+#endif
1583
+ int version;
1584
+ version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`;
1585
+ if (version < 4)
1586
+ printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version);
1587
+ else
1588
+ printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version);
1589
+ exit (0);
1590
+#endif
1591
+
1592
+#if defined (MULTIMAX) || defined (n16)
1593
+#if defined (UMAXV)
1594
+ printf ("ns32k-encore-sysv\n"); exit (0);
1595
+#else
1596
+#if defined (CMU)
1597
+ printf ("ns32k-encore-mach\n"); exit (0);
1598
+#else
1599
+ printf ("ns32k-encore-bsd\n"); exit (0);
1600
+#endif
1601
+#endif
1602
+#endif
1603
+
1604
+#if defined (__386BSD__)
1605
+ printf ("i386-pc-bsd\n"); exit (0);
1606
+#endif
1607
+
1608
+#if defined (sequent)
1609
+#if defined (i386)
1610
+ printf ("i386-sequent-dynix\n"); exit (0);
1611
+#endif
1612
+#if defined (ns32000)
1613
+ printf ("ns32k-sequent-dynix\n"); exit (0);
1614
+#endif
1615
+#endif
1616
+
1617
+#if defined (_SEQUENT_)
1618
+ struct utsname un;
1619
+
1620
+ uname(&un);
1621
+ if (strncmp(un.version, "V2", 2) == 0) {
1622
+ printf ("i386-sequent-ptx2\n"); exit (0);
1623
+ }
1624
+ if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */
1625
+ printf ("i386-sequent-ptx1\n"); exit (0);
1626
+ }
1627
+ printf ("i386-sequent-ptx\n"); exit (0);
1628
+#endif
1629
+
1630
+#if defined (vax)
1631
+#if !defined (ultrix)
1632
+#include <sys/param.h>
1633
+#if defined (BSD)
1634
+#if BSD == 43
1635
+ printf ("vax-dec-bsd4.3\n"); exit (0);
1636
+#else
1637
+#if BSD == 199006
1638
+ printf ("vax-dec-bsd4.3reno\n"); exit (0);
1639
+#else
1640
+ printf ("vax-dec-bsd\n"); exit (0);
1641
+#endif
1642
+#endif
1643
+#else
1644
+ printf ("vax-dec-bsd\n"); exit (0);
1645
+#endif
1646
+#else
1647
+#if defined(_SIZE_T_) || defined(SIGLOST)
1648
+ struct utsname un;
1649
+ uname (&un);
1650
+ printf ("vax-dec-ultrix%s\n", un.release); exit (0);
1651
+#else
1652
+ printf ("vax-dec-ultrix\n"); exit (0);
1653
+#endif
1654
+#endif
1655
+#endif
1656
+#if defined(ultrix) || defined(_ultrix) || defined(__ultrix) || defined(__ultrix__)
1657
+#if defined(mips) || defined(__mips) || defined(__mips__) || defined(MIPS) || defined(__MIPS__)
1658
+#if defined(_SIZE_T_) || defined(SIGLOST)
1659
+ struct utsname *un;
1660
+ uname (&un);
1661
+ printf ("mips-dec-ultrix%s\n", un.release); exit (0);
1662
+#else
1663
+ printf ("mips-dec-ultrix\n"); exit (0);
1664
+#endif
1665
+#endif
1666
+#endif
1667
+
1668
+#if defined (alliant) && defined (i860)
1669
+ printf ("i860-alliant-bsd\n"); exit (0);
1670
+#endif
1671
+
1672
+ exit (1);
1673
+}
1674
+EOF
1675
+
1676
+$CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null && SYSTEM_NAME=`"$dummy"` &&
1677
+ { echo "$SYSTEM_NAME"; exit; }
1678
+
1679
+# Apollos put the system type in the environment.
1680
+test -d /usr/apollo && { echo "$ISP-apollo-$SYSTYPE"; exit; }
1681
+
14191682
echo "$0: unable to guess system type" >&2
14201683
1421
-case "$UNAME_MACHINE:$UNAME_SYSTEM" in
1684
+case $UNAME_MACHINE:$UNAME_SYSTEM in
14221685
mips:Linux | mips64:Linux)
14231686
# If we got here on MIPS GNU/Linux, output extra information.
14241687
cat >&2 <<EOF
14251688
14261689
NOTE: MIPS GNU/Linux systems require a C compiler to fully recognize
@@ -1433,13 +1696,21 @@
14331696
14341697
This script (version $timestamp), has failed to recognize the
14351698
operating system you are using. If your script is old, overwrite *all*
14361699
copies of config.guess and config.sub with the latest versions from:
14371700
1438
- https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess
1701
+ https://git.savannah.gnu.org/cgit/config.git/plain/config.guess
14391702
and
1440
- https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub
1703
+ https://git.savannah.gnu.org/cgit/config.git/plain/config.sub
1704
+EOF
1705
+
1706
+our_year=`echo $timestamp | sed 's,-.*,,'`
1707
+thisyear=`date +%Y`
1708
+# shellcheck disable=SC2003
1709
+script_age=`expr "$thisyear" - "$our_year"`
1710
+if test "$script_age" -lt 3 ; then
1711
+ cat >&2 <<EOF
14411712
14421713
If $0 has already been updated, send the following data and any
14431714
information you think might be pertinent to [email protected] to
14441715
provide the necessary information to handle your system.
14451716
@@ -1463,14 +1734,15 @@
14631734
UNAME_MACHINE = "$UNAME_MACHINE"
14641735
UNAME_RELEASE = "$UNAME_RELEASE"
14651736
UNAME_SYSTEM = "$UNAME_SYSTEM"
14661737
UNAME_VERSION = "$UNAME_VERSION"
14671738
EOF
1739
+fi
14681740
14691741
exit 1
14701742
14711743
# Local variables:
14721744
# eval: (add-hook 'before-save-hook 'time-stamp)
14731745
# time-stamp-start: "timestamp='"
14741746
# time-stamp-format: "%:y-%02m-%02d"
14751747
# time-stamp-end: "'"
14761748
# End:
14771749
--- autosetup/autosetup-config.guess
+++ autosetup/autosetup-config.guess
@@ -1,10 +1,12 @@
1 #! /bin/sh
2 # Attempt to guess a canonical system name.
3 # Copyright 1992-2018 Free Software Foundation, Inc.
4
5 timestamp='2018-03-08'
 
 
6
7 # This file is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
@@ -25,14 +27,22 @@
25 # of the GNU General Public License, version 3 ("GPLv3").
26 #
27 # Originally written by Per Bothner; maintained since 2000 by Ben Elliston.
28 #
29 # You can get the latest version of this script from:
30 # https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess
31 #
32 # Please send patches to <[email protected]>.
33
 
 
 
 
 
 
 
 
34
35 me=`echo "$0" | sed -e 's,.*/,,'`
36
37 usage="\
38 Usage: $0 [OPTION]
@@ -48,11 +58,11 @@
48
49 version="\
50 GNU config.guess ($timestamp)
51
52 Originally written by Per Bothner.
53 Copyright 1992-2018 Free Software Foundation, Inc.
54
55 This is free software; see the source for copying conditions. There is NO
56 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
57
58 help="
@@ -82,11 +92,12 @@
82 if test $# != 0; then
83 echo "$me: too many arguments$help" >&2
84 exit 1
85 fi
86
87 trap 'exit 1' 1 2 15
 
88
89 # CC_FOR_BUILD -- compiler used by this script. Note that the use of a
90 # compiler to aid in system detection is discouraged as it requires
91 # temporary files to be created and, as you can see below, it is a
92 # headache to deal with in a portable fashion.
@@ -94,77 +105,94 @@
94 # Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still
95 # use `HOST_CC' if defined, but it is deprecated.
96
97 # Portable tmp directory creation inspired by the Autoconf team.
98
99 set_cc_for_build='
100 trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ;
101 trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ;
102 : ${TMPDIR=/tmp} ;
103 { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
104 { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } ||
105 { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } ||
106 { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ;
107 dummy=$tmp/dummy ;
108 tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ;
109 case $CC_FOR_BUILD,$HOST_CC,$CC in
110 ,,) echo "int x;" > "$dummy.c" ;
111 for c in cc gcc c89 c99 ; do
112 if ($c -c -o "$dummy.o" "$dummy.c") >/dev/null 2>&1 ; then
113 CC_FOR_BUILD="$c"; break ;
114 fi ;
115 done ;
116 if test x"$CC_FOR_BUILD" = x ; then
117 CC_FOR_BUILD=no_compiler_found ;
118 fi
119 ;;
120 ,,*) CC_FOR_BUILD=$CC ;;
121 ,*,*) CC_FOR_BUILD=$HOST_CC ;;
122 esac ; set_cc_for_build= ;'
 
 
 
 
 
 
123
124 # This is needed to find uname on a Pyramid OSx when run in the BSD universe.
125 # ([email protected] 1994-08-24)
126 if (test -f /.attbin/uname) >/dev/null 2>&1 ; then
127 PATH=$PATH:/.attbin ; export PATH
128 fi
129
130 UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown
131 UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown
132 UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown
133 UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown
134
135 case "$UNAME_SYSTEM" in
136 Linux|GNU|GNU/*)
137 # If the system lacks a compiler, then just pick glibc.
138 # We could probably try harder.
139 LIBC=gnu
140
141 eval "$set_cc_for_build"
142 cat <<-EOF > "$dummy.c"
143 #include <features.h>
144 #if defined(__UCLIBC__)
145 LIBC=uclibc
146 #elif defined(__dietlibc__)
147 LIBC=dietlibc
148 #else
149 LIBC=gnu
 
 
 
 
 
 
150 #endif
151 EOF
152 eval "`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^LIBC' | sed 's, ,,g'`"
 
 
 
 
 
 
 
 
153
154 # If ldd exists, use it to detect musl libc.
155 if command -v ldd >/dev/null && \
156 ldd --version 2>&1 | grep -q ^musl
157 then
158 LIBC=musl
159 fi
160 ;;
161 esac
162
163 # Note: order is significant - the case branches are not exclusive.
164
165 case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in
166 *:NetBSD:*:*)
167 # NetBSD (nbsd) targets should (where applicable) match one or
168 # more of the tuples: *-*-netbsdelf*, *-*-netbsdaout*,
169 # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently
170 # switched to ELF, *-*-netbsd* would select the old
@@ -172,36 +200,36 @@
172 # compatibility and a consistent mechanism for selecting the
173 # object file format.
174 #
175 # Note: NetBSD doesn't particularly care about the vendor
176 # portion of the name. We always set it to "unknown".
177 sysctl="sysctl -n hw.machine_arch"
178 UNAME_MACHINE_ARCH=`(uname -p 2>/dev/null || \
179 "/sbin/$sysctl" 2>/dev/null || \
180 "/usr/sbin/$sysctl" 2>/dev/null || \
181 echo unknown)`
182 case "$UNAME_MACHINE_ARCH" in
 
183 armeb) machine=armeb-unknown ;;
184 arm*) machine=arm-unknown ;;
185 sh3el) machine=shl-unknown ;;
186 sh3eb) machine=sh-unknown ;;
187 sh5el) machine=sh5le-unknown ;;
188 earmv*)
189 arch=`echo "$UNAME_MACHINE_ARCH" | sed -e 's,^e\(armv[0-9]\).*$,\1,'`
190 endian=`echo "$UNAME_MACHINE_ARCH" | sed -ne 's,^.*\(eb\)$,\1,p'`
191 machine="${arch}${endian}"-unknown
192 ;;
193 *) machine="$UNAME_MACHINE_ARCH"-unknown ;;
194 esac
195 # The Operating System including object format, if it has switched
196 # to ELF recently (or will in the future) and ABI.
197 case "$UNAME_MACHINE_ARCH" in
198 earm*)
199 os=netbsdelf
200 ;;
201 arm*|i386|m68k|ns32k|sh3*|sparc|vax)
202 eval "$set_cc_for_build"
203 if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \
204 | grep -q __ELF__
205 then
206 # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout).
207 # Return netbsd for either. FIX?
@@ -213,11 +241,11 @@
213 *)
214 os=netbsd
215 ;;
216 esac
217 # Determine ABI tags.
218 case "$UNAME_MACHINE_ARCH" in
219 earm*)
220 expr='s/^earmv[0-9]/-eabi/;s/eb$//'
221 abi=`echo "$UNAME_MACHINE_ARCH" | sed -e "$expr"`
222 ;;
223 esac
@@ -224,11 +252,11 @@
224 # The OS release
225 # Debian GNU/NetBSD machines have a different userland, and
226 # thus, need a distinct triplet. However, they do not need
227 # kernel version information, so it can be replaced with a
228 # suitable tag, in the style of linux-gnu.
229 case "$UNAME_VERSION" in
230 Debian*)
231 release='-gnu'
232 ;;
233 *)
234 release=`echo "$UNAME_RELEASE" | sed -e 's/[-_].*//' | cut -d. -f1,2`
@@ -235,49 +263,61 @@
235 ;;
236 esac
237 # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM:
238 # contains redundant information, the shorter form:
239 # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used.
240 echo "$machine-${os}${release}${abi}"
241 exit ;;
242 *:Bitrig:*:*)
243 UNAME_MACHINE_ARCH=`arch | sed 's/Bitrig.//'`
244 echo "$UNAME_MACHINE_ARCH"-unknown-bitrig"$UNAME_RELEASE"
245 exit ;;
246 *:OpenBSD:*:*)
247 UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'`
248 echo "$UNAME_MACHINE_ARCH"-unknown-openbsd"$UNAME_RELEASE"
249 exit ;;
 
 
 
 
250 *:LibertyBSD:*:*)
251 UNAME_MACHINE_ARCH=`arch | sed 's/^.*BSD\.//'`
252 echo "$UNAME_MACHINE_ARCH"-unknown-libertybsd"$UNAME_RELEASE"
253 exit ;;
254 *:MidnightBSD:*:*)
255 echo "$UNAME_MACHINE"-unknown-midnightbsd"$UNAME_RELEASE"
256 exit ;;
257 *:ekkoBSD:*:*)
258 echo "$UNAME_MACHINE"-unknown-ekkobsd"$UNAME_RELEASE"
259 exit ;;
260 *:SolidBSD:*:*)
261 echo "$UNAME_MACHINE"-unknown-solidbsd"$UNAME_RELEASE"
262 exit ;;
 
 
 
263 macppc:MirBSD:*:*)
264 echo powerpc-unknown-mirbsd"$UNAME_RELEASE"
265 exit ;;
266 *:MirBSD:*:*)
267 echo "$UNAME_MACHINE"-unknown-mirbsd"$UNAME_RELEASE"
268 exit ;;
269 *:Sortix:*:*)
270 echo "$UNAME_MACHINE"-unknown-sortix
271 exit ;;
 
 
 
272 *:Redox:*:*)
273 echo "$UNAME_MACHINE"-unknown-redox
274 exit ;;
275 mips:OSF1:*.*)
276 echo mips-dec-osf1
277 exit ;;
278 alpha:OSF1:*:*)
 
 
279 case $UNAME_RELEASE in
280 *4.0)
281 UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'`
282 ;;
283 *5.*)
@@ -287,11 +327,11 @@
287 # According to Compaq, /usr/sbin/psrinfo has been available on
288 # OSF/1 and Tru64 systems produced since 1995. I hope that
289 # covers most systems running today. This code pipes the CPU
290 # types through head -n 1, so we only detect the type of CPU 0.
291 ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1`
292 case "$ALPHA_CPU_TYPE" in
293 "EV4 (21064)")
294 UNAME_MACHINE=alpha ;;
295 "EV4.5 (21064)")
296 UNAME_MACHINE=alpha ;;
297 "LCA4 (21066/21068)")
@@ -324,167 +364,171 @@
324 # A Pn.n version is a patched version.
325 # A Vn.n version is a released version.
326 # A Tn.n version is a released field test version.
327 # A Xn.n version is an unreleased experimental baselevel.
328 # 1.2 uses "1.2" for uname -r.
329 echo "$UNAME_MACHINE"-dec-osf"`echo "$UNAME_RELEASE" | sed -e 's/^[PVTX]//' | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`"
330 # Reset EXIT trap before exiting to avoid spurious non-zero exit code.
331 exitcode=$?
332 trap '' 0
333 exit $exitcode ;;
334 Amiga*:UNIX_System_V:4.0:*)
335 echo m68k-unknown-sysv4
336 exit ;;
337 *:[Aa]miga[Oo][Ss]:*:*)
338 echo "$UNAME_MACHINE"-unknown-amigaos
339 exit ;;
340 *:[Mm]orph[Oo][Ss]:*:*)
341 echo "$UNAME_MACHINE"-unknown-morphos
342 exit ;;
343 *:OS/390:*:*)
344 echo i370-ibm-openedition
345 exit ;;
346 *:z/VM:*:*)
347 echo s390-ibm-zvmoe
348 exit ;;
349 *:OS400:*:*)
350 echo powerpc-ibm-os400
351 exit ;;
352 arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
353 echo arm-acorn-riscix"$UNAME_RELEASE"
354 exit ;;
355 arm*:riscos:*:*|arm*:RISCOS:*:*)
356 echo arm-unknown-riscos
357 exit ;;
358 SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*)
359 echo hppa1.1-hitachi-hiuxmpp
360 exit ;;
361 Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*)
362 # [email protected] (Earle F. Ake) contributed MIS and NILE.
363 if test "`(/bin/universe) 2>/dev/null`" = att ; then
364 echo pyramid-pyramid-sysv3
365 else
366 echo pyramid-pyramid-bsd
367 fi
368 exit ;;
369 NILE*:*:*:dcosx)
370 echo pyramid-pyramid-svr4
371 exit ;;
372 DRS?6000:unix:4.0:6*)
373 echo sparc-icl-nx6
374 exit ;;
375 DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*)
376 case `/usr/bin/uname -p` in
377 sparc) echo sparc-icl-nx7; exit ;;
378 esac ;;
 
379 s390x:SunOS:*:*)
380 echo "$UNAME_MACHINE"-ibm-solaris2"`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'`"
381 exit ;;
 
382 sun4H:SunOS:5.*:*)
383 echo sparc-hal-solaris2"`echo "$UNAME_RELEASE"|sed -e 's/[^.]*//'`"
384 exit ;;
 
385 sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*)
386 echo sparc-sun-solaris2"`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'`"
387 exit ;;
 
388 i86pc:AuroraUX:5.*:* | i86xen:AuroraUX:5.*:*)
389 echo i386-pc-auroraux"$UNAME_RELEASE"
390 exit ;;
391 i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*)
392 eval "$set_cc_for_build"
393 SUN_ARCH=i386
394 # If there is a compiler, see if it is configured for 64-bit objects.
395 # Note that the Sun cc does not turn __LP64__ into 1 like gcc does.
396 # This test works for both compilers.
397 if [ "$CC_FOR_BUILD" != no_compiler_found ]; then
398 if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \
399 (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \
400 grep IS_64BIT_ARCH >/dev/null
401 then
402 SUN_ARCH=x86_64
403 fi
404 fi
405 echo "$SUN_ARCH"-pc-solaris2"`echo "$UNAME_RELEASE"|sed -e 's/[^.]*//'`"
406 exit ;;
 
407 sun4*:SunOS:6*:*)
408 # According to config.sub, this is the proper way to canonicalize
409 # SunOS6. Hard to guess exactly what SunOS6 will be like, but
410 # it's likely to be more like Solaris than SunOS4.
411 echo sparc-sun-solaris3"`echo "$UNAME_RELEASE"|sed -e 's/[^.]*//'`"
412 exit ;;
 
413 sun4*:SunOS:*:*)
414 case "`/usr/bin/arch -k`" in
415 Series*|S4*)
416 UNAME_RELEASE=`uname -v`
417 ;;
418 esac
419 # Japanese Language versions have a version number like `4.1.3-JL'.
420 echo sparc-sun-sunos"`echo "$UNAME_RELEASE"|sed -e 's/-/_/'`"
421 exit ;;
 
422 sun3*:SunOS:*:*)
423 echo m68k-sun-sunos"$UNAME_RELEASE"
424 exit ;;
425 sun*:*:4.2BSD:*)
426 UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null`
427 test "x$UNAME_RELEASE" = x && UNAME_RELEASE=3
428 case "`/bin/arch`" in
429 sun3)
430 echo m68k-sun-sunos"$UNAME_RELEASE"
431 ;;
432 sun4)
433 echo sparc-sun-sunos"$UNAME_RELEASE"
434 ;;
435 esac
436 exit ;;
437 aushp:SunOS:*:*)
438 echo sparc-auspex-sunos"$UNAME_RELEASE"
439 exit ;;
440 # The situation for MiNT is a little confusing. The machine name
441 # can be virtually everything (everything which is not
442 # "atarist" or "atariste" at least should have a processor
443 # > m68000). The system name ranges from "MiNT" over "FreeMiNT"
444 # to the lowercase version "mint" (or "freemint"). Finally
445 # the system name "TOS" denotes a system which is actually not
446 # MiNT. But MiNT is downward compatible to TOS, so this should
447 # be no problem.
448 atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*)
449 echo m68k-atari-mint"$UNAME_RELEASE"
450 exit ;;
451 atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*)
452 echo m68k-atari-mint"$UNAME_RELEASE"
453 exit ;;
454 *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*)
455 echo m68k-atari-mint"$UNAME_RELEASE"
456 exit ;;
457 milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*)
458 echo m68k-milan-mint"$UNAME_RELEASE"
459 exit ;;
460 hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*)
461 echo m68k-hades-mint"$UNAME_RELEASE"
462 exit ;;
463 *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*)
464 echo m68k-unknown-mint"$UNAME_RELEASE"
465 exit ;;
466 m68k:machten:*:*)
467 echo m68k-apple-machten"$UNAME_RELEASE"
468 exit ;;
469 powerpc:machten:*:*)
470 echo powerpc-apple-machten"$UNAME_RELEASE"
471 exit ;;
472 RISC*:Mach:*:*)
473 echo mips-dec-mach_bsd4.3
474 exit ;;
475 RISC*:ULTRIX:*:*)
476 echo mips-dec-ultrix"$UNAME_RELEASE"
477 exit ;;
478 VAX*:ULTRIX*:*:*)
479 echo vax-dec-ultrix"$UNAME_RELEASE"
480 exit ;;
481 2020:CLIX:*:* | 2430:CLIX:*:*)
482 echo clipper-intergraph-clix"$UNAME_RELEASE"
483 exit ;;
484 mips:*:*:UMIPS | mips:*:*:RISCos)
485 eval "$set_cc_for_build"
486 sed 's/^ //' << EOF > "$dummy.c"
487 #ifdef __cplusplus
488 #include <stdio.h> /* for printf() prototype */
489 int main (int argc, char *argv[]) {
490 #else
@@ -506,82 +550,83 @@
506 EOF
507 $CC_FOR_BUILD -o "$dummy" "$dummy.c" &&
508 dummyarg=`echo "$UNAME_RELEASE" | sed -n 's/\([0-9]*\).*/\1/p'` &&
509 SYSTEM_NAME=`"$dummy" "$dummyarg"` &&
510 { echo "$SYSTEM_NAME"; exit; }
511 echo mips-mips-riscos"$UNAME_RELEASE"
512 exit ;;
513 Motorola:PowerMAX_OS:*:*)
514 echo powerpc-motorola-powermax
515 exit ;;
516 Motorola:*:4.3:PL8-*)
517 echo powerpc-harris-powermax
518 exit ;;
519 Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*)
520 echo powerpc-harris-powermax
521 exit ;;
522 Night_Hawk:Power_UNIX:*:*)
523 echo powerpc-harris-powerunix
524 exit ;;
525 m88k:CX/UX:7*:*)
526 echo m88k-harris-cxux7
527 exit ;;
528 m88k:*:4*:R4*)
529 echo m88k-motorola-sysv4
530 exit ;;
531 m88k:*:3*:R3*)
532 echo m88k-motorola-sysv3
533 exit ;;
534 AViiON:dgux:*:*)
535 # DG/UX returns AViiON for all architectures
536 UNAME_PROCESSOR=`/usr/bin/uname -p`
537 if [ "$UNAME_PROCESSOR" = mc88100 ] || [ "$UNAME_PROCESSOR" = mc88110 ]
538 then
539 if [ "$TARGET_BINARY_INTERFACE"x = m88kdguxelfx ] || \
540 [ "$TARGET_BINARY_INTERFACE"x = x ]
541 then
542 echo m88k-dg-dgux"$UNAME_RELEASE"
543 else
544 echo m88k-dg-dguxbcs"$UNAME_RELEASE"
545 fi
546 else
547 echo i586-dg-dgux"$UNAME_RELEASE"
548 fi
549 exit ;;
550 M88*:DolphinOS:*:*) # DolphinOS (SVR3)
551 echo m88k-dolphin-sysv3
552 exit ;;
553 M88*:*:R3*:*)
554 # Delta 88k system running SVR3
555 echo m88k-motorola-sysv3
556 exit ;;
557 XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3)
558 echo m88k-tektronix-sysv3
559 exit ;;
560 Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD)
561 echo m68k-tektronix-bsd
562 exit ;;
563 *:IRIX*:*:*)
564 echo mips-sgi-irix"`echo "$UNAME_RELEASE"|sed -e 's/-/_/g'`"
565 exit ;;
 
566 ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX.
567 echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id
568 exit ;; # Note that: echo "'`uname -s`'" gives 'AIX '
569 i*86:AIX:*:*)
570 echo i386-ibm-aix
571 exit ;;
572 ia64:AIX:*:*)
573 if [ -x /usr/bin/oslevel ] ; then
574 IBM_REV=`/usr/bin/oslevel`
575 else
576 IBM_REV="$UNAME_VERSION.$UNAME_RELEASE"
577 fi
578 echo "$UNAME_MACHINE"-ibm-aix"$IBM_REV"
579 exit ;;
580 *:AIX:2:3)
581 if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then
582 eval "$set_cc_for_build"
583 sed 's/^ //' << EOF > "$dummy.c"
584 #include <sys/systemcfg.h>
585
586 main()
587 {
@@ -591,78 +636,78 @@
591 exit(0);
592 }
593 EOF
594 if $CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=`"$dummy"`
595 then
596 echo "$SYSTEM_NAME"
597 else
598 echo rs6000-ibm-aix3.2.5
599 fi
600 elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then
601 echo rs6000-ibm-aix3.2.4
602 else
603 echo rs6000-ibm-aix3.2
604 fi
605 exit ;;
606 *:AIX:*:[4567])
607 IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`
608 if /usr/sbin/lsattr -El "$IBM_CPU_ID" | grep ' POWER' >/dev/null 2>&1; then
609 IBM_ARCH=rs6000
610 else
611 IBM_ARCH=powerpc
612 fi
613 if [ -x /usr/bin/lslpp ] ; then
614 IBM_REV=`/usr/bin/lslpp -Lqc bos.rte.libc |
615 awk -F: '{ print $3 }' | sed s/[0-9]*$/0/`
616 else
617 IBM_REV="$UNAME_VERSION.$UNAME_RELEASE"
618 fi
619 echo "$IBM_ARCH"-ibm-aix"$IBM_REV"
620 exit ;;
621 *:AIX:*:*)
622 echo rs6000-ibm-aix
623 exit ;;
624 ibmrt:4.4BSD:*|romp-ibm:4.4BSD:*)
625 echo romp-ibm-bsd4.4
626 exit ;;
627 ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and
628 echo romp-ibm-bsd"$UNAME_RELEASE" # 4.3 with uname added to
629 exit ;; # report: romp-ibm BSD 4.3
630 *:BOSX:*:*)
631 echo rs6000-bull-bosx
632 exit ;;
633 DPX/2?00:B.O.S.:*:*)
634 echo m68k-bull-sysv3
635 exit ;;
636 9000/[34]??:4.3bsd:1.*:*)
637 echo m68k-hp-bsd
638 exit ;;
639 hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*)
640 echo m68k-hp-bsd4.4
641 exit ;;
642 9000/[34678]??:HP-UX:*:*)
643 HPUX_REV=`echo "$UNAME_RELEASE"|sed -e 's/[^.]*.[0B]*//'`
644 case "$UNAME_MACHINE" in
645 9000/31?) HP_ARCH=m68000 ;;
646 9000/[34]??) HP_ARCH=m68k ;;
647 9000/[678][0-9][0-9])
648 if [ -x /usr/bin/getconf ]; then
649 sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null`
650 sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`
651 case "$sc_cpu_version" in
652 523) HP_ARCH=hppa1.0 ;; # CPU_PA_RISC1_0
653 528) HP_ARCH=hppa1.1 ;; # CPU_PA_RISC1_1
654 532) # CPU_PA_RISC2_0
655 case "$sc_kernel_bits" in
656 32) HP_ARCH=hppa2.0n ;;
657 64) HP_ARCH=hppa2.0w ;;
658 '') HP_ARCH=hppa2.0 ;; # HP-UX 10.20
659 esac ;;
660 esac
661 fi
662 if [ "$HP_ARCH" = "" ]; then
663 eval "$set_cc_for_build"
664 sed 's/^ //' << EOF > "$dummy.c"
665
666 #define _HPUX_SOURCE
667 #include <stdlib.h>
668 #include <unistd.h>
@@ -696,13 +741,13 @@
696 EOF
697 (CCOPTS="" $CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null) && HP_ARCH=`"$dummy"`
698 test -z "$HP_ARCH" && HP_ARCH=hppa
699 fi ;;
700 esac
701 if [ "$HP_ARCH" = hppa2.0w ]
702 then
703 eval "$set_cc_for_build"
704
705 # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating
706 # 32-bit code. hppa64-hp-hpux* has the same kernel and a compiler
707 # generating 64-bit code. GNU and HP use different nomenclature:
708 #
@@ -717,18 +762,18 @@
717 HP_ARCH=hppa2.0w
718 else
719 HP_ARCH=hppa64
720 fi
721 fi
722 echo "$HP_ARCH"-hp-hpux"$HPUX_REV"
723 exit ;;
724 ia64:HP-UX:*:*)
725 HPUX_REV=`echo "$UNAME_RELEASE"|sed -e 's/[^.]*.[0B]*//'`
726 echo ia64-hp-hpux"$HPUX_REV"
727 exit ;;
728 3050*:HI-UX:*:*)
729 eval "$set_cc_for_build"
730 sed 's/^ //' << EOF > "$dummy.c"
731 #include <unistd.h>
732 int
733 main ()
734 {
@@ -752,162 +797,186 @@
752 exit (0);
753 }
754 EOF
755 $CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=`"$dummy"` &&
756 { echo "$SYSTEM_NAME"; exit; }
757 echo unknown-hitachi-hiuxwe2
758 exit ;;
759 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:*)
760 echo hppa1.1-hp-bsd
761 exit ;;
762 9000/8??:4.3bsd:*:*)
763 echo hppa1.0-hp-bsd
764 exit ;;
765 *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*)
766 echo hppa1.0-hp-mpeix
767 exit ;;
768 hp7??:OSF1:*:* | hp8?[79]:OSF1:*:*)
769 echo hppa1.1-hp-osf
770 exit ;;
771 hp8??:OSF1:*:*)
772 echo hppa1.0-hp-osf
773 exit ;;
774 i*86:OSF1:*:*)
775 if [ -x /usr/sbin/sysversion ] ; then
776 echo "$UNAME_MACHINE"-unknown-osf1mk
777 else
778 echo "$UNAME_MACHINE"-unknown-osf1
779 fi
780 exit ;;
781 parisc*:Lites*:*:*)
782 echo hppa1.1-hp-lites
783 exit ;;
784 C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*)
785 echo c1-convex-bsd
786 exit ;;
787 C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*)
788 if getsysinfo -f scalar_acc
789 then echo c32-convex-bsd
790 else echo c2-convex-bsd
791 fi
792 exit ;;
793 C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*)
794 echo c34-convex-bsd
795 exit ;;
796 C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*)
797 echo c38-convex-bsd
798 exit ;;
799 C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*)
800 echo c4-convex-bsd
801 exit ;;
802 CRAY*Y-MP:*:*:*)
803 echo ymp-cray-unicos"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'
804 exit ;;
 
805 CRAY*[A-Z]90:*:*:*)
806 echo "$UNAME_MACHINE"-cray-unicos"$UNAME_RELEASE" \
807 | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \
808 -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \
809 -e 's/\.[^.]*$/.X/'
810 exit ;;
811 CRAY*TS:*:*:*)
812 echo t90-cray-unicos"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'
813 exit ;;
 
814 CRAY*T3E:*:*:*)
815 echo alphaev5-cray-unicosmk"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'
816 exit ;;
 
817 CRAY*SV1:*:*:*)
818 echo sv1-cray-unicos"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'
819 exit ;;
 
820 *:UNICOS/mp:*:*)
821 echo craynv-cray-unicosmp"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'
822 exit ;;
 
823 F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*)
824 FUJITSU_PROC=`uname -m | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`
825 FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'`
826 FUJITSU_REL=`echo "$UNAME_RELEASE" | sed -e 's/ /_/'`
827 echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
828 exit ;;
829 5000:UNIX_System_V:4.*:*)
830 FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'`
831 FUJITSU_REL=`echo "$UNAME_RELEASE" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/ /_/'`
832 echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
833 exit ;;
834 i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*)
835 echo "$UNAME_MACHINE"-pc-bsdi"$UNAME_RELEASE"
836 exit ;;
837 sparc*:BSD/OS:*:*)
838 echo sparc-unknown-bsdi"$UNAME_RELEASE"
839 exit ;;
840 *:BSD/OS:*:*)
841 echo "$UNAME_MACHINE"-unknown-bsdi"$UNAME_RELEASE"
842 exit ;;
 
 
 
 
 
 
 
 
 
 
 
 
 
843 *:FreeBSD:*:*)
844 UNAME_PROCESSOR=`/usr/bin/uname -p`
845 case "$UNAME_PROCESSOR" in
846 amd64)
847 UNAME_PROCESSOR=x86_64 ;;
848 i386)
849 UNAME_PROCESSOR=i586 ;;
850 esac
851 echo "$UNAME_PROCESSOR"-unknown-freebsd"`echo "$UNAME_RELEASE"|sed -e 's/[-(].*//'`"
852 exit ;;
 
853 i*:CYGWIN*:*)
854 echo "$UNAME_MACHINE"-pc-cygwin
855 exit ;;
856 *:MINGW64*:*)
857 echo "$UNAME_MACHINE"-pc-mingw64
858 exit ;;
859 *:MINGW*:*)
860 echo "$UNAME_MACHINE"-pc-mingw32
861 exit ;;
862 *:MSYS*:*)
863 echo "$UNAME_MACHINE"-pc-msys
864 exit ;;
865 i*:PW*:*)
866 echo "$UNAME_MACHINE"-pc-pw32
867 exit ;;
868 *:Interix*:*)
869 case "$UNAME_MACHINE" in
870 x86)
871 echo i586-pc-interix"$UNAME_RELEASE"
872 exit ;;
873 authenticamd | genuineintel | EM64T)
874 echo x86_64-unknown-interix"$UNAME_RELEASE"
875 exit ;;
876 IA64)
877 echo ia64-unknown-interix"$UNAME_RELEASE"
878 exit ;;
879 esac ;;
880 i*:UWIN*:*)
881 echo "$UNAME_MACHINE"-pc-uwin
882 exit ;;
883 amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*)
884 echo x86_64-unknown-cygwin
885 exit ;;
886 prep*:SunOS:5.*:*)
887 echo powerpcle-unknown-solaris2"`echo "$UNAME_RELEASE"|sed -e 's/[^.]*//'`"
888 exit ;;
 
889 *:GNU:*:*)
890 # the GNU system
891 echo "`echo "$UNAME_MACHINE"|sed -e 's,[-/].*$,,'`-unknown-$LIBC`echo "$UNAME_RELEASE"|sed -e 's,/.*$,,'`"
892 exit ;;
 
 
893 *:GNU/*:*:*)
894 # other systems with GNU libc and userland
895 echo "$UNAME_MACHINE-unknown-`echo "$UNAME_SYSTEM" | sed 's,^[^/]*/,,' | tr "[:upper:]" "[:lower:]"``echo "$UNAME_RELEASE"|sed -e 's/[-(].*//'`-$LIBC"
896 exit ;;
897 i*86:Minix:*:*)
898 echo "$UNAME_MACHINE"-pc-minix
899 exit ;;
 
 
900 aarch64:Linux:*:*)
901 echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
902 exit ;;
903 aarch64_be:Linux:*:*)
904 UNAME_MACHINE=aarch64_be
905 echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
906 exit ;;
907 alpha:Linux:*:*)
908 case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in
909 EV5) UNAME_MACHINE=alphaev5 ;;
910 EV56) UNAME_MACHINE=alphaev56 ;;
911 PCA56) UNAME_MACHINE=alphapca56 ;;
912 PCA57) UNAME_MACHINE=alphapca56 ;;
913 EV6) UNAME_MACHINE=alphaev6 ;;
@@ -914,246 +983,288 @@
914 EV67) UNAME_MACHINE=alphaev67 ;;
915 EV68*) UNAME_MACHINE=alphaev68 ;;
916 esac
917 objdump --private-headers /bin/sh | grep -q ld.so.1
918 if test "$?" = 0 ; then LIBC=gnulibc1 ; fi
919 echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
920 exit ;;
921 arc:Linux:*:* | arceb:Linux:*:*)
922 echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
923 exit ;;
924 arm*:Linux:*:*)
925 eval "$set_cc_for_build"
926 if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \
927 | grep -q __ARM_EABI__
928 then
929 echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
930 else
931 if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \
932 | grep -q __ARM_PCS_VFP
933 then
934 echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"eabi
935 else
936 echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"eabihf
937 fi
938 fi
939 exit ;;
940 avr32*:Linux:*:*)
941 echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
942 exit ;;
943 cris:Linux:*:*)
944 echo "$UNAME_MACHINE"-axis-linux-"$LIBC"
945 exit ;;
946 crisv32:Linux:*:*)
947 echo "$UNAME_MACHINE"-axis-linux-"$LIBC"
948 exit ;;
949 e2k:Linux:*:*)
950 echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
951 exit ;;
952 frv:Linux:*:*)
953 echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
954 exit ;;
955 hexagon:Linux:*:*)
956 echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
957 exit ;;
958 i*86:Linux:*:*)
959 echo "$UNAME_MACHINE"-pc-linux-"$LIBC"
960 exit ;;
961 ia64:Linux:*:*)
962 echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
963 exit ;;
964 k1om:Linux:*:*)
965 echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
966 exit ;;
 
 
 
967 m32r*:Linux:*:*)
968 echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
969 exit ;;
970 m68*:Linux:*:*)
971 echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
972 exit ;;
973 mips:Linux:*:* | mips64:Linux:*:*)
974 eval "$set_cc_for_build"
 
 
975 sed 's/^ //' << EOF > "$dummy.c"
976 #undef CPU
977 #undef ${UNAME_MACHINE}
978 #undef ${UNAME_MACHINE}el
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
979 #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
980 CPU=${UNAME_MACHINE}el
981 #else
982 #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
983 CPU=${UNAME_MACHINE}
984 #else
985 CPU=
986 #endif
987 #endif
988 EOF
989 eval "`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^CPU'`"
990 test "x$CPU" != x && { echo "$CPU-unknown-linux-$LIBC"; exit; }
 
991 ;;
992 mips64el:Linux:*:*)
993 echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
994 exit ;;
995 openrisc*:Linux:*:*)
996 echo or1k-unknown-linux-"$LIBC"
997 exit ;;
998 or32:Linux:*:* | or1k*:Linux:*:*)
999 echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
1000 exit ;;
1001 padre:Linux:*:*)
1002 echo sparc-unknown-linux-"$LIBC"
1003 exit ;;
1004 parisc64:Linux:*:* | hppa64:Linux:*:*)
1005 echo hppa64-unknown-linux-"$LIBC"
1006 exit ;;
1007 parisc:Linux:*:* | hppa:Linux:*:*)
1008 # Look for CPU level
1009 case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in
1010 PA7*) echo hppa1.1-unknown-linux-"$LIBC" ;;
1011 PA8*) echo hppa2.0-unknown-linux-"$LIBC" ;;
1012 *) echo hppa-unknown-linux-"$LIBC" ;;
1013 esac
1014 exit ;;
1015 ppc64:Linux:*:*)
1016 echo powerpc64-unknown-linux-"$LIBC"
1017 exit ;;
1018 ppc:Linux:*:*)
1019 echo powerpc-unknown-linux-"$LIBC"
1020 exit ;;
1021 ppc64le:Linux:*:*)
1022 echo powerpc64le-unknown-linux-"$LIBC"
1023 exit ;;
1024 ppcle:Linux:*:*)
1025 echo powerpcle-unknown-linux-"$LIBC"
1026 exit ;;
1027 riscv32:Linux:*:* | riscv64:Linux:*:*)
1028 echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
1029 exit ;;
1030 s390:Linux:*:* | s390x:Linux:*:*)
1031 echo "$UNAME_MACHINE"-ibm-linux-"$LIBC"
1032 exit ;;
1033 sh64*:Linux:*:*)
1034 echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
1035 exit ;;
1036 sh*:Linux:*:*)
1037 echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
1038 exit ;;
1039 sparc:Linux:*:* | sparc64:Linux:*:*)
1040 echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
1041 exit ;;
1042 tile*:Linux:*:*)
1043 echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
1044 exit ;;
1045 vax:Linux:*:*)
1046 echo "$UNAME_MACHINE"-dec-linux-"$LIBC"
1047 exit ;;
1048 x86_64:Linux:*:*)
1049 echo "$UNAME_MACHINE"-pc-linux-"$LIBC"
1050 exit ;;
 
 
 
 
 
 
 
 
 
 
1051 xtensa*:Linux:*:*)
1052 echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
1053 exit ;;
1054 i*86:DYNIX/ptx:4*:*)
1055 # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there.
1056 # earlier versions are messed up and put the nodename in both
1057 # sysname and nodename.
1058 echo i386-sequent-sysv4
1059 exit ;;
1060 i*86:UNIX_SV:4.2MP:2.*)
1061 # Unixware is an offshoot of SVR4, but it has its own version
1062 # number series starting with 2...
1063 # I am not positive that other SVR4 systems won't match this,
1064 # I just have to hope. -- rms.
1065 # Use sysv4.2uw... so that sysv4* matches it.
1066 echo "$UNAME_MACHINE"-pc-sysv4.2uw"$UNAME_VERSION"
1067 exit ;;
1068 i*86:OS/2:*:*)
1069 # If we were able to find `uname', then EMX Unix compatibility
1070 # is probably installed.
1071 echo "$UNAME_MACHINE"-pc-os2-emx
1072 exit ;;
1073 i*86:XTS-300:*:STOP)
1074 echo "$UNAME_MACHINE"-unknown-stop
1075 exit ;;
1076 i*86:atheos:*:*)
1077 echo "$UNAME_MACHINE"-unknown-atheos
1078 exit ;;
1079 i*86:syllable:*:*)
1080 echo "$UNAME_MACHINE"-pc-syllable
1081 exit ;;
1082 i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.[02]*:*)
1083 echo i386-unknown-lynxos"$UNAME_RELEASE"
1084 exit ;;
1085 i*86:*DOS:*:*)
1086 echo "$UNAME_MACHINE"-pc-msdosdjgpp
1087 exit ;;
1088 i*86:*:4.*:*)
1089 UNAME_REL=`echo "$UNAME_RELEASE" | sed 's/\/MP$//'`
1090 if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then
1091 echo "$UNAME_MACHINE"-univel-sysv"$UNAME_REL"
1092 else
1093 echo "$UNAME_MACHINE"-pc-sysv"$UNAME_REL"
1094 fi
1095 exit ;;
1096 i*86:*:5:[678]*)
1097 # UnixWare 7.x, OpenUNIX and OpenServer 6.
1098 case `/bin/uname -X | grep "^Machine"` in
1099 *486*) UNAME_MACHINE=i486 ;;
1100 *Pentium) UNAME_MACHINE=i586 ;;
1101 *Pent*|*Celeron) UNAME_MACHINE=i686 ;;
1102 esac
1103 echo "$UNAME_MACHINE-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}{$UNAME_VERSION}"
1104 exit ;;
1105 i*86:*:3.2:*)
1106 if test -f /usr/options/cb.name; then
1107 UNAME_REL=`sed -n 's/.*Version //p' </usr/options/cb.name`
1108 echo "$UNAME_MACHINE"-pc-isc"$UNAME_REL"
1109 elif /bin/uname -X 2>/dev/null >/dev/null ; then
1110 UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')`
1111 (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486
1112 (/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \
1113 && UNAME_MACHINE=i586
1114 (/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \
1115 && UNAME_MACHINE=i686
1116 (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \
1117 && UNAME_MACHINE=i686
1118 echo "$UNAME_MACHINE"-pc-sco"$UNAME_REL"
1119 else
1120 echo "$UNAME_MACHINE"-pc-sysv32
1121 fi
1122 exit ;;
1123 pc:*:*:*)
1124 # Left here for compatibility:
1125 # uname -m prints for DJGPP always 'pc', but it prints nothing about
1126 # the processor, so we play safe by assuming i586.
1127 # Note: whatever this is, it MUST be the same as what config.sub
1128 # prints for the "djgpp" host, or else GDB configure will decide that
1129 # this is a cross-build.
1130 echo i586-pc-msdosdjgpp
1131 exit ;;
1132 Intel:Mach:3*:*)
1133 echo i386-pc-mach3
1134 exit ;;
1135 paragon:*:*:*)
1136 echo i860-intel-osf1
1137 exit ;;
1138 i860:*:4.*:*) # i860-SVR4
1139 if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then
1140 echo i860-stardent-sysv"$UNAME_RELEASE" # Stardent Vistra i860-SVR4
1141 else # Add other i860-SVR4 vendors below as they are discovered.
1142 echo i860-unknown-sysv"$UNAME_RELEASE" # Unknown i860-SVR4
1143 fi
1144 exit ;;
1145 mini*:CTIX:SYS*5:*)
1146 # "miniframe"
1147 echo m68010-convergent-sysv
1148 exit ;;
1149 mc68k:UNIX:SYSTEM5:3.51m)
1150 echo m68k-convergent-sysv
1151 exit ;;
1152 M680?0:D-NIX:5.3:*)
1153 echo m68k-diab-dnix
1154 exit ;;
1155 M68*:*:R3V[5678]*:*)
1156 test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;;
1157 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)
1158 OS_REL=''
1159 test -r /etc/.relid \
@@ -1174,253 +1285,405 @@
1174 /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
1175 && { echo i586-ncr-sysv4.3"$OS_REL"; exit; }
1176 /bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \
1177 && { echo i586-ncr-sysv4.3"$OS_REL"; exit; } ;;
1178 m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*)
1179 echo m68k-unknown-lynxos"$UNAME_RELEASE"
1180 exit ;;
1181 mc68030:UNIX_System_V:4.*:*)
1182 echo m68k-atari-sysv4
1183 exit ;;
1184 TSUNAMI:LynxOS:2.*:*)
1185 echo sparc-unknown-lynxos"$UNAME_RELEASE"
1186 exit ;;
1187 rs6000:LynxOS:2.*:*)
1188 echo rs6000-unknown-lynxos"$UNAME_RELEASE"
1189 exit ;;
1190 PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.[02]*:*)
1191 echo powerpc-unknown-lynxos"$UNAME_RELEASE"
1192 exit ;;
1193 SM[BE]S:UNIX_SV:*:*)
1194 echo mips-dde-sysv"$UNAME_RELEASE"
1195 exit ;;
1196 RM*:ReliantUNIX-*:*:*)
1197 echo mips-sni-sysv4
1198 exit ;;
1199 RM*:SINIX-*:*:*)
1200 echo mips-sni-sysv4
1201 exit ;;
1202 *:SINIX-*:*:*)
1203 if uname -p 2>/dev/null >/dev/null ; then
1204 UNAME_MACHINE=`(uname -p) 2>/dev/null`
1205 echo "$UNAME_MACHINE"-sni-sysv4
1206 else
1207 echo ns32k-sni-sysv
1208 fi
1209 exit ;;
1210 PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort
1211 # says <[email protected]>
1212 echo i586-unisys-sysv4
1213 exit ;;
1214 *:UNIX_System_V:4*:FTX*)
1215 # From Gerald Hewes <[email protected]>.
1216 # How about differentiating between stratus architectures? -djm
1217 echo hppa1.1-stratus-sysv4
1218 exit ;;
1219 *:*:*:FTX*)
1220 # From [email protected].
1221 echo i860-stratus-sysv4
1222 exit ;;
1223 i*86:VOS:*:*)
1224 # From [email protected].
1225 echo "$UNAME_MACHINE"-stratus-vos
1226 exit ;;
1227 *:VOS:*:*)
1228 # From [email protected].
1229 echo hppa1.1-stratus-vos
1230 exit ;;
1231 mc68*:A/UX:*:*)
1232 echo m68k-apple-aux"$UNAME_RELEASE"
1233 exit ;;
1234 news*:NEWS-OS:6*:*)
1235 echo mips-sony-newsos6
1236 exit ;;
1237 R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*)
1238 if [ -d /usr/nec ]; then
1239 echo mips-nec-sysv"$UNAME_RELEASE"
1240 else
1241 echo mips-unknown-sysv"$UNAME_RELEASE"
1242 fi
1243 exit ;;
1244 BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only.
1245 echo powerpc-be-beos
1246 exit ;;
1247 BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only.
1248 echo powerpc-apple-beos
1249 exit ;;
1250 BePC:BeOS:*:*) # BeOS running on Intel PC compatible.
1251 echo i586-pc-beos
1252 exit ;;
1253 BePC:Haiku:*:*) # Haiku running on Intel PC compatible.
1254 echo i586-pc-haiku
1255 exit ;;
1256 x86_64:Haiku:*:*)
1257 echo x86_64-unknown-haiku
1258 exit ;;
1259 SX-4:SUPER-UX:*:*)
1260 echo sx4-nec-superux"$UNAME_RELEASE"
1261 exit ;;
1262 SX-5:SUPER-UX:*:*)
1263 echo sx5-nec-superux"$UNAME_RELEASE"
1264 exit ;;
1265 SX-6:SUPER-UX:*:*)
1266 echo sx6-nec-superux"$UNAME_RELEASE"
1267 exit ;;
1268 SX-7:SUPER-UX:*:*)
1269 echo sx7-nec-superux"$UNAME_RELEASE"
1270 exit ;;
1271 SX-8:SUPER-UX:*:*)
1272 echo sx8-nec-superux"$UNAME_RELEASE"
1273 exit ;;
1274 SX-8R:SUPER-UX:*:*)
1275 echo sx8r-nec-superux"$UNAME_RELEASE"
1276 exit ;;
1277 SX-ACE:SUPER-UX:*:*)
1278 echo sxace-nec-superux"$UNAME_RELEASE"
1279 exit ;;
1280 Power*:Rhapsody:*:*)
1281 echo powerpc-apple-rhapsody"$UNAME_RELEASE"
1282 exit ;;
1283 *:Rhapsody:*:*)
1284 echo "$UNAME_MACHINE"-apple-rhapsody"$UNAME_RELEASE"
1285 exit ;;
 
 
 
1286 *:Darwin:*:*)
1287 UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown
1288 eval "$set_cc_for_build"
1289 if test "$UNAME_PROCESSOR" = unknown ; then
1290 UNAME_PROCESSOR=powerpc
1291 fi
1292 if test "`echo "$UNAME_RELEASE" | sed -e 's/\..*//'`" -le 10 ; then
1293 if [ "$CC_FOR_BUILD" != no_compiler_found ]; then
1294 if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \
1295 (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \
1296 grep IS_64BIT_ARCH >/dev/null
1297 then
1298 case $UNAME_PROCESSOR in
1299 i386) UNAME_PROCESSOR=x86_64 ;;
1300 powerpc) UNAME_PROCESSOR=powerpc64 ;;
1301 esac
1302 fi
1303 # On 10.4-10.6 one might compile for PowerPC via gcc -arch ppc
1304 if (echo '#ifdef __POWERPC__'; echo IS_PPC; echo '#endif') | \
1305 (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \
1306 grep IS_PPC >/dev/null
1307 then
1308 UNAME_PROCESSOR=powerpc
1309 fi
 
 
 
 
 
 
1310 fi
1311 elif test "$UNAME_PROCESSOR" = i386 ; then
1312 # Avoid executing cc on OS X 10.9, as it ships with a stub
1313 # that puts up a graphical alert prompting to install
1314 # developer tools. Any system running Mac OS X 10.7 or
1315 # later (Darwin 11 and later) is required to have a 64-bit
1316 # processor. This is not true of the ARM version of Darwin
1317 # that Apple uses in portable devices.
1318 UNAME_PROCESSOR=x86_64
1319 fi
1320 echo "$UNAME_PROCESSOR"-apple-darwin"$UNAME_RELEASE"
1321 exit ;;
1322 *:procnto*:*:* | *:QNX:[0123456789]*:*)
1323 UNAME_PROCESSOR=`uname -p`
1324 if test "$UNAME_PROCESSOR" = x86; then
1325 UNAME_PROCESSOR=i386
1326 UNAME_MACHINE=pc
1327 fi
1328 echo "$UNAME_PROCESSOR"-"$UNAME_MACHINE"-nto-qnx"$UNAME_RELEASE"
1329 exit ;;
1330 *:QNX:*:4*)
1331 echo i386-pc-qnx
1332 exit ;;
1333 NEO-*:NONSTOP_KERNEL:*:*)
1334 echo neo-tandem-nsk"$UNAME_RELEASE"
1335 exit ;;
1336 NSE-*:NONSTOP_KERNEL:*:*)
1337 echo nse-tandem-nsk"$UNAME_RELEASE"
1338 exit ;;
1339 NSR-*:NONSTOP_KERNEL:*:*)
1340 echo nsr-tandem-nsk"$UNAME_RELEASE"
1341 exit ;;
1342 NSV-*:NONSTOP_KERNEL:*:*)
1343 echo nsv-tandem-nsk"$UNAME_RELEASE"
1344 exit ;;
1345 NSX-*:NONSTOP_KERNEL:*:*)
1346 echo nsx-tandem-nsk"$UNAME_RELEASE"
1347 exit ;;
1348 *:NonStop-UX:*:*)
1349 echo mips-compaq-nonstopux
1350 exit ;;
1351 BS2000:POSIX*:*:*)
1352 echo bs2000-siemens-sysv
1353 exit ;;
1354 DS/*:UNIX_System_V:*:*)
1355 echo "$UNAME_MACHINE"-"$UNAME_SYSTEM"-"$UNAME_RELEASE"
1356 exit ;;
1357 *:Plan9:*:*)
1358 # "uname -m" is not consistent, so use $cputype instead. 386
1359 # is converted to i386 for consistency with other x86
1360 # operating systems.
1361 if test "$cputype" = 386; then
1362 UNAME_MACHINE=i386
1363 else
1364 UNAME_MACHINE="$cputype"
1365 fi
1366 echo "$UNAME_MACHINE"-unknown-plan9
1367 exit ;;
1368 *:TOPS-10:*:*)
1369 echo pdp10-unknown-tops10
1370 exit ;;
1371 *:TENEX:*:*)
1372 echo pdp10-unknown-tenex
1373 exit ;;
1374 KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*)
1375 echo pdp10-dec-tops20
1376 exit ;;
1377 XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*)
1378 echo pdp10-xkl-tops20
1379 exit ;;
1380 *:TOPS-20:*:*)
1381 echo pdp10-unknown-tops20
1382 exit ;;
1383 *:ITS:*:*)
1384 echo pdp10-unknown-its
1385 exit ;;
1386 SEI:*:*:SEIUX)
1387 echo mips-sei-seiux"$UNAME_RELEASE"
1388 exit ;;
1389 *:DragonFly:*:*)
1390 echo "$UNAME_MACHINE"-unknown-dragonfly"`echo "$UNAME_RELEASE"|sed -e 's/[-(].*//'`"
1391 exit ;;
 
1392 *:*VMS:*:*)
1393 UNAME_MACHINE=`(uname -p) 2>/dev/null`
1394 case "$UNAME_MACHINE" in
1395 A*) echo alpha-dec-vms ; exit ;;
1396 I*) echo ia64-dec-vms ; exit ;;
1397 V*) echo vax-dec-vms ; exit ;;
1398 esac ;;
1399 *:XENIX:*:SysV)
1400 echo i386-pc-xenix
1401 exit ;;
1402 i*86:skyos:*:*)
1403 echo "$UNAME_MACHINE"-pc-skyos"`echo "$UNAME_RELEASE" | sed -e 's/ .*$//'`"
1404 exit ;;
 
1405 i*86:rdos:*:*)
1406 echo "$UNAME_MACHINE"-pc-rdos
1407 exit ;;
1408 i*86:AROS:*:*)
1409 echo "$UNAME_MACHINE"-pc-aros
1410 exit ;;
1411 x86_64:VMkernel:*:*)
1412 echo "$UNAME_MACHINE"-unknown-esx
1413 exit ;;
1414 amd64:Isilon\ OneFS:*:*)
1415 echo x86_64-unknown-onefs
1416 exit ;;
 
 
 
1417 esac
1418
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1419 echo "$0: unable to guess system type" >&2
1420
1421 case "$UNAME_MACHINE:$UNAME_SYSTEM" in
1422 mips:Linux | mips64:Linux)
1423 # If we got here on MIPS GNU/Linux, output extra information.
1424 cat >&2 <<EOF
1425
1426 NOTE: MIPS GNU/Linux systems require a C compiler to fully recognize
@@ -1433,13 +1696,21 @@
1433
1434 This script (version $timestamp), has failed to recognize the
1435 operating system you are using. If your script is old, overwrite *all*
1436 copies of config.guess and config.sub with the latest versions from:
1437
1438 https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess
1439 and
1440 https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub
 
 
 
 
 
 
 
 
1441
1442 If $0 has already been updated, send the following data and any
1443 information you think might be pertinent to [email protected] to
1444 provide the necessary information to handle your system.
1445
@@ -1463,14 +1734,15 @@
1463 UNAME_MACHINE = "$UNAME_MACHINE"
1464 UNAME_RELEASE = "$UNAME_RELEASE"
1465 UNAME_SYSTEM = "$UNAME_SYSTEM"
1466 UNAME_VERSION = "$UNAME_VERSION"
1467 EOF
 
1468
1469 exit 1
1470
1471 # Local variables:
1472 # eval: (add-hook 'before-save-hook 'time-stamp)
1473 # time-stamp-start: "timestamp='"
1474 # time-stamp-format: "%:y-%02m-%02d"
1475 # time-stamp-end: "'"
1476 # End:
1477
--- autosetup/autosetup-config.guess
+++ autosetup/autosetup-config.guess
@@ -1,10 +1,12 @@
1 #! /bin/sh
2 # Attempt to guess a canonical system name.
3 # Copyright 1992-2021 Free Software Foundation, Inc.
4
5 # shellcheck disable=SC2006,SC2268 # see below for rationale
6
7 timestamp='2021-06-03'
8
9 # This file is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
@@ -25,14 +27,22 @@
27 # of the GNU General Public License, version 3 ("GPLv3").
28 #
29 # Originally written by Per Bothner; maintained since 2000 by Ben Elliston.
30 #
31 # You can get the latest version of this script from:
32 # https://git.savannah.gnu.org/cgit/config.git/plain/config.guess
33 #
34 # Please send patches to <[email protected]>.
35
36
37 # The "shellcheck disable" line above the timestamp inhibits complaints
38 # about features and limitations of the classic Bourne shell that were
39 # superseded or lifted in POSIX. However, this script identifies a wide
40 # variety of pre-POSIX systems that do not have POSIX shells at all, and
41 # even some reasonably current systems (Solaris 10 as case-in-point) still
42 # have a pre-POSIX /bin/sh.
43
44
45 me=`echo "$0" | sed -e 's,.*/,,'`
46
47 usage="\
48 Usage: $0 [OPTION]
@@ -48,11 +58,11 @@
58
59 version="\
60 GNU config.guess ($timestamp)
61
62 Originally written by Per Bothner.
63 Copyright 1992-2021 Free Software Foundation, Inc.
64
65 This is free software; see the source for copying conditions. There is NO
66 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
67
68 help="
@@ -82,11 +92,12 @@
92 if test $# != 0; then
93 echo "$me: too many arguments$help" >&2
94 exit 1
95 fi
96
97 # Just in case it came from the environment.
98 GUESS=
99
100 # CC_FOR_BUILD -- compiler used by this script. Note that the use of a
101 # compiler to aid in system detection is discouraged as it requires
102 # temporary files to be created and, as you can see below, it is a
103 # headache to deal with in a portable fashion.
@@ -94,77 +105,94 @@
105 # Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still
106 # use `HOST_CC' if defined, but it is deprecated.
107
108 # Portable tmp directory creation inspired by the Autoconf team.
109
110 tmp=
111 # shellcheck disable=SC2172
112 trap 'test -z "$tmp" || rm -fr "$tmp"' 0 1 2 13 15
113
114 set_cc_for_build() {
115 # prevent multiple calls if $tmp is already set
116 test "$tmp" && return 0
117 : "${TMPDIR=/tmp}"
118 # shellcheck disable=SC2039,SC3028
119 { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
120 { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir "$tmp" 2>/dev/null) ; } ||
121 { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir "$tmp" 2>/dev/null) && echo "Warning: creating insecure temp directory" >&2 ; } ||
122 { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; }
123 dummy=$tmp/dummy
124 case ${CC_FOR_BUILD-},${HOST_CC-},${CC-} in
125 ,,) echo "int x;" > "$dummy.c"
126 for driver in cc gcc c89 c99 ; do
127 if ($driver -c -o "$dummy.o" "$dummy.c") >/dev/null 2>&1 ; then
128 CC_FOR_BUILD=$driver
129 break
130 fi
131 done
132 if test x"$CC_FOR_BUILD" = x ; then
133 CC_FOR_BUILD=no_compiler_found
134 fi
135 ;;
136 ,,*) CC_FOR_BUILD=$CC ;;
137 ,*,*) CC_FOR_BUILD=$HOST_CC ;;
138 esac
139 }
140
141 # This is needed to find uname on a Pyramid OSx when run in the BSD universe.
142 # ([email protected] 1994-08-24)
143 if test -f /.attbin/uname ; then
144 PATH=$PATH:/.attbin ; export PATH
145 fi
146
147 UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown
148 UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown
149 UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown
150 UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown
151
152 case $UNAME_SYSTEM in
153 Linux|GNU|GNU/*)
154 LIBC=unknown
 
 
155
156 set_cc_for_build
157 cat <<-EOF > "$dummy.c"
158 #include <features.h>
159 #if defined(__UCLIBC__)
160 LIBC=uclibc
161 #elif defined(__dietlibc__)
162 LIBC=dietlibc
163 #elif defined(__GLIBC__)
164 LIBC=gnu
165 #else
166 #include <stdarg.h>
167 /* First heuristic to detect musl libc. */
168 #ifdef __DEFINED_va_list
169 LIBC=musl
170 #endif
171 #endif
172 EOF
173 cc_set_libc=`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^LIBC' | sed 's, ,,g'`
174 eval "$cc_set_libc"
175
176 # Second heuristic to detect musl libc.
177 if [ "$LIBC" = unknown ] &&
178 command -v ldd >/dev/null &&
179 ldd --version 2>&1 | grep -q ^musl; then
180 LIBC=musl
181 fi
182
183 # If the system lacks a compiler, then just pick glibc.
184 # We could probably try harder.
185 if [ "$LIBC" = unknown ]; then
186 LIBC=gnu
 
187 fi
188 ;;
189 esac
190
191 # Note: order is significant - the case branches are not exclusive.
192
193 case $UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION in
194 *:NetBSD:*:*)
195 # NetBSD (nbsd) targets should (where applicable) match one or
196 # more of the tuples: *-*-netbsdelf*, *-*-netbsdaout*,
197 # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently
198 # switched to ELF, *-*-netbsd* would select the old
@@ -172,36 +200,36 @@
200 # compatibility and a consistent mechanism for selecting the
201 # object file format.
202 #
203 # Note: NetBSD doesn't particularly care about the vendor
204 # portion of the name. We always set it to "unknown".
 
205 UNAME_MACHINE_ARCH=`(uname -p 2>/dev/null || \
206 /sbin/sysctl -n hw.machine_arch 2>/dev/null || \
207 /usr/sbin/sysctl -n hw.machine_arch 2>/dev/null || \
208 echo unknown)`
209 case $UNAME_MACHINE_ARCH in
210 aarch64eb) machine=aarch64_be-unknown ;;
211 armeb) machine=armeb-unknown ;;
212 arm*) machine=arm-unknown ;;
213 sh3el) machine=shl-unknown ;;
214 sh3eb) machine=sh-unknown ;;
215 sh5el) machine=sh5le-unknown ;;
216 earmv*)
217 arch=`echo "$UNAME_MACHINE_ARCH" | sed -e 's,^e\(armv[0-9]\).*$,\1,'`
218 endian=`echo "$UNAME_MACHINE_ARCH" | sed -ne 's,^.*\(eb\)$,\1,p'`
219 machine=${arch}${endian}-unknown
220 ;;
221 *) machine=$UNAME_MACHINE_ARCH-unknown ;;
222 esac
223 # The Operating System including object format, if it has switched
224 # to ELF recently (or will in the future) and ABI.
225 case $UNAME_MACHINE_ARCH in
226 earm*)
227 os=netbsdelf
228 ;;
229 arm*|i386|m68k|ns32k|sh3*|sparc|vax)
230 set_cc_for_build
231 if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \
232 | grep -q __ELF__
233 then
234 # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout).
235 # Return netbsd for either. FIX?
@@ -213,11 +241,11 @@
241 *)
242 os=netbsd
243 ;;
244 esac
245 # Determine ABI tags.
246 case $UNAME_MACHINE_ARCH in
247 earm*)
248 expr='s/^earmv[0-9]/-eabi/;s/eb$//'
249 abi=`echo "$UNAME_MACHINE_ARCH" | sed -e "$expr"`
250 ;;
251 esac
@@ -224,11 +252,11 @@
252 # The OS release
253 # Debian GNU/NetBSD machines have a different userland, and
254 # thus, need a distinct triplet. However, they do not need
255 # kernel version information, so it can be replaced with a
256 # suitable tag, in the style of linux-gnu.
257 case $UNAME_VERSION in
258 Debian*)
259 release='-gnu'
260 ;;
261 *)
262 release=`echo "$UNAME_RELEASE" | sed -e 's/[-_].*//' | cut -d. -f1,2`
@@ -235,49 +263,61 @@
263 ;;
264 esac
265 # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM:
266 # contains redundant information, the shorter form:
267 # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used.
268 GUESS=$machine-${os}${release}${abi-}
269 ;;
270 *:Bitrig:*:*)
271 UNAME_MACHINE_ARCH=`arch | sed 's/Bitrig.//'`
272 GUESS=$UNAME_MACHINE_ARCH-unknown-bitrig$UNAME_RELEASE
273 ;;
274 *:OpenBSD:*:*)
275 UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'`
276 GUESS=$UNAME_MACHINE_ARCH-unknown-openbsd$UNAME_RELEASE
277 ;;
278 *:SecBSD:*:*)
279 UNAME_MACHINE_ARCH=`arch | sed 's/SecBSD.//'`
280 GUESS=$UNAME_MACHINE_ARCH-unknown-secbsd$UNAME_RELEASE
281 ;;
282 *:LibertyBSD:*:*)
283 UNAME_MACHINE_ARCH=`arch | sed 's/^.*BSD\.//'`
284 GUESS=$UNAME_MACHINE_ARCH-unknown-libertybsd$UNAME_RELEASE
285 ;;
286 *:MidnightBSD:*:*)
287 GUESS=$UNAME_MACHINE-unknown-midnightbsd$UNAME_RELEASE
288 ;;
289 *:ekkoBSD:*:*)
290 GUESS=$UNAME_MACHINE-unknown-ekkobsd$UNAME_RELEASE
291 ;;
292 *:SolidBSD:*:*)
293 GUESS=$UNAME_MACHINE-unknown-solidbsd$UNAME_RELEASE
294 ;;
295 *:OS108:*:*)
296 GUESS=$UNAME_MACHINE-unknown-os108_$UNAME_RELEASE
297 ;;
298 macppc:MirBSD:*:*)
299 GUESS=powerpc-unknown-mirbsd$UNAME_RELEASE
300 ;;
301 *:MirBSD:*:*)
302 GUESS=$UNAME_MACHINE-unknown-mirbsd$UNAME_RELEASE
303 ;;
304 *:Sortix:*:*)
305 GUESS=$UNAME_MACHINE-unknown-sortix
306 ;;
307 *:Twizzler:*:*)
308 GUESS=$UNAME_MACHINE-unknown-twizzler
309 ;;
310 *:Redox:*:*)
311 GUESS=$UNAME_MACHINE-unknown-redox
312 ;;
313 mips:OSF1:*.*)
314 GUESS=mips-dec-osf1
315 ;;
316 alpha:OSF1:*:*)
317 # Reset EXIT trap before exiting to avoid spurious non-zero exit code.
318 trap '' 0
319 case $UNAME_RELEASE in
320 *4.0)
321 UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'`
322 ;;
323 *5.*)
@@ -287,11 +327,11 @@
327 # According to Compaq, /usr/sbin/psrinfo has been available on
328 # OSF/1 and Tru64 systems produced since 1995. I hope that
329 # covers most systems running today. This code pipes the CPU
330 # types through head -n 1, so we only detect the type of CPU 0.
331 ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1`
332 case $ALPHA_CPU_TYPE in
333 "EV4 (21064)")
334 UNAME_MACHINE=alpha ;;
335 "EV4.5 (21064)")
336 UNAME_MACHINE=alpha ;;
337 "LCA4 (21066/21068)")
@@ -324,167 +364,171 @@
364 # A Pn.n version is a patched version.
365 # A Vn.n version is a released version.
366 # A Tn.n version is a released field test version.
367 # A Xn.n version is an unreleased experimental baselevel.
368 # 1.2 uses "1.2" for uname -r.
369 OSF_REL=`echo "$UNAME_RELEASE" | sed -e 's/^[PVTX]//' | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`
370 GUESS=$UNAME_MACHINE-dec-osf$OSF_REL
371 ;;
 
 
372 Amiga*:UNIX_System_V:4.0:*)
373 GUESS=m68k-unknown-sysv4
374 ;;
375 *:[Aa]miga[Oo][Ss]:*:*)
376 GUESS=$UNAME_MACHINE-unknown-amigaos
377 ;;
378 *:[Mm]orph[Oo][Ss]:*:*)
379 GUESS=$UNAME_MACHINE-unknown-morphos
380 ;;
381 *:OS/390:*:*)
382 GUESS=i370-ibm-openedition
383 ;;
384 *:z/VM:*:*)
385 GUESS=s390-ibm-zvmoe
386 ;;
387 *:OS400:*:*)
388 GUESS=powerpc-ibm-os400
389 ;;
390 arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
391 GUESS=arm-acorn-riscix$UNAME_RELEASE
392 ;;
393 arm*:riscos:*:*|arm*:RISCOS:*:*)
394 GUESS=arm-unknown-riscos
395 ;;
396 SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*)
397 GUESS=hppa1.1-hitachi-hiuxmpp
398 ;;
399 Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*)
400 # [email protected] (Earle F. Ake) contributed MIS and NILE.
401 case `(/bin/universe) 2>/dev/null` in
402 att) GUESS=pyramid-pyramid-sysv3 ;;
403 *) GUESS=pyramid-pyramid-bsd ;;
404 esac
405 ;;
 
406 NILE*:*:*:dcosx)
407 GUESS=pyramid-pyramid-svr4
408 ;;
409 DRS?6000:unix:4.0:6*)
410 GUESS=sparc-icl-nx6
411 ;;
412 DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*)
413 case `/usr/bin/uname -p` in
414 sparc) GUESS=sparc-icl-nx7 ;;
415 esac
416 ;;
417 s390x:SunOS:*:*)
418 SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'`
419 GUESS=$UNAME_MACHINE-ibm-solaris2$SUN_REL
420 ;;
421 sun4H:SunOS:5.*:*)
422 SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'`
423 GUESS=sparc-hal-solaris2$SUN_REL
424 ;;
425 sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*)
426 SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'`
427 GUESS=sparc-sun-solaris2$SUN_REL
428 ;;
429 i86pc:AuroraUX:5.*:* | i86xen:AuroraUX:5.*:*)
430 GUESS=i386-pc-auroraux$UNAME_RELEASE
431 ;;
432 i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*)
433 set_cc_for_build
434 SUN_ARCH=i386
435 # If there is a compiler, see if it is configured for 64-bit objects.
436 # Note that the Sun cc does not turn __LP64__ into 1 like gcc does.
437 # This test works for both compilers.
438 if test "$CC_FOR_BUILD" != no_compiler_found; then
439 if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \
440 (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \
441 grep IS_64BIT_ARCH >/dev/null
442 then
443 SUN_ARCH=x86_64
444 fi
445 fi
446 SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'`
447 GUESS=$SUN_ARCH-pc-solaris2$SUN_REL
448 ;;
449 sun4*:SunOS:6*:*)
450 # According to config.sub, this is the proper way to canonicalize
451 # SunOS6. Hard to guess exactly what SunOS6 will be like, but
452 # it's likely to be more like Solaris than SunOS4.
453 SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'`
454 GUESS=sparc-sun-solaris3$SUN_REL
455 ;;
456 sun4*:SunOS:*:*)
457 case `/usr/bin/arch -k` in
458 Series*|S4*)
459 UNAME_RELEASE=`uname -v`
460 ;;
461 esac
462 # Japanese Language versions have a version number like `4.1.3-JL'.
463 SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/-/_/'`
464 GUESS=sparc-sun-sunos$SUN_REL
465 ;;
466 sun3*:SunOS:*:*)
467 GUESS=m68k-sun-sunos$UNAME_RELEASE
468 ;;
469 sun*:*:4.2BSD:*)
470 UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null`
471 test "x$UNAME_RELEASE" = x && UNAME_RELEASE=3
472 case `/bin/arch` in
473 sun3)
474 GUESS=m68k-sun-sunos$UNAME_RELEASE
475 ;;
476 sun4)
477 GUESS=sparc-sun-sunos$UNAME_RELEASE
478 ;;
479 esac
480 ;;
481 aushp:SunOS:*:*)
482 GUESS=sparc-auspex-sunos$UNAME_RELEASE
483 ;;
484 # The situation for MiNT is a little confusing. The machine name
485 # can be virtually everything (everything which is not
486 # "atarist" or "atariste" at least should have a processor
487 # > m68000). The system name ranges from "MiNT" over "FreeMiNT"
488 # to the lowercase version "mint" (or "freemint"). Finally
489 # the system name "TOS" denotes a system which is actually not
490 # MiNT. But MiNT is downward compatible to TOS, so this should
491 # be no problem.
492 atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*)
493 GUESS=m68k-atari-mint$UNAME_RELEASE
494 ;;
495 atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*)
496 GUESS=m68k-atari-mint$UNAME_RELEASE
497 ;;
498 *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*)
499 GUESS=m68k-atari-mint$UNAME_RELEASE
500 ;;
501 milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*)
502 GUESS=m68k-milan-mint$UNAME_RELEASE
503 ;;
504 hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*)
505 GUESS=m68k-hades-mint$UNAME_RELEASE
506 ;;
507 *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*)
508 GUESS=m68k-unknown-mint$UNAME_RELEASE
509 ;;
510 m68k:machten:*:*)
511 GUESS=m68k-apple-machten$UNAME_RELEASE
512 ;;
513 powerpc:machten:*:*)
514 GUESS=powerpc-apple-machten$UNAME_RELEASE
515 ;;
516 RISC*:Mach:*:*)
517 GUESS=mips-dec-mach_bsd4.3
518 ;;
519 RISC*:ULTRIX:*:*)
520 GUESS=mips-dec-ultrix$UNAME_RELEASE
521 ;;
522 VAX*:ULTRIX*:*:*)
523 GUESS=vax-dec-ultrix$UNAME_RELEASE
524 ;;
525 2020:CLIX:*:* | 2430:CLIX:*:*)
526 GUESS=clipper-intergraph-clix$UNAME_RELEASE
527 ;;
528 mips:*:*:UMIPS | mips:*:*:RISCos)
529 set_cc_for_build
530 sed 's/^ //' << EOF > "$dummy.c"
531 #ifdef __cplusplus
532 #include <stdio.h> /* for printf() prototype */
533 int main (int argc, char *argv[]) {
534 #else
@@ -506,82 +550,83 @@
550 EOF
551 $CC_FOR_BUILD -o "$dummy" "$dummy.c" &&
552 dummyarg=`echo "$UNAME_RELEASE" | sed -n 's/\([0-9]*\).*/\1/p'` &&
553 SYSTEM_NAME=`"$dummy" "$dummyarg"` &&
554 { echo "$SYSTEM_NAME"; exit; }
555 GUESS=mips-mips-riscos$UNAME_RELEASE
556 ;;
557 Motorola:PowerMAX_OS:*:*)
558 GUESS=powerpc-motorola-powermax
559 ;;
560 Motorola:*:4.3:PL8-*)
561 GUESS=powerpc-harris-powermax
562 ;;
563 Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*)
564 GUESS=powerpc-harris-powermax
565 ;;
566 Night_Hawk:Power_UNIX:*:*)
567 GUESS=powerpc-harris-powerunix
568 ;;
569 m88k:CX/UX:7*:*)
570 GUESS=m88k-harris-cxux7
571 ;;
572 m88k:*:4*:R4*)
573 GUESS=m88k-motorola-sysv4
574 ;;
575 m88k:*:3*:R3*)
576 GUESS=m88k-motorola-sysv3
577 ;;
578 AViiON:dgux:*:*)
579 # DG/UX returns AViiON for all architectures
580 UNAME_PROCESSOR=`/usr/bin/uname -p`
581 if test "$UNAME_PROCESSOR" = mc88100 || test "$UNAME_PROCESSOR" = mc88110
582 then
583 if test "$TARGET_BINARY_INTERFACE"x = m88kdguxelfx || \
584 test "$TARGET_BINARY_INTERFACE"x = x
585 then
586 GUESS=m88k-dg-dgux$UNAME_RELEASE
587 else
588 GUESS=m88k-dg-dguxbcs$UNAME_RELEASE
589 fi
590 else
591 GUESS=i586-dg-dgux$UNAME_RELEASE
592 fi
593 ;;
594 M88*:DolphinOS:*:*) # DolphinOS (SVR3)
595 GUESS=m88k-dolphin-sysv3
596 ;;
597 M88*:*:R3*:*)
598 # Delta 88k system running SVR3
599 GUESS=m88k-motorola-sysv3
600 ;;
601 XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3)
602 GUESS=m88k-tektronix-sysv3
603 ;;
604 Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD)
605 GUESS=m68k-tektronix-bsd
606 ;;
607 *:IRIX*:*:*)
608 IRIX_REL=`echo "$UNAME_RELEASE" | sed -e 's/-/_/g'`
609 GUESS=mips-sgi-irix$IRIX_REL
610 ;;
611 ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX.
612 GUESS=romp-ibm-aix # uname -m gives an 8 hex-code CPU id
613 ;; # Note that: echo "'`uname -s`'" gives 'AIX '
614 i*86:AIX:*:*)
615 GUESS=i386-ibm-aix
616 ;;
617 ia64:AIX:*:*)
618 if test -x /usr/bin/oslevel ; then
619 IBM_REV=`/usr/bin/oslevel`
620 else
621 IBM_REV=$UNAME_VERSION.$UNAME_RELEASE
622 fi
623 GUESS=$UNAME_MACHINE-ibm-aix$IBM_REV
624 ;;
625 *:AIX:2:3)
626 if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then
627 set_cc_for_build
628 sed 's/^ //' << EOF > "$dummy.c"
629 #include <sys/systemcfg.h>
630
631 main()
632 {
@@ -591,78 +636,78 @@
636 exit(0);
637 }
638 EOF
639 if $CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=`"$dummy"`
640 then
641 GUESS=$SYSTEM_NAME
642 else
643 GUESS=rs6000-ibm-aix3.2.5
644 fi
645 elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then
646 GUESS=rs6000-ibm-aix3.2.4
647 else
648 GUESS=rs6000-ibm-aix3.2
649 fi
650 ;;
651 *:AIX:*:[4567])
652 IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`
653 if /usr/sbin/lsattr -El "$IBM_CPU_ID" | grep ' POWER' >/dev/null 2>&1; then
654 IBM_ARCH=rs6000
655 else
656 IBM_ARCH=powerpc
657 fi
658 if test -x /usr/bin/lslpp ; then
659 IBM_REV=`/usr/bin/lslpp -Lqc bos.rte.libc | \
660 awk -F: '{ print $3 }' | sed s/[0-9]*$/0/`
661 else
662 IBM_REV=$UNAME_VERSION.$UNAME_RELEASE
663 fi
664 GUESS=$IBM_ARCH-ibm-aix$IBM_REV
665 ;;
666 *:AIX:*:*)
667 GUESS=rs6000-ibm-aix
668 ;;
669 ibmrt:4.4BSD:*|romp-ibm:4.4BSD:*)
670 GUESS=romp-ibm-bsd4.4
671 ;;
672 ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and
673 GUESS=romp-ibm-bsd$UNAME_RELEASE # 4.3 with uname added to
674 ;; # report: romp-ibm BSD 4.3
675 *:BOSX:*:*)
676 GUESS=rs6000-bull-bosx
677 ;;
678 DPX/2?00:B.O.S.:*:*)
679 GUESS=m68k-bull-sysv3
680 ;;
681 9000/[34]??:4.3bsd:1.*:*)
682 GUESS=m68k-hp-bsd
683 ;;
684 hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*)
685 GUESS=m68k-hp-bsd4.4
686 ;;
687 9000/[34678]??:HP-UX:*:*)
688 HPUX_REV=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*.[0B]*//'`
689 case $UNAME_MACHINE in
690 9000/31?) HP_ARCH=m68000 ;;
691 9000/[34]??) HP_ARCH=m68k ;;
692 9000/[678][0-9][0-9])
693 if test -x /usr/bin/getconf; then
694 sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null`
695 sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`
696 case $sc_cpu_version in
697 523) HP_ARCH=hppa1.0 ;; # CPU_PA_RISC1_0
698 528) HP_ARCH=hppa1.1 ;; # CPU_PA_RISC1_1
699 532) # CPU_PA_RISC2_0
700 case $sc_kernel_bits in
701 32) HP_ARCH=hppa2.0n ;;
702 64) HP_ARCH=hppa2.0w ;;
703 '') HP_ARCH=hppa2.0 ;; # HP-UX 10.20
704 esac ;;
705 esac
706 fi
707 if test "$HP_ARCH" = ""; then
708 set_cc_for_build
709 sed 's/^ //' << EOF > "$dummy.c"
710
711 #define _HPUX_SOURCE
712 #include <stdlib.h>
713 #include <unistd.h>
@@ -696,13 +741,13 @@
741 EOF
742 (CCOPTS="" $CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null) && HP_ARCH=`"$dummy"`
743 test -z "$HP_ARCH" && HP_ARCH=hppa
744 fi ;;
745 esac
746 if test "$HP_ARCH" = hppa2.0w
747 then
748 set_cc_for_build
749
750 # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating
751 # 32-bit code. hppa64-hp-hpux* has the same kernel and a compiler
752 # generating 64-bit code. GNU and HP use different nomenclature:
753 #
@@ -717,18 +762,18 @@
762 HP_ARCH=hppa2.0w
763 else
764 HP_ARCH=hppa64
765 fi
766 fi
767 GUESS=$HP_ARCH-hp-hpux$HPUX_REV
768 ;;
769 ia64:HP-UX:*:*)
770 HPUX_REV=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*.[0B]*//'`
771 GUESS=ia64-hp-hpux$HPUX_REV
772 ;;
773 3050*:HI-UX:*:*)
774 set_cc_for_build
775 sed 's/^ //' << EOF > "$dummy.c"
776 #include <unistd.h>
777 int
778 main ()
779 {
@@ -752,162 +797,186 @@
797 exit (0);
798 }
799 EOF
800 $CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=`"$dummy"` &&
801 { echo "$SYSTEM_NAME"; exit; }
802 GUESS=unknown-hitachi-hiuxwe2
803 ;;
804 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:*)
805 GUESS=hppa1.1-hp-bsd
806 ;;
807 9000/8??:4.3bsd:*:*)
808 GUESS=hppa1.0-hp-bsd
809 ;;
810 *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*)
811 GUESS=hppa1.0-hp-mpeix
812 ;;
813 hp7??:OSF1:*:* | hp8?[79]:OSF1:*:*)
814 GUESS=hppa1.1-hp-osf
815 ;;
816 hp8??:OSF1:*:*)
817 GUESS=hppa1.0-hp-osf
818 ;;
819 i*86:OSF1:*:*)
820 if test -x /usr/sbin/sysversion ; then
821 GUESS=$UNAME_MACHINE-unknown-osf1mk
822 else
823 GUESS=$UNAME_MACHINE-unknown-osf1
824 fi
825 ;;
826 parisc*:Lites*:*:*)
827 GUESS=hppa1.1-hp-lites
828 ;;
829 C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*)
830 GUESS=c1-convex-bsd
831 ;;
832 C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*)
833 if getsysinfo -f scalar_acc
834 then echo c32-convex-bsd
835 else echo c2-convex-bsd
836 fi
837 exit ;;
838 C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*)
839 GUESS=c34-convex-bsd
840 ;;
841 C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*)
842 GUESS=c38-convex-bsd
843 ;;
844 C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*)
845 GUESS=c4-convex-bsd
846 ;;
847 CRAY*Y-MP:*:*:*)
848 CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'`
849 GUESS=ymp-cray-unicos$CRAY_REL
850 ;;
851 CRAY*[A-Z]90:*:*:*)
852 echo "$UNAME_MACHINE"-cray-unicos"$UNAME_RELEASE" \
853 | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \
854 -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \
855 -e 's/\.[^.]*$/.X/'
856 exit ;;
857 CRAY*TS:*:*:*)
858 CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'`
859 GUESS=t90-cray-unicos$CRAY_REL
860 ;;
861 CRAY*T3E:*:*:*)
862 CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'`
863 GUESS=alphaev5-cray-unicosmk$CRAY_REL
864 ;;
865 CRAY*SV1:*:*:*)
866 CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'`
867 GUESS=sv1-cray-unicos$CRAY_REL
868 ;;
869 *:UNICOS/mp:*:*)
870 CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'`
871 GUESS=craynv-cray-unicosmp$CRAY_REL
872 ;;
873 F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*)
874 FUJITSU_PROC=`uname -m | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`
875 FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'`
876 FUJITSU_REL=`echo "$UNAME_RELEASE" | sed -e 's/ /_/'`
877 GUESS=${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}
878 ;;
879 5000:UNIX_System_V:4.*:*)
880 FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'`
881 FUJITSU_REL=`echo "$UNAME_RELEASE" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/ /_/'`
882 GUESS=sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}
883 ;;
884 i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*)
885 GUESS=$UNAME_MACHINE-pc-bsdi$UNAME_RELEASE
886 ;;
887 sparc*:BSD/OS:*:*)
888 GUESS=sparc-unknown-bsdi$UNAME_RELEASE
889 ;;
890 *:BSD/OS:*:*)
891 GUESS=$UNAME_MACHINE-unknown-bsdi$UNAME_RELEASE
892 ;;
893 arm:FreeBSD:*:*)
894 UNAME_PROCESSOR=`uname -p`
895 set_cc_for_build
896 if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \
897 | grep -q __ARM_PCS_VFP
898 then
899 FREEBSD_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'`
900 GUESS=$UNAME_PROCESSOR-unknown-freebsd$FREEBSD_REL-gnueabi
901 else
902 FREEBSD_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'`
903 GUESS=$UNAME_PROCESSOR-unknown-freebsd$FREEBSD_REL-gnueabihf
904 fi
905 ;;
906 *:FreeBSD:*:*)
907 UNAME_PROCESSOR=`/usr/bin/uname -p`
908 case $UNAME_PROCESSOR in
909 amd64)
910 UNAME_PROCESSOR=x86_64 ;;
911 i386)
912 UNAME_PROCESSOR=i586 ;;
913 esac
914 FREEBSD_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'`
915 GUESS=$UNAME_PROCESSOR-unknown-freebsd$FREEBSD_REL
916 ;;
917 i*:CYGWIN*:*)
918 GUESS=$UNAME_MACHINE-pc-cygwin
919 ;;
920 *:MINGW64*:*)
921 GUESS=$UNAME_MACHINE-pc-mingw64
922 ;;
923 *:MINGW*:*)
924 GUESS=$UNAME_MACHINE-pc-mingw32
925 ;;
926 *:MSYS*:*)
927 GUESS=$UNAME_MACHINE-pc-msys
928 ;;
929 i*:PW*:*)
930 GUESS=$UNAME_MACHINE-pc-pw32
931 ;;
932 *:Interix*:*)
933 case $UNAME_MACHINE in
934 x86)
935 GUESS=i586-pc-interix$UNAME_RELEASE
936 ;;
937 authenticamd | genuineintel | EM64T)
938 GUESS=x86_64-unknown-interix$UNAME_RELEASE
939 ;;
940 IA64)
941 GUESS=ia64-unknown-interix$UNAME_RELEASE
942 ;;
943 esac ;;
944 i*:UWIN*:*)
945 GUESS=$UNAME_MACHINE-pc-uwin
946 ;;
947 amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*)
948 GUESS=x86_64-pc-cygwin
949 ;;
950 prep*:SunOS:5.*:*)
951 SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'`
952 GUESS=powerpcle-unknown-solaris2$SUN_REL
953 ;;
954 *:GNU:*:*)
955 # the GNU system
956 GNU_ARCH=`echo "$UNAME_MACHINE" | sed -e 's,[-/].*$,,'`
957 GNU_REL=`echo "$UNAME_RELEASE" | sed -e 's,/.*$,,'`
958 GUESS=$GNU_ARCH-unknown-$LIBC$GNU_REL
959 ;;
960 *:GNU/*:*:*)
961 # other systems with GNU libc and userland
962 GNU_SYS=`echo "$UNAME_SYSTEM" | sed 's,^[^/]*/,,' | tr "[:upper:]" "[:lower:]"`
963 GNU_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'`
964 GUESS=$UNAME_MACHINE-unknown-$GNU_SYS$GNU_REL-$LIBC
965 ;;
966 *:Minix:*:*)
967 GUESS=$UNAME_MACHINE-unknown-minix
968 ;;
969 aarch64:Linux:*:*)
970 GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
971 ;;
972 aarch64_be:Linux:*:*)
973 UNAME_MACHINE=aarch64_be
974 GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
975 ;;
976 alpha:Linux:*:*)
977 case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' /proc/cpuinfo 2>/dev/null` in
978 EV5) UNAME_MACHINE=alphaev5 ;;
979 EV56) UNAME_MACHINE=alphaev56 ;;
980 PCA56) UNAME_MACHINE=alphapca56 ;;
981 PCA57) UNAME_MACHINE=alphapca56 ;;
982 EV6) UNAME_MACHINE=alphaev6 ;;
@@ -914,246 +983,288 @@
983 EV67) UNAME_MACHINE=alphaev67 ;;
984 EV68*) UNAME_MACHINE=alphaev68 ;;
985 esac
986 objdump --private-headers /bin/sh | grep -q ld.so.1
987 if test "$?" = 0 ; then LIBC=gnulibc1 ; fi
988 GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
989 ;;
990 arc:Linux:*:* | arceb:Linux:*:* | arc32:Linux:*:* | arc64:Linux:*:*)
991 GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
992 ;;
993 arm*:Linux:*:*)
994 set_cc_for_build
995 if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \
996 | grep -q __ARM_EABI__
997 then
998 GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
999 else
1000 if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \
1001 | grep -q __ARM_PCS_VFP
1002 then
1003 GUESS=$UNAME_MACHINE-unknown-linux-${LIBC}eabi
1004 else
1005 GUESS=$UNAME_MACHINE-unknown-linux-${LIBC}eabihf
1006 fi
1007 fi
1008 ;;
1009 avr32*:Linux:*:*)
1010 GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
1011 ;;
1012 cris:Linux:*:*)
1013 GUESS=$UNAME_MACHINE-axis-linux-$LIBC
1014 ;;
1015 crisv32:Linux:*:*)
1016 GUESS=$UNAME_MACHINE-axis-linux-$LIBC
1017 ;;
1018 e2k:Linux:*:*)
1019 GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
1020 ;;
1021 frv:Linux:*:*)
1022 GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
1023 ;;
1024 hexagon:Linux:*:*)
1025 GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
1026 ;;
1027 i*86:Linux:*:*)
1028 GUESS=$UNAME_MACHINE-pc-linux-$LIBC
1029 ;;
1030 ia64:Linux:*:*)
1031 GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
1032 ;;
1033 k1om:Linux:*:*)
1034 GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
1035 ;;
1036 loongarch32:Linux:*:* | loongarch64:Linux:*:* | loongarchx32:Linux:*:*)
1037 GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
1038 ;;
1039 m32r*:Linux:*:*)
1040 GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
1041 ;;
1042 m68*:Linux:*:*)
1043 GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
1044 ;;
1045 mips:Linux:*:* | mips64:Linux:*:*)
1046 set_cc_for_build
1047 IS_GLIBC=0
1048 test x"${LIBC}" = xgnu && IS_GLIBC=1
1049 sed 's/^ //' << EOF > "$dummy.c"
1050 #undef CPU
1051 #undef mips
1052 #undef mipsel
1053 #undef mips64
1054 #undef mips64el
1055 #if ${IS_GLIBC} && defined(_ABI64)
1056 LIBCABI=gnuabi64
1057 #else
1058 #if ${IS_GLIBC} && defined(_ABIN32)
1059 LIBCABI=gnuabin32
1060 #else
1061 LIBCABI=${LIBC}
1062 #endif
1063 #endif
1064
1065 #if ${IS_GLIBC} && defined(__mips64) && defined(__mips_isa_rev) && __mips_isa_rev>=6
1066 CPU=mipsisa64r6
1067 #else
1068 #if ${IS_GLIBC} && !defined(__mips64) && defined(__mips_isa_rev) && __mips_isa_rev>=6
1069 CPU=mipsisa32r6
1070 #else
1071 #if defined(__mips64)
1072 CPU=mips64
1073 #else
1074 CPU=mips
1075 #endif
1076 #endif
1077 #endif
1078
1079 #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
1080 MIPS_ENDIAN=el
1081 #else
1082 #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
1083 MIPS_ENDIAN=
1084 #else
1085 MIPS_ENDIAN=
1086 #endif
1087 #endif
1088 EOF
1089 cc_set_vars=`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^CPU\|^MIPS_ENDIAN\|^LIBCABI'`
1090 eval "$cc_set_vars"
1091 test "x$CPU" != x && { echo "$CPU${MIPS_ENDIAN}-unknown-linux-$LIBCABI"; exit; }
1092 ;;
1093 mips64el:Linux:*:*)
1094 GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
1095 ;;
1096 openrisc*:Linux:*:*)
1097 GUESS=or1k-unknown-linux-$LIBC
1098 ;;
1099 or32:Linux:*:* | or1k*:Linux:*:*)
1100 GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
1101 ;;
1102 padre:Linux:*:*)
1103 GUESS=sparc-unknown-linux-$LIBC
1104 ;;
1105 parisc64:Linux:*:* | hppa64:Linux:*:*)
1106 GUESS=hppa64-unknown-linux-$LIBC
1107 ;;
1108 parisc:Linux:*:* | hppa:Linux:*:*)
1109 # Look for CPU level
1110 case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in
1111 PA7*) GUESS=hppa1.1-unknown-linux-$LIBC ;;
1112 PA8*) GUESS=hppa2.0-unknown-linux-$LIBC ;;
1113 *) GUESS=hppa-unknown-linux-$LIBC ;;
1114 esac
1115 ;;
1116 ppc64:Linux:*:*)
1117 GUESS=powerpc64-unknown-linux-$LIBC
1118 ;;
1119 ppc:Linux:*:*)
1120 GUESS=powerpc-unknown-linux-$LIBC
1121 ;;
1122 ppc64le:Linux:*:*)
1123 GUESS=powerpc64le-unknown-linux-$LIBC
1124 ;;
1125 ppcle:Linux:*:*)
1126 GUESS=powerpcle-unknown-linux-$LIBC
1127 ;;
1128 riscv32:Linux:*:* | riscv32be:Linux:*:* | riscv64:Linux:*:* | riscv64be:Linux:*:*)
1129 GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
1130 ;;
1131 s390:Linux:*:* | s390x:Linux:*:*)
1132 GUESS=$UNAME_MACHINE-ibm-linux-$LIBC
1133 ;;
1134 sh64*:Linux:*:*)
1135 GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
1136 ;;
1137 sh*:Linux:*:*)
1138 GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
1139 ;;
1140 sparc:Linux:*:* | sparc64:Linux:*:*)
1141 GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
1142 ;;
1143 tile*:Linux:*:*)
1144 GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
1145 ;;
1146 vax:Linux:*:*)
1147 GUESS=$UNAME_MACHINE-dec-linux-$LIBC
1148 ;;
1149 x86_64:Linux:*:*)
1150 set_cc_for_build
1151 LIBCABI=$LIBC
1152 if test "$CC_FOR_BUILD" != no_compiler_found; then
1153 if (echo '#ifdef __ILP32__'; echo IS_X32; echo '#endif') | \
1154 (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \
1155 grep IS_X32 >/dev/null
1156 then
1157 LIBCABI=${LIBC}x32
1158 fi
1159 fi
1160 GUESS=$UNAME_MACHINE-pc-linux-$LIBCABI
1161 ;;
1162 xtensa*:Linux:*:*)
1163 GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
1164 ;;
1165 i*86:DYNIX/ptx:4*:*)
1166 # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there.
1167 # earlier versions are messed up and put the nodename in both
1168 # sysname and nodename.
1169 GUESS=i386-sequent-sysv4
1170 ;;
1171 i*86:UNIX_SV:4.2MP:2.*)
1172 # Unixware is an offshoot of SVR4, but it has its own version
1173 # number series starting with 2...
1174 # I am not positive that other SVR4 systems won't match this,
1175 # I just have to hope. -- rms.
1176 # Use sysv4.2uw... so that sysv4* matches it.
1177 GUESS=$UNAME_MACHINE-pc-sysv4.2uw$UNAME_VERSION
1178 ;;
1179 i*86:OS/2:*:*)
1180 # If we were able to find `uname', then EMX Unix compatibility
1181 # is probably installed.
1182 GUESS=$UNAME_MACHINE-pc-os2-emx
1183 ;;
1184 i*86:XTS-300:*:STOP)
1185 GUESS=$UNAME_MACHINE-unknown-stop
1186 ;;
1187 i*86:atheos:*:*)
1188 GUESS=$UNAME_MACHINE-unknown-atheos
1189 ;;
1190 i*86:syllable:*:*)
1191 GUESS=$UNAME_MACHINE-pc-syllable
1192 ;;
1193 i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.[02]*:*)
1194 GUESS=i386-unknown-lynxos$UNAME_RELEASE
1195 ;;
1196 i*86:*DOS:*:*)
1197 GUESS=$UNAME_MACHINE-pc-msdosdjgpp
1198 ;;
1199 i*86:*:4.*:*)
1200 UNAME_REL=`echo "$UNAME_RELEASE" | sed 's/\/MP$//'`
1201 if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then
1202 GUESS=$UNAME_MACHINE-univel-sysv$UNAME_REL
1203 else
1204 GUESS=$UNAME_MACHINE-pc-sysv$UNAME_REL
1205 fi
1206 ;;
1207 i*86:*:5:[678]*)
1208 # UnixWare 7.x, OpenUNIX and OpenServer 6.
1209 case `/bin/uname -X | grep "^Machine"` in
1210 *486*) UNAME_MACHINE=i486 ;;
1211 *Pentium) UNAME_MACHINE=i586 ;;
1212 *Pent*|*Celeron) UNAME_MACHINE=i686 ;;
1213 esac
1214 GUESS=$UNAME_MACHINE-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION}
1215 ;;
1216 i*86:*:3.2:*)
1217 if test -f /usr/options/cb.name; then
1218 UNAME_REL=`sed -n 's/.*Version //p' </usr/options/cb.name`
1219 GUESS=$UNAME_MACHINE-pc-isc$UNAME_REL
1220 elif /bin/uname -X 2>/dev/null >/dev/null ; then
1221 UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')`
1222 (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486
1223 (/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \
1224 && UNAME_MACHINE=i586
1225 (/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \
1226 && UNAME_MACHINE=i686
1227 (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \
1228 && UNAME_MACHINE=i686
1229 GUESS=$UNAME_MACHINE-pc-sco$UNAME_REL
1230 else
1231 GUESS=$UNAME_MACHINE-pc-sysv32
1232 fi
1233 ;;
1234 pc:*:*:*)
1235 # Left here for compatibility:
1236 # uname -m prints for DJGPP always 'pc', but it prints nothing about
1237 # the processor, so we play safe by assuming i586.
1238 # Note: whatever this is, it MUST be the same as what config.sub
1239 # prints for the "djgpp" host, or else GDB configure will decide that
1240 # this is a cross-build.
1241 GUESS=i586-pc-msdosdjgpp
1242 ;;
1243 Intel:Mach:3*:*)
1244 GUESS=i386-pc-mach3
1245 ;;
1246 paragon:*:*:*)
1247 GUESS=i860-intel-osf1
1248 ;;
1249 i860:*:4.*:*) # i860-SVR4
1250 if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then
1251 GUESS=i860-stardent-sysv$UNAME_RELEASE # Stardent Vistra i860-SVR4
1252 else # Add other i860-SVR4 vendors below as they are discovered.
1253 GUESS=i860-unknown-sysv$UNAME_RELEASE # Unknown i860-SVR4
1254 fi
1255 ;;
1256 mini*:CTIX:SYS*5:*)
1257 # "miniframe"
1258 GUESS=m68010-convergent-sysv
1259 ;;
1260 mc68k:UNIX:SYSTEM5:3.51m)
1261 GUESS=m68k-convergent-sysv
1262 ;;
1263 M680?0:D-NIX:5.3:*)
1264 GUESS=m68k-diab-dnix
1265 ;;
1266 M68*:*:R3V[5678]*:*)
1267 test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;;
1268 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)
1269 OS_REL=''
1270 test -r /etc/.relid \
@@ -1174,253 +1285,405 @@
1285 /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
1286 && { echo i586-ncr-sysv4.3"$OS_REL"; exit; }
1287 /bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \
1288 && { echo i586-ncr-sysv4.3"$OS_REL"; exit; } ;;
1289 m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*)
1290 GUESS=m68k-unknown-lynxos$UNAME_RELEASE
1291 ;;
1292 mc68030:UNIX_System_V:4.*:*)
1293 GUESS=m68k-atari-sysv4
1294 ;;
1295 TSUNAMI:LynxOS:2.*:*)
1296 GUESS=sparc-unknown-lynxos$UNAME_RELEASE
1297 ;;
1298 rs6000:LynxOS:2.*:*)
1299 GUESS=rs6000-unknown-lynxos$UNAME_RELEASE
1300 ;;
1301 PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.[02]*:*)
1302 GUESS=powerpc-unknown-lynxos$UNAME_RELEASE
1303 ;;
1304 SM[BE]S:UNIX_SV:*:*)
1305 GUESS=mips-dde-sysv$UNAME_RELEASE
1306 ;;
1307 RM*:ReliantUNIX-*:*:*)
1308 GUESS=mips-sni-sysv4
1309 ;;
1310 RM*:SINIX-*:*:*)
1311 GUESS=mips-sni-sysv4
1312 ;;
1313 *:SINIX-*:*:*)
1314 if uname -p 2>/dev/null >/dev/null ; then
1315 UNAME_MACHINE=`(uname -p) 2>/dev/null`
1316 GUESS=$UNAME_MACHINE-sni-sysv4
1317 else
1318 GUESS=ns32k-sni-sysv
1319 fi
1320 ;;
1321 PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort
1322 # says <[email protected]>
1323 GUESS=i586-unisys-sysv4
1324 ;;
1325 *:UNIX_System_V:4*:FTX*)
1326 # From Gerald Hewes <[email protected]>.
1327 # How about differentiating between stratus architectures? -djm
1328 GUESS=hppa1.1-stratus-sysv4
1329 ;;
1330 *:*:*:FTX*)
1331 # From [email protected].
1332 GUESS=i860-stratus-sysv4
1333 ;;
1334 i*86:VOS:*:*)
1335 # From [email protected].
1336 GUESS=$UNAME_MACHINE-stratus-vos
1337 ;;
1338 *:VOS:*:*)
1339 # From [email protected].
1340 GUESS=hppa1.1-stratus-vos
1341 ;;
1342 mc68*:A/UX:*:*)
1343 GUESS=m68k-apple-aux$UNAME_RELEASE
1344 ;;
1345 news*:NEWS-OS:6*:*)
1346 GUESS=mips-sony-newsos6
1347 ;;
1348 R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*)
1349 if test -d /usr/nec; then
1350 GUESS=mips-nec-sysv$UNAME_RELEASE
1351 else
1352 GUESS=mips-unknown-sysv$UNAME_RELEASE
1353 fi
1354 ;;
1355 BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only.
1356 GUESS=powerpc-be-beos
1357 ;;
1358 BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only.
1359 GUESS=powerpc-apple-beos
1360 ;;
1361 BePC:BeOS:*:*) # BeOS running on Intel PC compatible.
1362 GUESS=i586-pc-beos
1363 ;;
1364 BePC:Haiku:*:*) # Haiku running on Intel PC compatible.
1365 GUESS=i586-pc-haiku
1366 ;;
1367 x86_64:Haiku:*:*)
1368 GUESS=x86_64-unknown-haiku
1369 ;;
1370 SX-4:SUPER-UX:*:*)
1371 GUESS=sx4-nec-superux$UNAME_RELEASE
1372 ;;
1373 SX-5:SUPER-UX:*:*)
1374 GUESS=sx5-nec-superux$UNAME_RELEASE
1375 ;;
1376 SX-6:SUPER-UX:*:*)
1377 GUESS=sx6-nec-superux$UNAME_RELEASE
1378 ;;
1379 SX-7:SUPER-UX:*:*)
1380 GUESS=sx7-nec-superux$UNAME_RELEASE
1381 ;;
1382 SX-8:SUPER-UX:*:*)
1383 GUESS=sx8-nec-superux$UNAME_RELEASE
1384 ;;
1385 SX-8R:SUPER-UX:*:*)
1386 GUESS=sx8r-nec-superux$UNAME_RELEASE
1387 ;;
1388 SX-ACE:SUPER-UX:*:*)
1389 GUESS=sxace-nec-superux$UNAME_RELEASE
1390 ;;
1391 Power*:Rhapsody:*:*)
1392 GUESS=powerpc-apple-rhapsody$UNAME_RELEASE
1393 ;;
1394 *:Rhapsody:*:*)
1395 GUESS=$UNAME_MACHINE-apple-rhapsody$UNAME_RELEASE
1396 ;;
1397 arm64:Darwin:*:*)
1398 GUESS=aarch64-apple-darwin$UNAME_RELEASE
1399 ;;
1400 *:Darwin:*:*)
1401 UNAME_PROCESSOR=`uname -p`
1402 case $UNAME_PROCESSOR in
1403 unknown) UNAME_PROCESSOR=powerpc ;;
1404 esac
1405 if command -v xcode-select > /dev/null 2> /dev/null && \
1406 ! xcode-select --print-path > /dev/null 2> /dev/null ; then
1407 # Avoid executing cc if there is no toolchain installed as
1408 # cc will be a stub that puts up a graphical alert
1409 # prompting the user to install developer tools.
1410 CC_FOR_BUILD=no_compiler_found
1411 else
1412 set_cc_for_build
1413 fi
1414 if test "$CC_FOR_BUILD" != no_compiler_found; then
1415 if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \
1416 (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \
1417 grep IS_64BIT_ARCH >/dev/null
1418 then
1419 case $UNAME_PROCESSOR in
1420 i386) UNAME_PROCESSOR=x86_64 ;;
1421 powerpc) UNAME_PROCESSOR=powerpc64 ;;
1422 esac
1423 fi
1424 # On 10.4-10.6 one might compile for PowerPC via gcc -arch ppc
1425 if (echo '#ifdef __POWERPC__'; echo IS_PPC; echo '#endif') | \
1426 (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \
1427 grep IS_PPC >/dev/null
1428 then
1429 UNAME_PROCESSOR=powerpc
1430 fi
1431 elif test "$UNAME_PROCESSOR" = i386 ; then
1432 # uname -m returns i386 or x86_64
1433 UNAME_PROCESSOR=$UNAME_MACHINE
 
 
 
 
 
1434 fi
1435 GUESS=$UNAME_PROCESSOR-apple-darwin$UNAME_RELEASE
1436 ;;
1437 *:procnto*:*:* | *:QNX:[0123456789]*:*)
1438 UNAME_PROCESSOR=`uname -p`
1439 if test "$UNAME_PROCESSOR" = x86; then
1440 UNAME_PROCESSOR=i386
1441 UNAME_MACHINE=pc
1442 fi
1443 GUESS=$UNAME_PROCESSOR-$UNAME_MACHINE-nto-qnx$UNAME_RELEASE
1444 ;;
1445 *:QNX:*:4*)
1446 GUESS=i386-pc-qnx
1447 ;;
1448 NEO-*:NONSTOP_KERNEL:*:*)
1449 GUESS=neo-tandem-nsk$UNAME_RELEASE
1450 ;;
1451 NSE-*:NONSTOP_KERNEL:*:*)
1452 GUESS=nse-tandem-nsk$UNAME_RELEASE
1453 ;;
1454 NSR-*:NONSTOP_KERNEL:*:*)
1455 GUESS=nsr-tandem-nsk$UNAME_RELEASE
1456 ;;
1457 NSV-*:NONSTOP_KERNEL:*:*)
1458 GUESS=nsv-tandem-nsk$UNAME_RELEASE
1459 ;;
1460 NSX-*:NONSTOP_KERNEL:*:*)
1461 GUESS=nsx-tandem-nsk$UNAME_RELEASE
1462 ;;
1463 *:NonStop-UX:*:*)
1464 GUESS=mips-compaq-nonstopux
1465 ;;
1466 BS2000:POSIX*:*:*)
1467 GUESS=bs2000-siemens-sysv
1468 ;;
1469 DS/*:UNIX_System_V:*:*)
1470 GUESS=$UNAME_MACHINE-$UNAME_SYSTEM-$UNAME_RELEASE
1471 ;;
1472 *:Plan9:*:*)
1473 # "uname -m" is not consistent, so use $cputype instead. 386
1474 # is converted to i386 for consistency with other x86
1475 # operating systems.
1476 if test "${cputype-}" = 386; then
1477 UNAME_MACHINE=i386
1478 elif test "x${cputype-}" != x; then
1479 UNAME_MACHINE=$cputype
1480 fi
1481 GUESS=$UNAME_MACHINE-unknown-plan9
1482 ;;
1483 *:TOPS-10:*:*)
1484 GUESS=pdp10-unknown-tops10
1485 ;;
1486 *:TENEX:*:*)
1487 GUESS=pdp10-unknown-tenex
1488 ;;
1489 KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*)
1490 GUESS=pdp10-dec-tops20
1491 ;;
1492 XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*)
1493 GUESS=pdp10-xkl-tops20
1494 ;;
1495 *:TOPS-20:*:*)
1496 GUESS=pdp10-unknown-tops20
1497 ;;
1498 *:ITS:*:*)
1499 GUESS=pdp10-unknown-its
1500 ;;
1501 SEI:*:*:SEIUX)
1502 GUESS=mips-sei-seiux$UNAME_RELEASE
1503 ;;
1504 *:DragonFly:*:*)
1505 DRAGONFLY_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'`
1506 GUESS=$UNAME_MACHINE-unknown-dragonfly$DRAGONFLY_REL
1507 ;;
1508 *:*VMS:*:*)
1509 UNAME_MACHINE=`(uname -p) 2>/dev/null`
1510 case $UNAME_MACHINE in
1511 A*) GUESS=alpha-dec-vms ;;
1512 I*) GUESS=ia64-dec-vms ;;
1513 V*) GUESS=vax-dec-vms ;;
1514 esac ;;
1515 *:XENIX:*:SysV)
1516 GUESS=i386-pc-xenix
1517 ;;
1518 i*86:skyos:*:*)
1519 SKYOS_REL=`echo "$UNAME_RELEASE" | sed -e 's/ .*$//'`
1520 GUESS=$UNAME_MACHINE-pc-skyos$SKYOS_REL
1521 ;;
1522 i*86:rdos:*:*)
1523 GUESS=$UNAME_MACHINE-pc-rdos
1524 ;;
1525 *:AROS:*:*)
1526 GUESS=$UNAME_MACHINE-unknown-aros
1527 ;;
1528 x86_64:VMkernel:*:*)
1529 GUESS=$UNAME_MACHINE-unknown-esx
1530 ;;
1531 amd64:Isilon\ OneFS:*:*)
1532 GUESS=x86_64-unknown-onefs
1533 ;;
1534 *:Unleashed:*:*)
1535 GUESS=$UNAME_MACHINE-unknown-unleashed$UNAME_RELEASE
1536 ;;
1537 esac
1538
1539 # Do we have a guess based on uname results?
1540 if test "x$GUESS" != x; then
1541 echo "$GUESS"
1542 exit
1543 fi
1544
1545 # No uname command or uname output not recognized.
1546 set_cc_for_build
1547 cat > "$dummy.c" <<EOF
1548 #ifdef _SEQUENT_
1549 #include <sys/types.h>
1550 #include <sys/utsname.h>
1551 #endif
1552 #if defined(ultrix) || defined(_ultrix) || defined(__ultrix) || defined(__ultrix__)
1553 #if defined (vax) || defined (__vax) || defined (__vax__) || defined(mips) || defined(__mips) || defined(__mips__) || defined(MIPS) || defined(__MIPS__)
1554 #include <signal.h>
1555 #if defined(_SIZE_T_) || defined(SIGLOST)
1556 #include <sys/utsname.h>
1557 #endif
1558 #endif
1559 #endif
1560 main ()
1561 {
1562 #if defined (sony)
1563 #if defined (MIPSEB)
1564 /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed,
1565 I don't know.... */
1566 printf ("mips-sony-bsd\n"); exit (0);
1567 #else
1568 #include <sys/param.h>
1569 printf ("m68k-sony-newsos%s\n",
1570 #ifdef NEWSOS4
1571 "4"
1572 #else
1573 ""
1574 #endif
1575 ); exit (0);
1576 #endif
1577 #endif
1578
1579 #if defined (NeXT)
1580 #if !defined (__ARCHITECTURE__)
1581 #define __ARCHITECTURE__ "m68k"
1582 #endif
1583 int version;
1584 version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`;
1585 if (version < 4)
1586 printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version);
1587 else
1588 printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version);
1589 exit (0);
1590 #endif
1591
1592 #if defined (MULTIMAX) || defined (n16)
1593 #if defined (UMAXV)
1594 printf ("ns32k-encore-sysv\n"); exit (0);
1595 #else
1596 #if defined (CMU)
1597 printf ("ns32k-encore-mach\n"); exit (0);
1598 #else
1599 printf ("ns32k-encore-bsd\n"); exit (0);
1600 #endif
1601 #endif
1602 #endif
1603
1604 #if defined (__386BSD__)
1605 printf ("i386-pc-bsd\n"); exit (0);
1606 #endif
1607
1608 #if defined (sequent)
1609 #if defined (i386)
1610 printf ("i386-sequent-dynix\n"); exit (0);
1611 #endif
1612 #if defined (ns32000)
1613 printf ("ns32k-sequent-dynix\n"); exit (0);
1614 #endif
1615 #endif
1616
1617 #if defined (_SEQUENT_)
1618 struct utsname un;
1619
1620 uname(&un);
1621 if (strncmp(un.version, "V2", 2) == 0) {
1622 printf ("i386-sequent-ptx2\n"); exit (0);
1623 }
1624 if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */
1625 printf ("i386-sequent-ptx1\n"); exit (0);
1626 }
1627 printf ("i386-sequent-ptx\n"); exit (0);
1628 #endif
1629
1630 #if defined (vax)
1631 #if !defined (ultrix)
1632 #include <sys/param.h>
1633 #if defined (BSD)
1634 #if BSD == 43
1635 printf ("vax-dec-bsd4.3\n"); exit (0);
1636 #else
1637 #if BSD == 199006
1638 printf ("vax-dec-bsd4.3reno\n"); exit (0);
1639 #else
1640 printf ("vax-dec-bsd\n"); exit (0);
1641 #endif
1642 #endif
1643 #else
1644 printf ("vax-dec-bsd\n"); exit (0);
1645 #endif
1646 #else
1647 #if defined(_SIZE_T_) || defined(SIGLOST)
1648 struct utsname un;
1649 uname (&un);
1650 printf ("vax-dec-ultrix%s\n", un.release); exit (0);
1651 #else
1652 printf ("vax-dec-ultrix\n"); exit (0);
1653 #endif
1654 #endif
1655 #endif
1656 #if defined(ultrix) || defined(_ultrix) || defined(__ultrix) || defined(__ultrix__)
1657 #if defined(mips) || defined(__mips) || defined(__mips__) || defined(MIPS) || defined(__MIPS__)
1658 #if defined(_SIZE_T_) || defined(SIGLOST)
1659 struct utsname *un;
1660 uname (&un);
1661 printf ("mips-dec-ultrix%s\n", un.release); exit (0);
1662 #else
1663 printf ("mips-dec-ultrix\n"); exit (0);
1664 #endif
1665 #endif
1666 #endif
1667
1668 #if defined (alliant) && defined (i860)
1669 printf ("i860-alliant-bsd\n"); exit (0);
1670 #endif
1671
1672 exit (1);
1673 }
1674 EOF
1675
1676 $CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null && SYSTEM_NAME=`"$dummy"` &&
1677 { echo "$SYSTEM_NAME"; exit; }
1678
1679 # Apollos put the system type in the environment.
1680 test -d /usr/apollo && { echo "$ISP-apollo-$SYSTYPE"; exit; }
1681
1682 echo "$0: unable to guess system type" >&2
1683
1684 case $UNAME_MACHINE:$UNAME_SYSTEM in
1685 mips:Linux | mips64:Linux)
1686 # If we got here on MIPS GNU/Linux, output extra information.
1687 cat >&2 <<EOF
1688
1689 NOTE: MIPS GNU/Linux systems require a C compiler to fully recognize
@@ -1433,13 +1696,21 @@
1696
1697 This script (version $timestamp), has failed to recognize the
1698 operating system you are using. If your script is old, overwrite *all*
1699 copies of config.guess and config.sub with the latest versions from:
1700
1701 https://git.savannah.gnu.org/cgit/config.git/plain/config.guess
1702 and
1703 https://git.savannah.gnu.org/cgit/config.git/plain/config.sub
1704 EOF
1705
1706 our_year=`echo $timestamp | sed 's,-.*,,'`
1707 thisyear=`date +%Y`
1708 # shellcheck disable=SC2003
1709 script_age=`expr "$thisyear" - "$our_year"`
1710 if test "$script_age" -lt 3 ; then
1711 cat >&2 <<EOF
1712
1713 If $0 has already been updated, send the following data and any
1714 information you think might be pertinent to [email protected] to
1715 provide the necessary information to handle your system.
1716
@@ -1463,14 +1734,15 @@
1734 UNAME_MACHINE = "$UNAME_MACHINE"
1735 UNAME_RELEASE = "$UNAME_RELEASE"
1736 UNAME_SYSTEM = "$UNAME_SYSTEM"
1737 UNAME_VERSION = "$UNAME_VERSION"
1738 EOF
1739 fi
1740
1741 exit 1
1742
1743 # Local variables:
1744 # eval: (add-hook 'before-save-hook 'time-stamp)
1745 # time-stamp-start: "timestamp='"
1746 # time-stamp-format: "%:y-%02m-%02d"
1747 # time-stamp-end: "'"
1748 # End:
1749
--- autosetup/autosetup-config.sub
+++ autosetup/autosetup-config.sub
@@ -1,10 +1,12 @@
11
#! /bin/sh
22
# Configuration validation subroutine script.
3
-# Copyright 1992-2018 Free Software Foundation, Inc.
3
+# Copyright 1992-2021 Free Software Foundation, Inc.
4
+
5
+# shellcheck disable=SC2006,SC2268 # see below for rationale
46
5
-timestamp='2018-03-08'
7
+timestamp='2021-07-03'
68
79
# This file is free software; you can redistribute it and/or modify it
810
# under the terms of the GNU General Public License as published by
911
# the Free Software Foundation; either version 3 of the License, or
1012
# (at your option) any later version.
@@ -31,11 +33,11 @@
3133
# Supply the specified configuration type as an argument.
3234
# If it is invalid, we print an error message on stderr and exit with code 1.
3335
# Otherwise, we print the canonical config type on stdout and succeed.
3436
3537
# You can get the latest version of this script from:
36
-# https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub
38
+# https://git.savannah.gnu.org/cgit/config.git/plain/config.sub
3739
3840
# This file is supposed to be the same for all GNU packages
3941
# and recognize all the CPU types, system types and aliases
4042
# that are meaningful with *any* GNU software.
4143
# Each package is responsible for reporting which valid configurations
@@ -47,10 +49,17 @@
4749
# machine specification into a single specification in the form:
4850
# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM
4951
# or in some cases, the newer four-part form:
5052
# CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM
5153
# It is wrong to echo any other type of specification.
54
+
55
+# The "shellcheck disable" line above the timestamp inhibits complaints
56
+# about features and limitations of the classic Bourne shell that were
57
+# superseded or lifted in POSIX. However, this script identifies a wide
58
+# variety of pre-POSIX systems that do not have POSIX shells at all, and
59
+# even some reasonably current systems (Solaris 10 as case-in-point) still
60
+# have a pre-POSIX /bin/sh.
5261
5362
me=`echo "$0" | sed -e 's,.*/,,'`
5463
5564
usage="\
5665
Usage: $0 [OPTION] CPU-MFR-OPSYS or ALIAS
@@ -65,11 +74,11 @@
6574
Report bugs and patches to <[email protected]>."
6675
6776
version="\
6877
GNU config.sub ($timestamp)
6978
70
-Copyright 1992-2018 Free Software Foundation, Inc.
79
+Copyright 1992-2021 Free Software Foundation, Inc.
7180
7281
This is free software; see the source for copying conditions. There is NO
7382
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
7483
7584
help="
@@ -87,11 +96,11 @@
8796
-- ) # Stop option processing
8897
shift; break ;;
8998
- ) # Use stdin as input.
9099
break ;;
91100
-* )
92
- echo "$me: invalid option $1$help"
101
+ echo "$me: invalid option $1$help" >&2
93102
exit 1 ;;
94103
95104
*local*)
96105
# First pass through any local machine types.
97106
echo "$1"
@@ -108,1431 +117,1391 @@
108117
1) ;;
109118
*) echo "$me: too many arguments$help" >&2
110119
exit 1;;
111120
esac
112121
113
-# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any).
114
-# Here we must recognize all the valid KERNEL-OS combinations.
115
-maybe_os=`echo "$1" | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
116
-case $maybe_os in
117
- nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc | linux-newlib* | \
118
- linux-musl* | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \
119
- knetbsd*-gnu* | netbsd*-gnu* | netbsd*-eabi* | \
120
- kopensolaris*-gnu* | cloudabi*-eabi* | \
121
- storm-chaos* | os2-emx* | rtmk-nova*)
122
- os=-$maybe_os
123
- basic_machine=`echo "$1" | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
124
- ;;
125
- android-linux)
126
- os=-linux-android
127
- basic_machine=`echo "$1" | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`-unknown
128
- ;;
129
- *)
130
- basic_machine=`echo "$1" | sed 's/-[^-]*$//'`
131
- if [ "$basic_machine" != "$1" ]
132
- then os=`echo "$1" | sed 's/.*-/-/'`
133
- else os=; fi
134
- ;;
135
-esac
136
-
137
-### Let's recognize common machines as not being operating systems so
138
-### that things like config.sub decstation-3100 work. We also
139
-### recognize some manufacturers as not being operating systems, so we
140
-### can provide default operating systems below.
141
-case $os in
142
- -sun*os*)
143
- # Prevent following clause from handling this invalid input.
144
- ;;
145
- -dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \
146
- -att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \
147
- -unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \
148
- -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\
149
- -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \
150
- -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \
151
- -apple | -axis | -knuth | -cray | -microblaze*)
152
- os=
153
- basic_machine=$1
154
- ;;
155
- -bluegene*)
156
- os=-cnk
157
- ;;
158
- -sim | -cisco | -oki | -wec | -winbond)
159
- os=
160
- basic_machine=$1
161
- ;;
162
- -scout)
163
- ;;
164
- -wrs)
165
- os=-vxworks
166
- basic_machine=$1
167
- ;;
168
- -chorusos*)
169
- os=-chorusos
170
- basic_machine=$1
171
- ;;
172
- -chorusrdb)
173
- os=-chorusrdb
174
- basic_machine=$1
175
- ;;
176
- -hiux*)
177
- os=-hiuxwe2
178
- ;;
179
- -sco6)
180
- os=-sco5v6
181
- basic_machine=`echo "$1" | sed -e 's/86-.*/86-pc/'`
182
- ;;
183
- -sco5)
184
- os=-sco3.2v5
185
- basic_machine=`echo "$1" | sed -e 's/86-.*/86-pc/'`
186
- ;;
187
- -sco4)
188
- os=-sco3.2v4
189
- basic_machine=`echo "$1" | sed -e 's/86-.*/86-pc/'`
190
- ;;
191
- -sco3.2.[4-9]*)
192
- os=`echo $os | sed -e 's/sco3.2./sco3.2v/'`
193
- basic_machine=`echo "$1" | sed -e 's/86-.*/86-pc/'`
194
- ;;
195
- -sco3.2v[4-9]*)
196
- # Don't forget version if it is 3.2v4 or newer.
197
- basic_machine=`echo "$1" | sed -e 's/86-.*/86-pc/'`
198
- ;;
199
- -sco5v6*)
200
- # Don't forget version if it is 3.2v4 or newer.
201
- basic_machine=`echo "$1" | sed -e 's/86-.*/86-pc/'`
202
- ;;
203
- -sco*)
204
- os=-sco3.2v2
205
- basic_machine=`echo "$1" | sed -e 's/86-.*/86-pc/'`
206
- ;;
207
- -udk*)
208
- basic_machine=`echo "$1" | sed -e 's/86-.*/86-pc/'`
209
- ;;
210
- -isc)
211
- os=-isc2.2
212
- basic_machine=`echo "$1" | sed -e 's/86-.*/86-pc/'`
213
- ;;
214
- -clix*)
215
- basic_machine=clipper-intergraph
216
- ;;
217
- -isc*)
218
- basic_machine=`echo "$1" | sed -e 's/86-.*/86-pc/'`
219
- ;;
220
- -lynx*178)
221
- os=-lynxos178
222
- ;;
223
- -lynx*5)
224
- os=-lynxos5
225
- ;;
226
- -lynx*)
227
- os=-lynxos
228
- ;;
229
- -ptx*)
230
- basic_machine=`echo "$1" | sed -e 's/86-.*/86-sequent/'`
231
- ;;
232
- -psos*)
233
- os=-psos
234
- ;;
235
- -mint | -mint[0-9]*)
236
- basic_machine=m68k-atari
237
- os=-mint
238
- ;;
239
-esac
240
-
241
-# Decode aliases for certain CPU-COMPANY combinations.
122
+# Split fields of configuration type
123
+# shellcheck disable=SC2162
124
+IFS="-" read field1 field2 field3 field4 <<EOF
125
+$1
126
+EOF
127
+
128
+# Separate into logical components for further validation
129
+case $1 in
130
+ *-*-*-*-*)
131
+ echo Invalid configuration \`"$1"\': more than four components >&2
132
+ exit 1
133
+ ;;
134
+ *-*-*-*)
135
+ basic_machine=$field1-$field2
136
+ basic_os=$field3-$field4
137
+ ;;
138
+ *-*-*)
139
+ # Ambiguous whether COMPANY is present, or skipped and KERNEL-OS is two
140
+ # parts
141
+ maybe_os=$field2-$field3
142
+ case $maybe_os in
143
+ nto-qnx* | linux-* | uclinux-uclibc* \
144
+ | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* \
145
+ | netbsd*-eabi* | kopensolaris*-gnu* | cloudabi*-eabi* \
146
+ | storm-chaos* | os2-emx* | rtmk-nova*)
147
+ basic_machine=$field1
148
+ basic_os=$maybe_os
149
+ ;;
150
+ android-linux)
151
+ basic_machine=$field1-unknown
152
+ basic_os=linux-android
153
+ ;;
154
+ *)
155
+ basic_machine=$field1-$field2
156
+ basic_os=$field3
157
+ ;;
158
+ esac
159
+ ;;
160
+ *-*)
161
+ # A lone config we happen to match not fitting any pattern
162
+ case $field1-$field2 in
163
+ decstation-3100)
164
+ basic_machine=mips-dec
165
+ basic_os=
166
+ ;;
167
+ *-*)
168
+ # Second component is usually, but not always the OS
169
+ case $field2 in
170
+ # Prevent following clause from handling this valid os
171
+ sun*os*)
172
+ basic_machine=$field1
173
+ basic_os=$field2
174
+ ;;
175
+ # Manufacturers
176
+ dec* | mips* | sequent* | encore* | pc533* | sgi* | sony* \
177
+ | att* | 7300* | 3300* | delta* | motorola* | sun[234]* \
178
+ | unicom* | ibm* | next | hp | isi* | apollo | altos* \
179
+ | convergent* | ncr* | news | 32* | 3600* | 3100* \
180
+ | hitachi* | c[123]* | convex* | sun | crds | omron* | dg \
181
+ | ultra | tti* | harris | dolphin | highlevel | gould \
182
+ | cbm | ns | masscomp | apple | axis | knuth | cray \
183
+ | microblaze* | sim | cisco \
184
+ | oki | wec | wrs | winbond)
185
+ basic_machine=$field1-$field2
186
+ basic_os=
187
+ ;;
188
+ *)
189
+ basic_machine=$field1
190
+ basic_os=$field2
191
+ ;;
192
+ esac
193
+ ;;
194
+ esac
195
+ ;;
196
+ *)
197
+ # Convert single-component short-hands not valid as part of
198
+ # multi-component configurations.
199
+ case $field1 in
200
+ 386bsd)
201
+ basic_machine=i386-pc
202
+ basic_os=bsd
203
+ ;;
204
+ a29khif)
205
+ basic_machine=a29k-amd
206
+ basic_os=udi
207
+ ;;
208
+ adobe68k)
209
+ basic_machine=m68010-adobe
210
+ basic_os=scout
211
+ ;;
212
+ alliant)
213
+ basic_machine=fx80-alliant
214
+ basic_os=
215
+ ;;
216
+ altos | altos3068)
217
+ basic_machine=m68k-altos
218
+ basic_os=
219
+ ;;
220
+ am29k)
221
+ basic_machine=a29k-none
222
+ basic_os=bsd
223
+ ;;
224
+ amdahl)
225
+ basic_machine=580-amdahl
226
+ basic_os=sysv
227
+ ;;
228
+ amiga)
229
+ basic_machine=m68k-unknown
230
+ basic_os=
231
+ ;;
232
+ amigaos | amigados)
233
+ basic_machine=m68k-unknown
234
+ basic_os=amigaos
235
+ ;;
236
+ amigaunix | amix)
237
+ basic_machine=m68k-unknown
238
+ basic_os=sysv4
239
+ ;;
240
+ apollo68)
241
+ basic_machine=m68k-apollo
242
+ basic_os=sysv
243
+ ;;
244
+ apollo68bsd)
245
+ basic_machine=m68k-apollo
246
+ basic_os=bsd
247
+ ;;
248
+ aros)
249
+ basic_machine=i386-pc
250
+ basic_os=aros
251
+ ;;
252
+ aux)
253
+ basic_machine=m68k-apple
254
+ basic_os=aux
255
+ ;;
256
+ balance)
257
+ basic_machine=ns32k-sequent
258
+ basic_os=dynix
259
+ ;;
260
+ blackfin)
261
+ basic_machine=bfin-unknown
262
+ basic_os=linux
263
+ ;;
264
+ cegcc)
265
+ basic_machine=arm-unknown
266
+ basic_os=cegcc
267
+ ;;
268
+ convex-c1)
269
+ basic_machine=c1-convex
270
+ basic_os=bsd
271
+ ;;
272
+ convex-c2)
273
+ basic_machine=c2-convex
274
+ basic_os=bsd
275
+ ;;
276
+ convex-c32)
277
+ basic_machine=c32-convex
278
+ basic_os=bsd
279
+ ;;
280
+ convex-c34)
281
+ basic_machine=c34-convex
282
+ basic_os=bsd
283
+ ;;
284
+ convex-c38)
285
+ basic_machine=c38-convex
286
+ basic_os=bsd
287
+ ;;
288
+ cray)
289
+ basic_machine=j90-cray
290
+ basic_os=unicos
291
+ ;;
292
+ crds | unos)
293
+ basic_machine=m68k-crds
294
+ basic_os=
295
+ ;;
296
+ da30)
297
+ basic_machine=m68k-da30
298
+ basic_os=
299
+ ;;
300
+ decstation | pmax | pmin | dec3100 | decstatn)
301
+ basic_machine=mips-dec
302
+ basic_os=
303
+ ;;
304
+ delta88)
305
+ basic_machine=m88k-motorola
306
+ basic_os=sysv3
307
+ ;;
308
+ dicos)
309
+ basic_machine=i686-pc
310
+ basic_os=dicos
311
+ ;;
312
+ djgpp)
313
+ basic_machine=i586-pc
314
+ basic_os=msdosdjgpp
315
+ ;;
316
+ ebmon29k)
317
+ basic_machine=a29k-amd
318
+ basic_os=ebmon
319
+ ;;
320
+ es1800 | OSE68k | ose68k | ose | OSE)
321
+ basic_machine=m68k-ericsson
322
+ basic_os=ose
323
+ ;;
324
+ gmicro)
325
+ basic_machine=tron-gmicro
326
+ basic_os=sysv
327
+ ;;
328
+ go32)
329
+ basic_machine=i386-pc
330
+ basic_os=go32
331
+ ;;
332
+ h8300hms)
333
+ basic_machine=h8300-hitachi
334
+ basic_os=hms
335
+ ;;
336
+ h8300xray)
337
+ basic_machine=h8300-hitachi
338
+ basic_os=xray
339
+ ;;
340
+ h8500hms)
341
+ basic_machine=h8500-hitachi
342
+ basic_os=hms
343
+ ;;
344
+ harris)
345
+ basic_machine=m88k-harris
346
+ basic_os=sysv3
347
+ ;;
348
+ hp300 | hp300hpux)
349
+ basic_machine=m68k-hp
350
+ basic_os=hpux
351
+ ;;
352
+ hp300bsd)
353
+ basic_machine=m68k-hp
354
+ basic_os=bsd
355
+ ;;
356
+ hppaosf)
357
+ basic_machine=hppa1.1-hp
358
+ basic_os=osf
359
+ ;;
360
+ hppro)
361
+ basic_machine=hppa1.1-hp
362
+ basic_os=proelf
363
+ ;;
364
+ i386mach)
365
+ basic_machine=i386-mach
366
+ basic_os=mach
367
+ ;;
368
+ isi68 | isi)
369
+ basic_machine=m68k-isi
370
+ basic_os=sysv
371
+ ;;
372
+ m68knommu)
373
+ basic_machine=m68k-unknown
374
+ basic_os=linux
375
+ ;;
376
+ magnum | m3230)
377
+ basic_machine=mips-mips
378
+ basic_os=sysv
379
+ ;;
380
+ merlin)
381
+ basic_machine=ns32k-utek
382
+ basic_os=sysv
383
+ ;;
384
+ mingw64)
385
+ basic_machine=x86_64-pc
386
+ basic_os=mingw64
387
+ ;;
388
+ mingw32)
389
+ basic_machine=i686-pc
390
+ basic_os=mingw32
391
+ ;;
392
+ mingw32ce)
393
+ basic_machine=arm-unknown
394
+ basic_os=mingw32ce
395
+ ;;
396
+ monitor)
397
+ basic_machine=m68k-rom68k
398
+ basic_os=coff
399
+ ;;
400
+ morphos)
401
+ basic_machine=powerpc-unknown
402
+ basic_os=morphos
403
+ ;;
404
+ moxiebox)
405
+ basic_machine=moxie-unknown
406
+ basic_os=moxiebox
407
+ ;;
408
+ msdos)
409
+ basic_machine=i386-pc
410
+ basic_os=msdos
411
+ ;;
412
+ msys)
413
+ basic_machine=i686-pc
414
+ basic_os=msys
415
+ ;;
416
+ mvs)
417
+ basic_machine=i370-ibm
418
+ basic_os=mvs
419
+ ;;
420
+ nacl)
421
+ basic_machine=le32-unknown
422
+ basic_os=nacl
423
+ ;;
424
+ ncr3000)
425
+ basic_machine=i486-ncr
426
+ basic_os=sysv4
427
+ ;;
428
+ netbsd386)
429
+ basic_machine=i386-pc
430
+ basic_os=netbsd
431
+ ;;
432
+ netwinder)
433
+ basic_machine=armv4l-rebel
434
+ basic_os=linux
435
+ ;;
436
+ news | news700 | news800 | news900)
437
+ basic_machine=m68k-sony
438
+ basic_os=newsos
439
+ ;;
440
+ news1000)
441
+ basic_machine=m68030-sony
442
+ basic_os=newsos
443
+ ;;
444
+ necv70)
445
+ basic_machine=v70-nec
446
+ basic_os=sysv
447
+ ;;
448
+ nh3000)
449
+ basic_machine=m68k-harris
450
+ basic_os=cxux
451
+ ;;
452
+ nh[45]000)
453
+ basic_machine=m88k-harris
454
+ basic_os=cxux
455
+ ;;
456
+ nindy960)
457
+ basic_machine=i960-intel
458
+ basic_os=nindy
459
+ ;;
460
+ mon960)
461
+ basic_machine=i960-intel
462
+ basic_os=mon960
463
+ ;;
464
+ nonstopux)
465
+ basic_machine=mips-compaq
466
+ basic_os=nonstopux
467
+ ;;
468
+ os400)
469
+ basic_machine=powerpc-ibm
470
+ basic_os=os400
471
+ ;;
472
+ OSE68000 | ose68000)
473
+ basic_machine=m68000-ericsson
474
+ basic_os=ose
475
+ ;;
476
+ os68k)
477
+ basic_machine=m68k-none
478
+ basic_os=os68k
479
+ ;;
480
+ paragon)
481
+ basic_machine=i860-intel
482
+ basic_os=osf
483
+ ;;
484
+ parisc)
485
+ basic_machine=hppa-unknown
486
+ basic_os=linux
487
+ ;;
488
+ psp)
489
+ basic_machine=mipsallegrexel-sony
490
+ basic_os=psp
491
+ ;;
492
+ pw32)
493
+ basic_machine=i586-unknown
494
+ basic_os=pw32
495
+ ;;
496
+ rdos | rdos64)
497
+ basic_machine=x86_64-pc
498
+ basic_os=rdos
499
+ ;;
500
+ rdos32)
501
+ basic_machine=i386-pc
502
+ basic_os=rdos
503
+ ;;
504
+ rom68k)
505
+ basic_machine=m68k-rom68k
506
+ basic_os=coff
507
+ ;;
508
+ sa29200)
509
+ basic_machine=a29k-amd
510
+ basic_os=udi
511
+ ;;
512
+ sei)
513
+ basic_machine=mips-sei
514
+ basic_os=seiux
515
+ ;;
516
+ sequent)
517
+ basic_machine=i386-sequent
518
+ basic_os=
519
+ ;;
520
+ sps7)
521
+ basic_machine=m68k-bull
522
+ basic_os=sysv2
523
+ ;;
524
+ st2000)
525
+ basic_machine=m68k-tandem
526
+ basic_os=
527
+ ;;
528
+ stratus)
529
+ basic_machine=i860-stratus
530
+ basic_os=sysv4
531
+ ;;
532
+ sun2)
533
+ basic_machine=m68000-sun
534
+ basic_os=
535
+ ;;
536
+ sun2os3)
537
+ basic_machine=m68000-sun
538
+ basic_os=sunos3
539
+ ;;
540
+ sun2os4)
541
+ basic_machine=m68000-sun
542
+ basic_os=sunos4
543
+ ;;
544
+ sun3)
545
+ basic_machine=m68k-sun
546
+ basic_os=
547
+ ;;
548
+ sun3os3)
549
+ basic_machine=m68k-sun
550
+ basic_os=sunos3
551
+ ;;
552
+ sun3os4)
553
+ basic_machine=m68k-sun
554
+ basic_os=sunos4
555
+ ;;
556
+ sun4)
557
+ basic_machine=sparc-sun
558
+ basic_os=
559
+ ;;
560
+ sun4os3)
561
+ basic_machine=sparc-sun
562
+ basic_os=sunos3
563
+ ;;
564
+ sun4os4)
565
+ basic_machine=sparc-sun
566
+ basic_os=sunos4
567
+ ;;
568
+ sun4sol2)
569
+ basic_machine=sparc-sun
570
+ basic_os=solaris2
571
+ ;;
572
+ sun386 | sun386i | roadrunner)
573
+ basic_machine=i386-sun
574
+ basic_os=
575
+ ;;
576
+ sv1)
577
+ basic_machine=sv1-cray
578
+ basic_os=unicos
579
+ ;;
580
+ symmetry)
581
+ basic_machine=i386-sequent
582
+ basic_os=dynix
583
+ ;;
584
+ t3e)
585
+ basic_machine=alphaev5-cray
586
+ basic_os=unicos
587
+ ;;
588
+ t90)
589
+ basic_machine=t90-cray
590
+ basic_os=unicos
591
+ ;;
592
+ toad1)
593
+ basic_machine=pdp10-xkl
594
+ basic_os=tops20
595
+ ;;
596
+ tpf)
597
+ basic_machine=s390x-ibm
598
+ basic_os=tpf
599
+ ;;
600
+ udi29k)
601
+ basic_machine=a29k-amd
602
+ basic_os=udi
603
+ ;;
604
+ ultra3)
605
+ basic_machine=a29k-nyu
606
+ basic_os=sym1
607
+ ;;
608
+ v810 | necv810)
609
+ basic_machine=v810-nec
610
+ basic_os=none
611
+ ;;
612
+ vaxv)
613
+ basic_machine=vax-dec
614
+ basic_os=sysv
615
+ ;;
616
+ vms)
617
+ basic_machine=vax-dec
618
+ basic_os=vms
619
+ ;;
620
+ vsta)
621
+ basic_machine=i386-pc
622
+ basic_os=vsta
623
+ ;;
624
+ vxworks960)
625
+ basic_machine=i960-wrs
626
+ basic_os=vxworks
627
+ ;;
628
+ vxworks68)
629
+ basic_machine=m68k-wrs
630
+ basic_os=vxworks
631
+ ;;
632
+ vxworks29k)
633
+ basic_machine=a29k-wrs
634
+ basic_os=vxworks
635
+ ;;
636
+ xbox)
637
+ basic_machine=i686-pc
638
+ basic_os=mingw32
639
+ ;;
640
+ ymp)
641
+ basic_machine=ymp-cray
642
+ basic_os=unicos
643
+ ;;
644
+ *)
645
+ basic_machine=$1
646
+ basic_os=
647
+ ;;
648
+ esac
649
+ ;;
650
+esac
651
+
652
+# Decode 1-component or ad-hoc basic machines
242653
case $basic_machine in
243
- # Recognize the basic CPU types without company name.
244
- # Some are omitted here because they have special meanings below.
245
- 1750a | 580 \
246
- | a29k \
247
- | aarch64 | aarch64_be \
248
- | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \
249
- | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \
250
- | am33_2.0 \
251
- | arc | arceb \
252
- | arm | arm[bl]e | arme[lb] | armv[2-8] | armv[3-8][lb] | armv7[arm] \
253
- | avr | avr32 \
254
- | ba \
255
- | be32 | be64 \
256
- | bfin \
257
- | c4x | c8051 | clipper \
258
- | d10v | d30v | dlx | dsp16xx \
259
- | e2k | epiphany \
260
- | fido | fr30 | frv | ft32 \
261
- | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
262
- | hexagon \
263
- | i370 | i860 | i960 | ia16 | ia64 \
264
- | ip2k | iq2000 \
265
- | k1om \
266
- | le32 | le64 \
267
- | lm32 \
268
- | m32c | m32r | m32rle | m68000 | m68k | m88k \
269
- | maxq | mb | microblaze | microblazeel | mcore | mep | metag \
270
- | mips | mipsbe | mipseb | mipsel | mipsle \
271
- | mips16 \
272
- | mips64 | mips64el \
273
- | mips64octeon | mips64octeonel \
274
- | mips64orion | mips64orionel \
275
- | mips64r5900 | mips64r5900el \
276
- | mips64vr | mips64vrel \
277
- | mips64vr4100 | mips64vr4100el \
278
- | mips64vr4300 | mips64vr4300el \
279
- | mips64vr5000 | mips64vr5000el \
280
- | mips64vr5900 | mips64vr5900el \
281
- | mipsisa32 | mipsisa32el \
282
- | mipsisa32r2 | mipsisa32r2el \
283
- | mipsisa32r6 | mipsisa32r6el \
284
- | mipsisa64 | mipsisa64el \
285
- | mipsisa64r2 | mipsisa64r2el \
286
- | mipsisa64r6 | mipsisa64r6el \
287
- | mipsisa64sb1 | mipsisa64sb1el \
288
- | mipsisa64sr71k | mipsisa64sr71kel \
289
- | mipsr5900 | mipsr5900el \
290
- | mipstx39 | mipstx39el \
291
- | mn10200 | mn10300 \
292
- | moxie \
293
- | mt \
294
- | msp430 \
295
- | nds32 | nds32le | nds32be \
296
- | nios | nios2 | nios2eb | nios2el \
297
- | ns16k | ns32k \
298
- | open8 | or1k | or1knd | or32 \
299
- | pdp10 | pj | pjl \
300
- | powerpc | powerpc64 | powerpc64le | powerpcle \
301
- | pru \
302
- | pyramid \
303
- | riscv32 | riscv64 \
304
- | rl78 | rx \
305
- | score \
306
- | sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[234]eb | sheb | shbe | shle | sh[1234]le | sh3ele \
307
- | sh64 | sh64le \
308
- | sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \
309
- | sparcv8 | sparcv9 | sparcv9b | sparcv9v \
310
- | spu \
311
- | tahoe | tic4x | tic54x | tic55x | tic6x | tic80 | tron \
312
- | ubicom32 \
313
- | v850 | v850e | v850e1 | v850e2 | v850es | v850e2v3 \
314
- | visium \
315
- | wasm32 \
316
- | x86 | xc16x | xstormy16 | xtensa \
317
- | z8k | z80)
318
- basic_machine=$basic_machine-unknown
319
- ;;
320
- c54x)
321
- basic_machine=tic54x-unknown
322
- ;;
323
- c55x)
324
- basic_machine=tic55x-unknown
325
- ;;
326
- c6x)
327
- basic_machine=tic6x-unknown
654
+ # Here we handle the default manufacturer of certain CPU types. It is in
655
+ # some cases the only manufacturer, in others, it is the most popular.
656
+ w89k)
657
+ cpu=hppa1.1
658
+ vendor=winbond
659
+ ;;
660
+ op50n)
661
+ cpu=hppa1.1
662
+ vendor=oki
663
+ ;;
664
+ op60c)
665
+ cpu=hppa1.1
666
+ vendor=oki
667
+ ;;
668
+ ibm*)
669
+ cpu=i370
670
+ vendor=ibm
671
+ ;;
672
+ orion105)
673
+ cpu=clipper
674
+ vendor=highlevel
675
+ ;;
676
+ mac | mpw | mac-mpw)
677
+ cpu=m68k
678
+ vendor=apple
679
+ ;;
680
+ pmac | pmac-mpw)
681
+ cpu=powerpc
682
+ vendor=apple
683
+ ;;
684
+
685
+ # Recognize the various machine names and aliases which stand
686
+ # for a CPU type and a company and sometimes even an OS.
687
+ 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc)
688
+ cpu=m68000
689
+ vendor=att
690
+ ;;
691
+ 3b*)
692
+ cpu=we32k
693
+ vendor=att
694
+ ;;
695
+ bluegene*)
696
+ cpu=powerpc
697
+ vendor=ibm
698
+ basic_os=cnk
699
+ ;;
700
+ decsystem10* | dec10*)
701
+ cpu=pdp10
702
+ vendor=dec
703
+ basic_os=tops10
704
+ ;;
705
+ decsystem20* | dec20*)
706
+ cpu=pdp10
707
+ vendor=dec
708
+ basic_os=tops20
709
+ ;;
710
+ delta | 3300 | motorola-3300 | motorola-delta \
711
+ | 3300-motorola | delta-motorola)
712
+ cpu=m68k
713
+ vendor=motorola
714
+ ;;
715
+ dpx2*)
716
+ cpu=m68k
717
+ vendor=bull
718
+ basic_os=sysv3
719
+ ;;
720
+ encore | umax | mmax)
721
+ cpu=ns32k
722
+ vendor=encore
723
+ ;;
724
+ elxsi)
725
+ cpu=elxsi
726
+ vendor=elxsi
727
+ basic_os=${basic_os:-bsd}
728
+ ;;
729
+ fx2800)
730
+ cpu=i860
731
+ vendor=alliant
732
+ ;;
733
+ genix)
734
+ cpu=ns32k
735
+ vendor=ns
736
+ ;;
737
+ h3050r* | hiux*)
738
+ cpu=hppa1.1
739
+ vendor=hitachi
740
+ basic_os=hiuxwe2
741
+ ;;
742
+ hp3k9[0-9][0-9] | hp9[0-9][0-9])
743
+ cpu=hppa1.0
744
+ vendor=hp
745
+ ;;
746
+ hp9k2[0-9][0-9] | hp9k31[0-9])
747
+ cpu=m68000
748
+ vendor=hp
749
+ ;;
750
+ hp9k3[2-9][0-9])
751
+ cpu=m68k
752
+ vendor=hp
753
+ ;;
754
+ hp9k6[0-9][0-9] | hp6[0-9][0-9])
755
+ cpu=hppa1.0
756
+ vendor=hp
757
+ ;;
758
+ hp9k7[0-79][0-9] | hp7[0-79][0-9])
759
+ cpu=hppa1.1
760
+ vendor=hp
761
+ ;;
762
+ hp9k78[0-9] | hp78[0-9])
763
+ # FIXME: really hppa2.0-hp
764
+ cpu=hppa1.1
765
+ vendor=hp
766
+ ;;
767
+ hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893)
768
+ # FIXME: really hppa2.0-hp
769
+ cpu=hppa1.1
770
+ vendor=hp
771
+ ;;
772
+ hp9k8[0-9][13679] | hp8[0-9][13679])
773
+ cpu=hppa1.1
774
+ vendor=hp
775
+ ;;
776
+ hp9k8[0-9][0-9] | hp8[0-9][0-9])
777
+ cpu=hppa1.0
778
+ vendor=hp
779
+ ;;
780
+ i*86v32)
781
+ cpu=`echo "$1" | sed -e 's/86.*/86/'`
782
+ vendor=pc
783
+ basic_os=sysv32
784
+ ;;
785
+ i*86v4*)
786
+ cpu=`echo "$1" | sed -e 's/86.*/86/'`
787
+ vendor=pc
788
+ basic_os=sysv4
789
+ ;;
790
+ i*86v)
791
+ cpu=`echo "$1" | sed -e 's/86.*/86/'`
792
+ vendor=pc
793
+ basic_os=sysv
794
+ ;;
795
+ i*86sol2)
796
+ cpu=`echo "$1" | sed -e 's/86.*/86/'`
797
+ vendor=pc
798
+ basic_os=solaris2
799
+ ;;
800
+ j90 | j90-cray)
801
+ cpu=j90
802
+ vendor=cray
803
+ basic_os=${basic_os:-unicos}
804
+ ;;
805
+ iris | iris4d)
806
+ cpu=mips
807
+ vendor=sgi
808
+ case $basic_os in
809
+ irix*)
810
+ ;;
811
+ *)
812
+ basic_os=irix4
813
+ ;;
814
+ esac
815
+ ;;
816
+ miniframe)
817
+ cpu=m68000
818
+ vendor=convergent
819
+ ;;
820
+ *mint | mint[0-9]* | *MiNT | *MiNT[0-9]*)
821
+ cpu=m68k
822
+ vendor=atari
823
+ basic_os=mint
824
+ ;;
825
+ news-3600 | risc-news)
826
+ cpu=mips
827
+ vendor=sony
828
+ basic_os=newsos
829
+ ;;
830
+ next | m*-next)
831
+ cpu=m68k
832
+ vendor=next
833
+ case $basic_os in
834
+ openstep*)
835
+ ;;
836
+ nextstep*)
837
+ ;;
838
+ ns2*)
839
+ basic_os=nextstep2
840
+ ;;
841
+ *)
842
+ basic_os=nextstep3
843
+ ;;
844
+ esac
845
+ ;;
846
+ np1)
847
+ cpu=np1
848
+ vendor=gould
849
+ ;;
850
+ op50n-* | op60c-*)
851
+ cpu=hppa1.1
852
+ vendor=oki
853
+ basic_os=proelf
854
+ ;;
855
+ pa-hitachi)
856
+ cpu=hppa1.1
857
+ vendor=hitachi
858
+ basic_os=hiuxwe2
859
+ ;;
860
+ pbd)
861
+ cpu=sparc
862
+ vendor=tti
863
+ ;;
864
+ pbb)
865
+ cpu=m68k
866
+ vendor=tti
867
+ ;;
868
+ pc532)
869
+ cpu=ns32k
870
+ vendor=pc532
871
+ ;;
872
+ pn)
873
+ cpu=pn
874
+ vendor=gould
875
+ ;;
876
+ power)
877
+ cpu=power
878
+ vendor=ibm
879
+ ;;
880
+ ps2)
881
+ cpu=i386
882
+ vendor=ibm
883
+ ;;
884
+ rm[46]00)
885
+ cpu=mips
886
+ vendor=siemens
887
+ ;;
888
+ rtpc | rtpc-*)
889
+ cpu=romp
890
+ vendor=ibm
891
+ ;;
892
+ sde)
893
+ cpu=mipsisa32
894
+ vendor=sde
895
+ basic_os=${basic_os:-elf}
896
+ ;;
897
+ simso-wrs)
898
+ cpu=sparclite
899
+ vendor=wrs
900
+ basic_os=vxworks
901
+ ;;
902
+ tower | tower-32)
903
+ cpu=m68k
904
+ vendor=ncr
905
+ ;;
906
+ vpp*|vx|vx-*)
907
+ cpu=f301
908
+ vendor=fujitsu
909
+ ;;
910
+ w65)
911
+ cpu=w65
912
+ vendor=wdc
913
+ ;;
914
+ w89k-*)
915
+ cpu=hppa1.1
916
+ vendor=winbond
917
+ basic_os=proelf
918
+ ;;
919
+ none)
920
+ cpu=none
921
+ vendor=none
328922
;;
329923
leon|leon[3-9])
330
- basic_machine=sparc-$basic_machine
331
- ;;
332
- m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x | nvptx | picochip)
333
- basic_machine=$basic_machine-unknown
334
- os=-none
335
- ;;
336
- m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65)
337
- ;;
338
- ms1)
339
- basic_machine=mt-unknown
340
- ;;
341
-
342
- strongarm | thumb | xscale)
343
- basic_machine=arm-unknown
344
- ;;
345
- xgate)
346
- basic_machine=$basic_machine-unknown
347
- os=-none
348
- ;;
349
- xscaleeb)
350
- basic_machine=armeb-unknown
351
- ;;
352
-
353
- xscaleel)
354
- basic_machine=armel-unknown
355
- ;;
356
-
924
+ cpu=sparc
925
+ vendor=$basic_machine
926
+ ;;
927
+ leon-*|leon[3-9]-*)
928
+ cpu=sparc
929
+ vendor=`echo "$basic_machine" | sed 's/-.*//'`
930
+ ;;
931
+
932
+ *-*)
933
+ # shellcheck disable=SC2162
934
+ IFS="-" read cpu vendor <<EOF
935
+$basic_machine
936
+EOF
937
+ ;;
357938
# We use `pc' rather than `unknown'
358939
# because (1) that's what they normally are, and
359940
# (2) the word "unknown" tends to confuse beginning users.
360941
i*86 | x86_64)
361
- basic_machine=$basic_machine-pc
362
- ;;
363
- # Object if more than one company name word.
364
- *-*-*)
365
- echo Invalid configuration \`"$1"\': machine \`"$basic_machine"\' not recognized 1>&2
366
- exit 1
367
- ;;
368
- # Recognize the basic CPU types with company name.
369
- 580-* \
370
- | a29k-* \
371
- | aarch64-* | aarch64_be-* \
372
- | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \
373
- | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \
374
- | alphapca5[67]-* | alpha64pca5[67]-* | arc-* | arceb-* \
375
- | arm-* | armbe-* | armle-* | armeb-* | armv*-* \
376
- | avr-* | avr32-* \
377
- | ba-* \
378
- | be32-* | be64-* \
379
- | bfin-* | bs2000-* \
380
- | c[123]* | c30-* | [cjt]90-* | c4x-* \
381
- | c8051-* | clipper-* | craynv-* | cydra-* \
382
- | d10v-* | d30v-* | dlx-* \
383
- | e2k-* | elxsi-* \
384
- | f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \
385
- | h8300-* | h8500-* \
386
- | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \
387
- | hexagon-* \
388
- | i*86-* | i860-* | i960-* | ia16-* | ia64-* \
389
- | ip2k-* | iq2000-* \
390
- | k1om-* \
391
- | le32-* | le64-* \
392
- | lm32-* \
393
- | m32c-* | m32r-* | m32rle-* \
394
- | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \
395
- | m88110-* | m88k-* | maxq-* | mcore-* | metag-* \
396
- | microblaze-* | microblazeel-* \
397
- | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \
398
- | mips16-* \
399
- | mips64-* | mips64el-* \
400
- | mips64octeon-* | mips64octeonel-* \
401
- | mips64orion-* | mips64orionel-* \
402
- | mips64r5900-* | mips64r5900el-* \
403
- | mips64vr-* | mips64vrel-* \
404
- | mips64vr4100-* | mips64vr4100el-* \
405
- | mips64vr4300-* | mips64vr4300el-* \
406
- | mips64vr5000-* | mips64vr5000el-* \
407
- | mips64vr5900-* | mips64vr5900el-* \
408
- | mipsisa32-* | mipsisa32el-* \
409
- | mipsisa32r2-* | mipsisa32r2el-* \
410
- | mipsisa32r6-* | mipsisa32r6el-* \
411
- | mipsisa64-* | mipsisa64el-* \
412
- | mipsisa64r2-* | mipsisa64r2el-* \
413
- | mipsisa64r6-* | mipsisa64r6el-* \
414
- | mipsisa64sb1-* | mipsisa64sb1el-* \
415
- | mipsisa64sr71k-* | mipsisa64sr71kel-* \
416
- | mipsr5900-* | mipsr5900el-* \
417
- | mipstx39-* | mipstx39el-* \
418
- | mmix-* \
419
- | mt-* \
420
- | msp430-* \
421
- | nds32-* | nds32le-* | nds32be-* \
422
- | nios-* | nios2-* | nios2eb-* | nios2el-* \
423
- | none-* | np1-* | ns16k-* | ns32k-* \
424
- | open8-* \
425
- | or1k*-* \
426
- | orion-* \
427
- | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \
428
- | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* \
429
- | pru-* \
430
- | pyramid-* \
431
- | riscv32-* | riscv64-* \
432
- | rl78-* | romp-* | rs6000-* | rx-* \
433
- | sh-* | sh[1234]-* | sh[24]a-* | sh[24]aeb-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \
434
- | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \
435
- | sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \
436
- | sparclite-* \
437
- | sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | sv1-* | sx*-* \
438
- | tahoe-* \
439
- | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \
440
- | tile*-* \
441
- | tron-* \
442
- | ubicom32-* \
443
- | v850-* | v850e-* | v850e1-* | v850es-* | v850e2-* | v850e2v3-* \
444
- | vax-* \
445
- | visium-* \
446
- | wasm32-* \
447
- | we32k-* \
448
- | x86-* | x86_64-* | xc16x-* | xps100-* \
449
- | xstormy16-* | xtensa*-* \
450
- | ymp-* \
451
- | z8k-* | z80-*)
452
- ;;
453
- # Recognize the basic CPU types without company name, with glob match.
454
- xtensa*)
455
- basic_machine=$basic_machine-unknown
456
- ;;
457
- # Recognize the various machine names and aliases which stand
458
- # for a CPU type and a company and sometimes even an OS.
459
- 386bsd)
460
- basic_machine=i386-pc
461
- os=-bsd
462
- ;;
463
- 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc)
464
- basic_machine=m68000-att
465
- ;;
466
- 3b*)
467
- basic_machine=we32k-att
468
- ;;
469
- a29khif)
470
- basic_machine=a29k-amd
471
- os=-udi
472
- ;;
473
- abacus)
474
- basic_machine=abacus-unknown
475
- ;;
476
- adobe68k)
477
- basic_machine=m68010-adobe
478
- os=-scout
479
- ;;
480
- alliant | fx80)
481
- basic_machine=fx80-alliant
482
- ;;
483
- altos | altos3068)
484
- basic_machine=m68k-altos
485
- ;;
486
- am29k)
487
- basic_machine=a29k-none
488
- os=-bsd
489
- ;;
490
- amd64)
491
- basic_machine=x86_64-pc
492
- ;;
942
+ cpu=$basic_machine
943
+ vendor=pc
944
+ ;;
945
+ # These rules are duplicated from below for sake of the special case above;
946
+ # i.e. things that normalized to x86 arches should also default to "pc"
947
+ pc98)
948
+ cpu=i386
949
+ vendor=pc
950
+ ;;
951
+ x64 | amd64)
952
+ cpu=x86_64
953
+ vendor=pc
954
+ ;;
955
+ # Recognize the basic CPU types without company name.
956
+ *)
957
+ cpu=$basic_machine
958
+ vendor=unknown
959
+ ;;
960
+esac
961
+
962
+unset -v basic_machine
963
+
964
+# Decode basic machines in the full and proper CPU-Company form.
965
+case $cpu-$vendor in
966
+ # Here we handle the default manufacturer of certain CPU types in canonical form. It is in
967
+ # some cases the only manufacturer, in others, it is the most popular.
968
+ craynv-unknown)
969
+ vendor=cray
970
+ basic_os=${basic_os:-unicosmp}
971
+ ;;
972
+ c90-unknown | c90-cray)
973
+ vendor=cray
974
+ basic_os=${Basic_os:-unicos}
975
+ ;;
976
+ fx80-unknown)
977
+ vendor=alliant
978
+ ;;
979
+ romp-unknown)
980
+ vendor=ibm
981
+ ;;
982
+ mmix-unknown)
983
+ vendor=knuth
984
+ ;;
985
+ microblaze-unknown | microblazeel-unknown)
986
+ vendor=xilinx
987
+ ;;
988
+ rs6000-unknown)
989
+ vendor=ibm
990
+ ;;
991
+ vax-unknown)
992
+ vendor=dec
993
+ ;;
994
+ pdp11-unknown)
995
+ vendor=dec
996
+ ;;
997
+ we32k-unknown)
998
+ vendor=att
999
+ ;;
1000
+ cydra-unknown)
1001
+ vendor=cydrome
1002
+ ;;
1003
+ i370-ibm*)
1004
+ vendor=ibm
1005
+ ;;
1006
+ orion-unknown)
1007
+ vendor=highlevel
1008
+ ;;
1009
+ xps-unknown | xps100-unknown)
1010
+ cpu=xps100
1011
+ vendor=honeywell
1012
+ ;;
1013
+
1014
+ # Here we normalize CPU types with a missing or matching vendor
1015
+ dpx20-unknown | dpx20-bull)
1016
+ cpu=rs6000
1017
+ vendor=bull
1018
+ basic_os=${basic_os:-bosx}
1019
+ ;;
1020
+
1021
+ # Here we normalize CPU types irrespective of the vendor
4931022
amd64-*)
494
- basic_machine=x86_64-`echo "$basic_machine" | sed 's/^[^-]*-//'`
495
- ;;
496
- amdahl)
497
- basic_machine=580-amdahl
498
- os=-sysv
499
- ;;
500
- amiga | amiga-*)
501
- basic_machine=m68k-unknown
502
- ;;
503
- amigaos | amigados)
504
- basic_machine=m68k-unknown
505
- os=-amigaos
506
- ;;
507
- amigaunix | amix)
508
- basic_machine=m68k-unknown
509
- os=-sysv4
510
- ;;
511
- apollo68)
512
- basic_machine=m68k-apollo
513
- os=-sysv
514
- ;;
515
- apollo68bsd)
516
- basic_machine=m68k-apollo
517
- os=-bsd
518
- ;;
519
- aros)
520
- basic_machine=i386-pc
521
- os=-aros
522
- ;;
523
- asmjs)
524
- basic_machine=asmjs-unknown
525
- ;;
526
- aux)
527
- basic_machine=m68k-apple
528
- os=-aux
529
- ;;
530
- balance)
531
- basic_machine=ns32k-sequent
532
- os=-dynix
533
- ;;
534
- blackfin)
535
- basic_machine=bfin-unknown
536
- os=-linux
1023
+ cpu=x86_64
5371024
;;
5381025
blackfin-*)
539
- basic_machine=bfin-`echo "$basic_machine" | sed 's/^[^-]*-//'`
540
- os=-linux
541
- ;;
542
- bluegene*)
543
- basic_machine=powerpc-ibm
544
- os=-cnk
1026
+ cpu=bfin
1027
+ basic_os=linux
5451028
;;
5461029
c54x-*)
547
- basic_machine=tic54x-`echo "$basic_machine" | sed 's/^[^-]*-//'`
1030
+ cpu=tic54x
5481031
;;
5491032
c55x-*)
550
- basic_machine=tic55x-`echo "$basic_machine" | sed 's/^[^-]*-//'`
1033
+ cpu=tic55x
5511034
;;
5521035
c6x-*)
553
- basic_machine=tic6x-`echo "$basic_machine" | sed 's/^[^-]*-//'`
554
- ;;
555
- c90)
556
- basic_machine=c90-cray
557
- os=-unicos
558
- ;;
559
- cegcc)
560
- basic_machine=arm-unknown
561
- os=-cegcc
562
- ;;
563
- convex-c1)
564
- basic_machine=c1-convex
565
- os=-bsd
566
- ;;
567
- convex-c2)
568
- basic_machine=c2-convex
569
- os=-bsd
570
- ;;
571
- convex-c32)
572
- basic_machine=c32-convex
573
- os=-bsd
574
- ;;
575
- convex-c34)
576
- basic_machine=c34-convex
577
- os=-bsd
578
- ;;
579
- convex-c38)
580
- basic_machine=c38-convex
581
- os=-bsd
582
- ;;
583
- cray | j90)
584
- basic_machine=j90-cray
585
- os=-unicos
586
- ;;
587
- craynv)
588
- basic_machine=craynv-cray
589
- os=-unicosmp
590
- ;;
591
- cr16 | cr16-*)
592
- basic_machine=cr16-unknown
593
- os=-elf
594
- ;;
595
- crds | unos)
596
- basic_machine=m68k-crds
597
- ;;
598
- crisv32 | crisv32-* | etraxfs*)
599
- basic_machine=crisv32-axis
600
- ;;
601
- cris | cris-* | etrax*)
602
- basic_machine=cris-axis
603
- ;;
604
- crx)
605
- basic_machine=crx-unknown
606
- os=-elf
607
- ;;
608
- da30 | da30-*)
609
- basic_machine=m68k-da30
610
- ;;
611
- decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn)
612
- basic_machine=mips-dec
613
- ;;
614
- decsystem10* | dec10*)
615
- basic_machine=pdp10-dec
616
- os=-tops10
617
- ;;
618
- decsystem20* | dec20*)
619
- basic_machine=pdp10-dec
620
- os=-tops20
621
- ;;
622
- delta | 3300 | motorola-3300 | motorola-delta \
623
- | 3300-motorola | delta-motorola)
624
- basic_machine=m68k-motorola
625
- ;;
626
- delta88)
627
- basic_machine=m88k-motorola
628
- os=-sysv3
629
- ;;
630
- dicos)
631
- basic_machine=i686-pc
632
- os=-dicos
633
- ;;
634
- djgpp)
635
- basic_machine=i586-pc
636
- os=-msdosdjgpp
637
- ;;
638
- dpx20 | dpx20-*)
639
- basic_machine=rs6000-bull
640
- os=-bosx
641
- ;;
642
- dpx2*)
643
- basic_machine=m68k-bull
644
- os=-sysv3
645
- ;;
646
- e500v[12])
647
- basic_machine=powerpc-unknown
648
- os=$os"spe"
1036
+ cpu=tic6x
6491037
;;
6501038
e500v[12]-*)
651
- basic_machine=powerpc-`echo "$basic_machine" | sed 's/^[^-]*-//'`
652
- os=$os"spe"
653
- ;;
654
- ebmon29k)
655
- basic_machine=a29k-amd
656
- os=-ebmon
657
- ;;
658
- elxsi)
659
- basic_machine=elxsi-elxsi
660
- os=-bsd
661
- ;;
662
- encore | umax | mmax)
663
- basic_machine=ns32k-encore
664
- ;;
665
- es1800 | OSE68k | ose68k | ose | OSE)
666
- basic_machine=m68k-ericsson
667
- os=-ose
668
- ;;
669
- fx2800)
670
- basic_machine=i860-alliant
671
- ;;
672
- genix)
673
- basic_machine=ns32k-ns
674
- ;;
675
- gmicro)
676
- basic_machine=tron-gmicro
677
- os=-sysv
678
- ;;
679
- go32)
680
- basic_machine=i386-pc
681
- os=-go32
682
- ;;
683
- h3050r* | hiux*)
684
- basic_machine=hppa1.1-hitachi
685
- os=-hiuxwe2
686
- ;;
687
- h8300hms)
688
- basic_machine=h8300-hitachi
689
- os=-hms
690
- ;;
691
- h8300xray)
692
- basic_machine=h8300-hitachi
693
- os=-xray
694
- ;;
695
- h8500hms)
696
- basic_machine=h8500-hitachi
697
- os=-hms
698
- ;;
699
- harris)
700
- basic_machine=m88k-harris
701
- os=-sysv3
702
- ;;
703
- hp300-*)
704
- basic_machine=m68k-hp
705
- ;;
706
- hp300bsd)
707
- basic_machine=m68k-hp
708
- os=-bsd
709
- ;;
710
- hp300hpux)
711
- basic_machine=m68k-hp
712
- os=-hpux
713
- ;;
714
- hp3k9[0-9][0-9] | hp9[0-9][0-9])
715
- basic_machine=hppa1.0-hp
716
- ;;
717
- hp9k2[0-9][0-9] | hp9k31[0-9])
718
- basic_machine=m68000-hp
719
- ;;
720
- hp9k3[2-9][0-9])
721
- basic_machine=m68k-hp
722
- ;;
723
- hp9k6[0-9][0-9] | hp6[0-9][0-9])
724
- basic_machine=hppa1.0-hp
725
- ;;
726
- hp9k7[0-79][0-9] | hp7[0-79][0-9])
727
- basic_machine=hppa1.1-hp
728
- ;;
729
- hp9k78[0-9] | hp78[0-9])
730
- # FIXME: really hppa2.0-hp
731
- basic_machine=hppa1.1-hp
732
- ;;
733
- hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893)
734
- # FIXME: really hppa2.0-hp
735
- basic_machine=hppa1.1-hp
736
- ;;
737
- hp9k8[0-9][13679] | hp8[0-9][13679])
738
- basic_machine=hppa1.1-hp
739
- ;;
740
- hp9k8[0-9][0-9] | hp8[0-9][0-9])
741
- basic_machine=hppa1.0-hp
742
- ;;
743
- hppaosf)
744
- basic_machine=hppa1.1-hp
745
- os=-osf
746
- ;;
747
- hppro)
748
- basic_machine=hppa1.1-hp
749
- os=-proelf
750
- ;;
751
- i370-ibm* | ibm*)
752
- basic_machine=i370-ibm
753
- ;;
754
- i*86v32)
755
- basic_machine=`echo "$1" | sed -e 's/86.*/86-pc/'`
756
- os=-sysv32
757
- ;;
758
- i*86v4*)
759
- basic_machine=`echo "$1" | sed -e 's/86.*/86-pc/'`
760
- os=-sysv4
761
- ;;
762
- i*86v)
763
- basic_machine=`echo "$1" | sed -e 's/86.*/86-pc/'`
764
- os=-sysv
765
- ;;
766
- i*86sol2)
767
- basic_machine=`echo "$1" | sed -e 's/86.*/86-pc/'`
768
- os=-solaris2
769
- ;;
770
- i386mach)
771
- basic_machine=i386-mach
772
- os=-mach
773
- ;;
774
- vsta)
775
- basic_machine=i386-unknown
776
- os=-vsta
777
- ;;
778
- iris | iris4d)
779
- basic_machine=mips-sgi
780
- case $os in
781
- -irix*)
782
- ;;
783
- *)
784
- os=-irix4
785
- ;;
786
- esac
787
- ;;
788
- isi68 | isi)
789
- basic_machine=m68k-isi
790
- os=-sysv
791
- ;;
792
- leon-*|leon[3-9]-*)
793
- basic_machine=sparc-`echo "$basic_machine" | sed 's/-.*//'`
794
- ;;
795
- m68knommu)
796
- basic_machine=m68k-unknown
797
- os=-linux
1039
+ cpu=powerpc
1040
+ basic_os=${basic_os}"spe"
1041
+ ;;
1042
+ mips3*-*)
1043
+ cpu=mips64
1044
+ ;;
1045
+ ms1-*)
1046
+ cpu=mt
7981047
;;
7991048
m68knommu-*)
800
- basic_machine=m68k-`echo "$basic_machine" | sed 's/^[^-]*-//'`
801
- os=-linux
802
- ;;
803
- magnum | m3230)
804
- basic_machine=mips-mips
805
- os=-sysv
806
- ;;
807
- merlin)
808
- basic_machine=ns32k-utek
809
- os=-sysv
810
- ;;
811
- microblaze*)
812
- basic_machine=microblaze-xilinx
813
- ;;
814
- mingw64)
815
- basic_machine=x86_64-pc
816
- os=-mingw64
817
- ;;
818
- mingw32)
819
- basic_machine=i686-pc
820
- os=-mingw32
821
- ;;
822
- mingw32ce)
823
- basic_machine=arm-unknown
824
- os=-mingw32ce
825
- ;;
826
- miniframe)
827
- basic_machine=m68000-convergent
828
- ;;
829
- *mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*)
830
- basic_machine=m68k-atari
831
- os=-mint
832
- ;;
833
- mips3*-*)
834
- basic_machine=`echo "$basic_machine" | sed -e 's/mips3/mips64/'`
835
- ;;
836
- mips3*)
837
- basic_machine=`echo "$basic_machine" | sed -e 's/mips3/mips64/'`-unknown
838
- ;;
839
- monitor)
840
- basic_machine=m68k-rom68k
841
- os=-coff
842
- ;;
843
- morphos)
844
- basic_machine=powerpc-unknown
845
- os=-morphos
846
- ;;
847
- moxiebox)
848
- basic_machine=moxie-unknown
849
- os=-moxiebox
850
- ;;
851
- msdos)
852
- basic_machine=i386-pc
853
- os=-msdos
854
- ;;
855
- ms1-*)
856
- basic_machine=`echo "$basic_machine" | sed -e 's/ms1-/mt-/'`
857
- ;;
858
- msys)
859
- basic_machine=i686-pc
860
- os=-msys
861
- ;;
862
- mvs)
863
- basic_machine=i370-ibm
864
- os=-mvs
865
- ;;
866
- nacl)
867
- basic_machine=le32-unknown
868
- os=-nacl
869
- ;;
870
- ncr3000)
871
- basic_machine=i486-ncr
872
- os=-sysv4
873
- ;;
874
- netbsd386)
875
- basic_machine=i386-unknown
876
- os=-netbsd
877
- ;;
878
- netwinder)
879
- basic_machine=armv4l-rebel
880
- os=-linux
881
- ;;
882
- news | news700 | news800 | news900)
883
- basic_machine=m68k-sony
884
- os=-newsos
885
- ;;
886
- news1000)
887
- basic_machine=m68030-sony
888
- os=-newsos
889
- ;;
890
- news-3600 | risc-news)
891
- basic_machine=mips-sony
892
- os=-newsos
893
- ;;
894
- necv70)
895
- basic_machine=v70-nec
896
- os=-sysv
897
- ;;
898
- next | m*-next)
899
- basic_machine=m68k-next
900
- case $os in
901
- -nextstep* )
902
- ;;
903
- -ns2*)
904
- os=-nextstep2
905
- ;;
906
- *)
907
- os=-nextstep3
908
- ;;
909
- esac
910
- ;;
911
- nh3000)
912
- basic_machine=m68k-harris
913
- os=-cxux
914
- ;;
915
- nh[45]000)
916
- basic_machine=m88k-harris
917
- os=-cxux
918
- ;;
919
- nindy960)
920
- basic_machine=i960-intel
921
- os=-nindy
922
- ;;
923
- mon960)
924
- basic_machine=i960-intel
925
- os=-mon960
926
- ;;
927
- nonstopux)
928
- basic_machine=mips-compaq
929
- os=-nonstopux
930
- ;;
931
- np1)
932
- basic_machine=np1-gould
1049
+ cpu=m68k
1050
+ basic_os=linux
1051
+ ;;
1052
+ m9s12z-* | m68hcs12z-* | hcs12z-* | s12z-*)
1053
+ cpu=s12z
1054
+ ;;
1055
+ openrisc-*)
1056
+ cpu=or32
1057
+ ;;
1058
+ parisc-*)
1059
+ cpu=hppa
1060
+ basic_os=linux
1061
+ ;;
1062
+ pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*)
1063
+ cpu=i586
1064
+ ;;
1065
+ pentiumpro-* | p6-* | 6x86-* | athlon-* | athalon_*-*)
1066
+ cpu=i686
1067
+ ;;
1068
+ pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*)
1069
+ cpu=i686
1070
+ ;;
1071
+ pentium4-*)
1072
+ cpu=i786
1073
+ ;;
1074
+ pc98-*)
1075
+ cpu=i386
1076
+ ;;
1077
+ ppc-* | ppcbe-*)
1078
+ cpu=powerpc
1079
+ ;;
1080
+ ppcle-* | powerpclittle-*)
1081
+ cpu=powerpcle
1082
+ ;;
1083
+ ppc64-*)
1084
+ cpu=powerpc64
1085
+ ;;
1086
+ ppc64le-* | powerpc64little-*)
1087
+ cpu=powerpc64le
1088
+ ;;
1089
+ sb1-*)
1090
+ cpu=mipsisa64sb1
1091
+ ;;
1092
+ sb1el-*)
1093
+ cpu=mipsisa64sb1el
1094
+ ;;
1095
+ sh5e[lb]-*)
1096
+ cpu=`echo "$cpu" | sed 's/^\(sh.\)e\(.\)$/\1\2e/'`
1097
+ ;;
1098
+ spur-*)
1099
+ cpu=spur
1100
+ ;;
1101
+ strongarm-* | thumb-*)
1102
+ cpu=arm
1103
+ ;;
1104
+ tx39-*)
1105
+ cpu=mipstx39
1106
+ ;;
1107
+ tx39el-*)
1108
+ cpu=mipstx39el
1109
+ ;;
1110
+ x64-*)
1111
+ cpu=x86_64
1112
+ ;;
1113
+ xscale-* | xscalee[bl]-*)
1114
+ cpu=`echo "$cpu" | sed 's/^xscale/arm/'`
1115
+ ;;
1116
+ arm64-*)
1117
+ cpu=aarch64
1118
+ ;;
1119
+
1120
+ # Recognize the canonical CPU Types that limit and/or modify the
1121
+ # company names they are paired with.
1122
+ cr16-*)
1123
+ basic_os=${basic_os:-elf}
1124
+ ;;
1125
+ crisv32-* | etraxfs*-*)
1126
+ cpu=crisv32
1127
+ vendor=axis
1128
+ ;;
1129
+ cris-* | etrax*-*)
1130
+ cpu=cris
1131
+ vendor=axis
1132
+ ;;
1133
+ crx-*)
1134
+ basic_os=${basic_os:-elf}
9331135
;;
9341136
neo-tandem)
935
- basic_machine=neo-tandem
1137
+ cpu=neo
1138
+ vendor=tandem
9361139
;;
9371140
nse-tandem)
938
- basic_machine=nse-tandem
1141
+ cpu=nse
1142
+ vendor=tandem
9391143
;;
9401144
nsr-tandem)
941
- basic_machine=nsr-tandem
1145
+ cpu=nsr
1146
+ vendor=tandem
9421147
;;
9431148
nsv-tandem)
944
- basic_machine=nsv-tandem
1149
+ cpu=nsv
1150
+ vendor=tandem
9451151
;;
9461152
nsx-tandem)
947
- basic_machine=nsx-tandem
948
- ;;
949
- op50n-* | op60c-*)
950
- basic_machine=hppa1.1-oki
951
- os=-proelf
952
- ;;
953
- openrisc | openrisc-*)
954
- basic_machine=or32-unknown
955
- ;;
956
- os400)
957
- basic_machine=powerpc-ibm
958
- os=-os400
959
- ;;
960
- OSE68000 | ose68000)
961
- basic_machine=m68000-ericsson
962
- os=-ose
963
- ;;
964
- os68k)
965
- basic_machine=m68k-none
966
- os=-os68k
967
- ;;
968
- pa-hitachi)
969
- basic_machine=hppa1.1-hitachi
970
- os=-hiuxwe2
971
- ;;
972
- paragon)
973
- basic_machine=i860-intel
974
- os=-osf
975
- ;;
976
- parisc)
977
- basic_machine=hppa-unknown
978
- os=-linux
979
- ;;
980
- parisc-*)
981
- basic_machine=hppa-`echo "$basic_machine" | sed 's/^[^-]*-//'`
982
- os=-linux
983
- ;;
984
- pbd)
985
- basic_machine=sparc-tti
986
- ;;
987
- pbb)
988
- basic_machine=m68k-tti
989
- ;;
990
- pc532 | pc532-*)
991
- basic_machine=ns32k-pc532
992
- ;;
993
- pc98)
994
- basic_machine=i386-pc
995
- ;;
996
- pc98-*)
997
- basic_machine=i386-`echo "$basic_machine" | sed 's/^[^-]*-//'`
998
- ;;
999
- pentium | p5 | k5 | k6 | nexgen | viac3)
1000
- basic_machine=i586-pc
1001
- ;;
1002
- pentiumpro | p6 | 6x86 | athlon | athlon_*)
1003
- basic_machine=i686-pc
1004
- ;;
1005
- pentiumii | pentium2 | pentiumiii | pentium3)
1006
- basic_machine=i686-pc
1007
- ;;
1008
- pentium4)
1009
- basic_machine=i786-pc
1010
- ;;
1011
- pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*)
1012
- basic_machine=i586-`echo "$basic_machine" | sed 's/^[^-]*-//'`
1013
- ;;
1014
- pentiumpro-* | p6-* | 6x86-* | athlon-*)
1015
- basic_machine=i686-`echo "$basic_machine" | sed 's/^[^-]*-//'`
1016
- ;;
1017
- pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*)
1018
- basic_machine=i686-`echo "$basic_machine" | sed 's/^[^-]*-//'`
1019
- ;;
1020
- pentium4-*)
1021
- basic_machine=i786-`echo "$basic_machine" | sed 's/^[^-]*-//'`
1022
- ;;
1023
- pn)
1024
- basic_machine=pn-gould
1025
- ;;
1026
- power) basic_machine=power-ibm
1027
- ;;
1028
- ppc | ppcbe) basic_machine=powerpc-unknown
1029
- ;;
1030
- ppc-* | ppcbe-*)
1031
- basic_machine=powerpc-`echo "$basic_machine" | sed 's/^[^-]*-//'`
1032
- ;;
1033
- ppcle | powerpclittle)
1034
- basic_machine=powerpcle-unknown
1035
- ;;
1036
- ppcle-* | powerpclittle-*)
1037
- basic_machine=powerpcle-`echo "$basic_machine" | sed 's/^[^-]*-//'`
1038
- ;;
1039
- ppc64) basic_machine=powerpc64-unknown
1040
- ;;
1041
- ppc64-*) basic_machine=powerpc64-`echo "$basic_machine" | sed 's/^[^-]*-//'`
1042
- ;;
1043
- ppc64le | powerpc64little)
1044
- basic_machine=powerpc64le-unknown
1045
- ;;
1046
- ppc64le-* | powerpc64little-*)
1047
- basic_machine=powerpc64le-`echo "$basic_machine" | sed 's/^[^-]*-//'`
1048
- ;;
1049
- ps2)
1050
- basic_machine=i386-ibm
1051
- ;;
1052
- pw32)
1053
- basic_machine=i586-unknown
1054
- os=-pw32
1055
- ;;
1056
- rdos | rdos64)
1057
- basic_machine=x86_64-pc
1058
- os=-rdos
1059
- ;;
1060
- rdos32)
1061
- basic_machine=i386-pc
1062
- os=-rdos
1063
- ;;
1064
- rom68k)
1065
- basic_machine=m68k-rom68k
1066
- os=-coff
1067
- ;;
1068
- rm[46]00)
1069
- basic_machine=mips-siemens
1070
- ;;
1071
- rtpc | rtpc-*)
1072
- basic_machine=romp-ibm
1073
- ;;
1074
- s390 | s390-*)
1075
- basic_machine=s390-ibm
1076
- ;;
1077
- s390x | s390x-*)
1078
- basic_machine=s390x-ibm
1079
- ;;
1080
- sa29200)
1081
- basic_machine=a29k-amd
1082
- os=-udi
1083
- ;;
1084
- sb1)
1085
- basic_machine=mipsisa64sb1-unknown
1086
- ;;
1087
- sb1el)
1088
- basic_machine=mipsisa64sb1el-unknown
1089
- ;;
1090
- sde)
1091
- basic_machine=mipsisa32-sde
1092
- os=-elf
1093
- ;;
1094
- sei)
1095
- basic_machine=mips-sei
1096
- os=-seiux
1097
- ;;
1098
- sequent)
1099
- basic_machine=i386-sequent
1100
- ;;
1101
- sh5el)
1102
- basic_machine=sh5le-unknown
1103
- ;;
1104
- simso-wrs)
1105
- basic_machine=sparclite-wrs
1106
- os=-vxworks
1107
- ;;
1108
- sps7)
1109
- basic_machine=m68k-bull
1110
- os=-sysv2
1111
- ;;
1112
- spur)
1113
- basic_machine=spur-unknown
1114
- ;;
1115
- st2000)
1116
- basic_machine=m68k-tandem
1117
- ;;
1118
- stratus)
1119
- basic_machine=i860-stratus
1120
- os=-sysv4
1121
- ;;
1122
- strongarm-* | thumb-*)
1123
- basic_machine=arm-`echo "$basic_machine" | sed 's/^[^-]*-//'`
1124
- ;;
1125
- sun2)
1126
- basic_machine=m68000-sun
1127
- ;;
1128
- sun2os3)
1129
- basic_machine=m68000-sun
1130
- os=-sunos3
1131
- ;;
1132
- sun2os4)
1133
- basic_machine=m68000-sun
1134
- os=-sunos4
1135
- ;;
1136
- sun3os3)
1137
- basic_machine=m68k-sun
1138
- os=-sunos3
1139
- ;;
1140
- sun3os4)
1141
- basic_machine=m68k-sun
1142
- os=-sunos4
1143
- ;;
1144
- sun4os3)
1145
- basic_machine=sparc-sun
1146
- os=-sunos3
1147
- ;;
1148
- sun4os4)
1149
- basic_machine=sparc-sun
1150
- os=-sunos4
1151
- ;;
1152
- sun4sol2)
1153
- basic_machine=sparc-sun
1154
- os=-solaris2
1155
- ;;
1156
- sun3 | sun3-*)
1157
- basic_machine=m68k-sun
1158
- ;;
1159
- sun4)
1160
- basic_machine=sparc-sun
1161
- ;;
1162
- sun386 | sun386i | roadrunner)
1163
- basic_machine=i386-sun
1164
- ;;
1165
- sv1)
1166
- basic_machine=sv1-cray
1167
- os=-unicos
1168
- ;;
1169
- symmetry)
1170
- basic_machine=i386-sequent
1171
- os=-dynix
1172
- ;;
1173
- t3e)
1174
- basic_machine=alphaev5-cray
1175
- os=-unicos
1176
- ;;
1177
- t90)
1178
- basic_machine=t90-cray
1179
- os=-unicos
1180
- ;;
1181
- tile*)
1182
- basic_machine=$basic_machine-unknown
1183
- os=-linux-gnu
1184
- ;;
1185
- tx39)
1186
- basic_machine=mipstx39-unknown
1187
- ;;
1188
- tx39el)
1189
- basic_machine=mipstx39el-unknown
1190
- ;;
1191
- toad1)
1192
- basic_machine=pdp10-xkl
1193
- os=-tops20
1194
- ;;
1195
- tower | tower-32)
1196
- basic_machine=m68k-ncr
1197
- ;;
1198
- tpf)
1199
- basic_machine=s390x-ibm
1200
- os=-tpf
1201
- ;;
1202
- udi29k)
1203
- basic_machine=a29k-amd
1204
- os=-udi
1205
- ;;
1206
- ultra3)
1207
- basic_machine=a29k-nyu
1208
- os=-sym1
1209
- ;;
1210
- v810 | necv810)
1211
- basic_machine=v810-nec
1212
- os=-none
1213
- ;;
1214
- vaxv)
1215
- basic_machine=vax-dec
1216
- os=-sysv
1217
- ;;
1218
- vms)
1219
- basic_machine=vax-dec
1220
- os=-vms
1221
- ;;
1222
- vpp*|vx|vx-*)
1223
- basic_machine=f301-fujitsu
1224
- ;;
1225
- vxworks960)
1226
- basic_machine=i960-wrs
1227
- os=-vxworks
1228
- ;;
1229
- vxworks68)
1230
- basic_machine=m68k-wrs
1231
- os=-vxworks
1232
- ;;
1233
- vxworks29k)
1234
- basic_machine=a29k-wrs
1235
- os=-vxworks
1236
- ;;
1237
- w65*)
1238
- basic_machine=w65-wdc
1239
- os=-none
1240
- ;;
1241
- w89k-*)
1242
- basic_machine=hppa1.1-winbond
1243
- os=-proelf
1244
- ;;
1245
- x64)
1246
- basic_machine=x86_64-pc
1247
- ;;
1248
- xbox)
1249
- basic_machine=i686-pc
1250
- os=-mingw32
1251
- ;;
1252
- xps | xps100)
1253
- basic_machine=xps100-honeywell
1254
- ;;
1255
- xscale-* | xscalee[bl]-*)
1256
- basic_machine=`echo "$basic_machine" | sed 's/^xscale/arm/'`
1257
- ;;
1258
- ymp)
1259
- basic_machine=ymp-cray
1260
- os=-unicos
1261
- ;;
1262
- none)
1263
- basic_machine=none-none
1264
- os=-none
1265
- ;;
1266
-
1267
-# Here we handle the default manufacturer of certain CPU types. It is in
1268
-# some cases the only manufacturer, in others, it is the most popular.
1269
- w89k)
1270
- basic_machine=hppa1.1-winbond
1271
- ;;
1272
- op50n)
1273
- basic_machine=hppa1.1-oki
1274
- ;;
1275
- op60c)
1276
- basic_machine=hppa1.1-oki
1277
- ;;
1278
- romp)
1279
- basic_machine=romp-ibm
1280
- ;;
1281
- mmix)
1282
- basic_machine=mmix-knuth
1283
- ;;
1284
- rs6000)
1285
- basic_machine=rs6000-ibm
1286
- ;;
1287
- vax)
1288
- basic_machine=vax-dec
1289
- ;;
1290
- pdp11)
1291
- basic_machine=pdp11-dec
1292
- ;;
1293
- we32k)
1294
- basic_machine=we32k-att
1295
- ;;
1296
- sh[1234] | sh[24]a | sh[24]aeb | sh[34]eb | sh[1234]le | sh[23]ele)
1297
- basic_machine=sh-unknown
1298
- ;;
1299
- cydra)
1300
- basic_machine=cydra-cydrome
1301
- ;;
1302
- orion)
1303
- basic_machine=orion-highlevel
1304
- ;;
1305
- orion105)
1306
- basic_machine=clipper-highlevel
1307
- ;;
1308
- mac | mpw | mac-mpw)
1309
- basic_machine=m68k-apple
1310
- ;;
1311
- pmac | pmac-mpw)
1312
- basic_machine=powerpc-apple
1313
- ;;
1314
- *-unknown)
1315
- # Make sure to match an already-canonicalized machine name.
1316
- ;;
1317
- *)
1318
- echo Invalid configuration \`"$1"\': machine \`"$basic_machine"\' not recognized 1>&2
1319
- exit 1
1153
+ cpu=nsx
1154
+ vendor=tandem
1155
+ ;;
1156
+ mipsallegrexel-sony)
1157
+ cpu=mipsallegrexel
1158
+ vendor=sony
1159
+ ;;
1160
+ tile*-*)
1161
+ basic_os=${basic_os:-linux-gnu}
1162
+ ;;
1163
+
1164
+ *)
1165
+ # Recognize the canonical CPU types that are allowed with any
1166
+ # company name.
1167
+ case $cpu in
1168
+ 1750a | 580 \
1169
+ | a29k \
1170
+ | aarch64 | aarch64_be \
1171
+ | abacus \
1172
+ | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] \
1173
+ | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] \
1174
+ | alphapca5[67] | alpha64pca5[67] \
1175
+ | am33_2.0 \
1176
+ | amdgcn \
1177
+ | arc | arceb | arc32 | arc64 \
1178
+ | arm | arm[lb]e | arme[lb] | armv* \
1179
+ | avr | avr32 \
1180
+ | asmjs \
1181
+ | ba \
1182
+ | be32 | be64 \
1183
+ | bfin | bpf | bs2000 \
1184
+ | c[123]* | c30 | [cjt]90 | c4x \
1185
+ | c8051 | clipper | craynv | csky | cydra \
1186
+ | d10v | d30v | dlx | dsp16xx \
1187
+ | e2k | elxsi | epiphany \
1188
+ | f30[01] | f700 | fido | fr30 | frv | ft32 | fx80 \
1189
+ | h8300 | h8500 \
1190
+ | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
1191
+ | hexagon \
1192
+ | i370 | i*86 | i860 | i960 | ia16 | ia64 \
1193
+ | ip2k | iq2000 \
1194
+ | k1om \
1195
+ | le32 | le64 \
1196
+ | lm32 \
1197
+ | loongarch32 | loongarch64 | loongarchx32 \
1198
+ | m32c | m32r | m32rle \
1199
+ | m5200 | m68000 | m680[012346]0 | m68360 | m683?2 | m68k \
1200
+ | m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x \
1201
+ | m88110 | m88k | maxq | mb | mcore | mep | metag \
1202
+ | microblaze | microblazeel \
1203
+ | mips | mipsbe | mipseb | mipsel | mipsle \
1204
+ | mips16 \
1205
+ | mips64 | mips64eb | mips64el \
1206
+ | mips64octeon | mips64octeonel \
1207
+ | mips64orion | mips64orionel \
1208
+ | mips64r5900 | mips64r5900el \
1209
+ | mips64vr | mips64vrel \
1210
+ | mips64vr4100 | mips64vr4100el \
1211
+ | mips64vr4300 | mips64vr4300el \
1212
+ | mips64vr5000 | mips64vr5000el \
1213
+ | mips64vr5900 | mips64vr5900el \
1214
+ | mipsisa32 | mipsisa32el \
1215
+ | mipsisa32r2 | mipsisa32r2el \
1216
+ | mipsisa32r3 | mipsisa32r3el \
1217
+ | mipsisa32r5 | mipsisa32r5el \
1218
+ | mipsisa32r6 | mipsisa32r6el \
1219
+ | mipsisa64 | mipsisa64el \
1220
+ | mipsisa64r2 | mipsisa64r2el \
1221
+ | mipsisa64r3 | mipsisa64r3el \
1222
+ | mipsisa64r5 | mipsisa64r5el \
1223
+ | mipsisa64r6 | mipsisa64r6el \
1224
+ | mipsisa64sb1 | mipsisa64sb1el \
1225
+ | mipsisa64sr71k | mipsisa64sr71kel \
1226
+ | mipsr5900 | mipsr5900el \
1227
+ | mipstx39 | mipstx39el \
1228
+ | mmix \
1229
+ | mn10200 | mn10300 \
1230
+ | moxie \
1231
+ | mt \
1232
+ | msp430 \
1233
+ | nds32 | nds32le | nds32be \
1234
+ | nfp \
1235
+ | nios | nios2 | nios2eb | nios2el \
1236
+ | none | np1 | ns16k | ns32k | nvptx \
1237
+ | open8 \
1238
+ | or1k* \
1239
+ | or32 \
1240
+ | orion \
1241
+ | picochip \
1242
+ | pdp10 | pdp11 | pj | pjl | pn | power \
1243
+ | powerpc | powerpc64 | powerpc64le | powerpcle | powerpcspe \
1244
+ | pru \
1245
+ | pyramid \
1246
+ | riscv | riscv32 | riscv32be | riscv64 | riscv64be \
1247
+ | rl78 | romp | rs6000 | rx \
1248
+ | s390 | s390x \
1249
+ | score \
1250
+ | sh | shl \
1251
+ | sh[1234] | sh[24]a | sh[24]ae[lb] | sh[23]e | she[lb] | sh[lb]e \
1252
+ | sh[1234]e[lb] | sh[12345][lb]e | sh[23]ele | sh64 | sh64le \
1253
+ | sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet \
1254
+ | sparclite \
1255
+ | sparcv8 | sparcv9 | sparcv9b | sparcv9v | sv1 | sx* \
1256
+ | spu \
1257
+ | tahoe \
1258
+ | thumbv7* \
1259
+ | tic30 | tic4x | tic54x | tic55x | tic6x | tic80 \
1260
+ | tron \
1261
+ | ubicom32 \
1262
+ | v70 | v850 | v850e | v850e1 | v850es | v850e2 | v850e2v3 \
1263
+ | vax \
1264
+ | visium \
1265
+ | w65 \
1266
+ | wasm32 | wasm64 \
1267
+ | we32k \
1268
+ | x86 | x86_64 | xc16x | xgate | xps100 \
1269
+ | xstormy16 | xtensa* \
1270
+ | ymp \
1271
+ | z8k | z80)
1272
+ ;;
1273
+
1274
+ *)
1275
+ echo Invalid configuration \`"$1"\': machine \`"$cpu-$vendor"\' not recognized 1>&2
1276
+ exit 1
1277
+ ;;
1278
+ esac
13201279
;;
13211280
esac
13221281
13231282
# Here we canonicalize certain aliases for manufacturers.
1324
-case $basic_machine in
1325
- *-digital*)
1326
- basic_machine=`echo "$basic_machine" | sed 's/digital.*/dec/'`
1283
+case $vendor in
1284
+ digital*)
1285
+ vendor=dec
13271286
;;
1328
- *-commodore*)
1329
- basic_machine=`echo "$basic_machine" | sed 's/commodore.*/cbm/'`
1287
+ commodore*)
1288
+ vendor=cbm
13301289
;;
13311290
*)
13321291
;;
13331292
esac
13341293
13351294
# Decode manufacturer-specific aliases for certain operating systems.
13361295
1337
-if [ x"$os" != x"" ]
1296
+if test x$basic_os != x
13381297
then
1298
+
1299
+# First recognize some ad-hoc caes, or perhaps split kernel-os, or else just
1300
+# set os.
1301
+case $basic_os in
1302
+ gnu/linux*)
1303
+ kernel=linux
1304
+ os=`echo "$basic_os" | sed -e 's|gnu/linux|gnu|'`
1305
+ ;;
1306
+ os2-emx)
1307
+ kernel=os2
1308
+ os=`echo "$basic_os" | sed -e 's|os2-emx|emx|'`
1309
+ ;;
1310
+ nto-qnx*)
1311
+ kernel=nto
1312
+ os=`echo "$basic_os" | sed -e 's|nto-qnx|qnx|'`
1313
+ ;;
1314
+ *-*)
1315
+ # shellcheck disable=SC2162
1316
+ IFS="-" read kernel os <<EOF
1317
+$basic_os
1318
+EOF
1319
+ ;;
1320
+ # Default OS when just kernel was specified
1321
+ nto*)
1322
+ kernel=nto
1323
+ os=`echo "$basic_os" | sed -e 's|nto|qnx|'`
1324
+ ;;
1325
+ linux*)
1326
+ kernel=linux
1327
+ os=`echo "$basic_os" | sed -e 's|linux|gnu|'`
1328
+ ;;
1329
+ *)
1330
+ kernel=
1331
+ os=$basic_os
1332
+ ;;
1333
+esac
1334
+
1335
+# Now, normalize the OS (knowing we just have one component, it's not a kernel,
1336
+# etc.)
13391337
case $os in
13401338
# First match some system type aliases that might get confused
13411339
# with valid system types.
1342
- # -solaris* is a basic system type, with this one exception.
1343
- -auroraux)
1344
- os=-auroraux
1345
- ;;
1346
- -solaris1 | -solaris1.*)
1347
- os=`echo $os | sed -e 's|solaris1|sunos4|'`
1348
- ;;
1349
- -solaris)
1350
- os=-solaris2
1351
- ;;
1352
- -unixware*)
1353
- os=-sysv4.2uw
1354
- ;;
1355
- -gnu/linux*)
1356
- os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'`
1340
+ # solaris* is a basic system type, with this one exception.
1341
+ auroraux)
1342
+ os=auroraux
1343
+ ;;
1344
+ bluegene*)
1345
+ os=cnk
1346
+ ;;
1347
+ solaris1 | solaris1.*)
1348
+ os=`echo "$os" | sed -e 's|solaris1|sunos4|'`
1349
+ ;;
1350
+ solaris)
1351
+ os=solaris2
1352
+ ;;
1353
+ unixware*)
1354
+ os=sysv4.2uw
13571355
;;
13581356
# es1800 is here to avoid being matched by es* (a different OS)
1359
- -es1800*)
1360
- os=-ose
1361
- ;;
1362
- # Now accept the basic system types.
1363
- # The portable systems comes first.
1364
- # Each alternative MUST end in a * to match a version number.
1365
- # -sysv* is not here because it comes later, after sysvr4.
1366
- -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \
1367
- | -*vms* | -sco* | -esix* | -isc* | -aix* | -cnk* | -sunos | -sunos[34]*\
1368
- | -hpux* | -unos* | -osf* | -luna* | -dgux* | -auroraux* | -solaris* \
1369
- | -sym* | -kopensolaris* | -plan9* \
1370
- | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
1371
- | -aos* | -aros* | -cloudabi* | -sortix* \
1372
- | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
1373
- | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
1374
- | -hiux* | -knetbsd* | -mirbsd* | -netbsd* \
1375
- | -bitrig* | -openbsd* | -solidbsd* | -libertybsd* \
1376
- | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \
1377
- | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \
1378
- | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
1379
- | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* | -hcos* \
1380
- | -chorusos* | -chorusrdb* | -cegcc* | -glidix* \
1381
- | -cygwin* | -msys* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
1382
- | -midipix* | -mingw32* | -mingw64* | -linux-gnu* | -linux-android* \
1383
- | -linux-newlib* | -linux-musl* | -linux-uclibc* \
1384
- | -uxpv* | -beos* | -mpeix* | -udk* | -moxiebox* \
1385
- | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* \
1386
- | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
1387
- | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \
1388
- | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \
1389
- | -morphos* | -superux* | -rtmk* | -windiss* \
1390
- | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \
1391
- | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es* \
1392
- | -onefs* | -tirtos* | -phoenix* | -fuchsia* | -redox* | -bme* \
1393
- | -midnightbsd*)
1394
- # Remember, each alternative MUST END IN *, to match a version number.
1395
- ;;
1396
- -qnx*)
1397
- case $basic_machine in
1398
- x86-* | i*86-*)
1399
- ;;
1400
- *)
1401
- os=-nto$os
1402
- ;;
1403
- esac
1404
- ;;
1405
- -nto-qnx*)
1406
- ;;
1407
- -nto*)
1408
- os=`echo $os | sed -e 's|nto|nto-qnx|'`
1409
- ;;
1410
- -sim | -xray | -os68k* | -v88r* \
1411
- | -windows* | -osx | -abug | -netware* | -os9* \
1412
- | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*)
1413
- ;;
1414
- -mac*)
1357
+ es1800*)
1358
+ os=ose
1359
+ ;;
1360
+ # Some version numbers need modification
1361
+ chorusos*)
1362
+ os=chorusos
1363
+ ;;
1364
+ isc)
1365
+ os=isc2.2
1366
+ ;;
1367
+ sco6)
1368
+ os=sco5v6
1369
+ ;;
1370
+ sco5)
1371
+ os=sco3.2v5
1372
+ ;;
1373
+ sco4)
1374
+ os=sco3.2v4
1375
+ ;;
1376
+ sco3.2.[4-9]*)
1377
+ os=`echo "$os" | sed -e 's/sco3.2./sco3.2v/'`
1378
+ ;;
1379
+ sco*v* | scout)
1380
+ # Don't match below
1381
+ ;;
1382
+ sco*)
1383
+ os=sco3.2v2
1384
+ ;;
1385
+ psos*)
1386
+ os=psos
1387
+ ;;
1388
+ qnx*)
1389
+ os=qnx
1390
+ ;;
1391
+ hiux*)
1392
+ os=hiuxwe2
1393
+ ;;
1394
+ lynx*178)
1395
+ os=lynxos178
1396
+ ;;
1397
+ lynx*5)
1398
+ os=lynxos5
1399
+ ;;
1400
+ lynxos*)
1401
+ # don't get caught up in next wildcard
1402
+ ;;
1403
+ lynx*)
1404
+ os=lynxos
1405
+ ;;
1406
+ mac[0-9]*)
14151407
os=`echo "$os" | sed -e 's|mac|macos|'`
14161408
;;
1417
- -linux-dietlibc)
1418
- os=-linux-dietlibc
1409
+ opened*)
1410
+ os=openedition
14191411
;;
1420
- -linux*)
1421
- os=`echo $os | sed -e 's|linux|linux-gnu|'`
1412
+ os400*)
1413
+ os=os400
14221414
;;
1423
- -sunos5*)
1415
+ sunos5*)
14241416
os=`echo "$os" | sed -e 's|sunos5|solaris2|'`
14251417
;;
1426
- -sunos6*)
1418
+ sunos6*)
14271419
os=`echo "$os" | sed -e 's|sunos6|solaris3|'`
14281420
;;
1429
- -opened*)
1430
- os=-openedition
1431
- ;;
1432
- -os400*)
1433
- os=-os400
1434
- ;;
1435
- -wince*)
1436
- os=-wince
1437
- ;;
1438
- -utek*)
1439
- os=-bsd
1440
- ;;
1441
- -dynix*)
1442
- os=-bsd
1443
- ;;
1444
- -acis*)
1445
- os=-aos
1446
- ;;
1447
- -atheos*)
1448
- os=-atheos
1449
- ;;
1450
- -syllable*)
1451
- os=-syllable
1452
- ;;
1453
- -386bsd)
1454
- os=-bsd
1455
- ;;
1456
- -ctix* | -uts*)
1457
- os=-sysv
1458
- ;;
1459
- -nova*)
1460
- os=-rtmk-nova
1461
- ;;
1462
- -ns2)
1463
- os=-nextstep2
1464
- ;;
1465
- -nsk*)
1466
- os=-nsk
1421
+ wince*)
1422
+ os=wince
1423
+ ;;
1424
+ utek*)
1425
+ os=bsd
1426
+ ;;
1427
+ dynix*)
1428
+ os=bsd
1429
+ ;;
1430
+ acis*)
1431
+ os=aos
1432
+ ;;
1433
+ atheos*)
1434
+ os=atheos
1435
+ ;;
1436
+ syllable*)
1437
+ os=syllable
1438
+ ;;
1439
+ 386bsd)
1440
+ os=bsd
1441
+ ;;
1442
+ ctix* | uts*)
1443
+ os=sysv
1444
+ ;;
1445
+ nova*)
1446
+ os=rtmk-nova
1447
+ ;;
1448
+ ns2)
1449
+ os=nextstep2
14671450
;;
14681451
# Preserve the version number of sinix5.
1469
- -sinix5.*)
1470
- os=`echo $os | sed -e 's|sinix|sysv|'`
1471
- ;;
1472
- -sinix*)
1473
- os=-sysv4
1474
- ;;
1475
- -tpf*)
1476
- os=-tpf
1477
- ;;
1478
- -triton*)
1479
- os=-sysv3
1480
- ;;
1481
- -oss*)
1482
- os=-sysv3
1483
- ;;
1484
- -svr4*)
1485
- os=-sysv4
1486
- ;;
1487
- -svr3)
1488
- os=-sysv3
1489
- ;;
1490
- -sysvr4)
1491
- os=-sysv4
1492
- ;;
1493
- # This must come after -sysvr4.
1494
- -sysv*)
1495
- ;;
1496
- -ose*)
1497
- os=-ose
1498
- ;;
1499
- -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
1500
- os=-mint
1501
- ;;
1502
- -zvmoe)
1503
- os=-zvmoe
1504
- ;;
1505
- -dicos*)
1506
- os=-dicos
1507
- ;;
1508
- -pikeos*)
1452
+ sinix5.*)
1453
+ os=`echo "$os" | sed -e 's|sinix|sysv|'`
1454
+ ;;
1455
+ sinix*)
1456
+ os=sysv4
1457
+ ;;
1458
+ tpf*)
1459
+ os=tpf
1460
+ ;;
1461
+ triton*)
1462
+ os=sysv3
1463
+ ;;
1464
+ oss*)
1465
+ os=sysv3
1466
+ ;;
1467
+ svr4*)
1468
+ os=sysv4
1469
+ ;;
1470
+ svr3)
1471
+ os=sysv3
1472
+ ;;
1473
+ sysvr4)
1474
+ os=sysv4
1475
+ ;;
1476
+ ose*)
1477
+ os=ose
1478
+ ;;
1479
+ *mint | mint[0-9]* | *MiNT | MiNT[0-9]*)
1480
+ os=mint
1481
+ ;;
1482
+ dicos*)
1483
+ os=dicos
1484
+ ;;
1485
+ pikeos*)
15091486
# Until real need of OS specific support for
15101487
# particular features comes up, bare metal
15111488
# configurations are quite functional.
1512
- case $basic_machine in
1513
- arm*)
1514
- os=-eabi
1515
- ;;
1516
- *)
1517
- os=-elf
1518
- ;;
1519
- esac
1520
- ;;
1521
- -nacl*)
1522
- ;;
1523
- -ios)
1524
- ;;
1525
- -none)
1526
- ;;
1527
- *)
1528
- # Get rid of the `-' at the beginning of $os.
1529
- os=`echo $os | sed 's/[^-]*-//'`
1530
- echo Invalid configuration \`"$1"\': system \`"$os"\' not recognized 1>&2
1531
- exit 1
1532
- ;;
1533
-esac
1489
+ case $cpu in
1490
+ arm*)
1491
+ os=eabi
1492
+ ;;
1493
+ *)
1494
+ os=elf
1495
+ ;;
1496
+ esac
1497
+ ;;
1498
+ *)
1499
+ # No normalization, but not necessarily accepted, that comes below.
1500
+ ;;
1501
+esac
1502
+
15341503
else
15351504
15361505
# Here we handle the default operating systems that come with various machines.
15371506
# The value should be what the vendor currently ships out the door with their
15381507
# machine or put another way, the most popular os provided with the machine.
@@ -1541,261 +1510,364 @@
15411510
# "-sun"), then you have to tell the case statement up towards the top
15421511
# that MANUFACTURER isn't an operating system. Otherwise, code above
15431512
# will signal an error saying that MANUFACTURER isn't an operating
15441513
# system, and we'll never get to this point.
15451514
1546
-case $basic_machine in
1515
+kernel=
1516
+case $cpu-$vendor in
15471517
score-*)
1548
- os=-elf
1518
+ os=elf
15491519
;;
15501520
spu-*)
1551
- os=-elf
1521
+ os=elf
15521522
;;
15531523
*-acorn)
1554
- os=-riscix1.2
1524
+ os=riscix1.2
15551525
;;
15561526
arm*-rebel)
1557
- os=-linux
1527
+ kernel=linux
1528
+ os=gnu
15581529
;;
15591530
arm*-semi)
1560
- os=-aout
1531
+ os=aout
15611532
;;
15621533
c4x-* | tic4x-*)
1563
- os=-coff
1534
+ os=coff
15641535
;;
15651536
c8051-*)
1566
- os=-elf
1537
+ os=elf
1538
+ ;;
1539
+ clipper-intergraph)
1540
+ os=clix
15671541
;;
15681542
hexagon-*)
1569
- os=-elf
1543
+ os=elf
15701544
;;
15711545
tic54x-*)
1572
- os=-coff
1546
+ os=coff
15731547
;;
15741548
tic55x-*)
1575
- os=-coff
1549
+ os=coff
15761550
;;
15771551
tic6x-*)
1578
- os=-coff
1552
+ os=coff
15791553
;;
15801554
# This must come before the *-dec entry.
15811555
pdp10-*)
1582
- os=-tops20
1556
+ os=tops20
15831557
;;
15841558
pdp11-*)
1585
- os=-none
1559
+ os=none
15861560
;;
15871561
*-dec | vax-*)
1588
- os=-ultrix4.2
1562
+ os=ultrix4.2
15891563
;;
15901564
m68*-apollo)
1591
- os=-domain
1565
+ os=domain
15921566
;;
15931567
i386-sun)
1594
- os=-sunos4.0.2
1568
+ os=sunos4.0.2
15951569
;;
15961570
m68000-sun)
1597
- os=-sunos3
1571
+ os=sunos3
15981572
;;
15991573
m68*-cisco)
1600
- os=-aout
1574
+ os=aout
16011575
;;
16021576
mep-*)
1603
- os=-elf
1577
+ os=elf
16041578
;;
16051579
mips*-cisco)
1606
- os=-elf
1580
+ os=elf
16071581
;;
16081582
mips*-*)
1609
- os=-elf
1583
+ os=elf
16101584
;;
16111585
or32-*)
1612
- os=-coff
1586
+ os=coff
16131587
;;
16141588
*-tti) # must be before sparc entry or we get the wrong os.
1615
- os=-sysv3
1589
+ os=sysv3
16161590
;;
16171591
sparc-* | *-sun)
1618
- os=-sunos4.1.1
1592
+ os=sunos4.1.1
16191593
;;
16201594
pru-*)
1621
- os=-elf
1595
+ os=elf
16221596
;;
16231597
*-be)
1624
- os=-beos
1598
+ os=beos
16251599
;;
16261600
*-ibm)
1627
- os=-aix
1601
+ os=aix
16281602
;;
16291603
*-knuth)
1630
- os=-mmixware
1604
+ os=mmixware
16311605
;;
16321606
*-wec)
1633
- os=-proelf
1607
+ os=proelf
16341608
;;
16351609
*-winbond)
1636
- os=-proelf
1610
+ os=proelf
16371611
;;
16381612
*-oki)
1639
- os=-proelf
1613
+ os=proelf
16401614
;;
16411615
*-hp)
1642
- os=-hpux
1616
+ os=hpux
16431617
;;
16441618
*-hitachi)
1645
- os=-hiux
1619
+ os=hiux
16461620
;;
16471621
i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent)
1648
- os=-sysv
1622
+ os=sysv
16491623
;;
16501624
*-cbm)
1651
- os=-amigaos
1625
+ os=amigaos
16521626
;;
16531627
*-dg)
1654
- os=-dgux
1628
+ os=dgux
16551629
;;
16561630
*-dolphin)
1657
- os=-sysv3
1631
+ os=sysv3
16581632
;;
16591633
m68k-ccur)
1660
- os=-rtu
1634
+ os=rtu
16611635
;;
16621636
m88k-omron*)
1663
- os=-luna
1637
+ os=luna
16641638
;;
16651639
*-next)
1666
- os=-nextstep
1640
+ os=nextstep
16671641
;;
16681642
*-sequent)
1669
- os=-ptx
1643
+ os=ptx
16701644
;;
16711645
*-crds)
1672
- os=-unos
1646
+ os=unos
16731647
;;
16741648
*-ns)
1675
- os=-genix
1649
+ os=genix
16761650
;;
16771651
i370-*)
1678
- os=-mvs
1652
+ os=mvs
16791653
;;
16801654
*-gould)
1681
- os=-sysv
1655
+ os=sysv
16821656
;;
16831657
*-highlevel)
1684
- os=-bsd
1658
+ os=bsd
16851659
;;
16861660
*-encore)
1687
- os=-bsd
1661
+ os=bsd
16881662
;;
16891663
*-sgi)
1690
- os=-irix
1664
+ os=irix
16911665
;;
16921666
*-siemens)
1693
- os=-sysv4
1667
+ os=sysv4
16941668
;;
16951669
*-masscomp)
1696
- os=-rtu
1670
+ os=rtu
16971671
;;
16981672
f30[01]-fujitsu | f700-fujitsu)
1699
- os=-uxpv
1673
+ os=uxpv
17001674
;;
17011675
*-rom68k)
1702
- os=-coff
1676
+ os=coff
17031677
;;
17041678
*-*bug)
1705
- os=-coff
1679
+ os=coff
17061680
;;
17071681
*-apple)
1708
- os=-macos
1682
+ os=macos
17091683
;;
17101684
*-atari*)
1711
- os=-mint
1685
+ os=mint
1686
+ ;;
1687
+ *-wrs)
1688
+ os=vxworks
1689
+ ;;
1690
+ *)
1691
+ os=none
1692
+ ;;
1693
+esac
1694
+
1695
+fi
1696
+
1697
+# Now, validate our (potentially fixed-up) OS.
1698
+case $os in
1699
+ # Sometimes we do "kernel-libc", so those need to count as OSes.
1700
+ musl* | newlib* | uclibc*)
1701
+ ;;
1702
+ # Likewise for "kernel-abi"
1703
+ eabi* | gnueabi*)
1704
+ ;;
1705
+ # VxWorks passes extra cpu info in the 4th filed.
1706
+ simlinux | simwindows | spe)
1707
+ ;;
1708
+ # Now accept the basic system types.
1709
+ # The portable systems comes first.
1710
+ # Each alternative MUST end in a * to match a version number.
1711
+ gnu* | android* | bsd* | mach* | minix* | genix* | ultrix* | irix* \
1712
+ | *vms* | esix* | aix* | cnk* | sunos | sunos[34]* \
1713
+ | hpux* | unos* | osf* | luna* | dgux* | auroraux* | solaris* \
1714
+ | sym* | plan9* | psp* | sim* | xray* | os68k* | v88r* \
1715
+ | hiux* | abug | nacl* | netware* | windows* \
1716
+ | os9* | macos* | osx* | ios* \
1717
+ | mpw* | magic* | mmixware* | mon960* | lnews* \
1718
+ | amigaos* | amigados* | msdos* | newsos* | unicos* | aof* \
1719
+ | aos* | aros* | cloudabi* | sortix* | twizzler* \
1720
+ | nindy* | vxsim* | vxworks* | ebmon* | hms* | mvs* \
1721
+ | clix* | riscos* | uniplus* | iris* | isc* | rtu* | xenix* \
1722
+ | mirbsd* | netbsd* | dicos* | openedition* | ose* \
1723
+ | bitrig* | openbsd* | secbsd* | solidbsd* | libertybsd* | os108* \
1724
+ | ekkobsd* | freebsd* | riscix* | lynxos* | os400* \
1725
+ | bosx* | nextstep* | cxux* | aout* | elf* | oabi* \
1726
+ | ptx* | coff* | ecoff* | winnt* | domain* | vsta* \
1727
+ | udi* | lites* | ieee* | go32* | aux* | hcos* \
1728
+ | chorusrdb* | cegcc* | glidix* | serenity* \
1729
+ | cygwin* | msys* | pe* | moss* | proelf* | rtems* \
1730
+ | midipix* | mingw32* | mingw64* | mint* \
1731
+ | uxpv* | beos* | mpeix* | udk* | moxiebox* \
1732
+ | interix* | uwin* | mks* | rhapsody* | darwin* \
1733
+ | openstep* | oskit* | conix* | pw32* | nonstopux* \
1734
+ | storm-chaos* | tops10* | tenex* | tops20* | its* \
1735
+ | os2* | vos* | palmos* | uclinux* | nucleus* | morphos* \
1736
+ | scout* | superux* | sysv* | rtmk* | tpf* | windiss* \
1737
+ | powermax* | dnix* | nx6 | nx7 | sei* | dragonfly* \
1738
+ | skyos* | haiku* | rdos* | toppers* | drops* | es* \
1739
+ | onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \
1740
+ | midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \
1741
+ | nsk* | powerunix* | genode* | zvmoe* | qnx* | emx*)
1742
+ ;;
1743
+ # This one is extra strict with allowed versions
1744
+ sco3.2v2 | sco3.2v[4-9]* | sco5v6*)
1745
+ # Don't forget version if it is 3.2v4 or newer.
1746
+ ;;
1747
+ none)
17121748
;;
17131749
*)
1714
- os=-none
1750
+ echo Invalid configuration \`"$1"\': OS \`"$os"\' not recognized 1>&2
1751
+ exit 1
17151752
;;
17161753
esac
1717
-fi
1754
+
1755
+# As a final step for OS-related things, validate the OS-kernel combination
1756
+# (given a valid OS), if there is a kernel.
1757
+case $kernel-$os in
1758
+ linux-gnu* | linux-dietlibc* | linux-android* | linux-newlib* | linux-musl* | linux-uclibc* )
1759
+ ;;
1760
+ uclinux-uclibc* )
1761
+ ;;
1762
+ -dietlibc* | -newlib* | -musl* | -uclibc* )
1763
+ # These are just libc implementations, not actual OSes, and thus
1764
+ # require a kernel.
1765
+ echo "Invalid configuration \`$1': libc \`$os' needs explicit kernel." 1>&2
1766
+ exit 1
1767
+ ;;
1768
+ kfreebsd*-gnu* | kopensolaris*-gnu*)
1769
+ ;;
1770
+ vxworks-simlinux | vxworks-simwindows | vxworks-spe)
1771
+ ;;
1772
+ nto-qnx*)
1773
+ ;;
1774
+ os2-emx)
1775
+ ;;
1776
+ *-eabi* | *-gnueabi*)
1777
+ ;;
1778
+ -*)
1779
+ # Blank kernel with real OS is always fine.
1780
+ ;;
1781
+ *-*)
1782
+ echo "Invalid configuration \`$1': Kernel \`$kernel' not known to work with OS \`$os'." 1>&2
1783
+ exit 1
1784
+ ;;
1785
+esac
17181786
17191787
# Here we handle the case where we know the os, and the CPU type, but not the
17201788
# manufacturer. We pick the logical manufacturer.
1721
-vendor=unknown
1722
-case $basic_machine in
1723
- *-unknown)
1724
- case $os in
1725
- -riscix*)
1789
+case $vendor in
1790
+ unknown)
1791
+ case $cpu-$os in
1792
+ *-riscix*)
17261793
vendor=acorn
17271794
;;
1728
- -sunos*)
1795
+ *-sunos*)
17291796
vendor=sun
17301797
;;
1731
- -cnk*|-aix*)
1798
+ *-cnk* | *-aix*)
17321799
vendor=ibm
17331800
;;
1734
- -beos*)
1801
+ *-beos*)
17351802
vendor=be
17361803
;;
1737
- -hpux*)
1804
+ *-hpux*)
17381805
vendor=hp
17391806
;;
1740
- -mpeix*)
1807
+ *-mpeix*)
17411808
vendor=hp
17421809
;;
1743
- -hiux*)
1810
+ *-hiux*)
17441811
vendor=hitachi
17451812
;;
1746
- -unos*)
1813
+ *-unos*)
17471814
vendor=crds
17481815
;;
1749
- -dgux*)
1816
+ *-dgux*)
17501817
vendor=dg
17511818
;;
1752
- -luna*)
1819
+ *-luna*)
17531820
vendor=omron
17541821
;;
1755
- -genix*)
1756
- vendor=ns
1757
- ;;
1758
- -mvs* | -opened*)
1759
- vendor=ibm
1760
- ;;
1761
- -os400*)
1762
- vendor=ibm
1763
- ;;
1764
- -ptx*)
1765
- vendor=sequent
1766
- ;;
1767
- -tpf*)
1768
- vendor=ibm
1769
- ;;
1770
- -vxsim* | -vxworks* | -windiss*)
1771
- vendor=wrs
1772
- ;;
1773
- -aux*)
1774
- vendor=apple
1775
- ;;
1776
- -hms*)
1777
- vendor=hitachi
1778
- ;;
1779
- -mpw* | -macos*)
1780
- vendor=apple
1781
- ;;
1782
- -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
1783
- vendor=atari
1784
- ;;
1785
- -vos*)
1822
+ *-genix*)
1823
+ vendor=ns
1824
+ ;;
1825
+ *-clix*)
1826
+ vendor=intergraph
1827
+ ;;
1828
+ *-mvs* | *-opened*)
1829
+ vendor=ibm
1830
+ ;;
1831
+ *-os400*)
1832
+ vendor=ibm
1833
+ ;;
1834
+ s390-* | s390x-*)
1835
+ vendor=ibm
1836
+ ;;
1837
+ *-ptx*)
1838
+ vendor=sequent
1839
+ ;;
1840
+ *-tpf*)
1841
+ vendor=ibm
1842
+ ;;
1843
+ *-vxsim* | *-vxworks* | *-windiss*)
1844
+ vendor=wrs
1845
+ ;;
1846
+ *-aux*)
1847
+ vendor=apple
1848
+ ;;
1849
+ *-hms*)
1850
+ vendor=hitachi
1851
+ ;;
1852
+ *-mpw* | *-macos*)
1853
+ vendor=apple
1854
+ ;;
1855
+ *-*mint | *-mint[0-9]* | *-*MiNT | *-MiNT[0-9]*)
1856
+ vendor=atari
1857
+ ;;
1858
+ *-vos*)
17861859
vendor=stratus
17871860
;;
17881861
esac
1789
- basic_machine=`echo "$basic_machine" | sed "s/unknown/$vendor/"`
17901862
;;
17911863
esac
17921864
1793
-echo "$basic_machine$os"
1865
+echo "$cpu-$vendor-${kernel:+$kernel-}$os"
17941866
exit
17951867
17961868
# Local variables:
17971869
# eval: (add-hook 'before-save-hook 'time-stamp)
17981870
# time-stamp-start: "timestamp='"
17991871
# time-stamp-format: "%:y-%02m-%02d"
18001872
# time-stamp-end: "'"
18011873
# End:
18021874
--- autosetup/autosetup-config.sub
+++ autosetup/autosetup-config.sub
@@ -1,10 +1,12 @@
1 #! /bin/sh
2 # Configuration validation subroutine script.
3 # Copyright 1992-2018 Free Software Foundation, Inc.
 
 
4
5 timestamp='2018-03-08'
6
7 # This file is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
@@ -31,11 +33,11 @@
31 # Supply the specified configuration type as an argument.
32 # If it is invalid, we print an error message on stderr and exit with code 1.
33 # Otherwise, we print the canonical config type on stdout and succeed.
34
35 # You can get the latest version of this script from:
36 # https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub
37
38 # This file is supposed to be the same for all GNU packages
39 # and recognize all the CPU types, system types and aliases
40 # that are meaningful with *any* GNU software.
41 # Each package is responsible for reporting which valid configurations
@@ -47,10 +49,17 @@
47 # machine specification into a single specification in the form:
48 # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM
49 # or in some cases, the newer four-part form:
50 # CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM
51 # It is wrong to echo any other type of specification.
 
 
 
 
 
 
 
52
53 me=`echo "$0" | sed -e 's,.*/,,'`
54
55 usage="\
56 Usage: $0 [OPTION] CPU-MFR-OPSYS or ALIAS
@@ -65,11 +74,11 @@
65 Report bugs and patches to <[email protected]>."
66
67 version="\
68 GNU config.sub ($timestamp)
69
70 Copyright 1992-2018 Free Software Foundation, Inc.
71
72 This is free software; see the source for copying conditions. There is NO
73 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
74
75 help="
@@ -87,11 +96,11 @@
87 -- ) # Stop option processing
88 shift; break ;;
89 - ) # Use stdin as input.
90 break ;;
91 -* )
92 echo "$me: invalid option $1$help"
93 exit 1 ;;
94
95 *local*)
96 # First pass through any local machine types.
97 echo "$1"
@@ -108,1431 +117,1391 @@
108 1) ;;
109 *) echo "$me: too many arguments$help" >&2
110 exit 1;;
111 esac
112
113 # Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any).
114 # Here we must recognize all the valid KERNEL-OS combinations.
115 maybe_os=`echo "$1" | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
116 case $maybe_os in
117 nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc | linux-newlib* | \
118 linux-musl* | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \
119 knetbsd*-gnu* | netbsd*-gnu* | netbsd*-eabi* | \
120 kopensolaris*-gnu* | cloudabi*-eabi* | \
121 storm-chaos* | os2-emx* | rtmk-nova*)
122 os=-$maybe_os
123 basic_machine=`echo "$1" | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
124 ;;
125 android-linux)
126 os=-linux-android
127 basic_machine=`echo "$1" | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`-unknown
128 ;;
129 *)
130 basic_machine=`echo "$1" | sed 's/-[^-]*$//'`
131 if [ "$basic_machine" != "$1" ]
132 then os=`echo "$1" | sed 's/.*-/-/'`
133 else os=; fi
134 ;;
135 esac
136
137 ### Let's recognize common machines as not being operating systems so
138 ### that things like config.sub decstation-3100 work. We also
139 ### recognize some manufacturers as not being operating systems, so we
140 ### can provide default operating systems below.
141 case $os in
142 -sun*os*)
143 # Prevent following clause from handling this invalid input.
144 ;;
145 -dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \
146 -att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \
147 -unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \
148 -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\
149 -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \
150 -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \
151 -apple | -axis | -knuth | -cray | -microblaze*)
152 os=
153 basic_machine=$1
154 ;;
155 -bluegene*)
156 os=-cnk
157 ;;
158 -sim | -cisco | -oki | -wec | -winbond)
159 os=
160 basic_machine=$1
161 ;;
162 -scout)
163 ;;
164 -wrs)
165 os=-vxworks
166 basic_machine=$1
167 ;;
168 -chorusos*)
169 os=-chorusos
170 basic_machine=$1
171 ;;
172 -chorusrdb)
173 os=-chorusrdb
174 basic_machine=$1
175 ;;
176 -hiux*)
177 os=-hiuxwe2
178 ;;
179 -sco6)
180 os=-sco5v6
181 basic_machine=`echo "$1" | sed -e 's/86-.*/86-pc/'`
182 ;;
183 -sco5)
184 os=-sco3.2v5
185 basic_machine=`echo "$1" | sed -e 's/86-.*/86-pc/'`
186 ;;
187 -sco4)
188 os=-sco3.2v4
189 basic_machine=`echo "$1" | sed -e 's/86-.*/86-pc/'`
190 ;;
191 -sco3.2.[4-9]*)
192 os=`echo $os | sed -e 's/sco3.2./sco3.2v/'`
193 basic_machine=`echo "$1" | sed -e 's/86-.*/86-pc/'`
194 ;;
195 -sco3.2v[4-9]*)
196 # Don't forget version if it is 3.2v4 or newer.
197 basic_machine=`echo "$1" | sed -e 's/86-.*/86-pc/'`
198 ;;
199 -sco5v6*)
200 # Don't forget version if it is 3.2v4 or newer.
201 basic_machine=`echo "$1" | sed -e 's/86-.*/86-pc/'`
202 ;;
203 -sco*)
204 os=-sco3.2v2
205 basic_machine=`echo "$1" | sed -e 's/86-.*/86-pc/'`
206 ;;
207 -udk*)
208 basic_machine=`echo "$1" | sed -e 's/86-.*/86-pc/'`
209 ;;
210 -isc)
211 os=-isc2.2
212 basic_machine=`echo "$1" | sed -e 's/86-.*/86-pc/'`
213 ;;
214 -clix*)
215 basic_machine=clipper-intergraph
216 ;;
217 -isc*)
218 basic_machine=`echo "$1" | sed -e 's/86-.*/86-pc/'`
219 ;;
220 -lynx*178)
221 os=-lynxos178
222 ;;
223 -lynx*5)
224 os=-lynxos5
225 ;;
226 -lynx*)
227 os=-lynxos
228 ;;
229 -ptx*)
230 basic_machine=`echo "$1" | sed -e 's/86-.*/86-sequent/'`
231 ;;
232 -psos*)
233 os=-psos
234 ;;
235 -mint | -mint[0-9]*)
236 basic_machine=m68k-atari
237 os=-mint
238 ;;
239 esac
240
241 # Decode aliases for certain CPU-COMPANY combinations.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
242 case $basic_machine in
243 # Recognize the basic CPU types without company name.
244 # Some are omitted here because they have special meanings below.
245 1750a | 580 \
246 | a29k \
247 | aarch64 | aarch64_be \
248 | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \
249 | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \
250 | am33_2.0 \
251 | arc | arceb \
252 | arm | arm[bl]e | arme[lb] | armv[2-8] | armv[3-8][lb] | armv7[arm] \
253 | avr | avr32 \
254 | ba \
255 | be32 | be64 \
256 | bfin \
257 | c4x | c8051 | clipper \
258 | d10v | d30v | dlx | dsp16xx \
259 | e2k | epiphany \
260 | fido | fr30 | frv | ft32 \
261 | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
262 | hexagon \
263 | i370 | i860 | i960 | ia16 | ia64 \
264 | ip2k | iq2000 \
265 | k1om \
266 | le32 | le64 \
267 | lm32 \
268 | m32c | m32r | m32rle | m68000 | m68k | m88k \
269 | maxq | mb | microblaze | microblazeel | mcore | mep | metag \
270 | mips | mipsbe | mipseb | mipsel | mipsle \
271 | mips16 \
272 | mips64 | mips64el \
273 | mips64octeon | mips64octeonel \
274 | mips64orion | mips64orionel \
275 | mips64r5900 | mips64r5900el \
276 | mips64vr | mips64vrel \
277 | mips64vr4100 | mips64vr4100el \
278 | mips64vr4300 | mips64vr4300el \
279 | mips64vr5000 | mips64vr5000el \
280 | mips64vr5900 | mips64vr5900el \
281 | mipsisa32 | mipsisa32el \
282 | mipsisa32r2 | mipsisa32r2el \
283 | mipsisa32r6 | mipsisa32r6el \
284 | mipsisa64 | mipsisa64el \
285 | mipsisa64r2 | mipsisa64r2el \
286 | mipsisa64r6 | mipsisa64r6el \
287 | mipsisa64sb1 | mipsisa64sb1el \
288 | mipsisa64sr71k | mipsisa64sr71kel \
289 | mipsr5900 | mipsr5900el \
290 | mipstx39 | mipstx39el \
291 | mn10200 | mn10300 \
292 | moxie \
293 | mt \
294 | msp430 \
295 | nds32 | nds32le | nds32be \
296 | nios | nios2 | nios2eb | nios2el \
297 | ns16k | ns32k \
298 | open8 | or1k | or1knd | or32 \
299 | pdp10 | pj | pjl \
300 | powerpc | powerpc64 | powerpc64le | powerpcle \
301 | pru \
302 | pyramid \
303 | riscv32 | riscv64 \
304 | rl78 | rx \
305 | score \
306 | sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[234]eb | sheb | shbe | shle | sh[1234]le | sh3ele \
307 | sh64 | sh64le \
308 | sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \
309 | sparcv8 | sparcv9 | sparcv9b | sparcv9v \
310 | spu \
311 | tahoe | tic4x | tic54x | tic55x | tic6x | tic80 | tron \
312 | ubicom32 \
313 | v850 | v850e | v850e1 | v850e2 | v850es | v850e2v3 \
314 | visium \
315 | wasm32 \
316 | x86 | xc16x | xstormy16 | xtensa \
317 | z8k | z80)
318 basic_machine=$basic_machine-unknown
319 ;;
320 c54x)
321 basic_machine=tic54x-unknown
322 ;;
323 c55x)
324 basic_machine=tic55x-unknown
325 ;;
326 c6x)
327 basic_machine=tic6x-unknown
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
328 ;;
329 leon|leon[3-9])
330 basic_machine=sparc-$basic_machine
331 ;;
332 m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x | nvptx | picochip)
333 basic_machine=$basic_machine-unknown
334 os=-none
335 ;;
336 m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65)
337 ;;
338 ms1)
339 basic_machine=mt-unknown
340 ;;
341
342 strongarm | thumb | xscale)
343 basic_machine=arm-unknown
344 ;;
345 xgate)
346 basic_machine=$basic_machine-unknown
347 os=-none
348 ;;
349 xscaleeb)
350 basic_machine=armeb-unknown
351 ;;
352
353 xscaleel)
354 basic_machine=armel-unknown
355 ;;
356
357 # We use `pc' rather than `unknown'
358 # because (1) that's what they normally are, and
359 # (2) the word "unknown" tends to confuse beginning users.
360 i*86 | x86_64)
361 basic_machine=$basic_machine-pc
362 ;;
363 # Object if more than one company name word.
364 *-*-*)
365 echo Invalid configuration \`"$1"\': machine \`"$basic_machine"\' not recognized 1>&2
366 exit 1
367 ;;
368 # Recognize the basic CPU types with company name.
369 580-* \
370 | a29k-* \
371 | aarch64-* | aarch64_be-* \
372 | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \
373 | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \
374 | alphapca5[67]-* | alpha64pca5[67]-* | arc-* | arceb-* \
375 | arm-* | armbe-* | armle-* | armeb-* | armv*-* \
376 | avr-* | avr32-* \
377 | ba-* \
378 | be32-* | be64-* \
379 | bfin-* | bs2000-* \
380 | c[123]* | c30-* | [cjt]90-* | c4x-* \
381 | c8051-* | clipper-* | craynv-* | cydra-* \
382 | d10v-* | d30v-* | dlx-* \
383 | e2k-* | elxsi-* \
384 | f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \
385 | h8300-* | h8500-* \
386 | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \
387 | hexagon-* \
388 | i*86-* | i860-* | i960-* | ia16-* | ia64-* \
389 | ip2k-* | iq2000-* \
390 | k1om-* \
391 | le32-* | le64-* \
392 | lm32-* \
393 | m32c-* | m32r-* | m32rle-* \
394 | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \
395 | m88110-* | m88k-* | maxq-* | mcore-* | metag-* \
396 | microblaze-* | microblazeel-* \
397 | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \
398 | mips16-* \
399 | mips64-* | mips64el-* \
400 | mips64octeon-* | mips64octeonel-* \
401 | mips64orion-* | mips64orionel-* \
402 | mips64r5900-* | mips64r5900el-* \
403 | mips64vr-* | mips64vrel-* \
404 | mips64vr4100-* | mips64vr4100el-* \
405 | mips64vr4300-* | mips64vr4300el-* \
406 | mips64vr5000-* | mips64vr5000el-* \
407 | mips64vr5900-* | mips64vr5900el-* \
408 | mipsisa32-* | mipsisa32el-* \
409 | mipsisa32r2-* | mipsisa32r2el-* \
410 | mipsisa32r6-* | mipsisa32r6el-* \
411 | mipsisa64-* | mipsisa64el-* \
412 | mipsisa64r2-* | mipsisa64r2el-* \
413 | mipsisa64r6-* | mipsisa64r6el-* \
414 | mipsisa64sb1-* | mipsisa64sb1el-* \
415 | mipsisa64sr71k-* | mipsisa64sr71kel-* \
416 | mipsr5900-* | mipsr5900el-* \
417 | mipstx39-* | mipstx39el-* \
418 | mmix-* \
419 | mt-* \
420 | msp430-* \
421 | nds32-* | nds32le-* | nds32be-* \
422 | nios-* | nios2-* | nios2eb-* | nios2el-* \
423 | none-* | np1-* | ns16k-* | ns32k-* \
424 | open8-* \
425 | or1k*-* \
426 | orion-* \
427 | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \
428 | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* \
429 | pru-* \
430 | pyramid-* \
431 | riscv32-* | riscv64-* \
432 | rl78-* | romp-* | rs6000-* | rx-* \
433 | sh-* | sh[1234]-* | sh[24]a-* | sh[24]aeb-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \
434 | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \
435 | sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \
436 | sparclite-* \
437 | sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | sv1-* | sx*-* \
438 | tahoe-* \
439 | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \
440 | tile*-* \
441 | tron-* \
442 | ubicom32-* \
443 | v850-* | v850e-* | v850e1-* | v850es-* | v850e2-* | v850e2v3-* \
444 | vax-* \
445 | visium-* \
446 | wasm32-* \
447 | we32k-* \
448 | x86-* | x86_64-* | xc16x-* | xps100-* \
449 | xstormy16-* | xtensa*-* \
450 | ymp-* \
451 | z8k-* | z80-*)
452 ;;
453 # Recognize the basic CPU types without company name, with glob match.
454 xtensa*)
455 basic_machine=$basic_machine-unknown
456 ;;
457 # Recognize the various machine names and aliases which stand
458 # for a CPU type and a company and sometimes even an OS.
459 386bsd)
460 basic_machine=i386-pc
461 os=-bsd
462 ;;
463 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc)
464 basic_machine=m68000-att
465 ;;
466 3b*)
467 basic_machine=we32k-att
468 ;;
469 a29khif)
470 basic_machine=a29k-amd
471 os=-udi
472 ;;
473 abacus)
474 basic_machine=abacus-unknown
475 ;;
476 adobe68k)
477 basic_machine=m68010-adobe
478 os=-scout
479 ;;
480 alliant | fx80)
481 basic_machine=fx80-alliant
482 ;;
483 altos | altos3068)
484 basic_machine=m68k-altos
485 ;;
486 am29k)
487 basic_machine=a29k-none
488 os=-bsd
489 ;;
490 amd64)
491 basic_machine=x86_64-pc
492 ;;
493 amd64-*)
494 basic_machine=x86_64-`echo "$basic_machine" | sed 's/^[^-]*-//'`
495 ;;
496 amdahl)
497 basic_machine=580-amdahl
498 os=-sysv
499 ;;
500 amiga | amiga-*)
501 basic_machine=m68k-unknown
502 ;;
503 amigaos | amigados)
504 basic_machine=m68k-unknown
505 os=-amigaos
506 ;;
507 amigaunix | amix)
508 basic_machine=m68k-unknown
509 os=-sysv4
510 ;;
511 apollo68)
512 basic_machine=m68k-apollo
513 os=-sysv
514 ;;
515 apollo68bsd)
516 basic_machine=m68k-apollo
517 os=-bsd
518 ;;
519 aros)
520 basic_machine=i386-pc
521 os=-aros
522 ;;
523 asmjs)
524 basic_machine=asmjs-unknown
525 ;;
526 aux)
527 basic_machine=m68k-apple
528 os=-aux
529 ;;
530 balance)
531 basic_machine=ns32k-sequent
532 os=-dynix
533 ;;
534 blackfin)
535 basic_machine=bfin-unknown
536 os=-linux
537 ;;
538 blackfin-*)
539 basic_machine=bfin-`echo "$basic_machine" | sed 's/^[^-]*-//'`
540 os=-linux
541 ;;
542 bluegene*)
543 basic_machine=powerpc-ibm
544 os=-cnk
545 ;;
546 c54x-*)
547 basic_machine=tic54x-`echo "$basic_machine" | sed 's/^[^-]*-//'`
548 ;;
549 c55x-*)
550 basic_machine=tic55x-`echo "$basic_machine" | sed 's/^[^-]*-//'`
551 ;;
552 c6x-*)
553 basic_machine=tic6x-`echo "$basic_machine" | sed 's/^[^-]*-//'`
554 ;;
555 c90)
556 basic_machine=c90-cray
557 os=-unicos
558 ;;
559 cegcc)
560 basic_machine=arm-unknown
561 os=-cegcc
562 ;;
563 convex-c1)
564 basic_machine=c1-convex
565 os=-bsd
566 ;;
567 convex-c2)
568 basic_machine=c2-convex
569 os=-bsd
570 ;;
571 convex-c32)
572 basic_machine=c32-convex
573 os=-bsd
574 ;;
575 convex-c34)
576 basic_machine=c34-convex
577 os=-bsd
578 ;;
579 convex-c38)
580 basic_machine=c38-convex
581 os=-bsd
582 ;;
583 cray | j90)
584 basic_machine=j90-cray
585 os=-unicos
586 ;;
587 craynv)
588 basic_machine=craynv-cray
589 os=-unicosmp
590 ;;
591 cr16 | cr16-*)
592 basic_machine=cr16-unknown
593 os=-elf
594 ;;
595 crds | unos)
596 basic_machine=m68k-crds
597 ;;
598 crisv32 | crisv32-* | etraxfs*)
599 basic_machine=crisv32-axis
600 ;;
601 cris | cris-* | etrax*)
602 basic_machine=cris-axis
603 ;;
604 crx)
605 basic_machine=crx-unknown
606 os=-elf
607 ;;
608 da30 | da30-*)
609 basic_machine=m68k-da30
610 ;;
611 decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn)
612 basic_machine=mips-dec
613 ;;
614 decsystem10* | dec10*)
615 basic_machine=pdp10-dec
616 os=-tops10
617 ;;
618 decsystem20* | dec20*)
619 basic_machine=pdp10-dec
620 os=-tops20
621 ;;
622 delta | 3300 | motorola-3300 | motorola-delta \
623 | 3300-motorola | delta-motorola)
624 basic_machine=m68k-motorola
625 ;;
626 delta88)
627 basic_machine=m88k-motorola
628 os=-sysv3
629 ;;
630 dicos)
631 basic_machine=i686-pc
632 os=-dicos
633 ;;
634 djgpp)
635 basic_machine=i586-pc
636 os=-msdosdjgpp
637 ;;
638 dpx20 | dpx20-*)
639 basic_machine=rs6000-bull
640 os=-bosx
641 ;;
642 dpx2*)
643 basic_machine=m68k-bull
644 os=-sysv3
645 ;;
646 e500v[12])
647 basic_machine=powerpc-unknown
648 os=$os"spe"
649 ;;
650 e500v[12]-*)
651 basic_machine=powerpc-`echo "$basic_machine" | sed 's/^[^-]*-//'`
652 os=$os"spe"
653 ;;
654 ebmon29k)
655 basic_machine=a29k-amd
656 os=-ebmon
657 ;;
658 elxsi)
659 basic_machine=elxsi-elxsi
660 os=-bsd
661 ;;
662 encore | umax | mmax)
663 basic_machine=ns32k-encore
664 ;;
665 es1800 | OSE68k | ose68k | ose | OSE)
666 basic_machine=m68k-ericsson
667 os=-ose
668 ;;
669 fx2800)
670 basic_machine=i860-alliant
671 ;;
672 genix)
673 basic_machine=ns32k-ns
674 ;;
675 gmicro)
676 basic_machine=tron-gmicro
677 os=-sysv
678 ;;
679 go32)
680 basic_machine=i386-pc
681 os=-go32
682 ;;
683 h3050r* | hiux*)
684 basic_machine=hppa1.1-hitachi
685 os=-hiuxwe2
686 ;;
687 h8300hms)
688 basic_machine=h8300-hitachi
689 os=-hms
690 ;;
691 h8300xray)
692 basic_machine=h8300-hitachi
693 os=-xray
694 ;;
695 h8500hms)
696 basic_machine=h8500-hitachi
697 os=-hms
698 ;;
699 harris)
700 basic_machine=m88k-harris
701 os=-sysv3
702 ;;
703 hp300-*)
704 basic_machine=m68k-hp
705 ;;
706 hp300bsd)
707 basic_machine=m68k-hp
708 os=-bsd
709 ;;
710 hp300hpux)
711 basic_machine=m68k-hp
712 os=-hpux
713 ;;
714 hp3k9[0-9][0-9] | hp9[0-9][0-9])
715 basic_machine=hppa1.0-hp
716 ;;
717 hp9k2[0-9][0-9] | hp9k31[0-9])
718 basic_machine=m68000-hp
719 ;;
720 hp9k3[2-9][0-9])
721 basic_machine=m68k-hp
722 ;;
723 hp9k6[0-9][0-9] | hp6[0-9][0-9])
724 basic_machine=hppa1.0-hp
725 ;;
726 hp9k7[0-79][0-9] | hp7[0-79][0-9])
727 basic_machine=hppa1.1-hp
728 ;;
729 hp9k78[0-9] | hp78[0-9])
730 # FIXME: really hppa2.0-hp
731 basic_machine=hppa1.1-hp
732 ;;
733 hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893)
734 # FIXME: really hppa2.0-hp
735 basic_machine=hppa1.1-hp
736 ;;
737 hp9k8[0-9][13679] | hp8[0-9][13679])
738 basic_machine=hppa1.1-hp
739 ;;
740 hp9k8[0-9][0-9] | hp8[0-9][0-9])
741 basic_machine=hppa1.0-hp
742 ;;
743 hppaosf)
744 basic_machine=hppa1.1-hp
745 os=-osf
746 ;;
747 hppro)
748 basic_machine=hppa1.1-hp
749 os=-proelf
750 ;;
751 i370-ibm* | ibm*)
752 basic_machine=i370-ibm
753 ;;
754 i*86v32)
755 basic_machine=`echo "$1" | sed -e 's/86.*/86-pc/'`
756 os=-sysv32
757 ;;
758 i*86v4*)
759 basic_machine=`echo "$1" | sed -e 's/86.*/86-pc/'`
760 os=-sysv4
761 ;;
762 i*86v)
763 basic_machine=`echo "$1" | sed -e 's/86.*/86-pc/'`
764 os=-sysv
765 ;;
766 i*86sol2)
767 basic_machine=`echo "$1" | sed -e 's/86.*/86-pc/'`
768 os=-solaris2
769 ;;
770 i386mach)
771 basic_machine=i386-mach
772 os=-mach
773 ;;
774 vsta)
775 basic_machine=i386-unknown
776 os=-vsta
777 ;;
778 iris | iris4d)
779 basic_machine=mips-sgi
780 case $os in
781 -irix*)
782 ;;
783 *)
784 os=-irix4
785 ;;
786 esac
787 ;;
788 isi68 | isi)
789 basic_machine=m68k-isi
790 os=-sysv
791 ;;
792 leon-*|leon[3-9]-*)
793 basic_machine=sparc-`echo "$basic_machine" | sed 's/-.*//'`
794 ;;
795 m68knommu)
796 basic_machine=m68k-unknown
797 os=-linux
798 ;;
799 m68knommu-*)
800 basic_machine=m68k-`echo "$basic_machine" | sed 's/^[^-]*-//'`
801 os=-linux
802 ;;
803 magnum | m3230)
804 basic_machine=mips-mips
805 os=-sysv
806 ;;
807 merlin)
808 basic_machine=ns32k-utek
809 os=-sysv
810 ;;
811 microblaze*)
812 basic_machine=microblaze-xilinx
813 ;;
814 mingw64)
815 basic_machine=x86_64-pc
816 os=-mingw64
817 ;;
818 mingw32)
819 basic_machine=i686-pc
820 os=-mingw32
821 ;;
822 mingw32ce)
823 basic_machine=arm-unknown
824 os=-mingw32ce
825 ;;
826 miniframe)
827 basic_machine=m68000-convergent
828 ;;
829 *mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*)
830 basic_machine=m68k-atari
831 os=-mint
832 ;;
833 mips3*-*)
834 basic_machine=`echo "$basic_machine" | sed -e 's/mips3/mips64/'`
835 ;;
836 mips3*)
837 basic_machine=`echo "$basic_machine" | sed -e 's/mips3/mips64/'`-unknown
838 ;;
839 monitor)
840 basic_machine=m68k-rom68k
841 os=-coff
842 ;;
843 morphos)
844 basic_machine=powerpc-unknown
845 os=-morphos
846 ;;
847 moxiebox)
848 basic_machine=moxie-unknown
849 os=-moxiebox
850 ;;
851 msdos)
852 basic_machine=i386-pc
853 os=-msdos
854 ;;
855 ms1-*)
856 basic_machine=`echo "$basic_machine" | sed -e 's/ms1-/mt-/'`
857 ;;
858 msys)
859 basic_machine=i686-pc
860 os=-msys
861 ;;
862 mvs)
863 basic_machine=i370-ibm
864 os=-mvs
865 ;;
866 nacl)
867 basic_machine=le32-unknown
868 os=-nacl
869 ;;
870 ncr3000)
871 basic_machine=i486-ncr
872 os=-sysv4
873 ;;
874 netbsd386)
875 basic_machine=i386-unknown
876 os=-netbsd
877 ;;
878 netwinder)
879 basic_machine=armv4l-rebel
880 os=-linux
881 ;;
882 news | news700 | news800 | news900)
883 basic_machine=m68k-sony
884 os=-newsos
885 ;;
886 news1000)
887 basic_machine=m68030-sony
888 os=-newsos
889 ;;
890 news-3600 | risc-news)
891 basic_machine=mips-sony
892 os=-newsos
893 ;;
894 necv70)
895 basic_machine=v70-nec
896 os=-sysv
897 ;;
898 next | m*-next)
899 basic_machine=m68k-next
900 case $os in
901 -nextstep* )
902 ;;
903 -ns2*)
904 os=-nextstep2
905 ;;
906 *)
907 os=-nextstep3
908 ;;
909 esac
910 ;;
911 nh3000)
912 basic_machine=m68k-harris
913 os=-cxux
914 ;;
915 nh[45]000)
916 basic_machine=m88k-harris
917 os=-cxux
918 ;;
919 nindy960)
920 basic_machine=i960-intel
921 os=-nindy
922 ;;
923 mon960)
924 basic_machine=i960-intel
925 os=-mon960
926 ;;
927 nonstopux)
928 basic_machine=mips-compaq
929 os=-nonstopux
930 ;;
931 np1)
932 basic_machine=np1-gould
933 ;;
934 neo-tandem)
935 basic_machine=neo-tandem
 
936 ;;
937 nse-tandem)
938 basic_machine=nse-tandem
 
939 ;;
940 nsr-tandem)
941 basic_machine=nsr-tandem
 
942 ;;
943 nsv-tandem)
944 basic_machine=nsv-tandem
 
945 ;;
946 nsx-tandem)
947 basic_machine=nsx-tandem
948 ;;
949 op50n-* | op60c-*)
950 basic_machine=hppa1.1-oki
951 os=-proelf
952 ;;
953 openrisc | openrisc-*)
954 basic_machine=or32-unknown
955 ;;
956 os400)
957 basic_machine=powerpc-ibm
958 os=-os400
959 ;;
960 OSE68000 | ose68000)
961 basic_machine=m68000-ericsson
962 os=-ose
963 ;;
964 os68k)
965 basic_machine=m68k-none
966 os=-os68k
967 ;;
968 pa-hitachi)
969 basic_machine=hppa1.1-hitachi
970 os=-hiuxwe2
971 ;;
972 paragon)
973 basic_machine=i860-intel
974 os=-osf
975 ;;
976 parisc)
977 basic_machine=hppa-unknown
978 os=-linux
979 ;;
980 parisc-*)
981 basic_machine=hppa-`echo "$basic_machine" | sed 's/^[^-]*-//'`
982 os=-linux
983 ;;
984 pbd)
985 basic_machine=sparc-tti
986 ;;
987 pbb)
988 basic_machine=m68k-tti
989 ;;
990 pc532 | pc532-*)
991 basic_machine=ns32k-pc532
992 ;;
993 pc98)
994 basic_machine=i386-pc
995 ;;
996 pc98-*)
997 basic_machine=i386-`echo "$basic_machine" | sed 's/^[^-]*-//'`
998 ;;
999 pentium | p5 | k5 | k6 | nexgen | viac3)
1000 basic_machine=i586-pc
1001 ;;
1002 pentiumpro | p6 | 6x86 | athlon | athlon_*)
1003 basic_machine=i686-pc
1004 ;;
1005 pentiumii | pentium2 | pentiumiii | pentium3)
1006 basic_machine=i686-pc
1007 ;;
1008 pentium4)
1009 basic_machine=i786-pc
1010 ;;
1011 pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*)
1012 basic_machine=i586-`echo "$basic_machine" | sed 's/^[^-]*-//'`
1013 ;;
1014 pentiumpro-* | p6-* | 6x86-* | athlon-*)
1015 basic_machine=i686-`echo "$basic_machine" | sed 's/^[^-]*-//'`
1016 ;;
1017 pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*)
1018 basic_machine=i686-`echo "$basic_machine" | sed 's/^[^-]*-//'`
1019 ;;
1020 pentium4-*)
1021 basic_machine=i786-`echo "$basic_machine" | sed 's/^[^-]*-//'`
1022 ;;
1023 pn)
1024 basic_machine=pn-gould
1025 ;;
1026 power) basic_machine=power-ibm
1027 ;;
1028 ppc | ppcbe) basic_machine=powerpc-unknown
1029 ;;
1030 ppc-* | ppcbe-*)
1031 basic_machine=powerpc-`echo "$basic_machine" | sed 's/^[^-]*-//'`
1032 ;;
1033 ppcle | powerpclittle)
1034 basic_machine=powerpcle-unknown
1035 ;;
1036 ppcle-* | powerpclittle-*)
1037 basic_machine=powerpcle-`echo "$basic_machine" | sed 's/^[^-]*-//'`
1038 ;;
1039 ppc64) basic_machine=powerpc64-unknown
1040 ;;
1041 ppc64-*) basic_machine=powerpc64-`echo "$basic_machine" | sed 's/^[^-]*-//'`
1042 ;;
1043 ppc64le | powerpc64little)
1044 basic_machine=powerpc64le-unknown
1045 ;;
1046 ppc64le-* | powerpc64little-*)
1047 basic_machine=powerpc64le-`echo "$basic_machine" | sed 's/^[^-]*-//'`
1048 ;;
1049 ps2)
1050 basic_machine=i386-ibm
1051 ;;
1052 pw32)
1053 basic_machine=i586-unknown
1054 os=-pw32
1055 ;;
1056 rdos | rdos64)
1057 basic_machine=x86_64-pc
1058 os=-rdos
1059 ;;
1060 rdos32)
1061 basic_machine=i386-pc
1062 os=-rdos
1063 ;;
1064 rom68k)
1065 basic_machine=m68k-rom68k
1066 os=-coff
1067 ;;
1068 rm[46]00)
1069 basic_machine=mips-siemens
1070 ;;
1071 rtpc | rtpc-*)
1072 basic_machine=romp-ibm
1073 ;;
1074 s390 | s390-*)
1075 basic_machine=s390-ibm
1076 ;;
1077 s390x | s390x-*)
1078 basic_machine=s390x-ibm
1079 ;;
1080 sa29200)
1081 basic_machine=a29k-amd
1082 os=-udi
1083 ;;
1084 sb1)
1085 basic_machine=mipsisa64sb1-unknown
1086 ;;
1087 sb1el)
1088 basic_machine=mipsisa64sb1el-unknown
1089 ;;
1090 sde)
1091 basic_machine=mipsisa32-sde
1092 os=-elf
1093 ;;
1094 sei)
1095 basic_machine=mips-sei
1096 os=-seiux
1097 ;;
1098 sequent)
1099 basic_machine=i386-sequent
1100 ;;
1101 sh5el)
1102 basic_machine=sh5le-unknown
1103 ;;
1104 simso-wrs)
1105 basic_machine=sparclite-wrs
1106 os=-vxworks
1107 ;;
1108 sps7)
1109 basic_machine=m68k-bull
1110 os=-sysv2
1111 ;;
1112 spur)
1113 basic_machine=spur-unknown
1114 ;;
1115 st2000)
1116 basic_machine=m68k-tandem
1117 ;;
1118 stratus)
1119 basic_machine=i860-stratus
1120 os=-sysv4
1121 ;;
1122 strongarm-* | thumb-*)
1123 basic_machine=arm-`echo "$basic_machine" | sed 's/^[^-]*-//'`
1124 ;;
1125 sun2)
1126 basic_machine=m68000-sun
1127 ;;
1128 sun2os3)
1129 basic_machine=m68000-sun
1130 os=-sunos3
1131 ;;
1132 sun2os4)
1133 basic_machine=m68000-sun
1134 os=-sunos4
1135 ;;
1136 sun3os3)
1137 basic_machine=m68k-sun
1138 os=-sunos3
1139 ;;
1140 sun3os4)
1141 basic_machine=m68k-sun
1142 os=-sunos4
1143 ;;
1144 sun4os3)
1145 basic_machine=sparc-sun
1146 os=-sunos3
1147 ;;
1148 sun4os4)
1149 basic_machine=sparc-sun
1150 os=-sunos4
1151 ;;
1152 sun4sol2)
1153 basic_machine=sparc-sun
1154 os=-solaris2
1155 ;;
1156 sun3 | sun3-*)
1157 basic_machine=m68k-sun
1158 ;;
1159 sun4)
1160 basic_machine=sparc-sun
1161 ;;
1162 sun386 | sun386i | roadrunner)
1163 basic_machine=i386-sun
1164 ;;
1165 sv1)
1166 basic_machine=sv1-cray
1167 os=-unicos
1168 ;;
1169 symmetry)
1170 basic_machine=i386-sequent
1171 os=-dynix
1172 ;;
1173 t3e)
1174 basic_machine=alphaev5-cray
1175 os=-unicos
1176 ;;
1177 t90)
1178 basic_machine=t90-cray
1179 os=-unicos
1180 ;;
1181 tile*)
1182 basic_machine=$basic_machine-unknown
1183 os=-linux-gnu
1184 ;;
1185 tx39)
1186 basic_machine=mipstx39-unknown
1187 ;;
1188 tx39el)
1189 basic_machine=mipstx39el-unknown
1190 ;;
1191 toad1)
1192 basic_machine=pdp10-xkl
1193 os=-tops20
1194 ;;
1195 tower | tower-32)
1196 basic_machine=m68k-ncr
1197 ;;
1198 tpf)
1199 basic_machine=s390x-ibm
1200 os=-tpf
1201 ;;
1202 udi29k)
1203 basic_machine=a29k-amd
1204 os=-udi
1205 ;;
1206 ultra3)
1207 basic_machine=a29k-nyu
1208 os=-sym1
1209 ;;
1210 v810 | necv810)
1211 basic_machine=v810-nec
1212 os=-none
1213 ;;
1214 vaxv)
1215 basic_machine=vax-dec
1216 os=-sysv
1217 ;;
1218 vms)
1219 basic_machine=vax-dec
1220 os=-vms
1221 ;;
1222 vpp*|vx|vx-*)
1223 basic_machine=f301-fujitsu
1224 ;;
1225 vxworks960)
1226 basic_machine=i960-wrs
1227 os=-vxworks
1228 ;;
1229 vxworks68)
1230 basic_machine=m68k-wrs
1231 os=-vxworks
1232 ;;
1233 vxworks29k)
1234 basic_machine=a29k-wrs
1235 os=-vxworks
1236 ;;
1237 w65*)
1238 basic_machine=w65-wdc
1239 os=-none
1240 ;;
1241 w89k-*)
1242 basic_machine=hppa1.1-winbond
1243 os=-proelf
1244 ;;
1245 x64)
1246 basic_machine=x86_64-pc
1247 ;;
1248 xbox)
1249 basic_machine=i686-pc
1250 os=-mingw32
1251 ;;
1252 xps | xps100)
1253 basic_machine=xps100-honeywell
1254 ;;
1255 xscale-* | xscalee[bl]-*)
1256 basic_machine=`echo "$basic_machine" | sed 's/^xscale/arm/'`
1257 ;;
1258 ymp)
1259 basic_machine=ymp-cray
1260 os=-unicos
1261 ;;
1262 none)
1263 basic_machine=none-none
1264 os=-none
1265 ;;
1266
1267 # Here we handle the default manufacturer of certain CPU types. It is in
1268 # some cases the only manufacturer, in others, it is the most popular.
1269 w89k)
1270 basic_machine=hppa1.1-winbond
1271 ;;
1272 op50n)
1273 basic_machine=hppa1.1-oki
1274 ;;
1275 op60c)
1276 basic_machine=hppa1.1-oki
1277 ;;
1278 romp)
1279 basic_machine=romp-ibm
1280 ;;
1281 mmix)
1282 basic_machine=mmix-knuth
1283 ;;
1284 rs6000)
1285 basic_machine=rs6000-ibm
1286 ;;
1287 vax)
1288 basic_machine=vax-dec
1289 ;;
1290 pdp11)
1291 basic_machine=pdp11-dec
1292 ;;
1293 we32k)
1294 basic_machine=we32k-att
1295 ;;
1296 sh[1234] | sh[24]a | sh[24]aeb | sh[34]eb | sh[1234]le | sh[23]ele)
1297 basic_machine=sh-unknown
1298 ;;
1299 cydra)
1300 basic_machine=cydra-cydrome
1301 ;;
1302 orion)
1303 basic_machine=orion-highlevel
1304 ;;
1305 orion105)
1306 basic_machine=clipper-highlevel
1307 ;;
1308 mac | mpw | mac-mpw)
1309 basic_machine=m68k-apple
1310 ;;
1311 pmac | pmac-mpw)
1312 basic_machine=powerpc-apple
1313 ;;
1314 *-unknown)
1315 # Make sure to match an already-canonicalized machine name.
1316 ;;
1317 *)
1318 echo Invalid configuration \`"$1"\': machine \`"$basic_machine"\' not recognized 1>&2
1319 exit 1
1320 ;;
1321 esac
1322
1323 # Here we canonicalize certain aliases for manufacturers.
1324 case $basic_machine in
1325 *-digital*)
1326 basic_machine=`echo "$basic_machine" | sed 's/digital.*/dec/'`
1327 ;;
1328 *-commodore*)
1329 basic_machine=`echo "$basic_machine" | sed 's/commodore.*/cbm/'`
1330 ;;
1331 *)
1332 ;;
1333 esac
1334
1335 # Decode manufacturer-specific aliases for certain operating systems.
1336
1337 if [ x"$os" != x"" ]
1338 then
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1339 case $os in
1340 # First match some system type aliases that might get confused
1341 # with valid system types.
1342 # -solaris* is a basic system type, with this one exception.
1343 -auroraux)
1344 os=-auroraux
1345 ;;
1346 -solaris1 | -solaris1.*)
1347 os=`echo $os | sed -e 's|solaris1|sunos4|'`
1348 ;;
1349 -solaris)
1350 os=-solaris2
1351 ;;
1352 -unixware*)
1353 os=-sysv4.2uw
1354 ;;
1355 -gnu/linux*)
1356 os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'`
1357 ;;
1358 # es1800 is here to avoid being matched by es* (a different OS)
1359 -es1800*)
1360 os=-ose
1361 ;;
1362 # Now accept the basic system types.
1363 # The portable systems comes first.
1364 # Each alternative MUST end in a * to match a version number.
1365 # -sysv* is not here because it comes later, after sysvr4.
1366 -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \
1367 | -*vms* | -sco* | -esix* | -isc* | -aix* | -cnk* | -sunos | -sunos[34]*\
1368 | -hpux* | -unos* | -osf* | -luna* | -dgux* | -auroraux* | -solaris* \
1369 | -sym* | -kopensolaris* | -plan9* \
1370 | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
1371 | -aos* | -aros* | -cloudabi* | -sortix* \
1372 | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
1373 | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
1374 | -hiux* | -knetbsd* | -mirbsd* | -netbsd* \
1375 | -bitrig* | -openbsd* | -solidbsd* | -libertybsd* \
1376 | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \
1377 | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \
1378 | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
1379 | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* | -hcos* \
1380 | -chorusos* | -chorusrdb* | -cegcc* | -glidix* \
1381 | -cygwin* | -msys* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
1382 | -midipix* | -mingw32* | -mingw64* | -linux-gnu* | -linux-android* \
1383 | -linux-newlib* | -linux-musl* | -linux-uclibc* \
1384 | -uxpv* | -beos* | -mpeix* | -udk* | -moxiebox* \
1385 | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* \
1386 | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
1387 | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \
1388 | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \
1389 | -morphos* | -superux* | -rtmk* | -windiss* \
1390 | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \
1391 | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es* \
1392 | -onefs* | -tirtos* | -phoenix* | -fuchsia* | -redox* | -bme* \
1393 | -midnightbsd*)
1394 # Remember, each alternative MUST END IN *, to match a version number.
1395 ;;
1396 -qnx*)
1397 case $basic_machine in
1398 x86-* | i*86-*)
1399 ;;
1400 *)
1401 os=-nto$os
1402 ;;
1403 esac
1404 ;;
1405 -nto-qnx*)
1406 ;;
1407 -nto*)
1408 os=`echo $os | sed -e 's|nto|nto-qnx|'`
1409 ;;
1410 -sim | -xray | -os68k* | -v88r* \
1411 | -windows* | -osx | -abug | -netware* | -os9* \
1412 | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*)
1413 ;;
1414 -mac*)
1415 os=`echo "$os" | sed -e 's|mac|macos|'`
1416 ;;
1417 -linux-dietlibc)
1418 os=-linux-dietlibc
1419 ;;
1420 -linux*)
1421 os=`echo $os | sed -e 's|linux|linux-gnu|'`
1422 ;;
1423 -sunos5*)
1424 os=`echo "$os" | sed -e 's|sunos5|solaris2|'`
1425 ;;
1426 -sunos6*)
1427 os=`echo "$os" | sed -e 's|sunos6|solaris3|'`
1428 ;;
1429 -opened*)
1430 os=-openedition
1431 ;;
1432 -os400*)
1433 os=-os400
1434 ;;
1435 -wince*)
1436 os=-wince
1437 ;;
1438 -utek*)
1439 os=-bsd
1440 ;;
1441 -dynix*)
1442 os=-bsd
1443 ;;
1444 -acis*)
1445 os=-aos
1446 ;;
1447 -atheos*)
1448 os=-atheos
1449 ;;
1450 -syllable*)
1451 os=-syllable
1452 ;;
1453 -386bsd)
1454 os=-bsd
1455 ;;
1456 -ctix* | -uts*)
1457 os=-sysv
1458 ;;
1459 -nova*)
1460 os=-rtmk-nova
1461 ;;
1462 -ns2)
1463 os=-nextstep2
1464 ;;
1465 -nsk*)
1466 os=-nsk
1467 ;;
1468 # Preserve the version number of sinix5.
1469 -sinix5.*)
1470 os=`echo $os | sed -e 's|sinix|sysv|'`
1471 ;;
1472 -sinix*)
1473 os=-sysv4
1474 ;;
1475 -tpf*)
1476 os=-tpf
1477 ;;
1478 -triton*)
1479 os=-sysv3
1480 ;;
1481 -oss*)
1482 os=-sysv3
1483 ;;
1484 -svr4*)
1485 os=-sysv4
1486 ;;
1487 -svr3)
1488 os=-sysv3
1489 ;;
1490 -sysvr4)
1491 os=-sysv4
1492 ;;
1493 # This must come after -sysvr4.
1494 -sysv*)
1495 ;;
1496 -ose*)
1497 os=-ose
1498 ;;
1499 -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
1500 os=-mint
1501 ;;
1502 -zvmoe)
1503 os=-zvmoe
1504 ;;
1505 -dicos*)
1506 os=-dicos
1507 ;;
1508 -pikeos*)
1509 # Until real need of OS specific support for
1510 # particular features comes up, bare metal
1511 # configurations are quite functional.
1512 case $basic_machine in
1513 arm*)
1514 os=-eabi
1515 ;;
1516 *)
1517 os=-elf
1518 ;;
1519 esac
1520 ;;
1521 -nacl*)
1522 ;;
1523 -ios)
1524 ;;
1525 -none)
1526 ;;
1527 *)
1528 # Get rid of the `-' at the beginning of $os.
1529 os=`echo $os | sed 's/[^-]*-//'`
1530 echo Invalid configuration \`"$1"\': system \`"$os"\' not recognized 1>&2
1531 exit 1
1532 ;;
1533 esac
1534 else
1535
1536 # Here we handle the default operating systems that come with various machines.
1537 # The value should be what the vendor currently ships out the door with their
1538 # machine or put another way, the most popular os provided with the machine.
@@ -1541,261 +1510,364 @@
1541 # "-sun"), then you have to tell the case statement up towards the top
1542 # that MANUFACTURER isn't an operating system. Otherwise, code above
1543 # will signal an error saying that MANUFACTURER isn't an operating
1544 # system, and we'll never get to this point.
1545
1546 case $basic_machine in
 
1547 score-*)
1548 os=-elf
1549 ;;
1550 spu-*)
1551 os=-elf
1552 ;;
1553 *-acorn)
1554 os=-riscix1.2
1555 ;;
1556 arm*-rebel)
1557 os=-linux
 
1558 ;;
1559 arm*-semi)
1560 os=-aout
1561 ;;
1562 c4x-* | tic4x-*)
1563 os=-coff
1564 ;;
1565 c8051-*)
1566 os=-elf
 
 
 
1567 ;;
1568 hexagon-*)
1569 os=-elf
1570 ;;
1571 tic54x-*)
1572 os=-coff
1573 ;;
1574 tic55x-*)
1575 os=-coff
1576 ;;
1577 tic6x-*)
1578 os=-coff
1579 ;;
1580 # This must come before the *-dec entry.
1581 pdp10-*)
1582 os=-tops20
1583 ;;
1584 pdp11-*)
1585 os=-none
1586 ;;
1587 *-dec | vax-*)
1588 os=-ultrix4.2
1589 ;;
1590 m68*-apollo)
1591 os=-domain
1592 ;;
1593 i386-sun)
1594 os=-sunos4.0.2
1595 ;;
1596 m68000-sun)
1597 os=-sunos3
1598 ;;
1599 m68*-cisco)
1600 os=-aout
1601 ;;
1602 mep-*)
1603 os=-elf
1604 ;;
1605 mips*-cisco)
1606 os=-elf
1607 ;;
1608 mips*-*)
1609 os=-elf
1610 ;;
1611 or32-*)
1612 os=-coff
1613 ;;
1614 *-tti) # must be before sparc entry or we get the wrong os.
1615 os=-sysv3
1616 ;;
1617 sparc-* | *-sun)
1618 os=-sunos4.1.1
1619 ;;
1620 pru-*)
1621 os=-elf
1622 ;;
1623 *-be)
1624 os=-beos
1625 ;;
1626 *-ibm)
1627 os=-aix
1628 ;;
1629 *-knuth)
1630 os=-mmixware
1631 ;;
1632 *-wec)
1633 os=-proelf
1634 ;;
1635 *-winbond)
1636 os=-proelf
1637 ;;
1638 *-oki)
1639 os=-proelf
1640 ;;
1641 *-hp)
1642 os=-hpux
1643 ;;
1644 *-hitachi)
1645 os=-hiux
1646 ;;
1647 i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent)
1648 os=-sysv
1649 ;;
1650 *-cbm)
1651 os=-amigaos
1652 ;;
1653 *-dg)
1654 os=-dgux
1655 ;;
1656 *-dolphin)
1657 os=-sysv3
1658 ;;
1659 m68k-ccur)
1660 os=-rtu
1661 ;;
1662 m88k-omron*)
1663 os=-luna
1664 ;;
1665 *-next)
1666 os=-nextstep
1667 ;;
1668 *-sequent)
1669 os=-ptx
1670 ;;
1671 *-crds)
1672 os=-unos
1673 ;;
1674 *-ns)
1675 os=-genix
1676 ;;
1677 i370-*)
1678 os=-mvs
1679 ;;
1680 *-gould)
1681 os=-sysv
1682 ;;
1683 *-highlevel)
1684 os=-bsd
1685 ;;
1686 *-encore)
1687 os=-bsd
1688 ;;
1689 *-sgi)
1690 os=-irix
1691 ;;
1692 *-siemens)
1693 os=-sysv4
1694 ;;
1695 *-masscomp)
1696 os=-rtu
1697 ;;
1698 f30[01]-fujitsu | f700-fujitsu)
1699 os=-uxpv
1700 ;;
1701 *-rom68k)
1702 os=-coff
1703 ;;
1704 *-*bug)
1705 os=-coff
1706 ;;
1707 *-apple)
1708 os=-macos
1709 ;;
1710 *-atari*)
1711 os=-mint
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1712 ;;
1713 *)
1714 os=-none
 
1715 ;;
1716 esac
1717 fi
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1718
1719 # Here we handle the case where we know the os, and the CPU type, but not the
1720 # manufacturer. We pick the logical manufacturer.
1721 vendor=unknown
1722 case $basic_machine in
1723 *-unknown)
1724 case $os in
1725 -riscix*)
1726 vendor=acorn
1727 ;;
1728 -sunos*)
1729 vendor=sun
1730 ;;
1731 -cnk*|-aix*)
1732 vendor=ibm
1733 ;;
1734 -beos*)
1735 vendor=be
1736 ;;
1737 -hpux*)
1738 vendor=hp
1739 ;;
1740 -mpeix*)
1741 vendor=hp
1742 ;;
1743 -hiux*)
1744 vendor=hitachi
1745 ;;
1746 -unos*)
1747 vendor=crds
1748 ;;
1749 -dgux*)
1750 vendor=dg
1751 ;;
1752 -luna*)
1753 vendor=omron
1754 ;;
1755 -genix*)
1756 vendor=ns
1757 ;;
1758 -mvs* | -opened*)
1759 vendor=ibm
1760 ;;
1761 -os400*)
1762 vendor=ibm
1763 ;;
1764 -ptx*)
1765 vendor=sequent
1766 ;;
1767 -tpf*)
1768 vendor=ibm
1769 ;;
1770 -vxsim* | -vxworks* | -windiss*)
1771 vendor=wrs
1772 ;;
1773 -aux*)
1774 vendor=apple
1775 ;;
1776 -hms*)
1777 vendor=hitachi
1778 ;;
1779 -mpw* | -macos*)
1780 vendor=apple
1781 ;;
1782 -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
1783 vendor=atari
1784 ;;
1785 -vos*)
 
 
 
 
 
 
1786 vendor=stratus
1787 ;;
1788 esac
1789 basic_machine=`echo "$basic_machine" | sed "s/unknown/$vendor/"`
1790 ;;
1791 esac
1792
1793 echo "$basic_machine$os"
1794 exit
1795
1796 # Local variables:
1797 # eval: (add-hook 'before-save-hook 'time-stamp)
1798 # time-stamp-start: "timestamp='"
1799 # time-stamp-format: "%:y-%02m-%02d"
1800 # time-stamp-end: "'"
1801 # End:
1802
--- autosetup/autosetup-config.sub
+++ autosetup/autosetup-config.sub
@@ -1,10 +1,12 @@
1 #! /bin/sh
2 # Configuration validation subroutine script.
3 # Copyright 1992-2021 Free Software Foundation, Inc.
4
5 # shellcheck disable=SC2006,SC2268 # see below for rationale
6
7 timestamp='2021-07-03'
8
9 # This file is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
@@ -31,11 +33,11 @@
33 # Supply the specified configuration type as an argument.
34 # If it is invalid, we print an error message on stderr and exit with code 1.
35 # Otherwise, we print the canonical config type on stdout and succeed.
36
37 # You can get the latest version of this script from:
38 # https://git.savannah.gnu.org/cgit/config.git/plain/config.sub
39
40 # This file is supposed to be the same for all GNU packages
41 # and recognize all the CPU types, system types and aliases
42 # that are meaningful with *any* GNU software.
43 # Each package is responsible for reporting which valid configurations
@@ -47,10 +49,17 @@
49 # machine specification into a single specification in the form:
50 # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM
51 # or in some cases, the newer four-part form:
52 # CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM
53 # It is wrong to echo any other type of specification.
54
55 # The "shellcheck disable" line above the timestamp inhibits complaints
56 # about features and limitations of the classic Bourne shell that were
57 # superseded or lifted in POSIX. However, this script identifies a wide
58 # variety of pre-POSIX systems that do not have POSIX shells at all, and
59 # even some reasonably current systems (Solaris 10 as case-in-point) still
60 # have a pre-POSIX /bin/sh.
61
62 me=`echo "$0" | sed -e 's,.*/,,'`
63
64 usage="\
65 Usage: $0 [OPTION] CPU-MFR-OPSYS or ALIAS
@@ -65,11 +74,11 @@
74 Report bugs and patches to <[email protected]>."
75
76 version="\
77 GNU config.sub ($timestamp)
78
79 Copyright 1992-2021 Free Software Foundation, Inc.
80
81 This is free software; see the source for copying conditions. There is NO
82 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
83
84 help="
@@ -87,11 +96,11 @@
96 -- ) # Stop option processing
97 shift; break ;;
98 - ) # Use stdin as input.
99 break ;;
100 -* )
101 echo "$me: invalid option $1$help" >&2
102 exit 1 ;;
103
104 *local*)
105 # First pass through any local machine types.
106 echo "$1"
@@ -108,1431 +117,1391 @@
117 1) ;;
118 *) echo "$me: too many arguments$help" >&2
119 exit 1;;
120 esac
121
122 # Split fields of configuration type
123 # shellcheck disable=SC2162
124 IFS="-" read field1 field2 field3 field4 <<EOF
125 $1
126 EOF
127
128 # Separate into logical components for further validation
129 case $1 in
130 *-*-*-*-*)
131 echo Invalid configuration \`"$1"\': more than four components >&2
132 exit 1
133 ;;
134 *-*-*-*)
135 basic_machine=$field1-$field2
136 basic_os=$field3-$field4
137 ;;
138 *-*-*)
139 # Ambiguous whether COMPANY is present, or skipped and KERNEL-OS is two
140 # parts
141 maybe_os=$field2-$field3
142 case $maybe_os in
143 nto-qnx* | linux-* | uclinux-uclibc* \
144 | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* \
145 | netbsd*-eabi* | kopensolaris*-gnu* | cloudabi*-eabi* \
146 | storm-chaos* | os2-emx* | rtmk-nova*)
147 basic_machine=$field1
148 basic_os=$maybe_os
149 ;;
150 android-linux)
151 basic_machine=$field1-unknown
152 basic_os=linux-android
153 ;;
154 *)
155 basic_machine=$field1-$field2
156 basic_os=$field3
157 ;;
158 esac
159 ;;
160 *-*)
161 # A lone config we happen to match not fitting any pattern
162 case $field1-$field2 in
163 decstation-3100)
164 basic_machine=mips-dec
165 basic_os=
166 ;;
167 *-*)
168 # Second component is usually, but not always the OS
169 case $field2 in
170 # Prevent following clause from handling this valid os
171 sun*os*)
172 basic_machine=$field1
173 basic_os=$field2
174 ;;
175 # Manufacturers
176 dec* | mips* | sequent* | encore* | pc533* | sgi* | sony* \
177 | att* | 7300* | 3300* | delta* | motorola* | sun[234]* \
178 | unicom* | ibm* | next | hp | isi* | apollo | altos* \
179 | convergent* | ncr* | news | 32* | 3600* | 3100* \
180 | hitachi* | c[123]* | convex* | sun | crds | omron* | dg \
181 | ultra | tti* | harris | dolphin | highlevel | gould \
182 | cbm | ns | masscomp | apple | axis | knuth | cray \
183 | microblaze* | sim | cisco \
184 | oki | wec | wrs | winbond)
185 basic_machine=$field1-$field2
186 basic_os=
187 ;;
188 *)
189 basic_machine=$field1
190 basic_os=$field2
191 ;;
192 esac
193 ;;
194 esac
195 ;;
196 *)
197 # Convert single-component short-hands not valid as part of
198 # multi-component configurations.
199 case $field1 in
200 386bsd)
201 basic_machine=i386-pc
202 basic_os=bsd
203 ;;
204 a29khif)
205 basic_machine=a29k-amd
206 basic_os=udi
207 ;;
208 adobe68k)
209 basic_machine=m68010-adobe
210 basic_os=scout
211 ;;
212 alliant)
213 basic_machine=fx80-alliant
214 basic_os=
215 ;;
216 altos | altos3068)
217 basic_machine=m68k-altos
218 basic_os=
219 ;;
220 am29k)
221 basic_machine=a29k-none
222 basic_os=bsd
223 ;;
224 amdahl)
225 basic_machine=580-amdahl
226 basic_os=sysv
227 ;;
228 amiga)
229 basic_machine=m68k-unknown
230 basic_os=
231 ;;
232 amigaos | amigados)
233 basic_machine=m68k-unknown
234 basic_os=amigaos
235 ;;
236 amigaunix | amix)
237 basic_machine=m68k-unknown
238 basic_os=sysv4
239 ;;
240 apollo68)
241 basic_machine=m68k-apollo
242 basic_os=sysv
243 ;;
244 apollo68bsd)
245 basic_machine=m68k-apollo
246 basic_os=bsd
247 ;;
248 aros)
249 basic_machine=i386-pc
250 basic_os=aros
251 ;;
252 aux)
253 basic_machine=m68k-apple
254 basic_os=aux
255 ;;
256 balance)
257 basic_machine=ns32k-sequent
258 basic_os=dynix
259 ;;
260 blackfin)
261 basic_machine=bfin-unknown
262 basic_os=linux
263 ;;
264 cegcc)
265 basic_machine=arm-unknown
266 basic_os=cegcc
267 ;;
268 convex-c1)
269 basic_machine=c1-convex
270 basic_os=bsd
271 ;;
272 convex-c2)
273 basic_machine=c2-convex
274 basic_os=bsd
275 ;;
276 convex-c32)
277 basic_machine=c32-convex
278 basic_os=bsd
279 ;;
280 convex-c34)
281 basic_machine=c34-convex
282 basic_os=bsd
283 ;;
284 convex-c38)
285 basic_machine=c38-convex
286 basic_os=bsd
287 ;;
288 cray)
289 basic_machine=j90-cray
290 basic_os=unicos
291 ;;
292 crds | unos)
293 basic_machine=m68k-crds
294 basic_os=
295 ;;
296 da30)
297 basic_machine=m68k-da30
298 basic_os=
299 ;;
300 decstation | pmax | pmin | dec3100 | decstatn)
301 basic_machine=mips-dec
302 basic_os=
303 ;;
304 delta88)
305 basic_machine=m88k-motorola
306 basic_os=sysv3
307 ;;
308 dicos)
309 basic_machine=i686-pc
310 basic_os=dicos
311 ;;
312 djgpp)
313 basic_machine=i586-pc
314 basic_os=msdosdjgpp
315 ;;
316 ebmon29k)
317 basic_machine=a29k-amd
318 basic_os=ebmon
319 ;;
320 es1800 | OSE68k | ose68k | ose | OSE)
321 basic_machine=m68k-ericsson
322 basic_os=ose
323 ;;
324 gmicro)
325 basic_machine=tron-gmicro
326 basic_os=sysv
327 ;;
328 go32)
329 basic_machine=i386-pc
330 basic_os=go32
331 ;;
332 h8300hms)
333 basic_machine=h8300-hitachi
334 basic_os=hms
335 ;;
336 h8300xray)
337 basic_machine=h8300-hitachi
338 basic_os=xray
339 ;;
340 h8500hms)
341 basic_machine=h8500-hitachi
342 basic_os=hms
343 ;;
344 harris)
345 basic_machine=m88k-harris
346 basic_os=sysv3
347 ;;
348 hp300 | hp300hpux)
349 basic_machine=m68k-hp
350 basic_os=hpux
351 ;;
352 hp300bsd)
353 basic_machine=m68k-hp
354 basic_os=bsd
355 ;;
356 hppaosf)
357 basic_machine=hppa1.1-hp
358 basic_os=osf
359 ;;
360 hppro)
361 basic_machine=hppa1.1-hp
362 basic_os=proelf
363 ;;
364 i386mach)
365 basic_machine=i386-mach
366 basic_os=mach
367 ;;
368 isi68 | isi)
369 basic_machine=m68k-isi
370 basic_os=sysv
371 ;;
372 m68knommu)
373 basic_machine=m68k-unknown
374 basic_os=linux
375 ;;
376 magnum | m3230)
377 basic_machine=mips-mips
378 basic_os=sysv
379 ;;
380 merlin)
381 basic_machine=ns32k-utek
382 basic_os=sysv
383 ;;
384 mingw64)
385 basic_machine=x86_64-pc
386 basic_os=mingw64
387 ;;
388 mingw32)
389 basic_machine=i686-pc
390 basic_os=mingw32
391 ;;
392 mingw32ce)
393 basic_machine=arm-unknown
394 basic_os=mingw32ce
395 ;;
396 monitor)
397 basic_machine=m68k-rom68k
398 basic_os=coff
399 ;;
400 morphos)
401 basic_machine=powerpc-unknown
402 basic_os=morphos
403 ;;
404 moxiebox)
405 basic_machine=moxie-unknown
406 basic_os=moxiebox
407 ;;
408 msdos)
409 basic_machine=i386-pc
410 basic_os=msdos
411 ;;
412 msys)
413 basic_machine=i686-pc
414 basic_os=msys
415 ;;
416 mvs)
417 basic_machine=i370-ibm
418 basic_os=mvs
419 ;;
420 nacl)
421 basic_machine=le32-unknown
422 basic_os=nacl
423 ;;
424 ncr3000)
425 basic_machine=i486-ncr
426 basic_os=sysv4
427 ;;
428 netbsd386)
429 basic_machine=i386-pc
430 basic_os=netbsd
431 ;;
432 netwinder)
433 basic_machine=armv4l-rebel
434 basic_os=linux
435 ;;
436 news | news700 | news800 | news900)
437 basic_machine=m68k-sony
438 basic_os=newsos
439 ;;
440 news1000)
441 basic_machine=m68030-sony
442 basic_os=newsos
443 ;;
444 necv70)
445 basic_machine=v70-nec
446 basic_os=sysv
447 ;;
448 nh3000)
449 basic_machine=m68k-harris
450 basic_os=cxux
451 ;;
452 nh[45]000)
453 basic_machine=m88k-harris
454 basic_os=cxux
455 ;;
456 nindy960)
457 basic_machine=i960-intel
458 basic_os=nindy
459 ;;
460 mon960)
461 basic_machine=i960-intel
462 basic_os=mon960
463 ;;
464 nonstopux)
465 basic_machine=mips-compaq
466 basic_os=nonstopux
467 ;;
468 os400)
469 basic_machine=powerpc-ibm
470 basic_os=os400
471 ;;
472 OSE68000 | ose68000)
473 basic_machine=m68000-ericsson
474 basic_os=ose
475 ;;
476 os68k)
477 basic_machine=m68k-none
478 basic_os=os68k
479 ;;
480 paragon)
481 basic_machine=i860-intel
482 basic_os=osf
483 ;;
484 parisc)
485 basic_machine=hppa-unknown
486 basic_os=linux
487 ;;
488 psp)
489 basic_machine=mipsallegrexel-sony
490 basic_os=psp
491 ;;
492 pw32)
493 basic_machine=i586-unknown
494 basic_os=pw32
495 ;;
496 rdos | rdos64)
497 basic_machine=x86_64-pc
498 basic_os=rdos
499 ;;
500 rdos32)
501 basic_machine=i386-pc
502 basic_os=rdos
503 ;;
504 rom68k)
505 basic_machine=m68k-rom68k
506 basic_os=coff
507 ;;
508 sa29200)
509 basic_machine=a29k-amd
510 basic_os=udi
511 ;;
512 sei)
513 basic_machine=mips-sei
514 basic_os=seiux
515 ;;
516 sequent)
517 basic_machine=i386-sequent
518 basic_os=
519 ;;
520 sps7)
521 basic_machine=m68k-bull
522 basic_os=sysv2
523 ;;
524 st2000)
525 basic_machine=m68k-tandem
526 basic_os=
527 ;;
528 stratus)
529 basic_machine=i860-stratus
530 basic_os=sysv4
531 ;;
532 sun2)
533 basic_machine=m68000-sun
534 basic_os=
535 ;;
536 sun2os3)
537 basic_machine=m68000-sun
538 basic_os=sunos3
539 ;;
540 sun2os4)
541 basic_machine=m68000-sun
542 basic_os=sunos4
543 ;;
544 sun3)
545 basic_machine=m68k-sun
546 basic_os=
547 ;;
548 sun3os3)
549 basic_machine=m68k-sun
550 basic_os=sunos3
551 ;;
552 sun3os4)
553 basic_machine=m68k-sun
554 basic_os=sunos4
555 ;;
556 sun4)
557 basic_machine=sparc-sun
558 basic_os=
559 ;;
560 sun4os3)
561 basic_machine=sparc-sun
562 basic_os=sunos3
563 ;;
564 sun4os4)
565 basic_machine=sparc-sun
566 basic_os=sunos4
567 ;;
568 sun4sol2)
569 basic_machine=sparc-sun
570 basic_os=solaris2
571 ;;
572 sun386 | sun386i | roadrunner)
573 basic_machine=i386-sun
574 basic_os=
575 ;;
576 sv1)
577 basic_machine=sv1-cray
578 basic_os=unicos
579 ;;
580 symmetry)
581 basic_machine=i386-sequent
582 basic_os=dynix
583 ;;
584 t3e)
585 basic_machine=alphaev5-cray
586 basic_os=unicos
587 ;;
588 t90)
589 basic_machine=t90-cray
590 basic_os=unicos
591 ;;
592 toad1)
593 basic_machine=pdp10-xkl
594 basic_os=tops20
595 ;;
596 tpf)
597 basic_machine=s390x-ibm
598 basic_os=tpf
599 ;;
600 udi29k)
601 basic_machine=a29k-amd
602 basic_os=udi
603 ;;
604 ultra3)
605 basic_machine=a29k-nyu
606 basic_os=sym1
607 ;;
608 v810 | necv810)
609 basic_machine=v810-nec
610 basic_os=none
611 ;;
612 vaxv)
613 basic_machine=vax-dec
614 basic_os=sysv
615 ;;
616 vms)
617 basic_machine=vax-dec
618 basic_os=vms
619 ;;
620 vsta)
621 basic_machine=i386-pc
622 basic_os=vsta
623 ;;
624 vxworks960)
625 basic_machine=i960-wrs
626 basic_os=vxworks
627 ;;
628 vxworks68)
629 basic_machine=m68k-wrs
630 basic_os=vxworks
631 ;;
632 vxworks29k)
633 basic_machine=a29k-wrs
634 basic_os=vxworks
635 ;;
636 xbox)
637 basic_machine=i686-pc
638 basic_os=mingw32
639 ;;
640 ymp)
641 basic_machine=ymp-cray
642 basic_os=unicos
643 ;;
644 *)
645 basic_machine=$1
646 basic_os=
647 ;;
648 esac
649 ;;
650 esac
651
652 # Decode 1-component or ad-hoc basic machines
653 case $basic_machine in
654 # Here we handle the default manufacturer of certain CPU types. It is in
655 # some cases the only manufacturer, in others, it is the most popular.
656 w89k)
657 cpu=hppa1.1
658 vendor=winbond
659 ;;
660 op50n)
661 cpu=hppa1.1
662 vendor=oki
663 ;;
664 op60c)
665 cpu=hppa1.1
666 vendor=oki
667 ;;
668 ibm*)
669 cpu=i370
670 vendor=ibm
671 ;;
672 orion105)
673 cpu=clipper
674 vendor=highlevel
675 ;;
676 mac | mpw | mac-mpw)
677 cpu=m68k
678 vendor=apple
679 ;;
680 pmac | pmac-mpw)
681 cpu=powerpc
682 vendor=apple
683 ;;
684
685 # Recognize the various machine names and aliases which stand
686 # for a CPU type and a company and sometimes even an OS.
687 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc)
688 cpu=m68000
689 vendor=att
690 ;;
691 3b*)
692 cpu=we32k
693 vendor=att
694 ;;
695 bluegene*)
696 cpu=powerpc
697 vendor=ibm
698 basic_os=cnk
699 ;;
700 decsystem10* | dec10*)
701 cpu=pdp10
702 vendor=dec
703 basic_os=tops10
704 ;;
705 decsystem20* | dec20*)
706 cpu=pdp10
707 vendor=dec
708 basic_os=tops20
709 ;;
710 delta | 3300 | motorola-3300 | motorola-delta \
711 | 3300-motorola | delta-motorola)
712 cpu=m68k
713 vendor=motorola
714 ;;
715 dpx2*)
716 cpu=m68k
717 vendor=bull
718 basic_os=sysv3
719 ;;
720 encore | umax | mmax)
721 cpu=ns32k
722 vendor=encore
723 ;;
724 elxsi)
725 cpu=elxsi
726 vendor=elxsi
727 basic_os=${basic_os:-bsd}
728 ;;
729 fx2800)
730 cpu=i860
731 vendor=alliant
732 ;;
733 genix)
734 cpu=ns32k
735 vendor=ns
736 ;;
737 h3050r* | hiux*)
738 cpu=hppa1.1
739 vendor=hitachi
740 basic_os=hiuxwe2
741 ;;
742 hp3k9[0-9][0-9] | hp9[0-9][0-9])
743 cpu=hppa1.0
744 vendor=hp
745 ;;
746 hp9k2[0-9][0-9] | hp9k31[0-9])
747 cpu=m68000
748 vendor=hp
749 ;;
750 hp9k3[2-9][0-9])
751 cpu=m68k
752 vendor=hp
753 ;;
754 hp9k6[0-9][0-9] | hp6[0-9][0-9])
755 cpu=hppa1.0
756 vendor=hp
757 ;;
758 hp9k7[0-79][0-9] | hp7[0-79][0-9])
759 cpu=hppa1.1
760 vendor=hp
761 ;;
762 hp9k78[0-9] | hp78[0-9])
763 # FIXME: really hppa2.0-hp
764 cpu=hppa1.1
765 vendor=hp
766 ;;
767 hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893)
768 # FIXME: really hppa2.0-hp
769 cpu=hppa1.1
770 vendor=hp
771 ;;
772 hp9k8[0-9][13679] | hp8[0-9][13679])
773 cpu=hppa1.1
774 vendor=hp
775 ;;
776 hp9k8[0-9][0-9] | hp8[0-9][0-9])
777 cpu=hppa1.0
778 vendor=hp
779 ;;
780 i*86v32)
781 cpu=`echo "$1" | sed -e 's/86.*/86/'`
782 vendor=pc
783 basic_os=sysv32
784 ;;
785 i*86v4*)
786 cpu=`echo "$1" | sed -e 's/86.*/86/'`
787 vendor=pc
788 basic_os=sysv4
789 ;;
790 i*86v)
791 cpu=`echo "$1" | sed -e 's/86.*/86/'`
792 vendor=pc
793 basic_os=sysv
794 ;;
795 i*86sol2)
796 cpu=`echo "$1" | sed -e 's/86.*/86/'`
797 vendor=pc
798 basic_os=solaris2
799 ;;
800 j90 | j90-cray)
801 cpu=j90
802 vendor=cray
803 basic_os=${basic_os:-unicos}
804 ;;
805 iris | iris4d)
806 cpu=mips
807 vendor=sgi
808 case $basic_os in
809 irix*)
810 ;;
811 *)
812 basic_os=irix4
813 ;;
814 esac
815 ;;
816 miniframe)
817 cpu=m68000
818 vendor=convergent
819 ;;
820 *mint | mint[0-9]* | *MiNT | *MiNT[0-9]*)
821 cpu=m68k
822 vendor=atari
823 basic_os=mint
824 ;;
825 news-3600 | risc-news)
826 cpu=mips
827 vendor=sony
828 basic_os=newsos
829 ;;
830 next | m*-next)
831 cpu=m68k
832 vendor=next
833 case $basic_os in
834 openstep*)
835 ;;
836 nextstep*)
837 ;;
838 ns2*)
839 basic_os=nextstep2
840 ;;
841 *)
842 basic_os=nextstep3
843 ;;
844 esac
845 ;;
846 np1)
847 cpu=np1
848 vendor=gould
849 ;;
850 op50n-* | op60c-*)
851 cpu=hppa1.1
852 vendor=oki
853 basic_os=proelf
854 ;;
855 pa-hitachi)
856 cpu=hppa1.1
857 vendor=hitachi
858 basic_os=hiuxwe2
859 ;;
860 pbd)
861 cpu=sparc
862 vendor=tti
863 ;;
864 pbb)
865 cpu=m68k
866 vendor=tti
867 ;;
868 pc532)
869 cpu=ns32k
870 vendor=pc532
871 ;;
872 pn)
873 cpu=pn
874 vendor=gould
875 ;;
876 power)
877 cpu=power
878 vendor=ibm
879 ;;
880 ps2)
881 cpu=i386
882 vendor=ibm
883 ;;
884 rm[46]00)
885 cpu=mips
886 vendor=siemens
887 ;;
888 rtpc | rtpc-*)
889 cpu=romp
890 vendor=ibm
891 ;;
892 sde)
893 cpu=mipsisa32
894 vendor=sde
895 basic_os=${basic_os:-elf}
896 ;;
897 simso-wrs)
898 cpu=sparclite
899 vendor=wrs
900 basic_os=vxworks
901 ;;
902 tower | tower-32)
903 cpu=m68k
904 vendor=ncr
905 ;;
906 vpp*|vx|vx-*)
907 cpu=f301
908 vendor=fujitsu
909 ;;
910 w65)
911 cpu=w65
912 vendor=wdc
913 ;;
914 w89k-*)
915 cpu=hppa1.1
916 vendor=winbond
917 basic_os=proelf
918 ;;
919 none)
920 cpu=none
921 vendor=none
922 ;;
923 leon|leon[3-9])
924 cpu=sparc
925 vendor=$basic_machine
926 ;;
927 leon-*|leon[3-9]-*)
928 cpu=sparc
929 vendor=`echo "$basic_machine" | sed 's/-.*//'`
930 ;;
931
932 *-*)
933 # shellcheck disable=SC2162
934 IFS="-" read cpu vendor <<EOF
935 $basic_machine
936 EOF
937 ;;
 
 
 
 
 
 
 
 
 
 
 
 
 
938 # We use `pc' rather than `unknown'
939 # because (1) that's what they normally are, and
940 # (2) the word "unknown" tends to confuse beginning users.
941 i*86 | x86_64)
942 cpu=$basic_machine
943 vendor=pc
944 ;;
945 # These rules are duplicated from below for sake of the special case above;
946 # i.e. things that normalized to x86 arches should also default to "pc"
947 pc98)
948 cpu=i386
949 vendor=pc
950 ;;
951 x64 | amd64)
952 cpu=x86_64
953 vendor=pc
954 ;;
955 # Recognize the basic CPU types without company name.
956 *)
957 cpu=$basic_machine
958 vendor=unknown
959 ;;
960 esac
961
962 unset -v basic_machine
963
964 # Decode basic machines in the full and proper CPU-Company form.
965 case $cpu-$vendor in
966 # Here we handle the default manufacturer of certain CPU types in canonical form. It is in
967 # some cases the only manufacturer, in others, it is the most popular.
968 craynv-unknown)
969 vendor=cray
970 basic_os=${basic_os:-unicosmp}
971 ;;
972 c90-unknown | c90-cray)
973 vendor=cray
974 basic_os=${Basic_os:-unicos}
975 ;;
976 fx80-unknown)
977 vendor=alliant
978 ;;
979 romp-unknown)
980 vendor=ibm
981 ;;
982 mmix-unknown)
983 vendor=knuth
984 ;;
985 microblaze-unknown | microblazeel-unknown)
986 vendor=xilinx
987 ;;
988 rs6000-unknown)
989 vendor=ibm
990 ;;
991 vax-unknown)
992 vendor=dec
993 ;;
994 pdp11-unknown)
995 vendor=dec
996 ;;
997 we32k-unknown)
998 vendor=att
999 ;;
1000 cydra-unknown)
1001 vendor=cydrome
1002 ;;
1003 i370-ibm*)
1004 vendor=ibm
1005 ;;
1006 orion-unknown)
1007 vendor=highlevel
1008 ;;
1009 xps-unknown | xps100-unknown)
1010 cpu=xps100
1011 vendor=honeywell
1012 ;;
1013
1014 # Here we normalize CPU types with a missing or matching vendor
1015 dpx20-unknown | dpx20-bull)
1016 cpu=rs6000
1017 vendor=bull
1018 basic_os=${basic_os:-bosx}
1019 ;;
1020
1021 # Here we normalize CPU types irrespective of the vendor
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1022 amd64-*)
1023 cpu=x86_64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1024 ;;
1025 blackfin-*)
1026 cpu=bfin
1027 basic_os=linux
 
 
 
 
1028 ;;
1029 c54x-*)
1030 cpu=tic54x
1031 ;;
1032 c55x-*)
1033 cpu=tic55x
1034 ;;
1035 c6x-*)
1036 cpu=tic6x
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1037 ;;
1038 e500v[12]-*)
1039 cpu=powerpc
1040 basic_os=${basic_os}"spe"
1041 ;;
1042 mips3*-*)
1043 cpu=mips64
1044 ;;
1045 ms1-*)
1046 cpu=mt
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1047 ;;
1048 m68knommu-*)
1049 cpu=m68k
1050 basic_os=linux
1051 ;;
1052 m9s12z-* | m68hcs12z-* | hcs12z-* | s12z-*)
1053 cpu=s12z
1054 ;;
1055 openrisc-*)
1056 cpu=or32
1057 ;;
1058 parisc-*)
1059 cpu=hppa
1060 basic_os=linux
1061 ;;
1062 pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*)
1063 cpu=i586
1064 ;;
1065 pentiumpro-* | p6-* | 6x86-* | athlon-* | athalon_*-*)
1066 cpu=i686
1067 ;;
1068 pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*)
1069 cpu=i686
1070 ;;
1071 pentium4-*)
1072 cpu=i786
1073 ;;
1074 pc98-*)
1075 cpu=i386
1076 ;;
1077 ppc-* | ppcbe-*)
1078 cpu=powerpc
1079 ;;
1080 ppcle-* | powerpclittle-*)
1081 cpu=powerpcle
1082 ;;
1083 ppc64-*)
1084 cpu=powerpc64
1085 ;;
1086 ppc64le-* | powerpc64little-*)
1087 cpu=powerpc64le
1088 ;;
1089 sb1-*)
1090 cpu=mipsisa64sb1
1091 ;;
1092 sb1el-*)
1093 cpu=mipsisa64sb1el
1094 ;;
1095 sh5e[lb]-*)
1096 cpu=`echo "$cpu" | sed 's/^\(sh.\)e\(.\)$/\1\2e/'`
1097 ;;
1098 spur-*)
1099 cpu=spur
1100 ;;
1101 strongarm-* | thumb-*)
1102 cpu=arm
1103 ;;
1104 tx39-*)
1105 cpu=mipstx39
1106 ;;
1107 tx39el-*)
1108 cpu=mipstx39el
1109 ;;
1110 x64-*)
1111 cpu=x86_64
1112 ;;
1113 xscale-* | xscalee[bl]-*)
1114 cpu=`echo "$cpu" | sed 's/^xscale/arm/'`
1115 ;;
1116 arm64-*)
1117 cpu=aarch64
1118 ;;
1119
1120 # Recognize the canonical CPU Types that limit and/or modify the
1121 # company names they are paired with.
1122 cr16-*)
1123 basic_os=${basic_os:-elf}
1124 ;;
1125 crisv32-* | etraxfs*-*)
1126 cpu=crisv32
1127 vendor=axis
1128 ;;
1129 cris-* | etrax*-*)
1130 cpu=cris
1131 vendor=axis
1132 ;;
1133 crx-*)
1134 basic_os=${basic_os:-elf}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1135 ;;
1136 neo-tandem)
1137 cpu=neo
1138 vendor=tandem
1139 ;;
1140 nse-tandem)
1141 cpu=nse
1142 vendor=tandem
1143 ;;
1144 nsr-tandem)
1145 cpu=nsr
1146 vendor=tandem
1147 ;;
1148 nsv-tandem)
1149 cpu=nsv
1150 vendor=tandem
1151 ;;
1152 nsx-tandem)
1153 cpu=nsx
1154 vendor=tandem
1155 ;;
1156 mipsallegrexel-sony)
1157 cpu=mipsallegrexel
1158 vendor=sony
1159 ;;
1160 tile*-*)
1161 basic_os=${basic_os:-linux-gnu}
1162 ;;
1163
1164 *)
1165 # Recognize the canonical CPU types that are allowed with any
1166 # company name.
1167 case $cpu in
1168 1750a | 580 \
1169 | a29k \
1170 | aarch64 | aarch64_be \
1171 | abacus \
1172 | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] \
1173 | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] \
1174 | alphapca5[67] | alpha64pca5[67] \
1175 | am33_2.0 \
1176 | amdgcn \
1177 | arc | arceb | arc32 | arc64 \
1178 | arm | arm[lb]e | arme[lb] | armv* \
1179 | avr | avr32 \
1180 | asmjs \
1181 | ba \
1182 | be32 | be64 \
1183 | bfin | bpf | bs2000 \
1184 | c[123]* | c30 | [cjt]90 | c4x \
1185 | c8051 | clipper | craynv | csky | cydra \
1186 | d10v | d30v | dlx | dsp16xx \
1187 | e2k | elxsi | epiphany \
1188 | f30[01] | f700 | fido | fr30 | frv | ft32 | fx80 \
1189 | h8300 | h8500 \
1190 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
1191 | hexagon \
1192 | i370 | i*86 | i860 | i960 | ia16 | ia64 \
1193 | ip2k | iq2000 \
1194 | k1om \
1195 | le32 | le64 \
1196 | lm32 \
1197 | loongarch32 | loongarch64 | loongarchx32 \
1198 | m32c | m32r | m32rle \
1199 | m5200 | m68000 | m680[012346]0 | m68360 | m683?2 | m68k \
1200 | m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x \
1201 | m88110 | m88k | maxq | mb | mcore | mep | metag \
1202 | microblaze | microblazeel \
1203 | mips | mipsbe | mipseb | mipsel | mipsle \
1204 | mips16 \
1205 | mips64 | mips64eb | mips64el \
1206 | mips64octeon | mips64octeonel \
1207 | mips64orion | mips64orionel \
1208 | mips64r5900 | mips64r5900el \
1209 | mips64vr | mips64vrel \
1210 | mips64vr4100 | mips64vr4100el \
1211 | mips64vr4300 | mips64vr4300el \
1212 | mips64vr5000 | mips64vr5000el \
1213 | mips64vr5900 | mips64vr5900el \
1214 | mipsisa32 | mipsisa32el \
1215 | mipsisa32r2 | mipsisa32r2el \
1216 | mipsisa32r3 | mipsisa32r3el \
1217 | mipsisa32r5 | mipsisa32r5el \
1218 | mipsisa32r6 | mipsisa32r6el \
1219 | mipsisa64 | mipsisa64el \
1220 | mipsisa64r2 | mipsisa64r2el \
1221 | mipsisa64r3 | mipsisa64r3el \
1222 | mipsisa64r5 | mipsisa64r5el \
1223 | mipsisa64r6 | mipsisa64r6el \
1224 | mipsisa64sb1 | mipsisa64sb1el \
1225 | mipsisa64sr71k | mipsisa64sr71kel \
1226 | mipsr5900 | mipsr5900el \
1227 | mipstx39 | mipstx39el \
1228 | mmix \
1229 | mn10200 | mn10300 \
1230 | moxie \
1231 | mt \
1232 | msp430 \
1233 | nds32 | nds32le | nds32be \
1234 | nfp \
1235 | nios | nios2 | nios2eb | nios2el \
1236 | none | np1 | ns16k | ns32k | nvptx \
1237 | open8 \
1238 | or1k* \
1239 | or32 \
1240 | orion \
1241 | picochip \
1242 | pdp10 | pdp11 | pj | pjl | pn | power \
1243 | powerpc | powerpc64 | powerpc64le | powerpcle | powerpcspe \
1244 | pru \
1245 | pyramid \
1246 | riscv | riscv32 | riscv32be | riscv64 | riscv64be \
1247 | rl78 | romp | rs6000 | rx \
1248 | s390 | s390x \
1249 | score \
1250 | sh | shl \
1251 | sh[1234] | sh[24]a | sh[24]ae[lb] | sh[23]e | she[lb] | sh[lb]e \
1252 | sh[1234]e[lb] | sh[12345][lb]e | sh[23]ele | sh64 | sh64le \
1253 | sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet \
1254 | sparclite \
1255 | sparcv8 | sparcv9 | sparcv9b | sparcv9v | sv1 | sx* \
1256 | spu \
1257 | tahoe \
1258 | thumbv7* \
1259 | tic30 | tic4x | tic54x | tic55x | tic6x | tic80 \
1260 | tron \
1261 | ubicom32 \
1262 | v70 | v850 | v850e | v850e1 | v850es | v850e2 | v850e2v3 \
1263 | vax \
1264 | visium \
1265 | w65 \
1266 | wasm32 | wasm64 \
1267 | we32k \
1268 | x86 | x86_64 | xc16x | xgate | xps100 \
1269 | xstormy16 | xtensa* \
1270 | ymp \
1271 | z8k | z80)
1272 ;;
1273
1274 *)
1275 echo Invalid configuration \`"$1"\': machine \`"$cpu-$vendor"\' not recognized 1>&2
1276 exit 1
1277 ;;
1278 esac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1279 ;;
1280 esac
1281
1282 # Here we canonicalize certain aliases for manufacturers.
1283 case $vendor in
1284 digital*)
1285 vendor=dec
1286 ;;
1287 commodore*)
1288 vendor=cbm
1289 ;;
1290 *)
1291 ;;
1292 esac
1293
1294 # Decode manufacturer-specific aliases for certain operating systems.
1295
1296 if test x$basic_os != x
1297 then
1298
1299 # First recognize some ad-hoc caes, or perhaps split kernel-os, or else just
1300 # set os.
1301 case $basic_os in
1302 gnu/linux*)
1303 kernel=linux
1304 os=`echo "$basic_os" | sed -e 's|gnu/linux|gnu|'`
1305 ;;
1306 os2-emx)
1307 kernel=os2
1308 os=`echo "$basic_os" | sed -e 's|os2-emx|emx|'`
1309 ;;
1310 nto-qnx*)
1311 kernel=nto
1312 os=`echo "$basic_os" | sed -e 's|nto-qnx|qnx|'`
1313 ;;
1314 *-*)
1315 # shellcheck disable=SC2162
1316 IFS="-" read kernel os <<EOF
1317 $basic_os
1318 EOF
1319 ;;
1320 # Default OS when just kernel was specified
1321 nto*)
1322 kernel=nto
1323 os=`echo "$basic_os" | sed -e 's|nto|qnx|'`
1324 ;;
1325 linux*)
1326 kernel=linux
1327 os=`echo "$basic_os" | sed -e 's|linux|gnu|'`
1328 ;;
1329 *)
1330 kernel=
1331 os=$basic_os
1332 ;;
1333 esac
1334
1335 # Now, normalize the OS (knowing we just have one component, it's not a kernel,
1336 # etc.)
1337 case $os in
1338 # First match some system type aliases that might get confused
1339 # with valid system types.
1340 # solaris* is a basic system type, with this one exception.
1341 auroraux)
1342 os=auroraux
1343 ;;
1344 bluegene*)
1345 os=cnk
1346 ;;
1347 solaris1 | solaris1.*)
1348 os=`echo "$os" | sed -e 's|solaris1|sunos4|'`
1349 ;;
1350 solaris)
1351 os=solaris2
1352 ;;
1353 unixware*)
1354 os=sysv4.2uw
1355 ;;
1356 # es1800 is here to avoid being matched by es* (a different OS)
1357 es1800*)
1358 os=ose
1359 ;;
1360 # Some version numbers need modification
1361 chorusos*)
1362 os=chorusos
1363 ;;
1364 isc)
1365 os=isc2.2
1366 ;;
1367 sco6)
1368 os=sco5v6
1369 ;;
1370 sco5)
1371 os=sco3.2v5
1372 ;;
1373 sco4)
1374 os=sco3.2v4
1375 ;;
1376 sco3.2.[4-9]*)
1377 os=`echo "$os" | sed -e 's/sco3.2./sco3.2v/'`
1378 ;;
1379 sco*v* | scout)
1380 # Don't match below
1381 ;;
1382 sco*)
1383 os=sco3.2v2
1384 ;;
1385 psos*)
1386 os=psos
1387 ;;
1388 qnx*)
1389 os=qnx
1390 ;;
1391 hiux*)
1392 os=hiuxwe2
1393 ;;
1394 lynx*178)
1395 os=lynxos178
1396 ;;
1397 lynx*5)
1398 os=lynxos5
1399 ;;
1400 lynxos*)
1401 # don't get caught up in next wildcard
1402 ;;
1403 lynx*)
1404 os=lynxos
1405 ;;
1406 mac[0-9]*)
 
 
 
 
 
 
1407 os=`echo "$os" | sed -e 's|mac|macos|'`
1408 ;;
1409 opened*)
1410 os=openedition
1411 ;;
1412 os400*)
1413 os=os400
1414 ;;
1415 sunos5*)
1416 os=`echo "$os" | sed -e 's|sunos5|solaris2|'`
1417 ;;
1418 sunos6*)
1419 os=`echo "$os" | sed -e 's|sunos6|solaris3|'`
1420 ;;
1421 wince*)
1422 os=wince
1423 ;;
1424 utek*)
1425 os=bsd
1426 ;;
1427 dynix*)
1428 os=bsd
1429 ;;
1430 acis*)
1431 os=aos
1432 ;;
1433 atheos*)
1434 os=atheos
1435 ;;
1436 syllable*)
1437 os=syllable
1438 ;;
1439 386bsd)
1440 os=bsd
1441 ;;
1442 ctix* | uts*)
1443 os=sysv
1444 ;;
1445 nova*)
1446 os=rtmk-nova
1447 ;;
1448 ns2)
1449 os=nextstep2
 
 
 
 
 
 
 
 
 
1450 ;;
1451 # Preserve the version number of sinix5.
1452 sinix5.*)
1453 os=`echo "$os" | sed -e 's|sinix|sysv|'`
1454 ;;
1455 sinix*)
1456 os=sysv4
1457 ;;
1458 tpf*)
1459 os=tpf
1460 ;;
1461 triton*)
1462 os=sysv3
1463 ;;
1464 oss*)
1465 os=sysv3
1466 ;;
1467 svr4*)
1468 os=sysv4
1469 ;;
1470 svr3)
1471 os=sysv3
1472 ;;
1473 sysvr4)
1474 os=sysv4
1475 ;;
1476 ose*)
1477 os=ose
1478 ;;
1479 *mint | mint[0-9]* | *MiNT | MiNT[0-9]*)
1480 os=mint
1481 ;;
1482 dicos*)
1483 os=dicos
1484 ;;
1485 pikeos*)
 
 
 
 
 
 
1486 # Until real need of OS specific support for
1487 # particular features comes up, bare metal
1488 # configurations are quite functional.
1489 case $cpu in
1490 arm*)
1491 os=eabi
1492 ;;
1493 *)
1494 os=elf
1495 ;;
1496 esac
1497 ;;
1498 *)
1499 # No normalization, but not necessarily accepted, that comes below.
1500 ;;
1501 esac
1502
 
 
 
 
 
 
 
 
1503 else
1504
1505 # Here we handle the default operating systems that come with various machines.
1506 # The value should be what the vendor currently ships out the door with their
1507 # machine or put another way, the most popular os provided with the machine.
@@ -1541,261 +1510,364 @@
1510 # "-sun"), then you have to tell the case statement up towards the top
1511 # that MANUFACTURER isn't an operating system. Otherwise, code above
1512 # will signal an error saying that MANUFACTURER isn't an operating
1513 # system, and we'll never get to this point.
1514
1515 kernel=
1516 case $cpu-$vendor in
1517 score-*)
1518 os=elf
1519 ;;
1520 spu-*)
1521 os=elf
1522 ;;
1523 *-acorn)
1524 os=riscix1.2
1525 ;;
1526 arm*-rebel)
1527 kernel=linux
1528 os=gnu
1529 ;;
1530 arm*-semi)
1531 os=aout
1532 ;;
1533 c4x-* | tic4x-*)
1534 os=coff
1535 ;;
1536 c8051-*)
1537 os=elf
1538 ;;
1539 clipper-intergraph)
1540 os=clix
1541 ;;
1542 hexagon-*)
1543 os=elf
1544 ;;
1545 tic54x-*)
1546 os=coff
1547 ;;
1548 tic55x-*)
1549 os=coff
1550 ;;
1551 tic6x-*)
1552 os=coff
1553 ;;
1554 # This must come before the *-dec entry.
1555 pdp10-*)
1556 os=tops20
1557 ;;
1558 pdp11-*)
1559 os=none
1560 ;;
1561 *-dec | vax-*)
1562 os=ultrix4.2
1563 ;;
1564 m68*-apollo)
1565 os=domain
1566 ;;
1567 i386-sun)
1568 os=sunos4.0.2
1569 ;;
1570 m68000-sun)
1571 os=sunos3
1572 ;;
1573 m68*-cisco)
1574 os=aout
1575 ;;
1576 mep-*)
1577 os=elf
1578 ;;
1579 mips*-cisco)
1580 os=elf
1581 ;;
1582 mips*-*)
1583 os=elf
1584 ;;
1585 or32-*)
1586 os=coff
1587 ;;
1588 *-tti) # must be before sparc entry or we get the wrong os.
1589 os=sysv3
1590 ;;
1591 sparc-* | *-sun)
1592 os=sunos4.1.1
1593 ;;
1594 pru-*)
1595 os=elf
1596 ;;
1597 *-be)
1598 os=beos
1599 ;;
1600 *-ibm)
1601 os=aix
1602 ;;
1603 *-knuth)
1604 os=mmixware
1605 ;;
1606 *-wec)
1607 os=proelf
1608 ;;
1609 *-winbond)
1610 os=proelf
1611 ;;
1612 *-oki)
1613 os=proelf
1614 ;;
1615 *-hp)
1616 os=hpux
1617 ;;
1618 *-hitachi)
1619 os=hiux
1620 ;;
1621 i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent)
1622 os=sysv
1623 ;;
1624 *-cbm)
1625 os=amigaos
1626 ;;
1627 *-dg)
1628 os=dgux
1629 ;;
1630 *-dolphin)
1631 os=sysv3
1632 ;;
1633 m68k-ccur)
1634 os=rtu
1635 ;;
1636 m88k-omron*)
1637 os=luna
1638 ;;
1639 *-next)
1640 os=nextstep
1641 ;;
1642 *-sequent)
1643 os=ptx
1644 ;;
1645 *-crds)
1646 os=unos
1647 ;;
1648 *-ns)
1649 os=genix
1650 ;;
1651 i370-*)
1652 os=mvs
1653 ;;
1654 *-gould)
1655 os=sysv
1656 ;;
1657 *-highlevel)
1658 os=bsd
1659 ;;
1660 *-encore)
1661 os=bsd
1662 ;;
1663 *-sgi)
1664 os=irix
1665 ;;
1666 *-siemens)
1667 os=sysv4
1668 ;;
1669 *-masscomp)
1670 os=rtu
1671 ;;
1672 f30[01]-fujitsu | f700-fujitsu)
1673 os=uxpv
1674 ;;
1675 *-rom68k)
1676 os=coff
1677 ;;
1678 *-*bug)
1679 os=coff
1680 ;;
1681 *-apple)
1682 os=macos
1683 ;;
1684 *-atari*)
1685 os=mint
1686 ;;
1687 *-wrs)
1688 os=vxworks
1689 ;;
1690 *)
1691 os=none
1692 ;;
1693 esac
1694
1695 fi
1696
1697 # Now, validate our (potentially fixed-up) OS.
1698 case $os in
1699 # Sometimes we do "kernel-libc", so those need to count as OSes.
1700 musl* | newlib* | uclibc*)
1701 ;;
1702 # Likewise for "kernel-abi"
1703 eabi* | gnueabi*)
1704 ;;
1705 # VxWorks passes extra cpu info in the 4th filed.
1706 simlinux | simwindows | spe)
1707 ;;
1708 # Now accept the basic system types.
1709 # The portable systems comes first.
1710 # Each alternative MUST end in a * to match a version number.
1711 gnu* | android* | bsd* | mach* | minix* | genix* | ultrix* | irix* \
1712 | *vms* | esix* | aix* | cnk* | sunos | sunos[34]* \
1713 | hpux* | unos* | osf* | luna* | dgux* | auroraux* | solaris* \
1714 | sym* | plan9* | psp* | sim* | xray* | os68k* | v88r* \
1715 | hiux* | abug | nacl* | netware* | windows* \
1716 | os9* | macos* | osx* | ios* \
1717 | mpw* | magic* | mmixware* | mon960* | lnews* \
1718 | amigaos* | amigados* | msdos* | newsos* | unicos* | aof* \
1719 | aos* | aros* | cloudabi* | sortix* | twizzler* \
1720 | nindy* | vxsim* | vxworks* | ebmon* | hms* | mvs* \
1721 | clix* | riscos* | uniplus* | iris* | isc* | rtu* | xenix* \
1722 | mirbsd* | netbsd* | dicos* | openedition* | ose* \
1723 | bitrig* | openbsd* | secbsd* | solidbsd* | libertybsd* | os108* \
1724 | ekkobsd* | freebsd* | riscix* | lynxos* | os400* \
1725 | bosx* | nextstep* | cxux* | aout* | elf* | oabi* \
1726 | ptx* | coff* | ecoff* | winnt* | domain* | vsta* \
1727 | udi* | lites* | ieee* | go32* | aux* | hcos* \
1728 | chorusrdb* | cegcc* | glidix* | serenity* \
1729 | cygwin* | msys* | pe* | moss* | proelf* | rtems* \
1730 | midipix* | mingw32* | mingw64* | mint* \
1731 | uxpv* | beos* | mpeix* | udk* | moxiebox* \
1732 | interix* | uwin* | mks* | rhapsody* | darwin* \
1733 | openstep* | oskit* | conix* | pw32* | nonstopux* \
1734 | storm-chaos* | tops10* | tenex* | tops20* | its* \
1735 | os2* | vos* | palmos* | uclinux* | nucleus* | morphos* \
1736 | scout* | superux* | sysv* | rtmk* | tpf* | windiss* \
1737 | powermax* | dnix* | nx6 | nx7 | sei* | dragonfly* \
1738 | skyos* | haiku* | rdos* | toppers* | drops* | es* \
1739 | onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \
1740 | midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \
1741 | nsk* | powerunix* | genode* | zvmoe* | qnx* | emx*)
1742 ;;
1743 # This one is extra strict with allowed versions
1744 sco3.2v2 | sco3.2v[4-9]* | sco5v6*)
1745 # Don't forget version if it is 3.2v4 or newer.
1746 ;;
1747 none)
1748 ;;
1749 *)
1750 echo Invalid configuration \`"$1"\': OS \`"$os"\' not recognized 1>&2
1751 exit 1
1752 ;;
1753 esac
1754
1755 # As a final step for OS-related things, validate the OS-kernel combination
1756 # (given a valid OS), if there is a kernel.
1757 case $kernel-$os in
1758 linux-gnu* | linux-dietlibc* | linux-android* | linux-newlib* | linux-musl* | linux-uclibc* )
1759 ;;
1760 uclinux-uclibc* )
1761 ;;
1762 -dietlibc* | -newlib* | -musl* | -uclibc* )
1763 # These are just libc implementations, not actual OSes, and thus
1764 # require a kernel.
1765 echo "Invalid configuration \`$1': libc \`$os' needs explicit kernel." 1>&2
1766 exit 1
1767 ;;
1768 kfreebsd*-gnu* | kopensolaris*-gnu*)
1769 ;;
1770 vxworks-simlinux | vxworks-simwindows | vxworks-spe)
1771 ;;
1772 nto-qnx*)
1773 ;;
1774 os2-emx)
1775 ;;
1776 *-eabi* | *-gnueabi*)
1777 ;;
1778 -*)
1779 # Blank kernel with real OS is always fine.
1780 ;;
1781 *-*)
1782 echo "Invalid configuration \`$1': Kernel \`$kernel' not known to work with OS \`$os'." 1>&2
1783 exit 1
1784 ;;
1785 esac
1786
1787 # Here we handle the case where we know the os, and the CPU type, but not the
1788 # manufacturer. We pick the logical manufacturer.
1789 case $vendor in
1790 unknown)
1791 case $cpu-$os in
1792 *-riscix*)
 
1793 vendor=acorn
1794 ;;
1795 *-sunos*)
1796 vendor=sun
1797 ;;
1798 *-cnk* | *-aix*)
1799 vendor=ibm
1800 ;;
1801 *-beos*)
1802 vendor=be
1803 ;;
1804 *-hpux*)
1805 vendor=hp
1806 ;;
1807 *-mpeix*)
1808 vendor=hp
1809 ;;
1810 *-hiux*)
1811 vendor=hitachi
1812 ;;
1813 *-unos*)
1814 vendor=crds
1815 ;;
1816 *-dgux*)
1817 vendor=dg
1818 ;;
1819 *-luna*)
1820 vendor=omron
1821 ;;
1822 *-genix*)
1823 vendor=ns
1824 ;;
1825 *-clix*)
1826 vendor=intergraph
1827 ;;
1828 *-mvs* | *-opened*)
1829 vendor=ibm
1830 ;;
1831 *-os400*)
1832 vendor=ibm
1833 ;;
1834 s390-* | s390x-*)
1835 vendor=ibm
1836 ;;
1837 *-ptx*)
1838 vendor=sequent
1839 ;;
1840 *-tpf*)
1841 vendor=ibm
1842 ;;
1843 *-vxsim* | *-vxworks* | *-windiss*)
1844 vendor=wrs
1845 ;;
1846 *-aux*)
1847 vendor=apple
1848 ;;
1849 *-hms*)
1850 vendor=hitachi
1851 ;;
1852 *-mpw* | *-macos*)
1853 vendor=apple
1854 ;;
1855 *-*mint | *-mint[0-9]* | *-*MiNT | *-MiNT[0-9]*)
1856 vendor=atari
1857 ;;
1858 *-vos*)
1859 vendor=stratus
1860 ;;
1861 esac
 
1862 ;;
1863 esac
1864
1865 echo "$cpu-$vendor-${kernel:+$kernel-}$os"
1866 exit
1867
1868 # Local variables:
1869 # eval: (add-hook 'before-save-hook 'time-stamp)
1870 # time-stamp-start: "timestamp='"
1871 # time-stamp-format: "%:y-%02m-%02d"
1872 # time-stamp-end: "'"
1873 # End:
1874
--- autosetup/autosetup-find-tclsh
+++ autosetup/autosetup-find-tclsh
@@ -1,17 +1,16 @@
11
#!/bin/sh
22
# Looks for a suitable tclsh or jimsh in the PATH
3
-# If not found, builds a bootstrap jimsh from source
4
-# Prefer $autosetup_tclsh if is set in the environment
5
-d=`dirname "$0"`
6
-{ "$d/jimsh0" "$d/autosetup-test-tclsh"; } 2>/dev/null && exit 0
7
-PATH="$PATH:$d"; export PATH
8
-for tclsh in $autosetup_tclsh jimsh tclsh tclsh8.5 tclsh8.6; do
9
- { $tclsh "$d/autosetup-test-tclsh"; } 2>/dev/null && exit 0
3
+# If not found, builds a bootstrap jimsh in current dir from source
4
+# Prefer $autosetup_tclsh if is set in the environment (unless ./jimsh0 works)
5
+# If an argument is given, use that as the test instead of autosetup-test-tclsh
6
+d="`dirname "$0"`"
7
+for tclsh in ./jimsh0 $autosetup_tclsh jimsh tclsh tclsh8.5 tclsh8.6 tclsh8.7; do
8
+ { $tclsh "$d/${1-autosetup-test-tclsh}"; } 2>/dev/null && exit 0
109
done
1110
echo 1>&2 "No installed jimsh or tclsh, building local bootstrap jimsh0"
1211
for cc in ${CC_FOR_BUILD:-cc} gcc; do
13
- { $cc -o "$d/jimsh0" "$d/jimsh0.c"; } >/dev/null 2>&1 || continue
14
- "$d/jimsh0" "$d/autosetup-test-tclsh" && exit 0
12
+ { $cc -o jimsh0 "$d/jimsh0.c"; } 2>/dev/null || continue
13
+ ./jimsh0 "$d/${1-autosetup-test-tclsh}" && exit 0
1514
done
1615
echo 1>&2 "No working C compiler found. Tried ${CC_FOR_BUILD:-cc} and gcc."
1716
echo false
1817
--- autosetup/autosetup-find-tclsh
+++ autosetup/autosetup-find-tclsh
@@ -1,17 +1,16 @@
1 #!/bin/sh
2 # Looks for a suitable tclsh or jimsh in the PATH
3 # If not found, builds a bootstrap jimsh from source
4 # Prefer $autosetup_tclsh if is set in the environment
5 d=`dirname "$0"`
6 { "$d/jimsh0" "$d/autosetup-test-tclsh"; } 2>/dev/null && exit 0
7 PATH="$PATH:$d"; export PATH
8 for tclsh in $autosetup_tclsh jimsh tclsh tclsh8.5 tclsh8.6; do
9 { $tclsh "$d/autosetup-test-tclsh"; } 2>/dev/null && exit 0
10 done
11 echo 1>&2 "No installed jimsh or tclsh, building local bootstrap jimsh0"
12 for cc in ${CC_FOR_BUILD:-cc} gcc; do
13 { $cc -o "$d/jimsh0" "$d/jimsh0.c"; } >/dev/null 2>&1 || continue
14 "$d/jimsh0" "$d/autosetup-test-tclsh" && exit 0
15 done
16 echo 1>&2 "No working C compiler found. Tried ${CC_FOR_BUILD:-cc} and gcc."
17 echo false
18
--- autosetup/autosetup-find-tclsh
+++ autosetup/autosetup-find-tclsh
@@ -1,17 +1,16 @@
1 #!/bin/sh
2 # Looks for a suitable tclsh or jimsh in the PATH
3 # If not found, builds a bootstrap jimsh in current dir from source
4 # Prefer $autosetup_tclsh if is set in the environment (unless ./jimsh0 works)
5 # If an argument is given, use that as the test instead of autosetup-test-tclsh
6 d="`dirname "$0"`"
7 for tclsh in ./jimsh0 $autosetup_tclsh jimsh tclsh tclsh8.5 tclsh8.6 tclsh8.7; do
8 { $tclsh "$d/${1-autosetup-test-tclsh}"; } 2>/dev/null && exit 0
 
9 done
10 echo 1>&2 "No installed jimsh or tclsh, building local bootstrap jimsh0"
11 for cc in ${CC_FOR_BUILD:-cc} gcc; do
12 { $cc -o jimsh0 "$d/jimsh0.c"; } 2>/dev/null || continue
13 ./jimsh0 "$d/${1-autosetup-test-tclsh}" && exit 0
14 done
15 echo 1>&2 "No working C compiler found. Tried ${CC_FOR_BUILD:-cc} and gcc."
16 echo false
17
--- autosetup/cc-db.tcl
+++ autosetup/cc-db.tcl
@@ -6,10 +6,10 @@
66
# The 'cc-db' module provides a knowledge-base of system idiosyncrasies.
77
# In general, this module can always be included.
88
99
use cc
1010
11
-module-options {}
11
+options {}
1212
1313
# openbsd needs sys/types.h to detect some system headers
1414
cc-include-needs sys/socket.h sys/types.h
1515
cc-include-needs netinet/in.h sys/types.h
1616
--- autosetup/cc-db.tcl
+++ autosetup/cc-db.tcl
@@ -6,10 +6,10 @@
6 # The 'cc-db' module provides a knowledge-base of system idiosyncrasies.
7 # In general, this module can always be included.
8
9 use cc
10
11 module-options {}
12
13 # openbsd needs sys/types.h to detect some system headers
14 cc-include-needs sys/socket.h sys/types.h
15 cc-include-needs netinet/in.h sys/types.h
16
--- autosetup/cc-db.tcl
+++ autosetup/cc-db.tcl
@@ -6,10 +6,10 @@
6 # The 'cc-db' module provides a knowledge-base of system idiosyncrasies.
7 # In general, this module can always be included.
8
9 use cc
10
11 options {}
12
13 # openbsd needs sys/types.h to detect some system headers
14 cc-include-needs sys/socket.h sys/types.h
15 cc-include-needs netinet/in.h sys/types.h
16
--- autosetup/cc-lib.tcl
+++ autosetup/cc-lib.tcl
@@ -5,12 +5,10 @@
55
#
66
# Provides a library of common tests on top of the 'cc' module.
77
88
use cc
99
10
-module-options {}
11
-
1210
# @cc-check-lfs
1311
#
1412
# The equivalent of the 'AC_SYS_LARGEFILE' macro.
1513
#
1614
# defines 'HAVE_LFS' if LFS is available,
@@ -78,11 +76,11 @@
7876
7977
# @cc-check-flags flag ?...?
8078
#
8179
# Checks whether the given C/C++ compiler flags can be used. Defines feature
8280
# names prefixed with 'HAVE_CFLAG' and 'HAVE_CXXFLAG' respectively, and
83
-# appends working flags to '-cflags' and 'CFLAGS' or 'CXXFLAGS'.
81
+# appends working flags to '-cflags' and 'AS_CFLAGS' or 'AS_CXXFLAGS'.
8482
proc cc-check-flags {args} {
8583
set result 1
8684
array set opts [cc-get-settings]
8785
switch -exact -- $opts(-lang) {
8886
c++ {
@@ -101,11 +99,11 @@
10199
msg-checking "Checking whether the $lang compiler accepts $flag..."
102100
if {[cctest -cflags $flag]} {
103101
msg-result yes
104102
define-feature $prefix$flag
105103
cc-with [list -cflags [list $flag]]
106
- define-append ${prefix}S $flag
104
+ define-append AS_${prefix}S $flag
107105
} else {
108106
msg-result no
109107
set result 0
110108
}
111109
}
@@ -113,12 +111,12 @@
113111
}
114112
115113
# @cc-check-standards ver ?...?
116114
#
117115
# Checks whether the C/C++ compiler accepts one of the specified '-std=$ver'
118
-# options, and appends the first working one to '-cflags' and 'CFLAGS' or
119
-# 'CXXFLAGS'.
116
+# options, and appends the first working one to '-cflags' and 'AS_CFLAGS' or
117
+# 'AS_CXXFLAGS'.
120118
proc cc-check-standards {args} {
121119
array set opts [cc-get-settings]
122120
foreach std $args {
123121
if {[cc-check-flags -std=$std]} {
124122
return $std
125123
--- autosetup/cc-lib.tcl
+++ autosetup/cc-lib.tcl
@@ -5,12 +5,10 @@
5 #
6 # Provides a library of common tests on top of the 'cc' module.
7
8 use cc
9
10 module-options {}
11
12 # @cc-check-lfs
13 #
14 # The equivalent of the 'AC_SYS_LARGEFILE' macro.
15 #
16 # defines 'HAVE_LFS' if LFS is available,
@@ -78,11 +76,11 @@
78
79 # @cc-check-flags flag ?...?
80 #
81 # Checks whether the given C/C++ compiler flags can be used. Defines feature
82 # names prefixed with 'HAVE_CFLAG' and 'HAVE_CXXFLAG' respectively, and
83 # appends working flags to '-cflags' and 'CFLAGS' or 'CXXFLAGS'.
84 proc cc-check-flags {args} {
85 set result 1
86 array set opts [cc-get-settings]
87 switch -exact -- $opts(-lang) {
88 c++ {
@@ -101,11 +99,11 @@
101 msg-checking "Checking whether the $lang compiler accepts $flag..."
102 if {[cctest -cflags $flag]} {
103 msg-result yes
104 define-feature $prefix$flag
105 cc-with [list -cflags [list $flag]]
106 define-append ${prefix}S $flag
107 } else {
108 msg-result no
109 set result 0
110 }
111 }
@@ -113,12 +111,12 @@
113 }
114
115 # @cc-check-standards ver ?...?
116 #
117 # Checks whether the C/C++ compiler accepts one of the specified '-std=$ver'
118 # options, and appends the first working one to '-cflags' and 'CFLAGS' or
119 # 'CXXFLAGS'.
120 proc cc-check-standards {args} {
121 array set opts [cc-get-settings]
122 foreach std $args {
123 if {[cc-check-flags -std=$std]} {
124 return $std
125
--- autosetup/cc-lib.tcl
+++ autosetup/cc-lib.tcl
@@ -5,12 +5,10 @@
5 #
6 # Provides a library of common tests on top of the 'cc' module.
7
8 use cc
9
 
 
10 # @cc-check-lfs
11 #
12 # The equivalent of the 'AC_SYS_LARGEFILE' macro.
13 #
14 # defines 'HAVE_LFS' if LFS is available,
@@ -78,11 +76,11 @@
76
77 # @cc-check-flags flag ?...?
78 #
79 # Checks whether the given C/C++ compiler flags can be used. Defines feature
80 # names prefixed with 'HAVE_CFLAG' and 'HAVE_CXXFLAG' respectively, and
81 # appends working flags to '-cflags' and 'AS_CFLAGS' or 'AS_CXXFLAGS'.
82 proc cc-check-flags {args} {
83 set result 1
84 array set opts [cc-get-settings]
85 switch -exact -- $opts(-lang) {
86 c++ {
@@ -101,11 +99,11 @@
99 msg-checking "Checking whether the $lang compiler accepts $flag..."
100 if {[cctest -cflags $flag]} {
101 msg-result yes
102 define-feature $prefix$flag
103 cc-with [list -cflags [list $flag]]
104 define-append AS_${prefix}S $flag
105 } else {
106 msg-result no
107 set result 0
108 }
109 }
@@ -113,12 +111,12 @@
111 }
112
113 # @cc-check-standards ver ?...?
114 #
115 # Checks whether the C/C++ compiler accepts one of the specified '-std=$ver'
116 # options, and appends the first working one to '-cflags' and 'AS_CFLAGS' or
117 # 'AS_CXXFLAGS'.
118 proc cc-check-standards {args} {
119 array set opts [cc-get-settings]
120 foreach std $args {
121 if {[cc-check-flags -std=$std]} {
122 return $std
123
--- autosetup/cc-shared.tcl
+++ autosetup/cc-shared.tcl
@@ -18,11 +18,11 @@
1818
## SH_LINKRPATH Format for setting the rpath when linking an executable, %s = path
1919
## SH_LINKFLAGS Flags to use linking an executable which will load shared objects
2020
## LD_LIBRARY_PATH Environment variable which specifies path to shared libraries
2121
## STRIPLIBFLAGS Arguments to strip a dynamic library
2222
23
-module-options {}
23
+options {}
2424
2525
# Defaults: gcc on unix
2626
define SHOBJ_CFLAGS -fPIC
2727
define SHOBJ_LDFLAGS -shared
2828
define SH_CFLAGS -fPIC
2929
--- autosetup/cc-shared.tcl
+++ autosetup/cc-shared.tcl
@@ -18,11 +18,11 @@
18 ## SH_LINKRPATH Format for setting the rpath when linking an executable, %s = path
19 ## SH_LINKFLAGS Flags to use linking an executable which will load shared objects
20 ## LD_LIBRARY_PATH Environment variable which specifies path to shared libraries
21 ## STRIPLIBFLAGS Arguments to strip a dynamic library
22
23 module-options {}
24
25 # Defaults: gcc on unix
26 define SHOBJ_CFLAGS -fPIC
27 define SHOBJ_LDFLAGS -shared
28 define SH_CFLAGS -fPIC
29
--- autosetup/cc-shared.tcl
+++ autosetup/cc-shared.tcl
@@ -18,11 +18,11 @@
18 ## SH_LINKRPATH Format for setting the rpath when linking an executable, %s = path
19 ## SH_LINKFLAGS Flags to use linking an executable which will load shared objects
20 ## LD_LIBRARY_PATH Environment variable which specifies path to shared libraries
21 ## STRIPLIBFLAGS Arguments to strip a dynamic library
22
23 options {}
24
25 # Defaults: gcc on unix
26 define SHOBJ_CFLAGS -fPIC
27 define SHOBJ_LDFLAGS -shared
28 define SH_CFLAGS -fPIC
29
+41 -18
--- autosetup/cc.tcl
+++ autosetup/cc.tcl
@@ -11,27 +11,27 @@
1111
#
1212
## CC - C compiler
1313
## CXX - C++ compiler
1414
## CPP - C preprocessor
1515
## CCACHE - Set to "none" to disable automatic use of ccache
16
+## CPPFLAGS - Additional C preprocessor compiler flags (C and C++), before CFLAGS, CXXFLAGS
1617
## CFLAGS - Additional C compiler flags
1718
## CXXFLAGS - Additional C++ compiler flags
1819
## LDFLAGS - Additional compiler flags during linking
20
+## LINKFLAGS - ?How is this different from LDFLAGS?
1921
## LIBS - Additional libraries to use (for all tests)
2022
## CROSS - Tool prefix for cross compilation
2123
#
2224
# The following variables are defined from the corresponding
2325
# environment variables if set.
2426
#
25
-## CPPFLAGS
26
-## LINKFLAGS
2727
## CC_FOR_BUILD
2828
## LD
2929
3030
use system
3131
32
-module-options {}
32
+options {}
3333
3434
# Checks for the existence of the given function by linking
3535
#
3636
proc cctest_function {function} {
3737
cctest -link 1 -declare "extern void $function\(void);" -code "$function\();"
@@ -262,15 +262,15 @@
262262
#
263263
proc cc-check-tools {args} {
264264
foreach tool $args {
265265
set TOOL [string toupper $tool]
266266
set exe [get-env $TOOL [get-define cross]$tool]
267
- if {[find-executable {*}$exe]} {
267
+ if {[find-executable $exe]} {
268268
define $TOOL $exe
269269
continue
270270
}
271
- if {[find-executable {*}$tool]} {
271
+ if {[find-executable $tool]} {
272272
msg-result "Warning: Failed to find $exe, falling back to $tool which may be incorrect"
273273
define $TOOL $tool
274274
continue
275275
}
276276
user-error "Failed to find $exe"
@@ -416,10 +416,17 @@
416416
## cc-with {-libs -ldl} {
417417
## cctest -libs -lsocket ...
418418
## # libs will be in this order: -lsocket -ldl -lc -lm
419419
## }
420420
## }
421
+#
422
+# If you wish to invoke something like cc-check-flags but not have -cflags updated,
423
+# use the following idiom:
424
+#
425
+## cc-with {} {
426
+## cc-check-flags ...
427
+## }
421428
proc cc-with {settings args} {
422429
if {[llength $args] == 0} {
423430
cc-add-settings $settings
424431
} elseif {[llength $args] > 1} {
425432
autosetup-error "usage: cc-with settings ?script?"
@@ -453,18 +460,26 @@
453460
## -nooutput 1 Treat any compiler output (e.g. a warning) as an error
454461
#
455462
# Unless '-source' or '-sourcefile' is specified, the C program looks like:
456463
#
457464
## #include <firstinclude> /* same for remaining includes in the list */
458
-##
459465
## declare-code /* any code in -declare, verbatim */
460
-##
461466
## int main(void) {
462467
## code /* any code in -code, verbatim */
463468
## return 0;
464469
## }
465470
#
471
+# And the command line looks like:
472
+#
473
+## CC -cflags CFLAGS CPPFLAGS conftest.c -o conftest.o
474
+## CXX -cflags CXXFLAGS CPPFLAGS conftest.cpp -o conftest.o
475
+#
476
+# And if linking:
477
+#
478
+## CC LDFLAGS -cflags CFLAGS conftest.c -o conftest -libs LIBS
479
+## CXX LDFLAGS -cflags CXXFLAGS conftest.c -o conftest -libs LIBS
480
+#
466481
# Any failures are recorded in 'config.log'
467482
#
468483
proc cctest {args} {
469484
set tmp conftest__
470485
@@ -506,31 +521,34 @@
506521
set cmdline {}
507522
lappend cmdline {*}[get-define CCACHE]
508523
switch -exact -- $opts(-lang) {
509524
c++ {
510525
set src conftest__.cpp
511
- lappend cmdline {*}[get-define CXX] {*}[get-define CXXFLAGS]
526
+ lappend cmdline {*}[get-define CXX]
527
+ set cflags [get-define CXXFLAGS]
512528
}
513529
c {
514530
set src conftest__.c
515
- lappend cmdline {*}[get-define CC] {*}[get-define CFLAGS]
531
+ lappend cmdline {*}[get-define CC]
532
+ set cflags [get-define CFLAGS]
516533
}
517534
default {
518535
autosetup-error "cctest called with unknown language: $opts(-lang)"
519536
}
520537
}
521538
522539
if {$opts(-link)} {
523540
lappend cmdline {*}[get-define LDFLAGS]
524541
} else {
542
+ lappend cflags {*}[get-define CPPFLAGS]
525543
set tmp conftest__.o
526544
lappend cmdline -c
527545
}
528
- lappend cmdline {*}$opts(-cflags) {*}[get-define cc-default-debug ""]
529
- lappend cmdline $src -o $tmp {*}$opts(-libs)
546
+ lappend cmdline {*}$opts(-cflags) {*}[get-define cc-default-debug ""] {*}$cflags
547
+ lappend cmdline $src -o $tmp
530548
if {$opts(-link)} {
531
- lappend cmdline {*}[get-define LIBS]
549
+ lappend cmdline {*}$opts(-libs) {*}[get-define LIBS]
532550
}
533551
534552
# At this point we have the complete command line and the
535553
# complete source to be compiled. Get the result from cache if
536554
# we can
@@ -658,11 +676,11 @@
658676
}
659677
return ""
660678
}
661679
662680
# Initialise some values from the environment or commandline or default settings
663
-foreach i {LDFLAGS LIBS CPPFLAGS LINKFLAGS {CFLAGS "-g -O2"}} {
681
+foreach i {LDFLAGS LIBS CPPFLAGS LINKFLAGS CFLAGS} {
664682
lassign $i var default
665683
define $var [get-env $var $default]
666684
}
667685
668686
if {[env-is-set CC]} {
@@ -678,15 +696,15 @@
678696
}
679697
680698
define CPP [get-env CPP "[get-define CC] -E"]
681699
682700
# XXX: Could avoid looking for a C++ compiler until requested
683
-# Note that if CXX isn't found, we just set it to "false". It might not be needed.
701
+# If CXX isn't found, it is set to the empty string.
684702
if {[env-is-set CXX]} {
685703
define CXX [find-an-executable -required [get-env CXX ""]]
686704
} else {
687
- define CXX [find-an-executable [get-define cross]c++ [get-define cross]g++ false]
705
+ define CXX [find-an-executable [get-define cross]c++ [get-define cross]g++]
688706
}
689707
690708
# CXXFLAGS default to CFLAGS if not specified
691709
define CXXFLAGS [get-env CXXFLAGS [get-define CFLAGS]]
692710
@@ -694,29 +712,34 @@
694712
define CC_FOR_BUILD [find-an-executable [get-env CC_FOR_BUILD ""] cc gcc false]
695713
696714
if {[get-define CC] eq ""} {
697715
user-error "Could not find a C compiler. Tried: [join $try ", "]"
698716
}
717
+
718
+# These start empty and never come from the user or environment
719
+define AS_CFLAGS ""
720
+define AS_CPPFLAGS ""
721
+define AS_CXXFLAGS ""
699722
700723
define CCACHE [find-an-executable [get-env CCACHE ccache]]
701724
702725
# If any of these are set in the environment, propagate them to the AUTOREMAKE commandline
703726
foreach i {CC CXX CCACHE CPP CFLAGS CXXFLAGS CXXFLAGS LDFLAGS LIBS CROSS CPPFLAGS LINKFLAGS CC_FOR_BUILD LD} {
704727
if {[env-is-set $i]} {
705728
# Note: If the variable is set on the command line, get-env will return that value
706729
# so the command line will continue to override the environment
707
- define-append AUTOREMAKE [quote-if-needed $i=[get-env $i ""]]
730
+ define-append-argv AUTOREMAKE $i=[get-env $i ""]
708731
}
709732
}
710733
711734
# Initial cctest settings
712735
cc-store-settings {-cflags {} -includes {} -declare {} -link 0 -lang c -libs {} -code {} -nooutput 0}
713736
set autosetup(cc-include-deps) {}
714737
715
-msg-result "C compiler...[get-define CCACHE] [get-define CC] [get-define CFLAGS]"
738
+msg-result "C compiler...[get-define CCACHE] [get-define CC] [get-define CFLAGS] [get-define CPPFLAGS]"
716739
if {[get-define CXX] ne "false"} {
717
- msg-result "C++ compiler...[get-define CCACHE] [get-define CXX] [get-define CXXFLAGS]"
740
+ msg-result "C++ compiler...[get-define CCACHE] [get-define CXX] [get-define CXXFLAGS] [get-define CPPFLAGS]"
718741
}
719742
msg-result "Build C compiler...[get-define CC_FOR_BUILD]"
720743
721744
# On Darwin, we prefer to use -g0 to avoid creating .dSYM directories
722745
# but some compilers may not support it, so test here.
723746
--- autosetup/cc.tcl
+++ autosetup/cc.tcl
@@ -11,27 +11,27 @@
11 #
12 ## CC - C compiler
13 ## CXX - C++ compiler
14 ## CPP - C preprocessor
15 ## CCACHE - Set to "none" to disable automatic use of ccache
 
16 ## CFLAGS - Additional C compiler flags
17 ## CXXFLAGS - Additional C++ compiler flags
18 ## LDFLAGS - Additional compiler flags during linking
 
19 ## LIBS - Additional libraries to use (for all tests)
20 ## CROSS - Tool prefix for cross compilation
21 #
22 # The following variables are defined from the corresponding
23 # environment variables if set.
24 #
25 ## CPPFLAGS
26 ## LINKFLAGS
27 ## CC_FOR_BUILD
28 ## LD
29
30 use system
31
32 module-options {}
33
34 # Checks for the existence of the given function by linking
35 #
36 proc cctest_function {function} {
37 cctest -link 1 -declare "extern void $function\(void);" -code "$function\();"
@@ -262,15 +262,15 @@
262 #
263 proc cc-check-tools {args} {
264 foreach tool $args {
265 set TOOL [string toupper $tool]
266 set exe [get-env $TOOL [get-define cross]$tool]
267 if {[find-executable {*}$exe]} {
268 define $TOOL $exe
269 continue
270 }
271 if {[find-executable {*}$tool]} {
272 msg-result "Warning: Failed to find $exe, falling back to $tool which may be incorrect"
273 define $TOOL $tool
274 continue
275 }
276 user-error "Failed to find $exe"
@@ -416,10 +416,17 @@
416 ## cc-with {-libs -ldl} {
417 ## cctest -libs -lsocket ...
418 ## # libs will be in this order: -lsocket -ldl -lc -lm
419 ## }
420 ## }
 
 
 
 
 
 
 
421 proc cc-with {settings args} {
422 if {[llength $args] == 0} {
423 cc-add-settings $settings
424 } elseif {[llength $args] > 1} {
425 autosetup-error "usage: cc-with settings ?script?"
@@ -453,18 +460,26 @@
453 ## -nooutput 1 Treat any compiler output (e.g. a warning) as an error
454 #
455 # Unless '-source' or '-sourcefile' is specified, the C program looks like:
456 #
457 ## #include <firstinclude> /* same for remaining includes in the list */
458 ##
459 ## declare-code /* any code in -declare, verbatim */
460 ##
461 ## int main(void) {
462 ## code /* any code in -code, verbatim */
463 ## return 0;
464 ## }
465 #
 
 
 
 
 
 
 
 
 
 
466 # Any failures are recorded in 'config.log'
467 #
468 proc cctest {args} {
469 set tmp conftest__
470
@@ -506,31 +521,34 @@
506 set cmdline {}
507 lappend cmdline {*}[get-define CCACHE]
508 switch -exact -- $opts(-lang) {
509 c++ {
510 set src conftest__.cpp
511 lappend cmdline {*}[get-define CXX] {*}[get-define CXXFLAGS]
 
512 }
513 c {
514 set src conftest__.c
515 lappend cmdline {*}[get-define CC] {*}[get-define CFLAGS]
 
516 }
517 default {
518 autosetup-error "cctest called with unknown language: $opts(-lang)"
519 }
520 }
521
522 if {$opts(-link)} {
523 lappend cmdline {*}[get-define LDFLAGS]
524 } else {
 
525 set tmp conftest__.o
526 lappend cmdline -c
527 }
528 lappend cmdline {*}$opts(-cflags) {*}[get-define cc-default-debug ""]
529 lappend cmdline $src -o $tmp {*}$opts(-libs)
530 if {$opts(-link)} {
531 lappend cmdline {*}[get-define LIBS]
532 }
533
534 # At this point we have the complete command line and the
535 # complete source to be compiled. Get the result from cache if
536 # we can
@@ -658,11 +676,11 @@
658 }
659 return ""
660 }
661
662 # Initialise some values from the environment or commandline or default settings
663 foreach i {LDFLAGS LIBS CPPFLAGS LINKFLAGS {CFLAGS "-g -O2"}} {
664 lassign $i var default
665 define $var [get-env $var $default]
666 }
667
668 if {[env-is-set CC]} {
@@ -678,15 +696,15 @@
678 }
679
680 define CPP [get-env CPP "[get-define CC] -E"]
681
682 # XXX: Could avoid looking for a C++ compiler until requested
683 # Note that if CXX isn't found, we just set it to "false". It might not be needed.
684 if {[env-is-set CXX]} {
685 define CXX [find-an-executable -required [get-env CXX ""]]
686 } else {
687 define CXX [find-an-executable [get-define cross]c++ [get-define cross]g++ false]
688 }
689
690 # CXXFLAGS default to CFLAGS if not specified
691 define CXXFLAGS [get-env CXXFLAGS [get-define CFLAGS]]
692
@@ -694,29 +712,34 @@
694 define CC_FOR_BUILD [find-an-executable [get-env CC_FOR_BUILD ""] cc gcc false]
695
696 if {[get-define CC] eq ""} {
697 user-error "Could not find a C compiler. Tried: [join $try ", "]"
698 }
 
 
 
 
 
699
700 define CCACHE [find-an-executable [get-env CCACHE ccache]]
701
702 # If any of these are set in the environment, propagate them to the AUTOREMAKE commandline
703 foreach i {CC CXX CCACHE CPP CFLAGS CXXFLAGS CXXFLAGS LDFLAGS LIBS CROSS CPPFLAGS LINKFLAGS CC_FOR_BUILD LD} {
704 if {[env-is-set $i]} {
705 # Note: If the variable is set on the command line, get-env will return that value
706 # so the command line will continue to override the environment
707 define-append AUTOREMAKE [quote-if-needed $i=[get-env $i ""]]
708 }
709 }
710
711 # Initial cctest settings
712 cc-store-settings {-cflags {} -includes {} -declare {} -link 0 -lang c -libs {} -code {} -nooutput 0}
713 set autosetup(cc-include-deps) {}
714
715 msg-result "C compiler...[get-define CCACHE] [get-define CC] [get-define CFLAGS]"
716 if {[get-define CXX] ne "false"} {
717 msg-result "C++ compiler...[get-define CCACHE] [get-define CXX] [get-define CXXFLAGS]"
718 }
719 msg-result "Build C compiler...[get-define CC_FOR_BUILD]"
720
721 # On Darwin, we prefer to use -g0 to avoid creating .dSYM directories
722 # but some compilers may not support it, so test here.
723
--- autosetup/cc.tcl
+++ autosetup/cc.tcl
@@ -11,27 +11,27 @@
11 #
12 ## CC - C compiler
13 ## CXX - C++ compiler
14 ## CPP - C preprocessor
15 ## CCACHE - Set to "none" to disable automatic use of ccache
16 ## CPPFLAGS - Additional C preprocessor compiler flags (C and C++), before CFLAGS, CXXFLAGS
17 ## CFLAGS - Additional C compiler flags
18 ## CXXFLAGS - Additional C++ compiler flags
19 ## LDFLAGS - Additional compiler flags during linking
20 ## LINKFLAGS - ?How is this different from LDFLAGS?
21 ## LIBS - Additional libraries to use (for all tests)
22 ## CROSS - Tool prefix for cross compilation
23 #
24 # The following variables are defined from the corresponding
25 # environment variables if set.
26 #
 
 
27 ## CC_FOR_BUILD
28 ## LD
29
30 use system
31
32 options {}
33
34 # Checks for the existence of the given function by linking
35 #
36 proc cctest_function {function} {
37 cctest -link 1 -declare "extern void $function\(void);" -code "$function\();"
@@ -262,15 +262,15 @@
262 #
263 proc cc-check-tools {args} {
264 foreach tool $args {
265 set TOOL [string toupper $tool]
266 set exe [get-env $TOOL [get-define cross]$tool]
267 if {[find-executable $exe]} {
268 define $TOOL $exe
269 continue
270 }
271 if {[find-executable $tool]} {
272 msg-result "Warning: Failed to find $exe, falling back to $tool which may be incorrect"
273 define $TOOL $tool
274 continue
275 }
276 user-error "Failed to find $exe"
@@ -416,10 +416,17 @@
416 ## cc-with {-libs -ldl} {
417 ## cctest -libs -lsocket ...
418 ## # libs will be in this order: -lsocket -ldl -lc -lm
419 ## }
420 ## }
421 #
422 # If you wish to invoke something like cc-check-flags but not have -cflags updated,
423 # use the following idiom:
424 #
425 ## cc-with {} {
426 ## cc-check-flags ...
427 ## }
428 proc cc-with {settings args} {
429 if {[llength $args] == 0} {
430 cc-add-settings $settings
431 } elseif {[llength $args] > 1} {
432 autosetup-error "usage: cc-with settings ?script?"
@@ -453,18 +460,26 @@
460 ## -nooutput 1 Treat any compiler output (e.g. a warning) as an error
461 #
462 # Unless '-source' or '-sourcefile' is specified, the C program looks like:
463 #
464 ## #include <firstinclude> /* same for remaining includes in the list */
 
465 ## declare-code /* any code in -declare, verbatim */
 
466 ## int main(void) {
467 ## code /* any code in -code, verbatim */
468 ## return 0;
469 ## }
470 #
471 # And the command line looks like:
472 #
473 ## CC -cflags CFLAGS CPPFLAGS conftest.c -o conftest.o
474 ## CXX -cflags CXXFLAGS CPPFLAGS conftest.cpp -o conftest.o
475 #
476 # And if linking:
477 #
478 ## CC LDFLAGS -cflags CFLAGS conftest.c -o conftest -libs LIBS
479 ## CXX LDFLAGS -cflags CXXFLAGS conftest.c -o conftest -libs LIBS
480 #
481 # Any failures are recorded in 'config.log'
482 #
483 proc cctest {args} {
484 set tmp conftest__
485
@@ -506,31 +521,34 @@
521 set cmdline {}
522 lappend cmdline {*}[get-define CCACHE]
523 switch -exact -- $opts(-lang) {
524 c++ {
525 set src conftest__.cpp
526 lappend cmdline {*}[get-define CXX]
527 set cflags [get-define CXXFLAGS]
528 }
529 c {
530 set src conftest__.c
531 lappend cmdline {*}[get-define CC]
532 set cflags [get-define CFLAGS]
533 }
534 default {
535 autosetup-error "cctest called with unknown language: $opts(-lang)"
536 }
537 }
538
539 if {$opts(-link)} {
540 lappend cmdline {*}[get-define LDFLAGS]
541 } else {
542 lappend cflags {*}[get-define CPPFLAGS]
543 set tmp conftest__.o
544 lappend cmdline -c
545 }
546 lappend cmdline {*}$opts(-cflags) {*}[get-define cc-default-debug ""] {*}$cflags
547 lappend cmdline $src -o $tmp
548 if {$opts(-link)} {
549 lappend cmdline {*}$opts(-libs) {*}[get-define LIBS]
550 }
551
552 # At this point we have the complete command line and the
553 # complete source to be compiled. Get the result from cache if
554 # we can
@@ -658,11 +676,11 @@
676 }
677 return ""
678 }
679
680 # Initialise some values from the environment or commandline or default settings
681 foreach i {LDFLAGS LIBS CPPFLAGS LINKFLAGS CFLAGS} {
682 lassign $i var default
683 define $var [get-env $var $default]
684 }
685
686 if {[env-is-set CC]} {
@@ -678,15 +696,15 @@
696 }
697
698 define CPP [get-env CPP "[get-define CC] -E"]
699
700 # XXX: Could avoid looking for a C++ compiler until requested
701 # If CXX isn't found, it is set to the empty string.
702 if {[env-is-set CXX]} {
703 define CXX [find-an-executable -required [get-env CXX ""]]
704 } else {
705 define CXX [find-an-executable [get-define cross]c++ [get-define cross]g++]
706 }
707
708 # CXXFLAGS default to CFLAGS if not specified
709 define CXXFLAGS [get-env CXXFLAGS [get-define CFLAGS]]
710
@@ -694,29 +712,34 @@
712 define CC_FOR_BUILD [find-an-executable [get-env CC_FOR_BUILD ""] cc gcc false]
713
714 if {[get-define CC] eq ""} {
715 user-error "Could not find a C compiler. Tried: [join $try ", "]"
716 }
717
718 # These start empty and never come from the user or environment
719 define AS_CFLAGS ""
720 define AS_CPPFLAGS ""
721 define AS_CXXFLAGS ""
722
723 define CCACHE [find-an-executable [get-env CCACHE ccache]]
724
725 # If any of these are set in the environment, propagate them to the AUTOREMAKE commandline
726 foreach i {CC CXX CCACHE CPP CFLAGS CXXFLAGS CXXFLAGS LDFLAGS LIBS CROSS CPPFLAGS LINKFLAGS CC_FOR_BUILD LD} {
727 if {[env-is-set $i]} {
728 # Note: If the variable is set on the command line, get-env will return that value
729 # so the command line will continue to override the environment
730 define-append-argv AUTOREMAKE $i=[get-env $i ""]
731 }
732 }
733
734 # Initial cctest settings
735 cc-store-settings {-cflags {} -includes {} -declare {} -link 0 -lang c -libs {} -code {} -nooutput 0}
736 set autosetup(cc-include-deps) {}
737
738 msg-result "C compiler...[get-define CCACHE] [get-define CC] [get-define CFLAGS] [get-define CPPFLAGS]"
739 if {[get-define CXX] ne "false"} {
740 msg-result "C++ compiler...[get-define CCACHE] [get-define CXX] [get-define CXXFLAGS] [get-define CPPFLAGS]"
741 }
742 msg-result "Build C compiler...[get-define CC_FOR_BUILD]"
743
744 # On Darwin, we prefer to use -g0 to avoid creating .dSYM directories
745 # but some compilers may not support it, so test here.
746
+4125 -2319
--- autosetup/jimsh0.c
+++ autosetup/jimsh0.c
@@ -10,10 +10,11 @@
1010
#define jim_ext_readdir
1111
#define jim_ext_regexp
1212
#define jim_ext_file
1313
#define jim_ext_glob
1414
#define jim_ext_exec
15
+#define jim_ext_posix
1516
#define jim_ext_clock
1617
#define jim_ext_array
1718
#define jim_ext_stdlib
1819
#define jim_ext_tclcompat
1920
#if defined(_MSC_VER)
@@ -47,21 +48,23 @@
4748
#define vfork fork
4849
#define _POSIX_SOURCE
4950
#else
5051
#define _GNU_SOURCE
5152
#endif
52
-#define HAVE_VFORK
53
+#define HAVE_FORK
5354
#define HAVE_WAITPID
5455
#define HAVE_ISATTY
5556
#define HAVE_MKSTEMP
5657
#define HAVE_LINK
5758
#define HAVE_SYS_TIME_H
5859
#define HAVE_DIRENT_H
5960
#define HAVE_UNISTD_H
6061
#define HAVE_UMASK
62
+#define HAVE_PIPE
63
+#define _FILE_OFFSET_BITS 64
6164
#endif
62
-#define JIM_VERSION 78
65
+#define JIM_VERSION 82
6366
#ifndef JIM_WIN32COMPAT_H
6467
#define JIM_WIN32COMPAT_H
6568
6669
6770
@@ -184,11 +187,10 @@
184187
extern "C" {
185188
#endif
186189
187190
#include <time.h>
188191
#include <limits.h>
189
-#include <stdio.h>
190192
#include <stdlib.h>
191193
#include <stdarg.h>
192194
193195
194196
#ifndef HAVE_NO_AUTOCONF
@@ -223,10 +225,13 @@
223225
#endif
224226
225227
#define UCHAR(c) ((unsigned char)(c))
226228
227229
230
+
231
+#define JIM_ABI_VERSION 101
232
+
228233
#define JIM_OK 0
229234
#define JIM_ERR 1
230235
#define JIM_RETURN 2
231236
#define JIM_BREAK 3
232237
#define JIM_CONTINUE 4
@@ -244,10 +249,11 @@
244249
#define JIM_NONE 0
245250
#define JIM_ERRMSG 1
246251
#define JIM_ENUM_ABBREV 2
247252
#define JIM_UNSHARED 4
248253
#define JIM_MUSTEXIST 8
254
+#define JIM_NORESULT 16
249255
250256
251257
#define JIM_SUBST_NOVAR 1
252258
#define JIM_SUBST_NOCMD 2
253259
#define JIM_SUBST_NOESC 4
@@ -254,10 +260,11 @@
254260
#define JIM_SUBST_FLAG 128
255261
256262
257263
#define JIM_CASESENS 0
258264
#define JIM_NOCASE 1
265
+#define JIM_OPT_END 2
259266
260267
261268
#define JIM_PATH_LEN 1024
262269
263270
@@ -322,10 +329,12 @@
322329
(entry)->u.val = (ht)->type->valDup((ht)->privdata, (_val_)); \
323330
else \
324331
(entry)->u.val = (_val_); \
325332
} while(0)
326333
334
+#define Jim_SetHashIntVal(ht, entry, _val_) (entry)->u.intval = (_val_)
335
+
327336
#define Jim_FreeEntryKey(ht, entry) \
328337
if ((ht)->type->keyDestructor) \
329338
(ht)->type->keyDestructor((ht)->privdata, (entry)->key)
330339
331340
#define Jim_SetHashKey(ht, entry, _key_) do { \
@@ -342,10 +351,11 @@
342351
343352
#define Jim_HashKey(ht, key) ((ht)->type->hashFunction(key) + (ht)->uniq)
344353
345354
#define Jim_GetHashEntryKey(he) ((he)->key)
346355
#define Jim_GetHashEntryVal(he) ((he)->u.val)
356
+#define Jim_GetHashEntryIntVal(he) ((he)->u.intval)
347357
#define Jim_GetHashTableCollisions(ht) ((ht)->collisions)
348358
#define Jim_GetHashTableSize(ht) ((ht)->size)
349359
#define Jim_GetHashTableUsed(ht) ((ht)->used)
350360
351361
@@ -375,11 +385,11 @@
375385
int int1;
376386
int int2;
377387
} ptrIntValue;
378388
379389
struct {
380
- struct Jim_Var *varPtr;
390
+ struct Jim_VarVal *vv;
381391
unsigned long callFrameId;
382392
int global;
383393
} varValue;
384394
385395
struct {
@@ -391,10 +401,12 @@
391401
struct {
392402
struct Jim_Obj **ele;
393403
int len;
394404
int maxLen;
395405
} listValue;
406
+
407
+ struct Jim_Dict *dictValue;
396408
397409
struct {
398410
int maxLength;
399411
int charLength;
400412
} strValue;
@@ -477,33 +489,59 @@
477489
int argc;
478490
Jim_Obj *procArgsObjPtr;
479491
Jim_Obj *procBodyObjPtr;
480492
struct Jim_CallFrame *next;
481493
Jim_Obj *nsObj;
482
- Jim_Obj *fileNameObj;
483
- int line;
494
+ Jim_Obj *unused_fileNameObj;
495
+ int unused_line;
484496
Jim_Stack *localCommands;
485497
struct Jim_Obj *tailcallObj;
486498
struct Jim_Cmd *tailcallCmd;
487499
} Jim_CallFrame;
488500
489
-typedef struct Jim_Var {
501
+
502
+typedef struct Jim_EvalFrame {
503
+ Jim_CallFrame *framePtr;
504
+ int level;
505
+ int procLevel;
506
+ struct Jim_Cmd *cmd;
507
+ struct Jim_EvalFrame *parent;
508
+ Jim_Obj *const *argv;
509
+ int argc;
510
+ Jim_Obj *scriptObj;
511
+} Jim_EvalFrame;
512
+
513
+typedef struct Jim_VarVal {
490514
Jim_Obj *objPtr;
491515
struct Jim_CallFrame *linkFramePtr;
492
-} Jim_Var;
516
+ int refCount;
517
+} Jim_VarVal;
493518
494519
495520
typedef int Jim_CmdProc(struct Jim_Interp *interp, int argc,
496521
Jim_Obj *const *argv);
497522
typedef void Jim_DelCmdProc(struct Jim_Interp *interp, void *privData);
498523
499
-
524
+typedef struct Jim_Dict {
525
+ struct JimDictHashEntry {
526
+ int offset;
527
+ unsigned hash;
528
+ } *ht;
529
+ unsigned int size;
530
+ unsigned int sizemask;
531
+ unsigned int uniq;
532
+ Jim_Obj **table;
533
+ int len;
534
+ int maxLen;
535
+ unsigned int dummy;
536
+} Jim_Dict;
500537
501538
typedef struct Jim_Cmd {
502539
int inUse;
503540
int isproc;
504541
struct Jim_Cmd *prevCmd;
542
+ Jim_Obj *cmdNameObj;
505543
union {
506544
struct {
507545
508546
Jim_CmdProc *cmdProc;
509547
Jim_DelCmdProc *delProc;
@@ -534,13 +572,13 @@
534572
unsigned int i, j;
535573
} Jim_PrngState;
536574
537575
typedef struct Jim_Interp {
538576
Jim_Obj *result;
539
- int errorLine;
540
- Jim_Obj *errorFileNameObj;
541
- int addStackTrace;
577
+ int unused_errorLine;
578
+ Jim_Obj *currentFilenameObj;
579
+ int unused_addStackTrace;
542580
int maxCallFrameDepth;
543581
int maxEvalDepth;
544582
int evalDepth;
545583
int returnCode;
546584
int returnLevel;
@@ -558,13 +596,19 @@
558596
unsigned long callFrameEpoch; /* Incremented every time a new
559597
callframe is created. This id is used for the
560598
'ID' field contained in the Jim_CallFrame
561599
structure. */
562600
int local;
601
+ int quitting;
602
+ int safeexpr;
563603
Jim_Obj *liveList;
564604
Jim_Obj *freeList;
565
- Jim_Obj *currentScriptObj;
605
+ Jim_Obj *unused_currentScriptObj;
606
+ Jim_EvalFrame topEvalFrame;
607
+ Jim_EvalFrame *evalFrame;
608
+ int procLevel;
609
+ Jim_Obj * const *unused_argv;
566610
Jim_Obj *nullScriptObj;
567611
Jim_Obj *emptyObj;
568612
Jim_Obj *trueObj;
569613
Jim_Obj *falseObj;
570614
unsigned long referenceNextId;
@@ -572,28 +616,31 @@
572616
unsigned long lastCollectId; /* reference max Id of the last GC
573617
execution. It's set to ~0 while the collection
574618
is running as sentinel to avoid to recursive
575619
calls via the [collect] command inside
576620
finalizers. */
577
- time_t lastCollectTime;
621
+ jim_wide lastCollectTime;
578622
Jim_Obj *stackTrace;
579623
Jim_Obj *errorProc;
580624
Jim_Obj *unknown;
625
+ Jim_Obj *defer;
626
+ Jim_Obj *traceCmdObj;
581627
int unknown_called;
582628
int errorFlag;
583629
void *cmdPrivData; /* Used to pass the private data pointer to
584630
a command. It is set to what the user specified
585631
via Jim_CreateCommand(). */
586632
633
+ Jim_Cmd *oldCmdCache;
634
+ int oldCmdCacheSize;
587635
struct Jim_CallFrame *freeFramesList;
588636
struct Jim_HashTable assocData;
589637
Jim_PrngState *prngState;
590638
struct Jim_HashTable packages;
591639
Jim_Stack *loadHandles;
592640
} Jim_Interp;
593641
594
-#define Jim_InterpIncrProcEpoch(i) (i)->procEpoch++
595642
#define Jim_SetResultString(i,s,l) Jim_SetResult(i, Jim_NewStringObj(i,s,l))
596643
#define Jim_SetResultInt(i,intval) Jim_SetResult(i, Jim_NewIntObj(i,intval))
597644
598645
#define Jim_SetResultBool(i,b) Jim_SetResultInt(i, b)
599646
#define Jim_SetEmptyResult(i) Jim_SetResult(i, (i)->emptyObj)
@@ -621,23 +668,36 @@
621668
622669
623670
#define Jim_NewEmptyStringObj(i) Jim_NewStringObj(i, "", 0)
624671
#define Jim_FreeHashTableIterator(iter) Jim_Free(iter)
625672
626
-#define JIM_EXPORT
673
+#define JIM_EXPORT extern
627674
628675
629
-JIM_EXPORT void *Jim_Alloc (int size);
630
-JIM_EXPORT void *Jim_Realloc(void *ptr, int size);
631
-JIM_EXPORT void Jim_Free (void *ptr);
676
+
677
+JIM_EXPORT void *(*Jim_Allocator)(void *ptr, size_t size);
678
+
679
+#define Jim_Free(P) Jim_Allocator((P), 0)
680
+#define Jim_Realloc(P, S) Jim_Allocator((P), (S))
681
+#define Jim_Alloc(S) Jim_Allocator(NULL, (S))
632682
JIM_EXPORT char * Jim_StrDup (const char *s);
633683
JIM_EXPORT char *Jim_StrDupLen(const char *s, int l);
634684
635685
636686
JIM_EXPORT char **Jim_GetEnviron(void);
637687
JIM_EXPORT void Jim_SetEnviron(char **env);
638688
JIM_EXPORT int Jim_MakeTempFile(Jim_Interp *interp, const char *filename_template, int unlink_file);
689
+#ifndef CLOCK_REALTIME
690
+# define CLOCK_REALTIME 0
691
+#endif
692
+#ifndef CLOCK_MONOTONIC
693
+# define CLOCK_MONOTONIC 1
694
+#endif
695
+#ifndef CLOCK_MONOTONIC_RAW
696
+# define CLOCK_MONOTONIC_RAW CLOCK_MONOTONIC
697
+#endif
698
+JIM_EXPORT jim_wide Jim_GetTimeUsec(unsigned type);
639699
640700
641701
JIM_EXPORT int Jim_Eval(Jim_Interp *interp, const char *script);
642702
643703
@@ -680,11 +740,10 @@
680740
JIM_EXPORT int Jim_DeleteHashEntry (Jim_HashTable *ht,
681741
const void *key);
682742
JIM_EXPORT int Jim_FreeHashTable (Jim_HashTable *ht);
683743
JIM_EXPORT Jim_HashEntry * Jim_FindHashEntry (Jim_HashTable *ht,
684744
const void *key);
685
-JIM_EXPORT void Jim_ResizeHashTable (Jim_HashTable *ht);
686745
JIM_EXPORT Jim_HashTableIterator *Jim_GetHashTableIterator
687746
(Jim_HashTable *ht);
688747
JIM_EXPORT Jim_HashEntry * Jim_NextHashEntry
689748
(Jim_HashTableIterator *iter);
690749
@@ -724,12 +783,10 @@
724783
Jim_Obj *fmtObjPtr, int flags);
725784
JIM_EXPORT int Jim_CompareStringImmediate (Jim_Interp *interp,
726785
Jim_Obj *objPtr, const char *str);
727786
JIM_EXPORT int Jim_StringCompareObj(Jim_Interp *interp, Jim_Obj *firstObjPtr,
728787
Jim_Obj *secondObjPtr, int nocase);
729
-JIM_EXPORT int Jim_StringCompareLenObj(Jim_Interp *interp, Jim_Obj *firstObjPtr,
730
- Jim_Obj *secondObjPtr, int nocase);
731788
JIM_EXPORT int Jim_Utf8Length(Jim_Interp *interp, Jim_Obj *objPtr);
732789
733790
734791
JIM_EXPORT Jim_Obj * Jim_NewReference (Jim_Interp *interp,
735792
Jim_Obj *objPtr, Jim_Obj *tagPtr, Jim_Obj *cmdNamePtr);
@@ -749,13 +806,13 @@
749806
JIM_EXPORT void Jim_RegisterCoreCommands (Jim_Interp *interp);
750807
JIM_EXPORT int Jim_CreateCommand (Jim_Interp *interp,
751808
const char *cmdName, Jim_CmdProc *cmdProc, void *privData,
752809
Jim_DelCmdProc *delProc);
753810
JIM_EXPORT int Jim_DeleteCommand (Jim_Interp *interp,
754
- const char *cmdName);
811
+ Jim_Obj *cmdNameObj);
755812
JIM_EXPORT int Jim_RenameCommand (Jim_Interp *interp,
756
- const char *oldName, const char *newName);
813
+ Jim_Obj *oldNameObj, Jim_Obj *newNameObj);
757814
JIM_EXPORT Jim_Cmd * Jim_GetCommand (Jim_Interp *interp,
758815
Jim_Obj *objPtr, int flags);
759816
JIM_EXPORT int Jim_SetVariable (Jim_Interp *interp,
760817
Jim_Obj *nameObjPtr, Jim_Obj *valObjPtr);
761818
JIM_EXPORT int Jim_SetVariableStr (Jim_Interp *interp,
@@ -822,12 +879,12 @@
822879
Jim_Obj *dictPtr, Jim_Obj *const *keyv, int keyc,
823880
Jim_Obj **objPtrPtr, int flags);
824881
JIM_EXPORT int Jim_SetDictKeysVector (Jim_Interp *interp,
825882
Jim_Obj *varNamePtr, Jim_Obj *const *keyv, int keyc,
826883
Jim_Obj *newObjPtr, int flags);
827
-JIM_EXPORT int Jim_DictPairs(Jim_Interp *interp,
828
- Jim_Obj *dictPtr, Jim_Obj ***objPtrPtr, int *len);
884
+JIM_EXPORT Jim_Obj **Jim_DictPairs(Jim_Interp *interp,
885
+ Jim_Obj *dictPtr, int *len);
829886
JIM_EXPORT int Jim_DictAddElement(Jim_Interp *interp, Jim_Obj *objPtr,
830887
Jim_Obj *keyObjPtr, Jim_Obj *valueObjPtr);
831888
832889
#define JIM_DICTMATCH_KEYS 0x0001
833890
#define JIM_DICTMATCH_VALUES 0x002
@@ -851,10 +908,12 @@
851908
JIM_EXPORT int Jim_GetBoolean(Jim_Interp *interp, Jim_Obj *objPtr,
852909
int *booleanPtr);
853910
854911
855912
JIM_EXPORT int Jim_GetWide (Jim_Interp *interp, Jim_Obj *objPtr,
913
+ jim_wide *widePtr);
914
+JIM_EXPORT int Jim_GetWideExpr(Jim_Interp *interp, Jim_Obj *objPtr,
856915
jim_wide *widePtr);
857916
JIM_EXPORT int Jim_GetLong (Jim_Interp *interp, Jim_Obj *objPtr,
858917
long *longPtr);
859918
#define Jim_NewWideObj Jim_NewIntObj
860919
JIM_EXPORT Jim_Obj * Jim_NewIntObj (Jim_Interp *interp,
@@ -883,43 +942,52 @@
883942
typedef void (Jim_InterpDeleteProc)(Jim_Interp *interp, void *data);
884943
JIM_EXPORT void * Jim_GetAssocData(Jim_Interp *interp, const char *key);
885944
JIM_EXPORT int Jim_SetAssocData(Jim_Interp *interp, const char *key,
886945
Jim_InterpDeleteProc *delProc, void *data);
887946
JIM_EXPORT int Jim_DeleteAssocData(Jim_Interp *interp, const char *key);
947
+JIM_EXPORT int Jim_CheckAbiVersion(Jim_Interp *interp, int abi_version);
948
+
888949
889950
890951
891952
JIM_EXPORT int Jim_PackageProvide (Jim_Interp *interp,
892953
const char *name, const char *ver, int flags);
893954
JIM_EXPORT int Jim_PackageRequire (Jim_Interp *interp,
894955
const char *name, int flags);
956
+#define Jim_PackageProvideCheck(INTERP, NAME) \
957
+ if (Jim_CheckAbiVersion(INTERP, JIM_ABI_VERSION) == JIM_ERR || Jim_PackageProvide(INTERP, NAME, "1.0", JIM_ERRMSG)) \
958
+ return JIM_ERR
895959
896960
897961
JIM_EXPORT void Jim_MakeErrorMessage (Jim_Interp *interp);
898962
899963
900964
JIM_EXPORT int Jim_InteractivePrompt (Jim_Interp *interp);
901965
JIM_EXPORT void Jim_HistoryLoad(const char *filename);
902966
JIM_EXPORT void Jim_HistorySave(const char *filename);
903967
JIM_EXPORT char *Jim_HistoryGetline(Jim_Interp *interp, const char *prompt);
904
-JIM_EXPORT void Jim_HistorySetCompletion(Jim_Interp *interp, Jim_Obj *commandObj);
968
+JIM_EXPORT void Jim_HistorySetCompletion(Jim_Interp *interp, Jim_Obj *completionCommandObj);
969
+JIM_EXPORT void Jim_HistorySetHints(Jim_Interp *interp, Jim_Obj *hintsCommandObj);
905970
JIM_EXPORT void Jim_HistoryAdd(const char *line);
906971
JIM_EXPORT void Jim_HistoryShow(void);
972
+JIM_EXPORT void Jim_HistorySetMaxLen(int length);
973
+JIM_EXPORT int Jim_HistoryGetMaxLen(void);
907974
908975
909976
JIM_EXPORT int Jim_InitStaticExtensions(Jim_Interp *interp);
910977
JIM_EXPORT int Jim_StringToWide(const char *str, jim_wide *widePtr, int base);
911978
JIM_EXPORT int Jim_IsBigEndian(void);
912979
913980
#define Jim_CheckSignal(i) ((i)->signal_level && (i)->sigmask)
981
+JIM_EXPORT void Jim_SignalSetIgnored(jim_wide mask);
914982
915983
916984
JIM_EXPORT int Jim_LoadLibrary(Jim_Interp *interp, const char *pathName);
917985
JIM_EXPORT void Jim_FreeLoadHandles(Jim_Interp *interp);
918986
919987
920
-JIM_EXPORT FILE *Jim_AioFilehandle(Jim_Interp *interp, Jim_Obj *command);
988
+JIM_EXPORT int Jim_AioFilehandle(Jim_Interp *interp, Jim_Obj *command);
921989
922990
923991
JIM_EXPORT int Jim_IsDict(Jim_Obj *objPtr);
924992
JIM_EXPORT int Jim_IsList(Jim_Obj *objPtr);
925993
@@ -952,16 +1020,21 @@
9521020
short minargs;
9531021
short maxargs;
9541022
unsigned short flags;
9551023
} jim_subcmd_type;
9561024
1025
+#define JIM_DEF_SUBCMD(name, args, minargs, maxargs) { name, args, NULL, minargs, maxargs }
1026
+#define JIM_DEF_SUBCMD_HIDDEN(name, args, minargs, maxargs) { name, args, NULL, minargs, maxargs, JIM_MODFLAG_HIDDEN }
1027
+
9571028
const jim_subcmd_type *
9581029
Jim_ParseSubCmd(Jim_Interp *interp, const jim_subcmd_type *command_table, int argc, Jim_Obj *const *argv);
9591030
9601031
int Jim_SubCmdProc(Jim_Interp *interp, int argc, Jim_Obj *const *argv);
9611032
9621033
int Jim_CallSubCmd(Jim_Interp *interp, const jim_subcmd_type *ct, int argc, Jim_Obj *const *argv);
1034
+
1035
+void Jim_SubCmdArgError(Jim_Interp *interp, const jim_subcmd_type *ct, Jim_Obj *subcmd);
9631036
9641037
#ifdef __cplusplus
9651038
}
9661039
#endif
9671040
@@ -1034,20 +1107,21 @@
10341107
REG_ERR_JUNK_ON_END,
10351108
REG_ERR_OPERAND_COULD_BE_EMPTY,
10361109
REG_ERR_NESTED_COUNT,
10371110
REG_ERR_INTERNAL,
10381111
REG_ERR_COUNT_FOLLOWS_NOTHING,
1039
- REG_ERR_TRAILING_BACKSLASH,
1112
+ REG_ERR_INVALID_ESCAPE,
10401113
REG_ERR_CORRUPTED,
10411114
REG_ERR_NULL_CHAR,
1115
+ REG_ERR_UNMATCHED_BRACKET,
10421116
REG_ERR_NUM
10431117
};
10441118
1045
-int regcomp(regex_t *preg, const char *regex, int cflags);
1046
-int regexec(regex_t *preg, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags);
1047
-size_t regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size);
1048
-void regfree(regex_t *preg);
1119
+int jim_regcomp(regex_t *preg, const char *regex, int cflags);
1120
+int jim_regexec(regex_t *preg, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags);
1121
+size_t jim_regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size);
1122
+void jim_regfree(regex_t *preg);
10491123
10501124
#ifdef __cplusplus
10511125
}
10521126
#endif
10531127
@@ -1070,10 +1144,11 @@
10701144
#define JIMIOCOMPAT_H
10711145
10721146
10731147
#include <stdio.h>
10741148
#include <errno.h>
1149
+#include <sys/stat.h>
10751150
10761151
10771152
void Jim_SetResultErrno(Jim_Interp *interp, const char *msg);
10781153
10791154
int Jim_OpenForWrite(const char *filename, int append);
@@ -1088,67 +1163,109 @@
10881163
#include <windows.h>
10891164
#include <fcntl.h>
10901165
#include <io.h>
10911166
#include <process.h>
10921167
1093
- typedef HANDLE pidtype;
1094
- #define JIM_BAD_PID INVALID_HANDLE_VALUE
1095
-
1096
- #define JIM_NO_PID INVALID_HANDLE_VALUE
1168
+ typedef HANDLE phandle_t;
1169
+ #define JIM_BAD_PHANDLE INVALID_HANDLE_VALUE
10971170
10981171
10991172
#define WIFEXITED(STATUS) (((STATUS) & 0xff00) == 0)
11001173
#define WEXITSTATUS(STATUS) ((STATUS) & 0x00ff)
11011174
#define WIFSIGNALED(STATUS) (((STATUS) & 0xff00) != 0)
11021175
#define WTERMSIG(STATUS) (((STATUS) >> 8) & 0xff)
11031176
#define WNOHANG 1
11041177
11051178
int Jim_Errno(void);
1106
- pidtype waitpid(pidtype pid, int *status, int nohang);
1179
+
1180
+ long waitpid(phandle_t phandle, int *status, int nohang);
1181
+
1182
+ phandle_t JimWaitPid(long processid, int *status, int nohang);
1183
+
1184
+ long JimProcessPid(phandle_t phandle);
11071185
11081186
#define HAVE_PIPE
11091187
#define pipe(P) _pipe((P), 0, O_NOINHERIT)
11101188
1111
-#elif defined(HAVE_UNISTD_H)
1112
- #include <unistd.h>
1113
- #include <fcntl.h>
1114
- #include <sys/wait.h>
1115
- #include <sys/stat.h>
1116
-
1117
- typedef int pidtype;
1118
- #define Jim_Errno() errno
1119
- #define JIM_BAD_PID -1
1120
- #define JIM_NO_PID 0
1121
-
1122
- #ifndef HAVE_EXECVPE
1123
- #define execvpe(ARG0, ARGV, ENV) execvp(ARG0, ARGV)
1189
+ typedef struct __stat64 jim_stat_t;
1190
+ #define Jim_Stat _stat64
1191
+ #define Jim_FileStat _fstat64
1192
+ #define Jim_Lseek _lseeki64
1193
+
1194
+#else
1195
+ #if defined(HAVE_STAT64)
1196
+ typedef struct stat64 jim_stat_t;
1197
+ #define Jim_Stat stat64
1198
+ #if defined(HAVE_FSTAT64)
1199
+ #define Jim_FileStat fstat64
1200
+ #endif
1201
+ #if defined(HAVE_LSTAT64)
1202
+ #define Jim_LinkStat lstat64
1203
+ #endif
1204
+ #else
1205
+ typedef struct stat jim_stat_t;
1206
+ #define Jim_Stat stat
1207
+ #if defined(HAVE_FSTAT)
1208
+ #define Jim_FileStat fstat
1209
+ #endif
1210
+ #if defined(HAVE_LSTAT)
1211
+ #define Jim_LinkStat lstat
1212
+ #endif
1213
+ #endif
1214
+ #if defined(HAVE_LSEEK64)
1215
+ #define Jim_Lseek lseek64
1216
+ #else
1217
+ #define Jim_Lseek lseek
1218
+ #endif
1219
+
1220
+ #if defined(HAVE_UNISTD_H)
1221
+ #include <unistd.h>
1222
+ #include <fcntl.h>
1223
+ #include <sys/wait.h>
1224
+
1225
+ typedef int phandle_t;
1226
+ #define Jim_Errno() errno
1227
+ #define JIM_BAD_PHANDLE -1
1228
+ #define JimProcessPid(PIDTYPE) (PIDTYPE)
1229
+ #define JimWaitPid waitpid
1230
+
1231
+ #ifndef HAVE_EXECVPE
1232
+ #define execvpe(ARG0, ARGV, ENV) execvp(ARG0, ARGV)
1233
+ #endif
11241234
#endif
11251235
#endif
11261236
1237
+#ifndef O_TEXT
1238
+#define O_TEXT 0
1239
+#endif
1240
+
1241
+
1242
+int Jim_FileStoreStatData(Jim_Interp *interp, Jim_Obj *varName, const jim_stat_t *sb);
1243
+
11271244
#endif
11281245
int Jim_bootstrapInit(Jim_Interp *interp)
11291246
{
11301247
if (Jim_PackageProvide(interp, "bootstrap", "1.0", JIM_ERRMSG))
11311248
return JIM_ERR;
11321249
11331250
return Jim_EvalSource(interp, "bootstrap.tcl", 1,
11341251
"\n"
1135
-"\n"
1136
-"proc package {cmd pkg args} {\n"
1252
+"proc package {cmd args} {\n"
11371253
" if {$cmd eq \"require\"} {\n"
11381254
" foreach path $::auto_path {\n"
1255
+" lassign $args pkg\n"
11391256
" set pkgpath $path/$pkg.tcl\n"
11401257
" if {$path eq \".\"} {\n"
11411258
" set pkgpath $pkg.tcl\n"
11421259
" }\n"
11431260
" if {[file exists $pkgpath]} {\n"
1144
-" uplevel #0 [list source $pkgpath]\n"
1145
-" return\n"
1261
+" tailcall uplevel #0 [list source $pkgpath]\n"
11461262
" }\n"
11471263
" }\n"
11481264
" }\n"
11491265
"}\n"
1266
+"set tcl_platform(bootstrap) 1\n"
11501267
);
11511268
}
11521269
int Jim_initjimshInit(Jim_Interp *interp)
11531270
{
11541271
if (Jim_PackageProvide(interp, "initjimsh", "1.0", JIM_ERRMSG))
@@ -1199,11 +1316,11 @@
11991316
"if {$tcl_platform(platform) eq \"windows\"} {\n"
12001317
" set jim::argv0 [string map {\\\\ /} $jim::argv0]\n"
12011318
"}\n"
12021319
"\n"
12031320
"\n"
1204
-"set tcl::autocomplete_commands {info tcl::prefix socket namespace array clock file package string dict signal history}\n"
1321
+"set tcl::autocomplete_commands {array clock debug dict file history info namespace package signal socket string tcl::prefix zlib}\n"
12051322
"\n"
12061323
"\n"
12071324
"\n"
12081325
"proc tcl::autocomplete {prefix} {\n"
12091326
" if {[set space [string first \" \" $prefix]] != -1} {\n"
@@ -1231,10 +1348,67 @@
12311348
" }\n"
12321349
" function $p\n"
12331350
" }]\n"
12341351
"}\n"
12351352
"\n"
1353
+"\n"
1354
+"set tcl::stdhint_commands {array clock debug dict file history info namespace package signal string zlib}\n"
1355
+"\n"
1356
+"set tcl::stdhint_cols {\n"
1357
+" none {0}\n"
1358
+" black {30}\n"
1359
+" red {31}\n"
1360
+" green {32}\n"
1361
+" yellow {33}\n"
1362
+" blue {34}\n"
1363
+" purple {35}\n"
1364
+" cyan {36}\n"
1365
+" normal {37}\n"
1366
+" grey {30 1}\n"
1367
+" gray {30 1}\n"
1368
+" lred {31 1}\n"
1369
+" lgreen {32 1}\n"
1370
+" lyellow {33 1}\n"
1371
+" lblue {34 1}\n"
1372
+" lpurple {35 1}\n"
1373
+" lcyan {36 1}\n"
1374
+" white {37 1}\n"
1375
+"}\n"
1376
+"\n"
1377
+"\n"
1378
+"set tcl::stdhint_col $tcl::stdhint_cols(lcyan)\n"
1379
+"\n"
1380
+"\n"
1381
+"proc tcl::stdhint {string} {\n"
1382
+" set result \"\"\n"
1383
+" if {[llength $string] >= 2} {\n"
1384
+" lassign $string cmd arg\n"
1385
+" if {$cmd in $::tcl::stdhint_commands || [info channel $cmd] ne \"\"} {\n"
1386
+" catch {\n"
1387
+" set help [$cmd -help $arg]\n"
1388
+" if {[string match \"Usage: $cmd *\" $help]} {\n"
1389
+" set n [llength $string]\n"
1390
+" set subcmd [lindex $help $n]\n"
1391
+" incr n\n"
1392
+" set hint [join [lrange $help $n end]]\n"
1393
+" set prefix \"\"\n"
1394
+" if {![string match \"* \" $string]} {\n"
1395
+" if {$n == 3 && $subcmd ne $arg} {\n"
1396
+"\n"
1397
+" set prefix \"[string range $subcmd [string length $arg] end] \"\n"
1398
+" } else {\n"
1399
+" set prefix \" \"\n"
1400
+" }\n"
1401
+" }\n"
1402
+" set result [list $prefix$hint {*}$::tcl::stdhint_col]\n"
1403
+" }\n"
1404
+" }\n"
1405
+" }\n"
1406
+" }\n"
1407
+" return $result\n"
1408
+"}\n"
1409
+"\n"
12361410
"_jimsh_init\n"
12371411
);
12381412
}
12391413
int Jim_globInit(Jim_Interp *interp)
12401414
{
@@ -1480,40 +1654,35 @@
14801654
"proc function {value} {\n"
14811655
" return $value\n"
14821656
"}\n"
14831657
"\n"
14841658
"\n"
1485
-"\n"
1486
-"\n"
1487
-"proc stacktrace {{skip 0}} {\n"
1488
-" set trace {}\n"
1489
-" incr skip\n"
1490
-" foreach level [range $skip [info level]] {\n"
1491
-" lappend trace {*}[info frame -$level]\n"
1492
-" }\n"
1493
-" return $trace\n"
1494
-"}\n"
1495
-"\n"
1496
-"\n"
14971659
"proc stackdump {stacktrace} {\n"
14981660
" set lines {}\n"
1499
-" foreach {l f p} [lreverse $stacktrace] {\n"
1661
+" lappend lines \"Traceback (most recent call last):\"\n"
1662
+" foreach {cmd l f p} [lreverse $stacktrace] {\n"
15001663
" set line {}\n"
1664
+" if {$f ne \"\"} {\n"
1665
+" append line \" File \\\"$f\\\", line $l\"\n"
1666
+" }\n"
15011667
" if {$p ne \"\"} {\n"
1502
-" append line \"in procedure '$p' \"\n"
1503
-" if {$f ne \"\"} {\n"
1504
-" append line \"called \"\n"
1505
-" }\n"
1506
-" }\n"
1507
-" if {$f ne \"\"} {\n"
1508
-" append line \"at file \\\"$f\\\", line $l\"\n"
1668
+" append line \", in $p\"\n"
15091669
" }\n"
15101670
" if {$line ne \"\"} {\n"
15111671
" lappend lines $line\n"
1672
+" if {$cmd ne \"\"} {\n"
1673
+" set nl [string first \\n $cmd 1]\n"
1674
+" if {$nl >= 0} {\n"
1675
+" set cmd [string range $cmd 0 $nl-1]...\n"
1676
+" }\n"
1677
+" lappend lines \" $cmd\"\n"
1678
+" }\n"
15121679
" }\n"
15131680
" }\n"
1514
-" join $lines \\n\n"
1681
+" if {[llength $lines] > 1} {\n"
1682
+" return [join $lines \\n]\n"
1683
+" }\n"
15151684
"}\n"
15161685
"\n"
15171686
"\n"
15181687
"\n"
15191688
"proc defer {script} {\n"
@@ -1525,14 +1694,12 @@
15251694
"\n"
15261695
"proc errorInfo {msg {stacktrace \"\"}} {\n"
15271696
" if {$stacktrace eq \"\"} {\n"
15281697
"\n"
15291698
" set stacktrace [info stacktrace]\n"
1530
-"\n"
1531
-" lappend stacktrace {*}[stacktrace 1]\n"
15321699
" }\n"
1533
-" lassign $stacktrace p f l\n"
1700
+" lassign $stacktrace p f l cmd\n"
15341701
" if {$f ne \"\"} {\n"
15351702
" set result \"$f:$l: Error: \"\n"
15361703
" }\n"
15371704
" append result \"$msg\\n\"\n"
15381705
" append result [stackdump $stacktrace]\n"
@@ -1641,11 +1808,11 @@
16411808
"\n"
16421809
"\n"
16431810
"set env [env]\n"
16441811
"\n"
16451812
"\n"
1646
-"if {[info commands stdout] ne \"\"} {\n"
1813
+"if {[exists -command stdout]} {\n"
16471814
"\n"
16481815
" foreach p {gets flush close eof seek tell} {\n"
16491816
" proc $p {chan args} {p} {\n"
16501817
" tailcall $chan $p {*}$args\n"
16511818
" }\n"
@@ -1815,76 +1982,10 @@
18151982
" return $pids\n"
18161983
"}\n"
18171984
"\n"
18181985
"\n"
18191986
"\n"
1820
-"\n"
1821
-"\n"
1822
-"\n"
1823
-"\n"
1824
-"\n"
1825
-"\n"
1826
-"\n"
1827
-"proc try {args} {\n"
1828
-" set catchopts {}\n"
1829
-" while {[string match -* [lindex $args 0]]} {\n"
1830
-" set args [lassign $args opt]\n"
1831
-" if {$opt eq \"--\"} {\n"
1832
-" break\n"
1833
-" }\n"
1834
-" lappend catchopts $opt\n"
1835
-" }\n"
1836
-" if {[llength $args] == 0} {\n"
1837
-" return -code error {wrong # args: should be \"try ?options? script ?argument ...?\"}\n"
1838
-" }\n"
1839
-" set args [lassign $args script]\n"
1840
-" set code [catch -eval {*}$catchopts {uplevel 1 $script} msg opts]\n"
1841
-"\n"
1842
-" set handled 0\n"
1843
-"\n"
1844
-" foreach {on codes vars script} $args {\n"
1845
-" switch -- $on \\\n"
1846
-" on {\n"
1847
-" if {!$handled && ($codes eq \"*\" || [info returncode $code] in $codes)} {\n"
1848
-" lassign $vars msgvar optsvar\n"
1849
-" if {$msgvar ne \"\"} {\n"
1850
-" upvar $msgvar hmsg\n"
1851
-" set hmsg $msg\n"
1852
-" }\n"
1853
-" if {$optsvar ne \"\"} {\n"
1854
-" upvar $optsvar hopts\n"
1855
-" set hopts $opts\n"
1856
-" }\n"
1857
-"\n"
1858
-" set code [catch {uplevel 1 $script} msg opts]\n"
1859
-" incr handled\n"
1860
-" }\n"
1861
-" } \\\n"
1862
-" finally {\n"
1863
-" set finalcode [catch {uplevel 1 $codes} finalmsg finalopts]\n"
1864
-" if {$finalcode} {\n"
1865
-"\n"
1866
-" set code $finalcode\n"
1867
-" set msg $finalmsg\n"
1868
-" set opts $finalopts\n"
1869
-" }\n"
1870
-" break\n"
1871
-" } \\\n"
1872
-" default {\n"
1873
-" return -code error \"try: expected 'on' or 'finally', got '$on'\"\n"
1874
-" }\n"
1875
-" }\n"
1876
-"\n"
1877
-" if {$code} {\n"
1878
-" incr opts(-level)\n"
1879
-" return {*}$opts $msg\n"
1880
-" }\n"
1881
-" return $msg\n"
1882
-"}\n"
1883
-"\n"
1884
-"\n"
1885
-"\n"
18861987
"proc throw {code {msg \"\"}} {\n"
18871988
" return -code $code $msg\n"
18881989
"}\n"
18891990
"\n"
18901991
"\n"
@@ -1896,20 +1997,24 @@
18961997
"}\n"
18971998
);
18981999
}
18992000
19002001
1901
-#ifndef _GNU_SOURCE
1902
-#define _GNU_SOURCE
1903
-#endif
19042002
#include <stdio.h>
19052003
#include <string.h>
19062004
#include <errno.h>
19072005
#include <fcntl.h>
2006
+#include <assert.h>
19082007
#ifdef HAVE_UNISTD_H
19092008
#include <unistd.h>
19102009
#include <sys/stat.h>
2010
+#endif
2011
+#ifdef HAVE_UTIL_H
2012
+#include <util.h>
2013
+#endif
2014
+#ifdef HAVE_PTY_H
2015
+#include <pty.h>
19112016
#endif
19122017
19132018
19142019
#if defined(HAVE_SYS_SOCKET_H) && defined(HAVE_SELECT) && defined(HAVE_NETINET_IN_H) && defined(HAVE_NETDB_H) && defined(HAVE_ARPA_INET_H)
19152020
#include <sys/socket.h>
@@ -1921,12 +2026,10 @@
19212026
#include <sys/un.h>
19222027
#endif
19232028
#define HAVE_SOCKETS
19242029
#elif defined (__MINGW32__)
19252030
1926
-#else
1927
-#define JIM_ANSIC
19282031
#endif
19292032
19302033
#if defined(JIM_SSL)
19312034
#include <openssl/ssl.h>
19322035
#include <openssl/err.h>
@@ -1936,98 +2039,136 @@
19362039
#endif
19372040
19382041
19392042
#define AIO_CMD_LEN 32
19402043
#define AIO_BUF_LEN 256
1941
-
1942
-#ifndef HAVE_FTELLO
1943
- #define ftello ftell
1944
-#endif
1945
-#ifndef HAVE_FSEEKO
1946
- #define fseeko fseek
1947
-#endif
2044
+#define AIO_WBUF_FULL_SIZE (64 * 1024)
19482045
19492046
#define AIO_KEEPOPEN 1
2047
+#define AIO_NODELETE 2
2048
+#define AIO_EOF 4
2049
+#define AIO_WBUF_NONE 8
2050
+#define AIO_NONBLOCK 16
2051
+
2052
+enum wbuftype {
2053
+ WBUF_OPT_NONE,
2054
+ WBUF_OPT_LINE,
2055
+ WBUF_OPT_FULL,
2056
+};
19502057
19512058
#if defined(JIM_IPV6)
19522059
#define IPV6 1
19532060
#else
19542061
#define IPV6 0
19552062
#ifndef PF_INET6
19562063
#define PF_INET6 0
19572064
#endif
19582065
#endif
2066
+#if defined(HAVE_SYS_UN_H) && defined(PF_UNIX)
2067
+#define UNIX_SOCKETS 1
2068
+#else
2069
+#define UNIX_SOCKETS 0
2070
+#endif
19592071
1960
-#ifdef JIM_ANSIC
2072
+#ifndef MAXPATHLEN
2073
+#define MAXPATHLEN JIM_PATH_LEN
2074
+#endif
19612075
1962
-#undef HAVE_PIPE
1963
-#undef HAVE_SOCKETPAIR
2076
+
2077
+
2078
+
2079
+static int JimReadableTimeout(int fd, long ms)
2080
+{
2081
+#ifdef HAVE_SELECT
2082
+ int retval;
2083
+ struct timeval tv;
2084
+ fd_set rfds;
2085
+
2086
+ FD_ZERO(&rfds);
2087
+
2088
+ FD_SET(fd, &rfds);
2089
+ tv.tv_sec = ms / 1000;
2090
+ tv.tv_usec = (ms % 1000) * 1000;
2091
+
2092
+ retval = select(fd + 1, &rfds, NULL, NULL, ms == 0 ? NULL : &tv);
2093
+
2094
+ if (retval > 0) {
2095
+ return JIM_OK;
2096
+ }
2097
+ return JIM_ERR;
2098
+#else
2099
+ return JIM_OK;
19642100
#endif
2101
+}
19652102
19662103
19672104
struct AioFile;
19682105
19692106
typedef struct {
19702107
int (*writer)(struct AioFile *af, const char *buf, int len);
1971
- int (*reader)(struct AioFile *af, char *buf, int len);
1972
- const char *(*getline)(struct AioFile *af, char *buf, int len);
2108
+ int (*reader)(struct AioFile *af, char *buf, int len, int pending);
19732109
int (*error)(const struct AioFile *af);
19742110
const char *(*strerror)(struct AioFile *af);
19752111
int (*verify)(struct AioFile *af);
19762112
} JimAioFopsType;
19772113
19782114
typedef struct AioFile
19792115
{
1980
- FILE *fp;
19812116
Jim_Obj *filename;
1982
- int type;
1983
- int openFlags;
2117
+ int wbuft;
2118
+ int flags;
2119
+ long timeout;
19842120
int fd;
1985
- Jim_Obj *rEvent;
1986
- Jim_Obj *wEvent;
1987
- Jim_Obj *eEvent;
19882121
int addr_family;
19892122
void *ssl;
19902123
const JimAioFopsType *fops;
2124
+ Jim_Obj *readbuf;
2125
+ Jim_Obj *writebuf;
19912126
} AioFile;
19922127
19932128
static int stdio_writer(struct AioFile *af, const char *buf, int len)
19942129
{
1995
- return fwrite(buf, 1, len, af->fp);
2130
+ return write(af->fd, buf, len);
19962131
}
19972132
1998
-static int stdio_reader(struct AioFile *af, char *buf, int len)
1999
-{
2000
- return fread(buf, 1, len, af->fp);
2001
-}
2002
-
2003
-static const char *stdio_getline(struct AioFile *af, char *buf, int len)
2004
-{
2005
- return fgets(buf, len, af->fp);
2133
+static int stdio_reader(struct AioFile *af, char *buf, int len, int nb)
2134
+{
2135
+ if (nb || af->timeout == 0 || JimReadableTimeout(af->fd, af->timeout) == JIM_OK) {
2136
+
2137
+ int ret;
2138
+
2139
+ errno = 0;
2140
+ ret = read(af->fd, buf, len);
2141
+ if (ret <= 0 && errno != EAGAIN && errno != EINTR) {
2142
+ af->flags |= AIO_EOF;
2143
+ }
2144
+ return ret;
2145
+ }
2146
+ errno = ETIMEDOUT;
2147
+ return -1;
20062148
}
20072149
20082150
static int stdio_error(const AioFile *af)
20092151
{
2010
- if (!ferror(af->fp)) {
2152
+ if (af->flags & AIO_EOF) {
20112153
return JIM_OK;
20122154
}
2013
- clearerr(af->fp);
20142155
2015
- if (feof(af->fp) || errno == EAGAIN || errno == EINTR) {
2016
- return JIM_OK;
2017
- }
2156
+ switch (errno) {
2157
+ case EAGAIN:
2158
+ case EINTR:
2159
+ case ETIMEDOUT:
20182160
#ifdef ECONNRESET
2019
- if (errno == ECONNRESET) {
2020
- return JIM_OK;
2021
- }
2161
+ case ECONNRESET:
20222162
#endif
20232163
#ifdef ECONNABORTED
2024
- if (errno == ECONNABORTED) {
2025
- return JIM_OK;
2164
+ case ECONNABORTED:
2165
+#endif
2166
+ return JIM_OK;
2167
+ default:
2168
+ return JIM_ERR;
20262169
}
2027
-#endif
2028
- return JIM_ERR;
20292170
}
20302171
20312172
static const char *stdio_strerror(struct AioFile *af)
20322173
{
20332174
return strerror(errno);
@@ -2034,20 +2175,47 @@
20342175
}
20352176
20362177
static const JimAioFopsType stdio_fops = {
20372178
stdio_writer,
20382179
stdio_reader,
2039
- stdio_getline,
20402180
stdio_error,
20412181
stdio_strerror,
2042
- NULL
2182
+ NULL,
20432183
};
20442184
2185
+
2186
+static void aio_set_nonblocking(AioFile *af, int nb)
2187
+{
2188
+#ifdef O_NDELAY
2189
+ int old = !!(af->flags & AIO_NONBLOCK);
2190
+ if (old != nb) {
2191
+ int fmode = fcntl(af->fd, F_GETFL);
2192
+ if (nb) {
2193
+ fmode |= O_NDELAY;
2194
+ af->flags |= AIO_NONBLOCK;
2195
+ }
2196
+ else {
2197
+ fmode &= ~O_NDELAY;
2198
+ af->flags &= ~AIO_NONBLOCK;
2199
+ }
2200
+ (void)fcntl(af->fd, F_SETFL, fmode);
2201
+ }
2202
+#endif
2203
+}
2204
+
2205
+static int aio_start_nonblocking(AioFile *af)
2206
+{
2207
+ int old = !!(af->flags & AIO_NONBLOCK);
2208
+ if (af->timeout) {
2209
+ aio_set_nonblocking(af, 1);
2210
+ }
2211
+ return old;
2212
+}
20452213
20462214
static int JimAioSubCmdProc(Jim_Interp *interp, int argc, Jim_Obj *const *argv);
2047
-static AioFile *JimMakeChannel(Jim_Interp *interp, FILE *fh, int fd, Jim_Obj *filename,
2048
- const char *hdlfmt, int family, const char *mode);
2215
+static AioFile *JimMakeChannel(Jim_Interp *interp, int fd, Jim_Obj *filename,
2216
+ const char *hdlfmt, int family, int flags);
20492217
20502218
20512219
static const char *JimAioErrorString(AioFile *af)
20522220
{
20532221
if (af && af->fops)
@@ -2065,26 +2233,171 @@
20652233
}
20662234
else {
20672235
Jim_SetResultString(interp, JimAioErrorString(af), -1);
20682236
}
20692237
}
2238
+
2239
+static int aio_eof(AioFile *af)
2240
+{
2241
+ return af->flags & AIO_EOF;
2242
+}
20702243
20712244
static int JimCheckStreamError(Jim_Interp *interp, AioFile *af)
20722245
{
2073
- int ret = af->fops->error(af);
2074
- if (ret) {
2075
- JimAioSetError(interp, af->filename);
2076
- }
2077
- return ret;
2246
+ int ret = 0;
2247
+ if (!aio_eof(af)) {
2248
+ ret = af->fops->error(af);
2249
+ if (ret) {
2250
+ JimAioSetError(interp, af->filename);
2251
+ }
2252
+ }
2253
+ return ret;
2254
+}
2255
+
2256
+static void aio_consume(Jim_Obj *objPtr, int n)
2257
+{
2258
+ assert(objPtr->bytes);
2259
+ assert(n <= objPtr->length);
2260
+
2261
+
2262
+ memmove(objPtr->bytes, objPtr->bytes + n, objPtr->length - n + 1);
2263
+ objPtr->length -= n;
2264
+}
2265
+
2266
+
2267
+static int aio_autoflush(Jim_Interp *interp, void *clientData, int mask);
2268
+
2269
+static int aio_flush(Jim_Interp *interp, AioFile *af)
2270
+{
2271
+ int len;
2272
+ const char *pt = Jim_GetString(af->writebuf, &len);
2273
+ if (len) {
2274
+ int ret = af->fops->writer(af, pt, len);
2275
+ if (ret > 0) {
2276
+
2277
+ aio_consume(af->writebuf, ret);
2278
+ }
2279
+ if (ret < 0) {
2280
+ return JimCheckStreamError(interp, af);
2281
+ }
2282
+ if (Jim_Length(af->writebuf)) {
2283
+#ifdef jim_ext_eventloop
2284
+ void *handler = Jim_FindFileHandler(interp, af->fd, JIM_EVENT_WRITABLE);
2285
+ if (handler == NULL) {
2286
+ Jim_CreateFileHandler(interp, af->fd, JIM_EVENT_WRITABLE, aio_autoflush, af, NULL);
2287
+ return JIM_OK;
2288
+ }
2289
+ else if (handler == af) {
2290
+
2291
+ return JIM_OK;
2292
+ }
2293
+#endif
2294
+
2295
+ Jim_SetResultString(interp, "send buffer is full", -1);
2296
+ return JIM_ERR;
2297
+ }
2298
+ }
2299
+ return JIM_OK;
2300
+}
2301
+
2302
+static int aio_autoflush(Jim_Interp *interp, void *clientData, int mask)
2303
+{
2304
+ AioFile *af = clientData;
2305
+
2306
+ aio_flush(interp, af);
2307
+ if (Jim_Length(af->writebuf) == 0) {
2308
+
2309
+ return -1;
2310
+ }
2311
+ return 0;
2312
+}
2313
+
2314
+static int aio_read_len(Jim_Interp *interp, AioFile *af, int nb, char *buf, size_t buflen, int neededLen)
2315
+{
2316
+ if (!af->readbuf) {
2317
+ af->readbuf = Jim_NewStringObj(interp, NULL, 0);
2318
+ }
2319
+
2320
+ if (neededLen >= 0) {
2321
+ neededLen -= Jim_Length(af->readbuf);
2322
+ if (neededLen <= 0) {
2323
+ return JIM_OK;
2324
+ }
2325
+ }
2326
+
2327
+ while (neededLen && !aio_eof(af)) {
2328
+ int retval;
2329
+ int readlen;
2330
+
2331
+ if (neededLen == -1) {
2332
+ readlen = AIO_BUF_LEN;
2333
+ }
2334
+ else {
2335
+ readlen = (neededLen > AIO_BUF_LEN ? AIO_BUF_LEN : neededLen);
2336
+ }
2337
+ retval = af->fops->reader(af, buf, readlen, nb);
2338
+ if (retval > 0) {
2339
+ Jim_AppendString(interp, af->readbuf, buf, retval);
2340
+ if (neededLen != -1) {
2341
+ neededLen -= retval;
2342
+ }
2343
+ continue;
2344
+ }
2345
+ if (JimCheckStreamError(interp, af)) {
2346
+ return JIM_ERR;
2347
+ }
2348
+ if (nb || af->timeout) {
2349
+ return JIM_OK;
2350
+ }
2351
+ }
2352
+
2353
+ return JIM_OK;
2354
+}
2355
+
2356
+static Jim_Obj *aio_read_consume(Jim_Interp *interp, AioFile *af, int neededLen)
2357
+{
2358
+ Jim_Obj *objPtr = NULL;
2359
+
2360
+ if (neededLen < 0 || af->readbuf == NULL || Jim_Length(af->readbuf) <= neededLen) {
2361
+ objPtr = af->readbuf;
2362
+ af->readbuf = NULL;
2363
+ }
2364
+ else if (af->readbuf) {
2365
+
2366
+ int len;
2367
+ const char *pt = Jim_GetString(af->readbuf, &len);
2368
+
2369
+ objPtr = Jim_NewStringObj(interp, pt, neededLen);
2370
+ aio_consume(af->readbuf, neededLen);
2371
+ }
2372
+
2373
+ return objPtr;
20782374
}
20792375
20802376
static void JimAioDelProc(Jim_Interp *interp, void *privData)
20812377
{
20822378
AioFile *af = privData;
20832379
20842380
JIM_NOTUSED(interp);
20852381
2382
+
2383
+ aio_flush(interp, af);
2384
+ Jim_DecrRefCount(interp, af->writebuf);
2385
+
2386
+#if UNIX_SOCKETS
2387
+ if (af->addr_family == PF_UNIX && (af->flags & AIO_NODELETE) == 0) {
2388
+
2389
+ Jim_Obj *filenameObj = aio_sockname(interp, af->fd);
2390
+ if (filenameObj) {
2391
+ if (Jim_Length(filenameObj)) {
2392
+ remove(Jim_String(filenameObj));
2393
+ }
2394
+ Jim_FreeNewObj(interp, filenameObj);
2395
+ }
2396
+ }
2397
+#endif
2398
+
20862399
Jim_DecrRefCount(interp, af->filename);
20872400
20882401
#ifdef jim_ext_eventloop
20892402
20902403
Jim_DeleteFileHandler(interp, af->fd, JIM_EVENT_READABLE | JIM_EVENT_WRITABLE | JIM_EVENT_EXCEPTION);
@@ -2093,144 +2406,180 @@
20932406
#if defined(JIM_SSL)
20942407
if (af->ssl != NULL) {
20952408
SSL_free(af->ssl);
20962409
}
20972410
#endif
2098
- if (!(af->openFlags & AIO_KEEPOPEN)) {
2099
- fclose(af->fp);
2411
+ if (!(af->flags & AIO_KEEPOPEN)) {
2412
+ close(af->fd);
2413
+ }
2414
+ if (af->readbuf) {
2415
+ Jim_FreeNewObj(interp, af->readbuf);
21002416
}
21012417
21022418
Jim_Free(af);
21032419
}
21042420
21052421
static int aio_cmd_read(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
21062422
{
21072423
AioFile *af = Jim_CmdPrivData(interp);
2108
- char buf[AIO_BUF_LEN];
2109
- Jim_Obj *objPtr;
21102424
int nonewline = 0;
21112425
jim_wide neededLen = -1;
2426
+ static const char * const options[] = { "-pending", "-nonewline", NULL };
2427
+ enum { OPT_PENDING, OPT_NONEWLINE };
2428
+ int option;
2429
+ int nb;
2430
+ Jim_Obj *objPtr;
2431
+ char buf[AIO_BUF_LEN];
21122432
2113
- if (argc && Jim_CompareStringImmediate(interp, argv[0], "-nonewline")) {
2114
- nonewline = 1;
2115
- argv++;
2433
+ if (argc) {
2434
+ if (*Jim_String(argv[0]) == '-') {
2435
+ if (Jim_GetEnum(interp, argv[0], options, &option, NULL, JIM_ERRMSG) != JIM_OK) {
2436
+ return JIM_ERR;
2437
+ }
2438
+ switch (option) {
2439
+ case OPT_PENDING:
2440
+
2441
+ break;
2442
+ case OPT_NONEWLINE:
2443
+ nonewline++;
2444
+ break;
2445
+ }
2446
+ }
2447
+ else {
2448
+ if (Jim_GetWide(interp, argv[0], &neededLen) != JIM_OK)
2449
+ return JIM_ERR;
2450
+ if (neededLen < 0) {
2451
+ Jim_SetResultString(interp, "invalid parameter: negative len", -1);
2452
+ return JIM_ERR;
2453
+ }
2454
+ }
21162455
argc--;
2117
- }
2118
- if (argc == 1) {
2119
- if (Jim_GetWide(interp, argv[0], &neededLen) != JIM_OK)
2120
- return JIM_ERR;
2121
- if (neededLen < 0) {
2122
- Jim_SetResultString(interp, "invalid parameter: negative len", -1);
2123
- return JIM_ERR;
2124
- }
2125
- }
2126
- else if (argc) {
2456
+ argv++;
2457
+ }
2458
+ if (argc) {
21272459
return -1;
21282460
}
2129
- objPtr = Jim_NewStringObj(interp, NULL, 0);
2130
- while (neededLen != 0) {
2131
- int retval;
2132
- int readlen;
2133
-
2134
- if (neededLen == -1) {
2135
- readlen = AIO_BUF_LEN;
2136
- }
2137
- else {
2138
- readlen = (neededLen > AIO_BUF_LEN ? AIO_BUF_LEN : neededLen);
2139
- }
2140
- retval = af->fops->reader(af, buf, readlen);
2141
- if (retval > 0) {
2142
- Jim_AppendString(interp, objPtr, buf, retval);
2143
- if (neededLen != -1) {
2144
- neededLen -= retval;
2145
- }
2146
- }
2147
- if (retval != readlen)
2148
- break;
2149
- }
2150
-
2151
- if (JimCheckStreamError(interp, af)) {
2152
- Jim_FreeNewObj(interp, objPtr);
2153
- return JIM_ERR;
2154
- }
2155
- if (nonewline) {
2156
- int len;
2157
- const char *s = Jim_GetString(objPtr, &len);
2158
-
2159
- if (len > 0 && s[len - 1] == '\n') {
2160
- objPtr->length--;
2161
- objPtr->bytes[objPtr->length] = '\0';
2162
- }
2163
- }
2164
- Jim_SetResult(interp, objPtr);
2461
+
2462
+
2463
+ nb = aio_start_nonblocking(af);
2464
+
2465
+ if (aio_read_len(interp, af, nb, buf, sizeof(buf), neededLen) != JIM_OK) {
2466
+ aio_set_nonblocking(af, nb);
2467
+ return JIM_ERR;
2468
+ }
2469
+ objPtr = aio_read_consume(interp, af, neededLen);
2470
+
2471
+ aio_set_nonblocking(af, nb);
2472
+
2473
+ if (objPtr) {
2474
+ if (nonewline) {
2475
+ int len;
2476
+ const char *s = Jim_GetString(objPtr, &len);
2477
+
2478
+ if (len > 0 && s[len - 1] == '\n') {
2479
+ objPtr->length--;
2480
+ objPtr->bytes[objPtr->length] = '\0';
2481
+ }
2482
+ }
2483
+ Jim_SetResult(interp, objPtr);
2484
+ }
2485
+ else {
2486
+ Jim_SetEmptyResult(interp);
2487
+ }
21652488
return JIM_OK;
21662489
}
21672490
2168
-AioFile *Jim_AioFile(Jim_Interp *interp, Jim_Obj *command)
2491
+int Jim_AioFilehandle(Jim_Interp *interp, Jim_Obj *command)
21692492
{
21702493
Jim_Cmd *cmdPtr = Jim_GetCommand(interp, command, JIM_ERRMSG);
21712494
21722495
21732496
if (cmdPtr && !cmdPtr->isproc && cmdPtr->u.native.cmdProc == JimAioSubCmdProc) {
2174
- return (AioFile *) cmdPtr->u.native.privData;
2497
+ return ((AioFile *) cmdPtr->u.native.privData)->fd;
21752498
}
21762499
Jim_SetResultFormatted(interp, "Not a filehandle: \"%#s\"", command);
2177
- return NULL;
2178
-}
2179
-
2180
-FILE *Jim_AioFilehandle(Jim_Interp *interp, Jim_Obj *command)
2181
-{
2182
- AioFile *af;
2183
-
2184
- af = Jim_AioFile(interp, command);
2185
- if (af == NULL) {
2186
- return NULL;
2187
- }
2188
-
2189
- return af->fp;
2500
+ return -1;
21902501
}
21912502
21922503
static int aio_cmd_getfd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
21932504
{
21942505
AioFile *af = Jim_CmdPrivData(interp);
21952506
2196
- fflush(af->fp);
2197
- Jim_SetResultInt(interp, fileno(af->fp));
2507
+
2508
+ aio_flush(interp, af);
2509
+
2510
+ Jim_SetResultInt(interp, af->fd);
21982511
21992512
return JIM_OK;
22002513
}
22012514
22022515
static int aio_cmd_copy(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
22032516
{
22042517
AioFile *af = Jim_CmdPrivData(interp);
22052518
jim_wide count = 0;
22062519
jim_wide maxlen = JIM_WIDE_MAX;
2207
- AioFile *outf = Jim_AioFile(interp, argv[0]);
22082520
2209
- if (outf == NULL) {
2210
- return JIM_ERR;
2211
- }
2521
+ char buf[AIO_BUF_LEN];
2522
+
2523
+ char *bufp = buf;
2524
+ int buflen = sizeof(buf);
2525
+ int ok = 1;
2526
+ Jim_Obj *objv[4];
22122527
22132528
if (argc == 2) {
22142529
if (Jim_GetWide(interp, argv[1], &maxlen) != JIM_OK) {
22152530
return JIM_ERR;
22162531
}
22172532
}
22182533
2534
+ objv[0] = argv[0];
2535
+ objv[1] = Jim_NewStringObj(interp, "flush", -1);
2536
+ if (Jim_EvalObjVector(interp, 2, objv) != JIM_OK) {
2537
+ Jim_SetResultFormatted(interp, "Not a filehandle: \"%#s\"", argv[0]);
2538
+ return JIM_ERR;
2539
+ }
2540
+
2541
+
2542
+ objv[0] = argv[0];
2543
+ objv[1] = Jim_NewStringObj(interp, "puts", -1);
2544
+ objv[2] = Jim_NewStringObj(interp, "-nonewline", -1);
2545
+ Jim_IncrRefCount(objv[1]);
2546
+ Jim_IncrRefCount(objv[2]);
2547
+
22192548
while (count < maxlen) {
2220
- char ch;
2221
-
2222
- if (af->fops->reader(af, &ch, 1) != 1) {
2549
+ jim_wide len = maxlen - count;
2550
+ if (len > buflen) {
2551
+ len = buflen;
2552
+ }
2553
+ if (aio_read_len(interp, af, 0, bufp, buflen, len) != JIM_OK) {
2554
+ ok = 0;
22232555
break;
22242556
}
2225
- if (outf->fops->writer(outf, &ch, 1) != 1) {
2557
+ objv[3] = aio_read_consume(interp, af, len);
2558
+ count += Jim_Length(objv[3]);
2559
+ if (Jim_EvalObjVector(interp, 4, objv) != JIM_OK) {
2560
+ ok = 0;
22262561
break;
22272562
}
2228
- count++;
2563
+ if (aio_eof(af)) {
2564
+ break;
2565
+ }
2566
+ if (count >= 16384 && bufp == buf) {
2567
+
2568
+ buflen = 65536;
2569
+ bufp = Jim_Alloc(buflen);
2570
+ }
22292571
}
22302572
2231
- if (JimCheckStreamError(interp, af) || JimCheckStreamError(interp, outf)) {
2573
+ if (bufp != buf) {
2574
+ Jim_Free(bufp);
2575
+ }
2576
+
2577
+ Jim_DecrRefCount(interp, objv[1]);
2578
+ Jim_DecrRefCount(interp, objv[2]);
2579
+
2580
+ if (!ok) {
22322581
return JIM_ERR;
22332582
}
22342583
22352584
Jim_SetResultInt(interp, count);
22362585
@@ -2239,42 +2588,58 @@
22392588
22402589
static int aio_cmd_gets(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
22412590
{
22422591
AioFile *af = Jim_CmdPrivData(interp);
22432592
char buf[AIO_BUF_LEN];
2244
- Jim_Obj *objPtr;
2593
+ Jim_Obj *objPtr = NULL;
22452594
int len;
2595
+ int nb;
2596
+ char *nl = NULL;
2597
+ int offset = 0;
22462598
22472599
errno = 0;
22482600
2249
- objPtr = Jim_NewStringObj(interp, NULL, 0);
2250
- while (1) {
2251
- buf[AIO_BUF_LEN - 1] = '_';
2252
-
2253
- if (af->fops->getline(af, buf, AIO_BUF_LEN) == NULL)
2254
- break;
2255
-
2256
- if (buf[AIO_BUF_LEN - 1] == '\0' && buf[AIO_BUF_LEN - 2] != '\n') {
2257
- Jim_AppendString(interp, objPtr, buf, AIO_BUF_LEN - 1);
2258
- }
2259
- else {
2260
- len = strlen(buf);
2261
-
2262
- if (len && (buf[len - 1] == '\n')) {
2263
-
2264
- len--;
2265
- }
2266
-
2267
- Jim_AppendString(interp, objPtr, buf, len);
2268
- break;
2269
- }
2270
- }
2271
-
2272
- if (JimCheckStreamError(interp, af)) {
2273
-
2274
- Jim_FreeNewObj(interp, objPtr);
2275
- return JIM_ERR;
2601
+
2602
+ nb = aio_start_nonblocking(af);
2603
+
2604
+ if (!af->readbuf) {
2605
+ af->readbuf = Jim_NewStringObj(interp, NULL, 0);
2606
+ }
2607
+
2608
+ while (!aio_eof(af)) {
2609
+ const char *pt = Jim_GetString(af->readbuf, &len);
2610
+ nl = memchr(pt + offset, '\n', len - offset);
2611
+ if (nl) {
2612
+
2613
+ objPtr = Jim_NewStringObj(interp, pt, nl - pt);
2614
+
2615
+ aio_consume(af->readbuf, nl - pt + 1);
2616
+ break;
2617
+ }
2618
+
2619
+ offset = len;
2620
+ len = af->fops->reader(af, buf, AIO_BUF_LEN, nb);
2621
+ if (len <= 0) {
2622
+ if (nb || af->timeout) {
2623
+
2624
+ break;
2625
+ }
2626
+ }
2627
+ else {
2628
+ Jim_AppendString(interp, af->readbuf, buf, len);
2629
+ }
2630
+ }
2631
+
2632
+ aio_set_nonblocking(af, nb);
2633
+
2634
+ if (!nl && aio_eof(af)) {
2635
+
2636
+ objPtr = af->readbuf;
2637
+ af->readbuf = NULL;
2638
+ }
2639
+ else if (!objPtr) {
2640
+ objPtr = Jim_NewStringObj(interp, NULL, 0);
22762641
}
22772642
22782643
if (argc) {
22792644
if (Jim_SetVariable(interp, argv[0], objPtr) != JIM_OK) {
22802645
Jim_FreeNewObj(interp, objPtr);
@@ -2281,11 +2646,11 @@
22812646
return JIM_ERR;
22822647
}
22832648
22842649
len = Jim_Length(objPtr);
22852650
2286
- if (len == 0 && feof(af->fp)) {
2651
+ if (!nl && len == 0) {
22872652
22882653
len = -1;
22892654
}
22902655
Jim_SetResultInt(interp, len);
22912656
}
@@ -2299,36 +2664,62 @@
22992664
{
23002665
AioFile *af = Jim_CmdPrivData(interp);
23012666
int wlen;
23022667
const char *wdata;
23032668
Jim_Obj *strObj;
2669
+ int wnow = 0;
2670
+ int nl = 1;
23042671
23052672
if (argc == 2) {
23062673
if (!Jim_CompareStringImmediate(interp, argv[0], "-nonewline")) {
23072674
return -1;
23082675
}
23092676
strObj = argv[1];
2677
+ nl = 0;
23102678
}
23112679
else {
23122680
strObj = argv[0];
23132681
}
23142682
2315
- wdata = Jim_GetString(strObj, &wlen);
2316
- if (af->fops->writer(af, wdata, wlen) == wlen) {
2317
- if (argc == 2 || af->fops->writer(af, "\n", 1) == 1) {
2318
- return JIM_OK;
2319
- }
2320
- }
2321
- JimAioSetError(interp, af->filename);
2322
- return JIM_ERR;
2683
+ Jim_AppendObj(interp, af->writebuf, strObj);
2684
+ if (nl) {
2685
+ Jim_AppendString(interp, af->writebuf, "\n", 1);
2686
+ }
2687
+
2688
+
2689
+ wdata = Jim_GetString(af->writebuf, &wlen);
2690
+ switch (af->wbuft) {
2691
+ case WBUF_OPT_NONE:
2692
+
2693
+ wnow = 1;
2694
+ break;
2695
+
2696
+ case WBUF_OPT_LINE:
2697
+
2698
+ if (nl || memchr(wdata, '\n', wlen) != NULL) {
2699
+ wnow = 1;
2700
+ }
2701
+ break;
2702
+
2703
+ case WBUF_OPT_FULL:
2704
+ if (wlen >= AIO_WBUF_FULL_SIZE) {
2705
+ wnow = 1;
2706
+ }
2707
+ break;
2708
+ }
2709
+
2710
+ if (wnow) {
2711
+ return aio_flush(interp, af);
2712
+ }
2713
+ return JIM_OK;
23232714
}
23242715
23252716
static int aio_cmd_isatty(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
23262717
{
23272718
#ifdef HAVE_ISATTY
23282719
AioFile *af = Jim_CmdPrivData(interp);
2329
- Jim_SetResultInt(interp, isatty(fileno(af->fp)));
2720
+ Jim_SetResultInt(interp, isatty(af->fd));
23302721
#else
23312722
Jim_SetResultInt(interp, 0);
23322723
#endif
23332724
23342725
return JIM_OK;
@@ -2336,49 +2727,62 @@
23362727
23372728
23382729
static int aio_cmd_flush(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
23392730
{
23402731
AioFile *af = Jim_CmdPrivData(interp);
2341
-
2342
- if (fflush(af->fp) == EOF) {
2343
- JimAioSetError(interp, af->filename);
2344
- return JIM_ERR;
2345
- }
2346
- return JIM_OK;
2732
+ return aio_flush(interp, af);
23472733
}
23482734
23492735
static int aio_cmd_eof(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
23502736
{
23512737
AioFile *af = Jim_CmdPrivData(interp);
23522738
2353
- Jim_SetResultInt(interp, feof(af->fp));
2739
+ Jim_SetResultInt(interp, !!aio_eof(af));
23542740
return JIM_OK;
23552741
}
23562742
23572743
static int aio_cmd_close(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
23582744
{
2745
+ AioFile *af = Jim_CmdPrivData(interp);
23592746
if (argc == 3) {
2360
-#if defined(HAVE_SOCKETS) && defined(HAVE_SHUTDOWN)
2361
- static const char * const options[] = { "r", "w", NULL };
2362
- enum { OPT_R, OPT_W, };
2363
- int option;
2364
- AioFile *af = Jim_CmdPrivData(interp);
2747
+ int option = -1;
2748
+#if defined(HAVE_SOCKETS)
2749
+ static const char * const options[] = { "r", "w", "-nodelete", NULL };
2750
+ enum { OPT_R, OPT_W, OPT_NODELETE };
23652751
23662752
if (Jim_GetEnum(interp, argv[2], options, &option, NULL, JIM_ERRMSG) != JIM_OK) {
23672753
return JIM_ERR;
23682754
}
2369
- if (shutdown(af->fd, option == OPT_R ? SHUT_RD : SHUT_WR) == 0) {
2370
- return JIM_OK;
2371
- }
2372
- JimAioSetError(interp, NULL);
2373
-#else
2374
- Jim_SetResultString(interp, "async close not supported", -1);
2375
-#endif
2376
- return JIM_ERR;
2755
+#endif
2756
+ switch (option) {
2757
+#if defined(HAVE_SHUTDOWN)
2758
+ case OPT_R:
2759
+ case OPT_W:
2760
+ if (shutdown(af->fd, option == OPT_R ? SHUT_RD : SHUT_WR) == 0) {
2761
+ return JIM_OK;
2762
+ }
2763
+ JimAioSetError(interp, NULL);
2764
+ return JIM_ERR;
2765
+#endif
2766
+#if UNIX_SOCKETS
2767
+ case OPT_NODELETE:
2768
+ if (af->addr_family == PF_UNIX) {
2769
+ af->flags |= AIO_NODELETE;
2770
+ break;
2771
+ }
2772
+
2773
+#endif
2774
+ default:
2775
+ Jim_SetResultString(interp, "not supported", -1);
2776
+ return JIM_ERR;
2777
+ }
23772778
}
23782779
2379
- return Jim_DeleteCommand(interp, Jim_String(argv[0]));
2780
+
2781
+ af->flags &= ~AIO_KEEPOPEN;
2782
+
2783
+ return Jim_DeleteCommand(interp, argv[0]);
23802784
}
23812785
23822786
static int aio_cmd_seek(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
23832787
{
23842788
AioFile *af = Jim_CmdPrivData(interp);
@@ -2397,22 +2801,31 @@
23972801
}
23982802
}
23992803
if (Jim_GetWide(interp, argv[0], &offset) != JIM_OK) {
24002804
return JIM_ERR;
24012805
}
2402
- if (fseeko(af->fp, offset, orig) == -1) {
2806
+ if (orig != SEEK_CUR || offset != 0) {
2807
+
2808
+ aio_flush(interp, af);
2809
+ }
2810
+ if (Jim_Lseek(af->fd, offset, orig) == -1) {
24032811
JimAioSetError(interp, af->filename);
24042812
return JIM_ERR;
24052813
}
2814
+ if (af->readbuf) {
2815
+ Jim_FreeNewObj(interp, af->readbuf);
2816
+ af->readbuf = NULL;
2817
+ }
2818
+ af->flags &= ~AIO_EOF;
24062819
return JIM_OK;
24072820
}
24082821
24092822
static int aio_cmd_tell(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
24102823
{
24112824
AioFile *af = Jim_CmdPrivData(interp);
24122825
2413
- Jim_SetResultInt(interp, ftello(af->fp));
2826
+ Jim_SetResultInt(interp, Jim_Lseek(af->fd, 0, SEEK_CUR));
24142827
return JIM_OK;
24152828
}
24162829
24172830
static int aio_cmd_filename(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
24182831
{
@@ -2425,27 +2838,19 @@
24252838
#ifdef O_NDELAY
24262839
static int aio_cmd_ndelay(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
24272840
{
24282841
AioFile *af = Jim_CmdPrivData(interp);
24292842
2430
- int fmode = fcntl(af->fd, F_GETFL);
2431
-
24322843
if (argc) {
24332844
long nb;
24342845
24352846
if (Jim_GetLong(interp, argv[0], &nb) != JIM_OK) {
24362847
return JIM_ERR;
24372848
}
2438
- if (nb) {
2439
- fmode |= O_NDELAY;
2440
- }
2441
- else {
2442
- fmode &= ~O_NDELAY;
2443
- }
2444
- (void)fcntl(af->fd, F_SETFL, fmode);
2445
- }
2446
- Jim_SetResultInt(interp, (fmode & O_NONBLOCK) ? 1 : 0);
2849
+ aio_set_nonblocking(af, nb);
2850
+ }
2851
+ Jim_SetResultInt(interp, (af->flags & AIO_NONBLOCK) ? 1 : 0);
24472852
return JIM_OK;
24482853
}
24492854
#endif
24502855
24512856
@@ -2452,11 +2857,13 @@
24522857
#ifdef HAVE_FSYNC
24532858
static int aio_cmd_sync(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
24542859
{
24552860
AioFile *af = Jim_CmdPrivData(interp);
24562861
2457
- fflush(af->fp);
2862
+ if (aio_flush(interp, af) != JIM_OK) {
2863
+ return JIM_ERR;
2864
+ }
24582865
fsync(af->fd);
24592866
return JIM_OK;
24602867
}
24612868
#endif
24622869
@@ -2468,111 +2875,105 @@
24682875
"none",
24692876
"line",
24702877
"full",
24712878
NULL
24722879
};
2473
- enum
2474
- {
2475
- OPT_NONE,
2476
- OPT_LINE,
2477
- OPT_FULL,
2478
- };
2479
- int option;
2480
-
2481
- if (Jim_GetEnum(interp, argv[0], options, &option, NULL, JIM_ERRMSG) != JIM_OK) {
2880
+
2881
+ if (Jim_GetEnum(interp, argv[0], options, &af->wbuft, NULL, JIM_ERRMSG) != JIM_OK) {
24822882
return JIM_ERR;
24832883
}
2484
- switch (option) {
2485
- case OPT_NONE:
2486
- setvbuf(af->fp, NULL, _IONBF, 0);
2487
- break;
2488
- case OPT_LINE:
2489
- setvbuf(af->fp, NULL, _IOLBF, BUFSIZ);
2490
- break;
2491
- case OPT_FULL:
2492
- setvbuf(af->fp, NULL, _IOFBF, BUFSIZ);
2493
- break;
2494
- }
2495
- return JIM_OK;
2884
+
2885
+ if (af->wbuft == WBUF_OPT_NONE) {
2886
+ return aio_flush(interp, af);
2887
+ }
2888
+
2889
+ return JIM_OK;
2890
+}
2891
+
2892
+static int aio_cmd_timeout(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
2893
+{
2894
+#ifdef HAVE_SELECT
2895
+ AioFile *af = Jim_CmdPrivData(interp);
2896
+ if (argc == 1) {
2897
+ if (Jim_GetLong(interp, argv[0], &af->timeout) != JIM_OK) {
2898
+ return JIM_ERR;
2899
+ }
2900
+ }
2901
+ Jim_SetResultInt(interp, af->timeout);
2902
+ return JIM_OK;
2903
+#else
2904
+ Jim_SetResultString(interp, "timeout not supported", -1);
2905
+ return JIM_ERR;
2906
+#endif
24962907
}
24972908
24982909
#ifdef jim_ext_eventloop
2499
-static void JimAioFileEventFinalizer(Jim_Interp *interp, void *clientData)
2500
-{
2501
- Jim_Obj **objPtrPtr = clientData;
2502
-
2503
- Jim_DecrRefCount(interp, *objPtrPtr);
2504
- *objPtrPtr = NULL;
2505
-}
2506
-
2507
-static int JimAioFileEventHandler(Jim_Interp *interp, void *clientData, int mask)
2508
-{
2509
- Jim_Obj **objPtrPtr = clientData;
2510
-
2511
- return Jim_EvalObjBackground(interp, *objPtrPtr);
2512
-}
2513
-
2514
-static int aio_eventinfo(Jim_Interp *interp, AioFile * af, unsigned mask, Jim_Obj **scriptHandlerObj,
2910
+static int aio_eventinfo(Jim_Interp *interp, AioFile * af, unsigned mask,
25152911
int argc, Jim_Obj * const *argv)
25162912
{
25172913
if (argc == 0) {
25182914
2519
- if (*scriptHandlerObj) {
2520
- Jim_SetResult(interp, *scriptHandlerObj);
2915
+ Jim_Obj *objPtr = Jim_FindFileHandler(interp, af->fd, mask);
2916
+ if (objPtr) {
2917
+ Jim_SetResult(interp, objPtr);
25212918
}
25222919
return JIM_OK;
25232920
}
25242921
2525
- if (*scriptHandlerObj) {
2526
-
2527
- Jim_DeleteFileHandler(interp, af->fd, mask);
2528
- }
2529
-
2530
-
2531
- if (Jim_Length(argv[0]) == 0) {
2532
-
2533
- return JIM_OK;
2534
- }
2535
-
2536
-
2537
- Jim_IncrRefCount(argv[0]);
2538
- *scriptHandlerObj = argv[0];
2539
-
2540
- Jim_CreateFileHandler(interp, af->fd, mask,
2541
- JimAioFileEventHandler, scriptHandlerObj, JimAioFileEventFinalizer);
2922
+
2923
+ Jim_DeleteFileHandler(interp, af->fd, mask);
2924
+
2925
+
2926
+ if (Jim_Length(argv[0])) {
2927
+ Jim_CreateScriptFileHandler(interp, af->fd, mask, argv[0]);
2928
+ }
25422929
25432930
return JIM_OK;
25442931
}
25452932
25462933
static int aio_cmd_readable(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
25472934
{
25482935
AioFile *af = Jim_CmdPrivData(interp);
25492936
2550
- return aio_eventinfo(interp, af, JIM_EVENT_READABLE, &af->rEvent, argc, argv);
2937
+ return aio_eventinfo(interp, af, JIM_EVENT_READABLE, argc, argv);
25512938
}
25522939
25532940
static int aio_cmd_writable(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
25542941
{
25552942
AioFile *af = Jim_CmdPrivData(interp);
25562943
2557
- return aio_eventinfo(interp, af, JIM_EVENT_WRITABLE, &af->wEvent, argc, argv);
2944
+ return aio_eventinfo(interp, af, JIM_EVENT_WRITABLE, argc, argv);
25582945
}
25592946
25602947
static int aio_cmd_onexception(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
25612948
{
25622949
AioFile *af = Jim_CmdPrivData(interp);
25632950
2564
- return aio_eventinfo(interp, af, JIM_EVENT_EXCEPTION, &af->eEvent, argc, argv);
2951
+ return aio_eventinfo(interp, af, JIM_EVENT_EXCEPTION, argc, argv);
2952
+}
2953
+#endif
2954
+
2955
+#if defined(jim_ext_file) && defined(Jim_FileStat)
2956
+static int aio_cmd_stat(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
2957
+{
2958
+ jim_stat_t sb;
2959
+ AioFile *af = Jim_CmdPrivData(interp);
2960
+
2961
+ if (Jim_FileStat(af->fd, &sb) == -1) {
2962
+ JimAioSetError(interp, NULL);
2963
+ return JIM_ERR;
2964
+ }
2965
+ return Jim_FileStoreStatData(interp, argc == 0 ? NULL : argv[0], &sb);
25652966
}
25662967
#endif
25672968
25682969
25692970
25702971
25712972
static const jim_subcmd_type aio_command_table[] = {
25722973
{ "read",
2573
- "?-nonewline? ?len?",
2974
+ "?-nonewline|len?",
25742975
aio_cmd_read,
25752976
0,
25762977
2,
25772978
25782979
},
@@ -2677,10 +3078,19 @@
26773078
aio_cmd_buffering,
26783079
1,
26793080
1,
26803081
26813082
},
3083
+#if defined(jim_ext_file) && defined(Jim_FileStat)
3084
+ { "stat",
3085
+ "?var?",
3086
+ aio_cmd_stat,
3087
+ 0,
3088
+ 1,
3089
+
3090
+ },
3091
+#endif
26823092
#ifdef jim_ext_eventloop
26833093
{ "readable",
26843094
"?readable-script?",
26853095
aio_cmd_readable,
26863096
0,
@@ -2698,126 +3108,235 @@
26983108
"?exception-script?",
26993109
aio_cmd_onexception,
27003110
0,
27013111
1,
27023112
3113
+ },
3114
+ { "timeout",
3115
+ "?ms?",
3116
+ aio_cmd_timeout,
3117
+ 0,
3118
+ 1,
3119
+
27033120
},
27043121
#endif
27053122
{ NULL }
27063123
};
27073124
27083125
static int JimAioSubCmdProc(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
27093126
{
27103127
return Jim_CallSubCmd(interp, Jim_ParseSubCmd(interp, aio_command_table, argc, argv), argc, argv);
27113128
}
3129
+
3130
+static int parse_posix_open_mode(Jim_Interp *interp, Jim_Obj *modeObj)
3131
+{
3132
+ int i;
3133
+ int flags = 0;
3134
+ #ifndef O_NOCTTY
3135
+
3136
+ #define O_NOCTTY 0
3137
+ #endif
3138
+ static const char * const modetypes[] = {
3139
+ "RDONLY", "WRONLY", "RDWR", "APPEND", "BINARY", "CREAT", "EXCL", "NOCTTY", "TRUNC", NULL
3140
+ };
3141
+ static const int modeflags[] = {
3142
+ O_RDONLY, O_WRONLY, O_RDWR, O_APPEND, 0, O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC,
3143
+ };
3144
+
3145
+ for (i = 0; i < Jim_ListLength(interp, modeObj); i++) {
3146
+ int opt;
3147
+ Jim_Obj *objPtr = Jim_ListGetIndex(interp, modeObj, i);
3148
+ if (Jim_GetEnum(interp, objPtr, modetypes, &opt, "access mode", JIM_ERRMSG) != JIM_OK) {
3149
+ return -1;
3150
+ }
3151
+ flags |= modeflags[opt];
3152
+ }
3153
+ return flags;
3154
+}
3155
+
3156
+static int parse_open_mode(Jim_Interp *interp, Jim_Obj *filenameObj, Jim_Obj *modeObj)
3157
+{
3158
+
3159
+ int flags;
3160
+ const char *mode = Jim_String(modeObj);
3161
+ if (*mode == 'R' || *mode == 'W') {
3162
+ return parse_posix_open_mode(interp, modeObj);
3163
+ }
3164
+ if (*mode == 'r') {
3165
+ flags = O_RDONLY;
3166
+ }
3167
+ else if (*mode == 'w') {
3168
+ flags = O_WRONLY | O_CREAT | O_TRUNC;
3169
+ }
3170
+ else if (*mode == 'a') {
3171
+ flags = O_WRONLY | O_CREAT | O_APPEND;
3172
+ }
3173
+ else {
3174
+ Jim_SetResultFormatted(interp, "%s: invalid open mode '%s'", Jim_String(filenameObj), mode);
3175
+ return -1;
3176
+ }
3177
+ mode++;
3178
+
3179
+ if (*mode == 'b') {
3180
+#ifdef O_BINARY
3181
+ flags |= O_BINARY;
3182
+#endif
3183
+ mode++;
3184
+ }
3185
+
3186
+ if (*mode == 't') {
3187
+#ifdef O_TEXT
3188
+ flags |= O_TEXT;
3189
+#endif
3190
+ mode++;
3191
+ }
3192
+
3193
+ if (*mode == '+') {
3194
+ mode++;
3195
+
3196
+ flags &= ~(O_RDONLY | O_WRONLY);
3197
+ flags |= O_RDWR;
3198
+ }
3199
+
3200
+ if (*mode == 'x') {
3201
+ mode++;
3202
+#ifdef O_EXCL
3203
+ flags |= O_EXCL;
3204
+#endif
3205
+ }
3206
+
3207
+ if (*mode == 'F') {
3208
+ mode++;
3209
+#ifdef O_LARGEFILE
3210
+ flags |= O_LARGEFILE;
3211
+#endif
3212
+ }
3213
+
3214
+ if (*mode == 'e') {
3215
+
3216
+ mode++;
3217
+ }
3218
+ return flags;
3219
+}
27123220
27133221
static int JimAioOpenCommand(Jim_Interp *interp, int argc,
27143222
Jim_Obj *const *argv)
27153223
{
2716
- const char *mode;
3224
+ int openflags;
3225
+ const char *filename;
3226
+ int fd = -1;
3227
+ int n = 0;
3228
+ int flags = 0;
27173229
2718
- if (argc != 2 && argc != 3) {
2719
- Jim_WrongNumArgs(interp, 1, argv, "filename ?mode?");
3230
+ if (argc > 2 && Jim_CompareStringImmediate(interp, argv[2], "-noclose")) {
3231
+ flags = AIO_KEEPOPEN;
3232
+ n++;
3233
+ }
3234
+ if (argc < 2 || argc > 3 + n) {
3235
+ Jim_WrongNumArgs(interp, 1, argv, "filename ?-noclose? ?mode?");
27203236
return JIM_ERR;
27213237
}
27223238
2723
- mode = (argc == 3) ? Jim_String(argv[2]) : "r";
3239
+ filename = Jim_String(argv[1]);
27243240
27253241
#ifdef jim_ext_tclcompat
27263242
{
2727
- const char *filename = Jim_String(argv[1]);
27283243
27293244
27303245
if (*filename == '|') {
27313246
Jim_Obj *evalObj[3];
3247
+ int i = 0;
27323248
2733
- evalObj[0] = Jim_NewStringObj(interp, "::popen", -1);
2734
- evalObj[1] = Jim_NewStringObj(interp, filename + 1, -1);
2735
- evalObj[2] = Jim_NewStringObj(interp, mode, -1);
3249
+ evalObj[i++] = Jim_NewStringObj(interp, "::popen", -1);
3250
+ evalObj[i++] = Jim_NewStringObj(interp, filename + 1, -1);
3251
+ if (argc == 3 + n) {
3252
+ evalObj[i++] = argv[2 + n];
3253
+ }
27363254
2737
- return Jim_EvalObjVector(interp, 3, evalObj);
3255
+ return Jim_EvalObjVector(interp, i, evalObj);
27383256
}
27393257
}
27403258
#endif
2741
- return JimMakeChannel(interp, NULL, -1, argv[1], "aio.handle%ld", 0, mode) ? JIM_OK : JIM_ERR;
3259
+ if (argc == 3 + n) {
3260
+ openflags = parse_open_mode(interp, argv[1], argv[2 + n]);
3261
+ if (openflags == -1) {
3262
+ return JIM_ERR;
3263
+ }
3264
+ }
3265
+ else {
3266
+ openflags = O_RDONLY;
3267
+ }
3268
+ fd = open(filename, openflags, 0666);
3269
+ if (fd < 0) {
3270
+ JimAioSetError(interp, argv[1]);
3271
+ return JIM_ERR;
3272
+ }
3273
+
3274
+ return JimMakeChannel(interp, fd, argv[1], "aio.handle%ld", 0, flags) ? JIM_OK : JIM_ERR;
27423275
}
27433276
27443277
2745
-static AioFile *JimMakeChannel(Jim_Interp *interp, FILE *fh, int fd, Jim_Obj *filename,
2746
- const char *hdlfmt, int family, const char *mode)
3278
+static AioFile *JimMakeChannel(Jim_Interp *interp, int fd, Jim_Obj *filename,
3279
+ const char *hdlfmt, int family, int flags)
27473280
{
27483281
AioFile *af;
27493282
char buf[AIO_CMD_LEN];
2750
- int openFlags = 0;
2751
-
2752
- snprintf(buf, sizeof(buf), hdlfmt, Jim_GetId(interp));
2753
-
2754
- if (fh) {
2755
- openFlags = AIO_KEEPOPEN;
2756
- }
2757
-
2758
- snprintf(buf, sizeof(buf), hdlfmt, Jim_GetId(interp));
2759
- if (!filename) {
2760
- filename = Jim_NewStringObj(interp, buf, -1);
2761
- }
2762
-
2763
- Jim_IncrRefCount(filename);
2764
-
2765
- if (fh == NULL) {
2766
- if (fd >= 0) {
2767
-#ifndef JIM_ANSIC
2768
- fh = fdopen(fd, mode);
2769
-#endif
2770
- }
2771
- else
2772
- fh = fopen(Jim_String(filename), mode);
2773
-
2774
- if (fh == NULL) {
2775
- JimAioSetError(interp, filename);
2776
-#ifndef JIM_ANSIC
2777
- if (fd >= 0) {
2778
- close(fd);
2779
- }
2780
-#endif
2781
- Jim_DecrRefCount(interp, filename);
2782
- return NULL;
2783
- }
2784
- }
3283
+ Jim_Obj *cmdname;
3284
+
3285
+ snprintf(buf, sizeof(buf), hdlfmt, Jim_GetId(interp));
3286
+ cmdname = Jim_NewStringObj(interp, buf, -1);
3287
+ if (!filename) {
3288
+ filename = cmdname;
3289
+ }
3290
+ Jim_IncrRefCount(filename);
27853291
27863292
27873293
af = Jim_Alloc(sizeof(*af));
27883294
memset(af, 0, sizeof(*af));
2789
- af->fp = fh;
27903295
af->filename = filename;
2791
- af->openFlags = openFlags;
2792
-#ifndef JIM_ANSIC
2793
- af->fd = fileno(fh);
3296
+ af->fd = fd;
3297
+ af->addr_family = family;
3298
+ af->fops = &stdio_fops;
3299
+ af->ssl = NULL;
3300
+ if (flags & AIO_WBUF_NONE) {
3301
+ af->wbuft = WBUF_OPT_NONE;
3302
+ }
3303
+ else {
3304
+#ifdef HAVE_ISATTY
3305
+ af->wbuft = isatty(af->fd) ? WBUF_OPT_LINE : WBUF_OPT_FULL;
3306
+#else
3307
+ af->wbuft = WBUF_OPT_FULL;
3308
+#endif
3309
+ }
3310
+
27943311
#ifdef FD_CLOEXEC
2795
- if ((openFlags & AIO_KEEPOPEN) == 0) {
3312
+ if ((flags & AIO_KEEPOPEN) == 0) {
27963313
(void)fcntl(af->fd, F_SETFD, FD_CLOEXEC);
27973314
}
27983315
#endif
2799
-#endif
2800
- af->addr_family = family;
2801
- af->fops = &stdio_fops;
2802
- af->ssl = NULL;
3316
+ aio_set_nonblocking(af, !!(flags & AIO_NONBLOCK));
3317
+
3318
+ af->flags |= flags;
3319
+
3320
+ af->writebuf = Jim_NewStringObj(interp, NULL, 0);
3321
+ Jim_IncrRefCount(af->writebuf);
28033322
28043323
Jim_CreateCommand(interp, buf, JimAioSubCmdProc, af, JimAioDelProc);
28053324
2806
- Jim_SetResult(interp, Jim_MakeGlobalNamespaceName(interp, Jim_NewStringObj(interp, buf, -1)));
3325
+ Jim_SetResult(interp, Jim_MakeGlobalNamespaceName(interp, cmdname));
28073326
28083327
return af;
28093328
}
28103329
2811
-#if defined(HAVE_PIPE) || (defined(HAVE_SOCKETPAIR) && defined(HAVE_SYS_UN_H))
3330
+#if defined(HAVE_PIPE) || (defined(HAVE_SOCKETPAIR) && UNIX_SOCKETS) || defined(HAVE_OPENPTY)
28123331
static int JimMakeChannelPair(Jim_Interp *interp, int p[2], Jim_Obj *filename,
2813
- const char *hdlfmt, int family, const char *mode[2])
3332
+ const char *hdlfmt, int family, int flags)
28143333
{
2815
- if (JimMakeChannel(interp, NULL, p[0], filename, hdlfmt, family, mode[0])) {
3334
+ if (JimMakeChannel(interp, p[0], filename, hdlfmt, family, flags)) {
28163335
Jim_Obj *objPtr = Jim_NewListObj(interp, NULL, 0);
28173336
Jim_ListAppendElement(interp, objPtr, Jim_GetResult(interp));
2818
- if (JimMakeChannel(interp, NULL, p[1], filename, hdlfmt, family, mode[1])) {
3337
+ if (JimMakeChannel(interp, p[1], filename, hdlfmt, family, flags)) {
28193338
Jim_ListAppendElement(interp, objPtr, Jim_GetResult(interp));
28203339
Jim_SetResult(interp, objPtr);
28213340
return JIM_OK;
28223341
}
28233342
}
@@ -2829,26 +3348,52 @@
28293348
return JIM_ERR;
28303349
}
28313350
#endif
28323351
28333352
#ifdef HAVE_PIPE
2834
-static int JimAioPipeCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
3353
+static int JimCreatePipe(Jim_Interp *interp, Jim_Obj *filenameObj, int flags)
28353354
{
28363355
int p[2];
2837
- static const char *mode[2] = { "r", "w" };
2838
-
2839
- if (argc != 1) {
2840
- Jim_WrongNumArgs(interp, 1, argv, "");
2841
- return JIM_ERR;
2842
- }
28433356
28443357
if (pipe(p) != 0) {
28453358
JimAioSetError(interp, NULL);
28463359
return JIM_ERR;
28473360
}
28483361
2849
- return JimMakeChannelPair(interp, p, argv[0], "aio.pipe%ld", 0, mode);
3362
+ return JimMakeChannelPair(interp, p, filenameObj, "aio.pipe%ld", 0, flags);
3363
+}
3364
+
3365
+
3366
+static int JimAioPipeCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
3367
+{
3368
+ if (argc != 1) {
3369
+ Jim_WrongNumArgs(interp, 1, argv, "");
3370
+ return JIM_ERR;
3371
+ }
3372
+ return JimCreatePipe(interp, argv[0], 0);
3373
+}
3374
+#endif
3375
+
3376
+#ifdef HAVE_OPENPTY
3377
+static int JimAioOpenPtyCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
3378
+{
3379
+ int p[2];
3380
+ char path[MAXPATHLEN];
3381
+
3382
+ if (argc != 1) {
3383
+ Jim_WrongNumArgs(interp, 1, argv, "");
3384
+ return JIM_ERR;
3385
+ }
3386
+
3387
+ if (openpty(&p[0], &p[1], path, NULL, NULL) != 0) {
3388
+ JimAioSetError(interp, NULL);
3389
+ return JIM_ERR;
3390
+ }
3391
+
3392
+
3393
+ return JimMakeChannelPair(interp, p, Jim_NewStringObj(interp, path, -1), "aio.pty%ld", 0, 0);
3394
+ return JimMakeChannelPair(interp, p, Jim_NewStringObj(interp, path, -1), "aio.pty%ld", 0, 0);
28503395
}
28513396
#endif
28523397
28533398
28543399
@@ -2868,13 +3413,13 @@
28683413
#ifdef HAVE_PIPE
28693414
Jim_CreateCommand(interp, "pipe", JimAioPipeCommand, NULL, NULL);
28703415
#endif
28713416
28723417
2873
- JimMakeChannel(interp, stdin, -1, NULL, "stdin", 0, "r");
2874
- JimMakeChannel(interp, stdout, -1, NULL, "stdout", 0, "w");
2875
- JimMakeChannel(interp, stderr, -1, NULL, "stderr", 0, "w");
3418
+ JimMakeChannel(interp, fileno(stdin), NULL, "stdin", 0, AIO_KEEPOPEN);
3419
+ JimMakeChannel(interp, fileno(stdout), NULL, "stdout", 0, AIO_KEEPOPEN);
3420
+ JimMakeChannel(interp, fileno(stderr), NULL, "stderr", 0, AIO_KEEPOPEN | AIO_WBUF_NONE);
28763421
28773422
return JIM_OK;
28783423
}
28793424
28803425
#include <errno.h>
@@ -2932,13 +3477,11 @@
29323477
}
29333478
}
29343479
29353480
int Jim_readdirInit(Jim_Interp *interp)
29363481
{
2937
- if (Jim_PackageProvide(interp, "readdir", "1.0", JIM_ERRMSG))
2938
- return JIM_ERR;
2939
-
3482
+ Jim_PackageProvideCheck(interp, "readdir");
29403483
Jim_CreateCommand(interp, "readdir", Jim_ReaddirCmd, NULL, NULL);
29413484
return JIM_OK;
29423485
}
29433486
29443487
#include <stdlib.h>
@@ -2945,15 +3488,19 @@
29453488
#include <string.h>
29463489
29473490
#if defined(JIM_REGEXP)
29483491
#else
29493492
#include <regex.h>
3493
+ #define jim_regcomp regcomp
3494
+ #define jim_regexec regexec
3495
+ #define jim_regerror regerror
3496
+ #define jim_regfree regfree
29503497
#endif
29513498
29523499
static void FreeRegexpInternalRep(Jim_Interp *interp, Jim_Obj *objPtr)
29533500
{
2954
- regfree(objPtr->internalRep.ptrIntValue.ptr);
3501
+ jim_regfree(objPtr->internalRep.ptrIntValue.ptr);
29553502
Jim_Free(objPtr->internalRep.ptrIntValue.ptr);
29563503
}
29573504
29583505
static const Jim_ObjType regexpObjType = {
29593506
"regexp",
@@ -2980,16 +3527,16 @@
29803527
29813528
29823529
pattern = Jim_String(objPtr);
29833530
compre = Jim_Alloc(sizeof(regex_t));
29843531
2985
- if ((ret = regcomp(compre, pattern, REG_EXTENDED | flags)) != 0) {
3532
+ if ((ret = jim_regcomp(compre, pattern, REG_EXTENDED | flags)) != 0) {
29863533
char buf[100];
29873534
2988
- regerror(ret, compre, buf, sizeof(buf));
3535
+ jim_regerror(ret, compre, buf, sizeof(buf));
29893536
Jim_SetResultFormatted(interp, "couldn't compile regular expression pattern: %s", buf);
2990
- regfree(compre);
3537
+ jim_regfree(compre);
29913538
Jim_Free(compre);
29923539
return NULL;
29933540
}
29943541
29953542
Jim_FreeIntRep(interp, objPtr);
@@ -3110,25 +3657,25 @@
31103657
}
31113658
if (offset > source_len) {
31123659
source_str += source_len;
31133660
}
31143661
else if (offset > 0) {
3115
- source_str += offset;
3662
+ source_str += utf8_index(source_str, offset);
31163663
}
31173664
eflags |= REG_NOTBOL;
31183665
}
31193666
31203667
if (opt_inline) {
31213668
resultListObj = Jim_NewListObj(interp, NULL, 0);
31223669
}
31233670
31243671
next_match:
3125
- match = regexec(regex, source_str, num_vars + 1, pmatch, eflags);
3672
+ match = jim_regexec(regex, source_str, num_vars + 1, pmatch, eflags);
31263673
if (match >= REG_BADPAT) {
31273674
char buf[100];
31283675
3129
- regerror(match, regex, buf, sizeof(buf));
3676
+ jim_regerror(match, regex, buf, sizeof(buf));
31303677
Jim_SetResultFormatted(interp, "error while matching pattern: %s", buf);
31313678
result = JIM_ERR;
31323679
goto done;
31333680
}
31343681
@@ -3160,20 +3707,19 @@
31603707
Jim_ListAppendElement(interp, resultObj, Jim_NewIntObj(interp, -1));
31613708
Jim_ListAppendElement(interp, resultObj, Jim_NewIntObj(interp, -1));
31623709
}
31633710
}
31643711
else {
3165
- int len = pmatch[j].rm_eo - pmatch[j].rm_so;
3166
-
31673712
if (opt_indices) {
3168
- Jim_ListAppendElement(interp, resultObj, Jim_NewIntObj(interp,
3169
- offset + pmatch[j].rm_so));
3170
- Jim_ListAppendElement(interp, resultObj, Jim_NewIntObj(interp,
3171
- offset + pmatch[j].rm_so + len - 1));
3713
+
3714
+ int so = utf8_strlen(source_str, pmatch[j].rm_so);
3715
+ int eo = utf8_strlen(source_str, pmatch[j].rm_eo);
3716
+ Jim_ListAppendElement(interp, resultObj, Jim_NewIntObj(interp, offset + so));
3717
+ Jim_ListAppendElement(interp, resultObj, Jim_NewIntObj(interp, offset + eo - 1));
31723718
}
31733719
else {
3174
- Jim_AppendString(interp, resultObj, source_str + pmatch[j].rm_so, len);
3720
+ Jim_AppendString(interp, resultObj, source_str + pmatch[j].rm_so, pmatch[j].rm_eo - pmatch[j].rm_so);
31753721
}
31763722
}
31773723
31783724
if (opt_inline) {
31793725
Jim_ListAppendElement(interp, resultListObj, resultObj);
@@ -3190,11 +3736,11 @@
31903736
}
31913737
31923738
try_next_match:
31933739
if (opt_all && (pattern[0] != '^' || (regcomp_flags & REG_NEWLINE)) && *source_str) {
31943740
if (pmatch[0].rm_eo) {
3195
- offset += pmatch[0].rm_eo;
3741
+ offset += utf8_strlen(source_str, pmatch[0].rm_eo);
31963742
source_str += pmatch[0].rm_eo;
31973743
}
31983744
else {
31993745
source_str++;
32003746
offset++;
@@ -3319,23 +3865,25 @@
33193865
else if (offset < 0) {
33203866
offset = 0;
33213867
}
33223868
}
33233869
3870
+ offset = utf8_index(source_str, offset);
3871
+
33243872
33253873
Jim_AppendString(interp, resultObj, source_str, offset);
33263874
33273875
33283876
n = source_len - offset;
33293877
p = source_str + offset;
33303878
do {
3331
- int match = regexec(regex, p, MAX_SUB_MATCHES, pmatch, regexec_flags);
3879
+ int match = jim_regexec(regex, p, MAX_SUB_MATCHES, pmatch, regexec_flags);
33323880
33333881
if (match >= REG_BADPAT) {
33343882
char buf[100];
33353883
3336
- regerror(match, regex, buf, sizeof(buf));
3884
+ jim_regerror(match, regex, buf, sizeof(buf));
33373885
Jim_SetResultFormatted(interp, "error while matching pattern: %s", buf);
33383886
return JIM_ERR;
33393887
}
33403888
if (match == REG_NOMATCH) {
33413889
break;
@@ -3396,11 +3944,18 @@
33963944
Jim_AppendString(interp, resultObj, p, 1);
33973945
p++;
33983946
n--;
33993947
}
34003948
3401
- regexec_flags |= REG_NOTBOL;
3949
+ if (pmatch[0].rm_eo == pmatch[0].rm_so) {
3950
+
3951
+ regexec_flags = REG_NOTBOL;
3952
+ }
3953
+ else {
3954
+ regexec_flags = 0;
3955
+ }
3956
+
34023957
} while (n);
34033958
34043959
Jim_AppendString(interp, resultObj, p, -1);
34053960
34063961
@@ -3422,13 +3977,11 @@
34223977
return result;
34233978
}
34243979
34253980
int Jim_regexpInit(Jim_Interp *interp)
34263981
{
3427
- if (Jim_PackageProvide(interp, "regexp", "1.0", JIM_ERRMSG))
3428
- return JIM_ERR;
3429
-
3982
+ Jim_PackageProvideCheck(interp, "regexp");
34303983
Jim_CreateCommand(interp, "regexp", Jim_RegexpCmd, NULL, NULL);
34313984
Jim_CreateCommand(interp, "regsub", Jim_RegsubCmd, NULL, NULL);
34323985
return JIM_OK;
34333986
}
34343987
@@ -3435,11 +3988,10 @@
34353988
#include <limits.h>
34363989
#include <stdlib.h>
34373990
#include <string.h>
34383991
#include <stdio.h>
34393992
#include <errno.h>
3440
-#include <sys/stat.h>
34413993
34423994
34433995
#ifdef HAVE_UTIMES
34443996
#include <sys/time.h>
34453997
#endif
@@ -3453,15 +4005,21 @@
34534005
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
34544006
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
34554007
#endif
34564008
34574009
# ifndef MAXPATHLEN
4010
+# ifdef PATH_MAX
4011
+# define MAXPATHLEN PATH_MAX
4012
+# else
34584013
# define MAXPATHLEN JIM_PATH_LEN
4014
+# endif
34594015
# endif
34604016
34614017
#if defined(__MINGW32__) || defined(__MSYS__) || defined(_MSC_VER)
34624018
#define ISWINDOWS 1
4019
+
4020
+#undef HAVE_SYMLINK
34634021
#else
34644022
#define ISWINDOWS 0
34654023
#endif
34664024
34674025
@@ -3469,10 +4027,22 @@
34694027
#define STAT_MTIME_US(STAT) ((STAT).st_mtimespec.tv_sec * 1000000ll + (STAT).st_mtimespec.tv_nsec / 1000)
34704028
#elif defined(HAVE_STRUCT_STAT_ST_MTIM)
34714029
#define STAT_MTIME_US(STAT) ((STAT).st_mtim.tv_sec * 1000000ll + (STAT).st_mtim.tv_nsec / 1000)
34724030
#endif
34734031
4032
+
4033
+static void JimFixPath(char *path)
4034
+{
4035
+ if (ISWINDOWS) {
4036
+
4037
+ char *p = path;
4038
+ while ((p = strchr(p, '\\')) != NULL) {
4039
+ *p++ = '/';
4040
+ }
4041
+ }
4042
+}
4043
+
34744044
34754045
static const char *JimGetFileType(int mode)
34764046
{
34774047
if (S_ISREG(mode)) {
34784048
return "file";
@@ -3512,11 +4082,11 @@
35124082
{
35134083
Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, key, -1));
35144084
Jim_ListAppendElement(interp, listObj, Jim_NewIntObj(interp, value));
35154085
}
35164086
3517
-static int StoreStatData(Jim_Interp *interp, Jim_Obj *varName, const struct stat *sb)
4087
+int Jim_FileStoreStatData(Jim_Interp *interp, Jim_Obj *varName, const jim_stat_t *sb)
35184088
{
35194089
35204090
Jim_Obj *listObj = Jim_NewListObj(interp, NULL, 0);
35214091
35224092
AppendStatElement(interp, listObj, "dev", sb->st_dev);
@@ -3565,31 +4135,91 @@
35654135
35664136
Jim_SetResult(interp, listObj);
35674137
35684138
return JIM_OK;
35694139
}
4140
+
4141
+static int JimPathLenNoTrailingSlashes(const char *path, int len)
4142
+{
4143
+ int i;
4144
+ for (i = len; i > 1 && path[i - 1] == '/'; i--) {
4145
+
4146
+ if (ISWINDOWS && path[i - 2] == ':') {
4147
+
4148
+ break;
4149
+ }
4150
+ }
4151
+ return i;
4152
+}
4153
+
4154
+static Jim_Obj *JimStripTrailingSlashes(Jim_Interp *interp, Jim_Obj *objPtr)
4155
+{
4156
+ int len = Jim_Length(objPtr);
4157
+ const char *path = Jim_String(objPtr);
4158
+ int i = JimPathLenNoTrailingSlashes(path, len);
4159
+ if (i != len) {
4160
+ objPtr = Jim_NewStringObj(interp, path, i);
4161
+ }
4162
+ Jim_IncrRefCount(objPtr);
4163
+ return objPtr;
4164
+}
35704165
35714166
static int file_cmd_dirname(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
35724167
{
3573
- const char *path = Jim_String(argv[0]);
4168
+ Jim_Obj *objPtr = JimStripTrailingSlashes(interp, argv[0]);
4169
+ const char *path = Jim_String(objPtr);
35744170
const char *p = strrchr(path, '/');
35754171
3576
- if (!p && path[0] == '.' && path[1] == '.' && path[2] == '\0') {
3577
- Jim_SetResultString(interp, "..", -1);
3578
- } else if (!p) {
4172
+ if (!p) {
35794173
Jim_SetResultString(interp, ".", -1);
35804174
}
4175
+ else if (p[1] == 0) {
4176
+
4177
+ Jim_SetResult(interp, objPtr);
4178
+ }
35814179
else if (p == path) {
35824180
Jim_SetResultString(interp, "/", -1);
35834181
}
35844182
else if (ISWINDOWS && p[-1] == ':') {
35854183
35864184
Jim_SetResultString(interp, path, p - path + 1);
35874185
}
35884186
else {
3589
- Jim_SetResultString(interp, path, p - path);
4187
+
4188
+ int len = JimPathLenNoTrailingSlashes(path, p - path);
4189
+ Jim_SetResultString(interp, path, len);
35904190
}
4191
+ Jim_DecrRefCount(interp, objPtr);
4192
+ return JIM_OK;
4193
+}
4194
+
4195
+static int file_cmd_split(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
4196
+{
4197
+ Jim_Obj *listObj = Jim_NewListObj(interp, NULL, 0);
4198
+ const char *path = Jim_String(argv[0]);
4199
+
4200
+ if (*path == '/') {
4201
+ Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, "/", 1));
4202
+ }
4203
+
4204
+ while (1) {
4205
+
4206
+ while (*path == '/') {
4207
+ path++;
4208
+ }
4209
+ if (*path) {
4210
+ const char *pt = strchr(path, '/');
4211
+ if (pt) {
4212
+ Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, path, pt - path));
4213
+ path = pt;
4214
+ continue;
4215
+ }
4216
+ Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, path, -1));
4217
+ }
4218
+ break;
4219
+ }
4220
+ Jim_SetResult(interp, listObj);
35914221
return JIM_OK;
35924222
}
35934223
35944224
static int file_cmd_rootname(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
35954225
{
@@ -3606,54 +4236,67 @@
36064236
return JIM_OK;
36074237
}
36084238
36094239
static int file_cmd_extension(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
36104240
{
3611
- const char *path = Jim_String(argv[0]);
4241
+ Jim_Obj *objPtr = JimStripTrailingSlashes(interp, argv[0]);
4242
+ const char *path = Jim_String(objPtr);
36124243
const char *lastSlash = strrchr(path, '/');
36134244
const char *p = strrchr(path, '.');
36144245
36154246
if (p == NULL || (lastSlash != NULL && lastSlash >= p)) {
36164247
p = "";
36174248
}
36184249
Jim_SetResultString(interp, p, -1);
4250
+ Jim_DecrRefCount(interp, objPtr);
36194251
return JIM_OK;
36204252
}
36214253
36224254
static int file_cmd_tail(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
36234255
{
3624
- const char *path = Jim_String(argv[0]);
4256
+ Jim_Obj *objPtr = JimStripTrailingSlashes(interp, argv[0]);
4257
+ const char *path = Jim_String(objPtr);
36254258
const char *lastSlash = strrchr(path, '/');
36264259
36274260
if (lastSlash) {
36284261
Jim_SetResultString(interp, lastSlash + 1, -1);
36294262
}
36304263
else {
3631
- Jim_SetResult(interp, argv[0]);
4264
+ Jim_SetResult(interp, objPtr);
36324265
}
4266
+ Jim_DecrRefCount(interp, objPtr);
36334267
return JIM_OK;
36344268
}
4269
+
4270
+#ifndef HAVE_RESTRICT
4271
+#define restrict
4272
+#endif
4273
+
4274
+static char *JimRealPath(const char *restrict path, char *restrict resolved_path, size_t len)
4275
+{
4276
+#if defined(HAVE__FULLPATH)
4277
+ return _fullpath(resolved_path, path, len);
4278
+#elif defined(HAVE_REALPATH)
4279
+ return realpath(path, resolved_path);
4280
+#else
4281
+ return NULL;
4282
+#endif
4283
+}
36354284
36364285
static int file_cmd_normalize(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
36374286
{
3638
-#ifdef HAVE_REALPATH
36394287
const char *path = Jim_String(argv[0]);
3640
- char *newname = Jim_Alloc(MAXPATHLEN + 1);
4288
+ char *newname = Jim_Alloc(MAXPATHLEN);
36414289
3642
- if (realpath(path, newname)) {
4290
+ if (JimRealPath(path, newname, MAXPATHLEN)) {
4291
+ JimFixPath(newname);
36434292
Jim_SetResult(interp, Jim_NewStringObjNoAlloc(interp, newname, -1));
36444293
return JIM_OK;
36454294
}
3646
- else {
3647
- Jim_Free(newname);
3648
- Jim_SetResultFormatted(interp, "can't normalize \"%#s\": %s", argv[0], strerror(errno));
3649
- return JIM_ERR;
3650
- }
3651
-#else
3652
- Jim_SetResultString(interp, "Not implemented", -1);
3653
- return JIM_ERR;
3654
-#endif
4295
+ Jim_Free(newname);
4296
+ Jim_SetResultFormatted(interp, "can't normalize \"%#s\": %s", argv[0], strerror(errno));
4297
+ return JIM_ERR;
36554298
}
36564299
36574300
static int file_cmd_join(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
36584301
{
36594302
int i;
@@ -3755,12 +4398,12 @@
37554398
static int file_cmd_delete(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
37564399
{
37574400
int force = Jim_CompareStringImmediate(interp, argv[0], "-force");
37584401
37594402
if (force || Jim_CompareStringImmediate(interp, argv[0], "--")) {
3760
- argc++;
3761
- argv--;
4403
+ argc--;
4404
+ argv++;
37624405
}
37634406
37644407
while (argc--) {
37654408
const char *path = Jim_String(argv[0]);
37664409
@@ -3813,13 +4456,13 @@
38134456
38144457
continue;
38154458
}
38164459
38174460
if (errno == EEXIST) {
3818
- struct stat sb;
4461
+ jim_stat_t sb;
38194462
3820
- if (stat(path, &sb) == 0 && S_ISDIR(sb.st_mode)) {
4463
+ if (Jim_Stat(path, &sb) == 0 && S_ISDIR(sb.st_mode)) {
38214464
return 0;
38224465
}
38234466
38244467
errno = EEXIST;
38254468
}
@@ -3879,11 +4522,16 @@
38794522
if (!force && access(dest, F_OK) == 0) {
38804523
Jim_SetResultFormatted(interp, "error renaming \"%#s\" to \"%#s\": target exists", argv[0],
38814524
argv[1]);
38824525
return JIM_ERR;
38834526
}
4527
+#if ISWINDOWS
4528
+ if (access(dest, F_OK) == 0) {
38844529
4530
+ remove(dest);
4531
+ }
4532
+#endif
38854533
if (rename(source, dest) != 0) {
38864534
Jim_SetResultFormatted(interp, "error renaming \"%#s\" to \"%#s\": %s", argv[0], argv[1],
38874535
strerror(errno));
38884536
return JIM_ERR;
38894537
}
@@ -3927,27 +4575,27 @@
39274575
39284576
return JIM_OK;
39294577
}
39304578
#endif
39314579
3932
-static int file_stat(Jim_Interp *interp, Jim_Obj *filename, struct stat *sb)
4580
+static int file_stat(Jim_Interp *interp, Jim_Obj *filename, jim_stat_t *sb)
39334581
{
39344582
const char *path = Jim_String(filename);
39354583
3936
- if (stat(path, sb) == -1) {
4584
+ if (Jim_Stat(path, sb) == -1) {
39374585
Jim_SetResultFormatted(interp, "could not read \"%#s\": %s", filename, strerror(errno));
39384586
return JIM_ERR;
39394587
}
39404588
return JIM_OK;
39414589
}
39424590
3943
-#ifdef HAVE_LSTAT
3944
-static int file_lstat(Jim_Interp *interp, Jim_Obj *filename, struct stat *sb)
4591
+#ifdef Jim_LinkStat
4592
+static int file_lstat(Jim_Interp *interp, Jim_Obj *filename, jim_stat_t *sb)
39454593
{
39464594
const char *path = Jim_String(filename);
39474595
3948
- if (lstat(path, sb) == -1) {
4596
+ if (Jim_LinkStat(path, sb) == -1) {
39494597
Jim_SetResultFormatted(interp, "could not read \"%#s\": %s", filename, strerror(errno));
39504598
return JIM_ERR;
39514599
}
39524600
return JIM_OK;
39534601
}
@@ -3955,11 +4603,11 @@
39554603
#define file_lstat file_stat
39564604
#endif
39574605
39584606
static int file_cmd_atime(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
39594607
{
3960
- struct stat sb;
4608
+ jim_stat_t sb;
39614609
39624610
if (file_stat(interp, argv[0], &sb) != JIM_OK) {
39634611
return JIM_ERR;
39644612
}
39654613
Jim_SetResultInt(interp, sb.st_atime);
@@ -3985,11 +4633,11 @@
39854633
#endif
39864634
}
39874635
39884636
static int file_cmd_mtime(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
39894637
{
3990
- struct stat sb;
4638
+ jim_stat_t sb;
39914639
39924640
if (argc == 2) {
39934641
jim_wide secs;
39944642
if (Jim_GetWide(interp, argv[1], &secs) != JIM_OK) {
39954643
return JIM_ERR;
@@ -4004,11 +4652,11 @@
40044652
}
40054653
40064654
#ifdef STAT_MTIME_US
40074655
static int file_cmd_mtimeus(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
40084656
{
4009
- struct stat sb;
4657
+ jim_stat_t sb;
40104658
40114659
if (argc == 2) {
40124660
jim_wide us;
40134661
if (Jim_GetWide(interp, argv[1], &us) != JIM_OK) {
40144662
return JIM_ERR;
@@ -4028,11 +4676,11 @@
40284676
return Jim_EvalPrefix(interp, "file copy", argc, argv);
40294677
}
40304678
40314679
static int file_cmd_size(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
40324680
{
4033
- struct stat sb;
4681
+ jim_stat_t sb;
40344682
40354683
if (file_stat(interp, argv[0], &sb) != JIM_OK) {
40364684
return JIM_ERR;
40374685
}
40384686
Jim_SetResultInt(interp, sb.st_size);
@@ -4039,11 +4687,11 @@
40394687
return JIM_OK;
40404688
}
40414689
40424690
static int file_cmd_isdirectory(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
40434691
{
4044
- struct stat sb;
4692
+ jim_stat_t sb;
40454693
int ret = 0;
40464694
40474695
if (file_stat(interp, argv[0], &sb) == JIM_OK) {
40484696
ret = S_ISDIR(sb.st_mode);
40494697
}
@@ -4051,11 +4699,11 @@
40514699
return JIM_OK;
40524700
}
40534701
40544702
static int file_cmd_isfile(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
40554703
{
4056
- struct stat sb;
4704
+ jim_stat_t sb;
40574705
int ret = 0;
40584706
40594707
if (file_stat(interp, argv[0], &sb) == JIM_OK) {
40604708
ret = S_ISREG(sb.st_mode);
40614709
}
@@ -4064,11 +4712,11 @@
40644712
}
40654713
40664714
#ifdef HAVE_GETEUID
40674715
static int file_cmd_owned(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
40684716
{
4069
- struct stat sb;
4717
+ jim_stat_t sb;
40704718
int ret = 0;
40714719
40724720
if (file_stat(interp, argv[0], &sb) == JIM_OK) {
40734721
ret = (geteuid() == sb.st_uid);
40744722
}
@@ -4085,11 +4733,11 @@
40854733
40864734
int linkLength = readlink(path, linkValue, MAXPATHLEN);
40874735
40884736
if (linkLength == -1) {
40894737
Jim_Free(linkValue);
4090
- Jim_SetResultFormatted(interp, "couldn't readlink \"%#s\": %s", argv[0], strerror(errno));
4738
+ Jim_SetResultFormatted(interp, "could not read link \"%#s\": %s", argv[0], strerror(errno));
40914739
return JIM_ERR;
40924740
}
40934741
linkValue[linkLength] = 0;
40944742
Jim_SetResult(interp, Jim_NewStringObjNoAlloc(interp, linkValue, linkLength));
40954743
return JIM_OK;
@@ -4096,41 +4744,41 @@
40964744
}
40974745
#endif
40984746
40994747
static int file_cmd_type(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
41004748
{
4101
- struct stat sb;
4749
+ jim_stat_t sb;
41024750
41034751
if (file_lstat(interp, argv[0], &sb) != JIM_OK) {
41044752
return JIM_ERR;
41054753
}
41064754
Jim_SetResultString(interp, JimGetFileType((int)sb.st_mode), -1);
41074755
return JIM_OK;
41084756
}
41094757
4110
-#ifdef HAVE_LSTAT
4758
+#ifdef Jim_LinkStat
41114759
static int file_cmd_lstat(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
41124760
{
4113
- struct stat sb;
4761
+ jim_stat_t sb;
41144762
41154763
if (file_lstat(interp, argv[0], &sb) != JIM_OK) {
41164764
return JIM_ERR;
41174765
}
4118
- return StoreStatData(interp, argc == 2 ? argv[1] : NULL, &sb);
4766
+ return Jim_FileStoreStatData(interp, argc == 2 ? argv[1] : NULL, &sb);
41194767
}
41204768
#else
41214769
#define file_cmd_lstat file_cmd_stat
41224770
#endif
41234771
41244772
static int file_cmd_stat(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
41254773
{
4126
- struct stat sb;
4774
+ jim_stat_t sb;
41274775
41284776
if (file_stat(interp, argv[0], &sb) != JIM_OK) {
41294777
return JIM_ERR;
41304778
}
4131
- return StoreStatData(interp, argc == 2 ? argv[1] : NULL, &sb);
4779
+ return Jim_FileStoreStatData(interp, argc == 2 ? argv[1] : NULL, &sb);
41324780
}
41334781
41344782
static const jim_subcmd_type file_command_table[] = {
41354783
{ "atime",
41364784
"name",
@@ -4187,10 +4835,17 @@
41874835
"name",
41884836
file_cmd_tail,
41894837
1,
41904838
1,
41914839
4840
+ },
4841
+ { "split",
4842
+ "name",
4843
+ file_cmd_split,
4844
+ 1,
4845
+ 1,
4846
+
41924847
},
41934848
{ "normalize",
41944849
"name",
41954850
file_cmd_normalize,
41964851
1,
@@ -4360,43 +5015,31 @@
43605015
if (getcwd(cwd, MAXPATHLEN) == NULL) {
43615016
Jim_SetResultString(interp, "Failed to get pwd", -1);
43625017
Jim_Free(cwd);
43635018
return JIM_ERR;
43645019
}
4365
- else if (ISWINDOWS) {
4366
-
4367
- char *p = cwd;
4368
- while ((p = strchr(p, '\\')) != NULL) {
4369
- *p++ = '/';
4370
- }
4371
- }
4372
-
5020
+ JimFixPath(cwd);
43735021
Jim_SetResultString(interp, cwd, -1);
43745022
43755023
Jim_Free(cwd);
43765024
return JIM_OK;
43775025
}
43785026
43795027
int Jim_fileInit(Jim_Interp *interp)
43805028
{
4381
- if (Jim_PackageProvide(interp, "file", "1.0", JIM_ERRMSG))
4382
- return JIM_ERR;
4383
-
5029
+ Jim_PackageProvideCheck(interp, "file");
43845030
Jim_CreateCommand(interp, "file", Jim_SubCmdProc, (void *)file_command_table, NULL);
43855031
Jim_CreateCommand(interp, "pwd", Jim_PwdCmd, NULL, NULL);
43865032
Jim_CreateCommand(interp, "cd", Jim_CdCmd, NULL, NULL);
43875033
return JIM_OK;
43885034
}
43895035
4390
-#ifndef _GNU_SOURCE
4391
-#define _GNU_SOURCE
4392
-#endif
43935036
#include <string.h>
43945037
#include <ctype.h>
43955038
43965039
4397
-#if (!defined(HAVE_VFORK) || !defined(HAVE_WAITPID)) && !defined(__MINGW32__)
5040
+#if (!(defined(HAVE_VFORK) || defined(HAVE_FORK)) || !defined(HAVE_WAITPID)) && !defined(__MINGW32__)
43985041
static int Jim_ExecCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
43995042
{
44005043
Jim_Obj *cmdlineObj = Jim_NewEmptyStringObj(interp);
44015044
int i, j;
44025045
int rc;
@@ -4440,13 +5083,11 @@
44405083
return JIM_OK;
44415084
}
44425085
44435086
int Jim_execInit(Jim_Interp *interp)
44445087
{
4445
- if (Jim_PackageProvide(interp, "exec", "1.0", JIM_ERRMSG))
4446
- return JIM_ERR;
4447
-
5088
+ Jim_PackageProvideCheck(interp, "exec");
44485089
Jim_CreateCommand(interp, "exec", Jim_ExecCmd, NULL, NULL);
44495090
return JIM_OK;
44505091
}
44515092
#else
44525093
@@ -4459,17 +5100,17 @@
44595100
44605101
static char **JimOriginalEnviron(void);
44615102
static char **JimSaveEnv(char **env);
44625103
static void JimRestoreEnv(char **env);
44635104
static int JimCreatePipeline(Jim_Interp *interp, int argc, Jim_Obj *const *argv,
4464
- pidtype **pidArrayPtr, int *inPipePtr, int *outPipePtr, int *errFilePtr);
4465
-static void JimDetachPids(struct WaitInfoTable *table, int numPids, const pidtype *pidPtr);
4466
-static int JimCleanupChildren(Jim_Interp *interp, int numPids, pidtype *pidPtr, Jim_Obj *errStrObj);
5105
+ phandle_t **pidArrayPtr, int *inPipePtr, int *outPipePtr, int *errFilePtr);
5106
+static void JimDetachPids(struct WaitInfoTable *table, int numPids, const phandle_t *pidPtr);
5107
+static int JimCleanupChildren(Jim_Interp *interp, int numPids, phandle_t *pidPtr, Jim_Obj *errStrObj);
44675108
static int Jim_WaitCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv);
44685109
44695110
#if defined(__MINGW32__)
4470
-static pidtype JimStartWinProcess(Jim_Interp *interp, char **argv, char **env, int inputId, int outputId, int errorId);
5111
+static phandle_t JimStartWinProcess(Jim_Interp *interp, char **argv, char **env, int inputId, int outputId, int errorId);
44715112
#endif
44725113
44735114
static void Jim_RemoveTrailingNewline(Jim_Obj *objPtr)
44745115
{
44755116
int len;
@@ -4482,28 +5123,23 @@
44825123
}
44835124
44845125
static int JimAppendStreamToString(Jim_Interp *interp, int fd, Jim_Obj *strObj)
44855126
{
44865127
char buf[256];
4487
- FILE *fh = fdopen(fd, "r");
44885128
int ret = 0;
44895129
4490
- if (fh == NULL) {
4491
- return -1;
4492
- }
4493
-
44945130
while (1) {
4495
- int retval = fread(buf, 1, sizeof(buf), fh);
5131
+ int retval = read(fd, buf, sizeof(buf));
44965132
if (retval > 0) {
44975133
ret = 1;
44985134
Jim_AppendString(interp, strObj, buf, retval);
44995135
}
4500
- if (retval != sizeof(buf)) {
5136
+ if (retval <= 0) {
45015137
break;
45025138
}
45035139
}
4504
- fclose(fh);
5140
+ close(fd);
45055141
return ret;
45065142
}
45075143
45085144
static char **JimBuildEnv(Jim_Interp *interp)
45095145
{
@@ -4558,22 +5194,22 @@
45585194
if (env != original_environ) {
45595195
Jim_Free(env);
45605196
}
45615197
}
45625198
4563
-static Jim_Obj *JimMakeErrorCode(Jim_Interp *interp, pidtype pid, int waitStatus, Jim_Obj *errStrObj)
5199
+static Jim_Obj *JimMakeErrorCode(Jim_Interp *interp, long pid, int waitStatus, Jim_Obj *errStrObj)
45645200
{
45655201
Jim_Obj *errorCode = Jim_NewListObj(interp, NULL, 0);
45665202
4567
- if (pid == JIM_BAD_PID || pid == JIM_NO_PID) {
5203
+ if (pid <= 0) {
45685204
Jim_ListAppendElement(interp, errorCode, Jim_NewStringObj(interp, "NONE", -1));
4569
- Jim_ListAppendElement(interp, errorCode, Jim_NewIntObj(interp, (long)pid));
5205
+ Jim_ListAppendElement(interp, errorCode, Jim_NewIntObj(interp, pid));
45705206
Jim_ListAppendElement(interp, errorCode, Jim_NewIntObj(interp, -1));
45715207
}
45725208
else if (WIFEXITED(waitStatus)) {
45735209
Jim_ListAppendElement(interp, errorCode, Jim_NewStringObj(interp, "CHILDSTATUS", -1));
4574
- Jim_ListAppendElement(interp, errorCode, Jim_NewIntObj(interp, (long)pid));
5210
+ Jim_ListAppendElement(interp, errorCode, Jim_NewIntObj(interp, pid));
45755211
Jim_ListAppendElement(interp, errorCode, Jim_NewIntObj(interp, WEXITSTATUS(waitStatus)));
45765212
}
45775213
else {
45785214
const char *type;
45795215
const char *action;
@@ -4594,17 +5230,17 @@
45945230
45955231
if (errStrObj) {
45965232
Jim_AppendStrings(interp, errStrObj, "child ", action, " by signal ", Jim_SignalId(WTERMSIG(waitStatus)), "\n", NULL);
45975233
}
45985234
4599
- Jim_ListAppendElement(interp, errorCode, Jim_NewIntObj(interp, (long)pid));
5235
+ Jim_ListAppendElement(interp, errorCode, Jim_NewIntObj(interp, pid));
46005236
Jim_ListAppendElement(interp, errorCode, Jim_NewStringObj(interp, signame, -1));
46015237
}
46025238
return errorCode;
46035239
}
46045240
4605
-static int JimCheckWaitStatus(Jim_Interp *interp, pidtype pid, int waitStatus, Jim_Obj *errStrObj)
5241
+static int JimCheckWaitStatus(Jim_Interp *interp, long pid, int waitStatus, Jim_Obj *errStrObj)
46065242
{
46075243
if (WIFEXITED(waitStatus) && WEXITSTATUS(waitStatus) == 0) {
46085244
return JIM_OK;
46095245
}
46105246
Jim_SetGlobalVariableStr(interp, "errorCode", JimMakeErrorCode(interp, pid, waitStatus, errStrObj));
@@ -4613,11 +5249,11 @@
46135249
}
46145250
46155251
46165252
struct WaitInfo
46175253
{
4618
- pidtype pid;
5254
+ phandle_t phandle;
46195255
int status;
46205256
int flags;
46215257
};
46225258
46235259
@@ -4651,17 +5287,17 @@
46515287
table->refcount = 1;
46525288
46535289
return table;
46545290
}
46555291
4656
-static int JimWaitRemove(struct WaitInfoTable *table, pidtype pid)
5292
+static int JimWaitRemove(struct WaitInfoTable *table, phandle_t phandle)
46575293
{
46585294
int i;
46595295
46605296
46615297
for (i = 0; i < table->used; i++) {
4662
- if (pid == table->info[i].pid) {
5298
+ if (phandle == table->info[i].phandle) {
46635299
if (i != table->used - 1) {
46645300
table->info[i] = table->info[table->used - 1];
46655301
}
46665302
table->used--;
46675303
return 0;
@@ -4672,11 +5308,11 @@
46725308
46735309
static int Jim_ExecCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
46745310
{
46755311
int outputId;
46765312
int errorId;
4677
- pidtype *pidPtr;
5313
+ phandle_t *pidPtr;
46785314
int numPids, result;
46795315
int child_siginfo = 1;
46805316
Jim_Obj *childErrObj;
46815317
Jim_Obj *errStrObj;
46825318
struct WaitInfoTable *table = Jim_CmdPrivData(interp);
@@ -4691,11 +5327,11 @@
46915327
return JIM_ERR;
46925328
}
46935329
46945330
listObj = Jim_NewListObj(interp, NULL, 0);
46955331
for (i = 0; i < numPids; i++) {
4696
- Jim_ListAppendElement(interp, listObj, Jim_NewIntObj(interp, (long)pidPtr[i]));
5332
+ Jim_ListAppendElement(interp, listObj, Jim_NewIntObj(interp, JimProcessPid(pidPtr[i])));
46975333
}
46985334
Jim_SetResult(interp, listObj);
46995335
JimDetachPids(table, numPids, pidPtr);
47005336
Jim_Free(pidPtr);
47015337
return JIM_OK;
@@ -4728,11 +5364,11 @@
47285364
result = JIM_ERR;
47295365
}
47305366
47315367
if (errorId != -1) {
47325368
int ret;
4733
- lseek(errorId, 0, SEEK_SET);
5369
+ Jim_Lseek(errorId, 0, SEEK_SET);
47345370
ret = JimAppendStreamToString(interp, errorId, errStrObj);
47355371
if (ret < 0) {
47365372
Jim_SetResultErrno(interp, "error reading from error pipe");
47375373
result = JIM_ERR;
47385374
}
@@ -4755,31 +5391,30 @@
47555391
Jim_SetResult(interp, errStrObj);
47565392
47575393
return result;
47585394
}
47595395
4760
-static pidtype JimWaitForProcess(struct WaitInfoTable *table, pidtype pid, int *statusPtr)
5396
+static long JimWaitForProcess(struct WaitInfoTable *table, phandle_t phandle, int *statusPtr)
47615397
{
4762
- if (JimWaitRemove(table, pid) == 0) {
5398
+ if (JimWaitRemove(table, phandle) == 0) {
47635399
4764
- waitpid(pid, statusPtr, 0);
4765
- return pid;
5400
+ return waitpid(phandle, statusPtr, 0);
47665401
}
47675402
47685403
4769
- return JIM_BAD_PID;
5404
+ return -1;
47705405
}
47715406
4772
-static void JimDetachPids(struct WaitInfoTable *table, int numPids, const pidtype *pidPtr)
5407
+static void JimDetachPids(struct WaitInfoTable *table, int numPids, const phandle_t *pidPtr)
47735408
{
47745409
int j;
47755410
47765411
for (j = 0; j < numPids; j++) {
47775412
47785413
int i;
47795414
for (i = 0; i < table->used; i++) {
4780
- if (pidPtr[j] == table->info[i].pid) {
5415
+ if (pidPtr[j] == table->info[i].phandle) {
47815416
table->info[i].flags |= WI_DETACHED;
47825417
break;
47835418
}
47845419
}
47855420
}
@@ -4814,12 +5449,12 @@
48145449
waitPtr = table->info;
48155450
dest = 0;
48165451
for (count = table->used; count > 0; waitPtr++, count--) {
48175452
if (waitPtr->flags & WI_DETACHED) {
48185453
int status;
4819
- pidtype pid = waitpid(waitPtr->pid, &status, WNOHANG);
4820
- if (pid == waitPtr->pid) {
5454
+ long pid = waitpid(waitPtr->phandle, &status, WNOHANG);
5455
+ if (pid > 0) {
48215456
48225457
table->used--;
48235458
continue;
48245459
}
48255460
}
@@ -4832,12 +5467,12 @@
48325467
48335468
static int Jim_WaitCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
48345469
{
48355470
struct WaitInfoTable *table = Jim_CmdPrivData(interp);
48365471
int nohang = 0;
4837
- pidtype pid;
4838
- long pidarg;
5472
+ long pid;
5473
+ phandle_t phandle;
48395474
int status;
48405475
Jim_Obj *errCodeObj;
48415476
48425477
48435478
if (argc == 1) {
@@ -4850,21 +5485,30 @@
48505485
}
48515486
if (argc != nohang + 2) {
48525487
Jim_WrongNumArgs(interp, 1, argv, "?-nohang? ?pid?");
48535488
return JIM_ERR;
48545489
}
4855
- if (Jim_GetLong(interp, argv[nohang + 1], &pidarg) != JIM_OK) {
5490
+ if (Jim_GetLong(interp, argv[nohang + 1], &pid) != JIM_OK) {
48565491
return JIM_ERR;
48575492
}
48585493
4859
- pid = waitpid((pidtype)pidarg, &status, nohang ? WNOHANG : 0);
5494
+
5495
+ phandle = JimWaitPid(pid, &status, nohang ? WNOHANG : 0);
5496
+ if (phandle == JIM_BAD_PHANDLE) {
5497
+ pid = -1;
5498
+ }
5499
+#ifndef __MINGW32__
5500
+ else if (pid < 0) {
5501
+ pid = phandle;
5502
+ }
5503
+#endif
48605504
48615505
errCodeObj = JimMakeErrorCode(interp, pid, status, NULL);
48625506
4863
- if (pid != JIM_BAD_PID && (WIFEXITED(status) || WIFSIGNALED(status))) {
5507
+ if (phandle != JIM_BAD_PHANDLE && (WIFEXITED(status) || WIFSIGNALED(status))) {
48645508
4865
- JimWaitRemove(table, pid);
5509
+ JimWaitRemove(table, phandle);
48665510
}
48675511
Jim_SetResult(interp, errCodeObj);
48685512
return JIM_OK;
48695513
}
48705514
@@ -4878,14 +5522,14 @@
48785522
Jim_SetResultInt(interp, (jim_wide)getpid());
48795523
return JIM_OK;
48805524
}
48815525
48825526
static int
4883
-JimCreatePipeline(Jim_Interp *interp, int argc, Jim_Obj *const *argv, pidtype **pidArrayPtr,
5527
+JimCreatePipeline(Jim_Interp *interp, int argc, Jim_Obj *const *argv, phandle_t **pidArrayPtr,
48845528
int *inPipePtr, int *outPipePtr, int *errFilePtr)
48855529
{
4886
- pidtype *pidPtr = NULL; /* Points to malloc-ed array holding all
5530
+ phandle_t *pidPtr = NULL; /* Points to alloc-ed array holding all
48875531
* the pids of child processes. */
48885532
int numPids = 0; /* Actual number of processes that exist
48895533
* at *pidPtr right now. */
48905534
int cmdCount; /* Count of number of distinct commands
48915535
* found in argc/argv. */
@@ -4925,13 +5569,13 @@
49255569
int pipeIds[2];
49265570
int firstArg, lastArg; /* Indexes of first and last arguments in
49275571
* current command. */
49285572
int lastBar;
49295573
int i;
4930
- pidtype pid;
5574
+ phandle_t phandle;
49315575
char **save_environ;
4932
-#ifndef __MINGW32__
5576
+#if defined(HAVE_EXECVPE) && !defined(__MINGW32__)
49335577
char **child_environ;
49345578
#endif
49355579
struct WaitInfoTable *table = Jim_CmdPrivData(interp);
49365580
49375581
@@ -5053,11 +5697,11 @@
50535697
if (write(inputId, input, input_len) != input_len) {
50545698
Jim_SetResultErrno(interp, "couldn't write temp file");
50555699
close(inputId);
50565700
goto error;
50575701
}
5058
- lseek(inputId, 0L, SEEK_SET);
5702
+ Jim_Lseek(inputId, 0L, SEEK_SET);
50595703
}
50605704
else if (inputFile == FILE_HANDLE) {
50615705
int fd = JimGetChannelFd(interp, input);
50625706
50635707
if (fd < 0) {
@@ -5145,13 +5789,10 @@
51455789
*errFilePtr = dup(errorId);
51465790
}
51475791
51485792
51495793
pidPtr = Jim_Alloc(cmdCount * sizeof(*pidPtr));
5150
- for (i = 0; i < numPids; i++) {
5151
- pidPtr[i] = JIM_BAD_PID;
5152
- }
51535794
for (firstArg = 0; firstArg < arg_count; numPids++, firstArg = lastArg + 1) {
51545795
int pipe_dup_err = 0;
51555796
int origErrorId = errorId;
51565797
51575798
for (lastArg = firstArg; lastArg < arg_count; lastArg++) {
@@ -5189,58 +5830,61 @@
51895830
}
51905831
51915832
51925833
51935834
#ifdef __MINGW32__
5194
- pid = JimStartWinProcess(interp, &arg_array[firstArg], save_environ, inputId, outputId, errorId);
5195
- if (pid == JIM_BAD_PID) {
5835
+ phandle = JimStartWinProcess(interp, &arg_array[firstArg], save_environ, inputId, outputId, errorId);
5836
+ if (phandle == JIM_BAD_PHANDLE) {
51965837
Jim_SetResultFormatted(interp, "couldn't exec \"%s\"", arg_array[firstArg]);
51975838
goto error;
51985839
}
51995840
#else
52005841
i = strlen(arg_array[firstArg]);
52015842
5843
+#ifdef HAVE_EXECVPE
52025844
child_environ = Jim_GetEnviron();
5203
- pid = vfork();
5204
- if (pid < 0) {
5845
+#endif
5846
+#ifdef HAVE_VFORK
5847
+ phandle = vfork();
5848
+#else
5849
+ phandle = fork();
5850
+#endif
5851
+ if (phandle < 0) {
52055852
Jim_SetResultErrno(interp, "couldn't fork child process");
52065853
goto error;
52075854
}
5208
- if (pid == 0) {
5855
+ if (phandle == 0) {
52095856
52105857
5211
- if (inputId != -1) {
5858
+ if (inputId != -1 && inputId != fileno(stdin)) {
52125859
dup2(inputId, fileno(stdin));
52135860
close(inputId);
52145861
}
5215
- if (outputId != -1) {
5862
+ if (outputId != -1 && outputId != fileno(stdout)) {
52165863
dup2(outputId, fileno(stdout));
52175864
if (outputId != errorId) {
52185865
close(outputId);
52195866
}
52205867
}
5221
- if (errorId != -1) {
5868
+ if (errorId != -1 && errorId != fileno(stderr)) {
52225869
dup2(errorId, fileno(stderr));
52235870
close(errorId);
52245871
}
52255872
5226
- if (outPipePtr) {
5873
+ if (outPipePtr && *outPipePtr != -1) {
52275874
close(*outPipePtr);
52285875
}
5229
- if (errFilePtr) {
5876
+ if (errFilePtr && *errFilePtr != -1) {
52305877
close(*errFilePtr);
52315878
}
52325879
if (pipeIds[0] != -1) {
52335880
close(pipeIds[0]);
52345881
}
52355882
if (lastOutputId != -1) {
52365883
close(lastOutputId);
52375884
}
52385885
5239
-
5240
- (void)signal(SIGPIPE, SIG_DFL);
5241
-
52425886
execvpe(arg_array[firstArg], &arg_array[firstArg], child_environ);
52435887
52445888
if (write(fileno(stderr), "couldn't exec \"", 15) &&
52455889
write(fileno(stderr), arg_array[firstArg], i) &&
52465890
write(fileno(stderr), "\"\n", 2)) {
@@ -5262,15 +5906,15 @@
52625906
if (table->used == table->size) {
52635907
table->size += WAIT_TABLE_GROW_BY;
52645908
table->info = Jim_Realloc(table->info, table->size * sizeof(*table->info));
52655909
}
52665910
5267
- table->info[table->used].pid = pid;
5911
+ table->info[table->used].phandle = phandle;
52685912
table->info[table->used].flags = 0;
52695913
table->used++;
52705914
5271
- pidPtr[numPids] = pid;
5915
+ pidPtr[numPids] = phandle;
52725916
52735917
52745918
errorId = origErrorId;
52755919
52765920
@@ -5322,11 +5966,11 @@
53225966
if (pipeIds[1] != -1) {
53235967
close(pipeIds[1]);
53245968
}
53255969
if (pidPtr != NULL) {
53265970
for (i = 0; i < numPids; i++) {
5327
- if (pidPtr[i] != JIM_BAD_PID) {
5971
+ if (pidPtr[i] != JIM_BAD_PHANDLE) {
53285972
JimDetachPids(table, 1, &pidPtr[i]);
53295973
}
53305974
}
53315975
Jim_Free(pidPtr);
53325976
}
@@ -5333,21 +5977,22 @@
53335977
numPids = -1;
53345978
goto cleanup;
53355979
}
53365980
53375981
5338
-static int JimCleanupChildren(Jim_Interp *interp, int numPids, pidtype *pidPtr, Jim_Obj *errStrObj)
5982
+static int JimCleanupChildren(Jim_Interp *interp, int numPids, phandle_t *pidPtr, Jim_Obj *errStrObj)
53395983
{
53405984
struct WaitInfoTable *table = Jim_CmdPrivData(interp);
53415985
int result = JIM_OK;
53425986
int i;
53435987
53445988
53455989
for (i = 0; i < numPids; i++) {
53465990
int waitStatus = 0;
5347
- if (JimWaitForProcess(table, pidPtr[i], &waitStatus) != JIM_BAD_PID) {
5348
- if (JimCheckWaitStatus(interp, pidPtr[i], waitStatus, errStrObj) != JIM_OK) {
5991
+ long pid = JimWaitForProcess(table, pidPtr[i], &waitStatus);
5992
+ if (pid > 0) {
5993
+ if (JimCheckWaitStatus(interp, pid, waitStatus, errStrObj) != JIM_OK) {
53495994
result = JIM_ERR;
53505995
}
53515996
}
53525997
}
53535998
Jim_Free(pidPtr);
@@ -5356,16 +6001,12 @@
53566001
}
53576002
53586003
int Jim_execInit(Jim_Interp *interp)
53596004
{
53606005
struct WaitInfoTable *waitinfo;
5361
- if (Jim_PackageProvide(interp, "exec", "1.0", JIM_ERRMSG))
5362
- return JIM_ERR;
53636006
5364
-#ifdef SIGPIPE
5365
- (void)signal(SIGPIPE, SIG_IGN);
5366
-#endif
6007
+ Jim_PackageProvideCheck(interp, "exec");
53676008
53686009
waitinfo = JimAllocWaitInfoTable();
53696010
Jim_CreateCommand(interp, "exec", Jim_ExecCmd, waitinfo, JimFreeWaitInfoTable);
53706011
waitinfo->refcount++;
53716012
Jim_CreateCommand(interp, "wait", Jim_WaitCommand, waitinfo, JimFreeWaitInfoTable);
@@ -5483,23 +6124,23 @@
54836124
}
54846125
}
54856126
return strObj;
54866127
}
54876128
5488
-static pidtype
6129
+static phandle_t
54896130
JimStartWinProcess(Jim_Interp *interp, char **argv, char **env, int inputId, int outputId, int errorId)
54906131
{
54916132
STARTUPINFO startInfo;
54926133
PROCESS_INFORMATION procInfo;
54936134
HANDLE hProcess;
54946135
char execPath[MAX_PATH];
5495
- pidtype pid = JIM_BAD_PID;
6136
+ phandle_t phandle = INVALID_HANDLE_VALUE;
54966137
Jim_Obj *cmdLineObj;
54976138
char *winenv;
54986139
54996140
if (JimWinFindExecutable(argv[0], execPath) < 0) {
5500
- return JIM_BAD_PID;
6141
+ return phandle;
55016142
}
55026143
argv[0] = execPath;
55036144
55046145
hProcess = GetCurrentProcess();
55056146
cmdLineObj = JimWinBuildCommandLine(interp, argv);
@@ -5558,11 +6199,11 @@
55586199
55596200
55606201
WaitForInputIdle(procInfo.hProcess, 5000);
55616202
CloseHandle(procInfo.hThread);
55626203
5563
- pid = procInfo.hProcess;
6204
+ phandle = procInfo.hProcess;
55646205
55656206
end:
55666207
Jim_FreeNewObj(interp, cmdLineObj);
55676208
if (startInfo.hStdInput != INVALID_HANDLE_VALUE) {
55686209
CloseHandle(startInfo.hStdInput);
@@ -5571,11 +6212,11 @@
55716212
CloseHandle(startInfo.hStdOutput);
55726213
}
55736214
if (startInfo.hStdError != INVALID_HANDLE_VALUE) {
55746215
CloseHandle(startInfo.hStdError);
55756216
}
5576
- return pid;
6217
+ return phandle;
55776218
}
55786219
55796220
#else
55806221
55816222
static char **JimOriginalEnviron(void)
@@ -5597,22 +6238,10 @@
55976238
}
55986239
#endif
55996240
#endif
56006241
56016242
5602
-
5603
-#ifdef STRPTIME_NEEDS_XOPEN_SOURCE
5604
-#ifndef _XOPEN_SOURCE
5605
-#define _XOPEN_SOURCE 500
5606
-#endif
5607
-#endif
5608
-
5609
-
5610
-#ifndef _GNU_SOURCE
5611
-#define _GNU_SOURCE
5612
-#endif
5613
-
56146243
#include <stdlib.h>
56156244
#include <string.h>
56166245
#include <stdio.h>
56176246
#include <time.h>
56186247
@@ -5732,41 +6361,36 @@
57326361
}
57336362
#endif
57346363
57356364
static int clock_cmd_seconds(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
57366365
{
5737
- Jim_SetResultInt(interp, time(NULL));
6366
+ Jim_SetResultInt(interp, Jim_GetTimeUsec(CLOCK_REALTIME) / 1000000);
6367
+ return JIM_OK;
6368
+}
57386369
6370
+static int clock_cmd_clicks(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
6371
+{
6372
+ Jim_SetResultInt(interp, Jim_GetTimeUsec(CLOCK_MONOTONIC_RAW));
57396373
return JIM_OK;
57406374
}
57416375
57426376
static int clock_cmd_micros(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
57436377
{
5744
- struct timeval tv;
5745
-
5746
- gettimeofday(&tv, NULL);
5747
-
5748
- Jim_SetResultInt(interp, (jim_wide) tv.tv_sec * 1000000 + tv.tv_usec);
5749
-
6378
+ Jim_SetResultInt(interp, Jim_GetTimeUsec(CLOCK_REALTIME));
57506379
return JIM_OK;
57516380
}
57526381
57536382
static int clock_cmd_millis(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
57546383
{
5755
- struct timeval tv;
5756
-
5757
- gettimeofday(&tv, NULL);
5758
-
5759
- Jim_SetResultInt(interp, (jim_wide) tv.tv_sec * 1000 + tv.tv_usec / 1000);
5760
-
6384
+ Jim_SetResultInt(interp, Jim_GetTimeUsec(CLOCK_REALTIME) / 1000);
57616385
return JIM_OK;
57626386
}
57636387
57646388
static const jim_subcmd_type clock_command_table[] = {
57656389
{ "clicks",
57666390
NULL,
5767
- clock_cmd_micros,
6391
+ clock_cmd_clicks,
57686392
0,
57696393
0,
57706394
57716395
},
57726396
{ "format",
@@ -5809,13 +6433,11 @@
58096433
{ NULL }
58106434
};
58116435
58126436
int Jim_clockInit(Jim_Interp *interp)
58136437
{
5814
- if (Jim_PackageProvide(interp, "clock", "1.0", JIM_ERRMSG))
5815
- return JIM_ERR;
5816
-
6438
+ Jim_PackageProvideCheck(interp, "clock");
58176439
Jim_CreateCommand(interp, "clock", Jim_SubCmdProc, (void *)clock_command_table, NULL);
58186440
return JIM_OK;
58196441
}
58206442
58216443
#include <limits.h>
@@ -5886,11 +6508,12 @@
58866508
if (objPtr == NULL) {
58876509
58886510
return JIM_OK;
58896511
}
58906512
5891
- if (Jim_DictPairs(interp, objPtr, &dictValuesObj, &len) != JIM_OK) {
6513
+ dictValuesObj = Jim_DictPairs(interp, objPtr, &len);
6514
+ if (dictValuesObj == NULL) {
58926515
58936516
Jim_SetResultString(interp, "", -1);
58946517
return JIM_OK;
58956518
}
58966519
@@ -5900,11 +6523,10 @@
59006523
for (i = 0; i < len; i += 2) {
59016524
if (!Jim_StringMatchObj(interp, argv[1], dictValuesObj[i], 0)) {
59026525
Jim_DictAddElement(interp, resultObj, dictValuesObj[i], dictValuesObj[i + 1]);
59036526
}
59046527
}
5905
- Jim_Free(dictValuesObj);
59066528
59076529
Jim_SetVariable(interp, argv[0], resultObj);
59086530
return JIM_OK;
59096531
}
59106532
@@ -6031,25 +6653,71 @@
60316653
}
60326654
};
60336655
60346656
int Jim_arrayInit(Jim_Interp *interp)
60356657
{
6036
- if (Jim_PackageProvide(interp, "array", "1.0", JIM_ERRMSG))
6037
- return JIM_ERR;
6038
-
6658
+ Jim_PackageProvideCheck(interp, "array");
60396659
Jim_CreateCommand(interp, "array", Jim_SubCmdProc, (void *)array_command_table, NULL);
60406660
return JIM_OK;
60416661
}
6662
+
6663
+#include <sys/types.h>
6664
+#include <sys/time.h>
6665
+#include <sys/wait.h>
6666
+#include <unistd.h>
6667
+#include <string.h>
6668
+#include <errno.h>
6669
+
6670
+
6671
+#ifdef HAVE_SYS_SYSINFO_H
6672
+#include <sys/sysinfo.h>
6673
+#endif
6674
+
6675
+static void Jim_PosixSetError(Jim_Interp *interp)
6676
+{
6677
+ Jim_SetResultString(interp, strerror(errno), -1);
6678
+}
6679
+
6680
+#if defined(HAVE_FORK)
6681
+static int Jim_PosixForkCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
6682
+{
6683
+ pid_t pid;
6684
+
6685
+ JIM_NOTUSED(argv);
6686
+
6687
+ if (argc != 1) {
6688
+ Jim_WrongNumArgs(interp, 1, argv, "");
6689
+ return JIM_ERR;
6690
+ }
6691
+ if ((pid = fork()) == -1) {
6692
+ Jim_PosixSetError(interp);
6693
+ return JIM_ERR;
6694
+ }
6695
+ Jim_SetResultInt(interp, (jim_wide) pid);
6696
+ return JIM_OK;
6697
+}
6698
+#endif
6699
+
6700
+
6701
+int Jim_posixInit(Jim_Interp *interp)
6702
+{
6703
+ Jim_PackageProvideCheck(interp, "posix");
6704
+#ifdef HAVE_FORK
6705
+ Jim_CreateCommand(interp, "os.fork", Jim_PosixForkCommand, NULL, NULL);
6706
+#endif
6707
+ return JIM_OK;
6708
+}
60426709
int Jim_InitStaticExtensions(Jim_Interp *interp)
60436710
{
60446711
extern int Jim_bootstrapInit(Jim_Interp *);
60456712
extern int Jim_aioInit(Jim_Interp *);
60466713
extern int Jim_readdirInit(Jim_Interp *);
60476714
extern int Jim_regexpInit(Jim_Interp *);
60486715
extern int Jim_fileInit(Jim_Interp *);
60496716
extern int Jim_globInit(Jim_Interp *);
60506717
extern int Jim_execInit(Jim_Interp *);
6718
+extern int Jim_posixInit(Jim_Interp *);
60516719
extern int Jim_clockInit(Jim_Interp *);
60526720
extern int Jim_arrayInit(Jim_Interp *);
60536721
extern int Jim_stdlibInit(Jim_Interp *);
60546722
extern int Jim_tclcompatInit(Jim_Interp *);
60556723
Jim_bootstrapInit(interp);
@@ -6057,20 +6725,18 @@
60576725
Jim_readdirInit(interp);
60586726
Jim_regexpInit(interp);
60596727
Jim_fileInit(interp);
60606728
Jim_globInit(interp);
60616729
Jim_execInit(interp);
6730
+Jim_posixInit(interp);
60626731
Jim_clockInit(interp);
60636732
Jim_arrayInit(interp);
60646733
Jim_stdlibInit(interp);
60656734
Jim_tclcompatInit(interp);
60666735
return JIM_OK;
60676736
}
60686737
#define JIM_OPTIMIZATION
6069
-#ifndef _GNU_SOURCE
6070
-#define _GNU_SOURCE
6071
-#endif
60726738
60736739
#include <stdio.h>
60746740
#include <stdlib.h>
60756741
60766742
#include <string.h>
@@ -6084,11 +6750,11 @@
60846750
60856751
60866752
#ifdef HAVE_SYS_TIME_H
60876753
#include <sys/time.h>
60886754
#endif
6089
-#ifdef HAVE_BACKTRACE
6755
+#ifdef HAVE_EXECINFO_H
60906756
#include <execinfo.h>
60916757
#endif
60926758
#ifdef HAVE_CRT_EXTERNS_H
60936759
#include <crt_externs.h>
60946760
#endif
@@ -6136,10 +6802,11 @@
61366802
#else
61376803
#define JimPanic(X)
61386804
#endif
61396805
61406806
#ifdef JIM_OPTIMIZATION
6807
+static int JimIsWide(Jim_Obj *objPtr);
61416808
#define JIM_IF_OPTIM(X) X
61426809
#else
61436810
#define JIM_IF_OPTIM(X)
61446811
#endif
61456812
@@ -6147,22 +6814,29 @@
61476814
static char JimEmptyStringRep[] = "";
61486815
61496816
static void JimFreeCallFrame(Jim_Interp *interp, Jim_CallFrame *cf, int action);
61506817
static int ListSetIndex(Jim_Interp *interp, Jim_Obj *listPtr, int listindex, Jim_Obj *newObjPtr,
61516818
int flags);
6819
+static int Jim_ListIndices(Jim_Interp *interp, Jim_Obj *listPtr, Jim_Obj *const *indexv, int indexc,
6820
+ Jim_Obj **resultObj, int flags);
61526821
static int JimDeleteLocalProcs(Jim_Interp *interp, Jim_Stack *localCommands);
61536822
static Jim_Obj *JimExpandDictSugar(Jim_Interp *interp, Jim_Obj *objPtr);
61546823
static void SetDictSubstFromAny(Jim_Interp *interp, Jim_Obj *objPtr);
6155
-static Jim_Obj **JimDictPairs(Jim_Obj *dictPtr, int *len);
61566824
static void JimSetFailedEnumResult(Jim_Interp *interp, const char *arg, const char *badtype,
61576825
const char *prefix, const char *const *tablePtr, const char *name);
61586826
static int JimCallProcedure(Jim_Interp *interp, Jim_Cmd *cmd, int argc, Jim_Obj *const *argv);
61596827
static int JimGetWideNoErr(Jim_Interp *interp, Jim_Obj *objPtr, jim_wide * widePtr);
61606828
static int JimSign(jim_wide w);
6161
-static int JimValidName(Jim_Interp *interp, const char *type, Jim_Obj *nameObjPtr);
61626829
static void JimPrngSeed(Jim_Interp *interp, unsigned char *seed, int seedLen);
61636830
static void JimRandomBytes(Jim_Interp *interp, void *dest, unsigned int len);
6831
+static int JimSetNewVariable(Jim_HashTable *ht, Jim_Obj *nameObjPtr, Jim_VarVal *vv);
6832
+static Jim_VarVal *JimFindVariable(Jim_HashTable *ht, Jim_Obj *nameObjPtr);
6833
+static void JimSetErrorStack(Jim_Interp *interp);
6834
+static int SetVariableFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr);
6835
+
6836
+#define JIM_DICT_SUGAR 100
6837
+
61646838
61656839
61666840
61676841
#define JimWideValue(objPtr) (objPtr)->internalRep.wideValue
61686842
@@ -6175,20 +6849,32 @@
61756849
*uc = utf8_upper(*uc);
61766850
}
61776851
return l;
61786852
}
61796853
6854
+static Jim_Obj *JimPushInterpObjImpl(Jim_Obj **iop, Jim_Obj *no)
6855
+{
6856
+ Jim_Obj *io = *iop;
6857
+ Jim_IncrRefCount(no);
6858
+ *iop = no;
6859
+ return io;
6860
+}
6861
+
6862
+#define JimPushInterpObj(IO, NO) JimPushInterpObjImpl(&(IO), NO)
6863
+#define JimPopInterpObj(I, IO, SO) do { Jim_DecrRefCount(I, IO); IO = SO; } while (0)
6864
+
61806865
61816866
#define JIM_CHARSET_SCAN 2
61826867
#define JIM_CHARSET_GLOB 0
61836868
6184
-static const char *JimCharsetMatch(const char *pattern, int c, int flags)
6869
+static const char *JimCharsetMatch(const char *pattern, int plen, int c, int flags)
61856870
{
61866871
int not = 0;
61876872
int pchar;
61886873
int match = 0;
61896874
int nocase = 0;
6875
+ int n;
61906876
61916877
if (flags & JIM_NOCASE) {
61926878
nocase++;
61936879
c = utf8_upper(c);
61946880
}
@@ -6195,34 +6881,40 @@
61956881
61966882
if (flags & JIM_CHARSET_SCAN) {
61976883
if (*pattern == '^') {
61986884
not++;
61996885
pattern++;
6886
+ plen--;
62006887
}
62016888
62026889
62036890
if (*pattern == ']') {
62046891
goto first;
62056892
}
62066893
}
62076894
6208
- while (*pattern && *pattern != ']') {
6895
+ while (plen && *pattern != ']') {
62096896
62106897
if (pattern[0] == '\\') {
62116898
first:
6212
- pattern += utf8_tounicode_case(pattern, &pchar, nocase);
6899
+ n = utf8_tounicode_case(pattern, &pchar, nocase);
6900
+ pattern += n;
6901
+ plen -= n;
62136902
}
62146903
else {
62156904
62166905
int start;
62176906
int end;
62186907
6219
- pattern += utf8_tounicode_case(pattern, &start, nocase);
6220
- if (pattern[0] == '-' && pattern[1]) {
6908
+ n = utf8_tounicode_case(pattern, &start, nocase);
6909
+ pattern += n;
6910
+ plen -= n;
6911
+ if (pattern[0] == '-' && plen > 1) {
62216912
6222
- pattern++;
6223
- pattern += utf8_tounicode_case(pattern, &end, nocase);
6913
+ n = 1 + utf8_tounicode_case(pattern + 1, &end, nocase);
6914
+ pattern += n;
6915
+ plen -= n;
62246916
62256917
62266918
if ((c >= start && c <= end) || (c >= end && c <= start)) {
62276919
match = 1;
62286920
}
@@ -6242,108 +6934,115 @@
62426934
return match ? pattern : NULL;
62436935
}
62446936
62456937
62466938
6247
-static int JimGlobMatch(const char *pattern, const char *string, int nocase)
6939
+static int JimGlobMatch(const char *pattern, int plen, const char *string, int slen, int nocase)
62486940
{
62496941
int c;
62506942
int pchar;
6251
- while (*pattern) {
6252
- switch (pattern[0]) {
6253
- case '*':
6254
- while (pattern[1] == '*') {
6255
- pattern++;
6256
- }
6257
- pattern++;
6258
- if (!pattern[0]) {
6259
- return 1;
6260
- }
6261
- while (*string) {
6262
-
6263
- if (JimGlobMatch(pattern, string, nocase))
6264
- return 1;
6265
- string += utf8_tounicode(string, &c);
6943
+ int n;
6944
+ const char *p;
6945
+ while (plen) {
6946
+ switch (pattern[0]) {
6947
+ case '*':
6948
+ while (pattern[1] == '*' && plen) {
6949
+ pattern++;
6950
+ plen--;
6951
+ }
6952
+ pattern++;
6953
+ plen--;
6954
+ if (!plen) {
6955
+ return 1;
6956
+ }
6957
+ while (slen) {
6958
+
6959
+ if (JimGlobMatch(pattern, plen, string, slen, nocase))
6960
+ return 1;
6961
+ n = utf8_tounicode(string, &c);
6962
+ string += n;
6963
+ slen -= n;
62666964
}
62676965
return 0;
62686966
62696967
case '?':
6270
- string += utf8_tounicode(string, &c);
6968
+ n = utf8_tounicode(string, &c);
6969
+ string += n;
6970
+ slen -= n;
62716971
break;
62726972
62736973
case '[': {
6274
- string += utf8_tounicode(string, &c);
6275
- pattern = JimCharsetMatch(pattern + 1, c, nocase ? JIM_NOCASE : 0);
6276
- if (!pattern) {
6974
+ n = utf8_tounicode(string, &c);
6975
+ string += n;
6976
+ slen -= n;
6977
+ p = JimCharsetMatch(pattern + 1, plen - 1, c, nocase ? JIM_NOCASE : 0);
6978
+ if (!p) {
62776979
return 0;
62786980
}
6279
- if (!*pattern) {
6981
+ plen -= p - pattern;
6982
+ pattern = p;
6983
+
6984
+ if (!plen) {
62806985
62816986
continue;
62826987
}
62836988
break;
62846989
}
62856990
case '\\':
62866991
if (pattern[1]) {
62876992
pattern++;
6993
+ plen--;
62886994
}
62896995
62906996
default:
6291
- string += utf8_tounicode_case(string, &c, nocase);
6997
+ n = utf8_tounicode_case(string, &c, nocase);
6998
+ string += n;
6999
+ slen -= n;
62927000
utf8_tounicode_case(pattern, &pchar, nocase);
62937001
if (pchar != c) {
62947002
return 0;
62957003
}
62967004
break;
62977005
}
6298
- pattern += utf8_tounicode_case(pattern, &pchar, nocase);
6299
- if (!*string) {
6300
- while (*pattern == '*') {
7006
+ n = utf8_tounicode_case(pattern, &pchar, nocase);
7007
+ pattern += n;
7008
+ plen -= n;
7009
+ if (!slen) {
7010
+ while (*pattern == '*' && plen) {
63017011
pattern++;
7012
+ plen--;
63027013
}
63037014
break;
63047015
}
63057016
}
6306
- if (!*pattern && !*string) {
7017
+ if (!plen && !slen) {
63077018
return 1;
63087019
}
63097020
return 0;
63107021
}
63117022
6312
-static int JimStringCompare(const char *s1, int l1, const char *s2, int l2)
6313
-{
6314
- if (l1 < l2) {
6315
- return memcmp(s1, s2, l1) <= 0 ? -1 : 1;
6316
- }
6317
- else if (l2 < l1) {
6318
- return memcmp(s1, s2, l2) >= 0 ? 1 : -1;
6319
- }
6320
- else {
6321
- return JimSign(memcmp(s1, s2, l1));
6322
- }
6323
-}
6324
-
6325
-static int JimStringCompareLen(const char *s1, const char *s2, int maxchars, int nocase)
6326
-{
6327
- while (*s1 && *s2 && maxchars) {
7023
+static int JimStringCompareUtf8(const char *s1, int l1, const char *s2, int l2, int nocase)
7024
+{
7025
+ int minlen = l1;
7026
+ if (l2 < l1) {
7027
+ minlen = l2;
7028
+ }
7029
+ while (minlen) {
63287030
int c1, c2;
63297031
s1 += utf8_tounicode_case(s1, &c1, nocase);
63307032
s2 += utf8_tounicode_case(s2, &c2, nocase);
63317033
if (c1 != c2) {
63327034
return JimSign(c1 - c2);
63337035
}
6334
- maxchars--;
6335
- }
6336
- if (!maxchars) {
6337
- return 0;
7036
+ minlen--;
63387037
}
63397038
6340
- if (*s1) {
6341
- return 1;
6342
- }
6343
- if (*s2) {
7039
+ if (l1 < l2) {
63447040
return -1;
7041
+ }
7042
+ if (l1 > l2) {
7043
+ return 1;
63457044
}
63467045
return 0;
63477046
}
63487047
63497048
static int JimStringFirst(const char *s1, int l1, const char *s2, int l2, int idx)
@@ -6416,11 +7115,11 @@
64167115
64177116
static int JimNumberBase(const char *str, int *base, int *sign)
64187117
{
64197118
int i = 0;
64207119
6421
- *base = 10;
7120
+ *base = 0;
64227121
64237122
while (isspace(UCHAR(str[i]))) {
64247123
i++;
64257124
}
64267125
@@ -6443,30 +7142,31 @@
64437142
64447143
switch (str[i + 1]) {
64457144
case 'x': case 'X': *base = 16; break;
64467145
case 'o': case 'O': *base = 8; break;
64477146
case 'b': case 'B': *base = 2; break;
7147
+ case 'd': case 'D': *base = 10; break;
64487148
default: return 0;
64497149
}
64507150
i += 2;
64517151
64527152
if (str[i] != '-' && str[i] != '+' && !isspace(UCHAR(str[i]))) {
64537153
64547154
return i;
64557155
}
64567156
6457
- *base = 10;
7157
+ *base = 0;
64587158
return 0;
64597159
}
64607160
64617161
static long jim_strtol(const char *str, char **endptr)
64627162
{
64637163
int sign;
64647164
int base;
64657165
int i = JimNumberBase(str, &base, &sign);
64667166
6467
- if (base != 10) {
7167
+ if (base != 0) {
64687168
long value = strtol(str + i, endptr, base);
64697169
if (endptr == NULL || *endptr != str + i) {
64707170
return value * sign;
64717171
}
64727172
}
@@ -6481,11 +7181,11 @@
64817181
#ifdef HAVE_LONG_LONG
64827182
int sign;
64837183
int base;
64847184
int i = JimNumberBase(str, &base, &sign);
64857185
6486
- if (base != 10) {
7186
+ if (base != 0) {
64877187
jim_wide value = strtoull(str + i, endptr, base);
64887188
if (endptr == NULL || *endptr != str + i) {
64897189
return value * sign;
64907190
}
64917191
}
@@ -6563,11 +7263,11 @@
65637263
fprintf(stderr, "\nJIM INTERPRETER PANIC: ");
65647264
vfprintf(stderr, fmt, ap);
65657265
fprintf(stderr, "\n\n");
65667266
va_end(ap);
65677267
6568
-#ifdef HAVE_BACKTRACE
7268
+#if defined(HAVE_BACKTRACE)
65697269
{
65707270
void *array[40];
65717271
int size, i;
65727272
char **strings;
65737273
@@ -6583,48 +7283,64 @@
65837283
exit(1);
65847284
}
65857285
#endif
65867286
65877287
6588
-void *Jim_Alloc(int size)
7288
+void *JimDefaultAllocator(void *ptr, size_t size)
65897289
{
6590
- return size ? malloc(size) : NULL;
7290
+ if (size == 0) {
7291
+ free(ptr);
7292
+ return NULL;
7293
+ }
7294
+ else if (ptr) {
7295
+ return realloc(ptr, size);
7296
+ }
7297
+ else {
7298
+ return malloc(size);
7299
+ }
65917300
}
65927301
6593
-void Jim_Free(void *ptr)
6594
-{
6595
- free(ptr);
6596
-}
6597
-
6598
-void *Jim_Realloc(void *ptr, int size)
6599
-{
6600
- return realloc(ptr, size);
6601
-}
7302
+void *(*Jim_Allocator)(void *ptr, size_t size) = JimDefaultAllocator;
66027303
66037304
char *Jim_StrDup(const char *s)
66047305
{
6605
- return strdup(s);
7306
+ return Jim_StrDupLen(s, strlen(s));
66067307
}
66077308
66087309
char *Jim_StrDupLen(const char *s, int l)
66097310
{
66107311
char *copy = Jim_Alloc(l + 1);
66117312
6612
- memcpy(copy, s, l + 1);
7313
+ memcpy(copy, s, l);
66137314
copy[l] = 0;
66147315
return copy;
66157316
}
66167317
66177318
6618
-
6619
-static jim_wide JimClock(void)
7319
+jim_wide Jim_GetTimeUsec(unsigned type)
66207320
{
7321
+ long long now;
66217322
struct timeval tv;
66227323
6623
- gettimeofday(&tv, NULL);
6624
- return (jim_wide) tv.tv_sec * 1000000 + tv.tv_usec;
7324
+#if defined(HAVE_CLOCK_GETTIME)
7325
+ struct timespec ts;
7326
+
7327
+ if (clock_gettime(type, &ts) == 0) {
7328
+ now = ts.tv_sec * 1000000LL + ts.tv_nsec / 1000;
7329
+ }
7330
+ else
7331
+#endif
7332
+ {
7333
+ gettimeofday(&tv, NULL);
7334
+
7335
+ now = tv.tv_sec * 1000000LL + tv.tv_usec;
7336
+ }
7337
+
7338
+ return now;
66257339
}
7340
+
7341
+
66267342
66277343
66287344
66297345
static void JimExpandHashTableIfNeeded(Jim_HashTable *ht);
66307346
static unsigned int JimHashTableNextPower(unsigned int size);
@@ -6642,19 +7358,20 @@
66427358
key += ~(key << 11);
66437359
key ^= (key >> 16);
66447360
return key;
66457361
}
66467362
6647
-unsigned int Jim_GenHashFunction(const unsigned char *buf, int len)
6648
-{
6649
- unsigned int h = 0;
6650
-
6651
- while (len--)
6652
- h += (h << 3) + *buf++;
6653
- return h;
6654
-}
6655
-
7363
+
7364
+unsigned int Jim_GenHashFunction(const unsigned char *string, int length)
7365
+{
7366
+ unsigned result = 0;
7367
+ string += length;
7368
+ while (length--) {
7369
+ result += (result << 3) + (unsigned char)(*--string);
7370
+ }
7371
+ return result;
7372
+}
66567373
66577374
66587375
66597376
static void JimResetHashTable(Jim_HashTable *ht)
66607377
{
@@ -6685,19 +7402,10 @@
66857402
ht->type = type;
66867403
ht->privdata = privDataPtr;
66877404
return JIM_OK;
66887405
}
66897406
6690
-void Jim_ResizeHashTable(Jim_HashTable *ht)
6691
-{
6692
- int minimal = ht->used;
6693
-
6694
- if (minimal < JIM_HT_INITIAL_SIZE)
6695
- minimal = JIM_HT_INITIAL_SIZE;
6696
- Jim_ExpandHashTable(ht, minimal);
6697
-}
6698
-
66997407
67007408
void Jim_ExpandHashTable(Jim_HashTable *ht, unsigned int size)
67017409
{
67027410
Jim_HashTable n;
67037411
unsigned int realsize = JimHashTableNextPower(size), i;
@@ -6742,16 +7450,13 @@
67427450
67437451
67447452
*ht = n;
67457453
}
67467454
6747
-
67487455
int Jim_AddHashEntry(Jim_HashTable *ht, const void *key, void *val)
67497456
{
6750
- Jim_HashEntry *entry;
6751
-
6752
- entry = JimInsertHashEntry(ht, key, 0);
7457
+ Jim_HashEntry *entry = JimInsertHashEntry(ht, key, 0);;
67537458
if (entry == NULL)
67547459
return JIM_ERR;
67557460
67567461
67577462
Jim_SetHashKey(ht, entry, key);
@@ -6786,61 +7491,62 @@
67867491
}
67877492
67887493
return existed;
67897494
}
67907495
6791
-
67927496
int Jim_DeleteHashEntry(Jim_HashTable *ht, const void *key)
67937497
{
6794
- unsigned int h;
6795
- Jim_HashEntry *he, *prevHe;
6796
-
6797
- if (ht->used == 0)
6798
- return JIM_ERR;
6799
- h = Jim_HashKey(ht, key) & ht->sizemask;
6800
- he = ht->table[h];
6801
-
6802
- prevHe = NULL;
6803
- while (he) {
6804
- if (Jim_CompareHashKeys(ht, key, he->key)) {
6805
-
6806
- if (prevHe)
6807
- prevHe->next = he->next;
6808
- else
6809
- ht->table[h] = he->next;
6810
- Jim_FreeEntryKey(ht, he);
6811
- Jim_FreeEntryVal(ht, he);
6812
- Jim_Free(he);
6813
- ht->used--;
6814
- return JIM_OK;
6815
- }
6816
- prevHe = he;
6817
- he = he->next;
6818
- }
6819
- return JIM_ERR;
6820
-}
6821
-
6822
-
6823
-int Jim_FreeHashTable(Jim_HashTable *ht)
7498
+ if (ht->used) {
7499
+ unsigned int h = Jim_HashKey(ht, key) & ht->sizemask;
7500
+ Jim_HashEntry *prevHe = NULL;
7501
+ Jim_HashEntry *he = ht->table[h];
7502
+
7503
+ while (he) {
7504
+ if (Jim_CompareHashKeys(ht, key, he->key)) {
7505
+
7506
+ if (prevHe)
7507
+ prevHe->next = he->next;
7508
+ else
7509
+ ht->table[h] = he->next;
7510
+ ht->used--;
7511
+ Jim_FreeEntryKey(ht, he);
7512
+ Jim_FreeEntryVal(ht, he);
7513
+ Jim_Free(he);
7514
+ return JIM_OK;
7515
+ }
7516
+ prevHe = he;
7517
+ he = he->next;
7518
+ }
7519
+ }
7520
+
7521
+ return JIM_ERR;
7522
+}
7523
+
7524
+void Jim_ClearHashTable(Jim_HashTable *ht)
68247525
{
68257526
unsigned int i;
68267527
68277528
68287529
for (i = 0; ht->used > 0; i++) {
68297530
Jim_HashEntry *he, *nextHe;
68307531
6831
- if ((he = ht->table[i]) == NULL)
6832
- continue;
7532
+ he = ht->table[i];
68337533
while (he) {
68347534
nextHe = he->next;
68357535
Jim_FreeEntryKey(ht, he);
68367536
Jim_FreeEntryVal(ht, he);
68377537
Jim_Free(he);
68387538
ht->used--;
68397539
he = nextHe;
68407540
}
7541
+ ht->table[i] = NULL;
68417542
}
7543
+}
7544
+
7545
+int Jim_FreeHashTable(Jim_HashTable *ht)
7546
+{
7547
+ Jim_ClearHashTable(ht);
68427548
68437549
Jim_Free(ht->table);
68447550
68457551
JimResetHashTable(ht);
68467552
return JIM_OK;
@@ -7140,10 +7846,13 @@
71407846
if (!pc->len) {
71417847
pc->tstart = pc->p;
71427848
pc->tend = pc->p - 1;
71437849
pc->tline = pc->linenr;
71447850
pc->tt = JIM_TT_EOL;
7851
+ if (pc->inquote) {
7852
+ pc->missing.ch = '"';
7853
+ }
71457854
pc->eof = 1;
71467855
return JIM_OK;
71477856
}
71487857
switch (*(pc->p)) {
71497858
case '\\':
@@ -7354,10 +8063,13 @@
73548063
break;
73558064
73568065
case '"':
73578066
if (startofword) {
73588067
JimParseSubQuote(pc);
8068
+ if (pc->missing.ch == '"') {
8069
+ return;
8070
+ }
73598071
continue;
73608072
}
73618073
break;
73628074
73638075
case '{':
@@ -8305,37 +9017,28 @@
83059017
}
83069018
}
83079019
83089020
int Jim_StringMatchObj(Jim_Interp *interp, Jim_Obj *patternObjPtr, Jim_Obj *objPtr, int nocase)
83099021
{
8310
- return JimGlobMatch(Jim_String(patternObjPtr), Jim_String(objPtr), nocase);
9022
+ int plen, slen;
9023
+ const char *pattern = Jim_GetString(patternObjPtr, &plen);
9024
+ const char *string = Jim_GetString(objPtr, &slen);
9025
+ return JimGlobMatch(pattern, plen, string, slen, nocase);
83119026
}
83129027
83139028
int Jim_StringCompareObj(Jim_Interp *interp, Jim_Obj *firstObjPtr, Jim_Obj *secondObjPtr, int nocase)
83149029
{
8315
- int l1, l2;
8316
- const char *s1 = Jim_GetString(firstObjPtr, &l1);
8317
- const char *s2 = Jim_GetString(secondObjPtr, &l2);
8318
-
8319
- if (nocase) {
8320
-
8321
- return JimStringCompareLen(s1, s2, -1, nocase);
8322
- }
8323
- return JimStringCompare(s1, l1, s2, l2);
8324
-}
8325
-
8326
-int Jim_StringCompareLenObj(Jim_Interp *interp, Jim_Obj *firstObjPtr, Jim_Obj *secondObjPtr, int nocase)
8327
-{
83289030
const char *s1 = Jim_String(firstObjPtr);
9031
+ int l1 = Jim_Utf8Length(interp, firstObjPtr);
83299032
const char *s2 = Jim_String(secondObjPtr);
8330
-
8331
- return JimStringCompareLen(s1, s2, Jim_Utf8Length(interp, firstObjPtr), nocase);
9033
+ int l2 = Jim_Utf8Length(interp, secondObjPtr);
9034
+ return JimStringCompareUtf8(s1, l1, s2, l2, nocase);
83329035
}
83339036
83349037
static int JimRelToAbsIndex(int len, int idx)
83359038
{
8336
- if (idx < 0)
9039
+ if (idx < 0 && idx > -INT_MAX)
83379040
return len + idx;
83389041
return idx;
83399042
}
83409043
83419044
static void JimRelToAbsRange(int len, int *firstPtr, int *lastPtr, int *rangeLenPtr)
@@ -8849,11 +9552,11 @@
88499552
static const Jim_ObjType scriptObjType = {
88509553
"script",
88519554
FreeScriptInternalRep,
88529555
DupScriptInternalRep,
88539556
NULL,
8854
- JIM_TYPE_REFERENCES,
9557
+ JIM_TYPE_NONE,
88559558
};
88569559
88579560
typedef struct ScriptToken
88589561
{
88599562
Jim_Obj *objPtr;
@@ -9223,12 +9926,10 @@
92239926
Jim_FreeIntRep(interp, objPtr);
92249927
Jim_SetIntRepPtr(objPtr, script);
92259928
objPtr->typePtr = &scriptObjType;
92269929
}
92279930
9228
-static void JimAddErrorToStack(Jim_Interp *interp, ScriptObj *script);
9229
-
92309931
static ScriptObj *JimGetScript(Jim_Interp *interp, Jim_Obj *objPtr)
92319932
{
92329933
if (objPtr == interp->emptyObj) {
92339934
92349935
objPtr = interp->nullScriptObj;
@@ -9239,19 +9940,22 @@
92399940
}
92409941
92419942
return (ScriptObj *)Jim_GetIntRepPtr(objPtr);
92429943
}
92439944
9244
-static int JimScriptValid(Jim_Interp *interp, ScriptObj *script)
9245
-{
9246
- if (JimParseCheckMissing(interp, script->missing) == JIM_ERR) {
9247
- JimAddErrorToStack(interp, script);
9248
- return 0;
9249
- }
9250
- return 1;
9251
-}
9252
-
9945
+void Jim_InterpIncrProcEpoch(Jim_Interp *interp)
9946
+{
9947
+ interp->procEpoch++;
9948
+
9949
+
9950
+ while (interp->oldCmdCache) {
9951
+ Jim_Cmd *next = interp->oldCmdCache->prevCmd;
9952
+ Jim_Free(interp->oldCmdCache);
9953
+ interp->oldCmdCache = next;
9954
+ }
9955
+ interp->oldCmdCacheSize = 0;
9956
+}
92539957
92549958
static void JimIncrCmdRefCount(Jim_Cmd *cmdPtr)
92559959
{
92569960
cmdPtr->inUse++;
92579961
}
@@ -9276,65 +9980,156 @@
92769980
}
92779981
if (cmdPtr->prevCmd) {
92789982
92799983
JimDecrCmdRefCount(interp, cmdPtr->prevCmd);
92809984
}
9281
- Jim_Free(cmdPtr);
9985
+
9986
+ cmdPtr->prevCmd = interp->oldCmdCache;
9987
+ interp->oldCmdCache = cmdPtr;
9988
+ if (!interp->quitting && ++interp->oldCmdCacheSize >= 1000) {
9989
+ Jim_InterpIncrProcEpoch(interp);
9990
+ }
9991
+ }
9992
+}
9993
+
9994
+static void JimIncrVarRef(Jim_VarVal *vv)
9995
+{
9996
+ vv->refCount++;
9997
+}
9998
+
9999
+static void JimDecrVarRef(Jim_Interp *interp, Jim_VarVal *vv)
10000
+{
10001
+ assert(vv->refCount > 0);
10002
+ if (--vv->refCount == 0) {
10003
+ if (vv->objPtr) {
10004
+ Jim_DecrRefCount(interp, vv->objPtr);
10005
+ }
10006
+ Jim_Free(vv);
928210007
}
928310008
}
928410009
928510010
static void JimVariablesHTValDestructor(void *interp, void *val)
928610011
{
9287
- Jim_DecrRefCount(interp, ((Jim_Var *)val)->objPtr);
9288
- Jim_Free(val);
10012
+ JimDecrVarRef(interp, val);
10013
+}
10014
+
10015
+static unsigned int JimObjectHTHashFunction(const void *key)
10016
+{
10017
+ Jim_Obj *keyObj = (Jim_Obj *)key;
10018
+ int length;
10019
+ const char *string;
10020
+
10021
+#ifdef JIM_OPTIMIZATION
10022
+ if (JimIsWide(keyObj) && keyObj->bytes == NULL) {
10023
+
10024
+ jim_wide objValue = JimWideValue(keyObj);
10025
+ if (objValue > INT_MIN && objValue < INT_MAX) {
10026
+ unsigned result = 0;
10027
+ unsigned value = (unsigned)objValue;
10028
+
10029
+ if (objValue < 0) {
10030
+ value = (unsigned)-objValue;
10031
+ }
10032
+
10033
+
10034
+ do {
10035
+ result += (result << 3) + (value % 10 + '0');
10036
+ value /= 10;
10037
+ } while (value);
10038
+
10039
+ if (objValue < 0) {
10040
+ result += (result << 3) + '-';
10041
+ }
10042
+ return result;
10043
+ }
10044
+ }
10045
+#endif
10046
+ string = Jim_GetString(keyObj, &length);
10047
+ return Jim_GenHashFunction((const unsigned char *)string, length);
10048
+}
10049
+
10050
+static int JimObjectHTKeyCompare(void *privdata, const void *key1, const void *key2)
10051
+{
10052
+ return Jim_StringEqObj((Jim_Obj *)key1, (Jim_Obj *)key2);
10053
+}
10054
+
10055
+static void *JimObjectHTKeyValDup(void *privdata, const void *val)
10056
+{
10057
+ Jim_IncrRefCount((Jim_Obj *)val);
10058
+ return (void *)val;
10059
+}
10060
+
10061
+static void JimObjectHTKeyValDestructor(void *interp, void *val)
10062
+{
10063
+ Jim_DecrRefCount(interp, (Jim_Obj *)val);
10064
+}
10065
+
10066
+
10067
+static void *JimVariablesHTValDup(void *privdata, const void *val)
10068
+{
10069
+ JimIncrVarRef((Jim_VarVal *)val);
10070
+ return (void *)val;
928910071
}
929010072
929110073
static const Jim_HashTableType JimVariablesHashTableType = {
9292
- JimStringCopyHTHashFunction,
9293
- JimStringCopyHTDup,
9294
- NULL,
9295
- JimStringCopyHTKeyCompare,
9296
- JimStringCopyHTKeyDestructor,
10074
+ JimObjectHTHashFunction,
10075
+ JimObjectHTKeyValDup,
10076
+ JimVariablesHTValDup,
10077
+ JimObjectHTKeyCompare,
10078
+ JimObjectHTKeyValDestructor,
929710079
JimVariablesHTValDestructor
929810080
};
929910081
10082
+
10083
+static const char *Jim_GetStringNoQualifier(Jim_Obj *objPtr, int *length)
10084
+{
10085
+ int len;
10086
+ const char *str = Jim_GetString(objPtr, &len);
10087
+ if (len >= 2 && str[0] == ':' && str[1] == ':') {
10088
+ while (len && *str == ':') {
10089
+ len--;
10090
+ str++;
10091
+ }
10092
+ }
10093
+ *length = len;
10094
+ return str;
10095
+}
10096
+
10097
+static unsigned int JimCommandsHT_HashFunction(const void *key)
10098
+{
10099
+ int len;
10100
+ const char *str = Jim_GetStringNoQualifier((Jim_Obj *)key, &len);
10101
+ return Jim_GenHashFunction((const unsigned char *)str, len);
10102
+}
10103
+
10104
+static int JimCommandsHT_KeyCompare(void *privdata, const void *key1, const void *key2)
10105
+{
10106
+ int len1, len2;
10107
+ const char *str1 = Jim_GetStringNoQualifier((Jim_Obj *)key1, &len1);
10108
+ const char *str2 = Jim_GetStringNoQualifier((Jim_Obj *)key2, &len2);
10109
+ return len1 == len2 && memcmp(str1, str2, len1) == 0;
10110
+}
10111
+
930010112
static void JimCommandsHT_ValDestructor(void *interp, void *val)
930110113
{
930210114
JimDecrCmdRefCount(interp, val);
930310115
}
930410116
930510117
static const Jim_HashTableType JimCommandsHashTableType = {
9306
- JimStringCopyHTHashFunction,
9307
- JimStringCopyHTDup,
10118
+ JimCommandsHT_HashFunction,
10119
+ JimObjectHTKeyValDup,
930810120
NULL,
9309
- JimStringCopyHTKeyCompare,
9310
- JimStringCopyHTKeyDestructor,
10121
+ JimCommandsHT_KeyCompare,
10122
+ JimObjectHTKeyValDestructor,
931110123
JimCommandsHT_ValDestructor
931210124
};
931310125
931410126
931510127
9316
-#ifdef jim_ext_namespace
9317
-static Jim_Obj *JimQualifyNameObj(Jim_Interp *interp, Jim_Obj *nsObj)
9318
-{
9319
- const char *name = Jim_String(nsObj);
9320
- if (name[0] == ':' && name[1] == ':') {
9321
-
9322
- while (*++name == ':') {
9323
- }
9324
- nsObj = Jim_NewStringObj(interp, name, -1);
9325
- }
9326
- else if (Jim_Length(interp->framePtr->nsObj)) {
9327
-
9328
- nsObj = Jim_DuplicateObj(interp, interp->framePtr->nsObj);
9329
- Jim_AppendStrings(interp, nsObj, "::", name, NULL);
9330
- }
9331
- return nsObj;
9332
-}
9333
-
933410128
Jim_Obj *Jim_MakeGlobalNamespaceName(Jim_Interp *interp, Jim_Obj *nameObjPtr)
933510129
{
10130
+#ifdef jim_ext_namespace
933610131
Jim_Obj *resultObj;
933710132
933810133
const char *name = Jim_String(nameObjPtr);
933910134
if (name[0] == ':' && name[1] == ':') {
934010135
return nameObjPtr;
@@ -9343,71 +10138,54 @@
934310138
resultObj = Jim_NewStringObj(interp, "::", -1);
934410139
Jim_AppendObj(interp, resultObj, nameObjPtr);
934510140
Jim_DecrRefCount(interp, nameObjPtr);
934610141
934710142
return resultObj;
9348
-}
9349
-
9350
-static const char *JimQualifyName(Jim_Interp *interp, const char *name, Jim_Obj **objPtrPtr)
9351
-{
9352
- Jim_Obj *objPtr = interp->emptyObj;
9353
-
9354
- if (name[0] == ':' && name[1] == ':') {
9355
-
9356
- while (*++name == ':') {
9357
- }
9358
- }
9359
- else if (Jim_Length(interp->framePtr->nsObj)) {
9360
-
9361
- objPtr = Jim_DuplicateObj(interp, interp->framePtr->nsObj);
9362
- Jim_AppendStrings(interp, objPtr, "::", name, NULL);
9363
- name = Jim_String(objPtr);
9364
- }
9365
- Jim_IncrRefCount(objPtr);
9366
- *objPtrPtr = objPtr;
9367
- return name;
9368
-}
9369
-
9370
- #define JimFreeQualifiedName(INTERP, OBJ) Jim_DecrRefCount((INTERP), (OBJ))
9371
-
9372
-#else
9373
-
9374
- #define JimQualifyName(INTERP, NAME, DUMMY) (((NAME)[0] == ':' && (NAME)[1] == ':') ? (NAME) + 2 : (NAME))
9375
- #define JimFreeQualifiedName(INTERP, DUMMY) (void)(DUMMY)
9376
-
9377
-Jim_Obj *Jim_MakeGlobalNamespaceName(Jim_Interp *interp, Jim_Obj *nameObjPtr)
9378
-{
9379
- return nameObjPtr;
9380
-}
9381
-#endif
9382
-
9383
-static int JimCreateCommand(Jim_Interp *interp, const char *name, Jim_Cmd *cmd)
9384
-{
9385
- Jim_HashEntry *he = Jim_FindHashEntry(&interp->commands, name);
9386
- if (he) {
9387
-
9388
- Jim_InterpIncrProcEpoch(interp);
9389
- }
9390
-
9391
- if (he && interp->local) {
9392
-
9393
- cmd->prevCmd = Jim_GetHashEntryVal(he);
9394
- Jim_SetHashVal(&interp->commands, he, cmd);
9395
- }
9396
- else {
9397
- if (he) {
9398
-
9399
- Jim_DeleteHashEntry(&interp->commands, name);
9400
- }
9401
-
9402
- Jim_AddHashEntry(&interp->commands, name, cmd);
9403
- }
9404
- return JIM_OK;
9405
-}
9406
-
9407
-
9408
-int Jim_CreateCommand(Jim_Interp *interp, const char *cmdNameStr,
10143
+#else
10144
+ return nameObjPtr;
10145
+#endif
10146
+}
10147
+
10148
+static Jim_Obj *JimQualifyName(Jim_Interp *interp, Jim_Obj *objPtr)
10149
+{
10150
+#ifdef jim_ext_namespace
10151
+ if (Jim_Length(interp->framePtr->nsObj)) {
10152
+ int len;
10153
+ const char *name = Jim_GetString(objPtr, &len);
10154
+ if (len < 2 || name[0] != ':' || name[1] != ':') {
10155
+
10156
+ objPtr = Jim_DuplicateObj(interp, interp->framePtr->nsObj);
10157
+ Jim_AppendStrings(interp, objPtr, "::", name, NULL);
10158
+ }
10159
+ }
10160
+#endif
10161
+ Jim_IncrRefCount(objPtr);
10162
+ return objPtr;
10163
+}
10164
+
10165
+static void JimCreateCommand(Jim_Interp *interp, Jim_Obj *nameObjPtr, Jim_Cmd *cmd)
10166
+{
10167
+ JimPanic((nameObjPtr->refCount == 0, "JimCreateCommand called with zero ref count name"));
10168
+
10169
+ if (interp->local) {
10170
+ Jim_HashEntry *he = Jim_FindHashEntry(&interp->commands, nameObjPtr);
10171
+ if (he) {
10172
+
10173
+ cmd->prevCmd = Jim_GetHashEntryVal(he);
10174
+ Jim_SetHashVal(&interp->commands, he, cmd);
10175
+
10176
+ Jim_InterpIncrProcEpoch(interp);
10177
+ return;
10178
+ }
10179
+ }
10180
+
10181
+
10182
+
10183
+ Jim_ReplaceHashEntry(&interp->commands, nameObjPtr, cmd);
10184
+}
10185
+
10186
+int Jim_CreateCommandObj(Jim_Interp *interp, Jim_Obj *cmdNameObj,
940910187
Jim_CmdProc *cmdProc, void *privData, Jim_DelCmdProc *delProc)
941010188
{
941110189
Jim_Cmd *cmdPtr = Jim_Alloc(sizeof(*cmdPtr));
941210190
941310191
@@ -9415,15 +10193,24 @@
941510193
cmdPtr->inUse = 1;
941610194
cmdPtr->u.native.delProc = delProc;
941710195
cmdPtr->u.native.cmdProc = cmdProc;
941810196
cmdPtr->u.native.privData = privData;
941910197
9420
- JimCreateCommand(interp, cmdNameStr, cmdPtr);
10198
+ Jim_IncrRefCount(cmdNameObj);
10199
+ JimCreateCommand(interp, cmdNameObj, cmdPtr);
10200
+ Jim_DecrRefCount(interp, cmdNameObj);
942110201
942210202
return JIM_OK;
942310203
}
942410204
10205
+
10206
+int Jim_CreateCommand(Jim_Interp *interp, const char *cmdNameStr,
10207
+ Jim_CmdProc *cmdProc, void *privData, Jim_DelCmdProc *delProc)
10208
+{
10209
+ return Jim_CreateCommandObj(interp, Jim_NewStringObj(interp, cmdNameStr, -1), cmdProc, privData, delProc);
10210
+}
10211
+
942510212
static int JimCreateProcedureStatics(Jim_Interp *interp, Jim_Cmd *cmdPtr, Jim_Obj *staticsListObjPtr)
942610213
{
942710214
int len, i;
942810215
942910216
len = Jim_ListLength(interp, staticsListObjPtr);
@@ -9432,72 +10219,129 @@
943210219
}
943310220
943410221
cmdPtr->u.proc.staticVars = Jim_Alloc(sizeof(Jim_HashTable));
943510222
Jim_InitHashTable(cmdPtr->u.proc.staticVars, &JimVariablesHashTableType, interp);
943610223
for (i = 0; i < len; i++) {
9437
- Jim_Obj *objPtr, *initObjPtr, *nameObjPtr;
9438
- Jim_Var *varPtr;
9439
- int subLen;
9440
-
9441
- objPtr = Jim_ListGetIndex(interp, staticsListObjPtr, i);
9442
-
9443
- subLen = Jim_ListLength(interp, objPtr);
9444
- if (subLen == 1 || subLen == 2) {
9445
- nameObjPtr = Jim_ListGetIndex(interp, objPtr, 0);
9446
- if (subLen == 1) {
9447
- initObjPtr = Jim_GetVariable(interp, nameObjPtr, JIM_NONE);
9448
- if (initObjPtr == NULL) {
9449
- Jim_SetResultFormatted(interp,
9450
- "variable for initialization of static \"%#s\" not found in the local context",
9451
- nameObjPtr);
9452
- return JIM_ERR;
9453
- }
9454
- }
9455
- else {
9456
- initObjPtr = Jim_ListGetIndex(interp, objPtr, 1);
9457
- }
9458
- if (JimValidName(interp, "static variable", nameObjPtr) != JIM_OK) {
9459
- return JIM_ERR;
9460
- }
9461
-
9462
- varPtr = Jim_Alloc(sizeof(*varPtr));
9463
- varPtr->objPtr = initObjPtr;
9464
- Jim_IncrRefCount(initObjPtr);
9465
- varPtr->linkFramePtr = NULL;
9466
- if (Jim_AddHashEntry(cmdPtr->u.proc.staticVars,
9467
- Jim_String(nameObjPtr), varPtr) != JIM_OK) {
9468
- Jim_SetResultFormatted(interp,
9469
- "static variable name \"%#s\" duplicated in statics list", nameObjPtr);
9470
- Jim_DecrRefCount(interp, initObjPtr);
9471
- Jim_Free(varPtr);
9472
- return JIM_ERR;
9473
- }
9474
- }
9475
- else {
10224
+ Jim_Obj *initObjPtr = NULL;
10225
+ Jim_Obj *nameObjPtr;
10226
+ Jim_VarVal *vv = NULL;
10227
+ Jim_Obj *objPtr = Jim_ListGetIndex(interp, staticsListObjPtr, i);
10228
+ int subLen = Jim_ListLength(interp, objPtr);
10229
+ int byref = 0;
10230
+
10231
+
10232
+ if (subLen != 1 && subLen != 2) {
947610233
Jim_SetResultFormatted(interp, "too many fields in static specifier \"%#s\"",
947710234
objPtr);
947810235
return JIM_ERR;
947910236
}
10237
+
10238
+ nameObjPtr = Jim_ListGetIndex(interp, objPtr, 0);
10239
+
10240
+
10241
+ if (subLen == 1) {
10242
+ int len;
10243
+ const char *pt = Jim_GetString(nameObjPtr, &len);
10244
+ if (*pt == '&') {
10245
+
10246
+ nameObjPtr = Jim_NewStringObj(interp, pt + 1, len - 1);
10247
+ byref = 1;
10248
+ }
10249
+ }
10250
+ Jim_IncrRefCount(nameObjPtr);
10251
+
10252
+ if (subLen == 1) {
10253
+ switch (SetVariableFromAny(interp, nameObjPtr)) {
10254
+ case JIM_DICT_SUGAR:
10255
+
10256
+ if (byref) {
10257
+ Jim_SetResultFormatted(interp, "Can't link to array element \"%#s\"", nameObjPtr);
10258
+ }
10259
+ else {
10260
+ Jim_SetResultFormatted(interp, "Can't initialise array element \"%#s\"", nameObjPtr);
10261
+ }
10262
+ Jim_DecrRefCount(interp, nameObjPtr);
10263
+ return JIM_ERR;
10264
+
10265
+ case JIM_OK:
10266
+ if (byref) {
10267
+ vv = nameObjPtr->internalRep.varValue.vv;
10268
+ }
10269
+ else {
10270
+ initObjPtr = Jim_GetVariable(interp, nameObjPtr, JIM_NONE);
10271
+ }
10272
+ break;
10273
+
10274
+ case JIM_ERR:
10275
+
10276
+ Jim_SetResultFormatted(interp,
10277
+ "variable for initialization of static \"%#s\" not found in the local context",
10278
+ nameObjPtr);
10279
+ Jim_DecrRefCount(interp, nameObjPtr);
10280
+ return JIM_ERR;
10281
+ }
10282
+ }
10283
+ else {
10284
+ initObjPtr = Jim_ListGetIndex(interp, objPtr, 1);
10285
+ }
10286
+
10287
+ if (vv == NULL) {
10288
+ vv = Jim_Alloc(sizeof(*vv));
10289
+ vv->objPtr = initObjPtr;
10290
+ Jim_IncrRefCount(vv->objPtr);
10291
+ vv->linkFramePtr = NULL;
10292
+ vv->refCount = 0;
10293
+ }
10294
+
10295
+ if (JimSetNewVariable(cmdPtr->u.proc.staticVars, nameObjPtr, vv) != JIM_OK) {
10296
+ Jim_SetResultFormatted(interp,
10297
+ "static variable name \"%#s\" duplicated in statics list", nameObjPtr);
10298
+ JimIncrVarRef(vv);
10299
+ JimDecrVarRef(interp, vv);
10300
+ Jim_DecrRefCount(interp, nameObjPtr);
10301
+ return JIM_ERR;
10302
+ }
10303
+
10304
+ Jim_DecrRefCount(interp, nameObjPtr);
948010305
}
948110306
return JIM_OK;
948210307
}
948310308
9484
-static void JimUpdateProcNamespace(Jim_Interp *interp, Jim_Cmd *cmdPtr, const char *cmdname)
10309
+
10310
+#ifdef jim_ext_namespace
10311
+static const char *Jim_memrchr(const char *p, int c, int len)
10312
+{
10313
+ int i;
10314
+ for (i = len; i > 0; i--) {
10315
+ if (p[i] == c) {
10316
+ return p + i;
10317
+ }
10318
+ }
10319
+ return NULL;
10320
+}
10321
+#endif
10322
+
10323
+static void JimUpdateProcNamespace(Jim_Interp *interp, Jim_Cmd *cmdPtr, Jim_Obj *nameObjPtr)
948510324
{
948610325
#ifdef jim_ext_namespace
948710326
if (cmdPtr->isproc) {
10327
+ int len;
10328
+ const char *cmdname = Jim_GetStringNoQualifier(nameObjPtr, &len);
948810329
9489
- const char *pt = strrchr(cmdname, ':');
10330
+ const char *pt = Jim_memrchr(cmdname, ':', len);
949010331
if (pt && pt != cmdname && pt[-1] == ':') {
10332
+ pt++;
949110333
Jim_DecrRefCount(interp, cmdPtr->u.proc.nsObj);
9492
- cmdPtr->u.proc.nsObj = Jim_NewStringObj(interp, cmdname, pt - cmdname - 1);
10334
+ cmdPtr->u.proc.nsObj = Jim_NewStringObj(interp, cmdname, pt - cmdname - 2);
949310335
Jim_IncrRefCount(cmdPtr->u.proc.nsObj);
949410336
9495
- if (Jim_FindHashEntry(&interp->commands, pt + 1)) {
10337
+ Jim_Obj *tempObj = Jim_NewStringObj(interp, pt, len - (pt - cmdname));
10338
+ if (Jim_FindHashEntry(&interp->commands, tempObj)) {
949610339
949710340
Jim_InterpIncrProcEpoch(interp);
949810341
}
10342
+ Jim_FreeNewObj(interp, tempObj);
949910343
}
950010344
}
950110345
#endif
950210346
}
950310347
@@ -9510,10 +10354,11 @@
951010354
951110355
argListLen = Jim_ListLength(interp, argListObjPtr);
951210356
951310357
951410358
cmdPtr = Jim_Alloc(sizeof(*cmdPtr) + sizeof(struct Jim_ProcArg) * argListLen);
10359
+ assert(cmdPtr);
951510360
memset(cmdPtr, 0, sizeof(*cmdPtr));
951610361
cmdPtr->inUse = 1;
951710362
cmdPtr->isproc = 1;
951810363
cmdPtr->u.proc.argListObjPtr = argListObjPtr;
951910364
cmdPtr->u.proc.argListLen = argListLen;
@@ -9585,72 +10430,71 @@
958510430
}
958610431
958710432
return cmdPtr;
958810433
}
958910434
9590
-int Jim_DeleteCommand(Jim_Interp *interp, const char *name)
10435
+int Jim_DeleteCommand(Jim_Interp *interp, Jim_Obj *nameObj)
959110436
{
959210437
int ret = JIM_OK;
9593
- Jim_Obj *qualifiedNameObj;
9594
- const char *qualname = JimQualifyName(interp, name, &qualifiedNameObj);
959510438
9596
- if (Jim_DeleteHashEntry(&interp->commands, qualname) == JIM_ERR) {
9597
- Jim_SetResultFormatted(interp, "can't delete \"%s\": command doesn't exist", name);
10439
+ nameObj = JimQualifyName(interp, nameObj);
10440
+
10441
+ if (Jim_DeleteHashEntry(&interp->commands, nameObj) == JIM_ERR) {
10442
+ Jim_SetResultFormatted(interp, "can't delete \"%#s\": command doesn't exist", nameObj);
959810443
ret = JIM_ERR;
959910444
}
9600
- else {
9601
- Jim_InterpIncrProcEpoch(interp);
9602
- }
9603
-
9604
- JimFreeQualifiedName(interp, qualifiedNameObj);
10445
+ Jim_DecrRefCount(interp, nameObj);
960510446
960610447
return ret;
960710448
}
960810449
9609
-int Jim_RenameCommand(Jim_Interp *interp, const char *oldName, const char *newName)
10450
+int Jim_RenameCommand(Jim_Interp *interp, Jim_Obj *oldNameObj, Jim_Obj *newNameObj)
961010451
{
961110452
int ret = JIM_ERR;
961210453
Jim_HashEntry *he;
961310454
Jim_Cmd *cmdPtr;
9614
- Jim_Obj *qualifiedOldNameObj;
9615
- Jim_Obj *qualifiedNewNameObj;
9616
- const char *fqold;
9617
- const char *fqnew;
961810455
9619
- if (newName[0] == 0) {
9620
- return Jim_DeleteCommand(interp, oldName);
10456
+ if (Jim_Length(newNameObj) == 0) {
10457
+ return Jim_DeleteCommand(interp, oldNameObj);
962110458
}
962210459
9623
- fqold = JimQualifyName(interp, oldName, &qualifiedOldNameObj);
9624
- fqnew = JimQualifyName(interp, newName, &qualifiedNewNameObj);
962510460
962610461
9627
- he = Jim_FindHashEntry(&interp->commands, fqold);
10462
+ oldNameObj = JimQualifyName(interp, oldNameObj);
10463
+ newNameObj = JimQualifyName(interp, newNameObj);
10464
+
10465
+
10466
+ he = Jim_FindHashEntry(&interp->commands, oldNameObj);
962810467
if (he == NULL) {
9629
- Jim_SetResultFormatted(interp, "can't rename \"%s\": command doesn't exist", oldName);
10468
+ Jim_SetResultFormatted(interp, "can't rename \"%#s\": command doesn't exist", oldNameObj);
963010469
}
9631
- else if (Jim_FindHashEntry(&interp->commands, fqnew)) {
9632
- Jim_SetResultFormatted(interp, "can't rename to \"%s\": command already exists", newName);
10470
+ else if (Jim_FindHashEntry(&interp->commands, newNameObj)) {
10471
+ Jim_SetResultFormatted(interp, "can't rename to \"%#s\": command already exists", newNameObj);
963310472
}
963410473
else {
9635
-
963610474
cmdPtr = Jim_GetHashEntryVal(he);
9637
- JimIncrCmdRefCount(cmdPtr);
9638
- JimUpdateProcNamespace(interp, cmdPtr, fqnew);
9639
- Jim_AddHashEntry(&interp->commands, fqnew, cmdPtr);
9640
-
9641
-
9642
- Jim_DeleteHashEntry(&interp->commands, fqold);
9643
-
9644
-
9645
- Jim_InterpIncrProcEpoch(interp);
9646
-
9647
- ret = JIM_OK;
9648
- }
9649
-
9650
- JimFreeQualifiedName(interp, qualifiedOldNameObj);
9651
- JimFreeQualifiedName(interp, qualifiedNewNameObj);
10475
+ if (cmdPtr->prevCmd) {
10476
+ Jim_SetResultFormatted(interp, "can't rename local command \"%#s\"", oldNameObj);
10477
+ }
10478
+ else {
10479
+
10480
+ JimIncrCmdRefCount(cmdPtr);
10481
+ JimUpdateProcNamespace(interp, cmdPtr, newNameObj);
10482
+ Jim_AddHashEntry(&interp->commands, newNameObj, cmdPtr);
10483
+
10484
+
10485
+ Jim_DeleteHashEntry(&interp->commands, oldNameObj);
10486
+
10487
+
10488
+ Jim_InterpIncrProcEpoch(interp);
10489
+
10490
+ ret = JIM_OK;
10491
+ }
10492
+ }
10493
+
10494
+ Jim_DecrRefCount(interp, oldNameObj);
10495
+ Jim_DecrRefCount(interp, newNameObj);
965210496
965310497
return ret;
965410498
}
965510499
965610500
@@ -9676,104 +10520,70 @@
967610520
967710521
Jim_Cmd *Jim_GetCommand(Jim_Interp *interp, Jim_Obj *objPtr, int flags)
967810522
{
967910523
Jim_Cmd *cmd;
968010524
9681
- if (objPtr->typePtr != &commandObjType ||
9682
- objPtr->internalRep.cmdValue.procEpoch != interp->procEpoch
9683
-#ifdef jim_ext_namespace
9684
- || !Jim_StringEqObj(objPtr->internalRep.cmdValue.nsObj, interp->framePtr->nsObj)
9685
-#endif
9686
- ) {
9687
-
9688
-
9689
-
9690
- const char *name = Jim_String(objPtr);
9691
- Jim_HashEntry *he;
9692
-
9693
- if (name[0] == ':' && name[1] == ':') {
9694
- while (*++name == ':') {
9695
- }
9696
- }
9697
-#ifdef jim_ext_namespace
9698
- else if (Jim_Length(interp->framePtr->nsObj)) {
9699
-
9700
- Jim_Obj *nameObj = Jim_DuplicateObj(interp, interp->framePtr->nsObj);
9701
- Jim_AppendStrings(interp, nameObj, "::", name, NULL);
9702
- he = Jim_FindHashEntry(&interp->commands, Jim_String(nameObj));
9703
- Jim_FreeNewObj(interp, nameObj);
9704
- if (he) {
9705
- goto found;
9706
- }
9707
- }
9708
-#endif
9709
-
9710
-
9711
- he = Jim_FindHashEntry(&interp->commands, name);
10525
+ if (objPtr->typePtr == &commandObjType
10526
+ && objPtr->internalRep.cmdValue.procEpoch == interp->procEpoch
10527
+#ifdef jim_ext_namespace
10528
+ && Jim_StringEqObj(objPtr->internalRep.cmdValue.nsObj, interp->framePtr->nsObj)
10529
+#endif
10530
+ && objPtr->internalRep.cmdValue.cmdPtr->inUse) {
10531
+
10532
+ cmd = objPtr->internalRep.cmdValue.cmdPtr;
10533
+ }
10534
+ else {
10535
+ Jim_Obj *qualifiedNameObj = JimQualifyName(interp, objPtr);
10536
+ Jim_HashEntry *he = Jim_FindHashEntry(&interp->commands, qualifiedNameObj);
10537
+#ifdef jim_ext_namespace
10538
+ if (he == NULL && Jim_Length(interp->framePtr->nsObj)) {
10539
+ he = Jim_FindHashEntry(&interp->commands, objPtr);
10540
+ }
10541
+#endif
971210542
if (he == NULL) {
971310543
if (flags & JIM_ERRMSG) {
971410544
Jim_SetResultFormatted(interp, "invalid command name \"%#s\"", objPtr);
971510545
}
10546
+ Jim_DecrRefCount(interp, qualifiedNameObj);
971610547
return NULL;
971710548
}
9718
-#ifdef jim_ext_namespace
9719
-found:
9720
-#endif
972110549
cmd = Jim_GetHashEntryVal(he);
10550
+
10551
+ cmd->cmdNameObj = Jim_GetHashEntryKey(he);
972210552
972310553
972410554
Jim_FreeIntRep(interp, objPtr);
972510555
objPtr->typePtr = &commandObjType;
972610556
objPtr->internalRep.cmdValue.procEpoch = interp->procEpoch;
972710557
objPtr->internalRep.cmdValue.cmdPtr = cmd;
972810558
objPtr->internalRep.cmdValue.nsObj = interp->framePtr->nsObj;
972910559
Jim_IncrRefCount(interp->framePtr->nsObj);
9730
- }
9731
- else {
9732
- cmd = objPtr->internalRep.cmdValue.cmdPtr;
10560
+ Jim_DecrRefCount(interp, qualifiedNameObj);
973310561
}
973410562
while (cmd->u.proc.upcall) {
973510563
cmd = cmd->prevCmd;
973610564
}
973710565
return cmd;
973810566
}
973910567
974010568
974110569
9742
-#define JIM_DICT_SUGAR 100
9743
-
9744
-static int SetVariableFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr);
9745
-
974610570
static const Jim_ObjType variableObjType = {
974710571
"variable",
974810572
NULL,
974910573
NULL,
975010574
NULL,
975110575
JIM_TYPE_REFERENCES,
975210576
};
975310577
9754
-static int JimValidName(Jim_Interp *interp, const char *type, Jim_Obj *nameObjPtr)
9755
-{
9756
-
9757
- if (nameObjPtr->typePtr != &variableObjType) {
9758
- int len;
9759
- const char *str = Jim_GetString(nameObjPtr, &len);
9760
- if (memchr(str, '\0', len)) {
9761
- Jim_SetResultFormatted(interp, "%s name contains embedded null", type);
9762
- return JIM_ERR;
9763
- }
9764
- }
9765
- return JIM_OK;
9766
-}
9767
-
976810578
static int SetVariableFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr)
976910579
{
977010580
const char *varName;
977110581
Jim_CallFrame *framePtr;
9772
- Jim_HashEntry *he;
977310582
int global;
977410583
int len;
10584
+ Jim_VarVal *vv;
977510585
977610586
977710587
if (objPtr->typePtr == &variableObjType) {
977810588
framePtr = objPtr->internalRep.varValue.global ? interp->topFramePtr : interp->framePtr;
977910589
if (objPtr->internalRep.varValue.callFrameId == framePtr->id) {
@@ -9783,126 +10593,144 @@
978310593
978410594
}
978510595
else if (objPtr->typePtr == &dictSubstObjType) {
978610596
return JIM_DICT_SUGAR;
978710597
}
9788
- else if (JimValidName(interp, "variable", objPtr) != JIM_OK) {
9789
- return JIM_ERR;
9790
- }
9791
-
979210598
979310599
varName = Jim_GetString(objPtr, &len);
979410600
979510601
979610602
if (len && varName[len - 1] == ')' && strchr(varName, '(') != NULL) {
979710603
return JIM_DICT_SUGAR;
979810604
}
979910605
980010606
if (varName[0] == ':' && varName[1] == ':') {
9801
- while (*++varName == ':') {
10607
+ while (*varName == ':') {
10608
+ varName++;
10609
+ len--;
980210610
}
980310611
global = 1;
980410612
framePtr = interp->topFramePtr;
10613
+
10614
+ Jim_Obj *tempObj = Jim_NewStringObj(interp, varName, len);
10615
+ vv = JimFindVariable(&framePtr->vars, tempObj);
10616
+ Jim_FreeNewObj(interp, tempObj);
980510617
}
980610618
else {
980710619
global = 0;
980810620
framePtr = interp->framePtr;
10621
+
10622
+ vv = JimFindVariable(&framePtr->vars, objPtr);
10623
+ if (vv == NULL && framePtr->staticVars) {
10624
+
10625
+ vv = JimFindVariable(framePtr->staticVars, objPtr);
10626
+ }
980910627
}
981010628
9811
-
9812
- he = Jim_FindHashEntry(&framePtr->vars, varName);
9813
- if (he == NULL) {
9814
- if (!global && framePtr->staticVars) {
9815
-
9816
- he = Jim_FindHashEntry(framePtr->staticVars, varName);
9817
- }
9818
- if (he == NULL) {
9819
- return JIM_ERR;
9820
- }
10629
+ if (vv == NULL) {
10630
+ return JIM_ERR;
982110631
}
982210632
982310633
982410634
Jim_FreeIntRep(interp, objPtr);
982510635
objPtr->typePtr = &variableObjType;
982610636
objPtr->internalRep.varValue.callFrameId = framePtr->id;
9827
- objPtr->internalRep.varValue.varPtr = Jim_GetHashEntryVal(he);
10637
+ objPtr->internalRep.varValue.vv = vv;
982810638
objPtr->internalRep.varValue.global = global;
982910639
return JIM_OK;
983010640
}
983110641
983210642
983310643
static int JimDictSugarSet(Jim_Interp *interp, Jim_Obj *ObjPtr, Jim_Obj *valObjPtr);
983410644
static Jim_Obj *JimDictSugarGet(Jim_Interp *interp, Jim_Obj *ObjPtr, int flags);
983510645
9836
-static Jim_Var *JimCreateVariable(Jim_Interp *interp, Jim_Obj *nameObjPtr, Jim_Obj *valObjPtr)
10646
+static int JimSetNewVariable(Jim_HashTable *ht, Jim_Obj *nameObjPtr, Jim_VarVal *vv)
10647
+{
10648
+ return Jim_AddHashEntry(ht, nameObjPtr, vv);
10649
+}
10650
+
10651
+static Jim_VarVal *JimFindVariable(Jim_HashTable *ht, Jim_Obj *nameObjPtr)
10652
+{
10653
+ Jim_HashEntry *he = Jim_FindHashEntry(ht, nameObjPtr);
10654
+ if (he) {
10655
+ return (Jim_VarVal *)Jim_GetHashEntryVal(he);
10656
+ }
10657
+ return NULL;
10658
+}
10659
+
10660
+static int JimUnsetVariable(Jim_HashTable *ht, Jim_Obj *nameObjPtr)
10661
+{
10662
+ return Jim_DeleteHashEntry(ht, nameObjPtr);
10663
+}
10664
+
10665
+static Jim_VarVal *JimCreateVariable(Jim_Interp *interp, Jim_Obj *nameObjPtr, Jim_Obj *valObjPtr)
983710666
{
983810667
const char *name;
983910668
Jim_CallFrame *framePtr;
984010669
int global;
10670
+ int len;
984110671
984210672
9843
- Jim_Var *var = Jim_Alloc(sizeof(*var));
10673
+ Jim_VarVal *vv = Jim_Alloc(sizeof(*vv));
984410674
9845
- var->objPtr = valObjPtr;
10675
+ vv->objPtr = valObjPtr;
984610676
Jim_IncrRefCount(valObjPtr);
9847
- var->linkFramePtr = NULL;
10677
+ vv->linkFramePtr = NULL;
10678
+ vv->refCount = 0;
984810679
9849
- name = Jim_String(nameObjPtr);
10680
+ name = Jim_GetString(nameObjPtr, &len);
985010681
if (name[0] == ':' && name[1] == ':') {
9851
- while (*++name == ':') {
10682
+ while (*name == ':') {
10683
+ name++;
10684
+ len--;
985210685
}
985310686
framePtr = interp->topFramePtr;
985410687
global = 1;
10688
+ JimSetNewVariable(&framePtr->vars, Jim_NewStringObj(interp, name, len), vv);
985510689
}
985610690
else {
985710691
framePtr = interp->framePtr;
985810692
global = 0;
10693
+ JimSetNewVariable(&framePtr->vars, nameObjPtr, vv);
985910694
}
986010695
9861
-
9862
- Jim_AddHashEntry(&framePtr->vars, name, var);
9863
-
986410696
986510697
Jim_FreeIntRep(interp, nameObjPtr);
986610698
nameObjPtr->typePtr = &variableObjType;
986710699
nameObjPtr->internalRep.varValue.callFrameId = framePtr->id;
9868
- nameObjPtr->internalRep.varValue.varPtr = var;
10700
+ nameObjPtr->internalRep.varValue.vv = vv;
986910701
nameObjPtr->internalRep.varValue.global = global;
987010702
9871
- return var;
10703
+ return vv;
987210704
}
9873
-
987410705
987510706
int Jim_SetVariable(Jim_Interp *interp, Jim_Obj *nameObjPtr, Jim_Obj *valObjPtr)
987610707
{
987710708
int err;
9878
- Jim_Var *var;
10709
+ Jim_VarVal *vv;
987910710
988010711
switch (SetVariableFromAny(interp, nameObjPtr)) {
988110712
case JIM_DICT_SUGAR:
988210713
return JimDictSugarSet(interp, nameObjPtr, valObjPtr);
988310714
988410715
case JIM_ERR:
9885
- if (JimValidName(interp, "variable", nameObjPtr) != JIM_OK) {
9886
- return JIM_ERR;
9887
- }
988810716
JimCreateVariable(interp, nameObjPtr, valObjPtr);
988910717
break;
989010718
989110719
case JIM_OK:
9892
- var = nameObjPtr->internalRep.varValue.varPtr;
9893
- if (var->linkFramePtr == NULL) {
10720
+ vv = nameObjPtr->internalRep.varValue.vv;
10721
+ if (vv->linkFramePtr == NULL) {
989410722
Jim_IncrRefCount(valObjPtr);
9895
- Jim_DecrRefCount(interp, var->objPtr);
9896
- var->objPtr = valObjPtr;
10723
+ Jim_DecrRefCount(interp, vv->objPtr);
10724
+ vv->objPtr = valObjPtr;
989710725
}
989810726
else {
989910727
Jim_CallFrame *savedCallFrame;
990010728
990110729
savedCallFrame = interp->framePtr;
9902
- interp->framePtr = var->linkFramePtr;
9903
- err = Jim_SetVariable(interp, var->objPtr, valObjPtr);
10730
+ interp->framePtr = vv->linkFramePtr;
10731
+ err = Jim_SetVariable(interp, vv->objPtr, valObjPtr);
990410732
interp->framePtr = savedCallFrame;
990510733
if (err != JIM_OK)
990610734
return err;
990710735
}
990810736
}
@@ -9949,51 +10777,57 @@
994910777
Jim_Obj *targetNameObjPtr, Jim_CallFrame *targetCallFrame)
995010778
{
995110779
const char *varName;
995210780
const char *targetName;
995310781
Jim_CallFrame *framePtr;
9954
- Jim_Var *varPtr;
10782
+ Jim_VarVal *vv;
10783
+ int len;
10784
+ int varnamelen;
995510785
995610786
995710787
switch (SetVariableFromAny(interp, nameObjPtr)) {
995810788
case JIM_DICT_SUGAR:
995910789
996010790
Jim_SetResultFormatted(interp, "bad variable name \"%#s\": upvar won't create a scalar variable that looks like an array element", nameObjPtr);
996110791
return JIM_ERR;
996210792
996310793
case JIM_OK:
9964
- varPtr = nameObjPtr->internalRep.varValue.varPtr;
10794
+ vv = nameObjPtr->internalRep.varValue.vv;
996510795
9966
- if (varPtr->linkFramePtr == NULL) {
10796
+ if (vv->linkFramePtr == NULL) {
996710797
Jim_SetResultFormatted(interp, "variable \"%#s\" already exists", nameObjPtr);
996810798
return JIM_ERR;
996910799
}
997010800
997110801
9972
- varPtr->linkFramePtr = NULL;
10802
+ vv->linkFramePtr = NULL;
997310803
break;
997410804
}
997510805
997610806
997710807
9978
- varName = Jim_String(nameObjPtr);
10808
+ varName = Jim_GetString(nameObjPtr, &varnamelen);
997910809
998010810
if (varName[0] == ':' && varName[1] == ':') {
9981
- while (*++varName == ':') {
10811
+ while (*varName == ':') {
10812
+ varName++;
10813
+ varnamelen--;
998210814
}
998310815
998410816
framePtr = interp->topFramePtr;
998510817
}
998610818
else {
998710819
framePtr = interp->framePtr;
998810820
}
998910821
9990
- targetName = Jim_String(targetNameObjPtr);
10822
+ targetName = Jim_GetString(targetNameObjPtr, &len);
999110823
if (targetName[0] == ':' && targetName[1] == ':') {
9992
- while (*++targetName == ':') {
10824
+ while (*targetName == ':') {
10825
+ targetName++;
10826
+ len--;
999310827
}
9994
- targetNameObjPtr = Jim_NewStringObj(interp, targetName, -1);
10828
+ targetNameObjPtr = Jim_NewStringObj(interp, targetName, len);
999510829
targetCallFrame = interp->topFramePtr;
999610830
}
999710831
Jim_IncrRefCount(targetNameObjPtr);
999810832
999910833
if (framePtr->level < targetCallFrame->level) {
@@ -10008,49 +10842,52 @@
1000810842
if (framePtr == targetCallFrame) {
1000910843
Jim_Obj *objPtr = targetNameObjPtr;
1001010844
1001110845
1001210846
while (1) {
10013
- if (strcmp(Jim_String(objPtr), varName) == 0) {
10847
+ if (Jim_Length(objPtr) == varnamelen && memcmp(Jim_String(objPtr), varName, varnamelen) == 0) {
1001410848
Jim_SetResultString(interp, "can't upvar from variable to itself", -1);
1001510849
Jim_DecrRefCount(interp, targetNameObjPtr);
1001610850
return JIM_ERR;
1001710851
}
1001810852
if (SetVariableFromAny(interp, objPtr) != JIM_OK)
1001910853
break;
10020
- varPtr = objPtr->internalRep.varValue.varPtr;
10021
- if (varPtr->linkFramePtr != targetCallFrame)
10854
+ vv = objPtr->internalRep.varValue.vv;
10855
+ if (vv->linkFramePtr != targetCallFrame)
1002210856
break;
10023
- objPtr = varPtr->objPtr;
10857
+ objPtr = vv->objPtr;
1002410858
}
1002510859
}
1002610860
1002710861
1002810862
Jim_SetVariable(interp, nameObjPtr, targetNameObjPtr);
1002910863
10030
- nameObjPtr->internalRep.varValue.varPtr->linkFramePtr = targetCallFrame;
10864
+ nameObjPtr->internalRep.varValue.vv->linkFramePtr = targetCallFrame;
1003110865
Jim_DecrRefCount(interp, targetNameObjPtr);
1003210866
return JIM_OK;
1003310867
}
1003410868
1003510869
Jim_Obj *Jim_GetVariable(Jim_Interp *interp, Jim_Obj *nameObjPtr, int flags)
1003610870
{
10871
+ if (interp->safeexpr) {
10872
+ return nameObjPtr;
10873
+ }
1003710874
switch (SetVariableFromAny(interp, nameObjPtr)) {
1003810875
case JIM_OK:{
10039
- Jim_Var *varPtr = nameObjPtr->internalRep.varValue.varPtr;
10876
+ Jim_VarVal *vv = nameObjPtr->internalRep.varValue.vv;
1004010877
10041
- if (varPtr->linkFramePtr == NULL) {
10042
- return varPtr->objPtr;
10878
+ if (vv->linkFramePtr == NULL) {
10879
+ return vv->objPtr;
1004310880
}
1004410881
else {
1004510882
Jim_Obj *objPtr;
1004610883
1004710884
1004810885
Jim_CallFrame *savedCallFrame = interp->framePtr;
1004910886
10050
- interp->framePtr = varPtr->linkFramePtr;
10051
- objPtr = Jim_GetVariable(interp, varPtr->objPtr, flags);
10887
+ interp->framePtr = vv->linkFramePtr;
10888
+ objPtr = Jim_GetVariable(interp, vv->objPtr, flags);
1005210889
interp->framePtr = savedCallFrame;
1005310890
if (objPtr) {
1005410891
return objPtr;
1005510892
}
1005610893
@@ -10105,40 +10942,47 @@
1010510942
return objPtr;
1010610943
}
1010710944
1010810945
int Jim_UnsetVariable(Jim_Interp *interp, Jim_Obj *nameObjPtr, int flags)
1010910946
{
10110
- Jim_Var *varPtr;
10947
+ Jim_VarVal *vv;
1011110948
int retval;
1011210949
Jim_CallFrame *framePtr;
1011310950
1011410951
retval = SetVariableFromAny(interp, nameObjPtr);
1011510952
if (retval == JIM_DICT_SUGAR) {
1011610953
1011710954
return JimDictSugarSet(interp, nameObjPtr, NULL);
1011810955
}
1011910956
else if (retval == JIM_OK) {
10120
- varPtr = nameObjPtr->internalRep.varValue.varPtr;
10957
+ vv = nameObjPtr->internalRep.varValue.vv;
1012110958
1012210959
10123
- if (varPtr->linkFramePtr) {
10960
+ if (vv->linkFramePtr) {
1012410961
framePtr = interp->framePtr;
10125
- interp->framePtr = varPtr->linkFramePtr;
10126
- retval = Jim_UnsetVariable(interp, varPtr->objPtr, JIM_NONE);
10962
+ interp->framePtr = vv->linkFramePtr;
10963
+ retval = Jim_UnsetVariable(interp, vv->objPtr, JIM_NONE);
1012710964
interp->framePtr = framePtr;
1012810965
}
1012910966
else {
10130
- const char *name = Jim_String(nameObjPtr);
1013110967
if (nameObjPtr->internalRep.varValue.global) {
10132
- name += 2;
10968
+ int len;
10969
+ const char *name = Jim_GetString(nameObjPtr, &len);
10970
+ while (*name == ':') {
10971
+ name++;
10972
+ len--;
10973
+ }
1013310974
framePtr = interp->topFramePtr;
10975
+ Jim_Obj *tempObj = Jim_NewStringObj(interp, name, len);
10976
+ retval = JimUnsetVariable(&framePtr->vars, tempObj);
10977
+ Jim_FreeNewObj(interp, tempObj);
1013410978
}
1013510979
else {
1013610980
framePtr = interp->framePtr;
10981
+ retval = JimUnsetVariable(&framePtr->vars, nameObjPtr);
1013710982
}
1013810983
10139
- retval = Jim_DeleteHashEntry(&framePtr->vars, name);
1014010984
if (retval == JIM_OK) {
1014110985
1014210986
framePtr->id = interp->callFrameEpoch++;
1014310987
}
1014410988
}
@@ -10290,10 +11134,14 @@
1029011134
1029111135
static Jim_Obj *JimExpandDictSugar(Jim_Interp *interp, Jim_Obj *objPtr)
1029211136
{
1029311137
Jim_Obj *resObjPtr = NULL;
1029411138
Jim_Obj *substKeyObjPtr = NULL;
11139
+
11140
+ if (interp->safeexpr) {
11141
+ return objPtr;
11142
+ }
1029511143
1029611144
SetDictSubstFromAny(interp, objPtr);
1029711145
1029811146
if (Jim_SubstObj(interp, objPtr->internalRep.dictSubstValue.indexObjPtr,
1029911147
&substKeyObjPtr, JIM_NONE)
@@ -10307,18 +11155,10 @@
1030711155
Jim_DecrRefCount(interp, substKeyObjPtr);
1030811156
1030911157
return resObjPtr;
1031011158
}
1031111159
10312
-static Jim_Obj *JimExpandExprSugar(Jim_Interp *interp, Jim_Obj *objPtr)
10313
-{
10314
- if (Jim_EvalExpression(interp, objPtr) == JIM_OK) {
10315
- return Jim_GetResult(interp);
10316
- }
10317
- return NULL;
10318
-}
10319
-
1032011160
1032111161
static Jim_CallFrame *JimCreateCallFrame(Jim_Interp *interp, Jim_CallFrame *parent, Jim_Obj *nsObj)
1032211162
{
1032311163
Jim_CallFrame *cf;
1032411164
@@ -10357,18 +11197,12 @@
1035711197
1035811198
if (localCommands) {
1035911199
Jim_Obj *cmdNameObj;
1036011200
1036111201
while ((cmdNameObj = Jim_StackPop(localCommands)) != NULL) {
10362
- Jim_HashEntry *he;
10363
- Jim_Obj *fqObjName;
1036411202
Jim_HashTable *ht = &interp->commands;
10365
-
10366
- const char *fqname = JimQualifyName(interp, Jim_String(cmdNameObj), &fqObjName);
10367
-
10368
- he = Jim_FindHashEntry(ht, fqname);
10369
-
11203
+ Jim_HashEntry *he = Jim_FindHashEntry(ht, cmdNameObj);
1037011204
if (he) {
1037111205
Jim_Cmd *cmd = Jim_GetHashEntryVal(he);
1037211206
if (cmd->prevCmd) {
1037311207
Jim_Cmd *prevCmd = cmd->prevCmd;
1037411208
cmd->prevCmd = NULL;
@@ -10378,16 +11212,14 @@
1037811212
1037911213
1038011214
Jim_SetHashVal(ht, he, prevCmd);
1038111215
}
1038211216
else {
10383
- Jim_DeleteHashEntry(ht, fqname);
11217
+ Jim_DeleteHashEntry(ht, cmdNameObj);
1038411218
}
10385
- Jim_InterpIncrProcEpoch(interp);
1038611219
}
1038711220
Jim_DecrRefCount(interp, cmdNameObj);
10388
- JimFreeQualifiedName(interp, fqObjName);
1038911221
}
1039011222
Jim_FreeStack(localCommands);
1039111223
Jim_Free(localCommands);
1039211224
}
1039311225
return JIM_OK;
@@ -10396,15 +11228,14 @@
1039611228
static int JimInvokeDefer(Jim_Interp *interp, int retcode)
1039711229
{
1039811230
Jim_Obj *objPtr;
1039911231
1040011232
10401
- if (Jim_FindHashEntry(&interp->framePtr->vars, "jim::defer") == NULL) {
11233
+ if (JimFindVariable(&interp->framePtr->vars, interp->defer) == NULL) {
1040211234
return retcode;
1040311235
}
10404
-
10405
- objPtr = Jim_GetVariableStr(interp, "jim::defer", JIM_NONE);
11236
+ objPtr = Jim_GetVariable(interp, interp->defer, JIM_NONE);
1040611237
1040711238
if (objPtr) {
1040811239
int ret = JIM_OK;
1040911240
int i;
1041011241
int listLen = Jim_ListLength(interp, objPtr);
@@ -10452,28 +11283,11 @@
1045211283
Jim_DecrRefCount(interp, cf->procBodyObjPtr);
1045311284
Jim_DecrRefCount(interp, cf->nsObj);
1045411285
if (action == JIM_FCF_FULL || cf->vars.size != JIM_HT_INITIAL_SIZE)
1045511286
Jim_FreeHashTable(&cf->vars);
1045611287
else {
10457
- int i;
10458
- Jim_HashEntry **table = cf->vars.table, *he;
10459
-
10460
- for (i = 0; i < JIM_HT_INITIAL_SIZE; i++) {
10461
- he = table[i];
10462
- while (he != NULL) {
10463
- Jim_HashEntry *nextEntry = he->next;
10464
- Jim_Var *varPtr = Jim_GetHashEntryVal(he);
10465
-
10466
- Jim_DecrRefCount(interp, varPtr->objPtr);
10467
- Jim_Free(Jim_GetHashEntryKey(he));
10468
- Jim_Free(varPtr);
10469
- Jim_Free(he);
10470
- table[i] = NULL;
10471
- he = nextEntry;
10472
- }
10473
- }
10474
- cf->vars.used = 0;
11288
+ Jim_ClearHashTable(&cf->vars);
1047511289
}
1047611290
cf->next = interp->freeFramesList;
1047711291
interp->freeFramesList = cf;
1047811292
}
1047911293
@@ -10496,11 +11310,11 @@
1049611310
1049711311
memset(i, 0, sizeof(*i));
1049811312
1049911313
i->maxCallFrameDepth = JIM_MAX_CALLFRAME_DEPTH;
1050011314
i->maxEvalDepth = JIM_MAX_EVAL_DEPTH;
10501
- i->lastCollectTime = time(NULL);
11315
+ i->lastCollectTime = Jim_GetTimeUsec(CLOCK_MONOTONIC_RAW);
1050211316
1050311317
Jim_InitHashTable(&i->commands, &JimCommandsHashTableType, i);
1050411318
#ifdef JIM_REFERENCES
1050511319
Jim_InitHashTable(&i->references, &JimReferencesHashTableType, i);
1050611320
#endif
@@ -10508,27 +11322,28 @@
1050811322
Jim_InitHashTable(&i->packages, &JimPackageHashTableType, NULL);
1050911323
i->emptyObj = Jim_NewEmptyStringObj(i);
1051011324
i->trueObj = Jim_NewIntObj(i, 1);
1051111325
i->falseObj = Jim_NewIntObj(i, 0);
1051211326
i->framePtr = i->topFramePtr = JimCreateCallFrame(i, NULL, i->emptyObj);
10513
- i->errorFileNameObj = i->emptyObj;
1051411327
i->result = i->emptyObj;
1051511328
i->stackTrace = Jim_NewListObj(i, NULL, 0);
1051611329
i->unknown = Jim_NewStringObj(i, "unknown", -1);
11330
+ i->defer = Jim_NewStringObj(i, "jim::defer", -1);
1051711331
i->errorProc = i->emptyObj;
10518
- i->currentScriptObj = Jim_NewEmptyStringObj(i);
1051911332
i->nullScriptObj = Jim_NewEmptyStringObj(i);
11333
+ i->evalFrame = &i->topEvalFrame;
11334
+ i->currentFilenameObj = Jim_NewEmptyStringObj(i);
1052011335
Jim_IncrRefCount(i->emptyObj);
10521
- Jim_IncrRefCount(i->errorFileNameObj);
1052211336
Jim_IncrRefCount(i->result);
1052311337
Jim_IncrRefCount(i->stackTrace);
1052411338
Jim_IncrRefCount(i->unknown);
10525
- Jim_IncrRefCount(i->currentScriptObj);
11339
+ Jim_IncrRefCount(i->defer);
1052611340
Jim_IncrRefCount(i->nullScriptObj);
1052711341
Jim_IncrRefCount(i->errorProc);
1052811342
Jim_IncrRefCount(i->trueObj);
1052911343
Jim_IncrRefCount(i->falseObj);
11344
+ Jim_IncrRefCount(i->currentFilenameObj);
1053011345
1053111346
1053211347
Jim_SetVariableStrWithStr(i, JIM_LIBPATH, TCL_LIBRARY);
1053311348
Jim_SetVariableStrWithStr(i, JIM_INTERACTIVE, "0");
1053411349
@@ -10536,21 +11351,25 @@
1053611351
Jim_SetVariableStrWithStr(i, "tcl_platform(os)", TCL_PLATFORM_OS);
1053711352
Jim_SetVariableStrWithStr(i, "tcl_platform(platform)", TCL_PLATFORM_PLATFORM);
1053811353
Jim_SetVariableStrWithStr(i, "tcl_platform(pathSeparator)", TCL_PLATFORM_PATH_SEPARATOR);
1053911354
Jim_SetVariableStrWithStr(i, "tcl_platform(byteOrder)", Jim_IsBigEndian() ? "bigEndian" : "littleEndian");
1054011355
Jim_SetVariableStrWithStr(i, "tcl_platform(threaded)", "0");
11356
+ Jim_SetVariableStrWithStr(i, "tcl_platform(bootstrap)", "0");
1054111357
Jim_SetVariableStr(i, "tcl_platform(pointerSize)", Jim_NewIntObj(i, sizeof(void *)));
1054211358
Jim_SetVariableStr(i, "tcl_platform(wordSize)", Jim_NewIntObj(i, sizeof(jim_wide)));
11359
+ Jim_SetVariableStr(i, "tcl_platform(stackFormat)", Jim_NewIntObj(i, 4));
1054311360
1054411361
return i;
1054511362
}
1054611363
1054711364
void Jim_FreeInterp(Jim_Interp *i)
1054811365
{
1054911366
Jim_CallFrame *cf, *cfx;
1055011367
1055111368
Jim_Obj *objPtr, *nextObjPtr;
11369
+
11370
+ i->quitting = 1;
1055211371
1055311372
1055411373
for (cf = i->framePtr; cf; cf = cfx) {
1055511374
1055611375
JimInvokeDefer(i, JIM_OK);
@@ -10563,20 +11382,27 @@
1056311382
Jim_DecrRefCount(i, i->falseObj);
1056411383
Jim_DecrRefCount(i, i->result);
1056511384
Jim_DecrRefCount(i, i->stackTrace);
1056611385
Jim_DecrRefCount(i, i->errorProc);
1056711386
Jim_DecrRefCount(i, i->unknown);
10568
- Jim_DecrRefCount(i, i->errorFileNameObj);
10569
- Jim_DecrRefCount(i, i->currentScriptObj);
11387
+ Jim_DecrRefCount(i, i->defer);
1057011388
Jim_DecrRefCount(i, i->nullScriptObj);
11389
+ Jim_DecrRefCount(i, i->currentFilenameObj);
11390
+
11391
+
11392
+ Jim_InterpIncrProcEpoch(i);
11393
+
1057111394
Jim_FreeHashTable(&i->commands);
1057211395
#ifdef JIM_REFERENCES
1057311396
Jim_FreeHashTable(&i->references);
1057411397
#endif
1057511398
Jim_FreeHashTable(&i->packages);
1057611399
Jim_Free(i->prngState);
1057711400
Jim_FreeHashTable(&i->assocData);
11401
+ if (i->traceCmdObj) {
11402
+ Jim_DecrRefCount(i, i->traceCmdObj);
11403
+ }
1057811404
1057911405
#ifdef JIM_MAINTAINER
1058011406
if (i->liveList != NULL) {
1058111407
objPtr = i->liveList;
1058211408
@@ -10671,102 +11497,115 @@
1067111497
1067211498
Jim_SetResultFormatted(interp, "bad level \"%s\"", str);
1067311499
return NULL;
1067411500
}
1067511501
10676
-static Jim_CallFrame *JimGetCallFrameByInteger(Jim_Interp *interp, Jim_Obj *levelObjPtr)
11502
+static Jim_CallFrame *JimGetCallFrameByInteger(Jim_Interp *interp, long level)
1067711503
{
10678
- long level;
1067911504
Jim_CallFrame *framePtr;
1068011505
10681
- if (Jim_GetLong(interp, levelObjPtr, &level) == JIM_OK) {
10682
- if (level <= 0) {
10683
-
10684
- level = interp->framePtr->level + level;
10685
- }
10686
-
10687
- if (level == 0) {
10688
- return interp->topFramePtr;
10689
- }
10690
-
11506
+ if (level == 0) {
11507
+ return interp->framePtr;
11508
+ }
11509
+
11510
+ if (level < 0) {
11511
+
11512
+ level = interp->framePtr->level + level;
11513
+ }
11514
+
11515
+ if (level > 0) {
1069111516
1069211517
for (framePtr = interp->framePtr; framePtr; framePtr = framePtr->parent) {
1069311518
if (framePtr->level == level) {
1069411519
return framePtr;
1069511520
}
1069611521
}
1069711522
}
11523
+ return NULL;
11524
+}
1069811525
10699
- Jim_SetResultFormatted(interp, "bad level \"%#s\"", levelObjPtr);
11526
+static Jim_EvalFrame *JimGetEvalFrameByProcLevel(Jim_Interp *interp, int proclevel)
11527
+{
11528
+ Jim_EvalFrame *evalFrame;
11529
+
11530
+ if (proclevel == 0) {
11531
+ return interp->evalFrame;
11532
+ }
11533
+
11534
+ if (proclevel < 0) {
11535
+
11536
+ proclevel = interp->procLevel + proclevel;
11537
+ }
11538
+
11539
+ if (proclevel >= 0) {
11540
+
11541
+ for (evalFrame = interp->evalFrame; evalFrame; evalFrame = evalFrame->parent) {
11542
+ if (evalFrame->procLevel == proclevel) {
11543
+ return evalFrame;
11544
+ }
11545
+ }
11546
+ }
11547
+ return NULL;
11548
+}
11549
+
11550
+static Jim_Obj *JimProcForEvalFrame(Jim_Interp *interp, Jim_EvalFrame *frame)
11551
+{
11552
+ if (frame == interp->evalFrame || (frame->cmd && frame->cmd->cmdNameObj)) {
11553
+ Jim_EvalFrame *e;
11554
+ for (e = frame->parent; e; e = e->parent) {
11555
+ if (e->cmd && e->cmd->isproc && e->cmd->cmdNameObj) {
11556
+ break;
11557
+ }
11558
+ }
11559
+ if (e && e->cmd && e->cmd->cmdNameObj) {
11560
+ return e->cmd->cmdNameObj;
11561
+ }
11562
+ }
1070011563
return NULL;
1070111564
}
1070211565
10703
-static void JimResetStackTrace(Jim_Interp *interp)
11566
+static void JimAddStackFrame(Jim_Interp *interp, Jim_EvalFrame *frame, Jim_Obj *listObj)
1070411567
{
10705
- Jim_DecrRefCount(interp, interp->stackTrace);
10706
- interp->stackTrace = Jim_NewListObj(interp, NULL, 0);
10707
- Jim_IncrRefCount(interp->stackTrace);
11568
+ Jim_Obj *procNameObj = JimProcForEvalFrame(interp, frame);
11569
+ Jim_Obj *fileNameObj = interp->emptyObj;
11570
+ int linenr = 1;
11571
+
11572
+ if (frame->scriptObj) {
11573
+ ScriptObj *script = JimGetScript(interp, frame->scriptObj);
11574
+ fileNameObj = script->fileNameObj;
11575
+ linenr = script->linenr;
11576
+ }
11577
+
11578
+ Jim_ListAppendElement(interp, listObj, procNameObj ? procNameObj : interp->emptyObj);
11579
+ Jim_ListAppendElement(interp, listObj, fileNameObj);
11580
+ Jim_ListAppendElement(interp, listObj, Jim_NewIntObj(interp, linenr));
11581
+ Jim_ListAppendElement(interp, listObj, Jim_NewListObj(interp, frame->argv, frame->argc));
1070811582
}
1070911583
1071011584
static void JimSetStackTrace(Jim_Interp *interp, Jim_Obj *stackTraceObj)
1071111585
{
10712
- int len;
10713
-
1071411586
1071511587
Jim_IncrRefCount(stackTraceObj);
1071611588
Jim_DecrRefCount(interp, interp->stackTrace);
1071711589
interp->stackTrace = stackTraceObj;
1071811590
interp->errorFlag = 1;
10719
-
10720
- len = Jim_ListLength(interp, interp->stackTrace);
10721
- if (len >= 3) {
10722
- if (Jim_Length(Jim_ListGetIndex(interp, interp->stackTrace, len - 2)) == 0) {
10723
- interp->addStackTrace = 1;
10724
- }
10725
- }
10726
-}
10727
-
10728
-static void JimAppendStackTrace(Jim_Interp *interp, const char *procname,
10729
- Jim_Obj *fileNameObj, int linenr)
10730
-{
10731
- if (strcmp(procname, "unknown") == 0) {
10732
- procname = "";
10733
- }
10734
- if (!*procname && !Jim_Length(fileNameObj)) {
10735
-
10736
- return;
10737
- }
10738
-
10739
- if (Jim_IsShared(interp->stackTrace)) {
10740
- Jim_DecrRefCount(interp, interp->stackTrace);
10741
- interp->stackTrace = Jim_DuplicateObj(interp, interp->stackTrace);
10742
- Jim_IncrRefCount(interp->stackTrace);
10743
- }
10744
-
10745
-
10746
- if (!*procname && Jim_Length(fileNameObj)) {
10747
-
10748
- int len = Jim_ListLength(interp, interp->stackTrace);
10749
-
10750
- if (len >= 3) {
10751
- Jim_Obj *objPtr = Jim_ListGetIndex(interp, interp->stackTrace, len - 3);
10752
- if (Jim_Length(objPtr)) {
10753
-
10754
- objPtr = Jim_ListGetIndex(interp, interp->stackTrace, len - 2);
10755
- if (Jim_Length(objPtr) == 0) {
10756
-
10757
- ListSetIndex(interp, interp->stackTrace, len - 2, fileNameObj, 0);
10758
- ListSetIndex(interp, interp->stackTrace, len - 1, Jim_NewIntObj(interp, linenr), 0);
10759
- return;
10760
- }
10761
- }
10762
- }
10763
- }
10764
-
10765
- Jim_ListAppendElement(interp, interp->stackTrace, Jim_NewStringObj(interp, procname, -1));
10766
- Jim_ListAppendElement(interp, interp->stackTrace, fileNameObj);
10767
- Jim_ListAppendElement(interp, interp->stackTrace, Jim_NewIntObj(interp, linenr));
11591
+}
11592
+
11593
+static void JimSetErrorStack(Jim_Interp *interp)
11594
+{
11595
+ if (!interp->errorFlag) {
11596
+ int i;
11597
+ Jim_Obj *stackTrace = Jim_NewListObj(interp, NULL, 0);
11598
+
11599
+ for (i = 0; i <= interp->procLevel; i++) {
11600
+ Jim_EvalFrame *frame = JimGetEvalFrameByProcLevel(interp, -i);
11601
+ if (frame) {
11602
+ JimAddStackFrame(interp, frame, stackTrace);
11603
+ }
11604
+ }
11605
+ JimSetStackTrace(interp, stackTrace);
11606
+ }
1076811607
}
1076911608
1077011609
int Jim_SetAssocData(Jim_Interp *interp, const char *key, Jim_InterpDeleteProc * delProc,
1077111610
void *data)
1077211611
{
@@ -10897,10 +11736,36 @@
1089711736
return JIM_ERR;
1089811737
*widePtr = JimWideValue(objPtr);
1089911738
return JIM_OK;
1090011739
}
1090111740
11741
+int Jim_GetWideExpr(Jim_Interp *interp, Jim_Obj *objPtr, jim_wide * widePtr)
11742
+{
11743
+ int ret = JIM_OK;
11744
+
11745
+ if (objPtr->typePtr == &sourceObjType || objPtr->typePtr == NULL) {
11746
+ SetIntFromAny(interp, objPtr, 0);
11747
+ }
11748
+ if (objPtr->typePtr == &intObjType) {
11749
+ *widePtr = JimWideValue(objPtr);
11750
+ }
11751
+ else {
11752
+ JimPanic((interp->safeexpr, "interp->safeexpr is set"));
11753
+ interp->safeexpr++;
11754
+ ret = Jim_EvalExpression(interp, objPtr);
11755
+ interp->safeexpr--;
11756
+
11757
+ if (ret == JIM_OK) {
11758
+ ret = Jim_GetWide(interp, Jim_GetResult(interp), widePtr);
11759
+ }
11760
+ if (ret != JIM_OK) {
11761
+ Jim_SetResultFormatted(interp, "expected integer expression but got \"%#s\"", objPtr);
11762
+ }
11763
+ }
11764
+ return ret;
11765
+}
11766
+
1090211767
1090311768
static int JimGetWideNoErr(Jim_Interp *interp, Jim_Obj *objPtr, jim_wide * widePtr)
1090411769
{
1090511770
if (objPtr->typePtr != &intObjType && SetIntFromAny(interp, objPtr, JIM_NONE) == JIM_ERR)
1090611771
return JIM_ERR;
@@ -10943,15 +11808,15 @@
1094311808
NULL,
1094411809
UpdateStringOfDouble,
1094511810
JIM_TYPE_NONE,
1094611811
};
1094711812
10948
-#ifndef HAVE_ISNAN
11813
+#if !HAVE_DECL_ISNAN
1094911814
#undef isnan
1095011815
#define isnan(X) ((X) != (X))
1095111816
#endif
10952
-#ifndef HAVE_ISINF
11817
+#if !HAVE_DECL_ISINF
1095311818
#undef isinf
1095411819
#define isinf(X) (1.0 / (X) == 0.0)
1095511820
#endif
1095611821
1095711822
static void UpdateStringOfDouble(struct Jim_Obj *objPtr)
@@ -11078,38 +11943,37 @@
1107811943
if (objPtr->typePtr != &intObjType && SetBooleanFromAny(interp, objPtr, JIM_ERRMSG) == JIM_ERR)
1107911944
return JIM_ERR;
1108011945
*booleanPtr = (int) JimWideValue(objPtr);
1108111946
return JIM_OK;
1108211947
}
11948
+
11949
+static const char * const jim_true_false_strings[8] = {
11950
+ "1", "true", "yes", "on",
11951
+ "0", "false", "no", "off"
11952
+};
11953
+
11954
+static const int jim_true_false_lens[8] = {
11955
+ 1, 4, 3, 2,
11956
+ 1, 5, 2, 3,
11957
+};
1108311958
1108411959
static int SetBooleanFromAny(Jim_Interp *interp, Jim_Obj *objPtr, int flags)
1108511960
{
11086
- static const char * const falses[] = {
11087
- "0", "false", "no", "off", NULL
11088
- };
11089
- static const char * const trues[] = {
11090
- "1", "true", "yes", "on", NULL
11091
- };
11092
-
11093
- int boolean;
11094
-
11095
- int index;
11096
- if (Jim_GetEnum(interp, objPtr, falses, &index, NULL, 0) == JIM_OK) {
11097
- boolean = 0;
11098
- } else if (Jim_GetEnum(interp, objPtr, trues, &index, NULL, 0) == JIM_OK) {
11099
- boolean = 1;
11100
- } else {
11961
+ int index = Jim_FindByName(Jim_String(objPtr), jim_true_false_strings,
11962
+ sizeof(jim_true_false_strings) / sizeof(*jim_true_false_strings));
11963
+ if (index < 0) {
1110111964
if (flags & JIM_ERRMSG) {
1110211965
Jim_SetResultFormatted(interp, "expected boolean but got \"%#s\"", objPtr);
1110311966
}
1110411967
return JIM_ERR;
1110511968
}
1110611969
1110711970
1110811971
Jim_FreeIntRep(interp, objPtr);
1110911972
objPtr->typePtr = &intObjType;
11110
- objPtr->internalRep.wideValue = boolean;
11973
+
11974
+ objPtr->internalRep.wideValue = index < 4 ? 1 : 0;
1111111975
return JIM_OK;
1111211976
}
1111311977
1111411978
static void ListInsertElements(Jim_Obj *listPtr, int idx, int elemc, Jim_Obj *const *elemVec);
1111511979
static void ListAppendElement(Jim_Obj *listPtr, Jim_Obj *objPtr);
@@ -11404,28 +12268,26 @@
1140412268
int linenr;
1140512269
1140612270
if (objPtr->typePtr == &listObjType) {
1140712271
return JIM_OK;
1140812272
}
12273
+
1140912274
1141012275
if (Jim_IsDict(objPtr) && objPtr->bytes == NULL) {
11411
- Jim_Obj **listObjPtrPtr;
11412
- int len;
11413
- int i;
11414
-
11415
- listObjPtrPtr = JimDictPairs(objPtr, &len);
11416
- for (i = 0; i < len; i++) {
11417
- Jim_IncrRefCount(listObjPtrPtr[i]);
11418
- }
12276
+ Jim_Dict *dict = objPtr->internalRep.dictValue;
1141912277
1142012278
11421
- Jim_FreeIntRep(interp, objPtr);
1142212279
objPtr->typePtr = &listObjType;
11423
- objPtr->internalRep.listValue.len = len;
11424
- objPtr->internalRep.listValue.maxLen = len;
11425
- objPtr->internalRep.listValue.ele = listObjPtrPtr;
12280
+ objPtr->internalRep.listValue.len = dict->len;
12281
+ objPtr->internalRep.listValue.maxLen = dict->maxLen;
12282
+ objPtr->internalRep.listValue.ele = dict->table;
1142612283
12284
+
12285
+ Jim_Free(dict->ht);
12286
+
12287
+
12288
+ Jim_Free(dict);
1142712289
return JIM_OK;
1142812290
}
1142912291
1143012292
1143112293
if (objPtr->typePtr == &sourceObjType) {
@@ -11513,12 +12375,12 @@
1151312375
JIM_LSORT_INTEGER,
1151412376
JIM_LSORT_REAL,
1151512377
JIM_LSORT_COMMAND
1151612378
} type;
1151712379
int order;
11518
- int index;
11519
- int indexed;
12380
+ Jim_Obj **indexv;
12381
+ int indexc;
1152012382
int unique;
1152112383
int (*subfn)(Jim_Obj **, Jim_Obj **);
1152212384
};
1152312385
1152412386
static struct lsort_info *sort_info;
@@ -11525,12 +12387,12 @@
1152512387
1152612388
static int ListSortIndexHelper(Jim_Obj **lhsObj, Jim_Obj **rhsObj)
1152712389
{
1152812390
Jim_Obj *lObj, *rObj;
1152912391
11530
- if (Jim_ListIndex(sort_info->interp, *lhsObj, sort_info->index, &lObj, JIM_ERRMSG) != JIM_OK ||
11531
- Jim_ListIndex(sort_info->interp, *rhsObj, sort_info->index, &rObj, JIM_ERRMSG) != JIM_OK) {
12392
+ if (Jim_ListIndices(sort_info->interp, *lhsObj, sort_info->indexv, sort_info->indexc, &lObj, JIM_ERRMSG) != JIM_OK ||
12393
+ Jim_ListIndices(sort_info->interp, *rhsObj, sort_info->indexv, sort_info->indexc, &rObj, JIM_ERRMSG) != JIM_OK) {
1153212394
longjmp(sort_info->jmpbuf, JIM_ERR);
1153312395
}
1153412396
return sort_info->subfn(&lObj, &rObj);
1153512397
}
1153612398
@@ -11663,11 +12525,11 @@
1166312525
fn = NULL;
1166412526
JimPanic((1, "ListSort called with invalid sort type"));
1166512527
return -1;
1166612528
}
1166712529
11668
- if (info->indexed) {
12530
+ if (info->indexc) {
1166912531
1167012532
info->subfn = fn;
1167112533
fn = ListSortIndexHelper;
1167212534
}
1167312535
@@ -11683,30 +12545,39 @@
1168312545
sort_info = prev_info;
1168412546
1168512547
return rc;
1168612548
}
1168712549
12550
+
12551
+static void ListEnsureLength(Jim_Obj *listPtr, int idx)
12552
+{
12553
+ assert(idx >= 0);
12554
+ if (idx >= listPtr->internalRep.listValue.maxLen) {
12555
+ if (idx < 4) {
12556
+
12557
+ idx = 4;
12558
+ }
12559
+ listPtr->internalRep.listValue.ele = Jim_Realloc(listPtr->internalRep.listValue.ele,
12560
+ sizeof(Jim_Obj *) * idx);
12561
+
12562
+ listPtr->internalRep.listValue.maxLen = idx;
12563
+ }
12564
+}
12565
+
1168812566
static void ListInsertElements(Jim_Obj *listPtr, int idx, int elemc, Jim_Obj *const *elemVec)
1168912567
{
1169012568
int currentLen = listPtr->internalRep.listValue.len;
1169112569
int requiredLen = currentLen + elemc;
1169212570
int i;
1169312571
Jim_Obj **point;
1169412572
1169512573
if (requiredLen > listPtr->internalRep.listValue.maxLen) {
11696
- if (requiredLen < 2) {
12574
+ if (currentLen) {
1169712575
11698
- requiredLen = 4;
11699
- }
11700
- else {
1170112576
requiredLen *= 2;
1170212577
}
11703
-
11704
- listPtr->internalRep.listValue.ele = Jim_Realloc(listPtr->internalRep.listValue.ele,
11705
- sizeof(Jim_Obj *) * requiredLen);
11706
-
11707
- listPtr->internalRep.listValue.maxLen = requiredLen;
12578
+ ListEnsureLength(listPtr, requiredLen);
1170812579
}
1170912580
if (idx < 0) {
1171012581
idx = currentLen;
1171112582
}
1171212583
point = listPtr->internalRep.listValue.ele + idx;
@@ -11786,10 +12657,51 @@
1178612657
}
1178712658
return JIM_ERR;
1178812659
}
1178912660
return JIM_OK;
1179012661
}
12662
+
12663
+static int Jim_ListIndices(Jim_Interp *interp, Jim_Obj *listPtr,
12664
+ Jim_Obj *const *indexv, int indexc, Jim_Obj **resultObj, int flags)
12665
+{
12666
+ int i;
12667
+ int static_idxes[5];
12668
+ int *idxes = static_idxes;
12669
+ int ret = JIM_OK;
12670
+
12671
+ if (indexc > sizeof(static_idxes) / sizeof(*static_idxes)) {
12672
+ idxes = Jim_Alloc(indexc * sizeof(*idxes));
12673
+ }
12674
+
12675
+ for (i = 0; i < indexc; i++) {
12676
+ ret = Jim_GetIndex(interp, indexv[i], &idxes[i]);
12677
+ if (ret != JIM_OK) {
12678
+ goto err;
12679
+ }
12680
+ }
12681
+
12682
+ for (i = 0; i < indexc; i++) {
12683
+ Jim_Obj *objPtr = Jim_ListGetIndex(interp, listPtr, idxes[i]);
12684
+ if (!objPtr) {
12685
+ if (flags & JIM_ERRMSG) {
12686
+ if (idxes[i] < 0 || idxes[i] > Jim_ListLength(interp, listPtr)) {
12687
+ Jim_SetResultFormatted(interp, "index \"%#s\" out of range", indexv[i]);
12688
+ }
12689
+ else {
12690
+ Jim_SetResultFormatted(interp, "element %#s missing from sublist \"%#s\"", indexv[i], listPtr);
12691
+ }
12692
+ }
12693
+ return -1;
12694
+ }
12695
+ listPtr = objPtr;
12696
+ }
12697
+ *resultObj = listPtr;
12698
+err:
12699
+ if (idxes != static_idxes)
12700
+ Jim_Free(idxes);
12701
+ return ret;
12702
+}
1179112703
1179212704
static int ListSetIndex(Jim_Interp *interp, Jim_Obj *listPtr, int idx,
1179312705
Jim_Obj *newObjPtr, int flags)
1179412706
{
1179512707
SetListFromAny(interp, listPtr);
@@ -11821,11 +12733,14 @@
1182112733
varObjPtr = objPtr = Jim_DuplicateObj(interp, objPtr);
1182212734
for (i = 0; i < indexc - 1; i++) {
1182312735
listObjPtr = objPtr;
1182412736
if (Jim_GetIndex(interp, indexv[i], &idx) != JIM_OK)
1182512737
goto err;
11826
- if (Jim_ListIndex(interp, listObjPtr, idx, &objPtr, JIM_ERRMSG) != JIM_OK) {
12738
+
12739
+ objPtr = Jim_ListGetIndex(interp, listObjPtr, idx);
12740
+ if (objPtr == NULL) {
12741
+ Jim_SetResultFormatted(interp, "index \"%#s\" out of range", indexv[i]);
1182712742
goto err;
1182812743
}
1182912744
if (Jim_IsShared(objPtr)) {
1183012745
objPtr = Jim_DuplicateObj(interp, objPtr);
1183112746
ListSetIndex(interp, listObjPtr, idx, objPtr, JIM_NONE);
@@ -11948,112 +12863,186 @@
1194812863
static void DupDictInternalRep(Jim_Interp *interp, Jim_Obj *srcPtr, Jim_Obj *dupPtr);
1194912864
static void UpdateStringOfDict(struct Jim_Obj *objPtr);
1195012865
static int SetDictFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr);
1195112866
1195212867
11953
-static unsigned int JimObjectHTHashFunction(const void *key)
11954
-{
11955
- int len;
11956
- const char *str = Jim_GetString((Jim_Obj *)key, &len);
11957
- return Jim_GenHashFunction((const unsigned char *)str, len);
11958
-}
11959
-
11960
-static int JimObjectHTKeyCompare(void *privdata, const void *key1, const void *key2)
11961
-{
11962
- return Jim_StringEqObj((Jim_Obj *)key1, (Jim_Obj *)key2);
11963
-}
11964
-
11965
-static void *JimObjectHTKeyValDup(void *privdata, const void *val)
11966
-{
11967
- Jim_IncrRefCount((Jim_Obj *)val);
11968
- return (void *)val;
11969
-}
11970
-
11971
-static void JimObjectHTKeyValDestructor(void *interp, void *val)
11972
-{
11973
- Jim_DecrRefCount(interp, (Jim_Obj *)val);
11974
-}
11975
-
11976
-static const Jim_HashTableType JimDictHashTableType = {
11977
- JimObjectHTHashFunction,
11978
- JimObjectHTKeyValDup,
11979
- JimObjectHTKeyValDup,
11980
- JimObjectHTKeyCompare,
11981
- JimObjectHTKeyValDestructor,
11982
- JimObjectHTKeyValDestructor
11983
-};
11984
-
1198512868
static const Jim_ObjType dictObjType = {
1198612869
"dict",
1198712870
FreeDictInternalRep,
1198812871
DupDictInternalRep,
1198912872
UpdateStringOfDict,
1199012873
JIM_TYPE_NONE,
1199112874
};
1199212875
11993
-void FreeDictInternalRep(Jim_Interp *interp, Jim_Obj *objPtr)
11994
-{
11995
- JIM_NOTUSED(interp);
11996
-
11997
- Jim_FreeHashTable(objPtr->internalRep.ptr);
11998
- Jim_Free(objPtr->internalRep.ptr);
11999
-}
12000
-
12001
-void DupDictInternalRep(Jim_Interp *interp, Jim_Obj *srcPtr, Jim_Obj *dupPtr)
12002
-{
12003
- Jim_HashTable *ht, *dupHt;
12004
- Jim_HashTableIterator htiter;
12005
- Jim_HashEntry *he;
12006
-
12007
-
12008
- ht = srcPtr->internalRep.ptr;
12009
- dupHt = Jim_Alloc(sizeof(*dupHt));
12010
- Jim_InitHashTable(dupHt, &JimDictHashTableType, interp);
12011
- if (ht->size != 0)
12012
- Jim_ExpandHashTable(dupHt, ht->size);
12013
-
12014
- JimInitHashTableIterator(ht, &htiter);
12015
- while ((he = Jim_NextHashEntry(&htiter)) != NULL) {
12016
- Jim_AddHashEntry(dupHt, he->key, he->u.val);
12017
- }
12018
-
12019
- dupPtr->internalRep.ptr = dupHt;
12020
- dupPtr->typePtr = &dictObjType;
12021
-}
12022
-
12023
-static Jim_Obj **JimDictPairs(Jim_Obj *dictPtr, int *len)
12024
-{
12025
- Jim_HashTable *ht;
12026
- Jim_HashTableIterator htiter;
12027
- Jim_HashEntry *he;
12028
- Jim_Obj **objv;
12876
+static void JimFreeDict(Jim_Interp *interp, Jim_Dict *dict)
12877
+{
12878
+ int i;
12879
+ for (i = 0; i < dict->len; i++) {
12880
+ Jim_DecrRefCount(interp, dict->table[i]);
12881
+ }
12882
+ Jim_Free(dict->table);
12883
+ Jim_Free(dict->ht);
12884
+ Jim_Free(dict);
12885
+}
12886
+
12887
+enum {
12888
+ DICT_HASH_FIND = -1,
12889
+ DICT_HASH_REMOVE = -2,
12890
+ DICT_HASH_ADD = -3,
12891
+};
12892
+
12893
+static int JimDictHashFind(Jim_Dict *dict, Jim_Obj *keyObjPtr, int op_tvoffset)
12894
+{
12895
+ unsigned h = (JimObjectHTHashFunction(keyObjPtr) + dict->uniq);
12896
+ unsigned idx = h & dict->sizemask;
12897
+ int tvoffset = 0;
12898
+ unsigned peturb = h;
12899
+ unsigned first_removed = ~0;
12900
+
12901
+ if (dict->len) {
12902
+ while ((tvoffset = dict->ht[idx].offset)) {
12903
+ if (tvoffset == -1) {
12904
+ if (first_removed == ~0) {
12905
+ first_removed = idx;
12906
+ }
12907
+ }
12908
+ else if (dict->ht[idx].hash == h) {
12909
+ if (Jim_StringEqObj(keyObjPtr, dict->table[tvoffset - 1])) {
12910
+ break;
12911
+ }
12912
+ }
12913
+
12914
+ peturb >>= 5;
12915
+ idx = (5 * idx + 1 + peturb) & dict->sizemask;
12916
+ }
12917
+ }
12918
+
12919
+ switch (op_tvoffset) {
12920
+ case DICT_HASH_FIND:
12921
+
12922
+ break;
12923
+ case DICT_HASH_REMOVE:
12924
+ if (tvoffset) {
12925
+
12926
+ dict->ht[idx].offset = -1;
12927
+ dict->dummy++;
12928
+ }
12929
+
12930
+ break;
12931
+ case DICT_HASH_ADD:
12932
+ if (tvoffset == 0) {
12933
+
12934
+ if (first_removed != ~0) {
12935
+ idx = first_removed;
12936
+ dict->dummy--;
12937
+ }
12938
+ dict->ht[idx].offset = dict->len + 1;
12939
+ dict->ht[idx].hash = h;
12940
+ }
12941
+
12942
+ break;
12943
+ default:
12944
+ assert(tvoffset);
12945
+
12946
+ dict->ht[idx].offset = op_tvoffset;
12947
+ break;
12948
+ }
12949
+
12950
+ return tvoffset;
12951
+}
12952
+
12953
+static void JimDictExpandHashTable(Jim_Dict *dict, unsigned int size)
12954
+{
12955
+ int i;
12956
+ struct JimDictHashEntry *prevht = dict->ht;
12957
+ int prevsize = dict->size;
12958
+
12959
+ dict->size = JimHashTableNextPower(size);
12960
+ dict->sizemask = dict->size - 1;
12961
+
12962
+
12963
+ dict->ht = Jim_Alloc(dict->size * sizeof(*dict->ht));
12964
+ memset(dict->ht, 0, dict->size * sizeof(*dict->ht));
12965
+
12966
+
12967
+ for (i = 0; i < prevsize; i++) {
12968
+ if (prevht[i].offset > 0) {
12969
+
12970
+ unsigned h = prevht[i].hash;
12971
+ unsigned idx = h & dict->sizemask;
12972
+ unsigned peturb = h;
12973
+
12974
+ while (dict->ht[idx].offset) {
12975
+ peturb >>= 5;
12976
+ idx = (5 * idx + 1 + peturb) & dict->sizemask;
12977
+ }
12978
+ dict->ht[idx].offset = prevht[i].offset;
12979
+ dict->ht[idx].hash = h;
12980
+ }
12981
+ }
12982
+ Jim_Free(prevht);
12983
+}
12984
+
12985
+static int JimDictAdd(Jim_Dict *dict, Jim_Obj *keyObjPtr)
12986
+{
12987
+ if (dict->size <= dict->len + dict->dummy) {
12988
+ JimDictExpandHashTable(dict, dict->size ? dict->size * 2 : 8);
12989
+ }
12990
+ return JimDictHashFind(dict, keyObjPtr, DICT_HASH_ADD);
12991
+}
12992
+
12993
+static Jim_Dict *JimDictNew(Jim_Interp *interp, int table_size, int ht_size)
12994
+{
12995
+ Jim_Dict *dict = Jim_Alloc(sizeof(*dict));
12996
+ memset(dict, 0, sizeof(*dict));
12997
+
12998
+ if (ht_size) {
12999
+ JimDictExpandHashTable(dict, ht_size);
13000
+ }
13001
+ if (table_size) {
13002
+ dict->table = Jim_Alloc(table_size * sizeof(*dict->table));
13003
+ dict->maxLen = table_size;
13004
+ }
13005
+#ifdef JIM_RANDOMISE_HASH
13006
+ dict->uniq = (rand() ^ time(NULL) ^ clock());
13007
+#endif
13008
+ return dict;
13009
+}
13010
+
13011
+static void FreeDictInternalRep(Jim_Interp *interp, Jim_Obj *objPtr)
13012
+{
13013
+ JimFreeDict(interp, objPtr->internalRep.dictValue);
13014
+}
13015
+
13016
+static void DupDictInternalRep(Jim_Interp *interp, Jim_Obj *srcPtr, Jim_Obj *dupPtr)
13017
+{
13018
+ Jim_Dict *oldDict = srcPtr->internalRep.dictValue;
1202913019
int i;
1203013020
12031
- ht = dictPtr->internalRep.ptr;
13021
+
13022
+ Jim_Dict *newDict = JimDictNew(interp, oldDict->maxLen, oldDict->size);
1203213023
1203313024
12034
- objv = Jim_Alloc((ht->used * 2) * sizeof(Jim_Obj *));
12035
- JimInitHashTableIterator(ht, &htiter);
12036
- i = 0;
12037
- while ((he = Jim_NextHashEntry(&htiter)) != NULL) {
12038
- objv[i++] = Jim_GetHashEntryKey(he);
12039
- objv[i++] = Jim_GetHashEntryVal(he);
12040
- }
12041
- *len = i;
12042
- return objv;
13025
+ for (i = 0; i < oldDict->len; i++) {
13026
+ newDict->table[i] = oldDict->table[i];
13027
+ Jim_IncrRefCount(newDict->table[i]);
13028
+ }
13029
+ newDict->len = oldDict->len;
13030
+
13031
+
13032
+ newDict->uniq = oldDict->uniq;
13033
+
13034
+
13035
+ memcpy(newDict->ht, oldDict->ht, sizeof(*oldDict->ht) * oldDict->size);
13036
+
13037
+ dupPtr->internalRep.dictValue = newDict;
13038
+ dupPtr->typePtr = &dictObjType;
1204313039
}
1204413040
1204513041
static void UpdateStringOfDict(struct Jim_Obj *objPtr)
1204613042
{
12047
-
12048
- int len;
12049
- Jim_Obj **objv = JimDictPairs(objPtr, &len);
12050
-
12051
-
12052
- JimMakeListStringRep(objPtr, objv, len);
12053
-
12054
- Jim_Free(objv);
13043
+ JimMakeListStringRep(objPtr, objPtr->internalRep.dictValue->table, objPtr->internalRep.dictValue->len);
1205513044
}
1205613045
1205713046
static int SetDictFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr)
1205813047
{
1205913048
int listlen;
@@ -12064,34 +13053,49 @@
1206413053
1206513054
if (Jim_IsList(objPtr) && Jim_IsShared(objPtr)) {
1206613055
Jim_String(objPtr);
1206713056
}
1206813057
12069
-
1207013058
listlen = Jim_ListLength(interp, objPtr);
1207113059
if (listlen % 2) {
1207213060
Jim_SetResultString(interp, "missing value to go with key", -1);
1207313061
return JIM_ERR;
1207413062
}
1207513063
else {
1207613064
12077
- Jim_HashTable *ht;
13065
+ Jim_Dict *dict = JimDictNew(interp, 0, listlen);
1207813066
int i;
1207913067
12080
- ht = Jim_Alloc(sizeof(*ht));
12081
- Jim_InitHashTable(ht, &JimDictHashTableType, interp);
13068
+
13069
+ dict->table = objPtr->internalRep.listValue.ele;
13070
+ dict->maxLen = objPtr->internalRep.listValue.maxLen;
13071
+
1208213072
1208313073
for (i = 0; i < listlen; i += 2) {
12084
- Jim_Obj *keyObjPtr = Jim_ListGetIndex(interp, objPtr, i);
12085
- Jim_Obj *valObjPtr = Jim_ListGetIndex(interp, objPtr, i + 1);
13074
+ int tvoffset = JimDictAdd(dict, dict->table[i]);
13075
+ if (tvoffset) {
1208613076
12087
- Jim_ReplaceHashEntry(ht, keyObjPtr, valObjPtr);
13077
+
13078
+ Jim_DecrRefCount(interp, dict->table[tvoffset]);
13079
+
13080
+ dict->table[tvoffset] = dict->table[i + 1];
13081
+
13082
+ Jim_DecrRefCount(interp, dict->table[i]);
13083
+ }
13084
+ else {
13085
+ if (dict->len != i) {
13086
+ dict->table[dict->len++] = dict->table[i];
13087
+ dict->table[dict->len++] = dict->table[i + 1];
13088
+ }
13089
+ else {
13090
+ dict->len += 2;
13091
+ }
13092
+ }
1208813093
}
1208913094
12090
- Jim_FreeIntRep(interp, objPtr);
1209113095
objPtr->typePtr = &dictObjType;
12092
- objPtr->internalRep.ptr = ht;
13096
+ objPtr->internalRep.dictValue = dict;
1209313097
1209413098
return JIM_OK;
1209513099
}
1209613100
}
1209713101
@@ -12098,17 +13102,60 @@
1209813102
1209913103
1210013104
static int DictAddElement(Jim_Interp *interp, Jim_Obj *objPtr,
1210113105
Jim_Obj *keyObjPtr, Jim_Obj *valueObjPtr)
1210213106
{
12103
- Jim_HashTable *ht = objPtr->internalRep.ptr;
12104
-
13107
+ Jim_Dict *dict = objPtr->internalRep.dictValue;
1210513108
if (valueObjPtr == NULL) {
12106
- return Jim_DeleteHashEntry(ht, keyObjPtr);
13109
+
13110
+ int tvoffset = JimDictHashFind(dict, keyObjPtr, DICT_HASH_REMOVE);
13111
+ if (tvoffset) {
13112
+
13113
+ Jim_DecrRefCount(interp, dict->table[tvoffset - 1]);
13114
+ Jim_DecrRefCount(interp, dict->table[tvoffset]);
13115
+ dict->len -= 2;
13116
+ if (tvoffset != dict->len + 1) {
13117
+
13118
+ dict->table[tvoffset - 1] = dict->table[dict->len];
13119
+ dict->table[tvoffset] = dict->table[dict->len + 1];
13120
+
13121
+
13122
+ JimDictHashFind(dict, dict->table[tvoffset - 1], tvoffset);
13123
+ }
13124
+ return JIM_OK;
13125
+ }
13126
+ return JIM_ERR;
1210713127
}
12108
- Jim_ReplaceHashEntry(ht, keyObjPtr, valueObjPtr);
12109
- return JIM_OK;
13128
+ else {
13129
+
13130
+ int tvoffset = JimDictAdd(dict, keyObjPtr);
13131
+ if (tvoffset) {
13132
+
13133
+ Jim_IncrRefCount(valueObjPtr);
13134
+ Jim_DecrRefCount(interp, dict->table[tvoffset]);
13135
+ dict->table[tvoffset] = valueObjPtr;
13136
+ }
13137
+ else {
13138
+ if (dict->maxLen == dict->len) {
13139
+
13140
+ if (dict->maxLen < 4) {
13141
+ dict->maxLen = 4;
13142
+ }
13143
+ else {
13144
+ dict->maxLen *= 2;
13145
+ }
13146
+ dict->table = Jim_Realloc(dict->table, dict->maxLen * sizeof(*dict->table));
13147
+ }
13148
+ Jim_IncrRefCount(keyObjPtr);
13149
+ Jim_IncrRefCount(valueObjPtr);
13150
+
13151
+ dict->table[dict->len++] = keyObjPtr;
13152
+ dict->table[dict->len++] = valueObjPtr;
13153
+
13154
+ }
13155
+ return JIM_OK;
13156
+ }
1211013157
}
1211113158
1211213159
int Jim_DictAddElement(Jim_Interp *interp, Jim_Obj *objPtr,
1211313160
Jim_Obj *keyObjPtr, Jim_Obj *valueObjPtr)
1211413161
{
@@ -12128,50 +13175,57 @@
1212813175
JimPanic((len % 2, "Jim_NewDictObj() 'len' argument must be even"));
1212913176
1213013177
objPtr = Jim_NewObj(interp);
1213113178
objPtr->typePtr = &dictObjType;
1213213179
objPtr->bytes = NULL;
12133
- objPtr->internalRep.ptr = Jim_Alloc(sizeof(Jim_HashTable));
12134
- Jim_InitHashTable(objPtr->internalRep.ptr, &JimDictHashTableType, interp);
13180
+
13181
+ objPtr->internalRep.dictValue = JimDictNew(interp, len, len);
1213513182
for (i = 0; i < len; i += 2)
1213613183
DictAddElement(interp, objPtr, elements[i], elements[i + 1]);
1213713184
return objPtr;
1213813185
}
1213913186
1214013187
int Jim_DictKey(Jim_Interp *interp, Jim_Obj *dictPtr, Jim_Obj *keyPtr,
1214113188
Jim_Obj **objPtrPtr, int flags)
1214213189
{
12143
- Jim_HashEntry *he;
12144
- Jim_HashTable *ht;
13190
+ int tvoffset;
13191
+ Jim_Dict *dict;
1214513192
1214613193
if (SetDictFromAny(interp, dictPtr) != JIM_OK) {
1214713194
return -1;
1214813195
}
12149
- ht = dictPtr->internalRep.ptr;
12150
- if ((he = Jim_FindHashEntry(ht, keyPtr)) == NULL) {
13196
+ dict = dictPtr->internalRep.dictValue;
13197
+ tvoffset = JimDictHashFind(dict, keyPtr, DICT_HASH_FIND);
13198
+ if (tvoffset == 0) {
1215113199
if (flags & JIM_ERRMSG) {
1215213200
Jim_SetResultFormatted(interp, "key \"%#s\" not known in dictionary", keyPtr);
1215313201
}
1215413202
return JIM_ERR;
1215513203
}
12156
- else {
12157
- *objPtrPtr = Jim_GetHashEntryVal(he);
12158
- return JIM_OK;
12159
- }
13204
+ *objPtrPtr = dict->table[tvoffset];
13205
+ return JIM_OK;
1216013206
}
1216113207
13208
+Jim_Obj **Jim_DictPairs(Jim_Interp *interp, Jim_Obj *dictPtr, int *len)
13209
+{
1216213210
12163
-int Jim_DictPairs(Jim_Interp *interp, Jim_Obj *dictPtr, Jim_Obj ***objPtrPtr, int *len)
12164
-{
13211
+ if (Jim_IsList(dictPtr)) {
13212
+ Jim_Obj **table;
13213
+ JimListGetElements(interp, dictPtr, len, &table);
13214
+ if (*len % 2 == 0) {
13215
+ return table;
13216
+ }
13217
+
13218
+ }
1216513219
if (SetDictFromAny(interp, dictPtr) != JIM_OK) {
12166
- return JIM_ERR;
13220
+
13221
+ *len = 1;
13222
+ return NULL;
1216713223
}
12168
- *objPtrPtr = JimDictPairs(dictPtr, len);
12169
-
12170
- return JIM_OK;
13224
+ *len = dictPtr->internalRep.dictValue->len;
13225
+ return dictPtr->internalRep.dictValue->table;
1217113226
}
12172
-
1217313227
1217413228
1217513229
int Jim_DictKeysVector(Jim_Interp *interp, Jim_Obj *dictPtr,
1217613230
Jim_Obj *const *keyv, int keyc, Jim_Obj **objPtrPtr, int flags)
1217713231
{
@@ -12254,11 +13308,14 @@
1225413308
Jim_InvalidateStringRep(objPtr);
1225513309
Jim_InvalidateStringRep(varObjPtr);
1225613310
if (Jim_SetVariable(interp, varNamePtr, varObjPtr) != JIM_OK) {
1225713311
goto err;
1225813312
}
12259
- Jim_SetResult(interp, varObjPtr);
13313
+
13314
+ if (!(flags & JIM_NORESULT)) {
13315
+ Jim_SetResult(interp, varObjPtr);
13316
+ }
1226013317
return JIM_OK;
1226113318
err:
1226213319
if (shared) {
1226313320
Jim_FreeNewObj(interp, varObjPtr);
1226413321
}
@@ -12281,11 +13338,11 @@
1228113338
if (objPtr->internalRep.intValue == -1) {
1228213339
JimSetStringBytes(objPtr, "end");
1228313340
}
1228413341
else {
1228513342
char buf[JIM_INTEGER_SPACE + 1];
12286
- if (objPtr->internalRep.intValue >= 0) {
13343
+ if (objPtr->internalRep.intValue >= 0 || objPtr->internalRep.intValue == -INT_MAX) {
1228713344
sprintf(buf, "%d", objPtr->internalRep.intValue);
1228813345
}
1228913346
else {
1229013347
1229113348
sprintf(buf, "end%d", objPtr->internalRep.intValue + 1);
@@ -12294,49 +13351,49 @@
1229413351
}
1229513352
}
1229613353
1229713354
static int SetIndexFromAny(Jim_Interp *interp, Jim_Obj *objPtr)
1229813355
{
12299
- int idx, end = 0;
13356
+ jim_wide idx;
13357
+ int end = 0;
1230013358
const char *str;
12301
- char *endptr;
13359
+ Jim_Obj *exprObj = objPtr;
13360
+
13361
+ JimPanic((objPtr->refCount == 0, "SetIndexFromAny() called with zero refcount object"));
1230213362
1230313363
1230413364
str = Jim_String(objPtr);
1230513365
1230613366
1230713367
if (strncmp(str, "end", 3) == 0) {
1230813368
end = 1;
1230913369
str += 3;
1231013370
idx = 0;
12311
- }
12312
- else {
12313
- idx = jim_strtol(str, &endptr);
12314
-
12315
- if (endptr == str) {
12316
- goto badindex;
12317
- }
12318
- str = endptr;
12319
- }
12320
-
12321
-
12322
- if (*str == '+' || *str == '-') {
12323
- int sign = (*str == '+' ? 1 : -1);
12324
-
12325
- idx += sign * jim_strtol(++str, &endptr);
12326
- if (str == endptr || *endptr) {
12327
- goto badindex;
12328
- }
12329
- str = endptr;
12330
- }
12331
-
12332
- while (isspace(UCHAR(*str))) {
12333
- str++;
12334
- }
12335
- if (*str) {
12336
- goto badindex;
12337
- }
13371
+ switch (*str) {
13372
+ case '\0':
13373
+ exprObj = NULL;
13374
+ break;
13375
+
13376
+ case '-':
13377
+ case '+':
13378
+ exprObj = Jim_NewStringObj(interp, str, -1);
13379
+ break;
13380
+
13381
+ default:
13382
+ goto badindex;
13383
+ }
13384
+ }
13385
+ if (exprObj) {
13386
+ int ret;
13387
+ Jim_IncrRefCount(exprObj);
13388
+ ret = Jim_GetWideExpr(interp, exprObj, &idx);
13389
+ Jim_DecrRefCount(interp, exprObj);
13390
+ if (ret != JIM_OK) {
13391
+ goto badindex;
13392
+ }
13393
+ }
13394
+
1233813395
if (end) {
1233913396
if (idx > 0) {
1234013397
idx = INT_MAX;
1234113398
}
1234213399
else {
@@ -12354,11 +13411,11 @@
1235413411
objPtr->internalRep.intValue = idx;
1235513412
return JIM_OK;
1235613413
1235713414
badindex:
1235813415
Jim_SetResultFormatted(interp,
12359
- "bad index \"%#s\": must be integer?[+-]integer? or end?[+-]integer?", objPtr);
13416
+ "bad index \"%#s\": must be intexpr or end?[+-]intexpr?", objPtr);
1236013417
return JIM_ERR;
1236113418
}
1236213419
1236313420
int Jim_GetIndex(Jim_Interp *interp, Jim_Obj *objPtr, int *indexPtr)
1236413421
{
@@ -12479,10 +13536,14 @@
1247913536
1248013537
JIM_EXPROP_STREQ,
1248113538
JIM_EXPROP_STRNE,
1248213539
JIM_EXPROP_STRIN,
1248313540
JIM_EXPROP_STRNI,
13541
+ JIM_EXPROP_STRLT,
13542
+ JIM_EXPROP_STRGT,
13543
+ JIM_EXPROP_STRLE,
13544
+ JIM_EXPROP_STRGE,
1248413545
1248513546
1248613547
JIM_EXPROP_NOT,
1248713548
JIM_EXPROP_BITNOT,
1248813549
JIM_EXPROP_UNARYMINUS,
@@ -12544,11 +13605,11 @@
1254413605
static int JimExprEvalTermNode(Jim_Interp *interp, struct JimExprNode *node);
1254513606
1254613607
static int JimExprOpNumUnary(Jim_Interp *interp, struct JimExprNode *node)
1254713608
{
1254813609
int intresult = 1;
12549
- int rc;
13610
+ int rc, bA = 0;
1255013611
double dA, dC = 0;
1255113612
jim_wide wA, wC = 0;
1255213613
Jim_Obj *A;
1255313614
1255413615
if ((rc = JimExprGetTerm(interp, node->left, &A)) != JIM_OK) {
@@ -12611,10 +13672,19 @@
1261113672
break;
1261213673
default:
1261313674
abort();
1261413675
}
1261513676
}
13677
+ else if ((rc = Jim_GetBoolean(interp, A, &bA)) == JIM_OK) {
13678
+ switch (node->type) {
13679
+ case JIM_EXPROP_NOT:
13680
+ wC = !bA;
13681
+ break;
13682
+ default:
13683
+ abort();
13684
+ }
13685
+ }
1261613686
1261713687
if (rc == JIM_OK) {
1261813688
if (intresult) {
1261913689
Jim_SetResultInt(interp, wC);
1262013690
}
@@ -12631,11 +13701,11 @@
1263113701
static double JimRandDouble(Jim_Interp *interp)
1263213702
{
1263313703
unsigned long x;
1263413704
JimRandomBytes(interp, &x, sizeof(x));
1263513705
12636
- return (double)x / (unsigned long)~0;
13706
+ return (double)x / (double)~0UL;
1263713707
}
1263813708
1263913709
static int JimExprOpIntUnary(Jim_Interp *interp, struct JimExprNode *node)
1264013710
{
1264113711
jim_wide wA;
@@ -13040,11 +14110,11 @@
1304014110
1304114111
static int JimExprOpStrBin(Jim_Interp *interp, struct JimExprNode *node)
1304214112
{
1304314113
Jim_Obj *A, *B;
1304414114
jim_wide wC;
13045
- int rc;
14115
+ int comp, rc;
1304614116
1304714117
if ((rc = JimExprGetTerm(interp, node->left, &A)) != JIM_OK) {
1304814118
return rc;
1304914119
}
1305014120
if ((rc = JimExprGetTerm(interp, node->right, &B)) != JIM_OK) {
@@ -13057,10 +14127,25 @@
1305714127
case JIM_EXPROP_STRNE:
1305814128
wC = Jim_StringEqObj(A, B);
1305914129
if (node->type == JIM_EXPROP_STRNE) {
1306014130
wC = !wC;
1306114131
}
14132
+ break;
14133
+ case JIM_EXPROP_STRLT:
14134
+ case JIM_EXPROP_STRGT:
14135
+ case JIM_EXPROP_STRLE:
14136
+ case JIM_EXPROP_STRGE:
14137
+ comp = Jim_StringCompareObj(interp, A, B, 0);
14138
+ if (node->type == JIM_EXPROP_STRLT) {
14139
+ wC = comp == -1;
14140
+ } else if (node->type == JIM_EXPROP_STRGT) {
14141
+ wC = comp == 1;
14142
+ } else if (node->type == JIM_EXPROP_STRLE) {
14143
+ wC = comp == -1 || comp == 0;
14144
+ } else {
14145
+ wC = comp == 0 || comp == 1;
14146
+ }
1306214147
break;
1306314148
case JIM_EXPROP_STRIN:
1306414149
wC = JimSearchList(interp, B, A);
1306514150
break;
1306614151
case JIM_EXPROP_STRNI:
@@ -13196,10 +14281,15 @@
1319614281
OPRINIT("eq", 60, 2, JimExprOpStrBin),
1319714282
OPRINIT("ne", 60, 2, JimExprOpStrBin),
1319814283
1319914284
OPRINIT("in", 55, 2, JimExprOpStrBin),
1320014285
OPRINIT("ni", 55, 2, JimExprOpStrBin),
14286
+
14287
+ OPRINIT("lt", 75, 2, JimExprOpStrBin),
14288
+ OPRINIT("gt", 75, 2, JimExprOpStrBin),
14289
+ OPRINIT("le", 75, 2, JimExprOpStrBin),
14290
+ OPRINIT("ge", 75, 2, JimExprOpStrBin),
1320114291
1320214292
OPRINIT_ATTR("!", 150, 1, JimExprOpNumUnary, OP_RIGHT_ASSOC),
1320314293
OPRINIT_ATTR("~", 150, 1, JimExprOpIntUnary, OP_RIGHT_ASSOC),
1320414294
OPRINIT_ATTR(" -", 150, 1, JimExprOpNumUnary, OP_RIGHT_ASSOC),
1320514295
OPRINIT_ATTR(" +", 150, 1, JimExprOpNumUnary, OP_RIGHT_ASSOC),
@@ -13242,17 +14332,26 @@
1324214332
#define JIM_EXPR_OPERATORS_NUM \
1324314333
(sizeof(Jim_ExprOperators)/sizeof(struct Jim_ExprOperator))
1324414334
1324514335
static int JimParseExpression(struct JimParserCtx *pc)
1324614336
{
14337
+ while (1) {
1324714338
13248
- while (isspace(UCHAR(*pc->p)) || (*(pc->p) == '\\' && *(pc->p + 1) == '\n')) {
13249
- if (*pc->p == '\n') {
13250
- pc->linenr++;
14339
+ while (isspace(UCHAR(*pc->p)) || (*(pc->p) == '\\' && *(pc->p + 1) == '\n')) {
14340
+ if (*pc->p == '\n') {
14341
+ pc->linenr++;
14342
+ }
14343
+ pc->p++;
14344
+ pc->len--;
1325114345
}
13252
- pc->p++;
13253
- pc->len--;
14346
+
14347
+ if (*pc->p == '#') {
14348
+ JimParseComment(pc);
14349
+
14350
+ continue;
14351
+ }
14352
+ break;
1325414353
}
1325514354
1325614355
1325714356
pc->tline = pc->linenr;
1325814357
pc->tstart = pc->p;
@@ -13372,21 +14471,15 @@
1337214471
return JIM_ERR;
1337314472
}
1337414473
1337514474
static int JimParseExprBoolean(struct JimParserCtx *pc)
1337614475
{
13377
- const char *booleans[] = { "false", "no", "off", "true", "yes", "on", NULL };
13378
- const int lengths[] = { 5, 2, 3, 4, 3, 2, 0 };
1337914476
int i;
13380
-
13381
- for (i = 0; booleans[i]; i++) {
13382
- const char *boolean = booleans[i];
13383
- int length = lengths[i];
13384
-
13385
- if (strncmp(boolean, pc->p, length) == 0) {
13386
- pc->p += length;
13387
- pc->len -= length;
14477
+ for (i = 0; i < sizeof(jim_true_false_strings) / sizeof(*jim_true_false_strings); i++) {
14478
+ if (strncmp(pc->p, jim_true_false_strings[i], jim_true_false_lens[i]) == 0) {
14479
+ pc->p += jim_true_false_lens[i];
14480
+ pc->len -= jim_true_false_lens[i];
1338814481
pc->tend = pc->p - 1;
1338914482
pc->tt = JIM_TT_EXPR_BOOLEAN;
1339014483
return JIM_OK;
1339114484
}
1339214485
}
@@ -13479,11 +14572,11 @@
1347914572
static const Jim_ObjType exprObjType = {
1348014573
"expression",
1348114574
FreeExprInternalRep,
1348214575
DupExprInternalRep,
1348314576
NULL,
13484
- JIM_TYPE_REFERENCES,
14577
+ JIM_TYPE_NONE,
1348514578
};
1348614579
1348714580
1348814581
struct ExprTree
1348914582
{
@@ -13571,12 +14664,11 @@
1357114664
1357214665
#define EXPR_UNTIL_CLOSE 0x0001
1357314666
#define EXPR_FUNC_ARGS 0x0002
1357414667
#define EXPR_TERNARY 0x0004
1357514668
13576
-static int ExprTreeBuildTree(Jim_Interp *interp, struct ExprBuilder *builder, int precedence, int flags, int exp_numterms)
13577
-{
14669
+static int ExprTreeBuildTree(Jim_Interp *interp, struct ExprBuilder *builder, int precedence, int flags, int exp_numterms) {
1357814670
int rc;
1357914671
struct JimExprNode *node;
1358014672
1358114673
int exp_stacklen = builder->stack.len + exp_numterms;
1358214674
@@ -13826,11 +14918,11 @@
1382614918
builder.level = 0;
1382714919
builder.token = builder.first_token = tokenlist->list;
1382814920
builder.exprObjPtr = exprObjPtr;
1382914921
builder.fileNameObj = fileNameObj;
1383014922
13831
- builder.nodes = malloc(sizeof(struct JimExprNode) * (tokenlist->count - 1));
14923
+ builder.nodes = Jim_Alloc(sizeof(struct JimExprNode) * (tokenlist->count - 1));
1383214924
memset(builder.nodes, 0, sizeof(struct JimExprNode) * (tokenlist->count - 1));
1383314925
builder.next = builder.nodes;
1383414926
Jim_InitStack(&builder.stack);
1383514927
1383614928
rc = ExprTreeBuildTree(interp, &builder, 0, 0, 1);
@@ -14004,17 +15096,23 @@
1400415096
return JIM_OK;
1400515097
}
1400615098
return JIM_ERR;
1400715099
1400815100
case JIM_TT_ESC:
15101
+ if (interp->safeexpr) {
15102
+ return JIM_ERR;
15103
+ }
1400915104
if (Jim_SubstObj(interp, node->objPtr, &objPtr, JIM_NONE) == JIM_OK) {
1401015105
Jim_SetResult(interp, objPtr);
1401115106
return JIM_OK;
1401215107
}
1401315108
return JIM_ERR;
1401415109
1401515110
case JIM_TT_CMD:
15111
+ if (interp->safeexpr) {
15112
+ return JIM_ERR;
15113
+ }
1401615114
return Jim_EvalObj(interp, node->objPtr);
1401715115
1401815116
default:
1401915117
1402015118
return JIM_ERR;
@@ -14043,36 +15141,38 @@
1404315141
int Jim_EvalExpression(Jim_Interp *interp, Jim_Obj *exprObjPtr)
1404415142
{
1404515143
struct ExprTree *expr;
1404615144
int retcode = JIM_OK;
1404715145
15146
+ Jim_IncrRefCount(exprObjPtr);
1404815147
expr = JimGetExpression(interp, exprObjPtr);
1404915148
if (!expr) {
14050
- return JIM_ERR;
15149
+ retcode = JIM_ERR;
15150
+ goto done;
1405115151
}
1405215152
1405315153
#ifdef JIM_OPTIMIZATION
14054
- {
15154
+ if (!interp->safeexpr) {
1405515155
Jim_Obj *objPtr;
1405615156
1405715157
1405815158
switch (expr->len) {
1405915159
case 1:
1406015160
objPtr = JimExprIntValOrVar(interp, expr->expr);
1406115161
if (objPtr) {
1406215162
Jim_SetResult(interp, objPtr);
14063
- return JIM_OK;
15163
+ goto done;
1406415164
}
1406515165
break;
1406615166
1406715167
case 2:
1406815168
if (expr->expr->type == JIM_EXPROP_NOT) {
1406915169
objPtr = JimExprIntValOrVar(interp, expr->expr->left);
1407015170
1407115171
if (objPtr && JimIsWide(objPtr)) {
1407215172
Jim_SetResult(interp, JimWideValue(objPtr) ? interp->falseObj : interp->trueObj);
14073
- return JIM_OK;
15173
+ goto done;
1407415174
}
1407515175
}
1407615176
break;
1407715177
1407815178
case 3:
@@ -14104,11 +15204,11 @@
1410415204
break;
1410515205
default:
1410615206
goto noopt;
1410715207
}
1410815208
Jim_SetResult(interp, cmpRes ? interp->trueObj : interp->falseObj);
14109
- return JIM_OK;
15209
+ goto done;
1411015210
}
1411115211
}
1411215212
break;
1411315213
}
1411415214
}
@@ -14118,11 +15218,17 @@
1411815218
expr->inUse++;
1411915219
1412015220
1412115221
retcode = JimExprEvalTermNode(interp, expr->expr);
1412215222
14123
- expr->inUse--;
15223
+
15224
+ Jim_FreeIntRep(interp, exprObjPtr);
15225
+ exprObjPtr->typePtr = &exprObjType;
15226
+ Jim_SetIntRepPtr(exprObjPtr, expr);
15227
+
15228
+done:
15229
+ Jim_DecrRefCount(interp, exprObjPtr);
1412415230
1412515231
return retcode;
1412615232
}
1412715233
1412815234
int Jim_GetBoolFromExpr(Jim_Interp *interp, Jim_Obj *exprObjPtr, int *boolPtr)
@@ -14405,21 +15511,21 @@
1440515511
1440615512
if (!sdescr && isspace(UCHAR(*str)))
1440715513
break;
1440815514
1440915515
n = utf8_tounicode(str, &c);
14410
- if (sdescr && !JimCharsetMatch(sdescr, c, JIM_CHARSET_SCAN))
15516
+ if (sdescr && !JimCharsetMatch(sdescr, strlen(sdescr), c, JIM_CHARSET_SCAN))
1441115517
break;
1441215518
while (n--)
1441315519
*p++ = *str++;
1441415520
}
1441515521
*p = 0;
1441615522
return Jim_NewStringObjNoAlloc(interp, buffer, p - buffer);
1441715523
}
1441815524
1441915525
14420
-static int ScanOneEntry(Jim_Interp *interp, const char *str, int pos, int strLen,
15526
+static int ScanOneEntry(Jim_Interp *interp, const char *str, int pos, int str_bytelen,
1442115527
ScanFmtStringObj * fmtObj, long idx, Jim_Obj **valObjPtr)
1442215528
{
1442315529
const char *tok;
1442415530
const ScanFmtPartDescr *descr = &fmtObj->descr[idx];
1442515531
size_t scanned = 0;
@@ -14428,52 +15534,53 @@
1442815534
Jim_Obj *tmpObj = NULL;
1442915535
1443015536
1443115537
*valObjPtr = 0;
1443215538
if (descr->prefix) {
14433
- for (i = 0; pos < strLen && descr->prefix[i]; ++i) {
15539
+ for (i = 0; pos < str_bytelen && descr->prefix[i]; ++i) {
1443415540
1443515541
if (isspace(UCHAR(descr->prefix[i])))
14436
- while (pos < strLen && isspace(UCHAR(str[pos])))
15542
+ while (pos < str_bytelen && isspace(UCHAR(str[pos])))
1443715543
++pos;
1443815544
else if (descr->prefix[i] != str[pos])
1443915545
break;
1444015546
else
1444115547
++pos;
1444215548
}
14443
- if (pos >= strLen) {
15549
+ if (pos >= str_bytelen) {
1444415550
return -1;
1444515551
}
1444615552
else if (descr->prefix[i] != 0)
1444715553
return 0;
1444815554
}
1444915555
1445015556
if (descr->type != 'c' && descr->type != '[' && descr->type != 'n')
1445115557
while (isspace(UCHAR(str[pos])))
1445215558
++pos;
15559
+
1445315560
1445415561
scanned = pos - anchor;
1445515562
1445615563
1445715564
if (descr->type == 'n') {
1445815565
1445915566
*valObjPtr = Jim_NewIntObj(interp, anchor + scanned);
1446015567
}
14461
- else if (pos >= strLen) {
15568
+ else if (pos >= str_bytelen) {
1446215569
1446315570
return -1;
1446415571
}
1446515572
else if (descr->type == 'c') {
14466
- int c;
14467
- scanned += utf8_tounicode(&str[pos], &c);
14468
- *valObjPtr = Jim_NewIntObj(interp, c);
14469
- return scanned;
15573
+ int c;
15574
+ scanned += utf8_tounicode(&str[pos], &c);
15575
+ *valObjPtr = Jim_NewIntObj(interp, c);
15576
+ return scanned;
1447015577
}
1447115578
else {
1447215579
1447315580
if (descr->width > 0) {
14474
- size_t sLen = utf8_strlen(&str[pos], strLen - pos);
15581
+ size_t sLen = utf8_strlen(&str[pos], str_bytelen - pos);
1447515582
size_t tLen = descr->width > sLen ? sLen : descr->width;
1447615583
1447715584
tmpObj = Jim_NewStringObjUtf8(interp, str + pos, tLen);
1447815585
tok = tmpObj->bytes;
1447915586
}
@@ -14548,11 +15655,11 @@
1454815655
Jim_Obj *Jim_ScanString(Jim_Interp *interp, Jim_Obj *strObjPtr, Jim_Obj *fmtObjPtr, int flags)
1454915656
{
1455015657
size_t i, pos;
1455115658
int scanned = 1;
1455215659
const char *str = Jim_String(strObjPtr);
14553
- int strLen = Jim_Utf8Length(interp, strObjPtr);
15660
+ int str_bytelen = Jim_Length(strObjPtr);
1455415661
Jim_Obj *resultList = 0;
1455515662
Jim_Obj **resultVec = 0;
1455615663
int resultc;
1455715664
Jim_Obj *emptyStr = 0;
1455815665
ScanFmtStringObj *fmtObj;
@@ -14585,11 +15692,11 @@
1458515692
1458615693
if (descr->type == 0)
1458715694
continue;
1458815695
1458915696
if (scanned > 0)
14590
- scanned = ScanOneEntry(interp, str, pos, strLen, fmtObj, i, &value);
15697
+ scanned = ScanOneEntry(interp, str, pos, str_bytelen, fmtObj, i, &value);
1459115698
1459215699
if (scanned == -1 && i == 0)
1459315700
goto eof;
1459415701
1459515702
pos += scanned;
@@ -14707,11 +15814,11 @@
1470715814
if (argc != 2 && argc != 3) {
1470815815
Jim_WrongNumArgs(interp, 1, argv, "varName ?increment?");
1470915816
return JIM_ERR;
1471015817
}
1471115818
if (argc == 3) {
14712
- if (Jim_GetWide(interp, argv[2], &increment) != JIM_OK)
15819
+ if (Jim_GetWideExpr(interp, argv[2], &increment) != JIM_OK)
1471315820
return JIM_ERR;
1471415821
}
1471515822
intObjPtr = Jim_GetVariable(interp, argv[1], JIM_UNSHARED);
1471615823
if (!intObjPtr) {
1471715824
@@ -14743,10 +15850,49 @@
1474315850
1474415851
1474515852
#define JIM_EVAL_SARGV_LEN 8
1474615853
#define JIM_EVAL_SINTV_LEN 8
1474715854
15855
+static int JimTraceCallback(Jim_Interp *interp, const char *type, int argc, Jim_Obj *const *argv)
15856
+{
15857
+ JimPanic((interp->traceCmdObj == NULL, "xtrace invoked with no object"));
15858
+
15859
+ int ret;
15860
+ Jim_Obj *nargv[7];
15861
+ Jim_Obj *traceCmdObj = interp->traceCmdObj;
15862
+ Jim_Obj *resultObj = Jim_GetResult(interp);
15863
+
15864
+ ScriptObj *script = JimGetScript(interp, interp->evalFrame->scriptObj);
15865
+
15866
+ nargv[0] = traceCmdObj;
15867
+ nargv[1] = Jim_NewStringObj(interp, type, -1);
15868
+ nargv[2] = script->fileNameObj;
15869
+ nargv[3] = Jim_NewIntObj(interp, script->linenr);
15870
+ nargv[4] = resultObj;
15871
+ nargv[5] = argv[0];
15872
+ nargv[6] = Jim_NewListObj(interp, argv + 1, argc - 1);
15873
+
15874
+
15875
+ interp->traceCmdObj = NULL;
15876
+
15877
+ Jim_IncrRefCount(resultObj);
15878
+ ret = Jim_EvalObjVector(interp, 7, nargv);
15879
+ Jim_DecrRefCount(interp, resultObj);
15880
+
15881
+ if (ret == JIM_OK || ret == JIM_RETURN) {
15882
+
15883
+ interp->traceCmdObj = traceCmdObj;
15884
+ Jim_SetEmptyResult(interp);
15885
+ ret = JIM_OK;
15886
+ }
15887
+ else {
15888
+
15889
+ Jim_DecrRefCount(interp, traceCmdObj);
15890
+ }
15891
+ return ret;
15892
+}
15893
+
1474815894
1474915895
static int JimUnknown(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
1475015896
{
1475115897
int retcode;
1475215898
@@ -14764,16 +15910,44 @@
1476415910
retcode = Jim_EvalObjPrefix(interp, interp->unknown, argc, argv);
1476515911
interp->unknown_called--;
1476615912
1476715913
return retcode;
1476815914
}
15915
+
15916
+static void JimPushEvalFrame(Jim_Interp *interp, Jim_EvalFrame *frame, Jim_Obj *scriptObj)
15917
+{
15918
+ memset(frame, 0, sizeof(*frame));
15919
+ frame->parent = interp->evalFrame;
15920
+ frame->level = frame->parent->level + 1;
15921
+ frame->procLevel = interp->procLevel;
15922
+ frame->framePtr = interp->framePtr;
15923
+ if (scriptObj) {
15924
+ frame->scriptObj = scriptObj;
15925
+ }
15926
+ else {
15927
+ frame->scriptObj = frame->parent->scriptObj;
15928
+ }
15929
+ interp->evalFrame = frame;
15930
+#if 0
15931
+ if (frame->scriptObj) {
15932
+ printf("script: %.*s\n", 20, Jim_String(frame->scriptObj));
15933
+ }
15934
+#endif
15935
+}
15936
+
15937
+static void JimPopEvalFrame(Jim_Interp *interp)
15938
+{
15939
+ interp->evalFrame = interp->evalFrame->parent;
15940
+}
15941
+
1476915942
1477015943
static int JimInvokeCommand(Jim_Interp *interp, int objc, Jim_Obj *const *objv)
1477115944
{
1477215945
int retcode;
1477315946
Jim_Cmd *cmdPtr;
1477415947
void *prevPrivData;
15948
+ Jim_Obj *tailcallObj = NULL;
1477515949
1477615950
#if 0
1477715951
printf("invoke");
1477815952
int j;
1477915953
for (j = 0; j < objc; j++) {
@@ -14780,58 +15954,104 @@
1478015954
printf(" '%s'", Jim_String(objv[j]));
1478115955
}
1478215956
printf("\n");
1478315957
#endif
1478415958
14785
- if (interp->framePtr->tailcallCmd) {
14786
-
14787
- cmdPtr = interp->framePtr->tailcallCmd;
14788
- interp->framePtr->tailcallCmd = NULL;
14789
- }
14790
- else {
14791
- cmdPtr = Jim_GetCommand(interp, objv[0], JIM_ERRMSG);
14792
- if (cmdPtr == NULL) {
14793
- return JimUnknown(interp, objc, objv);
14794
- }
14795
- JimIncrCmdRefCount(cmdPtr);
14796
- }
15959
+ cmdPtr = Jim_GetCommand(interp, objv[0], JIM_ERRMSG);
15960
+ if (cmdPtr == NULL) {
15961
+ return JimUnknown(interp, objc, objv);
15962
+ }
15963
+ JimIncrCmdRefCount(cmdPtr);
1479715964
1479815965
if (interp->evalDepth == interp->maxEvalDepth) {
1479915966
Jim_SetResultString(interp, "Infinite eval recursion", -1);
1480015967
retcode = JIM_ERR;
1480115968
goto out;
1480215969
}
1480315970
interp->evalDepth++;
1480415971
prevPrivData = interp->cmdPrivData;
1480515972
14806
-
14807
- Jim_SetEmptyResult(interp);
14808
- if (cmdPtr->isproc) {
14809
- retcode = JimCallProcedure(interp, cmdPtr, objc, objv);
14810
- }
14811
- else {
14812
- interp->cmdPrivData = cmdPtr->u.native.privData;
14813
- retcode = cmdPtr->u.native.cmdProc(interp, objc, objv);
14814
- }
15973
+tailcall:
15974
+
15975
+ interp->evalFrame->argc = objc;
15976
+ interp->evalFrame->argv = objv;
15977
+ interp->evalFrame->cmd = cmdPtr;
15978
+
15979
+ if (!interp->traceCmdObj ||
15980
+ (retcode = JimTraceCallback(interp, "cmd", objc, objv)) == JIM_OK) {
15981
+
15982
+ Jim_SetEmptyResult(interp);
15983
+ if (cmdPtr->isproc) {
15984
+ retcode = JimCallProcedure(interp, cmdPtr, objc, objv);
15985
+ }
15986
+ else {
15987
+ interp->cmdPrivData = cmdPtr->u.native.privData;
15988
+ retcode = cmdPtr->u.native.cmdProc(interp, objc, objv);
15989
+ }
15990
+ if (retcode == JIM_ERR) {
15991
+ JimSetErrorStack(interp);
15992
+ }
15993
+ }
15994
+
15995
+ if (tailcallObj) {
15996
+
15997
+ Jim_DecrRefCount(interp, tailcallObj);
15998
+ tailcallObj = NULL;
15999
+ }
16000
+
16001
+
16002
+ interp->evalFrame->argc = 0;
16003
+ interp->evalFrame->argv = NULL;
16004
+
16005
+
16006
+ if (retcode == JIM_EVAL && interp->framePtr->tailcallObj) {
16007
+ JimDecrCmdRefCount(interp, cmdPtr);
16008
+
16009
+
16010
+ cmdPtr = interp->framePtr->tailcallCmd;
16011
+ interp->framePtr->tailcallCmd = NULL;
16012
+ tailcallObj = interp->framePtr->tailcallObj;
16013
+ interp->framePtr->tailcallObj = NULL;
16014
+ objc = tailcallObj->internalRep.listValue.len;
16015
+ objv = tailcallObj->internalRep.listValue.ele;
16016
+ goto tailcall;
16017
+ }
16018
+
1481516019
interp->cmdPrivData = prevPrivData;
1481616020
interp->evalDepth--;
1481716021
1481816022
out:
1481916023
JimDecrCmdRefCount(interp, cmdPtr);
16024
+
16025
+ if (retcode == JIM_ERR) {
16026
+ JimSetErrorStack(interp);
16027
+ }
16028
+
16029
+ if (interp->framePtr->tailcallObj) {
16030
+ JimDecrCmdRefCount(interp, interp->framePtr->tailcallCmd);
16031
+ Jim_DecrRefCount(interp, interp->framePtr->tailcallObj);
16032
+ interp->framePtr->tailcallCmd = NULL;
16033
+ interp->framePtr->tailcallObj = NULL;
16034
+ }
1482016035
1482116036
return retcode;
1482216037
}
1482316038
1482416039
int Jim_EvalObjVector(Jim_Interp *interp, int objc, Jim_Obj *const *objv)
1482516040
{
1482616041
int i, retcode;
16042
+ Jim_EvalFrame frame;
1482716043
1482816044
1482916045
for (i = 0; i < objc; i++)
1483016046
Jim_IncrRefCount(objv[i]);
16047
+
16048
+ JimPushEvalFrame(interp, &frame, NULL);
1483116049
1483216050
retcode = JimInvokeCommand(interp, objc, objv);
16051
+
16052
+ JimPopEvalFrame(interp);
1483316053
1483416054
1483516055
for (i = 0; i < objc; i++)
1483616056
Jim_DecrRefCount(interp, objv[i]);
1483716057
@@ -14848,44 +16068,14 @@
1484816068
ret = Jim_EvalObjVector(interp, objc + 1, nargv);
1484916069
Jim_Free(nargv);
1485016070
return ret;
1485116071
}
1485216072
14853
-static void JimAddErrorToStack(Jim_Interp *interp, ScriptObj *script)
14854
-{
14855
- if (!interp->errorFlag) {
14856
-
14857
- interp->errorFlag = 1;
14858
- Jim_IncrRefCount(script->fileNameObj);
14859
- Jim_DecrRefCount(interp, interp->errorFileNameObj);
14860
- interp->errorFileNameObj = script->fileNameObj;
14861
- interp->errorLine = script->linenr;
14862
-
14863
- JimResetStackTrace(interp);
14864
-
14865
- interp->addStackTrace++;
14866
- }
14867
-
14868
-
14869
- if (interp->addStackTrace > 0) {
14870
-
14871
-
14872
- JimAppendStackTrace(interp, Jim_String(interp->errorProc), script->fileNameObj, script->linenr);
14873
-
14874
- if (Jim_Length(script->fileNameObj)) {
14875
- interp->addStackTrace = 0;
14876
- }
14877
-
14878
- Jim_DecrRefCount(interp, interp->errorProc);
14879
- interp->errorProc = interp->emptyObj;
14880
- Jim_IncrRefCount(interp->errorProc);
14881
- }
14882
-}
14883
-
1488416073
static int JimSubstOneToken(Jim_Interp *interp, const ScriptToken *token, Jim_Obj **objPtrPtr)
1488516074
{
1488616075
Jim_Obj *objPtr;
16076
+ int ret = JIM_ERR;
1488716077
1488816078
switch (token->type) {
1488916079
case JIM_TT_STR:
1489016080
case JIM_TT_ESC:
1489116081
objPtr = token->objPtr;
@@ -14895,26 +16085,25 @@
1489516085
break;
1489616086
case JIM_TT_DICTSUGAR:
1489716087
objPtr = JimExpandDictSugar(interp, token->objPtr);
1489816088
break;
1489916089
case JIM_TT_EXPRSUGAR:
14900
- objPtr = JimExpandExprSugar(interp, token->objPtr);
16090
+ ret = Jim_EvalExpression(interp, token->objPtr);
16091
+ if (ret == JIM_OK) {
16092
+ objPtr = Jim_GetResult(interp);
16093
+ }
16094
+ else {
16095
+ objPtr = NULL;
16096
+ }
1490116097
break;
1490216098
case JIM_TT_CMD:
14903
- switch (Jim_EvalObj(interp, token->objPtr)) {
14904
- case JIM_OK:
14905
- case JIM_RETURN:
14906
- objPtr = interp->result;
14907
- break;
14908
- case JIM_BREAK:
14909
-
14910
- return JIM_BREAK;
14911
- case JIM_CONTINUE:
14912
-
14913
- return JIM_CONTINUE;
14914
- default:
14915
- return JIM_ERR;
16099
+ ret = Jim_EvalObj(interp, token->objPtr);
16100
+ if (ret == JIM_OK || ret == JIM_RETURN) {
16101
+ objPtr = interp->result;
16102
+ } else {
16103
+
16104
+ objPtr = NULL;
1491616105
}
1491716106
break;
1491816107
default:
1491916108
JimPanic((1,
1492016109
"default token type (%d) reached " "in Jim_SubstObj().", token->type));
@@ -14923,11 +16112,11 @@
1492316112
}
1492416113
if (objPtr) {
1492516114
*objPtrPtr = objPtr;
1492616115
return JIM_OK;
1492716116
}
14928
- return JIM_ERR;
16117
+ return ret;
1492916118
}
1493016119
1493116120
static Jim_Obj *JimInterpolateTokens(Jim_Interp *interp, const ScriptToken * token, int tokens, int flags)
1493216121
{
1493316122
int totlen = 0, i;
@@ -15018,20 +16207,26 @@
1501816207
1501916208
1502016209
static int JimEvalObjList(Jim_Interp *interp, Jim_Obj *listPtr)
1502116210
{
1502216211
int retcode = JIM_OK;
16212
+ Jim_EvalFrame frame;
1502316213
1502416214
JimPanic((Jim_IsList(listPtr) == 0, "JimEvalObjList() invoked on non-list."));
16215
+
16216
+ JimPushEvalFrame(interp, &frame, NULL);
1502516217
1502616218
if (listPtr->internalRep.listValue.len) {
1502716219
Jim_IncrRefCount(listPtr);
1502816220
retcode = JimInvokeCommand(interp,
1502916221
listPtr->internalRep.listValue.len,
1503016222
listPtr->internalRep.listValue.ele);
1503116223
Jim_DecrRefCount(interp, listPtr);
1503216224
}
16225
+
16226
+ JimPopEvalFrame(interp);
16227
+
1503316228
return retcode;
1503416229
}
1503516230
1503616231
int Jim_EvalObjList(Jim_Interp *interp, Jim_Obj *listPtr)
1503716232
{
@@ -15044,19 +16239,20 @@
1504416239
int i;
1504516240
ScriptObj *script;
1504616241
ScriptToken *token;
1504716242
int retcode = JIM_OK;
1504816243
Jim_Obj *sargv[JIM_EVAL_SARGV_LEN], **argv = NULL;
15049
- Jim_Obj *prevScriptObj;
16244
+ Jim_EvalFrame frame;
1505016245
1505116246
if (Jim_IsList(scriptObjPtr) && scriptObjPtr->bytes == NULL) {
1505216247
return JimEvalObjList(interp, scriptObjPtr);
1505316248
}
1505416249
1505516250
Jim_IncrRefCount(scriptObjPtr);
1505616251
script = JimGetScript(interp, scriptObjPtr);
15057
- if (!JimScriptValid(interp, script)) {
16252
+ if (JimParseCheckMissing(interp, script->missing) == JIM_ERR) {
16253
+ JimSetErrorStack(interp);
1505816254
Jim_DecrRefCount(interp, scriptObjPtr);
1505916255
return JIM_ERR;
1506016256
}
1506116257
1506216258
Jim_SetEmptyResult(interp);
@@ -15086,13 +16282,12 @@
1508616282
}
1508716283
#endif
1508816284
1508916285
script->inUse++;
1509016286
16287
+ JimPushEvalFrame(interp, &frame, scriptObjPtr);
1509116288
15092
- prevScriptObj = interp->currentScriptObj;
15093
- interp->currentScriptObj = scriptObjPtr;
1509416289
1509516290
interp->errorFlag = 0;
1509616291
argv = sargv;
1509716292
1509816293
for (i = 0; i < script->len && retcode == JIM_OK; ) {
@@ -15132,11 +16327,17 @@
1513216327
break;
1513316328
case JIM_TT_VAR:
1513416329
wordObjPtr = Jim_GetVariable(interp, token[i].objPtr, JIM_ERRMSG);
1513516330
break;
1513616331
case JIM_TT_EXPRSUGAR:
15137
- wordObjPtr = JimExpandExprSugar(interp, token[i].objPtr);
16332
+ retcode = Jim_EvalExpression(interp, token[i].objPtr);
16333
+ if (retcode == JIM_OK) {
16334
+ wordObjPtr = Jim_GetResult(interp);
16335
+ }
16336
+ else {
16337
+ wordObjPtr = NULL;
16338
+ }
1513816339
break;
1513916340
case JIM_TT_DICTSUGAR:
1514016341
wordObjPtr = JimExpandDictSugar(interp, token[i].objPtr);
1514116342
break;
1514216343
case JIM_TT_CMD:
@@ -15219,20 +16420,14 @@
1521916420
}
1522016421
}
1522116422
1522216423
1522316424
if (retcode == JIM_ERR) {
15224
- JimAddErrorToStack(interp, script);
16425
+ JimSetErrorStack(interp);
1522516426
}
1522616427
15227
- else if (retcode != JIM_RETURN || interp->returnCode != JIM_ERR) {
15228
-
15229
- interp->addStackTrace = 0;
15230
- }
15231
-
15232
-
15233
- interp->currentScriptObj = prevScriptObj;
16428
+ JimPopEvalFrame(interp);
1523416429
1523516430
Jim_FreeIntRep(interp, scriptObjPtr);
1523616431
scriptObjPtr->typePtr = &scriptObjType;
1523716432
Jim_SetIntRepPtr(scriptObjPtr, script);
1523816433
Jim_DecrRefCount(interp, scriptObjPtr);
@@ -15285,11 +16480,11 @@
1528516480
Jim_AppendObj(interp, argmsg, cmd->u.proc.arglist[i].defaultObjPtr);
1528616481
Jim_AppendString(interp, argmsg, " ...?", -1);
1528716482
}
1528816483
else {
1528916484
15290
- Jim_AppendString(interp, argmsg, "?arg...?", -1);
16485
+ Jim_AppendString(interp, argmsg, "?arg ...?", -1);
1529116486
}
1529216487
}
1529316488
else {
1529416489
if (cmd->u.proc.arglist[i].defaultObjPtr) {
1529516490
Jim_AppendString(interp, argmsg, "?", 1);
@@ -15314,17 +16509,15 @@
1531416509
Jim_CallFrame *callFramePtr;
1531516510
int retcode;
1531616511
1531716512
1531816513
callFramePtr = JimCreateCallFrame(interp, interp->framePtr, nsObj);
15319
- callFramePtr->argv = &interp->emptyObj;
15320
- callFramePtr->argc = 0;
16514
+ callFramePtr->argv = interp->evalFrame->argv;
16515
+ callFramePtr->argc = interp->evalFrame->argc;
1532116516
callFramePtr->procArgsObjPtr = NULL;
1532216517
callFramePtr->procBodyObjPtr = scriptObj;
1532316518
callFramePtr->staticVars = NULL;
15324
- callFramePtr->fileNameObj = interp->emptyObj;
15325
- callFramePtr->line = 0;
1532616519
Jim_IncrRefCount(scriptObj);
1532716520
interp->framePtr = callFramePtr;
1532816521
1532916522
1533016523
if (interp->framePtr->level == interp->maxCallFrameDepth) {
@@ -15346,11 +16539,10 @@
1534616539
1534716540
static int JimCallProcedure(Jim_Interp *interp, Jim_Cmd *cmd, int argc, Jim_Obj *const *argv)
1534816541
{
1534916542
Jim_CallFrame *callFramePtr;
1535016543
int i, d, retcode, optargs;
15351
- ScriptObj *script;
1535216544
1535316545
1535416546
if (argc - 1 < cmd->u.proc.reqArity ||
1535516547
(cmd->u.proc.argsPos < 0 && argc - 1 > cmd->u.proc.reqArity + cmd->u.proc.optArity)) {
1535616548
JimSetProcWrongArgs(interp, argv[0], cmd);
@@ -15374,14 +16566,11 @@
1537416566
callFramePtr->argc = argc;
1537516567
callFramePtr->procArgsObjPtr = cmd->u.proc.argListObjPtr;
1537616568
callFramePtr->procBodyObjPtr = cmd->u.proc.bodyObjPtr;
1537716569
callFramePtr->staticVars = cmd->u.proc.staticVars;
1537816570
15379
-
15380
- script = JimGetScript(interp, interp->currentScriptObj);
15381
- callFramePtr->fileNameObj = script->fileNameObj;
15382
- callFramePtr->line = script->linenr;
16571
+ interp->procLevel++;
1538316572
1538416573
Jim_IncrRefCount(cmd->u.proc.argListObjPtr);
1538516574
Jim_IncrRefCount(cmd->u.proc.bodyObjPtr);
1538616575
interp->framePtr = callFramePtr;
1538716576
@@ -15425,57 +16614,32 @@
1542516614
if (retcode != JIM_OK) {
1542616615
goto badargset;
1542716616
}
1542816617
}
1542916618
16619
+ if (interp->traceCmdObj == NULL ||
16620
+ (retcode = JimTraceCallback(interp, "proc", argc, argv)) == JIM_OK) {
1543016621
15431
- retcode = Jim_EvalObj(interp, cmd->u.proc.bodyObjPtr);
16622
+ retcode = Jim_EvalObj(interp, cmd->u.proc.bodyObjPtr);
16623
+ }
1543216624
1543316625
badargset:
1543416626
1543516627
1543616628
retcode = JimInvokeDefer(interp, retcode);
1543716629
interp->framePtr = interp->framePtr->parent;
1543816630
JimFreeCallFrame(interp, callFramePtr, JIM_FCF_REUSE);
1543916631
15440
-
15441
- if (interp->framePtr->tailcallObj) {
15442
- do {
15443
- Jim_Obj *tailcallObj = interp->framePtr->tailcallObj;
15444
-
15445
- interp->framePtr->tailcallObj = NULL;
15446
-
15447
- if (retcode == JIM_EVAL) {
15448
- retcode = Jim_EvalObjList(interp, tailcallObj);
15449
- if (retcode == JIM_RETURN) {
15450
- interp->returnLevel++;
15451
- }
15452
- }
15453
- Jim_DecrRefCount(interp, tailcallObj);
15454
- } while (interp->framePtr->tailcallObj);
15455
-
15456
-
15457
- if (interp->framePtr->tailcallCmd) {
15458
- JimDecrCmdRefCount(interp, interp->framePtr->tailcallCmd);
15459
- interp->framePtr->tailcallCmd = NULL;
15460
- }
15461
- }
15462
-
1546316632
1546416633
if (retcode == JIM_RETURN) {
1546516634
if (--interp->returnLevel <= 0) {
1546616635
retcode = interp->returnCode;
1546716636
interp->returnCode = JIM_OK;
1546816637
interp->returnLevel = 0;
1546916638
}
1547016639
}
15471
- else if (retcode == JIM_ERR) {
15472
- interp->addStackTrace++;
15473
- Jim_DecrRefCount(interp, interp->errorProc);
15474
- interp->errorProc = argv[0];
15475
- Jim_IncrRefCount(interp->errorProc);
15476
- }
16640
+ interp->procLevel--;
1547716641
1547816642
return retcode;
1547916643
}
1548016644
1548116645
int Jim_EvalSource(Jim_Interp *interp, const char *filename, int lineno, const char *script)
@@ -15483,26 +16647,14 @@
1548316647
int retval;
1548416648
Jim_Obj *scriptObjPtr;
1548516649
1548616650
scriptObjPtr = Jim_NewStringObj(interp, script, -1);
1548716651
Jim_IncrRefCount(scriptObjPtr);
15488
-
1548916652
if (filename) {
15490
- Jim_Obj *prevScriptObj;
15491
-
1549216653
JimSetSourceInfo(interp, scriptObjPtr, Jim_NewStringObj(interp, filename, -1), lineno);
15493
-
15494
- prevScriptObj = interp->currentScriptObj;
15495
- interp->currentScriptObj = scriptObjPtr;
15496
-
15497
- retval = Jim_EvalObj(interp, scriptObjPtr);
15498
-
15499
- interp->currentScriptObj = prevScriptObj;
15500
- }
15501
- else {
15502
- retval = Jim_EvalObj(interp, scriptObjPtr);
15503
- }
16654
+ }
16655
+ retval = Jim_EvalObj(interp, scriptObjPtr);
1550416656
Jim_DecrRefCount(interp, scriptObjPtr);
1550516657
return retval;
1550616658
}
1550716659
1550816660
int Jim_Eval(Jim_Interp *interp, const char *script)
@@ -15535,65 +16687,69 @@
1553516687
return retval;
1553616688
}
1553716689
1553816690
#include <sys/stat.h>
1553916691
15540
-int Jim_EvalFile(Jim_Interp *interp, const char *filename)
15541
-{
15542
- FILE *fp;
15543
- char *buf;
15544
- Jim_Obj *scriptObjPtr;
15545
- Jim_Obj *prevScriptObj;
15546
- struct stat sb;
15547
- int retcode;
16692
+static Jim_Obj *JimReadTextFile(Jim_Interp *interp, const char *filename)
16693
+{
16694
+ jim_stat_t sb;
16695
+ int fd;
16696
+ char *buf;
1554816697
int readlen;
1554916698
15550
- if (stat(filename, &sb) != 0 || (fp = fopen(filename, "rt")) == NULL) {
16699
+ if (Jim_Stat(filename, &sb) == -1 || (fd = open(filename, O_RDONLY | O_TEXT, 0666)) < 0) {
1555116700
Jim_SetResultFormatted(interp, "couldn't read file \"%s\": %s", filename, strerror(errno));
15552
- return JIM_ERR;
16701
+ return NULL;
1555316702
}
15554
- if (sb.st_size == 0) {
15555
- fclose(fp);
15556
- return JIM_OK;
15557
- }
15558
-
1555916703
buf = Jim_Alloc(sb.st_size + 1);
15560
- readlen = fread(buf, 1, sb.st_size, fp);
15561
- if (ferror(fp)) {
15562
- fclose(fp);
16704
+ readlen = read(fd, buf, sb.st_size);
16705
+ close(fd);
16706
+ if (readlen < 0) {
1556316707
Jim_Free(buf);
1556416708
Jim_SetResultFormatted(interp, "failed to load file \"%s\": %s", filename, strerror(errno));
16709
+ return NULL;
16710
+ }
16711
+ else {
16712
+ Jim_Obj *objPtr;
16713
+ buf[readlen] = 0;
16714
+
16715
+ objPtr = Jim_NewStringObjNoAlloc(interp, buf, readlen);
16716
+
16717
+ return objPtr;
16718
+ }
16719
+}
16720
+
16721
+
16722
+int Jim_EvalFile(Jim_Interp *interp, const char *filename)
16723
+{
16724
+ Jim_Obj *filenameObj;
16725
+ Jim_Obj *oldFilenameObj;
16726
+ Jim_Obj *scriptObjPtr;
16727
+ int retcode;
16728
+
16729
+ scriptObjPtr = JimReadTextFile(interp, filename);
16730
+ if (!scriptObjPtr) {
1556516731
return JIM_ERR;
1556616732
}
15567
- fclose(fp);
15568
- buf[readlen] = 0;
15569
-
15570
- scriptObjPtr = Jim_NewStringObjNoAlloc(interp, buf, readlen);
15571
- JimSetSourceInfo(interp, scriptObjPtr, Jim_NewStringObj(interp, filename, -1), 1);
15572
- Jim_IncrRefCount(scriptObjPtr);
15573
-
15574
- prevScriptObj = interp->currentScriptObj;
15575
- interp->currentScriptObj = scriptObjPtr;
16733
+
16734
+ filenameObj = Jim_NewStringObj(interp, filename, -1);
16735
+ JimSetSourceInfo(interp, scriptObjPtr, filenameObj, 1);
16736
+
16737
+ oldFilenameObj = JimPushInterpObj(interp->currentFilenameObj, filenameObj);
1557616738
1557716739
retcode = Jim_EvalObj(interp, scriptObjPtr);
16740
+
16741
+ JimPopInterpObj(interp, interp->currentFilenameObj, oldFilenameObj);
1557816742
1557916743
1558016744
if (retcode == JIM_RETURN) {
1558116745
if (--interp->returnLevel <= 0) {
1558216746
retcode = interp->returnCode;
1558316747
interp->returnCode = JIM_OK;
1558416748
interp->returnLevel = 0;
1558516749
}
1558616750
}
15587
- if (retcode == JIM_ERR) {
15588
-
15589
- interp->addStackTrace++;
15590
- }
15591
-
15592
- interp->currentScriptObj = prevScriptObj;
15593
-
15594
- Jim_DecrRefCount(interp, scriptObjPtr);
1559516751
1559616752
return retcode;
1559716753
}
1559816754
1559916755
static void JimParseSubst(struct JimParserCtx *pc, int flags)
@@ -15696,11 +16852,15 @@
1569616852
return (ScriptObj *) Jim_GetIntRepPtr(objPtr);
1569716853
}
1569816854
1569916855
int Jim_SubstObj(Jim_Interp *interp, Jim_Obj *substObjPtr, Jim_Obj **resObjPtrPtr, int flags)
1570016856
{
15701
- ScriptObj *script = Jim_GetSubst(interp, substObjPtr, flags);
16857
+ ScriptObj *script;
16858
+
16859
+ JimPanic((substObjPtr->refCount == 0, "Jim_SubstObj() called with zero refcount object"));
16860
+
16861
+ script = Jim_GetSubst(interp, substObjPtr, flags);
1570216862
1570316863
Jim_IncrRefCount(substObjPtr);
1570416864
script->inUse++;
1570516865
1570616866
*resObjPtrPtr = JimInterpolateTokens(interp, script->token, script->len, flags);
@@ -15731,11 +16891,11 @@
1573116891
1573216892
Jim_SetResultFormatted(interp, "wrong # args: should be \"%#s\"", objPtr);
1573316893
}
1573416894
1573516895
typedef void JimHashtableIteratorCallbackType(Jim_Interp *interp, Jim_Obj *listObjPtr,
15736
- Jim_HashEntry *he, int type);
16896
+ Jim_Obj *keyObjPtr, void *value, Jim_Obj *patternObjPtr, int type);
1573716897
1573816898
#define JimTrivialMatch(pattern) (strpbrk((pattern), "*[?\\") == NULL)
1573916899
1574016900
static Jim_Obj *JimHashtablePatternMatch(Jim_Interp *interp, Jim_HashTable *ht, Jim_Obj *patternObjPtr,
1574116901
JimHashtableIteratorCallbackType *callback, int type)
@@ -15743,22 +16903,22 @@
1574316903
Jim_HashEntry *he;
1574416904
Jim_Obj *listObjPtr = Jim_NewListObj(interp, NULL, 0);
1574516905
1574616906
1574716907
if (patternObjPtr && JimTrivialMatch(Jim_String(patternObjPtr))) {
15748
- he = Jim_FindHashEntry(ht, Jim_String(patternObjPtr));
16908
+ he = Jim_FindHashEntry(ht, patternObjPtr);
1574916909
if (he) {
15750
- callback(interp, listObjPtr, he, type);
16910
+ callback(interp, listObjPtr, Jim_GetHashEntryKey(he), Jim_GetHashEntryVal(he),
16911
+ patternObjPtr, type);
1575116912
}
1575216913
}
1575316914
else {
1575416915
Jim_HashTableIterator htiter;
1575516916
JimInitHashTableIterator(ht, &htiter);
1575616917
while ((he = Jim_NextHashEntry(&htiter)) != NULL) {
15757
- if (patternObjPtr == NULL || JimGlobMatch(Jim_String(patternObjPtr), he->key, 0)) {
15758
- callback(interp, listObjPtr, he, type);
15759
- }
16918
+ callback(interp, listObjPtr, Jim_GetHashEntryKey(he), Jim_GetHashEntryVal(he),
16919
+ patternObjPtr, type);
1576016920
}
1576116921
}
1576216922
return listObjPtr;
1576316923
}
1576416924
@@ -15766,29 +16926,40 @@
1576616926
#define JIM_CMDLIST_COMMANDS 0
1576716927
#define JIM_CMDLIST_PROCS 1
1576816928
#define JIM_CMDLIST_CHANNELS 2
1576916929
1577016930
static void JimCommandMatch(Jim_Interp *interp, Jim_Obj *listObjPtr,
15771
- Jim_HashEntry *he, int type)
16931
+ Jim_Obj *keyObj, void *value, Jim_Obj *patternObj, int type)
1577216932
{
15773
- Jim_Cmd *cmdPtr = Jim_GetHashEntryVal(he);
15774
- Jim_Obj *objPtr;
16933
+ Jim_Cmd *cmdPtr = (Jim_Cmd *)value;
1577516934
1577616935
if (type == JIM_CMDLIST_PROCS && !cmdPtr->isproc) {
1577716936
1577816937
return;
1577916938
}
1578016939
15781
- objPtr = Jim_NewStringObj(interp, he->key, -1);
15782
- Jim_IncrRefCount(objPtr);
15783
-
15784
- if (type != JIM_CMDLIST_CHANNELS || Jim_AioFilehandle(interp, objPtr)) {
15785
- Jim_ListAppendElement(interp, listObjPtr, objPtr);
15786
- }
15787
- Jim_DecrRefCount(interp, objPtr);
15788
-}
15789
-
16940
+ Jim_IncrRefCount(keyObj);
16941
+
16942
+ if (type != JIM_CMDLIST_CHANNELS || Jim_AioFilehandle(interp, keyObj) >= 0) {
16943
+ int match = 1;
16944
+ if (patternObj) {
16945
+ int plen, slen;
16946
+ const char *pattern = Jim_GetStringNoQualifier(patternObj, &plen);
16947
+ const char *str = Jim_GetStringNoQualifier(keyObj, &slen);
16948
+#ifdef JIM_NO_INTROSPECTION
16949
+
16950
+ match = (JimStringCompareUtf8(pattern, plen, str, slen, 0) == 0);
16951
+#else
16952
+ match = JimGlobMatch(pattern, plen, str, slen, 0);
16953
+#endif
16954
+ }
16955
+ if (match) {
16956
+ Jim_ListAppendElement(interp, listObjPtr, keyObj);
16957
+ }
16958
+ }
16959
+ Jim_DecrRefCount(interp, keyObj);
16960
+}
1579016961
1579116962
static Jim_Obj *JimCommandsList(Jim_Interp *interp, Jim_Obj *patternObjPtr, int type)
1579216963
{
1579316964
return JimHashtablePatternMatch(interp, &interp->commands, patternObjPtr, JimCommandMatch, type);
1579416965
}
@@ -15795,22 +16966,25 @@
1579516966
1579616967
1579716968
#define JIM_VARLIST_GLOBALS 0
1579816969
#define JIM_VARLIST_LOCALS 1
1579916970
#define JIM_VARLIST_VARS 2
16971
+#define JIM_VARLIST_MASK 0x000f
1580016972
1580116973
#define JIM_VARLIST_VALUES 0x1000
1580216974
1580316975
static void JimVariablesMatch(Jim_Interp *interp, Jim_Obj *listObjPtr,
15804
- Jim_HashEntry *he, int type)
15805
-{
15806
- Jim_Var *varPtr = Jim_GetHashEntryVal(he);
15807
-
15808
- if (type != JIM_VARLIST_LOCALS || varPtr->linkFramePtr == NULL) {
15809
- Jim_ListAppendElement(interp, listObjPtr, Jim_NewStringObj(interp, he->key, -1));
15810
- if (type & JIM_VARLIST_VALUES) {
15811
- Jim_ListAppendElement(interp, listObjPtr, varPtr->objPtr);
16976
+ Jim_Obj *keyObj, void *value, Jim_Obj *patternObj, int type)
16977
+{
16978
+ Jim_VarVal *vv = (Jim_VarVal *)value;
16979
+
16980
+ if ((type & JIM_VARLIST_MASK) != JIM_VARLIST_LOCALS || vv->linkFramePtr == NULL) {
16981
+ if (patternObj == NULL || Jim_StringMatchObj(interp, patternObj, keyObj, 0)) {
16982
+ Jim_ListAppendElement(interp, listObjPtr, keyObj);
16983
+ if (type & JIM_VARLIST_VALUES) {
16984
+ Jim_ListAppendElement(interp, listObjPtr, vv->objPtr);
16985
+ }
1581216986
}
1581316987
}
1581416988
}
1581516989
1581616990
@@ -15819,42 +16993,78 @@
1581916993
if (mode == JIM_VARLIST_LOCALS && interp->framePtr == interp->topFramePtr) {
1582016994
return interp->emptyObj;
1582116995
}
1582216996
else {
1582316997
Jim_CallFrame *framePtr = (mode == JIM_VARLIST_GLOBALS) ? interp->topFramePtr : interp->framePtr;
15824
- return JimHashtablePatternMatch(interp, &framePtr->vars, patternObjPtr, JimVariablesMatch, mode);
15825
- }
15826
-}
15827
-
15828
-static int JimInfoLevel(Jim_Interp *interp, Jim_Obj *levelObjPtr,
15829
- Jim_Obj **objPtrPtr, int info_level_cmd)
15830
-{
15831
- Jim_CallFrame *targetCallFrame;
15832
-
15833
- targetCallFrame = JimGetCallFrameByInteger(interp, levelObjPtr);
15834
- if (targetCallFrame == NULL) {
15835
- return JIM_ERR;
15836
- }
15837
-
15838
- if (targetCallFrame == interp->topFramePtr) {
15839
- Jim_SetResultFormatted(interp, "bad level \"%#s\"", levelObjPtr);
15840
- return JIM_ERR;
15841
- }
15842
- if (info_level_cmd) {
15843
- *objPtrPtr = Jim_NewListObj(interp, targetCallFrame->argv, targetCallFrame->argc);
15844
- }
15845
- else {
15846
- Jim_Obj *listObj = Jim_NewListObj(interp, NULL, 0);
15847
-
15848
- Jim_ListAppendElement(interp, listObj, targetCallFrame->argv[0]);
15849
- Jim_ListAppendElement(interp, listObj, targetCallFrame->fileNameObj);
15850
- Jim_ListAppendElement(interp, listObj, Jim_NewIntObj(interp, targetCallFrame->line));
15851
- *objPtrPtr = listObj;
15852
- }
15853
- return JIM_OK;
15854
-}
15855
-
16998
+ return JimHashtablePatternMatch(interp, &framePtr->vars, patternObjPtr, JimVariablesMatch,
16999
+ mode);
17000
+ }
17001
+}
17002
+
17003
+static int JimInfoLevel(Jim_Interp *interp, Jim_Obj *levelObjPtr, Jim_Obj **objPtrPtr)
17004
+{
17005
+ long level;
17006
+
17007
+ if (Jim_GetLong(interp, levelObjPtr, &level) == JIM_OK) {
17008
+ Jim_CallFrame *targetCallFrame = JimGetCallFrameByInteger(interp, level);
17009
+ if (targetCallFrame && targetCallFrame != interp->topFramePtr) {
17010
+#ifdef JIM_NO_INTROSPECTION
17011
+
17012
+ *objPtrPtr = Jim_NewListObj(interp, targetCallFrame->argv, 1);
17013
+#else
17014
+ *objPtrPtr = Jim_NewListObj(interp, targetCallFrame->argv, targetCallFrame->argc);
17015
+#endif
17016
+ return JIM_OK;
17017
+ }
17018
+ }
17019
+ Jim_SetResultFormatted(interp, "bad level \"%#s\"", levelObjPtr);
17020
+ return JIM_ERR;
17021
+}
17022
+
17023
+static int JimInfoFrame(Jim_Interp *interp, Jim_Obj *levelObjPtr, Jim_Obj **objPtrPtr)
17024
+{
17025
+ long level;
17026
+
17027
+ if (Jim_GetLong(interp, levelObjPtr, &level) == JIM_OK) {
17028
+ Jim_EvalFrame *frame = JimGetEvalFrameByProcLevel(interp, level);
17029
+ if (frame) {
17030
+ Jim_Obj *listObj = Jim_NewListObj(interp, NULL, 0);
17031
+
17032
+ Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, "type", -1));
17033
+ Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, "source", -1));
17034
+ if (frame->scriptObj) {
17035
+ ScriptObj *script = JimGetScript(interp, frame->scriptObj);
17036
+ Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, "line", -1));
17037
+ Jim_ListAppendElement(interp, listObj, Jim_NewIntObj(interp, script->linenr));
17038
+ Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, "file", -1));
17039
+ Jim_ListAppendElement(interp, listObj, script->fileNameObj);
17040
+ }
17041
+#ifndef JIM_NO_INTROSPECTION
17042
+ {
17043
+ Jim_Obj *cmdObj = Jim_NewListObj(interp, frame->argv, frame->argc);
17044
+
17045
+ Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, "cmd", -1));
17046
+ Jim_ListAppendElement(interp, listObj, cmdObj);
17047
+ }
17048
+#endif
17049
+ {
17050
+ Jim_Obj *procNameObj = JimProcForEvalFrame(interp, frame);
17051
+ if (procNameObj) {
17052
+ Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, "proc", -1));
17053
+ Jim_ListAppendElement(interp, listObj, procNameObj);
17054
+ }
17055
+ }
17056
+ Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, "level", -1));
17057
+ Jim_ListAppendElement(interp, listObj, Jim_NewIntObj(interp, interp->framePtr->level - frame->framePtr->level));
17058
+
17059
+ *objPtrPtr = listObj;
17060
+ return JIM_OK;
17061
+ }
17062
+ }
17063
+ Jim_SetResultFormatted(interp, "bad level \"%#s\"", levelObjPtr);
17064
+ return JIM_ERR;
17065
+}
1585617066
1585717067
1585817068
static int Jim_PutsCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
1585917069
{
1586017070
if (argc != 2 && argc != 3) {
@@ -16056,12 +17266,24 @@
1605617266
&& complain) {
1605717267
return JIM_ERR;
1605817268
}
1605917269
i++;
1606017270
}
17271
+
17272
+ Jim_SetEmptyResult(interp);
1606117273
return JIM_OK;
1606217274
}
17275
+
17276
+static int JimCheckLoopRetcode(Jim_Interp *interp, int retval)
17277
+{
17278
+ if (retval == JIM_BREAK || retval == JIM_CONTINUE) {
17279
+ if (--interp->returnLevel > 0) {
17280
+ return 1;
17281
+ }
17282
+ }
17283
+ return 0;
17284
+}
1606317285
1606417286
1606517287
static int Jim_WhileCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
1606617288
{
1606717289
if (argc != 3) {
@@ -16069,25 +17291,26 @@
1606917291
return JIM_ERR;
1607017292
}
1607117293
1607217294
1607317295
while (1) {
16074
- int boolean, retval;
17296
+ int boolean = 0, retval;
1607517297
1607617298
if ((retval = Jim_GetBoolFromExpr(interp, argv[1], &boolean)) != JIM_OK)
1607717299
return retval;
1607817300
if (!boolean)
1607917301
break;
1608017302
1608117303
if ((retval = Jim_EvalObj(interp, argv[2])) != JIM_OK) {
17304
+ if (JimCheckLoopRetcode(interp, retval)) {
17305
+ return retval;
17306
+ }
1608217307
switch (retval) {
1608317308
case JIM_BREAK:
1608417309
goto out;
16085
- break;
1608617310
case JIM_CONTINUE:
1608717311
continue;
16088
- break;
1608917312
default:
1609017313
return retval;
1609117314
}
1609217315
}
1609317316
}
@@ -16099,10 +17322,11 @@
1609917322
1610017323
static int Jim_ForCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
1610117324
{
1610217325
int retval;
1610317326
int boolean = 1;
17327
+ int immediate = 0;
1610417328
Jim_Obj *varNamePtr = NULL;
1610517329
Jim_Obj *stopVarNamePtr = NULL;
1610617330
1610717331
if (argc != 5) {
1610817332
Jim_WrongNumArgs(interp, 1, argv, "start test next body");
@@ -16166,11 +17390,11 @@
1616617390
goto evalstart;
1616717391
}
1616817392
1616917393
1617017394
if (expr->expr->right->type == JIM_TT_EXPR_INT) {
16171
- if (Jim_GetWide(interp, expr->expr->right->objPtr, &stop) == JIM_ERR) {
17395
+ if (Jim_GetWideExpr(interp, expr->expr->right->objPtr, &stop) == JIM_ERR) {
1617217396
goto evalstart;
1617317397
}
1617417398
}
1617517399
else {
1617617400
stopVarNamePtr = expr->expr->right->objPtr;
@@ -16205,10 +17429,14 @@
1620517429
break;
1620617430
}
1620717431
1620817432
1620917433
retval = Jim_EvalObj(interp, argv[4]);
17434
+ if (JimCheckLoopRetcode(interp, retval)) {
17435
+ immediate++;
17436
+ goto out;
17437
+ }
1621017438
if (retval == JIM_OK || retval == JIM_CONTINUE) {
1621117439
retval = JIM_OK;
1621217440
1621317441
objPtr = Jim_GetVariable(interp, varNamePtr, JIM_ERRMSG);
1621417442
@@ -16241,10 +17469,14 @@
1624117469
1624217470
if (retval == JIM_OK || retval == JIM_CONTINUE) {
1624317471
1624417472
JIM_IF_OPTIM(evalnext:)
1624517473
retval = Jim_EvalObj(interp, argv[3]);
17474
+ if (JimCheckLoopRetcode(interp, retval)) {
17475
+ immediate++;
17476
+ goto out;
17477
+ }
1624617478
if (retval == JIM_OK || retval == JIM_CONTINUE) {
1624717479
1624817480
JIM_IF_OPTIM(testcond:)
1624917481
retval = Jim_GetBoolFromExpr(interp, argv[2], &boolean);
1625017482
}
@@ -16256,13 +17488,15 @@
1625617488
}
1625717489
if (varNamePtr) {
1625817490
Jim_DecrRefCount(interp, varNamePtr);
1625917491
}
1626017492
16261
- if (retval == JIM_CONTINUE || retval == JIM_BREAK || retval == JIM_OK) {
16262
- Jim_SetEmptyResult(interp);
16263
- return JIM_OK;
17493
+ if (!immediate) {
17494
+ if (retval == JIM_CONTINUE || retval == JIM_BREAK || retval == JIM_OK) {
17495
+ Jim_SetEmptyResult(interp);
17496
+ return JIM_OK;
17497
+ }
1626417498
}
1626517499
1626617500
return retval;
1626717501
}
1626817502
@@ -16273,26 +17507,38 @@
1627317507
jim_wide i;
1627417508
jim_wide limit;
1627517509
jim_wide incr = 1;
1627617510
Jim_Obj *bodyObjPtr;
1627717511
16278
- if (argc != 5 && argc != 6) {
16279
- Jim_WrongNumArgs(interp, 1, argv, "var first limit ?incr? body");
17512
+ if (argc < 4 || argc > 6) {
17513
+ Jim_WrongNumArgs(interp, 1, argv, "var ?first? limit ?incr? body");
1628017514
return JIM_ERR;
1628117515
}
1628217516
16283
- if (Jim_GetWide(interp, argv[2], &i) != JIM_OK ||
16284
- Jim_GetWide(interp, argv[3], &limit) != JIM_OK ||
16285
- (argc == 6 && Jim_GetWide(interp, argv[4], &incr) != JIM_OK)) {
16286
- return JIM_ERR;
16287
- }
16288
- bodyObjPtr = (argc == 5) ? argv[4] : argv[5];
16289
-
16290
- retval = Jim_SetVariable(interp, argv[1], argv[2]);
17517
+ retval = Jim_GetWideExpr(interp, argv[2], &i);
17518
+ if (argc > 4 && retval == JIM_OK) {
17519
+ retval = Jim_GetWideExpr(interp, argv[3], &limit);
17520
+ }
17521
+ if (argc > 5 && retval == JIM_OK) {
17522
+ Jim_GetWideExpr(interp, argv[4], &incr);
17523
+ }
17524
+ if (retval != JIM_OK) {
17525
+ return retval;
17526
+ }
17527
+ if (argc == 4) {
17528
+ limit = i;
17529
+ i = 0;
17530
+ }
17531
+ bodyObjPtr = argv[argc - 1];
17532
+
17533
+ retval = Jim_SetVariable(interp, argv[1], Jim_NewIntObj(interp, i));
1629117534
1629217535
while (((i < limit && incr > 0) || (i > limit && incr < 0)) && retval == JIM_OK) {
1629317536
retval = Jim_EvalObj(interp, bodyObjPtr);
17537
+ if (JimCheckLoopRetcode(interp, retval)) {
17538
+ return retval;
17539
+ }
1629417540
if (retval == JIM_OK || retval == JIM_CONTINUE) {
1629517541
Jim_Obj *objPtr = Jim_GetVariable(interp, argv[1], JIM_ERRMSG);
1629617542
1629717543
retval = JIM_OK;
1629817544
@@ -16429,11 +17675,15 @@
1642917675
if (result != JIM_OK) {
1643017676
goto err;
1643117677
}
1643217678
}
1643317679
}
16434
- switch (result = Jim_EvalObj(interp, script)) {
17680
+ result = Jim_EvalObj(interp, script);
17681
+ if (JimCheckLoopRetcode(interp, result)) {
17682
+ goto err;
17683
+ }
17684
+ switch (result) {
1643517685
case JIM_OK:
1643617686
if (doMap) {
1643717687
Jim_ListAppendElement(interp, resultObj, interp->result);
1643817688
}
1643917689
break;
@@ -16550,23 +17800,25 @@
1655017800
Jim_WrongNumArgs(interp, 1, argv, "condition ?then? trueBody ?elseif ...? ?else? falseBody");
1655117801
return JIM_ERR;
1655217802
}
1655317803
1655417804
16555
-
1655617805
int Jim_CommandMatchObj(Jim_Interp *interp, Jim_Obj *commandObj, Jim_Obj *patternObj,
16557
- Jim_Obj *stringObj, int nocase)
17806
+ Jim_Obj *stringObj, int flags)
1655817807
{
16559
- Jim_Obj *parms[4];
17808
+ Jim_Obj *parms[5];
1656017809
int argc = 0;
1656117810
long eq;
1656217811
int rc;
1656317812
1656417813
parms[argc++] = commandObj;
16565
- if (nocase) {
17814
+ if (flags & JIM_NOCASE) {
1656617815
parms[argc++] = Jim_NewStringObj(interp, "-nocase", -1);
1656717816
}
17817
+ if (flags & JIM_OPT_END) {
17818
+ parms[argc++] = Jim_NewStringObj(interp, "--", -1);
17819
+ }
1656817820
parms[argc++] = patternObj;
1656917821
parms[argc++] = stringObj;
1657017822
1657117823
rc = Jim_EvalObjVector(interp, argc, parms);
1657217824
@@ -16580,10 +17832,11 @@
1658017832
1658117833
static int Jim_SwitchCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
1658217834
{
1658317835
enum { SWITCH_EXACT, SWITCH_GLOB, SWITCH_RE, SWITCH_CMD };
1658417836
int matchOpt = SWITCH_EXACT, opt = 1, patCount, i;
17837
+ int match_flags = 0;
1658517838
Jim_Obj *command = NULL, *scriptObj = NULL, *strObj;
1658617839
Jim_Obj **caseList;
1658717840
1658817841
if (argc < 3) {
1658917842
wrongnumargs:
@@ -16602,12 +17855,14 @@
1660217855
}
1660317856
else if (strncmp(option, "-exact", 2) == 0)
1660417857
matchOpt = SWITCH_EXACT;
1660517858
else if (strncmp(option, "-glob", 2) == 0)
1660617859
matchOpt = SWITCH_GLOB;
16607
- else if (strncmp(option, "-regexp", 2) == 0)
17860
+ else if (strncmp(option, "-regexp", 2) == 0) {
1660817861
matchOpt = SWITCH_RE;
17862
+ match_flags |= JIM_OPT_END;
17863
+ }
1660917864
else if (strncmp(option, "-command", 2) == 0) {
1661017865
matchOpt = SWITCH_CMD;
1661117866
if ((argc - opt) < 2)
1661217867
goto wrongnumargs;
1661317868
command = argv[++opt];
@@ -16646,11 +17901,11 @@
1664617901
break;
1664717902
case SWITCH_RE:
1664817903
command = Jim_NewStringObj(interp, "regexp", -1);
1664917904
1665017905
case SWITCH_CMD:{
16651
- int rc = Jim_CommandMatchObj(interp, command, patObj, strObj, 0);
17906
+ int rc = Jim_CommandMatchObj(interp, command, patObj, strObj, match_flags);
1665217907
1665317908
if (argc - opt == 1) {
1665417909
JimListGetElements(interp, argv[opt], &patCount, &caseList);
1665517910
}
1665617911
@@ -16691,37 +17946,26 @@
1669117946
}
1669217947
1669317948
1669417949
static int Jim_LindexCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
1669517950
{
16696
- Jim_Obj *objPtr, *listObjPtr;
16697
- int i;
16698
- int idx;
17951
+ Jim_Obj *objPtr;
17952
+ int ret;
1669917953
1670017954
if (argc < 2) {
1670117955
Jim_WrongNumArgs(interp, 1, argv, "list ?index ...?");
1670217956
return JIM_ERR;
1670317957
}
16704
- objPtr = argv[1];
16705
- Jim_IncrRefCount(objPtr);
16706
- for (i = 2; i < argc; i++) {
16707
- listObjPtr = objPtr;
16708
- if (Jim_GetIndex(interp, argv[i], &idx) != JIM_OK) {
16709
- Jim_DecrRefCount(interp, listObjPtr);
16710
- return JIM_ERR;
16711
- }
16712
- if (Jim_ListIndex(interp, listObjPtr, idx, &objPtr, JIM_NONE) != JIM_OK) {
16713
- Jim_DecrRefCount(interp, listObjPtr);
16714
- Jim_SetEmptyResult(interp);
16715
- return JIM_OK;
16716
- }
16717
- Jim_IncrRefCount(objPtr);
16718
- Jim_DecrRefCount(interp, listObjPtr);
16719
- }
16720
- Jim_SetResult(interp, objPtr);
16721
- Jim_DecrRefCount(interp, objPtr);
16722
- return JIM_OK;
17958
+ ret = Jim_ListIndices(interp, argv[1], argv + 2, argc - 2, &objPtr, JIM_NONE);
17959
+ if (ret < 0) {
17960
+ ret = JIM_OK;
17961
+ Jim_SetEmptyResult(interp);
17962
+ }
17963
+ else if (ret == JIM_OK) {
17964
+ Jim_SetResult(interp, objPtr);
17965
+ }
17966
+ return ret;
1672317967
}
1672417968
1672517969
1672617970
static int Jim_LlengthCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
1672717971
{
@@ -16736,31 +17980,33 @@
1673617980
1673717981
static int Jim_LsearchCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
1673817982
{
1673917983
static const char * const options[] = {
1674017984
"-bool", "-not", "-nocase", "-exact", "-glob", "-regexp", "-all", "-inline", "-command",
16741
- NULL
17985
+ "-stride", "-index", NULL
1674217986
};
1674317987
enum
1674417988
{ OPT_BOOL, OPT_NOT, OPT_NOCASE, OPT_EXACT, OPT_GLOB, OPT_REGEXP, OPT_ALL, OPT_INLINE,
16745
- OPT_COMMAND };
17989
+ OPT_COMMAND, OPT_STRIDE, OPT_INDEX };
1674617990
int i;
1674717991
int opt_bool = 0;
1674817992
int opt_not = 0;
16749
- int opt_nocase = 0;
1675017993
int opt_all = 0;
1675117994
int opt_inline = 0;
1675217995
int opt_match = OPT_EXACT;
1675317996
int listlen;
1675417997
int rc = JIM_OK;
1675517998
Jim_Obj *listObjPtr = NULL;
1675617999
Jim_Obj *commandObj = NULL;
18000
+ Jim_Obj *indexObj = NULL;
18001
+ int match_flags = 0;
18002
+ long stride = 1;
1675718003
1675818004
if (argc < 3) {
1675918005
wrongargs:
1676018006
Jim_WrongNumArgs(interp, 1, argv,
16761
- "?-exact|-glob|-regexp|-command 'command'? ?-bool|-inline? ?-not? ?-nocase? ?-all? list value");
18007
+ "?-exact|-glob|-regexp|-command 'command'? ?-bool|-inline? ?-not? ?-nocase? ?-all? ?-stride len? ?-index val? list value");
1676218008
return JIM_ERR;
1676318009
}
1676418010
1676518011
for (i = 1; i < argc - 2; i++) {
1676618012
int option;
@@ -16775,34 +18021,65 @@
1677518021
break;
1677618022
case OPT_NOT:
1677718023
opt_not = 1;
1677818024
break;
1677918025
case OPT_NOCASE:
16780
- opt_nocase = 1;
18026
+ match_flags |= JIM_NOCASE;
1678118027
break;
1678218028
case OPT_INLINE:
1678318029
opt_inline = 1;
1678418030
opt_bool = 0;
1678518031
break;
1678618032
case OPT_ALL:
1678718033
opt_all = 1;
1678818034
break;
18035
+ case OPT_REGEXP:
18036
+ opt_match = option;
18037
+ match_flags |= JIM_OPT_END;
18038
+ break;
1678918039
case OPT_COMMAND:
1679018040
if (i >= argc - 2) {
1679118041
goto wrongargs;
1679218042
}
1679318043
commandObj = argv[++i];
1679418044
1679518045
case OPT_EXACT:
1679618046
case OPT_GLOB:
16797
- case OPT_REGEXP:
1679818047
opt_match = option;
1679918048
break;
18049
+ case OPT_INDEX:
18050
+ if (i >= argc - 2) {
18051
+ goto wrongargs;
18052
+ }
18053
+ indexObj = argv[++i];
18054
+ break;
18055
+ case OPT_STRIDE:
18056
+ if (i >= argc - 2) {
18057
+ goto wrongargs;
18058
+ }
18059
+ if (Jim_GetLong(interp, argv[++i], &stride) != JIM_OK) {
18060
+ return JIM_ERR;
18061
+ }
18062
+ if (stride < 1) {
18063
+ Jim_SetResultString(interp, "stride length must be at least 1", -1);
18064
+ return JIM_ERR;
18065
+ }
18066
+ break;
1680018067
}
1680118068
}
1680218069
18070
+ argc -= i;
18071
+ if (argc < 2) {
18072
+ goto wrongargs;
18073
+ }
1680318074
argv += i;
18075
+
18076
+ listlen = Jim_ListLength(interp, argv[0]);
18077
+ if (listlen % stride) {
18078
+ Jim_SetResultString(interp, "list size must be a multiple of the stride length", -1);
18079
+ return JIM_ERR;
18080
+ }
1680418081
1680518082
if (opt_all) {
1680618083
listObjPtr = Jim_NewListObj(interp, NULL, 0);
1680718084
}
1680818085
if (opt_match == OPT_REGEXP) {
@@ -16810,68 +18087,104 @@
1681018087
}
1681118088
if (commandObj) {
1681218089
Jim_IncrRefCount(commandObj);
1681318090
}
1681418091
16815
- listlen = Jim_ListLength(interp, argv[0]);
16816
- for (i = 0; i < listlen; i++) {
18092
+ for (i = 0; i < listlen; i += stride) {
1681718093
int eq = 0;
16818
- Jim_Obj *objPtr = Jim_ListGetIndex(interp, argv[0], i);
18094
+ Jim_Obj *searchListObj;
18095
+ Jim_Obj *objPtr;
18096
+ int offset;
18097
+
18098
+ if (indexObj) {
18099
+ int indexlen = Jim_ListLength(interp, indexObj);
18100
+ if (stride == 1) {
18101
+ searchListObj = Jim_ListGetIndex(interp, argv[0], i);
18102
+ }
18103
+ else {
18104
+ searchListObj = Jim_NewListObj(interp, argv[0]->internalRep.listValue.ele + i, stride);
18105
+ }
18106
+ Jim_IncrRefCount(searchListObj);
18107
+ rc = Jim_ListIndices(interp, searchListObj, indexObj->internalRep.listValue.ele, indexlen, &objPtr, JIM_ERRMSG);
18108
+ if (rc != JIM_OK) {
18109
+ Jim_DecrRefCount(interp, searchListObj);
18110
+ rc = JIM_ERR;
18111
+ goto done;
18112
+ }
18113
+
18114
+ offset = 0;
18115
+ }
18116
+ else {
18117
+
18118
+ searchListObj = argv[0];
18119
+ offset = i;
18120
+ objPtr = Jim_ListGetIndex(interp, searchListObj, i);
18121
+ Jim_IncrRefCount(searchListObj);
18122
+ }
1681918123
1682018124
switch (opt_match) {
1682118125
case OPT_EXACT:
16822
- eq = Jim_StringCompareObj(interp, argv[1], objPtr, opt_nocase) == 0;
18126
+ eq = Jim_StringCompareObj(interp, argv[1], objPtr, match_flags) == 0;
1682318127
break;
1682418128
1682518129
case OPT_GLOB:
16826
- eq = Jim_StringMatchObj(interp, argv[1], objPtr, opt_nocase);
18130
+ eq = Jim_StringMatchObj(interp, argv[1], objPtr, match_flags);
1682718131
break;
1682818132
1682918133
case OPT_REGEXP:
1683018134
case OPT_COMMAND:
16831
- eq = Jim_CommandMatchObj(interp, commandObj, argv[1], objPtr, opt_nocase);
18135
+ eq = Jim_CommandMatchObj(interp, commandObj, argv[1], objPtr, match_flags);
1683218136
if (eq < 0) {
16833
- if (listObjPtr) {
16834
- Jim_FreeNewObj(interp, listObjPtr);
16835
- }
18137
+ Jim_DecrRefCount(interp, searchListObj);
1683618138
rc = JIM_ERR;
1683718139
goto done;
1683818140
}
1683918141
break;
1684018142
}
1684118143
1684218144
16843
- if (!eq && opt_bool && opt_not && !opt_all) {
16844
- continue;
16845
- }
16846
-
1684718145
if ((!opt_bool && eq == !opt_not) || (opt_bool && (eq || opt_all))) {
16848
-
1684918146
Jim_Obj *resultObj;
1685018147
1685118148
if (opt_bool) {
1685218149
resultObj = Jim_NewIntObj(interp, eq ^ opt_not);
1685318150
}
1685418151
else if (!opt_inline) {
1685518152
resultObj = Jim_NewIntObj(interp, i);
1685618153
}
16857
- else {
18154
+ else if (stride == 1) {
1685818155
resultObj = objPtr;
1685918156
}
18157
+ else if (opt_all) {
18158
+
18159
+ ListInsertElements(listObjPtr, -1, stride,
18160
+ searchListObj->internalRep.listValue.ele + offset);
18161
+
18162
+ resultObj = NULL;
18163
+ }
18164
+ else {
18165
+ resultObj = Jim_NewListObj(interp, searchListObj->internalRep.listValue.ele + offset, stride);
18166
+ }
1686018167
1686118168
if (opt_all) {
16862
- Jim_ListAppendElement(interp, listObjPtr, resultObj);
18169
+
18170
+ if (stride == 1) {
18171
+ Jim_ListAppendElement(interp, listObjPtr, resultObj);
18172
+ }
1686318173
}
1686418174
else {
1686518175
Jim_SetResult(interp, resultObj);
18176
+ Jim_DecrRefCount(interp, searchListObj);
1686618177
goto done;
1686718178
}
1686818179
}
18180
+ Jim_DecrRefCount(interp, searchListObj);
1686918181
}
1687018182
1687118183
if (opt_all) {
1687218184
Jim_SetResult(interp, listObjPtr);
18185
+ listObjPtr = NULL;
1687318186
}
1687418187
else {
1687518188
1687618189
if (opt_bool) {
1687718190
Jim_SetResultBool(interp, opt_not);
@@ -16880,10 +18193,13 @@
1688018193
Jim_SetResultInt(interp, -1);
1688118194
}
1688218195
}
1688318196
1688418197
done:
18198
+ if (listObjPtr) {
18199
+ Jim_FreeNewObj(interp, listObjPtr);
18200
+ }
1688518201
if (commandObj) {
1688618202
Jim_DecrRefCount(interp, commandObj);
1688718203
}
1688818204
return rc;
1688918205
}
@@ -16993,11 +18309,11 @@
1699318309
1699418310
1699518311
static int Jim_LsetCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
1699618312
{
1699718313
if (argc < 3) {
16998
- Jim_WrongNumArgs(interp, 1, argv, "listVar ?index...? newVal");
18314
+ Jim_WrongNumArgs(interp, 1, argv, "listVar ?index ...? value");
1699918315
return JIM_ERR;
1700018316
}
1700118317
else if (argc == 3) {
1700218318
1700318319
if (Jim_SetVariable(interp, argv[1], argv[2]) != JIM_OK)
@@ -17010,29 +18326,34 @@
1701018326
1701118327
1701218328
static int Jim_LsortCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const argv[])
1701318329
{
1701418330
static const char * const options[] = {
17015
- "-ascii", "-nocase", "-increasing", "-decreasing", "-command", "-integer", "-real", "-index", "-unique", NULL
18331
+ "-ascii", "-nocase", "-increasing", "-decreasing", "-command", "-integer", "-real", "-index", "-unique",
18332
+ "-stride", NULL
1701618333
};
17017
- enum
17018
- { OPT_ASCII, OPT_NOCASE, OPT_INCREASING, OPT_DECREASING, OPT_COMMAND, OPT_INTEGER, OPT_REAL, OPT_INDEX, OPT_UNIQUE };
18334
+ enum {
18335
+ OPT_ASCII, OPT_NOCASE, OPT_INCREASING, OPT_DECREASING, OPT_COMMAND, OPT_INTEGER, OPT_REAL, OPT_INDEX, OPT_UNIQUE,
18336
+ OPT_STRIDE
18337
+ };
1701918338
Jim_Obj *resObj;
1702018339
int i;
1702118340
int retCode;
1702218341
int shared;
18342
+ long stride = 1;
1702318343
1702418344
struct lsort_info info;
1702518345
1702618346
if (argc < 2) {
18347
+wrongargs:
1702718348
Jim_WrongNumArgs(interp, 1, argv, "?options? list");
1702818349
return JIM_ERR;
1702918350
}
1703018351
1703118352
info.type = JIM_LSORT_ASCII;
1703218353
info.order = 1;
17033
- info.indexed = 0;
18354
+ info.indexc = 0;
1703418355
info.unique = 0;
1703518356
info.command = NULL;
1703618357
info.interp = interp;
1703718358
1703818359
for (i = 1; i < (argc - 1); i++) {
@@ -17069,33 +18390,77 @@
1706918390
return JIM_ERR;
1707018391
}
1707118392
info.type = JIM_LSORT_COMMAND;
1707218393
info.command = argv[i + 1];
1707318394
i++;
18395
+ break;
18396
+ case OPT_STRIDE:
18397
+ if (i >= argc - 2) {
18398
+ goto wrongargs;
18399
+ }
18400
+ if (Jim_GetLong(interp, argv[++i], &stride) != JIM_OK) {
18401
+ return JIM_ERR;
18402
+ }
18403
+ if (stride < 2) {
18404
+ Jim_SetResultString(interp, "stride length must be at least 2", -1);
18405
+ return JIM_ERR;
18406
+ }
1707418407
break;
1707518408
case OPT_INDEX:
1707618409
if (i >= (argc - 2)) {
18410
+badindex:
1707718411
Jim_SetResultString(interp, "\"-index\" option must be followed by list index", -1);
1707818412
return JIM_ERR;
1707918413
}
17080
- if (Jim_GetIndex(interp, argv[i + 1], &info.index) != JIM_OK) {
17081
- return JIM_ERR;
18414
+ JimListGetElements(interp, argv[i + 1], &info.indexc, &info.indexv);
18415
+ if (info.indexc == 0) {
18416
+ goto badindex;
1708218417
}
17083
- info.indexed = 1;
1708418418
i++;
1708518419
break;
1708618420
}
1708718421
}
1708818422
resObj = argv[argc - 1];
17089
- if ((shared = Jim_IsShared(resObj)))
17090
- resObj = Jim_DuplicateObj(interp, resObj);
17091
- retCode = ListSortElements(interp, resObj, &info);
17092
- if (retCode == JIM_OK) {
17093
- Jim_SetResult(interp, resObj);
17094
- }
17095
- else if (shared) {
17096
- Jim_FreeNewObj(interp, resObj);
18423
+ if (stride > 1) {
18424
+ Jim_Obj *tmpListObj;
18425
+ Jim_Obj **elements;
18426
+ int listlen;
18427
+ int i;
18428
+
18429
+ JimListGetElements(interp, resObj, &listlen, &elements);
18430
+ if (listlen % stride) {
18431
+ Jim_SetResultString(interp, "list size must be a multiple of the stride length", -1);
18432
+ return JIM_ERR;
18433
+ }
18434
+
18435
+ tmpListObj = Jim_NewListObj(interp, NULL, 0);
18436
+ Jim_IncrRefCount(tmpListObj);
18437
+ for (i = 0; i < listlen; i += stride) {
18438
+ Jim_ListAppendElement(interp, tmpListObj, Jim_NewListObj(interp, elements + i, stride));
18439
+ }
18440
+ retCode = ListSortElements(interp, tmpListObj, &info);
18441
+ if (retCode == JIM_OK) {
18442
+ resObj = Jim_NewListObj(interp, NULL, 0);
18443
+
18444
+ for (i = 0; i < listlen; i += stride) {
18445
+ Jim_ListAppendList(interp, resObj, Jim_ListGetIndex(interp, tmpListObj, i / stride));
18446
+ }
18447
+ Jim_SetResult(interp, resObj);
18448
+ }
18449
+ Jim_DecrRefCount(interp, tmpListObj);
18450
+ }
18451
+ else {
18452
+ if ((shared = Jim_IsShared(resObj))) {
18453
+ resObj = Jim_DuplicateObj(interp, resObj);
18454
+ }
18455
+ retCode = ListSortElements(interp, resObj, &info);
18456
+ if (retCode == JIM_OK) {
18457
+ Jim_SetResult(interp, resObj);
18458
+ }
18459
+ else if (shared) {
18460
+ Jim_FreeNewObj(interp, resObj);
18461
+ }
1709718462
}
1709818463
return retCode;
1709918464
}
1710018465
1710118466
@@ -17139,17 +18504,10 @@
1713918504
return JIM_OK;
1714018505
}
1714118506
1714218507
1714318508
17144
-static int Jim_DebugCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
17145
-{
17146
-#if !defined(JIM_DEBUG_COMMAND)
17147
- Jim_SetResultString(interp, "unsupported", -1);
17148
- return JIM_ERR;
17149
-#endif
17150
-}
1715118509
1715218510
1715318511
static int Jim_EvalCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
1715418512
{
1715518513
int rc;
@@ -17164,14 +18522,10 @@
1716418522
}
1716518523
else {
1716618524
rc = Jim_EvalObj(interp, Jim_ConcatObj(interp, argc - 1, argv + 1));
1716718525
}
1716818526
17169
- if (rc == JIM_ERR) {
17170
-
17171
- interp->addStackTrace++;
17172
- }
1717318527
return rc;
1717418528
}
1717518529
1717618530
1717718531
static int Jim_UplevelCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
@@ -17224,10 +18578,16 @@
1722418578
int retcode;
1722518579
1722618580
if (argc == 2) {
1722718581
retcode = Jim_EvalExpression(interp, argv[1]);
1722818582
}
18583
+#ifndef JIM_COMPAT
18584
+ else {
18585
+ Jim_WrongNumArgs(interp, 1, argv, "expression");
18586
+ retcode = JIM_ERR;
18587
+ }
18588
+#else
1722918589
else if (argc > 2) {
1723018590
Jim_Obj *objPtr;
1723118591
1723218592
objPtr = Jim_ConcatObj(interp, argc - 1, argv + 1);
1723318593
Jim_IncrRefCount(objPtr);
@@ -17236,33 +18596,72 @@
1723618596
}
1723718597
else {
1723818598
Jim_WrongNumArgs(interp, 1, argv, "expression ?...?");
1723918599
return JIM_ERR;
1724018600
}
17241
- if (retcode != JIM_OK)
17242
- return retcode;
17243
- return JIM_OK;
18601
+#endif
18602
+ return retcode;
18603
+}
18604
+
18605
+static int JimBreakContinueHelper(Jim_Interp *interp, int argc, Jim_Obj *const *argv, int retcode)
18606
+{
18607
+ if (argc != 1 && argc != 2) {
18608
+ Jim_WrongNumArgs(interp, 1, argv, "?level?");
18609
+ return JIM_ERR;
18610
+ }
18611
+ if (argc == 2) {
18612
+ long level;
18613
+ int ret = Jim_GetLong(interp, argv[1], &level);
18614
+ if (ret != JIM_OK) {
18615
+ return ret;
18616
+ }
18617
+ interp->returnLevel = level;
18618
+ }
18619
+ return retcode;
1724418620
}
1724518621
1724618622
1724718623
static int Jim_BreakCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
1724818624
{
17249
- if (argc != 1) {
17250
- Jim_WrongNumArgs(interp, 1, argv, "");
17251
- return JIM_ERR;
17252
- }
17253
- return JIM_BREAK;
18625
+ return JimBreakContinueHelper(interp, argc, argv, JIM_BREAK);
1725418626
}
1725518627
1725618628
1725718629
static int Jim_ContinueCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
1725818630
{
17259
- if (argc != 1) {
17260
- Jim_WrongNumArgs(interp, 1, argv, "");
17261
- return JIM_ERR;
18631
+ return JimBreakContinueHelper(interp, argc, argv, JIM_CONTINUE);
18632
+}
18633
+
18634
+
18635
+static int Jim_StacktraceCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
18636
+{
18637
+ Jim_Obj *listObj;
18638
+ int i;
18639
+ jim_wide skip = 0;
18640
+ jim_wide last = 0;
18641
+
18642
+ if (argc > 1) {
18643
+ if (Jim_GetWideExpr(interp, argv[1], &skip) != JIM_OK) {
18644
+ return JIM_ERR;
18645
+ }
1726218646
}
17263
- return JIM_CONTINUE;
18647
+ if (argc > 2) {
18648
+ if (Jim_GetWideExpr(interp, argv[2], &last) != JIM_OK) {
18649
+ return JIM_ERR;
18650
+ }
18651
+ }
18652
+
18653
+ listObj = Jim_NewListObj(interp, NULL, 0);
18654
+ for (i = skip; i <= interp->procLevel; i++) {
18655
+ Jim_EvalFrame *frame = JimGetEvalFrameByProcLevel(interp, -i);
18656
+ if (frame->procLevel < last) {
18657
+ break;
18658
+ }
18659
+ JimAddStackFrame(interp, frame, listObj);
18660
+ }
18661
+ Jim_SetResult(interp, listObj);
18662
+ return JIM_OK;
1726418663
}
1726518664
1726618665
1726718666
static int Jim_ReturnCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
1726818667
{
@@ -17312,11 +18711,11 @@
1731218711
interp->returnLevel = level;
1731318712
1731418713
if (i == argc - 1) {
1731518714
Jim_SetResult(interp, argv[i]);
1731618715
}
17317
- return JIM_RETURN;
18716
+ return level == 0 ? returnCode : JIM_RETURN;
1731818717
}
1731918718
1732018719
1732118720
static int Jim_TailcallCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
1732218721
{
@@ -17370,28 +18769,21 @@
1737018769
}
1737118770
1737218771
static int Jim_AliasCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
1737318772
{
1737418773
Jim_Obj *prefixListObj;
17375
- const char *newname;
1737618774
1737718775
if (argc < 3) {
1737818776
Jim_WrongNumArgs(interp, 1, argv, "newname command ?args ...?");
1737918777
return JIM_ERR;
1738018778
}
1738118779
1738218780
prefixListObj = Jim_NewListObj(interp, argv + 2, argc - 2);
1738318781
Jim_IncrRefCount(prefixListObj);
17384
- newname = Jim_String(argv[1]);
17385
- if (newname[0] == ':' && newname[1] == ':') {
17386
- while (*++newname == ':') {
17387
- }
17388
- }
17389
-
1739018782
Jim_SetResult(interp, argv[1]);
1739118783
17392
- return Jim_CreateCommand(interp, newname, JimAliasCmd, prefixListObj, JimAliasCmdDelete);
18784
+ return Jim_CreateCommandObj(interp, argv[1], JimAliasCmd, prefixListObj, JimAliasCmdDelete);
1739318785
}
1739418786
1739518787
1739618788
static int Jim_ProcCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
1739718789
{
@@ -17400,40 +18792,54 @@
1740018792
if (argc != 4 && argc != 5) {
1740118793
Jim_WrongNumArgs(interp, 1, argv, "name arglist ?statics? body");
1740218794
return JIM_ERR;
1740318795
}
1740418796
17405
- if (JimValidName(interp, "procedure", argv[1]) != JIM_OK) {
17406
- return JIM_ERR;
17407
- }
17408
-
1740918797
if (argc == 4) {
1741018798
cmd = JimCreateProcedureCmd(interp, argv[2], NULL, argv[3], NULL);
1741118799
}
1741218800
else {
1741318801
cmd = JimCreateProcedureCmd(interp, argv[2], argv[3], argv[4], NULL);
1741418802
}
1741518803
1741618804
if (cmd) {
1741718805
17418
- Jim_Obj *qualifiedCmdNameObj;
17419
- const char *cmdname = JimQualifyName(interp, Jim_String(argv[1]), &qualifiedCmdNameObj);
17420
-
17421
- JimCreateCommand(interp, cmdname, cmd);
18806
+ Jim_Obj *nameObjPtr = JimQualifyName(interp, argv[1]);
18807
+ JimCreateCommand(interp, nameObjPtr, cmd);
1742218808
1742318809
17424
- JimUpdateProcNamespace(interp, cmd, cmdname);
17425
-
17426
- JimFreeQualifiedName(interp, qualifiedCmdNameObj);
18810
+ JimUpdateProcNamespace(interp, cmd, nameObjPtr);
18811
+ Jim_DecrRefCount(interp, nameObjPtr);
1742718812
1742818813
1742918814
Jim_SetResult(interp, argv[1]);
1743018815
return JIM_OK;
1743118816
}
1743218817
return JIM_ERR;
1743318818
}
1743418819
18820
+
18821
+static int Jim_XtraceCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
18822
+{
18823
+ if (argc != 2) {
18824
+ Jim_WrongNumArgs(interp, 1, argv, "callback");
18825
+ return JIM_ERR;
18826
+ }
18827
+
18828
+ if (interp->traceCmdObj) {
18829
+ Jim_DecrRefCount(interp, interp->traceCmdObj);
18830
+ interp->traceCmdObj = NULL;
18831
+ }
18832
+
18833
+ if (Jim_Length(argv[1])) {
18834
+
18835
+ interp->traceCmdObj = argv[1];
18836
+ Jim_IncrRefCount(interp->traceCmdObj);
18837
+ }
18838
+ return JIM_OK;
18839
+}
18840
+
1743518841
1743618842
static int Jim_LocalCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
1743718843
{
1743818844
int retcode;
1743918845
@@ -17518,11 +18924,11 @@
1751818924
}
1751918925
1752018926
if (len == 3) {
1752118927
#ifdef jim_ext_namespace
1752218928
17523
- nsObj = JimQualifyNameObj(interp, Jim_ListGetIndex(interp, argv[1], 2));
18929
+ nsObj = Jim_ListGetIndex(interp, argv[1], 2);
1752418930
#else
1752518931
Jim_SetResultString(interp, "namespaces not enabled", -1);
1752618932
return JIM_ERR;
1752718933
#endif
1752818934
}
@@ -17641,11 +19047,11 @@
1764119047
k = Jim_String(eachObjPtr);
1764219048
kl = Jim_Utf8Length(interp, eachObjPtr);
1764319049
1764419050
if (strLen >= kl && kl) {
1764519051
int rc;
17646
- rc = JimStringCompareLen(str, k, kl, nocase);
19052
+ rc = JimStringCompareUtf8(str, kl, k, kl, nocase);
1764719053
if (rc == 0) {
1764819054
if (noMatchStart) {
1764919055
Jim_AppendString(interp, resultObjPtr, noMatchStart, str - noMatchStart);
1765019056
noMatchStart = NULL;
1765119057
}
@@ -17674,50 +19080,85 @@
1767419080
static int Jim_StringCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
1767519081
{
1767619082
int len;
1767719083
int opt_case = 1;
1767819084
int option;
17679
- static const char * const options[] = {
17680
- "bytelength", "length", "compare", "match", "equal", "is", "byterange", "range", "replace",
17681
- "map", "repeat", "reverse", "index", "first", "last", "cat",
17682
- "trim", "trimleft", "trimright", "tolower", "toupper", "totitle", NULL
17683
- };
17684
- enum
17685
- {
17686
- OPT_BYTELENGTH, OPT_LENGTH, OPT_COMPARE, OPT_MATCH, OPT_EQUAL, OPT_IS, OPT_BYTERANGE, OPT_RANGE, OPT_REPLACE,
17687
- OPT_MAP, OPT_REPEAT, OPT_REVERSE, OPT_INDEX, OPT_FIRST, OPT_LAST, OPT_CAT,
17688
- OPT_TRIM, OPT_TRIMLEFT, OPT_TRIMRIGHT, OPT_TOLOWER, OPT_TOUPPER, OPT_TOTITLE
17689
- };
1769019085
static const char * const nocase_options[] = {
1769119086
"-nocase", NULL
1769219087
};
1769319088
static const char * const nocase_length_options[] = {
1769419089
"-nocase", "-length", NULL
1769519090
};
1769619091
17697
- if (argc < 2) {
17698
- Jim_WrongNumArgs(interp, 1, argv, "option ?arguments ...?");
19092
+ enum {
19093
+ OPT_BYTELENGTH,
19094
+ OPT_BYTERANGE,
19095
+ OPT_CAT,
19096
+ OPT_COMPARE,
19097
+ OPT_EQUAL,
19098
+ OPT_FIRST,
19099
+ OPT_INDEX,
19100
+ OPT_IS,
19101
+ OPT_LAST,
19102
+ OPT_LENGTH,
19103
+ OPT_MAP,
19104
+ OPT_MATCH,
19105
+ OPT_RANGE,
19106
+ OPT_REPEAT,
19107
+ OPT_REPLACE,
19108
+ OPT_REVERSE,
19109
+ OPT_TOLOWER,
19110
+ OPT_TOTITLE,
19111
+ OPT_TOUPPER,
19112
+ OPT_TRIM,
19113
+ OPT_TRIMLEFT,
19114
+ OPT_TRIMRIGHT,
19115
+ OPT_COUNT
19116
+ };
19117
+ static const jim_subcmd_type cmds[OPT_COUNT + 1] = {
19118
+ JIM_DEF_SUBCMD("bytelength", "string", 1, 1),
19119
+ JIM_DEF_SUBCMD("byterange", "string first last", 3, 3),
19120
+ JIM_DEF_SUBCMD("cat", "?...?", 0, -1),
19121
+ JIM_DEF_SUBCMD("compare", "?-nocase? ?-length int? string1 string2", 2, 5),
19122
+ JIM_DEF_SUBCMD("equal", "?-nocase? ?-length int? string1 string2", 2, 5),
19123
+ JIM_DEF_SUBCMD("first", "subString string ?index?", 2, 3),
19124
+ JIM_DEF_SUBCMD("index", "string index", 2, 2),
19125
+ JIM_DEF_SUBCMD("is", "class ?-strict? str", 2, 3),
19126
+ JIM_DEF_SUBCMD("last", "subString string ?index?", 2, 3),
19127
+ JIM_DEF_SUBCMD("length","string", 1, 1),
19128
+ JIM_DEF_SUBCMD("map", "?-nocase? mapList string", 2, 3),
19129
+ JIM_DEF_SUBCMD("match", "?-nocase? pattern string", 2, 3),
19130
+ JIM_DEF_SUBCMD("range", "string first last", 3, 3),
19131
+ JIM_DEF_SUBCMD("repeat", "string count", 2, 2),
19132
+ JIM_DEF_SUBCMD("replace", "string first last ?string?", 3, 4),
19133
+ JIM_DEF_SUBCMD("reverse", "string", 1, 1),
19134
+ JIM_DEF_SUBCMD("tolower", "string", 1, 1),
19135
+ JIM_DEF_SUBCMD("totitle", "string", 1, 1),
19136
+ JIM_DEF_SUBCMD("toupper", "string", 1, 1),
19137
+ JIM_DEF_SUBCMD("trim", "string ?trimchars?", 1, 2),
19138
+ JIM_DEF_SUBCMD("trimleft", "string ?trimchars?", 1, 2),
19139
+ JIM_DEF_SUBCMD("trimright", "string ?trimchars?", 1, 2),
19140
+ { }
19141
+ };
19142
+ const jim_subcmd_type *ct = Jim_ParseSubCmd(interp, cmds, argc, argv);
19143
+ if (!ct) {
1769919144
return JIM_ERR;
1770019145
}
17701
- if (Jim_GetEnum(interp, argv[1], options, &option, NULL,
17702
- JIM_ERRMSG | JIM_ENUM_ABBREV) != JIM_OK)
17703
- return Jim_CheckShowCommands(interp, argv[1], options);
19146
+ if (ct->function) {
19147
+
19148
+ return ct->function(interp, argc, argv);
19149
+ }
19150
+
19151
+ option = ct - cmds;
1770419152
1770519153
switch (option) {
1770619154
case OPT_LENGTH:
19155
+ Jim_SetResultInt(interp, Jim_Utf8Length(interp, argv[2]));
19156
+ return JIM_OK;
19157
+
1770719158
case OPT_BYTELENGTH:
17708
- if (argc != 3) {
17709
- Jim_WrongNumArgs(interp, 2, argv, "string");
17710
- return JIM_ERR;
17711
- }
17712
- if (option == OPT_LENGTH) {
17713
- len = Jim_Utf8Length(interp, argv[2]);
17714
- }
17715
- else {
17716
- len = Jim_Length(argv[2]);
17717
- }
17718
- Jim_SetResultInt(interp, len);
19159
+ Jim_SetResultInt(interp, Jim_Length(argv[2]));
1771919160
return JIM_OK;
1772019161
1772119162
case OPT_CAT:{
1772219163
Jim_Obj *objPtr;
1772319164
if (argc == 3) {
@@ -17747,11 +19188,11 @@
1774719188
while (n > 0) {
1774819189
int subopt;
1774919190
if (Jim_GetEnum(interp, argv[i++], nocase_length_options, &subopt, NULL,
1775019191
JIM_ENUM_ABBREV) != JIM_OK) {
1775119192
badcompareargs:
17752
- Jim_WrongNumArgs(interp, 2, argv, "?-nocase? ?-length int? string1 string2");
19193
+ Jim_SubCmdArgError(interp, ct, argv[0]);
1775319194
return JIM_ERR;
1775419195
}
1775519196
if (subopt == 0) {
1775619197
1775719198
opt_case = 0;
@@ -17775,16 +19216,23 @@
1777519216
if (opt_length < 0 && option != OPT_COMPARE && opt_case) {
1777619217
1777719218
Jim_SetResultBool(interp, Jim_StringEqObj(argv[0], argv[1]));
1777819219
}
1777919220
else {
19221
+ const char *s1 = Jim_String(argv[0]);
19222
+ int l1 = Jim_Utf8Length(interp, argv[0]);
19223
+ const char *s2 = Jim_String(argv[1]);
19224
+ int l2 = Jim_Utf8Length(interp, argv[1]);
1778019225
if (opt_length >= 0) {
17781
- n = JimStringCompareLen(Jim_String(argv[0]), Jim_String(argv[1]), opt_length, !opt_case);
17782
- }
17783
- else {
17784
- n = Jim_StringCompareObj(interp, argv[0], argv[1], !opt_case);
19226
+ if (l1 > opt_length) {
19227
+ l1 = opt_length;
19228
+ }
19229
+ if (l2 > opt_length) {
19230
+ l2 = opt_length;
19231
+ }
1778519232
}
19233
+ n = JimStringCompareUtf8(s1, l1, s2, l2, !opt_case);
1778619234
Jim_SetResultInt(interp, option == OPT_COMPARE ? n : n == 0);
1778719235
}
1778819236
return JIM_OK;
1778919237
}
1779019238
@@ -17822,41 +19270,30 @@
1782219270
}
1782319271
Jim_SetResult(interp, objPtr);
1782419272
return JIM_OK;
1782519273
}
1782619274
17827
- case OPT_RANGE:
19275
+ case OPT_RANGE:{
19276
+ Jim_Obj *objPtr = Jim_StringRangeObj(interp, argv[2], argv[3], argv[4]);
19277
+ if (objPtr == NULL) {
19278
+ return JIM_ERR;
19279
+ }
19280
+ Jim_SetResult(interp, objPtr);
19281
+ return JIM_OK;
19282
+ }
19283
+
1782819284
case OPT_BYTERANGE:{
17829
- Jim_Obj *objPtr;
17830
-
17831
- if (argc != 5) {
17832
- Jim_WrongNumArgs(interp, 2, argv, "string first last");
17833
- return JIM_ERR;
17834
- }
17835
- if (option == OPT_RANGE) {
17836
- objPtr = Jim_StringRangeObj(interp, argv[2], argv[3], argv[4]);
17837
- }
17838
- else
17839
- {
17840
- objPtr = Jim_StringByteRangeObj(interp, argv[2], argv[3], argv[4]);
17841
- }
17842
-
19285
+ Jim_Obj *objPtr = Jim_StringByteRangeObj(interp, argv[2], argv[3], argv[4]);
1784319286
if (objPtr == NULL) {
1784419287
return JIM_ERR;
1784519288
}
1784619289
Jim_SetResult(interp, objPtr);
1784719290
return JIM_OK;
1784819291
}
1784919292
1785019293
case OPT_REPLACE:{
17851
- Jim_Obj *objPtr;
17852
-
17853
- if (argc != 5 && argc != 6) {
17854
- Jim_WrongNumArgs(interp, 2, argv, "string first last ?string?");
17855
- return JIM_ERR;
17856
- }
17857
- objPtr = JimStringReplaceObj(interp, argv[2], argv[3], argv[4], argc == 6 ? argv[5] : NULL);
19294
+ Jim_Obj *objPtr = JimStringReplaceObj(interp, argv[2], argv[3], argv[4], argc == 6 ? argv[5] : NULL);
1785819295
if (objPtr == NULL) {
1785919296
return JIM_ERR;
1786019297
}
1786119298
Jim_SetResult(interp, objPtr);
1786219299
return JIM_OK;
@@ -17865,15 +19302,11 @@
1786519302
1786619303
case OPT_REPEAT:{
1786719304
Jim_Obj *objPtr;
1786819305
jim_wide count;
1786919306
17870
- if (argc != 4) {
17871
- Jim_WrongNumArgs(interp, 2, argv, "string count");
17872
- return JIM_ERR;
17873
- }
17874
- if (Jim_GetWide(interp, argv[3], &count) != JIM_OK) {
19307
+ if (Jim_GetWideExpr(interp, argv[3], &count) != JIM_OK) {
1787519308
return JIM_ERR;
1787619309
}
1787719310
objPtr = Jim_NewStringObj(interp, "", 0);
1787819311
if (count > 0) {
1787919312
while (count--) {
@@ -17887,17 +19320,13 @@
1788719320
case OPT_REVERSE:{
1788819321
char *buf, *p;
1788919322
const char *str;
1789019323
int i;
1789119324
17892
- if (argc != 3) {
17893
- Jim_WrongNumArgs(interp, 2, argv, "string");
17894
- return JIM_ERR;
17895
- }
17896
-
1789719325
str = Jim_GetString(argv[2], &len);
1789819326
buf = Jim_Alloc(len + 1);
19327
+ assert(buf);
1789919328
p = buf + len;
1790019329
*p = 0;
1790119330
for (i = 0; i < len; ) {
1790219331
int c;
1790319332
int l = utf8_tounicode(str, &c);
@@ -17912,22 +19341,16 @@
1791219341
1791319342
case OPT_INDEX:{
1791419343
int idx;
1791519344
const char *str;
1791619345
17917
- if (argc != 4) {
17918
- Jim_WrongNumArgs(interp, 2, argv, "string index");
17919
- return JIM_ERR;
17920
- }
1792119346
if (Jim_GetIndex(interp, argv[3], &idx) != JIM_OK) {
1792219347
return JIM_ERR;
1792319348
}
1792419349
str = Jim_String(argv[2]);
1792519350
len = Jim_Utf8Length(interp, argv[2]);
17926
- if (idx != INT_MIN && idx != INT_MAX) {
17927
- idx = JimRelToAbsIndex(len, idx);
17928
- }
19351
+ idx = JimRelToAbsIndex(len, idx);
1792919352
if (idx < 0 || idx >= len || str == NULL) {
1793019353
Jim_SetResultString(interp, "", 0);
1793119354
}
1793219355
else if (len == Jim_Length(argv[2])) {
1793319356
@@ -17944,23 +19367,22 @@
1794419367
case OPT_FIRST:
1794519368
case OPT_LAST:{
1794619369
int idx = 0, l1, l2;
1794719370
const char *s1, *s2;
1794819371
17949
- if (argc != 4 && argc != 5) {
17950
- Jim_WrongNumArgs(interp, 2, argv, "subString string ?index?");
17951
- return JIM_ERR;
17952
- }
1795319372
s1 = Jim_String(argv[2]);
1795419373
s2 = Jim_String(argv[3]);
1795519374
l1 = Jim_Utf8Length(interp, argv[2]);
1795619375
l2 = Jim_Utf8Length(interp, argv[3]);
1795719376
if (argc == 5) {
1795819377
if (Jim_GetIndex(interp, argv[4], &idx) != JIM_OK) {
1795919378
return JIM_ERR;
1796019379
}
1796119380
idx = JimRelToAbsIndex(l2, idx);
19381
+ if (idx < 0) {
19382
+ idx = 0;
19383
+ }
1796219384
}
1796319385
else if (option == OPT_LAST) {
1796419386
idx = l2;
1796519387
}
1796619388
if (option == OPT_FIRST) {
@@ -17975,66 +19397,45 @@
1797519397
}
1797619398
return JIM_OK;
1797719399
}
1797819400
1797919401
case OPT_TRIM:
19402
+ Jim_SetResult(interp, JimStringTrim(interp, argv[2], argc == 4 ? argv[3] : NULL));
19403
+ return JIM_OK;
1798019404
case OPT_TRIMLEFT:
19405
+ Jim_SetResult(interp, JimStringTrimLeft(interp, argv[2], argc == 4 ? argv[3] : NULL));
19406
+ return JIM_OK;
1798119407
case OPT_TRIMRIGHT:{
17982
- Jim_Obj *trimchars;
17983
-
17984
- if (argc != 3 && argc != 4) {
17985
- Jim_WrongNumArgs(interp, 2, argv, "string ?trimchars?");
17986
- return JIM_ERR;
17987
- }
17988
- trimchars = (argc == 4 ? argv[3] : NULL);
17989
- if (option == OPT_TRIM) {
17990
- Jim_SetResult(interp, JimStringTrim(interp, argv[2], trimchars));
17991
- }
17992
- else if (option == OPT_TRIMLEFT) {
17993
- Jim_SetResult(interp, JimStringTrimLeft(interp, argv[2], trimchars));
17994
- }
17995
- else if (option == OPT_TRIMRIGHT) {
17996
- Jim_SetResult(interp, JimStringTrimRight(interp, argv[2], trimchars));
17997
- }
19408
+ Jim_SetResult(interp, JimStringTrimRight(interp, argv[2], argc == 4 ? argv[3] : NULL));
1799819409
return JIM_OK;
17999
- }
19410
+ }
1800019411
1800119412
case OPT_TOLOWER:
18002
- case OPT_TOUPPER:
18003
- case OPT_TOTITLE:
18004
- if (argc != 3) {
18005
- Jim_WrongNumArgs(interp, 2, argv, "string");
18006
- return JIM_ERR;
18007
- }
18008
- if (option == OPT_TOLOWER) {
1800919413
Jim_SetResult(interp, JimStringToLower(interp, argv[2]));
18010
- }
18011
- else if (option == OPT_TOUPPER) {
19414
+ return JIM_OK;
19415
+ case OPT_TOUPPER:
1801219416
Jim_SetResult(interp, JimStringToUpper(interp, argv[2]));
18013
- }
18014
- else {
19417
+ return JIM_OK;
19418
+ case OPT_TOTITLE:
1801519419
Jim_SetResult(interp, JimStringToTitle(interp, argv[2]));
18016
- }
18017
- return JIM_OK;
19420
+ return JIM_OK;
1801819421
1801919422
case OPT_IS:
18020
- if (argc == 4 || (argc == 5 && Jim_CompareStringImmediate(interp, argv[3], "-strict"))) {
18021
- return JimStringIs(interp, argv[argc - 1], argv[2], argc == 5);
19423
+ if (argc == 5 && !Jim_CompareStringImmediate(interp, argv[3], "-strict")) {
19424
+ Jim_SubCmdArgError(interp, ct, argv[0]);
19425
+ return JIM_ERR;
1802219426
}
18023
- Jim_WrongNumArgs(interp, 2, argv, "class ?-strict? str");
18024
- return JIM_ERR;
19427
+ return JimStringIs(interp, argv[argc - 1], argv[2], argc == 5);
1802519428
}
1802619429
return JIM_OK;
1802719430
}
1802819431
1802919432
1803019433
static int Jim_TimeCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
1803119434
{
1803219435
long i, count = 1;
1803319436
jim_wide start, elapsed;
18034
- char buf[60];
18035
- const char *fmt = "%" JIM_WIDE_MODIFIER " microseconds per iteration";
1803619437
1803719438
if (argc < 2) {
1803819439
Jim_WrongNumArgs(interp, 1, argv, "script ?count?");
1803919440
return JIM_ERR;
1804019441
}
@@ -18043,22 +19444,92 @@
1804319444
return JIM_ERR;
1804419445
}
1804519446
if (count < 0)
1804619447
return JIM_OK;
1804719448
i = count;
18048
- start = JimClock();
19449
+ start = Jim_GetTimeUsec(CLOCK_MONOTONIC_RAW);
1804919450
while (i-- > 0) {
1805019451
int retval;
1805119452
1805219453
retval = Jim_EvalObj(interp, argv[1]);
1805319454
if (retval != JIM_OK) {
1805419455
return retval;
1805519456
}
1805619457
}
18057
- elapsed = JimClock() - start;
18058
- sprintf(buf, fmt, count == 0 ? 0 : elapsed / count);
18059
- Jim_SetResultString(interp, buf, -1);
19458
+ elapsed = Jim_GetTimeUsec(CLOCK_MONOTONIC_RAW) - start;
19459
+ if (elapsed < count * 10) {
19460
+ Jim_SetResult(interp, Jim_NewDoubleObj(interp, elapsed * 1.0 / count));
19461
+ }
19462
+ else {
19463
+ Jim_SetResultInt(interp, count == 0 ? 0 : elapsed / count);
19464
+ }
19465
+ Jim_AppendString(interp, Jim_GetResult(interp)," microseconds per iteration", -1);
19466
+ return JIM_OK;
19467
+}
19468
+
19469
+
19470
+static int Jim_TimeRateCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
19471
+{
19472
+ long us = 0;
19473
+ jim_wide start, delta, overhead;
19474
+ Jim_Obj *objPtr;
19475
+ double us_per_iter;
19476
+ int count;
19477
+ int n;
19478
+
19479
+ if (argc < 2) {
19480
+ Jim_WrongNumArgs(interp, 1, argv, "script ?milliseconds?");
19481
+ return JIM_ERR;
19482
+ }
19483
+ if (argc == 3) {
19484
+ if (Jim_GetLong(interp, argv[2], &us) != JIM_OK)
19485
+ return JIM_ERR;
19486
+ us *= 1000;
19487
+ }
19488
+ if (us < 1) {
19489
+
19490
+ us = 1000 * 1000;
19491
+ }
19492
+
19493
+
19494
+ start = Jim_GetTimeUsec(CLOCK_MONOTONIC_RAW);
19495
+ count = 0;
19496
+ do {
19497
+ int retval = Jim_EvalObj(interp, argv[1]);
19498
+ delta = Jim_GetTimeUsec(CLOCK_MONOTONIC_RAW) - start;
19499
+ if (retval != JIM_OK) {
19500
+ return retval;
19501
+ }
19502
+ count++;
19503
+ } while (delta < us);
19504
+
19505
+
19506
+ start = Jim_GetTimeUsec(CLOCK_MONOTONIC_RAW);
19507
+ n = 0;
19508
+ do {
19509
+ int retval = Jim_EvalObj(interp, interp->nullScriptObj);
19510
+ overhead = Jim_GetTimeUsec(CLOCK_MONOTONIC_RAW) - start;
19511
+ if (retval != JIM_OK) {
19512
+ return retval;
19513
+ }
19514
+ n++;
19515
+ } while (n < count);
19516
+
19517
+ delta -= overhead;
19518
+
19519
+ us_per_iter = (double)delta / count;
19520
+ objPtr = Jim_NewListObj(interp, NULL, 0);
19521
+
19522
+ Jim_ListAppendElement(interp, objPtr, Jim_NewStringObj(interp, "us_per_iter", -1));
19523
+ Jim_ListAppendElement(interp, objPtr, Jim_NewDoubleObj(interp, us_per_iter));
19524
+ Jim_ListAppendElement(interp, objPtr, Jim_NewStringObj(interp, "iters_per_sec", -1));
19525
+ Jim_ListAppendElement(interp, objPtr, Jim_NewDoubleObj(interp, 1e6 / us_per_iter));
19526
+ Jim_ListAppendElement(interp, objPtr, Jim_NewStringObj(interp, "count", -1));
19527
+ Jim_ListAppendElement(interp, objPtr, Jim_NewIntObj(interp, count));
19528
+ Jim_ListAppendElement(interp, objPtr, Jim_NewStringObj(interp, "elapsed_us", -1));
19529
+ Jim_ListAppendElement(interp, objPtr, Jim_NewIntObj(interp, delta));
19530
+ Jim_SetResult(interp, objPtr);
1806019531
return JIM_OK;
1806119532
}
1806219533
1806319534
1806419535
static int Jim_ExitCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
@@ -18070,25 +19541,55 @@
1807019541
return JIM_ERR;
1807119542
}
1807219543
if (argc == 2) {
1807319544
if (Jim_GetLong(interp, argv[1], &exitCode) != JIM_OK)
1807419545
return JIM_ERR;
19546
+ Jim_SetResult(interp, argv[1]);
1807519547
}
1807619548
interp->exitCode = exitCode;
1807719549
return JIM_EXIT;
1807819550
}
1807919551
19552
+static int JimMatchReturnCodes(Jim_Interp *interp, Jim_Obj *retcodeListObj, int rc)
19553
+{
19554
+ int len = Jim_ListLength(interp, retcodeListObj);
19555
+ int i;
19556
+ for (i = 0; i < len; i++) {
19557
+ int returncode;
19558
+ if (Jim_GetReturnCode(interp, Jim_ListGetIndex(interp, retcodeListObj, i), &returncode) != JIM_OK) {
19559
+ return JIM_ERR;
19560
+ }
19561
+ if (rc == returncode) {
19562
+ return JIM_OK;
19563
+ }
19564
+ }
19565
+ return -1;
19566
+}
1808019567
18081
-static int Jim_CatchCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
19568
+
19569
+static int JimCatchTryHelper(Jim_Interp *interp, int istry, int argc, Jim_Obj *const *argv)
1808219570
{
19571
+ static const char * const wrongargs_catchtry[2] = {
19572
+ "?-?no?code ... --? script ?resultVarName? ?optionVarName?",
19573
+ "?-?no?code ... --? script ?on|trap codes vars script? ... ?finally script?"
19574
+ };
1808319575
int exitCode = 0;
1808419576
int i;
1808519577
int sig = 0;
19578
+ int ok;
19579
+ Jim_Obj *finallyScriptObj = NULL;
19580
+ Jim_Obj *msgVarObj = NULL;
19581
+ Jim_Obj *optsVarObj = NULL;
19582
+ Jim_Obj *handlerScriptObj = NULL;
19583
+ Jim_Obj *errorCodeObj;
19584
+ int idx;
1808619585
1808719586
1808819587
jim_wide ignore_mask = (1 << JIM_EXIT) | (1 << JIM_EVAL) | (1 << JIM_SIGNAL);
1808919588
static const int max_ignore_code = sizeof(ignore_mask) * 8;
19589
+
19590
+ JimPanic((istry != 0 && istry != 1, "wrong args to JimCatchTryHelper"));
1809019591
1809119592
Jim_SetGlobalVariableStr(interp, "errorCode", Jim_NewStringObj(interp, "NONE", -1));
1809219593
1809319594
for (i = 1; i < argc - 1; i++) {
1809419595
const char *arg = Jim_String(argv[i]);
@@ -18129,18 +19630,17 @@
1812919630
else {
1813019631
ignore_mask &= (~((jim_wide)1 << option));
1813119632
}
1813219633
}
1813319634
18134
- argc -= i;
18135
- if (argc < 1 || argc > 3) {
18136
- wrongargs:
18137
- Jim_WrongNumArgs(interp, 1, argv,
18138
- "?-?no?code ... --? script ?resultVarName? ?optionVarName?");
19635
+ idx = i;
19636
+
19637
+ if (argc - idx < 1) {
19638
+wrongargs:
19639
+ Jim_WrongNumArgs(interp, 1, argv, wrongargs_catchtry[istry]);
1813919640
return JIM_ERR;
1814019641
}
18141
- argv += i;
1814219642
1814319643
if ((ignore_mask & (1 << JIM_SIGNAL)) == 0) {
1814419644
sig++;
1814519645
}
1814619646
@@ -18148,64 +19648,172 @@
1814819648
if (Jim_CheckSignal(interp)) {
1814919649
1815019650
exitCode = JIM_SIGNAL;
1815119651
}
1815219652
else {
18153
- exitCode = Jim_EvalObj(interp, argv[0]);
19653
+ exitCode = Jim_EvalObj(interp, argv[idx]);
1815419654
1815519655
interp->errorFlag = 0;
1815619656
}
1815719657
interp->signal_level -= sig;
1815819658
19659
+ errorCodeObj = Jim_GetGlobalVariableStr(interp, "errorCode", JIM_NONE);
19660
+
19661
+ idx++;
19662
+ if (istry) {
19663
+ while (idx < argc) {
19664
+ int option;
19665
+ int ret;
19666
+ static const char * const try_options[] = { "on", "trap", "finally", NULL };
19667
+ enum { TRY_ON, TRY_TRAP, TRY_FINALLY, };
19668
+
19669
+ if (Jim_GetEnum(interp, argv[idx], try_options, &option, "handler", JIM_ERRMSG) != JIM_OK) {
19670
+ return JIM_ERR;
19671
+ }
19672
+ switch (option) {
19673
+ case TRY_ON:
19674
+ case TRY_TRAP:
19675
+ if (idx + 4 > argc) {
19676
+ goto wrongargs;
19677
+ }
19678
+ if (option == TRY_ON) {
19679
+ ret = JimMatchReturnCodes(interp, argv[idx + 1], exitCode);
19680
+ if (ret > JIM_OK) {
19681
+ goto wrongargs;
19682
+ }
19683
+ }
19684
+ else if (errorCodeObj) {
19685
+ int len = Jim_ListLength(interp, argv[idx + 1]);
19686
+ int i;
19687
+
19688
+ ret = JIM_OK;
19689
+
19690
+ for (i = 0; i < len; i++) {
19691
+ Jim_Obj *matchObj = Jim_ListGetIndex(interp, argv[idx + 1], i);
19692
+ Jim_Obj *objPtr = Jim_ListGetIndex(interp, errorCodeObj, i);
19693
+ if (Jim_StringCompareObj(interp, matchObj, objPtr, 0) != 0) {
19694
+ ret = -1;
19695
+ break;
19696
+ }
19697
+ }
19698
+ }
19699
+ else {
19700
+
19701
+ ret = -1;
19702
+ }
19703
+
19704
+ if (ret == JIM_OK && handlerScriptObj == NULL) {
19705
+ msgVarObj = Jim_ListGetIndex(interp, argv[idx + 2], 0);
19706
+ optsVarObj = Jim_ListGetIndex(interp, argv[idx + 2], 1);
19707
+ handlerScriptObj = argv[idx + 3];
19708
+ }
19709
+ idx += 4;
19710
+ break;
19711
+ case TRY_FINALLY:
19712
+ if (idx + 2 != argc) {
19713
+ goto wrongargs;
19714
+ }
19715
+ finallyScriptObj = argv[idx + 1];
19716
+ idx += 2;
19717
+ break;
19718
+ }
19719
+ }
19720
+ }
19721
+ else {
19722
+ if (argc - idx >= 1) {
19723
+ msgVarObj = argv[idx];
19724
+ idx++;
19725
+ if (argc - idx >= 1) {
19726
+ optsVarObj = argv[idx];
19727
+ idx++;
19728
+ }
19729
+ }
19730
+ }
19731
+
1815919732
1816019733
if (exitCode >= 0 && exitCode < max_ignore_code && (((unsigned jim_wide)1 << exitCode) & ignore_mask)) {
1816119734
19735
+ if (finallyScriptObj) {
19736
+ Jim_EvalObj(interp, finallyScriptObj);
19737
+ }
1816219738
return exitCode;
1816319739
}
1816419740
1816519741
if (sig && exitCode == JIM_SIGNAL) {
1816619742
1816719743
if (interp->signal_set_result) {
1816819744
interp->signal_set_result(interp, interp->sigmask);
1816919745
}
18170
- else {
19746
+ else if (!istry) {
1817119747
Jim_SetResultInt(interp, interp->sigmask);
1817219748
}
1817319749
interp->sigmask = 0;
1817419750
}
1817519751
18176
- if (argc >= 2) {
18177
- if (Jim_SetVariable(interp, argv[1], Jim_GetResult(interp)) != JIM_OK) {
18178
- return JIM_ERR;
18179
- }
18180
- if (argc == 3) {
18181
- Jim_Obj *optListObj = Jim_NewListObj(interp, NULL, 0);
18182
-
18183
- Jim_ListAppendElement(interp, optListObj, Jim_NewStringObj(interp, "-code", -1));
18184
- Jim_ListAppendElement(interp, optListObj,
18185
- Jim_NewIntObj(interp, exitCode == JIM_RETURN ? interp->returnCode : exitCode));
18186
- Jim_ListAppendElement(interp, optListObj, Jim_NewStringObj(interp, "-level", -1));
18187
- Jim_ListAppendElement(interp, optListObj, Jim_NewIntObj(interp, interp->returnLevel));
18188
- if (exitCode == JIM_ERR) {
18189
- Jim_Obj *errorCode;
18190
- Jim_ListAppendElement(interp, optListObj, Jim_NewStringObj(interp, "-errorinfo",
18191
- -1));
18192
- Jim_ListAppendElement(interp, optListObj, interp->stackTrace);
18193
-
18194
- errorCode = Jim_GetGlobalVariableStr(interp, "errorCode", JIM_NONE);
18195
- if (errorCode) {
18196
- Jim_ListAppendElement(interp, optListObj, Jim_NewStringObj(interp, "-errorcode", -1));
18197
- Jim_ListAppendElement(interp, optListObj, errorCode);
18198
- }
18199
- }
18200
- if (Jim_SetVariable(interp, argv[2], optListObj) != JIM_OK) {
18201
- return JIM_ERR;
18202
- }
18203
- }
18204
- }
18205
- Jim_SetResultInt(interp, exitCode);
18206
- return JIM_OK;
19752
+ ok = 1;
19753
+ if (msgVarObj && Jim_Length(msgVarObj)) {
19754
+ if (Jim_SetVariable(interp, msgVarObj, Jim_GetResult(interp)) != JIM_OK) {
19755
+ ok = 0;
19756
+ }
19757
+ }
19758
+ if (ok && optsVarObj && Jim_Length(optsVarObj)) {
19759
+ Jim_Obj *optListObj = Jim_NewListObj(interp, NULL, 0);
19760
+
19761
+ Jim_ListAppendElement(interp, optListObj, Jim_NewStringObj(interp, "-code", -1));
19762
+ Jim_ListAppendElement(interp, optListObj,
19763
+ Jim_NewIntObj(interp, exitCode == JIM_RETURN ? interp->returnCode : exitCode));
19764
+ Jim_ListAppendElement(interp, optListObj, Jim_NewStringObj(interp, "-level", -1));
19765
+ Jim_ListAppendElement(interp, optListObj, Jim_NewIntObj(interp, interp->returnLevel));
19766
+ if (exitCode == JIM_ERR) {
19767
+ Jim_ListAppendElement(interp, optListObj, Jim_NewStringObj(interp, "-errorinfo",
19768
+ -1));
19769
+ Jim_ListAppendElement(interp, optListObj, interp->stackTrace);
19770
+
19771
+ if (errorCodeObj) {
19772
+ Jim_ListAppendElement(interp, optListObj, Jim_NewStringObj(interp, "-errorcode", -1));
19773
+ Jim_ListAppendElement(interp, optListObj, errorCodeObj);
19774
+ }
19775
+ }
19776
+ if (Jim_SetVariable(interp, optsVarObj, optListObj) != JIM_OK) {
19777
+ ok = 0;
19778
+ }
19779
+ }
19780
+ if (ok && handlerScriptObj) {
19781
+
19782
+ exitCode = Jim_EvalObj(interp, handlerScriptObj);
19783
+ }
19784
+
19785
+ if (finallyScriptObj) {
19786
+
19787
+ Jim_Obj *prevResultObj = Jim_GetResult(interp);
19788
+ Jim_IncrRefCount(prevResultObj);
19789
+ int ret = Jim_EvalObj(interp, finallyScriptObj);
19790
+ if (ret == JIM_OK) {
19791
+ Jim_SetResult(interp, prevResultObj);
19792
+ }
19793
+ else {
19794
+ exitCode = ret;
19795
+ }
19796
+ Jim_DecrRefCount(interp, prevResultObj);
19797
+ }
19798
+ if (!istry) {
19799
+ Jim_SetResultInt(interp, exitCode);
19800
+ exitCode = JIM_OK;
19801
+ }
19802
+ return exitCode;
19803
+}
19804
+
19805
+
19806
+static int Jim_CatchCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
19807
+{
19808
+ return JimCatchTryHelper(interp, 0, argc, argv);
19809
+}
19810
+
19811
+
19812
+static int Jim_TryCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
19813
+{
19814
+ return JimCatchTryHelper(interp, 1, argc, argv);
1820719815
}
1820819816
1820919817
1821019818
1821119819
static int Jim_RenameCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
@@ -18213,46 +19821,44 @@
1821319821
if (argc != 3) {
1821419822
Jim_WrongNumArgs(interp, 1, argv, "oldName newName");
1821519823
return JIM_ERR;
1821619824
}
1821719825
18218
- if (JimValidName(interp, "new procedure", argv[2])) {
18219
- return JIM_ERR;
18220
- }
18221
-
18222
- return Jim_RenameCommand(interp, Jim_String(argv[1]), Jim_String(argv[2]));
19826
+ return Jim_RenameCommand(interp, argv[1], argv[2]);
1822319827
}
1822419828
1822519829
#define JIM_DICTMATCH_KEYS 0x0001
1822619830
#define JIM_DICTMATCH_VALUES 0x002
1822719831
1822819832
int Jim_DictMatchTypes(Jim_Interp *interp, Jim_Obj *objPtr, Jim_Obj *patternObj, int match_type, int return_types)
1822919833
{
18230
- Jim_HashEntry *he;
1823119834
Jim_Obj *listObjPtr;
18232
- Jim_HashTableIterator htiter;
19835
+ Jim_Dict *dict;
19836
+ int i;
1823319837
1823419838
if (SetDictFromAny(interp, objPtr) != JIM_OK) {
1823519839
return JIM_ERR;
1823619840
}
19841
+ dict = objPtr->internalRep.dictValue;
1823719842
1823819843
listObjPtr = Jim_NewListObj(interp, NULL, 0);
1823919844
18240
- JimInitHashTableIterator(objPtr->internalRep.ptr, &htiter);
18241
- while ((he = Jim_NextHashEntry(&htiter)) != NULL) {
19845
+ for (i = 0; i < dict->len; i += 2 ) {
19846
+ Jim_Obj *keyObj = dict->table[i];
19847
+ Jim_Obj *valObj = dict->table[i + 1];
1824219848
if (patternObj) {
18243
- Jim_Obj *matchObj = (match_type == JIM_DICTMATCH_KEYS) ? (Jim_Obj *)he->key : Jim_GetHashEntryVal(he);
18244
- if (!JimGlobMatch(Jim_String(patternObj), Jim_String(matchObj), 0)) {
19849
+ Jim_Obj *matchObj = (match_type == JIM_DICTMATCH_KEYS) ? keyObj : valObj;
19850
+ if (!Jim_StringMatchObj(interp, patternObj, matchObj, 0)) {
1824519851
1824619852
continue;
1824719853
}
1824819854
}
1824919855
if (return_types & JIM_DICTMATCH_KEYS) {
18250
- Jim_ListAppendElement(interp, listObjPtr, (Jim_Obj *)he->key);
19856
+ Jim_ListAppendElement(interp, listObjPtr, keyObj);
1825119857
}
1825219858
if (return_types & JIM_DICTMATCH_VALUES) {
18253
- Jim_ListAppendElement(interp, listObjPtr, Jim_GetHashEntryVal(he));
19859
+ Jim_ListAppendElement(interp, listObjPtr, valObj);
1825419860
}
1825519861
}
1825619862
1825719863
Jim_SetResult(interp, listObjPtr);
1825819864
return JIM_OK;
@@ -18261,11 +19867,11 @@
1826119867
int Jim_DictSize(Jim_Interp *interp, Jim_Obj *objPtr)
1826219868
{
1826319869
if (SetDictFromAny(interp, objPtr) != JIM_OK) {
1826419870
return -1;
1826519871
}
18266
- return ((Jim_HashTable *)objPtr->internalRep.ptr)->used;
19872
+ return objPtr->internalRep.dictValue->len / 2;
1826719873
}
1826819874
1826919875
Jim_Obj *Jim_DictMerge(Jim_Interp *interp, int objc, Jim_Obj *const *objv)
1827019876
{
1827119877
Jim_Obj *objPtr = Jim_NewDictObj(interp, NULL, 0);
@@ -18274,73 +19880,41 @@
1827419880
JimPanic((objc == 0, "Jim_DictMerge called with objc=0"));
1827519881
1827619882
1827719883
1827819884
for (i = 0; i < objc; i++) {
18279
- Jim_HashTable *ht;
18280
- Jim_HashTableIterator htiter;
18281
- Jim_HashEntry *he;
19885
+ Jim_Obj **table;
19886
+ int tablelen;
19887
+ int j;
1828219888
18283
- if (SetDictFromAny(interp, objv[i]) != JIM_OK) {
19889
+ table = Jim_DictPairs(interp, objv[i], &tablelen);
19890
+ if (tablelen && !table) {
1828419891
Jim_FreeNewObj(interp, objPtr);
1828519892
return NULL;
1828619893
}
18287
- ht = objv[i]->internalRep.ptr;
18288
- JimInitHashTableIterator(ht, &htiter);
18289
- while ((he = Jim_NextHashEntry(&htiter)) != NULL) {
18290
- Jim_ReplaceHashEntry(objPtr->internalRep.ptr, Jim_GetHashEntryKey(he), Jim_GetHashEntryVal(he));
19894
+ for (j = 0; j < tablelen; j += 2) {
19895
+ DictAddElement(interp, objPtr, table[j], table[j + 1]);
1829119896
}
1829219897
}
1829319898
return objPtr;
1829419899
}
1829519900
1829619901
int Jim_DictInfo(Jim_Interp *interp, Jim_Obj *objPtr)
1829719902
{
18298
- Jim_HashTable *ht;
18299
- unsigned int i;
1830019903
char buffer[100];
18301
- int sum = 0;
18302
- int nonzero_count = 0;
1830319904
Jim_Obj *output;
18304
- int bucket_counts[11] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
19905
+ Jim_Dict *dict;
1830519906
1830619907
if (SetDictFromAny(interp, objPtr) != JIM_OK) {
1830719908
return JIM_ERR;
1830819909
}
1830919910
18310
- ht = (Jim_HashTable *)objPtr->internalRep.ptr;
18311
-
18312
-
18313
- snprintf(buffer, sizeof(buffer), "%d entries in table, %d buckets\n", ht->used, ht->size);
18314
- output = Jim_NewStringObj(interp, buffer, -1);
18315
-
18316
- for (i = 0; i < ht->size; i++) {
18317
- Jim_HashEntry *he = ht->table[i];
18318
- int entries = 0;
18319
- while (he) {
18320
- entries++;
18321
- he = he->next;
18322
- }
18323
- if (entries > 9) {
18324
- bucket_counts[10]++;
18325
- }
18326
- else {
18327
- bucket_counts[entries]++;
18328
- }
18329
- if (entries) {
18330
- sum += entries;
18331
- nonzero_count++;
18332
- }
18333
- }
18334
- for (i = 0; i < 10; i++) {
18335
- snprintf(buffer, sizeof(buffer), "number of buckets with %d entries: %d\n", i, bucket_counts[i]);
18336
- Jim_AppendString(interp, output, buffer, -1);
18337
- }
18338
- snprintf(buffer, sizeof(buffer), "number of buckets with 10 or more entries: %d\n", bucket_counts[10]);
18339
- Jim_AppendString(interp, output, buffer, -1);
18340
- snprintf(buffer, sizeof(buffer), "average search distance for entry: %.1f", nonzero_count ? (double)sum / nonzero_count : 0.0);
18341
- Jim_AppendString(interp, output, buffer, -1);
19911
+ dict = objPtr->internalRep.dictValue;
19912
+
19913
+
19914
+ snprintf(buffer, sizeof(buffer), "%d entries in table, %d buckets", dict->len, dict->size);
19915
+ output = Jim_NewStringObj(interp, buffer, -1);
1834219916
Jim_SetResult(interp, output);
1834319917
return JIM_OK;
1834419918
}
1834519919
1834619920
static int Jim_EvalEnsemble(Jim_Interp *interp, const char *basecmd, const char *subcmd, int argc, Jim_Obj *const *argv)
@@ -18366,16 +19940,16 @@
1836619940
dictObj = Jim_GetVariable(interp, dictVarName, JIM_ERRMSG);
1836719941
if (dictObj == NULL || Jim_DictKeysVector(interp, dictObj, keyv, keyc, &objPtr, JIM_ERRMSG) != JIM_OK) {
1836819942
return JIM_ERR;
1836919943
}
1837019944
18371
- if (Jim_DictPairs(interp, objPtr, &dictValues, &len) == JIM_ERR) {
19945
+ dictValues = Jim_DictPairs(interp, objPtr, &len);
19946
+ if (len && dictValues == NULL) {
1837219947
return JIM_ERR;
1837319948
}
1837419949
for (i = 0; i < len; i += 2) {
1837519950
if (Jim_SetVariable(interp, dictValues[i], dictValues[i + 1]) == JIM_ERR) {
18376
- Jim_Free(dictValues);
1837719951
return JIM_ERR;
1837819952
}
1837919953
}
1838019954
1838119955
@@ -18390,110 +19964,137 @@
1839019964
newkeyv[i] = keyv[i];
1839119965
}
1839219966
1839319967
for (i = 0; i < len; i += 2) {
1839419968
18395
- objPtr = Jim_GetVariable(interp, dictValues[i], 0);
18396
- newkeyv[keyc] = dictValues[i];
18397
- Jim_SetDictKeysVector(interp, dictVarName, newkeyv, keyc + 1, objPtr, 0);
19969
+ if (Jim_StringCompareObj(interp, dictVarName, dictValues[i], 0) != 0) {
19970
+
19971
+ objPtr = Jim_GetVariable(interp, dictValues[i], 0);
19972
+ newkeyv[keyc] = dictValues[i];
19973
+ Jim_SetDictKeysVector(interp, dictVarName, newkeyv, keyc + 1, objPtr, JIM_NORESULT);
19974
+ }
1839819975
}
1839919976
Jim_Free(newkeyv);
1840019977
}
1840119978
}
1840219979
18403
- Jim_Free(dictValues);
18404
-
1840519980
return ret;
1840619981
}
1840719982
1840819983
1840919984
static int Jim_DictCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
1841019985
{
1841119986
Jim_Obj *objPtr;
1841219987
int types = JIM_DICTMATCH_KEYS;
18413
- int option;
18414
- static const char * const options[] = {
18415
- "create", "get", "set", "unset", "exists", "keys", "size", "info",
18416
- "merge", "with", "append", "lappend", "incr", "remove", "values", "for",
18417
- "replace", "update", NULL
18418
- };
18419
- enum
18420
- {
18421
- OPT_CREATE, OPT_GET, OPT_SET, OPT_UNSET, OPT_EXISTS, OPT_KEYS, OPT_SIZE, OPT_INFO,
18422
- OPT_MERGE, OPT_WITH, OPT_APPEND, OPT_LAPPEND, OPT_INCR, OPT_REMOVE, OPT_VALUES, OPT_FOR,
18423
- OPT_REPLACE, OPT_UPDATE,
18424
- };
18425
-
18426
- if (argc < 2) {
18427
- Jim_WrongNumArgs(interp, 1, argv, "subcommand ?arguments ...?");
18428
- return JIM_ERR;
18429
- }
18430
-
18431
- if (Jim_GetEnum(interp, argv[1], options, &option, "subcommand", JIM_ERRMSG) != JIM_OK) {
18432
- return Jim_CheckShowCommands(interp, argv[1], options);
18433
- }
18434
-
18435
- switch (option) {
18436
- case OPT_GET:
18437
- if (argc < 3) {
18438
- Jim_WrongNumArgs(interp, 2, argv, "dictionary ?key ...?");
18439
- return JIM_ERR;
18440
- }
19988
+
19989
+ enum {
19990
+ OPT_CREATE,
19991
+ OPT_GET,
19992
+ OPT_GETDEF,
19993
+ OPT_GETWITHDEFAULT,
19994
+ OPT_SET,
19995
+ OPT_UNSET,
19996
+ OPT_EXISTS,
19997
+ OPT_KEYS,
19998
+ OPT_SIZE,
19999
+ OPT_INFO,
20000
+ OPT_MERGE,
20001
+ OPT_WITH,
20002
+ OPT_APPEND,
20003
+ OPT_LAPPEND,
20004
+ OPT_INCR,
20005
+ OPT_REMOVE,
20006
+ OPT_VALUES,
20007
+ OPT_FOR,
20008
+ OPT_REPLACE,
20009
+ OPT_UPDATE,
20010
+ OPT_COUNT
20011
+ };
20012
+ static const jim_subcmd_type cmds[OPT_COUNT + 1] = {
20013
+ JIM_DEF_SUBCMD("create", "?key value ...?", 0, -2),
20014
+ JIM_DEF_SUBCMD("get", "dictionary ?key ...?", 1, -1),
20015
+ JIM_DEF_SUBCMD_HIDDEN("getdef", "dictionary ?key ...? key default", 3, -1),
20016
+ JIM_DEF_SUBCMD("getwithdefault", "dictionary ?key ...? key default", 3, -1),
20017
+ JIM_DEF_SUBCMD("set", "varName key ?key ...? value", 3, -1),
20018
+ JIM_DEF_SUBCMD("unset", "varName key ?key ...?", 2, -1),
20019
+ JIM_DEF_SUBCMD("exists", "dictionary key ?key ...?", 2, -1),
20020
+ JIM_DEF_SUBCMD("keys", "dictionary ?pattern?", 1, 2),
20021
+ JIM_DEF_SUBCMD("size", "dictionary", 1, 1),
20022
+ JIM_DEF_SUBCMD("info", "dictionary", 1, 1),
20023
+ JIM_DEF_SUBCMD("merge", "?...?", 0, -1),
20024
+ JIM_DEF_SUBCMD("with", "dictVar ?key ...? script", 2, -1),
20025
+ JIM_DEF_SUBCMD("append", "varName key ?value ...?", 2, -1),
20026
+ JIM_DEF_SUBCMD("lappend", "varName key ?value ...?", 2, -1),
20027
+ JIM_DEF_SUBCMD("incr", "varName key ?increment?", 2, 3),
20028
+ JIM_DEF_SUBCMD("remove", "dictionary ?key ...?", 1, -1),
20029
+ JIM_DEF_SUBCMD("values", "dictionary ?pattern?", 1, 2),
20030
+ JIM_DEF_SUBCMD("for", "vars dictionary script", 3, 3),
20031
+ JIM_DEF_SUBCMD("replace", "dictionary ?key value ...?", 1, -1),
20032
+ JIM_DEF_SUBCMD("update", "varName ?arg ...? script", 2, -1),
20033
+ { }
20034
+ };
20035
+ const jim_subcmd_type *ct = Jim_ParseSubCmd(interp, cmds, argc, argv);
20036
+ if (!ct) {
20037
+ return JIM_ERR;
20038
+ }
20039
+ if (ct->function) {
20040
+
20041
+ return ct->function(interp, argc, argv);
20042
+ }
20043
+
20044
+
20045
+ switch (ct - cmds) {
20046
+ case OPT_GET:
1844120047
if (Jim_DictKeysVector(interp, argv[2], argv + 3, argc - 3, &objPtr,
1844220048
JIM_ERRMSG) != JIM_OK) {
1844320049
return JIM_ERR;
1844420050
}
1844520051
Jim_SetResult(interp, objPtr);
1844620052
return JIM_OK;
1844720053
18448
- case OPT_SET:
18449
- if (argc < 5) {
18450
- Jim_WrongNumArgs(interp, 2, argv, "varName key ?key ...? value");
20054
+ case OPT_GETDEF:
20055
+ case OPT_GETWITHDEFAULT:{
20056
+ int rc = Jim_DictKeysVector(interp, argv[2], argv + 3, argc - 4, &objPtr, JIM_ERRMSG);
20057
+ if (rc == -1) {
20058
+
1845120059
return JIM_ERR;
1845220060
}
20061
+ if (rc == JIM_ERR) {
20062
+ Jim_SetResult(interp, argv[argc - 1]);
20063
+ }
20064
+ else {
20065
+ Jim_SetResult(interp, objPtr);
20066
+ }
20067
+ return JIM_OK;
20068
+ }
20069
+
20070
+ case OPT_SET:
1845320071
return Jim_SetDictKeysVector(interp, argv[2], argv + 3, argc - 4, argv[argc - 1], JIM_ERRMSG);
1845420072
18455
- case OPT_EXISTS:
18456
- if (argc < 4) {
18457
- Jim_WrongNumArgs(interp, 2, argv, "dictionary key ?key ...?");
18458
- return JIM_ERR;
18459
- }
18460
- else {
18461
- int rc = Jim_DictKeysVector(interp, argv[2], argv + 3, argc - 3, &objPtr, JIM_ERRMSG);
20073
+ case OPT_EXISTS:{
20074
+ int rc = Jim_DictKeysVector(interp, argv[2], argv + 3, argc - 3, &objPtr, JIM_NONE);
1846220075
if (rc < 0) {
1846320076
return JIM_ERR;
1846420077
}
1846520078
Jim_SetResultBool(interp, rc == JIM_OK);
1846620079
return JIM_OK;
1846720080
}
1846820081
1846920082
case OPT_UNSET:
18470
- if (argc < 4) {
18471
- Jim_WrongNumArgs(interp, 2, argv, "varName key ?key ...?");
18472
- return JIM_ERR;
18473
- }
18474
- if (Jim_SetDictKeysVector(interp, argv[2], argv + 3, argc - 3, NULL, 0) != JIM_OK) {
20083
+ if (Jim_SetDictKeysVector(interp, argv[2], argv + 3, argc - 3, NULL, JIM_NONE) != JIM_OK) {
1847520084
return JIM_ERR;
1847620085
}
1847720086
return JIM_OK;
1847820087
1847920088
case OPT_VALUES:
1848020089
types = JIM_DICTMATCH_VALUES;
1848120090
1848220091
case OPT_KEYS:
18483
- if (argc != 3 && argc != 4) {
18484
- Jim_WrongNumArgs(interp, 2, argv, "dictionary ?pattern?");
18485
- return JIM_ERR;
18486
- }
1848720092
return Jim_DictMatchTypes(interp, argv[2], argc == 4 ? argv[3] : NULL, types, types);
1848820093
1848920094
case OPT_SIZE:
18490
- if (argc != 3) {
18491
- Jim_WrongNumArgs(interp, 2, argv, "dictionary");
18492
- return JIM_ERR;
18493
- }
18494
- else if (Jim_DictSize(interp, argv[2]) < 0) {
20095
+ if (Jim_DictSize(interp, argv[2]) < 0) {
1849520096
return JIM_ERR;
1849620097
}
1849720098
Jim_SetResultInt(interp, Jim_DictSize(interp, argv[2]));
1849820099
return JIM_OK;
1849920100
@@ -18506,42 +20107,30 @@
1850620107
return JIM_ERR;
1850720108
}
1850820109
Jim_SetResult(interp, objPtr);
1850920110
return JIM_OK;
1851020111
18511
- case OPT_UPDATE:
18512
- if (argc < 6 || argc % 2) {
18513
-
18514
- argc = 2;
18515
- }
18516
- break;
18517
-
1851820112
case OPT_CREATE:
18519
- if (argc % 2) {
18520
- Jim_WrongNumArgs(interp, 2, argv, "?key value ...?");
18521
- return JIM_ERR;
18522
- }
1852320113
objPtr = Jim_NewDictObj(interp, argv + 2, argc - 2);
1852420114
Jim_SetResult(interp, objPtr);
1852520115
return JIM_OK;
1852620116
1852720117
case OPT_INFO:
18528
- if (argc != 3) {
18529
- Jim_WrongNumArgs(interp, 2, argv, "dictionary");
18530
- return JIM_ERR;
18531
- }
1853220118
return Jim_DictInfo(interp, argv[2]);
1853320119
1853420120
case OPT_WITH:
18535
- if (argc < 4) {
18536
- Jim_WrongNumArgs(interp, 2, argv, "dictVar ?key ...? script");
18537
- return JIM_ERR;
18538
- }
1853920121
return JimDictWith(interp, argv[2], argv + 3, argc - 4, argv[argc - 1]);
20122
+
20123
+ case OPT_UPDATE:
20124
+ if (argc < 6 || argc % 2) {
20125
+
20126
+ argc = 2;
20127
+ }
20128
+
20129
+ default:
20130
+ return Jim_EvalEnsemble(interp, "dict", Jim_String(argv[1]), argc - 2, argv + 2);
1854020131
}
18541
-
18542
- return Jim_EvalEnsemble(interp, "dict", options[option], argc - 2, argv + 2);
1854320132
}
1854420133
1854520134
1854620135
static int Jim_SubstCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
1854720136
{
@@ -18582,30 +20171,79 @@
1858220171
}
1858320172
Jim_SetResult(interp, objPtr);
1858420173
return JIM_OK;
1858520174
}
1858620175
20176
+#ifdef jim_ext_namespace
20177
+static int JimIsGlobalNamespace(Jim_Obj *objPtr)
20178
+{
20179
+ int len;
20180
+ const char *str = Jim_GetString(objPtr, &len);
20181
+ return len >= 2 && str[0] == ':' && str[1] == ':';
20182
+}
20183
+#endif
20184
+
1858720185
1858820186
static int Jim_InfoCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
1858920187
{
18590
- int cmd;
1859120188
Jim_Obj *objPtr;
1859220189
int mode = 0;
1859320190
18594
- static const char * const commands[] = {
18595
- "body", "statics", "commands", "procs", "channels", "exists", "globals", "level", "frame", "locals",
18596
- "vars", "version", "patchlevel", "complete", "args", "hostname",
18597
- "script", "source", "stacktrace", "nameofexecutable", "returncodes",
18598
- "references", "alias", NULL
18599
- };
18600
- enum
18601
- { INFO_BODY, INFO_STATICS, INFO_COMMANDS, INFO_PROCS, INFO_CHANNELS, INFO_EXISTS, INFO_GLOBALS, INFO_LEVEL,
18602
- INFO_FRAME, INFO_LOCALS, INFO_VARS, INFO_VERSION, INFO_PATCHLEVEL, INFO_COMPLETE, INFO_ARGS,
18603
- INFO_HOSTNAME, INFO_SCRIPT, INFO_SOURCE, INFO_STACKTRACE, INFO_NAMEOFEXECUTABLE,
18604
- INFO_RETURNCODES, INFO_REFERENCES, INFO_ALIAS,
18605
- };
18606
-
20191
+
20192
+ enum {
20193
+ INFO_ALIAS,
20194
+ INFO_ARGS,
20195
+ INFO_BODY,
20196
+ INFO_CHANNELS,
20197
+ INFO_COMMANDS,
20198
+ INFO_COMPLETE,
20199
+ INFO_EXISTS,
20200
+ INFO_FRAME,
20201
+ INFO_GLOBALS,
20202
+ INFO_HOSTNAME,
20203
+ INFO_LEVEL,
20204
+ INFO_LOCALS,
20205
+ INFO_NAMEOFEXECUTABLE,
20206
+ INFO_PATCHLEVEL,
20207
+ INFO_PROCS,
20208
+ INFO_REFERENCES,
20209
+ INFO_RETURNCODES,
20210
+ INFO_SCRIPT,
20211
+ INFO_SOURCE,
20212
+ INFO_STACKTRACE,
20213
+ INFO_STATICS,
20214
+ INFO_VARS,
20215
+ INFO_VERSION,
20216
+ INFO_COUNT
20217
+ };
20218
+ static const jim_subcmd_type cmds[INFO_COUNT + 1] = {
20219
+ JIM_DEF_SUBCMD("alias", "command", 1, 1),
20220
+ JIM_DEF_SUBCMD("args", "procname", 1, 1),
20221
+ JIM_DEF_SUBCMD("body", "procname", 1, 1),
20222
+ JIM_DEF_SUBCMD("channels", "?pattern?", 0, 1),
20223
+ JIM_DEF_SUBCMD("commands", "?pattern?", 0, 1),
20224
+ JIM_DEF_SUBCMD("complete", "script ?missing?", 1, 2),
20225
+ JIM_DEF_SUBCMD("exists", "varName", 1, 1),
20226
+ JIM_DEF_SUBCMD("frame", "?levelNum?", 0, 1),
20227
+ JIM_DEF_SUBCMD("globals", "?pattern?", 0, 1),
20228
+ JIM_DEF_SUBCMD("hostname", NULL, 0, 0),
20229
+ JIM_DEF_SUBCMD("level", "?levelNum?", 0, 1),
20230
+ JIM_DEF_SUBCMD("locals", "?pattern?", 0, 1),
20231
+ JIM_DEF_SUBCMD("nameofexecutable", NULL, 0, 0),
20232
+ JIM_DEF_SUBCMD("patchlevel", NULL, 0, 0),
20233
+ JIM_DEF_SUBCMD("procs", "?pattern?", 0, 1),
20234
+ JIM_DEF_SUBCMD("references", NULL, 0, 0),
20235
+ JIM_DEF_SUBCMD("returncodes", "?code?", 0, 1),
20236
+ JIM_DEF_SUBCMD("script", "?filename?", 0, 1),
20237
+ JIM_DEF_SUBCMD("source", "source ?filename line?", 1, 3),
20238
+ JIM_DEF_SUBCMD("stacktrace", NULL, 0, 0),
20239
+ JIM_DEF_SUBCMD("statics", "procname", 1, 1),
20240
+ JIM_DEF_SUBCMD("vars", "?pattern?", 0, 1),
20241
+ JIM_DEF_SUBCMD("version", NULL, 0, 0),
20242
+ { }
20243
+ };
20244
+ const jim_subcmd_type *ct;
1860720245
#ifdef jim_ext_namespace
1860820246
int nons = 0;
1860920247
1861020248
if (argc > 2 && Jim_CompareStringImmediate(interp, argv[1], "-nons")) {
1861120249
@@ -18612,36 +20250,29 @@
1861220250
argc--;
1861320251
argv++;
1861420252
nons = 1;
1861520253
}
1861620254
#endif
18617
-
18618
- if (argc < 2) {
18619
- Jim_WrongNumArgs(interp, 1, argv, "subcommand ?args ...?");
20255
+ ct = Jim_ParseSubCmd(interp, cmds, argc, argv);
20256
+ if (!ct) {
1862020257
return JIM_ERR;
1862120258
}
18622
- if (Jim_GetEnum(interp, argv[1], commands, &cmd, "subcommand", JIM_ERRMSG | JIM_ENUM_ABBREV) != JIM_OK) {
18623
- return Jim_CheckShowCommands(interp, argv[1], commands);
20259
+ if (ct->function) {
20260
+
20261
+ return ct->function(interp, argc, argv);
1862420262
}
1862520263
20264
+ int option = ct - cmds;
1862620265
18627
- switch (cmd) {
20266
+ switch (option) {
1862820267
case INFO_EXISTS:
18629
- if (argc != 3) {
18630
- Jim_WrongNumArgs(interp, 2, argv, "varName");
18631
- return JIM_ERR;
18632
- }
1863320268
Jim_SetResultBool(interp, Jim_GetVariable(interp, argv[2], 0) != NULL);
18634
- break;
20269
+ return JIM_OK;
1863520270
1863620271
case INFO_ALIAS:{
1863720272
Jim_Cmd *cmdPtr;
1863820273
18639
- if (argc != 3) {
18640
- Jim_WrongNumArgs(interp, 2, argv, "command");
18641
- return JIM_ERR;
18642
- }
1864320274
if ((cmdPtr = Jim_GetCommand(interp, argv[2], JIM_ERRMSG)) == NULL) {
1864420275
return JIM_ERR;
1864520276
}
1864620277
if (cmdPtr->isproc || cmdPtr->u.native.cmdProc != JimAliasCmd) {
1864720278
Jim_SetResultFormatted(interp, "command \"%#s\" is not an alias", argv[2]);
@@ -18661,61 +20292,54 @@
1866120292
case INFO_PROCS:
1866220293
mode++;
1866320294
1866420295
case INFO_COMMANDS:
1866520296
18666
- if (argc != 2 && argc != 3) {
18667
- Jim_WrongNumArgs(interp, 2, argv, "?pattern?");
18668
- return JIM_ERR;
18669
- }
1867020297
#ifdef jim_ext_namespace
1867120298
if (!nons) {
18672
- if (Jim_Length(interp->framePtr->nsObj) || (argc == 3 && JimGlobMatch("::*", Jim_String(argv[2]), 0))) {
20299
+ if (Jim_Length(interp->framePtr->nsObj) || (argc == 3 && JimIsGlobalNamespace(argv[2]))) {
1867320300
return Jim_EvalPrefix(interp, "namespace info", argc - 1, argv + 1);
1867420301
}
1867520302
}
1867620303
#endif
1867720304
Jim_SetResult(interp, JimCommandsList(interp, (argc == 3) ? argv[2] : NULL, mode));
18678
- break;
20305
+ return JIM_OK;
1867920306
1868020307
case INFO_VARS:
1868120308
mode++;
1868220309
1868320310
case INFO_LOCALS:
1868420311
mode++;
1868520312
1868620313
case INFO_GLOBALS:
1868720314
18688
- if (argc != 2 && argc != 3) {
18689
- Jim_WrongNumArgs(interp, 2, argv, "?pattern?");
18690
- return JIM_ERR;
18691
- }
1869220315
#ifdef jim_ext_namespace
1869320316
if (!nons) {
18694
- if (Jim_Length(interp->framePtr->nsObj) || (argc == 3 && JimGlobMatch("::*", Jim_String(argv[2]), 0))) {
20317
+ if (Jim_Length(interp->framePtr->nsObj) || (argc == 3 && JimIsGlobalNamespace(argv[2]))) {
1869520318
return Jim_EvalPrefix(interp, "namespace info", argc - 1, argv + 1);
1869620319
}
1869720320
}
1869820321
#endif
1869920322
Jim_SetResult(interp, JimVariablesList(interp, argc == 3 ? argv[2] : NULL, mode));
18700
- break;
20323
+ return JIM_OK;
1870120324
1870220325
case INFO_SCRIPT:
18703
- if (argc != 2) {
18704
- Jim_WrongNumArgs(interp, 2, argv, "");
18705
- return JIM_ERR;
20326
+ if (argc == 3) {
20327
+ Jim_IncrRefCount(argv[2]);
20328
+ Jim_DecrRefCount(interp, interp->currentFilenameObj);
20329
+ interp->currentFilenameObj = argv[2];
1870620330
}
18707
- Jim_SetResult(interp, JimGetScript(interp, interp->currentScriptObj)->fileNameObj);
18708
- break;
20331
+ Jim_SetResult(interp, interp->currentFilenameObj);
20332
+ return JIM_OK;
1870920333
1871020334
case INFO_SOURCE:{
1871120335
jim_wide line;
1871220336
Jim_Obj *resObjPtr;
1871320337
Jim_Obj *fileNameObj;
1871420338
18715
- if (argc != 3 && argc != 5) {
18716
- Jim_WrongNumArgs(interp, 2, argv, "source ?filename line?");
20339
+ if (argc == 4) {
20340
+ Jim_SubCmdArgError(interp, ct, argv[0]);
1871720341
return JIM_ERR;
1871820342
}
1871920343
if (argc == 5) {
1872020344
if (Jim_GetWide(interp, argv[4], &line) != JIM_OK) {
1872120345
return JIM_ERR;
@@ -18740,93 +20364,94 @@
1874020364
resObjPtr = Jim_NewListObj(interp, NULL, 0);
1874120365
Jim_ListAppendElement(interp, resObjPtr, fileNameObj);
1874220366
Jim_ListAppendElement(interp, resObjPtr, Jim_NewIntObj(interp, line));
1874320367
}
1874420368
Jim_SetResult(interp, resObjPtr);
18745
- break;
20369
+ return JIM_OK;
1874620370
}
1874720371
1874820372
case INFO_STACKTRACE:
1874920373
Jim_SetResult(interp, interp->stackTrace);
18750
- break;
20374
+ return JIM_OK;
1875120375
1875220376
case INFO_LEVEL:
18753
- case INFO_FRAME:
18754
- switch (argc) {
18755
- case 2:
18756
- Jim_SetResultInt(interp, interp->framePtr->level);
18757
- break;
18758
-
18759
- case 3:
18760
- if (JimInfoLevel(interp, argv[2], &objPtr, cmd == INFO_LEVEL) != JIM_OK) {
18761
- return JIM_ERR;
18762
- }
18763
- Jim_SetResult(interp, objPtr);
18764
- break;
18765
-
18766
- default:
18767
- Jim_WrongNumArgs(interp, 2, argv, "?levelNum?");
18768
- return JIM_ERR;
18769
- }
18770
- break;
20377
+ if (argc == 2) {
20378
+ Jim_SetResultInt(interp, interp->framePtr->level);
20379
+ }
20380
+ else {
20381
+ if (JimInfoLevel(interp, argv[2], &objPtr) != JIM_OK) {
20382
+ return JIM_ERR;
20383
+ }
20384
+ Jim_SetResult(interp, objPtr);
20385
+ }
20386
+ return JIM_OK;
20387
+
20388
+ case INFO_FRAME:
20389
+ if (argc == 2) {
20390
+ Jim_SetResultInt(interp, interp->procLevel + 1);
20391
+ }
20392
+ else {
20393
+ if (JimInfoFrame(interp, argv[2], &objPtr) != JIM_OK) {
20394
+ return JIM_ERR;
20395
+ }
20396
+ Jim_SetResult(interp, objPtr);
20397
+ }
20398
+ return JIM_OK;
1877120399
1877220400
case INFO_BODY:
1877320401
case INFO_STATICS:
1877420402
case INFO_ARGS:{
1877520403
Jim_Cmd *cmdPtr;
1877620404
18777
- if (argc != 3) {
18778
- Jim_WrongNumArgs(interp, 2, argv, "procname");
18779
- return JIM_ERR;
18780
- }
1878120405
if ((cmdPtr = Jim_GetCommand(interp, argv[2], JIM_ERRMSG)) == NULL) {
1878220406
return JIM_ERR;
1878320407
}
1878420408
if (!cmdPtr->isproc) {
1878520409
Jim_SetResultFormatted(interp, "command \"%#s\" is not a procedure", argv[2]);
1878620410
return JIM_ERR;
1878720411
}
18788
- switch (cmd) {
20412
+ switch (option) {
20413
+#ifdef JIM_NO_INTROSPECTION
20414
+ default:
20415
+ Jim_SetResultString(interp, "unsupported", -1);
20416
+ return JIM_ERR;
20417
+#else
1878920418
case INFO_BODY:
1879020419
Jim_SetResult(interp, cmdPtr->u.proc.bodyObjPtr);
1879120420
break;
1879220421
case INFO_ARGS:
1879320422
Jim_SetResult(interp, cmdPtr->u.proc.argListObjPtr);
1879420423
break;
20424
+#endif
1879520425
case INFO_STATICS:
1879620426
if (cmdPtr->u.proc.staticVars) {
1879720427
Jim_SetResult(interp, JimHashtablePatternMatch(interp, cmdPtr->u.proc.staticVars,
1879820428
NULL, JimVariablesMatch, JIM_VARLIST_LOCALS | JIM_VARLIST_VALUES));
1879920429
}
1880020430
break;
1880120431
}
18802
- break;
20432
+ return JIM_OK;
1880320433
}
1880420434
1880520435
case INFO_VERSION:
1880620436
case INFO_PATCHLEVEL:{
1880720437
char buf[(JIM_INTEGER_SPACE * 2) + 1];
1880820438
1880920439
sprintf(buf, "%d.%d", JIM_VERSION / 100, JIM_VERSION % 100);
1881020440
Jim_SetResultString(interp, buf, -1);
18811
- break;
20441
+ return JIM_OK;
1881220442
}
1881320443
18814
- case INFO_COMPLETE:
18815
- if (argc != 3 && argc != 4) {
18816
- Jim_WrongNumArgs(interp, 2, argv, "script ?missing?");
18817
- return JIM_ERR;
18818
- }
18819
- else {
20444
+ case INFO_COMPLETE: {
1882020445
char missing;
1882120446
1882220447
Jim_SetResultBool(interp, Jim_ScriptIsComplete(interp, argv[2], &missing));
1882320448
if (missing != ' ' && argc == 4) {
1882420449
Jim_SetVariable(interp, argv[3], Jim_NewStringObj(interp, &missing, 1));
1882520450
}
20451
+ return JIM_OK;
1882620452
}
18827
- break;
1882820453
1882920454
case INFO_HOSTNAME:
1883020455
1883120456
return Jim_Eval(interp, "os.gethostname");
1883220457
@@ -18860,24 +20485,21 @@
1886020485
}
1886120486
else {
1886220487
Jim_SetResultString(interp, name, -1);
1886320488
}
1886420489
}
18865
- else {
18866
- Jim_WrongNumArgs(interp, 2, argv, "?code?");
18867
- return JIM_ERR;
18868
- }
18869
- break;
20490
+ return JIM_OK;
1887020491
case INFO_REFERENCES:
1887120492
#ifdef JIM_REFERENCES
1887220493
return JimInfoReferences(interp, argc, argv);
1887320494
#else
1887420495
Jim_SetResultString(interp, "not supported", -1);
1887520496
return JIM_ERR;
1887620497
#endif
20498
+ default:
20499
+ abort();
1887720500
}
18878
- return JIM_OK;
1887920501
}
1888020502
1888120503
1888220504
static int Jim_ExistsCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
1888320505
{
@@ -19145,11 +20767,10 @@
1914520767
Jim_SetResult(interp, argv[1]);
1914620768
if (argc == 3) {
1914720769
JimSetStackTrace(interp, argv[2]);
1914820770
return JIM_ERR;
1914920771
}
19150
- interp->addStackTrace++;
1915120772
return JIM_ERR;
1915220773
}
1915320774
1915420775
1915520776
static int Jim_LrangeCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
@@ -19168,26 +20789,27 @@
1916820789
1916920790
1917020791
static int Jim_LrepeatCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
1917120792
{
1917220793
Jim_Obj *objPtr;
19173
- long count;
20794
+ jim_wide count;
1917420795
19175
- if (argc < 2 || Jim_GetLong(interp, argv[1], &count) != JIM_OK || count < 0) {
20796
+ if (argc < 2 || Jim_GetWideExpr(interp, argv[1], &count) != JIM_OK || count < 0) {
1917620797
Jim_WrongNumArgs(interp, 1, argv, "count ?value ...?");
1917720798
return JIM_ERR;
1917820799
}
19179
-
1918020800
if (count == 0 || argc == 2) {
20801
+ Jim_SetEmptyResult(interp);
1918120802
return JIM_OK;
1918220803
}
1918320804
1918420805
argc -= 2;
1918520806
argv += 2;
1918620807
19187
- objPtr = Jim_NewListObj(interp, argv, argc);
19188
- while (--count) {
20808
+ objPtr = Jim_NewListObj(interp, NULL, 0);
20809
+ ListEnsureLength(objPtr, argc * count);
20810
+ while (count--) {
1918920811
ListInsertElements(objPtr, -1, argc, argv);
1919020812
}
1919120813
1919220814
Jim_SetResult(interp, objPtr);
1919320815
return JIM_OK;
@@ -19243,11 +20865,11 @@
1924320865
1924420866
Jim_SetResult(interp, listObjPtr);
1924520867
return JIM_OK;
1924620868
}
1924720869
19248
- if (argc < 2) {
20870
+ if (argc > 3) {
1924920871
Jim_WrongNumArgs(interp, 1, argv, "varName ?default?");
1925020872
return JIM_ERR;
1925120873
}
1925220874
key = Jim_String(argv[1]);
1925320875
val = getenv(key);
@@ -19286,12 +20908,13 @@
1928620908
if (argc != 2) {
1928720909
Jim_WrongNumArgs(interp, 1, argv, "list");
1928820910
return JIM_ERR;
1928920911
}
1929020912
JimListGetElements(interp, argv[1], &len, &ele);
19291
- len--;
1929220913
revObjPtr = Jim_NewListObj(interp, NULL, 0);
20914
+ ListEnsureLength(revObjPtr, len);
20915
+ len--;
1929320916
while (len >= 0)
1929420917
ListAppendElement(revObjPtr, ele[len--]);
1929520918
Jim_SetResult(interp, revObjPtr);
1929620919
return JIM_OK;
1929720920
}
@@ -19329,25 +20952,26 @@
1932920952
if (argc < 2 || argc > 4) {
1933020953
Jim_WrongNumArgs(interp, 1, argv, "?start? end ?step?");
1933120954
return JIM_ERR;
1933220955
}
1933320956
if (argc == 2) {
19334
- if (Jim_GetWide(interp, argv[1], &end) != JIM_OK)
19335
- return JIM_ERR;
19336
- }
19337
- else {
19338
- if (Jim_GetWide(interp, argv[1], &start) != JIM_OK ||
19339
- Jim_GetWide(interp, argv[2], &end) != JIM_OK)
19340
- return JIM_ERR;
19341
- if (argc == 4 && Jim_GetWide(interp, argv[3], &step) != JIM_OK)
20957
+ if (Jim_GetWideExpr(interp, argv[1], &end) != JIM_OK)
20958
+ return JIM_ERR;
20959
+ }
20960
+ else {
20961
+ if (Jim_GetWideExpr(interp, argv[1], &start) != JIM_OK ||
20962
+ Jim_GetWideExpr(interp, argv[2], &end) != JIM_OK)
20963
+ return JIM_ERR;
20964
+ if (argc == 4 && Jim_GetWideExpr(interp, argv[3], &step) != JIM_OK)
1934220965
return JIM_ERR;
1934320966
}
1934420967
if ((len = JimRangeLen(start, end, step)) == -1) {
1934520968
Jim_SetResultString(interp, "Invalid (infinite?) range specified", -1);
1934620969
return JIM_ERR;
1934720970
}
1934820971
objPtr = Jim_NewListObj(interp, NULL, 0);
20972
+ ListEnsureLength(objPtr, len);
1934920973
for (i = 0; i < len; i++)
1935020974
ListAppendElement(objPtr, Jim_NewIntObj(interp, start + i * step));
1935120975
Jim_SetResult(interp, objPtr);
1935220976
return JIM_OK;
1935320977
}
@@ -19362,15 +20986,15 @@
1936220986
return JIM_ERR;
1936320987
}
1936420988
if (argc == 1) {
1936520989
max = JIM_WIDE_MAX;
1936620990
} else if (argc == 2) {
19367
- if (Jim_GetWide(interp, argv[1], &max) != JIM_OK)
20991
+ if (Jim_GetWideExpr(interp, argv[1], &max) != JIM_OK)
1936820992
return JIM_ERR;
1936920993
} else if (argc == 3) {
19370
- if (Jim_GetWide(interp, argv[1], &min) != JIM_OK ||
19371
- Jim_GetWide(interp, argv[2], &max) != JIM_OK)
20994
+ if (Jim_GetWideExpr(interp, argv[1], &min) != JIM_OK ||
20995
+ Jim_GetWideExpr(interp, argv[2], &max) != JIM_OK)
1937220996
return JIM_ERR;
1937320997
}
1937420998
len = max-min;
1937520999
if (len < 0) {
1937621000
Jim_SetResultString(interp, "Invalid arguments (max < min)", -1);
@@ -19417,25 +21041,27 @@
1941721041
{"lappend", Jim_LappendCoreCommand},
1941821042
{"linsert", Jim_LinsertCoreCommand},
1941921043
{"lreplace", Jim_LreplaceCoreCommand},
1942021044
{"lsort", Jim_LsortCoreCommand},
1942121045
{"append", Jim_AppendCoreCommand},
19422
- {"debug", Jim_DebugCoreCommand},
1942321046
{"eval", Jim_EvalCoreCommand},
1942421047
{"uplevel", Jim_UplevelCoreCommand},
1942521048
{"expr", Jim_ExprCoreCommand},
1942621049
{"break", Jim_BreakCoreCommand},
1942721050
{"continue", Jim_ContinueCoreCommand},
1942821051
{"proc", Jim_ProcCoreCommand},
21052
+ {"xtrace", Jim_XtraceCoreCommand},
1942921053
{"concat", Jim_ConcatCoreCommand},
1943021054
{"return", Jim_ReturnCoreCommand},
1943121055
{"upvar", Jim_UpvarCoreCommand},
1943221056
{"global", Jim_GlobalCoreCommand},
1943321057
{"string", Jim_StringCoreCommand},
1943421058
{"time", Jim_TimeCoreCommand},
21059
+ {"timerate", Jim_TimeRateCoreCommand},
1943521060
{"exit", Jim_ExitCoreCommand},
1943621061
{"catch", Jim_CatchCoreCommand},
21062
+ {"try", Jim_TryCoreCommand},
1943721063
#ifdef JIM_REFERENCES
1943821064
{"ref", Jim_RefCoreCommand},
1943921065
{"getref", Jim_GetrefCoreCommand},
1944021066
{"setref", Jim_SetrefCoreCommand},
1944121067
{"finalize", Jim_FinalizeCoreCommand},
@@ -19460,10 +21086,11 @@
1946021086
{"rand", Jim_RandCoreCommand},
1946121087
{"tailcall", Jim_TailcallCoreCommand},
1946221088
{"local", Jim_LocalCoreCommand},
1946321089
{"upcall", Jim_UpcallCoreCommand},
1946421090
{"apply", Jim_ApplyCoreCommand},
21091
+ {"stacktrace", Jim_StacktraceCoreCommand},
1946521092
{NULL, NULL},
1946621093
};
1946721094
1946821095
void Jim_RegisterCoreCommands(Jim_Interp *interp)
1946921096
{
@@ -19687,22 +21314,30 @@
1968721314
for (i = 0; i < nobjparam; i++) {
1968821315
Jim_DecrRefCount(interp, objparam[i]);
1968921316
}
1969021317
}
1969121318
21319
+int Jim_CheckAbiVersion(Jim_Interp *interp, int abi_version)
21320
+{
21321
+ if (abi_version != JIM_ABI_VERSION) {
21322
+ Jim_SetResultString(interp, "ABI version mismatch", -1);
21323
+ return JIM_ERR;
21324
+ }
21325
+ return JIM_OK;
21326
+}
21327
+
1969221328
1969321329
#ifndef jim_ext_package
1969421330
int Jim_PackageProvide(Jim_Interp *interp, const char *name, const char *ver, int flags)
1969521331
{
1969621332
return JIM_OK;
1969721333
}
1969821334
#endif
1969921335
#ifndef jim_ext_aio
19700
-FILE *Jim_AioFilehandle(Jim_Interp *interp, Jim_Obj *fhObj)
21336
+int Jim_AioFilehandle(Jim_Interp *interp, Jim_Obj *fhObj)
1970121337
{
19702
- Jim_SetResultString(interp, "aio not enabled", -1);
19703
- return NULL;
21338
+ return -1;
1970421339
}
1970521340
#endif
1970621341
1970721342
1970821343
#include <stdio.h>
@@ -19717,34 +21352,45 @@
1971721352
1971821353
static const jim_subcmd_type dummy_subcmd = {
1971921354
"dummy", NULL, subcmd_null, 0, 0, JIM_MODFLAG_HIDDEN
1972021355
};
1972121356
19722
-static void add_commands(Jim_Interp *interp, const jim_subcmd_type * ct, const char *sep)
21357
+static Jim_Obj *subcmd_cmd_list(Jim_Interp *interp, const jim_subcmd_type * ct, const char *sep)
1972321358
{
19724
- const char *s = "";
21359
+
21360
+ Jim_Obj *listObj = Jim_NewListObj(interp, NULL, 0);
21361
+ Jim_Obj *sortCmd[2];
1972521362
1972621363
for (; ct->cmd; ct++) {
1972721364
if (!(ct->flags & JIM_MODFLAG_HIDDEN)) {
19728
- Jim_AppendStrings(interp, Jim_GetResult(interp), s, ct->cmd, NULL);
19729
- s = sep;
21365
+ Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, ct->cmd, -1));
1973021366
}
1973121367
}
21368
+
21369
+
21370
+ sortCmd[0] = Jim_NewStringObj(interp, "lsort", -1);
21371
+ sortCmd[1] = listObj;
21372
+
21373
+ if (Jim_EvalObjVector(interp, 2, sortCmd) == JIM_OK) {
21374
+ return Jim_ListJoin(interp, Jim_GetResult(interp), sep, strlen(sep));
21375
+ }
21376
+
21377
+ return Jim_GetResult(interp);
1973221378
}
1973321379
1973421380
static void bad_subcmd(Jim_Interp *interp, const jim_subcmd_type * command_table, const char *type,
1973521381
Jim_Obj *cmd, Jim_Obj *subcmd)
1973621382
{
19737
- Jim_SetResultFormatted(interp, "%#s, %s command \"%#s\": should be ", cmd, type, subcmd);
19738
- add_commands(interp, command_table, ", ");
21383
+ Jim_SetResultFormatted(interp, "%#s, %s command \"%#s\": should be %#s", cmd, type,
21384
+ subcmd, subcmd_cmd_list(interp, command_table, ", "));
1973921385
}
1974021386
1974121387
static void show_cmd_usage(Jim_Interp *interp, const jim_subcmd_type * command_table, int argc,
1974221388
Jim_Obj *const *argv)
1974321389
{
19744
- Jim_SetResultFormatted(interp, "Usage: \"%#s command ... \", where command is one of: ", argv[0]);
19745
- add_commands(interp, command_table, ", ");
21390
+ Jim_SetResultFormatted(interp, "Usage: \"%#s command ... \", where command is one of: %#s",
21391
+ argv[0], subcmd_cmd_list(interp, command_table, ", "));
1974621392
}
1974721393
1974821394
static void add_cmd_usage(Jim_Interp *interp, const jim_subcmd_type * ct, Jim_Obj *cmd)
1974921395
{
1975021396
if (cmd) {
@@ -19754,14 +21400,14 @@
1975421400
if (ct->args && *ct->args) {
1975521401
Jim_AppendStrings(interp, Jim_GetResult(interp), " ", ct->args, NULL);
1975621402
}
1975721403
}
1975821404
19759
-static void set_wrong_args(Jim_Interp *interp, const jim_subcmd_type * command_table, Jim_Obj *subcmd)
21405
+void Jim_SubCmdArgError(Jim_Interp *interp, const jim_subcmd_type * ct, Jim_Obj *subcmd)
1976021406
{
1976121407
Jim_SetResultString(interp, "wrong # args: should be \"", -1);
19762
- add_cmd_usage(interp, command_table, subcmd);
21408
+ add_cmd_usage(interp, ct, subcmd);
1976321409
Jim_AppendStrings(interp, Jim_GetResult(interp), "\"", NULL);
1976421410
}
1976521411
1976621412
static const Jim_ObjType subcmdLookupObjType = {
1976721413
"subcmd-lookup",
@@ -19778,10 +21424,11 @@
1977821424
const jim_subcmd_type *partial = 0;
1977921425
int cmdlen;
1978021426
Jim_Obj *cmd;
1978121427
const char *cmdstr;
1978221428
int help = 0;
21429
+ int argsok = 1;
1978321430
1978421431
if (argc < 2) {
1978521432
Jim_SetResultFormatted(interp, "wrong # args: should be \"%#s command ...\"\n"
1978621433
"Use \"%#s -help ?command?\" for help", argv[0], argv[0]);
1978721434
return 0;
@@ -19810,13 +21457,11 @@
1981021457
cmd = argv[2];
1981121458
}
1981221459
1981321460
1981421461
if (Jim_CompareStringImmediate(interp, cmd, "-commands")) {
19815
-
19816
- Jim_SetResult(interp, Jim_NewEmptyStringObj(interp));
19817
- add_commands(interp, command_table, " ");
21462
+ Jim_SetResult(interp, subcmd_cmd_list(interp, command_table, " "));
1981821463
return &dummy_subcmd;
1981921464
}
1982021465
1982121466
cmdstr = Jim_GetString(cmd, &cmdlen);
1982221467
@@ -19870,11 +21515,22 @@
1987021515
cmd->internalRep.ptrIntValue.ptr = (void *)command_table;
1987121516
cmd->internalRep.ptrIntValue.int1 = ct - command_table;
1987221517
1987321518
found:
1987421519
19875
- if (argc - 2 < ct->minargs || (ct->maxargs >= 0 && argc - 2 > ct->maxargs)) {
21520
+
21521
+ if (argc - 2 < ct->minargs) {
21522
+ argsok = 0;
21523
+ }
21524
+ else if (ct->maxargs >= 0 && argc - 2 > ct->maxargs) {
21525
+ argsok = 0;
21526
+ }
21527
+ else if (ct->maxargs < -1 && (argc - 2) % -ct->maxargs != 0) {
21528
+
21529
+ argsok = 0;
21530
+ }
21531
+ if (!argsok) {
1987621532
Jim_SetResultString(interp, "wrong # args: should be \"", -1);
1987721533
1987821534
add_cmd_usage(interp, ct, argv[0]);
1987921535
Jim_AppendStrings(interp, Jim_GetResult(interp), "\"", NULL);
1988021536
@@ -19895,11 +21551,11 @@
1989521551
}
1989621552
else {
1989721553
ret = ct->function(interp, argc - 2, argv + 2);
1989821554
}
1989921555
if (ret < 0) {
19900
- set_wrong_args(interp, ct, argv[0]);
21556
+ Jim_SubCmdArgError(interp, ct, argv[0]);
1990121557
ret = JIM_ERR;
1990221558
}
1990321559
}
1990421560
return ret;
1990521561
}
@@ -19946,10 +21602,11 @@
1994621602
}
1994721603
}
1994821604
1994921605
#include <ctype.h>
1995021606
#include <string.h>
21607
+#include <stdio.h>
1995121608
1995221609
1995321610
#define JIM_INTEGER_SPACE 24
1995421611
#define MAX_FLOAT_WIDTH 320
1995521612
@@ -20192,11 +21849,11 @@
2019221849
}
2019321850
2019421851
j = 0;
2019521852
for (i = length; i > 0; ) {
2019621853
i--;
20197
- if (w & ((unsigned jim_wide)1 << i)) {
21854
+ if (w & ((unsigned jim_wide)1 << i)) {
2019821855
num_buffer[j++] = '1';
2019921856
}
2020021857
else if (j || i == 0) {
2020121858
num_buffer[j++] = '0';
2020221859
}
@@ -20428,11 +22085,11 @@
2042822085
n++;
2042922086
}
2043022087
return n;
2043122088
}
2043222089
20433
-int regcomp(regex_t *preg, const char *exp, int cflags)
22090
+int jim_regcomp(regex_t *preg, const char *exp, int cflags)
2043422091
{
2043522092
int scan;
2043622093
int longest;
2043722094
unsigned len;
2043822095
int flags;
@@ -20843,11 +22500,11 @@
2084322500
if (*pattern == ']' || *pattern == '-') {
2084422501
reg_addrange(preg, *pattern, *pattern);
2084522502
pattern++;
2084622503
}
2084722504
20848
- while (*pattern && *pattern != ']') {
22505
+ while (*pattern != ']') {
2084922506
2085022507
int start;
2085122508
int end;
2085222509
2085322510
enum {
@@ -20854,10 +22511,15 @@
2085422511
CC_ALPHA, CC_ALNUM, CC_SPACE, CC_BLANK, CC_UPPER, CC_LOWER,
2085522512
CC_DIGIT, CC_XDIGIT, CC_CNTRL, CC_GRAPH, CC_PRINT, CC_PUNCT,
2085622513
CC_NUM
2085722514
};
2085822515
int cc;
22516
+
22517
+ if (!*pattern) {
22518
+ preg->err = REG_ERR_UNMATCHED_BRACKET;
22519
+ return 0;
22520
+ }
2085922521
2086022522
pattern += reg_utf8_tounicode_case(pattern, &start, nocase);
2086122523
if (start == '\\') {
2086222524
2086322525
switch (*pattern) {
@@ -20878,10 +22540,14 @@
2087822540
pattern += reg_decode_escape(pattern, &start);
2087922541
if (start == 0) {
2088022542
preg->err = REG_ERR_NULL_CHAR;
2088122543
return 0;
2088222544
}
22545
+ if (start == '\\' && *pattern == 0) {
22546
+ preg->err = REG_ERR_INVALID_ESCAPE;
22547
+ return 0;
22548
+ }
2088322549
}
2088422550
if (pattern[0] == '-' && pattern[1] && pattern[1] != ']') {
2088522551
2088622552
pattern += utf8_tounicode(pattern, &end);
2088722553
pattern += reg_utf8_tounicode_case(pattern, &end, nocase);
@@ -20888,10 +22554,14 @@
2088822554
if (end == '\\') {
2088922555
pattern += reg_decode_escape(pattern, &end);
2089022556
if (end == 0) {
2089122557
preg->err = REG_ERR_NULL_CHAR;
2089222558
return 0;
22559
+ }
22560
+ if (end == '\\' && *pattern == 0) {
22561
+ preg->err = REG_ERR_INVALID_ESCAPE;
22562
+ return 0;
2089322563
}
2089422564
}
2089522565
2089622566
reg_addrange(preg, start, end);
2089722567
continue;
@@ -20903,10 +22573,14 @@
2090322573
};
2090422574
2090522575
for (cc = 0; cc < CC_NUM; cc++) {
2090622576
n = strlen(character_class[cc]);
2090722577
if (strncmp(pattern, character_class[cc], n) == 0) {
22578
+ if (pattern[n] != ']') {
22579
+ preg->err = REG_ERR_UNMATCHED_BRACKET;
22580
+ return 0;
22581
+ }
2090822582
2090922583
pattern += n + 1;
2091022584
break;
2091122585
}
2091222586
}
@@ -20993,11 +22667,11 @@
2099322667
return 0;
2099422668
case '\\':
2099522669
ch = *preg->regparse++;
2099622670
switch (ch) {
2099722671
case '\0':
20998
- preg->err = REG_ERR_TRAILING_BACKSLASH;
22672
+ preg->err = REG_ERR_INVALID_ESCAPE;
2099922673
return 0;
2100022674
case 'A':
2100122675
ret = regnode(preg, BOLX);
2100222676
break;
2100322677
case 'Z':
@@ -21180,11 +22854,11 @@
2118022854
2118122855
static int regtry(regex_t *preg, const char *string );
2118222856
static int regmatch(regex_t *preg, int prog);
2118322857
static int regrepeat(regex_t *preg, int p, int max);
2118422858
21185
-int regexec(regex_t *preg, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags)
22859
+int jim_regexec(regex_t *preg, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags)
2118622860
{
2118722861
const char *s;
2118822862
int scan;
2118922863
2119022864
@@ -21521,11 +23195,11 @@
2152123195
break;
2152223196
case WORDZ:
2152323197
2152423198
if (preg->reginput > preg->regbol) {
2152523199
21526
- if (reg_iseol(preg, c) || !isalnum(UCHAR(c)) || c != '_') {
23200
+ if (reg_iseol(preg, c) || !(isalnum(UCHAR(c)) || c == '_')) {
2152723201
c = preg->reginput[-1];
2152823202
2152923203
if (isalnum(UCHAR(c)) || c == '_') {
2153023204
break;
2153123205
}
@@ -21617,10 +23291,12 @@
2161723291
preg->pmatch[no].rm_eo = save - preg->start;
2161823292
}
2161923293
}
2162023294
return(1);
2162123295
}
23296
+
23297
+ preg->reginput = save;
2162223298
return(0);
2162323299
}
2162423300
return REG_ERR_INTERNAL;
2162523301
}
2162623302
@@ -21640,14 +23316,13 @@
2164023316
2164123317
scan = preg->reginput;
2164223318
opnd = OPERAND(p);
2164323319
switch (OP(preg, p)) {
2164423320
case ANY:
21645
-
2164623321
while (!reg_iseol(preg, *scan) && count < max) {
2164723322
count++;
21648
- scan++;
23323
+ scan += utf8_charlen(*scan);
2164923324
}
2165023325
break;
2165123326
case EXACTLY:
2165223327
while (count < max) {
2165323328
n = reg_utf8_tounicode_case(scan, &ch, preg->cflags & REG_ICASE);
@@ -21724,11 +23399,11 @@
2172423399
}
2172523400
return 2;
2172623401
}
2172723402
2172823403
21729
-size_t regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)
23404
+size_t jim_regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)
2173023405
{
2173123406
static const char *error_strings[] = {
2173223407
"success",
2173323408
"no match",
2173423409
"bad pattern",
@@ -21743,13 +23418,14 @@
2174323418
"extra characters",
2174423419
"*+ of empty atom",
2174523420
"nested count",
2174623421
"internal error",
2174723422
"count follows nothing",
21748
- "trailing backslash",
23423
+ "invalid escape \\ sequence",
2174923424
"corrupted program",
2175023425
"contains null char",
23426
+ "brackets [] not balanced",
2175123427
};
2175223428
const char *err;
2175323429
2175423430
if (errcode < 0 || errcode >= REG_ERR_NUM) {
2175523431
err = "Bad error code";
@@ -21759,11 +23435,11 @@
2175923435
}
2176023436
2176123437
return snprintf(errbuf, errbuf_size, "%s", err);
2176223438
}
2176323439
21764
-void regfree(regex_t *preg)
23440
+void jim_regfree(regex_t *preg)
2176523441
{
2176623442
free(preg->program);
2176723443
}
2176823444
2176923445
#endif
@@ -21856,20 +23532,46 @@
2185623532
case ERROR_DIRECTORY: return ENOTDIR;
2185723533
}
2185823534
return EINVAL;
2185923535
}
2186023536
21861
-pidtype waitpid(pidtype pid, int *status, int nohang)
23537
+long JimProcessPid(phandle_t pid)
23538
+{
23539
+ if (pid == INVALID_HANDLE_VALUE) {
23540
+ return -1;
23541
+ }
23542
+ return GetProcessId(pid);
23543
+}
23544
+
23545
+phandle_t JimWaitPid(long pid, int *status, int nohang)
23546
+{
23547
+ if (pid > 0) {
23548
+ HANDLE h = OpenProcess(PROCESS_QUERY_INFORMATION | SYNCHRONIZE, FALSE, pid);
23549
+ if (h) {
23550
+ long pid = waitpid(h, status, nohang);
23551
+ CloseHandle(h);
23552
+ if (pid > 0) {
23553
+ return h;
23554
+ }
23555
+ }
23556
+ }
23557
+ return JIM_BAD_PHANDLE;
23558
+}
23559
+
23560
+long waitpid(phandle_t phandle, int *status, int nohang)
2186223561
{
21863
- DWORD ret = WaitForSingleObject(pid, nohang ? 0 : INFINITE);
23562
+ long pid;
23563
+ DWORD ret = WaitForSingleObject(phandle, nohang ? 0 : INFINITE);
2186423564
if (ret == WAIT_TIMEOUT || ret == WAIT_FAILED) {
2186523565
21866
- return JIM_BAD_PID;
23566
+ return -1;
2186723567
}
21868
- GetExitCodeProcess(pid, &ret);
23568
+ GetExitCodeProcess(phandle, &ret);
2186923569
*status = ret;
21870
- CloseHandle(pid);
23570
+
23571
+ pid = GetProcessId(phandle);
23572
+ CloseHandle(phandle);
2187123573
return pid;
2187223574
}
2187323575
2187423576
int Jim_MakeTempFile(Jim_Interp *interp, const char *filename_template, int unlink_file)
2187523577
{
@@ -21887,11 +23589,11 @@
2188723589
if (handle == INVALID_HANDLE_VALUE) {
2188823590
goto error;
2188923591
}
2189023592
2189123593
Jim_SetResultString(interp, name, -1);
21892
- return _open_osfhandle((int)handle, _O_RDWR | _O_TEXT);
23594
+ return _open_osfhandle((intptr_t)handle, _O_RDWR | _O_TEXT);
2189323595
2189423596
error:
2189523597
Jim_SetResultErrno(interp, name);
2189623598
DeleteFile(name);
2189723599
return -1;
@@ -22125,10 +23827,11 @@
2212523827
return buf;
2212623828
}
2212723829
#ifndef JIM_BOOTSTRAP_LIB_ONLY
2212823830
#include <errno.h>
2212923831
#include <string.h>
23832
+#include <stdio.h>
2213023833
2213123834
2213223835
#ifdef USE_LINENOISE
2213323836
#ifdef HAVE_UNISTD_H
2213423837
#include <unistd.h>
@@ -22140,42 +23843,58 @@
2214023843
#else
2214123844
#define MAX_LINE_LEN 512
2214223845
#endif
2214323846
2214423847
#ifdef USE_LINENOISE
23848
+struct JimCompletionInfo {
23849
+ Jim_Interp *interp;
23850
+ Jim_Obj *completion_command;
23851
+ Jim_Obj *hints_command;
23852
+
23853
+};
23854
+
23855
+static struct JimCompletionInfo *JimGetCompletionInfo(Jim_Interp *interp);
2214523856
static void JimCompletionCallback(const char *prefix, linenoiseCompletions *comp, void *userdata);
2214623857
static const char completion_callback_assoc_key[] = "interactive-completion";
23858
+static char *JimHintsCallback(const char *prefix, int *color, int *bold, void *userdata);
23859
+static void JimFreeHintsCallback(void *hint, void *userdata);
2214723860
#endif
2214823861
2214923862
char *Jim_HistoryGetline(Jim_Interp *interp, const char *prompt)
2215023863
{
2215123864
#ifdef USE_LINENOISE
22152
- struct JimCompletionInfo *compinfo = Jim_GetAssocData(interp, completion_callback_assoc_key);
23865
+ struct JimCompletionInfo *compinfo = JimGetCompletionInfo(interp);
2215323866
char *result;
2215423867
Jim_Obj *objPtr;
2215523868
long mlmode = 0;
22156
- if (compinfo) {
23869
+ if (compinfo->completion_command) {
2215723870
linenoiseSetCompletionCallback(JimCompletionCallback, compinfo);
2215823871
}
23872
+ if (compinfo->hints_command) {
23873
+ linenoiseSetHintsCallback(JimHintsCallback, compinfo);
23874
+ linenoiseSetFreeHintsCallback(JimFreeHintsCallback);
23875
+ }
2215923876
objPtr = Jim_GetVariableStr(interp, "history::multiline", JIM_NONE);
2216023877
if (objPtr && Jim_GetLong(interp, objPtr, &mlmode) == JIM_NONE) {
2216123878
linenoiseSetMultiLine(mlmode);
2216223879
}
2216323880
2216423881
result = linenoise(prompt);
2216523882
2216623883
linenoiseSetCompletionCallback(NULL, NULL);
23884
+ linenoiseSetHintsCallback(NULL, NULL);
23885
+ linenoiseSetFreeHintsCallback(NULL);
2216723886
return result;
2216823887
#else
2216923888
int len;
22170
- char *line = malloc(MAX_LINE_LEN);
23889
+ char *line = Jim_Alloc(MAX_LINE_LEN);
2217123890
2217223891
fputs(prompt, stdout);
2217323892
fflush(stdout);
2217423893
2217523894
if (fgets(line, MAX_LINE_LEN, stdin) == NULL) {
22176
- free(line);
23895
+ Jim_Free(line);
2217723896
return NULL;
2217823897
}
2217923898
len = strlen(line);
2218023899
if (len && line[len - 1] == '\n') {
2218123900
line[len - 1] = '\0';
@@ -22224,23 +23943,33 @@
2222423943
printf("%4d %s\n", i + 1, history[i]);
2222523944
}
2222623945
#endif
2222723946
}
2222823947
23948
+void Jim_HistorySetMaxLen(int length)
23949
+{
23950
+#ifdef USE_LINENOISE
23951
+ linenoiseHistorySetMaxLen(length);
23952
+#endif
23953
+}
23954
+
23955
+int Jim_HistoryGetMaxLen(void)
23956
+{
2222923957
#ifdef USE_LINENOISE
22230
-struct JimCompletionInfo {
22231
- Jim_Interp *interp;
22232
- Jim_Obj *command;
22233
-};
23958
+ return linenoiseHistoryGetMaxLen();
23959
+#endif
23960
+ return 0;
23961
+}
2223423962
23963
+#ifdef USE_LINENOISE
2223523964
static void JimCompletionCallback(const char *prefix, linenoiseCompletions *comp, void *userdata)
2223623965
{
2223723966
struct JimCompletionInfo *info = (struct JimCompletionInfo *)userdata;
2223823967
Jim_Obj *objv[2];
2223923968
int ret;
2224023969
22241
- objv[0] = info->command;
23970
+ objv[0] = info->completion_command;
2224223971
objv[1] = Jim_NewStringObj(info->interp, prefix, -1);
2224323972
2224423973
ret = Jim_EvalObjVector(info->interp, 2, objv);
2224523974
2224623975
@@ -22251,38 +23980,106 @@
2225123980
for (i = 0; i < len; i++) {
2225223981
linenoiseAddCompletion(comp, Jim_String(Jim_ListGetIndex(info->interp, listObj, i)));
2225323982
}
2225423983
}
2225523984
}
23985
+
23986
+static char *JimHintsCallback(const char *prefix, int *color, int *bold, void *userdata)
23987
+{
23988
+ struct JimCompletionInfo *info = (struct JimCompletionInfo *)userdata;
23989
+ Jim_Obj *objv[2];
23990
+ int ret;
23991
+ char *result = NULL;
23992
+
23993
+ objv[0] = info->hints_command;
23994
+ objv[1] = Jim_NewStringObj(info->interp, prefix, -1);
23995
+
23996
+ ret = Jim_EvalObjVector(info->interp, 2, objv);
23997
+
23998
+
23999
+ if (ret == JIM_OK) {
24000
+ Jim_Obj *listObj = Jim_GetResult(info->interp);
24001
+ Jim_IncrRefCount(listObj);
24002
+
24003
+ int len = Jim_ListLength(info->interp, listObj);
24004
+ if (len >= 1) {
24005
+ long x;
24006
+ result = Jim_StrDup(Jim_String(Jim_ListGetIndex(info->interp, listObj, 0)));
24007
+ if (len >= 2 && Jim_GetLong(info->interp, Jim_ListGetIndex(info->interp, listObj, 1), &x) == JIM_OK) {
24008
+ *color = x;
24009
+ }
24010
+ if (len >= 3 && Jim_GetLong(info->interp, Jim_ListGetIndex(info->interp, listObj, 2), &x) == JIM_OK) {
24011
+ *bold = x;
24012
+ }
24013
+ }
24014
+ Jim_DecrRefCount(info->interp, listObj);
24015
+ }
24016
+ return result;
24017
+}
24018
+
24019
+static void JimFreeHintsCallback(void *hint, void *userdata)
24020
+{
24021
+ Jim_Free(hint);
24022
+}
2225624023
2225724024
static void JimHistoryFreeCompletion(Jim_Interp *interp, void *data)
2225824025
{
2225924026
struct JimCompletionInfo *compinfo = data;
2226024027
22261
- Jim_DecrRefCount(interp, compinfo->command);
24028
+ if (compinfo->completion_command) {
24029
+ Jim_DecrRefCount(interp, compinfo->completion_command);
24030
+ }
24031
+ if (compinfo->hints_command) {
24032
+ Jim_DecrRefCount(interp, compinfo->hints_command);
24033
+ }
2226224034
2226324035
Jim_Free(compinfo);
2226424036
}
22265
-#endif
22266
-
22267
-void Jim_HistorySetCompletion(Jim_Interp *interp, Jim_Obj *commandObj)
22268
-{
22269
-#ifdef USE_LINENOISE
22270
- if (commandObj) {
22271
-
22272
- Jim_IncrRefCount(commandObj);
22273
- }
22274
-
22275
- Jim_DeleteAssocData(interp, completion_callback_assoc_key);
22276
-
22277
- if (commandObj) {
22278
- struct JimCompletionInfo *compinfo = Jim_Alloc(sizeof(*compinfo));
24037
+
24038
+static struct JimCompletionInfo *JimGetCompletionInfo(Jim_Interp *interp)
24039
+{
24040
+ struct JimCompletionInfo *compinfo = Jim_GetAssocData(interp, completion_callback_assoc_key);
24041
+ if (compinfo == NULL) {
24042
+ compinfo = Jim_Alloc(sizeof(*compinfo));
2227924043
compinfo->interp = interp;
22280
- compinfo->command = commandObj;
22281
-
24044
+ compinfo->completion_command = NULL;
24045
+ compinfo->hints_command = NULL;
2228224046
Jim_SetAssocData(interp, completion_callback_assoc_key, JimHistoryFreeCompletion, compinfo);
2228324047
}
24048
+ return compinfo;
24049
+}
24050
+#endif
24051
+
24052
+void Jim_HistorySetCompletion(Jim_Interp *interp, Jim_Obj *completionCommandObj)
24053
+{
24054
+#ifdef USE_LINENOISE
24055
+ struct JimCompletionInfo *compinfo = JimGetCompletionInfo(interp);
24056
+
24057
+ if (completionCommandObj) {
24058
+
24059
+ Jim_IncrRefCount(completionCommandObj);
24060
+ }
24061
+ if (compinfo->completion_command) {
24062
+ Jim_DecrRefCount(interp, compinfo->completion_command);
24063
+ }
24064
+ compinfo->completion_command = completionCommandObj;
24065
+#endif
24066
+}
24067
+
24068
+void Jim_HistorySetHints(Jim_Interp *interp, Jim_Obj *hintsCommandObj)
24069
+{
24070
+#ifdef USE_LINENOISE
24071
+ struct JimCompletionInfo *compinfo = JimGetCompletionInfo(interp);
24072
+
24073
+ if (hintsCommandObj) {
24074
+
24075
+ Jim_IncrRefCount(hintsCommandObj);
24076
+ }
24077
+ if (compinfo->hints_command) {
24078
+ Jim_DecrRefCount(interp, compinfo->hints_command);
24079
+ }
24080
+ compinfo->hints_command = hintsCommandObj;
2228424081
#endif
2228524082
}
2228624083
2228724084
int Jim_InteractivePrompt(Jim_Interp *interp)
2228824085
{
@@ -22298,10 +24095,11 @@
2229824095
snprintf(history_file, history_len, "%s/.jim_history", home);
2229924096
Jim_HistoryLoad(history_file);
2230024097
}
2230124098
2230224099
Jim_HistorySetCompletion(interp, Jim_NewStringObj(interp, "tcl::autocomplete", -1));
24100
+ Jim_HistorySetHints(interp, Jim_NewStringObj(interp, "tcl::stdhint", -1));
2230324101
#endif
2230424102
2230524103
printf("Welcome to Jim version %d.%d\n",
2230624104
JIM_VERSION / 100, JIM_VERSION % 100);
2230724105
Jim_SetVariableStrWithStr(interp, JIM_INTERACTIVE, "1");
@@ -22344,11 +24142,11 @@
2234424142
if (Jim_Length(scriptObjPtr) != 0) {
2234524143
2234624144
Jim_AppendString(interp, scriptObjPtr, "\n", 1);
2234724145
}
2234824146
Jim_AppendString(interp, scriptObjPtr, line, -1);
22349
- free(line);
24147
+ Jim_Free(line);
2235024148
if (Jim_ScriptIsComplete(interp, scriptObjPtr, &state))
2235124149
break;
2235224150
2235324151
snprintf(prompt, sizeof(prompt), "%c> ", state);
2235424152
}
@@ -22374,11 +24172,14 @@
2237424172
if (retcode == JIM_ERR) {
2237524173
Jim_MakeErrorMessage(interp);
2237624174
}
2237724175
result = Jim_GetString(Jim_GetResult(interp), &reslen);
2237824176
if (reslen) {
22379
- printf("%s\n", result);
24177
+ if (fwrite(result, reslen, 1, stdout) == 0) {
24178
+
24179
+ }
24180
+ putchar('\n');
2238024181
}
2238124182
}
2238224183
out:
2238324184
Jim_Free(history_file);
2238424185
@@ -22476,11 +24277,16 @@
2247624277
if (argc > 2 && strcmp(argv[1], "-e") == 0) {
2247724278
2247824279
JimSetArgv(interp, argc - 3, argv + 3);
2247924280
retcode = Jim_Eval(interp, argv[2]);
2248024281
if (retcode != JIM_ERR) {
22481
- printf("%s\n", Jim_String(Jim_GetResult(interp)));
24282
+ int len;
24283
+ const char *msg = Jim_GetString(Jim_GetResult(interp), &len);
24284
+ if (fwrite(msg, len, 1, stdout) == 0) {
24285
+
24286
+ }
24287
+ putchar('\n');
2248224288
}
2248324289
}
2248424290
else {
2248524291
Jim_SetVariableStr(interp, "argv0", Jim_NewStringObj(interp, argv[1], -1));
2248624292
JimSetArgv(interp, argc - 2, argv + 2);
2248724293
--- autosetup/jimsh0.c
+++ autosetup/jimsh0.c
@@ -10,10 +10,11 @@
10 #define jim_ext_readdir
11 #define jim_ext_regexp
12 #define jim_ext_file
13 #define jim_ext_glob
14 #define jim_ext_exec
 
15 #define jim_ext_clock
16 #define jim_ext_array
17 #define jim_ext_stdlib
18 #define jim_ext_tclcompat
19 #if defined(_MSC_VER)
@@ -47,21 +48,23 @@
47 #define vfork fork
48 #define _POSIX_SOURCE
49 #else
50 #define _GNU_SOURCE
51 #endif
52 #define HAVE_VFORK
53 #define HAVE_WAITPID
54 #define HAVE_ISATTY
55 #define HAVE_MKSTEMP
56 #define HAVE_LINK
57 #define HAVE_SYS_TIME_H
58 #define HAVE_DIRENT_H
59 #define HAVE_UNISTD_H
60 #define HAVE_UMASK
 
 
61 #endif
62 #define JIM_VERSION 78
63 #ifndef JIM_WIN32COMPAT_H
64 #define JIM_WIN32COMPAT_H
65
66
67
@@ -184,11 +187,10 @@
184 extern "C" {
185 #endif
186
187 #include <time.h>
188 #include <limits.h>
189 #include <stdio.h>
190 #include <stdlib.h>
191 #include <stdarg.h>
192
193
194 #ifndef HAVE_NO_AUTOCONF
@@ -223,10 +225,13 @@
223 #endif
224
225 #define UCHAR(c) ((unsigned char)(c))
226
227
 
 
 
228 #define JIM_OK 0
229 #define JIM_ERR 1
230 #define JIM_RETURN 2
231 #define JIM_BREAK 3
232 #define JIM_CONTINUE 4
@@ -244,10 +249,11 @@
244 #define JIM_NONE 0
245 #define JIM_ERRMSG 1
246 #define JIM_ENUM_ABBREV 2
247 #define JIM_UNSHARED 4
248 #define JIM_MUSTEXIST 8
 
249
250
251 #define JIM_SUBST_NOVAR 1
252 #define JIM_SUBST_NOCMD 2
253 #define JIM_SUBST_NOESC 4
@@ -254,10 +260,11 @@
254 #define JIM_SUBST_FLAG 128
255
256
257 #define JIM_CASESENS 0
258 #define JIM_NOCASE 1
 
259
260
261 #define JIM_PATH_LEN 1024
262
263
@@ -322,10 +329,12 @@
322 (entry)->u.val = (ht)->type->valDup((ht)->privdata, (_val_)); \
323 else \
324 (entry)->u.val = (_val_); \
325 } while(0)
326
 
 
327 #define Jim_FreeEntryKey(ht, entry) \
328 if ((ht)->type->keyDestructor) \
329 (ht)->type->keyDestructor((ht)->privdata, (entry)->key)
330
331 #define Jim_SetHashKey(ht, entry, _key_) do { \
@@ -342,10 +351,11 @@
342
343 #define Jim_HashKey(ht, key) ((ht)->type->hashFunction(key) + (ht)->uniq)
344
345 #define Jim_GetHashEntryKey(he) ((he)->key)
346 #define Jim_GetHashEntryVal(he) ((he)->u.val)
 
347 #define Jim_GetHashTableCollisions(ht) ((ht)->collisions)
348 #define Jim_GetHashTableSize(ht) ((ht)->size)
349 #define Jim_GetHashTableUsed(ht) ((ht)->used)
350
351
@@ -375,11 +385,11 @@
375 int int1;
376 int int2;
377 } ptrIntValue;
378
379 struct {
380 struct Jim_Var *varPtr;
381 unsigned long callFrameId;
382 int global;
383 } varValue;
384
385 struct {
@@ -391,10 +401,12 @@
391 struct {
392 struct Jim_Obj **ele;
393 int len;
394 int maxLen;
395 } listValue;
 
 
396
397 struct {
398 int maxLength;
399 int charLength;
400 } strValue;
@@ -477,33 +489,59 @@
477 int argc;
478 Jim_Obj *procArgsObjPtr;
479 Jim_Obj *procBodyObjPtr;
480 struct Jim_CallFrame *next;
481 Jim_Obj *nsObj;
482 Jim_Obj *fileNameObj;
483 int line;
484 Jim_Stack *localCommands;
485 struct Jim_Obj *tailcallObj;
486 struct Jim_Cmd *tailcallCmd;
487 } Jim_CallFrame;
488
489 typedef struct Jim_Var {
 
 
 
 
 
 
 
 
 
 
 
 
490 Jim_Obj *objPtr;
491 struct Jim_CallFrame *linkFramePtr;
492 } Jim_Var;
 
493
494
495 typedef int Jim_CmdProc(struct Jim_Interp *interp, int argc,
496 Jim_Obj *const *argv);
497 typedef void Jim_DelCmdProc(struct Jim_Interp *interp, void *privData);
498
499
 
 
 
 
 
 
 
 
 
 
 
 
500
501 typedef struct Jim_Cmd {
502 int inUse;
503 int isproc;
504 struct Jim_Cmd *prevCmd;
 
505 union {
506 struct {
507
508 Jim_CmdProc *cmdProc;
509 Jim_DelCmdProc *delProc;
@@ -534,13 +572,13 @@
534 unsigned int i, j;
535 } Jim_PrngState;
536
537 typedef struct Jim_Interp {
538 Jim_Obj *result;
539 int errorLine;
540 Jim_Obj *errorFileNameObj;
541 int addStackTrace;
542 int maxCallFrameDepth;
543 int maxEvalDepth;
544 int evalDepth;
545 int returnCode;
546 int returnLevel;
@@ -558,13 +596,19 @@
558 unsigned long callFrameEpoch; /* Incremented every time a new
559 callframe is created. This id is used for the
560 'ID' field contained in the Jim_CallFrame
561 structure. */
562 int local;
 
 
563 Jim_Obj *liveList;
564 Jim_Obj *freeList;
565 Jim_Obj *currentScriptObj;
 
 
 
 
566 Jim_Obj *nullScriptObj;
567 Jim_Obj *emptyObj;
568 Jim_Obj *trueObj;
569 Jim_Obj *falseObj;
570 unsigned long referenceNextId;
@@ -572,28 +616,31 @@
572 unsigned long lastCollectId; /* reference max Id of the last GC
573 execution. It's set to ~0 while the collection
574 is running as sentinel to avoid to recursive
575 calls via the [collect] command inside
576 finalizers. */
577 time_t lastCollectTime;
578 Jim_Obj *stackTrace;
579 Jim_Obj *errorProc;
580 Jim_Obj *unknown;
 
 
581 int unknown_called;
582 int errorFlag;
583 void *cmdPrivData; /* Used to pass the private data pointer to
584 a command. It is set to what the user specified
585 via Jim_CreateCommand(). */
586
 
 
587 struct Jim_CallFrame *freeFramesList;
588 struct Jim_HashTable assocData;
589 Jim_PrngState *prngState;
590 struct Jim_HashTable packages;
591 Jim_Stack *loadHandles;
592 } Jim_Interp;
593
594 #define Jim_InterpIncrProcEpoch(i) (i)->procEpoch++
595 #define Jim_SetResultString(i,s,l) Jim_SetResult(i, Jim_NewStringObj(i,s,l))
596 #define Jim_SetResultInt(i,intval) Jim_SetResult(i, Jim_NewIntObj(i,intval))
597
598 #define Jim_SetResultBool(i,b) Jim_SetResultInt(i, b)
599 #define Jim_SetEmptyResult(i) Jim_SetResult(i, (i)->emptyObj)
@@ -621,23 +668,36 @@
621
622
623 #define Jim_NewEmptyStringObj(i) Jim_NewStringObj(i, "", 0)
624 #define Jim_FreeHashTableIterator(iter) Jim_Free(iter)
625
626 #define JIM_EXPORT
627
628
629 JIM_EXPORT void *Jim_Alloc (int size);
630 JIM_EXPORT void *Jim_Realloc(void *ptr, int size);
631 JIM_EXPORT void Jim_Free (void *ptr);
 
 
 
632 JIM_EXPORT char * Jim_StrDup (const char *s);
633 JIM_EXPORT char *Jim_StrDupLen(const char *s, int l);
634
635
636 JIM_EXPORT char **Jim_GetEnviron(void);
637 JIM_EXPORT void Jim_SetEnviron(char **env);
638 JIM_EXPORT int Jim_MakeTempFile(Jim_Interp *interp, const char *filename_template, int unlink_file);
 
 
 
 
 
 
 
 
 
 
639
640
641 JIM_EXPORT int Jim_Eval(Jim_Interp *interp, const char *script);
642
643
@@ -680,11 +740,10 @@
680 JIM_EXPORT int Jim_DeleteHashEntry (Jim_HashTable *ht,
681 const void *key);
682 JIM_EXPORT int Jim_FreeHashTable (Jim_HashTable *ht);
683 JIM_EXPORT Jim_HashEntry * Jim_FindHashEntry (Jim_HashTable *ht,
684 const void *key);
685 JIM_EXPORT void Jim_ResizeHashTable (Jim_HashTable *ht);
686 JIM_EXPORT Jim_HashTableIterator *Jim_GetHashTableIterator
687 (Jim_HashTable *ht);
688 JIM_EXPORT Jim_HashEntry * Jim_NextHashEntry
689 (Jim_HashTableIterator *iter);
690
@@ -724,12 +783,10 @@
724 Jim_Obj *fmtObjPtr, int flags);
725 JIM_EXPORT int Jim_CompareStringImmediate (Jim_Interp *interp,
726 Jim_Obj *objPtr, const char *str);
727 JIM_EXPORT int Jim_StringCompareObj(Jim_Interp *interp, Jim_Obj *firstObjPtr,
728 Jim_Obj *secondObjPtr, int nocase);
729 JIM_EXPORT int Jim_StringCompareLenObj(Jim_Interp *interp, Jim_Obj *firstObjPtr,
730 Jim_Obj *secondObjPtr, int nocase);
731 JIM_EXPORT int Jim_Utf8Length(Jim_Interp *interp, Jim_Obj *objPtr);
732
733
734 JIM_EXPORT Jim_Obj * Jim_NewReference (Jim_Interp *interp,
735 Jim_Obj *objPtr, Jim_Obj *tagPtr, Jim_Obj *cmdNamePtr);
@@ -749,13 +806,13 @@
749 JIM_EXPORT void Jim_RegisterCoreCommands (Jim_Interp *interp);
750 JIM_EXPORT int Jim_CreateCommand (Jim_Interp *interp,
751 const char *cmdName, Jim_CmdProc *cmdProc, void *privData,
752 Jim_DelCmdProc *delProc);
753 JIM_EXPORT int Jim_DeleteCommand (Jim_Interp *interp,
754 const char *cmdName);
755 JIM_EXPORT int Jim_RenameCommand (Jim_Interp *interp,
756 const char *oldName, const char *newName);
757 JIM_EXPORT Jim_Cmd * Jim_GetCommand (Jim_Interp *interp,
758 Jim_Obj *objPtr, int flags);
759 JIM_EXPORT int Jim_SetVariable (Jim_Interp *interp,
760 Jim_Obj *nameObjPtr, Jim_Obj *valObjPtr);
761 JIM_EXPORT int Jim_SetVariableStr (Jim_Interp *interp,
@@ -822,12 +879,12 @@
822 Jim_Obj *dictPtr, Jim_Obj *const *keyv, int keyc,
823 Jim_Obj **objPtrPtr, int flags);
824 JIM_EXPORT int Jim_SetDictKeysVector (Jim_Interp *interp,
825 Jim_Obj *varNamePtr, Jim_Obj *const *keyv, int keyc,
826 Jim_Obj *newObjPtr, int flags);
827 JIM_EXPORT int Jim_DictPairs(Jim_Interp *interp,
828 Jim_Obj *dictPtr, Jim_Obj ***objPtrPtr, int *len);
829 JIM_EXPORT int Jim_DictAddElement(Jim_Interp *interp, Jim_Obj *objPtr,
830 Jim_Obj *keyObjPtr, Jim_Obj *valueObjPtr);
831
832 #define JIM_DICTMATCH_KEYS 0x0001
833 #define JIM_DICTMATCH_VALUES 0x002
@@ -851,10 +908,12 @@
851 JIM_EXPORT int Jim_GetBoolean(Jim_Interp *interp, Jim_Obj *objPtr,
852 int *booleanPtr);
853
854
855 JIM_EXPORT int Jim_GetWide (Jim_Interp *interp, Jim_Obj *objPtr,
 
 
856 jim_wide *widePtr);
857 JIM_EXPORT int Jim_GetLong (Jim_Interp *interp, Jim_Obj *objPtr,
858 long *longPtr);
859 #define Jim_NewWideObj Jim_NewIntObj
860 JIM_EXPORT Jim_Obj * Jim_NewIntObj (Jim_Interp *interp,
@@ -883,43 +942,52 @@
883 typedef void (Jim_InterpDeleteProc)(Jim_Interp *interp, void *data);
884 JIM_EXPORT void * Jim_GetAssocData(Jim_Interp *interp, const char *key);
885 JIM_EXPORT int Jim_SetAssocData(Jim_Interp *interp, const char *key,
886 Jim_InterpDeleteProc *delProc, void *data);
887 JIM_EXPORT int Jim_DeleteAssocData(Jim_Interp *interp, const char *key);
 
 
888
889
890
891 JIM_EXPORT int Jim_PackageProvide (Jim_Interp *interp,
892 const char *name, const char *ver, int flags);
893 JIM_EXPORT int Jim_PackageRequire (Jim_Interp *interp,
894 const char *name, int flags);
 
 
 
895
896
897 JIM_EXPORT void Jim_MakeErrorMessage (Jim_Interp *interp);
898
899
900 JIM_EXPORT int Jim_InteractivePrompt (Jim_Interp *interp);
901 JIM_EXPORT void Jim_HistoryLoad(const char *filename);
902 JIM_EXPORT void Jim_HistorySave(const char *filename);
903 JIM_EXPORT char *Jim_HistoryGetline(Jim_Interp *interp, const char *prompt);
904 JIM_EXPORT void Jim_HistorySetCompletion(Jim_Interp *interp, Jim_Obj *commandObj);
 
905 JIM_EXPORT void Jim_HistoryAdd(const char *line);
906 JIM_EXPORT void Jim_HistoryShow(void);
 
 
907
908
909 JIM_EXPORT int Jim_InitStaticExtensions(Jim_Interp *interp);
910 JIM_EXPORT int Jim_StringToWide(const char *str, jim_wide *widePtr, int base);
911 JIM_EXPORT int Jim_IsBigEndian(void);
912
913 #define Jim_CheckSignal(i) ((i)->signal_level && (i)->sigmask)
 
914
915
916 JIM_EXPORT int Jim_LoadLibrary(Jim_Interp *interp, const char *pathName);
917 JIM_EXPORT void Jim_FreeLoadHandles(Jim_Interp *interp);
918
919
920 JIM_EXPORT FILE *Jim_AioFilehandle(Jim_Interp *interp, Jim_Obj *command);
921
922
923 JIM_EXPORT int Jim_IsDict(Jim_Obj *objPtr);
924 JIM_EXPORT int Jim_IsList(Jim_Obj *objPtr);
925
@@ -952,16 +1020,21 @@
952 short minargs;
953 short maxargs;
954 unsigned short flags;
955 } jim_subcmd_type;
956
 
 
 
957 const jim_subcmd_type *
958 Jim_ParseSubCmd(Jim_Interp *interp, const jim_subcmd_type *command_table, int argc, Jim_Obj *const *argv);
959
960 int Jim_SubCmdProc(Jim_Interp *interp, int argc, Jim_Obj *const *argv);
961
962 int Jim_CallSubCmd(Jim_Interp *interp, const jim_subcmd_type *ct, int argc, Jim_Obj *const *argv);
 
 
963
964 #ifdef __cplusplus
965 }
966 #endif
967
@@ -1034,20 +1107,21 @@
1034 REG_ERR_JUNK_ON_END,
1035 REG_ERR_OPERAND_COULD_BE_EMPTY,
1036 REG_ERR_NESTED_COUNT,
1037 REG_ERR_INTERNAL,
1038 REG_ERR_COUNT_FOLLOWS_NOTHING,
1039 REG_ERR_TRAILING_BACKSLASH,
1040 REG_ERR_CORRUPTED,
1041 REG_ERR_NULL_CHAR,
 
1042 REG_ERR_NUM
1043 };
1044
1045 int regcomp(regex_t *preg, const char *regex, int cflags);
1046 int regexec(regex_t *preg, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags);
1047 size_t regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size);
1048 void regfree(regex_t *preg);
1049
1050 #ifdef __cplusplus
1051 }
1052 #endif
1053
@@ -1070,10 +1144,11 @@
1070 #define JIMIOCOMPAT_H
1071
1072
1073 #include <stdio.h>
1074 #include <errno.h>
 
1075
1076
1077 void Jim_SetResultErrno(Jim_Interp *interp, const char *msg);
1078
1079 int Jim_OpenForWrite(const char *filename, int append);
@@ -1088,67 +1163,109 @@
1088 #include <windows.h>
1089 #include <fcntl.h>
1090 #include <io.h>
1091 #include <process.h>
1092
1093 typedef HANDLE pidtype;
1094 #define JIM_BAD_PID INVALID_HANDLE_VALUE
1095
1096 #define JIM_NO_PID INVALID_HANDLE_VALUE
1097
1098
1099 #define WIFEXITED(STATUS) (((STATUS) & 0xff00) == 0)
1100 #define WEXITSTATUS(STATUS) ((STATUS) & 0x00ff)
1101 #define WIFSIGNALED(STATUS) (((STATUS) & 0xff00) != 0)
1102 #define WTERMSIG(STATUS) (((STATUS) >> 8) & 0xff)
1103 #define WNOHANG 1
1104
1105 int Jim_Errno(void);
1106 pidtype waitpid(pidtype pid, int *status, int nohang);
 
 
 
 
 
1107
1108 #define HAVE_PIPE
1109 #define pipe(P) _pipe((P), 0, O_NOINHERIT)
1110
1111 #elif defined(HAVE_UNISTD_H)
1112 #include <unistd.h>
1113 #include <fcntl.h>
1114 #include <sys/wait.h>
1115 #include <sys/stat.h>
1116
1117 typedef int pidtype;
1118 #define Jim_Errno() errno
1119 #define JIM_BAD_PID -1
1120 #define JIM_NO_PID 0
1121
1122 #ifndef HAVE_EXECVPE
1123 #define execvpe(ARG0, ARGV, ENV) execvp(ARG0, ARGV)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1124 #endif
1125 #endif
1126
 
 
 
 
 
 
 
1127 #endif
1128 int Jim_bootstrapInit(Jim_Interp *interp)
1129 {
1130 if (Jim_PackageProvide(interp, "bootstrap", "1.0", JIM_ERRMSG))
1131 return JIM_ERR;
1132
1133 return Jim_EvalSource(interp, "bootstrap.tcl", 1,
1134 "\n"
1135 "\n"
1136 "proc package {cmd pkg args} {\n"
1137 " if {$cmd eq \"require\"} {\n"
1138 " foreach path $::auto_path {\n"
 
1139 " set pkgpath $path/$pkg.tcl\n"
1140 " if {$path eq \".\"} {\n"
1141 " set pkgpath $pkg.tcl\n"
1142 " }\n"
1143 " if {[file exists $pkgpath]} {\n"
1144 " uplevel #0 [list source $pkgpath]\n"
1145 " return\n"
1146 " }\n"
1147 " }\n"
1148 " }\n"
1149 "}\n"
 
1150 );
1151 }
1152 int Jim_initjimshInit(Jim_Interp *interp)
1153 {
1154 if (Jim_PackageProvide(interp, "initjimsh", "1.0", JIM_ERRMSG))
@@ -1199,11 +1316,11 @@
1199 "if {$tcl_platform(platform) eq \"windows\"} {\n"
1200 " set jim::argv0 [string map {\\\\ /} $jim::argv0]\n"
1201 "}\n"
1202 "\n"
1203 "\n"
1204 "set tcl::autocomplete_commands {info tcl::prefix socket namespace array clock file package string dict signal history}\n"
1205 "\n"
1206 "\n"
1207 "\n"
1208 "proc tcl::autocomplete {prefix} {\n"
1209 " if {[set space [string first \" \" $prefix]] != -1} {\n"
@@ -1231,10 +1348,67 @@
1231 " }\n"
1232 " function $p\n"
1233 " }]\n"
1234 "}\n"
1235 "\n"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1236 "_jimsh_init\n"
1237 );
1238 }
1239 int Jim_globInit(Jim_Interp *interp)
1240 {
@@ -1480,40 +1654,35 @@
1480 "proc function {value} {\n"
1481 " return $value\n"
1482 "}\n"
1483 "\n"
1484 "\n"
1485 "\n"
1486 "\n"
1487 "proc stacktrace {{skip 0}} {\n"
1488 " set trace {}\n"
1489 " incr skip\n"
1490 " foreach level [range $skip [info level]] {\n"
1491 " lappend trace {*}[info frame -$level]\n"
1492 " }\n"
1493 " return $trace\n"
1494 "}\n"
1495 "\n"
1496 "\n"
1497 "proc stackdump {stacktrace} {\n"
1498 " set lines {}\n"
1499 " foreach {l f p} [lreverse $stacktrace] {\n"
 
1500 " set line {}\n"
 
 
 
1501 " if {$p ne \"\"} {\n"
1502 " append line \"in procedure '$p' \"\n"
1503 " if {$f ne \"\"} {\n"
1504 " append line \"called \"\n"
1505 " }\n"
1506 " }\n"
1507 " if {$f ne \"\"} {\n"
1508 " append line \"at file \\\"$f\\\", line $l\"\n"
1509 " }\n"
1510 " if {$line ne \"\"} {\n"
1511 " lappend lines $line\n"
 
 
 
 
 
 
 
1512 " }\n"
1513 " }\n"
1514 " join $lines \\n\n"
 
 
1515 "}\n"
1516 "\n"
1517 "\n"
1518 "\n"
1519 "proc defer {script} {\n"
@@ -1525,14 +1694,12 @@
1525 "\n"
1526 "proc errorInfo {msg {stacktrace \"\"}} {\n"
1527 " if {$stacktrace eq \"\"} {\n"
1528 "\n"
1529 " set stacktrace [info stacktrace]\n"
1530 "\n"
1531 " lappend stacktrace {*}[stacktrace 1]\n"
1532 " }\n"
1533 " lassign $stacktrace p f l\n"
1534 " if {$f ne \"\"} {\n"
1535 " set result \"$f:$l: Error: \"\n"
1536 " }\n"
1537 " append result \"$msg\\n\"\n"
1538 " append result [stackdump $stacktrace]\n"
@@ -1641,11 +1808,11 @@
1641 "\n"
1642 "\n"
1643 "set env [env]\n"
1644 "\n"
1645 "\n"
1646 "if {[info commands stdout] ne \"\"} {\n"
1647 "\n"
1648 " foreach p {gets flush close eof seek tell} {\n"
1649 " proc $p {chan args} {p} {\n"
1650 " tailcall $chan $p {*}$args\n"
1651 " }\n"
@@ -1815,76 +1982,10 @@
1815 " return $pids\n"
1816 "}\n"
1817 "\n"
1818 "\n"
1819 "\n"
1820 "\n"
1821 "\n"
1822 "\n"
1823 "\n"
1824 "\n"
1825 "\n"
1826 "\n"
1827 "proc try {args} {\n"
1828 " set catchopts {}\n"
1829 " while {[string match -* [lindex $args 0]]} {\n"
1830 " set args [lassign $args opt]\n"
1831 " if {$opt eq \"--\"} {\n"
1832 " break\n"
1833 " }\n"
1834 " lappend catchopts $opt\n"
1835 " }\n"
1836 " if {[llength $args] == 0} {\n"
1837 " return -code error {wrong # args: should be \"try ?options? script ?argument ...?\"}\n"
1838 " }\n"
1839 " set args [lassign $args script]\n"
1840 " set code [catch -eval {*}$catchopts {uplevel 1 $script} msg opts]\n"
1841 "\n"
1842 " set handled 0\n"
1843 "\n"
1844 " foreach {on codes vars script} $args {\n"
1845 " switch -- $on \\\n"
1846 " on {\n"
1847 " if {!$handled && ($codes eq \"*\" || [info returncode $code] in $codes)} {\n"
1848 " lassign $vars msgvar optsvar\n"
1849 " if {$msgvar ne \"\"} {\n"
1850 " upvar $msgvar hmsg\n"
1851 " set hmsg $msg\n"
1852 " }\n"
1853 " if {$optsvar ne \"\"} {\n"
1854 " upvar $optsvar hopts\n"
1855 " set hopts $opts\n"
1856 " }\n"
1857 "\n"
1858 " set code [catch {uplevel 1 $script} msg opts]\n"
1859 " incr handled\n"
1860 " }\n"
1861 " } \\\n"
1862 " finally {\n"
1863 " set finalcode [catch {uplevel 1 $codes} finalmsg finalopts]\n"
1864 " if {$finalcode} {\n"
1865 "\n"
1866 " set code $finalcode\n"
1867 " set msg $finalmsg\n"
1868 " set opts $finalopts\n"
1869 " }\n"
1870 " break\n"
1871 " } \\\n"
1872 " default {\n"
1873 " return -code error \"try: expected 'on' or 'finally', got '$on'\"\n"
1874 " }\n"
1875 " }\n"
1876 "\n"
1877 " if {$code} {\n"
1878 " incr opts(-level)\n"
1879 " return {*}$opts $msg\n"
1880 " }\n"
1881 " return $msg\n"
1882 "}\n"
1883 "\n"
1884 "\n"
1885 "\n"
1886 "proc throw {code {msg \"\"}} {\n"
1887 " return -code $code $msg\n"
1888 "}\n"
1889 "\n"
1890 "\n"
@@ -1896,20 +1997,24 @@
1896 "}\n"
1897 );
1898 }
1899
1900
1901 #ifndef _GNU_SOURCE
1902 #define _GNU_SOURCE
1903 #endif
1904 #include <stdio.h>
1905 #include <string.h>
1906 #include <errno.h>
1907 #include <fcntl.h>
 
1908 #ifdef HAVE_UNISTD_H
1909 #include <unistd.h>
1910 #include <sys/stat.h>
 
 
 
 
 
 
1911 #endif
1912
1913
1914 #if defined(HAVE_SYS_SOCKET_H) && defined(HAVE_SELECT) && defined(HAVE_NETINET_IN_H) && defined(HAVE_NETDB_H) && defined(HAVE_ARPA_INET_H)
1915 #include <sys/socket.h>
@@ -1921,12 +2026,10 @@
1921 #include <sys/un.h>
1922 #endif
1923 #define HAVE_SOCKETS
1924 #elif defined (__MINGW32__)
1925
1926 #else
1927 #define JIM_ANSIC
1928 #endif
1929
1930 #if defined(JIM_SSL)
1931 #include <openssl/ssl.h>
1932 #include <openssl/err.h>
@@ -1936,98 +2039,136 @@
1936 #endif
1937
1938
1939 #define AIO_CMD_LEN 32
1940 #define AIO_BUF_LEN 256
1941
1942 #ifndef HAVE_FTELLO
1943 #define ftello ftell
1944 #endif
1945 #ifndef HAVE_FSEEKO
1946 #define fseeko fseek
1947 #endif
1948
1949 #define AIO_KEEPOPEN 1
 
 
 
 
 
 
 
 
 
 
1950
1951 #if defined(JIM_IPV6)
1952 #define IPV6 1
1953 #else
1954 #define IPV6 0
1955 #ifndef PF_INET6
1956 #define PF_INET6 0
1957 #endif
1958 #endif
 
 
 
 
 
1959
1960 #ifdef JIM_ANSIC
 
 
1961
1962 #undef HAVE_PIPE
1963 #undef HAVE_SOCKETPAIR
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1964 #endif
 
1965
1966
1967 struct AioFile;
1968
1969 typedef struct {
1970 int (*writer)(struct AioFile *af, const char *buf, int len);
1971 int (*reader)(struct AioFile *af, char *buf, int len);
1972 const char *(*getline)(struct AioFile *af, char *buf, int len);
1973 int (*error)(const struct AioFile *af);
1974 const char *(*strerror)(struct AioFile *af);
1975 int (*verify)(struct AioFile *af);
1976 } JimAioFopsType;
1977
1978 typedef struct AioFile
1979 {
1980 FILE *fp;
1981 Jim_Obj *filename;
1982 int type;
1983 int openFlags;
 
1984 int fd;
1985 Jim_Obj *rEvent;
1986 Jim_Obj *wEvent;
1987 Jim_Obj *eEvent;
1988 int addr_family;
1989 void *ssl;
1990 const JimAioFopsType *fops;
 
 
1991 } AioFile;
1992
1993 static int stdio_writer(struct AioFile *af, const char *buf, int len)
1994 {
1995 return fwrite(buf, 1, len, af->fp);
1996 }
1997
1998 static int stdio_reader(struct AioFile *af, char *buf, int len)
1999 {
2000 return fread(buf, 1, len, af->fp);
2001 }
2002
2003 static const char *stdio_getline(struct AioFile *af, char *buf, int len)
2004 {
2005 return fgets(buf, len, af->fp);
 
 
 
 
 
 
 
2006 }
2007
2008 static int stdio_error(const AioFile *af)
2009 {
2010 if (!ferror(af->fp)) {
2011 return JIM_OK;
2012 }
2013 clearerr(af->fp);
2014
2015 if (feof(af->fp) || errno == EAGAIN || errno == EINTR) {
2016 return JIM_OK;
2017 }
 
2018 #ifdef ECONNRESET
2019 if (errno == ECONNRESET) {
2020 return JIM_OK;
2021 }
2022 #endif
2023 #ifdef ECONNABORTED
2024 if (errno == ECONNABORTED) {
2025 return JIM_OK;
 
 
 
2026 }
2027 #endif
2028 return JIM_ERR;
2029 }
2030
2031 static const char *stdio_strerror(struct AioFile *af)
2032 {
2033 return strerror(errno);
@@ -2034,20 +2175,47 @@
2034 }
2035
2036 static const JimAioFopsType stdio_fops = {
2037 stdio_writer,
2038 stdio_reader,
2039 stdio_getline,
2040 stdio_error,
2041 stdio_strerror,
2042 NULL
2043 };
2044
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2045
2046 static int JimAioSubCmdProc(Jim_Interp *interp, int argc, Jim_Obj *const *argv);
2047 static AioFile *JimMakeChannel(Jim_Interp *interp, FILE *fh, int fd, Jim_Obj *filename,
2048 const char *hdlfmt, int family, const char *mode);
2049
2050
2051 static const char *JimAioErrorString(AioFile *af)
2052 {
2053 if (af && af->fops)
@@ -2065,26 +2233,171 @@
2065 }
2066 else {
2067 Jim_SetResultString(interp, JimAioErrorString(af), -1);
2068 }
2069 }
 
 
 
 
 
2070
2071 static int JimCheckStreamError(Jim_Interp *interp, AioFile *af)
2072 {
2073 int ret = af->fops->error(af);
2074 if (ret) {
2075 JimAioSetError(interp, af->filename);
2076 }
2077 return ret;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2078 }
2079
2080 static void JimAioDelProc(Jim_Interp *interp, void *privData)
2081 {
2082 AioFile *af = privData;
2083
2084 JIM_NOTUSED(interp);
2085
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2086 Jim_DecrRefCount(interp, af->filename);
2087
2088 #ifdef jim_ext_eventloop
2089
2090 Jim_DeleteFileHandler(interp, af->fd, JIM_EVENT_READABLE | JIM_EVENT_WRITABLE | JIM_EVENT_EXCEPTION);
@@ -2093,144 +2406,180 @@
2093 #if defined(JIM_SSL)
2094 if (af->ssl != NULL) {
2095 SSL_free(af->ssl);
2096 }
2097 #endif
2098 if (!(af->openFlags & AIO_KEEPOPEN)) {
2099 fclose(af->fp);
 
 
 
2100 }
2101
2102 Jim_Free(af);
2103 }
2104
2105 static int aio_cmd_read(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
2106 {
2107 AioFile *af = Jim_CmdPrivData(interp);
2108 char buf[AIO_BUF_LEN];
2109 Jim_Obj *objPtr;
2110 int nonewline = 0;
2111 jim_wide neededLen = -1;
 
 
 
 
 
 
2112
2113 if (argc && Jim_CompareStringImmediate(interp, argv[0], "-nonewline")) {
2114 nonewline = 1;
2115 argv++;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2116 argc--;
2117 }
2118 if (argc == 1) {
2119 if (Jim_GetWide(interp, argv[0], &neededLen) != JIM_OK)
2120 return JIM_ERR;
2121 if (neededLen < 0) {
2122 Jim_SetResultString(interp, "invalid parameter: negative len", -1);
2123 return JIM_ERR;
2124 }
2125 }
2126 else if (argc) {
2127 return -1;
2128 }
2129 objPtr = Jim_NewStringObj(interp, NULL, 0);
2130 while (neededLen != 0) {
2131 int retval;
2132 int readlen;
2133
2134 if (neededLen == -1) {
2135 readlen = AIO_BUF_LEN;
2136 }
2137 else {
2138 readlen = (neededLen > AIO_BUF_LEN ? AIO_BUF_LEN : neededLen);
2139 }
2140 retval = af->fops->reader(af, buf, readlen);
2141 if (retval > 0) {
2142 Jim_AppendString(interp, objPtr, buf, retval);
2143 if (neededLen != -1) {
2144 neededLen -= retval;
2145 }
2146 }
2147 if (retval != readlen)
2148 break;
2149 }
2150
2151 if (JimCheckStreamError(interp, af)) {
2152 Jim_FreeNewObj(interp, objPtr);
2153 return JIM_ERR;
2154 }
2155 if (nonewline) {
2156 int len;
2157 const char *s = Jim_GetString(objPtr, &len);
2158
2159 if (len > 0 && s[len - 1] == '\n') {
2160 objPtr->length--;
2161 objPtr->bytes[objPtr->length] = '\0';
2162 }
2163 }
2164 Jim_SetResult(interp, objPtr);
2165 return JIM_OK;
2166 }
2167
2168 AioFile *Jim_AioFile(Jim_Interp *interp, Jim_Obj *command)
2169 {
2170 Jim_Cmd *cmdPtr = Jim_GetCommand(interp, command, JIM_ERRMSG);
2171
2172
2173 if (cmdPtr && !cmdPtr->isproc && cmdPtr->u.native.cmdProc == JimAioSubCmdProc) {
2174 return (AioFile *) cmdPtr->u.native.privData;
2175 }
2176 Jim_SetResultFormatted(interp, "Not a filehandle: \"%#s\"", command);
2177 return NULL;
2178 }
2179
2180 FILE *Jim_AioFilehandle(Jim_Interp *interp, Jim_Obj *command)
2181 {
2182 AioFile *af;
2183
2184 af = Jim_AioFile(interp, command);
2185 if (af == NULL) {
2186 return NULL;
2187 }
2188
2189 return af->fp;
2190 }
2191
2192 static int aio_cmd_getfd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
2193 {
2194 AioFile *af = Jim_CmdPrivData(interp);
2195
2196 fflush(af->fp);
2197 Jim_SetResultInt(interp, fileno(af->fp));
 
 
2198
2199 return JIM_OK;
2200 }
2201
2202 static int aio_cmd_copy(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
2203 {
2204 AioFile *af = Jim_CmdPrivData(interp);
2205 jim_wide count = 0;
2206 jim_wide maxlen = JIM_WIDE_MAX;
2207 AioFile *outf = Jim_AioFile(interp, argv[0]);
2208
2209 if (outf == NULL) {
2210 return JIM_ERR;
2211 }
 
 
 
2212
2213 if (argc == 2) {
2214 if (Jim_GetWide(interp, argv[1], &maxlen) != JIM_OK) {
2215 return JIM_ERR;
2216 }
2217 }
2218
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2219 while (count < maxlen) {
2220 char ch;
2221
2222 if (af->fops->reader(af, &ch, 1) != 1) {
 
 
 
2223 break;
2224 }
2225 if (outf->fops->writer(outf, &ch, 1) != 1) {
 
 
 
2226 break;
2227 }
2228 count++;
 
 
 
 
 
 
 
2229 }
2230
2231 if (JimCheckStreamError(interp, af) || JimCheckStreamError(interp, outf)) {
 
 
 
 
 
 
 
2232 return JIM_ERR;
2233 }
2234
2235 Jim_SetResultInt(interp, count);
2236
@@ -2239,42 +2588,58 @@
2239
2240 static int aio_cmd_gets(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
2241 {
2242 AioFile *af = Jim_CmdPrivData(interp);
2243 char buf[AIO_BUF_LEN];
2244 Jim_Obj *objPtr;
2245 int len;
 
 
 
2246
2247 errno = 0;
2248
2249 objPtr = Jim_NewStringObj(interp, NULL, 0);
2250 while (1) {
2251 buf[AIO_BUF_LEN - 1] = '_';
2252
2253 if (af->fops->getline(af, buf, AIO_BUF_LEN) == NULL)
2254 break;
2255
2256 if (buf[AIO_BUF_LEN - 1] == '\0' && buf[AIO_BUF_LEN - 2] != '\n') {
2257 Jim_AppendString(interp, objPtr, buf, AIO_BUF_LEN - 1);
2258 }
2259 else {
2260 len = strlen(buf);
2261
2262 if (len && (buf[len - 1] == '\n')) {
2263
2264 len--;
2265 }
2266
2267 Jim_AppendString(interp, objPtr, buf, len);
2268 break;
2269 }
2270 }
2271
2272 if (JimCheckStreamError(interp, af)) {
2273
2274 Jim_FreeNewObj(interp, objPtr);
2275 return JIM_ERR;
 
 
 
 
 
 
 
 
 
 
 
 
 
2276 }
2277
2278 if (argc) {
2279 if (Jim_SetVariable(interp, argv[0], objPtr) != JIM_OK) {
2280 Jim_FreeNewObj(interp, objPtr);
@@ -2281,11 +2646,11 @@
2281 return JIM_ERR;
2282 }
2283
2284 len = Jim_Length(objPtr);
2285
2286 if (len == 0 && feof(af->fp)) {
2287
2288 len = -1;
2289 }
2290 Jim_SetResultInt(interp, len);
2291 }
@@ -2299,36 +2664,62 @@
2299 {
2300 AioFile *af = Jim_CmdPrivData(interp);
2301 int wlen;
2302 const char *wdata;
2303 Jim_Obj *strObj;
 
 
2304
2305 if (argc == 2) {
2306 if (!Jim_CompareStringImmediate(interp, argv[0], "-nonewline")) {
2307 return -1;
2308 }
2309 strObj = argv[1];
 
2310 }
2311 else {
2312 strObj = argv[0];
2313 }
2314
2315 wdata = Jim_GetString(strObj, &wlen);
2316 if (af->fops->writer(af, wdata, wlen) == wlen) {
2317 if (argc == 2 || af->fops->writer(af, "\n", 1) == 1) {
2318 return JIM_OK;
2319 }
2320 }
2321 JimAioSetError(interp, af->filename);
2322 return JIM_ERR;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2323 }
2324
2325 static int aio_cmd_isatty(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
2326 {
2327 #ifdef HAVE_ISATTY
2328 AioFile *af = Jim_CmdPrivData(interp);
2329 Jim_SetResultInt(interp, isatty(fileno(af->fp)));
2330 #else
2331 Jim_SetResultInt(interp, 0);
2332 #endif
2333
2334 return JIM_OK;
@@ -2336,49 +2727,62 @@
2336
2337
2338 static int aio_cmd_flush(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
2339 {
2340 AioFile *af = Jim_CmdPrivData(interp);
2341
2342 if (fflush(af->fp) == EOF) {
2343 JimAioSetError(interp, af->filename);
2344 return JIM_ERR;
2345 }
2346 return JIM_OK;
2347 }
2348
2349 static int aio_cmd_eof(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
2350 {
2351 AioFile *af = Jim_CmdPrivData(interp);
2352
2353 Jim_SetResultInt(interp, feof(af->fp));
2354 return JIM_OK;
2355 }
2356
2357 static int aio_cmd_close(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
2358 {
 
2359 if (argc == 3) {
2360 #if defined(HAVE_SOCKETS) && defined(HAVE_SHUTDOWN)
2361 static const char * const options[] = { "r", "w", NULL };
2362 enum { OPT_R, OPT_W, };
2363 int option;
2364 AioFile *af = Jim_CmdPrivData(interp);
2365
2366 if (Jim_GetEnum(interp, argv[2], options, &option, NULL, JIM_ERRMSG) != JIM_OK) {
2367 return JIM_ERR;
2368 }
2369 if (shutdown(af->fd, option == OPT_R ? SHUT_RD : SHUT_WR) == 0) {
2370 return JIM_OK;
2371 }
2372 JimAioSetError(interp, NULL);
2373 #else
2374 Jim_SetResultString(interp, "async close not supported", -1);
2375 #endif
2376 return JIM_ERR;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2377 }
2378
2379 return Jim_DeleteCommand(interp, Jim_String(argv[0]));
 
 
 
2380 }
2381
2382 static int aio_cmd_seek(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
2383 {
2384 AioFile *af = Jim_CmdPrivData(interp);
@@ -2397,22 +2801,31 @@
2397 }
2398 }
2399 if (Jim_GetWide(interp, argv[0], &offset) != JIM_OK) {
2400 return JIM_ERR;
2401 }
2402 if (fseeko(af->fp, offset, orig) == -1) {
 
 
 
 
2403 JimAioSetError(interp, af->filename);
2404 return JIM_ERR;
2405 }
 
 
 
 
 
2406 return JIM_OK;
2407 }
2408
2409 static int aio_cmd_tell(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
2410 {
2411 AioFile *af = Jim_CmdPrivData(interp);
2412
2413 Jim_SetResultInt(interp, ftello(af->fp));
2414 return JIM_OK;
2415 }
2416
2417 static int aio_cmd_filename(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
2418 {
@@ -2425,27 +2838,19 @@
2425 #ifdef O_NDELAY
2426 static int aio_cmd_ndelay(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
2427 {
2428 AioFile *af = Jim_CmdPrivData(interp);
2429
2430 int fmode = fcntl(af->fd, F_GETFL);
2431
2432 if (argc) {
2433 long nb;
2434
2435 if (Jim_GetLong(interp, argv[0], &nb) != JIM_OK) {
2436 return JIM_ERR;
2437 }
2438 if (nb) {
2439 fmode |= O_NDELAY;
2440 }
2441 else {
2442 fmode &= ~O_NDELAY;
2443 }
2444 (void)fcntl(af->fd, F_SETFL, fmode);
2445 }
2446 Jim_SetResultInt(interp, (fmode & O_NONBLOCK) ? 1 : 0);
2447 return JIM_OK;
2448 }
2449 #endif
2450
2451
@@ -2452,11 +2857,13 @@
2452 #ifdef HAVE_FSYNC
2453 static int aio_cmd_sync(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
2454 {
2455 AioFile *af = Jim_CmdPrivData(interp);
2456
2457 fflush(af->fp);
 
 
2458 fsync(af->fd);
2459 return JIM_OK;
2460 }
2461 #endif
2462
@@ -2468,111 +2875,105 @@
2468 "none",
2469 "line",
2470 "full",
2471 NULL
2472 };
2473 enum
2474 {
2475 OPT_NONE,
2476 OPT_LINE,
2477 OPT_FULL,
2478 };
2479 int option;
2480
2481 if (Jim_GetEnum(interp, argv[0], options, &option, NULL, JIM_ERRMSG) != JIM_OK) {
2482 return JIM_ERR;
2483 }
2484 switch (option) {
2485 case OPT_NONE:
2486 setvbuf(af->fp, NULL, _IONBF, 0);
2487 break;
2488 case OPT_LINE:
2489 setvbuf(af->fp, NULL, _IOLBF, BUFSIZ);
2490 break;
2491 case OPT_FULL:
2492 setvbuf(af->fp, NULL, _IOFBF, BUFSIZ);
2493 break;
2494 }
2495 return JIM_OK;
 
 
 
 
 
 
 
 
 
 
 
2496 }
2497
2498 #ifdef jim_ext_eventloop
2499 static void JimAioFileEventFinalizer(Jim_Interp *interp, void *clientData)
2500 {
2501 Jim_Obj **objPtrPtr = clientData;
2502
2503 Jim_DecrRefCount(interp, *objPtrPtr);
2504 *objPtrPtr = NULL;
2505 }
2506
2507 static int JimAioFileEventHandler(Jim_Interp *interp, void *clientData, int mask)
2508 {
2509 Jim_Obj **objPtrPtr = clientData;
2510
2511 return Jim_EvalObjBackground(interp, *objPtrPtr);
2512 }
2513
2514 static int aio_eventinfo(Jim_Interp *interp, AioFile * af, unsigned mask, Jim_Obj **scriptHandlerObj,
2515 int argc, Jim_Obj * const *argv)
2516 {
2517 if (argc == 0) {
2518
2519 if (*scriptHandlerObj) {
2520 Jim_SetResult(interp, *scriptHandlerObj);
 
2521 }
2522 return JIM_OK;
2523 }
2524
2525 if (*scriptHandlerObj) {
2526
2527 Jim_DeleteFileHandler(interp, af->fd, mask);
2528 }
2529
2530
2531 if (Jim_Length(argv[0]) == 0) {
2532
2533 return JIM_OK;
2534 }
2535
2536
2537 Jim_IncrRefCount(argv[0]);
2538 *scriptHandlerObj = argv[0];
2539
2540 Jim_CreateFileHandler(interp, af->fd, mask,
2541 JimAioFileEventHandler, scriptHandlerObj, JimAioFileEventFinalizer);
2542
2543 return JIM_OK;
2544 }
2545
2546 static int aio_cmd_readable(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
2547 {
2548 AioFile *af = Jim_CmdPrivData(interp);
2549
2550 return aio_eventinfo(interp, af, JIM_EVENT_READABLE, &af->rEvent, argc, argv);
2551 }
2552
2553 static int aio_cmd_writable(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
2554 {
2555 AioFile *af = Jim_CmdPrivData(interp);
2556
2557 return aio_eventinfo(interp, af, JIM_EVENT_WRITABLE, &af->wEvent, argc, argv);
2558 }
2559
2560 static int aio_cmd_onexception(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
2561 {
2562 AioFile *af = Jim_CmdPrivData(interp);
2563
2564 return aio_eventinfo(interp, af, JIM_EVENT_EXCEPTION, &af->eEvent, argc, argv);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2565 }
2566 #endif
2567
2568
2569
2570
2571 static const jim_subcmd_type aio_command_table[] = {
2572 { "read",
2573 "?-nonewline? ?len?",
2574 aio_cmd_read,
2575 0,
2576 2,
2577
2578 },
@@ -2677,10 +3078,19 @@
2677 aio_cmd_buffering,
2678 1,
2679 1,
2680
2681 },
 
 
 
 
 
 
 
 
 
2682 #ifdef jim_ext_eventloop
2683 { "readable",
2684 "?readable-script?",
2685 aio_cmd_readable,
2686 0,
@@ -2698,126 +3108,235 @@
2698 "?exception-script?",
2699 aio_cmd_onexception,
2700 0,
2701 1,
2702
 
 
 
 
 
 
 
2703 },
2704 #endif
2705 { NULL }
2706 };
2707
2708 static int JimAioSubCmdProc(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
2709 {
2710 return Jim_CallSubCmd(interp, Jim_ParseSubCmd(interp, aio_command_table, argc, argv), argc, argv);
2711 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2712
2713 static int JimAioOpenCommand(Jim_Interp *interp, int argc,
2714 Jim_Obj *const *argv)
2715 {
2716 const char *mode;
 
 
 
 
2717
2718 if (argc != 2 && argc != 3) {
2719 Jim_WrongNumArgs(interp, 1, argv, "filename ?mode?");
 
 
 
 
2720 return JIM_ERR;
2721 }
2722
2723 mode = (argc == 3) ? Jim_String(argv[2]) : "r";
2724
2725 #ifdef jim_ext_tclcompat
2726 {
2727 const char *filename = Jim_String(argv[1]);
2728
2729
2730 if (*filename == '|') {
2731 Jim_Obj *evalObj[3];
 
2732
2733 evalObj[0] = Jim_NewStringObj(interp, "::popen", -1);
2734 evalObj[1] = Jim_NewStringObj(interp, filename + 1, -1);
2735 evalObj[2] = Jim_NewStringObj(interp, mode, -1);
 
 
2736
2737 return Jim_EvalObjVector(interp, 3, evalObj);
2738 }
2739 }
2740 #endif
2741 return JimMakeChannel(interp, NULL, -1, argv[1], "aio.handle%ld", 0, mode) ? JIM_OK : JIM_ERR;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2742 }
2743
2744
2745 static AioFile *JimMakeChannel(Jim_Interp *interp, FILE *fh, int fd, Jim_Obj *filename,
2746 const char *hdlfmt, int family, const char *mode)
2747 {
2748 AioFile *af;
2749 char buf[AIO_CMD_LEN];
2750 int openFlags = 0;
2751
2752 snprintf(buf, sizeof(buf), hdlfmt, Jim_GetId(interp));
2753
2754 if (fh) {
2755 openFlags = AIO_KEEPOPEN;
2756 }
2757
2758 snprintf(buf, sizeof(buf), hdlfmt, Jim_GetId(interp));
2759 if (!filename) {
2760 filename = Jim_NewStringObj(interp, buf, -1);
2761 }
2762
2763 Jim_IncrRefCount(filename);
2764
2765 if (fh == NULL) {
2766 if (fd >= 0) {
2767 #ifndef JIM_ANSIC
2768 fh = fdopen(fd, mode);
2769 #endif
2770 }
2771 else
2772 fh = fopen(Jim_String(filename), mode);
2773
2774 if (fh == NULL) {
2775 JimAioSetError(interp, filename);
2776 #ifndef JIM_ANSIC
2777 if (fd >= 0) {
2778 close(fd);
2779 }
2780 #endif
2781 Jim_DecrRefCount(interp, filename);
2782 return NULL;
2783 }
2784 }
2785
2786
2787 af = Jim_Alloc(sizeof(*af));
2788 memset(af, 0, sizeof(*af));
2789 af->fp = fh;
2790 af->filename = filename;
2791 af->openFlags = openFlags;
2792 #ifndef JIM_ANSIC
2793 af->fd = fileno(fh);
 
 
 
 
 
 
 
 
 
 
 
 
2794 #ifdef FD_CLOEXEC
2795 if ((openFlags & AIO_KEEPOPEN) == 0) {
2796 (void)fcntl(af->fd, F_SETFD, FD_CLOEXEC);
2797 }
2798 #endif
2799 #endif
2800 af->addr_family = family;
2801 af->fops = &stdio_fops;
2802 af->ssl = NULL;
 
 
2803
2804 Jim_CreateCommand(interp, buf, JimAioSubCmdProc, af, JimAioDelProc);
2805
2806 Jim_SetResult(interp, Jim_MakeGlobalNamespaceName(interp, Jim_NewStringObj(interp, buf, -1)));
2807
2808 return af;
2809 }
2810
2811 #if defined(HAVE_PIPE) || (defined(HAVE_SOCKETPAIR) && defined(HAVE_SYS_UN_H))
2812 static int JimMakeChannelPair(Jim_Interp *interp, int p[2], Jim_Obj *filename,
2813 const char *hdlfmt, int family, const char *mode[2])
2814 {
2815 if (JimMakeChannel(interp, NULL, p[0], filename, hdlfmt, family, mode[0])) {
2816 Jim_Obj *objPtr = Jim_NewListObj(interp, NULL, 0);
2817 Jim_ListAppendElement(interp, objPtr, Jim_GetResult(interp));
2818 if (JimMakeChannel(interp, NULL, p[1], filename, hdlfmt, family, mode[1])) {
2819 Jim_ListAppendElement(interp, objPtr, Jim_GetResult(interp));
2820 Jim_SetResult(interp, objPtr);
2821 return JIM_OK;
2822 }
2823 }
@@ -2829,26 +3348,52 @@
2829 return JIM_ERR;
2830 }
2831 #endif
2832
2833 #ifdef HAVE_PIPE
2834 static int JimAioPipeCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
2835 {
2836 int p[2];
2837 static const char *mode[2] = { "r", "w" };
2838
2839 if (argc != 1) {
2840 Jim_WrongNumArgs(interp, 1, argv, "");
2841 return JIM_ERR;
2842 }
2843
2844 if (pipe(p) != 0) {
2845 JimAioSetError(interp, NULL);
2846 return JIM_ERR;
2847 }
2848
2849 return JimMakeChannelPair(interp, p, argv[0], "aio.pipe%ld", 0, mode);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2850 }
2851 #endif
2852
2853
2854
@@ -2868,13 +3413,13 @@
2868 #ifdef HAVE_PIPE
2869 Jim_CreateCommand(interp, "pipe", JimAioPipeCommand, NULL, NULL);
2870 #endif
2871
2872
2873 JimMakeChannel(interp, stdin, -1, NULL, "stdin", 0, "r");
2874 JimMakeChannel(interp, stdout, -1, NULL, "stdout", 0, "w");
2875 JimMakeChannel(interp, stderr, -1, NULL, "stderr", 0, "w");
2876
2877 return JIM_OK;
2878 }
2879
2880 #include <errno.h>
@@ -2932,13 +3477,11 @@
2932 }
2933 }
2934
2935 int Jim_readdirInit(Jim_Interp *interp)
2936 {
2937 if (Jim_PackageProvide(interp, "readdir", "1.0", JIM_ERRMSG))
2938 return JIM_ERR;
2939
2940 Jim_CreateCommand(interp, "readdir", Jim_ReaddirCmd, NULL, NULL);
2941 return JIM_OK;
2942 }
2943
2944 #include <stdlib.h>
@@ -2945,15 +3488,19 @@
2945 #include <string.h>
2946
2947 #if defined(JIM_REGEXP)
2948 #else
2949 #include <regex.h>
 
 
 
 
2950 #endif
2951
2952 static void FreeRegexpInternalRep(Jim_Interp *interp, Jim_Obj *objPtr)
2953 {
2954 regfree(objPtr->internalRep.ptrIntValue.ptr);
2955 Jim_Free(objPtr->internalRep.ptrIntValue.ptr);
2956 }
2957
2958 static const Jim_ObjType regexpObjType = {
2959 "regexp",
@@ -2980,16 +3527,16 @@
2980
2981
2982 pattern = Jim_String(objPtr);
2983 compre = Jim_Alloc(sizeof(regex_t));
2984
2985 if ((ret = regcomp(compre, pattern, REG_EXTENDED | flags)) != 0) {
2986 char buf[100];
2987
2988 regerror(ret, compre, buf, sizeof(buf));
2989 Jim_SetResultFormatted(interp, "couldn't compile regular expression pattern: %s", buf);
2990 regfree(compre);
2991 Jim_Free(compre);
2992 return NULL;
2993 }
2994
2995 Jim_FreeIntRep(interp, objPtr);
@@ -3110,25 +3657,25 @@
3110 }
3111 if (offset > source_len) {
3112 source_str += source_len;
3113 }
3114 else if (offset > 0) {
3115 source_str += offset;
3116 }
3117 eflags |= REG_NOTBOL;
3118 }
3119
3120 if (opt_inline) {
3121 resultListObj = Jim_NewListObj(interp, NULL, 0);
3122 }
3123
3124 next_match:
3125 match = regexec(regex, source_str, num_vars + 1, pmatch, eflags);
3126 if (match >= REG_BADPAT) {
3127 char buf[100];
3128
3129 regerror(match, regex, buf, sizeof(buf));
3130 Jim_SetResultFormatted(interp, "error while matching pattern: %s", buf);
3131 result = JIM_ERR;
3132 goto done;
3133 }
3134
@@ -3160,20 +3707,19 @@
3160 Jim_ListAppendElement(interp, resultObj, Jim_NewIntObj(interp, -1));
3161 Jim_ListAppendElement(interp, resultObj, Jim_NewIntObj(interp, -1));
3162 }
3163 }
3164 else {
3165 int len = pmatch[j].rm_eo - pmatch[j].rm_so;
3166
3167 if (opt_indices) {
3168 Jim_ListAppendElement(interp, resultObj, Jim_NewIntObj(interp,
3169 offset + pmatch[j].rm_so));
3170 Jim_ListAppendElement(interp, resultObj, Jim_NewIntObj(interp,
3171 offset + pmatch[j].rm_so + len - 1));
 
3172 }
3173 else {
3174 Jim_AppendString(interp, resultObj, source_str + pmatch[j].rm_so, len);
3175 }
3176 }
3177
3178 if (opt_inline) {
3179 Jim_ListAppendElement(interp, resultListObj, resultObj);
@@ -3190,11 +3736,11 @@
3190 }
3191
3192 try_next_match:
3193 if (opt_all && (pattern[0] != '^' || (regcomp_flags & REG_NEWLINE)) && *source_str) {
3194 if (pmatch[0].rm_eo) {
3195 offset += pmatch[0].rm_eo;
3196 source_str += pmatch[0].rm_eo;
3197 }
3198 else {
3199 source_str++;
3200 offset++;
@@ -3319,23 +3865,25 @@
3319 else if (offset < 0) {
3320 offset = 0;
3321 }
3322 }
3323
 
 
3324
3325 Jim_AppendString(interp, resultObj, source_str, offset);
3326
3327
3328 n = source_len - offset;
3329 p = source_str + offset;
3330 do {
3331 int match = regexec(regex, p, MAX_SUB_MATCHES, pmatch, regexec_flags);
3332
3333 if (match >= REG_BADPAT) {
3334 char buf[100];
3335
3336 regerror(match, regex, buf, sizeof(buf));
3337 Jim_SetResultFormatted(interp, "error while matching pattern: %s", buf);
3338 return JIM_ERR;
3339 }
3340 if (match == REG_NOMATCH) {
3341 break;
@@ -3396,11 +3944,18 @@
3396 Jim_AppendString(interp, resultObj, p, 1);
3397 p++;
3398 n--;
3399 }
3400
3401 regexec_flags |= REG_NOTBOL;
 
 
 
 
 
 
 
3402 } while (n);
3403
3404 Jim_AppendString(interp, resultObj, p, -1);
3405
3406
@@ -3422,13 +3977,11 @@
3422 return result;
3423 }
3424
3425 int Jim_regexpInit(Jim_Interp *interp)
3426 {
3427 if (Jim_PackageProvide(interp, "regexp", "1.0", JIM_ERRMSG))
3428 return JIM_ERR;
3429
3430 Jim_CreateCommand(interp, "regexp", Jim_RegexpCmd, NULL, NULL);
3431 Jim_CreateCommand(interp, "regsub", Jim_RegsubCmd, NULL, NULL);
3432 return JIM_OK;
3433 }
3434
@@ -3435,11 +3988,10 @@
3435 #include <limits.h>
3436 #include <stdlib.h>
3437 #include <string.h>
3438 #include <stdio.h>
3439 #include <errno.h>
3440 #include <sys/stat.h>
3441
3442
3443 #ifdef HAVE_UTIMES
3444 #include <sys/time.h>
3445 #endif
@@ -3453,15 +4005,21 @@
3453 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
3454 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
3455 #endif
3456
3457 # ifndef MAXPATHLEN
 
 
 
3458 # define MAXPATHLEN JIM_PATH_LEN
 
3459 # endif
3460
3461 #if defined(__MINGW32__) || defined(__MSYS__) || defined(_MSC_VER)
3462 #define ISWINDOWS 1
 
 
3463 #else
3464 #define ISWINDOWS 0
3465 #endif
3466
3467
@@ -3469,10 +4027,22 @@
3469 #define STAT_MTIME_US(STAT) ((STAT).st_mtimespec.tv_sec * 1000000ll + (STAT).st_mtimespec.tv_nsec / 1000)
3470 #elif defined(HAVE_STRUCT_STAT_ST_MTIM)
3471 #define STAT_MTIME_US(STAT) ((STAT).st_mtim.tv_sec * 1000000ll + (STAT).st_mtim.tv_nsec / 1000)
3472 #endif
3473
 
 
 
 
 
 
 
 
 
 
 
 
3474
3475 static const char *JimGetFileType(int mode)
3476 {
3477 if (S_ISREG(mode)) {
3478 return "file";
@@ -3512,11 +4082,11 @@
3512 {
3513 Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, key, -1));
3514 Jim_ListAppendElement(interp, listObj, Jim_NewIntObj(interp, value));
3515 }
3516
3517 static int StoreStatData(Jim_Interp *interp, Jim_Obj *varName, const struct stat *sb)
3518 {
3519
3520 Jim_Obj *listObj = Jim_NewListObj(interp, NULL, 0);
3521
3522 AppendStatElement(interp, listObj, "dev", sb->st_dev);
@@ -3565,31 +4135,91 @@
3565
3566 Jim_SetResult(interp, listObj);
3567
3568 return JIM_OK;
3569 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3570
3571 static int file_cmd_dirname(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
3572 {
3573 const char *path = Jim_String(argv[0]);
 
3574 const char *p = strrchr(path, '/');
3575
3576 if (!p && path[0] == '.' && path[1] == '.' && path[2] == '\0') {
3577 Jim_SetResultString(interp, "..", -1);
3578 } else if (!p) {
3579 Jim_SetResultString(interp, ".", -1);
3580 }
 
 
 
 
3581 else if (p == path) {
3582 Jim_SetResultString(interp, "/", -1);
3583 }
3584 else if (ISWINDOWS && p[-1] == ':') {
3585
3586 Jim_SetResultString(interp, path, p - path + 1);
3587 }
3588 else {
3589 Jim_SetResultString(interp, path, p - path);
 
 
3590 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3591 return JIM_OK;
3592 }
3593
3594 static int file_cmd_rootname(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
3595 {
@@ -3606,54 +4236,67 @@
3606 return JIM_OK;
3607 }
3608
3609 static int file_cmd_extension(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
3610 {
3611 const char *path = Jim_String(argv[0]);
 
3612 const char *lastSlash = strrchr(path, '/');
3613 const char *p = strrchr(path, '.');
3614
3615 if (p == NULL || (lastSlash != NULL && lastSlash >= p)) {
3616 p = "";
3617 }
3618 Jim_SetResultString(interp, p, -1);
 
3619 return JIM_OK;
3620 }
3621
3622 static int file_cmd_tail(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
3623 {
3624 const char *path = Jim_String(argv[0]);
 
3625 const char *lastSlash = strrchr(path, '/');
3626
3627 if (lastSlash) {
3628 Jim_SetResultString(interp, lastSlash + 1, -1);
3629 }
3630 else {
3631 Jim_SetResult(interp, argv[0]);
3632 }
 
3633 return JIM_OK;
3634 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3635
3636 static int file_cmd_normalize(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
3637 {
3638 #ifdef HAVE_REALPATH
3639 const char *path = Jim_String(argv[0]);
3640 char *newname = Jim_Alloc(MAXPATHLEN + 1);
3641
3642 if (realpath(path, newname)) {
 
3643 Jim_SetResult(interp, Jim_NewStringObjNoAlloc(interp, newname, -1));
3644 return JIM_OK;
3645 }
3646 else {
3647 Jim_Free(newname);
3648 Jim_SetResultFormatted(interp, "can't normalize \"%#s\": %s", argv[0], strerror(errno));
3649 return JIM_ERR;
3650 }
3651 #else
3652 Jim_SetResultString(interp, "Not implemented", -1);
3653 return JIM_ERR;
3654 #endif
3655 }
3656
3657 static int file_cmd_join(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
3658 {
3659 int i;
@@ -3755,12 +4398,12 @@
3755 static int file_cmd_delete(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
3756 {
3757 int force = Jim_CompareStringImmediate(interp, argv[0], "-force");
3758
3759 if (force || Jim_CompareStringImmediate(interp, argv[0], "--")) {
3760 argc++;
3761 argv--;
3762 }
3763
3764 while (argc--) {
3765 const char *path = Jim_String(argv[0]);
3766
@@ -3813,13 +4456,13 @@
3813
3814 continue;
3815 }
3816
3817 if (errno == EEXIST) {
3818 struct stat sb;
3819
3820 if (stat(path, &sb) == 0 && S_ISDIR(sb.st_mode)) {
3821 return 0;
3822 }
3823
3824 errno = EEXIST;
3825 }
@@ -3879,11 +4522,16 @@
3879 if (!force && access(dest, F_OK) == 0) {
3880 Jim_SetResultFormatted(interp, "error renaming \"%#s\" to \"%#s\": target exists", argv[0],
3881 argv[1]);
3882 return JIM_ERR;
3883 }
 
 
3884
 
 
 
3885 if (rename(source, dest) != 0) {
3886 Jim_SetResultFormatted(interp, "error renaming \"%#s\" to \"%#s\": %s", argv[0], argv[1],
3887 strerror(errno));
3888 return JIM_ERR;
3889 }
@@ -3927,27 +4575,27 @@
3927
3928 return JIM_OK;
3929 }
3930 #endif
3931
3932 static int file_stat(Jim_Interp *interp, Jim_Obj *filename, struct stat *sb)
3933 {
3934 const char *path = Jim_String(filename);
3935
3936 if (stat(path, sb) == -1) {
3937 Jim_SetResultFormatted(interp, "could not read \"%#s\": %s", filename, strerror(errno));
3938 return JIM_ERR;
3939 }
3940 return JIM_OK;
3941 }
3942
3943 #ifdef HAVE_LSTAT
3944 static int file_lstat(Jim_Interp *interp, Jim_Obj *filename, struct stat *sb)
3945 {
3946 const char *path = Jim_String(filename);
3947
3948 if (lstat(path, sb) == -1) {
3949 Jim_SetResultFormatted(interp, "could not read \"%#s\": %s", filename, strerror(errno));
3950 return JIM_ERR;
3951 }
3952 return JIM_OK;
3953 }
@@ -3955,11 +4603,11 @@
3955 #define file_lstat file_stat
3956 #endif
3957
3958 static int file_cmd_atime(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
3959 {
3960 struct stat sb;
3961
3962 if (file_stat(interp, argv[0], &sb) != JIM_OK) {
3963 return JIM_ERR;
3964 }
3965 Jim_SetResultInt(interp, sb.st_atime);
@@ -3985,11 +4633,11 @@
3985 #endif
3986 }
3987
3988 static int file_cmd_mtime(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
3989 {
3990 struct stat sb;
3991
3992 if (argc == 2) {
3993 jim_wide secs;
3994 if (Jim_GetWide(interp, argv[1], &secs) != JIM_OK) {
3995 return JIM_ERR;
@@ -4004,11 +4652,11 @@
4004 }
4005
4006 #ifdef STAT_MTIME_US
4007 static int file_cmd_mtimeus(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
4008 {
4009 struct stat sb;
4010
4011 if (argc == 2) {
4012 jim_wide us;
4013 if (Jim_GetWide(interp, argv[1], &us) != JIM_OK) {
4014 return JIM_ERR;
@@ -4028,11 +4676,11 @@
4028 return Jim_EvalPrefix(interp, "file copy", argc, argv);
4029 }
4030
4031 static int file_cmd_size(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
4032 {
4033 struct stat sb;
4034
4035 if (file_stat(interp, argv[0], &sb) != JIM_OK) {
4036 return JIM_ERR;
4037 }
4038 Jim_SetResultInt(interp, sb.st_size);
@@ -4039,11 +4687,11 @@
4039 return JIM_OK;
4040 }
4041
4042 static int file_cmd_isdirectory(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
4043 {
4044 struct stat sb;
4045 int ret = 0;
4046
4047 if (file_stat(interp, argv[0], &sb) == JIM_OK) {
4048 ret = S_ISDIR(sb.st_mode);
4049 }
@@ -4051,11 +4699,11 @@
4051 return JIM_OK;
4052 }
4053
4054 static int file_cmd_isfile(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
4055 {
4056 struct stat sb;
4057 int ret = 0;
4058
4059 if (file_stat(interp, argv[0], &sb) == JIM_OK) {
4060 ret = S_ISREG(sb.st_mode);
4061 }
@@ -4064,11 +4712,11 @@
4064 }
4065
4066 #ifdef HAVE_GETEUID
4067 static int file_cmd_owned(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
4068 {
4069 struct stat sb;
4070 int ret = 0;
4071
4072 if (file_stat(interp, argv[0], &sb) == JIM_OK) {
4073 ret = (geteuid() == sb.st_uid);
4074 }
@@ -4085,11 +4733,11 @@
4085
4086 int linkLength = readlink(path, linkValue, MAXPATHLEN);
4087
4088 if (linkLength == -1) {
4089 Jim_Free(linkValue);
4090 Jim_SetResultFormatted(interp, "couldn't readlink \"%#s\": %s", argv[0], strerror(errno));
4091 return JIM_ERR;
4092 }
4093 linkValue[linkLength] = 0;
4094 Jim_SetResult(interp, Jim_NewStringObjNoAlloc(interp, linkValue, linkLength));
4095 return JIM_OK;
@@ -4096,41 +4744,41 @@
4096 }
4097 #endif
4098
4099 static int file_cmd_type(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
4100 {
4101 struct stat sb;
4102
4103 if (file_lstat(interp, argv[0], &sb) != JIM_OK) {
4104 return JIM_ERR;
4105 }
4106 Jim_SetResultString(interp, JimGetFileType((int)sb.st_mode), -1);
4107 return JIM_OK;
4108 }
4109
4110 #ifdef HAVE_LSTAT
4111 static int file_cmd_lstat(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
4112 {
4113 struct stat sb;
4114
4115 if (file_lstat(interp, argv[0], &sb) != JIM_OK) {
4116 return JIM_ERR;
4117 }
4118 return StoreStatData(interp, argc == 2 ? argv[1] : NULL, &sb);
4119 }
4120 #else
4121 #define file_cmd_lstat file_cmd_stat
4122 #endif
4123
4124 static int file_cmd_stat(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
4125 {
4126 struct stat sb;
4127
4128 if (file_stat(interp, argv[0], &sb) != JIM_OK) {
4129 return JIM_ERR;
4130 }
4131 return StoreStatData(interp, argc == 2 ? argv[1] : NULL, &sb);
4132 }
4133
4134 static const jim_subcmd_type file_command_table[] = {
4135 { "atime",
4136 "name",
@@ -4187,10 +4835,17 @@
4187 "name",
4188 file_cmd_tail,
4189 1,
4190 1,
4191
 
 
 
 
 
 
 
4192 },
4193 { "normalize",
4194 "name",
4195 file_cmd_normalize,
4196 1,
@@ -4360,43 +5015,31 @@
4360 if (getcwd(cwd, MAXPATHLEN) == NULL) {
4361 Jim_SetResultString(interp, "Failed to get pwd", -1);
4362 Jim_Free(cwd);
4363 return JIM_ERR;
4364 }
4365 else if (ISWINDOWS) {
4366
4367 char *p = cwd;
4368 while ((p = strchr(p, '\\')) != NULL) {
4369 *p++ = '/';
4370 }
4371 }
4372
4373 Jim_SetResultString(interp, cwd, -1);
4374
4375 Jim_Free(cwd);
4376 return JIM_OK;
4377 }
4378
4379 int Jim_fileInit(Jim_Interp *interp)
4380 {
4381 if (Jim_PackageProvide(interp, "file", "1.0", JIM_ERRMSG))
4382 return JIM_ERR;
4383
4384 Jim_CreateCommand(interp, "file", Jim_SubCmdProc, (void *)file_command_table, NULL);
4385 Jim_CreateCommand(interp, "pwd", Jim_PwdCmd, NULL, NULL);
4386 Jim_CreateCommand(interp, "cd", Jim_CdCmd, NULL, NULL);
4387 return JIM_OK;
4388 }
4389
4390 #ifndef _GNU_SOURCE
4391 #define _GNU_SOURCE
4392 #endif
4393 #include <string.h>
4394 #include <ctype.h>
4395
4396
4397 #if (!defined(HAVE_VFORK) || !defined(HAVE_WAITPID)) && !defined(__MINGW32__)
4398 static int Jim_ExecCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
4399 {
4400 Jim_Obj *cmdlineObj = Jim_NewEmptyStringObj(interp);
4401 int i, j;
4402 int rc;
@@ -4440,13 +5083,11 @@
4440 return JIM_OK;
4441 }
4442
4443 int Jim_execInit(Jim_Interp *interp)
4444 {
4445 if (Jim_PackageProvide(interp, "exec", "1.0", JIM_ERRMSG))
4446 return JIM_ERR;
4447
4448 Jim_CreateCommand(interp, "exec", Jim_ExecCmd, NULL, NULL);
4449 return JIM_OK;
4450 }
4451 #else
4452
@@ -4459,17 +5100,17 @@
4459
4460 static char **JimOriginalEnviron(void);
4461 static char **JimSaveEnv(char **env);
4462 static void JimRestoreEnv(char **env);
4463 static int JimCreatePipeline(Jim_Interp *interp, int argc, Jim_Obj *const *argv,
4464 pidtype **pidArrayPtr, int *inPipePtr, int *outPipePtr, int *errFilePtr);
4465 static void JimDetachPids(struct WaitInfoTable *table, int numPids, const pidtype *pidPtr);
4466 static int JimCleanupChildren(Jim_Interp *interp, int numPids, pidtype *pidPtr, Jim_Obj *errStrObj);
4467 static int Jim_WaitCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv);
4468
4469 #if defined(__MINGW32__)
4470 static pidtype JimStartWinProcess(Jim_Interp *interp, char **argv, char **env, int inputId, int outputId, int errorId);
4471 #endif
4472
4473 static void Jim_RemoveTrailingNewline(Jim_Obj *objPtr)
4474 {
4475 int len;
@@ -4482,28 +5123,23 @@
4482 }
4483
4484 static int JimAppendStreamToString(Jim_Interp *interp, int fd, Jim_Obj *strObj)
4485 {
4486 char buf[256];
4487 FILE *fh = fdopen(fd, "r");
4488 int ret = 0;
4489
4490 if (fh == NULL) {
4491 return -1;
4492 }
4493
4494 while (1) {
4495 int retval = fread(buf, 1, sizeof(buf), fh);
4496 if (retval > 0) {
4497 ret = 1;
4498 Jim_AppendString(interp, strObj, buf, retval);
4499 }
4500 if (retval != sizeof(buf)) {
4501 break;
4502 }
4503 }
4504 fclose(fh);
4505 return ret;
4506 }
4507
4508 static char **JimBuildEnv(Jim_Interp *interp)
4509 {
@@ -4558,22 +5194,22 @@
4558 if (env != original_environ) {
4559 Jim_Free(env);
4560 }
4561 }
4562
4563 static Jim_Obj *JimMakeErrorCode(Jim_Interp *interp, pidtype pid, int waitStatus, Jim_Obj *errStrObj)
4564 {
4565 Jim_Obj *errorCode = Jim_NewListObj(interp, NULL, 0);
4566
4567 if (pid == JIM_BAD_PID || pid == JIM_NO_PID) {
4568 Jim_ListAppendElement(interp, errorCode, Jim_NewStringObj(interp, "NONE", -1));
4569 Jim_ListAppendElement(interp, errorCode, Jim_NewIntObj(interp, (long)pid));
4570 Jim_ListAppendElement(interp, errorCode, Jim_NewIntObj(interp, -1));
4571 }
4572 else if (WIFEXITED(waitStatus)) {
4573 Jim_ListAppendElement(interp, errorCode, Jim_NewStringObj(interp, "CHILDSTATUS", -1));
4574 Jim_ListAppendElement(interp, errorCode, Jim_NewIntObj(interp, (long)pid));
4575 Jim_ListAppendElement(interp, errorCode, Jim_NewIntObj(interp, WEXITSTATUS(waitStatus)));
4576 }
4577 else {
4578 const char *type;
4579 const char *action;
@@ -4594,17 +5230,17 @@
4594
4595 if (errStrObj) {
4596 Jim_AppendStrings(interp, errStrObj, "child ", action, " by signal ", Jim_SignalId(WTERMSIG(waitStatus)), "\n", NULL);
4597 }
4598
4599 Jim_ListAppendElement(interp, errorCode, Jim_NewIntObj(interp, (long)pid));
4600 Jim_ListAppendElement(interp, errorCode, Jim_NewStringObj(interp, signame, -1));
4601 }
4602 return errorCode;
4603 }
4604
4605 static int JimCheckWaitStatus(Jim_Interp *interp, pidtype pid, int waitStatus, Jim_Obj *errStrObj)
4606 {
4607 if (WIFEXITED(waitStatus) && WEXITSTATUS(waitStatus) == 0) {
4608 return JIM_OK;
4609 }
4610 Jim_SetGlobalVariableStr(interp, "errorCode", JimMakeErrorCode(interp, pid, waitStatus, errStrObj));
@@ -4613,11 +5249,11 @@
4613 }
4614
4615
4616 struct WaitInfo
4617 {
4618 pidtype pid;
4619 int status;
4620 int flags;
4621 };
4622
4623
@@ -4651,17 +5287,17 @@
4651 table->refcount = 1;
4652
4653 return table;
4654 }
4655
4656 static int JimWaitRemove(struct WaitInfoTable *table, pidtype pid)
4657 {
4658 int i;
4659
4660
4661 for (i = 0; i < table->used; i++) {
4662 if (pid == table->info[i].pid) {
4663 if (i != table->used - 1) {
4664 table->info[i] = table->info[table->used - 1];
4665 }
4666 table->used--;
4667 return 0;
@@ -4672,11 +5308,11 @@
4672
4673 static int Jim_ExecCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
4674 {
4675 int outputId;
4676 int errorId;
4677 pidtype *pidPtr;
4678 int numPids, result;
4679 int child_siginfo = 1;
4680 Jim_Obj *childErrObj;
4681 Jim_Obj *errStrObj;
4682 struct WaitInfoTable *table = Jim_CmdPrivData(interp);
@@ -4691,11 +5327,11 @@
4691 return JIM_ERR;
4692 }
4693
4694 listObj = Jim_NewListObj(interp, NULL, 0);
4695 for (i = 0; i < numPids; i++) {
4696 Jim_ListAppendElement(interp, listObj, Jim_NewIntObj(interp, (long)pidPtr[i]));
4697 }
4698 Jim_SetResult(interp, listObj);
4699 JimDetachPids(table, numPids, pidPtr);
4700 Jim_Free(pidPtr);
4701 return JIM_OK;
@@ -4728,11 +5364,11 @@
4728 result = JIM_ERR;
4729 }
4730
4731 if (errorId != -1) {
4732 int ret;
4733 lseek(errorId, 0, SEEK_SET);
4734 ret = JimAppendStreamToString(interp, errorId, errStrObj);
4735 if (ret < 0) {
4736 Jim_SetResultErrno(interp, "error reading from error pipe");
4737 result = JIM_ERR;
4738 }
@@ -4755,31 +5391,30 @@
4755 Jim_SetResult(interp, errStrObj);
4756
4757 return result;
4758 }
4759
4760 static pidtype JimWaitForProcess(struct WaitInfoTable *table, pidtype pid, int *statusPtr)
4761 {
4762 if (JimWaitRemove(table, pid) == 0) {
4763
4764 waitpid(pid, statusPtr, 0);
4765 return pid;
4766 }
4767
4768
4769 return JIM_BAD_PID;
4770 }
4771
4772 static void JimDetachPids(struct WaitInfoTable *table, int numPids, const pidtype *pidPtr)
4773 {
4774 int j;
4775
4776 for (j = 0; j < numPids; j++) {
4777
4778 int i;
4779 for (i = 0; i < table->used; i++) {
4780 if (pidPtr[j] == table->info[i].pid) {
4781 table->info[i].flags |= WI_DETACHED;
4782 break;
4783 }
4784 }
4785 }
@@ -4814,12 +5449,12 @@
4814 waitPtr = table->info;
4815 dest = 0;
4816 for (count = table->used; count > 0; waitPtr++, count--) {
4817 if (waitPtr->flags & WI_DETACHED) {
4818 int status;
4819 pidtype pid = waitpid(waitPtr->pid, &status, WNOHANG);
4820 if (pid == waitPtr->pid) {
4821
4822 table->used--;
4823 continue;
4824 }
4825 }
@@ -4832,12 +5467,12 @@
4832
4833 static int Jim_WaitCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
4834 {
4835 struct WaitInfoTable *table = Jim_CmdPrivData(interp);
4836 int nohang = 0;
4837 pidtype pid;
4838 long pidarg;
4839 int status;
4840 Jim_Obj *errCodeObj;
4841
4842
4843 if (argc == 1) {
@@ -4850,21 +5485,30 @@
4850 }
4851 if (argc != nohang + 2) {
4852 Jim_WrongNumArgs(interp, 1, argv, "?-nohang? ?pid?");
4853 return JIM_ERR;
4854 }
4855 if (Jim_GetLong(interp, argv[nohang + 1], &pidarg) != JIM_OK) {
4856 return JIM_ERR;
4857 }
4858
4859 pid = waitpid((pidtype)pidarg, &status, nohang ? WNOHANG : 0);
 
 
 
 
 
 
 
 
 
4860
4861 errCodeObj = JimMakeErrorCode(interp, pid, status, NULL);
4862
4863 if (pid != JIM_BAD_PID && (WIFEXITED(status) || WIFSIGNALED(status))) {
4864
4865 JimWaitRemove(table, pid);
4866 }
4867 Jim_SetResult(interp, errCodeObj);
4868 return JIM_OK;
4869 }
4870
@@ -4878,14 +5522,14 @@
4878 Jim_SetResultInt(interp, (jim_wide)getpid());
4879 return JIM_OK;
4880 }
4881
4882 static int
4883 JimCreatePipeline(Jim_Interp *interp, int argc, Jim_Obj *const *argv, pidtype **pidArrayPtr,
4884 int *inPipePtr, int *outPipePtr, int *errFilePtr)
4885 {
4886 pidtype *pidPtr = NULL; /* Points to malloc-ed array holding all
4887 * the pids of child processes. */
4888 int numPids = 0; /* Actual number of processes that exist
4889 * at *pidPtr right now. */
4890 int cmdCount; /* Count of number of distinct commands
4891 * found in argc/argv. */
@@ -4925,13 +5569,13 @@
4925 int pipeIds[2];
4926 int firstArg, lastArg; /* Indexes of first and last arguments in
4927 * current command. */
4928 int lastBar;
4929 int i;
4930 pidtype pid;
4931 char **save_environ;
4932 #ifndef __MINGW32__
4933 char **child_environ;
4934 #endif
4935 struct WaitInfoTable *table = Jim_CmdPrivData(interp);
4936
4937
@@ -5053,11 +5697,11 @@
5053 if (write(inputId, input, input_len) != input_len) {
5054 Jim_SetResultErrno(interp, "couldn't write temp file");
5055 close(inputId);
5056 goto error;
5057 }
5058 lseek(inputId, 0L, SEEK_SET);
5059 }
5060 else if (inputFile == FILE_HANDLE) {
5061 int fd = JimGetChannelFd(interp, input);
5062
5063 if (fd < 0) {
@@ -5145,13 +5789,10 @@
5145 *errFilePtr = dup(errorId);
5146 }
5147
5148
5149 pidPtr = Jim_Alloc(cmdCount * sizeof(*pidPtr));
5150 for (i = 0; i < numPids; i++) {
5151 pidPtr[i] = JIM_BAD_PID;
5152 }
5153 for (firstArg = 0; firstArg < arg_count; numPids++, firstArg = lastArg + 1) {
5154 int pipe_dup_err = 0;
5155 int origErrorId = errorId;
5156
5157 for (lastArg = firstArg; lastArg < arg_count; lastArg++) {
@@ -5189,58 +5830,61 @@
5189 }
5190
5191
5192
5193 #ifdef __MINGW32__
5194 pid = JimStartWinProcess(interp, &arg_array[firstArg], save_environ, inputId, outputId, errorId);
5195 if (pid == JIM_BAD_PID) {
5196 Jim_SetResultFormatted(interp, "couldn't exec \"%s\"", arg_array[firstArg]);
5197 goto error;
5198 }
5199 #else
5200 i = strlen(arg_array[firstArg]);
5201
 
5202 child_environ = Jim_GetEnviron();
5203 pid = vfork();
5204 if (pid < 0) {
 
 
 
 
 
5205 Jim_SetResultErrno(interp, "couldn't fork child process");
5206 goto error;
5207 }
5208 if (pid == 0) {
5209
5210
5211 if (inputId != -1) {
5212 dup2(inputId, fileno(stdin));
5213 close(inputId);
5214 }
5215 if (outputId != -1) {
5216 dup2(outputId, fileno(stdout));
5217 if (outputId != errorId) {
5218 close(outputId);
5219 }
5220 }
5221 if (errorId != -1) {
5222 dup2(errorId, fileno(stderr));
5223 close(errorId);
5224 }
5225
5226 if (outPipePtr) {
5227 close(*outPipePtr);
5228 }
5229 if (errFilePtr) {
5230 close(*errFilePtr);
5231 }
5232 if (pipeIds[0] != -1) {
5233 close(pipeIds[0]);
5234 }
5235 if (lastOutputId != -1) {
5236 close(lastOutputId);
5237 }
5238
5239
5240 (void)signal(SIGPIPE, SIG_DFL);
5241
5242 execvpe(arg_array[firstArg], &arg_array[firstArg], child_environ);
5243
5244 if (write(fileno(stderr), "couldn't exec \"", 15) &&
5245 write(fileno(stderr), arg_array[firstArg], i) &&
5246 write(fileno(stderr), "\"\n", 2)) {
@@ -5262,15 +5906,15 @@
5262 if (table->used == table->size) {
5263 table->size += WAIT_TABLE_GROW_BY;
5264 table->info = Jim_Realloc(table->info, table->size * sizeof(*table->info));
5265 }
5266
5267 table->info[table->used].pid = pid;
5268 table->info[table->used].flags = 0;
5269 table->used++;
5270
5271 pidPtr[numPids] = pid;
5272
5273
5274 errorId = origErrorId;
5275
5276
@@ -5322,11 +5966,11 @@
5322 if (pipeIds[1] != -1) {
5323 close(pipeIds[1]);
5324 }
5325 if (pidPtr != NULL) {
5326 for (i = 0; i < numPids; i++) {
5327 if (pidPtr[i] != JIM_BAD_PID) {
5328 JimDetachPids(table, 1, &pidPtr[i]);
5329 }
5330 }
5331 Jim_Free(pidPtr);
5332 }
@@ -5333,21 +5977,22 @@
5333 numPids = -1;
5334 goto cleanup;
5335 }
5336
5337
5338 static int JimCleanupChildren(Jim_Interp *interp, int numPids, pidtype *pidPtr, Jim_Obj *errStrObj)
5339 {
5340 struct WaitInfoTable *table = Jim_CmdPrivData(interp);
5341 int result = JIM_OK;
5342 int i;
5343
5344
5345 for (i = 0; i < numPids; i++) {
5346 int waitStatus = 0;
5347 if (JimWaitForProcess(table, pidPtr[i], &waitStatus) != JIM_BAD_PID) {
5348 if (JimCheckWaitStatus(interp, pidPtr[i], waitStatus, errStrObj) != JIM_OK) {
 
5349 result = JIM_ERR;
5350 }
5351 }
5352 }
5353 Jim_Free(pidPtr);
@@ -5356,16 +6001,12 @@
5356 }
5357
5358 int Jim_execInit(Jim_Interp *interp)
5359 {
5360 struct WaitInfoTable *waitinfo;
5361 if (Jim_PackageProvide(interp, "exec", "1.0", JIM_ERRMSG))
5362 return JIM_ERR;
5363
5364 #ifdef SIGPIPE
5365 (void)signal(SIGPIPE, SIG_IGN);
5366 #endif
5367
5368 waitinfo = JimAllocWaitInfoTable();
5369 Jim_CreateCommand(interp, "exec", Jim_ExecCmd, waitinfo, JimFreeWaitInfoTable);
5370 waitinfo->refcount++;
5371 Jim_CreateCommand(interp, "wait", Jim_WaitCommand, waitinfo, JimFreeWaitInfoTable);
@@ -5483,23 +6124,23 @@
5483 }
5484 }
5485 return strObj;
5486 }
5487
5488 static pidtype
5489 JimStartWinProcess(Jim_Interp *interp, char **argv, char **env, int inputId, int outputId, int errorId)
5490 {
5491 STARTUPINFO startInfo;
5492 PROCESS_INFORMATION procInfo;
5493 HANDLE hProcess;
5494 char execPath[MAX_PATH];
5495 pidtype pid = JIM_BAD_PID;
5496 Jim_Obj *cmdLineObj;
5497 char *winenv;
5498
5499 if (JimWinFindExecutable(argv[0], execPath) < 0) {
5500 return JIM_BAD_PID;
5501 }
5502 argv[0] = execPath;
5503
5504 hProcess = GetCurrentProcess();
5505 cmdLineObj = JimWinBuildCommandLine(interp, argv);
@@ -5558,11 +6199,11 @@
5558
5559
5560 WaitForInputIdle(procInfo.hProcess, 5000);
5561 CloseHandle(procInfo.hThread);
5562
5563 pid = procInfo.hProcess;
5564
5565 end:
5566 Jim_FreeNewObj(interp, cmdLineObj);
5567 if (startInfo.hStdInput != INVALID_HANDLE_VALUE) {
5568 CloseHandle(startInfo.hStdInput);
@@ -5571,11 +6212,11 @@
5571 CloseHandle(startInfo.hStdOutput);
5572 }
5573 if (startInfo.hStdError != INVALID_HANDLE_VALUE) {
5574 CloseHandle(startInfo.hStdError);
5575 }
5576 return pid;
5577 }
5578
5579 #else
5580
5581 static char **JimOriginalEnviron(void)
@@ -5597,22 +6238,10 @@
5597 }
5598 #endif
5599 #endif
5600
5601
5602
5603 #ifdef STRPTIME_NEEDS_XOPEN_SOURCE
5604 #ifndef _XOPEN_SOURCE
5605 #define _XOPEN_SOURCE 500
5606 #endif
5607 #endif
5608
5609
5610 #ifndef _GNU_SOURCE
5611 #define _GNU_SOURCE
5612 #endif
5613
5614 #include <stdlib.h>
5615 #include <string.h>
5616 #include <stdio.h>
5617 #include <time.h>
5618
@@ -5732,41 +6361,36 @@
5732 }
5733 #endif
5734
5735 static int clock_cmd_seconds(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
5736 {
5737 Jim_SetResultInt(interp, time(NULL));
 
 
5738
 
 
 
5739 return JIM_OK;
5740 }
5741
5742 static int clock_cmd_micros(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
5743 {
5744 struct timeval tv;
5745
5746 gettimeofday(&tv, NULL);
5747
5748 Jim_SetResultInt(interp, (jim_wide) tv.tv_sec * 1000000 + tv.tv_usec);
5749
5750 return JIM_OK;
5751 }
5752
5753 static int clock_cmd_millis(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
5754 {
5755 struct timeval tv;
5756
5757 gettimeofday(&tv, NULL);
5758
5759 Jim_SetResultInt(interp, (jim_wide) tv.tv_sec * 1000 + tv.tv_usec / 1000);
5760
5761 return JIM_OK;
5762 }
5763
5764 static const jim_subcmd_type clock_command_table[] = {
5765 { "clicks",
5766 NULL,
5767 clock_cmd_micros,
5768 0,
5769 0,
5770
5771 },
5772 { "format",
@@ -5809,13 +6433,11 @@
5809 { NULL }
5810 };
5811
5812 int Jim_clockInit(Jim_Interp *interp)
5813 {
5814 if (Jim_PackageProvide(interp, "clock", "1.0", JIM_ERRMSG))
5815 return JIM_ERR;
5816
5817 Jim_CreateCommand(interp, "clock", Jim_SubCmdProc, (void *)clock_command_table, NULL);
5818 return JIM_OK;
5819 }
5820
5821 #include <limits.h>
@@ -5886,11 +6508,12 @@
5886 if (objPtr == NULL) {
5887
5888 return JIM_OK;
5889 }
5890
5891 if (Jim_DictPairs(interp, objPtr, &dictValuesObj, &len) != JIM_OK) {
 
5892
5893 Jim_SetResultString(interp, "", -1);
5894 return JIM_OK;
5895 }
5896
@@ -5900,11 +6523,10 @@
5900 for (i = 0; i < len; i += 2) {
5901 if (!Jim_StringMatchObj(interp, argv[1], dictValuesObj[i], 0)) {
5902 Jim_DictAddElement(interp, resultObj, dictValuesObj[i], dictValuesObj[i + 1]);
5903 }
5904 }
5905 Jim_Free(dictValuesObj);
5906
5907 Jim_SetVariable(interp, argv[0], resultObj);
5908 return JIM_OK;
5909 }
5910
@@ -6031,25 +6653,71 @@
6031 }
6032 };
6033
6034 int Jim_arrayInit(Jim_Interp *interp)
6035 {
6036 if (Jim_PackageProvide(interp, "array", "1.0", JIM_ERRMSG))
6037 return JIM_ERR;
6038
6039 Jim_CreateCommand(interp, "array", Jim_SubCmdProc, (void *)array_command_table, NULL);
6040 return JIM_OK;
6041 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6042 int Jim_InitStaticExtensions(Jim_Interp *interp)
6043 {
6044 extern int Jim_bootstrapInit(Jim_Interp *);
6045 extern int Jim_aioInit(Jim_Interp *);
6046 extern int Jim_readdirInit(Jim_Interp *);
6047 extern int Jim_regexpInit(Jim_Interp *);
6048 extern int Jim_fileInit(Jim_Interp *);
6049 extern int Jim_globInit(Jim_Interp *);
6050 extern int Jim_execInit(Jim_Interp *);
 
6051 extern int Jim_clockInit(Jim_Interp *);
6052 extern int Jim_arrayInit(Jim_Interp *);
6053 extern int Jim_stdlibInit(Jim_Interp *);
6054 extern int Jim_tclcompatInit(Jim_Interp *);
6055 Jim_bootstrapInit(interp);
@@ -6057,20 +6725,18 @@
6057 Jim_readdirInit(interp);
6058 Jim_regexpInit(interp);
6059 Jim_fileInit(interp);
6060 Jim_globInit(interp);
6061 Jim_execInit(interp);
 
6062 Jim_clockInit(interp);
6063 Jim_arrayInit(interp);
6064 Jim_stdlibInit(interp);
6065 Jim_tclcompatInit(interp);
6066 return JIM_OK;
6067 }
6068 #define JIM_OPTIMIZATION
6069 #ifndef _GNU_SOURCE
6070 #define _GNU_SOURCE
6071 #endif
6072
6073 #include <stdio.h>
6074 #include <stdlib.h>
6075
6076 #include <string.h>
@@ -6084,11 +6750,11 @@
6084
6085
6086 #ifdef HAVE_SYS_TIME_H
6087 #include <sys/time.h>
6088 #endif
6089 #ifdef HAVE_BACKTRACE
6090 #include <execinfo.h>
6091 #endif
6092 #ifdef HAVE_CRT_EXTERNS_H
6093 #include <crt_externs.h>
6094 #endif
@@ -6136,10 +6802,11 @@
6136 #else
6137 #define JimPanic(X)
6138 #endif
6139
6140 #ifdef JIM_OPTIMIZATION
 
6141 #define JIM_IF_OPTIM(X) X
6142 #else
6143 #define JIM_IF_OPTIM(X)
6144 #endif
6145
@@ -6147,22 +6814,29 @@
6147 static char JimEmptyStringRep[] = "";
6148
6149 static void JimFreeCallFrame(Jim_Interp *interp, Jim_CallFrame *cf, int action);
6150 static int ListSetIndex(Jim_Interp *interp, Jim_Obj *listPtr, int listindex, Jim_Obj *newObjPtr,
6151 int flags);
 
 
6152 static int JimDeleteLocalProcs(Jim_Interp *interp, Jim_Stack *localCommands);
6153 static Jim_Obj *JimExpandDictSugar(Jim_Interp *interp, Jim_Obj *objPtr);
6154 static void SetDictSubstFromAny(Jim_Interp *interp, Jim_Obj *objPtr);
6155 static Jim_Obj **JimDictPairs(Jim_Obj *dictPtr, int *len);
6156 static void JimSetFailedEnumResult(Jim_Interp *interp, const char *arg, const char *badtype,
6157 const char *prefix, const char *const *tablePtr, const char *name);
6158 static int JimCallProcedure(Jim_Interp *interp, Jim_Cmd *cmd, int argc, Jim_Obj *const *argv);
6159 static int JimGetWideNoErr(Jim_Interp *interp, Jim_Obj *objPtr, jim_wide * widePtr);
6160 static int JimSign(jim_wide w);
6161 static int JimValidName(Jim_Interp *interp, const char *type, Jim_Obj *nameObjPtr);
6162 static void JimPrngSeed(Jim_Interp *interp, unsigned char *seed, int seedLen);
6163 static void JimRandomBytes(Jim_Interp *interp, void *dest, unsigned int len);
 
 
 
 
 
 
 
6164
6165
6166
6167 #define JimWideValue(objPtr) (objPtr)->internalRep.wideValue
6168
@@ -6175,20 +6849,32 @@
6175 *uc = utf8_upper(*uc);
6176 }
6177 return l;
6178 }
6179
 
 
 
 
 
 
 
 
 
 
 
6180
6181 #define JIM_CHARSET_SCAN 2
6182 #define JIM_CHARSET_GLOB 0
6183
6184 static const char *JimCharsetMatch(const char *pattern, int c, int flags)
6185 {
6186 int not = 0;
6187 int pchar;
6188 int match = 0;
6189 int nocase = 0;
 
6190
6191 if (flags & JIM_NOCASE) {
6192 nocase++;
6193 c = utf8_upper(c);
6194 }
@@ -6195,34 +6881,40 @@
6195
6196 if (flags & JIM_CHARSET_SCAN) {
6197 if (*pattern == '^') {
6198 not++;
6199 pattern++;
 
6200 }
6201
6202
6203 if (*pattern == ']') {
6204 goto first;
6205 }
6206 }
6207
6208 while (*pattern && *pattern != ']') {
6209
6210 if (pattern[0] == '\\') {
6211 first:
6212 pattern += utf8_tounicode_case(pattern, &pchar, nocase);
 
 
6213 }
6214 else {
6215
6216 int start;
6217 int end;
6218
6219 pattern += utf8_tounicode_case(pattern, &start, nocase);
6220 if (pattern[0] == '-' && pattern[1]) {
 
 
6221
6222 pattern++;
6223 pattern += utf8_tounicode_case(pattern, &end, nocase);
 
6224
6225
6226 if ((c >= start && c <= end) || (c >= end && c <= start)) {
6227 match = 1;
6228 }
@@ -6242,108 +6934,115 @@
6242 return match ? pattern : NULL;
6243 }
6244
6245
6246
6247 static int JimGlobMatch(const char *pattern, const char *string, int nocase)
6248 {
6249 int c;
6250 int pchar;
6251 while (*pattern) {
6252 switch (pattern[0]) {
6253 case '*':
6254 while (pattern[1] == '*') {
6255 pattern++;
6256 }
6257 pattern++;
6258 if (!pattern[0]) {
6259 return 1;
6260 }
6261 while (*string) {
6262
6263 if (JimGlobMatch(pattern, string, nocase))
6264 return 1;
6265 string += utf8_tounicode(string, &c);
 
 
 
 
 
 
6266 }
6267 return 0;
6268
6269 case '?':
6270 string += utf8_tounicode(string, &c);
 
 
6271 break;
6272
6273 case '[': {
6274 string += utf8_tounicode(string, &c);
6275 pattern = JimCharsetMatch(pattern + 1, c, nocase ? JIM_NOCASE : 0);
6276 if (!pattern) {
 
 
6277 return 0;
6278 }
6279 if (!*pattern) {
 
 
 
6280
6281 continue;
6282 }
6283 break;
6284 }
6285 case '\\':
6286 if (pattern[1]) {
6287 pattern++;
 
6288 }
6289
6290 default:
6291 string += utf8_tounicode_case(string, &c, nocase);
 
 
6292 utf8_tounicode_case(pattern, &pchar, nocase);
6293 if (pchar != c) {
6294 return 0;
6295 }
6296 break;
6297 }
6298 pattern += utf8_tounicode_case(pattern, &pchar, nocase);
6299 if (!*string) {
6300 while (*pattern == '*') {
 
 
6301 pattern++;
 
6302 }
6303 break;
6304 }
6305 }
6306 if (!*pattern && !*string) {
6307 return 1;
6308 }
6309 return 0;
6310 }
6311
6312 static int JimStringCompare(const char *s1, int l1, const char *s2, int l2)
6313 {
6314 if (l1 < l2) {
6315 return memcmp(s1, s2, l1) <= 0 ? -1 : 1;
6316 }
6317 else if (l2 < l1) {
6318 return memcmp(s1, s2, l2) >= 0 ? 1 : -1;
6319 }
6320 else {
6321 return JimSign(memcmp(s1, s2, l1));
6322 }
6323 }
6324
6325 static int JimStringCompareLen(const char *s1, const char *s2, int maxchars, int nocase)
6326 {
6327 while (*s1 && *s2 && maxchars) {
6328 int c1, c2;
6329 s1 += utf8_tounicode_case(s1, &c1, nocase);
6330 s2 += utf8_tounicode_case(s2, &c2, nocase);
6331 if (c1 != c2) {
6332 return JimSign(c1 - c2);
6333 }
6334 maxchars--;
6335 }
6336 if (!maxchars) {
6337 return 0;
6338 }
6339
6340 if (*s1) {
6341 return 1;
6342 }
6343 if (*s2) {
6344 return -1;
 
 
 
6345 }
6346 return 0;
6347 }
6348
6349 static int JimStringFirst(const char *s1, int l1, const char *s2, int l2, int idx)
@@ -6416,11 +7115,11 @@
6416
6417 static int JimNumberBase(const char *str, int *base, int *sign)
6418 {
6419 int i = 0;
6420
6421 *base = 10;
6422
6423 while (isspace(UCHAR(str[i]))) {
6424 i++;
6425 }
6426
@@ -6443,30 +7142,31 @@
6443
6444 switch (str[i + 1]) {
6445 case 'x': case 'X': *base = 16; break;
6446 case 'o': case 'O': *base = 8; break;
6447 case 'b': case 'B': *base = 2; break;
 
6448 default: return 0;
6449 }
6450 i += 2;
6451
6452 if (str[i] != '-' && str[i] != '+' && !isspace(UCHAR(str[i]))) {
6453
6454 return i;
6455 }
6456
6457 *base = 10;
6458 return 0;
6459 }
6460
6461 static long jim_strtol(const char *str, char **endptr)
6462 {
6463 int sign;
6464 int base;
6465 int i = JimNumberBase(str, &base, &sign);
6466
6467 if (base != 10) {
6468 long value = strtol(str + i, endptr, base);
6469 if (endptr == NULL || *endptr != str + i) {
6470 return value * sign;
6471 }
6472 }
@@ -6481,11 +7181,11 @@
6481 #ifdef HAVE_LONG_LONG
6482 int sign;
6483 int base;
6484 int i = JimNumberBase(str, &base, &sign);
6485
6486 if (base != 10) {
6487 jim_wide value = strtoull(str + i, endptr, base);
6488 if (endptr == NULL || *endptr != str + i) {
6489 return value * sign;
6490 }
6491 }
@@ -6563,11 +7263,11 @@
6563 fprintf(stderr, "\nJIM INTERPRETER PANIC: ");
6564 vfprintf(stderr, fmt, ap);
6565 fprintf(stderr, "\n\n");
6566 va_end(ap);
6567
6568 #ifdef HAVE_BACKTRACE
6569 {
6570 void *array[40];
6571 int size, i;
6572 char **strings;
6573
@@ -6583,48 +7283,64 @@
6583 exit(1);
6584 }
6585 #endif
6586
6587
6588 void *Jim_Alloc(int size)
6589 {
6590 return size ? malloc(size) : NULL;
 
 
 
 
 
 
 
 
 
6591 }
6592
6593 void Jim_Free(void *ptr)
6594 {
6595 free(ptr);
6596 }
6597
6598 void *Jim_Realloc(void *ptr, int size)
6599 {
6600 return realloc(ptr, size);
6601 }
6602
6603 char *Jim_StrDup(const char *s)
6604 {
6605 return strdup(s);
6606 }
6607
6608 char *Jim_StrDupLen(const char *s, int l)
6609 {
6610 char *copy = Jim_Alloc(l + 1);
6611
6612 memcpy(copy, s, l + 1);
6613 copy[l] = 0;
6614 return copy;
6615 }
6616
6617
6618
6619 static jim_wide JimClock(void)
6620 {
 
6621 struct timeval tv;
6622
6623 gettimeofday(&tv, NULL);
6624 return (jim_wide) tv.tv_sec * 1000000 + tv.tv_usec;
 
 
 
 
 
 
 
 
 
 
 
 
 
6625 }
 
 
6626
6627
6628
6629 static void JimExpandHashTableIfNeeded(Jim_HashTable *ht);
6630 static unsigned int JimHashTableNextPower(unsigned int size);
@@ -6642,19 +7358,20 @@
6642 key += ~(key << 11);
6643 key ^= (key >> 16);
6644 return key;
6645 }
6646
6647 unsigned int Jim_GenHashFunction(const unsigned char *buf, int len)
6648 {
6649 unsigned int h = 0;
6650
6651 while (len--)
6652 h += (h << 3) + *buf++;
6653 return h;
6654 }
6655
 
6656
6657
6658
6659 static void JimResetHashTable(Jim_HashTable *ht)
6660 {
@@ -6685,19 +7402,10 @@
6685 ht->type = type;
6686 ht->privdata = privDataPtr;
6687 return JIM_OK;
6688 }
6689
6690 void Jim_ResizeHashTable(Jim_HashTable *ht)
6691 {
6692 int minimal = ht->used;
6693
6694 if (minimal < JIM_HT_INITIAL_SIZE)
6695 minimal = JIM_HT_INITIAL_SIZE;
6696 Jim_ExpandHashTable(ht, minimal);
6697 }
6698
6699
6700 void Jim_ExpandHashTable(Jim_HashTable *ht, unsigned int size)
6701 {
6702 Jim_HashTable n;
6703 unsigned int realsize = JimHashTableNextPower(size), i;
@@ -6742,16 +7450,13 @@
6742
6743
6744 *ht = n;
6745 }
6746
6747
6748 int Jim_AddHashEntry(Jim_HashTable *ht, const void *key, void *val)
6749 {
6750 Jim_HashEntry *entry;
6751
6752 entry = JimInsertHashEntry(ht, key, 0);
6753 if (entry == NULL)
6754 return JIM_ERR;
6755
6756
6757 Jim_SetHashKey(ht, entry, key);
@@ -6786,61 +7491,62 @@
6786 }
6787
6788 return existed;
6789 }
6790
6791
6792 int Jim_DeleteHashEntry(Jim_HashTable *ht, const void *key)
6793 {
6794 unsigned int h;
6795 Jim_HashEntry *he, *prevHe;
6796
6797 if (ht->used == 0)
6798 return JIM_ERR;
6799 h = Jim_HashKey(ht, key) & ht->sizemask;
6800 he = ht->table[h];
6801
6802 prevHe = NULL;
6803 while (he) {
6804 if (Jim_CompareHashKeys(ht, key, he->key)) {
6805
6806 if (prevHe)
6807 prevHe->next = he->next;
6808 else
6809 ht->table[h] = he->next;
6810 Jim_FreeEntryKey(ht, he);
6811 Jim_FreeEntryVal(ht, he);
6812 Jim_Free(he);
6813 ht->used--;
6814 return JIM_OK;
6815 }
6816 prevHe = he;
6817 he = he->next;
6818 }
6819 return JIM_ERR;
6820 }
6821
6822
6823 int Jim_FreeHashTable(Jim_HashTable *ht)
6824 {
6825 unsigned int i;
6826
6827
6828 for (i = 0; ht->used > 0; i++) {
6829 Jim_HashEntry *he, *nextHe;
6830
6831 if ((he = ht->table[i]) == NULL)
6832 continue;
6833 while (he) {
6834 nextHe = he->next;
6835 Jim_FreeEntryKey(ht, he);
6836 Jim_FreeEntryVal(ht, he);
6837 Jim_Free(he);
6838 ht->used--;
6839 he = nextHe;
6840 }
 
6841 }
 
 
 
 
 
6842
6843 Jim_Free(ht->table);
6844
6845 JimResetHashTable(ht);
6846 return JIM_OK;
@@ -7140,10 +7846,13 @@
7140 if (!pc->len) {
7141 pc->tstart = pc->p;
7142 pc->tend = pc->p - 1;
7143 pc->tline = pc->linenr;
7144 pc->tt = JIM_TT_EOL;
 
 
 
7145 pc->eof = 1;
7146 return JIM_OK;
7147 }
7148 switch (*(pc->p)) {
7149 case '\\':
@@ -7354,10 +8063,13 @@
7354 break;
7355
7356 case '"':
7357 if (startofword) {
7358 JimParseSubQuote(pc);
 
 
 
7359 continue;
7360 }
7361 break;
7362
7363 case '{':
@@ -8305,37 +9017,28 @@
8305 }
8306 }
8307
8308 int Jim_StringMatchObj(Jim_Interp *interp, Jim_Obj *patternObjPtr, Jim_Obj *objPtr, int nocase)
8309 {
8310 return JimGlobMatch(Jim_String(patternObjPtr), Jim_String(objPtr), nocase);
 
 
 
8311 }
8312
8313 int Jim_StringCompareObj(Jim_Interp *interp, Jim_Obj *firstObjPtr, Jim_Obj *secondObjPtr, int nocase)
8314 {
8315 int l1, l2;
8316 const char *s1 = Jim_GetString(firstObjPtr, &l1);
8317 const char *s2 = Jim_GetString(secondObjPtr, &l2);
8318
8319 if (nocase) {
8320
8321 return JimStringCompareLen(s1, s2, -1, nocase);
8322 }
8323 return JimStringCompare(s1, l1, s2, l2);
8324 }
8325
8326 int Jim_StringCompareLenObj(Jim_Interp *interp, Jim_Obj *firstObjPtr, Jim_Obj *secondObjPtr, int nocase)
8327 {
8328 const char *s1 = Jim_String(firstObjPtr);
 
8329 const char *s2 = Jim_String(secondObjPtr);
8330
8331 return JimStringCompareLen(s1, s2, Jim_Utf8Length(interp, firstObjPtr), nocase);
8332 }
8333
8334 static int JimRelToAbsIndex(int len, int idx)
8335 {
8336 if (idx < 0)
8337 return len + idx;
8338 return idx;
8339 }
8340
8341 static void JimRelToAbsRange(int len, int *firstPtr, int *lastPtr, int *rangeLenPtr)
@@ -8849,11 +9552,11 @@
8849 static const Jim_ObjType scriptObjType = {
8850 "script",
8851 FreeScriptInternalRep,
8852 DupScriptInternalRep,
8853 NULL,
8854 JIM_TYPE_REFERENCES,
8855 };
8856
8857 typedef struct ScriptToken
8858 {
8859 Jim_Obj *objPtr;
@@ -9223,12 +9926,10 @@
9223 Jim_FreeIntRep(interp, objPtr);
9224 Jim_SetIntRepPtr(objPtr, script);
9225 objPtr->typePtr = &scriptObjType;
9226 }
9227
9228 static void JimAddErrorToStack(Jim_Interp *interp, ScriptObj *script);
9229
9230 static ScriptObj *JimGetScript(Jim_Interp *interp, Jim_Obj *objPtr)
9231 {
9232 if (objPtr == interp->emptyObj) {
9233
9234 objPtr = interp->nullScriptObj;
@@ -9239,19 +9940,22 @@
9239 }
9240
9241 return (ScriptObj *)Jim_GetIntRepPtr(objPtr);
9242 }
9243
9244 static int JimScriptValid(Jim_Interp *interp, ScriptObj *script)
9245 {
9246 if (JimParseCheckMissing(interp, script->missing) == JIM_ERR) {
9247 JimAddErrorToStack(interp, script);
9248 return 0;
9249 }
9250 return 1;
9251 }
9252
 
 
 
9253
9254 static void JimIncrCmdRefCount(Jim_Cmd *cmdPtr)
9255 {
9256 cmdPtr->inUse++;
9257 }
@@ -9276,65 +9980,156 @@
9276 }
9277 if (cmdPtr->prevCmd) {
9278
9279 JimDecrCmdRefCount(interp, cmdPtr->prevCmd);
9280 }
9281 Jim_Free(cmdPtr);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9282 }
9283 }
9284
9285 static void JimVariablesHTValDestructor(void *interp, void *val)
9286 {
9287 Jim_DecrRefCount(interp, ((Jim_Var *)val)->objPtr);
9288 Jim_Free(val);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9289 }
9290
9291 static const Jim_HashTableType JimVariablesHashTableType = {
9292 JimStringCopyHTHashFunction,
9293 JimStringCopyHTDup,
9294 NULL,
9295 JimStringCopyHTKeyCompare,
9296 JimStringCopyHTKeyDestructor,
9297 JimVariablesHTValDestructor
9298 };
9299
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9300 static void JimCommandsHT_ValDestructor(void *interp, void *val)
9301 {
9302 JimDecrCmdRefCount(interp, val);
9303 }
9304
9305 static const Jim_HashTableType JimCommandsHashTableType = {
9306 JimStringCopyHTHashFunction,
9307 JimStringCopyHTDup,
9308 NULL,
9309 JimStringCopyHTKeyCompare,
9310 JimStringCopyHTKeyDestructor,
9311 JimCommandsHT_ValDestructor
9312 };
9313
9314
9315
9316 #ifdef jim_ext_namespace
9317 static Jim_Obj *JimQualifyNameObj(Jim_Interp *interp, Jim_Obj *nsObj)
9318 {
9319 const char *name = Jim_String(nsObj);
9320 if (name[0] == ':' && name[1] == ':') {
9321
9322 while (*++name == ':') {
9323 }
9324 nsObj = Jim_NewStringObj(interp, name, -1);
9325 }
9326 else if (Jim_Length(interp->framePtr->nsObj)) {
9327
9328 nsObj = Jim_DuplicateObj(interp, interp->framePtr->nsObj);
9329 Jim_AppendStrings(interp, nsObj, "::", name, NULL);
9330 }
9331 return nsObj;
9332 }
9333
9334 Jim_Obj *Jim_MakeGlobalNamespaceName(Jim_Interp *interp, Jim_Obj *nameObjPtr)
9335 {
 
9336 Jim_Obj *resultObj;
9337
9338 const char *name = Jim_String(nameObjPtr);
9339 if (name[0] == ':' && name[1] == ':') {
9340 return nameObjPtr;
@@ -9343,71 +10138,54 @@
9343 resultObj = Jim_NewStringObj(interp, "::", -1);
9344 Jim_AppendObj(interp, resultObj, nameObjPtr);
9345 Jim_DecrRefCount(interp, nameObjPtr);
9346
9347 return resultObj;
9348 }
9349
9350 static const char *JimQualifyName(Jim_Interp *interp, const char *name, Jim_Obj **objPtrPtr)
9351 {
9352 Jim_Obj *objPtr = interp->emptyObj;
9353
9354 if (name[0] == ':' && name[1] == ':') {
9355
9356 while (*++name == ':') {
9357 }
9358 }
9359 else if (Jim_Length(interp->framePtr->nsObj)) {
9360
9361 objPtr = Jim_DuplicateObj(interp, interp->framePtr->nsObj);
9362 Jim_AppendStrings(interp, objPtr, "::", name, NULL);
9363 name = Jim_String(objPtr);
9364 }
9365 Jim_IncrRefCount(objPtr);
9366 *objPtrPtr = objPtr;
9367 return name;
9368 }
9369
9370 #define JimFreeQualifiedName(INTERP, OBJ) Jim_DecrRefCount((INTERP), (OBJ))
9371
9372 #else
9373
9374 #define JimQualifyName(INTERP, NAME, DUMMY) (((NAME)[0] == ':' && (NAME)[1] == ':') ? (NAME) + 2 : (NAME))
9375 #define JimFreeQualifiedName(INTERP, DUMMY) (void)(DUMMY)
9376
9377 Jim_Obj *Jim_MakeGlobalNamespaceName(Jim_Interp *interp, Jim_Obj *nameObjPtr)
9378 {
9379 return nameObjPtr;
9380 }
9381 #endif
9382
9383 static int JimCreateCommand(Jim_Interp *interp, const char *name, Jim_Cmd *cmd)
9384 {
9385 Jim_HashEntry *he = Jim_FindHashEntry(&interp->commands, name);
9386 if (he) {
9387
9388 Jim_InterpIncrProcEpoch(interp);
9389 }
9390
9391 if (he && interp->local) {
9392
9393 cmd->prevCmd = Jim_GetHashEntryVal(he);
9394 Jim_SetHashVal(&interp->commands, he, cmd);
9395 }
9396 else {
9397 if (he) {
9398
9399 Jim_DeleteHashEntry(&interp->commands, name);
9400 }
9401
9402 Jim_AddHashEntry(&interp->commands, name, cmd);
9403 }
9404 return JIM_OK;
9405 }
9406
9407
9408 int Jim_CreateCommand(Jim_Interp *interp, const char *cmdNameStr,
9409 Jim_CmdProc *cmdProc, void *privData, Jim_DelCmdProc *delProc)
9410 {
9411 Jim_Cmd *cmdPtr = Jim_Alloc(sizeof(*cmdPtr));
9412
9413
@@ -9415,15 +10193,24 @@
9415 cmdPtr->inUse = 1;
9416 cmdPtr->u.native.delProc = delProc;
9417 cmdPtr->u.native.cmdProc = cmdProc;
9418 cmdPtr->u.native.privData = privData;
9419
9420 JimCreateCommand(interp, cmdNameStr, cmdPtr);
 
 
9421
9422 return JIM_OK;
9423 }
9424
 
 
 
 
 
 
 
9425 static int JimCreateProcedureStatics(Jim_Interp *interp, Jim_Cmd *cmdPtr, Jim_Obj *staticsListObjPtr)
9426 {
9427 int len, i;
9428
9429 len = Jim_ListLength(interp, staticsListObjPtr);
@@ -9432,72 +10219,129 @@
9432 }
9433
9434 cmdPtr->u.proc.staticVars = Jim_Alloc(sizeof(Jim_HashTable));
9435 Jim_InitHashTable(cmdPtr->u.proc.staticVars, &JimVariablesHashTableType, interp);
9436 for (i = 0; i < len; i++) {
9437 Jim_Obj *objPtr, *initObjPtr, *nameObjPtr;
9438 Jim_Var *varPtr;
9439 int subLen;
9440
9441 objPtr = Jim_ListGetIndex(interp, staticsListObjPtr, i);
9442
9443 subLen = Jim_ListLength(interp, objPtr);
9444 if (subLen == 1 || subLen == 2) {
9445 nameObjPtr = Jim_ListGetIndex(interp, objPtr, 0);
9446 if (subLen == 1) {
9447 initObjPtr = Jim_GetVariable(interp, nameObjPtr, JIM_NONE);
9448 if (initObjPtr == NULL) {
9449 Jim_SetResultFormatted(interp,
9450 "variable for initialization of static \"%#s\" not found in the local context",
9451 nameObjPtr);
9452 return JIM_ERR;
9453 }
9454 }
9455 else {
9456 initObjPtr = Jim_ListGetIndex(interp, objPtr, 1);
9457 }
9458 if (JimValidName(interp, "static variable", nameObjPtr) != JIM_OK) {
9459 return JIM_ERR;
9460 }
9461
9462 varPtr = Jim_Alloc(sizeof(*varPtr));
9463 varPtr->objPtr = initObjPtr;
9464 Jim_IncrRefCount(initObjPtr);
9465 varPtr->linkFramePtr = NULL;
9466 if (Jim_AddHashEntry(cmdPtr->u.proc.staticVars,
9467 Jim_String(nameObjPtr), varPtr) != JIM_OK) {
9468 Jim_SetResultFormatted(interp,
9469 "static variable name \"%#s\" duplicated in statics list", nameObjPtr);
9470 Jim_DecrRefCount(interp, initObjPtr);
9471 Jim_Free(varPtr);
9472 return JIM_ERR;
9473 }
9474 }
9475 else {
9476 Jim_SetResultFormatted(interp, "too many fields in static specifier \"%#s\"",
9477 objPtr);
9478 return JIM_ERR;
9479 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9480 }
9481 return JIM_OK;
9482 }
9483
9484 static void JimUpdateProcNamespace(Jim_Interp *interp, Jim_Cmd *cmdPtr, const char *cmdname)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9485 {
9486 #ifdef jim_ext_namespace
9487 if (cmdPtr->isproc) {
 
 
9488
9489 const char *pt = strrchr(cmdname, ':');
9490 if (pt && pt != cmdname && pt[-1] == ':') {
 
9491 Jim_DecrRefCount(interp, cmdPtr->u.proc.nsObj);
9492 cmdPtr->u.proc.nsObj = Jim_NewStringObj(interp, cmdname, pt - cmdname - 1);
9493 Jim_IncrRefCount(cmdPtr->u.proc.nsObj);
9494
9495 if (Jim_FindHashEntry(&interp->commands, pt + 1)) {
 
9496
9497 Jim_InterpIncrProcEpoch(interp);
9498 }
 
9499 }
9500 }
9501 #endif
9502 }
9503
@@ -9510,10 +10354,11 @@
9510
9511 argListLen = Jim_ListLength(interp, argListObjPtr);
9512
9513
9514 cmdPtr = Jim_Alloc(sizeof(*cmdPtr) + sizeof(struct Jim_ProcArg) * argListLen);
 
9515 memset(cmdPtr, 0, sizeof(*cmdPtr));
9516 cmdPtr->inUse = 1;
9517 cmdPtr->isproc = 1;
9518 cmdPtr->u.proc.argListObjPtr = argListObjPtr;
9519 cmdPtr->u.proc.argListLen = argListLen;
@@ -9585,72 +10430,71 @@
9585 }
9586
9587 return cmdPtr;
9588 }
9589
9590 int Jim_DeleteCommand(Jim_Interp *interp, const char *name)
9591 {
9592 int ret = JIM_OK;
9593 Jim_Obj *qualifiedNameObj;
9594 const char *qualname = JimQualifyName(interp, name, &qualifiedNameObj);
9595
9596 if (Jim_DeleteHashEntry(&interp->commands, qualname) == JIM_ERR) {
9597 Jim_SetResultFormatted(interp, "can't delete \"%s\": command doesn't exist", name);
 
 
9598 ret = JIM_ERR;
9599 }
9600 else {
9601 Jim_InterpIncrProcEpoch(interp);
9602 }
9603
9604 JimFreeQualifiedName(interp, qualifiedNameObj);
9605
9606 return ret;
9607 }
9608
9609 int Jim_RenameCommand(Jim_Interp *interp, const char *oldName, const char *newName)
9610 {
9611 int ret = JIM_ERR;
9612 Jim_HashEntry *he;
9613 Jim_Cmd *cmdPtr;
9614 Jim_Obj *qualifiedOldNameObj;
9615 Jim_Obj *qualifiedNewNameObj;
9616 const char *fqold;
9617 const char *fqnew;
9618
9619 if (newName[0] == 0) {
9620 return Jim_DeleteCommand(interp, oldName);
9621 }
9622
9623 fqold = JimQualifyName(interp, oldName, &qualifiedOldNameObj);
9624 fqnew = JimQualifyName(interp, newName, &qualifiedNewNameObj);
9625
9626
9627 he = Jim_FindHashEntry(&interp->commands, fqold);
 
 
 
 
9628 if (he == NULL) {
9629 Jim_SetResultFormatted(interp, "can't rename \"%s\": command doesn't exist", oldName);
9630 }
9631 else if (Jim_FindHashEntry(&interp->commands, fqnew)) {
9632 Jim_SetResultFormatted(interp, "can't rename to \"%s\": command already exists", newName);
9633 }
9634 else {
9635
9636 cmdPtr = Jim_GetHashEntryVal(he);
9637 JimIncrCmdRefCount(cmdPtr);
9638 JimUpdateProcNamespace(interp, cmdPtr, fqnew);
9639 Jim_AddHashEntry(&interp->commands, fqnew, cmdPtr);
9640
9641
9642 Jim_DeleteHashEntry(&interp->commands, fqold);
9643
9644
9645 Jim_InterpIncrProcEpoch(interp);
9646
9647 ret = JIM_OK;
9648 }
9649
9650 JimFreeQualifiedName(interp, qualifiedOldNameObj);
9651 JimFreeQualifiedName(interp, qualifiedNewNameObj);
 
 
 
 
 
 
9652
9653 return ret;
9654 }
9655
9656
@@ -9676,104 +10520,70 @@
9676
9677 Jim_Cmd *Jim_GetCommand(Jim_Interp *interp, Jim_Obj *objPtr, int flags)
9678 {
9679 Jim_Cmd *cmd;
9680
9681 if (objPtr->typePtr != &commandObjType ||
9682 objPtr->internalRep.cmdValue.procEpoch != interp->procEpoch
9683 #ifdef jim_ext_namespace
9684 || !Jim_StringEqObj(objPtr->internalRep.cmdValue.nsObj, interp->framePtr->nsObj)
9685 #endif
9686 ) {
9687
9688
9689
9690 const char *name = Jim_String(objPtr);
9691 Jim_HashEntry *he;
9692
9693 if (name[0] == ':' && name[1] == ':') {
9694 while (*++name == ':') {
9695 }
9696 }
9697 #ifdef jim_ext_namespace
9698 else if (Jim_Length(interp->framePtr->nsObj)) {
9699
9700 Jim_Obj *nameObj = Jim_DuplicateObj(interp, interp->framePtr->nsObj);
9701 Jim_AppendStrings(interp, nameObj, "::", name, NULL);
9702 he = Jim_FindHashEntry(&interp->commands, Jim_String(nameObj));
9703 Jim_FreeNewObj(interp, nameObj);
9704 if (he) {
9705 goto found;
9706 }
9707 }
9708 #endif
9709
9710
9711 he = Jim_FindHashEntry(&interp->commands, name);
9712 if (he == NULL) {
9713 if (flags & JIM_ERRMSG) {
9714 Jim_SetResultFormatted(interp, "invalid command name \"%#s\"", objPtr);
9715 }
 
9716 return NULL;
9717 }
9718 #ifdef jim_ext_namespace
9719 found:
9720 #endif
9721 cmd = Jim_GetHashEntryVal(he);
 
 
9722
9723
9724 Jim_FreeIntRep(interp, objPtr);
9725 objPtr->typePtr = &commandObjType;
9726 objPtr->internalRep.cmdValue.procEpoch = interp->procEpoch;
9727 objPtr->internalRep.cmdValue.cmdPtr = cmd;
9728 objPtr->internalRep.cmdValue.nsObj = interp->framePtr->nsObj;
9729 Jim_IncrRefCount(interp->framePtr->nsObj);
9730 }
9731 else {
9732 cmd = objPtr->internalRep.cmdValue.cmdPtr;
9733 }
9734 while (cmd->u.proc.upcall) {
9735 cmd = cmd->prevCmd;
9736 }
9737 return cmd;
9738 }
9739
9740
9741
9742 #define JIM_DICT_SUGAR 100
9743
9744 static int SetVariableFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr);
9745
9746 static const Jim_ObjType variableObjType = {
9747 "variable",
9748 NULL,
9749 NULL,
9750 NULL,
9751 JIM_TYPE_REFERENCES,
9752 };
9753
9754 static int JimValidName(Jim_Interp *interp, const char *type, Jim_Obj *nameObjPtr)
9755 {
9756
9757 if (nameObjPtr->typePtr != &variableObjType) {
9758 int len;
9759 const char *str = Jim_GetString(nameObjPtr, &len);
9760 if (memchr(str, '\0', len)) {
9761 Jim_SetResultFormatted(interp, "%s name contains embedded null", type);
9762 return JIM_ERR;
9763 }
9764 }
9765 return JIM_OK;
9766 }
9767
9768 static int SetVariableFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr)
9769 {
9770 const char *varName;
9771 Jim_CallFrame *framePtr;
9772 Jim_HashEntry *he;
9773 int global;
9774 int len;
 
9775
9776
9777 if (objPtr->typePtr == &variableObjType) {
9778 framePtr = objPtr->internalRep.varValue.global ? interp->topFramePtr : interp->framePtr;
9779 if (objPtr->internalRep.varValue.callFrameId == framePtr->id) {
@@ -9783,126 +10593,144 @@
9783
9784 }
9785 else if (objPtr->typePtr == &dictSubstObjType) {
9786 return JIM_DICT_SUGAR;
9787 }
9788 else if (JimValidName(interp, "variable", objPtr) != JIM_OK) {
9789 return JIM_ERR;
9790 }
9791
9792
9793 varName = Jim_GetString(objPtr, &len);
9794
9795
9796 if (len && varName[len - 1] == ')' && strchr(varName, '(') != NULL) {
9797 return JIM_DICT_SUGAR;
9798 }
9799
9800 if (varName[0] == ':' && varName[1] == ':') {
9801 while (*++varName == ':') {
 
 
9802 }
9803 global = 1;
9804 framePtr = interp->topFramePtr;
 
 
 
 
9805 }
9806 else {
9807 global = 0;
9808 framePtr = interp->framePtr;
 
 
 
 
 
 
9809 }
9810
9811
9812 he = Jim_FindHashEntry(&framePtr->vars, varName);
9813 if (he == NULL) {
9814 if (!global && framePtr->staticVars) {
9815
9816 he = Jim_FindHashEntry(framePtr->staticVars, varName);
9817 }
9818 if (he == NULL) {
9819 return JIM_ERR;
9820 }
9821 }
9822
9823
9824 Jim_FreeIntRep(interp, objPtr);
9825 objPtr->typePtr = &variableObjType;
9826 objPtr->internalRep.varValue.callFrameId = framePtr->id;
9827 objPtr->internalRep.varValue.varPtr = Jim_GetHashEntryVal(he);
9828 objPtr->internalRep.varValue.global = global;
9829 return JIM_OK;
9830 }
9831
9832
9833 static int JimDictSugarSet(Jim_Interp *interp, Jim_Obj *ObjPtr, Jim_Obj *valObjPtr);
9834 static Jim_Obj *JimDictSugarGet(Jim_Interp *interp, Jim_Obj *ObjPtr, int flags);
9835
9836 static Jim_Var *JimCreateVariable(Jim_Interp *interp, Jim_Obj *nameObjPtr, Jim_Obj *valObjPtr)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9837 {
9838 const char *name;
9839 Jim_CallFrame *framePtr;
9840 int global;
 
9841
9842
9843 Jim_Var *var = Jim_Alloc(sizeof(*var));
9844
9845 var->objPtr = valObjPtr;
9846 Jim_IncrRefCount(valObjPtr);
9847 var->linkFramePtr = NULL;
 
9848
9849 name = Jim_String(nameObjPtr);
9850 if (name[0] == ':' && name[1] == ':') {
9851 while (*++name == ':') {
 
 
9852 }
9853 framePtr = interp->topFramePtr;
9854 global = 1;
 
9855 }
9856 else {
9857 framePtr = interp->framePtr;
9858 global = 0;
 
9859 }
9860
9861
9862 Jim_AddHashEntry(&framePtr->vars, name, var);
9863
9864
9865 Jim_FreeIntRep(interp, nameObjPtr);
9866 nameObjPtr->typePtr = &variableObjType;
9867 nameObjPtr->internalRep.varValue.callFrameId = framePtr->id;
9868 nameObjPtr->internalRep.varValue.varPtr = var;
9869 nameObjPtr->internalRep.varValue.global = global;
9870
9871 return var;
9872 }
9873
9874
9875 int Jim_SetVariable(Jim_Interp *interp, Jim_Obj *nameObjPtr, Jim_Obj *valObjPtr)
9876 {
9877 int err;
9878 Jim_Var *var;
9879
9880 switch (SetVariableFromAny(interp, nameObjPtr)) {
9881 case JIM_DICT_SUGAR:
9882 return JimDictSugarSet(interp, nameObjPtr, valObjPtr);
9883
9884 case JIM_ERR:
9885 if (JimValidName(interp, "variable", nameObjPtr) != JIM_OK) {
9886 return JIM_ERR;
9887 }
9888 JimCreateVariable(interp, nameObjPtr, valObjPtr);
9889 break;
9890
9891 case JIM_OK:
9892 var = nameObjPtr->internalRep.varValue.varPtr;
9893 if (var->linkFramePtr == NULL) {
9894 Jim_IncrRefCount(valObjPtr);
9895 Jim_DecrRefCount(interp, var->objPtr);
9896 var->objPtr = valObjPtr;
9897 }
9898 else {
9899 Jim_CallFrame *savedCallFrame;
9900
9901 savedCallFrame = interp->framePtr;
9902 interp->framePtr = var->linkFramePtr;
9903 err = Jim_SetVariable(interp, var->objPtr, valObjPtr);
9904 interp->framePtr = savedCallFrame;
9905 if (err != JIM_OK)
9906 return err;
9907 }
9908 }
@@ -9949,51 +10777,57 @@
9949 Jim_Obj *targetNameObjPtr, Jim_CallFrame *targetCallFrame)
9950 {
9951 const char *varName;
9952 const char *targetName;
9953 Jim_CallFrame *framePtr;
9954 Jim_Var *varPtr;
 
 
9955
9956
9957 switch (SetVariableFromAny(interp, nameObjPtr)) {
9958 case JIM_DICT_SUGAR:
9959
9960 Jim_SetResultFormatted(interp, "bad variable name \"%#s\": upvar won't create a scalar variable that looks like an array element", nameObjPtr);
9961 return JIM_ERR;
9962
9963 case JIM_OK:
9964 varPtr = nameObjPtr->internalRep.varValue.varPtr;
9965
9966 if (varPtr->linkFramePtr == NULL) {
9967 Jim_SetResultFormatted(interp, "variable \"%#s\" already exists", nameObjPtr);
9968 return JIM_ERR;
9969 }
9970
9971
9972 varPtr->linkFramePtr = NULL;
9973 break;
9974 }
9975
9976
9977
9978 varName = Jim_String(nameObjPtr);
9979
9980 if (varName[0] == ':' && varName[1] == ':') {
9981 while (*++varName == ':') {
 
 
9982 }
9983
9984 framePtr = interp->topFramePtr;
9985 }
9986 else {
9987 framePtr = interp->framePtr;
9988 }
9989
9990 targetName = Jim_String(targetNameObjPtr);
9991 if (targetName[0] == ':' && targetName[1] == ':') {
9992 while (*++targetName == ':') {
 
 
9993 }
9994 targetNameObjPtr = Jim_NewStringObj(interp, targetName, -1);
9995 targetCallFrame = interp->topFramePtr;
9996 }
9997 Jim_IncrRefCount(targetNameObjPtr);
9998
9999 if (framePtr->level < targetCallFrame->level) {
@@ -10008,49 +10842,52 @@
10008 if (framePtr == targetCallFrame) {
10009 Jim_Obj *objPtr = targetNameObjPtr;
10010
10011
10012 while (1) {
10013 if (strcmp(Jim_String(objPtr), varName) == 0) {
10014 Jim_SetResultString(interp, "can't upvar from variable to itself", -1);
10015 Jim_DecrRefCount(interp, targetNameObjPtr);
10016 return JIM_ERR;
10017 }
10018 if (SetVariableFromAny(interp, objPtr) != JIM_OK)
10019 break;
10020 varPtr = objPtr->internalRep.varValue.varPtr;
10021 if (varPtr->linkFramePtr != targetCallFrame)
10022 break;
10023 objPtr = varPtr->objPtr;
10024 }
10025 }
10026
10027
10028 Jim_SetVariable(interp, nameObjPtr, targetNameObjPtr);
10029
10030 nameObjPtr->internalRep.varValue.varPtr->linkFramePtr = targetCallFrame;
10031 Jim_DecrRefCount(interp, targetNameObjPtr);
10032 return JIM_OK;
10033 }
10034
10035 Jim_Obj *Jim_GetVariable(Jim_Interp *interp, Jim_Obj *nameObjPtr, int flags)
10036 {
 
 
 
10037 switch (SetVariableFromAny(interp, nameObjPtr)) {
10038 case JIM_OK:{
10039 Jim_Var *varPtr = nameObjPtr->internalRep.varValue.varPtr;
10040
10041 if (varPtr->linkFramePtr == NULL) {
10042 return varPtr->objPtr;
10043 }
10044 else {
10045 Jim_Obj *objPtr;
10046
10047
10048 Jim_CallFrame *savedCallFrame = interp->framePtr;
10049
10050 interp->framePtr = varPtr->linkFramePtr;
10051 objPtr = Jim_GetVariable(interp, varPtr->objPtr, flags);
10052 interp->framePtr = savedCallFrame;
10053 if (objPtr) {
10054 return objPtr;
10055 }
10056
@@ -10105,40 +10942,47 @@
10105 return objPtr;
10106 }
10107
10108 int Jim_UnsetVariable(Jim_Interp *interp, Jim_Obj *nameObjPtr, int flags)
10109 {
10110 Jim_Var *varPtr;
10111 int retval;
10112 Jim_CallFrame *framePtr;
10113
10114 retval = SetVariableFromAny(interp, nameObjPtr);
10115 if (retval == JIM_DICT_SUGAR) {
10116
10117 return JimDictSugarSet(interp, nameObjPtr, NULL);
10118 }
10119 else if (retval == JIM_OK) {
10120 varPtr = nameObjPtr->internalRep.varValue.varPtr;
10121
10122
10123 if (varPtr->linkFramePtr) {
10124 framePtr = interp->framePtr;
10125 interp->framePtr = varPtr->linkFramePtr;
10126 retval = Jim_UnsetVariable(interp, varPtr->objPtr, JIM_NONE);
10127 interp->framePtr = framePtr;
10128 }
10129 else {
10130 const char *name = Jim_String(nameObjPtr);
10131 if (nameObjPtr->internalRep.varValue.global) {
10132 name += 2;
 
 
 
 
 
10133 framePtr = interp->topFramePtr;
 
 
 
10134 }
10135 else {
10136 framePtr = interp->framePtr;
 
10137 }
10138
10139 retval = Jim_DeleteHashEntry(&framePtr->vars, name);
10140 if (retval == JIM_OK) {
10141
10142 framePtr->id = interp->callFrameEpoch++;
10143 }
10144 }
@@ -10290,10 +11134,14 @@
10290
10291 static Jim_Obj *JimExpandDictSugar(Jim_Interp *interp, Jim_Obj *objPtr)
10292 {
10293 Jim_Obj *resObjPtr = NULL;
10294 Jim_Obj *substKeyObjPtr = NULL;
 
 
 
 
10295
10296 SetDictSubstFromAny(interp, objPtr);
10297
10298 if (Jim_SubstObj(interp, objPtr->internalRep.dictSubstValue.indexObjPtr,
10299 &substKeyObjPtr, JIM_NONE)
@@ -10307,18 +11155,10 @@
10307 Jim_DecrRefCount(interp, substKeyObjPtr);
10308
10309 return resObjPtr;
10310 }
10311
10312 static Jim_Obj *JimExpandExprSugar(Jim_Interp *interp, Jim_Obj *objPtr)
10313 {
10314 if (Jim_EvalExpression(interp, objPtr) == JIM_OK) {
10315 return Jim_GetResult(interp);
10316 }
10317 return NULL;
10318 }
10319
10320
10321 static Jim_CallFrame *JimCreateCallFrame(Jim_Interp *interp, Jim_CallFrame *parent, Jim_Obj *nsObj)
10322 {
10323 Jim_CallFrame *cf;
10324
@@ -10357,18 +11197,12 @@
10357
10358 if (localCommands) {
10359 Jim_Obj *cmdNameObj;
10360
10361 while ((cmdNameObj = Jim_StackPop(localCommands)) != NULL) {
10362 Jim_HashEntry *he;
10363 Jim_Obj *fqObjName;
10364 Jim_HashTable *ht = &interp->commands;
10365
10366 const char *fqname = JimQualifyName(interp, Jim_String(cmdNameObj), &fqObjName);
10367
10368 he = Jim_FindHashEntry(ht, fqname);
10369
10370 if (he) {
10371 Jim_Cmd *cmd = Jim_GetHashEntryVal(he);
10372 if (cmd->prevCmd) {
10373 Jim_Cmd *prevCmd = cmd->prevCmd;
10374 cmd->prevCmd = NULL;
@@ -10378,16 +11212,14 @@
10378
10379
10380 Jim_SetHashVal(ht, he, prevCmd);
10381 }
10382 else {
10383 Jim_DeleteHashEntry(ht, fqname);
10384 }
10385 Jim_InterpIncrProcEpoch(interp);
10386 }
10387 Jim_DecrRefCount(interp, cmdNameObj);
10388 JimFreeQualifiedName(interp, fqObjName);
10389 }
10390 Jim_FreeStack(localCommands);
10391 Jim_Free(localCommands);
10392 }
10393 return JIM_OK;
@@ -10396,15 +11228,14 @@
10396 static int JimInvokeDefer(Jim_Interp *interp, int retcode)
10397 {
10398 Jim_Obj *objPtr;
10399
10400
10401 if (Jim_FindHashEntry(&interp->framePtr->vars, "jim::defer") == NULL) {
10402 return retcode;
10403 }
10404
10405 objPtr = Jim_GetVariableStr(interp, "jim::defer", JIM_NONE);
10406
10407 if (objPtr) {
10408 int ret = JIM_OK;
10409 int i;
10410 int listLen = Jim_ListLength(interp, objPtr);
@@ -10452,28 +11283,11 @@
10452 Jim_DecrRefCount(interp, cf->procBodyObjPtr);
10453 Jim_DecrRefCount(interp, cf->nsObj);
10454 if (action == JIM_FCF_FULL || cf->vars.size != JIM_HT_INITIAL_SIZE)
10455 Jim_FreeHashTable(&cf->vars);
10456 else {
10457 int i;
10458 Jim_HashEntry **table = cf->vars.table, *he;
10459
10460 for (i = 0; i < JIM_HT_INITIAL_SIZE; i++) {
10461 he = table[i];
10462 while (he != NULL) {
10463 Jim_HashEntry *nextEntry = he->next;
10464 Jim_Var *varPtr = Jim_GetHashEntryVal(he);
10465
10466 Jim_DecrRefCount(interp, varPtr->objPtr);
10467 Jim_Free(Jim_GetHashEntryKey(he));
10468 Jim_Free(varPtr);
10469 Jim_Free(he);
10470 table[i] = NULL;
10471 he = nextEntry;
10472 }
10473 }
10474 cf->vars.used = 0;
10475 }
10476 cf->next = interp->freeFramesList;
10477 interp->freeFramesList = cf;
10478 }
10479
@@ -10496,11 +11310,11 @@
10496
10497 memset(i, 0, sizeof(*i));
10498
10499 i->maxCallFrameDepth = JIM_MAX_CALLFRAME_DEPTH;
10500 i->maxEvalDepth = JIM_MAX_EVAL_DEPTH;
10501 i->lastCollectTime = time(NULL);
10502
10503 Jim_InitHashTable(&i->commands, &JimCommandsHashTableType, i);
10504 #ifdef JIM_REFERENCES
10505 Jim_InitHashTable(&i->references, &JimReferencesHashTableType, i);
10506 #endif
@@ -10508,27 +11322,28 @@
10508 Jim_InitHashTable(&i->packages, &JimPackageHashTableType, NULL);
10509 i->emptyObj = Jim_NewEmptyStringObj(i);
10510 i->trueObj = Jim_NewIntObj(i, 1);
10511 i->falseObj = Jim_NewIntObj(i, 0);
10512 i->framePtr = i->topFramePtr = JimCreateCallFrame(i, NULL, i->emptyObj);
10513 i->errorFileNameObj = i->emptyObj;
10514 i->result = i->emptyObj;
10515 i->stackTrace = Jim_NewListObj(i, NULL, 0);
10516 i->unknown = Jim_NewStringObj(i, "unknown", -1);
 
10517 i->errorProc = i->emptyObj;
10518 i->currentScriptObj = Jim_NewEmptyStringObj(i);
10519 i->nullScriptObj = Jim_NewEmptyStringObj(i);
 
 
10520 Jim_IncrRefCount(i->emptyObj);
10521 Jim_IncrRefCount(i->errorFileNameObj);
10522 Jim_IncrRefCount(i->result);
10523 Jim_IncrRefCount(i->stackTrace);
10524 Jim_IncrRefCount(i->unknown);
10525 Jim_IncrRefCount(i->currentScriptObj);
10526 Jim_IncrRefCount(i->nullScriptObj);
10527 Jim_IncrRefCount(i->errorProc);
10528 Jim_IncrRefCount(i->trueObj);
10529 Jim_IncrRefCount(i->falseObj);
 
10530
10531
10532 Jim_SetVariableStrWithStr(i, JIM_LIBPATH, TCL_LIBRARY);
10533 Jim_SetVariableStrWithStr(i, JIM_INTERACTIVE, "0");
10534
@@ -10536,21 +11351,25 @@
10536 Jim_SetVariableStrWithStr(i, "tcl_platform(os)", TCL_PLATFORM_OS);
10537 Jim_SetVariableStrWithStr(i, "tcl_platform(platform)", TCL_PLATFORM_PLATFORM);
10538 Jim_SetVariableStrWithStr(i, "tcl_platform(pathSeparator)", TCL_PLATFORM_PATH_SEPARATOR);
10539 Jim_SetVariableStrWithStr(i, "tcl_platform(byteOrder)", Jim_IsBigEndian() ? "bigEndian" : "littleEndian");
10540 Jim_SetVariableStrWithStr(i, "tcl_platform(threaded)", "0");
 
10541 Jim_SetVariableStr(i, "tcl_platform(pointerSize)", Jim_NewIntObj(i, sizeof(void *)));
10542 Jim_SetVariableStr(i, "tcl_platform(wordSize)", Jim_NewIntObj(i, sizeof(jim_wide)));
 
10543
10544 return i;
10545 }
10546
10547 void Jim_FreeInterp(Jim_Interp *i)
10548 {
10549 Jim_CallFrame *cf, *cfx;
10550
10551 Jim_Obj *objPtr, *nextObjPtr;
 
 
10552
10553
10554 for (cf = i->framePtr; cf; cf = cfx) {
10555
10556 JimInvokeDefer(i, JIM_OK);
@@ -10563,20 +11382,27 @@
10563 Jim_DecrRefCount(i, i->falseObj);
10564 Jim_DecrRefCount(i, i->result);
10565 Jim_DecrRefCount(i, i->stackTrace);
10566 Jim_DecrRefCount(i, i->errorProc);
10567 Jim_DecrRefCount(i, i->unknown);
10568 Jim_DecrRefCount(i, i->errorFileNameObj);
10569 Jim_DecrRefCount(i, i->currentScriptObj);
10570 Jim_DecrRefCount(i, i->nullScriptObj);
 
 
 
 
 
10571 Jim_FreeHashTable(&i->commands);
10572 #ifdef JIM_REFERENCES
10573 Jim_FreeHashTable(&i->references);
10574 #endif
10575 Jim_FreeHashTable(&i->packages);
10576 Jim_Free(i->prngState);
10577 Jim_FreeHashTable(&i->assocData);
 
 
 
10578
10579 #ifdef JIM_MAINTAINER
10580 if (i->liveList != NULL) {
10581 objPtr = i->liveList;
10582
@@ -10671,102 +11497,115 @@
10671
10672 Jim_SetResultFormatted(interp, "bad level \"%s\"", str);
10673 return NULL;
10674 }
10675
10676 static Jim_CallFrame *JimGetCallFrameByInteger(Jim_Interp *interp, Jim_Obj *levelObjPtr)
10677 {
10678 long level;
10679 Jim_CallFrame *framePtr;
10680
10681 if (Jim_GetLong(interp, levelObjPtr, &level) == JIM_OK) {
10682 if (level <= 0) {
10683
10684 level = interp->framePtr->level + level;
10685 }
10686
10687 if (level == 0) {
10688 return interp->topFramePtr;
10689 }
10690
10691
10692 for (framePtr = interp->framePtr; framePtr; framePtr = framePtr->parent) {
10693 if (framePtr->level == level) {
10694 return framePtr;
10695 }
10696 }
10697 }
 
 
10698
10699 Jim_SetResultFormatted(interp, "bad level \"%#s\"", levelObjPtr);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10700 return NULL;
10701 }
10702
10703 static void JimResetStackTrace(Jim_Interp *interp)
10704 {
10705 Jim_DecrRefCount(interp, interp->stackTrace);
10706 interp->stackTrace = Jim_NewListObj(interp, NULL, 0);
10707 Jim_IncrRefCount(interp->stackTrace);
 
 
 
 
 
 
 
 
 
 
 
10708 }
10709
10710 static void JimSetStackTrace(Jim_Interp *interp, Jim_Obj *stackTraceObj)
10711 {
10712 int len;
10713
10714
10715 Jim_IncrRefCount(stackTraceObj);
10716 Jim_DecrRefCount(interp, interp->stackTrace);
10717 interp->stackTrace = stackTraceObj;
10718 interp->errorFlag = 1;
10719
10720 len = Jim_ListLength(interp, interp->stackTrace);
10721 if (len >= 3) {
10722 if (Jim_Length(Jim_ListGetIndex(interp, interp->stackTrace, len - 2)) == 0) {
10723 interp->addStackTrace = 1;
10724 }
10725 }
10726 }
10727
10728 static void JimAppendStackTrace(Jim_Interp *interp, const char *procname,
10729 Jim_Obj *fileNameObj, int linenr)
10730 {
10731 if (strcmp(procname, "unknown") == 0) {
10732 procname = "";
10733 }
10734 if (!*procname && !Jim_Length(fileNameObj)) {
10735
10736 return;
10737 }
10738
10739 if (Jim_IsShared(interp->stackTrace)) {
10740 Jim_DecrRefCount(interp, interp->stackTrace);
10741 interp->stackTrace = Jim_DuplicateObj(interp, interp->stackTrace);
10742 Jim_IncrRefCount(interp->stackTrace);
10743 }
10744
10745
10746 if (!*procname && Jim_Length(fileNameObj)) {
10747
10748 int len = Jim_ListLength(interp, interp->stackTrace);
10749
10750 if (len >= 3) {
10751 Jim_Obj *objPtr = Jim_ListGetIndex(interp, interp->stackTrace, len - 3);
10752 if (Jim_Length(objPtr)) {
10753
10754 objPtr = Jim_ListGetIndex(interp, interp->stackTrace, len - 2);
10755 if (Jim_Length(objPtr) == 0) {
10756
10757 ListSetIndex(interp, interp->stackTrace, len - 2, fileNameObj, 0);
10758 ListSetIndex(interp, interp->stackTrace, len - 1, Jim_NewIntObj(interp, linenr), 0);
10759 return;
10760 }
10761 }
10762 }
10763 }
10764
10765 Jim_ListAppendElement(interp, interp->stackTrace, Jim_NewStringObj(interp, procname, -1));
10766 Jim_ListAppendElement(interp, interp->stackTrace, fileNameObj);
10767 Jim_ListAppendElement(interp, interp->stackTrace, Jim_NewIntObj(interp, linenr));
10768 }
10769
10770 int Jim_SetAssocData(Jim_Interp *interp, const char *key, Jim_InterpDeleteProc * delProc,
10771 void *data)
10772 {
@@ -10897,10 +11736,36 @@
10897 return JIM_ERR;
10898 *widePtr = JimWideValue(objPtr);
10899 return JIM_OK;
10900 }
10901
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10902
10903 static int JimGetWideNoErr(Jim_Interp *interp, Jim_Obj *objPtr, jim_wide * widePtr)
10904 {
10905 if (objPtr->typePtr != &intObjType && SetIntFromAny(interp, objPtr, JIM_NONE) == JIM_ERR)
10906 return JIM_ERR;
@@ -10943,15 +11808,15 @@
10943 NULL,
10944 UpdateStringOfDouble,
10945 JIM_TYPE_NONE,
10946 };
10947
10948 #ifndef HAVE_ISNAN
10949 #undef isnan
10950 #define isnan(X) ((X) != (X))
10951 #endif
10952 #ifndef HAVE_ISINF
10953 #undef isinf
10954 #define isinf(X) (1.0 / (X) == 0.0)
10955 #endif
10956
10957 static void UpdateStringOfDouble(struct Jim_Obj *objPtr)
@@ -11078,38 +11943,37 @@
11078 if (objPtr->typePtr != &intObjType && SetBooleanFromAny(interp, objPtr, JIM_ERRMSG) == JIM_ERR)
11079 return JIM_ERR;
11080 *booleanPtr = (int) JimWideValue(objPtr);
11081 return JIM_OK;
11082 }
 
 
 
 
 
 
 
 
 
 
11083
11084 static int SetBooleanFromAny(Jim_Interp *interp, Jim_Obj *objPtr, int flags)
11085 {
11086 static const char * const falses[] = {
11087 "0", "false", "no", "off", NULL
11088 };
11089 static const char * const trues[] = {
11090 "1", "true", "yes", "on", NULL
11091 };
11092
11093 int boolean;
11094
11095 int index;
11096 if (Jim_GetEnum(interp, objPtr, falses, &index, NULL, 0) == JIM_OK) {
11097 boolean = 0;
11098 } else if (Jim_GetEnum(interp, objPtr, trues, &index, NULL, 0) == JIM_OK) {
11099 boolean = 1;
11100 } else {
11101 if (flags & JIM_ERRMSG) {
11102 Jim_SetResultFormatted(interp, "expected boolean but got \"%#s\"", objPtr);
11103 }
11104 return JIM_ERR;
11105 }
11106
11107
11108 Jim_FreeIntRep(interp, objPtr);
11109 objPtr->typePtr = &intObjType;
11110 objPtr->internalRep.wideValue = boolean;
 
11111 return JIM_OK;
11112 }
11113
11114 static void ListInsertElements(Jim_Obj *listPtr, int idx, int elemc, Jim_Obj *const *elemVec);
11115 static void ListAppendElement(Jim_Obj *listPtr, Jim_Obj *objPtr);
@@ -11404,28 +12268,26 @@
11404 int linenr;
11405
11406 if (objPtr->typePtr == &listObjType) {
11407 return JIM_OK;
11408 }
 
11409
11410 if (Jim_IsDict(objPtr) && objPtr->bytes == NULL) {
11411 Jim_Obj **listObjPtrPtr;
11412 int len;
11413 int i;
11414
11415 listObjPtrPtr = JimDictPairs(objPtr, &len);
11416 for (i = 0; i < len; i++) {
11417 Jim_IncrRefCount(listObjPtrPtr[i]);
11418 }
11419
11420
11421 Jim_FreeIntRep(interp, objPtr);
11422 objPtr->typePtr = &listObjType;
11423 objPtr->internalRep.listValue.len = len;
11424 objPtr->internalRep.listValue.maxLen = len;
11425 objPtr->internalRep.listValue.ele = listObjPtrPtr;
11426
 
 
 
 
 
11427 return JIM_OK;
11428 }
11429
11430
11431 if (objPtr->typePtr == &sourceObjType) {
@@ -11513,12 +12375,12 @@
11513 JIM_LSORT_INTEGER,
11514 JIM_LSORT_REAL,
11515 JIM_LSORT_COMMAND
11516 } type;
11517 int order;
11518 int index;
11519 int indexed;
11520 int unique;
11521 int (*subfn)(Jim_Obj **, Jim_Obj **);
11522 };
11523
11524 static struct lsort_info *sort_info;
@@ -11525,12 +12387,12 @@
11525
11526 static int ListSortIndexHelper(Jim_Obj **lhsObj, Jim_Obj **rhsObj)
11527 {
11528 Jim_Obj *lObj, *rObj;
11529
11530 if (Jim_ListIndex(sort_info->interp, *lhsObj, sort_info->index, &lObj, JIM_ERRMSG) != JIM_OK ||
11531 Jim_ListIndex(sort_info->interp, *rhsObj, sort_info->index, &rObj, JIM_ERRMSG) != JIM_OK) {
11532 longjmp(sort_info->jmpbuf, JIM_ERR);
11533 }
11534 return sort_info->subfn(&lObj, &rObj);
11535 }
11536
@@ -11663,11 +12525,11 @@
11663 fn = NULL;
11664 JimPanic((1, "ListSort called with invalid sort type"));
11665 return -1;
11666 }
11667
11668 if (info->indexed) {
11669
11670 info->subfn = fn;
11671 fn = ListSortIndexHelper;
11672 }
11673
@@ -11683,30 +12545,39 @@
11683 sort_info = prev_info;
11684
11685 return rc;
11686 }
11687
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11688 static void ListInsertElements(Jim_Obj *listPtr, int idx, int elemc, Jim_Obj *const *elemVec)
11689 {
11690 int currentLen = listPtr->internalRep.listValue.len;
11691 int requiredLen = currentLen + elemc;
11692 int i;
11693 Jim_Obj **point;
11694
11695 if (requiredLen > listPtr->internalRep.listValue.maxLen) {
11696 if (requiredLen < 2) {
11697
11698 requiredLen = 4;
11699 }
11700 else {
11701 requiredLen *= 2;
11702 }
11703
11704 listPtr->internalRep.listValue.ele = Jim_Realloc(listPtr->internalRep.listValue.ele,
11705 sizeof(Jim_Obj *) * requiredLen);
11706
11707 listPtr->internalRep.listValue.maxLen = requiredLen;
11708 }
11709 if (idx < 0) {
11710 idx = currentLen;
11711 }
11712 point = listPtr->internalRep.listValue.ele + idx;
@@ -11786,10 +12657,51 @@
11786 }
11787 return JIM_ERR;
11788 }
11789 return JIM_OK;
11790 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11791
11792 static int ListSetIndex(Jim_Interp *interp, Jim_Obj *listPtr, int idx,
11793 Jim_Obj *newObjPtr, int flags)
11794 {
11795 SetListFromAny(interp, listPtr);
@@ -11821,11 +12733,14 @@
11821 varObjPtr = objPtr = Jim_DuplicateObj(interp, objPtr);
11822 for (i = 0; i < indexc - 1; i++) {
11823 listObjPtr = objPtr;
11824 if (Jim_GetIndex(interp, indexv[i], &idx) != JIM_OK)
11825 goto err;
11826 if (Jim_ListIndex(interp, listObjPtr, idx, &objPtr, JIM_ERRMSG) != JIM_OK) {
 
 
 
11827 goto err;
11828 }
11829 if (Jim_IsShared(objPtr)) {
11830 objPtr = Jim_DuplicateObj(interp, objPtr);
11831 ListSetIndex(interp, listObjPtr, idx, objPtr, JIM_NONE);
@@ -11948,112 +12863,186 @@
11948 static void DupDictInternalRep(Jim_Interp *interp, Jim_Obj *srcPtr, Jim_Obj *dupPtr);
11949 static void UpdateStringOfDict(struct Jim_Obj *objPtr);
11950 static int SetDictFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr);
11951
11952
11953 static unsigned int JimObjectHTHashFunction(const void *key)
11954 {
11955 int len;
11956 const char *str = Jim_GetString((Jim_Obj *)key, &len);
11957 return Jim_GenHashFunction((const unsigned char *)str, len);
11958 }
11959
11960 static int JimObjectHTKeyCompare(void *privdata, const void *key1, const void *key2)
11961 {
11962 return Jim_StringEqObj((Jim_Obj *)key1, (Jim_Obj *)key2);
11963 }
11964
11965 static void *JimObjectHTKeyValDup(void *privdata, const void *val)
11966 {
11967 Jim_IncrRefCount((Jim_Obj *)val);
11968 return (void *)val;
11969 }
11970
11971 static void JimObjectHTKeyValDestructor(void *interp, void *val)
11972 {
11973 Jim_DecrRefCount(interp, (Jim_Obj *)val);
11974 }
11975
11976 static const Jim_HashTableType JimDictHashTableType = {
11977 JimObjectHTHashFunction,
11978 JimObjectHTKeyValDup,
11979 JimObjectHTKeyValDup,
11980 JimObjectHTKeyCompare,
11981 JimObjectHTKeyValDestructor,
11982 JimObjectHTKeyValDestructor
11983 };
11984
11985 static const Jim_ObjType dictObjType = {
11986 "dict",
11987 FreeDictInternalRep,
11988 DupDictInternalRep,
11989 UpdateStringOfDict,
11990 JIM_TYPE_NONE,
11991 };
11992
11993 void FreeDictInternalRep(Jim_Interp *interp, Jim_Obj *objPtr)
11994 {
11995 JIM_NOTUSED(interp);
11996
11997 Jim_FreeHashTable(objPtr->internalRep.ptr);
11998 Jim_Free(objPtr->internalRep.ptr);
11999 }
12000
12001 void DupDictInternalRep(Jim_Interp *interp, Jim_Obj *srcPtr, Jim_Obj *dupPtr)
12002 {
12003 Jim_HashTable *ht, *dupHt;
12004 Jim_HashTableIterator htiter;
12005 Jim_HashEntry *he;
12006
12007
12008 ht = srcPtr->internalRep.ptr;
12009 dupHt = Jim_Alloc(sizeof(*dupHt));
12010 Jim_InitHashTable(dupHt, &JimDictHashTableType, interp);
12011 if (ht->size != 0)
12012 Jim_ExpandHashTable(dupHt, ht->size);
12013
12014 JimInitHashTableIterator(ht, &htiter);
12015 while ((he = Jim_NextHashEntry(&htiter)) != NULL) {
12016 Jim_AddHashEntry(dupHt, he->key, he->u.val);
12017 }
12018
12019 dupPtr->internalRep.ptr = dupHt;
12020 dupPtr->typePtr = &dictObjType;
12021 }
12022
12023 static Jim_Obj **JimDictPairs(Jim_Obj *dictPtr, int *len)
12024 {
12025 Jim_HashTable *ht;
12026 Jim_HashTableIterator htiter;
12027 Jim_HashEntry *he;
12028 Jim_Obj **objv;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12029 int i;
12030
12031 ht = dictPtr->internalRep.ptr;
 
12032
12033
12034 objv = Jim_Alloc((ht->used * 2) * sizeof(Jim_Obj *));
12035 JimInitHashTableIterator(ht, &htiter);
12036 i = 0;
12037 while ((he = Jim_NextHashEntry(&htiter)) != NULL) {
12038 objv[i++] = Jim_GetHashEntryKey(he);
12039 objv[i++] = Jim_GetHashEntryVal(he);
12040 }
12041 *len = i;
12042 return objv;
 
 
 
 
 
12043 }
12044
12045 static void UpdateStringOfDict(struct Jim_Obj *objPtr)
12046 {
12047
12048 int len;
12049 Jim_Obj **objv = JimDictPairs(objPtr, &len);
12050
12051
12052 JimMakeListStringRep(objPtr, objv, len);
12053
12054 Jim_Free(objv);
12055 }
12056
12057 static int SetDictFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr)
12058 {
12059 int listlen;
@@ -12064,34 +13053,49 @@
12064
12065 if (Jim_IsList(objPtr) && Jim_IsShared(objPtr)) {
12066 Jim_String(objPtr);
12067 }
12068
12069
12070 listlen = Jim_ListLength(interp, objPtr);
12071 if (listlen % 2) {
12072 Jim_SetResultString(interp, "missing value to go with key", -1);
12073 return JIM_ERR;
12074 }
12075 else {
12076
12077 Jim_HashTable *ht;
12078 int i;
12079
12080 ht = Jim_Alloc(sizeof(*ht));
12081 Jim_InitHashTable(ht, &JimDictHashTableType, interp);
 
 
12082
12083 for (i = 0; i < listlen; i += 2) {
12084 Jim_Obj *keyObjPtr = Jim_ListGetIndex(interp, objPtr, i);
12085 Jim_Obj *valObjPtr = Jim_ListGetIndex(interp, objPtr, i + 1);
12086
12087 Jim_ReplaceHashEntry(ht, keyObjPtr, valObjPtr);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12088 }
12089
12090 Jim_FreeIntRep(interp, objPtr);
12091 objPtr->typePtr = &dictObjType;
12092 objPtr->internalRep.ptr = ht;
12093
12094 return JIM_OK;
12095 }
12096 }
12097
@@ -12098,17 +13102,60 @@
12098
12099
12100 static int DictAddElement(Jim_Interp *interp, Jim_Obj *objPtr,
12101 Jim_Obj *keyObjPtr, Jim_Obj *valueObjPtr)
12102 {
12103 Jim_HashTable *ht = objPtr->internalRep.ptr;
12104
12105 if (valueObjPtr == NULL) {
12106 return Jim_DeleteHashEntry(ht, keyObjPtr);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12107 }
12108 Jim_ReplaceHashEntry(ht, keyObjPtr, valueObjPtr);
12109 return JIM_OK;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12110 }
12111
12112 int Jim_DictAddElement(Jim_Interp *interp, Jim_Obj *objPtr,
12113 Jim_Obj *keyObjPtr, Jim_Obj *valueObjPtr)
12114 {
@@ -12128,50 +13175,57 @@
12128 JimPanic((len % 2, "Jim_NewDictObj() 'len' argument must be even"));
12129
12130 objPtr = Jim_NewObj(interp);
12131 objPtr->typePtr = &dictObjType;
12132 objPtr->bytes = NULL;
12133 objPtr->internalRep.ptr = Jim_Alloc(sizeof(Jim_HashTable));
12134 Jim_InitHashTable(objPtr->internalRep.ptr, &JimDictHashTableType, interp);
12135 for (i = 0; i < len; i += 2)
12136 DictAddElement(interp, objPtr, elements[i], elements[i + 1]);
12137 return objPtr;
12138 }
12139
12140 int Jim_DictKey(Jim_Interp *interp, Jim_Obj *dictPtr, Jim_Obj *keyPtr,
12141 Jim_Obj **objPtrPtr, int flags)
12142 {
12143 Jim_HashEntry *he;
12144 Jim_HashTable *ht;
12145
12146 if (SetDictFromAny(interp, dictPtr) != JIM_OK) {
12147 return -1;
12148 }
12149 ht = dictPtr->internalRep.ptr;
12150 if ((he = Jim_FindHashEntry(ht, keyPtr)) == NULL) {
 
12151 if (flags & JIM_ERRMSG) {
12152 Jim_SetResultFormatted(interp, "key \"%#s\" not known in dictionary", keyPtr);
12153 }
12154 return JIM_ERR;
12155 }
12156 else {
12157 *objPtrPtr = Jim_GetHashEntryVal(he);
12158 return JIM_OK;
12159 }
12160 }
12161
 
 
12162
12163 int Jim_DictPairs(Jim_Interp *interp, Jim_Obj *dictPtr, Jim_Obj ***objPtrPtr, int *len)
12164 {
 
 
 
 
 
 
12165 if (SetDictFromAny(interp, dictPtr) != JIM_OK) {
12166 return JIM_ERR;
 
 
12167 }
12168 *objPtrPtr = JimDictPairs(dictPtr, len);
12169
12170 return JIM_OK;
12171 }
12172
12173
12174
12175 int Jim_DictKeysVector(Jim_Interp *interp, Jim_Obj *dictPtr,
12176 Jim_Obj *const *keyv, int keyc, Jim_Obj **objPtrPtr, int flags)
12177 {
@@ -12254,11 +13308,14 @@
12254 Jim_InvalidateStringRep(objPtr);
12255 Jim_InvalidateStringRep(varObjPtr);
12256 if (Jim_SetVariable(interp, varNamePtr, varObjPtr) != JIM_OK) {
12257 goto err;
12258 }
12259 Jim_SetResult(interp, varObjPtr);
 
 
 
12260 return JIM_OK;
12261 err:
12262 if (shared) {
12263 Jim_FreeNewObj(interp, varObjPtr);
12264 }
@@ -12281,11 +13338,11 @@
12281 if (objPtr->internalRep.intValue == -1) {
12282 JimSetStringBytes(objPtr, "end");
12283 }
12284 else {
12285 char buf[JIM_INTEGER_SPACE + 1];
12286 if (objPtr->internalRep.intValue >= 0) {
12287 sprintf(buf, "%d", objPtr->internalRep.intValue);
12288 }
12289 else {
12290
12291 sprintf(buf, "end%d", objPtr->internalRep.intValue + 1);
@@ -12294,49 +13351,49 @@
12294 }
12295 }
12296
12297 static int SetIndexFromAny(Jim_Interp *interp, Jim_Obj *objPtr)
12298 {
12299 int idx, end = 0;
 
12300 const char *str;
12301 char *endptr;
 
 
12302
12303
12304 str = Jim_String(objPtr);
12305
12306
12307 if (strncmp(str, "end", 3) == 0) {
12308 end = 1;
12309 str += 3;
12310 idx = 0;
12311 }
12312 else {
12313 idx = jim_strtol(str, &endptr);
12314
12315 if (endptr == str) {
12316 goto badindex;
12317 }
12318 str = endptr;
12319 }
12320
12321
12322 if (*str == '+' || *str == '-') {
12323 int sign = (*str == '+' ? 1 : -1);
12324
12325 idx += sign * jim_strtol(++str, &endptr);
12326 if (str == endptr || *endptr) {
12327 goto badindex;
12328 }
12329 str = endptr;
12330 }
12331
12332 while (isspace(UCHAR(*str))) {
12333 str++;
12334 }
12335 if (*str) {
12336 goto badindex;
12337 }
12338 if (end) {
12339 if (idx > 0) {
12340 idx = INT_MAX;
12341 }
12342 else {
@@ -12354,11 +13411,11 @@
12354 objPtr->internalRep.intValue = idx;
12355 return JIM_OK;
12356
12357 badindex:
12358 Jim_SetResultFormatted(interp,
12359 "bad index \"%#s\": must be integer?[+-]integer? or end?[+-]integer?", objPtr);
12360 return JIM_ERR;
12361 }
12362
12363 int Jim_GetIndex(Jim_Interp *interp, Jim_Obj *objPtr, int *indexPtr)
12364 {
@@ -12479,10 +13536,14 @@
12479
12480 JIM_EXPROP_STREQ,
12481 JIM_EXPROP_STRNE,
12482 JIM_EXPROP_STRIN,
12483 JIM_EXPROP_STRNI,
 
 
 
 
12484
12485
12486 JIM_EXPROP_NOT,
12487 JIM_EXPROP_BITNOT,
12488 JIM_EXPROP_UNARYMINUS,
@@ -12544,11 +13605,11 @@
12544 static int JimExprEvalTermNode(Jim_Interp *interp, struct JimExprNode *node);
12545
12546 static int JimExprOpNumUnary(Jim_Interp *interp, struct JimExprNode *node)
12547 {
12548 int intresult = 1;
12549 int rc;
12550 double dA, dC = 0;
12551 jim_wide wA, wC = 0;
12552 Jim_Obj *A;
12553
12554 if ((rc = JimExprGetTerm(interp, node->left, &A)) != JIM_OK) {
@@ -12611,10 +13672,19 @@
12611 break;
12612 default:
12613 abort();
12614 }
12615 }
 
 
 
 
 
 
 
 
 
12616
12617 if (rc == JIM_OK) {
12618 if (intresult) {
12619 Jim_SetResultInt(interp, wC);
12620 }
@@ -12631,11 +13701,11 @@
12631 static double JimRandDouble(Jim_Interp *interp)
12632 {
12633 unsigned long x;
12634 JimRandomBytes(interp, &x, sizeof(x));
12635
12636 return (double)x / (unsigned long)~0;
12637 }
12638
12639 static int JimExprOpIntUnary(Jim_Interp *interp, struct JimExprNode *node)
12640 {
12641 jim_wide wA;
@@ -13040,11 +14110,11 @@
13040
13041 static int JimExprOpStrBin(Jim_Interp *interp, struct JimExprNode *node)
13042 {
13043 Jim_Obj *A, *B;
13044 jim_wide wC;
13045 int rc;
13046
13047 if ((rc = JimExprGetTerm(interp, node->left, &A)) != JIM_OK) {
13048 return rc;
13049 }
13050 if ((rc = JimExprGetTerm(interp, node->right, &B)) != JIM_OK) {
@@ -13057,10 +14127,25 @@
13057 case JIM_EXPROP_STRNE:
13058 wC = Jim_StringEqObj(A, B);
13059 if (node->type == JIM_EXPROP_STRNE) {
13060 wC = !wC;
13061 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13062 break;
13063 case JIM_EXPROP_STRIN:
13064 wC = JimSearchList(interp, B, A);
13065 break;
13066 case JIM_EXPROP_STRNI:
@@ -13196,10 +14281,15 @@
13196 OPRINIT("eq", 60, 2, JimExprOpStrBin),
13197 OPRINIT("ne", 60, 2, JimExprOpStrBin),
13198
13199 OPRINIT("in", 55, 2, JimExprOpStrBin),
13200 OPRINIT("ni", 55, 2, JimExprOpStrBin),
 
 
 
 
 
13201
13202 OPRINIT_ATTR("!", 150, 1, JimExprOpNumUnary, OP_RIGHT_ASSOC),
13203 OPRINIT_ATTR("~", 150, 1, JimExprOpIntUnary, OP_RIGHT_ASSOC),
13204 OPRINIT_ATTR(" -", 150, 1, JimExprOpNumUnary, OP_RIGHT_ASSOC),
13205 OPRINIT_ATTR(" +", 150, 1, JimExprOpNumUnary, OP_RIGHT_ASSOC),
@@ -13242,17 +14332,26 @@
13242 #define JIM_EXPR_OPERATORS_NUM \
13243 (sizeof(Jim_ExprOperators)/sizeof(struct Jim_ExprOperator))
13244
13245 static int JimParseExpression(struct JimParserCtx *pc)
13246 {
 
13247
13248 while (isspace(UCHAR(*pc->p)) || (*(pc->p) == '\\' && *(pc->p + 1) == '\n')) {
13249 if (*pc->p == '\n') {
13250 pc->linenr++;
 
 
 
13251 }
13252 pc->p++;
13253 pc->len--;
 
 
 
 
 
13254 }
13255
13256
13257 pc->tline = pc->linenr;
13258 pc->tstart = pc->p;
@@ -13372,21 +14471,15 @@
13372 return JIM_ERR;
13373 }
13374
13375 static int JimParseExprBoolean(struct JimParserCtx *pc)
13376 {
13377 const char *booleans[] = { "false", "no", "off", "true", "yes", "on", NULL };
13378 const int lengths[] = { 5, 2, 3, 4, 3, 2, 0 };
13379 int i;
13380
13381 for (i = 0; booleans[i]; i++) {
13382 const char *boolean = booleans[i];
13383 int length = lengths[i];
13384
13385 if (strncmp(boolean, pc->p, length) == 0) {
13386 pc->p += length;
13387 pc->len -= length;
13388 pc->tend = pc->p - 1;
13389 pc->tt = JIM_TT_EXPR_BOOLEAN;
13390 return JIM_OK;
13391 }
13392 }
@@ -13479,11 +14572,11 @@
13479 static const Jim_ObjType exprObjType = {
13480 "expression",
13481 FreeExprInternalRep,
13482 DupExprInternalRep,
13483 NULL,
13484 JIM_TYPE_REFERENCES,
13485 };
13486
13487
13488 struct ExprTree
13489 {
@@ -13571,12 +14664,11 @@
13571
13572 #define EXPR_UNTIL_CLOSE 0x0001
13573 #define EXPR_FUNC_ARGS 0x0002
13574 #define EXPR_TERNARY 0x0004
13575
13576 static int ExprTreeBuildTree(Jim_Interp *interp, struct ExprBuilder *builder, int precedence, int flags, int exp_numterms)
13577 {
13578 int rc;
13579 struct JimExprNode *node;
13580
13581 int exp_stacklen = builder->stack.len + exp_numterms;
13582
@@ -13826,11 +14918,11 @@
13826 builder.level = 0;
13827 builder.token = builder.first_token = tokenlist->list;
13828 builder.exprObjPtr = exprObjPtr;
13829 builder.fileNameObj = fileNameObj;
13830
13831 builder.nodes = malloc(sizeof(struct JimExprNode) * (tokenlist->count - 1));
13832 memset(builder.nodes, 0, sizeof(struct JimExprNode) * (tokenlist->count - 1));
13833 builder.next = builder.nodes;
13834 Jim_InitStack(&builder.stack);
13835
13836 rc = ExprTreeBuildTree(interp, &builder, 0, 0, 1);
@@ -14004,17 +15096,23 @@
14004 return JIM_OK;
14005 }
14006 return JIM_ERR;
14007
14008 case JIM_TT_ESC:
 
 
 
14009 if (Jim_SubstObj(interp, node->objPtr, &objPtr, JIM_NONE) == JIM_OK) {
14010 Jim_SetResult(interp, objPtr);
14011 return JIM_OK;
14012 }
14013 return JIM_ERR;
14014
14015 case JIM_TT_CMD:
 
 
 
14016 return Jim_EvalObj(interp, node->objPtr);
14017
14018 default:
14019
14020 return JIM_ERR;
@@ -14043,36 +15141,38 @@
14043 int Jim_EvalExpression(Jim_Interp *interp, Jim_Obj *exprObjPtr)
14044 {
14045 struct ExprTree *expr;
14046 int retcode = JIM_OK;
14047
 
14048 expr = JimGetExpression(interp, exprObjPtr);
14049 if (!expr) {
14050 return JIM_ERR;
 
14051 }
14052
14053 #ifdef JIM_OPTIMIZATION
14054 {
14055 Jim_Obj *objPtr;
14056
14057
14058 switch (expr->len) {
14059 case 1:
14060 objPtr = JimExprIntValOrVar(interp, expr->expr);
14061 if (objPtr) {
14062 Jim_SetResult(interp, objPtr);
14063 return JIM_OK;
14064 }
14065 break;
14066
14067 case 2:
14068 if (expr->expr->type == JIM_EXPROP_NOT) {
14069 objPtr = JimExprIntValOrVar(interp, expr->expr->left);
14070
14071 if (objPtr && JimIsWide(objPtr)) {
14072 Jim_SetResult(interp, JimWideValue(objPtr) ? interp->falseObj : interp->trueObj);
14073 return JIM_OK;
14074 }
14075 }
14076 break;
14077
14078 case 3:
@@ -14104,11 +15204,11 @@
14104 break;
14105 default:
14106 goto noopt;
14107 }
14108 Jim_SetResult(interp, cmpRes ? interp->trueObj : interp->falseObj);
14109 return JIM_OK;
14110 }
14111 }
14112 break;
14113 }
14114 }
@@ -14118,11 +15218,17 @@
14118 expr->inUse++;
14119
14120
14121 retcode = JimExprEvalTermNode(interp, expr->expr);
14122
14123 expr->inUse--;
 
 
 
 
 
 
14124
14125 return retcode;
14126 }
14127
14128 int Jim_GetBoolFromExpr(Jim_Interp *interp, Jim_Obj *exprObjPtr, int *boolPtr)
@@ -14405,21 +15511,21 @@
14405
14406 if (!sdescr && isspace(UCHAR(*str)))
14407 break;
14408
14409 n = utf8_tounicode(str, &c);
14410 if (sdescr && !JimCharsetMatch(sdescr, c, JIM_CHARSET_SCAN))
14411 break;
14412 while (n--)
14413 *p++ = *str++;
14414 }
14415 *p = 0;
14416 return Jim_NewStringObjNoAlloc(interp, buffer, p - buffer);
14417 }
14418
14419
14420 static int ScanOneEntry(Jim_Interp *interp, const char *str, int pos, int strLen,
14421 ScanFmtStringObj * fmtObj, long idx, Jim_Obj **valObjPtr)
14422 {
14423 const char *tok;
14424 const ScanFmtPartDescr *descr = &fmtObj->descr[idx];
14425 size_t scanned = 0;
@@ -14428,52 +15534,53 @@
14428 Jim_Obj *tmpObj = NULL;
14429
14430
14431 *valObjPtr = 0;
14432 if (descr->prefix) {
14433 for (i = 0; pos < strLen && descr->prefix[i]; ++i) {
14434
14435 if (isspace(UCHAR(descr->prefix[i])))
14436 while (pos < strLen && isspace(UCHAR(str[pos])))
14437 ++pos;
14438 else if (descr->prefix[i] != str[pos])
14439 break;
14440 else
14441 ++pos;
14442 }
14443 if (pos >= strLen) {
14444 return -1;
14445 }
14446 else if (descr->prefix[i] != 0)
14447 return 0;
14448 }
14449
14450 if (descr->type != 'c' && descr->type != '[' && descr->type != 'n')
14451 while (isspace(UCHAR(str[pos])))
14452 ++pos;
 
14453
14454 scanned = pos - anchor;
14455
14456
14457 if (descr->type == 'n') {
14458
14459 *valObjPtr = Jim_NewIntObj(interp, anchor + scanned);
14460 }
14461 else if (pos >= strLen) {
14462
14463 return -1;
14464 }
14465 else if (descr->type == 'c') {
14466 int c;
14467 scanned += utf8_tounicode(&str[pos], &c);
14468 *valObjPtr = Jim_NewIntObj(interp, c);
14469 return scanned;
14470 }
14471 else {
14472
14473 if (descr->width > 0) {
14474 size_t sLen = utf8_strlen(&str[pos], strLen - pos);
14475 size_t tLen = descr->width > sLen ? sLen : descr->width;
14476
14477 tmpObj = Jim_NewStringObjUtf8(interp, str + pos, tLen);
14478 tok = tmpObj->bytes;
14479 }
@@ -14548,11 +15655,11 @@
14548 Jim_Obj *Jim_ScanString(Jim_Interp *interp, Jim_Obj *strObjPtr, Jim_Obj *fmtObjPtr, int flags)
14549 {
14550 size_t i, pos;
14551 int scanned = 1;
14552 const char *str = Jim_String(strObjPtr);
14553 int strLen = Jim_Utf8Length(interp, strObjPtr);
14554 Jim_Obj *resultList = 0;
14555 Jim_Obj **resultVec = 0;
14556 int resultc;
14557 Jim_Obj *emptyStr = 0;
14558 ScanFmtStringObj *fmtObj;
@@ -14585,11 +15692,11 @@
14585
14586 if (descr->type == 0)
14587 continue;
14588
14589 if (scanned > 0)
14590 scanned = ScanOneEntry(interp, str, pos, strLen, fmtObj, i, &value);
14591
14592 if (scanned == -1 && i == 0)
14593 goto eof;
14594
14595 pos += scanned;
@@ -14707,11 +15814,11 @@
14707 if (argc != 2 && argc != 3) {
14708 Jim_WrongNumArgs(interp, 1, argv, "varName ?increment?");
14709 return JIM_ERR;
14710 }
14711 if (argc == 3) {
14712 if (Jim_GetWide(interp, argv[2], &increment) != JIM_OK)
14713 return JIM_ERR;
14714 }
14715 intObjPtr = Jim_GetVariable(interp, argv[1], JIM_UNSHARED);
14716 if (!intObjPtr) {
14717
@@ -14743,10 +15850,49 @@
14743
14744
14745 #define JIM_EVAL_SARGV_LEN 8
14746 #define JIM_EVAL_SINTV_LEN 8
14747
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14748
14749 static int JimUnknown(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
14750 {
14751 int retcode;
14752
@@ -14764,16 +15910,44 @@
14764 retcode = Jim_EvalObjPrefix(interp, interp->unknown, argc, argv);
14765 interp->unknown_called--;
14766
14767 return retcode;
14768 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14769
14770 static int JimInvokeCommand(Jim_Interp *interp, int objc, Jim_Obj *const *objv)
14771 {
14772 int retcode;
14773 Jim_Cmd *cmdPtr;
14774 void *prevPrivData;
 
14775
14776 #if 0
14777 printf("invoke");
14778 int j;
14779 for (j = 0; j < objc; j++) {
@@ -14780,58 +15954,104 @@
14780 printf(" '%s'", Jim_String(objv[j]));
14781 }
14782 printf("\n");
14783 #endif
14784
14785 if (interp->framePtr->tailcallCmd) {
14786
14787 cmdPtr = interp->framePtr->tailcallCmd;
14788 interp->framePtr->tailcallCmd = NULL;
14789 }
14790 else {
14791 cmdPtr = Jim_GetCommand(interp, objv[0], JIM_ERRMSG);
14792 if (cmdPtr == NULL) {
14793 return JimUnknown(interp, objc, objv);
14794 }
14795 JimIncrCmdRefCount(cmdPtr);
14796 }
14797
14798 if (interp->evalDepth == interp->maxEvalDepth) {
14799 Jim_SetResultString(interp, "Infinite eval recursion", -1);
14800 retcode = JIM_ERR;
14801 goto out;
14802 }
14803 interp->evalDepth++;
14804 prevPrivData = interp->cmdPrivData;
14805
14806
14807 Jim_SetEmptyResult(interp);
14808 if (cmdPtr->isproc) {
14809 retcode = JimCallProcedure(interp, cmdPtr, objc, objv);
14810 }
14811 else {
14812 interp->cmdPrivData = cmdPtr->u.native.privData;
14813 retcode = cmdPtr->u.native.cmdProc(interp, objc, objv);
14814 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14815 interp->cmdPrivData = prevPrivData;
14816 interp->evalDepth--;
14817
14818 out:
14819 JimDecrCmdRefCount(interp, cmdPtr);
 
 
 
 
 
 
 
 
 
 
 
14820
14821 return retcode;
14822 }
14823
14824 int Jim_EvalObjVector(Jim_Interp *interp, int objc, Jim_Obj *const *objv)
14825 {
14826 int i, retcode;
 
14827
14828
14829 for (i = 0; i < objc; i++)
14830 Jim_IncrRefCount(objv[i]);
 
 
14831
14832 retcode = JimInvokeCommand(interp, objc, objv);
 
 
14833
14834
14835 for (i = 0; i < objc; i++)
14836 Jim_DecrRefCount(interp, objv[i]);
14837
@@ -14848,44 +16068,14 @@
14848 ret = Jim_EvalObjVector(interp, objc + 1, nargv);
14849 Jim_Free(nargv);
14850 return ret;
14851 }
14852
14853 static void JimAddErrorToStack(Jim_Interp *interp, ScriptObj *script)
14854 {
14855 if (!interp->errorFlag) {
14856
14857 interp->errorFlag = 1;
14858 Jim_IncrRefCount(script->fileNameObj);
14859 Jim_DecrRefCount(interp, interp->errorFileNameObj);
14860 interp->errorFileNameObj = script->fileNameObj;
14861 interp->errorLine = script->linenr;
14862
14863 JimResetStackTrace(interp);
14864
14865 interp->addStackTrace++;
14866 }
14867
14868
14869 if (interp->addStackTrace > 0) {
14870
14871
14872 JimAppendStackTrace(interp, Jim_String(interp->errorProc), script->fileNameObj, script->linenr);
14873
14874 if (Jim_Length(script->fileNameObj)) {
14875 interp->addStackTrace = 0;
14876 }
14877
14878 Jim_DecrRefCount(interp, interp->errorProc);
14879 interp->errorProc = interp->emptyObj;
14880 Jim_IncrRefCount(interp->errorProc);
14881 }
14882 }
14883
14884 static int JimSubstOneToken(Jim_Interp *interp, const ScriptToken *token, Jim_Obj **objPtrPtr)
14885 {
14886 Jim_Obj *objPtr;
 
14887
14888 switch (token->type) {
14889 case JIM_TT_STR:
14890 case JIM_TT_ESC:
14891 objPtr = token->objPtr;
@@ -14895,26 +16085,25 @@
14895 break;
14896 case JIM_TT_DICTSUGAR:
14897 objPtr = JimExpandDictSugar(interp, token->objPtr);
14898 break;
14899 case JIM_TT_EXPRSUGAR:
14900 objPtr = JimExpandExprSugar(interp, token->objPtr);
 
 
 
 
 
 
14901 break;
14902 case JIM_TT_CMD:
14903 switch (Jim_EvalObj(interp, token->objPtr)) {
14904 case JIM_OK:
14905 case JIM_RETURN:
14906 objPtr = interp->result;
14907 break;
14908 case JIM_BREAK:
14909
14910 return JIM_BREAK;
14911 case JIM_CONTINUE:
14912
14913 return JIM_CONTINUE;
14914 default:
14915 return JIM_ERR;
14916 }
14917 break;
14918 default:
14919 JimPanic((1,
14920 "default token type (%d) reached " "in Jim_SubstObj().", token->type));
@@ -14923,11 +16112,11 @@
14923 }
14924 if (objPtr) {
14925 *objPtrPtr = objPtr;
14926 return JIM_OK;
14927 }
14928 return JIM_ERR;
14929 }
14930
14931 static Jim_Obj *JimInterpolateTokens(Jim_Interp *interp, const ScriptToken * token, int tokens, int flags)
14932 {
14933 int totlen = 0, i;
@@ -15018,20 +16207,26 @@
15018
15019
15020 static int JimEvalObjList(Jim_Interp *interp, Jim_Obj *listPtr)
15021 {
15022 int retcode = JIM_OK;
 
15023
15024 JimPanic((Jim_IsList(listPtr) == 0, "JimEvalObjList() invoked on non-list."));
 
 
15025
15026 if (listPtr->internalRep.listValue.len) {
15027 Jim_IncrRefCount(listPtr);
15028 retcode = JimInvokeCommand(interp,
15029 listPtr->internalRep.listValue.len,
15030 listPtr->internalRep.listValue.ele);
15031 Jim_DecrRefCount(interp, listPtr);
15032 }
 
 
 
15033 return retcode;
15034 }
15035
15036 int Jim_EvalObjList(Jim_Interp *interp, Jim_Obj *listPtr)
15037 {
@@ -15044,19 +16239,20 @@
15044 int i;
15045 ScriptObj *script;
15046 ScriptToken *token;
15047 int retcode = JIM_OK;
15048 Jim_Obj *sargv[JIM_EVAL_SARGV_LEN], **argv = NULL;
15049 Jim_Obj *prevScriptObj;
15050
15051 if (Jim_IsList(scriptObjPtr) && scriptObjPtr->bytes == NULL) {
15052 return JimEvalObjList(interp, scriptObjPtr);
15053 }
15054
15055 Jim_IncrRefCount(scriptObjPtr);
15056 script = JimGetScript(interp, scriptObjPtr);
15057 if (!JimScriptValid(interp, script)) {
 
15058 Jim_DecrRefCount(interp, scriptObjPtr);
15059 return JIM_ERR;
15060 }
15061
15062 Jim_SetEmptyResult(interp);
@@ -15086,13 +16282,12 @@
15086 }
15087 #endif
15088
15089 script->inUse++;
15090
 
15091
15092 prevScriptObj = interp->currentScriptObj;
15093 interp->currentScriptObj = scriptObjPtr;
15094
15095 interp->errorFlag = 0;
15096 argv = sargv;
15097
15098 for (i = 0; i < script->len && retcode == JIM_OK; ) {
@@ -15132,11 +16327,17 @@
15132 break;
15133 case JIM_TT_VAR:
15134 wordObjPtr = Jim_GetVariable(interp, token[i].objPtr, JIM_ERRMSG);
15135 break;
15136 case JIM_TT_EXPRSUGAR:
15137 wordObjPtr = JimExpandExprSugar(interp, token[i].objPtr);
 
 
 
 
 
 
15138 break;
15139 case JIM_TT_DICTSUGAR:
15140 wordObjPtr = JimExpandDictSugar(interp, token[i].objPtr);
15141 break;
15142 case JIM_TT_CMD:
@@ -15219,20 +16420,14 @@
15219 }
15220 }
15221
15222
15223 if (retcode == JIM_ERR) {
15224 JimAddErrorToStack(interp, script);
15225 }
15226
15227 else if (retcode != JIM_RETURN || interp->returnCode != JIM_ERR) {
15228
15229 interp->addStackTrace = 0;
15230 }
15231
15232
15233 interp->currentScriptObj = prevScriptObj;
15234
15235 Jim_FreeIntRep(interp, scriptObjPtr);
15236 scriptObjPtr->typePtr = &scriptObjType;
15237 Jim_SetIntRepPtr(scriptObjPtr, script);
15238 Jim_DecrRefCount(interp, scriptObjPtr);
@@ -15285,11 +16480,11 @@
15285 Jim_AppendObj(interp, argmsg, cmd->u.proc.arglist[i].defaultObjPtr);
15286 Jim_AppendString(interp, argmsg, " ...?", -1);
15287 }
15288 else {
15289
15290 Jim_AppendString(interp, argmsg, "?arg...?", -1);
15291 }
15292 }
15293 else {
15294 if (cmd->u.proc.arglist[i].defaultObjPtr) {
15295 Jim_AppendString(interp, argmsg, "?", 1);
@@ -15314,17 +16509,15 @@
15314 Jim_CallFrame *callFramePtr;
15315 int retcode;
15316
15317
15318 callFramePtr = JimCreateCallFrame(interp, interp->framePtr, nsObj);
15319 callFramePtr->argv = &interp->emptyObj;
15320 callFramePtr->argc = 0;
15321 callFramePtr->procArgsObjPtr = NULL;
15322 callFramePtr->procBodyObjPtr = scriptObj;
15323 callFramePtr->staticVars = NULL;
15324 callFramePtr->fileNameObj = interp->emptyObj;
15325 callFramePtr->line = 0;
15326 Jim_IncrRefCount(scriptObj);
15327 interp->framePtr = callFramePtr;
15328
15329
15330 if (interp->framePtr->level == interp->maxCallFrameDepth) {
@@ -15346,11 +16539,10 @@
15346
15347 static int JimCallProcedure(Jim_Interp *interp, Jim_Cmd *cmd, int argc, Jim_Obj *const *argv)
15348 {
15349 Jim_CallFrame *callFramePtr;
15350 int i, d, retcode, optargs;
15351 ScriptObj *script;
15352
15353
15354 if (argc - 1 < cmd->u.proc.reqArity ||
15355 (cmd->u.proc.argsPos < 0 && argc - 1 > cmd->u.proc.reqArity + cmd->u.proc.optArity)) {
15356 JimSetProcWrongArgs(interp, argv[0], cmd);
@@ -15374,14 +16566,11 @@
15374 callFramePtr->argc = argc;
15375 callFramePtr->procArgsObjPtr = cmd->u.proc.argListObjPtr;
15376 callFramePtr->procBodyObjPtr = cmd->u.proc.bodyObjPtr;
15377 callFramePtr->staticVars = cmd->u.proc.staticVars;
15378
15379
15380 script = JimGetScript(interp, interp->currentScriptObj);
15381 callFramePtr->fileNameObj = script->fileNameObj;
15382 callFramePtr->line = script->linenr;
15383
15384 Jim_IncrRefCount(cmd->u.proc.argListObjPtr);
15385 Jim_IncrRefCount(cmd->u.proc.bodyObjPtr);
15386 interp->framePtr = callFramePtr;
15387
@@ -15425,57 +16614,32 @@
15425 if (retcode != JIM_OK) {
15426 goto badargset;
15427 }
15428 }
15429
 
 
15430
15431 retcode = Jim_EvalObj(interp, cmd->u.proc.bodyObjPtr);
 
15432
15433 badargset:
15434
15435
15436 retcode = JimInvokeDefer(interp, retcode);
15437 interp->framePtr = interp->framePtr->parent;
15438 JimFreeCallFrame(interp, callFramePtr, JIM_FCF_REUSE);
15439
15440
15441 if (interp->framePtr->tailcallObj) {
15442 do {
15443 Jim_Obj *tailcallObj = interp->framePtr->tailcallObj;
15444
15445 interp->framePtr->tailcallObj = NULL;
15446
15447 if (retcode == JIM_EVAL) {
15448 retcode = Jim_EvalObjList(interp, tailcallObj);
15449 if (retcode == JIM_RETURN) {
15450 interp->returnLevel++;
15451 }
15452 }
15453 Jim_DecrRefCount(interp, tailcallObj);
15454 } while (interp->framePtr->tailcallObj);
15455
15456
15457 if (interp->framePtr->tailcallCmd) {
15458 JimDecrCmdRefCount(interp, interp->framePtr->tailcallCmd);
15459 interp->framePtr->tailcallCmd = NULL;
15460 }
15461 }
15462
15463
15464 if (retcode == JIM_RETURN) {
15465 if (--interp->returnLevel <= 0) {
15466 retcode = interp->returnCode;
15467 interp->returnCode = JIM_OK;
15468 interp->returnLevel = 0;
15469 }
15470 }
15471 else if (retcode == JIM_ERR) {
15472 interp->addStackTrace++;
15473 Jim_DecrRefCount(interp, interp->errorProc);
15474 interp->errorProc = argv[0];
15475 Jim_IncrRefCount(interp->errorProc);
15476 }
15477
15478 return retcode;
15479 }
15480
15481 int Jim_EvalSource(Jim_Interp *interp, const char *filename, int lineno, const char *script)
@@ -15483,26 +16647,14 @@
15483 int retval;
15484 Jim_Obj *scriptObjPtr;
15485
15486 scriptObjPtr = Jim_NewStringObj(interp, script, -1);
15487 Jim_IncrRefCount(scriptObjPtr);
15488
15489 if (filename) {
15490 Jim_Obj *prevScriptObj;
15491
15492 JimSetSourceInfo(interp, scriptObjPtr, Jim_NewStringObj(interp, filename, -1), lineno);
15493
15494 prevScriptObj = interp->currentScriptObj;
15495 interp->currentScriptObj = scriptObjPtr;
15496
15497 retval = Jim_EvalObj(interp, scriptObjPtr);
15498
15499 interp->currentScriptObj = prevScriptObj;
15500 }
15501 else {
15502 retval = Jim_EvalObj(interp, scriptObjPtr);
15503 }
15504 Jim_DecrRefCount(interp, scriptObjPtr);
15505 return retval;
15506 }
15507
15508 int Jim_Eval(Jim_Interp *interp, const char *script)
@@ -15535,65 +16687,69 @@
15535 return retval;
15536 }
15537
15538 #include <sys/stat.h>
15539
15540 int Jim_EvalFile(Jim_Interp *interp, const char *filename)
15541 {
15542 FILE *fp;
15543 char *buf;
15544 Jim_Obj *scriptObjPtr;
15545 Jim_Obj *prevScriptObj;
15546 struct stat sb;
15547 int retcode;
15548 int readlen;
15549
15550 if (stat(filename, &sb) != 0 || (fp = fopen(filename, "rt")) == NULL) {
15551 Jim_SetResultFormatted(interp, "couldn't read file \"%s\": %s", filename, strerror(errno));
15552 return JIM_ERR;
15553 }
15554 if (sb.st_size == 0) {
15555 fclose(fp);
15556 return JIM_OK;
15557 }
15558
15559 buf = Jim_Alloc(sb.st_size + 1);
15560 readlen = fread(buf, 1, sb.st_size, fp);
15561 if (ferror(fp)) {
15562 fclose(fp);
15563 Jim_Free(buf);
15564 Jim_SetResultFormatted(interp, "failed to load file \"%s\": %s", filename, strerror(errno));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15565 return JIM_ERR;
15566 }
15567 fclose(fp);
15568 buf[readlen] = 0;
15569
15570 scriptObjPtr = Jim_NewStringObjNoAlloc(interp, buf, readlen);
15571 JimSetSourceInfo(interp, scriptObjPtr, Jim_NewStringObj(interp, filename, -1), 1);
15572 Jim_IncrRefCount(scriptObjPtr);
15573
15574 prevScriptObj = interp->currentScriptObj;
15575 interp->currentScriptObj = scriptObjPtr;
15576
15577 retcode = Jim_EvalObj(interp, scriptObjPtr);
 
 
15578
15579
15580 if (retcode == JIM_RETURN) {
15581 if (--interp->returnLevel <= 0) {
15582 retcode = interp->returnCode;
15583 interp->returnCode = JIM_OK;
15584 interp->returnLevel = 0;
15585 }
15586 }
15587 if (retcode == JIM_ERR) {
15588
15589 interp->addStackTrace++;
15590 }
15591
15592 interp->currentScriptObj = prevScriptObj;
15593
15594 Jim_DecrRefCount(interp, scriptObjPtr);
15595
15596 return retcode;
15597 }
15598
15599 static void JimParseSubst(struct JimParserCtx *pc, int flags)
@@ -15696,11 +16852,15 @@
15696 return (ScriptObj *) Jim_GetIntRepPtr(objPtr);
15697 }
15698
15699 int Jim_SubstObj(Jim_Interp *interp, Jim_Obj *substObjPtr, Jim_Obj **resObjPtrPtr, int flags)
15700 {
15701 ScriptObj *script = Jim_GetSubst(interp, substObjPtr, flags);
 
 
 
 
15702
15703 Jim_IncrRefCount(substObjPtr);
15704 script->inUse++;
15705
15706 *resObjPtrPtr = JimInterpolateTokens(interp, script->token, script->len, flags);
@@ -15731,11 +16891,11 @@
15731
15732 Jim_SetResultFormatted(interp, "wrong # args: should be \"%#s\"", objPtr);
15733 }
15734
15735 typedef void JimHashtableIteratorCallbackType(Jim_Interp *interp, Jim_Obj *listObjPtr,
15736 Jim_HashEntry *he, int type);
15737
15738 #define JimTrivialMatch(pattern) (strpbrk((pattern), "*[?\\") == NULL)
15739
15740 static Jim_Obj *JimHashtablePatternMatch(Jim_Interp *interp, Jim_HashTable *ht, Jim_Obj *patternObjPtr,
15741 JimHashtableIteratorCallbackType *callback, int type)
@@ -15743,22 +16903,22 @@
15743 Jim_HashEntry *he;
15744 Jim_Obj *listObjPtr = Jim_NewListObj(interp, NULL, 0);
15745
15746
15747 if (patternObjPtr && JimTrivialMatch(Jim_String(patternObjPtr))) {
15748 he = Jim_FindHashEntry(ht, Jim_String(patternObjPtr));
15749 if (he) {
15750 callback(interp, listObjPtr, he, type);
 
15751 }
15752 }
15753 else {
15754 Jim_HashTableIterator htiter;
15755 JimInitHashTableIterator(ht, &htiter);
15756 while ((he = Jim_NextHashEntry(&htiter)) != NULL) {
15757 if (patternObjPtr == NULL || JimGlobMatch(Jim_String(patternObjPtr), he->key, 0)) {
15758 callback(interp, listObjPtr, he, type);
15759 }
15760 }
15761 }
15762 return listObjPtr;
15763 }
15764
@@ -15766,29 +16926,40 @@
15766 #define JIM_CMDLIST_COMMANDS 0
15767 #define JIM_CMDLIST_PROCS 1
15768 #define JIM_CMDLIST_CHANNELS 2
15769
15770 static void JimCommandMatch(Jim_Interp *interp, Jim_Obj *listObjPtr,
15771 Jim_HashEntry *he, int type)
15772 {
15773 Jim_Cmd *cmdPtr = Jim_GetHashEntryVal(he);
15774 Jim_Obj *objPtr;
15775
15776 if (type == JIM_CMDLIST_PROCS && !cmdPtr->isproc) {
15777
15778 return;
15779 }
15780
15781 objPtr = Jim_NewStringObj(interp, he->key, -1);
15782 Jim_IncrRefCount(objPtr);
15783
15784 if (type != JIM_CMDLIST_CHANNELS || Jim_AioFilehandle(interp, objPtr)) {
15785 Jim_ListAppendElement(interp, listObjPtr, objPtr);
15786 }
15787 Jim_DecrRefCount(interp, objPtr);
15788 }
15789
 
 
 
 
 
 
 
 
 
 
 
 
15790
15791 static Jim_Obj *JimCommandsList(Jim_Interp *interp, Jim_Obj *patternObjPtr, int type)
15792 {
15793 return JimHashtablePatternMatch(interp, &interp->commands, patternObjPtr, JimCommandMatch, type);
15794 }
@@ -15795,22 +16966,25 @@
15795
15796
15797 #define JIM_VARLIST_GLOBALS 0
15798 #define JIM_VARLIST_LOCALS 1
15799 #define JIM_VARLIST_VARS 2
 
15800
15801 #define JIM_VARLIST_VALUES 0x1000
15802
15803 static void JimVariablesMatch(Jim_Interp *interp, Jim_Obj *listObjPtr,
15804 Jim_HashEntry *he, int type)
15805 {
15806 Jim_Var *varPtr = Jim_GetHashEntryVal(he);
15807
15808 if (type != JIM_VARLIST_LOCALS || varPtr->linkFramePtr == NULL) {
15809 Jim_ListAppendElement(interp, listObjPtr, Jim_NewStringObj(interp, he->key, -1));
15810 if (type & JIM_VARLIST_VALUES) {
15811 Jim_ListAppendElement(interp, listObjPtr, varPtr->objPtr);
 
 
15812 }
15813 }
15814 }
15815
15816
@@ -15819,42 +16993,78 @@
15819 if (mode == JIM_VARLIST_LOCALS && interp->framePtr == interp->topFramePtr) {
15820 return interp->emptyObj;
15821 }
15822 else {
15823 Jim_CallFrame *framePtr = (mode == JIM_VARLIST_GLOBALS) ? interp->topFramePtr : interp->framePtr;
15824 return JimHashtablePatternMatch(interp, &framePtr->vars, patternObjPtr, JimVariablesMatch, mode);
15825 }
15826 }
15827
15828 static int JimInfoLevel(Jim_Interp *interp, Jim_Obj *levelObjPtr,
15829 Jim_Obj **objPtrPtr, int info_level_cmd)
15830 {
15831 Jim_CallFrame *targetCallFrame;
15832
15833 targetCallFrame = JimGetCallFrameByInteger(interp, levelObjPtr);
15834 if (targetCallFrame == NULL) {
15835 return JIM_ERR;
15836 }
15837
15838 if (targetCallFrame == interp->topFramePtr) {
15839 Jim_SetResultFormatted(interp, "bad level \"%#s\"", levelObjPtr);
15840 return JIM_ERR;
15841 }
15842 if (info_level_cmd) {
15843 *objPtrPtr = Jim_NewListObj(interp, targetCallFrame->argv, targetCallFrame->argc);
15844 }
15845 else {
15846 Jim_Obj *listObj = Jim_NewListObj(interp, NULL, 0);
15847
15848 Jim_ListAppendElement(interp, listObj, targetCallFrame->argv[0]);
15849 Jim_ListAppendElement(interp, listObj, targetCallFrame->fileNameObj);
15850 Jim_ListAppendElement(interp, listObj, Jim_NewIntObj(interp, targetCallFrame->line));
15851 *objPtrPtr = listObj;
15852 }
15853 return JIM_OK;
15854 }
15855
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15856
15857
15858 static int Jim_PutsCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
15859 {
15860 if (argc != 2 && argc != 3) {
@@ -16056,12 +17266,24 @@
16056 && complain) {
16057 return JIM_ERR;
16058 }
16059 i++;
16060 }
 
 
16061 return JIM_OK;
16062 }
 
 
 
 
 
 
 
 
 
 
16063
16064
16065 static int Jim_WhileCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
16066 {
16067 if (argc != 3) {
@@ -16069,25 +17291,26 @@
16069 return JIM_ERR;
16070 }
16071
16072
16073 while (1) {
16074 int boolean, retval;
16075
16076 if ((retval = Jim_GetBoolFromExpr(interp, argv[1], &boolean)) != JIM_OK)
16077 return retval;
16078 if (!boolean)
16079 break;
16080
16081 if ((retval = Jim_EvalObj(interp, argv[2])) != JIM_OK) {
 
 
 
16082 switch (retval) {
16083 case JIM_BREAK:
16084 goto out;
16085 break;
16086 case JIM_CONTINUE:
16087 continue;
16088 break;
16089 default:
16090 return retval;
16091 }
16092 }
16093 }
@@ -16099,10 +17322,11 @@
16099
16100 static int Jim_ForCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
16101 {
16102 int retval;
16103 int boolean = 1;
 
16104 Jim_Obj *varNamePtr = NULL;
16105 Jim_Obj *stopVarNamePtr = NULL;
16106
16107 if (argc != 5) {
16108 Jim_WrongNumArgs(interp, 1, argv, "start test next body");
@@ -16166,11 +17390,11 @@
16166 goto evalstart;
16167 }
16168
16169
16170 if (expr->expr->right->type == JIM_TT_EXPR_INT) {
16171 if (Jim_GetWide(interp, expr->expr->right->objPtr, &stop) == JIM_ERR) {
16172 goto evalstart;
16173 }
16174 }
16175 else {
16176 stopVarNamePtr = expr->expr->right->objPtr;
@@ -16205,10 +17429,14 @@
16205 break;
16206 }
16207
16208
16209 retval = Jim_EvalObj(interp, argv[4]);
 
 
 
 
16210 if (retval == JIM_OK || retval == JIM_CONTINUE) {
16211 retval = JIM_OK;
16212
16213 objPtr = Jim_GetVariable(interp, varNamePtr, JIM_ERRMSG);
16214
@@ -16241,10 +17469,14 @@
16241
16242 if (retval == JIM_OK || retval == JIM_CONTINUE) {
16243
16244 JIM_IF_OPTIM(evalnext:)
16245 retval = Jim_EvalObj(interp, argv[3]);
 
 
 
 
16246 if (retval == JIM_OK || retval == JIM_CONTINUE) {
16247
16248 JIM_IF_OPTIM(testcond:)
16249 retval = Jim_GetBoolFromExpr(interp, argv[2], &boolean);
16250 }
@@ -16256,13 +17488,15 @@
16256 }
16257 if (varNamePtr) {
16258 Jim_DecrRefCount(interp, varNamePtr);
16259 }
16260
16261 if (retval == JIM_CONTINUE || retval == JIM_BREAK || retval == JIM_OK) {
16262 Jim_SetEmptyResult(interp);
16263 return JIM_OK;
 
 
16264 }
16265
16266 return retval;
16267 }
16268
@@ -16273,26 +17507,38 @@
16273 jim_wide i;
16274 jim_wide limit;
16275 jim_wide incr = 1;
16276 Jim_Obj *bodyObjPtr;
16277
16278 if (argc != 5 && argc != 6) {
16279 Jim_WrongNumArgs(interp, 1, argv, "var first limit ?incr? body");
16280 return JIM_ERR;
16281 }
16282
16283 if (Jim_GetWide(interp, argv[2], &i) != JIM_OK ||
16284 Jim_GetWide(interp, argv[3], &limit) != JIM_OK ||
16285 (argc == 6 && Jim_GetWide(interp, argv[4], &incr) != JIM_OK)) {
16286 return JIM_ERR;
16287 }
16288 bodyObjPtr = (argc == 5) ? argv[4] : argv[5];
16289
16290 retval = Jim_SetVariable(interp, argv[1], argv[2]);
 
 
 
 
 
 
 
 
 
16291
16292 while (((i < limit && incr > 0) || (i > limit && incr < 0)) && retval == JIM_OK) {
16293 retval = Jim_EvalObj(interp, bodyObjPtr);
 
 
 
16294 if (retval == JIM_OK || retval == JIM_CONTINUE) {
16295 Jim_Obj *objPtr = Jim_GetVariable(interp, argv[1], JIM_ERRMSG);
16296
16297 retval = JIM_OK;
16298
@@ -16429,11 +17675,15 @@
16429 if (result != JIM_OK) {
16430 goto err;
16431 }
16432 }
16433 }
16434 switch (result = Jim_EvalObj(interp, script)) {
 
 
 
 
16435 case JIM_OK:
16436 if (doMap) {
16437 Jim_ListAppendElement(interp, resultObj, interp->result);
16438 }
16439 break;
@@ -16550,23 +17800,25 @@
16550 Jim_WrongNumArgs(interp, 1, argv, "condition ?then? trueBody ?elseif ...? ?else? falseBody");
16551 return JIM_ERR;
16552 }
16553
16554
16555
16556 int Jim_CommandMatchObj(Jim_Interp *interp, Jim_Obj *commandObj, Jim_Obj *patternObj,
16557 Jim_Obj *stringObj, int nocase)
16558 {
16559 Jim_Obj *parms[4];
16560 int argc = 0;
16561 long eq;
16562 int rc;
16563
16564 parms[argc++] = commandObj;
16565 if (nocase) {
16566 parms[argc++] = Jim_NewStringObj(interp, "-nocase", -1);
16567 }
 
 
 
16568 parms[argc++] = patternObj;
16569 parms[argc++] = stringObj;
16570
16571 rc = Jim_EvalObjVector(interp, argc, parms);
16572
@@ -16580,10 +17832,11 @@
16580
16581 static int Jim_SwitchCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
16582 {
16583 enum { SWITCH_EXACT, SWITCH_GLOB, SWITCH_RE, SWITCH_CMD };
16584 int matchOpt = SWITCH_EXACT, opt = 1, patCount, i;
 
16585 Jim_Obj *command = NULL, *scriptObj = NULL, *strObj;
16586 Jim_Obj **caseList;
16587
16588 if (argc < 3) {
16589 wrongnumargs:
@@ -16602,12 +17855,14 @@
16602 }
16603 else if (strncmp(option, "-exact", 2) == 0)
16604 matchOpt = SWITCH_EXACT;
16605 else if (strncmp(option, "-glob", 2) == 0)
16606 matchOpt = SWITCH_GLOB;
16607 else if (strncmp(option, "-regexp", 2) == 0)
16608 matchOpt = SWITCH_RE;
 
 
16609 else if (strncmp(option, "-command", 2) == 0) {
16610 matchOpt = SWITCH_CMD;
16611 if ((argc - opt) < 2)
16612 goto wrongnumargs;
16613 command = argv[++opt];
@@ -16646,11 +17901,11 @@
16646 break;
16647 case SWITCH_RE:
16648 command = Jim_NewStringObj(interp, "regexp", -1);
16649
16650 case SWITCH_CMD:{
16651 int rc = Jim_CommandMatchObj(interp, command, patObj, strObj, 0);
16652
16653 if (argc - opt == 1) {
16654 JimListGetElements(interp, argv[opt], &patCount, &caseList);
16655 }
16656
@@ -16691,37 +17946,26 @@
16691 }
16692
16693
16694 static int Jim_LindexCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
16695 {
16696 Jim_Obj *objPtr, *listObjPtr;
16697 int i;
16698 int idx;
16699
16700 if (argc < 2) {
16701 Jim_WrongNumArgs(interp, 1, argv, "list ?index ...?");
16702 return JIM_ERR;
16703 }
16704 objPtr = argv[1];
16705 Jim_IncrRefCount(objPtr);
16706 for (i = 2; i < argc; i++) {
16707 listObjPtr = objPtr;
16708 if (Jim_GetIndex(interp, argv[i], &idx) != JIM_OK) {
16709 Jim_DecrRefCount(interp, listObjPtr);
16710 return JIM_ERR;
16711 }
16712 if (Jim_ListIndex(interp, listObjPtr, idx, &objPtr, JIM_NONE) != JIM_OK) {
16713 Jim_DecrRefCount(interp, listObjPtr);
16714 Jim_SetEmptyResult(interp);
16715 return JIM_OK;
16716 }
16717 Jim_IncrRefCount(objPtr);
16718 Jim_DecrRefCount(interp, listObjPtr);
16719 }
16720 Jim_SetResult(interp, objPtr);
16721 Jim_DecrRefCount(interp, objPtr);
16722 return JIM_OK;
16723 }
16724
16725
16726 static int Jim_LlengthCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
16727 {
@@ -16736,31 +17980,33 @@
16736
16737 static int Jim_LsearchCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
16738 {
16739 static const char * const options[] = {
16740 "-bool", "-not", "-nocase", "-exact", "-glob", "-regexp", "-all", "-inline", "-command",
16741 NULL
16742 };
16743 enum
16744 { OPT_BOOL, OPT_NOT, OPT_NOCASE, OPT_EXACT, OPT_GLOB, OPT_REGEXP, OPT_ALL, OPT_INLINE,
16745 OPT_COMMAND };
16746 int i;
16747 int opt_bool = 0;
16748 int opt_not = 0;
16749 int opt_nocase = 0;
16750 int opt_all = 0;
16751 int opt_inline = 0;
16752 int opt_match = OPT_EXACT;
16753 int listlen;
16754 int rc = JIM_OK;
16755 Jim_Obj *listObjPtr = NULL;
16756 Jim_Obj *commandObj = NULL;
 
 
 
16757
16758 if (argc < 3) {
16759 wrongargs:
16760 Jim_WrongNumArgs(interp, 1, argv,
16761 "?-exact|-glob|-regexp|-command 'command'? ?-bool|-inline? ?-not? ?-nocase? ?-all? list value");
16762 return JIM_ERR;
16763 }
16764
16765 for (i = 1; i < argc - 2; i++) {
16766 int option;
@@ -16775,34 +18021,65 @@
16775 break;
16776 case OPT_NOT:
16777 opt_not = 1;
16778 break;
16779 case OPT_NOCASE:
16780 opt_nocase = 1;
16781 break;
16782 case OPT_INLINE:
16783 opt_inline = 1;
16784 opt_bool = 0;
16785 break;
16786 case OPT_ALL:
16787 opt_all = 1;
16788 break;
 
 
 
 
16789 case OPT_COMMAND:
16790 if (i >= argc - 2) {
16791 goto wrongargs;
16792 }
16793 commandObj = argv[++i];
16794
16795 case OPT_EXACT:
16796 case OPT_GLOB:
16797 case OPT_REGEXP:
16798 opt_match = option;
16799 break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16800 }
16801 }
16802
 
 
 
 
16803 argv += i;
 
 
 
 
 
 
16804
16805 if (opt_all) {
16806 listObjPtr = Jim_NewListObj(interp, NULL, 0);
16807 }
16808 if (opt_match == OPT_REGEXP) {
@@ -16810,68 +18087,104 @@
16810 }
16811 if (commandObj) {
16812 Jim_IncrRefCount(commandObj);
16813 }
16814
16815 listlen = Jim_ListLength(interp, argv[0]);
16816 for (i = 0; i < listlen; i++) {
16817 int eq = 0;
16818 Jim_Obj *objPtr = Jim_ListGetIndex(interp, argv[0], i);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16819
16820 switch (opt_match) {
16821 case OPT_EXACT:
16822 eq = Jim_StringCompareObj(interp, argv[1], objPtr, opt_nocase) == 0;
16823 break;
16824
16825 case OPT_GLOB:
16826 eq = Jim_StringMatchObj(interp, argv[1], objPtr, opt_nocase);
16827 break;
16828
16829 case OPT_REGEXP:
16830 case OPT_COMMAND:
16831 eq = Jim_CommandMatchObj(interp, commandObj, argv[1], objPtr, opt_nocase);
16832 if (eq < 0) {
16833 if (listObjPtr) {
16834 Jim_FreeNewObj(interp, listObjPtr);
16835 }
16836 rc = JIM_ERR;
16837 goto done;
16838 }
16839 break;
16840 }
16841
16842
16843 if (!eq && opt_bool && opt_not && !opt_all) {
16844 continue;
16845 }
16846
16847 if ((!opt_bool && eq == !opt_not) || (opt_bool && (eq || opt_all))) {
16848
16849 Jim_Obj *resultObj;
16850
16851 if (opt_bool) {
16852 resultObj = Jim_NewIntObj(interp, eq ^ opt_not);
16853 }
16854 else if (!opt_inline) {
16855 resultObj = Jim_NewIntObj(interp, i);
16856 }
16857 else {
16858 resultObj = objPtr;
16859 }
 
 
 
 
 
 
 
 
 
 
16860
16861 if (opt_all) {
16862 Jim_ListAppendElement(interp, listObjPtr, resultObj);
 
 
 
16863 }
16864 else {
16865 Jim_SetResult(interp, resultObj);
 
16866 goto done;
16867 }
16868 }
 
16869 }
16870
16871 if (opt_all) {
16872 Jim_SetResult(interp, listObjPtr);
 
16873 }
16874 else {
16875
16876 if (opt_bool) {
16877 Jim_SetResultBool(interp, opt_not);
@@ -16880,10 +18193,13 @@
16880 Jim_SetResultInt(interp, -1);
16881 }
16882 }
16883
16884 done:
 
 
 
16885 if (commandObj) {
16886 Jim_DecrRefCount(interp, commandObj);
16887 }
16888 return rc;
16889 }
@@ -16993,11 +18309,11 @@
16993
16994
16995 static int Jim_LsetCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
16996 {
16997 if (argc < 3) {
16998 Jim_WrongNumArgs(interp, 1, argv, "listVar ?index...? newVal");
16999 return JIM_ERR;
17000 }
17001 else if (argc == 3) {
17002
17003 if (Jim_SetVariable(interp, argv[1], argv[2]) != JIM_OK)
@@ -17010,29 +18326,34 @@
17010
17011
17012 static int Jim_LsortCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const argv[])
17013 {
17014 static const char * const options[] = {
17015 "-ascii", "-nocase", "-increasing", "-decreasing", "-command", "-integer", "-real", "-index", "-unique", NULL
 
17016 };
17017 enum
17018 { OPT_ASCII, OPT_NOCASE, OPT_INCREASING, OPT_DECREASING, OPT_COMMAND, OPT_INTEGER, OPT_REAL, OPT_INDEX, OPT_UNIQUE };
 
 
17019 Jim_Obj *resObj;
17020 int i;
17021 int retCode;
17022 int shared;
 
17023
17024 struct lsort_info info;
17025
17026 if (argc < 2) {
 
17027 Jim_WrongNumArgs(interp, 1, argv, "?options? list");
17028 return JIM_ERR;
17029 }
17030
17031 info.type = JIM_LSORT_ASCII;
17032 info.order = 1;
17033 info.indexed = 0;
17034 info.unique = 0;
17035 info.command = NULL;
17036 info.interp = interp;
17037
17038 for (i = 1; i < (argc - 1); i++) {
@@ -17069,33 +18390,77 @@
17069 return JIM_ERR;
17070 }
17071 info.type = JIM_LSORT_COMMAND;
17072 info.command = argv[i + 1];
17073 i++;
 
 
 
 
 
 
 
 
 
 
 
 
17074 break;
17075 case OPT_INDEX:
17076 if (i >= (argc - 2)) {
 
17077 Jim_SetResultString(interp, "\"-index\" option must be followed by list index", -1);
17078 return JIM_ERR;
17079 }
17080 if (Jim_GetIndex(interp, argv[i + 1], &info.index) != JIM_OK) {
17081 return JIM_ERR;
 
17082 }
17083 info.indexed = 1;
17084 i++;
17085 break;
17086 }
17087 }
17088 resObj = argv[argc - 1];
17089 if ((shared = Jim_IsShared(resObj)))
17090 resObj = Jim_DuplicateObj(interp, resObj);
17091 retCode = ListSortElements(interp, resObj, &info);
17092 if (retCode == JIM_OK) {
17093 Jim_SetResult(interp, resObj);
17094 }
17095 else if (shared) {
17096 Jim_FreeNewObj(interp, resObj);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17097 }
17098 return retCode;
17099 }
17100
17101
@@ -17139,17 +18504,10 @@
17139 return JIM_OK;
17140 }
17141
17142
17143
17144 static int Jim_DebugCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
17145 {
17146 #if !defined(JIM_DEBUG_COMMAND)
17147 Jim_SetResultString(interp, "unsupported", -1);
17148 return JIM_ERR;
17149 #endif
17150 }
17151
17152
17153 static int Jim_EvalCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
17154 {
17155 int rc;
@@ -17164,14 +18522,10 @@
17164 }
17165 else {
17166 rc = Jim_EvalObj(interp, Jim_ConcatObj(interp, argc - 1, argv + 1));
17167 }
17168
17169 if (rc == JIM_ERR) {
17170
17171 interp->addStackTrace++;
17172 }
17173 return rc;
17174 }
17175
17176
17177 static int Jim_UplevelCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
@@ -17224,10 +18578,16 @@
17224 int retcode;
17225
17226 if (argc == 2) {
17227 retcode = Jim_EvalExpression(interp, argv[1]);
17228 }
 
 
 
 
 
 
17229 else if (argc > 2) {
17230 Jim_Obj *objPtr;
17231
17232 objPtr = Jim_ConcatObj(interp, argc - 1, argv + 1);
17233 Jim_IncrRefCount(objPtr);
@@ -17236,33 +18596,72 @@
17236 }
17237 else {
17238 Jim_WrongNumArgs(interp, 1, argv, "expression ?...?");
17239 return JIM_ERR;
17240 }
17241 if (retcode != JIM_OK)
17242 return retcode;
17243 return JIM_OK;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17244 }
17245
17246
17247 static int Jim_BreakCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
17248 {
17249 if (argc != 1) {
17250 Jim_WrongNumArgs(interp, 1, argv, "");
17251 return JIM_ERR;
17252 }
17253 return JIM_BREAK;
17254 }
17255
17256
17257 static int Jim_ContinueCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
17258 {
17259 if (argc != 1) {
17260 Jim_WrongNumArgs(interp, 1, argv, "");
17261 return JIM_ERR;
 
 
 
 
 
 
 
 
 
 
 
 
17262 }
17263 return JIM_CONTINUE;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17264 }
17265
17266
17267 static int Jim_ReturnCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
17268 {
@@ -17312,11 +18711,11 @@
17312 interp->returnLevel = level;
17313
17314 if (i == argc - 1) {
17315 Jim_SetResult(interp, argv[i]);
17316 }
17317 return JIM_RETURN;
17318 }
17319
17320
17321 static int Jim_TailcallCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
17322 {
@@ -17370,28 +18769,21 @@
17370 }
17371
17372 static int Jim_AliasCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
17373 {
17374 Jim_Obj *prefixListObj;
17375 const char *newname;
17376
17377 if (argc < 3) {
17378 Jim_WrongNumArgs(interp, 1, argv, "newname command ?args ...?");
17379 return JIM_ERR;
17380 }
17381
17382 prefixListObj = Jim_NewListObj(interp, argv + 2, argc - 2);
17383 Jim_IncrRefCount(prefixListObj);
17384 newname = Jim_String(argv[1]);
17385 if (newname[0] == ':' && newname[1] == ':') {
17386 while (*++newname == ':') {
17387 }
17388 }
17389
17390 Jim_SetResult(interp, argv[1]);
17391
17392 return Jim_CreateCommand(interp, newname, JimAliasCmd, prefixListObj, JimAliasCmdDelete);
17393 }
17394
17395
17396 static int Jim_ProcCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
17397 {
@@ -17400,40 +18792,54 @@
17400 if (argc != 4 && argc != 5) {
17401 Jim_WrongNumArgs(interp, 1, argv, "name arglist ?statics? body");
17402 return JIM_ERR;
17403 }
17404
17405 if (JimValidName(interp, "procedure", argv[1]) != JIM_OK) {
17406 return JIM_ERR;
17407 }
17408
17409 if (argc == 4) {
17410 cmd = JimCreateProcedureCmd(interp, argv[2], NULL, argv[3], NULL);
17411 }
17412 else {
17413 cmd = JimCreateProcedureCmd(interp, argv[2], argv[3], argv[4], NULL);
17414 }
17415
17416 if (cmd) {
17417
17418 Jim_Obj *qualifiedCmdNameObj;
17419 const char *cmdname = JimQualifyName(interp, Jim_String(argv[1]), &qualifiedCmdNameObj);
17420
17421 JimCreateCommand(interp, cmdname, cmd);
17422
17423
17424 JimUpdateProcNamespace(interp, cmd, cmdname);
17425
17426 JimFreeQualifiedName(interp, qualifiedCmdNameObj);
17427
17428
17429 Jim_SetResult(interp, argv[1]);
17430 return JIM_OK;
17431 }
17432 return JIM_ERR;
17433 }
17434
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17435
17436 static int Jim_LocalCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
17437 {
17438 int retcode;
17439
@@ -17518,11 +18924,11 @@
17518 }
17519
17520 if (len == 3) {
17521 #ifdef jim_ext_namespace
17522
17523 nsObj = JimQualifyNameObj(interp, Jim_ListGetIndex(interp, argv[1], 2));
17524 #else
17525 Jim_SetResultString(interp, "namespaces not enabled", -1);
17526 return JIM_ERR;
17527 #endif
17528 }
@@ -17641,11 +19047,11 @@
17641 k = Jim_String(eachObjPtr);
17642 kl = Jim_Utf8Length(interp, eachObjPtr);
17643
17644 if (strLen >= kl && kl) {
17645 int rc;
17646 rc = JimStringCompareLen(str, k, kl, nocase);
17647 if (rc == 0) {
17648 if (noMatchStart) {
17649 Jim_AppendString(interp, resultObjPtr, noMatchStart, str - noMatchStart);
17650 noMatchStart = NULL;
17651 }
@@ -17674,50 +19080,85 @@
17674 static int Jim_StringCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
17675 {
17676 int len;
17677 int opt_case = 1;
17678 int option;
17679 static const char * const options[] = {
17680 "bytelength", "length", "compare", "match", "equal", "is", "byterange", "range", "replace",
17681 "map", "repeat", "reverse", "index", "first", "last", "cat",
17682 "trim", "trimleft", "trimright", "tolower", "toupper", "totitle", NULL
17683 };
17684 enum
17685 {
17686 OPT_BYTELENGTH, OPT_LENGTH, OPT_COMPARE, OPT_MATCH, OPT_EQUAL, OPT_IS, OPT_BYTERANGE, OPT_RANGE, OPT_REPLACE,
17687 OPT_MAP, OPT_REPEAT, OPT_REVERSE, OPT_INDEX, OPT_FIRST, OPT_LAST, OPT_CAT,
17688 OPT_TRIM, OPT_TRIMLEFT, OPT_TRIMRIGHT, OPT_TOLOWER, OPT_TOUPPER, OPT_TOTITLE
17689 };
17690 static const char * const nocase_options[] = {
17691 "-nocase", NULL
17692 };
17693 static const char * const nocase_length_options[] = {
17694 "-nocase", "-length", NULL
17695 };
17696
17697 if (argc < 2) {
17698 Jim_WrongNumArgs(interp, 1, argv, "option ?arguments ...?");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17699 return JIM_ERR;
17700 }
17701 if (Jim_GetEnum(interp, argv[1], options, &option, NULL,
17702 JIM_ERRMSG | JIM_ENUM_ABBREV) != JIM_OK)
17703 return Jim_CheckShowCommands(interp, argv[1], options);
 
 
 
17704
17705 switch (option) {
17706 case OPT_LENGTH:
 
 
 
17707 case OPT_BYTELENGTH:
17708 if (argc != 3) {
17709 Jim_WrongNumArgs(interp, 2, argv, "string");
17710 return JIM_ERR;
17711 }
17712 if (option == OPT_LENGTH) {
17713 len = Jim_Utf8Length(interp, argv[2]);
17714 }
17715 else {
17716 len = Jim_Length(argv[2]);
17717 }
17718 Jim_SetResultInt(interp, len);
17719 return JIM_OK;
17720
17721 case OPT_CAT:{
17722 Jim_Obj *objPtr;
17723 if (argc == 3) {
@@ -17747,11 +19188,11 @@
17747 while (n > 0) {
17748 int subopt;
17749 if (Jim_GetEnum(interp, argv[i++], nocase_length_options, &subopt, NULL,
17750 JIM_ENUM_ABBREV) != JIM_OK) {
17751 badcompareargs:
17752 Jim_WrongNumArgs(interp, 2, argv, "?-nocase? ?-length int? string1 string2");
17753 return JIM_ERR;
17754 }
17755 if (subopt == 0) {
17756
17757 opt_case = 0;
@@ -17775,16 +19216,23 @@
17775 if (opt_length < 0 && option != OPT_COMPARE && opt_case) {
17776
17777 Jim_SetResultBool(interp, Jim_StringEqObj(argv[0], argv[1]));
17778 }
17779 else {
 
 
 
 
17780 if (opt_length >= 0) {
17781 n = JimStringCompareLen(Jim_String(argv[0]), Jim_String(argv[1]), opt_length, !opt_case);
17782 }
17783 else {
17784 n = Jim_StringCompareObj(interp, argv[0], argv[1], !opt_case);
 
 
17785 }
 
17786 Jim_SetResultInt(interp, option == OPT_COMPARE ? n : n == 0);
17787 }
17788 return JIM_OK;
17789 }
17790
@@ -17822,41 +19270,30 @@
17822 }
17823 Jim_SetResult(interp, objPtr);
17824 return JIM_OK;
17825 }
17826
17827 case OPT_RANGE:
 
 
 
 
 
 
 
 
17828 case OPT_BYTERANGE:{
17829 Jim_Obj *objPtr;
17830
17831 if (argc != 5) {
17832 Jim_WrongNumArgs(interp, 2, argv, "string first last");
17833 return JIM_ERR;
17834 }
17835 if (option == OPT_RANGE) {
17836 objPtr = Jim_StringRangeObj(interp, argv[2], argv[3], argv[4]);
17837 }
17838 else
17839 {
17840 objPtr = Jim_StringByteRangeObj(interp, argv[2], argv[3], argv[4]);
17841 }
17842
17843 if (objPtr == NULL) {
17844 return JIM_ERR;
17845 }
17846 Jim_SetResult(interp, objPtr);
17847 return JIM_OK;
17848 }
17849
17850 case OPT_REPLACE:{
17851 Jim_Obj *objPtr;
17852
17853 if (argc != 5 && argc != 6) {
17854 Jim_WrongNumArgs(interp, 2, argv, "string first last ?string?");
17855 return JIM_ERR;
17856 }
17857 objPtr = JimStringReplaceObj(interp, argv[2], argv[3], argv[4], argc == 6 ? argv[5] : NULL);
17858 if (objPtr == NULL) {
17859 return JIM_ERR;
17860 }
17861 Jim_SetResult(interp, objPtr);
17862 return JIM_OK;
@@ -17865,15 +19302,11 @@
17865
17866 case OPT_REPEAT:{
17867 Jim_Obj *objPtr;
17868 jim_wide count;
17869
17870 if (argc != 4) {
17871 Jim_WrongNumArgs(interp, 2, argv, "string count");
17872 return JIM_ERR;
17873 }
17874 if (Jim_GetWide(interp, argv[3], &count) != JIM_OK) {
17875 return JIM_ERR;
17876 }
17877 objPtr = Jim_NewStringObj(interp, "", 0);
17878 if (count > 0) {
17879 while (count--) {
@@ -17887,17 +19320,13 @@
17887 case OPT_REVERSE:{
17888 char *buf, *p;
17889 const char *str;
17890 int i;
17891
17892 if (argc != 3) {
17893 Jim_WrongNumArgs(interp, 2, argv, "string");
17894 return JIM_ERR;
17895 }
17896
17897 str = Jim_GetString(argv[2], &len);
17898 buf = Jim_Alloc(len + 1);
 
17899 p = buf + len;
17900 *p = 0;
17901 for (i = 0; i < len; ) {
17902 int c;
17903 int l = utf8_tounicode(str, &c);
@@ -17912,22 +19341,16 @@
17912
17913 case OPT_INDEX:{
17914 int idx;
17915 const char *str;
17916
17917 if (argc != 4) {
17918 Jim_WrongNumArgs(interp, 2, argv, "string index");
17919 return JIM_ERR;
17920 }
17921 if (Jim_GetIndex(interp, argv[3], &idx) != JIM_OK) {
17922 return JIM_ERR;
17923 }
17924 str = Jim_String(argv[2]);
17925 len = Jim_Utf8Length(interp, argv[2]);
17926 if (idx != INT_MIN && idx != INT_MAX) {
17927 idx = JimRelToAbsIndex(len, idx);
17928 }
17929 if (idx < 0 || idx >= len || str == NULL) {
17930 Jim_SetResultString(interp, "", 0);
17931 }
17932 else if (len == Jim_Length(argv[2])) {
17933
@@ -17944,23 +19367,22 @@
17944 case OPT_FIRST:
17945 case OPT_LAST:{
17946 int idx = 0, l1, l2;
17947 const char *s1, *s2;
17948
17949 if (argc != 4 && argc != 5) {
17950 Jim_WrongNumArgs(interp, 2, argv, "subString string ?index?");
17951 return JIM_ERR;
17952 }
17953 s1 = Jim_String(argv[2]);
17954 s2 = Jim_String(argv[3]);
17955 l1 = Jim_Utf8Length(interp, argv[2]);
17956 l2 = Jim_Utf8Length(interp, argv[3]);
17957 if (argc == 5) {
17958 if (Jim_GetIndex(interp, argv[4], &idx) != JIM_OK) {
17959 return JIM_ERR;
17960 }
17961 idx = JimRelToAbsIndex(l2, idx);
 
 
 
17962 }
17963 else if (option == OPT_LAST) {
17964 idx = l2;
17965 }
17966 if (option == OPT_FIRST) {
@@ -17975,66 +19397,45 @@
17975 }
17976 return JIM_OK;
17977 }
17978
17979 case OPT_TRIM:
 
 
17980 case OPT_TRIMLEFT:
 
 
17981 case OPT_TRIMRIGHT:{
17982 Jim_Obj *trimchars;
17983
17984 if (argc != 3 && argc != 4) {
17985 Jim_WrongNumArgs(interp, 2, argv, "string ?trimchars?");
17986 return JIM_ERR;
17987 }
17988 trimchars = (argc == 4 ? argv[3] : NULL);
17989 if (option == OPT_TRIM) {
17990 Jim_SetResult(interp, JimStringTrim(interp, argv[2], trimchars));
17991 }
17992 else if (option == OPT_TRIMLEFT) {
17993 Jim_SetResult(interp, JimStringTrimLeft(interp, argv[2], trimchars));
17994 }
17995 else if (option == OPT_TRIMRIGHT) {
17996 Jim_SetResult(interp, JimStringTrimRight(interp, argv[2], trimchars));
17997 }
17998 return JIM_OK;
17999 }
18000
18001 case OPT_TOLOWER:
18002 case OPT_TOUPPER:
18003 case OPT_TOTITLE:
18004 if (argc != 3) {
18005 Jim_WrongNumArgs(interp, 2, argv, "string");
18006 return JIM_ERR;
18007 }
18008 if (option == OPT_TOLOWER) {
18009 Jim_SetResult(interp, JimStringToLower(interp, argv[2]));
18010 }
18011 else if (option == OPT_TOUPPER) {
18012 Jim_SetResult(interp, JimStringToUpper(interp, argv[2]));
18013 }
18014 else {
18015 Jim_SetResult(interp, JimStringToTitle(interp, argv[2]));
18016 }
18017 return JIM_OK;
18018
18019 case OPT_IS:
18020 if (argc == 4 || (argc == 5 && Jim_CompareStringImmediate(interp, argv[3], "-strict"))) {
18021 return JimStringIs(interp, argv[argc - 1], argv[2], argc == 5);
 
18022 }
18023 Jim_WrongNumArgs(interp, 2, argv, "class ?-strict? str");
18024 return JIM_ERR;
18025 }
18026 return JIM_OK;
18027 }
18028
18029
18030 static int Jim_TimeCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
18031 {
18032 long i, count = 1;
18033 jim_wide start, elapsed;
18034 char buf[60];
18035 const char *fmt = "%" JIM_WIDE_MODIFIER " microseconds per iteration";
18036
18037 if (argc < 2) {
18038 Jim_WrongNumArgs(interp, 1, argv, "script ?count?");
18039 return JIM_ERR;
18040 }
@@ -18043,22 +19444,92 @@
18043 return JIM_ERR;
18044 }
18045 if (count < 0)
18046 return JIM_OK;
18047 i = count;
18048 start = JimClock();
18049 while (i-- > 0) {
18050 int retval;
18051
18052 retval = Jim_EvalObj(interp, argv[1]);
18053 if (retval != JIM_OK) {
18054 return retval;
18055 }
18056 }
18057 elapsed = JimClock() - start;
18058 sprintf(buf, fmt, count == 0 ? 0 : elapsed / count);
18059 Jim_SetResultString(interp, buf, -1);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18060 return JIM_OK;
18061 }
18062
18063
18064 static int Jim_ExitCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
@@ -18070,25 +19541,55 @@
18070 return JIM_ERR;
18071 }
18072 if (argc == 2) {
18073 if (Jim_GetLong(interp, argv[1], &exitCode) != JIM_OK)
18074 return JIM_ERR;
 
18075 }
18076 interp->exitCode = exitCode;
18077 return JIM_EXIT;
18078 }
18079
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18080
18081 static int Jim_CatchCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
 
18082 {
 
 
 
 
18083 int exitCode = 0;
18084 int i;
18085 int sig = 0;
 
 
 
 
 
 
 
18086
18087
18088 jim_wide ignore_mask = (1 << JIM_EXIT) | (1 << JIM_EVAL) | (1 << JIM_SIGNAL);
18089 static const int max_ignore_code = sizeof(ignore_mask) * 8;
 
 
18090
18091 Jim_SetGlobalVariableStr(interp, "errorCode", Jim_NewStringObj(interp, "NONE", -1));
18092
18093 for (i = 1; i < argc - 1; i++) {
18094 const char *arg = Jim_String(argv[i]);
@@ -18129,18 +19630,17 @@
18129 else {
18130 ignore_mask &= (~((jim_wide)1 << option));
18131 }
18132 }
18133
18134 argc -= i;
18135 if (argc < 1 || argc > 3) {
18136 wrongargs:
18137 Jim_WrongNumArgs(interp, 1, argv,
18138 "?-?no?code ... --? script ?resultVarName? ?optionVarName?");
18139 return JIM_ERR;
18140 }
18141 argv += i;
18142
18143 if ((ignore_mask & (1 << JIM_SIGNAL)) == 0) {
18144 sig++;
18145 }
18146
@@ -18148,64 +19648,172 @@
18148 if (Jim_CheckSignal(interp)) {
18149
18150 exitCode = JIM_SIGNAL;
18151 }
18152 else {
18153 exitCode = Jim_EvalObj(interp, argv[0]);
18154
18155 interp->errorFlag = 0;
18156 }
18157 interp->signal_level -= sig;
18158
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18159
18160 if (exitCode >= 0 && exitCode < max_ignore_code && (((unsigned jim_wide)1 << exitCode) & ignore_mask)) {
18161
 
 
 
18162 return exitCode;
18163 }
18164
18165 if (sig && exitCode == JIM_SIGNAL) {
18166
18167 if (interp->signal_set_result) {
18168 interp->signal_set_result(interp, interp->sigmask);
18169 }
18170 else {
18171 Jim_SetResultInt(interp, interp->sigmask);
18172 }
18173 interp->sigmask = 0;
18174 }
18175
18176 if (argc >= 2) {
18177 if (Jim_SetVariable(interp, argv[1], Jim_GetResult(interp)) != JIM_OK) {
18178 return JIM_ERR;
18179 }
18180 if (argc == 3) {
18181 Jim_Obj *optListObj = Jim_NewListObj(interp, NULL, 0);
18182
18183 Jim_ListAppendElement(interp, optListObj, Jim_NewStringObj(interp, "-code", -1));
18184 Jim_ListAppendElement(interp, optListObj,
18185 Jim_NewIntObj(interp, exitCode == JIM_RETURN ? interp->returnCode : exitCode));
18186 Jim_ListAppendElement(interp, optListObj, Jim_NewStringObj(interp, "-level", -1));
18187 Jim_ListAppendElement(interp, optListObj, Jim_NewIntObj(interp, interp->returnLevel));
18188 if (exitCode == JIM_ERR) {
18189 Jim_Obj *errorCode;
18190 Jim_ListAppendElement(interp, optListObj, Jim_NewStringObj(interp, "-errorinfo",
18191 -1));
18192 Jim_ListAppendElement(interp, optListObj, interp->stackTrace);
18193
18194 errorCode = Jim_GetGlobalVariableStr(interp, "errorCode", JIM_NONE);
18195 if (errorCode) {
18196 Jim_ListAppendElement(interp, optListObj, Jim_NewStringObj(interp, "-errorcode", -1));
18197 Jim_ListAppendElement(interp, optListObj, errorCode);
18198 }
18199 }
18200 if (Jim_SetVariable(interp, argv[2], optListObj) != JIM_OK) {
18201 return JIM_ERR;
18202 }
18203 }
18204 }
18205 Jim_SetResultInt(interp, exitCode);
18206 return JIM_OK;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18207 }
18208
18209
18210
18211 static int Jim_RenameCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
@@ -18213,46 +19821,44 @@
18213 if (argc != 3) {
18214 Jim_WrongNumArgs(interp, 1, argv, "oldName newName");
18215 return JIM_ERR;
18216 }
18217
18218 if (JimValidName(interp, "new procedure", argv[2])) {
18219 return JIM_ERR;
18220 }
18221
18222 return Jim_RenameCommand(interp, Jim_String(argv[1]), Jim_String(argv[2]));
18223 }
18224
18225 #define JIM_DICTMATCH_KEYS 0x0001
18226 #define JIM_DICTMATCH_VALUES 0x002
18227
18228 int Jim_DictMatchTypes(Jim_Interp *interp, Jim_Obj *objPtr, Jim_Obj *patternObj, int match_type, int return_types)
18229 {
18230 Jim_HashEntry *he;
18231 Jim_Obj *listObjPtr;
18232 Jim_HashTableIterator htiter;
 
18233
18234 if (SetDictFromAny(interp, objPtr) != JIM_OK) {
18235 return JIM_ERR;
18236 }
 
18237
18238 listObjPtr = Jim_NewListObj(interp, NULL, 0);
18239
18240 JimInitHashTableIterator(objPtr->internalRep.ptr, &htiter);
18241 while ((he = Jim_NextHashEntry(&htiter)) != NULL) {
 
18242 if (patternObj) {
18243 Jim_Obj *matchObj = (match_type == JIM_DICTMATCH_KEYS) ? (Jim_Obj *)he->key : Jim_GetHashEntryVal(he);
18244 if (!JimGlobMatch(Jim_String(patternObj), Jim_String(matchObj), 0)) {
18245
18246 continue;
18247 }
18248 }
18249 if (return_types & JIM_DICTMATCH_KEYS) {
18250 Jim_ListAppendElement(interp, listObjPtr, (Jim_Obj *)he->key);
18251 }
18252 if (return_types & JIM_DICTMATCH_VALUES) {
18253 Jim_ListAppendElement(interp, listObjPtr, Jim_GetHashEntryVal(he));
18254 }
18255 }
18256
18257 Jim_SetResult(interp, listObjPtr);
18258 return JIM_OK;
@@ -18261,11 +19867,11 @@
18261 int Jim_DictSize(Jim_Interp *interp, Jim_Obj *objPtr)
18262 {
18263 if (SetDictFromAny(interp, objPtr) != JIM_OK) {
18264 return -1;
18265 }
18266 return ((Jim_HashTable *)objPtr->internalRep.ptr)->used;
18267 }
18268
18269 Jim_Obj *Jim_DictMerge(Jim_Interp *interp, int objc, Jim_Obj *const *objv)
18270 {
18271 Jim_Obj *objPtr = Jim_NewDictObj(interp, NULL, 0);
@@ -18274,73 +19880,41 @@
18274 JimPanic((objc == 0, "Jim_DictMerge called with objc=0"));
18275
18276
18277
18278 for (i = 0; i < objc; i++) {
18279 Jim_HashTable *ht;
18280 Jim_HashTableIterator htiter;
18281 Jim_HashEntry *he;
18282
18283 if (SetDictFromAny(interp, objv[i]) != JIM_OK) {
 
18284 Jim_FreeNewObj(interp, objPtr);
18285 return NULL;
18286 }
18287 ht = objv[i]->internalRep.ptr;
18288 JimInitHashTableIterator(ht, &htiter);
18289 while ((he = Jim_NextHashEntry(&htiter)) != NULL) {
18290 Jim_ReplaceHashEntry(objPtr->internalRep.ptr, Jim_GetHashEntryKey(he), Jim_GetHashEntryVal(he));
18291 }
18292 }
18293 return objPtr;
18294 }
18295
18296 int Jim_DictInfo(Jim_Interp *interp, Jim_Obj *objPtr)
18297 {
18298 Jim_HashTable *ht;
18299 unsigned int i;
18300 char buffer[100];
18301 int sum = 0;
18302 int nonzero_count = 0;
18303 Jim_Obj *output;
18304 int bucket_counts[11] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
18305
18306 if (SetDictFromAny(interp, objPtr) != JIM_OK) {
18307 return JIM_ERR;
18308 }
18309
18310 ht = (Jim_HashTable *)objPtr->internalRep.ptr;
18311
18312
18313 snprintf(buffer, sizeof(buffer), "%d entries in table, %d buckets\n", ht->used, ht->size);
18314 output = Jim_NewStringObj(interp, buffer, -1);
18315
18316 for (i = 0; i < ht->size; i++) {
18317 Jim_HashEntry *he = ht->table[i];
18318 int entries = 0;
18319 while (he) {
18320 entries++;
18321 he = he->next;
18322 }
18323 if (entries > 9) {
18324 bucket_counts[10]++;
18325 }
18326 else {
18327 bucket_counts[entries]++;
18328 }
18329 if (entries) {
18330 sum += entries;
18331 nonzero_count++;
18332 }
18333 }
18334 for (i = 0; i < 10; i++) {
18335 snprintf(buffer, sizeof(buffer), "number of buckets with %d entries: %d\n", i, bucket_counts[i]);
18336 Jim_AppendString(interp, output, buffer, -1);
18337 }
18338 snprintf(buffer, sizeof(buffer), "number of buckets with 10 or more entries: %d\n", bucket_counts[10]);
18339 Jim_AppendString(interp, output, buffer, -1);
18340 snprintf(buffer, sizeof(buffer), "average search distance for entry: %.1f", nonzero_count ? (double)sum / nonzero_count : 0.0);
18341 Jim_AppendString(interp, output, buffer, -1);
18342 Jim_SetResult(interp, output);
18343 return JIM_OK;
18344 }
18345
18346 static int Jim_EvalEnsemble(Jim_Interp *interp, const char *basecmd, const char *subcmd, int argc, Jim_Obj *const *argv)
@@ -18366,16 +19940,16 @@
18366 dictObj = Jim_GetVariable(interp, dictVarName, JIM_ERRMSG);
18367 if (dictObj == NULL || Jim_DictKeysVector(interp, dictObj, keyv, keyc, &objPtr, JIM_ERRMSG) != JIM_OK) {
18368 return JIM_ERR;
18369 }
18370
18371 if (Jim_DictPairs(interp, objPtr, &dictValues, &len) == JIM_ERR) {
 
18372 return JIM_ERR;
18373 }
18374 for (i = 0; i < len; i += 2) {
18375 if (Jim_SetVariable(interp, dictValues[i], dictValues[i + 1]) == JIM_ERR) {
18376 Jim_Free(dictValues);
18377 return JIM_ERR;
18378 }
18379 }
18380
18381
@@ -18390,110 +19964,137 @@
18390 newkeyv[i] = keyv[i];
18391 }
18392
18393 for (i = 0; i < len; i += 2) {
18394
18395 objPtr = Jim_GetVariable(interp, dictValues[i], 0);
18396 newkeyv[keyc] = dictValues[i];
18397 Jim_SetDictKeysVector(interp, dictVarName, newkeyv, keyc + 1, objPtr, 0);
 
 
 
18398 }
18399 Jim_Free(newkeyv);
18400 }
18401 }
18402
18403 Jim_Free(dictValues);
18404
18405 return ret;
18406 }
18407
18408
18409 static int Jim_DictCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
18410 {
18411 Jim_Obj *objPtr;
18412 int types = JIM_DICTMATCH_KEYS;
18413 int option;
18414 static const char * const options[] = {
18415 "create", "get", "set", "unset", "exists", "keys", "size", "info",
18416 "merge", "with", "append", "lappend", "incr", "remove", "values", "for",
18417 "replace", "update", NULL
18418 };
18419 enum
18420 {
18421 OPT_CREATE, OPT_GET, OPT_SET, OPT_UNSET, OPT_EXISTS, OPT_KEYS, OPT_SIZE, OPT_INFO,
18422 OPT_MERGE, OPT_WITH, OPT_APPEND, OPT_LAPPEND, OPT_INCR, OPT_REMOVE, OPT_VALUES, OPT_FOR,
18423 OPT_REPLACE, OPT_UPDATE,
18424 };
18425
18426 if (argc < 2) {
18427 Jim_WrongNumArgs(interp, 1, argv, "subcommand ?arguments ...?");
18428 return JIM_ERR;
18429 }
18430
18431 if (Jim_GetEnum(interp, argv[1], options, &option, "subcommand", JIM_ERRMSG) != JIM_OK) {
18432 return Jim_CheckShowCommands(interp, argv[1], options);
18433 }
18434
18435 switch (option) {
18436 case OPT_GET:
18437 if (argc < 3) {
18438 Jim_WrongNumArgs(interp, 2, argv, "dictionary ?key ...?");
18439 return JIM_ERR;
18440 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18441 if (Jim_DictKeysVector(interp, argv[2], argv + 3, argc - 3, &objPtr,
18442 JIM_ERRMSG) != JIM_OK) {
18443 return JIM_ERR;
18444 }
18445 Jim_SetResult(interp, objPtr);
18446 return JIM_OK;
18447
18448 case OPT_SET:
18449 if (argc < 5) {
18450 Jim_WrongNumArgs(interp, 2, argv, "varName key ?key ...? value");
 
 
18451 return JIM_ERR;
18452 }
 
 
 
 
 
 
 
 
 
 
18453 return Jim_SetDictKeysVector(interp, argv[2], argv + 3, argc - 4, argv[argc - 1], JIM_ERRMSG);
18454
18455 case OPT_EXISTS:
18456 if (argc < 4) {
18457 Jim_WrongNumArgs(interp, 2, argv, "dictionary key ?key ...?");
18458 return JIM_ERR;
18459 }
18460 else {
18461 int rc = Jim_DictKeysVector(interp, argv[2], argv + 3, argc - 3, &objPtr, JIM_ERRMSG);
18462 if (rc < 0) {
18463 return JIM_ERR;
18464 }
18465 Jim_SetResultBool(interp, rc == JIM_OK);
18466 return JIM_OK;
18467 }
18468
18469 case OPT_UNSET:
18470 if (argc < 4) {
18471 Jim_WrongNumArgs(interp, 2, argv, "varName key ?key ...?");
18472 return JIM_ERR;
18473 }
18474 if (Jim_SetDictKeysVector(interp, argv[2], argv + 3, argc - 3, NULL, 0) != JIM_OK) {
18475 return JIM_ERR;
18476 }
18477 return JIM_OK;
18478
18479 case OPT_VALUES:
18480 types = JIM_DICTMATCH_VALUES;
18481
18482 case OPT_KEYS:
18483 if (argc != 3 && argc != 4) {
18484 Jim_WrongNumArgs(interp, 2, argv, "dictionary ?pattern?");
18485 return JIM_ERR;
18486 }
18487 return Jim_DictMatchTypes(interp, argv[2], argc == 4 ? argv[3] : NULL, types, types);
18488
18489 case OPT_SIZE:
18490 if (argc != 3) {
18491 Jim_WrongNumArgs(interp, 2, argv, "dictionary");
18492 return JIM_ERR;
18493 }
18494 else if (Jim_DictSize(interp, argv[2]) < 0) {
18495 return JIM_ERR;
18496 }
18497 Jim_SetResultInt(interp, Jim_DictSize(interp, argv[2]));
18498 return JIM_OK;
18499
@@ -18506,42 +20107,30 @@
18506 return JIM_ERR;
18507 }
18508 Jim_SetResult(interp, objPtr);
18509 return JIM_OK;
18510
18511 case OPT_UPDATE:
18512 if (argc < 6 || argc % 2) {
18513
18514 argc = 2;
18515 }
18516 break;
18517
18518 case OPT_CREATE:
18519 if (argc % 2) {
18520 Jim_WrongNumArgs(interp, 2, argv, "?key value ...?");
18521 return JIM_ERR;
18522 }
18523 objPtr = Jim_NewDictObj(interp, argv + 2, argc - 2);
18524 Jim_SetResult(interp, objPtr);
18525 return JIM_OK;
18526
18527 case OPT_INFO:
18528 if (argc != 3) {
18529 Jim_WrongNumArgs(interp, 2, argv, "dictionary");
18530 return JIM_ERR;
18531 }
18532 return Jim_DictInfo(interp, argv[2]);
18533
18534 case OPT_WITH:
18535 if (argc < 4) {
18536 Jim_WrongNumArgs(interp, 2, argv, "dictVar ?key ...? script");
18537 return JIM_ERR;
18538 }
18539 return JimDictWith(interp, argv[2], argv + 3, argc - 4, argv[argc - 1]);
 
 
 
 
 
 
 
 
 
18540 }
18541
18542 return Jim_EvalEnsemble(interp, "dict", options[option], argc - 2, argv + 2);
18543 }
18544
18545
18546 static int Jim_SubstCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
18547 {
@@ -18582,30 +20171,79 @@
18582 }
18583 Jim_SetResult(interp, objPtr);
18584 return JIM_OK;
18585 }
18586
 
 
 
 
 
 
 
 
 
18587
18588 static int Jim_InfoCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
18589 {
18590 int cmd;
18591 Jim_Obj *objPtr;
18592 int mode = 0;
18593
18594 static const char * const commands[] = {
18595 "body", "statics", "commands", "procs", "channels", "exists", "globals", "level", "frame", "locals",
18596 "vars", "version", "patchlevel", "complete", "args", "hostname",
18597 "script", "source", "stacktrace", "nameofexecutable", "returncodes",
18598 "references", "alias", NULL
18599 };
18600 enum
18601 { INFO_BODY, INFO_STATICS, INFO_COMMANDS, INFO_PROCS, INFO_CHANNELS, INFO_EXISTS, INFO_GLOBALS, INFO_LEVEL,
18602 INFO_FRAME, INFO_LOCALS, INFO_VARS, INFO_VERSION, INFO_PATCHLEVEL, INFO_COMPLETE, INFO_ARGS,
18603 INFO_HOSTNAME, INFO_SCRIPT, INFO_SOURCE, INFO_STACKTRACE, INFO_NAMEOFEXECUTABLE,
18604 INFO_RETURNCODES, INFO_REFERENCES, INFO_ALIAS,
18605 };
18606
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18607 #ifdef jim_ext_namespace
18608 int nons = 0;
18609
18610 if (argc > 2 && Jim_CompareStringImmediate(interp, argv[1], "-nons")) {
18611
@@ -18612,36 +20250,29 @@
18612 argc--;
18613 argv++;
18614 nons = 1;
18615 }
18616 #endif
18617
18618 if (argc < 2) {
18619 Jim_WrongNumArgs(interp, 1, argv, "subcommand ?args ...?");
18620 return JIM_ERR;
18621 }
18622 if (Jim_GetEnum(interp, argv[1], commands, &cmd, "subcommand", JIM_ERRMSG | JIM_ENUM_ABBREV) != JIM_OK) {
18623 return Jim_CheckShowCommands(interp, argv[1], commands);
 
18624 }
18625
 
18626
18627 switch (cmd) {
18628 case INFO_EXISTS:
18629 if (argc != 3) {
18630 Jim_WrongNumArgs(interp, 2, argv, "varName");
18631 return JIM_ERR;
18632 }
18633 Jim_SetResultBool(interp, Jim_GetVariable(interp, argv[2], 0) != NULL);
18634 break;
18635
18636 case INFO_ALIAS:{
18637 Jim_Cmd *cmdPtr;
18638
18639 if (argc != 3) {
18640 Jim_WrongNumArgs(interp, 2, argv, "command");
18641 return JIM_ERR;
18642 }
18643 if ((cmdPtr = Jim_GetCommand(interp, argv[2], JIM_ERRMSG)) == NULL) {
18644 return JIM_ERR;
18645 }
18646 if (cmdPtr->isproc || cmdPtr->u.native.cmdProc != JimAliasCmd) {
18647 Jim_SetResultFormatted(interp, "command \"%#s\" is not an alias", argv[2]);
@@ -18661,61 +20292,54 @@
18661 case INFO_PROCS:
18662 mode++;
18663
18664 case INFO_COMMANDS:
18665
18666 if (argc != 2 && argc != 3) {
18667 Jim_WrongNumArgs(interp, 2, argv, "?pattern?");
18668 return JIM_ERR;
18669 }
18670 #ifdef jim_ext_namespace
18671 if (!nons) {
18672 if (Jim_Length(interp->framePtr->nsObj) || (argc == 3 && JimGlobMatch("::*", Jim_String(argv[2]), 0))) {
18673 return Jim_EvalPrefix(interp, "namespace info", argc - 1, argv + 1);
18674 }
18675 }
18676 #endif
18677 Jim_SetResult(interp, JimCommandsList(interp, (argc == 3) ? argv[2] : NULL, mode));
18678 break;
18679
18680 case INFO_VARS:
18681 mode++;
18682
18683 case INFO_LOCALS:
18684 mode++;
18685
18686 case INFO_GLOBALS:
18687
18688 if (argc != 2 && argc != 3) {
18689 Jim_WrongNumArgs(interp, 2, argv, "?pattern?");
18690 return JIM_ERR;
18691 }
18692 #ifdef jim_ext_namespace
18693 if (!nons) {
18694 if (Jim_Length(interp->framePtr->nsObj) || (argc == 3 && JimGlobMatch("::*", Jim_String(argv[2]), 0))) {
18695 return Jim_EvalPrefix(interp, "namespace info", argc - 1, argv + 1);
18696 }
18697 }
18698 #endif
18699 Jim_SetResult(interp, JimVariablesList(interp, argc == 3 ? argv[2] : NULL, mode));
18700 break;
18701
18702 case INFO_SCRIPT:
18703 if (argc != 2) {
18704 Jim_WrongNumArgs(interp, 2, argv, "");
18705 return JIM_ERR;
 
18706 }
18707 Jim_SetResult(interp, JimGetScript(interp, interp->currentScriptObj)->fileNameObj);
18708 break;
18709
18710 case INFO_SOURCE:{
18711 jim_wide line;
18712 Jim_Obj *resObjPtr;
18713 Jim_Obj *fileNameObj;
18714
18715 if (argc != 3 && argc != 5) {
18716 Jim_WrongNumArgs(interp, 2, argv, "source ?filename line?");
18717 return JIM_ERR;
18718 }
18719 if (argc == 5) {
18720 if (Jim_GetWide(interp, argv[4], &line) != JIM_OK) {
18721 return JIM_ERR;
@@ -18740,93 +20364,94 @@
18740 resObjPtr = Jim_NewListObj(interp, NULL, 0);
18741 Jim_ListAppendElement(interp, resObjPtr, fileNameObj);
18742 Jim_ListAppendElement(interp, resObjPtr, Jim_NewIntObj(interp, line));
18743 }
18744 Jim_SetResult(interp, resObjPtr);
18745 break;
18746 }
18747
18748 case INFO_STACKTRACE:
18749 Jim_SetResult(interp, interp->stackTrace);
18750 break;
18751
18752 case INFO_LEVEL:
18753 case INFO_FRAME:
18754 switch (argc) {
18755 case 2:
18756 Jim_SetResultInt(interp, interp->framePtr->level);
18757 break;
18758
18759 case 3:
18760 if (JimInfoLevel(interp, argv[2], &objPtr, cmd == INFO_LEVEL) != JIM_OK) {
18761 return JIM_ERR;
18762 }
18763 Jim_SetResult(interp, objPtr);
18764 break;
18765
18766 default:
18767 Jim_WrongNumArgs(interp, 2, argv, "?levelNum?");
18768 return JIM_ERR;
18769 }
18770 break;
 
 
 
 
18771
18772 case INFO_BODY:
18773 case INFO_STATICS:
18774 case INFO_ARGS:{
18775 Jim_Cmd *cmdPtr;
18776
18777 if (argc != 3) {
18778 Jim_WrongNumArgs(interp, 2, argv, "procname");
18779 return JIM_ERR;
18780 }
18781 if ((cmdPtr = Jim_GetCommand(interp, argv[2], JIM_ERRMSG)) == NULL) {
18782 return JIM_ERR;
18783 }
18784 if (!cmdPtr->isproc) {
18785 Jim_SetResultFormatted(interp, "command \"%#s\" is not a procedure", argv[2]);
18786 return JIM_ERR;
18787 }
18788 switch (cmd) {
 
 
 
 
 
18789 case INFO_BODY:
18790 Jim_SetResult(interp, cmdPtr->u.proc.bodyObjPtr);
18791 break;
18792 case INFO_ARGS:
18793 Jim_SetResult(interp, cmdPtr->u.proc.argListObjPtr);
18794 break;
 
18795 case INFO_STATICS:
18796 if (cmdPtr->u.proc.staticVars) {
18797 Jim_SetResult(interp, JimHashtablePatternMatch(interp, cmdPtr->u.proc.staticVars,
18798 NULL, JimVariablesMatch, JIM_VARLIST_LOCALS | JIM_VARLIST_VALUES));
18799 }
18800 break;
18801 }
18802 break;
18803 }
18804
18805 case INFO_VERSION:
18806 case INFO_PATCHLEVEL:{
18807 char buf[(JIM_INTEGER_SPACE * 2) + 1];
18808
18809 sprintf(buf, "%d.%d", JIM_VERSION / 100, JIM_VERSION % 100);
18810 Jim_SetResultString(interp, buf, -1);
18811 break;
18812 }
18813
18814 case INFO_COMPLETE:
18815 if (argc != 3 && argc != 4) {
18816 Jim_WrongNumArgs(interp, 2, argv, "script ?missing?");
18817 return JIM_ERR;
18818 }
18819 else {
18820 char missing;
18821
18822 Jim_SetResultBool(interp, Jim_ScriptIsComplete(interp, argv[2], &missing));
18823 if (missing != ' ' && argc == 4) {
18824 Jim_SetVariable(interp, argv[3], Jim_NewStringObj(interp, &missing, 1));
18825 }
 
18826 }
18827 break;
18828
18829 case INFO_HOSTNAME:
18830
18831 return Jim_Eval(interp, "os.gethostname");
18832
@@ -18860,24 +20485,21 @@
18860 }
18861 else {
18862 Jim_SetResultString(interp, name, -1);
18863 }
18864 }
18865 else {
18866 Jim_WrongNumArgs(interp, 2, argv, "?code?");
18867 return JIM_ERR;
18868 }
18869 break;
18870 case INFO_REFERENCES:
18871 #ifdef JIM_REFERENCES
18872 return JimInfoReferences(interp, argc, argv);
18873 #else
18874 Jim_SetResultString(interp, "not supported", -1);
18875 return JIM_ERR;
18876 #endif
 
 
18877 }
18878 return JIM_OK;
18879 }
18880
18881
18882 static int Jim_ExistsCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
18883 {
@@ -19145,11 +20767,10 @@
19145 Jim_SetResult(interp, argv[1]);
19146 if (argc == 3) {
19147 JimSetStackTrace(interp, argv[2]);
19148 return JIM_ERR;
19149 }
19150 interp->addStackTrace++;
19151 return JIM_ERR;
19152 }
19153
19154
19155 static int Jim_LrangeCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
@@ -19168,26 +20789,27 @@
19168
19169
19170 static int Jim_LrepeatCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
19171 {
19172 Jim_Obj *objPtr;
19173 long count;
19174
19175 if (argc < 2 || Jim_GetLong(interp, argv[1], &count) != JIM_OK || count < 0) {
19176 Jim_WrongNumArgs(interp, 1, argv, "count ?value ...?");
19177 return JIM_ERR;
19178 }
19179
19180 if (count == 0 || argc == 2) {
 
19181 return JIM_OK;
19182 }
19183
19184 argc -= 2;
19185 argv += 2;
19186
19187 objPtr = Jim_NewListObj(interp, argv, argc);
19188 while (--count) {
 
19189 ListInsertElements(objPtr, -1, argc, argv);
19190 }
19191
19192 Jim_SetResult(interp, objPtr);
19193 return JIM_OK;
@@ -19243,11 +20865,11 @@
19243
19244 Jim_SetResult(interp, listObjPtr);
19245 return JIM_OK;
19246 }
19247
19248 if (argc < 2) {
19249 Jim_WrongNumArgs(interp, 1, argv, "varName ?default?");
19250 return JIM_ERR;
19251 }
19252 key = Jim_String(argv[1]);
19253 val = getenv(key);
@@ -19286,12 +20908,13 @@
19286 if (argc != 2) {
19287 Jim_WrongNumArgs(interp, 1, argv, "list");
19288 return JIM_ERR;
19289 }
19290 JimListGetElements(interp, argv[1], &len, &ele);
19291 len--;
19292 revObjPtr = Jim_NewListObj(interp, NULL, 0);
 
 
19293 while (len >= 0)
19294 ListAppendElement(revObjPtr, ele[len--]);
19295 Jim_SetResult(interp, revObjPtr);
19296 return JIM_OK;
19297 }
@@ -19329,25 +20952,26 @@
19329 if (argc < 2 || argc > 4) {
19330 Jim_WrongNumArgs(interp, 1, argv, "?start? end ?step?");
19331 return JIM_ERR;
19332 }
19333 if (argc == 2) {
19334 if (Jim_GetWide(interp, argv[1], &end) != JIM_OK)
19335 return JIM_ERR;
19336 }
19337 else {
19338 if (Jim_GetWide(interp, argv[1], &start) != JIM_OK ||
19339 Jim_GetWide(interp, argv[2], &end) != JIM_OK)
19340 return JIM_ERR;
19341 if (argc == 4 && Jim_GetWide(interp, argv[3], &step) != JIM_OK)
19342 return JIM_ERR;
19343 }
19344 if ((len = JimRangeLen(start, end, step)) == -1) {
19345 Jim_SetResultString(interp, "Invalid (infinite?) range specified", -1);
19346 return JIM_ERR;
19347 }
19348 objPtr = Jim_NewListObj(interp, NULL, 0);
 
19349 for (i = 0; i < len; i++)
19350 ListAppendElement(objPtr, Jim_NewIntObj(interp, start + i * step));
19351 Jim_SetResult(interp, objPtr);
19352 return JIM_OK;
19353 }
@@ -19362,15 +20986,15 @@
19362 return JIM_ERR;
19363 }
19364 if (argc == 1) {
19365 max = JIM_WIDE_MAX;
19366 } else if (argc == 2) {
19367 if (Jim_GetWide(interp, argv[1], &max) != JIM_OK)
19368 return JIM_ERR;
19369 } else if (argc == 3) {
19370 if (Jim_GetWide(interp, argv[1], &min) != JIM_OK ||
19371 Jim_GetWide(interp, argv[2], &max) != JIM_OK)
19372 return JIM_ERR;
19373 }
19374 len = max-min;
19375 if (len < 0) {
19376 Jim_SetResultString(interp, "Invalid arguments (max < min)", -1);
@@ -19417,25 +21041,27 @@
19417 {"lappend", Jim_LappendCoreCommand},
19418 {"linsert", Jim_LinsertCoreCommand},
19419 {"lreplace", Jim_LreplaceCoreCommand},
19420 {"lsort", Jim_LsortCoreCommand},
19421 {"append", Jim_AppendCoreCommand},
19422 {"debug", Jim_DebugCoreCommand},
19423 {"eval", Jim_EvalCoreCommand},
19424 {"uplevel", Jim_UplevelCoreCommand},
19425 {"expr", Jim_ExprCoreCommand},
19426 {"break", Jim_BreakCoreCommand},
19427 {"continue", Jim_ContinueCoreCommand},
19428 {"proc", Jim_ProcCoreCommand},
 
19429 {"concat", Jim_ConcatCoreCommand},
19430 {"return", Jim_ReturnCoreCommand},
19431 {"upvar", Jim_UpvarCoreCommand},
19432 {"global", Jim_GlobalCoreCommand},
19433 {"string", Jim_StringCoreCommand},
19434 {"time", Jim_TimeCoreCommand},
 
19435 {"exit", Jim_ExitCoreCommand},
19436 {"catch", Jim_CatchCoreCommand},
 
19437 #ifdef JIM_REFERENCES
19438 {"ref", Jim_RefCoreCommand},
19439 {"getref", Jim_GetrefCoreCommand},
19440 {"setref", Jim_SetrefCoreCommand},
19441 {"finalize", Jim_FinalizeCoreCommand},
@@ -19460,10 +21086,11 @@
19460 {"rand", Jim_RandCoreCommand},
19461 {"tailcall", Jim_TailcallCoreCommand},
19462 {"local", Jim_LocalCoreCommand},
19463 {"upcall", Jim_UpcallCoreCommand},
19464 {"apply", Jim_ApplyCoreCommand},
 
19465 {NULL, NULL},
19466 };
19467
19468 void Jim_RegisterCoreCommands(Jim_Interp *interp)
19469 {
@@ -19687,22 +21314,30 @@
19687 for (i = 0; i < nobjparam; i++) {
19688 Jim_DecrRefCount(interp, objparam[i]);
19689 }
19690 }
19691
 
 
 
 
 
 
 
 
 
19692
19693 #ifndef jim_ext_package
19694 int Jim_PackageProvide(Jim_Interp *interp, const char *name, const char *ver, int flags)
19695 {
19696 return JIM_OK;
19697 }
19698 #endif
19699 #ifndef jim_ext_aio
19700 FILE *Jim_AioFilehandle(Jim_Interp *interp, Jim_Obj *fhObj)
19701 {
19702 Jim_SetResultString(interp, "aio not enabled", -1);
19703 return NULL;
19704 }
19705 #endif
19706
19707
19708 #include <stdio.h>
@@ -19717,34 +21352,45 @@
19717
19718 static const jim_subcmd_type dummy_subcmd = {
19719 "dummy", NULL, subcmd_null, 0, 0, JIM_MODFLAG_HIDDEN
19720 };
19721
19722 static void add_commands(Jim_Interp *interp, const jim_subcmd_type * ct, const char *sep)
19723 {
19724 const char *s = "";
 
 
19725
19726 for (; ct->cmd; ct++) {
19727 if (!(ct->flags & JIM_MODFLAG_HIDDEN)) {
19728 Jim_AppendStrings(interp, Jim_GetResult(interp), s, ct->cmd, NULL);
19729 s = sep;
19730 }
19731 }
 
 
 
 
 
 
 
 
 
 
19732 }
19733
19734 static void bad_subcmd(Jim_Interp *interp, const jim_subcmd_type * command_table, const char *type,
19735 Jim_Obj *cmd, Jim_Obj *subcmd)
19736 {
19737 Jim_SetResultFormatted(interp, "%#s, %s command \"%#s\": should be ", cmd, type, subcmd);
19738 add_commands(interp, command_table, ", ");
19739 }
19740
19741 static void show_cmd_usage(Jim_Interp *interp, const jim_subcmd_type * command_table, int argc,
19742 Jim_Obj *const *argv)
19743 {
19744 Jim_SetResultFormatted(interp, "Usage: \"%#s command ... \", where command is one of: ", argv[0]);
19745 add_commands(interp, command_table, ", ");
19746 }
19747
19748 static void add_cmd_usage(Jim_Interp *interp, const jim_subcmd_type * ct, Jim_Obj *cmd)
19749 {
19750 if (cmd) {
@@ -19754,14 +21400,14 @@
19754 if (ct->args && *ct->args) {
19755 Jim_AppendStrings(interp, Jim_GetResult(interp), " ", ct->args, NULL);
19756 }
19757 }
19758
19759 static void set_wrong_args(Jim_Interp *interp, const jim_subcmd_type * command_table, Jim_Obj *subcmd)
19760 {
19761 Jim_SetResultString(interp, "wrong # args: should be \"", -1);
19762 add_cmd_usage(interp, command_table, subcmd);
19763 Jim_AppendStrings(interp, Jim_GetResult(interp), "\"", NULL);
19764 }
19765
19766 static const Jim_ObjType subcmdLookupObjType = {
19767 "subcmd-lookup",
@@ -19778,10 +21424,11 @@
19778 const jim_subcmd_type *partial = 0;
19779 int cmdlen;
19780 Jim_Obj *cmd;
19781 const char *cmdstr;
19782 int help = 0;
 
19783
19784 if (argc < 2) {
19785 Jim_SetResultFormatted(interp, "wrong # args: should be \"%#s command ...\"\n"
19786 "Use \"%#s -help ?command?\" for help", argv[0], argv[0]);
19787 return 0;
@@ -19810,13 +21457,11 @@
19810 cmd = argv[2];
19811 }
19812
19813
19814 if (Jim_CompareStringImmediate(interp, cmd, "-commands")) {
19815
19816 Jim_SetResult(interp, Jim_NewEmptyStringObj(interp));
19817 add_commands(interp, command_table, " ");
19818 return &dummy_subcmd;
19819 }
19820
19821 cmdstr = Jim_GetString(cmd, &cmdlen);
19822
@@ -19870,11 +21515,22 @@
19870 cmd->internalRep.ptrIntValue.ptr = (void *)command_table;
19871 cmd->internalRep.ptrIntValue.int1 = ct - command_table;
19872
19873 found:
19874
19875 if (argc - 2 < ct->minargs || (ct->maxargs >= 0 && argc - 2 > ct->maxargs)) {
 
 
 
 
 
 
 
 
 
 
 
19876 Jim_SetResultString(interp, "wrong # args: should be \"", -1);
19877
19878 add_cmd_usage(interp, ct, argv[0]);
19879 Jim_AppendStrings(interp, Jim_GetResult(interp), "\"", NULL);
19880
@@ -19895,11 +21551,11 @@
19895 }
19896 else {
19897 ret = ct->function(interp, argc - 2, argv + 2);
19898 }
19899 if (ret < 0) {
19900 set_wrong_args(interp, ct, argv[0]);
19901 ret = JIM_ERR;
19902 }
19903 }
19904 return ret;
19905 }
@@ -19946,10 +21602,11 @@
19946 }
19947 }
19948
19949 #include <ctype.h>
19950 #include <string.h>
 
19951
19952
19953 #define JIM_INTEGER_SPACE 24
19954 #define MAX_FLOAT_WIDTH 320
19955
@@ -20192,11 +21849,11 @@
20192 }
20193
20194 j = 0;
20195 for (i = length; i > 0; ) {
20196 i--;
20197 if (w & ((unsigned jim_wide)1 << i)) {
20198 num_buffer[j++] = '1';
20199 }
20200 else if (j || i == 0) {
20201 num_buffer[j++] = '0';
20202 }
@@ -20428,11 +22085,11 @@
20428 n++;
20429 }
20430 return n;
20431 }
20432
20433 int regcomp(regex_t *preg, const char *exp, int cflags)
20434 {
20435 int scan;
20436 int longest;
20437 unsigned len;
20438 int flags;
@@ -20843,11 +22500,11 @@
20843 if (*pattern == ']' || *pattern == '-') {
20844 reg_addrange(preg, *pattern, *pattern);
20845 pattern++;
20846 }
20847
20848 while (*pattern && *pattern != ']') {
20849
20850 int start;
20851 int end;
20852
20853 enum {
@@ -20854,10 +22511,15 @@
20854 CC_ALPHA, CC_ALNUM, CC_SPACE, CC_BLANK, CC_UPPER, CC_LOWER,
20855 CC_DIGIT, CC_XDIGIT, CC_CNTRL, CC_GRAPH, CC_PRINT, CC_PUNCT,
20856 CC_NUM
20857 };
20858 int cc;
 
 
 
 
 
20859
20860 pattern += reg_utf8_tounicode_case(pattern, &start, nocase);
20861 if (start == '\\') {
20862
20863 switch (*pattern) {
@@ -20878,10 +22540,14 @@
20878 pattern += reg_decode_escape(pattern, &start);
20879 if (start == 0) {
20880 preg->err = REG_ERR_NULL_CHAR;
20881 return 0;
20882 }
 
 
 
 
20883 }
20884 if (pattern[0] == '-' && pattern[1] && pattern[1] != ']') {
20885
20886 pattern += utf8_tounicode(pattern, &end);
20887 pattern += reg_utf8_tounicode_case(pattern, &end, nocase);
@@ -20888,10 +22554,14 @@
20888 if (end == '\\') {
20889 pattern += reg_decode_escape(pattern, &end);
20890 if (end == 0) {
20891 preg->err = REG_ERR_NULL_CHAR;
20892 return 0;
 
 
 
 
20893 }
20894 }
20895
20896 reg_addrange(preg, start, end);
20897 continue;
@@ -20903,10 +22573,14 @@
20903 };
20904
20905 for (cc = 0; cc < CC_NUM; cc++) {
20906 n = strlen(character_class[cc]);
20907 if (strncmp(pattern, character_class[cc], n) == 0) {
 
 
 
 
20908
20909 pattern += n + 1;
20910 break;
20911 }
20912 }
@@ -20993,11 +22667,11 @@
20993 return 0;
20994 case '\\':
20995 ch = *preg->regparse++;
20996 switch (ch) {
20997 case '\0':
20998 preg->err = REG_ERR_TRAILING_BACKSLASH;
20999 return 0;
21000 case 'A':
21001 ret = regnode(preg, BOLX);
21002 break;
21003 case 'Z':
@@ -21180,11 +22854,11 @@
21180
21181 static int regtry(regex_t *preg, const char *string );
21182 static int regmatch(regex_t *preg, int prog);
21183 static int regrepeat(regex_t *preg, int p, int max);
21184
21185 int regexec(regex_t *preg, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags)
21186 {
21187 const char *s;
21188 int scan;
21189
21190
@@ -21521,11 +23195,11 @@
21521 break;
21522 case WORDZ:
21523
21524 if (preg->reginput > preg->regbol) {
21525
21526 if (reg_iseol(preg, c) || !isalnum(UCHAR(c)) || c != '_') {
21527 c = preg->reginput[-1];
21528
21529 if (isalnum(UCHAR(c)) || c == '_') {
21530 break;
21531 }
@@ -21617,10 +23291,12 @@
21617 preg->pmatch[no].rm_eo = save - preg->start;
21618 }
21619 }
21620 return(1);
21621 }
 
 
21622 return(0);
21623 }
21624 return REG_ERR_INTERNAL;
21625 }
21626
@@ -21640,14 +23316,13 @@
21640
21641 scan = preg->reginput;
21642 opnd = OPERAND(p);
21643 switch (OP(preg, p)) {
21644 case ANY:
21645
21646 while (!reg_iseol(preg, *scan) && count < max) {
21647 count++;
21648 scan++;
21649 }
21650 break;
21651 case EXACTLY:
21652 while (count < max) {
21653 n = reg_utf8_tounicode_case(scan, &ch, preg->cflags & REG_ICASE);
@@ -21724,11 +23399,11 @@
21724 }
21725 return 2;
21726 }
21727
21728
21729 size_t regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)
21730 {
21731 static const char *error_strings[] = {
21732 "success",
21733 "no match",
21734 "bad pattern",
@@ -21743,13 +23418,14 @@
21743 "extra characters",
21744 "*+ of empty atom",
21745 "nested count",
21746 "internal error",
21747 "count follows nothing",
21748 "trailing backslash",
21749 "corrupted program",
21750 "contains null char",
 
21751 };
21752 const char *err;
21753
21754 if (errcode < 0 || errcode >= REG_ERR_NUM) {
21755 err = "Bad error code";
@@ -21759,11 +23435,11 @@
21759 }
21760
21761 return snprintf(errbuf, errbuf_size, "%s", err);
21762 }
21763
21764 void regfree(regex_t *preg)
21765 {
21766 free(preg->program);
21767 }
21768
21769 #endif
@@ -21856,20 +23532,46 @@
21856 case ERROR_DIRECTORY: return ENOTDIR;
21857 }
21858 return EINVAL;
21859 }
21860
21861 pidtype waitpid(pidtype pid, int *status, int nohang)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21862 {
21863 DWORD ret = WaitForSingleObject(pid, nohang ? 0 : INFINITE);
 
21864 if (ret == WAIT_TIMEOUT || ret == WAIT_FAILED) {
21865
21866 return JIM_BAD_PID;
21867 }
21868 GetExitCodeProcess(pid, &ret);
21869 *status = ret;
21870 CloseHandle(pid);
 
 
21871 return pid;
21872 }
21873
21874 int Jim_MakeTempFile(Jim_Interp *interp, const char *filename_template, int unlink_file)
21875 {
@@ -21887,11 +23589,11 @@
21887 if (handle == INVALID_HANDLE_VALUE) {
21888 goto error;
21889 }
21890
21891 Jim_SetResultString(interp, name, -1);
21892 return _open_osfhandle((int)handle, _O_RDWR | _O_TEXT);
21893
21894 error:
21895 Jim_SetResultErrno(interp, name);
21896 DeleteFile(name);
21897 return -1;
@@ -22125,10 +23827,11 @@
22125 return buf;
22126 }
22127 #ifndef JIM_BOOTSTRAP_LIB_ONLY
22128 #include <errno.h>
22129 #include <string.h>
 
22130
22131
22132 #ifdef USE_LINENOISE
22133 #ifdef HAVE_UNISTD_H
22134 #include <unistd.h>
@@ -22140,42 +23843,58 @@
22140 #else
22141 #define MAX_LINE_LEN 512
22142 #endif
22143
22144 #ifdef USE_LINENOISE
 
 
 
 
 
 
 
 
22145 static void JimCompletionCallback(const char *prefix, linenoiseCompletions *comp, void *userdata);
22146 static const char completion_callback_assoc_key[] = "interactive-completion";
 
 
22147 #endif
22148
22149 char *Jim_HistoryGetline(Jim_Interp *interp, const char *prompt)
22150 {
22151 #ifdef USE_LINENOISE
22152 struct JimCompletionInfo *compinfo = Jim_GetAssocData(interp, completion_callback_assoc_key);
22153 char *result;
22154 Jim_Obj *objPtr;
22155 long mlmode = 0;
22156 if (compinfo) {
22157 linenoiseSetCompletionCallback(JimCompletionCallback, compinfo);
22158 }
 
 
 
 
22159 objPtr = Jim_GetVariableStr(interp, "history::multiline", JIM_NONE);
22160 if (objPtr && Jim_GetLong(interp, objPtr, &mlmode) == JIM_NONE) {
22161 linenoiseSetMultiLine(mlmode);
22162 }
22163
22164 result = linenoise(prompt);
22165
22166 linenoiseSetCompletionCallback(NULL, NULL);
 
 
22167 return result;
22168 #else
22169 int len;
22170 char *line = malloc(MAX_LINE_LEN);
22171
22172 fputs(prompt, stdout);
22173 fflush(stdout);
22174
22175 if (fgets(line, MAX_LINE_LEN, stdin) == NULL) {
22176 free(line);
22177 return NULL;
22178 }
22179 len = strlen(line);
22180 if (len && line[len - 1] == '\n') {
22181 line[len - 1] = '\0';
@@ -22224,23 +23943,33 @@
22224 printf("%4d %s\n", i + 1, history[i]);
22225 }
22226 #endif
22227 }
22228
 
 
 
 
 
 
 
 
 
22229 #ifdef USE_LINENOISE
22230 struct JimCompletionInfo {
22231 Jim_Interp *interp;
22232 Jim_Obj *command;
22233 };
22234
 
22235 static void JimCompletionCallback(const char *prefix, linenoiseCompletions *comp, void *userdata)
22236 {
22237 struct JimCompletionInfo *info = (struct JimCompletionInfo *)userdata;
22238 Jim_Obj *objv[2];
22239 int ret;
22240
22241 objv[0] = info->command;
22242 objv[1] = Jim_NewStringObj(info->interp, prefix, -1);
22243
22244 ret = Jim_EvalObjVector(info->interp, 2, objv);
22245
22246
@@ -22251,38 +23980,106 @@
22251 for (i = 0; i < len; i++) {
22252 linenoiseAddCompletion(comp, Jim_String(Jim_ListGetIndex(info->interp, listObj, i)));
22253 }
22254 }
22255 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22256
22257 static void JimHistoryFreeCompletion(Jim_Interp *interp, void *data)
22258 {
22259 struct JimCompletionInfo *compinfo = data;
22260
22261 Jim_DecrRefCount(interp, compinfo->command);
 
 
 
 
 
22262
22263 Jim_Free(compinfo);
22264 }
22265 #endif
22266
22267 void Jim_HistorySetCompletion(Jim_Interp *interp, Jim_Obj *commandObj)
22268 {
22269 #ifdef USE_LINENOISE
22270 if (commandObj) {
22271
22272 Jim_IncrRefCount(commandObj);
22273 }
22274
22275 Jim_DeleteAssocData(interp, completion_callback_assoc_key);
22276
22277 if (commandObj) {
22278 struct JimCompletionInfo *compinfo = Jim_Alloc(sizeof(*compinfo));
22279 compinfo->interp = interp;
22280 compinfo->command = commandObj;
22281
22282 Jim_SetAssocData(interp, completion_callback_assoc_key, JimHistoryFreeCompletion, compinfo);
22283 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22284 #endif
22285 }
22286
22287 int Jim_InteractivePrompt(Jim_Interp *interp)
22288 {
@@ -22298,10 +24095,11 @@
22298 snprintf(history_file, history_len, "%s/.jim_history", home);
22299 Jim_HistoryLoad(history_file);
22300 }
22301
22302 Jim_HistorySetCompletion(interp, Jim_NewStringObj(interp, "tcl::autocomplete", -1));
 
22303 #endif
22304
22305 printf("Welcome to Jim version %d.%d\n",
22306 JIM_VERSION / 100, JIM_VERSION % 100);
22307 Jim_SetVariableStrWithStr(interp, JIM_INTERACTIVE, "1");
@@ -22344,11 +24142,11 @@
22344 if (Jim_Length(scriptObjPtr) != 0) {
22345
22346 Jim_AppendString(interp, scriptObjPtr, "\n", 1);
22347 }
22348 Jim_AppendString(interp, scriptObjPtr, line, -1);
22349 free(line);
22350 if (Jim_ScriptIsComplete(interp, scriptObjPtr, &state))
22351 break;
22352
22353 snprintf(prompt, sizeof(prompt), "%c> ", state);
22354 }
@@ -22374,11 +24172,14 @@
22374 if (retcode == JIM_ERR) {
22375 Jim_MakeErrorMessage(interp);
22376 }
22377 result = Jim_GetString(Jim_GetResult(interp), &reslen);
22378 if (reslen) {
22379 printf("%s\n", result);
 
 
 
22380 }
22381 }
22382 out:
22383 Jim_Free(history_file);
22384
@@ -22476,11 +24277,16 @@
22476 if (argc > 2 && strcmp(argv[1], "-e") == 0) {
22477
22478 JimSetArgv(interp, argc - 3, argv + 3);
22479 retcode = Jim_Eval(interp, argv[2]);
22480 if (retcode != JIM_ERR) {
22481 printf("%s\n", Jim_String(Jim_GetResult(interp)));
 
 
 
 
 
22482 }
22483 }
22484 else {
22485 Jim_SetVariableStr(interp, "argv0", Jim_NewStringObj(interp, argv[1], -1));
22486 JimSetArgv(interp, argc - 2, argv + 2);
22487
--- autosetup/jimsh0.c
+++ autosetup/jimsh0.c
@@ -10,10 +10,11 @@
10 #define jim_ext_readdir
11 #define jim_ext_regexp
12 #define jim_ext_file
13 #define jim_ext_glob
14 #define jim_ext_exec
15 #define jim_ext_posix
16 #define jim_ext_clock
17 #define jim_ext_array
18 #define jim_ext_stdlib
19 #define jim_ext_tclcompat
20 #if defined(_MSC_VER)
@@ -47,21 +48,23 @@
48 #define vfork fork
49 #define _POSIX_SOURCE
50 #else
51 #define _GNU_SOURCE
52 #endif
53 #define HAVE_FORK
54 #define HAVE_WAITPID
55 #define HAVE_ISATTY
56 #define HAVE_MKSTEMP
57 #define HAVE_LINK
58 #define HAVE_SYS_TIME_H
59 #define HAVE_DIRENT_H
60 #define HAVE_UNISTD_H
61 #define HAVE_UMASK
62 #define HAVE_PIPE
63 #define _FILE_OFFSET_BITS 64
64 #endif
65 #define JIM_VERSION 82
66 #ifndef JIM_WIN32COMPAT_H
67 #define JIM_WIN32COMPAT_H
68
69
70
@@ -184,11 +187,10 @@
187 extern "C" {
188 #endif
189
190 #include <time.h>
191 #include <limits.h>
 
192 #include <stdlib.h>
193 #include <stdarg.h>
194
195
196 #ifndef HAVE_NO_AUTOCONF
@@ -223,10 +225,13 @@
225 #endif
226
227 #define UCHAR(c) ((unsigned char)(c))
228
229
230
231 #define JIM_ABI_VERSION 101
232
233 #define JIM_OK 0
234 #define JIM_ERR 1
235 #define JIM_RETURN 2
236 #define JIM_BREAK 3
237 #define JIM_CONTINUE 4
@@ -244,10 +249,11 @@
249 #define JIM_NONE 0
250 #define JIM_ERRMSG 1
251 #define JIM_ENUM_ABBREV 2
252 #define JIM_UNSHARED 4
253 #define JIM_MUSTEXIST 8
254 #define JIM_NORESULT 16
255
256
257 #define JIM_SUBST_NOVAR 1
258 #define JIM_SUBST_NOCMD 2
259 #define JIM_SUBST_NOESC 4
@@ -254,10 +260,11 @@
260 #define JIM_SUBST_FLAG 128
261
262
263 #define JIM_CASESENS 0
264 #define JIM_NOCASE 1
265 #define JIM_OPT_END 2
266
267
268 #define JIM_PATH_LEN 1024
269
270
@@ -322,10 +329,12 @@
329 (entry)->u.val = (ht)->type->valDup((ht)->privdata, (_val_)); \
330 else \
331 (entry)->u.val = (_val_); \
332 } while(0)
333
334 #define Jim_SetHashIntVal(ht, entry, _val_) (entry)->u.intval = (_val_)
335
336 #define Jim_FreeEntryKey(ht, entry) \
337 if ((ht)->type->keyDestructor) \
338 (ht)->type->keyDestructor((ht)->privdata, (entry)->key)
339
340 #define Jim_SetHashKey(ht, entry, _key_) do { \
@@ -342,10 +351,11 @@
351
352 #define Jim_HashKey(ht, key) ((ht)->type->hashFunction(key) + (ht)->uniq)
353
354 #define Jim_GetHashEntryKey(he) ((he)->key)
355 #define Jim_GetHashEntryVal(he) ((he)->u.val)
356 #define Jim_GetHashEntryIntVal(he) ((he)->u.intval)
357 #define Jim_GetHashTableCollisions(ht) ((ht)->collisions)
358 #define Jim_GetHashTableSize(ht) ((ht)->size)
359 #define Jim_GetHashTableUsed(ht) ((ht)->used)
360
361
@@ -375,11 +385,11 @@
385 int int1;
386 int int2;
387 } ptrIntValue;
388
389 struct {
390 struct Jim_VarVal *vv;
391 unsigned long callFrameId;
392 int global;
393 } varValue;
394
395 struct {
@@ -391,10 +401,12 @@
401 struct {
402 struct Jim_Obj **ele;
403 int len;
404 int maxLen;
405 } listValue;
406
407 struct Jim_Dict *dictValue;
408
409 struct {
410 int maxLength;
411 int charLength;
412 } strValue;
@@ -477,33 +489,59 @@
489 int argc;
490 Jim_Obj *procArgsObjPtr;
491 Jim_Obj *procBodyObjPtr;
492 struct Jim_CallFrame *next;
493 Jim_Obj *nsObj;
494 Jim_Obj *unused_fileNameObj;
495 int unused_line;
496 Jim_Stack *localCommands;
497 struct Jim_Obj *tailcallObj;
498 struct Jim_Cmd *tailcallCmd;
499 } Jim_CallFrame;
500
501
502 typedef struct Jim_EvalFrame {
503 Jim_CallFrame *framePtr;
504 int level;
505 int procLevel;
506 struct Jim_Cmd *cmd;
507 struct Jim_EvalFrame *parent;
508 Jim_Obj *const *argv;
509 int argc;
510 Jim_Obj *scriptObj;
511 } Jim_EvalFrame;
512
513 typedef struct Jim_VarVal {
514 Jim_Obj *objPtr;
515 struct Jim_CallFrame *linkFramePtr;
516 int refCount;
517 } Jim_VarVal;
518
519
520 typedef int Jim_CmdProc(struct Jim_Interp *interp, int argc,
521 Jim_Obj *const *argv);
522 typedef void Jim_DelCmdProc(struct Jim_Interp *interp, void *privData);
523
524 typedef struct Jim_Dict {
525 struct JimDictHashEntry {
526 int offset;
527 unsigned hash;
528 } *ht;
529 unsigned int size;
530 unsigned int sizemask;
531 unsigned int uniq;
532 Jim_Obj **table;
533 int len;
534 int maxLen;
535 unsigned int dummy;
536 } Jim_Dict;
537
538 typedef struct Jim_Cmd {
539 int inUse;
540 int isproc;
541 struct Jim_Cmd *prevCmd;
542 Jim_Obj *cmdNameObj;
543 union {
544 struct {
545
546 Jim_CmdProc *cmdProc;
547 Jim_DelCmdProc *delProc;
@@ -534,13 +572,13 @@
572 unsigned int i, j;
573 } Jim_PrngState;
574
575 typedef struct Jim_Interp {
576 Jim_Obj *result;
577 int unused_errorLine;
578 Jim_Obj *currentFilenameObj;
579 int unused_addStackTrace;
580 int maxCallFrameDepth;
581 int maxEvalDepth;
582 int evalDepth;
583 int returnCode;
584 int returnLevel;
@@ -558,13 +596,19 @@
596 unsigned long callFrameEpoch; /* Incremented every time a new
597 callframe is created. This id is used for the
598 'ID' field contained in the Jim_CallFrame
599 structure. */
600 int local;
601 int quitting;
602 int safeexpr;
603 Jim_Obj *liveList;
604 Jim_Obj *freeList;
605 Jim_Obj *unused_currentScriptObj;
606 Jim_EvalFrame topEvalFrame;
607 Jim_EvalFrame *evalFrame;
608 int procLevel;
609 Jim_Obj * const *unused_argv;
610 Jim_Obj *nullScriptObj;
611 Jim_Obj *emptyObj;
612 Jim_Obj *trueObj;
613 Jim_Obj *falseObj;
614 unsigned long referenceNextId;
@@ -572,28 +616,31 @@
616 unsigned long lastCollectId; /* reference max Id of the last GC
617 execution. It's set to ~0 while the collection
618 is running as sentinel to avoid to recursive
619 calls via the [collect] command inside
620 finalizers. */
621 jim_wide lastCollectTime;
622 Jim_Obj *stackTrace;
623 Jim_Obj *errorProc;
624 Jim_Obj *unknown;
625 Jim_Obj *defer;
626 Jim_Obj *traceCmdObj;
627 int unknown_called;
628 int errorFlag;
629 void *cmdPrivData; /* Used to pass the private data pointer to
630 a command. It is set to what the user specified
631 via Jim_CreateCommand(). */
632
633 Jim_Cmd *oldCmdCache;
634 int oldCmdCacheSize;
635 struct Jim_CallFrame *freeFramesList;
636 struct Jim_HashTable assocData;
637 Jim_PrngState *prngState;
638 struct Jim_HashTable packages;
639 Jim_Stack *loadHandles;
640 } Jim_Interp;
641
 
642 #define Jim_SetResultString(i,s,l) Jim_SetResult(i, Jim_NewStringObj(i,s,l))
643 #define Jim_SetResultInt(i,intval) Jim_SetResult(i, Jim_NewIntObj(i,intval))
644
645 #define Jim_SetResultBool(i,b) Jim_SetResultInt(i, b)
646 #define Jim_SetEmptyResult(i) Jim_SetResult(i, (i)->emptyObj)
@@ -621,23 +668,36 @@
668
669
670 #define Jim_NewEmptyStringObj(i) Jim_NewStringObj(i, "", 0)
671 #define Jim_FreeHashTableIterator(iter) Jim_Free(iter)
672
673 #define JIM_EXPORT extern
674
675
676
677 JIM_EXPORT void *(*Jim_Allocator)(void *ptr, size_t size);
678
679 #define Jim_Free(P) Jim_Allocator((P), 0)
680 #define Jim_Realloc(P, S) Jim_Allocator((P), (S))
681 #define Jim_Alloc(S) Jim_Allocator(NULL, (S))
682 JIM_EXPORT char * Jim_StrDup (const char *s);
683 JIM_EXPORT char *Jim_StrDupLen(const char *s, int l);
684
685
686 JIM_EXPORT char **Jim_GetEnviron(void);
687 JIM_EXPORT void Jim_SetEnviron(char **env);
688 JIM_EXPORT int Jim_MakeTempFile(Jim_Interp *interp, const char *filename_template, int unlink_file);
689 #ifndef CLOCK_REALTIME
690 # define CLOCK_REALTIME 0
691 #endif
692 #ifndef CLOCK_MONOTONIC
693 # define CLOCK_MONOTONIC 1
694 #endif
695 #ifndef CLOCK_MONOTONIC_RAW
696 # define CLOCK_MONOTONIC_RAW CLOCK_MONOTONIC
697 #endif
698 JIM_EXPORT jim_wide Jim_GetTimeUsec(unsigned type);
699
700
701 JIM_EXPORT int Jim_Eval(Jim_Interp *interp, const char *script);
702
703
@@ -680,11 +740,10 @@
740 JIM_EXPORT int Jim_DeleteHashEntry (Jim_HashTable *ht,
741 const void *key);
742 JIM_EXPORT int Jim_FreeHashTable (Jim_HashTable *ht);
743 JIM_EXPORT Jim_HashEntry * Jim_FindHashEntry (Jim_HashTable *ht,
744 const void *key);
 
745 JIM_EXPORT Jim_HashTableIterator *Jim_GetHashTableIterator
746 (Jim_HashTable *ht);
747 JIM_EXPORT Jim_HashEntry * Jim_NextHashEntry
748 (Jim_HashTableIterator *iter);
749
@@ -724,12 +783,10 @@
783 Jim_Obj *fmtObjPtr, int flags);
784 JIM_EXPORT int Jim_CompareStringImmediate (Jim_Interp *interp,
785 Jim_Obj *objPtr, const char *str);
786 JIM_EXPORT int Jim_StringCompareObj(Jim_Interp *interp, Jim_Obj *firstObjPtr,
787 Jim_Obj *secondObjPtr, int nocase);
 
 
788 JIM_EXPORT int Jim_Utf8Length(Jim_Interp *interp, Jim_Obj *objPtr);
789
790
791 JIM_EXPORT Jim_Obj * Jim_NewReference (Jim_Interp *interp,
792 Jim_Obj *objPtr, Jim_Obj *tagPtr, Jim_Obj *cmdNamePtr);
@@ -749,13 +806,13 @@
806 JIM_EXPORT void Jim_RegisterCoreCommands (Jim_Interp *interp);
807 JIM_EXPORT int Jim_CreateCommand (Jim_Interp *interp,
808 const char *cmdName, Jim_CmdProc *cmdProc, void *privData,
809 Jim_DelCmdProc *delProc);
810 JIM_EXPORT int Jim_DeleteCommand (Jim_Interp *interp,
811 Jim_Obj *cmdNameObj);
812 JIM_EXPORT int Jim_RenameCommand (Jim_Interp *interp,
813 Jim_Obj *oldNameObj, Jim_Obj *newNameObj);
814 JIM_EXPORT Jim_Cmd * Jim_GetCommand (Jim_Interp *interp,
815 Jim_Obj *objPtr, int flags);
816 JIM_EXPORT int Jim_SetVariable (Jim_Interp *interp,
817 Jim_Obj *nameObjPtr, Jim_Obj *valObjPtr);
818 JIM_EXPORT int Jim_SetVariableStr (Jim_Interp *interp,
@@ -822,12 +879,12 @@
879 Jim_Obj *dictPtr, Jim_Obj *const *keyv, int keyc,
880 Jim_Obj **objPtrPtr, int flags);
881 JIM_EXPORT int Jim_SetDictKeysVector (Jim_Interp *interp,
882 Jim_Obj *varNamePtr, Jim_Obj *const *keyv, int keyc,
883 Jim_Obj *newObjPtr, int flags);
884 JIM_EXPORT Jim_Obj **Jim_DictPairs(Jim_Interp *interp,
885 Jim_Obj *dictPtr, int *len);
886 JIM_EXPORT int Jim_DictAddElement(Jim_Interp *interp, Jim_Obj *objPtr,
887 Jim_Obj *keyObjPtr, Jim_Obj *valueObjPtr);
888
889 #define JIM_DICTMATCH_KEYS 0x0001
890 #define JIM_DICTMATCH_VALUES 0x002
@@ -851,10 +908,12 @@
908 JIM_EXPORT int Jim_GetBoolean(Jim_Interp *interp, Jim_Obj *objPtr,
909 int *booleanPtr);
910
911
912 JIM_EXPORT int Jim_GetWide (Jim_Interp *interp, Jim_Obj *objPtr,
913 jim_wide *widePtr);
914 JIM_EXPORT int Jim_GetWideExpr(Jim_Interp *interp, Jim_Obj *objPtr,
915 jim_wide *widePtr);
916 JIM_EXPORT int Jim_GetLong (Jim_Interp *interp, Jim_Obj *objPtr,
917 long *longPtr);
918 #define Jim_NewWideObj Jim_NewIntObj
919 JIM_EXPORT Jim_Obj * Jim_NewIntObj (Jim_Interp *interp,
@@ -883,43 +942,52 @@
942 typedef void (Jim_InterpDeleteProc)(Jim_Interp *interp, void *data);
943 JIM_EXPORT void * Jim_GetAssocData(Jim_Interp *interp, const char *key);
944 JIM_EXPORT int Jim_SetAssocData(Jim_Interp *interp, const char *key,
945 Jim_InterpDeleteProc *delProc, void *data);
946 JIM_EXPORT int Jim_DeleteAssocData(Jim_Interp *interp, const char *key);
947 JIM_EXPORT int Jim_CheckAbiVersion(Jim_Interp *interp, int abi_version);
948
949
950
951
952 JIM_EXPORT int Jim_PackageProvide (Jim_Interp *interp,
953 const char *name, const char *ver, int flags);
954 JIM_EXPORT int Jim_PackageRequire (Jim_Interp *interp,
955 const char *name, int flags);
956 #define Jim_PackageProvideCheck(INTERP, NAME) \
957 if (Jim_CheckAbiVersion(INTERP, JIM_ABI_VERSION) == JIM_ERR || Jim_PackageProvide(INTERP, NAME, "1.0", JIM_ERRMSG)) \
958 return JIM_ERR
959
960
961 JIM_EXPORT void Jim_MakeErrorMessage (Jim_Interp *interp);
962
963
964 JIM_EXPORT int Jim_InteractivePrompt (Jim_Interp *interp);
965 JIM_EXPORT void Jim_HistoryLoad(const char *filename);
966 JIM_EXPORT void Jim_HistorySave(const char *filename);
967 JIM_EXPORT char *Jim_HistoryGetline(Jim_Interp *interp, const char *prompt);
968 JIM_EXPORT void Jim_HistorySetCompletion(Jim_Interp *interp, Jim_Obj *completionCommandObj);
969 JIM_EXPORT void Jim_HistorySetHints(Jim_Interp *interp, Jim_Obj *hintsCommandObj);
970 JIM_EXPORT void Jim_HistoryAdd(const char *line);
971 JIM_EXPORT void Jim_HistoryShow(void);
972 JIM_EXPORT void Jim_HistorySetMaxLen(int length);
973 JIM_EXPORT int Jim_HistoryGetMaxLen(void);
974
975
976 JIM_EXPORT int Jim_InitStaticExtensions(Jim_Interp *interp);
977 JIM_EXPORT int Jim_StringToWide(const char *str, jim_wide *widePtr, int base);
978 JIM_EXPORT int Jim_IsBigEndian(void);
979
980 #define Jim_CheckSignal(i) ((i)->signal_level && (i)->sigmask)
981 JIM_EXPORT void Jim_SignalSetIgnored(jim_wide mask);
982
983
984 JIM_EXPORT int Jim_LoadLibrary(Jim_Interp *interp, const char *pathName);
985 JIM_EXPORT void Jim_FreeLoadHandles(Jim_Interp *interp);
986
987
988 JIM_EXPORT int Jim_AioFilehandle(Jim_Interp *interp, Jim_Obj *command);
989
990
991 JIM_EXPORT int Jim_IsDict(Jim_Obj *objPtr);
992 JIM_EXPORT int Jim_IsList(Jim_Obj *objPtr);
993
@@ -952,16 +1020,21 @@
1020 short minargs;
1021 short maxargs;
1022 unsigned short flags;
1023 } jim_subcmd_type;
1024
1025 #define JIM_DEF_SUBCMD(name, args, minargs, maxargs) { name, args, NULL, minargs, maxargs }
1026 #define JIM_DEF_SUBCMD_HIDDEN(name, args, minargs, maxargs) { name, args, NULL, minargs, maxargs, JIM_MODFLAG_HIDDEN }
1027
1028 const jim_subcmd_type *
1029 Jim_ParseSubCmd(Jim_Interp *interp, const jim_subcmd_type *command_table, int argc, Jim_Obj *const *argv);
1030
1031 int Jim_SubCmdProc(Jim_Interp *interp, int argc, Jim_Obj *const *argv);
1032
1033 int Jim_CallSubCmd(Jim_Interp *interp, const jim_subcmd_type *ct, int argc, Jim_Obj *const *argv);
1034
1035 void Jim_SubCmdArgError(Jim_Interp *interp, const jim_subcmd_type *ct, Jim_Obj *subcmd);
1036
1037 #ifdef __cplusplus
1038 }
1039 #endif
1040
@@ -1034,20 +1107,21 @@
1107 REG_ERR_JUNK_ON_END,
1108 REG_ERR_OPERAND_COULD_BE_EMPTY,
1109 REG_ERR_NESTED_COUNT,
1110 REG_ERR_INTERNAL,
1111 REG_ERR_COUNT_FOLLOWS_NOTHING,
1112 REG_ERR_INVALID_ESCAPE,
1113 REG_ERR_CORRUPTED,
1114 REG_ERR_NULL_CHAR,
1115 REG_ERR_UNMATCHED_BRACKET,
1116 REG_ERR_NUM
1117 };
1118
1119 int jim_regcomp(regex_t *preg, const char *regex, int cflags);
1120 int jim_regexec(regex_t *preg, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags);
1121 size_t jim_regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size);
1122 void jim_regfree(regex_t *preg);
1123
1124 #ifdef __cplusplus
1125 }
1126 #endif
1127
@@ -1070,10 +1144,11 @@
1144 #define JIMIOCOMPAT_H
1145
1146
1147 #include <stdio.h>
1148 #include <errno.h>
1149 #include <sys/stat.h>
1150
1151
1152 void Jim_SetResultErrno(Jim_Interp *interp, const char *msg);
1153
1154 int Jim_OpenForWrite(const char *filename, int append);
@@ -1088,67 +1163,109 @@
1163 #include <windows.h>
1164 #include <fcntl.h>
1165 #include <io.h>
1166 #include <process.h>
1167
1168 typedef HANDLE phandle_t;
1169 #define JIM_BAD_PHANDLE INVALID_HANDLE_VALUE
 
 
1170
1171
1172 #define WIFEXITED(STATUS) (((STATUS) & 0xff00) == 0)
1173 #define WEXITSTATUS(STATUS) ((STATUS) & 0x00ff)
1174 #define WIFSIGNALED(STATUS) (((STATUS) & 0xff00) != 0)
1175 #define WTERMSIG(STATUS) (((STATUS) >> 8) & 0xff)
1176 #define WNOHANG 1
1177
1178 int Jim_Errno(void);
1179
1180 long waitpid(phandle_t phandle, int *status, int nohang);
1181
1182 phandle_t JimWaitPid(long processid, int *status, int nohang);
1183
1184 long JimProcessPid(phandle_t phandle);
1185
1186 #define HAVE_PIPE
1187 #define pipe(P) _pipe((P), 0, O_NOINHERIT)
1188
1189 typedef struct __stat64 jim_stat_t;
1190 #define Jim_Stat _stat64
1191 #define Jim_FileStat _fstat64
1192 #define Jim_Lseek _lseeki64
1193
1194 #else
1195 #if defined(HAVE_STAT64)
1196 typedef struct stat64 jim_stat_t;
1197 #define Jim_Stat stat64
1198 #if defined(HAVE_FSTAT64)
1199 #define Jim_FileStat fstat64
1200 #endif
1201 #if defined(HAVE_LSTAT64)
1202 #define Jim_LinkStat lstat64
1203 #endif
1204 #else
1205 typedef struct stat jim_stat_t;
1206 #define Jim_Stat stat
1207 #if defined(HAVE_FSTAT)
1208 #define Jim_FileStat fstat
1209 #endif
1210 #if defined(HAVE_LSTAT)
1211 #define Jim_LinkStat lstat
1212 #endif
1213 #endif
1214 #if defined(HAVE_LSEEK64)
1215 #define Jim_Lseek lseek64
1216 #else
1217 #define Jim_Lseek lseek
1218 #endif
1219
1220 #if defined(HAVE_UNISTD_H)
1221 #include <unistd.h>
1222 #include <fcntl.h>
1223 #include <sys/wait.h>
1224
1225 typedef int phandle_t;
1226 #define Jim_Errno() errno
1227 #define JIM_BAD_PHANDLE -1
1228 #define JimProcessPid(PIDTYPE) (PIDTYPE)
1229 #define JimWaitPid waitpid
1230
1231 #ifndef HAVE_EXECVPE
1232 #define execvpe(ARG0, ARGV, ENV) execvp(ARG0, ARGV)
1233 #endif
1234 #endif
1235 #endif
1236
1237 #ifndef O_TEXT
1238 #define O_TEXT 0
1239 #endif
1240
1241
1242 int Jim_FileStoreStatData(Jim_Interp *interp, Jim_Obj *varName, const jim_stat_t *sb);
1243
1244 #endif
1245 int Jim_bootstrapInit(Jim_Interp *interp)
1246 {
1247 if (Jim_PackageProvide(interp, "bootstrap", "1.0", JIM_ERRMSG))
1248 return JIM_ERR;
1249
1250 return Jim_EvalSource(interp, "bootstrap.tcl", 1,
1251 "\n"
1252 "proc package {cmd args} {\n"
 
1253 " if {$cmd eq \"require\"} {\n"
1254 " foreach path $::auto_path {\n"
1255 " lassign $args pkg\n"
1256 " set pkgpath $path/$pkg.tcl\n"
1257 " if {$path eq \".\"} {\n"
1258 " set pkgpath $pkg.tcl\n"
1259 " }\n"
1260 " if {[file exists $pkgpath]} {\n"
1261 " tailcall uplevel #0 [list source $pkgpath]\n"
 
1262 " }\n"
1263 " }\n"
1264 " }\n"
1265 "}\n"
1266 "set tcl_platform(bootstrap) 1\n"
1267 );
1268 }
1269 int Jim_initjimshInit(Jim_Interp *interp)
1270 {
1271 if (Jim_PackageProvide(interp, "initjimsh", "1.0", JIM_ERRMSG))
@@ -1199,11 +1316,11 @@
1316 "if {$tcl_platform(platform) eq \"windows\"} {\n"
1317 " set jim::argv0 [string map {\\\\ /} $jim::argv0]\n"
1318 "}\n"
1319 "\n"
1320 "\n"
1321 "set tcl::autocomplete_commands {array clock debug dict file history info namespace package signal socket string tcl::prefix zlib}\n"
1322 "\n"
1323 "\n"
1324 "\n"
1325 "proc tcl::autocomplete {prefix} {\n"
1326 " if {[set space [string first \" \" $prefix]] != -1} {\n"
@@ -1231,10 +1348,67 @@
1348 " }\n"
1349 " function $p\n"
1350 " }]\n"
1351 "}\n"
1352 "\n"
1353 "\n"
1354 "set tcl::stdhint_commands {array clock debug dict file history info namespace package signal string zlib}\n"
1355 "\n"
1356 "set tcl::stdhint_cols {\n"
1357 " none {0}\n"
1358 " black {30}\n"
1359 " red {31}\n"
1360 " green {32}\n"
1361 " yellow {33}\n"
1362 " blue {34}\n"
1363 " purple {35}\n"
1364 " cyan {36}\n"
1365 " normal {37}\n"
1366 " grey {30 1}\n"
1367 " gray {30 1}\n"
1368 " lred {31 1}\n"
1369 " lgreen {32 1}\n"
1370 " lyellow {33 1}\n"
1371 " lblue {34 1}\n"
1372 " lpurple {35 1}\n"
1373 " lcyan {36 1}\n"
1374 " white {37 1}\n"
1375 "}\n"
1376 "\n"
1377 "\n"
1378 "set tcl::stdhint_col $tcl::stdhint_cols(lcyan)\n"
1379 "\n"
1380 "\n"
1381 "proc tcl::stdhint {string} {\n"
1382 " set result \"\"\n"
1383 " if {[llength $string] >= 2} {\n"
1384 " lassign $string cmd arg\n"
1385 " if {$cmd in $::tcl::stdhint_commands || [info channel $cmd] ne \"\"} {\n"
1386 " catch {\n"
1387 " set help [$cmd -help $arg]\n"
1388 " if {[string match \"Usage: $cmd *\" $help]} {\n"
1389 " set n [llength $string]\n"
1390 " set subcmd [lindex $help $n]\n"
1391 " incr n\n"
1392 " set hint [join [lrange $help $n end]]\n"
1393 " set prefix \"\"\n"
1394 " if {![string match \"* \" $string]} {\n"
1395 " if {$n == 3 && $subcmd ne $arg} {\n"
1396 "\n"
1397 " set prefix \"[string range $subcmd [string length $arg] end] \"\n"
1398 " } else {\n"
1399 " set prefix \" \"\n"
1400 " }\n"
1401 " }\n"
1402 " set result [list $prefix$hint {*}$::tcl::stdhint_col]\n"
1403 " }\n"
1404 " }\n"
1405 " }\n"
1406 " }\n"
1407 " return $result\n"
1408 "}\n"
1409 "\n"
1410 "_jimsh_init\n"
1411 );
1412 }
1413 int Jim_globInit(Jim_Interp *interp)
1414 {
@@ -1480,40 +1654,35 @@
1654 "proc function {value} {\n"
1655 " return $value\n"
1656 "}\n"
1657 "\n"
1658 "\n"
 
 
 
 
 
 
 
 
 
 
 
 
1659 "proc stackdump {stacktrace} {\n"
1660 " set lines {}\n"
1661 " lappend lines \"Traceback (most recent call last):\"\n"
1662 " foreach {cmd l f p} [lreverse $stacktrace] {\n"
1663 " set line {}\n"
1664 " if {$f ne \"\"} {\n"
1665 " append line \" File \\\"$f\\\", line $l\"\n"
1666 " }\n"
1667 " if {$p ne \"\"} {\n"
1668 " append line \", in $p\"\n"
 
 
 
 
 
 
1669 " }\n"
1670 " if {$line ne \"\"} {\n"
1671 " lappend lines $line\n"
1672 " if {$cmd ne \"\"} {\n"
1673 " set nl [string first \\n $cmd 1]\n"
1674 " if {$nl >= 0} {\n"
1675 " set cmd [string range $cmd 0 $nl-1]...\n"
1676 " }\n"
1677 " lappend lines \" $cmd\"\n"
1678 " }\n"
1679 " }\n"
1680 " }\n"
1681 " if {[llength $lines] > 1} {\n"
1682 " return [join $lines \\n]\n"
1683 " }\n"
1684 "}\n"
1685 "\n"
1686 "\n"
1687 "\n"
1688 "proc defer {script} {\n"
@@ -1525,14 +1694,12 @@
1694 "\n"
1695 "proc errorInfo {msg {stacktrace \"\"}} {\n"
1696 " if {$stacktrace eq \"\"} {\n"
1697 "\n"
1698 " set stacktrace [info stacktrace]\n"
 
 
1699 " }\n"
1700 " lassign $stacktrace p f l cmd\n"
1701 " if {$f ne \"\"} {\n"
1702 " set result \"$f:$l: Error: \"\n"
1703 " }\n"
1704 " append result \"$msg\\n\"\n"
1705 " append result [stackdump $stacktrace]\n"
@@ -1641,11 +1808,11 @@
1808 "\n"
1809 "\n"
1810 "set env [env]\n"
1811 "\n"
1812 "\n"
1813 "if {[exists -command stdout]} {\n"
1814 "\n"
1815 " foreach p {gets flush close eof seek tell} {\n"
1816 " proc $p {chan args} {p} {\n"
1817 " tailcall $chan $p {*}$args\n"
1818 " }\n"
@@ -1815,76 +1982,10 @@
1982 " return $pids\n"
1983 "}\n"
1984 "\n"
1985 "\n"
1986 "\n"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1987 "proc throw {code {msg \"\"}} {\n"
1988 " return -code $code $msg\n"
1989 "}\n"
1990 "\n"
1991 "\n"
@@ -1896,20 +1997,24 @@
1997 "}\n"
1998 );
1999 }
2000
2001
 
 
 
2002 #include <stdio.h>
2003 #include <string.h>
2004 #include <errno.h>
2005 #include <fcntl.h>
2006 #include <assert.h>
2007 #ifdef HAVE_UNISTD_H
2008 #include <unistd.h>
2009 #include <sys/stat.h>
2010 #endif
2011 #ifdef HAVE_UTIL_H
2012 #include <util.h>
2013 #endif
2014 #ifdef HAVE_PTY_H
2015 #include <pty.h>
2016 #endif
2017
2018
2019 #if defined(HAVE_SYS_SOCKET_H) && defined(HAVE_SELECT) && defined(HAVE_NETINET_IN_H) && defined(HAVE_NETDB_H) && defined(HAVE_ARPA_INET_H)
2020 #include <sys/socket.h>
@@ -1921,12 +2026,10 @@
2026 #include <sys/un.h>
2027 #endif
2028 #define HAVE_SOCKETS
2029 #elif defined (__MINGW32__)
2030
 
 
2031 #endif
2032
2033 #if defined(JIM_SSL)
2034 #include <openssl/ssl.h>
2035 #include <openssl/err.h>
@@ -1936,98 +2039,136 @@
2039 #endif
2040
2041
2042 #define AIO_CMD_LEN 32
2043 #define AIO_BUF_LEN 256
2044 #define AIO_WBUF_FULL_SIZE (64 * 1024)
 
 
 
 
 
 
2045
2046 #define AIO_KEEPOPEN 1
2047 #define AIO_NODELETE 2
2048 #define AIO_EOF 4
2049 #define AIO_WBUF_NONE 8
2050 #define AIO_NONBLOCK 16
2051
2052 enum wbuftype {
2053 WBUF_OPT_NONE,
2054 WBUF_OPT_LINE,
2055 WBUF_OPT_FULL,
2056 };
2057
2058 #if defined(JIM_IPV6)
2059 #define IPV6 1
2060 #else
2061 #define IPV6 0
2062 #ifndef PF_INET6
2063 #define PF_INET6 0
2064 #endif
2065 #endif
2066 #if defined(HAVE_SYS_UN_H) && defined(PF_UNIX)
2067 #define UNIX_SOCKETS 1
2068 #else
2069 #define UNIX_SOCKETS 0
2070 #endif
2071
2072 #ifndef MAXPATHLEN
2073 #define MAXPATHLEN JIM_PATH_LEN
2074 #endif
2075
2076
2077
2078
2079 static int JimReadableTimeout(int fd, long ms)
2080 {
2081 #ifdef HAVE_SELECT
2082 int retval;
2083 struct timeval tv;
2084 fd_set rfds;
2085
2086 FD_ZERO(&rfds);
2087
2088 FD_SET(fd, &rfds);
2089 tv.tv_sec = ms / 1000;
2090 tv.tv_usec = (ms % 1000) * 1000;
2091
2092 retval = select(fd + 1, &rfds, NULL, NULL, ms == 0 ? NULL : &tv);
2093
2094 if (retval > 0) {
2095 return JIM_OK;
2096 }
2097 return JIM_ERR;
2098 #else
2099 return JIM_OK;
2100 #endif
2101 }
2102
2103
2104 struct AioFile;
2105
2106 typedef struct {
2107 int (*writer)(struct AioFile *af, const char *buf, int len);
2108 int (*reader)(struct AioFile *af, char *buf, int len, int pending);
 
2109 int (*error)(const struct AioFile *af);
2110 const char *(*strerror)(struct AioFile *af);
2111 int (*verify)(struct AioFile *af);
2112 } JimAioFopsType;
2113
2114 typedef struct AioFile
2115 {
 
2116 Jim_Obj *filename;
2117 int wbuft;
2118 int flags;
2119 long timeout;
2120 int fd;
 
 
 
2121 int addr_family;
2122 void *ssl;
2123 const JimAioFopsType *fops;
2124 Jim_Obj *readbuf;
2125 Jim_Obj *writebuf;
2126 } AioFile;
2127
2128 static int stdio_writer(struct AioFile *af, const char *buf, int len)
2129 {
2130 return write(af->fd, buf, len);
2131 }
2132
2133 static int stdio_reader(struct AioFile *af, char *buf, int len, int nb)
2134 {
2135 if (nb || af->timeout == 0 || JimReadableTimeout(af->fd, af->timeout) == JIM_OK) {
2136
2137 int ret;
2138
2139 errno = 0;
2140 ret = read(af->fd, buf, len);
2141 if (ret <= 0 && errno != EAGAIN && errno != EINTR) {
2142 af->flags |= AIO_EOF;
2143 }
2144 return ret;
2145 }
2146 errno = ETIMEDOUT;
2147 return -1;
2148 }
2149
2150 static int stdio_error(const AioFile *af)
2151 {
2152 if (af->flags & AIO_EOF) {
2153 return JIM_OK;
2154 }
 
2155
2156 switch (errno) {
2157 case EAGAIN:
2158 case EINTR:
2159 case ETIMEDOUT:
2160 #ifdef ECONNRESET
2161 case ECONNRESET:
 
 
2162 #endif
2163 #ifdef ECONNABORTED
2164 case ECONNABORTED:
2165 #endif
2166 return JIM_OK;
2167 default:
2168 return JIM_ERR;
2169 }
 
 
2170 }
2171
2172 static const char *stdio_strerror(struct AioFile *af)
2173 {
2174 return strerror(errno);
@@ -2034,20 +2175,47 @@
2175 }
2176
2177 static const JimAioFopsType stdio_fops = {
2178 stdio_writer,
2179 stdio_reader,
 
2180 stdio_error,
2181 stdio_strerror,
2182 NULL,
2183 };
2184
2185
2186 static void aio_set_nonblocking(AioFile *af, int nb)
2187 {
2188 #ifdef O_NDELAY
2189 int old = !!(af->flags & AIO_NONBLOCK);
2190 if (old != nb) {
2191 int fmode = fcntl(af->fd, F_GETFL);
2192 if (nb) {
2193 fmode |= O_NDELAY;
2194 af->flags |= AIO_NONBLOCK;
2195 }
2196 else {
2197 fmode &= ~O_NDELAY;
2198 af->flags &= ~AIO_NONBLOCK;
2199 }
2200 (void)fcntl(af->fd, F_SETFL, fmode);
2201 }
2202 #endif
2203 }
2204
2205 static int aio_start_nonblocking(AioFile *af)
2206 {
2207 int old = !!(af->flags & AIO_NONBLOCK);
2208 if (af->timeout) {
2209 aio_set_nonblocking(af, 1);
2210 }
2211 return old;
2212 }
2213
2214 static int JimAioSubCmdProc(Jim_Interp *interp, int argc, Jim_Obj *const *argv);
2215 static AioFile *JimMakeChannel(Jim_Interp *interp, int fd, Jim_Obj *filename,
2216 const char *hdlfmt, int family, int flags);
2217
2218
2219 static const char *JimAioErrorString(AioFile *af)
2220 {
2221 if (af && af->fops)
@@ -2065,26 +2233,171 @@
2233 }
2234 else {
2235 Jim_SetResultString(interp, JimAioErrorString(af), -1);
2236 }
2237 }
2238
2239 static int aio_eof(AioFile *af)
2240 {
2241 return af->flags & AIO_EOF;
2242 }
2243
2244 static int JimCheckStreamError(Jim_Interp *interp, AioFile *af)
2245 {
2246 int ret = 0;
2247 if (!aio_eof(af)) {
2248 ret = af->fops->error(af);
2249 if (ret) {
2250 JimAioSetError(interp, af->filename);
2251 }
2252 }
2253 return ret;
2254 }
2255
2256 static void aio_consume(Jim_Obj *objPtr, int n)
2257 {
2258 assert(objPtr->bytes);
2259 assert(n <= objPtr->length);
2260
2261
2262 memmove(objPtr->bytes, objPtr->bytes + n, objPtr->length - n + 1);
2263 objPtr->length -= n;
2264 }
2265
2266
2267 static int aio_autoflush(Jim_Interp *interp, void *clientData, int mask);
2268
2269 static int aio_flush(Jim_Interp *interp, AioFile *af)
2270 {
2271 int len;
2272 const char *pt = Jim_GetString(af->writebuf, &len);
2273 if (len) {
2274 int ret = af->fops->writer(af, pt, len);
2275 if (ret > 0) {
2276
2277 aio_consume(af->writebuf, ret);
2278 }
2279 if (ret < 0) {
2280 return JimCheckStreamError(interp, af);
2281 }
2282 if (Jim_Length(af->writebuf)) {
2283 #ifdef jim_ext_eventloop
2284 void *handler = Jim_FindFileHandler(interp, af->fd, JIM_EVENT_WRITABLE);
2285 if (handler == NULL) {
2286 Jim_CreateFileHandler(interp, af->fd, JIM_EVENT_WRITABLE, aio_autoflush, af, NULL);
2287 return JIM_OK;
2288 }
2289 else if (handler == af) {
2290
2291 return JIM_OK;
2292 }
2293 #endif
2294
2295 Jim_SetResultString(interp, "send buffer is full", -1);
2296 return JIM_ERR;
2297 }
2298 }
2299 return JIM_OK;
2300 }
2301
2302 static int aio_autoflush(Jim_Interp *interp, void *clientData, int mask)
2303 {
2304 AioFile *af = clientData;
2305
2306 aio_flush(interp, af);
2307 if (Jim_Length(af->writebuf) == 0) {
2308
2309 return -1;
2310 }
2311 return 0;
2312 }
2313
2314 static int aio_read_len(Jim_Interp *interp, AioFile *af, int nb, char *buf, size_t buflen, int neededLen)
2315 {
2316 if (!af->readbuf) {
2317 af->readbuf = Jim_NewStringObj(interp, NULL, 0);
2318 }
2319
2320 if (neededLen >= 0) {
2321 neededLen -= Jim_Length(af->readbuf);
2322 if (neededLen <= 0) {
2323 return JIM_OK;
2324 }
2325 }
2326
2327 while (neededLen && !aio_eof(af)) {
2328 int retval;
2329 int readlen;
2330
2331 if (neededLen == -1) {
2332 readlen = AIO_BUF_LEN;
2333 }
2334 else {
2335 readlen = (neededLen > AIO_BUF_LEN ? AIO_BUF_LEN : neededLen);
2336 }
2337 retval = af->fops->reader(af, buf, readlen, nb);
2338 if (retval > 0) {
2339 Jim_AppendString(interp, af->readbuf, buf, retval);
2340 if (neededLen != -1) {
2341 neededLen -= retval;
2342 }
2343 continue;
2344 }
2345 if (JimCheckStreamError(interp, af)) {
2346 return JIM_ERR;
2347 }
2348 if (nb || af->timeout) {
2349 return JIM_OK;
2350 }
2351 }
2352
2353 return JIM_OK;
2354 }
2355
2356 static Jim_Obj *aio_read_consume(Jim_Interp *interp, AioFile *af, int neededLen)
2357 {
2358 Jim_Obj *objPtr = NULL;
2359
2360 if (neededLen < 0 || af->readbuf == NULL || Jim_Length(af->readbuf) <= neededLen) {
2361 objPtr = af->readbuf;
2362 af->readbuf = NULL;
2363 }
2364 else if (af->readbuf) {
2365
2366 int len;
2367 const char *pt = Jim_GetString(af->readbuf, &len);
2368
2369 objPtr = Jim_NewStringObj(interp, pt, neededLen);
2370 aio_consume(af->readbuf, neededLen);
2371 }
2372
2373 return objPtr;
2374 }
2375
2376 static void JimAioDelProc(Jim_Interp *interp, void *privData)
2377 {
2378 AioFile *af = privData;
2379
2380 JIM_NOTUSED(interp);
2381
2382
2383 aio_flush(interp, af);
2384 Jim_DecrRefCount(interp, af->writebuf);
2385
2386 #if UNIX_SOCKETS
2387 if (af->addr_family == PF_UNIX && (af->flags & AIO_NODELETE) == 0) {
2388
2389 Jim_Obj *filenameObj = aio_sockname(interp, af->fd);
2390 if (filenameObj) {
2391 if (Jim_Length(filenameObj)) {
2392 remove(Jim_String(filenameObj));
2393 }
2394 Jim_FreeNewObj(interp, filenameObj);
2395 }
2396 }
2397 #endif
2398
2399 Jim_DecrRefCount(interp, af->filename);
2400
2401 #ifdef jim_ext_eventloop
2402
2403 Jim_DeleteFileHandler(interp, af->fd, JIM_EVENT_READABLE | JIM_EVENT_WRITABLE | JIM_EVENT_EXCEPTION);
@@ -2093,144 +2406,180 @@
2406 #if defined(JIM_SSL)
2407 if (af->ssl != NULL) {
2408 SSL_free(af->ssl);
2409 }
2410 #endif
2411 if (!(af->flags & AIO_KEEPOPEN)) {
2412 close(af->fd);
2413 }
2414 if (af->readbuf) {
2415 Jim_FreeNewObj(interp, af->readbuf);
2416 }
2417
2418 Jim_Free(af);
2419 }
2420
2421 static int aio_cmd_read(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
2422 {
2423 AioFile *af = Jim_CmdPrivData(interp);
 
 
2424 int nonewline = 0;
2425 jim_wide neededLen = -1;
2426 static const char * const options[] = { "-pending", "-nonewline", NULL };
2427 enum { OPT_PENDING, OPT_NONEWLINE };
2428 int option;
2429 int nb;
2430 Jim_Obj *objPtr;
2431 char buf[AIO_BUF_LEN];
2432
2433 if (argc) {
2434 if (*Jim_String(argv[0]) == '-') {
2435 if (Jim_GetEnum(interp, argv[0], options, &option, NULL, JIM_ERRMSG) != JIM_OK) {
2436 return JIM_ERR;
2437 }
2438 switch (option) {
2439 case OPT_PENDING:
2440
2441 break;
2442 case OPT_NONEWLINE:
2443 nonewline++;
2444 break;
2445 }
2446 }
2447 else {
2448 if (Jim_GetWide(interp, argv[0], &neededLen) != JIM_OK)
2449 return JIM_ERR;
2450 if (neededLen < 0) {
2451 Jim_SetResultString(interp, "invalid parameter: negative len", -1);
2452 return JIM_ERR;
2453 }
2454 }
2455 argc--;
2456 argv++;
2457 }
2458 if (argc) {
 
 
 
 
 
 
 
2459 return -1;
2460 }
2461
2462
2463 nb = aio_start_nonblocking(af);
2464
2465 if (aio_read_len(interp, af, nb, buf, sizeof(buf), neededLen) != JIM_OK) {
2466 aio_set_nonblocking(af, nb);
2467 return JIM_ERR;
2468 }
2469 objPtr = aio_read_consume(interp, af, neededLen);
2470
2471 aio_set_nonblocking(af, nb);
2472
2473 if (objPtr) {
2474 if (nonewline) {
2475 int len;
2476 const char *s = Jim_GetString(objPtr, &len);
2477
2478 if (len > 0 && s[len - 1] == '\n') {
2479 objPtr->length--;
2480 objPtr->bytes[objPtr->length] = '\0';
2481 }
2482 }
2483 Jim_SetResult(interp, objPtr);
2484 }
2485 else {
2486 Jim_SetEmptyResult(interp);
2487 }
 
 
 
 
 
 
 
 
 
2488 return JIM_OK;
2489 }
2490
2491 int Jim_AioFilehandle(Jim_Interp *interp, Jim_Obj *command)
2492 {
2493 Jim_Cmd *cmdPtr = Jim_GetCommand(interp, command, JIM_ERRMSG);
2494
2495
2496 if (cmdPtr && !cmdPtr->isproc && cmdPtr->u.native.cmdProc == JimAioSubCmdProc) {
2497 return ((AioFile *) cmdPtr->u.native.privData)->fd;
2498 }
2499 Jim_SetResultFormatted(interp, "Not a filehandle: \"%#s\"", command);
2500 return -1;
 
 
 
 
 
 
 
 
 
 
 
 
2501 }
2502
2503 static int aio_cmd_getfd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
2504 {
2505 AioFile *af = Jim_CmdPrivData(interp);
2506
2507
2508 aio_flush(interp, af);
2509
2510 Jim_SetResultInt(interp, af->fd);
2511
2512 return JIM_OK;
2513 }
2514
2515 static int aio_cmd_copy(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
2516 {
2517 AioFile *af = Jim_CmdPrivData(interp);
2518 jim_wide count = 0;
2519 jim_wide maxlen = JIM_WIDE_MAX;
 
2520
2521 char buf[AIO_BUF_LEN];
2522
2523 char *bufp = buf;
2524 int buflen = sizeof(buf);
2525 int ok = 1;
2526 Jim_Obj *objv[4];
2527
2528 if (argc == 2) {
2529 if (Jim_GetWide(interp, argv[1], &maxlen) != JIM_OK) {
2530 return JIM_ERR;
2531 }
2532 }
2533
2534 objv[0] = argv[0];
2535 objv[1] = Jim_NewStringObj(interp, "flush", -1);
2536 if (Jim_EvalObjVector(interp, 2, objv) != JIM_OK) {
2537 Jim_SetResultFormatted(interp, "Not a filehandle: \"%#s\"", argv[0]);
2538 return JIM_ERR;
2539 }
2540
2541
2542 objv[0] = argv[0];
2543 objv[1] = Jim_NewStringObj(interp, "puts", -1);
2544 objv[2] = Jim_NewStringObj(interp, "-nonewline", -1);
2545 Jim_IncrRefCount(objv[1]);
2546 Jim_IncrRefCount(objv[2]);
2547
2548 while (count < maxlen) {
2549 jim_wide len = maxlen - count;
2550 if (len > buflen) {
2551 len = buflen;
2552 }
2553 if (aio_read_len(interp, af, 0, bufp, buflen, len) != JIM_OK) {
2554 ok = 0;
2555 break;
2556 }
2557 objv[3] = aio_read_consume(interp, af, len);
2558 count += Jim_Length(objv[3]);
2559 if (Jim_EvalObjVector(interp, 4, objv) != JIM_OK) {
2560 ok = 0;
2561 break;
2562 }
2563 if (aio_eof(af)) {
2564 break;
2565 }
2566 if (count >= 16384 && bufp == buf) {
2567
2568 buflen = 65536;
2569 bufp = Jim_Alloc(buflen);
2570 }
2571 }
2572
2573 if (bufp != buf) {
2574 Jim_Free(bufp);
2575 }
2576
2577 Jim_DecrRefCount(interp, objv[1]);
2578 Jim_DecrRefCount(interp, objv[2]);
2579
2580 if (!ok) {
2581 return JIM_ERR;
2582 }
2583
2584 Jim_SetResultInt(interp, count);
2585
@@ -2239,42 +2588,58 @@
2588
2589 static int aio_cmd_gets(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
2590 {
2591 AioFile *af = Jim_CmdPrivData(interp);
2592 char buf[AIO_BUF_LEN];
2593 Jim_Obj *objPtr = NULL;
2594 int len;
2595 int nb;
2596 char *nl = NULL;
2597 int offset = 0;
2598
2599 errno = 0;
2600
2601
2602 nb = aio_start_nonblocking(af);
2603
2604 if (!af->readbuf) {
2605 af->readbuf = Jim_NewStringObj(interp, NULL, 0);
2606 }
2607
2608 while (!aio_eof(af)) {
2609 const char *pt = Jim_GetString(af->readbuf, &len);
2610 nl = memchr(pt + offset, '\n', len - offset);
2611 if (nl) {
2612
2613 objPtr = Jim_NewStringObj(interp, pt, nl - pt);
2614
2615 aio_consume(af->readbuf, nl - pt + 1);
2616 break;
2617 }
2618
2619 offset = len;
2620 len = af->fops->reader(af, buf, AIO_BUF_LEN, nb);
2621 if (len <= 0) {
2622 if (nb || af->timeout) {
2623
2624 break;
2625 }
2626 }
2627 else {
2628 Jim_AppendString(interp, af->readbuf, buf, len);
2629 }
2630 }
2631
2632 aio_set_nonblocking(af, nb);
2633
2634 if (!nl && aio_eof(af)) {
2635
2636 objPtr = af->readbuf;
2637 af->readbuf = NULL;
2638 }
2639 else if (!objPtr) {
2640 objPtr = Jim_NewStringObj(interp, NULL, 0);
2641 }
2642
2643 if (argc) {
2644 if (Jim_SetVariable(interp, argv[0], objPtr) != JIM_OK) {
2645 Jim_FreeNewObj(interp, objPtr);
@@ -2281,11 +2646,11 @@
2646 return JIM_ERR;
2647 }
2648
2649 len = Jim_Length(objPtr);
2650
2651 if (!nl && len == 0) {
2652
2653 len = -1;
2654 }
2655 Jim_SetResultInt(interp, len);
2656 }
@@ -2299,36 +2664,62 @@
2664 {
2665 AioFile *af = Jim_CmdPrivData(interp);
2666 int wlen;
2667 const char *wdata;
2668 Jim_Obj *strObj;
2669 int wnow = 0;
2670 int nl = 1;
2671
2672 if (argc == 2) {
2673 if (!Jim_CompareStringImmediate(interp, argv[0], "-nonewline")) {
2674 return -1;
2675 }
2676 strObj = argv[1];
2677 nl = 0;
2678 }
2679 else {
2680 strObj = argv[0];
2681 }
2682
2683 Jim_AppendObj(interp, af->writebuf, strObj);
2684 if (nl) {
2685 Jim_AppendString(interp, af->writebuf, "\n", 1);
2686 }
2687
2688
2689 wdata = Jim_GetString(af->writebuf, &wlen);
2690 switch (af->wbuft) {
2691 case WBUF_OPT_NONE:
2692
2693 wnow = 1;
2694 break;
2695
2696 case WBUF_OPT_LINE:
2697
2698 if (nl || memchr(wdata, '\n', wlen) != NULL) {
2699 wnow = 1;
2700 }
2701 break;
2702
2703 case WBUF_OPT_FULL:
2704 if (wlen >= AIO_WBUF_FULL_SIZE) {
2705 wnow = 1;
2706 }
2707 break;
2708 }
2709
2710 if (wnow) {
2711 return aio_flush(interp, af);
2712 }
2713 return JIM_OK;
2714 }
2715
2716 static int aio_cmd_isatty(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
2717 {
2718 #ifdef HAVE_ISATTY
2719 AioFile *af = Jim_CmdPrivData(interp);
2720 Jim_SetResultInt(interp, isatty(af->fd));
2721 #else
2722 Jim_SetResultInt(interp, 0);
2723 #endif
2724
2725 return JIM_OK;
@@ -2336,49 +2727,62 @@
2727
2728
2729 static int aio_cmd_flush(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
2730 {
2731 AioFile *af = Jim_CmdPrivData(interp);
2732 return aio_flush(interp, af);
 
 
 
 
 
2733 }
2734
2735 static int aio_cmd_eof(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
2736 {
2737 AioFile *af = Jim_CmdPrivData(interp);
2738
2739 Jim_SetResultInt(interp, !!aio_eof(af));
2740 return JIM_OK;
2741 }
2742
2743 static int aio_cmd_close(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
2744 {
2745 AioFile *af = Jim_CmdPrivData(interp);
2746 if (argc == 3) {
2747 int option = -1;
2748 #if defined(HAVE_SOCKETS)
2749 static const char * const options[] = { "r", "w", "-nodelete", NULL };
2750 enum { OPT_R, OPT_W, OPT_NODELETE };
 
2751
2752 if (Jim_GetEnum(interp, argv[2], options, &option, NULL, JIM_ERRMSG) != JIM_OK) {
2753 return JIM_ERR;
2754 }
2755 #endif
2756 switch (option) {
2757 #if defined(HAVE_SHUTDOWN)
2758 case OPT_R:
2759 case OPT_W:
2760 if (shutdown(af->fd, option == OPT_R ? SHUT_RD : SHUT_WR) == 0) {
2761 return JIM_OK;
2762 }
2763 JimAioSetError(interp, NULL);
2764 return JIM_ERR;
2765 #endif
2766 #if UNIX_SOCKETS
2767 case OPT_NODELETE:
2768 if (af->addr_family == PF_UNIX) {
2769 af->flags |= AIO_NODELETE;
2770 break;
2771 }
2772
2773 #endif
2774 default:
2775 Jim_SetResultString(interp, "not supported", -1);
2776 return JIM_ERR;
2777 }
2778 }
2779
2780
2781 af->flags &= ~AIO_KEEPOPEN;
2782
2783 return Jim_DeleteCommand(interp, argv[0]);
2784 }
2785
2786 static int aio_cmd_seek(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
2787 {
2788 AioFile *af = Jim_CmdPrivData(interp);
@@ -2397,22 +2801,31 @@
2801 }
2802 }
2803 if (Jim_GetWide(interp, argv[0], &offset) != JIM_OK) {
2804 return JIM_ERR;
2805 }
2806 if (orig != SEEK_CUR || offset != 0) {
2807
2808 aio_flush(interp, af);
2809 }
2810 if (Jim_Lseek(af->fd, offset, orig) == -1) {
2811 JimAioSetError(interp, af->filename);
2812 return JIM_ERR;
2813 }
2814 if (af->readbuf) {
2815 Jim_FreeNewObj(interp, af->readbuf);
2816 af->readbuf = NULL;
2817 }
2818 af->flags &= ~AIO_EOF;
2819 return JIM_OK;
2820 }
2821
2822 static int aio_cmd_tell(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
2823 {
2824 AioFile *af = Jim_CmdPrivData(interp);
2825
2826 Jim_SetResultInt(interp, Jim_Lseek(af->fd, 0, SEEK_CUR));
2827 return JIM_OK;
2828 }
2829
2830 static int aio_cmd_filename(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
2831 {
@@ -2425,27 +2838,19 @@
2838 #ifdef O_NDELAY
2839 static int aio_cmd_ndelay(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
2840 {
2841 AioFile *af = Jim_CmdPrivData(interp);
2842
 
 
2843 if (argc) {
2844 long nb;
2845
2846 if (Jim_GetLong(interp, argv[0], &nb) != JIM_OK) {
2847 return JIM_ERR;
2848 }
2849 aio_set_nonblocking(af, nb);
2850 }
2851 Jim_SetResultInt(interp, (af->flags & AIO_NONBLOCK) ? 1 : 0);
 
 
 
 
 
 
2852 return JIM_OK;
2853 }
2854 #endif
2855
2856
@@ -2452,11 +2857,13 @@
2857 #ifdef HAVE_FSYNC
2858 static int aio_cmd_sync(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
2859 {
2860 AioFile *af = Jim_CmdPrivData(interp);
2861
2862 if (aio_flush(interp, af) != JIM_OK) {
2863 return JIM_ERR;
2864 }
2865 fsync(af->fd);
2866 return JIM_OK;
2867 }
2868 #endif
2869
@@ -2468,111 +2875,105 @@
2875 "none",
2876 "line",
2877 "full",
2878 NULL
2879 };
2880
2881 if (Jim_GetEnum(interp, argv[0], options, &af->wbuft, NULL, JIM_ERRMSG) != JIM_OK) {
 
 
 
 
 
 
 
2882 return JIM_ERR;
2883 }
2884
2885 if (af->wbuft == WBUF_OPT_NONE) {
2886 return aio_flush(interp, af);
2887 }
2888
2889 return JIM_OK;
2890 }
2891
2892 static int aio_cmd_timeout(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
2893 {
2894 #ifdef HAVE_SELECT
2895 AioFile *af = Jim_CmdPrivData(interp);
2896 if (argc == 1) {
2897 if (Jim_GetLong(interp, argv[0], &af->timeout) != JIM_OK) {
2898 return JIM_ERR;
2899 }
2900 }
2901 Jim_SetResultInt(interp, af->timeout);
2902 return JIM_OK;
2903 #else
2904 Jim_SetResultString(interp, "timeout not supported", -1);
2905 return JIM_ERR;
2906 #endif
2907 }
2908
2909 #ifdef jim_ext_eventloop
2910 static int aio_eventinfo(Jim_Interp *interp, AioFile * af, unsigned mask,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2911 int argc, Jim_Obj * const *argv)
2912 {
2913 if (argc == 0) {
2914
2915 Jim_Obj *objPtr = Jim_FindFileHandler(interp, af->fd, mask);
2916 if (objPtr) {
2917 Jim_SetResult(interp, objPtr);
2918 }
2919 return JIM_OK;
2920 }
2921
2922
2923 Jim_DeleteFileHandler(interp, af->fd, mask);
2924
2925
2926 if (Jim_Length(argv[0])) {
2927 Jim_CreateScriptFileHandler(interp, af->fd, mask, argv[0]);
2928 }
 
 
 
 
 
 
 
 
 
 
2929
2930 return JIM_OK;
2931 }
2932
2933 static int aio_cmd_readable(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
2934 {
2935 AioFile *af = Jim_CmdPrivData(interp);
2936
2937 return aio_eventinfo(interp, af, JIM_EVENT_READABLE, argc, argv);
2938 }
2939
2940 static int aio_cmd_writable(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
2941 {
2942 AioFile *af = Jim_CmdPrivData(interp);
2943
2944 return aio_eventinfo(interp, af, JIM_EVENT_WRITABLE, argc, argv);
2945 }
2946
2947 static int aio_cmd_onexception(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
2948 {
2949 AioFile *af = Jim_CmdPrivData(interp);
2950
2951 return aio_eventinfo(interp, af, JIM_EVENT_EXCEPTION, argc, argv);
2952 }
2953 #endif
2954
2955 #if defined(jim_ext_file) && defined(Jim_FileStat)
2956 static int aio_cmd_stat(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
2957 {
2958 jim_stat_t sb;
2959 AioFile *af = Jim_CmdPrivData(interp);
2960
2961 if (Jim_FileStat(af->fd, &sb) == -1) {
2962 JimAioSetError(interp, NULL);
2963 return JIM_ERR;
2964 }
2965 return Jim_FileStoreStatData(interp, argc == 0 ? NULL : argv[0], &sb);
2966 }
2967 #endif
2968
2969
2970
2971
2972 static const jim_subcmd_type aio_command_table[] = {
2973 { "read",
2974 "?-nonewline|len?",
2975 aio_cmd_read,
2976 0,
2977 2,
2978
2979 },
@@ -2677,10 +3078,19 @@
3078 aio_cmd_buffering,
3079 1,
3080 1,
3081
3082 },
3083 #if defined(jim_ext_file) && defined(Jim_FileStat)
3084 { "stat",
3085 "?var?",
3086 aio_cmd_stat,
3087 0,
3088 1,
3089
3090 },
3091 #endif
3092 #ifdef jim_ext_eventloop
3093 { "readable",
3094 "?readable-script?",
3095 aio_cmd_readable,
3096 0,
@@ -2698,126 +3108,235 @@
3108 "?exception-script?",
3109 aio_cmd_onexception,
3110 0,
3111 1,
3112
3113 },
3114 { "timeout",
3115 "?ms?",
3116 aio_cmd_timeout,
3117 0,
3118 1,
3119
3120 },
3121 #endif
3122 { NULL }
3123 };
3124
3125 static int JimAioSubCmdProc(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
3126 {
3127 return Jim_CallSubCmd(interp, Jim_ParseSubCmd(interp, aio_command_table, argc, argv), argc, argv);
3128 }
3129
3130 static int parse_posix_open_mode(Jim_Interp *interp, Jim_Obj *modeObj)
3131 {
3132 int i;
3133 int flags = 0;
3134 #ifndef O_NOCTTY
3135
3136 #define O_NOCTTY 0
3137 #endif
3138 static const char * const modetypes[] = {
3139 "RDONLY", "WRONLY", "RDWR", "APPEND", "BINARY", "CREAT", "EXCL", "NOCTTY", "TRUNC", NULL
3140 };
3141 static const int modeflags[] = {
3142 O_RDONLY, O_WRONLY, O_RDWR, O_APPEND, 0, O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC,
3143 };
3144
3145 for (i = 0; i < Jim_ListLength(interp, modeObj); i++) {
3146 int opt;
3147 Jim_Obj *objPtr = Jim_ListGetIndex(interp, modeObj, i);
3148 if (Jim_GetEnum(interp, objPtr, modetypes, &opt, "access mode", JIM_ERRMSG) != JIM_OK) {
3149 return -1;
3150 }
3151 flags |= modeflags[opt];
3152 }
3153 return flags;
3154 }
3155
3156 static int parse_open_mode(Jim_Interp *interp, Jim_Obj *filenameObj, Jim_Obj *modeObj)
3157 {
3158
3159 int flags;
3160 const char *mode = Jim_String(modeObj);
3161 if (*mode == 'R' || *mode == 'W') {
3162 return parse_posix_open_mode(interp, modeObj);
3163 }
3164 if (*mode == 'r') {
3165 flags = O_RDONLY;
3166 }
3167 else if (*mode == 'w') {
3168 flags = O_WRONLY | O_CREAT | O_TRUNC;
3169 }
3170 else if (*mode == 'a') {
3171 flags = O_WRONLY | O_CREAT | O_APPEND;
3172 }
3173 else {
3174 Jim_SetResultFormatted(interp, "%s: invalid open mode '%s'", Jim_String(filenameObj), mode);
3175 return -1;
3176 }
3177 mode++;
3178
3179 if (*mode == 'b') {
3180 #ifdef O_BINARY
3181 flags |= O_BINARY;
3182 #endif
3183 mode++;
3184 }
3185
3186 if (*mode == 't') {
3187 #ifdef O_TEXT
3188 flags |= O_TEXT;
3189 #endif
3190 mode++;
3191 }
3192
3193 if (*mode == '+') {
3194 mode++;
3195
3196 flags &= ~(O_RDONLY | O_WRONLY);
3197 flags |= O_RDWR;
3198 }
3199
3200 if (*mode == 'x') {
3201 mode++;
3202 #ifdef O_EXCL
3203 flags |= O_EXCL;
3204 #endif
3205 }
3206
3207 if (*mode == 'F') {
3208 mode++;
3209 #ifdef O_LARGEFILE
3210 flags |= O_LARGEFILE;
3211 #endif
3212 }
3213
3214 if (*mode == 'e') {
3215
3216 mode++;
3217 }
3218 return flags;
3219 }
3220
3221 static int JimAioOpenCommand(Jim_Interp *interp, int argc,
3222 Jim_Obj *const *argv)
3223 {
3224 int openflags;
3225 const char *filename;
3226 int fd = -1;
3227 int n = 0;
3228 int flags = 0;
3229
3230 if (argc > 2 && Jim_CompareStringImmediate(interp, argv[2], "-noclose")) {
3231 flags = AIO_KEEPOPEN;
3232 n++;
3233 }
3234 if (argc < 2 || argc > 3 + n) {
3235 Jim_WrongNumArgs(interp, 1, argv, "filename ?-noclose? ?mode?");
3236 return JIM_ERR;
3237 }
3238
3239 filename = Jim_String(argv[1]);
3240
3241 #ifdef jim_ext_tclcompat
3242 {
 
3243
3244
3245 if (*filename == '|') {
3246 Jim_Obj *evalObj[3];
3247 int i = 0;
3248
3249 evalObj[i++] = Jim_NewStringObj(interp, "::popen", -1);
3250 evalObj[i++] = Jim_NewStringObj(interp, filename + 1, -1);
3251 if (argc == 3 + n) {
3252 evalObj[i++] = argv[2 + n];
3253 }
3254
3255 return Jim_EvalObjVector(interp, i, evalObj);
3256 }
3257 }
3258 #endif
3259 if (argc == 3 + n) {
3260 openflags = parse_open_mode(interp, argv[1], argv[2 + n]);
3261 if (openflags == -1) {
3262 return JIM_ERR;
3263 }
3264 }
3265 else {
3266 openflags = O_RDONLY;
3267 }
3268 fd = open(filename, openflags, 0666);
3269 if (fd < 0) {
3270 JimAioSetError(interp, argv[1]);
3271 return JIM_ERR;
3272 }
3273
3274 return JimMakeChannel(interp, fd, argv[1], "aio.handle%ld", 0, flags) ? JIM_OK : JIM_ERR;
3275 }
3276
3277
3278 static AioFile *JimMakeChannel(Jim_Interp *interp, int fd, Jim_Obj *filename,
3279 const char *hdlfmt, int family, int flags)
3280 {
3281 AioFile *af;
3282 char buf[AIO_CMD_LEN];
3283 Jim_Obj *cmdname;
3284
3285 snprintf(buf, sizeof(buf), hdlfmt, Jim_GetId(interp));
3286 cmdname = Jim_NewStringObj(interp, buf, -1);
3287 if (!filename) {
3288 filename = cmdname;
3289 }
3290 Jim_IncrRefCount(filename);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3291
3292
3293 af = Jim_Alloc(sizeof(*af));
3294 memset(af, 0, sizeof(*af));
 
3295 af->filename = filename;
3296 af->fd = fd;
3297 af->addr_family = family;
3298 af->fops = &stdio_fops;
3299 af->ssl = NULL;
3300 if (flags & AIO_WBUF_NONE) {
3301 af->wbuft = WBUF_OPT_NONE;
3302 }
3303 else {
3304 #ifdef HAVE_ISATTY
3305 af->wbuft = isatty(af->fd) ? WBUF_OPT_LINE : WBUF_OPT_FULL;
3306 #else
3307 af->wbuft = WBUF_OPT_FULL;
3308 #endif
3309 }
3310
3311 #ifdef FD_CLOEXEC
3312 if ((flags & AIO_KEEPOPEN) == 0) {
3313 (void)fcntl(af->fd, F_SETFD, FD_CLOEXEC);
3314 }
3315 #endif
3316 aio_set_nonblocking(af, !!(flags & AIO_NONBLOCK));
3317
3318 af->flags |= flags;
3319
3320 af->writebuf = Jim_NewStringObj(interp, NULL, 0);
3321 Jim_IncrRefCount(af->writebuf);
3322
3323 Jim_CreateCommand(interp, buf, JimAioSubCmdProc, af, JimAioDelProc);
3324
3325 Jim_SetResult(interp, Jim_MakeGlobalNamespaceName(interp, cmdname));
3326
3327 return af;
3328 }
3329
3330 #if defined(HAVE_PIPE) || (defined(HAVE_SOCKETPAIR) && UNIX_SOCKETS) || defined(HAVE_OPENPTY)
3331 static int JimMakeChannelPair(Jim_Interp *interp, int p[2], Jim_Obj *filename,
3332 const char *hdlfmt, int family, int flags)
3333 {
3334 if (JimMakeChannel(interp, p[0], filename, hdlfmt, family, flags)) {
3335 Jim_Obj *objPtr = Jim_NewListObj(interp, NULL, 0);
3336 Jim_ListAppendElement(interp, objPtr, Jim_GetResult(interp));
3337 if (JimMakeChannel(interp, p[1], filename, hdlfmt, family, flags)) {
3338 Jim_ListAppendElement(interp, objPtr, Jim_GetResult(interp));
3339 Jim_SetResult(interp, objPtr);
3340 return JIM_OK;
3341 }
3342 }
@@ -2829,26 +3348,52 @@
3348 return JIM_ERR;
3349 }
3350 #endif
3351
3352 #ifdef HAVE_PIPE
3353 static int JimCreatePipe(Jim_Interp *interp, Jim_Obj *filenameObj, int flags)
3354 {
3355 int p[2];
 
 
 
 
 
 
3356
3357 if (pipe(p) != 0) {
3358 JimAioSetError(interp, NULL);
3359 return JIM_ERR;
3360 }
3361
3362 return JimMakeChannelPair(interp, p, filenameObj, "aio.pipe%ld", 0, flags);
3363 }
3364
3365
3366 static int JimAioPipeCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
3367 {
3368 if (argc != 1) {
3369 Jim_WrongNumArgs(interp, 1, argv, "");
3370 return JIM_ERR;
3371 }
3372 return JimCreatePipe(interp, argv[0], 0);
3373 }
3374 #endif
3375
3376 #ifdef HAVE_OPENPTY
3377 static int JimAioOpenPtyCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
3378 {
3379 int p[2];
3380 char path[MAXPATHLEN];
3381
3382 if (argc != 1) {
3383 Jim_WrongNumArgs(interp, 1, argv, "");
3384 return JIM_ERR;
3385 }
3386
3387 if (openpty(&p[0], &p[1], path, NULL, NULL) != 0) {
3388 JimAioSetError(interp, NULL);
3389 return JIM_ERR;
3390 }
3391
3392
3393 return JimMakeChannelPair(interp, p, Jim_NewStringObj(interp, path, -1), "aio.pty%ld", 0, 0);
3394 return JimMakeChannelPair(interp, p, Jim_NewStringObj(interp, path, -1), "aio.pty%ld", 0, 0);
3395 }
3396 #endif
3397
3398
3399
@@ -2868,13 +3413,13 @@
3413 #ifdef HAVE_PIPE
3414 Jim_CreateCommand(interp, "pipe", JimAioPipeCommand, NULL, NULL);
3415 #endif
3416
3417
3418 JimMakeChannel(interp, fileno(stdin), NULL, "stdin", 0, AIO_KEEPOPEN);
3419 JimMakeChannel(interp, fileno(stdout), NULL, "stdout", 0, AIO_KEEPOPEN);
3420 JimMakeChannel(interp, fileno(stderr), NULL, "stderr", 0, AIO_KEEPOPEN | AIO_WBUF_NONE);
3421
3422 return JIM_OK;
3423 }
3424
3425 #include <errno.h>
@@ -2932,13 +3477,11 @@
3477 }
3478 }
3479
3480 int Jim_readdirInit(Jim_Interp *interp)
3481 {
3482 Jim_PackageProvideCheck(interp, "readdir");
 
 
3483 Jim_CreateCommand(interp, "readdir", Jim_ReaddirCmd, NULL, NULL);
3484 return JIM_OK;
3485 }
3486
3487 #include <stdlib.h>
@@ -2945,15 +3488,19 @@
3488 #include <string.h>
3489
3490 #if defined(JIM_REGEXP)
3491 #else
3492 #include <regex.h>
3493 #define jim_regcomp regcomp
3494 #define jim_regexec regexec
3495 #define jim_regerror regerror
3496 #define jim_regfree regfree
3497 #endif
3498
3499 static void FreeRegexpInternalRep(Jim_Interp *interp, Jim_Obj *objPtr)
3500 {
3501 jim_regfree(objPtr->internalRep.ptrIntValue.ptr);
3502 Jim_Free(objPtr->internalRep.ptrIntValue.ptr);
3503 }
3504
3505 static const Jim_ObjType regexpObjType = {
3506 "regexp",
@@ -2980,16 +3527,16 @@
3527
3528
3529 pattern = Jim_String(objPtr);
3530 compre = Jim_Alloc(sizeof(regex_t));
3531
3532 if ((ret = jim_regcomp(compre, pattern, REG_EXTENDED | flags)) != 0) {
3533 char buf[100];
3534
3535 jim_regerror(ret, compre, buf, sizeof(buf));
3536 Jim_SetResultFormatted(interp, "couldn't compile regular expression pattern: %s", buf);
3537 jim_regfree(compre);
3538 Jim_Free(compre);
3539 return NULL;
3540 }
3541
3542 Jim_FreeIntRep(interp, objPtr);
@@ -3110,25 +3657,25 @@
3657 }
3658 if (offset > source_len) {
3659 source_str += source_len;
3660 }
3661 else if (offset > 0) {
3662 source_str += utf8_index(source_str, offset);
3663 }
3664 eflags |= REG_NOTBOL;
3665 }
3666
3667 if (opt_inline) {
3668 resultListObj = Jim_NewListObj(interp, NULL, 0);
3669 }
3670
3671 next_match:
3672 match = jim_regexec(regex, source_str, num_vars + 1, pmatch, eflags);
3673 if (match >= REG_BADPAT) {
3674 char buf[100];
3675
3676 jim_regerror(match, regex, buf, sizeof(buf));
3677 Jim_SetResultFormatted(interp, "error while matching pattern: %s", buf);
3678 result = JIM_ERR;
3679 goto done;
3680 }
3681
@@ -3160,20 +3707,19 @@
3707 Jim_ListAppendElement(interp, resultObj, Jim_NewIntObj(interp, -1));
3708 Jim_ListAppendElement(interp, resultObj, Jim_NewIntObj(interp, -1));
3709 }
3710 }
3711 else {
 
 
3712 if (opt_indices) {
3713
3714 int so = utf8_strlen(source_str, pmatch[j].rm_so);
3715 int eo = utf8_strlen(source_str, pmatch[j].rm_eo);
3716 Jim_ListAppendElement(interp, resultObj, Jim_NewIntObj(interp, offset + so));
3717 Jim_ListAppendElement(interp, resultObj, Jim_NewIntObj(interp, offset + eo - 1));
3718 }
3719 else {
3720 Jim_AppendString(interp, resultObj, source_str + pmatch[j].rm_so, pmatch[j].rm_eo - pmatch[j].rm_so);
3721 }
3722 }
3723
3724 if (opt_inline) {
3725 Jim_ListAppendElement(interp, resultListObj, resultObj);
@@ -3190,11 +3736,11 @@
3736 }
3737
3738 try_next_match:
3739 if (opt_all && (pattern[0] != '^' || (regcomp_flags & REG_NEWLINE)) && *source_str) {
3740 if (pmatch[0].rm_eo) {
3741 offset += utf8_strlen(source_str, pmatch[0].rm_eo);
3742 source_str += pmatch[0].rm_eo;
3743 }
3744 else {
3745 source_str++;
3746 offset++;
@@ -3319,23 +3865,25 @@
3865 else if (offset < 0) {
3866 offset = 0;
3867 }
3868 }
3869
3870 offset = utf8_index(source_str, offset);
3871
3872
3873 Jim_AppendString(interp, resultObj, source_str, offset);
3874
3875
3876 n = source_len - offset;
3877 p = source_str + offset;
3878 do {
3879 int match = jim_regexec(regex, p, MAX_SUB_MATCHES, pmatch, regexec_flags);
3880
3881 if (match >= REG_BADPAT) {
3882 char buf[100];
3883
3884 jim_regerror(match, regex, buf, sizeof(buf));
3885 Jim_SetResultFormatted(interp, "error while matching pattern: %s", buf);
3886 return JIM_ERR;
3887 }
3888 if (match == REG_NOMATCH) {
3889 break;
@@ -3396,11 +3944,18 @@
3944 Jim_AppendString(interp, resultObj, p, 1);
3945 p++;
3946 n--;
3947 }
3948
3949 if (pmatch[0].rm_eo == pmatch[0].rm_so) {
3950
3951 regexec_flags = REG_NOTBOL;
3952 }
3953 else {
3954 regexec_flags = 0;
3955 }
3956
3957 } while (n);
3958
3959 Jim_AppendString(interp, resultObj, p, -1);
3960
3961
@@ -3422,13 +3977,11 @@
3977 return result;
3978 }
3979
3980 int Jim_regexpInit(Jim_Interp *interp)
3981 {
3982 Jim_PackageProvideCheck(interp, "regexp");
 
 
3983 Jim_CreateCommand(interp, "regexp", Jim_RegexpCmd, NULL, NULL);
3984 Jim_CreateCommand(interp, "regsub", Jim_RegsubCmd, NULL, NULL);
3985 return JIM_OK;
3986 }
3987
@@ -3435,11 +3988,10 @@
3988 #include <limits.h>
3989 #include <stdlib.h>
3990 #include <string.h>
3991 #include <stdio.h>
3992 #include <errno.h>
 
3993
3994
3995 #ifdef HAVE_UTIMES
3996 #include <sys/time.h>
3997 #endif
@@ -3453,15 +4005,21 @@
4005 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
4006 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
4007 #endif
4008
4009 # ifndef MAXPATHLEN
4010 # ifdef PATH_MAX
4011 # define MAXPATHLEN PATH_MAX
4012 # else
4013 # define MAXPATHLEN JIM_PATH_LEN
4014 # endif
4015 # endif
4016
4017 #if defined(__MINGW32__) || defined(__MSYS__) || defined(_MSC_VER)
4018 #define ISWINDOWS 1
4019
4020 #undef HAVE_SYMLINK
4021 #else
4022 #define ISWINDOWS 0
4023 #endif
4024
4025
@@ -3469,10 +4027,22 @@
4027 #define STAT_MTIME_US(STAT) ((STAT).st_mtimespec.tv_sec * 1000000ll + (STAT).st_mtimespec.tv_nsec / 1000)
4028 #elif defined(HAVE_STRUCT_STAT_ST_MTIM)
4029 #define STAT_MTIME_US(STAT) ((STAT).st_mtim.tv_sec * 1000000ll + (STAT).st_mtim.tv_nsec / 1000)
4030 #endif
4031
4032
4033 static void JimFixPath(char *path)
4034 {
4035 if (ISWINDOWS) {
4036
4037 char *p = path;
4038 while ((p = strchr(p, '\\')) != NULL) {
4039 *p++ = '/';
4040 }
4041 }
4042 }
4043
4044
4045 static const char *JimGetFileType(int mode)
4046 {
4047 if (S_ISREG(mode)) {
4048 return "file";
@@ -3512,11 +4082,11 @@
4082 {
4083 Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, key, -1));
4084 Jim_ListAppendElement(interp, listObj, Jim_NewIntObj(interp, value));
4085 }
4086
4087 int Jim_FileStoreStatData(Jim_Interp *interp, Jim_Obj *varName, const jim_stat_t *sb)
4088 {
4089
4090 Jim_Obj *listObj = Jim_NewListObj(interp, NULL, 0);
4091
4092 AppendStatElement(interp, listObj, "dev", sb->st_dev);
@@ -3565,31 +4135,91 @@
4135
4136 Jim_SetResult(interp, listObj);
4137
4138 return JIM_OK;
4139 }
4140
4141 static int JimPathLenNoTrailingSlashes(const char *path, int len)
4142 {
4143 int i;
4144 for (i = len; i > 1 && path[i - 1] == '/'; i--) {
4145
4146 if (ISWINDOWS && path[i - 2] == ':') {
4147
4148 break;
4149 }
4150 }
4151 return i;
4152 }
4153
4154 static Jim_Obj *JimStripTrailingSlashes(Jim_Interp *interp, Jim_Obj *objPtr)
4155 {
4156 int len = Jim_Length(objPtr);
4157 const char *path = Jim_String(objPtr);
4158 int i = JimPathLenNoTrailingSlashes(path, len);
4159 if (i != len) {
4160 objPtr = Jim_NewStringObj(interp, path, i);
4161 }
4162 Jim_IncrRefCount(objPtr);
4163 return objPtr;
4164 }
4165
4166 static int file_cmd_dirname(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
4167 {
4168 Jim_Obj *objPtr = JimStripTrailingSlashes(interp, argv[0]);
4169 const char *path = Jim_String(objPtr);
4170 const char *p = strrchr(path, '/');
4171
4172 if (!p) {
 
 
4173 Jim_SetResultString(interp, ".", -1);
4174 }
4175 else if (p[1] == 0) {
4176
4177 Jim_SetResult(interp, objPtr);
4178 }
4179 else if (p == path) {
4180 Jim_SetResultString(interp, "/", -1);
4181 }
4182 else if (ISWINDOWS && p[-1] == ':') {
4183
4184 Jim_SetResultString(interp, path, p - path + 1);
4185 }
4186 else {
4187
4188 int len = JimPathLenNoTrailingSlashes(path, p - path);
4189 Jim_SetResultString(interp, path, len);
4190 }
4191 Jim_DecrRefCount(interp, objPtr);
4192 return JIM_OK;
4193 }
4194
4195 static int file_cmd_split(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
4196 {
4197 Jim_Obj *listObj = Jim_NewListObj(interp, NULL, 0);
4198 const char *path = Jim_String(argv[0]);
4199
4200 if (*path == '/') {
4201 Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, "/", 1));
4202 }
4203
4204 while (1) {
4205
4206 while (*path == '/') {
4207 path++;
4208 }
4209 if (*path) {
4210 const char *pt = strchr(path, '/');
4211 if (pt) {
4212 Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, path, pt - path));
4213 path = pt;
4214 continue;
4215 }
4216 Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, path, -1));
4217 }
4218 break;
4219 }
4220 Jim_SetResult(interp, listObj);
4221 return JIM_OK;
4222 }
4223
4224 static int file_cmd_rootname(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
4225 {
@@ -3606,54 +4236,67 @@
4236 return JIM_OK;
4237 }
4238
4239 static int file_cmd_extension(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
4240 {
4241 Jim_Obj *objPtr = JimStripTrailingSlashes(interp, argv[0]);
4242 const char *path = Jim_String(objPtr);
4243 const char *lastSlash = strrchr(path, '/');
4244 const char *p = strrchr(path, '.');
4245
4246 if (p == NULL || (lastSlash != NULL && lastSlash >= p)) {
4247 p = "";
4248 }
4249 Jim_SetResultString(interp, p, -1);
4250 Jim_DecrRefCount(interp, objPtr);
4251 return JIM_OK;
4252 }
4253
4254 static int file_cmd_tail(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
4255 {
4256 Jim_Obj *objPtr = JimStripTrailingSlashes(interp, argv[0]);
4257 const char *path = Jim_String(objPtr);
4258 const char *lastSlash = strrchr(path, '/');
4259
4260 if (lastSlash) {
4261 Jim_SetResultString(interp, lastSlash + 1, -1);
4262 }
4263 else {
4264 Jim_SetResult(interp, objPtr);
4265 }
4266 Jim_DecrRefCount(interp, objPtr);
4267 return JIM_OK;
4268 }
4269
4270 #ifndef HAVE_RESTRICT
4271 #define restrict
4272 #endif
4273
4274 static char *JimRealPath(const char *restrict path, char *restrict resolved_path, size_t len)
4275 {
4276 #if defined(HAVE__FULLPATH)
4277 return _fullpath(resolved_path, path, len);
4278 #elif defined(HAVE_REALPATH)
4279 return realpath(path, resolved_path);
4280 #else
4281 return NULL;
4282 #endif
4283 }
4284
4285 static int file_cmd_normalize(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
4286 {
 
4287 const char *path = Jim_String(argv[0]);
4288 char *newname = Jim_Alloc(MAXPATHLEN);
4289
4290 if (JimRealPath(path, newname, MAXPATHLEN)) {
4291 JimFixPath(newname);
4292 Jim_SetResult(interp, Jim_NewStringObjNoAlloc(interp, newname, -1));
4293 return JIM_OK;
4294 }
4295 Jim_Free(newname);
4296 Jim_SetResultFormatted(interp, "can't normalize \"%#s\": %s", argv[0], strerror(errno));
4297 return JIM_ERR;
 
 
 
 
 
 
4298 }
4299
4300 static int file_cmd_join(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
4301 {
4302 int i;
@@ -3755,12 +4398,12 @@
4398 static int file_cmd_delete(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
4399 {
4400 int force = Jim_CompareStringImmediate(interp, argv[0], "-force");
4401
4402 if (force || Jim_CompareStringImmediate(interp, argv[0], "--")) {
4403 argc--;
4404 argv++;
4405 }
4406
4407 while (argc--) {
4408 const char *path = Jim_String(argv[0]);
4409
@@ -3813,13 +4456,13 @@
4456
4457 continue;
4458 }
4459
4460 if (errno == EEXIST) {
4461 jim_stat_t sb;
4462
4463 if (Jim_Stat(path, &sb) == 0 && S_ISDIR(sb.st_mode)) {
4464 return 0;
4465 }
4466
4467 errno = EEXIST;
4468 }
@@ -3879,11 +4522,16 @@
4522 if (!force && access(dest, F_OK) == 0) {
4523 Jim_SetResultFormatted(interp, "error renaming \"%#s\" to \"%#s\": target exists", argv[0],
4524 argv[1]);
4525 return JIM_ERR;
4526 }
4527 #if ISWINDOWS
4528 if (access(dest, F_OK) == 0) {
4529
4530 remove(dest);
4531 }
4532 #endif
4533 if (rename(source, dest) != 0) {
4534 Jim_SetResultFormatted(interp, "error renaming \"%#s\" to \"%#s\": %s", argv[0], argv[1],
4535 strerror(errno));
4536 return JIM_ERR;
4537 }
@@ -3927,27 +4575,27 @@
4575
4576 return JIM_OK;
4577 }
4578 #endif
4579
4580 static int file_stat(Jim_Interp *interp, Jim_Obj *filename, jim_stat_t *sb)
4581 {
4582 const char *path = Jim_String(filename);
4583
4584 if (Jim_Stat(path, sb) == -1) {
4585 Jim_SetResultFormatted(interp, "could not read \"%#s\": %s", filename, strerror(errno));
4586 return JIM_ERR;
4587 }
4588 return JIM_OK;
4589 }
4590
4591 #ifdef Jim_LinkStat
4592 static int file_lstat(Jim_Interp *interp, Jim_Obj *filename, jim_stat_t *sb)
4593 {
4594 const char *path = Jim_String(filename);
4595
4596 if (Jim_LinkStat(path, sb) == -1) {
4597 Jim_SetResultFormatted(interp, "could not read \"%#s\": %s", filename, strerror(errno));
4598 return JIM_ERR;
4599 }
4600 return JIM_OK;
4601 }
@@ -3955,11 +4603,11 @@
4603 #define file_lstat file_stat
4604 #endif
4605
4606 static int file_cmd_atime(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
4607 {
4608 jim_stat_t sb;
4609
4610 if (file_stat(interp, argv[0], &sb) != JIM_OK) {
4611 return JIM_ERR;
4612 }
4613 Jim_SetResultInt(interp, sb.st_atime);
@@ -3985,11 +4633,11 @@
4633 #endif
4634 }
4635
4636 static int file_cmd_mtime(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
4637 {
4638 jim_stat_t sb;
4639
4640 if (argc == 2) {
4641 jim_wide secs;
4642 if (Jim_GetWide(interp, argv[1], &secs) != JIM_OK) {
4643 return JIM_ERR;
@@ -4004,11 +4652,11 @@
4652 }
4653
4654 #ifdef STAT_MTIME_US
4655 static int file_cmd_mtimeus(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
4656 {
4657 jim_stat_t sb;
4658
4659 if (argc == 2) {
4660 jim_wide us;
4661 if (Jim_GetWide(interp, argv[1], &us) != JIM_OK) {
4662 return JIM_ERR;
@@ -4028,11 +4676,11 @@
4676 return Jim_EvalPrefix(interp, "file copy", argc, argv);
4677 }
4678
4679 static int file_cmd_size(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
4680 {
4681 jim_stat_t sb;
4682
4683 if (file_stat(interp, argv[0], &sb) != JIM_OK) {
4684 return JIM_ERR;
4685 }
4686 Jim_SetResultInt(interp, sb.st_size);
@@ -4039,11 +4687,11 @@
4687 return JIM_OK;
4688 }
4689
4690 static int file_cmd_isdirectory(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
4691 {
4692 jim_stat_t sb;
4693 int ret = 0;
4694
4695 if (file_stat(interp, argv[0], &sb) == JIM_OK) {
4696 ret = S_ISDIR(sb.st_mode);
4697 }
@@ -4051,11 +4699,11 @@
4699 return JIM_OK;
4700 }
4701
4702 static int file_cmd_isfile(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
4703 {
4704 jim_stat_t sb;
4705 int ret = 0;
4706
4707 if (file_stat(interp, argv[0], &sb) == JIM_OK) {
4708 ret = S_ISREG(sb.st_mode);
4709 }
@@ -4064,11 +4712,11 @@
4712 }
4713
4714 #ifdef HAVE_GETEUID
4715 static int file_cmd_owned(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
4716 {
4717 jim_stat_t sb;
4718 int ret = 0;
4719
4720 if (file_stat(interp, argv[0], &sb) == JIM_OK) {
4721 ret = (geteuid() == sb.st_uid);
4722 }
@@ -4085,11 +4733,11 @@
4733
4734 int linkLength = readlink(path, linkValue, MAXPATHLEN);
4735
4736 if (linkLength == -1) {
4737 Jim_Free(linkValue);
4738 Jim_SetResultFormatted(interp, "could not read link \"%#s\": %s", argv[0], strerror(errno));
4739 return JIM_ERR;
4740 }
4741 linkValue[linkLength] = 0;
4742 Jim_SetResult(interp, Jim_NewStringObjNoAlloc(interp, linkValue, linkLength));
4743 return JIM_OK;
@@ -4096,41 +4744,41 @@
4744 }
4745 #endif
4746
4747 static int file_cmd_type(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
4748 {
4749 jim_stat_t sb;
4750
4751 if (file_lstat(interp, argv[0], &sb) != JIM_OK) {
4752 return JIM_ERR;
4753 }
4754 Jim_SetResultString(interp, JimGetFileType((int)sb.st_mode), -1);
4755 return JIM_OK;
4756 }
4757
4758 #ifdef Jim_LinkStat
4759 static int file_cmd_lstat(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
4760 {
4761 jim_stat_t sb;
4762
4763 if (file_lstat(interp, argv[0], &sb) != JIM_OK) {
4764 return JIM_ERR;
4765 }
4766 return Jim_FileStoreStatData(interp, argc == 2 ? argv[1] : NULL, &sb);
4767 }
4768 #else
4769 #define file_cmd_lstat file_cmd_stat
4770 #endif
4771
4772 static int file_cmd_stat(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
4773 {
4774 jim_stat_t sb;
4775
4776 if (file_stat(interp, argv[0], &sb) != JIM_OK) {
4777 return JIM_ERR;
4778 }
4779 return Jim_FileStoreStatData(interp, argc == 2 ? argv[1] : NULL, &sb);
4780 }
4781
4782 static const jim_subcmd_type file_command_table[] = {
4783 { "atime",
4784 "name",
@@ -4187,10 +4835,17 @@
4835 "name",
4836 file_cmd_tail,
4837 1,
4838 1,
4839
4840 },
4841 { "split",
4842 "name",
4843 file_cmd_split,
4844 1,
4845 1,
4846
4847 },
4848 { "normalize",
4849 "name",
4850 file_cmd_normalize,
4851 1,
@@ -4360,43 +5015,31 @@
5015 if (getcwd(cwd, MAXPATHLEN) == NULL) {
5016 Jim_SetResultString(interp, "Failed to get pwd", -1);
5017 Jim_Free(cwd);
5018 return JIM_ERR;
5019 }
5020 JimFixPath(cwd);
 
 
 
 
 
 
 
5021 Jim_SetResultString(interp, cwd, -1);
5022
5023 Jim_Free(cwd);
5024 return JIM_OK;
5025 }
5026
5027 int Jim_fileInit(Jim_Interp *interp)
5028 {
5029 Jim_PackageProvideCheck(interp, "file");
 
 
5030 Jim_CreateCommand(interp, "file", Jim_SubCmdProc, (void *)file_command_table, NULL);
5031 Jim_CreateCommand(interp, "pwd", Jim_PwdCmd, NULL, NULL);
5032 Jim_CreateCommand(interp, "cd", Jim_CdCmd, NULL, NULL);
5033 return JIM_OK;
5034 }
5035
 
 
 
5036 #include <string.h>
5037 #include <ctype.h>
5038
5039
5040 #if (!(defined(HAVE_VFORK) || defined(HAVE_FORK)) || !defined(HAVE_WAITPID)) && !defined(__MINGW32__)
5041 static int Jim_ExecCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
5042 {
5043 Jim_Obj *cmdlineObj = Jim_NewEmptyStringObj(interp);
5044 int i, j;
5045 int rc;
@@ -4440,13 +5083,11 @@
5083 return JIM_OK;
5084 }
5085
5086 int Jim_execInit(Jim_Interp *interp)
5087 {
5088 Jim_PackageProvideCheck(interp, "exec");
 
 
5089 Jim_CreateCommand(interp, "exec", Jim_ExecCmd, NULL, NULL);
5090 return JIM_OK;
5091 }
5092 #else
5093
@@ -4459,17 +5100,17 @@
5100
5101 static char **JimOriginalEnviron(void);
5102 static char **JimSaveEnv(char **env);
5103 static void JimRestoreEnv(char **env);
5104 static int JimCreatePipeline(Jim_Interp *interp, int argc, Jim_Obj *const *argv,
5105 phandle_t **pidArrayPtr, int *inPipePtr, int *outPipePtr, int *errFilePtr);
5106 static void JimDetachPids(struct WaitInfoTable *table, int numPids, const phandle_t *pidPtr);
5107 static int JimCleanupChildren(Jim_Interp *interp, int numPids, phandle_t *pidPtr, Jim_Obj *errStrObj);
5108 static int Jim_WaitCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv);
5109
5110 #if defined(__MINGW32__)
5111 static phandle_t JimStartWinProcess(Jim_Interp *interp, char **argv, char **env, int inputId, int outputId, int errorId);
5112 #endif
5113
5114 static void Jim_RemoveTrailingNewline(Jim_Obj *objPtr)
5115 {
5116 int len;
@@ -4482,28 +5123,23 @@
5123 }
5124
5125 static int JimAppendStreamToString(Jim_Interp *interp, int fd, Jim_Obj *strObj)
5126 {
5127 char buf[256];
 
5128 int ret = 0;
5129
 
 
 
 
5130 while (1) {
5131 int retval = read(fd, buf, sizeof(buf));
5132 if (retval > 0) {
5133 ret = 1;
5134 Jim_AppendString(interp, strObj, buf, retval);
5135 }
5136 if (retval <= 0) {
5137 break;
5138 }
5139 }
5140 close(fd);
5141 return ret;
5142 }
5143
5144 static char **JimBuildEnv(Jim_Interp *interp)
5145 {
@@ -4558,22 +5194,22 @@
5194 if (env != original_environ) {
5195 Jim_Free(env);
5196 }
5197 }
5198
5199 static Jim_Obj *JimMakeErrorCode(Jim_Interp *interp, long pid, int waitStatus, Jim_Obj *errStrObj)
5200 {
5201 Jim_Obj *errorCode = Jim_NewListObj(interp, NULL, 0);
5202
5203 if (pid <= 0) {
5204 Jim_ListAppendElement(interp, errorCode, Jim_NewStringObj(interp, "NONE", -1));
5205 Jim_ListAppendElement(interp, errorCode, Jim_NewIntObj(interp, pid));
5206 Jim_ListAppendElement(interp, errorCode, Jim_NewIntObj(interp, -1));
5207 }
5208 else if (WIFEXITED(waitStatus)) {
5209 Jim_ListAppendElement(interp, errorCode, Jim_NewStringObj(interp, "CHILDSTATUS", -1));
5210 Jim_ListAppendElement(interp, errorCode, Jim_NewIntObj(interp, pid));
5211 Jim_ListAppendElement(interp, errorCode, Jim_NewIntObj(interp, WEXITSTATUS(waitStatus)));
5212 }
5213 else {
5214 const char *type;
5215 const char *action;
@@ -4594,17 +5230,17 @@
5230
5231 if (errStrObj) {
5232 Jim_AppendStrings(interp, errStrObj, "child ", action, " by signal ", Jim_SignalId(WTERMSIG(waitStatus)), "\n", NULL);
5233 }
5234
5235 Jim_ListAppendElement(interp, errorCode, Jim_NewIntObj(interp, pid));
5236 Jim_ListAppendElement(interp, errorCode, Jim_NewStringObj(interp, signame, -1));
5237 }
5238 return errorCode;
5239 }
5240
5241 static int JimCheckWaitStatus(Jim_Interp *interp, long pid, int waitStatus, Jim_Obj *errStrObj)
5242 {
5243 if (WIFEXITED(waitStatus) && WEXITSTATUS(waitStatus) == 0) {
5244 return JIM_OK;
5245 }
5246 Jim_SetGlobalVariableStr(interp, "errorCode", JimMakeErrorCode(interp, pid, waitStatus, errStrObj));
@@ -4613,11 +5249,11 @@
5249 }
5250
5251
5252 struct WaitInfo
5253 {
5254 phandle_t phandle;
5255 int status;
5256 int flags;
5257 };
5258
5259
@@ -4651,17 +5287,17 @@
5287 table->refcount = 1;
5288
5289 return table;
5290 }
5291
5292 static int JimWaitRemove(struct WaitInfoTable *table, phandle_t phandle)
5293 {
5294 int i;
5295
5296
5297 for (i = 0; i < table->used; i++) {
5298 if (phandle == table->info[i].phandle) {
5299 if (i != table->used - 1) {
5300 table->info[i] = table->info[table->used - 1];
5301 }
5302 table->used--;
5303 return 0;
@@ -4672,11 +5308,11 @@
5308
5309 static int Jim_ExecCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
5310 {
5311 int outputId;
5312 int errorId;
5313 phandle_t *pidPtr;
5314 int numPids, result;
5315 int child_siginfo = 1;
5316 Jim_Obj *childErrObj;
5317 Jim_Obj *errStrObj;
5318 struct WaitInfoTable *table = Jim_CmdPrivData(interp);
@@ -4691,11 +5327,11 @@
5327 return JIM_ERR;
5328 }
5329
5330 listObj = Jim_NewListObj(interp, NULL, 0);
5331 for (i = 0; i < numPids; i++) {
5332 Jim_ListAppendElement(interp, listObj, Jim_NewIntObj(interp, JimProcessPid(pidPtr[i])));
5333 }
5334 Jim_SetResult(interp, listObj);
5335 JimDetachPids(table, numPids, pidPtr);
5336 Jim_Free(pidPtr);
5337 return JIM_OK;
@@ -4728,11 +5364,11 @@
5364 result = JIM_ERR;
5365 }
5366
5367 if (errorId != -1) {
5368 int ret;
5369 Jim_Lseek(errorId, 0, SEEK_SET);
5370 ret = JimAppendStreamToString(interp, errorId, errStrObj);
5371 if (ret < 0) {
5372 Jim_SetResultErrno(interp, "error reading from error pipe");
5373 result = JIM_ERR;
5374 }
@@ -4755,31 +5391,30 @@
5391 Jim_SetResult(interp, errStrObj);
5392
5393 return result;
5394 }
5395
5396 static long JimWaitForProcess(struct WaitInfoTable *table, phandle_t phandle, int *statusPtr)
5397 {
5398 if (JimWaitRemove(table, phandle) == 0) {
5399
5400 return waitpid(phandle, statusPtr, 0);
 
5401 }
5402
5403
5404 return -1;
5405 }
5406
5407 static void JimDetachPids(struct WaitInfoTable *table, int numPids, const phandle_t *pidPtr)
5408 {
5409 int j;
5410
5411 for (j = 0; j < numPids; j++) {
5412
5413 int i;
5414 for (i = 0; i < table->used; i++) {
5415 if (pidPtr[j] == table->info[i].phandle) {
5416 table->info[i].flags |= WI_DETACHED;
5417 break;
5418 }
5419 }
5420 }
@@ -4814,12 +5449,12 @@
5449 waitPtr = table->info;
5450 dest = 0;
5451 for (count = table->used; count > 0; waitPtr++, count--) {
5452 if (waitPtr->flags & WI_DETACHED) {
5453 int status;
5454 long pid = waitpid(waitPtr->phandle, &status, WNOHANG);
5455 if (pid > 0) {
5456
5457 table->used--;
5458 continue;
5459 }
5460 }
@@ -4832,12 +5467,12 @@
5467
5468 static int Jim_WaitCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
5469 {
5470 struct WaitInfoTable *table = Jim_CmdPrivData(interp);
5471 int nohang = 0;
5472 long pid;
5473 phandle_t phandle;
5474 int status;
5475 Jim_Obj *errCodeObj;
5476
5477
5478 if (argc == 1) {
@@ -4850,21 +5485,30 @@
5485 }
5486 if (argc != nohang + 2) {
5487 Jim_WrongNumArgs(interp, 1, argv, "?-nohang? ?pid?");
5488 return JIM_ERR;
5489 }
5490 if (Jim_GetLong(interp, argv[nohang + 1], &pid) != JIM_OK) {
5491 return JIM_ERR;
5492 }
5493
5494
5495 phandle = JimWaitPid(pid, &status, nohang ? WNOHANG : 0);
5496 if (phandle == JIM_BAD_PHANDLE) {
5497 pid = -1;
5498 }
5499 #ifndef __MINGW32__
5500 else if (pid < 0) {
5501 pid = phandle;
5502 }
5503 #endif
5504
5505 errCodeObj = JimMakeErrorCode(interp, pid, status, NULL);
5506
5507 if (phandle != JIM_BAD_PHANDLE && (WIFEXITED(status) || WIFSIGNALED(status))) {
5508
5509 JimWaitRemove(table, phandle);
5510 }
5511 Jim_SetResult(interp, errCodeObj);
5512 return JIM_OK;
5513 }
5514
@@ -4878,14 +5522,14 @@
5522 Jim_SetResultInt(interp, (jim_wide)getpid());
5523 return JIM_OK;
5524 }
5525
5526 static int
5527 JimCreatePipeline(Jim_Interp *interp, int argc, Jim_Obj *const *argv, phandle_t **pidArrayPtr,
5528 int *inPipePtr, int *outPipePtr, int *errFilePtr)
5529 {
5530 phandle_t *pidPtr = NULL; /* Points to alloc-ed array holding all
5531 * the pids of child processes. */
5532 int numPids = 0; /* Actual number of processes that exist
5533 * at *pidPtr right now. */
5534 int cmdCount; /* Count of number of distinct commands
5535 * found in argc/argv. */
@@ -4925,13 +5569,13 @@
5569 int pipeIds[2];
5570 int firstArg, lastArg; /* Indexes of first and last arguments in
5571 * current command. */
5572 int lastBar;
5573 int i;
5574 phandle_t phandle;
5575 char **save_environ;
5576 #if defined(HAVE_EXECVPE) && !defined(__MINGW32__)
5577 char **child_environ;
5578 #endif
5579 struct WaitInfoTable *table = Jim_CmdPrivData(interp);
5580
5581
@@ -5053,11 +5697,11 @@
5697 if (write(inputId, input, input_len) != input_len) {
5698 Jim_SetResultErrno(interp, "couldn't write temp file");
5699 close(inputId);
5700 goto error;
5701 }
5702 Jim_Lseek(inputId, 0L, SEEK_SET);
5703 }
5704 else if (inputFile == FILE_HANDLE) {
5705 int fd = JimGetChannelFd(interp, input);
5706
5707 if (fd < 0) {
@@ -5145,13 +5789,10 @@
5789 *errFilePtr = dup(errorId);
5790 }
5791
5792
5793 pidPtr = Jim_Alloc(cmdCount * sizeof(*pidPtr));
 
 
 
5794 for (firstArg = 0; firstArg < arg_count; numPids++, firstArg = lastArg + 1) {
5795 int pipe_dup_err = 0;
5796 int origErrorId = errorId;
5797
5798 for (lastArg = firstArg; lastArg < arg_count; lastArg++) {
@@ -5189,58 +5830,61 @@
5830 }
5831
5832
5833
5834 #ifdef __MINGW32__
5835 phandle = JimStartWinProcess(interp, &arg_array[firstArg], save_environ, inputId, outputId, errorId);
5836 if (phandle == JIM_BAD_PHANDLE) {
5837 Jim_SetResultFormatted(interp, "couldn't exec \"%s\"", arg_array[firstArg]);
5838 goto error;
5839 }
5840 #else
5841 i = strlen(arg_array[firstArg]);
5842
5843 #ifdef HAVE_EXECVPE
5844 child_environ = Jim_GetEnviron();
5845 #endif
5846 #ifdef HAVE_VFORK
5847 phandle = vfork();
5848 #else
5849 phandle = fork();
5850 #endif
5851 if (phandle < 0) {
5852 Jim_SetResultErrno(interp, "couldn't fork child process");
5853 goto error;
5854 }
5855 if (phandle == 0) {
5856
5857
5858 if (inputId != -1 && inputId != fileno(stdin)) {
5859 dup2(inputId, fileno(stdin));
5860 close(inputId);
5861 }
5862 if (outputId != -1 && outputId != fileno(stdout)) {
5863 dup2(outputId, fileno(stdout));
5864 if (outputId != errorId) {
5865 close(outputId);
5866 }
5867 }
5868 if (errorId != -1 && errorId != fileno(stderr)) {
5869 dup2(errorId, fileno(stderr));
5870 close(errorId);
5871 }
5872
5873 if (outPipePtr && *outPipePtr != -1) {
5874 close(*outPipePtr);
5875 }
5876 if (errFilePtr && *errFilePtr != -1) {
5877 close(*errFilePtr);
5878 }
5879 if (pipeIds[0] != -1) {
5880 close(pipeIds[0]);
5881 }
5882 if (lastOutputId != -1) {
5883 close(lastOutputId);
5884 }
5885
 
 
 
5886 execvpe(arg_array[firstArg], &arg_array[firstArg], child_environ);
5887
5888 if (write(fileno(stderr), "couldn't exec \"", 15) &&
5889 write(fileno(stderr), arg_array[firstArg], i) &&
5890 write(fileno(stderr), "\"\n", 2)) {
@@ -5262,15 +5906,15 @@
5906 if (table->used == table->size) {
5907 table->size += WAIT_TABLE_GROW_BY;
5908 table->info = Jim_Realloc(table->info, table->size * sizeof(*table->info));
5909 }
5910
5911 table->info[table->used].phandle = phandle;
5912 table->info[table->used].flags = 0;
5913 table->used++;
5914
5915 pidPtr[numPids] = phandle;
5916
5917
5918 errorId = origErrorId;
5919
5920
@@ -5322,11 +5966,11 @@
5966 if (pipeIds[1] != -1) {
5967 close(pipeIds[1]);
5968 }
5969 if (pidPtr != NULL) {
5970 for (i = 0; i < numPids; i++) {
5971 if (pidPtr[i] != JIM_BAD_PHANDLE) {
5972 JimDetachPids(table, 1, &pidPtr[i]);
5973 }
5974 }
5975 Jim_Free(pidPtr);
5976 }
@@ -5333,21 +5977,22 @@
5977 numPids = -1;
5978 goto cleanup;
5979 }
5980
5981
5982 static int JimCleanupChildren(Jim_Interp *interp, int numPids, phandle_t *pidPtr, Jim_Obj *errStrObj)
5983 {
5984 struct WaitInfoTable *table = Jim_CmdPrivData(interp);
5985 int result = JIM_OK;
5986 int i;
5987
5988
5989 for (i = 0; i < numPids; i++) {
5990 int waitStatus = 0;
5991 long pid = JimWaitForProcess(table, pidPtr[i], &waitStatus);
5992 if (pid > 0) {
5993 if (JimCheckWaitStatus(interp, pid, waitStatus, errStrObj) != JIM_OK) {
5994 result = JIM_ERR;
5995 }
5996 }
5997 }
5998 Jim_Free(pidPtr);
@@ -5356,16 +6001,12 @@
6001 }
6002
6003 int Jim_execInit(Jim_Interp *interp)
6004 {
6005 struct WaitInfoTable *waitinfo;
 
 
6006
6007 Jim_PackageProvideCheck(interp, "exec");
 
 
6008
6009 waitinfo = JimAllocWaitInfoTable();
6010 Jim_CreateCommand(interp, "exec", Jim_ExecCmd, waitinfo, JimFreeWaitInfoTable);
6011 waitinfo->refcount++;
6012 Jim_CreateCommand(interp, "wait", Jim_WaitCommand, waitinfo, JimFreeWaitInfoTable);
@@ -5483,23 +6124,23 @@
6124 }
6125 }
6126 return strObj;
6127 }
6128
6129 static phandle_t
6130 JimStartWinProcess(Jim_Interp *interp, char **argv, char **env, int inputId, int outputId, int errorId)
6131 {
6132 STARTUPINFO startInfo;
6133 PROCESS_INFORMATION procInfo;
6134 HANDLE hProcess;
6135 char execPath[MAX_PATH];
6136 phandle_t phandle = INVALID_HANDLE_VALUE;
6137 Jim_Obj *cmdLineObj;
6138 char *winenv;
6139
6140 if (JimWinFindExecutable(argv[0], execPath) < 0) {
6141 return phandle;
6142 }
6143 argv[0] = execPath;
6144
6145 hProcess = GetCurrentProcess();
6146 cmdLineObj = JimWinBuildCommandLine(interp, argv);
@@ -5558,11 +6199,11 @@
6199
6200
6201 WaitForInputIdle(procInfo.hProcess, 5000);
6202 CloseHandle(procInfo.hThread);
6203
6204 phandle = procInfo.hProcess;
6205
6206 end:
6207 Jim_FreeNewObj(interp, cmdLineObj);
6208 if (startInfo.hStdInput != INVALID_HANDLE_VALUE) {
6209 CloseHandle(startInfo.hStdInput);
@@ -5571,11 +6212,11 @@
6212 CloseHandle(startInfo.hStdOutput);
6213 }
6214 if (startInfo.hStdError != INVALID_HANDLE_VALUE) {
6215 CloseHandle(startInfo.hStdError);
6216 }
6217 return phandle;
6218 }
6219
6220 #else
6221
6222 static char **JimOriginalEnviron(void)
@@ -5597,22 +6238,10 @@
6238 }
6239 #endif
6240 #endif
6241
6242
 
 
 
 
 
 
 
 
 
 
 
 
6243 #include <stdlib.h>
6244 #include <string.h>
6245 #include <stdio.h>
6246 #include <time.h>
6247
@@ -5732,41 +6361,36 @@
6361 }
6362 #endif
6363
6364 static int clock_cmd_seconds(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
6365 {
6366 Jim_SetResultInt(interp, Jim_GetTimeUsec(CLOCK_REALTIME) / 1000000);
6367 return JIM_OK;
6368 }
6369
6370 static int clock_cmd_clicks(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
6371 {
6372 Jim_SetResultInt(interp, Jim_GetTimeUsec(CLOCK_MONOTONIC_RAW));
6373 return JIM_OK;
6374 }
6375
6376 static int clock_cmd_micros(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
6377 {
6378 Jim_SetResultInt(interp, Jim_GetTimeUsec(CLOCK_REALTIME));
 
 
 
 
 
6379 return JIM_OK;
6380 }
6381
6382 static int clock_cmd_millis(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
6383 {
6384 Jim_SetResultInt(interp, Jim_GetTimeUsec(CLOCK_REALTIME) / 1000);
 
 
 
 
 
6385 return JIM_OK;
6386 }
6387
6388 static const jim_subcmd_type clock_command_table[] = {
6389 { "clicks",
6390 NULL,
6391 clock_cmd_clicks,
6392 0,
6393 0,
6394
6395 },
6396 { "format",
@@ -5809,13 +6433,11 @@
6433 { NULL }
6434 };
6435
6436 int Jim_clockInit(Jim_Interp *interp)
6437 {
6438 Jim_PackageProvideCheck(interp, "clock");
 
 
6439 Jim_CreateCommand(interp, "clock", Jim_SubCmdProc, (void *)clock_command_table, NULL);
6440 return JIM_OK;
6441 }
6442
6443 #include <limits.h>
@@ -5886,11 +6508,12 @@
6508 if (objPtr == NULL) {
6509
6510 return JIM_OK;
6511 }
6512
6513 dictValuesObj = Jim_DictPairs(interp, objPtr, &len);
6514 if (dictValuesObj == NULL) {
6515
6516 Jim_SetResultString(interp, "", -1);
6517 return JIM_OK;
6518 }
6519
@@ -5900,11 +6523,10 @@
6523 for (i = 0; i < len; i += 2) {
6524 if (!Jim_StringMatchObj(interp, argv[1], dictValuesObj[i], 0)) {
6525 Jim_DictAddElement(interp, resultObj, dictValuesObj[i], dictValuesObj[i + 1]);
6526 }
6527 }
 
6528
6529 Jim_SetVariable(interp, argv[0], resultObj);
6530 return JIM_OK;
6531 }
6532
@@ -6031,25 +6653,71 @@
6653 }
6654 };
6655
6656 int Jim_arrayInit(Jim_Interp *interp)
6657 {
6658 Jim_PackageProvideCheck(interp, "array");
 
 
6659 Jim_CreateCommand(interp, "array", Jim_SubCmdProc, (void *)array_command_table, NULL);
6660 return JIM_OK;
6661 }
6662
6663 #include <sys/types.h>
6664 #include <sys/time.h>
6665 #include <sys/wait.h>
6666 #include <unistd.h>
6667 #include <string.h>
6668 #include <errno.h>
6669
6670
6671 #ifdef HAVE_SYS_SYSINFO_H
6672 #include <sys/sysinfo.h>
6673 #endif
6674
6675 static void Jim_PosixSetError(Jim_Interp *interp)
6676 {
6677 Jim_SetResultString(interp, strerror(errno), -1);
6678 }
6679
6680 #if defined(HAVE_FORK)
6681 static int Jim_PosixForkCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
6682 {
6683 pid_t pid;
6684
6685 JIM_NOTUSED(argv);
6686
6687 if (argc != 1) {
6688 Jim_WrongNumArgs(interp, 1, argv, "");
6689 return JIM_ERR;
6690 }
6691 if ((pid = fork()) == -1) {
6692 Jim_PosixSetError(interp);
6693 return JIM_ERR;
6694 }
6695 Jim_SetResultInt(interp, (jim_wide) pid);
6696 return JIM_OK;
6697 }
6698 #endif
6699
6700
6701 int Jim_posixInit(Jim_Interp *interp)
6702 {
6703 Jim_PackageProvideCheck(interp, "posix");
6704 #ifdef HAVE_FORK
6705 Jim_CreateCommand(interp, "os.fork", Jim_PosixForkCommand, NULL, NULL);
6706 #endif
6707 return JIM_OK;
6708 }
6709 int Jim_InitStaticExtensions(Jim_Interp *interp)
6710 {
6711 extern int Jim_bootstrapInit(Jim_Interp *);
6712 extern int Jim_aioInit(Jim_Interp *);
6713 extern int Jim_readdirInit(Jim_Interp *);
6714 extern int Jim_regexpInit(Jim_Interp *);
6715 extern int Jim_fileInit(Jim_Interp *);
6716 extern int Jim_globInit(Jim_Interp *);
6717 extern int Jim_execInit(Jim_Interp *);
6718 extern int Jim_posixInit(Jim_Interp *);
6719 extern int Jim_clockInit(Jim_Interp *);
6720 extern int Jim_arrayInit(Jim_Interp *);
6721 extern int Jim_stdlibInit(Jim_Interp *);
6722 extern int Jim_tclcompatInit(Jim_Interp *);
6723 Jim_bootstrapInit(interp);
@@ -6057,20 +6725,18 @@
6725 Jim_readdirInit(interp);
6726 Jim_regexpInit(interp);
6727 Jim_fileInit(interp);
6728 Jim_globInit(interp);
6729 Jim_execInit(interp);
6730 Jim_posixInit(interp);
6731 Jim_clockInit(interp);
6732 Jim_arrayInit(interp);
6733 Jim_stdlibInit(interp);
6734 Jim_tclcompatInit(interp);
6735 return JIM_OK;
6736 }
6737 #define JIM_OPTIMIZATION
 
 
 
6738
6739 #include <stdio.h>
6740 #include <stdlib.h>
6741
6742 #include <string.h>
@@ -6084,11 +6750,11 @@
6750
6751
6752 #ifdef HAVE_SYS_TIME_H
6753 #include <sys/time.h>
6754 #endif
6755 #ifdef HAVE_EXECINFO_H
6756 #include <execinfo.h>
6757 #endif
6758 #ifdef HAVE_CRT_EXTERNS_H
6759 #include <crt_externs.h>
6760 #endif
@@ -6136,10 +6802,11 @@
6802 #else
6803 #define JimPanic(X)
6804 #endif
6805
6806 #ifdef JIM_OPTIMIZATION
6807 static int JimIsWide(Jim_Obj *objPtr);
6808 #define JIM_IF_OPTIM(X) X
6809 #else
6810 #define JIM_IF_OPTIM(X)
6811 #endif
6812
@@ -6147,22 +6814,29 @@
6814 static char JimEmptyStringRep[] = "";
6815
6816 static void JimFreeCallFrame(Jim_Interp *interp, Jim_CallFrame *cf, int action);
6817 static int ListSetIndex(Jim_Interp *interp, Jim_Obj *listPtr, int listindex, Jim_Obj *newObjPtr,
6818 int flags);
6819 static int Jim_ListIndices(Jim_Interp *interp, Jim_Obj *listPtr, Jim_Obj *const *indexv, int indexc,
6820 Jim_Obj **resultObj, int flags);
6821 static int JimDeleteLocalProcs(Jim_Interp *interp, Jim_Stack *localCommands);
6822 static Jim_Obj *JimExpandDictSugar(Jim_Interp *interp, Jim_Obj *objPtr);
6823 static void SetDictSubstFromAny(Jim_Interp *interp, Jim_Obj *objPtr);
 
6824 static void JimSetFailedEnumResult(Jim_Interp *interp, const char *arg, const char *badtype,
6825 const char *prefix, const char *const *tablePtr, const char *name);
6826 static int JimCallProcedure(Jim_Interp *interp, Jim_Cmd *cmd, int argc, Jim_Obj *const *argv);
6827 static int JimGetWideNoErr(Jim_Interp *interp, Jim_Obj *objPtr, jim_wide * widePtr);
6828 static int JimSign(jim_wide w);
 
6829 static void JimPrngSeed(Jim_Interp *interp, unsigned char *seed, int seedLen);
6830 static void JimRandomBytes(Jim_Interp *interp, void *dest, unsigned int len);
6831 static int JimSetNewVariable(Jim_HashTable *ht, Jim_Obj *nameObjPtr, Jim_VarVal *vv);
6832 static Jim_VarVal *JimFindVariable(Jim_HashTable *ht, Jim_Obj *nameObjPtr);
6833 static void JimSetErrorStack(Jim_Interp *interp);
6834 static int SetVariableFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr);
6835
6836 #define JIM_DICT_SUGAR 100
6837
6838
6839
6840
6841 #define JimWideValue(objPtr) (objPtr)->internalRep.wideValue
6842
@@ -6175,20 +6849,32 @@
6849 *uc = utf8_upper(*uc);
6850 }
6851 return l;
6852 }
6853
6854 static Jim_Obj *JimPushInterpObjImpl(Jim_Obj **iop, Jim_Obj *no)
6855 {
6856 Jim_Obj *io = *iop;
6857 Jim_IncrRefCount(no);
6858 *iop = no;
6859 return io;
6860 }
6861
6862 #define JimPushInterpObj(IO, NO) JimPushInterpObjImpl(&(IO), NO)
6863 #define JimPopInterpObj(I, IO, SO) do { Jim_DecrRefCount(I, IO); IO = SO; } while (0)
6864
6865
6866 #define JIM_CHARSET_SCAN 2
6867 #define JIM_CHARSET_GLOB 0
6868
6869 static const char *JimCharsetMatch(const char *pattern, int plen, int c, int flags)
6870 {
6871 int not = 0;
6872 int pchar;
6873 int match = 0;
6874 int nocase = 0;
6875 int n;
6876
6877 if (flags & JIM_NOCASE) {
6878 nocase++;
6879 c = utf8_upper(c);
6880 }
@@ -6195,34 +6881,40 @@
6881
6882 if (flags & JIM_CHARSET_SCAN) {
6883 if (*pattern == '^') {
6884 not++;
6885 pattern++;
6886 plen--;
6887 }
6888
6889
6890 if (*pattern == ']') {
6891 goto first;
6892 }
6893 }
6894
6895 while (plen && *pattern != ']') {
6896
6897 if (pattern[0] == '\\') {
6898 first:
6899 n = utf8_tounicode_case(pattern, &pchar, nocase);
6900 pattern += n;
6901 plen -= n;
6902 }
6903 else {
6904
6905 int start;
6906 int end;
6907
6908 n = utf8_tounicode_case(pattern, &start, nocase);
6909 pattern += n;
6910 plen -= n;
6911 if (pattern[0] == '-' && plen > 1) {
6912
6913 n = 1 + utf8_tounicode_case(pattern + 1, &end, nocase);
6914 pattern += n;
6915 plen -= n;
6916
6917
6918 if ((c >= start && c <= end) || (c >= end && c <= start)) {
6919 match = 1;
6920 }
@@ -6242,108 +6934,115 @@
6934 return match ? pattern : NULL;
6935 }
6936
6937
6938
6939 static int JimGlobMatch(const char *pattern, int plen, const char *string, int slen, int nocase)
6940 {
6941 int c;
6942 int pchar;
6943 int n;
6944 const char *p;
6945 while (plen) {
6946 switch (pattern[0]) {
6947 case '*':
6948 while (pattern[1] == '*' && plen) {
6949 pattern++;
6950 plen--;
6951 }
6952 pattern++;
6953 plen--;
6954 if (!plen) {
6955 return 1;
6956 }
6957 while (slen) {
6958
6959 if (JimGlobMatch(pattern, plen, string, slen, nocase))
6960 return 1;
6961 n = utf8_tounicode(string, &c);
6962 string += n;
6963 slen -= n;
6964 }
6965 return 0;
6966
6967 case '?':
6968 n = utf8_tounicode(string, &c);
6969 string += n;
6970 slen -= n;
6971 break;
6972
6973 case '[': {
6974 n = utf8_tounicode(string, &c);
6975 string += n;
6976 slen -= n;
6977 p = JimCharsetMatch(pattern + 1, plen - 1, c, nocase ? JIM_NOCASE : 0);
6978 if (!p) {
6979 return 0;
6980 }
6981 plen -= p - pattern;
6982 pattern = p;
6983
6984 if (!plen) {
6985
6986 continue;
6987 }
6988 break;
6989 }
6990 case '\\':
6991 if (pattern[1]) {
6992 pattern++;
6993 plen--;
6994 }
6995
6996 default:
6997 n = utf8_tounicode_case(string, &c, nocase);
6998 string += n;
6999 slen -= n;
7000 utf8_tounicode_case(pattern, &pchar, nocase);
7001 if (pchar != c) {
7002 return 0;
7003 }
7004 break;
7005 }
7006 n = utf8_tounicode_case(pattern, &pchar, nocase);
7007 pattern += n;
7008 plen -= n;
7009 if (!slen) {
7010 while (*pattern == '*' && plen) {
7011 pattern++;
7012 plen--;
7013 }
7014 break;
7015 }
7016 }
7017 if (!plen && !slen) {
7018 return 1;
7019 }
7020 return 0;
7021 }
7022
7023 static int JimStringCompareUtf8(const char *s1, int l1, const char *s2, int l2, int nocase)
7024 {
7025 int minlen = l1;
7026 if (l2 < l1) {
7027 minlen = l2;
7028 }
7029 while (minlen) {
 
 
 
 
 
 
 
 
 
7030 int c1, c2;
7031 s1 += utf8_tounicode_case(s1, &c1, nocase);
7032 s2 += utf8_tounicode_case(s2, &c2, nocase);
7033 if (c1 != c2) {
7034 return JimSign(c1 - c2);
7035 }
7036 minlen--;
 
 
 
7037 }
7038
7039 if (l1 < l2) {
 
 
 
7040 return -1;
7041 }
7042 if (l1 > l2) {
7043 return 1;
7044 }
7045 return 0;
7046 }
7047
7048 static int JimStringFirst(const char *s1, int l1, const char *s2, int l2, int idx)
@@ -6416,11 +7115,11 @@
7115
7116 static int JimNumberBase(const char *str, int *base, int *sign)
7117 {
7118 int i = 0;
7119
7120 *base = 0;
7121
7122 while (isspace(UCHAR(str[i]))) {
7123 i++;
7124 }
7125
@@ -6443,30 +7142,31 @@
7142
7143 switch (str[i + 1]) {
7144 case 'x': case 'X': *base = 16; break;
7145 case 'o': case 'O': *base = 8; break;
7146 case 'b': case 'B': *base = 2; break;
7147 case 'd': case 'D': *base = 10; break;
7148 default: return 0;
7149 }
7150 i += 2;
7151
7152 if (str[i] != '-' && str[i] != '+' && !isspace(UCHAR(str[i]))) {
7153
7154 return i;
7155 }
7156
7157 *base = 0;
7158 return 0;
7159 }
7160
7161 static long jim_strtol(const char *str, char **endptr)
7162 {
7163 int sign;
7164 int base;
7165 int i = JimNumberBase(str, &base, &sign);
7166
7167 if (base != 0) {
7168 long value = strtol(str + i, endptr, base);
7169 if (endptr == NULL || *endptr != str + i) {
7170 return value * sign;
7171 }
7172 }
@@ -6481,11 +7181,11 @@
7181 #ifdef HAVE_LONG_LONG
7182 int sign;
7183 int base;
7184 int i = JimNumberBase(str, &base, &sign);
7185
7186 if (base != 0) {
7187 jim_wide value = strtoull(str + i, endptr, base);
7188 if (endptr == NULL || *endptr != str + i) {
7189 return value * sign;
7190 }
7191 }
@@ -6563,11 +7263,11 @@
7263 fprintf(stderr, "\nJIM INTERPRETER PANIC: ");
7264 vfprintf(stderr, fmt, ap);
7265 fprintf(stderr, "\n\n");
7266 va_end(ap);
7267
7268 #if defined(HAVE_BACKTRACE)
7269 {
7270 void *array[40];
7271 int size, i;
7272 char **strings;
7273
@@ -6583,48 +7283,64 @@
7283 exit(1);
7284 }
7285 #endif
7286
7287
7288 void *JimDefaultAllocator(void *ptr, size_t size)
7289 {
7290 if (size == 0) {
7291 free(ptr);
7292 return NULL;
7293 }
7294 else if (ptr) {
7295 return realloc(ptr, size);
7296 }
7297 else {
7298 return malloc(size);
7299 }
7300 }
7301
7302 void *(*Jim_Allocator)(void *ptr, size_t size) = JimDefaultAllocator;
 
 
 
 
 
 
 
 
7303
7304 char *Jim_StrDup(const char *s)
7305 {
7306 return Jim_StrDupLen(s, strlen(s));
7307 }
7308
7309 char *Jim_StrDupLen(const char *s, int l)
7310 {
7311 char *copy = Jim_Alloc(l + 1);
7312
7313 memcpy(copy, s, l);
7314 copy[l] = 0;
7315 return copy;
7316 }
7317
7318
7319 jim_wide Jim_GetTimeUsec(unsigned type)
 
7320 {
7321 long long now;
7322 struct timeval tv;
7323
7324 #if defined(HAVE_CLOCK_GETTIME)
7325 struct timespec ts;
7326
7327 if (clock_gettime(type, &ts) == 0) {
7328 now = ts.tv_sec * 1000000LL + ts.tv_nsec / 1000;
7329 }
7330 else
7331 #endif
7332 {
7333 gettimeofday(&tv, NULL);
7334
7335 now = tv.tv_sec * 1000000LL + tv.tv_usec;
7336 }
7337
7338 return now;
7339 }
7340
7341
7342
7343
7344
7345 static void JimExpandHashTableIfNeeded(Jim_HashTable *ht);
7346 static unsigned int JimHashTableNextPower(unsigned int size);
@@ -6642,19 +7358,20 @@
7358 key += ~(key << 11);
7359 key ^= (key >> 16);
7360 return key;
7361 }
7362
7363
7364 unsigned int Jim_GenHashFunction(const unsigned char *string, int length)
7365 {
7366 unsigned result = 0;
7367 string += length;
7368 while (length--) {
7369 result += (result << 3) + (unsigned char)(*--string);
7370 }
7371 return result;
7372 }
7373
7374
7375
7376 static void JimResetHashTable(Jim_HashTable *ht)
7377 {
@@ -6685,19 +7402,10 @@
7402 ht->type = type;
7403 ht->privdata = privDataPtr;
7404 return JIM_OK;
7405 }
7406
 
 
 
 
 
 
 
 
 
7407
7408 void Jim_ExpandHashTable(Jim_HashTable *ht, unsigned int size)
7409 {
7410 Jim_HashTable n;
7411 unsigned int realsize = JimHashTableNextPower(size), i;
@@ -6742,16 +7450,13 @@
7450
7451
7452 *ht = n;
7453 }
7454
 
7455 int Jim_AddHashEntry(Jim_HashTable *ht, const void *key, void *val)
7456 {
7457 Jim_HashEntry *entry = JimInsertHashEntry(ht, key, 0);;
 
 
7458 if (entry == NULL)
7459 return JIM_ERR;
7460
7461
7462 Jim_SetHashKey(ht, entry, key);
@@ -6786,61 +7491,62 @@
7491 }
7492
7493 return existed;
7494 }
7495
 
7496 int Jim_DeleteHashEntry(Jim_HashTable *ht, const void *key)
7497 {
7498 if (ht->used) {
7499 unsigned int h = Jim_HashKey(ht, key) & ht->sizemask;
7500 Jim_HashEntry *prevHe = NULL;
7501 Jim_HashEntry *he = ht->table[h];
7502
7503 while (he) {
7504 if (Jim_CompareHashKeys(ht, key, he->key)) {
7505
7506 if (prevHe)
7507 prevHe->next = he->next;
7508 else
7509 ht->table[h] = he->next;
7510 ht->used--;
7511 Jim_FreeEntryKey(ht, he);
7512 Jim_FreeEntryVal(ht, he);
7513 Jim_Free(he);
7514 return JIM_OK;
7515 }
7516 prevHe = he;
7517 he = he->next;
7518 }
7519 }
7520
7521 return JIM_ERR;
7522 }
7523
7524 void Jim_ClearHashTable(Jim_HashTable *ht)
 
 
 
7525 {
7526 unsigned int i;
7527
7528
7529 for (i = 0; ht->used > 0; i++) {
7530 Jim_HashEntry *he, *nextHe;
7531
7532 he = ht->table[i];
 
7533 while (he) {
7534 nextHe = he->next;
7535 Jim_FreeEntryKey(ht, he);
7536 Jim_FreeEntryVal(ht, he);
7537 Jim_Free(he);
7538 ht->used--;
7539 he = nextHe;
7540 }
7541 ht->table[i] = NULL;
7542 }
7543 }
7544
7545 int Jim_FreeHashTable(Jim_HashTable *ht)
7546 {
7547 Jim_ClearHashTable(ht);
7548
7549 Jim_Free(ht->table);
7550
7551 JimResetHashTable(ht);
7552 return JIM_OK;
@@ -7140,10 +7846,13 @@
7846 if (!pc->len) {
7847 pc->tstart = pc->p;
7848 pc->tend = pc->p - 1;
7849 pc->tline = pc->linenr;
7850 pc->tt = JIM_TT_EOL;
7851 if (pc->inquote) {
7852 pc->missing.ch = '"';
7853 }
7854 pc->eof = 1;
7855 return JIM_OK;
7856 }
7857 switch (*(pc->p)) {
7858 case '\\':
@@ -7354,10 +8063,13 @@
8063 break;
8064
8065 case '"':
8066 if (startofword) {
8067 JimParseSubQuote(pc);
8068 if (pc->missing.ch == '"') {
8069 return;
8070 }
8071 continue;
8072 }
8073 break;
8074
8075 case '{':
@@ -8305,37 +9017,28 @@
9017 }
9018 }
9019
9020 int Jim_StringMatchObj(Jim_Interp *interp, Jim_Obj *patternObjPtr, Jim_Obj *objPtr, int nocase)
9021 {
9022 int plen, slen;
9023 const char *pattern = Jim_GetString(patternObjPtr, &plen);
9024 const char *string = Jim_GetString(objPtr, &slen);
9025 return JimGlobMatch(pattern, plen, string, slen, nocase);
9026 }
9027
9028 int Jim_StringCompareObj(Jim_Interp *interp, Jim_Obj *firstObjPtr, Jim_Obj *secondObjPtr, int nocase)
9029 {
 
 
 
 
 
 
 
 
 
 
 
 
 
9030 const char *s1 = Jim_String(firstObjPtr);
9031 int l1 = Jim_Utf8Length(interp, firstObjPtr);
9032 const char *s2 = Jim_String(secondObjPtr);
9033 int l2 = Jim_Utf8Length(interp, secondObjPtr);
9034 return JimStringCompareUtf8(s1, l1, s2, l2, nocase);
9035 }
9036
9037 static int JimRelToAbsIndex(int len, int idx)
9038 {
9039 if (idx < 0 && idx > -INT_MAX)
9040 return len + idx;
9041 return idx;
9042 }
9043
9044 static void JimRelToAbsRange(int len, int *firstPtr, int *lastPtr, int *rangeLenPtr)
@@ -8849,11 +9552,11 @@
9552 static const Jim_ObjType scriptObjType = {
9553 "script",
9554 FreeScriptInternalRep,
9555 DupScriptInternalRep,
9556 NULL,
9557 JIM_TYPE_NONE,
9558 };
9559
9560 typedef struct ScriptToken
9561 {
9562 Jim_Obj *objPtr;
@@ -9223,12 +9926,10 @@
9926 Jim_FreeIntRep(interp, objPtr);
9927 Jim_SetIntRepPtr(objPtr, script);
9928 objPtr->typePtr = &scriptObjType;
9929 }
9930
 
 
9931 static ScriptObj *JimGetScript(Jim_Interp *interp, Jim_Obj *objPtr)
9932 {
9933 if (objPtr == interp->emptyObj) {
9934
9935 objPtr = interp->nullScriptObj;
@@ -9239,19 +9940,22 @@
9940 }
9941
9942 return (ScriptObj *)Jim_GetIntRepPtr(objPtr);
9943 }
9944
9945 void Jim_InterpIncrProcEpoch(Jim_Interp *interp)
9946 {
9947 interp->procEpoch++;
9948
9949
9950 while (interp->oldCmdCache) {
9951 Jim_Cmd *next = interp->oldCmdCache->prevCmd;
9952 Jim_Free(interp->oldCmdCache);
9953 interp->oldCmdCache = next;
9954 }
9955 interp->oldCmdCacheSize = 0;
9956 }
9957
9958 static void JimIncrCmdRefCount(Jim_Cmd *cmdPtr)
9959 {
9960 cmdPtr->inUse++;
9961 }
@@ -9276,65 +9980,156 @@
9980 }
9981 if (cmdPtr->prevCmd) {
9982
9983 JimDecrCmdRefCount(interp, cmdPtr->prevCmd);
9984 }
9985
9986 cmdPtr->prevCmd = interp->oldCmdCache;
9987 interp->oldCmdCache = cmdPtr;
9988 if (!interp->quitting && ++interp->oldCmdCacheSize >= 1000) {
9989 Jim_InterpIncrProcEpoch(interp);
9990 }
9991 }
9992 }
9993
9994 static void JimIncrVarRef(Jim_VarVal *vv)
9995 {
9996 vv->refCount++;
9997 }
9998
9999 static void JimDecrVarRef(Jim_Interp *interp, Jim_VarVal *vv)
10000 {
10001 assert(vv->refCount > 0);
10002 if (--vv->refCount == 0) {
10003 if (vv->objPtr) {
10004 Jim_DecrRefCount(interp, vv->objPtr);
10005 }
10006 Jim_Free(vv);
10007 }
10008 }
10009
10010 static void JimVariablesHTValDestructor(void *interp, void *val)
10011 {
10012 JimDecrVarRef(interp, val);
10013 }
10014
10015 static unsigned int JimObjectHTHashFunction(const void *key)
10016 {
10017 Jim_Obj *keyObj = (Jim_Obj *)key;
10018 int length;
10019 const char *string;
10020
10021 #ifdef JIM_OPTIMIZATION
10022 if (JimIsWide(keyObj) && keyObj->bytes == NULL) {
10023
10024 jim_wide objValue = JimWideValue(keyObj);
10025 if (objValue > INT_MIN && objValue < INT_MAX) {
10026 unsigned result = 0;
10027 unsigned value = (unsigned)objValue;
10028
10029 if (objValue < 0) {
10030 value = (unsigned)-objValue;
10031 }
10032
10033
10034 do {
10035 result += (result << 3) + (value % 10 + '0');
10036 value /= 10;
10037 } while (value);
10038
10039 if (objValue < 0) {
10040 result += (result << 3) + '-';
10041 }
10042 return result;
10043 }
10044 }
10045 #endif
10046 string = Jim_GetString(keyObj, &length);
10047 return Jim_GenHashFunction((const unsigned char *)string, length);
10048 }
10049
10050 static int JimObjectHTKeyCompare(void *privdata, const void *key1, const void *key2)
10051 {
10052 return Jim_StringEqObj((Jim_Obj *)key1, (Jim_Obj *)key2);
10053 }
10054
10055 static void *JimObjectHTKeyValDup(void *privdata, const void *val)
10056 {
10057 Jim_IncrRefCount((Jim_Obj *)val);
10058 return (void *)val;
10059 }
10060
10061 static void JimObjectHTKeyValDestructor(void *interp, void *val)
10062 {
10063 Jim_DecrRefCount(interp, (Jim_Obj *)val);
10064 }
10065
10066
10067 static void *JimVariablesHTValDup(void *privdata, const void *val)
10068 {
10069 JimIncrVarRef((Jim_VarVal *)val);
10070 return (void *)val;
10071 }
10072
10073 static const Jim_HashTableType JimVariablesHashTableType = {
10074 JimObjectHTHashFunction,
10075 JimObjectHTKeyValDup,
10076 JimVariablesHTValDup,
10077 JimObjectHTKeyCompare,
10078 JimObjectHTKeyValDestructor,
10079 JimVariablesHTValDestructor
10080 };
10081
10082
10083 static const char *Jim_GetStringNoQualifier(Jim_Obj *objPtr, int *length)
10084 {
10085 int len;
10086 const char *str = Jim_GetString(objPtr, &len);
10087 if (len >= 2 && str[0] == ':' && str[1] == ':') {
10088 while (len && *str == ':') {
10089 len--;
10090 str++;
10091 }
10092 }
10093 *length = len;
10094 return str;
10095 }
10096
10097 static unsigned int JimCommandsHT_HashFunction(const void *key)
10098 {
10099 int len;
10100 const char *str = Jim_GetStringNoQualifier((Jim_Obj *)key, &len);
10101 return Jim_GenHashFunction((const unsigned char *)str, len);
10102 }
10103
10104 static int JimCommandsHT_KeyCompare(void *privdata, const void *key1, const void *key2)
10105 {
10106 int len1, len2;
10107 const char *str1 = Jim_GetStringNoQualifier((Jim_Obj *)key1, &len1);
10108 const char *str2 = Jim_GetStringNoQualifier((Jim_Obj *)key2, &len2);
10109 return len1 == len2 && memcmp(str1, str2, len1) == 0;
10110 }
10111
10112 static void JimCommandsHT_ValDestructor(void *interp, void *val)
10113 {
10114 JimDecrCmdRefCount(interp, val);
10115 }
10116
10117 static const Jim_HashTableType JimCommandsHashTableType = {
10118 JimCommandsHT_HashFunction,
10119 JimObjectHTKeyValDup,
10120 NULL,
10121 JimCommandsHT_KeyCompare,
10122 JimObjectHTKeyValDestructor,
10123 JimCommandsHT_ValDestructor
10124 };
10125
10126
10127
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10128 Jim_Obj *Jim_MakeGlobalNamespaceName(Jim_Interp *interp, Jim_Obj *nameObjPtr)
10129 {
10130 #ifdef jim_ext_namespace
10131 Jim_Obj *resultObj;
10132
10133 const char *name = Jim_String(nameObjPtr);
10134 if (name[0] == ':' && name[1] == ':') {
10135 return nameObjPtr;
@@ -9343,71 +10138,54 @@
10138 resultObj = Jim_NewStringObj(interp, "::", -1);
10139 Jim_AppendObj(interp, resultObj, nameObjPtr);
10140 Jim_DecrRefCount(interp, nameObjPtr);
10141
10142 return resultObj;
10143 #else
10144 return nameObjPtr;
10145 #endif
10146 }
10147
10148 static Jim_Obj *JimQualifyName(Jim_Interp *interp, Jim_Obj *objPtr)
10149 {
10150 #ifdef jim_ext_namespace
10151 if (Jim_Length(interp->framePtr->nsObj)) {
10152 int len;
10153 const char *name = Jim_GetString(objPtr, &len);
10154 if (len < 2 || name[0] != ':' || name[1] != ':') {
10155
10156 objPtr = Jim_DuplicateObj(interp, interp->framePtr->nsObj);
10157 Jim_AppendStrings(interp, objPtr, "::", name, NULL);
10158 }
10159 }
10160 #endif
10161 Jim_IncrRefCount(objPtr);
10162 return objPtr;
10163 }
10164
10165 static void JimCreateCommand(Jim_Interp *interp, Jim_Obj *nameObjPtr, Jim_Cmd *cmd)
10166 {
10167 JimPanic((nameObjPtr->refCount == 0, "JimCreateCommand called with zero ref count name"));
10168
10169 if (interp->local) {
10170 Jim_HashEntry *he = Jim_FindHashEntry(&interp->commands, nameObjPtr);
10171 if (he) {
10172
10173 cmd->prevCmd = Jim_GetHashEntryVal(he);
10174 Jim_SetHashVal(&interp->commands, he, cmd);
10175
10176 Jim_InterpIncrProcEpoch(interp);
10177 return;
10178 }
10179 }
10180
10181
10182
10183 Jim_ReplaceHashEntry(&interp->commands, nameObjPtr, cmd);
10184 }
10185
10186 int Jim_CreateCommandObj(Jim_Interp *interp, Jim_Obj *cmdNameObj,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10187 Jim_CmdProc *cmdProc, void *privData, Jim_DelCmdProc *delProc)
10188 {
10189 Jim_Cmd *cmdPtr = Jim_Alloc(sizeof(*cmdPtr));
10190
10191
@@ -9415,15 +10193,24 @@
10193 cmdPtr->inUse = 1;
10194 cmdPtr->u.native.delProc = delProc;
10195 cmdPtr->u.native.cmdProc = cmdProc;
10196 cmdPtr->u.native.privData = privData;
10197
10198 Jim_IncrRefCount(cmdNameObj);
10199 JimCreateCommand(interp, cmdNameObj, cmdPtr);
10200 Jim_DecrRefCount(interp, cmdNameObj);
10201
10202 return JIM_OK;
10203 }
10204
10205
10206 int Jim_CreateCommand(Jim_Interp *interp, const char *cmdNameStr,
10207 Jim_CmdProc *cmdProc, void *privData, Jim_DelCmdProc *delProc)
10208 {
10209 return Jim_CreateCommandObj(interp, Jim_NewStringObj(interp, cmdNameStr, -1), cmdProc, privData, delProc);
10210 }
10211
10212 static int JimCreateProcedureStatics(Jim_Interp *interp, Jim_Cmd *cmdPtr, Jim_Obj *staticsListObjPtr)
10213 {
10214 int len, i;
10215
10216 len = Jim_ListLength(interp, staticsListObjPtr);
@@ -9432,72 +10219,129 @@
10219 }
10220
10221 cmdPtr->u.proc.staticVars = Jim_Alloc(sizeof(Jim_HashTable));
10222 Jim_InitHashTable(cmdPtr->u.proc.staticVars, &JimVariablesHashTableType, interp);
10223 for (i = 0; i < len; i++) {
10224 Jim_Obj *initObjPtr = NULL;
10225 Jim_Obj *nameObjPtr;
10226 Jim_VarVal *vv = NULL;
10227 Jim_Obj *objPtr = Jim_ListGetIndex(interp, staticsListObjPtr, i);
10228 int subLen = Jim_ListLength(interp, objPtr);
10229 int byref = 0;
10230
10231
10232 if (subLen != 1 && subLen != 2) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10233 Jim_SetResultFormatted(interp, "too many fields in static specifier \"%#s\"",
10234 objPtr);
10235 return JIM_ERR;
10236 }
10237
10238 nameObjPtr = Jim_ListGetIndex(interp, objPtr, 0);
10239
10240
10241 if (subLen == 1) {
10242 int len;
10243 const char *pt = Jim_GetString(nameObjPtr, &len);
10244 if (*pt == '&') {
10245
10246 nameObjPtr = Jim_NewStringObj(interp, pt + 1, len - 1);
10247 byref = 1;
10248 }
10249 }
10250 Jim_IncrRefCount(nameObjPtr);
10251
10252 if (subLen == 1) {
10253 switch (SetVariableFromAny(interp, nameObjPtr)) {
10254 case JIM_DICT_SUGAR:
10255
10256 if (byref) {
10257 Jim_SetResultFormatted(interp, "Can't link to array element \"%#s\"", nameObjPtr);
10258 }
10259 else {
10260 Jim_SetResultFormatted(interp, "Can't initialise array element \"%#s\"", nameObjPtr);
10261 }
10262 Jim_DecrRefCount(interp, nameObjPtr);
10263 return JIM_ERR;
10264
10265 case JIM_OK:
10266 if (byref) {
10267 vv = nameObjPtr->internalRep.varValue.vv;
10268 }
10269 else {
10270 initObjPtr = Jim_GetVariable(interp, nameObjPtr, JIM_NONE);
10271 }
10272 break;
10273
10274 case JIM_ERR:
10275
10276 Jim_SetResultFormatted(interp,
10277 "variable for initialization of static \"%#s\" not found in the local context",
10278 nameObjPtr);
10279 Jim_DecrRefCount(interp, nameObjPtr);
10280 return JIM_ERR;
10281 }
10282 }
10283 else {
10284 initObjPtr = Jim_ListGetIndex(interp, objPtr, 1);
10285 }
10286
10287 if (vv == NULL) {
10288 vv = Jim_Alloc(sizeof(*vv));
10289 vv->objPtr = initObjPtr;
10290 Jim_IncrRefCount(vv->objPtr);
10291 vv->linkFramePtr = NULL;
10292 vv->refCount = 0;
10293 }
10294
10295 if (JimSetNewVariable(cmdPtr->u.proc.staticVars, nameObjPtr, vv) != JIM_OK) {
10296 Jim_SetResultFormatted(interp,
10297 "static variable name \"%#s\" duplicated in statics list", nameObjPtr);
10298 JimIncrVarRef(vv);
10299 JimDecrVarRef(interp, vv);
10300 Jim_DecrRefCount(interp, nameObjPtr);
10301 return JIM_ERR;
10302 }
10303
10304 Jim_DecrRefCount(interp, nameObjPtr);
10305 }
10306 return JIM_OK;
10307 }
10308
10309
10310 #ifdef jim_ext_namespace
10311 static const char *Jim_memrchr(const char *p, int c, int len)
10312 {
10313 int i;
10314 for (i = len; i > 0; i--) {
10315 if (p[i] == c) {
10316 return p + i;
10317 }
10318 }
10319 return NULL;
10320 }
10321 #endif
10322
10323 static void JimUpdateProcNamespace(Jim_Interp *interp, Jim_Cmd *cmdPtr, Jim_Obj *nameObjPtr)
10324 {
10325 #ifdef jim_ext_namespace
10326 if (cmdPtr->isproc) {
10327 int len;
10328 const char *cmdname = Jim_GetStringNoQualifier(nameObjPtr, &len);
10329
10330 const char *pt = Jim_memrchr(cmdname, ':', len);
10331 if (pt && pt != cmdname && pt[-1] == ':') {
10332 pt++;
10333 Jim_DecrRefCount(interp, cmdPtr->u.proc.nsObj);
10334 cmdPtr->u.proc.nsObj = Jim_NewStringObj(interp, cmdname, pt - cmdname - 2);
10335 Jim_IncrRefCount(cmdPtr->u.proc.nsObj);
10336
10337 Jim_Obj *tempObj = Jim_NewStringObj(interp, pt, len - (pt - cmdname));
10338 if (Jim_FindHashEntry(&interp->commands, tempObj)) {
10339
10340 Jim_InterpIncrProcEpoch(interp);
10341 }
10342 Jim_FreeNewObj(interp, tempObj);
10343 }
10344 }
10345 #endif
10346 }
10347
@@ -9510,10 +10354,11 @@
10354
10355 argListLen = Jim_ListLength(interp, argListObjPtr);
10356
10357
10358 cmdPtr = Jim_Alloc(sizeof(*cmdPtr) + sizeof(struct Jim_ProcArg) * argListLen);
10359 assert(cmdPtr);
10360 memset(cmdPtr, 0, sizeof(*cmdPtr));
10361 cmdPtr->inUse = 1;
10362 cmdPtr->isproc = 1;
10363 cmdPtr->u.proc.argListObjPtr = argListObjPtr;
10364 cmdPtr->u.proc.argListLen = argListLen;
@@ -9585,72 +10430,71 @@
10430 }
10431
10432 return cmdPtr;
10433 }
10434
10435 int Jim_DeleteCommand(Jim_Interp *interp, Jim_Obj *nameObj)
10436 {
10437 int ret = JIM_OK;
 
 
10438
10439 nameObj = JimQualifyName(interp, nameObj);
10440
10441 if (Jim_DeleteHashEntry(&interp->commands, nameObj) == JIM_ERR) {
10442 Jim_SetResultFormatted(interp, "can't delete \"%#s\": command doesn't exist", nameObj);
10443 ret = JIM_ERR;
10444 }
10445 Jim_DecrRefCount(interp, nameObj);
 
 
 
 
10446
10447 return ret;
10448 }
10449
10450 int Jim_RenameCommand(Jim_Interp *interp, Jim_Obj *oldNameObj, Jim_Obj *newNameObj)
10451 {
10452 int ret = JIM_ERR;
10453 Jim_HashEntry *he;
10454 Jim_Cmd *cmdPtr;
 
 
 
 
10455
10456 if (Jim_Length(newNameObj) == 0) {
10457 return Jim_DeleteCommand(interp, oldNameObj);
10458 }
10459
 
 
10460
10461
10462 oldNameObj = JimQualifyName(interp, oldNameObj);
10463 newNameObj = JimQualifyName(interp, newNameObj);
10464
10465
10466 he = Jim_FindHashEntry(&interp->commands, oldNameObj);
10467 if (he == NULL) {
10468 Jim_SetResultFormatted(interp, "can't rename \"%#s\": command doesn't exist", oldNameObj);
10469 }
10470 else if (Jim_FindHashEntry(&interp->commands, newNameObj)) {
10471 Jim_SetResultFormatted(interp, "can't rename to \"%#s\": command already exists", newNameObj);
10472 }
10473 else {
 
10474 cmdPtr = Jim_GetHashEntryVal(he);
10475 if (cmdPtr->prevCmd) {
10476 Jim_SetResultFormatted(interp, "can't rename local command \"%#s\"", oldNameObj);
10477 }
10478 else {
10479
10480 JimIncrCmdRefCount(cmdPtr);
10481 JimUpdateProcNamespace(interp, cmdPtr, newNameObj);
10482 Jim_AddHashEntry(&interp->commands, newNameObj, cmdPtr);
10483
10484
10485 Jim_DeleteHashEntry(&interp->commands, oldNameObj);
10486
10487
10488 Jim_InterpIncrProcEpoch(interp);
10489
10490 ret = JIM_OK;
10491 }
10492 }
10493
10494 Jim_DecrRefCount(interp, oldNameObj);
10495 Jim_DecrRefCount(interp, newNameObj);
10496
10497 return ret;
10498 }
10499
10500
@@ -9676,104 +10520,70 @@
10520
10521 Jim_Cmd *Jim_GetCommand(Jim_Interp *interp, Jim_Obj *objPtr, int flags)
10522 {
10523 Jim_Cmd *cmd;
10524
10525 if (objPtr->typePtr == &commandObjType
10526 && objPtr->internalRep.cmdValue.procEpoch == interp->procEpoch
10527 #ifdef jim_ext_namespace
10528 && Jim_StringEqObj(objPtr->internalRep.cmdValue.nsObj, interp->framePtr->nsObj)
10529 #endif
10530 && objPtr->internalRep.cmdValue.cmdPtr->inUse) {
10531
10532 cmd = objPtr->internalRep.cmdValue.cmdPtr;
10533 }
10534 else {
10535 Jim_Obj *qualifiedNameObj = JimQualifyName(interp, objPtr);
10536 Jim_HashEntry *he = Jim_FindHashEntry(&interp->commands, qualifiedNameObj);
10537 #ifdef jim_ext_namespace
10538 if (he == NULL && Jim_Length(interp->framePtr->nsObj)) {
10539 he = Jim_FindHashEntry(&interp->commands, objPtr);
10540 }
10541 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10542 if (he == NULL) {
10543 if (flags & JIM_ERRMSG) {
10544 Jim_SetResultFormatted(interp, "invalid command name \"%#s\"", objPtr);
10545 }
10546 Jim_DecrRefCount(interp, qualifiedNameObj);
10547 return NULL;
10548 }
 
 
 
10549 cmd = Jim_GetHashEntryVal(he);
10550
10551 cmd->cmdNameObj = Jim_GetHashEntryKey(he);
10552
10553
10554 Jim_FreeIntRep(interp, objPtr);
10555 objPtr->typePtr = &commandObjType;
10556 objPtr->internalRep.cmdValue.procEpoch = interp->procEpoch;
10557 objPtr->internalRep.cmdValue.cmdPtr = cmd;
10558 objPtr->internalRep.cmdValue.nsObj = interp->framePtr->nsObj;
10559 Jim_IncrRefCount(interp->framePtr->nsObj);
10560 Jim_DecrRefCount(interp, qualifiedNameObj);
 
 
10561 }
10562 while (cmd->u.proc.upcall) {
10563 cmd = cmd->prevCmd;
10564 }
10565 return cmd;
10566 }
10567
10568
10569
 
 
 
 
10570 static const Jim_ObjType variableObjType = {
10571 "variable",
10572 NULL,
10573 NULL,
10574 NULL,
10575 JIM_TYPE_REFERENCES,
10576 };
10577
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10578 static int SetVariableFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr)
10579 {
10580 const char *varName;
10581 Jim_CallFrame *framePtr;
 
10582 int global;
10583 int len;
10584 Jim_VarVal *vv;
10585
10586
10587 if (objPtr->typePtr == &variableObjType) {
10588 framePtr = objPtr->internalRep.varValue.global ? interp->topFramePtr : interp->framePtr;
10589 if (objPtr->internalRep.varValue.callFrameId == framePtr->id) {
@@ -9783,126 +10593,144 @@
10593
10594 }
10595 else if (objPtr->typePtr == &dictSubstObjType) {
10596 return JIM_DICT_SUGAR;
10597 }
 
 
 
 
10598
10599 varName = Jim_GetString(objPtr, &len);
10600
10601
10602 if (len && varName[len - 1] == ')' && strchr(varName, '(') != NULL) {
10603 return JIM_DICT_SUGAR;
10604 }
10605
10606 if (varName[0] == ':' && varName[1] == ':') {
10607 while (*varName == ':') {
10608 varName++;
10609 len--;
10610 }
10611 global = 1;
10612 framePtr = interp->topFramePtr;
10613
10614 Jim_Obj *tempObj = Jim_NewStringObj(interp, varName, len);
10615 vv = JimFindVariable(&framePtr->vars, tempObj);
10616 Jim_FreeNewObj(interp, tempObj);
10617 }
10618 else {
10619 global = 0;
10620 framePtr = interp->framePtr;
10621
10622 vv = JimFindVariable(&framePtr->vars, objPtr);
10623 if (vv == NULL && framePtr->staticVars) {
10624
10625 vv = JimFindVariable(framePtr->staticVars, objPtr);
10626 }
10627 }
10628
10629 if (vv == NULL) {
10630 return JIM_ERR;
 
 
 
 
 
 
 
 
10631 }
10632
10633
10634 Jim_FreeIntRep(interp, objPtr);
10635 objPtr->typePtr = &variableObjType;
10636 objPtr->internalRep.varValue.callFrameId = framePtr->id;
10637 objPtr->internalRep.varValue.vv = vv;
10638 objPtr->internalRep.varValue.global = global;
10639 return JIM_OK;
10640 }
10641
10642
10643 static int JimDictSugarSet(Jim_Interp *interp, Jim_Obj *ObjPtr, Jim_Obj *valObjPtr);
10644 static Jim_Obj *JimDictSugarGet(Jim_Interp *interp, Jim_Obj *ObjPtr, int flags);
10645
10646 static int JimSetNewVariable(Jim_HashTable *ht, Jim_Obj *nameObjPtr, Jim_VarVal *vv)
10647 {
10648 return Jim_AddHashEntry(ht, nameObjPtr, vv);
10649 }
10650
10651 static Jim_VarVal *JimFindVariable(Jim_HashTable *ht, Jim_Obj *nameObjPtr)
10652 {
10653 Jim_HashEntry *he = Jim_FindHashEntry(ht, nameObjPtr);
10654 if (he) {
10655 return (Jim_VarVal *)Jim_GetHashEntryVal(he);
10656 }
10657 return NULL;
10658 }
10659
10660 static int JimUnsetVariable(Jim_HashTable *ht, Jim_Obj *nameObjPtr)
10661 {
10662 return Jim_DeleteHashEntry(ht, nameObjPtr);
10663 }
10664
10665 static Jim_VarVal *JimCreateVariable(Jim_Interp *interp, Jim_Obj *nameObjPtr, Jim_Obj *valObjPtr)
10666 {
10667 const char *name;
10668 Jim_CallFrame *framePtr;
10669 int global;
10670 int len;
10671
10672
10673 Jim_VarVal *vv = Jim_Alloc(sizeof(*vv));
10674
10675 vv->objPtr = valObjPtr;
10676 Jim_IncrRefCount(valObjPtr);
10677 vv->linkFramePtr = NULL;
10678 vv->refCount = 0;
10679
10680 name = Jim_GetString(nameObjPtr, &len);
10681 if (name[0] == ':' && name[1] == ':') {
10682 while (*name == ':') {
10683 name++;
10684 len--;
10685 }
10686 framePtr = interp->topFramePtr;
10687 global = 1;
10688 JimSetNewVariable(&framePtr->vars, Jim_NewStringObj(interp, name, len), vv);
10689 }
10690 else {
10691 framePtr = interp->framePtr;
10692 global = 0;
10693 JimSetNewVariable(&framePtr->vars, nameObjPtr, vv);
10694 }
10695
 
 
 
10696
10697 Jim_FreeIntRep(interp, nameObjPtr);
10698 nameObjPtr->typePtr = &variableObjType;
10699 nameObjPtr->internalRep.varValue.callFrameId = framePtr->id;
10700 nameObjPtr->internalRep.varValue.vv = vv;
10701 nameObjPtr->internalRep.varValue.global = global;
10702
10703 return vv;
10704 }
 
10705
10706 int Jim_SetVariable(Jim_Interp *interp, Jim_Obj *nameObjPtr, Jim_Obj *valObjPtr)
10707 {
10708 int err;
10709 Jim_VarVal *vv;
10710
10711 switch (SetVariableFromAny(interp, nameObjPtr)) {
10712 case JIM_DICT_SUGAR:
10713 return JimDictSugarSet(interp, nameObjPtr, valObjPtr);
10714
10715 case JIM_ERR:
 
 
 
10716 JimCreateVariable(interp, nameObjPtr, valObjPtr);
10717 break;
10718
10719 case JIM_OK:
10720 vv = nameObjPtr->internalRep.varValue.vv;
10721 if (vv->linkFramePtr == NULL) {
10722 Jim_IncrRefCount(valObjPtr);
10723 Jim_DecrRefCount(interp, vv->objPtr);
10724 vv->objPtr = valObjPtr;
10725 }
10726 else {
10727 Jim_CallFrame *savedCallFrame;
10728
10729 savedCallFrame = interp->framePtr;
10730 interp->framePtr = vv->linkFramePtr;
10731 err = Jim_SetVariable(interp, vv->objPtr, valObjPtr);
10732 interp->framePtr = savedCallFrame;
10733 if (err != JIM_OK)
10734 return err;
10735 }
10736 }
@@ -9949,51 +10777,57 @@
10777 Jim_Obj *targetNameObjPtr, Jim_CallFrame *targetCallFrame)
10778 {
10779 const char *varName;
10780 const char *targetName;
10781 Jim_CallFrame *framePtr;
10782 Jim_VarVal *vv;
10783 int len;
10784 int varnamelen;
10785
10786
10787 switch (SetVariableFromAny(interp, nameObjPtr)) {
10788 case JIM_DICT_SUGAR:
10789
10790 Jim_SetResultFormatted(interp, "bad variable name \"%#s\": upvar won't create a scalar variable that looks like an array element", nameObjPtr);
10791 return JIM_ERR;
10792
10793 case JIM_OK:
10794 vv = nameObjPtr->internalRep.varValue.vv;
10795
10796 if (vv->linkFramePtr == NULL) {
10797 Jim_SetResultFormatted(interp, "variable \"%#s\" already exists", nameObjPtr);
10798 return JIM_ERR;
10799 }
10800
10801
10802 vv->linkFramePtr = NULL;
10803 break;
10804 }
10805
10806
10807
10808 varName = Jim_GetString(nameObjPtr, &varnamelen);
10809
10810 if (varName[0] == ':' && varName[1] == ':') {
10811 while (*varName == ':') {
10812 varName++;
10813 varnamelen--;
10814 }
10815
10816 framePtr = interp->topFramePtr;
10817 }
10818 else {
10819 framePtr = interp->framePtr;
10820 }
10821
10822 targetName = Jim_GetString(targetNameObjPtr, &len);
10823 if (targetName[0] == ':' && targetName[1] == ':') {
10824 while (*targetName == ':') {
10825 targetName++;
10826 len--;
10827 }
10828 targetNameObjPtr = Jim_NewStringObj(interp, targetName, len);
10829 targetCallFrame = interp->topFramePtr;
10830 }
10831 Jim_IncrRefCount(targetNameObjPtr);
10832
10833 if (framePtr->level < targetCallFrame->level) {
@@ -10008,49 +10842,52 @@
10842 if (framePtr == targetCallFrame) {
10843 Jim_Obj *objPtr = targetNameObjPtr;
10844
10845
10846 while (1) {
10847 if (Jim_Length(objPtr) == varnamelen && memcmp(Jim_String(objPtr), varName, varnamelen) == 0) {
10848 Jim_SetResultString(interp, "can't upvar from variable to itself", -1);
10849 Jim_DecrRefCount(interp, targetNameObjPtr);
10850 return JIM_ERR;
10851 }
10852 if (SetVariableFromAny(interp, objPtr) != JIM_OK)
10853 break;
10854 vv = objPtr->internalRep.varValue.vv;
10855 if (vv->linkFramePtr != targetCallFrame)
10856 break;
10857 objPtr = vv->objPtr;
10858 }
10859 }
10860
10861
10862 Jim_SetVariable(interp, nameObjPtr, targetNameObjPtr);
10863
10864 nameObjPtr->internalRep.varValue.vv->linkFramePtr = targetCallFrame;
10865 Jim_DecrRefCount(interp, targetNameObjPtr);
10866 return JIM_OK;
10867 }
10868
10869 Jim_Obj *Jim_GetVariable(Jim_Interp *interp, Jim_Obj *nameObjPtr, int flags)
10870 {
10871 if (interp->safeexpr) {
10872 return nameObjPtr;
10873 }
10874 switch (SetVariableFromAny(interp, nameObjPtr)) {
10875 case JIM_OK:{
10876 Jim_VarVal *vv = nameObjPtr->internalRep.varValue.vv;
10877
10878 if (vv->linkFramePtr == NULL) {
10879 return vv->objPtr;
10880 }
10881 else {
10882 Jim_Obj *objPtr;
10883
10884
10885 Jim_CallFrame *savedCallFrame = interp->framePtr;
10886
10887 interp->framePtr = vv->linkFramePtr;
10888 objPtr = Jim_GetVariable(interp, vv->objPtr, flags);
10889 interp->framePtr = savedCallFrame;
10890 if (objPtr) {
10891 return objPtr;
10892 }
10893
@@ -10105,40 +10942,47 @@
10942 return objPtr;
10943 }
10944
10945 int Jim_UnsetVariable(Jim_Interp *interp, Jim_Obj *nameObjPtr, int flags)
10946 {
10947 Jim_VarVal *vv;
10948 int retval;
10949 Jim_CallFrame *framePtr;
10950
10951 retval = SetVariableFromAny(interp, nameObjPtr);
10952 if (retval == JIM_DICT_SUGAR) {
10953
10954 return JimDictSugarSet(interp, nameObjPtr, NULL);
10955 }
10956 else if (retval == JIM_OK) {
10957 vv = nameObjPtr->internalRep.varValue.vv;
10958
10959
10960 if (vv->linkFramePtr) {
10961 framePtr = interp->framePtr;
10962 interp->framePtr = vv->linkFramePtr;
10963 retval = Jim_UnsetVariable(interp, vv->objPtr, JIM_NONE);
10964 interp->framePtr = framePtr;
10965 }
10966 else {
 
10967 if (nameObjPtr->internalRep.varValue.global) {
10968 int len;
10969 const char *name = Jim_GetString(nameObjPtr, &len);
10970 while (*name == ':') {
10971 name++;
10972 len--;
10973 }
10974 framePtr = interp->topFramePtr;
10975 Jim_Obj *tempObj = Jim_NewStringObj(interp, name, len);
10976 retval = JimUnsetVariable(&framePtr->vars, tempObj);
10977 Jim_FreeNewObj(interp, tempObj);
10978 }
10979 else {
10980 framePtr = interp->framePtr;
10981 retval = JimUnsetVariable(&framePtr->vars, nameObjPtr);
10982 }
10983
 
10984 if (retval == JIM_OK) {
10985
10986 framePtr->id = interp->callFrameEpoch++;
10987 }
10988 }
@@ -10290,10 +11134,14 @@
11134
11135 static Jim_Obj *JimExpandDictSugar(Jim_Interp *interp, Jim_Obj *objPtr)
11136 {
11137 Jim_Obj *resObjPtr = NULL;
11138 Jim_Obj *substKeyObjPtr = NULL;
11139
11140 if (interp->safeexpr) {
11141 return objPtr;
11142 }
11143
11144 SetDictSubstFromAny(interp, objPtr);
11145
11146 if (Jim_SubstObj(interp, objPtr->internalRep.dictSubstValue.indexObjPtr,
11147 &substKeyObjPtr, JIM_NONE)
@@ -10307,18 +11155,10 @@
11155 Jim_DecrRefCount(interp, substKeyObjPtr);
11156
11157 return resObjPtr;
11158 }
11159
 
 
 
 
 
 
 
 
11160
11161 static Jim_CallFrame *JimCreateCallFrame(Jim_Interp *interp, Jim_CallFrame *parent, Jim_Obj *nsObj)
11162 {
11163 Jim_CallFrame *cf;
11164
@@ -10357,18 +11197,12 @@
11197
11198 if (localCommands) {
11199 Jim_Obj *cmdNameObj;
11200
11201 while ((cmdNameObj = Jim_StackPop(localCommands)) != NULL) {
 
 
11202 Jim_HashTable *ht = &interp->commands;
11203 Jim_HashEntry *he = Jim_FindHashEntry(ht, cmdNameObj);
 
 
 
 
11204 if (he) {
11205 Jim_Cmd *cmd = Jim_GetHashEntryVal(he);
11206 if (cmd->prevCmd) {
11207 Jim_Cmd *prevCmd = cmd->prevCmd;
11208 cmd->prevCmd = NULL;
@@ -10378,16 +11212,14 @@
11212
11213
11214 Jim_SetHashVal(ht, he, prevCmd);
11215 }
11216 else {
11217 Jim_DeleteHashEntry(ht, cmdNameObj);
11218 }
 
11219 }
11220 Jim_DecrRefCount(interp, cmdNameObj);
 
11221 }
11222 Jim_FreeStack(localCommands);
11223 Jim_Free(localCommands);
11224 }
11225 return JIM_OK;
@@ -10396,15 +11228,14 @@
11228 static int JimInvokeDefer(Jim_Interp *interp, int retcode)
11229 {
11230 Jim_Obj *objPtr;
11231
11232
11233 if (JimFindVariable(&interp->framePtr->vars, interp->defer) == NULL) {
11234 return retcode;
11235 }
11236 objPtr = Jim_GetVariable(interp, interp->defer, JIM_NONE);
 
11237
11238 if (objPtr) {
11239 int ret = JIM_OK;
11240 int i;
11241 int listLen = Jim_ListLength(interp, objPtr);
@@ -10452,28 +11283,11 @@
11283 Jim_DecrRefCount(interp, cf->procBodyObjPtr);
11284 Jim_DecrRefCount(interp, cf->nsObj);
11285 if (action == JIM_FCF_FULL || cf->vars.size != JIM_HT_INITIAL_SIZE)
11286 Jim_FreeHashTable(&cf->vars);
11287 else {
11288 Jim_ClearHashTable(&cf->vars);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11289 }
11290 cf->next = interp->freeFramesList;
11291 interp->freeFramesList = cf;
11292 }
11293
@@ -10496,11 +11310,11 @@
11310
11311 memset(i, 0, sizeof(*i));
11312
11313 i->maxCallFrameDepth = JIM_MAX_CALLFRAME_DEPTH;
11314 i->maxEvalDepth = JIM_MAX_EVAL_DEPTH;
11315 i->lastCollectTime = Jim_GetTimeUsec(CLOCK_MONOTONIC_RAW);
11316
11317 Jim_InitHashTable(&i->commands, &JimCommandsHashTableType, i);
11318 #ifdef JIM_REFERENCES
11319 Jim_InitHashTable(&i->references, &JimReferencesHashTableType, i);
11320 #endif
@@ -10508,27 +11322,28 @@
11322 Jim_InitHashTable(&i->packages, &JimPackageHashTableType, NULL);
11323 i->emptyObj = Jim_NewEmptyStringObj(i);
11324 i->trueObj = Jim_NewIntObj(i, 1);
11325 i->falseObj = Jim_NewIntObj(i, 0);
11326 i->framePtr = i->topFramePtr = JimCreateCallFrame(i, NULL, i->emptyObj);
 
11327 i->result = i->emptyObj;
11328 i->stackTrace = Jim_NewListObj(i, NULL, 0);
11329 i->unknown = Jim_NewStringObj(i, "unknown", -1);
11330 i->defer = Jim_NewStringObj(i, "jim::defer", -1);
11331 i->errorProc = i->emptyObj;
 
11332 i->nullScriptObj = Jim_NewEmptyStringObj(i);
11333 i->evalFrame = &i->topEvalFrame;
11334 i->currentFilenameObj = Jim_NewEmptyStringObj(i);
11335 Jim_IncrRefCount(i->emptyObj);
 
11336 Jim_IncrRefCount(i->result);
11337 Jim_IncrRefCount(i->stackTrace);
11338 Jim_IncrRefCount(i->unknown);
11339 Jim_IncrRefCount(i->defer);
11340 Jim_IncrRefCount(i->nullScriptObj);
11341 Jim_IncrRefCount(i->errorProc);
11342 Jim_IncrRefCount(i->trueObj);
11343 Jim_IncrRefCount(i->falseObj);
11344 Jim_IncrRefCount(i->currentFilenameObj);
11345
11346
11347 Jim_SetVariableStrWithStr(i, JIM_LIBPATH, TCL_LIBRARY);
11348 Jim_SetVariableStrWithStr(i, JIM_INTERACTIVE, "0");
11349
@@ -10536,21 +11351,25 @@
11351 Jim_SetVariableStrWithStr(i, "tcl_platform(os)", TCL_PLATFORM_OS);
11352 Jim_SetVariableStrWithStr(i, "tcl_platform(platform)", TCL_PLATFORM_PLATFORM);
11353 Jim_SetVariableStrWithStr(i, "tcl_platform(pathSeparator)", TCL_PLATFORM_PATH_SEPARATOR);
11354 Jim_SetVariableStrWithStr(i, "tcl_platform(byteOrder)", Jim_IsBigEndian() ? "bigEndian" : "littleEndian");
11355 Jim_SetVariableStrWithStr(i, "tcl_platform(threaded)", "0");
11356 Jim_SetVariableStrWithStr(i, "tcl_platform(bootstrap)", "0");
11357 Jim_SetVariableStr(i, "tcl_platform(pointerSize)", Jim_NewIntObj(i, sizeof(void *)));
11358 Jim_SetVariableStr(i, "tcl_platform(wordSize)", Jim_NewIntObj(i, sizeof(jim_wide)));
11359 Jim_SetVariableStr(i, "tcl_platform(stackFormat)", Jim_NewIntObj(i, 4));
11360
11361 return i;
11362 }
11363
11364 void Jim_FreeInterp(Jim_Interp *i)
11365 {
11366 Jim_CallFrame *cf, *cfx;
11367
11368 Jim_Obj *objPtr, *nextObjPtr;
11369
11370 i->quitting = 1;
11371
11372
11373 for (cf = i->framePtr; cf; cf = cfx) {
11374
11375 JimInvokeDefer(i, JIM_OK);
@@ -10563,20 +11382,27 @@
11382 Jim_DecrRefCount(i, i->falseObj);
11383 Jim_DecrRefCount(i, i->result);
11384 Jim_DecrRefCount(i, i->stackTrace);
11385 Jim_DecrRefCount(i, i->errorProc);
11386 Jim_DecrRefCount(i, i->unknown);
11387 Jim_DecrRefCount(i, i->defer);
 
11388 Jim_DecrRefCount(i, i->nullScriptObj);
11389 Jim_DecrRefCount(i, i->currentFilenameObj);
11390
11391
11392 Jim_InterpIncrProcEpoch(i);
11393
11394 Jim_FreeHashTable(&i->commands);
11395 #ifdef JIM_REFERENCES
11396 Jim_FreeHashTable(&i->references);
11397 #endif
11398 Jim_FreeHashTable(&i->packages);
11399 Jim_Free(i->prngState);
11400 Jim_FreeHashTable(&i->assocData);
11401 if (i->traceCmdObj) {
11402 Jim_DecrRefCount(i, i->traceCmdObj);
11403 }
11404
11405 #ifdef JIM_MAINTAINER
11406 if (i->liveList != NULL) {
11407 objPtr = i->liveList;
11408
@@ -10671,102 +11497,115 @@
11497
11498 Jim_SetResultFormatted(interp, "bad level \"%s\"", str);
11499 return NULL;
11500 }
11501
11502 static Jim_CallFrame *JimGetCallFrameByInteger(Jim_Interp *interp, long level)
11503 {
 
11504 Jim_CallFrame *framePtr;
11505
11506 if (level == 0) {
11507 return interp->framePtr;
11508 }
11509
11510 if (level < 0) {
11511
11512 level = interp->framePtr->level + level;
11513 }
11514
11515 if (level > 0) {
11516
11517 for (framePtr = interp->framePtr; framePtr; framePtr = framePtr->parent) {
11518 if (framePtr->level == level) {
11519 return framePtr;
11520 }
11521 }
11522 }
11523 return NULL;
11524 }
11525
11526 static Jim_EvalFrame *JimGetEvalFrameByProcLevel(Jim_Interp *interp, int proclevel)
11527 {
11528 Jim_EvalFrame *evalFrame;
11529
11530 if (proclevel == 0) {
11531 return interp->evalFrame;
11532 }
11533
11534 if (proclevel < 0) {
11535
11536 proclevel = interp->procLevel + proclevel;
11537 }
11538
11539 if (proclevel >= 0) {
11540
11541 for (evalFrame = interp->evalFrame; evalFrame; evalFrame = evalFrame->parent) {
11542 if (evalFrame->procLevel == proclevel) {
11543 return evalFrame;
11544 }
11545 }
11546 }
11547 return NULL;
11548 }
11549
11550 static Jim_Obj *JimProcForEvalFrame(Jim_Interp *interp, Jim_EvalFrame *frame)
11551 {
11552 if (frame == interp->evalFrame || (frame->cmd && frame->cmd->cmdNameObj)) {
11553 Jim_EvalFrame *e;
11554 for (e = frame->parent; e; e = e->parent) {
11555 if (e->cmd && e->cmd->isproc && e->cmd->cmdNameObj) {
11556 break;
11557 }
11558 }
11559 if (e && e->cmd && e->cmd->cmdNameObj) {
11560 return e->cmd->cmdNameObj;
11561 }
11562 }
11563 return NULL;
11564 }
11565
11566 static void JimAddStackFrame(Jim_Interp *interp, Jim_EvalFrame *frame, Jim_Obj *listObj)
11567 {
11568 Jim_Obj *procNameObj = JimProcForEvalFrame(interp, frame);
11569 Jim_Obj *fileNameObj = interp->emptyObj;
11570 int linenr = 1;
11571
11572 if (frame->scriptObj) {
11573 ScriptObj *script = JimGetScript(interp, frame->scriptObj);
11574 fileNameObj = script->fileNameObj;
11575 linenr = script->linenr;
11576 }
11577
11578 Jim_ListAppendElement(interp, listObj, procNameObj ? procNameObj : interp->emptyObj);
11579 Jim_ListAppendElement(interp, listObj, fileNameObj);
11580 Jim_ListAppendElement(interp, listObj, Jim_NewIntObj(interp, linenr));
11581 Jim_ListAppendElement(interp, listObj, Jim_NewListObj(interp, frame->argv, frame->argc));
11582 }
11583
11584 static void JimSetStackTrace(Jim_Interp *interp, Jim_Obj *stackTraceObj)
11585 {
 
 
11586
11587 Jim_IncrRefCount(stackTraceObj);
11588 Jim_DecrRefCount(interp, interp->stackTrace);
11589 interp->stackTrace = stackTraceObj;
11590 interp->errorFlag = 1;
11591 }
11592
11593 static void JimSetErrorStack(Jim_Interp *interp)
11594 {
11595 if (!interp->errorFlag) {
11596 int i;
11597 Jim_Obj *stackTrace = Jim_NewListObj(interp, NULL, 0);
11598
11599 for (i = 0; i <= interp->procLevel; i++) {
11600 Jim_EvalFrame *frame = JimGetEvalFrameByProcLevel(interp, -i);
11601 if (frame) {
11602 JimAddStackFrame(interp, frame, stackTrace);
11603 }
11604 }
11605 JimSetStackTrace(interp, stackTrace);
11606 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11607 }
11608
11609 int Jim_SetAssocData(Jim_Interp *interp, const char *key, Jim_InterpDeleteProc * delProc,
11610 void *data)
11611 {
@@ -10897,10 +11736,36 @@
11736 return JIM_ERR;
11737 *widePtr = JimWideValue(objPtr);
11738 return JIM_OK;
11739 }
11740
11741 int Jim_GetWideExpr(Jim_Interp *interp, Jim_Obj *objPtr, jim_wide * widePtr)
11742 {
11743 int ret = JIM_OK;
11744
11745 if (objPtr->typePtr == &sourceObjType || objPtr->typePtr == NULL) {
11746 SetIntFromAny(interp, objPtr, 0);
11747 }
11748 if (objPtr->typePtr == &intObjType) {
11749 *widePtr = JimWideValue(objPtr);
11750 }
11751 else {
11752 JimPanic((interp->safeexpr, "interp->safeexpr is set"));
11753 interp->safeexpr++;
11754 ret = Jim_EvalExpression(interp, objPtr);
11755 interp->safeexpr--;
11756
11757 if (ret == JIM_OK) {
11758 ret = Jim_GetWide(interp, Jim_GetResult(interp), widePtr);
11759 }
11760 if (ret != JIM_OK) {
11761 Jim_SetResultFormatted(interp, "expected integer expression but got \"%#s\"", objPtr);
11762 }
11763 }
11764 return ret;
11765 }
11766
11767
11768 static int JimGetWideNoErr(Jim_Interp *interp, Jim_Obj *objPtr, jim_wide * widePtr)
11769 {
11770 if (objPtr->typePtr != &intObjType && SetIntFromAny(interp, objPtr, JIM_NONE) == JIM_ERR)
11771 return JIM_ERR;
@@ -10943,15 +11808,15 @@
11808 NULL,
11809 UpdateStringOfDouble,
11810 JIM_TYPE_NONE,
11811 };
11812
11813 #if !HAVE_DECL_ISNAN
11814 #undef isnan
11815 #define isnan(X) ((X) != (X))
11816 #endif
11817 #if !HAVE_DECL_ISINF
11818 #undef isinf
11819 #define isinf(X) (1.0 / (X) == 0.0)
11820 #endif
11821
11822 static void UpdateStringOfDouble(struct Jim_Obj *objPtr)
@@ -11078,38 +11943,37 @@
11943 if (objPtr->typePtr != &intObjType && SetBooleanFromAny(interp, objPtr, JIM_ERRMSG) == JIM_ERR)
11944 return JIM_ERR;
11945 *booleanPtr = (int) JimWideValue(objPtr);
11946 return JIM_OK;
11947 }
11948
11949 static const char * const jim_true_false_strings[8] = {
11950 "1", "true", "yes", "on",
11951 "0", "false", "no", "off"
11952 };
11953
11954 static const int jim_true_false_lens[8] = {
11955 1, 4, 3, 2,
11956 1, 5, 2, 3,
11957 };
11958
11959 static int SetBooleanFromAny(Jim_Interp *interp, Jim_Obj *objPtr, int flags)
11960 {
11961 int index = Jim_FindByName(Jim_String(objPtr), jim_true_false_strings,
11962 sizeof(jim_true_false_strings) / sizeof(*jim_true_false_strings));
11963 if (index < 0) {
 
 
 
 
 
 
 
 
 
 
 
 
11964 if (flags & JIM_ERRMSG) {
11965 Jim_SetResultFormatted(interp, "expected boolean but got \"%#s\"", objPtr);
11966 }
11967 return JIM_ERR;
11968 }
11969
11970
11971 Jim_FreeIntRep(interp, objPtr);
11972 objPtr->typePtr = &intObjType;
11973
11974 objPtr->internalRep.wideValue = index < 4 ? 1 : 0;
11975 return JIM_OK;
11976 }
11977
11978 static void ListInsertElements(Jim_Obj *listPtr, int idx, int elemc, Jim_Obj *const *elemVec);
11979 static void ListAppendElement(Jim_Obj *listPtr, Jim_Obj *objPtr);
@@ -11404,28 +12268,26 @@
12268 int linenr;
12269
12270 if (objPtr->typePtr == &listObjType) {
12271 return JIM_OK;
12272 }
12273
12274
12275 if (Jim_IsDict(objPtr) && objPtr->bytes == NULL) {
12276 Jim_Dict *dict = objPtr->internalRep.dictValue;
 
 
 
 
 
 
 
12277
12278
 
12279 objPtr->typePtr = &listObjType;
12280 objPtr->internalRep.listValue.len = dict->len;
12281 objPtr->internalRep.listValue.maxLen = dict->maxLen;
12282 objPtr->internalRep.listValue.ele = dict->table;
12283
12284
12285 Jim_Free(dict->ht);
12286
12287
12288 Jim_Free(dict);
12289 return JIM_OK;
12290 }
12291
12292
12293 if (objPtr->typePtr == &sourceObjType) {
@@ -11513,12 +12375,12 @@
12375 JIM_LSORT_INTEGER,
12376 JIM_LSORT_REAL,
12377 JIM_LSORT_COMMAND
12378 } type;
12379 int order;
12380 Jim_Obj **indexv;
12381 int indexc;
12382 int unique;
12383 int (*subfn)(Jim_Obj **, Jim_Obj **);
12384 };
12385
12386 static struct lsort_info *sort_info;
@@ -11525,12 +12387,12 @@
12387
12388 static int ListSortIndexHelper(Jim_Obj **lhsObj, Jim_Obj **rhsObj)
12389 {
12390 Jim_Obj *lObj, *rObj;
12391
12392 if (Jim_ListIndices(sort_info->interp, *lhsObj, sort_info->indexv, sort_info->indexc, &lObj, JIM_ERRMSG) != JIM_OK ||
12393 Jim_ListIndices(sort_info->interp, *rhsObj, sort_info->indexv, sort_info->indexc, &rObj, JIM_ERRMSG) != JIM_OK) {
12394 longjmp(sort_info->jmpbuf, JIM_ERR);
12395 }
12396 return sort_info->subfn(&lObj, &rObj);
12397 }
12398
@@ -11663,11 +12525,11 @@
12525 fn = NULL;
12526 JimPanic((1, "ListSort called with invalid sort type"));
12527 return -1;
12528 }
12529
12530 if (info->indexc) {
12531
12532 info->subfn = fn;
12533 fn = ListSortIndexHelper;
12534 }
12535
@@ -11683,30 +12545,39 @@
12545 sort_info = prev_info;
12546
12547 return rc;
12548 }
12549
12550
12551 static void ListEnsureLength(Jim_Obj *listPtr, int idx)
12552 {
12553 assert(idx >= 0);
12554 if (idx >= listPtr->internalRep.listValue.maxLen) {
12555 if (idx < 4) {
12556
12557 idx = 4;
12558 }
12559 listPtr->internalRep.listValue.ele = Jim_Realloc(listPtr->internalRep.listValue.ele,
12560 sizeof(Jim_Obj *) * idx);
12561
12562 listPtr->internalRep.listValue.maxLen = idx;
12563 }
12564 }
12565
12566 static void ListInsertElements(Jim_Obj *listPtr, int idx, int elemc, Jim_Obj *const *elemVec)
12567 {
12568 int currentLen = listPtr->internalRep.listValue.len;
12569 int requiredLen = currentLen + elemc;
12570 int i;
12571 Jim_Obj **point;
12572
12573 if (requiredLen > listPtr->internalRep.listValue.maxLen) {
12574 if (currentLen) {
12575
 
 
 
12576 requiredLen *= 2;
12577 }
12578 ListEnsureLength(listPtr, requiredLen);
 
 
 
 
12579 }
12580 if (idx < 0) {
12581 idx = currentLen;
12582 }
12583 point = listPtr->internalRep.listValue.ele + idx;
@@ -11786,10 +12657,51 @@
12657 }
12658 return JIM_ERR;
12659 }
12660 return JIM_OK;
12661 }
12662
12663 static int Jim_ListIndices(Jim_Interp *interp, Jim_Obj *listPtr,
12664 Jim_Obj *const *indexv, int indexc, Jim_Obj **resultObj, int flags)
12665 {
12666 int i;
12667 int static_idxes[5];
12668 int *idxes = static_idxes;
12669 int ret = JIM_OK;
12670
12671 if (indexc > sizeof(static_idxes) / sizeof(*static_idxes)) {
12672 idxes = Jim_Alloc(indexc * sizeof(*idxes));
12673 }
12674
12675 for (i = 0; i < indexc; i++) {
12676 ret = Jim_GetIndex(interp, indexv[i], &idxes[i]);
12677 if (ret != JIM_OK) {
12678 goto err;
12679 }
12680 }
12681
12682 for (i = 0; i < indexc; i++) {
12683 Jim_Obj *objPtr = Jim_ListGetIndex(interp, listPtr, idxes[i]);
12684 if (!objPtr) {
12685 if (flags & JIM_ERRMSG) {
12686 if (idxes[i] < 0 || idxes[i] > Jim_ListLength(interp, listPtr)) {
12687 Jim_SetResultFormatted(interp, "index \"%#s\" out of range", indexv[i]);
12688 }
12689 else {
12690 Jim_SetResultFormatted(interp, "element %#s missing from sublist \"%#s\"", indexv[i], listPtr);
12691 }
12692 }
12693 return -1;
12694 }
12695 listPtr = objPtr;
12696 }
12697 *resultObj = listPtr;
12698 err:
12699 if (idxes != static_idxes)
12700 Jim_Free(idxes);
12701 return ret;
12702 }
12703
12704 static int ListSetIndex(Jim_Interp *interp, Jim_Obj *listPtr, int idx,
12705 Jim_Obj *newObjPtr, int flags)
12706 {
12707 SetListFromAny(interp, listPtr);
@@ -11821,11 +12733,14 @@
12733 varObjPtr = objPtr = Jim_DuplicateObj(interp, objPtr);
12734 for (i = 0; i < indexc - 1; i++) {
12735 listObjPtr = objPtr;
12736 if (Jim_GetIndex(interp, indexv[i], &idx) != JIM_OK)
12737 goto err;
12738
12739 objPtr = Jim_ListGetIndex(interp, listObjPtr, idx);
12740 if (objPtr == NULL) {
12741 Jim_SetResultFormatted(interp, "index \"%#s\" out of range", indexv[i]);
12742 goto err;
12743 }
12744 if (Jim_IsShared(objPtr)) {
12745 objPtr = Jim_DuplicateObj(interp, objPtr);
12746 ListSetIndex(interp, listObjPtr, idx, objPtr, JIM_NONE);
@@ -11948,112 +12863,186 @@
12863 static void DupDictInternalRep(Jim_Interp *interp, Jim_Obj *srcPtr, Jim_Obj *dupPtr);
12864 static void UpdateStringOfDict(struct Jim_Obj *objPtr);
12865 static int SetDictFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr);
12866
12867
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12868 static const Jim_ObjType dictObjType = {
12869 "dict",
12870 FreeDictInternalRep,
12871 DupDictInternalRep,
12872 UpdateStringOfDict,
12873 JIM_TYPE_NONE,
12874 };
12875
12876 static void JimFreeDict(Jim_Interp *interp, Jim_Dict *dict)
12877 {
12878 int i;
12879 for (i = 0; i < dict->len; i++) {
12880 Jim_DecrRefCount(interp, dict->table[i]);
12881 }
12882 Jim_Free(dict->table);
12883 Jim_Free(dict->ht);
12884 Jim_Free(dict);
12885 }
12886
12887 enum {
12888 DICT_HASH_FIND = -1,
12889 DICT_HASH_REMOVE = -2,
12890 DICT_HASH_ADD = -3,
12891 };
12892
12893 static int JimDictHashFind(Jim_Dict *dict, Jim_Obj *keyObjPtr, int op_tvoffset)
12894 {
12895 unsigned h = (JimObjectHTHashFunction(keyObjPtr) + dict->uniq);
12896 unsigned idx = h & dict->sizemask;
12897 int tvoffset = 0;
12898 unsigned peturb = h;
12899 unsigned first_removed = ~0;
12900
12901 if (dict->len) {
12902 while ((tvoffset = dict->ht[idx].offset)) {
12903 if (tvoffset == -1) {
12904 if (first_removed == ~0) {
12905 first_removed = idx;
12906 }
12907 }
12908 else if (dict->ht[idx].hash == h) {
12909 if (Jim_StringEqObj(keyObjPtr, dict->table[tvoffset - 1])) {
12910 break;
12911 }
12912 }
12913
12914 peturb >>= 5;
12915 idx = (5 * idx + 1 + peturb) & dict->sizemask;
12916 }
12917 }
12918
12919 switch (op_tvoffset) {
12920 case DICT_HASH_FIND:
12921
12922 break;
12923 case DICT_HASH_REMOVE:
12924 if (tvoffset) {
12925
12926 dict->ht[idx].offset = -1;
12927 dict->dummy++;
12928 }
12929
12930 break;
12931 case DICT_HASH_ADD:
12932 if (tvoffset == 0) {
12933
12934 if (first_removed != ~0) {
12935 idx = first_removed;
12936 dict->dummy--;
12937 }
12938 dict->ht[idx].offset = dict->len + 1;
12939 dict->ht[idx].hash = h;
12940 }
12941
12942 break;
12943 default:
12944 assert(tvoffset);
12945
12946 dict->ht[idx].offset = op_tvoffset;
12947 break;
12948 }
12949
12950 return tvoffset;
12951 }
12952
12953 static void JimDictExpandHashTable(Jim_Dict *dict, unsigned int size)
12954 {
12955 int i;
12956 struct JimDictHashEntry *prevht = dict->ht;
12957 int prevsize = dict->size;
12958
12959 dict->size = JimHashTableNextPower(size);
12960 dict->sizemask = dict->size - 1;
12961
12962
12963 dict->ht = Jim_Alloc(dict->size * sizeof(*dict->ht));
12964 memset(dict->ht, 0, dict->size * sizeof(*dict->ht));
12965
12966
12967 for (i = 0; i < prevsize; i++) {
12968 if (prevht[i].offset > 0) {
12969
12970 unsigned h = prevht[i].hash;
12971 unsigned idx = h & dict->sizemask;
12972 unsigned peturb = h;
12973
12974 while (dict->ht[idx].offset) {
12975 peturb >>= 5;
12976 idx = (5 * idx + 1 + peturb) & dict->sizemask;
12977 }
12978 dict->ht[idx].offset = prevht[i].offset;
12979 dict->ht[idx].hash = h;
12980 }
12981 }
12982 Jim_Free(prevht);
12983 }
12984
12985 static int JimDictAdd(Jim_Dict *dict, Jim_Obj *keyObjPtr)
12986 {
12987 if (dict->size <= dict->len + dict->dummy) {
12988 JimDictExpandHashTable(dict, dict->size ? dict->size * 2 : 8);
12989 }
12990 return JimDictHashFind(dict, keyObjPtr, DICT_HASH_ADD);
12991 }
12992
12993 static Jim_Dict *JimDictNew(Jim_Interp *interp, int table_size, int ht_size)
12994 {
12995 Jim_Dict *dict = Jim_Alloc(sizeof(*dict));
12996 memset(dict, 0, sizeof(*dict));
12997
12998 if (ht_size) {
12999 JimDictExpandHashTable(dict, ht_size);
13000 }
13001 if (table_size) {
13002 dict->table = Jim_Alloc(table_size * sizeof(*dict->table));
13003 dict->maxLen = table_size;
13004 }
13005 #ifdef JIM_RANDOMISE_HASH
13006 dict->uniq = (rand() ^ time(NULL) ^ clock());
13007 #endif
13008 return dict;
13009 }
13010
13011 static void FreeDictInternalRep(Jim_Interp *interp, Jim_Obj *objPtr)
13012 {
13013 JimFreeDict(interp, objPtr->internalRep.dictValue);
13014 }
13015
13016 static void DupDictInternalRep(Jim_Interp *interp, Jim_Obj *srcPtr, Jim_Obj *dupPtr)
13017 {
13018 Jim_Dict *oldDict = srcPtr->internalRep.dictValue;
13019 int i;
13020
13021
13022 Jim_Dict *newDict = JimDictNew(interp, oldDict->maxLen, oldDict->size);
13023
13024
13025 for (i = 0; i < oldDict->len; i++) {
13026 newDict->table[i] = oldDict->table[i];
13027 Jim_IncrRefCount(newDict->table[i]);
13028 }
13029 newDict->len = oldDict->len;
13030
13031
13032 newDict->uniq = oldDict->uniq;
13033
13034
13035 memcpy(newDict->ht, oldDict->ht, sizeof(*oldDict->ht) * oldDict->size);
13036
13037 dupPtr->internalRep.dictValue = newDict;
13038 dupPtr->typePtr = &dictObjType;
13039 }
13040
13041 static void UpdateStringOfDict(struct Jim_Obj *objPtr)
13042 {
13043 JimMakeListStringRep(objPtr, objPtr->internalRep.dictValue->table, objPtr->internalRep.dictValue->len);
 
 
 
 
 
 
 
13044 }
13045
13046 static int SetDictFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr)
13047 {
13048 int listlen;
@@ -12064,34 +13053,49 @@
13053
13054 if (Jim_IsList(objPtr) && Jim_IsShared(objPtr)) {
13055 Jim_String(objPtr);
13056 }
13057
 
13058 listlen = Jim_ListLength(interp, objPtr);
13059 if (listlen % 2) {
13060 Jim_SetResultString(interp, "missing value to go with key", -1);
13061 return JIM_ERR;
13062 }
13063 else {
13064
13065 Jim_Dict *dict = JimDictNew(interp, 0, listlen);
13066 int i;
13067
13068
13069 dict->table = objPtr->internalRep.listValue.ele;
13070 dict->maxLen = objPtr->internalRep.listValue.maxLen;
13071
13072
13073 for (i = 0; i < listlen; i += 2) {
13074 int tvoffset = JimDictAdd(dict, dict->table[i]);
13075 if (tvoffset) {
13076
13077
13078 Jim_DecrRefCount(interp, dict->table[tvoffset]);
13079
13080 dict->table[tvoffset] = dict->table[i + 1];
13081
13082 Jim_DecrRefCount(interp, dict->table[i]);
13083 }
13084 else {
13085 if (dict->len != i) {
13086 dict->table[dict->len++] = dict->table[i];
13087 dict->table[dict->len++] = dict->table[i + 1];
13088 }
13089 else {
13090 dict->len += 2;
13091 }
13092 }
13093 }
13094
 
13095 objPtr->typePtr = &dictObjType;
13096 objPtr->internalRep.dictValue = dict;
13097
13098 return JIM_OK;
13099 }
13100 }
13101
@@ -12098,17 +13102,60 @@
13102
13103
13104 static int DictAddElement(Jim_Interp *interp, Jim_Obj *objPtr,
13105 Jim_Obj *keyObjPtr, Jim_Obj *valueObjPtr)
13106 {
13107 Jim_Dict *dict = objPtr->internalRep.dictValue;
 
13108 if (valueObjPtr == NULL) {
13109
13110 int tvoffset = JimDictHashFind(dict, keyObjPtr, DICT_HASH_REMOVE);
13111 if (tvoffset) {
13112
13113 Jim_DecrRefCount(interp, dict->table[tvoffset - 1]);
13114 Jim_DecrRefCount(interp, dict->table[tvoffset]);
13115 dict->len -= 2;
13116 if (tvoffset != dict->len + 1) {
13117
13118 dict->table[tvoffset - 1] = dict->table[dict->len];
13119 dict->table[tvoffset] = dict->table[dict->len + 1];
13120
13121
13122 JimDictHashFind(dict, dict->table[tvoffset - 1], tvoffset);
13123 }
13124 return JIM_OK;
13125 }
13126 return JIM_ERR;
13127 }
13128 else {
13129
13130 int tvoffset = JimDictAdd(dict, keyObjPtr);
13131 if (tvoffset) {
13132
13133 Jim_IncrRefCount(valueObjPtr);
13134 Jim_DecrRefCount(interp, dict->table[tvoffset]);
13135 dict->table[tvoffset] = valueObjPtr;
13136 }
13137 else {
13138 if (dict->maxLen == dict->len) {
13139
13140 if (dict->maxLen < 4) {
13141 dict->maxLen = 4;
13142 }
13143 else {
13144 dict->maxLen *= 2;
13145 }
13146 dict->table = Jim_Realloc(dict->table, dict->maxLen * sizeof(*dict->table));
13147 }
13148 Jim_IncrRefCount(keyObjPtr);
13149 Jim_IncrRefCount(valueObjPtr);
13150
13151 dict->table[dict->len++] = keyObjPtr;
13152 dict->table[dict->len++] = valueObjPtr;
13153
13154 }
13155 return JIM_OK;
13156 }
13157 }
13158
13159 int Jim_DictAddElement(Jim_Interp *interp, Jim_Obj *objPtr,
13160 Jim_Obj *keyObjPtr, Jim_Obj *valueObjPtr)
13161 {
@@ -12128,50 +13175,57 @@
13175 JimPanic((len % 2, "Jim_NewDictObj() 'len' argument must be even"));
13176
13177 objPtr = Jim_NewObj(interp);
13178 objPtr->typePtr = &dictObjType;
13179 objPtr->bytes = NULL;
13180
13181 objPtr->internalRep.dictValue = JimDictNew(interp, len, len);
13182 for (i = 0; i < len; i += 2)
13183 DictAddElement(interp, objPtr, elements[i], elements[i + 1]);
13184 return objPtr;
13185 }
13186
13187 int Jim_DictKey(Jim_Interp *interp, Jim_Obj *dictPtr, Jim_Obj *keyPtr,
13188 Jim_Obj **objPtrPtr, int flags)
13189 {
13190 int tvoffset;
13191 Jim_Dict *dict;
13192
13193 if (SetDictFromAny(interp, dictPtr) != JIM_OK) {
13194 return -1;
13195 }
13196 dict = dictPtr->internalRep.dictValue;
13197 tvoffset = JimDictHashFind(dict, keyPtr, DICT_HASH_FIND);
13198 if (tvoffset == 0) {
13199 if (flags & JIM_ERRMSG) {
13200 Jim_SetResultFormatted(interp, "key \"%#s\" not known in dictionary", keyPtr);
13201 }
13202 return JIM_ERR;
13203 }
13204 *objPtrPtr = dict->table[tvoffset];
13205 return JIM_OK;
 
 
13206 }
13207
13208 Jim_Obj **Jim_DictPairs(Jim_Interp *interp, Jim_Obj *dictPtr, int *len)
13209 {
13210
13211 if (Jim_IsList(dictPtr)) {
13212 Jim_Obj **table;
13213 JimListGetElements(interp, dictPtr, len, &table);
13214 if (*len % 2 == 0) {
13215 return table;
13216 }
13217
13218 }
13219 if (SetDictFromAny(interp, dictPtr) != JIM_OK) {
13220
13221 *len = 1;
13222 return NULL;
13223 }
13224 *len = dictPtr->internalRep.dictValue->len;
13225 return dictPtr->internalRep.dictValue->table;
 
13226 }
 
13227
13228
13229 int Jim_DictKeysVector(Jim_Interp *interp, Jim_Obj *dictPtr,
13230 Jim_Obj *const *keyv, int keyc, Jim_Obj **objPtrPtr, int flags)
13231 {
@@ -12254,11 +13308,14 @@
13308 Jim_InvalidateStringRep(objPtr);
13309 Jim_InvalidateStringRep(varObjPtr);
13310 if (Jim_SetVariable(interp, varNamePtr, varObjPtr) != JIM_OK) {
13311 goto err;
13312 }
13313
13314 if (!(flags & JIM_NORESULT)) {
13315 Jim_SetResult(interp, varObjPtr);
13316 }
13317 return JIM_OK;
13318 err:
13319 if (shared) {
13320 Jim_FreeNewObj(interp, varObjPtr);
13321 }
@@ -12281,11 +13338,11 @@
13338 if (objPtr->internalRep.intValue == -1) {
13339 JimSetStringBytes(objPtr, "end");
13340 }
13341 else {
13342 char buf[JIM_INTEGER_SPACE + 1];
13343 if (objPtr->internalRep.intValue >= 0 || objPtr->internalRep.intValue == -INT_MAX) {
13344 sprintf(buf, "%d", objPtr->internalRep.intValue);
13345 }
13346 else {
13347
13348 sprintf(buf, "end%d", objPtr->internalRep.intValue + 1);
@@ -12294,49 +13351,49 @@
13351 }
13352 }
13353
13354 static int SetIndexFromAny(Jim_Interp *interp, Jim_Obj *objPtr)
13355 {
13356 jim_wide idx;
13357 int end = 0;
13358 const char *str;
13359 Jim_Obj *exprObj = objPtr;
13360
13361 JimPanic((objPtr->refCount == 0, "SetIndexFromAny() called with zero refcount object"));
13362
13363
13364 str = Jim_String(objPtr);
13365
13366
13367 if (strncmp(str, "end", 3) == 0) {
13368 end = 1;
13369 str += 3;
13370 idx = 0;
13371 switch (*str) {
13372 case '\0':
13373 exprObj = NULL;
13374 break;
13375
13376 case '-':
13377 case '+':
13378 exprObj = Jim_NewStringObj(interp, str, -1);
13379 break;
13380
13381 default:
13382 goto badindex;
13383 }
13384 }
13385 if (exprObj) {
13386 int ret;
13387 Jim_IncrRefCount(exprObj);
13388 ret = Jim_GetWideExpr(interp, exprObj, &idx);
13389 Jim_DecrRefCount(interp, exprObj);
13390 if (ret != JIM_OK) {
13391 goto badindex;
13392 }
13393 }
13394
 
 
 
13395 if (end) {
13396 if (idx > 0) {
13397 idx = INT_MAX;
13398 }
13399 else {
@@ -12354,11 +13411,11 @@
13411 objPtr->internalRep.intValue = idx;
13412 return JIM_OK;
13413
13414 badindex:
13415 Jim_SetResultFormatted(interp,
13416 "bad index \"%#s\": must be intexpr or end?[+-]intexpr?", objPtr);
13417 return JIM_ERR;
13418 }
13419
13420 int Jim_GetIndex(Jim_Interp *interp, Jim_Obj *objPtr, int *indexPtr)
13421 {
@@ -12479,10 +13536,14 @@
13536
13537 JIM_EXPROP_STREQ,
13538 JIM_EXPROP_STRNE,
13539 JIM_EXPROP_STRIN,
13540 JIM_EXPROP_STRNI,
13541 JIM_EXPROP_STRLT,
13542 JIM_EXPROP_STRGT,
13543 JIM_EXPROP_STRLE,
13544 JIM_EXPROP_STRGE,
13545
13546
13547 JIM_EXPROP_NOT,
13548 JIM_EXPROP_BITNOT,
13549 JIM_EXPROP_UNARYMINUS,
@@ -12544,11 +13605,11 @@
13605 static int JimExprEvalTermNode(Jim_Interp *interp, struct JimExprNode *node);
13606
13607 static int JimExprOpNumUnary(Jim_Interp *interp, struct JimExprNode *node)
13608 {
13609 int intresult = 1;
13610 int rc, bA = 0;
13611 double dA, dC = 0;
13612 jim_wide wA, wC = 0;
13613 Jim_Obj *A;
13614
13615 if ((rc = JimExprGetTerm(interp, node->left, &A)) != JIM_OK) {
@@ -12611,10 +13672,19 @@
13672 break;
13673 default:
13674 abort();
13675 }
13676 }
13677 else if ((rc = Jim_GetBoolean(interp, A, &bA)) == JIM_OK) {
13678 switch (node->type) {
13679 case JIM_EXPROP_NOT:
13680 wC = !bA;
13681 break;
13682 default:
13683 abort();
13684 }
13685 }
13686
13687 if (rc == JIM_OK) {
13688 if (intresult) {
13689 Jim_SetResultInt(interp, wC);
13690 }
@@ -12631,11 +13701,11 @@
13701 static double JimRandDouble(Jim_Interp *interp)
13702 {
13703 unsigned long x;
13704 JimRandomBytes(interp, &x, sizeof(x));
13705
13706 return (double)x / (double)~0UL;
13707 }
13708
13709 static int JimExprOpIntUnary(Jim_Interp *interp, struct JimExprNode *node)
13710 {
13711 jim_wide wA;
@@ -13040,11 +14110,11 @@
14110
14111 static int JimExprOpStrBin(Jim_Interp *interp, struct JimExprNode *node)
14112 {
14113 Jim_Obj *A, *B;
14114 jim_wide wC;
14115 int comp, rc;
14116
14117 if ((rc = JimExprGetTerm(interp, node->left, &A)) != JIM_OK) {
14118 return rc;
14119 }
14120 if ((rc = JimExprGetTerm(interp, node->right, &B)) != JIM_OK) {
@@ -13057,10 +14127,25 @@
14127 case JIM_EXPROP_STRNE:
14128 wC = Jim_StringEqObj(A, B);
14129 if (node->type == JIM_EXPROP_STRNE) {
14130 wC = !wC;
14131 }
14132 break;
14133 case JIM_EXPROP_STRLT:
14134 case JIM_EXPROP_STRGT:
14135 case JIM_EXPROP_STRLE:
14136 case JIM_EXPROP_STRGE:
14137 comp = Jim_StringCompareObj(interp, A, B, 0);
14138 if (node->type == JIM_EXPROP_STRLT) {
14139 wC = comp == -1;
14140 } else if (node->type == JIM_EXPROP_STRGT) {
14141 wC = comp == 1;
14142 } else if (node->type == JIM_EXPROP_STRLE) {
14143 wC = comp == -1 || comp == 0;
14144 } else {
14145 wC = comp == 0 || comp == 1;
14146 }
14147 break;
14148 case JIM_EXPROP_STRIN:
14149 wC = JimSearchList(interp, B, A);
14150 break;
14151 case JIM_EXPROP_STRNI:
@@ -13196,10 +14281,15 @@
14281 OPRINIT("eq", 60, 2, JimExprOpStrBin),
14282 OPRINIT("ne", 60, 2, JimExprOpStrBin),
14283
14284 OPRINIT("in", 55, 2, JimExprOpStrBin),
14285 OPRINIT("ni", 55, 2, JimExprOpStrBin),
14286
14287 OPRINIT("lt", 75, 2, JimExprOpStrBin),
14288 OPRINIT("gt", 75, 2, JimExprOpStrBin),
14289 OPRINIT("le", 75, 2, JimExprOpStrBin),
14290 OPRINIT("ge", 75, 2, JimExprOpStrBin),
14291
14292 OPRINIT_ATTR("!", 150, 1, JimExprOpNumUnary, OP_RIGHT_ASSOC),
14293 OPRINIT_ATTR("~", 150, 1, JimExprOpIntUnary, OP_RIGHT_ASSOC),
14294 OPRINIT_ATTR(" -", 150, 1, JimExprOpNumUnary, OP_RIGHT_ASSOC),
14295 OPRINIT_ATTR(" +", 150, 1, JimExprOpNumUnary, OP_RIGHT_ASSOC),
@@ -13242,17 +14332,26 @@
14332 #define JIM_EXPR_OPERATORS_NUM \
14333 (sizeof(Jim_ExprOperators)/sizeof(struct Jim_ExprOperator))
14334
14335 static int JimParseExpression(struct JimParserCtx *pc)
14336 {
14337 while (1) {
14338
14339 while (isspace(UCHAR(*pc->p)) || (*(pc->p) == '\\' && *(pc->p + 1) == '\n')) {
14340 if (*pc->p == '\n') {
14341 pc->linenr++;
14342 }
14343 pc->p++;
14344 pc->len--;
14345 }
14346
14347 if (*pc->p == '#') {
14348 JimParseComment(pc);
14349
14350 continue;
14351 }
14352 break;
14353 }
14354
14355
14356 pc->tline = pc->linenr;
14357 pc->tstart = pc->p;
@@ -13372,21 +14471,15 @@
14471 return JIM_ERR;
14472 }
14473
14474 static int JimParseExprBoolean(struct JimParserCtx *pc)
14475 {
 
 
14476 int i;
14477 for (i = 0; i < sizeof(jim_true_false_strings) / sizeof(*jim_true_false_strings); i++) {
14478 if (strncmp(pc->p, jim_true_false_strings[i], jim_true_false_lens[i]) == 0) {
14479 pc->p += jim_true_false_lens[i];
14480 pc->len -= jim_true_false_lens[i];
 
 
 
 
14481 pc->tend = pc->p - 1;
14482 pc->tt = JIM_TT_EXPR_BOOLEAN;
14483 return JIM_OK;
14484 }
14485 }
@@ -13479,11 +14572,11 @@
14572 static const Jim_ObjType exprObjType = {
14573 "expression",
14574 FreeExprInternalRep,
14575 DupExprInternalRep,
14576 NULL,
14577 JIM_TYPE_NONE,
14578 };
14579
14580
14581 struct ExprTree
14582 {
@@ -13571,12 +14664,11 @@
14664
14665 #define EXPR_UNTIL_CLOSE 0x0001
14666 #define EXPR_FUNC_ARGS 0x0002
14667 #define EXPR_TERNARY 0x0004
14668
14669 static int ExprTreeBuildTree(Jim_Interp *interp, struct ExprBuilder *builder, int precedence, int flags, int exp_numterms) {
 
14670 int rc;
14671 struct JimExprNode *node;
14672
14673 int exp_stacklen = builder->stack.len + exp_numterms;
14674
@@ -13826,11 +14918,11 @@
14918 builder.level = 0;
14919 builder.token = builder.first_token = tokenlist->list;
14920 builder.exprObjPtr = exprObjPtr;
14921 builder.fileNameObj = fileNameObj;
14922
14923 builder.nodes = Jim_Alloc(sizeof(struct JimExprNode) * (tokenlist->count - 1));
14924 memset(builder.nodes, 0, sizeof(struct JimExprNode) * (tokenlist->count - 1));
14925 builder.next = builder.nodes;
14926 Jim_InitStack(&builder.stack);
14927
14928 rc = ExprTreeBuildTree(interp, &builder, 0, 0, 1);
@@ -14004,17 +15096,23 @@
15096 return JIM_OK;
15097 }
15098 return JIM_ERR;
15099
15100 case JIM_TT_ESC:
15101 if (interp->safeexpr) {
15102 return JIM_ERR;
15103 }
15104 if (Jim_SubstObj(interp, node->objPtr, &objPtr, JIM_NONE) == JIM_OK) {
15105 Jim_SetResult(interp, objPtr);
15106 return JIM_OK;
15107 }
15108 return JIM_ERR;
15109
15110 case JIM_TT_CMD:
15111 if (interp->safeexpr) {
15112 return JIM_ERR;
15113 }
15114 return Jim_EvalObj(interp, node->objPtr);
15115
15116 default:
15117
15118 return JIM_ERR;
@@ -14043,36 +15141,38 @@
15141 int Jim_EvalExpression(Jim_Interp *interp, Jim_Obj *exprObjPtr)
15142 {
15143 struct ExprTree *expr;
15144 int retcode = JIM_OK;
15145
15146 Jim_IncrRefCount(exprObjPtr);
15147 expr = JimGetExpression(interp, exprObjPtr);
15148 if (!expr) {
15149 retcode = JIM_ERR;
15150 goto done;
15151 }
15152
15153 #ifdef JIM_OPTIMIZATION
15154 if (!interp->safeexpr) {
15155 Jim_Obj *objPtr;
15156
15157
15158 switch (expr->len) {
15159 case 1:
15160 objPtr = JimExprIntValOrVar(interp, expr->expr);
15161 if (objPtr) {
15162 Jim_SetResult(interp, objPtr);
15163 goto done;
15164 }
15165 break;
15166
15167 case 2:
15168 if (expr->expr->type == JIM_EXPROP_NOT) {
15169 objPtr = JimExprIntValOrVar(interp, expr->expr->left);
15170
15171 if (objPtr && JimIsWide(objPtr)) {
15172 Jim_SetResult(interp, JimWideValue(objPtr) ? interp->falseObj : interp->trueObj);
15173 goto done;
15174 }
15175 }
15176 break;
15177
15178 case 3:
@@ -14104,11 +15204,11 @@
15204 break;
15205 default:
15206 goto noopt;
15207 }
15208 Jim_SetResult(interp, cmpRes ? interp->trueObj : interp->falseObj);
15209 goto done;
15210 }
15211 }
15212 break;
15213 }
15214 }
@@ -14118,11 +15218,17 @@
15218 expr->inUse++;
15219
15220
15221 retcode = JimExprEvalTermNode(interp, expr->expr);
15222
15223
15224 Jim_FreeIntRep(interp, exprObjPtr);
15225 exprObjPtr->typePtr = &exprObjType;
15226 Jim_SetIntRepPtr(exprObjPtr, expr);
15227
15228 done:
15229 Jim_DecrRefCount(interp, exprObjPtr);
15230
15231 return retcode;
15232 }
15233
15234 int Jim_GetBoolFromExpr(Jim_Interp *interp, Jim_Obj *exprObjPtr, int *boolPtr)
@@ -14405,21 +15511,21 @@
15511
15512 if (!sdescr && isspace(UCHAR(*str)))
15513 break;
15514
15515 n = utf8_tounicode(str, &c);
15516 if (sdescr && !JimCharsetMatch(sdescr, strlen(sdescr), c, JIM_CHARSET_SCAN))
15517 break;
15518 while (n--)
15519 *p++ = *str++;
15520 }
15521 *p = 0;
15522 return Jim_NewStringObjNoAlloc(interp, buffer, p - buffer);
15523 }
15524
15525
15526 static int ScanOneEntry(Jim_Interp *interp, const char *str, int pos, int str_bytelen,
15527 ScanFmtStringObj * fmtObj, long idx, Jim_Obj **valObjPtr)
15528 {
15529 const char *tok;
15530 const ScanFmtPartDescr *descr = &fmtObj->descr[idx];
15531 size_t scanned = 0;
@@ -14428,52 +15534,53 @@
15534 Jim_Obj *tmpObj = NULL;
15535
15536
15537 *valObjPtr = 0;
15538 if (descr->prefix) {
15539 for (i = 0; pos < str_bytelen && descr->prefix[i]; ++i) {
15540
15541 if (isspace(UCHAR(descr->prefix[i])))
15542 while (pos < str_bytelen && isspace(UCHAR(str[pos])))
15543 ++pos;
15544 else if (descr->prefix[i] != str[pos])
15545 break;
15546 else
15547 ++pos;
15548 }
15549 if (pos >= str_bytelen) {
15550 return -1;
15551 }
15552 else if (descr->prefix[i] != 0)
15553 return 0;
15554 }
15555
15556 if (descr->type != 'c' && descr->type != '[' && descr->type != 'n')
15557 while (isspace(UCHAR(str[pos])))
15558 ++pos;
15559
15560
15561 scanned = pos - anchor;
15562
15563
15564 if (descr->type == 'n') {
15565
15566 *valObjPtr = Jim_NewIntObj(interp, anchor + scanned);
15567 }
15568 else if (pos >= str_bytelen) {
15569
15570 return -1;
15571 }
15572 else if (descr->type == 'c') {
15573 int c;
15574 scanned += utf8_tounicode(&str[pos], &c);
15575 *valObjPtr = Jim_NewIntObj(interp, c);
15576 return scanned;
15577 }
15578 else {
15579
15580 if (descr->width > 0) {
15581 size_t sLen = utf8_strlen(&str[pos], str_bytelen - pos);
15582 size_t tLen = descr->width > sLen ? sLen : descr->width;
15583
15584 tmpObj = Jim_NewStringObjUtf8(interp, str + pos, tLen);
15585 tok = tmpObj->bytes;
15586 }
@@ -14548,11 +15655,11 @@
15655 Jim_Obj *Jim_ScanString(Jim_Interp *interp, Jim_Obj *strObjPtr, Jim_Obj *fmtObjPtr, int flags)
15656 {
15657 size_t i, pos;
15658 int scanned = 1;
15659 const char *str = Jim_String(strObjPtr);
15660 int str_bytelen = Jim_Length(strObjPtr);
15661 Jim_Obj *resultList = 0;
15662 Jim_Obj **resultVec = 0;
15663 int resultc;
15664 Jim_Obj *emptyStr = 0;
15665 ScanFmtStringObj *fmtObj;
@@ -14585,11 +15692,11 @@
15692
15693 if (descr->type == 0)
15694 continue;
15695
15696 if (scanned > 0)
15697 scanned = ScanOneEntry(interp, str, pos, str_bytelen, fmtObj, i, &value);
15698
15699 if (scanned == -1 && i == 0)
15700 goto eof;
15701
15702 pos += scanned;
@@ -14707,11 +15814,11 @@
15814 if (argc != 2 && argc != 3) {
15815 Jim_WrongNumArgs(interp, 1, argv, "varName ?increment?");
15816 return JIM_ERR;
15817 }
15818 if (argc == 3) {
15819 if (Jim_GetWideExpr(interp, argv[2], &increment) != JIM_OK)
15820 return JIM_ERR;
15821 }
15822 intObjPtr = Jim_GetVariable(interp, argv[1], JIM_UNSHARED);
15823 if (!intObjPtr) {
15824
@@ -14743,10 +15850,49 @@
15850
15851
15852 #define JIM_EVAL_SARGV_LEN 8
15853 #define JIM_EVAL_SINTV_LEN 8
15854
15855 static int JimTraceCallback(Jim_Interp *interp, const char *type, int argc, Jim_Obj *const *argv)
15856 {
15857 JimPanic((interp->traceCmdObj == NULL, "xtrace invoked with no object"));
15858
15859 int ret;
15860 Jim_Obj *nargv[7];
15861 Jim_Obj *traceCmdObj = interp->traceCmdObj;
15862 Jim_Obj *resultObj = Jim_GetResult(interp);
15863
15864 ScriptObj *script = JimGetScript(interp, interp->evalFrame->scriptObj);
15865
15866 nargv[0] = traceCmdObj;
15867 nargv[1] = Jim_NewStringObj(interp, type, -1);
15868 nargv[2] = script->fileNameObj;
15869 nargv[3] = Jim_NewIntObj(interp, script->linenr);
15870 nargv[4] = resultObj;
15871 nargv[5] = argv[0];
15872 nargv[6] = Jim_NewListObj(interp, argv + 1, argc - 1);
15873
15874
15875 interp->traceCmdObj = NULL;
15876
15877 Jim_IncrRefCount(resultObj);
15878 ret = Jim_EvalObjVector(interp, 7, nargv);
15879 Jim_DecrRefCount(interp, resultObj);
15880
15881 if (ret == JIM_OK || ret == JIM_RETURN) {
15882
15883 interp->traceCmdObj = traceCmdObj;
15884 Jim_SetEmptyResult(interp);
15885 ret = JIM_OK;
15886 }
15887 else {
15888
15889 Jim_DecrRefCount(interp, traceCmdObj);
15890 }
15891 return ret;
15892 }
15893
15894
15895 static int JimUnknown(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
15896 {
15897 int retcode;
15898
@@ -14764,16 +15910,44 @@
15910 retcode = Jim_EvalObjPrefix(interp, interp->unknown, argc, argv);
15911 interp->unknown_called--;
15912
15913 return retcode;
15914 }
15915
15916 static void JimPushEvalFrame(Jim_Interp *interp, Jim_EvalFrame *frame, Jim_Obj *scriptObj)
15917 {
15918 memset(frame, 0, sizeof(*frame));
15919 frame->parent = interp->evalFrame;
15920 frame->level = frame->parent->level + 1;
15921 frame->procLevel = interp->procLevel;
15922 frame->framePtr = interp->framePtr;
15923 if (scriptObj) {
15924 frame->scriptObj = scriptObj;
15925 }
15926 else {
15927 frame->scriptObj = frame->parent->scriptObj;
15928 }
15929 interp->evalFrame = frame;
15930 #if 0
15931 if (frame->scriptObj) {
15932 printf("script: %.*s\n", 20, Jim_String(frame->scriptObj));
15933 }
15934 #endif
15935 }
15936
15937 static void JimPopEvalFrame(Jim_Interp *interp)
15938 {
15939 interp->evalFrame = interp->evalFrame->parent;
15940 }
15941
15942
15943 static int JimInvokeCommand(Jim_Interp *interp, int objc, Jim_Obj *const *objv)
15944 {
15945 int retcode;
15946 Jim_Cmd *cmdPtr;
15947 void *prevPrivData;
15948 Jim_Obj *tailcallObj = NULL;
15949
15950 #if 0
15951 printf("invoke");
15952 int j;
15953 for (j = 0; j < objc; j++) {
@@ -14780,58 +15954,104 @@
15954 printf(" '%s'", Jim_String(objv[j]));
15955 }
15956 printf("\n");
15957 #endif
15958
15959 cmdPtr = Jim_GetCommand(interp, objv[0], JIM_ERRMSG);
15960 if (cmdPtr == NULL) {
15961 return JimUnknown(interp, objc, objv);
15962 }
15963 JimIncrCmdRefCount(cmdPtr);
 
 
 
 
 
 
 
15964
15965 if (interp->evalDepth == interp->maxEvalDepth) {
15966 Jim_SetResultString(interp, "Infinite eval recursion", -1);
15967 retcode = JIM_ERR;
15968 goto out;
15969 }
15970 interp->evalDepth++;
15971 prevPrivData = interp->cmdPrivData;
15972
15973 tailcall:
15974
15975 interp->evalFrame->argc = objc;
15976 interp->evalFrame->argv = objv;
15977 interp->evalFrame->cmd = cmdPtr;
15978
15979 if (!interp->traceCmdObj ||
15980 (retcode = JimTraceCallback(interp, "cmd", objc, objv)) == JIM_OK) {
15981
15982 Jim_SetEmptyResult(interp);
15983 if (cmdPtr->isproc) {
15984 retcode = JimCallProcedure(interp, cmdPtr, objc, objv);
15985 }
15986 else {
15987 interp->cmdPrivData = cmdPtr->u.native.privData;
15988 retcode = cmdPtr->u.native.cmdProc(interp, objc, objv);
15989 }
15990 if (retcode == JIM_ERR) {
15991 JimSetErrorStack(interp);
15992 }
15993 }
15994
15995 if (tailcallObj) {
15996
15997 Jim_DecrRefCount(interp, tailcallObj);
15998 tailcallObj = NULL;
15999 }
16000
16001
16002 interp->evalFrame->argc = 0;
16003 interp->evalFrame->argv = NULL;
16004
16005
16006 if (retcode == JIM_EVAL && interp->framePtr->tailcallObj) {
16007 JimDecrCmdRefCount(interp, cmdPtr);
16008
16009
16010 cmdPtr = interp->framePtr->tailcallCmd;
16011 interp->framePtr->tailcallCmd = NULL;
16012 tailcallObj = interp->framePtr->tailcallObj;
16013 interp->framePtr->tailcallObj = NULL;
16014 objc = tailcallObj->internalRep.listValue.len;
16015 objv = tailcallObj->internalRep.listValue.ele;
16016 goto tailcall;
16017 }
16018
16019 interp->cmdPrivData = prevPrivData;
16020 interp->evalDepth--;
16021
16022 out:
16023 JimDecrCmdRefCount(interp, cmdPtr);
16024
16025 if (retcode == JIM_ERR) {
16026 JimSetErrorStack(interp);
16027 }
16028
16029 if (interp->framePtr->tailcallObj) {
16030 JimDecrCmdRefCount(interp, interp->framePtr->tailcallCmd);
16031 Jim_DecrRefCount(interp, interp->framePtr->tailcallObj);
16032 interp->framePtr->tailcallCmd = NULL;
16033 interp->framePtr->tailcallObj = NULL;
16034 }
16035
16036 return retcode;
16037 }
16038
16039 int Jim_EvalObjVector(Jim_Interp *interp, int objc, Jim_Obj *const *objv)
16040 {
16041 int i, retcode;
16042 Jim_EvalFrame frame;
16043
16044
16045 for (i = 0; i < objc; i++)
16046 Jim_IncrRefCount(objv[i]);
16047
16048 JimPushEvalFrame(interp, &frame, NULL);
16049
16050 retcode = JimInvokeCommand(interp, objc, objv);
16051
16052 JimPopEvalFrame(interp);
16053
16054
16055 for (i = 0; i < objc; i++)
16056 Jim_DecrRefCount(interp, objv[i]);
16057
@@ -14848,44 +16068,14 @@
16068 ret = Jim_EvalObjVector(interp, objc + 1, nargv);
16069 Jim_Free(nargv);
16070 return ret;
16071 }
16072
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16073 static int JimSubstOneToken(Jim_Interp *interp, const ScriptToken *token, Jim_Obj **objPtrPtr)
16074 {
16075 Jim_Obj *objPtr;
16076 int ret = JIM_ERR;
16077
16078 switch (token->type) {
16079 case JIM_TT_STR:
16080 case JIM_TT_ESC:
16081 objPtr = token->objPtr;
@@ -14895,26 +16085,25 @@
16085 break;
16086 case JIM_TT_DICTSUGAR:
16087 objPtr = JimExpandDictSugar(interp, token->objPtr);
16088 break;
16089 case JIM_TT_EXPRSUGAR:
16090 ret = Jim_EvalExpression(interp, token->objPtr);
16091 if (ret == JIM_OK) {
16092 objPtr = Jim_GetResult(interp);
16093 }
16094 else {
16095 objPtr = NULL;
16096 }
16097 break;
16098 case JIM_TT_CMD:
16099 ret = Jim_EvalObj(interp, token->objPtr);
16100 if (ret == JIM_OK || ret == JIM_RETURN) {
16101 objPtr = interp->result;
16102 } else {
16103
16104 objPtr = NULL;
 
 
 
 
 
 
 
16105 }
16106 break;
16107 default:
16108 JimPanic((1,
16109 "default token type (%d) reached " "in Jim_SubstObj().", token->type));
@@ -14923,11 +16112,11 @@
16112 }
16113 if (objPtr) {
16114 *objPtrPtr = objPtr;
16115 return JIM_OK;
16116 }
16117 return ret;
16118 }
16119
16120 static Jim_Obj *JimInterpolateTokens(Jim_Interp *interp, const ScriptToken * token, int tokens, int flags)
16121 {
16122 int totlen = 0, i;
@@ -15018,20 +16207,26 @@
16207
16208
16209 static int JimEvalObjList(Jim_Interp *interp, Jim_Obj *listPtr)
16210 {
16211 int retcode = JIM_OK;
16212 Jim_EvalFrame frame;
16213
16214 JimPanic((Jim_IsList(listPtr) == 0, "JimEvalObjList() invoked on non-list."));
16215
16216 JimPushEvalFrame(interp, &frame, NULL);
16217
16218 if (listPtr->internalRep.listValue.len) {
16219 Jim_IncrRefCount(listPtr);
16220 retcode = JimInvokeCommand(interp,
16221 listPtr->internalRep.listValue.len,
16222 listPtr->internalRep.listValue.ele);
16223 Jim_DecrRefCount(interp, listPtr);
16224 }
16225
16226 JimPopEvalFrame(interp);
16227
16228 return retcode;
16229 }
16230
16231 int Jim_EvalObjList(Jim_Interp *interp, Jim_Obj *listPtr)
16232 {
@@ -15044,19 +16239,20 @@
16239 int i;
16240 ScriptObj *script;
16241 ScriptToken *token;
16242 int retcode = JIM_OK;
16243 Jim_Obj *sargv[JIM_EVAL_SARGV_LEN], **argv = NULL;
16244 Jim_EvalFrame frame;
16245
16246 if (Jim_IsList(scriptObjPtr) && scriptObjPtr->bytes == NULL) {
16247 return JimEvalObjList(interp, scriptObjPtr);
16248 }
16249
16250 Jim_IncrRefCount(scriptObjPtr);
16251 script = JimGetScript(interp, scriptObjPtr);
16252 if (JimParseCheckMissing(interp, script->missing) == JIM_ERR) {
16253 JimSetErrorStack(interp);
16254 Jim_DecrRefCount(interp, scriptObjPtr);
16255 return JIM_ERR;
16256 }
16257
16258 Jim_SetEmptyResult(interp);
@@ -15086,13 +16282,12 @@
16282 }
16283 #endif
16284
16285 script->inUse++;
16286
16287 JimPushEvalFrame(interp, &frame, scriptObjPtr);
16288
 
 
16289
16290 interp->errorFlag = 0;
16291 argv = sargv;
16292
16293 for (i = 0; i < script->len && retcode == JIM_OK; ) {
@@ -15132,11 +16327,17 @@
16327 break;
16328 case JIM_TT_VAR:
16329 wordObjPtr = Jim_GetVariable(interp, token[i].objPtr, JIM_ERRMSG);
16330 break;
16331 case JIM_TT_EXPRSUGAR:
16332 retcode = Jim_EvalExpression(interp, token[i].objPtr);
16333 if (retcode == JIM_OK) {
16334 wordObjPtr = Jim_GetResult(interp);
16335 }
16336 else {
16337 wordObjPtr = NULL;
16338 }
16339 break;
16340 case JIM_TT_DICTSUGAR:
16341 wordObjPtr = JimExpandDictSugar(interp, token[i].objPtr);
16342 break;
16343 case JIM_TT_CMD:
@@ -15219,20 +16420,14 @@
16420 }
16421 }
16422
16423
16424 if (retcode == JIM_ERR) {
16425 JimSetErrorStack(interp);
16426 }
16427
16428 JimPopEvalFrame(interp);
 
 
 
 
 
 
16429
16430 Jim_FreeIntRep(interp, scriptObjPtr);
16431 scriptObjPtr->typePtr = &scriptObjType;
16432 Jim_SetIntRepPtr(scriptObjPtr, script);
16433 Jim_DecrRefCount(interp, scriptObjPtr);
@@ -15285,11 +16480,11 @@
16480 Jim_AppendObj(interp, argmsg, cmd->u.proc.arglist[i].defaultObjPtr);
16481 Jim_AppendString(interp, argmsg, " ...?", -1);
16482 }
16483 else {
16484
16485 Jim_AppendString(interp, argmsg, "?arg ...?", -1);
16486 }
16487 }
16488 else {
16489 if (cmd->u.proc.arglist[i].defaultObjPtr) {
16490 Jim_AppendString(interp, argmsg, "?", 1);
@@ -15314,17 +16509,15 @@
16509 Jim_CallFrame *callFramePtr;
16510 int retcode;
16511
16512
16513 callFramePtr = JimCreateCallFrame(interp, interp->framePtr, nsObj);
16514 callFramePtr->argv = interp->evalFrame->argv;
16515 callFramePtr->argc = interp->evalFrame->argc;
16516 callFramePtr->procArgsObjPtr = NULL;
16517 callFramePtr->procBodyObjPtr = scriptObj;
16518 callFramePtr->staticVars = NULL;
 
 
16519 Jim_IncrRefCount(scriptObj);
16520 interp->framePtr = callFramePtr;
16521
16522
16523 if (interp->framePtr->level == interp->maxCallFrameDepth) {
@@ -15346,11 +16539,10 @@
16539
16540 static int JimCallProcedure(Jim_Interp *interp, Jim_Cmd *cmd, int argc, Jim_Obj *const *argv)
16541 {
16542 Jim_CallFrame *callFramePtr;
16543 int i, d, retcode, optargs;
 
16544
16545
16546 if (argc - 1 < cmd->u.proc.reqArity ||
16547 (cmd->u.proc.argsPos < 0 && argc - 1 > cmd->u.proc.reqArity + cmd->u.proc.optArity)) {
16548 JimSetProcWrongArgs(interp, argv[0], cmd);
@@ -15374,14 +16566,11 @@
16566 callFramePtr->argc = argc;
16567 callFramePtr->procArgsObjPtr = cmd->u.proc.argListObjPtr;
16568 callFramePtr->procBodyObjPtr = cmd->u.proc.bodyObjPtr;
16569 callFramePtr->staticVars = cmd->u.proc.staticVars;
16570
16571 interp->procLevel++;
 
 
 
16572
16573 Jim_IncrRefCount(cmd->u.proc.argListObjPtr);
16574 Jim_IncrRefCount(cmd->u.proc.bodyObjPtr);
16575 interp->framePtr = callFramePtr;
16576
@@ -15425,57 +16614,32 @@
16614 if (retcode != JIM_OK) {
16615 goto badargset;
16616 }
16617 }
16618
16619 if (interp->traceCmdObj == NULL ||
16620 (retcode = JimTraceCallback(interp, "proc", argc, argv)) == JIM_OK) {
16621
16622 retcode = Jim_EvalObj(interp, cmd->u.proc.bodyObjPtr);
16623 }
16624
16625 badargset:
16626
16627
16628 retcode = JimInvokeDefer(interp, retcode);
16629 interp->framePtr = interp->framePtr->parent;
16630 JimFreeCallFrame(interp, callFramePtr, JIM_FCF_REUSE);
16631
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16632
16633 if (retcode == JIM_RETURN) {
16634 if (--interp->returnLevel <= 0) {
16635 retcode = interp->returnCode;
16636 interp->returnCode = JIM_OK;
16637 interp->returnLevel = 0;
16638 }
16639 }
16640 interp->procLevel--;
 
 
 
 
 
16641
16642 return retcode;
16643 }
16644
16645 int Jim_EvalSource(Jim_Interp *interp, const char *filename, int lineno, const char *script)
@@ -15483,26 +16647,14 @@
16647 int retval;
16648 Jim_Obj *scriptObjPtr;
16649
16650 scriptObjPtr = Jim_NewStringObj(interp, script, -1);
16651 Jim_IncrRefCount(scriptObjPtr);
 
16652 if (filename) {
 
 
16653 JimSetSourceInfo(interp, scriptObjPtr, Jim_NewStringObj(interp, filename, -1), lineno);
16654 }
16655 retval = Jim_EvalObj(interp, scriptObjPtr);
 
 
 
 
 
 
 
 
 
16656 Jim_DecrRefCount(interp, scriptObjPtr);
16657 return retval;
16658 }
16659
16660 int Jim_Eval(Jim_Interp *interp, const char *script)
@@ -15535,65 +16687,69 @@
16687 return retval;
16688 }
16689
16690 #include <sys/stat.h>
16691
16692 static Jim_Obj *JimReadTextFile(Jim_Interp *interp, const char *filename)
16693 {
16694 jim_stat_t sb;
16695 int fd;
16696 char *buf;
 
 
 
16697 int readlen;
16698
16699 if (Jim_Stat(filename, &sb) == -1 || (fd = open(filename, O_RDONLY | O_TEXT, 0666)) < 0) {
16700 Jim_SetResultFormatted(interp, "couldn't read file \"%s\": %s", filename, strerror(errno));
16701 return NULL;
16702 }
 
 
 
 
 
16703 buf = Jim_Alloc(sb.st_size + 1);
16704 readlen = read(fd, buf, sb.st_size);
16705 close(fd);
16706 if (readlen < 0) {
16707 Jim_Free(buf);
16708 Jim_SetResultFormatted(interp, "failed to load file \"%s\": %s", filename, strerror(errno));
16709 return NULL;
16710 }
16711 else {
16712 Jim_Obj *objPtr;
16713 buf[readlen] = 0;
16714
16715 objPtr = Jim_NewStringObjNoAlloc(interp, buf, readlen);
16716
16717 return objPtr;
16718 }
16719 }
16720
16721
16722 int Jim_EvalFile(Jim_Interp *interp, const char *filename)
16723 {
16724 Jim_Obj *filenameObj;
16725 Jim_Obj *oldFilenameObj;
16726 Jim_Obj *scriptObjPtr;
16727 int retcode;
16728
16729 scriptObjPtr = JimReadTextFile(interp, filename);
16730 if (!scriptObjPtr) {
16731 return JIM_ERR;
16732 }
16733
16734 filenameObj = Jim_NewStringObj(interp, filename, -1);
16735 JimSetSourceInfo(interp, scriptObjPtr, filenameObj, 1);
16736
16737 oldFilenameObj = JimPushInterpObj(interp->currentFilenameObj, filenameObj);
 
 
 
 
16738
16739 retcode = Jim_EvalObj(interp, scriptObjPtr);
16740
16741 JimPopInterpObj(interp, interp->currentFilenameObj, oldFilenameObj);
16742
16743
16744 if (retcode == JIM_RETURN) {
16745 if (--interp->returnLevel <= 0) {
16746 retcode = interp->returnCode;
16747 interp->returnCode = JIM_OK;
16748 interp->returnLevel = 0;
16749 }
16750 }
 
 
 
 
 
 
 
 
16751
16752 return retcode;
16753 }
16754
16755 static void JimParseSubst(struct JimParserCtx *pc, int flags)
@@ -15696,11 +16852,15 @@
16852 return (ScriptObj *) Jim_GetIntRepPtr(objPtr);
16853 }
16854
16855 int Jim_SubstObj(Jim_Interp *interp, Jim_Obj *substObjPtr, Jim_Obj **resObjPtrPtr, int flags)
16856 {
16857 ScriptObj *script;
16858
16859 JimPanic((substObjPtr->refCount == 0, "Jim_SubstObj() called with zero refcount object"));
16860
16861 script = Jim_GetSubst(interp, substObjPtr, flags);
16862
16863 Jim_IncrRefCount(substObjPtr);
16864 script->inUse++;
16865
16866 *resObjPtrPtr = JimInterpolateTokens(interp, script->token, script->len, flags);
@@ -15731,11 +16891,11 @@
16891
16892 Jim_SetResultFormatted(interp, "wrong # args: should be \"%#s\"", objPtr);
16893 }
16894
16895 typedef void JimHashtableIteratorCallbackType(Jim_Interp *interp, Jim_Obj *listObjPtr,
16896 Jim_Obj *keyObjPtr, void *value, Jim_Obj *patternObjPtr, int type);
16897
16898 #define JimTrivialMatch(pattern) (strpbrk((pattern), "*[?\\") == NULL)
16899
16900 static Jim_Obj *JimHashtablePatternMatch(Jim_Interp *interp, Jim_HashTable *ht, Jim_Obj *patternObjPtr,
16901 JimHashtableIteratorCallbackType *callback, int type)
@@ -15743,22 +16903,22 @@
16903 Jim_HashEntry *he;
16904 Jim_Obj *listObjPtr = Jim_NewListObj(interp, NULL, 0);
16905
16906
16907 if (patternObjPtr && JimTrivialMatch(Jim_String(patternObjPtr))) {
16908 he = Jim_FindHashEntry(ht, patternObjPtr);
16909 if (he) {
16910 callback(interp, listObjPtr, Jim_GetHashEntryKey(he), Jim_GetHashEntryVal(he),
16911 patternObjPtr, type);
16912 }
16913 }
16914 else {
16915 Jim_HashTableIterator htiter;
16916 JimInitHashTableIterator(ht, &htiter);
16917 while ((he = Jim_NextHashEntry(&htiter)) != NULL) {
16918 callback(interp, listObjPtr, Jim_GetHashEntryKey(he), Jim_GetHashEntryVal(he),
16919 patternObjPtr, type);
 
16920 }
16921 }
16922 return listObjPtr;
16923 }
16924
@@ -15766,29 +16926,40 @@
16926 #define JIM_CMDLIST_COMMANDS 0
16927 #define JIM_CMDLIST_PROCS 1
16928 #define JIM_CMDLIST_CHANNELS 2
16929
16930 static void JimCommandMatch(Jim_Interp *interp, Jim_Obj *listObjPtr,
16931 Jim_Obj *keyObj, void *value, Jim_Obj *patternObj, int type)
16932 {
16933 Jim_Cmd *cmdPtr = (Jim_Cmd *)value;
 
16934
16935 if (type == JIM_CMDLIST_PROCS && !cmdPtr->isproc) {
16936
16937 return;
16938 }
16939
16940 Jim_IncrRefCount(keyObj);
16941
16942 if (type != JIM_CMDLIST_CHANNELS || Jim_AioFilehandle(interp, keyObj) >= 0) {
16943 int match = 1;
16944 if (patternObj) {
16945 int plen, slen;
16946 const char *pattern = Jim_GetStringNoQualifier(patternObj, &plen);
16947 const char *str = Jim_GetStringNoQualifier(keyObj, &slen);
16948 #ifdef JIM_NO_INTROSPECTION
16949
16950 match = (JimStringCompareUtf8(pattern, plen, str, slen, 0) == 0);
16951 #else
16952 match = JimGlobMatch(pattern, plen, str, slen, 0);
16953 #endif
16954 }
16955 if (match) {
16956 Jim_ListAppendElement(interp, listObjPtr, keyObj);
16957 }
16958 }
16959 Jim_DecrRefCount(interp, keyObj);
16960 }
16961
16962 static Jim_Obj *JimCommandsList(Jim_Interp *interp, Jim_Obj *patternObjPtr, int type)
16963 {
16964 return JimHashtablePatternMatch(interp, &interp->commands, patternObjPtr, JimCommandMatch, type);
16965 }
@@ -15795,22 +16966,25 @@
16966
16967
16968 #define JIM_VARLIST_GLOBALS 0
16969 #define JIM_VARLIST_LOCALS 1
16970 #define JIM_VARLIST_VARS 2
16971 #define JIM_VARLIST_MASK 0x000f
16972
16973 #define JIM_VARLIST_VALUES 0x1000
16974
16975 static void JimVariablesMatch(Jim_Interp *interp, Jim_Obj *listObjPtr,
16976 Jim_Obj *keyObj, void *value, Jim_Obj *patternObj, int type)
16977 {
16978 Jim_VarVal *vv = (Jim_VarVal *)value;
16979
16980 if ((type & JIM_VARLIST_MASK) != JIM_VARLIST_LOCALS || vv->linkFramePtr == NULL) {
16981 if (patternObj == NULL || Jim_StringMatchObj(interp, patternObj, keyObj, 0)) {
16982 Jim_ListAppendElement(interp, listObjPtr, keyObj);
16983 if (type & JIM_VARLIST_VALUES) {
16984 Jim_ListAppendElement(interp, listObjPtr, vv->objPtr);
16985 }
16986 }
16987 }
16988 }
16989
16990
@@ -15819,42 +16993,78 @@
16993 if (mode == JIM_VARLIST_LOCALS && interp->framePtr == interp->topFramePtr) {
16994 return interp->emptyObj;
16995 }
16996 else {
16997 Jim_CallFrame *framePtr = (mode == JIM_VARLIST_GLOBALS) ? interp->topFramePtr : interp->framePtr;
16998 return JimHashtablePatternMatch(interp, &framePtr->vars, patternObjPtr, JimVariablesMatch,
16999 mode);
17000 }
17001 }
17002
17003 static int JimInfoLevel(Jim_Interp *interp, Jim_Obj *levelObjPtr, Jim_Obj **objPtrPtr)
17004 {
17005 long level;
17006
17007 if (Jim_GetLong(interp, levelObjPtr, &level) == JIM_OK) {
17008 Jim_CallFrame *targetCallFrame = JimGetCallFrameByInteger(interp, level);
17009 if (targetCallFrame && targetCallFrame != interp->topFramePtr) {
17010 #ifdef JIM_NO_INTROSPECTION
17011
17012 *objPtrPtr = Jim_NewListObj(interp, targetCallFrame->argv, 1);
17013 #else
17014 *objPtrPtr = Jim_NewListObj(interp, targetCallFrame->argv, targetCallFrame->argc);
17015 #endif
17016 return JIM_OK;
17017 }
17018 }
17019 Jim_SetResultFormatted(interp, "bad level \"%#s\"", levelObjPtr);
17020 return JIM_ERR;
17021 }
17022
17023 static int JimInfoFrame(Jim_Interp *interp, Jim_Obj *levelObjPtr, Jim_Obj **objPtrPtr)
17024 {
17025 long level;
17026
17027 if (Jim_GetLong(interp, levelObjPtr, &level) == JIM_OK) {
17028 Jim_EvalFrame *frame = JimGetEvalFrameByProcLevel(interp, level);
17029 if (frame) {
17030 Jim_Obj *listObj = Jim_NewListObj(interp, NULL, 0);
17031
17032 Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, "type", -1));
17033 Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, "source", -1));
17034 if (frame->scriptObj) {
17035 ScriptObj *script = JimGetScript(interp, frame->scriptObj);
17036 Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, "line", -1));
17037 Jim_ListAppendElement(interp, listObj, Jim_NewIntObj(interp, script->linenr));
17038 Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, "file", -1));
17039 Jim_ListAppendElement(interp, listObj, script->fileNameObj);
17040 }
17041 #ifndef JIM_NO_INTROSPECTION
17042 {
17043 Jim_Obj *cmdObj = Jim_NewListObj(interp, frame->argv, frame->argc);
17044
17045 Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, "cmd", -1));
17046 Jim_ListAppendElement(interp, listObj, cmdObj);
17047 }
17048 #endif
17049 {
17050 Jim_Obj *procNameObj = JimProcForEvalFrame(interp, frame);
17051 if (procNameObj) {
17052 Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, "proc", -1));
17053 Jim_ListAppendElement(interp, listObj, procNameObj);
17054 }
17055 }
17056 Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, "level", -1));
17057 Jim_ListAppendElement(interp, listObj, Jim_NewIntObj(interp, interp->framePtr->level - frame->framePtr->level));
17058
17059 *objPtrPtr = listObj;
17060 return JIM_OK;
17061 }
17062 }
17063 Jim_SetResultFormatted(interp, "bad level \"%#s\"", levelObjPtr);
17064 return JIM_ERR;
17065 }
17066
17067
17068 static int Jim_PutsCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
17069 {
17070 if (argc != 2 && argc != 3) {
@@ -16056,12 +17266,24 @@
17266 && complain) {
17267 return JIM_ERR;
17268 }
17269 i++;
17270 }
17271
17272 Jim_SetEmptyResult(interp);
17273 return JIM_OK;
17274 }
17275
17276 static int JimCheckLoopRetcode(Jim_Interp *interp, int retval)
17277 {
17278 if (retval == JIM_BREAK || retval == JIM_CONTINUE) {
17279 if (--interp->returnLevel > 0) {
17280 return 1;
17281 }
17282 }
17283 return 0;
17284 }
17285
17286
17287 static int Jim_WhileCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
17288 {
17289 if (argc != 3) {
@@ -16069,25 +17291,26 @@
17291 return JIM_ERR;
17292 }
17293
17294
17295 while (1) {
17296 int boolean = 0, retval;
17297
17298 if ((retval = Jim_GetBoolFromExpr(interp, argv[1], &boolean)) != JIM_OK)
17299 return retval;
17300 if (!boolean)
17301 break;
17302
17303 if ((retval = Jim_EvalObj(interp, argv[2])) != JIM_OK) {
17304 if (JimCheckLoopRetcode(interp, retval)) {
17305 return retval;
17306 }
17307 switch (retval) {
17308 case JIM_BREAK:
17309 goto out;
 
17310 case JIM_CONTINUE:
17311 continue;
 
17312 default:
17313 return retval;
17314 }
17315 }
17316 }
@@ -16099,10 +17322,11 @@
17322
17323 static int Jim_ForCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
17324 {
17325 int retval;
17326 int boolean = 1;
17327 int immediate = 0;
17328 Jim_Obj *varNamePtr = NULL;
17329 Jim_Obj *stopVarNamePtr = NULL;
17330
17331 if (argc != 5) {
17332 Jim_WrongNumArgs(interp, 1, argv, "start test next body");
@@ -16166,11 +17390,11 @@
17390 goto evalstart;
17391 }
17392
17393
17394 if (expr->expr->right->type == JIM_TT_EXPR_INT) {
17395 if (Jim_GetWideExpr(interp, expr->expr->right->objPtr, &stop) == JIM_ERR) {
17396 goto evalstart;
17397 }
17398 }
17399 else {
17400 stopVarNamePtr = expr->expr->right->objPtr;
@@ -16205,10 +17429,14 @@
17429 break;
17430 }
17431
17432
17433 retval = Jim_EvalObj(interp, argv[4]);
17434 if (JimCheckLoopRetcode(interp, retval)) {
17435 immediate++;
17436 goto out;
17437 }
17438 if (retval == JIM_OK || retval == JIM_CONTINUE) {
17439 retval = JIM_OK;
17440
17441 objPtr = Jim_GetVariable(interp, varNamePtr, JIM_ERRMSG);
17442
@@ -16241,10 +17469,14 @@
17469
17470 if (retval == JIM_OK || retval == JIM_CONTINUE) {
17471
17472 JIM_IF_OPTIM(evalnext:)
17473 retval = Jim_EvalObj(interp, argv[3]);
17474 if (JimCheckLoopRetcode(interp, retval)) {
17475 immediate++;
17476 goto out;
17477 }
17478 if (retval == JIM_OK || retval == JIM_CONTINUE) {
17479
17480 JIM_IF_OPTIM(testcond:)
17481 retval = Jim_GetBoolFromExpr(interp, argv[2], &boolean);
17482 }
@@ -16256,13 +17488,15 @@
17488 }
17489 if (varNamePtr) {
17490 Jim_DecrRefCount(interp, varNamePtr);
17491 }
17492
17493 if (!immediate) {
17494 if (retval == JIM_CONTINUE || retval == JIM_BREAK || retval == JIM_OK) {
17495 Jim_SetEmptyResult(interp);
17496 return JIM_OK;
17497 }
17498 }
17499
17500 return retval;
17501 }
17502
@@ -16273,26 +17507,38 @@
17507 jim_wide i;
17508 jim_wide limit;
17509 jim_wide incr = 1;
17510 Jim_Obj *bodyObjPtr;
17511
17512 if (argc < 4 || argc > 6) {
17513 Jim_WrongNumArgs(interp, 1, argv, "var ?first? limit ?incr? body");
17514 return JIM_ERR;
17515 }
17516
17517 retval = Jim_GetWideExpr(interp, argv[2], &i);
17518 if (argc > 4 && retval == JIM_OK) {
17519 retval = Jim_GetWideExpr(interp, argv[3], &limit);
17520 }
17521 if (argc > 5 && retval == JIM_OK) {
17522 Jim_GetWideExpr(interp, argv[4], &incr);
17523 }
17524 if (retval != JIM_OK) {
17525 return retval;
17526 }
17527 if (argc == 4) {
17528 limit = i;
17529 i = 0;
17530 }
17531 bodyObjPtr = argv[argc - 1];
17532
17533 retval = Jim_SetVariable(interp, argv[1], Jim_NewIntObj(interp, i));
17534
17535 while (((i < limit && incr > 0) || (i > limit && incr < 0)) && retval == JIM_OK) {
17536 retval = Jim_EvalObj(interp, bodyObjPtr);
17537 if (JimCheckLoopRetcode(interp, retval)) {
17538 return retval;
17539 }
17540 if (retval == JIM_OK || retval == JIM_CONTINUE) {
17541 Jim_Obj *objPtr = Jim_GetVariable(interp, argv[1], JIM_ERRMSG);
17542
17543 retval = JIM_OK;
17544
@@ -16429,11 +17675,15 @@
17675 if (result != JIM_OK) {
17676 goto err;
17677 }
17678 }
17679 }
17680 result = Jim_EvalObj(interp, script);
17681 if (JimCheckLoopRetcode(interp, result)) {
17682 goto err;
17683 }
17684 switch (result) {
17685 case JIM_OK:
17686 if (doMap) {
17687 Jim_ListAppendElement(interp, resultObj, interp->result);
17688 }
17689 break;
@@ -16550,23 +17800,25 @@
17800 Jim_WrongNumArgs(interp, 1, argv, "condition ?then? trueBody ?elseif ...? ?else? falseBody");
17801 return JIM_ERR;
17802 }
17803
17804
 
17805 int Jim_CommandMatchObj(Jim_Interp *interp, Jim_Obj *commandObj, Jim_Obj *patternObj,
17806 Jim_Obj *stringObj, int flags)
17807 {
17808 Jim_Obj *parms[5];
17809 int argc = 0;
17810 long eq;
17811 int rc;
17812
17813 parms[argc++] = commandObj;
17814 if (flags & JIM_NOCASE) {
17815 parms[argc++] = Jim_NewStringObj(interp, "-nocase", -1);
17816 }
17817 if (flags & JIM_OPT_END) {
17818 parms[argc++] = Jim_NewStringObj(interp, "--", -1);
17819 }
17820 parms[argc++] = patternObj;
17821 parms[argc++] = stringObj;
17822
17823 rc = Jim_EvalObjVector(interp, argc, parms);
17824
@@ -16580,10 +17832,11 @@
17832
17833 static int Jim_SwitchCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
17834 {
17835 enum { SWITCH_EXACT, SWITCH_GLOB, SWITCH_RE, SWITCH_CMD };
17836 int matchOpt = SWITCH_EXACT, opt = 1, patCount, i;
17837 int match_flags = 0;
17838 Jim_Obj *command = NULL, *scriptObj = NULL, *strObj;
17839 Jim_Obj **caseList;
17840
17841 if (argc < 3) {
17842 wrongnumargs:
@@ -16602,12 +17855,14 @@
17855 }
17856 else if (strncmp(option, "-exact", 2) == 0)
17857 matchOpt = SWITCH_EXACT;
17858 else if (strncmp(option, "-glob", 2) == 0)
17859 matchOpt = SWITCH_GLOB;
17860 else if (strncmp(option, "-regexp", 2) == 0) {
17861 matchOpt = SWITCH_RE;
17862 match_flags |= JIM_OPT_END;
17863 }
17864 else if (strncmp(option, "-command", 2) == 0) {
17865 matchOpt = SWITCH_CMD;
17866 if ((argc - opt) < 2)
17867 goto wrongnumargs;
17868 command = argv[++opt];
@@ -16646,11 +17901,11 @@
17901 break;
17902 case SWITCH_RE:
17903 command = Jim_NewStringObj(interp, "regexp", -1);
17904
17905 case SWITCH_CMD:{
17906 int rc = Jim_CommandMatchObj(interp, command, patObj, strObj, match_flags);
17907
17908 if (argc - opt == 1) {
17909 JimListGetElements(interp, argv[opt], &patCount, &caseList);
17910 }
17911
@@ -16691,37 +17946,26 @@
17946 }
17947
17948
17949 static int Jim_LindexCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
17950 {
17951 Jim_Obj *objPtr;
17952 int ret;
 
17953
17954 if (argc < 2) {
17955 Jim_WrongNumArgs(interp, 1, argv, "list ?index ...?");
17956 return JIM_ERR;
17957 }
17958 ret = Jim_ListIndices(interp, argv[1], argv + 2, argc - 2, &objPtr, JIM_NONE);
17959 if (ret < 0) {
17960 ret = JIM_OK;
17961 Jim_SetEmptyResult(interp);
17962 }
17963 else if (ret == JIM_OK) {
17964 Jim_SetResult(interp, objPtr);
17965 }
17966 return ret;
 
 
 
 
 
 
 
 
 
 
17967 }
17968
17969
17970 static int Jim_LlengthCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
17971 {
@@ -16736,31 +17980,33 @@
17980
17981 static int Jim_LsearchCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
17982 {
17983 static const char * const options[] = {
17984 "-bool", "-not", "-nocase", "-exact", "-glob", "-regexp", "-all", "-inline", "-command",
17985 "-stride", "-index", NULL
17986 };
17987 enum
17988 { OPT_BOOL, OPT_NOT, OPT_NOCASE, OPT_EXACT, OPT_GLOB, OPT_REGEXP, OPT_ALL, OPT_INLINE,
17989 OPT_COMMAND, OPT_STRIDE, OPT_INDEX };
17990 int i;
17991 int opt_bool = 0;
17992 int opt_not = 0;
 
17993 int opt_all = 0;
17994 int opt_inline = 0;
17995 int opt_match = OPT_EXACT;
17996 int listlen;
17997 int rc = JIM_OK;
17998 Jim_Obj *listObjPtr = NULL;
17999 Jim_Obj *commandObj = NULL;
18000 Jim_Obj *indexObj = NULL;
18001 int match_flags = 0;
18002 long stride = 1;
18003
18004 if (argc < 3) {
18005 wrongargs:
18006 Jim_WrongNumArgs(interp, 1, argv,
18007 "?-exact|-glob|-regexp|-command 'command'? ?-bool|-inline? ?-not? ?-nocase? ?-all? ?-stride len? ?-index val? list value");
18008 return JIM_ERR;
18009 }
18010
18011 for (i = 1; i < argc - 2; i++) {
18012 int option;
@@ -16775,34 +18021,65 @@
18021 break;
18022 case OPT_NOT:
18023 opt_not = 1;
18024 break;
18025 case OPT_NOCASE:
18026 match_flags |= JIM_NOCASE;
18027 break;
18028 case OPT_INLINE:
18029 opt_inline = 1;
18030 opt_bool = 0;
18031 break;
18032 case OPT_ALL:
18033 opt_all = 1;
18034 break;
18035 case OPT_REGEXP:
18036 opt_match = option;
18037 match_flags |= JIM_OPT_END;
18038 break;
18039 case OPT_COMMAND:
18040 if (i >= argc - 2) {
18041 goto wrongargs;
18042 }
18043 commandObj = argv[++i];
18044
18045 case OPT_EXACT:
18046 case OPT_GLOB:
 
18047 opt_match = option;
18048 break;
18049 case OPT_INDEX:
18050 if (i >= argc - 2) {
18051 goto wrongargs;
18052 }
18053 indexObj = argv[++i];
18054 break;
18055 case OPT_STRIDE:
18056 if (i >= argc - 2) {
18057 goto wrongargs;
18058 }
18059 if (Jim_GetLong(interp, argv[++i], &stride) != JIM_OK) {
18060 return JIM_ERR;
18061 }
18062 if (stride < 1) {
18063 Jim_SetResultString(interp, "stride length must be at least 1", -1);
18064 return JIM_ERR;
18065 }
18066 break;
18067 }
18068 }
18069
18070 argc -= i;
18071 if (argc < 2) {
18072 goto wrongargs;
18073 }
18074 argv += i;
18075
18076 listlen = Jim_ListLength(interp, argv[0]);
18077 if (listlen % stride) {
18078 Jim_SetResultString(interp, "list size must be a multiple of the stride length", -1);
18079 return JIM_ERR;
18080 }
18081
18082 if (opt_all) {
18083 listObjPtr = Jim_NewListObj(interp, NULL, 0);
18084 }
18085 if (opt_match == OPT_REGEXP) {
@@ -16810,68 +18087,104 @@
18087 }
18088 if (commandObj) {
18089 Jim_IncrRefCount(commandObj);
18090 }
18091
18092 for (i = 0; i < listlen; i += stride) {
 
18093 int eq = 0;
18094 Jim_Obj *searchListObj;
18095 Jim_Obj *objPtr;
18096 int offset;
18097
18098 if (indexObj) {
18099 int indexlen = Jim_ListLength(interp, indexObj);
18100 if (stride == 1) {
18101 searchListObj = Jim_ListGetIndex(interp, argv[0], i);
18102 }
18103 else {
18104 searchListObj = Jim_NewListObj(interp, argv[0]->internalRep.listValue.ele + i, stride);
18105 }
18106 Jim_IncrRefCount(searchListObj);
18107 rc = Jim_ListIndices(interp, searchListObj, indexObj->internalRep.listValue.ele, indexlen, &objPtr, JIM_ERRMSG);
18108 if (rc != JIM_OK) {
18109 Jim_DecrRefCount(interp, searchListObj);
18110 rc = JIM_ERR;
18111 goto done;
18112 }
18113
18114 offset = 0;
18115 }
18116 else {
18117
18118 searchListObj = argv[0];
18119 offset = i;
18120 objPtr = Jim_ListGetIndex(interp, searchListObj, i);
18121 Jim_IncrRefCount(searchListObj);
18122 }
18123
18124 switch (opt_match) {
18125 case OPT_EXACT:
18126 eq = Jim_StringCompareObj(interp, argv[1], objPtr, match_flags) == 0;
18127 break;
18128
18129 case OPT_GLOB:
18130 eq = Jim_StringMatchObj(interp, argv[1], objPtr, match_flags);
18131 break;
18132
18133 case OPT_REGEXP:
18134 case OPT_COMMAND:
18135 eq = Jim_CommandMatchObj(interp, commandObj, argv[1], objPtr, match_flags);
18136 if (eq < 0) {
18137 Jim_DecrRefCount(interp, searchListObj);
 
 
18138 rc = JIM_ERR;
18139 goto done;
18140 }
18141 break;
18142 }
18143
18144
 
 
 
 
18145 if ((!opt_bool && eq == !opt_not) || (opt_bool && (eq || opt_all))) {
 
18146 Jim_Obj *resultObj;
18147
18148 if (opt_bool) {
18149 resultObj = Jim_NewIntObj(interp, eq ^ opt_not);
18150 }
18151 else if (!opt_inline) {
18152 resultObj = Jim_NewIntObj(interp, i);
18153 }
18154 else if (stride == 1) {
18155 resultObj = objPtr;
18156 }
18157 else if (opt_all) {
18158
18159 ListInsertElements(listObjPtr, -1, stride,
18160 searchListObj->internalRep.listValue.ele + offset);
18161
18162 resultObj = NULL;
18163 }
18164 else {
18165 resultObj = Jim_NewListObj(interp, searchListObj->internalRep.listValue.ele + offset, stride);
18166 }
18167
18168 if (opt_all) {
18169
18170 if (stride == 1) {
18171 Jim_ListAppendElement(interp, listObjPtr, resultObj);
18172 }
18173 }
18174 else {
18175 Jim_SetResult(interp, resultObj);
18176 Jim_DecrRefCount(interp, searchListObj);
18177 goto done;
18178 }
18179 }
18180 Jim_DecrRefCount(interp, searchListObj);
18181 }
18182
18183 if (opt_all) {
18184 Jim_SetResult(interp, listObjPtr);
18185 listObjPtr = NULL;
18186 }
18187 else {
18188
18189 if (opt_bool) {
18190 Jim_SetResultBool(interp, opt_not);
@@ -16880,10 +18193,13 @@
18193 Jim_SetResultInt(interp, -1);
18194 }
18195 }
18196
18197 done:
18198 if (listObjPtr) {
18199 Jim_FreeNewObj(interp, listObjPtr);
18200 }
18201 if (commandObj) {
18202 Jim_DecrRefCount(interp, commandObj);
18203 }
18204 return rc;
18205 }
@@ -16993,11 +18309,11 @@
18309
18310
18311 static int Jim_LsetCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
18312 {
18313 if (argc < 3) {
18314 Jim_WrongNumArgs(interp, 1, argv, "listVar ?index ...? value");
18315 return JIM_ERR;
18316 }
18317 else if (argc == 3) {
18318
18319 if (Jim_SetVariable(interp, argv[1], argv[2]) != JIM_OK)
@@ -17010,29 +18326,34 @@
18326
18327
18328 static int Jim_LsortCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const argv[])
18329 {
18330 static const char * const options[] = {
18331 "-ascii", "-nocase", "-increasing", "-decreasing", "-command", "-integer", "-real", "-index", "-unique",
18332 "-stride", NULL
18333 };
18334 enum {
18335 OPT_ASCII, OPT_NOCASE, OPT_INCREASING, OPT_DECREASING, OPT_COMMAND, OPT_INTEGER, OPT_REAL, OPT_INDEX, OPT_UNIQUE,
18336 OPT_STRIDE
18337 };
18338 Jim_Obj *resObj;
18339 int i;
18340 int retCode;
18341 int shared;
18342 long stride = 1;
18343
18344 struct lsort_info info;
18345
18346 if (argc < 2) {
18347 wrongargs:
18348 Jim_WrongNumArgs(interp, 1, argv, "?options? list");
18349 return JIM_ERR;
18350 }
18351
18352 info.type = JIM_LSORT_ASCII;
18353 info.order = 1;
18354 info.indexc = 0;
18355 info.unique = 0;
18356 info.command = NULL;
18357 info.interp = interp;
18358
18359 for (i = 1; i < (argc - 1); i++) {
@@ -17069,33 +18390,77 @@
18390 return JIM_ERR;
18391 }
18392 info.type = JIM_LSORT_COMMAND;
18393 info.command = argv[i + 1];
18394 i++;
18395 break;
18396 case OPT_STRIDE:
18397 if (i >= argc - 2) {
18398 goto wrongargs;
18399 }
18400 if (Jim_GetLong(interp, argv[++i], &stride) != JIM_OK) {
18401 return JIM_ERR;
18402 }
18403 if (stride < 2) {
18404 Jim_SetResultString(interp, "stride length must be at least 2", -1);
18405 return JIM_ERR;
18406 }
18407 break;
18408 case OPT_INDEX:
18409 if (i >= (argc - 2)) {
18410 badindex:
18411 Jim_SetResultString(interp, "\"-index\" option must be followed by list index", -1);
18412 return JIM_ERR;
18413 }
18414 JimListGetElements(interp, argv[i + 1], &info.indexc, &info.indexv);
18415 if (info.indexc == 0) {
18416 goto badindex;
18417 }
 
18418 i++;
18419 break;
18420 }
18421 }
18422 resObj = argv[argc - 1];
18423 if (stride > 1) {
18424 Jim_Obj *tmpListObj;
18425 Jim_Obj **elements;
18426 int listlen;
18427 int i;
18428
18429 JimListGetElements(interp, resObj, &listlen, &elements);
18430 if (listlen % stride) {
18431 Jim_SetResultString(interp, "list size must be a multiple of the stride length", -1);
18432 return JIM_ERR;
18433 }
18434
18435 tmpListObj = Jim_NewListObj(interp, NULL, 0);
18436 Jim_IncrRefCount(tmpListObj);
18437 for (i = 0; i < listlen; i += stride) {
18438 Jim_ListAppendElement(interp, tmpListObj, Jim_NewListObj(interp, elements + i, stride));
18439 }
18440 retCode = ListSortElements(interp, tmpListObj, &info);
18441 if (retCode == JIM_OK) {
18442 resObj = Jim_NewListObj(interp, NULL, 0);
18443
18444 for (i = 0; i < listlen; i += stride) {
18445 Jim_ListAppendList(interp, resObj, Jim_ListGetIndex(interp, tmpListObj, i / stride));
18446 }
18447 Jim_SetResult(interp, resObj);
18448 }
18449 Jim_DecrRefCount(interp, tmpListObj);
18450 }
18451 else {
18452 if ((shared = Jim_IsShared(resObj))) {
18453 resObj = Jim_DuplicateObj(interp, resObj);
18454 }
18455 retCode = ListSortElements(interp, resObj, &info);
18456 if (retCode == JIM_OK) {
18457 Jim_SetResult(interp, resObj);
18458 }
18459 else if (shared) {
18460 Jim_FreeNewObj(interp, resObj);
18461 }
18462 }
18463 return retCode;
18464 }
18465
18466
@@ -17139,17 +18504,10 @@
18504 return JIM_OK;
18505 }
18506
18507
18508
 
 
 
 
 
 
 
18509
18510
18511 static int Jim_EvalCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
18512 {
18513 int rc;
@@ -17164,14 +18522,10 @@
18522 }
18523 else {
18524 rc = Jim_EvalObj(interp, Jim_ConcatObj(interp, argc - 1, argv + 1));
18525 }
18526
 
 
 
 
18527 return rc;
18528 }
18529
18530
18531 static int Jim_UplevelCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
@@ -17224,10 +18578,16 @@
18578 int retcode;
18579
18580 if (argc == 2) {
18581 retcode = Jim_EvalExpression(interp, argv[1]);
18582 }
18583 #ifndef JIM_COMPAT
18584 else {
18585 Jim_WrongNumArgs(interp, 1, argv, "expression");
18586 retcode = JIM_ERR;
18587 }
18588 #else
18589 else if (argc > 2) {
18590 Jim_Obj *objPtr;
18591
18592 objPtr = Jim_ConcatObj(interp, argc - 1, argv + 1);
18593 Jim_IncrRefCount(objPtr);
@@ -17236,33 +18596,72 @@
18596 }
18597 else {
18598 Jim_WrongNumArgs(interp, 1, argv, "expression ?...?");
18599 return JIM_ERR;
18600 }
18601 #endif
18602 return retcode;
18603 }
18604
18605 static int JimBreakContinueHelper(Jim_Interp *interp, int argc, Jim_Obj *const *argv, int retcode)
18606 {
18607 if (argc != 1 && argc != 2) {
18608 Jim_WrongNumArgs(interp, 1, argv, "?level?");
18609 return JIM_ERR;
18610 }
18611 if (argc == 2) {
18612 long level;
18613 int ret = Jim_GetLong(interp, argv[1], &level);
18614 if (ret != JIM_OK) {
18615 return ret;
18616 }
18617 interp->returnLevel = level;
18618 }
18619 return retcode;
18620 }
18621
18622
18623 static int Jim_BreakCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
18624 {
18625 return JimBreakContinueHelper(interp, argc, argv, JIM_BREAK);
 
 
 
 
18626 }
18627
18628
18629 static int Jim_ContinueCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
18630 {
18631 return JimBreakContinueHelper(interp, argc, argv, JIM_CONTINUE);
18632 }
18633
18634
18635 static int Jim_StacktraceCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
18636 {
18637 Jim_Obj *listObj;
18638 int i;
18639 jim_wide skip = 0;
18640 jim_wide last = 0;
18641
18642 if (argc > 1) {
18643 if (Jim_GetWideExpr(interp, argv[1], &skip) != JIM_OK) {
18644 return JIM_ERR;
18645 }
18646 }
18647 if (argc > 2) {
18648 if (Jim_GetWideExpr(interp, argv[2], &last) != JIM_OK) {
18649 return JIM_ERR;
18650 }
18651 }
18652
18653 listObj = Jim_NewListObj(interp, NULL, 0);
18654 for (i = skip; i <= interp->procLevel; i++) {
18655 Jim_EvalFrame *frame = JimGetEvalFrameByProcLevel(interp, -i);
18656 if (frame->procLevel < last) {
18657 break;
18658 }
18659 JimAddStackFrame(interp, frame, listObj);
18660 }
18661 Jim_SetResult(interp, listObj);
18662 return JIM_OK;
18663 }
18664
18665
18666 static int Jim_ReturnCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
18667 {
@@ -17312,11 +18711,11 @@
18711 interp->returnLevel = level;
18712
18713 if (i == argc - 1) {
18714 Jim_SetResult(interp, argv[i]);
18715 }
18716 return level == 0 ? returnCode : JIM_RETURN;
18717 }
18718
18719
18720 static int Jim_TailcallCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
18721 {
@@ -17370,28 +18769,21 @@
18769 }
18770
18771 static int Jim_AliasCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
18772 {
18773 Jim_Obj *prefixListObj;
 
18774
18775 if (argc < 3) {
18776 Jim_WrongNumArgs(interp, 1, argv, "newname command ?args ...?");
18777 return JIM_ERR;
18778 }
18779
18780 prefixListObj = Jim_NewListObj(interp, argv + 2, argc - 2);
18781 Jim_IncrRefCount(prefixListObj);
 
 
 
 
 
 
18782 Jim_SetResult(interp, argv[1]);
18783
18784 return Jim_CreateCommandObj(interp, argv[1], JimAliasCmd, prefixListObj, JimAliasCmdDelete);
18785 }
18786
18787
18788 static int Jim_ProcCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
18789 {
@@ -17400,40 +18792,54 @@
18792 if (argc != 4 && argc != 5) {
18793 Jim_WrongNumArgs(interp, 1, argv, "name arglist ?statics? body");
18794 return JIM_ERR;
18795 }
18796
 
 
 
 
18797 if (argc == 4) {
18798 cmd = JimCreateProcedureCmd(interp, argv[2], NULL, argv[3], NULL);
18799 }
18800 else {
18801 cmd = JimCreateProcedureCmd(interp, argv[2], argv[3], argv[4], NULL);
18802 }
18803
18804 if (cmd) {
18805
18806 Jim_Obj *nameObjPtr = JimQualifyName(interp, argv[1]);
18807 JimCreateCommand(interp, nameObjPtr, cmd);
 
 
18808
18809
18810 JimUpdateProcNamespace(interp, cmd, nameObjPtr);
18811 Jim_DecrRefCount(interp, nameObjPtr);
 
18812
18813
18814 Jim_SetResult(interp, argv[1]);
18815 return JIM_OK;
18816 }
18817 return JIM_ERR;
18818 }
18819
18820
18821 static int Jim_XtraceCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
18822 {
18823 if (argc != 2) {
18824 Jim_WrongNumArgs(interp, 1, argv, "callback");
18825 return JIM_ERR;
18826 }
18827
18828 if (interp->traceCmdObj) {
18829 Jim_DecrRefCount(interp, interp->traceCmdObj);
18830 interp->traceCmdObj = NULL;
18831 }
18832
18833 if (Jim_Length(argv[1])) {
18834
18835 interp->traceCmdObj = argv[1];
18836 Jim_IncrRefCount(interp->traceCmdObj);
18837 }
18838 return JIM_OK;
18839 }
18840
18841
18842 static int Jim_LocalCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
18843 {
18844 int retcode;
18845
@@ -17518,11 +18924,11 @@
18924 }
18925
18926 if (len == 3) {
18927 #ifdef jim_ext_namespace
18928
18929 nsObj = Jim_ListGetIndex(interp, argv[1], 2);
18930 #else
18931 Jim_SetResultString(interp, "namespaces not enabled", -1);
18932 return JIM_ERR;
18933 #endif
18934 }
@@ -17641,11 +19047,11 @@
19047 k = Jim_String(eachObjPtr);
19048 kl = Jim_Utf8Length(interp, eachObjPtr);
19049
19050 if (strLen >= kl && kl) {
19051 int rc;
19052 rc = JimStringCompareUtf8(str, kl, k, kl, nocase);
19053 if (rc == 0) {
19054 if (noMatchStart) {
19055 Jim_AppendString(interp, resultObjPtr, noMatchStart, str - noMatchStart);
19056 noMatchStart = NULL;
19057 }
@@ -17674,50 +19080,85 @@
19080 static int Jim_StringCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
19081 {
19082 int len;
19083 int opt_case = 1;
19084 int option;
 
 
 
 
 
 
 
 
 
 
 
19085 static const char * const nocase_options[] = {
19086 "-nocase", NULL
19087 };
19088 static const char * const nocase_length_options[] = {
19089 "-nocase", "-length", NULL
19090 };
19091
19092 enum {
19093 OPT_BYTELENGTH,
19094 OPT_BYTERANGE,
19095 OPT_CAT,
19096 OPT_COMPARE,
19097 OPT_EQUAL,
19098 OPT_FIRST,
19099 OPT_INDEX,
19100 OPT_IS,
19101 OPT_LAST,
19102 OPT_LENGTH,
19103 OPT_MAP,
19104 OPT_MATCH,
19105 OPT_RANGE,
19106 OPT_REPEAT,
19107 OPT_REPLACE,
19108 OPT_REVERSE,
19109 OPT_TOLOWER,
19110 OPT_TOTITLE,
19111 OPT_TOUPPER,
19112 OPT_TRIM,
19113 OPT_TRIMLEFT,
19114 OPT_TRIMRIGHT,
19115 OPT_COUNT
19116 };
19117 static const jim_subcmd_type cmds[OPT_COUNT + 1] = {
19118 JIM_DEF_SUBCMD("bytelength", "string", 1, 1),
19119 JIM_DEF_SUBCMD("byterange", "string first last", 3, 3),
19120 JIM_DEF_SUBCMD("cat", "?...?", 0, -1),
19121 JIM_DEF_SUBCMD("compare", "?-nocase? ?-length int? string1 string2", 2, 5),
19122 JIM_DEF_SUBCMD("equal", "?-nocase? ?-length int? string1 string2", 2, 5),
19123 JIM_DEF_SUBCMD("first", "subString string ?index?", 2, 3),
19124 JIM_DEF_SUBCMD("index", "string index", 2, 2),
19125 JIM_DEF_SUBCMD("is", "class ?-strict? str", 2, 3),
19126 JIM_DEF_SUBCMD("last", "subString string ?index?", 2, 3),
19127 JIM_DEF_SUBCMD("length","string", 1, 1),
19128 JIM_DEF_SUBCMD("map", "?-nocase? mapList string", 2, 3),
19129 JIM_DEF_SUBCMD("match", "?-nocase? pattern string", 2, 3),
19130 JIM_DEF_SUBCMD("range", "string first last", 3, 3),
19131 JIM_DEF_SUBCMD("repeat", "string count", 2, 2),
19132 JIM_DEF_SUBCMD("replace", "string first last ?string?", 3, 4),
19133 JIM_DEF_SUBCMD("reverse", "string", 1, 1),
19134 JIM_DEF_SUBCMD("tolower", "string", 1, 1),
19135 JIM_DEF_SUBCMD("totitle", "string", 1, 1),
19136 JIM_DEF_SUBCMD("toupper", "string", 1, 1),
19137 JIM_DEF_SUBCMD("trim", "string ?trimchars?", 1, 2),
19138 JIM_DEF_SUBCMD("trimleft", "string ?trimchars?", 1, 2),
19139 JIM_DEF_SUBCMD("trimright", "string ?trimchars?", 1, 2),
19140 { }
19141 };
19142 const jim_subcmd_type *ct = Jim_ParseSubCmd(interp, cmds, argc, argv);
19143 if (!ct) {
19144 return JIM_ERR;
19145 }
19146 if (ct->function) {
19147
19148 return ct->function(interp, argc, argv);
19149 }
19150
19151 option = ct - cmds;
19152
19153 switch (option) {
19154 case OPT_LENGTH:
19155 Jim_SetResultInt(interp, Jim_Utf8Length(interp, argv[2]));
19156 return JIM_OK;
19157
19158 case OPT_BYTELENGTH:
19159 Jim_SetResultInt(interp, Jim_Length(argv[2]));
 
 
 
 
 
 
 
 
 
 
19160 return JIM_OK;
19161
19162 case OPT_CAT:{
19163 Jim_Obj *objPtr;
19164 if (argc == 3) {
@@ -17747,11 +19188,11 @@
19188 while (n > 0) {
19189 int subopt;
19190 if (Jim_GetEnum(interp, argv[i++], nocase_length_options, &subopt, NULL,
19191 JIM_ENUM_ABBREV) != JIM_OK) {
19192 badcompareargs:
19193 Jim_SubCmdArgError(interp, ct, argv[0]);
19194 return JIM_ERR;
19195 }
19196 if (subopt == 0) {
19197
19198 opt_case = 0;
@@ -17775,16 +19216,23 @@
19216 if (opt_length < 0 && option != OPT_COMPARE && opt_case) {
19217
19218 Jim_SetResultBool(interp, Jim_StringEqObj(argv[0], argv[1]));
19219 }
19220 else {
19221 const char *s1 = Jim_String(argv[0]);
19222 int l1 = Jim_Utf8Length(interp, argv[0]);
19223 const char *s2 = Jim_String(argv[1]);
19224 int l2 = Jim_Utf8Length(interp, argv[1]);
19225 if (opt_length >= 0) {
19226 if (l1 > opt_length) {
19227 l1 = opt_length;
19228 }
19229 if (l2 > opt_length) {
19230 l2 = opt_length;
19231 }
19232 }
19233 n = JimStringCompareUtf8(s1, l1, s2, l2, !opt_case);
19234 Jim_SetResultInt(interp, option == OPT_COMPARE ? n : n == 0);
19235 }
19236 return JIM_OK;
19237 }
19238
@@ -17822,41 +19270,30 @@
19270 }
19271 Jim_SetResult(interp, objPtr);
19272 return JIM_OK;
19273 }
19274
19275 case OPT_RANGE:{
19276 Jim_Obj *objPtr = Jim_StringRangeObj(interp, argv[2], argv[3], argv[4]);
19277 if (objPtr == NULL) {
19278 return JIM_ERR;
19279 }
19280 Jim_SetResult(interp, objPtr);
19281 return JIM_OK;
19282 }
19283
19284 case OPT_BYTERANGE:{
19285 Jim_Obj *objPtr = Jim_StringByteRangeObj(interp, argv[2], argv[3], argv[4]);
 
 
 
 
 
 
 
 
 
 
 
 
 
19286 if (objPtr == NULL) {
19287 return JIM_ERR;
19288 }
19289 Jim_SetResult(interp, objPtr);
19290 return JIM_OK;
19291 }
19292
19293 case OPT_REPLACE:{
19294 Jim_Obj *objPtr = JimStringReplaceObj(interp, argv[2], argv[3], argv[4], argc == 6 ? argv[5] : NULL);
 
 
 
 
 
 
19295 if (objPtr == NULL) {
19296 return JIM_ERR;
19297 }
19298 Jim_SetResult(interp, objPtr);
19299 return JIM_OK;
@@ -17865,15 +19302,11 @@
19302
19303 case OPT_REPEAT:{
19304 Jim_Obj *objPtr;
19305 jim_wide count;
19306
19307 if (Jim_GetWideExpr(interp, argv[3], &count) != JIM_OK) {
 
 
 
 
19308 return JIM_ERR;
19309 }
19310 objPtr = Jim_NewStringObj(interp, "", 0);
19311 if (count > 0) {
19312 while (count--) {
@@ -17887,17 +19320,13 @@
19320 case OPT_REVERSE:{
19321 char *buf, *p;
19322 const char *str;
19323 int i;
19324
 
 
 
 
 
19325 str = Jim_GetString(argv[2], &len);
19326 buf = Jim_Alloc(len + 1);
19327 assert(buf);
19328 p = buf + len;
19329 *p = 0;
19330 for (i = 0; i < len; ) {
19331 int c;
19332 int l = utf8_tounicode(str, &c);
@@ -17912,22 +19341,16 @@
19341
19342 case OPT_INDEX:{
19343 int idx;
19344 const char *str;
19345
 
 
 
 
19346 if (Jim_GetIndex(interp, argv[3], &idx) != JIM_OK) {
19347 return JIM_ERR;
19348 }
19349 str = Jim_String(argv[2]);
19350 len = Jim_Utf8Length(interp, argv[2]);
19351 idx = JimRelToAbsIndex(len, idx);
 
 
19352 if (idx < 0 || idx >= len || str == NULL) {
19353 Jim_SetResultString(interp, "", 0);
19354 }
19355 else if (len == Jim_Length(argv[2])) {
19356
@@ -17944,23 +19367,22 @@
19367 case OPT_FIRST:
19368 case OPT_LAST:{
19369 int idx = 0, l1, l2;
19370 const char *s1, *s2;
19371
 
 
 
 
19372 s1 = Jim_String(argv[2]);
19373 s2 = Jim_String(argv[3]);
19374 l1 = Jim_Utf8Length(interp, argv[2]);
19375 l2 = Jim_Utf8Length(interp, argv[3]);
19376 if (argc == 5) {
19377 if (Jim_GetIndex(interp, argv[4], &idx) != JIM_OK) {
19378 return JIM_ERR;
19379 }
19380 idx = JimRelToAbsIndex(l2, idx);
19381 if (idx < 0) {
19382 idx = 0;
19383 }
19384 }
19385 else if (option == OPT_LAST) {
19386 idx = l2;
19387 }
19388 if (option == OPT_FIRST) {
@@ -17975,66 +19397,45 @@
19397 }
19398 return JIM_OK;
19399 }
19400
19401 case OPT_TRIM:
19402 Jim_SetResult(interp, JimStringTrim(interp, argv[2], argc == 4 ? argv[3] : NULL));
19403 return JIM_OK;
19404 case OPT_TRIMLEFT:
19405 Jim_SetResult(interp, JimStringTrimLeft(interp, argv[2], argc == 4 ? argv[3] : NULL));
19406 return JIM_OK;
19407 case OPT_TRIMRIGHT:{
19408 Jim_SetResult(interp, JimStringTrimRight(interp, argv[2], argc == 4 ? argv[3] : NULL));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19409 return JIM_OK;
19410 }
19411
19412 case OPT_TOLOWER:
 
 
 
 
 
 
 
19413 Jim_SetResult(interp, JimStringToLower(interp, argv[2]));
19414 return JIM_OK;
19415 case OPT_TOUPPER:
19416 Jim_SetResult(interp, JimStringToUpper(interp, argv[2]));
19417 return JIM_OK;
19418 case OPT_TOTITLE:
19419 Jim_SetResult(interp, JimStringToTitle(interp, argv[2]));
19420 return JIM_OK;
 
19421
19422 case OPT_IS:
19423 if (argc == 5 && !Jim_CompareStringImmediate(interp, argv[3], "-strict")) {
19424 Jim_SubCmdArgError(interp, ct, argv[0]);
19425 return JIM_ERR;
19426 }
19427 return JimStringIs(interp, argv[argc - 1], argv[2], argc == 5);
 
19428 }
19429 return JIM_OK;
19430 }
19431
19432
19433 static int Jim_TimeCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
19434 {
19435 long i, count = 1;
19436 jim_wide start, elapsed;
 
 
19437
19438 if (argc < 2) {
19439 Jim_WrongNumArgs(interp, 1, argv, "script ?count?");
19440 return JIM_ERR;
19441 }
@@ -18043,22 +19444,92 @@
19444 return JIM_ERR;
19445 }
19446 if (count < 0)
19447 return JIM_OK;
19448 i = count;
19449 start = Jim_GetTimeUsec(CLOCK_MONOTONIC_RAW);
19450 while (i-- > 0) {
19451 int retval;
19452
19453 retval = Jim_EvalObj(interp, argv[1]);
19454 if (retval != JIM_OK) {
19455 return retval;
19456 }
19457 }
19458 elapsed = Jim_GetTimeUsec(CLOCK_MONOTONIC_RAW) - start;
19459 if (elapsed < count * 10) {
19460 Jim_SetResult(interp, Jim_NewDoubleObj(interp, elapsed * 1.0 / count));
19461 }
19462 else {
19463 Jim_SetResultInt(interp, count == 0 ? 0 : elapsed / count);
19464 }
19465 Jim_AppendString(interp, Jim_GetResult(interp)," microseconds per iteration", -1);
19466 return JIM_OK;
19467 }
19468
19469
19470 static int Jim_TimeRateCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
19471 {
19472 long us = 0;
19473 jim_wide start, delta, overhead;
19474 Jim_Obj *objPtr;
19475 double us_per_iter;
19476 int count;
19477 int n;
19478
19479 if (argc < 2) {
19480 Jim_WrongNumArgs(interp, 1, argv, "script ?milliseconds?");
19481 return JIM_ERR;
19482 }
19483 if (argc == 3) {
19484 if (Jim_GetLong(interp, argv[2], &us) != JIM_OK)
19485 return JIM_ERR;
19486 us *= 1000;
19487 }
19488 if (us < 1) {
19489
19490 us = 1000 * 1000;
19491 }
19492
19493
19494 start = Jim_GetTimeUsec(CLOCK_MONOTONIC_RAW);
19495 count = 0;
19496 do {
19497 int retval = Jim_EvalObj(interp, argv[1]);
19498 delta = Jim_GetTimeUsec(CLOCK_MONOTONIC_RAW) - start;
19499 if (retval != JIM_OK) {
19500 return retval;
19501 }
19502 count++;
19503 } while (delta < us);
19504
19505
19506 start = Jim_GetTimeUsec(CLOCK_MONOTONIC_RAW);
19507 n = 0;
19508 do {
19509 int retval = Jim_EvalObj(interp, interp->nullScriptObj);
19510 overhead = Jim_GetTimeUsec(CLOCK_MONOTONIC_RAW) - start;
19511 if (retval != JIM_OK) {
19512 return retval;
19513 }
19514 n++;
19515 } while (n < count);
19516
19517 delta -= overhead;
19518
19519 us_per_iter = (double)delta / count;
19520 objPtr = Jim_NewListObj(interp, NULL, 0);
19521
19522 Jim_ListAppendElement(interp, objPtr, Jim_NewStringObj(interp, "us_per_iter", -1));
19523 Jim_ListAppendElement(interp, objPtr, Jim_NewDoubleObj(interp, us_per_iter));
19524 Jim_ListAppendElement(interp, objPtr, Jim_NewStringObj(interp, "iters_per_sec", -1));
19525 Jim_ListAppendElement(interp, objPtr, Jim_NewDoubleObj(interp, 1e6 / us_per_iter));
19526 Jim_ListAppendElement(interp, objPtr, Jim_NewStringObj(interp, "count", -1));
19527 Jim_ListAppendElement(interp, objPtr, Jim_NewIntObj(interp, count));
19528 Jim_ListAppendElement(interp, objPtr, Jim_NewStringObj(interp, "elapsed_us", -1));
19529 Jim_ListAppendElement(interp, objPtr, Jim_NewIntObj(interp, delta));
19530 Jim_SetResult(interp, objPtr);
19531 return JIM_OK;
19532 }
19533
19534
19535 static int Jim_ExitCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
@@ -18070,25 +19541,55 @@
19541 return JIM_ERR;
19542 }
19543 if (argc == 2) {
19544 if (Jim_GetLong(interp, argv[1], &exitCode) != JIM_OK)
19545 return JIM_ERR;
19546 Jim_SetResult(interp, argv[1]);
19547 }
19548 interp->exitCode = exitCode;
19549 return JIM_EXIT;
19550 }
19551
19552 static int JimMatchReturnCodes(Jim_Interp *interp, Jim_Obj *retcodeListObj, int rc)
19553 {
19554 int len = Jim_ListLength(interp, retcodeListObj);
19555 int i;
19556 for (i = 0; i < len; i++) {
19557 int returncode;
19558 if (Jim_GetReturnCode(interp, Jim_ListGetIndex(interp, retcodeListObj, i), &returncode) != JIM_OK) {
19559 return JIM_ERR;
19560 }
19561 if (rc == returncode) {
19562 return JIM_OK;
19563 }
19564 }
19565 return -1;
19566 }
19567
19568
19569 static int JimCatchTryHelper(Jim_Interp *interp, int istry, int argc, Jim_Obj *const *argv)
19570 {
19571 static const char * const wrongargs_catchtry[2] = {
19572 "?-?no?code ... --? script ?resultVarName? ?optionVarName?",
19573 "?-?no?code ... --? script ?on|trap codes vars script? ... ?finally script?"
19574 };
19575 int exitCode = 0;
19576 int i;
19577 int sig = 0;
19578 int ok;
19579 Jim_Obj *finallyScriptObj = NULL;
19580 Jim_Obj *msgVarObj = NULL;
19581 Jim_Obj *optsVarObj = NULL;
19582 Jim_Obj *handlerScriptObj = NULL;
19583 Jim_Obj *errorCodeObj;
19584 int idx;
19585
19586
19587 jim_wide ignore_mask = (1 << JIM_EXIT) | (1 << JIM_EVAL) | (1 << JIM_SIGNAL);
19588 static const int max_ignore_code = sizeof(ignore_mask) * 8;
19589
19590 JimPanic((istry != 0 && istry != 1, "wrong args to JimCatchTryHelper"));
19591
19592 Jim_SetGlobalVariableStr(interp, "errorCode", Jim_NewStringObj(interp, "NONE", -1));
19593
19594 for (i = 1; i < argc - 1; i++) {
19595 const char *arg = Jim_String(argv[i]);
@@ -18129,18 +19630,17 @@
19630 else {
19631 ignore_mask &= (~((jim_wide)1 << option));
19632 }
19633 }
19634
19635 idx = i;
19636
19637 if (argc - idx < 1) {
19638 wrongargs:
19639 Jim_WrongNumArgs(interp, 1, argv, wrongargs_catchtry[istry]);
19640 return JIM_ERR;
19641 }
 
19642
19643 if ((ignore_mask & (1 << JIM_SIGNAL)) == 0) {
19644 sig++;
19645 }
19646
@@ -18148,64 +19648,172 @@
19648 if (Jim_CheckSignal(interp)) {
19649
19650 exitCode = JIM_SIGNAL;
19651 }
19652 else {
19653 exitCode = Jim_EvalObj(interp, argv[idx]);
19654
19655 interp->errorFlag = 0;
19656 }
19657 interp->signal_level -= sig;
19658
19659 errorCodeObj = Jim_GetGlobalVariableStr(interp, "errorCode", JIM_NONE);
19660
19661 idx++;
19662 if (istry) {
19663 while (idx < argc) {
19664 int option;
19665 int ret;
19666 static const char * const try_options[] = { "on", "trap", "finally", NULL };
19667 enum { TRY_ON, TRY_TRAP, TRY_FINALLY, };
19668
19669 if (Jim_GetEnum(interp, argv[idx], try_options, &option, "handler", JIM_ERRMSG) != JIM_OK) {
19670 return JIM_ERR;
19671 }
19672 switch (option) {
19673 case TRY_ON:
19674 case TRY_TRAP:
19675 if (idx + 4 > argc) {
19676 goto wrongargs;
19677 }
19678 if (option == TRY_ON) {
19679 ret = JimMatchReturnCodes(interp, argv[idx + 1], exitCode);
19680 if (ret > JIM_OK) {
19681 goto wrongargs;
19682 }
19683 }
19684 else if (errorCodeObj) {
19685 int len = Jim_ListLength(interp, argv[idx + 1]);
19686 int i;
19687
19688 ret = JIM_OK;
19689
19690 for (i = 0; i < len; i++) {
19691 Jim_Obj *matchObj = Jim_ListGetIndex(interp, argv[idx + 1], i);
19692 Jim_Obj *objPtr = Jim_ListGetIndex(interp, errorCodeObj, i);
19693 if (Jim_StringCompareObj(interp, matchObj, objPtr, 0) != 0) {
19694 ret = -1;
19695 break;
19696 }
19697 }
19698 }
19699 else {
19700
19701 ret = -1;
19702 }
19703
19704 if (ret == JIM_OK && handlerScriptObj == NULL) {
19705 msgVarObj = Jim_ListGetIndex(interp, argv[idx + 2], 0);
19706 optsVarObj = Jim_ListGetIndex(interp, argv[idx + 2], 1);
19707 handlerScriptObj = argv[idx + 3];
19708 }
19709 idx += 4;
19710 break;
19711 case TRY_FINALLY:
19712 if (idx + 2 != argc) {
19713 goto wrongargs;
19714 }
19715 finallyScriptObj = argv[idx + 1];
19716 idx += 2;
19717 break;
19718 }
19719 }
19720 }
19721 else {
19722 if (argc - idx >= 1) {
19723 msgVarObj = argv[idx];
19724 idx++;
19725 if (argc - idx >= 1) {
19726 optsVarObj = argv[idx];
19727 idx++;
19728 }
19729 }
19730 }
19731
19732
19733 if (exitCode >= 0 && exitCode < max_ignore_code && (((unsigned jim_wide)1 << exitCode) & ignore_mask)) {
19734
19735 if (finallyScriptObj) {
19736 Jim_EvalObj(interp, finallyScriptObj);
19737 }
19738 return exitCode;
19739 }
19740
19741 if (sig && exitCode == JIM_SIGNAL) {
19742
19743 if (interp->signal_set_result) {
19744 interp->signal_set_result(interp, interp->sigmask);
19745 }
19746 else if (!istry) {
19747 Jim_SetResultInt(interp, interp->sigmask);
19748 }
19749 interp->sigmask = 0;
19750 }
19751
19752 ok = 1;
19753 if (msgVarObj && Jim_Length(msgVarObj)) {
19754 if (Jim_SetVariable(interp, msgVarObj, Jim_GetResult(interp)) != JIM_OK) {
19755 ok = 0;
19756 }
19757 }
19758 if (ok && optsVarObj && Jim_Length(optsVarObj)) {
19759 Jim_Obj *optListObj = Jim_NewListObj(interp, NULL, 0);
19760
19761 Jim_ListAppendElement(interp, optListObj, Jim_NewStringObj(interp, "-code", -1));
19762 Jim_ListAppendElement(interp, optListObj,
19763 Jim_NewIntObj(interp, exitCode == JIM_RETURN ? interp->returnCode : exitCode));
19764 Jim_ListAppendElement(interp, optListObj, Jim_NewStringObj(interp, "-level", -1));
19765 Jim_ListAppendElement(interp, optListObj, Jim_NewIntObj(interp, interp->returnLevel));
19766 if (exitCode == JIM_ERR) {
19767 Jim_ListAppendElement(interp, optListObj, Jim_NewStringObj(interp, "-errorinfo",
19768 -1));
19769 Jim_ListAppendElement(interp, optListObj, interp->stackTrace);
19770
19771 if (errorCodeObj) {
19772 Jim_ListAppendElement(interp, optListObj, Jim_NewStringObj(interp, "-errorcode", -1));
19773 Jim_ListAppendElement(interp, optListObj, errorCodeObj);
19774 }
19775 }
19776 if (Jim_SetVariable(interp, optsVarObj, optListObj) != JIM_OK) {
19777 ok = 0;
19778 }
19779 }
19780 if (ok && handlerScriptObj) {
19781
19782 exitCode = Jim_EvalObj(interp, handlerScriptObj);
19783 }
19784
19785 if (finallyScriptObj) {
19786
19787 Jim_Obj *prevResultObj = Jim_GetResult(interp);
19788 Jim_IncrRefCount(prevResultObj);
19789 int ret = Jim_EvalObj(interp, finallyScriptObj);
19790 if (ret == JIM_OK) {
19791 Jim_SetResult(interp, prevResultObj);
19792 }
19793 else {
19794 exitCode = ret;
19795 }
19796 Jim_DecrRefCount(interp, prevResultObj);
19797 }
19798 if (!istry) {
19799 Jim_SetResultInt(interp, exitCode);
19800 exitCode = JIM_OK;
19801 }
19802 return exitCode;
19803 }
19804
19805
19806 static int Jim_CatchCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
19807 {
19808 return JimCatchTryHelper(interp, 0, argc, argv);
19809 }
19810
19811
19812 static int Jim_TryCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
19813 {
19814 return JimCatchTryHelper(interp, 1, argc, argv);
19815 }
19816
19817
19818
19819 static int Jim_RenameCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
@@ -18213,46 +19821,44 @@
19821 if (argc != 3) {
19822 Jim_WrongNumArgs(interp, 1, argv, "oldName newName");
19823 return JIM_ERR;
19824 }
19825
19826 return Jim_RenameCommand(interp, argv[1], argv[2]);
 
 
 
 
19827 }
19828
19829 #define JIM_DICTMATCH_KEYS 0x0001
19830 #define JIM_DICTMATCH_VALUES 0x002
19831
19832 int Jim_DictMatchTypes(Jim_Interp *interp, Jim_Obj *objPtr, Jim_Obj *patternObj, int match_type, int return_types)
19833 {
 
19834 Jim_Obj *listObjPtr;
19835 Jim_Dict *dict;
19836 int i;
19837
19838 if (SetDictFromAny(interp, objPtr) != JIM_OK) {
19839 return JIM_ERR;
19840 }
19841 dict = objPtr->internalRep.dictValue;
19842
19843 listObjPtr = Jim_NewListObj(interp, NULL, 0);
19844
19845 for (i = 0; i < dict->len; i += 2 ) {
19846 Jim_Obj *keyObj = dict->table[i];
19847 Jim_Obj *valObj = dict->table[i + 1];
19848 if (patternObj) {
19849 Jim_Obj *matchObj = (match_type == JIM_DICTMATCH_KEYS) ? keyObj : valObj;
19850 if (!Jim_StringMatchObj(interp, patternObj, matchObj, 0)) {
19851
19852 continue;
19853 }
19854 }
19855 if (return_types & JIM_DICTMATCH_KEYS) {
19856 Jim_ListAppendElement(interp, listObjPtr, keyObj);
19857 }
19858 if (return_types & JIM_DICTMATCH_VALUES) {
19859 Jim_ListAppendElement(interp, listObjPtr, valObj);
19860 }
19861 }
19862
19863 Jim_SetResult(interp, listObjPtr);
19864 return JIM_OK;
@@ -18261,11 +19867,11 @@
19867 int Jim_DictSize(Jim_Interp *interp, Jim_Obj *objPtr)
19868 {
19869 if (SetDictFromAny(interp, objPtr) != JIM_OK) {
19870 return -1;
19871 }
19872 return objPtr->internalRep.dictValue->len / 2;
19873 }
19874
19875 Jim_Obj *Jim_DictMerge(Jim_Interp *interp, int objc, Jim_Obj *const *objv)
19876 {
19877 Jim_Obj *objPtr = Jim_NewDictObj(interp, NULL, 0);
@@ -18274,73 +19880,41 @@
19880 JimPanic((objc == 0, "Jim_DictMerge called with objc=0"));
19881
19882
19883
19884 for (i = 0; i < objc; i++) {
19885 Jim_Obj **table;
19886 int tablelen;
19887 int j;
19888
19889 table = Jim_DictPairs(interp, objv[i], &tablelen);
19890 if (tablelen && !table) {
19891 Jim_FreeNewObj(interp, objPtr);
19892 return NULL;
19893 }
19894 for (j = 0; j < tablelen; j += 2) {
19895 DictAddElement(interp, objPtr, table[j], table[j + 1]);
 
 
19896 }
19897 }
19898 return objPtr;
19899 }
19900
19901 int Jim_DictInfo(Jim_Interp *interp, Jim_Obj *objPtr)
19902 {
 
 
19903 char buffer[100];
 
 
19904 Jim_Obj *output;
19905 Jim_Dict *dict;
19906
19907 if (SetDictFromAny(interp, objPtr) != JIM_OK) {
19908 return JIM_ERR;
19909 }
19910
19911 dict = objPtr->internalRep.dictValue;
19912
19913
19914 snprintf(buffer, sizeof(buffer), "%d entries in table, %d buckets", dict->len, dict->size);
19915 output = Jim_NewStringObj(interp, buffer, -1);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19916 Jim_SetResult(interp, output);
19917 return JIM_OK;
19918 }
19919
19920 static int Jim_EvalEnsemble(Jim_Interp *interp, const char *basecmd, const char *subcmd, int argc, Jim_Obj *const *argv)
@@ -18366,16 +19940,16 @@
19940 dictObj = Jim_GetVariable(interp, dictVarName, JIM_ERRMSG);
19941 if (dictObj == NULL || Jim_DictKeysVector(interp, dictObj, keyv, keyc, &objPtr, JIM_ERRMSG) != JIM_OK) {
19942 return JIM_ERR;
19943 }
19944
19945 dictValues = Jim_DictPairs(interp, objPtr, &len);
19946 if (len && dictValues == NULL) {
19947 return JIM_ERR;
19948 }
19949 for (i = 0; i < len; i += 2) {
19950 if (Jim_SetVariable(interp, dictValues[i], dictValues[i + 1]) == JIM_ERR) {
 
19951 return JIM_ERR;
19952 }
19953 }
19954
19955
@@ -18390,110 +19964,137 @@
19964 newkeyv[i] = keyv[i];
19965 }
19966
19967 for (i = 0; i < len; i += 2) {
19968
19969 if (Jim_StringCompareObj(interp, dictVarName, dictValues[i], 0) != 0) {
19970
19971 objPtr = Jim_GetVariable(interp, dictValues[i], 0);
19972 newkeyv[keyc] = dictValues[i];
19973 Jim_SetDictKeysVector(interp, dictVarName, newkeyv, keyc + 1, objPtr, JIM_NORESULT);
19974 }
19975 }
19976 Jim_Free(newkeyv);
19977 }
19978 }
19979
 
 
19980 return ret;
19981 }
19982
19983
19984 static int Jim_DictCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
19985 {
19986 Jim_Obj *objPtr;
19987 int types = JIM_DICTMATCH_KEYS;
19988
19989 enum {
19990 OPT_CREATE,
19991 OPT_GET,
19992 OPT_GETDEF,
19993 OPT_GETWITHDEFAULT,
19994 OPT_SET,
19995 OPT_UNSET,
19996 OPT_EXISTS,
19997 OPT_KEYS,
19998 OPT_SIZE,
19999 OPT_INFO,
20000 OPT_MERGE,
20001 OPT_WITH,
20002 OPT_APPEND,
20003 OPT_LAPPEND,
20004 OPT_INCR,
20005 OPT_REMOVE,
20006 OPT_VALUES,
20007 OPT_FOR,
20008 OPT_REPLACE,
20009 OPT_UPDATE,
20010 OPT_COUNT
20011 };
20012 static const jim_subcmd_type cmds[OPT_COUNT + 1] = {
20013 JIM_DEF_SUBCMD("create", "?key value ...?", 0, -2),
20014 JIM_DEF_SUBCMD("get", "dictionary ?key ...?", 1, -1),
20015 JIM_DEF_SUBCMD_HIDDEN("getdef", "dictionary ?key ...? key default", 3, -1),
20016 JIM_DEF_SUBCMD("getwithdefault", "dictionary ?key ...? key default", 3, -1),
20017 JIM_DEF_SUBCMD("set", "varName key ?key ...? value", 3, -1),
20018 JIM_DEF_SUBCMD("unset", "varName key ?key ...?", 2, -1),
20019 JIM_DEF_SUBCMD("exists", "dictionary key ?key ...?", 2, -1),
20020 JIM_DEF_SUBCMD("keys", "dictionary ?pattern?", 1, 2),
20021 JIM_DEF_SUBCMD("size", "dictionary", 1, 1),
20022 JIM_DEF_SUBCMD("info", "dictionary", 1, 1),
20023 JIM_DEF_SUBCMD("merge", "?...?", 0, -1),
20024 JIM_DEF_SUBCMD("with", "dictVar ?key ...? script", 2, -1),
20025 JIM_DEF_SUBCMD("append", "varName key ?value ...?", 2, -1),
20026 JIM_DEF_SUBCMD("lappend", "varName key ?value ...?", 2, -1),
20027 JIM_DEF_SUBCMD("incr", "varName key ?increment?", 2, 3),
20028 JIM_DEF_SUBCMD("remove", "dictionary ?key ...?", 1, -1),
20029 JIM_DEF_SUBCMD("values", "dictionary ?pattern?", 1, 2),
20030 JIM_DEF_SUBCMD("for", "vars dictionary script", 3, 3),
20031 JIM_DEF_SUBCMD("replace", "dictionary ?key value ...?", 1, -1),
20032 JIM_DEF_SUBCMD("update", "varName ?arg ...? script", 2, -1),
20033 { }
20034 };
20035 const jim_subcmd_type *ct = Jim_ParseSubCmd(interp, cmds, argc, argv);
20036 if (!ct) {
20037 return JIM_ERR;
20038 }
20039 if (ct->function) {
20040
20041 return ct->function(interp, argc, argv);
20042 }
20043
20044
20045 switch (ct - cmds) {
20046 case OPT_GET:
20047 if (Jim_DictKeysVector(interp, argv[2], argv + 3, argc - 3, &objPtr,
20048 JIM_ERRMSG) != JIM_OK) {
20049 return JIM_ERR;
20050 }
20051 Jim_SetResult(interp, objPtr);
20052 return JIM_OK;
20053
20054 case OPT_GETDEF:
20055 case OPT_GETWITHDEFAULT:{
20056 int rc = Jim_DictKeysVector(interp, argv[2], argv + 3, argc - 4, &objPtr, JIM_ERRMSG);
20057 if (rc == -1) {
20058
20059 return JIM_ERR;
20060 }
20061 if (rc == JIM_ERR) {
20062 Jim_SetResult(interp, argv[argc - 1]);
20063 }
20064 else {
20065 Jim_SetResult(interp, objPtr);
20066 }
20067 return JIM_OK;
20068 }
20069
20070 case OPT_SET:
20071 return Jim_SetDictKeysVector(interp, argv[2], argv + 3, argc - 4, argv[argc - 1], JIM_ERRMSG);
20072
20073 case OPT_EXISTS:{
20074 int rc = Jim_DictKeysVector(interp, argv[2], argv + 3, argc - 3, &objPtr, JIM_NONE);
 
 
 
 
 
20075 if (rc < 0) {
20076 return JIM_ERR;
20077 }
20078 Jim_SetResultBool(interp, rc == JIM_OK);
20079 return JIM_OK;
20080 }
20081
20082 case OPT_UNSET:
20083 if (Jim_SetDictKeysVector(interp, argv[2], argv + 3, argc - 3, NULL, JIM_NONE) != JIM_OK) {
 
 
 
 
20084 return JIM_ERR;
20085 }
20086 return JIM_OK;
20087
20088 case OPT_VALUES:
20089 types = JIM_DICTMATCH_VALUES;
20090
20091 case OPT_KEYS:
 
 
 
 
20092 return Jim_DictMatchTypes(interp, argv[2], argc == 4 ? argv[3] : NULL, types, types);
20093
20094 case OPT_SIZE:
20095 if (Jim_DictSize(interp, argv[2]) < 0) {
 
 
 
 
20096 return JIM_ERR;
20097 }
20098 Jim_SetResultInt(interp, Jim_DictSize(interp, argv[2]));
20099 return JIM_OK;
20100
@@ -18506,42 +20107,30 @@
20107 return JIM_ERR;
20108 }
20109 Jim_SetResult(interp, objPtr);
20110 return JIM_OK;
20111
 
 
 
 
 
 
 
20112 case OPT_CREATE:
 
 
 
 
20113 objPtr = Jim_NewDictObj(interp, argv + 2, argc - 2);
20114 Jim_SetResult(interp, objPtr);
20115 return JIM_OK;
20116
20117 case OPT_INFO:
 
 
 
 
20118 return Jim_DictInfo(interp, argv[2]);
20119
20120 case OPT_WITH:
 
 
 
 
20121 return JimDictWith(interp, argv[2], argv + 3, argc - 4, argv[argc - 1]);
20122
20123 case OPT_UPDATE:
20124 if (argc < 6 || argc % 2) {
20125
20126 argc = 2;
20127 }
20128
20129 default:
20130 return Jim_EvalEnsemble(interp, "dict", Jim_String(argv[1]), argc - 2, argv + 2);
20131 }
 
 
20132 }
20133
20134
20135 static int Jim_SubstCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
20136 {
@@ -18582,30 +20171,79 @@
20171 }
20172 Jim_SetResult(interp, objPtr);
20173 return JIM_OK;
20174 }
20175
20176 #ifdef jim_ext_namespace
20177 static int JimIsGlobalNamespace(Jim_Obj *objPtr)
20178 {
20179 int len;
20180 const char *str = Jim_GetString(objPtr, &len);
20181 return len >= 2 && str[0] == ':' && str[1] == ':';
20182 }
20183 #endif
20184
20185
20186 static int Jim_InfoCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
20187 {
 
20188 Jim_Obj *objPtr;
20189 int mode = 0;
20190
20191
20192 enum {
20193 INFO_ALIAS,
20194 INFO_ARGS,
20195 INFO_BODY,
20196 INFO_CHANNELS,
20197 INFO_COMMANDS,
20198 INFO_COMPLETE,
20199 INFO_EXISTS,
20200 INFO_FRAME,
20201 INFO_GLOBALS,
20202 INFO_HOSTNAME,
20203 INFO_LEVEL,
20204 INFO_LOCALS,
20205 INFO_NAMEOFEXECUTABLE,
20206 INFO_PATCHLEVEL,
20207 INFO_PROCS,
20208 INFO_REFERENCES,
20209 INFO_RETURNCODES,
20210 INFO_SCRIPT,
20211 INFO_SOURCE,
20212 INFO_STACKTRACE,
20213 INFO_STATICS,
20214 INFO_VARS,
20215 INFO_VERSION,
20216 INFO_COUNT
20217 };
20218 static const jim_subcmd_type cmds[INFO_COUNT + 1] = {
20219 JIM_DEF_SUBCMD("alias", "command", 1, 1),
20220 JIM_DEF_SUBCMD("args", "procname", 1, 1),
20221 JIM_DEF_SUBCMD("body", "procname", 1, 1),
20222 JIM_DEF_SUBCMD("channels", "?pattern?", 0, 1),
20223 JIM_DEF_SUBCMD("commands", "?pattern?", 0, 1),
20224 JIM_DEF_SUBCMD("complete", "script ?missing?", 1, 2),
20225 JIM_DEF_SUBCMD("exists", "varName", 1, 1),
20226 JIM_DEF_SUBCMD("frame", "?levelNum?", 0, 1),
20227 JIM_DEF_SUBCMD("globals", "?pattern?", 0, 1),
20228 JIM_DEF_SUBCMD("hostname", NULL, 0, 0),
20229 JIM_DEF_SUBCMD("level", "?levelNum?", 0, 1),
20230 JIM_DEF_SUBCMD("locals", "?pattern?", 0, 1),
20231 JIM_DEF_SUBCMD("nameofexecutable", NULL, 0, 0),
20232 JIM_DEF_SUBCMD("patchlevel", NULL, 0, 0),
20233 JIM_DEF_SUBCMD("procs", "?pattern?", 0, 1),
20234 JIM_DEF_SUBCMD("references", NULL, 0, 0),
20235 JIM_DEF_SUBCMD("returncodes", "?code?", 0, 1),
20236 JIM_DEF_SUBCMD("script", "?filename?", 0, 1),
20237 JIM_DEF_SUBCMD("source", "source ?filename line?", 1, 3),
20238 JIM_DEF_SUBCMD("stacktrace", NULL, 0, 0),
20239 JIM_DEF_SUBCMD("statics", "procname", 1, 1),
20240 JIM_DEF_SUBCMD("vars", "?pattern?", 0, 1),
20241 JIM_DEF_SUBCMD("version", NULL, 0, 0),
20242 { }
20243 };
20244 const jim_subcmd_type *ct;
20245 #ifdef jim_ext_namespace
20246 int nons = 0;
20247
20248 if (argc > 2 && Jim_CompareStringImmediate(interp, argv[1], "-nons")) {
20249
@@ -18612,36 +20250,29 @@
20250 argc--;
20251 argv++;
20252 nons = 1;
20253 }
20254 #endif
20255 ct = Jim_ParseSubCmd(interp, cmds, argc, argv);
20256 if (!ct) {
 
20257 return JIM_ERR;
20258 }
20259 if (ct->function) {
20260
20261 return ct->function(interp, argc, argv);
20262 }
20263
20264 int option = ct - cmds;
20265
20266 switch (option) {
20267 case INFO_EXISTS:
 
 
 
 
20268 Jim_SetResultBool(interp, Jim_GetVariable(interp, argv[2], 0) != NULL);
20269 return JIM_OK;
20270
20271 case INFO_ALIAS:{
20272 Jim_Cmd *cmdPtr;
20273
 
 
 
 
20274 if ((cmdPtr = Jim_GetCommand(interp, argv[2], JIM_ERRMSG)) == NULL) {
20275 return JIM_ERR;
20276 }
20277 if (cmdPtr->isproc || cmdPtr->u.native.cmdProc != JimAliasCmd) {
20278 Jim_SetResultFormatted(interp, "command \"%#s\" is not an alias", argv[2]);
@@ -18661,61 +20292,54 @@
20292 case INFO_PROCS:
20293 mode++;
20294
20295 case INFO_COMMANDS:
20296
 
 
 
 
20297 #ifdef jim_ext_namespace
20298 if (!nons) {
20299 if (Jim_Length(interp->framePtr->nsObj) || (argc == 3 && JimIsGlobalNamespace(argv[2]))) {
20300 return Jim_EvalPrefix(interp, "namespace info", argc - 1, argv + 1);
20301 }
20302 }
20303 #endif
20304 Jim_SetResult(interp, JimCommandsList(interp, (argc == 3) ? argv[2] : NULL, mode));
20305 return JIM_OK;
20306
20307 case INFO_VARS:
20308 mode++;
20309
20310 case INFO_LOCALS:
20311 mode++;
20312
20313 case INFO_GLOBALS:
20314
 
 
 
 
20315 #ifdef jim_ext_namespace
20316 if (!nons) {
20317 if (Jim_Length(interp->framePtr->nsObj) || (argc == 3 && JimIsGlobalNamespace(argv[2]))) {
20318 return Jim_EvalPrefix(interp, "namespace info", argc - 1, argv + 1);
20319 }
20320 }
20321 #endif
20322 Jim_SetResult(interp, JimVariablesList(interp, argc == 3 ? argv[2] : NULL, mode));
20323 return JIM_OK;
20324
20325 case INFO_SCRIPT:
20326 if (argc == 3) {
20327 Jim_IncrRefCount(argv[2]);
20328 Jim_DecrRefCount(interp, interp->currentFilenameObj);
20329 interp->currentFilenameObj = argv[2];
20330 }
20331 Jim_SetResult(interp, interp->currentFilenameObj);
20332 return JIM_OK;
20333
20334 case INFO_SOURCE:{
20335 jim_wide line;
20336 Jim_Obj *resObjPtr;
20337 Jim_Obj *fileNameObj;
20338
20339 if (argc == 4) {
20340 Jim_SubCmdArgError(interp, ct, argv[0]);
20341 return JIM_ERR;
20342 }
20343 if (argc == 5) {
20344 if (Jim_GetWide(interp, argv[4], &line) != JIM_OK) {
20345 return JIM_ERR;
@@ -18740,93 +20364,94 @@
20364 resObjPtr = Jim_NewListObj(interp, NULL, 0);
20365 Jim_ListAppendElement(interp, resObjPtr, fileNameObj);
20366 Jim_ListAppendElement(interp, resObjPtr, Jim_NewIntObj(interp, line));
20367 }
20368 Jim_SetResult(interp, resObjPtr);
20369 return JIM_OK;
20370 }
20371
20372 case INFO_STACKTRACE:
20373 Jim_SetResult(interp, interp->stackTrace);
20374 return JIM_OK;
20375
20376 case INFO_LEVEL:
20377 if (argc == 2) {
20378 Jim_SetResultInt(interp, interp->framePtr->level);
20379 }
20380 else {
20381 if (JimInfoLevel(interp, argv[2], &objPtr) != JIM_OK) {
20382 return JIM_ERR;
20383 }
20384 Jim_SetResult(interp, objPtr);
20385 }
20386 return JIM_OK;
20387
20388 case INFO_FRAME:
20389 if (argc == 2) {
20390 Jim_SetResultInt(interp, interp->procLevel + 1);
20391 }
20392 else {
20393 if (JimInfoFrame(interp, argv[2], &objPtr) != JIM_OK) {
20394 return JIM_ERR;
20395 }
20396 Jim_SetResult(interp, objPtr);
20397 }
20398 return JIM_OK;
20399
20400 case INFO_BODY:
20401 case INFO_STATICS:
20402 case INFO_ARGS:{
20403 Jim_Cmd *cmdPtr;
20404
 
 
 
 
20405 if ((cmdPtr = Jim_GetCommand(interp, argv[2], JIM_ERRMSG)) == NULL) {
20406 return JIM_ERR;
20407 }
20408 if (!cmdPtr->isproc) {
20409 Jim_SetResultFormatted(interp, "command \"%#s\" is not a procedure", argv[2]);
20410 return JIM_ERR;
20411 }
20412 switch (option) {
20413 #ifdef JIM_NO_INTROSPECTION
20414 default:
20415 Jim_SetResultString(interp, "unsupported", -1);
20416 return JIM_ERR;
20417 #else
20418 case INFO_BODY:
20419 Jim_SetResult(interp, cmdPtr->u.proc.bodyObjPtr);
20420 break;
20421 case INFO_ARGS:
20422 Jim_SetResult(interp, cmdPtr->u.proc.argListObjPtr);
20423 break;
20424 #endif
20425 case INFO_STATICS:
20426 if (cmdPtr->u.proc.staticVars) {
20427 Jim_SetResult(interp, JimHashtablePatternMatch(interp, cmdPtr->u.proc.staticVars,
20428 NULL, JimVariablesMatch, JIM_VARLIST_LOCALS | JIM_VARLIST_VALUES));
20429 }
20430 break;
20431 }
20432 return JIM_OK;
20433 }
20434
20435 case INFO_VERSION:
20436 case INFO_PATCHLEVEL:{
20437 char buf[(JIM_INTEGER_SPACE * 2) + 1];
20438
20439 sprintf(buf, "%d.%d", JIM_VERSION / 100, JIM_VERSION % 100);
20440 Jim_SetResultString(interp, buf, -1);
20441 return JIM_OK;
20442 }
20443
20444 case INFO_COMPLETE: {
 
 
 
 
 
20445 char missing;
20446
20447 Jim_SetResultBool(interp, Jim_ScriptIsComplete(interp, argv[2], &missing));
20448 if (missing != ' ' && argc == 4) {
20449 Jim_SetVariable(interp, argv[3], Jim_NewStringObj(interp, &missing, 1));
20450 }
20451 return JIM_OK;
20452 }
 
20453
20454 case INFO_HOSTNAME:
20455
20456 return Jim_Eval(interp, "os.gethostname");
20457
@@ -18860,24 +20485,21 @@
20485 }
20486 else {
20487 Jim_SetResultString(interp, name, -1);
20488 }
20489 }
20490 return JIM_OK;
 
 
 
 
20491 case INFO_REFERENCES:
20492 #ifdef JIM_REFERENCES
20493 return JimInfoReferences(interp, argc, argv);
20494 #else
20495 Jim_SetResultString(interp, "not supported", -1);
20496 return JIM_ERR;
20497 #endif
20498 default:
20499 abort();
20500 }
 
20501 }
20502
20503
20504 static int Jim_ExistsCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
20505 {
@@ -19145,11 +20767,10 @@
20767 Jim_SetResult(interp, argv[1]);
20768 if (argc == 3) {
20769 JimSetStackTrace(interp, argv[2]);
20770 return JIM_ERR;
20771 }
 
20772 return JIM_ERR;
20773 }
20774
20775
20776 static int Jim_LrangeCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
@@ -19168,26 +20789,27 @@
20789
20790
20791 static int Jim_LrepeatCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
20792 {
20793 Jim_Obj *objPtr;
20794 jim_wide count;
20795
20796 if (argc < 2 || Jim_GetWideExpr(interp, argv[1], &count) != JIM_OK || count < 0) {
20797 Jim_WrongNumArgs(interp, 1, argv, "count ?value ...?");
20798 return JIM_ERR;
20799 }
 
20800 if (count == 0 || argc == 2) {
20801 Jim_SetEmptyResult(interp);
20802 return JIM_OK;
20803 }
20804
20805 argc -= 2;
20806 argv += 2;
20807
20808 objPtr = Jim_NewListObj(interp, NULL, 0);
20809 ListEnsureLength(objPtr, argc * count);
20810 while (count--) {
20811 ListInsertElements(objPtr, -1, argc, argv);
20812 }
20813
20814 Jim_SetResult(interp, objPtr);
20815 return JIM_OK;
@@ -19243,11 +20865,11 @@
20865
20866 Jim_SetResult(interp, listObjPtr);
20867 return JIM_OK;
20868 }
20869
20870 if (argc > 3) {
20871 Jim_WrongNumArgs(interp, 1, argv, "varName ?default?");
20872 return JIM_ERR;
20873 }
20874 key = Jim_String(argv[1]);
20875 val = getenv(key);
@@ -19286,12 +20908,13 @@
20908 if (argc != 2) {
20909 Jim_WrongNumArgs(interp, 1, argv, "list");
20910 return JIM_ERR;
20911 }
20912 JimListGetElements(interp, argv[1], &len, &ele);
 
20913 revObjPtr = Jim_NewListObj(interp, NULL, 0);
20914 ListEnsureLength(revObjPtr, len);
20915 len--;
20916 while (len >= 0)
20917 ListAppendElement(revObjPtr, ele[len--]);
20918 Jim_SetResult(interp, revObjPtr);
20919 return JIM_OK;
20920 }
@@ -19329,25 +20952,26 @@
20952 if (argc < 2 || argc > 4) {
20953 Jim_WrongNumArgs(interp, 1, argv, "?start? end ?step?");
20954 return JIM_ERR;
20955 }
20956 if (argc == 2) {
20957 if (Jim_GetWideExpr(interp, argv[1], &end) != JIM_OK)
20958 return JIM_ERR;
20959 }
20960 else {
20961 if (Jim_GetWideExpr(interp, argv[1], &start) != JIM_OK ||
20962 Jim_GetWideExpr(interp, argv[2], &end) != JIM_OK)
20963 return JIM_ERR;
20964 if (argc == 4 && Jim_GetWideExpr(interp, argv[3], &step) != JIM_OK)
20965 return JIM_ERR;
20966 }
20967 if ((len = JimRangeLen(start, end, step)) == -1) {
20968 Jim_SetResultString(interp, "Invalid (infinite?) range specified", -1);
20969 return JIM_ERR;
20970 }
20971 objPtr = Jim_NewListObj(interp, NULL, 0);
20972 ListEnsureLength(objPtr, len);
20973 for (i = 0; i < len; i++)
20974 ListAppendElement(objPtr, Jim_NewIntObj(interp, start + i * step));
20975 Jim_SetResult(interp, objPtr);
20976 return JIM_OK;
20977 }
@@ -19362,15 +20986,15 @@
20986 return JIM_ERR;
20987 }
20988 if (argc == 1) {
20989 max = JIM_WIDE_MAX;
20990 } else if (argc == 2) {
20991 if (Jim_GetWideExpr(interp, argv[1], &max) != JIM_OK)
20992 return JIM_ERR;
20993 } else if (argc == 3) {
20994 if (Jim_GetWideExpr(interp, argv[1], &min) != JIM_OK ||
20995 Jim_GetWideExpr(interp, argv[2], &max) != JIM_OK)
20996 return JIM_ERR;
20997 }
20998 len = max-min;
20999 if (len < 0) {
21000 Jim_SetResultString(interp, "Invalid arguments (max < min)", -1);
@@ -19417,25 +21041,27 @@
21041 {"lappend", Jim_LappendCoreCommand},
21042 {"linsert", Jim_LinsertCoreCommand},
21043 {"lreplace", Jim_LreplaceCoreCommand},
21044 {"lsort", Jim_LsortCoreCommand},
21045 {"append", Jim_AppendCoreCommand},
 
21046 {"eval", Jim_EvalCoreCommand},
21047 {"uplevel", Jim_UplevelCoreCommand},
21048 {"expr", Jim_ExprCoreCommand},
21049 {"break", Jim_BreakCoreCommand},
21050 {"continue", Jim_ContinueCoreCommand},
21051 {"proc", Jim_ProcCoreCommand},
21052 {"xtrace", Jim_XtraceCoreCommand},
21053 {"concat", Jim_ConcatCoreCommand},
21054 {"return", Jim_ReturnCoreCommand},
21055 {"upvar", Jim_UpvarCoreCommand},
21056 {"global", Jim_GlobalCoreCommand},
21057 {"string", Jim_StringCoreCommand},
21058 {"time", Jim_TimeCoreCommand},
21059 {"timerate", Jim_TimeRateCoreCommand},
21060 {"exit", Jim_ExitCoreCommand},
21061 {"catch", Jim_CatchCoreCommand},
21062 {"try", Jim_TryCoreCommand},
21063 #ifdef JIM_REFERENCES
21064 {"ref", Jim_RefCoreCommand},
21065 {"getref", Jim_GetrefCoreCommand},
21066 {"setref", Jim_SetrefCoreCommand},
21067 {"finalize", Jim_FinalizeCoreCommand},
@@ -19460,10 +21086,11 @@
21086 {"rand", Jim_RandCoreCommand},
21087 {"tailcall", Jim_TailcallCoreCommand},
21088 {"local", Jim_LocalCoreCommand},
21089 {"upcall", Jim_UpcallCoreCommand},
21090 {"apply", Jim_ApplyCoreCommand},
21091 {"stacktrace", Jim_StacktraceCoreCommand},
21092 {NULL, NULL},
21093 };
21094
21095 void Jim_RegisterCoreCommands(Jim_Interp *interp)
21096 {
@@ -19687,22 +21314,30 @@
21314 for (i = 0; i < nobjparam; i++) {
21315 Jim_DecrRefCount(interp, objparam[i]);
21316 }
21317 }
21318
21319 int Jim_CheckAbiVersion(Jim_Interp *interp, int abi_version)
21320 {
21321 if (abi_version != JIM_ABI_VERSION) {
21322 Jim_SetResultString(interp, "ABI version mismatch", -1);
21323 return JIM_ERR;
21324 }
21325 return JIM_OK;
21326 }
21327
21328
21329 #ifndef jim_ext_package
21330 int Jim_PackageProvide(Jim_Interp *interp, const char *name, const char *ver, int flags)
21331 {
21332 return JIM_OK;
21333 }
21334 #endif
21335 #ifndef jim_ext_aio
21336 int Jim_AioFilehandle(Jim_Interp *interp, Jim_Obj *fhObj)
21337 {
21338 return -1;
 
21339 }
21340 #endif
21341
21342
21343 #include <stdio.h>
@@ -19717,34 +21352,45 @@
21352
21353 static const jim_subcmd_type dummy_subcmd = {
21354 "dummy", NULL, subcmd_null, 0, 0, JIM_MODFLAG_HIDDEN
21355 };
21356
21357 static Jim_Obj *subcmd_cmd_list(Jim_Interp *interp, const jim_subcmd_type * ct, const char *sep)
21358 {
21359
21360 Jim_Obj *listObj = Jim_NewListObj(interp, NULL, 0);
21361 Jim_Obj *sortCmd[2];
21362
21363 for (; ct->cmd; ct++) {
21364 if (!(ct->flags & JIM_MODFLAG_HIDDEN)) {
21365 Jim_ListAppendElement(interp, listObj, Jim_NewStringObj(interp, ct->cmd, -1));
 
21366 }
21367 }
21368
21369
21370 sortCmd[0] = Jim_NewStringObj(interp, "lsort", -1);
21371 sortCmd[1] = listObj;
21372
21373 if (Jim_EvalObjVector(interp, 2, sortCmd) == JIM_OK) {
21374 return Jim_ListJoin(interp, Jim_GetResult(interp), sep, strlen(sep));
21375 }
21376
21377 return Jim_GetResult(interp);
21378 }
21379
21380 static void bad_subcmd(Jim_Interp *interp, const jim_subcmd_type * command_table, const char *type,
21381 Jim_Obj *cmd, Jim_Obj *subcmd)
21382 {
21383 Jim_SetResultFormatted(interp, "%#s, %s command \"%#s\": should be %#s", cmd, type,
21384 subcmd, subcmd_cmd_list(interp, command_table, ", "));
21385 }
21386
21387 static void show_cmd_usage(Jim_Interp *interp, const jim_subcmd_type * command_table, int argc,
21388 Jim_Obj *const *argv)
21389 {
21390 Jim_SetResultFormatted(interp, "Usage: \"%#s command ... \", where command is one of: %#s",
21391 argv[0], subcmd_cmd_list(interp, command_table, ", "));
21392 }
21393
21394 static void add_cmd_usage(Jim_Interp *interp, const jim_subcmd_type * ct, Jim_Obj *cmd)
21395 {
21396 if (cmd) {
@@ -19754,14 +21400,14 @@
21400 if (ct->args && *ct->args) {
21401 Jim_AppendStrings(interp, Jim_GetResult(interp), " ", ct->args, NULL);
21402 }
21403 }
21404
21405 void Jim_SubCmdArgError(Jim_Interp *interp, const jim_subcmd_type * ct, Jim_Obj *subcmd)
21406 {
21407 Jim_SetResultString(interp, "wrong # args: should be \"", -1);
21408 add_cmd_usage(interp, ct, subcmd);
21409 Jim_AppendStrings(interp, Jim_GetResult(interp), "\"", NULL);
21410 }
21411
21412 static const Jim_ObjType subcmdLookupObjType = {
21413 "subcmd-lookup",
@@ -19778,10 +21424,11 @@
21424 const jim_subcmd_type *partial = 0;
21425 int cmdlen;
21426 Jim_Obj *cmd;
21427 const char *cmdstr;
21428 int help = 0;
21429 int argsok = 1;
21430
21431 if (argc < 2) {
21432 Jim_SetResultFormatted(interp, "wrong # args: should be \"%#s command ...\"\n"
21433 "Use \"%#s -help ?command?\" for help", argv[0], argv[0]);
21434 return 0;
@@ -19810,13 +21457,11 @@
21457 cmd = argv[2];
21458 }
21459
21460
21461 if (Jim_CompareStringImmediate(interp, cmd, "-commands")) {
21462 Jim_SetResult(interp, subcmd_cmd_list(interp, command_table, " "));
 
 
21463 return &dummy_subcmd;
21464 }
21465
21466 cmdstr = Jim_GetString(cmd, &cmdlen);
21467
@@ -19870,11 +21515,22 @@
21515 cmd->internalRep.ptrIntValue.ptr = (void *)command_table;
21516 cmd->internalRep.ptrIntValue.int1 = ct - command_table;
21517
21518 found:
21519
21520
21521 if (argc - 2 < ct->minargs) {
21522 argsok = 0;
21523 }
21524 else if (ct->maxargs >= 0 && argc - 2 > ct->maxargs) {
21525 argsok = 0;
21526 }
21527 else if (ct->maxargs < -1 && (argc - 2) % -ct->maxargs != 0) {
21528
21529 argsok = 0;
21530 }
21531 if (!argsok) {
21532 Jim_SetResultString(interp, "wrong # args: should be \"", -1);
21533
21534 add_cmd_usage(interp, ct, argv[0]);
21535 Jim_AppendStrings(interp, Jim_GetResult(interp), "\"", NULL);
21536
@@ -19895,11 +21551,11 @@
21551 }
21552 else {
21553 ret = ct->function(interp, argc - 2, argv + 2);
21554 }
21555 if (ret < 0) {
21556 Jim_SubCmdArgError(interp, ct, argv[0]);
21557 ret = JIM_ERR;
21558 }
21559 }
21560 return ret;
21561 }
@@ -19946,10 +21602,11 @@
21602 }
21603 }
21604
21605 #include <ctype.h>
21606 #include <string.h>
21607 #include <stdio.h>
21608
21609
21610 #define JIM_INTEGER_SPACE 24
21611 #define MAX_FLOAT_WIDTH 320
21612
@@ -20192,11 +21849,11 @@
21849 }
21850
21851 j = 0;
21852 for (i = length; i > 0; ) {
21853 i--;
21854 if (w & ((unsigned jim_wide)1 << i)) {
21855 num_buffer[j++] = '1';
21856 }
21857 else if (j || i == 0) {
21858 num_buffer[j++] = '0';
21859 }
@@ -20428,11 +22085,11 @@
22085 n++;
22086 }
22087 return n;
22088 }
22089
22090 int jim_regcomp(regex_t *preg, const char *exp, int cflags)
22091 {
22092 int scan;
22093 int longest;
22094 unsigned len;
22095 int flags;
@@ -20843,11 +22500,11 @@
22500 if (*pattern == ']' || *pattern == '-') {
22501 reg_addrange(preg, *pattern, *pattern);
22502 pattern++;
22503 }
22504
22505 while (*pattern != ']') {
22506
22507 int start;
22508 int end;
22509
22510 enum {
@@ -20854,10 +22511,15 @@
22511 CC_ALPHA, CC_ALNUM, CC_SPACE, CC_BLANK, CC_UPPER, CC_LOWER,
22512 CC_DIGIT, CC_XDIGIT, CC_CNTRL, CC_GRAPH, CC_PRINT, CC_PUNCT,
22513 CC_NUM
22514 };
22515 int cc;
22516
22517 if (!*pattern) {
22518 preg->err = REG_ERR_UNMATCHED_BRACKET;
22519 return 0;
22520 }
22521
22522 pattern += reg_utf8_tounicode_case(pattern, &start, nocase);
22523 if (start == '\\') {
22524
22525 switch (*pattern) {
@@ -20878,10 +22540,14 @@
22540 pattern += reg_decode_escape(pattern, &start);
22541 if (start == 0) {
22542 preg->err = REG_ERR_NULL_CHAR;
22543 return 0;
22544 }
22545 if (start == '\\' && *pattern == 0) {
22546 preg->err = REG_ERR_INVALID_ESCAPE;
22547 return 0;
22548 }
22549 }
22550 if (pattern[0] == '-' && pattern[1] && pattern[1] != ']') {
22551
22552 pattern += utf8_tounicode(pattern, &end);
22553 pattern += reg_utf8_tounicode_case(pattern, &end, nocase);
@@ -20888,10 +22554,14 @@
22554 if (end == '\\') {
22555 pattern += reg_decode_escape(pattern, &end);
22556 if (end == 0) {
22557 preg->err = REG_ERR_NULL_CHAR;
22558 return 0;
22559 }
22560 if (end == '\\' && *pattern == 0) {
22561 preg->err = REG_ERR_INVALID_ESCAPE;
22562 return 0;
22563 }
22564 }
22565
22566 reg_addrange(preg, start, end);
22567 continue;
@@ -20903,10 +22573,14 @@
22573 };
22574
22575 for (cc = 0; cc < CC_NUM; cc++) {
22576 n = strlen(character_class[cc]);
22577 if (strncmp(pattern, character_class[cc], n) == 0) {
22578 if (pattern[n] != ']') {
22579 preg->err = REG_ERR_UNMATCHED_BRACKET;
22580 return 0;
22581 }
22582
22583 pattern += n + 1;
22584 break;
22585 }
22586 }
@@ -20993,11 +22667,11 @@
22667 return 0;
22668 case '\\':
22669 ch = *preg->regparse++;
22670 switch (ch) {
22671 case '\0':
22672 preg->err = REG_ERR_INVALID_ESCAPE;
22673 return 0;
22674 case 'A':
22675 ret = regnode(preg, BOLX);
22676 break;
22677 case 'Z':
@@ -21180,11 +22854,11 @@
22854
22855 static int regtry(regex_t *preg, const char *string );
22856 static int regmatch(regex_t *preg, int prog);
22857 static int regrepeat(regex_t *preg, int p, int max);
22858
22859 int jim_regexec(regex_t *preg, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags)
22860 {
22861 const char *s;
22862 int scan;
22863
22864
@@ -21521,11 +23195,11 @@
23195 break;
23196 case WORDZ:
23197
23198 if (preg->reginput > preg->regbol) {
23199
23200 if (reg_iseol(preg, c) || !(isalnum(UCHAR(c)) || c == '_')) {
23201 c = preg->reginput[-1];
23202
23203 if (isalnum(UCHAR(c)) || c == '_') {
23204 break;
23205 }
@@ -21617,10 +23291,12 @@
23291 preg->pmatch[no].rm_eo = save - preg->start;
23292 }
23293 }
23294 return(1);
23295 }
23296
23297 preg->reginput = save;
23298 return(0);
23299 }
23300 return REG_ERR_INTERNAL;
23301 }
23302
@@ -21640,14 +23316,13 @@
23316
23317 scan = preg->reginput;
23318 opnd = OPERAND(p);
23319 switch (OP(preg, p)) {
23320 case ANY:
 
23321 while (!reg_iseol(preg, *scan) && count < max) {
23322 count++;
23323 scan += utf8_charlen(*scan);
23324 }
23325 break;
23326 case EXACTLY:
23327 while (count < max) {
23328 n = reg_utf8_tounicode_case(scan, &ch, preg->cflags & REG_ICASE);
@@ -21724,11 +23399,11 @@
23399 }
23400 return 2;
23401 }
23402
23403
23404 size_t jim_regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)
23405 {
23406 static const char *error_strings[] = {
23407 "success",
23408 "no match",
23409 "bad pattern",
@@ -21743,13 +23418,14 @@
23418 "extra characters",
23419 "*+ of empty atom",
23420 "nested count",
23421 "internal error",
23422 "count follows nothing",
23423 "invalid escape \\ sequence",
23424 "corrupted program",
23425 "contains null char",
23426 "brackets [] not balanced",
23427 };
23428 const char *err;
23429
23430 if (errcode < 0 || errcode >= REG_ERR_NUM) {
23431 err = "Bad error code";
@@ -21759,11 +23435,11 @@
23435 }
23436
23437 return snprintf(errbuf, errbuf_size, "%s", err);
23438 }
23439
23440 void jim_regfree(regex_t *preg)
23441 {
23442 free(preg->program);
23443 }
23444
23445 #endif
@@ -21856,20 +23532,46 @@
23532 case ERROR_DIRECTORY: return ENOTDIR;
23533 }
23534 return EINVAL;
23535 }
23536
23537 long JimProcessPid(phandle_t pid)
23538 {
23539 if (pid == INVALID_HANDLE_VALUE) {
23540 return -1;
23541 }
23542 return GetProcessId(pid);
23543 }
23544
23545 phandle_t JimWaitPid(long pid, int *status, int nohang)
23546 {
23547 if (pid > 0) {
23548 HANDLE h = OpenProcess(PROCESS_QUERY_INFORMATION | SYNCHRONIZE, FALSE, pid);
23549 if (h) {
23550 long pid = waitpid(h, status, nohang);
23551 CloseHandle(h);
23552 if (pid > 0) {
23553 return h;
23554 }
23555 }
23556 }
23557 return JIM_BAD_PHANDLE;
23558 }
23559
23560 long waitpid(phandle_t phandle, int *status, int nohang)
23561 {
23562 long pid;
23563 DWORD ret = WaitForSingleObject(phandle, nohang ? 0 : INFINITE);
23564 if (ret == WAIT_TIMEOUT || ret == WAIT_FAILED) {
23565
23566 return -1;
23567 }
23568 GetExitCodeProcess(phandle, &ret);
23569 *status = ret;
23570
23571 pid = GetProcessId(phandle);
23572 CloseHandle(phandle);
23573 return pid;
23574 }
23575
23576 int Jim_MakeTempFile(Jim_Interp *interp, const char *filename_template, int unlink_file)
23577 {
@@ -21887,11 +23589,11 @@
23589 if (handle == INVALID_HANDLE_VALUE) {
23590 goto error;
23591 }
23592
23593 Jim_SetResultString(interp, name, -1);
23594 return _open_osfhandle((intptr_t)handle, _O_RDWR | _O_TEXT);
23595
23596 error:
23597 Jim_SetResultErrno(interp, name);
23598 DeleteFile(name);
23599 return -1;
@@ -22125,10 +23827,11 @@
23827 return buf;
23828 }
23829 #ifndef JIM_BOOTSTRAP_LIB_ONLY
23830 #include <errno.h>
23831 #include <string.h>
23832 #include <stdio.h>
23833
23834
23835 #ifdef USE_LINENOISE
23836 #ifdef HAVE_UNISTD_H
23837 #include <unistd.h>
@@ -22140,42 +23843,58 @@
23843 #else
23844 #define MAX_LINE_LEN 512
23845 #endif
23846
23847 #ifdef USE_LINENOISE
23848 struct JimCompletionInfo {
23849 Jim_Interp *interp;
23850 Jim_Obj *completion_command;
23851 Jim_Obj *hints_command;
23852
23853 };
23854
23855 static struct JimCompletionInfo *JimGetCompletionInfo(Jim_Interp *interp);
23856 static void JimCompletionCallback(const char *prefix, linenoiseCompletions *comp, void *userdata);
23857 static const char completion_callback_assoc_key[] = "interactive-completion";
23858 static char *JimHintsCallback(const char *prefix, int *color, int *bold, void *userdata);
23859 static void JimFreeHintsCallback(void *hint, void *userdata);
23860 #endif
23861
23862 char *Jim_HistoryGetline(Jim_Interp *interp, const char *prompt)
23863 {
23864 #ifdef USE_LINENOISE
23865 struct JimCompletionInfo *compinfo = JimGetCompletionInfo(interp);
23866 char *result;
23867 Jim_Obj *objPtr;
23868 long mlmode = 0;
23869 if (compinfo->completion_command) {
23870 linenoiseSetCompletionCallback(JimCompletionCallback, compinfo);
23871 }
23872 if (compinfo->hints_command) {
23873 linenoiseSetHintsCallback(JimHintsCallback, compinfo);
23874 linenoiseSetFreeHintsCallback(JimFreeHintsCallback);
23875 }
23876 objPtr = Jim_GetVariableStr(interp, "history::multiline", JIM_NONE);
23877 if (objPtr && Jim_GetLong(interp, objPtr, &mlmode) == JIM_NONE) {
23878 linenoiseSetMultiLine(mlmode);
23879 }
23880
23881 result = linenoise(prompt);
23882
23883 linenoiseSetCompletionCallback(NULL, NULL);
23884 linenoiseSetHintsCallback(NULL, NULL);
23885 linenoiseSetFreeHintsCallback(NULL);
23886 return result;
23887 #else
23888 int len;
23889 char *line = Jim_Alloc(MAX_LINE_LEN);
23890
23891 fputs(prompt, stdout);
23892 fflush(stdout);
23893
23894 if (fgets(line, MAX_LINE_LEN, stdin) == NULL) {
23895 Jim_Free(line);
23896 return NULL;
23897 }
23898 len = strlen(line);
23899 if (len && line[len - 1] == '\n') {
23900 line[len - 1] = '\0';
@@ -22224,23 +23943,33 @@
23943 printf("%4d %s\n", i + 1, history[i]);
23944 }
23945 #endif
23946 }
23947
23948 void Jim_HistorySetMaxLen(int length)
23949 {
23950 #ifdef USE_LINENOISE
23951 linenoiseHistorySetMaxLen(length);
23952 #endif
23953 }
23954
23955 int Jim_HistoryGetMaxLen(void)
23956 {
23957 #ifdef USE_LINENOISE
23958 return linenoiseHistoryGetMaxLen();
23959 #endif
23960 return 0;
23961 }
23962
23963 #ifdef USE_LINENOISE
23964 static void JimCompletionCallback(const char *prefix, linenoiseCompletions *comp, void *userdata)
23965 {
23966 struct JimCompletionInfo *info = (struct JimCompletionInfo *)userdata;
23967 Jim_Obj *objv[2];
23968 int ret;
23969
23970 objv[0] = info->completion_command;
23971 objv[1] = Jim_NewStringObj(info->interp, prefix, -1);
23972
23973 ret = Jim_EvalObjVector(info->interp, 2, objv);
23974
23975
@@ -22251,38 +23980,106 @@
23980 for (i = 0; i < len; i++) {
23981 linenoiseAddCompletion(comp, Jim_String(Jim_ListGetIndex(info->interp, listObj, i)));
23982 }
23983 }
23984 }
23985
23986 static char *JimHintsCallback(const char *prefix, int *color, int *bold, void *userdata)
23987 {
23988 struct JimCompletionInfo *info = (struct JimCompletionInfo *)userdata;
23989 Jim_Obj *objv[2];
23990 int ret;
23991 char *result = NULL;
23992
23993 objv[0] = info->hints_command;
23994 objv[1] = Jim_NewStringObj(info->interp, prefix, -1);
23995
23996 ret = Jim_EvalObjVector(info->interp, 2, objv);
23997
23998
23999 if (ret == JIM_OK) {
24000 Jim_Obj *listObj = Jim_GetResult(info->interp);
24001 Jim_IncrRefCount(listObj);
24002
24003 int len = Jim_ListLength(info->interp, listObj);
24004 if (len >= 1) {
24005 long x;
24006 result = Jim_StrDup(Jim_String(Jim_ListGetIndex(info->interp, listObj, 0)));
24007 if (len >= 2 && Jim_GetLong(info->interp, Jim_ListGetIndex(info->interp, listObj, 1), &x) == JIM_OK) {
24008 *color = x;
24009 }
24010 if (len >= 3 && Jim_GetLong(info->interp, Jim_ListGetIndex(info->interp, listObj, 2), &x) == JIM_OK) {
24011 *bold = x;
24012 }
24013 }
24014 Jim_DecrRefCount(info->interp, listObj);
24015 }
24016 return result;
24017 }
24018
24019 static void JimFreeHintsCallback(void *hint, void *userdata)
24020 {
24021 Jim_Free(hint);
24022 }
24023
24024 static void JimHistoryFreeCompletion(Jim_Interp *interp, void *data)
24025 {
24026 struct JimCompletionInfo *compinfo = data;
24027
24028 if (compinfo->completion_command) {
24029 Jim_DecrRefCount(interp, compinfo->completion_command);
24030 }
24031 if (compinfo->hints_command) {
24032 Jim_DecrRefCount(interp, compinfo->hints_command);
24033 }
24034
24035 Jim_Free(compinfo);
24036 }
24037
24038 static struct JimCompletionInfo *JimGetCompletionInfo(Jim_Interp *interp)
24039 {
24040 struct JimCompletionInfo *compinfo = Jim_GetAssocData(interp, completion_callback_assoc_key);
24041 if (compinfo == NULL) {
24042 compinfo = Jim_Alloc(sizeof(*compinfo));
 
 
 
 
 
 
 
 
24043 compinfo->interp = interp;
24044 compinfo->completion_command = NULL;
24045 compinfo->hints_command = NULL;
24046 Jim_SetAssocData(interp, completion_callback_assoc_key, JimHistoryFreeCompletion, compinfo);
24047 }
24048 return compinfo;
24049 }
24050 #endif
24051
24052 void Jim_HistorySetCompletion(Jim_Interp *interp, Jim_Obj *completionCommandObj)
24053 {
24054 #ifdef USE_LINENOISE
24055 struct JimCompletionInfo *compinfo = JimGetCompletionInfo(interp);
24056
24057 if (completionCommandObj) {
24058
24059 Jim_IncrRefCount(completionCommandObj);
24060 }
24061 if (compinfo->completion_command) {
24062 Jim_DecrRefCount(interp, compinfo->completion_command);
24063 }
24064 compinfo->completion_command = completionCommandObj;
24065 #endif
24066 }
24067
24068 void Jim_HistorySetHints(Jim_Interp *interp, Jim_Obj *hintsCommandObj)
24069 {
24070 #ifdef USE_LINENOISE
24071 struct JimCompletionInfo *compinfo = JimGetCompletionInfo(interp);
24072
24073 if (hintsCommandObj) {
24074
24075 Jim_IncrRefCount(hintsCommandObj);
24076 }
24077 if (compinfo->hints_command) {
24078 Jim_DecrRefCount(interp, compinfo->hints_command);
24079 }
24080 compinfo->hints_command = hintsCommandObj;
24081 #endif
24082 }
24083
24084 int Jim_InteractivePrompt(Jim_Interp *interp)
24085 {
@@ -22298,10 +24095,11 @@
24095 snprintf(history_file, history_len, "%s/.jim_history", home);
24096 Jim_HistoryLoad(history_file);
24097 }
24098
24099 Jim_HistorySetCompletion(interp, Jim_NewStringObj(interp, "tcl::autocomplete", -1));
24100 Jim_HistorySetHints(interp, Jim_NewStringObj(interp, "tcl::stdhint", -1));
24101 #endif
24102
24103 printf("Welcome to Jim version %d.%d\n",
24104 JIM_VERSION / 100, JIM_VERSION % 100);
24105 Jim_SetVariableStrWithStr(interp, JIM_INTERACTIVE, "1");
@@ -22344,11 +24142,11 @@
24142 if (Jim_Length(scriptObjPtr) != 0) {
24143
24144 Jim_AppendString(interp, scriptObjPtr, "\n", 1);
24145 }
24146 Jim_AppendString(interp, scriptObjPtr, line, -1);
24147 Jim_Free(line);
24148 if (Jim_ScriptIsComplete(interp, scriptObjPtr, &state))
24149 break;
24150
24151 snprintf(prompt, sizeof(prompt), "%c> ", state);
24152 }
@@ -22374,11 +24172,14 @@
24172 if (retcode == JIM_ERR) {
24173 Jim_MakeErrorMessage(interp);
24174 }
24175 result = Jim_GetString(Jim_GetResult(interp), &reslen);
24176 if (reslen) {
24177 if (fwrite(result, reslen, 1, stdout) == 0) {
24178
24179 }
24180 putchar('\n');
24181 }
24182 }
24183 out:
24184 Jim_Free(history_file);
24185
@@ -22476,11 +24277,16 @@
24277 if (argc > 2 && strcmp(argv[1], "-e") == 0) {
24278
24279 JimSetArgv(interp, argc - 3, argv + 3);
24280 retcode = Jim_Eval(interp, argv[2]);
24281 if (retcode != JIM_ERR) {
24282 int len;
24283 const char *msg = Jim_GetString(Jim_GetResult(interp), &len);
24284 if (fwrite(msg, len, 1, stdout) == 0) {
24285
24286 }
24287 putchar('\n');
24288 }
24289 }
24290 else {
24291 Jim_SetVariableStr(interp, "argv0", Jim_NewStringObj(interp, argv[1], -1));
24292 JimSetArgv(interp, argc - 2, argv + 2);
24293
--- autosetup/pkg-config.tcl
+++ autosetup/pkg-config.tcl
@@ -13,11 +13,11 @@
1313
#
1414
# 'PKG_CONFIG' may be set to use an alternative to 'pkg-config'.
1515
1616
use cc
1717
18
-module-options {
18
+options {
1919
sysroot:dir => "Override compiler sysroot for pkg-config search path"
2020
}
2121
2222
# @pkg-config-init ?required?
2323
#
@@ -51,15 +51,16 @@
5151
5252
if {[opt-str sysroot o]} {
5353
define SYSROOT [file-normalize $o]
5454
msg-result "Using specified sysroot [get-define SYSROOT]"
5555
} elseif {[get-define build] ne [get-define host]} {
56
- if {[catch {exec-with-stderr [get-define CC] -print-sysroot} result errinfo] == 0} {
56
+ if {[catch {exec-with-stderr {*}[get-define CC] -print-sysroot} result errinfo] == 0} {
5757
# Use the compiler sysroot, if there is one
5858
define SYSROOT $result
5959
msg-result "Found compiler sysroot $result"
6060
} else {
61
+ configlog "[get-define CC] -print-sysroot: $result"
6162
set msg "pkg-config: Cross compiling, but no compiler sysroot and no --sysroot supplied"
6263
if {$required} {
6364
user-error $msg
6465
} else {
6566
msg-result $msg
@@ -71,10 +72,13 @@
7172
set sysroot [get-define SYSROOT]
7273
7374
# XXX: It's possible that these should be set only when invoking pkg-config
7475
global env
7576
set env(PKG_CONFIG_DIR) ""
77
+ # Supposedly setting PKG_CONFIG_LIBDIR means that PKG_CONFIG_PATH is ignored,
78
+ # but it doesn't seem to work that way in practice
79
+ set env(PKG_CONFIG_PATH) ""
7680
# Do we need to try /usr/local as well or instead?
7781
set env(PKG_CONFIG_LIBDIR) $sysroot/usr/lib/pkgconfig:$sysroot/usr/share/pkgconfig
7882
set env(PKG_CONFIG_SYSROOT_DIR) $sysroot
7983
}
8084
}
@@ -106,22 +110,34 @@
106110
if {!$ok} {
107111
msg-result "no pkg-config"
108112
return 0
109113
}
110114
111
- if {[catch {exec [get-define PKG_CONFIG] --modversion "$module $args"} version]} {
115
+ set pkgconfig [get-define PKG_CONFIG]
116
+
117
+ set ret [catch {exec $pkgconfig --modversion "$module $args"} version]
118
+ configlog "$pkgconfig --modversion $module $args: $version"
119
+ if {$ret} {
112120
msg-result "not found"
113
- configlog "pkg-config --modversion $module $args: $version"
121
+ return 0
122
+ }
123
+ # Sometimes --modversion succeeds but because of dependencies it isn't usable
124
+ # This seems to show up with --cflags
125
+ set ret [catch {exec $pkgconfig --cflags $module} cflags]
126
+ if {$ret} {
127
+ msg-result "unusable ($version - see config.log)"
128
+ configlog "$pkgconfig --cflags $module"
129
+ configlog $cflags
114130
return 0
115131
}
116132
msg-result $version
117133
set prefix [feature-define-name $module PKG_]
118134
define HAVE_${prefix}
119135
define ${prefix}_VERSION $version
120
- define ${prefix}_LIBS [exec pkg-config --libs-only-l $module]
121
- define ${prefix}_LDFLAGS [exec pkg-config --libs-only-L $module]
122
- define ${prefix}_CFLAGS [exec pkg-config --cflags $module]
136
+ define ${prefix}_CFLAGS $cflags
137
+ define ${prefix}_LIBS [exec $pkgconfig --libs-only-l $module]
138
+ define ${prefix}_LDFLAGS [exec $pkgconfig --libs-only-L $module]
123139
return 1
124140
}
125141
126142
# @pkg-config-get module setting
127143
#
@@ -131,5 +147,22 @@
131147
# the value of 'PKG_PANGO_CFLAGS', or '""' if not defined.
132148
proc pkg-config-get {module name} {
133149
set prefix [feature-define-name $module PKG_]
134150
get-define ${prefix}_${name} ""
135151
}
152
+
153
+# @pkg-config-get-var module variable
154
+#
155
+# Return the value of the given variable from the given pkg-config module.
156
+# The module must already have been successfully detected with pkg-config.
157
+# e.g.
158
+#
159
+## if {[pkg-config harfbuzz >= 2.5]} {
160
+## define harfbuzz_libdir [pkg-config-get-var harfbuzz libdir]
161
+## }
162
+#
163
+# Returns the empty string if the variable isn't defined.
164
+proc pkg-config-get-var {module variable} {
165
+ set pkgconfig [get-define PKG_CONFIG]
166
+ set prefix [feature-define-name $module HAVE_PKG_]
167
+ exec $pkgconfig $module --variable $variable
168
+}
136169
--- autosetup/pkg-config.tcl
+++ autosetup/pkg-config.tcl
@@ -13,11 +13,11 @@
13 #
14 # 'PKG_CONFIG' may be set to use an alternative to 'pkg-config'.
15
16 use cc
17
18 module-options {
19 sysroot:dir => "Override compiler sysroot for pkg-config search path"
20 }
21
22 # @pkg-config-init ?required?
23 #
@@ -51,15 +51,16 @@
51
52 if {[opt-str sysroot o]} {
53 define SYSROOT [file-normalize $o]
54 msg-result "Using specified sysroot [get-define SYSROOT]"
55 } elseif {[get-define build] ne [get-define host]} {
56 if {[catch {exec-with-stderr [get-define CC] -print-sysroot} result errinfo] == 0} {
57 # Use the compiler sysroot, if there is one
58 define SYSROOT $result
59 msg-result "Found compiler sysroot $result"
60 } else {
 
61 set msg "pkg-config: Cross compiling, but no compiler sysroot and no --sysroot supplied"
62 if {$required} {
63 user-error $msg
64 } else {
65 msg-result $msg
@@ -71,10 +72,13 @@
71 set sysroot [get-define SYSROOT]
72
73 # XXX: It's possible that these should be set only when invoking pkg-config
74 global env
75 set env(PKG_CONFIG_DIR) ""
 
 
 
76 # Do we need to try /usr/local as well or instead?
77 set env(PKG_CONFIG_LIBDIR) $sysroot/usr/lib/pkgconfig:$sysroot/usr/share/pkgconfig
78 set env(PKG_CONFIG_SYSROOT_DIR) $sysroot
79 }
80 }
@@ -106,22 +110,34 @@
106 if {!$ok} {
107 msg-result "no pkg-config"
108 return 0
109 }
110
111 if {[catch {exec [get-define PKG_CONFIG] --modversion "$module $args"} version]} {
 
 
 
 
112 msg-result "not found"
113 configlog "pkg-config --modversion $module $args: $version"
 
 
 
 
 
 
 
 
114 return 0
115 }
116 msg-result $version
117 set prefix [feature-define-name $module PKG_]
118 define HAVE_${prefix}
119 define ${prefix}_VERSION $version
120 define ${prefix}_LIBS [exec pkg-config --libs-only-l $module]
121 define ${prefix}_LDFLAGS [exec pkg-config --libs-only-L $module]
122 define ${prefix}_CFLAGS [exec pkg-config --cflags $module]
123 return 1
124 }
125
126 # @pkg-config-get module setting
127 #
@@ -131,5 +147,22 @@
131 # the value of 'PKG_PANGO_CFLAGS', or '""' if not defined.
132 proc pkg-config-get {module name} {
133 set prefix [feature-define-name $module PKG_]
134 get-define ${prefix}_${name} ""
135 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
--- autosetup/pkg-config.tcl
+++ autosetup/pkg-config.tcl
@@ -13,11 +13,11 @@
13 #
14 # 'PKG_CONFIG' may be set to use an alternative to 'pkg-config'.
15
16 use cc
17
18 options {
19 sysroot:dir => "Override compiler sysroot for pkg-config search path"
20 }
21
22 # @pkg-config-init ?required?
23 #
@@ -51,15 +51,16 @@
51
52 if {[opt-str sysroot o]} {
53 define SYSROOT [file-normalize $o]
54 msg-result "Using specified sysroot [get-define SYSROOT]"
55 } elseif {[get-define build] ne [get-define host]} {
56 if {[catch {exec-with-stderr {*}[get-define CC] -print-sysroot} result errinfo] == 0} {
57 # Use the compiler sysroot, if there is one
58 define SYSROOT $result
59 msg-result "Found compiler sysroot $result"
60 } else {
61 configlog "[get-define CC] -print-sysroot: $result"
62 set msg "pkg-config: Cross compiling, but no compiler sysroot and no --sysroot supplied"
63 if {$required} {
64 user-error $msg
65 } else {
66 msg-result $msg
@@ -71,10 +72,13 @@
72 set sysroot [get-define SYSROOT]
73
74 # XXX: It's possible that these should be set only when invoking pkg-config
75 global env
76 set env(PKG_CONFIG_DIR) ""
77 # Supposedly setting PKG_CONFIG_LIBDIR means that PKG_CONFIG_PATH is ignored,
78 # but it doesn't seem to work that way in practice
79 set env(PKG_CONFIG_PATH) ""
80 # Do we need to try /usr/local as well or instead?
81 set env(PKG_CONFIG_LIBDIR) $sysroot/usr/lib/pkgconfig:$sysroot/usr/share/pkgconfig
82 set env(PKG_CONFIG_SYSROOT_DIR) $sysroot
83 }
84 }
@@ -106,22 +110,34 @@
110 if {!$ok} {
111 msg-result "no pkg-config"
112 return 0
113 }
114
115 set pkgconfig [get-define PKG_CONFIG]
116
117 set ret [catch {exec $pkgconfig --modversion "$module $args"} version]
118 configlog "$pkgconfig --modversion $module $args: $version"
119 if {$ret} {
120 msg-result "not found"
121 return 0
122 }
123 # Sometimes --modversion succeeds but because of dependencies it isn't usable
124 # This seems to show up with --cflags
125 set ret [catch {exec $pkgconfig --cflags $module} cflags]
126 if {$ret} {
127 msg-result "unusable ($version - see config.log)"
128 configlog "$pkgconfig --cflags $module"
129 configlog $cflags
130 return 0
131 }
132 msg-result $version
133 set prefix [feature-define-name $module PKG_]
134 define HAVE_${prefix}
135 define ${prefix}_VERSION $version
136 define ${prefix}_CFLAGS $cflags
137 define ${prefix}_LIBS [exec $pkgconfig --libs-only-l $module]
138 define ${prefix}_LDFLAGS [exec $pkgconfig --libs-only-L $module]
139 return 1
140 }
141
142 # @pkg-config-get module setting
143 #
@@ -131,5 +147,22 @@
147 # the value of 'PKG_PANGO_CFLAGS', or '""' if not defined.
148 proc pkg-config-get {module name} {
149 set prefix [feature-define-name $module PKG_]
150 get-define ${prefix}_${name} ""
151 }
152
153 # @pkg-config-get-var module variable
154 #
155 # Return the value of the given variable from the given pkg-config module.
156 # The module must already have been successfully detected with pkg-config.
157 # e.g.
158 #
159 ## if {[pkg-config harfbuzz >= 2.5]} {
160 ## define harfbuzz_libdir [pkg-config-get-var harfbuzz libdir]
161 ## }
162 #
163 # Returns the empty string if the variable isn't defined.
164 proc pkg-config-get-var {module variable} {
165 set pkgconfig [get-define PKG_CONFIG]
166 set prefix [feature-define-name $module HAVE_PKG_]
167 exec $pkgconfig $module --variable $variable
168 }
169
--- autosetup/system.tcl
+++ autosetup/system.tcl
@@ -17,19 +17,19 @@
1717
## localstatedir
1818
## infodir
1919
## mandir
2020
## includedir
2121
#
22
-# If '--prefix' is not supplied, it defaults to '/usr/local' unless 'defaultprefix' is defined *before*
22
+# If '--prefix' is not supplied, it defaults to '/usr/local' unless 'options-defaults { prefix ... }' is used *before*
2323
# including the 'system' module.
2424
2525
if {[is-defined defaultprefix]} {
2626
user-notice "Note: defaultprefix is deprecated. Use options-defaults to set default options"
2727
options-defaults [list prefix [get-define defaultprefix]]
2828
}
2929
30
-module-options [subst -noc -nob {
30
+options {
3131
host:host-alias => {a complete or partial cpu-vendor-opsys for the system where
3232
the application will run (defaults to the same value as --build)}
3333
build:build-alias => {a complete or partial cpu-vendor-opsys for the system
3434
where the application will be built (defaults to the
3535
result of running config.guess)}
@@ -50,11 +50,14 @@
5050
localstatedir:
5151
runstatedir:
5252
maintainer-mode=0
5353
dependency-tracking=0
5454
silent-rules=0
55
-}]
55
+ program-prefix:
56
+ program-suffix:
57
+ program-transform-name:
58
+}
5659
5760
# @check-feature name { script }
5861
#
5962
# defines feature '$name' to the return value of '$script',
6063
# which should be 1 if found or 0 if not found.
@@ -204,25 +207,27 @@
204207
}
205208
lpop condstack
206209
}
207210
}
208211
continue
209
- } elseif {[regexp {^@include\s+(.*)} $line -> filearg]} {
212
+ }
213
+ # Only continue if the stack contains all "true"
214
+ if {"0" in $condstack} {
215
+ continue
216
+ }
217
+ if {[regexp {^@include\s+(.*)} $line -> filearg]} {
210218
set incfile [string map $mapping $filearg]
211219
if {[file exists $incfile]} {
212220
lappend ::autosetup(deps) [file-normalize $incfile]
213221
lappend result {*}[include-file $incfile $mapping]
214222
} else {
215223
user-error "$infile:$linenum: Include file $incfile is missing"
216224
}
217225
continue
218
- } elseif {[regexp {^@define\s+(\w+)\s+(.*)} $line -> var val]} {
219
- define $var $val
220
- continue
221226
}
222
- # Only output this line if the stack contains all "true"
223
- if {"0" in $condstack} {
227
+ if {[regexp {^@define\s+(\w+)\s+(.*)} $line -> var val]} {
228
+ define $var $val
224229
continue
225230
}
226231
lappend result $line
227232
}
228233
return $result
229234
--- autosetup/system.tcl
+++ autosetup/system.tcl
@@ -17,19 +17,19 @@
17 ## localstatedir
18 ## infodir
19 ## mandir
20 ## includedir
21 #
22 # If '--prefix' is not supplied, it defaults to '/usr/local' unless 'defaultprefix' is defined *before*
23 # including the 'system' module.
24
25 if {[is-defined defaultprefix]} {
26 user-notice "Note: defaultprefix is deprecated. Use options-defaults to set default options"
27 options-defaults [list prefix [get-define defaultprefix]]
28 }
29
30 module-options [subst -noc -nob {
31 host:host-alias => {a complete or partial cpu-vendor-opsys for the system where
32 the application will run (defaults to the same value as --build)}
33 build:build-alias => {a complete or partial cpu-vendor-opsys for the system
34 where the application will be built (defaults to the
35 result of running config.guess)}
@@ -50,11 +50,14 @@
50 localstatedir:
51 runstatedir:
52 maintainer-mode=0
53 dependency-tracking=0
54 silent-rules=0
55 }]
 
 
 
56
57 # @check-feature name { script }
58 #
59 # defines feature '$name' to the return value of '$script',
60 # which should be 1 if found or 0 if not found.
@@ -204,25 +207,27 @@
204 }
205 lpop condstack
206 }
207 }
208 continue
209 } elseif {[regexp {^@include\s+(.*)} $line -> filearg]} {
 
 
 
 
 
210 set incfile [string map $mapping $filearg]
211 if {[file exists $incfile]} {
212 lappend ::autosetup(deps) [file-normalize $incfile]
213 lappend result {*}[include-file $incfile $mapping]
214 } else {
215 user-error "$infile:$linenum: Include file $incfile is missing"
216 }
217 continue
218 } elseif {[regexp {^@define\s+(\w+)\s+(.*)} $line -> var val]} {
219 define $var $val
220 continue
221 }
222 # Only output this line if the stack contains all "true"
223 if {"0" in $condstack} {
224 continue
225 }
226 lappend result $line
227 }
228 return $result
229
--- autosetup/system.tcl
+++ autosetup/system.tcl
@@ -17,19 +17,19 @@
17 ## localstatedir
18 ## infodir
19 ## mandir
20 ## includedir
21 #
22 # If '--prefix' is not supplied, it defaults to '/usr/local' unless 'options-defaults { prefix ... }' is used *before*
23 # including the 'system' module.
24
25 if {[is-defined defaultprefix]} {
26 user-notice "Note: defaultprefix is deprecated. Use options-defaults to set default options"
27 options-defaults [list prefix [get-define defaultprefix]]
28 }
29
30 options {
31 host:host-alias => {a complete or partial cpu-vendor-opsys for the system where
32 the application will run (defaults to the same value as --build)}
33 build:build-alias => {a complete or partial cpu-vendor-opsys for the system
34 where the application will be built (defaults to the
35 result of running config.guess)}
@@ -50,11 +50,14 @@
50 localstatedir:
51 runstatedir:
52 maintainer-mode=0
53 dependency-tracking=0
54 silent-rules=0
55 program-prefix:
56 program-suffix:
57 program-transform-name:
58 }
59
60 # @check-feature name { script }
61 #
62 # defines feature '$name' to the return value of '$script',
63 # which should be 1 if found or 0 if not found.
@@ -204,25 +207,27 @@
207 }
208 lpop condstack
209 }
210 }
211 continue
212 }
213 # Only continue if the stack contains all "true"
214 if {"0" in $condstack} {
215 continue
216 }
217 if {[regexp {^@include\s+(.*)} $line -> filearg]} {
218 set incfile [string map $mapping $filearg]
219 if {[file exists $incfile]} {
220 lappend ::autosetup(deps) [file-normalize $incfile]
221 lappend result {*}[include-file $incfile $mapping]
222 } else {
223 user-error "$infile:$linenum: Include file $incfile is missing"
224 }
225 continue
 
 
 
226 }
227 if {[regexp {^@define\s+(\w+)\s+(.*)} $line -> var val]} {
228 define $var $val
229 continue
230 }
231 lappend result $line
232 }
233 return $result
234
--- autosetup/tmake.auto
+++ autosetup/tmake.auto
@@ -47,9 +47,27 @@
4747
# And don't process this file any further
4848
ifconfig false
4949
}
5050
}
5151
52
+ set configure [readfile configure]
53
+ # XXX Do we need also need to support a system install of tmake?
54
+ if {[string first {#@TMAKEUPDATED@} $configure] < 0} {
55
+ if {[regsub {#@@INITCHECK@@#} $configure \
56
+ {test -z "$TMAKE" -a -x "$dir/tmake" \&\& exec "$dir/tmake" --force --configure "$@"; #@TMAKEUPDATED@} configure]} {
57
+ writefile configure $configure\n
58
+ exec chmod +x configure
59
+ puts "Updated configure to invoke local tmake."
60
+ if {![file exec autosetup/tmake]} {
61
+ puts "Warning: autosetup/tmake is missing."
62
+ puts " Install it with: tmake --install=autosetup"
63
+ }
64
+ } else {
65
+ puts "Warning: configure isn't created by a recent autosetup, not updating."
66
+ }
67
+ } else {
68
+ puts "I see configure for tmake already exists."
69
+ }
5270
if {![file exists build.spec]} {
5371
puts "Note: I don't see build.spec. Try running: tmake --genie"
5472
}
5573
}
5674
--- autosetup/tmake.auto
+++ autosetup/tmake.auto
@@ -47,9 +47,27 @@
47 # And don't process this file any further
48 ifconfig false
49 }
50 }
51
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52 if {![file exists build.spec]} {
53 puts "Note: I don't see build.spec. Try running: tmake --genie"
54 }
55 }
56
--- autosetup/tmake.auto
+++ autosetup/tmake.auto
@@ -47,9 +47,27 @@
47 # And don't process this file any further
48 ifconfig false
49 }
50 }
51
52 set configure [readfile configure]
53 # XXX Do we need also need to support a system install of tmake?
54 if {[string first {#@TMAKEUPDATED@} $configure] < 0} {
55 if {[regsub {#@@INITCHECK@@#} $configure \
56 {test -z "$TMAKE" -a -x "$dir/tmake" \&\& exec "$dir/tmake" --force --configure "$@"; #@TMAKEUPDATED@} configure]} {
57 writefile configure $configure\n
58 exec chmod +x configure
59 puts "Updated configure to invoke local tmake."
60 if {![file exec autosetup/tmake]} {
61 puts "Warning: autosetup/tmake is missing."
62 puts " Install it with: tmake --install=autosetup"
63 }
64 } else {
65 puts "Warning: configure isn't created by a recent autosetup, not updating."
66 }
67 } else {
68 puts "I see configure for tmake already exists."
69 }
70 if {![file exists build.spec]} {
71 puts "Note: I don't see build.spec. Try running: tmake --genie"
72 }
73 }
74
--- autosetup/tmake.tcl
+++ autosetup/tmake.tcl
@@ -9,11 +9,11 @@
99
#
1010
## CONFIGURED - to indicate that the project is configured
1111
1212
use system
1313
14
-module-options {}
14
+options {}
1515
1616
define CONFIGURED
1717
1818
# @make-tmake-settings outfile patterns ...
1919
#
2020
--- autosetup/tmake.tcl
+++ autosetup/tmake.tcl
@@ -9,11 +9,11 @@
9 #
10 ## CONFIGURED - to indicate that the project is configured
11
12 use system
13
14 module-options {}
15
16 define CONFIGURED
17
18 # @make-tmake-settings outfile patterns ...
19 #
20
--- autosetup/tmake.tcl
+++ autosetup/tmake.tcl
@@ -9,11 +9,11 @@
9 #
10 ## CONFIGURED - to indicate that the project is configured
11
12 use system
13
14 options {}
15
16 define CONFIGURED
17
18 # @make-tmake-settings outfile patterns ...
19 #
20
+1
--- configure
+++ configure
@@ -1,3 +1,4 @@
11
#!/bin/sh
22
dir="`dirname "$0"`/autosetup"
3
+#@@INITCHECK@@#
34
WRAPPER="$0"; export WRAPPER; exec "`"$dir/autosetup-find-tclsh"`" "$dir/autosetup" "$@"
45
--- configure
+++ configure
@@ -1,3 +1,4 @@
1 #!/bin/sh
2 dir="`dirname "$0"`/autosetup"
 
3 WRAPPER="$0"; export WRAPPER; exec "`"$dir/autosetup-find-tclsh"`" "$dir/autosetup" "$@"
4
--- configure
+++ configure
@@ -1,3 +1,4 @@
1 #!/bin/sh
2 dir="`dirname "$0"`/autosetup"
3 #@@INITCHECK@@#
4 WRAPPER="$0"; export WRAPPER; exec "`"$dir/autosetup-find-tclsh"`" "$dir/autosetup" "$@"
5

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button