From: walter h. <wh...@bf...> - 2007-06-07 19:00:58
|
hi all, I got carried away and forgot to add the textdomain stuff now added. this replace the first patch. I added the other header also. It is only for complettness. The rest is a list of variables and that make no sense to translate. re, wh --- lpf.c.org 2007-06-07 16:22:16.000000000 +0200 +++ lpf.c 2007-06-07 19:11:48.000000000 +0200 @@ -166,70 +166,49 @@ # endif #endif -char *Time_str(int shortform, time_t t); + +static char *lpf_time_str(int shortform, time_t t) +{ + static char buffer[99]; + struct tm *tmptr; + struct timeval tv={0,0}; + + + if ( gettimeofday( &tv, 0 ) == -1 ){ + logerr_die( "Time_str: gettimeofday failed"); + } + + tmptr = localtime( &tv.tv_sec ); + SNPRINTF( buffer, sizeof(buffer)) + "%02d:%02d:%02d.%03d", + tmptr->tm_hour, tmptr->tm_min, tmptr->tm_sec, + (int)(tv.tv_usec/1000) ); + + return( buffer ); +} /* * default exit status, causes abort */ -int errorcode; -char *name; /* name of filter */ +static int errorcode; +static char *name; /* name of filter */ /* set from flags */ -int debug, width, length, xwidth, ylength, literal, indent; -char *zopts, *class, *job, *login, *accntname, *host, *accntfile, *format; -char *printer, *controlfile, *bnrname, *comment; -char *queuename, *errorfile; -int npages; /* number of pages */ -char *statusfile; -char filter_stop[] = "\031\001"; /* sent to cause filter to suspend */ -int accounting_fd; -int crlf; /* change lf to CRLF */ - -void getargs( int argc, char *argv[], char *envp[] ); -extern void banner( void ); -extern void doaccnt( void ); -extern void filter_pgm( char * ); -int of_filter; +static int debug, width, length, xwidth, ylength, literal, indent; +static char *zopts, *class, *job, *login, *accntname, *host, *accntfile, *format; +static char *printer, *controlfile, *bnrname, *comment; +static char *queuename, *errorfile; +static int npages; /* number of pages */ +static char *statusfile; +static char filter_stop[] = "\031\001"; /* sent to cause filter to suspend */ +static int accounting_fd; +static int crlf; /* change lf to CRLF */ + +static void getargs( int argc, char *argv[], char *envp[] ); +//extern void banner( void ); +//extern void doaccnt( void ); +//extern void filter_pgm( char * ); +static int of_filter; -int main( int argc, char *argv[], char *envp[] ) -{ - - /* check to see if you have the accounting fd */ - accounting_fd = dup(3); - /* if this works, then you have one */ - if( accounting_fd >= 0 ){ - (void)close( accounting_fd ); - accounting_fd = 3; - } else { - accounting_fd = -1; - } - if( fcntl(0,F_GETFL,0) == -1 ){ - FPRINTF(STDERR,"BAD FD 0\n"); - exit(2); - } - if( fcntl(1,F_GETFL,0) == -1 ){ - FPRINTF(STDERR,"BAD FD 1\n"); - exit(2); - } - if( fcntl(2,F_GETFL,0) == -1 ){ - FPRINTF(STDERR,"BAD FD 2\n"); - exit(2); - } - getargs( argc, argv, envp ); - /* - * Turn off SIGPIPE - */ - (void)signal( SIGPIPE, SIG_IGN ); - (void)signal( SIGINT, SIG_DFL ); - (void)signal( SIGHUP, SIG_DFL ); - (void)signal( SIGQUIT, SIG_DFL ); - (void)signal( SIGCHLD, SIG_DFL ); - if( of_filter || (format && format[0] == 'o') ){ - filter_pgm( filter_stop ); - } else { - filter_pgm( (char *)0 ); - } - return(0); -} static int Write_fd_str( int fd, const char *msg ) { @@ -238,6 +217,7 @@ return write(fd,msg,n); } + /* VARARGS2 */ #ifdef HAVE_STDARGS void safefprintf (int fd, char *format,...) @@ -261,6 +241,8 @@ Write_fd_str(fd,buf); } + + /**************************************************************************** * Extract the necessary definitions for error message reporting ****************************************************************************/ @@ -336,14 +318,14 @@ * writes the accounting information to the accounting file * This has the format: user host printer pages format date */ -void doaccnt(void) +static void doaccnt(void) { time_t t; char buffer[256]; FILE *f; int l, len, c; + // t = time((time_t *)0); - t = time((time_t *)0); SNPRINTF(buffer, sizeof(buffer)) "%s\t%s\t%s\t%7d\t%s\t%s\n", login? login: "NULL", @@ -351,7 +333,8 @@ printer? printer: "NULL", npages, format? format: "NULL", - Time_str(0,0)); + lpf_time_str(0,0)); + len = strlen( buffer ); if( accounting_fd < 0 ){ if(accntfile && (f = fopen(accntfile, "a" )) != NULL ) { @@ -383,7 +366,7 @@ of_filter = (strstr( s, "of" ) != 0); for( i = 1; i < argc && (arg = argv[i])[0] == '-'; ++i ){ if( (c = arg[1]) == 0 ){ - FPRINTF( STDERR, "missing option flag"); + FPRINTF( STDERR, _("missing option flag")); i = argc; break; } @@ -395,7 +378,7 @@ if( arg[2] == 0 ){ optargv = argv[i++]; if( optargv == 0 ){ - FPRINTF( STDERR, "missing option '%c' value", c ); + FPRINTF( STDERR,_( "missing option '%c' value"), c ); i = argc; break; } @@ -444,9 +427,9 @@ int fd; fd = open( errorfile, O_APPEND | O_WRONLY, 0600 ); if( fd < 0 ){ - FPRINTF( STDERR, "cannot open error log file '%s'", errorfile ); + FPRINTF( STDERR, _("cannot open error log file '%s'"), errorfile ); } else { - FPRINTF( STDERR, "using error log file '%s'", errorfile ); + FPRINTF( STDERR, _("using error log file '%s'"), errorfile ); if( fd != 2 ){ dup2(fd, 2 ); close(fd); @@ -461,7 +444,7 @@ FPRINTF( STDERR, "\n" ); } if( debug ){ - FPRINTF(STDERR, "FILTER decoded options: " ); + FPRINTF(STDERR,_("FILTER decoded options: ") ); FPRINTF(STDERR,"accntfile '%s'\n", accntfile? accntfile : "null" ); FPRINTF(STDERR,"accntname '%s'\n", accntname? accntname : "null" ); FPRINTF(STDERR,"class '%s'\n", class? class : "null" ); @@ -481,7 +464,7 @@ FPRINTF(STDERR,"ylength, %d\n", ylength); FPRINTF(STDERR,"zopts '%s'\n", zopts? zopts : "null" ); - FPRINTF(STDERR, "FILTER environment: " ); + FPRINTF(STDERR, _("FILTER environment: ") ); for( i = 0; (arg = envp[i]); ++i ){ FPRINTF(STDERR,"%s\n", arg ); } @@ -506,7 +489,7 @@ * if any. ******************************************/ -void filter_pgm(char *stop) +static void filter_pgm(char *stop) { int c; int state, i, xout, lastc; @@ -580,39 +563,49 @@ doaccnt(); } -/* - * Time_str: return "cleaned up" ctime() string... - * - * in YY/MO/DY/hr:mn:sc - * Thu Aug 4 12:34:17 BST 1994 -> 12:34:17 - */ -char *Time_str(int shortform, time_t t) +int main( int argc, char *argv[], char *envp[] ) { - static char buffer[99]; - struct tm *tmptr; - struct timeval tv; +#if defined (HAVE_LOCALE_H) + setlocale(LC_ALL, ""); + bindtextdomain (PACKAGE, LOCALEDIR); + textdomain (PACKAGE); +#endif - tv.tv_usec = 0; - if( t == 0 ){ - if( gettimeofday( &tv, 0 ) == -1 ){ - logerr_die( "Time_str: gettimeofday failed"); - } - t = tv.tv_sec; + /* check to see if you have the accounting fd */ + accounting_fd = dup(3); + /* if this works, then you have one */ + if( accounting_fd >= 0 ){ + (void)close( accounting_fd ); + accounting_fd = 3; + } else { + accounting_fd = -1; } - tmptr = localtime( &t ); - if( shortform ){ - SNPRINTF( buffer, sizeof(buffer)) - "%02d:%02d:%02d.%03d", - tmptr->tm_hour, tmptr->tm_min, tmptr->tm_sec, - (int)(tv.tv_usec/1000) ); + if( fcntl(0,F_GETFL,0) == -1 ){ + FPRINTF(STDERR,"BAD FD 0\n"); + exit(2); + } + if( fcntl(1,F_GETFL,0) == -1 ){ + FPRINTF(STDERR,"BAD FD 1\n"); + exit(2); + } + if( fcntl(2,F_GETFL,0) == -1 ){ + FPRINTF(STDERR,"BAD FD 2\n"); + exit(2); + } + getargs( argc, argv, envp ); + /* + * Turn off SIGPIPE + */ + (void)signal( SIGPIPE, SIG_IGN ); + (void)signal( SIGINT, SIG_DFL ); + (void)signal( SIGHUP, SIG_DFL ); + (void)signal( SIGQUIT, SIG_DFL ); + (void)signal( SIGCHLD, SIG_DFL ); + if( of_filter || (format && format[0] == 'o') ){ + filter_pgm( filter_stop ); } else { - SNPRINTF( buffer, sizeof(buffer)) - "%d-%02d-%02d-%02d:%02d:%02d.%03d", - tmptr->tm_year+1900, tmptr->tm_mon+1, tmptr->tm_mday, - tmptr->tm_hour, tmptr->tm_min, tmptr->tm_sec, - (int)(tv.tv_usec/1000) ); + filter_pgm( (char *)0 ); } - /* now format the time */ - return( buffer ); + return(0); } |