techniques for parsing interactive input(like a shell)? - parsing

I'm working on a program that can be used directly from the command line with options and input files, or entirely interactively like a shell. For the initial execution I'm using GNU's Getopt to parse the command line options.
When being used on a file I'm using Flex and Bison. This simplifies the parsing greatly since the grammar is very simple, but I'm not entirely sure how I should tackle the shell aspect. I have used GNU's readline and history libraries before, when then I did this I relied solely on strtok and many comparisons with nested switch statements. It worked but it seemed kind of like a hack-job too me...
Is there a better way to approach this problem?
For the data input that the shell would allow I was thinking about piping it directly to a temp file and using Flex and Bison again, but for various parameters(like the command line options that Getopt is parsing for me now) is there a better way?
I was toying around with the idea of trying to recycle my getopt code, since its flexible to capture everything and if its not a option I could assume its data and pipe it out. But I'd love a 2nd opinion.
Thanks

Just write it in Python. Use the cmd module to write the shell program and use shlex for parsing input just like the shell.

Related

Start and pipe to process such as gnuplot in F# interactive

Essentially I want start a gnuplot process from within a .fsx script and pipe text commands to it so I can have my script replot. So far I have just been piping the stdout using the command line like this.
fsharpi "something.fsx" | gnuplot
I am doing this instead of using a plotting library because I am using gnuplot for other plots and I want the style to be the same. Also it's nice to have a lightweight solution. I am using mono on arch linux.
How can I start a gnuplot process from within a .fsx script and create a stream which allows me to pipe commands to it?
I hope that was enough detail. Thank you :)
There is actually a semi-abandoned F# wrapper for gnuplot called FnuPlot.
The library aimed to build a nice F#-friendly DSL for constructing GnuPlot charts, but it is very incomplete and does not cover very many of the charts and features you can use with GnuPlot.
However, it also implements some core functionality for calling GnuPlot, including starting GnuPlot, sending data to it and formatting various parameters. So, even if you cannot use the library directly, you can explore the code and use some bits of the code from there. For example here is how it starts the gnuplot process and here is how to send data to gnuplot. Of course, it would be even better if you wanted to contribute and help develop and maintain the library further :-).

Evaluating Rascal's Performance?

I want to evaluate the performance of Rascal for a given rewrite system that I've written. I'm wondering if there's a good way of doing it?
Ideally, I'd generate some compiled Java classes from the system and then run them manually against my inputs. Is there an easy or recommended way to do it?
Cheers,
One way to do this is to use the functions in the library util::Benchmark. Typically, you could write something like
cpuType( (){ call_the_function_I_want_to_observe(); } ). This will execute your function and print the cpu time used.
Note that Rascal can be executed in two ways: interpreted and compiled which makes a big difference when measuring performance. We are working hard at the moment to fully integrate the compiler in the Eclipse IDE, but a stand alone version is available as well. This can be called as java -Xss8m -jar rascal-0.8.4-SNAPSHOT.jar --compiledREPL followed by at least values for directories for sources (--src), and binaries (--bin). Here rascal-0.8.4-SNAPSHOT.jar (but most likely named differently) is downloaded from the https://update.rascal-mpl.org/console/rascal-shell-unstable.jar.
If you need more information, don't hesitate to ask for more details: this part of our tool chain is unfortunately still undocumented.

How SciTE IDE for lua automatically or manually format my code

I am new in lua,need basic type of help.After install BabeLua extension on Visual Studio,they indent and everything for me. Want to work with SciTE IDE, It's a pain in having to indent my code all the time so looking a way which can format my lua code manually and automatically.
Note: try to use source-code-formatter and beautifier.I failed to use them in my lua module.How to use them in lua?They are workable or not?
I think the idea with those beautifiers you reference is that you can run them as an external program: save your current buffer to a file, run through the filter to beautify, then read the result back into the current buffer in SciTE.
I can vouch for the second program as I used it in the past to re-indent some of my code; I ended up re-implementing it in Perl as it didn't handle all the cases I was interested in.
If you want to integrate it into SciTE, you can probably strip some of the io functions and just use functions to read buffer content in SciTE (like GetLine) and then modify the indentation (probably using GetLineIndentation and SetLineIndentation). I've implemented a very similar logic in my Lua IDE, which is using the same editor component that is used in SciTE.

Is there a way to programatically export files using Wireshark's facilities?

I am trying to automate a repetitive manual process for which I use WireShark:
1) Load a given pcap file
2) Apply a simple filter for a given protocol
3) Use the export dialog box to export the displayed packets to CSV file
4) Use the export dialog box to export the displayed packets in XML PDML form.
This is tedious, and requires human involvement in the middle of a process that is mostly automated (including the analysis of the files to produce reports).
Is there some way to either automate Wireshark, or do somehow access the underlying libraries used for export?
UPDATE: As several people here indicated, TShark turns out to be the way to go.
The exact command line I ended up using is:
tshark -r MyDataFile.pcap -T pdml -R MyProtocol > MyOutputFile.xml\
I then use an event based XML parser (Python's expat) to parse the generated 2GB file
I watched at the dependency list of wireshark on my debian system, and I found Tshark: it's the command line version of wireshark.
It seems interesting, but I didn't read the manual yet, however it's for sure more script friendly.
Also I'll stay tuned on this thread and post more info when I'll start using it.
I think what you should do is look into tshark. That is the linux command line version, which will allow exactly what you ask for (assuming you have access to it). And of course, this assumes that it is acceptable to run tshark and then review the outputs manually.
I haven't ever tried to automate Wireshark before, though I have had to do something similar to what you describe. I ended up reducing the handful of human (and thus error-prone) steps to one step that was automated.
Autohotkey is my solution for lots of repetitive GUI-based tasks. You can very easily write a keystroke playback script that will do all of the above steps. You'll probably have to have it increment the filename for you automatically. You could also have your other automated tool kick off the Autohotkey script with a keystroke.

Weird results using P4COM

I'm using P4COM to communicate with our perforce server. I have written an little utility to simplify our QA of what files have changed from one release to another. I have been using the P4COM interface from Delphi. So far so good.
I though it might be nice to allow users to view the diff between the two versions of the file from within my little utility rather than going back to p4v. So I print (get) the files at each revision using p4COM and the following command
print -o "E:\Development\TempProjects\p4Changes\temp\File_dispatch.pas#25" "//depot/mydepotpath/File_dispatch.pas"#25
and
print -o "E:\Development\TempProjects\p4Changes\temp\File_dispatch.pas#26" "//depot/mydepotpath/File_dispatch.pas"#26
However when I do this from my app using P4COM I seem to get random files (and they appear to be deleted ones). If I run the exact same command from the command line I get perfect results. Running both of these does return a file and correctly dumps it to disk where I want it, its just not the file I've asked for.
Any ideas?
Could it be a backslash issue in the command string? This would work fine at the command line, but a single backslash may be being interpreted as an escape code by whatever language compiler you are using (if C or C++, then this will definitely cause a problem, and that maybe happening under the hood on the P4COM side).
Try using double backslashes and see if that fixes it.
You're probably better of asking this to Perforce support itself, as this sounds like a bug in their software.
As a sidenote : Why do you use p4v? (I hugely prefer p4win myself)

Resources