diff --git a/dc/dc.c b/dc/dc.c index ccdb1c2..1f7f1ad 100644 --- a/dc/dc.c +++ b/dc/dc.c @@ -43,6 +43,8 @@ # include #endif #include +#include +#include #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': diff --git a/doc/dc.1 b/doc/dc.1 index 7a79ad4..02c4abd 100644 --- a/doc/dc.1 +++ b/doc/dc.1 @@ -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