Created
January 16, 2012 05:40
-
-
Save radiofreejohn/1619238 to your computer and use it in GitHub Desktop.
create a skeleton C source with main() and includes
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 | |
#+ | |
# Usage | |
# newc filename [include[.h] ...] | |
# | |
# Output | |
# Creates a file (filename) with a skeleton main function, with | |
# optional include files in the header. If the file exists in | |
# /usr/include then #include <include.h> is added, if it is not | |
# found in /usr/include, but is found in the current directory | |
# then #include "include.h" is added. | |
# | |
# Examples | |
# newc test stdio | |
# newc test.c stdio stdlib string test | |
# newc test.c stdio.h stdlib.h string.h test.h | |
#- | |
if [ "$1" == "" ] | |
then | |
echo "Usage: newc filename" | |
exit | |
fi | |
if [ ! -e $1 ] ; then | |
FILENAME="`basename $1 .c`.c" | |
shift | |
for i in $@ ; do | |
if [ -f "/usr/include/`basename $i .h`.h" ] ; then | |
echo "#include <`basename $i .h`.h>" | |
echo "#include <`basename $i .h`.h>" >> $FILENAME | |
elif [ -f "`basename $i .h`.h" ] ; then | |
echo "#include \"`basename $i .h`.h\"" | |
echo "#include \"`basename $i .h`.h\"" >> $FILENAME | |
fi | |
done | |
echo "" >> $FILENAME | |
echo "int main(int argc, char *argv[]) {" >> $FILENAME | |
echo "" >> $FILENAME | |
echo "" >> $FILENAME | |
echo " return 0;" >> $FILENAME | |
echo "}" >> $FILENAME | |
echo "$FILENAME: created." | |
else echo "$FILENAME: file exists" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment