CSC Roslyn compiler - write errors to STDERR - roslyn

By default the CSC compiler writes all output to STDOUT. Is there a compiler option that can redirect the errors to STDERR?
I need this functionality to write all of the errors to a file. Another option would be to manually parse the output for errors with regex; however there should be a simpler solution.

No; all output always goes to Console.Out.
You can see this in the source.
If you want to, you can send a pull request to change this.
You can also pass the /errorlog option to write errors to a file.

Related

Using FOP, is it possible to output info/warning on the command line?

I use the basic fop command in a cron. Under certain circumstances, for example when a value does not exists, I would like to print a warning on the standard output.
Ideally, I expect a special command like <fox:stdout></fox:stdout> which outputs nothing on the document but can be wrapped inside an <xsl:if></xsl:if> or something alike.
I could not find anything like that in the official documentation (https://xmlgraphics.apache.org/fop/2.0/), how would you do such a thing?
You can use xsl:message to output messages.
Note though that how those messages are output can be different from one processor to the next.

Uncrustify - only report errors without changing the file

Is it possible to only list the set of rules which would have failed on input file without actually applying them? I find it too harsh to just modify the file without letting developer know that file is getting changed under the hood but I would like to get common coding standards and cause build breaks when rules are broken.
I know about --check flag but it only returns whether it succeeded or not without letting developer know which rule failed on which line. Perfectly I would like to get something like:
test.cpp - uncrustify failed on line 42, incorrect use of tabs - pos 0:6.
Also if you know other options where this could be more easily achieved please let me know.

Compatibility issue with old lex-yacc code in new flex-bison

I am on a migration project to move a C++ application from HP-UX to redhad 6.4 server. Now there is a parser application written using lex-yacc, which works fine in HP-UX. Now once we moved the lex specification file (l file) and yacc specification file (y file) to the RHEL 6.4 server, we compiled the code into new system without much change. But the generated parser is not working, everytime it is giving some syntax error with same input file which is correctly parsed in HP-UX. Now as per some reference material on lex and flex incompatibility, there are below points I see in the l file -
It has redefined input, unput and output methods.
The yylineno variable is initialized, and incremented in the redifined input method when '\n' character is found.
The data in lex is read from standard input cin, which looks to be in scanner mode.
How can I find out the possible incompatibilities and remedies for this issue? And is there any way other than using gdb to debug the parser?
Both flex and yacc/bison have useful trace features which can aid in debugging grammars.
For flex, simply regenerate the scanner with the -d option, which will cause a trace line to be written to stderr every time a pattern is matched (whether or not it generates a token). I'm not sure how line number tracking by the debugging option will work with your program's explicit yylineno manipulation, but I guess that is just cosmetic. (Personally, unless you have a good reason not to, I'd just let flex track line numbers.)
For bison, you need to both include tracing code in the parser, and enable tracing in the executable. You do the former with the -t command-line option, and the latter by assigning a non-zero value to the global variable yydebug. See the bison manual for more details and options.
These options may or may not work with the HPUX tools, but it would be worth trying because that will give you two sets of traces which you can compare.
You don't want to debug the generated code, you want to debug the parser (lex/yacc code).
I would first verify the lexer is returning the same stream of tokens on both platforms.
Then reduce the problem. You know the line of input that the syntax error occurs on. Create a stripped down parser that supports parsing the contents of that line, and if you can't figure out what is going on from that, post the reduced code.

Change the text of a gcc compiler error

At my company we have recently done some tricky stuff with C++ and templates, making use of some features of the compiler. When working with this code people need to take a few setup steps otherwise they get some rather cryptic compiler errors, what I would like to do is determine if there is a way to tell the compiler to inject, and or swap out the message published for an error when compiling? so that I either get a friendly message that instructs the person in conjunction with the cryptic error or instead of the cryptic error.
Thank you.
You have a couple of options, I think. First, you could use your build system and add a step to post-process the build output before showing it to the user; then you could detect and modify the error messages you care about. The other option, if you have access to your compiler's source code, is just to modify those strings in the compiler directly.
You should look into Static Assert.
gcc source.c 2>&1 | sed -e 's/Cryptic Message/Friendly Message/'
Mostly kidding. Adding post build step is probably better.
Could you wrap the compiler in a script instead? The script would run the compiler and consume STDOUT/STDERR, and output user friendly messages instead.

C++ Passing Options To Executable

How do you pass options to an executable? Is there an easier way than making the options boolean arguments?
EDIT: The last two answers have suggested using arguments. I know I can code a workable solution like that, but I'd rather have them be options.
EDIT2: Per requests for clarification, I'll use this simple example:
It's fairly easy to handle arguments because they automatically get parsed into an array.
./printfile file.txt 1000
If I want to know what the name of the file the user wants to print, I access it via argv[1].
Now about how this situation:
./printfile file.txt 1000 --nolinebreaks
The user wants to print the file with no line breaks. This is not required for the program to be able to run (as the filename and number of lines to print are), but the user has the option of using if if s/he would like. Now I could do this using:
./printfile file.txt 1000 true
The usage prompt would inform the user that the third argument is used to determine whether to print the file with line breaks or not. However, this seems rather clumsy.
Command-line arguments is the way to go. You may want to consider using Boost.ProgramOptions to simplify this task.
You seem to think that there is some fundamental difference between "options" that start with "--" and "arguments" that don't. The only difference is in how you parse them.
It might be worth your time to look at GNU's getopt()/getopt_long() option parser. It supports passing arguments with options such as --number-of-line-breaks 47.
I use two methods for passing information:
1/ The use of command line arguments, which are made easier to handle with specific libraries such as getargs.
2/ As environment variables, using getenv.
Pax has the right idea here.
If you need more thorough two-way communication, open the process with pipes and send stuff to stdin/listen on stdout.
You can also use Window's PostMessage() function. This is very handy if the executable you want to send the options to is already running. I can post some example code if you are interested in this technique.
The question isn't blazingly clear as to the context and just what you are trying to do - you mean running an executable from within a C++ program? There are several standard C library functions with names like execl(), execv(), execve(), ... that take the options as strings or pointer to an array of strings. There's also system() which takes a string containing whatever you'd be typing at a bash prompt, options and all.
I like the popt library. It is C, but works fine from C++ as well.
It doesn't appear to be cross-platform though. I found that out when I had to hack out my own API-compatible version of it for a Windows port of some Linux software.
You can put options in a .ini file and use the GetPrivateProfileXXX API's to create a class that can read the type of program options you're looking for from the .ini.
You can also create an interactive shell for your app to change certain settings real-time.
EDIT:
From your edits, can't you just parse each option looking for special keywords associated with that option that are "optional"?