Exemplo n.º 1
0
Arquivo: main.c Projeto: sebnow/mush
int main()
{
	char *prompt_argv[2] = {"prompt", "% "};
	cmd_prompt(2, prompt_argv);
	setupSignalHandler();
	run();
	return 0;
}
Exemplo n.º 2
0
/* Put out prompt and wait input from user. */
static void
vty_prompt(vty_t *vty)
{
	struct utsname names;
	const char*hostname;

	if (vty->type == VTY_TERM) {
		hostname = host.name;
		if (!hostname) {
			uname(&names);
			hostname = names.nodename;
		}
		vty_out(vty, cmd_prompt (vty->node), hostname);
	}
}
Exemplo n.º 3
0
static void
send_recv(int i, int sockfd, struct User user)
{
	char send_buf[BUFSIZE];
	char message_str[BUFSIZE - 512];
	char recv_buf[BUFSIZE];
	char room[WORD];
	int nbyte_recvd;
	char stime[WORD];
	time_t rawtime;
	struct tm *timeinfo;
	int sn_bytes;

	if (i != SEND) {
		nbyte_recvd = recv(sockfd, recv_buf, BUFSIZE, 0);
		recv_buf[nbyte_recvd] = '\0';

		sscanf(recv_buf, "%s ", room);

		if (strcmp(room, user.room) == 0)
			printf("%s\n", recv_buf);
		return;
	}
	
	
	fgets(message_str, BUFSIZE, stdin);
	
	if (strcmp(message_str, "/quit\n") == 0) {
		close_session(user, sockfd);
		exit(0);
	}
	
	if (message_str[0] == '/'){
		cmd_prompt(user, message_str, sockfd);
		return;
	}

	time(&rawtime);
	timeinfo = localtime(&rawtime);
	strftime(stime, sizeof(stime), "%H:%M:%S", timeinfo);

	sn_bytes = sprintf(send_buf, "%s room: (%s) (%s): %s",
	    user.room, user.name, stime, message_str);
	send_buf[sn_bytes] = '\0';
	send(sockfd, send_buf, sn_bytes, 0);

}