Exemplo n.º 1
0
int scm_list_to_imht_set(SCM scm_a, imht_set_t **result) {
  int a_length = scm_to_uint32((scm_length(scm_a)));
  if (!imht_set_create((3 + a_length), result)) {
    return (1);
  };
  while (!scm_is_null(scm_a)) {
    if (!imht_set_add((*result), (scm_to_int((SCM_CAR(scm_a)))))) {
      imht_set_destroy((*result));
      return (2);
    };
    scm_a = SCM_CDR(scm_a);
  };
  return (0);
};
Exemplo n.º 2
0
Arquivo: scheme.c Projeto: nizmic/nwm
static SCM scm_draw_border(SCM client_smob, SCM color, SCM width)
{
    client_t *client = (client_t *)SCM_SMOB_DATA(client_smob);
    uint32_t color_uint;
    int width_int;
    if (scm_is_integer(color))
        color_uint = scm_to_uint32(color);
    else
        color_uint = 0x6CA0A3;
    if (scm_is_integer(width))
        width_int = scm_to_int(width);
    else
        width_int = 1;
    draw_border(client, color_uint, width_int);
    return SCM_UNSPECIFIED;
}
Exemplo n.º 3
0
Arquivo: scheme.c Projeto: nizmic/nwm
static SCM scm_bind_key(SCM mod_mask, SCM key, SCM proc)
{
    xcb_keysym_t keysym;
    if (scm_is_true(scm_number_p(key)))
        keysym = scm_to_uint32(key);
    else if (scm_is_true(scm_string_p(key))) {
        scm_dynwind_begin(0);
        char *c_key = scm_to_locale_string(key);
        scm_dynwind_free(c_key);
        keysym = get_keysym(c_key);
        scm_dynwind_end();
    }
    else
        return SCM_UNSPECIFIED;
    bind_key(scm_to_uint16(mod_mask), keysym, proc);
    return SCM_UNSPECIFIED;
}
Exemplo n.º 4
0
SCM
guile_sock_connect (SCM host, SCM proto, SCM port)
{
    svz_socket_t *sock;
    uint32_t xhost;
    uint16_t xport = 0;
    uint16_t p;
    int xproto;
    char *str;
    struct sockaddr_in addr;
    SCM ret = SCM_BOOL_F;

    SCM_ASSERT (scm_is_integer (host) || scm_is_string (host), host, SCM_ARG1,
                FUNC_NAME);
    SCM_ASSERT (scm_is_integer (proto), proto, SCM_ARG2, FUNC_NAME);

    /* Extract host to connect to.  */
    if (scm_is_integer (host))
        xhost = htonl (scm_to_uint32 (host));
    else
    {
        str = guile_to_string (host);
        if (svz_inet_aton (str, &addr) == -1)
        {
            if (guile_resolve (str, &xhost) == -1)
            {
                guile_error ("%s: IP in dotted decimals or hostname expected",
                             FUNC_NAME);
                free (str);
                return ret;
            }
        }
        else
            xhost = addr.sin_addr.s_addr;
        free (str);
    }

    /* Extract protocol to use.  */
    xproto = scm_to_int (proto);

    /* Find out about given port.  */
    if (!SCM_UNBNDP (port))
    {
        SCM_ASSERT (scm_is_integer (port), port, SCM_ARG3, FUNC_NAME);
        p = scm_to_uint16 (port);
        xport = htons (p);
    }

    /* Depending on the requested protocol; create different kinds of
       socket structures.  */
    switch (xproto)
    {
    case PROTO_TCP:
        sock = svz_tcp_connect (xhost, xport);
        break;
    case PROTO_UDP:
        sock = svz_udp_connect (xhost, xport);
        break;
    case PROTO_ICMP:
        sock = svz_icmp_connect (xhost, xport, ICMP_SERVEEZ);
        break;
    default:
        scm_out_of_range (FUNC_NAME, proto);
    }

    if (sock == NULL)
        return ret;

    sock->disconnected_socket = guile_func_disconnected_socket;
    SCM_RETURN_NEWSMOB (guile_svz_socket_tag, sock);
}