Skip to content
Myr

Merge branch 'autotools'

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Stephen Dolan · committed by Stephen Dolan · parents 7813f36, 4b1b9c2 · Browse files · 38 files+3291 added−767 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

38 files+3291 added−767 removed

  • tests:+579 added−0 removed
  • other:+2712 added−767 removed

38 files+3291 added−767 removed

added:build/.gitignore+1 added
1*
added:config/compile+343 added
1#! /bin/sh2# Wrapper for compilers which do not understand '-c -o'.34scriptversion=2012-03-05.13; # UTC56# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2009, 2010, 2012 Free7# Software Foundation, Inc.8# Written by Tom Tromey <tromey@cygnus.com>.9#10# This program is free software; you can redistribute it and/or modify11# it under the terms of the GNU General Public License as published by12# the Free Software Foundation; either version 2, or (at your option)13# any later version.14#15# This program is distributed in the hope that it will be useful,16# but WITHOUT ANY WARRANTY; without even the implied warranty of17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the18# GNU General Public License for more details.19#20# You should have received a copy of the GNU General Public License21# along with this program. If not, see <http://www.gnu.org/licenses/>.2223# As a special exception to the GNU General Public License, if you24# distribute this file as part of a program that contains a25# configuration script generated by Autoconf, you may include it under26# the same distribution terms that you use for the rest of that program.2728# This file is maintained in Automake, please report29# bugs to <bug-automake@gnu.org> or send patches to30# <automake-patches@gnu.org>.3132nl='33'3435# We need space, tab and new line, in precisely that order. Quoting is36# there to prevent tools from complaining about whitespace usage.37IFS=" "" $nl"3839file_conv=4041# func_file_conv build_file lazy42# Convert a $build file to $host form and store it in $file43# Currently only supports Windows hosts. If the determined conversion44# type is listed in (the comma separated) LAZY, no conversion will45# take place.46func_file_conv ()47{48 file=$149 case $file in50 / | /[!/]*) # absolute file, and not a UNC file51 if test -z "$file_conv"; then52 # lazily determine how to convert abs files53 case `uname -s` in54 MINGW*)55 file_conv=mingw56 ;;57 CYGWIN*)58 file_conv=cygwin59 ;;60 *)61 file_conv=wine62 ;;63 esac64 fi65 case $file_conv/,$2, in66 *,$file_conv,*)67 ;;68 mingw/*)69 file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`70 ;;71 cygwin/*)72 file=`cygpath -m "$file" || echo "$file"`73 ;;74 wine/*)75 file=`winepath -w "$file" || echo "$file"`76 ;;77 esac78 ;;79 esac80}8182# func_cl_dashL linkdir83# Make cl look for libraries in LINKDIR84func_cl_dashL ()85{86 func_file_conv "$1"87 if test -z "$lib_path"; then88 lib_path=$file89 else90 lib_path="$lib_path;$file"91 fi92 linker_opts="$linker_opts -LIBPATH:$file"93}9495# func_cl_dashl library96# Do a library search-path lookup for cl97func_cl_dashl ()98{99 lib=$1100 found=no101 save_IFS=$IFS102 IFS=';'103 for dir in $lib_path $LIB104 do105 IFS=$save_IFS106 if $shared && test -f "$dir/$lib.dll.lib"; then107 found=yes108 lib=$dir/$lib.dll.lib109 break110 fi111 if test -f "$dir/$lib.lib"; then112 found=yes113 lib=$dir/$lib.lib114 break115 fi116 done117 IFS=$save_IFS118119 if test "$found" != yes; then120 lib=$lib.lib121 fi122}123124# func_cl_wrapper cl arg...125# Adjust compile command to suit cl126func_cl_wrapper ()127{128 # Assume a capable shell129 lib_path=130 shared=:131 linker_opts=132 for arg133 do134 if test -n "$eat"; then135 eat=136 else137 case $1 in138 -o)139 # configure might choose to run compile as 'compile cc -o foo foo.c'.140 eat=1141 case $2 in142 *.o | *.[oO][bB][jJ])143 func_file_conv "$2"144 set x "$@" -Fo"$file"145 shift146 ;;147 *)148 func_file_conv "$2"149 set x "$@" -Fe"$file"150 shift151 ;;152 esac153 ;;154 -I)155 eat=1156 func_file_conv "$2" mingw157 set x "$@" -I"$file"158 shift159 ;;160 -I*)161 func_file_conv "${1#-I}" mingw162 set x "$@" -I"$file"163 shift164 ;;165 -l)166 eat=1167 func_cl_dashl "$2"168 set x "$@" "$lib"169 shift170 ;;171 -l*)172 func_cl_dashl "${1#-l}"173 set x "$@" "$lib"174 shift175 ;;176 -L)177 eat=1178 func_cl_dashL "$2"179 ;;180 -L*)181 func_cl_dashL "${1#-L}"182 ;;183 -static)184 shared=false185 ;;186 -Wl,*)187 arg=${1#-Wl,}188 save_ifs="$IFS"; IFS=','189 for flag in $arg; do190 IFS="$save_ifs"191 linker_opts="$linker_opts $flag"192 done193 IFS="$save_ifs"194 ;;195 -Xlinker)196 eat=1197 linker_opts="$linker_opts $2"198 ;;199 -*)200 set x "$@" "$1"201 shift202 ;;203 *.cc | *.CC | *.cxx | *.CXX | *.[cC]++)204 func_file_conv "$1"205 set x "$@" -Tp"$file"206 shift207 ;;208 *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO])209 func_file_conv "$1" mingw210 set x "$@" "$file"211 shift212 ;;213 *)214 set x "$@" "$1"215 shift216 ;;217 esac218 fi219 shift220 done221 if test -n "$linker_opts"; then222 linker_opts="-link$linker_opts"223 fi224 exec "$@" $linker_opts225 exit 1226}227228eat=229230case $1 in231 '')232 echo "$0: No command. Try '$0 --help' for more information." 1>&2233 exit 1;234 ;;235 -h | --h*)236 cat <<\EOF237Usage: compile [--help] [--version] PROGRAM [ARGS]238239Wrapper for compilers which do not understand '-c -o'.240Remove '-o dest.o' from ARGS, run PROGRAM with the remaining241arguments, and rename the output as expected.242243If you are trying to build a whole package this is not the244right script to run: please start by reading the file 'INSTALL'.245246Report bugs to <bug-automake@gnu.org>.247EOF248 exit $?249 ;;250 -v | --v*)251 echo "compile $scriptversion"252 exit $?253 ;;254 cl | *[/\\]cl | cl.exe | *[/\\]cl.exe )255 func_cl_wrapper "$@" # Doesn't return...256 ;;257esac258259ofile=260cfile=261262for arg263do264 if test -n "$eat"; then265 eat=266 else267 case $1 in268 -o)269 # configure might choose to run compile as 'compile cc -o foo foo.c'.270 # So we strip '-o arg' only if arg is an object.271 eat=1272 case $2 in273 *.o | *.obj)274 ofile=$2275 ;;276 *)277 set x "$@" -o "$2"278 shift279 ;;280 esac281 ;;282 *.c)283 cfile=$1284 set x "$@" "$1"285 shift286 ;;287 *)288 set x "$@" "$1"289 shift290 ;;291 esac292 fi293 shift294done295296if test -z "$ofile" || test -z "$cfile"; then297 # If no '-o' option was seen then we might have been invoked from a298 # pattern rule where we don't need one. That is ok -- this is a299 # normal compilation that the losing compiler can handle. If no300 # '.c' file was seen then we are probably linking. That is also301 # ok.302 exec "$@"303fi304305# Name of file we expect compiler to create.306cofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`307308# Create the lock directory.309# Note: use '[/\\:.-]' here to ensure that we don't use the same name310# that we are using for the .o file. Also, base the name on the expected311# object file name, since that is what matters with a parallel build.312lockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d313while true; do314 if mkdir "$lockdir" >/dev/null 2>&1; then315 break316 fi317 sleep 1318done319# FIXME: race condition here if user kills between mkdir and trap.320trap "rmdir '$lockdir'; exit 1" 1 2 15321322# Run the compile.323"$@"324ret=$?325326if test -f "$cofile"; then327 test "$cofile" = "$ofile" || mv "$cofile" "$ofile"328elif test -f "${cofile}bj"; then329 test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile"330fi331332rmdir "$lockdir"333exit $ret334335# Local Variables:336# mode: shell-script337# sh-indentation: 2338# eval: (add-hook 'write-file-hooks 'time-stamp)339# time-stamp-start: "scriptversion="340# time-stamp-format: "%:y-%02m-%02d.%02H"341# time-stamp-time-zone: "UTC"342# time-stamp-end: "; # UTC"343# End:
added:config/depcomp+708 added
1#! /bin/sh2# depcomp - compile a program generating dependencies as side-effects34scriptversion=2012-03-27.16; # UTC56# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2009, 2010,7# 2011, 2012 Free Software Foundation, Inc.89# This program is free software; you can redistribute it and/or modify10# it under the terms of the GNU General Public License as published by11# the Free Software Foundation; either version 2, or (at your option)12# any later version.1314# This program is distributed in the hope that it will be useful,15# but WITHOUT ANY WARRANTY; without even the implied warranty of16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the17# GNU General Public License for more details.1819# You should have received a copy of the GNU General Public License20# along with this program. If not, see <http://www.gnu.org/licenses/>.2122# As a special exception to the GNU General Public License, if you23# distribute this file as part of a program that contains a24# configuration script generated by Autoconf, you may include it under25# the same distribution terms that you use for the rest of that program.2627# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.2829case $1 in30 '')31 echo "$0: No command. Try '$0 --help' for more information." 1>&232 exit 1;33 ;;34 -h | --h*)35 cat <<\EOF36Usage: depcomp [--help] [--version] PROGRAM [ARGS]3738Run PROGRAMS ARGS to compile a file, generating dependencies39as side-effects.4041Environment variables:42 depmode Dependency tracking mode.43 source Source file read by 'PROGRAMS ARGS'.44 object Object file output by 'PROGRAMS ARGS'.45 DEPDIR directory where to store dependencies.46 depfile Dependency file to output.47 tmpdepfile Temporary file to use when outputting dependencies.48 libtool Whether libtool is used (yes/no).4950Report bugs to <bug-automake@gnu.org>.51EOF52 exit $?53 ;;54 -v | --v*)55 echo "depcomp $scriptversion"56 exit $?57 ;;58esac5960# A tabulation character.61tab=' '62# A newline character.63nl='64'6566if test -z "$depmode" || test -z "$source" || test -z "$object"; then67 echo "depcomp: Variables source, object and depmode must be set" 1>&268 exit 169fi7071# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.72depfile=${depfile-`echo "$object" |73 sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}74tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}7576rm -f "$tmpdepfile"7778# Some modes work just like other modes, but use different flags. We79# parameterize here, but still list the modes in the big case below,80# to make depend.m4 easier to write. Note that we *cannot* use a case81# here, because this file can only contain one case statement.82if test "$depmode" = hp; then83 # HP compiler uses -M and no extra arg.84 gccflag=-M85 depmode=gcc86fi8788if test "$depmode" = dashXmstdout; then89 # This is just like dashmstdout with a different argument.90 dashmflag=-xM91 depmode=dashmstdout92fi9394cygpath_u="cygpath -u -f -"95if test "$depmode" = msvcmsys; then96 # This is just like msvisualcpp but w/o cygpath translation.97 # Just convert the backslash-escaped backslashes to single forward98 # slashes to satisfy depend.m499 cygpath_u='sed s,\\\\,/,g'100 depmode=msvisualcpp101fi102103if test "$depmode" = msvc7msys; then104 # This is just like msvc7 but w/o cygpath translation.105 # Just convert the backslash-escaped backslashes to single forward106 # slashes to satisfy depend.m4107 cygpath_u='sed s,\\\\,/,g'108 depmode=msvc7109fi110111if test "$depmode" = xlc; then112 # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency informations.113 gccflag=-qmakedep=gcc,-MF114 depmode=gcc115fi116117case "$depmode" in118gcc3)119## gcc 3 implements dependency tracking that does exactly what120## we want. Yay! Note: for some reason libtool 1.4 doesn't like121## it if -MD -MP comes after the -MF stuff. Hmm.122## Unfortunately, FreeBSD c89 acceptance of flags depends upon123## the command line argument order; so add the flags where they124## appear in depend2.am. Note that the slowdown incurred here125## affects only configure: in makefiles, %FASTDEP% shortcuts this.126 for arg127 do128 case $arg in129 -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;130 *) set fnord "$@" "$arg" ;;131 esac132 shift # fnord133 shift # $arg134 done135 "$@"136 stat=$?137 if test $stat -eq 0; then :138 else139 rm -f "$tmpdepfile"140 exit $stat141 fi142 mv "$tmpdepfile" "$depfile"143 ;;144145gcc)146## There are various ways to get dependency output from gcc. Here's147## why we pick this rather obscure method:148## - Don't want to use -MD because we'd like the dependencies to end149## up in a subdir. Having to rename by hand is ugly.150## (We might end up doing this anyway to support other compilers.)151## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like152## -MM, not -M (despite what the docs say).153## - Using -M directly means running the compiler twice (even worse154## than renaming).155 if test -z "$gccflag"; then156 gccflag=-MD,157 fi158 "$@" -Wp,"$gccflag$tmpdepfile"159 stat=$?160 if test $stat -eq 0; then :161 else162 rm -f "$tmpdepfile"163 exit $stat164 fi165 rm -f "$depfile"166 echo "$object : \\" > "$depfile"167 alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz168## The second -e expression handles DOS-style file names with drive letters.169 sed -e 's/^[^:]*: / /' \170 -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"171## This next piece of magic avoids the "deleted header file" problem.172## The problem is that when a header file which appears in a .P file173## is deleted, the dependency causes make to die (because there is174## typically no way to rebuild the header). We avoid this by adding175## dummy dependencies for each header file. Too bad gcc doesn't do176## this for us directly.177 tr ' ' "$nl" < "$tmpdepfile" |178## Some versions of gcc put a space before the ':'. On the theory179## that the space means something, we add a space to the output as180## well. hp depmode also adds that space, but also prefixes the VPATH181## to the object. Take care to not repeat it in the output.182## Some versions of the HPUX 10.20 sed can't process this invocation183## correctly. Breaking it into two sed invocations is a workaround.184 sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \185 | sed -e 's/$/ :/' >> "$depfile"186 rm -f "$tmpdepfile"187 ;;188189hp)190 # This case exists only to let depend.m4 do its work. It works by191 # looking at the text of this script. This case will never be run,192 # since it is checked for above.193 exit 1194 ;;195196sgi)197 if test "$libtool" = yes; then198 "$@" "-Wp,-MDupdate,$tmpdepfile"199 else200 "$@" -MDupdate "$tmpdepfile"201 fi202 stat=$?203 if test $stat -eq 0; then :204 else205 rm -f "$tmpdepfile"206 exit $stat207 fi208 rm -f "$depfile"209210 if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files211 echo "$object : \\" > "$depfile"212213 # Clip off the initial element (the dependent). Don't try to be214 # clever and replace this with sed code, as IRIX sed won't handle215 # lines with more than a fixed number of characters (4096 in216 # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines;217 # the IRIX cc adds comments like '#:fec' to the end of the218 # dependency line.219 tr ' ' "$nl" < "$tmpdepfile" \220 | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \221 tr "$nl" ' ' >> "$depfile"222 echo >> "$depfile"223224 # The second pass generates a dummy entry for each header file.225 tr ' ' "$nl" < "$tmpdepfile" \226 | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \227 >> "$depfile"228 else229 # The sourcefile does not contain any dependencies, so just230 # store a dummy comment line, to avoid errors with the Makefile231 # "include basename.Plo" scheme.232 echo "#dummy" > "$depfile"233 fi234 rm -f "$tmpdepfile"235 ;;236237xlc)238 # This case exists only to let depend.m4 do its work. It works by239 # looking at the text of this script. This case will never be run,240 # since it is checked for above.241 exit 1242 ;;243244aix)245 # The C for AIX Compiler uses -M and outputs the dependencies246 # in a .u file. In older versions, this file always lives in the247 # current directory. Also, the AIX compiler puts '$object:' at the248 # start of each line; $object doesn't have directory information.249 # Version 6 uses the directory in both cases.250 dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`251 test "x$dir" = "x$object" && dir=252 base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`253 if test "$libtool" = yes; then254 tmpdepfile1=$dir$base.u255 tmpdepfile2=$base.u256 tmpdepfile3=$dir.libs/$base.u257 "$@" -Wc,-M258 else259 tmpdepfile1=$dir$base.u260 tmpdepfile2=$dir$base.u261 tmpdepfile3=$dir$base.u262 "$@" -M263 fi264 stat=$?265266 if test $stat -eq 0; then :267 else268 rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"269 exit $stat270 fi271272 for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"273 do274 test -f "$tmpdepfile" && break275 done276 if test -f "$tmpdepfile"; then277 # Each line is of the form 'foo.o: dependent.h'.278 # Do two passes, one to just change these to279 # '$object: dependent.h' and one to simply 'dependent.h:'.280 sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"281 sed -e 's,^.*\.[a-z]*:['"$tab"' ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"282 else283 # The sourcefile does not contain any dependencies, so just284 # store a dummy comment line, to avoid errors with the Makefile285 # "include basename.Plo" scheme.286 echo "#dummy" > "$depfile"287 fi288 rm -f "$tmpdepfile"289 ;;290291icc)292 # Intel's C compiler anf tcc (Tiny C Compiler) understand '-MD -MF file'.293 # However on294 # $CC -MD -MF foo.d -c -o sub/foo.o sub/foo.c295 # ICC 7.0 will fill foo.d with something like296 # foo.o: sub/foo.c297 # foo.o: sub/foo.h298 # which is wrong. We want299 # sub/foo.o: sub/foo.c300 # sub/foo.o: sub/foo.h301 # sub/foo.c:302 # sub/foo.h:303 # ICC 7.1 will output304 # foo.o: sub/foo.c sub/foo.h305 # and will wrap long lines using '\':306 # foo.o: sub/foo.c ... \307 # sub/foo.h ... \308 # ...309 # tcc 0.9.26 (FIXME still under development at the moment of writing)310 # will emit a similar output, but also prepend the continuation lines311 # with horizontal tabulation characters.312 "$@" -MD -MF "$tmpdepfile"313 stat=$?314 if test $stat -eq 0; then :315 else316 rm -f "$tmpdepfile"317 exit $stat318 fi319 rm -f "$depfile"320 # Each line is of the form 'foo.o: dependent.h',321 # or 'foo.o: dep1.h dep2.h \', or ' dep3.h dep4.h \'.322 # Do two passes, one to just change these to323 # '$object: dependent.h' and one to simply 'dependent.h:'.324 sed -e "s/^[ $tab][ $tab]*/ /" -e "s,^[^:]*:,$object :," \325 < "$tmpdepfile" > "$depfile"326 sed '327 s/[ '"$tab"'][ '"$tab"']*/ /g328 s/^ *//329 s/ *\\*$//330 s/^[^:]*: *//331 /^$/d332 /:$/d333 s/$/ :/334 ' < "$tmpdepfile" >> "$depfile"335 rm -f "$tmpdepfile"336 ;;337338hp2)339 # The "hp" stanza above does not work with aCC (C++) and HP's ia64340 # compilers, which have integrated preprocessors. The correct option341 # to use with these is +Maked; it writes dependencies to a file named342 # 'foo.d', which lands next to the object file, wherever that343 # happens to be.344 # Much of this is similar to the tru64 case; see comments there.345 dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`346 test "x$dir" = "x$object" && dir=347 base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`348 if test "$libtool" = yes; then349 tmpdepfile1=$dir$base.d350 tmpdepfile2=$dir.libs/$base.d351 "$@" -Wc,+Maked352 else353 tmpdepfile1=$dir$base.d354 tmpdepfile2=$dir$base.d355 "$@" +Maked356 fi357 stat=$?358 if test $stat -eq 0; then :359 else360 rm -f "$tmpdepfile1" "$tmpdepfile2"361 exit $stat362 fi363364 for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"365 do366 test -f "$tmpdepfile" && break367 done368 if test -f "$tmpdepfile"; then369 sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"370 # Add 'dependent.h:' lines.371 sed -ne '2,${372 s/^ *//373 s/ \\*$//374 s/$/:/375 p376 }' "$tmpdepfile" >> "$depfile"377 else378 echo "#dummy" > "$depfile"379 fi380 rm -f "$tmpdepfile" "$tmpdepfile2"381 ;;382383tru64)384 # The Tru64 compiler uses -MD to generate dependencies as a side385 # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.386 # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put387 # dependencies in 'foo.d' instead, so we check for that too.388 # Subdirectories are respected.389 dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`390 test "x$dir" = "x$object" && dir=391 base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`392393 if test "$libtool" = yes; then394 # With Tru64 cc, shared objects can also be used to make a395 # static library. This mechanism is used in libtool 1.4 series to396 # handle both shared and static libraries in a single compilation.397 # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.398 #399 # With libtool 1.5 this exception was removed, and libtool now400 # generates 2 separate objects for the 2 libraries. These two401 # compilations output dependencies in $dir.libs/$base.o.d and402 # in $dir$base.o.d. We have to check for both files, because403 # one of the two compilations can be disabled. We should prefer404 # $dir$base.o.d over $dir.libs/$base.o.d because the latter is405 # automatically cleaned when .libs/ is deleted, while ignoring406 # the former would cause a distcleancheck panic.407 tmpdepfile1=$dir.libs/$base.lo.d # libtool 1.4408 tmpdepfile2=$dir$base.o.d # libtool 1.5409 tmpdepfile3=$dir.libs/$base.o.d # libtool 1.5410 tmpdepfile4=$dir.libs/$base.d # Compaq CCC V6.2-504411 "$@" -Wc,-MD412 else413 tmpdepfile1=$dir$base.o.d414 tmpdepfile2=$dir$base.d415 tmpdepfile3=$dir$base.d416 tmpdepfile4=$dir$base.d417 "$@" -MD418 fi419420 stat=$?421 if test $stat -eq 0; then :422 else423 rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"424 exit $stat425 fi426427 for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"428 do429 test -f "$tmpdepfile" && break430 done431 if test -f "$tmpdepfile"; then432 sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"433 sed -e 's,^.*\.[a-z]*:['"$tab"' ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"434 else435 echo "#dummy" > "$depfile"436 fi437 rm -f "$tmpdepfile"438 ;;439440msvc7)441 if test "$libtool" = yes; then442 showIncludes=-Wc,-showIncludes443 else444 showIncludes=-showIncludes445 fi446 "$@" $showIncludes > "$tmpdepfile"447 stat=$?448 grep -v '^Note: including file: ' "$tmpdepfile"449 if test "$stat" = 0; then :450 else451 rm -f "$tmpdepfile"452 exit $stat453 fi454 rm -f "$depfile"455 echo "$object : \\" > "$depfile"456 # The first sed program below extracts the file names and escapes457 # backslashes for cygpath. The second sed program outputs the file458 # name when reading, but also accumulates all include files in the459 # hold buffer in order to output them again at the end. This only460 # works with sed implementations that can handle large buffers.461 sed < "$tmpdepfile" -n '462/^Note: including file: *\(.*\)/ {463 s//\1/464 s/\\/\\\\/g465 p466}' | $cygpath_u | sort -u | sed -n '467s/ /\\ /g468s/\(.*\)/'"$tab"'\1 \\/p469s/.\(.*\) \\/\1:/470H471$ {472 s/.*/'"$tab"'/473 G474 p475}' >> "$depfile"476 rm -f "$tmpdepfile"477 ;;478479msvc7msys)480 # This case exists only to let depend.m4 do its work. It works by481 # looking at the text of this script. This case will never be run,482 # since it is checked for above.483 exit 1484 ;;485486#nosideeffect)487 # This comment above is used by automake to tell side-effect488 # dependency tracking mechanisms from slower ones.489490dashmstdout)491 # Important note: in order to support this mode, a compiler *must*492 # always write the preprocessed file to stdout, regardless of -o.493 "$@" || exit $?494495 # Remove the call to Libtool.496 if test "$libtool" = yes; then497 while test "X$1" != 'X--mode=compile'; do498 shift499 done500 shift501 fi502503 # Remove '-o $object'.504 IFS=" "505 for arg506 do507 case $arg in508 -o)509 shift510 ;;511 $object)512 shift513 ;;514 *)515 set fnord "$@" "$arg"516 shift # fnord517 shift # $arg518 ;;519 esac520 done521522 test -z "$dashmflag" && dashmflag=-M523 # Require at least two characters before searching for ':'524 # in the target name. This is to cope with DOS-style filenames:525 # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.526 "$@" $dashmflag |527 sed 's:^['"$tab"' ]*[^:'"$tab"' ][^:][^:]*\:['"$tab"' ]*:'"$object"'\: :' > "$tmpdepfile"528 rm -f "$depfile"529 cat < "$tmpdepfile" > "$depfile"530 tr ' ' "$nl" < "$tmpdepfile" | \531## Some versions of the HPUX 10.20 sed can't process this invocation532## correctly. Breaking it into two sed invocations is a workaround.533 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"534 rm -f "$tmpdepfile"535 ;;536537dashXmstdout)538 # This case only exists to satisfy depend.m4. It is never actually539 # run, as this mode is specially recognized in the preamble.540 exit 1541 ;;542543makedepend)544 "$@" || exit $?545 # Remove any Libtool call546 if test "$libtool" = yes; then547 while test "X$1" != 'X--mode=compile'; do548 shift549 done550 shift551 fi552 # X makedepend553 shift554 cleared=no eat=no555 for arg556 do557 case $cleared in558 no)559 set ""; shift560 cleared=yes ;;561 esac562 if test $eat = yes; then563 eat=no564 continue565 fi566 case "$arg" in567 -D*|-I*)568 set fnord "$@" "$arg"; shift ;;569 # Strip any option that makedepend may not understand. Remove570 # the object too, otherwise makedepend will parse it as a source file.571 -arch)572 eat=yes ;;573 -*|$object)574 ;;575 *)576 set fnord "$@" "$arg"; shift ;;577 esac578 done579 obj_suffix=`echo "$object" | sed 's/^.*\././'`580 touch "$tmpdepfile"581 ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"582 rm -f "$depfile"583 # makedepend may prepend the VPATH from the source file name to the object.584 # No need to regex-escape $object, excess matching of '.' is harmless.585 sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"586 sed '1,2d' "$tmpdepfile" | tr ' ' "$nl" | \587## Some versions of the HPUX 10.20 sed can't process this invocation588## correctly. Breaking it into two sed invocations is a workaround.589 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"590 rm -f "$tmpdepfile" "$tmpdepfile".bak591 ;;592593cpp)594 # Important note: in order to support this mode, a compiler *must*595 # always write the preprocessed file to stdout.596 "$@" || exit $?597598 # Remove the call to Libtool.599 if test "$libtool" = yes; then600 while test "X$1" != 'X--mode=compile'; do601 shift602 done603 shift604 fi605606 # Remove '-o $object'.607 IFS=" "608 for arg609 do610 case $arg in611 -o)612 shift613 ;;614 $object)615 shift616 ;;617 *)618 set fnord "$@" "$arg"619 shift # fnord620 shift # $arg621 ;;622 esac623 done624625 "$@" -E |626 sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \627 -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |628 sed '$ s: \\$::' > "$tmpdepfile"629 rm -f "$depfile"630 echo "$object : \\" > "$depfile"631 cat < "$tmpdepfile" >> "$depfile"632 sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"633 rm -f "$tmpdepfile"634 ;;635636msvisualcpp)637 # Important note: in order to support this mode, a compiler *must*638 # always write the preprocessed file to stdout.639 "$@" || exit $?640641 # Remove the call to Libtool.642 if test "$libtool" = yes; then643 while test "X$1" != 'X--mode=compile'; do644 shift645 done646 shift647 fi648649 IFS=" "650 for arg651 do652 case "$arg" in653 -o)654 shift655 ;;656 $object)657 shift658 ;;659 "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")660 set fnord "$@"661 shift662 shift663 ;;664 *)665 set fnord "$@" "$arg"666 shift667 shift668 ;;669 esac670 done671 "$@" -E 2>/dev/null |672 sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"673 rm -f "$depfile"674 echo "$object : \\" > "$depfile"675 sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"676 echo "$tab" >> "$depfile"677 sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"678 rm -f "$tmpdepfile"679 ;;680681msvcmsys)682 # This case exists only to let depend.m4 do its work. It works by683 # looking at the text of this script. This case will never be run,684 # since it is checked for above.685 exit 1686 ;;687688none)689 exec "$@"690 ;;691692*)693 echo "Unknown depmode $depmode" 1>&2694 exit 1695 ;;696esac697698exit 0699700# Local Variables:701# mode: shell-script702# sh-indentation: 2703# eval: (add-hook 'write-file-hooks 'time-stamp)704# time-stamp-start: "scriptversion="705# time-stamp-format: "%:y-%02m-%02d.%02H"706# time-stamp-time-zone: "UTC"707# time-stamp-end: "; # UTC"708# End:
added:config/install-sh+527 added
1#!/bin/sh2# install - install a program, script, or datafile34scriptversion=2011-01-19.21; # UTC56# This originates from X11R5 (mit/util/scripts/install.sh), which was7# later released in X11R6 (xc/config/util/install.sh) with the8# following copyright and license.9#10# Copyright (C) 1994 X Consortium11#12# Permission is hereby granted, free of charge, to any person obtaining a copy13# of this software and associated documentation files (the "Software"), to14# deal in the Software without restriction, including without limitation the15# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or16# sell copies of the Software, and to permit persons to whom the Software is17# furnished to do so, subject to the following conditions:18#19# The above copyright notice and this permission notice shall be included in20# all copies or substantial portions of the Software.21#22# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR23# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,24# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE25# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN26# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-27# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.28#29# Except as contained in this notice, the name of the X Consortium shall not30# be used in advertising or otherwise to promote the sale, use or other deal-31# ings in this Software without prior written authorization from the X Consor-32# tium.33#34#35# FSF changes to this file are in the public domain.36#37# Calling this script install-sh is preferred over install.sh, to prevent38# `make' implicit rules from creating a file called install from it39# when there is no Makefile.40#41# This script is compatible with the BSD install script, but was written42# from scratch.4344nl='45'46IFS=" "" $nl"4748# set DOITPROG to echo to test this script4950# Don't use :- since 4.3BSD and earlier shells don't like it.51doit=${DOITPROG-}52if test -z "$doit"; then53 doit_exec=exec54else55 doit_exec=$doit56fi5758# Put in absolute file names if you don't have them in your path;59# or use environment vars.6061chgrpprog=${CHGRPPROG-chgrp}62chmodprog=${CHMODPROG-chmod}63chownprog=${CHOWNPROG-chown}64cmpprog=${CMPPROG-cmp}65cpprog=${CPPROG-cp}66mkdirprog=${MKDIRPROG-mkdir}67mvprog=${MVPROG-mv}68rmprog=${RMPROG-rm}69stripprog=${STRIPPROG-strip}7071posix_glob='?'72initialize_posix_glob='73 test "$posix_glob" != "?" || {74 if (set -f) 2>/dev/null; then75 posix_glob=76 else77 posix_glob=:78 fi79 }80'8182posix_mkdir=8384# Desired mode of installed file.85mode=07558687chgrpcmd=88chmodcmd=$chmodprog89chowncmd=90mvcmd=$mvprog91rmcmd="$rmprog -f"92stripcmd=9394src=95dst=96dir_arg=97dst_arg=9899copy_on_change=false100no_target_directory=101102usage="\103Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE104 or: $0 [OPTION]... SRCFILES... DIRECTORY105 or: $0 [OPTION]... -t DIRECTORY SRCFILES...106 or: $0 [OPTION]... -d DIRECTORIES...107108In the 1st form, copy SRCFILE to DSTFILE.109In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.110In the 4th, create DIRECTORIES.111112Options:113 --help display this help and exit.114 --version display version info and exit.115116 -c (ignored)117 -C install only if different (preserve the last data modification time)118 -d create directories instead of installing files.119 -g GROUP $chgrpprog installed files to GROUP.120 -m MODE $chmodprog installed files to MODE.121 -o USER $chownprog installed files to USER.122 -s $stripprog installed files.123 -t DIRECTORY install into DIRECTORY.124 -T report an error if DSTFILE is a directory.125126Environment variables override the default commands:127 CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG128 RMPROG STRIPPROG129"130131while test $# -ne 0; do132 case $1 in133 -c) ;;134135 -C) copy_on_change=true;;136137 -d) dir_arg=true;;138139 -g) chgrpcmd="$chgrpprog $2"140 shift;;141142 --help) echo "$usage"; exit $?;;143144 -m) mode=$2145 case $mode in146 *' '* | *' '* | *'147'* | *'*'* | *'?'* | *'['*)148 echo "$0: invalid mode: $mode" >&2149 exit 1;;150 esac151 shift;;152153 -o) chowncmd="$chownprog $2"154 shift;;155156 -s) stripcmd=$stripprog;;157158 -t) dst_arg=$2159 # Protect names problematic for `test' and other utilities.160 case $dst_arg in161 -* | [=\(\)!]) dst_arg=./$dst_arg;;162 esac163 shift;;164165 -T) no_target_directory=true;;166167 --version) echo "$0 $scriptversion"; exit $?;;168169 --) shift170 break;;171172 -*) echo "$0: invalid option: $1" >&2173 exit 1;;174175 *) break;;176 esac177 shift178done179180if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then181 # When -d is used, all remaining arguments are directories to create.182 # When -t is used, the destination is already specified.183 # Otherwise, the last argument is the destination. Remove it from $@.184 for arg185 do186 if test -n "$dst_arg"; then187 # $@ is not empty: it contains at least $arg.188 set fnord "$@" "$dst_arg"189 shift # fnord190 fi191 shift # arg192 dst_arg=$arg193 # Protect names problematic for `test' and other utilities.194 case $dst_arg in195 -* | [=\(\)!]) dst_arg=./$dst_arg;;196 esac197 done198fi199200if test $# -eq 0; then201 if test -z "$dir_arg"; then202 echo "$0: no input file specified." >&2203 exit 1204 fi205 # It's OK to call `install-sh -d' without argument.206 # This can happen when creating conditional directories.207 exit 0208fi209210if test -z "$dir_arg"; then211 do_exit='(exit $ret); exit $ret'212 trap "ret=129; $do_exit" 1213 trap "ret=130; $do_exit" 2214 trap "ret=141; $do_exit" 13215 trap "ret=143; $do_exit" 15216217 # Set umask so as not to create temps with too-generous modes.218 # However, 'strip' requires both read and write access to temps.219 case $mode in220 # Optimize common cases.221 *644) cp_umask=133;;222 *755) cp_umask=22;;223224 *[0-7])225 if test -z "$stripcmd"; then226 u_plus_rw=227 else228 u_plus_rw='% 200'229 fi230 cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;231 *)232 if test -z "$stripcmd"; then233 u_plus_rw=234 else235 u_plus_rw=,u+rw236 fi237 cp_umask=$mode$u_plus_rw;;238 esac239fi240241for src242do243 # Protect names problematic for `test' and other utilities.244 case $src in245 -* | [=\(\)!]) src=./$src;;246 esac247248 if test -n "$dir_arg"; then249 dst=$src250 dstdir=$dst251 test -d "$dstdir"252 dstdir_status=$?253 else254255 # Waiting for this to be detected by the "$cpprog $src $dsttmp" command256 # might cause directories to be created, which would be especially bad257 # if $src (and thus $dsttmp) contains '*'.258 if test ! -f "$src" && test ! -d "$src"; then259 echo "$0: $src does not exist." >&2260 exit 1261 fi262263 if test -z "$dst_arg"; then264 echo "$0: no destination specified." >&2265 exit 1266 fi267 dst=$dst_arg268269 # If destination is a directory, append the input filename; won't work270 # if double slashes aren't ignored.271 if test -d "$dst"; then272 if test -n "$no_target_directory"; then273 echo "$0: $dst_arg: Is a directory" >&2274 exit 1275 fi276 dstdir=$dst277 dst=$dstdir/`basename "$src"`278 dstdir_status=0279 else280 # Prefer dirname, but fall back on a substitute if dirname fails.281 dstdir=`282 (dirname "$dst") 2>/dev/null ||283 expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \284 X"$dst" : 'X\(//\)[^/]' \| \285 X"$dst" : 'X\(//\)$' \| \286 X"$dst" : 'X\(/\)' \| . 2>/dev/null ||287 echo X"$dst" |288 sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{289 s//\1/290 q291 }292 /^X\(\/\/\)[^/].*/{293 s//\1/294 q295 }296 /^X\(\/\/\)$/{297 s//\1/298 q299 }300 /^X\(\/\).*/{301 s//\1/302 q303 }304 s/.*/./; q'305 `306307 test -d "$dstdir"308 dstdir_status=$?309 fi310 fi311312 obsolete_mkdir_used=false313314 if test $dstdir_status != 0; then315 case $posix_mkdir in316 '')317 # Create intermediate dirs using mode 755 as modified by the umask.318 # This is like FreeBSD 'install' as of 1997-10-28.319 umask=`umask`320 case $stripcmd.$umask in321 # Optimize common cases.322 *[2367][2367]) mkdir_umask=$umask;;323 .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;324325 *[0-7])326 mkdir_umask=`expr $umask + 22 \327 - $umask % 100 % 40 + $umask % 20 \328 - $umask % 10 % 4 + $umask % 2329 `;;330 *) mkdir_umask=$umask,go-w;;331 esac332333 # With -d, create the new directory with the user-specified mode.334 # Otherwise, rely on $mkdir_umask.335 if test -n "$dir_arg"; then336 mkdir_mode=-m$mode337 else338 mkdir_mode=339 fi340341 posix_mkdir=false342 case $umask in343 *[123567][0-7][0-7])344 # POSIX mkdir -p sets u+wx bits regardless of umask, which345 # is incompatible with FreeBSD 'install' when (umask & 300) != 0.346 ;;347 *)348 tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$349 trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0350351 if (umask $mkdir_umask &&352 exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1353 then354 if test -z "$dir_arg" || {355 # Check for POSIX incompatibilities with -m.356 # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or357 # other-writeable bit of parent directory when it shouldn't.358 # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.359 ls_ld_tmpdir=`ls -ld "$tmpdir"`360 case $ls_ld_tmpdir in361 d????-?r-*) different_mode=700;;362 d????-?--*) different_mode=755;;363 *) false;;364 esac &&365 $mkdirprog -m$different_mode -p -- "$tmpdir" && {366 ls_ld_tmpdir_1=`ls -ld "$tmpdir"`367 test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"368 }369 }370 then posix_mkdir=:371 fi372 rmdir "$tmpdir/d" "$tmpdir"373 else374 # Remove any dirs left behind by ancient mkdir implementations.375 rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null376 fi377 trap '' 0;;378 esac;;379 esac380381 if382 $posix_mkdir && (383 umask $mkdir_umask &&384 $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"385 )386 then :387 else388389 # The umask is ridiculous, or mkdir does not conform to POSIX,390 # or it failed possibly due to a race condition. Create the391 # directory the slow way, step by step, checking for races as we go.392393 case $dstdir in394 /*) prefix='/';;395 [-=\(\)!]*) prefix='./';;396 *) prefix='';;397 esac398399 eval "$initialize_posix_glob"400401 oIFS=$IFS402 IFS=/403 $posix_glob set -f404 set fnord $dstdir405 shift406 $posix_glob set +f407 IFS=$oIFS408409 prefixes=410411 for d412 do413 test X"$d" = X && continue414415 prefix=$prefix$d416 if test -d "$prefix"; then417 prefixes=418 else419 if $posix_mkdir; then420 (umask=$mkdir_umask &&421 $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break422 # Don't fail if two instances are running concurrently.423 test -d "$prefix" || exit 1424 else425 case $prefix in426 *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;427 *) qprefix=$prefix;;428 esac429 prefixes="$prefixes '$qprefix'"430 fi431 fi432 prefix=$prefix/433 done434435 if test -n "$prefixes"; then436 # Don't fail if two instances are running concurrently.437 (umask $mkdir_umask &&438 eval "\$doit_exec \$mkdirprog $prefixes") ||439 test -d "$dstdir" || exit 1440 obsolete_mkdir_used=true441 fi442 fi443 fi444445 if test -n "$dir_arg"; then446 { test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&447 { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&448 { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||449 test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1450 else451452 # Make a couple of temp file names in the proper directory.453 dsttmp=$dstdir/_inst.$$_454 rmtmp=$dstdir/_rm.$$_455456 # Trap to clean up those temp files at exit.457 trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0458459 # Copy the file name to the temp name.460 (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&461462 # and set any options; do chmod last to preserve setuid bits.463 #464 # If any of these fail, we abort the whole thing. If we want to465 # ignore errors from any of these, just make sure not to ignore466 # errors from the above "$doit $cpprog $src $dsttmp" command.467 #468 { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } &&469 { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } &&470 { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } &&471 { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&472473 # If -C, don't bother to copy if it wouldn't change the file.474 if $copy_on_change &&475 old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` &&476 new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` &&477478 eval "$initialize_posix_glob" &&479 $posix_glob set -f &&480 set X $old && old=:$2:$4:$5:$6 &&481 set X $new && new=:$2:$4:$5:$6 &&482 $posix_glob set +f &&483484 test "$old" = "$new" &&485 $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1486 then487 rm -f "$dsttmp"488 else489 # Rename the file to the real destination.490 $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||491492 # The rename failed, perhaps because mv can't rename something else493 # to itself, or perhaps because mv is so ancient that it does not494 # support -f.495 {496 # Now remove or move aside any old file at destination location.497 # We try this two ways since rm can't unlink itself on some498 # systems and the destination file might be busy for other499 # reasons. In this case, the final cleanup might fail but the new500 # file should still install successfully.501 {502 test ! -f "$dst" ||503 $doit $rmcmd -f "$dst" 2>/dev/null ||504 { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&505 { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }506 } ||507 { echo "$0: cannot unlink or rename $dst" >&2508 (exit 1); exit 1509 }510 } &&511512 # Now rename the file to the real destination.513 $doit $mvcmd "$dsttmp" "$dst"514 }515 fi || exit 1516517 trap '' 0518 fi519done520521# Local variables:522# eval: (add-hook 'write-file-hooks 'time-stamp)523# time-stamp-start: "scriptversion="524# time-stamp-format: "%:y-%02m-%02d.%02H"525# time-stamp-time-zone: "UTC"526# time-stamp-end: "; # UTC"527# End:
added:config/missing+331 added
1#! /bin/sh2# Common stub for a few missing GNU programs while installing.34scriptversion=2012-01-06.13; # UTC56# Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2005, 2006,7# 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.8# Originally by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.910# This program is free software; you can redistribute it and/or modify11# it under the terms of the GNU General Public License as published by12# the Free Software Foundation; either version 2, or (at your option)13# any later version.1415# This program is distributed in the hope that it will be useful,16# but WITHOUT ANY WARRANTY; without even the implied warranty of17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the18# GNU General Public License for more details.1920# You should have received a copy of the GNU General Public License21# along with this program. If not, see <http://www.gnu.org/licenses/>.2223# As a special exception to the GNU General Public License, if you24# distribute this file as part of a program that contains a25# configuration script generated by Autoconf, you may include it under26# the same distribution terms that you use for the rest of that program.2728if test $# -eq 0; then29 echo 1>&2 "Try \`$0 --help' for more information"30 exit 131fi3233run=:34sed_output='s/.* --output[ =]\([^ ]*\).*/\1/p'35sed_minuso='s/.* -o \([^ ]*\).*/\1/p'3637# In the cases where this matters, `missing' is being run in the38# srcdir already.39if test -f configure.ac; then40 configure_ac=configure.ac41else42 configure_ac=configure.in43fi4445msg="missing on your system"4647case $1 in48--run)49 # Try to run requested program, and just exit if it succeeds.50 run=51 shift52 "$@" && exit 053 # Exit code 63 means version mismatch. This often happens54 # when the user try to use an ancient version of a tool on55 # a file that requires a minimum version. In this case we56 # we should proceed has if the program had been absent, or57 # if --run hadn't been passed.58 if test $? = 63; then59 run=:60 msg="probably too old"61 fi62 ;;6364 -h|--h|--he|--hel|--help)65 echo "\66$0 [OPTION]... PROGRAM [ARGUMENT]...6768Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an69error status if there is no known handling for PROGRAM.7071Options:72 -h, --help display this help and exit73 -v, --version output version information and exit74 --run try to run the given command, and emulate it if it fails7576Supported PROGRAM values:77 aclocal touch file \`aclocal.m4'78 autoconf touch file \`configure'79 autoheader touch file \`config.h.in'80 autom4te touch the output file, or create a stub one81 automake touch all \`Makefile.in' files82 bison create \`y.tab.[ch]', if possible, from existing .[ch]83 flex create \`lex.yy.c', if possible, from existing .c84 help2man touch the output file85 lex create \`lex.yy.c', if possible, from existing .c86 makeinfo touch the output file87 yacc create \`y.tab.[ch]', if possible, from existing .[ch]8889Version suffixes to PROGRAM as well as the prefixes \`gnu-', \`gnu', and90\`g' are ignored when checking the name.9192Send bug reports to <bug-automake@gnu.org>."93 exit $?94 ;;9596 -v|--v|--ve|--ver|--vers|--versi|--versio|--version)97 echo "missing $scriptversion (GNU Automake)"98 exit $?99 ;;100101 -*)102 echo 1>&2 "$0: Unknown \`$1' option"103 echo 1>&2 "Try \`$0 --help' for more information"104 exit 1105 ;;106107esac108109# normalize program name to check for.110program=`echo "$1" | sed '111 s/^gnu-//; t112 s/^gnu//; t113 s/^g//; t'`114115# Now exit if we have it, but it failed. Also exit now if we116# don't have it and --version was passed (most likely to detect117# the program). This is about non-GNU programs, so use $1 not118# $program.119case $1 in120 lex*|yacc*)121 # Not GNU programs, they don't have --version.122 ;;123124 *)125 if test -z "$run" && ($1 --version) > /dev/null 2>&1; then126 # We have it, but it failed.127 exit 1128 elif test "x$2" = "x--version" || test "x$2" = "x--help"; then129 # Could not run --version or --help. This is probably someone130 # running `$TOOL --version' or `$TOOL --help' to check whether131 # $TOOL exists and not knowing $TOOL uses missing.132 exit 1133 fi134 ;;135esac136137# If it does not exist, or fails to run (possibly an outdated version),138# try to emulate it.139case $program in140 aclocal*)141 echo 1>&2 "\142WARNING: \`$1' is $msg. You should only need it if143 you modified \`acinclude.m4' or \`${configure_ac}'. You might want144 to install the \`Automake' and \`Perl' packages. Grab them from145 any GNU archive site."146 touch aclocal.m4147 ;;148149 autoconf*)150 echo 1>&2 "\151WARNING: \`$1' is $msg. You should only need it if152 you modified \`${configure_ac}'. You might want to install the153 \`Autoconf' and \`GNU m4' packages. Grab them from any GNU154 archive site."155 touch configure156 ;;157158 autoheader*)159 echo 1>&2 "\160WARNING: \`$1' is $msg. You should only need it if161 you modified \`acconfig.h' or \`${configure_ac}'. You might want162 to install the \`Autoconf' and \`GNU m4' packages. Grab them163 from any GNU archive site."164 files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}`165 test -z "$files" && files="config.h"166 touch_files=167 for f in $files; do168 case $f in169 *:*) touch_files="$touch_files "`echo "$f" |170 sed -e 's/^[^:]*://' -e 's/:.*//'`;;171 *) touch_files="$touch_files $f.in";;172 esac173 done174 touch $touch_files175 ;;176177 automake*)178 echo 1>&2 "\179WARNING: \`$1' is $msg. You should only need it if180 you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'.181 You might want to install the \`Automake' and \`Perl' packages.182 Grab them from any GNU archive site."183 find . -type f -name Makefile.am -print |184 sed 's/\.am$/.in/' |185 while read f; do touch "$f"; done186 ;;187188 autom4te*)189 echo 1>&2 "\190WARNING: \`$1' is needed, but is $msg.191 You might have modified some files without having the192 proper tools for further handling them.193 You can get \`$1' as part of \`Autoconf' from any GNU194 archive site."195196 file=`echo "$*" | sed -n "$sed_output"`197 test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`198 if test -f "$file"; then199 touch $file200 else201 test -z "$file" || exec >$file202 echo "#! /bin/sh"203 echo "# Created by GNU Automake missing as a replacement of"204 echo "# $ $@"205 echo "exit 0"206 chmod +x $file207 exit 1208 fi209 ;;210211 bison*|yacc*)212 echo 1>&2 "\213WARNING: \`$1' $msg. You should only need it if214 you modified a \`.y' file. You may need the \`Bison' package215 in order for those modifications to take effect. You can get216 \`Bison' from any GNU archive site."217 rm -f y.tab.c y.tab.h218 if test $# -ne 1; then219 eval LASTARG=\${$#}220 case $LASTARG in221 *.y)222 SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'`223 if test -f "$SRCFILE"; then224 cp "$SRCFILE" y.tab.c225 fi226 SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'`227 if test -f "$SRCFILE"; then228 cp "$SRCFILE" y.tab.h229 fi230 ;;231 esac232 fi233 if test ! -f y.tab.h; then234 echo >y.tab.h235 fi236 if test ! -f y.tab.c; then237 echo 'main() { return 0; }' >y.tab.c238 fi239 ;;240241 lex*|flex*)242 echo 1>&2 "\243WARNING: \`$1' is $msg. You should only need it if244 you modified a \`.l' file. You may need the \`Flex' package245 in order for those modifications to take effect. You can get246 \`Flex' from any GNU archive site."247 rm -f lex.yy.c248 if test $# -ne 1; then249 eval LASTARG=\${$#}250 case $LASTARG in251 *.l)252 SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'`253 if test -f "$SRCFILE"; then254 cp "$SRCFILE" lex.yy.c255 fi256 ;;257 esac258 fi259 if test ! -f lex.yy.c; then260 echo 'main() { return 0; }' >lex.yy.c261 fi262 ;;263264 help2man*)265 echo 1>&2 "\266WARNING: \`$1' is $msg. You should only need it if267 you modified a dependency of a manual page. You may need the268 \`Help2man' package in order for those modifications to take269 effect. You can get \`Help2man' from any GNU archive site."270271 file=`echo "$*" | sed -n "$sed_output"`272 test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`273 if test -f "$file"; then274 touch $file275 else276 test -z "$file" || exec >$file277 echo ".ab help2man is required to generate this page"278 exit $?279 fi280 ;;281282 makeinfo*)283 echo 1>&2 "\284WARNING: \`$1' is $msg. You should only need it if285 you modified a \`.texi' or \`.texinfo' file, or any other file286 indirectly affecting the aspect of the manual. The spurious287 call might also be the consequence of using a buggy \`make' (AIX,288 DU, IRIX). You might want to install the \`Texinfo' package or289 the \`GNU make' package. Grab either from any GNU archive site."290 # The file to touch is that specified with -o ...291 file=`echo "$*" | sed -n "$sed_output"`292 test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`293 if test -z "$file"; then294 # ... or it is the one specified with @setfilename ...295 infile=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'`296 file=`sed -n '297 /^@setfilename/{298 s/.* \([^ ]*\) *$/\1/299 p300 q301 }' $infile`302 # ... or it is derived from the source name (dir/f.texi becomes f.info)303 test -z "$file" && file=`echo "$infile" | sed 's,.*/,,;s,.[^.]*$,,'`.info304 fi305 # If the file does not exist, the user really needs makeinfo;306 # let's fail without touching anything.307 test -f $file || exit 1308 touch $file309 ;;310311 *)312 echo 1>&2 "\313WARNING: \`$1' is needed, and is $msg.314 You might have modified some files without having the315 proper tools for further handling them. Check the \`README' file,316 it often tells you about the needed prerequisites for installing317 this package. You may also peek at any GNU archive site, in case318 some other package would contain this missing \`$1' program."319 exit 1320 ;;321esac322323exit 0324325# Local variables:326# eval: (add-hook 'write-file-hooks 'time-stamp)327# time-stamp-start: "scriptversion="328# time-stamp-format: "%:y-%02m-%02d.%02H"329# time-stamp-time-zone: "UTC"330# time-stamp-end: "; # UTC"331# End:
added:config/ylwrap+226 added
1#! /bin/sh2# ylwrap - wrapper for lex/yacc invocations.34scriptversion=2011-08-25.18; # UTC56# Copyright (C) 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004, 2005,7# 2007, 2009, 2010, 2011 Free Software Foundation, Inc.8#9# Written by Tom Tromey <tromey@cygnus.com>.10#11# This program is free software; you can redistribute it and/or modify12# it under the terms of the GNU General Public License as published by13# the Free Software Foundation; either version 2, or (at your option)14# any later version.15#16# This program is distributed in the hope that it will be useful,17# but WITHOUT ANY WARRANTY; without even the implied warranty of18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the19# GNU General Public License for more details.20#21# You should have received a copy of the GNU General Public License22# along with this program. If not, see <http://www.gnu.org/licenses/>.2324# As a special exception to the GNU General Public License, if you25# distribute this file as part of a program that contains a26# configuration script generated by Autoconf, you may include it under27# the same distribution terms that you use for the rest of that program.2829# This file is maintained in Automake, please report30# bugs to <bug-automake@gnu.org> or send patches to31# <automake-patches@gnu.org>.3233case "$1" in34 '')35 echo "$0: No files given. Try \`$0 --help' for more information." 1>&236 exit 137 ;;38 --basedir)39 basedir=$240 shift 241 ;;42 -h|--h*)43 cat <<\EOF44Usage: ylwrap [--help|--version] INPUT [OUTPUT DESIRED]... -- PROGRAM [ARGS]...4546Wrapper for lex/yacc invocations, renaming files as desired.4748 INPUT is the input file49 OUTPUT is one file PROG generates50 DESIRED is the file we actually want instead of OUTPUT51 PROGRAM is program to run52 ARGS are passed to PROG5354Any number of OUTPUT,DESIRED pairs may be used.5556Report bugs to <bug-automake@gnu.org>.57EOF58 exit $?59 ;;60 -v|--v*)61 echo "ylwrap $scriptversion"62 exit $?63 ;;64esac656667# The input.68input="$1"69shift70case "$input" in71 [\\/]* | ?:[\\/]*)72 # Absolute path; do nothing.73 ;;74 *)75 # Relative path. Make it absolute.76 input="`pwd`/$input"77 ;;78esac7980pairlist=81while test "$#" -ne 0; do82 if test "$1" = "--"; then83 shift84 break85 fi86 pairlist="$pairlist $1"87 shift88done8990# The program to run.91prog="$1"92shift93# Make any relative path in $prog absolute.94case "$prog" in95 [\\/]* | ?:[\\/]*) ;;96 *[\\/]*) prog="`pwd`/$prog" ;;97esac9899# FIXME: add hostname here for parallel makes that run commands on100# other machines. But that might take us over the 14-char limit.101dirname=ylwrap$$102do_exit="cd '`pwd`' && rm -rf $dirname > /dev/null 2>&1;"' (exit $ret); exit $ret'103trap "ret=129; $do_exit" 1104trap "ret=130; $do_exit" 2105trap "ret=141; $do_exit" 13106trap "ret=143; $do_exit" 15107mkdir $dirname || exit 1108109cd $dirname110111case $# in112 0) "$prog" "$input" ;;113 *) "$prog" "$@" "$input" ;;114esac115ret=$?116117if test $ret -eq 0; then118 set X $pairlist119 shift120 first=yes121 # Since DOS filename conventions don't allow two dots,122 # the DOS version of Bison writes out y_tab.c instead of y.tab.c123 # and y_tab.h instead of y.tab.h. Test to see if this is the case.124 y_tab_nodot="no"125 if test -f y_tab.c || test -f y_tab.h; then126 y_tab_nodot="yes"127 fi128129 # The directory holding the input.130 input_dir=`echo "$input" | sed -e 's,\([\\/]\)[^\\/]*$,\1,'`131 # Quote $INPUT_DIR so we can use it in a regexp.132 # FIXME: really we should care about more than `.' and `\'.133 input_rx=`echo "$input_dir" | sed 's,\\\\,\\\\\\\\,g;s,\\.,\\\\.,g'`134135 while test "$#" -ne 0; do136 from="$1"137 # Handle y_tab.c and y_tab.h output by DOS138 if test $y_tab_nodot = "yes"; then139 if test $from = "y.tab.c"; then140 from="y_tab.c"141 else142 if test $from = "y.tab.h"; then143 from="y_tab.h"144 fi145 fi146 fi147 if test -f "$from"; then148 # If $2 is an absolute path name, then just use that,149 # otherwise prepend `../'.150 case "$2" in151 [\\/]* | ?:[\\/]*) target="$2";;152 *) target="../$2";;153 esac154155 # We do not want to overwrite a header file if it hasn't156 # changed. This avoid useless recompilations. However the157 # parser itself (the first file) should always be updated,158 # because it is the destination of the .y.c rule in the159 # Makefile. Divert the output of all other files to a temporary160 # file so we can compare them to existing versions.161 if test $first = no; then162 realtarget="$target"163 target="tmp-`echo $target | sed s/.*[\\/]//g`"164 fi165 # Edit out `#line' or `#' directives.166 #167 # We don't want the resulting debug information to point at168 # an absolute srcdir; it is better for it to just mention the169 # .y file with no path.170 #171 # We want to use the real output file name, not yy.lex.c for172 # instance.173 #174 # We want the include guards to be adjusted too.175 FROM=`echo "$from" | sed \176 -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\177 -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'`178 TARGET=`echo "$2" | sed \179 -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\180 -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'`181182 sed -e "/^#/!b" -e "s,$input_rx,," -e "s,$from,$2," \183 -e "s,$FROM,$TARGET," "$from" >"$target" || ret=$?184185 # Check whether header files must be updated.186 if test $first = no; then187 if test -f "$realtarget" && cmp -s "$realtarget" "$target"; then188 echo "$2" is unchanged189 rm -f "$target"190 else191 echo updating "$2"192 mv -f "$target" "$realtarget"193 fi194 fi195 else196 # A missing file is only an error for the first file. This197 # is a blatant hack to let us support using "yacc -d". If -d198 # is not specified, we don't want an error when the header199 # file is "missing".200 if test $first = yes; then201 ret=1202 fi203 fi204 shift205 shift206 first=no207 done208else209 ret=$?210fi211212# Remove the directory.213cd ..214rm -rf $dirname215216exit $ret217218# Local Variables:219# mode: shell-script220# sh-indentation: 2221# eval: (add-hook 'write-file-hooks 'time-stamp)222# time-stamp-start: "scriptversion="223# time-stamp-format: "%:y-%02m-%02d.%02H"224# time-stamp-time-zone: "UTC"225# time-stamp-end: "; # UTC"226# End:
modified:docs/content/3.manual/manual.yml+2 added-2 removed
164 unmodified lines
165 166 You can also look up fields of an object using syntax like167 `.["foo"]` (.foo above is a shorthand version of this). This168 one works for arrays as well, if the key is an169 integer. Arrays are zero-based (like javascript), so .[2]169 integer. Arrays are zero-based (like javascript), so `.[2]`170 returns the third element of the array.171172 examples:173 - program: '.[0]'
96 unmodified lines
270 in `[.foo, .bar, .baz]`) or to "collect" all the results of a271 filter into an array (as in `[.items[].name]`)272 273 Once you understand the "," operator, you can look at jq's array274 syntax in a different light: the expression [1,2,3] is not using a274 syntax in a different light: the expression `[1,2,3]` is not using a275 built-in syntax for comma-separated arrays, but is instead applying276 the `[]` operator (collect results) to the expression 1,2,3 (which277 produces three different results).278
922 unmodified lines
added:docs/default_manpage.md+22 added
modified:docs/Rakefile+35 added
1require 'yaml'2require 'bonsai'3require 'liquid'4require 'maruku'5require 'json'
57 unmodified lines
63 Bonsai.root_dir = Dir.pwd64 Bonsai::Exporter.publish!65end6667$BINARIES = {68 :osx32 => "--host=i686-apple-darwin10 CFLAGS='-m32 -g -O'",69 :osx64 => "--host=i686-apple-darwin10 CFLAGS='-m64 -g -O'",70 :win32 => "--host=i686-w64-mingw32 CFLAGS='-g -O'",71 :win64 => "--host=x86_64-w64-mingw32 CFLAGS='-g -O'",72 :linux32 => "--host=x86_64-linux-gnu CFLAGS='-m32 -g -O'",73 :linux64 => "--host=x86_64-linux-gnu CFLAGS='-m64 -g -O'"74}7576$BINARIES.each do |name, args|77 file "../build/#{name}" do |t|78 sh "MAKEFLAGS=-j4 ../scripts/crosscompile #{name} #{args}"79 end80 task :binaries => ["../build/#{name}"]81end8283task :binaries => ["output/download"] do84 $BINARIES.each do |name, args|85 FileUtils.cp_r "../build/#{name}", "output/download/"86 end87end8889def load_manual90 YAML::ENGINE.yamler = 'syck'91 YAML::load(File.open("content/3.manual/manual.yml"))92end
26 unmodified lines
119 puts Ronn::Document.new(f.path).convert('roff').gsub(/<\/?code>/,"")120 end 121end122123task :manpage_default => ["default_manpage.md"] do124 puts Ronn::Document.new("default_manpage.md").convert('roff').gsub(/<\/?code>/,"")125end126127task :mantests do128 load_manual['sections'].each do |section|129 (section['entries'] || []).each do |entry|130 (entry['examples'] || []).each do |example|
4 unmodified lines
135 end136 end137 end138end139140directory "output/download/source"141task :tarball => ["output/download/source"] do142 sh "cd ..; ./configure && make dist && make distclean"143 sh "cp ../jq-*.tar.gz output/download/source"144end145146task :dist => [:build, :binaries, :tarball]
added:docs/README.md+25 added
modified:docs/site.yml+5 added-1 removed
added:scripts/crosscompile+31 added
1#!/bin/sh23# This script is used to cross-compile binaries for 4# platforms other than the current one56# Usage: $0 <platformname> <configure options>7# <platformname> is arbitrary, it is the name8# of the directory which will be created to contain9# the output binaries.1011# e.g. $0 win32 --host=i686-w64-mingw321213set -e14cd `dirname "$0"`/../build1516plat="$1"17[ -z "$plat" ] && exit 118shift1920[ -d "$plat" ] || mkdir "$plat"21rm -rf "$plat/tmp"22mkdir "$plat/tmp"23cd "$plat/tmp"24mkdir install_other25../../../configure \26 --prefix="`pwd`/install_other" \27 --bindir="`pwd`/.." \28 "$@"29make install-binaries30cd ..31rm -rf tmp
added:tests/all.test+576 added
1# Tests are groups of three lines: program, input, expected output2# Blank lines and lines starting with # are ignored34#5# Simple value tests to check parser. Input is irrelevant6#78true9null10true1112false13null14false1516null174218null1920121null221232425-126null27-12829# FIXME: much more number testing needed3031{}32null33{}3435[]36null37[]3839# The input line starts with a 0xFEFF (byte order mark) codepoint40# No, there is no reason to have a byte order mark in UTF8 text.41# But apparently people do, so jq shouldn't break on it.42.43"byte order mark"44"byte order mark"4546# We test escapes by matching them against Unicode codepoints47# FIXME: more tests needed for weird unicode stuff (e.g. utf16 pairs)48"Aa\r\n\t\b\f\u03bc"49null50"Aa\u000d\u000a\u0009\u0008\u000c\u03bc"5152.53"Aa\r\n\t\b\f\u03bc"54"Aa\u000d\u000a\u0009\u0008\u000c\u03bc"5556"inter\("pol" + "ation")"57null58"interpolation"5960@text,@json,([1,.] | @csv),@html,@uri,@sh,@base6461"<>&'\""62"<>&'\""63"\"<>&'\\\"\""64"1,\"<>&'\"\"\""65"&lt;&gt;&amp;&apos;&quot;"66"%3c%3e%26'%22"67"'<>&'\\''\"'"68"PD4mJyI="6970@uri71"\u03bc"72"%ce%bc"7374@html "<b>\(.)</b>"75"<script>hax</script>"76"<b>&lt;script&gt;hax&lt;/script&gt;</b>"7778#79# Dictionary construction syntax80#8182{a: 1}83null84{"a":1}8586{a,b,(.d):.a,e:.b}87{"a":1, "b":2, "c":3, "d":"c"}88{"a":1, "b":2, "c":1, "e":2}8990{"a",b,"a$\(1+1)"}91{"a":1, "b":2, "c":3, "a$2":4}92{"a":1, "b":2, "a$2":4}9394#95# Field access, piping96#9798.foo99{"foo": 42, "bar": 43}10042101102.foo | .bar103{"foo": {"bar": 42}, "bar": "badvalue"}10442105106.foo.bar107{"foo": {"bar": 42}, "bar": "badvalue"}10842109110.foo_bar111{"foo_bar": 2}1122113114.["foo"].bar115{"foo": {"bar": 42}, "bar": "badvalue"}11642117118119#120# Multiple outputs, iteration121#122123.[]124[1,2,3]1251126212731281291,1130[]131113211331341,.135[]1361137[]138139[.]140[2]141[[2]]142143[[2]]144[3]145[[2]]146147[{}]148[2]149[{}]150151[.[]]152["a"]153["a"]154155[(.,1),((.,.[]),(2,3))]156["a","b"]157[["a","b"],1,["a","b"],"a","b",2,3]158159[([5,5][]),.,.[]]160[1,2,3]161[5,5,[1,2,3],1,2,3]162163{x: (1,2)},{x:3} | .x164null165116621673168169#170# Variables171#1721731 as $x | 2 as $y | [$x,$y,$x]174null175[1,2,1]176177[1,2,3][] as $x | [[4,5,6,7][$x]]178null179[5]180[6]181[7]18218342 as $x | . | . | . + 432 | $x + 118434324185431861871 as $x | [$x,$x,$x as $x | $x]188null189[1,1,1]190191# [.,(.[] | {x:.},.),.,.[]]192193#194# Builtin functions195#1961971+1198null19922002011+1202"wtasdf"2032.02042052-1206null20712082092-(-1)210null21132122131e+0+0.001e3214"I wonder what this will be?"21520e-1216217.+42181521919.0220221.+null222{"a":42}223{"a":42}224225null+.226null227null228229.a+.b230{"a":42}23142232233[1,2,3] + [.]234null235[1,2,3,null]236237{"a":1} + {"b":2} + {"c":3}238"asdfasdf"239{"a":1, "b":2, "c":3}240241"asdf" + "jkl;" + . + . + .242"some string"243"asdfjkl;some stringsome stringsome string"244245"\u0000\u0020\u0000" + .246"\u0000\u0020\u0000"247"\u0000 \u0000\u0000 \u0000"24824942 - .2501125131252253[1,2,3,4,1] - [.,3]2541255[2,4]256257[10 * 20, 20 / .]2584259[200, 5]2602611 + 2 * 2 + 10 / 2262null26310264265[16 / 4 / 2, 16 / 4 * 2, 16 - 4 - 2, 16 - 4 + 2]266null267[2, 8, 10, 14]2682691 + tonumber + ("10" | tonumber)270427115272273[{"a":42},.object,10,.num,false,true,null,"b",[1,4]] | .[] as $x | [$x == .[]]274{"object": {"a":42}, "num":10.0}275[true, true, false, false, false, false, false, false, false]276[true, true, false, false, false, false, false, false, false]277[false, false, true, true, false, false, false, false, false]278[false, false, true, true, false, false, false, false, false]279[false, false, false, false, true, false, false, false, false]280[false, false, false, false, false, true, false, false, false]281[false, false, false, false, false, false, true, false, false]282[false, false, false, false, false, false, false, true, false]283[false, false, false, false, false, false, false, false, true ]284285[.[] | length]286[[], {}, [1,2], {"a":42}, "asdf"]287[0, 0, 2, 1, 4]288289map(keys)290[{}, {"abcd":1,"abc":2,"abcde":3}, {"x":1, "z": 3, "y":2}]291[[], ["abc","abcd","abcde"], ["x","y","z"]]292293[1,2,empty,3,empty,4]294null295[1,2,3,4]296297map(add)298[[], [1,2,3], ["a","b","c"], [[3],[4,5],[6]], [{"a":1}, {"b":2}, {"a":3}]]299[null, 6, "abc", [3,4,5,6], {"a":3, "b": 2}]300301#302# User-defined functions303# Oh god.304#305306def f: . + 1; def g: def g: . + 100; f | g | f; (f | g), g3073.0308106.0309105.0310311def f: (1000,2000); f31212341234531310003142000315316([1,2] + [4,5])317[1,2,3]318[1,2,4,5]319320true321[1]322true323324null,1,null325"hello"326null3271328null329330[1,2,3]331[5,6]332[1,2,3]333334def f(x): x | x; f([.], . + [42])335[1,2,3]336[[[1,2,3]]]337[[1,2,3],42]338[[1,2,3,42]]339[1,2,3,42,42]340341# test closures and lexical scoping342def id(x):x; 2000 as $x | def f(x):1 as $x | id([$x, x, x]); def g(x): 100 as $x | f($x,$x+x); g($x)343"more testing"344[1,100,2100.0,100,2100.0]345346# test backtracking through function calls and returns347# this test is *evil*348[[20,10][1,0] as $x | def f: (100,200) as $y | def g: [$x + $y, .]; . + $x | g; f[0] | [f][0][1] | f]349999999999350[[110.0, 130.0], [210.0, 130.0], [110.0, 230.0], [210.0, 230.0], [120.0, 160.0], [220.0, 160.0], [120.0, 260.0], [220.0, 260.0]]351352# test recursion353def fac: if . == 1 then 1 else . * (. - 1 | fac) end; [.[] | fac]354[1,2,3,4]355[1,2,6,24]356357# test stack overflow and reallocation358# this test is disabled for now, it takes a realllllly long time.359# def f: if length > 1000 then . else .+[1]|f end; f | length360# []361# 1001362363fold 0 as $s (.[] | $s + .)364[1,2,4]3657366367#368# Paths369#370371path(.foo[0,1])372null373["foo", 0]374["foo", 1]375376path(.[] | select(.>3))377[1,5,3]378[1]379380path(.)38142382[]383384["foo",1] as $p | getpath($p), setpath($p; 20), delpaths([$p])385{"bar": 42, "foo": ["a", "b", "c", "d"]}386"b"387{"bar": 42, "foo": ["a", 20, "c", "d"]}388{"bar": 42, "foo": ["a", "c", "d"]}389390map(getpath([2])), map(setpath([2]; 42)), map(delpaths([[2]]))391[[0], [0,1], [0,1,2]]392[null, null, 2]393[[0,null,42], [0,1,42], [0,1,42]]394[[0], [0,1], [0,1]]395396map(delpaths([[0,"foo"]]))397[[{"foo":2, "x":1}], [{"bar":2}]]398[[{"x":1}], [{"bar":2}]]399400["foo",1] as $p | getpath($p), setpath($p; 20), delpaths([$p])401{"bar":false}402null403{"bar":false, "foo": [null, 20]}404{"bar":false}405406delpaths([[-200]])407[1,2,3]408[1,2,3]409410del(.), del(empty), del((.foo,.bar,.baz) | .[2,3,0]), del(.foo[0], .bar[0], .foo, .baz.bar[0].x)411{"foo": [0,1,2,3,4], "bar": [0,1]}412null413{"foo": [0,1,2,3,4], "bar": [0,1]}414{"foo": [1,4], "bar": [1]}415{"bar": [1]}416417#418# Assignment419#420.message = "goodbye"421{"message": "hello"}422{"message": "goodbye"}423424.foo = .bar425{"bar":42}426{"foo":42, "bar":42}427428.foo |= .+1429{"foo": 42}430{"foo": 43}431432.[] += 2, .[] *= 2, .[] -= 2, .[] /= 2433[1,3,5]434[3,5,7]435[2,6,10]436[-1,1,3]437[0.5, 1.5, 2.5]438439.foo += .foo440{"foo":2}441{"foo":4}442443.[0].a |= {"old":., "new":(.+1)}444[{"a":1,"b":2}]445[{"a":{"old":1, "new":2},"b":2}]446447def inc(x): x |= .+1; inc(.[].a)448[{"a":1,"b":2},{"a":2,"b":4},{"a":7,"b":8}]449[{"a":2,"b":2},{"a":3,"b":4},{"a":8,"b":8}]450451.[2][3] = 1452[4]453[4, null, [null, null, null, 1]]454455.foo[2].bar = 1456{"foo":[11], "bar":42}457{"foo":[11,null,{"bar":1}], "bar":42}458459#460# Conditionals461#462463[.[] | if .foo then "yep" else "nope" end]464[{"foo":0},{"foo":1},{"foo":[]},{"foo":true},{"foo":false},{"foo":null},{"foo":"foo"},{}]465["yep","yep","yep","yep","nope","nope","yep","nope"]466467[.[] | if .baz then "strange" elif .foo then "yep" else "nope" end]468[{"foo":0},{"foo":1},{"foo":[]},{"foo":true},{"foo":false},{"foo":null},{"foo":"foo"},{}]469["yep","yep","yep","yep","nope","nope","yep","nope"]470471472# FIXME: define/test behaviour of 'if (.foo,.bar) then A else B end'473474[.[] | [.foo[] // .bar]]475[{"foo":[1,2], "bar": 42}, {"foo":[1], "bar": null}, {"foo":[null,false,3], "bar": 18}, {"foo":[], "bar":42}, {"foo": [null,false,null], "bar": 41}]476[[1,2], [1], [3], [42], [41]]477478# FIXME: behaviour of update operators479# .[] //= .[0]480# ["hello",true,false,[false],null]481# ["hello",true,"hello",[false],"hello"]482483.[] | [.[0] and .[1], .[0] or .[1]]484[[true,[]], [false,1], [42,null], [null,false]]485[true,true]486[false,true]487[false,true]488[false,false]489490[.[] | not]491[1,0,false,null,true,"hello"]492[false,false,true,true,false,false]493494# Check numeric comparison binops495[10 > 0, 10 > 10, 10 > 20, 10 < 0, 10 < 10, 10 < 20]496{}497[true,false,false,false,false,true]498499[10 >= 0, 10 >= 10, 10 >= 20, 10 <= 0, 10 <= 10, 10 <= 20]500{}501[true,true,false,false,true,true]502503# And some in/equality tests504[ 10 == 10, 10 != 10, 10 != 11, 10 == 11]505{}506[true,false,true,false]507508["hello" == "hello", "hello" != "hello", "hello" == "world", "hello" != "world" ]509{}510[true,false,false,true]511512[[1,2,3] == [1,2,3], [1,2,3] != [1,2,3], [1,2,3] == [4,5,6], [1,2,3] != [4,5,6]]513{}514[true,false,false,true]515516[{"foo":42} == {"foo":42},{"foo":42} != {"foo":42}, {"foo":42} != {"bar":42}, {"foo":42} == {"bar":42}]517{}518[true,false,true,false]519520# ugly complicated thing521[{"foo":[1,2,{"bar":18},"world"]} == {"foo":[1,2,{"bar":18},"world"]},{"foo":[1,2,{"bar":18},"world"]} == {"foo":[1,2,{"bar":19},"world"]}]522{}523[true,false]524525# containment operator526[("foo" | contains("foo")), ("foobar" | contains("foo")), ("foo" | contains("foobar"))]527{}528[true, true, false]529530map(.[1] as $needle | .[0] | contains($needle))531[[[],[]], [[1,2,3], [1,2]], [[1,2,3], [3,1]], [[1,2,3], [4]], [[1,2,3], [1,4]]]532[true, true, true, false, false]533534map(.[1] as $needle | .[0] | contains($needle))535[[["foobar", "foobaz"], ["baz", "bar"]], [["foobar", "foobaz"], ["foo"]], [["foobar", "foobaz"], ["blap"]]]536[true, true, false]537538[({foo: 12, bar:13} | contains({foo: 12})), ({foo: 12} | contains({})), ({foo: 12, bar:13} | contains({baz:14}))]539{}540[true, true, false]541542{foo: {baz: 12, blap: {bar: 13}}, bar: 14} | contains({bar: 14, foo: {blap: {}}})543{}544true545546{foo: {baz: 12, blap: {bar: 13}}, bar: 14} | contains({bar: 14, foo: {blap: {bar: 14}}})547{}548false549550sort551[42,[2,5,3,11],10,{"a":42,"b":2},{"a":42},true,2,[2,6],"hello",null,[2,5,6],{"a":[],"b":1},"abc","ab",[3,10],{},false,"abcd",null]552[null,null,false,true,2,10,42,"ab","abc","abcd","hello",[2,5,3,11],[2,5,6],[2,6],[3,10],{},{"a":42},{"a":42,"b":2},{"a":[],"b":1}]553554(sort_by(.b) | sort_by(.a)), sort_by(.a, .b), sort_by(.b, .c), group_by(.b), group_by(.a + .b - .c == 2)555[{"a": 1, "b": 4, "c": 14}, {"a": 4, "b": 1, "c": 3}, {"a": 1, "b": 4, "c": 3}, {"a": 0, "b": 2, "c": 43}]556[{"a": 0, "b": 2, "c": 43}, {"a": 1, "b": 4, "c": 14}, {"a": 1, "b": 4, "c": 3}, {"a": 4, "b": 1, "c": 3}]557[{"a": 0, "b": 2, "c": 43}, {"a": 1, "b": 4, "c": 14}, {"a": 1, "b": 4, "c": 3}, {"a": 4, "b": 1, "c": 3}]558[{"a": 4, "b": 1, "c": 3}, {"a": 0, "b": 2, "c": 43}, {"a": 1, "b": 4, "c": 3}, {"a": 1, "b": 4, "c": 14}]559[[{"a": 4, "b": 1, "c": 3}], [{"a": 0, "b": 2, "c": 43}], [{"a": 1, "b": 4, "c": 14}, {"a": 1, "b": 4, "c": 3}]]560[[{"a": 1, "b": 4, "c": 14}, {"a": 0, "b": 2, "c": 43}], [{"a": 4, "b": 1, "c": 3}, {"a": 1, "b": 4, "c": 3}]]561562unique563[1,2,5,3,5,3,1,3]564[1,2,3,5]565566[min, max, min_by(.[1]), max_by(.[1]), min_by(.[2]), max_by(.[2])]567[[4,2,"a"],[3,1,"a"],[2,4,"a"],[1,3,"a"]]568[[1,3,"a"],[4,2,"a"],[3,1,"a"],[2,4,"a"],[4,2,"a"],[1,3,"a"]]569570[min,max,min_by(.),max_by(.)]571[]572[null,null,null,null]573574.foo[.baz]575{"foo":{"bar":4},"baz":"bar"}5764
added:tests/run+3 added
1#!/bin/sh23cat $@ | valgrind --error-exitcode=1 -q --leak-check=full ./jq --run-tests
modified:.gitignore+21 added-6 removed
1*.o2*~34# Autogenerated5*.gen.*67jq_test8build4jq5jq.167# Something delightfully recursive happens otherwise13docs/content/2.download/source/*8docs/content/2.download/source/*910# Autogenerated11lexer.c12lexer.h13parser.c14parser.h1516# Autotools junk17.deps18*.log19stamp-h120config.log21config.status22autom4te.cache23config.h24Makefile25jq-*.tar.gz26configure27aclocal.m428Makefile.in
added:AUTHORS+6 added
1Created By:2Stephen Dolan <mu@netsoc.tcd.ie>34Contributions by5Anthony Shortland <anthony.shortland@me.com> - rpmbuild target6Lee Thompson <stagr.lee@gmail.com> - autoconf stuff
modified:builtin.c+1 added-1 removed
1#include <string.h>2#include "builtin.h"3#include "compile.h"4#include "parser.h"4#include "jq_parser.h"5#include "locfile.h"6#include "jv_aux.h"7#include "jv_unicode.h"8
557 unmodified lines
added:config.h.in+32 added
1/* config.h.in. Generated from configure.ac by autoheader. */23/* Define to 1 if your C compiler doesn't accept -c and -o together. */4#undef NO_MINUS_C_MINUS_O56/* Name of package */7#undef PACKAGE89/* Define to the address where bug reports for this package should be sent. */10#undef PACKAGE_BUGREPORT1112/* Define to the full name of this package. */13#undef PACKAGE_NAME1415/* Define to the full name and version of this package. */16#undef PACKAGE_STRING1718/* Define to the one symbol short name of this package. */19#undef PACKAGE_TARNAME2021/* Define to the home page for this package. */22#undef PACKAGE_URL2324/* Define to the version of this package. */25#undef PACKAGE_VERSION2627/* Version number of package */28#undef VERSION2930/* Define to 1 if `lex' declares `yytext' as a `char *' by default, not a31 `char[]'. */32#undef YYTEXT_POINTER
added:configure.ac+66 added
1AC_INIT([jq], [1.2], [mu@netsoc.tcd.ie],2 [jq], [http://stedolan.github.com/jq/])34dnl Created autoconf implementation thompson@dtosolutions, 26NOV125AC_PREREQ([2.61])6AC_CONFIG_AUX_DIR([config])7AM_INIT_AUTOMAKE([parallel-tests foreign])8AM_SILENT_RULES([yes])9AC_PROG_CC10AC_PROG_CC_STDC11AC_PROG_CPP_WERROR12AC_PROG_YACC1314AM_PROG_CC_C_O1516dnl couldn't use AM_PROG_LEX as it doesn't support header files like the17dnl AC_PROG_YACC macros...1819dnl20dnl these program checks should probably be deleted21dnl2223AC_PROG_LEX24if test "x$LEX" != xflex; then25 LEX="$SHELL $missing_dir/missing flex"26fi272829dnl Check for valgrind30AC_CHECK_PROGS(valgrind_cmd, valgrind)31if test "x$valgrind_cmd" = "x" ; then32 AC_MSG_WARN([valgrind is required to test jq.])33fi343536dnl Don't attempt to build docs if there's no Ruby lying around37AC_ARG_ENABLE([docs],38 AC_HELP_STRING([--disable-docs], [don't build docs]))3940AS_IF([test "x$enable_docs" != "xno"],[41 AC_CHECK_PROGS(bundle_cmd, bundle)42 AS_IF([test "x$bundle_cmd" = "x" || \43 ! ( cd ${srcdir}/docs; "$bundle_cmd" check 2>/dev/null )],[44 AC_MSG_WARN([no bundler])45 cat <<EOF46*****************************************************************47* Ruby dependencies for building jq documentation not found. *48* You can still build, install and hack on jq, but the manpage *49* will not be rebuilt and some of the tests won't run. *50* See docs/README.md for how to install the docs dependencies. *51*****************************************************************52EOF53 enable_docs=no54 ])55])5657AM_CONDITIONAL([ENABLE_DOCS], [test "x$enable_docs" != xno])58AC_SUBST([BUNDLER], ["$bundle_cmd"])5960dnl AC_CONFIG_MACRO_DIR([m4])61AC_CONFIG_HEADERS(config.h)62AM_INIT_AUTOMAKE([-Wall])63AC_CONFIG_FILES([Makefile])64AC_OUTPUT6566
modified:execute.c+2 added-1 removed
10 unmodified lines
11#include "forkable_stack.h"12#include "frame_layout.h"1314#include "jv_alloc.h"15#include "jq_parser.h"16#include "locfile.h"17#include "jv.h"18#include "jv_aux.h"19#include "parser.h"
147 unmodified lines
167 if (jq->debug_trace_enabled) {168 dump_operation(frame_current_bytecode(&jq->frame_stk), pc);169 printf("\t");170 const struct opcode_description* opdesc = opcode_describe(opcode);170 data_stk_elem* param;171 data_stk_elem* param = 0;172 int stack_in = opdesc->stack_in;173 if (stack_in == -1) stack_in = pc[1];174 for (int i=0; i<stack_in; i++) {175 if (i == 0) {
363 unmodified lines
modified:gen_utf8_tables.py+2 added
1#!/usr/bin/python23# This program was used to generate jv_utf8_tables.gen.h45mask = lambda n: (1 << n) - 1678def print_table(type, name, t):
24 unmodified lines
added:jq_parser.h+7 added
1#ifndef JQ_PARSER_H2#define JQ_PARSER_H34int jq_parse(struct locfile* source, block* answer);5int jq_parse_library(struct locfile* locations, block* answer);67#endif
modified:jq_test.c+2 added-19 removed
6 unmodified lines
78static void jv_test();9static void run_jq_tests();1011FILE* testdata;1112int jq_testsuite(int argc, char* argv[]) {13 jv_test();15 if (argc == 1) {16 testdata = fopen("testdata", "r");17 } else if (argc == 2) {18 if (!strcmp(argv[1], "-")) {19 testdata = stdin;20 } else {21 testdata = fopen(argv[1], "r");22 }23 } else {24 printf("usage: %s OR cat testdata | %s - OR %s testdata\n", argv[0], argv[0], argv[0]);25 return 127;26 }27 run_jq_tests();14 run_jq_tests(stdin);28 if (testdata != stdin) fclose(testdata);15 return 0;16}1732333418static int skipline(const char* buf) {19 int p = 0;20 while (buf[p] == ' ' || buf[p] == '\t') p++;21 if (buf[p] == '#' || buf[p] == '\n' || buf[p] == 0) return 1;22 return 0;23}2442static void run_jq_tests() {25static void run_jq_tests(FILE *testdata) {26 char buf[4096];27 int tests = 0, passed = 0, invalid = 0;28 jq_state *jq = NULL;29
200 unmodified lines
added:jq.1.default+39 added
1.\" generated with Ronn/v0.7.32.\" http://github.com/rtomayko/ronn/tree/0.7.33.4.TH "JQ" "1" "May 2013" "" ""5.6.SH "NAME"7\fBjq\fR \- Command\-line JSON processor8.9.SH "DESCRIPTION"10\fBjq\fR can transform JSON in various ways, by selecting, iterating, reducing and otherwise mangling JSON documents\.11.12.P13This version of \fBjq\fR was built without a manual, so this manpage is a stub\. For full documentation of the \fBjq\fR language, see:14.15.IP "" 416.17.nf1819http://stedolan\.github\.com/jq20.21.fi22.23.IP "" 024.25.SH "BUGS"26Presumably\. Report them or discuss them at:27.28.IP "" 429.30.nf3132https://github\.com/stedolan/jq/issues33.34.fi35.36.IP "" 037.38.SH "AUTHOR"39Stephen Dolan \fB<mu@netsoc\.tcd\.ie>\fR
added:jq.spec+65 added
1# This is spec file maintained by developers of JQ, not by a OS distro.2# Your OS of choice will likely ignore this RPM spec file.3Summary: Command-line JSON processor4Name: jq5Version: %{myver}6Release: %{myrel}%{?dist}7Source0: jq-%{myver}.tar.gz8URL: https://github.com/stedolan/jq9License: BSD10AutoReqProv: no11#BuildPrereq: autoconf, libtool, automake, flex, bison, python1213Group: Applications/System14# Requires:1516# Disables debug packages and stripping of binaries:17%global _enable_debug_package 018%global debug_package %{nil}19%global __os_install_post %{nil}2021# Crank up the compression22%define _binary_payload w7.lzdio2324%description25jq is a command-line JSON processor2627%prep28%setup2930%build31echo "Building in: \"$(pwd)\""32%if "%{devbuild}" == "yes"33./configure --prefix=%{_prefix} --enable-devel34%else35./configure --prefix=%{_prefix}36%endif37make3839%install40echo "Installing to: \"%{buildroot}\""41make install DESTDIR=%{buildroot}4243%clean44rm -rf %{buildroot}4546%files47%defattr(-,root,root)48%{_bindir}/jq49%if "%{devbuild}" == "yes"50%{_libexecdir}/%{name}/jq_test51%{_libexecdir}/%{name}/testdata52%endif53%{_datadir}/doc/%{name}/AUTHORS54%{_datadir}/doc/%{name}/COPYING55%{_datadir}/doc/%{name}/INSTALL56%{_datadir}/doc/%{name}/NEWS57%{_datadir}/doc/%{name}/README58%{_datadir}/doc/%{name}/README.md59%{_datadir}/man/man1/jq.16061%changelog6263%pre6465%post
modified:jv_unicode.c+1 added-1 removed
1#include <stdio.h>2#include <assert.h>3#include "jv_unicode.h"4#include "jv_utf8_tables.gen.h"4#include "jv_utf8_tables.h"56const char* jvp_utf8_next(const char* in, const char* end, int* codepoint) {7 if (in == end) {8 codepoint = 0;
56 unmodified lines
added:jv_utf8_tables.h+35 added
1#define UTF8_CONTINUATION_BYTE ((unsigned char)255)2static const unsigned char utf8_coding_length[] =3 {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,4 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,5 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,6 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,7 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,8 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,9 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,10 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,11 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,12 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,13 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,14 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,15 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,16 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,17 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,18 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};19static const unsigned char utf8_coding_bits[] =20 {0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f,21 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f,22 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f,23 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f,24 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f,25 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f,26 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f,27 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f,28 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f,29 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f,30 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f,31 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f,32 0x00, 0x00, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f,33 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f,34 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,35 0x07, 0x07, 0x07, 0x07, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
modified:lexer.l+1 added-1 removed
2 unmodified lines
3#include "compile.h"45struct lexer_param;67#include "parser.gen.h" /* Generated by bison. */7#include "parser.h" /* Generated by bison. */89#define YY_USER_ACTION \10 do { \11 yylloc->start = yyget_extra(yyscanner); \
160 unmodified lines
modified:main.c+7 added-5 removed
6 unmodified lines
7#include "compile.h"8#include "jv.h"9#include "jv_parse.h"10#include "execute.h"11#include "config.h" /* Autoconf generated header file */12#include "jv_alloc.h"12#include "version.gen.h"1314int jq_testsuite(int argc, char* argv[]);1516static const char* progname;1718static void usage() {19 fprintf(stderr, "\njq - commandline JSON processor [version %s]\n", JQ_VERSION);19 fprintf(stderr, "\njq - commandline JSON processor [version %s]\n", PACKAGE_VERSION);20 fprintf(stderr, "Usage: %s [options] <jq filter> [file...]\n\n", progname);21 fprintf(stderr, "For a description of the command line options and\n");22 fprintf(stderr, "how to write jq filters (and why you might want to)\n");23 fprintf(stderr, "see the jq manpage, or the online documentation at\n");
49 unmodified lines
73 fwrite(jv_string_value(result), 1, jv_string_length(jv_copy(result)), stdout);74 jv_free(result);75 } else {76 int dumpopts;77#ifdef JQ_DEFAULT_ENABLE_COLOR78 dumpopts = JQ_DEFAULT_ENABLE_COLOR ? JV_PRINT_COLOUR : 0;77 /* Disable colour by default on Windows builds as Windows78 terminals tend not to display it correctly */79#ifdef WIN3280 dumpopts = 0;81#else82 dumpopts = isatty(fileno(stdout)) ? JV_PRINT_COLOUR : 0;83#endif84 if (!(options & COMPACT_OUTPUT)) dumpopts |= JV_PRINT_PRETTY;
119 unmodified lines
204 jq_flags |= JQ_DEBUG_TRACE;205 } else if (isoption(argv[i], 'h', "help")) {206 usage();207 } else if (isoption(argv[i], 'V', "version")) {206 fprintf(stderr, "jq version %s\n", JQ_VERSION);208 fprintf(stderr, "jq version %s\n", PACKAGE_VERSION);209 return 0;210 } else {211 fprintf(stderr, "%s: Unknown option %s\n", progname, argv[i]);212 die();
88 unmodified lines
deleted:Makefile-142 removed
1CC=gcc2CFLAGS=-Wextra -Wall -Wno-missing-field-initializers -Wno-unused-parameter -std=gnu99 -ggdb -Wno-unused-function $(EXTRA_CFLAGS)34prefix=/usr/local5mandir=$(prefix)/share/man678.PHONY: all clean releasedep tarball install uninstall test releasetag9all: jq1011lexer.gen.c: lexer.l12 flex -o lexer.gen.c --header-file=lexer.gen.h lexer.l13lexer.gen.h: lexer.gen.c1415parser.gen.c: parser.y lexer.gen.h16 bison -W -d parser.y -v --report-file=parser.gen.info -o $@17parser.gen.h: parser.gen.c1819jv_utf8_tables.gen.h: gen_utf8_tables.py20 python $^ > $@21jv_unicode.c: jv_utf8_tables.gen.h2223version.gen.h: VERSION24 sed 's/.*/#define JQ_VERSION "&"/' $^ > $@25main.c: version.gen.h2627JQ_SRC=parser.gen.c lexer.gen.c opcode.c bytecode.c compile.c execute.c builtin.c jv.c jv_parse.c jv_print.c jv_dtoa.c jv_unicode.c jv_aux.c jv_alloc.c282930jq: $(JQ_SRC) main.c jq_test.c31 $(CC) $(CFLAGS) $(CFLAGS_OPT) -o $@ $^3233test: jq34 valgrind --error-exitcode=1 -q --leak-check=full ./jq --run-tests >/dev/null3536LIBRARIES=libjq37BINARIES=jq38PLATFORMS=linux32 linux64 osx32 osx64 win32 win643940build/linux32%: CC='x86_64-linux-gnu-gcc -m32'41build/linux64%: CC='x86_64-linux-gnu-gcc -m64'4243# OS X cross compilers can be gotten from44# https://launchpad.net/~flosoft/+archive/cross-apple45build/osx32%: CC='i686-apple-darwin10-gcc -m32'46build/osx64%: CC='i686-apple-darwin10-gcc -m64'4748# On Debian, you can get windows compilers in the49# gcc-mingw-w64-i686 and gcc-mingw-w64-x86-64 packages.50build/win32%: CC='i686-w64-mingw32-gcc -m32' EXTRA_CFLAGS=-DJQ_DEFAULT_ENABLE_COLOR=051build/win64%: CC='x86_64-w64-mingw32-gcc -m64' EXTRA_CFLAGS=-DJQ_DEFAULT_ENABLE_COLOR=05253BIN_SUFFIX_win32 = .exe54BIN_SUFFIX_win64 = .exe55LIB_SUFFIX_win32 = .dll56LIB_SUFFIX_win64 = .dll5758LIB_SUFFIX_linux32 = .so59LIB_SUFFIX_linux64 = .so6061LIB_SUFFIX_osx32 = .so62LIB_SUFFIX_osx64 = .so6364ALL_BINARIES=\65 $(foreach platform, $(PLATFORMS), \66 $(foreach binary, $(BINARIES), \67 build/$(platform)/$(binary)$(BIN_SUFFIX_$(platform))))6869$(ALL_BINARIES): build/%:70 mkdir -p $(@D)71 echo $(dir $*)72 make -B $(BINARIES) CC=$(CC)73 $(foreach binary, $(BINARIES), cp $(binary) $(@D)/$(binary)$(suffix $*);)7475libjq: CFLAGS += -fPIC76libjq: $(JQ_SRC)77 $(CC) -shared -Wl,-soname,libjq.so.1 $(CFLAGS) $(CFLAGS_OPT) -o $@ $^7879ALL_LIBRARIES=\80 $(foreach platform, $(PLATFORMS), \81 $(foreach library, $(LIBRARIES), \82 build/$(platform)/$(library)$(LIB_SUFFIX_$(platform))))8384$(ALL_LIBRARIES): build/%:85 mkdir -p $(@D)86 echo $(dir $*)87 make -B $(LIBRARIES) CC=$(CC)88 $(foreach library, $(LIBRARIES), cp $(library) $(@D)/$(library)$(suffix $*);)8990binaries: $(ALL_BINARIES)91libraries: $(ALL_LIBRARIES)9293clean:94 rm -rf build95 rm -f $(LIBRARIES) $(BINARIES) *.gen.*9697releasedep: lexer.gen.c parser.gen.c jv_utf8_tables.gen.h9899releasetag:100 git tag -s "jq-$$(cat VERSION)" -m "jq release $$(cat VERSION)"101102docs/content/2.download/source/jq.tgz: jq103 mkdir -p `dirname $@`104 tar -czvf $@ `git ls-files; ls *.gen.*`105106tarball: docs/content/2.download/source/jq.tgz107108jq.1: docs/content/3.manual/manual.yml109 ( cd docs; bundle exec rake manpage; ) > $@110111install: jq jq.1 libjq112 install -d -m 0755 $(prefix)/bin113 install -d -m 0755 $(prefix)/lib114 install -d -m 0755 $(prefix)/include115 install -d -m 0755 $(prefix)/include/jq116 install -m 0755 jq $(prefix)/bin117 ln libjq libjq.so.1118 install -m 0755 execute.h $(prefix)/include/jq119 install -m 0755 compile.h $(prefix)/include/jq120 install -m 0755 jv.h $(prefix)/include/jq121 install -m 0755 jv_parse.h $(prefix)/include/jq122 install -m 0755 jv_alloc.h $(prefix)/include/jq123 install -m 0755 libjq.so.1 $(prefix)/bin124 install -m 0644 execute.h $(prefix)/bin125 install -d -m 0755 $(mandir)/man1126 install -m 0644 jq.1 $(mandir)/man1127128uninstall:129 rm -vf $(prefix)/bin/jq130 rm -vf $(prefix)/lib/libjq.so.1131 rm -vf $(mandir)/man1/jq.1132133134www: docs/output www_binaries135136docs/output:137 cd docs; rake build138139www_binaries: docs/output binaries140 $(foreach platform, $(PLATFORMS), \141 mkdir -p docs/output/download/$(platform); \142 cp build/$(platform)/* docs/output/download/$(platform)/; )
added:Makefile.am+123 added
1### C source files to be built and distributed.23JQ_INCS = jq_parser.h builtin.h bytecode.h compile.h execute.h \4 forkable_stack.h frame_layout.h jv.h jv_alloc.h jv_aux.h jv_dtoa.h \5 jv_parse.h jv_unicode.h locfile.h opcode.h opcode_list.h parser.y \6 jv_utf8_tables.h lexer.l78JQ_SRC = opcode.c bytecode.c compile.c execute.c builtin.c jv.c \9 jv_parse.c jv_print.c jv_dtoa.c jv_unicode.c jv_aux.c jv_alloc.c \10 jq_test.c ${JQ_INCS}111213### C build options1415AM_CFLAGS = -Wextra -Wall -Wno-missing-field-initializers \16 -Wno-unused-parameter -Wno-unused-function171819### Generating the lexer and parser2021# While there is some autoconf macro support for lex/flex, it doesn't support22# header file creation so we'll use good old make23BUILT_SOURCES = lexer.h lexer.c parser.h parser.c24lexer.c: lexer.l25 flex -o lexer.c --header-file=lexer.h $<26lexer.h: lexer.c2728# Tell YACC (bison) autoconf macros that you want a header file created.29# If the --warnings=all fails, you probably have an old version of bison30# OSX ships an old bison, so update with homebrew or macports31AM_YFLAGS = --warnings=all -d323334### Building the jq binary3536main.c: config.h3738bin_PROGRAMS = jq39jq_SOURCES = ${JQ_SRC} main.c404142### Tests (make check)4344TESTS = tests/all.test45TEST_LOG_COMPILER = ${srcdir}/tests/run464748### Building the manpage4950# If ENABLE_DOCS is not set, just copy jq.1.default to jq.151# The real_docs target succeeds (possibly after building jq.1) only if ENABLE_DOCS is set52# Thus, making "dist" depend on "real_docs" ensures that we never build a tarball with53# a stub manpage.5455man_MANS = jq.156.PHONY: real_docs57if ENABLE_DOCS58jq.1: $(srcdir)/docs/content/3.manual/manual.yml59 ( cd ${abs_srcdir}/docs; '$(BUNDLER)' exec rake manpage ) > $@ || { rm -f $@; false; }60jq.1.default: $(srcdir)/docs/default_manpage.md61 ( cd ${abs_srcdir}/docs; '$(BUNDLER)' exec rake manpage_default ) > $@ || { rm -f $@; false; }62real_docs: jq.163 if cmp jq.1 $(srcdir)/jq.1.default > /dev/null; then\64 rm -f jq.1; $(MAKE) $(AM_MAKEFLAGS) jq.1;\65 fi66else67jq.1: $(srcdir)/jq.1.default68 cp $^ $@69real_docs:70 @echo "Ruby dependencies not found, cannot build manpage." > /dev/stderr71 @echo "Follow the instructions in docs/README.md to install them" > /dev/stderr72 @echo "and then rerun ./configure" > /dev/stderr73 false74endif757677### Packaging7879docs/site.yml: configure.ac80 sed 's/^jq_version: .*/jq_version: $(VERSION)/' $@ > $@.new81 mv $@.new $@8283install-binaries: $(BUILT_SOURCES)84 $(MAKE) $(AM_MAKEFLAGS) install-exec8586# Ensure "make dist" fails when we can't build the real manpage87dist-hook: real_docs8889DOC_FILES = docs/content docs/public docs/templates docs/site.yml \90 docs/Gemfile docs/Gemfile.lock docs/Rakefile docs/README.md \91 docs/default_manpage.md jq.1.default9293# setup is only used by distribution developers, not package developers.94# Still, as a matter of allowing patching, its not a bad idea to distribute 95# the developer setup script in the tarball.96EXTRA_DIST = config.h.in $(BUILT_SOURCES) $(man_MANS) $(TESTS) \97 $(TEST_LOG_COMPILER) gen_utf8_tables.py jq.spec \98 $(DOC_FILES)99100# README.md is expected in Github projects, good stuff in it, so we'll 101# distribute it and install it with the package in the doc directory.102docdir = ${datadir}/doc/${PACKAGE}103dist_doc_DATA = README.md COPYING AUTHORS README104105releasetag:106 git tag -s "jq-$$(cat VERSION)" -m "jq release $$(cat VERSION)"107108RELEASE ?= 1109rpm: jq110 @echo "Packaging jq as an RPM ..."111 mkdir -p rpm/SOURCES rpm/BUILD rpm/BUILDROOT rpm/RPMS rpm/SPECS112 cp jq-$$(cat VERSION).tar.gz rpm/SOURCES/113 rpmbuild -tb --define "_topdir ${PWD}/rpm" --define "_prefix /usr" --define "myver $$(cat VERSION)" --define "myrel ${RELEASE}" rpm/SOURCES/jq-$$(cat VERSION).tar.gz114 find rpm/RPMS/ -name "*.rpm" -exec mv {} ./ \;115 rm -rf rpm116117dist-clean-local:118 rm -f ${BUILT_SOURCES}119120# Not sure why this doesn't get cleaned up automatically, guess121# automake used to man pages which are hand coded?122clean-local:123 rm -f jq.1
deleted:parser.h-7 removed
1#ifndef PARSER_H2#define PARSER_H34int jq_parse(struct locfile* source, block* answer);5int jq_parse_library(struct locfile* locations, block* answer);67#endif
modified:parser.y+1 added-1 removed
90 unmodified lines
919293%type <blk> Exp Term MkDict MkDictPair ExpD ElseBody QQString FuncDef FuncDefs String94%{95#include "lexer.gen.h"95#include "lexer.h"96struct lexer_param {97 yyscan_t lexer;98};99#define FAIL(loc, msg) \
400 unmodified lines
added:README+1 added
1README.md
modified:README.md+12 added-3 removed
6 unmodified lines
7[http://stedolan.github.com/jq](http://stedolan.github.com/jq). This8documentation is generated from the docs/ folder of this repository.910If you want to hack on jq, feel free, but be warned that its internals11are not well-documented at the moment. Bring a hard hat and a shovel.11are not well-documented at the moment. Bring a hard hat and a12shovel. Also, read the wiki: http://github.com/stedolan/jq/wiki1313You can find some basic build instructions at14[http://stedolan.github.com/jq/download](http://stedolan.github.com/jq/download)14To build jq, run1516 ./configure17 make18 sudo make install (optionally)1920If you've just checked out the latest version from git (rather than21using a released source tarball) then you'll need to run this first:2223 autoreconf
added:setup.sh+32 added
1#!/usr/bin/env bash23# RUN ME after pulling the code from git!4#5# This script is handy after pulling the code out of git without having6# to remember all the typing needed to build up and tear down all the7# crap that autotools puts in your source repo. The intent is to keep8# all generated files out of git.910if [ "clean" == "$1" ]; then11 make distclean || echo "continuing..."12 rm -rf tmp autom4te.cache config13 rm -f INSTALL Makefile.in aclocal.m4 configure config.h.in ChangeLog14 rm -f jv_utf8_tables.gen.h lexer.c lexer.h parser.c parser.h15elif [ "superclean" == "$1" ]; then16 # if autoconf errors during distcheck, it leaves files that need chmod'ing17 ver=$(tr -d '\n' <VERSION)18 if [ "x${ver}" != "x" ]; then19 if [ -d jq-${ver} ]; then20 chmod -R u+w jq-${ver}21 rm -rf jq-${ver}22 fi23 rm -f jq-${ver}*24 fi25else26 autoreconf --install27 ./configure --prefix=/opt/junk28 make check29 mkdir tmp30 make DESTDIR=./tmp install31 make distcheck32fi
deleted:testdata-576 removed
1# Tests are groups of three lines: program, input, expected output2# Blank lines and lines starting with # are ignored34#5# Simple value tests to check parser. Input is irrelevant6#78true9null10true1112false13null14false1516null174218null1920121null221232425-126null27-12829# FIXME: much more number testing needed3031{}32null33{}3435[]36null37[]3839# The input line starts with a 0xFEFF (byte order mark) codepoint40# No, there is no reason to have a byte order mark in UTF8 text.41# But apparently people do, so jq shouldn't break on it.42.43"byte order mark"44"byte order mark"4546# We test escapes by matching them against Unicode codepoints47# FIXME: more tests needed for weird unicode stuff (e.g. utf16 pairs)48"Aa\r\n\t\b\f\u03bc"49null50"Aa\u000d\u000a\u0009\u0008\u000c\u03bc"5152.53"Aa\r\n\t\b\f\u03bc"54"Aa\u000d\u000a\u0009\u0008\u000c\u03bc"5556"inter\("pol" + "ation")"57null58"interpolation"5960@text,@json,([1,.] | @csv),@html,@uri,@sh,@base6461"<>&'\""62"<>&'\""63"\"<>&'\\\"\""64"1,\"<>&'\"\"\""65"&lt;&gt;&amp;&apos;&quot;"66"%3c%3e%26'%22"67"'<>&'\\''\"'"68"PD4mJyI="6970@uri71"\u03bc"72"%ce%bc"7374@html "<b>\(.)</b>"75"<script>hax</script>"76"<b>&lt;script&gt;hax&lt;/script&gt;</b>"7778#79# Dictionary construction syntax80#8182{a: 1}83null84{"a":1}8586{a,b,(.d):.a,e:.b}87{"a":1, "b":2, "c":3, "d":"c"}88{"a":1, "b":2, "c":1, "e":2}8990{"a",b,"a$\(1+1)"}91{"a":1, "b":2, "c":3, "a$2":4}92{"a":1, "b":2, "a$2":4}9394#95# Field access, piping96#9798.foo99{"foo": 42, "bar": 43}10042101102.foo | .bar103{"foo": {"bar": 42}, "bar": "badvalue"}10442105106.foo.bar107{"foo": {"bar": 42}, "bar": "badvalue"}10842109110.foo_bar111{"foo_bar": 2}1122113114.["foo"].bar115{"foo": {"bar": 42}, "bar": "badvalue"}11642117118119#120# Multiple outputs, iteration121#122123.[]124[1,2,3]1251126212731281291,1130[]131113211331341,.135[]1361137[]138139[.]140[2]141[[2]]142143[[2]]144[3]145[[2]]146147[{}]148[2]149[{}]150151[.[]]152["a"]153["a"]154155[(.,1),((.,.[]),(2,3))]156["a","b"]157[["a","b"],1,["a","b"],"a","b",2,3]158159[([5,5][]),.,.[]]160[1,2,3]161[5,5,[1,2,3],1,2,3]162163{x: (1,2)},{x:3} | .x164null165116621673168169#170# Variables171#1721731 as $x | 2 as $y | [$x,$y,$x]174null175[1,2,1]176177[1,2,3][] as $x | [[4,5,6,7][$x]]178null179[5]180[6]181[7]18218342 as $x | . | . | . + 432 | $x + 118434324185431861871 as $x | [$x,$x,$x as $x | $x]188null189[1,1,1]190191# [.,(.[] | {x:.},.),.,.[]]192193#194# Builtin functions195#1961971+1198null19922002011+1202"wtasdf"2032.02042052-1206null20712082092-(-1)210null21132122131e+0+0.001e3214"I wonder what this will be?"21520e-1216217.+42181521919.0220221.+null222{"a":42}223{"a":42}224225null+.226null227null228229.a+.b230{"a":42}23142232233[1,2,3] + [.]234null235[1,2,3,null]236237{"a":1} + {"b":2} + {"c":3}238"asdfasdf"239{"a":1, "b":2, "c":3}240241"asdf" + "jkl;" + . + . + .242"some string"243"asdfjkl;some stringsome stringsome string"244245"\u0000\u0020\u0000" + .246"\u0000\u0020\u0000"247"\u0000 \u0000\u0000 \u0000"24824942 - .2501125131252253[1,2,3,4,1] - [.,3]2541255[2,4]256257[10 * 20, 20 / .]2584259[200, 5]2602611 + 2 * 2 + 10 / 2262null26310264265[16 / 4 / 2, 16 / 4 * 2, 16 - 4 - 2, 16 - 4 + 2]266null267[2, 8, 10, 14]2682691 + tonumber + ("10" | tonumber)270427115272273[{"a":42},.object,10,.num,false,true,null,"b",[1,4]] | .[] as $x | [$x == .[]]274{"object": {"a":42}, "num":10.0}275[true, true, false, false, false, false, false, false, false]276[true, true, false, false, false, false, false, false, false]277[false, false, true, true, false, false, false, false, false]278[false, false, true, true, false, false, false, false, false]279[false, false, false, false, true, false, false, false, false]280[false, false, false, false, false, true, false, false, false]281[false, false, false, false, false, false, true, false, false]282[false, false, false, false, false, false, false, true, false]283[false, false, false, false, false, false, false, false, true ]284285[.[] | length]286[[], {}, [1,2], {"a":42}, "asdf"]287[0, 0, 2, 1, 4]288289map(keys)290[{}, {"abcd":1,"abc":2,"abcde":3}, {"x":1, "z": 3, "y":2}]291[[], ["abc","abcd","abcde"], ["x","y","z"]]292293[1,2,empty,3,empty,4]294null295[1,2,3,4]296297map(add)298[[], [1,2,3], ["a","b","c"], [[3],[4,5],[6]], [{"a":1}, {"b":2}, {"a":3}]]299[null, 6, "abc", [3,4,5,6], {"a":3, "b": 2}]300301#302# User-defined functions303# Oh god.304#305306def f: . + 1; def g: def g: . + 100; f | g | f; (f | g), g3073.0308106.0309105.0310311def f: (1000,2000); f31212341234531310003142000315316([1,2] + [4,5])317[1,2,3]318[1,2,4,5]319320true321[1]322true323324null,1,null325"hello"326null3271328null329330[1,2,3]331[5,6]332[1,2,3]333334def f(x): x | x; f([.], . + [42])335[1,2,3]336[[[1,2,3]]]337[[1,2,3],42]338[[1,2,3,42]]339[1,2,3,42,42]340341# test closures and lexical scoping342def id(x):x; 2000 as $x | def f(x):1 as $x | id([$x, x, x]); def g(x): 100 as $x | f($x,$x+x); g($x)343"more testing"344[1,100,2100.0,100,2100.0]345346# test backtracking through function calls and returns347# this test is *evil*348[[20,10][1,0] as $x | def f: (100,200) as $y | def g: [$x + $y, .]; . + $x | g; f[0] | [f][0][1] | f]349999999999350[[110.0, 130.0], [210.0, 130.0], [110.0, 230.0], [210.0, 230.0], [120.0, 160.0], [220.0, 160.0], [120.0, 260.0], [220.0, 260.0]]351352# test recursion353def fac: if . == 1 then 1 else . * (. - 1 | fac) end; [.[] | fac]354[1,2,3,4]355[1,2,6,24]356357# test stack overflow and reallocation358# this test is disabled for now, it takes a realllllly long time.359# def f: if length > 1000 then . else .+[1]|f end; f | length360# []361# 1001362363fold 0 as $s (.[] | $s + .)364[1,2,4]3657366367#368# Paths369#370371path(.foo[0,1])372null373["foo", 0]374["foo", 1]375376path(.[] | select(.>3))377[1,5,3]378[1]379380path(.)38142382[]383384["foo",1] as $p | getpath($p), setpath($p; 20), delpaths([$p])385{"bar": 42, "foo": ["a", "b", "c", "d"]}386"b"387{"bar": 42, "foo": ["a", 20, "c", "d"]}388{"bar": 42, "foo": ["a", "c", "d"]}389390map(getpath([2])), map(setpath([2]; 42)), map(delpaths([[2]]))391[[0], [0,1], [0,1,2]]392[null, null, 2]393[[0,null,42], [0,1,42], [0,1,42]]394[[0], [0,1], [0,1]]395396map(delpaths([[0,"foo"]]))397[[{"foo":2, "x":1}], [{"bar":2}]]398[[{"x":1}], [{"bar":2}]]399400["foo",1] as $p | getpath($p), setpath($p; 20), delpaths([$p])401{"bar":false}402null403{"bar":false, "foo": [null, 20]}404{"bar":false}405406delpaths([[-200]])407[1,2,3]408[1,2,3]409410del(.), del(empty), del((.foo,.bar,.baz) | .[2,3,0]), del(.foo[0], .bar[0], .foo, .baz.bar[0].x)411{"foo": [0,1,2,3,4], "bar": [0,1]}412null413{"foo": [0,1,2,3,4], "bar": [0,1]}414{"foo": [1,4], "bar": [1]}415{"bar": [1]}416417#418# Assignment419#420.message = "goodbye"421{"message": "hello"}422{"message": "goodbye"}423424.foo = .bar425{"bar":42}426{"foo":42, "bar":42}427428.foo |= .+1429{"foo": 42}430{"foo": 43}431432.[] += 2, .[] *= 2, .[] -= 2, .[] /= 2433[1,3,5]434[3,5,7]435[2,6,10]436[-1,1,3]437[0.5, 1.5, 2.5]438439.foo += .foo440{"foo":2}441{"foo":4}442443.[0].a |= {"old":., "new":(.+1)}444[{"a":1,"b":2}]445[{"a":{"old":1, "new":2},"b":2}]446447def inc(x): x |= .+1; inc(.[].a)448[{"a":1,"b":2},{"a":2,"b":4},{"a":7,"b":8}]449[{"a":2,"b":2},{"a":3,"b":4},{"a":8,"b":8}]450451.[2][3] = 1452[4]453[4, null, [null, null, null, 1]]454455.foo[2].bar = 1456{"foo":[11], "bar":42}457{"foo":[11,null,{"bar":1}], "bar":42}458459#460# Conditionals461#462463[.[] | if .foo then "yep" else "nope" end]464[{"foo":0},{"foo":1},{"foo":[]},{"foo":true},{"foo":false},{"foo":null},{"foo":"foo"},{}]465["yep","yep","yep","yep","nope","nope","yep","nope"]466467[.[] | if .baz then "strange" elif .foo then "yep" else "nope" end]468[{"foo":0},{"foo":1},{"foo":[]},{"foo":true},{"foo":false},{"foo":null},{"foo":"foo"},{}]469["yep","yep","yep","yep","nope","nope","yep","nope"]470471472# FIXME: define/test behaviour of 'if (.foo,.bar) then A else B end'473474[.[] | [.foo[] // .bar]]475[{"foo":[1,2], "bar": 42}, {"foo":[1], "bar": null}, {"foo":[null,false,3], "bar": 18}, {"foo":[], "bar":42}, {"foo": [null,false,null], "bar": 41}]476[[1,2], [1], [3], [42], [41]]477478# FIXME: behaviour of update operators479# .[] //= .[0]480# ["hello",true,false,[false],null]481# ["hello",true,"hello",[false],"hello"]482483.[] | [.[0] and .[1], .[0] or .[1]]484[[true,[]], [false,1], [42,null], [null,false]]485[true,true]486[false,true]487[false,true]488[false,false]489490[.[] | not]491[1,0,false,null,true,"hello"]492[false,false,true,true,false,false]493494# Check numeric comparison binops495[10 > 0, 10 > 10, 10 > 20, 10 < 0, 10 < 10, 10 < 20]496{}497[true,false,false,false,false,true]498499[10 >= 0, 10 >= 10, 10 >= 20, 10 <= 0, 10 <= 10, 10 <= 20]500{}501[true,true,false,false,true,true]502503# And some in/equality tests504[ 10 == 10, 10 != 10, 10 != 11, 10 == 11]505{}506[true,false,true,false]507508["hello" == "hello", "hello" != "hello", "hello" == "world", "hello" != "world" ]509{}510[true,false,false,true]511512[[1,2,3] == [1,2,3], [1,2,3] != [1,2,3], [1,2,3] == [4,5,6], [1,2,3] != [4,5,6]]513{}514[true,false,false,true]515516[{"foo":42} == {"foo":42},{"foo":42} != {"foo":42}, {"foo":42} != {"bar":42}, {"foo":42} == {"bar":42}]517{}518[true,false,true,false]519520# ugly complicated thing521[{"foo":[1,2,{"bar":18},"world"]} == {"foo":[1,2,{"bar":18},"world"]},{"foo":[1,2,{"bar":18},"world"]} == {"foo":[1,2,{"bar":19},"world"]}]522{}523[true,false]524525# containment operator526[("foo" | contains("foo")), ("foobar" | contains("foo")), ("foo" | contains("foobar"))]527{}528[true, true, false]529530map(.[1] as $needle | .[0] | contains($needle))531[[[],[]], [[1,2,3], [1,2]], [[1,2,3], [3,1]], [[1,2,3], [4]], [[1,2,3], [1,4]]]532[true, true, true, false, false]533534map(.[1] as $needle | .[0] | contains($needle))535[[["foobar", "foobaz"], ["baz", "bar"]], [["foobar", "foobaz"], ["foo"]], [["foobar", "foobaz"], ["blap"]]]536[true, true, false]537538[({foo: 12, bar:13} | contains({foo: 12})), ({foo: 12} | contains({})), ({foo: 12, bar:13} | contains({baz:14}))]539{}540[true, true, false]541542{foo: {baz: 12, blap: {bar: 13}}, bar: 14} | contains({bar: 14, foo: {blap: {}}})543{}544true545546{foo: {baz: 12, blap: {bar: 13}}, bar: 14} | contains({bar: 14, foo: {blap: {bar: 14}}})547{}548false549550sort551[42,[2,5,3,11],10,{"a":42,"b":2},{"a":42},true,2,[2,6],"hello",null,[2,5,6],{"a":[],"b":1},"abc","ab",[3,10],{},false,"abcd",null]552[null,null,false,true,2,10,42,"ab","abc","abcd","hello",[2,5,3,11],[2,5,6],[2,6],[3,10],{},{"a":42},{"a":42,"b":2},{"a":[],"b":1}]553554(sort_by(.b) | sort_by(.a)), sort_by(.a, .b), sort_by(.b, .c), group_by(.b), group_by(.a + .b - .c == 2)555[{"a": 1, "b": 4, "c": 14}, {"a": 4, "b": 1, "c": 3}, {"a": 1, "b": 4, "c": 3}, {"a": 0, "b": 2, "c": 43}]556[{"a": 0, "b": 2, "c": 43}, {"a": 1, "b": 4, "c": 14}, {"a": 1, "b": 4, "c": 3}, {"a": 4, "b": 1, "c": 3}]557[{"a": 0, "b": 2, "c": 43}, {"a": 1, "b": 4, "c": 14}, {"a": 1, "b": 4, "c": 3}, {"a": 4, "b": 1, "c": 3}]558[{"a": 4, "b": 1, "c": 3}, {"a": 0, "b": 2, "c": 43}, {"a": 1, "b": 4, "c": 3}, {"a": 1, "b": 4, "c": 14}]559[[{"a": 4, "b": 1, "c": 3}], [{"a": 0, "b": 2, "c": 43}], [{"a": 1, "b": 4, "c": 14}, {"a": 1, "b": 4, "c": 3}]]560[[{"a": 1, "b": 4, "c": 14}, {"a": 0, "b": 2, "c": 43}], [{"a": 4, "b": 1, "c": 3}, {"a": 1, "b": 4, "c": 3}]]561562unique563[1,2,5,3,5,3,1,3]564[1,2,3,5]565566[min, max, min_by(.[1]), max_by(.[1]), min_by(.[2]), max_by(.[2])]567[[4,2,"a"],[3,1,"a"],[2,4,"a"],[1,3,"a"]]568[[1,3,"a"],[4,2,"a"],[3,1,"a"],[2,4,"a"],[4,2,"a"],[1,3,"a"]]569570[min,max,min_by(.),max_by(.)]571[]572[null,null,null,null]573574.foo[.baz]575{"foo":{"bar":4},"baz":"bar"}5764
deleted:VERSION-1 removed
11.2