Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F87265122
file_to_cstr.sh
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Oct 11, 15:31
Size
1 KB
Mime Type
text/x-shellscript
Expires
Sun, Oct 13, 15:31 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
21566023
Attached To
rLAMMPS lammps
file_to_cstr.sh
View Options
#!/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
Event Timeline
Log In to Comment