诸暨麻将添加redis
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

151 satır
4.3 KiB

  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. *
  10. * This software is licensed as described in the file COPYING, which
  11. * you should have received as part of this distribution. The terms
  12. * are also available at http://curl.haxx.se/docs/copyright.html.
  13. *
  14. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. * copies of the Software, and permit persons to whom the Software is
  16. * furnished to do so, under the terms of the COPYING file.
  17. *
  18. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. * KIND, either express or implied.
  20. *
  21. ***************************************************************************/
  22. #include "tool_setup.h"
  23. #define ENABLE_CURLX_PRINTF
  24. /* use our own printf() functions */
  25. #include "curlx.h"
  26. #include "tool_cfgable.h"
  27. #include "tool_cb_prg.h"
  28. #include "tool_util.h"
  29. #include "memdebug.h" /* keep this as LAST include */
  30. /*
  31. ** callback for CURLOPT_PROGRESSFUNCTION
  32. */
  33. #define MAX_BARLENGTH 256
  34. int tool_progress_cb(void *clientp,
  35. double dltotal, double dlnow,
  36. double ultotal, double ulnow)
  37. {
  38. /* The original progress-bar source code was written for curl by Lars Aas,
  39. and this new edition inherits some of his concepts. */
  40. char line[MAX_BARLENGTH+1];
  41. char format[40];
  42. double frac;
  43. double percent;
  44. int barwidth;
  45. int num;
  46. struct timeval now = tvnow();
  47. struct ProgressData *bar = (struct ProgressData *)clientp;
  48. curl_off_t total;
  49. curl_off_t point;
  50. if(bar->calls && (tvdiff(now, bar->prevtime) < 200L))
  51. /* after first call, limit progress-bar updating to 5 Hz */
  52. return 0;
  53. /* expected transfer size */
  54. total = (curl_off_t)dltotal + (curl_off_t)ultotal + bar->initial_size;
  55. /* we've come this far */
  56. point = (curl_off_t)dlnow + (curl_off_t)ulnow + bar->initial_size;
  57. if(point > total)
  58. /* we have got more than the expected total! */
  59. total = point;
  60. /* simply count invokes */
  61. bar->calls++;
  62. if(total < 1) {
  63. curl_off_t prevblock = bar->prev / 1024;
  64. curl_off_t thisblock = point / 1024;
  65. while(thisblock > prevblock) {
  66. fprintf(bar->out, "#");
  67. prevblock++;
  68. }
  69. }
  70. else if(point != bar->prev) {
  71. frac = (double)point / (double)total;
  72. percent = frac * 100.0f;
  73. barwidth = bar->width - 7;
  74. num = (int) (((double)barwidth) * frac);
  75. if(num > MAX_BARLENGTH)
  76. num = MAX_BARLENGTH;
  77. memset(line, '#', num);
  78. line[num] = '\0';
  79. snprintf(format, sizeof(format), "\r%%-%ds %%5.1f%%%%", barwidth);
  80. fprintf(bar->out, format, line, percent);
  81. }
  82. fflush(bar->out);
  83. bar->prev = point;
  84. bar->prevtime = now;
  85. return 0;
  86. }
  87. void progressbarinit(struct ProgressData *bar,
  88. struct Configurable *config)
  89. {
  90. #ifdef __EMX__
  91. /* 20000318 mgs */
  92. int scr_size[2];
  93. #endif
  94. char *colp;
  95. memset(bar, 0, sizeof(struct ProgressData));
  96. /* pass this through to progress function so
  97. * it can display progress towards total file
  98. * not just the part that's left. (21-may-03, dbyron) */
  99. if(config->use_resume)
  100. bar->initial_size = config->resume_from;
  101. /* TODO: get terminal width through ansi escapes or something similar.
  102. try to update width when xterm is resized... - 19990617 larsa */
  103. #ifndef __EMX__
  104. /* 20000318 mgs
  105. * OS/2 users most likely won't have this env var set, and besides that
  106. * we're using our own way to determine screen width */
  107. colp = curlx_getenv("COLUMNS");
  108. if(colp) {
  109. char *endptr;
  110. long num = strtol(colp, &endptr, 10);
  111. if((endptr != colp) && (endptr == colp + strlen(colp)) && (num > 0))
  112. bar->width = (int)num;
  113. else
  114. bar->width = 79;
  115. curl_free(colp);
  116. }
  117. else
  118. bar->width = 79;
  119. #else
  120. /* 20000318 mgs
  121. * We use this emx library call to get the screen width, and subtract
  122. * one from what we got in order to avoid a problem with the cursor
  123. * advancing to the next line if we print a string that is as long as
  124. * the screen is wide. */
  125. _scrsize(scr_size);
  126. bar->width = scr_size[0] - 1;
  127. #endif
  128. bar->out = config->errors;
  129. }