This file is indexed.

/usr/bin/sdfapi is in sdf 2.001+1-5.

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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/usr/bin/perl
# $Id$
$VERSION{'PUBLIC'} = '2.000';
$VERSION{''.__FILE__} = '$Revision$';
#
# >>Title::     API Extraction Utility
#
# >>Copyright::
# Copyright (c) 1992-1996, Ian Clatworthy (ianc@mincom.com).
# You may distribute under the terms specified in the LICENSE file.
#
# >>History::
# -----------------------------------------------------------------------
# Date      Who     Change
# 29-Feb-96 ianc    SDF 2.000
# -----------------------------------------------------------------------
#
# >>Purpose::
# {{CMD:sdfapi}} extracts {{Application Programming Interface}} information
# from ([[Perl]]) source code.
#
# >>Description::
# !SDF_OPT_STD
#
# The format of the output can be controlled using the -f option.
# Supported formats are {{std}} and {{concise}}. The default is {{std}}.
# {{std}} format is:
#
# E:require "abc.pl";
# E:
# E:$myvar = ...
# E:
# E:$result =
# E:&myfunc($myparams);
#
# {{concise}} format has fewer blank lines and uses 1 line per symbol.
#
# A comma-separated list of symbol types to output can be specified
# using the -s option. Supported symbol types are:
#
# * {{sub}} - subroutines
# * {{var}} - variables
#
# The default is to extract all symbols.
#
# The -p option is used to extract only a subset of the symbols.
# If not supplied, the pattern is symbols beginning with a letter.
# If supplied without an option, the pattern defaults to all symbols.
# If perl libraries use the coding convention that symbols beginning
# with underscore are private, then -p_ can be used to extract the
# private symbols.
#
# The -j option can be used to request SDF-style hypertext jumps
# be added for each symbol. The jump target is {{lib_sym}} where:
#
# * {{lib}} is the library name
# * {{sym}} is the symbol name.
#
# >>Limitations::
# The only language currently supported is [[Perl]].
#
# It would be useful to extract messages from the scripts too.
# This would require a new utility called {{sdfmsg}} say,
# which searched through the source (including libraries) for
# {{Y:AppMsg}} and {{Y:AppExit}} calls.
#
# Internally, it may be better to implement formats via routines.
# This would give better control over output. e.g. it would be up to
# the routine to decide if it wanted to output the 'require' header.
#
# >>Resources::
#
# >>Implementation::
#

require "sdf/app.pl";
require "sdf/apiperl.pl";

########## Initialisation ##########

# Table of formatting tags
# (update %PERLIF_RULE if you change this)
@PERLIF_FMT = ('std', 'concise');

# Tables of formatting rules. Each format needs 3 rules:
#
# * var - variable format
# * proc - routine with no result (i.e. procedure)
# * func - routine with result (i.e. function).
#
%PERLIF_RULE = (
    "std.var",      '"${prefix}$name = ...\n\n"',
    "std.proc",     '"${prefix}$name($params);\n\n"',
    "std.func",     '"$result =\n${prefix}$name($params);\n\n"',
    "concise.var",  '"${prefix}$name = ...\n"',
    "concise.proc", '"${prefix}$name($params);\n"',
    "concise.func", '"$result = ${prefix}$name($params);\n"',
);

# define configuration
%app_config = (
    'libdir',   'sdf/home',
);

# define options
push(@app_option, (
    #'Name|Spec|Help',
    'fmt_tag|STR-@PERLIF_FMT;std|output format tag',
    'pattern|STR;^[A-Za-z];|only symbols matching pattern',
    'sym_type|STRLIST-("sub","var")|only symbols of these types',
    'jumps|BOOL|add SDF-style hypertext jumps from each symbol',
));

# handle options
&AppInit('file ...', 'extract the API from a (perl) library', 'SDF') ||
  &AppExit();

########## Processing ##########

sub argProcess {
    local($perl_file) = @_;
#   local();

    # Fetch File
    ($ok_perl, @perl) = &PerlFetch($perl_file);
    unless ($ok_perl) {
        &AppMsg('abort', "error fetching perl file '$perl_file'");
        return;
    }

    # Get perl symbols
    @symbol = &PerlSymbols(*perl, $pattern, @sym_type);

    # Find longest strings (optionally used in routine formatting)
    $max_name = 0;
    $max_result = 0;
    $max_params = 0;
    for $symbol (@symbol) {
        ($sym_type, $name, $result, $params) = split(/:/, $symbol);
        next unless $sym_type eq 'sub';
        $len = length($name);
        $max_name = $len if $len > $max_name;
        $len = length($result);
        $max_result = $len if $len > $max_result;
        $len = length($params);
        $max_params = $len if $len > $max_params;
    }

    # Output the header unless a subset requested
    if (scalar(@sym_type) == 0) {
        ($dir, $base, $ext) = &NameSplit($perl_file);
        printf "require \"%s\";\n\n", &NameJoin('', $base, $ext);
    }

    # Output symbols
    for $symbol (@symbol) {
        ($sym_type, $name, $result, $params) = split(/:/, $symbol);
        if ($sym_type eq 'sub') {
            $sym_type = $result ? 'func' : 'proc';
            $prefix = '&';
        }
        else {
            $name =~ s/^(.)//;
            $prefix = $1;
        }
        $action = $PERLIF_RULE{"$fmt_tag.$sym_type"};
        if ($jumps) {
            $action =~ s/\$name/{{N[jump='#\${base}_\$name']\$name}}/;
        }
        print eval $action;
    }
}

&AppProcess('argProcess');
&AppExit();