kode yard
all about C++ and PHP
Saturday, May 8, 2010
utility script-2
This is a shell script that automates the compilation of single c/c++ source file and executes this.
#!/bin/bash
#Developed by : lipun4u@gmail.com
file_name=$1
c_extension=".c"
cpp_extension=".cpp"
ip_file_name="$file_name$c_extension"
i=0
if [ $# -ne 1 ]
then
echo "Usage: `basename $0`
"
echo "Source file should be without extension"
echo "e.g :-`basename $0` test"
exit 1
fi
if [ -f $ip_file_name ]
then
echo "compiling c-source file $file_name ....."
gcc -o $file_name $ip_file_name -lpthread
if [ $? -eq 0 ]
then
i=1
fi
else
ip_file_name="$file_name$cpp_extension"
if [ -f $ip_file_name ]
then
echo "compiling c++-source file $file_name ....."
g++ -o $file_name $ip_file_name -lpthread
if [ $? -eq 0 ]
then
i=1
fi
else
echo "compilation failed"
exit 1
fi
fi
if [ $i -eq 1 ]
then
echo "Output file name : $file_name"
echo "Executing......"
echo
./$file_name
exit_status=$?
if [ $exit_status -ne 0 ]
then
echo "Program execution failed with exit status $exit_status"
exit 1
fi
echo
echo "Program executed successful"
fi
Saturday, May 1, 2010
utility script-1
This is an utility script that makes a file executable and opens in vi editor.
#!/bin/bash
#Developed by : lipun4u@gmail.com
if [ $# -ne 1 ]
then
echo "Usage: `basename $0`
"
exit 1
fi
touch $1
chmod u+x $1
vi $1
Thursday, November 5, 2009
clipboard logger
This code snippet logs all clipboard text in a log file...
#include
#include
#include
#include
using namespace std;
void myfree();
FILE *fp;
char *p;
HANDLE clip;
int main()
{
HANDLE clip;
p=(char*)malloc(1);
*p='\0';
fp= fopen("log.txt", "a");
atexit(myfree);
while(true)
{
if (OpenClipboard(NULL))
{
clip = GetClipboardData(CF_TEXT);
if(strcmp(p,(char*)clip)!=0)
{
free(p);
p = (char*)malloc(strlen((char*)clip)+1);
strcpy(p,(char*)clip);
fprintf(fp,"%s",p);
}
CloseClipboard();
}
Sleep(500);
}
}
void myfree()
{
free(p);
if(fp!=NULL)
fclose(fp);
free(clip);
}
This is well tested in Dev C++.
Newer Posts
Older Posts
Home
Subscribe to:
Posts (Atom)