if (fexist(fconcat(httrack.path_log,"hts-in_progress.lock"))) {
/* Old cache */
if ( (fexist(fconcat(httrack.path_log,"hts-cache/old.dat"))) && (fexist(fconcat(httrack.path_log,"hts-cache/old.ndx"))) ) {
fprintf(httrack.log,"Warning!\n");
fprintf(httrack.log,"An aborted mirror has been detected!\nThe current temporary cache is required for any update operation and only contains data downloaded during the last aborted session.\nThe former cache might contain more complete information; if you do not want to lose that information, you have to restore it and delete the current cache.\nThis can easily be done here by erasing the hts-cache/new.* files\n");
fprintf(httrack.log,"Please restart HTTrack with --quiet (-q) option to override this message!\n");
exit(0);
}
}
}
// remplacer "macros" comme --spider
// permet de lancer httrack sans a avoir α se rappeler de syntaxes comme p0C0I0Qc32 ..
#if DEBUG_STEPS
printf("Checking last macros\n");
#endif
{
int i;
for(i=0;i<argc;i++) {
#if DEBUG_STEPS
printf("Checking #%d:\n",argv[i]);
printf("%s\n",argv[i]);
#endif
if (argv[i][0]=='-') {
if (argv[i][1]=='-') { // --xxx
// Note: on fait attention α ne pas Θcrire plus qu'il n'y avait avant..
/*
if (strfield2(argv[i]+2,"spider")) // mode spider (scan+log)
strcpy(argv[i]+1,"p0C0I0t");
else if (strfield2(argv[i]+2,"wide-spider")) // spider
strcpy(argv[i]+1,"p0C0I0c32t");
else if (strfield2(argv[i]+2,"tiny-spider")) // i am a little grasshoper
strcpy(argv[i]+1,"p0C0I0c1t");
else if (strfield2(argv[i]+2,"testsite")) // mode test site (scan+log)
strcpy(argv[i]+1,"p0C0I0t");
else if (strfield2(argv[i]+2,"wide-testsite"))
strcpy(argv[i]+1,"p0C0I0c32t");
else if (strfield2(argv[i]+2,"tiny-testsite"))
strcpy(argv[i]+1,"p0C0I0c1t");
//
else if (strfield2(argv[i]+2,"testlinks")) // mode test bookmark (scan+log)
strcpy(argv[i]+1,"r1p0C0I0t");
else if (strfield2(argv[i]+2,"wide-testlinks"))
strcpy(argv[i]+1,"r1p0C0I0c32t");
else if (strfield2(argv[i]+2,"tiny-testlinks"))
strcpy(argv[i]+1,"r1p0C0I0c1t");
else if ( (strfield2(argv[i]+2,"testlink")) || (strfield2(argv[i]+2,"bookmark"))) {
HTS_PANIC_PRINTF("Please use --testlinks to check links in a page");
return -1;
}
//
else if (strfield2(argv[i]+2,"mirrorlinks")) // mode test bookmark (scan+log)
strcpy(argv[i]+1,"Y");
else if (strfield2(argv[i]+2,"wide-mirrorlinks")) // mode test bookmark (scan+log)
strcpy(argv[i]+1,"Yc32");
else if (strfield2(argv[i]+2,"tiny-mirrorlinks")) // mode test bookmark (scan+log)
strcpy(argv[i]+1,"Yc1");
//
else if (strfield2(argv[i]+2,"mirror")) // miroir (mode par dΘfaut)
strcpy(argv[i]+1,"");
else if (strfield2(argv[i]+2,"wide-mirror"))
strcpy(argv[i]+1,"c32");
else if (strfield2(argv[i]+2,"tiny-mirror"))
strcpy(argv[i]+1,"c1");
//
else if (strfield2(argv[i]+2,"testscan")) // scan sans log
strcpy(argv[i]+1,"p0C0I0Q");
else if (strfield2(argv[i]+2,"wide-testscan"))
strcpy(argv[i]+1,"p0C0I0c32Q");
else if (strfield2(argv[i]+2,"tiny-testscan"))
strcpy(argv[i]+1,"p0C0I0c1Q");
else if ((strfield2(argv[i]+2,"scan")) || (strfield2(argv[i]+2,"test")) || (strfield2(argv[i]+2,"check"))) {
HTS_PANIC_PRINTF("Please use --spider to check all links in a site");
return -1;
}
//
else if (strfield2(argv[i]+2,"skeleton")) // rΘcupΘrer squelette (html)
strcpy(argv[i]+1,"p1");
else if (strfield2(argv[i]+2,"wide-skeleton"))
strcpy(argv[i]+1,"p1c32");
else if (strfield2(argv[i]+2,"tiny-skeleton"))
strcpy(argv[i]+1,"p1c1");
//
else if (strfield2(argv[i]+2,"get")) // rΘcupΘrer fichiers isolΘs
strcpy(argv[i]+1,"qg");
else if (strfield2(argv[i]+2,"update")) // update: pas de question
strcpy(argv[i]+1,"iC2");
else if (strfield2(argv[i]+2,"continue")) // continue, cache prio
strcpy(argv[i]+1,"iC1");
else if (strfield2(argv[i]+2,"restart")) // idem
strcpy(argv[i]+1,"iC1");
//
else if (strfield2(argv[i]+2,"sucker")) // web sucker...toi aussi suce le web!
strcpy(argv[i]+1,"r99");
//
else if (strfield2(argv[i]+2,"help")) // un peu d'aide
strcpy(argv[i]+1,"h");
else if (strfield2(argv[i]+2,"documentation"))
strcpy(argv[i]+1,"h");
else if (strfield2(argv[i]+2,"doc"))
strcpy(argv[i]+1,"h");
//
else if (strfield2(argv[i]+2,"wide"))
strcpy(argv[i]+1,"c32");
else if (strfield2(argv[i]+2,"tiny"))
strcpy(argv[i]+1,"c1");
else if (strfield2(argv[i]+2,"ultrawide")) // oulαα..
strcpy(argv[i]+1,"c48");
//
else if (strfield2(argv[i]+2,"http10")) // use if possible HTTP/1.0
strcpy(argv[i]+1,"%h");
//
else if ( (strfield2(argv[i]+2,"filelist")) // file list
|| (strfield2(argv[i]+2,"list")) )
strcpy(argv[i]+1,"%L");
else */
if ((strfield2(argv[i]+2,"clean")) || (strfield2(argv[i]+2,"tide"))) { // nettoyer
strcpy(argv[i]+1,"");
if (fexist(fconcat(httrack.path_log,"hts-log.txt")))
remove(fconcat(httrack.path_log,"hts-log.txt"));
if (fexist(fconcat(httrack.path_log,"hts-err.txt")))
remove(fconcat(httrack.path_log,"hts-err.txt"));
if (fexist(fconcat(httrack.path_html,"index.html")))
remove(fconcat(httrack.path_html,"index.html"));
if (fexist(fconcat(httrack.path_log,"hts-cache/new.dat")))
httrack.quiet=1; // ne pas poser de questions! (nohup par exemple)
if ((strchr(argv[na],'i')!=NULL)) { // doit.log!
argv_url=0;
na=argc;
}
}
}
}
*/
// Ici on ajoute les arguments qui ont ΘtΘ appelΘs avant au cas o∙ on rΘcupΦre une session
// Exemple: httrack www.truc.fr -L0 puis ^C puis httrack sans URL : ajouter URL prΘcΘdente
/*
if (argv_url==0) {
//if ((fexist(fconcat(httrack.path_log,"hts-cache/new.dat"))) && (fexist(fconcat(httrack.path_log,"hts-cache/new.ndx")))) { // il existe dΘja un cache prΘcΘdent.. renommer
if (fexist(fconcat(httrack.path_log,"hts-cache/doit.log"))) { // un cache est prΘsent
if ((strcmp(argv[na],"-P")==0) || (strcmp(argv[na],"-N")==0) || (strcmp(argv[na],"-F")==0) || (strcmp(argv[na],"-O")==0) || (strcmp(argv[na],"-V")==0))
na++; // sauter nom de proxy
} else {
if ((strchr(argv[na],'q')!=NULL) || (strchr(argv[na],'i')!=NULL))
httrack.quiet=1; // ne pas poser de questions! (nohup par exemple)
}
}
}
*/
// Pas d'URL
#if DEBUG_STEPS
printf("Checking URLs\n");
#endif
if (argv_url==0) {
// PrΘsence d'un cache, que faire?..
if ((fexist(fconcat(httrack.path_log,"hts-cache/new.dat"))) && (fexist(fconcat(httrack.path_log,"hts-cache/new.ndx")))) { // il existe dΘja un cache prΘcΘdent.. renommer
if (fexist(fconcat(httrack.path_log,"hts-cache/doit.log"))) { // un cache est prΘsent
HTS_PANIC_PRINTF("A cache has been found, but no command line");
printf("Please launch httrack with proper parameters to reuse the cache\n");
return -1;
}
} else { // aucune URL dΘfinie et pas de cache
#if HTS_ANALYSTE!=2
if (httrack.quiet) {
#endif
help(argv[0],!httrack.quiet);
return -1;
#if HTS_ANALYSTE!=2
} else {
help_wizard(&httrack);
return -1;
}
#endif
return 0;
}
} else { // plus de 2 paramΦtres
// un fichier log existe?
if (fexist(fconcat(httrack.path_log,"hts-in_progress.lock"))) { // fichier lock?
//char s[32];
httrack.cache=1; // cache prioritaire
if (httrack.quiet==0) {
if ((fexist(fconcat(httrack.path_log,"hts-cache/new.dat"))) && (fexist(fconcat(httrack.path_log,"hts-cache/new.ndx")))) { // il existe dΘja un cache prΘcΘdent.. renommer
HT_REQUEST_START;
HT_PRINT("There is a lock-file in the current directory"LF);
HT_PRINT("That means that a mirror has not been terminated"LF);
HT_PRINT("Be sure you call httrack with proper parameters"LF);
HT_PRINT("(The cache allows you to restart faster the transfer)"LF);
HT_REQUEST_END;
if (!ask_continue()) return 0;
/*} else {
HT_PRINT("There is a lock-file in the current directory"LF);
HT_PRINT("That means that a mirror has not been terminated"LF);
HT_PRINT("There is no cache, HTtrack will not be able to use formerly loaded files"LF);*/
}
}
} else if (fexist(fconcat(httrack.path_html,"index.html"))) {
//char s[32];
httrack.cache=2; // cache vient aprΦs test de validitΘ
if (httrack.quiet==0) {
if ((fexist(fconcat(httrack.path_log,"hts-cache/new.dat"))) && (fexist(fconcat(httrack.path_log,"hts-cache/new.ndx")))) { // il existe dΘja un cache prΘcΘdent.. renommer
HT_REQUEST_START;
HT_PRINT("There is an index.html in the current directory, and a cache"LF);
HT_PRINT("A site may have been mirrored here, that could mean that you want to update it"LF);
HT_PRINT("Be sure parameters are ok"LF);
HT_REQUEST_END;
if (!ask_continue()) return 0;
} else {
HT_REQUEST_START;
HT_PRINT("There is an index.html in the current directory, but no cache"LF);
HT_PRINT("A site may have been mirrored here, and erased.."LF);
HT_PRINT("Be sure parameters are ok"LF);
HT_REQUEST_END;
if (!ask_continue()) return 0;
}
}
}
}
// Treat parameters
// Traiter les paramΦtres
#if DEBUG_STEPS
printf("Analyze parameters\n");
#endif
{
char* com;
int na;
for(na=1;na<argc;na++) {
if (argv[na][0]=='"') {
char tempo[HTS_CDLMAXSIZE];
strcpy(tempo,argv[na]+1);
if (tempo[strlen(tempo)-1]!='"') {
char s[HTS_CDLMAXSIZE];
sprintf(s,"Missing quote in %s",argv[na]);
HTS_PANIC_PRINTF(s);
return -1;
}
tempo[strlen(tempo)-1]='\0';
strcpy(argv[na],tempo);
}
if (cmdl_opt(argv[na])) { // option
com=argv[na]+1;
while(*com) {
switch(*com) {
case ' ': case 9: case '-': case '\0': break;
//
case 'h': help(argv[0],0); return 0; // dΘja fait normalement
//
case 'g': // rΘcupΘrer un (ou plusieurs) fichiers isolΘs
httrack.wizard=2; // le wizard on peut plus s'en passer..
//httrack.wizard=0; // pas de wizard
httrack.cache=0; // ni de cache
httrack.makeindex=0; // ni d'index
httrack_logmode=1; // erreurs α l'Θcran
httrack.savename_type=1003; // mettre dans le rΘpertoire courant
httrack.depth=0; // ne pas explorer la page
break;
case 'w': httrack.wizard=2; // wizard 'soft' (ne pose pas de questions)
httrack.travel=0;
httrack.seeker=1;
break;
case 'W': httrack.wizard=1; // Wizard-Help (pose des questions)
httrack.travel=0;
httrack.seeker=1;
break;
case 'r': // n'est plus le recurse get bestial mais wizard itou!
if (isdigit((unsigned char)*(com+1))) {
sscanf(com+1,"%d",&httrack.depth);
while(isdigit((unsigned char)*(com+1))) com++;
} else httrack.depth=3;
break;
/*
case 'r': httrack.wizard=0;
if (isdigit((unsigned char)*(com+1))) {
sscanf(com+1,"%d",&httrack.depth);
while(isdigit((unsigned char)*(com+1))) com++;
} else httrack.depth=3;
break;
*/
//
// note: les tests httrack.depth sont pour Θviter de faire
// un miroir du web (:-O) accidentelement ;-)
case 'a': /*if (httrack.depth==9999) httrack.depth=3;*/
httrack.travel=0+(httrack.travel&256); break;
case 'd': /*if (httrack.depth==9999) httrack.depth=3;*/
httrack.travel=1+(httrack.travel&256); break;
case 'l': /*if (httrack.depth==9999) httrack.depth=3;*/
httrack.travel=2+(httrack.travel&256); break;
case 'e': /*if (httrack.depth==9999) httrack.depth=3;*/
httrack.travel=7+(httrack.travel&256); break;
case 't': httrack.travel|=256; break;
case 'n': httrack.nearlink=1; break;
case 'x': httrack.external=1; break;
//
case 'U': httrack.seeker=2; break;
case 'D': httrack.seeker=1; break;
case 'S': httrack.seeker=0; break;
case 'B': httrack.seeker=3; break;
//
case 'Y': httrack.mirror_first_page=1; break;
//
case 'q': case 'i': httrack.quiet=1; break;
//
case 'Q': httrack_logmode=0; break;
case 'v': httrack_logmode=1; break;
case 'f': httrack_logmode=2; if (*(com+1)=='2') httrack_logmode=3; while(isdigit((unsigned char)*(com+1))) com++; break;
//
//case 'A': httrack.urlmode=1; break;
//case 'R': httrack.urlmode=2; break;
case 'K': httrack.urlmode=0; if (*(com+1)=='0') { httrack.urlmode=2; com++; } break;
//
case 'c':
if (isdigit((unsigned char)*(com+1))) {
sscanf(com+1,"%d",&httrack.maxsoc);
while(isdigit((unsigned char)*(com+1))) com++;
httrack.maxsoc=max(httrack.maxsoc,1); // FORCER A 1
} else httrack.maxsoc=8;
break;
//
case 'p': sscanf(com+1,"%d",&httrack.getmode); while(isdigit((unsigned char)*(com+1))) com++; break;
//
case 'G': sscanf(com+1,"%d",&httrack.fragment); while(isdigit((unsigned char)*(com+1))) com++; break;
case 'M': sscanf(com+1,"%d",&httrack.maxsite); while(isdigit((unsigned char)*(com+1))) com++; break;
case 'm': sscanf(com+1,"%d",&httrack.maxfile_nonhtml); while(isdigit((unsigned char)*(com+1))) com++;
fprintf(httrack.log,"* * MIRROR ABORTED! * *\nThe current temporary cache is required for any update operation and only contains data downloaded during the present aborted session.\nThe former cache might contain more complete information; if you do not want to lose that information, you have to restore it and delete the current cache.\nThis can easily be done here by erasing the hts-cache/new.* files]\n");
}
}
#if HTS_ANALYSTE
hts_htmlcheck_uninit();
#endif
if (httrack_logmode==1) {
if (httrack.errlog == httrack.log) httrack.errlog=NULL;
if (httrack.log) { fclose(httrack.log); httrack.log=NULL; }
if (httrack.errlog) { fclose(httrack.errlog); httrack.errlog=NULL; }
}
// DΘbuggage des en tΩtes
if (_DEBUG_HEAD) {
if (ioinfo) {
fclose(ioinfo);
}
}
// supprimer lock
remove(n_lock);
}
if (x_argvblk)
freet(x_argvblk);
#if HTS_WIN
#if HTS_ANALYSTE!=2
// WSACleanup(); // ** non en cas de thread tjs prΘsent!..
#endif
#endif
#if HTS_TRACE_MALLOC
hts_freeall();
#endif
printf("Thanks for using HTTrack!\n");
io_flush;
return 0; // OK
}
// main() subroutines
// vΘrifier chemin path
void check_path(char* s) {
int i;
expand_home(s); /* expand from ~/ to /home/smith/ */