writing a few lines of comments that work in most languages
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
But you can almost never translate a real source code from one language to another, there is no such tool. And because of the complexity (and incompatibility) of the existing languages it will never exist.
Actually, back in the days of the Y2K project, there were some one-to-one tools.
I ended up trying a FORTRAN to C tool to try and save time.
The code prob worked (I can't remember), but it was very odd looking 'C' of course ...
Iirc in the end I did re-code it into C by hand, but it was handy to have a 'C' version as an extra reference ...
Last edited by chrism01; 04-04-2023 at 08:23 PM.
Reason: missed ']'; dang and a missed word ...
Actually, back in the days of the Y2K project, there were some one-to-one tools.
I ended up trying a FORTRAN to C tool to try and save time.
The code prob worked (I can't remember), but it was very odd looking 'C' of course ...
Iirc in the end I did re-code it into C by hand, but it was handy to a 'C' version as an extra reference ...
Oh yes, there are examples like this, but there is no general "translator". Interestingly the gnu compiler set (and probably other compilers) will produce byte code [during the compilation] which is quite similar (or identical) for every language handled by the tool, but the reverse direction does not work very well (reconstructing the original source files).
By the way using those "reasonably arbitrary text as comments" would mean just a new language - which can be easily converted to some(?) other languages.
my purpose is to attach a code or certificate to each file. i probably will need to create something different for each class of language (classed by comment syntax) that reads a common form of the text/cert (probably 8 or so lines of 64 chars). python and bash would be in one class with a bunch of others. C would be in another with some. Fortran might have is own. same for COBOL.
Of course, it's important what you want that "code or certificate" to say say/do. Are you withholding that information, or do you not know the answer yourself?
Before you answer, read the following very carefully:
the current need is to give a file to other people for them to add to each file. it can be added anywhere in their file, and the process using it will work. they may have lots of files of many languages to add it to. i do not want to burden them with the need to figure out which of many variants for many languages they need to use with that file, which maybe is too hard for them to automate.
i do not believe a universal tool exists for that purpose. for example, when using the "file" utility, many of my Python source files are typed as "CLIPPER instruction trace" (no idea what CLIPPER is). a nice tool would be able to read a file and give the correct language it is (with its common name extension) or list of possible languages it could be. maybe some new AI could do that (what would we train it with?).
if you can embed this string inside of another such that this string can still be seen, but will look like something that does not change the working of the source file when compiled (such as a comment or discarded literal) then that might be the solution. as you can see, this will be very difficult, if not impossible.
C voodoo code = 4e3c1f5b5e617112b85872c4243a60f927e528023a0577f76f1a190c3b12668ef3a073f7ad7ff50393dd98d6bbe81e425aaa2753ee23d92a9d7eec08285ba3f041b13fcea40a16bf29e2fd73b7b2f35c09db44a592f77300b0e2895be19482d1abc747d64e9f695e6580f3d7cc8eda1471974d29077ddc498af4b83d6adc56bc5cc0c6fb091dd532ef8cbea668297ae8
How would that voodoo code be generated, what information would it contain, and what would read it?
I see that in your post, the voodoo code is the same every time. If it's just an identifier, and the the idea is to locate files that contain it, then I have a better idea. Create a directory named after the voodoo code, and symlink all of the source files into it.
if you can embed this string inside of another such that this string can still be seen, but will look like something that does not change the working of the source file when compiled (such as a comment or discarded literal) then that might be the solution. as you can see, this will be very difficult, if not impossible.
I still have no idea what do you want to solve and how will it solve anything. Obviously we can embed [almost] any string into any language.
the current need is to give a file to other people for them to add to each file. it can be added anywhere in their file, and the process using it will work. they may have lots of files of many languages to add it to. i do not want to burden them with the need to figure out which of many variants for many languages they need to use with that file, which maybe is too hard for them to automate.
So you're intending to have source code files edited by people who don't even know how to write comments in those languages?
Silliness of this aside, it's standard practice to have a Continuous Integration server that builds the source code and ensures that it's at least is still syntactically correct. Yes this is also (largely) true for interpreted languages.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.