w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

escapesrc.cpp File Reference
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <iostream>
#include <fstream>
#include "unicode/utf8.h"
#include "cptbl.h"
Include dependency graph for escapesrc.cpp:

Go to the source code of this file.

Macros

#define cp1047_to_8859(c)   cp1047_8859_1[c]
 

Functions

void usage ()
 
int cleanup (const std::string &outfile)
 
const char * skipws (const char *p, const char *e)
 
void appendByte (std::string &outstr, uint8_t byte)
 
Bool__ appendUtf8 (std::string &outstr, const std::string &linestr, size_t &pos, size_t chars)
 
Bool__ fixu8 (std::string &linestr, size_t origpos, size_t &endpos)
 
Bool__ fixAt (std::string &linestr, size_t pos)
 
Bool__ fixLine (int, std::string &linestr)
 
int convert (const std::string &infile, const std::string &outfile)
 
int main (int argc, const char *argv[])
 

Variables

static const char kSPACE = 0x20
 
static const char kTAB = 0x09
 
static const char kLF = 0x0A
 
static const char kCR = 0x0D
 
std::string prog
 

Macro Definition Documentation

◆ cp1047_to_8859

#define cp1047_to_8859 (   c)    cp1047_8859_1[c]

Definition at line 52 of file escapesrc.cpp.

Function Documentation

◆ appendByte()

void appendByte ( std::string outstr,
uint8_t  byte 
)

Append a byte, hex encoded

Parameters
outstrsstring to append to
bytethe byte to append

Definition at line 113 of file escapesrc.cpp.

References sprintf.

Referenced by appendUtf8(), and fixu8().

◆ appendUtf8()

Bool__ appendUtf8 ( std::string outstr,
const std::string linestr,
size_t pos,
size_t  chars 
)

Append the bytes from 'linestr' into outstr, with escaping

Parameters
outstrthe output buffer
linestrthe input buffer
posin/out: the current char under consideration
charsthe number of chars to consider
Returns
true on failure

Definition at line 128 of file escapesrc.cpp.

References appendByte(), bytes, c, ch, chars, fprintf, i, pos, s, sscanf(), U8_APPEND_UNSAFE, and U8_LENGTH.

Referenced by fixu8().

◆ cleanup()

int cleanup ( const std::string outfile)

Delete the output file (if any) We want to delete even if we didn't generate, because it might be stale.

Definition at line 68 of file escapesrc.cpp.

References errno, fprintf, outfile, perror(), prog, rc, and remove().

Referenced by convert().

◆ convert()

int convert ( const std::string infile,
const std::string outfile 
)

Convert a whole file

Parameters
infile
outfile
Returns
1 on err, 0 otherwise

Definition at line 367 of file escapesrc.cpp.

References cleanup(), fixLine(), fprintf, getline(), in, inf, infile, no, out, outf, outfile, prog, and string.

Referenced by main().

◆ fixAt()

Bool__ fixAt ( std::string linestr,
size_t  pos 
)

fix the u"x"/u'x'/u8"x" string at the position u8'x' is not supported, sorry.

Parameters
linestrthe input string
posthe position
Returns
false = no err, true = had err

Definition at line 208 of file escapesrc.cpp.

References c, cp1047_to_8859, fixu8(), fprintf, i, length, oldIllegal, pos, quote, s, sprintf, strlen(), U8_COUNT_TRAIL_BYTES, U8_IS_SINGLE, and U8_NEXT.

Referenced by fixLine().

◆ fixLine()

Bool__ fixLine ( int  ,
std::string linestr 
)

Fixup an entire line false = no err true = had err

Parameters
nothe line number (not used)
linestrthe string to fix
Returns
true if any err, else false

Definition at line 319 of file escapesrc.cpp.

References fixAt(), INT32_MAX, len, pos, and strstr().

Referenced by convert().

◆ fixu8()

Bool__ fixu8 ( std::string linestr,
size_t  origpos,
size_t endpos 
)

Fixup u8"x"

Parameters
linestrstring to mutate. Already escaped into \u format.
origposbeginning, points to 'u8"' @param pos end, points to "
Returns
false for no-problem, true for failure!

Definition at line 164 of file escapesrc.cpp.

References appendByte(), appendUtf8(), c, c2, cp1047_to_8859, pos, and string.

Referenced by fixAt().

◆ main()

int main ( int  argc,
const char *  argv[] 
)

Main function

Definition at line 415 of file escapesrc.cpp.

References argc, argv, convert(), infile, outfile, prog, string, and usage().

◆ skipws()

const char* skipws ( const char *  p,
const char *  e 
)
inline

Skip across any known whitespace.

Parameters
pstartpoint
elimit
Returns
first non-whitespace char

Definition at line 93 of file escapesrc.cpp.

References e, kCR, kLF, kSPACE, kTAB, and p.

◆ usage()

void usage ( void  uerr)

Give the usual 1-line documentation and exit

Definition at line 60 of file escapesrc.cpp.

References fprintf, and prog.

Referenced by main().

Variable Documentation

◆ kCR

const char kCR = 0x0D
static

Definition at line 49 of file escapesrc.cpp.

Referenced by skipws().

◆ kLF

const char kLF = 0x0A
static

Definition at line 48 of file escapesrc.cpp.

Referenced by skipws().

◆ kSPACE

const char kSPACE = 0x20
static

What is this?

"This" is a preprocessor that makes an attempt to convert fully valid C++11 source code in utf-8 into something consumable by certain compilers (Solaris, xlC) which aren't quite standards compliant.

  • u"<unicode>" or u'<unicode>' gets converted to u"\uNNNN" or u'\uNNNN'
  • u8"<unicode>" gets converted to "\xAA\xBB\xCC\xDD" etc. (some compilers do not support the u8 prefix correctly.)
  • if the system is EBCDIC-based, that is used to correct the input characters.

Usage: escapesrc infile.cpp outfile.cpp Normally this is invoked by the build stage, with a rule such as:

_%.cpp: /%.cpp $(BINDIR)/escapesrc $< $@ %.o: _%.cpp $(COMPILE.cc) ... $@ $<

In the Makefiles, SKIP_ESCAPING=YES is used to prevent escapesrc.cpp from being itself escaped.

Definition at line 46 of file escapesrc.cpp.

Referenced by skipws().

◆ kTAB

const char kTAB = 0x09
static

Definition at line 47 of file escapesrc.cpp.

Referenced by skipws().

◆ prog

Definition at line 55 of file escapesrc.cpp.

Referenced by cleanup(), convert(), main(), and usage().