Home Libraries Author Links

Cuglify: C and C++ Source Code Uglifier
[Match Test]

Collaboration diagram for Cuglify: C and C++ Source Code Uglifier:

Detailed Description

CLI based console C program demonstrating the usage and testing the implementation of pattern matching in strings by means of regular expressions.


Files

file  cuglify.c
 Implementation of the console command cuglify, a C and C++ source code uglifier.

Data Structures

struct  CuglifyEnv
 Match environment CuglifyEnv. More...

Typedefs

typedef struct CuglifyEnv CuglifyEnv
 Type name of the match environment CuglifyEnv.

Enumerations

enum  LastChar {
  NORMAL,
  PLUS,
  MINUS,
  GREATER,
  TIMES,
  AMPERSAND,
  POUND,
  IDCHAR
}
 Last character state enumeration LastChar. More...

Functions

int main (int argc, char **argv)
 Main function implementing the command cuglify.
static int out (StmMtcFctCmd cmd, StmQreMtc qreMtc)
 Qualified regular expression action function for the qualified regular expression action out.
static int errout (StmMtcFctCmd cmd, StmQreMtc qreMtc)
 Qualified regular expression action function for the qualified regular expression action errout.
static int pout (StmMtcFctCmd cmd, StmQreMtc qreMtc)
 Qualified regular expression action function for the qualified regular expression action pout.
static int bout (StmMtcFctCmd cmd, StmQreMtc qreMtc)
 Qualified regular expression action function for the qualified regular expression action bout.
static int pnlout (StmMtcFctCmd cmd, StmQreMtc qreMtc)
 Qualified regular expression action function for the qualified regular expression action pnlout.
static int cnlout (StmMtcFctCmd cmd, StmQreMtc qreMtc)
 Qualified regular expression action function for the qualified regular expression action cnlout.
static int commout (StmMtcFctCmd cmd, StmQreMtc qreMtc)
 Qualified regular expression action function for the qualified regular expression action commout.
static int setclbeg (StmMtcFctCmd cmd, StmQreMtc qreMtc)
 Qualified regular expression action function for the qualified regular expression action setclbeg.
static int cmode (StmMtcFctCmd cmd, StmQreMtc qreMtc)
 Qualified regular expression action function for the qualified regular expression action cmode.
static int incif (StmMtcFctCmd cmd, StmQreMtc qreMtc)
 Qualified regular expression action function for the qualified regular expression action incif.
static int chkif (StmMtcFctCmd cmd, StmQreMtc qreMtc)
 Qualified regular expression action function for the qualified regular expression action chkif.
static int decif (StmMtcFctCmd cmd, StmQreMtc qreMtc)
 Qualified regular expression action function for the qualified regular expression action decif.
static int newlnr (StmMtcFctCmd cmd, StmQreMtc qreMtc)
 Qualified regular expression action function for the qualified regular expression action newlnr.
static int newfile (StmMtcFctCmd cmd, StmQreMtc qreMtc)
 Qualified regular expression action function for the qualified regular expression action newfile.
static void defsreact (StmReCtrl reCtrl, CuglifyEnv *env)
 Definition of regular expression StmRe objects and of qualified regular expression action functions.
static StmBool readline (CuglifyEnv *env)
 Read a logical line from the input and store it in the match environment.
static void flushout (CuglifyEnv *env)
 Flushes any still existing characters prepared for output.
static void gatherout (CuglifyEnv *env, const char *str, int len)
 Prepares characters for output.

Variables

static const char * man []
 Man page.


Typedef Documentation

typedef struct CuglifyEnv CuglifyEnv

Type name of the match environment CuglifyEnv.

Definition at line 174 of file cuglify.c.


Enumeration Type Documentation

enum typedef enum LastChar LastChar

Last character state enumeration LastChar.

Type name of the last character state enumeration LastChar.

Enumerator:
NORMAL  Normal character.

PLUS  '+' character.

MINUS  '-' character.

