static const char *skip_past_eol(const char *s, const char *end)
{
	while (s < end && !is_eol(*s++))
		;

	return s;
}
コード例 #2
0
ファイル: infcore.c プロジェクト: GYGit/reactos
/* handler for parser QUOTES state */
static const WCHAR *quotes_state( struct parser *parser, const WCHAR *pos )
{
  const WCHAR *p, *token_end = parser->start;

  for (p = pos; !is_eol( parser, p ); p++)
    {
      if (*p == '"')
        {
          if (p+1 < parser->end && p[1] == '"')  /* double quotes */
            {
              push_token( parser, p + 1 );
              parser->start = token_end = p + 2;
              p++;
            }
          else  /* end of quotes */
            {
              push_token( parser, p );
              parser->start = p + 1;
              pop_state( parser );
              return p + 1;
            }
        }
    }
  push_token( parser, p );
  pop_state( parser );
  return p;
}
コード例 #3
0
ファイル: gamepad.c プロジェクト: craksz/sdk_gtk-201
static C_RESULT parse_string(FILE* f, char* str, int32_t maxlen)
{
  int32_t i = 0;
  bool_t is_quoted = is_quote(current_c);

  if( is_quoted )
  {
    while( SUCCEED(fetch_char(f)) && ! ( is_separator(current_c) && is_quote(current_c) ) )  {
      str[i] = current_c;
      i++;
    }
  }
  else
  {
    while( SUCCEED(fetch_char(f)) && !is_separator(current_c) )  {
      str[i] = current_c;
      i++;
    }
  }

  str[i] = '\0';
  // PRINT("parse_string: %s\n", str);

  return is_eol( current_c ) ? C_FAIL : C_OK;
}
コード例 #4
0
ファイル: srtdec.c プロジェクト: aronlu/FFmpeg
static void read_chunk(AVIOContext *pb, AVBPrint *buf)
{
    char eol_buf[5];
    int n = 0, i = 0, nb_eol = 0;

    av_bprint_clear(buf);

    for (;;) {
        char c = avio_r8(pb);

        if (!c)
            break;

        /* ignore all initial line breaks */
        if (n == 0 && is_eol(c))
            continue;

        /* line break buffering: we don't want to add the trailing \r\n */
        if (is_eol(c)) {
            nb_eol += c == '\n';
            if (nb_eol == 2)
                break;
            eol_buf[i++] = c;
            if (i == sizeof(eol_buf) - 1)
                break;
            continue;
        }

        /* only one line break followed by data: we flush the line breaks
         * buffer */
        if (i) {
            eol_buf[i] = 0;
            av_bprintf(buf, "%s", eol_buf);
            i = nb_eol = 0;
        }

        av_bprint_chars(buf, c, 1);
        n++;
    }

    /* FIXME: remove the following when the lavc SubRip decoder is fixed
     * (trailing tags are not correctly flushed, see what happens to FATE when
     * you disable this code) */
    if (buf->len)
        av_bprintf(buf, "\n");
}
コード例 #5
0
ファイル: infcore.c プロジェクト: GYGit/reactos
/* handler for parser COMMENT state */
static const WCHAR *comment_state( struct parser *parser, const WCHAR *pos )
{
  const WCHAR *p = pos;

  while (!is_eol( parser, p ))
     p++;
  pop_state( parser );
  return p;
}
コード例 #6
0
void clear_eol(std::istream& input)
{
	char c = input.peek();
	while (input.good() && is_eol(c))
	{
		input.get(c);
		c = input.peek();
	}
}
コード例 #7
0
ファイル: textdec.c プロジェクト: NullEmpty/rk_ffmpeg_android
static int text_read_packet(AVFormatContext *s, AVPacket *pkt)
{
    char buffer[2048], *ptr = buffer, *ptr2, *prt3;
    char data[1024] = {0};
    int64_t pos = avio_tell(s->pb);
    int res = AVERROR_EOF;

    do {
        ptr2 = ptr;
        ptr += ff_get_line(s->pb, ptr, sizeof(buffer)+buffer-ptr);
    } while(is_eol(*ptr2) && !url_feof(s->pb) && ptr-buffer<sizeof(buffer)-1);

    do {
        prt3 = ptr;
        ptr += ff_get_line(s->pb, ptr, sizeof(buffer)+buffer-ptr);
    } while(is_eol(*prt3) && !url_feof(s->pb) && ptr-buffer<sizeof(buffer)-1);

    


    if (buffer[0]) {
        int64_t pts;
        int duration;
        const char *end = ptr;


        ptr = buffer;

        pts = get_pts(&ptr, &duration, data);
        
        if (pts != AV_NOPTS_VALUE &&
            !(res = av_new_packet(pkt, strlen(data)))) {
            memcpy(pkt->data, data, strlen(data));
            memset(data, 0, 1024);
            pkt->flags |= AV_PKT_FLAG_KEY;
            pkt->pos = pos;
            pkt->pts = pkt->dts = pts;
            pkt->duration = duration;
        }

    }
    
    return res;
}
コード例 #8
0
ファイル: inffile.c プロジェクト: RareHare/reactos
/* handler for parser KEY_NAME state */
static
const CHAR*
key_name_state(
    struct parser *parser,
    const CHAR *pos)
{
    const CHAR *p, *token_end = parser->start;

    for (p = pos; !is_eol(parser, p); p++)
    {
        if (*p == ',') break;
        switch(*p)
        {

        case '=':
            push_token(parser, token_end);
            if (!add_field_from_token(parser, 1)) return NULL;
            parser->start = p + 1;
            push_state(parser, VALUE_NAME);
            set_state(parser, LEADING_SPACES);
            return p + 1;
        case ';':
            push_token(parser, token_end);
            if (!add_field_from_token(parser, 0)) return NULL;
            push_state(parser, LINE_START);
            set_state(parser, COMMENT);
            return p + 1;
        case '"':
            push_token(parser, token_end);
            parser->start = p + 1;
            push_state(parser, KEY_NAME);
            set_state(parser, QUOTES);
            return p + 1;
        case '\\':
            push_token(parser, token_end);
            parser->start = p;
            push_state(parser, KEY_NAME);
            set_state(parser, EOL_BACKSLASH);
            return p;
        default:
            if (!isspace((unsigned char)*p)) token_end = p + 1;
            else
            {
                push_token(parser, p);
                push_state(parser, KEY_NAME);
                set_state(parser, TRAILING_SPACES);
                return p;
            }
            break;
        }
    }
    push_token(parser, token_end);
    set_state(parser, VALUE_NAME);
    return p;
}
コード例 #9
0
ファイル: main.c プロジェクト: texane/stratasys_cartridge
static uint8_t read_line(char* line, uint8_t len)
{
  uint8_t i;

  for (i = 0; i != len; ++i, ++line)
  {
    uart_read_uint8((uint8_t*)line);
    if (is_eol(*line)) break ;
  }

  return i;
}
コード例 #10
0
static unsigned get_till_eol(std::istream& input, char *buf, unsigned bufsize)
{
	unsigned count = 0;
	while (count < bufsize && input.good())
	{
		char c = input.get();
		buf[count++] = c;
		if (is_eol(c))
			break;
	}
	return count;
}
コード例 #11
0
void ff_subtitles_read_chunk(AVIOContext *pb, AVBPrint *buf)
{
    char eol_buf[5];
    int n = 0, i = 0, nb_eol = 0;

    av_bprint_clear(buf);

    for (;;) {
        char c = avio_r8(pb);

        if (!c)
            break;

        /* ignore all initial line breaks */
        if (n == 0 && is_eol(c))
            continue;

        /* line break buffering: we don't want to add the trailing \r\n */
        if (is_eol(c)) {
            nb_eol += c == '\n';
            if (nb_eol == 2)
                break;
            eol_buf[i++] = c;
            if (i == sizeof(eol_buf) - 1)
                break;
            continue;
        }

        /* only one line break followed by data: we flush the line breaks
         * buffer */
        if (i) {
            eol_buf[i] = 0;
            av_bprintf(buf, "%s", eol_buf);
            i = nb_eol = 0;
        }

        av_bprint_chars(buf, c, 1);
        n++;
    }
}
コード例 #12
0
ファイル: infcore.c プロジェクト: GYGit/reactos
/* handler for parser TRAILING_SPACES state */
static const WCHAR *trailing_spaces_state( struct parser *parser, const WCHAR *pos )
{
  const WCHAR *p;

  for (p = pos; !is_eol( parser, p ); p++)
    {
      if (*p == '\\')
        {
          set_state( parser, EOL_BACKSLASH );
          return p;
        }
      if (!isspaceW(*p))
        break;
    }
  pop_state( parser );
  return p;
}
コード例 #13
0
ファイル: gamepad.c プロジェクト: craksz/sdk_gtk-201
static C_RESULT parse_I(FILE* f)
{
  char keyword[KW_MAX_LEN];

  while( SUCCEED(fetch_char(f)) && is_separator(next_c) );

  while( !is_eol(next_c) ) {
    keyword_t kw;

    parse_string( f, keyword, KW_MAX_LEN );
    if( SUCCEED( match_keyword( keyword, &kw ) ) )
    {
      parse_keyword( f, kw );
    }
  }

  return C_OK;
}
コード例 #14
0
ファイル: infcore.c プロジェクト: GYGit/reactos
/* handler for parser SECTION_NAME state */
static const WCHAR *section_name_state( struct parser *parser, const WCHAR *pos )
{
  const WCHAR *p;

  for (p = pos; !is_eol( parser, p ); p++)
    {
      if (*p == ']')
        {
          push_token( parser, p );
          if (add_section_from_token( parser ) == NULL)
            return NULL;
          push_state( parser, LINE_START );
          set_state( parser, COMMENT );  /* ignore everything else on the line */
          return p + 1;
        }
    }
  parser->error = INF_STATUS_BAD_SECTION_NAME_LINE; /* unfinished section name */
  return NULL;
}
コード例 #15
0
ファイル: srtdec.c プロジェクト: 0x0B501E7E/ffmpeg
static int srt_read_packet(AVFormatContext *s, AVPacket *pkt)
{
    char buffer[2048], *ptr = buffer, *ptr2;
    int64_t pos = avio_tell(s->pb);
    int res = AVERROR_EOF;

    do {
        ptr2 = ptr;
        ptr += ff_get_line(s->pb, ptr, sizeof(buffer)+buffer-ptr);
    } while (!is_eol(*ptr2) && !url_feof(s->pb) && ptr-buffer<sizeof(buffer)-1);

    if (buffer[0] && !(res = av_new_packet(pkt, ptr-buffer))) {
        memcpy(pkt->data, buffer, pkt->size);
        pkt->flags |= AV_PKT_FLAG_KEY;
        pkt->pos = pos;
        pkt->pts = pkt->dts = get_pts(pkt->data);
    }
    return res;
}
コード例 #16
0
int convert_k(char const *const s, double* k, int* n) {
  int ret;
  const char* sp = s;

  // get the first value
  *n = 1;
  if( (ret = convert_float(&sp, k)) != 0)
    return ret;

  // see if there's more data on this line
  while(isblank(*sp)) sp++;
  if(is_eol(*sp))
    return 0;

  // must be another digit, assume we're dealing with complex data
  *n = 2;
  if( (ret = convert_float(&sp, k+1)) != 0)
    return ret;

  // all done
  return 0;
}
コード例 #17
0
ファイル: gamepad.c プロジェクト: craksz/sdk_gtk-201
static C_RESULT parse_H(FILE* f)
{
  C_RESULT res = C_FAIL;
  char keyword[KW_MAX_LEN];

  while( SUCCEED(fetch_char(f)) && is_separator(next_c) );

  while( !is_eol(next_c) ) {
    parse_string( f, keyword, KW_MAX_LEN );
    if( strcmp( keyword, kw_tab[KW_HANDLERS].name ) == 0 )
    {
      while( FAILED(res) && SUCCEED( parse_string(f,
                                                  (char*)((char*)&current_device + kw_tab[KW_HANDLERS].value_offset),
                                                  KW_MAX_LEN ) ) )
      {
        res = match_handler();
      }
    }
  }

  return res;
}
コード例 #18
0
ファイル: srtdec.c プロジェクト: ikoaoo/FFmpeg
static int srt_read_packet(AVFormatContext *s, AVPacket *pkt)
{
    char buffer[2048], *ptr = buffer, *ptr2;
    int64_t pos = avio_tell(s->pb);
    int res = AVERROR_EOF;

    do {
        ptr2 = ptr;
        ptr += ff_get_line(s->pb, ptr, sizeof(buffer)+buffer-ptr);
    } while (!is_eol(*ptr2) && !url_feof(s->pb) && ptr-buffer<sizeof(buffer)-1);

    if (buffer[0]) {
        int64_t pts;
        int duration;
        const char *end = ptr;
        int32_t x1 = -1, y1 = -1, x2 = -1, y2 = -1;

        ptr = buffer;
        pts = get_pts(&ptr, &duration, &x1, &y1, &x2, &y2);
        if (pts != AV_NOPTS_VALUE &&
            !(res = av_new_packet(pkt, end - ptr))) {
            memcpy(pkt->data, ptr, pkt->size);
            pkt->flags |= AV_PKT_FLAG_KEY;
            pkt->pos = pos;
            pkt->pts = pkt->dts = pts;
            pkt->duration = duration;
            if (x1 != -1) {
                uint8_t *p = av_packet_new_side_data(pkt, AV_PKT_DATA_SUBTITLE_POSITION, 16);
                if (p) {
                    AV_WL32(p,      x1);
                    AV_WL32(p +  4, y1);
                    AV_WL32(p +  8, x2);
                    AV_WL32(p + 12, y2);
                }
            }
        }
    }
    return res;
}
コード例 #19
0
ファイル: inffile.c プロジェクト: RareHare/reactos
/* handler for parser LEADING_SPACES state */
static
const CHAR*
leading_spaces_state(
    struct parser *parser,
    const CHAR *pos )
{
    const CHAR *p;

    for (p = pos; !is_eol(parser, p); p++)
    {
        if (*p == '\\')
        {
            parser->start = p;
            set_state(parser, EOL_BACKSLASH);
            return p;
        }
        if (!isspace((unsigned char)*p))
            break;
    }
    parser->start = p;
    pop_state(parser);
    return p;
}
コード例 #20
0
ファイル: passthrough.c プロジェクト: Distrotech/bogofilter
static bool write_header(rc_t status, readfunc_t rf, void *rfarg)
{
    ssize_t rd;
    char   *out;

    bool hadlf = true;
    bool seen_subj = false;

    bool seen_place_header = false;

    int bogolen = strlen(spam_header_name);
    const char *subjstr = "Subject:";
    int subjlen = strlen(subjstr);

    eol = NULL;

    /* print headers */
    while ((rd = rf(&out, rfarg)) > 0)
    {
	if (eol == NULL) {
	    if (memcmp(out+rd-1, NL, 1) == 0)
		eol = NL;
	    if (rd >=2 && memcmp(out+rd-2, CRLF, 2) == 0)
		eol = CRLF;
	}

	/* skip over spam_header_name ("X-Bogosity:") lines */
	while (rd >= bogolen && 
	       memcmp(out, spam_header_name, bogolen) == 0) {
	    while (((rd = rf(&out, rfarg)) > 0) && 
		   (out[0] == ' ' || out[0] == '\t') )
		/* empty loop */ ;
	}

	/* detect spam_header_place line */
	if ( !seen_place_header &&
	     *spam_header_place != '\0' &&
	    memcmp(out, spam_header_place, strlen(spam_header_place)) == 0)
	{
	    seen_place_header = true;
	    write_spam_info();
	}

	/* detect end of headers */
	if (is_eol(out, rd) ||
	    is_hb_delim(out, rd, have_body))
	    /* check for non-empty blank line */
	    break;

	/* rewrite "Subject: " line */
	if (!seen_subj && rd >= subjlen) {
	    const char *tag = NULL;

	    if (status == RC_SPAM && spam_subject_tag != NULL)
		tag = spam_subject_tag;

	    if (status == RC_UNSURE && unsure_subject_tag != NULL)
		tag = unsure_subject_tag;

	    if (tag != NULL && strncasecmp(out, subjstr, subjlen) == 0) {
		seen_subj = true;
		(void) fprintf(fpo, "%.*s %s", subjlen, out, tag);
		if (out[subjlen] != ' ')
		    fputc(' ', fpo);
		(void) fwrite(out + subjlen, 1, rd - subjlen, fpo);
		continue;
	    }
	}

	hadlf = (out[rd-1] == '\n');
	(void) fwrite(out, 1, rd, fpo);
	if (ferror(fpo)) cleanup_exit(EX_ERROR, 1);
    }

    if (!seen_place_header)
	write_spam_info();

    if (!hadlf)
	(void) fputs(eol, fpo);

    return seen_subj;
}
コード例 #21
0
ファイル: sb_lexer.c プロジェクト: skeezix/skeebasic
sb_token_t *lex_pull_token ( void ) {
  g_sb_token [ 0 ] = '\0';
  lex_mode_e mode = mode_seek_statement;

  while ( 1 ) {

    //printf ( "%c", *_cursor );

    switch ( mode ) {

    case mode_seek_statement:

      if ( is_whitespace ( *_cursor ) ) {
	// ignore
      } else if ( *_cursor == '#' ) {
	mode = mode_consume_comment;
      } else if ( *_cursor == '"' ) {
	mode = mode_consume_string;
      } else if ( is_number ( *_cursor ) ) {
	mode = mode_consume_constant;
	tokencat ( *_cursor );
      } else if ( is_operator ( *_cursor ) ) {
	mode = mode_consume_op;
	tokencat ( *_cursor );
      } else if ( is_eol ( *_cursor ) ) {
	_cursor++;
	sb_token_t *t = make_token();
	t -> type = sbt_eol;
	return ( t );
      } else if ( *_cursor == '\0' ) {
	_cursor++;
	sb_token_t *t = make_token();
	t -> type = sbt_eof;
	return ( t );
      } else if ( is_alpha ( *_cursor ) ) {
	mode = mode_consume_word;
	tokencat ( *_cursor );
      }

      break;

    case mode_consume_comment:

      if ( *_cursor == '\r' ) {
	break;
      } else if ( *_cursor == '\n' ) {
	// let top loop return a EOL
	_cursor--;
	mode = mode_seek_statement;
      } else if ( *_cursor == '\0' ) {
	// let top loop return a EOF
	_cursor--;
	mode = mode_seek_statement;
      }

      break;

    case mode_consume_constant:

      if ( is_eol ( *_cursor ) ||
	   *_cursor == '#' ||
	   is_whitespace ( *_cursor )
	 )
      {
	mode = mode_seek_statement;

	sb_token_t *t = make_token();
	t -> type = sbt_constant;
	t -> data.text = strdup ( g_sb_token );
	return ( t );

      } else {
	tokencat ( *_cursor );
	//_cursor++;
      }

      break;

    case mode_consume_string:

      if ( is_eol ( *_cursor ) ||
	   *_cursor == '"' )
      {

	if ( is_eol ( *_cursor ) ) {
	  printf ( "String terminator not found; assuming terminator at EOL\n" );
	} else {
	  _cursor++;
	}

	mode = mode_seek_statement;

	sb_token_t *t = make_token();
	t -> type = sbt_string;
	t -> data.text = strdup ( g_sb_token );
	return ( t );
      } else {
	rawcat ( *_cursor );
      }

      break;

    case mode_consume_op:

      if ( is_eol ( *_cursor ) ||
	   *_cursor == '#' ||
	   is_whitespace ( *_cursor )
	 )
      {
	mode = mode_seek_statement;
	_cursor++;

	sb_token_t *t = make_token();
	t -> type = sbt_op;
	t -> data.text = strdup ( g_sb_token );
	return ( t );

      } else {
	tokencat ( *_cursor );
      }

      break;

    case mode_consume_word:

      if ( is_eol ( *_cursor ) || *_cursor == '#' || is_whitespace ( *_cursor ) ) {

	// back up cursor, so when we come back into lexer it'll just
	// find the # or ' ' and start consuming comment or word..
	// no need to do it here.
	if ( *_cursor == '#' ) {
	  mode = mode_seek_statement; // consume comment and restart
	} else if ( is_whitespace ( *_cursor ) ) {
	  mode = mode_consume_word; // try to build another word
	} else if ( is_eol ( *_cursor ) ) {
	  mode = mode_seek_statement; // consume comment and restart
	}

	// do it
	if ( strcmp ( g_sb_token, "LET" ) == 0 ) {
	  sb_token_t *t = make_token();
	  t -> type = sbt_let;
	  return ( t );
	} else if ( strcmp ( g_sb_token, "EXIT" ) == 0 ) {
	  sb_token_t *t = make_token();
	  t -> type = sbt_exit;
	  return ( t );
	} else if ( strcmp ( g_sb_token, "PRINT" ) == 0 ) {
	  sb_token_t *t = make_token();
	  t -> type = sbt_print;
	  return ( t );
	} else if ( strcmp ( g_sb_token, "WHILE" ) == 0 ) {
	  sb_token_t *t = make_token();
	  t -> type = sbt_while;
	  return ( t );
	} else if ( strcmp ( g_sb_token, "GOSUB" ) == 0 ) {
	  sb_token_t *t = make_token();
	  t -> type = sbt_gosub;
	  return ( t );
	} else if ( strcmp ( g_sb_token, "SUBROUTINE" ) == 0 ) {
	  sb_token_t *t = make_token();
	  t -> type = sbt_proc;
	  return ( t );
	} else if ( ( strcmp ( g_sb_token, "ENDWHILE" ) == 0 ) ||
		    ( strcmp ( g_sb_token, "ENDIF" ) == 0 ) ||
		    ( strcmp ( g_sb_token, "ENDPROC" ) == 0 ) ||
		    ( strcmp ( g_sb_token, "ENDSUB" ) == 0 ) ||
		    ( strcmp ( g_sb_token, "END" ) == 0 )
		  )
	{
	  sb_token_t *t = make_token();
	  t -> type = sbt_end;
	  t -> data.text = strdup ( g_sb_token );
	  return ( t );
	} else if ( strcmp ( g_sb_token, "IF" ) == 0 ) {
	  sb_token_t *t = make_token();
	  t -> type = sbt_if;
	  return ( t );
	} else if ( strcmp ( g_sb_token, "ELSE" ) == 0 ) {
	  sb_token_t *t = make_token();
	  t -> type = sbt_else;
	  return ( t );
	} else {
	  sb_token_t *t = make_token();
	  t -> type = sbt_word;
	  t -> data.text = strdup ( g_sb_token );
	  return ( t );
	}

      } else if ( is_alpha ( *_cursor ) || is_number ( *_cursor ) || ( *_cursor == '_' ) ) {
	tokencat ( *_cursor );
      }

      break;

    } // switch on mode

    // we done here?
    if ( mode == mode_done ) {
      break;
    }

    _cursor++;
  } // while forever

  return NULL;
}
コード例 #22
0
ファイル: GUI_Prefs.cpp プロジェクト: highattack30/xptools
inline void	skip_eol(const char *&p, const char * e) { while(p<e && is_eol(*p)) ++p; }
コード例 #23
0
ファイル: gsargs.c プロジェクト: BorodaZizitopa/ghostscript
/* Note that these are not copied to the heap. */
const char *
arg_next(arg_list * pal, int *code)
{
    arg_source *pas;
    FILE *f;
    const char *astr = 0;	/* initialized only to pacify gcc */
    char *cstr;
    const char *result;
    int endc;
    int c, i;
    bool in_quote, eol;

  top:pas = &pal->sources[pal->depth - 1];
    if (pal->depth == 0) {
        if (pal->argn <= 0)	/* all done */
            return 0;
        pal->argn--;
        result = *(pal->argp++);
        goto at;
    }
    if (pas->is_file)
        f = pas->u.file, endc = EOF;
    else if (pas->u.s.parsed)
        /* this	string is a "pushed-back" argument		     */
        /* (retrieved by a precedeing arg_next(), but not processed) */
        if (strlen(pas->u.s.str) >= arg_str_max) {
            errprintf(pas->u.s.memory, "Command too long: %s\n", pas->u.s.str);
            *code = gs_error_Fatal;
            return NULL;
        } else {
            strcpy(pal->cstr, pas->u.s.str);
            result = pal->cstr;
            if (pas->u.s.memory)
                gs_free_object(pas->u.s.memory,	pas->u.s.chars,	"arg_next");
            pal->depth--;
            pas--;
            goto at;
        }
    else
        astr = pas->u.s.str, f = NULL, endc = 0;
    result = cstr = pal->cstr;
#define cfsgetc() (f == NULL ? (int)(unsigned char)(*astr ? *astr++ : 0) : fgetc(f))
#define is_eol(c) (c == '\r' || c == '\n')
    i = 0;
    in_quote = false;
    eol = true;
    c = cfsgetc();
    for (i = 0;;) {
        if (c == endc) {
            if (in_quote) {
                cstr[i] = 0;
                errprintf(pas->u.s.memory,
                          "Unterminated quote in @-file: %s\n", cstr);
                *code = gs_error_Fatal;
                return NULL;
            }
            if (i == 0) {
                /* EOF before any argument characters. */
                if (f != NULL)
                    fclose(f);
                else if (pas->u.s.memory)
                    gs_free_object(pas->u.s.memory, pas->u.s.chars,
                                   "arg_next");
                pal->depth--;
                goto top;
            }
            break;
        }
        /* c != endc */
        if (isspace(c)) {
            if (i == 0) {
                c = cfsgetc();
                continue;
            }
            if (!in_quote)
                break;
        }
        /* c isn't leading or terminating whitespace. */
        if (c == '#' && eol) {
            /* Skip a comment. */
            do {
                c = cfsgetc();
            } while (!(c == endc || is_eol(c)));
            if (c == '\r')
                c = cfsgetc();
            if (c == '\n')
                c = cfsgetc();
            continue;
        }
        if (c == '\\') {
            /* Check for \ followed by newline. */
            c = cfsgetc();
            if (is_eol(c)) {
                if (c == '\r')
                    c = cfsgetc();
                if (c == '\n')
                    c = cfsgetc();
                eol = true;
                continue;
            }
            /* \ anywhere else is treated as a printing character. */
            /* This is different from the Unix shells. */
            if (i == arg_str_max - 1) {
                cstr[i] = 0;
                errprintf(pas->u.s.memory, "Command too long: %s\n", cstr);
                *code = gs_error_Fatal;
                return NULL;
            }
            cstr[i++] = '\\';
            eol = false;
            continue;
        }
        /* c will become part of the argument */
        if (i == arg_str_max - 1) {
            cstr[i] = 0;
            errprintf(pas->u.s.memory, "Command too long: %s\n", cstr);
            *code = gs_error_Fatal;
            return NULL;
        }
        /* Allow quotes to protect whitespace. */
        /* (special cases have already been handled and don't reach this point) */
        if (c == '"')
            in_quote = !in_quote;
        else
            cstr[i++] = c;
        eol = is_eol(c);
        c = cfsgetc();
    }
    cstr[i] = 0;
    if (f == NULL)
        pas->u.s.str = astr;
  at:if (pal->expand_ats && result[0] == '@') {
        if (pal->depth == arg_depth_max) {
            errprintf(pas->u.s.memory, "Too much nesting of @-files.\n");
            *code = gs_error_Fatal;
            return NULL;
        }
        result++;		/* skip @ */
        f = (*pal->arg_fopen) (result, pal->fopen_data);
        if (f == NULL) {
            errprintf(pas->u.s.memory, "Unable to open command line file %s\n", result);
            *code = gs_error_Fatal;
            return NULL;
        }
        pal->depth++;
        pas++;
        pas->is_file = true;
        pas->u.file = f;
        goto top;
    }
    return result;
}
コード例 #24
0
static inline int readmm_header(FILE* f,
  int* object, int* format, int* datatype, int* symmetry,
  int* rows, int* cols, int* nz,
  char** comments) {

  assert(f != NULL);

  // valid field types
  const char* header[]      = { "%%matrixmarket", NULL };
  const char* objects[]     = { "matrix", NULL };
  const char* formats[]     = { "array", "coordinate", NULL };
  const char* datatypes[]   = { "real", "integer", "complex", "pattern", NULL };
  const char* symmetries[]  = { "general", "symmetric", "skew-symmetric", "hermitian", NULL };

  const int FIELDS = 5;
  int dummy;
  char const **const fields[] = { header, objects, formats, datatypes, symmetries, NULL};
  int *             outputs[] = { &dummy, object,  format,  datatype,  symmetry,   NULL };

  const int CHARS = 1025;
  char line[CHARS];

  // read the first line of the file (stops at EOF or newline, null terminated)
  const char* lp = fgets(line, CHARS, f);
  if(lp == NULL)
    return -1; // error or EOF w/ no characters

  // initialize results
  int i;
  for(i=0; i<FIELDS; i++) {
    *(outputs[i]) = -1;
  }
  *rows = *cols = *nz = 0;
  if(comments != NULL) {
    free(*comments);
    *comments = NULL;
  }

  // loop through the strings to decode the header
  int ret = 0;
  char const **fp = fields[0];
  int fi = 0;
  lp = line; // reset string ptr to start-of-line
  while((fp != NULL) && (ret == 0)) {
    int sp = 0;
    while((fp[sp] != NULL) && (sp >= 0)) {
      // compare the string
      const size_t chars_in_string = strlen(fp[sp]);
      if(strncasecmp(lp, fp[sp], chars_in_string) != 0) {
	sp++;
	continue;
      }

      // if it matches, check that the next character is ' ', '\n'
      char const *const lpt = lp + chars_in_string; // temporary pointer for looking ahead
      if(!isspace(*lpt)) {
	sp++;
	continue;
      }

      // on match save result and set sp = -1 to break out of the loop
      lp += chars_in_string;
      *(outputs[fi]) = sp;
      sp = -1;
    }
    // see if we recognized this field, no need to go further if we're lost
    if(*outputs[fi] == -1)
      ret = -2; // unrecognized format
    fi++;
    fp = fields[fi];

    // and consume any leading spaces before looking at the next string
    while(isblank(*lp)) lp++;
  }
  // no need to go further if we're already confused
  if(ret != 0)
    return ret;

  // store comments if requested
  if(comments != NULL) {
    assert(0); // TODO unfinished code
  }
  else { // just get past the comments
    do {
      // check for long lines which would screw up this parsing
      // the first line ending aught to be in here somewhere...
      while(isprint(*lp)) lp++;
      if(!is_eol(*lp))
        return -3; // line too long

      // read in the next line
      lp = fgets(line, CHARS, f);
    } while((*lp == '%') || is_eol(*lp));
  }
  // lp now points to the first non-blank line after the comments

  // find matrix dimensions
  if(*format == 0) { // dense array, expecting "  <rows> <columns>"
    int err1 = convert_int(&lp, rows);
    int err2 = convert_int(&lp, cols);
    *nz = (*rows) * (*cols);

    if(err1 | err2)
      return -2;
  }
  else { // must be COO format, expecting "  <rows> <columns> <non-zeros>"
    int err1 = convert_int(&lp, rows);
    int err2 = convert_int(&lp, cols);
    int err3 = convert_int(&lp, nz);

    if(err1 | err2 | err3)
      return -2;
  }

  // final check for end of line
  while(isblank(*lp)) lp++;
  if(!is_eol(*lp))
    return -3; // line too long

  return ret;
}
コード例 #25
0
void write_message(rc_t status)
{
    ssize_t rd;
    readfunc_t rf = NULL;	/* assignment to quench warning */
    void *rfarg = 0;		/* assignment to quench warning */
    char *out;
    textdata_t *text;
    int seen_subj = 0;

    if (passthrough) {
	int hadlf = 1;
	int bogolen = strlen(spam_header_name);
	const char *subjstr = "Subject:";
	int subjlen = strlen(subjstr);
	/* initialize */
	switch (passmode) {
	    case PASS_MEM:
		rf = read_mem;
		text = textblock_head();
		rfarg = &text;
		break;
	    case PASS_SEEK:
		rf = read_seek;
		rfarg = fpin;
		rewind(rfarg);
		break;
	    default:
		abort();
	}

	/* print headers */
	while ((rd = rf(&out, rfarg)) > 0)
	{
	    /* skip over spam_header ("X-Bogosity:") lines */
	    while (rd >= bogolen && memcmp(out, spam_header_name, bogolen) == 0) {
		while (((rd = rf(&out, rfarg)) > 0) && 
		       (out[0] == ' ' || out[0] == '\t') )
		    /* empty loop */ ;
	    }

	    /* detect end of headers */
	    if (is_eol(out, rd) ||
		is_hb_delim(out, rd, have_body))
		/* check for non-empty blank line */
		break;

	    /* rewrite "Subject: " line */
	    if (status == RC_SPAM &&
		rd >= subjlen && 
		spam_subject_tag != NULL &&
		strncasecmp(out, subjstr, subjlen) == 0) {
		(void) fprintf(fpo, "%.*s %s", subjlen, out, spam_subject_tag);
		if (out[subjlen] != ' ')
		    fputc(' ', fpo);
		(void) fwrite(out + subjlen, 1, rd - subjlen, fpo);
		seen_subj = 1;
		continue;
	    }

	    hadlf = (out[rd-1] == '\n');
	    (void) fwrite(out, 1, rd, fpo);
	    if (ferror(fpo)) cleanup_exit(2, 1);
	}

	if (!hadlf)
	    fputc('\n', fpo);
    }

    if (passthrough || verbose || terse) {
	typedef char *formatter(char *buff, size_t size);
	formatter *fcn = terse ? format_terse : format_header;
	char buff[256];
	/* print spam-status at the end of the header
	 * then mark the beginning of the message body */
	(*fcn)(buff, sizeof(buff));
	fputs (buff, fpo);
	fputs ("\n", fpo);
    }

    if (verbose || passthrough || Rtable) {
	verbose += passthrough;
	print_stats( stdout );
	verbose -= passthrough;
    }

    if (passthrough && !seen_subj &&
	status == RC_SPAM && spam_subject_tag != NULL) {
	(void) fprintf(fpo, "Subject: %s\n", spam_subject_tag);
    }

    if (passthrough) {
	int hadlf = 1;
	/* If the message terminated early (without body or blank
	 * line between header and body), enforce a blank line to
	 * prevent anything past us from choking. */
	(void)fputc('\n', fpo);

	/* print body */
	while ((rd = rf(&out, rfarg)) > 0)
	{
	    (void) fwrite(out, 1, rd, fpo);
	    hadlf = (out[rd-1] == '\n');
	    if (ferror(fpo)) cleanup_exit(2, 1);
	}

	if (!hadlf) fputc('\n', fpo);

	if (fflush(fpo) || ferror(fpo) || (fpo != stdout && fclose(fpo))) {
	    cleanup_exit(2, 1);
	}
    }
}
コード例 #26
0
ファイル: var-expand.cpp プロジェクト: Jingyu9/sra-tools
    bool parse_input_line ( char const* line, size_t line_size,
        char const** pkey, size_t* pkey_len,
        char const** pref_name, size_t* pref_name_len,
        char const** pallele, size_t* pallele_len,
        size_t* pref_pos, size_t* pdel_len )
    {
        size_t i = 0;
        char const* pstr;
        size_t str_len;

        char const SEP_SPACE[] = " \t\n\r";
        char const SEP_COLON[] = ":\n\r";

        // key
        pstr = & line[i];
        str_len = 0;
        for (; i < line_size && !is_sep(line[i], SEP_SPACE) && !is_eol(line[i]); ++i, ++str_len);
        if (i == line_size || str_len == 0 || is_eol(line[i]))
            return false;
        *pkey = pstr;
        *pkey_len = str_len;
        for (++i; i < line_size && is_sep(line[i], SEP_SPACE) && !is_eol(line[i]); ++i);

        // ref_name
        pstr = & line[i];
        str_len = 0;
        for (; i < line_size && !is_sep(line[i], SEP_COLON) && !is_eol(line[i]); ++i, ++str_len);
        if (i == line_size || str_len == 0 || is_eol(line[i]))
            return false;
        *pref_name = pstr;
        *pref_name_len = str_len;

        // ref_pos
        ++i;
        pstr = & line[i];
        str_len = 0;
        for (; i < line_size && !is_sep(line[i], SEP_COLON) && !is_eol(line[i]); ++i, ++str_len);
        if (i == line_size
            || str_len == 0
            || is_eol (line[i])
            || ! parse_number (pstr, str_len, pref_pos))
        {
            return false;
        }
        
        // del_len
        ++i;
        pstr = & line[i];
        str_len = 0;
        for (; i < line_size && !is_sep(line[i], SEP_COLON) && !is_eol(line[i]); ++i, ++str_len);
        if (i == line_size
            || str_len == 0
            || is_eol (line[i])
            || ! parse_number (pstr, str_len, pdel_len))
        {
            return false;
        }

        // allele
        ++i;
        pstr = & line[i];
        str_len = 0;
        for (; i < line_size && !is_sep(line[i], SEP_COLON) && !is_eol(line[i]); ++i, ++str_len);
        *pallele = pstr;
        *pallele_len = str_len;
        // treat "-" as ""
        if (*pallele_len == 1 && (*pallele)[0] == '-')
            *pallele_len = 0;

        return true;
    }
