henesyinit from p9fce6d0435 years agoHistory
63 lines · 883 B · C
RawDownload
#include "all.h" #define	DOTDOT	(&fmt+1) static Cmd *head;static Cmd *tail;static Cmd *freecmd; int	cmdpending; voidputcmd(char *fmt, ...){	Cmd *cp; 	if(cp = freecmd)	/* assign = */		freecmd = cp->next;	else		cp = malloc(sizeof(Cmd));	cp->next = 0; 	cp->wptr = doprint(cp->buf, cp->buf+CMDSIZE, fmt, DOTDOT);	if(head)		tail->next = cp;	else		head = cp;	tail = cp;	if(debug)		print("queued \"%s\"\n", cp->buf);	sendcmd();} voidsendcmd(void){	Cmd *cp; 	if(cmdpending)		return;	if(!(cp = head))	/* assign = */		return;	head = cp->next;	if(head == 0)		tail = 0;	write(fonefd, cp->buf, cp->wptr-cp->buf);	if(debug)		print("sent \"%s\"\n", cp->buf);	cmdpending = 1;	cp->next = freecmd;	freecmd = cp->next;} voidflushcmd(void){	if(!cmdpending || !head)		return;	cmdpending = 0;	tail->next = freecmd;	freecmd = head;	head = 0;	tail = 0;}