12.06.2015 Views

The Annoyance Filter.pdf - Fourmilab

The Annoyance Filter.pdf - Fourmilab

The Annoyance Filter.pdf - Fourmilab

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

§133 ANNOYANCE-FILTER MAIL FOLDER 117<br />

133. Before testing whether the input file is compressed, see if the name we were given is a symbolic<br />

link. If so, follow the link and test the actual file. We only follow links up to 50 levels. We copy the<br />

file name given us to jname , then attempt to interpret it as a symbolic link by calling readlink , which<br />

will fail if the name is not, in fact, a symbolic link. If it is, we obtain the link destination as a C string,<br />

which is copied into jname prior to the test for a compressed file extension.<br />

〈 Check for symbolic link to compressed file 133 〉 ≡<br />

#ifdef HAVE_READLINK<br />

int maxSlinks = 50;<br />

string jname = fname ;<br />

char slbuf [1024];<br />

while (maxSlinks −− > 0) {<br />

int sll = readlink (jname .c str ( ), slbuf , (sizeof slbuf ) − 1);<br />

if (sll ≥ 0) {<br />

assert(sll < static cast〈int〉(sizeof slbuf ));<br />

slbuf [sll ] = 0;<br />

jname = slbuf ;<br />

}<br />

else {<br />

break;<br />

}<br />

}<br />

if (maxSlinks ≤ 0) {<br />

cerr ≪ "Warning:␣probable␣symbolic␣link␣loop␣for␣\"" ≪ fname ≪ "\"" ≪ endl ;<br />

}<br />

#endif<br />

This code is used in sections 129 and 137.<br />

134. If our input file bears an extension which identifies it as a compressed file, we use popen to<br />

create a file handle connected to a pipe to the appropriate decompression program. <strong>The</strong> pipe is then<br />

screwed into the input stream from which we subsequently read.<br />

〈 Open pipe to read compressed file 134 〉 ≡<br />

string cmd (Uncompress command );<br />

cmd += ’␣’ + fname ;<br />

ip = popen (cmd .c str ( ), "r");<br />

#ifdef HAVE_FDSTREAM_COMPATIBILITY<br />

iscc.attach (fileno(ip));<br />

is = &iscc;<br />

#else<br />

isc.attach (fileno(ip));<br />

is = &isc;<br />

#endif<br />

This code is used in section 129.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!