dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnet/csdoc cssrc2html.c,NONE,1.1 cssrc2html.


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnet/csdoc cssrc2html.c,NONE,1.1 cssrc2html.h,NONE,1.1 fontcolors.c,NONE,1.1 fontcolors.h,NONE,1.1 scanner.c,NONE,1.1 scanner.h,NONE,1.1 tokens.h,NONE,1.1 Makefile.am,1.15,1.16
Date: Tue, 24 Jun 2003 00:20:27 -0400

Update of /cvsroot/dotgnu-pnet/pnet/csdoc
In directory subversions:/tmp/cvs-serv14336/csdoc

Modified Files:
        Makefile.am 
Added Files:
        cssrc2html.c cssrc2html.h fontcolors.c fontcolors.h scanner.c 
        scanner.h tokens.h 
Log Message:


Add the "cssrc2html" program to the tree.


--- NEW FILE ---

/*
 * cssrc2html.c - C# source file to HTML translator
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * Author: Jeff Post
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */

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

#include        "cssrc2html.h"
#include        "fontcolors.h"
#include        "tokens.h"
#include        "scanner.h"

#define MAX_FN_LEN      128

char            lineBuffer[MAX_LENGTH];         // input line from source file
bool            inComment = FALSE;
bool            firstFont = TRUE;
int             token;
int             tabspace = 4;
int             column = 0;                                             // for 
expanding tabs
int             lastcolor;                                              // last 
color tagged in HTML file

char            basename[MAX_FN_LEN];           // input file base name
char            srcname[MAX_FN_LEN];                    // name of input source 
file
char            dstname[MAX_FN_LEN];                    // name of html output 
file
char            optiontext[MAX_FN_LEN];

// Read next line from input file

bool ReadFromTextFile(FILE *sr)
{
        if (fgets(lineBuffer, MAX_LENGTH - 1, sr) != NULL)
                return TRUE;
        return FALSE;
}

// Write line to output file.
// Returns true if write ok, else returns false.

bool WriteToHtmlFile(FILE *sw, char *str)
{
        if (fputs(str, sw) == EOF)
        {
                printf("Error writing HTML file!\n");
                return FALSE;
        }
        return TRUE;
}

// Put italic tag in HTML file

bool italicize(FILE *sw)
{
        if (fputs("<i>", sw) == EOF)
        {
                printf("Error writing HTML file!\n");
                return FALSE;
        }
        return TRUE;
}

bool deItalicize(FILE *sw)
{
        if (fputs("</i>", sw) == EOF)
        {
                printf("Error writing HTML file!\n");
                return FALSE;
        }
        return TRUE;
}

// Set font color tag in HTML file

bool setColor(FILE *sw, int color)
{
        if (!firstFont && (color != lastcolor) && (fputs("</FONT>", sw) == EOF))
        {
                printf("Error writing HTML file!\n");
                return FALSE;
        }
        firstFont = FALSE;
        if (fputs("<FONT class=\"", sw) == EOF)
        {
                printf("Error writing HTML file!\n");
                return FALSE;
        }
        if (fputs(fontColors[color], sw) == EOF)
        {
                printf("Error writing HTML file!\n");
                return FALSE;
        }
        if (fputs("\">", sw) == EOF)
        {
                printf("Error writing HTML file!\n");
                return FALSE;
        }
        return TRUE;
}

void usage(void)
{
        printf("\nUsage: cssrc2html [-options] filename"
                         "\noptions:"
                         "\n  -tn  set tab spacing to n (default 4)"
                         "\n  -v   display version number and exit"
                         "\n  -h or -? display this help message and exit"
                         "\n\n");
}

//
// The conversion program.
//

