home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / d / d008 / 2.ddi / RTSMP.PAK / OVLOOPS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-30  |  6.8 KB  |  201 lines

  1. // Borland ObjectVision -- (C) Copyright 1991 by Borland International
  2.  
  3. /*
  4.     Build OVLOOPS.DLL with commands such as these:
  5.  
  6.         bcc -c -ml -WDE -Ic:\bc\include ovloops.c
  7.         tlink -Twd -c -Lc:\bc\lib c0dl ovloops,ovloops,, cwinl cl import,ovloops
  8.         rc ovloops.dll
  9. */
  10.  
  11. #include <windows.h>
  12.  
  13. typedef LPSTR FAR PASCAL OVCALLBACK_GET           ( LPSTR );
  14. typedef void  FAR PASCAL OVCALLBACK_PUT           ( LPSTR, LPSTR );
  15. typedef LPSTR FAR PASCAL OVCALLBACK_EXECUTESTRING ( LPSTR, LPSTR, unsigned,
  16.     unsigned );
  17.  
  18.  
  19. /******************************************************************************
  20. *
  21. * name          SelfRegister -- Register all of the functions of this DLL
  22. *
  23. * arguments     1.  OVCALLBACK_EXECUTESTRING lpfnCallBack -- callback fn
  24. *
  25. * return        Zero
  26. *
  27. * register      @REGISTER("@REGISTER_OVLOOPS","In","","ovloops.dll",
  28. *                   "SelfRegister",1)
  29. *
  30. ******************************************************************************/
  31.  
  32. int FAR PASCAL _export SelfRegister( OVCALLBACK_EXECUTESTRING lpfnCallBack )
  33. {
  34.     (void)(*lpfnCallBack)(
  35.         "@REGISTER(\"@WHILELOOP\",\"ICCn\",\"\"\"ConditionExpression\"\","
  36.             "\"\"ActionExpression\"\"\",\"ovloops.dll\",\"iWhileLoop\",1)"
  37.         , 0, 0, 0 );
  38.     (void)(*lpfnCallBack)(
  39.         "@REGISTER(\"@WHILEFIELD\",\"JCCwx\",\"\"\"ConditionField\"\","
  40.             "\"\"EventField\"\"\",\"ovloops.dll\",\"lWhileField\",1)"
  41.         , 0, 0, 0 );
  42.     (void)(*lpfnCallBack)(
  43.         "@REGISTER(\"@EXECUTE\",\"CCnF\",\"\"\"CommandToExecute\"\"\","
  44.             "\"ovloops.dll\",\"szExecuteString\",1)"
  45.         , 0, 0, 0 );
  46.     return 0;
  47. }
  48.  
  49. /******************************************************************************
  50. *
  51. * name          iWhileLoop -- While function using ExecuteString callback
  52. *
  53. * description   You can use this function to implement an @WHILELOOP in OV.
  54. *               Link error reporting is disabled during both condition and
  55. *               action execution.
  56. *
  57. * arguments     1.  LPSTR szCondition -- the condition expression
  58. *               2.  LPSTR szAction -- the action expression
  59. *               3.  OVCALLBACK_EXECUTESTRING lpfnCallBack -- callback fn
  60. *
  61. * return        Zero (an int)
  62. *
  63. * register      @REGISTER("@WHILELOOP","ICCn",
  64. *                   """ConditionExpression"",""ActionExpression""",
  65. *                   "ovloops.dll","iWhileLoop",1)
  66. *
  67. ******************************************************************************/
  68.  
  69. int FAR PASCAL _export iWhileLoop(
  70.     LPSTR szCondition,
  71.     LPSTR szAction,
  72.     OVCALLBACK_EXECUTESTRING lpfnCallBack )
  73. {
  74.     char sBuf[10];
  75.     char * szConditionResult;
  76.  
  77.     szConditionResult = (*lpfnCallBack)( szCondition, sBuf, sizeof(sBuf), 1 );
  78.     while ( szConditionResult && !lstrcmpi(szConditionResult,"Yes") )
  79.     {
  80.         (void)(*lpfnCallBack)( szAction, (LPSTR)0, 0, 1 );
  81.         szConditionResult = (*lpfnCallBack)( szCondition, sBuf,
  82.                                                  sizeof(sBuf), 1 );
  83.     }
  84.     return 0;
  85. }
  86.  
  87. /******************************************************************************
  88. *
  89. * name          lWhileField --  While function using only Get & Put callbacks
  90. *
  91. * description   You can use this function to implement an @WHILEFIELD in OV.
  92. *
  93. * arguments     1.  LPSTR szConditionField
  94. *               2.  LPSTR szEventField
  95. *               3.  OVCALLBACK_PUT lpfnPutCallBack
  96. *               4.  OVCALLBACK_GET lpfnGetCallBack
  97. *
  98. * return        unsigned long -- the number of times through the loop
  99. *
  100. * register      @REGISTER("@WHILEFIELD","JCCwx","""ConditionField"",
  101. *                   ""EventField""","ovloops.dll","lWhileField",1)
  102. *
  103. ******************************************************************************/
  104.  
  105. unsigned long FAR PASCAL _export lWhileField(
  106.     LPSTR szConditionField,
  107.     LPSTR szEventField,
  108.     OVCALLBACK_PUT lpfnPutCallBack,
  109.     OVCALLBACK_GET lpfnGetCallBack  )
  110. {
  111.     char far * szCondition;
  112.     char far * szEvent;
  113.     char sNumber[20];
  114.     unsigned long lLoop;
  115.  
  116.     szCondition = (*lpfnGetCallBack)( szConditionField );
  117.     szEvent = (*lpfnGetCallBack)( szEventField );
  118.     if ( szCondition == 0 || szEvent == 0 )
  119.     {
  120.         // One of the fields doesn't exists. Don't event try because
  121.         // the while would loop forever.
  122.         lLoop = 0;
  123.     }
  124.     else
  125.     {
  126.         lLoop = 0;
  127.         while ( lstrcmpi(szCondition,"No") )
  128.         {
  129.             lLoop++;
  130.             sprintf(sNumber,"%ld",lLoop);
  131.             if ( lLoop == 1 && !lstrcmpi(szEvent,sNumber) )
  132.             {
  133.                 lstrcpy( sNumber, "0" ); // To ensure we get a change event
  134.             }
  135.             (*lpfnPutCallBack)( (LPSTR)szEventField, (LPSTR)sNumber );
  136.             szCondition = (*lpfnGetCallBack)( szConditionField );
  137.         }
  138.     }
  139.     return lLoop;
  140. }
  141.  
  142. /******************************************************************************
  143. *
  144. * name          szExecuteString -- Send a command string to OV for execution
  145. *
  146. * description   Use this function to send a command to OV for execution.
  147. *
  148. * arguments     1.  LPSTR szCommand  -- the command to execute
  149. *               2.  OVCALLBACK_EXECUTESTRING lpfnCallBack -- callback fn
  150. *               3.  LPSTR sAnswerBuffer -- place for the answer
  151. *
  152. * return        LPSTR -- result string
  153. *
  154. * register      @REGISTER("@EXECUTE","CCnF","""CommandToExecute""",
  155. *                   "ovloops.dll","szExecuteString",1)
  156. *
  157. ******************************************************************************/
  158.  
  159. LPSTR FAR PASCAL _export szExecuteString(
  160.     LPSTR szCommand,
  161.     OVCALLBACK_EXECUTESTRING lpfnCallBack,
  162.     LPSTR sAnswerBuf )
  163. {
  164.     LPSTR szResult;
  165.     szResult = (*lpfnCallBack)( szCommand, sAnswerBuf, 4096, 0 );
  166.     if ( !szResult )
  167.     {
  168.         szResult = ""; // Return something
  169.     }
  170.     return szResult;
  171. }
  172.  
  173. // ------------------------------------------------------------------- //
  174. //                                                                     //
  175. //   Every DLL has an entry point LibMain and an exit point WEP        //
  176. //                                                                     //
  177. // ------------------------------------------------------------------- //
  178.  
  179. // Turn off "Parameter never used" warning
  180. #pragma argsused
  181.  
  182. int FAR PASCAL LibMain( HANDLE hInstance, WORD wDataSegment,
  183.                         WORD wHeapSize, LPSTR lpszCmdLine )
  184. {
  185.     // The startup code for the DLL initializes the local heap (if
  186.     // there is one) with a call to LocalInit which locks the data
  187.     // segment.
  188.     if ( wHeapSize != 0 )
  189.         UnlockData( 0 );
  190.     return 1;   // Indicate that the DLL was initialized successfully.
  191. }
  192.  
  193. // Turn off "Parameter never used" warning
  194. #pragma argsused
  195.  
  196. int FAR PASCAL WEP ( int bSystemExit )
  197. {
  198.     return 1;
  199. }
  200.  
  201.