]> ncurses.scripts.mit.edu Git - ncurses.git/blob - Ada95/samples/split-path.awk
ncurses 6.2 - patch 20200212
[ncurses.git] / Ada95 / samples / split-path.awk
1 ##############################################################################
2 # Copyright 2020 Thomas E. Dickey                                            #
3 #                                                                            #
4 # Permission is hereby granted, free of charge, to any person obtaining a    #
5 # copy of this software and associated documentation files (the "Software"), #
6 # to deal in the Software without restriction, including without limitation  #
7 # the rights to use, copy, modify, merge, publish, distribute, distribute    #
8 # with modifications, sublicense, and/or sell copies of the Software, and to #
9 # permit persons to whom the Software is furnished to do so, subject to the  #
10 # following conditions:                                                      #
11 #                                                                            #
12 # The above copyright notice and this permission notice shall be included in #
13 # all copies or substantial portions of the Software.                        #
14 #                                                                            #
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
16 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   #
17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    #
18 # THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER      #
19 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING    #
20 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER        #
21 # DEALINGS IN THE SOFTWARE.                                                  #
22 #                                                                            #
23 # Except as contained in this notice, the name(s) of the above copyright     #
24 # holders shall not be used in advertising or otherwise to promote the sale, #
25 # use or other dealings in this Software without prior written               #
26 # authorization.                                                             #
27 ##############################################################################
28 #
29 #  Author:  Thomas E. Dickey
30 #
31 #  $Id: split-path.awk,v 1.3 2020/02/02 23:34:34 tom Exp $
32 BEGIN   { cols = 72; }
33 /[$]THIS_DATADIR/ {
34         gsub("[$]THIS_DATADIR", "\"" this_datadir "\"");
35         if ( length ($0) > cols ) {
36                 indent = index($0, "\"") - 1;
37                 broken = index($0, "&");
38                 if (broken > 0 && broken < indent)
39                         indent = broken - 1;
40                 leader = sprintf ("%*s& ", indent, " ");
41                 buffer = $0;
42                 first  = 1;
43                 while ( length(buffer) > cols ) {
44                         printf("%.*s\"\n", cols, buffer);
45                         buffer = leader "\"" substr(buffer, cols + 1);
46                 }
47                 if ( buffer != "" && buffer != leader "\"\"" )
48                         printf("%.*s\n", cols, buffer);
49                 next;
50         }
51 }
52 {
53         print;
54 }