/* * Note: we don't use any kind of indexes (btrees, etc) here, because * that would add more overhead than it would improve performance. */ #include "hwscan2.h" int is_new_context = 0; char * context_id = NULL; char * context_name = NULL; char * context_comm = NULL; void new_context() { if ( context_id != NULL ) free(context_id); if ( context_name != NULL ) free(context_name); if ( context_comm != NULL ) free(context_comm); context_id = context_name = context_comm = NULL; is_new_context = 1; } int set_context_id(const char *fmt, ...) { va_list ap; int rc; if ( context_id != NULL ) free(context_id); va_start(ap, fmt); rc = vasprintf(&context_id, fmt, ap); va_end(ap); return rc; } int set_context_name(const char *fmt, ...) { va_list ap; int rc; if ( context_name != NULL ) free(context_name); va_start(ap, fmt); rc = vasprintf(&context_name, fmt, ap); va_end(ap); return rc; } int set_context_comm(const char *fmt, ...) { va_list ap; int rc; if ( context_comm != NULL ) free(context_comm); va_start(ap, fmt); rc = vasprintf(&context_comm, fmt, ap); va_end(ap); return rc; } void out_header() { if ( !is_new_context ) return; printf("\n# [%s]%s%s\n", context_id == NULL ? "UNKNOWN" : context_id, context_name == NULL ? "" : " ", context_name == NULL ? "" : context_name); if ( context_comm != NULL ) printf("# %s\n", context_comm); is_new_context = 0; } void out_module(struct modmap_t *module, char *fmt, ...) { if ( context_name == NULL && fmt != NULL ) { va_list ap; va_start(ap, fmt); vasprintf(&context_name, fmt, ap); va_end(ap); } out_header(); if ( module && module->basename ) printf("modprobe %s\n", module->basename); }