r93212 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93211‎ | r93212 | r93213 >
Date:17:09, 26 July 2011
Author:platonides
Status:ok
Tags:
Comment:
Send errors by stderr, not in stdour intermingled with the output. Hopefully stderr will go to a sane place.
I assume that in case of no match we want to send the url as-is?
Skip all the processing code in case of errors by continuing the while (instead of relying on 'rc < 0 and path is initialised to the empty string).
Typo in r93199 comment. Spacing.
Modified paths:
  • /trunk/debs/squid/redirector.c (modified) (history)

Diff [purge]

Index: trunk/debs/squid/redirector.c
@@ -2,15 +2,15 @@
33 *
44 * Squid Redirect Helper - reads from stdin, outputs 302 to $1.m.wikipedia.org/$2
55 * if original matches "^http:\\/\\/(\\w+)\\.wikipedia\\.org[:\\d]*\\/(.*)"
6 - * A new base url in place of m.wikiedpia.org may be provided as the only argument.
 6+ * A new base url in place of m.wikipedia.org may be provided as the only argument.
77 *
88 * To compile: gcc -O3 -o redirector -lpcre redirector.c
99 *
1010 */
1111
1212 #include <stdio.h>
13 -#include<stdlib.h>
14 -#include<string.h>
 13+#include <stdlib.h>
 14+#include <string.h>
1515 #include <pcre.h>
1616
1717 #define MAX_BUFF 8256
@@ -108,13 +108,20 @@
109109
110110 if (rc < 0) {
111111 switch(rc) {
112 - case PCRE_ERROR_NOMATCH: printf("%s\n", in_buff->url); break;
113 - default: printf("Matching error %d\n", rc); break;
 112+ case PCRE_ERROR_NOMATCH:
 113+ printf("%s\n", in_buff->url);
 114+ fflush(stdout);
 115+
 116+ break;
 117+ default:
 118+ fprintf(stderr, "Matching error %d\n", rc);
 119+ break;
114120 }
 121+ continue;
115122 }
116123
117124 char lang[20] = "";
118 - char path[MAX_BUFF] = "";
 125+ char path[MAX_BUFF] = "";
119126
120127 for (i = 0; i < rc; i++) {
121128

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r93199commentasher16:11, 26 July 2011

Status & tagging log