home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_02_03 / 2n03027a < prev    next >
Text File  |  1991-01-11  |  946b  |  56 lines

  1.  
  2.  
  3. {*
  4.  * arraycmp - a general-purpose array comparer in Pascal
  5.  *}
  6.  
  7. type
  8.     cf_t = function (var x, y) : integer;
  9.  
  10. function arraycmp(var s1, s2; n, size : word; cf : cf_t)
  11.     : integer;
  12.     type
  13.         bytes = array [0 .. 65534] of byte;
  14.     var
  15.         cmp : integer;
  16.         i : word;
  17.     begin
  18.     cmp := 0;
  19.     i := 0;
  20.     while (i < n * size) and (cmp = 0) do
  21.         begin
  22.         cmp := cf(bytes(s1)[i], bytes(s2)[i]);
  23.         i := i + size;
  24.         end;
  25.     arraycmp := cmp;
  26.     end;
  27.  
  28. {*
  29.  * Some element comparison functions
  30.  *}
  31. function intcf(var p, q) : integer; far;
  32.     begin
  33.     intcf := integer(p) - integer(q);
  34.     end;
  35.  
  36. function realcf(var p, q) : integer; far;
  37.     begin
  38.     if real(p) < real(q) then
  39.         realcf := -1
  40.     else if real(p) < real(q) then
  41.         realcf := 0
  42.     else
  43.         realcf := 1;
  44.     end;
  45.  
  46. function strcf(var p, q) : integer; far;
  47.     begin
  48.     if string(p) < string(q) then
  49.         strcf := -1
  50.     else if string(p) < string(q) then
  51.         strcf := 0
  52.     else
  53.         strcf := 1;
  54.     end;
  55.  
  56.