snarf-basename-patch.diff 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. diff -ruN snarf-7.0.orig/http.c snarf-7.0/http.c
  2. --- snarf-7.0.orig/http.c 2000-08-09 01:33:30.000000000 +0100
  3. +++ snarf-7.0/http.c 2003-07-28 12:19:08.000000000 +0100
  4. @@ -14,8 +14,6 @@
  5. #include "util.h"
  6. #include "llist.h"
  7. -extern int default_opts;
  8. -
  9. int redirect_count = 0;
  10. #define REDIRECT_MAX 10
  11. diff -ruN snarf-7.0.orig/options.c snarf-7.0/options.c
  12. --- snarf-7.0.orig/options.c 1999-07-27 20:42:51.000000000 +0100
  13. +++ snarf-7.0/options.c 2003-07-28 11:59:05.000000000 +0100
  14. @@ -8,8 +8,8 @@
  15. int default_opts;
  16. extern int debug_enabled;
  17. -unsigned char
  18. -set_options(unsigned char opts, char *optstring)
  19. +unsigned int
  20. +set_options(unsigned int opts, char *optstring)
  21. {
  22. int i;
  23. @@ -78,6 +78,15 @@
  24. case 'd':
  25. debug_enabled = !debug_enabled;
  26. break;
  27. +
  28. + case 'b':
  29. + opts |= OPT_BASENAME;
  30. + break;
  31. +
  32. + case 'B':
  33. + default_opts |= OPT_BASENAME;
  34. + break;
  35. +
  36. default:
  37. report(WARN, "unknown option `%c', ignoring", optstring[i]);
  38. }
  39. diff -ruN snarf-7.0.orig/options.h snarf-7.0/options.h
  40. --- snarf-7.0.orig/options.h 1999-07-27 20:42:51.000000000 +0100
  41. +++ snarf-7.0/options.h 2003-07-28 12:20:47.000000000 +0100
  42. @@ -12,12 +12,13 @@
  43. #define OPT_PROGRESS (1 << 5) /* for python aka markus fleck */
  44. #define OPT_BE_MOZILLA (1 << 6) /* To act like Mozilla */
  45. #define OPT_BE_MSIE (1 << 7) /* To act like MSIE */
  46. +#define OPT_BASENAME (1 << 8) /* Only show basename() of output */
  47. /* Funcs */
  48. #ifdef PROTOTYPES
  49. -unsigned char set_options(unsigned char, char *);
  50. +unsigned int set_options(unsigned int, char *);
  51. #endif /* PROTOTYPES */
  52. diff -ruN snarf-7.0.orig/snarf.1 snarf-7.0/snarf.1
  53. --- snarf-7.0.orig/snarf.1 2000-01-17 14:26:13.000000000 +0000
  54. +++ snarf-7.0/snarf.1 2003-07-28 12:45:26.000000000 +0100
  55. @@ -90,6 +90,9 @@
  56. .I "\-m"
  57. Send a user-agent string similar to what Microsoft Internet Explorer
  58. uses.
  59. +.TP
  60. +.I "\-b"
  61. +Only print the basename of output file with the progress bars.
  62. .PP
  63. Each option only affects the URL that immediately follows it. To have
  64. an option affect all URLs that follow it, use an uppercase letter for
  65. diff -ruN snarf-7.0.orig/snarf.c snarf-7.0/snarf.c
  66. --- snarf-7.0.orig/snarf.c 2000-08-09 01:34:45.000000000 +0100
  67. +++ snarf-7.0/snarf.c 2003-07-28 12:43:29.000000000 +0100
  68. @@ -50,6 +50,7 @@
  69. " -n Ignore '-r' and transfer file in its entirety\n"
  70. " -m Spoof MSIE user-agent string\n"
  71. " -z Spoof Navigator user-agent string\n"
  72. + " -b Only print basename of output file\n"
  73. "\n"
  74. "Lowercase option letters only affect the URLs that "
  75. "immediately follow them.\n"
  76. diff -ruN snarf-7.0.orig/url.h snarf-7.0/url.h
  77. --- snarf-7.0.orig/url.h 1999-07-27 20:42:51.000000000 +0100
  78. +++ snarf-7.0/url.h 2003-07-28 12:00:03.000000000 +0100
  79. @@ -28,7 +28,7 @@
  80. char *proxy;
  81. char *proxy_username;
  82. char *proxy_password;
  83. - unsigned char options;
  84. + unsigned int options;
  85. off_t outfile_size;
  86. off_t outfile_offset;
  87. };
  88. diff -ruN snarf-7.0.orig/util.c snarf-7.0/util.c
  89. --- snarf-7.0.orig/util.c 2000-08-09 01:12:39.000000000 +0100
  90. +++ snarf-7.0/util.c 2003-07-28 13:29:46.000000000 +0100
  91. @@ -32,6 +32,7 @@
  92. #include <ctype.h>
  93. #include <errno.h>
  94. #include <time.h>
  95. +#include <libgen.h>
  96. #include "url.h"
  97. #include "options.h"
  98. @@ -292,6 +293,10 @@
  99. filename = strdup(rsrc->outfile);
  100. + if( rsrc->options & OPT_BASENAME ){
  101. + filename = basename(filename);
  102. + }
  103. +
  104. if( strlen(filename) > 24 )
  105. filename[24] = '\0';
  106. @@ -312,6 +317,7 @@
  107. progress_update(Progress * p,
  108. long int increment)
  109. {
  110. + char *filename = NULL;
  111. unsigned int units;
  112. char *anim = "-\\|/";
  113. @@ -320,12 +326,16 @@
  114. p->current += increment;
  115. - if (strlen(p->rsrc->outfile) > 24) {
  116. - p->rsrc->outfile[24] = '\0';
  117. - }
  118. + if( p->rsrc->options & OPT_BASENAME ){
  119. + filename = basename(strdup(p->rsrc->outfile));
  120. + } else
  121. + filename = strdup(p->rsrc->outfile);
  122. + if (strlen(filename) > 24)
  123. + filename[24] = '\0';
  124. +
  125. fprintf(stderr, "\r");
  126. - fprintf(stderr, "%-25s [", p->rsrc->outfile);
  127. + fprintf(stderr, "%-25s [", filename);
  128. if( p->length ) {