fistgen rot13fs template
[Posted August 4, 2004 by corbet]
%{
/*
* rot13fs: "encrypts" file data using rot13
*/
%}
filter data;
debug on;
// this is a FiST comment, not copied to output files
// rot13fs's smallest encoding/decoding unit is 1 byte (1 is default also)
//encoding_blocksize 1;
// block type encoding is also the default
//encoding_type block;
%%
%%
/*
* rot13 each byte
* return the number of bytes written
*/
int
rot13fs_encode_block(const char *inbuf, char *outbuf, int len, const vnode_t *vp, const vfs_t *vfsp, u_long pagenum)
{
unsigned char *incp = (unsigned char *) inbuf;
unsigned char *outcp = (unsigned char *) outbuf;
unsigned char c;
int i;
for (i = 0; i < len; i++) {
c = *incp & ~0x20; /* uppercase c */
*outcp = *incp;
if (c >= 'A' && c <= 'Z') {
if (c > 'M')
*outcp -= 13;
else
*outcp += 13;
}
incp++;
outcp++;
}
return len;
}
/*
* un-rot13 each byte
* return the number of bytes written
*/
int
rot13fs_decode_block(const char *inbuf, char *outbuf, int len, const vnode_t *vp, const vfs_t *vfsp, u_long pagenum)
{
/* rot13fs decode and encode are identical */
return rot13fs_encode_block(inbuf, outbuf, len, vp, vfsp, pagenum);
}
/*
* Local variables:
* c-basic-offset: 4
* End:
*/