manual: script handles inlisting text

This commit is contained in:
Milanka Ringwald 2015-04-26 00:22:14 +02:00
parent 5fe5b179f5
commit 5b39d92507
2 changed files with 70 additions and 40 deletions

View File

@ -8,17 +8,17 @@ list_of_groups = ["Hello World", "GAP", "SDP Queries", "SPP Server", "BNEP/PAN",
# Defines which examples belong to a group. Example is defined as [example file, example title].
list_of_examples = {
"Hello World" : [["led_counter"]],
"GAP" : [["gap_inquiry"]],
"SDP Queries" :[["sdp_general_query"],
# "Hello World" : [["led_counter"]],
# "GAP" : [["gap_inquiry"]],
"SDP Queries" :[#["sdp_general_query"],
["sdp_bnep_query"]
],
"SPP Server" : [["spp_counter"],
["spp_flowcontrol"]],
"BNEP/PAN" : [["panu_demo"]],
"Low Energy" : [["gatt_browser"],
["le_counter"]],
"Dual Mode" : [["spp_and_le_counter"]],
# "SPP Server" : [["spp_counter"],
# ["spp_flowcontrol"]],
# "BNEP/PAN" : [["panu_demo"]],
# "Low Energy" : [["gatt_browser"],
# ["le_counter"]],
# "Dual Mode" : [["spp_and_le_counter"]],
}
lst_header = """
@ -100,6 +100,9 @@ def latexText(text, ref_prefix):
def isEmptyCommentLine(line):
return re.match('(\s*\*\s*)\n',line)
def isCommentLine(line):
return re.match('(\s*\*\s*).*',line)
def isEndOfComment(line):
return re.match('\s*\*/.*', line)
@ -145,12 +148,27 @@ class State:
SearchItemizeEnd = 5
ReachedExampleEnd = 6
text_block = ''
itemize_block = ''
def writeTextBlock(aout, lstStarted):
global text_block
if text_block and not lstStarted:
aout.write(text_block)
text_block = ''
def writeItemizeBlock(aout, lstStarted):
global itemize_block
if itemize_block and not lstStarted:
aout.write(itemize_block + "\n\end{itemize}\n")
itemize_block = ''
def writeListings(aout, infile_name, ref_prefix):
global text_block, itemize_block
itemText = None
state = State.SearchExampleStart
code_in_listing = ""
text_block = None
itemize_block = None
skip_code = 0
with open(infile_name, 'rb') as fin:
for line in fin:
@ -178,40 +196,45 @@ def writeListings(aout, infile_name, ref_prefix):
continue
if isTextTag(line):
text_block = processTextLine(line, ref_prefix)
text_block = text_block + "\n\n" + processTextLine(line, ref_prefix)
continue
skip_code = 0
lstStarted = state != State.SearchListingStart
if text_block or itemize_block:
if isEndOfComment(line) or isEmptyCommentLine(line):
skip_code = 1
if itemize_block:
# finish itemize
aout.write(itemize_block + "\n\end{itemize}\n")
itemize_block = None
writeItemizeBlock(aout, lstStarted)
else:
if isEmptyCommentLine(line):
text_block = text_block + "\n\n"
else:
# finish text
aout.write(text_block)
text_block = None
writeTextBlock(aout, lstStarted)
else:
if isNewItem(line) and not itemize_block:
skip_code = 1
# finish text, start itemize
aout.write(text_block)
text_block = None
writeTextBlock(aout, lstStarted)
itemize_block = "\n \\begin{itemize}"
continue
if itemize_block:
skip_code = 1
itemize_block = itemize_block + processTextLine(line, ref_prefix)
else:
elif isCommentLine(line):
# append text
skip_code = 1
text_block = text_block + processTextLine(line, ref_prefix)
continue
else:
skip_code = 0
#continue
if state == State.SearchListingStart:
parts = re.match('.*(LISTING_START)\((.*)\):\s*(.*\s*)(\*/).*',line)
parts = re.match('.*(LISTING_START)\((.*)\):\s*(.*)(\s+\*/).*',line)
if parts:
lst_lable = parts.group(2)
@ -232,12 +255,15 @@ def writeListings(aout, infile_name, ref_prefix):
code_in_listing = ""
aout.write(listing_ending)
state = State.SearchListingStart
writeItemizeBlock(aout, 0)
writeTextBlock(aout, 0)
elif parts_pause:
code_in_listing = code_in_listing + "...\n"
state = State.SearchListingResume
elif not end_comment_parts:
# aout.write(line)
code_in_listing = code_in_listing + line.replace(" ", " ")
if not skip_code:
code_in_listing = code_in_listing + line.replace(" ", " ")
continue
if state == State.SearchListingResume:
@ -250,6 +276,8 @@ def writeListings(aout, infile_name, ref_prefix):
if parts:
if state != State.SearchListingStart:
print "Formating error detected"
writeItemizeBlock(aout, 0)
writeTextBlock(aout, 0)
state = State.ReachedExampleEnd
print "Reached end of the example"

View File

@ -160,19 +160,11 @@ char * get_string_from_data_element(uint8_t * element){
* value, see Listing HandleSDPQUeryResult. Here, we show how to parse the
* Service Class ID List and Protocol Descriptor List, as they contain
* the BNEP Protocol UUID and L2CAP PSM respectively.
*
* The Service Class ID List is a Data Element Sequence (DES) of UUIDs.
* The BNEP PAN protocol UUID is within this list.
*
* The Protocol Descriptor List is DES
* which contains one DES for each protocol. For PAN serivces, it contains
* a DES with the L2CAP Protocol UUID and a PSM,
* and another DES with the BNEP UUID and the the BNEP version.
*/
/* LISTING_START(HandleSDPQUeryResult): Extracting BNEP Prototocol UUID and L2CAP PSM. */
/* LISTING_START(HandleSDPQUeryResult): Extracting BNEP Prototocol UUID and L2CAP PSM */
static void handle_sdp_client_query_result(sdp_query_event_t * event){
/* LISTING_PAUSE */
/* LISTING_PAUSE */
sdp_query_attribute_value_event_t * ve;
sdp_query_complete_event_t * ce;
des_iterator_t des_list_it;
@ -194,7 +186,11 @@ static void handle_sdp_client_query_result(sdp_query_event_t * event){
attribute_value[ve->data_offset] = ve->data;
if ((uint16_t)(ve->data_offset+1) == ve->attribute_length){
/* LISTING_RESUME */
/* LISTING_RESUME */
/* @text The Service Class ID List is a Data Element Sequence (DES) of UUIDs.
* The BNEP PAN protocol UUID is within this list.
*/
switch(ve->attribute_id){
// 0x0001 "Service Class ID List"
case SDP_ServiceClassIDList:
@ -214,7 +210,7 @@ static void handle_sdp_client_query_result(sdp_query_event_t * event){
}
}
break;
/* LISTING_PAUSE */
/* LISTING_PAUSE */
// 0x0100 "Service Name"
case 0x0100:
// 0x0101 "Service Description"
@ -223,7 +219,13 @@ static void handle_sdp_client_query_result(sdp_query_event_t * event){
printf(" ** Attribute 0x%04x: %s\n", ve->attribute_id, str);
free(str);
break;
/* LISTING_RESUME */
/* LISTING_RESUME */
/* @text The Protocol Descriptor List is DES
* which contains one DES for each protocol. For PAN serivces, it contains
* a DES with the L2CAP Protocol UUID and a PSM,
* and another DES with the BNEP UUID and the the BNEP version.
*/
case SDP_ProtocolDescriptorList:{
printf(" ** Attribute 0x%04x: ", ve->attribute_id);
@ -255,7 +257,7 @@ static void handle_sdp_client_query_result(sdp_query_event_t * event){
printf("l2cap_psm 0x%04x, bnep_version 0x%04x\n", l2cap_psm, bnep_version);
}
break;
/* LISTING_PAUSE */
/* LISTING_PAUSE */
default:
break;
}
@ -266,7 +268,7 @@ static void handle_sdp_client_query_result(sdp_query_event_t * event){
printf("General query done with status %d.\n\n", ce->status);
break;
}
/* LISTING_RESUME */
/* LISTING_RESUME */
}
/* LISTING_END */