📄 tags.c
字号:
/*
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
**********************************************************************
TAGS.C holds code to manage the various tags that can fit at the left
hand side of each line in a source file. Tags inclue breakpoints,
bookmarks, and tags related to the find in files function. This file
also defines the bookmark functionality and dialogs, and the routines to
save and restore tags to the project file
**********************************************************************
*/
#include <windows.h>
#include <commctrl.h>
#include <commdlg.h>
#include <richedit.h>
#include <stdio.h>
#include "header.h"
#include "winconst.h"
extern HANDLE children[MAX_CHILDREN];
extern int numberofdrawwindows;
extern HWND hwndFrame;
extern HINSTANCE hInstance;
HWND hwndBookmark;
static char bpModule[256];
static int bpLine;
static LOGFONT fontdata =
{
15, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE,
"Arial"
};
DWINFO currentBM;
struct tagfile *tagFileList, *last_module;
int oldline(struct tagfile *, int, int);
int IsTagged(char *module, int line)
{
struct tagfile *l = tagFileList;
if (last_module && !stricmp(module, last_module->name))
{
l = last_module;
goto join;
}
while (l)
{
if (!stricmp(l->name, module))
{
int i;
last_module = l;
join: for (i = 0; i < TAG_MAX; i++)
{
struct tag *t = l->tagArray[i];
while (t)
{
if (line == t->drawnLineno)
if (t->enabled)
if (t->enabled &TAGF_GRAYED)
return TAG_BPGRAYED;
else
return i;
else
break;
t = t->next;
}
}
return - 1;
}
l = l->next;
}
return - 1;
}
//-------------------------------------------------------------------------
int Tag(int type, char *name, int drawnLineno, int charpos, void *extra, int
freeextra, int alwaysadd)
{
struct tagfile **l = &tagFileList;
struct tag *t, **oldt;
while (*l)
{
if (!stricmp((*l)->name, name))
break;
l = &(*l)->next;
} if (! *l)
{
*l = calloc(sizeof(struct tagfile), 1);
if (! *l)
return FALSE ;
strcpy((*l)->name, name);
}
t = (*l)->tagArray[type];
oldt = &(*l)->tagArray[type];
while (t)
{
if (drawnLineno == t->drawnLineno)
{
if (alwaysadd)
{
t->enabled = TAGF_ENABLED;
if (!t->enabled && type == TAG_BP)
if (!dbgSetBreakPoint(name, t->debugLineno, extra))
t->enabled |= TAGF_GRAYED;
InvalidateByName((*l)->name);
return TRUE;
}
if (t->enabled && type == TAG_BP && (!t->extra || freeextra) ||
type != TAG_BP)
{
*oldt = t->next;
if (type == TAG_BP)
dbgClearBreakPoint((*l)->name, t->debugLineno);
free(t->extra);
free(t);
InvalidateByName((*l)->name);
}
else
{
t->enabled = !t->enabled;
if (t->enabled)
{
if (!dbgSetBreakPoint((*l)->name, t->debugLineno, t->extra))
t->enabled |= TAGF_GRAYED;
}
else
dbgClearBreakPoint((*l)->name, t->debugLineno);
InvalidateByName((*l)->name);
return t->enabled;
}
return FALSE;
}
if (drawnLineno < t->drawnLineno)
break;
oldt = &t->next;
t = t->next;
}
t = calloc(sizeof(struct tag), 1);
if (!t)
return FALSE ;
t->editingLineno = t->drawnLineno = drawnLineno;
t->debugLineno = oldline(l, drawnLineno, FALSE);
t->charpos = charpos;
t->extra = extra;
t->next = *oldt;
t->enabled = TAGF_ENABLED;
*oldt = t;
if (type == TAG_BP)
if (!dbgSetBreakPoint(name, t->debugLineno, extra))
t->enabled |= TAGF_GRAYED;
InvalidateByName((*l)->name);
return TRUE;
}
//-------------------------------------------------------------------------
void TagRemoveAll(int type)
{
struct tagfile *l = &tagFileList;
struct tag *t;
while (l)
{
t = l->tagArray[type];
l->tagArray[type] = NULL;
while (t)
{
struct tag *nt = t->next;
if (type == TAG_BP)
dbgClearBreakPoint(l->name, t->debugLineno);
free(t->extra);
free(t);
t = nt;
} InvalidateByName(l->name);
l = l->next;
}
}
// used after BP are restored from data file
void TagRegenBreakPoints(void)
{
struct tagfile *l = tagFileList;
struct tag *t;
int flag = FALSE;
while (l)
{
t = l->tagArray[TAG_BP];
while (t)
{
if (t->enabled == TAGF_ENABLED)
if (!dbgSetBreakPoint(l->name, t->debugLineno, t->extra))
{
flag = TRUE;
t->enabled |= TAGF_GRAYED;
InvalidateByName(l->name);
} t = t->next;
}
l = l->next;
}
if (flag)
ExtendedMessageBox("Breakpoints", 0,
"One or more breakpoints were not positioned on valid lines and were disabled");
}
//-------------------------------------------------------------------------
static int oldline(struct tagfile *l, int lineno, int allowmiddle)
{
struct tagchangeln *c = l->changedLines;
while (c && lineno >= c->lineno)
{
if (lineno < c->lineno + c->delta)
{
if (allowmiddle)
return c->lineno;
else
return 0;
} lineno -= c->delta;
c = c->next;
}
return lineno;
}
//-------------------------------------------------------------------------
int TagOldLine(char *name, int lineno)
{
struct tagfile *l = tagFileList;
int rv = lineno;
while (l)
{
if (!stricmp(l->name, name))
{
return oldline(l, lineno, FALSE);
} l = l->next;
}
return lineno;
}
//-------------------------------------------------------------------------
static int newline(struct tagfile *l, int line)
{
int delta = 0;
struct tagchangeln *c = l->changedLines;
while (c && line >= c->lineno)
{
delta += c->delta;
c = c->next;
} return delta + line;
}
//-------------------------------------------------------------------------
int TagNewLine(char *name, int lineno)
{
struct tagfile *l = tagFileList;
int rv = lineno;
while (l)
{
if (!stricmp(l->name, name))
{
return newline(l, lineno);
} l = l->next;
}
return lineno;
}
//-------------------------------------------------------------------------
void TagRemoveOld(struct tagfile *l)
{
struct tagchangeln *c = l->changedLines;
while (c)
{
struct tagchangeln *x = c->next;
free(c);
c = x;
} l->changedLines = 0;
}
//-------------------------------------------------------------------------
static void TagInsertChange(struct tagfile *l, int lineno, int delta)
{
struct tagchangeln **c = &l->changedLines, *newone, **insert = 0;
int found = FALSE;
lineno = oldline(l, lineno, TRUE);
while (*c)
{
if ((*c)->lineno >= lineno)
{
if ((*c)->lineno == lineno)
found = TRUE;
else
if (!insert)
insert = c;
(*c)->delta += delta;
} c = &(*c)->next;
}
if (!found)
{
if (!insert)
insert = c;
newone = calloc(1, sizeof(struct tagchangeln));
if (!newone)
return ;
newone->next = *insert;
newone->lineno = lineno;
newone->delta = delta;
(*insert) = newone; // relies on link being first field
}
}
//-------------------------------------------------------------------------
void TagLineChange(char *name, int drawnLineno, int delta)
{
struct tagfile *l = tagFileList;
int i;
while (l)
{
if (!stricmp(l->name, name))
{
TagInsertChange(l, drawnLineno, delta);
for (i = 0; i < TAG_MAX; i++)
{
struct tag *t = l->tagArray[i];
while (t)
{
if (t->drawnLineno >= drawnLineno)
t->drawnLineno += delta;
t = t->next;
}
}
break;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -