How to change Doxygen macro / function arguments formatting? - doxygen

I want to change Doxygen macros and function arguments formatting. Whatever this formatting is trying to achieve can be done with #param, which will describe function parameters way better in the section down below. Also, explicitly saying void as function arguments formats it with some strange spacing, while right above it Doxygen understood that nop(void) is equal to nop(), which just drives me crazy.
I think that macro / function arguments formatting should be a configurable option. I want to change mine formatting from multiline to one line, since I don't see the benefits of doing otherwise.
#define ADD(a, b) a + b
int add(int a, int b)
I couldn't find anything about function arguments formatting. About void people said to use aliases, but gave no examples, so I am stuck here. Hope I gave enough info on what I am trying to achieve!

Related

libreoffice calc - varargs in macros

I understand Excel has a TEXTJOINfunction which allows one to display multiple values as a tuple.
I also understand Libre Office does - for whatever reason - not have them.
How do I write an auxiliary macro vec that produces the desired tuple representation for me?
E.g. =vec(A1) should produce ="("&A1&")",
=vec(A1:A3) should produce ="("&A1&","&A2&","&A3&")",
=vec(A1,X5:X99,Z3) should result in ="("&A1&","&"X5"&","&X6&...&x99&","&Z3&")"
etc, etc.
Easy enough a macro to implement in, say, bash, but I would like to just define it once then use it in calc, not constantly copy from console to spreadsheet.
How do I implement this in calc?
According to https://forum.openoffice.org/en/forum/viewtopic.php?f=45&t=67880, it is possible for a Basic function to use a variable number of arguments if it is declared with Option Compatible. This makes it behave more like MS Excel. The argument is declared as ParamArray pa().
The link that #tohuwawohu posted shows most of the implementation details needed.
To do it in a way that is more native to LibreOffice, write a Spreadsheet Add-In with a Java declaration that uses any[] as an argument. For information about add-in argument types, see https://www.openoffice.org/api/docs/common/ref/com/sun/star/sheet/AddIn.html.
The actual function can also be implemented in Java. Or, it can probably be implemented in another language that accepts a variable number of arguments, such as Python *args.

Get old-style help in Matlab's command window

Short version of question
In recent versions of Matlab (I have seen it in R2014b and R2015a on Windows), when you type help foo you get a brief description of the function and its signatures. For example, typing help bsxfun produces something like this (only with better format):
This MATLAB function applies the element-by-element binary operation specified by the function handle fun to arrays A and B, with singleton expansion enabled.
C = bsxfun(fun,A,B)
Reference page for bsxfun
See also arrayfun, repmat
Other uses of bsxfun
distcomp/bsxfun
This is of course only a summary of the actual documentation. To get the full documentation you need to type doc foo. This opens the HTML help browser, which takes quite some time (at least on some computers).
Is there a way to get the full help in the command window (thus avoiding the help browser), as it used to be in older Matlab versions?
Long version of question
To look into this in more detail, I'll define "old" Matlab versions as those that don't have HTML help, and "new" versions as those that do. I also need to give each type of help a name, in order to refer to them:
FP (Full, Plain): full help in the form of plain text, shown in Matlab command window (old style).
SH (Summarized, HTML): summarized help in the form of HTML, shown in Matlab command window.
FH (Full, HTML): full help in the form of HTML, shown in the help browser.
As is well known, the text for FP help is contained in the first comment lines in the file defining the function. In new Matlab versions, functions may also have an associated HTML file. This file contains SH help in an HTML tag, and FH help in HTML code.
Possible behaviour is:
In old Matlab versions, help foo produced FP help.
In new Matlab versions, help foo produces SH help if foo has an associated HTML help file, and FP help if it doesn't.
In new Matlab versions, doc foo produces FH help if foo has an associated HTML help file. If it doesn't, FP help is shown in the help browser (without format).
So the problem is more properly phrased as: how to show FP help in new Matlab versions when foo has an associated HTML help file. The question is meaningful because
Most Matlab functions do have an associated HTML help file.
Most Matlab functions, even built-in functions (that have no m-code), have and m-file containing FP help.
An additional motivation is that in some cases the FP documentation contains features that don't appear in the FH documentation (see for example here).
Original answer (Matlab versions R2014b, R2015a)
Although the documentation doesn't tell, the help function in these Matlab versions supports zero, one or two output arguments. You can check this typing open help and looking at the function signature:
function [out, docTopic] = help(varargin)
In essence, help works internally as follows:
It creates an object called process, of class helpUtils.helpProcess, by calling the class constructor as:
process = helpUtils.helpProcess(nargout, nargin, varargin);
where nargout, argin and varargin are those with which help was called.
It runs the method process.getHelpText, which calls the undocumented, built-in function helpfunc, and as a result sets the property process.helpStr. This property contains the help string which is shown in the command window.
As it turns out, at least on Windows, depending on the value of nargout (which gets passed to the constructor helpUtils.helpProcess) the resulting help string will be FP or SH. Namely, it will be FP if nargout>0, and SH if nargout==0. You can check this by typing the following code (adapted from help.m) directly in the command window:
process = helpUtils.helpProcess(1, 1, {'bsxfun'});
process.getHelpText
process.helpStr
This will produce FP help. On the other hand, changing the first 1 (which corresponds to nargout in the actual call) into a 0,
process = helpUtils.helpProcess(0, 1, {'bsxfun'});
process.getHelpText
process.helpStr
will produce SH help.
I don't know why this is so, that is, how it works on a deeper level than this. All I know is that the getHelp method calls the undocumented helpfunc, which is at least involved in producing FP help.
So, to get FP help you need to call help with one or two output arguments. For example,
str = help('foo')
assigns the FP help text to variable str and displays it. Or you can use
disp(help('foo'))
which also has the effect of calling help with an (implicit) output argument.
To have this behaviour from the standard command help foo, you could define a help function to override Matlab's help, and place it in your Matlab document folder. This folder normally appears first in the path (or you can make sure it does by editing startup.m), and thus has precedence. The new function will essentially call Matlab's help with one output argument, and then display the resulting (FP) help text. In order to call the overriden function it is necessary to temporarily change to its folder:
function help(varargin)
if isempty(varargin)
varargin = {'help'}; %// `help` should be equivalent to `help help`
end
d = pwd; %// take note of current folder
cd(fullfile(matlabroot, 'toolbox', 'matlab', 'helptools')) %// folder where the
%// standard `help` function is
disp(help(varargin{1}));
cd(d) %// restore folder
So now, finally, help foo produces the old-style (FP) help.
Edit for Matlab version R2015b
In Matlab R2015b the behaviour seems to have changed for the better. Typing help foo no longer produces SH help. It's not exactly FP either. In fact it's better than that: it produces FH help but in the command Window, not in the browser. Or, equivalently, it produces FP help but with links and better formattting.
So no need to tweak anymore!
Edit for Matlab version R2018a
Matlab R2018a again gives SH help. The solution provided in this answer works (that is, produces FP help).
So back to tweaking!
A better way is to include the full path to the function when using the help command, then old style full help is displayed and the links also work, e.g. try:
help surf
help(fullfile(matlabroot, 'toolbox', 'matlab', 'graph3d', 'surf.m'))
I’ve just submitted an override help function based on this to MATLAB FEX:Full Command Line Help

In a function show passed arguments in a different color [duplicate]

In Emacs, is it possible to mark all variables of different data types with different colors? e.g. if I have the following variables in C/C++ my program
int i,j;
float g,h;
char a,b;
Then throughout the source code i and j would be marked as red, g and h as green, a and b as blue.
I am not sure how useful this will be in future, but I feel it would help me while reading code,
and be a good alternative to the Hungarian notation(not that I use this notation :D).
No. Emacs has no idea about the type of a specific expression; doing this would be tantamount to writing a significant part of a C compiler in ELisp.
However, there is a light at the end of the tunnel.
E.g., if you edit OCaml code using tuareg-mode, you can ask Emacs about the type of any expression because the ocaml compiler provides that information; thus you should be able to ask it to highlight variables by type. This is the path to follow.
Alas, gcc does not provide that information; however, its extensiongccxml does.
Also, other C compilers, e.g., clang, provide that information out of the box, and there is a new file semantic-clang.el which relies on those features (although for completion only, not for syntax highlighting).
So, nothing out of the box for you here, but if you are willing to use clang instead of gcc and contribute to the CEDET development, you might get what you want.
No, it's not possible to selectively assign a given color to a given variable in emacs (or just for one given program).
However, if it's just syntax highlighting you are looking for, of course, emacs will highlight most languages, and you can even create syntax highlighting for languages emacs would not know about.
Ex. Smali: https://github.com/strazzere/Emacs-Smali

C\C++ Preprocessor different arg for overloaded macros

I want to realize logging in my project.
I have macro, smth like
__LOG_TRACE(lg, expr,...) LOG_TRACE_STREAM(lg) << expr;
So I want to realize interface for this macro - another macro, but I want to support 2 types:
LOG_TRACE(msg);
LOG_TRACE(my_logger, msg);
I have some global logger, and first macro will write msg using global logger.
Second macro will take my_logger and write msg using it.
I can make it with LOG_TRACE(msg, my_logger); - but it's not good, it's harder to read in code. Order of arguments in __LOG_TRACE is not necessary.
Upd:
I don't mean overloading macros.
Look - for example I can do this
#define LOG_TRACE(...) __LOG_TRACE(__VA_ARGS__, current_active)
Now I can write
LOG_TRACE(msg);
LOG_TRACE(msg, logger);
But I want not msg,logger and logger,msg
Macro overloading is not allowed in C or C++. But there are workarounds. Here's an article that will help you "overload" your macro: http://cplusplus.co.il/2010/08/31/overloading-macros/
If you don't have a variable number of loggers, i recommend you to make a macro for each logger. ex (LOG_TRACE_XML, LOG_TRACE_OUT, LOG_TRACE_TXT). Because simpler is better.
But a better way to do this is to have LOG_TRACE_ERROR/ LOG_TRACE_WARNING/ LOG_TRACE_INFO and manage the way these macros behave using IPC or another macro (SET_MODE(XML/TXT/OUT))
You cannot overload pre-processor macros, your compiler will consider this a redeclaration, rather than an overload, and so only the 2nd will be valid.
You should attempt to name your macros differently, both for readability and because that's the only way you'll get the functionality you want.
Why not make it a function + do and stringify expression macro?
#define DO_AND_RETURN_STRING_EXPR(x) (x,#x)
ov(DO_AND_RETURN_STRING_EXPR(y))
ov(my_logger, DO_AND_RETURN_STRING_EXPR(y))
(note I haven't tested this code).
__VA_ARGS__ is an extension to the current C++ standard, but if you are willing to play with this P99 has a lot of utility macros to achieve what you want. In particular macros that implement conditionals according to the number of arguments they are called.
#define LOG_TRACE(...) \
P99_IF_EQ_1(P99_NARG(__VA_ARGS__)) \
(LOG_TRACE_(my_logger, __VA_ARGS__)) \
(LOG_TRACE_(__VA_ARGS__))
P99 is not really C++ compatible, so you'd have to adapt things a bit.
BTW, identifiers that start with _ and a capital letter or another underscore are reserved by C and C++. Double underscores in general are not allowed for C++ because they could interfere with name mangling. So you'd better chose a different name for your base macro.

ANTLR, C-styled macro definitions

What is the easiest (or the best) way to implement macro definitions in ANTLR?
What I want is a mechanism similar to the one that is present in C/C++ language:
#define FUNCTION(a, b) a+b
#define PI 3.1415
How and when should I perform replacement?
If you are doing a pre-processor in the style of C, then you will want to do a separate first pass for pre-processing (which is what this term means - a processing pass before your standard lex/parse pass).
Exactly how you want to do the pass is up to you - you can pass your input text to one grammar in antlr, take the result and hand that off to another grammar, etc.
Or you can create separate programs, which are able to take input on stdin and output to stdout, or pass text between pipes, etc.
Once you have that worked out, its a simple matter of looking for your keywords. Check every token that you see against your table of #defines, and if it matches, replace it with the definition that you have. You will also have to be able to parse function parameters, but that shouldn't add too much effort.