Exemplo n.º 1
0
void test_regex_replace()
{
    std::string text = "This is a element and this a unique ID.";
    const std::regex pattern("(\\ba (a|e|i|u|o))+");
    std::string replace = "an $2";
    std::string newtext = std::regex_replace(text, pattern, replace);
    std::cout << newtext << std::endl;
    std::cout << std::endl;

    std::string date1 = "1/2/2008";
    std::string date2 = "12.08.2008";
    std::cout << date1 << " -> " << format_date(date1) << std::endl;
    std::cout << date2 << " -> " << format_date(date2) << std::endl;
    std::cout << std::endl;
}
Exemplo n.º 2
0
void		print_long(char *path)
{
	struct stat		filestat;
	struct passwd	*userpswd;
	struct group	*grppswd;
//	int				size_max;

	stat(path, &filestat);
	ft_putstr(perm_display(filestat));
	ft_putstr(" ");
	ft_putnbr(filestat.st_nlink);
	ft_putchar(' ');
	userpswd = getpwuid(filestat.st_uid);
	ft_putstr(userpswd->pw_name);
	ft_putstr("  ");
	grppswd = getgrgid(filestat.st_gid);
	ft_putstr(grppswd->gr_name);
	ft_putstr("  ");
	print_size(filestat.st_size);
	ft_putchar(' ');
	ft_putstr(format_date(ctime(&filestat.st_mtime)));
	ft_putchar(' ');
//  v - Ligne a modifier plus tard, fonctionne dans le cas ou le path contient './'
	ft_putendl(&path[2]);
}
Exemplo n.º 3
0
static void PrintResList(AttrList* ad)
{
  // ad->fPrint(stdout);

  char  attrName[32], attrStartTime[32];
  char  name[128];
  int   StartTime;

  const char* Fmt="%-30s %12s %12s\n";

  printf(Fmt,"Resource Name"," Start Time"," Match Time");
  printf(Fmt,"-------------"," ----------"," ----------");

  int i;

  for (i=1;;i++) {
    sprintf( attrName , "Name%d", i );
    sprintf( attrStartTime , "StartTime%d", i );

    if( !ad->LookupString   ( attrName, name, COUNTOF(name) ) ||
		!ad->LookupInteger  ( attrStartTime, StartTime))
            break;

    char* p=strrchr(name,'@');
    *p='\0';
    time_t Now=time(0)-StartTime;
	printf(Fmt,name,format_date(StartTime),format_time(Now));
  }

  printf(Fmt,"-------------"," ------------"," ------------");
  printf("Number of Resources Used: %d\n",i-1);

  return;
} 
Exemplo n.º 4
0
void format_terminal_message(TerminalData *data, TerminalText *text) {
  struct tm *local = localtime(&(data->time));

  char date_string[20];
  char day_string[20];
  char time_string[20];

  format_date(date_string, 20, local);
  strftime(day_string, 20, "%A", local);
  clock_copy_time_string(time_string, 20);

  make_upper_case(date_string, 20);
  make_upper_case(day_string, 20);
  make_upper_case(time_string, 20);

  const char * format_string = "%s\n" //City
                               "%s\n" //Temperature
                               "%s\n" //Forecast
                               "%s\n" //Date
                               "%s\n" //Day of week
                               "BATTERY %u\n" //Battery
                               "%u STEPS\n" //Step count
                               "%s"; //Time

  snprintf(text->text_buffer, TERMINAL_BUFFER_SIZE, format_string, data->city,
                                                                   data->temperature,
                                                                   data->forecast,
                                                                   date_string,
                                                                   day_string,
                                                                   data->battery_level,
                                                                   data->step_count,
                                                                   time_string);
}
Exemplo n.º 5
0
static void print_tag (FILE * out, const database_t * db, tag_t * tag,
                       cvs_connection_t * s)
{
    fprintf (stderr, "%s %s %s\n",
             format_date (&tag->changeset.time, false),
             tag->branch_versions ? "BRANCH" : "TAG",
             tag->tag);

    tag_t * branch;
    if (tag->parent == NULL)
        branch = NULL;
    else if (tag->parent->type == ct_commit)
        branch = tag->parent->versions[0]->branch;
    else
        branch = as_tag (tag->parent);

    assert (tag->parent == NULL || (branch && branch->last == tag->parent));

    tag->last = &tag->changeset;

    create_fixups (db, branch ? branch->branch_versions : NULL, tag);

    // If the tag is a branch, then rewind the current versions to the parent
    // versions.  The fix-up commits will restore things.  FIXME - we should
    // just initialise the branch correctly!
    if (tag->branch_versions) {
        size_t bytes = sizeof branch->branch_versions[0]
            * (db->files_end - db->files);
        if (branch)
            memcpy (tag->branch_versions, branch->branch_versions, bytes);
        else
            memset (tag->branch_versions, 0, bytes);
    }

    if (tag->parent)
        tag->changeset.mark = tag->parent->mark;
    else
        tag->changeset.mark = 0;

    if (tag->deleted
        && (!tag->merge_source || tag->fixups == tag->fixups_end)) {
        assert (tag->branch_versions == NULL);
        return;
    }

    if (!tag->deleted) {
        fprintf (out, "reset %s/%s\n",
                 tag->branch_versions ? branch_prefix : tag_prefix,
                 *tag->tag ? tag->tag : master);
        if (tag->changeset.mark != 0)
            fprintf (out, "from :%zu\n", tag->changeset.mark);
    }

    if (tag->branch_versions == NULL)
        // For a tag, just force out all the fixups immediately.
        print_fixups (out, db, branch ? branch->branch_versions : NULL,
                      tag, NULL, s);
}
Exemplo n.º 6
0
static void print_commit (FILE * out, const database_t * db, changeset_t * cs,
                          cvs_connection_t * s)
{
    version_t * v = cs->versions[0];

    version_t ** fetch = NULL;
    version_t ** fetch_end = NULL;

    // Get the list of versions to fetch.
    for (version_t ** i = cs->versions; i != cs->versions_end; ++i) {
        if (!(*i)->used)
            continue;

        version_t * cv = version_live (*i);
        if (cv != NULL && cv->mark == SIZE_MAX)
            ARRAY_APPEND (fetch, cv);
    }

    fprintf (stderr, "%s COMMIT", format_date (&cs->time, false));

    // Get the versions.
    grab_versions (out, db, s, fetch, fetch_end);
    xfree (fetch);

    v->branch->last = cs;
    cs->mark = ++mark_counter;
    v->branch->changeset.mark = cs->mark;

    fprintf (out, "commit %s/%s\n",
             branch_prefix, *v->branch->tag ? v->branch->tag : master);
    fprintf (out, "mark :%zu\n", cs->mark);
    fprintf (out, "committer %s <%s> %ld +0000\n",
             v->author, v->author, cs->time);
    fprintf (out, "data %zu\n%s\n", strlen (v->log), v->log);
    for (changeset_t ** i = cs->merge; i != cs->merge_end; ++i)
        if ((*i)->mark == 0)
            fprintf (stderr, "Whoops, out of order!\n");
        else if ((*i)->mark == mark_counter)
            fprintf (stderr, "Whoops, self-ref\n");
        else
            fprintf (out, "merge :%zu\n", (*i)->mark);

    const char * last_path = NULL;
    for (version_t ** i = cs->versions; i != cs->versions_end; ++i)
        if ((*i)->used) {
            version_t * vv = version_normalise (*i);
            if (vv->dead)
                fprintf (out, "D %s\n", vv->file->path);
            else
                fprintf (out, "M %s :%zu %s\n",
                         vv->exec ? "755" : "644", vv->mark, vv->file->path);
            last_path = output_entries_list (
                out, db, v->branch->branch_versions, vv->file, last_path);
        }

    fprintf (stderr, "\n");
}
Exemplo n.º 7
0
static const char *
formatElapsedDate (int dt, AttrList *al, Formatter &)
{
	int now;
	if (al->LookupInteger(ATTR_LAST_HEARD_FROM , now)) {
		return format_date(now - dt);
	}
	return "";
}
Exemplo n.º 8
0
static void grab_versions (FILE * out, const database_t * db,
                           cvs_connection_t * s,
                           version_t ** fetch, version_t ** fetch_end)
{
    if (fetch_end == fetch)
        return;

    if (fetch_end == fetch + 1) {
        grab_version (out, db, s, *fetch);
        return;
    }

    bool idver = true;
    for (version_t ** i = fetch + 1; i != fetch_end; ++i)
        if ((*i)->version != fetch[0]->version) {
            idver = false;
            break;
        }
    if (idver) {
        grab_by_option (out, db, s,
                        fetch[0]->version, NULL,
                        fetch, fetch_end);
        return;
    }

    time_t dmin = fetch[0]->time;
    time_t dmax = fetch[0]->time;
    for (version_t ** i = fetch + 1; i != fetch_end; ++i)
        if ((*i)->time < dmin)
            dmin = (*i)->time;
        else if ((*i)->time > dmax)
            dmax = (*i)->time;

    if (dmax - dmin < 300 && fetch[0]->branch && !fetch[0]->branch->dummy) {
        // Format the date.
        struct tm tm;
        gmtime_r (&dmax, &tm);
        char date[64];
        if (strftime (date, 64, "%d %b %Y %H:%M:%S -0000", &tm) == 0)
            fatal ("strftime failed\n");

        grab_by_option (out, db, s,
                        fetch[0]->branch->tag[0] ? fetch[0]->branch->tag : NULL,
                        format_date (&dmax, true),
                        fetch, fetch_end);

        for (version_t ** i = fetch; i != fetch_end; ++i)
            if ((*i)->mark == SIZE_MAX)
                fprintf (stderr, "Missed first time round: %s %s\n",
                         (*i)->file->path, (*i)->version);
    }

    for (version_t ** i = fetch; i != fetch_end; ++i)
        if ((*i)->mark == SIZE_MAX)
            grab_version (out, db, s, *i);
}
Exemplo n.º 9
0
Arquivo: task.c Projeto: bhutley/pit
static void task_log_create(PTask pt, POptions po)
{
    Action a = { pt->project_id, pt->id, 0 };

    sprintf(a.message, "created task %d: %s (status: %s, priority: %s", pt->id, po->task.name, po->task.status, po->task.priority);
    if (po->task.date > 0) sprintf(a.message + strlen(a.message), ", date: %s", format_date(po->task.date));
    if (po->task.time > 0) sprintf(a.message + strlen(a.message), ", time: %s", format_time(po->task.time));
    sprintf(a.message + strlen(a.message), ", project: %d)", pt->project_id);
    pit_action(&a);
}
Exemplo n.º 10
0
void SystemView::Draw3D()
{
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(50, Pi::GetScrAspect(), 1.0, 1000.0);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glClearColor(0,0,0,0);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	
	SystemPath path = Pi::sectorView->GetSelectedSystem();
	if (m_system) {
		if (!m_system->GetPath().IsSameSystem(path)) {
			m_system.Reset();
			ResetViewpoint();
		}
	}
	m_time += m_timeStep*Pi::GetFrameTime();
	std::string t = Lang::TIME_POINT+format_date(m_time);
	m_timePoint->SetText(t);

	if (!m_system) m_system = StarSystem::GetCached(path);

	glDisable(GL_LIGHTING);
	glEnable(GL_FOG);
	glFogi(GL_FOG_MODE, GL_EXP2);
	glFogfv(GL_FOG_COLOR, fogColor);
	glFogf(GL_FOG_DENSITY, fogDensity);
	glHint(GL_FOG_HINT, GL_NICEST);

	glTranslatef(0,0,-ROUGH_SIZE_OF_TURD);
	glRotatef(m_rot_x, 1, 0, 0);
	glRotatef(m_rot_z, 0, 0, 1);
	
	vector3d pos(0,0,0);
	if (m_selectedObject) GetTransformTo(m_selectedObject, pos);

	m_objectLabels->Clear();
	if (m_system->m_unexplored)
		m_infoLabel->SetText(Lang::UNEXPLORED_SYSTEM_NO_SYSTEM_VIEW);
	else if (m_system->rootBody) {
		PutBody(m_system->rootBody, pos);
		if (Pi::game->GetSpace()->GetStarSystem() == m_system) {
			const Body *navTarget = Pi::player->GetNavTarget();
			const SBody *navTargetSBody = navTarget ? navTarget->GetSBody() : 0;
			if (navTargetSBody)
				PutSelectionBox(navTargetSBody, pos, Color(0.0, 1.0, 0.0, 1.0));
		}
	}

	glEnable(GL_LIGHTING);
	glDisable(GL_FOG);
}
Exemplo n.º 11
0
void ShipCpanel::Draw()
{
	std::string time = format_date(Pi::game->GetTime());
	m_clock->SetText(time);

	View *cur = Pi::GetView();
	if ((cur != Pi::sectorView) && (cur != Pi::systemView) &&
	    (cur != Pi::systemInfoView) && (cur != Pi::galacticView)) {
		HideMapviewButtons();
	}

	Gui::Fixed::Draw();
}
Exemplo n.º 12
0
char *format_datetime(Date d, Time t)
{
    char *dfmt, *tfmt, *ret;

    dfmt = format_date(d);
    tfmt = format_time(t);
    ret = smalloc(2 + strlen(dfmt) + strlen(tfmt));
    sprintf(ret, "%s %s", dfmt, tfmt);
    sfree(dfmt);
    sfree(tfmt);

    return ret;
}
Exemplo n.º 13
0
      std::ostream& operator<< (std::ostream& stream, const Study& item)
      {
        stream << MR::printf ("    %-30s %-16s %10s %8s\n", 
              item.name.c_str(), 
              format_ID(item.ID).c_str(),
              format_date(item.date).c_str(),
              format_time(item.time).c_str() );

        for (size_t n = 0; n < item.size(); n++) 
          stream << *item[n];

        return stream;
      }
Exemplo n.º 14
0
static int format( char * message, const struct config * config )
{
	char * cursor;
	int limit = MESSAGE_LENGTH;
	int formatted;
	const struct param_arg * param_arg;
	int i;
	
	assert( message != NULL );
	assert( config != NULL );
	
	message[ 0 ] = '\0';
	cursor = message;
	
	for( i = 0; i < config->nof_params; ++i )
	{
		param_arg = & config->order[ i ];
		switch( param_arg->param )
		{
			case PARAM_DATE:
				formatted = format_date( cursor, limit, param_arg->arg );
				break;
			case PARAM_TIME:
				formatted = format_time( cursor, limit, param_arg->arg );
				break;
			default:
				return fail( "parameters parsed incorrectly" );
		}
		
		if( formatted < 0 )
			return fail( "can`t format parameter" );
			
		limit -= formatted;
		cursor += formatted;
		
		if( limit == 0 )
			break;
			
		* cursor = ' ';
		++cursor;
		* cursor = '\0';
		--limit;
	}
	
	return 0;
}
Exemplo n.º 15
0
 friend std::ostream& operator << (std::ostream &os, const Calendar<T> &c) {
     os << "BEGIN:VCALENDAR" << std::endl;
     os << "VERSION:2.0" << std::endl;
     os << "PRODID:???????" << std::endl;
     for (auto i = c.event_map.begin(); i != c.event_map.end(); i++) {
         if(i->first >= *(c.dp)) {
             for(auto desc = i->second->begin(); desc != i->second->end(); desc++) {
                 os << "BEGIN:VEVENT" << std::endl;
                 os << "DTSTART:" << format_date(i->first.year(), i->first.month(), i->first.day()) << "T120000" << std::endl;
                 os << "SUMMARY:" << *desc << std::endl;
                 os << "DESCRIPTION:" << *desc << std::endl;
                 os << "END:VEVENT" << std::endl;
             }
         }
     }
     os << "END:VCALENDAR";
     return os;
 }
