-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate main to WinMain - resolves #1
- Loading branch information
1 parent
f81337c
commit 4fdb46e
Showing
1 changed file
with
18 additions
and
23 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,41 @@ | ||
#include <stdio.h> | ||
#include <unistd.h> | ||
#include <windows.h> | ||
|
||
//run contents of winrun.cfg line by line on command interpreter | ||
int main(int argc, char *argv[]) | ||
{ | ||
//create local variables | ||
FILE * fp; | ||
char * linebuf[ 256+1 ] = { 0 }; | ||
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { | ||
FILE* fp; | ||
char linebuf[256 + 1] = { 0 }; | ||
char path[MAX_PATH]; | ||
|
||
//get and chdir executable dir | ||
char *dirsep = strrchr( argv[0], '\\' ); | ||
if ( NULL != dirsep ) | ||
{ | ||
*dirsep=0; | ||
if ( 0 > chdir( argv[0] ) ) | ||
{ | ||
GetModuleFileName( NULL, path, MAX_PATH ); | ||
char* dirsep = strrchr( path, '\\' ); | ||
if ( NULL != dirsep ) { | ||
*dirsep = 0; | ||
if ( 0 > chdir( path ) ) { | ||
perror( "chdir() not successful" ); | ||
return -1; | ||
} | ||
} | ||
|
||
//open cfg file | ||
fp = fopen("winrun.cfg", "r"); | ||
if ( NULL == fp ) | ||
{ | ||
perror("Could not open file winrun.cfg"); | ||
fp = fopen( "winrun.cfg", "r" ); | ||
if ( NULL == fp ) { | ||
perror( "Could not open file winrun.cfg" ); | ||
return -2; | ||
} | ||
|
||
//read and execute from file line by line | ||
while( 0 < fscanf( fp , "%256[A-Za-z0-9 -\\:]\n", &linebuf ) ) | ||
{ | ||
printf("> %s\n", linebuf); | ||
if ( -1 == system( linebuf )) | ||
{ | ||
perror("ERROR Executing system()"); | ||
while ( 0 < fscanf( fp, "%256[A-Za-z0-9 -\\:]\n", linebuf ) ) { | ||
printf( "> %s\n", linebuf ); | ||
if ( -1 == system( linebuf ) ) { | ||
perror( "ERROR Executing system()" ); | ||
fclose( fp ); | ||
return -3; | ||
} | ||
} | ||
|
||
//cleanup and close | ||
// cleanup and close | ||
fclose( fp ); | ||
exit( 0 ); | ||
} |