Ignore:
Timestamp:
Dec 24, 2002, 8:44:35 AM (23 years ago)
Author:
umoeller
Message:

Misc fixes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/helpers/tmsgfile.c

    r222 r238  
    148148 *@@added V0.9.18 (2002-03-24) [umoeller]
    149149 *@@changed V0.9.20 (2002-07-19) [umoeller]: optimized, no longer holding all msgs im mem
     150 *@@changed V1.0.1 (2002-12-16) [pr]: Ctrl-Z fix
    150151 */
    151152
     
    181182                cbRead - 1);    // not including null byte
    182183
    183         // convert to plain C format
    184         /* xstrConvertLineFormat(&pTmf->strContent,
    185                               CRLF2LF);
    186         */
    187 
    188         // kick out all the comments
    189         /*
    190         while (pStartOfMarker = strstr(pTmf->strContent.psz, "\n;"))
    191         {
    192             // copy the next line over this
    193             PCSZ pEOL = strhFindEOL(pStartOfMarker + 2, NULL);
    194             xstrrpl(&pTmf->strContent,
    195                     // ofs of first char to replace: "\n;"
    196                     pStartOfMarker - pTmf->strContent.psz,
    197                     // no. of chars to replace:
    198                     pEOL - pStartOfMarker,
    199                     // string to replace chars with:
    200                     NULL,
    201                     // length of replacement string:
    202                     0);
    203         }
    204         */
    205 
    206         // free excessive memory
    207         // xstrShrink(&pTmf->strContent);
    208 
     184        // go build a tree of all message IDs...
    209185        pStartOfFile = strContents.psz;
    210 
    211         // go build a tree of all message IDs...
    212186
    213187        // find first start message marker
     
    301275                        pNew->cbText = strlen(pStartOfText);
    302276
    303                 // remove trailing newlines
     277                // remove trailing newlines and Ctrl-Z
    304278                while (    (pNew->cbText)
    305279                        && (    (pStartOfText[pNew->cbText - 1] == '\n')
    306280                             || (pStartOfText[pNew->cbText - 1] == '\r')
     281                             || (pStartOfText[pNew->cbText - 1] == '\x1a') // V1.0.1 (2002-12-16) [pr]
    307282                           )
    308283                      )
     
    335310 *
    336311 *      Use tmfCloseMessageFile to close the file
    337  *      again and free all resources. This thing
    338  *      can allocate quite a bit of memory.
     312 *      again and free all resources.
    339313 *
    340314 *      Returns:
     
    415389STATIC VOID FreeInternalMem(PTMFMSGFILE pTmf)
    416390{
    417     LONG   cItems;
     391    LONG    cItems;
    418392    TREE**  papNodes;
    419393
    420     if (cItems = pTmf->cIDs)
     394    if (    (cItems = pTmf->cIDs)
     395         && (papNodes = treeBuildArray(pTmf->IDsTreeRoot,
     396                                       &cItems))
     397       )
    421398    {
    422         if (papNodes = treeBuildArray(pTmf->IDsTreeRoot,
    423                                       &cItems))
     399        ULONG ul;
     400        for (ul = 0; ul < cItems; ul++)
    424401        {
    425             ULONG ul;
    426             for (ul = 0; ul < cItems; ul++)
    427             {
    428                 PMSGENTRY pNodeThis = (PMSGENTRY)(papNodes[ul]);
    429 
    430                 xstrClear(&pNodeThis->strID);
    431 
    432                 free(pNodeThis);
    433             }
    434 
    435             free(papNodes);
     402            PMSGENTRY pNodeThis = (PMSGENTRY)(papNodes[ul]);
     403
     404            xstrClear(&pNodeThis->strID);
     405
     406            free(pNodeThis);
    436407        }
     408
     409        free(papNodes);
    437410    }
    438411}
     
    464437    }
    465438
    466     return (ERROR_INVALID_PARAMETER);
     439    return ERROR_INVALID_PARAMETER;
    467440}
    468441
     
    503476                     ULONG cTableEntries)       // in: count of items in pTable or null
    504477{
    505     APIRET arc = NO_ERROR;
     478    APIRET  arc;
     479    ULONG   cbFile;
     480    PXFILE  pFile;
    506481
    507482    if (    (!pMsgFile)
    508483         || (!pMsgFile->pszFilename)
    509484       )
    510         arc = ERROR_INVALID_PARAMETER;
    511     else
     485        return ERROR_INVALID_PARAMETER;
     486
     487    // open the file again V0.9.20 (2002-07-19) [umoeller]
     488    if (!(arc = doshOpen(pMsgFile->pszFilename,
     489                         XOPEN_READ_EXISTING,
     490                         &cbFile,
     491                         &pFile)))
    512492    {
    513         // open the file again V0.9.20 (2002-07-19) [umoeller]
    514         ULONG   cbFile;
    515         PXFILE  pFile;
    516         if (!(arc = doshOpen(pMsgFile->pszFilename,
    517                              XOPEN_READ_EXISTING,
    518                              &cbFile,
    519                              &pFile)))
     493        // check if last-write date/time changed compared
     494        // to the last time we opened the thing...
     495        // V0.9.18 (2002-03-24) [umoeller]
     496        FILESTATUS3 fs3;
     497        if (!(arc = DosQueryFileInfo(pFile->hf,
     498                                     FIL_STANDARD,
     499                                     &fs3,
     500                                     sizeof(fs3))))
    520501        {
    521             // check if last-write date/time changed compared
    522             // to the last time we opened the thing...
    523             // V0.9.18 (2002-03-24) [umoeller]
    524             FILESTATUS3 fs3;
    525             if (!(arc = DosQueryFileInfo(pFile->hf,
    526                                          FIL_STANDARD,
    527                                          &fs3,
    528                                          sizeof(fs3))))
     502            CHAR szTemp[30];
     503            dtCreateFileTimeStamp(szTemp,
     504                                  &fs3.fdateLastWrite,
     505                                  &fs3.ftimeLastWrite);
     506            if (strcmp(szTemp, pMsgFile->szTimestamp))
    529507            {
    530                 CHAR szTemp[30];
    531                 dtCreateFileTimeStamp(szTemp,
    532                                       &fs3.fdateLastWrite,
    533                                       &fs3.ftimeLastWrite);
    534                 if (strcmp(szTemp, pMsgFile->szTimestamp))
     508                // last write date changed:
     509                _Pmpf((__FUNCTION__ ": timestamp changed, recompiling"));
     510                FreeInternalMem(pMsgFile);
     511
     512                if (!(arc = LoadAndCompile(pMsgFile, pFile)))
     513                    strcpy(pMsgFile->szTimestamp, szTemp);
     514            }
     515        }
     516
     517        if (!arc)
     518        {
     519            // go find the message in the tree
     520            PMSGENTRY pEntry;
     521            if (!(pEntry = (PMSGENTRY)treeFind(pMsgFile->IDsTreeRoot,
     522                                               (ULONG)pcszMessageName,
     523                                               treeCompareStrings)))
     524                arc = ERROR_MR_MID_NOT_FOUND;
     525            else
     526            {
     527                PSZ     pszMsg;
     528                ULONG   cbRead = pEntry->cbText;
     529
     530                if (!(pszMsg = (PSZ)malloc(cbRead + 1)))
     531                    arc = ERROR_NOT_ENOUGH_MEMORY;
     532                else if (!(arc = doshReadAt(pFile,
     533                                            pEntry->ulOfsText,
     534                                            &cbRead,
     535                                            pszMsg,
     536                                            DRFL_NOCACHE | DRFL_FAILIFLESS)))
    535537                {
    536                     // last write date changed:
    537                     _Pmpf((__FUNCTION__ ": timestamp changed, recompiling"));
    538                     FreeInternalMem(pMsgFile);
    539 
    540                     if (!(arc = LoadAndCompile(pMsgFile, pFile)))
    541                         strcpy(pMsgFile->szTimestamp, szTemp);
    542                 }
    543             }
    544 
    545             if (!arc)
    546             {
    547                 // go find the message in the tree
    548                 PMSGENTRY pEntry;
    549                 if (!(pEntry = (PMSGENTRY)treeFind(pMsgFile->IDsTreeRoot,
    550                                                    (ULONG)pcszMessageName,
    551                                                    treeCompareStrings)))
    552                     arc = ERROR_MR_MID_NOT_FOUND;
    553                 else
    554                 {
    555                     PSZ     pszMsg;
    556                     ULONG   cbRead = pEntry->cbText;
    557 
    558                     if (!(pszMsg = (PSZ)malloc(cbRead + 1)))
    559                         arc = ERROR_NOT_ENOUGH_MEMORY;
    560                     else if (!(arc = doshReadAt(pFile,
    561                                                 pEntry->ulOfsText,
    562                                                 &cbRead,
    563                                                 pszMsg,
    564                                                 DRFL_NOCACHE | DRFL_FAILIFLESS)))
     538                    // null-terminate
     539                    pszMsg[cbRead] = '\0';
     540                    xstrset2(pstr,
     541                             pszMsg,
     542                             cbRead);
     543
     544                    // kick out \r\n
     545                    xstrConvertLineFormat(pstr,
     546                                          CRLF2LF);
     547
     548                    // now replace strings from the table
     549                    if (cTableEntries && pTable)
    565550                    {
    566                         // null-terminate
    567                         pszMsg[cbRead] = '\0';
    568                         xstrset2(pstr,
    569                                  pszMsg,
    570                                  cbRead);
    571 
    572                         // kick out \r\n
    573                         xstrConvertLineFormat(pstr,
    574                                               CRLF2LF);
    575 
    576                         // now replace strings from the table
    577                         if (cTableEntries && pTable)
     551                        CHAR szFind[10] = "%0";
     552                        ULONG ul;
     553                        for (ul = 0;
     554                             ul < cTableEntries;
     555                             ul++)
    578556                        {
    579                             CHAR szFind[10] = "%0";
    580                             ULONG ul;
    581                             for (ul = 0;
    582                                  ul < cTableEntries;
    583                                  ul++)
    584                             {
    585                                 ULONG ulOfs = 0;
    586 
    587                                 _ultoa(ul + 1, szFind + 1, 10);
    588                                 while (xstrFindReplaceC(pstr,
    589                                                         &ulOfs,
    590                                                         szFind,
    591                                                         pTable[ul]))
    592                                     ;
    593                             }
     557                            ULONG ulOfs = 0;
     558
     559                            _ultoa(ul + 1, szFind + 1, 10);
     560                            while (xstrFindReplaceC(pstr,
     561                                                    &ulOfs,
     562                                                    szFind,
     563                                                    pTable[ul]))
     564                                ;
    594565                        }
    595566                    }
    596567                }
    597568            }
    598 
    599             doshClose(&pFile);
    600569        }
     570
     571        doshClose(&pFile);
    601572    }
    602573
Note: See TracChangeset for help on using the changeset viewer.