From: Peter Stephenson <pws@cambridgesiliconradio.com>
To: zsh-workers@sunsite.auc.dk (Zsh hackers list)
Subject: Re: Zsh 3.1.{6,9} patches
Date: Thu, 13 Jul 2000 17:32:53 +0100 [thread overview]
Message-ID: <0FXN00BPE9YTW3@la-la.cambridgesiliconradio.com> (raw)
In-Reply-To: "Your message of Thu, 13 Jul 2000 15:53:33 -0000." <1000713155333.ZM19233@candle.brasslantern.com>
Bart wrote:
> On Jul 13, 12:12pm, Peter Stephenson wrote:
> } Subject: Re: Zsh 3.1.{6,9} patches
> }
> } Would anyone object if I got rid of hostnam and made the prompt code
> } read $HOST? The only user-visible change would be that the prompt
> } reflects changes in $HOST, as it already does with $HOME.
>
> I think that would be fine.
Here it is. We save almost a quarter of a kilobyte, since hostnam was
always initialised to 256 bytes which were never freed. (And I checked out
this morning's %-1m, which allows you to display your .com address in the
prompt.)
Index: Src/init.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/init.c,v
retrieving revision 1.5
diff -u -r1.5 init.c
--- Src/init.c 2000/05/27 08:32:58 1.5
+++ Src/init.c 2000/07/13 16:26:23
@@ -595,9 +595,6 @@
gettimeofday(&shtimer, &dummy_tz); /* init $SECONDS */
srand((unsigned int)(shtimer.tv_sec + shtimer.tv_usec)); /* seed $RANDOM */
- hostnam = (char *) zalloc(256);
- gethostname(hostnam, 256);
-
/* Set default path */
path = (char **) zalloc(sizeof(*path) * 5);
path[0] = ztrdup("/bin");
Index: Src/params.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/params.c,v
retrieving revision 1.22
diff -u -r1.22 params.c
--- Src/params.c 2000/07/04 15:04:17 1.22
+++ Src/params.c 2000/07/13 16:26:27
@@ -56,7 +56,6 @@
/**/
char *argzero, /* $0 */
*home, /* $HOME */
- *hostnam, /* $HOST */
*nullcmd, /* $NULLCMD */
*oldpwd, /* $OLDPWD */
*zoptarg, /* $OPTARG */
@@ -458,7 +457,7 @@
Param ip, pm;
char **new_environ, **envp, **envp2, **sigptr, **t;
char **old_environ = environ;
- char buf[50], *str, *iname;
+ char buf[50], *str, *iname, *hostnam;
int num_env, oae = opts[ALLEXPORT];
#ifdef HAVE_UNAME
struct utsname unamebuf;
@@ -494,7 +493,12 @@
setsparam("TMPPREFIX", ztrdup(DEFAULT_TMPPREFIX));
setsparam("TIMEFMT", ztrdup(DEFAULT_TIMEFMT));
setsparam("WATCHFMT", ztrdup(default_watchfmt));
+
+ hostnam = (char *)zalloc(256);
+ gethostname(hostnam, 256);
setsparam("HOST", ztrdup(hostnam));
+ zfree(hostnam, 256);
+
setsparam("LOGNAME", ztrdup((str = getlogin()) && *str ? str : cached_username));
/* Copy the environment variables we are inheriting to dynamic *
Index: Src/prompt.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/prompt.c,v
retrieving revision 1.2
diff -u -r1.2 prompt.c
--- Src/prompt.c 2000/07/13 11:20:46 1.2
+++ Src/prompt.c 2000/07/13 16:26:30
@@ -201,7 +201,7 @@
static int
putpromptchar(int doprint, int endchar)
{
- char *ss, *tmbuf = NULL;
+ char *ss, *tmbuf = NULL, *hostnam;
int t0, arg, test, sep;
struct tm *tm;
time_t timet;
@@ -372,11 +372,14 @@
bp += strlen(bp);
break;
case 'M':
- stradd(hostnam);
+ if ((hostnam = getsparam("HOST")))
+ stradd(hostnam);
break;
case 'm':
if (!arg)
arg++;
+ if (!(hostnam = getsparam("HOST")))
+ break;
if (arg < 0) {
for (ss = hostnam + strlen(hostnam); ss > hostnam; ss--)
if (ss[-1] == '.' && !++arg)
--
Peter Stephenson <pws@cambridgesiliconradio.com>
Cambridge Silicon Radio, Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK Tel: +44 (0)1223 392070
next prev parent reply other threads:[~2000-07-13 16:33 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-07-13 9:59 Fr. Br. George
2000-07-13 11:12 ` Peter Stephenson
2000-07-13 14:56 ` Clint Adams
2000-07-13 15:16 ` Peter Stephenson
2000-07-13 15:53 ` Bart Schaefer
2000-07-13 16:32 ` Peter Stephenson [this message]
2000-07-14 11:32 ` Fr. Br. George
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0FXN00BPE9YTW3@la-la.cambridgesiliconradio.com \
--to=pws@cambridgesiliconradio.com \
--cc=zsh-workers@sunsite.auc.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).