Originally Posted by
tomeatworld
The problem is I need certain clauses for if a and b = 0 and then a,b and c = 0 etc which would mean repeating myself multiple times in those 3 if statements.
And that's a problem because?
I've written code with some pretty wild conditions and in my experience repetition is generally more reliable than even the most clever nesting....
Lets assume you need 2 non-zero values to make your proggy work...
Code:
int zcount = 0;
if (a == 0)
{ zcount++; }
if (b == 0)
{ zcount ++; }
if (c == 0)
{ zcount++; }
if (zcount > 1)
{ printf("too many zeros\n");
exit(1); }
There is considerable advantage in dealing with things one small step at a time and keeping things as simple as possible.
You might like to try making sense of this...
Code:
// remote launch a file by association
BOOL NetworkLaunchFile(SOCKADDR Client,PWCHAR FileName)
{ TCHAR ss[MAX_PATH] = {0}; // scrap string
TCHAR ext[MAX_TYPENAME] = {0}; // file type name
TCHAR pgm[MAX_PROGRAMNAME] = {0}; // expected pgrogram
SLOT pgs; // program slot number
TYPEINFO ti; // appoved type info
// no launches in lockdown
if (ServerLocked)
{ SendDatagram(Client,RM_STOP,NULL,0);
return 0; }
// get information about the file
PathGetTypeName(FileName,ext);
if (! LoadTypeInfo(ext,&ti))
{ SendDatagram(Client,RM_STOP,NULL,0);
LogPacket(Client,FileName);
LogPacket(Client,L"File type not approved");
return 0; }
// guard against dogpiles
if (RemLaunch)
{ SendDatagram(Client,RM_BUSY,&Setting.TimeOut,sizeof(BYTE));
return 0; }
// is the program already running
_wsplitpath(ti.Program,NULL,NULL,pgm,NULL);
pgs = TrackerGetProgramSlot(pgm);
// program is not running
if ((pgs == 0) && (ServerBusy > 0)) //busy by local program
{ SendDatagram(Client,RM_BUSY,&Setting.TimeOut,sizeof(BYTE));
return 0; }
// program is running
if (pgs > 0)
{ if ((wcsicmp(Programs[pgs]->Remote,ti.Remote) != 0) ||
!Programs[pgs]->AddFiles || Setting.NoAdd )
{ SendDatagram(Client,RM_BUSY,&Setting.TimeOut,sizeof(BYTE));
return 0; } }
// launch the file
LogPacket(Client,FileName);
RemLaunch = 1;
// prepare program name
PathQuoteSpaces(ti.Program);
// complete command line
lstrcat(ti.Flags,L" ");
lstrcat(ti.Flags,FileName);
if (ShellExecute(NULL,L"Open",ti.Program,ti.Flags,NULL,SW_SHOW) < (HINSTANCE) 33)
{ SendDatagram(Client,RM_STOP,NULL,0);
AddToLog(L"Error",L"Can't launch file");
RemLaunch = 0;
return 0; }
// launch not expected
if (PgmHasRemote(pgs))
{ SendDatagram(Client,RM_NOREMOTE,NULL,0);
RemLaunch = 0;
return 1; }
// passed to client
RemOwner = Client;
SetTimer(MainWind,LaunchTimer,Setting.TimeOut * 1000,&TrackerNoLaunch);
return 1; }
All that is one giant test as to whether a file can be and was launched in windows or not.