/*********************************************************************** * HandleCommandLine * * Handle command line options * * ARGUMENTS: * - command line options passed to the program (as string): * char *cmdline * RETURNS: none */ static void HandleCommandLine(char *cmdline) { /* file name is passed in the command line */ if (*cmdline) { /* Remove double-quotes from filename */ /* Double-quotes are not allowed in Windows filenames */ if (cmdline[0] == '"') { char *wc; cmdline++; wc = cmdline; while (*wc && *wc != '"') wc++; *wc = 0; } if (FileExists(cmdline)) { DoOpenFile(cmdline); InvalidateRect(Globals.hMainWnd, NULL, false); } else { switch (AlertFileDoesNotExist(cmdline)) { case IDYES: SetFileName(cmdline); UpdateWindowCaption(); break; case IDNO: break; case IDCANCEL: DestroyWindow(Globals.hMainWnd); break; } } } }
static void HandleCommandLine(LPTSTR cmdline) { int opt_print=0; while (*cmdline == _T(' ') || *cmdline == _T('-') || *cmdline == _T('/')) { TCHAR option; if (*cmdline++ == _T(' ')) continue; option = *cmdline; if (option) cmdline++; while (*cmdline == _T(' ')) cmdline++; switch(option) { case 'p': case 'P': opt_print=1; break; } } if (*cmdline) { /* file name is passed in the command line */ LPCTSTR file_name = NULL; BOOL file_exists = FALSE; TCHAR buf[MAX_PATH]; if (cmdline[0] == _T('"')) { cmdline++; cmdline[lstrlen(cmdline) - 1] = 0; } file_name = cmdline; if (FileExists(file_name)) { file_exists = TRUE; } else if (!HasFileExtension(cmdline)) { static const TCHAR txt[] = _T(".txt"); /* try to find file with ".txt" extension */ if (!_tcscmp(txt, cmdline + _tcslen(cmdline) - _tcslen(txt))) { file_exists = FALSE; } else { _tcsncpy(buf, cmdline, MAX_PATH - _tcslen(txt) - 1); _tcscat(buf, txt); file_name = buf; file_exists = FileExists(file_name); } } if (file_exists) { DoOpenFile(file_name); InvalidateRect(Globals.hMainWnd, NULL, FALSE); if (opt_print) DIALOG_FilePrint(); } else { switch (AlertFileDoesNotExist(file_name)) { case IDYES: DoOpenFile(file_name); break; case IDNO: break; } } } }