示例#1
0
文件: inet_mod.c 项目: adh/dfsch
DFSCH_DEFINE_PRIMITIVE(inet_base64_encode, NULL) {
    dfsch_strbuf_t* str;
    dfsch_object_t* wrap;
    dfsch_object_t* pad;
    DFSCH_BUFFER_ARG(args, str);
    DFSCH_OBJECT_ARG_OPT(args, wrap, NULL);
    DFSCH_OBJECT_ARG_OPT(args, pad, NULL);
    DFSCH_ARG_END(args);

    return dfsch_make_string_nocopy(dfsch_inet_base64_encode(str,
                                    wrap!=NULL,
                                    pad!=NULL));
}
示例#2
0
文件: ports.c 项目: leia/dfsch
DFSCH_DEFINE_PRIMITIVE(read, NULL){
  dfsch_object_t* port;
  char *buf;
  DFSCH_OBJECT_ARG_OPT(args, port, dfsch_current_input_port());  
  DFSCH_ARG_END(args);

  return dfsch_parser_read_from_port(port);
}
示例#3
0
文件: ports.c 项目: leia/dfsch
DFSCH_DEFINE_PRIMITIVE(newline, NULL){
  dfsch_object_t* port;
  char *buf;
  DFSCH_OBJECT_ARG_OPT(args, port, dfsch_current_output_port());  
  DFSCH_ARG_END(args);

  dfsch_port_write_buf(port, "\n", 1);
  
  return NULL;
}
示例#4
0
文件: ports.c 项目: leia/dfsch
DFSCH_DEFINE_PRIMITIVE(display, NULL){
  dfsch_object_t* port;
  dfsch_object_t* object;
  char *buf;
  DFSCH_OBJECT_ARG(args, object);
  DFSCH_OBJECT_ARG_OPT(args, port, dfsch_current_output_port());  
  DFSCH_ARG_END(args);

  buf = dfsch_object_2_string(object, 1000, 0);
  dfsch_port_write_buf(port, buf, strlen(buf));
  
  return NULL;
}
示例#5
0
文件: ports.c 项目: leia/dfsch
DFSCH_DEFINE_PRIMITIVE(port_read_buf, NULL){
  dfsch_object_t* port;
  size_t len;
  char* buf;
  DFSCH_LONG_ARG(args, len);
  DFSCH_OBJECT_ARG_OPT(args, port, dfsch_current_input_port());  
  DFSCH_ARG_END(args);

  buf = GC_MALLOC_ATOMIC(len);
  len = dfsch_port_read_buf(port, buf, len);
  
  if (len == 0){
    return NULL;
  }

  return dfsch_make_string_buf(buf, len);
}
示例#6
0
文件: system.c 项目: adh/dfsch
DFSCH_DEFINE_PRIMITIVE(decode_universal_time, NULL){
  time_t time;
  dfsch_object_t* utc;
  dfsch_object_t* ret;

  DFSCH_LONG_ARG(args, time);
  DFSCH_OBJECT_ARG_OPT(args, utc, NULL);
  DFSCH_ARG_END(args);

  ret = dfsch_make_decoded_time();

  if (utc){
    gmtime_r(&time, dfsch_decoded_time_get_tm(ret));
  } else {
    localtime_r(&time, dfsch_decoded_time_get_tm(ret));
  }
 
  return ret;
}
示例#7
0
文件: system.c 项目: adh/dfsch
DFSCH_DEFINE_PRIMITIVE(iso_format_time, NULL){
  char t = ' ';
  dfsch_object_t* use_t;
  dfsch_object_t* time;
  struct tm* tm;
  DFSCH_OBJECT_ARG(args, time);
  DFSCH_OBJECT_ARG_OPT(args, use_t, NULL);
  DFSCH_ARG_END(args);

  if (use_t){
    t = 'T';
  }

  tm = dfsch_decoded_time_get_tm(time);

  return dfsch_make_string_cstr(saprintf("%04d-%02d-%02d%c%02d:%02d:%02d",
                                         tm->tm_year+1900, tm->tm_mon+1, 
                                         tm->tm_mday, t,
                                         tm->tm_hour, tm->tm_min, tm->tm_sec));
}
示例#8
0
文件: system.c 项目: adh/dfsch
DFSCH_DEFINE_PRIMITIVE(get_decoded_time, NULL){
  time_t t;
  dfsch_object_t* utc;
  dfsch_object_t* ret;

  DFSCH_OBJECT_ARG_OPT(args, utc, NULL);
  DFSCH_ARG_END(args);

  ret = dfsch_make_decoded_time();

  t = time(NULL);

  if (utc){
    gmtime_r(&t, dfsch_decoded_time_get_tm(ret));
  } else {
    localtime_r(&t, dfsch_decoded_time_get_tm(ret));
  }
 
  return ret;  
}