int main(int argc, char *argv[])
{
        int     i, j;
        int     keycolor;               // current font color for key words
        char    option;
        FILE    *sr;                            // the input source file
        FILE    *sw;                            // the output HTML file

        if (argc < 2)
        {
                usage();
                return 1;
        }

        lastcolor = keycolor = 0;
        namespace[0] = '\0';

        for (i=1; i<argc; i++)
        {
                if (*argv[i] == '-')                    // if command line 
option
                {
                        option = argv[i][1];
                        if (option == 'v')                      // report 
version and exit
                        {
                                printf("\ncssrc2html version %d.%d.%d\n\n", 
VERSION, REV_MAJOR, REV_MINOR);
                                return 0;
                        }
                        else if (option == 't' || option == 'T')        // set 
tab spacing
                        {
                                j = strlen(argv[i]) - 2;
                                strncpy(optiontext, &argv[i][2], j);
                                optiontext[j] = '\0';
                                tabspace = atoi(optiontext);
                                if (tabspace < 2)
                                {
                                        printf("\ntab spacing must be 2 or 
greater\n");
                                        return 1;
                                }
                        }
                        else if (option == 'h' || option == 'H' || option == 
'?')
                        {
                                usage();
                                return 1;
                        }
                }
                else                                                            
// get name of input file
                {
                        j = strlen(argv[i]) - 1;        // find file name 
extension, if any
                        while (j > 0)
                        {
                                if (argv[i][j] == '.')
                                        break;
                                --j;
                        }

                        if (!j)                                                 
// if user did not specify file extention, default to '.cs'
                        {
                                strcpy(basename, argv[i]);
                                strcpy(srcname, basename);
                                strcat(srcname, ".cs");
                        }
                        else                                                    
        // else use file name specified
                        {
                                strncpy(basename, argv[i], j);
                                strcpy(srcname, argv[i]);
                        }
                        strcpy(dstname, basename);
                        strcat(dstname, ".html");
                }
        }

        printf("\ncssrc2html\n   input file: %s, output file %s\n", srcname, 
dstname);
        printf("   tab spacing %d\n\n", tabspace);

        sr = fopen(srcname, "r");
        if (!sr)
        {
                printf("Can't open input file\n");
                return 1;
        }

        sw = fopen(dstname, "w");
        if (!sw)
        {
                printf("Can't create HTML file!\n");
                fclose(sr);
                return 1;
        }

// Create preamble in output file

        fputs("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">\n", sw);
        fputs("<HTML><HEAD>\n<TITLE>", sw);
        fputs(srcname, sw);
        fputs("</TITLE>\n", sw);
        fputs("<STYLE type=\"text/css\">\n", sw);
        for (i=0; i<MAX_COLOR; i++)
                fputs(fontColorText[i], sw);
        fputs("</STYLE>\n", sw);
        fputs("</HEAD><BODY><PRE>\n", sw);

        while (ReadFromTextFile(sr))            // process the input file line 
by line
        {
                token = TokenNULL;
                do
                {                                                               
                // til end of line...
                        token = getToken();

                        if (token == TokenEND)          // end of line found
                        {
                                column = 0;
                                if (!WriteToHtmlFile(sw, tokenString))
                                {
                                        fclose(sr);
                                        return 1;
                                }
                        }
                        else if (token == TokenTAB)     // expand tabs
                        {
                                do
                                {
                                        if (!WriteToHtmlFile(sw, " "))
                                        {
                                                fclose(sr);
                                                return 1;
                                        }
                                        column++;
                                } while ((column % tabspace) != 0);
                        }
                        else                                                    
                // process token
                        {
                                column += strlen(tokenString);
                                if (token == TokenCOMMENT)                      
// start of comment
                                {
                                        inComment = TRUE;
                                        if (lastcolor != CommentColor && 
!setColor(sw, CommentColor))
                                        {
                                                fclose(sr);
                                                return 1;
                                        }
                                        lastcolor = CommentColor;
                                        if (!italicize(sw))
                                        {
                                                fclose(sr);
                                                return 1;
                                        }
                                        if (!WriteToHtmlFile(sw, tokenString))
                                        {
                                                fclose(sr);
                                                return 1;
                                        }
                                }
                                else if (token == TokenCOMMENTEND && inComment) 
// end of comment
                                {
                                        inComment = FALSE;
                                        if (!WriteToHtmlFile(sw, tokenString))
                                        {
                                                fclose(sr);
                                                return 1;
                                        }
                                        if (!deItalicize(sw))
                                        {
                                                fclose(sr);
                                                return 1;
                                        }
                                }
                                else
                                {
                                        if (!inComment)         // set colors 
for keywords, if not in comment
                                        {
                                                switch (token)
                                                {
                                                        case TokenDeclKEYWORD:
                                                                keycolor = 
DeclKeywordColor;
                                                                break;

                                                        case TokenTypeKEYWORD:
                                                                keycolor = 
TypeKeywordColor;
                                                                break;

                                                        case TokenStmtKEYWORD:
                                                                keycolor = 
StmtKeywordColor;
                                                                break;

                                                        case TokenExprKEYWORD:
                                                                keycolor = 
ExprKeywordColor;
                                                                break;

                                                        case TokenSTRING:
                                                                keycolor = 
StringColor;
                                                                break;

                                                        default:                
                // not a keyword, so revert to normal color
                                                                keycolor = 
NormalColor;
                                                                break;
                                                }
                                                if (lastcolor != keycolor && 
!setColor(sw, keycolor))
                                                {
                                                        fclose(sr);
                                                        return 1;
                                                }
                                                lastcolor = keycolor;
                                        }
                                        if (!WriteToHtmlFile(sw, tokenString))  
// output the token text
                                        {
                                                fclose(sr);
                                                return 1;
                                        }
                                }
                        }
                } while (token != TokenEND && token != TokenERROR);
        }

// Create postamble in output file

        if (fputs("<br><br></FONT></PRE></BODY></HTML>\n", sw) == EOF)
        {
                printf("Error writing HTML file!\n");
                fclose(sr);
                return 1;
        }
        fclose(sr);                     // all done
        fflush(sw);
        fclose(sw);
        return 0;
}

// end of file

--- NEW FILE ---

/*
 * cssrc2html.h - C# source file to HTML translator
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * Author: Jeff Post
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */

#ifndef FALSE
#define FALSE   0
#endif
#ifndef TRUE
#define TRUE    1
#endif

#define VERSION         0
#define REV_MAJOR       0
#define REV_MINOR       3

#define bool            int

#define MAX_LENGTH              128     // maximum string & token length

extern char             lineBuffer[MAX_LENGTH];

// end of file

--- NEW FILE ---

/*
 * fontcolors.c - C# source file to HTML translator
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * Author: Jeff Post
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */
 
#include        "fontcolors.h"

char *fontColors[MAX_COLOR] = {
        "normal",               // black - normal text
        "csdecl",               // purple - declaration keywords
        "cstype",               // red - type keywords
        "csstmt",               // teal (blue-green) - statement keywords
        "csexpr",               // maroon (brown) -  expression keywords
        "comment",              // navy (dark blue) - comments
        "string"                        // green - quoted strings
};

// Choose colors for token types

char *fontColorText[MAX_COLOR] = {
        "  .normal {color: black}\n",           // black - normal text
        "  .csdecl {color: purple}\n",  // purple - declaration keywords
        "  .cstype {color: red}\n",             // red - type keywords
        "  .csstmt {color: teal}\n",            // teal (blue-green) - 
statement keywords
        "  .csexpr {color: maroon}\n",  // maroon (brown) -  expression keywords
        "  .comment {color: navy}\n",           // navy (dark blue) - comments
        "  .string {color: green}\n"            // green - quoted strings
};

// end of file

--- NEW FILE ---

/*
 * fontcolors.h - C# source file to HTML translator
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * Author: Jeff Post
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */

enum KeywordColors {
        NormalColor,
        DeclKeywordColor,
        TypeKeywordColor,
        StmtKeywordColor,
        ExprKeywordColor,
        CommentColor,
        StringColor,
        MAX_COLOR
};

extern char     *fontColors[MAX_COLOR];
extern char     *fontColorText[MAX_COLOR];

// end of file

--- NEW FILE ---

/*
 * scanner.c - C# source file to HTML translator
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * Author: Jeff Post
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */

// Scanner/parser for cssrc2html

#include        <stdio.h>
#include        <stdlib.h>
#include        <ctype.h>
#include        <string.h>

#include        "cssrc2html.h"
#include        "tokens.h"
#include        "scanner.h"

char *SpecialNameTable[] = {            // identifiers for a refs
        "namespace", "class"
};

char *DeclKeywordTable[] = {            // C# declaration key words
        "abstract", "__arglist", "class", "const", "delegate",
        "enum", "event", "explicit", "extern", "implicit",
        "interface", "internal", "__module", "namespace",
        "operator", "out", "override", "params", "private",
        "protected", "public", "readonly", "ref", "sealed",
        "static", "struct", "unsafe", "using", "virtual",
        "volatile",
        NULL
};

char *TypeKeywordTable[] = {            // C# type key words
        "bool", "byte", "char", "decimal", "double", "float",
        "int", "long", "__long_double", "object", "sbyte",
        "short", "string", "uint", "ulong", "ushort", "void",
        NULL
};

char *StmtKeywordTable[] = {            // C# statement key words
        "break", "case", "catch", "checked", "continue",
        "default", "do", "else", "endif", "finally", "fixed",
        "for", "foreach", "goto", "if", "lock", "return",
        "switch", "throw", "try", "unchecked", "while",
        NULL
};

char *ExprKeywordTable[] = {            // C# expression key words
        "as", "base", "false", "in", "is", "__makeref", "new",
        "null", "__reftype", "refvalue", "sizeof", "stackalloc",
        "this", "true", "typeof",
        NULL
};

int     linePosition = 0;
char    lastchar;

char    namespace[MAX_LENGTH];                  // token string for namespace
char    className[MAX_LENGTH];                  // token string for current 
class
char    methodName[MAX_LENGTH];                 // token string for method name
int     depth = 0;                                                      // for 
determining if a token is a method name

char    tokenString[MAX_LENGTH];                // next token string from 
scanner
char    expandText[8];                                          // for 
expanding special characters
int     expandPosition = 0;
bool    expand = FALSE;
int     token;                                                          // 
current token for scanner/parser
int     error = NoError;                                        // scanner 
error code
bool    inCcomment = FALSE;                             // true if parsing C 
style comment
bool    inCPPcomment = FALSE;                   // true if parsing C++ style 
comment
bool    inString = FALSE;                                       // true if 
parsing quoted string
bool    namespacePending = FALSE;
bool    classPending = FALSE;
bool    methodPending = FALSE;

/* Return Token type if current tokenString is a special keyword,
        or return false if not */

bool tokenIsSpecial(void)
{
        int     i, type;

        i = 0;
        type = TokenNAMESPACE;
        while (SpecialNameTable[i])
        {
                if (strcmp(tokenString, SpecialNameTable[i]) == 0)
                {
                        return type;
                }
                i++;
                type++;
        }
        return FALSE;
}

/* Return Token type if current tokenString is a keyword,
   or return false if not a keyword. */

bool tokenIsKeyword(void)
{
        int     i;

        i = 0;
        while (DeclKeywordTable[i])
        {
                if (strcmp(tokenString, DeclKeywordTable[i]) == 0)
                        return TokenDeclKEYWORD;
                i++;
        }
        i = 0;
        while (TypeKeywordTable[i])
        {
                if (strcmp(tokenString, TypeKeywordTable[i]) == 0)
                        return TokenTypeKEYWORD;
                i++;
        }
        i = 0;
        while (StmtKeywordTable[i])
        {
                if (strcmp(tokenString, StmtKeywordTable[i]) == 0)
                        return TokenStmtKEYWORD;
                i++;
        }
        i = 0;
        while (ExprKeywordTable[i])
        {
                if (strcmp(tokenString, ExprKeywordTable[i]) == 0)
                        return TokenExprKEYWORD;
                i++;
        }
        return FALSE;
}

/* Return True if valid identifier character */

bool isIdChar(char c)
{
        if (isalnum(c) || c == '_')
                return TRUE;
        if (c == '.' && namespacePending)
                return TRUE;
        return FALSE;
}

/* Fetch the next character from the input stream for the scanner */

char getNextChar(void)
{
        char    c;

        if (expand)
        {
                c = expandText[expandPosition];
                if (c)
                {
                        expandPosition++;
                        return c;
                }
                else
                {
                        expand = FALSE;
                        expandPosition = 0;
                }
        }
        if (linePosition < strlen(lineBuffer))                  // not at end 
of line
        {
                c = lineBuffer[linePosition++];
                switch (c)
                {
                        case '<':
                                strcpy(expandText, "&lt;");
                                expandPosition = 1;
                                expand = TRUE;
                                c = '&';
                                break;

                        case '>':
                                strcpy(expandText, "&gt;");
                                expandPosition = 1;
                                expand = TRUE;
                                c = '&';
                                break;

                        case '&':
                                strcpy(expandText, "&amp;");
                                expandPosition = 1;
                                expand = TRUE;
                                c = '&';
                                break;
                }
                return c;
        }
        linePosition = 0;                       // end of line
        return ('\n');
}

/* Push current character back into the input stream - used by getToken() 
scanner */

void ungetNextChar(void)
{
        if (expand && expandPosition > 0)
        {
                --expandPosition;
                return;
        }

        if (linePosition > 0)
                --linePosition;
        else
                printf("DEBUG - Why are we pushing onto an EMPTY line?\n");
}

/*-----------------------------------------
 *
 * This is the scanner.
 * Returns next token from the source file.
 *
 *----------------------------------------*/

int getToken(void)
{
        char    c;
        bool    save;
        int     kword = TokenNULL;
        int     tsoffset;
        int     currentToken;
        int     scan_state;

        scan_state = START;
        tokenString[0] = '\0';                          // init token string to 
null
        tsoffset = 0;
        currentToken = TokenNULL;
        while (scan_state != DONE)                      // until we've got a 
complete token...
        {
                save = TRUE;
                c = getNextChar();

                if (c == '{')
                        depth++;
                else if (c == '}')
                        --depth;

                if (c == (char) 0)
                {
                        scan_state = DONE;
                        currentToken = TokenERROR;
                        linePosition = 0;
                        break;
                }

                if (inCcomment || inCPPcomment)         // if we were 
processing a comment,
                        scan_state = INCOMMENT;                         // 
remain in that state until end of comment

                switch (scan_state)
                {
                        case START:                                             
                // beginning of token
                                if (methodPending)                              
        // if last token was a method name, make a tag for it
                                {
                                        ungetNextChar();
                                        strcpy(tokenString, "<a name=\"");
                                        if (strlen(namespace) > 0)
                                        {
                                                strcat(tokenString, namespace);
                                                strcat(tokenString, ".");
                                        }
                                        strcat(tokenString, className);
                                        strcat(tokenString, ".");
                                        strcat(tokenString, methodName);
                                        strcat(tokenString, "\">");
                                        save = FALSE;
                                        scan_state = DONE;
                                        currentToken = TokenMETHOD;
                                        methodPending = FALSE;
                                }
                                else                                            
                                // if last token not a method name, then start 
new scan
                                {
                                        if (isIdChar(c))
                                                scan_state = INID;              
        // is possible keyword
                                        else if (c == '/')
                                                        scan_state = INCOMMENT; 
        // may be a comment
                                        else if (c == '"')
                                                scan_state = INSTRING;          
// is a quoted string
                                        else if (c == '\t')                     
        // return tab as a token so it can be expanded
                                        {
                                                scan_state = DONE;
                                                currentToken = TokenTAB;
                                        }
                                        else if (c == '\n')                     
        // newline at start of token
                                        {
                                                linePosition = 0;
                                                currentToken = TokenEND;
                                                scan_state = DONE;
                                        }
                                        else                                    
                                // if none of the above, must be normal text
                                                scan_state = INTEXT;
                                }                       
                                break;

                        case INID:
                                if (!isIdChar(c))                               
        // if not a valid keyword character,
                                {
                                        if (namespacePending)           // if 
it's the namespace, make a tag for it
                                        {
                                                ungetNextChar();
                                                strcpy(namespace, tokenString);
                                                strcpy(tokenString, "<a 
name=\"");
                                                strcat(tokenString, namespace);
                                                strcat(tokenString, "\">");
                                                strcat(tokenString, namespace);
                                                save = FALSE;
                                                scan_state = DONE;
                                                currentToken = TokenNAMESPACE;
                                                namespacePending = FALSE;
                                                depth = 0;
                                        }
                                        else if (classPending)          // it 
it's a class name, make a tag for it
                                        {
                                                ungetNextChar();
                                                strcpy(className, tokenString);
                                                strcpy(tokenString, "<a 
name=\"");
                                                if (strlen(namespace) > 0)
                                                {
                                                        strcat(tokenString, 
namespace);
                                                        strcat(tokenString, 
".");
                                                }
                                                strcat(tokenString, className);
                                                strcat(tokenString, "\">");
                                                strcat(tokenString, className);
                                                save = FALSE;
                                                scan_state = DONE;
                                                currentToken = TokenCLASS;
                                                classPending = FALSE;
                                                depth = 1;
                                        }
                                        else
                                        {                                       
// If character is '(' and last token was not an expression keyword,
                                                                                
// and current token string is not the class name nor "this", nor "base",
                                                                                
// then this token string is a method name.
                                                if (c == '(' && depth == 2 && 
kword != TokenExprKEYWORD &&
                                                                
strcmp(tokenString, className) &&
                                                                
strcmp(tokenString, "this") &&
                                                                
strcmp(tokenString, "base") &&
                                                                
strcmp(tokenString, methodName))
                                                {
                                                        strcpy(methodName, 
tokenString);                // save method name for tag
                                                        methodPending = TRUE;
                                                }

                                                ungetNextChar();                
                // push it back, and check if what we have so
                                                save = FALSE;                   
                // far is a C# keyword
                                                scan_state = DONE;

                                                if (namespacePending)
                                                        strcpy(namespace, 
tokenString);
                                                else if (classPending)
                                                strcpy(className, tokenString);

                                                kword = tokenIsSpecial();       
// check for 'namespace', 'class' keywords
                                                if (kword)
                                                {
                                                        switch (kword)
                                                        {
                                                                case 
TokenNAMESPACE:                            // if next token is an ID,
                                                                        
namespacePending = TRUE;        // then save it as namespace
                                                                        break;

                                                                case 
TokenCLASS:                                // if next token is an ID,
                                                                        
classPending = TRUE;            // then save it as className
                                                                        break;
                                                        }
                                                }
                                                kword = tokenIsKeyword();       
// check keyword tables
                                                if (kword)
                                                        currentToken = kword;   
// is one of the defined key words
                                                else
                                                        currentToken = 
TokenTEXT;       // else is normal text
                                        }                               
                                }
                                break;

                        case INTEXT:
                                if (c == '\n' || c == '/' || c == '\t' || c == 
'"' || isIdChar(c))
                                {
                                        save = FALSE;                           
        // may be part of key word or invalid text character
                                        ungetNextChar();                        
        // so push it back
                                        scan_state = DONE;                      
// and return text token
                                        currentToken = TokenTEXT;
                                }
                                break;

                        case INSTRING:
                                if (c == '"')                                   
        // end of quoted string
                                {
                                        scan_state = DONE;
                                        currentToken = TokenSTRING;
                                }
                                break;

                        case INCOMMENT:
                                if (c == '\t')                                  
        // expand tabs separately from comment
                                {
                                        if (tokenString[0])
                                        {
                                                save = FALSE;
                                                ungetNextChar();
                                                scan_state = DONE;
                                                currentToken = TokenTEXT;
                                        }
                                        else
                                        {
                                                scan_state = DONE;
                                                currentToken = TokenTAB;
                                        }
                                }

                                if (!inCcomment && !inCPPcomment)       // 
possible start of comment
                                {
                                        if (c == '/')                           
                        // C++ style comment
                                        {
                                                inCPPcomment = TRUE;
                                        }
                                        else if (c == '*')                      
                // C style comment
                                        {
                                                inCcomment = TRUE;
                                        }
                                        if (inCcomment || inCPPcomment) // let 
caller know about it
                                        {
                                                scan_state = DONE;
                                                currentToken = TokenCOMMENT;
                                        }
                                        else
                                        {
                                                save = FALSE;
                                                ungetNextChar();
                                                scan_state = DONE;
                                                currentToken = TokenTEXT;
                                        }
                                }
                                else                                            
                // already in comment text, check for end of comment
                                {
                                        if (inCcomment)
                                        {
                                                if (c == '\n')
                                                {
                                                        linePosition = 0;
                                                        scan_state = DONE;
                                                        currentToken = TokenEND;
                                                }
                                                else if (lastchar == '*' && c 
== '/')   // end of C comment
                                                {
                                                        scan_state = DONE;
                                                        currentToken = 
TokenCOMMENTEND;
                                                        inCcomment = FALSE;
                                                }
                                        }
                                        else if (inCPPcomment)
                                        {
                                                if (c == '\n')                  
        // newline ends C++ comment
                                                {
                                                        save = FALSE;
                                                        ungetNextChar();
                                                        scan_state = DONE;
                                                        currentToken = 
TokenCOMMENTEND;
                                                        inCPPcomment = FALSE;
                                                }
                                        }
                                }
                                lastchar = c;
                                break;

                        case DONE:
                                break;

                        default:
                                printf("Scanner state error\n");
                                error = ScannerStateError;
                                break;
                }

                if (save)
                {
                        tokenString[tsoffset++] = c;
                        tokenString[tsoffset] = '\0';
                }
        }
        return currentToken;
}

// end of file

--- NEW FILE ---

/*
 * scanner.h - C# source file to HTML translator
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * Author: Jeff Post
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */

enum ErrorCodes {
        NoError,
        UnexpectedToken,
        ScannerStateError,
};

enum scanState {                        // scanner states
        START, INID, INCOMMENT, INTEXT, INSTRING, DONE
};

extern char     tokenString[MAX_LENGTH];                // next token string 
from scanner
extern char     namespace[MAX_LENGTH];                  // token string for 
namespace

extern int      getToken(void);

// end of file

--- NEW FILE ---

/*
 * tokens.h - C# source file to HTML translator
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * Author: Jeff Post
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */

// These are tokens returned by the scanner/parser

enum Tokens {
        TokenNULL,                      // placeholder, used to do loop in line 
parsing
        TokenEND,                       // end of line (newline)
        TokenTAB,                       // for expanding tabs in HTML
        TokenDeclKEYWORD,       // C# declaration reserved word
        TokenTypeKEYWORD,       // C# type reserved word
        TokenStmtKEYWORD,       // C# statement reserved word
        TokenExprKEYWORD,       // C# expression reserved word
        TokenCOMMENT,           // beginning of C or C++ comment
        TokenCOMMENTEND,        // end of comment (*/ if C comment, newline if 
C++ comment)
        TokenTEXT,                      // text that is not keyword or quoted 
string
        TokenSTRING,            // quoted string
        TokenNAMESPACE, // start of namespace declaration (for csdoc)
        TokenCLASS,                     // start of class declaration (for 
csdoc)
        TokenMETHOD,            // start of method code (for csdoc)
        TokenPROPERTY,          // start of property (for csdoc)
        TokenERROR                      // should never get this :)
};

