usr.bin/checknr/checknr.c
static void
addmac(const char *mac)
{
	int i, slot;

	if (ncmds >= MAXCMDS) {
		errx(1, "Only %d known commands allowed", MAXCMDS);
	}

	/* Don't try to add it if it's already in the table. */
	if (binsrch(mac, &slot) >= 0) {
#ifdef DEBUG
		printf("binsrch(%s) -> already in table\n", mac);
#endif /* DEBUG */
		return;
	}
#ifdef DEBUG
	printf("binsrch(%s) -> %d\n", mac, slot);
#endif
	for (i = ncmds - 1; i >= slot; i--) {
		strncpy(knowncmds[i + 1], knowncmds[i], 2);
	}
	strncpy(knowncmds[slot], mac, 2);
	ncmds++;
#ifdef DEBUG
	printf("after: %s %s %s %s %s, %d cmds\n", knowncmds[slot-2],
		knowncmds[slot-1], knowncmds[slot], knowncmds[slot+1],
		knowncmds[slot+2], ncmds);
#endif
}
/*
 * Add mac to the list.  We should really have some kind of tree
 * structure here, but the loop below is reasonably fast.
 */
Add mac to the list.  We should really have some kind of tree
structure here, but the loop below is reasonably fast.
Add mac to the list . We should really have some kind of tree structure here but the loop below is reasonably fast .
static void
addmac(const char *mac)
{
	int i, slot;
	if (ncmds >= MAXCMDS) {
		errx(1, "Only %d known commands allowed", MAXCMDS);
	}
	if (binsrch(mac, &slot) >= 0) {
#ifdef DEBUG
		printf("binsrch(%s) -> already in table\n", mac);
#endif 
		return;
	}
#ifdef DEBUG
	printf("binsrch(%s) -> %d\n", mac, slot);
#endif
	for (i = ncmds - 1; i >= slot; i--) {
		strncpy(knowncmds[i + 1], knowncmds[i], 2);
	}
	strncpy(knowncmds[slot], mac, 2);
	ncmds++;
#ifdef DEBUG
	printf("after: %s %s %s %s %s, %d cmds\n", knowncmds[slot-2],
		knowncmds[slot-1], knowncmds[slot], knowncmds[slot+1],
		knowncmds[slot+2], ncmds);
#endif
}
static void addmac ( const char * mac ) { int i , slot ; if ( ncmds >= MAXCMDS ) { errx ( 1 , " " , MAXCMDS ) ; } if ( binsrch ( mac , & slot ) >= 0 ) { #ifdef DEBUG printf ( " \n " , mac ) ; #endif return ; } #ifdef DEBUG printf ( " \n " , mac , slot ) ; #endif for ( i = ncmds - 1 ; i >= slot ; i -- ) { strncpy ( knowncmds [ i + 1 ] , knowncmds [ i ] , 2 ) ; } strncpy ( knowncmds [ slot ] , mac , 2 ) ; ncmds ++ ; #ifdef DEBUG printf ( " \n " , knowncmds [ slot - 2 ] , knowncmds [ slot - 1 ] , knowncmds [ slot ] , knowncmds [ slot + 1 ] , knowncmds [ slot + 2 ] , ncmds ) ; #endif }
Add mac to the list.
Add mac to the list .
/* Don't try to add it if it's already in the table. */ /* DEBUG */