コード例 #1
0
ファイル: Program.cpp プロジェクト: ppham27/snapstream-reader
void snap::Program::read_header(const std::string &header) {
  std::istringstream is(header);
  std::string line;
  while (getline(is, line)) {
    if (line.substr(0,7) == "Title: ") {
      this -> title = line.substr(7, line.length() - 7);
    } else if (line.substr(0, 13) == "Description: ") {
      this -> description = line.substr(13, line.length() - 13);
    } else if (line.substr(0, 9) == "Channel: ") {
      this -> channel = line.substr(9, line.length() - 9);
    } else if (line.substr(0, 13) == "Recorded On: ") {
      this -> recorded_date = read_date(line.substr(13, line.length() - 13));
    } else if (line.substr(0, 19) == "Original Air Date: ") {
      this -> aired_date = read_date(line.substr(19, line.length() - 19));
    }
  }  
}
コード例 #2
0
ファイル: commands.c プロジェクト: RobDeBagel/survex
static void
cmd_date(void)
{
    int year, month, day;
    int days1, days2;
    bool implicit_range = fFalse;

    read_date(&year, &month, &day);
    days1 = days_since_1900(year, month ? month : 1, day ? day : 1);

    if (days1 > current_days_since_1900) {
	compile_warning(-/*Date is in the future!*/80);
    }

    skipblanks();
    if (ch == '-') {
	nextch();
	read_date(&year, &month, &day);
    } else {
	if (month && day) {
	    days2 = days1;
	    goto read;
	}
	implicit_range = fTrue;
    }

    if (month == 0) month = 12;
    if (day == 0) day = last_day(year, month);
    days2 = days_since_1900(year, month, day);

    if (!implicit_range && days2 > current_days_since_1900) {
	compile_warning(-/*Date is in the future!*/80);
    }

    if (days2 < days1) {
	compile_error(-/*End of date range is before the start*/81);
    }

read:
    copy_on_write_meta(pcs);
    pcs->meta->days1 = days1;
    pcs->meta->days2 = days2;
}
コード例 #3
0
    void read_ride_summary(int *bytes_read = NULL, int *sum = NULL)
    {
        read_bytes(1, bytes_read, sum); // data_version
        read_bytes(1, bytes_read, sum); // firmware_minor_version

        QDateTime t = read_date(bytes_read, sum);

        rideFile->setStartTime(t);

        read_bytes(148, bytes_read, sum);
    }
コード例 #4
0
    QDateTime read_RTC_mark(double *secs, int *bytes_read = NULL, int *sum = NULL)
    {
        QDateTime date = read_date(bytes_read, sum);

        read_bytes(1, bytes_read, sum); // dummy
        read_bytes(4, bytes_read, sum); // time_moving
        *secs = double(read_bytes(4, bytes_read, sum));
        read_bytes(16, bytes_read, sum);  // dummy

        return date;
    }
コード例 #5
0
    QDateTime read_RTC_mark(double *secs, int *bytes_read = NULL, int *sum = NULL)
    {
        QDateTime date = read_date(bytes_read, sum);

        if (jouleGPS) {
            read_bytes(1, bytes_read, sum); // dummy
            read_bytes(4, bytes_read, sum); // time_moving

            // time
            double newsecs = double(read_bytes(4, bytes_read, sum));
            if (BIN2_DEBUG)
                qDebug() << "read_RTC_mark new ridetime" << newsecs << "secs (old" << *secs <<"secs)";

            *secs = newsecs;
            read_bytes(16, bytes_read, sum);  // dummy
        } else {
            read_bytes(13, bytes_read, sum);  // dummy
        }

        return date;
    }
コード例 #6
0
ファイル: birthdays.c プロジェクト: qlkzy/cccp
int main(void)
{
	char reply;
	struct date birthday;
	long no_of_days;

	do
	{

		printf("Please enter the date of your ");
		printf("birth, in the form: dd mm yy\n");

		birthday = read_date();
		no_of_days = get_day_number(birthday);
		printf("Number of days = %ld\n", no_of_days);
		printf("You were born on a ");
		write_day(no_of_days % 7);
		printf("Do you want to do that again? ");
		reply = getchar();
	} while (reply == 'y' || reply == 'Y');

	return 0;
}
コード例 #7
0
    void read_ride_summary(int *bytes_read = NULL, int *sum = NULL)
    {
        data_version = read_bytes(1, bytes_read, sum); // data_version
        read_bytes(1, bytes_read, sum); // firmware_minor_version

        QDateTime t = read_date(bytes_read, sum);

        rideFile->setStartTime(t);

        if (jouleGPS)
        {
            read_bytes(148, bytes_read, sum);

            if (data_version >= 4)
                read_bytes(8, bytes_read, sum);

            if (data_version >= 6)
                read_bytes(8, bytes_read, sum);
       } else
       {
            read_bytes(84, bytes_read, sum);
       }
    }
