92 lines
2.7 KiB
C
92 lines
2.7 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <getopt.h>
|
|
#include <string.h>
|
|
|
|
#include "utils.h"
|
|
#include "args.h"
|
|
|
|
// void global_help() {
|
|
// printf("Usage: bs [[-l] [--list]] [[-n] [--nprobe]] [[-b] [--bsdl]] [[-d] [--device_id]] PROBE_NUM] [<cmd>] [<cmd_options>]\n");
|
|
// }
|
|
|
|
// int parse_args(struct args *a, int argc, char *argv[]) {
|
|
// int opt = 0;
|
|
// int i = 0;
|
|
// unsigned int devid = 0;
|
|
// int command = 0;
|
|
// __uint8_t option_arg[MAX_PATH] = {0};
|
|
|
|
// // Définir les options longues
|
|
// static struct option long_options[] = {
|
|
// {"list", no_argument, 0, 'l'},
|
|
// {"nprobe", required_argument, 0, 'n'},
|
|
// {"bsdl", required_argument, 0, 'b'},
|
|
// {"device_id", required_argument, 0, 'd'},
|
|
// {0, 0, 0, 0}
|
|
// };
|
|
|
|
// // Utilisation de getopt_long pour parser les options
|
|
// while ((opt = getopt_long(argc, argv, "ln:b:d:", long_options, NULL)) != -1) {
|
|
// switch (opt) {
|
|
// case 'h':
|
|
// a->list = 1;
|
|
// break;
|
|
// case 'n':
|
|
// snprintf(option_arg, sizeof(option_arg)-2, "%s", optarg);
|
|
// a->probe = atoi(option_arg);
|
|
// break;
|
|
// case 'b':
|
|
// snprintf(a->bsdl, MAX_PATH-2, "%s", optarg);
|
|
// break;
|
|
// case 'd':
|
|
// i = sscanf(optarg, "0x%x", &devid);
|
|
// if (i == 0) {
|
|
// printf("Device ID must be an hex value like '0xABCD'");
|
|
// return EXIT_FAILURE;
|
|
// }
|
|
// break;
|
|
// default:
|
|
// usage();
|
|
// return EXIT_FAILURE;
|
|
// }
|
|
// }
|
|
|
|
// // Positional arguments
|
|
// if (optind < argc) {
|
|
// /* Positional arguments */
|
|
// while (optind < argc) {
|
|
// for (i=0;i<COMMANDS_NUMBER-1;i++) {
|
|
// if (0 == strcmp(COMMAND_STRINGS[i], argv[optind])) {
|
|
// a->cmds[command] = (enum commands)i+1;
|
|
// }
|
|
// }
|
|
// optind++;
|
|
// }
|
|
// }
|
|
|
|
// // Si aucune option n'est fournie, afficher l'aide
|
|
// if (optind == 1) {
|
|
// usage();
|
|
// }
|
|
|
|
// return EXIT_SUCCESS;
|
|
// }
|
|
|
|
// void parse_command(char *line, int *argc, char **argv) {
|
|
// *argc = 0;
|
|
// while (*line != '\0') {
|
|
// while (*line == ' ' || *line == '\t' || *line == '\n') {
|
|
// *line++ = '\0';
|
|
// }
|
|
// if (*argc >= MAX_ARGS) break;
|
|
// (*argc)++;
|
|
// *argv++ = line;
|
|
// while (*line != '\0' && *line != ' ' && *line != '\t' && *line != '\n') {
|
|
// line++;
|
|
// }
|
|
// }
|
|
// *argv = '\0';
|
|
// }
|