static int pop_three_float_vectors (SLang_Array_Type **a, SLang_Array_Type **b, SLang_Array_Type **c) { *a = *b = *c = NULL; if (-1 == pop_float_vector (c)) return -1; if (-1 == pop_two_float_vectors (a, b)) { SLang_free_array (*c); *c = NULL; return -1; } if (-1 == check_vectors (*a, *c)) { free_arrays (*a, *b, *c, NULL); *a = *b = *c = NULL; return -1; } return 0; }
static int pop_two_float_vectors (SLang_Array_Type **a, SLang_Array_Type **b) { *a = *b = NULL; if (-1 == pop_float_vector (b)) return -1; if (-1 == pop_float_vector (a)) { SLang_free_array (*b); *b = 0; return -1; } if (-1 == check_vectors (*a, *b)) { free_arrays (*a, *b, NULL, NULL); *a = *b = NULL; return -1; } return 0; }
static int pop_four_float_vectors (SLang_Array_Type **a, SLang_Array_Type **b, SLang_Array_Type **c, SLang_Array_Type **d) { *a = *b = *c = *d = NULL; if (-1 == pop_float_vector (d)) return -1; if (-1 == pop_three_float_vectors (a, b, c)) { SLang_free_array (*d); *d = NULL; return -1; } if (-1 == check_vectors (*a, *d)) { free_arrays (*a, *b, *c, *d); *a = *b = *c = *d = NULL; return -1; } return 0; }
static int cr_subpr_alg( FILE *fp ) { ALG *algs; ALG P; VECTORS v; int i, err, errf; char outf[NAME_LEN_LIMIT+1]; int *sizes; errf=NO_ERROR; print_spopen("Creating an algebra in a subproduct."); v.list= (VEC *)NULL; P.func=NULL; sizes=NULL; algs=NULL; /* These lines for free_ to work properly */ if( (err = get_next_line(name, NAME_LEN_LIMIT, fp)) != NO_ERROR) { errf=ERROR; goto WLe_cr_subpr_alg; } err = ps_vectors(name, &v, ALG_SIZE_LIMIT); /* must have a third arg. */ if(err!= NO_ERROR) { errf=ERROR; hlp_cr_subpr_alg(); goto WLe_cr_subpr_alg; } if(v.lvecs>=PROD_LIMIT) { print_derr("Illegal number %d of components (should be at most %d).", v.lvecs, PROD_LIMIT-1 ); errf=ERROR; goto WLe_cr_subpr_alg; } if(v.nvecs == 0) { print_dpres("The universe of this algebra is empty, it cannot be created."); errf=ERROR; goto WLe_cr_subpr_alg; } /* allocate room for algebras */ algs= (ALG *)(calloc(v.lvecs,sizeof(ALG))); if(algs== NULL) { print_derr("Not enough memory to store algebras."); errf=ERROR; hlp_cr_subpr_alg(); goto WLe_cr_subpr_alg; } for(i=0; i<v.lvecs; i++) { (algs[i]).func= (FUNCT *)NULL; } for(i=0; i<v.lvecs; i++) { if( (err = get_next_line(name, NAME_LEN_LIMIT, fp)) != NO_ERROR) { errf=ERROR; goto WLe_cr_subpr_alg; } err= ps_alg(name, &(algs[i])); if(err!= NO_ERROR) { errf=ERROR; print_nerr("%d algebra description lines needed.", v.lvecs); hlp_cr_subpr_alg(); goto WLe_cr_subpr_alg; } } /* algebras read, now check vector entries */ sizes= (int *) (calloc(v.lvecs,sizeof(int))); if(sizes== NULL) { print_derr("Not enough memory to check vector entries."); errf=ERROR; hlp_cr_subpr_alg(); goto WLe_cr_subpr_alg; } for(i=0; i<v.lvecs; i++) { sizes[i]=(algs[i]).size; } err=check_vectors(&v,sizes); if(err!= NO_ERROR) { errf=ERROR; goto WLe_cr_subpr_alg; } if( (err = get_next_line(name, NAME_LEN_LIMIT, fp)) != NO_ERROR) { errf=ERROR; goto WLe_cr_subpr_alg; } err=ps_out(name, outf); if(err != NO_ERROR) { errf=ERROR; print_nerr("%d algebra lines and an output line needed.", v.lvecs); hlp_cr_subpr_alg(); hlp_alg_file(); goto WLe_cr_subpr_alg; } err= sub_prod_alg(algs, &v, &P); if(err!= NO_ERROR) { errf=ERROR; goto WLe_cr_subpr_alg; } err = wr_alg(outf, &P); if(err!= NO_ERROR) { errf=ERROR; goto WLe_cr_subpr_alg; } WLe_cr_subpr_alg: if(sizes!=NULL) free((void *)sizes); if(algs!=NULL) { for(i=0; i<v.lvecs; i++) { free_alg(&(algs[i])); } free((void *)algs); } free_alg(&P); free_vectors(&v); if(errf==NO_ERROR) { print_spclose("End of creating an algebra in a subproduct."); } return(errf); }