| 1 | 
 | 
|---|
| 2 | /***********************************************************************
 | 
|---|
| 3 | 
 | 
|---|
| 4 |   $Id: fm2cmd.c 1438 2009-06-28 20:47:00Z gyoung $
 | 
|---|
| 5 | 
 | 
|---|
| 6 |   Copyright (c) 1993-98 M. Kimes
 | 
|---|
| 7 |   Copyright (c) 2003, 2008 Steven H.Levine
 | 
|---|
| 8 | 
 | 
|---|
| 9 |   Command processing
 | 
|---|
| 10 | 
 | 
|---|
| 11 |   20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
 | 
|---|
| 12 |   28 Jun 09 GKY Added AddBackslashToPath() to remove repeatative code.
 | 
|---|
| 13 | 
 | 
|---|
| 14 | ***********************************************************************/
 | 
|---|
| 15 | 
 | 
|---|
| 16 | #include <string.h>
 | 
|---|
| 17 | 
 | 
|---|
| 18 | #define INCL_DOS
 | 
|---|
| 19 | #define INCL_WIN
 | 
|---|
| 20 | #define INCL_LONGLONG                   // dircnrs.h
 | 
|---|
| 21 | 
 | 
|---|
| 22 | #include "fm3dll.h"
 | 
|---|
| 23 | #include "fm3dll2.h"                    // #define's for UM_*, control id's, etc.
 | 
|---|
| 24 | #include "notebook.h"                   // Data declaration(s)
 | 
|---|
| 25 | #include "fm3dlg.h"
 | 
|---|
| 26 | #include "fm3str.h"
 | 
|---|
| 27 | #include "errutil.h"                    // Dos_Error...
 | 
|---|
| 28 | #include "strutil.h"                    // GetPString
 | 
|---|
| 29 | #include "fm2cmd.h"
 | 
|---|
| 30 | #include "mainwnd.h"                    // FindDirCnrByName
 | 
|---|
| 31 | #include "valid.h"                      // MakeFullName
 | 
|---|
| 32 | #include "misc.h"                       // PostMsg
 | 
|---|
| 33 | #include "delims.h"                     // skip_delim
 | 
|---|
| 34 | #include "pathutil.h"                   // AddBackslashToPath
 | 
|---|
| 35 | 
 | 
|---|
| 36 | 
 | 
|---|
| 37 | static VOID fullname(CHAR * directory, CHAR * name);
 | 
|---|
| 38 | static VOID parse(CHAR * command, CHAR * key, CHAR * rest);
 | 
|---|
| 39 | 
 | 
|---|
| 40 | // Data definitions
 | 
|---|
| 41 | #pragma data_seg(GLOBAL1)
 | 
|---|
| 42 | BOOL fKeepCmdLine;
 | 
|---|
| 43 | BOOL fSaveMiniCmds;
 | 
|---|
| 44 | 
 | 
|---|
| 45 | #pragma data_seg(DATA2)
 | 
|---|
| 46 | 
 | 
|---|
| 47 | static VOID fullname(CHAR * directory, CHAR * name)
 | 
|---|
| 48 | {
 | 
|---|
| 49 | 
 | 
|---|
| 50 |   CHAR temp[CCHMAXPATH];
 | 
|---|
| 51 | 
 | 
|---|
| 52 |   if (!*name) {
 | 
|---|
| 53 |     strcpy(name, directory);
 | 
|---|
| 54 |     return;
 | 
|---|
| 55 |   }
 | 
|---|
| 56 |   if (!strchr(name, ':')) {
 | 
|---|
| 57 |     if (*name != '\\' && *name != '/') {
 | 
|---|
| 58 |       strcpy(temp, directory);
 | 
|---|
| 59 |       AddBackslashToPath(directory);
 | 
|---|
| 60 |       //if (directory[strlen(directory) - 1] != '\\')
 | 
|---|
| 61 |       //  strcat(temp, "\\");
 | 
|---|
| 62 |     }
 | 
|---|
| 63 |     else {
 | 
|---|
| 64 |       *temp = *directory;
 | 
|---|
| 65 |       temp[1] = ':';
 | 
|---|
| 66 |       temp[2] = 0;
 | 
|---|
| 67 |     }
 | 
|---|
| 68 |     strcat(temp, name);
 | 
|---|
| 69 |     strcpy(name, temp);
 | 
|---|
| 70 |   }
 | 
|---|
| 71 |   MakeFullName(name);
 | 
|---|
| 72 | }
 | 
|---|
| 73 | 
 | 
|---|
| 74 | static VOID parse(CHAR * command, CHAR * key, CHAR * rest)
 | 
