FreeBSD/contrib/ntp/ntpq/ntpq-subs.c
/* 
 * config - send a configuration command to a remote host
 */
send a configuration command to a remote host
send a configuration command to a remote host
static void 
config (
	struct parse *pcmd,
	FILE *fp
	)
{
	const char *cfgcmd;
	u_short rstatus;
	size_t rsize;
	const char *rdata;
	char *resp;
	int res;
	int col;
	int i;
	cfgcmd = pcmd->argval[0].string;
	if (debug > 2)
		fprintf(stderr, 
			"In Config\n"
			"Keyword = %s\n"
			"Command = %s\n", pcmd->keyword, cfgcmd);
	res = doquery(CTL_OP_CONFIGURE, 0, 1,
		      strlen(cfgcmd), cfgcmd,
		      &rstatus, &rsize, &rdata);
	if (res != 0)
		return;
	if (rsize > 0 && '\n' == rdata[rsize - 1])
		rsize--;
	resp = emalloc(rsize + 1);
	memcpy(resp, rdata, rsize);
	resp[rsize] = '\0';
	col = -1;
	if (1 == sscanf(resp, "column %d syntax error", &col)
	    && col >= 0 && (size_t)col <= strlen(cfgcmd) + 1) {
		if (interactive) {
			printf("______");	
			printf("________");	
		} else
			printf("%s\n", cfgcmd);
		for (i = 1; i < col; i++)
			putchar('_');
		printf("^\n");
	}
	printf("%s\n", resp);
	free(resp);
}
static void config ( struct parse * pcmd , FILE * fp ) { const char * cfgcmd ; u_short rstatus ; size_t rsize ; const char * rdata ; char * resp ; int res ; int col ; int i ; cfgcmd = pcmd -> argval [ 0 ] . string ; if ( debug > 2 ) fprintf ( stderr , " \n " " \n " " \n " , pcmd -> keyword , cfgcmd ) ; res = doquery ( CTL_OP_CONFIGURE , 0 , 1 , strlen ( cfgcmd ) , cfgcmd , & rstatus , & rsize , & rdata ) ; if ( res != 0 ) return ; if ( rsize > 0 && ' \n ' == rdata [ rsize - 1 ] ) rsize -- ; resp = emalloc ( rsize + 1 ) ; memcpy ( resp , rdata , rsize ) ; resp [ rsize ] = ' \0 ' ; col = -1 ; if ( 1 == sscanf ( resp , " " , & col ) && col >= 0 && ( size_t ) col <= strlen ( cfgcmd ) + 1 ) { if ( interactive ) { printf ( " " ) ; printf ( " " ) ; } else printf ( " \n " , cfgcmd ) ; for ( i = 1 ; i < col ; i ++ ) putchar ( ' ' ) ; printf ( " \n " ) ; } printf ( " \n " , resp ) ; free ( resp ) ; }
config - send a configuration command to a remote host
config - send a configuration command to a remote host
/* "ntpq> " */ /* ":config " */