Exemplo n.º 16
0
static char *
ctime_format (struct timespec ts)
{
  const struct tm * ptm;
#define TIME_BUF_LEN 1024
  static char resultbuf[TIME_BUF_LEN];
  int nout;

  ptm = localtime (&ts.tv_sec);
  if (ptm)
    {
      assert (ptm->tm_wday >=  0);
      assert (ptm->tm_wday <   7);
      assert (ptm->tm_mon  >=  0);
      assert (ptm->tm_mon  <  12);
      assert (ptm->tm_hour >=  0);
      assert (ptm->tm_hour <  24);
      assert (ptm->tm_min  <  60);
      assert (ptm->tm_sec  <= 61); /* allows 2 leap seconds. */

      /* wkday mon mday hh:mm:ss.nnnnnnnnn yyyy */
      nout = snprintf (resultbuf, TIME_BUF_LEN,
                       "%3s %3s %2d %02d:%02d:%02d.%09ld0 %04d",
                       weekdays[ptm->tm_wday],
                       months[ptm->tm_mon],
                       ptm->tm_mday,
                       ptm->tm_hour,
                       ptm->tm_min,
                       ptm->tm_sec,
                       (long int)ts.tv_nsec,
                       1900 + ptm->tm_year);

      assert (nout < TIME_BUF_LEN);
      return resultbuf;
    }
  else
    {
      /* The time cannot be represented as a struct tm.
         Output it as an integer.  */
      return format_date (ts, '@');
    }
}
Exemplo n.º 17
0
Arquivo: task.c Projeto: bhutley/pit
static void task_show(int id)
{
    PTask pt;

    pit_db_load();
    id = task_find_current(id, &pt);

    if (pt) {
        /* printf("The task was created on %s, last updated on %s\n", format_timestamp(pt->created_at), format_timestamp(pt->updated_at)); */
        printf("* %d: (%s) %s (project: %d, status: %s, priority: %s", pt->id, pt->username, pt->name, pt->project_id, pt->status, pt->priority);
        if (pt->date) printf(", date: %s", format_date(pt->date));
        if (pt->time) printf(", time: %s", format_time(pt->time));
        printf(", %d note%s)\n", pt->number_of_notes, pt->number_of_notes != 1 ? "s" : "");
        pit_table_mark(tasks, pt->id);
        if (pt->number_of_notes > 0)
            pit_note_list(pt);
        pit_db_save();
    } else {
        die("could not find the task");
    }
}
Exemplo n.º 18
0
/*
  Print a line of data for the "short" display of a PROC structure.  The
  "short" display is the one used by "condor_q".  N.B. the columns used
  by this routine must match those defined by the short_header routine
  defined above.
*/
void
short_print(
	int cluster,
	int proc,
	const char *owner,
	int date,
	int time,
	int status,
	int prio,
	int image_size,
	const char *cmd
	) {
	printf( "%4d.%-3d %-14s %-11s %-12s %-2c %-3d %-4.1f %-18.18s\n",
		cluster,
		proc,
		owner,
		format_date((time_t)date),
		format_time(time),
		encode_status(status),
		prio,
		image_size/1024.0,
		cmd
	);
}
Exemplo n.º 19
0
void template_preprocess_aggregator_item( map <string, string> &variables ) 
{
	map <string, string> item = variables;

	variables["feed_url"] = check_url( item["link"] );
	variables["feed_title"] = check_plain( item["title"] );
	variables["content"] = aggregator_filter_xss( item["description"] );

	variables["source_url"] = "";
	variables["source_title"] = "";
	if ( isset(item["ftitle"]) && isset(item["fid"]) ) 
	{
		variables["source_url"] = url("aggregator/sources/"+item["fid"]);
		variables["source_title"] = check_plain(item["ftitle"]);
	}
	if ( date("Ymd", item["timestamp"]) == date("Ymd") ) 
	{
		variables["source_date"] = format_interval(time() - intval(item["timestamp"]) ) + " ago";
	}
	else 
	{
		variables["source_date"] = format_date( item["timestamp"] );
	}
}
Exemplo n.º 20
0
static void http_put_date(struct wpabuf *buf)
{
	wpabuf_put_str(buf, "Date: ");
	format_date(buf);
	wpabuf_put_str(buf, "\r\n");
}
Exemplo n.º 21
0
/*
 * Function: Date
 *
 * Create a string representation of the given date/time value.
 *
 * > string = Format.Date(date)
 *
 * Parameters:
 *
 *   date - a date/time value, as seconds since 3200-01-01  00:00:00
 *
 * Return:
 *
 *   string - the string representation
 *
 * Availability:
 *
 *   alpha 10
 *
 * Status:
 *
 *   stable
 */
static int l_format_date(lua_State *l)
{
	double t = luaL_checknumber(l, 1);
	lua_pushstring(l, format_date(t).c_str());
	return 1;
}
Exemplo n.º 22
0
	virtual void UpdateInfo() {
		const float YSEP = Gui::Screen::GetFontHeight() * 1.5f;
		DeleteAllChildren();

		Gui::Label *l = new Gui::Label(Lang::MISSIONS);
		Add(l, 20, 20);

		l = new Gui::Label(Lang::TYPE);
		Add(l, 20, 20+YSEP*2);
		
		l = new Gui::Label(Lang::CLIENT);
		Add(l, 100, 20+YSEP*2);
		
		l = new Gui::Label(Lang::LOCATION);
		Add(l, 260, 20+YSEP*2);
		
		l = new Gui::Label(Lang::DUE);
		Add(l, 420, 20+YSEP*2);
		
		l = new Gui::Label(Lang::REWARD);
		Add(l, 580, 20+YSEP*2);

		l = new Gui::Label(Lang::STATUS);
		Add(l, 680, 20+YSEP*2);

		ShowChildren();

		Gui::VScrollBar *scroll = new Gui::VScrollBar();
		Gui::VScrollPortal *portal = new Gui::VScrollPortal(760);
		scroll->SetAdjustment(&portal->vscrollAdjust);

		const std::list<const Mission*> &missions = Pi::player->missions.GetAll();
		Gui::Fixed *innerbox = new Gui::Fixed(760, YSEP*3 * missions.size());

		float ypos = 0;
		for (std::list<const Mission*>::const_iterator i = missions.begin(); i != missions.end(); ++i) {
			SystemPath path = (*i)->location;
			StarSystem *s = StarSystem::GetCached(path);
			SBody *sbody = s->GetBodyByPath(&path);

			l = new Gui::Label((*i)->type);
			innerbox->Add(l, 0, ypos);
			
			l = new Gui::Label((*i)->client);
			innerbox->Add(l, 80, ypos);
			
			l = new Gui::Label(stringf("%0,\n%1 [%2{d},%3{d},%4{d}]", sbody->name.c_str(), s->GetName().c_str(), path.sectorX, path.sectorY, path.sectorZ));
			innerbox->Add(l, 240, ypos);
			
			l = new Gui::Label(format_date((*i)->due));
			innerbox->Add(l, 400, ypos);

			l = new Gui::Label(format_money((*i)->reward));
			innerbox->Add(l, 560, ypos);

			switch ((*i)->status) {
                case Mission::FAILED: l = new Gui::Label(std::string("#f00")+std::string(Lang::FAILED)); break;
                case Mission::COMPLETED: l = new Gui::Label(std::string("#ff0")+std::string(Lang::COMPLETED)); break;
				default:
                case Mission::ACTIVE: l = new Gui::Label(std::string("#0f0")+std::string(Lang::ACTIVE)); break;
			}
			innerbox->Add(l, 660, ypos);

			ypos += YSEP*3;
		}
		Add(portal, 20, 20 + YSEP*3);
		Add(scroll, 780, 20 + YSEP*3);
		scroll->ShowAll();
		portal->Add(innerbox);
		portal->ShowAll();
	}
