Annotation of mstools/samples/sdktools/perfmon/perfmops.c, revision 1.1.1.1

1.1       root        1: 
                      2: #include "perfmon.h"
                      3: #include <lmcons.h>
                      4: #include <lmerr.h>
                      5: #include <lmapibuf.h>
                      6: #include <lmwksta.h>
                      7: #include <stdio.h>         // for sprintf
                      8: #include <locale.h>        // for setlocale
                      9: #include "utils.h"
                     10: 
                     11: #include "perfdata.h"      // for OpenSystemPerfData
                     12: #include "alert.h"         // for AlertInsertLine
                     13: #include "report.h"        // for ReportInsertLine
                     14: #include "grafdata.h"      // for GraphInsertLine
                     15: #include "log.h"           // for OpenLog
                     16: #include "fileopen.h"      // for FileGetName
                     17: #include "fileutil.h"      // for FileRead etc
                     18: #include "command.h"       // for PrepareMenu
                     19: #include "playback.h"      // for PlayingBackLog & LogPositionSystemTime
                     20: #include "system.h"
                     21: #include "globals.h"
                     22: #include "pmemory.h"       // for MemoryFree
                     23: #include "status.h"        // for StatusLineReady
                     24: #include "pmhelpid.h"
                     25: 
                     26: // test for delimiter, end of line and non-digit characters
                     27: // used by IsNumberInUnicodeList routine
                     28: //
                     29: #define DIGIT       1
                     30: #define DELIMITER   2
                     31: #define INVALID     3
                     32: 
                     33: // globals used for International Date and Time formats
                     34: enum DATE_STYLE
                     35:    {
                     36:    YEAR_FIRST,       // YYMMDD
                     37:    DAY_FIRST,        // DDMMYY
                     38:    MONTH_FIRST       // MMDDYY
                     39:    } DateStyle ;
                     40: 
                     41: TCHAR szInternational[] = TEXT("Intl") ;
                     42: TCHAR sz1159[6] ;       // AM String
                     43: TCHAR sz2359[6] ;       // PM String
                     44: int   iTime ;           // = 0 for 12-hour format,  <> 0 for 24-hour format
                     45: int   YearCharCount ;   // = 4 for 1990, = 2 for 90
                     46: 
                     47: TCHAR szDateFormat[ResourceStringLen] ;
                     48: TCHAR szTimeFormat[ResourceStringLen] ;
                     49: 
                     50: TCHAR LeadingZeroStr [] = TEXT("%02d") ;
                     51: TCHAR NoLeadingZeroStr [] = TEXT("%d") ;
                     52: 
                     53: #define EvalThisChar(c,d) ( \
                     54:      (c == d) ? DELIMITER : \
                     55:      (c == 0) ? DELIMITER : \
                     56:      (c < (WCHAR)'0') ? INVALID : \
                     57:      (c > (WCHAR)'9') ? INVALID : \
                     58:      DIGIT)
                     59: 
                     60: #define SIZE_OF_BIGGEST_INTEGER  16 
                     61: // #define SIZE_OF_BIGGEST_INTEGER (16*sizeof(WCHAR)) 
                     62: 
                     63: 
                     64: //==========================================================================//
                     65: //                                  Typedefs                                //
                     66: //==========================================================================//
                     67: 
                     68: BOOL AddObjectToSystem ( PLINE , PPERFSYSTEM );
                     69: BOOL GetLogFileComputer (HWND hWndParent, LPTSTR lpComputerName, DWORD BufferSize) ;
                     70: 
                     71: 
                     72: HWND PerfmonViewWindow (void)
                     73: /*
                     74:    Effect:        Return the current data window, i.e. the window currently
                     75:                   visible as the client area of Perfmon.  This is either a
                     76:                   chart, log, alert, or report window.
                     77: */
                     78:    {  // PerfmonDataWindow
                     79:    switch (iPerfmonView)
                     80:       {  // switch
                     81:       case IDM_VIEWLOG:
                     82:          return (hWndLog) ;
                     83: 
                     84:       case IDM_VIEWALERT:
                     85:          return (hWndAlert) ;
                     86: 
                     87:       case IDM_VIEWREPORT:
                     88:          return (hWndReport) ;
                     89: 
                     90: //      case IDM_VIEWCHART:
                     91:       default:
                     92:          return (hWndGraph) ;
                     93:       }  // switch
                     94:    }  // PerfmonViewWindow
                     95: 
                     96: 
                     97: 
                     98: 
                     99: BOOL ChooseComputer (HWND hWndParent, LPTSTR lpszComputer)
                    100: /*
                    101:    Effect:        Display the choose Domain/Computer dialog
                    102:                   If the user selects a computer,  copy the 
                    103:                   computer name to lpszComputer and return
                    104:                   nonnull. If the user cancels, return FALSE.
                    105: 
                    106:    Assert:        lpszComputer is at least MAX_SYSTEM_NAME_LENGTH + 1
                    107:                   characters.
                    108: */
                    109:    {  // ChooseComputer
                    110:    BOOL                     bSuccess ;
                    111:    WCHAR                    wszWideComputer[MAX_COMPUTERNAME_LENGTH + 3] ;
                    112: 
                    113:    // bring up the select Log Computer dialog
                    114:    bSuccess = GetLogFileComputer (hWndParent, wszWideComputer,
                    115:          sizeof(wszWideComputer) / sizeof(WCHAR)) ;
                    116: 
                    117:    if (bSuccess)
                    118:       {
                    119:       lstrcpy (lpszComputer, wszWideComputer) ;
                    120:       }
                    121: 
                    122:    return (bSuccess) ;
                    123:    }  // ChooseComputer
                    124:    
                    125: 
                    126: void SystemTimeDateString (SYSTEMTIME *pSystemTime,
                    127:                            LPTSTR lpszDate)
                    128:    {
                    129:    int      wYear ;
                    130:    
                    131:    wYear = pSystemTime->wYear ;
                    132:    if (YearCharCount == 2)
                    133:       {
                    134:       wYear %= 100 ;
                    135:       }
                    136: 
                    137:    switch (DateStyle)
                    138:       {
                    139:       case YEAR_FIRST:
                    140:          TSPRINTF (lpszDate, szDateFormat,
                    141:              wYear, pSystemTime->wMonth, pSystemTime->wDay) ;
                    142:          break ;
                    143: 
                    144:       case DAY_FIRST:
                    145:          TSPRINTF (lpszDate, szDateFormat,
                    146:              pSystemTime->wDay, pSystemTime->wMonth, wYear) ;
                    147:          break ;
                    148: 
                    149:       case MONTH_FIRST:
                    150:       default:
                    151:          TSPRINTF (lpszDate, szDateFormat,
                    152:              pSystemTime->wMonth, pSystemTime->wDay, wYear) ;
                    153:          break ;
                    154:       }
                    155:    }
                    156: 
                    157: 
                    158: void SystemTimeTimeString (SYSTEMTIME *pSystemTime,
                    159:                            LPTSTR lpszTime)
                    160:    {
                    161:    int            iHour ;
                    162:    BOOL           bPM ;
                    163: 
                    164:    if (iTime)
                    165:       {
                    166:       // 24 hor format
                    167:       TSPRINTF (lpszTime, szTimeFormat,
                    168:                 pSystemTime->wHour,
                    169:                 pSystemTime->wMinute,
                    170:                 (FLOAT)pSystemTime->wSecond +
                    171:                 (FLOAT)pSystemTime->wMilliseconds / (FLOAT) 1000.0) ;
                    172: 
                    173:       }
                    174:    else
                    175:       {
                    176:       // 12 hour format
                    177:       iHour = pSystemTime->wHour ;
                    178:       bPM = (iHour >= 12) ;
                    179: 
                    180:       if (iHour > 12)
                    181:          iHour -= 12 ;
                    182:       else if (!iHour)
                    183:          iHour = 12 ;
                    184: 
                    185:       TSPRINTF (lpszTime, szTimeFormat,
                    186:                 iHour, pSystemTime->wMinute,
                    187:                 (FLOAT)pSystemTime->wSecond + 
                    188:                 (FLOAT)pSystemTime->wMilliseconds / (FLOAT) 1000.0 ,
                    189:                 bPM ? sz2359 : sz1159) ;
                    190:       }
                    191:    }
                    192:             
                    193: 
                    194: void ShowPerfmonMenu (BOOL bMenu)
                    195:    {  // ShowPerfmonMenu
                    196:    if (!bMenu)
                    197:       {
                    198:       WindowEnableTitle (hWndMain, FALSE) ;
                    199: //      SetMenu(hWndMain, NULL) ;
                    200:       }
                    201:    else
                    202:       {
                    203:       WindowEnableTitle (hWndMain, TRUE) ;
                    204:       switch (iPerfmonView)
                    205:          {  // switch
                    206:          case IDM_VIEWCHART:
                    207:             SetMenu (hWndMain, hMenuChart) ;
                    208:             break ;
                    209: 
                    210:          case IDM_VIEWALERT:
                    211:             SetMenu (hWndMain, hMenuAlert) ;
                    212:             break ;
                    213: 
                    214:          case IDM_VIEWLOG:
                    215:             SetMenu (hWndMain, hMenuLog) ;
                    216:             break ;
                    217: 
                    218:          case IDM_VIEWREPORT:
                    219:             SetMenu (hWndMain, hMenuReport) ;
                    220:             break ;
                    221:          }  // switch
                    222:       }  // else
                    223: 
                    224:    if (bMenu != Options.bMenubar)
                    225:       {
                    226:       PrepareMenu (GetMenu (hWndMain)) ;
                    227:       }
                    228: 
                    229:    Options.bMenubar = bMenu ;
                    230:    }  // ShowPerfmonMenu
                    231: 
                    232: 
                    233: 
                    234: void SmallFileSizeString (int iFileSize,
                    235:                           LPTSTR lpszFileText)
                    236:    {  // SmallFileSizeString
                    237:    if (iFileSize < 1000000)
                    238:       TSPRINTF (lpszFileText, TEXT(" %1.1fK "), ((FLOAT) iFileSize) / 1000.0) ;
                    239:    else
                    240:       TSPRINTF (lpszFileText, TEXT(" %1.1fM "), ((FLOAT) iFileSize) / 1000000.0) ;
                    241:    }  // SmallFileSizeString   
                    242: 
                    243: 
                    244: 
                    245: BOOL DoWindowDrag (LPARAM lParam)
                    246:    {
                    247:    if (!Options.bMenubar && !IsZoomed (hWndMain))
                    248:       {
                    249:       SendMessage (hWndMain, WM_NCLBUTTONDOWN, HTCAPTION, lParam) ;
                    250:       return (TRUE) ;
                    251:       }
                    252:    else
                    253:       return (FALSE) ;
                    254:    }
                    255: 
                    256: 
                    257: 
                    258: // Filetimes are in 100NS units
                    259: #define FILETIMES_PER_SECOND     10000000
                    260: 
                    261: 
                    262: int SystemTimeDifference (SYSTEMTIME *pst1, SYSTEMTIME *pst2)
                    263:    {
                    264:    LARGE_INTEGER  li1, li2 ;
                    265:    LARGE_INTEGER  liDifference, liDifferenceSeconds ;
                    266:    DWORD          uRemainder ;
                    267: 
                    268: 
                    269:    SystemTimeToFileTime (pst1, (FILETIME *) &li1) ;
                    270:    SystemTimeToFileTime (pst2, (FILETIME *) &li2) ;
                    271: 
                    272:    liDifference = LargeIntegerSubtract (li2, li1) ;
                    273:    liDifference.LowPart += (FILETIMES_PER_SECOND / 2) ;
                    274: 
                    275:    liDifferenceSeconds =
                    276:      ExtendedLargeIntegerDivide (liDifference, FILETIMES_PER_SECOND, 
                    277:                                     &uRemainder) ;
                    278: 
                    279:    return (liDifferenceSeconds.LowPart) ;
                    280:    }
                    281:  
                    282: 
                    283: BOOL InsertLine (PLINE pLine)
                    284: {  // InsertLine
                    285: 
                    286:     BOOL bReturn;
                    287:    
                    288:     switch (pLine->iLineType) {  // switch
                    289:         case LineTypeChart:
                    290:             bReturn = ChartInsertLine (pGraphs, pLine) ;
                    291:             break ;
                    292: 
                    293:         case LineTypeAlert:
                    294:             bReturn = AlertInsertLine (hWndAlert, pLine) ;
                    295:             break ;
                    296: 
                    297:         case LineTypeReport:
                    298:             bReturn = ReportInsertLine (hWndReport, pLine) ;
                    299:             break ;
                    300: 
                    301:     }  // switch
                    302: 
                    303:     return bReturn;
                    304: 
                    305: }  // InsertLine
                    306:    
                    307: 
                    308: BOOL OpenWorkspace (HANDLE hFile, DWORD dwMajorVersion, DWORD dwMinorVersion)
                    309:    {
                    310:    DISKWORKSPACE  DiskWorkspace ;
                    311:    
                    312:    if (!FileRead (hFile, &DiskWorkspace, sizeof(DiskWorkspace)))
                    313:       {
                    314:       goto Exit0 ;
                    315:       }
                    316: 
                    317:    if (DiskWorkspace.ChartOffset == 0 &&
                    318:        DiskWorkspace.AlertOffset == 0 &&
                    319:        DiskWorkspace.LogOffset == 0 &&
                    320:        DiskWorkspace.ReportOffset == 0)
                    321:       {
                    322:       goto Exit0 ;
                    323:       }
                    324: 
                    325:    switch (dwMajorVersion)
                    326:       {  // switch
                    327:       case (1):
                    328: 
                    329:          if (dwMinorVersion == 1 || dwMinorVersion == 2)
                    330:             {
                    331:             // setup the window position and size
                    332:             SetWindowPlacement (hWndMain, &(DiskWorkspace.WindowPlacement)) ;
                    333:             }
                    334: 
                    335:          // change to the view as stored in the workspace file
                    336:          SendMessage (hWndMain, WM_COMMAND,
                    337:             (LONG)DiskWorkspace.iPerfmonView, 0L) ;
                    338:          iPerfmonView = DiskWorkspace.iPerfmonView ;
                    339: 
                    340:          if (DiskWorkspace.ChartOffset)
                    341:             {
                    342:             if (FileSeekBegin(hFile, DiskWorkspace.ChartOffset) == 0xFFFFFFFF)
                    343:                {
                    344:                goto Exit0 ;
                    345:                }
                    346: 
                    347:             if (!OpenChart (hWndGraph,
                    348:                            hFile,
                    349:                            dwMajorVersion,
                    350:                            dwMinorVersion,
                    351:                            FALSE))
                    352:                {
                    353:                goto Exit0 ;
                    354:                }
                    355:             }
                    356:          if (DiskWorkspace.AlertOffset)
                    357:             {
                    358:             if (FileSeekBegin(hFile, DiskWorkspace.AlertOffset) == 0xffffffff)
                    359:                {
                    360:                goto Exit0 ;
                    361:                }
                    362:             if (!OpenAlert (hWndAlert,
                    363:                        hFile,
                    364:                        dwMajorVersion,
                    365:                        dwMinorVersion,
                    366:                        FALSE))
                    367:                {
                    368:                goto Exit0 ;
                    369:                }
                    370:             }
                    371:          if (DiskWorkspace.LogOffset)
                    372:             {
                    373:             if (FileSeekBegin(hFile, DiskWorkspace.LogOffset) == 0xffffffff)
                    374:                {
                    375:                goto Exit0 ;
                    376:                }
                    377:             if (!OpenLog (hWndLog,
                    378:                           hFile,
                    379:                           dwMajorVersion,
                    380:                           dwMinorVersion,
                    381:                           FALSE))
                    382:                {
                    383:                goto Exit0 ;
                    384:                }
                    385:             }
                    386:          if (DiskWorkspace.ReportOffset)
                    387:             {
                    388:             if (FileSeekBegin(hFile, DiskWorkspace.ReportOffset) == 0xffffffff)
                    389:                {
                    390:                goto Exit0 ;
                    391:                }
                    392:             if (!OpenReport (hWndReport,
                    393:                         hFile,
                    394:                         dwMajorVersion,
                    395:                         dwMinorVersion,
                    396:                         FALSE))
                    397:                {
                    398:                goto Exit0 ;
                    399:                }
                    400:             }
                    401:          break ;
                    402: 
                    403:       default:
                    404:          goto Exit0 ;
                    405:          break ;
                    406:       }
                    407: 
                    408:    CloseHandle (hFile) ;
                    409:    return (TRUE) ;
                    410: 
                    411: 
                    412: Exit0:
                    413:    CloseHandle (hFile) ;
                    414:    return (FALSE) ;
                    415: 
                    416:    }  // OpenWorkspace
                    417: 
                    418: 
                    419: BOOL SaveWorkspace (void)
                    420:    {
                    421:    DISKWORKSPACE  DiskWorkspace ;
                    422:    PERFFILEHEADER FileHeader ;
                    423:    HANDLE         hFile ;
                    424:    long           DiskWorkspacePosition ;
                    425:    TCHAR          szFileName[FilePathLen] ;
                    426:    BOOL           bWriteErr = TRUE ;
                    427: 
                    428:    if (!FileGetName (PerfmonViewWindow(), IDS_WORKSPACEFILE, szFileName))
                    429:       {
                    430:       return (FALSE) ;
                    431:       }
                    432: 
                    433:    hFile = FileHandleCreate (szFileName) ;
                    434:    if (!hFile)
                    435:       {
                    436:       DlgErrorBox (PerfmonViewWindow (), ERR_CANT_OPEN, szFileName) ;
                    437:       return (FALSE) ;
                    438:       }
                    439: 
                    440:    memset (&FileHeader, 0, sizeof (FileHeader)) ;
                    441:    lstrcpy (FileHeader.szSignature, szPerfWorkspaceSignature) ;
                    442:    FileHeader.dwMajorVersion = WorkspaceMajorVersion ;
                    443:    FileHeader.dwMinorVersion = WorkspaceMinorVersion ;
                    444: 
                    445:    if (!FileWrite (hFile, &FileHeader, sizeof (PERFFILEHEADER)))
                    446:       {
                    447:       goto Exit0 ;
                    448:       }
                    449: 
                    450:    // reserve space in the file.  We will fill up info
                    451:    // and write into this guy later.
                    452:    memset (&DiskWorkspace, 0, sizeof(DiskWorkspace)) ;
                    453:    DiskWorkspacePosition = FileTell (hFile) ;
                    454:    GetWindowPlacement (hWndMain, &(DiskWorkspace.WindowPlacement)) ;
                    455:    if (!FileWrite (hFile, &DiskWorkspace, sizeof (DISKWORKSPACE)))
                    456:       {
                    457:       goto Exit0 ;
                    458:       }
                    459: 
                    460:    // put in chart data
                    461:    DiskWorkspace.ChartOffset = FileTell (hFile) ;
                    462:    if (!SaveChart (hWndGraph, hFile, 0))
                    463:       {
                    464:       goto Exit0 ;
                    465:       }
                    466: 
                    467:    // put in alert data
                    468:    DiskWorkspace.AlertOffset = FileTell (hFile) ;
                    469:    if (!SaveAlert (hWndAlert, hFile, 0))
                    470:       {
                    471:       goto Exit0 ;
                    472:       }
                    473: 
                    474:    // put in log data
                    475:    DiskWorkspace.LogOffset = FileTell (hFile) ;
                    476:    if (!SaveLog (hWndLog, hFile, 0))
                    477:       {
                    478:       goto Exit0 ;
                    479:       }
                    480: 
                    481:    // put in report data
                    482:    DiskWorkspace.ReportOffset = FileTell (hFile) ;
                    483:    if (!SaveReport (hWndReport, hFile, 0))
                    484:       {
                    485:       goto Exit0 ;
                    486:       }
                    487: 
                    488:    // put in the disk header info
                    489:    DiskWorkspace.iPerfmonView = iPerfmonView ;
                    490:    FileSeekBegin (hFile, DiskWorkspacePosition) ;
                    491:    if (!FileWrite (hFile, &DiskWorkspace, sizeof (DISKWORKSPACE)))
                    492:       {
                    493:       goto Exit0 ;
                    494:       }
                    495:    bWriteErr = FALSE ;
                    496: 
                    497: Exit0:
                    498:    if (bWriteErr)
                    499:       {
                    500:       DlgErrorBox (PerfmonViewWindow (), ERR_SETTING_FILE, szFileName) ;
                    501:       }
                    502: 
                    503:    CloseHandle (hFile) ;
                    504: 
                    505:    }  // SaveWorkspace
                    506: 
                    507: void SetPerfmonOptions (OPTIONS *pOptions)
                    508:    {
                    509:    Options = *pOptions ;
                    510:    ShowPerfmonMenu (Options.bMenubar) ;
                    511:    SizePerfmonComponents () ;
                    512:    WindowSetTopmost (hWndMain, Options.bAlwaysOnTop) ;
                    513:    }  // SetPerfmonOptions
                    514: 
                    515: void ChangeSaveFileName (LPTSTR szFileName, int iPMView)
                    516:    {
                    517:    LPTSTR   *ppFullName ;
                    518:    LPTSTR   *ppFileName ;
                    519:    BOOL     errorInput = FALSE ;
                    520: 
                    521: 
                    522:    switch (iPMView)
                    523:       {
                    524:       case IDM_VIEWCHART:
                    525:          ppFileName = &pChartFileName ;
                    526:          ppFullName = &pChartFullFileName ;
                    527:          break ;
                    528: 
                    529:       case IDM_VIEWALERT:
                    530:          ppFileName = &pAlertFileName ;
                    531:          ppFullName = &pAlertFullFileName ;
                    532:          break ;
                    533: 
                    534:       case IDM_VIEWREPORT:
                    535:          ppFileName = &pReportFileName ;
                    536:          ppFullName = &pReportFullFileName ;
                    537:          break ;
                    538: 
                    539:       case IDM_VIEWLOG:
                    540:          ppFileName = &pLogFileName ;
                    541:          ppFullName = &pLogFullFileName ;
                    542:          break ;
                    543: 
                    544:       default:
                    545:          errorInput = TRUE ;
                    546:          break ;
                    547:       }
                    548: 
                    549:    if (errorInput)
                    550:       {
                    551:       return ;
                    552:       }
                    553: 
                    554:    // release last filename
                    555:    if (*ppFullName)
                    556:       {
                    557:       MemoryFree (*ppFullName) ;
                    558:       *ppFileName = NULL ;
                    559:       *ppFullName = NULL ;
                    560:       }
                    561: 
                    562:    // allocate new file name and display it
                    563:    if (szFileName && (*ppFullName = StringAllocate (szFileName)))
                    564:       {
                    565:       *ppFileName = ExtractFileName (*ppFullName) ;
                    566:       }
                    567: 
                    568:    StatusLineReady (hWndStatus) ;
                    569: 
                    570:    }     // ChangeSaveFileName
                    571: 
                    572: 
                    573: 
                    574: 
                    575: BOOL
                    576: IsNumberInUnicodeList (
                    577:     IN DWORD   dwNumber,
                    578:     IN LPWSTR  lpwszUnicodeList
                    579: )
                    580: /*++
                    581: 
                    582: IsNumberInUnicodeList
                    583: 
                    584: Arguments:
                    585:         
                    586:     IN dwNumber
                    587:         DWORD number to find in list
                    588: 
                    589:     IN lpwszUnicodeList
                    590:         Null terminated, Space delimited list of decimal numbers
                    591: 
                    592: Return Value:
                    593: 
                    594:     TRUE:
                    595:             dwNumber was found in the list of unicode number strings
                    596: 
                    597:     FALSE:
                    598:             dwNumber was not found in the list.
                    599: 
                    600: --*/
                    601: {
                    602:     DWORD   dwThisNumber;
                    603:     WCHAR   *pwcThisChar;
                    604:     BOOL    bValidNumber;
                    605:     BOOL    bNewItem;
                    606:     WCHAR   wcDelimiter;    // could be an argument to be more flexible
                    607: 
                    608:     if (lpwszUnicodeList == 0) return FALSE;    // null pointer, # not founde
                    609: 
                    610:     pwcThisChar = lpwszUnicodeList;
                    611:     dwThisNumber = 0;
                    612:     wcDelimiter = (WCHAR)' ';
                    613:     bValidNumber = FALSE;
                    614:     bNewItem = TRUE;
                    615:     
                    616:     while (TRUE) {
                    617:         switch (EvalThisChar (*pwcThisChar, wcDelimiter)) {
                    618:             case DIGIT:
                    619:                 // if this is the first digit after a delimiter, then 
                    620:                 // set flags to start computing the new number
                    621:                 if (bNewItem) {
                    622:                     bNewItem = FALSE;
                    623:                     bValidNumber = TRUE;
                    624:                 }
                    625:                 if (bValidNumber) {
                    626:                     dwThisNumber *= 10;
                    627:                     dwThisNumber += (*pwcThisChar - (WCHAR)'0');
                    628:                 }
                    629:                 break;
                    630:             
                    631:             case DELIMITER:
                    632:                 // a delimter is either the delimiter character or the 
                    633:                 // end of the string ('\0') if when the delimiter has been
                    634:                 // reached a valid number was found, then compare it to the
                    635:                 // number from the argument list. if this is the end of the
                    636:                 // string and no match was found, then return.
                    637:                 //
                    638:                 if (bValidNumber) {
                    639:                     if (dwThisNumber == dwNumber) return TRUE;
                    640:                     bValidNumber = FALSE;
                    641:                 }
                    642:                 if (*pwcThisChar == 0) {
                    643:                     return FALSE;
                    644:                 } else {
                    645:                     bNewItem = TRUE;
                    646:                     dwThisNumber = 0;
                    647:                 }
                    648:                 break;
                    649: 
                    650:             case INVALID:
                    651:                 // if an invalid character was encountered, ignore all
                    652:                 // characters up to the next delimiter and then start fresh.
                    653:                 // the invalid number is not compared.
                    654:                 bValidNumber = FALSE;
                    655:                 break;
                    656: 
                    657:             default:
                    658:                 break;
                    659: 
                    660:         }
                    661:         pwcThisChar++;
                    662:     }
                    663: 
                    664: }   // IsNumberInUnicodeList
                    665: 
                    666: BOOL
                    667: AppendObjectToValueList (
                    668:     DWORD   dwObjectId,
                    669:     PWSTR   pwszValueList
                    670: )
                    671: /*++
                    672: 
                    673: AppendObjectToValueList
                    674: 
                    675: Arguments:
                    676:         
                    677:     IN dwNumber
                    678:         DWORD number to insert in list
                    679: 
                    680:     IN PUNICODE_STRING
                    681:         pointer to unicode string structure that contains buffer that is
                    682:         Null terminated, Space delimited list of decimal numbers that
                    683:         may have this number appended to. 
                    684: 
                    685: Return Value:
                    686: 
                    687:     TRUE:
                    688:             dwNumber was added to list
                    689: 
                    690:     FALSE:
                    691:             dwNumber was not added. (because it's already there or
                    692:                 an error occured)
                    693: 
                    694: --*/
                    695: {
                    696:     WCHAR           tempString [SIZE_OF_BIGGEST_INTEGER] ;
                    697:     DWORD           dwStrLen, dwNewStrLen;
                    698: 
                    699:     if (!pwszValueList) {
                    700:         return FALSE;
                    701:     }
                    702: 
                    703:     if (IsNumberInUnicodeList(dwObjectId, pwszValueList)) {
                    704:         return FALSE;   // object already in list
                    705:     } else {
                    706:         // append the new object id the  value list
                    707:         TSPRINTF (tempString, TEXT("%d "), dwObjectId) ;
                    708: 
                    709:         // see if string will fit (compare in bytes)
                    710: 
                    711:         dwStrLen = MemorySize (pwszValueList) - sizeof (UNICODE_NULL);
                    712: 
                    713:         dwNewStrLen = (lstrlen (pwszValueList) + lstrlen (tempString)) *
                    714:             sizeof (WCHAR);
                    715: 
                    716:         if (dwNewStrLen <= dwStrLen) {
                    717:             lstrcat (pwszValueList, tempString);
                    718:             return TRUE;
                    719:         } else {
                    720:             SetLastError (ERROR_OUTOFMEMORY); 
                    721:             return FALSE;
                    722:         }
                    723:     }
                    724: }
                    725: 
                    726: BOOL
                    727: AddObjectToSystem (
                    728:     PLINE pLine,
                    729:     PPERFSYSTEM pFirstSystem
                    730: )
                    731: {
                    732:     PPERFSYSTEM     pSystem;
                    733:     
                    734:     if ((ARGUMENT_PRESENT (pLine)) && (ARGUMENT_PRESENT(pFirstSystem))) {
                    735:         pSystem = SystemGet (pFirstSystem, pLine->lnSystemName);
                    736: 
                    737:         if (pSystem) {
                    738:             return AppendObjectToValueList (
                    739:                 pLine->lnObject.ObjectNameTitleIndex,
                    740:                 pSystem->lpszValue);
                    741:         } else {
                    742:             return FALSE;
                    743:         }
                    744:     } else {
                    745:         return FALSE;
                    746:     }
                    747: }
                    748: 
                    749: BOOL
                    750: RemoveObjectsFromSystem (
                    751:     PPERFSYSTEM pSystem
                    752: )
                    753: {
                    754:     DWORD   dwBufferSize = 0;
                    755: 
                    756:     if (ARGUMENT_PRESENT (pSystem)) {
                    757:         // don't do foreign computers
                    758:         if (pSystem->lpszValue && !strsame (pSystem->lpszValue, L"Foreign")){
                    759:             dwBufferSize = MemorySize (pSystem->lpszValue);
                    760: 
                    761:             memset (pSystem->lpszValue, 0, dwBufferSize);
                    762:             return TRUE;
                    763:         } else {
                    764:             return FALSE;
                    765:         }
                    766:     } else {
                    767:         return FALSE;
                    768:     }
                    769: 
                    770: 
                    771: }    
                    772: 
                    773: BOOL
                    774: BuildValueListForSystems (
                    775:     PPERFSYSTEM pSystemListHead,
                    776:     PLINE       pLineListHead
                    777: )
                    778: /*++
                    779: 
                    780: BuildValueListForSystem
                    781: 
                    782: Abstract:
                    783: 
                    784:     Walks down line list and builds the list of objects to query from
                    785:     that system containing that line.
                    786: 
                    787: Arguments:
                    788: 
                    789:     pSystemListHead
                    790: 
                    791:         head of system linked list
                    792:         each system will have it's "Value Name" list appended
                    793: 
                    794:     pLineListHead
                    795: 
                    796:         head of line list that will be searched for creating the new
                    797:         valuelist.
                    798: 
                    799: 
                    800: Return Value:
                    801: 
                    802: 
                    803: --*/
                    804: {
                    805: 
                    806:     PPERFSYSTEM     pSystem;    // system that contains current line
                    807:     PLINE           pThisLine;  // current line
                    808: 
                    809:     if ((ARGUMENT_PRESENT (pLineListHead)) && (ARGUMENT_PRESENT(pSystemListHead))) {
                    810:         // clear system entries:
                    811:         for (pSystem = pSystemListHead; pSystem; pSystem = pSystem->pSystemNext) {
                    812:             if (pSystem) {
                    813:                 RemoveObjectsFromSystem (pSystem);
                    814:             }
                    815:         }
                    816: 
                    817:         // add new enties
                    818: 
                    819:         for (pThisLine = pLineListHead; pThisLine; pThisLine = pThisLine->pLineNext) {
                    820: 
                    821:             pSystem = SystemGet (pSystemListHead, pThisLine->lnSystemName);
                    822:             if (pSystem) {
                    823:                 AppendObjectToValueList (
                    824:                     pThisLine->lnObject.ObjectNameTitleIndex,
                    825:                     pSystem->lpszValue);
                    826: 
                    827:             }
                    828:         }
                    829:         return TRUE;
                    830:     } else {    // argument(s) missing
                    831:         return FALSE;
                    832:     }
                    833: }
                    834: 
                    835: // define in Addline.c
                    836: extern   PLINESTRUCT       pLineEdit ;
                    837: #define  bEditLine (pLineEdit != NULL)
                    838: 
                    839: BOOL
                    840: SetSystemValueNameToGlobal (
                    841:     PPERFSYSTEM pSystem
                    842: )
                    843: {
                    844: 
                    845:     if (!bEditLine && ARGUMENT_PRESENT(pSystem)) {
                    846:         if (pSystem->lpszValue && RemoveObjectsFromSystem(pSystem)) {
                    847:             lstrcpy (
                    848:                 pSystem->lpszValue,
                    849:                 TEXT("Global ")) ;
                    850:             return TRUE;
                    851:         } else {
                    852:             return FALSE;
                    853:         }
                    854:     } else {
                    855:         return FALSE;
                    856:     }
                    857: }
                    858: 
                    859: BOOL
                    860: RemoveUnusedSystems (
                    861:     PPERFSYSTEM pSystemHead,
                    862:     PLINE       pLineHead
                    863: )
                    864: /*++
                    865: 
                    866:     walks system list and removes systems with no lines from list
                    867: 
                    868: --*/
                    869: {
                    870:     PPERFSYSTEM pSystem;
                    871:     PPERFSYSTEM pLastSystem;
                    872:     PLINE       pLine;
                    873:     BOOL        bSystemFound;
                    874: 
                    875:     pLastSystem = NULL;
                    876: 
                    877:     if ((ARGUMENT_PRESENT (pLineHead)) && (ARGUMENT_PRESENT(pSystemHead))) {
                    878:         for (pSystem = pSystemHead;
                    879:              pSystem;
                    880:              pLastSystem = pSystem, pSystem = pSystem->pSystemNext) {
                    881:             
                    882:             if (pSystem) {
                    883:                 bSystemFound = FALSE;
                    884:                 // walk lines to see if this system has a line
                    885:                 for (pLine = pLineHead; pLine; pLine = pLine->pLineNext) {
                    886:                     // if system in line is this system, then bailout
                    887:                     if (strsame (pLine->lnSystemName, pSystem->sysName)) {
                    888:                         bSystemFound = TRUE;
                    889:                         break;
                    890:                     }
                    891:                 }
                    892:                 
                    893:                 if (!bSystemFound) {    // delete this unused system
                    894: 
                    895:                     // fix pointers
                    896:                     pLastSystem->pSystemNext = pSystem->pSystemNext;
                    897: 
                    898:                     SystemFree (pSystem, TRUE);
                    899: 
                    900:                     // set pointer back to a valid structure
                    901:                     pSystem = pLastSystem; 
                    902:                 }
                    903:             }
                    904:         }
                    905:     }
                    906:     return TRUE;
                    907: }
                    908: 
                    909: void CreatePerfmonSystemObjects ()
                    910: {
                    911:    ColorBtnFace = GetSysColor (COLOR_BTNFACE) ;
                    912:    hBrushFace = CreateSolidBrush (ColorBtnFace) ;
                    913:    hPenHighlight = CreatePen (PS_SOLID, 1, GetSysColor (COLOR_BTNHIGHLIGHT)) ;
                    914:    hPenShadow = CreatePen (PS_SOLID, 1, GetSysColor (COLOR_BTNSHADOW)) ;
                    915: }
                    916: 
                    917: void DeletePerfmonSystemObjects ()
                    918: {
                    919:    if (hBrushFace)
                    920:       {
                    921:       DeleteBrush (hBrushFace) ;
                    922:       hBrushFace = 0 ;
                    923:       }
                    924:    if (hPenHighlight)
                    925:       {
                    926:       DeletePen (hPenHighlight) ;
                    927:       hPenHighlight = 0 ;
                    928:       }
                    929:    if (hPenShadow)
                    930:       {
                    931:       DeletePen (hPenShadow) ;
                    932:       hPenShadow = 0 ;
                    933:       }
                    934: }
                    935: 
                    936: // This routine count the number of the same charatcer in the input string
                    937: int  SameCharCount (LPTSTR pInputString)
                    938: {
                    939:    int      Count = 0 ;
                    940:    TCHAR    InputChar = *pInputString ;
                    941: 
                    942:    if (InputChar)
                    943:       {
                    944:       while (InputChar == *pInputString)
                    945:          {
                    946:          Count ++ ;
                    947:          pInputString ++ ;
                    948:          }
                    949:       }
                    950:    return (Count) ;
                    951: }
                    952: 
                    953: // create the format to be used in SystemTimeDateString()
                    954: BOOL CreateDateFormat (LPTSTR pShortDate)
                    955: {
                    956:    int   iIndex ;
                    957:    int   iDayCount ;
                    958:    int   iMonthCount ;
                    959:    int   DateSeparatorCount ;
                    960:    TCHAR szDateSeparator [10] ;
                    961:    BOOL  bFirstLeading, bSecondLeading, bThirdLeading ;
                    962: 
                    963:    // get the date format based on the first char
                    964:    if (*pShortDate == TEXT('M') || *pShortDate == TEXT('m'))
                    965:       {
                    966:       DateStyle = MONTH_FIRST ;
                    967:       }
                    968:    else if (*pShortDate == TEXT('D') || *pShortDate == TEXT('d'))
                    969:       {
                    970:       DateStyle = DAY_FIRST ;
                    971:       }
                    972:    else if (*pShortDate == TEXT('Y') || *pShortDate == TEXT('y'))
                    973:       {
                    974:       DateStyle = YEAR_FIRST ;
                    975:       }
                    976:    else
                    977:       {
                    978:       // bad format 
                    979:       return FALSE ;
                    980:       }
                    981: 
                    982:    bFirstLeading = bSecondLeading = bThirdLeading = FALSE ;
                    983: 
                    984:    switch (DateStyle)
                    985:       {
                    986:       case YEAR_FIRST:
                    987:          // YYYY-MM-DD
                    988:          YearCharCount = SameCharCount (pShortDate) ;
                    989:          pShortDate += YearCharCount ;
                    990:          DateSeparatorCount = SameCharCount (pShortDate) ;
                    991: 
                    992:          // get the separator string
                    993:          for (iIndex = 0; iIndex < DateSeparatorCount; iIndex ++)
                    994:             {
                    995:             szDateSeparator [iIndex] = *pShortDate++ ;
                    996:             }
                    997:          szDateSeparator [iIndex] = TEXT('\0') ;
                    998: 
                    999:          iMonthCount = SameCharCount (pShortDate) ;
                   1000:          pShortDate += iMonthCount + DateSeparatorCount ;
                   1001:          iDayCount = SameCharCount (pShortDate) ;
                   1002: 
                   1003:          if (YearCharCount == 2)
                   1004:             {
                   1005:             bFirstLeading = TRUE ;
                   1006:             }
                   1007: 
                   1008:          if (iMonthCount == 2)
                   1009:             {
                   1010:             bSecondLeading = TRUE ;
                   1011:             }
                   1012: 
                   1013:          if (iDayCount == 2)
                   1014:             {
                   1015:             bThirdLeading = TRUE ;
                   1016:             }
                   1017: 
                   1018:          break ;
                   1019: 
                   1020:       case MONTH_FIRST:
                   1021:          // MM-DD-YYYY
                   1022:          iMonthCount = SameCharCount (pShortDate) ;
                   1023:          pShortDate += iMonthCount ;
                   1024:          DateSeparatorCount = SameCharCount (pShortDate) ;
                   1025: 
                   1026:          // get the separator string
                   1027:          for (iIndex = 0; iIndex < DateSeparatorCount; iIndex ++)
                   1028:             {
                   1029:             szDateSeparator [iIndex] = *pShortDate++ ;
                   1030:             }
                   1031:          szDateSeparator [iIndex] = TEXT('\0') ;
                   1032:          
                   1033:          iDayCount = SameCharCount (pShortDate) ;
                   1034:          pShortDate += iMonthCount + DateSeparatorCount ;
                   1035:          YearCharCount = SameCharCount (pShortDate) ;
                   1036: 
                   1037: 
                   1038:          if (iMonthCount == 2)
                   1039:             {
                   1040:             bFirstLeading = TRUE ;
                   1041:             }
                   1042: 
                   1043:          if (iDayCount == 2)
                   1044:             {
                   1045:             bSecondLeading = TRUE ;
                   1046:             }
                   1047: 
                   1048:          if (YearCharCount == 2)
                   1049:             {
                   1050:             bThirdLeading = TRUE ;
                   1051:             }
                   1052: 
                   1053:          break ;
                   1054: 
                   1055:       case DAY_FIRST:
                   1056:          // DD-MM-YYYY
                   1057:          iDayCount = SameCharCount (pShortDate) ;
                   1058:          pShortDate += iDayCount ;
                   1059:          DateSeparatorCount = SameCharCount (pShortDate) ;
                   1060: 
                   1061:          // get the separator string
                   1062:          for (iIndex = 0; iIndex < DateSeparatorCount; iIndex ++)
                   1063:             {
                   1064:             szDateSeparator [iIndex] = *pShortDate++ ;
                   1065:             }
                   1066:          szDateSeparator [iIndex] = TEXT('\0') ;
                   1067:          
                   1068:          iMonthCount = SameCharCount (pShortDate) ;
                   1069:          pShortDate += iMonthCount + DateSeparatorCount ;
                   1070:          YearCharCount = SameCharCount (pShortDate) ;
                   1071: 
                   1072:          if (iDayCount == 2)
                   1073:             {
                   1074:             bFirstLeading = TRUE ;
                   1075:             }
                   1076: 
                   1077:          if (iMonthCount == 2)
                   1078:             {
                   1079:             bSecondLeading = TRUE ;
                   1080:             }
                   1081: 
                   1082:          if (YearCharCount == 2)
                   1083:             {
                   1084:             bThirdLeading = TRUE ;
                   1085:             }
                   1086: 
                   1087:          break ;
                   1088:       }
                   1089: 
                   1090:    // now generate the date format
                   1091:    lstrcpy (szDateFormat, bFirstLeading ? LeadingZeroStr : NoLeadingZeroStr) ;
                   1092:    lstrcat (szDateFormat, szDateSeparator) ;
                   1093:    lstrcat (szDateFormat, bSecondLeading ? LeadingZeroStr : NoLeadingZeroStr) ;
                   1094:    lstrcat (szDateFormat, szDateSeparator) ;
                   1095:    lstrcat (szDateFormat, bThirdLeading ? LeadingZeroStr : NoLeadingZeroStr) ;
                   1096: 
                   1097:    return TRUE ;
                   1098: }
                   1099: 
                   1100: BOOL CreateTimeFormat (LPTSTR pTimeSeparator, int iLeadingZero)
                   1101: {
                   1102:    // create the format to be used in SystemTimeTimeString 
                   1103:    if (iLeadingZero)
                   1104:       {
                   1105:       lstrcpy (szTimeFormat, LeadingZeroStr) ;
                   1106:       }
                   1107:    else
                   1108:       {
                   1109:       lstrcpy (szTimeFormat, NoLeadingZeroStr) ;
                   1110:       }
                   1111: 
                   1112:    lstrcat (szTimeFormat, pTimeSeparator) ;
                   1113:    lstrcat (szTimeFormat, LeadingZeroStr) ;
                   1114:    lstrcat (szTimeFormat, pTimeSeparator) ;
                   1115: //   lstrcat (szTimeFormat, LeadingZeroStr) ;
                   1116: 
                   1117:    // for the msec
                   1118:    lstrcat (szTimeFormat, TEXT("%02.1f")) ;
                   1119:    if (iTime == 0)
                   1120:       {
                   1121:       lstrcat (szTimeFormat, TEXT(" %s ")) ;
                   1122:       }
                   1123: 
                   1124:    return TRUE ;
                   1125: }  // CreateTimeFormats
                   1126: 
                   1127: BOOL GetInternational()
                   1128: {
                   1129:    TCHAR szShortDate[40] ;
                   1130:    TCHAR szTime[40] ;   // time separator
                   1131:    DWORD RetCode ;
                   1132:    int   iTLZero = 0;      // = 0 for no leading zero, <> 0 for leading zero
                   1133:    CHAR  aLanguageStr [2] ;
                   1134:    LPSTR pRetStr ;
                   1135: 
                   1136:    // read the data from the win.ini (which i smapped to registry)
                   1137:    RetCode = GetProfileString(szInternational,
                   1138:       TEXT("sShortDate"), szShortDate, szShortDate, sizeof(szShortDate)/sizeof(TCHAR));
                   1139:    
                   1140:    if (RetCode)
                   1141:       {
                   1142:       RetCode = GetProfileString(szInternational,
                   1143:          TEXT("sTime"), szTime, szTime, sizeof(szTime)/sizeof(TCHAR));
                   1144:       }
                   1145: 
                   1146: 
                   1147:    if (RetCode)
                   1148:       {
                   1149:       iTime   = GetProfileInt(szInternational, TEXT("iTime"), iTime);
                   1150:       iTLZero = GetProfileInt(szInternational, TEXT("iTLZero"), iTLZero);
                   1151: 
                   1152:       if (iTime == 0)
                   1153:          {
                   1154:          // get the AM PM strings for 12-hour format.
                   1155:          // These two strings could be NULL.
                   1156:          sz1159[0] = sz2359[0] = TEXT('\0') ;
                   1157:          GetProfileString(szInternational,
                   1158:             TEXT("s1159"), sz1159, sz1159, sizeof(sz1159)/sizeof(TCHAR));
                   1159: 
                   1160:          GetProfileString(szInternational,
                   1161:             TEXT("s2359"), sz2359, sz2359, sizeof(sz2359)/sizeof(TCHAR));
                   1162:          }
                   1163:       }
                   1164: 
                   1165:    // create the two formats
                   1166:    if (RetCode)
                   1167:       {
                   1168:       RetCode = (DWORD) CreateDateFormat (szShortDate) ;
                   1169:       }
                   1170: 
                   1171:    if (RetCode)
                   1172:       {
                   1173:       RetCode = (DWORD) CreateTimeFormat (szTime, iTLZero) ;
                   1174:       }
                   1175: 
                   1176:    // use the system default language numeric
                   1177:    aLanguageStr[0] = '\0' ;
                   1178:    pRetStr = setlocale(LC_NUMERIC, aLanguageStr);
                   1179: 
                   1180:    return (RetCode != 0) ;
                   1181: }  // GetInternational
                   1182: 
                   1183: 
                   1184: // this routine is called to get the date/time formats either
                   1185: // for the resource or from the registry.
                   1186: void GetDateTimeFormats ()
                   1187: {
                   1188:    PALERT        pAlert ;
                   1189:    PLOG          pLog ;
                   1190:    if (!GetInternational())
                   1191:       {
                   1192:       // GetInternational failed, then get default formats from resource
                   1193:       iTime = 0 ;
                   1194:       DateStyle = MONTH_FIRST ;
                   1195:       YearCharCount = 4 ;
                   1196:       StringLoad (IDS_S1159, sz1159) ;
                   1197:       StringLoad (IDS_S2359, sz2359) ;
                   1198:       StringLoad (IDS_TIME_FORMAT, szTimeFormat) ;
                   1199:       StringLoad (IDS_SHORT_DATE_FORMAT, szDateFormat) ;
                   1200:       }
                   1201:    WindowInvalidate (PerfmonViewWindow()) ;
                   1202: 
                   1203:    // reset all the field taht may be affected by the
                   1204:    // language numberic changes
                   1205: 
                   1206:    pAlert = AlertData (hWndMain) ;
                   1207:    pLog = LogData (hWndMain) ;
                   1208: 
                   1209:    if (pAlert)
                   1210:       {
                   1211:       DialogSetInterval (hWndAlert, IDD_ALERTINTERVAL, pAlert->iIntervalMSecs) ;
                   1212:       }
                   1213: 
                   1214:    if (pLog)
                   1215:       {
                   1216:       DialogSetInterval (hWndLog, IDD_LOGINTERVAL, pLog->iIntervalMSecs) ;
                   1217:       }
                   1218: }  // GetDateTimeFormats
                   1219: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.