📄 test1.c
字号:
#define BORLANDC
/*
Copyright 2001-2003 Free Software Foundation, Inc.
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.
You may contact the author at:
mailto::camille@bluegrass.net
or by snail mail at:
David Lindauer
850 Washburn Ave Apt 99
Louisville, KY 40222
**********************************************************************
XEDIT is an edit control, similar in some respects to rich edit but
not having the full functionality of the rich edit control. It was written
in order to speed up the process of drawing colored text and get around
various bugs inherent in the rich edit control. This module forms
the basic functionality for the edit windows, however the windows created
with the class in this module are superclassed with the routines in the
EDITOR module, to add various functionality such as loading and storing
files to disk, processing hints, putting up the right-click menu, and
interacting with other windows in the CCIDE program.
**********************************************************************
*/
// assumes tabs aren't going to get reset yet
#define STRICT
#include <windows.h>
#include <commctrl.h>
#include <stdio.h>
#include "header.h"
#include <richedit.h>
#include <limits.h>
#include <commctrl.h>
// some things that caused problems
// also look for the 'if' statements where it breaks up '"' character constants wrong
// and there are various indentation problems this file as well.
short *aa = L "hi there";
short bb = L 'h';
#define ListView_SetCheckState(hwndLV, i, fCheck) \
ListView_SetItemState(hwndLV, i, INDEXTOSTATEIMAGEMASK((fCheck)?2:1),
LVIS_STATEIMAGEMASK)
// This defines the maximum range for the horizontal scroll bar on the window
#define MAX_HSCROLL 256
// The INTERNAL_CHAR structure is used to store one character that is displayed.
// It has all the information needed to render the character.
typedef struct
{
COLORREF color;
short effect;
char ch;
char pad;
} INTERNAL_CHAR;
#define CRLF_DUMMY 255
// The next few constants control the UNDO mechanism
#define UNDO_MAX 100
#define UNDO_INSERT 1
#define UNDO_DELETE 2
#define UNDO_BACKSPACE 3
#define UNDO_MODIFY 4
#define UNDO_DELETESELECTION 5
#define UNDO_INSERTSELECTION 6
#define UNDO_CASECHANGE 7
#define UNDO_INSERTINDENT 8
#define UNDO_DELETEINDENT 9
// a list of UNDO structures describe each operation the user performs.
// The list is traversed backwards if 'undo' is pressed.
typedef struct
{
char type;
char modified;
int preselstart;
int preselend;
int postselstart;
int postselend;
int len;
int max;
unsigned char *data;
} UNDO;
// the EDITDATA structure holds all information the edit control has
// available on a per window basis. Note that this isn't all the information
// there is about the window; things that aren't related to editing
// may be held in structures in the EDITOR module
typedef struct
{
HWND tooltip;
RECT ttrect;
char ttident[256];
int ttlineno;
HFONT hFont, hBoldFont, hItalicFont, hItalicBoldFont;
HBRUSH hbrBackground;
COLORREF defforeground;
COLORREF defbackground;
char *lastgottext;
INTERNAL_CHAR *text;
int textlen;
int textmaxlen;
int selstartcharpos;
int selendcharpos;
int textshowncharpos;
int leftshownindex;
int tabs;
int leftmargin;
int updowncol;
UNDO undolist[UNDO_MAX];
char undohead;
char undotail;
char undoing;
char colorize;
char modified;
char txtFontHeight;
char txtFontWidth;
char nosel;
char inserting;
char selecting;
char buttondown;
char autoscrolldir;
char hasfocus;
char hiddenCaret;
char ttup;
char sendchangeonpaint;
char readonly;
} EDITDATA;
// The KEYLIST structure holds information about text which should be
// colorized. It gives the name of a keyword (e.g. 'int') and the color
// to display it in.
typedef struct
{
char *text;
COLORREF *color;
} KEYLIST;
// The next few variables hold the configuration information from the
// editor properties screen. IT is mostly set to defaults here,
// and will be overwritten from the registry and later from the project
// file
extern int editFlags;
COLORREF keywordColor = 0xff8000;
COLORREF numberColor = 0x0000ff;
COLORREF commentColor = 0x00c000;
COLORREF stringColor = 0x8000ff;
COLORREF escapeColor = 0xff0000;
COLORREF backgroundColor = 0xffffff;
COLORREF textColor = 0;
LOGFONT EditFont =
{
- 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FIXED_PITCH
| FF_DONTCARE, "Courier New"
};
int tabs = 4;
// COLORREF selcolor = 0 ;
// For drawing, put a little margin at the left
#define LEFTMARGIN 5
// well we aren't 'totally' independent of the rest of CCIDE...
// the following is used for the tooltip
extern enum DebugState uState;
extern HINSTANCE hInstance;
extern PROJLIST *selectedProject;
void SendUpdate(HWND hwnd);
// The C_keywordList is a list of all keywords, with colorization info
static KEYLIST C_keywordList[] =
{
#include "c_kw.h"
};
static KEYLIST ASM_keywordList[] =
{
#include "asm_kw.h"
};
/**********************************************************************
* SaveColors saves the color and font settings to the registry
**********************************************************************/
void saveColors(void)
{
IntToProfile("KeywordColor", keywordColor);
IntToProfile("NumberColor", numberColor);
IntToProfile("CommentColor", commentColor);
IntToProfile("StringColor", stringColor);
IntToProfile("EscapeColor", escapeColor);
IntToProfile("BackgroundColor", backgroundColor);
IntToProfile("TextColor", textColor);
IntToProfile("lfHeight", EditFont.lfHeight);
IntToProfile("lfWidth", EditFont.lfWidth);
IntToProfile("lfEscapement", EditFont.lfEscapement);
IntToProfile("lfOrientation", EditFont.lfOrientation);
IntToProfile("lfWeight", EditFont.lfWeight);
IntToProfile("lfItalic", EditFont.lfItalic);
IntToProfile("lfUnderline", EditFont.lfUnderline);
IntToProfile("lfStrikeOut", EditFont.lfStrikeOut);
IntToProfile("lfCharSet", EditFont.lfCharSet);
IntToProfile("lfOutPrecision", EditFont.lfOutPrecision);
IntToProfile("lfClipPrecision", EditFont.lfClipPrecision);
IntToProfile("lfQuality", EditFont.lfQuality);
IntToProfile("lfPitchAndFamily", EditFont.lfPitchAndFamily);
StringToProfile("lfFaceName", EditFont.lfFaceName);
}
/**********************************************************************
* RestoreColors restores the color and font settings from the registry
**********************************************************************/
void restoreColors(void)
{
keywordColor = ProfileToInt("KeywordColor", keywordColor);
numberColor = ProfileToInt("NumberColor", numberColor);
commentColor = ProfileToInt("CommentColor", commentColor);
stringColor = ProfileToInt("StringColor", stringColor);
escapeColor = ProfileToInt("EscapeColor", escapeColor);
backgroundColor = ProfileToInt("BackgroundColor", backgroundColor);
textColor = ProfileToInt("TextColor", textColor);
EditFont.lfHeight = ProfileToInt("lfHeight", EditFont.lfHeight);
EditFont.lfWidth = ProfileToInt("lfWidth", EditFont.lfWidth);
EditFont.lfEscapement = ProfileToInt("lfEscapement", EditFont.lfEscapement);
EditFont.lfOrientation = ProfileToInt("lfOrientation",
EditFont.lfOrientation);
EditFont.lfWeight = ProfileToInt("lfWeight", EditFont.lfWeight);
EditFont.lfItalic = ProfileToInt("lfItalic", EditFont.lfItalic);
EditFont.lfUnderline = ProfileToInt("lfUnderline", EditFont.lfUnderline);
EditFont.lfStrikeOut = ProfileToInt("lfStrikeOut", EditFont.lfStrikeOut);
EditFont.lfCharSet = ProfileToInt("lfCharSet", EditFont.lfCharSet);
EditFont.lfOutPrecision = ProfileToInt("lfOutPrecision",
EditFont.lfOutPrecision);
EditFont.lfClipPrecision = ProfileToInt("lfClipPrecision",
EditFont.lfClipPrecision);
EditFont.lfQuality = ProfileToInt("lfQuality", EditFont.lfQuality);
EditFont.lfPitchAndFamily = ProfileToInt("lfPitchAndFamily",
EditFont.lfPitchAndFamily);
strcpy(EditFont.lfFaceName, ProfileToString("lfFaceName",
EditFont.lfFaceName));
}
/**********************************************************************
* Colorize marks a range of text with a specific color and attributes
**********************************************************************/
static void Colorize(INTERNAL_CHAR *buf, int start, int len, int color, int
italic)
{
int dwEffects = 0, i;
INTERNAL_CHAR *p = buf + start;
if (italic)
dwEffects |= CFE_ITALIC;
if (!color)
dwEffects |= CFE_AUTOCOLOR;
else
{
if (!italic)
dwEffects |= CFE_BOLD;
}
for (i = 0; i < len; i++, p++)
{
p->color = color;
p->effect = dwEffects;
}
}
/**********************************************************************
* keysym returns true if it is a symbol that can be used in a keyword
**********************************************************************/
int keysym(char x)
{
return isalnum(x) || x == '_';
}
/**********************************************************************
* strpstr finds a text string within a string organized as internal
* characters. Returns 0 if it couldn't find the string
**********************************************************************/
INTERNAL_CHAR *strpstr(INTERNAL_CHAR *t, char *text, int len)
{
while (t->ch && len)
{
if (t->ch == text[0])
{
char *t1 = text;
INTERNAL_CHAR *it1 = t;
while (*t1 && it1->ch == *t1)
{
t1++;
it1++;
}
if (! *t1)
return t;
}
t++;
len--;
}
return 0;
}
/**********************************************************************
* strplen finds the length of an internal_char array
**********************************************************************/
int strplen(INTERNAL_CHAR *t)
{
int rv = 0;
while (t->ch)
rv++, t++;
return rv;
}
/**********************************************************************
* backalpha goes backwards to find out if the current (numeric)
* character is part of an identifier, or if it is a standalone number.
* returns TRUE if part of an identifier. Used in colorizing numbers
**********************************************************************/
static int backalpha(INTERNAL_CHAR *buf, int i)
{
while (i >= 0)
{
if (isalpha(buf[i].ch))
return TRUE;
if (buf[i].ch == '_')
return TRUE;
if (!isdigit(buf[i].ch))
return FALSE;
i--;
}
return FALSE;
}
//-------------------------------------------------------------------------
int pcmp(INTERNAL_CHAR *s, char *t, int preproc, int *retlen, int
caseinsensitive)
{
*retlen = 0;
while (*t && s->ch)
{
int val = s->ch;
if (caseinsensitive)
val = tolower(val);
if (val < *t)
return - 1;
else if (val > *t)
return 1;
else
{
if (*t == preproc)
{
while (isspace(s[1].ch) && s[1].ch != '\n')
s++, (*retlen)++;
}
s++, t++, (*retlen)++;
}
}
return keysym(s->ch);
}
/**********************************************************************
* See if a keyword matches the current text location
**********************************************************************/
KEYLIST *matchkeyword(KEYLIST *table, int tabsize, int preproc, INTERNAL_CHAR
*t, int *retlen, int insensitive)
{
int top = tabsize;
int bottom = 0;
int mid = (top + bottom) / 2;
while (1)
{
int v = pcmp(t, table[mid].text, preproc, retlen, insensitive);
if (!v)
{
return &table[mid];
}
if (mid == bottom)
// || mid >=top-1)
return 0;
if (v < 0)
{
top = mid;
mid = (mid + bottom) / 2;
}
else
{
bottom = mid;
mid = (mid + top) / 2;
}
if (mid >= top)
return 0;
}
}
/**********************************************************************
* SearchKeywords searches a range of INTERNAL_CHARs for keywords,
* numbers, and strings, and colorizes them
**********************************************************************/
static void SearchKeywords(INTERNAL_CHAR *buf, int chars, int start, int type)
{
int i;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -