*/ static REBSER *String_List_To_Block(REBCHR *str) /* ** Convert a series of null terminated strings to ** a block of strings separated with '='. ** ***********************************************************************/ { REBCNT n; REBCNT len = 0; REBCHR *start = str; REBCHR *eq; REBSER *blk; while (n = LEN_STR(str)) { len++; str += n + 1; // next } blk = Make_Block(len*2); SAVE_SERIES(blk); str = start; while (NZ(eq = FIND_CHR(str+1, '=')) && NZ(n = LEN_STR(str))) { Set_Series(REB_STRING, Append_Value(blk), Copy_OS_Str(str, eq-str)); Set_Series(REB_STRING, Append_Value(blk), Copy_OS_Str(eq+1, n-(eq-str)-1)); str += n + 1; // next } Block_As_Map(blk); UNSAVE_SERIES(blk); return blk; }
// // Make_OS_Error: C // void Make_OS_Error(REBVAL *out, int errnum) { REBCHR str[100]; OS_FORM_ERROR(errnum, str, 100); Val_Init_String(out, Copy_OS_Str(str, OS_STRLEN(str))); }
*/ REBVAL *Make_OS_Error() /* ***********************************************************************/ { REBCHR str[100]; OS_FORM_ERROR(0, str, 100); Set_String(DS_RETURN, Copy_OS_Str(str, LEN_STR(str))); return DS_RETURN; }
*/ static int Read_Dir(REBREQ *dir, REBSER *files) /* ** Provide option to get file info too. ** Provide option to prepend dir path. ** Provide option to use wildcards. ** ***********************************************************************/ { REBINT result; REBCNT len; REBSER *fname; REBSER *name; REBREQ file; RESET_TAIL(files); CLEARS(&file); // Temporary filename storage: fname = BUF_OS_STR; file.special.file.path = cast(REBCHR*, Reset_Buffer(fname, MAX_FILE_NAME)); SET_FLAG(dir->modes, RFM_DIR); dir->common.data = cast(REBYTE*, &file); while ((result = OS_DO_DEVICE(dir, RDC_READ)) == 0 && !GET_FLAG(dir->flags, RRF_DONE)) { len = OS_STRLEN(file.special.file.path); if (GET_FLAG(file.modes, RFM_DIR)) len++; name = Copy_OS_Str(file.special.file.path, len); if (GET_FLAG(file.modes, RFM_DIR)) SET_ANY_CHAR(name, name->tail-1, '/'); Val_Init_File(Alloc_Tail_Array(files), name); } if (result < 0 && dir->error != -RFE_OPEN_FAIL && ( OS_STRCHR(dir->special.file.path, '*') || OS_STRCHR(dir->special.file.path, '?') ) ) { result = 0; // no matches found, but not an error } return result; }
*/ static int Read_Dir(REBREQ *dir, REBSER *files) /* ** Provide option to get file info too. ** Provide option to prepend dir path. ** Provide option to use wildcards. ** ***********************************************************************/ { REBINT result; REBCNT len; REBSER *fname; REBSER *name; REBREQ file; RESET_TAIL(files); CLEARS(&file); // Temporary filename storage: fname = BUF_OS_STR; file.file.path = (REBCHR*)Reset_Buffer(fname, MAX_FILE_NAME); SET_FLAG(dir->modes, RFM_DIR); dir->data = (REBYTE*)(&file); while ((result = OS_DO_DEVICE(dir, RDC_READ)) == 0 && !GET_FLAG(dir->flags, RRF_DONE)) { len = LEN_STR(file.file.path); if (GET_FLAG(file.modes, RFM_DIR)) len++; name = Copy_OS_Str(file.file.path, len); if (GET_FLAG(file.modes, RFM_DIR)) SET_ANY_CHAR(name, name->tail-1, '/'); Set_Series(REB_FILE, Append_Value(files), name); } if (result < 0 && dir->error != -RFE_OPEN_FAIL && (FIND_CHR(dir->file.path, '*') || FIND_CHR(dir->file.path, '?'))) result = 0; // no matches found, but not an error return result; }