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


C++ read_chars函数代码示例

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


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

示例1: g_read

static int g_read(lua_State *L, FILE *f, int first)
{
    int nargs = lua_gettop(L) - 1;
    int success;
    int n;
    clearerr(f);

    if(nargs == 0)     /* no arguments? */
    {
        success = read_line(L, f);
        n = first+1;  /* to return 1 result */
    }
    else    /* ensure stack space for all results and for auxlib's buffer */
    {
        luaL_checkstack(L, nargs+LUA_MINSTACK, "too many arguments");
        success = 1;

        for(n = first; nargs-- && success; n++)
        {
            if(lua_type(L, n) == LUA_TNUMBER)
            {
                size_t l = (size_t)lua_tointeger(L, n);
                success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l);
            }
            else
            {
                const char *p = lua_tostring(L, n);
                luaL_argcheck(L, p && p[0] == '*', n, "invalid option");

                switch(p[1])
                {
                case 'n':  /* number */
                    success = read_number(L, f);
                    break;
                case 'l':  /* line */
                    success = read_line(L, f);
                    break;
                case 'a':  /* file */
                    read_chars(L, f, ~((size_t)0));  /* read MAX_SIZE_T chars */
                    success = 1; /* always success */
                    break;
                default:
                    return luaL_argerror(L, n, "invalid format");
                }
            }
        }
    }

    if(ferror(f))
        return pushresult(L, 0, NULL);

    if(!success)
    {
        lua_pop(L, 1);  /* remove last result */
        lua_pushnil(L);  /* push nil instead */
    }

    return n - first;
}
开发者ID:Frankie-666,项目名称:farmanager,代码行数:59,代码来源:uliolib51.c

示例2: elua_read

static int
elua_read(lua_State *L)
{
   FILE *f   = tofile(L);
   int nargs = lua_gettop(L) - 1;
   int first = 2;
   int success, n;
   clearerr(f);
   if (!nargs)
     {
        success = read_line(L, f);
        n = first + 1;
     }
   else
     {
        luaL_checkstack(L, nargs + LUA_MINSTACK, "too many arguments");
        success = 1;
        for (n = first; nargs-- && success; ++n)
          {
             if (lua_type(L, n) == LUA_TNUMBER)
               {
                  size_t l = (size_t)lua_tointeger(L, n);
                  success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l);
               }
             else
               {
                  const char *p = lua_tostring(L, n);
                  luaL_argcheck(L, p && p[0] == '*', n, "invalid option");
                  switch (p[1])
                    {
                       case 'n':
                          success = read_number(L, f);
                          break;
                       case 'l':
                          success = read_line(L, f);
                          break;
                       case 'a':
                          read_chars(L, f, ~((size_t)0));
                          success = 1;
                          break;
                       default:
                          return luaL_argerror(L, n, "invalid format");
                    }
               }
          }
     }
   if (ferror(f))
      return push_ret(L, 0, NULL);
   if (!success)
     {
        lua_pop(L, 1);
        lua_pushnil(L);
     }
   return n - first;
}
开发者ID:Stefan-Schmidt,项目名称:efl,代码行数:55,代码来源:io.c

示例3: sgi_set_parttype

static int sgi_set_parttype(struct fdisk_context *cxt, int i,
			    struct fdisk_parttype *t)
{
	if (i >= partitions || !t || t->type > UINT32_MAX)
		return -EINVAL;

	if (sgi_get_num_sectors(cxt, i) == 0)	/* caught already before, ... */ {
		printf(_("Sorry, only for non-empty partitions you can change the tag.\n"));
		return -EINVAL;
	}

	if ((i == 10 && t->type != ENTIRE_DISK) || (i == 8 && t->type != 0))
		printf(_("Consider leaving partition 9 as volume header (0), "
			 "and partition 11 as entire volume (6), as IRIX "
			 "expects it.\n\n"));

	if (((t->type != ENTIRE_DISK) && (t->type != SGI_VOLHDR))
	    && (sgi_get_start_sector(cxt, i) < 1)) {
		read_chars(
			_("It is highly recommended that the partition at offset 0\n"
			  "is of type \"SGI volhdr\", the IRIX system will rely on it to\n"
			  "retrieve from its directory standalone tools like sash and fx.\n"
			  "Only the \"SGI volume\" entire disk section may violate this.\n"
			  "Type YES if you are sure about tagging this partition differently.\n"));
		if (strcmp (line_ptr, _("YES\n")))
			return 1;
	}
	sgilabel->partitions[i].id = SSWAP32(t->type);
	return 0;
}
开发者ID:dtrebbien,项目名称:util-linux,代码行数:30,代码来源:fdisksgilabel.c

