Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I would like to know if it is possible to port GNU grep as a libary, leaving aside the legal complications, if any, as this is purely for non-commercial, but academic use. I have seen many ports exist of GNU grep. For example : GNU grep for win 32 here.
I wonder why nobody has ever attempted to port grep as a library ? It would be a huge benefit to applications that exploit string searching/mining as they can use the power of GNU grep internally in the their applications. I would like to attempt this feat, but since I am new to string searching/mining, would love to know the obvious challenges that may arise and why it has not been done as yet.
EDIT - The advantage of a GNU grep library is that it will do string searching much faster, using its own modified version of boyer-moore. Where as when using a regular expression wrapper library such as PCRE or Boost reg exp or Qt Reg expressions etc, the application has to read the file line-by-line and parse each line against the regexp. This is the obvious advantage that I see.
Yes. Just link it as a library and call its main() with its intended arguments. Or better if you rename its main() to some better, f.e. to grep().
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 months ago.
Improve this question
Does anyone know how I can run a VBS code in a C code?
I don't say run an external file, I say run a vbs CODE in the same code as C
In the same way Javascript and HTML come together, I want to do it with C and VBS
Responding to comments
There are two ways to add macro support to your applications. Pay money to Microsoft and license VBA or use VBScript/JScript for free.
C requires a lot of plumbing code. EG a . in C++/VB6 is lines of code in C as it has no knowledge of COM. But to write C one has to choose to use C++ or C# and restrict oneself from using the inbuilt features and then duplicate the same features with lots of lines of code. There is plenty of 20 year old source code on the internet showing how.
VBScript is an Active Scripting language. See https://en.wikipedia.org/wiki/Active_Scripting. This allows COM programming languages to add VBS/JS macros to their programs.
Active Scripting allows you to add a macro language to your program.
You can of course implement IActiveScripting and there is plenty of C code for that on the internet.
For 32 bit programs only there is a MSScript.ocx control that implements IActiveScript and related interfaces in an easy control.
The VBScript code is (I'm not a C programmer - but in C# and C++ [but not C] it is just as easy as VBScript) as they both do COM easily.
set ScriptControl1 = wscript.createObject("MSScriptControl.ScriptControl",SC)
With ScriptControl1
.Language = "VBScript"
.UseSafeSubset = False
.AllowUI = True
.AddCode Script
End With
The documentation was in System32 as msscript.chm but is no longer present in Win 10.
Here is some C# sample code. Note 32 Bit ONLY. https://learn.microsoft.com/en-us/troubleshoot/developer/visualstudio/cpp/libraries/call-script-control-run-method
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I wonder, why is Flex used even till now as far as I know?
If it is not used now and was used earlier, then also what is the advantage it provided over writing C code directly?
This is what I read about Flex
It takes as its input a text file containing regular expressions, together with the action to be
taken when each expression is matched. It produces an output file that contains C source code
defining a function yylex that is a table-driven implementation of a DFA corresponding to the
regular expressions of the input file. The Flex output file is then compiled with a C compiler to
get an executable.
What is the need of Flex? Is it better than writing directly C programs?
better in terms of execution or speed of code writing?
I am referring this as my source
Compared with writing out a state machine by hand, it certainly takes less code to produce a lexical scanner with flex. It is also much easier to read a flex specification and understand what tokens are recognized by it.
While it is possible to hand-optimize a scanner and beat flex in terms of execution time, it is rarely a good use of programmer time. In most parsing problems, the lexical scan is not the bottleneck, and a small performance improvement will be invisible. Also, the naive use of tools like regular expression libraries is likely to produce code which is both much slower and much harder to maintain.
Nothing has changed in the C language over the last 20 years which would affect either of the above statements.
All of the above is contingent on the programmer having some understanding of how to use the tool and for which problems it is and is not appropriate. As with any toolset.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I was reading "The C Programming Language" by Kernighan & Ritchie and came across some programs which mimic some Unix commands (also implemented in Linux) such as the cat command. The program took command line arguments just like the original cat command.
I am just curious to know whether they are the same thing or not.
Correct me if I'm wrong, any help would be appreciated.
In a command-line environment (such as, of course, Unix/Linux), a principle unit of abstraction is the command. A command has a well-defined interface: the command-line arguments it expects, the input it reads (if any), and the output it generates. You can reimplement a command any time you like, either using a different internal algorithm, or a different language, or just because you want to write your own version. Yes, cat was originally written in C, but we could rewrite it in C++, or Perl, or Python, or sh, or other languages. As long as our reimplementation meets the same interface requirements, we can accurately say that it "is" cat.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
In reading the man pages for tcpdump, I saw that the -dd arguement would output the dump as a fragment of a C file. In what situations is that useful? I take it this is to quickly include and compile the fragment in a program that will be used to process the data according to code we write ourselves? Does this have its utility with unknown or new protocols? Is there some other common, standing situation in which this is needed? Just curious.
It's useful if you're writing a program using libpcap/WinPcap that would use a filter but that, for whatever reason, wouldn't run pcap_compile() to translate a filter string into BPF machine code; it lets you do the compilation with tcpdump and generate some text that you could use in the initialization of an array of struct bpf_insn (a pointer to which, and a count of elements in which, you'd put in a struct bpf_program).
I'm not sure who would do that, however.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I am trying to try some C code from base R. I may need to modify the
code and compile it to understand how it works.
For example, I am trying to understand the function C_modelmatrix.
One thing can be done is that I directly modify the source code
src/library/stats/src/model.c where modelmatrix() is defined. But I
will need to compile the whole R source and load this newly modified
R, each time when I modify C_modelmatrix. This process is not
efficient.
Another way is to only extract the related C code and compile it as an
.so file. Then load the .so file with an existing R. But this approach
seems to be difficult. I'm yet to figure out an exact procedure on how
to do this.
Does anybody have any suggestions on what might be the best way to play with
the C code in base R?
I have my source directory (from svn) in ~/src/R-devel
~/src$ svn co https://svn.r-project.org/R/trunk R-devel
... (additional commands, e.g., R-devel/tools/rsync-recommended
I build in ~/bin/R-devel/
~/bin/R-devel$ CFLAGS="-g -O0" CXXFLAGS="-g -O0" ~/src/R-devel/configure
~/bin/R-devel$ make -j
I would make a change in ~/src/R-devel/src/library/stats/src/, then inside the directory ~/bin/R-devel/src/library/stats I can run
~/bin/R-devel/src/library/stats$ make
and only the stats package will be compiled / installed.
For exploring C code I actually prefer to use gdb to step through and interact with the code, with some hints available.