2009-05-16 23:53:32 +00:00
|
|
|
#! /usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# file gen_lfuns.py
|
|
|
|
# This file is part of LyX, the document processor.
|
|
|
|
# Licence details can be found in the file COPYING.
|
|
|
|
|
|
|
|
# author Ewan Davies
|
|
|
|
|
|
|
|
# Full author contact details are available in file CREDITS
|
|
|
|
|
|
|
|
# Usage:
|
|
|
|
# gen_lfuns.py <path/to/LyXAction.cpp> <where/to/save/LFUNs.lyx>
|
|
|
|
|
2014-02-13 08:55:40 +00:00
|
|
|
import sys,re,os.path
|
2016-06-04 17:40:53 +00:00
|
|
|
import io
|
2009-05-16 23:53:32 +00:00
|
|
|
|
|
|
|
def error(message):
|
|
|
|
sys.stderr.write(message + '\n')
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
def usage(prog_name):
|
2009-05-17 00:34:29 +00:00
|
|
|
return "Usage: %s <path/to/LyXAction.cpp> [<where/to/save/LFUNs.lyx>]" % prog_name
|
2009-05-16 23:53:32 +00:00
|
|
|
|
|
|
|
DOXYGEN_START = "/*!"
|
2014-02-13 08:55:40 +00:00
|
|
|
DOXYGEN_END = "},"
|
2009-05-16 23:53:32 +00:00
|
|
|
|
2016-06-04 17:40:53 +00:00
|
|
|
LYX_NEWLINE = u"\n\\begin_inset Newline newline\n\\end_inset\n\n"
|
|
|
|
LYX_BACKSLASH = u"\n\\backslash\n"
|
2009-05-16 23:53:32 +00:00
|
|
|
|
2016-06-04 17:40:53 +00:00
|
|
|
HTMLONLY_START = u"\\htmlonly"
|
|
|
|
HTMLONLY_END = u"\\endhtmlonly"
|
|
|
|
LFUN_NAME_ID = u"\\var lyx::FuncCode lyx::"
|
|
|
|
LFUN_ACTION_ID = u"\\li Action: "
|
|
|
|
LFUN_NOTION_ID = u"\\li Notion: "
|
|
|
|
LFUN_SYNTAX_ID = u"\\li Syntax: "
|
|
|
|
LFUN_PARAMS_ID = u"\\li Params: "
|
|
|
|
LFUN_SAMPLE_ID = u"\\li Sample: "
|
|
|
|
LFUN_ORIGIN_ID = u"\\li Origin: "
|
|
|
|
LFUN_ENDVAR = u"\\endvar"
|
2009-05-16 23:53:32 +00:00
|
|
|
|
|
|
|
ID_DICT = dict(name=LFUN_NAME_ID, action=LFUN_ACTION_ID, notion=LFUN_NOTION_ID,
|
|
|
|
syntax=LFUN_SYNTAX_ID, params=LFUN_PARAMS_ID, sample=LFUN_SAMPLE_ID, origin=LFUN_ORIGIN_ID)
|
|
|
|
|
2016-06-04 17:40:53 +00:00
|
|
|
LFUNS_HEADER = u"""# gen_lfuns.py generated this file. For more info see http://www.lyx.org/
|
2016-06-04 17:46:40 +00:00
|
|
|
\\lyxformat 509
|
2009-05-16 23:53:32 +00:00
|
|
|
\\begin_document
|
|
|
|
\\begin_header
|
2016-01-15 20:31:57 +00:00
|
|
|
\\save_transient_properties true
|
2015-11-11 20:48:20 +00:00
|
|
|
\\origin /systemlyxdir/doc/
|
2009-10-19 00:01:01 +00:00
|
|
|
\\textclass article
|
2009-10-19 23:44:11 +00:00
|
|
|
\\begin_preamble
|
|
|
|
\\renewcommand{\\descriptionlabel}[1]{\\hspace\\labelsep\\upshape\\bfseries #1:}
|
|
|
|
\\renewenvironment{description}{\\list{}{%
|
|
|
|
\\setlength{\\itemsep}{-2pt}
|
|
|
|
\\advance\\leftmargini6\\p@ \\itemindent-12\\p@
|
|
|
|
\\labelwidth\\z@ \\let\\makelabel\\descriptionlabel}%
|
|
|
|
}{
|
|
|
|
\\endlist
|
|
|
|
}
|
|
|
|
\\end_preamble
|
2009-05-16 23:53:32 +00:00
|
|
|
\\use_default_options false
|
2014-02-10 07:35:22 +00:00
|
|
|
\\maintain_unincluded_children false
|
2014-02-13 09:44:12 +00:00
|
|
|
\\begin_local_layout
|
|
|
|
Style Description
|
|
|
|
LabelIndent MM
|
|
|
|
LeftMargin MMMMMxx
|
|
|
|
End
|
|
|
|
\\end_local_layout
|
2009-05-16 23:53:32 +00:00
|
|
|
\\language english
|
2014-02-10 07:35:22 +00:00
|
|
|
\\language_package default
|
2009-05-16 23:53:32 +00:00
|
|
|
\\inputencoding auto
|
2014-02-10 07:35:22 +00:00
|
|
|
\\fontencoding global
|
2015-11-11 20:48:20 +00:00
|
|
|
\\font_roman "default" "default"
|
|
|
|
\\font_sans "default" "default"
|
|
|
|
\\font_typewriter "default" "default"
|
|
|
|
\\font_math "auto" "auto"
|
2009-05-16 23:53:32 +00:00
|
|
|
\\font_default_family default
|
2014-02-10 07:35:22 +00:00
|
|
|
\\use_non_tex_fonts false
|
2009-05-16 23:53:32 +00:00
|
|
|
\\font_sc false
|
|
|
|
\\font_osf false
|
2015-11-11 20:48:20 +00:00
|
|
|
\\font_sf_scale 100 100
|
|
|
|
\\font_tt_scale 100 100
|
2016-06-04 17:46:40 +00:00
|
|
|
\\use_microtype 0
|
2009-05-16 23:53:32 +00:00
|
|
|
\\graphics default
|
2014-02-10 07:35:22 +00:00
|
|
|
\\default_output_format default
|
|
|
|
\\output_sync 0
|
|
|
|
\\bibtex_command default
|
|
|
|
\\index_command default
|
2009-05-16 23:53:32 +00:00
|
|
|
\\paperfontsize default
|
2009-10-19 00:01:01 +00:00
|
|
|
\\spacing single
|
2009-05-16 23:53:32 +00:00
|
|
|
\\use_hyperref false
|
|
|
|
\\papersize default
|
|
|
|
\\use_geometry true
|
2014-02-10 07:35:22 +00:00
|
|
|
\\use_package amsmath 1
|
|
|
|
\\use_package amssymb 1
|
|
|
|
\\use_package cancel 0
|
|
|
|
\\use_package esint 1
|
|
|
|
\\use_package mathdots 0
|
|
|
|
\\use_package mathtools 0
|
|
|
|
\\use_package mhchem 1
|
|
|
|
\\use_package stackrel 0
|
|
|
|
\\use_package stmaryrd 0
|
|
|
|
\\use_package undertilde 0
|
2009-05-16 23:53:32 +00:00
|
|
|
\\cite_engine basic
|
2014-02-10 07:35:22 +00:00
|
|
|
\\cite_engine_type default
|
|
|
|
\\biblio_style plain
|
2009-05-16 23:53:32 +00:00
|
|
|
\\use_bibtopic false
|
2014-02-10 07:35:22 +00:00
|
|
|
\\use_indices false
|
2009-05-16 23:53:32 +00:00
|
|
|
\\paperorientation portrait
|
2014-02-10 07:35:22 +00:00
|
|
|
\\suppress_date false
|
|
|
|
\\justification true
|
|
|
|
\\use_refstyle 0
|
|
|
|
\\index Index
|
|
|
|
\\shortcut idx
|
|
|
|
\\color #008000
|
|
|
|
\\end_index
|
2009-05-16 23:53:32 +00:00
|
|
|
\\leftmargin 2.5cm
|
|
|
|
\\topmargin 2cm
|
|
|
|
\\rightmargin 3cm
|
2014-02-10 07:35:22 +00:00
|
|
|
\\bottommargin 2.5cm
|
2009-05-16 23:53:32 +00:00
|
|
|
\\secnumdepth 3
|
|
|
|
\\tocdepth 3
|
|
|
|
\\paragraph_separation indent
|
2014-02-10 07:35:22 +00:00
|
|
|
\\paragraph_indentation default
|
2009-05-16 23:53:32 +00:00
|
|
|
\\quotes_language english
|
|
|
|
\\papercolumns 1
|
|
|
|
\\papersides 1
|
|
|
|
\\paperpagestyle default
|
|
|
|
\\tracking_changes false
|
|
|
|
\\output_changes false
|
2014-02-10 07:35:22 +00:00
|
|
|
\\html_math_output 0
|
|
|
|
\\html_css_as_file 0
|
|
|
|
\\html_be_strict false
|
2009-05-16 23:53:32 +00:00
|
|
|
\\end_header
|
|
|
|
|
|
|
|
\\begin_body
|
|
|
|
|
2014-02-10 07:35:22 +00:00
|
|
|
\\begin_layout Title
|
2015-11-11 20:48:20 +00:00
|
|
|
\\SpecialChar LyX
|
|
|
|
Functions (LFUNs)
|
2014-02-10 07:35:22 +00:00
|
|
|
\\end_layout
|
|
|
|
|
|
|
|
\\begin_layout Author
|
2015-11-11 20:48:20 +00:00
|
|
|
The \\SpecialChar LyX
|
|
|
|
Team
|
2014-02-10 07:35:22 +00:00
|
|
|
\\end_layout
|
|
|
|
|
2014-02-13 08:55:40 +00:00
|
|
|
"""
|
2009-05-16 23:53:32 +00:00
|
|
|
|
2016-06-04 17:40:53 +00:00
|
|
|
LFUNS_INTRO = u"""\\begin_layout Section*
|
2014-02-13 08:55:40 +00:00
|
|
|
About this manual
|
|
|
|
\\end_layout
|
2009-05-16 23:53:32 +00:00
|
|
|
|
2014-02-13 08:55:40 +00:00
|
|
|
\\begin_layout Standard
|
|
|
|
This manual documents the
|
|
|
|
\\begin_inset Quotes eld
|
|
|
|
\\end_inset
|
2009-05-16 23:53:32 +00:00
|
|
|
|
2014-02-13 08:55:40 +00:00
|
|
|
LyX Functions
|
|
|
|
\\begin_inset Quotes erd
|
|
|
|
\\end_inset
|
|
|
|
|
|
|
|
(abbreviated LFUNs).
|
2015-11-11 20:48:20 +00:00
|
|
|
These are commands that are used to make \\SpecialChar LyX
|
|
|
|
perform specific actions.
|
|
|
|
\\SpecialChar LyX
|
|
|
|
itself uses these functions internally, and every internal action is
|
2014-02-13 08:55:40 +00:00
|
|
|
bound to an LFUN.
|
2009-05-16 23:53:32 +00:00
|
|
|
\\end_layout
|
|
|
|
|
2014-02-13 08:55:40 +00:00
|
|
|
\\begin_layout Standard
|
|
|
|
LFUNs are also used in the files that define keyboard shortcuts, menu or
|
|
|
|
toolbar items.
|
2015-11-11 20:48:20 +00:00
|
|
|
So if you want to change\\SpecialChar breakableslash
|
2014-02-13 08:55:40 +00:00
|
|
|
customize the user interface, you need to deal
|
|
|
|
with LFUNs.
|
|
|
|
Furthermore, external programs can use LFUNs to communicate with and
|
|
|
|
\\begin_inset Quotes eld
|
2009-05-16 23:53:32 +00:00
|
|
|
\\end_inset
|
|
|
|
|
2014-02-13 08:55:40 +00:00
|
|
|
remote-control
|
|
|
|
\\begin_inset Quotes erd
|
|
|
|
\\end_inset
|
2009-05-16 23:53:32 +00:00
|
|
|
|
2015-11-11 20:48:20 +00:00
|
|
|
\\SpecialChar LyX
|
|
|
|
.
|
2014-02-13 08:55:40 +00:00
|
|
|
Finally, you can also issue LFUNs directly via the so called mini-buffer
|
|
|
|
which can be opened via
|
|
|
|
\\begin_inset Info
|
|
|
|
type "shortcuts"
|
|
|
|
arg "command-execute"
|
2009-05-16 23:53:32 +00:00
|
|
|
\\end_inset
|
|
|
|
|
2014-02-13 08:55:40 +00:00
|
|
|
.
|
|
|
|
\\end_layout
|
2009-05-16 23:53:32 +00:00
|
|
|
|
2014-02-13 08:55:40 +00:00
|
|
|
\\begin_layout Standard
|
|
|
|
In the following, all LFUNs are listed, categorized by function.
|
2009-05-16 23:53:32 +00:00
|
|
|
\\end_layout
|
2014-02-13 08:55:40 +00:00
|
|
|
|
2009-05-16 23:53:32 +00:00
|
|
|
"""
|
2014-02-13 08:55:40 +00:00
|
|
|
|
|
|
|
|
2016-06-04 17:40:53 +00:00
|
|
|
LFUNS_FOOTER = u"""\\end_body
|
2009-05-16 23:53:32 +00:00
|
|
|
\\end_document
|
|
|
|
"""
|
|
|
|
|
|
|
|
def parse_lfun(str):
|
|
|
|
"""Takes a comment block (str) and parses it for fields describing the LFUN. Returns a dict containing the fields."""
|
|
|
|
|
2014-02-13 08:55:40 +00:00
|
|
|
lfun = dict(action="", notion="", syntax="", params="", sample="", origin="")
|
2009-05-16 23:53:32 +00:00
|
|
|
field = ""
|
|
|
|
lines = str.splitlines()
|
|
|
|
# strip leading whitespace and * from the lines of the comment to get
|
|
|
|
# rid of unimportant characters
|
|
|
|
for i in range(0, len(lines)):
|
|
|
|
lines[i] = lines[i].strip(" *")
|
|
|
|
|
|
|
|
for i in range(0, len(lines) - 1):
|
|
|
|
# work out what field is being read if none of these is found, the line will be added
|
|
|
|
# to the last field edited
|
|
|
|
# since the field identifier is not included skip it out if it's found, otherwise skip
|
|
|
|
# nothing as an existing field is being added to
|
|
|
|
# if a field id is found, then its the first line of the field so set the pre_space to ""
|
|
|
|
# so that the first line isn't prespaced
|
2014-02-13 08:55:40 +00:00
|
|
|
if lines[i].startswith(LFUN_ACTION_ID):
|
2009-05-16 23:53:32 +00:00
|
|
|
field = "action"
|
|
|
|
pre_space = ""
|
|
|
|
skip = len(ID_DICT[field])
|
|
|
|
elif lines[i].startswith(LFUN_NOTION_ID):
|
|
|
|
field = "notion"
|
|
|
|
pre_space = ""
|
|
|
|
skip = len(ID_DICT[field])
|
|
|
|
elif lines[i].startswith(LFUN_SYNTAX_ID):
|
|
|
|
field = "syntax"
|
|
|
|
pre_space = ""
|
|
|
|
skip = len(ID_DICT[field])
|
|
|
|
elif lines[i].startswith(LFUN_PARAMS_ID):
|
|
|
|
field = "params"
|
|
|
|
pre_space = ""
|
|
|
|
skip = len(ID_DICT[field])
|
|
|
|
elif lines[i].startswith(LFUN_SAMPLE_ID):
|
|
|
|
field = "sample"
|
|
|
|
pre_space = ""
|
|
|
|
skip = len(ID_DICT[field])
|
|
|
|
elif lines[i].startswith(LFUN_ORIGIN_ID):
|
|
|
|
field = "origin"
|
|
|
|
pre_space = ""
|
|
|
|
skip = len(ID_DICT[field])
|
|
|
|
elif lines[i].startswith(LFUN_ENDVAR):
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
skip = 0
|
|
|
|
# if a manual line break was found last line, don't prespace this line
|
|
|
|
if i > 1 and lines[i-1].endswith("\\n"):
|
|
|
|
pre_space = ""
|
|
|
|
else:
|
|
|
|
pre_space = " "
|
|
|
|
|
|
|
|
# add the line to the field, processing it for \ characters and \n
|
|
|
|
# which, if occurring at the end of a line, must become a LYX_NEWLINE
|
|
|
|
line = lines[i][skip:]
|
|
|
|
|
|
|
|
# deal with \htmlonly
|
|
|
|
# TODO: convert chars found in htmlonly to unicode
|
|
|
|
start = line.find(HTMLONLY_START)
|
|
|
|
if start > 0:
|
|
|
|
# if removing the htmlonly element leaves a double space, go back one to remove it
|
|
|
|
if line[start-1] == " ":
|
|
|
|
start = start - 1
|
|
|
|
end = line.find(HTMLONLY_END)
|
|
|
|
if end > start:
|
|
|
|
end = line.find(HTMLONLY_END) + len(HTMLONLY_END)
|
|
|
|
line = line[:start] + line[end:]
|
|
|
|
#else:
|
|
|
|
# TODO: if HTMLONLY_END is not found, look on the next line
|
|
|
|
# TODO: in the current LyXAction.cpp there are no htmlonly fields which go over a line break
|
|
|
|
|
|
|
|
# deal with \ but leave \n if at the end of the line
|
|
|
|
slash_idx = line.find("\\")
|
|
|
|
while slash_idx >= 0:
|
|
|
|
if slash_idx < len(line)-2 \
|
|
|
|
or slash_idx == len(line)-1:
|
|
|
|
# true when the \ is not the last or second last char
|
|
|
|
# or when the slash is the last char of the line
|
|
|
|
|
|
|
|
# slash must be interpreted literaly so swap it for a LYX_BACKSLASH
|
|
|
|
line = line[:slash_idx] + LYX_BACKSLASH + line[slash_idx+1:]
|
|
|
|
# skip the index ahead beyond the added text
|
|
|
|
slash_idx = slash_idx + len(LYX_BACKSLASH)
|
|
|
|
elif line[slash_idx+1] != "n": # only evaluated if the line ends "\x" where 'x' != 'n'
|
|
|
|
line = line[:slash_idx] + LYX_BACKSLASH + line[slash_idx+1:]
|
|
|
|
# skip the index ahead beyond the added text
|
|
|
|
slash_idx = slash_idx + len(LYX_BACKSLASH)
|
|
|
|
# look for the next \
|
|
|
|
slash_idx = line.find("\\", slash_idx+1)
|
|
|
|
|
|
|
|
# \n at the end of lines will not be processed by the above while loop
|
|
|
|
# so sort those out now
|
|
|
|
# sometime lines end " \n" so chop the space if its there
|
|
|
|
if line.endswith(" \\n"):
|
|
|
|
line = line[:len(line)-3] + LYX_NEWLINE
|
|
|
|
elif line.endswith("\\n"):
|
|
|
|
line = line[:len(line)-2] + LYX_NEWLINE
|
|
|
|
|
|
|
|
# any references to other LFUNs need the # removing
|
|
|
|
# TODO: actually insert a cross-reference here
|
|
|
|
line = line.replace("#LFUN", "LFUN")
|
|
|
|
|
2009-05-17 00:04:10 +00:00
|
|
|
# handle the few #lyx:: cases
|
|
|
|
line = line.replace("#lyx::", "lyx::")
|
|
|
|
|
2009-05-16 23:53:32 +00:00
|
|
|
# the first line might not have a field in it in which
|
|
|
|
# case the variable field won't have a value, so check
|
|
|
|
# to avoid an error
|
|
|
|
if field != "":
|
|
|
|
lfun[field] = lfun[field] + pre_space + line
|
|
|
|
|
|
|
|
# TODO: sort out chopping lines of more that 80 chars in length
|
|
|
|
|
|
|
|
return lfun
|
|
|
|
|
|
|
|
def write_fields(file, lfun):
|
|
|
|
"""Writes the LFUN contained in the dict lfun to the file. Does not write a the file header or footer"""
|
|
|
|
# add lfun to LFUNs.lyx
|
2016-06-04 17:40:53 +00:00
|
|
|
file.write(u"\\begin_layout Subsection*\n")
|
2009-05-16 23:53:32 +00:00
|
|
|
file.write(lfun["name"] + "\n")
|
2016-06-04 17:40:53 +00:00
|
|
|
file.write(u"\\end_layout\n")
|
|
|
|
file.write(u"\n")
|
2009-05-16 23:53:32 +00:00
|
|
|
if lfun["action"] != "":
|
2016-06-04 17:40:53 +00:00
|
|
|
file.write(u"\\begin_layout Description\n")
|
2009-05-16 23:53:32 +00:00
|
|
|
file.write("Action " + lfun["action"] + "\n")
|
2016-06-04 17:40:53 +00:00
|
|
|
file.write(u"\\end_layout\n")
|
|
|
|
file.write(u"\n")
|
2009-05-16 23:53:32 +00:00
|
|
|
if lfun["notion"] != "":
|
2016-06-04 17:40:53 +00:00
|
|
|
file.write(u"\\begin_layout Description\n")
|
2009-05-16 23:53:32 +00:00
|
|
|
file.write("Notion " + lfun["notion"] + "\n")
|
2016-06-04 17:40:53 +00:00
|
|
|
file.write(u"\\end_layout\n")
|
|
|
|
file.write(u"\n")
|
2009-05-16 23:53:32 +00:00
|
|
|
if lfun["syntax"] != "":
|
2016-06-04 17:40:53 +00:00
|
|
|
file.write(u"\\begin_layout Description\n")
|
2009-05-16 23:53:32 +00:00
|
|
|
file.write("Syntax " + lfun["syntax"] + "\n")
|
2016-06-04 17:40:53 +00:00
|
|
|
file.write(u"\\end_layout\n")
|
|
|
|
file.write(u"\n")
|
2009-05-16 23:53:32 +00:00
|
|
|
if lfun["params"] != "":
|
2016-06-04 17:40:53 +00:00
|
|
|
file.write(u"\\begin_layout Description\n")
|
2009-05-16 23:53:32 +00:00
|
|
|
file.write("Params " + lfun["params"] + "\n")
|
2016-06-04 17:40:53 +00:00
|
|
|
file.write(u"\\end_layout\n")
|
|
|
|
file.write(u"\n")
|
2009-05-16 23:53:32 +00:00
|
|
|
if lfun["sample"] != "":
|
2016-06-04 17:40:53 +00:00
|
|
|
file.write(u"\\begin_layout Description\n")
|
2009-05-16 23:53:32 +00:00
|
|
|
file.write("Sample " + lfun["sample"] + "\n")
|
2016-06-04 17:40:53 +00:00
|
|
|
file.write(u"\\end_layout\n")
|
|
|
|
file.write(u"\n")
|
2009-05-16 23:53:32 +00:00
|
|
|
if lfun["origin"] != "":
|
2016-06-04 17:40:53 +00:00
|
|
|
file.write(u"\\begin_layout Description\n")
|
2009-05-16 23:53:32 +00:00
|
|
|
file.write("Origin " + lfun["origin"] + "\n")
|
2016-06-04 17:40:53 +00:00
|
|
|
file.write(u"\\end_layout\n")
|
|
|
|
file.write(u"\n")
|
2014-02-13 08:55:40 +00:00
|
|
|
|
|
|
|
def write_sections(file,lfuns):
|
|
|
|
"""Write sections of LFUNs"""
|
|
|
|
sections = ["Layout", "Edit", "Math", "Buffer", "System", "Hidden"]
|
|
|
|
section_headings = {
|
2016-06-04 17:40:53 +00:00
|
|
|
"Layout": u"Layout Functions (Font, Layout and Textclass related)",
|
|
|
|
"Edit": u"Editing Functions (Cursor and Mouse Movement, Copy/Paste etc.)",
|
|
|
|
"Math": u"Math Editor Functions",
|
|
|
|
"Buffer": u"Buffer Fuctions (File and Window related)",
|
|
|
|
"System": u"System Functions (Preferences, LyX Server etc.)",
|
|
|
|
"Hidden": u"Hidden Functions (not listed for configuration)"
|
2014-02-13 08:55:40 +00:00
|
|
|
}
|
|
|
|
# write the lfuns to the file
|
|
|
|
for val in sections:
|
2016-06-04 17:40:53 +00:00
|
|
|
file.write(u"\\begin_layout Section\n")
|
2014-02-13 08:55:40 +00:00
|
|
|
file.write(section_headings[val] + "\n")
|
2016-06-04 17:40:53 +00:00
|
|
|
file.write(u"\\end_layout\n")
|
|
|
|
file.write(u"\n")
|
2014-02-13 08:55:40 +00:00
|
|
|
for lf in lfuns:
|
|
|
|
if lf["type"] == val:
|
|
|
|
write_fields(file, lf)
|
2009-05-16 23:53:32 +00:00
|
|
|
|
|
|
|
def main(argv):
|
2014-02-13 12:26:18 +00:00
|
|
|
# parse command line arguments
|
2009-05-16 23:53:32 +00:00
|
|
|
script_path, script_name = os.path.split(argv[0])
|
2009-05-17 00:34:29 +00:00
|
|
|
if len(argv) < 2:
|
2009-05-16 23:53:32 +00:00
|
|
|
error(usage(script_name))
|
|
|
|
# input file
|
|
|
|
lyxaction_path = argv[1]
|
2014-02-13 12:26:18 +00:00
|
|
|
if not os.path.isfile(lyxaction_path):
|
|
|
|
error(script_name + ": %s is not a valid path" % lyxaction_path)
|
2009-05-16 23:53:32 +00:00
|
|
|
|
|
|
|
# output file
|
2009-05-17 00:34:29 +00:00
|
|
|
if len(argv) == 3:
|
|
|
|
lfuns_path = argv[2]
|
|
|
|
if os.path.isdir(lfuns_path):
|
|
|
|
lfuns_path = lfuns_path + "LFUNs.lyx"
|
|
|
|
elif os.path.exists(lfuns_path):
|
|
|
|
error(script_name + ": %s already exists, delete it and rerun the script" % lfuns_path)
|
2016-06-04 17:40:53 +00:00
|
|
|
lfuns_file = io.open(lfuns_path, 'w', encoding='utf_8')
|
2009-05-17 00:34:29 +00:00
|
|
|
else:
|
|
|
|
lfuns_file = sys.stdout
|
2009-05-16 23:53:32 +00:00
|
|
|
|
2009-05-17 00:34:29 +00:00
|
|
|
sys.stderr.write(script_name + ": Start processing " + argv[1] + '\n')
|
2009-05-16 23:53:32 +00:00
|
|
|
# Read the input file and write the output file
|
2016-06-04 17:40:53 +00:00
|
|
|
lyxaction_file = io.open(lyxaction_path, 'r', encoding='utf_8')
|
2014-02-13 08:55:40 +00:00
|
|
|
|
2009-05-16 23:53:32 +00:00
|
|
|
lyxaction_text = lyxaction_file.read()
|
2014-02-13 08:55:40 +00:00
|
|
|
|
2009-05-16 23:53:32 +00:00
|
|
|
lfuns_file.write(LFUNS_HEADER)
|
2014-02-13 08:55:40 +00:00
|
|
|
|
|
|
|
# An introductory section
|
|
|
|
lfuns_file.write(LFUNS_INTRO)
|
|
|
|
|
|
|
|
# seek to the important bit of LyXAction.cpp
|
2009-05-16 23:53:32 +00:00
|
|
|
try:
|
|
|
|
start = lyxaction_text.index("ev_item const items[] = {")
|
|
|
|
except ValueError:
|
|
|
|
lyxaction_file.close()
|
|
|
|
lfuns_file.close()
|
|
|
|
error(script_name + ": LFUNs not found in " + lyxaction_file)
|
|
|
|
|
|
|
|
done = count = 0
|
|
|
|
|
2014-02-10 07:35:22 +00:00
|
|
|
lfun_list_unsorted = []
|
|
|
|
|
2009-05-16 23:53:32 +00:00
|
|
|
while done == 0:
|
|
|
|
# look for a doxygen comment
|
|
|
|
start = lyxaction_text.find(DOXYGEN_START, start)
|
|
|
|
end = lyxaction_text.find(DOXYGEN_END, start) + len(DOXYGEN_END)
|
2014-02-13 08:55:40 +00:00
|
|
|
name = ""
|
|
|
|
atype = ""
|
|
|
|
snippet = lyxaction_text[start:end]
|
|
|
|
defline = snippet.replace("\n", "")
|
|
|
|
match = re.match(r'.*\s*\{\s*(.+),\s*"(.*)",\s*([\w\|\s]+),\s*(\w+)\s*\},.*$', defline)
|
|
|
|
if match:
|
|
|
|
name = match.group(2)
|
|
|
|
atype = match.group(4)
|
2009-05-16 23:53:32 +00:00
|
|
|
# parse the lfun if it is found
|
|
|
|
if start > 0:
|
2014-02-13 08:55:40 +00:00
|
|
|
if name:
|
|
|
|
count = count + 1
|
|
|
|
lfun = parse_lfun(snippet)
|
|
|
|
lfun["name"] = name
|
|
|
|
lfun["type"] = atype
|
|
|
|
# save the lfun (we sort it before writing)
|
|
|
|
lfun_list_unsorted.append(lfun)
|
2014-02-10 07:35:22 +00:00
|
|
|
# get the next one
|
2009-05-16 23:53:32 +00:00
|
|
|
start = end
|
|
|
|
else:
|
|
|
|
# if no more lfuns are found, EOF reached
|
|
|
|
done = 1
|
2014-02-10 07:35:22 +00:00
|
|
|
|
|
|
|
lfun_list = sorted(lfun_list_unsorted, key=lambda k: k['name'])
|
2009-05-16 23:53:32 +00:00
|
|
|
|
2014-02-10 07:35:22 +00:00
|
|
|
# write the lfuns to the file
|
2014-02-13 08:55:40 +00:00
|
|
|
write_sections(lfuns_file, lfun_list)
|
2014-02-10 07:35:22 +00:00
|
|
|
|
|
|
|
sys.stderr.write(script_name + ": Created documentation for " + str(count) + " LFUNs\n")
|
|
|
|
|
2009-05-16 23:53:32 +00:00
|
|
|
# write the last part of LFUNs.lyx
|
|
|
|
lfuns_file.write(LFUNS_FOOTER)
|
|
|
|
|
|
|
|
lyxaction_file.close()
|
|
|
|
lfuns_file.close()
|
|
|
|
|
2009-05-17 00:34:29 +00:00
|
|
|
sys.stderr.write(script_name + ": Finished\n")
|
2009-05-16 23:53:32 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main(sys.argv)
|