Last active
December 20, 2015 19:58
-
-
Save yoursunny/6186598 to your computer and use it in GitHub Desktop.
CCNx shim for NDNx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# CCNx shim for NDNx | |
# This script creates shim headers so that apps written for CCNx can compile with NDNx. | |
# NDNx is available at https://github.com/named-data/ndnx | |
# | |
# Usage: sudo ./ndnx-ccnx-shim.sh | |
# updated: 2013-09-02 | |
INCLUDE_DIR=/usr/local/include | |
LIB_DIR=/usr/local/lib | |
BIN_DIR=/usr/local/bin | |
if [ ! -f $INCLUDE_DIR/ndn/ndn.h ] | |
then | |
echo "$INCLUDE_DIR/ndn/ndn.h is not found" | |
return | |
fi | |
rm -rf $INCLUDE_DIR/ccn | |
mkdir -p $INCLUDE_DIR/ccn/ | |
for f in `ls $INCLUDE_DIR/ndn/` | |
do | |
f=`basename $f` | |
cat $INCLUDE_DIR/ndn/$f | php5 -r ' | |
$in = file("php://stdin"); | |
$includes = array(); | |
foreach ($in as &$l) { | |
if (preg_match("/^\#include\s<ndn\/([a-z0-9\_]+\.h)>/",$l,$match)) { | |
$includes[] = $match[1]; | |
} | |
if (preg_match("/^\/\*|^\s\*|^\#include\s|^\#(?:ifndef|define).*_DEFINED/",$l)) $l=""; | |
} | |
foreach ($includes as $include) { | |
printf("#include <ccn/%s>\n", $include); | |
} | |
$f = $argv[1]; | |
printf("#include <ndn/%s>\n",$f); | |
$in = implode($in); | |
preg_match_all("/ndn[a-z0-9\_]*|[a-z0-9\_]*\_ndnb/i", $in, $matches); | |
$tokens = array_unique($matches[0]); | |
foreach ($tokens as $token) { | |
$ccn_token = str_replace(array("ndn","NDN"),array("ccn","CCN"),$token); | |
printf("#define %s %s\n", $ccn_token, $token); | |
} | |
' $f > $INCLUDE_DIR/ccn/$f | |
done | |
for f in `ls $INCLUDE_DIR/ndn/ndn*` | |
do | |
f=`basename $f` | |
ln -s $f $INCLUDE_DIR/ccn/${f//ndn/ccn} | |
done | |
rm -rf $LIB_DIR/*ccn* | |
for f in `ls $LIB_DIR/*ndn*` | |
do | |
f=`basename $f` | |
ln -s $f $LIB_DIR/${f//ndn/ccn} | |
done | |
rm -rf $BIN_DIR/*ccn* | |
for f in `ls $BIN_DIR/*ndn*` | |
do | |
f=`basename $f` | |
ln -s $f $BIN_DIR/${f//ndn/ccn} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment