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_ListToArray(ScmObj list, int *nelts, ScmObj *store, int alloc) { ScmObj *array, lp; int len = Scm_Length(list), i; if (len < 0) Scm_Error("proper list required, but got %S", list); if (store == NULL) { array = SCM_NEW_ARRAY(ScmObj, len); } else { if (*nelts < len) { if (!alloc) Scm_Error("ListToArray: storage too small"); array = SCM_NEW_ARRAY(ScmObj, len); } else { array = store; } } for (i=0, lp=list; i<len; i++, lp=SCM_CDR(lp)) { array[i] = SCM_CAR(lp); } *nelts = len; return array; }
ScmObj Scm_ForkptyAndExec(ScmString *file, ScmObj args, ScmObj iomap, ScmObj slaveterm, ScmSysSigset *mask) { int argc = Scm_Length(args); char **argv; const char *program; int *fds; int master; pid_t pid; struct termios *term = NULL; if (argc < 1) { Scm_Error("argument list must have at least one element: %S", args); } argv = Scm_ListToCStringArray(args, TRUE, NULL); program = Scm_GetStringConst(file); if (SCM_SYS_TERMIOS_P(slaveterm)) { term = &SCM_SYS_TERMIOS(slaveterm)->term; } fds = Scm_SysPrepareFdMap(iomap); if ((pid = forkpty(&master, NULL, term, NULL)) < 0) { Scm_SysError("forkpty failed"); } if (pid == 0) { Scm_SysSwapFds(fds); if (mask) { Scm_ResetSignalHandlers(&mask->set); Scm_SysSigmask(SIG_SETMASK, mask); } execvp(program, (char *const*)argv); /* here, we failed */ Scm_Panic("exec failed: %s: %s", program, strerror(errno)); } return Scm_Values2(Scm_MakeInteger(pid), SCM_MAKE_INT(master)); }