This file is indexed.

/usr/bin/alt_getopt is in runawk 1.5.1-1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env runawk

# Copyright (c) 2010 Aleksey Cheusov <vle@gmx.net>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

#use "alt_assert.awk"
#use "alt_getopt.awk"
#use "shquote.awk"
#use "embed_str.awk"

#env "LC_ALL=C"

#.begin-str help
# alt_getopt is a command options parser, it gets options
# specification and application's options as arguments and outputs
# shell commands to be executed.
# Usage:
#   alt_getopt -h
#   alt_getopt [OPTIONS] opt1 sh_cmd1 [opt2 sh_cmd2...] -- [args]
# OPTIONS:
#    -h|--help        display this screen
#    -c               do not output 'shift' command, variable
#                     __shifts_cnt is assigned instead
#.end-str

function __takes_arg (opt){
	if (!opt in __getopt_opts)
		return 0
	if (__getopt_opts [opt] == takes_arg)
		return 1
	if (__getopt_opts [opt] == "")
		return 0
	return __getopt_opts [__getopt_opts [opt]] == takes_arg
}

BEGIN {
	start = 1
	if (ARGV [1] == "-h" || ARGV [1] == "--help"){
		print EMBED_STR ["help"] > "/dev/stderr"
		exitnow(0)
	}
	if (ARGV [1] == "-c"){
		delete ARGV [1]
		++start
		output_shift_cnt = 1
	}

	for (i=start; i < ARGC; i += 2){
		if (ARGV [i] == "--"){
			delete ARGV [i]
			++i
			break
		}

		if (ARGV [i] == "" || ARGV [i+1] == ""){
			print "bad arguments, see alt_getopt -h for more information" \
				> "/dev/stderr"
		}

		if (ARGV [i] ~ /^[A-Za-z0-9!@%^=+\/,.]$/){
			shopts = shopts ARGV [i]
			action [ARGV [i]] = ARGV [i+1]
		}else if (ARGV [i] ~ /^=[A-Za-z0-9!@%^=+\/,.]$/){
			opt = substr(ARGV [i], 2)
			shopts = shopts opt ":"
			action [opt] = ARGV [i+1]
		}else if (ARGV [i] ~ /^[A-Za-z0-9!@%^=+\/,.][ |][^ |]+$/){
			split(ARGV [i], arr, /[ |]/)
			shopts = shopts arr [1]
			long_opts [arr [2]] = arr [1]
			action [arr [1]] = ARGV [i+1]
		}else if (ARGV [i] ~ /^=[A-Za-z0-9!@%^=+\/,.][ |][^ |]+$/){
			split(substr(ARGV [i], 2), arr, /[ |]/)
			shopts = shopts arr [1] ":"
			long_opts [arr [2]] = arr [1]
			action [arr [1]] = ARGV [i+1]
		}else if (ARGV [i] ~ /^[^=][^ |]*$/){
			long_opts [ARGV [i]] = ""
			action [ARGV [i]] = ARGV [i+1]
		}else if (ARGV [i] ~ /^=[^ |]+$/){
			opt = substr(ARGV [i], 2)
			long_opts [opt] = takes_arg
			action [opt] = ARGV [i+1]
		}else{
			abort("unknown format of'" ARGV [i] "'")
		}

		delete ARGV [i]
		delete ARGV [i+1]
	}

	first = i

	while (getopt(shopts, 1)){
		if (__takes_arg(optopt))
			print action [optopt] shquote(optarg)
		else
			print action [optopt]
	}

	shifts_cnt = 0
	for (i=first; i < ARGC; ++i){
		if (ARGV [i] == "")
			++shifts_cnt
	}
	if (output_shift_cnt)
		print "shifts=" shifts_cnt
	else
		print "shift", shifts_cnt

	exitnow(0)
}