/* $Id: preconv.c,v 1.15 2015/10/06 18:32:19 schwarze Exp $ */
/*
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "config.h"
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include "mandoc.h"
#include "libmandoc.h"
int
int *filenc)
{
unsigned char *cu;
int nby;
unsigned int accum;
if ( ! (*filenc & MPARSE_UTF8))
goto latin;
nby = 1;
nby++;
switch (nby) {
case 2:
goto latin;
break;
case 3:
break;
case 4:
goto latin;
break;
default: /* Bad sequence header. */
goto latin;
}
cu++;
switch (nby) {
case 3:
goto latin;
break;
case 4:
goto latin;
break;
default:
break;
}
while (--nby) {
goto latin;
accum <<= 6;
cu++;
}
*filenc &= ~MPARSE_LATIN1;
return 1;
if ( ! (*filenc & MPARSE_LATIN1))
return 0;
*filenc &= ~MPARSE_UTF8;
return 1;
}
int
{
/* Look for the end-of-line. */
return MPARSE_UTF8 | MPARSE_LATIN1;
/* Move after the header and adjust for the trailer. */
ln += 7;
sz -= 10;
while (sz > 0) {
ln++;
sz--;
}
if (0 == sz)
break;
/* Find the end-of-phrase marker (or eoln). */
else
eoph++;
/* Only account for the "coding" phrase. */
continue;
}
sz -= 7;
ln += 7;
ln++;
sz--;
}
if (0 == sz)
return 0;
/* Check us against known encodings. */
return MPARSE_UTF8;
return MPARSE_LATIN1;
return 0;
}
return MPARSE_UTF8 | MPARSE_LATIN1;
}