/* returns a list of ranges contained in the charset */ ScmObj Scm_CharSetRanges(ScmCharSet *cs) { ScmObj h = SCM_NIL, t = SCM_NIL; int ind, begin = 0, prev = FALSE; for (ind = 0; ind < SCM_CHAR_SET_SMALL_CHARS; ind++) { int bit = MASK_ISSET(cs, ind); if (!prev && bit) begin = ind; if (prev && !bit) { ScmObj cell = Scm_Cons(SCM_MAKE_INT(begin), SCM_MAKE_INT(ind-1)); SCM_APPEND1(h, t, cell); } prev = bit; } if (prev) { ScmObj cell = Scm_Cons(SCM_MAKE_INT(begin), SCM_MAKE_INT(ind-1)); SCM_APPEND1(h, t, cell); } ScmTreeIter iter; ScmDictEntry *e; Scm_TreeIterInit(&iter, &cs->large, NULL); while ((e = Scm_TreeIterNext(&iter)) != NULL) { ScmObj cell = Scm_Cons(SCM_MAKE_INT(e->key), SCM_MAKE_INT(e->value)); SCM_APPEND1(h, t, cell); } return h; }
ScmObj Scm_CopyList(ScmObj list) { if (!SCM_PAIRP(list)) return list; ScmObj start = SCM_NIL, last = SCM_NIL; SCM_FOR_EACH(list, list) { SCM_APPEND1(start, last, SCM_CAR(list)); }
ScmObj Scm_ArrayToListWithTail(ScmObj *elts, int nelts, ScmObj tail) { ScmObj h = SCM_NIL, t = SCM_NIL; if (elts) { for (int i=0; i<nelts; i++) SCM_APPEND1(h, t, *elts++); } if (!SCM_NULLP(tail)) SCM_APPEND(h, t, tail); return h; }
ScmObj Scm_UngottenBytesUnsafe(ScmPort *p) #endif { VMDECL; SHORTCUT(p, return Scm_UngottenBytesUnsafe(p)); char buf[SCM_CHAR_MAX_BYTES]; LOCK(p); for (int i=0; i<p->scrcnt; i++) buf[i] = p->scratch[i]; int n = p->scrcnt; UNLOCK(p); ScmObj h = SCM_NIL, t = SCM_NIL; for (int i=0; i<n; i++) { SCM_APPEND1(h, t, SCM_MAKE_INT((unsigned char)buf[i])); } return h; }
ScmObj Scm_MakeCompoundCondition(ScmObj conditions) { ScmObj h = SCM_NIL, t = SCM_NIL; int serious = FALSE; int nconds = Scm_Length(conditions); /* some boundary cases */ if (nconds < 0) { Scm_Error("Scm_MakeCompoundCondition: list required, but got %S", conditions); } if (nconds == 0) { return compound_allocate(SCM_CLASS_COMPOUND_CONDITION, SCM_NIL); } if (nconds == 1) { if (!SCM_CONDITIONP(SCM_CAR(conditions))) { Scm_Error("make-compound-condition: given non-condition object: %S", SCM_CAR(conditions)); } return SCM_CAR(conditions); } /* collect conditions and creates compound one */ ScmObj cp; SCM_FOR_EACH(cp, conditions) { ScmObj c = SCM_CAR(cp); if (!SCM_CONDITIONP(c)) { Scm_Error("make-compound-condition: given non-condition object: %S", SCM_CAR(cp)); } if (SCM_SERIOUS_CONDITION_P(c)) { serious = TRUE; } if (SCM_COMPOUND_CONDITION_P(c)) { ScmCompoundCondition *cc = SCM_COMPOUND_CONDITION(c); SCM_APPEND(h, t, cc->conditions); } else { SCM_APPEND1(h, t, c); } }
ScmObj Scm_DeleteKeyword(ScmObj key, ScmObj list) { ScmObj cp; SCM_FOR_EACH(cp, list) { if (!SCM_PAIRP(SCM_CDR(cp))) { Scm_Error("incomplete key list: %S", list); } if (key == SCM_CAR(cp)) { /* found */ ScmObj h = SCM_NIL, t = SCM_NIL; ScmObj tail = Scm_DeleteKeyword(key, SCM_CDR(SCM_CDR(cp))); ScmObj cp2; SCM_FOR_EACH(cp2, list) { if (cp2 == cp) { SCM_APPEND(h, t, tail); return h; } else { SCM_APPEND1(h, t, SCM_CAR(cp2)); } } } cp = SCM_CDR(cp); }