Example #1
0
*/	REBOOL OS_Request_File(REBRFR *fr)
/*
***********************************************************************/
{
	OPENFILENAME ofn = {0};
	BOOL ret;
	//int err;
	REBCHR *filters = TEXT("All files\0*.*\0REBOL scripts\0*.r\0Text files\0*.txt\0"	);

	ofn.lStructSize = sizeof(ofn);

	// ofn.hwndOwner = WIN_WIN(win); // Must find a way to set this

	ofn.lpstrTitle = fr->title;
	ofn.lpstrInitialDir = fr->dir;
	ofn.lpstrFile = fr->files;
	ofn.lpstrFilter = fr->filter ? fr->filter : filters;
	ofn.nMaxFile = fr->len;
	ofn.lpstrFileTitle = 0;
	ofn.nMaxFileTitle = 0;

	ofn.Flags = OFN_HIDEREADONLY | OFN_EXPLORER | OFN_NOCHANGEDIR; //|OFN_NONETWORKBUTTON; //;

	if (GET_FLAG(fr->flags, FRF_MULTI)) ofn.Flags |= OFN_ALLOWMULTISELECT;

	if (GET_FLAG(fr->flags, FRF_SAVE))
		ret = GetSaveFileName(&ofn);
	else
		ret = GetOpenFileName(&ofn);

	//if (!ret)
	//	err = CommDlgExtendedError(); // CDERR_FINDRESFAILURE

	return ret;
}
Example #2
0
//
//  Open_IO: C
//
DEVICE_CMD Open_IO(REBREQ *req)
{
    REBDEV *dev;

    dev = Devices[req->device];

    // Avoid opening the console twice (compare dev and req flags):
    if (GET_FLAG(dev->flags, RDF_OPEN)) {
        // Device was opened earlier as null, so req must have that flag:
        if (GET_FLAG(dev->flags, SF_DEV_NULL))
            SET_FLAG(req->modes, RDM_NULL);
        SET_FLAG(req->flags, RRF_OPEN);
        return DR_DONE; // Do not do it again
    }

    if (!GET_FLAG(req->modes, RDM_NULL)) {
        // Get the raw stdio handles:
        Std_Out = GetStdHandle(STD_OUTPUT_HANDLE);
        Std_Inp = GetStdHandle(STD_INPUT_HANDLE);
        //Std_Err = GetStdHandle(STD_ERROR_HANDLE);
        Std_Echo = 0;

        Redir_Out = (GetFileType(Std_Out) != 0);
        Redir_Inp = (GetFileType(Std_Inp) != 0);

        if (!Redir_Inp || !Redir_Out) {
            // If either input or output is not redirected, preallocate
            // a buffer for conversion from/to UTF-8.
            Std_Buf = OS_ALLOC_N(wchar_t, BUF_SIZE);
        }
Example #3
0
*/	DEVICE_CMD Write_File(REBREQ *file)
/*
**	Bug?: update file->size value after write !?
**
***********************************************************************/
{
	if (!file->id) {
		file->error = -RFE_NO_HANDLE;
		return DR_ERROR;
	}

	if (GET_FLAG(file->modes, RFM_APPEND)) {
		CLR_FLAG(file->modes, RFM_APPEND);
		lseek(file->id, 0, SEEK_END);
	}

	if (file->modes & ((1 << RFM_SEEK) | (1 << RFM_RESEEK) | (1 << RFM_TRUNCATE))) {
		CLR_FLAG(file->modes, RFM_RESEEK);
		if (!Seek_File_64(file)) return DR_ERROR;
		if (GET_FLAG(file->modes, RFM_TRUNCATE))
			if (ftruncate(file->id, file->file.index)) return DR_ERROR;
	}

	if (file->length == 0) return DR_DONE;

	file->actual = write(file->id, file->data, file->length);
	if (file->actual < 0) {
		if (errno == ENOSPC) file->error = -RFE_DISK_FULL;
		else file->error = -RFE_BAD_WRITE;
		return DR_ERROR;
	}

	return DR_DONE;
}
Example #4
0
//
//  Open_IO: C
//
DEVICE_CMD Open_IO(REBREQ *req)
{
    REBDEV *dev;

    dev = Devices[req->device];

    // Avoid opening the console twice (compare dev and req flags):
    if (GET_FLAG(dev->flags, RDF_OPEN)) {
        // Device was opened earlier as null, so req must have that flag:
        if (GET_FLAG(dev->flags, SF_DEV_NULL))
            SET_FLAG(req->modes, RDM_NULL);
        SET_FLAG(req->flags, RRF_OPEN);
        return DR_DONE; // Do not do it again
    }

    Init_Signals();

    if (!GET_FLAG(req->modes, RDM_NULL)) {

#ifndef HAS_SMART_CONSOLE
        if (isatty(Std_Inp))
            Term_IO = Init_Terminal();
#endif
        //printf("%x\r\n", req->requestee.handle);
    }
    else
        SET_FLAG(dev->flags, SF_DEV_NULL);

    SET_FLAG(req->flags, RRF_OPEN);
    SET_FLAG(dev->flags, RDF_OPEN);

    return DR_DONE;
}
Example #5
0
std::string enchant::print_to_file() const
{
	std::stringstream out;
	out << "Ench: I " << name_ << "\n" << " T "<< type_ << "\n";

	for (std::vector<obj_affected_type>::const_iterator i = affected_.begin(),
		iend = affected_.end(); i != iend; ++i)
	{
		out << " A " << i->location << " " << i->modifier << "\n";
	}

	*buf = '\0';
	tascii(&GET_FLAG(affects_flags_, 0), 4, buf);
	out << " F " << buf << "\n";

	*buf = '\0';
	tascii(&GET_FLAG(extra_flags_, 0), 4, buf);
	out << " E " << buf << "\n";

	*buf = '\0';
	tascii(&GET_FLAG(no_flags_, 0), 4, buf);
	out << " N " << buf << "\n";

	out << " W " << weight_ << "\n";
	out << " B " << ndice_ << "\n";
	out << " C " << sdice_ << "\n";
	out << "~\n";

	return out.str();
}
Example #6
0
static REBCNT find_string(REBSER *series, REBCNT index, REBCNT end, REBVAL *target, REBCNT len, REBCNT flags, REBINT skip)
{
	REBCNT start = index;

	if (flags & (AM_FIND_REVERSE | AM_FIND_LAST)) {
		skip = -1;
		start = 0;
		if (flags & AM_FIND_LAST) index = end - len;
		else index--;
	}

	if (ANY_BINSTR(target)) {
		// Do the optimal search or the general search?
		if (BYTE_SIZE(series) && VAL_BYTE_SIZE(target) && !(flags & ~(AM_FIND_CASE|AM_FIND_MATCH)))
			return Find_Byte_Str(series, start, VAL_BIN_DATA(target), len, !GET_FLAG(flags, ARG_FIND_CASE-1), GET_FLAG(flags, ARG_FIND_MATCH-1));
		else
			return Find_Str_Str(series, start, index, end, skip, VAL_SERIES(target), VAL_INDEX(target), len, flags & (AM_FIND_MATCH|AM_FIND_CASE));
	}
	else if (IS_BINARY(target)) {
		return Find_Byte_Str(series, start, VAL_BIN_DATA(target), len, 0, GET_FLAG(flags, ARG_FIND_MATCH-1));
	}
	else if (IS_CHAR(target)) {
		return Find_Str_Char(series, start, index, end, skip, VAL_CHAR(target), flags);
	}
	else if (IS_INTEGER(target)) {
		return Find_Str_Char(series, start, index, end, skip, (REBUNI)VAL_INT32(target), flags);
	}
	else if (IS_BITSET(target)) {
		return Find_Str_Bitset(series, start, index, end, skip, VAL_SERIES(target), flags);
	}

	return NOT_FOUND;
}
Example #7
0
void
delayed_trigger_activity ()
{
	CHAR_DATA *ch;

	//for (ch = character_list; ch; ch = ch->next)
	for (std::list<char_data*>::iterator tch_iterator = character_list.begin(); tch_iterator != character_list.end(); tch_iterator++)
	{
		ch = *tch_iterator;

		if (ch->deleted)
			continue;

		if (GET_FLAG (ch, FLAG_INHIBITTED))
		{

			if (!GET_FLAG (ch, FLAG_ENTERING) &&
				!GET_FLAG (ch, FLAG_LEAVING) && !ch->delay)
				ch->flags &= ~FLAG_INHIBITTED;
			else
				continue;
		}

		if (ch->trigger_delay && !--(ch->trigger_delay))
			trigger (ch, "", ch->trigger_id);
	}
}
Example #8
0
/*
 * Stream contains open file descriptors that could not be completed.
 * If stream has only pending open file descriptors close file
 * descriptors.
 */
static void
closeStream()
{
	FileInfo_t *file;
	int id;

	id = Stream->first;
	while (id > EOS) {
		PthreadMutexLock(&Stream->mutex);
		file = GetFile(id);
		PthreadMutexLock(&file->mutex);
		if (GET_FLAG(file->flags, FI_DCACHE_CLOSE)) {
			if (close(file->dcache) == -1) {
				WarnSyscallError(HERE,
				    "close", "");
			}
			CLEAR_FLAG(file->flags, FI_DCACHE);
			NumOpenFiles--;

		} else if (GET_FLAG(file->flags, FI_DCACHE)) {
			SendErrorResponse(file);
		}

		id = file->next;
		PthreadMutexUnlock(&Stream->mutex);
		PthreadMutexUnlock(&file->mutex);
	}

	if (GET_FLAG(Stream->flags, SR_UNAVAIL)) {
		rejectRequest(ENODEV, B_TRUE);
	} else {
		rejectRequest(0, B_TRUE);
	}
}
Example #9
0
*/	DEVICE_CMD Read_DNS(REBREQ *sock)
/*
**		Initiate the GetHost request and return immediately.
**		Note the temporary results buffer (must be freed later).
**
***********************************************************************/
{
	void *host;
#ifdef HAS_ASYNC_DNS
	HANDLE handle;
#else
	HOSTENT *he;
#endif

	host = OS_Make(MAXGETHOSTSTRUCT); // be sure to free it

#ifdef HAS_ASYNC_DNS
	if (!GET_FLAG(sock->modes, RST_REVERSE)) // hostname lookup
		handle = WSAAsyncGetHostByName(Event_Handle, WM_DNS, sock->data, host, MAXGETHOSTSTRUCT);
	else
		handle = WSAAsyncGetHostByAddr(Event_Handle, WM_DNS, (char*)&(sock->net.remote_ip), 4, AF_INET, host, MAXGETHOSTSTRUCT);

	if (handle != 0) {
		sock->net.host_info = host;
		sock->handle = handle;
		return DR_PEND; // keep it on pending list
	}
#else
	// Use old-style blocking DNS (mainly for testing purposes):
	if (GET_FLAG(sock->modes, RST_REVERSE)) {
		he = gethostbyaddr((char*)&sock->net.remote_ip, 4, AF_INET);
		if (he) {
			sock->net.host_info = host; //???
			sock->data = he->h_name;
			SET_FLAG(sock->flags, RRF_DONE);
			return DR_DONE;
		}
	}
	else {
		he = gethostbyname(sock->data);
		if (he) {
			sock->net.host_info = host; // ?? who deallocs?
			COPY_MEM((char*)&(sock->net.remote_ip), (char *)(*he->h_addr_list), 4); //he->h_length);
			SET_FLAG(sock->flags, RRF_DONE);
			return DR_DONE;
		}
	}
#endif

	OS_Free(host);
	sock->net.host_info = 0;

	sock->error = GET_ERROR;
	//Signal_Device(sock, EVT_ERROR);
	return DR_ERROR; // Remove it from pending list
}
Example #10
0
*/	int OS_Do_Device(REBREQ *req, REBCNT command)
/*
**		Tell a device to perform a command. Non-blocking in many
**		cases and will attach the request for polling.
**
**		Returns:
**			=0: for command success
**			>0: for command still pending
**			<0: for command error
**
***********************************************************************/
{
	REBDEV *dev;
	REBINT result;

	req->error = 0; // A94 - be sure its cleared

	// Validate device:
	if (req->device >= RDI_MAX || !(dev = Devices[req->device])) {
		req->error = RDE_NO_DEVICE;
		return -1;
	}

	// Confirm device is initialized. If not, return an error or init
	// it if auto init option is set.
	if (!GET_FLAG(dev->flags, RDF_INIT)) {
		if (GET_FLAG(dev->flags, RDO_MUST_INIT)) {
			req->error = RDE_NO_INIT;
			return -1;
		}
		if (!dev->commands[RDC_INIT] || !dev->commands[RDC_INIT]((REBREQ*)dev))
		SET_FLAG(dev->flags, RDF_INIT);
	}

	// Validate command:
	if (command > dev->max_command || dev->commands[command] == 0) {
		req->error = RDE_NO_COMMAND;
		return -1;
	}

	// Do the command:
	req->command = command;
	result = dev->commands[command](req);

	// If request is pending, attach it to device for polling:
	if (result > 0) Attach_Request(&dev->pending, req);
	else if (dev->pending) {
		Detach_Request(&dev->pending, req); // often a no-op
		if (result == DR_ERROR && GET_FLAG(req->flags, RRF_ALLOC)) { // not on stack
			Signal_Device(req, EVT_ERROR);
		}
	}

	return result;
}
Example #11
0
void catalog_validate_objects()
{
    catalog_object_header * i = local_catalog->invalid_list;
    while (i != NULL) {
        if (GET_FLAG(i->flags, CAT_OBJECT_DELETED_FLAG)) {
        } else if (GET_FLAG(i->flags, CAT_OBJECT_INVALID_FLAG)) {
            i->validate();
        }
        i = i->next_invalid;
    }

    local_catalog->invalid_list = NULL;
}
Example #12
0
*/	static void Protect_Word(REBVAL *value, REBCNT flags)
/*
***********************************************************************/
{
	if (GET_FLAG(flags, PROT_WORD)) {
		if (GET_FLAG(flags, PROT_SET)) VAL_SET_OPT(value, OPTS_LOCK);
		else VAL_CLR_OPT(value, OPTS_LOCK);
	}

	if (GET_FLAG(flags, PROT_HIDE)) {
		if GET_FLAG(flags, PROT_SET) VAL_SET_OPT(value, OPTS_HIDE);
		else VAL_CLR_OPT(value, OPTS_HIDE);
	}
Example #13
0
/**
 * Get the flags associated with a format string
 * @param format The format string to search.
 * @param flags A pointer to flags that are turned on.
 * @return A pointer to the format string
 */
const char *_get_flags(const char *format, uchar *flags)
{
	uchar f;
	uchar done = 0;
	
	// start with no flags
	CLEAR_FLAGS(f, PRINTF_ALL);
	
	// skip past the % char
	++format;
	
	while(!done) {

		char ch = *format++;

		switch(ch) {
		case '-':
			// justify, overrides padding
			SET_FLAGS(f, PRINTF_JUSTIFY);
			CLEAR_FLAGS(f, PRINTF_PADDING);
			break;
		case '+':
			// sign, overrides space
			SET_FLAGS(f, PRINTF_SIGN);
			CLEAR_FLAGS(f, PRINTF_SPACE);
			break;
		case ' ':
			if(!GET_FLAG(f, PRINTF_SIGN)) {
				SET_FLAGS(f, PRINTF_SPACE);
			}
			break;
		case '#':
			SET_FLAGS(f, PRINTF_PREFIX);
			break;
		case '0':
			if(!GET_FLAG(f, PRINTF_JUSTIFY)) {
				SET_FLAGS(f, PRINTF_PADDING);
			}
			break;
		default:
			done = 1;
			--format;
		}
	}

	*flags = f;

	return format;
}
Example #14
0
*/	REBCNT Find_Str_Char(REBSER *ser, REBCNT head, REBCNT index, REBCNT tail, REBINT skip, REBUNI c2, REBCNT flags)
/*
**		General purpose find a char in a string.
**
**		Supports: forward/reverse with skip, cased/uncase, Unicode/byte.
**
**		Skip can be set positive or negative (for reverse).
**
**		Flags are set according to ALL_FIND_REFS
**
***********************************************************************/
{
	REBUNI c1;
	REBOOL uncase = !GET_FLAG(flags, ARG_FIND_CASE-1); // uncase = case insenstive

	if (uncase && c2 < UNICODE_CASES) c2 = LO_CASE(c2);

	for (; index >= head && index < tail; index += skip) {

		c1 = GET_ANY_CHAR(ser, index);
		if (uncase && c1 < UNICODE_CASES) c1 = LO_CASE(c1);

		if (c1 == c2) return index;

		if GET_FLAG(flags, ARG_FIND_MATCH-1) break;
	}

	return NOT_FOUND;
}
Example #15
0
*/	int OS_Quit_Devices(int flags)
/*
**		Terminate all devices in preparation to quit.
**
**		Allows devices to perform cleanup and resource freeing.
**
**		Set flags to zero for now. (May later be used to indicate
**		a device query check or a brute force quit.)
**
**		Returns: 0 for now.
**
***********************************************************************/
{
	int d;
	REBDEV *dev;

	for (d = RDI_MAX-1; d >= 0; d--) {
		dev = Devices[d];
		if (dev && GET_FLAG(dev->flags, RDF_INIT) && dev->commands[RDC_QUIT]) {
			dev->commands[RDC_QUIT]((REBREQ*)dev);
		}
	}

	return 0;
}
Example #16
0
int
process_output (DESCRIPTOR_DATA * t)
{
  char i[MAX_STRING_LENGTH + 1];

  if (!t->prompt_mode && !t->connected && t->edit_index == -1)
    if (write_to_descriptor (t, "\r\n") < 0)
      return (-1);

  /* Cycle thru output queue */
  while (get_from_q (&t->output, i))
    {
      if (t->snoop.snoop_by && t->snoop.snoop_by->desc != NULL
	  && !IS_NPC (t->snoop.snoop_by))
	{
	  write_to_q ("% ", &t->snoop.snoop_by->desc->output);
	  write_to_q (i, &t->snoop.snoop_by->desc->output);
	}
      if (write_to_descriptor (t, i))
	return (-1);
    }

  if (!t->connected && !(t->character && !IS_NPC (t->character) &&
			 GET_FLAG (t->character, FLAG_COMPACT)))
    if (IS_SET (t->edit_mode, MODE_DONE_EDITING) && t->edit_index == -1)
      if (write_to_descriptor (t, "\r\n") < 0)
	return (-1);

  return (1);
}
Example #17
0
//
//  Write_IO: C
//
// Low level "raw" standard output function.
//
// Allowed to restrict the write to a max OS buffer size.
//
// Returns the number of chars written.
//
DEVICE_CMD Write_IO(REBREQ *req)
{
    long total;

    if (GET_FLAG(req->modes, RDM_NULL)) {
        req->actual = req->length;
        return DR_DONE;
    }

    if (Std_Out >= 0) {

        total = write(Std_Out, req->common.data, req->length);

        if (total < 0) {
            req->error = errno;
            return DR_ERROR;
        }

        //if (GET_FLAG(req->flags, RRF_FLUSH)) {
        //FLUSH();
        //}

        req->actual = total;
    }

    if (Std_Echo) {
        fwrite(req->common.data, req->length, 1, Std_Echo);
        //fflush(Std_Echo); //slow!
    }

    return DR_DONE;
}
static void
update_sensitivity (void *unused, GtkWidget *dialog)
{
  TerminalSearchDialogPrivate *priv = TERMINAL_SEARCH_DIALOG_GET_PRIVATE (dialog);
  const gchar *search_string;
  gboolean valid;

  if (priv->regex) {
    g_regex_unref (priv->regex);
    priv->regex = NULL;
  }

  search_string = gtk_entry_get_text (GTK_ENTRY (priv->search_text_entry));
  g_return_if_fail (search_string != NULL);

  valid = *search_string != '\0';

  if (valid && GET_FLAG (regex_checkbutton)) {
    /* Check that the regex is valid */
    valid = NULL != terminal_search_dialog_get_regex (dialog);
    /* TODO show the error message somewhere */
  }

  gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT, valid);
}
Example #19
0
*/	DEVICE_CMD Read_File(REBREQ *file)
/*
***********************************************************************/
{
	if (GET_FLAG(file->modes, RFM_DIR)) {
		return Read_Directory(file, (REBREQ*)file->data);
	}

	if (!file->id) {
		file->error = -RFE_NO_HANDLE;
		return DR_ERROR;
	}

	if (file->modes & ((1 << RFM_SEEK) | (1 << RFM_RESEEK))) {
		CLR_FLAG(file->modes, RFM_RESEEK);
		if (!Seek_File_64(file)) return DR_ERROR;
	}

	// printf("read %d len %d\n", file->id, file->length);
	file->actual = read(file->id, file->data, file->length);
	if (file->actual < 0) {
		file->error = -RFE_BAD_READ;
		return DR_ERROR;
	} else {
		file->file.index += file->actual;
	}

	return DR_DONE;
}
Example #20
0
*/	REBCNT Find_Str_Bitset(REBSER *ser, REBCNT head, REBCNT index, REBCNT tail, REBINT skip, REBSER *bset, REBCNT flags)
/*
**		General purpose find a bitset char in a string.
**
**		Supports: forward/reverse with skip, cased/uncase, Unicode/byte.
**
**		Skip can be set positive or negative (for reverse).
**
**		Flags are set according to ALL_FIND_REFS
**
***********************************************************************/
{
	REBUNI c1;
	REBOOL uncase = !GET_FLAG(flags, ARG_FIND_CASE-1); // uncase = case insenstive

	for (; index >= head && index < tail; index += skip) {

		c1 = GET_ANY_CHAR(ser, index);

		//if (uncase && c1 < UNICODE_CASES) {
		//	if (Check_Bit(bset, LO_CASE(c1)) || Check_Bit(bset, UP_CASE(c1)))
		//		return index;
		//}
		//else
		if (Check_Bit(bset, c1, uncase)) return index;

		if (flags & AM_FIND_MATCH) break;
	}

	return NOT_FOUND;
}
Example #21
0
catalog_object_header * catalog_find_name(
        enum catalog_named_objects obj_type,
        const char * name)
{
    catalog_object_header * result = NULL;
    catalog_name_record * n = NULL;

    n = catalog_cachetree_find_name(obj_type, name);

    if (n != NULL) {
        if (n->name_deleted) { return NULL; }
        result = n->obj;
    }

    if (result == NULL) {
        xptr obj = catalog_nametree_find_name(CATALOG_NAME_TREE(obj_type), name);

        if (obj != XNULL) {
            result = catalog_acquire_object(obj);
            catalog_cachetree_add_name(obj_type, name, result);
        }
    } else if (GET_FLAG(result->flags, CAT_OBJECT_DELETED_FLAG)) {
        return NULL;
    }

    return result;
}
Example #22
0
*/	 DEVICE_CMD Close_Socket(REBREQ *sock)
/*
**		Close a socket.
**
**		Returns 0 on success.
**		On failure, error code is OS local.
**
***********************************************************************/
{
	sock->error = 0;

	if (GET_FLAG(sock->state, RSM_OPEN)) {

		sock->state = 0;  // clear: RSM_OPEN, RSM_CONNECT

		// If DNS pending, abort it:
		if (sock->net.host_info) {  // indicates DNS phase active
#ifdef HAS_ASYNC_DNS
			if (sock->handle) WSACancelAsyncRequest(sock->handle);
#endif
			OS_Free(sock->net.host_info);
			sock->socket = sock->length; // Restore TCP socket (see Lookup)
		}

		if (CLOSE_SOCKET(sock->socket)) {
			sock->error = GET_ERROR;
			return DR_ERROR;
		}
	}

	return DR_DONE;
}
Example #23
0
/*
 * Open disk cache file.
 */
int
DiskCacheOpen(
	FileInfo_t *file)
{
	int fd;

	/*
	 * If saved, restore open disk cache file descriptor.
	 * This occurs when processing multivolume.
	 */
	if (GET_FLAG(file->flags, FI_DCACHE) && file->dcache > 0) {

		fd = file->dcache;
		Trace(TR_FILES, "Restore disk cache fd: %d", fd);

	} else if (ifVerify(file) == B_TRUE) {

		fd = openVerify(file);
		Trace(TR_FILES, "Verify disk cache fd: %d", fd);

	} else {

		fd = openStage(file);
		Trace(TR_FILES, "Stage disk cache fd: %d", fd);
	}

	return (fd);
}
Example #24
0
/*
 * Is filesystem mounted.
 */
boolean_t
IsFileSystemMounted(
	equ_t eq)
{
	int i;
	struct sam_fs_status *fs;
	boolean_t mounted = B_FALSE;

	ReconfigLock();		/* wait on reconfig */

	for (i = 0; i < fileSystemTable.entries; i++) {
		fs = &fileSystemTable.data[i];

		if (fs->fs_eq == eq) {
			if (GET_FLAG(fs->fs_status, FS_MOUNTED)) {
				mounted = B_TRUE;

			} else {
				struct sam_fs_info fi;
				if (GetFsInfo(fs->fs_name, &fi) == -1) {
					WarnSyscallError(HERE, "GetFsInfo",
					    fs->fs_name);
				}
				if (fi.fi_status & FS_MOUNTED) {
					SET_FLAG(fs->fs_status, FS_MOUNTED);
					mounted = B_TRUE;
				}
			}
			break;
		}
	}
	ReconfigUnlock();		/* allow reconfig */

	return (mounted);
}
Example #25
0
File: p-file.c Project: 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);
}
Example #26
0
void OpenCLCommandQueue :: create(OpenCLContext &ctx, const OpenCLDevice &dev, bool ordered, bool profiling) {
	destroy();
	detach();
	
	cl_command_queue_properties properties = 0;
	if(profiling) {
		properties |= CL_QUEUE_PROFILING_ENABLE;
	}
	if(! ordered) {
		if(GET_FLAG(CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, dev.get_queue_properties())) {
			properties |= CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE;
		}
		else {
			opencl_error(USER_OPENCL_ERROR, "Device doesn't support out of order execution ... disabling");
		}
	}
	
	cl_int res = CL_SUCCESS;
	cl_command_queue command_queue = clCreateCommandQueue(
		ctx.get_context(),
		dev.get_device(),
		properties,
		&res
	);
	
	if(opencl_error(res, "clCreateCommandQueue error creating command queue")) {
		return;
	}
	
	mCommandQueue = command_queue;
	ctx.attach_resource(this);
}
GRegex *
terminal_search_dialog_get_regex (GtkWidget *dialog)
{
  TerminalSearchDialogPrivate *priv;
  GRegexCompileFlags compile_flags;
  const char *text, *pattern;

  g_return_val_if_fail (GTK_IS_DIALOG (dialog), NULL);

  priv = TERMINAL_SEARCH_DIALOG_GET_PRIVATE (dialog);
  g_return_val_if_fail (priv, NULL);

  pattern = text = terminal_search_dialog_get_search_text (dialog);

  compile_flags = G_REGEX_OPTIMIZE;

  if (!GET_FLAG (match_case_checkbutton))
    compile_flags |= G_REGEX_CASELESS;

  if (GET_FLAG (regex_checkbutton))
    compile_flags |= G_REGEX_MULTILINE;
  else
    pattern = g_regex_escape_string (text, -1);

  if (GET_FLAG (entire_word_checkbutton)) {
    const char *old_pattern = pattern;
    pattern = g_strdup_printf ("\\b%s\\b", pattern);
    if (old_pattern != text)
      g_free ((char *) old_pattern);
  }

  if (!priv->regex || priv->regex_compile_flags != compile_flags ||
      g_strcmp0 (pattern, g_regex_get_pattern (priv->regex)) != 0) {
    priv->regex_compile_flags = compile_flags;
    if (priv->regex)
      g_regex_unref (priv->regex);

    /* TODO Error handling */
    priv->regex = g_regex_new (pattern, compile_flags, 0, NULL);
  }

  if (pattern != text)
    g_free ((char *) pattern);

  return priv->regex;
}
Example #28
0
/*
 * Remove file with dcache opened from stream.
 * Caller must have the stream lock held.
 */
