本文整理汇总了C++中ctime函数的典型用法代码示例。如果您正苦于以下问题:C++ ctime函数的具体用法?C++ ctime怎么用?C++ ctime使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ctime函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
uint16_t currentItemNr = itemNumber.toShort();
EQItemDB* itemDB = new EQItemDB;
QString nameString;
QString loreString;
bool hasEntry = false;
EQItemDBEntry* entry = NULL;
hasEntry = itemDB->GetItemData(currentItemNr, &entry);
out << "<H1>Information on ItemID: " << currentItemNr << "</H1>\n";
if (hasEntry)
{
loreString = entry->GetLoreName();
nameString = entry->GetName();
if (displayIcon)
out << "<P><IMG src=\"" << ICON_DIR << entry->GetIconNr()
<< ".png\" alt=\"Icon: " << entry->GetIconNr() << "\"/></P>";
if (!nameString.isEmpty())
{
out << "<H2>" << nameString << "</H2>\n";
out << "<P><B>Lore:</B> " << loreString << "<BR></P>\n";
}
else
{
out << "<H2>Lore: " << loreString << "</H2>\n";
}
out << "<P>\n";
time_t updated = entry->GetUpdated();
out << "<B>Last Updated:</B> " << ctime(&updated) << "<BR>\n";
out << "<B>Icon Number:</B> " << entry->GetIconNr() << "<BR>\n";
out << "<B>Model:</B> " << entry->GetIdFile() << "<BR>\n";
out << "<B>ItemType:</B> " << QString::number(entry->GetItemType())
<< "<BR>\n";
out << "<B>Weight:</B> " << (int)entry->GetWeight() << "<BR>\n";
out << "<B>Flags:</B> ";
if (entry->IsBook())
out << " BOOK";
if (entry->IsContainer())
out << " CONTAINER";
if (entry->GetNoDrop() == 0)
out << " NO-DROP";
if (entry->GetNoRent() == 0)
out << " NO-RENT";
if (entry->GetMagic() == 1)
out << " MAGIC";
if (loreString[0] == '*')
out << " LORE";
else if (loreString[0] == '&')
out << " SUMMONED";
else if (loreString[0] == '#')
out << " ARTIFACT";
else if (loreString[0] == '~')
out << " PENDING-LORE";
out << "<BR>\n";
out << "<B>Size:</B> " << size_name(entry->GetSize()) << "<BR>\n";
out << "<B>Slots:</B> " << print_slot(entry->GetSlots()) << "<BR>\n";
out << "<B>Base Price:</B> " << reformatMoney(entry->GetCost())
<< "<BR>\n";
if (entry->GetSTR())
out << "<B>Str:</B> " << (int)entry->GetSTR() << "<BR>\n";
示例2: display_attribute
//获取文件属性并打印
void display_attribute(struct stat *buf, char *path)
{
char time[32];
struct passwd *psd;
struct group *grp;
//获取并打印文件类型
if (S_ISLNK(buf->st_mode)) {
printf("l");
} else if (S_ISREG(buf->st_mode)) {
printf("-");
} else if (S_ISDIR(buf->st_mode)) {
printf("d");
} else if (S_ISCHR(buf->st_mode)) {
printf("c");
} else if (S_ISBLK(buf->st_mode)) {
printf("b");
} else if (S_ISFIFO(buf->st_mode)) {
printf("f");
} else if (S_ISSOCK(buf->st_mode)) {
printf("s");
}
//获取所有者的权限
if (buf->st_mode & S_IRUSR) {
printf("r");
} else {
printf("-");
}
if (buf->st_mode & S_IWUSR) {
printf("w");
} else {
printf("-");
}
if (buf->st_mode & S_IXUSR) {
printf("x");
} else {
printf("-");
}
//获取组权限
if (buf->st_mode & S_IRGRP) {
printf("r");
} else {
printf("-");
}
if (buf->st_mode & S_IWGRP) {
printf("w");
} else {
printf("-");
}
if (buf->st_mode & S_IXGRP) {
printf("x");
} else {
printf("-");
}
//获取其他用户权限
if (buf->st_mode & S_IROTH) {
printf("r");
} else {
printf("-");
}
if (buf->st_mode & S_IWOTH) {
printf("w");
} else {
printf("-");
}
if (buf->st_mode & S_IXOTH) {
printf("x");
} else {
printf("-");
}
printf(" ");
printf("%5lu ", buf->st_nlink); //打印文件连接数
//根据uid,gid获取用户名和组名
psd = getpwuid(buf->st_uid);
grp = getgrgid(buf->st_gid);
printf("%-s\t", psd -> pw_name);
printf("%-s\t", grp -> gr_name);
printf("%10ld ", buf->st_size); //打印文件大小
strcpy(time, ctime(&buf -> st_mtime));
time[(strlen(time)) - 1] = '\0';
printf("%s ", time); //打印时间
printf("%s\n", path); //打印文件名
}
示例3: erl_crash_dump_v
//.........这里部分代码省略.........
env_erl_crash_dump_seconds_set = 0;
secs = -1;
} else {
env_erl_crash_dump_seconds_set = 1;
secs = atoi(env);
}
if (secs == 0) {
return;
}
/* erts_sys_prepare_crash_dump returns 1 if heart port is found, otherwise 0
* If we don't find heart (0) and we don't have ERL_CRASH_DUMP_SECONDS set
* we should continue writing a dump
*
* beware: secs -1 means no alarm
*/
if (erts_sys_prepare_crash_dump(secs) && !env_erl_crash_dump_seconds_set ) {
return;
}
if (erts_sys_getenv__("ERL_CRASH_DUMP",&dumpnamebuf[0],&dumpnamebufsize) != 0)
dumpname = "erl_crash.dump";
else
dumpname = &dumpnamebuf[0];
erts_fprintf(stderr,"\nCrash dump is being written to: %s...", dumpname);
fd = open(dumpname,O_WRONLY | O_CREAT | O_TRUNC,0640);
if (fd < 0)
return; /* Can't create the crash dump, skip it */
time(&now);
erts_fdprintf(fd, "=erl_crash_dump:0.3\n%s", ctime(&now));
if (file != NULL)
erts_fdprintf(fd, "The error occurred in file %s, line %d\n", file, line);
if (fmt != NULL && *fmt != '\0') {
erts_fdprintf(fd, "Slogan: ");
erts_vfdprintf(fd, fmt, args);
}
erts_fdprintf(fd, "System version: ");
erts_print_system_version(fd, NULL, NULL);
#if ERTS_SAVED_COMPILE_TIME
erts_fdprintf(fd, "%s\n", "Compiled: " ERLANG_COMPILE_DATE);
#endif
erts_fdprintf(fd, "Taints: ");
erts_print_nif_taints(fd, NULL);
erts_fdprintf(fd, "Atoms: %d\n", atom_table_size());
#ifdef USE_THREADS
/* We want to note which thread it was that called erts_exit */
if (erts_get_scheduler_data()) {
erts_fdprintf(fd, "Calling Thread: scheduler:%d\n",
erts_get_scheduler_data()->no);
} else {
if (!erts_thr_getname(erts_thr_self(), dumpnamebuf, MAXPATHLEN))
erts_fdprintf(fd, "Calling Thread: %s\n", dumpnamebuf);
else
erts_fdprintf(fd, "Calling Thread: %p\n", erts_thr_self());
}
#else
erts_fdprintf(fd, "Calling Thread: scheduler:1\n");
#endif
示例4: update_id
void update_id( D_MOBILE *dMob, I_ID *id )
{
id->last_modified = ctime( ¤t_time );
id->modified_by = strdup( dMob->name );
return;
}
示例5: deliver_local
int
deliver_local(struct qitem *it)
{
char fn[PATH_MAX+1];
char line[1000];
const char *sender;
const char *newline = "\n";
size_t linelen;
int tries = 0;
int mbox;
int error;
int hadnl = 0;
off_t mboxlen;
time_t now = time(NULL);
error = snprintf(fn, sizeof(fn), "%s/%s", _PATH_MAILDIR, it->addr);
if (error < 0 || (size_t)error >= sizeof(fn)) {
syslog(LOG_NOTICE, "local delivery deferred: %m");
return (1);
}
retry:
/* wait for a maximum of 100s to get the lock to the file */
do_timeout(100, 0);
/* don't use O_CREAT here, because we might be running as the wrong user. */
mbox = open_locked(fn, O_WRONLY|O_APPEND);
if (mbox < 0) {
int e = errno;
do_timeout(0, 0);
switch (e) {
case EACCES:
case ENOENT:
/*
* The file does not exist or we can't access it.
* Call dma-mbox-create to create it and fix permissions.
*/
if (tries > 0 || create_mbox(it->addr) != 0) {
syslog(LOG_ERR, "local delivery deferred: can not create `%s'", fn);
return (1);
}
++tries;
goto retry;
case EINTR:
syslog(LOG_NOTICE, "local delivery deferred: can not lock `%s'", fn);
break;
default:
syslog(LOG_NOTICE, "local delivery deferred: can not open `%s': %m", fn);
break;
}
return (1);
}
do_timeout(0, 0);
mboxlen = lseek(mbox, 0, SEEK_END);
/* New mails start with \nFrom ...., unless we're at the beginning of the mbox */
if (mboxlen == 0)
newline = "";
/* If we're bouncing a message, claim it comes from MAILER-DAEMON */
sender = it->sender;
if (strcmp(sender, "") == 0)
sender = "MAILER-DAEMON";
if (fseek(it->mailf, 0, SEEK_SET) != 0) {
syslog(LOG_NOTICE, "local delivery deferred: can not seek: %m");
goto out;
}
error = snprintf(line, sizeof(line), "%sFrom %s %s", newline, sender, ctime(&now));
if (error < 0 || (size_t)error >= sizeof(line)) {
syslog(LOG_NOTICE, "local delivery deferred: can not write header: %m");
goto out;
}
if (write(mbox, line, error) != error)
goto wrerror;
while (!feof(it->mailf)) {
if (fgets(line, sizeof(line), it->mailf) == NULL)
break;
linelen = strlen(line);
if (linelen == 0 || line[linelen - 1] != '\n') {
syslog(LOG_CRIT, "local delivery failed: corrupted queue file");
snprintf(errmsg, sizeof(errmsg), "corrupted queue file");
error = -1;
goto chop;
}
/*
* mboxro processing:
* - escape lines that start with "From " with a > sign.
* - be reversible by escaping lines that contain an arbitrary
* number of > signs, followed by "From ", i.e. />*From / in regexp.
* - strict mbox processing only requires escaping after empty lines,
* yet most MUAs seem to relax this requirement and will treat any
//.........这里部分代码省略.........
示例6: erl_crash_dump_v
/* XXX THIS SHOULD BE IN SYSTEM !!!! */
void
erl_crash_dump_v(char *file, int line, char* fmt, va_list args)
{
#ifdef ERTS_SMP
ErtsThrPrgrData tpd_buf; /* in case we aren't a managed thread... */
#endif
int fd;
time_t now;
size_t dumpnamebufsize = MAXPATHLEN;
char dumpnamebuf[MAXPATHLEN];
char* dumpname;
if (ERTS_SOMEONE_IS_CRASH_DUMPING)
return;
#ifdef ERTS_SMP
/*
* Wait for all managed threads to block. If all threads haven't blocked
* after a minute, we go anyway and hope for the best...
*
* We do not release system again. We expect an exit() or abort() after
* dump has been written.
*/
erts_thr_progress_fatal_error_block(60000, &tpd_buf);
/* Either worked or not... */
/* Allow us to pass certain places without locking... */
erts_smp_atomic32_set_mb(&erts_writing_erl_crash_dump, 1);
erts_smp_tsd_set(erts_is_crash_dumping_key, (void *) 1);
#else
erts_writing_erl_crash_dump = 1;
#endif
erts_sys_prepare_crash_dump();
if (erts_sys_getenv_raw("ERL_CRASH_DUMP",&dumpnamebuf[0],&dumpnamebufsize) != 0)
dumpname = "erl_crash.dump";
else
dumpname = &dumpnamebuf[0];
fd = open(dumpname,O_WRONLY | O_CREAT | O_TRUNC,0640);
if (fd < 0)
return; /* Can't create the crash dump, skip it */
time(&now);
erts_fdprintf(fd, "=erl_crash_dump:0.1\n%s", ctime(&now));
if (file != NULL)
erts_fdprintf(fd, "The error occurred in file %s, line %d\n", file, line);
if (fmt != NULL && *fmt != '\0') {
erts_fdprintf(fd, "Slogan: ");
erts_vfdprintf(fd, fmt, args);
}
erts_fdprintf(fd, "System version: ");
erts_print_system_version(fd, NULL, NULL);
erts_fdprintf(fd, "%s\n", "Compiled: " ERLANG_COMPILE_DATE);
erts_fdprintf(fd, "Taints: ");
erts_print_nif_taints(fd, NULL);
erts_fdprintf(fd, "Atoms: %d\n", atom_table_size());
info(fd, NULL); /* General system info */
if (erts_proc.tab)
process_info(fd, NULL); /* Info about each process and port */
db_info(fd, NULL, 0);
erts_print_bif_timer_info(fd, NULL);
distribution_info(fd, NULL);
erts_fdprintf(fd, "=loaded_modules\n");
loaded(fd, NULL);
erts_dump_fun_entries(fd, NULL);
erts_deep_process_dump(fd, NULL);
erts_fdprintf(fd, "=atoms\n");
dump_atoms(fd, NULL);
/* Keep the instrumentation data at the end of the dump */
if (erts_instr_memory_map || erts_instr_stat) {
erts_fdprintf(fd, "=instr_data\n");
if (erts_instr_stat) {
erts_fdprintf(fd, "=memory_status\n");
erts_instr_dump_stat_to_fd(fd, 0);
}
if (erts_instr_memory_map) {
erts_fdprintf(fd, "=memory_map\n");
erts_instr_dump_memory_map_to_fd(fd);
}
}
erts_fdprintf(fd, "=end\n");
close(fd);
erts_fprintf(stderr,"\nCrash dump was written to: %s\n", dumpname);
}
示例7: sl_journal_dump
/*
* Dump the contents of a journal file.
* @fn: journal filename to query.
*
* Each time mds restarts, it writes log entries starting from the very
* first slot of the log. Anyway, the function dumps all log entries,
* some of them may be from previous incarnations of the MDS.
*/
void
sl_journal_dump(const char *fn)
{
int i, ntotal, nmagic, nchksum, nformat, ndump, first = 1;
uint32_t slot, highest_slot = -1, lowest_slot = -1;
uint64_t chksum, highest_xid = 0, lowest_xid = 0;
struct psc_journal_enthdr *pje;
struct psc_journal_hdr *pjh;
struct psc_journal *pj;
struct stat statbuf;
unsigned char *jbuf;
ssize_t nb, pjhlen;
time_t ts;
ntotal = nmagic = nchksum = nformat = ndump = 0;
pj = PSCALLOC(sizeof(*pj));
strlcpy(pj->pj_name, pfl_basename(fn), sizeof(pj->pj_name));
pj->pj_fd = open(fn, O_RDWR | O_DIRECT);
if (pj->pj_fd == -1)
psc_fatal("failed to open journal %s", fn);
if (fstat(pj->pj_fd, &statbuf) == -1)
psc_fatal("failed to stat journal %s", fn);
/*
* O_DIRECT may impose alignment restrictions so align the
* buffer and perform I/O in multiples of file system block
* size.
*/
pjhlen = PSC_ALIGN(sizeof(*pjh), statbuf.st_blksize);
pjh = psc_alloc(pjhlen, PAF_PAGEALIGN);
nb = pread(pj->pj_fd, pjh, pjhlen, 0);
if (nb != pjhlen)
psc_fatal("failed to read journal header");
pj->pj_hdr = pjh;
if (pjh->pjh_magic != PJH_MAGIC)
psc_fatalx("journal header has a bad magic number "
"%#"PRIx64, pjh->pjh_magic);
if (pjh->pjh_version != PJH_VERSION)
psc_fatalx("journal header has an invalid version "
"number %d", pjh->pjh_version);
psc_crc64_init(&chksum);
psc_crc64_add(&chksum, pjh, offsetof(struct psc_journal_hdr,
pjh_chksum));
psc_crc64_fini(&chksum);
if (pjh->pjh_chksum != chksum)
psc_fatalx("journal header has an invalid checksum "
"value %"PSCPRIxCRC64" vs %"PSCPRIxCRC64,
pjh->pjh_chksum, chksum);
if (S_ISREG(statbuf.st_mode) && statbuf.st_size !=
(off_t)(pjhlen + pjh->pjh_nents * PJ_PJESZ(pj)))
psc_fatalx("size of the journal log %"PSCPRIdOFFT"d does "
"not match specs in its header", statbuf.st_size);
if (pjh->pjh_nents % pjh->pjh_readsize)
psc_fatalx("number of entries %d is not a multiple of the "
"readsize %d", pjh->pjh_nents, pjh->pjh_readsize);
ts = pjh->pjh_timestamp;
printf("%s:\n"
" version: %u\n"
" entry size: %u\n"
" number of entries: %u\n"
" batch read size: %u\n"
" entry start offset: %"PRId64"\n"
" format time: %s"
" uuid: %"PRIx64"\n"
" %8s %3s %12s %12s %s\n",
fn, pjh->pjh_version, PJ_PJESZ(pj), pjh->pjh_nents,
pjh->pjh_readsize, pjh->pjh_start_off,
ctime(&ts), pjh->pjh_fsuuid,
"idx", "type", "xid", "txg", "details");
jbuf = psc_alloc(PJ_PJESZ(pj) * pj->pj_hdr->pjh_readsize,
PAF_PAGEALIGN);
for (slot = 0; slot < pjh->pjh_nents;
slot += pjh->pjh_readsize) {
nb = pread(pj->pj_fd, jbuf, PJ_PJESZ(pj) *
pjh->pjh_readsize, PJ_GETENTOFF(pj, slot));
if (nb != PJ_PJESZ(pj) * pjh->pjh_readsize)
warn("failed to read %d log entries at slot %d",
pjh->pjh_readsize, slot);
for (i = 0; i < pjh->pjh_readsize; i++) {
//.........这里部分代码省略.........
示例8: cray_setup
//.........这里部分代码省略.........
pwdacm.atype = IA_SECURID;
pwdacm.pwdp = NULL;
pwdacm.next = &pwdudb;
pwdudb.atype = IA_UDB;
pwdudb.pwdp = NULL;
pwdudb.next = &pwddce;
pwddce.atype = IA_DCE;
pwddce.pwdp = NULL;
pwddce.next = &pwddialup;
pwddialup.atype = IA_DIALUP;
pwddialup.pwdp = NULL;
/* pwddialup.next = &pwdwal; */
pwddialup.next = NULL;
pwdwal.atype = IA_WAL;
pwdwal.pwdp = NULL;
pwdwal.next = NULL;
uret.revision = 0;
uret.pswd = NULL;
uret.normal = 0;
ia_rcode = ia_user(&usent, &uret);
switch (ia_rcode) {
/*
* These are acceptable return codes from ia_user()
*/
case IA_UDBWEEK: /* Password Expires in 1 week */
expiration_time = ue.ue_pwage.time + ue.ue_pwage.maxage;
printf ("WARNING - your current password will expire %s\n",
ctime((const time_t *)&expiration_time));
break;
case IA_UDBEXPIRED:
if (ttyname(0) != NULL) {
/* Force a password change */
printf("Your password has expired; Choose a new one.\n");
execl("/bin/passwd", "passwd", username, 0);
exit(9);
}
break;
case IA_NORMAL: /* Normal Return Code */
break;
case IA_BACKDOOR:
/* XXX: can we memset it to zero here so save some of this */
strlcpy(ue.ue_name, "root", sizeof(ue.ue_name));
strlcpy(ue.ue_dir, "/", sizeof(ue.ue_dir));
strlcpy(ue.ue_shell, "/bin/sh", sizeof(ue.ue_shell));
ue.ue_passwd[0] = '\0';
ue.ue_age[0] = '\0';
ue.ue_comment[0] = '\0';
ue.ue_loghost[0] = '\0';
ue.ue_logline[0] = '\0';
ue.ue_uid = -1;
ue.ue_nice[UDBRC_INTER] = 0;
for (i = 0; i < MAXVIDS; i++)
ue.ue_gids[i] = 0;
ue.ue_logfails = 0;
ue.ue_minlvl = ue.ue_maxlvl = ue.ue_deflvl = minslevel;
ue.ue_defcomps = 0;
示例9: repeat_refresh
void repeat_refresh() {
today = ctime(time())[4..9];
call_out((:repeat_refresh:),86400);
}
示例10: refresh
void refresh() {
today = ctime(time())[4..9];
}
示例11: dump_config
/* This procedure will dump the configuration data into an organized format,
optionally into a file. Between the dumped data one may find the current
date of the test and the output and input file name. For understand these
lines, go through the printed strings. It can't be hard. */
void dump_config(FILE* fp, const parameter_t* par)
{
time_t current_time = time(NULL); /* just a dummy variable for timing */
char temp[100]; /* for temporary strings */
fprintf(fp, "-+- CONFIGURATION PARAMETERS\n");
fprintf(fp, " +- Date: %s", ctime(¤t_time));
fprintf(fp, " +- Input File: %s\n", par->ifname);
if (par->output_file)
fprintf(fp, " +- Output File: %s.data \n", par->ofhint);
else
fprintf(fp, " +- Output File: [redirected to standard output]\n");
fprintf(fp, " +- Output Information: ");
if (par->dump_rings) fprintf(fp, "Rings\n");
else if (par->dump_digis) fprintf(fp, "Digis\n");
else if (par->dump_uniform_digis) fprintf(fp, "Uniform Digis\n");
else fprintf(fp, "Uniform Rois\n");
/* The type of dumped information and normalization */
if (! par->dump_digis ) {
fprintf(fp, " +- Uniformizing Selection: %s\n",
layer2string(&par->layer_flags,temp));
if (! par->dump_uniform_digis ) {
fprintf(fp, " +- Printing Selection: %s\n",
layer2string(&par->print_flags,temp));
fprintf(fp, " +- Normalization: %s\n",
normalization2string(&par->normalization,temp));
if ( normal_is_weighted_all(&par->normalization) ||
normal_is_weighted_seg(&par->normalization) ) {
int i;
fprintf(fp, " +- Stop Rings (Weighted Norm.): ");
for (i=0; i<par->config_weighted.nlayers; ++i)
fprintf(fp, "%d ", par->config_weighted.last2norm[i]);
fprintf(fp, "\n");
}
if ( par->max_radius > 0 )
fprintf(fp, " +- Maximum normalization radius: %e\n", par->max_radius);
}
}
/* The event accouting */
fprintf(fp, " +- Event number dumping: %s\n",
(par->dump_eventno)?"Yes":"No" );
/* The event number filename */
if (par->eventno_file && par->dump_eventno) {
if (par->evfp != par->ofp)
fprintf(fp, " +- Event-number File: %s.eventno \n", par->ofhint);
else
fprintf(fp, " +- Event-number File: %s.data \n", par->ofhint);
}
/* The event number comment string, if it exists */
if (strcmp(par->event_comment_str, "") != 0 )
fprintf(fp, " +- Event number comment string: %s\n",
par->event_comment_str);
/* What types of energy are going to be printed */
fprintf(fp, " +- Energy printing: %s\n",
edump2string(&par->dump_energy,temp));
/* The energy filename */
if (par->energy_file && par->dump_energy) {
if (par->efp != par->ofp)
fprintf(fp, " +- Energy File: %s.energy \n", par->ofhint);
else
fprintf(fp, " +- Energy File: %s.data \n", par->ofhint);
}
/* The energy comment string, if it exists */
if (strcmp(par->edump_comment_str, "") != 0 )
fprintf(fp, " +- Energy comment string: %s\n", par->edump_comment_str);
fprintf(fp, " +- Output Format: ");
if (par->format_snns) {
fprintf(fp, "SNNS\n");
fprintf(fp, " +- Particle Type for SNNS targets: ");
if (par->particle == JET) fprintf(fp, "Jet\n");
else fprintf(fp, "Electron\n");
}
else fprintf(fp, "Raw\n");
if (par->process_all_rois)
fprintf(fp, " +- Processing: All Events\n");
else
fprintf(fp, " +- Processing: Event %ld, RoI %ld\n",
par->event_no, par->roi_no);
fprintf(fp, " +- Verbose output: %s\n", (par->verbose)?"YES":"NO");
if (par->run_fast)
fprintf(fp, " +- Fast Processing: YES (using obstacks)\n");
//.........这里部分代码省略.........
示例12: linphone_gtk_call_log_update
void linphone_gtk_call_log_update(GtkWidget *w){
GtkTreeView *v=GTK_TREE_VIEW(linphone_gtk_get_widget(w,"logs_view"));
GtkTreeStore *store;
const MSList *logs;
GtkTreeSelection *select;
GtkWidget *notebook=linphone_gtk_get_widget(w,"viewswitch");
gint nb;
store=(GtkTreeStore*)gtk_tree_view_get_model(v);
if (store==NULL){
store=gtk_tree_store_new(3,GDK_TYPE_PIXBUF,G_TYPE_STRING,G_TYPE_POINTER,G_TYPE_STRING);
gtk_tree_view_set_model(v,GTK_TREE_MODEL(store));
g_object_unref(G_OBJECT(store));
fill_renderers(GTK_TREE_VIEW(linphone_gtk_get_widget(w,"logs_view")));
select=gtk_tree_view_get_selection(v);
gtk_tree_selection_set_mode(select, GTK_SELECTION_SINGLE);
g_signal_connect_swapped(G_OBJECT(select),"changed",(GCallback)call_log_selection_changed,v);
g_signal_connect(G_OBJECT(notebook),"focus-tab",(GCallback)linphone_gtk_call_log_reset_missed_call,NULL);
g_signal_connect(G_OBJECT(v),"button-press-event",(GCallback)linphone_gtk_call_log_button_pressed,NULL);
// gtk_button_set_image(GTK_BUTTON(linphone_gtk_get_widget(w,"call_back_button")),
// create_pixmap (linphone_gtk_get_ui_config("callback_button","status-green.png")));
}
nb=linphone_core_get_missed_calls_count(linphone_gtk_get_core());
if(nb > 0)
linphone_gtk_call_log_display_missed_call(nb);
gtk_tree_store_clear (store);
for (logs=linphone_core_get_call_logs(linphone_gtk_get_core());logs!=NULL;logs=logs->next){
LinphoneCallLog *cl=(LinphoneCallLog*)logs->data;
GtkTreeIter iter, iter2;
LinphoneAddress *la=linphone_call_log_get_dir(cl)==LinphoneCallIncoming ? linphone_call_log_get_from(cl) : linphone_call_log_get_to(cl);
char *addr= linphone_address_as_string(la);
const char *display;
gchar *logtxt, *headtxt, *minutes, *seconds;
gchar quality[20];
const char *status=NULL;
gchar *start_date=NULL;
LinphoneFriend *lf=NULL;
int duration=linphone_call_log_get_duration(cl);
time_t start_date_time=linphone_call_log_get_start_date(cl);
#if GLIB_CHECK_VERSION(2,26,0)
if (start_date_time){
GDateTime *dt=g_date_time_new_from_unix_local(start_date_time);
start_date=g_date_time_format(dt,"%c");
g_date_time_unref(dt);
}
#else
start_date=g_strdup(ctime(&start_date_time));
#endif
lf=linphone_core_get_friend_by_address(linphone_gtk_get_core(),addr);
if(lf != NULL){
if ((display=linphone_address_get_display_name(linphone_friend_get_address(lf)))) {
/*update display name from friend*/
linphone_address_set_display_name(la,display);
}
} else {
display=linphone_address_get_display_name(la);
}
if (display==NULL){
display=linphone_address_get_username (la);
if (display==NULL){
display=linphone_address_get_domain (la);
}
}
if (linphone_call_log_get_quality(cl)!=-1){
snprintf(quality,sizeof(quality),"%.1f",linphone_call_log_get_quality(cl));
}else snprintf(quality,sizeof(quality)-1,"%s",_("n/a"));
switch(linphone_call_log_get_status(cl)){
case LinphoneCallAborted:
status=_("Aborted");
break;
case LinphoneCallMissed:
status=_("Missed");
break;
case LinphoneCallDeclined:
status=_("Declined");
break;
default:
break;
}
minutes=g_markup_printf_escaped(
ngettext("%i minute", "%i minutes", duration/60),
duration/60);
seconds=g_markup_printf_escaped(
ngettext("%i second", "%i seconds", duration%60),
duration%60);
if (status==NULL) {
headtxt=g_markup_printf_escaped(_("<big><b>%s</b></big>\t%s"),display,start_date ? start_date : "");
logtxt=g_markup_printf_escaped(
_("<small><i>%s</i>\t"
"<i>Quality: %s</i></small>\n%s\t%s\t"),
addr, quality, minutes, seconds);
} else {
headtxt=g_markup_printf_escaped(_("<big><b>%s</b></big>\t%s"),display,start_date ? start_date : "");
logtxt=g_markup_printf_escaped(
_("<small><i>%s</i></small>\t"
"\n%s"),addr, status);
}
//.........这里部分代码省略.........
示例13: MonLogSymbolicValue
//.........这里部分代码省略.........
if (a.measure.extraction_regex)
{
Log(LOG_LEVEL_VERBOSE, "Now looking for a matching extractor \"%s\"", a.measure.extraction_regex);
strncpy(value, ExtractFirstReference(a.measure.extraction_regex, match->name), CF_MAXVARSIZE - 1);
Log(LOG_LEVEL_INFO, "Extracted value \"%s\" for promise \"%s\"", value, handle);
AppendItem(&matches, value, NULL);
}
break;
}
if (a.measure.select_line_matching && StringMatchFull(a.measure.select_line_matching, ip->name))
{
Log(LOG_LEVEL_VERBOSE, "Found line %d by pattern...", count);
found = true;
match = ip;
match_count++;
if (a.measure.extraction_regex)
{
Log(LOG_LEVEL_VERBOSE, "Now looking for a matching extractor \"%s\"", a.measure.extraction_regex);
strncpy(value, ExtractFirstReference(a.measure.extraction_regex, match->name), CF_MAXVARSIZE - 1);
Log(LOG_LEVEL_INFO, "Extracted value \"%s\" for promise \"%s\"", value, handle);
AppendItem(&matches, value, NULL);
}
}
count++;
}
if (!found)
{
cfPS(ctx, LOG_LEVEL_ERR, PROMISE_RESULT_FAIL, pp, a, "Promiser '%s' found no matching line.", pp->promiser);
*result = PromiseResultUpdate(*result, PROMISE_RESULT_FAIL);
return;
}
if (match_count > 1)
{
Log(LOG_LEVEL_INFO, "Warning: %d lines matched the line_selection \"%s\"- matching to last", match_count,
a.measure.select_line_matching);
}
switch (a.measure.data_type)
{
case CF_DATA_TYPE_COUNTER:
Log(LOG_LEVEL_VERBOSE, "Counted %d for %s", match_count, handle);
snprintf(value, CF_MAXVARSIZE, "%d", match_count);
break;
case CF_DATA_TYPE_STRING_LIST:
v = ItemList2CSV(matches);
snprintf(value, CF_BUFSIZE, "%s", v);
free(v);
break;
default:
snprintf(value, CF_BUFSIZE, "%s", matches->name);
}
DeleteItemList(matches);
if (a.measure.history_type && strcmp(a.measure.history_type, "log") == 0)
{
snprintf(filename, CF_BUFSIZE, "%s%cstate%c%s_measure.log", CFWORKDIR, FILE_SEPARATOR, FILE_SEPARATOR, handle);
if ((fout = fopen(filename, "a")) == NULL)
{
cfPS(ctx, LOG_LEVEL_ERR, PROMISE_RESULT_FAIL, pp, a, "Unable to open the output log \"%s\"", filename);
*result = PromiseResultUpdate(*result, PROMISE_RESULT_FAIL);
PromiseRef(LOG_LEVEL_ERR, pp);
return;
}
strncpy(sdate, ctime(&now), CF_MAXVARSIZE - 1);
if (Chop(sdate, CF_EXPANDSIZE) == -1)
{
Log(LOG_LEVEL_ERR, "Chop was called on a string that seemed to have no terminator");
}
fprintf(fout, "%s,%ld,%s\n", sdate, (long) now, value);
Log(LOG_LEVEL_VERBOSE, "Logging: %s,%s to %s", sdate, value, filename);
fclose(fout);
}
else // scalar or static
{
CF_DB *dbp;
char id[CF_MAXVARSIZE];
if (!OpenDB(&dbp, dbid_static))
{
return;
}
snprintf(id, CF_MAXVARSIZE - 1, "%s:%d", handle, a.measure.data_type);
WriteDB(dbp, id, value, strlen(value) + 1);
CloseDB(dbp);
}
}
示例14: main
int
main(int argc, const char *const argv[], const char *const envp[])
{
ifmon_t *ifmons;
char **ifnames;
int nifs;
int ret;
int flags;
int ch;
double delta;
double dtxb;
double drxb;
double dtxp;
double drxp;
int i;
if ( 2 > argc ) {
_usage(argv[0]);
}
/* Get interfaces */
nifs = argc - 1;
ifnames = malloc(sizeof(char *) * nifs);
if ( NULL == ifnames ) {
perror("malloc()");
return EXIT_FAILURE;
}
ifmons = malloc(sizeof(ifmon_t) * nifs);
if ( NULL == ifmons ) {
perror("malloc()");
return EXIT_FAILURE;
}
for ( i = 0; i < nifs; i++ ) {
ifnames[i] = strdup(argv[i+1]);
if ( NULL == ifnames[i] ) {
perror("strdup()");
return EXIT_FAILURE;
}
if ( NULL == ifmon_init(&ifmons[i], ifnames[i]) ) {
/* Error */
fprintf(stderr, "Error: ifname=%s\n", ifnames[i]);
return EXIT_FAILURE;
}
}
#if WITH_CURSES
/* curses */
if ( NULL == initscr() ) {
fprintf(stderr, "initscr(): Cannot initialize screen\n");
return EXIT_FAILURE;
}
cbreak();
noecho();
scrollok(stdscr, FALSE);
move(0, 0);
#endif
/* Set stdin as non-blocking */
flags = fcntl(STDIN_FILENO, F_GETFL, 0);
if ( -1 == flags ) {
flags = 0;
}
fcntl(STDIN_FILENO, F_SETFL, flags | O_NONBLOCK);
for ( ;; ) {
#if WITH_CURSES
ch = getch();
if ( 'q' == ch ) {
break;
}
#endif
for ( i = 0; i < nifs; i++ ) {
ret = ifmon_update(&ifmons[i]);
if ( 0 != ret ) {
/* Error */
break;
}
}
#if WITH_CURSES
clear();
#endif
#if WITH_CURSES
time_t timer;
time(&timer);
/*
struct tm *tm;
tm = localtime(&timer);
*/
/*printw("Time: %.6f\n", );*/
printw("Interface statistics\n%s\n", ctime(&timer));
printw(" pkts/s kbps\n");
printw(" TX RX TX RX\n");
#endif
for ( i = 0; i < nifs; i++ ) {
delta = ifmons[i].curstat.time - ifmons[i].prevstat.time;
dtxp = ifmons[i].curstat.total_pkts.tx
//.........这里部分代码省略.........
示例15: syslog
/*
* Print
* sysname: time: mesg
* on /sys/log/logname.
* If cons or log file can't be opened, print on the system console, too.
*/
void
syslog(int cons, const char *logname, const char *fmt, ...)
{
char buf[1024];
char *ctim, *p;
va_list arg;
int n;
Dir *d;
char err[ERRMAX];
err[0] = '\0';
errstr(err, sizeof err);
lock(&sl);
/*
* paranoia makes us stat to make sure a fork+close
* hasn't broken our fd's
*/
d = dirfstat(sl.fd);
if(sl.fd < 0 || sl.name == nil || strcmp(sl.name, logname) != 0 ||
!eqdirdev(d, sl.d)){
free(sl.name);
sl.name = strdup(logname);
if(sl.name == nil)
cons = 1;
else{
free(sl.d);
sl.d = nil;
_syslogopen();
if(sl.fd < 0)
cons = 1;
else
sl.d = dirfstat(sl.fd);
}
}
free(d);
if(cons){
d = dirfstat(sl.consfd);
if(sl.consfd < 0 || !eqdirdev(d, sl.consd)){
free(sl.consd);
sl.consd = nil;
sl.consfd = open("#c/cons", OWRITE|OCEXEC);
if(sl.consfd >= 0)
sl.consd = dirfstat(sl.consfd);
}
free(d);
}
if(fmt == nil){
unlock(&sl);
return;
}
ctim = ctime(time(0));
p = buf + snprint(buf, sizeof(buf)-1, "%s ", sysname());
strncpy(p, ctim+4, 15);
p += 15;
*p++ = ' ';
errstr(err, sizeof err);
va_start(arg, fmt);
p = vseprint(p, buf+sizeof(buf)-1, fmt, arg);
va_end(arg);
*p++ = '\n';
n = p - buf;
if(sl.fd >= 0){
seek(sl.fd, 0, 2);
write(sl.fd, buf, n);
}
if(cons && sl.consfd >=0)
write(sl.consfd, buf, n);
unlock(&sl);
}