示例4: memfile_read

static int
memfile_read (lua_State *L) {
    MemoryFile *f = luaL_checkudata(L, 1, MEMORYFILE_MT_NAME);
    int nargs = lua_gettop(L) - 1;
    int success;
    int n;

    if (nargs == 0) {   /* no arguments? */
        success = read_line(f, L);
        n = 3;          /* to return 1 result */
    }
    else {  /* ensure stack space for all results and for auxlib's buffer */
        luaL_checkstack(L, nargs + LUA_MINSTACK, "too many arguments");
        success = 1;
        for (n = 2; nargs-- && success; n++) {
            if (lua_type(L, n) == LUA_TNUMBER) {
                size_t l = (size_t) lua_tointeger(L, n);
                success = (l == 0) ? test_eof(f, L) : read_chars(f, L, l);
            }
            else {
                const char *p = lua_tostring(L, n);
                luaL_argcheck(L, p && p[0] == '*', n, "invalid option");
                switch (p[1]) {
                    case 'n':  /* number */
                        success = read_number(f, L);
                        break;
                    case 'l':  /* line */
                        success = read_line(f, L);
                        break;
                    case 'a':  /* all the rest of the file */
                        read_chars(f, L, ~((size_t)0)); /* MAX_SIZE_T bytes */
                        success = 1; /* always success */
                        break;
                    default:
                        return luaL_argerror(L, n, "invalid format");
                }
            }
        }
    }

    if (!success) {
        lua_pop(L, 1);      /* remove last result */
        lua_pushnil(L);     /* push nil instead */
    }

    return n - 2;
}
开发者ID:brkpt,项目名称:luaplus51-all,代码行数:47,代码来源:memoryfile.c

示例5: drop_chars

void
drop_chars (gint fd, gint count)
{
  gchar *buffer;

  buffer = read_chars (fd, count);
  flush_buffer (buffer);
}
开发者ID:BackupTheBerlios,项目名称:freenx-svn,代码行数:8,代码来源:thinnx.c

示例6: dos_new_partition

/*
 * Ask the user for new partition type information (logical, extended).
 * This function calls the actual partition adding logic - dos_add_partition.
 */
void dos_new_partition(struct fdisk_context *cxt)
{
	int i, free_primary = 0;

	for (i = 0; i < 4; i++)
		free_primary += !ptes[i].part_table->sys_ind;

	if (!free_primary && partitions >= MAXIMUM_PARTS) {
		printf(_("The maximum number of partitions has been created\n"));
		return;
	}

	if (!free_primary) {
		if (extended_offset) {
			printf(_("All primary partitions are in use\n"));
			add_logical(cxt);
		} else
			printf(_("If you want to create more than four partitions, you must replace a\n"
				 "primary partition with an extended partition first.\n"));
	} else if (partitions >= MAXIMUM_PARTS) {
		printf(_("All logical partitions are in use\n"));
		printf(_("Adding a primary partition\n"));
		dos_add_partition(cxt, get_partition(cxt, 0, 4), LINUX_NATIVE);
	} else {
		char c, dflt, line[LINE_LENGTH];

		dflt = (free_primary == 1 && !extended_offset) ? 'e' : 'p';
		snprintf(line, sizeof(line),
			 _("Partition type:\n"
			   "   p   primary (%d primary, %d extended, %d free)\n"
			   "%s\n"
			   "Select (default %c): "),
			 4 - (extended_offset ? 1 : 0) - free_primary, extended_offset ? 1 : 0, free_primary,
			 extended_offset ? _("   l   logical (numbered from 5)") : _("   e   extended"),
			 dflt);

		c = tolower(read_chars(line));
		if (c == '\n') {
			c = dflt;
			printf(_("Using default response %c\n"), c);
		}
		if (c == 'p') {
			int i = get_nonexisting_partition(cxt, 0, 4);
			if (i >= 0)
				dos_add_partition(cxt, i, LINUX_NATIVE);
			return;
		} else if (c == 'l' && extended_offset) {
			add_logical(cxt);
			return;
		} else if (c == 'e' && !extended_offset) {
			int i = get_nonexisting_partition(cxt, 0, 4);
			if (i >= 0)
				dos_add_partition(cxt, i, EXTENDED);
			return;
		} else
			printf(_("Invalid partition type `%c'\n"), c);
	}
}
开发者ID:dankamongmen,项目名称:util-linux,代码行数:62,代码来源:fdiskdoslabel.c

示例7: read_object_basic

int read_object_basic(FILE *fp, int *index, object *obj)
{
	int	i;
	char	str[10];
	
/* begin of object data */
	read_int(fp, index);  /* object # */
	
	read_chars(fp, obj->name, sizeof(obj->name));
	read_chars(fp, obj->description, sizeof(obj->description));
	for (i = 0; i != 3; i++)
		read_chars(fp, obj->key[i], sizeof(obj->key[i]));
	read_chars(fp, obj->use_output, sizeof(obj->use_output));
	read_long(fp, &obj->value);
	read_short(fp, &obj->weight);
	
	read_char(fp, &obj->type);
	read_char(fp, &obj->adjustment);
	
	read_short(fp, &obj->shotsmax);
	read_short(fp, &obj->shotscur);
	read_short(fp, &obj->ndice);
	read_short(fp, &obj->sdice);
	read_short(fp, &obj->pdice);
	
	read_char(fp, &obj->armor);
	read_char(fp, &obj->wearflag);
	read_char(fp, &obj->magicpower);
	read_char(fp, &obj->magicrealm);
	read_short(fp, &obj->special);
	read_chars(fp, obj->flags, sizeof(obj->flags));
	read_char(fp, &obj->questnum);
	read_char(fp,&obj->strength);
	read_char(fp,&obj->dexterity);
	read_char(fp,&obj->constitution);
	read_char(fp,&obj->intelligence);
	read_char(fp,&obj->piety);
	for (i = 0; i != 16; i++)
		read_short(fp, &obj->sets_flag[i]);
	read_short(fp,&obj->special1);
	read_long(fp,&obj->special2);
	
/* end of object data */
	return(0);
}
开发者ID:FuzzyHobbit,项目名称:mordor,代码行数:45,代码来源:ascii1.c

示例8: get_directory_entry

// grabs the 32 bytes for the file at (directory_clus, entry_num) and place it
// where ptr points to
int get_directory_entry(union directory_entry *ptr, unsigned int directory_clus, unsigned int entry_num) {
	unsigned int first_dir_clus, entry_first_byte_offset;
	first_dir_clus = get_first_sector_of_cluster(directory_clus);
	if ((entry_first_byte_offset = 32*entry_num) >= img_info.bytes_per_sec*img_info.sec_per_clus) {
		// bad offset
		return 0;
	}
	read_chars(ptr, entry_first_byte_offset + first_dir_clus*img_info.bytes_per_sec, sizeof(union directory_entry));
	return 1;
}
开发者ID:cop4610t-cool-group,项目名称:project3,代码行数:12,代码来源:file_types.c

示例9: icu_ufile_read

static int icu_ufile_read(lua_State *L) {
	int nargs = lua_gettop(L) - 1;
	int success;
	int n;
	UFILE* ufile = icu4lua_checkufile(L,1,UFILE_UV_META);
	if (nargs == 0) { // no arguments?
		success = read_line(L, ufile);
		n = 3; // to return 1 result
	}
	else {
		luaL_checkstack(L, nargs+LUA_MINSTACK, "too many arguments");
		success = 1;
		for (n = 2; nargs-- && success; n++) {
			if (lua_type(L,n) == LUA_TNUMBER) {
				int32_t l = (int32_t)lua_tointeger(L, n);
				success = (l == 0) ? test_eof(L, ufile) : read_chars(L, ufile, l);
			}
			else {
				const char* p = lua_tostring(L, n);
				luaL_argcheck(L, p && p[0] == '*', n, "invalid option");
				switch(p[1]) {
					case 'n': // number
						success = read_number(L, ufile);
						break;
					case 'l': // line
						success = read_line(L, ufile);
						break;
					case 'a': // file
						read_chars(L, ufile, INT32_MAX);
						success = 1;
						break;
					default:
						return luaL_argerror(L, n, "invalid format");
				}
			}
		}
	}
	if (!success) {
		lua_pop(L,1); // remove last result
		lua_pushnil(L); // push nil instead
	}
	return n - 2;
}
开发者ID:Chingliu,项目名称:icu4lua,代码行数:43,代码来源:icu.ufile.c

示例10: read_file

