Version 7.0
Copyright © 2021 Lowell D. Thomas
APG
… an ABNF Parser Generator
Macros | Functions
input.c File Reference

The API input functions. These functions assist with retrieving the ABNF grammar or grammars for processing. More...

#include "./api.h"
#include "./apip.h"
#include "./attributes.h"
Include dependency graph for input.c:

Go to the source code of this file.

Macros

#define CR   13
 
#define LF   10
 
#define TAB   9
 
#define BUF_SIZE   128
 

Functions

void vApiInClear (void *vpCtx)
 Clears the input and related memory. More...
 
const char * cpApiInFile (void *vpCtx, const char *cpFileName)
 Reads an SABNF grammar byte stream from a file. More...
 
const char * cpApiInString (void *vpCtx, const char *cpString)
 Reads an SABNF grammar byte stream from a string. More...
 
void vApiInValidate (void *vpCtx, abool bStrict)
 Scans the input SABNF grammar for invalid characters and line ends. More...
 
void vApiInToAscii (void *vpCtx, const char *cpFileName)
 Display the input lines with line numbers and character offsets. More...
 
void vApiInToHtml (void *vpCtx, const char *cpFileName, const char *cpTitle)
 Display the input lines with line numbers and character offsets. More...
 
void vLineError (api *spCtx, aint uiCharIndex, const char *cpSrc, const char *cpMsg)
 Finds the grammar line associated with a character index and formats an error message to the error log. More...
 

Detailed Description

The API input functions. These functions assist with retrieving the ABNF grammar or grammars for processing.

Definition in file input.c.

Macro Definition Documentation

◆ BUF_SIZE

#define BUF_SIZE   128

Definition at line 45 of file input.c.

◆ CR

#define CR   13

Definition at line 42 of file input.c.

◆ LF

#define LF   10

Definition at line 43 of file input.c.

◆ TAB

#define TAB   9

Definition at line 44 of file input.c.

Function Documentation

◆ cpApiInFile()

const char* cpApiInFile ( void *  vpCtx,
const char *  cpFileName 
)

Reads an SABNF grammar byte stream from a file.

May be called multiple times. Successive calls will append data to the previous grammar result. May be mixed with calls to cpApiInString().

Parameters
[in]vpCtx- Pointer to an API context previously returned from vpApiCtor().
[in]cpFileName- Name of the file to read.
Returns
Pointer to the cumulative, null-terminated SABNF grammar string.

Definition at line 117 of file input.c.

◆ cpApiInString()

const char* cpApiInString ( void *  vpCtx,
const char *  cpString 
)

Reads an SABNF grammar byte stream from a string.

May be called multiple times. Successive calls will append data to the previous SABNF grammar result. May be mixed with calls to cpApiInFile().

Parameters
[in]vpCtx- Pointer to an API context previously returned from vpApiCtor().
[in]cpString- Pointer to the string to read.
Returns
Pointer to the cumulative, null-terminated SABNF grammar string.

Definition at line 165 of file input.c.

◆ vApiInClear()

void vApiInClear ( void *  vpCtx)

Clears the input and related memory.

The user must call this to clear any previous input grammar before reusing the API object for another job.

Parameters
[in]vpCtx- Pointer to an API context previously returned from vpApiCtor().

Definition at line 61 of file input.c.

◆ vApiInToAscii()

void vApiInToAscii ( void *  vpCtx,
const char *  cpFileName 
)

Display the input lines with line numbers and character offsets.

Writes the input grammar in ASCII format to a file.

  • Valid control characters are single quoted, e.g. '\t', '\n', '\r'
  • Invalid characters are double quoted hex, e.g. '\xHH'
  • Invalid last line with no line ending is indicated as "EOF"
    Parameters
    [in]vpCtx- pointer to an API context previously returned from vpApiCtor().
    [in]cpFileName- Name of the file to write the result to. If NULL, stdout is used.

Definition at line 261 of file input.c.

◆ vApiInToHtml()

void vApiInToHtml ( void *  vpCtx,
const char *  cpFileName,
const char *  cpTitle 
)

Display the input lines with line numbers and character offsets.

Writes the input grammar as an HTML page to a file.

  • Valid control characters are stylized as TAB, LF and CR
  • Invalid characters are error stylized in hex, e.g. \xHH
  • Invalid last line with no line ending is error stylized as EOF
    Parameters
    [in]vpCtx- pointer to an API context previously returned from vpApiCtor().
    [in]cpFileName- name of the file to write the result to.
    [in]cpTitle- HTML title. If NULL, a default page title is used.

Definition at line 319 of file input.c.

◆ vApiInValidate()

void vApiInValidate ( void *  vpCtx,
abool  bStrict 
)

Scans the input SABNF grammar for invalid characters and line ends.

Constructs a lines object for dealing with finding and handling lines.

Parameters
[in]vpCtx- Pointer to an API context previously returned from vpApiCtor().
[in]bStrict- If true, validate as strict ABNF. If APG_TRUE, validate as strict ABNF (RFC5234 & RFC7405). Otherwise, validate as SABNF.
Returns
Throws exception on error.

Definition at line 204 of file input.c.

◆ vLineError()

void vLineError ( api spCtx,
aint  uiCharIndex,
const char *  cpSrc,
const char *  cpMsg 
)

Finds the grammar line associated with a character index and formats an error message to the error log.

Parameters
[in]spCtx- pointer to an API context previously returned from vpApiCtor().
uiCharIndexThe index of the character whose line number is desired.
cpSrcAn string idendifying the caller.
cpMsgThe error message.

Definition at line 383 of file input.c.

APG Version 7.0 is licensed under the 2-Clause BSD License,
an Open Source Initiative Approved License.