bomstrip-9004070000017500001750000000000001103025624400111615ustar00mjlmjlbomstrip-9/correct004070000017500001750000000000001075411723100126265ustar00mjlmjlbomstrip-9/correct/rnobom2010060000017500001750000000000051075411723100142000ustar00mjlmjl1234 bomstrip-9/correct/rnobom1010060000017500001750000000000021075411723100141740ustar00mjlmjl1 bomstrip-9/correct/rnobom0010060000017500001750000000000001075411723100141710ustar00mjlmjlbomstrip-9/correct/rbom1010060000017500001750000000000051075411723100136420ustar00mjlmjlbliebbomstrip-9/correct/rbom0010060000017500001750000000000001075411723100136340ustar00mjlmjlbomstrip-9/bomstrip.py010075000017500001750000000012461103025136300134560ustar00mjlmjl#!/usr/bin/env python2.3 """ Strip leading byte-order-mark from utf-8 files. """ import sys def usage(prog): print >>sys.stderr, 'usage: %s' % prog sys.exit(1) def main(prog, *args): bufsize = 65536 utf8bom = '\xef\xbb\xbf' from getopt import getopt, GetoptError try: opts, args = getopt(args, '') except GetoptError: usage(prog) if args: usage(prog) inf = sys.stdin outf = sys.stdout buf = inf.read(len(utf8bom)) if buf != utf8bom: outf.write(buf) if buf == '': return while True: buf = inf.read(bufsize) if buf == '': break outf.write(buf) if __name__ == '__main__': try: main(*sys.argv) except KeyboardInterrupt: sys.exit(1) bomstrip-9/nobom1010060000017500001750000000000021075411723100123510ustar00mjlmjl1 bomstrip-9/nobom2010060000017500001750000000000051075411723100123550ustar00mjlmjl1234 bomstrip-9/nobom0010060000017500001750000000000001075411723100123460ustar00mjlmjlbomstrip-9/bom0010060000017500001750000000000031075411723100120140ustar00mjlmjlbomstrip-9/bomstrip.c010075000017500001750000000011301103025274100132410ustar00mjlmjl#include #include #include #include void usage(char *prog) { fprintf(stderr, "usage: %s\n", prog); exit(1); } int main(int argc, char *argv[]) { size_t nread; char buf[65536]; char *utf8bom = "\xef\xbb\xbf"; if (argc > 1) usage(argv[0]); nread = fread(buf, 1, strlen(utf8bom), stdin); if (nread == 0) return 0; if (strcmp(buf, utf8bom) != 0) fwrite(buf, 1, nread, stdout); for (;;) { nread = fread(buf, 1, sizeof buf, stdin); if (nread < 0) exit(1); if (nread == 0) return 0; fwrite(buf, 1, nread, stdout); } return 0; } bomstrip-9/bomstrip.bf010075000017500001750000000007151075411723100134240ustar00mjlmjl,+[-[>>+<+<-]>>>>>>+++++[<++++>-]<[<++++>-]<[<+++>-]<-[<->-]+<[>-> >>++++[<++++[<++++[<++++[<+>-]>-]>-]>-]<<<<[-]]>[-,+[-[>>+<+<-]>>> >>>+++++++[<+++>-]<[<+++>-]<[<+++>-]<--[<->-]+<[>->>>++++[<++++[<+ +++[<++++[<+>-]>-]>-]>-]<<<<[-]]>[-,+[-[>>+<+<-]>>>>>>+++++++[<+++ >-]<[<+++>-]<[<+++>-]<++[<->-]+<[>->>>++++[<++++[<++++[<++++[<+>-] >-]>-]>-]<<<<[-]]>[-<<[-]<<<[-]<<<[-]>>>>>>>>]<<<]]<<<]]<<<]>[.>]> >[.>]>>[.>],+[-.,+] Berteun Damman; 2005; Public Domain; bomstrip-9/bomstrip.sed010075000017500001750000000012411075411723100136030ustar00mjlmjl# this only works with some seds. # lines without newline should get a newline after outputting. # (strange, but that's how sed is supposed to work). # actually, it seems sed input "should" always have a newline at # the end of a file. # it is know to work with: # - sed on openbsd 3.7 # - sed on debian (probably gnu sed) # it is know to not work with: # - sun os (ignores "trailing text without newline" all together) # - mac os and plan 9 (their sed print newlines after every "line" # of input, even when it does not have a newline). since mac os # sed seems to come from freebsd, it is expected that freebsd sed # also does not work. # too bad... 1s/^// bomstrip-9/bomstrip.pl010075000017500001750000000001711103025136300134350ustar00mjlmjl#!/usr/bin/perl my $buf; if (read STDIN, $buf, 3) { print $buf if $buf ne "\xef\xbb\xbf"; undef $/; print ; } bomstrip-9/test.sh010070000017500001750000000004301103025374600125540ustar00mjlmjl#!/bin/sh test -z "$BOM" && BOM='ocaml ./bomstrip.ocaml' test -z "$BOMFILES" && BOMFILES='bom0 bom1 nobom0 nobom1 nobom2' res=0 for f in $BOMFILES; do $BOM < "$f" > "r$f" if ! cmp "r$f" correct/"r$f"; then echo "$f is wrong" res=1 else rm -f "r$f" fi done exit "$res" bomstrip-9/bomstrip.ook010075000017500001750000000101611075411723100136210ustar00mjlmjlOok. Ook! Ook. Ook. Ook! Ook? Ook! Ook! Ook! Ook? Ook. Ook? Ook. Ook? Ook. Ook. Ook? Ook. Ook. Ook. Ook? Ook. Ook! Ook! Ook? Ook! Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook? Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook! Ook! Ook? Ook! Ook? Ook. Ook! Ook? Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook! Ook! Ook? Ook! Ook? Ook. Ook! Ook? Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook! Ook! Ook? Ook! Ook? Ook. Ook! Ook! Ook! Ook? Ook? Ook. Ook! Ook! Ook. Ook? Ook! Ook! Ook? Ook! Ook. Ook. Ook? Ook. Ook! Ook? Ook. Ook? Ook! Ook! Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook? Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook? Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook? Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook? Ook? Ook. Ook. Ook. Ook. Ook? Ook! Ook! Ook? Ook! Ook. Ook? Ook! Ook! Ook? Ook! Ook. Ook? Ook! Ook! Ook? Ook! Ook. Ook? Ook! Ook! Ook? Ook! Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook! Ook? Ook! Ook! Ook? Ook! Ook? Ook! Ook. Ook? Ook! Ook? Ook! Ook! Ook. Ook! Ook. Ook. Ook! Ook? Ook! Ook! Ook! Ook? Ook. Ook? Ook. Ook? Ook. Ook. Ook? Ook. Ook. Ook. Ook? Ook. Ook! Ook! Ook? Ook! Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook? Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook! Ook! Ook? Ook! Ook? Ook. Ook! Ook? Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook! Ook! Ook? Ook! Ook? Ook. Ook! Ook? Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook! Ook! Ook? Ook! Ook? Ook. Ook! Ook! Ook! Ook! Ook! Ook? Ook? Ook. Ook! Ook! Ook. Ook? Ook! Ook! Ook? Ook! Ook. Ook. Ook? Ook. Ook! Ook? Ook. Ook? Ook! Ook! Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook? Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook? Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook? Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook? Ook? Ook. Ook. Ook. Ook. Ook? Ook! Ook! Ook? Ook! Ook. Ook? Ook! Ook! Ook? Ook! Ook. Ook? Ook! Ook! Ook? Ook! Ook. Ook? Ook! Ook! Ook? Ook! Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook! Ook? Ook! Ook! Ook? Ook! Ook? Ook! Ook. Ook? Ook! Ook? Ook! Ook! Ook. Ook! Ook. Ook. Ook! Ook? Ook! Ook! Ook! Ook? Ook. Ook? Ook. Ook? Ook. Ook. Ook? Ook. Ook. Ook. Ook? Ook. Ook! Ook! Ook? Ook! Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook? Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook! Ook! Ook? Ook! Ook? Ook. Ook! Ook? Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook! Ook! Ook? Ook! Ook? Ook. Ook! Ook? Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook! Ook! Ook? Ook! Ook? Ook. Ook. Ook. Ook. Ook. Ook! Ook? Ook? Ook. Ook! Ook! Ook. Ook? Ook! Ook! Ook? Ook! Ook. Ook. Ook? Ook. Ook! Ook? Ook. Ook? Ook! Ook! Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook? Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook? Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook? Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook? Ook? Ook. Ook. Ook. Ook. Ook? Ook! Ook! Ook? Ook! Ook. Ook? Ook! Ook! Ook? Ook! Ook. Ook? Ook! Ook! Ook? Ook! Ook. Ook? Ook! Ook! Ook? Ook! Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook! Ook? Ook! Ook! Ook? Ook! Ook? Ook! Ook. Ook? Ook! Ook? Ook! Ook! Ook? Ook. Ook? Ook. Ook! Ook? Ook! Ook! Ook? Ook! Ook? Ook. Ook? Ook. Ook? Ook. Ook! Ook? Ook! Ook! Ook? Ook! Ook? Ook. Ook? Ook. Ook? Ook. Ook! Ook? Ook! Ook! Ook? Ook! Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook? Ook! Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook! Ook? Ook! Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook! Ook? Ook! Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook! Ook. Ook? Ook! Ook? Ook! Ook. Ook. Ook? Ook? Ook! Ook. Ook? Ook. Ook? Ook! Ook? Ook! Ook. Ook. Ook? Ook? Ook! Ook. Ook? Ook. Ook? Ook! Ook? Ook! Ook. Ook. Ook? Ook? Ook! Ook. Ook! Ook. Ook. Ook! Ook? Ook! Ook! Ook! Ook. Ook. Ook! Ook. Ook. Ook? Ook! bomstrip-9/bomstrip_expl.bf010075000017500001750000000050311075411723100144500ustar00mjlmjlBerteun Damman; 2005; Public Domain; Read the first three bytes; the BOM marker (if it's there) The marker; in case it's there it is 0xEF 0xBB 0xBF (239 187 191) Read a byte of input; if it's minus 1 we treat it as an EOF ,+ [ - So it's not an EOF and we make two copies of it [>>+<+<-]>> And we put our constant after it; as the number 239 itself is a prime we use 240 which factorizes nicely as 2^4 * 3 * 5 and substract one from it >>>>+++++[<++++>-]<[<++++>-]<[<+++>-]<- While our constant is not zero we substract one from it and also from the input byte [<->-] Now change our constant to 1 (our flag) + Check whether the input byte is zero; if so we have a match < [ It was non zero we go to our flag and turn it back to zero >->>>++++ As the input byte might be negative (or wrapped! but in that case this won't hurt) we're going to add 256 which will make it positive for sure [<++++[<++++[<++++[<+>-]>-]>-]>-] <<<< [-] ] > [ - If we get here the flag was non zero We now basically do the same but for the second byte ,+ [ - So it's not an EOF and we make two copies of it [>>+<+<-]>> And we put our constant again next to it; We first calculate 189; which is 3^3 * 7 and substract 2 >>>>+++++++[<+++>-]<[<+++>-]<[<+++>-]<-- The number 0xBB While our constant is not zero we substract one from it and also from the input byte [<->-] Now change our constant to 1 (our flag) + Check whether the input byte is zero; if so we have a match < [ It was non zero we go to our flag and turn it back to zero and add in case of negative >->>>++++ [<++++[<++++[<++++[<+>-]>-]>-]>-] <<<< [-] ] > [ - ,+ [ - And the whole story again [>>+<+<-]>> >>>>+++++++[<+++>-]<[<+++>-]<[<+++>-]<++ The number 0xBB [<->-] + < [ >->>>++++ [<++++[<++++[<++++[<+>-]>-]>-]>-] <<<< [-] ] > [ - Evil Bom Found: clear the inputs <<[-]<<<[-]<<<[-] >>>>>>>> ] Third byte test failed! <<< ] End of file at third byte ] Second byte test failed <<< ] End of file at second byte ] First byte test failed <<< ] End of file at first byte If we broke out of the loops somewhere that means that we have to print the inputs on the tape; we do this by going from left to right and at the positions where the input should be we print it if it is non zero When the BOM is found the whole tape has been made blank and we do not print anything >[.>]>>[.>]>>[.>] Print the remainder ,+[-.,+] bomstrip-9/bom1010060000017500001750000000000101075411723100120130ustar00mjlmjlbliebbomstrip-9/BomStrip.java010060000017500001750000000017561075411723100136560ustar00mjlmjlpublic class BomStrip { private static final int BUFFER_LENGTH = 65536; private static final int EOF = -1; private static final byte UTF8_BOM_1 = (byte) 0xef; private static final byte UTF8_BOM_2 = (byte) 0xbb; private static final byte UTF8_BOM_3 = (byte) 0xbf; public static void main(String[] args) { final byte[] utf8Bom = {UTF8_BOM_1, UTF8_BOM_2, UTF8_BOM_3}; byte[] buffer = new byte[BUFFER_LENGTH]; byte[] bomBuffer = new byte[utf8Bom.length]; try { int nRead = System.in.read(bomBuffer, 0, bomBuffer.length); if (nRead != EOF) { if (!java.util.Arrays.equals(bomBuffer, utf8Bom)) { System.out.write(bomBuffer, 0, nRead); } boolean eof = false; while (!eof) { nRead = System.in.read(buffer, 0, buffer.length); eof = nRead == EOF; if (!eof) { System.out.write(buffer, 0, nRead); } } } } catch (java.io.IOException e) { System.err.println("I/O error occurred: " + e.getMessage()); System.exit(1); } } } bomstrip-9/bomstrip.ps010075000017500001750000000015101075411723100134510ustar00mjlmjl%!PS-Adobe-2.0 %%Title: Bomstrip %%Author: Berteun Damman % Run with something like: gs -q -sDEVICE=nullpage bomstrip.ps % Public Domain, 2005 % Definitions /inc { % Stack: Number 1 add } def % No graphics output nulldevice (%stdin) (r) file /input exch def (%stdout) (w) file /output exch def 0 % Number of bytes read 3 { input read { exch inc } { exit } ifelse } repeat dup % Did we read less than three bytes? 2 le { dup 1 ge { % Swap if needed dup inc -1 roll exch { output exch write } repeat } if quit } if % We read at least three bytes, copy them for comparison copy 16#BF 4 2 roll 16#BB 5 2 roll 16#EF 6 2 roll true 3 { 3 1 roll eq and } repeat not { % Reverse the order exch 3 -1 roll 3 { output exch write } repeat } if % Final output loop { input read not { quit } if output exch write } loop bomstrip-9/bomstrip.pas010075000017500001750000000022561075411723100136220ustar00mjlmjlProgram Bomstrip; (* Berteun Damman, 2005, Public Domain * Compiles with FreePascal and GNU Pasal (at least) and * besides that also seems to work.... *) Type BOMT = Array[1..3] of Byte; Const UTF8BOM: BOMT = ($EF, $BB, $BF); Var C: Char; F: Boolean; I, J: Integer; BOM: BOMT; Begin (* Try to read 3 Bytes, if an EOF happens before, gracefully exit, and print the first one or two bytes. *) I := 0; While Not EOF And Not EOLn And (I <= 2) Do Begin Inc(I); Read(C); BOM[I] := Ord(C); End; (* Assume we have a BOM if the input has length 3 *) F := (I = 3); For J := 1 To I Do If BOM[J] <> UTF8BOM[J] Then F := False; (* Not a BOM, print it. *) If Not F Then For J := 1 To I Do Write(Chr(BOM[J])); (* If EOF, then Exit *) If EOF Then Exit; (* Print the remainder. *) While Not EOF Do Begin If EOLn Then Begin (* Actually GPC reads an EOLn as a space. I * do not know whether that is correct (FPC does not) * but this works either way. * Perhaps we do run into some implicit CR/LF <-> LF * conversion. * TODO Test this! *) WriteLn; Read(C); End Else Begin Read(C); Write(C); End; End; End. bomstrip-9/bomstrip.unl010075000017500001750000000021451075411723100136320ustar00mjlmjl# BOM strip implementation in Unlambda # # Author: Matthijs Bomhoff # # This implementation is mainly constructed by composing pieces from # http://www.madore.org/~david/programs/unlambda/ # # Maybe, if this was not the first program I ever wrote in Unlambda, # it would have been nicer ;) ` ` ` ` ` #IF ``s`kc``s`k`s`k`k`ki``ss`k`kk # # Read a char and compare it to the first pattern byte ``@?ïi # THEN `d``` #IF ``s`kc``s`k`s`k`k`ki``ss`k`kk # # Read a char and compare it to the second pattern byte ``@?»i # THEN `d``` #IF ``s`kc``s`k`s`k`k`ki``ss`k`kk # # Read a char and compare it to the third pattern byte ``@?¿i # THEN i # ELSE # Mismatch, print first two bytes of pattern, followed by last byte read `d`|`.ï.» #END IF # ELSE # Mismatch, print first byte of pattern, followed by last byte read `d`|.ï #END IF # ELSE # Mismatch, print last byte read `d`|i # END IF # COPY FILE `d ```s``sii`ki ``s``s`ks``s``s`ks``s`k`s`ki``s`k`si``s`kd``s`kk `d`@i k`k `d`|i i # Dummy function, needed as ``input'' bomstrip-9/bomstrip.b010075000017500001750000000014501075411723100132530ustar00mjlmjlimplement Bomstrip; include "sys.m"; include "draw.m"; Bomstrip: module { init: fn(ctxt: ref Draw->Context, argv: list of string); }; init(nil: ref Draw->Context, nil: list of string) { sys := load Sys Sys->PATH; buf := array[sys->ATOMICIO] of byte; utf8bom := array[3] of {byte 16rEF, byte 16rBB, byte 16rBF}; stdin := sys->fildes(0); stdout := sys->fildes(1); n := sys->read(stdin, buf, len buf); if(n < 0) raise "fail:read"; if(n == 0) return; m := 3; if(n < m) m = n; if(m != 3 || buf[0] != utf8bom[0] || buf[1] != utf8bom[1] || buf[2] != utf8bom[2]) sys->write(stdout, buf[0:3], m); if(n > 3) sys->write(stdout, buf[3:n], n-3); for(;;) { n = sys->read(stdin, buf, len buf); if(n < 0) raise "fail:read"; if(n == 0) break; sys->write(stdout, buf, n); } } bomstrip-9/bomstrip.hs010075000017500001750000000003341075411723100134440ustar00mjlmjl-- by mechiel lukkien, 18 september 2005, public domain putStrNoBOM :: String -> IO () putStrNoBOM ('\xef':'\xbb':'\xbf':s) = putStr s putStrNoBOM s = putStr s main :: IO () main = do s <- getContents putStrNoBOM s bomstrip-9/bomstrip.ocaml010075000017500001750000000004611075411723100141260ustar00mjlmjl(* by mechiel lukkien, 18 september 2005, public domain *) let buf = String.create 3 in let n = input stdin buf 0 3 in match (n, buf) with (3, "\xef\xbb\xbf") -> () | (n, buf) -> output stdout buf 0 n ;; try while true do output_char stdout (input_char stdin) done with End_of_file -> () ;; bomstrip-9/bomstrip.php010075000017500001750000000004221075411725000136200ustar00mjlmjl#!/usr/bin/env php bomstrip-9/bomstrip.rb010075000017500001750000000002411075412030100134220ustar00mjlmjl#!/usr/bin/env ruby if !(buf = STDIN.read(3)).nil? && buf != "\xef\xbb\xbf" STDOUT.write(buf) end while !(buf = STDIN.read(8*1024)).nil? STDOUT.write(buf) end bomstrip-9/bomstrip.fs010075000017500001750000000026021103025473100134350ustar00mjlmjl\ by Peter Pentchev, 2008, public domain. \ \ This works with GNU Forth. It really ought to work with other \ Forths, too - as long as they have the STDIN and STDOUT words, \ which at least FICL seems to be missing. \ The buffer where the input is read - 8KB should be enough for everyone ;) CREATE STRIP-BUF 8192 CHARS ALLOT \ The UTF-8 BOM to compare to CREATE UTF-8-BOM 239 C, 187 C, 191 C, \ Read three bytes, skip them if it is the BOM, output them otherwise : STRIP-FIRST ( -- ) ( read three bytes ) STRIP-BUF 3 STDIN READ-FILE IF EXIT THEN ( less than three bytes read? ) DUP 3 < IF ( yep, just write them to stdout ) STRIP-BUF SWAP STDOUT WRITE-FILE IF BYE THEN ELSE ( are they the same as the three bytes in the UTF-8-BOM? ) STRIP-BUF SWAP 2DUP UTF-8-BOM 3 COMPARE IF ( nope, must copy them, write them to stdout ) STDOUT WRITE-FILE IF BYE THEN THEN THEN ; \ Read as much as we can from stdin and copy it to stdout, in 8192-byte blocks : STRIP-REST ( -- ) ( read up to 8KB ) STRIP-BUF 8192 STDIN READ-FILE IF BYE THEN ( just return on EOF ) DUP 0= IF EXIT THEN ( copy to stdout ) STRIP-BUF SWAP STDOUT WRITE-FILE IF BYE THEN ( actually equivalent to a forever loop :) RECURSE ; \ First examine the first three bytes, then copy the rest : BOMSTRIP ( -- ) STRIP-FIRST STRIP-REST ; \ This is a bomstrip filter - run BOMSTRIP, then exit the interpreter BOMSTRIP BYE bomstrip-9/bomstrip2.pl010075000017500001750000000001341103025311700135150ustar00mjlmjl#!/usr/bin/perl -wp # by Peter Pentchev, 2008, public domain. $. == 1 && s/^\xef\xbb\xbf//; bomstrip-9/bomstrip.awk010075000017500001750000000003451103025617300136130ustar00mjlmjl#!/usr/bin/awk -f # by Peter Pentchev, 2008, public domain. # does not work on the one true awk, does work on the gnu clone. but still then fails if file does not end in newline. NR == 1 && /^/ { sub("^...", "") } { print } bomstrip-9/bomstrip.cpp010075000017500001750000000012771103025470200136140ustar00mjlmjl/* by Peter Pentchev, 2008, public domain. */ #include #include #include using namespace std; const char *utf8bom = "\xef\xbb\xbf"; static void usage(const char *); static void outendl(string &); static void usage(const char *prog) { cerr << "usage: " << prog << endl; exit(1); } static void outendl(string &s) { cout << s; if (!cin.eof()) cout << endl; } int main(int argc, const char * const argv[]) { string s; if (argc > 1) usage(argv[0]); /* Empty? */ if (!getline(cin, s)) return 0; /* First line... */ if (!s.substr(0, 3).compare(utf8bom)) s = s.substr(3); outendl(s); /* ...and the rest. */ while (getline(cin, s)) outendl(s); }