/*! @decl string dgettext(string domain, string msg) *! *! Return a translated version of @[msg] within the context *! of the specified @[domain] and current locale. If there is *! no translation available, @[msg] is returned. *! *! @note *! Obsoleted by @[gettext()] in Pike 7.3. *! *! @seealso *! @[bindtextdomain], @[textdomain], @[gettext], @[setlocale], @[localeconv] */ void f_dgettext(INT32 args) { const char *domain, *msg; get_all_args(NULL, args, "%c%c", &domain, &msg); push_text(dgettext(domain, msg)); stack_pop_n_elems_keep_top(args); }
/*! @decl string dcgettext(string domain, string msg, int category) *! *! Return a translated version of @[msg] within the context of the *! specified @[domain] and current locale for the specified *! @[category]. Calling dcgettext with category @[Locale.Gettext.LC_MESSAGES] *! gives the same result as dgettext. *! *! If there is no translation available, @[msg] is returned. *! *! @note *! Obsoleted by @[gettext()] in Pike 7.3. *! *! @seealso *! @[bindtextdomain], @[textdomain], @[gettext], @[setlocale], @[localeconv] */ void f_dcgettext(INT32 args) { const char *domain, *msg; int category; get_all_args(NULL, args, "%c%c%d", &domain, &msg, &category); push_text(dcgettext(domain, msg, category)); stack_pop_n_elems_keep_top(args); }
static void port_accept(INT32 args) { PIKE_SOCKADDR addr; struct port *this=THIS; int fd, err; ACCEPT_SIZE_T len=0; int one = 1; if(this->box.fd < 0) Pike_error("port->accept(): Port not open.\n"); /* FIXME: Race. */ THIS->box.revents = 0; THREADS_ALLOW(); len=sizeof(addr); do { fd=fd_accept(this->box.fd, (struct sockaddr *)&addr, &len); err = errno; } while (fd < 0 && err == EINTR); THREADS_DISALLOW(); INVALIDATE_CURRENT_TIME(); if(fd < 0) { this->my_errno=errno = err; pop_n_elems(args); push_int(0); return; } /* We don't really care if setsockopt fails, since it's just a hint. */ while ((fd_setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&one, sizeof(int)) < 0) && (errno == EINTR)) one = 1; my_set_close_on_exec(fd,1); push_new_fd_object(port_fd_factory_fun_num, fd, FILE_READ | FILE_WRITE, SOCKET_CAPABILITIES); if (this->box.backend) { struct object *o = Pike_sp[-1].u.object; struct my_file *f = (struct my_file *) (o->storage + o->prog->inherits[SUBTYPEOF(Pike_sp[-1])].storage_offset); change_backend_for_box(&f->box, this->box.backend); } stack_pop_n_elems_keep_top(args); }
/*! @decl int match(string str) *! *! Returns 1 if @[str] matches the regexp bound to the regexp object. *! Zero otherwise. *! *! @decl array(string) match(array(string) strs) *! *! Returns an array containing strings in @[strs] that match the *! regexp bound to the regexp object. *! *! @bugs *! The current implementation doesn't support searching *! in strings containing the NUL character or any *! wide character. *! *! @seealso *! @[split] */ static void regexp_match(INT32 args) { int i; struct regexp *regexp = THIS->regexp; if(args < 1) SIMPLE_TOO_FEW_ARGS_ERROR("Regexp.SimpleRegexp->match", 1); if(Pike_sp[-args].type == T_STRING) { if(Pike_sp[-args].u.string->size_shift) SIMPLE_BAD_ARG_ERROR("Regexp.SimpleRegexp->match", 1, "Expected string (8bit)"); i = pike_regexec(regexp, (char *)STR0(Pike_sp[-args].u.string)); pop_n_elems(args); push_int(i); return; } else if(Pike_sp[-args].type == T_ARRAY) { struct array *arr; int i, n; arr = Pike_sp[-args].u.array; for(i = n = 0; i < arr->size; i++) { struct svalue *sv = ITEM(arr) + i; if(sv->type != T_STRING || sv->u.string->size_shift) SIMPLE_BAD_ARG_ERROR("Regexp.SimpleRegexp->match", 1, "Expected string (8bit)"); if(pike_regexec(regexp, (char *)STR0(sv->u.string))) { ref_push_string(sv->u.string); n++; } } f_aggregate(n); stack_pop_n_elems_keep_top(args); return; } else SIMPLE_BAD_ARG_ERROR("Regexp.SimpleRegexp->match", 1, "string|array(string)"); }
/*! @decl string gettext(string msg) *! @decl string gettext(string msg, string domain) *! @decl string gettext(string msg, string domain, int category) *! *! @param msg *! Message to be translated. *! *! @param domain *! Domain from within the message should be translated. *! Defaults to the current domain. *! *! @param category *! Category from which the translation should be taken. *! Defaults to @[Locale.Gettext.LC_MESSAGES]. *! *! Return a translated version of @[msg] within the context *! of the specified @[domain] and current locale. If there is no *! translation available, @[msg] is returned. *! *! @seealso *! @[bindtextdomain], @[textdomain], @[setlocale], @[localeconv] */ void f_gettext(INT32 args) { const char *domain = NULL, *msg; int cat = 0; get_all_args(NULL, args, "%c.%C%D", &msg, &domain, &cat); if (domain) { if (args > 2 && SUBTYPEOF(Pike_sp[2-args]) == NUMBER_NUMBER) push_text(dcgettext(domain, msg, cat)); else push_text(dgettext(domain, msg)); } else push_text(gettext(msg)); stack_pop_n_elems_keep_top(args); }
/*! @decl mapping localeconv() *! *! The localeconv() function returns a mapping with settings for *! the current locale. This mapping contains all values *! associated with the locale categories @[LC_NUMERIC] and *! @[LC_MONETARY]. *! *! @mapping *! @member string "decimal_point" *! The decimal-point character used to format *! non-monetary quantities. *! *! @member string "thousands_sep" *! The character used to separate groups of digits to *! the left of the decimal-point character in *! formatted non-monetary quantities. *! *! @member string "int_curr_symbol" *! The international currency symbol applicable to *! the current locale, left-justified within a *! four-character space-padded field. The character *! sequences should match with those specified in ISO *! 4217 Codes for the Representation of Currency and *! Funds. *! *! @member string "currency_symbol" *! The local currency symbol applicable to the *! current locale. *! *! @member string "mon_decimal_point" *! The decimal point used to format monetary quantities. *! *! @member string "mon_thousands_sep" *! The separator for groups of digits to the left of *! the decimal point in formatted monetary quantities. *! *! @member string "positive_sign" *! The string used to indicate a non-negative-valued *! formatted monetary quantity. *! *! @member string "negative_sign" *! The string used to indicate a negative-valued *! formatted monetary quantity. *! *! @member int "int_frac_digits" *! The number of fractional digits (those to the *! right of the decimal point) to be displayed in an *! internationally formatted monetary quantity. *! *! @member int "frac_digits" *! The number of fractional digits (those to the *! right of the decimal point) to be displayed in a *! formatted monetary quantity. *! *! @member int(0..1) "p_cs_precedes" *! Set to 1 or 0 if the currency_symbol respectively *! precedes or succeeds the value for a non-negative *! formatted monetary quantity. *! *! @member int(0..1) "p_sep_by_space" *! Set to 1 or 0 if the currency_symbol respectively *! is or is not separated by a space from the value *! for a non-negative formatted monetary quantity. *! *! @member int(0..1) "n_cs_precedes" *! Set to 1 or 0 if the currency_symbol respectively *! precedes or succeeds the value for a negative *! formatted monetary quantity. *! *! @member int(0..1) "n_sep_by_space" *! Set to 1 or 0 if the currency_symbol respectively *! is or is not separated by a space from the value *! for a negative formatted monetary quantity. *! *! @member int(0..4) "p_sign_posn" *! Set to a value indicating the positioning of the *! positive_sign for a non-negative formatted *! monetary quantity. The value of p_sign_posn is *! interpreted according to the following: *! *! @int *! @value 0 *! Parentheses surround the quantity and currency_symbol. *! @value 1 *! The sign string precedes the quantity and currency_symbol. *! @value 2 *! The sign string succeeds the quantity and currency_symbol. *! @value 3 *! The sign string immediately precedes the currency_symbol. *! @value 4 *! The sign string immediately succeeds the currency_symbol. *! @endint *! *! @member int "n_sign_posn" *! Set to a value indicating the positioning of the *! negative_sign for a negative formatted monetary *! quantity. The value of n_sign_posn is interpreted *! according to the rules described under p_sign_posn. *! @endmapping *! *! @seealso *! @[bindtextdomain], @[textdomain], @[gettext], @[dgettext], @[dcgettext], @[setlocale] */ void f_localeconv(INT32 args) { struct lconv *locale; /* Information about the current locale */ struct svalue *save_sp = Pike_sp; locale = localeconv(); #define MAPSTR(key) do { \ push_text(TOSTR(key)); \ push_text(locale->key); \ } while(0) #define MAPINT(key) do { \ push_text(TOSTR(key)); \ push_int(locale->key); \ } while(0) MAPSTR(decimal_point); MAPSTR(thousands_sep); MAPSTR(int_curr_symbol); MAPSTR(currency_symbol); MAPSTR(mon_decimal_point); MAPSTR(mon_thousands_sep); MAPSTR(positive_sign); MAPSTR(negative_sign); /* * MAPCHAR(grouping); * MAPCHAR(mon_grouping); */ MAPINT(int_frac_digits); MAPINT(frac_digits); MAPINT(p_cs_precedes); MAPINT(p_sep_by_space); MAPINT(n_cs_precedes); MAPINT(n_sep_by_space); MAPINT(p_sign_posn); MAPINT(n_sign_posn); f_aggregate_mapping(Pike_sp - save_sp); stack_pop_n_elems_keep_top(args); }