home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 July / CMCD0704.ISO / Software / Freeware / Comunicatii / htttrack / httrack-3.32-2.exe / {app} / src / httrack.c < prev    next >
Encoding:
C/C++ Source or Header  |  2004-04-07  |  19.4 KB  |  632 lines

  1. /* ------------------------------------------------------------ */
  2. /*
  3. HTTrack Website Copier, Offline Browser for Windows and Unix
  4. Copyright (C) Xavier Roche and other contributors
  5.  
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  19.  
  20.  
  21. Important notes:
  22.  
  23. - We hereby ask people using this source NOT to use it in purpose of grabbing
  24. emails addresses, or collecting any other private information on persons.
  25. This would disgrace our work, and spoil the many hours we spent on it.
  26.  
  27.  
  28. Please visit our Website: http://www.httrack.com
  29. */
  30.  
  31.  
  32. /* ------------------------------------------------------------ */
  33. /* File: htsshow.c console progress info                        */
  34. /* Only used on Linux version                                   */
  35. /* Author: Xavier Roche                                         */
  36. /* ------------------------------------------------------------ */
  37.  
  38. #ifndef _WIN32
  39. #ifndef Sleep
  40. #define Sleep(a) { if (((a)*1000)%1000000) usleep(((a)*1000)%1000000); if (((a)*1000)/1000000) sleep(((a)*1000)/1000000); }
  41. #endif
  42. #endif
  43.  
  44. #include "httrack-library.h"
  45.  
  46. #include "htsglobal.h"
  47. #include "htsbase.h"
  48. #include "htsopt.h"
  49. #include "httrack.h"
  50.  
  51. /* Static definitions */
  52. static int fexist(char* s);
  53. static int linput(FILE* fp,char* s,int max);
  54.  
  55.  
  56. // htswrap_add
  57. #include "htswrap.h"
  58.  
  59. #if HTS_ANALYSTE_CONSOLE
  60.  
  61. /* specific definitions */
  62. //#include "htsbase.h"
  63. #include <stdio.h>
  64. #include <stdlib.h>
  65. #include <string.h>
  66. #ifdef HAVE_SYS_TYPES_H
  67. #include <sys/types.h>
  68. #endif
  69. #ifdef HAVE_SYS_STAT_H
  70. #include <sys/stat.h>
  71. #endif
  72. #ifdef HAVE_UNISTD_H
  73. #include <unistd.h>
  74. #endif
  75. #include <ctype.h>
  76. #ifdef _WIN32
  77. //#include "Winsock.h"
  78. #endif
  79. /* END specific definitions */
  80.  
  81. // ISO VT100/220 definitions
  82. #define VT_COL_TEXT_BLACK    "30"
  83. #define VT_COL_TEXT_RED      "31"
  84. #define VT_COL_TEXT_GREEN    "32"
  85. #define VT_COL_TEXT_YELLOW   "33"
  86. #define VT_COL_TEXT_BLUE     "34"
  87. #define VT_COL_TEXT_MAGENTA  "35"
  88. #define VT_COL_TEXT_CYAN     "36"
  89. #define VT_COL_TEXT_WHITE    "37"
  90. #define VT_COL_BACK_BLACK    "40"
  91. #define VT_COL_BACK_RED      "41"
  92. #define VT_COL_BACK_GREEN    "42"
  93. #define VT_COL_BACK_YELLOW   "43"
  94. #define VT_COL_BACK_BLUE     "44"
  95. #define VT_COL_BACK_MAGENTA  "45"
  96. #define VT_COL_BACK_CYAN     "46"
  97. #define VT_COL_BACK_WHITE    "47"
  98. //
  99. #define VT_GOTOXY(X,Y)  "\33["Y";"X"f"
  100. #define VT_COLOR(C)     "\33["C"m"
  101. #define VT_RESET        "\33[m"
  102. #define VT_REVERSE      "\33[7m"
  103. #define VT_UNREVERSE    "\33[27m"
  104. #define VT_BOLD         "\33[1m"
  105. #define VT_UNBOLD       "\33[22m"
  106. #define VT_BLINK        "\33[5m"
  107. #define VT_UNBLINK      "\33[25m"
  108. //
  109. #define VT_CLREOL       "\33[K"
  110. #define VT_CLRSOL       "\33[1K"
  111. #define VT_CLRLIN       "\33[2K"
  112. #define VT_CLREOS       "\33[J"
  113. #define VT_CLRSOS       "\33[1J"
  114. #define VT_CLRSCR       "\33[2J"
  115. //
  116. #define csi(X)          printf(s_csi( X ));
  117. static void vt_clear(void) {
  118.   printf("%s%s%s",VT_RESET,VT_CLRSCR,VT_GOTOXY("1","0"));
  119. }
  120. static void vt_home(void) {
  121.   printf("%s%s",VT_RESET,VT_GOTOXY("1","0"));
  122. }
  123. //
  124.  
  125.  
  126. /*
  127. #define STYLE_STATVALUES VT_COLOR(VT_COL_TEXT_BLACK)
  128. #define STYLE_STATTEXT   VT_COLOR(VT_COL_TEXT_BLUE)   
  129. */
  130. #define STYLE_STATVALUES VT_BOLD
  131. #define STYLE_STATTEXT   VT_UNBOLD
  132. #define STYLE_STATRESET  VT_UNBOLD
  133. #define NStatsBuffer     14
  134. #define MAX_LEN_INPROGRESS 40
  135.  
  136. static int use_show;
  137.  
  138. int main(int argc, char **argv) {
  139.   int ret = 0;
  140.   hts_init();
  141.  
  142.   /*
  143.   hts_htmlcheck_init         = (t_hts_htmlcheck_init)           htswrap_read("init");
  144. Log: "engine: init"
  145.  
  146.   hts_htmlcheck_uninit       = (t_hts_htmlcheck_uninit)         htswrap_read("free");
  147. Log: "engine: free"
  148.  
  149.   hts_htmlcheck_start        = (t_hts_htmlcheck_start)          htswrap_read("start");
  150. Log: "engine: start"
  151.  
  152.   hts_htmlcheck_end          = (t_hts_htmlcheck_end)            htswrap_read("end");
  153. Log: "engine: end"
  154.  
  155.   hts_htmlcheck_chopt        = (t_hts_htmlcheck_chopt)          htswrap_read("change-options");
  156. Log: "engine: change-options"
  157.  
  158.   hts_htmlcheck              = (t_hts_htmlcheck)                htswrap_read("check-html");
  159. Log: "check-html: <url>"
  160.  
  161.   hts_htmlcheck_query        = (t_hts_htmlcheck_query)          htswrap_read("query");
  162.   hts_htmlcheck_query2       = (t_hts_htmlcheck_query2)         htswrap_read("query2");
  163.   hts_htmlcheck_query3       = (t_hts_htmlcheck_query3)         htswrap_read("query3");
  164.   hts_htmlcheck_loop         = (t_hts_htmlcheck_loop)           htswrap_read("loop");
  165.   hts_htmlcheck_check        = (t_hts_htmlcheck_check)          htswrap_read("check-link");
  166. Log: none
  167.  
  168.   hts_htmlcheck_pause        = (t_hts_htmlcheck_pause)          htswrap_read("pause");
  169. Log: "pause: <lockfile>"
  170.  
  171.   hts_htmlcheck_filesave     = (t_hts_htmlcheck_filesave)       htswrap_read("save-file");
  172.   hts_htmlcheck_linkdetected = (t_hts_htmlcheck_linkdetected)   htswrap_read("link-detected");
  173. Log: none
  174.  
  175.   hts_htmlcheck_xfrstatus    = (t_hts_htmlcheck_xfrstatus)      htswrap_read("transfer-status");
  176. Log: 
  177.     "engine: transfer-status: link updated: <url> -> <file>"
  178.   | "engine: transfer-status: link added: <url> -> <file>"
  179.   | "engine: transfer-status: link recorded: <url> -> <file>"
  180.   | "engine: transfer-status: link link error (<errno>, '<err_msg>'): <url>"
  181.   hts_htmlcheck_savename     = (t_hts_htmlcheck_savename  )     htswrap_read("save-name");
  182. Log: 
  183.     "engine: save-name: local name: <url> -> <file>"
  184. */
  185.   
  186.   htswrap_add("init",htsshow_init);
  187.   htswrap_add("free",htsshow_uninit);
  188.   htswrap_add("start",htsshow_start);
  189.   htswrap_add("change-options",htsshow_chopt);
  190.   htswrap_add("end",htsshow_end);
  191.   htswrap_add("check-html",htsshow_checkhtml);
  192.   htswrap_add("loop",htsshow_loop);
  193.   htswrap_add("query",htsshow_query);
  194.   htswrap_add("query2",htsshow_query2);
  195.   htswrap_add("query3",htsshow_query3);
  196.   htswrap_add("check-link",htsshow_check);
  197.   htswrap_add("pause",htsshow_pause);
  198.   htswrap_add("save-file",htsshow_filesave);
  199.   htswrap_add("link-detected",htsshow_linkdetected);
  200.   htswrap_add("transfer-status",htsshow_xfrstatus);
  201.   htswrap_add("save-name",htsshow_savename);
  202.   htswrap_add("send-header", htsshow_sendheader);
  203.   htswrap_add("receive-header", htsshow_receiveheader);
  204.  
  205.   ret = hts_main(argc,argv);
  206.   if (ret) {
  207.     fprintf(stderr, "* %s\n", hts_errmsg());
  208.   }
  209.   return ret;
  210. }
  211.  
  212.  
  213. /* CALLBACK FUNCTIONS */
  214.  
  215. /* Initialize the Winsock */
  216. static void __cdecl htsshow_init(void) {
  217. #ifdef _WIN32
  218.   {
  219.     WORD   wVersionRequested;   // requested version WinSock API
  220.     WSADATA wsadata;            // Windows Sockets API data
  221.     int stat;
  222.     wVersionRequested = 0x0101;
  223.     stat = WSAStartup( wVersionRequested, &wsadata );
  224.     if (stat != 0) {
  225.       printf("Winsock not found!\n");
  226.       return;
  227.     } else if (LOBYTE(wsadata.wVersion) != 1  && HIBYTE(wsadata.wVersion) != 1) {
  228.       printf("WINSOCK.DLL does not support version 1.1\n");
  229.       WSACleanup();
  230.       return;
  231.     }
  232.   }
  233. #endif
  234.  
  235. }
  236. static void __cdecl htsshow_uninit(void) {
  237. #ifdef _WIN32
  238.   WSACleanup();
  239. #endif
  240. }
  241. static int __cdecl htsshow_start(httrackp* opt) {
  242.   use_show=0;
  243.   if (opt->verbosedisplay==2) {
  244.     use_show=1;
  245.     vt_clear();
  246.   }
  247.   return 1; 
  248. }
  249. static int __cdecl htsshow_chopt(httrackp* opt) {
  250.   return htsshow_start(opt);
  251. }
  252. static int  __cdecl htsshow_end(void) { 
  253.   return 1; 
  254. }
  255. static int __cdecl htsshow_checkhtml(char* html,int len,char* url_adresse,char* url_fichier) {
  256.   return 1;
  257. }
  258. static int __cdecl htsshow_loop(lien_back* back,int back_max,int back_index,int lien_n,int lien_tot,int stat_time, hts_stat_struct* stats) {    // appelΘ α chaque boucle de HTTrack
  259.   static TStamp prev_mytime=0; /* ok */
  260.   static t_InpInfo SInfo; /* ok */
  261.   //
  262.   TStamp mytime;
  263.   long int rate=0;
  264.   char st[256];
  265.   //
  266.   int stat_written=-1;
  267.   int stat_updated=-1;
  268.   int stat_errors=-1;
  269.   int stat_warnings=-1;
  270.   int stat_infos=-1;
  271.   int nbk=-1;
  272.   LLint nb=-1;
  273.   int stat_nsocket=-1;
  274.   LLint stat_bytes=-1;
  275.   LLint stat_bytes_recv=-1;
  276.   int irate=-1;
  277.   if (stats) {
  278.     stat_written=stats->stat_files;
  279.     stat_updated=stats->stat_updated_files;
  280.     stat_errors=stats->stat_errors;
  281.     stat_warnings=stats->stat_warnings;
  282.     stat_infos=stats->stat_infos;
  283.     nbk=stats->nbk;
  284.     stat_nsocket=stats->stat_nsocket;
  285.     irate=(int)stats->rate;
  286.     nb=stats->nb;
  287.     stat_bytes=stats->nb;
  288.     stat_bytes_recv=stats->HTS_TOTAL_RECV;
  289.   }
  290.  
  291.   if (!use_show)
  292.     return 1;
  293.  
  294.   mytime=mtime_local();
  295.   if ((stat_time>0) && (stat_bytes_recv>0))
  296.     rate=(int)(stat_bytes_recv/stat_time);
  297.   else
  298.     rate=0;    // pas d'infos
  299.  
  300.   /* Infos */
  301.   if (stat_bytes>=0) SInfo.stat_bytes=stat_bytes;      // bytes
  302.   if (stat_time>=0) SInfo.stat_time=stat_time;         // time
  303.   if (lien_tot>=0) SInfo.lien_tot=lien_tot; // nb liens
  304.   if (lien_n>=0) SInfo.lien_n=lien_n;       // scanned
  305.   SInfo.stat_nsocket=stat_nsocket;          // socks
  306.   if (rate>0)  SInfo.rate=rate;                // rate
  307.   if (irate>=0) SInfo.irate=irate;             // irate
  308.   if (SInfo.irate<0) SInfo.irate=SInfo.rate;
  309.   if (nbk>=0) SInfo.stat_back=nbk;
  310.   if (stat_written>=0) SInfo.stat_written=stat_written;
  311.   if (stat_updated>=0) SInfo.stat_updated=stat_updated;
  312.   if (stat_errors>=0)  SInfo.stat_errors=stat_errors;
  313.   if (stat_warnings>=0)  SInfo.stat_warnings=stat_warnings;
  314.   if (stat_infos>=0)  SInfo.stat_infos=stat_infos;
  315.  
  316.  
  317.   if ( ((mytime - prev_mytime)>100) || ((mytime - prev_mytime)<0) ) {
  318.     prev_mytime=mytime;
  319.  
  320.     
  321.     st[0]='\0';
  322.     qsec2str(st,stat_time);
  323.     vt_home();
  324.     printf(
  325.     VT_GOTOXY("1","1")
  326.     VT_CLREOL
  327.                            STYLE_STATTEXT   "Bytes saved:"
  328.                            STYLE_STATVALUES " \t%s"
  329.                            "\t"
  330.     VT_CLREOL
  331.     VT_GOTOXY("40","1")
  332.                            STYLE_STATTEXT   "Links scanned:"
  333.                            STYLE_STATVALUES " \t%d/%d (+%d)"
  334.     VT_CLREOL"\n"VT_CLREOL
  335.     VT_GOTOXY("1","2")
  336.                            STYLE_STATTEXT   "Time:"
  337.                                             " \t"
  338.                            STYLE_STATVALUES "%s"
  339.                            "\t"
  340.     VT_CLREOL
  341.     VT_GOTOXY("40","2")
  342.                            STYLE_STATTEXT   "Files written:"
  343.                                             " \t"
  344.                            STYLE_STATVALUES "%d"
  345.     VT_CLREOL"\n"VT_CLREOL
  346.     VT_GOTOXY("1","3")
  347.                            STYLE_STATTEXT   "Transfer rate:"
  348.                                             " \t"
  349.                            STYLE_STATVALUES "%s (%s)"
  350.                            "\t"
  351.     VT_CLREOL
  352.     VT_GOTOXY("40","3")
  353.                            STYLE_STATTEXT   "Files updated:"
  354.                                             " \t"
  355.                            STYLE_STATVALUES "%d"
  356.     VT_CLREOL"\n"VT_CLREOL
  357.     VT_GOTOXY("1","4")
  358.                            STYLE_STATTEXT   "Active connections:"
  359.                                             " \t"
  360.                            STYLE_STATVALUES "%d"
  361.                            "\t"
  362.     VT_CLREOL
  363.     VT_GOTOXY("40","4")
  364.                            STYLE_STATTEXT   "Errors:"
  365.                            STYLE_STATVALUES " \t"
  366.                            STYLE_STATVALUES "%d"
  367.     VT_CLREOL"\n"
  368.     STYLE_STATRESET
  369.     ,
  370.       /* */
  371.       (char*)int2bytes(SInfo.stat_bytes),
  372.       (int)lien_n,(int)SInfo.lien_tot,(int)nbk,
  373.       (char*)st,
  374.       (int)SInfo.stat_written,
  375.       (char*)int2bytessec(SInfo.irate),(char*)int2bytessec(SInfo.rate),
  376.       (int)SInfo.stat_updated,
  377.       (int)SInfo.stat_nsocket,
  378.       (int)SInfo.stat_errors
  379.       /* */
  380.       );
  381.  
  382.     
  383.     // parcourir registre des liens
  384.     if (back_index>=0) {  // seulement si index passΘ
  385.       int j,k;
  386.       int index=0;
  387.       int ok=0;         // idem
  388.       int l;            // idem
  389.       //
  390.       t_StatsBuffer StatsBuffer[NStatsBuffer];
  391.       
  392.       {
  393.         int i;
  394.         for(i=0;i<NStatsBuffer;i++) {
  395.           strcpybuff(StatsBuffer[i].state,"");
  396.           strcpybuff(StatsBuffer[i].name,"");
  397.           strcpybuff(StatsBuffer[i].file,"");
  398.           strcpybuff(StatsBuffer[i].url_sav,"");
  399.           StatsBuffer[i].back=0;
  400.           StatsBuffer[i].size=0;
  401.           StatsBuffer[i].sizetot=0;
  402.         }
  403.       }
  404.       for(k=0;k<2;k++) {    // 0: lien en cours 1: autres liens
  405.         for(j=0;(j<3) && (index<NStatsBuffer);j++) {  // passe de prioritΘ
  406.           int _i;
  407.           for(_i=0+k;(_i< max(back_max*k,1) ) && (index<NStatsBuffer);_i++) {  // no lien
  408.             int i=(back_index+_i)%back_max;    // commencer par le "premier" (l'actuel)
  409.             if (back[i].status>=0) {     // signifie "lien actif"
  410.               // int ok=0;  // OPTI
  411.               ok=0;
  412.               switch(j) {
  413.               case 0:     // prioritaire
  414.                 if ((back[i].status>0) && (back[i].status<99)) {
  415.                   strcpybuff(StatsBuffer[index].state,"receive"); ok=1;
  416.                 }
  417.                 break;
  418.               case 1:
  419.                 if (back[i].status==99) {
  420.                   strcpybuff(StatsBuffer[index].state,"request"); ok=1;
  421.                 }
  422.                 else if (back[i].status==100) {
  423.                   strcpybuff(StatsBuffer[index].state,"connect"); ok=1;
  424.                 }
  425.                 else if (back[i].status==101) {
  426.                   strcpybuff(StatsBuffer[index].state,"search"); ok=1;
  427.                 }
  428.                 else if (back[i].status==1000) {    // ohh le beau ftp
  429.                   sprintf(StatsBuffer[index].state,"ftp: %s",back[i].info); ok=1;
  430.                 }
  431.                 break;
  432.               default:
  433.                 if (back[i].status==0) {  // prΩt
  434.                   if ((back[i].r.statuscode==200)) {
  435.                     strcpybuff(StatsBuffer[index].state,"ready"); ok=1;
  436.                   }
  437.                   else if ((back[i].r.statuscode>=100) && (back[i].r.statuscode<=599)) {
  438.                     char tempo[256]; tempo[0]='\0';
  439.                     infostatuscode(tempo,back[i].r.statuscode);
  440.                     strcpybuff(StatsBuffer[index].state,tempo); ok=1;
  441.                   }
  442.                   else {
  443.                     strcpybuff(StatsBuffer[index].state,"error"); ok=1;
  444.                   }
  445.                 }
  446.                 break;
  447.               }
  448.               
  449.               if (ok) {
  450.                 char s[HTS_URLMAXSIZE*2];
  451.                 //
  452.                 StatsBuffer[index].back=i;        // index pour + d'infos
  453.                 //
  454.                 s[0]='\0';
  455.                 strcpybuff(StatsBuffer[index].url_sav,back[i].url_sav);   // pour cancel
  456.                 if (strcmp(back[i].url_adr,"file://"))
  457.                   strcatbuff(s,back[i].url_adr);
  458.                 else
  459.                   strcatbuff(s,"localhost");
  460.                 if (back[i].url_fil[0]!='/')
  461.                   strcatbuff(s,"/");
  462.                 strcatbuff(s,back[i].url_fil);
  463.                 
  464.                 StatsBuffer[index].file[0]='\0';
  465.                 {
  466.                   char* a=strrchr(s,'/');
  467.                   if (a) {
  468.                     strncatbuff(StatsBuffer[index].file,a,200);
  469.                     *a='\0';
  470.                   }
  471.                 }
  472.                 
  473.                 if ((l=strlen(s))<MAX_LEN_INPROGRESS)
  474.                   strcpybuff(StatsBuffer[index].name,s);
  475.                 else {
  476.                   // couper
  477.                   StatsBuffer[index].name[0]='\0';
  478.                   strncatbuff(StatsBuffer[index].name,s,MAX_LEN_INPROGRESS/2-2);
  479.                   strcatbuff(StatsBuffer[index].name,"...");
  480.                   strcatbuff(StatsBuffer[index].name,s+l-MAX_LEN_INPROGRESS/2+2);
  481.                 }
  482.                                
  483.                 if (back[i].r.totalsize>0) {  // taille prΘdΘfinie
  484.                   StatsBuffer[index].sizetot=back[i].r.totalsize;
  485.                   StatsBuffer[index].size=back[i].r.size;
  486.                 } else {  // pas de taille prΘdΘfinie
  487.                   if (back[i].status==0) {  // prΩt
  488.                     StatsBuffer[index].sizetot=back[i].r.size;
  489.                     StatsBuffer[index].size=back[i].r.size;
  490.                   } else {
  491.                     StatsBuffer[index].sizetot=8192;
  492.                     StatsBuffer[index].size=(back[i].r.size % 8192);
  493.                   }
  494.                 }
  495.                 index++;
  496.               }
  497.             }
  498.           }
  499.         }
  500.       }
  501.  
  502.       /* LF */
  503.       printf("%s\n",VT_CLREOL);
  504.  
  505.       /* Display current job */
  506.       {
  507.         int parsing=0;
  508.         printf("Current job: ");
  509.         if (!(parsing=hts_is_parsing(-1)))
  510.           printf("receiving files");
  511.         else {
  512.           switch(hts_is_testing()) {
  513.           case 0:
  514.             printf("parsing HTML file (%d%%)",parsing);
  515.             break;
  516.           case 1:
  517.             printf("parsing HTML file: testing links (%d%%)",parsing);
  518.             break;
  519.           case 2:
  520.             printf("purging files");
  521.             break;
  522.           }
  523.         }
  524.         printf("%s\n",VT_CLREOL);
  525.       }
  526.       
  527.       /* Display background jobs */
  528.       {
  529.         int i;
  530.         for(i=0;i<NStatsBuffer;i++) {
  531.           if (strnotempty(StatsBuffer[i].state)) {
  532.             printf(VT_CLREOL" %s - \t%s%s \t%s / \t%s",
  533.               StatsBuffer[i].state,
  534.               StatsBuffer[i].name,
  535.               StatsBuffer[i].file,
  536.               int2bytes(StatsBuffer[i].size),
  537.               int2bytes(StatsBuffer[i].sizetot)
  538.               );
  539.           }
  540.           printf("%s\n",VT_CLREOL);
  541.         }
  542.       }
  543.  
  544.  
  545.     }
  546.  
  547.   }
  548.  
  549.  
  550.  
  551.   return 1;
  552. }
  553. static char* __cdecl htsshow_query(char* question) {
  554.   static char s[12]=""; /* ok */
  555.   printf("%s\nPress <Y><Enter> to confirm, <N><Enter> to abort\n",question);
  556.   io_flush; linput(stdin,s,4);
  557.   return s;
  558. }
  559. static char* __cdecl htsshow_query2(char* question) {
  560.   static char s[12]=""; /* ok */
  561.   printf("%s\nPress <Y><Enter> to confirm, <N><Enter> to abort\n",question);
  562.   io_flush; linput(stdin,s,4);
  563.   return s;
  564. }
  565. static char* __cdecl htsshow_query3(char* question) {
  566.   static char line[256]; /* ok */
  567.   do {
  568.     io_flush; linput(stdin,line,206);
  569.   } while(!strnotempty(line));
  570.   printf("ok..\n");
  571.   return line;
  572. }
  573. static int __cdecl htsshow_check(char* adr,char* fil,int status) {
  574.   return -1;
  575. }
  576. static void __cdecl htsshow_pause(char* lockfile) {
  577.   while (fexist(lockfile)) {
  578.     Sleep(1000);
  579.   }
  580. }
  581. static void __cdecl htsshow_filesave(char* file) {
  582. }
  583. static int __cdecl htsshow_linkdetected(char* link) {
  584.   return 1;
  585. }
  586. static int __cdecl htsshow_xfrstatus(lien_back* back) {
  587.   return 1;
  588. }
  589. static int __cdecl htsshow_savename(char* adr_complete,char* fil_complete,char* referer_adr,char* referer_fil,char* save) {
  590.   return 1;
  591. }
  592. static int __cdecl htsshow_sendheader(char* buff, char* adr, char* fil, char* referer_adr, char* referer_fil, htsblk* outgoing) {
  593.   return 1;
  594. }
  595. static int __cdecl htsshow_receiveheader(char* buff, char* adr, char* fil, char* referer_adr, char* referer_fil, htsblk* incoming) {
  596.   return 1;
  597. }
  598.  
  599. /* *** Various functions *** */
  600.  
  601.  
  602. static int fexist(char* s) {
  603.   struct stat st;
  604.   memset(&st, 0, sizeof(st));
  605.   if (stat(s, &st) == 0) {
  606.     if (S_ISREG(st.st_mode)) {
  607.       return 1;
  608.     }
  609.   }
  610.   return 0;
  611.  
  612. static int linput(FILE* fp,char* s,int max) {
  613.   int c;
  614.   int j=0;
  615.   do {
  616.     c=fgetc(fp);
  617.     if (c!=EOF) {
  618.       switch(c) {
  619.         case 13: break;  // sauter CR
  620.         case 10: c=-1; break;
  621.         case 9: case 12: break;  // sauter ces caractΦres
  622.         default: s[j++]=(char) c; break;
  623.       }
  624.     }
  625.   }  while((c!=-1) && (c!=EOF) && (j<(max-1)));
  626.   s[j]='\0';
  627.   return j;
  628. }
  629.  
  630. #endif
  631.