home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / netds / sna / cpic / cpicsr.c < prev    next >
Text File  |  1997-04-09  |  29KB  |  800 lines

  1. /* CPICSR.C */
  2. /* (C) COPYRIGHT DATA CONNECTION LIMITED 1993 */
  3.  
  4. /*****************************************************************************/
  5. /* Change History                                                            */
  6. /*                                                                           */
  7. /*       30/06/93 NGR Created.                                               */
  8. /*****************************************************************************/
  9.  
  10. /*****************************************************************************/
  11. /*                                                                           */
  12. /* ROUTINE : CPICSR                                                          */
  13. /*                                                                           */
  14. /* FUNCTION: This file contains the main routines for CPI-C versions of the  */
  15. /*           send and receive TPs.                                           */
  16. /*           sending and receiving TPs SENDTP and RECVTP                     */
  17. /*                                                                           */
  18. /* INPUTS  : C:\CPICSEND.CFG (file) (documented below)                       */
  19. /*           C:\CPICRECV.CFG (file) (documented below)                       */
  20. /*           Note files are in executable's directory in WIN32               */
  21. /*                                                                           */
  22. /* OUTPUTS : CPICSEND.OUT                                                    */
  23. /*           CPICRECV.OUT                                                    */
  24. /*                                                                           */
  25. /*****************************************************************************/
  26.  
  27. /*****************************************************************************/
  28. /* Configuration files:                                                      */
  29. /*                                                                           */
  30. /* Configuration file is C:\CPICSEND.CFG or CPICRECV.CFG which contains      */
  31. /* the following, one per line in any order. If not present then the given   */
  32. /* default is assumed.                                                       */
  33. /*                                                                           */
  34. /* ResultFile = <Name of file for results, default C:\CPIC(SEND/RECV).OUT>   */
  35. /* NumConversations = <Number of conversations to be done, default = 1>      */
  36. /* LocalTPName = <Name to be used for TP started, default SENDTP/RECVTP>     */
  37. /* WaitMode = Yes/No/Block (default = No)                                    */
  38. /*            Yes      - Verbs are non-blocking but completed via CMWAIT     */
  39. /*            No       - Verbs are completed via posted Windows messages     */
  40. /*            Block    - All verbs are blocking                              */
  41. /*                                                                           */
  42. /* The following only apply to CPICSEND:                                     */
  43. /* SymDestName = <symbolic destination name, default = CPICRECV>             */
  44. /* NumSends = <number of CMSEND verbs per conversation, default = 2>         */
  45. /* ConfirmEvery = <number of CMSEND verbs between CMCFMs, default = 1>       */
  46. /* SendSize = <number of bytes per CMSEND, default = 1024>                   */
  47. /*                                                                           */
  48. /* The following only applies to CPICRECV:                                   */
  49. /* LocalTPName = <Name to be used for CMSLTP verb, default CPICRECV          */
  50. /*                                                                           */
  51. /* If NumConversations is zero, then the TPs will do an infinite number of   */
  52. /* conversations.                                                            */
  53. /* If NumSends is zero, then CPICSEND will never CMDEAL the first            */
  54. /* conversation.                                                             */
  55. /* If ConfirmEvery is zero, then SENDTP will not issue CONFIRM verbs.        */
  56. /*****************************************************************************/
  57.  
  58. #if (defined(WINDOWS)||defined(WIN32))
  59. #include <windows.h>
  60. HINSTANCE hInst;
  61. #endif
  62. #include <stdio.h>
  63. #include <stdlib.h>
  64. #include <string.h>
  65. #include <wincpic.h>
  66. #include "cpicsr.h"
  67.  
  68.  
  69. /*****************************************************************************/
  70. /* WinMain - reads initialisation info and controls message loop             */
  71. /*           NT and Win16 version                                            */
  72. /*****************************************************************************/
  73. int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  74.                    LPSTR lpCmdLine, int nCmdShow)
  75. {
  76.  
  77.   MSG msg;
  78.  
  79.   hInst = hInstance;
  80.  
  81.   ReadConfig();
  82.  
  83.   if (!InitialiseWinMain(hInstance))
  84.   {
  85.      return (FALSE);
  86.   }
  87.  
  88.   InitialiseMain();
  89.  
  90.   while(GetMessage(&msg,NULL,0,0))
  91.   {
  92.      TranslateMessage(&msg);
  93.      DispatchMessage(&msg);
  94.   }
  95.  
  96.   return msg.wParam;         /* save exit parameter for return               */
  97.  
  98. }
  99.  
  100. /*****************************************************************************/
  101. /* InitialiseWinMain - does the windows bits of initialisation               */
  102. /*****************************************************************************/
  103. BOOL InitialiseWinMain(HINSTANCE hInstance)
  104. {
  105.    WCPICDATA CPICData;
  106.    WNDCLASS class;
  107.    #define WinCPICVERSION  0x0001
  108.  
  109.    /**************************************************************************/
  110.    /* Startup WinAPPC                                                        */
  111.    /**************************************************************************/
  112.    if (WinCPICStartup(WinCPICVERSION,&CPICData))
  113.    {
  114.       return (FALSE);
  115.    }
  116.  
  117.    if ( (ASYNC_COMPLETE =
  118.          RegisterWindowMessage(WIN_CPIC_ASYNC_COMPLETE_MESSAGE)) == 0 )
  119.    {
  120.       return (0);
  121.    }
  122.  
  123.    /**************************************************************************/
  124.    /* Register Window Class for our icon                                     */
  125.    /**************************************************************************/
  126.  
  127.    class.style = 0;
  128.    class.lpfnWndProc   = (WNDPROC)TPWndProc;
  129.    class.cbClsExtra    = (DWORD)0;
  130.    class.cbWndExtra    = (DWORD)0;
  131.    class.hInstance     = hInstance;
  132.    class.hIcon         = LoadIcon(hInstance,"MainIcon");
  133.    class.hCursor       = LoadCursor(NULL, IDC_ARROW);
  134.    class.hbrBackground = GetStockObject(WHITE_BRUSH);
  135.    class.lpszMenuName  = (LPSTR) NULL;
  136.    class.lpszClassName = (LPSTR) "CPICSR\0";
  137.  
  138.    if (!RegisterClass(&class))
  139.    {
  140.      return (FALSE);
  141.    }
  142.  
  143.    /**************************************************************************/
  144.    /* Create the window                                                      */
  145.    /**************************************************************************/
  146. #ifdef CPICSEND
  147.    sprintf(title,"CPI-C Send TP\0");
  148. #else
  149.    sprintf(title,"CPI-C Receive TP\0");
  150. #endif
  151.  
  152.    if ((hWndMain = CreateWindow("CPICSR\0",        /* window class           */
  153.        title,                                      /* window name            */
  154.        WS_MINIMIZE|WS_OVERLAPPEDWINDOW,            /* window style           */
  155.        0,                                          /* x position             */
  156.        0,                                          /* y position             */
  157.        10,                                         /* width                  */
  158.        10,                                         /* height                 */
  159.        NULL,                                       /* parent handle          */
  160.        NULL,                                       /* menu or child ID       */
  161.        hInstance,                                  /* instance               */
  162.        NULL))                                      /* additional info        */
  163.        == NULL)
  164.    {
  165.       return (FALSE);
  166.    }
  167.  
  168.    ShowWindow(hWndMain, SW_MINIMIZE);
  169.  
  170.    /**************************************************************************/
  171.    /* Specify the window handle to be used, if this is NULL then we must use */
  172.    /* Wait_For_Conversation to wait for the verb to complete.                */
  173.    /**************************************************************************/
  174.    xchwnd((wait_mode || blocking) ? NULL : hWndMain, &return_code);
  175. #ifndef CPICSEND
  176.    /**************************************************************************/
  177.    /* Specify our local TP name. Note that because we have done this, the    */
  178.    /* cmaccp will return asynchronously using the current notification type  */
  179.    /**************************************************************************/
  180.    {
  181.       CM_INT32 temp_length;
  182.       CM_INT32 temp_return_code;
  183.       temp_length = strlen(LocalTPName);
  184.       cmsltp(LocalTPName,&temp_length,&temp_return_code);
  185.    }
  186. #endif
  187.  
  188.    return(TRUE);
  189.  
  190. }
  191.  
  192. /*****************************************************************************/
  193. /* Window proc for the iconised window                                       */
  194. /*****************************************************************************/
  195. LONG FAR PASCAL TPWndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
  196. {
  197.    if (message == ASYNC_COMPLETE)
  198.    {
  199.       return_code = (CM_RETURN_CODE) wParam;
  200.       IssueNextVerb();
  201.    }
  202.    else
  203.    {
  204.       switch (message)
  205.       {
  206.          case WM_CREATE:
  207.             /*****************************************************************/
  208.             /* Post a message to ourselves to kick off the first verb        */
  209.             /*****************************************************************/
  210.             PostMessage(hWnd, ASYNC_COMPLETE, 0, 0);
  211.             break;
  212.  
  213.          case WM_QUERYOPEN:
  214.             /*****************************************************************/
  215.             /* Prevent the window being opened                               */
  216.             /*****************************************************************/
  217.             break;
  218.  
  219.          case WM_CLOSE:
  220.             TPDead = TRUE;
  221.             WinCPICCleanup();
  222.             OutputResults();
  223.             return DefWindowProc(hWnd, message, wParam, lParam);
  224.             break;
  225.  
  226.          case WM_DESTROY:
  227.             PostQuitMessage(0);
  228.             break;
  229.  
  230.          default:
  231.             return DefWindowProc(hWnd, message, wParam, lParam);
  232.             break;
  233.       }
  234.    }
  235.    return 0l;
  236. }
  237.  
  238. /*****************************************************************************/
  239. /* InitialiseMain - blanks out variables and allocates buffers.              */
  240. /*****************************************************************************/
  241. void InitialiseMain()
  242. {
  243.    TPDead = FALSE;
  244.    FirstConv = TRUE;
  245.    last_verb = 0;
  246.    ConvCount = 0;
  247.  
  248.    DataPtr = malloc((size_t) SendSize);
  249. #ifdef CPICSEND
  250.    GenerateData();
  251.    SendCount = 0;
  252.    ConfirmCount = 0;
  253. #else
  254.    Deallocated = FALSE;
  255. #endif
  256.  
  257.    ResultBuf = (NumConversations == 0) ?
  258.                NULL : malloc(NumConversations * sizeof(RESULT));
  259.    ResultPtr = ResultBuf;
  260.  
  261. }
  262.  
  263. /*****************************************************************************/
  264. /* IssueNextVerb - looks at the verb which has just completed and does the   */
  265. /*                 next one                                                  */
  266. /*****************************************************************************/
  267. void IssueNextVerb()
  268. {
  269.    unsigned char wait_conv_ID[8];
  270.    CM_INT32 wait_return_code;
  271.    /**************************************************************************/
  272.    /* last_verb = 0 is special case, before any verb has been issued.        */
  273.    /**************************************************************************/
  274.    if (last_verb != 0)
  275.    {
  276.       ProcessReturns();
  277.    }
  278.    if (!TPDead)
  279.    {
  280.       switch (last_verb)
  281.       {
  282.          case 0x0000:
  283. #ifdef CPICSEND
  284.             NewConversation();
  285.             Do_cminit();
  286. #else
  287.             Do_cmaccp();
  288. #endif
  289.             break;
  290.  
  291. #ifdef CPICSEND
  292.          case C_INIT:
  293.             /*****************************************************************/
  294.             /* Set the processing mode for this conversation to non-blocking */
  295.             /* we have already used xchwnd to set the window handle (or to   */
  296.             /* NULL it for WAIT mode)                                        */
  297.             /*****************************************************************/
  298.             {
  299.                CM_INT32 receive_type = (blocking) ? CM_BLOCKING :
  300.                                                     CM_NON_BLOCKING ;
  301.                CM_INT32 temp_return_code;
  302.                cmspm(conversation_ID, &receive_type, &temp_return_code);
  303.             }
  304.             /*****************************************************************/
  305.             /* Set the sync level for this conversation                      */
  306.             /*****************************************************************/
  307.             {
  308.                CM_INT32 sync_level;
  309.                CM_INT32 temp_return_code;
  310.                sync_level = (ConfirmEvery == 0) ? CM_NONE : CM_CONFIRM;
  311.                cmssl(conversation_ID, &sync_level, &temp_return_code);
  312.             }
  313.             Do_cmallc();
  314.             break;
  315.  
  316.          case C_ALLC:
  317.             Do_cmsend();
  318.             break;
  319.  
  320.          case C_SEND:
  321.             SendCount++;
  322.             ConfirmCount++;
  323.             if ((NumSends != 0) && (SendCount == NumSends))
  324.             {
  325.                Do_cmdeal();
  326.             }
  327.             else if ((ConfirmEvery != 0) && (ConfirmCount == ConfirmEvery))
  328.             {
  329.                Do_cmcfm();
  330.             }
  331.             else
  332.             {
  333.                Do_cmsend();
  334.             }
  335.             break;
  336.  
  337.          case C_CFM:
  338.             ConfirmCount=0;
  339.             Do_cmsend();
  340.             break;
  341.  
  342.          case C_DEAL:
  343.             if ((NumConversations !=0) && (ConvCount == NumConversations))
  344.             {
  345.                NewConversation();
  346.                TPDead = TRUE;
  347.             }
  348.             else
  349.             {
  350. #if 0
  351.             /*****************************************************************/
  352.             /* Enable this to check Startup/Cleanup in loop                  */
  353.             /*****************************************************************/
  354.                  WCPICDATA CPICData;
  355.                   WinCPICCleanup();
  356.                   WinCPICStartup(WinCPICVERSION,&CPICData);
  357. #endif
  358.                NewConversation();
  359.                Do_cminit();
  360.             }
  361.             break;
  362.  
  363. #else
  364.          case C_ACCP:
  365.             NewConversation();
  366.             Do_cmrcv();
  367.             break;
  368.  
  369.          case C_RCV:
  370.             if (return_code == CM_DEALLOCATED_NORMAL)
  371.             {
  372.                if ((NumConversations != 0) && (ConvCount < NumConversations))
  373.                {
  374.                   Do_cmaccp();
  375.                }
  376.                else
  377.                {
  378.                   NewConversation();
  379.                   TPDead = TRUE;
  380.                }
  381.             }
  382.             else if (status_received == CM_CONFIRM_RECEIVED)
  383.             {
  384.                Do_cmcfmd();
  385.                Deallocated = FALSE;
  386.             }
  387.             else if (status_received == CM_CONFIRM_DEALLOC_RECEIVED)
  388.             {
  389.                Do_cmcfmd();
  390.                Deallocated = TRUE;
  391.             }
  392.             else
  393.             {
  394.                Do_cmrcv();
  395.             }
  396.             break;
  397.  
  398.          case C_CFMD:
  399.             if (Deallocated)
  400.             {
  401.                if ((NumConversations != 0) && (ConvCount < NumConversations))
  402.                {
  403.                   Do_cmaccp();
  404.                }
  405.                else
  406.                {
  407.                   NewConversation();
  408.                   TPDead = TRUE;
  409.                }
  410.             }
  411.             else
  412.             {
  413.                Do_cmrcv();
  414.             }
  415.             break;
  416.  
  417. #endif
  418.  
  419.          default:
  420.             /*****************************************************************/
  421.             /* What is this verb then ??                                     */
  422.             /*****************************************************************/
  423.             TPDead = TRUE;
  424. #ifdef WIN32
  425.             DebugBreak();
  426. #endif
  427.             break;
  428.  
  429.       } /* last_verb switch */
  430.  
  431.    } /* TPDead after previous verb */
  432.    if (!TPDead)
  433.    {
  434.       /***********************************************************************/
  435.       /* If the verb just issued has already completed, then post ourselves  */
  436.       /* a message to kick off the next verb.                                */
  437.       /* Otherwise, if the async mode being used is WAIT, then issue a       */
  438.       /* Wait_For_Conversation verb and then post ourselves a message        */
  439.       /* If the async mode is POST then WinCPIC will post a message for us   */
  440.       /***********************************************************************/
  441.       if (return_code != CM_OPERATION_INCOMPLETE)
  442.       {
  443.          PostMessage(hWndMain, ASYNC_COMPLETE, (WPARAM)return_code,
  444.                                       (LPARAM)((void FAR *)&conversation_ID));
  445.       }
  446.       else if (wait_mode)
  447.       {
  448.          cmwait(wait_conv_ID, &return_code, &wait_return_code);
  449.          /********************************************************************/
  450.          /* We don't bother checking the wait_conv_ID since we only have one */
  451.          /* conversation in progress.                                        */
  452.          /********************************************************************/
  453.          PostMessage(hWndMain, ASYNC_COMPLETE, (WPARAM)return_code,
  454.                                       (LPARAM)((void FAR *)&conversation_ID));
  455.       }
  456.    }
  457.    else
  458.    {
  459.       /***********************************************************************/
  460.       /* If we have finished then post ourselves a close message. Note that  */
  461.       /* WinCPICCleanup will be done in the WM_CLOSE processing, so that the */
  462.       /* case where the user closes the application prematurely is caught    */
  463.       /***********************************************************************/
  464.       PostMessage(hWndMain, WM_CLOSE, 0, 0);
  465.    }
  466. } /* Issue next verb */
  467.  
  468. #ifdef CPICSEND
  469. void Do_cminit()
  470. {
  471.    cminit(conversation_ID,SymDestName,&return_code);
  472.    last_verb = C_INIT;
  473. }
  474.  
  475. void Do_cmallc()
  476. {
  477.    cmallc(conversation_ID,&return_code);
  478.    last_verb = C_ALLC;
  479. }
  480.  
  481. void Do_cmdeal()
  482. {
  483.    cmdeal(conversation_ID,&return_code);
  484.    last_verb = C_DEAL;
  485. }
  486.  
  487. void Do_cmsend()
  488. {
  489.    cmsend(conversation_ID,DataPtr,&SendSize,&request_to_send_received,
  490.                                                                  &return_code);
  491.    last_verb = C_SEND;
  492. }
  493.  
  494. void Do_cmcfm()
  495. {
  496.    cmcfm(conversation_ID,&request_to_send_received,&return_code);
  497.    last_verb = C_CFM;
  498. }
  499.  
  500. #else
  501.  
  502. void Do_cmaccp()
  503. {
  504.    cmaccp(conversation_ID,&return_code);
  505.    last_verb = C_ACCP;
  506. }
  507.  
  508. void Do_cmrcv()
  509. {
  510.    cmrcv(conversation_ID,DataPtr,&SendSize,&data_received,&received_length,
  511.                       &status_received,&request_to_send_received,&return_code);
  512.    last_verb = C_RCV;
  513. }
  514.  
  515. void Do_cmcfmd()
  516. {
  517.    cmcfmd(conversation_ID,&return_code);
  518.    last_verb = C_CFMD;
  519. }
  520. #endif
  521.  
  522. /*****************************************************************************/
  523. /* ProcessReturns - Checks return codes from the last verb to complete and   */
  524. /*                  saves off any useful information. If the return code is  */
  525. /*                  bad then we just die.                                    */
  526. /*****************************************************************************/
  527. void ProcessReturns()
  528. {
  529.    if ( (return_code != CM_OK) &&
  530.        !( (last_verb == C_RCV) &&
  531.           (return_code == CM_DEALLOCATED_NORMAL) ) )
  532.    {
  533.       TPDead = TRUE;
  534.    }
  535. }
  536.  
  537. /*****************************************************************************/
  538. /* ReadConfig - Reads config info from SENDTP.CFG also allocates buffer for  */
  539. /*              sending                                                      */
  540. /*****************************************************************************/
  541. void ReadConfig()
  542. {
  543.    char buffer[200];
  544.  
  545. #ifdef CPICSEND
  546.  
  547.    if (!ReadString("ResultFile",FileName,20))
  548.    {
  549.       strcpy(FileName,"C:\\CPICSEND.OUT");
  550.    }
  551.    if (!ReadString("SymDestName",SymDestName,8))
  552.    {
  553.       strcpy(SymDestName,"CPICRECV");
  554.    }
  555.    NumSends=2;
  556.    if (ReadString("NumSends",buffer,200))
  557.    {
  558.       NumSends=atoi(buffer);
  559.    }
  560.    ConfirmEvery=1;
  561.    if (ReadString("ConfirmEvery",buffer,200))
  562.    {
  563.       ConfirmEvery=atoi(buffer);
  564.    }
  565.    SendSize=1024;
  566.    if (ReadString("SendSize",buffer,200))
  567.    {
  568.       SendSize=atoi(buffer);
  569.    }
  570.  
  571. #else
  572.  
  573.    SendSize = 0x7FFF;
  574.    if (!ReadString("ResultFile",FileName,20))
  575.    {
  576.       strcpy(FileName,"C:\\CPICRECV.OUT");
  577.    }
  578.    if (!ReadString("LocalTPName",LocalTPName,64))
  579.    {
  580.       strcpy(LocalTPName,"CPICRECV");
  581.    }
  582.  
  583. #endif
  584.  
  585.    wait_mode = FALSE;                                                  /*BLOK*/
  586.    blocking  = FALSE;                                                  /*BLOK*/
  587.    if (ReadString("WaitMode",buffer,200))                              /*BLOK*/
  588.    {                                                                   /*BLOK*/
  589.       wait_mode = (*(strupr(buffer)) != 'N');  /* Yes or Blocking */   /*BLOK*/
  590. #ifdef CPICSEND                                                        /*BLOK*/
  591.       blocking  = (*(strupr(buffer)) == 'B');  /* Blocking  */         /*BLOK*/
  592. #endif                                                                 /*BLOK*/
  593.    }                                                                   /*BLOK*/
  594.  
  595.    NumConversations=1;
  596.    if (ReadString("NumConversations",buffer,200))
  597.    {
  598.       NumConversations=atoi(buffer);
  599.    }
  600.  
  601. }
  602.  
  603. /*****************************************************************************/
  604. /* NewConversation - Reset and record timers for this conversation.          */
  605. /*****************************************************************************/
  606. void NewConversation()
  607. {
  608.    RESULT NewTime;
  609.  
  610. #ifdef CPICSEND
  611.    SendCount = 0;
  612.    ConfirmCount =0;
  613. #endif
  614.  
  615.    if (FirstConv)
  616.    {
  617.       FirstConv = FALSE;
  618.       ConvStarted = GetTickCount();
  619.    }
  620.    else if (ResultPtr != NULL)
  621.    {
  622.       *ResultPtr++ = ((NewTime = GetTickCount()) - ConvStarted);
  623.       ConvStarted = NewTime;
  624.    }
  625.    ConvCount++;
  626.    OUTPUTNUMBER
  627. }
  628.  
  629. #ifdef CPICSEND
  630. /*****************************************************************************/
  631. /* GenerateData    - Fill in data buffer                                     */
  632. /*****************************************************************************/
  633. void GenerateData()
  634. {
  635.    int i;
  636.    int div;
  637.    int rem;
  638.    char * dptr;
  639.  
  640.    dptr = DataPtr;
  641.    div = SendSize / 5;
  642.    rem = SendSize % 5;
  643.  
  644.    for (; div--;)
  645.    {
  646.       for (i=4; i--; *dptr++ = datach);
  647.       *dptr++ = '.';
  648.    }
  649.    for (; rem--; *dptr++ = datach);
  650.  
  651.    datach = (datach=='Z' ? 'A' : datach + 1);
  652. }
  653. #endif
  654.  
  655. /*****************************************************************************/
  656. /* ReadString - Get a line of text from the config file.                     */
  657. /*****************************************************************************/
  658. int ReadString(char * lpValueName,char * lpData, int maxlen)
  659. {
  660.    char       buffer[200];
  661.    char       value[200];
  662.    char      *p = NULL;
  663.    FILE      *h = NULL;
  664.    BOOL       match = FALSE;
  665.    BOOL       eof   = FALSE;
  666.    int        rc = 0;
  667.    int        ch = 0;
  668.    int        i = 0;
  669.    BOOL       gotdata = FALSE;
  670.    char       separators[] = " =\t\n";
  671.  
  672. #if (defined(WINDOWS)||defined(WIN32))                                 /*PATH*/
  673.                                                                        /*PATH*/
  674.     GetModuleFileName( hInst, buffer, sizeof(buffer) );                /*PATH*/
  675.     lstrcpy( buffer+lstrlen(buffer) - 4, ".CFG" );                     /*PATH*/
  676.     h = fopen( buffer, "r" );                                          /*PATH*/
  677.     buffer[0] = '\0';                                                  /*PATH*/
  678.                                                                        /*PATH*/
  679. #else                                                                  /*PATH*/
  680. #ifdef CPICSEND
  681.    h = fopen("C:\\cpicsend.cfg", "r");
  682. #else
  683.    h = fopen("C:\\cpicrecv.cfg", "r");
  684. #endif
  685. #endif                                                                 /*PATH*/
  686.  
  687.    strupr(strcpy(value,lpValueName));
  688.  
  689.    if (h != NULL)
  690.    {
  691.       while ((!match) && (!eof))
  692.       {
  693.          /********************************************************************/
  694.          /* Use fgetc to read a line of text from the file.                  */
  695.          /********************************************************************/
  696.          for (i=0; (i<sizeof(buffer))     &&
  697.                    ((ch=getc(h)) != EOF)  &&
  698.                    ((char)ch != '\n');
  699.                                       i++)
  700.          {
  701.             buffer[i] = (char)ch;
  702.          }
  703.          if ((char)ch == '\n')
  704.          {
  705.             buffer[i++] = (char)ch;
  706.          }
  707.          if (ch == EOF)
  708.          {
  709.             eof = TRUE;
  710.          }
  711.          else
  712.          {
  713.             /*****************************************************************/
  714.             /* Compare the 1st token in the line read with the requested     */
  715.             /* param.                                                        */
  716.             /*****************************************************************/
  717.             if (!strcmpi(strupr(strtok(buffer, separators)), lpValueName))
  718.             {
  719.                match = TRUE;
  720.                /**************************************************************/
  721.                /* Get a pointer to the 2nd token (the value we want)         */
  722.                /**************************************************************/
  723.                p = strtok(NULL, separators);
  724.  
  725.                /**************************************************************/
  726.                /* Copy the data IF there is some.                            */
  727.                /**************************************************************/
  728.                if (p != NULL)
  729.                {
  730.                   /***********************************************************/
  731.                   /* Force a NULL after the 2nn token                        */
  732.                   /***********************************************************/
  733.                   strtok(NULL, separators);
  734.  
  735.                   /***********************************************************/
  736.                   /* Copy the data                                           */
  737.                   /***********************************************************/
  738.                   strncpy(lpData, p, maxlen);
  739.                   gotdata = TRUE;
  740.                }
  741.                else
  742.                {
  743.                   gotdata = FALSE;
  744.                }
  745.             }
  746.          }
  747.       }
  748.  
  749.       if (gotdata)
  750.       {
  751.          rc = 1;
  752.       }
  753.  
  754.       fclose(h);
  755.    }
  756.  
  757. return(rc);
  758. }
  759.  
  760. /*****************************************************************************/
  761. /* OutputResults - dump the times of conversations to file                   */
  762. /*****************************************************************************/
  763. void OutputResults()
  764. {
  765.    FILE *h = NULL;
  766.    RESULT * ptr = NULL;
  767.    unsigned short i = 0;
  768.  
  769.    h = fopen(FileName,"w");
  770.    if (h != NULL)
  771.    {
  772. #ifdef CPICSEND
  773.      fprintf(h,"CPICSEND Results\n----------------\n\n");
  774.      fprintf(h,"Symbolic destination name = %s\n",SymDestName);
  775.      fprintf(h,"Number of conversations = %d\n",NumConversations);
  776.      fprintf(h,"Sends per conversation  = %d\n",NumSends);
  777.      fprintf(h,"Sends between confirms  = %d\n",ConfirmEvery);
  778.      fprintf(h,"Bytes per send          = %d\n",SendSize);
  779.      fprintf(h,"Wait mode               = %s\n",(wait_mode ? "Yes" : "No"));
  780.      fprintf(h,"Blocking                = %s\n",(blocking  ? "Yes" : "No"));
  781.      fprintf(h,"\n");
  782. #else
  783.      fprintf(h,"CPICRECV Results\n----------------\n\n");
  784.      fprintf(h,"Local TP Name           = %s\n",LocalTPName);
  785.      fprintf(h,"Number of conversations = %d\n",NumConversations);
  786.      fprintf(h,"Wait mode               = %s\n",(wait_mode ? "Yes" : "No"));
  787.      fprintf(h,"\n");
  788. #endif
  789.  
  790.      ptr = ResultBuf;
  791.      while (ptr < ResultPtr)
  792.      {
  793.        fprintf(h,"Conversation number %d, time = %.3f seconds\n",i++,
  794.                                               (((float) *ptr++) / 1000.0 ));
  795.      }
  796.      fclose(h);
  797.    }
  798. }
  799.  
  800.