GREATER  '<' character.

TIMES  '*' character.

AMPERSAND  '&' character.

POUND  '#' character.

IDCHAR  Identifier character.

Definition at line 158 of file cuglify.c.


Function Documentation

int main ( int  argc,
char **  argv 
)

Main function implementing the command cuglify.

Parameters:
[in] argc Argument count.
[in] argv Pointer to an array of argc argument strings followed by an additional NULL array element.
Returns:
0, if no error occurred.

-1, if an internal system error occurred (should not occur).

1, if the command was used erroneously or the input could not be parsed successfully.

2, if one of the command line options --help or --versionn has been used.

Main function implementing the command cuglify.

Parameters:
[in] argc Argument count.
[in] argv Pointer to an array of argc argument strings followed by an additional NULL array element (only used internally).
Returns:
0, if no error occurred.

1, if an error occurred.

Definition at line 456 of file cuglify.c.

static int out ( StmMtcFctCmd  cmd,
StmQreMtc  qreMtc 
) [static]

Qualified regular expression action function for the qualified regular expression action out.

The function is assigned to the named qualified regular expression action out and prepares the token matched for output.

Examples:
cuglify.c, and matchtst.c.

Definition at line 687 of file cuglify.c.

Referenced by defsreact().

static int errout ( StmMtcFctCmd  cmd,
StmQreMtc  qreMtc 
) [static]

Qualified regular expression action function for the qualified regular expression action errout.

The function is assigned to the named qualified regular expression action errout. It prints an error message containing the current input line number on stderr and ends the program.

Examples:
cuglify.c.

Definition at line 775 of file cuglify.c.

Referenced by defsreact().

static int pout ( StmMtcFctCmd  cmd,
StmQreMtc  qreMtc 
) [static]

Qualified regular expression action function for the qualified regular expression action pout.

The function is assigned to the named qualified regular expression action pout. It prepares a '#' character at line begin for output.

Examples:
cuglify.c.

Definition at line 798 of file cuglify.c.

Referenced by defsreact().

static int bout ( StmMtcFctCmd  cmd,
StmQreMtc  qreMtc 
) [static]

Qualified regular expression action function for the qualified regular expression action bout.

The function is assigned to the named qualified regular expression action bout. It flags that a space character shall be output.

Examples:
cuglify.c.

Definition at line 820 of file cuglify.c.

Referenced by defsreact().

static int pnlout ( StmMtcFctCmd  cmd,
StmQreMtc  qreMtc 
) [static]

Qualified regular expression action function for the qualified regular expression action pnlout.

The function is assigned to the named qualified regular expression action pnlout. It flags that after a preprocessor line a newline character shall be output.

Examples:
cuglify.c.

Definition at line 836 of file cuglify.c.

Referenced by defsreact().

static int cnlout ( StmMtcFctCmd  cmd,
StmQreMtc  qreMtc 
) [static]

Qualified regular expression action function for the qualified regular expression action cnlout.

The function is assigned to the named qualified regular expression action cnlout. It flags that if a comment follows, the string contained in CuglifyEnv::clbegstr shall be output on a new line.

Examples:
cuglify.c.

Definition at line 853 of file cuglify.c.

Referenced by defsreact().

static int commout ( StmMtcFctCmd  cmd,
StmQreMtc  qreMtc 
) [static]

Qualified regular expression action function for the qualified regular expression action commout.

The function is assigned to the named qualified regular expression action commout. If CuglifyEnv::comments is StmTrue, it prepares the string CuglifyEnv::comment for output.

Examples:
cuglify.c.

Definition at line 884 of file cuglify.c.

Referenced by defsreact().

static int setclbeg ( StmMtcFctCmd  cmd,
StmQreMtc  qreMtc 
) [static]

Qualified regular expression action function for the qualified regular expression action setclbeg.

The function is assigned to the named qualified regular expression action setclbeg. It flags that if a comment follows, at first a newline character shall be output.

