f



Save the file in strings, and evaulate the strings in Tcl source

Hi there,

I am reading into the tcl source code, and hoping I can find a way to
do this.

I want to save a script file into char arrays inside the Tcl source
code, and then I can "source" these char arrays as I "source"  a
script file.

Is there a way I can do this ? Any comment will be greatly
appreciated.

Regards
S-Y. Chen

0
shenyeh_chen (102)
11/13/2009 4:02:00 PM
comp.lang.tcl 23429 articles. 2 followers. Post Follow

4 Replies
830 Views

Similar Articles

[PageSpeed] 59

S-Y. Chen wrote:
> I want to save a script file into char arrays inside the Tcl source
> code, and then I can "source" these char arrays as I "source"  a
> script file.
> 
> Is there a way I can do this ? Any comment will be greatly
> appreciated.

Use the Tcl_Eval() routine to evaluate a script stored in a properly
encoded char array.

DGP
0
dgp2341 (685)
11/13/2009 4:25:43 PM
On Nov 14, 12:25=A0am, Donald G Porter <d...@nist.gov> wrote:
> S-Y. Chen wrote:
> > I want to save a script file into char arrays inside the Tcl source
> > code, and then I can "source" these char arrays as I "source" =A0a
> > script file.
>
> > Is there a way I can do this ? Any comment will be greatly
> > appreciated.
>
> Use the Tcl_Eval() routine to evaluate a script stored in a properly
> encoded char array.
>
> DGP

I have used Tcl_Eval for command in one line, but.......dose Tcl_Eval
also work for scripts expanding several lines ?  Like : if  while and
such......

And, is there an example showing how can a script be "properly coded"
in char array ?


Thanks again for the help.

Regards
S-Y. Chen
0
shenyeh_chen (102)
11/15/2009 5:05:06 AM
On 15 Nov, 05:05, "S-Y. Chen" <shenyeh_c...@hotmail.com> wrote:
> I have used Tcl_Eval for command in one line, but.......dose Tcl_Eval
> also work for scripts expanding several lines ? =A0Like : if =A0while and
> such......

Yes. Remember, newlines need to be written as \n in C strings and some
compilers (I'm looking at you, MSVC!) have problems with very long
string literals (well, more than a few kB) so it is better to write
this:

  "if {some condition} {\n"
  "    puts Satisfied!\n"
  "}"

rather than this:

  "if {some condition} {\n\
       puts Satisfied!\n\
   }"

Yes, they're the same at the byte level once compiled. Except to
certain brain-dead compilers. Note also that the two forms are pretty
much as easy to write as each other. (You could also use a very long
single line I suppose, but then you might run into compiler limits
again and preserving something like the newlines in the source aids
readability.)

> And, is there an example showing how can a script be "properly coded"
> in char array ?

The easiest way is to only use ASCII characters, and use \u escapes
for any characters outside that. That works fine for scripts you're
embedding by hand (and is in fact pretty easy to do mechanically too).
There are other ways of doing it, but I think they're much less
convenient.

Donal.
0
11/15/2009 11:32:40 AM
>> And, is there an example showing how can a script be "properly coded"
>> in char array ?

> The easiest way is to only use ASCII characters, and use \u escapes
> for any characters outside that. 

When using this approach, be sure to use \u0000 if you need the NUL
character as well.  Do not put a zero byte in your char array (except
of course the one at the end that terminates the string).

-- 
| Don Porter          Mathematical and Computational Sciences Division |
| donald.porter@nist.gov             Information Technology Laboratory |
| http://math.nist.gov/~DPorter/                                  NIST |
|______________________________________________________________________|
0
dgp2341 (685)
11/16/2009 3:28:57 PM
Reply:

Similar Artilces:

Sourcing a TCL file from within a tcl file
I am a newbie which I am sure I don't need to state :) I am trying to create a variable with a TCL file that will source another tcl file when I type the variable name something like this if I enter A through my keyboard then source a.tcl Can someone show me how to do this thanks guy On Dec 10, 1:15=A0pm, guy <gcoletta2...@gmail.com> wrote: > I am a newbie which I am sure I don't need to state :) > > I am trying to create a variable with a TCL file that will source > another tcl file when I type the variable name > > something like this > > if I enter A through my keyboard =A0then source a.tcl > > Can someone show me how to do this > > thanks > guy What you are asking is not hard. Will your program have a graphical user interface? Aric On Dec 10, 3:26=A0pm, Aric Bills <aric.bi...@gmail.com> wrote: > On Dec 10, 1:15=A0pm, guy <gcoletta2...@gmail.com> wrote: > > > I am a newbie which I am sure I don't need to state :) > > > I am trying to create a variable with a TCL file that will source > > another tcl file when I type the variable name > > > something like this > > > if I enter A through my keyboard =A0then source a.tcl > > > Can someone show me how to do this > > > thanks > > guy > > What you are asking is not hard. =A0Will your program have a graphical > user interface? > > Aric no I am just using this script...

Strings, Strings and Damned Strings
I have an int variable (always <100) that I want to convert to a two character string, e.g. if myint = 1, mystr = "01" if myint = 81, mystr = "81" At the moment I can't figure out how to do this cleanly. Then I wish to push a bunch of these strings into an array, for example: typedef char LABEL[3]; LABEL mystrArray[100]; But having read a couple of tutorials I am still no clearer on the best way to do an "array of strings" in this situation, nor how to do it. Any help much appreciated! cheers, Ben Ben wrote: > I have an int variable (always &...

String[] to String
/* I am writing this class to see the output of:args.toString();I want to see if the toString() method on the String[] will convertthe array contents into one string or it will write out it's typename,i.e. the <code>Class</code> class' name.As observed, the output is[java.lang.String@1693e2;which looks like the array's underlying type's name and the startingmemory address.*/public class Ats /*implying Array To String */{ public static void main(String[] args) { if ( args.length == 0 ) System.out.println("Usage: ats arg1 [arg2 [arg3...]]"); else Syste...

when string is not a string
Curious javascript sample. Consider the following code: var s = "asd" var f = function() { return typeof(this) } An expression typeof(s) returns true (as it is expected), but f.call(s) returns false! To make matters worse consider the following snippet: var s = "asd" var f = function() { return this instanceof String } An expression f.call(s) returns true, but (s instanceof String) returns false! The question is why call transforms this to an object? Is it made for unification, e.g. to make this iterable using 'for (var i in this)' loop?...

String or string
I am doing something where I do=20 If "force" || "spells" Puts "blah" When I use it it gives a warning about comparing strings, what's happening a= nd how do I fix it? Scratch.mit.edu. Go there! -gbear605= It doesn't seem to mind if those are pre-assigned ... ruby-1.9.2-p0 > if "force" || "spells" ruby-1.9.2-p0 ?> puts "blah" ruby-1.9.2-p0 ?> end (irb):3: warning: string literal in condition (irb):3: warning: string literal in condition blah => nil ruby-1.9.2-p0 > f = "forc...

tcl strings
hi, I am a newbie to tcl.. I want to get the dir and file name using some kind of a split command.. I have the file path name in the format /abc/xyzdir/filename and I want to get just /abc/xyzdir/ I tried [string trimright $path "/"] but didn't get it to work. let me know an easy way to get this. thanks, Parmesh On Fri, 16 Jul 2004, param wrote: > hi, > > I am a newbie to tcl.. > > I want to get the dir and file name using some kind of a split command.. > > I have the file path name in the format /abc/xyzdir/filename > and I want to get ...

strings in TcL
hello every one I have very small dought in TcL strings evaluation, i need to perform soem function only IF conditions satifies . I am accessing line by line from a file using fconfigure comand . The file has lines starting with # and other with out hash and now i have to put all the lines start ting with # in a list with out the #itslef and other lines in an other variable for this .. i am using the following code set fp [open new_file1 r] fconfigure $fp -buffering line gets $fp data while {$data != ""} { set data_1 [split $data ""] if { [string compare [lindex...

String and what is string
Hello All, I noticed that my knowledge of C language is pretty low today. I have the b= elow: char* ytest =3D "*314159 * 10000 ) "; char* xtest =3D " print \"hello, \" + \" world joost\" "; Fig(1) But when I tokenize pointer of character , ytest, I discover that it also t= raverses xtext values. It took me a while to figure this out. And it happen= s when there is space after my last character. For the below it wont happen= .. char* ytest =3D "*314159 * 10000 )"; char* xtest =3D " print \"hello, \" + \" world joost\""; Fig(2) I notice that if I append '\0' to the char variables in fig(1), it works as= expected, that is it wont tokenize xtest varaible. Also if I turn the poin= ter to character varaibles to array (char ytest[]) it works very well. To m= e that means that my compiler appends '\0' for me. But I also noticed that my isspace function fails if I have at the back of= the last character.=20 char* ytest =3D "*314159 * 10000 ) \0"; char* xtest =3D " print \"hello, \" + \" world joost\" \0"; But this works well with isspace function char* ytest =3D "*314159 * 10000 )\0"; char* xtest =3D " print \"hello, \" + \" world joost\" \0";=20 Could someone help me out in figuri...

RfD: FILE-SOURCE STRING-SOURCE and CLOSE-SOURCE
Two or three weeks ago I said I would write this RfD. Problem ~~~~~~~ To handle text from different types of input sources ANS Forth provides various words such as SOURCE SOURCE-ID REFILL >IN PARSE WORD SAVE-INPUT RESTORE-INPUT and the Forth 200X PARSE-NAME. In addition other parsing words such as CREATE ' etc work on the current input source. Many applications use the File-Access word set to handle text files and, having opened a file, can't immediately use words such as REFILL on that file. This is because the words ANS Forth provides for opening new input sources (INCLUDE-FILE ...

Is there a way to un-source Tcl source files?
Experts, When a Tcl source file gets sourced the script is getting passed to the Tcl-interpreter. As of my understanding the interpreter needs to have the code somewhere in memory and perform look-ups on procedure calls. My application has many Tcl source files. To save memory, and time for lookup of procedure code in the Tcl-interp I'd like to un-source source files when they are not needed to be present at a given time. Is there a way to tell Tcl to forget about the source code in a specific file? source foo.tcl unsource foo.tcl Thanks Bibi At Fri, 12 Jul 2013 09:44:22 -0700 (PDT) Bibi <bibi.postlmayr@gmail.com> wrote: > > Experts, > > When a Tcl source file gets sourced the script is getting passed to the Tcl-interpreter. > As of my understanding the interpreter needs to have the code somewhere in memory and perform look-ups on procedure calls. > > My application has many Tcl source files. > To save memory, and time for lookup of procedure code in the Tcl-interp > I'd like to un-source source files when they are not needed to be present at a given time. > > Is there a way to tell Tcl to forget about the source code in a specific file? > > source foo.tcl > unsource foo.tcl Not really, but you could use namespaces. If the file foo.tcl wraps all of its code in a namespace eval foo block, you can then later later delete the namespace with namespace delete foo. That is: fo...

how to replace a string by other string in a text file?
Do you have any answer to it? thx. Umesh wrote: > Do you have any answer to it? thx. > sed. -- Ian Collins. On May 30, 3:55 am, Umesh <fraternitydispo...@gmail.com> wrote: > Do you have any answer to it? thx. system("sed ...") #include <stdio.h> #include <string.h> int main () { char str[] ="This is a simple string"; char * pch; pch = strstr (str,"simple"); strncpy (pch,"sample",5); puts (str); return 0; } Quentin Godfroy wrote: > On May 30, 3:55 am, Umesh <fraternitydispo...@gmail.com> wrote: &...

Reading strings from files into a string array
I have a text file with entries like foo bar baz yadda yadda What command will read them into an array? dlmread apparently works only with numbers. Vijay Kumar Adhikari <vijaykcm@gmail.com> > I have a text file with entries like > foo > yadda > What command will read them into an array... a hint: help import; help textread; help textscan; us ...

Reading text file String by String
Respected sir, I am having a text File and I have to read that file string by string and I have to store these strings I an array of String. How can I acheive this. Kindly help us. "Migrators" <bkchandar@yahoo.com> wrote in message news:fa16f8ad.0312090315.4ac1b40@posting.google.com... ... > I am having a text File and I have to read that file string by string > and I have to store these strings I an array of String. How can I > acheive this. You need to look into the following classes: File, InputStream and FileInputStream. > Kindly help us. Help yourself, sta...

How Tcl source finds init.tcl???
Hi, I have one question about how Tcl finds init.tcl. What environment variable does Tcl source use to get the search path for init.tcl? Is there any way to specifically use init.tcl from a certain path? Thanks a lot in advance! Lihong lihong pei wrote: > I have one question about how Tcl finds init.tcl. > What environment variable does Tcl source use to get the search path for > init.tcl? If the environment variable TCL_LIBRARY exists, it's value is assumed to be a single directory which is added to the search path for init.tcl. Note that this is offered mostly as a way for...

string map in Tcl
For my curiosity, is this a complete way to implement [string map] in plain Tcl? proc stringmap {maplist s} { if {[llength $maplist] == 0} { return $s } elseif {[llength $maplist] % 2 != 0} { error "char map list unbalanced" } set new "" while {[string length $s] > 0} { set replacement [string index $s 0] set i 1 foreach {key value} $maplist { set len [string length $key] if {$len > 0 && [string match "$key*" $s]} { set replacement $value set i $len break } } append new $replacement set s [string range $s $i end] } return $new } stringmap {abc 1 ab 2 a 3 1 0} 1abcaababcabababc ;# => 01321221 stringmap {aa X a Y} baaa ;# => bXY stringmap {a Y aa X} baaa ;# => bYYY -- Glenn Jackman Write a wise saying and your name will live forever. -- Anonymous On Jun 16, 10:48=A0am, Glenn Jackman <gle...@ncf.ca> wrote: > For my curiosity, is this a complete way to implement [string map] in > plain Tcl? > > =A0 =A0 proc stringmap {maplist s} { > =A0 =A0 =A0 =A0 if {[llength $maplist] =3D=3D 0} { > =A0 =A0 =A0 =A0 =A0 =A0 return $s > =A0 =A0 =A0 =A0 } elseif {[llength $maplist] % 2 !=3D 0} { > =A0 =A0 =A0 =A0 =A0 =A0 error &quo...

How to pop any string between ( ) in TCL?
have the following lines:- ----- line1 line2 CELL (HAHA1) { TPYE : A; line3 lin4 CELL (HAHA2) { TPYE : B; line5 lin6 ----- Now, I already have the above lines in a list. I am able to iterate over the list and whenever i get to line containing CELL ... I want to pop-out HAHA1 and HAHA2 from it Basically, how do I pop-out any string between ( ) SImilarly, I want to pop-out any string after : i.e A and B in my case Thanks, On Dec 3, 2:43 pm, entrepreneur.wann...@gmail.com wrote: > have the following lines:- > > ----- > line1 > line2 > CELL (HAHA1) { > TPYE : A; > line3 > lin4 > CELL (HAHA2) { > TPYE : B; > line5 > lin6 > ----- > > Now, I already have the above lines in a list. I am able to iterate > over the list and whenever i get to line containing CELL ... I want to > pop-out HAHA1 and HAHA2 from it > > Basically, how do I pop-out any string between ( ) What do you mean "pop"? Do you mean "extract"? If so then it's as simple as: if {[regexp {CELL\s*\((.+)\)} $line -> value]} { do_something_with $value } But in list context "pop" usually mean "get the last element of the list and remove it from the list". So if you mean "extract then remove it from the line" you can do it with: if {[regexp {CELL\s*\((.+)\)} $line -> value]} { # remove $value from the line: set line [regsub "(?q)$value" $line {}] do_something_with $value } >...

Saving a string to a file
Hi all, I am trying to save a string that I get from a JTextArea like this: --------- String s = textArea.getText(); --------- After getting the text I save it using the following code ---------------Simplified to reduce number of lines---------- fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); int returnVal = fc.showSaveDialog(frame); try { if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); SF = (file.toString() + ".txt"); File...

using std::string; string("hello") vs std::string("hello") in header file.
In Accellerated C++, the author recommends that in a header file one should not declare using std::string, using std::vector etc instead one should directly specify the namespace specifier in code. for example, this is bad practice: header.h #include <string> using std::string; class a{ string x; }; instead, one should write: #include <string> class a{ std::string x; }; The reason given by the author is that 'using std::string' actually pollutes the scope where 'using std::string' is declared. I find this style is rather inconvenient when I want to experiment with different implementation of certain classes in large projects. For example, I may want to try myns::string or john::string, it's actually much easier to replace 'using std::string' to 'using myns::string' and instantly switch to another string implementation. This is much better than going through all the instances of 'std::string variable' and replace them to 'myns::string variable'. What are your thoughts on this coding style? Fei Liu wrote: > In Accellerated C++, the author recommends that in a header file one > should > not declare > using std::string, using std::vector etc instead one should directly > specify > the namespace specifier in code. Doesn't it say "at top level"? > The reason given by the author is that 'using std::string' actually > pollutes > the scope where 'using...

String function (counting string within a string)
Does anyone know of a string function in Access that will allow me to count the number of instances one string occurs within another? Or if there is some sort of word count function? If there is, I'm not aware of it. I've tried the following unsuccessfully ... SELECT *, (Len([myfield])-Len(Replace([myfield],' what_im_looking_to_count','')))/(Len(' what_im_looking_to_count')) AS KeywordFoundCountFROM tblYourTable; That'll find how many times the phrase what_im_looking_to_count occurs within the field called 'myfield' Thanks, Ralph Noble ralph_nobl...

print string to file when string is a batch argument
Hi, I'd like to know how to use gawk to print a string to a file when the string is given as a batch file argument. I am using gawk in winxp. For example, I have a batch file called mybatch.bat. I'd like to be able to type in the DOS prompt mybatch.bat HelloWorld , and hope that the following action will happen. -> gawk saves the string "HelloWorld" to a new file with predesignated file name, say, myjob.txt. The content of myjob.txt contains only the string "HelloWorld" (no quotes). -> Another application takes over and works on the file myjob.txt. So, what should I put in mybatch.bat to have gawk save the string to a file? I am thinking of something like gawk printf %1 > myjob.txt but of course it does not work. Any solution, gawk or DOS, will be greatly appreciated! In article <ecdcf4f9.0311241503.7bf6a9fc@posting.google.com>, Eddy <eddy_05831@yahoo.com> wrote: >Hi, > >I'd like to know how to use gawk to print a string to a file when the >string is given as a batch file argument. I am using gawk in winxp. > >For example, I have a batch file called mybatch.bat. I'd like to be >able to type in the DOS prompt > mybatch.bat HelloWorld >, and hope that the following action will happen. > >-> gawk saves the string "HelloWorld" to a new file with predesignated >file name, say, myjob.txt. The content of myjob.txt contains only the >string "HelloWorl...

grep for a string and delete the files containing that string
Hi, I have a number of files. I need to search them for a particular string in them. Also I need to remove the files containing that particular string. How to do this in UNIX ?? Gokul wrote: > Hi, > I have a number of files. > I need to search them for a particular string in them. > Also I need to remove the files containing that particular string. > How to do this in UNIX ?? Check the man pages and have a play with find and grep. -- Ian Collins. On Sep 23, 9:33=A0am, Gokul <gokul.b...@gmail.com> wrote: > I have a number of files. > I need to search them for a ...

How to capture the output from TCL prompt and save it to a file on Linux file system.
Hello All, I login to TCL prompt and run a simple query which lists few rows. I want to capture those rows and save it to a file on file system. I am working on a Sun Solaris ver. 5.9. Here is the sample query that i run from TCL prompt: >SELECT DISTINCT CATEGORY FROM DS_JOBS; And the Resultant set looks like this: Category............ ABC\ACEIQ\JOBS\C UST_SPCLTY ABC\ACEIQ\JOBS\C UST_SPC SSHIP\SEQ PLIC\CNTRL Any advise is greatly appreciated. Thanks Vini On Mar 22, 7:26=A0pm, Vini <vinay.renukun...@gmail.com> wrote: > Hello All, > > I login to TCL prompt and run a simple query which lists few rows. I > want to capture those rows and save it to a file on file system. I am > working on a Sun Solaris ver. 5.9. > > Here is the sample query that i run from TCL prompt: > > >SELECT DISTINCT CATEGORY FROM DS_JOBS; > > And the Resultant set looks like this: > > Category............ > > ABC\ACEIQ\JOBS\C > UST_SPCLTY > ABC\ACEIQ\JOBS\C > UST_SPC > SSHIP\SEQ > PLIC\CNTRL > > Any advise is greatly appreciated. Wrong group. You mean "SQL" rather than "TCL". -Alex On Mar 22, 2:30=A0pm, Alexandre Ferrieux <alexandre.ferri...@gmail.com> wrote: > On Mar 22, 7:26=A0pm, Vini <vinay.renukun...@gmail.com> wrote: > > > > > > > > > > > Hello All, > > > I login to TCL prompt and run a simple query which lists few rows. I > > want...

Saving string to a text file
Hi Just want to know how to save string into text file so I can open this file later on to filter the data. The string looks like this: >> txtSec txtSec = ************ stp next dat stp next dat stp next dat [14:26:54:71 [14:26:54:71 stp next dat ************ stp next dat stp next dat ************ stp next dat gelosoutputs stp next dat ==== 3 92 ;;;;;; ++++ stp next dat addothstatus === >> whos Name Size Bytes Class txtSec 25x12 600 char array I used the code below in my function but I didn�t get the result I want. fid1 = fopen('...

Dose there any tcl script to translate an file with embedded tcl
Hi I need to generate some big file, but there are rules for generate these files Ex . ============================== Start input a [0] wire input a [1] wire .. .. .. .. input a [1000] wire End ================================= Dose there any tcl script can help to translate a file with embedded tcl script into a new file For example this is a source file ======================== Start * set i 0 * for { set i 0 } { $i < 1000 } { incr i } { * puts input a [$i] wire * } End ========================== After Translate ======================= Start input a [0] wire input a [1] wire .. .. ...

Web resources about - Save the file in strings, and evaulate the strings in Tcl source - comp.lang.tcl

Malzberg - Rick Santorum: He'll re-evaulate run if he finishes out in the top 3 in Iowa - YouTube
More Related Videos & NewsmaxTV Live: http://www.newsmaxtv.com Subscribe to NewsmaxTV: http://www.youtube.com/subscribe_widget?p=NewsmaxTV Subscribe ...

Twitter
Sign in Sign up You are on Mobile because you are using an old version of Internet Explorer. Learn more here Suzanne Goldenberg @ suzyji Big. ...

Biological integrity - Wikipedia, the free encyclopedia
Biological integrity is associated with how “pristine” an environment is and its function relative to the potential or original state of an ecosystem ...

WNBL: Canberra Capitals recruit Rosie Fadljevic embraces short-term contract
Canberra Capitals recruit Rosie Fadljevic needed a break after year-long basketball for the past few seasons.

Testimonials - Emotive Health
The Equilibration Process has been the most amazing process I have been through so far in my life. I had no real idea of what I was letting myself ...

PM's challenge to Abbott on disability scheme
Prime Minister Julia Gillard has made the funding of the long-awaited disability insurance scheme a major election issue by announcing that a ...

"We weren't expecting this many people would buy a PlayStation 4"
Shuhei Yoshida says platform still exceeding expectations

Election 2006 and Social Media
Things have been quiet here lately, a bit too quiet ... Oh, that's right, it's because all my non-work energy has been put into a 5-part series ...

Why we don't have a parent selector
Snook.ca - Web Design, Development and Consulting Services

Screen Shots - Advanced Web Ranking
Screen Shots - Advanced Web Ranking

Resources last updated: 3/13/2016 11:10:12 AM