Re: suggested addition to 'date'

From: Giorgos Keramidas <keramida_at_FreeBSD.org>
Date: Sat, 12 Aug 2006 07:15:35 +0300
On 2006-08-11 20:54, Julian Elischer <julian_at_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");
		}
	} ...
			
Received on Sat Aug 12 2006 - 02:16:05 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:58 UTC