|---|
| 75 | {
 | 
|---|
| 76 | 
 | 
|---|
| 77 |   CHAR *p;
 | 
|---|
| 78 | 
 | 
|---|
| 79 |   *key = *rest = 0;
 | 
|---|
| 80 |   strcpy(key, command);
 | 
|---|
| 81 |   p = strchr(key, ' ');
 | 
|---|
| 82 |   if (p) {
 | 
|---|
| 83 |     *p = 0;
 | 
|---|
| 84 |     p++;
 | 
|---|
| 85 |     p = skip_delim(p, " \t");
 | 
|---|
| 86 |     strcpy(rest, p);
 | 
|---|
| 87 |   }
 | 
|---|
| 88 | }
 | 
|---|
| 89 | 
 | 
|---|
| 90 | BOOL FM2Command(CHAR * directory, CHAR * command)
 | 
|---|
| 91 | {
 | 
|---|
| 92 | 
 | 
|---|
| 93 |   BOOL ret = FALSE;
 | 
|---|
| 94 |   CHAR key[CCHMAXPATH], rest[CCHMAXPATH];
 | 
|---|
| 95 |   HWND hwnd;
 | 
|---|
| 96 | 
 | 
|---|
| 97 |   if (command && *command == '/') {
 | 
|---|
| 98 |     parse(command, key, rest);
 | 
|---|
| 99 |     if (!stricmp(key, GetPString(IDS_OPENCMDTEXT))) {
 | 
|---|
| 100 |       fullname(directory, rest);
 | 
|---|
| 101 |       WinSendMsg(hwndTree, UM_OPENWINDOWFORME, MPFROMP(rest), MPVOID);
 | 
|---|
| 102 |       ret = TRUE;
 | 
|---|
| 103 |     }
 | 
|---|
| 104 |     else if (!stricmp(key, GetPString(IDS_CLOSECMDTEXT))) {
 | 
|---|
| 105 |       fullname(directory, rest);
 | 
|---|
| 106 |       hwnd = FindDirCnrByName(rest, FALSE);
 | 
|---|
| 107 |       if (hwnd)
 | 
|---|
| 108 |         PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
 | 
|---|
| 109 |       ret = TRUE;
 | 
|---|
| 110 |     }
 | 
|---|
| 111 |     else if (!stricmp(key, GetPString(IDS_HELPCMDTEXT))) {
 | 
|---|
| 112 |       saymsg(MB_ENTER, (hwndMain) ? hwndMain : HWND_DESKTOP,
 | 
|---|
| 113 |              GetPString(IDS_FM2CMDHELPHDRTEXT), GetPString(IDS_FM2CMDHELPTEXT));
 | 
|---|
| 114 |       ret = TRUE;
 | 
|---|
| 115 |     }
 | 
|---|
| 116 |     else if (!stricmp(key, GetPString(IDS_FILTERCMDTEXT))) {
 | 
|---|
| 117 |       hwnd = FindDirCnrByName(directory, FALSE);
 | 
|---|
| 118 |       if (hwnd) {
 | 
|---|
| 119 |         WinSendMsg(hwnd, UM_FILTER, MPFROMP(rest), MPVOID);
 | 
|---|
| 120 |         ret = TRUE;
 | 
|---|
| 121 |       }
 | 
|---|
| 122 |     }
 | 
|---|
| 123 |     else if (!stricmp(key, GetPString(IDS_KEEPCMDTEXT)) ||
 | 
|---|
| 124 |              !stricmp(key, GetPString(IDS_NOKEEPCMDTEXT))) {
 | 
|---|
| 125 |       if (!stricmp(key, GetPString(IDS_NOKEEPCMDTEXT)))
 | 
|---|
| 126 |         fKeepCmdLine = FALSE;
 | 
|---|
| 127 |       else
 | 
|---|
| 128 |         fKeepCmdLine = TRUE;
 | 
|---|
| 129 |       PrfWriteProfileData(fmprof, FM3Str, "KeepCmdLine", &fKeepCmdLine,
 | 
|---|
| 130 |                           sizeof(BOOL));
 | 
|---|
| 131 |       ret = TRUE;
 | 
|---|
| 132 |     }
 | 
|---|
| 133 |     else if (!stricmp(key, GetPString(IDS_SAVECMDTEXT)) ||
 | 
|---|
| 134 |              !stricmp(key, GetPString(IDS_NOSAVECMDTEXT))) {
 | 
|---|
| 135 |       if (!stricmp(key, GetPString(IDS_NOSAVECMDTEXT)))
 | 
|---|
| 136 |         fSaveMiniCmds = FALSE;
 | 
|---|
| 137 |       else
 | 
|---|
| 138 |         fSaveMiniCmds = TRUE;
 | 
|---|
| 139 |       PrfWriteProfileData(fmprof, FM3Str, "SaveMiniCmds", &fSaveMiniCmds,
 | 
|---|
| 140 |                           sizeof(BOOL));
 | 
|---|
| 141 |       ret = TRUE;
 | 
|---|
| 142 |     }
 | 
|---|
| 143 |   }
 | 
|---|
| 144 |   return ret;
 | 
|---|
| 145 | }
 | 
|---|
| 146 | 
 | 
|---|
| 147 | #pragma alloc_text(FM2CMD,FM2Command,fullname,parse)
 | 
|---|