/*
 * write a message to all logged-in users
 *
 *  Copyright (c) 2000 David Parsons. All rights reserved.
 *
 *  This software is released under a berkeley-style copyright; the
 *  details can be found in the file COPYRIGHT.
 */

#include <stdio.h>
#include <malloc.h>
#include <stdarg.h>
#include <unistd.h>

char *pgm;


void
error(char *fmt, ...)
{
    va_list ptr;

    va_start(ptr, fmt);
    fprintf(stderr, "%s: ", pgm);
    vfprintf(stderr, fmt, ptr);
    fputc('\n', stderr);
    va_end(ptr);
    exit(1);
} /* error */


main(int argc, char **argv)
{
    char *bfr;
    int   size;
    int   i;

    pgm = basename(argv[0]);

    if (argc > 1) {
	for (size = 0, i = 1; i < argc; i++)
	    size += strlen(argv[i]) + 1;
    }
    else {
	size = 4000;
    }

    if ( (bfr = malloc(size)) == 0)
	error("can't allocate memory for message");

    if (argc > 1) {
	for (i=1; i < argc; i++) {
	    if (i > 1)
		strcat(bfr, " ");
	    strcat(bfr, argv[i]);
	}
    }
    else
	why_why_why_are_we("the message to send", bfr, size);

    wall(bfr);
    exit(0);
} /* wall */