int read_file(union directory_entry *file, unsigned int position, unsigned int size) {
	unsigned int offset, bytes_left, cur_clus, bytes_per_clus, byte_position, nmemb;
	char *buffer;
	bytes_per_clus = img_info.bytes_per_sec*img_info.sec_per_clus;
	buffer = malloc(sizeof(char)*(bytes_per_clus));
	offset = position;
	bytes_left = size;
	cur_clus = get_file_cluster(file);
	while (offset > bytes_per_clus) {
		cur_clus = get_next_cluster_in_fat(cur_clus);
		if (end_of_chain(cur_clus)) {
			free(buffer);
			return 0;
		}
		offset -= bytes_per_clus;
	}
	byte_position = img_info.bytes_per_sec*get_first_sector_of_cluster(cur_clus) + offset;
	if (bytes_left > bytes_per_clus - offset) {
		nmemb = bytes_per_clus - offset;
	} else {
		nmemb = bytes_left;
	}
	read_chars(buffer, byte_position, nmemb);
	fwrite(buffer, sizeof(char), nmemb, stdout);
	bytes_left -= nmemb;
	while (bytes_left > 0) {
		cur_clus = get_next_cluster_in_fat(cur_clus);
		if (end_of_chain(cur_clus)) {
			free(buffer);
			return 0;
		}
		byte_position = img_info.bytes_per_sec*get_first_sector_of_cluster(cur_clus);
		if (bytes_left < bytes_per_clus) {
			nmemb = bytes_left;
		} else {
			nmemb = bytes_per_clus;
		}
		read_chars(buffer, byte_position, nmemb);
		fwrite(buffer, sizeof(char), nmemb, stdout);
		bytes_left -= nmemb;
	}
	return 1;
}
开发者ID:cop4610t-cool-group,项目名称:project3,代码行数:43,代码来源:file_types.c

示例11: proc

    // File Read Operatings {{{
    int LuaIOLib::g_read (lua_State *lua, FileHandle *file, int first) 
    {
        auto process = proc(lua);
        auto &vfs = process->vfs();

        int nargs = lua_gettop(lua) - 1;
        int success;
        int n;
        //clearerr(file);
        if (nargs == 0) {  /* no arguments? */
            success = read_line(lua, file, 1);
            n = first+1;  /* to return 1 result */
        }
        else {  /* ensure stack space for all results and for auxlib's buffer */
            luaL_checkstack(lua, nargs+LUA_MINSTACK, "too many arguments");
            success = 1;
            for (n = first; nargs-- && success; n++) {
                if (lua_type(lua, n) == LUA_TNUMBER) {
                    size_t l = (size_t)lua_tointeger(lua, n);
                    success = (l == 0) ? file->at_end_of_stream() : read_chars(lua, file, l);
                }
                else {
                    const char *p = lua_tostring(lua, n);
                    luaL_argcheck(lua, p && p[0] == '*', n, "invalid option");
                    switch (p[1]) {
                        case 'n':  /* number */
                            success = read_number(lua, file);
                            break;
                        case 'l':  /* line */
                            success = read_line(lua, file, 1);
                            break;
                        case 'L':  /* line with end-of-line */
                            success = read_line(lua, file, 0);
                            break;
                        case 'a':  /* file */
                            read_all(lua, file);  /* read entire file */
                            success = 1; /* always success */
                            break;
                        default:
                            return luaL_argerror(lua, n, "invalid format");
                    }
                }
            }
        }
        /*
        if (ferror(file))
            return luaL_fileresult(lua, 0, NULL);
            */
        if (!success) {
            lua_pop(lua, 1);  /* remove last result */
            lua_pushnil(lua);  /* push nil instead */
        }
        return n - first;
    }
开发者ID:astrellon,项目名称:loss,代码行数:55,代码来源:lua_iolib.cpp

示例12: get_next_directory_entry

int get_next_directory_entry(union directory_entry *ptr, unsigned int directory_clus, unsigned int entry_num) {
	unsigned int first_dir_clus, entry_first_byte_offset, next_num;
	next_num = entry_num + 1;
	if ((entry_first_byte_offset = 32*next_num) >= img_info.bytes_per_sec*img_info.sec_per_clus) {
		first_dir_clus = get_first_sector_of_cluster(get_next_cluster_in_fat(directory_clus));
		entry_first_byte_offset -= img_info.bytes_per_sec*img_info.sec_per_clus;
	} else {
		first_dir_clus = get_first_sector_of_cluster(directory_clus);
	}
	read_chars(ptr, entry_first_byte_offset + first_dir_clus*img_info.bytes_per_sec, sizeof(union directory_entry));
	return 1;
}
开发者ID:cop4610t-cool-group,项目名称:project3,代码行数:12,代码来源:file_types.c

