Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.94 KB | None | 0 0
  1.  //function to extract a tag from the string given in bcdata by tag ID
  2.   function extract_tag(tag_id:PAnsiChar; abcdata:PAnsiChar;var rsltdata:PAnsiChar):integer;
  3.   var
  4.   bflen:integer;
  5.   tslen:integer;
  6.   stpos:integer;
  7.   rfln:integer;
  8.   s_len:string;
  9.   eos:boolean;
  10.   pp:PAnsiChar;
  11.   begin
  12.        writeln('TAG '+tag_id+' bcdata '+abcdata);
  13.        writeln('String len in et '+IntToStr(strlen(abcdata)+1));
  14.        tslen:=strlen(abcdata);
  15.        if tslen = 0 then
  16.           begin
  17.                result:=-1;
  18.                exit;
  19.           end;
  20.        eos:=false;
  21.        stpos:=0;
  22.        while (eos=false) do
  23.              begin
  24.                   pp:=Stralloc(4);
  25.                   strlcopy(pp,@abcdata[stpos],3);
  26.                   s_len:=StrPas(pp);
  27.  
  28.                   StrDispose(pp);
  29.                   rfln:=StrToInt(s_len);
  30.                   writeln('FLEN '+tag_id+' bcdata '+abcdata);
  31.                   if ((rfln=0) or (stpos > tslen)) then
  32.                      begin
  33.                           eos:=true;
  34.                           result:=-1;
  35.                           exit;
  36.                      end;
  37.                   if (rfln > tslen) then
  38.                      begin
  39.                           eos:=true;
  40.                           result:=-1;
  41.                           exit;
  42.                      end;
  43.                   //ok if we are here we compare the tag id with the extracted one
  44.                   pp:= stralloc(3);
  45.  
  46.                   strlcopy(pp,@abcdata[stpos+3],2);
  47.                   if strlicomp(tag_id,pp,2) = 0 then
  48.                      begin
  49.                           strlcopy(rsltdata,@abcdata[stpos+5],rfln);
  50.                           eos:=true;
  51.                           result:=0;
  52.                      end
  53.                      else
  54.                      begin
  55.                           stpos:=stpos+rfln+5;
  56.                           //advance to next field
  57.                      end;
  58.  
  59.  
  60.              end;
  61.   end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement