Implement new '--output-dir' option.
authorSergio Durigan Junior <sergiodj@sergiodj.net>
Sun, 23 Mar 2014 05:19:29 +0000 (02:19 -0300)
committerThadeu Lima de Souza Cascardo <cascardo@cascardo.info>
Mon, 24 Mar 2014 22:46:14 +0000 (19:46 -0300)
commitbde4c96fb962e4f8f252bb6f21be8426deafbbb5
tree60875a8808dae56ccff3c150d3d7ea19473dc1be
parente65bbb776b2cc8a7b354e2b7ac16bb5fc19f8eda
Implement new '--output-dir' option.

This commit implements the new '--output-dir' (or '-o') option.  It can
be used to specify where the receipt of the submission will be saved.

Currently, rnetclient saves the receipt in your $HOME, with a generic
name which is composed using the CPF and some random digits.  This is
not good because the proprietary IRPF program expects the receipt name
to be the same as the declaration name, but with the extension renamed
from ".DEC" to ".REC".

This patch implements some new concepts.  First, if the user provides an
output directory in the command line, we save the receipt there.  If she
does not provide anything, then we save the receipt in the current
working dir (CWD), which is a more sensitive decision IMO.  Also, and
perhaps more important, is the fact that now the program automagically
detects when the filename has the ".DEC" extension, and uses the same
filename for the receipt in this case (replacing ".DEC" by ".REC", as
expected).  This makes the proprietary crap recognize our receipt
out-of-the-box, without having to worry with renamings.  It is worth
mentioning that if the user provides a declaration file which does not
have the ".DEC" extension, then rnetclient fallbacks to the old behavior
and saves the filename as "$CPF.REC" (I chose not to use random digits
in the end of the filename).

On a side note, I would like to say that I am not entirely happy with
the way we handle missing directories and files, but that is a topic for
a completely different patch...
rnetclient.c