File: sort.sl

package info (click to toggle)
jed 0.99.16-5
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 4,312 kB
  • ctags: 4,736
  • sloc: ansic: 36,879; sh: 8,660; makefile: 379
file content (68 lines) | stat: -rw-r--r-- 1,174 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
define sort_using_function (sort_fun)
{
   variable end_line, n, index, i, beg, begc, endc, keys;

   check_region(0);
   endc = what_column();
   end_line = what_line();
   pop_mark_1 ();
   beg = what_line();
  
   n = end_line - beg; ++n;	       %/* number of lines */
   begc = what_column();
  
   if (endc < begc)
     {
	endc; endc = begc; begc = ();
     }
   
   keys = String_Type [n];
  
  %
  % extract keys and fill array
  %

   goto_line(beg);
   for (i = 0; i < n; ++i)
     {
	goto_column(begc);
	push_mark_eol();
	if (what_column() > endc) goto_column(endc);
	keys[i] = bufsubstr();
	go_down_1 ();
     }
   
   index = array_sort(keys, sort_fun);

   %
   %  arrange region
   %
   goto_line (end_line);
   !if (down_1 ())
     {
	eol();
	newline();
     }
   
   push_spot();
   for(i = 0; i < n; ++i)
     {
	goto_line(index[i] + beg); 
	line_as_string (); 	       %  on stack-- also we are at eol now
	pop_spot();
	bol(); insert(()); newline();
	push_spot();
     }
   pop_spot();
   goto_line(beg);
   bol(); push_mark();
   goto_line(end_line + 1);
   bol(); del_region();
}

define sort ()
{
   sort_using_function (&strcmp);
   %flush("Done.");
}