dkegel@google.com | f20da1f | 2009-06-30 19:16:32 +0000 | [diff] [blame^] | 1 | #!/usr/bin/awk -f |
| 2 | #--------------------------------------------- |
| 3 | # |
| 4 | # generate-script.awk |
| 5 | # |
| 6 | # Simple AWK script to generate the XDG scripts, substituting the |
| 7 | # necessary text from other source files. |
| 8 | # |
| 9 | # Copyright 2006, Benedikt Meurer <benny@xfce.org> |
| 10 | # |
| 11 | # LICENSE: |
| 12 | # |
| 13 | # Permission is hereby granted, free of charge, to any person obtaining a |
| 14 | # copy of this software and associated documentation files (the "Software"), |
| 15 | # to deal in the Software without restriction, including without limitation |
| 16 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 17 | # and/or sell copies of the Software, and to permit persons to whom the |
| 18 | # Software is furnished to do so, subject to the following conditions: |
| 19 | # |
| 20 | # The above copyright notice and this permission notice shall be included |
| 21 | # in all copies or substantial portions of the Software. |
| 22 | # |
| 23 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 24 | # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 25 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 26 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 27 | # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 28 | # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 29 | # OTHER DEALINGS IN THE SOFTWARE. |
| 30 | # |
| 31 | #--------------------------------------------- |
| 32 | |
| 33 | |
| 34 | # All lines from the input file should be printed |
| 35 | { |
| 36 | print |
| 37 | } |
| 38 | |
| 39 | |
| 40 | # The text from ../LICENSE should be inserted after |
| 41 | # the "# LICENSE:" line |
| 42 | /^# LICENSE:/ { |
| 43 | while (getline < "../LICENSE") |
| 44 | print |
| 45 | close ("../LICENSE") |
| 46 | } |
| 47 | |
| 48 | |
| 49 | # Insert the examples text from the .txt file |
| 50 | # after the "cat << _MANUALPAGE" line |
| 51 | /^cat << _MANUALPAGE/ { |
| 52 | # determine the name of the .txt file |
| 53 | txtfile = FILENAME |
| 54 | sub(/\.in$/, ".txt", txtfile) |
| 55 | |
| 56 | # read the .txt file content |
| 57 | for (txtfile_print = 0; getline < txtfile; ) { |
| 58 | # if (match ($0, /^Examples/) != 0) { |
| 59 | # # print everything starting at the "Examples" line |
| 60 | # txtfile_print = 1 |
| 61 | # } |
| 62 | # if (txtfile_print != 0) { |
| 63 | # print $0 |
| 64 | # } |
| 65 | gsub("`","'") |
| 66 | gsub("—","-") |
| 67 | print $0 |
| 68 | } |
| 69 | close (txtfile) |
| 70 | } |
| 71 | |
| 72 | |
| 73 | # Insert the usage text from the .txt file |
| 74 | # after the "cat << _USAGE" line |
| 75 | /^cat << _USAGE/ { |
| 76 | # determine the name of the .txt file |
| 77 | txtfile = FILENAME |
| 78 | sub(/\.in$/, ".txt", txtfile) |
| 79 | |
| 80 | # read the .txt file content |
| 81 | for (txtfile_print = 0; getline < txtfile; ) { |
| 82 | if (match ($0, /^Name/) != 0) { |
| 83 | # skip empty line after "Name" |
| 84 | getline < txtfile |
| 85 | |
| 86 | # from now on, print everything |
| 87 | txtfile_print = 1 |
| 88 | } |
| 89 | else if (match ($0, /^Description/) != 0) { |
| 90 | # stop at "Description" |
| 91 | break |
| 92 | } |
| 93 | else if (txtfile_print != 0) { |
| 94 | gsub("—","-") |
| 95 | print $0 |
| 96 | } |
| 97 | } |
| 98 | close (txtfile) |
| 99 | } |
| 100 | |
| 101 | |
| 102 | # Insert the xdg-utils-common.in content after |
| 103 | # the "#@xdg-utils-common@" line |
| 104 | /^#@xdg-utils-common@/ { |
| 105 | while (getline < "xdg-utils-common.in") |
| 106 | print |
| 107 | close ("xdg-utils-common.in") |
| 108 | } |
| 109 | |
| 110 | |