Esempio n. 1
0
File: draw.c Progetto: sirpengi/rirc
int
print_line(int row, line *l)
{
	if (l < ccur->chat)
		l += SCROLLBACK_BUFFER;

	if (!l->len || l == ccur->cur_line)
		return 3;

	int count = 1;
	char *ptr1, *ptr2, *wrap;

	ptr1 = l->text;
	ptr2 = l->text + l->len;

	while ((ptr1 = word_wrap(ptr1, ptr2)) != NULL && ptr1 != ptr2)
		count++;

	if (row - count > 2)
		row = print_line(row - count, l - 1) + count - 1;

	ptr1 = l->text;
	if ((wrap = word_wrap(ptr1, ptr2)) != NULL)
		row = print_more(wrap, ptr2, row);
	else
		wrap = ptr2;

	int from_fg;
	char *from_bg = "";

	if (l->type == LINE_JOIN || l->type == LINE_PART || l->type == LINE_QUIT)
		from_fg = 239;
	else if (l->type == LINE_PINGED)
		from_fg = 255, from_bg = BG(1);
	else
		from_fg = nick_col(l->from);

	if (row > 2) {
		printf("\x1b[%d;1H\x1b[2K", row);
		printf(FG(239)" %02d:%02d  %*s"FG(%d)"%s%s"BG_R FG(239)" ~ "FG(250),
				l->time_h, l->time_m,
				(int)(ccur->nick_pad - strlen(l->from)), "",
				from_fg, from_bg, l->from);
		while (ptr1 < wrap)
			putchar(*ptr1++);
	}
Esempio n. 2
0
void
init()
{
    char 		*home, *realname, *argv[4];
    extern char		*getlogin();
    char		buf[MAXPATHLEN];
#if defined(SYSV) && !defined(HPUX) && !defined(IRIX4)
    extern struct passwd *getpwuid();  /* sys-v forgot this in pwd.h! */
    struct utsname ourhost;
#else
    char ourhost[128];
#endif /* SYSV && !HPUX && !IRIX4 */
    register char 	*p;
    struct passwd 	*entry;
    int			cnt;
#if defined(BSD) || defined(HPUX) || defined(IRIX4)
    struct hostent 	*hp;
#endif /* BSD || HPUX || IRIX4 */

    home = getenv("HOME");
    if (realname = getenv("NAME")) {
	(void) strcpy(buf, realname);
    }
    argv[1] = "=";
    argv[3] = NULL;

    if (!(entry = getpwuid(getuid())))
	if (p = getlogin())
	    strdup(login, p);
	else {
	    strdup(login, "unknown");
	    print("I don't know you, but that's ok.\n");
	}
    else {
	strdup(login, entry->pw_name);
	if (!home || !*home)
	    home = entry->pw_dir;
	if (!realname && (realname = entry->pw_gecos)) {
	    if (p = index(realname, ','))
		*p = 0;
	    for (p = buf; *realname; realname++)
		if (*realname == '&')
		    *p++ = upper(*login), p += Strcpy(p, login+1);
		else
		    *p++ = *realname;
	    *p = 0;
	}
	endpwent();
    }
    if (!home || !*home || Access(home, W_OK)) {
	if (home && *home)
	    error(home);
	else
	    print("No home!? ");
	print_more("Using \"%s\" as home.\n", home = ALTERNATE_HOME);
    } else {
	argv[0] = "home";
	argv[2] = home;
	(void) add_option(&set_options, argv);
    }

    if (realname && *buf) {
	/* realname has already been copied to buf */
	argv[0] = "realname";
	argv[2] = buf;
	(void) add_option(&set_options, argv);
    }

#ifdef HOMEMAIL
    strdup(spoolfile, sprintf(buf, "%s/%s", home, MAILFILE));
#else /* HOMEMAIL */
#ifdef ENV_MAIL
    if ((p = getenv("MAIL")) && *p)
	strdup(spoolfile, p);
    else
#endif /* ENV_MAIL */
	strdup(spoolfile, sprintf(buf, "%s/%s", MAILDIR, login));
#endif /* HOMEMAIL */
    mailfile = "";

    crt = 24;
    screen = 18;
    wrapcolumn = 0; /* Default is no wrap */
    escape = DEF_ESCAPE;
    prompt = DEF_PROMPT;

#if defined(BSD) || defined(HPUX) || defined(IRIX4)
    (void) gethostname(ourhost, sizeof ourhost);
    if (!(hp = gethostbyname(ourhost))) {
	if (ourname = (char **)calloc((unsigned)2, sizeof (char *)))
	    strdup(ourname[0], ourhost);
    } else {
	int n = -1;
	cnt = 2; /* 1 for ourhost and 1 for NULL terminator */

        for (p = hp->h_name; p && *p; p = hp->h_aliases[++n])
            if (strcmp(ourhost, p)) /* if host name is different */
                cnt++;

        if (ourname = (char **)malloc((unsigned)cnt * sizeof (char *))) {
            n = -1;
            cnt = 0;
            ourname[cnt++] = savestr(ourhost);
            for (p = hp->h_name; p && *p; p = hp->h_aliases[++n])
                if (strcmp(ourhost, p)) /* if host name is different */
                    ourname[cnt++] = savestr(p);
            ourname[cnt++] = NULL;
        }
    }
#else
#ifdef SYSV
    if (ourname = (char **)calloc((unsigned)2, sizeof (char *))) {
	if ((uname (&ourhost) >= 0) && (*ourhost.nodename))
	    ourname[0] = savestr(ourhost.nodename);
	else {
	    /* Try to use uuname -l to get host's name if uname didn't work */
	    char buff[50];
	    char *p;
	    FILE *F;

	    if (F = popen("exec uuname -l", "r")) {
		if ((fgets(buff, sizeof buff, F) == buff) &&
			(p = strchr(buff, '\n'))) {
		    *p = '\0';		/* eliminate newline */
		    ourname[0] = savestr (buff);
		}
	    (void)pclose(F);
	    }
	}
    }
#endif /* SYSV */
#endif /* BSD || HPUX || IRIX4 */
    if (ourname && ourname[0]) {
	for (p = buf, cnt = 0; ourname[cnt]; cnt++) {
	    if (cnt)
		*p++ = ' ';
	    p += Strcpy(p, ourname[cnt]);
	}
	argv[0] = "hostname";
	argv[2] = buf;
	(void) add_option(&set_options, argv);
    }

    init_bindings();
}