Read ~/.dcrc at startup of dc

Patch taken from old version of dc by Paul Dwerryhouse
Was initially applied by Francois Marier <francois@debian.org> in the NMU
1.06.94-3.1 to close http://bugs.debian.org/472250 .
Then it disappeared along the way, until users asked for it again.
Jan Braun <janbraun@gmx.net> updated it to read .drcr before argument
processing so that
    $ dc
    $ dc -
    $ dc -f -
all have the same behaviour
Origin: vendor
Bug-Debian: http://bugs.debian.org/582137
Bug-Ubuntu: https://bugs.launchpad.net/debian/+source/bc/+bug/918836
Forwarded: no
Reviewed-by: Ryan Kavanagh <rak@debian.org>
Last-Update: 2013-06-02

Gbp-Pq: Name 06_read_dcrc.diff
This commit is contained in:
Openkylin Developers 2022-08-15 16:25:12 +08:00 committed by Lu zhiping
parent 1f95a91f0f
commit 1db65a601a
2 changed files with 35 additions and 0 deletions

27
dc/dc.c
View File

@ -43,6 +43,8 @@
# include <sys/stat.h>
#endif
#include <getopt.h>
#include <pwd.h>
#include <unistd.h>
#include "dc.h"
#include "dc-proto.h"
@ -246,6 +248,29 @@ flush_okay DC_DECLVOID()
return r;
}
static void
try_rcfile(void)
{
char *homedir;
struct passwd *pw;
char *rcfile;
FILE *input;
homedir=getenv("HOME");
if (!homedir)
{
pw=getpwuid(getuid());
homedir=pw->pw_dir;
}
rcfile=malloc(strlen(homedir)+8);
sprintf(rcfile, "%s/.dcrc", homedir);
if (!(input=fopen(rcfile, "r")))
return;
if (dc_evalfile(input))
exit(EXIT_FAILURE);
fclose(input);
}
int
main DC_DECLARG((argc, argv))
@ -268,6 +293,8 @@ main DC_DECLARG((argc, argv))
dc_register_init();
dc_array_init();
try_rcfile();
while ((c = getopt_long(argc, argv, "hVe:f:", long_opts, (int *)0)) != EOF) {
switch (c) {
case 'e':

View File

@ -514,6 +514,14 @@ Thus \fB1 0:a 0Sa 2 0:a La 0;ap\fP will print 1,
because the 2 was stored in an instance of 0:a that
was later popped.
.SH
FILES
.TP 15
~/.dcrc
The commands in this file will be executed when
.I dc
is first run.
.PP
.SH
BUGS
.PP
Email bug reports to