[HACKERS] Patch to psql.c to allow .psqlrc file - Mailing list pgsql-hackers

From Andrew Martin
Subject [HACKERS] Patch to psql.c to allow .psqlrc file
Date
Msg-id 024d9227827da5fa66affde308565d98
Whole thread Raw
List pgsql-hackers
OK, here's a quick patch to psql.c which first reads commands from
/etc/psqlrc and then from $HOME/.psqlrc

I've used access() to check on the existence of these files; I'm
not sure if every system has access(), so it might be necessary
to change to stat() instead. Certainly Linux and Irix *do* have
access()

Andrew


*** src/bin/psql/psql.c.orig    Fri Jun 20 21:54:31 1997
- --- src/bin/psql/psql.c    Fri Jun 20 22:23:49 1997
***************
*** 1598,1603 ****
- --- 1598,1605 ----
      bool            singleSlashCmd = 0;
      int             c;

+     char           *home = NULL;  /* Used to store $HOME */
+
      memset(&settings, 0, sizeof settings);
      settings.opt.align = 1;
      settings.opt.header = 1;
***************
*** 1728,1733 ****
- --- 1730,1760 ----
      printf("   type \\g or terminate with semicolon to execute query\n");
      printf(" You are currently connected to the database: %s\n\n", dbname);
      }
+
+     /*
+      * 20.06.97 ACRM See if we've got a /etc/psqlrc or .psqlrc file
+      */
+     if(!access("/etc/psqlrc",R_OK))
+        HandleSlashCmds(&settings, "\\i /etc/psqlrc", "");
+     if((home = getenv("HOME"))!=NULL) {
+        char *psqlrc = NULL,
+        *line   = NULL;
+
+        if((psqlrc = (char *)malloc(strlen(home) + 10))!=NULL) {
+           sprintf(psqlrc, "%s/.psqlrc", home);
+           if(!access(psqlrc, R_OK)) {
+              if((line = (char *)malloc(strlen(psqlrc) + 5))!=NULL) {
+                 sprintf(line, "\\i %s", psqlrc);
+                 HandleSlashCmds(&settings, line, "");
+                 free(line);
+              }
+           }
+           free(psqlrc);
+        }
+     }
+     /* End of check for psqlrc files */
+
+
      if (qfilename || singleSlashCmd) {
      /*
       * read in a file full of queries instead of reading in queries

- ----------------------------------------------------------------------------
Dr. Andrew C.R. Martin                             University College London
EMAIL: (Work) martin@biochem.ucl.ac.uk    (Home) andrew@stagleys.demon.co.uk
URL:   http://www.biochem.ucl.ac.uk/~martin
Tel:   (Work) +44(0)171 419 3890                    (Home) +44(0)1372 275775

------------------------------

pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: [HACKERS] Tuple size
Next
From: Igor
Date:
Subject: Re: [HACKERS] 6.1 jumbo patch?