home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.tcl
- Path: sparky!uunet!usc!zaphod.mps.ohio-state.edu!menudo.uh.edu!sugar!karl
- From: karl@NeoSoft.com (Karl Lehenbauer)
- Subject: Re: Parsing "C" code in TCL ???
- Organization: NeoSoft Communications Services -- (713) 684-5900
- Date: Thu, 12 Nov 1992 06:20:42 GMT
- Message-ID: <BxLAyK.MHD@NeoSoft.com>
- Keywords: Interp
- References: <37572@uflorida.cis.ufl.edu>
- Lines: 59
-
- In article <37572@uflorida.cis.ufl.edu> palkar@reef.cis.ufl.edu (MMP) writes:
- >void trial (int K, int M)
- >{
- >if(M==1){
- > for (i=0;i<K;i++)
- > printf("%d \n",K);
- >}
- >else {
- > for (i=0;i<K;i++)
- > printf("%d \n",K*(K-1));
- >}
- >}
- >How do I convert TRIAL in a Tcl command. Do I have recompile everything (Tcl );
-
- Yes, you have to relink Tcl. This command would look something very close
- to the following:
-
- int
- Tcl_TrialCmd (clientData, interp, argc, argv)
- ClientData clientData;
- Tcl_Interp *interp;
- int argc;
- char **argv;
- {
- int M, K;
-
- if (argc != 3) {
- Tcl_AppendResult (interp, "wrong # args: ", argv [0],
- " K M", (char *) NULL);
- return TCL_ERROR;
- }
-
- if (Tcl_GetInt (interp, argv[1], &M) != TCL_OK)
- return TCL_ERROR;
-
- if (Tcl_GetInt (interp, argv[1], &K) != TCL_OK)
- return TCL_ERROR;
-
- if (M == 1) {
- for (i = 0; i < K; i++)
- printf("%d \n",K);
- } else {
- for (i = 0; i < K; i++)
- printf("%d \n",K*(K-1));
- }
- return TCL_OK;
- }
-
- Then arrange for this to be called:
-
- Tcl_CreateCommand (interp, "trial", Tcl_TrialCmd, (ClientData)NULL,
- (void (*)())NULL);
-
- There is a document included in Extended Tcl, extended/man/CmdWrite.man,
- that describes how to write C extensions for Tcl.
- --
- -- Email info@NeoSoft.com for info on getting interactive Internet access.
- "It took no computation to dance to the rock 'n roll station."
- -- VU
-