From 5b39d92507a9441e13cb97b2501d536cd7db2b71 Mon Sep 17 00:00:00 2001 From: Milanka Ringwald Date: Sun, 26 Apr 2015 00:22:14 +0200 Subject: [PATCH] manual: script handles inlisting text --- docs/manual/update_listings.py | 78 +++++++++++++++++++++---------- example/embedded/sdp_bnep_query.c | 32 +++++++------ 2 files changed, 70 insertions(+), 40 deletions(-) diff --git a/docs/manual/update_listings.py b/docs/manual/update_listings.py index 96b26e709..38037c98c 100755 --- a/docs/manual/update_listings.py +++ b/docs/manual/update_listings.py @@ -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" diff --git a/example/embedded/sdp_bnep_query.c b/example/embedded/sdp_bnep_query.c index 97e2f6f85..e24b09340 100644 --- a/example/embedded/sdp_bnep_query.c +++ b/example/embedded/sdp_bnep_query.c @@ -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 */