void dump_hdr 
   (DATA_HDR	*h,		/* ptr to Data_Hdr structure.		*/
    char	*str,		/* write debugging info into string.	*/
    int		date_fmt)	/* format specified for date/time.	*/
{
    int		seconds, usecs;
    double	usecs_per_point;
    char	begtime_str[40], exptime_str[40];
    INT_TIME	exptime;

    strcpy (begtime_str, time_to_str(h->begtime, date_fmt));

    /*	compute expected end time.  */
    time_interval2 (1,h->sample_rate,h->sample_rate_mult,&seconds,&usecs);
    usecs_per_point = seconds * (double)USECS_PER_SEC + usecs;
    exptime = add_dtime (h->endtime, usecs_per_point); 
    strcpy (exptime_str, time_to_str(exptime, date_fmt));

    sprintf (str,
	     "seq=%d stream=%s.%s.%s.%s time=%s to %s corr=%d nsamp=%d aflag=%02x ioflag=%02x qflag=%02x ",
	     h->seq_no, h->station_id, h->network_id, h->channel_id, h->location_id,
	     begtime_str, exptime_str, 
	     h->num_ticks_correction, h->num_samples, 
	     (int) h->activity_flags, (int) h->io_flags, 
	     (int) h->data_quality_flags);
    if (h->sample_rate_mult == 1)
	sprintf (str+strlen(str), "rate=%d\n", h->sample_rate);
    else
	sprintf (str+strlen(str), "rate=%.4lf\n", 
		 sps_rate(h->sample_rate, h->sample_rate_mult));
}
std::string generate_logging_table(statistics_global *ps, std::string username)
{
	std::vector<history_logins> log = ps -> get_login_history();

	std::string content = "<table class=\"table2 tablemargins fullwidth\">\n";
	content += "<tr class=\"lighttable\"><td class=\"timestamp\">event ts</td><td>event type</td><td>user</td><td>host</td><td>type</td></tr>\n";
	content += "<tr class=\"lighttable\"><td>connected since</td><td>duration</td><td colspan=\"3\">notes</td></tr>\n";

	double now_ts = get_ts();
	for(int index=log.size()-1; index >= 0; index--)
	{
		if (username.size() > 0 && log.at(index).user != username)
			continue;

		content += "<tr>";
		content += "<td>" + time_to_str((time_t)log.at(index).event_ts) + "</td>";
		content += "<td>";

		switch(log.at(index).hl)
		{
			case HL_LOGIN_OK:
				content += "login ok";
				break;
			case HL_LOGOUT_OK:
				content += "logout ok";
				break;
			case HL_LOGIN_USER_FAIL:
				content += "unknown user";
				break;
			case HL_LOGIN_PW_FAIL:
				content += "password fail";
				break;
			case HL_LOGIN_OTHER:
				content += "other error";
				break;
			default:
				content += "INTERNAL ERROR";
		}

		content += "</td><td>" + log.at(index).user + "</td>";
		content += "<td>" + log.at(index).host + "</td>";
		content += "<td>" + log.at(index).type + "</td>";
		content += "</tr>";
		content += "<tr class=\"lighttable2\">";
		content += "<td>" + time_to_str((time_t)log.at(index).time_logged_in) + "</td>";
		if (log.at(index).hl == HL_LOGOUT_OK)
			content += format("<td>%f</td>", log.at(index).duration);
		else if (log.at(index).hl == HL_LOGIN_OK)
			content += format("<td>[%f]</td>", now_ts - log.at(index).time_logged_in);
		else
			content += "<td></td>";
		content += "<td colspan=\"3\">" + log.at(index).details + "</td>";
		content += "</tr>\n";
	}
	content += "</table>\n";

	return content;
}
Exemple #3
0
gboolean 
time_handler (GUI *appGUI) {

gchar tmpbuf[BUFFER_SIZE];


    /* display current time in calendar day info */

    if (config.time_format == TIME_24) {
        sprintf(tmpbuf, "<tt>%s</tt>", time_to_str(TIME_HH_MM_SS));
    } else {
        sprintf(tmpbuf, "<tt>%s</tt>", time_to_str(TIME_HH_MM_SS_AMPM));
    }
    gtk_label_set_markup (GTK_LABEL (appGUI->cal->time_label), tmpbuf);

	return TRUE;
}
Exemple #4
0
int ask_date(xtime *save_where)
{
  time_t current_time = time(NULL);
  xtime current_xtime;
  char current_time_str[MAX_TIME_CHARS];
  char actual_time[MAX_TIME_CHARS];
  char permited_chars[MAX_TIME_CHARS] = "0123456789/: ";
  char *c;
  int i;

  time_t_to_xtime(&current_xtime, &current_time);
  time_to_str(&current_xtime, current_time_str);

  printf("São agora %s\n", current_time_str);

  printf("%sInsira a data que prentende, no formato DD/MM/AAAA HH:MM: ", COLOR_GREEN);
  reset_color();

  if (fgets(actual_time, MAX_TIME_CHARS, stdin) == NULL)
  {
    return 1;
  }

  strtok(actual_time, "\n");

  if (!strcmp(actual_time, "0"))
  {
    return 2;
  }

  if (strlen(actual_time) == MAX_TIME_CHARS - 1)
  {
    dump_line(stdin);
    return 1;
  }

  for (i = 0; actual_time[i] != '\0'; i++)
  {
    c = strchr(permited_chars, actual_time[i]);

    if (c == NULL)
    {
      return 1;
    }
  }

  sscanf(actual_time, "%d/%d/%d %d:%d", &save_where->day,
         &save_where->month,
         &save_where->year,
         &save_where->hour,
         &save_where->minute);

  return 0;
}
Exemple #5
0
void dtime_to_str(double dtime, char *str) {
    char t[128], dps[128];
    char *dpsd;
    int ip = (int)dtime; /* integer part */
    double dp = dtime - ip; /* decimal part */

    time_to_str(ip, t);
    strcpy(str, t);
    sprintf(dps, "%f", dp);
    dpsd = &dps[2];
    strcat(str, dpsd);
}
Exemple #6
0
gchar *
get_date_time_str (guint32 date, gint time)
{
static gchar buffer[BUFFER_SIZE];
TIME *s_time;

	s_time = seconds_to_time (time);
	g_snprintf (buffer, BUFFER_SIZE, "%s, %s",
	            julian_to_str (date, config.date_format), time_to_str (s_time, config.time_format));
	g_free (s_time);

	return buffer;
}
Exemple #7
0
// Source: http://stackoverflow.com/questions/6508461/logging-library-for-c
// TODO: implement log_gile function?
// Source: https://github.com/rxi/log.c/blob/master/src/log.c
int flog(log_level_enum lvl, const char* message) {
    if(lvl <= _LIBMZDB_LOGGING_DATA.min_log_level || !_LIBMZDB_LOGGING_DATA.file) return 0;

    char* str_time = time_to_str();
    if(_LIBMZDB_LOGGING_DATA.file == stdout && lvl >= LOG_WARN)
    {
        return fprintf(stderr, LOG_TEMPLATE, LOG_LEVELS[lvl], str_time, message, "\n");
    }
    else
    {
        int rc = fprintf(_LIBMZDB_LOGGING_DATA.file, LOG_TEMPLATE, LOG_LEVELS[lvl], str_time, message, "\n");
        fflush(_LIBMZDB_LOGGING_DATA.file);

        return rc;
    }
}
Exemple #8
0
gchar *
get_date_time_full_str (guint32 date, gint time)
{
static gchar buffer[BUFFER_SIZE];
TIME *s_time;

	if (time >= 0) {
		s_time = seconds_to_time (time);
		g_snprintf (buffer, BUFFER_SIZE, "%s, %s",
		            julian_to_str (date, config.date_format), time_to_str (s_time, TIME_HH_MM));
		g_free (s_time);
	} else {
		g_snprintf (buffer, BUFFER_SIZE, "%s", julian_to_str (date, config.date_format));
	}

	return buffer;
}
Exemple #9
0
void list_mem_print(char mask)
{
	int pos = 0;
	struct mblock_t *m;
	char time_str[50];
	char entro = 0;

	while (pos<list_mem->n) {
		m = list_get(list_mem, pos);
		if (!(m->type&MTYPE_MALLOC)) break;
		
		if (mask&MTYPE_MALLOC) {
			if(entro == 0){
				printf("Espacios reservados con malloc:\n");
				printf("DIRECCIÓN                   TAMAÑO INSTANTE\n");
				entro++;
			}
			
			time_to_str(m->time, time_str, sizeof(time_str));
			printf("0x%016lx %15zu %20s\n",
				(unsigned long)m->addr,
				m->size,
				time_str
				);
		}
		pos++;
	}
	
	entro = 0;
	while (pos<list_mem->n) {		
		m = list_get(list_mem, pos);
		if (!(m->type&MTYPE_MMAP)) break;
		
		if (mask&MTYPE_MMAP) {
			if(entro == 0){
				printf("Espacios reservados con mmap:\n");
				printf("DIRECCIÓN          TAMAÑO   INSTANTE             FD NOMBRE\n");
				entro++;
			}
			time_to_str(m->time, time_str, sizeof(time_str));
			printf("0x%016lx %-8zu %-20s %2d %s\n",
				(unsigned long)m->addr,
				m->size,
				time_str,
				m->fd,
				m->name
			);
		}
		pos++;
	}
	
	entro = 0;
	while (pos<list_mem->n) {	
		m = list_get(list_mem, pos);
		if (!(m->type&MTYPE_SHARED)) break;
		
		if (mask&MTYPE_SHARED) {
			if(entro == 0)
			{
				printf("Espacios reservados con shared:\n");
				printf("DIRECCIÓN                   TAMAÑO             INSTANTE         ID KEY\n");
				entro++;
			}
			time_to_str(m->time, time_str, sizeof(time_str));
			printf("0x%016lx %15zu %20s %10d 0x%08x\n",
				(unsigned long)m->addr,
				m->size,
				time_str,
				m->shmid,
				m->key
			);
		}
		pos++;
	}
}
http_bundle * http_file_users::do_request(http_request_t request_type, std::string request_url, http_bundle *request_details)
{
	std::map<std::string, std::string> request_parameters = split_parameters(request_url);

	std::vector<std::string> reply_headers;

	std::string content = get_style_header();

	std::vector<std::string> user_list = pusers -> get_users();

	content += "<table class=\"table2 fullwidth\">\n";
	content += "<tr class=\"lighttable\"><td>user</td><td>bits put</td><td>bits put raw</td><td>bits sent</td><td colspan=\"5\"></td></tr>\n";
	content += "<tr class=\"lighttable\"><td colspan=\"2\">latest logon</td><td colspan=\"2\">last message</td><td colspan=\"2\">last put</td><td colspan=\"2\">last get</td><td></td></tr>\n";
	content += "<tr class=\"lighttable\"><td>msgs</td><td>disconnects</td><td>empty</td><td>full</td><td>quota reached</td><td>submit while full</td><td>network error</td><td>protocol error</td><td>misc error</td></tr>\n";

	for(unsigned int index=0; index<user_list.size(); index++)
	{
		std::string username = user_list.at(index);

		// ** emit
		// row 1
		content += "<tr class=\"lighttable3\"><td class=\"lighttable4\">";
		content += username;
		content += "</td><td>";
		long long int total_bits_recv, total_bits_recv_in;
		int n_reqs;
		pusers -> get_recvs(username, &total_bits_recv, &n_reqs, &total_bits_recv_in);
		content += format("%lld", total_bits_recv);
		content += "</td><td>";
		content += format("%lld", total_bits_recv_in);
		content += "</td><td>";
		int n_sents;
		long long int total_bits_sent;
		pusers -> get_sents(username, &total_bits_sent, &n_sents);
		content += format("%lld", total_bits_sent);
		content += "</td><td colspan=\"5\"></td></tr>\n";
		// row 2
		content += "<tr class=\"lighttable2\"><td colspan=\"2\">";
		content += time_to_str((time_t)pusers -> get_last_login(username));
		content += "</td><td colspan=\"2\">";
		content += time_to_str((time_t)pusers -> get_last_msg_ts(username));
		content += "</td><td colspan=\"2\">";
		content += time_to_str((time_t)pusers -> get_last_put_msg_ts(username));
		content += "</td><td colspan=\"2\">";
		content += time_to_str((time_t)pusers -> get_last_get_msg_ts(username));
		content += "</td><td></td></tr>\n";
		// row 3
		content += "<tr><td>";
		content += format("%d", pusers -> get_msg_cnt(username));
		int disconnects = pusers -> get_disconnects(username);
		content += "</td><td" + std::string(disconnects > 0 ? " class=\"darkyellow\"" : "") + ">";
		content += format("%d", disconnects);
		int times_empty = pusers -> get_times_empty(username);
		content += "</td><td" + std::string(times_empty > 0 ? " class=\"darkyellow\"" : "") + ">";
		content += format("%d", times_empty);
		int times_full = pusers -> get_times_full(username);
		content += "</td><td" + std::string(times_full > 0 ? " class=\"darkyellow\"" : "") + ">";
		content += format("%d", times_full);
		int times_quota = pusers -> get_times_quota(username);
		content += "</td><td" + std::string(times_quota > 0 ? " class=\"darkyellow\"" : "") + ">";
		content += format("%d", times_quota);
		int submit_while_full = pusers -> get_submit_while_full(username);
		content += "</td><td" + std::string(submit_while_full > 0 ? " class=\"darkyellow\"" : "") + ">";
		content += format("%d", submit_while_full);
		int network_error = pusers -> get_network_error(username);
		content += "</td><td" + std::string(network_error > 0 ? " class=\"darkred\"" : "") + ">";
		content += format("%d", network_error);
		int protocol_error = pusers -> get_protocol_error(username);
		content += "</td><td" + std::string(protocol_error > 0 ? " class=\"darkred\"" : "") + ">";
		content += format("%d", protocol_error);
		int misc_errors = pusers -> get_misc_errors(username);
		content += "</td><td" + std::string(misc_errors > 0 ? " class=\"darkred\"" : "") + ">";
		content += format("%d", misc_errors);
		content += "</td></tr>\n";

		content += "</td></tr>\n";
	}

	content += "</table>\n";

	content += get_style_tail();

	return new http_bundle(reply_headers, content.c_str());
}
/**
 * Defines parameter mapping as following:
 *   0. Unused parameter
 *   1. Lead-in time (in seconds]
 *   2. Lead-out time (in seconds]
 *   3. Acceleration time (in seconds]
 *   4. Deceleration time (in seconds]
 *   5. Exposure time (in milliseconds]
 *   6. "film length" of film
 *   Time:
 *   11. time1
 *   12.
 *   13.
 *   14. time2
 *   Lists:
 *   20
 * */
