head	39.15;
access;
symbols
	V39_14:39.15
	V39_13:39.14
	V39_12:39.13
	V39_11:39.13
	V39_10:39.11
	c3910:39.12
	V39_9:39.10;
locks; strict;
comment	@ * @;


39.15
date	95.09.02.20.44.17;	author StRuppert;	state Exp;
branches;
next	39.14;

39.14
date	95.08.07.15.17.19;	author StRuppert;	state Exp;
branches;
next	39.13;

39.13
date	95.07.09.11.37.15;	author StRuppert;	state Exp;
branches;
next	39.12;

39.12
date	95.06.04.18.51.49;	author StRuppert;	state Exp;
branches;
next	39.11;

39.11
date	95.06.04.16.46.28;	author StRuppert;	state Exp;
branches;
next	39.10;

39.10
date	95.05.10.14.57.12;	author StRuppert;	state Exp;
branches;
next	;


desc
@initial
@


39.15
log
@*** empty log	message	***
@
text
@%{
/*
** $PROJECT: c.datatype
**
** $VER: cdt.y 39.15 (02.09.95)
**
** by
**
** Stefan Ruppert , Windthorststraße 5 , 65439 Flörsheim , GERMANY
**
** (C) Copyright 1995
** All Rights Reserved !
**
** $HISTORY:
**
** 02.09.95 : 039.015 : added userstorage and fixed some bugs (see history for V39.14)
** 07.08.95 : 039.014 : added userkeyword support, fixed bug in alloca replacement
** 09.07.95 : 039.013 : completely rewitten segment handling, separate c++/c keywords and more
** 04.06.95 : 039.012 : fixed c++ comment bug, which was damaged by the V39.11 changes
** 04.06.95 : 039.011 : handles tabs and spaces correctly, also for printing
** 10.05.95 : 039.010 : added userdefined types
** 28.04.95 : 039.009 : fixed tab calculation after a // comment
** 26.04.95 : 039.008 : fixed bug,a \ at the end of the line within a string wasn't handled correctly
** 22.04.95 : 039.007 : two bugs fixed (// comments and \ after a string)
** 14.04.95 : 039.006 : added nested switch
** 07.04.95 : 039.005 : else keyword wasn't correct sorted
** 24.03.95 : 039.004 : missing else keyword added
** 23.03.95 : 039.003 : now full tabs handling
** 12.03.95 : 039.002 : added C++ keywords
** 07.03.95 : 039.001 : initial
*/

#include "classbase.h"

/*FS*/ void add_line(struct CParse *cparse,struct Style *style,STRPTR text,LONG len)
{
	struct ClassBase *cb = cparse->ClassBase;
	struct Line *line;

	LONG lf = 0;

	if(len > 0 && text[len-1] == '\n')
	{
		lf = LNF_LF;
		len--;
	}

	if((style->Style & FSF_UNDERLINED) && *text == ' ')
	{
		STRPTR ptr = text;

		while(*text == ' ')
			text++;

		len -= (text-ptr);
		style->Style &= ~FSF_UNDERLINED;
		add_line(cparse,style,ptr,(text-ptr));
		style->Style |=  FSF_UNDERLINED;
	}

	if((line = AllocPooled(cparse->Data->cd_Pool,sizeof(struct Line))))
	{
		line->ln_Text     = text;
		line->ln_TextLen  = len;

		line->ln_XOffset  = cparse->XOffset;
		line->ln_YOffset  = cparse->YOffset;
		line->ln_Width    = TextLength(cparse->RPort,line->ln_Text,line->ln_TextLen);
		line->ln_Height   = cparse->RPort->TxHeight;
		line->ln_Flags    = lf;
		line->ln_FgPen    = style->FgPen;
		line->ln_BgPen    = style->BgPen;
		if(style->Style != ~0)
			line->ln_Style = style->Style;
		else
		{
			line->ln_Style = FS_NORMAL;
			line->ln_FgPen = cparse->Data->cd_CStyle[C_STANDARD].FgPen;
		}

		if(lf)
		{
			if(cparse->XOffset + line->ln_Width > cparse->MaxWidth)
				cparse->MaxWidth = cparse->XOffset + line->ln_Width;

			cparse->YOffset += line->ln_Height;
			cparse->XOffset  = 0;
		} else
		{
			cparse->XOffset += line->ln_Width;

#if 0
			D({
				STRPTR ptr = &line->ln_Text[line->ln_TextLen];
				UBYTE help = *ptr;

				*ptr = '\0';
				bug("text : %s\n",line->ln_Text);
				*ptr = help;
			  });
#endif
		}

		AddTail(cparse->LineList,(struct Node *) line);
	}
}
/*FE*/

/*FS*/ void add_cexpr1(struct CParse *cparse,LONG index,STRPTR text,LONG len)
{
	if(cparse->Data->cd_CStyle[index].Style != ~0 || text[len-1] == '\n')
	{
		if(cparse->SegPtr < cparse->TxtPtr)
		{
			UWORD mode = cparse->ModeStack[cparse->ModeSP];

			add_line(cparse,&cparse->Data->cd_CStyle[mode],
						cparse->SegPtr,(cparse->TxtPtr - cparse->SegPtr));
		}

		if(len > 0)
		{
			DB(("style index : %ld , len : %ld\n",index,len));

			add_line(cparse,&cparse->Data->cd_CStyle[index],text,len);
		}

		cparse->TxtPtr = cparse->ActPtr;
		cparse->SegPtr = cparse->ActPtr;
	} else
		cparse->TxtPtr = cparse->ActPtr;
}
/*FE*/

static int cdtparse_lex(int *lvalp,struct CParse *cparse);

#define _STDIO_H

#ifdef printf
#undef printf
#endif

#define printf                bug
#define add_cexpr(index)      add_cexpr1(cparse,index,cparse->TxtPtr,cparse->ActPtr-cparse->TxtPtr)

/* mode macros */
#define push_mode(mode)       cparse->ModeStack[++cparse->ModeSP] = mode
#define replace_mode(mode)    cparse->ModeStack[cparse->ModeSP] = mode
#define pop_mode              cparse->ModeSP--

#define LASTLF                (((struct Line *) cparse->LineList->lh_TailPred)->ln_Flags & LNF_LF)
#define YYPARSE_PARAM         struct CParse *cparse
#define YYLEX_PARAM           cparse

#ifdef yyerror
#undef yyerror
#endif
#define yyerror(x)            cdtparse_parseerror(cparse,x)

%}

