source: wspkg/wspkg-sh/packages-cpp.sh @ f6d5ca1

Last change on this file since f6d5ca1 was f6d5ca1, checked in by Ting-Wei Lan <lantw44@…>, 3 years ago

Use 'printf' to print non-constant strings in shell scripts

It is unsafe to use 'echo' with strings with variable substitutions.
Different 'echo' implementations may accept different options, and they
can interpret strings with escape characters in different ways. The
behavior of 'printf' is much more consistent so it should be preferred.

  • Property mode set to 100755
File size: 574 bytes
Line 
1#!/bin/sh
2
3toupper () {
4    printf '%s\n' "$1" | sed 's/^-//' | tr '[:lower:]' '[:upper:]'
5}
6
7[ -z "$1" ] && printf 'Usage: %s input_file cpp_args\n' "$0" && exit 1
8[ -z "$2" ] && default="yes"
9
10input_file="$1"
11shift
12
13: ${CPP:="cpp"}
14: ${CPPFLAGS:="-I."}
15while [ "$1" ]; do
16    case "$1" in
17        -*)
18            selarg="$selarg -D`toupper "$1"`"
19            ;;
20        *)
21            selarg="$selarg -DWSPKG_`toupper "$1"`"
22            ;;
23    esac
24    shift
25done
26
27${CPP} ${CPPFLAGS} $selarg "$input_file" | \
28    sed -e '/^#/d' -e '/^ *$/d' | tr ' ' '\n' | sed '/^ *$/d'
Note: See TracBrowser for help on using the repository browser.