int NerveTool::execute_line( String& s , FILE *sout , ClassList<Nerve>& nn ) { if( s.startsFrom( "<img" ) ) return( execute_img( s , sout , 0 , nn ) ); // parse string int level = s.find( "*" ); if( level < 0 ) return( 1 ); if( level < 2 ) return( 13 ); s.remove( 0 , level + 1 ); level -= 2; if( nn.count() > 0 ) { Nerve *np = nn.last(); if( np -> level < level ) if( level != np -> level + 1 ) return( 14 ); } s.trim(); if( s.startsFrom( "<img" ) ) return( execute_img( s , sout , level , nn ) ); if( !s.startsFrom( "*" ) ) return( 2 ); s.remove( 0 , 1 ); // name int idx = s.find( "*" ); if( idx < 0 ) return( 3 ); String name = s.getMid( 0 , idx ); s.remove( 0 , idx + 1 ); // synonyms String synonyms; if( s.startsFrom( " (" ) ) { s.remove( 0 , 2 ); idx = s.find( ")" ); if( idx < 0 ) return( 4 ); synonyms = s.getMid( 0 , idx ); s.remove( 0 , idx + 1 ); } String origin; String branches; String distribution; String modality; String fibers; if( s.startsFrom( "; " ) ) { s.remove( 0 , 2 ); if( !extract_item( sout , origin , s , "ORIGIN" ) ) return( 6 ); if( !extract_item( sout , branches , s , "BRANCHES" ) ) return( 8 ); if( !extract_item( sout , distribution , s , "DISTRIBUTION" ) ) return( 7 ); if( !extract_item( sout , modality , s , "MODALITY" ) ) return( 9 ); if( !extract_item( sout , fibers , s , "FIBERS" ) ) return( 10 ); } if( !s.isEmpty() ) return( 11 ); Nerve *n = new Nerve; n -> fibers = fibers; String fibersinfo; if( !fibers.isEmpty() ) if( !extract_fibers( sout , n -> fibersinfo , fibers ) ) { fprintf( sout , "wrong fibers=%s\n" , ( const char * )fibers ); delete n; return( 12 ); } n -> name = name; n -> synonyms = synonyms; n -> level = level; n -> origin = origin; n -> branches = branches; n -> distribution = distribution; n -> modality = modality; nn.add( n ); return( 0 ); }
void parse_atalk_nbp(struct Ferret *ferret, struct NetFrame *frame, const unsigned char *px, unsigned length) { struct { unsigned op; unsigned count; unsigned xid; } nbp; unsigned offset=0; if (length < 2) { FRAMERR(frame, "%s: truncated\n", "NBP"); return; } /* * Parse the header first */ nbp.op = (px[0]>>4)&0x0F; nbp.count = (px[0]>>0)&0x0F; nbp.xid = px[1]; offset = 2; /* * Parse all the name-bindings */ while (nbp.count) { unsigned atalk_addr; unsigned atalk_port; unsigned enumerator; unsigned object_len; const unsigned char *object; unsigned type_len; const unsigned char *type; unsigned zone_len; const unsigned char *zone; nbp.count--; if (offset + 6 > length) { FRAMERR(frame, "%s: truncated\n", "NBP"); return; } atalk_addr = ex24be(px+offset); offset += 3; atalk_port = px[offset++]; enumerator = px[offset++]; /* Extract the items */ extract_item(ferret, frame, px, length, &offset, &object, &object_len); extract_item(ferret, frame, px, length, &offset, &type, &type_len); extract_item(ferret, frame, px, length, &offset, &zone, &zone_len); if (offset > length) break; switch (nbp.op) { case 2: JOTDOWN(ferret, JOT_SRC("ID-ATALK", frame), JOT_PRINT("Lookup", type, type_len), JOT_PRINT("Object", object, object_len), JOT_PRINT("Zone", zone, zone_len), 0); break; default: FRAMERR(frame, "%s: not implemented\n", "NBP"); } } }