コード例 #27
0
ファイル: GUI_Prefs.cpp プロジェクト: highattack30/xptools
void			GUI_Prefs_Read(const char *app_name)
{
	sPrefs.clear();
	string pref_dir;
	if (!GUI_GetPrefsDir(pref_dir)) return;
	pref_dir += DIR_STR;
    #if LIN
    pref_dir += ".";
    pref_dir +=  app_name;
    #else
	pref_dir += app_name;
    #endif
	pref_dir += ".prefs";
	MFMemFile* f = MemFile_Open(pref_dir.c_str());
	GUI_PrefSection_t * cur=NULL;
	if(f)
	{
		const char * p = MemFile_GetBegin(f);
		const char * e = MemFile_GetEnd(f);
		while(p<e)
		{
			skip_space(p,e);
			if(p<e && *p=='[')
			{
				++p;
				const char * cs = p;
				while(p<e && !is_eol(*p) && *p != ']')
					++p;
				string cur_name(cs,p);
				cur=&sPrefs[cur_name];
			}
			else if(p<e && *p != '\r' && *p != '\n')
			{
				const char * ks = p;
				while(p<e && !is_spc(*p) && !is_eol(*p) && *p != '=')
				{
					if (*p=='\\')	++p;
					if(p<e)			++p;
				}

				const char * ke = p;
				skip_space(p,e);
				if(p<e && *p=='=')
				{
					++p;
					skip_space(p,e);
					if(p<e)
					{
						const char * vs = p;
						while(p<e && !is_spc(*p) && !is_eol(*p) && *p != '=')
						{
							if (*p=='\\')	++p;
							if(p<e)			++p;
						}
						const char * ve = p;
						if(cur)
						{
							string key(ks,ke);
							string val(vs,ve);
							dequote(key);
							dequote(val);
							(*cur)[key] = val;
						}
					}
				}
			}
			skip_eol(p,e);
		}
		MemFile_Close(f);
	}

	#if DEBUG_PREFS
	for(GUI_Prefs_t::iterator s = sPrefs.begin(); s != sPrefs.end(); ++s)
	{
		printf("[%s]" CRLF, s->first.c_str());
		for(GUI_PrefSection_t::iterator p = s->second.begin(); p != s->second.end(); ++p)
			printf("'%s'='%s'" CRLF, p->first.c_str(), p->second.c_str());
	}
	#endif
}
コード例 #28
0
ファイル: reverse.c プロジェクト: yangsuli/oscourseprojects
int main(int argc, char * argv[]){
	/*
	   if(argc > 3){
	   fprintf(stderr,"Usage: reverse <input> <output>\n");
	   exit(1);
	   }
	 */

	FILE *input,*output;

	switch(argc){
		case 1: 
			input = stdin;
			output = stdout;
			break;
		case 2: 
			input = fopen(argv[1],"r");
			if(input == NULL){
				fprintf(stderr, "Error: Cannot open file '%s'\n",argv[1]);
				exit(1);
			}
			output = stdout;
			break;
		case 3:
			if(strcmp(argv[1],argv[2])==0){
				fprintf(stderr,"Input and output file must differ\n");
				exit(1);
			}

			output = fopen(argv[2],"w");
			if(output == NULL){
				fprintf(stderr,"Error: Cannot open file '%s'\n",argv[2]);
				exit(1);
			}
			input = fopen(argv[1],"r");
			if(input == NULL){
				fprintf(stderr, "Error: Cannot open file '%s'\n",argv[1]);
				exit(1);
			}
			if(is_same_file(argv[1],argv[2])){
				fprintf(stderr,"Input and output file must differ\n");
				exit(1);
			}
			break;
		default:
			fprintf(stderr,"Usage: reverse <infile> <outfile>\n");
			exit(1);
	}

	char buf[MAX_LINE_SIZE];

	struct node *list = NULL; //the linked list that contains lines read from input file; 
	struct node *prev = NULL, *p = NULL, *current = NULL;

	//read the input file by line, and store the lines into a linked list.
	while(fgets(buf,MAX_LINE_SIZE,input)!=NULL){
		current = (struct node *)malloc(sizeof(struct node));
		if(current == NULL){
			fprintf(stderr,"malloc failed!\n");
			exit(1);
		}
		int i = 0;
		for( i = 0; i < MAX_LINE_SIZE; i++){
			current->line[i] = '\n'; //initialize with EOLs, essencial for future check
		}
		if(list == NULL){
			list = current;
		}
		current->prev = prev;
		if(current->prev != NULL){
			current->prev->next = current;
		}
		strcpy(current->line,buf);
		prev = current;

	}

	//since the pointer current now points to the last element in the list
	//struct node * last = current;
	while(current != NULL){
		struct node * current_line_start = current;
		while(current_line_start->prev != NULL && !is_eol(current_line_start->prev->line[MAX_LINE_SIZE - 2])){
			//fprintf(output,"%c\n",current_line_start->prev->line[MAX_LINE_SIZE - 2]);
			current_line_start = current_line_start->prev;
		}
		p = current_line_start;
		do{
			fprintf(output,p->line);
			//handle the special case that input file doesn't end with an EOF
		/*	if( p == last && !strchr(p->line,'\n') && !strchr(p->line,'\r') ){
				fprintf(output,"\n");
			} */
			p = p -> next;
		}while(p != current->next);

		current = current_line_start->prev;

	}

	//free the whole list;
	current = list;
	while(current != NULL){
		p = current->next;
		free(current);
		current = p;
	}

	return 0; // we won't explictly close input and output because the standard didn't say anything about fclose(stdin) or fclose(stdout). Instead we shall rely on the behaviour that all stream got closed when program terminates (by returning from main or calling exit() )


}
コード例 #29
0
ファイル: gamepad.c プロジェクト: craksz/sdk_gtk-201
static C_RESULT skip_line(FILE* f)
{
  while( !is_eol(next_c) && SUCCEED(fetch_char(f)) );

  return C_OK;
}
コード例 #30
0
void file_types_default_t::parse_item(
	string_t const &_mime_type, in_t::ptr_t &p, size_t depth
) {
	string_t mime_type = _mime_type;

	if(!mime_type) {
		while(true) { // skip comments
			if(!p) {
				init(depth);
				return;
			}

			if(*p != '#')
				break;

			++p;
			while(!is_eol(*p)) ++p;
			++p;
		}

		in_t::ptr_t p0 = p;

		while(!is_hspace(*p) && !is_eol(*p)) ++p;

		mime_type = string_t(p0, p - p0);
	}

	while(is_hspace(*p)) ++p;

	if(is_eol(*p)) {
		++p;
		parse_item(string_t::empty, p, depth);
		return;
	}

	in_t::ptr_t p0 = p;

	while(!is_hspace(*p) && !is_eol(*p)) ++p;

	string_t ext = string_t(p0, p - p0);

	parse_item(mime_type, p, depth + 1);

	item_t &item = items[depth];
	item.mime_type = mime_type;
	item.ext = ext;
	item.need_charset = mime_type_need_charset(mime_type);

	item_t *&list = bucket(ext);

	for(item_t **itempp = &list; *itempp; itempp = &(*itempp)->next) {
		item_t *itemp = *itempp;

		if(string_t::cmp<lower_t>(item.ext, itemp->ext)) {
			if(mime_type_compare(item.mime_type, itemp->mime_type)) {
				*itempp = itemp->next;
				itemp->next = NULL;
				break;
			}
			else
				return;
		}
	}

	item.next = list;
	list = &item;

	return;
}