home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / AP / JED / JED097-1.TAR / jed / lib / sort.sl < prev    next >
Encoding:
Text File  |  1994-12-12  |  1.2 KB  |  75 lines

  1. define sort_mycmp ()
  2. {
  3.    strcmp ((), ()) < 0;
  4. }
  5.   
  6. define sort_using_function (sort_fun)
  7. {
  8.    variable end_line, n, index, i, beg, begc, endc, keys;
  9.  
  10.    check_region(0);
  11.    endc = what_column();
  12.    end_line = whatline();
  13.    pop_mark(1);
  14.    beg = whatline();
  15.   
  16.    n = end_line - beg; ++n;           %/* number of lines */
  17.    begc = what_column();
  18.   
  19.    if (endc < begc)
  20.      {
  21.     endc; endc = begc; =begc;
  22.      }
  23.    
  24.    keys = create_array('s', n, 1);
  25.   
  26.   %
  27.   % extract keys and fill array
  28.   %
  29.  
  30.    goto_line(beg);
  31.    for (i = 0; i < n; ++i)
  32.      {
  33.     goto_column(begc);
  34.     push_mark();
  35.     eol();
  36.     if (what_column() > endc) goto_column(endc);
  37.     keys[i] = bufsubstr();
  38.     go_down(1);
  39.      }
  40.    
  41.    index = array_sort(keys, sort_fun);
  42.  
  43.    %
  44.    %  arrange region
  45.    %
  46.    goto_line(end_line);
  47.    !if (down(1))
  48.      {
  49.     eol();
  50.     newline();
  51.      }
  52.    
  53.    push_spot();
  54.    for(i = 0; i < n; ++i)
  55.      {
  56.     goto_line(index[i] + beg); 
  57.     bol(); push_mark(); eol(); bufsubstr();
  58.     pop_spot();
  59.     bol(); insert(()); newline();
  60.     push_spot();
  61.      }
  62.    pop_spot();
  63.    goto_line(beg);
  64.    bol(); push_mark();
  65.    goto_line(end_line + 1);
  66.    bol(); del_region();
  67.    flush("Done.");
  68. }
  69.  
  70. define sort ()
  71. {
  72.    sort_using_function ("sort_mycmp");
  73. }
  74.  
  75.