Exemplo n.º 23
0
void
new_record(int cluster, int proc, int start_time, int evict_time, 
		   int good_time, int cpu_usage, char const *host)
{
	static bool initialized = false;
	char hash[40];
	int wall_time = evict_time-start_time;

	// We detect bad records here.  One cause of bad records is the
	// fact that userlogs timestamps do not contain years, so we
	// always assume we are in the same year, which causes time to run
	// backwards at the turn of the year.
	if (wall_time < 0 ||
		good_time < 0 ||
		cpu_usage < 0) {
		if (debug_mode) {
			fprintf(stderr, "internal error: negative time computed for "
					"%d.%d!\n", cluster, proc);
			fprintf(stderr, "  (records around the turn of "
					"the year are not handled correctly)\n");
		}
		return;
	}

	sprintf(hash, "%d.%d", cluster, proc);
	HashKey jobkey(hash);

	JobStatistics *js;
	if (Stats.lookup(jobkey, js) < 0) {
		js = new JobStatistics(cluster, proc);
		Stats.insert(jobkey, js);
		numJobStats++;
	}
	js->allocations++;
	js->kills += (wall_time != good_time);
	js->wall_time += wall_time;
	js->good_time += good_time;
	js->cpu_usage += cpu_usage;

	char ip_addr[128];
	// only use the IP address in the key [TODO:IPV6] Parse IPv6 Addr
	strncpy(ip_addr, host+1, sizeof(ip_addr)-1);
	ip_addr[sizeof(ip_addr)-1] = '\0';
	for (int i=0; i < 128; i++) {
		if (ip_addr[i] == ':') {
			ip_addr[i] = '\0';
			break;
		}
	}
	HostStatistics *hs;
	HashKey hostkey(ip_addr);
	if (HStats.lookup(hostkey, hs) < 0) {
		condor_sockaddr addr;
		const char* hostname = NULL;
		MyString hostname_str;
		addr.from_sinful(host);
		if (!avoid_dns) {
			hostname_str = get_hostname(addr);
			hostname = hostname_str.Value();
		}
		if (hostname == NULL) {
			hostname = ip_addr;
		}
		hs = new HostStatistics(hostname);
		HStats.insert(hostkey, hs);
		numHostStats++;
	}
	hs->allocations++;
	hs->kills += (wall_time != good_time);
	hs->wall_time += wall_time;
	hs->good_time += good_time;
	hs->cpu_usage += cpu_usage;

	if (!totals_only) {
		if (!raw_data && !initialized) {
			printf("\n");
			printf("%-8.8s %-15.15s %-11.11s %-11.11s %9s %9s %9s\n",
				   "Job", "Host", "Start Time", "Evict Time", "Wall Time",
				   "Good Time", "CPU Usage");
			initialized = true;
		}

		printf("%-8.8s %-15.15s ", hash, hs->host);
		printf("%11s ", format_date(start_time));
		printf("%11s ", format_date(evict_time));
		printf("%9s ", format_time_nosecs(wall_time));
		printf("%9s ", format_time_nosecs(good_time));
		printf("%9s\n", format_time_nosecs(cpu_usage));
	}
}
Exemplo n.º 24
0
/**************************************************************************
 *
 *N  vpf_dump_table
 *
 *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Purpose:
 *P
 *    Dump the contents of a VPF table into an ASCII file
 *E
 *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Parameters:
 *A
 *    tablename <input> == (char *) VPF table to dump.
 *    outname   <input> == (char *) name of ASCII dump file.
 *E
 *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   History:
 *H
 *    Barry Michaels  DOS Turbo C
 *E
 *************************************************************************/
