mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-07 04:23:37 +00:00
manual: fix script
This commit is contained in:
parent
f2c3367255
commit
cf18d7621d
@ -8,6 +8,7 @@ example:
|
|||||||
./update_listings.py -s
|
./update_listings.py -s
|
||||||
subl examples.tex
|
subl examples.tex
|
||||||
pdflatex examples.tex
|
pdflatex examples.tex
|
||||||
|
pdflatex examples.tex
|
||||||
open examples.pdf
|
open examples.pdf
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
@ -11,7 +11,7 @@ list_of_examples = {
|
|||||||
"Hello World" : [["led_counter"]],
|
"Hello World" : [["led_counter"]],
|
||||||
"GAP" : [["gap_inquiry"]],
|
"GAP" : [["gap_inquiry"]],
|
||||||
"SDP Queries" :[["sdp_general_query"],
|
"SDP Queries" :[["sdp_general_query"],
|
||||||
# ["sdp_bnep_query"]
|
["sdp_bnep_query"]
|
||||||
],
|
],
|
||||||
"SPP Server" : [["spp_counter"],
|
"SPP Server" : [["spp_counter"],
|
||||||
["spp_flowcontrol"]],
|
["spp_flowcontrol"]],
|
||||||
@ -64,7 +64,7 @@ example_subsection = """
|
|||||||
|
|
||||||
listing_start = """
|
listing_start = """
|
||||||
$ $
|
$ $
|
||||||
\\begin{lstlisting}[caption= LISTING_CAPTION., label=listing:LISTING_LABLE]
|
\\begin{lstlisting}[caption= LISTING_CAPTION., label=listing:FILE_NAME:LISTING_LABLE]
|
||||||
"""
|
"""
|
||||||
|
|
||||||
listing_ending = """\end{lstlisting}
|
listing_ending = """\end{lstlisting}
|
||||||
@ -75,17 +75,20 @@ def replacePlaceholder(template, title, lable):
|
|||||||
snippet = template.replace("API_TITLE", title).replace("API_LABLE", lable)
|
snippet = template.replace("API_TITLE", title).replace("API_LABLE", lable)
|
||||||
return snippet
|
return snippet
|
||||||
|
|
||||||
def latexText(text):
|
def latexText(text, ref_prefix):
|
||||||
if not text:
|
if not text:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
brief = text.replace("_","\_")
|
brief = text.replace("_","\_")
|
||||||
|
# TODO: restore paths
|
||||||
|
|
||||||
brief = brief.replace(" in the BTstack manual","")
|
brief = brief.replace(" in the BTstack manual","")
|
||||||
|
|
||||||
refs = re.match('.*(Listing\s*)(\w*).*',brief)
|
refs = re.match('.*Listing\s*\s*(\w+)(?:.|\s).*',brief)
|
||||||
if refs:
|
if refs:
|
||||||
brief = brief.replace(refs.group(2), "\\ref{listing:"+refs.group(2)+"}")
|
brief = brief.replace(refs.group(1), "\\ref{listing:"+ref_prefix+":" + refs.group(1)+"}")
|
||||||
refs = re.match('.*(Section\s*)(\w*).*',brief)
|
|
||||||
|
refs = re.match('.*(Section\s*)(\w*).*',brief, re.I)
|
||||||
if refs:
|
if refs:
|
||||||
brief = brief.replace(refs.group(2), "\\ref{section:"+refs.group(2)+"}")
|
brief = brief.replace(refs.group(2), "\\ref{section:"+refs.group(2)+"}")
|
||||||
|
|
||||||
@ -106,18 +109,18 @@ def isTextTag(line):
|
|||||||
def isItemizeTag(line):
|
def isItemizeTag(line):
|
||||||
return re.match("(\s+\*\s+)(-\s)(.*)", line)
|
return re.match("(\s+\*\s+)(-\s)(.*)", line)
|
||||||
|
|
||||||
def processTextLine(line):
|
def processTextLine(line, ref_prefix):
|
||||||
if isTextTag(line):
|
if isTextTag(line):
|
||||||
text_line_parts = re.match(".*(@text)(.*)", line)
|
text_line_parts = re.match(".*(@text)(.*)", line)
|
||||||
return " " + latexText(text_line_parts.group(2))
|
return " " + latexText(text_line_parts.group(2), ref_prefix)
|
||||||
|
|
||||||
if isItemizeTag(line):
|
if isItemizeTag(line):
|
||||||
text_line_parts = re.match("(\s*\*\s*\-\s*)(.*)", line)
|
text_line_parts = re.match("(\s*\*\s*\-\s*)(.*)", line)
|
||||||
return "\n \item " + latexText(text_line_parts.group(2))
|
return "\n \item " + latexText(text_line_parts.group(2), ref_prefix)
|
||||||
|
|
||||||
text_line_parts = re.match("(\s+\*\s+)(.*)", line)
|
text_line_parts = re.match("(\s+\*\s+)(.*)", line)
|
||||||
if text_line_parts:
|
if text_line_parts:
|
||||||
return " " + latexText(text_line_parts.group(2))
|
return " " + latexText(text_line_parts.group(2), ref_prefix)
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def getExampleTitle(example_path):
|
def getExampleTitle(example_path):
|
||||||
@ -126,7 +129,7 @@ def getExampleTitle(example_path):
|
|||||||
for line in fin:
|
for line in fin:
|
||||||
parts = re.match('.*(EXAMPLE_START)\((.*)\):\s*(.*)(\*/)?\n',line)
|
parts = re.match('.*(EXAMPLE_START)\((.*)\):\s*(.*)(\*/)?\n',line)
|
||||||
if parts:
|
if parts:
|
||||||
example_title = latexText(parts.group(3))
|
example_title = parts.group(3).replace("_","\_")
|
||||||
continue
|
continue
|
||||||
return example_title
|
return example_title
|
||||||
|
|
||||||
@ -139,7 +142,7 @@ class State:
|
|||||||
SearchItemizeEnd = 5
|
SearchItemizeEnd = 5
|
||||||
ReachedExampleEnd = 6
|
ReachedExampleEnd = 6
|
||||||
|
|
||||||
def writeListings(aout, infile_name):
|
def writeListings(aout, infile_name, ref_prefix):
|
||||||
itemText = None
|
itemText = None
|
||||||
state = State.SearchExampleStart
|
state = State.SearchExampleStart
|
||||||
code_in_listing = ""
|
code_in_listing = ""
|
||||||
@ -152,8 +155,8 @@ def writeListings(aout, infile_name):
|
|||||||
parts = re.match('.*(EXAMPLE_START)\((.*)\):\s*(.*)(\*/)?\n',line)
|
parts = re.match('.*(EXAMPLE_START)\((.*)\):\s*(.*)(\*/)?\n',line)
|
||||||
if parts:
|
if parts:
|
||||||
lable = parts.group(2)
|
lable = parts.group(2)
|
||||||
title = latexText(parts.group(2))
|
title = latexText(parts.group(2), ref_prefix)
|
||||||
desc = latexText(parts.group(3))
|
desc = latexText(parts.group(3), ref_prefix)
|
||||||
aout.write(example_section.replace("EXAMPLE_TITLE", title).replace("EXAMPLE_DESC", desc).replace("EXAMPLE_LABLE", lable))
|
aout.write(example_section.replace("EXAMPLE_TITLE", title).replace("EXAMPLE_DESC", desc).replace("EXAMPLE_LABLE", lable))
|
||||||
state = State.SearchListingStart
|
state = State.SearchListingStart
|
||||||
continue
|
continue
|
||||||
@ -172,26 +175,35 @@ def writeListings(aout, infile_name):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
if isTextTag(line):
|
if isTextTag(line):
|
||||||
text_block = processTextLine(line)
|
text_block = processTextLine(line, ref_prefix)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if text_block:
|
if text_block or itemize_block:
|
||||||
if isEndOfComment(line):
|
if isEndOfComment(line) or isEmptyCommentLine(line):
|
||||||
if itemize_block:
|
if itemize_block:
|
||||||
|
# finish itemize
|
||||||
aout.write(itemize_block + "\n\end{itemize}\n")
|
aout.write(itemize_block + "\n\end{itemize}\n")
|
||||||
itemize_block = None
|
itemize_block = None
|
||||||
else:
|
else:
|
||||||
|
if isEmptyCommentLine(line):
|
||||||
|
text_block = text_block + "\n"
|
||||||
|
else:
|
||||||
|
# finish text
|
||||||
|
aout.write(text_block)
|
||||||
|
text_block = None
|
||||||
|
|
||||||
|
else:
|
||||||
|
if isNewItem(line) and not itemize_block:
|
||||||
|
# finish text, start itemize
|
||||||
aout.write(text_block)
|
aout.write(text_block)
|
||||||
text_block = None
|
text_block = None
|
||||||
else:
|
itemize_block = "\n \\begin{itemize}"
|
||||||
if isNewItem(line):
|
|
||||||
if not itemize_block:
|
|
||||||
itemize_block = "\n \\begin{itemize}"
|
|
||||||
|
|
||||||
if itemize_block:
|
if itemize_block:
|
||||||
itemize_block = itemize_block + processTextLine(line)
|
itemize_block = itemize_block + processTextLine(line, ref_prefix)
|
||||||
else:
|
else:
|
||||||
text_block = text_block + processTextLine(line)
|
# append text
|
||||||
|
text_block = text_block + processTextLine(line, ref_prefix)
|
||||||
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -200,8 +212,8 @@ def writeListings(aout, infile_name):
|
|||||||
|
|
||||||
if parts:
|
if parts:
|
||||||
lst_lable = parts.group(2)
|
lst_lable = parts.group(2)
|
||||||
lst_caption = latexText(parts.group(3))
|
lst_caption = latexText(parts.group(3), ref_prefix)
|
||||||
listing = listing_start.replace("LISTING_CAPTION", lst_caption).replace("LISTING_LABLE", lst_lable)
|
listing = listing_start.replace("LISTING_CAPTION", lst_caption).replace("FILE_NAME", ref_prefix).replace("LISTING_LABLE", lst_lable)
|
||||||
if listing:
|
if listing:
|
||||||
aout.write("\n" + listing)
|
aout.write("\n" + listing)
|
||||||
state = State.SearchListingEnd
|
state = State.SearchListingEnd
|
||||||
@ -243,6 +255,7 @@ def writeListings(aout, infile_name):
|
|||||||
def processExamples(examples_folder, standalone, examples_ofile):
|
def processExamples(examples_folder, standalone, examples_ofile):
|
||||||
with open(examples_ofile, 'w') as aout:
|
with open(examples_ofile, 'w') as aout:
|
||||||
for group_title in list_of_groups:
|
for group_title in list_of_groups:
|
||||||
|
if not list_of_examples.has_key(group_title): continue
|
||||||
examples = list_of_examples[group_title]
|
examples = list_of_examples[group_title]
|
||||||
for example in examples:
|
for example in examples:
|
||||||
example_path = examples_folder + example[0] + ".c"
|
example_path = examples_folder + example[0] + ".c"
|
||||||
@ -256,7 +269,9 @@ def processExamples(examples_folder, standalone, examples_ofile):
|
|||||||
aout.write("\n \\begin{itemize}\n");
|
aout.write("\n \\begin{itemize}\n");
|
||||||
|
|
||||||
for group_title in list_of_groups:
|
for group_title in list_of_groups:
|
||||||
|
if not list_of_examples.has_key(group_title): continue
|
||||||
examples = list_of_examples[group_title]
|
examples = list_of_examples[group_title]
|
||||||
|
|
||||||
group_title = group_title + " example"
|
group_title = group_title + " example"
|
||||||
if len(examples) > 1:
|
if len(examples) > 1:
|
||||||
group_title = group_title + "s"
|
group_title = group_title + "s"
|
||||||
@ -265,18 +280,20 @@ def processExamples(examples_folder, standalone, examples_ofile):
|
|||||||
aout.write(" \item " + group_title + "\n");
|
aout.write(" \item " + group_title + "\n");
|
||||||
aout.write(" \\begin{itemize}\n");
|
aout.write(" \\begin{itemize}\n");
|
||||||
for example in examples:
|
for example in examples:
|
||||||
lable = example[0]
|
ref_prefix = example[0]
|
||||||
title = latexText(example[0])
|
title = latexText(example[0], ref_prefix)
|
||||||
desc = latexText(example[1])
|
desc = latexText(example[1], ref_prefix)
|
||||||
aout.write(example_item.replace("EXAMPLE_TITLE", title).replace("EXAMPLE_DESC", desc).replace("EXAMPLE_LABLE", lable))
|
aout.write(example_item.replace("EXAMPLE_TITLE", title).replace("EXAMPLE_DESC", desc).replace("EXAMPLE_LABLE", ref_prefix))
|
||||||
aout.write(" \\end{itemize}\n")
|
aout.write(" \\end{itemize}\n")
|
||||||
aout.write("\\end{itemize}\n")
|
aout.write("\\end{itemize}\n")
|
||||||
|
|
||||||
for group_title in list_of_groups:
|
for group_title in list_of_groups:
|
||||||
|
if not list_of_examples.has_key(group_title): continue
|
||||||
examples = list_of_examples[group_title]
|
examples = list_of_examples[group_title]
|
||||||
|
|
||||||
for example in examples:
|
for example in examples:
|
||||||
file_name = examples_folder + example[0] + ".c"
|
file_name = examples_folder + example[0] + ".c"
|
||||||
writeListings(aout, file_name)
|
writeListings(aout, file_name, example[0])
|
||||||
|
|
||||||
if standalone:
|
if standalone:
|
||||||
aout.write(document_end)
|
aout.write(document_end)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user