#include <stdio.h>
#include <windows.h>
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
int nResponse;
setbuf(stdout,NULL); /* Make stdout unbuffered */
do
{
nResponse = MessageBox(NULL,"Press Yes or No for output, Cancel to exit\n",
"Windows stdout", MB_YESNOCANCEL);
switch (nResponse)
{
case IDYES:
printf("Yes button pressed\n");
break;
case IDNO:
printf("No button pressed\n");
break;
}
}
while (nResponse != IDCANCEL);
return 0;
}
#include <stdio.h>
int main()
{
while (!feof(stdin)) putchar(getchar());
return 0;
}
If you called this program winpipe you would then run:
#! /bin/sh
for i in `ls`
do
echo $i
done
NOTE : The ` character is not a '
#! /bin/sh
for i in `ls *.txt`
do
echo Converting $i
cat $i | tr -d '\r' > $i.tmp
mv -f $i.tmp $i
done
fif /usr/include/sys/ malloc /usr/include/sys//malloc.h 56: * @(#)malloc.h 8.5 (Berkeley) 5/3/95 67: * flags to malloc 289: * The malloc/free primatives used /usr/include/sys//mbuf.h 230:/* Need to include malloc.h to get right options for malloc */ 231:#includeThe script:/usr/include/sys//namei.h 186: * size a power of two to optimize malloc's. Minimum reasonable
#! /bin/sh
#Function to explain script usage
usage()
{
echo "Usage: $0 [directory] pattern"
echo " searches for pattern in ascii files"
exit 1
}
#Check correct number of arguments (1 or 2)
if [ $# -ne 1 -a $# -ne 2 ]
then
usage
fi
#If only one argument (pattern) use current directory as directory
if [ $# -eq 2 ]
then
start=$1
shift
else
start="."
fi
pattern=$1
#Do the work
for found in `find $start -type f`
do
# Check if the file is text
(file $found | grep text) > /dev/null
if [ $? -eq 0 ]
then
# See if the file contains the pattern
(grep "$pattern" $found) > /dev/null
if [ $? -eq 0 ]
then
# Found one or more matches print filename and matches
echo $found
grep -n "$pattern" $found
echo
fi
fi
done
Finally, the most complex script I have ever written. I used to
use this before I used CVS for source control. This script merges
two source code trees. You give the source and destination directories
as arguments and when it finds source files that differ, it prints
out the differences given by diff and then gives you the option
of overwritting the destination file, or merging by hand using xdiff.
Before using the script you have to configure it for the machine, by
adding the name returned from "hostname" to the case statement at
the begining of the script.
#! /bin/sh
#
# script to merge source files
#
# author patrick@nag-j.co.jp 12.3.99
#
# Requires GNU diff (for -q) and X11/Motif xdiff
#
# Set the compare and merge variables in the following case
# statement to point to these executables on your machine
#
# If your GNU diff distinguishes between binary and acsii
# files by saying Binary files x and y differ rather than
# just Files x and y differ with the -q option, you can set
# binaryok to 1
#
binaryok=0
diffargs="-wb"
recusivediff="-rq"
mergequiet="-D"
mergeargs="-wb"
# *** Add your machine to this case statement ***
case `hostname` in
hal )
compare=/bin/diff
merge="/usr/sbin/xdiff"
binaryok=1
;;
server )
compare=/usr/local/bin/diff
merge="/usr/local/bin/xdiff"
;;
extreme )
compare=/usr/local/bin/diff
merge="/usr/bin/X11/demos/mgdiff"
mergequiet="-quit"
mergeargs="-args -wb"
;;
* )
echo $0: Sorry not configured for this machine
echo " If you have GNU diff and X11/Motif xdiff installed add"
echo " this machine to the case statement at the begining of"
echo " " $0
exit 1
;;
esac
usage()
{
echo "Usage: $0 [-lnsIm] [-aargs] [-dargs] [-xargs] [-efile] source dest"
echo " -I -- Ignore Imakefiles"
echo " -M -- Ignore Makefiles"
echo " -l -- list mode. Just lists files that differ"
echo " -n -- (nowarnings) Does not warn when file to be overwritten is newer"
echo " -s -- (superuser) Allows source to be overwritten (recover)"
echo " -aargs -- pass args to diff and xdiff"
echo " -dargs -- pass args to diff"
echo " -xargs -- pass args to xdiff"
echo " -efile -- echo everything to file"
exit 1
}
echotolog ()
{
if [ $logfile ]
then
echo "$*" >> $logfile
fi
}
printout()
{
echo "$*"
echotolog "$*"
}
printnonl()
{
printf "$*"
if [ $logfile ]
then
printf "$*" >> $logfile
fi
}
getresponse ()
{
read ans
echotolog $ans
}
testcontinue ()
{
printnonl " Continue anyway (y,[n])?"
getresponse
case "$ans" in
y*) :
;;
*) exit 1
;;
esac
}
finalcopy()
{
cp -f $1 $2
if [ $? -eq 0 ]
then
printout $2
printout Overwritten by
printout $1
else
printnonl Copy failed.
testcontinue
fi
}
copyfile()
{
if [ $nowarning -eq 1 ]
then
finalcopy $2 $1
else
tail=`basename $1`
found=`find $1 -name $tail -newer $2`
if [ $found ]
then
printnonl "***Are you sure?" $1 is newer than $2 "(y,[n])?"
getresponse
case "$ans" in
y*) finalcopy $2 $1
;;
esac
else
finalcopy $2 $1
fi
fi
}
if [ $# -lt 2 ]
then
usage
exit 1
fi
nowarning=0
listmode=0
superuser=0
while [ $# -gt 2 ]
do
case $1 in
-* )
options=`expr "$1" : '-\(.*\)'`
;;
* )
options=$1
;;
esac
case $options in
e* )
logfile=`expr "$options" : 'e\(.*\)'`
;;
a* )
args=`expr "$options" : 'a\(.*\)'`
userdargs="$userdargs $args"
userxargs="$userxargs $args"
;;
d* )
args=`expr "$options" : 'd\(.*\)'`
userdargs="$userdargs $args"
;;
x* )
args=`expr "$options" : 'x\(.*\)'`
userxargs="$userxargs $args"
;;
* )
case $options in
*[!lnsIM]* )
echo $0: Unknown option $1
usage
;;
esac
case $options in
*[l]* )
listmode=1
;;
esac
case $options in
*[n]* )
nowarning=1
;;
esac
case $options in
*[s]* )
superuser=1
;;
esac
case $options in
*[I]* )
skipImake="-xImakefile"
;;
esac
case $options in
*[M]* )
skipMake="-xMakefile"
;;
esac
;;
esac
shift
done
if [ $listmode -ne 1 ]
then
# check DISPLAY is set and xdiff works
$merge $mergequiet $0 $0
if [ $? -ne 0 ]
then
printnonl Will not be able to merge files.
testcontinue
else
canmerge=1
fi
fi
if [ $listmode -eq 1 ]
then
echo List mode
fi
if [ $nowarning -eq 1 ]
then
echo Warnings disabled
fi
if [ $superuser -eq 1 ]
then
echo You are superuser
fi
if [ $skipImake ]
then
echo Ignoring Imakefiles
fi
if [ $skipMake ]
then
echo Ignoring Makefiles
fi
if [ $logfile ]
then
echo Echoing to $logfile
fi
if [ "$userdargs" ]
then
echo Extra diff args $userdargs
fi
if [ "$userxargs" ]
then
echo Extra xdiff args $userxargs
fi
echo Comparing files. Please wait...
if [ $listmode -eq 1 ]
then
if [ binaryok -eq 1 ]
then
printout `$compare $recusivediff $diffargs $userdargs $skipImake $skipMake $1 $2 | grep -v "Only in"\
| grep -v "Binary files" | awk '{print $2,$4 }'`
else
file1="_"
for file2 in `$compare $recusivediff $diffargs $userdargs $skipImake $skipMake $1 $2 | grep -v "Only in"\
| awk '{print $2,$4 }'`
do
if [ $file1 = "_" ] ; then file1=$file2 ;
else
$compare $diffargs $userdargs $file1 $file2 | grep "Binary files" > /dev/null
if [ $? -ne 0 ]
then
printout $file1 $file2
fi
file1="_"
fi
done
fi
exit 0
fi
file1="_"
for file2 in `$compare $recusivediff $diffargs $userdargs $skipImake $skipMake $1 $2 | grep -v "Only in"\
| grep -v "Binary files" | awk '{print $2,$4 }'`
do
if [ $file1 = "_" ] ; then file1=$file2 ;
else
continue=1
if [ binaryok -eq 0 ]
then
$compare $diffargs $userdargs $file1 $file2 | grep "Binary files" > /dev/null
if [ $? -eq 0 ]
then
continue=0
fi
fi
if [ $continue -eq 1 ]
then
printout \\n\\n\\n
$compare $diffargs $userdargs $file1 $file2
if [ $logfile ]
then
$compare $diffargs $userdargs $file1 $file2 >> $logfile
fi
($compare $diffargs $userdargs $file1 $file2 | awk '{ print $1 }' | grep ">") > /dev/null
noex1=$?
($compare $diffargs $userdargs $file1 $file2 | awk '{ print $1 }' | grep "<") > /dev/null
noex2=$?
if [ $noex1 -ne 1 -o $noex2 -ne 1 ]
then
ls -og $file1 | awk '{printf "\n\n< %s\n Date : ",$NF} \
{for (i=4; i < NF;i++) printf " %s",$i }\
{ print " Size : "$3 }'
if [ $noex1 -eq 0 -a $noex2 -eq 0 ]
then
printout " May need merging with"
elif [ $noex1 -eq 0 ]
then
printout " Has less code than"
else
printout " Contains extra code not in"
fi
ls -og $file2 | awk '{printf "> %s\n Date : ",$NF} \
{for (i=4; i < NF;i++) printf " %s",$i }\
{ print " Size : "$3 }'
printout
printout Overwrite $file2 "(yes,[no]"\\c
if [ $canmerge ]
then
printout ,merge\\c
fi
if [ $superuser -eq 1 ]
then
printout ",recover"\\c
fi
printout ")?"\\c
getresponse
case "$ans" in
y*) copyfile $file2 $file1
;;
r*) if [ $superuser -eq 1 ]
then
printout Overwrite $file1 "(yes,[no])?"\\c
getresponse
case "$ans" in
y*) copyfile $file1 $file2
;;
esac
fi
;;
m*) if [ $canmerge ]
then
chmod +w $file2
if [ $superuser -eq 1 ]
then
chmod +w $file1
fi
$merge $mergeargs $userxargs $file1 $file2
$compare $diffargs $userdargs $file1 $file2 > /dev/null
if [ $? -eq 0 ]
then
printout $file1
printout Merged with
printout $file2
else
printout Not merged
fi
chmod -w $file2
if [ $superuser -eq 1 ]
then
chmod -w $file1
fi
fi
;;
esac
fi
fi
file1="_"
fi
done
#include <windows.h>
#include <stdio.h>
#define PIPE_BUFFER 1024
struct handleInfo
{
HANDLE process;
HANDLE pipe;
};
DWORD WINAPI waitForExit(void *ptr)
{
handleInfo *info = (handleInfo *)ptr;
WaitForSingleObject(&(info->process),INFINITE);
CloseHandle(info->pipe);
return 0;
}
int main(int argc, char *argv[])
{
PROCESS_INFORMATION procInfo;
STARTUPINFO StartupInfo = { 0 };
DWORD why,bread,tid,code,i;
handleInfo hInfo;
HANDLE writePipe,readPipe,hThread;
SECURITY_ATTRIBUTES secAttr = {sizeof(SECURITY_ATTRIBUTES), NULL, TRUE};
LPSTR lpCmdLine;
int pos;
int ac;
int colon;
StartupInfo.cb = sizeof(STARTUPINFO);
StartupInfo.dwFlags = STARTF_USESTDHANDLES;
if (argc < 2)
{
printf("No command to execute!\n");
return 1;
}
if (!CreatePipe(&readPipe, &writePipe, &secAttr, 0))
{
why = GetLastError();
printf("CreatePipe Error : %d\n",why);
return 1;
}
StartupInfo.hStdInput = NULL;
StartupInfo.hStdOutput = writePipe;
StartupInfo.hStdError = writePipe;
lpCmdLine = new char[strlen(GetCommandLine())];
pos = 0;
for (ac = 1; ac < argc; ac++)
{
sprintf(lpCmdLine+pos,"%s ",argv[ac]);
pos += strlen(argv[ac])+1;
}
lpCmdLine[pos-1] = 0;
if (!CreateProcess(NULL, lpCmdLine, NULL, NULL, TRUE,
0, NULL,NULL, &StartupInfo, &procInfo))
{
why = GetLastError();
printf("CreateProcess \"%s\" Error : %d\n",lpCmdLine,why);
delete [] lpCmdLine;
return 1;
}
delete [] lpCmdLine;
char buffer[PIPE_BUFFER];
hInfo.process = procInfo.hProcess;
hInfo.pipe = writePipe;
hThread = CreateThread(NULL, 0, waitForExit,
&hInfo, 0, &tid);
if (hThread == NULL)
{
why = GetLastError();
printf("CreateThread Error : %d\n",why);
return 1;
}
colon = 0;
while (ReadFile(readPipe,buffer,PIPE_BUFFER-2,&bread,NULL))
{
if (bread == 0) break;
for (i = 0; i < bread; i++)
{
if (buffer[i] == '\n') colon = 0;
else if (buffer[i] == ':')
{
colon++;
switch (colon)
{
case 1:
buffer[i] = '(';
break;
case 2:
buffer[i++] = ')';
buffer[i] = ':';
if (i == bread) bread++;
break;
}
}
}
buffer[bread] = 0;
printf("%s",buffer);
}
if (!GetExitCodeProcess(procInfo.hProcess,&code)) code = 1;
return code;
}
If you compile this program to create an executable called JavaToVC.exe
you then just add this program to the front of the custom build command, e.g: