home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
muleos2.zip
/
omake.zip
/
newsconv.c
< prev
Wrap
C/C++ Source or Header
|
1994-02-18
|
6KB
|
231 lines
/*
uupcùp âjâàü[âXâRâôâoü[âgâvâìâOâëâÇ by O.Sasaki 1993.11
uupc rnews é¬ ò█æ╢é╖éΘâjâàü[âXâfü[â^é╠EOLé¬ CR/LF é╔é╚é┴é─éóéΘé╠é¬
GNUSé┼ê╡éñÅπé┼Ä╫ûéé╚é╠é┼üAEOLé≡LFé╠é▌é╔âRâôâoü[âgé╖éΘâvâìâOâëâÇé┼é╖üB
uupc rnewsé≡ò╧ìXé≡é╖éΘé╠é¬êΩö╘éóéóé╠é┼é╖é¬üAî┬Élé╔éµé┴é─æûé┴é─éóéΘ
uupcé╠âoü[âWâçâôé¬êßéñé╠é┼üAì╖ò¬é≡ì∞éΘé╠é¬û╩ô|é╛é┴é╜é╜é▀üA
ÅoùêÅπé¬é┴é─âeâLâXâgé⌐éτCRé≡ìφÅ£é╖éΘéµéñé╔é╡é▄é╡é╜üB
é▒é╠ò√û@é≡ì╠ùpé╡é╜é╠é═üAGNUSê╙èOé┼âjâàü[âXé≡ô╟é±é┼éóéΘÉlé╔é═üAEOLé¬
é╟éñé╚é┴é─éóé─éαè╓îWé╚éóé╡üAuupcé╠âoü[âWâçâôé¬éóé¡é┬é┼éαüAâjâàü[âXé≡
ô╟é▀éΘéµéñé╚è┬ï½é¬é┼é½é│éóé╖éΩé╬üAGNUSé┼âjâàü[âXé¬ô╟é▀éΘéµéñé╔é╚éΘ
ôÖé╠ùÿô_é¬ùLéΦé▄é╖üB
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/utime.h>
#define BUFFER_SIZE 256
#define HEADER_SIZE 2048
typedef struct {
char *name ;
char **value ;
} CONFIGDATA ;
char TmpName[] = "_)news(_.tmp" ;
char wbuf[HEADER_SIZE] ; /* ö─ùpâÅü[âNâoâbâtâ@ */
char nbuf[BUFFER_SIZE] ; /* ÉVâAâNâeâBâuôⁿù═âoâbâtâ@ */
char newsdir[BUFFER_SIZE] ; /* âjâàü[âXâfâBâîâNâgâèü[ */
char newsfile[BUFFER_SIZE] ; /* âjâàü[âXâtâ@âCâï */
char newstmp[BUFFER_SIZE] ; /* âjâàü[âXâtâ@âCâï */
char *UupcConfDir = NULL ; /* UUPCâRâôâtâBâOâfâBâîâNâgâèü[ */
char *UupcNewsDir = NULL ; /* UUPCâjâàü[âXâfâBâîâNâgâèü[ */
struct stat sb ;
struct utimbuf tb ;
CONFIGDATA Conf[] = {
{ "confdir", &UupcConfDir } ,
{ "newsdir", &UupcNewsDir } ,
{ NULL, NULL }
} ;
/********************************************************/
/* */
/* UUPCÉ▌ÆΦè┬ï½ô╟é▌ĵéΦÅêù¥ */
/* */
/* òKùvé╚É▌ÆΦìÇû┌é≡ô╟é▌ì₧é▌èeò╧Éöé╔ò█æ╢é╖éΘ */
/* */
/********************************************************/
void GetConfigData( char *rcname )
{
char *fname, *pos ;
FILE *fp ;
int lp, find ;
char tmp[BUFFER_SIZE] ;
fname = getenv( rcname ) ;
fp = fopen( fname, "r" ) ;
while ( fgets( tmp, BUFFER_SIZE, fp ) != NULL ) {
/* âRâüâôâgìsé═âXâLâbâv */
if ( *tmp == '#' )
continue ;
/* ɵô¬é╠ï≤öÆé≡Å┴é╡üAï≤ìsé╚éτâXâLâbâv */
pos = tmp ;
while ( isspace( *pos ) ) ++pos ;
if ( *pos == '\0' )
continue ;
strcpy( wbuf, pos ) ;
/* ÅIéφéΦé╠ï≤öÆéαìφÅ£é╖éΘ */
pos = strstr( wbuf, "\n" ) ;
while ( isspace( *pos ) ) --pos ;
*(++pos) = '\0' ;
/* âRâôâtâBâOÄ»ò╩Äqé≡É╪éΦÅoé╖ */
strcpy( tmp, wbuf ) ;
if ( ( pos = strstr( tmp, "=" ) ) == NULL )
continue ;
*pos = '\0' ;
strcpy( wbuf, wbuf + ( pos - tmp ) + 1 ) ;
/* âRâôâtâBâOÄ»ò╩Äqé≡żò╢ÄÜë╗é╖éΘ */
for ( pos = tmp ; *pos ; ++pos )
*pos = ( char )tolower( *pos ) ;
lp = find = 0 ;
while ( Conf[lp].name != NULL ) {
if ( strstr( tmp, Conf[lp].name ) == tmp ) {
find = lp + 1 ;
break ;
}
++lp ;
}
if ( !find )
continue ;
--find ;
if ( *Conf[find].value == NULL ) {
*Conf[find].value = malloc( strlen( wbuf ) + 1 ) ;
} else {
*Conf[find].value = realloc( *Conf[find].value,
strlen( wbuf ) + 1 ) ;
}
strcpy( Conf[find].value[0], wbuf ) ;
}
}
/********************************************************/
/* */
/* UUPCâRâôâtâBâOâtâ@âCâïùpò╧Éöé╠èJò· */
/* */
/********************************************************/
void FreeUupcValue( )
{
int lp ;
lp = 0 ;
while ( Conf[lp].name != NULL ) {
if ( *Conf[lp].value != NULL ) {
free( *Conf[lp].value ) ;
}
++lp ;
}
}
/********************************************************/
/* */
/* âüâCâôÅêù¥é╛éµ */
/* */
/********************************************************/
main( int argc, char *argv[] )
{
FILE *new, *old, *in, *out ;
int lp, len ;
int start, end, dmy ;
char *pnt ;
/* UUPCè┬ï½ÄµéΦì₧é▌ */
GetConfigData( "UUPCSYSRC" ) ;
GetConfigData( "UUPCUSRRC" ) ;
strcpy( wbuf, UupcConfDir ) ;
strcat( wbuf, "/active" ) ;
if ( ( new = fopen( wbuf, "r" ) ) == NULL ) {
FreeUupcValue( ) ;
exit( 1 ) ;
}
strcpy( wbuf, UupcConfDir ) ;
strcat( wbuf, "/newsconv" ) ;
old = fopen( wbuf, "r" ) ;
while ( fgets( nbuf, BUFFER_SIZE, new ) != NULL ) {
sscanf( nbuf, "%s %d %d", wbuf, &end, &start ) ;
for ( pnt = wbuf; *pnt; ++pnt )
if ( *pnt == '.' )
*pnt = '/' ;
sprintf( newsdir, "%s/%s", UupcNewsDir, wbuf ) ;
if ( old ) {
fgets( nbuf, BUFFER_SIZE, old ) ;
sscanf( nbuf, "%s %d", wbuf, &start ) ;
++start ;
}
for ( lp = start; lp <= end; ++lp ) {
sprintf( newsfile, "%s/%d", newsdir, lp ) ;
sprintf( newstmp, "%s.tmp", newsfile ) ;
if ( stat( newsfile, &sb ) == -1 )
continue ;
tb.actime = sb.st_atime ;
tb.modtime = sb.st_mtime ;
in = fopen( newsfile, "rb" ) ;
fgets( wbuf, HEADER_SIZE, in ) ;
len = strlen( wbuf ) ;
if ( wbuf[len -2] != '\r' ) {
fclose( in ) ;
continue ;
}
out = fopen( newstmp, "wb" ) ;
do {
len = strlen( wbuf ) ;
if ( wbuf[len -2] == '\r' ) {
wbuf[len -2] = '\n' ;
wbuf[len -1] = '\0' ;
}
fputs( wbuf, out ) ;
} while ( fgets( wbuf, HEADER_SIZE, in ) != 0 ) ;
fclose( out ) ;
fclose( in ) ;
strcpy( wbuf, newsfile ) ;
strcat( wbuf, ".bak" ) ;
if ( rename( newsfile, wbuf ) != -1 ) {
if ( rename( newstmp, newsfile ) != -1 ) {
utime( newsfile, &tb ) ;
unlink( wbuf ) ;
}
}
printf( "%s...done\n", newsfile ) ;
}
}
fclose( new ) ;
if ( old )
fclose( old ) ;
strcpy( wbuf, UupcConfDir ) ;
strcat( wbuf, "/active" ) ;
new = fopen( wbuf, "r" ) ;
strcpy( wbuf, UupcConfDir ) ;
strcat( wbuf, "/newsconv" ) ;
old = fopen( wbuf, "w" ) ;
while ( fgets( nbuf, BUFFER_SIZE, new ) != NULL )
fputs( nbuf, old ) ;
fclose( new ) ;
fclose( old ) ;
return 0 ;
}