Changeset 1840


Ignore:
Timestamp:
Aug 12, 2015, 7:06:11 AM (10 years ago)
Author:
Steven Levine
Message:

Expose GetTidForThread and use

Location:
trunk/dll
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/errutil.c

    r1722 r1840  
    77
    88  Copyright (c) 1993-98 M. Kimes
    9   Copyright (c) 2004, 2014 Steven H. Levine
     9  Copyright (c) 2004, 2015 Steven H. Levine
    1010
    1111  12 Aug 04 SHL Comments
     
    4242  16 Feb 14 GKY Rework readonly check on delete code so it actually works in a logical way
    4343                and so it works with move to trashcan inabled.
     44  09 Nov 13 SHL Use GetTidForThread in DbgMsg and tweak for for editors that understand file:line
    4445
    4546***********************************************************************/
     
    6162#include "notebook.h"                   // fErrorBeepOff
    6263#include "init.h"                       // Data declares
     64#include "misc.h"                       // GetTidForThread
    6365#include "wrappers.h"                   // xmallocz
    6466#include "fm3dll2.h"
     
    8183VOID DbgMsg(PCSZ pszSrcFile, UINT uSrcLineNo, PCSZ pszFmt, ...)
    8284{
    83   PIB *ppib;
    84   TIB *ptib;
    8585  ULONG ultid;
    86   APIRET apiret;
    8786  va_list va;
    8887
     
    106105#endif
    107106
    108   apiret = DosGetInfoBlocks(&ptib, &ppib);
    109   if (apiret)
    110     ultid = 0;
    111   else
    112     ultid = ptib->tib_ptib2->tib2_ultid;
     107  ultid = GetTidForThread();
    113108
    114109  // OK for source file name to be null
    115   fprintf(stderr, "%s %u (%lu)", pszSrcFile ? pszSrcFile : "n/a", uSrcLineNo, ultid);
     110  // 2015-08-08 SHL Use file:line for editors that support it
     111  fprintf(stderr, "%s:%u (%lu)", pszSrcFile ? pszSrcFile : "n/a", uSrcLineNo, ultid);
    116112  // If format null want just file and line
    117113  if (pszFmt) {
  • trunk/dll/misc.c

    r1835 r1840  
    66
    77  Copyright (c) 1993-98 M. Kimes
    8   Copyright (c) 2003, 2010 Steven H. Levine
     8  Copyright (c) 2003, 2015 Steven H. Levine
    99
    1010  11 Jun 03 SHL Add JFS and FAT32 support
     
    5959  08 Mar 09 GKY Removed variable aurguments from docopyf and unlinkf (not used)
    6060  28 Mar 09 GKY Add RemoveOldCnrSwitches to remove pre 3.16 style ini keys;
    61                 add State.version key for check
     61                add State.version key for check
    6262  12 Jul 09 GKY Add xDosQueryAppType and xDosAlloc... to allow FM/2 to load in high memory
    6363  22 Jul 09 GKY Check if drives support EAs add driveflag for this
    6464  22 Jul 09 GKY Allow .LONGNAME to be displayed for FAT drives.
    6565  21 Dec 09 GKY Allow command menu reorder without changing the "ID" or hot key for a command.
    66                 Added load_inicommand to load the IDs from the ini file.
     66                Added load_inicommand to load the IDs from the ini file.
    6767  17 JAN 10 GKY Changes to get working with Watcom 1.9 Beta (1/16/10). Mostly cast CHAR CONSTANT * as CHAR *.
    6868  23 Oct 10 GKY Add menu items for opening directory cnrs based on path of selected item
    69                 including the option to use walk directories to select path
     69                including the option to use walk directories to select path
    7070  26 Aug 11 GKY Add a low mem version of xDosAlloc* wrappers; move error checking into all the
    71                 xDosAlloc* wrappers.
     71                xDosAlloc* wrappers.
    7272  12 Nov 11 GKY Fixed HelpViewer's failure to open help files and subsequent failure with files with spaces.
    7373  28 Jun 14 GKY Fix errors identified with CPPCheck
    7474  12 Jul 15 GKY Fix CN_REALLOCPSZ file name editing code to: 1) Eliminate the possibility of
    75                 updating the container before CN_ENDEDIT is called. 2) Don't call RemoveCnrItems
    76                 for tree container and collector.
     75                updating the container before CN_ENDEDIT is called. 2) Don't call RemoveCnrItems
     76                for tree container and collector.
     77  09 Aug 15 SHL Expose GetTidForThread and rework usage
    7778
    7879***********************************************************************/
     
    163164    TIB *ptib;
    164165    BOOL yes;
    165     APIRET rc = DosGetInfoBlocks(&ptib, &ppib);
    166 
    167     if (rc) {
    168       Dos_Error(MB_CANCEL, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
    169                 PCSZ_DOSGETINFOBLOCKS);
     166    APIRET rc = xDosGetInfoBlocks(&ptib, &ppib);
     167
     168    if (rc)
    170169      yes = FALSE;
    171     }
    172170    else {
    173171      PID pid;
     
    190188 * window must exist and must be created by fm/2
    191189 * @param hwnd is window handle
    192  * @returns thread ordinal or -1 if error
     190 * @returns thread ordinal or 0 if error
    193191 */
    194192
    195 INT GetTidForWindow(HWND hwnd)
     193UINT GetTidForWindow(HWND hwnd)
    196194{
    197195    PIB *ppib;
    198196    TIB *ptib;
    199     LONG ordinal = -1;
    200     APIRET rc = DosGetInfoBlocks(&ptib, &ppib);
    201 
    202     if (rc) {
    203       Dos_Error(MB_CANCEL, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
    204                 PCSZ_DOSGETINFOBLOCKS);
    205     }
     197    LONG ordinal;
     198    APIRET rc = xDosGetInfoBlocks(&ptib, &ppib);
     199
     200    if (rc)
     201      ordinal = 0;
    206202    else {
    207203      PID pid;
    208204      TID tid;
    209       if (!WinQueryWindowProcess(hwnd, &pid, &tid))
    210         Win_Error(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__, "WinQueryWindowProcess failed for %X", hwnd);
    211       else if (pid != ppib->pib_ulpid)
    212         Runtime_Error(pszSrcFile, __LINE__, "hwnd %X not created by fm/2", hwnd);
     205      if (!WinQueryWindowProcess(hwnd, &pid, &tid)) {
     206        ordinal = -1;
     207        Win_Error(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__, "WinQueryWindowProcess failed for hwnd %x", hwnd);
     208      }
     209      else if (pid != ppib->pib_ulpid) {
     210        ordinal = 0;
     211        Runtime_Error(pszSrcFile, __LINE__, "hwnd %x not created by fm/2 process", hwnd);
     212      }
    213213      else
    214214        ordinal = ptib->tib_ptib2->tib2_ultid;
     
    217217}
    218218
     219#endif // FORTIFY
     220
    219221/**
    220  * Return thread ordinal for current thread
    221  * @returns thread ordinal or -1 if error
     222 * Return thread ordinal (1..n) for current thread
     223 * @returns thread ordinal or 0 if error
     224 * 2015-08-09 SHL changed return
    222225 */
    223226
    224 INT GetTidForThread(VOID)
     227UINT GetTidForThread(VOID)
    225228{
    226229    PIB *ppib;
    227230    TIB *ptib;
    228     LONG ordinal = -1;
    229     APIRET rc = DosGetInfoBlocks(&ptib, &ppib);
    230 
    231     if (rc) {
    232       Dos_Error(MB_CANCEL, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
    233                 PCSZ_DOSGETINFOBLOCKS);
    234     }
     231    LONG ordinal = 0;
     232    APIRET rc = xDosGetInfoBlocks(&ptib, &ppib);
     233
     234    if (rc)
     235      ordinal = 0;
    235236    else
    236237      ordinal = ptib->tib_ptib2->tib2_ultid;
     
    238239    return ordinal;
    239240}
    240 
    241 #endif // FORTIFY
    242241
    243242VOID SetShiftState(VOID)
     
    522521      hasAccessDT = TRUE;
    523522      if (driveflags[x] & DRIVE_NOEASUPPORT) {
    524         hasSubjects  = FALSE;
    525         hasLongNames = FALSE;
     523        hasSubjects  = FALSE;
     524        hasLongNames = FALSE;
    526525      }
    527526      else {
    528         hasSubjects  = TRUE;
    529         hasLongNames = TRUE;
     527        hasSubjects  = TRUE;
     528        hasLongNames = TRUE;
    530529      }
    531530    }
     
    534533      hasAccessDT = FALSE;
    535534      if (driveflags[x] & DRIVE_NOEASUPPORT) {
    536         hasSubjects  = FALSE;
    537         hasLongNames = FALSE;
     535        hasSubjects  = FALSE;
     536        hasLongNames = FALSE;
    538537      }
    539538      else {
    540         hasSubjects  = TRUE;
    541         hasLongNames = TRUE;
     539        hasSubjects  = TRUE;
     540        hasLongNames = TRUE;
    542541      }
    543542    }
     
    547546      hasAccessDT = FALSE;
    548547      if (driveflags[x] & DRIVE_NOEASUPPORT) {
    549         hasSubjects  = FALSE;
    550         hasLongNames = FALSE;
     548        hasSubjects  = FALSE;
     549        hasLongNames = FALSE;
    551550      }
    552551      else {
    553         hasSubjects  = TRUE;
    554         hasLongNames = TRUE;
     552        hasSubjects  = TRUE;
     553        hasLongNames = TRUE;
    555554      }
    556555    }
     
    585584                  GetPString(IDS_CRTIME),
    586585                  pds->detailscrtime ? hasCreateDT : FALSE,
    587                   FALSE);
     586                  FALSE);
    588587  if (pds->detailslongname && !pds->detailssubject && hasSubjects) {
    589588    AdjustCnrColVis(hwndCnr,
    590                     compare ? GetPString(IDS_STATUS) : GetPString(IDS_SUBJ),
     589                    compare ? GetPString(IDS_STATUS) : GetPString(IDS_SUBJ),
    591590                    TRUE,
    592                     FALSE);
     591                    FALSE);
    593592    AdjustCnrColVis(hwndCnr,
    594                     GetPString(IDS_LNAME),
    595                     pds->detailslongname ? hasLongNames : FALSE,
    596                     FALSE);
     593                    GetPString(IDS_LNAME),
     594                    pds->detailslongname ? hasLongNames : FALSE,
     595                    FALSE);
    597596    WinSendMsg(hwndCnr, CM_INVALIDATEDETAILFIELDINFO, MPVOID, MPVOID);
    598597  }
    599598  else
    600599    AdjustCnrColVis(hwndCnr,
    601                     GetPString(IDS_LNAME),
    602                     pds->detailslongname ? hasLongNames : FALSE,
    603                     FALSE);
     600                    GetPString(IDS_LNAME),
     601                    pds->detailslongname ? hasLongNames : FALSE,
     602                    FALSE);
    604603  AdjustCnrColVis(hwndCnr,
    605                   compare ? GetPString(IDS_STATUS) : GetPString(IDS_SUBJ),
    606                   pds->detailssubject ? hasSubjects : FALSE,
    607                   FALSE);
     604                  compare ? GetPString(IDS_STATUS) : GetPString(IDS_SUBJ),
     605                  pds->detailssubject ? hasSubjects : FALSE,
     606                  FALSE);
    608607  WinSendMsg(hwndCnr, CM_INVALIDATEDETAILFIELDINFO, MPVOID, MPVOID);
    609608}
     
    621620  if (!directory) {
    622621    AdjustCnrColVis(hwndCnr,
    623                     compare ? GetPString(IDS_STATUS) : GetPString(IDS_SUBJ),
    624                     pds->detailssubject,
    625                     FALSE);
     622                    compare ? GetPString(IDS_STATUS) : GetPString(IDS_SUBJ),
     623                    pds->detailssubject,
     624                    FALSE);
    626625    AdjustCnrColVis(hwndCnr, GetPString(IDS_LADATE), pds->detailsladate, FALSE);
    627626    AdjustCnrColVis(hwndCnr, GetPString(IDS_LATIME), pds->detailslatime, FALSE);
     
    693692    if (!dsDirCnrDefault.fSubjectInLeftPane)
    694693      pfiLastLeftCol = pfi;
    695     else 
     694    else
    696695      pfiLastLeftCol = pfi->pNextFieldInfo;
    697696
     
    703702    pfi->flTitle = CFA_LEFT | CFA_FITITLEREADONLY;
    704703    pfi->pTitleData = isCompCnr ? (PSZ)GetPString(IDS_STATUS) :
    705                                   (PSZ)GetPString(IDS_SUBJ);
     704                                  (PSZ)GetPString(IDS_SUBJ);
    706705    pfi->offStruct = FIELDOFFSET(CNRITEM, pszSubject);
    707706    pfi->cxWidth = dsDirCnrDefault.SubjectDisplayWidth;
     
    884883              xfree(psz, pszSrcFile, __LINE__);
    885884            }
    886             else {
    887               psz = xrealloc(pci->pszSubject, retlen + 1, pszSrcFile, __LINE__);
    888               if (psz)
    889                 pci->pszSubject = psz;
    890               else {
    891                 xfree(pci->pszSubject, pszSrcFile, __LINE__);
    892                 pci->pszSubject = NullStr;
    893                 return FALSE; // out of memory
    894               }
    895             }
     885            else {
     886              psz = xrealloc(pci->pszSubject, retlen + 1, pszSrcFile, __LINE__);
     887              if (psz)
     888                pci->pszSubject = psz;
     889              else {
     890                xfree(pci->pszSubject, pszSrcFile, __LINE__);
     891                pci->pszSubject = NullStr;
     892                return FALSE; // out of memory
     893              }
     894            }
    896895          }
    897896          else {
     
    949948              xfree(psz, pszSrcFile, __LINE__);
    950949            }
    951             else {
    952               psz = xrealloc(pci->pszLongName, retlen + 1, pszSrcFile, __LINE__);
    953               if (psz)
    954                 pci->pszLongName = psz;
    955               else {
    956                 xfree(pci->pszLongName, pszSrcFile, __LINE__);
    957                 pci->pszLongName = NullStr;
    958                 return FALSE; // out of memory
    959               }
    960             }
     950            else {
     951              psz = xrealloc(pci->pszLongName, retlen + 1, pszSrcFile, __LINE__);
     952              if (psz)
     953                pci->pszLongName = psz;
     954              else {
     955                xfree(pci->pszLongName, pszSrcFile, __LINE__);
     956                pci->pszLongName = NullStr;
     957                return FALSE; // out of memory
     958              }
     959            }
    961960          }
    962961          else {
     
    967966          return (MRESULT) WriteLongName(pci->pszFileName, longname);
    968967        }
    969         else {
    970           WinQueryWindowText(hwndMLE, sizeof(testname), testname);
    971           // fixme to check for other illegal chars? GKY 11 Jul 15
     968        else {
     969          WinQueryWindowText(hwndMLE, sizeof(testname), testname);
     970          // fixme to check for other illegal chars? GKY 11 Jul 15
    972971          if (strchr(testname, '?') || strchr(testname, '*'))
    973972            return (MRESULT) FALSE;
     
    977976          if (!IsFullName(testname))
    978977            Runtime_Error(pszSrcFile, __LINE__, "bad name");
    979           else {
     978          else {
    980979            if (DosQueryPathInfo(testname, //Why does this return 0 when the file doesn't exist?
    981980                                 FIL_QUERYFULLNAME, // No new directory creation?
     
    985984                                 FIL_QUERYFULLNAME,
    986985                                 oldname, sizeof(oldname)))
    987               strcpy(oldname, pci->pszFileName);
     986              strcpy(oldname, pci->pszFileName);
    988987            WinSetWindowText(hwndMLE, oldname);
    989             if (strcmp(oldname, newname)) { 
    990               if (stricmp(oldname, newname) && IsFile(newname) != -1) {
    991                 if (!fAlertBeepOff)
    992                   DosBeep(50, 100);       
     988            if (strcmp(oldname, newname)) {
     989              if (stricmp(oldname, newname) && IsFile(newname) != -1) {
     990                if (!fAlertBeepOff)
     991                  DosBeep(50, 100);
    993992                return (MRESULT) FALSE;    // exists; disallow
    994993              }
     
    1000999              if (docopyf(MOVE, oldname, newname))
    10011000                Runtime_Error(pszSrcFile, __LINE__, "docopyf");
    1002               else {
    1003                 fPostName = TRUE;
     1001              else {
     1002                fPostName = TRUE;
    10041003              }
    10051004              if (fResetVerify) {
     
    10201019
    10211020      if (fPostName) {
    1022         CHAR *filename;
    1023         DIRCNRDATA *dcd;
    1024 
    1025         if (!dcd)
    1026           dcd = INSTDATA(hwnd);
    1027         filename = xstrdup(oldname, pszSrcFile, __LINE__);
    1028         if (filename) {
    1029           if (!PostMsg(hwnd,UM_FIXEDITNAME, MPVOID, MPFROMP(filename)))
    1030             free(filename);
    1031         }
    1032         if (strcmp(newname, NullStr)) {
    1033           filename = xstrdup(newname, pszSrcFile, __LINE__);
    1034           if (filename) {
    1035             if (!PostMsg(hwnd, UM_FIXEDITNAME, MPVOID, MPFROMP(filename)))
    1036               free(filename);
    1037           }
    1038         }
    1039         fPostName = FALSE;
     1021        CHAR *filename;
     1022        DIRCNRDATA *dcd;
     1023
     1024        if (!dcd)
     1025          dcd = INSTDATA(hwnd);
     1026        filename = xstrdup(oldname, pszSrcFile, __LINE__);
     1027        if (filename) {
     1028          if (!PostMsg(hwnd,UM_FIXEDITNAME, MPVOID, MPFROMP(filename)))
     1029            free(filename);
     1030        }
     1031        if (strcmp(newname, NullStr)) {
     1032          filename = xstrdup(newname, pszSrcFile, __LINE__);
     1033          if (filename) {
     1034            if (!PostMsg(hwnd, UM_FIXEDITNAME, MPVOID, MPFROMP(filename)))
     1035              free(filename);
     1036          }
     1037        }
     1038        fPostName = FALSE;
    10401039      }
    10411040      if (pci && (INT) pci != -1 && !IsRoot(pci->pszFileName)) {
     
    13521351    while (info) {
    13531352      WinSendMsg(mit.hwndSubMenu, MM_DELETEITEM,
    1354                 MPFROMSHORT((SHORT) (info->ID)), MPVOID);
     1353                MPFROMSHORT((SHORT) (info->ID)), MPVOID);
    13551354      x++;
    13561355      info = info->next;
     
    13581357    while (numitems != MIT_ERROR) { // Delete items that were deleted from commands since the ID is gone
    13591358      numitems = (SHORT) WinSendMsg(mit.hwndSubMenu, MM_ITEMIDFROMPOSITION,
    1360                                     MPFROMSHORT((SHORT) 1), MPVOID);
     1359                                    MPFROMSHORT((SHORT) 1), MPVOID);
    13611360      WinSendMsg(mit.hwndSubMenu, MM_DELETEITEM,
    1362                 MPFROMSHORT(numitems), MPVOID);
     1361                MPFROMSHORT(numitems), MPVOID);
    13631362    }
    13641363    if (hwndCnr && cmdhead) {
     
    13671366      while (info) {
    13681367
    1369         CHAR s[CCHMAXPATH + 24];
     1368        CHAR s[CCHMAXPATH + 24];
    13701369
    13711370        sprintf(s,
    1372                 "%s {%i} %s%s%s",
     1371                "%s {%i} %s%s%s",
    13731372                info->title, info->ID,
    13741373                info->HotKeyID && info->HotKeyID < IDM_COMMANDNUM20 ? "\tCtrl + " : NullStr,
    1375                 info->HotKeyID && info->HotKeyID > IDM_COMMANDNUM19 ? "\tAlt + " : NullStr,
    1376                 info->HotKeyID && ((info->HotKeyID > IDM_COMMANDNUM9 &&
    1377                                    info->HotKeyID < IDM_COMMANDNUM20) ||
    1378                 info->HotKeyID > IDM_COMMANDNUM29) ? "Shift + " : NullStr);
     1374                info->HotKeyID && info->HotKeyID > IDM_COMMANDNUM19 ? "\tAlt + " : NullStr,
     1375                info->HotKeyID && ((info->HotKeyID > IDM_COMMANDNUM9 &&
     1376                                   info->HotKeyID < IDM_COMMANDNUM20) ||
     1377                info->HotKeyID > IDM_COMMANDNUM29) ? "Shift + " : NullStr);
    13791378        if (info->HotKeyID)
    13801379          sprintf(&s[strlen(s)], "%d",
    1381                   (((info->HotKeyID - IDM_COMMANDNUM0) % 10) + 1) == 10 ? 0 :
    1382                    ((info->HotKeyID - IDM_COMMANDNUM0) % 10) + 1);
    1383         mi.id = (USHORT) info->ID; 
     1380                  (((info->HotKeyID - IDM_COMMANDNUM0) % 10) + 1) == 10 ? 0 :
     1381                   ((info->HotKeyID - IDM_COMMANDNUM0) % 10) + 1);
     1382        mi.id = (USHORT) info->ID;
    13841383        mi.afAttribute = (info->flags & ONCE ? MIA_CHECKED : 0) |
    13851384                         (info->flags & PROMPT ? MIA_FRAMED : 0);
     
    14731472      PrfQueryProfileData(fmprof, appname, s, (PVOID) &pds->SubjectDisplayWidth, &size);
    14741473      if (pds->SubjectDisplayWidth < 50)
    1475         pds->SubjectDisplayWidth = 0;
     1474        pds->SubjectDisplayWidth = 0;
    14761475      else if (pds->SubjectDisplayWidth > 1000)
    1477         pds->SubjectDisplayWidth = 1000;
     1476        pds->SubjectDisplayWidth = 1000;
    14781477    }
    14791478  }
     
    17061705
    17071706  for (;;) {
    1708     pmi = (PMINIRECORDCORE) WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS,
     1707    pmi = (PMINIRECORDCORE) WinSendMsg(hwndCnr,
     1708                                       CM_QUERYRECORDEMPHASIS,
    17091709                                       MPFROMLONG(CMA_FIRST),
    17101710                                       MPFROMSHORT(attrib));
    1711     if ((!pmi || (INT) pmi == -1) && attrib == CRA_SELECTED)    // punt
    1712       attrib = CRA_CURSORED;
     1711    if ((!pmi || (INT)pmi == -1) && attrib == CRA_SELECTED)
     1712      attrib = CRA_CURSORED;            // Retry cursored
    17131713    else
    1714       break;
    1715   }
    1716   return ((INT)pmi == -1) ? NULL : pmi;
     1714      break;                            // punt
     1715  }
     1716  return (INT)pmi == -1 ? NULL : pmi;
    17171717}
    17181718
     
    20362036                            fDefaultDeletePerm ? IDM_PERMDELETE : IDM_DELETE);
    20372037      SetConditionalCascade(CollectorFileMenu, IDM_OPENSUBMENU,
    2038                             IDM_OPENDEFAULT);
     2038                            IDM_OPENDEFAULT);
    20392039      SetConditionalCascade(CollectorFileMenu, IDM_OPENSUBCNRMENU,
    20402040                            IDM_OPENWINDOW);
  • trunk/dll/misc.h

    r1444 r1840  
    77
    88  Copyright (c) 1993-98 M. Kimes
    9   Copyright (c) 2008, 2009 Steven H. Levine
     9  Copyright (c) 2008, 2015 Steven H. Levine
    1010
    1111  17 Jul 08 SHL Baseline
     
    1313  22 Jul 09 GKY Check if drives support EAs add driveflag for this
    1414  22 Jul 09 GKY Allow .LONGNAME to be displayed for FAT drives.
     15  09 Aug 15 SHL Expose GetTidForThread
    1516
    1617***********************************************************************/
     
    2526#include "dircnrs.h"            // typedef for DETAILS_SETTINGS
    2627
     28UINT GetTidForThread(VOID);
     29
    2730#ifdef FORTIFY
    28 INT GetTidForThread(VOID);
    29 INT GetTidForWindow(HWND hwnd);
     31UINT GetTidForWindow(HWND hwnd);
    3032#endif
    3133
Note: See TracChangeset for help on using the changeset viewer.