home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / tcl / 1809 < prev    next >
Encoding:
Text File  |  1992-11-11  |  1.8 KB  |  71 lines

  1. Newsgroups: comp.lang.tcl
  2. Path: sparky!uunet!usc!zaphod.mps.ohio-state.edu!menudo.uh.edu!sugar!karl
  3. From: karl@NeoSoft.com (Karl Lehenbauer)
  4. Subject: Re: Parsing "C" code in TCL ???
  5. Organization: NeoSoft Communications Services -- (713) 684-5900
  6. Date: Thu, 12 Nov 1992 06:20:42 GMT
  7. Message-ID: <BxLAyK.MHD@NeoSoft.com>
  8. Keywords: Interp
  9. References: <37572@uflorida.cis.ufl.edu>
  10. Lines: 59
  11.  
  12. In article <37572@uflorida.cis.ufl.edu> palkar@reef.cis.ufl.edu (MMP) writes:
  13. >void trial (int K, int M)
  14. >{
  15. >if(M==1){
  16. >    for (i=0;i<K;i++)
  17. >        printf("%d \n",K);
  18. >}
  19. >else {
  20. >    for (i=0;i<K;i++)
  21. >        printf("%d \n",K*(K-1));
  22. >}
  23. >}
  24. >How do I convert TRIAL in a Tcl command. Do I have recompile everything (Tcl );
  25.  
  26. Yes, you have to relink Tcl.  This command would look something very close
  27. to the following:
  28.  
  29. int
  30. Tcl_TrialCmd (clientData, interp, argc, argv)
  31.     ClientData  clientData;
  32.     Tcl_Interp *interp;
  33.     int         argc;
  34.     char      **argv;
  35. {
  36.     int M, K;
  37.  
  38.     if (argc != 3) {
  39.         Tcl_AppendResult (interp, "wrong # args: ", argv [0], 
  40.                           " K M", (char *) NULL);
  41.         return TCL_ERROR;
  42.     }
  43.  
  44.     if (Tcl_GetInt (interp, argv[1], &M) != TCL_OK)
  45.         return TCL_ERROR;
  46.  
  47.     if (Tcl_GetInt (interp, argv[1], &K) != TCL_OK)
  48.         return TCL_ERROR;
  49.  
  50.     if (M == 1) {
  51.     for (i = 0; i < K; i++)
  52.         printf("%d \n",K);
  53.     } else {
  54.     for (i = 0; i < K; i++)
  55.         printf("%d \n",K*(K-1));
  56.     }
  57.     return TCL_OK;
  58. }
  59.  
  60. Then arrange for this to be called:
  61.  
  62.     Tcl_CreateCommand (interp, "trial", Tcl_TrialCmd, (ClientData)NULL,
  63.                       (void (*)())NULL);
  64.  
  65. There is a document included in Extended Tcl, extended/man/CmdWrite.man,
  66. that describes how to write C extensions for Tcl.
  67. -- 
  68. -- Email info@NeoSoft.com for info on getting interactive Internet access.
  69. "It took no computation to dance to the rock 'n roll station."
  70. -- VU
  71.