#include "xlib.h"

s48_ref_t scx_Get_Default(s48_call_t call, s48_ref_t dpy, s48_ref_t program,
			  s48_ref_t option) {
  char* ret;
  
  if ((ret = XGetDefault(scx_extract_display(call, dpy),
                        s48_extract_string(call, program),
                        s48_extract_string(call, option))))
    return s48_enter_string(call, ret);
  else return s48_false_2(call);
}

s48_ref_t scx_Resource_Manager_String(s48_call_t call, s48_ref_t dpy) {
  char* ret;
  if ((ret = XResourceManagerString (scx_extract_display(call, dpy))))
    return s48_enter_string(call, ret);
  else return s48_false_2(call);
}

s48_ref_t scx_Parse_Geometry(s48_call_t call, s48_ref_t strg) {
  s48_ref_t ret;
  int x, y, res;
  unsigned int w, h;

  res = XParseGeometry (s48_extract_string(call, strg), &x, &y, &w, &h);

  ret = s48_make_vector_2(call, 6, s48_false_2(call));

  if (res & XNegative) s48_vector_set_2(call, ret, 0, s48_true_2(call));
  if (res & YNegative) s48_vector_set_2(call, ret, 1, s48_true_2(call));
  if (res & XValue) s48_vector_set_2(call, ret, 2, s48_enter_long_2(call, x));
  if (res & YValue) s48_vector_set_2(call, ret, 3, s48_enter_long_2(call, y));
  if (res & WidthValue) 
    s48_vector_set_2(call, ret, 4, s48_enter_long_2(call, w));
  if (res & HeightValue) 
    s48_vector_set_2(call, ret, 5, s48_enter_long_2(call, h));

  return ret;
}

void scx_init_util(void) {
  S48_EXPORT_FUNCTION(scx_Get_Default);
  S48_EXPORT_FUNCTION(scx_Resource_Manager_String);
  S48_EXPORT_FUNCTION(scx_Parse_Geometry);
}
