static NODE * kill_killpg(int (*func)(int, int)) { NODE *tmp; pid_t pid_prg; int sig; tmp = (NODE *) get_scalar_argument(0, FALSE); pid_prg = (pid_t) force_number(tmp); tmp = (NODE *) get_scalar_argument(1, FALSE); sig = get_signo(tmp); return make_number((AWKNUM) func(pid_prg, sig)); }
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; }
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 NODE * do_waitpid(int nargs) { NODE *pidnode; int ret = -1; double pidval; pid_t pid; int options = 0; if (do_lint && get_curfunc_arg_count() > 1) lintwarn("waitpid: called with too many arguments"); pidnode = get_scalar_argument(0, FALSE); if (pidnode != NULL) { pidval = force_number(pidnode); pid = (int) pidval; options = WNOHANG|WUNTRACED; ret = waitpid(pid, NULL, options); if (ret < 0) update_ERRNO(); } else if (do_lint) lintwarn("wait: called with no arguments"); /* Set the return value */ return make_number((AWKNUM) ret); }
NODE * do_BitmapLength(int nargs) { NODE *tmp; void *font; const unsigned char *string; tmp = (NODE *) get_scalar_argument(0, FALSE); force_string(tmp); if ((font = str2font(tmp->stptr)) == NULL) { // TODO } tmp = (NODE *) get_scalar_argument(1, FALSE); force_string(tmp); string = (const unsigned char *) tmp->stptr; //TODO cast return make_number((AWKNUM) glutBitmapLength(font, string)); }
NODE * do_StrokeString(int nargs) { NODE *tmp; void *font; const unsigned char *string; tmp = (NODE *) get_scalar_argument(0, FALSE); force_string(tmp); if ((font = str2font(tmp->stptr)) == NULL) { // TODO } tmp = (NODE *) get_scalar_argument(1, FALSE); force_string(tmp); string = (const unsigned char *) tmp->stptr; glutStrokeString(font, string); return make_number((AWKNUM) 0); }
NODE * do_BitmapWidth(int nargs) { NODE *tmp; void *font; int character; tmp = (NODE *) get_scalar_argument(0, FALSE); force_string(tmp); if ((font = str2font(tmp->stptr)) == NULL) { // TODO } tmp = (NODE *) get_scalar_argument(1, FALSE); force_string(tmp); if (tmp->stlen != 1) { // TODO } character = (int) tmp->stptr[0]; return make_number((AWKNUM) glutBitmapWidth(font, character)); }
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 NODE * do_alarm(int nargs) { NODE *tmp; unsigned int second; if (do_lint && get_curfunc_arg_count() > 1) lintwarn("alarm: called with too many arguments"); tmp = (NODE *) get_scalar_argument(0, FALSE); second = (unsigned int) force_number(tmp); return make_number((AWKNUM) alarm(second)); }
static NODE * do_raise(int nargs) { NODE *tmp; int sig; if (do_lint && get_curfunc_arg_count() > 1) lintwarn("raise: called with too many arguments"); tmp = (NODE *) get_scalar_argument(0, FALSE); sig = get_signo(tmp); return make_number((AWKNUM) raise(sig)); }
NODE * do_BitmapHeight(int nargs) { NODE *tmp; void *font; tmp = (NODE *) get_scalar_argument(0, FALSE); force_string(tmp); if ((font = str2font(tmp->stptr)) == NULL) { // TODO } return make_number((AWKNUM) glutBitmapHeight(font)); }
static NODE * do_sigprocmask(int nargs) { NODE *tmp; int how; sigset_t mask; sigset_t old; int ret; if (do_lint && get_curfunc_arg_count() > 1) lintwarn("sigsuspend: called with too many arguments"); tmp = (NODE *) get_scalar_argument(0, FALSE); force_string(tmp); how = str2how(tmp->stptr); ana_mask(&mask, 1); ret = sigprocmask(how, &mask, &old); ret_mask(&mask, 2); 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 NODE * do_signal(int nargs) { NODE *tmp; const char *str; int sig; NODE *fnc_ptr; SigTable *sig_tbl; struct sigaction sig_act; if (do_lint && get_curfunc_arg_count() > 4) lintwarn("signal: called with too many arguments"); memset(&sig_act, 0, sizeof(struct sigaction)); /* signal number */ tmp = (NODE *) get_scalar_argument(0, FALSE); sig = get_signo(tmp); /* signal handler */ tmp = (NODE *) get_scalar_argument(1, FALSE); force_string(tmp); str = tmp->stptr; sig_tbl = sig2ptr(sig); if (str[0] == '@') { str++; /* advance '@' */ if (strncmp(str, "SIG", 3) == 0) { str += 3; } if (strncmp(str, "_", 1) == 0) { str += 1; } if (strcmp(str, "DFL") == 0) { sig_act.sa_handler = SIG_DFL; } else if (strcmp(str, "IGN") == 0) { sig_act.sa_handler = SIG_IGN; } else { //TODO sig_act.sa_handler = SIG_IGN; fatal } sig_tbl->user_handler = NULL; } else { fnc_ptr = lookup(str); sig_tbl->user_handler = fnc_ptr; sig_act.sa_handler = handler; } if (fnc_ptr == NULL || fnc_ptr->type != Node_func) fatal(_("Callback function `%s' is not defined"), tmp->stptr); /* mask */ if (get_curfunc_arg_count() >= 3) ana_mask(&sig_act.sa_mask, 2); else sigfillset(&sig_act.sa_mask); /* flags */ if (get_curfunc_arg_count() >= 4) sig_act.sa_flags = ana_flags(3); else sig_act.sa_flags |= SA_RESTART; /* システムコールが中止しない */ return make_number((AWKNUM) sigaction(sig, &sig_act, NULL)); }
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_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); }