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]. # Defines which examples belong to a group. Example is defined as [example file, example title].
list_of_examples = { 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"]],
"BNEP/PAN" : [["panu_demo"]], # "BNEP/PAN" : [["panu_demo"]],
"Low Energy" : [["gatt_browser"], # "Low Energy" : [["gatt_browser"],
["le_counter"]], # ["le_counter"]],
"Dual Mode" : [["spp_and_le_counter"]], # "Dual Mode" : [["spp_and_le_counter"]],
} }
lst_header = """ lst_header = """
@ -100,6 +100,9 @@ def latexText(text, ref_prefix):
def isEmptyCommentLine(line): def isEmptyCommentLine(line):
return re.match('(\s*\*\s*)\n',line) return re.match('(\s*\*\s*)\n',line)
def isCommentLine(line):
return re.match('(\s*\*\s*).*',line)
def isEndOfComment(line): def isEndOfComment(line):
return re.match('\s*\*/.*', line) return re.match('\s*\*/.*', line)
@ -145,12 +148,27 @@ class State:
SearchItemizeEnd = 5 SearchItemizeEnd = 5
ReachedExampleEnd = 6 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): def writeListings(aout, infile_name, ref_prefix):
global text_block, itemize_block
itemText = None itemText = None
state = State.SearchExampleStart state = State.SearchExampleStart
code_in_listing = "" code_in_listing = ""
text_block = None skip_code = 0
itemize_block = None
with open(infile_name, 'rb') as fin: with open(infile_name, 'rb') as fin:
for line in fin: for line in fin:
@ -178,40 +196,45 @@ def writeListings(aout, infile_name, ref_prefix):
continue continue
if isTextTag(line): if isTextTag(line):
text_block = processTextLine(line, ref_prefix) text_block = text_block + "\n\n" + processTextLine(line, ref_prefix)
continue continue
skip_code = 0
lstStarted = state != State.SearchListingStart
if text_block or itemize_block: if text_block or itemize_block:
if isEndOfComment(line) or isEmptyCommentLine(line): if isEndOfComment(line) or isEmptyCommentLine(line):
skip_code = 1
if itemize_block: if itemize_block:
# finish itemize # finish itemize
aout.write(itemize_block + "\n\end{itemize}\n") writeItemizeBlock(aout, lstStarted)
itemize_block = None
else: else:
if isEmptyCommentLine(line): if isEmptyCommentLine(line):
text_block = text_block + "\n\n" text_block = text_block + "\n\n"
else: else:
# finish text writeTextBlock(aout, lstStarted)
aout.write(text_block)
text_block = None
else: else:
if isNewItem(line) and not itemize_block: if isNewItem(line) and not itemize_block:
skip_code = 1
# finish text, start itemize # finish text, start itemize
aout.write(text_block) writeTextBlock(aout, lstStarted)
text_block = None
itemize_block = "\n \\begin{itemize}" itemize_block = "\n \\begin{itemize}"
continue
if itemize_block: if itemize_block:
skip_code = 1
itemize_block = itemize_block + processTextLine(line, ref_prefix) itemize_block = itemize_block + processTextLine(line, ref_prefix)
else: elif isCommentLine(line):
# append text # append text
skip_code = 1
text_block = text_block + processTextLine(line, ref_prefix) text_block = text_block + processTextLine(line, ref_prefix)
else:
continue skip_code = 0
#continue
if state == State.SearchListingStart: if state == State.SearchListingStart:
parts = re.match('.*(LISTING_START)\((.*)\):\s*(.*\s*)(\*/).*',line) parts = re.match('.*(LISTING_START)\((.*)\):\s*(.*)(\s+\*/).*',line)
if parts: if parts:
lst_lable = parts.group(2) lst_lable = parts.group(2)
@ -232,12 +255,15 @@ def writeListings(aout, infile_name, ref_prefix):
code_in_listing = "" code_in_listing = ""
aout.write(listing_ending) aout.write(listing_ending)
state = State.SearchListingStart state = State.SearchListingStart
writeItemizeBlock(aout, 0)
writeTextBlock(aout, 0)
elif parts_pause: elif parts_pause:
code_in_listing = code_in_listing + "...\n" code_in_listing = code_in_listing + "...\n"
state = State.SearchListingResume state = State.SearchListingResume
elif not end_comment_parts: elif not end_comment_parts:
# aout.write(line) # aout.write(line)
code_in_listing = code_in_listing + line.replace(" ", " ") if not skip_code:
code_in_listing = code_in_listing + line.replace(" ", " ")
continue continue
if state == State.SearchListingResume: if state == State.SearchListingResume:
@ -250,6 +276,8 @@ def writeListings(aout, infile_name, ref_prefix):
if parts: if parts:
if state != State.SearchListingStart: if state != State.SearchListingStart:
print "Formating error detected" print "Formating error detected"
writeItemizeBlock(aout, 0)
writeTextBlock(aout, 0)
state = State.ReachedExampleEnd state = State.ReachedExampleEnd
print "Reached end of the example" 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 * value, see Listing HandleSDPQUeryResult. Here, we show how to parse the
* Service Class ID List and Protocol Descriptor List, as they contain * Service Class ID List and Protocol Descriptor List, as they contain
* the BNEP Protocol UUID and L2CAP PSM respectively. * 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){ 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_attribute_value_event_t * ve;
sdp_query_complete_event_t * ce; sdp_query_complete_event_t * ce;
des_iterator_t des_list_it; 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; attribute_value[ve->data_offset] = ve->data;
if ((uint16_t)(ve->data_offset+1) == ve->attribute_length){ 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){ switch(ve->attribute_id){
// 0x0001 "Service Class ID List" // 0x0001 "Service Class ID List"
case SDP_ServiceClassIDList: case SDP_ServiceClassIDList:
@ -214,7 +210,7 @@ static void handle_sdp_client_query_result(sdp_query_event_t * event){
} }
} }
break; break;
/* LISTING_PAUSE */ /* LISTING_PAUSE */
// 0x0100 "Service Name" // 0x0100 "Service Name"
case 0x0100: case 0x0100:
// 0x0101 "Service Description" // 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); printf(" ** Attribute 0x%04x: %s\n", ve->attribute_id, str);
free(str); free(str);
break; 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:{ case SDP_ProtocolDescriptorList:{
printf(" ** Attribute 0x%04x: ", ve->attribute_id); 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); printf("l2cap_psm 0x%04x, bnep_version 0x%04x\n", l2cap_psm, bnep_version);
} }
break; break;
/* LISTING_PAUSE */ /* LISTING_PAUSE */
default: default:
break; 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); printf("General query done with status %d.\n\n", ce->status);
break; break;
} }
/* LISTING_RESUME */ /* LISTING_RESUME */
} }
/* LISTING_END */ /* LISTING_END */