%pure_parser

/* cpp keywords */
%token T_INCLUDE T_DEFINE T_UNDEF T_PRAGMA T_LINE T_ERROR
%token T_IF T_IFDEF T_IFNDEF T_ELIF T_ENDIF

/* storage class */
%token T_AUTO T_EXTERN T_REGISTER T_STATIC
%token T_USERSTORAGE

/* type specifiers */
%token T_CHAR T_SHORT T_INT T_LONG T_BOOL
%token T_SIGNED T_UNSIGNED T_FLOAT T_DOUBLE T_VOID
%token T_USERTYPE
%token T_TEMPLATE

/* other c keywords */
%token T_SWITCH T_CASE T_BREAK T_DEFAULT
%token T_IF T_ELSE T_FOR T_DO T_WHILE T_CONTINUE
%token T_CONST T_VOLATILE
%token T_GOTO
%token T_RETURN
%token T_USERKEYWORD

%token T_STRUCT T_UNION T_ENUM T_TYPEDEF
%token T_SIZEOF

/* C++ keywords */
%token T_CLASS T_PUBLIC T_PRIVATE T_PROTECTED
%token T_VIRTUAL T_FRIEND
%token T_NEW T_DELETE T_OPERATOR
%token T_TRY T_CATCH T_THROW
%token T_INLINE

/* identifier */
%token T_ID
/* one char */
%token T_CHR
/* any number constant */
%token T_NUMBER

%%

input:
	  input2                   { if(!(LASTLF)) add_line(cparse,&cparse->Data->cd_CStyle[C_STANDARD],"\n",1); }
;

input2:
	  statement
	| input2 statement
;

statement:
	  '#'                      { push_mode(C_CPP); }
	  cppline                  { pop_mode; }
	| '\n'                     { add_cexpr(C_STANDARD); }
	| simple_type_name         { add_cexpr(C_TYPES);   }
	| storage_class            { add_cexpr(C_STORAGE); }
	| keywords
	| textlist
;

/*
cpp:
	  cppline    '\n'         { add_cexpr(C_STANDARD); }
;
*/

cppline:
	  cppkeyword               { add_cexpr(C_CPP); }
/*     cpptextlist */
	| T_INCLUDE                { add_cexpr(C_CPP); }
	  include                  { add_cexpr(C_HEADER); }
	| T_DEFINE                 { add_cexpr(C_CPP); replace_mode(C_STANDARD); }
	  T_ID                     { cparse->TxtPtr = cparse->ActPtr; }
	  definelist
;

cppkeyword:
	  T_UNDEF
	| T_PRAGMA
	| T_LINE
	| T_ERROR
	| T_IF
	| T_IFDEF
	| T_IFNDEF
	| T_ELIF
	| T_ENDIF
	| T_ELSE
;

include:
	  '"' headerstring '"'
	| '<' headerstring '>'
	| T_ID
;

headerstring:
	  headerstringtoken
	| headerstring headerstringtoken
;

headerstringtoken:
	  T_ID
	| T_CHR
	| '\\'
;
/*
cpptextlist:
	| textlist
;
*/
definelist:
	| definetextlist
;

definetextlist:
	  definetext
	| definetextlist definetext
;

definetext:
	  T_ID                     { cparse->TxtPtr = cparse->ActPtr; }
	| T_CHR                    { cparse->TxtPtr = cparse->ActPtr; }
	| T_NUMBER                 { add_cexpr(C_NUMBER);   }
	| '"'                      { cparse->TxtPtr = --cparse->ActPtr; add_cexpr(C_STANDARD); cparse->TxtPtr = ++cparse->ActPtr; push_mode(C_STRING); }
	  stringinner '"'          { add_cexpr(C_STRING);   pop_mode; }
	| '\'' char '\''           { add_cexpr(C_STRING);   }
	| '#'
	| '<'
	| '>'
	| '\\' '\n'                { add_cexpr(C_STANDARD); }
	  definelist
;

keywords:
	  keywordsincomplete       { add_cexpr(C_KEYWORD); }
	| keywordscomplete
;

keywordsincomplete:
	  T_CONST
	| T_VOLATILE
	| T_SWITCH
	| T_CASE
	| T_BREAK
	| T_IF
	| T_ELSE
	| T_FOR
	| T_DO
	| T_WHILE
	| T_CONTINUE
	| T_RETURN
	| T_DEFAULT
	| T_GOTO
	| T_TYPEDEF
	| T_SIZEOF
	| T_PUBLIC
	| T_PRIVATE
	| T_PROTECTED
	| T_TEMPLATE
	| T_VIRTUAL
	| T_FRIEND
	| T_NEW
	| T_DELETE
	| T_OPERATOR
	| T_TRY
	| T_CATCH
	| T_THROW
	| T_INLINE
	| T_USERKEYWORD
;

keywordscomplete:
	elaborated_type_specifier
;

elaborated_type_specifier:
	  class_key                { add_cexpr(C_KEYWORD); }
	  elaborated_type_specifier_name
	| T_ENUM                   { add_cexpr(C_KEYWORD); }
	  elaborated_type_specifier_name
;

class_key:
	  T_STRUCT
	| T_UNION
	| T_CLASS
