当前位置: 首页>>代码示例>>C++>>正文


C++ write_loop函数代码示例

本文整理汇总了C++中write_loop函数的典型用法代码示例。如果您正苦于以下问题:C++ write_loop函数的具体用法?C++ write_loop怎么用?C++ write_loop使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了write_loop函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: move_cursor

int	move_cursor(int fildes, int num_up, int num_left)
{
	int	ret;

	if (num_up < 0)
	{
		ret = write_loop (fildes, (unsigned char *)CURSOR_DOWN, -num_up);
		if (0 > ret)
			return -1;
	} else if (num_up > 0)
	{
		ret = write_loop (fildes, (unsigned char *)CURSOR_UP, num_up);
		if (0 > ret)
			return -1;
	}

	if (num_left < 0)
	{
		ret = write_loop(fildes, (unsigned char *)CURSOR_RIGHT, -num_left);
		if (0 > ret)
			return -1;
	} else if (num_left > 0)
	{
		ret = write_loop(fildes, (unsigned char *)CURSOR_LEFT, num_left);
		if (0 > ret)
			return -1;
	}
	return 0;
}
开发者ID:CeperaCPP,项目名称:fis-gtm,代码行数:29,代码来源:iott_edit.c

示例2: html_error_real

int html_error_real(const char *file, unsigned int lineno, const char *msg)
{
	char loc[128];
	char *msgt;
	const char *prefix = "The request has failed: ";

	if (!msg)
		msg = "Internal server error";

	const char *p = getenv("SERVER_PROTOCOL");
	if (!p || strcmp(p, "INCLUDED"))
		msgt = concat("Status: 404 Not Found\nContent-Type: text/plain\n\n", prefix, msg, "\n", NULL);
	else if (html_flags & HTML_HEADER)
		msgt = concat("\n<title>", prefix, msg, "</title>\n"
		    "<meta name=\"robots\" content=\"noindex\">\n", NULL);
	else
		msgt = concat("\n<p>", prefix, msg, "\n", footer, NULL);

	write_loop(STDOUT_FILENO, msgt, strlen(msgt));
	free(msgt);

	snprintf(loc, sizeof(loc), " (%s:%u)", file, lineno);
	msgt = concat("The request has failed: ", msg, loc, "\n", NULL);
	write_loop(STDERR_FILENO, msgt, strlen(msgt));
	free(msgt);

	return 1;
}
开发者ID:aabc,项目名称:blists,代码行数:28,代码来源:html.c

示例3: move_cursor_right

int 	move_cursor_right(int col, int num_cols)
{
	/* -------------------------------------------------------
	 *	moves cursor right by num_cols columns, if col is rightmost,
	 *	then it goes to the start of the next line
	 *	returns 0 if success, != 0 if error
	 * -------------------------------------------------------
	 */
	int	fildes = ((d_tt_struct *)((io_curr_device.in)->dev_sp))->fildes;
	int	ret;
	io_desc *io_ptr = io_curr_device.in;

	if (0 == num_cols)
		ret = 0;
	else if (0 > num_cols)
		ret = move_cursor_left(col, -num_cols);
	else if ((io_curr_device.in->width - num_cols) > col)
		ret = write_loop(fildes, (unsigned char *)CURSOR_RIGHT, num_cols);
	else
	{
		DOWRITERC(fildes, NATIVE_TTEOL, strlen(NATIVE_TTEOL), ret);
		if (0 > ret)
			return -1;
		num_cols -= (io_curr_device.in->width - col);
		if (num_cols)
			ret = write_loop(fildes, (unsigned char *)CURSOR_RIGHT, num_cols);
	}
	return ret;
}
开发者ID:CeperaCPP,项目名称:fis-gtm,代码行数:29,代码来源:iott_edit.c

示例4: move_cursor_left

