*/ static void Setup_File(REBREQ *file, REBCNT args, REBVAL *path) /* ** Convert native action refinements to file modes. ** ***********************************************************************/ { REBSER *ser; if (args & AM_OPEN_WRITE) SET_FLAG(file->modes, RFM_WRITE); if (args & AM_OPEN_READ) SET_FLAG(file->modes, RFM_READ); if (args & AM_OPEN_SEEK) SET_FLAG(file->modes, RFM_SEEK); if (args & AM_OPEN_NEW) { SET_FLAG(file->modes, RFM_NEW); if (!(args & AM_OPEN_WRITE)) Trap1(RE_BAD_FILE_MODE, path); } // Convert file name to OS format, let it GC later. if (!(ser = Value_To_OS_Path(path, TRUE))) Trap1(RE_BAD_FILE_PATH, path); file->special.file.path = cast(REBCHR*, ser->data); SET_FLAG(file->modes, RFM_NAME_MEM); Secure_Port(SYM_FILE, file, path, ser); }
*/ static void Init_Dir_Path(REBREQ *dir, REBVAL *path, REBINT wild, REBCNT policy) /* ** Convert REBOL dir path to file system path. ** On Windows, we will also need to append a * if necessary. ** ** ARGS: ** Wild: ** 0 - no wild cards, path must end in / else error ** 1 - accept wild cards * and ?, and * if need ** -1 - not wild, if path does not end in /, add it ** ***********************************************************************/ { REBINT len; REBSER *ser; //REBYTE *flags; SET_FLAG(dir->modes, RFM_DIR); // We depend on To_Local_Path giving us 2 extra chars for / and * ser = Value_To_OS_Path(path); len = ser->tail; dir->file.path = (REBCHR*)(ser->data); Secure_Port(SYM_FILE, dir, path, ser); if (len == 1 && dir->file.path[0] == '.') { if (wild > 0) { dir->file.path[0] = '*'; dir->file.path[1] = 0; } } else if (len == 2 && dir->file.path[0] == '.' && dir->file.path[1] == '.') { // Insert * if needed: if (wild > 0) { dir->file.path[len++] = '/'; dir->file.path[len++] = '*'; dir->file.path[len] = 0; } } else if (dir->file.path[len-1] == '/' || dir->file.path[len-1] == '\\') { if (policy & REMOVE_TAIL_SLASH) { dir->file.path[len-1] = 0; } else { // Insert * if needed: if (wild > 0) { dir->file.path[len++] = '*'; dir->file.path[len] = 0; } } } else { // Path did not end with /, so we better be wild: if (wild == 0) { ///OS_FREE(dir->file.path); Trap1(RE_BAD_FILE_PATH, path); } else if (wild < 0) { dir->file.path[len++] = OS_DIR_SEP; dir->file.path[len] = 0; } } }
*/ static void Init_Dir_Path(REBREQ *dir, REBVAL *path, REBINT wild, REBCNT policy) /* ** Convert REBOL dir path to file system path. ** On Windows, we will also need to append a * if necessary. ** ** ARGS: ** Wild: ** 0 - no wild cards, path must end in / else error ** 1 - accept wild cards * and ?, and * if need ** -1 - not wild, if path does not end in /, add it ** ***********************************************************************/ { REBINT len; REBSER *ser; //REBYTE *flags; SET_FLAG(dir->modes, RFM_DIR); // We depend on To_Local_Path giving us 2 extra chars for / and * ser = Value_To_OS_Path(path, TRUE); len = ser->tail; dir->special.file.path = cast(REBCHR*, ser->data); Secure_Port(SYM_FILE, dir, path, ser); if (len == 1 && OS_CH_EQUAL(dir->special.file.path[0], '.')) { if (wild > 0) { dir->special.file.path[0] = OS_MAKE_CH('*'); dir->special.file.path[1] = OS_MAKE_CH('\0'); } } else if ( len == 2 && OS_CH_EQUAL(dir->special.file.path[0], '.') && OS_CH_EQUAL(dir->special.file.path[1], '.') ) { // Insert * if needed: if (wild > 0) { dir->special.file.path[len++] = OS_MAKE_CH('/'); dir->special.file.path[len++] = OS_MAKE_CH('*'); dir->special.file.path[len] = OS_MAKE_CH('\0'); } } else if ( OS_CH_EQUAL(dir->special.file.path[len-1], '/') || OS_CH_EQUAL(dir->special.file.path[len-1], '\\') ) { if (policy & REMOVE_TAIL_SLASH) { dir->special.file.path[len-1] = OS_MAKE_CH('\0'); } else { // Insert * if needed: if (wild > 0) { dir->special.file.path[len++] = OS_MAKE_CH('*'); dir->special.file.path[len] = OS_MAKE_CH('\0'); } } } else { // Path did not end with /, so we better be wild: if (wild == 0) { // !!! Comment said `OS_FREE(dir->special.file.path);` (needed?) raise Error_1(RE_BAD_FILE_PATH, path); } else if (wild < 0) { dir->special.file.path[len++] = OS_MAKE_CH(OS_DIR_SEP); dir->special.file.path[len] = OS_MAKE_CH('\0'); } } }