#include <stdio.h>

#include "sbusprobe.h"



void printsbusDevices( int n, struct sbusDevice **devs, char *type ) {
    int i, j;

    if (n<0) {
	fprintf(stderr, "System error!\n");
	exit(1);
    } else if (n==0) {
	printf("No SBUS devices of type %s found.\n", type);
    } else {
	for (i=0; i<n; i++) {
	    printf("Card %d:    %d matches found in db\n", i, devs[i]->nhits);
	    for (j=0; j<devs[i]->nhits; j++) {
		printf("       Match %d:  |%s| -> |%s|\n",
		       j, devs[i]->name[j], devs[i]->module[j]);
	    }
	    if (devs[i]->class == SBUS_VIDEO) {
	    	printf("       Resolution %dx%d", devs[i]->fb->width, devs[i]->fb->height);
	    	if (devs[i]->fb->freq)
		    	printf("%d", devs[i]->fb->freq);
		if (devs[i]->fb->monitor != -1)
		    	printf(" Monitor type %d\n", devs[i]->fb->monitor);
		else
			printf("\n");
	    }
	}
    }
}

int main () {

    int i, n;
    struct sbusDevice **devs;
    
    printf("Probing for ETHERNET devices....\n");
    n = sbusProbeDevice(SBUS_ETHERNET, &devs);
    printsbusDevices(n, devs, "Ethernet");
    for (i=0; i<n; i++)
	sbusFreeDevice(devs[i]);
    
    printf("\nProbing for SCSI devices....\n");
    n = sbusProbeDevice(SBUS_SCSI, &devs);
    printsbusDevices(n, devs, "SCSI");
    for (i=0; i<n; i++)
	sbusFreeDevice(devs[i]);

    printf("\nProbing for VIDEO devices....\n");
    n = sbusProbeDevice(SBUS_VIDEO, &devs);
    printsbusDevices(n, devs, "Video");
    for (i=0; i<n; i++)
	sbusFreeDevice(devs[i]);

    return 0;
}
