hfaxd/FileSystem.c++
/*
 * Print a formatted string with fields filled in from
 * a file's stat buffer.  This functionality is
 * used to permit clients to get modem status listings
 * in preferred formats.
 */
Print a formatted string with fields filled in from
a file's stat buffer.  This functionality is
used to permit clients to get modem status listings
in preferred formats.
Print a formatted string with fields filled in from a file ' s stat buffer . This functionality is used to permit clients to get modem status listings in preferred formats .
void
HylaFAXServer::Fprintf(FILE* fd, const char* fmt,
    const char* filename, const struct stat& sb)
{
    for (const char* cp = fmt; *cp; cp++) {
	if (*cp == '%') {
#define	MAXSPEC	20
	    char fspec[MAXSPEC];
	    char* fp = fspec;
	    *fp++ = '%';
	    char c = *++cp;
	    if (c == '-')
		*fp++ = c, c = *++cp;
	    if (isdigit(c)) {
		do {
		    *fp++ = c;
		} while (isdigit(c = *++cp) && fp < &fspec[MAXSPEC-3]);
	    }
	    if (c == '.') {
		do {
		    *fp++ = c;
		} while (isdigit(c = *++cp) && fp < &fspec[MAXSPEC-2]);
	    }
	    if (!islower(c)) {
		if (c == '%')		
		    putc(c, fd);
		else
		    fprintf(fd, "%.*s%c", (int) (fp-fspec), fspec, c);
		continue;
	    }
	    fp[0] = fformat[c-'a'];	
	    fp[1] = '\0';
	    switch (c) {
	    case 'a':
		fprintf(fd, fspec, asctime(cvtTime(sb.st_atime))+4);
		break;
	    case 'c':
		fprintf(fd, fspec, asctime(cvtTime(sb.st_ctime))+4);
		break;
	    case 'd':
		fprintf(fd, fspec, (u_int) sb.st_dev);
		break;
	    case 'f':
		fprintf(fd, fspec, filename);
		break;
	    case 'g':
		fprintf(fd, fspec, (u_int) sb.st_gid);
		break;
	    case 'i':
		fprintf(fd, fspec, (u_int) sb.st_ino);		
		break;
	    case 'l':
		fprintf(fd, fspec, (u_int) sb.st_nlink);
		break;
	    case 'm':
		fprintf(fd, fspec, asctime(cvtTime(sb.st_mtime))+4);
		break;
	    case 'o':
		fprintf(fd, fspec, userName((u_int) sb.st_gid));
		break;
	    case 'p':
	    case 'q':
		{ char prot[10];				 HP C++
		  makeProt(sb, c == 'q', prot);
		  fprintf(fd, fspec, prot);
		}
		break;
	    case 'r':
		fprintf(fd, fspec, (u_int) sb.st_rdev);
		break;
	    case 's':
		fprintf(fd, fspec, (u_int) sb.st_size);		
		break;
	    case 'u':
		fprintf(fd, fspec, (u_int) sb.st_uid);
		break;
	    }
	} else
	    putc(*cp, fd);
    }
}
void HylaFAXServer :: Fprintf ( FILE * fd , const char * fmt , const char * filename , const struct stat & sb ) { for ( const char * cp = fmt ; * cp ; cp ++ ) { if ( * cp == ' ' ) { #define MAXSPEC 	20 char fspec [ MAXSPEC ] ; char * fp = fspec ; * fp ++ = ' ' ; char c = * ++ cp ; if ( c == ' ' ) * fp ++ = c , c = * ++ cp ; if ( isdigit ( c ) ) { do { * fp ++ = c ; } while ( isdigit ( c = * ++ cp ) && fp < & fspec [ MAXSPEC - 3 ] ) ; } if ( c == ' ' ) { do { * fp ++ = c ; } while ( isdigit ( c = * ++ cp ) && fp < & fspec [ MAXSPEC - 2 ] ) ; } if ( ! islower ( c ) ) { if ( c == ' ' ) putc ( c , fd ) ; else fprintf ( fd , " " , ( int ) ( fp - fspec ) , fspec , c ) ; continue ; } fp [ 0 ] = fformat [ c - ' ' ] ; fp [ 1 ] = ' \0 ' ; switch ( c ) { case ' ' : fprintf ( fd , fspec , asctime ( cvtTime ( sb . st_atime ) ) + 4 ) ; break ; case ' ' : fprintf ( fd , fspec , asctime ( cvtTime ( sb . st_ctime ) ) + 4 ) ; break ; case ' ' : fprintf ( fd , fspec , ( u_int ) sb . st_dev ) ; break ; case ' ' : fprintf ( fd , fspec , filename ) ; break ; case ' ' : fprintf ( fd , fspec , ( u_int ) sb . st_gid ) ; break ; case ' ' : fprintf ( fd , fspec , ( u_int ) sb . st_ino ) ; break ; case ' ' : fprintf ( fd , fspec , ( u_int ) sb . st_nlink ) ; break ; case ' ' : fprintf ( fd , fspec , asctime ( cvtTime ( sb . st_mtime ) ) + 4 ) ; break ; case ' ' : fprintf ( fd , fspec , userName ( ( u_int ) sb . st_gid ) ) ; break ; case ' ' : case ' ' : { char prot [ 10 ] ; makeProt ( sb , c == ' ' , prot ) ; fprintf ( fd , fspec , prot ) ; } break ; case ' ' : fprintf ( fd , fspec , ( u_int ) sb . st_rdev ) ; break ; case ' ' : fprintf ( fd , fspec , ( u_int ) sb . st_size ) ; break ; case ' ' : fprintf ( fd , fspec , ( u_int ) sb . st_uid ) ; break ; } } else putc ( * cp , fd ) ; } }
Print a formatted string with fields filled in from
 a file's stat buffer.
Print a formatted string with fields filled in from a file ' s stat buffer .
// %% -> % // printf format string // XXX // XXX HP C++ // XXX