static BOOL parents(t_get *word, t_get **words, t_cmd *link, char **bad_sintax) { BOOL no_word; t_get *organize; if (lvl_parents(words, bad_sintax) == FALSE) return (FALSE); if ((organize = word->next)) word->next->prev = NULL; rm_words(word); if ((word = (*words)->prev) == NULL) return (check_sintax(bad_sintax, 1, ERROR_NEAR_PARENTS)); if (MATCH(word->word, "(")) return (check_sintax(bad_sintax, 1, ERROR_NEAR_PARENTS)); word->next = NULL; word = (*words)->next; rm_words(*words); if ((link->parents = orga(organize, bad_sintax, &no_word, TRUE)) == NULL) return (check_sintax(bad_sintax, no_word, ERROR_NEAR_PARENTS)); while (word) if (!add_redir(word, &word, bad_sintax, link)) return (FALSE); return (TRUE); }
int main(int argc, char** argv){ float* h=NULL; float* x=NULL; int hsize; int xsize; t_entrada entradah; t_entrada entradax; init(&entradah); init(&entradax); int ileido,fleido; int error=0; int i; ileido=0; fleido=0; int pulso=0; int archivo=0; int errors=0; int opcion; const char* const short_options = "hVr:p:"; const struct option long_options[] = { { "help", 0, NULL, 'h' }, { "version", 0, NULL, 'V' }, { "response", 1, NULL, 'r' }, { "pulse", 1, NULL, 'p' }, { NULL, 0, NULL, 0 } }; int lista_archivos=0; int res; int opt=0; if(argc==1) fprintf(stderr,"Error: Falta especificar una opción."); else { do { opcion = getopt_long (argc, argv, short_options, long_options, NULL); switch (opcion) { case 'h': /* -h o --help */ imprimir_ayuda (stdout, 0); opt=1; break; case 'r': /* -r o --response */ if((!pulso)&&(!archivo)){ lista_archivos=1; res=leer_archivo(optarg,&entradah); if(res==3) fprintf(stderr,"ERROR: No se pudo abrir el archivo %s.\n",optarg); if(res==1) fprintf(stderr,"ERROR: No hay memoria suficiente para continuar.\n"); opt=1; archivo=1; } else{ errors=1; }; break; case 'p': /* -p o --pulse */ if((!pulso)&&(!archivo)){ res=generar_pulso(optarg,&h,&hsize); if(res==1) fprintf(stderr,"ERROR: No hay memoria suficiente para continuar.\n"); if(res==2) fprintf(stderr,"ERROR: la sintaxis del pulso ingresado es incorrecta.\n"); opt=1; ileido=1; fleido=1; pulso=1; } else{ errors=1; } break; case 'V': /* -V o --version */ imprimir_version (stdout, 0); opt=1; break; case '?': /*error*/ fprintf(stderr,"ERROR: La opción no existe.\n"); imprimir_ayuda (stderr, 1); opt=1; case -1: break; case ':': fprintf(stderr,"ERROR: Faltan argumentos.\n"); imprimir_ayuda (stderr, 1); break; default: break; } } while((opcion != -1)); if((!opt)&&(argc>1)) fprintf(stderr,"ERROR: Falta especificar una opción."); if(lista_archivos) { for (i = optind; i < argc; ++i) { res=leer_archivo(argv[i],&entradah); if(res==3) fprintf(stderr,"ERROR: No se pudo abrir el archivo %s.\n",optarg); if(res==1) fprintf(stderr,"ERROR: No hay memoria suficiente para continuar.\n"); } } } if(errors){ fprintf(stderr,"ERROR: las opciones ingresadas son incorrectas.\n"); destroy(&entradah); destroy(&entradax); return 1; }; entradah.data[entradah.index]='\0'; res=check_sintax(&entradah); if(res==0) error=armar_vector(entradah.data,&h,&hsize); else if(!pulso)fprintf(stderr,"ERROR: la sintaxis de h es incorrecta.\n"); if(!pulso){ if(error==1) fprintf(stderr,"ERROR: no hay memoria suficiente para continuar.\n "); if(error==2) fprintf(stderr,"ERROR: hay caracteres inválidos en el vector h.\n "); } destroy(&entradah); if(h==NULL){ /* no hay h , no se puede hacer nada*/ return 1; } if(!pulso) if((error)||(res!=0)) return 1; /* leo x desde stdin */; ileido=0; fleido=0; error=leerEntrada(stdin,&entradax); entradax.data[entradax.index]='\0'; res=check_sintax(&entradax); if(res==0) error=armar_vector(entradax.data,&x,&xsize); else fprintf(stderr,"ERROR: la sintaxis de x es incorrecta.\n"); destroy(&entradax); if(error==1) fprintf(stderr,"ERROR: no hay memoria suficiente para continuar.\n "); if(error==2) fprintf(stderr,"ERROR: hay caracteres inválidos en el vector x.\n "); if(x==NULL){ /*no tengo x, no puedo ahcer nada*/ if(h!=NULL){ /*libero h*/ free(h); return 1; } } if((error)||(res!=0)) return 1; /* tengo h y x*/ if((!errors)&&(!error)){ /*no hay error de sintaxis: -r y -p*/ i=0; /* si x tiene menos elementos que h, repito x*/ if(xsize<hsize){ while(xsize<hsize){ push_back(&x,&xsize,x[i]); i++; }; } /* reservo espacio para y, xsize + hsize -1 */ y=(float*)malloc((xsize+hsize-1)*sizeof(float)); if(y!=NULL){ /* LLAMAR A CONVOLUCIÓN*/ conv(x,xsize,h,hsize); }; /*imprimo y*/ printf("%s","[ "); for(i=0;i<xsize+hsize-1;i++){ printf("%.2f ",y[i]); } printf("%s","]\n"); /* LIBERO Y*/ if(y!=NULL) free(y); } /* printf("\n\n X es:"); i=0; while(i<xsize){ printf(" %f \n",x[i]); i++; } i=0; printf("\n\n h es:"); while(i<hsize){ printf(" %f \n",h[i]); i++; } */ /*LIBERO H y X*/ if(h!=NULL) free(h); if(x!=NULL) free(x); return 0; }