Site do Cléber | Desisto de ter 10 blogs

New – cria esqueletos de código fonte

Para evitar de ficar escrevendo os mesmos “esqueletos” de código fonte, eu criei esse scriptzinho bacana. Ele facilitou muito minha vida, principalmente na época em que eu precisava ficar criando Makefiles…

#!/bin/bash

case $1 in
###############################################################

“–help” | “-h”)
print “Uso: $(basename $0) [html|py|php|c|cpp|cMakefile|cppMakefile|sh|zsh]”
;;

###############################################################

“py”)

echo -e “#!/usr/bin/env python
#-*-encoding: latin-1 -*-

import sys

### Main ###

def Main():

pass

############

# Se o programa for chamado como um executável
if __name__ == ‘__main__’:
argc = len(sys.argv)
Main()

;;

###############################################################

“html”)
echo -e ”
<html>
<head>
<title></title>

<link rel=’stylesheet’ href=’style.css’ type=’text/css’>

<meta name=’author’ value=’$USER@$HOST’>
</head>
<body>

</body>
</html>

;;

###############################################################

“sh”)
echo -e “#!/bin/sh

if [[ \$1 == \"\" ]];then
echo \”Uso: \$0\”
exit 1
else
arquivo=\$1
fi


;;

###############################################################
#
“bash”)
echo -e “#!/bin/bash

if [[ \$1 == \"\" ]];then
echo \”Uso: \$0\”
exit 1
else
arquivo=\$1
fi


;;

#
“zsh”)
echo -e “#!/bin/zsh

if [[ \$1 == \"\" ]];then
echo \”Uso: \$0\”
exit 1
else
arquivo=\$1
fi

;;

###############################################################

“php”)
echo -e ”
<?

?>
<html>
<head>
<title></title>

<link rel=’stylesheet’ href=’style.css’ type=’text/css’>

<meta name=’author’ value=’$USER@$HOST’>
</head>
<body>

</body>
</html>


;;

###############################################################

“c”)
echo -e ”
#include <stdio.h>

int main(int argc, char *argv[])
{

if (argc <= 1)
{
}
else
{
}

}


;;

###############################################################

“cpp”)
echo -e ”
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
if (argc <= 1)
{
}
else
{
}
}

;;

###############################################################

[Mm]akefile|c[Mm]akefile)
names=”

for file in $(print *.c);do
names=($(echo $file | cut -f1 -d”.”) $names)
done

objs=”
srcs=”

for file in $names;do
objs=($file.o $objs)
srcs=($file.c $srcs)
done

for file in $names;do
if egrep “main *(.*)” $file.c > /dev/null;then
bin=$file
break
fi
done

if [[ -z $bin ]];then
bin=’a.out’
fi

echo -e ”
OFLAGS = -c -g
CFLAGS = -g
CC = gcc

All: $objs $srcs
\$(CC) \$(OFLAGS) $srcs
\$(CC) \$(CFLAGS) $objs -o $bin

for file in $names;do
echo -e ”
$file.o: $file.c
\$(CC) \$(OFLAGS) $file.c

done

echo -e ”
clean:
rm -rf *.o $bin

;;

###############################################################

cpp[Mm]akefile)
names=”

for file in $(print *.cpp);do
names=($(echo $file | cut -f1 -d”.”) $names)
done

objs=”
srcs=”

for file in $names;do
objs=($file.o $objs)
srcs=($file.cpp $srcs)
done

for file in $names;do
if egrep “main *(.*)” $file.cpp > /dev/null;then
bin=$file
break
fi
done

if [[ -z $bin ]];then
bin=’a.out’
fi

echo -e ”
CC = g++
OFLAGS = -c -g
CFLAGS = -g

All: $objs $srcs
\$(CC) \$(OFLAGS) $srcs
\$(CC) \$(CFLAGS) $objs -o $bin

for file in $names;do
echo -e ”
$file.o: $file.cpp
\$(CC) \$(OFLAGS) $file.cpp

echo -e ”
clean:
rm -rf *.o $bin

done
;;

###############################################################

*)
echo “ERRO! Formato desconhecido.” 1>&2
;;

esac

Avaliação: 5 stars

Nenhum comentário ainda.

Leave a comment!

Paged comment generated by AJAX Comment Page

Ratings Plugin created by Jake Ruston.