/* The values returned by this function are meaningful only after readline * has been used once. */ static void get_screen_size (void) { int rows, cols; #if USE_SLANG_READLINE rows = SLtt_Screen_Rows; cols = SLtt_Screen_Cols; #else rl_get_screen_size (&rows, &cols); #endif (void) SLang_push_int (rows); (void) SLang_push_int (cols); }
static void check_intrin_int_qualifier (char *name, int *def) { int q; if (-1 == SLang_get_int_qualifier (name, &q, *def)) return; SLang_push_int (q); }
static void rline_call_update_hook (SLrline_Type *rli, SLFUTURE_CONST char *prompt, SLFUTURE_CONST char *buf, unsigned int len, unsigned int point, VOID_STAR cd) { Rline_CB_Type *cb; (void) rli; (void) len; cb = (Rline_CB_Type *)cd; if (-1 == SLang_start_arg_list ()) return; if ((-1 == SLang_push_mmt (cb->mmt)) || (-1 == SLang_push_string (prompt)) || (-1 == SLang_push_string (buf)) || (-1 == SLang_push_int ((int) point)) || ((cb->cd != NULL) && (-1 == SLang_push_anytype (cb->cd)))) { (void) SLang_end_arg_list (); return; } (void) SLexecute_function (cb->update_hook); }
static int get_int_sockopt (Socket_Type *s, int level, int optname) { int val; socklen_t len; len = sizeof (int); if (-1 == do_getsockopt (s->fd, level, optname, (void *)&val, &len)) return -1; return SLang_push_int (val); }
static void getpriority_intrin (int *which, int *who) { int ret; errno = 0; ret = getpriority (*which, *who); if ((ret == -1) && (errno != 0)) { _pSLerrno_errno = errno; (void) SLang_push_null (); return; } (void) SLang_push_int (ret); }
static int test_type_sget (SLtype type, SLFUTURE_CONST char *name) { Test_Type *t; int status; (void) type; if (-1 == pop_test_type (&t)) return -1; status = -1; if (0 == strcmp (name, "field1")) status = SLang_push_int (t->field1); else if (0 == strcmp (name, "field2")) status = SLang_push_int (t->field2); else if (0 == strcmp (name, "any")) status = SLang_push_anytype (t->any); else SLang_verror (SL_INVALID_PARM, "Test_Type.%s is invalid", name); free_test_type (t); return status; }
static int call_simple_update_cb (SLang_Name_Type *f, Rline_CB_Type *cb, int *opt) { if (f == NULL) return 0; if (-1 == SLang_start_arg_list ()) return -1; if ((-1 == SLang_push_mmt (cb->mmt)) || ((opt != NULL) && (-1 == SLang_push_int (*opt))) || ((cb->cd != NULL) && (-1 == SLang_push_anytype (cb->cd)))) { (void) SLang_end_arg_list (); return -1; } return SLexecute_function (f); }
void sl_ioctl (void) { char *argp = NULL; int fd, retval; unsigned int length, request; SLFile_FD_Type *f; SLang_BString_Type *bstr; if (SLang_Num_Function_Args == 3) { if (SLang_pop_bstring (&bstr) == -1) goto usage_error; if (SLang_pop_uint ((unsigned int *) &request) == -1) goto usage_error; if (SLfile_pop_fd (&f) == -1) goto usage_error; argp = SLbstring_get_pointer (bstr, &length); } else if (SLang_Num_Function_Args == 2) { if (SLang_pop_uint ((unsigned int *) &request) == -1) goto usage_error; if (SLfile_pop_fd (&f) == -1) goto usage_error; } else goto usage_error; if (SLfile_get_fd (f, &fd) == -1) return; if ((retval = ioctl (fd, request, argp)) == -1) { SLang_set_error (SL_OS_Error); (void) SLerrno_set_errno (errno); return; } (void) SLang_push_int (retval); if (argp != NULL) (void) SLang_push_bstring (bstr); return; usage_error : SLang_set_error (SL_Usage_Error); return; }
static void nint_intrin (void) { double x; SLang_Array_Type *at, *bt; int (*at_to_int_fun)(SLang_Array_Type *, SLang_Array_Type *); if (SLang_peek_at_stack () != SLANG_ARRAY_TYPE) { if (-1 == SLang_pop_double (&x)) return; (void) SLang_push_int (do_nint (x)); return; } switch (SLang_peek_at_stack1 ()) { case -1: return; case SLANG_INT_TYPE: return; case SLANG_FLOAT_TYPE: if (-1 == SLang_pop_array_of_type (&at, SLANG_FLOAT_TYPE)) return; at_to_int_fun = float_to_nint; break; case SLANG_DOUBLE_TYPE: default: if (-1 == SLang_pop_array_of_type (&at, SLANG_DOUBLE_TYPE)) return; at_to_int_fun = double_to_nint; break; } if (NULL == (bt = SLang_create_array1 (SLANG_INT_TYPE, 0, NULL, at->dims, at->num_dims, 1))) { SLang_free_array (at); return; } if (0 == (*at_to_int_fun) (at, bt)) (void) SLang_push_array (bt, 0); SLang_free_array (bt); SLang_free_array (at); }
static int apply_line_modifier (Model_t *m, Model_Info_Type *info, DB_line_t *line, double *emis) /*{{{*/ { Plasma_State_Type lm_state; lm_state.temperature = m->temperature; lm_state.ndensity = m->density; SLang_start_arg_list (); SLang_push_array (info->line_emis_modifier_params, 0); SLang_push_int (line->indx); if (-1 == SLang_push_cstruct ((VOID_STAR)&lm_state, Plasma_State_Layout)) return -1; SLang_push_double (*emis); if (info->line_emis_modifier_args != NULL) isis_push_args (info->line_emis_modifier_args); if (info->line_emis_modifier_qualifiers == NULL) { SLang_end_arg_list (); if (-1 == SLexecute_function (info->line_emis_modifier)) return -1; } else { if ((-1 == SLang_push_function (info->line_emis_modifier)) || (-1 == SLang_push_struct (info->line_emis_modifier_qualifiers))) return -1; SLang_end_arg_list (); if (-1 == SLang_execute_function ("_isis->do_eval_with_qualifiers")) return -1; } if (-1 == SLang_pop_double (emis)) return -1; return 0; }
int _pSLbstring_foreach (SLtype type, SLang_Foreach_Context_Type *c) { unsigned char ch; SLwchar_Type wch; unsigned char *s, *s1, *smax; (void) type; s = c->s; smax = c->smax; if (s == smax) return 0; if (c->using_chars == 0) { ch = (unsigned char) *s++; c->s = s; if (-1 == SLclass_push_char_obj (SLANG_UCHAR_TYPE, ch)) return -1; return 1; } s1 = SLutf8_decode (s, smax, &wch, NULL); if (s1 == NULL) { int iwch = (int) *s; c->s = s + 1; /* Invalid encoded char-- return it as a negative int */ if (-1 == SLang_push_int (-iwch)) return -1; return 1; } c->s = s1; if (-1 == SLang_push_wchar (wch)) return -1; return 1; }
static int rl_complete (SLrline_Type *rli) { char *line; unsigned int i, n, nbytes; char **strings, *str0, ch0; int start_point, delta; SLang_Array_Type *at; SLang_Name_Type *completion_callback; SLang_Name_Type *list_completions_callback; if (NULL == (completion_callback = rli->completion_callback)) { completion_callback = Default_Completion_Callback; if (completion_callback == NULL) return SLrline_ins (rli, "\t", 1); } if (NULL == (list_completions_callback = rli->list_completions_callback)) list_completions_callback = Default_List_Completions_Callback; if (NULL == (line = SLrline_get_line (rli))) return -1; if ((-1 == SLang_start_arg_list ()) || (-1 == SLang_push_string (line)) || (-1 == SLang_push_int (rli->point)) || (-1 == SLang_end_arg_list ()) || (-1 == SLexecute_function (completion_callback))) { SLfree (line); return -1; } SLfree (line); if (-1 == SLang_pop_int (&start_point)) return -1; if (start_point < 0) start_point = 0; if (-1 == SLang_pop_array_of_type (&at, SLANG_STRING_TYPE)) return -1; strings = (char **) at->data; n = at->num_elements; if (n == 0) { SLang_free_array (at); return 0; } if ((n != 1) && (list_completions_callback != NULL)) { if ((-1 == SLang_start_arg_list ()) || (-1 == SLang_push_array (at, 0)) || (-1 == SLang_end_arg_list ()) || (-1 == SLexecute_function (list_completions_callback))) { SLang_free_array (at); return -1; } (void) SLrline_redraw (rli); } str0 = strings[0]; nbytes = 0; while (0 != (ch0 = str0[nbytes])) { for (i = 1; i < n; i++) { char ch1 = strings[i][nbytes]; if (ch0 != ch1) break; } if (i != n) break; nbytes++; } delta = start_point - rli->point; if (delta < 0) { (void) SLrline_move (rli, delta); delta = -delta; } (void) SLrline_del (rli, (unsigned int) delta); (void) SLrline_ins (rli, str0, nbytes); /* How should the completion be ended? * "foo/ --> "foo/ * "foo/bar --> "foo/bar" * "foo --> "foo" * foo --> fooSPACE * foo/bar --> fooSPACE */ if ((n == 1) && nbytes && (str0[nbytes-1] != '/') && (str0[nbytes-1] != '\\')) { char qch = ' '; if (start_point > 0) { ch0 = rli->buf[start_point-1]; if ((ch0 == '"') || (ch0 == '\'')) qch = ch0; } if (qch != 0) (void) SLrline_ins (rli, &qch, 1); } SLang_free_array (at); return 0; }
/* Returns a malloced value */ static char *get_input_line (SLang_Load_Type *x) { char *line; int parse_level; int free_prompt = 0; char *prompt; parse_level = x->parse_level; if (Prompt_Hook != NULL) { if ((-1 == SLang_start_arg_list ()) || (-1 == SLang_push_int (parse_level)) || (-1 == SLang_end_arg_list ()) || (-1 == SLexecute_function (Prompt_Hook)) || (-1 == SLang_pop_slstring (&prompt))) { SLang_verror (SL_RunTime_Error, "Disabling prompt hook"); SLang_free_function (Prompt_Hook); Prompt_Hook = NULL; return NULL; } free_prompt = 1; } else if (parse_level == 0) prompt = (char *) "slsh> "; else prompt = (char *) " "; if (parse_level == 0) { if (-1 == SLang_run_hooks ("slsh_interactive_before_hook", 0)) { if (free_prompt) SLang_free_slstring (prompt); return NULL; } } line = read_input_line (Default_Readline_Info, prompt, 0); if (free_prompt) SLang_free_slstring (prompt); if ((line == NULL) && (parse_level == 0) && (SLang_get_error() == 0)) { Slsh_Quit = 1; return NULL; } if (line == NULL) { return NULL; } /* This hook is used mainly for logging input */ (void) SLang_run_hooks ("slsh_interactive_after_hook", 1, line); (void) save_input_line (Default_Readline_Info, line); return line; }