示例13: io_read

static int io_read (lua_State *L) {
  IOCtrl *ctrl = (IOCtrl *)lua_touserdata(L, -1);
  int lastarg = lua_gettop(L) - 1;
  int firstarg = 1;
  FILE *f = gethandle(L, ctrl, firstarg);
  int n;
  if (f) firstarg++;
  else f = getfilebyref(L, ctrl, INFILE);  /* get _INPUT */
  lua_pop(L, 1);
  if (firstarg > lastarg) {  /* no arguments? */
    lua_settop(L, 0);  /* erase upvalue and other eventual garbage */
    firstarg = lastarg = 1;  /* correct indices */
    lua_pushstring(L, "*l");  /* push default argument */
  }
  else  /* ensure stack space for all results and for auxlib's buffer */
    luaL_checkstack(L, lastarg-firstarg+1+LUA_MINSTACK, "too many arguments");
  for (n = firstarg; n<=lastarg; n++) {
    int success;
    if (lua_isnumber(L, n))
      success = read_chars(L, f, (size_t)Re(lua_tonumber(L, n)));
    else {
      const char *p = luaL_check_string(L, n);
      if (p[0] != '*')
        success = read_pattern(L, f, p);  /* deprecated! */
      else {
        switch (p[1]) {
          case 'n':  /* number */
            if (!read_number(L, f)) goto endloop;  /* read fails */
            continue;  /* number is already pushed; avoid the "pushstring" */
          case 'l':  /* line */
            success = read_line(L, f);
            break;
          case 'a':  /* file */
            read_file(L, f);
            success = 1; /* always success */
            break;
          case 'w':  /* word */
            success = read_word(L, f);
            break;
          default:
            luaL_argerror(L, n, "invalid format");
            success = 0;  /* to avoid warnings */
        }
      }
    }
    if (!success) {
      lua_pop(L, 1);  /* remove last result */
      break;  /* read fails */
    }
  } endloop:
  return n - firstarg;
}
开发者ID:philm001,项目名称:Omni-FEM,代码行数:52,代码来源:liolib.cpp

示例14: read_db

void read_db() {
#ifdef DEBUG_VALUE
    //char cur_dir[256];
    //GetCurrentDirectory(256, cur_dir);
    //printf("in read_db(): %s\n", cur_dir);
#endif
    GLint charsRead = read_chars();
    GLint mapsRead = read_maps();
    GLint itemsRead = read_items();

    if (charsRead || mapsRead || itemsRead) {
        exit_glut("Error reading database!");
    }
}
开发者ID:cloverhap,项目名称:mapplus,代码行数:14,代码来源:database.cpp

示例15: put_handler

boolean put_handler(MiniWebServer& web_server) {
    web_server.send_error_code(200);
    web_server.end_headers();

    const char* length_str = web_server.get_header_value("Content-Length");
    long length = atol(length_str);
    uint32_t start_time = 0;
    boolean watchdog_start = false;

    EthernetClient client = web_server.get_client();

    if (put_handler_fn) {
        (*put_handler_fn)(web_server, START, NULL, length);
    }

    uint32_t i;
    for (i = 0; i < length && client.connected();) {
        int16_t size = read_chars(web_server, client, (uint8_t*)buffer, 64);
        if (!size) {
            if (watchdog_start) {
                if (millis() - start_time > 30000) {
                    // Exit if there has been zero data from connected client
                    // for more than 30 seconds.
#if DEBUG
                    Serial << F("TWS:There has been no data for >30 Sec.\n");
#endif
                    break;
                }
            } else {
                // We have hit an empty buffer, start the watchdog.
                start_time = millis();
                watchdog_start = true;
            }
            continue;
        }
        i += size;
        // Ensure we re-start the watchdog if we get ANY data input.
        watchdog_start = false;

        if (put_handler_fn) {
            (*put_handler_fn)(web_server, WRITE, buffer, size);
        }
    }
    if (put_handler_fn) {
        (*put_handler_fn)(web_server, END, NULL, 0);
    }

    return true;
}
开发者ID:masgari,项目名称:MiniWebServer,代码行数:49,代码来源:MiniWebServer.cpp


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