mirror of https://gitee.com/openkylin/bc.git
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:
parent
1f95a91f0f
commit
1db65a601a
27
dc/dc.c
27
dc/dc.c
|
@ -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':
|
||||
|
|
Loading…
Reference in New Issue