本文整理汇总了C++中read_string函数 的典型用法代码示例。如果您正苦于以下问题:C++ read_string函数的具体用法?C++ read_string怎么用?C++ read_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了read_string函数 的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: hcache_readfile
void
hcache_readfile(HCACHEFILE *file)
{
HCACHEDATA cachedata, *c, *last = 0;
FILE *f;
int bad_cache = 1, ch;
const char *version;
BUFFER buff;
long buffsize;
/* if( ! (hcachename = hcache_filename()) )
return;*/
if( ! (f = fopen( file->cachefilename, "rb" )) )
return;
fseek( f, 0, SEEK_END );
buffsize = ftell( f );
fseek( f, 0, SEEK_SET );
buffer_init( &buff );
buffer_resize( &buff, buffsize + 1 );
if ( fread( buffer_ptr( &buff ), buffsize, 1, f ) != 1 )
{
fclose( f );
goto bail;
}
buffer_ptr( &buff )[buffsize] = 0;
fclose( f );
version = read_string( &buff );
ch = buffer_getchar( &buff );
if (!version || strcmp( version, CACHE_FILE_VERSION ) || ch != '\n' ) {
goto bail;
}
for(;;) {
int i, count, ch;
LIST *l;
c = &cachedata;
c->boundname = read_string( &buff );
if( !c->boundname ) /* Test for eof */
break;
c->time = read_int( &buff );
c->age = read_int( &buff ) + 1; /* we're getting older... */
#ifdef OPT_BUILTIN_MD5CACHE_EXT
c->mtime = read_int( &buff );
read_md5sum( &buff, c->rulemd5sum );
memcpy( &c->currentrulemd5sum, &c->rulemd5sum, MD5_SUMSIZE );
read_md5sum( &buff, c->contentmd5sum );
memcpy( &c->currentcontentmd5sum, &c->contentmd5sum, MD5_SUMSIZE );
#endif
if( !c->boundname )
goto bail;
/* headers */
count = read_int( &buff );
for( l = 0, i = 0; i < count; ++i ) {
const char *s = read_string( &buff );
if( !s )
goto bail;
l = list_append( l, s, 0 );
}
c->includes = l;
/* hdrscan */
count = read_int( &buff );
for( l = 0, i = 0; i < count; ++i ) {
const char *s = read_string( &buff );
if( !s )
goto bail;
l = list_append( l, s, 0 );
}
c->hdrscan = l;
/* Read the newline */
ch = skip_spaces( &buff );
if( ch != '!' )
goto bail;
ch = skip_spaces( &buff );
if( ch != '\n' )
goto bail;
if( !hashenter( file->hcachehash, (HASHDATA **)&c ) ) {
printf( "jam: can't insert header cache item, bailing on %s\n",
file->cachefilename );
goto bail;
}
c->next = 0;
if( last )
last->next = c;
else
file->hcachelist = c;
last = c;
}
//.........这里部分代码省略.........
开发者ID:brkpt, 项目名称:jamplus, 代码行数:101, 代码来源:hcache.c
示例2: bdecode_recursive
//.........这里部分代码省略.........
#endif
return;
}
if (in == end)
{
err = true;
#ifdef TORRENT_DEBUG
ret.m_type_queried = false;
#endif
return;
}
}
#ifdef TORRENT_DEBUG
ret.m_type_queried = false;
#endif
TORRENT_ASSERT(*in == 'e');
++in; // 'e'
} break;
// ----------------------------------------------
// dictionary
case 'd':
{
ret = entry(entry::dictionary_t);
++in; // 'd'
while (*in != 'e')
{
entry key;
bdecode_recursive(in, end, key, err, depth + 1);
if (err || key.type() != entry::string_t)
{
#ifdef TORRENT_DEBUG
ret.m_type_queried = false;
#endif
return;
}
entry& e = ret[key.string()];
bdecode_recursive(in, end, e, err, depth + 1);
if (err)
{
#ifdef TORRENT_DEBUG
ret.m_type_queried = false;
#endif
return;
}
if (in == end)
{
err = true;
#ifdef TORRENT_DEBUG
ret.m_type_queried = false;
#endif
return;
}
}
#ifdef TORRENT_DEBUG
ret.m_type_queried = false;
#endif
TORRENT_ASSERT(*in == 'e');
++in; // 'e'
} break;
// ----------------------------------------------
// string
default:
if (is_digit((unsigned char)*in))
{
std::string len_s = read_until(in, end, ':', err);
if (err)
{
#ifdef TORRENT_DEBUG
ret.m_type_queried = false;
#endif
return;
}
TORRENT_ASSERT(*in == ':');
++in; // ':'
int len = atoi(len_s.c_str());
ret = entry(entry::string_t);
read_string(in, end, len, ret.string(), err);
if (err)
{
#ifdef TORRENT_DEBUG
ret.m_type_queried = false;
#endif
return;
}
}
else
{
err = true;
#ifdef TORRENT_DEBUG
ret.m_type_queried = false;
#endif
return;
}
#ifdef TORRENT_DEBUG
ret.m_type_queried = false;
#endif
}
}
开发者ID:andreicristianpetcu, 项目名称:popcorn-time, 代码行数:101, 代码来源:bencode.hpp
示例3: llex
static int llex(LexState *ls, SemInfo *seminfo) {
luaZ_resetbuffer(ls->buff);
for (;;) {
switch (ls->current) {
case '\n': case '\r': { /* line breaks */
inclinenumber(ls);
break;
}
case ' ': case '\f': case '\t': case '\v': { /* spaces */
next(ls);
break;
}
case '-': { /* '-' or '--' (comment) */
next(ls);
if (ls->current != '-') return '-';
/* else is a comment */
next(ls);
if (ls->current == '[') { /* long comment? */
int sep = skip_sep(ls);
luaZ_resetbuffer(ls->buff); /* 'skip_sep' may dirty the buffer */
if (sep >= 0) {
read_long_string(ls, NULL, sep); /* skip long comment */
luaZ_resetbuffer(ls->buff); /* previous call may dirty the buff. */
break;
}
}
/* else short comment */
while (!currIsNewline(ls) && ls->current != EOZ)
next(ls); /* skip until end of line (or end of file) */
break;
}
case '[': { /* long string or simply '[' */
int sep = skip_sep(ls);
if (sep >= 0) {
read_long_string(ls, seminfo, sep);
return TK_STRING;
}
else if (sep != -1) /* '[=...' missing second bracket */
lexerror(ls, "invalid long string delimiter", TK_STRING);
return '[';
}
case '=': {
next(ls);
if (check_next1(ls, '=')) return TK_EQ;
else return '=';
}
case '<': {
next(ls);
if (check_next1(ls, '=')) return TK_LE;
else if (check_next1(ls, '<')) return TK_SHL;
else return '<';
}
case '>': {
next(ls);
if (check_next1(ls, '=')) return TK_GE;
else if (check_next1(ls, '>')) return TK_SHR;
else return '>';
}
case '/': {
next(ls);
if (check_next1(ls, '/')) return TK_IDIV;
else return '/';
}
case '~': {
next(ls);
if (check_next1(ls, '=')) return TK_NE;
else return '~';
}
case ':': {
next(ls);
if (check_next1(ls, ':')) return TK_DBCOLON;
else return ':';
}
case '"': case '\'': { /* short literal strings */
read_string(ls, ls->current, seminfo);
return TK_STRING;
}
case '.': { /* '.', '..', '...', or number */
save_and_next(ls);
if (check_next1(ls, '.')) {
if (check_next1(ls, '.'))
return TK_DOTS; /* '...' */
else return TK_CONCAT; /* '..' */
}
else if (!lisdigit(ls->current)) return '.';
else return read_numeral(ls, seminfo);
}
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9': {
return read_numeral(ls, seminfo);
}
case EOZ: {
return TK_EOS;
}
default: {
if (lislalpha(ls->current)) { /* identifier or reserved word? */
TString *ts;
do {
save_and_next(ls);
} while (lislalnum(ls->current));
//.........这里部分代码省略.........
开发者ID:MORTAL2000, 项目名称:Cendric2, 代码行数:101, 代码来源:llex.c
示例4: process_fields
static const char*
process_fields(lsb_heka_field *f, const char *p, const char *e)
{
int tag = 0;
int wiretype = 0;
long long vi = 0;
p = lsb_pb_read_varint(p, e, &vi);
if (!p || vi < 0 || p + vi > e) {
return NULL;
}
e = p + vi; // only process to the end of the current field record
do {
p = lsb_pb_read_key(p, &tag, &wiretype);
switch (tag) {
case LSB_PB_NAME:
p = read_string(wiretype, p, e, &f->name);
break;
case LSB_PB_VALUE_TYPE:
p = process_varint(wiretype, p, e, &vi);
if (p) {
f->value_type = (int)vi;
}
break;
case LSB_PB_REPRESENTATION:
p = read_string(wiretype, p, e, &f->representation);
break;
// don't bother with the value(s) until we actually need them
// since this stream is created by Hindsight
// - tags are guaranteed to be properly ordered (values at the end)
// - there won't be repeated tags for packed values
case LSB_PB_VALUE_STRING:
case LSB_PB_VALUE_BYTES:
if (wiretype != 2) {
p = NULL;
break;
}
f->value.s = p - 1;
f->value.len = e - f->value.s;
p = e;
break;
case LSB_PB_VALUE_INTEGER:
case LSB_PB_VALUE_BOOL:
if (wiretype != 0 && wiretype != 2) {
p = NULL;
break;
}
// fall thru
case LSB_PB_VALUE_DOUBLE:
if (tag == 7 && wiretype != 1 && wiretype != 2) {
p = NULL;
break;
}
if (wiretype == 2) {
p = lsb_pb_read_varint(p, e, &vi);
if (!p || vi < 0 || p + vi > e) {
p = NULL;
break;
}
}
f->value.s = p;
f->value.len = e - f->value.s;
p = e;
break;
default:
p = NULL; // don't allow unknown tags
break;
}
} while (p && p < e);
return p && f->name.s ? p : NULL;
}
开发者ID:helioslite, 项目名称:lua_sandbox, 代码行数:79, 代码来源:heka_message.c
示例5: luaX_lex
int luaX_lex (LexState *LS, SemInfo *seminfo) {
for (;;) {
switch (LS->current) {
case '\n': {
inclinenumber(LS);
continue;
}
case '-': {
next(LS);
if (LS->current != '-') return '-';
/* else is a comment */
next(LS);
if (LS->current == '[' && (next(LS), LS->current == '['))
read_long_string(LS, NULL); /* long comment */
else /* short comment */
while (LS->current != '\n' && LS->current != EOZ)
next(LS);
continue;
}
case '[': {
next(LS);
if (LS->current != '[') return '[';
else {
read_long_string(LS, seminfo);
return TK_STRING;
}
}
case '=': {
next(LS);
if (LS->current != '=') return '=';
else { next(LS); return TK_EQ; }
}
case '<': {
next(LS);
if (LS->current != '=') return '<';
else { next(LS); return TK_LE; }
}
case '>': {
next(LS);
if (LS->current != '=') return '>';
else { next(LS); return TK_GE; }
}
case '~': {
next(LS);
if (LS->current != '=') return '~';
else { next(LS); return TK_NE; }
}
case '"':
case '\'': {
read_string(LS, LS->current, seminfo);
return TK_STRING;
}
case '.': {
next(LS);
if (LS->current == '.') {
next(LS);
if (LS->current == '.') {
next(LS);
return TK_DOTS; /* ... */
}
else return TK_CONCAT; /* .. */
}
else if (!isdigit(LS->current)) return '.';
else {
read_numeral(LS, 1, seminfo);
return TK_NUMBER;
}
}
case EOZ: {
return TK_EOS;
}
default: {
if (isspace(LS->current)) {
next(LS);
continue;
}
else if (isdigit(LS->current)) {
read_numeral(LS, 0, seminfo);
return TK_NUMBER;
}
else if (isalpha(LS->current) || LS->current == '_') {
/* identifier or reserved word */
size_t l = readname(LS);
TString *ts = luaS_newlstr(LS->L, luaZ_buffer(LS->buff), l);
if (ts->tsv.reserved > 0) /* reserved word? */
return ts->tsv.reserved - 1 + FIRST_RESERVED;
seminfo->ts = ts;
return TK_NAME;
}
else {
int c = LS->current;
if (iscntrl(c))
luaX_error(LS, "invalid control char",
luaO_pushfstring(LS->L, "char(%d)", c));
next(LS);
return c; /* single-char tokens (+ - / ...) */
}
}
}
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios, 项目名称:karlproj, 代码行数:101, 代码来源:llex.c
示例6: read_keyword
void Tool::read(char *& st, char *& k, bool new_format)
{
if (new_format && at_end(st)) {
ntools = 0;
return;
}
unsigned rank = 0;
k = read_keyword(st);
already_read = TRUE;
for (;;) {
if (strcmp(k, "tool")) {
if (new_format) {
ntools = rank;
wrong_keyword(k, "tool");
}
else if (strcmp(k, "end"))
wrong_keyword(k, "end");
else
k = read_keyword(st);
return;
}
if (rank == ntools) {
// too small table
ATool * t = new ATool[ntools + 16];
for (rank = 0; rank != ntools; rank += 1)
t[rank] = tools[rank];
if (tools)
delete [] tools;
tools = t;
ntools += 16;
}
ATool & tool = tools[rank++];
tool.display = read_string(st);
tool.cmd = read_string(st);
// fixe ghtml default conf bug
int index = tool.cmd.indexOf("ghtml - flat");
if (index != -1)
tool.cmd.remove(index + 7, 1);
if (new_format && at_end(st)) {
ntools = rank;
return;
}
k = read_keyword(st);
if (!strcmp(k, "Project")) {
tool.applicable[UmlProject] = TRUE;
if (new_format && at_end(st)) {
ntools = rank;
return;
}
k = read_keyword(st);
}
for (;;) {
// old format
const char * kc;
if (!strcmp(k, "Attribut"))
kc = "Attribute";
else if (((index = strlen(k)) > 4) &&
!strcmp(k + index - 4, "Icon")) {
k[index - 4] = 0;
kc = k;
}
else
kc = k;
for (index = 0; index != sizeof(ToolCase) / sizeof(*ToolCase); index += 1) {
if (!strcmp(kc, ToolCase[index].key))
break;
}
if (index != sizeof(ToolCase) / sizeof(*ToolCase))
tool.applicable[ToolCase[index].kind] = TRUE;
else
break;
if (new_format && at_end(st)) {
ntools = rank;
return;
}
k = read_keyword(st);
}
//.........这里部分代码省略.........
开发者ID:gilbertoca, 项目名称:douml, 代码行数:101, 代码来源:Tool.cpp
示例7: c_get_string
void
c_get_string (struct value *value, gdb_byte **buffer, int *length,
struct type **char_type, const char **charset)
{
int err, width;
unsigned int fetchlimit;
struct type *type = check_typedef (value_type (value));
struct type *element_type = TYPE_TARGET_TYPE (type);
int req_length = *length;
enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
enum c_string_type kind;
if (element_type == NULL)
goto error;
if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
{
/* If we know the size of the array, we can use it as a limit on the
number of characters to be fetched. */
if (TYPE_NFIELDS (type) == 1
&& TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_RANGE)
{
LONGEST low_bound, high_bound;
get_discrete_bounds (TYPE_FIELD_TYPE (type, 0),
&low_bound, &high_bound);
fetchlimit = high_bound - low_bound + 1;
}
else
fetchlimit = UINT_MAX;
}
else if (TYPE_CODE (type) == TYPE_CODE_PTR)
fetchlimit = UINT_MAX;
else
/* We work only with arrays and pointers. */
goto error;
if (! c_textual_element_type (element_type, 0))
goto error;
kind = classify_type (element_type,
get_type_arch (element_type),
charset);
width = TYPE_LENGTH (element_type);
/* If the string lives in GDB's memory instead of the inferior's, then we
just need to copy it to BUFFER. Also, since such strings are arrays
with known size, FETCHLIMIT will hold the size of the array. */
if ((VALUE_LVAL (value) == not_lval
|| VALUE_LVAL (value) == lval_internalvar)
&& fetchlimit != UINT_MAX)
{
int i;
const gdb_byte *contents = value_contents (value);
/* If a length is specified, use that. */
if (*length >= 0)
i = *length;
else
/* Otherwise, look for a null character. */
for (i = 0; i < fetchlimit; i++)
if (extract_unsigned_integer (contents + i * width, width,
byte_order) == 0)
break;
/* I is now either a user-defined length, the number of non-null
characters, or FETCHLIMIT. */
*length = i * width;
*buffer = xmalloc (*length);
memcpy (*buffer, contents, *length);
err = 0;
}
else
{
err = read_string (value_as_address (value), *length, width, fetchlimit,
byte_order, buffer, length);
if (err)
{
xfree (*buffer);
error (_("Error reading string from inferior: %s"),
safe_strerror (err));
}
}
/* If the LENGTH is specified at -1, we want to return the string
length up to the terminating null character. If an actual length
was specified, we want to return the length of exactly what was
read. */
if (req_length == -1)
/* If the last character is null, subtract it from LENGTH. */
if (*length > 0
&& extract_unsigned_integer (*buffer + *length - width, width,
byte_order) == 0)
*length -= width;
/* The read_string function will return the number of bytes read.
If length returned from read_string was > 0, return the number of
characters read by dividing the number of bytes by width. */
if (*length != 0)
*length = *length / width;
//.........这里部分代码省略.........
开发者ID:Akheon23, 项目名称:chromecast-mirrored-source.toolchain, 代码行数:101, 代码来源:c-lang.c
示例8: read_scan
int read_scan(const char *fmt, ...)
{
assert(fmt != NULL);
int return_code = 0;
int *out_int = NULL;
char *out_char = NULL;
char **out_string = NULL;
int max_buffer = 0;
va_list argp;
va_start(argp, fmt);
// @TODO better error handling everywhere (goto error)
// @TODO buffer overflow check & limit checking
for (int i = 0; fmt[i] != '\0'; i++) {
if (fmt[i] == '%') {
i++;
switch (fmt[i]) {
case '\0':
printf("Invalid format, you ended with %%.\n");
break;
case 'd':
out_int = va_arg(argp, int *);
int read_int_rc = read_int(out_int);
if (read_int_rc != 0) {
return_code = -1;
goto cleanup;
}
break;
case 'c':
out_char = va_arg(argp, char *);
int read_char_rc = read_char(out_char, CHOMP_NEWLINE);
if (read_char_rc != 0) {
return_code = -1;
goto cleanup;
}
break;
case 's':
out_string = va_arg(argp, char **);
max_buffer = va_arg(argp, int);
if (out_string == NULL) {
return_code = -1;
goto cleanup;
}
if (max_buffer <= 0) {
return_code = -1;
goto cleanup;
}
int read_string_rc = read_string(out_string, max_buffer);
if (read_string_rc != 0) {
return_code = -1;
goto cleanup;
}
break;
default:
printf("Invalid format.\n");
break;
}
}
// @TODO hier sollte nur feof geprüft werden
// ferror() eigentlich nach jedem read?
assert(!feof(stdin) && !ferror(stdin));
}
开发者ID:maxbeutel, 项目名称:learn-c-the-hard-way, 代码行数:84, 代码来源:ex25.c
示例9: String
Value *Parser::parse_string() {
return new String(read_string());
}
开发者ID:pzick, 项目名称:apitrace, 代码行数:3, 代码来源:trace_parser.cpp
示例10: parse_command_line
int parse_command_line(sym_environment *env, int argc, char **argv)
{
int i;
char line[MAX_LINE_LENGTH +1], tmp, c;
char key[MAX_LINE_LENGTH +1], value[MAX_LINE_LENGTH +1];
FILE *f = NULL, *f1 = NULL;
// str_int colgen_str[COLGEN_STR_SIZE] = COLGEN_STR_ARRAY;
tm_params *tm_par = &env->par.tm_par;
lp_params *lp_par = &env->par.lp_par;
cg_params *cg_par = &env->par.cg_par;
cp_params *cp_par = &env->par.cp_par;
dg_params *dg_par = &env->par.dg_par;
if (argc < 2){
usage();
exit(0);
}
printf("SYMPHONY was called with the following arguments:\n");
printf("%s ", argv[0]);
for (i = 1; i < argc; i++){
sscanf(argv[i], "%c", &tmp);
if (tmp == '-')
printf("\n");
printf("%s ", argv[i]);
}
printf("\n\n");
for (i = 0; i < argc; i++){
if (!strcmp(argv[i], "-f"))
break;
}
if (i == argc){
goto EXIT;
}else{
strncpy(env->par.param_file, argv[i+1], MAX_FILE_NAME_LENGTH);
}
if ((f = fopen(env->par.param_file, "r")) == NULL){
(void) fprintf(stderr, "Readparams: file '%s' can't be opened\n\n",
env->par.param_file);
return(ERROR__OPENING_PARAM_FILE);
}
printf("============= Other Parameter Settings =============\n\n");
while (NULL != fgets(line, MAX_LINE_LENGTH, f)){ /* read in parameters */
set_param(env, line);
printf("%s", line);
strcpy(key,"");
sscanf(line,"%s%s", key, value);
if (strcmp(key, "lp_mach_num") == 0 ||
strcmp(key, "TM_lp_mach_num") == 0){
if (tm_par->lp_mach_num){
char *lp_machs = (char *) malloc
(tm_par->lp_mach_num * (MACH_NAME_LENGTH + 1));
tm_par->lp_machs =
(char **) malloc(tm_par->lp_mach_num * sizeof(char *));
for (i=0; i<tm_par->lp_mach_num; i++)
tm_par->lp_machs[i] = lp_machs + i * (MACH_NAME_LENGTH+1);
for (i=0; i<tm_par->lp_mach_num; i++){
if (fgets(line, MAX_LINE_LENGTH, f) == NULL){
fprintf(stderr, "\nio: error reading lp_machine list\n\n");
return(ERROR__PARSING_PARAM_FILE);
}
strcpy(key, "");
sscanf(line, "%s%s", key, value);
if (strcmp(key, "TM_lp_machine") != 0){
fprintf(stderr, "\nio: error reading lp_machine list\n\n");
return(ERROR__PARSING_PARAM_FILE);
}
read_string(tm_par->lp_machs[i], line, MACH_NAME_LENGTH);
printf("%s", line);
}
}
}
else if (strcmp(key, "cg_mach_num") == 0 ||
strcmp(key, "TM_cg_mach_num") == 0){
if (tm_par->cg_mach_num){
char *cg_machs = (char *) malloc
(tm_par->cg_mach_num * (MACH_NAME_LENGTH + 1));
tm_par->cg_machs =
(char **) malloc(tm_par->cg_mach_num * sizeof(char *));
for (i=0; i<tm_par->cg_mach_num; i++)
tm_par->cg_machs[i] = cg_machs + i * (MACH_NAME_LENGTH+1);
for (i=0; i<tm_par->cg_mach_num; i++){
if (fgets(line, MAX_LINE_LENGTH, f) == NULL){
fprintf(stderr, "\nio: error reading cg_machine list\n\n");
return(ERROR__PARSING_PARAM_FILE);
}
strcpy(key, "");
sscanf(line, "%s%s", key, value);
if (strcmp(key, "TM_cg_machine") != 0){
fprintf(stderr, "\nio: error reading cg_machine list\n\n");
return(ERROR__PARSING_PARAM_FILE);
}
//.........这里部分代码省略.........
开发者ID:jkravets, 项目名称:ProjectEuler, 代码行数:101, 代码来源:master_io.c
示例11: parse
cell parse(char** s) {
// Skip whitespace
while (isspace(**s))
(*s)++;
if (!**s) return NIL;
switch (**s) {
case '"': {
*(*s)++;
cell str = read_string(s);
return cons(str, parse(s));
}
case ')':
(*s)++;
return NIL;
case '(': {
(*s)++;
cell first = parse(s);
return cons(first, parse(s));
}
case '\'': {
(*s)++;
cell rest = parse(s);
// ' -> ()
if (!rest) return NIL;
// '.a -> ()
// ' -> ()
if (!IS_PAIR(rest)) return NIL;
// 'a -> (quote a)
if (!IS_PAIR(car(rest)))
return cons(LIST2(sym("quote"), car(rest)), cdr(rest));
// '(a b c) -> (quote a b c)
return cons(cons(sym("quote"), rest), cdr(rest));
}
case '.': {
(*s)++;
cell rest = parse(s);
if (!rest) return NIL;
if (TYPE(rest) != PAIR) return NIL;
return car(rest);
}
default: {
char* i = *s;
while (*i && !isspace(*i) && *i != '(' && *i != ')')
i++;
size_t token_len = i - *s;
char* token = strncpy(malloc(token_len + 1), *s, token_len);
token[token_len] = '\0';
*s = i;
cell c;
// Try to turn the token into a number
char* endptr;
long val = strtol(token, &endptr, 0);
if (endptr != token)
c = make_int(val);
else
c = sym(token);
free(token);
return cons(c, parse(s));
}
}
}
开发者ID:andrewbuss, 项目名称:crisp, 代码行数:67, 代码来源:parse.c
示例12: cb_load_conf
//.........这里部分代码省略.........
} else if (strcmp (name, "abort-on-io-exception") == 0) {
if (strcmp (val, "any") == 0) {
cb_abort_on_io_exception = CB_ABORT_ON_IO_ANY;
} else if (strcmp (val, "fatal") == 0) {
cb_abort_on_io_exception = CB_ABORT_ON_IO_FATAL;
} else if (strcmp (val, "never") == 0) {
cb_abort_on_io_exception = CB_ABORT_ON_IO_NEVER;
} else {
invalid_value (fname, line, name);
ret = -1;
}
} else if (strcmp (name, "default-organization") == 0) {
if (strcmp (val, "record-sequential") == 0) {
cb_default_organization = CB_ORG_RECORD_SEQUENTIAL;
} else if (strcmp (val, "line-sequential") == 0) {
cb_default_organization = CB_ORG_LINE_SEQUENTIAL;
} else {
invalid_value (fname, line, name);
ret = -1;
}
}
break;
case INT:
for (j = 0; val[j]; j++) {
if (!isdigit (val[j])) {
invalid_value (fname, line, name);
ret = -1;
break;
}
}
*((int *)var) = atoi (val);
break;
case STRING:
val = read_string (val);
if (strcmp (name, "include") == 0) {
/* include another conf file */
saveret = ret;
if (cb_load_conf (val, 0, 1) != 0) {
return -1;
}
ret = saveret;
} else if (strcmp (name, "not-reserved") == 0) {
nores = read_string (val);
noresptr = cobc_malloc (sizeof (struct noreserve));
noresptr->noresword = cobc_malloc (strlen (nores) + 1);
strcpy (noresptr->noresword, nores);
noresptr->next = norestab;
norestab = noresptr;
} else {
*((const char **)var) = val;
}
break;
case CHAR:
if (1 != strnlen (val, 2)) {
invalid_value (fname, line, name);
ret = -1;
} else {
*((char *)var) = *val;
}
break;
case BOOLEAN:
if (strcmp (val, "yes") == 0) {
*((int *)var) = 1;
} else if (strcmp (val, "no") == 0) {
*((int *)var) = 0;
开发者ID:carriercomm, 项目名称:opensource-cobol, 代码行数:67, 代码来源:config.c
示例13: skinny_sbuf_parse
static enum proto_parse_status skinny_sbuf_parse(struct parser *parser, struct proto_info *parent, unsigned way, uint8_t const *packet, size_t cap_len, size_t wire_len, struct timeval const *now, size_t tot_cap_len, uint8_t const *tot_packet)
{
struct skinny_parser *skinny_parser = DOWNCAST(parser, parser, skinny_parser);
# define SKINNY_HDR_SIZE 8
# define SKINNY_MIN_MSG_SIZE 12
if (wire_len < SKINNY_MIN_MSG_SIZE) {
streambuf_set_restart(&skinny_parser->sbuf, way, packet, true); // wait for more
return PROTO_OK;
}
if (cap_len < SKINNY_MIN_MSG_SIZE) return PROTO_TOO_SHORT;
struct cursor curs;
cursor_ctor(&curs, packet, cap_len);
uint32_t msg_len = cursor_read_u32le(&curs);
enum skinny_header_version header_ver = cursor_read_u32le(&curs);
enum skinny_msgid msg_id = cursor_read_u32le(&curs);
SLOG(LOG_DEBUG, "New SKINNY msg of size %"PRIu32", msgid=0x%"PRIx32, msg_len, msg_id);
if (header_ver != SKINNY_BASIC && header_ver != SKINNY_CM7_TYPE_A && header_ver != SKINNY_CM7_TYPE_B && header_ver != SKINNY_CM7_TYPE_C) return PROTO_PARSE_ERR;
if (msg_len < 4 || msg_len > SKINNY_MAX_HDR_SIZE /* guestimated */) return PROTO_PARSE_ERR;
if (wire_len < msg_len + SKINNY_HDR_SIZE) return PROTO_TOO_SHORT; // wait for the message to be complete
// Ok we have what looks like a skinny message in there
struct skinny_proto_info info;
skinny_proto_info_ctor(&info, parser, parent, SKINNY_HDR_SIZE, msg_len, msg_id, header_ver);
switch (msg_id) {
case SKINNY_STATION_KEY_PAD_BUTTON:
if (curs.cap_len < 12) return PROTO_TOO_SHORT;
info.set_values |= SKINNY_NEW_KEY_PAD | SKINNY_LINE_INSTANCE | SKINNY_CALL_ID;
info.new_key_pad = cursor_read_u32le(&curs);
info.line_instance = cursor_read_u32le(&curs);
info.call_id = cursor_read_u32le(&curs);
break;
case SKINNY_MGR_CALL_STATE:
if (curs.cap_len < 12) return PROTO_TOO_SHORT;
info.set_values |= SKINNY_CALL_STATE | SKINNY_LINE_INSTANCE | SKINNY_CALL_ID;
info.call_state = cursor_read_u32le(&curs);
info.line_instance = cursor_read_u32le(&curs);
info.call_id = cursor_read_u32le(&curs);
SLOG(LOG_DEBUG, "New call state: %s", skinny_call_state_2_str(info.call_state));
break;
case SKINNY_MGR_CLOSE_RECV_CHANNEL:
case SKINNY_MGR_STOP_MEDIA_TRANSMIT:
if (curs.cap_len < 8) return PROTO_TOO_SHORT;
info.set_values |= SKINNY_CONFERENCE_ID | SKINNY_PASS_THRU_ID;
info.conf_id = cursor_read_u32le(&curs);
info.pass_thru_id = cursor_read_u32le(&curs);
break;
case SKINNY_MGR_START_MEDIA_TRANSMIT:
if (curs.cap_len < 8) return PROTO_TOO_SHORT;
info.set_values |= SKINNY_CONFERENCE_ID | SKINNY_PASS_THRU_ID;
info.conf_id = cursor_read_u32le(&curs);
info.pass_thru_id = cursor_read_u32le(&curs);
enum proto_parse_status status = read_channel(skinny_parser, FROM_MGR, &info, &curs, now);
if (PROTO_OK != status) return status;
break;
case SKINNY_STATION_OPEN_RECV_CHANNEL_ACK:
if (curs.cap_len < 4) return PROTO_TOO_SHORT;
uint32_t open_status = cursor_read_u32le(&curs);
if (open_status == 0 /* Ok */) {
enum proto_parse_status status = read_channel(skinny_parser, FROM_STATION, &info, &curs, now);
if (PROTO_OK != status) return status;
info.set_values |= SKINNY_PASS_THRU_ID;
if (curs.cap_len < 4) return PROTO_TOO_SHORT;
info.pass_thru_id = cursor_read_u32le(&curs);
}
break;
case SKINNY_MGR_OPEN_RECV_CHANNEL:
if (curs.cap_len < 8) return PROTO_TOO_SHORT;
info.set_values |= SKINNY_CONFERENCE_ID | SKINNY_PASS_THRU_ID;
info.conf_id = cursor_read_u32le(&curs);
info.pass_thru_id = cursor_read_u32le(&curs);
break;
case SKINNY_MGR_DIALED_NUMBER:
# define DIALED_NUMBER_SIZE 24
if (curs.cap_len < DIALED_NUMBER_SIZE+8) return PROTO_TOO_SHORT;
info.set_values |= SKINNY_CALLED_PARTY | SKINNY_LINE_INSTANCE | SKINNY_CALL_ID;
// 24 chars, terminated with 0 (if fits)
snprintf(info.called_party, sizeof(info.called_party), "%.*s", (int)DIALED_NUMBER_SIZE, curs.head);
cursor_drop(&curs, DIALED_NUMBER_SIZE);
info.line_instance = cursor_read_u32le(&curs);
info.call_id = cursor_read_u32le(&curs);
break;
case SKINNY_MGR_CALL_INFO:
if (curs.cap_len < 8 + 4 + 5*4) return PROTO_TOO_SHORT;
info.set_values |= SKINNY_CALLING_PARTY | SKINNY_CALLED_PARTY | SKINNY_LINE_INSTANCE | SKINNY_CALL_ID;
info.line_instance = cursor_read_u32le(&curs);
info.call_id = cursor_read_u32le(&curs);
cursor_drop(&curs, 4 + 5*4); // drop Call Type and 5 unknown fields
// From now on, informations are nul terminated strings
if (PROTO_OK != (status = read_string(info.calling_party, sizeof(info.calling_party), &curs))) return status; // Calling party
if (header_ver == SKINNY_CM7_TYPE_A || header_ver == SKINNY_CM7_TYPE_B || header_ver == SKINNY_CM7_TYPE_C) {
cursor_read_string(&curs, NULL, 24); // Drop calling party voice mailbox
}
if (PROTO_OK != (status = read_string(info.called_party, sizeof(info.called_party), &curs))) return status; // Called party
// discard the rest of informations
break;
default:
break;
}
(void)proto_parse(NULL, &info.info, way, NULL, 0, 0, now, tot_cap_len, tot_packet);
//.........这里部分代码省略.........
开发者ID:haiwanxue, 项目名称:junkie, 代码行数:101, 代码来源:skinny.c
示例14: load_ns_dbase
void load_ns_dbase(void)
{
dbFILE *f;
int ver, i, j, c;
NickAlias *na, **nalast, *naprev;
NickCore *nc, **nclast, *ncprev;
int failed = 0;
uint16 tmp16;
uint32 tmp32;
char *s, *pass;
if (!(f = open_db(s_NickServ, NickDBName, NICK_VERSION)))
return;
ver = get_file_version(f);
if (ver <= 11) {
// close_db(f);
// load_old_ns_dbase();
printf("old database gtfo !\n");
return;
}
/* First we load nick cores */
for (i = 0; i < 1024 && !failed; i++) {
nclast = &nclists[i];
ncprev = NULL;
while ((c = getc_db(f)) == 1) {
if (c != 1)
printf("Invalid format in %s", NickDBName);
nc = scalloc(1, sizeof(NickCore));
*nclast = nc;
nclast = &nc->next;
nc->prev = ncprev;
ncprev = nc;
slist_init(&nc->aliases);
SAFE(read_string(&nc->display, f));
printf("%s", nc->display);
if (ver < 14) {
SAFE(read_string(&pass, f));
if (pass) {
memset(nc->pass, 0, PASSMAX);
memcpy(nc->pass, pass, strlen(pass));
} else
memset(nc->pass, 0, PASSMAX);
} else
SAFE(read_buffer(nc->pass, f));
// printf(" %s", nc->pass);
SAFE(read_string(&nc->email, f));
// printf(" %s", nc->email);
SAFE(read_string(&nc->greet, f));
// printf(" %s", nc->greet);
SAFE(read_int32(&nc->icq, f));
// printf(" %d", nc->icq);
SAFE(read_string(&nc->url, f));
// printf(" %s\n", nc->url);
SAFE(read_int32(&nc->flags, f));
if (!NSAllowKillImmed)
nc->flags &= ~NI_KILL_IMMED;
SAFE(read_int16(&nc->language, f));
/* Add services opers and admins to the appropriate list, but
only if the database version is more than 10. */
/* if (nc->flags & NI_SERVICES_ADMIN)
slist_add(&servadmins, nc);
if (nc->flags & NI_SERVICES_OPER)
slist_add(&servopers, nc); */
// OSEF des axx Sop et Sadmin !
SAFE(read_int16(&nc->accesscount, f));
if (nc->accesscount) {
char **access;
access = scalloc(sizeof(char *) * nc->accesscount, 1);
nc->access = access;
for (j = 0; j < nc->accesscount; j++, access++)
SAFE(read_string(access, f));
}
SAFE(read_int16(&tmp16, f));
nc->memos.memocount = (int16) tmp16;
SAFE(read_int16(&tmp16, f));
nc->memos.memomax = (int16) tmp16;
if (nc->memos.memocount) {
Memo *memos;
memos = scalloc(sizeof(Memo) * nc->memos.memocount, 1);
nc->memos.memos = memos;
for (j = 0; j < nc->memos.memocount; j++, memos++) {
SAFE(read_int32(&memos->number, f));
SAFE(read_int16(&memos->flags, f));
SAFE(read_int32(&tmp32, f));
memos->time = tmp32;
SAFE(read_buffer(memos->sender, f));
SAFE(read_string(&memos->text, f));
//.........这里部分代码省略.........
开发者ID:fallen, 项目名称:anope2mysql, 代码行数:101, 代码来源:main.c
示例15: bdecode_recursive
void bdecode_recursive(InIt& in, InIt end, entry& ret, bool& err, int depth)
{
if (depth >= 100)
{
err = true;
return;
}
if (in == end)
{
err = true;
return;
}
switch (*in)
{
// ----------------------------------------------
// integer
case 'i':
{
++in; // 'i'
std::string val = read_until(in, end, 'e', err);
if (err) return;
TORRENT_ASSERT(*in == 'e');
++in; // 'e'
ret = entry(entry::int_t);
ret.integer() = boost::lexical_cast<entry::integer_type>(val);
} break;
// ----------------------------------------------
// list
case 'l':
{
ret = entry(entry::list_t);
++in; // 'l'
while (*in != 'e')
{
ret.list().push_back(entry());
entry& e = ret.list().back();
bdecode_recursive(in, end, e, err, depth + 1);
if (err) return;
if (in == end)
{
err = true;
return;
}
}
TORRENT_ASSERT(*in == 'e');
++in; // 'e'
} break;
// ----------------------------------------------
// dictionary
case 'd':
{
ret = entry(entry::dictionary_t);
++in; // 'd'
while (*in != 'e')
{
entry key;
bdecode_recursive(in, end, key, err, depth + 1);
if (err) return;
entry& e = ret[key.string()];
bdecode_recursive(in, end, e, err, depth + 1);
if (err) return;
if (in == end)
{
err = true;
return;
}
}
TORRENT_ASSERT(*in == 'e');
++in; // 'e'
} break;
// ----------------------------------------------
// string
default:
if (isdigit((unsigned char)*in))
{
std::string len_s = read_until(in, end, ':', err);
if (err) return;
TORRENT_ASSERT(*in == ':');
++in; // ':'
int len = std::atoi(len_s.c_str());
ret = entry(entry::string_t);
read_string(in, end, len, ret.string(), err);
if (err) return;
}
else
{
err = true;
return;
}
}
}
开发者ID:naroya, 项目名称:fdm, 代码行数:96, 代码来源:bencode.hpp
示例16: trace_report
ssize_t trace_report(int fd, struct pevent **ppevent, bool __repipe)
{
char buf[BUFSIZ];
char test[] = { 23, 8, 68 };
char *version;
int show_version = 0;
int show_funcs = 0;
int show_printk = 0;
ssize_t size = -1;
int file_bigendian;
int host_bigendian;
int file_long_size;
int file_page_size;
struct pevent *pevent;
int err;
*ppevent = NULL;
repipe = __repipe;
input_fd = fd;
if (do_read(buf, 3) < 0)
return -1;
if (memcmp(buf, test, 3) != 0) {
pr_debug("no trace data in the file");
return -1;
}
if (do_read(buf, 7) < 0)
return -1;
if (memcmp(buf, "tracing", 7) != 0) {
pr_debug("not a trace file (missing 'tracing' tag)");
return -1;
}
version = read_string();
if (version == NULL)
return -1;
if (show_version)
printf("version = %s\n", version);
free(version);
if (do_read(buf, 1) < 0)
return -1;
file_bigendian = buf[0];
host_bigendian = bigendian();
pevent = read_trace_init(file_bigendian, host_bigendian);
if (pevent == NULL) {
pr_debug("read_trace_init failed");
goto out;
}
if (do_read(buf, 1) < 0)
goto out;
file_long_size = buf[0];
file_page_size = read4(pevent);
if (!file_page_size)
goto out;
pevent_set_long_size(pevent, file_long_size);
pevent_set_page_size(pevent, file_page_size);
err = read_header_files(pevent);
if (err)
goto out;
err = read_ftrace_files(pevent);
if (err)
goto out;
err = read_event_files(pevent);
if (err)
goto out;
err = read_proc_kallsyms(pevent);
if (err)
goto out;
err = read_ftrace_printk(pevent);
if (err)
goto out;
size = trace_data_size;
repipe = false;
if (show_funcs) {
pevent_print_funcs(pevent);
} else if (show_printk) {
pevent_print_printk(pevent);
}
*ppevent = pevent;
pevent = NULL;
out:
if (pevent)
pevent_free(pevent);
return size;
}
开发者ID:AeroGirl, 项目名称:VAR-SOM-AM33-SDK7-Kernel, 代码行数:97, 代码来源:trace-event-read.c
六六分期app的软件客服如何联系?不知道吗?加qq群【895510560】即可!标题:六六分期
阅读:17974| 2023-10-27
今天小编告诉大家如何处理win10系统火狐flash插件总是崩溃的问题,可能很多用户都不知
阅读:9569| 2022-11-06
今天小编告诉大家如何对win10系统删除桌面回收站图标进行设置,可能很多用户都不知道
阅读:8129| 2022-11-06
今天小编告诉大家如何对win10系统电脑设置节能降温的设置方法,想必大家都遇到过需要
阅读:8511| 2022-11-06
我们在使用xp系统的过程中,经常需要对xp系统无线网络安装向导设置进行设置,可能很多
阅读:8415| 2022-11-06
今天小编告诉大家如何处理win7系统玩cf老是与主机连接不稳定的问题,可能很多用户都不
阅读:9309| 2022-11-06
电脑对日常生活的重要性小编就不多说了,可是一旦碰到win7系统设置cf烟雾头的问题,很
阅读:8378| 2022-11-06
我们在日常使用电脑的时候,有的小伙伴们可能在打开应用的时候会遇见提示应用程序无法
阅读:7810| 2022-11-06
今天小编告诉大家如何对win7系统打开vcf文件进行设置,可能很多用户都不知道怎么对win
阅读:8364| 2022-11-06
今天小编告诉大家如何对win10系统s4开启USB调试模式进行设置,可能很多用户都不知道怎
阅读:7362| 2022-11-06
请发表评论