int 	move_cursor_left(int col, int num_cols)
{
	/* -------------------------------------------------------
	 *  moves cursor left by num_cols columns.  if col is leftmost,
	 *  then it goes back to the end of the previous line
	 *  returns 0 if success, != 0 if error
	 * -------------------------------------------------------
	 */
	int	fildes = ((d_tt_struct *)((io_curr_device.in)->dev_sp))->fildes;
	int	ret;

	if (0 == num_cols)
		ret = 0;
	else if (0 > num_cols)
		ret = move_cursor_right(col, -num_cols);
	else if (0 < col)
	{
		ret = write_loop(fildes, (unsigned char *)CURSOR_LEFT, MIN(col, num_cols));
		num_cols -= MIN(col, num_cols);
		if (num_cols)
		{
			DOWRITERC(fildes, CURSOR_UP, strlen(CURSOR_UP), ret);
			if (0 > ret)
				return -1;
			ret = write_loop(fildes, (unsigned char *)CURSOR_RIGHT, io_curr_device.in->width - num_cols);
		}
	} else
	{
		DOWRITERC(fildes, CURSOR_UP, strlen(CURSOR_UP), ret);
		if (0 > ret)
			return -1;
		ret = write_loop(fildes, (unsigned char *)CURSOR_RIGHT, io_curr_device.in->width - num_cols);
	}
	return ret;
}
开发者ID:CeperaCPP,项目名称:fis-gtm,代码行数:35,代码来源:iott_edit.c

示例5: test_stuff

static bool test_stuff(screen_t *scr)
{
    data_buffer_t output;
    scoped_buffer_t scoped_buffer(&output);

    s_move(scr, &output, 0, 0);
    int screen_width = common_get_width();

    const wchar_t *left = L"left";
    const wchar_t *right = L"right";

    for (size_t idx = 0; idx < 80; idx++)
    {
        output.push_back('A');
    }

    if (! output.empty())
    {
        write_loop(STDOUT_FILENO, &output.at(0), output.size());
        output.clear();
    }

    sleep(5);

    for (size_t i=0; i < 1; i++)
    {
        writembs(cursor_left);
    }

    if (! output.empty())
    {
        write_loop(1, &output.at(0), output.size());
        output.clear();
    }



    while (1)
    {
        int c = getchar();
        if (c != EOF) break;
    }


    while (1)
    {
        int c = getchar();
        if (c != EOF) break;
    }
    puts("Bye");
    exit(0);
    while (1) sleep(10000);
    return true;
}
开发者ID:AlexShiLucky,项目名称:fish-shell,代码行数:54,代码来源:screen.cpp

示例6: write_statements

static void
write_statements(tree *statements)
{
  tree *list;
  tree *statement;

  list = statements;
  assert(list->tag == node_list);
  while(list) {
    statement = HEAD(list);
    switch(statement->tag) {
    case node_call:
      write_call(statement);
      break;
    case node_cond:
      write_cond(statement);  
      break;
    case node_loop:
      write_loop(statement);
      break; 
    default:
      write_expression(statement);
    }
    list = TAIL(list);
  }

}
开发者ID:jdelgadoalfonso,项目名称:gputils,代码行数:27,代码来源:codegen.c

示例7: s_check_status

static void s_check_status( screen_t *s)
{
	fflush( stdout );
	fflush( stderr );

	fstat( 1, &s->post_buff_1 );
	fstat( 2, &s->post_buff_2 );

	int changed = ( s->prev_buff_1.st_mtime != s->post_buff_1.st_mtime ) ||
		( s->prev_buff_2.st_mtime != s->post_buff_2.st_mtime );

	if (room_for_usec( &s->post_buff_1))
	{
		changed = changed || ( (&s->prev_buff_1.st_mtime)[1] != (&s->post_buff_1.st_mtime)[1] ) ||
			( (&s->prev_buff_2.st_mtime)[1] != (&s->post_buff_2.st_mtime)[1] );
	}

	if( changed )
	{
		/*
		  Ok, someone has been messing with our screen. We will want
		  to repaint. However, we do not know where the cursor is. It
		  is our best bet that we are still on the same line, so we
		  move to the beginning of the line, reset the modelled screen
		  contents, and then set the modeled cursor y-pos to its
		  earlier value.
		*/

		int prev_line = s->actual_cursor[1];
		write_loop( 1, "\r", 1 );
		s_reset( s, 0 );
		s->actual_cursor[1] = prev_line;
	}
}
开发者ID:brentdax,项目名称:fishfish,代码行数:34,代码来源:screen.c

