Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 12 Aug 2006 07:15:35 +0300
From:      Giorgos Keramidas <keramida@FreeBSD.org>
To:        Julian Elischer <julian@elischer.org>
Cc:        current@FreeBSD.org
Subject:   Re: suggested addition to 'date'
Message-ID:  <20060812041535.GA82669@gothmog.pc>
In-Reply-To: <44DD50FF.5040406@elischer.org>
References:  <44DD4510.5070002@elischer.org> <20060812033607.GB80768@gothmog.pc> <44DD50FF.5040406@elischer.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On 2006-08-11 20:54, Julian Elischer <julian@elischer.org> wrote:
> Yes I said I hacked it in :-)
> In my app you will never have such long lines..
> basically you need something that reads lines and tells you how much it 
> read..
> (I have no idea WHY fgets need sto return the START.. you already KNOW 
> that!)
> it'd be nice if you didn't have to to a strlen() on each line.

Perhaps the solution Sam proposed is much better then?  To read one
character at-a-time and only special-case the '\n' characters?

Maybe something like this?

	if (sflag) {
		int ch;
		time_t otval = 0;

		while ((ch = getchar()) != EOF) {
			putchar(ch);
			if (ch != '\n')
				continue;

			if (rlfag == 0 && time(&tval) == -1)
				err(1, "time");
			if (tval != otval) {
				lt = *localtime(&tval);
				badv = vary_apply(v, &lt);
				if (badv) {
					fprintf(stderr,
					    "%s: Cannot apply date adjustment\n",
					    badv->arg);
					vary_destroy(v);
					usage();
				}
				(void)strftime(buf, sizeof(buf), format, &lt);
				otval = tval;
			}
			(void)printf("%s", buf);
			if (fflush(stdout))
				err(1, "stdout");
		}
	} ...
			



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060812041535.GA82669>