コード例 #8
0
ファイル: parser.c プロジェクト: kurtraschke/comp-hist
void parse_line (struct Node *node)
{
	/* the main function which analyzes a field line */

	/* determine if there is an identifier which is a prefix of s */
	/* returns the position of the first character after the field name */
	/* if s begins with a field name */
	/* returns 0 otherwise */
	/* the comparison is case sensitive */

	int
		n,
		i = 0;

	char
		savech,
//		*s,
		*ts,
		**vv;

	struct NodeLink
		*nl;

	static struct NodeLink
		*nodelinkpool;

	static int
		nodelinkcount = 0;


	skip_spaces ();

	/* Find the field corresponding to this input line */


	while (1)
	{
		/* We start i at 0, so the pre-inc will check field[1] first.
			If we do not find the field id in this line and the client
			asks to store undefined fileds then we set i to 0
		 */

		if (0 == (n = strlen (fields[++i].fname)))
		{
			/* Check if this is an ignore field */

			vv = ignore_fields;
			while (*vv)
			{
				if (strncmp (current_pos, *vv, strlen (*vv)) == 0)
					return;
				vv++;
			}

			#if     UNKNOWNFIELDS == -1  /* Declare error */
				error (0, node->id, "Unknown field definition");
				return;
			#elsif  UNKNOWNFIELDS == 0   /* Silently ignore */
				return;
			#else                        /* Save in MSTR field[0] */
				i = 0;
				break;
			#endif
		}
		else if (0 == strncmp (current_pos, fields[i].fname, n))
			break;
	}

	/* i is the field index, n is the length of the field id string */

	current_pos += n;


	if (((fields[i].flags & ALLOWDUPS) == 0) && node->field[i])
		error (0, node->id, "Duplicate field");

	skip_spaces ();
	ts = current_pos;


	if (fields[i].typ == LINK)
	{
		/* For LINK fields, we delete any whitespace in the data portion of
			the field, this provides some flexibility in specifying node
			links
		 */

		char
		*cs = ts;

		while (*cs && (*cs != '#') && (*cs != '\n') && (*ts != '\r'))
			if ((' ' == *cs) || (*cs == '\t'))
				cs++;
			else
				*ts++ = *cs++;
	}
	else
	{
		/* Find end of line, # or \n */

		while (*ts && (*ts != '#') && (*ts != '\n') && (*ts != '\r'))
			ts++;

		/* Trim any trailing whitespace */

		ts--;
		while (((*ts == '\t') || (*ts == ' ')) && (ts >= current_pos))
			ts--;
		ts++;
	}

	/* And terminate the string */

	savech = *ts;
	*ts = '\0';

	switch (fields[i].typ)
	{
	case STR:
		(char *)(node->field[i]) = dupstr (current_pos);
		*(current_pos = ts) = savech;
		return;

	case LINK:
	case MSTR:
		/* All link fields are implemented using NodeLinks which
			allow multiple links.
		 */

		if (nodelinkcount == 0)
		{
			nodelinkpool = (struct NodeLink *) malloc (
				(nodelinkcount = NODELINKPOOL) * sizeof (struct NodeLink));

			if (nodelinkpool == NULL)
				out_of_memory ("allocating nodelinkpool");
		}

		/* Here we add the new nodelink to the end of the chain,
			or to the head if it is empty. Yes it is easier to add
			to the head but this way ensures that for multiple field
			specifications, the order in the list is the same as the
			order in the file.
		 */


		if ((nl = (struct NodeLink *)(node->field[i])) == NULL)
			nl = (struct NodeLink *)(node->field[i]) = nodelinkpool++;
		else
		{
			while (nl->next)
				nl = nl->next;

			nl->next = nodelinkpool++;
			nl = nl->next;
		}

		nl->next = NULL;
		nodelinkcount--;

		(char *)(nl->node) = dupstr (current_pos);
		*(current_pos = ts) = savech;

		return;

	case DATE:
		read_date (node->id, (struct Date **)&(node->field[i]));
		*ts = savech;

		return;

	case ENUM:
		vv = fields[i].values;

		while (1)
		{
			if (*vv == NULL)   /* End of valid values */
			{
				error (0, node->id, (*++vv == NULL) ? "Invalid field value" :
					"Invalid field value - using default");

				break;
			}

			if (strcmp (*vv, current_pos) == 0)
				break;

			vv++;
		}

		(char *)(node->field[i]) = *vv;
		return;
	}
}