static int ret_mask(sigset_t *mask, int arg_number) { // TODO; NODE *tmp, *array, *elm, *value; int i; int sig; array = (NODE *) get_array_argument(arg_number, FALSE); if ( array != NULL ) { #if 0 for (i = 0; i < array->array_size; i++) { for (elm = array->var_array[i]; elm != NULL; elm = elm->ahnext) { name = elm->hname; force_string(name); sig = str2sig(name->stptr); if (sig) { value = elm->hvalue; force_string(value); if (value->stptr[0] != '0' && value->stptr[0] != '\0') { sigaddset(mask, sig); } } } } #endif } else { tmp = (NODE *) get_scalar_argument(arg_number, FALSE); } return 0; }
static int ana_flags(int arg_number) { NODE *tmp, *array, *elm, *value; int i; int flag; int flags = 0; array = (NODE *) get_array_argument(arg_number, FALSE); if ( array != NULL ) { for (i = 0; i < array->array_size; i++) { for (elm = array->var_array[i]; elm != NULL; elm = elm->ahnext) { flag = str2flag(elm->hname); if (flag) { value = elm->hvalue; force_string(value); if (value->stptr[0] != '0' && value->stptr[0] != '\0') { flags |= flag; } } } } } else { tmp = (NODE *) get_scalar_argument(arg_number, FALSE); if (tmp->stptr[0] == '\0') { flags |= SA_RESTART; /* システムコールが中止しない */ } else { //TODO; } } return 0; }
exprt goto_convertt::get_array_argument(const exprt &src) { if(src.id()==ID_typecast) { assert(src.operands().size()==1); return get_array_argument(src.op0()); } if(src.id()!=ID_address_of) { err_location(src); throw "expected array-pointer as argument"; } assert(src.operands().size()==1); if(src.op0().id()!=ID_index) { err_location(src); throw "expected array-element as argument"; } assert(src.op0().operands().size()==2); if(ns.follow(src.op0().op0().type()).id()!=ID_array) { err_location(src); throw "expected array as argument"; } return src.op0().op0(); }
static awk_bool_t api_set_argument(awk_ext_id_t id, size_t count, awk_array_t new_array) { #ifdef DYNAMIC NODE *arg; NODE *array = (NODE *) new_array; (void) id; if (array == NULL || array->type != Node_var_array) return false; if ( (arg = get_argument(count)) == NULL || arg->type != Node_var_new) return false; arg = get_array_argument(count, false); if (arg == NULL) return false; array->vname = arg->vname; *arg = *array; freenode(array); return true; #else return false; #endif }
static NODE * do_writea(int nargs) { NODE *file, *array; int ret; int fd; uint32_t major = MAJOR; uint32_t minor = MINOR; if (do_lint && get_curfunc_arg_count() > 2) lintwarn("writea: called with too many arguments"); /* directory is first arg, array to dump is second */ file = get_scalar_argument(0, FALSE); array = get_array_argument(1, FALSE); /* open the file, if error, set ERRNO and return */ (void) force_string(file); fd = creat(file->stptr, 0600); if (fd < 0) { goto done1; } if (write(fd, MAGIC, strlen(MAGIC)) != strlen(MAGIC)) goto done1; major = htonl(major); if (write(fd, & major, sizeof(major)) != sizeof(major)) goto done1; minor = htonl(minor); if (write(fd, & minor, sizeof(minor)) != sizeof(minor)) goto done1; ret = write_array(fd, array); if (ret != 0) goto done1; ret = 0; goto done0; done1: ret = -1; update_ERRNO(); unlink(file->stptr); done0: close(fd); /* Set the return value */ return make_number((AWKNUM) ret); }
static int ana_mask(sigset_t *mask, int arg_number) { NODE *tmp, *array, *elm, *name, *value; int i; int sig; sigemptyset(mask); array = (NODE *) get_array_argument(arg_number, FALSE); if ( array != NULL ) { for (i = 0; i < array->array_size; i++) { for (elm = array->var_array[i]; elm != NULL; elm = elm->ahnext) { sig = str2sig(elm->hname); if (sig) { value = elm->hvalue; force_string(value); if (value->stptr[0] != '0' && value->stptr[0] != '\0') { sigaddset(mask, sig); } } } } } else { tmp = (NODE *) get_scalar_argument(arg_number, FALSE); if (strcmp(tmp->stptr, "@all") == 0) { // toupper TODO @FILL sigfillset(mask); } else if (strcmp(tmp->stptr, "@empty") == 0) { // TODO sigemptyset(mask); } else { } } return 0; }
static awk_bool_t api_get_argument(awk_ext_id_t id, size_t count, awk_valtype_t wanted, awk_value_t *result) { #ifdef DYNAMIC NODE *arg; if (result == NULL) return false; (void) id; /* set up default result */ memset(result, 0, sizeof(*result)); result->val_type = AWK_UNDEFINED; /* * Song and dance here. get_array_argument() and get_scalar_argument() * will force a change in type of a parameter that is Node_var_new. * * Start by looking at the unadulterated argument as it was passed. */ arg = get_argument(count); if (arg == NULL) return false; /* if type is undefined */ if (arg->type == Node_var_new) { if (wanted == AWK_UNDEFINED) return true; else if (wanted == AWK_ARRAY) { goto array; } else { goto scalar; } } /* at this point, we have real type */ if (arg->type == Node_var_array || arg->type == Node_array_ref) { if (wanted != AWK_ARRAY && wanted != AWK_UNDEFINED) return false; goto array; } else goto scalar; array: /* get the array here */ arg = get_array_argument(count, false); if (arg == NULL) return false; return node_to_awk_value(arg, result, wanted); scalar: /* at this point we have a real type that is not an array */ arg = get_scalar_argument(count, false); if (arg == NULL) return false; return node_to_awk_value(arg, result, wanted); #else return false; #endif }
static NODE * do_select(int nags) { NODE *tmp, *array, *elm, *value; int nfds; fd_set rfds, wfds, efds; struct timeval timeout; struct timeval *timeout_ptr; int retval; struct redirect *rp; double integer, point; int i, j; int fp; if (do_lint && get_curfunc_arg_count() > 4) lintwarn("select: called with too many arguments"); /*** Analyse File-descriptors ***/ nfds = -1; FD_ZERO(&rfds); FD_ZERO(&wfds); FD_ZERO(&efds); for (i = 0; i < 3; i++ ) { array = (NODE *) get_array_argument(i, FALSE); if ( array == NULL ) { continue; } for (j = 0; j < array->array_size; j++) { for (elm = array->var_array[j]; elm != NULL; elm = elm->ahnext) { value = elm->hvalue; force_string(value); rp = getredirect(value->stptr, value->stlen); if (rp == NULL) { if (do_lint) { lintwarn("select: `%.*s' is not an open file, pipe or co-process", (int) value->stlen, value->stptr); } } fp = fileno(rp->fp); switch (i) { case 0: FD_SET(fp, &rfds); break; case 1: FD_SET(fp, &wfds); break; case 2: FD_SET(fp, &efds); break; } if (fp + 1 > nfds ) { nfds = fp + 1; } } } } /*** Analyse Timeout ***/ /* timeout specified as milli-seconds */ tmp = (NODE *) get_actual_argument(3, FALSE, FALSE); point = modf(force_number(tmp), &integer); if (integer < 0) { timeout_ptr = NULL; } else { timeout.tv_sec = (time_t) (integer / 1000); timeout.tv_usec = (suseconds_t) (point * 1000); timeout_ptr = &timeout; } retval = select(nfds, &rfds, &wfds, &efds, timeout_ptr); if (retval == -1) { perror("select()"); } else if (retval != 0) { /* TODO */ } return make_number((AWKNUM) retval); }
static NODE * do_reada(int nargs) { NODE *file, *array; int ret; int fd; uint32_t major; uint32_t minor; char magic_buf[30]; if (do_lint && get_curfunc_arg_count() > 2) lintwarn("reada: called with too many arguments"); /* directory is first arg, array to dump is second */ file = get_scalar_argument(0, FALSE); array = get_array_argument(1, FALSE); (void) force_string(file); fd = open(file->stptr, O_RDONLY); if (fd < 0) { goto done1; } memset(magic_buf, '\0', sizeof(magic_buf)); if (read(fd, magic_buf, strlen(MAGIC)) != strlen(MAGIC)) { goto done1; } if (strcmp(magic_buf, MAGIC) != 0) { goto done1; } if (read(fd, & major, sizeof(major)) != sizeof(major)) { goto done1; } major = ntohl(major); if (major != MAJOR) { goto done1; } if (read(fd, & minor, sizeof(minor)) != sizeof(minor)) { goto done1; } minor = ntohl(minor); if (minor != MINOR) { goto done1; } assoc_clear(array); ret = read_array(fd, array); if (ret == 0) goto done0; done1: ret = -1; update_ERRNO(); done0: close(fd); /* Set the return value */ return make_number((AWKNUM) ret); }