void vpf_dump_table( char *tablename, char *outname )
{
   vpf_table_type table;
   long int   i,j,k,n;
   int        ival,*iptr;
   long int   lval,*lptr;
   float      fval,*fptr;
   date_type  dval,*dptr;
   id_triplet_type kval, *kptr;
   coordinate_type cval, *cptr;
   char       *buf,  ch, date[40];
   row_type   row;
   FILE       *fp;

   fp = fopen(outname,"w");

   table = vpf_open_table(tablename,disk,"rb",NULL);

   fprintf(fp,"%s\n%s\n\n",tablename,table.description);

   fprintf(fp,"Definition:\n");
   for (i=0;i<table.nfields;i++) {
      if (table.header[i].count < 0)
	 fprintf(fp,"%s (%c,*)  %s\n",
		 table.header[i].name,table.header[i].type,
		 table.header[i].description);
      else
	 fprintf(fp,"%s (%c,%ld)  %s\n",
		 table.header[i].name,table.header[i].type,
		 table.header[i].count,table.header[i].description);
   }

   fprintf(fp,"\nContents:\n");
   for (i=1;i<=table.nrows;i++) {
      row = read_next_row(table);
      for (j=0;j<table.nfields;j++) {
	 fprintf(fp,"%s: ",table.header[j].name);
	 switch (table.header[j].type) {
	    case 'T':
	       if (table.header[j].count==1) {
		  get_table_element(j,row,table,&ch,&n);
		  fprintf(fp,"%c\n",ch);
	       } else {
		  buf = (char *)get_table_element(j,row,table,NULL,&n);
		  n = (long)strlen(table.header[j].name) + 2;
		  for (k=0;(unsigned int)k<strlen(buf);k++) {
		     fprintf(fp,"%c",buf[k]);
		     n++;
		     if (n>80) {
			fprintf(fp,"\n");
			n = 0;
		     }
		  }
		  fprintf(fp,"\n");
		  free(buf);
	       }
	       break;
	    case 'I':
	       if (table.header[j].count==1) {
		  get_table_element(j,row,table,&lval,&n);
		  if (lval != MAXFLOAT)
		     fprintf(fp,"%ld\n",lval);
		  else
		     fprintf(fp,"(null)\n");
	       } else {
		  lptr = (long int*)get_table_element(j,row,table,NULL,&n);
		  for (k=0;k<n;k++) {
		     if (lptr[k] != MAXFLOAT)
			fprintf(fp,"%ld ",lptr[k]);
		     else
			fprintf(fp,"(null) ");
		  }
		  fprintf(fp,"\n");
		  free(lptr);
	       }
	       break;
	    case 'S':
	       if (table.header[j].count==1) {
		  get_table_element(j,row,table,&ival,&n);
		  if (ival != MAXINT)
		     fprintf(fp,"%d\n",ival);
		  else
		     fprintf(fp,"(null)\n");
	       } else {
		  iptr = (int*)get_table_element(j,row,table,NULL,&n);
		  for (k=0;k<n;k++) {
		     if (iptr[k] != MAXINT)
			fprintf(fp,"%d ",iptr[k]);
		     else
			fprintf(fp,"(null) ");
		  }
		  fprintf(fp,"\n");
		  free(iptr);
	       }
	       break;
	    case 'F':
	       if (table.header[j].count==1) {
		  get_table_element(j,row,table,&fval,&n);
		  if (fval != MAXFLOAT)
		     fprintf(fp,"%f\n",fval);
		  else
		     fprintf(fp,"(null)\n");
	       } else {
		  fptr = (float*)get_table_element(j,row,table,NULL,&n);
		  for (k=0;k<n;k++) {
		     if (fptr[k] != MAXFLOAT)
			fprintf(fp,"%f ",fptr[k]);
		     else
			fprintf(fp,"(null) ");
		  }
		  fprintf(fp,"\n");
		  free(fptr);
	       }
	       break;
	    case 'C':
	       if (table.header[j].count==1) {
		  get_table_element(j,row,table,&cval,&n);
		  fprintf(fp,"(%f,%f)\n",cval.x,cval.y);
	       } else {
		  cptr = (coordinate_type*)get_table_element(j,row,table,NULL,&n);
		  for (k=0;k<n;k++)
		     fprintf(fp,"(%f,%f) ",cptr[k].x,cptr[k].y);
		  fprintf(fp,"\n");
		  free(cptr);
	       }
	       break;
	    case 'K':
	       if (table.header[j].count==1) {
		  get_table_element(j,row,table,&kval,&n);
		  fprintf(fp,"(%ld,%ld,%ld)\n",
			  kval.id,kval.tile,kval.exid);
	       } else {
		  kptr = (id_triplet_type*)get_table_element(j,row,table,NULL,&n);
		  for (k=0;k<n;k++)
		     fprintf(fp,"(%ld,%ld,%ld)  ",
			     kptr[k].id,kptr[k].tile,kptr[k].exid);
		  fprintf(fp,"\n");
		  free(kptr);
	       }
	       break;
	    case 'D':   /* Date */
	       if (table.header[j].count==1) {
		  get_table_element(j,row,table,&dval,&n);
		  format_date(dval,date);
		  fprintf(fp,"%s\n",date);
	       } else {
		  dptr = (date_type*)get_table_element(j,row,table,NULL,&n);
		  for (k=0;k<n;k++) {
		     format_date((char*)(&dptr[k]),date);
		     fprintf(fp,"%s ",date);
		  }
		  fprintf(fp,"\n");
		  free(dptr);
	       }
	       break;
	 }
      }
      fprintf(fp,"\n");
      free_row( row, table );
   }

   fclose(fp);
   vpf_close_table( &table );
}
Exemplo n.º 25
0
bool
pred_fprintf (const char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
  struct format_val *dest = &pred_ptr->args.printf_vec;
  struct segment *segment;

  for (segment = dest->segment; segment; segment = segment->next)
    {
      if ( (KIND_FORMAT == segment->segkind) && segment->format_char[1]) /* Component of date. */
        {
          struct timespec ts;
          int valid = 0;

          switch (segment->format_char[0])
            {
            case 'A':
              ts = get_stat_atime (stat_buf);
              valid = 1;
              break;
            case 'B':
              ts = get_stat_birthtime (stat_buf);
              if ('@' == segment->format_char[1])
                valid = 1;
              else
                valid = (ts.tv_nsec >= 0);
              break;
            case 'C':
              ts = get_stat_ctime (stat_buf);
              valid = 1;
              break;
            case 'T':
              ts = get_stat_mtime (stat_buf);
              valid = 1;
              break;
            default:
              assert (0);
              abort ();
            }
          /* We trust the output of format_date not to contain
           * nasty characters, though the value of the date
           * is itself untrusted data.
           */
          if (valid)
            {
              /* trusted */
              checked_fprintf (dest, segment->text,
                               format_date (ts, segment->format_char[1]));
            }
          else
            {
              /* The specified timestamp is not available, output
               * nothing for the timestamp, but use the rest (so that
               * for example find foo -printf '[%Bs] %p\n' can print
               * "[] foo").
               */
              /* trusted */
              checked_fprintf (dest, segment->text, "");
            }
        }
      else
        {
          /* Print a segment which is not a date. */
          do_fprintf (dest, segment, pathname, stat_buf);
        }
    }
  return true;
}
Exemplo n.º 26
0
void ossimVpfTable::print(std::ostream& out)const
{
   if(theTableInformation &&
      (theTableInformation->status!=CLOSED))
   {
      // make sure we are at the beginning of the table.
      this->reset();


      // the rest of this code is from the vpfutil.  The vpfutil
      // was grabbed from the vhcl map server software.
      vpf_table_type& table = *theTableInformation;

      ossim_int32       i,j,k,n;
      ossim_int16  ival=0,*iptr=NULL;
      ossim_int32       lval=0,*lptr=NULL;
      ossim_float32      fval=0,*fptr=NULL;
      date_type  dval,*dptr=NULL;
      id_triplet_type kval={0,0,0}, *kptr=NULL;
      coordinate_type cval={0,0}, *cptr=NULL;
      char       *buf,  ch, date[40];
      row_type   row;


    out << "table name:        " << theTableName << std::endl
      << "desciption:        " << table.description << std::endl
      << std::endl;

    out << "Definition:" << std::endl;
      for (i=0;i<table.nfields;i++) {
         if (table.header[i].count < 0)
         {

            out << table.header[i].name << " ("
                << table.header[i].type << ",*)  "
        << table.header[i].description << std::endl;
         }
         else
         {
            out << table.header[i].name << " ("
                << table.header[i].type << ","
                << table.header[i].count << ")  "
        << table.header[i].description << std::endl;
         }
      }

    out << "\nContents:" << std::endl;
      for (i=1;i<=table.nrows;i++)
      {
         row = read_next_row(table);
         for (j=0;j<table.nfields;j++)
         {
            out << table.header[j].name << ": ";
            switch (table.header[j].type) {
      case 'T':
         if (table.header[j].count==1)
               {
      get_table_element(j,row,table,&ch,&n);

      out << ch << std::endl;
         }
               else
               {
      buf = (char *)get_table_element(j,row,table,NULL,&n);
      n = (long)strlen(table.header[j].name) + 2;
      for (k=0;k<(long)strlen(buf);k++)
                  {
                     out << buf[k];
         n++;
         if (n>80)
                     {
             out << std::endl;
      n = 0;
         }
      }
          out << std::endl;
      free(buf);
         }
         break;
      case 'I': // long
         if (table.header[j].count==1)
               {
      get_table_element(j,row,table,&lval,&n);
      if (!is_vpf_null_float(lval))
                  {
            out << lval << std::endl;
                  }
      else
                  {
            out << "null" << std::endl;
                  }
         }
               else
               {
      lptr = (ossim_int32*)get_table_element(j,row,table,NULL,&n);
      for (k=0;k<n;k++)
                  {
         if (!is_vpf_null_float(lptr[k]))
                     {
                        out << lptr[k];
                     }
         else
                     {
                        out << "null";
                     }
      }
          out << std::endl;
      free(lptr);
         }
         break;
            case 'R': // for double
            {
               double *dptr=NULL;
               double value = 0;
         if (table.header[j].count==1)
               {
      get_table_element(j,row,table,&value,&n);
                  if(!is_vpf_null_double(value))
                  {
            out << "null" << std::endl;
                  }
                  else
                  {
            out << value << std::endl;
                  }
               }
               else
               {
      dptr = (double*)get_table_element(j,row,table,NULL,&n);
      for (k=0;k<n;k++)
                  {
         if (!is_vpf_null_double(dptr[k]))
                     {
                        out << dptr[k];
                     }
         else
                     {
                        out << "null ";
                     }
      }
          out << std::endl;
      free(dptr);
               }
            }
      case 'S': // integer
         if (table.header[j].count==1)
               {
      get_table_element(j,row,table,&ival,&n);
      if (ival != (short int)INT_MAX)
                  {
            out << ival << std::endl;
                  }
      else
                  {
            out << "null" << std::endl;
                  }
         }
               else
               {
      iptr = (short int*)get_table_element(j,row,table,NULL,&n);
      for (k=0;k<n;k++)
                  {
         if (iptr[k] != (short int)INT_MAX)
                     {
                        out << iptr[k];
                     }
         else
                     {
                        out << "null ";
                     }
      }
          out << std::endl;
      free(iptr);
         }
         break;
      case 'F': // float type
         if (table.header[j].count==1)
               {
      get_table_element(j,row,table,&fval,&n);
      if (!is_vpf_null_float(fval))
                  {
            out << fval << std::endl;
                  }
      else
                  {
            out << "null" << std::endl;
                  }
         }
               else
               {
      fptr = (float*)get_table_element(j,row,table,NULL,&n);
      for (k=0;k<n;k++)
                  {
         if (!is_vpf_null_float(fptr[k]))
                     {
                        out << fptr[k] << " ";
                     }
         else
                     {
                        out << "null ";
                     }
      }
          out << std::endl;
      free(fptr);
         }
         break;
            case 'Y':
            {
               double_tri_coordinate_type dtctValue, *dtctPtr;
         if (table.header[j].count==1)
               {
                  get_table_element(j,row,table,&dtctValue,&n);
                  out << "(";
                  if(is_vpf_null_double(dtctValue.x))
                  {
                     out << "null, ";
                  }
                  else
                  {
                     out << dtctValue.x << ", ";
                  }
                  if(is_vpf_null_double(dtctValue.y))
                  {
                     out << "null, ";
                  }
                  else
                  {
                     out << dtctValue.y << ", ";
                  }
                  if(is_vpf_null_double(dtctValue.z))
                  {
                     out << "null, ";
                  }
                  else
                  {
                     out << dtctValue.z << ", ";
                  }
               }
               else
               {
      dtctPtr = (double_tri_coordinate_type*)get_table_element(j,row,table,NULL,&n);
      for (k=0;k<n;k++)
                  {
                     out << "(";
                     if(is_vpf_null_double(dtctPtr[k].x))
                     {
                        out << "null, ";
                     }
                     else
                     {
                        out << dtctPtr[k].x  << ", ";
                     }
                     if(is_vpf_null_double(dtctPtr[k].y))
                     {
                        out << "null, ";
                     }
                     else
                     {
                        out << dtctPtr[k].y  << ", ";
                     }
                     if(is_vpf_null_double(dtctPtr[k].z))
                     {
                        out << "null, ";
                     }
                     else
                     {
                        out << dtctPtr[k].z  << ", ";
                     }
                  }
                  free(dtctPtr);
               }
               break;
            }
            case 'Z': // tri coordinate types x, y, z
            {
               tri_coordinate_type tcval={0,0,0}, *tcptr=NULL;
         if (table.header[j].count==1)
               {
      get_table_element(j,row,table,&tcval,&n);
                  out << "(";
                  if(is_vpf_null_float(tcval.x))
                  {
                     out << "null" << ",";
                  }
                  else
                  {
                     out << tcval.x << ", ";
                  }
                  if(is_vpf_null_float(tcval.y))
                  {
                     out << "null" << ", ";
                  }
                  else
                  {
                     out << tcval.y << ", ";
                  }
                  if(is_vpf_null_float(tcval.z))
                  {
            out << "null)" << std::endl;
                  }
                  else
                  {
            out << tcval.z << ")" << std::endl;
                  }
         }
               else
               {
      tcptr = (tri_coordinate_type*)get_table_element(j,row,table,NULL,&n);
      for (k=0;k<n;k++)
                  {
                     out << "(";
                     if(is_vpf_null_float(tcptr[k].x))
                     {
                        out << "null, ";
                     }
                     else
                     {
                        out << tcptr[k].x << ", ";
                     }
                     if(is_vpf_null_float(tcptr[k].y))
                     {
                        out << "null, ";
                     }
                     else
                     {
                        out << tcptr[k].y << ", ";
                     }
                     if(is_vpf_null_float(tcptr[k].z))
                     {
                        out << "null)";
                     }
                     else
                     {
                        out << tcptr[k].z << ")";
                     }
                  }
          out << std::endl;
      free(tcptr);
         }
         break;
            }
      case 'C': // coordinate type  x, y
         if (table.header[j].count==1)
               {
      get_table_element(j,row,table,&cval,&n);
                  out << "(";
                  if(is_vpf_null_float(cval.x))
                  {
                     out << "null, ";
                  }
                  else
                  {
                     out << cval.x << ", ";
                  }
                  if(is_vpf_null_float(cval.y))
                  {
                     out << "null, ";
                  }
                  else
                  {
                     out << cval.y << ")";
                  }
         }
               else
               {
      cptr = (coordinate_type*)get_table_element(j,row,table,NULL,&n);
      for (k=0;k<n;k++)
                  {

                     out << "(" << cptr[k].x << "," << cptr[k].y << ") ";
                  }
          out << std::endl;
      free(cptr);
         }
         break;
            case 'B': // double coordinate type
            {
               double_coordinate_type dct, *dctPtr;

         if (table.header[j].count==1)
               {
      get_table_element(j,row,table,&dct,&n);

                  out << "(";
                  if(is_vpf_null_double(dct.x))
                  {
                     out << "null, ";
                  }
                  else
                  {
                     out << dct.x << ", ";
                  }
                  if(is_vpf_null_double(dct.y))
                  {
                     out << "null, ";
                  }
                  else
                  {
                     out << dct.y << ")";
                  }
         }
               else
               {
      dctPtr = (double_coordinate_type*)get_table_element(j,row,table,NULL,&n);
      for (k=0;k<n;k++)
                  {
                     out << "(";
                     if(is_vpf_null_double(dctPtr[k].x))
                     {
                        out << "null,";
                     }
                     else
                     {
                        out << dctPtr[k].x << ", ";
                     }
                     if(is_vpf_null_double(dctPtr[k].y))
                     {
                        out << "null,";
                     }
                     else
                     {
                        out << dctPtr[k].y << ", ";
                     }
                  }
          out << std::endl;
      free(dctPtr);
         }

            }
      case 'K': //id triplet
         if (table.header[j].count==1)
               {
      get_table_element(j,row,table,&kval,&n);
                  out <<  "(" << kval.id
                      << ", " << kval.tile
                      << ", " << kval.exid
            << ")" << std::endl;
         }
               else
               {
      kptr = (id_triplet_type*)get_table_element(j,row,table,NULL,&n);
      for (k=0;k<n;k++)
                  {
                     out <<  "(" << kptr[k].id
                         << ", " << kptr[k].tile
                         << ", " << kptr[k].exid
             << ")  " << std::endl;

                  }
          out << std::endl;
      free(kptr);
         }
         break;
      case 'D':   /* Date */
         if (table.header[j].count==1)
               {
      get_table_element(j,row,table,&dval,&n);
      format_date(dval,date);
      out << date << std::endl;
         }
               else
               {
      dptr = (date_type*)get_table_element(j,row,table,NULL,&n);
      for (k=0;k<n;k++)
                  {
         format_date((char*)(&dptr[k]),date);
                     out << dptr[k] << " ";
      }
          out << std::endl;
      free(dptr);
         }
         break;
            }
         }
     out << std::endl;
         free_row( row, table );
      }
   }
}
Exemplo n.º 27
0
ossimString ossimVpfTable::getColumnValueAsString(row_type& row,
                                                  long columnNumber)const
{
   ossimString result;
   ossim_int32 n=1;
   switch(theTableInformation->header[columnNumber].type)
   {
   case 'T': // it's of type text so
   {
      char c;
      char *buf = (char *)get_table_element(columnNumber,
                                            row,
                                            *theTableInformation,
                                            &c,
                                            &n);
      if(buf)
      {
         result = buf;
         free(buf);
      }
      else
      {
         result = c;
      }
      break;
   }
   case 'I':
   {
      ossim_int32 value;
      ossim_int32* v = (ossim_int32*)get_table_element(columnNumber,
                                                       row,
                                                       *theTableInformation,
                                                       &value,
                                                       &n);
      if(v)
      {
         result = ossimString::toString(v[0]);

         free(v);
      }
      else
      {
         result = ossimString::toString(value);
      }
      break;
   }
   case 'S':
   {
      short int value;
      short int* v = (short int*)get_table_element(columnNumber,
                                                   row,
                                                   *theTableInformation,
                                                   &value,
                                                   &n);
      if(v)
      {
         result = ossimString::toString(v[0]);

         free(v);
      }
      else
      {
         result = ossimString::toString(value);
      }
      break;
   }
   case 'F':
   {
      float value;
      float* v = (float*)get_table_element(columnNumber,
                                           row,
                                           *theTableInformation,
                                           &value,
                                           &n);
      if(v)
      {
         value = v[0];
         free(v);
      }
      if (!is_vpf_null_float(value))
      {
         result = ossimString::toString(value);
      }
      else
      {
         result = "nan";
      }
      break;
   }
   case 'B':
   {
      double value;
      double* tempBuf = (double*)get_table_element(columnNumber,
                                                 row,
                                                 *theTableInformation,
                                                 &value,
                                                 &n);
      if(tempBuf)
      {
         value = tempBuf[0];
         free(tempBuf);
      }
      if (!is_vpf_null_double(value))
      {
         result = ossimString::toString(value);
      }
      else
      {
         result = "nan";
      }

      break;
   }
   case 'C':
   {
      coordinate_type coordType;
      coordinate_type* temp = (coordinate_type*)get_table_element(columnNumber,
                                                                  row,
                                                                  *theTableInformation,
                                                                  &coordType,
                                                                  &n);
      if(temp)
      {
         coordType = temp[0];
         free(temp);
      }
      result = ossimString::toString(coordType.x)+
               ossimString(" ") +
               ossimString::toString(coordType.y);
      break;
   }
   case 'K':
   {
      id_triplet_type idTripletType;
      id_triplet_type* tempType = (id_triplet_type*)get_table_element(columnNumber,
                                                                      row,
                                                                      *theTableInformation,
                                                                      &idTripletType,
                                                                      &n);
      if(tempType)
      {
         idTripletType = tempType[0];
         free (tempType);
      }
      result = ossimString(idTripletType.type) +
         ossimString(" ") +
         ossimString::toString(static_cast<ossim_int32>(idTripletType.id)) +
         ossimString(" ") +
         ossimString::toString(static_cast<ossim_int32>(idTripletType.tile))+
         ossimString(" ") +
         ossimString::toString(static_cast<ossim_int32>(idTripletType.exid));
      break;
   }
   case 'D':
   {
      date_type date, formatDate;
      date_type* temp = (date_type*)get_table_element(columnNumber,
                                                      row,
                                                      *theTableInformation,
                                                      &date,
                                                      &n);
      if(temp)
      {
         free(temp);
      }
      format_date(date, formatDate);
      result = formatDate;
      break;
   }
   case 'Z': // tri coordinate types x, y, z
   {
      tri_coordinate_type  *tcptr=NULL;
      tcptr = (tri_coordinate_type *) get_table_element(columnNumber,row,
                                                        *theTableInformation, NULL,&n);
      result = "";
      for (int k=0;k<n;k++)
      {
         
         result = result + " (" +
            ossimString::toString(tcptr[k].x) +
            ossimString(" ") +
            ossimString::toString(tcptr[k].y) +
            ossimString(" ") +
            ossimString::toString(tcptr[k].z) +
            ossimString(") ") ;
      }
      
      if (tcptr)
      {
         free(tcptr);
      }
      break;
   }   
   }
   result.trim();
   return result;
}
Exemplo n.º 28
0
static int sqlite_log(struct ast_cdr *cdr)
{
	int res = 0;
	char *zErr = 0;
	char startstr[80], answerstr[80], endstr[80];
	int count;
#if LOG_HRTIME
	double hrbillsec = 0.0;
	double hrduration;
#endif

	ast_mutex_lock(&sqlite_lock);

	format_date(startstr, sizeof(startstr), &cdr->start);
	format_date(answerstr, sizeof(answerstr), &cdr->answer);
	format_date(endstr, sizeof(endstr), &cdr->end);

#if LOG_HRTIME
	if (!ast_tvzero(cdr->answer)) {
		hrbillsec = (double) ast_tvdiff_us(cdr->end, cdr->answer) / 1000000.0;
	}
	hrduration = (double) ast_tvdiff_us(cdr->end, cdr->start) / 1000000.0;
#endif

	for(count=0; count<5; count++) {
		res = sqlite_exec_printf(db,
			"INSERT INTO cdr ("
				"clid,src,dst,dcontext,"
				"channel,dstchannel,lastapp,lastdata, "
				"start,answer,end,"
				"duration,billsec,disposition,amaflags, "
				"accountcode"
#				if LOG_UNIQUEID
				",uniqueid"
#				endif
#				if LOG_USERFIELD
				",userfield"
#				endif
			") VALUES ("
				"'%q', '%q', '%q', '%q', "
				"'%q', '%q', '%q', '%q', "
				"'%q', '%q', '%q', "
#if LOG_HRTIME
				"%f, %f, %d, %d, "
#else
				"%d, %d, %d, %d, "
#endif
				"'%q'"
#				if LOG_UNIQUEID
				",'%q'"
#				endif
#				if LOG_USERFIELD
				",'%q'"
#				endif
			")", NULL, NULL, &zErr,
				cdr->clid, cdr->src, cdr->dst, cdr->dcontext,
				cdr->channel, cdr->dstchannel, cdr->lastapp, cdr->lastdata,
				startstr, answerstr, endstr,
#if LOG_HRTIME
				hrduration, hrbillsec, cdr->disposition, cdr->amaflags,
#else
				cdr->duration, cdr->billsec, cdr->disposition, cdr->amaflags,
#endif
				cdr->accountcode
#				if LOG_UNIQUEID
				,cdr->uniqueid
#				endif
#				if LOG_USERFIELD
				,cdr->userfield
#				endif
			);
		if (res != SQLITE_BUSY && res != SQLITE_LOCKED)
			break;
		usleep(200);
	}

	if (zErr) {
		ast_log(LOG_ERROR, "cdr_sqlite: %s\n", zErr);
		ast_free(zErr);
	}

	ast_mutex_unlock(&sqlite_lock);
	return res;
}
Exemplo n.º 29
0
void format_string_code(unsigned int format_code, char **dest, char **args)
{
	int value;

	switch (format_code) {
	case FORMAT_COMMA32:
		// Pop argument
		value = *((sint32*)*args);
		*args += 4;

		format_comma_separated_integer(dest, value);
		break;
	case FORMAT_INT32:
		// Pop argument
		value = *((sint32*)*args);
		*args += 4;

		format_integer(dest, value);
		break;
	case FORMAT_COMMA2DP32:
		// Pop argument
		value = *((sint32*)*args);
		*args += 4;

		format_comma_separated_fixed_2dp(dest, value);
		break;
		case FORMAT_COMMA1DP16:
		// Pop argument
		value = *((sint16*)*args);
		*args += 2;

		format_comma_separated_fixed_1dp(dest, value);
		break;
	case FORMAT_COMMA16:
		// Pop argument
		value = *((sint16*)*args);
		*args += 2;

		format_comma_separated_integer(dest, value);
		break;
	case FORMAT_UINT16:
		// Pop argument
		value = *((uint16*)*args);
		*args += 2;

		format_integer(dest, value);
		break;
	case FORMAT_CURRENCY2DP:
		// Pop argument
		value = *((sint32*)*args);
		*args += 4;

		format_currency_2dp(dest, value);
		break;
	case FORMAT_CURRENCY:
		// Pop argument
		value = *((sint32*)*args);
		*args += 4;

		format_currency(dest, value);
		break;
	case FORMAT_STRINGID:
	case FORMAT_STRINGID2:
		// Pop argument
		value = *((uint16*)*args);
		*args += 2;

		format_string_part(dest, value, args);
		(*dest)--;
		break;
	case FORMAT_STRING:
		// Pop argument
		value = *((uint32*)*args);
		*args += 4;

		if (value != 0) {
			strcpy(*dest, (char*)value);
			*dest += strlen(*dest);
		}
		break;
	case FORMAT_MONTHYEAR:
		// Pop argument
		value = *((uint16*)*args);
		*args += 2;

		format_date(dest, value);
		break;
	case FORMAT_MONTH:
		// Pop argument
		value = *((uint16*)*args);
		*args += 2;

		strcpy(*dest, language_get_string(STR_MONTH_MARCH + date_get_month(value)));
		*dest += strlen(*dest);
		break;
	case FORMAT_VELOCITY:
		// Pop argument
		value = *((sint16*)*args);
		*args += 2;

		format_velocity(dest, value);
		break;
	case FORMAT_POP16:
		*args += 2;
		break;
	case FORMAT_PUSH16:
		*args -= 2;
		break;
	case FORMAT_DURATION:
		// Pop argument
		value = *((uint16*)*args);
		*args += 2;

		format_duration(dest, value);
		break;
	case FORMAT_REALTIME:
		// Pop argument
		value = *((uint16*)*args);
		*args += 2;

		format_realtime(dest, value);
		break;
	case FORMAT_LENGTH:
		// Pop argument
		value = *((sint16*)*args);
		*args += 2;

		format_length(dest, value);
		break;
	case FORMAT_SPRITE:
		// Pop argument
		value = *((uint32*)*args);
		*args += 4;

		*(*dest)++ = 23;
		*((uint32*)(*dest)) = value;
		*dest += 4;
		break;
	}
}
Exemplo n.º 30
0
int main(int argc,char **argv)
{
  int n;
  int curr_arg;
  bool bDebug;
  bool bNoSort;
  int session_ix;
  FILE *fptr;
  int line_len;
  int set_size;
  int chara;
  int *sort_ixs;
  int retval;
  char *cpt;
  int num_rebounds;
  int in_losing_streak;
  int rebound_ix;
  int cumulative_loss;
  int cumulative_gain;
  int work;

  if ((argc < 2) || (argc > 4)) {
    printf(usage);
    return 1;
  }

  bDebug = false;
  bNoSort = false;

  for (curr_arg = 1; curr_arg < argc; curr_arg++) {
    if (!strcmp(argv[curr_arg],"-debug"))
      bDebug = true;
    else if (!strcmp(argv[curr_arg],"-no_sort"))
      bNoSort = true;
    else
      break;
  }

  if (argc - curr_arg != 1) {
    printf(usage);
    return 2;
  }

  if ((fptr = fopen(argv[curr_arg],"r")) == NULL) {
    printf(couldnt_open,argv[curr_arg]);
    return 3;
  }

  set_size = 0;

  for ( ; ; ) {
    GetLine(fptr,line,&line_len,MAX_LINE_LEN);

    if (feof(fptr))
      break;

    if (!line_len)
      continue;

    chara = line[0];

    if (((chara >= 'a') && (chara <= 'z')) ||
        ((chara >= 'A') && (chara <= 'Z')))
      continue;

    set_size++;
  }

  if ((session_info = (struct session_info_struct *)malloc(
    set_size * sizeof (struct session_info_struct))) == NULL) {
    printf(malloc_failed1,set_size);
    fclose(fptr);
    return 4;
  }

  fseek(fptr,0L,SEEK_SET);

  session_ix = 0;

  for ( ; ; ) {
    GetLine(fptr,line,&line_len,MAX_LINE_LEN);

    if (feof(fptr))
      break;

    if (!line_len)
      continue;

    chara = line[0];

    if (((chara >= 'a') && (chara <= 'z')) ||
        ((chara >= 'A') && (chara <= 'Z')))
      continue;

    retval = get_session_info(line,line_len,&session_info[session_ix]);

    if (retval) {
      printf("get_session_info() failed on line %d: %d\n",
        session_ix+1,retval);
      return 5;
    }

    session_ix++;
  }

  fclose(fptr);

  num_rebounds = 0;
  in_losing_streak = 0;

  for (n = 0; n < set_size; n++) {
    if (in_losing_streak) {
      if (session_info[n].delta > 0) {
        num_rebounds++;

        if (bDebug)
          printf("%3d\n",n);

        for (n++; n < set_size; n++) {
          if (session_info[n].delta < 0)
            break;
        }
      }

      continue;
    }
    else {
      if (session_info[n].delta < 0)
        in_losing_streak = 1;

      continue;
    }
  }

  if (bDebug)
    printf("num_rebounds = %d\n",num_rebounds);

  if ((rebound = (struct rebound_struct *)malloc(
    num_rebounds * sizeof (struct rebound_struct))) == NULL) {
    printf(malloc_failed2,num_rebounds);
    fclose(fptr);
    return 6;
  }

  if ((sort_ixs = (int *)malloc(
    num_rebounds * sizeof (int))) == NULL) {
    printf(malloc_failed3,num_rebounds);
    fclose(fptr);
    return 7;
  }

  rebound_ix = 0;
  cumulative_loss = 0;
  cumulative_gain = 0;
  in_losing_streak = 0;

  for (n = 0; n < set_size; n++) {
    if (in_losing_streak) {
      if (session_info[n].delta > 0) {
        cumulative_gain = session_info[n].delta;

        if (bDebug)
          printf("%3d\n",n);

        for (n++; n < set_size; n++) {
          if (session_info[n].delta < 0)
            break;
          else
            cumulative_gain += session_info[n].delta;
        }

        rebound[rebound_ix].poker_session_date =
          session_info[n-1].poker_session_date;

        work = cumulative_loss * -1;

        if (work > cumulative_gain)
          work = cumulative_gain;

        rebound[rebound_ix++].rebound = work;
        cumulative_loss = session_info[n].delta;
      }
      else
        cumulative_loss += session_info[n].delta;

      continue;
    }
    else {
      if (session_info[n].delta < 0) {
        in_losing_streak = 1;
        cumulative_loss = session_info[n].delta;
      }

      continue;
    }
  }

  for (n = 0; n < num_rebounds; n++)
    sort_ixs[n] = n;

  if (!bNoSort)
    qsort(sort_ixs,num_rebounds,sizeof (int),elem_compare);

  for (n = 0; n < num_rebounds; n++) {
    cpt = ctime(&rebound[sort_ixs[n]].poker_session_date);

    printf("%s %10d\n",
      format_date(cpt),rebound[sort_ixs[n]].rebound);
  }

  free(session_info);
  free(sort_ixs);

  return 0;
}