示例#1
0
文件: p-file.c 项目: mbk/ren-c
*/	void Ret_Query_File(REBSER *port, REBREQ *file, REBVAL *ret)
/*
**		Query file and set RET value to resulting STD_FILE_INFO object.
**
***********************************************************************/
{
	REBVAL *info = In_Object(port, STD_PORT_SCHEME, STD_SCHEME_INFO, 0);
	REBSER *obj;
	REBSER *ser;

	if (!info || !IS_OBJECT(info)) Trap_Port(RE_INVALID_SPEC, port, -10);

	obj = CLONE_OBJECT(VAL_OBJ_FRAME(info));

	SET_OBJECT(ret, obj);
	Init_Word_Unbound(
		OFV(obj, STD_FILE_INFO_TYPE),
		REB_WORD,
		GET_FLAG(file->modes, RFM_DIR) ? SYM_DIR : SYM_FILE
	);
	SET_INTEGER(OFV(obj, STD_FILE_INFO_SIZE), file->special.file.size);
	Set_File_Date(file, OFV(obj, STD_FILE_INFO_DATE));

	ser = To_REBOL_Path(file->special.file.path, 0, OS_WIDE, 0);

	Set_Series(REB_FILE, OFV(obj, STD_FILE_INFO_NAME), ser);
}
示例#2
0
*/	static REBSER *File_List_To_Block(REBCHR *str)
/*
**		Convert file directory and file name list to block.
**
***********************************************************************/
{
	REBCNT n;
	REBCNT len = 0;
	REBCHR *start = str;
	REBSER *blk;
	REBSER *dir;

	while (n = LEN_STR(str)) {
		len++;
		str += n + 1; // next
	}

	blk = Make_Block(len);
	SAVE_SERIES(blk);

	// First is a dir path or full file path:
	str = start;
	n = LEN_STR(str);

	if (len == 1) {  // First is full file path
		dir = To_REBOL_Path(str, n, -1, 0);
		Set_Series(REB_FILE, Append_Value(blk), dir);
	}
	else {  // First is dir path for the rest of the files
		dir = To_REBOL_Path(str, n, -1, TRUE);
		str += n + 1; // next
		len = dir->tail;
		while (n = LEN_STR(str)) {
			dir->tail = len;
			Append_Uni_Uni(dir, str, n);
			Set_Series(REB_FILE, Append_Value(blk), Copy_String(dir, 0, -1));
			str += n + 1; // next
		}
	}

	UNSAVE_SERIES(blk);
	return blk;
}