Does anyone know of any tool which can convert shell script '.sh' into a C file '.c' ?
I doubt that any such tool exists. C and shell files are extremely different languages with completely different purposes, and there is no way to automatically convert one to the other.
you can try shc. Its not a compiler, but it does generate .c files during encoding/encrypting.
Otherwise, do it by hand. Learn to code in C and shell, then translate them yourself. that's the best way to do it.
Related
I am trying to learn C and I have this C file that I want view the macros of. Is there a tool to view the macros of the compiled C file.
No. That's literally impossible.
The preprocessor is a textual replacement that happens before the main compile pass. There is no difference between using a macro and putting the code the macro expands to in its place.*
*Ignoring the debugger output. But even then you can do it if you know the right #pragma to tell it the file and line number.
They're always defined in the header file(s) that you've imported with #include, or that those files in turn #include.
This may involve a lot of digging. It may involve going into files that make no sense to you because they're not written for casual inspection.
Any macros of any importance are usually documented. They may use other more complex implementation-specific macros that you shouldn't concern yourself with ordinarily, but if you're curious how they work the source is all there.
That being said, this is only relevant if you have the source and more specifically a complete build environment. Once compiled all these definitions, like the source itself, do not appear in the executable and cannot be inferred directly from the executable, especially not a release build.
Unlike Java or C#, C compiles directly to machine code so there's no way to easily reverse that back to the source. There are "decompilers" that try, but they can only really guess as to the original source. VM-based languages like Java and C# only lightly compile the code, sot here are a lot of hints as to how that code was generated and reversing it is an easier process.
I want to start a program using a batch-file. When I start the program manually (just double-clicking the exe-file) I have to select two file paths manually. I want to make a bat-script which starts the program and passes these two paths as arguments, so that the paths are already set when the program starts. The problem is that I don't know what the program will accept as arguments, or what order the of the arguments should be.
Is there any way of figuring out which arguments an exe-file can take?
If the exe doesn't provide a help output using ? or h as parameter and there is no doc, there is no easy way. Depending on the language the program is written in and whether you are allowed to decompile it or not, you might use tools like Reflector to decompile it and check which arguments are possible. This might help you: How do I decompile a .NET EXE into readable C# source code?
However, most software licenses prohibit decompiling even if they can't prevent it.
So let's say I have a string containing some code in C, predictably read from a file that has other things in it besides normal C code. How would I turn this string into code usable by the program? Do I have to write an entire interpreter, or is there a library that already does this for me? The code in question may call subroutines that I declared in my actual C file, so one that only accounts for stock C commands may not work.
Whoo. With C this is actually pretty hard.
You've basically got a couple of options:
interpret the code
To do this, you'll hae to write an interpreter, and interpreting C is a fairly hard problem. There have been C interpreters available in the past, but I haven't read about one recently. In any case, unless you reallY really need this, writing your own interpreter is a big project.
Googling does show a couple of open-source (partial) C interpreters, like picoc
compile and dynamically load
If you can capture the code and wrap it so it makes a syntactically complete C source file, then you can compile it into a C dynamically loadable library: a DLL in Windows, or a .so in more variants of UNIX. Then you could load the result at runtime.
Now, what normally would lead someone to do this is a need to be able to express some complicated scripting functions. Have you considered the possibility of using a different language? Python, Scheme (guile) and Lua are easily available to add as a scripting language to a C application.
C has nothing of this nature. That's because C is compiled, and the compiler needs to do a lot of building of the code before the code starts running (hence receives a string as input) that it can't really change on the fly that easily. Compiled languages have a rigidity to them while interpreted languages have a flexibility.
You're thinking of Perl, Python PHP etc. and so called "fourth generation languages." I'm sure there's a technical term in c.s. for this flexibility, but C doesn't have it. You'll need to switch to one of these languages (and give up performance) if you have a task that requires this sort of string use much. Check out Perl's /e flag with regexes, for instance.
In C, you'll need to design your application so you don't need to do this. This is generally quite doable, as for its non-OO-ness and other deficiencies many huge, complex applications run on well-written C just fine.
I would like to list all the variables that have been declared in my C program for analysis. Is there an easy way I can do this? I would think that building a lexer just for this purpose would be cumbersome. Is there another way?
Well, I think I have to be more clear :-). I intend to analyse a lot of C files using a C library that I intend to write, which needs to have this functionality. Hence, it'd be great if I can do this using C (since it can integrate with my library). However I can pre-process in any other language as well. But it'd increase dependencies.
You're probably going to have to write a pretty powerful parser anyway, if you want to handle typedefs and so on. You might want to look at using clang/llvm - you can probably modify it to output the data you want pretty easily.
cscope (http://cscope.sourceforge.net/) can identify and index all symbols in your program and has a command line mode to query the symbol database from command line or GUI tools.
Doing the job properly requires a significant chunk of the C preprocessor and a lexical analyzer, which is quite a lot of a C compiler.
Doing the job ad hoc is easier - but you get to choose how ad hoc you're going to be.
I have a C program with an embedded Perl interpreter. I want to be able to precompile some Perl code from within the program. How do I do that?
Rationale (if anyone is interested) is to be able to compile it once, store the parse tree, and execute many times (as long as the compiled code does not change).
Thanks!
Madhu
PS: I am using Perl-5.8, though it would be good to know if Perl-6.0 makes this easier in any way.
This is the default behavior when you embed the Perl interpreter in a C program. After you've run perl_parse() to parse the Perl program, you can use perl_run() and call_argv() over and over with the same parsed Perl program.
You can use perlcc to create executable or C sources.
To compile your C code, you would need to use perl's library (could be -lperl or -llibperl).
In reference to Perl 6, it's not complete. But 5.10.0 might have some bug fixes over 5.8.