⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reporter.c

📁 开源备份软件源码 AMANDA, the Advanced Maryland Automatic Network Disk Archiver, is a backup system that a
💻 C
📖 第 1 页 / 共 5 页
字号:
 * Formats an integer of the form YYYYMMDDHHMMSS into the string * "Monthname DD, YYYY".  A pointer to the statically allocated string * is returned, so it must be copied to other storage (or just printed) * before calling nicedate() again. */static char *nicedate(    const char *datestamp){    static char nice[64];    char date[9];    int  numdate;    static char *months[13] = {		T_("BogusMonth"),		T_("January"),		T_("February"),		T_("March"),		T_("April"),		T_("May"),		T_("June"),		T_("July"),		T_("August"),		T_("September"),		T_("October"),		T_("November"),		T_("December")    };    int year, month, day;    strncpy(date, datestamp, 8);    date[8] = '\0';    numdate = atoi(date);    year  = numdate / 10000;    day   = numdate % 100;    month = (numdate / 100) % 100;    if (month > 12 )	month = 0;    g_snprintf(nice, SIZEOF(nice), "%s %d, %d", _(months[month]), day, year);    return nice;}static voidhandle_start(void){    static int started = 0;    char *label;    char *s, *fp;    int ch;    switch(curprog) {    case P_TAPER:	s = curstr;	ch = *s++;	skip_whitespace(s, ch);	if(ch == '\0' || strncmp_const_skip(s - 1, "datestamp", s, ch) != 0) {	    bogus_line(s - 1);	    return;	}	skip_whitespace(s, ch);	if(ch == '\0') {	    bogus_line(s - 1);	    return;	}	fp = s - 1;	skip_non_whitespace(s, ch);	s[-1] = '\0';	run_datestamp = newstralloc(run_datestamp, fp);	s[-1] = (char)ch;	skip_whitespace(s, ch);	if(ch == '\0' || strncmp_const_skip(s - 1, "label", s, ch) != 0) {	    bogus_line(s - 1);	    return;	}	skip_whitespace(s, ch);	if(ch == '\0') {	    bogus_line(s - 1);	    return;	}	fp = s - 1;	skip_non_whitespace(s, ch);	s[-1] = '\0';	label = stralloc(fp);	s[-1] = (char)ch;	if(tape_labels) {	    fp = vstralloc(tape_labels, ", ", label, NULL);	    amfree(tape_labels);	    tape_labels = fp;	} else {	    tape_labels = stralloc(label);	}	last_run_tapes++;	if(stats_by_tape == NULL) {	    stats_by_tape = current_tape = (taper_t *)alloc(SIZEOF(taper_t));	}	else {	    current_tape->next = (taper_t *)alloc(SIZEOF(taper_t));	    current_tape = current_tape->next;	}	current_tape->label = label;	current_tape->taper_time = 0.0;	current_tape->coutsize = 0.0;	current_tape->corigsize = 0.0;	current_tape->tapedisks = 0;	current_tape->tapechunks = 0;	current_tape->next = NULL;	tapefcount = 0;	return;    case P_PLANNER:	normal_run = 1;	break;    case P_DRIVER:	break;    case P_AMFLUSH:	amflush_run = 1;	break;    default:	;    }    if(!started) {	s = curstr;	ch = *s++;	skip_whitespace(s, ch);	if(ch == '\0' || strncmp_const_skip(s - 1, "date", s, ch) != 0) {	    return;				/* ignore bogus line */	}	skip_whitespace(s, ch);	if(ch == '\0') {	    bogus_line(s - 1);	    return;	}	fp = s - 1;	skip_non_whitespace(s, ch);	s[-1] = '\0';	run_datestamp = newstralloc(run_datestamp, fp);	s[-1] = (char)ch;	started = 1;    }    if(amflush_run && normal_run) {	amflush_run = 0;	addline(&notes,     _("  reporter: both amflush and planner output in log, ignoring amflush."));    }}static voidhandle_finish(void){    char *s;    int ch;    double a_time;    if(curprog == P_DRIVER || curprog == P_AMFLUSH || curprog == P_PLANNER) {	s = curstr;	ch = *s++;	skip_whitespace(s, ch);	if(ch == '\0' || strncmp_const_skip(s - 1, "date", s, ch) != 0) {	    bogus_line(s - 1);	    return;	}	skip_whitespace(s, ch);	if(ch == '\0') {	    bogus_line(s - 1);	    return;	}	skip_non_whitespace(s, ch);	/* ignore the date string */	skip_whitespace(s, ch);	if(ch == '\0' || strncmp_const_skip(s - 1, "time", s, ch) != 0) {	    /* older planner doesn't write time */	    if(curprog == P_PLANNER) return;	    bogus_line(s - 1);	    return;	}	skip_whitespace(s, ch);	if(ch == '\0') {	    bogus_line(s - 1);	    return;	}	if(sscanf(s - 1, "%lf", &a_time) != 1) {	    bogus_line(s - 1);	    return;	}	if(curprog == P_PLANNER) {	    planner_time = a_time;	}	else {	    total_time = a_time;	    got_finish = 1;	}    }}static voidhandle_stats(void){    char *s, *fp;    int ch;    char *hostname, *diskname, *datestamp, *qdiskname;    int level = 0;    double sec, kps, nbytes, cbytes;    repdata_t *repdata;    disk_t *dp;    if(curprog == P_DRIVER) {	s = curstr;	ch = *s++;	skip_whitespace(s, ch);	if(ch != '\0' && strncmp_const_skip(s - 1, "startup time", s, ch) == 0) {	    skip_whitespace(s, ch);	    if(ch == '\0') {		bogus_line(s - 1);		return;	    }	    if(sscanf(s - 1, "%lf", &startup_time) != 1) {		bogus_line(s - 1);		return;	    }	    planner_time = startup_time;	}	else if(ch != '\0' && strncmp_const_skip(s - 1, "hostname", s, ch) == 0) {	    skip_whitespace(s, ch);	    if(ch == '\0') {		bogus_line(s - 1);		return;	    }	    ghostname = stralloc(s-1);	}	else if(ch != '\0' && strncmp_const_skip(s - 1, "estimate", s, ch) == 0) {	    skip_whitespace(s, ch);	    if(ch == '\0') {		bogus_line(s - 1);		return;	    }	    fp = s - 1;	    skip_non_whitespace(s, ch);	    s[-1] = '\0';	    hostname = stralloc(fp);	    s[-1] = (char)ch;	    skip_whitespace(s, ch);	    if(ch == '\0') {		bogus_line(s - 1);		amfree(hostname);		return;	    }	    qdiskname = s - 1;	    skip_quoted_string(s, ch);	    s[-1] = '\0';	    diskname = unquote_string(qdiskname);	    s[-1] = (char)ch;	    skip_whitespace(s, ch);	    if(ch == '\0') {		bogus_line(s - 1);		amfree(hostname);		amfree(diskname);		return;	    }	    fp = s - 1;	    skip_non_whitespace(s, ch);	    s[-1] = '\0';	    datestamp = stralloc(fp);	    s[-1] = (char)ch;	    skip_whitespace(s, ch);	    if(ch == '\0' || sscanf(s - 1, "%d", &level) != 1) {		bogus_line(s - 1);		amfree(hostname);		amfree(diskname);		amfree(datestamp);		return;	    }	    skip_integer(s, ch);	    if(level < 0 || level > 9) {		amfree(hostname);		amfree(diskname);		amfree(datestamp);		return;	    }	    skip_whitespace(s, ch);	    if(sscanf(s - 1,"[sec %lf nkb %lf ckb %lf kps %lf",		      &sec, &nbytes, &cbytes, &kps) != 4)  {		bogus_line(s - 1);		amfree(hostname);		amfree(diskname);		amfree(datestamp);		return;	    }	    dp = lookup_disk(hostname, diskname);	    if(dp == NULL) {		addtoX_summary(&first_failed, &last_failed,			       hostname, diskname, level,			       _("ERROR [not in disklist]"));		exit_status |= STATUS_FAILED;		amfree(hostname);		amfree(diskname);		amfree(datestamp);		return;	    }	    repdata = find_repdata(dp, datestamp, level);	    repdata->est_nsize = nbytes;	    repdata->est_csize = cbytes;	    amfree(hostname);	    amfree(diskname);	    amfree(datestamp);	}	else {	    bogus_line(s - 1);	    return;	}#undef sc    }}static voidhandle_note(void){    char *str = NULL;    str = vstrallocf("  %s: %s", program_str[curprog], curstr);    addline(&notes, str);    amfree(str);}/* ----- */static voidhandle_error(void){    char *s = NULL, *nl;    int ch;    if(curlog == L_ERROR && curprog == P_TAPER) {	s = curstr;	ch = *s++;	skip_whitespace(s, ch);	if(ch != '\0' && strncmp_const_skip(s - 1, "no-tape", s, ch) == 0) {	    skip_whitespace(s, ch);	    if(ch != '\0') {		if((nl = strchr(s - 1, '\n')) != NULL) {		    *nl = '\0';		}		tapestart_error = newstralloc(tapestart_error, s - 1);		if(nl) *nl = '\n';		degraded_mode = 1;		exit_status |= STATUS_TAPE;;		return;	    }	    /* else some other tape error, handle like other errors */	}	/* else some other tape error, handle like other errors */    }    s = vstrallocf("  %s: %s %s", program_str[curprog],		  logtype_str[curlog], curstr);    addline(&errsum, s);    amfree(s);}/* ----- */static voidhandle_summary(void){    bogus_line(curstr);}/* ----- */static int nb_disk=0;static voidhandle_disk(void){    disk_t *dp;    char *s, *fp, *qdiskname;    int ch;    char *hostname = NULL, *diskname = NULL;    if(curprog != P_PLANNER && curprog != P_AMFLUSH) {	bogus_line(curstr);	return;    }    if(nb_disk==0) {	for(dp = diskq.head; dp != NULL; dp = dp->next)	    dp->todo = 0;    }    nb_disk++;    s = curstr;    ch = *s++;    skip_whitespace(s, ch);    if(ch == '\0') {	bogus_line(s - 1);	return;    }    fp = s - 1;    skip_non_whitespace(s, ch);    s[-1] = '\0';    hostname = newstralloc(hostname, fp);    s[-1] = (char)ch;    skip_whitespace(s, ch);    if(ch == '\0') {	bogus_line(s - 1);	amfree(hostname);	return;    }    qdiskname = s - 1;    skip_quoted_string(s, ch);    s[-1] = '\0';    diskname = unquote_string(qdiskname);    s[-1] = (char)ch;    dp = lookup_disk(hostname, diskname);    if(dp == NULL) {	dp = add_disk(&diskq, hostname, diskname);    }    amfree(hostname);    amfree(diskname);    dp->todo = 1;}/* XXX Just a placeholder, in case we decide to do something with L_CHUNK * log entries.  Right now they're just the equivalent of L_SUCCESS, but only * for a split chunk of the overall dumpfile. */static repdata_t *handle_chunk(    logtype_t logtype){    disk_t *dp;    double sec, kps, kbytes;    timedata_t *sp;    int i;    char *s, *fp;    int ch;    char *hostname = NULL;    char *diskname = NULL;    repdata_t *repdata;    int level, chunk;    char *datestamp;    char *label = NULL;    int fileno;    int totpart;        if(curprog != P_TAPER) { 	bogus_line(curstr); 	return NULL;    }        s = curstr;    ch = *s++;    skip_whitespace(s, ch);    if(ch == '\0') { 	bogus_line(s - 1); 	return NULL;    }    if (logtype == L_PART || logtype == L_PARTPARTIAL) {	fp = s - 1;	skip_non_whitespace(s, ch);	s[-1] = '\0';	label = stralloc(fp);	s[-1] = (char)ch;    	skip_whitespace(s, ch);	if(ch == '\0' || sscanf(s - 1, "%d", &fileno) != 1) {	    bogus_line(s - 1);	    amfree(label);	    return NULL;	}	skip_integer(s, ch);	skip_whitespace(s, ch);	if(ch == '\0') { 	    bogus_line(s - 1);	    amfree(label); 	    return NULL;	}	amfree(label);    }    fp = s - 1;    skip_non_whitespace(s, ch);    s[-1] = '\0';    hostname = stralloc(fp);    s[-1] = (char)ch;        skip_whitespace(s, ch);    if(ch == '\0') { 	bogus_line(s - 1); 	amfree(hostname); 	return NULL;    }    fp = s - 1;    skip_quoted_string(s, ch);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -