Exemplo n.º 1
0
Arquivo: rtc.c Projeto: 0day-ci/xen
static void rtc_set_time(RTCState *s)
{
    struct tm *tm = &s->current_tm;
    struct domain *d = vrtc_domain(s);
    unsigned long before, after; /* XXX s_time_t */
      
    ASSERT(spin_is_locked(&s->lock));

    before = mktime(get_year(tm->tm_year), tm->tm_mon + 1, tm->tm_mday,
		    tm->tm_hour, tm->tm_min, tm->tm_sec);
    
    tm->tm_sec = from_bcd(s, s->hw.cmos_data[RTC_SECONDS]);
    tm->tm_min = from_bcd(s, s->hw.cmos_data[RTC_MINUTES]);
    tm->tm_hour = convert_hour(s, s->hw.cmos_data[RTC_HOURS]);
    tm->tm_wday = from_bcd(s, s->hw.cmos_data[RTC_DAY_OF_WEEK]);
    tm->tm_mday = from_bcd(s, s->hw.cmos_data[RTC_DAY_OF_MONTH]);
    tm->tm_mon = from_bcd(s, s->hw.cmos_data[RTC_MONTH]) - 1;
    tm->tm_year = from_bcd(s, s->hw.cmos_data[RTC_YEAR]) + 100;

    after = mktime(get_year(tm->tm_year), tm->tm_mon + 1, tm->tm_mday,
                   tm->tm_hour, tm->tm_min, tm->tm_sec);

    /* We use the guest's setting of the RTC to define the local-time 
     * offset for this domain. */
    d->time_offset_seconds += (after - before);
    update_domain_wallclock_time(d);
    /* Also tell qemu-dm about it so it will be remembered for next boot. */
    send_timeoffset_req(after - before);
}
Exemplo n.º 2
0
void WidgetChatBubble::add_filerecv(Toxmm::EventFileRecv file) {
    auto msg_time = Glib::DateTime::create_now_utc();

    // remove seconds
    msg_time = Glib::DateTime::create_utc(msg_time.get_year(),
                                          msg_time.get_month(),
                                          msg_time.get_day_of_month(),
                                          msg_time.get_hour(),
                                          msg_time.get_minute(),
                                          0);

    bool display_time = true;

    if (m_last_timestamp != 0) {
        auto old_time = Glib::DateTime::create_now_utc(m_last_timestamp);
        // remove seconds
        old_time = Glib::DateTime::create_utc(old_time.get_year(),
                                              old_time.get_month(),
                                              old_time.get_day_of_month(),
                                              old_time.get_hour(),
                                              old_time.get_minute(),
                                              0);
        // check
        display_time = !(msg_time.compare(old_time) == 0);
    }

    // create a new row
    auto msg  = Gtk::manage(WidgetChatFileRecv::create(observable(), file));
    auto time = Gtk::manage(new Gtk::Label());
    m_last_timestamp = msg_time.to_unix();

    // get local time
    msg_time = Glib::DateTime::create_now_local(m_last_timestamp);

    time->set_text(msg_time.format("%R"));

    // add to grid
    if (m_side == RIGHT) {
        rows.emplace_back(m_grid, m_row_count, *msg, *time);
    } else {
        rows.emplace_back(m_grid, m_row_count, *time, *msg);
    }
    m_row_count += 1;

    // styling
    time->set_halign(Gtk::ALIGN_CENTER);
    time->set_valign(Gtk::ALIGN_START);
    time->get_style_context()->add_class("bubble_chat_line_time");

    msg->set_halign(Gtk::ALIGN_START);
    msg->set_valign(Gtk::ALIGN_CENTER);

    msg->show_all();
    time->show_all();
    time->set_no_show_all();
    if (!display_time) {
        time->hide();
    }
}
Exemplo n.º 3
0
void rtc_increase_days()
{
	CCR &= ~CLKEN;
	DOM++;
	if (DOM > days_of_month(get_month(), get_year()))
		DOM = days_of_month(get_month(), get_year());

	CCR |= CLKEN;
}
Exemplo n.º 4
0
        bool operator()(const std::string& d1, const std::string& d2)
        {
            int y1,y2,m1,m2;

            m1 = get_month(d1);
            m2 = get_month(d2);
            y1 = get_year(d1);
            y2 = get_year(d2);

            return y1 < y2 || (y1 == y2 && m1 < m2);
        }