;

elaborated_type_specifier_name:
	| T_ID                     { add_cexpr(C_TYPENAME); }
;

simple_type_name:
	  T_CHAR
	| T_SHORT
	| T_INT
	| T_LONG
	| T_SIGNED
	| T_UNSIGNED
	| T_FLOAT
	| T_DOUBLE
	| T_VOID
	| T_BOOL
	| T_USERTYPE
;

storage_class:
	  T_AUTO
	| T_EXTERN
	| T_STATIC
	| T_REGISTER
	| T_USERSTORAGE
;

textlist:
	  text
	| textlist text
;

text:
	  T_ID                     { cparse->TxtPtr = cparse->ActPtr; }
	| T_CHR                    { cparse->TxtPtr = cparse->ActPtr; }
	| T_NUMBER                 { add_cexpr(C_NUMBER); }
	| '<'
	| '>'
	| '\'' char  '\''          { add_cexpr(C_STRING); }
	| '"'                      { cparse->TxtPtr = --cparse->ActPtr; add_cexpr(C_STANDARD); cparse->TxtPtr = ++cparse->ActPtr; push_mode(C_STRING); }
	  stringinner '"'          { add_cexpr(C_STRING); pop_mode; }
	  stringend
;

char:
	| T_ID
	| T_CHR
	| T_NUMBER
	| '"'
	| '#'
	| '\\' stringescaped
;


stringend:
	| '\\' '\n'                { add_cexpr(C_STANDARD); }
;

stringinner:
	  stringtoken
	| stringinner stringtoken
;


stringtoken:
	| T_ID
	| T_CHR
	| T_NUMBER
	| '<'
	| '>'
	| '\''
	| '#'
	| '\\' stringescaped
;

stringescaped:
	  T_ID
	| T_CHR
	| T_NUMBER
	| '"'
	| '\\'
	| '\''
	| '<'
	| '>'
	| '\n'                     { add_cexpr(C_STRING); }
;

%%

/*FS*/ /*"Keyword definition"*/
struct Keyword
{
	STRPTR k_Word;
	int k_ID;
	int k_Len;
};

struct Keyword keywords[] =
{
	{"auto"     ,T_AUTO      ,4},
	{"break"    ,T_BREAK     ,5},
	{"case"     ,T_CASE      ,4},
	{"char"     ,T_CHAR      ,4},
	{"const"    ,T_CONST     ,5},
	{"continue" ,T_CONTINUE  ,8},
	{"default"  ,T_DEFAULT   ,7},
	{"do"       ,T_DO        ,2},
	{"double"   ,T_DOUBLE    ,6},
	{"else"     ,T_ELSE      ,4},
	{"enum"     ,T_ENUM      ,4},
	{"extern"   ,T_EXTERN    ,6},
	{"float"    ,T_FLOAT     ,5},
	{"for"      ,T_FOR       ,3},
	{"goto"     ,T_GOTO      ,4},
	{"if"       ,T_IF        ,2},
	{"int"      ,T_INT       ,3},
	{"long"     ,T_LONG      ,4},
	{"register" ,T_REGISTER  ,8},
	{"return"   ,T_RETURN    ,6},
	{"short"    ,T_SHORT     ,5},
	{"signed"   ,T_SIGNED    ,6},
	{"sizeof"   ,T_SIZEOF    ,6},
	{"static"   ,T_STATIC    ,6},
	{"struct"   ,T_STRUCT    ,6},
	{"switch"   ,T_SWITCH    ,6},
	{"typedef"  ,T_TYPEDEF   ,7},
	{"union"    ,T_UNION     ,5},
	{"unsigned" ,T_UNSIGNED  ,8},
	{"void"     ,T_VOID      ,4},
	{"volatile" ,T_VOLATILE  ,8},
	{"while"    ,T_WHILE     ,5},
	{NULL       ,0}
};

struct Keyword cpluspluskeywords[] =
{
	{"bool"     ,T_BOOL      ,4},
	{"catch"    ,T_CATCH     ,5},
	{"class"    ,T_CLASS     ,5},
	{"delete"   ,T_DELETE    ,6},
	{"friend"   ,T_FRIEND    ,6},
	{"inline"   ,T_INLINE    ,6},
	{"new"      ,T_NEW       ,3},
	{"operator" ,T_OPERATOR  ,8},
	{"private"  ,T_PRIVATE   ,7},
	{"protected",T_PROTECTED ,9},
	{"public"   ,T_PUBLIC    ,6},
	{"template" ,T_TEMPLATE  ,8},
	{"throw"    ,T_THROW     ,5},
	{"try"      ,T_TRY       ,3},
	{"virtual"  ,T_VIRTUAL   ,7},
	{NULL       ,0}
};

struct Keyword cppkeywords[] =
{
	{"define"   ,T_DEFINE    ,6},
	{"elif"     ,T_ELIF      ,4},
	{"else"     ,T_ELSE      ,4},
	{"endif"    ,T_ENDIF     ,5},
	{"error"    ,T_ERROR     ,5},
	{"if"       ,T_IF        ,2},
	{"ifdef"    ,T_IFDEF     ,5},
	{"ifndef"   ,T_IFNDEF    ,6},
	{"include"  ,T_INCLUDE   ,7},
	{"line"     ,T_LINE      ,4},
	{"pragma"   ,T_PRAGMA    ,6},
	{"undef"    ,T_UNDEF     ,5},
	{NULL       ,0}
};
/*FE*/

