| 1 |
|
|---|
| 2 | /***********************************************************************
|
|---|
| 3 |
|
|---|
| 4 | $Id: command.c 1673 2012-12-30 18:51:01Z gyoung $
|
|---|
| 5 |
|
|---|
| 6 | Custom commands
|
|---|
| 7 |
|
|---|
| 8 | Copyright (c) 1993-98 M. Kimes
|
|---|
| 9 | Copyright (c) 2004, 2010 Steven H. Levine
|
|---|
| 10 |
|
|---|
| 11 | 01 Aug 04 SHL Rework lstrip/rstrip usage
|
|---|
| 12 | 06 Jun 05 SHL Drop unused code
|
|---|
| 13 | 14 Jul 06 SHL Use Runtime_Error
|
|---|
| 14 | 29 Jul 06 SHL Use xfgets_bstripcr
|
|---|
| 15 | 15 Aug 06 SHL Better can't add message
|
|---|
| 16 | 18 Sep 06 GKY Add replace command and update okay to add if changed
|
|---|
| 17 | 17 Feb 07 GKY Move error messages etc to string file
|
|---|
| 18 | 22 Mar 07 GKY Use QWL_USER
|
|---|
| 19 | 23 Mar 07 GKY Replace doesn't change item position
|
|---|
| 20 | 23 Mar 07 GKY Okay fails silently when item not changed
|
|---|
| 21 | 19 Apr 07 SHL Sync with AcceptOneDrop GetOneDrop mods
|
|---|
| 22 | 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
|
|---|
| 23 | 06 Jan 08 GKY Use NormalizeCmdLine to check program strings on entry
|
|---|
| 24 | 29 Feb 08 GKY Changes to enable user settable command line length
|
|---|
| 25 | 29 Feb 08 GKY Use xfree where appropriate
|
|---|
| 26 | 18 Jul 08 SHL Add Fortify support
|
|---|
| 27 | 19 Jul 08 GKY Replace save_dir2(dir) with pFM2SaveDirectory and use BldFullPathName
|
|---|
| 28 | 24 Aug 08 GKY Warn full drive on save of .DAT file; prevent loss of existing file
|
|---|
| 29 | 15 Oct 08 GKY Prevent asking to add %a on NormalizeCmdLine abort
|
|---|
| 30 | 21 Dec 09 GKY Fix the environment so it can be saved, deleted and used consistently.
|
|---|
| 31 | 21 Dec 09 GKY Allow command menu reorder without changing the "ID" or hot key for a command.
|
|---|
| 32 | Added load_inicommand to load the IDs from the ini file.
|
|---|
| 33 | 21 Dec 09 GKY Added 20 new hot keys for commands.
|
|---|
| 34 | 21 Dec 09 GKY Added CheckExecutibleFlags to streamline code in command.c assoc.c & cmdline.c
|
|---|
| 35 | 27 Dec 09 GKY Moved Commands to the INI file this makes commands.dat obsolete
|
|---|
| 36 | 27 Dec 09 GKY Added QueryCommandSettings to streamline code
|
|---|
| 37 | 27 Dec 09 GKY Made command hotkeys user selectable.
|
|---|
| 38 | 17 JAN 10 GKY Changes to get working with Watcom 1.9 Beta (1/16/10).
|
|---|
| 39 | Mostly cast CHAR CONSTANT * as CHAR *.
|
|---|
| 40 | 01 May 10 GKY Add ENVIRONMENT_SIZE variable to standardize this size everywhere.
|
|---|
| 41 | 01 May 10 GKY Changes to move environment storage to INI file
|
|---|
| 42 | 03 Jul 11 GKY Fixed problem with creation of duplicate command IDs.
|
|---|
| 43 | 24 Sep 11 GKY Fixed trap caused by selecting cancel from duplicate hotkey dialog if adding or replacing a command
|
|---|
| 44 |
|
|---|
| 45 | ***********************************************************************/
|
|---|
| 46 |
|
|---|
| 47 | #include <stdlib.h>
|
|---|
| 48 | #include <string.h>
|
|---|
| 49 | #include <share.h>
|
|---|
| 50 |
|
|---|
| 51 | #define INCL_DOS
|
|---|
| 52 | #define INCL_WIN
|
|---|
| 53 | #define INCL_LONGLONG // dircnrs.h
|
|---|
| 54 |
|
|---|
| 55 | #include "fm3dll.h"
|
|---|
| 56 | #include "fm3dll2.h" // #define's for UM_*, control id's, etc.
|
|---|
| 57 | #include "notebook.h" // Data declaration(s)
|
|---|
| 58 | #include "init.h" // Data declaration(s)
|
|---|
| 59 | #include "mainwnd.h" // Data declaration(s)
|
|---|
| 60 | #include "newview.h" // Data declarations
|
|---|
| 61 | #include "fm3dlg.h"
|
|---|
| 62 | #include "fm3str.h"
|
|---|
| 63 | #include "tools.h"
|
|---|
| 64 | #include "arccnrs.h" // BldQuotedFileName
|
|---|
| 65 | #include "errutil.h" // Dos_Error...
|
|---|
| 66 | #include "strutil.h" // GetPString
|
|---|
| 67 | #include "droplist.h" // AcceptOneDrop, DropHelp, GetOneDrop
|
|---|
| 68 | #include "misc.h" // DrawTargetEmphasis
|
|---|
| 69 | #include "systemf.h" // ExecOnList
|
|---|
| 70 | #include "getnames.h" // insert_filename
|
|---|
| 71 | #include "wrappers.h" // xfgets
|
|---|
| 72 | #include "pathutil.h" // NormalizeCmdLine
|
|---|
| 73 | #include "command.h"
|
|---|
| 74 | #include "strips.h" // bstrip
|
|---|
| 75 | #include "dirs.h" // save_dir2
|
|---|
| 76 | #include "fortify.h"
|
|---|
| 77 |
|
|---|
| 78 | VOID load_inicommands(VOID);
|
|---|
| 79 |
|
|---|
| 80 | typedef struct
|
|---|
| 81 | {
|
|---|
| 82 | PSZ pszCmdLine;
|
|---|
| 83 | CHAR title[100];
|
|---|
| 84 | CHAR env[ENVIRONMENT_SIZE];
|
|---|
| 85 | ULONG flags;
|
|---|
| 86 | ULONG ID;
|
|---|
| 87 | ULONG HotKeyID;
|
|---|
| 88 | }
|
|---|
| 89 | COMMAND;
|
|---|
| 90 |
|
|---|
| 91 | BOOL QueryCommandSettings(HWND hwnd, COMMAND *temp);
|
|---|
| 92 | VOID save_commands(VOID);
|
|---|
| 93 |
|
|---|
| 94 | // Data defintions
|
|---|
| 95 | #pragma data_seg(DATA1)
|
|---|
| 96 |
|
|---|
| 97 | static PSZ pszSrcFile = __FILE__;
|
|---|
| 98 | static LINKCMDS *cmdtail;
|
|---|
| 99 | static BOOL UsedCommandIDs[300] = {FALSE};
|
|---|
| 100 | static BOOL UsedHotKeyIDs[40] = {FALSE};
|
|---|
| 101 | static PSZ pszCommandsList;
|
|---|
| 102 | static ULONG ulSizeCommandsList = 10000;
|
|---|
| 103 | static BOOL fLoadCommandsFromINI = FALSE;
|
|---|
| 104 |
|
|---|
| 105 | #pragma data_seg(GLOBAL2)
|
|---|
| 106 | LINKCMDS *cmdhead;
|
|---|
| 107 | BOOL cmdloaded;
|
|---|
| 108 |
|
|---|
| 109 | MRESULT EXPENTRY CommandTextProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
|---|
| 110 | {
|
|---|
| 111 | PFNWP oldproc = (PFNWP) WinQueryWindowPtr(hwnd, QWL_USER);
|
|---|
| 112 | static BOOL emphasized = FALSE;
|
|---|
| 113 |
|
|---|
| 114 | switch (msg) {
|
|---|
| 115 | case DM_DRAGOVER:
|
|---|
| 116 | if (!emphasized) {
|
|---|
| 117 | emphasized = TRUE;
|
|---|
| 118 | DrawTargetEmphasis(hwnd, emphasized);
|
|---|
| 119 | }
|
|---|
| 120 | if (AcceptOneDrop(hwnd, mp1, mp2))
|
|---|
| 121 | return MRFROM2SHORT(DOR_DROP, DO_MOVE);
|
|---|
| 122 | return MRFROM2SHORT(DOR_NEVERDROP, 0);
|
|---|
| 123 |
|
|---|
| 124 | case DM_DRAGLEAVE:
|
|---|
| 125 | if (emphasized) {
|
|---|
| 126 | emphasized = FALSE;
|
|---|
| 127 | DrawTargetEmphasis(hwnd, emphasized);
|
|---|
| 128 | }
|
|---|
| 129 | break;
|
|---|
| 130 |
|
|---|
| 131 | case DM_DROPHELP:
|
|---|
| 132 | DropHelp(mp1, mp2, hwnd, GetPString(IDS_DROPCMDHELPTEXT));
|
|---|
| 133 | return 0;
|
|---|
| 134 |
|
|---|
| 135 | case DM_DROP:
|
|---|
| 136 | {
|
|---|
| 137 | char szFrom[CCHMAXPATH + 5];
|
|---|
| 138 |
|
|---|
| 139 | if (emphasized) {
|
|---|
| 140 | emphasized = FALSE;
|
|---|
| 141 | DrawTargetEmphasis(hwnd, emphasized);
|
|---|
| 142 | }
|
|---|
| 143 | if (GetOneDrop(hwnd, mp1, mp2, szFrom, CCHMAXPATH)) {
|
|---|
| 144 | strcat(szFrom, " %a");
|
|---|
| 145 | WinSetWindowText(hwnd, szFrom);
|
|---|
| 146 | }
|
|---|
| 147 | }
|
|---|
| 148 | return 0;
|
|---|
| 149 | }
|
|---|
| 150 | return (oldproc) ? oldproc(hwnd, msg, mp1, mp2) :
|
|---|
| 151 | WinDefWindowProc(hwnd, msg, mp1, mp2);
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | MRESULT EXPENTRY ReOrderProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
|---|
| 155 | {
|
|---|
| 156 | switch (msg) {
|
|---|
| 157 | case WM_INITDLG:
|
|---|
| 158 | if (!cmdhead) {
|
|---|
| 159 | WinDismissDlg(hwnd, 0);
|
|---|
| 160 | break;
|
|---|
| 161 | }
|
|---|
| 162 | {
|
|---|
| 163 | LINKCMDS *info;
|
|---|
| 164 | SHORT x;
|
|---|
| 165 |
|
|---|
| 166 | info = cmdhead;
|
|---|
| 167 | while (info) {
|
|---|
| 168 | x = (SHORT) WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX, LM_INSERTITEM,
|
|---|
| 169 | MPFROMSHORT(LIT_END),
|
|---|
| 170 | MPFROMP(info->title));
|
|---|
| 171 | if (x < 0) {
|
|---|
| 172 | Runtime_Error(pszSrcFile, __LINE__, "no cmd");
|
|---|
| 173 | WinDismissDlg(hwnd, 0);
|
|---|
| 174 | }
|
|---|
| 175 | else {
|
|---|
| 176 | WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX, LM_SETITEMHANDLE,
|
|---|
| 177 | MPFROMSHORT(x), MPFROMP(info));
|
|---|
| 178 | }
|
|---|
| 179 | info = info->next;
|
|---|
| 180 | }
|
|---|
| 181 | }
|
|---|
| 182 | break;
|
|---|
| 183 |
|
|---|
| 184 | case WM_CONTROL:
|
|---|
| 185 | return 0;
|
|---|
| 186 |
|
|---|
| 187 | case WM_COMMAND:
|
|---|
| 188 | switch (SHORT1FROMMP(mp1)) {
|
|---|
| 189 | case DID_CANCEL:
|
|---|
| 190 | WinDismissDlg(hwnd, 0);
|
|---|
| 191 | break;
|
|---|
| 192 |
|
|---|
| 193 | case DID_OK:
|
|---|
| 194 | {
|
|---|
| 195 | LINKCMDS *temphead = NULL, *info, *last = NULL, *temptail = NULL;
|
|---|
| 196 | SHORT sSelect, numitems;
|
|---|
| 197 |
|
|---|
| 198 | sSelect = 0;
|
|---|
| 199 | numitems = (SHORT) WinSendDlgItemMsg(hwnd, RE_REMOVELISTBOX,
|
|---|
| 200 | LM_QUERYITEMCOUNT,
|
|---|
| 201 | MPVOID, MPVOID);
|
|---|
| 202 | while (numitems) {
|
|---|
| 203 | info = (LINKCMDS *) WinSendDlgItemMsg(hwnd, RE_REMOVELISTBOX,
|
|---|
| 204 | LM_QUERYITEMHANDLE,
|
|---|
| 205 | MPFROMSHORT(sSelect++),
|
|---|
| 206 | MPVOID);
|
|---|
| 207 | if (info) {
|
|---|
| 208 | if (!temphead) {
|
|---|
| 209 | temphead = info;
|
|---|
| 210 | info->prev = NULL;
|
|---|
| 211 | }
|
|---|
| 212 | else {
|
|---|
| 213 | last->next = info;
|
|---|
| 214 | info->prev = last;
|
|---|
| 215 | }
|
|---|
| 216 | temptail = info;
|
|---|
| 217 | last = info;
|
|---|
| 218 | info->next = NULL;
|
|---|
| 219 | }
|
|---|
| 220 | numitems--;
|
|---|
| 221 | }
|
|---|
| 222 | sSelect = 0;
|
|---|
| 223 | numitems = (SHORT) WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX,
|
|---|
| 224 | LM_QUERYITEMCOUNT,
|
|---|
| 225 | MPVOID, MPVOID);
|
|---|
| 226 | while (numitems) {
|
|---|
| 227 | info = (LINKCMDS *) WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX,
|
|---|
| 228 | LM_QUERYITEMHANDLE,
|
|---|
| 229 | MPFROMSHORT(sSelect++),
|
|---|
| 230 | MPVOID);
|
|---|
| 231 | if (info) {
|
|---|
| 232 | if (!temphead) {
|
|---|
| 233 | temphead = info;
|
|---|
| 234 | info->prev = NULL;
|
|---|
| 235 | }
|
|---|
| 236 | else {
|
|---|
| 237 | last->next = info;
|
|---|
| 238 | info->prev = last;
|
|---|
| 239 | }
|
|---|
| 240 | temptail = info;
|
|---|
| 241 | last = info;
|
|---|
| 242 | info->next = NULL;
|
|---|
| 243 | }
|
|---|
| 244 | numitems--;
|
|---|
| 245 | }
|
|---|
| 246 | cmdhead = temphead;
|
|---|
| 247 | cmdtail = temptail;
|
|---|
| 248 | }
|
|---|
| 249 | WinDismissDlg(hwnd, 1);
|
|---|
| 250 | break;
|
|---|
| 251 |
|
|---|
| 252 | case IDM_HELP:
|
|---|
| 253 | if (hwndHelp)
|
|---|
| 254 | WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
|
|---|
| 255 | MPFROM2SHORT(HELP_REORDERCOMMANDS, 0),
|
|---|
| 256 | MPFROMSHORT(HM_RESOURCEID));
|
|---|
| 257 | break;
|
|---|
| 258 |
|
|---|
| 259 | case RE_ADD:
|
|---|
| 260 | {
|
|---|
| 261 | SHORT sSelect, x;
|
|---|
| 262 | LINKCMDS *info;
|
|---|
| 263 |
|
|---|
| 264 | sSelect = (SHORT) WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX,
|
|---|
| 265 | LM_QUERYSELECTION,
|
|---|
| 266 | MPFROMSHORT(LIT_FIRST), MPVOID);
|
|---|
| 267 | while (sSelect >= 0) {
|
|---|
| 268 | info = (LINKCMDS *) WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX,
|
|---|
| 269 | LM_QUERYITEMHANDLE,
|
|---|
| 270 | MPFROMSHORT(sSelect), MPVOID);
|
|---|
| 271 | if (info) {
|
|---|
| 272 | x = (SHORT) WinSendDlgItemMsg(hwnd, RE_REMOVELISTBOX,
|
|---|
| 273 | LM_INSERTITEM,
|
|---|
| 274 | MPFROM2SHORT(LIT_END, 0),
|
|---|
| 275 | MPFROMP(info->title));
|
|---|
| 276 | if (x >= 0) {
|
|---|
| 277 | WinSendDlgItemMsg(hwnd, RE_REMOVELISTBOX,
|
|---|
| 278 | LM_SETITEMHANDLE,
|
|---|
| 279 | MPFROMSHORT(x), MPFROMP(info));
|
|---|
| 280 | WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX, LM_DELETEITEM,
|
|---|
| 281 | MPFROMSHORT(sSelect), MPVOID);
|
|---|
| 282 | }
|
|---|
| 283 | }
|
|---|
| 284 | else
|
|---|
| 285 | WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX, LM_SELECTITEM,
|
|---|
| 286 | MPFROMSHORT(sSelect), MPFROMSHORT(FALSE));
|
|---|
| 287 | sSelect = (USHORT) WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX,
|
|---|
| 288 | LM_QUERYSELECTION,
|
|---|
| 289 | MPFROMSHORT(LIT_FIRST),
|
|---|
| 290 | MPVOID);
|
|---|
| 291 | }
|
|---|
| 292 | }
|
|---|
| 293 | break;
|
|---|
| 294 |
|
|---|
| 295 | case RE_REMOVE:
|
|---|
| 296 | {
|
|---|
| 297 | SHORT sSelect, x;
|
|---|
| 298 | LINKCMDS *info;
|
|---|
| 299 |
|
|---|
| 300 | sSelect = (SHORT) WinSendDlgItemMsg(hwnd, RE_REMOVELISTBOX,
|
|---|
| 301 | LM_QUERYSELECTION,
|
|---|
| 302 | MPFROMSHORT(LIT_FIRST), MPVOID);
|
|---|
| 303 | while (sSelect >= 0) {
|
|---|
| 304 | info = (LINKCMDS *) WinSendDlgItemMsg(hwnd, RE_REMOVELISTBOX,
|
|---|
| 305 | LM_QUERYITEMHANDLE,
|
|---|
| 306 | MPFROMSHORT(sSelect), MPVOID);
|
|---|
| 307 | if (info) {
|
|---|
| 308 | x = (SHORT) WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX,
|
|---|
| 309 | LM_INSERTITEM,
|
|---|
| 310 | MPFROM2SHORT(LIT_END, 0),
|
|---|
| 311 | MPFROMP(info->title));
|
|---|
| 312 | if (x >= 0) {
|
|---|
| 313 | WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX,
|
|---|
| 314 | LM_SETITEMHANDLE,
|
|---|
| 315 | MPFROMSHORT(x), MPFROMP(info));
|
|---|
| 316 | WinSendDlgItemMsg(hwnd, RE_REMOVELISTBOX, LM_DELETEITEM,
|
|---|
| 317 | MPFROMSHORT(sSelect), MPVOID);
|
|---|
| 318 | }
|
|---|
| 319 | }
|
|---|
| 320 | else
|
|---|
| 321 | WinSendDlgItemMsg(hwnd, RE_REMOVELISTBOX, LM_SELECTITEM,
|
|---|
| 322 | MPFROMSHORT(sSelect), MPFROMSHORT(FALSE));
|
|---|
| 323 | sSelect = (USHORT) WinSendDlgItemMsg(hwnd, RE_REMOVELISTBOX,
|
|---|
| 324 | LM_QUERYSELECTION,
|
|---|
| 325 | MPFROMSHORT(LIT_FIRST),
|
|---|
| 326 | MPVOID);
|
|---|
| 327 | }
|
|---|
| 328 | }
|
|---|
| 329 | break;
|
|---|
| 330 | }
|
|---|
| 331 | return 0;
|
|---|
| 332 | }
|
|---|
| 333 | return WinDefDlgProc(hwnd, msg, mp1, mp2);
|
|---|
| 334 | }
|
|---|
| 335 |
|
|---|
| 336 | CHAR *command_title(INT cx)
|
|---|
| 337 | {
|
|---|
| 338 | static CHAR duh[] = "???";
|
|---|
| 339 | LINKCMDS *info;
|
|---|
| 340 | INT x = 0;
|
|---|
| 341 |
|
|---|
| 342 | if (!cmdloaded)
|
|---|
| 343 | load_commands();
|
|---|
| 344 | info = cmdhead;
|
|---|
| 345 | while (info) {
|
|---|
| 346 | if (x == cx)
|
|---|
| 347 | return info->title;
|
|---|
| 348 | info = info->next;
|
|---|
| 349 | }
|
|---|
| 350 | return duh;
|
|---|
| 351 | }
|
|---|
| 352 |
|
|---|
| 353 | VOID free_commands(VOID)
|
|---|
| 354 | {
|
|---|
| 355 | LINKCMDS *info, *next;
|
|---|
| 356 |
|
|---|
| 357 | info = cmdhead;
|
|---|
| 358 | while (info) {
|
|---|
| 359 | next = info->next;
|
|---|
| 360 | xfree(info->title, pszSrcFile, __LINE__);
|
|---|
| 361 | xfree(info->pszCmdLine, pszSrcFile, __LINE__);
|
|---|
| 362 | xfree(info->env, pszSrcFile, __LINE__);
|
|---|
| 363 | free(info);
|
|---|
| 364 | info = next;
|
|---|
| 365 | }
|
|---|
| 366 | free(pszCommandsList);
|
|---|
| 367 | cmdhead = cmdtail = NULL;
|
|---|
| 368 | }
|
|---|
| 369 |
|
|---|
| 370 | VOID load_commands(VOID)
|
|---|
| 371 | {
|
|---|
| 372 | FILE *fp;
|
|---|
| 373 | LINKCMDS *info;
|
|---|
| 374 | PSZ pszCmdLine;
|
|---|
| 375 | CHAR title[100];
|
|---|
| 376 | CHAR flags[34];
|
|---|
| 377 | CHAR *moder = "r";
|
|---|
| 378 | ULONG size;
|
|---|
| 379 |
|
|---|
| 380 | size = sizeof(BOOL);
|
|---|
| 381 | PrfQueryProfileData(fmprof, FM3Str, "COMMANDS.LoadCommandsFromINI",
|
|---|
| 382 | &fLoadCommandsFromINI, &size);
|
|---|
| 383 | if (!fLoadCommandsFromINI) {
|
|---|
| 384 | if (cmdhead)
|
|---|
| 385 | free_commands();
|
|---|
| 386 | cmdloaded = TRUE;
|
|---|
| 387 | pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
|
|---|
| 388 | pszCommandsList = xmallocz(ulSizeCommandsList, pszSrcFile, __LINE__);
|
|---|
| 389 | if (pszCmdLine) {
|
|---|
| 390 | BldFullPathName(pszCmdLine, pFM2SaveDirectory, PCSZ_COMMANDSDAT);
|
|---|
| 391 | fp = xfsopen(pszCmdLine, moder, SH_DENYWR, pszSrcFile, __LINE__, TRUE);
|
|---|
| 392 | if (fp) {
|
|---|
| 393 | while (!feof(fp)) {
|
|---|
| 394 | if (!xfgets_bstripcr(title, sizeof(title), fp, pszSrcFile, __LINE__))
|
|---|
| 395 | break;
|
|---|
| 396 | if (!*title || *title == ';')
|
|---|
| 397 | continue;
|
|---|
| 398 | if (!xfgets_bstripcr(pszCmdLine, MaxComLineStrg, fp, pszSrcFile, __LINE__))
|
|---|
| 399 | break; // error!
|
|---|
| 400 | if (!xfgets_bstripcr(flags, sizeof(flags), fp, pszSrcFile, __LINE__))
|
|---|
| 401 | break;
|
|---|
| 402 | flags[34] = 0;
|
|---|
| 403 | if (!pszCmdLine)
|
|---|
| 404 | continue;
|
|---|
| 405 | info = xmallocz(sizeof(LINKCMDS), pszSrcFile, __LINE__);
|
|---|
| 406 | if (info) {
|
|---|
| 407 | # ifdef FORTIFY
|
|---|
| 408 | Fortify_SetOwner(info, 1);
|
|---|
| 409 | Fortify_SetScope(info, 1);
|
|---|
| 410 | # endif
|
|---|
| 411 | info->pszCmdLine = xstrdup(pszCmdLine, pszSrcFile, __LINE__);
|
|---|
| 412 |
|
|---|
| 413 | if (pszCommandsList) {
|
|---|
| 414 | strcpy(pszCommandsList + strlen(pszCommandsList), title);
|
|---|
| 415 | strcpy(pszCommandsList + strlen(pszCommandsList), ";");
|
|---|
| 416 | }
|
|---|
| 417 | info->title = xstrdup(title, pszSrcFile, __LINE__);
|
|---|
| 418 | info->flags = atol(flags);
|
|---|
| 419 | if (!info->pszCmdLine || !info->title) {
|
|---|
| 420 | xfree(info->pszCmdLine, pszSrcFile, __LINE__);
|
|---|
| 421 | xfree(info->title, pszSrcFile, __LINE__);
|
|---|
| 422 | free(info);
|
|---|
| 423 | break;
|
|---|
| 424 | }
|
|---|
| 425 | # ifdef FORTIFY
|
|---|
| 426 | Fortify_SetOwner(info->pszCmdLine, 1);
|
|---|
| 427 | Fortify_SetScope(info->pszCmdLine, 1);
|
|---|
| 428 | Fortify_SetOwner(info->title, 1);
|
|---|
| 429 | Fortify_SetScope(info->title, 1);
|
|---|
| 430 | # endif
|
|---|
| 431 | if (!cmdhead)
|
|---|
| 432 | cmdhead = info;
|
|---|
| 433 | else {
|
|---|
| 434 | cmdtail->next = info;
|
|---|
| 435 | info->prev = cmdtail;
|
|---|
| 436 | }
|
|---|
| 437 | cmdtail = info;
|
|---|
| 438 | }
|
|---|
| 439 | }
|
|---|
| 440 | free(pszCmdLine);
|
|---|
| 441 | fclose(fp);
|
|---|
| 442 | if (pszCommandsList) {
|
|---|
| 443 | ulSizeCommandsList = strlen(pszCommandsList) + 1;
|
|---|
| 444 | }
|
|---|
| 445 | }
|
|---|
| 446 | }
|
|---|
| 447 | }
|
|---|
| 448 | load_inicommands();
|
|---|
| 449 | }
|
|---|
| 450 |
|
|---|
| 451 | /**
|
|---|
| 452 | * load_inicommand loads the data from the ini file into an info struct
|
|---|
| 453 | * after COMMANDS.DAT has been loaded; It generates new IDs where necessary
|
|---|
| 454 | * it saves the environment from the old ini key and deletes it as needed
|
|---|
| 455 | **/
|
|---|
| 456 |
|
|---|
| 457 | VOID load_inicommands(VOID)
|
|---|
| 458 | {
|
|---|
| 459 | LINKCMDS *info;;
|
|---|
| 460 | INT x = 0;
|
|---|
| 461 | INT y = 0;
|
|---|
| 462 | ULONG ID = 0;
|
|---|
| 463 | ULONG HotKeyID = 0;
|
|---|
| 464 | CHAR env[ENVIRONMENT_SIZE];
|
|---|
| 465 | CHAR key[120];
|
|---|
| 466 | CHAR szTitle[100];
|
|---|
| 467 | ULONG size;
|
|---|
| 468 | CHAR *p, *pp;
|
|---|
| 469 | PSZ pszCmdLine;
|
|---|
| 470 | ULONG flags;
|
|---|
| 471 |
|
|---|
| 472 | # ifdef FORTIFY
|
|---|
| 473 | Fortify_EnterScope();
|
|---|
| 474 | # endif
|
|---|
| 475 | pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
|
|---|
| 476 | if (pszCmdLine) {
|
|---|
| 477 | if (fLoadCommandsFromINI) {
|
|---|
| 478 | if (cmdhead)
|
|---|
| 479 | free_commands();
|
|---|
| 480 | cmdloaded = TRUE;
|
|---|
| 481 | size = sizeof(ULONG);
|
|---|
| 482 | PrfQueryProfileData(fmprof, FM3Str, "COMMANDS.SizeSortOrder",
|
|---|
| 483 | &ulSizeCommandsList, &size);
|
|---|
| 484 | pszCommandsList = xmallocz(ulSizeCommandsList, pszSrcFile, __LINE__);
|
|---|
| 485 | if (pszCommandsList) {
|
|---|
| 486 | PrfQueryProfileString(fmprof, FM3Str, "COMMANDS.SortOrder",
|
|---|
| 487 | NullStr, pszCommandsList, ulSizeCommandsList);
|
|---|
| 488 | p = pszCommandsList;
|
|---|
| 489 | while (*p == ';')
|
|---|
| 490 | p++;
|
|---|
| 491 | while (*p) {
|
|---|
| 492 | *szTitle = 0;
|
|---|
| 493 | pp = szTitle;
|
|---|
| 494 | while (*p && *p != ';')
|
|---|
| 495 | *pp++ = *p++;
|
|---|
| 496 | *pp = 0;
|
|---|
| 497 | while (*p == ';')
|
|---|
| 498 | p++;
|
|---|
| 499 | if (*szTitle) {
|
|---|
| 500 | bstripcr(szTitle);
|
|---|
| 501 | sprintf(key, "COMMAND.%sID", szTitle);
|
|---|
| 502 | size = sizeof(ULONG);
|
|---|
| 503 | PrfQueryProfileData(fmprof, FM3Str, key, &ID, &size);
|
|---|
| 504 | UsedCommandIDs[ID - IDM_COMMANDSTART] = TRUE; // No need to use profile just count them GKY 02 JUL 11
|
|---|
| 505 | sprintf(key, "COMMAND.%sHotKeyID", szTitle);
|
|---|
| 506 | size = sizeof(ULONG);
|
|---|
| 507 | PrfQueryProfileData(fmprof, FM3Str, key, &HotKeyID, &size);
|
|---|
| 508 | UsedHotKeyIDs[HotKeyID - IDM_COMMANDNUM0] = TRUE; // No need to use profile just count them GKY 02 JUL 11
|
|---|
| 509 | sprintf(key, "COMMAND.%sflags", szTitle);
|
|---|
| 510 | size = sizeof(ULONG);
|
|---|
| 511 | PrfQueryProfileData(fmprof, FM3Str, key, &flags, &size);
|
|---|
| 512 | sprintf(key, "COMMAND.%senv", szTitle);
|
|---|
| 513 | PrfQueryProfileString(fmprof, FM3Str, key, NullStr, env, sizeof(env));
|
|---|
| 514 | sprintf(key, "COMMAND.%sCmdLine", szTitle);
|
|---|
| 515 | PrfQueryProfileString(fmprof, FM3Str, key, NullStr, pszCmdLine, MaxComLineStrg);
|
|---|
| 516 | }
|
|---|
| 517 | info = xmallocz(sizeof(LINKCMDS), pszSrcFile, __LINE__);
|
|---|
| 518 | if (info) {
|
|---|
| 519 | # ifdef FORTIFY
|
|---|
| 520 | Fortify_SetOwner(info, 1);
|
|---|
| 521 | Fortify_SetScope(info, 1);
|
|---|
| 522 | # endif
|
|---|
| 523 | info->pszCmdLine = xstrdup(pszCmdLine, pszSrcFile, __LINE__);
|
|---|
| 524 | info->title = xstrdup(szTitle, pszSrcFile, __LINE__);
|
|---|
| 525 | info->flags = flags;
|
|---|
| 526 | if (env != NullStr)
|
|---|
| 527 | info->env = xstrdup(env, pszSrcFile, __LINE__);
|
|---|
| 528 | info->ID = ID;
|
|---|
| 529 | info->HotKeyID = HotKeyID;
|
|---|
| 530 | if (!info->pszCmdLine || !info->title) {
|
|---|
| 531 | xfree(info->pszCmdLine, pszSrcFile, __LINE__);
|
|---|
| 532 | xfree(info->title, pszSrcFile, __LINE__);
|
|---|
| 533 | xfree(info->env, pszSrcFile, __LINE__);
|
|---|
| 534 | free(info);
|
|---|
| 535 | break;
|
|---|
| 536 | }
|
|---|
| 537 | if (!cmdhead)
|
|---|
| 538 | cmdhead = info;
|
|---|
| 539 | else {
|
|---|
| 540 | cmdtail->next = info;
|
|---|
| 541 | info->prev = cmdtail;
|
|---|
| 542 | }
|
|---|
| 543 | cmdtail = info;
|
|---|
| 544 | }
|
|---|
| 545 | }
|
|---|
| 546 | }
|
|---|
| 547 | }
|
|---|
| 548 | else {
|
|---|
| 549 | info = cmdhead;
|
|---|
| 550 | while (info) {
|
|---|
| 551 | bstripcr(info->title);
|
|---|
| 552 | sprintf(key, "COMMAND.%sID", info->title);
|
|---|
| 553 | size = sizeof(ULONG);
|
|---|
| 554 | PrfQueryProfileData(fmprof, FM3Str, key, &ID, &size);
|
|---|
| 555 | sprintf(key, "COMMAND.%sHotKeyID", info->title);
|
|---|
| 556 | size = sizeof(ULONG);
|
|---|
| 557 | PrfQueryProfileData(fmprof, FM3Str, key, &HotKeyID, &size);
|
|---|
| 558 | sprintf(key, "COMMAND.%senv", info->title);
|
|---|
| 559 | PrfQueryProfileString(fmprof, FM3Str, key, NullStr, env, sizeof(env));
|
|---|
| 560 | if (ID != 0) {
|
|---|
| 561 | if (env != NullStr)
|
|---|
| 562 | info->env = xstrdup(env, pszSrcFile, __LINE__);
|
|---|
| 563 | info->ID = ID;
|
|---|
| 564 | info->HotKeyID = HotKeyID;
|
|---|
| 565 | }
|
|---|
| 566 | //This updates the old commands.dat file to the new format
|
|---|
| 567 | //assigning the IDs based on file order or on next available ID
|
|---|
| 568 | else {
|
|---|
| 569 | for (x = 0; x < 300; x++) {
|
|---|
| 570 | if (!UsedCommandIDs[x]) {
|
|---|
| 571 | ID = info->ID = IDM_COMMANDSTART + x;
|
|---|
| 572 | UsedCommandIDs[x] = TRUE;
|
|---|
| 573 | for (y = 0; y < 40; y++) {
|
|---|
| 574 | if (!UsedHotKeyIDs[y]) {
|
|---|
| 575 | HotKeyID = info->HotKeyID = IDM_COMMANDNUM0 + y;
|
|---|
| 576 | UsedHotKeyIDs[y] = TRUE;
|
|---|
| 577 | break;
|
|---|
| 578 | }
|
|---|
| 579 | }
|
|---|
| 580 | break;
|
|---|
| 581 | }
|
|---|
| 582 | if (x == 299)
|
|---|
| 583 | saymsg(MB_OK | MB_ICONEXCLAMATION , HWND_DESKTOP,
|
|---|
| 584 | GetPString(IDS_COMMANDSLIMITTITLETEXT),
|
|---|
| 585 | GetPString(IDS_COMMANDSLIMITREACHEDTEXT ));
|
|---|
| 586 | }
|
|---|
| 587 | PrfQueryProfileString(fmprof, FM3Str, info->pszCmdLine, NullStr, env, sizeof(env));
|
|---|
| 588 | info->env = xstrdup(env, pszSrcFile, __LINE__);
|
|---|
| 589 | }
|
|---|
| 590 | ID = 0;
|
|---|
| 591 | HotKeyID = 0;
|
|---|
| 592 | info = info->next;
|
|---|
| 593 | }
|
|---|
| 594 | fLoadCommandsFromINI = TRUE;
|
|---|
| 595 | save_commands();
|
|---|
| 596 | }
|
|---|
| 597 | free(pszCmdLine);
|
|---|
| 598 | }
|
|---|
| 599 | }
|
|---|
| 600 |
|
|---|
| 601 | VOID save_commands(VOID)
|
|---|
| 602 | {
|
|---|
| 603 | LINKCMDS *info;
|
|---|
| 604 | CHAR key[120];
|
|---|
| 605 |
|
|---|
| 606 | if (!cmdloaded || !cmdhead)
|
|---|
| 607 | return;
|
|---|
| 608 |
|
|---|
| 609 | info = cmdhead;
|
|---|
| 610 | pszCommandsList[0] = 0;
|
|---|
| 611 | while (info) {
|
|---|
| 612 | sprintf(key, "COMMAND.%sflags", info->title);
|
|---|
| 613 | PrfWriteProfileData(fmprof, FM3Str, key, &info->flags, sizeof(ULONG));
|
|---|
| 614 | sprintf(key, "COMMAND.%sCmdLine", info->title);
|
|---|
| 615 | PrfWriteProfileString(fmprof, FM3Str, key, info->pszCmdLine);
|
|---|
| 616 | bstripcr(info->title);
|
|---|
| 617 | sprintf(key, "COMMAND.%sID", info->title);
|
|---|
| 618 | PrfWriteProfileData(fmprof, FM3Str, key, &info->ID, sizeof(INT));
|
|---|
| 619 | UsedCommandIDs[info->ID - IDM_COMMANDSTART] = TRUE;
|
|---|
| 620 | sprintf(key, "COMMAND.%sHotKeyID", info->title);
|
|---|
| 621 | PrfWriteProfileData(fmprof, FM3Str, key, &info->HotKeyID, sizeof(INT));
|
|---|
| 622 | UsedHotKeyIDs[info->HotKeyID - IDM_COMMANDNUM0] = TRUE;
|
|---|
| 623 | if (info->env != NullStr) {
|
|---|
| 624 | sprintf(key, "COMMAND.%senv", info->title);
|
|---|
| 625 | PrfWriteProfileString(fmprof, FM3Str, key, info->env);
|
|---|
| 626 | }
|
|---|
| 627 | if ((strlen(pszCommandsList) + strlen(info->title) + 1) > ulSizeCommandsList)
|
|---|
| 628 | pszCommandsList = xrealloc(pszCommandsList,
|
|---|
| 629 | ulSizeCommandsList + strlen(info->title) + 1,
|
|---|
| 630 | pszSrcFile, __LINE__);
|
|---|
| 631 | strcpy(pszCommandsList + strlen(pszCommandsList), info->title);
|
|---|
| 632 | strcpy(pszCommandsList + strlen(pszCommandsList), ";");
|
|---|
| 633 | info = info->next;
|
|---|
| 634 | } // while info
|
|---|
| 635 | PrfWriteProfileData(fmprof, FM3Str, "COMMANDS.UsedCommandIDs", &UsedCommandIDs,
|
|---|
| 636 | sizeof(BOOL) * 300); // left for backward compatability GKY 02 Jul 11
|
|---|
| 637 | PrfWriteProfileData(fmprof, FM3Str, "COMMANDS.UsedHotKeyIDs", &UsedHotKeyIDs,
|
|---|
| 638 | sizeof(BOOL) * 40);// left for backward compatability GKY 02 Jul 11
|
|---|
| 639 | ulSizeCommandsList = strlen(pszCommandsList) + 1;
|
|---|
| 640 | PrfWriteProfileData(fmprof, FM3Str, "COMMANDS.SizeSortOrder",
|
|---|
| 641 | &ulSizeCommandsList, sizeof(ULONG));
|
|---|
| 642 | PrfWriteProfileString(fmprof, FM3Str, "COMMANDS.SortOrder", pszCommandsList);
|
|---|
| 643 | PrfWriteProfileData(fmprof, FM3Str, "COMMANDS.LoadCommandsFromINI",
|
|---|
| 644 | &fLoadCommandsFromINI, sizeof(BOOL));
|
|---|
| 645 | }
|
|---|
| 646 |
|
|---|
| 647 | //== add_command() Add command to list ==
|
|---|
| 648 |
|
|---|
| 649 | LINKCMDS *add_command(COMMAND *addme, BOOL fDontCheckHotKey)
|
|---|
| 650 | {
|
|---|
| 651 | LINKCMDS *info;
|
|---|
| 652 | INT x;
|
|---|
| 653 | INT y;
|
|---|
| 654 | APIRET ret;
|
|---|
| 655 |
|
|---|
| 656 | if (!addme || !*addme->pszCmdLine || !*addme->title)
|
|---|
| 657 | return NULL; // No data
|
|---|
| 658 | # ifdef FORTIFY
|
|---|
| 659 | Fortify_EnterScope();
|
|---|
| 660 | # endif
|
|---|
| 661 | info = cmdhead;
|
|---|
| 662 | while (info) {
|
|---|
| 663 | if (!stricmp(info->title, addme->title))
|
|---|
| 664 | return NULL; // Got a dup
|
|---|
| 665 | info = info->next;
|
|---|
| 666 | }
|
|---|
| 667 | if (!fDontCheckHotKey && UsedHotKeyIDs[addme->HotKeyID - IDM_COMMANDNUM0]) {
|
|---|
| 668 | info = cmdhead;
|
|---|
| 669 | while (info) {
|
|---|
| 670 | if (info->HotKeyID == addme->HotKeyID) { //avoid assigning hot key to multiple commands
|
|---|
| 671 | ret = saymsg(MB_YESNOCANCEL, HWND_DESKTOP, NullStr,
|
|---|
| 672 | GetPString(IDS_DUPLICATEHOTKEYTEXT));
|
|---|
| 673 | if (ret == MBID_YES) {
|
|---|
| 674 | info->HotKeyID = 0;
|
|---|
| 675 | UsedHotKeyIDs[addme->HotKeyID - IDM_COMMANDNUM0] = FALSE;
|
|---|
| 676 | break;
|
|---|
| 677 | }
|
|---|
| 678 | else if (ret == MBID_NO) {
|
|---|
| 679 | addme->HotKeyID = 0;
|
|---|
| 680 | break;
|
|---|
| 681 | }
|
|---|
| 682 | else
|
|---|
| 683 | return (LINKCMDS *) -1;
|
|---|
| 684 | }
|
|---|
| 685 | info = info->next;
|
|---|
| 686 | }
|
|---|
| 687 | }
|
|---|
| 688 | info = xmallocz(sizeof(LINKCMDS), pszSrcFile, __LINE__);
|
|---|
| 689 | if (!info)
|
|---|
| 690 | return NULL;
|
|---|
| 691 | info->pszCmdLine = xstrdup(addme->pszCmdLine, pszSrcFile, __LINE__);
|
|---|
| 692 | info->title = xstrdup(addme->title, pszSrcFile, __LINE__);
|
|---|
| 693 | info->HotKeyID = addme->HotKeyID;
|
|---|
| 694 | info->ID = addme->ID;
|
|---|
| 695 | if (info->HotKeyID >= IDM_COMMANDNUM0 && info->HotKeyID <= IDM_COMMANDNUM39) {
|
|---|
| 696 | UsedHotKeyIDs[info->HotKeyID - IDM_COMMANDNUM0] = TRUE;
|
|---|
| 697 | }
|
|---|
| 698 | else
|
|---|
| 699 | info->HotKeyID = 0;
|
|---|
| 700 | if (!info->ID) {
|
|---|
| 701 | //profile updated by save_commands
|
|---|
| 702 | for (x = 0; x < 300; x++) {
|
|---|
| 703 | if (!UsedCommandIDs[x]) {
|
|---|
| 704 | info->ID = IDM_COMMANDSTART + x;
|
|---|
| 705 | UsedCommandIDs[x] = TRUE;
|
|---|
| 706 | if (!info->HotKeyID && !fDontCheckHotKey) {
|
|---|
| 707 | for (y = 0; y < 40; y++) {
|
|---|
| 708 | if (!UsedHotKeyIDs[y]) {
|
|---|
| 709 | info->HotKeyID = IDM_COMMANDNUM0 + y;
|
|---|
| 710 | UsedHotKeyIDs[y] = TRUE;
|
|---|
| 711 | break;
|
|---|
| 712 | }
|
|---|
| 713 | }
|
|---|
| 714 | }
|
|---|
| 715 | break;
|
|---|
| 716 | }
|
|---|
| 717 | if (x == 299)
|
|---|
| 718 | saymsg(MB_OK | MB_ICONEXCLAMATION , HWND_DESKTOP,
|
|---|
| 719 | GetPString(IDS_COMMANDSLIMITTITLETEXT),
|
|---|
| 720 | GetPString(IDS_COMMANDSLIMITREACHEDTEXT ));
|
|---|
| 721 | }
|
|---|
| 722 | }
|
|---|
| 723 | if (addme->flags)
|
|---|
| 724 | info->flags = addme->flags;
|
|---|
| 725 | if (addme->env)
|
|---|
| 726 | info->env = xstrdup(addme->env, pszSrcFile, __LINE__);
|
|---|
| 727 | if (!info->pszCmdLine || !info->title || !info->ID) {
|
|---|
| 728 | xfree(info->pszCmdLine, pszSrcFile, __LINE__);
|
|---|
| 729 | xfree(info->title, pszSrcFile, __LINE__);
|
|---|
| 730 | xfree(info->env, pszSrcFile, __LINE__);
|
|---|
| 731 | free(info);
|
|---|
| 732 | return NULL;
|
|---|
| 733 | }
|
|---|
| 734 | if (!cmdhead) // only item in list
|
|---|
| 735 | cmdhead = cmdtail = info;
|
|---|
| 736 | else {
|
|---|
| 737 | // place at tail
|
|---|
| 738 | cmdtail->next = info;
|
|---|
| 739 | info->prev = cmdtail;
|
|---|
| 740 | cmdtail = info;
|
|---|
| 741 | }
|
|---|
| 742 | pszCommandsList = xrealloc(pszCommandsList, ulSizeCommandsList + strlen(info->title) + 1,
|
|---|
| 743 | pszSrcFile, __LINE__);
|
|---|
| 744 | if (pszCommandsList) {
|
|---|
| 745 | strcpy(pszCommandsList + strlen(pszCommandsList), info->title);
|
|---|
| 746 | strcpy(pszCommandsList + strlen(pszCommandsList), ";");
|
|---|
| 747 | ulSizeCommandsList = ulSizeCommandsList + strlen(info->title) + 1;
|
|---|
| 748 | }
|
|---|
| 749 | else {
|
|---|
| 750 | pszCommandsList = xmallocz(ulSizeCommandsList, pszSrcFile, __LINE__);
|
|---|
| 751 | if (pszCommandsList)
|
|---|
| 752 | PrfQueryProfileString(fmprof, FM3Str, "COMMANDS.SortOrder",
|
|---|
| 753 | NullStr, pszCommandsList, ulSizeCommandsList);
|
|---|
| 754 | return 0;
|
|---|
| 755 | }
|
|---|
| 756 | return info;
|
|---|
| 757 | }
|
|---|
| 758 |
|
|---|
| 759 | BOOL kill_command(CHAR * killme)
|
|---|
| 760 | {
|
|---|
| 761 | LINKCMDS *info;
|
|---|
| 762 |
|
|---|
| 763 | if (killme && *killme) {
|
|---|
| 764 | info = cmdhead;
|
|---|
| 765 | while (info) {
|
|---|
| 766 | if (!stricmp(info->title, killme)) {
|
|---|
| 767 | UsedCommandIDs[info->ID - IDM_COMMANDSTART] = FALSE;
|
|---|
| 768 | if (info->HotKeyID)
|
|---|
| 769 | UsedHotKeyIDs[info->HotKeyID - IDM_COMMANDNUM0] = FALSE;
|
|---|
| 770 | if (info == cmdhead) {
|
|---|
| 771 | cmdhead = info->next;
|
|---|
| 772 | if (info == cmdtail)
|
|---|
| 773 | cmdtail = info->prev;
|
|---|
| 774 | }
|
|---|
| 775 | else {
|
|---|
| 776 | if (info->next)
|
|---|
| 777 | (info->next)->prev = info->prev;
|
|---|
| 778 | if (info->prev)
|
|---|
| 779 | (info->prev)->next = info->next;
|
|---|
| 780 | if (info == cmdtail)
|
|---|
| 781 | cmdtail = info->prev;
|
|---|
| 782 | }
|
|---|
| 783 | xfree(info->pszCmdLine, pszSrcFile, __LINE__);
|
|---|
| 784 | xfree(info->title, pszSrcFile, __LINE__);
|
|---|
| 785 | xfree(info->env, pszSrcFile, __LINE__);
|
|---|
| 786 | free(info);
|
|---|
| 787 | return TRUE;
|
|---|
| 788 | }
|
|---|
| 789 | info = info->next;
|
|---|
| 790 | }
|
|---|
| 791 | }
|
|---|
| 792 | # ifdef FORTIFY
|
|---|
| 793 | Fortify_LeaveScope();
|
|---|
| 794 | # endif
|
|---|
| 795 | return FALSE;
|
|---|
| 796 | }
|
|---|
| 797 |
|
|---|
| 798 | BOOL QueryCommandSettings(HWND hwnd, COMMAND *temp)
|
|---|
| 799 | {
|
|---|
| 800 | PSZ pszWorkBuf;
|
|---|
| 801 | APIRET ret;
|
|---|
| 802 | CHAR env[ENVIRONMENT_SIZE];
|
|---|
| 803 | INT x;
|
|---|
| 804 |
|
|---|
| 805 | pszWorkBuf = xmalloc(MaxComLineStrg, pszSrcFile, __LINE__);
|
|---|
| 806 | if (!pszWorkBuf) {
|
|---|
| 807 | return FALSE; //already complained
|
|---|
| 808 | }
|
|---|
| 809 | WinQueryDlgItemText(hwnd, CMD_CL, MaxComLineStrg, temp->pszCmdLine);
|
|---|
| 810 | NormalizeCmdLine(pszWorkBuf, temp->pszCmdLine);
|
|---|
| 811 | memcpy(temp->pszCmdLine, pszWorkBuf, strlen(pszWorkBuf) + 1);
|
|---|
| 812 | free(pszWorkBuf);
|
|---|
| 813 | if (fCancelAction) {
|
|---|
| 814 | fCancelAction = FALSE;
|
|---|
| 815 | return FALSE;
|
|---|
| 816 | }
|
|---|
| 817 | if (!strchr(temp->pszCmdLine, '%')) {
|
|---|
| 818 | ret = saymsg(MB_YESNO,
|
|---|
| 819 | HWND_DESKTOP,
|
|---|
| 820 | NullStr,
|
|---|
| 821 | GetPString(IDS_TOACTONSELECTEDTEXT));
|
|---|
| 822 | if (ret == MBID_YES)
|
|---|
| 823 | strcat(temp->pszCmdLine, " %a");
|
|---|
| 824 | }
|
|---|
| 825 | WinQueryDlgItemText(hwnd, CMD_TITLE, sizeof(temp->title), temp->title);
|
|---|
| 826 | bstripcr(temp->title);
|
|---|
| 827 | temp->flags = CheckExecutibleFlags(hwnd, 3);
|
|---|
| 828 | *env = 0;
|
|---|
| 829 | WinQueryDlgItemText(hwnd, CMD_ENVIRON, ENVIRONMENT_SIZE - 1, env);
|
|---|
| 830 | bstripcr(env);
|
|---|
| 831 | if (*env)
|
|---|
| 832 | strcpy(temp->env, env);
|
|---|
| 833 | x = (SHORT) WinSendDlgItemMsg(hwnd, CMD_HOTKEY,
|
|---|
| 834 | LM_QUERYSELECTION,
|
|---|
| 835 | MPFROMSHORT(LIT_FIRST), MPVOID);
|
|---|
| 836 | if (x < 40)
|
|---|
| 837 | temp->HotKeyID = x + IDM_COMMANDNUM0;
|
|---|
| 838 | else
|
|---|
| 839 | temp->HotKeyID = 0;
|
|---|
| 840 | //DbgMsg(pszSrcFile, __LINE__, "info %i", temp->HotKeyID);
|
|---|
| 841 | return TRUE;
|
|---|
| 842 | }
|
|---|
| 843 |
|
|---|
| 844 | MRESULT EXPENTRY CommandDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
|---|
| 845 | {
|
|---|
| 846 | SHORT x, y;
|
|---|
| 847 | LINKCMDS *info;
|
|---|
| 848 |
|
|---|
| 849 | # ifdef FORTIFY
|
|---|
| 850 | Fortify_EnterScope();
|
|---|
| 851 | # endif
|
|---|
| 852 | switch (msg) {
|
|---|
| 853 | case WM_INITDLG:
|
|---|
| 854 | WinSendDlgItemMsg(hwnd, CMD_LISTBOX, LM_DELETEALL, MPVOID, MPVOID);
|
|---|
| 855 | WinSendDlgItemMsg(hwnd, CMD_CL, EM_SETTEXTLIMIT,
|
|---|
| 856 | MPFROM2SHORT(MaxComLineStrg - 1, 0), MPVOID);
|
|---|
| 857 | WinSendDlgItemMsg(hwnd, CMD_TITLE, EM_SETTEXTLIMIT,
|
|---|
| 858 | MPFROM2SHORT(99, 0), MPVOID);
|
|---|
| 859 | WinSetDlgItemText(hwnd, CMD_CL, NullStr);
|
|---|
| 860 | WinSetDlgItemText(hwnd, CMD_TITLE, NullStr);
|
|---|
| 861 | WinCheckButton(hwnd, CMD_DEFAULT, TRUE);
|
|---|
| 862 | WinCheckButton(hwnd, CMD_PROMPT, FALSE);
|
|---|
| 863 | WinCheckButton(hwnd, CMD_ONCE, FALSE);
|
|---|
| 864 | info = cmdhead;
|
|---|
| 865 | while (info) {
|
|---|
| 866 | x = (SHORT) WinSendDlgItemMsg(hwnd, CMD_LISTBOX, LM_INSERTITEM,
|
|---|
| 867 | MPFROM2SHORT(LIT_END, 0),
|
|---|
| 868 | MPFROMP(info->title));
|
|---|
| 869 | if (x >= 0)
|
|---|
| 870 | WinSendDlgItemMsg(hwnd, CMD_LISTBOX, LM_SETITEMHANDLE,
|
|---|
| 871 | MPFROMSHORT(x), MPFROMP(info));
|
|---|
| 872 | info = info->next;
|
|---|
| 873 | }
|
|---|
| 874 | WinSendDlgItemMsg(hwnd, CMD_LISTBOX, LM_SELECTITEM,
|
|---|
| 875 | MPFROMSHORT(0), MPFROMSHORT(TRUE));
|
|---|
| 876 | {
|
|---|
| 877 | PFNWP oldproc;
|
|---|
| 878 |
|
|---|
| 879 | oldproc = WinSubclassWindow(WinWindowFromID(hwnd, CMD_CL),
|
|---|
| 880 | (PFNWP) CommandTextProc);
|
|---|
| 881 | if (oldproc)
|
|---|
| 882 | WinSetWindowPtr(WinWindowFromID(hwnd, CMD_CL), QWL_USER, (PVOID) oldproc);
|
|---|
| 883 | }
|
|---|
| 884 | break;
|
|---|
| 885 |
|
|---|
| 886 | case WM_CONTROL:
|
|---|
| 887 | if (SHORT1FROMMP(mp1) == CMD_LISTBOX) {
|
|---|
| 888 | switch (SHORT2FROMMP(mp1)) {
|
|---|
| 889 | case LN_ENTER:
|
|---|
| 890 | case LN_SELECT:
|
|---|
| 891 | x = (SHORT) WinSendDlgItemMsg(hwnd, CMD_LISTBOX,
|
|---|
| 892 | LM_QUERYSELECTION,
|
|---|
| 893 | MPFROMSHORT(LIT_FIRST), MPVOID);
|
|---|
| 894 | if (x >= 0) {
|
|---|
| 895 | info = (LINKCMDS *) WinSendDlgItemMsg(hwnd, CMD_LISTBOX,
|
|---|
| 896 | LM_QUERYITEMHANDLE,
|
|---|
| 897 | MPFROMSHORT(x), MPVOID);
|
|---|
| 898 | if (!info) {
|
|---|
| 899 | Runtime_Error(pszSrcFile, __LINE__, "LM_QUERYITEMHANDLE");
|
|---|
| 900 | break;
|
|---|
| 901 | }
|
|---|
| 902 | WinSetDlgItemText(hwnd, CMD_CL, info->pszCmdLine);
|
|---|
| 903 | if (!(info->flags & 1023))
|
|---|
| 904 | WinCheckButton(hwnd, CMD_DEFAULT, TRUE);
|
|---|
| 905 | else {
|
|---|
| 906 | if (info->flags & FULLSCREEN)
|
|---|
| 907 | WinCheckButton(hwnd, CMD_FULLSCREEN, TRUE);
|
|---|
| 908 | else if (info->flags & MINIMIZED)
|
|---|
| 909 | WinCheckButton(hwnd, CMD_MINIMIZED, TRUE);
|
|---|
| 910 | else if (info->flags & MAXIMIZED)
|
|---|
| 911 | WinCheckButton(hwnd, CMD_MAXIMIZED, TRUE);
|
|---|
| 912 | else if (info->flags & INVISIBLE)
|
|---|
| 913 | WinCheckButton(hwnd, CMD_INVISIBLE, TRUE);
|
|---|
| 914 | }
|
|---|
| 915 | WinCheckButton(hwnd, CMD_PROMPT, ((info->flags & PROMPT) != 0));
|
|---|
| 916 | WinCheckButton(hwnd, CMD_KEEP, ((info->flags & KEEP) != 0));
|
|---|
| 917 | WinCheckButton(hwnd, CMD_ONCE, ((info->flags & ONCE) != 0));
|
|---|
| 918 | WinSetDlgItemText(hwnd, CMD_TITLE, info->title);
|
|---|
| 919 | if (info->env)
|
|---|
| 920 | WinSetDlgItemText(hwnd, CMD_ENVIRON, info->env);
|
|---|
| 921 | else
|
|---|
| 922 | WinSetDlgItemText(hwnd, CMD_ENVIRON, NullStr);
|
|---|
| 923 | for (x = 0; x < 40; x++) {
|
|---|
| 924 | CHAR s[CCHMAXPATH + 24];
|
|---|
| 925 |
|
|---|
| 926 | sprintf(s, "%s%s%s",
|
|---|
| 927 | x < IDM_COMMANDNUM20 - IDM_COMMANDNUM0 ? "Ctrl+" : NullStr,
|
|---|
| 928 | x > IDM_COMMANDNUM19 - IDM_COMMANDNUM0 ? "Alt+" : NullStr,
|
|---|
| 929 | (x > IDM_COMMANDNUM9 - IDM_COMMANDNUM0 &&
|
|---|
| 930 | x < IDM_COMMANDNUM20 - IDM_COMMANDNUM0) ||
|
|---|
| 931 | x > IDM_COMMANDNUM29 - IDM_COMMANDNUM0 ? "Shift+" : NullStr);
|
|---|
| 932 | sprintf(&s[strlen(s)], "%d", (x % 10) + 1 == 10 ? 0 : (x % 10) + 1);
|
|---|
| 933 | sprintf(&s[strlen(s)], " %s", UsedHotKeyIDs[x] ? "(in use)" : NullStr);
|
|---|
| 934 | WinSendMsg(WinWindowFromID(hwnd, CMD_HOTKEY), LM_INSERTITEM,
|
|---|
| 935 | MPFROM2SHORT(LIT_END, 0), MPFROMP(s));
|
|---|
| 936 | if (x == 39)
|
|---|
| 937 | WinSendMsg(WinWindowFromID(hwnd, CMD_HOTKEY), LM_INSERTITEM,
|
|---|
| 938 | MPFROM2SHORT(LIT_END, 0), MPFROMP("none"));
|
|---|
| 939 | if (info->HotKeyID == x + IDM_COMMANDNUM0)
|
|---|
| 940 | WinSendMsg(WinWindowFromID(hwnd, CMD_HOTKEY), LM_SELECTITEM,
|
|---|
| 941 | MPFROM2SHORT(x, 0), MPFROMLONG(TRUE));
|
|---|
| 942 | if (x == 39 && info->HotKeyID == 0)
|
|---|
| 943 | WinSendMsg(WinWindowFromID(hwnd, CMD_HOTKEY), LM_SELECTITEM,
|
|---|
| 944 | MPFROM2SHORT(x + 1, 0), MPFROMLONG(TRUE));
|
|---|
| 945 | } // for
|
|---|
| 946 | }
|
|---|
| 947 | break;
|
|---|
| 948 | }
|
|---|
| 949 | }
|
|---|
| 950 | return 0;
|
|---|
| 951 |
|
|---|
| 952 | case WM_COMMAND:
|
|---|
| 953 | switch (SHORT1FROMMP(mp1)) {
|
|---|
| 954 | case CMD_FIND:
|
|---|
| 955 | {
|
|---|
| 956 | CHAR filename[CCHMAXPATH + 9], szfilename[CCHMAXPATH + 9];
|
|---|
| 957 |
|
|---|
| 958 | *filename = 0;
|
|---|
| 959 | if (insert_filename(hwnd, filename, 2, FALSE) && *filename) {
|
|---|
| 960 | BldQuotedFileName(szfilename, filename);
|
|---|
| 961 | WinSetDlgItemText(hwnd, CMD_CL, szfilename);
|
|---|
| 962 | }
|
|---|
| 963 | }
|
|---|
| 964 | break;
|
|---|
| 965 |
|
|---|
| 966 | case CMD_REORDER:
|
|---|
| 967 | if (!cmdhead || !cmdhead->next) {
|
|---|
| 968 | Runtime_Error(pszSrcFile, __LINE__, "no cmd");
|
|---|
| 969 | break;
|
|---|
| 970 | }
|
|---|
| 971 | if (WinDlgBox(HWND_DESKTOP, hwnd, ReOrderProc, FM3ModHandle,
|
|---|
| 972 | RE_FRAME, MPVOID)) {
|
|---|
| 973 | WinSendDlgItemMsg(hwnd, CMD_LISTBOX, LM_DELETEALL, MPVOID, MPVOID);
|
|---|
| 974 | WinSetDlgItemText(hwnd, CMD_CL, NullStr);
|
|---|
| 975 | WinSetDlgItemText(hwnd, CMD_TITLE, NullStr);
|
|---|
| 976 | info = cmdhead;
|
|---|
| 977 | while (info) {
|
|---|
| 978 | x = (SHORT) WinSendDlgItemMsg(hwnd,
|
|---|
| 979 | CMD_LISTBOX,
|
|---|
| 980 | LM_INSERTITEM,
|
|---|
| 981 | MPFROM2SHORT(LIT_END, 0),
|
|---|
| 982 | MPFROMP(info->title));
|
|---|
| 983 | if (x >= 0)
|
|---|
| 984 | WinSendDlgItemMsg(hwnd,
|
|---|
| 985 | CMD_LISTBOX,
|
|---|
| 986 | LM_SETITEMHANDLE,
|
|---|
| 987 | MPFROMSHORT(x), MPFROMP(info));
|
|---|
| 988 | info = info->next;
|
|---|
| 989 | }
|
|---|
| 990 | WinSendDlgItemMsg(hwnd,
|
|---|
| 991 | CMD_LISTBOX,
|
|---|
| 992 | LM_SELECTITEM, MPFROMSHORT(0), MPFROMSHORT(TRUE));
|
|---|
| 993 | WinCheckButton(hwnd, CMD_DEFAULT, TRUE);
|
|---|
| 994 | WinCheckButton(hwnd, CMD_PROMPT, FALSE);
|
|---|
| 995 | WinCheckButton(hwnd, CMD_ONCE, FALSE);
|
|---|
| 996 | save_commands();
|
|---|
| 997 | }
|
|---|
| 998 | break;
|
|---|
| 999 |
|
|---|
| 1000 | case DID_OK:
|
|---|
| 1001 | {
|
|---|
| 1002 | COMMAND *temp;
|
|---|
| 1003 | BOOL fDontCheckHotKey = FALSE;
|
|---|
| 1004 |
|
|---|
| 1005 | temp = xmallocz(sizeof(COMMAND), pszSrcFile, __LINE__);
|
|---|
| 1006 | if (!temp)
|
|---|
| 1007 | break; //already complained
|
|---|
| 1008 | temp->pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
|
|---|
| 1009 | if (!temp->pszCmdLine) {
|
|---|
| 1010 | free (temp);
|
|---|
| 1011 | break; //already complained
|
|---|
| 1012 | }
|
|---|
| 1013 | if (QueryCommandSettings(hwnd, temp)){
|
|---|
| 1014 | if (temp->HotKeyID == 0)
|
|---|
| 1015 | fDontCheckHotKey = TRUE;
|
|---|
| 1016 | info = add_command(temp, fDontCheckHotKey);
|
|---|
| 1017 | if (info == (LINKCMDS *) -1) {
|
|---|
| 1018 | free(temp->pszCmdLine);
|
|---|
| 1019 | free(temp);
|
|---|
| 1020 | break;
|
|---|
| 1021 | }
|
|---|
| 1022 | }
|
|---|
| 1023 | else {
|
|---|
| 1024 | free(temp->pszCmdLine);
|
|---|
| 1025 | free(temp);
|
|---|
| 1026 | break;
|
|---|
| 1027 | }
|
|---|
| 1028 | free(temp->pszCmdLine);
|
|---|
| 1029 | free(temp);
|
|---|
| 1030 | save_commands();
|
|---|
| 1031 | WinDismissDlg(hwnd, 0);
|
|---|
| 1032 | break;
|
|---|
| 1033 | }
|
|---|
| 1034 |
|
|---|
| 1035 | case DID_CANCEL:
|
|---|
| 1036 | WinDismissDlg(hwnd, 0);
|
|---|
| 1037 | break;
|
|---|
| 1038 |
|
|---|
| 1039 | case IDM_HELP:
|
|---|
| 1040 | if (hwndHelp)
|
|---|
| 1041 | WinSendMsg(hwndHelp,
|
|---|
| 1042 | HM_DISPLAY_HELP,
|
|---|
| 1043 | MPFROM2SHORT(HELP_COMMAND, 0), MPFROMSHORT(HM_RESOURCEID));
|
|---|
| 1044 | break;
|
|---|
| 1045 |
|
|---|
| 1046 | case CMD_ADD:
|
|---|
| 1047 | {
|
|---|
| 1048 | COMMAND *temp;
|
|---|
| 1049 | BOOL fDontCheckHotKey = FALSE;
|
|---|
| 1050 |
|
|---|
| 1051 | temp = xmallocz(sizeof(COMMAND), pszSrcFile, __LINE__);
|
|---|
| 1052 | if (!temp)
|
|---|
| 1053 | break; //already complained
|
|---|
| 1054 | temp->pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
|
|---|
| 1055 | if (!temp->pszCmdLine) {
|
|---|
| 1056 | free (temp);
|
|---|
| 1057 | break; //already complained
|
|---|
| 1058 | }
|
|---|
| 1059 | if (!QueryCommandSettings(hwnd, temp)) {
|
|---|
| 1060 | free(temp->pszCmdLine);
|
|---|
| 1061 | free(temp);
|
|---|
| 1062 | break;
|
|---|
| 1063 | }
|
|---|
| 1064 | else {
|
|---|
| 1065 | if (temp->HotKeyID == 0)
|
|---|
| 1066 | fDontCheckHotKey = TRUE;
|
|---|
| 1067 | info = add_command(temp, fDontCheckHotKey);
|
|---|
| 1068 | if (!info) {
|
|---|
| 1069 | saymsg(MB_ENTER, hwnd, GetPString(IDS_ERRORTEXT),
|
|---|
| 1070 | GetPString(IDS_CANTADDCOMMANDTEXTDUP), temp->title);
|
|---|
| 1071 | free(temp->pszCmdLine);
|
|---|
| 1072 | free(temp);
|
|---|
| 1073 | break;
|
|---|
| 1074 | }
|
|---|
| 1075 | if (info == (LINKCMDS *) -1) {
|
|---|
| 1076 | free(temp->pszCmdLine);
|
|---|
| 1077 | free(temp);
|
|---|
| 1078 | break;
|
|---|
| 1079 | }
|
|---|
| 1080 | x = (SHORT) WinSendDlgItemMsg(hwnd,
|
|---|
| 1081 | CMD_LISTBOX,
|
|---|
| 1082 | LM_INSERTITEM,
|
|---|
| 1083 | MPFROM2SHORT(LIT_END, 0),
|
|---|
| 1084 | MPFROMP(temp->title));
|
|---|
| 1085 | if (x >= 0) {
|
|---|
| 1086 | WinSendDlgItemMsg(hwnd,
|
|---|
| 1087 | CMD_LISTBOX,
|
|---|
| 1088 | LM_SETITEMHANDLE,
|
|---|
| 1089 | MPFROMSHORT(x), MPFROMP(info));
|
|---|
| 1090 | WinSendDlgItemMsg(hwnd,
|
|---|
| 1091 | CMD_LISTBOX,
|
|---|
| 1092 | LM_SELECTITEM,
|
|---|
| 1093 | MPFROMSHORT(x), MPFROMSHORT(TRUE));
|
|---|
| 1094 | }
|
|---|
| 1095 | save_commands();
|
|---|
| 1096 | }
|
|---|
| 1097 | free(temp->pszCmdLine);
|
|---|
| 1098 | free(temp);
|
|---|
| 1099 | break;
|
|---|
| 1100 | }
|
|---|
| 1101 |
|
|---|
| 1102 | case CMD_DELETE:
|
|---|
| 1103 | {
|
|---|
| 1104 | CHAR temp[100];
|
|---|
| 1105 | CHAR key[120];
|
|---|
| 1106 |
|
|---|
| 1107 | WinQueryDlgItemText(hwnd, CMD_TITLE, 100, temp);
|
|---|
| 1108 | bstripcr(temp);
|
|---|
| 1109 | if (!kill_command(temp))
|
|---|
| 1110 | Runtime_Error(pszSrcFile, __LINE__, "kill_command");
|
|---|
| 1111 | else {
|
|---|
| 1112 | sprintf(key, "COMMAND.%sID", temp);
|
|---|
| 1113 | PrfWriteProfileData(fmprof, FM3Str, key, NULL, 0);
|
|---|
| 1114 | sprintf(key, "COMMAND.%sHotKeyID", temp);
|
|---|
| 1115 | PrfWriteProfileData(fmprof, FM3Str, key, NULL, 0);
|
|---|
| 1116 | sprintf(key, "COMMAND.%senv", temp);
|
|---|
| 1117 | PrfWriteProfileData(fmprof, FM3Str, key, NULL, 0);
|
|---|
| 1118 | sprintf(key, "COMMAND.%sflags", temp);
|
|---|
| 1119 | PrfWriteProfileData(fmprof, FM3Str, key, NULL, 0);
|
|---|
| 1120 | sprintf(key, "COMMAND.%sCmdLine", temp);
|
|---|
| 1121 | PrfWriteProfileData(fmprof, FM3Str, key, NULL, 0);
|
|---|
| 1122 | x = (SHORT) WinSendDlgItemMsg(hwnd,
|
|---|
| 1123 | CMD_LISTBOX,
|
|---|
| 1124 | LM_QUERYSELECTION,
|
|---|
| 1125 | MPFROMSHORT(LIT_FIRST), MPVOID);
|
|---|
| 1126 | if (x >= 0) {
|
|---|
| 1127 | WinSendDlgItemMsg(hwnd,
|
|---|
| 1128 | CMD_LISTBOX,
|
|---|
| 1129 | LM_DELETEITEM, MPFROMSHORT(x), MPVOID);
|
|---|
| 1130 | WinSendDlgItemMsg(hwnd,
|
|---|
| 1131 | CMD_LISTBOX,
|
|---|
| 1132 | LM_SELECTITEM,
|
|---|
| 1133 | MPFROMSHORT(0), MPFROMSHORT(TRUE));
|
|---|
| 1134 | }
|
|---|
| 1135 | save_commands();
|
|---|
| 1136 | }
|
|---|
| 1137 | }
|
|---|
| 1138 | break;
|
|---|
| 1139 |
|
|---|
| 1140 | case CMD_REPLACE:
|
|---|
| 1141 | {
|
|---|
| 1142 | COMMAND *temp;
|
|---|
| 1143 | CHAR keyID[120];
|
|---|
| 1144 | CHAR keyHotKeyID[120];
|
|---|
| 1145 | CHAR keyenv[120];
|
|---|
| 1146 | INT ID = 0;
|
|---|
| 1147 | INT HotKeyID = 0;
|
|---|
| 1148 | ULONG size;
|
|---|
| 1149 | BOOL fDontCheckHotKey = FALSE;
|
|---|
| 1150 |
|
|---|
| 1151 | // Query the dialog
|
|---|
| 1152 | temp = xmallocz(sizeof(COMMAND), pszSrcFile, __LINE__);
|
|---|
| 1153 | if (!temp)
|
|---|
| 1154 | break; //already complained
|
|---|
| 1155 | temp->pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
|
|---|
| 1156 | if (!temp->pszCmdLine) {
|
|---|
| 1157 | free (temp);
|
|---|
| 1158 | break; //already complained
|
|---|
| 1159 | }
|
|---|
| 1160 | if (!QueryCommandSettings(hwnd, temp)) {
|
|---|
| 1161 | free(temp->pszCmdLine);
|
|---|
| 1162 | free(temp);
|
|---|
| 1163 | break;
|
|---|
| 1164 | }
|
|---|
| 1165 | //remember item location in the list
|
|---|
| 1166 | y = (SHORT) WinSendDlgItemMsg(hwnd,
|
|---|
| 1167 | CMD_LISTBOX,
|
|---|
| 1168 | LM_QUERYSELECTION,
|
|---|
| 1169 | MPFROMSHORT(LIT_CURSOR), MPVOID);
|
|---|
| 1170 | //Delete
|
|---|
| 1171 | sprintf(keyID, "COMMAND.%sID", temp->title);
|
|---|
| 1172 | sprintf(keyHotKeyID, "COMMAND.%sHotKeyID", temp->title);
|
|---|
| 1173 | sprintf(keyenv, "COMMAND.%senv", temp->title);
|
|---|
| 1174 | PrfQueryProfileData(fmprof, FM3Str, keyID, &ID, &size);
|
|---|
| 1175 | PrfQueryProfileData(fmprof, FM3Str, keyHotKeyID, &HotKeyID, &size);
|
|---|
| 1176 | temp->ID = ID;
|
|---|
| 1177 | if (temp->HotKeyID == HotKeyID || temp->HotKeyID == 0)
|
|---|
| 1178 | fDontCheckHotKey = TRUE;
|
|---|
| 1179 | if (kill_command(temp->title)) {
|
|---|
| 1180 | PrfWriteProfileData(fmprof, FM3Str, keyID, NULL, 0);
|
|---|
| 1181 | PrfWriteProfileData(fmprof, FM3Str, keyHotKeyID, NULL, 0);
|
|---|
| 1182 | PrfWriteProfileString(fmprof, FM3Str, keyenv, NULL);
|
|---|
| 1183 | x = (SHORT) WinSendDlgItemMsg(hwnd,
|
|---|
| 1184 | CMD_LISTBOX,
|
|---|
| 1185 | LM_QUERYSELECTION,
|
|---|
| 1186 | MPFROMSHORT(LIT_FIRST), MPVOID);
|
|---|
| 1187 | if (x >= 0) {
|
|---|
| 1188 | WinSendDlgItemMsg(hwnd,
|
|---|
| 1189 | CMD_LISTBOX,
|
|---|
| 1190 | LM_DELETEITEM, MPFROMSHORT(x), MPVOID);
|
|---|
| 1191 | WinSendDlgItemMsg(hwnd,
|
|---|
| 1192 | CMD_LISTBOX,
|
|---|
| 1193 | LM_SELECTITEM,
|
|---|
| 1194 | MPFROMSHORT(LIT_NONE), MPFROMSHORT(FALSE));
|
|---|
| 1195 | }
|
|---|
| 1196 | } // then do an add
|
|---|
| 1197 | info = add_command(temp, fDontCheckHotKey);
|
|---|
| 1198 | if (!info || info == (LINKCMDS *) -1) {
|
|---|
| 1199 | if (!info)
|
|---|
| 1200 | saymsg(MB_ENTER, hwnd, GetPString(IDS_ERRORTEXT),
|
|---|
| 1201 | GetPString(IDS_CANTADDCOMMANDTEXT),
|
|---|
| 1202 | temp->title);
|
|---|
| 1203 | }
|
|---|
| 1204 | else {
|
|---|
| 1205 | //put item back in original place
|
|---|
| 1206 | x = (SHORT) WinSendDlgItemMsg(hwnd,
|
|---|
| 1207 | CMD_LISTBOX,
|
|---|
| 1208 | LM_INSERTITEM,
|
|---|
| 1209 | MPFROM2SHORT(y, 0),
|
|---|
| 1210 | MPFROMP(temp->title));
|
|---|
| 1211 | if (x >= 0) {
|
|---|
| 1212 | LINKCMDS *temphead = NULL,*last = NULL, *temptail = NULL;
|
|---|
| 1213 | SHORT numitems, sSelect = 0;
|
|---|
| 1214 |
|
|---|
| 1215 | WinSendDlgItemMsg(hwnd,
|
|---|
| 1216 | CMD_LISTBOX,
|
|---|
| 1217 | LM_SETITEMHANDLE,
|
|---|
| 1218 | MPFROMSHORT(x), MPFROMP(info));
|
|---|
| 1219 | WinSendDlgItemMsg(hwnd,
|
|---|
| 1220 | CMD_LISTBOX,
|
|---|
| 1221 | LM_SELECTITEM,
|
|---|
| 1222 | MPFROMSHORT(x), MPFROMSHORT(TRUE));
|
|---|
| 1223 | //then reorder
|
|---|
| 1224 | numitems = (SHORT) WinSendDlgItemMsg(hwnd, CMD_LISTBOX,
|
|---|
| 1225 | LM_QUERYITEMCOUNT,
|
|---|
| 1226 | MPVOID, MPVOID);
|
|---|
| 1227 |
|
|---|
| 1228 | while (numitems) {
|
|---|
| 1229 |
|
|---|
| 1230 |
|
|---|
| 1231 | info = (LINKCMDS *) WinSendDlgItemMsg(hwnd, CMD_LISTBOX,
|
|---|
| 1232 | LM_QUERYITEMHANDLE,
|
|---|
| 1233 | MPFROMSHORT(sSelect++),
|
|---|
| 1234 | MPVOID);
|
|---|
| 1235 | if (info) {
|
|---|
| 1236 | if (!temphead) {
|
|---|
| 1237 | temphead = info;
|
|---|
| 1238 | info->prev = NULL;
|
|---|
| 1239 | }
|
|---|
| 1240 | else {
|
|---|
| 1241 | last->next = info;
|
|---|
| 1242 | info->prev = last;
|
|---|
| 1243 | }
|
|---|
| 1244 | temptail = info;
|
|---|
| 1245 | last = info;
|
|---|
| 1246 | info->next = NULL;
|
|---|
| 1247 | }
|
|---|
| 1248 | numitems--;
|
|---|
| 1249 | }
|
|---|
| 1250 | cmdhead = temphead;
|
|---|
| 1251 | cmdtail = temptail;
|
|---|
| 1252 | save_commands();
|
|---|
| 1253 | }
|
|---|
| 1254 | }
|
|---|
| 1255 | xfree(temp->pszCmdLine, pszSrcFile, __LINE__);
|
|---|
| 1256 | xfree(temp, pszSrcFile, __LINE__);
|
|---|
| 1257 | }
|
|---|
| 1258 | break;
|
|---|
| 1259 | }
|
|---|
| 1260 | return 0;
|
|---|
| 1261 | }
|
|---|
| 1262 | # ifdef FORTIFY
|
|---|
| 1263 | Fortify_LeaveScope();
|
|---|
| 1264 | # endif
|
|---|
| 1265 | return WinDefDlgProc(hwnd, msg, mp1, mp2);
|
|---|
| 1266 | }
|
|---|
| 1267 |
|
|---|
| 1268 | VOID RunCommand(HWND hwnd, INT cx)
|
|---|
| 1269 | {
|
|---|
| 1270 | INT x;
|
|---|
| 1271 | CHAR **list;
|
|---|
| 1272 | LINKCMDS *info;
|
|---|
| 1273 |
|
|---|
| 1274 | list = BuildList(hwnd);
|
|---|
| 1275 | x = 0;
|
|---|
| 1276 | info = cmdhead;
|
|---|
| 1277 | while (info) {
|
|---|
| 1278 | if (cx < 4300) {
|
|---|
| 1279 | if (info->ID == cx)
|
|---|
| 1280 | break;
|
|---|
| 1281 | }
|
|---|
| 1282 | else {
|
|---|
| 1283 | if (info->HotKeyID == cx)
|
|---|
| 1284 | break;
|
|---|
| 1285 | }
|
|---|
| 1286 | info = info->next;
|
|---|
| 1287 | }
|
|---|
| 1288 | if (info) {
|
|---|
| 1289 |
|
|---|
| 1290 | INT flags;
|
|---|
| 1291 |
|
|---|
| 1292 | x--;
|
|---|
| 1293 | flags = info->flags;
|
|---|
| 1294 | if (!(flags & FULLSCREEN))
|
|---|
| 1295 | flags |= WINDOWED;
|
|---|
| 1296 | if (flags & KEEP)
|
|---|
| 1297 | flags |= SEPARATEKEEP;
|
|---|
| 1298 | else
|
|---|
| 1299 | flags |= SEPARATE;
|
|---|
| 1300 | flags &= ~(KEEP | DIEAFTER);
|
|---|
| 1301 | if (!strchr(info->pszCmdLine, '%')) {
|
|---|
| 1302 | CHAR *fakelist[2];
|
|---|
| 1303 |
|
|---|
| 1304 | *fakelist = "C";
|
|---|
| 1305 | fakelist[1] = NULL;
|
|---|
| 1306 | ExecOnList(hwnd,
|
|---|
| 1307 | info->pszCmdLine,
|
|---|
| 1308 | flags, NULL, info->env != NullStr ? info->env : NULL,
|
|---|
| 1309 | fakelist, GetPString(IDS_EXECCMDTITLETEXT),
|
|---|
| 1310 | pszSrcFile, __LINE__);
|
|---|
| 1311 | }
|
|---|
| 1312 | else if ((flags & ONCE) && list && list[0]) {
|
|---|
| 1313 |
|
|---|
| 1314 | CHAR *fakelist[2];
|
|---|
| 1315 | INT cntr;
|
|---|
| 1316 |
|
|---|
| 1317 | flags &= (~ONCE);
|
|---|
| 1318 | for (cntr = 0; list[cntr]; cntr++) {
|
|---|
| 1319 | *fakelist = list[cntr];
|
|---|
| 1320 | fakelist[1] = NULL;
|
|---|
| 1321 | ExecOnList(hwnd,
|
|---|
| 1322 | info->pszCmdLine,
|
|---|
| 1323 | flags, NULL, info->env != NullStr ? info->env : NULL,
|
|---|
| 1324 | fakelist, GetPString(IDS_EXECCMDTITLETEXT),
|
|---|
| 1325 | pszSrcFile, __LINE__);
|
|---|
| 1326 | }
|
|---|
| 1327 | }
|
|---|
| 1328 | else if (list && list[0])
|
|---|
| 1329 | ExecOnList(hwnd,
|
|---|
| 1330 | info->pszCmdLine,
|
|---|
| 1331 | flags, NULL, info->env != NullStr ? info->env : NULL,
|
|---|
| 1332 | list, GetPString(IDS_EXECCMDTITLETEXT),
|
|---|
| 1333 | pszSrcFile, __LINE__);
|
|---|
| 1334 | else
|
|---|
| 1335 | return;
|
|---|
| 1336 | }
|
|---|
| 1337 | FreeList(list);
|
|---|
| 1338 | DosPostEventSem(CompactSem);
|
|---|
| 1339 | }
|
|---|
| 1340 |
|
|---|
| 1341 | VOID EditCommands(HWND hwnd)
|
|---|
| 1342 | {
|
|---|
| 1343 | static CHAR stop = 0;
|
|---|
| 1344 |
|
|---|
| 1345 | if (stop)
|
|---|
| 1346 | return;
|
|---|
| 1347 | stop++;
|
|---|
| 1348 | if (!cmdloaded)
|
|---|
| 1349 | load_commands();
|
|---|
| 1350 | WinDlgBox(HWND_DESKTOP,
|
|---|
| 1351 | hwnd, CommandDlgProc, FM3ModHandle, CMD_FRAME, MPFROMP(&hwnd));
|
|---|
| 1352 | stop = 0;
|
|---|
| 1353 | }
|
|---|
| 1354 |
|
|---|
| 1355 | #pragma alloc_text(COMMAND,command_title,free_commands,add_command,kill_command)
|
|---|
| 1356 | #pragma alloc_text(COMMAND,CommandDlgProc,EditCommands,ReOrderProc,CommandTextProc)
|
|---|