// end of file

Index: Makefile.am
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/csdoc/Makefile.am,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -r1.15 -r1.16
*** Makefile.am 24 May 2003 01:56:32 -0000      1.15
--- Makefile.am 24 Jun 2003 04:20:25 -0000      1.16
***************
*** 1,3 ****
! bin_PROGRAMS       = csdoc2texi csdoc2html csdoc2hier
  noinst_PROGRAMS    = csdocvalil csdoc2stub csdoc2test src2xml il2doc
  man_MANS           = csdoc2texi.1 csdoc2html.1 csdoc2hier.1
--- 1,3 ----
! bin_PROGRAMS       = csdoc2texi csdoc2html csdoc2hier cssrc2html
  noinst_PROGRAMS    = csdocvalil csdoc2stub csdoc2test src2xml il2doc
  man_MANS           = csdoc2texi.1 csdoc2html.1 csdoc2hier.1
***************
*** 29,32 ****
--- 29,34 ----
  csdoc2test_SOURCES = doc_test.c $(CSDOC_COMMON)
  csdoc2test_LDADD   = $(CSDOC_LIBS)
+ 
+ cssrc2html_SOURCES = cssrc2html.c fontcolors.c scanner.c
  
  il2doc_SOURCES     = il2doc.c





reply via email to

[Prev in Thread] Current Thread [Next in Thread]