home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0090 - 0099 / ibm0090-0099 / ibm0099.tar / ibm0099 / SAMV11-1.ZIP / API / FINDCALL.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-11-23  |  5.5 KB  |  223 lines

  1. program findcall;
  2. uses dos;
  3.  
  4. {$I samapi.pas}
  5.  
  6. var
  7.   SamMuxid : byte;
  8.  
  9.  
  10.  { -----------------------------------------------------------------
  11.  . LocateSam
  12.  .
  13.  . Finds the resident SAMAPI code.  This MUST be called before
  14.  . other functions are used!.  It checks for the environment
  15.  . string SAMAPI=number to see if there is an override for the
  16.  . muxid (SAMAPI.EXE does the same thing).
  17.  .
  18.  . returns: true if resident code found and can be used, else false
  19.  . ----------------------------------------------------------------- }
  20.  
  21.  
  22. function LocateSam : boolean;
  23.   var
  24.     envstr : string[80];
  25.     v      : integer;
  26.     code   : integer;
  27.     r      : registers;
  28.  
  29.   begin
  30.     SamMuxid := DEFAULT_SAMMUX;
  31.     envstr := getenv('SAMAPI');
  32.     if length(envstr) <> 0 then
  33.     begin
  34.       val(envstr, v, code);
  35.       if (code = 0) and (v > 0) then
  36.          SamMuxid := v;
  37.     end;
  38.     r.ah := SamMuxid;
  39.     r.al := 0;
  40.     intr($2f, r);
  41.     LocateSam := (r.al = 1);
  42.   end;
  43.  
  44.  { -----------------------------------------------------------------
  45.  . CallSam
  46.  .
  47.  . Call the resident SAMAPI code.
  48.  .
  49.  . This expects a filled-in (all but header) command buffer
  50.  . and a to-be-filled-in response buffer.  cmd is stuffed into
  51.  . cmdbuf and the resident code is called (via int $2f).
  52.  . ----------------------------------------------------------------- }
  53.  
  54. procedure CallSam(cmdcode : integer; var cmd, rsp);
  55.   var
  56.     r : registers;
  57.     i : integer;
  58.   begin
  59.     chdr_t (cmd).cmd := cmdcode;
  60.     for i := 0 to 2 do
  61.       chdr_t (cmd).fill[i] := 0;
  62.     r.di := ofs(rsp);
  63.     r.es := seg(rsp);
  64.     r.si := ofs(cmd);
  65.     r.ds := seg(cmd);
  66.     r.al := 1;
  67.     r.ah := SamMuxid;
  68.     intr($2f, r);
  69.   end;
  70.  
  71.  { -----------------------------------------------------------------
  72.  . FromAsciz
  73.  .
  74.  . This converts a 0 terminated string to pascal style
  75.  . If maximum length exceeded, then string is truncated.
  76.  . ----------------------------------------------------------------- }
  77.  
  78. procedure FromAsciz(var dst, src; maxlen : integer);
  79.   type
  80.     bary = array [0..256] of byte;
  81.   var
  82.     i : integer;
  83.  
  84.   begin
  85.     i := 0;
  86.     while (bary(src)[i] <> 0) and (maxlen > 0) do
  87.     begin
  88.       bary(dst)[i+1] := bary(src)[i];
  89.       i := i + 1;
  90.       maxlen := maxlen - 1;
  91.     end;
  92.     bary(dst)[0] := i;   { set the length }
  93.   end;
  94.  
  95.  
  96.  { -----------------------------------------------------------------
  97.  . ToAsciz
  98.  .
  99.  . This converts a pascal string to a 0 terminated string
  100.  . If maximum length exceeded, then string is truncated.
  101.  . ----------------------------------------------------------------- }
  102.  
  103. procedure ToAsciz(var dst, src; maxlen : integer);
  104.   type
  105.     bary = array [0..256] of byte;
  106.   var
  107.     i : integer;
  108.  
  109.   begin
  110.     i := 0;
  111.     while (bary(src)[0] > i) and (maxlen > 0) do
  112.     begin
  113.       bary(dst)[i] := bary(src)[i+1];
  114.       i := i + 1;
  115.       maxlen := maxlen - 1;
  116.     end;
  117.     bary(dst)[i] := 0;   { set the terminator }
  118.   end;
  119.  
  120.  { -----------------------------------------------------------------
  121.  . GetSamStrings
  122.  .
  123.  . Extracts the 0-terminated strings from SAM interface datarec_t
  124.  . and puts them in record with pascal type strings
  125.  . ----------------------------------------------------------------- }
  126.  
  127. procedure GetSamStrings(var p : callstrings_t; var c : datarec_t);
  128.   begin
  129.     FromAsciz(p.Call, c.Call, 6);
  130.     FromAsciz(p.Class, c.Class, 1);
  131.     FromAsciz(p.FirstName, c.FirstName, 11);
  132.     FromAsciz(p.MidInitial, c.MidInitial, 1);
  133.     FromAsciz(p.LastName, c.LastName, 20);
  134.     FromAsciz(p.Address, c.Address, 35);
  135.     FromAsciz(p.City, c.City, 20);
  136.     FromAsciz(p.State, c.State, 2);
  137.     FromAsciz(p.Zip, c.Zip, 5);
  138.     FromAsciz(p.Dob, c.Dob, 2);
  139.   end;
  140.  
  141.  { -----------------------------------------------------------------
  142.  . display_call_4lines
  143.  .
  144.  . displays call in 4 line format:
  145.  .  1: callsign
  146.  .  2: first [m ]last
  147.  .  3: address
  148.  .  4: city, st zip
  149.  .
  150.  . input is data record strings in pascal format
  151.  .
  152.  . ----------------------------------------------------------------- }
  153.  
  154. procedure display_call_4lines(rec : callstrings_t);
  155.   begin
  156.     writeln(rec.Call);
  157.     write(rec.FirstName, ' ');
  158.     if (rec.MidInitial[1] <> ' ') then
  159.       write(rec.MidInitial, ' ');
  160.     writeln(rec.LastName);
  161.     writeln(rec.Address);
  162.     writeln(rec.City, ', ', rec.State, ' ', rec.Zip);
  163.   end;
  164.  
  165.  
  166. function lookup_call(call : string; var rec : callstrings_t) : integer;
  167.   var
  168.     cmd : cmdfindcall_t;
  169.     rsp : rspdatarec_t;
  170.     len : integer;
  171.     i   : integer;
  172.  
  173.   begin
  174.     ToAsciz(cmd.call, call, 6);
  175.     cmd.packflags := 0;
  176.     CallSam(SamFindCall, cmd, rsp);
  177.     GetSamStrings(rec, rsp.d);
  178.     lookup_call := rsp.h.err;
  179.   end;
  180.  
  181. function main : integer;
  182.  
  183.   var
  184.     drec : callstrings_t;
  185.     err  : integer;
  186.   begin
  187.     main := 0;
  188.     if true <> LocateSam then
  189.     begin
  190.       writeln('*** SAMAPI not installed');
  191.       main := 2
  192.     end
  193.     else if (ParamCount < 1) then
  194.     begin
  195.       writeln('*** No call specified');
  196.       main := 2;
  197.     end
  198.     else
  199.     begin
  200.       err := lookup_call(ParamStr(1), drec);
  201.  
  202.       if (err <> 0) and (err <> SerrNotFound) then
  203.       begin
  204.         writeln('*** SAMAPI error ', err);
  205.         main := 2;
  206.       end
  207.       else if err <> 0 then
  208.       begin
  209.         writeln('*** Call not found');
  210.         main := 1;
  211.       end
  212.       else
  213.       begin
  214.         display_call_4lines(drec);
  215.       end;
  216.     end;
  217.   end;
  218.  
  219.   {----------------- main ----------------}
  220. begin
  221.   halt(main);
  222. end.
  223.