view duart28/main.c @ 30:8de3891460db

duart28/eeprom_rd.c: fix analyze_eeprom() return value
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 09 Sep 2023 19:39:15 +0000
parents a7393d00996a
children 530ec3792de8
line wrap: on
line source

/*
 * Main module for fc-duart28-conf utility.
 */

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <usb.h>
#include "../libuwrap/open_close.h"

extern struct usb_device *find_duart28_usbdev();

oper_find()
{
	struct usb_device *dev;

	dev = find_duart28_usbdev();
	if (!dev)
		printf("No DUART28 adapter found\n");
	return 0;
}

oper_check_eeprom()
{
	struct usb_device *dev;
	usb_dev_handle *usbh;

	dev = find_duart28_usbdev();
	if (!dev) {
		fprintf(stderr, "error: no DUART28 adapter found\n");
		exit(1);
	}
	usbh = usbwrap_open_dev(dev, 1);
	read_eeprom(usbh);
	usbwrap_close_dev(usbh);
	analyze_eeprom();
	return 0;
}

oper_program(newconf)
{
	fprintf(stderr, "error: set command not yet implemented\n");
	exit(1);
}

main(argc, argv)
	char **argv;
{
	if (argc < 2)
		return oper_find();
	if (!strcmp(argv[1], "find")) {
		if (argc != 2) {
			fprintf(stderr,
				"error: %s find command takes no arguments\n",
				argv[0]);
			exit(1);
		}
		return oper_find();
	}
	if (!strcmp(argv[1], "check-eeprom")) {
		if (argc != 2) {
			fprintf(stderr,
			"error: %s check-eeprom command takes no arguments\n",
				argv[0]);
			exit(1);
		}
		return oper_check_eeprom();
	}
	if (!strcmp(argv[1], "set")) {
		if (argc != 3) {
			fprintf(stderr,
				"error: %s set command takes 1 argument\n",
				argv[0]);
			exit(1);
		}
		if (!strcmp(argv[2], "C") || !strcmp(argv[2], "S"))
			return oper_program(argv[2][0]);
		if (!strcmp(argv[2], "c") || !strcmp(argv[2], "s"))
			return oper_program(toupper(argv[2][0]));
		fprintf(stderr, "error: %s set argument must be C or S\n",
			argv[0]);
		exit(1);
	}
	fprintf(stderr, "%s error: non-understood command \"%s\"\n", argv[0],
		argv[1]);
	exit(1);
}