Exemplo n.º 5
0
std::string
Date::get_year_str() const
{
    std::stringstream result;
    result << get_year();
    return result.str();
}
Exemplo n.º 6
0
std::string DateTime::to_short_date_string() const
{
	throw_if_null();
	StringFormat format("%1-%2-%3");
	format.set_arg(1, get_year(), 4);
	format.set_arg(2, get_month(), 2);
	format.set_arg(3, get_day(), 2);
	return format.get_result();
}
Exemplo n.º 7
0
int main(void)
{
	T_DATE *pdate=NULL;
	//pdate=(T_DATE *)malloc(sizeof(T_DATE));	// error: invalid application of ‘sizeof’ to incomplete type ‘T_DATE’
	init_date(&pdate);
	set_date(pdate,10,7,2013);
	printf("%d-%d-%d\n",get_month(pdate),get_day(pdate),get_year(pdate));
	//printf("%d-%d-%d\n",pdate->month,pdate->day,pdate->year);// error: dereferencing pointer to incomplete type
	
	free_date(pdate);
	
	return 0;
}
Exemplo n.º 8
0
char	*get_fulldate(struct tm *ttime)
{
  char	*tmp;
  char	*tmp2;
  char	*result;

  tmp = get_year(ttime);
  tmp2 = get_day_ofmon(ttime, '0');
  result = my_printf_str("%s-%02d-%s", tmp, ttime->tm_mon + 1, tmp2);
  xfree(tmp);
  xfree(tmp2);
  return (result);
}
Exemplo n.º 9
0
std::string DateTime::to_short_datetime_string() const
{
	throw_if_null();
	// 2008-04-01
	StringFormat format("%1-%2-%3 %4:%5:%6");
	format.set_arg(1, get_year(), 4);
	format.set_arg(2, get_month(), 2);
	format.set_arg(3, get_day(), 2);
	format.set_arg(4, get_hour(), 2);
	format.set_arg(5, get_minutes(), 2);
	format.set_arg(6, get_seconds(), 2);
	return format.get_result();
}
Exemplo n.º 10
0
time_t
Date::get_ctime( const Date::date_t d )
{
    time_t t;
    time( &t );
    struct tm* timeinfo = localtime( &t );
    timeinfo->tm_year = get_year( d ) - 1900;
    timeinfo->tm_mon = get_month( d ) - 1;
    timeinfo->tm_mday = get_day( d );
    timeinfo->tm_hour = 0;
    timeinfo->tm_min = 0;
    timeinfo->tm_sec = 0;

    return( mktime( timeinfo ) );
}
Exemplo n.º 11
0
Ustring
Date::get_weekday_str() const
{
    // from wikipedia: http://en.wikipedia.org/wiki/Calculating_the_day_of_the_week
    const unsigned int year = get_year();
    const unsigned int century = ( year - ( year % 100 ) ) / 100;
    int c = 2 * ( 3 - ( century % 4 ) );
    int y = year % 100;
    y = y + floor( y / 4 );

    static const int t_m[] = { 0, 3, 3, 6, 1, 4, 6, 2, 5, 0, 3, 5 };
    struct tm ti;

    int m = get_month() - 1;
    int d = ( c + y + t_m[ m ] + get_day() );

    if( !( get_year() % 4 ) && m < 2 )  // leap year!
        d += 6;

    ti.tm_wday = ( d % 7 );
    char buf[ 32 ];
    strftime( buf, 32, "%A", &ti );
    return Ustring( buf );
}
static  void ICACHE_FLASH_ATTR pollThermostatCb(void * arg)
{
		unsigned long epoch = sntp_time+(sntp_tz*3600);
		int year=get_year(&epoch);
		int month=get_month(&epoch,year);
		int day=day=1+(epoch/86400);
		int dow=wd(year,month,day);
		epoch=epoch%86400;
		unsigned int hour=epoch/3600;
		epoch%=3600;
		unsigned int min=epoch/60;
		int minadj = (min*100/60);
		int currtime = hour*100+minadj;
				
		if(sysCfg.thermostat1state == 0) {
			os_printf("Thermostat switched off, abandoning routine.\n");
			return;
		}
		
		long Treading=-9999;
		
		if(sysCfg.sensor_dht22_enable) { 
			struct sensor_reading* result = readDHT();
			if(result->success) {
				Treading=result->temperature*100;
				if(sysCfg.thermostat1_input==2) // Humidistat
					Treading=result->humidity*100;
			}			
		}
		else { if(sysCfg.sensor_ds18b20_enable && sysCfg.thermostat1_input==0 ) { 
			struct sensor_reading* result = read_ds18b20();
			if(result->success) {
			    int SignBit, Whole, Fract;
				Treading = result->temperature;
				
				SignBit = Treading & 0x8000;  // test most sig bit
				if (SignBit) // negative
				Treading = (Treading ^ 0xffff) + 1; // 2's comp
	
				Whole = Treading >> 4;  // separate off the whole and fractional portions
				Fract = (Treading & 0xf) * 100 / 16;

				if (SignBit) // negative
					Whole*=-1;
				Treading=Whole*100+Fract;
			}
		}//ds8b20 enabled
		}
Exemplo n.º 13
0
std::string DateTime::to_string() const
{
	throw_if_null();
	// Mon Feb 3 12:32:54 2008
	std::string months[] =
	{
		"Jan",
		"Feb",
		"Mar",
		"Apr",
		"May",
		"Jun",
		"Jul",
		"Aug",
		"Sep",
		"Oct",
		"Nov",
		"Dec"
	};
	
	std::string days[] =
	{
		"Sun",
		"Mon",
		"Tue",
		"Wed",
		"Thu",
		"Fri",
		"Sat"
	};

	StringFormat format("%1 %2 %3 %4:%5:%6 %7");
	format.set_arg(1, days[get_day_of_week()]);
	format.set_arg(2, months[get_month() - 1]);
	format.set_arg(3, get_day());
	format.set_arg(4, get_hour(), 2);
	format.set_arg(5, get_minutes(), 2);
	format.set_arg(6, get_seconds(), 2);
	format.set_arg(7, get_year());
	return format.get_result();
}
Exemplo n.º 14
0
main()
{
   
   int year, day_code, leap_year; 
   
   FILE *fout;
   
   fout = fopen ("calendar.txt", "w");
   
   year = get_year();                           
   
   day_code = get_day_code (year);
   
   leap_year = get_leap_year (year);
   
   print_calendar(fout, year, day_code, leap_year);
   
   printf("Open up \'calendar.txt\' to see your calendar...\n");
   
     
}
//---------------------------------------------------------------------------------------
//Output Date (dd-mm-yy) & Time (hh:mm:ss)
int output_date_time(void){
	// Get the current date and time
	ds1307_read_date_time();
	// Get binary values + convert to ascii string
	bin_to_ascii(get_seconds(), secondASCII);
	bin_to_ascii(get_minutes(), minuteASCII);
	bin_to_ascii(get_hours(), hourASCII);
	bin_to_ascii(get_day(), dayASCII);
	bin_to_ascii(get_month(), monthASCII);
	bin_to_ascii(get_year(), yearASCII);
	// Send to LCD
	lcd_send_cmd(LINE1);
	lcd_printf(hourASCII); lcd_printf(":");
	lcd_printf(minuteASCII); lcd_printf(":");
	lcd_printf(secondASCII);
	lcd_send_cmd(LINE2);
	lcd_printf(dayASCII); lcd_printf("-");
	lcd_printf(monthASCII); lcd_printf("-");
	lcd_printf(yearASCII);
		
	return 0;
}
Exemplo n.º 16
0
int main(int argc, char* argv[]){

	int year, month, day;

	year = get_year("Please Input the Year: ");
	month = get_month("the Month: ");
	day = get_day("the Day: ", year, month);

	if( is_leap(year) ){
		months[1] = 29;
	}

	int i, days = 0;
	
	for(i = 0; i < month - 1; i++){
		days += months[i];
	}

	days += day;

	printf("%d.%d.%d is the %d days of this year.\n", year, month, day, days);

	return 0;
}
Exemplo n.º 17
0
bool SqlHelper::INSERT(const char* filepath, const char* url) const // TODO: NULL allowed?
{
#if 0
	if(mPlayerConnection == NULL)
		return;

	mPlayerConnection->pass_remote_command((QString("loadfile \"%1\"\n").arg(filepath).toAscii().data()));

	QString filename = filepath; // filename as SQL wants it
	filename.replace('\'', "''");

	QString metaTitle = corr( mPlayerConnection->fetchValue("get_meta_title\n", "ANS_META_TITLE=") );
	printf("metaTitle: %s\n",metaTitle.toAscii().data());
	if(metaTitle == "''")
	{
		metaTitle = strrchr(filepath, QDir::separator().toAscii()) + 1;
		metaTitle.resize(metaTitle.lastIndexOf('.')); // get rid of ending

		/*
			handle spaces
		*/
		metaTitle.replace('_', ' ');
		bool lastWasSpace = true;
		for(int i = 0; i<metaTitle.size(); i++)
		{
			if( lastWasSpace )
			 metaTitle[i] = metaTitle[i].toUpper();
			lastWasSpace = (metaTitle[i] == ' ');
		}
		metaTitle.prepend('\'');
		metaTitle.append('\'');

		metaTitle = corr(metaTitle);
		printf("metaTitle now: %s\n",metaTitle.toAscii().data());
	}

	QByteArray md5sum;
	calculate_md5sum(filepath, &md5sum);
	QDateTime last_changed = QFileInfo(filepath).lastModified();
	printf("str: %s\n",QString("INSERT INTO 'main' ('id' ,'titel' ,'kuenstler' ,'album' ,'tag' ,'genre' ,'jahr' ,'others' ,'yours' ,'dateityp' ,'qualitaet' ,'bew_yours' ,'bew_others' ,'pfad', 'last_changed', 'md5sum', 'url') "
				   "VALUES ( NULL, %1, %2, %3, '', %4, %5, '0', '0', %6, %7, '0', '0', '%8', '%9', '%10', '%11');")
				 .arg(
					 metaTitle,
					 corr( mPlayerConnection->fetchValue("get_meta_artist\n", "ANS_META_ARTIST=") ),
					 corr( mPlayerConnection->fetchValue("get_meta_album\n", "ANS_META_ALBUM=") ),

					 corr( mPlayerConnection->fetchValue("get_meta_genre\n", "ANS_META_GENRE=") ),
					 mPlayerConnection->fetchValue("get_meta_year\n", "ANS_META_YEAR="),
					 // TODO: interest

					 mPlayerConnection->fetchValue("get_audio_codec\n", "ANS_AUDIO_CODEC="),
					 mPlayerConnection->fetchValue("get_audio_bitrate\n", "ANS_AUDIO_BITRATE="),

					 filename,
					 md5sum.toHex().data()
				).arg(
					last_changed.toTime_t()
				).arg(
					url
				).toAscii().data());

	const QSqlQuery query = db.exec(
	/*QString str =*/	QString("INSERT INTO 'main' ('id' ,'titel' ,'kuenstler' ,'album' ,'tag' ,'genre' ,'jahr' ,'others' ,'yours' ,'dateityp' ,'qualitaet' ,'bew_yours' ,'bew_others' ,'pfad', 'last_changed', 'md5sum', 'url') "
					  "VALUES ( NULL, %1, %2, %3, '', %4, %5, '0', '0', %6, %7, '0', '0', '%8', '%9', '%10', '%11');")
					.arg(
						metaTitle,
						corr( mPlayerConnection->fetchValue("get_meta_artist\n", "ANS_META_ARTIST=") ),
						corr( mPlayerConnection->fetchValue("get_meta_album\n", "ANS_META_ALBUM=") ),

						corr( mPlayerConnection->fetchValue("get_meta_genre\n", "ANS_META_GENRE=") ),
						mPlayerConnection->fetchValue("get_meta_year\n", "ANS_META_YEAR="),
						// TODO: interest

						mPlayerConnection->fetchValue("get_audio_codec\n", "ANS_AUDIO_CODEC="),
						mPlayerConnection->fetchValue("get_audio_bitrate\n", "ANS_AUDIO_BITRATE="),

						filename )
					.arg(
						last_changed.toTime_t()
						)
					.arg (
						md5sum.toHex().data()
					)
					.arg (
						corr(url)
					)
			);
	if(!query.isValid()) {
		fputs(query.lastError().text().toAscii().data(),stderr);
	}
#else
	TagLib::FileRef fp(filepath);
	if(fp.isNull()) {
		printf("Warning: File not found.");
		return false;
	}
	TagLib::Tag* tag = fp.tag();
	TagLib::AudioProperties* audio_props = fp.audioProperties();

	QString filename = filepath; // filename as SQL wants it
	filename.replace('\'', "''");

	QString metaTitle = corr( TStringToQString(tag->title()) );
	printf("metaTitle: %s\n",metaTitle.toAscii().data());
	if(metaTitle.isEmpty())
	{
		metaTitle = strrchr(filepath, QDir::separator().toAscii()) + 1;
		metaTitle.resize(metaTitle.lastIndexOf('.')); // get rid of ending

		/*
			handle spaces
		*/
		metaTitle.replace('_', ' ');
		bool lastWasSpace = true;
		for(int i = 0; i<metaTitle.size(); i++)
		{
			if( lastWasSpace )
			 metaTitle[i] = metaTitle[i].toUpper();
			lastWasSpace = (metaTitle[i] == ' ');
		}
//		metaTitle.prepend('\'');
//		metaTitle.append('\'');

		metaTitle = corr(metaTitle);
		printf("metaTitle now: %s\n",metaTitle.toAscii().data());
	}

	QByteArray md5sum;
	calculate_md5sum(filepath, &md5sum);
	QDateTime last_changed = QFileInfo(filepath).lastModified();

	QString audio_codec = filename;
	audio_codec.remove(0, audio_codec.lastIndexOf('.')+1);

	printf("str: %s\n",QString("INSERT INTO 'main' ('id' ,'titel' ,'kuenstler' ,'album' ,'tag' ,'genre' ,'jahr' ,'others' ,'yours' ,'dateityp' ,'qualitaet' ,'bew_yours' ,'bew_others' ,'pfad', 'last_changed', 'md5sum', 'url') "
					  "VALUES ( NULL, '%1', '%2', '%3', '', '%4', '%5', '0', '0', '%6', '%7', '0', '0', '%8', '%9', '%10', '%11');")
				 .arg(
					metaTitle,
					corr( TStringToQString(tag->artist()) ),
					corr( TStringToQString(tag->album()) ),

					corr( TStringToQString(tag->genre()) ),
					get_year(tag),
					// TODO: interest

					audio_codec,
					QString::number(audio_props->bitrate()),

					filename,
					md5sum.toHex().data()
				).arg(
					last_changed.toTime_t()
				).arg(
					url
				).toAscii().data());

	const QSqlQuery query = db.exec(
	/*QString str =*/	QString("INSERT INTO 'main' ('id' ,'titel' ,'kuenstler' ,'album' ,'tag' ,'genre' ,'jahr' ,'others' ,'yours' ,'dateityp' ,'qualitaet' ,'bew_yours' ,'bew_others' ,'pfad', 'last_changed', 'md5sum', 'url') "
					  "VALUES ( NULL, '%1', '%2', '%3', '', '%4', '%5', '0', '0', '%6', '%7', '0', '0', '%8', '%9', '%10', '%11');")
					.arg(
						metaTitle,
						corr( TStringToQString(tag->artist()) ),
						corr( TStringToQString(tag->album()) ),

						corr( TStringToQString(tag->genre()) ),
						get_year(tag),
						// TODO: interest

						audio_codec,
						QString::number(audio_props->bitrate()),

						filename)
					.arg(
						last_changed.toTime_t()
						)
					.arg (
						md5sum.toHex().data()
					)
					.arg (
						corr(url)
					)
			);
	if(!query.isValid()) {
		fputs(query.lastError().text().toAscii().data(),stderr);
	}

	return true;
#endif

}
Exemplo n.º 18
0
int del_oldest_file_ext_fun()
{
	int i = 0;
	int j = 0;
	int ret = 0;
	int year = 0;
	int month = 0;
	int day = 0;
	int hour = 0;
	char dir_name[MAX_PATH];
	int  cur_year, cur_month, cur_day, cur_hour;
	int  disk_num;
	int  channel_num = get_av_channel_num();

	cur_year = get_year();		//获取当前时间-
	cur_month = get_month();	//获取当前时间-
	cur_day = get_day();		//获取当前时间-
	cur_hour = get_hour();

	do
	{
#ifdef SD_STORAGE
		
#endif

#if 1
		ret = get_oldest_time(&year, &month, &day, &hour);
		if (ret != 0)
		{
			del_file_status = -1;
			break;
		}
#endif		
		printf("the old time: %d %d %d %d\n", year, month, day, hour);
		//
		if (year < 1970 || year >2100 || month < 1 || month > 12 || day < 1 || day >31 || hour<0 || hour>=24)
		{
			del_file_status = -2;
			break;
		}
		/*
		//
		if (year == cur_year && month == cur_month && day == cur_day && hour == cur_hour)
		{
			del_file_status = -3;
			break;
		}
		*/

#ifdef SD_STORAGE
		for (j=0; j<channel_num; j++)
		{
			sprintf(dir_name,"/record/hd%02d/%02d/ch%02d/%04d-%02d-%02d/%02d",i,0,j,year,month,day,hour);
			//printf("Delete: %s\n", dir_name);
			delete_dir(dir_name);
		}
#else
		//
		disk_num = get_hard_disk_num();
		
		for (i=0; i<disk_num; i++)
		{
			//
			if (hd_get_mount_flag(i, 0) != 1)
			{
				continue;
			}

			//
			for (j=0; j<channel_num; j++)
			{
				sprintf(dir_name,"/record/hd%02d/%02d/ch%02d/%04d-%02d-%02d/%02d",i,0,j,year,month,day,hour);
				delete_dir(dir_name);
			}
		}
#endif
	}while(0);

	if (del_file_status == 1)
	{
		del_file_status = 0;
	}

	return 0;
}
Exemplo n.º 19
0
// 0 for no, 1 for yes
int is_in_range(char * start_date_string, char * end_date_string, long * date_column, int * time_column) {
    
    int start_month = get_month(start_date_string);
    int start_day = get_day(start_date_string);
    int start_year = get_year(start_date_string);
    int start_hour = get_hour(start_date_string);
    int start_minute = get_minute(start_date_string);
    
    int end_month = get_month(end_date_string);
    int end_day = get_day(end_date_string);
    int end_year = get_year(end_date_string);
    int end_hour = get_hour(end_date_string);
    int end_minute = get_minute(end_date_string);
    
    int row_year = ((int)*date_column) / 10000;
    int row_month = ((int)*date_column) / 100;
    row_month = row_month % 100;
    int row_day =((int)*date_column) % 100;
    
    if (*time_column > 2359 || *time_column < 0) {
        return -1;
    }
    
    int row_hour = *time_column / 100;
    int row_minute = *time_column % 100;

    if (start_year > end_year) {
        return -1;
    }
    if (start_year == end_year && start_month > end_month) {
        return -1;
    }
    if (start_year == end_year && start_month == end_month && start_day > end_day) {
        return -1;
    }
    if (start_year == end_year && start_month == end_month && start_day == end_day && start_hour > end_hour) {
        return -1;
    }
    if (start_year == end_year && start_month == end_month && start_day == end_day && start_hour == end_hour && start_minute > end_minute) {
        return -1;
    }
    
    // check if measurement was taken after start time, if not return 0
    if (row_year >= start_year) {
        if (row_year == start_year) {
            if (row_month >= start_month) {
                if (row_month == start_month) {
                    if (row_day >= start_day) {
                        if (row_day == start_day) {
                            if (row_hour >= start_hour) {
                                if (row_hour == start_hour) {
                                    if (row_minute >= start_minute) {
                                    } else return 0;
                                }
                            } else return 0;
                        }
                    } else return 0;
                }
            } else return 0;
        }
    } else return 0;
    
    if (row_year <= end_year) {
        if (row_year == end_year) {
            if(row_month <= end_month) {
                if (row_month == end_month) {
                    if (row_day <= end_day) {
                        if (row_day == end_day) {
                            if (row_hour <= end_hour) {
                                if (row_hour == end_hour) {
                                    if (row_minute <= end_minute) {
                                    } else return 0;
                                }
                            } else return 0;
                        }
                    } else return 0;
                }
            } else return 0;
        }
    } else return 0;
    
    return 1;
}
Exemplo n.º 20
0
//enroll screen
void enroll(char * username) {
    printf("\n\t\t\t---------------------------------------\n");
    printf("\t\t\t              Enroll Class               \n");
    printf("\t\t\t---------------------------------------\n");
    
    int m = 0, y = 0;
    char * semester;
    char * next_semester;
    
    get_year(&y);
    semester = get_semester(m);
    next_semester = get_next_semester(m);
    int y_next_semester = get_yearofnextsemester(y, semester);
    //print current quarter course list
    printf("\tCurrent Quarter: %s, %d\n\n", semester, y);
    
    //query
    char q[500] = "\0";
    MYSQL_RES *res_set;
    MYSQL_ROW row;
    
    sprintf(q, "select u.UoSCode, u.UoSName, o.Enrollment, o.MaxEnrollment,u.Credits from uosoffering o, unitofstudy u where o.uoscode = u.uoscode and o.semester ='%s' and o.year = %d;", semester, y);
    //puts(q);
    mysql_query(connection,q);
    res_set = mysql_store_result(connection);
    int numrows = (int)mysql_num_rows(res_set);
    // Display results
    printf("\tUoSCode");
    printf("\tCourse\t\t\t\t\t\t");
    printf("\tEnrollment");
    printf("\tCapacity");
    printf("\tCredit\n");
    for (int i = 0; i < numrows; i++)
    {
        row = mysql_fetch_row(res_set);

        if( row != NULL )
        {
            printf("\t%s ", row[0]);
            printf("\t%-40s ", row[1]);
            printf("\t%s", row[2]);
            printf("\t\t%s", row[3]);
            printf("\t\t%s\n", row[4]);
            
        }
    }
    //free resources
    mysql_free_result(res_set);
    
    //print next quarter course list
    printf("\n\tNext Quarter: %s, %d\n\n", next_semester, y_next_semester);
    //query
    memset(q, 0, sizeof(q));
    MYSQL_RES *res_set2;
    MYSQL_ROW row2;
    
    sprintf(q, "select u.UoSCode, u.UoSName, o.Enrollment, o.MaxEnrollment,u.Credits from uosoffering o, unitofstudy u where o.uoscode = u.uoscode and o.semester ='%s' and o.year = %d;", next_semester, y_next_semester);
    //puts(q);
    mysql_query(connection,q);
    res_set2 = mysql_store_result(connection);
    int numrows2 = (int)mysql_num_rows(res_set2);
    // Display results
    printf("\tUoSCode");
    printf("\tCourse\t\t\t\t\t\t");
    printf("\tEnrollment");
    printf("\tCapacity");
    printf("\tCredit\n");
    for (int i = 0; i < numrows2; i++)
    {
        row2 = mysql_fetch_row(res_set2);
        
        if( row2 != NULL )
        {
            printf("\t%s ", row2[0]);
            printf("\t%-40s ", row2[1]);
            printf("\t%s", row2[2]);
            printf("\t\t%s", row2[3]);
            printf("\t\t%s\n", row2[4]);
            
        }
    }
    //free resources
    mysql_free_result(res_set2);
    
    char z[20];
    do {
        printf("\n\t\t\t---------------------------------------\n");
        printf("\t\t\t           Commands List           \n");
        printf("\t\t\t---------------------------------------\n");
        printf("\t\t\t  [1]Enroll a class\n");
        printf("\t\t\t  [0]Back to main menu                 \n");
        printf("\t\t\t---------------------------------------\n\n");
        printf("Please enter the command: ");
        scanf("%s", z);
        //system("color 2f");
        if(strcmp(z, "0") == 0) {
            //studentMenu(username);
            break;
        }
        else if(strcmp(z, "1") == 0) {
            char coursenumber[9];
            int whichsemester;
            memset(q, 0, sizeof(q));
            MYSQL_RES *res_set3;
            MYSQL_ROW row3;
            printf("\nPlease enter course number: ");
            scanf("%s", coursenumber);
            
            printf("\nPlease choose current quarter or next quarter(input 1 for now, or 2 for next) : ");
            scanf("%d", &whichsemester);
            
            sprintf(q, "CALL enrollclass(%s, '%s', %d, '%s', %d);",
                    username, semester, y, coursenumber, whichsemester);
            // Display results
            mysql_query(connection,q);
            res_set3 = mysql_store_result(connection);
            int numrows3 = (int)mysql_num_rows(res_set3);
            
            for (int i = 0; i < numrows3; i++) {
                row3 = mysql_fetch_row(res_set3);
                if(row3 != NULL) {
                    if (i == 0) {
                        fprintf(stdout, "%s\n", row3[0]);
                    }
                    else {
                        fprintf(stdout, "Prerequisites: %s   %s\n", row3[0], row3[1]);
                    }
                }
            }
            //free resources
            mysql_free_result(res_set3);
            
        }
        else
            printf("INVALID COMMAND.");
    }
    while(1);
    
}
Exemplo n.º 21
0
void mc146818_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
{
	switch (id)
	{
	case TIMER_PERIODIC:
		m_data[REG_C] |= REG_C_PF;
		update_irq();
		break;

	case TIMER_CLOCK:
		if (!(m_data[REG_B] & REG_B_SET))
		{
			/// TODO: find out how the real chip deals with updates when binary/bcd values are already outside the normal range
			int seconds = get_seconds() + 1;
			if (seconds < 60)
			{
				set_seconds(seconds);
			}
			else
			{
				set_seconds(0);

				int minutes = get_minutes() + 1;
				if (minutes < 60)
				{
					set_minutes(minutes);
				}
				else
				{
					set_minutes(0);

					int hours = get_hours() + 1;
					if (hours < 24)
					{
						set_hours(hours);
					}
					else
					{
						set_hours(0);

						int dayofweek = get_dayofweek() + 1;
						if (dayofweek <= 7)
						{
							set_dayofweek(dayofweek);
						}
						else
						{
							set_dayofweek(1);
						}

						int dayofmonth = get_dayofmonth() + 1;
						if (dayofmonth <= gregorian_days_in_month(get_month(), get_year() + 2000))
						{
							set_dayofmonth(dayofmonth);
						}
						else
						{
							set_dayofmonth(1);

							int month = get_month() + 1;
							if (month <= 12)
							{
								set_month(month);
							}
							else
							{
								set_month(1);

								set_year((get_year() + 1) % 100);
							}
						}
					}
				}
			}

			if ((m_data[REG_ALARM_SECONDS] == m_data[REG_SECONDS] || (m_data[REG_ALARM_SECONDS] & ALARM_DONTCARE) == ALARM_DONTCARE) &&
				(m_data[REG_ALARM_MINUTES] == m_data[REG_MINUTES] || (m_data[REG_ALARM_MINUTES] & ALARM_DONTCARE) == ALARM_DONTCARE) &&
				(m_data[REG_ALARM_HOURS] == m_data[REG_HOURS] || (m_data[REG_ALARM_HOURS] & ALARM_DONTCARE) == ALARM_DONTCARE))
			{
				// set the alarm interrupt flag AF
				m_data[REG_C] |= REG_C_AF;
			}

			// set the update-ended interrupt Flag UF
			m_data[REG_C] |=  REG_C_UF;
			update_irq();

			m_last_refresh = machine().time();
		}
		break;
	}
}
Exemplo n.º 22
0
//withdraw screen
void withdraw(char * username) {
    printf("\n\t\t\t---------------------------------------\n");
    printf("\t\t\t              Withdraw Class               \n");
    printf("\t\t\t---------------------------------------\n");
    
    int m = 0, y = 0;
    char * semester;
    get_year(&y);
    semester = get_semester(m);

    //print current quarter course list
    printf("\tCurrent Registered classes: \n\n\t%s, %d\n\n", semester, y);
    
    //queryjj
    char q[500] = "\0";
    MYSQL_RES *res_set;
    MYSQL_ROW row;
    
    sprintf(q, "select t.uoscode, u.uosname, t.grade from transcript t, unitofstudy u where t.uoscode = u.uoscode and t.studid = %s and t.semester = '%s' and t.year = %d;",username , semester, y);
    //puts(q);
    mysql_query(connection,q);
    res_set = mysql_store_result(connection);
    int numrows = (int)mysql_num_rows(res_set);
    // Display results

    for (int i = 0; i < numrows; i++)
    {
        row = mysql_fetch_row(res_set);
        
        if( row != NULL )
        {
            printf("\t%s ", row[0]);
            printf("\t%-40s ", row[1]);
            printf("\t%s\n", row[2]);
            
        }
    }
    //free resources
    mysql_free_result(res_set);
    
    char z[20];
    do {
        printf("\n\t\t\t---------------------------------------\n");
        printf("\t\t\t           Commands List           \n");
        printf("\t\t\t---------------------------------------\n");
        printf("\t\t\t  [course number]Withdraw a class\n");
        printf("\t\t\t  [0]Back to main menu                 \n");
        printf("\t\t\t---------------------------------------\n\n");
        printf("Please enter the command: ");
        scanf("%s", z);
        //system("color 2f");
        if(strcmp(z, "0") == 0) {
            //studentMenu(username);
            
            break;
        }
        else {
            
        //call procedure withdraw here
            memset(q, 0, sizeof(q));
            MYSQL_RES *res_set2;
            MYSQL_ROW row2;
            sprintf(q, "call withdraw(%s, '%s', '%s', %d);", username, z, semester, y);
            //puts(q);
            mysql_query(connection,q);
            res_set2 = mysql_store_result(connection);
            int numrows2 = (int)mysql_num_rows(res_set);
            // Display results
            
            for (int i = 0; i < numrows2; i++)
            {
                row2 = mysql_fetch_row(res_set2);
                
                if( row2 != NULL )
                {
                    printf("\t%s\n", row2[0]);
 
                }
            }

            //free resources
            mysql_free_result(res_set2);
        }
    }
    while(1);
}
Exemplo n.º 23
0
static time_t
decode_broken_date (struct _date_token *tokens, int *tzone)
{
	gboolean got_wday, got_month, got_tzone;
	int hour, min, sec, offset, n;
	struct _date_token *token;
	struct tm tm;
	time_t time;

	memset ((void *) &tm, 0, sizeof (struct tm));
	got_wday = got_month = got_tzone = FALSE;
	offset = 0;

	token = tokens;
	while (token) {
		if (is_weekday (token) && !got_wday) {
			if ((n = get_wday (token->start, token->len)) != -1) {
				d(printf ("weekday; "));
				got_wday = TRUE;
				tm.tm_wday = n;
				goto next_token;
			}
		}

		if (is_month (token) && !got_month) {
			if ((n = get_month (token->start, token->len)) != -1) {
				d(printf ("month; "));
				got_month = TRUE;
				tm.tm_mon = n;
				goto next_token;
			}
		}

		if (is_time (token) && !tm.tm_hour && !tm.tm_min && !tm.tm_sec) {
			if (get_time (token->start, token->len, &hour, &min, &sec)) {
				d(printf ("time; "));
				tm.tm_hour = hour;
				tm.tm_min = min;
				tm.tm_sec = sec;
				goto next_token;
			}
		}

		if (is_tzone (token) && !got_tzone) {
			struct _date_token *t = token;

			if ((n = get_tzone (&t)) != -1) {
				d(printf ("tzone; "));
				got_tzone = TRUE;
				offset = n;
				goto next_token;
			}
		}

		if (is_numeric (token)) {
			if (token->len == 4 && !tm.tm_year) {
				if ((n = get_year (token->start, token->len)) != -1) {
					d(printf ("year; "));
					tm.tm_year = n - 1900;
					goto next_token;
				}
			} else {
				if (!got_month && !got_wday && token->next && is_numeric (token->next)) {
					d(printf ("mon; "));
					n = decode_int (token->start, token->len);
					got_month = TRUE;
					tm.tm_mon = n - 1;
					goto next_token;
				} else if (!tm.tm_mday && (n = get_mday (token->start, token->len)) != -1) {
					d(printf ("mday; "));
					tm.tm_mday = n;
					goto next_token;
				} else if (!tm.tm_year) {
					d(printf ("2-digit year; "));
					n = get_year (token->start, token->len);
					tm.tm_year = n - 1900;
					goto next_token;
				}
			}
		}

		d(printf ("???; "));

	next_token:

		token = token->next;
	}

	d(printf ("\n"));

	time = e_mktime_utc (&tm);

	/* time is now GMT of the time we want, but not offset by the timezone ... */

	/* this should convert the time to the GMT equiv time */
	time -= ((offset / 100) * 60 * 60) + (offset % 100) * 60;

	if (tzone)
		*tzone = offset;

	return time;
}
Exemplo n.º 24
0
//student menu screen
void studentMenu(char* username) {
    //query
    char q[150] = "\0";
    
    MYSQL_RES *res_set;
    MYSQL_ROW row;
    
    strcat(q, "SELECT name FROM student where id = ");
    strcat(q, username);
    
    mysql_query(connection,q);
    res_set = mysql_store_result(connection);
    
    row = mysql_fetch_row(res_set);
    
    int z;
    int m = 0, y = 0;
    char* semester;
    get_year(&y);
    semester = get_semester(m);
    
    printf("\t\t\t---------------------------------------\n");
    printf("\t\t\t           Student Menu           \n");
    printf("\t\t\t---------------------------------------\n\n");
    printf("\t\t\tHi, %s\n", row[0]);
    
    printf("\n\t\t\t%s, %d\n", semester, y);
    memset(q, 0, sizeof(q));
    
    MYSQL_RES *res_set2;
    MYSQL_ROW row2;
    
    sprintf(q, "select u.UoSName from unitofstudy u, transcript t where u.UoSCode = t.UoSCode and t.Studid = %s and t.Semester = '%s' and t.Year = %d;", username, semester, y);
    //puts(q);
    
    mysql_query(connection,q);
    res_set2 = mysql_store_result(connection);
    int numrows = (int)mysql_num_rows(res_set2);
    
    for (int i = 0; i < numrows; i++)
    {
        row2 = mysql_fetch_row(res_set2);
        if( row2 != NULL )
        {
            printf("\t\t\t%s\n", row2[0]);

        }
    }
    
    printf("\n\t\t\t---------------------------------------\n");
    
    //free?
    if(semester != NULL) {
        //free(semester);
        semester = NULL;
    }
    
    // free resources
    mysql_free_result(res_set);
    mysql_free_result(res_set2);
    
    do
    {
        printf("\t\t\t---------------------------------------\n");
        printf("\t\t\t           Commands List           \n");
        printf("\t\t\t---------------------------------------\n");
        printf("\t\t\t    [1]Transcript               \n");
        printf("\t\t\t    [2]Enroll Class             \n");
        printf("\t\t\t    [3]Withdraw Class           \n");
        printf("\t\t\t    [4]Personal Details         \n");
        printf("\t\t\t    [5]Logout                   \n");
        printf("\t\t\t    [0]Exit                     \n");
        printf("\t\t\t---------------------------------------\n\n");
        printf("Please enter the command: ");
        scanf("%d", &z);
        //system("color 2f");
        switch(z)
        {
            case 0 :return;
            case 1 :transcript(username);break;
            case 2 :enroll(username);break;
            case 3 :withdraw(username);break;
            case 4 :personaldetail(username);break;
            case 5 :logoutStudent(username);break;
            default:printf("\n INVALID COMMAND");
        }
    }
    while( 1 );
}
Exemplo n.º 25
0
void WidgetChatBubble::add_message(Line new_line) {
    auto msg_time = Glib::DateTime::create_now_utc(new_line.timestamp);
    // remove seconds
    msg_time = Glib::DateTime::create_utc(msg_time.get_year(),
                                          msg_time.get_month(),
                                          msg_time.get_day_of_month(),
                                          msg_time.get_hour(),
                                          msg_time.get_minute(),
                                          0);

    bool display_time = true;

    if (m_last_timestamp != 0) {
        auto old_time = Glib::DateTime::create_now_utc(m_last_timestamp);
        // remove seconds
        old_time = Glib::DateTime::create_utc(old_time.get_year(),
                                              old_time.get_month(),
                                              old_time.get_day_of_month(),
                                              old_time.get_hour(),
                                              old_time.get_minute(),
                                              0);
        // check
        display_time = !(msg_time.compare(old_time) == 0);
    }

    // create a new row
    auto msg  = Gtk::manage(new WidgetChatLabel());
    auto time = Gtk::manage(new Gtk::Label());
    m_last_timestamp = new_line.timestamp;

    // get local time
    msg_time = Glib::DateTime::create_now_local(m_last_timestamp);

    time->set_text(msg_time.format("%R"));
    msg->set_text(new_line.message);

    // add to grid
    if (m_side == RIGHT) {
        rows.emplace_back(m_grid, m_row_count, *msg, *time);
    } else {
        rows.emplace_back(m_grid, m_row_count, *time, *msg);
    }
    if (new_line.wait_for_receipt) {
        rows.back().set_class("message_pending");
        //callback !
        auto nr = new_line.nr;
        auto receipt = new_line.receipt;
        auto index = rows.size() - 1;
        rows.back().tox_callback = observer_add([this, index, nr, receipt](const ToxEvent &ev) {
            //wait for receipt
            if (ev.type() == typeid(Toxmm::EventReadReceipt)) {
                auto& row = rows[index];
                auto data = ev.get<Toxmm::EventReadReceipt>();
                if (data.nr == nr) {
                    if (data.receipt > receipt) {
                        //message failed !
                        row.set_class("message_failed");
                        row.tox_callback.reset();
                    } else if (data.receipt == receipt) {
                        //message got !
                        row.set_class("message_receipt");
                        row.tox_callback.reset();
                    }
                }
            }
        });
    }
    if (new_line.error) {
        rows.back().set_class("message_failed");
    }
    for(size_t i = 0; i < rows.size(); ++i) {
        rows[i].set_class(i == 0, i == rows.size()-1);
    }
    m_row_count += 1;

    // styling
    time->set_halign(Gtk::ALIGN_CENTER);
    time->set_valign(Gtk::ALIGN_START);
    time->get_style_context()->add_class("bubble_chat_line_time");

    msg->set_halign(Gtk::ALIGN_START);
    msg->set_valign(Gtk::ALIGN_CENTER);

    msg->show_all();
    time->show_all();
    time->set_no_show_all();
    if (!display_time) {
        time->hide();
    }
}
Exemplo n.º 26
0
/******************************************************************************
* 函数名称:del_oldest_file_fun
* 功能描述:以天为单位删除最老的录像文件(线程实现函数)
*
*
*
* 修改记录:
* 其他说明:
********************************************************************************/
int del_oldest_file_fun()
{
	int  i,j;
	int  ret;
	int  year,month,day;
	char dir_name[MAX_PATH];
	int  cur_year, cur_month, cur_day;
	int  disk_num;
	int  channel_num = get_av_channel_num();

	cur_year   = get_year();	//获取当前时间-
	cur_month  = get_month();	//获取当前时间-
	cur_day    = get_day();		//获取当前时间-

	do
	{
		ret = get_oldest_date(&year, &month, &day);
		if (ret != 0)
		{
			printf("get_oldest_date: Failed!\n");
			del_file_status = -1;
			break;
		}

		//
		if (year < 1970 || year >2100 || month < 1 || month > 12 || day < 1 || day >31 )
		{
			del_file_status = -2;
			break;
		}

		//
		if (year == cur_year && month == cur_month && day == cur_day )
		{
			del_file_status = -3;
			break;
		}

#ifdef SD_STORAGE
		disk_num = 1;
#else
		//
		disk_num = get_hard_disk_num();
#endif
		
		for (i=0; i<disk_num; i++)
		{
#ifdef SD_STORAGE

#else
			//
			if (hd_get_mount_flag(i, 0) != 1)
			{
				continue;
			}
#endif

			//
			for (j=0; j<channel_num; j++)
			{
				sprintf(dir_name,"/record/hd%02d/%02d/ch%02d/%04d-%02d-%02d",i,0,j,year,month,day);
				printf("Delete the oldest file: %s\n", dir_name);
				delete_dir(dir_name);
			}
		}
	}while(0);

	if (del_file_status == 1)
	{
		del_file_status = 0;
	}

	//pthread_exit(NULL);

	return 0;
}