示例8: load_or_save_variables_at_path

/**
   Load or save all variables
*/
static bool load_or_save_variables_at_path(bool save, const std::string &path)
{
    bool result = false;

    debug(4, L"Open file for %s: '%s'",
          save?"saving":"loading",
          path.c_str());

    /* OK to not use CLO_EXEC here because fishd is single threaded */
    int fd = open(path.c_str(), save?(O_CREAT | O_TRUNC | O_WRONLY):O_RDONLY, 0600);
    if (fd >= 0)
    {
        /* Success */
        result = true;
        connection_t c(fd);

        if (save)
        {
            /* Save to the file */
            write_loop(c.fd, SAVE_MSG, strlen(SAVE_MSG));
            enqueue_all(&c);
        }
        else
        {
            /* Read from the file */
            read_message(&c);
        }

        connection_destroy(&c);
    }
    return result;
}
开发者ID:jay2013,项目名称:fish-shell,代码行数:35,代码来源:fishd.cpp

示例9: s_check_status

/// Stat stdout and stderr and compare result to previous result in reader_save_status. Repaint if
/// modification time has changed.
///
/// Unfortunately, for some reason this call seems to give a lot of false positives, at least under
/// Linux.
static void s_check_status(screen_t *s) {
    fflush(stdout);
    fflush(stderr);

    fstat(1, &s->post_buff_1);
    fstat(2, &s->post_buff_2);

    int changed = (s->prev_buff_1.st_mtime != s->post_buff_1.st_mtime) ||
                  (s->prev_buff_2.st_mtime != s->post_buff_2.st_mtime);

#if defined HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC
    changed = changed ||
              s->prev_buff_1.st_mtimespec.tv_nsec != s->post_buff_1.st_mtimespec.tv_nsec ||
              s->prev_buff_2.st_mtimespec.tv_nsec != s->post_buff_2.st_mtimespec.tv_nsec;
#elif defined HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
    changed = changed || s->prev_buff_1.st_mtim.tv_nsec != s->post_buff_1.st_mtim.tv_nsec ||
              s->prev_buff_2.st_mtim.tv_nsec != s->post_buff_2.st_mtim.tv_nsec;
#endif

    if (changed) {
        // Ok, someone has been messing with our screen. We will want to repaint. However, we do not
        // know where the cursor is. It is our best bet that we are still on the same line, so we
        // move to the beginning of the line, reset the modelled screen contents, and then set the
        // modeled cursor y-pos to its earlier value.
        int prev_line = s->actual.cursor.y;
        write_loop(STDOUT_FILENO, "\r", 1);
        s_reset(s, screen_reset_current_line_and_prompt);
        s->actual.cursor.y = prev_line;
    }
}
开发者ID:AlexShiLucky,项目名称:fish-shell,代码行数:35,代码来源:screen.cpp

示例10: iothread_perform_on_main

void iothread_perform_on_main(void_function_t &&func) {
    if (is_main_thread()) {
        func();
        return;
    }

    // Make a new request. Note we are synchronous, so this can be stack allocated!
    main_thread_request_t req(std::move(func));

    // Append it. Do not delete the nested scope as it is crucial to the proper functioning of this
    // code by virtue of the lock management.
    {
        scoped_lock queue_lock(s_main_thread_request_q_lock);
        s_main_thread_request_queue.push(&req);
    }

    // Tell the pipe.
    const char wakeup_byte = IO_SERVICE_MAIN_THREAD_REQUEST_QUEUE;
    assert_with_errno(write_loop(s_write_pipe, &wakeup_byte, sizeof wakeup_byte) != -1);

    // Wait on the condition, until we're done.
    std::unique_lock<std::mutex> perform_lock(s_main_thread_performer_lock);
    while (!req.done) {
        // It would be nice to support checking for cancellation here, but the clients need a
        // deterministic way to clean up to avoid leaks
        s_main_thread_performer_cond.wait(perform_lock);
    }

    // Ok, the request must now be done.
    assert(req.done);
}
开发者ID:ArkBriar,项目名称:fish-shell,代码行数:31,代码来源:iothread.cpp

