📄 notationfile.cpp
字号:
Verify(!macroed);
macroed = true;
#endif
char new_buf[MAX_LINE_SIZE];
Macro::ReplaceMacros(macro_tree, buffer, new_buf, sizeof(new_buf));
p = new_buf;
goto Parse;
}
else
ProcessLine(stream, macro_tree, page, p);
}
//
//------------------------------------------------------------
// We are in raw mode, so just process each line as it happens
//------------------------------------------------------------
//
else
ProcessLine(stream, macro_tree, page, p);
}
if (comment_mode)
PAUSE(("There is a missing */ in %s", (const char*)m_fileName));
if (nested)
PAUSE(("There is a missing } in %s", (const char*)m_fileName));
//
//------------------------------------------------------------------------
// If we allocated the macro tree, delete it now. The extra braces are to
// remove the iterator needed for deletion
//------------------------------------------------------------------------
//
if (!orig_tree)
{
{
TreeIteratorOf<Macro*, MString> macros(macro_tree);
macros.DeletePlugs();
}
Check_Object(macro_tree);
delete macro_tree;
}
//
//---------------------
// Nothing to save, yet
//---------------------
//
m_dirtyFlag = false;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
NotationFile::Write(MemoryStream *stream)
{
Check_Object(this);
Check_Object(stream);
//
//----------------------------------
// Write each page out to the stream
//----------------------------------
//
PageIterator pages(&m_pages);
Page *page;
while ((page = pages.ReadAndNext()) != NULL)
{
Check_Object(page);
page->WriteNotes(stream);
}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
NotationFile::Save()
{
Check_Object(this);
//
//------------------------------------------------------
// If the file is dirty and has a filename, write it out
//------------------------------------------------------
//
if (m_dirtyFlag && m_fileName.GetLength()>0)
{
FileStream output(m_fileName, FileStream::WriteOnly);
Write(&output);
}
IgnoreChanges();
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
NotationFile::SaveAs(const char* file_name)
{
Check_Object(this);
//
//------------------------------------------------------
// If the file is dirty and has a filename, write it out
//------------------------------------------------------
//
FileStream output(file_name, FileStream::WriteOnly);
m_fileName = output.GetFileName();
Write(&output);
IgnoreChanges();
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
NotationFile::ProcessLine(
MemoryStream *stream,
MacroTree *macro_tree,
Page **notepage,
char *buffer
)
{
Check_Object(this);
Check_Object(stream);
Check_Object(macro_tree);
Check_Pointer(buffer);
Check_Pointer(notepage);
//
//--------------------------------
// find first non-blank character
//--------------------------------
//
char *p = buffer;
while (*p == ' ' || *p == '\t')
++p;
//
//----------------------------------------------------------------------
// If this is a page name, isolate the name, then only add it if it is a
// new page
//----------------------------------------------------------------------
//
char *token;
if (*p == '[')
{
token = p+1;
if ((p = strchr(token, ']')) != NULL)
*p = '\0';
*notepage = SetPage(token);
return;
}
//
//---------------------------------------------
// If this is a comment or empty line, stop now
//---------------------------------------------
//
if (!*p)
return;
//
//--------------------------------------------------------------
// Look for an entry, and if we find one, clear out the trailing
// whitespace on the name
//--------------------------------------------------------------
//
token = p;
char *entry = NULL;
if ((p = strchr(token, '=')) != NULL)
{
*p = '\0';
entry = p + 1;
--p;
while (*p == ' ' || *p == '\t')
{
*p = '\0';
if (--p < token)
break;
}
}
//
//----------------------------------------------------------------
// If a notepage structure does not exist yet, make the empty page
//----------------------------------------------------------------
//
if (!*notepage)
*notepage = AddPage("");
Check_Object(*notepage);
//
//--------------------------------------------------
// Create the new entry if it is not a complex entry
//--------------------------------------------------
//
Note *notation = (*notepage)->AddNote(token);
Check_Object(notation);
if (entry)
{
if (_stricmp(entry, "{"))
notation->SetEntry(entry);
//
//----------------------------------------------------------------------
// Now we create a new notation file to read the next part of the stream
// into
//----------------------------------------------------------------------
//
else
{
NotationFile nested_file;
nested_file.Read(stream, macro_tree, NULL, true);
DynamicMemoryStream file_buffer(5);
file_buffer << "{\r\n";
nested_file.Write(&file_buffer);
file_buffer << "}" << '\0';
file_buffer.Rewind();
notation->m_text = static_cast<const char*>(file_buffer.GetPointer());
}
}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
NotationFile::HandleBangStuff(
char *buffer,
MacroTree *macro_tree,
Page **page
)
{
Check_Pointer(buffer);
Check_Pointer(page);
Check_Object(macro_tree);
//
//-------------------------
// Move past any whitespace
//-------------------------
//
while (*buffer == ' ' || *buffer == '\t')
++buffer;
if (!*buffer)
return;
//
//----------------------------
// Handle an include directive
//----------------------------
//
char *p;
if (!strnicmp(buffer, "include", 7))
{
p = buffer+7;
//
//---------------------------------------
// Look for the beginning of the filename
//---------------------------------------
//
while (*p == ' ' || *p == '\t')
++p;
if (*p == '=')
{
++p;
while (*p == ' ' || *p == '\t')
++p;
}
//
//--------------------------------------------------
// If the filename starts with a quote, strip it off
//--------------------------------------------------
//
char *file_name;
if (*p == '"')
{
file_name = ++p;
p = strrchr(p, '"');
if (p)
*p = '\0';
}
else
file_name = p;
//
//---------------------------------------------------------------
// If there is a pathname in the file, it is searched for by gos,
// otherwise we assume it is relative to us
//---------------------------------------------------------------
//
char path[MAX_LINE_SIZE];
if (!strchr(file_name, '\\'))
{
Str_Copy(path, GetFileName(), sizeof(path));
p = strrchr(path, '\\');
if (p)
{
Str_Copy(p+1, file_name, sizeof(path) - (p - path) - 1);
file_name = path;
}
}
//
//---------------
// Now open it up
//---------------
//
FileStream input(file_name);
m_fileDependencies.AddDependency(&input);
Read(&input, macro_tree, page, false);
}
//
//------------------------------------------
// Otherwise, we must have ourselves a macro
//------------------------------------------
//
else
{
char *entry = NULL;
//
//--------------------------------
// trim the spaces off of the name
//--------------------------------
//
if ((p = strchr(buffer, '=')) != NULL)
{
*p = '\0';
entry = p + 1;
--p;
while (*p == ' ' || *p == '\t')
{
*p = '\0';
if (--p < buffer)
break;
}
}
//
//---------------------------------------------------------
// Make sure the name is decent and that the entry is valid
//---------------------------------------------------------
//
if (!*buffer || !entry || !*entry)
return;
Macro::AddValue(macro_tree, buffer, entry);
}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
Page*
NotationFile::FindPage(const char *pagename)
{
Check_Object(this);
Check_Pointer(pagename);
PageIterator pages(&m_pages);
Page *page;
while ((page = pages.ReadAndNext()) != NULL)
{
Check_Object(page);
const char* name = page->m_name;
if (name && !_stricmp(name, pagename))
return page;
}
return NULL;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
Page*
NotationFile::GetPage(const char *pagename)
{
Page *page = FindPage(pagename);
if (!page)
STOP((
"%s: [%s] is a required page!",
GetFileName(),
pagename
));
return page;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
Page*
NotationFile::SetPage(const char *pagename)
{
Check_Object(this);
Check_Pointer(pagename);
Page *page = FindPage(pagename);
if (!page)
page = AddPage(pagename);
Check_Object(page);
return page;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
Page*
NotationFile::AddPage(const char *pagename)
{
Check_Object(this);
Check_Pointer(pagename);
SetDirty();
Page *page = new Page(this);
Check_Object(page);
page->SetName(pagename);
m_pages.Add(page);
return page;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
NotationFile::DeletePage(const char *pagename)
{
Check_Object(this);
Check_Pointer(pagename);
Page *page = FindPage(pagename);
if (page)
{
Check_Object(page);
delete page;
SetDirty();
}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
NotationFile::DeleteAllPages()
{
Check_Object(this);
PageIterator pages(&m_pages);
Page *page;
while ((page = pages.ReadAndNext()) != NULL)
{
Check_Object(page);
delete page;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -