File: file_to_cstr.sh

package info (click to toggle)
lammps 20220106.git7586adbb6a%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 348,064 kB
  • sloc: cpp: 831,421; python: 24,896; xml: 14,949; f90: 10,845; ansic: 7,967; sh: 4,226; perl: 4,064; fortran: 2,424; makefile: 1,501; objc: 238; lisp: 163; csh: 16; awk: 14; tcl: 6
file content (54 lines) | stat: -rwxr-xr-x 1,127 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/sh

# convert ptx assembly output into
# a c-style string constant written
# in portable posix shell script.
# requires: sed, rm, mv
#
# Author: Axel Kohlmeyer, Temple University

num_args=$#

# Check command-line arguments
if [ $num_args -gt 9 ]; then
  echo "$0 can only take 9 arguments; not $num_args"
  exit 1
fi

if [ $num_args -lt 3 ]; then
  echo "Not enough arguments."
  echo "$0 name_for_string input_file1 input_file2 ... output"
  exit 1
fi

# Name is first arg, output file is last argument
string_name=$1
eval output=\${$num_args}
shift

# remove temporary file in case we're interrupted.
cleanup () {
  rm -f $output
}
trap cleanup INT QUIT TERM

# loop over arguments and convert to
# string constant.
i=2
echo "const char * $string_name = " > $output
while [ $i -lt $num_args ]
do \
  src=$1
  krn=${src##*/}
  krn=${krn%.*}
  echo "Converting $src to a c-style string"
  sed -e 's/\\/\\\\/g'   \
      -e 's/"/\\"/g'     \
      -e 's/ *\/\/.*$//' \
      -e '/\.file/D'     \
      -e '/^[ 	]*$/D'   \
      -e 's/^\(.*\)$/"\1\\n"/' $src >> $output
  shift
  i=`expr $i + 1`
done
echo ';' >> $output