int main(int argc, char **argv) { char **tab; int nb_line; int nb_col; if (argc != 3 || !test_arg(argv[1], argv[2])) { ft_printf("%rBad usage: puissance4 <nb_line> <nb_column>\n"); return (1); } nb_line = ft_atoi(argv[1]); nb_col = ft_atoi(argv[2]); if (nb_line < 6 || nb_col < 7) { ft_printf("%rBad usage, col < 7 or line < 6\n"); return (1); } if ((tab = get_tab(nb_line, nb_col)) == NULL) { ft_printf("%rAllocation Fail\n"); return (1); } print_tab(tab, nb_col, nb_line); launch_party(tab, nb_col, nb_line); free_tab(tab); return (0); }
int main(int ac, char **av) { t_prog_base base; if (!test_arg(ac, av)) { my_putstr("First argument is not a number.\n", 1); return (0); } init_base(&base, ac, av); print_screen(&base); (base.difficulty != 200) ? aff_game(&base) : ia_vs_ia(&base); free_base(&base); return (0); }
/* Remove any unknown event fields */ static struct filter_arg *collapse_tree(struct filter_arg *arg) { enum filter_vals ret; ret = test_arg(arg, arg); switch (ret) { case FILTER_VAL_NORM: return arg; case FILTER_VAL_TRUE: case FILTER_VAL_FALSE: free_arg(arg); arg = allocate_arg(); arg->type = FILTER_ARG_BOOLEAN; arg->boolean.value = ret == FILTER_VAL_TRUE; } return arg; }
int update_env(t_env *e, char **av) { int i; int res; i = 1; while (av[i] != NULL) { res = test_arg(e, av + i); if (res == -1) _exit(EXIT_FAILURE); i += res; } if (!test_env(e)) { usage(); _exit(EXIT_FAILURE); } return (1); }
int call_moveto (int argc, char **argv) { char pwd_flag = FALSE; char check_move = TRUE; int x; if (argc == 1) { Usage (argv[0]); return; } move_flag = FALSE; for (x = 1; x < argc; x++) { if (test_arg (argv[x],"-pwd",1)) pwd_flag = TRUE; else if (test_arg (argv[x],"-nopwd",3)) pwd_flag = FALSE; else if (test_arg (argv[x],"-check",1)) check_move = TRUE; else if (test_arg (argv[x],"-nocheck",3)) check_move = FALSE; else if (test_arg (argv[x], "-sequence",3)) { if (x + 1 == argc) { ps_printf (OPT, "We need a sequence name.\n"); return; } else { shuffle_up (argc--, argv, x); set_sequence (argv[x]); } } else if (move (argv[x]) == OK) { if (move_flag == TRUE) { ps_print (RPS,"Too many parameters !\n"); Usage (argv[0]); return; } move_flag = TRUE; } else { move_flag = FALSE; if (*argv[x] != '-') ps_printf (OPT,"Unknown entity '%s'\n",argv[x]); else Usage (argv[0]); return; } } if (check_move) if (test_move_dn() != TRUE) { move_flag = FALSE; return; } if (move_flag == TRUE) consolidate_move (); if (pwd_flag) { dn_print (RPS, fixed_pos, EDBOUT); ps_print (RPS, "\n"); } }
int call_showentry (int argc, char **argv) { Attr_Sequence eptr; char *vect[2]; int x; extern char name_flag; extern char all_flag; extern Attr_Sequence as_flag; extern char flag_show; char full_edb_flag; char *temp_file_name; extern int mod_template(); vect[0] = "showentry"; move_flag = FALSE; fred_flag = FALSE; fred_expand = FALSE; fred_list = FALSE; fred_long = 2; fred_phone = FALSE; fred_photo = FALSE; fred_sequence = TRUE; fred_subdisplay = FALSE; name_flag = FALSE; full_edb_flag = FALSE; for (x=1; x<argc; x++) { if (test_arg (argv[x], "-move",2)) move_flag = TRUE; else if (test_arg (argv[x], "-nomove",3)) move_flag = FALSE; else if (test_arg (argv[x], "-fred",4)) fred_flag = TRUE; else if (test_arg (argv[x], "-expand",4)) fred_expand = TRUE; else if (test_arg (argv[x], "-fredlist",8)) fred_list = TRUE; else if (test_arg (argv[x], "-full",4)) fred_long = TRUE; else if (test_arg (argv[x], "-summary",7)) fred_long = FALSE; else if (test_arg (argv[x], "-phone",5)) fred_phone = TRUE; else if (test_arg (argv[x], "-fredphoto",9)) fred_photo = dad_flag; else if (test_arg (argv[x], "-nofredseq",9)) fred_sequence = FALSE; else if (test_arg (argv[x], "-subdisplay",10)) fred_subdisplay = TRUE; else if (test_arg (argv[x], "-fedb",4)) { if (x + 1 == argc) { ps_printf (opt, "We need a filename for the full edb entry.\n"); return; } else { shuffle_up (argc, argv, x); argc--; if (*(temp_file_name = argv[x]) != '/') { ps_printf (opt, "We need a real file spec for the file name.\n"); return; } } full_edb_flag = TRUE; } else continue; shuffle_up (argc--,argv,x--); } if ((argc = read_cache (argc, argv)) < 0) return; if (argc != 1) { ps_printf (OPT,"Unknown option %s\n",argv[1]); Usage (argv[0]); return; } if (current_entry == NULLENTRY) { ps_print (OPT,"Specify an entry \n"); /* this CAN happen - when the entry is not cache, but -noread */ return; } if (full_edb_flag) { mod_template(temp_file_name,0); return; } if (fred_flag) { if (fred_long == 2) if ((fred_subdisplay && fred_expand) || (!fred_subdisplay && !fred_expand)) fred_long = TRUE; else fred_long = fred_expand; if (fred_expand) fred_long = fred_subdisplay = TRUE; if (fred_list && frompipe && rps -> ps_byteno == 0 && opt -> ps_byteno == 0) { DN new_dn = dn_cpy (current_dn); showfredDNs (new_dn, fred_long); dn_free (new_dn); } showfred (current_dn, fred_long, fred_subdisplay); } else { if (name_flag) { dn_print (RPS,dn,EDBOUT); ps_print (RPS,"\n"); } if (all_flag) eptr = current_entry->e_attributes; else eptr = as_flag; if (flag_show) for (; eptr != NULLATTR; eptr = eptr->attr_link) showattribute (eptr->attr_type); } consolidate_move(); }
int call_modify (int argc, char **argv) { struct ds_modifyentry_arg mod_arg; struct DSError error; struct entrymod *emnew, *ems_append(), *modify_avs(); Attr_Sequence as, #ifdef TURBO_DISK fget_attributes (), #else get_attributes (), #endif temp, trail = NULLATTR; AV_Sequence avst = NULLAV; extern AttributeType at_objectclass; extern int parse_status; Entry entry_ptr; FILE *fd; char draft_flag = FALSE; char noedit_flag = FALSE; int x; DN moddn; char *home; RDN new_rdn; struct list_element *start = 0 ; struct list_element *last ; struct list_element *l_temp ; /* char add = FALSE ; char rem = FALSE ; */ if ((argc = service_control (OPT, argc, argv, &mod_arg.mea_common)) == -1) return; mod_arg.mea_changes = NULLMOD; new_draft = FALSE; if (home = getenv ("DISHDRAFT")) strcpy (fname, home); else if (dad_flag) { strcpy (fname, "/tmp/dishXXXXXX"); unlink (mktemp (fname)); } else if (home = getenv ("HOME")) sprintf (fname, "%s/.dishdraft", home); else strcpy (fname, "./.dishdraft"); for (x=1; x<argc; x++) { if (test_arg (argv[x], "-draft",1)) { draft_flag = 1; shuffle_up (argc--,argv,x); if (x == argc) { ps_printf (OPT, "Draft file name missing\n"); Usage (argv[0]); return; } strcpy (fname, argv[x]); shuffle_up (argc--,argv,x--); } else if (test_arg (argv[x], "-newdraft",2)) { new_draft = TRUE; shuffle_up (argc--,argv,x--); } else if (test_arg (argv[x], "-noedit",3)) { noedit_flag = TRUE; shuffle_up (argc--,argv,x--); } else if (move (argv[x]) == OK) shuffle_up (argc--,argv,x--); else if (test_arg(argv[x], "-remove", 3)) { shuffle_up (argc--, argv, x); if (x == argc) { ps_printf(OPT, "Attribute to remove missing\n") ; Usage(argv[0]) ; return ; } l_temp = (struct list_element *) malloc (sizeof(struct list_element)) ; l_temp->mod = (char *) malloc ((unsigned)(strlen(argv[x]) + 1)); strcpy (l_temp->mod, argv[x]) ; l_temp->add = 0 ; l_temp->next = 0 ; if (start == 0) { start = last = l_temp ; } else { last->next = l_temp ; last = l_temp ; } shuffle_up (argc--,argv,x--); } else if (test_arg(argv[x], "-add", 2)) { shuffle_up (argc--, argv, x); if (x == argc) { ps_printf(OPT, "Attribute to insert missing\n") ; Usage(argv[0]) ; return ; } l_temp = (struct list_element *) malloc (sizeof(struct list_element)) ; l_temp->mod = (char *) malloc ((unsigned)(strlen(argv[x]) + 1)); strcpy (l_temp->mod, argv[x]) ; l_temp->add = 1 ; l_temp->next = 0 ; if (start == 0) { start = last = l_temp ; } else { last->next = l_temp ; last = l_temp ; } shuffle_up (argc--,argv,x--); } } if (dad_flag && (draft_flag || noedit_flag)) { ps_printf (OPT, "operation not allowed when using directory assistance server!\n"); return; } /* read attributes we want to modify */ if ((argc = read_cache_aux (argc, argv, FALSE, &mod_arg.mea_common)) <0 ) return; if (argc != 1) { ps_printf (OPT,"Unknown option %s\n",argv[1]); Usage (argv[0]); return; } if (start != 0) { if (build_modify(start, &mod_arg) == NOTOK) { return ; } while (ds_modifyentry (&mod_arg, &error) != DS_OK) { if (dish_error (OPT, &error) == 0) { return ; } mod_arg.mea_object = error.ERR_REFERRAL.DSE_ref_candidates->cr_name ; } ps_print (RPS, "Modified "); dn_print (RPS, dn, EDBOUT); ps_print (RPS, "\n"); delete_cache (dn); /* re-cache when next read */ return ; } if (!draft_flag) { if (mod_template (fname,noedit_flag) != OK) return; noedit_flag = FALSE; } else { new_draft = TRUE; /* Ugh ! */ mod_template ("/dev/null",TRUE); } if (! noedit_flag) if (editentry (1, argv) != OK) { make_old (fname,draft_flag); return; } /* now parse the files */ if ((fd = fopen (fname, "r")) == (FILE *) NULL) { ps_printf (OPT, "Can't open draft entry %s\n", fname); return; } entry_ptr = get_default_entry (NULLENTRY); #ifdef TURBO_DISK entry_ptr->e_attributes = fget_attributes (fd); #else entry_ptr->e_attributes = get_attributes (fd); #endif fclose (fd); if (parse_status != 0) return; mod_arg.mea_object = dn; for (moddn = dn ; moddn->dn_parent != NULLDN; moddn=moddn->dn_parent) ; entry_ptr->e_name = rdn_cpy (moddn->dn_rdn); /* add rdn as attribute */ for (new_rdn = entry_ptr->e_name; new_rdn != NULLRDN; new_rdn = new_rdn->rdn_next) { avst = avs_comp_new (AttrV_cpy (&new_rdn->rdn_av)); temp = as_comp_new (AttrT_cpy (new_rdn->rdn_at), avst, NULLACL_INFO); entry_ptr->e_attributes = as_merge (entry_ptr->e_attributes, temp); } for (as = entry_ptr->e_attributes; as != NULLATTR; as = as->attr_link) { emnew = NULLMOD; trail = as->attr_link; as->attr_link = NULLATTR; temp = current_entry->e_attributes; for (; temp != NULLATTR; temp = temp->attr_link) if (AttrT_cmp (as->attr_type, temp->attr_type) == 0) { /* found it - does it need changing ? */ if (avs_cmp (as->attr_value, temp->attr_value) != 0) emnew = modify_avs (as->attr_value, temp->attr_value,as->attr_type); break; } if (temp == NULLATTR) { emnew = em_alloc (); emnew->em_type = EM_ADDATTRIBUTE; emnew->em_what = as_cpy(as); emnew->em_next = NULLMOD; } if (emnew != NULLMOD) mod_arg.mea_changes = ems_append (mod_arg.mea_changes,emnew); as->attr_link = trail; } /* remove attribute missing in new entry */ for (as = current_entry->e_attributes; as != NULLATTR; as = as->attr_link) { emnew = NULLMOD; temp = entry_ptr->e_attributes; for (; temp != NULLATTR; temp = temp->attr_link) if (AttrT_cmp (as->attr_type, temp->attr_type) == 0) break; if (temp == NULLATTR) { emnew = em_alloc (); emnew->em_type = EM_REMOVEATTRIBUTE; emnew->em_what = as_comp_new(as->attr_type,NULLAV,NULLACL_INFO); emnew->em_next = NULLMOD; } if (emnew != NULLMOD) mod_arg.mea_changes = ems_append (mod_arg.mea_changes,emnew); } if (mod_arg.mea_changes == NULLMOD) { ps_print (RPS, "The draft entry and the entry for "); dn_print (RPS, dn, EDBOUT); ps_print (RPS, "\nare exactly the same - no change made!!!\n"); entry_free (entry_ptr); make_old (fname,draft_flag); return; } if (rebind () != OK) { entry_free (entry_ptr); return; } /* * If this operation is time-stamped, it may have expired while the user * was editing the entry. Re-calculate the time-stamp. Modify is the only * dish command where this needs to be done. */ if ((mod_arg.mea_common.ca_security != (struct security_parms *) 0) && (mod_arg.mea_common.ca_security->sp_time != NULLCP)) { char *new_version(); free(mod_arg.mea_common.ca_security->sp_time); mod_arg.mea_common.ca_security->sp_time = new_version(); } /* If security parameters are present, take this to mean that strong * authentication is required. This disallows 'parms + no signature' * (pointless) and 'signature + no parms' (security risk). */ if (mod_arg.mea_common.ca_security != (struct security_parms *) 0) { extern struct SecurityServices *dsap_security; mod_arg.mea_common.ca_sig = (dsap_security->serv_sign)((caddr_t)&mod_arg, _ZModifyEntryArgumentDataDAS, &_ZDAS_mod); } while (ds_modifyentry (&mod_arg, &error) != DS_OK) { if (dish_error (OPT, &error) == 0) { entry_free (entry_ptr); return; } mod_arg.mea_object = error.ERR_REFERRAL.DSE_ref_candidates->cr_name; } ps_print (RPS, "Modified "); dn_print (RPS, dn, EDBOUT); ps_print (RPS, "\n"); delete_cache (dn); /* re-cache when next read */ entry_free (entry_ptr); ems_part_free (mod_arg.mea_changes); make_old (fname,draft_flag); }
enum filter_vals test_arg(struct filter_arg *parent, struct filter_arg *arg) { enum filter_vals lval, rval; switch (arg->type) { /* bad case */ case FILTER_ARG_BOOLEAN: return FILTER_VAL_FALSE + arg->boolean.value; /* good cases: */ case FILTER_ARG_STR: case FILTER_ARG_VALUE: case FILTER_ARG_FIELD: return FILTER_VAL_NORM; case FILTER_ARG_EXP: lval = test_arg(arg, arg->exp.left); if (lval != FILTER_VAL_NORM) return lval; rval = test_arg(arg, arg->exp.right); if (rval != FILTER_VAL_NORM) return rval; return FILTER_VAL_NORM; case FILTER_ARG_NUM: lval = test_arg(arg, arg->num.left); if (lval != FILTER_VAL_NORM) return lval; rval = test_arg(arg, arg->num.right); if (rval != FILTER_VAL_NORM) return rval; return FILTER_VAL_NORM; case FILTER_ARG_OP: if (arg->op.type != FILTER_OP_NOT) { lval = test_arg(arg, arg->op.left); switch (lval) { case FILTER_VAL_NORM: break; case FILTER_VAL_TRUE: if (arg->op.type == FILTER_OP_OR) return FILTER_VAL_TRUE; rval = test_arg(arg, arg->op.right); if (rval != FILTER_VAL_NORM) return rval; reparent_op_arg(parent, arg, arg->op.right); return FILTER_VAL_NORM; case FILTER_VAL_FALSE: if (arg->op.type == FILTER_OP_AND) return FILTER_VAL_FALSE; rval = test_arg(arg, arg->op.right); if (rval != FILTER_VAL_NORM) return rval; reparent_op_arg(parent, arg, arg->op.right); return FILTER_VAL_NORM; } } rval = test_arg(arg, arg->op.right); switch (rval) { case FILTER_VAL_NORM: break; case FILTER_VAL_TRUE: if (arg->op.type == FILTER_OP_OR) return FILTER_VAL_TRUE; if (arg->op.type == FILTER_OP_NOT) return FILTER_VAL_FALSE; reparent_op_arg(parent, arg, arg->op.left); return FILTER_VAL_NORM; case FILTER_VAL_FALSE: if (arg->op.type == FILTER_OP_AND) return FILTER_VAL_FALSE; if (arg->op.type == FILTER_OP_NOT) return FILTER_VAL_TRUE; reparent_op_arg(parent, arg, arg->op.left); return FILTER_VAL_NORM; } return FILTER_VAL_NORM; default: die("bad arg in filter tree"); } return FILTER_VAL_NORM; }
void selftest(void) { // for handling "errout" if (setjmp(jbuf)) return; #if SELFTEST test_low_level(); test_multiply(); test_scan(); test_power(); test_factor_number(); test_test(); test_tensor(); test_bake(); test(__FILE__, s, sizeof (s) / sizeof (char *)); // "s" is in selftest.h test_abs(); test_adj(); test_arg(); test_besselj(); test_bessely(); test_ceiling(); test_choose(); test_circexp(); test_clock(); test_cofactor(); test_condense(); test_contract(); test_defint(); test_denominator(); test_derivative(); test_dirac(); test_erf(); test_erfc(); test_expand(); test_expcos(); test_expsin(); test_factorpoly(); test_float(); test_floor(); test_gamma(); test_gcd(); test_imag(); test_inner(); test_lcm(); test_log(); test_mag(); test_mod(); test_nroots(); test_numerator(); test_outer(); test_polar(); test_quotient(); test_rationalize(); test_real(); test_rect(); test_sgn(); test_taylor(); test_transpose(); test_zero(); test_hermite(); test_laguerre(); test_legendre(); test_binomial(); test_divisors(); test_coeff(); test_sin(); test_cos(); test_tan(); test_sinh(); test_cosh(); test_tanh(); test_arcsin(); test_arcsinh(); test_arccos(); test_arccosh(); test_arctan(); test_arctanh(); test_index(); test_isprime(); test_integral(); test_simplify(); test_roots(); test_eigen(); #endif mini_test(); logout("OK, all tests passed.\n"); }