예제 #1
0
int main(int argc, char *argv[])
{
	int r = 1, i;
	int next_option;
	enum fp_finger finger = RIGHT_INDEX;

	struct fp_dscv_dev *ddev;
	struct fp_dscv_dev **discovered_devs;
	struct fp_dev *dev;
	struct fp_print_data *data;
	
	const char * const short_options = "hf:";
	const struct option long_options[] = {
		{ "help", 0, NULL, 'h'},
		{ "enroll-finger", 1, NULL, 'f'},
		{ NULL, 0, NULL, 0}
	};
	
	do {
		next_option = getopt_long(argc, argv, short_options, long_options,
			NULL);
		switch (next_option) {
		case 'h':
			/* Printing usage */
			printf("Usage: %s options\n", argv[0]);
			printf("	-h	--help			Display this usage information.\n"
			   "	-f	--enroll-finger index	Enroll finger with index.\n\n");
			printf("	Valid indexes are:\n");
			for (i = LEFT_THUMB; i <= RIGHT_LITTLE; i++) {
				printf("	%d - %s\n", i, finger_names[i]);
			}
			exit(1);
			   
			break;
		case 'f':
			sscanf(optarg, "%d", &finger);
			if (finger < LEFT_THUMB || finger > RIGHT_LITTLE) {
				printf("%s: Invalid finger index.\n", argv[0]);
				printf("%s: Valid indexes are:\n", argv[0]);
				for (i = LEFT_THUMB; i <= RIGHT_LITTLE; i++) {
					printf("%s: %d - %s\n", argv[0], i, finger_names[i]);
				}
				exit(1);
			}
			break;
		case -1:	/* Done with options. */
			break;
		default:	/* Unexpected option */
			exit(1);
		}
	} while (next_option != -1);

	printf("This program will enroll your finger, "
		"unconditionally overwriting any selected print that was enrolled "
		"previously. If you want to continue, press enter, otherwise hit "
		"Ctrl+C\n");
	getchar();

	r = fp_init();
	if (r < 0) {
		fprintf(stderr, "Failed to initialize libfprint\n");
		exit(1);
	}

	discovered_devs = fp_discover_devs();
	if (!discovered_devs) {
		fprintf(stderr, "Could not discover devices\n");
		goto out;
	}

	ddev = discover_device(discovered_devs);
	if (!ddev) {
		fprintf(stderr, "No devices detected.\n");
		goto out;
	}

	dev = fp_dev_open(ddev);
	fp_dscv_devs_free(discovered_devs);
	if (!dev) {
		fprintf(stderr, "Could not open device.\n");
		goto out;
	}

	printf("Opened device. It's now time to enroll your finger.\n\n");
	data = enroll(dev, finger);
	if (!data)
		goto out_close;

	r = fp_print_data_save(data, finger);
	if (r < 0)
		fprintf(stderr, "Data save failed, code %d\n", r);

	fp_print_data_free(data);
out_close:
	fp_dev_close(dev);
out:
	fp_exit();
	return r;
}
예제 #2
0
int
main (int argc, char **argv)
{
  int r = 1;
  struct fp_dscv_dev *ddev;
  struct fp_dscv_dev **discovered_devs;
  struct fp_dev *dev;
  struct fp_print_data *data;

  int finger;

  finger = atoi(argv[3]);



  printf ("This program will enroll your right index finger, "
	  "unconditionally overwriting any right-index print that was enrolled "
	  "previously. If you want to continue, press enter, otherwise hit "
	  "Ctrl+C\n");
  getchar ();

  r = fp_init ();
  if (r < 0)
    {
      fprintf (stderr, "Failed to initialize libfprint\n");
      exit (1);
    }
  fp_set_debug (3);

  discovered_devs = fp_discover_devs ();
  if (!discovered_devs)
    {
      fprintf (stderr, "Could not discover devices\n");
      goto out;
    }

  ddev = discover_device (discovered_devs);
  if (!ddev)
    {
      fprintf (stderr, "No devices detected.\n");
      goto out;
    }

  dev = fp_dev_open (ddev);
  fp_dscv_devs_free (discovered_devs);
  if (!dev)
    {
      fprintf (stderr, "Could not open device.\n");
      goto out;
    }

  printf ("Opened device. It's now time to enroll your finger.\n\n");
  data = enroll (dev);
  if (!data)
    goto out_close;

  r = fp_print_data_save (data, finger, argv[1], argv[2]);
  if (r < 0)
    fprintf (stderr, "Data save failed, code %d\n", r);

  fp_print_data_free (data);
out_close:
  fp_dev_close (dev);
out:
  fp_exit ();
  return r;
}