File: bom.c

package info (click to toggle)
netcdf-parallel 1%3A4.7.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 105,352 kB
  • sloc: ansic: 229,114; sh: 11,180; yacc: 2,561; makefile: 1,390; lex: 1,173; xml: 173; awk: 2
file content (33 lines) | stat: -rw-r--r-- 1,002 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*********************************************************************
 *   Copyright 2018, UCAR/Unidata
 *   See netcdf/COPYRIGHT file for copying and redistribution conditions.
 *********************************************************************/

#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

/* BOM Sequences */
static char* U8   = "\xEF\xBB\xBF";    /* UTF-8 */
static char* BE32 = "\x00\x00\xFE\xFF"; /* UTF-32; big-endian */
/* static char* LE32 = "\xFF\xFE";       /\* UTF-32; little-endian *\/ */
static char* BE16 = "\xFE\xFF";       /* UTF-16; big-endian */
/* static char* LE16 = "\xFF\xFE";       /\* UTF-16; little-endian *\/ */

int
main(int argc, char** argv)
{
    char* bom = U8;
    size_t bomlen = 3;
    if(argc > 1 && strlen(argv[1]) > 0) {
	char* which = argv[1];
	switch (which[0]) {
	case '1': bom = BE16; bomlen = 2; break;
	case '3': bom = BE32; bomlen = 2; break;
	default: break;
	}
    }
    fwrite(bom,1,bomlen,stdout);
    exit(0);
}