static dfsch_object_t* decoded_time_apply(decoded_time_t* time, dfsch_object_t* args, dfsch_tail_escape_t* esc){ dfsch_object_t* selector; DFSCH_OBJECT_ARG(args, selector); DFSCH_ARG_END(args); if (dfsch_compare_keyword(selector, "sec")){ return dfsch_make_number_from_long(time->tm.tm_sec); } else if (dfsch_compare_keyword(selector, "min")){ return dfsch_make_number_from_long(time->tm.tm_min); } else if (dfsch_compare_keyword(selector, "hour")){ return dfsch_make_number_from_long(time->tm.tm_hour); } else if (dfsch_compare_keyword(selector, "date")){ return dfsch_make_number_from_long(time->tm.tm_mday); } else if (dfsch_compare_keyword(selector, "month")){ return dfsch_make_number_from_long(time->tm.tm_mon + 1); } else if (dfsch_compare_keyword(selector, "year")){ return dfsch_make_number_from_long(time->tm.tm_year + 1900); } else if (dfsch_compare_keyword(selector, "day")){ return dfsch_make_number_from_long(time->tm.tm_wday); } else if (dfsch_compare_keyword(selector, "year-day")){ return dfsch_make_number_from_long(time->tm.tm_yday + 1); } else if (dfsch_compare_keyword(selector, "dst?")){ return dfsch_bool(time->tm.tm_isdst == 1); } dfsch_error("Unknown field requested", selector); }
static dfsch_slot_t* make_slots(dfsch_object_t* slot_desc){ dfsch_object_t* i = slot_desc; size_t slot_count = dfsch_list_length_check(slot_desc); dfsch_slot_t* slots = GC_MALLOC((slot_count + 1) * sizeof(dfsch_slot_t)); dfsch_slot_t* j = slots; while (slot_count && DFSCH_PAIR_P(i)){ dfsch_object_t* name; dfsch_object_t* type; if (DFSCH_PAIR_P(DFSCH_FAST_CAR(i))){ dfsch_object_t* args = DFSCH_FAST_CAR(i); DFSCH_OBJECT_ARG(args, name); } else { name = DFSCH_FAST_CAR(i); } j->type = DFSCH_OBJECT_SLOT_TYPE; j->name = dfsch_symbol(name); j->documentation = NULL; j++; slot_count--; i = DFSCH_FAST_CDR(i); } j->type = NULL; j->name = NULL; j->access = DFSCH_SLOT_ACCESS_RW; j->documentation = NULL; return slots; }
DFSCH_DEFINE_PRIMITIVE(set_current_error_port, NULL){ dfsch_object_t* port; DFSCH_OBJECT_ARG(args, port); DFSCH_ARG_END(args); dfsch_set_current_error_port(port); return NULL; }
static void default_initialize_instance(dfsch_object_t* obj, class_t* klass, dfsch_object_t* args){ dfsch_object_t* i = klass->initvalues; while (DFSCH_PAIR_P(i)){ dfsch_object_t* j = DFSCH_FAST_CAR(i); dfsch_object_t* value; dfsch_object_t* slot; DFSCH_OBJECT_ARG(j, value); DFSCH_OBJECT_ARG(j, slot); dfsch_slot_set(obj, slot, value, 1); i = DFSCH_FAST_CDR(i); } while (DFSCH_PAIR_P(args)){ dfsch_object_t* keyword; dfsch_object_t* value; dfsch_object_t* slot; keyword = DFSCH_FAST_CAR(args); args = DFSCH_FAST_CDR(args); if (!DFSCH_PAIR_P(args)){ dfsch_error("Value expected for keyword", keyword); } value = DFSCH_FAST_CAR(args); args = DFSCH_FAST_CDR(args); slot = dfsch_assq(keyword, klass->initargs); if (!slot){ dfsch_error("Unknown keyword", keyword); } dfsch_slot_set(obj, dfsch_list_item(slot, 1), value, 1); } }
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; }
DFSCH_DEFINE_PRIMITIVE(regex_substrings, NULL){ dfsch_object_t* expression; char* string; int flags = 0; DFSCH_OBJECT_ARG(args, expression); DFSCH_STRING_ARG(args, string); DFSCH_FLAG_PARSER_BEGIN(args); DFSCH_FLAG_SET("notbol", REG_NOTBOL, flags); DFSCH_FLAG_SET("noteol", REG_NOTEOL, flags); DFSCH_FLAG_PARSER_END(args); return dfsch_regex_substrings(expression, string, flags); }
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)); }