/*FS*/ static int cdtparse_lex(int *lvalp,struct CParse *cparse)
{
	struct ClassBase *cb = cparse->ClassBase;
	struct CData *cd = cparse->Data;
	STRPTR ptr = cparse->ActPtr;
	STRPTR end = cparse->EndPtr;
	STRPTR name;
	ULONG tablen = cd->cd_TabLength;
	struct Keyword *kw = NULL;
	int retval = 0;
	int len;
	int tabs;
	int chrs;

	if(ptr < end)
	{
		UWORD mode = cparse->ModeStack[cparse->ModeSP];

		do
		{
			tabs = 0;
			chrs = cparse->Chars;

			while(ptr < end && (*ptr == ' ' || *ptr == '\t'))
			{
				if(*ptr++ == '\t')
				{
					chrs += (tablen - (chrs % tablen));
					tabs = 1;
				} else
					chrs++;
			}

			if(tabs)
			{
				if(mode != C_STANDARD)
					add_cexpr(mode);

				cparse->ActPtr = ptr;
				add_cexpr1(cparse,C_STANDARD,cparse->Data->cd_TabBuffer,chrs - cparse->Chars);
			}

			cparse->Chars = chrs;

			/* handle comments */
			if(*ptr == '/' && ptr < end - 1 && (ptr[1] == '*' || ptr[1] == '/') && mode != C_STRING)
			{
				cparse->TxtPtr = ptr;

				add_cexpr(C_COMMENT);

				push_mode(C_COMMENT);

				ptr += 2;
				if(ptr[-1] == '*')
				{
					int nested = 1;

					while(ptr < end && nested)
					{
						switch(*ptr)
						{
						case '*':
							if(ptr[1] == '/')
							{
								nested--;
								ptr++;
							}
							break;
						case '/':
							if(ptr[1] == '*' && cparse->Data->cd_Flags.Nested)
							{
								nested++;
								ptr++;
							}
							break;
						case '\n':
							ptr++;
							cparse->ActPtr = ptr;
							add_cexpr(C_COMMENT);
							cparse->Chars = 0;
							continue;
						case '\t':
							cparse->TxtPtr = ptr;

							chrs = cparse->Chars;

							while(*ptr == '\t' || *ptr == ' ')
							{
								if(*ptr++ == '\t')
									chrs += (tablen - (chrs % tablen));
								else
									chrs++;
							}

							cparse->ActPtr = ptr;
							add_cexpr1(cparse,C_COMMENT,cparse->Data->cd_TabBuffer,chrs - cparse->Chars);
							cparse->Chars  = chrs;

							ptr--;
							break;
						}
						cparse->Chars++;
						ptr++;
					}
					cparse->ActPtr = ptr;
					add_cexpr(C_COMMENT);
				} else
				{
					while(ptr < end && *ptr != '\n')
					{
						if(*ptr == '\t')
						{
							cparse->TxtPtr = ptr;
							chrs = cparse->Chars;

							while(*ptr == '\t')
							{
								chrs += (tablen - (chrs % tablen));
								ptr++;
							}

							cparse->ActPtr = ptr;
							add_cexpr1(cparse,C_COMMENT,cparse->Data->cd_TabBuffer,chrs - cparse->Chars);
							cparse->Chars = chrs;
						} else
							cparse->Chars++;
						ptr++;
					}
					cparse->ActPtr = ptr;

					add_cexpr(C_COMMENT);
				}

				pop_mode;
			} else
				break;

		} while(*ptr == ' ' || *ptr == '\t' || *ptr == '/');

		if(ptr < end)
		{
			if(isalpha(*ptr) || *ptr == '_')
			{
				name = ptr;

				while(ptr < end && (isalpha(*ptr) || isdigit(*ptr) || *ptr == '_'))
					ptr++;

				len  = (ptr - name);

				ptr--;

				retval = T_ID;

				/* only search for keyword if it is normal text or a cppline !!! */
				if(mode == C_CPP)
					kw = cppkeywords;
				else if(mode == C_STANDARD)
					kw = keywords;

				if(len > 1 && kw)
				{
					int cmp;

					while(kw->k_Word)
					{
						if(!(cmp = strncmp(kw->k_Word,name,len)))
						{
							DB(("len = %ld , strlen(kw) = %ld\n",len,kw->k_Len));
							if(len == kw->k_Len)
							{
								retval = kw->k_ID;
								break;
							}
						} else if(cmp > 0)
							break;
						kw++;
					}

					if(cmp != 0 && cparse->Language == LANG_CPLUSPLUS)
					{
						kw = cpluspluskeywords;
						while(kw->k_Word)
						{
							if(!(cmp = strncmp(kw->k_Word,name,len)))
							{
								DB(("len = %ld , strlen(kw) = %ld\n",len,kw->k_Len));
								if(len == kw->k_Len)
								{
									retval = kw->k_ID;
									break;
								}
							} else if(cmp > 0)
								break;
							kw++;
						}
					}

					/* try user defined type keywords */
					if(cmp)
					{
						struct Node *node;
						for(node = cd->cd_UserTypes.lh_Head ; node->ln_Succ ; node = node->ln_Succ)
						{
							if(len == node->ln_Type && !strncmp(node->ln_Name,name,len))
							{
								retval = T_USERTYPE;
								break;
							}
						}

						if(retval != T_USERTYPE)
						{
							for(node = cd->cd_UserKeywords.lh_Head ; node->ln_Succ ; node = node->ln_Succ)
							{
								if(len == node->ln_Type && !strncmp(node->ln_Name,name,len))
								{
									retval = T_USERKEYWORD;
									break;
								}
							}

							if(retval !=  T_USERKEYWORD)
								for(node = cd->cd_UserStorage.lh_Head ; node->ln_Succ ; node = node->ln_Succ)
								{
									if(len == node->ln_Type && !strncmp(node->ln_Name,name,len))
									{
										retval = T_USERSTORAGE;
										break;
									}
								}
						}
					}
				}
				cparse->Chars += len;
			} else if(isdigit(*ptr))
			{
				name = ptr;
				ptr++;

				if(*ptr == 'x' || *ptr == 'X')
				{
					ptr++;
					while(ptr < end && isxdigit(*ptr))
						ptr++;
				} else
				{
					while(ptr < end && isdigit(*ptr))
						ptr++;
				}

				cparse->Chars += (ptr - name);

				ptr--;

				retval = T_NUMBER;
			} else
			{
				retval = T_CHR;

				cparse->Chars++;
				switch(*ptr)
				{
				case '\n':
					cparse->Chars = 0;
				case '"':
				case '#':
				case '\\':
				case '\'':
				case '<':
				case '>':
					retval = *ptr;
					break;
				}
			}
			cparse->ActPtr = ptr + 1;
		}
	}

	if(SetSignal(0,SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C)
	{
		DB(("break signal received !\n"));
		cparse->Break = 1;
		return(0);
	}
	return((cparse->Token = retval));
}
/*FE*/

/*FS*/ void *cdtparse_alloc(struct CParse *cparse,int size)
{
	struct ClassBase *cb = cparse->ClassBase;
	struct cdtMem *mem;

	size += sizeof(struct cdtMem);
	if((mem = AllocPooled(cparse->Data->cd_Pool,size)))
	{
		mem->Next = cparse->Memory;
		mem->Size = size;

		cparse->Memory = mem;
		mem++;
	}
	return(mem);
}
/*FE*/
/*FS*/ void cdtparse_free(struct CParse *cparse)
{
	struct ClassBase *cb = cparse->ClassBase;
	struct cdtMem *mem = cparse->Memory;
	struct cdtMem *next;

	while(mem)
	{
		next = mem->Next;
		FreePooled(cparse->Data->cd_Pool,mem,mem->Size);
		mem = next;
	}
}
/*FE*/

/*FS*/ int cdtparse_error(char *str)
{
	DB(("error : %s\n",str));
	return(0);
}
/*FE*/
/*FS*/ void cdtparse_parseerror(struct CParse *cparse,char *str)
{
	struct ClassBase *cb = cparse->ClassBase;
	char *buf;

	if((buf = AllocPooled(cparse->Data->cd_Pool,100)))
	{
		STRPTR seg,act;

		seg =
		act = cparse->ActPtr;

		if(*seg == '\n')
			seg--;

		add_line(cparse,&cparse->Data->cd_CStyle[C_STANDARD],"\n",1);

		sprintf(buf,"Parse Error : last Token %4ld for line : \n",cparse->Token);

		add_line(cparse,&cparse->Data->cd_CStyle[C_STANDARD],buf,strlen(buf));

		while(seg > cparse->BegPtr && *seg != '\n')
			seg--;

		if(*seg == '\n')
			seg++;

		while(act < cparse->EndPtr && *act != '\n')
			act++;

		if(*act == '\n')
			act++;

		if(act > seg)
			add_line(cparse,&cparse->Data->cd_CStyle[C_STANDARD],seg,act-seg);
	}
}
/*FE*/

@


39.14
log
@*** empty log	message	***
@
text
@d5 1
a5 1
** $VER: cdt.y 39.14 (07.08.95)
d16 1
a47 1

d117 1
a117 1
			add_line(cparse,&cparse->Data->cd_CStyle[(mode < C_MAX) ? mode : C_STANDARD],
d151 1
d170 1
d206 4
d211 1
a211 1
	| input statement
d216 1
a216 1
	  cpp
d224 1
d226 1
a226 1
	  cppline     '\n'         { add_cexpr(C_STANDARD); }
d228 1
d231 5
a235 3
	  cppkeyword               { add_cexpr(C_CPP); replace_mode(C_CPPTEXTLIST); }
	  cpptextlist              { pop_mode; }
	| T_DEFINE                 { add_cexpr(C_CPP); replace_mode(C_CPPTEXTLIST); }
d237 1
a237 1
	  definelist               { pop_mode; }
d241 1
a241 2
	  T_INCLUDE
	| T_UNDEF
d253 17
d273 1
a273 1

d291 2
d375 1
d387 2
d419 2
d433 2
a530 1
	LONG addx;
d550 2
a551 4
					addx = (tablen - (chrs % tablen));

					tabs  += addx;
					chrs  += addx;
d556 1
a556 1
			if(tabs > 0)
d613 2
a614 5
								{
									addx = (tablen - (chrs % tablen));

									chrs += addx;
								} else
a638 2
							cparse->ActPtr = ptr;

d641 1
a641 3
								addx = (tablen - (chrs % tablen));

								chrs += addx;
d644 2
d736 1
d745 11
d764 1
a764 1
				if(*ptr == 'x')
d775 2
a777 1
				cparse->Chars += (ptr - name);
d793 2
@


39.13
log
@completely rewitten segment handling, separate c++/c keywords and more
@
text
@d5 1
a5 1
** $VER: cdt.y 39.13 (09.07.95)
d16 1
d182 1
d304 1
d707 10
d776 2
a777 1
	if((mem = AllocPooled(cparse->Data->cd_Pool,size + sizeof(struct cdtMem))))
d780 1
a780 1
		mem->Size = size + sizeof(struct cdtMem);
d782 1
a796 1
		mem--;
@


39.12
log
@fixed c++ comment bug, which was damaged by the V39.11 changes
@
text
@d5 1
a5 1
** $VER: cdt.y 39.12 (04.06.95)
d16 1
d33 1
a33 1
/*FS*/ void add_line(struct ClassBase *cb,struct CParse *cparse,ULONG index,UWORD flags)
d35 1
a35 1
	struct Style *style = &cparse->Data->cd_CStyle[index];
d38 3
a40 2
	/* ignore segments , which are marked as text and no tabs are found ! */
	if(!(style->Style == ~0 && index != C_STANDARD && cparse->XOffsetAdd == 0) || (flags & LNF_LF))
d42 3
a44 4
		if((line = AllocPooled(cparse->Data->cd_Pool,sizeof(struct Line))))
		{
			struct Line *tabline = NULL;
			STRPTR ptr = cparse->SegPtr;
a45 3
			if((style->Style & FSF_UNDERLINED) || cparse->XOffsetAdd > 0)
			{
				ULONG x = cparse->XOffsetAdd;
d47 3
a49 5
				while(*ptr == ' ' || *ptr == '\t')
				{
					if(*ptr++ == ' ')
						x++;
				}
d51 2
a52 15
				if((tabline = AllocPooled(cparse->Data->cd_Pool,sizeof(struct Line))))
				{
					tabline->ln_Text    = cparse->Data->cd_TabBuffer;
					tabline->ln_TextLen = x;
					tabline->ln_XOffset = cparse->XOffset;
					tabline->ln_YOffset = cparse->YOffset;

					x *= cparse->TabWidth;

					tabline->ln_Width   = x;
					tabline->ln_Height  = cparse->RPort->TxHeight;
					tabline->ln_Flags   = 0;
					tabline->ln_FgPen   = style->FgPen;
					tabline->ln_BgPen   = style->BgPen;
					tabline->ln_Style   = FS_NORMAL;
d54 5
a58 1
					cparse->XOffset += x;
d60 4
a63 3
					AddTail(cparse->LineList,(struct Node *) tabline);
				}
			}
d65 14
a78 1
			line->ln_Text    = ptr;
d80 4
a83 7
			if(ptr < cparse->ActPtr)
				line->ln_TextLen = cparse->ActPtr - ptr;
			else
			{
				line->ln_TextLen = 0;
				line->ln_Text    = NULL;
			}
d85 5
a89 2
			if((flags & LNF_LF) && line->ln_TextLen > 0)
				line->ln_TextLen--;
d91 11
a101 11
			line->ln_XOffset  = cparse->XOffset;
			line->ln_YOffset  = cparse->YOffset;
			line->ln_Width    = TextLength(cparse->RPort,line->ln_Text,line->ln_TextLen);
			line->ln_Height   = cparse->RPort->TxHeight;
			line->ln_Flags    = flags;
			line->ln_FgPen    = style->FgPen;
			line->ln_BgPen    = style->BgPen;
			if(style->Style != ~0)
				line->ln_Style = style->Style;
			else
				line->ln_Style = FS_NORMAL;
d103 4
a106 4
			if(flags & LNF_LF)
			{
				if(cparse->XOffset + line->ln_Width > cparse->MaxWidth)
					cparse->MaxWidth = cparse->XOffset + line->ln_Width;
d108 7
a114 5
				cparse->YOffset += line->ln_Height;
				cparse->XOffset  = 0;
			} else
			{
				cparse->XOffset += line->ln_Width;
d116 3
a118 9
				D({
					STRPTR ptr = &line->ln_Text[line->ln_TextLen];
					UBYTE help = *ptr;

					*ptr = '\0';
					bug("text : %s\n",line->ln_Text);
					*ptr = help;
				  });
			}
d120 3
a122 2
			cparse->XOffsetAdd = 0;
			cparse->SegPtr  = cparse->ActPtr;
d124 1
a124 1
			AddTail(cparse->LineList,(struct Node *) line);
d126 5
a130 1
	}
d134 1
a134 7
/*FS*/ void add_cexpr(struct ClassBase *cb,struct CParse *cparse,ULONG index,BOOL lf)
{
	if(cparse->TxtPtr > cparse->SegPtr && *cparse->SegPtr != '\n')
	{
		STRPTR actptr = cparse->ActPtr;
		ULONG index = (cparse->Mode < C_MAX) ? cparse->Mode : C_STANDARD;
		ULONG x = cparse->XOffsetAdd;
d136 1
a136 2
		cparse->XOffsetAdd = 0;
		cparse->ActPtr = cparse->TxtPtr;
d138 3
a140 1
		add_line(cb,cparse,index,0);
d142 2
a143 4
		cparse->XOffsetAdd = x;
		cparse->SegPtr = cparse->ActPtr;
		cparse->ActPtr = actptr;
	}
d145 4
d150 2
a151 1
	add_line(cb,cparse,index,lf);
d153 4
a156 3
	cparse->TxtPtr = cparse->ActPtr;
}
/*FE*/
d170 1
a170 1
%token T_CHAR T_SHORT T_INT T_LONG
d173 1
d201 3
a203 2
input:  statement
		| input statement
d207 7
a213 7
		  '#'                { cparse->Mode = C_CPP; }
		  cpp                { cparse->Mode = C_STANDARD; }
		| '\n'               { add_cexpr(cb,cparse,C_STANDARD,LNF_LF); }
		| simple_type_name   { add_cexpr(cb,cparse,C_TYPES,0);   }
		| storage_class      { add_cexpr(cb,cparse,C_STORAGE,0); }
		| keywords
		| textlist
d217 1
a217 1
		  cppline     '\n'         { add_cexpr(cb,cparse,C_STANDARD,LNF_LF); }
d221 5
a225 3
		  cppkeyword               { add_cexpr(cb,cparse,C_CPP,0); cparse->Mode = C_CPPTEXTLIST; }
		  cpptextlist
		| define
d229 11
a239 11
		  T_INCLUDE
		| T_UNDEF
		| T_PRAGMA
		| T_LINE
		| T_ERROR
		| T_IF
		| T_IFDEF
		| T_IFNDEF
		| T_ELIF
		| T_ENDIF
		| T_ELSE
d243 1
a243 7
		| textlist
;

define:
		  T_DEFINE                 { add_cexpr(cb,cparse,C_CPP,0); cparse->Mode = C_CPPTEXTLIST; cparse->TxtPtr = cparse->ActPtr; }
		  T_ID                     { cparse->TxtPtr = cparse->ActPtr;  }
		  definelist
d247 1
a247 1
		| definetextlist
d251 2
a252 4
		  definetext                { if(cparse->XOffsetAdd) add_cexpr(cb,cparse,C_STANDARD,0);
												cparse->TxtPtr = cparse->ActPtr;   }
		| definetextlist definetext { if(cparse->XOffsetAdd) add_cexpr(cb,cparse,C_STANDARD,0);
												cparse->TxtPtr = cparse->ActPtr;   }
d256 9
a264 8
		  T_ID
		| T_CHR
		| T_NUMBER                 { add_cexpr(cb,cparse,C_NUMBER,0);   }
		| '"' stringinner '"'      { add_cexpr(cb,cparse,C_STRING,0);   }
		| '\'' char '\''           { add_cexpr(cb,cparse,C_STRING,0);   }
		| '#'                      { cparse->TxtPtr = cparse->ActPtr;   }
		| '\\' '\n'                { add_cexpr(cb,cparse,C_STANDARD,LNF_LF); }
		  definelist
a266 2


d268 3
a270 2
		  keywordsincomplete       { add_cexpr(cb,cparse,C_KEYWORD,0); }
		| keywordscomplete
d273 29
a301 28
		  T_CONST
		| T_VOLATILE
		| T_SWITCH
		| T_CASE
		| T_BREAK
		| T_IF
		| T_ELSE
		| T_FOR
		| T_DO
		| T_WHILE
		| T_CONTINUE
		| T_RETURN
		| T_DEFAULT
		| T_GOTO
		| T_TYPEDEF
		| T_SIZEOF
		| T_PUBLIC
		| T_PRIVATE
		| T_PROTECTED
		| T_VIRTUAL
		| T_FRIEND
		| T_NEW
		| T_DELETE
		| T_OPERATOR
		| T_TRY
		| T_CATCH
		| T_THROW
		| T_INLINE
d305 1
a305 1
		  elaborated_type_specifier
d309 4
a312 4
		  class_key                { add_cexpr(cb,cparse,C_KEYWORD,0); }
		  elaborated_type_specifier_name
		| T_ENUM                   { add_cexpr(cb,cparse,C_KEYWORD,0); }
		  elaborated_type_specifier_name
d316 3
a318 3
		  T_STRUCT
		| T_UNION
		| T_CLASS
d322 1
a322 1
		| T_ID                     { add_cexpr(cb,cparse,C_TYPENAME,0); }
d326 11
a336 10
		  T_CHAR
		| T_SHORT
		| T_INT
		| T_LONG
		| T_SIGNED
		| T_UNSIGNED
		| T_FLOAT
		| T_DOUBLE
		| T_VOID
		| T_USERTYPE
d340 4
a343 4
		  T_AUTO
		| T_EXTERN
		| T_STATIC
		| T_REGISTER
d347 2
a348 4
		  text                     { if(cparse->XOffsetAdd) add_cexpr(cb,cparse,C_STANDARD,0);
											  cparse->TxtPtr = cparse->ActPtr; }
		| textlist text            { if(cparse->XOffsetAdd)  add_cexpr(cb,cparse,C_STANDARD,0);
											  cparse->TxtPtr = cparse->ActPtr; }
d352 7
a358 12
		  T_ID                     {  }
		| T_CHR
		| T_NUMBER                 { add_cexpr(cb,cparse,C_NUMBER,0); }
		| '\''
		  char
		  '\''                     { add_cexpr(cb,cparse,C_STRING,0); }
		| '"'                      { cparse->ActPtr--;add_cexpr(cb,cparse,C_STANDARD,0);
											  cparse->ActPtr++;cparse->Mode = C_STRING;         }
		  stringinner
		  '"'                      { add_cexpr(cb,cparse,C_STRING,0);
											  cparse->Mode = C_STANDARD; }
		  stringend
d362 6
a367 6
		| T_ID
		| T_CHR
		| T_NUMBER
		| '"'
		| '#'
		| '\\' stringescaped
d372 1
a372 1
		| '\\' '\n'                { add_cexpr(cb,cparse,C_STANDARD,LNF_LF); }
d376 2
a377 2
		  stringtoken
		| stringinner stringtoken
d382 6
a387 6
		| T_ID
		| T_CHR
		| T_NUMBER
		| '\''
		| '#'
		| '\\' stringescaped
d391 7
a397 7
		  T_ID
		| T_CHR
		| T_NUMBER
		| '"'
		| '\\'
		| '\''
		| '\n'                     { add_cexpr(cb,cparse,C_STRING,LNF_LF); }
a414 1
	{"catch"    ,T_CATCH     ,5},
a415 1
	{"class"    ,T_CLASS     ,5},
a418 1
	{"delete"   ,T_DELETE    ,6},
a425 1
	{"friend"   ,T_FRIEND    ,6},
a427 1
	{"inline"   ,T_INLINE    ,6},
a429 5
	{"new"      ,T_NEW       ,3},
	{"operator" ,T_OPERATOR  ,8},
	{"private"  ,T_PRIVATE   ,7},
	{"protected",T_PROTECTED ,9},
	{"public"   ,T_PUBLIC    ,6},
a437 2
	{"throw"    ,T_THROW     ,5},
	{"try"      ,T_TRY       ,3},
a440 1
	{"virtual"  ,T_VIRTUAL   ,7},
d447 20
d485 1
a485 1
/*FS*/ int cdtparse_lex(int *lvalp,struct ClassBase *cb,struct CParse *cparse)
d487 1
d497 2
d502 2
d506 2
d511 1
a511 1
				if(*ptr == '\t')
d513 1
a513 1
					addx = (tablen - (cparse->Chars % tablen));
d515 2
a516 2
					cparse->XOffsetAdd += addx;
					cparse->Chars      += addx;
d518 2
a519 1
					cparse->Chars++;
d521 7
a527 1
				ptr++;
d530 2
d533 1
a533 1
			if(*ptr == '/' && ptr < end - 1 && (ptr[1] == '*' || ptr[1] == '/') && cparse->Mode != C_STRING)
d535 6
d567 1
a567 1
							add_cexpr(cb,cparse,C_COMMENT,LNF_LF);
d571 3
a573 3
							cparse->ActPtr = ptr;
							if(cparse->Chars)
								add_cexpr(cb,cparse,C_COMMENT,0);
d577 1
a577 1
								if(*ptr == '\t')
d579 1
a579 1
									addx = (tablen - (cparse->Chars % tablen));
d581 1
a581 2
									cparse->XOffsetAdd += addx;
									cparse->Chars      += addx;
d583 1
a583 2
									cparse->Chars++;
								ptr++;
d585 5
d597 1
a597 1
					add_cexpr(cb,cparse,C_COMMENT,0);
d604 3
a608 2
							add_cexpr(cb,cparse,C_COMMENT,0);

d611 1
a611 1
								addx = (tablen - (cparse->Chars % tablen));
d613 1
a613 2
								cparse->XOffsetAdd += addx;
								cparse->Chars      += addx;
d616 2
a621 1
					ptr++;
d624 1
a624 2
					add_cexpr(cb,cparse,C_COMMENT,LNF_LF);
					cparse->Chars = 0;
d626 2
d649 1
a649 1
				if(cparse->Mode == C_CPP)
d651 1
a651 1
				else if(cparse->Mode == C_STANDARD)
d673 19
a706 1
				cparse->ActPtr = ptr + 1;
a724 1
				cparse->ActPtr = ptr + 1;
a742 1
				cparse->ActPtr = ptr + 1;
d744 1
d748 7
a754 4
	DB(("token : %ld\n",retval));
	cparse->Token = retval;

	return(retval);
d758 1
a758 1
/*FS*/ void *cdtparse_alloc(struct ClassBase *cb,struct CParse *cparse,int size)
d760 1
d773 1
a773 1
/*FS*/ void cdtparse_free(struct ClassBase *cb,struct CParse *cparse)
d775 1
d795 1
a795 1
/*FS*/ void cdtparse_parseerror(struct ClassBase *cb,struct CParse *cparse)
d797 1
d800 1
a800 1
	if((buf = AllocPooled(cparse->Data->cd_Pool,50)))
d802 11
a812 2
		STRPTR seg = cparse->SegPtr;
		STRPTR act = cparse->ActPtr;
d814 1
a814 4
		sprintf(buf,"Parse Error : last Token %4ld for line :",cparse->Token);
		cparse->SegPtr = buf;
		cparse->ActPtr = buf + strlen(buf);
		add_line(cb,cparse,C_STANDARD,LNF_LF);
d824 6
a829 3
		cparse->SegPtr = seg;
		cparse->ActPtr = act;
		add_line(cb,cparse,C_STANDARD,LNF_LF);
@


39.11
log
@handles tabs and spaces correctly, also for printing
@
text
@d5 1
a5 1
** $VER: cdt.y 39.11 (04.06.95)
d16 1
d242 1
a242 1
		  T_DEFINE                 { add_cexpr(cb,cparse,C_CPP,0); cparse->Mode = C_CPPTEXTLIST; }
d502 1
d582 1
a582 2
							if(cparse->Chars)
								add_cexpr(cb,cparse,C_COMMENT,0);
@


39.10
log
@*** empty log	message	***
@
text
@d5 1
a5 1
** $VER: cdt.y 39.10 (10.05.95)
d16 1
d31 1
a31 1
void add_line(struct ClassBase *cb,struct CParse *cparse,ULONG index,UWORD flags)
d41 1
a42 1
			ULONG x = cparse->XOffsetAdd;
d44 1
a44 1
			while(*ptr == ' ' || *ptr == '\t')
d46 28
a73 3
				if(*ptr == ' ')
					x += cparse->TabWidth;
				ptr++;
d77 1
d89 1
a89 1
			line->ln_XOffset  = cparse->XOffset + x;
d91 1
a91 1
			line->ln_Width    = TextLength(cparse->RPort,line->ln_Text,line->ln_TextLen) + x;
d129 1
d131 1
a131 1
void add_cexpr(struct ClassBase *cb,struct CParse *cparse,ULONG index,BOOL lf)
d154 1
d409 1
d483 1
d485 1
a485 1
int cdtparse_lex(int *lvalp,struct ClassBase *cb,struct CParse *cparse)
d492 1
a492 1
	LONG addx,chrs;
a500 1
			chrs = cparse->Chars;
d507 1
a507 4
					if(chrs)
						cparse->XOffsetAdd += addx * cparse->TabWidth;
					else
						cparse->XOffset    += addx * cparse->TabWidth;
d549 1
a549 2
							chrs = cparse->Chars;
							if(chrs)
d551 1
d558 1
a558 4
									if(chrs > 0)
										cparse->XOffsetAdd += addx * cparse->TabWidth;
									else
										cparse->XOffset    += addx * cparse->TabWidth;
d579 4
a582 2
							add_cexpr(cb,cparse,C_COMMENT,0);
							chrs = cparse->Chars;
d587 1
a587 4
								if(chrs)
									cparse->XOffsetAdd += addx * cparse->TabWidth;
								else
									cparse->XOffset    += addx * cparse->TabWidth;
d709 1
d711 1
a711 1
void *cdtparse_alloc(struct ClassBase *cb,struct CParse *cparse,int size)
d724 2
a725 2

void cdtparse_free(struct ClassBase *cb,struct CParse *cparse)
d738 1
d740 1
a740 1
int cdtparse_error(char *str)
d745 2
a746 2

void cdtparse_parseerror(struct ClassBase *cb,struct CParse *cparse)
d773 1
@
