Beispiel #1
0
void MsBopB(){

    switch (getAH()) {

        case 0 :
            setAH(0);
        while (!tkbhit());
        setAL((BYTE)tgetch());
            break;

        case 1 :
        tputch(getAL());
            break;
    }
}
/* getline: read a line into s, return length. This len returned does not include the \0, so if the len is 5, means that the message is contained in s[0-4] and in s[5] we have a \0. An empty line (starting with \n or EOF) has len = 0 */
int getlineLOCAL(char s[], int lim) {
	
	int c;				/*holds the input*/
	short i;			/*dummy*/
	lim--;				/*lim -1, because we need to save one slot for the \0!!*/

	/*Copying and counting*/
	for (i=0; i<lim ; i++) {		/*the for ranges the index from 0 to lim-1 and has an inner break condition too*/
		c = tgetch(DEFAULT_TIMER);
		if ( c==EOF || c=='\n')
			break;
		s[i] = c;
	}

	s[i] = '\0';				/*puts the \0 and the line is finished!*/
	return i;
}
Beispiel #3
0
int
main(int argc, char *argv[])
{
	const char *user = getenv("USER");
	const char *ircnick = getenv("IRCNICK");
	const char *server = SRV;
	unsigned short port = PORT;
	int o;

	while ((o=getopt(argc, argv, "hn:u:s:p:"))>=0)
		switch (o) {
		case 'h':
		case '?':
		usage:
			fputs("Usage: irc [-n NICK] [-u USER] [-s SERVER] [-p PORT] [-h]\n", stderr);
			exit(0);
		case 'n':
			if (strlen(optarg)>=sizeof nick) goto usage;
			strcpy(nick, optarg);
			break;
		case 'u':
			user = optarg;
			break;
		case 's':
			server = optarg;
			break;
		case 'p':
			if (!(port=strtol(optarg, 0, 0))) goto usage;
			break;
		}
	if (!nick[0] && ircnick && strlen(ircnick)<sizeof nick)
		strcpy(nick, ircnick);
	if (!nick[0]) goto usage;
	if (!user) user = "******";
	tinit();
	sfd = dial(server, port);
	chadd("*server*");
	sndf("NICK %s", nick);
	sndf("USER %s 8 * :%s", user, user);
	sndf("MODE %s +i", nick);
	while (!quit) {
		fd_set rfs, wfs;
		int ret;

		if (winchg)
			tresize();
		FD_ZERO(&wfs);
		FD_ZERO(&rfs);
		FD_SET(0, &rfs);
		FD_SET(sfd, &rfs);
		if (outp!=outb)
			FD_SET(sfd, &wfs);
		ret=select(sfd+1, &rfs, &wfs, 0, 0);
		if (ret<0) {
			if (errno==EINTR) continue;
			panic("Select failed.");
		}
		if (FD_ISSET(sfd, &rfs)) {
			if (!srd())
				quit=1;
		}
		if (FD_ISSET(sfd, &wfs)) {
			int wr;

			wr=write(sfd, outb, outp-outb);
			if (wr<0) {
				if (errno==EINTR) continue;
				panic("Write error.");
			}
			if (wr==0) continue;
			outp-=wr;
			memmove(outb, outb+wr, outp-outb);
		}
		if (FD_ISSET(0, &rfs)) {
			tgetch();
			wrefresh(scr.iw);
		}
	}
	close(sfd);
	while (nch--)
		free(chl[nch].buf);
	treset();
	exit(0);
}