
Новичок
Профиль
Группа: Участник
Сообщений: 10
Регистрация: 11.1.2007
Репутация: нет Всего: нет
|
From BCC32 Код | #include <stdio.h> #include <stdlib.h> #include <string.h> #include <dir.h>
#include <windows.h>
WIN32_FIND_DATA ffd; //FindFileData char *fexist( const char *Fname );
struct cell {
char htmteg[500]; struct cell *po; };
void main( int argc, char *argv[] ) { int i, j, c, q, p, ch, fs; char fname_in[MAXPATH], buf[500], old_dir[MAXDIR], new_dir[MAXDIR], drive[MAXDRIVE], dir[MAXDIR], file[MAXFILE], ext[MAXEXT], grabdir[MAXDIR], grabfile[MAXPATH];
FILE *f; if( argc >1 ) strcpy( fname_in, argv[1] ); // именем файла будет первый аргумент командной строки else { printf( "No find file na m e!\n" ); exit(1); }
if( (f=(fopen( fname_in, "r" ))) ==NULL ) { perror( "Error reading: " ); exit(1); }
// ____________________________________________________
struct cell *rex; struct cell *start=NULL; /* начало списка */ struct cell *end=NULL; /* конец списка */
fseek( f, 0L, SEEK_SET ); for( fs=0; (ch=fgetc( f ))!=EOF; ) {
if( ch =='<' && fs==0 ) { for( fs=0, i=0; (ch=fgetc( f ))!='>'; i++ ) { if( ch==EOF ) { fs=-1; break; } buf[i]=ch; } buf[i]='\0';
/* создание списка */ if( (strstr( buf, "img" ) !=NULL) && (strstr( buf, "src" ) !=NULL) ) { rex=( cell * ) malloc ( sizeof( cell ) ); strcpy( rex->htmteg, buf );
if( start==NULL && end==NULL ) start=rex; else end->po=rex; end=rex; end->po=NULL; } } if( fs==-1 ) break; }
/* изменение списка */ rex=start; while( rex!=NULL ) { memset( buf, NULL, strlen(buf)*sizeof( char * ) );
for( i=0; (unsigned)i <strlen(rex->htmteg); i++ ) { if( rex->htmteg[i] =='i' && rex->htmteg[i+1] =='m' && rex->htmteg[i+2] =='g' ) { for( j=i, fs=0; ; j++ ) { if( (unsigned)j ==strlen(rex->htmteg) ) { fs=-1; break; } else if( rex->htmteg[j] =='s' && rex->htmteg[j+1] =='r' && rex->htmteg[j+2] =='c' ) {
for( c=j, fs=0; ; c++ ) { if( (unsigned)c ==strlen(rex->htmteg) ) { fs=-1; break; }
else if( rex->htmteg[c] =='\"' && rex->htmteg[c+1] !='\"' ) {
for( p=0,q=c+1, fs=0; ; q++, p++ ) { if( ((unsigned)q ==strlen(rex->htmteg)) || (rex->htmteg[q] =='\"' && rex->htmteg[q+1] !='\"') ) { fs=-1; break; } buf[p] =rex->htmteg[q]; } buf[p]='\0'; } if( fs==-1 ) break; } } if( fs==-1 ) break; }
if( fs==-1 ) break; } }
if( buf ) strcpy( rex->htmteg, buf ); rex=rex->po; } /* имееем список с именами файлов */ // ____________________________________________________
fnsplit( fname_in, drive, dir, file, ext ); //разберем на запчасти путь к файлу if( strlen(drive)==0 && strlen(dir)==0 ) strcpy( dir, ".\\" ); fnmerge( new_dir, drive, dir, NULL, NULL );
GetCurrentDirectory( sizeof(old_dir), old_dir ); // текущий рабочий каталог SetCurrentDirectory( new_dir ); GetCurrentDirectory( sizeof(new_dir), new_dir );
strcpy( grabdir, old_dir ); strcat( grabdir, "\\grab" );
if( !fexist( grabdir ) ) { if( CreateDirectory( grabdir, NULL ) ) printf( "Directory create by %s\n", grabdir ); else { printf( "error creating directory\n" ); exit(1); } }
rex=start; while( rex!=NULL ) {
if( !fexist( rex->htmteg ) ) printf( "No File %s\n", rex->htmteg ); else { fnsplit( rex->htmteg, drive, dir, file, ext ); fnmerge( buf, NULL, NULL, file, ext ); strcpy( grabfile, grabdir ); strcat( grabfile, "\\" ); strcat( grabfile, buf ); CopyFile( rex->htmteg, grabfile, NULL ); } rex=rex->po; }
return; }
/* ******************************************************** */ char *fexist( const char *Fname ) { HANDLE handle;
handle = FindFirstFile( Fname, &ffd ); if( handle != INVALID_HANDLE_VALUE ) { FindClose( handle ); return ffd.cFileName; }
FindClose( handle ); return NULL; }
|
Это сообщение отредактировал(а) kot_matros - 17.1.2007, 11:02
|