示例11: pager_flush

/**
   Flush \c pager_buffer to stdout
*/
static void pager_flush()
{
    if (! pager_buffer.empty()) {
        write_loop( 1, & pager_buffer.at(0), pager_buffer.size() * sizeof(char) );
        pager_buffer.clear();
    }
}
开发者ID:anbotero,项目名称:fish-shell,代码行数:10,代码来源:fish_pager.cpp

示例12: UNUSED

/// The function that does thread work.
static void *iothread_worker(void *unused) {
    UNUSED(unused);
    struct spawn_request_t req;
    while (dequeue_spawn_request(&req)) {
        debug(5, "pthread %p dequeued", this_thread());

        // Perform the work
        req.handler();

        // If there's a completion handler, we have to enqueue it on the result queue.
        // Note we're using std::function's weirdo operator== here
        if (req.completion != nullptr) {
            // Enqueue the result, and tell the main thread about it.
            enqueue_thread_result(std::move(req));
            const char wakeup_byte = IO_SERVICE_RESULT_QUEUE;
            assert_with_errno(write_loop(s_write_pipe, &wakeup_byte, sizeof wakeup_byte) != -1);
        }
    }

    // We believe we have exhausted the thread request queue. We want to decrement
    // thread_count and exit. But it's possible that a request just came in. Furthermore,
    // it's possible that the main thread saw that thread_count is full, and decided to not
    // spawn a new thread, trusting in one of the existing threads to handle it. But we've already
    // committed to not handling anything else. Therefore, we have to decrement
    // the thread count under the lock, which we still hold. Likewise, the main thread must
    // check the value under the lock.
    int new_thread_count = --s_spawn_requests.acquire().value.thread_count;
    assert(new_thread_count >= 0);

    debug(5, "pthread %p exiting", this_thread());
    // We're done.
    return NULL;
}
开发者ID:ArkBriar,项目名称:fish-shell,代码行数:34,代码来源:iothread.cpp

示例13: my_list

void my_list(int data_conn_sock ,char *filepath)
{
	char mymode[11]= "----------";
	struct stat buf;
	struct dirent *p = NULL;
	struct passwd *passwd;	
	char uname[50];
	char gname[50];
	char mtime[50];
	DIR *mydir =  NULL;
	char buffer[100];

	chdir(filepath);
	mydir = opendir(filepath);

	while( (p = readdir(mydir)) != NULL )
	{		
		memset( &buf, 0, sizeof(buf));
		stat(p->d_name,&buf);
		
		getFileMode(buf.st_mode, mymode);
		getUserName(buf.st_uid, uname);
		getGroupName(buf.st_gid, gname);
		getTime(buf.st_mtime, mtime);

		sprintf(buffer,"%s %d %s %s %10d %s %s\r\n", mymode, buf.st_nlink, uname, gname, buf.st_size, mtime, p->d_name);
		if (data_conn_sock != 0)
		{			
			write_loop(data_conn_sock, buffer, strlen(buffer));
		}
	}

	closedir(mydir);
}
开发者ID:Lellansin,项目名称:SimpleFtp,代码行数:34,代码来源:list.c

示例14: exec_write_and_exit

/// Called in a forked child.
static void exec_write_and_exit(int fd, const char *buff, size_t count, int status) {
    if (write_loop(fd, buff, count) == -1) {
        debug(0, WRITE_ERROR);
        wperror(L"write");
        exit_without_destructors(status);
    }
    exit_without_destructors(status);
}
开发者ID:moverest,项目名称:fish-shell,代码行数:9,代码来源:exec.cpp

示例15: print_help

void print_help(const char *c, int fd) {
    char cmd[CMD_LEN];
    int printed = snprintf(cmd, CMD_LEN, "fish -c '__fish_print_help %s >&%d'", c, fd);

    if (printed < CMD_LEN && system(cmd) == -1) {
        write_loop(2, HELP_ERR, strlen(HELP_ERR));
    }
}
开发者ID:ArkBriar,项目名称:fish-shell,代码行数:8,代码来源:print_help.cpp


注:本文中的write_loop函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。