static void
removeDcachedFile(
	StreamInfo_t *stream,
	int error)
{
	int id;
	FileInfo_t *file, *prev = NULL;

	id = stream->first;
	while (id > EOS) {
		boolean_t removed = B_FALSE;

		file = GetFile(id);
		PthreadMutexLock(&file->mutex);

		if (prev != NULL) {
			PthreadMutexLock(&prev->mutex);
		}
		if (GET_FLAG(file->flags, FI_DCACHE)) {
			/*
			 * Remove file from stream.
			 * If multivolume and not section 0, set ECOMM to not
			 * retry from another copy.
			 */
			if (file->ar[file->copy].ext_ord != 0 ||
			    file->se_ord != 0) {
				file->error = ECOMM;
			} else {
				file->error = error;
			}
			SendErrorResponse(file);

			if (prev != NULL) {
				prev->next = file->next;
			} else {
				stream->first = file->next;
			}
			stream->count--;
			if (stream->first == EOS) {
				stream->last = EOS;
			} else if (file->sort == stream->last) {
				ASSERT(prev != NULL);
				stream->last = prev->sort;
			}
			removed = B_TRUE;
		}
		if (prev != NULL) {
			PthreadMutexUnlock(&prev->mutex);
		}
		PthreadMutexUnlock(&file->mutex);
		id = file->next;
		if (removed) {
			SetStageDone(file);
		} else {
			prev = file;
		}
	}
}
Example #29
0
*/	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;
}
TerminalSearchFlags
terminal_search_dialog_get_search_flags (GtkWidget *dialog)
{
  TerminalSearchDialogPrivate *priv;
  TerminalSearchFlags flags = 0;

  g_return_val_if_fail (GTK_IS_DIALOG (dialog), flags);

  priv = TERMINAL_SEARCH_DIALOG_GET_PRIVATE (dialog);
  g_return_val_if_fail (priv, flags);

  if (GET_FLAG (backwards_checkbutton))
    flags |= TERMINAL_SEARCH_FLAG_BACKWARDS;

  if (GET_FLAG (wrap_around_checkbutton))
    flags |= TERMINAL_SEARCH_FLAG_WRAP_AROUND;

  return flags;
}