Examples:
cuglify.c.

Definition at line 912 of file cuglify.c.

Referenced by defsreact().

static int cmode ( StmMtcFctCmd  cmd,
StmQreMtc  qreMtc 
) [static]

Qualified regular expression action function for the qualified regular expression action cmode.

The function is assigned to the named qualified regular expression action cmode. If the matched text begins with a newline character, it sets the CuglifyEnv::incomment flag to StmTrue else to StmFalse.

Examples:
cuglify.c.

Definition at line 928 of file cuglify.c.

Referenced by defsreact().

static int incif ( StmMtcFctCmd  cmd,
StmQreMtc  qreMtc 
) [static]

Qualified regular expression action function for the qualified regular expression action incif.

The function is assigned to the named qualified regular expression action incif. It increments the preprocessor if counter CuglifyEnv::iflevel.

Examples:
cuglify.c.

Definition at line 944 of file cuglify.c.

Referenced by defsreact().

static int chkif ( StmMtcFctCmd  cmd,
StmQreMtc  qreMtc 
) [static]

Qualified regular expression action function for the qualified regular expression action chkif.

The function is assigned to the named qualified regular expression action chkif. It checks the preprocessor if counter CuglifyEnv::iflevel. If it is not positive, the function issues an error message and returns with StmMtcFctFail.

Examples:
cuglify.c.

Definition at line 960 of file cuglify.c.

Referenced by defsreact().

static int decif ( StmMtcFctCmd  cmd,
StmQreMtc  qreMtc 
) [static]

Qualified regular expression action function for the qualified regular expression action decif.

The function is assigned to the named qualified regular expression action decif. It checks the preprocessor if counter CuglifyEnv::iflevel. If it is not positive, the function issues an error message and returns with StmMtcFctFail, else the counter is decremented.

Examples:
cuglify.c.

Definition at line 983 of file cuglify.c.

Referenced by defsreact().

static int newlnr ( StmMtcFctCmd  cmd,
StmQreMtc  qreMtc 
) [static]

Qualified regular expression action function for the qualified regular expression action newlnr.

The function is assigned to the named qualified regular expression action newlnr. It sets the preprocessor line counter CuglifyEnv::lnr with the number designated by the matched text.

Examples:
cuglify.c.

Definition at line 1006 of file cuglify.c.

Referenced by defsreact().

static int newfile ( StmMtcFctCmd  cmd,
StmQreMtc  qreMtc 
) [static]

Qualified regular expression action function for the qualified regular expression action newfile.

The function is assigned to the named qualified regular expression action newfile. It sets the preprocessor file variable CuglifyEnv::filename with the matched text.

Examples:
cuglify.c.

Definition at line 1023 of file cuglify.c.

Referenced by defsreact().

static void defsreact ( StmReCtrl  reCtrl,
CuglifyEnv env 
) [static]

Definition of regular expression StmRe objects and of qualified regular expression action functions.

Parameters:
reCtrl The StmReCtrl object.
env Pointer to the match environment.
Effects:
The function defines the named regular expressions and named regular expression action functions for the StmReCtrl object reCtrl necessary to parse the input.
Examples:
cuglify.c, and matchtst.c.

Definition at line 1040 of file cuglify.c.

Referenced by main().

static StmBool readline ( CuglifyEnv env  )  [static]

Read a logical line from the input and store it in the match environment.

Parameters:
env Pointer to the match environment.
Effects:
The function reads a logical line from CuglifyEnv::instream and stores it in CuglifyEnv::str. A logical line consists of input lines with line unsplicing an trigraph expansion done. Moreover, whitespace at both sides of newline characters not defining line splices is removed.
Returns:
StmFalse, if the input is exhausted.

StmTrue, if a logical line was read.

Examples:
cuglify.c.

Definition at line 1207 of file cuglify.c.

Referenced by main().

static void flushout ( CuglifyEnv env  )  [static]

Flushes any still existing characters prepared for output.

Parameters:
env Pointer to the match environment.
Effects:
If the output line length is not limited, the function just prints a newline character on CuglifyEnv::outstream.
Else, if CuglifyEnv::outlen is not null, it prints CuglifyEnv::outstr followed by a newline character on CuglifyEnv::outstream and resets CuglifyEnv::outstr and CuglifyEnv::outlen.
Examples:
cuglify.c.

Definition at line 1333 of file cuglify.c.

Referenced by commout(), main(), out(), and pout().

static void gatherout ( CuglifyEnv env,
const char *  str,
int  len 
) [static]

Prepares characters for output.

Parameters:
env Pointer to the match environment.
str Pointer to the characters to prepare for output.
len If not null, the number of characters to prepare for output, else that is determined by strlen.
Effects:
If the output line length is not limited, the function just prints the determined number of characters to prepare for output on CuglifyEnv::outstream.
Else, the characters to be handled are appended to any already existing characters prepared for output. Then as much complete lines of at most CuglifyEnv::linelen characters each as possible are printed on CuglifyEnv::outstream regarding preprocessing requirements and doing line splicing, if needed. The caracters remaining are the characters prepared for output and their address and length are stored in CuglifyEnv::outstr and CuglifyEnv::outlen, respectively.
Examples:
cuglify.c.

Definition at line 1349 of file cuglify.c.

Referenced by commout(), out(), and pout().


Variable Documentation

const char* man[] [static]

Initial value:

{
"NAME                                                                         ",
"       cuglify - c or c++ source code uglifier                               ",
"                                                                             ",
"SYNOPSIS                                                                     ",
"       cuglify [--keep-comments] [--c-plus-plus|--slash-slash-comments]      ",
"               [--line-length=<linelen>] [--output=<outfile>] [<file>]       ",
"       cuglify --help                                                        ",
"       cuglify --version                                                     ",
"                                                                             ",
"DESCRIPTION                                                                  ",
"       The command cuglify transforms the source code given by the <file>    "
"       argument, or if no <file> argument is supplied, by standard input into"
"       an ugly and for a human viewer almost unreadable form which, however, "
"       compiles without errors.                                              ",
"       Unless option --help or --version is supplied, the command returns    "
"       with an exit code 0 on success and with an exit code 1, if any error  "
"       did occur.                                                            ",
"                                                                             ",
"OPTIONS                                                                      ",
"       --help                                                                ",
"       -h     Print this man page on standard output and exit with exit code "
"              2.                                                             ",
"                                                                             ",
"       --version                                                             ",
"       -V     Print version info on standard output and exit with exit code  ",
"              2.                                                             ",
"                                                                             ",
"       --keep-comments                                                       ",
"       -c     Retain comments in the output.                                 ",
"                                                                             ",
"       --cpp                                                                 ",
"       --c-plus-plus                                                         ",
"       -C     Assume c++ input. The default is c input.                      ",
"                                                                             ",
"       --slash-slash-comments                                                ",
"       -D     Assume c input with c++ one line comments.                     ",
"                                                                             ",
"       --line-length=<linelen>                                               ",
"       -l <linelen>                                                          ",
"              Define the line length of the output, which defaults to 78.    "
"              The argument <linelen> shall be greater than 15 and less than  "
"              32768 or 0.  If it is 0, the length of output lines is         "
"              unlimited.                                                     ",
"                                                                             ",
"       --output=<outfile>                                                    ",
"       --output-file=<outfile>                                               ",
"       -o <outfile>                                                          ",
"              Direct the output to <outfile>.  By default the output goes to "
"              standard output.                                               "
}
Man page.

The string array man is formatted by the functions defined in Format and Print Manual Page Text.

Examples:
cuglify.c, and dsettst.c.

Definition at line 81 of file cuglify.c.

Referenced by main().


© Copyright Tom Michaelis 2002-2007

Distributed under the SysToMath Software License (See the accompanying file license.txt or a copy at www.SysToMath.com).