uint8_t MenuContext::formatParameterText(const uint8_t idx, uint8_t* cLineBuf, uint8_t* level, uint8_t* item )
{
   uint32_t value = readLiveParameter(idx);
   *level = 0;
   *item = 0;

   uint8_t len = 0;
   //temporary init as
   cLineBuf[0] = '[';
   cLineBuf[1] = '=';
   char* ptrStart = (char*)&cLineBuf[2];
	if ((idx > 0) && (idx < 10))  {
	//integer type
	   //sprintf(ptrStart, "%lu", value );
	   ultoa(value, ptrStart, 10);
   }
   /*dynamic list, very special case*/
   if (idx == 10) {
	   uint32_t listIdx = value;
	   RangeChecker::checkParamByIdx(idx, &listIdx);
	   //sprintf(ptrStart, "%s", &dynList[listIdx-1][0] );
	   strcpy(ptrStart, &dynList[listIdx-1][0]);
	   if (listIdx == dynListSize) {
	     *item = 2;
	     *level = CREATE_FILM_WIZARD;
	   } else {
		 *item = 1;
		 *level = AXIS_WIZARD;
	   }
   }
  /* magic 11(12)(13) or 14:15:16 is time type*/
   if ((idx == 11) || (idx == 14)){
	   uint32_t tmp = value;
	   uint8_t hour = tmp/3600;
	   //tmp = tmp - ((uint32_t)hour * 3600UL); // may be
	   tmp = tmp%3600;
	   uint8_t minutes = tmp/60;
	   //tmp = tmp - ((uint32_t)minutes * 60UL); //
	   tmp = tmp%60;
	   uint8_t secs = tmp;
	   time_to_str(ptrStart, hour, minutes, secs);
	   //sprintf(ptrStart, "%02d:%02d:%02d", hour, minutes, secs);

   }
   /*magic 20,21... is list type*/
   if ((idx >= 20) && (idx < NUMBER_OF_PARAMETERS))
   {
	   uint32_t listIdx = value;
	   RangeChecker::checkParamByIdx(idx, &listIdx);
       if (idx == 20){
         strcpy_P(ptrStart, &fixedList1[listIdx].caption[0]);
         *item = pgm_read_byte(&fixedList1[listIdx].jumpItem);
         *level = pgm_read_byte(&fixedList1[listIdx].jumpLevel);

       } else if (idx == 21){
    	 strcpy_P(ptrStart, &fixedList2[listIdx].caption[0]);
    	 *item = pgm_read_byte(&fixedList2[listIdx].jumpItem);
    	 *level = pgm_read_byte(&fixedList2[listIdx].jumpLevel);

       } else if (idx == 22){
      	 strcpy_P(ptrStart, &fixedList3[listIdx].caption[0]);
      	 *item = pgm_read_byte(&fixedList3[listIdx].jumpItem);
      	 *level = pgm_read_byte(&fixedList3[listIdx].jumpLevel);

       } else if (idx == 23){
   	     strcpy_P(ptrStart, &fixedList4[listIdx][0]);

       } else if (idx == 24){
      	 strcpy_P(ptrStart, &fixedList5[listIdx][0]);
       } else {
    	 //strcpy_P((char*)cLineBuf, PSTR("--noList--"));
       }
   }
   len = strlen((char*)cLineBuf);
   return len;
}
Exemple #12
0
int main(int argc, char *argv[]) {
    int c, index;
    double dist = 0.0;
    int finish = -1, pace = -1;
    double finishd = -1.0, paced = -1.0;
    int mode = MODE_NONE;

    while ((c = getopt_long(argc, argv, "hd:f:p:", options, &index)) != -1) {
        switch (c) {
            case 'h':
                print_help();
                return 0;

            case 'd':
                if (strcmp("h", optarg) == 0)
                    dist = DIST_HALF;
                else if (strcmp("f", optarg) == 0)
                    dist = DIST_FULL;
                else
                    dist = atof(optarg);
                break;

            case 'f':
                finish = str_to_time(optarg);
                mode = mode | MODE_FTOP;
                break;

            case 'p':
                pace = str_to_time(optarg);
                mode = mode | MODE_PTOF;
                break;

            default:
                break;
        }
    }

    /* main proc */
    /* more than 1 mode are on */
    if (1 < countbits(mode))
        exit_with_error("Selected more than 1 mode.");

    /* calc and prepare result */
    char finish_str[128], pace_str[128];
    if (mode == MODE_FTOP) {
        paced = (double)finish / dist;
        dtime_to_str(paced, pace_str);
        time_to_str(finish, finish_str);
    } else if (mode == MODE_PTOF) {
        finishd = (double)pace * dist;
        time_to_str(pace, pace_str);
        dtime_to_str(finishd, finish_str);
    }

    /* disp results */
    cout << "Results:" << endl;
    cout << "  mode        " << mode_str[mode] << endl;
    cout << "  dist        " << dist << " km" << endl;
    cout << "  finish-time " << finish_str << endl;
    cout << "  pace-time   " << pace_str << " /km" << endl;

    return 0;
}