#!/bin/sh VERSIONINFO="version 1.3, 7 june 1999, scott arrington" # 27 July 1998 # this places quotes (with a trailing newline in the quotes) around # each line of a file, making it suitable for use as a constant string # in C or C++. # # the output of this script goes to stdout # # 19 Nov 1998 # improved the thing to use a case statement that looks for # some standard arguments. also allows you to specify # "-e", which makes the program escape any embedded quote # characters in the source file. # # 7 June 1999 # better use of sed. nothing major... TACK_LEADING_QUOTE_CMD="/^/s/^/\"/" TACK_TRAILING_QUOTE_CMD="/\$/s//\\\\n\"/" ESC_EMBEDDED_QUOTES_CMD="/\"/s//\\\\\"/g" case "$1" in "") echo usage: $0 [-e] filename echo " try $0 --help for help" ;; -h|--help) echo usage: $0 [-e] filename echo " wrap a file in quotes and copy to stdout." echo " the idea is to produce a string suitable for inclusion in a C source file." echo " -e pre-process the input to escape embedded quotes." echo " the program also understands -h, --help, -V and --version." exit;; -V|--version) echo $VERSIONINFO exit;; -e) # pre-process for embedded quotes case "$2" in "") echo usage: $0 [-e] filename echo " try $0 --help for help" exit ;; *) ;; esac cat $2 | sed -e $ESC_EMBEDDED_QUOTES_CMD \ -e $TACK_TRAILING_QUOTE_CMD \ -e $TACK_LEADING_QUOTE_CMD ;; *) # default cat $1 | sed -e $TACK_TRAILING_QUOTE_CMD \ -e $TACK_LEADING_QUOTE_CMD ;; esac