#include #include #include #include #include "opcns.h" #define DIRLIB "." #define TRUE 1 #define FALSE 0 /****************** Opciones ******************/ static void escribeAyuda (int mas) { static char *ayuda[] ={ " -a dirArb directorio con arboles", " -d depuracion, nivel", " 1 una sola vez, rutinas", " -h ayuda, opciones y significado", " -o nombre alternativo", "#" }; int la; for (la=0;ayuda[la][0]!='#';la++) if (mas || (ayuda[la][0] != '.')) printf ("%s\n", ayuda[la]) ; } extern char *optarg; void misopc (int argc, char **argv) { int c, err; a_opcion = TRUE; a_valor = (char *) strdup (DIRLIB); d_opcion = FALSE; h_opcion = FALSE; H_opcion = FALSE; err = FALSE; while ((c = getopt(argc, argv, "a:d:hHo:")) != EOF){ switch (c){ case 'a': a_opcion = TRUE; a_valor = optarg; break; case 'd': d_opcion = TRUE; d_valor = optarg; d_valori = atoi (d_valor) ; break; case 'h': h_opcion = TRUE; break; case 'H': H_opcion = TRUE; break; case 'o': o_opcion = TRUE; if (o_num == 0) o_valor = (char **) malloc (10*sizeof(char *)); if (o_num == 10){ printf ("id3..opcns error: demasiadas o_opciones\n"); exit (1); } o_valor[o_num] = optarg; o_num ++; break; case '?': err = TRUE; break; } } if (err) { fprintf(stderr, "uso: %s [-a dirArb -d niv -o opc]\n", argv[0]); exit (1); } if (H_opcion){ escribeAyuda (TRUE); exit (0); } else if (h_opcion){ escribeAyuda (FALSE); exit (0); } if (d_valori >= 1) { int i; printf ("opcion a %d\n", a_opcion); if (a_opcion) printf ("el valor de la opcion a es: %s\n", a_valor); printf ("opcion d %d\n", d_opcion); if (d_opcion) printf ("el valor de la opcion d es: %s\n", d_valor); printf ("opcion h %d\n", h_opcion); printf ("opcion H %d\n", H_opcion); printf ("opcion o %d", o_opcion); for(i=0; i