"Fossies" - the Fresh Open Source Software Archive

Member "tnftp-20200705/libedit/makelist" (4 Jul 2020, 4620 Bytes) of package /linux/privat/tnftp-20200705.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/bin/sh -
    2 #   $NetBSD: makelist,v 1.5 2020/07/04 13:43:21 lukem Exp $
    3 #    NetBSD: makelist,v 1.29 2016/05/09 21:46:56 christos Exp  
    4 #
    5 # Copyright (c) 1992, 1993
    6 #   The Regents of the University of California.  All rights reserved.
    7 #
    8 # This code is derived from software contributed to Berkeley by
    9 # Christos Zoulas of Cornell University.
   10 #
   11 # Redistribution and use in source and binary forms, with or without
   12 # modification, are permitted provided that the following conditions
   13 # are met:
   14 # 1. Redistributions of source code must retain the above copyright
   15 #    notice, this list of conditions and the following disclaimer.
   16 # 2. Redistributions in binary form must reproduce the above copyright
   17 #    notice, this list of conditions and the following disclaimer in the
   18 #    documentation and/or other materials provided with the distribution.
   19 # 3. Neither the name of the University nor the names of its contributors
   20 #    may be used to endorse or promote products derived from this software
   21 #    without specific prior written permission.
   22 #
   23 # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   24 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   25 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   26 # ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   27 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   28 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   29 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   30 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   31 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   32 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   33 # SUCH DAMAGE.
   34 #
   35 #   @(#)makelist    5.3 (Berkeley) 6/4/93
   36 
   37 # makelist.sh: Automatically generate header files...
   38 
   39 : ${AWK:=awk}
   40 USAGE="Usage: $0 -h|-fc|-fh|-bh <filenames>"
   41 
   42 if [ "x$1" = "x" ]
   43 then
   44     echo $USAGE 1>&2
   45     exit 1
   46 fi
   47 
   48 FLAG="$1"
   49 shift
   50 
   51 FILES="$@"
   52 
   53 case $FLAG in
   54 
   55 -h)
   56     set - `echo $FILES | sed -e 's/\\./_/g'`
   57     hdr="_h_`basename $1`"
   58     cat $FILES | $AWK '
   59     BEGIN {
   60         printf("/* Automatically generated file, do not edit */\n");
   61         printf("#ifndef %s\n#define %s\n", "'$hdr'", "'$hdr'");
   62     }
   63     /\(\):/ {
   64         pr = substr($2, 1, 2);
   65         if (pr == "vi" || pr == "em" || pr == "ed") {
   66         name = substr($2, 1, length($2) - 3);
   67 #
   68 # XXX:  need a space between name and prototype so that -fc and -fh
   69 #   parsing is much easier
   70 #
   71         printf("libedit_private el_action_t\t%s (EditLine *, wint_t);\n",
   72             name);
   73         }
   74     }
   75     END {
   76         printf("#endif /* %s */\n", "'$hdr'");
   77     }'
   78     ;;
   79 
   80 #   generate help.h from various .c files
   81 #
   82 -bh)
   83     cat $FILES | $AWK '
   84     BEGIN {
   85         printf("/* Automatically generated file, do not edit */\n");
   86         printf("static const struct el_bindings_t el_func_help[] = {\n");
   87         low = "abcdefghijklmnopqrstuvwxyz_";
   88         high = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_";
   89         for (i = 1; i <= length(low); i++)
   90         tr[substr(low, i, 1)] = substr(high, i, 1);
   91     }
   92     /\(\):/ {
   93         pr = substr($2, 1, 2);
   94         if (pr == "vi" || pr == "em" || pr == "ed") {
   95         name = substr($2, 1, length($2) - 3);
   96         uname = "";
   97         fname = "";
   98         for (i = 1; i <= length(name); i++) {
   99             s = substr(name, i, 1);
  100             uname = uname tr[s];
  101             if (s == "_")
  102             s = "-";
  103             fname = fname s;
  104         }
  105 
  106         printf("    { %-30.30s %-30.30s\n","L\"" fname "\",", uname ",");
  107         ok = 1;
  108         }
  109     }
  110     /^ \*/ {
  111         if (ok) {
  112         printf("      L\"");
  113         for (i = 2; i < NF; i++)
  114             printf("%s ", $i);
  115         printf("%s\" },\n", $i);
  116         ok = 0;
  117         }
  118     }
  119     END {
  120         printf("};\n");
  121     }'
  122     ;;
  123 
  124 #   generate fcns.h from various .h files
  125 #
  126 -fh)
  127     cat $FILES | $AWK '/el_action_t/ { print $3 }' | \
  128     sort | tr '[:lower:]' '[:upper:]' | $AWK '
  129     BEGIN {
  130         printf("/* Automatically generated file, do not edit */\n");
  131         count = 0;
  132     }
  133     {
  134         printf("#define\t%-30.30s\t%3d\n", $1, count++);
  135     }
  136     END {
  137         printf("#define\t%-30.30s\t%3d\n", "EL_NUM_FCNS", count);
  138     }'
  139     ;;
  140 
  141 #   generate func.h from various .h files
  142 #
  143 -fc)
  144     cat $FILES | $AWK '/el_action_t/ { print $3 }' | sort | $AWK '
  145     BEGIN {
  146         printf("/* Automatically generated file, do not edit */\n");
  147         printf("static const el_func_t el_func[] = {");
  148         maxlen = 80;
  149         needn = 1;
  150         len = 0;
  151     }
  152     {
  153         clen = 25 + 2;
  154         len += clen;
  155         if (len >= maxlen)
  156         needn = 1;
  157         if (needn) {
  158         printf("\n    ");
  159         needn = 0;
  160         len = 4 + clen;
  161         }
  162         s = $1 ",";
  163         printf("%-26.26s ", s);
  164     }
  165     END {
  166         printf("\n};\n");
  167     }'
  168     ;;
  169 
  170 *)
  171     echo $USAGE 1>&2
  172     exit 1
  173     ;;
  174 
  175 esac