static void print_detail(const char *field, const char *value, int *x, int col, int percent) { char msg[256]=""; unsigned long long a=0; unsigned long long b=0; unsigned long long c=0; unsigned long long d=0; unsigned long long t=0; if(!field || !value || !*value || !strcmp(value, "0") || !strcmp(value, "0/0/0/0")) return; if(extract_ul(value, &a, &b, &c, &d, &t)) return; to_msg(msg, sizeof(msg), "% 22s % 9llu % 9llu % 9llu % 9llu % 9llu\n", field, a, b, c, t, d); print_line(msg, (*x)++, col); if(percent && d) { unsigned long long p; p=(t*100)/d; to_msg(msg, sizeof(msg), "% 22s % 9s % 9s % 9s % 9llu%% % 9s\n", "", "", "", "", p, ""); print_line(msg, (*x)++, col); } }
int str_to_counters(const char *str, char **client, char *status, char *phase, char **path, struct cntr *p1cntr, struct cntr *cntr, char ***backups) { int t=0; char *tok=NULL; char *copy=NULL; reset_filecounter(p1cntr, 0); reset_filecounter(cntr, 0); if(!(copy=strdup(str))) { log_out_of_memory(__FUNCTION__); return -1; } if((tok=strtok(copy, "\t\n"))) { char *counter_version=NULL; if(client && !(*client=strdup(tok))) { log_out_of_memory(__FUNCTION__); return -1; } if(!(counter_version=strtok(NULL, "\t\n"))) { free(copy); return 0; } // First token after the client name is the version of // the counter parser thing, which now has to be noted // because counters might be passed to the client instead // of just the server status monitor. if(*counter_version==COUNTER_VERSION_2 || *counter_version==COUNTER_VERSION_1) // old version { while(1) { int x=1; t++; if(!(tok=strtok(NULL, "\t\n"))) break; if (t==x++) { if(status) *status=*tok; } else if(t==x++) { if(status && (*status==STATUS_IDLE || *status==STATUS_SERVER_CRASHED || *status==STATUS_CLIENT_CRASHED)) { int b=0; if(backups) { // Build a list of backups. do { if(add_to_backup_list(backups, &b, tok)) { free(copy); return -1; } } while((tok=strtok(NULL, "\t\n"))); } } else { if(phase) *phase=*tok; } } else if(t==x++) { extract_ul(tok, &(cntr->total), &(cntr->total_changed), &(cntr->total_same), &(cntr->total_deleted), &(p1cntr->total)); } else if(t==x++) { extract_ul(tok, &(cntr->file), &(cntr->file_changed), &(cntr->file_same), &(cntr->file_deleted), &(p1cntr->file)); } else if(t==x++) { extract_ul(tok, &(cntr->enc), &(cntr->enc_changed), &(cntr->enc_same), &(cntr->enc_deleted), &(p1cntr->enc)); } else if(t==x++) { extract_ul(tok, &(cntr->meta), &(cntr->meta_changed), &(cntr->meta_same), &(cntr->meta_deleted), &(p1cntr->meta)); } else if(t==x++) { extract_ul(tok, &(cntr->encmeta), &(cntr->encmeta_changed), &(cntr->encmeta_same), &(cntr->encmeta_deleted), &(p1cntr->encmeta)); } else if(t==x++) { extract_ul(tok, &(cntr->dir), &(cntr->dir_changed), &(cntr->dir_same), &(cntr->dir_deleted), &(p1cntr->dir)); } else if(t==x++) { extract_ul(tok, &(cntr->slink), &(cntr->slink_changed), &(cntr->slink_same), &(cntr->slink_deleted), &(p1cntr->slink)); } else if(t==x++) { extract_ul(tok, &(cntr->hlink), &(cntr->hlink_changed), &(cntr->hlink_same), &(cntr->hlink_deleted), &(p1cntr->hlink)); } else if(t==x++) { extract_ul(tok, &(cntr->special), &(cntr->special_changed), &(cntr->special_same), &(cntr->special_deleted), &(p1cntr->special)); } else if(*counter_version==COUNTER_VERSION_2 && t==x++) { extract_ul(tok, &(cntr->vss), &(cntr->vss_changed), &(cntr->vss_same), &(cntr->vss_deleted), &(p1cntr->vss)); } else if(*counter_version==COUNTER_VERSION_2 && t==x++) { extract_ul(tok, &(cntr->encvss), &(cntr->encvss_changed), &(cntr->encvss_same), &(cntr->encvss_deleted), &(p1cntr->encvss)); } else if(*counter_version==COUNTER_VERSION_2 && t==x++) { extract_ul(tok, &(cntr->vss_t), &(cntr->vss_t_changed), &(cntr->vss_t_same), &(cntr->vss_t_deleted), &(p1cntr->vss_t)); } else if(*counter_version==COUNTER_VERSION_2 && t==x++) { extract_ul(tok, &(cntr->encvss_t), &(cntr->encvss_t_changed), &(cntr->encvss_t_same), &(cntr->encvss_t_deleted), &(p1cntr->encvss_t)); } else if(t==x++) { extract_ul(tok, &(cntr->gtotal), &(cntr->gtotal_changed), &(cntr->gtotal_same), &(cntr->gtotal_deleted), &(p1cntr->gtotal)); } else if(t==x++) { cntr->warning= strtoull(tok, NULL, 10); } else if(t==x++) { p1cntr->byte= strtoull(tok, NULL, 10); } else if(t==x++) { cntr->byte= strtoull(tok, NULL, 10); } else if(t==x++) { cntr->recvbyte= strtoull(tok, NULL, 10); } else if(t==x++) { cntr->sentbyte= strtoull(tok, NULL, 10); } else if(t==x++) { p1cntr->start=atol(tok); } else if(t==x++) { if(path && !(*path=strdup(tok))) { log_out_of_memory(__FUNCTION__); return -1; } } } } } free(copy); return 0; }
// Returns 1 if it printed a line, 0 otherwise. static int summary(char **toks, int t, int count, int row, int col) { char msg[1024]=""; if(*(toks[1])==STATUS_IDLE) { if(t>2) snprintf(msg, sizeof(msg), "%-14.14s %-14s last backup: %s", toks[0], "idle", get_backup_str(toks[2], TRUE)); else snprintf(msg, sizeof(msg), "%-14.14s %-14s", toks[0], "idle"); } if(*(toks[1])==STATUS_SERVER_CRASHED) { if(t>2) snprintf(msg, sizeof(msg), "%-14.14s %-14s last backup: %s", toks[0], "server crashed", get_backup_str(toks[2], TRUE)); else snprintf(msg, sizeof(msg), "%-14.14s %-14s", toks[0], "server crashed"); } if(*(toks[1])==STATUS_CLIENT_CRASHED) { if(t>2) snprintf(msg, sizeof(msg), "%-14.14s %-14s last backup: %s", toks[0], "client crashed", get_backup_str(toks[2], TRUE)); else snprintf(msg, sizeof(msg), "%-14.14s %-14s", toks[0], "client crashed"); } if(*(toks[1])==STATUS_RUNNING) { char f[64]=""; char b[64]=""; const char *s=""; if(t<3) return 0; s=running_status_to_text(*(toks[2])); if(t>3 && *(toks[3])) { unsigned long long a=0; unsigned long long b=0; unsigned long long c=0; unsigned long long d=0; unsigned long long t=0; unsigned long long p=0; if(!extract_ul(toks[3], &a, &b, &c, &d, &t)) { if(d) p=(t*100)/d; snprintf(f, sizeof(f), "%llu/%llu %llu%%", t, d, p); } } if(t>16 && *(toks[16]) && strcmp(toks[16], "0")) { //snprintf(b, sizeof(b), "%s bytes%s", toks[14], // bytes_to_human_str(toks[14])); snprintf(b, sizeof(b), "%s", bytes_to_human_str(toks[16])); } snprintf(msg, sizeof(msg), "%-14.14s %-14s %s%s", toks[0], s, f, b); } if(*msg) { print_line(msg, count, col); return 1; } return 0; }