FreeBSD/cddl/contrib/opensolaris/lib/libdtrace/common/dt_pragma.c
/*
 * Process a control line #directive by looking up the directive name in our
 * lookup table and invoking the corresponding function with the token list.
 * According to K&R[A12.9], we silently ignore null directive lines.
 */
Process a control line #directive by looking up the directive name in our
lookup table and invoking the corresponding function with the token list.
According to K&R[A12.9], we silently ignore null directive lines.
Process a control line #directive by looking up the directive name in our lookup table and invoking the corresponding function with the token list . According to K&R [ A12 . 9 ] we silently ignore null directive lines .
void
dt_pragma(dt_node_t *pnp)
{
	const struct dt_pragmadesc *dpd;
	dt_node_t *dnp;
	int kind = DT_PRAGMA_DIR;
	for (dnp = pnp; dnp != NULL; dnp = dnp->dn_list) {
		if (dnp->dn_kind == DT_NODE_INT) {
			dt_pragma_line("line", dnp);
			break;
		}
		if (dnp->dn_kind != DT_NODE_IDENT)
			xyerror(D_PRAGCTL_INVAL, "invalid control directive\n");
		if (kind == DT_PRAGMA_DIR &&
		    strcmp(dnp->dn_string, "pragma") == 0) {
			kind = DT_PRAGMA_SUB;
			continue;
		}
		if (kind == DT_PRAGMA_SUB &&
		    strcmp(dnp->dn_string, "D") == 0) {
			kind = DT_PRAGMA_DCP;
			continue;
		}
		for (dpd = dt_pragmas; dpd->dpd_name != NULL; dpd++) {
			if (dpd->dpd_kind <= kind &&
			    strcmp(dpd->dpd_name, dnp->dn_string) == 0)
				break;
		}
		yylineno--; 
		if (dpd->dpd_name != NULL) {
			dpd->dpd_func(dpd->dpd_name, dnp->dn_list);
			yylineno++;
			break;
		}
		switch (kind) {
		case DT_PRAGMA_DIR:
			xyerror(D_PRAGCTL_INVAL, "invalid control directive: "
			    "#%s\n", dnp->dn_string);
		case DT_PRAGMA_SUB:
			break; 
		case DT_PRAGMA_DCP:
		default:
			xyerror(D_PRAGMA_INVAL, "invalid D pragma: %s\n",
			    dnp->dn_string);
		}
		yylineno++;
		break;
	}
	dt_node_list_free(&pnp);
}
void dt_pragma ( dt_node_t * pnp ) { const struct dt_pragmadesc * dpd ; dt_node_t * dnp ; int kind = DT_PRAGMA_DIR ; for ( dnp = pnp ; dnp != NULL ; dnp = dnp -> dn_list ) { if ( dnp -> dn_kind == DT_NODE_INT ) { dt_pragma_line ( " " , dnp ) ; break ; } if ( dnp -> dn_kind != DT_NODE_IDENT ) xyerror ( D_PRAGCTL_INVAL , " \n " ) ; if ( kind == DT_PRAGMA_DIR && strcmp ( dnp -> dn_string , " " ) == 0 ) { kind = DT_PRAGMA_SUB ; continue ; } if ( kind == DT_PRAGMA_SUB && strcmp ( dnp -> dn_string , " " ) == 0 ) { kind = DT_PRAGMA_DCP ; continue ; } for ( dpd = dt_pragmas ; dpd -> dpd_name != NULL ; dpd ++ ) { if ( dpd -> dpd_kind <= kind && strcmp ( dpd -> dpd_name , dnp -> dn_string ) == 0 ) break ; } yylineno -- ; if ( dpd -> dpd_name != NULL ) { dpd -> dpd_func ( dpd -> dpd_name , dnp -> dn_list ) ; yylineno ++ ; break ; } switch ( kind ) { case DT_PRAGMA_DIR : xyerror ( D_PRAGCTL_INVAL , " " " \n " , dnp -> dn_string ) ; case DT_PRAGMA_SUB : break ; case DT_PRAGMA_DCP : default : xyerror ( D_PRAGMA_INVAL , " \n " , dnp -> dn_string ) ; } yylineno ++ ; break ; } dt_node_list_free ( & pnp ) ; }
Process a control line #directive by looking up the directive name in our
 lookup table and invoking the corresponding function with the token list.
Process a control line #directive by looking up the directive name in our lookup table and invoking the corresponding function with the token list .
/* since we've already seen \n */ /*NOTREACHED*/ /* K&R[A12.8] says to ignore unknown pragmas */