Wednesday, July 25, 2007

C++: Check a valid date

C++ has no checkdate, like php does. so i wrote this to filter out bad dates and feb29ths.

bool isValidDate(int m, int d, int y)
{
//
checks Gregorian date
if
(! (1582<= y ) )
return false;
if (! (1<= m && m<=12) )
return false;
if (! (1<= d && d<=31) )
return false;
if ( (d==31) && (m==2 || m==4 || m==6 || m==9 || m==11) )
return false;
if ( (d==30) && (m==2) )
return false;
if ( (m==2) && (d==29) && (y%4!=0) )
return false;
if ( (m==2) && (d==29) && (y%400==0) )
return true;
if ( (m==2) && (d==29) && (y%100==0) )
return false;
if ( (m==2) && (d==29) && (y%4==0) )
return true;

return true;
}


source(s): http://en.wikipedia.org/wiki/Leap_year

Monday, July 23, 2007

C++: Hide an Application from the Taskbar

(This solution is specific to Borland C++ Builder)

Use this code as your project source to prevent the window from showing up in your windows taskbar.

WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try
{
Application->Initialize();
Application->CreateForm(__classid(TForm1), &Form1);
SetWindowLong(Application->Handle,
GWL_EXSTYLE,
GetWindowLong(Application->Handle, GWL_EXSTYLE)
|
WS_EX_TOOLWINDOW) ;
Application->Run();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
return 0;
}


source(s): http://delphi.about.com/od/adptips1999/qt/hidefromtaskbar.htm

Friday, July 20, 2007

C++: Redirect command-line output

I've always wondered how to capture output from a command line program in windows, and the record it into a file.

while you can always just the greater-than-sign to output text into a file at the windows command prompt, sometimes it just isn't good enough.
"echo abc>hi.txt"

I ran into this once with mysqldump.exe.

Well I finally found the code that works. In this example I call 'dir'.

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char* argv[])
{
char psBuffer[128];
FILE *iopipe;

if( (iopipe = _popen( "dir", "rt" )) == NULL )
exit( 1 );

while( !feof( iopipe ) )
{
if( fgets( psBuffer, 128, iopipe ) != NULL )
printf( psBuffer );
}

printf( "\nProcess returned %d\n", _pclose( iopipe ) );

return 0;
}





source(s): www.daniweb.com/forums/thread5755.html

Thursday, July 05, 2007

SVN: Command-line SVN

Just a couple examples.

Use svn checkout help or svn update help for more details.
//you do the initial checkout like this:
svn checkout [svn path] [destination path]
//svn path: svn://192.168.0.93/srv/svn/src/trunk/proj
//dest path: /srv/www/htdocs/dest_path
//user note: it may prompt for a username and password

//this will update to the most recent revision
svn update [destination path]

//for more details call
svn checkout help
// or
svn update help