File: fixtxt

package info (click to toggle)
slang2 2.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 10,588 kB
  • ctags: 10,558
  • sloc: ansic: 95,506; sh: 3,277; makefile: 945; pascal: 143
file content (89 lines) | stat: -rwxr-xr-x 1,887 bytes parent folder | download | duplicates (7)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env jed-script

if (__argc != 2)
{
   () = fprintf (stderr, "Usage: %s file.txt\n", __argv[0]);
   exit (1);
}

% The txt file looks ugly and the contents at the beginning are
% totally misleading.

static define process_file (file)
{
   variable txt;

   () = read_file (file);
   % trim excess blank lines
   trim_buffer ();

   % fix the underscore chars
   bob ();
   while (fsearch ("_.ds h "))
     {
	deln (7);
	insert ("_");
	% Unfortunately, there are other things associated with this that are
	% messed up.  See my debian linuxdoc bug report.  In particular, the
	% table of contents associated with this are hosed and possibly the
	% rest of the text on this line.  Here is a fix for contents.
	push_spot ();
	bol_skip_white ();
	push_mark ();
	skip_chars ("0-9.");
	variable sect = bufsubstr ();
	skip_white ();
	push_mark ();
	eol ();
	txt = bufsubstr ();
	eob ();
	() = bsearch ("Table of Contents");
	sect = strcat ("  ",sect," ");
	if (bol_fsearch (sect))
	  {
	     go_right(strlen (sect));
	     del_eol ();
	     insert (txt);
	  }
	pop_spot ();
     }

   % Delete the contents at the beginning.  They are wrong.
   bob ();
   if (fsearch ("Table of Contents"))
     {
	bol ();
	push_mark ();
	if (fsearch ("____________________________________________"))
	  {
	     go_down(1);
	     del_region ();
	     % Grab the contents from the bottom
	     push_spot ();
	     eob ();
	     () = bsearch ("Table of Contents");
	     bol ();
	     push_mark ();
	     % Get rid of . . . stufff since the page numbers are meaningless
	     while (re_fsearch ("\\d$"))
	       {
		  eol ();
		  push_mark ();
		  bskip_chars ("[0-9]");
		  bskip_chars (" .");
		  del_region ();
	       }
	     eob ();
	     txt = bufsubstr_delete ();
	     pop_spot ();
	     insert (txt);
	  }
	else pop_mark (0);
     }

   save_buffer ();
}

process_file (__argv[1]);
exit (0);