File: posthook.sl

package info (click to toggle)
slrn 1.0.3%2Bdfsg-3
  • links: PTS
  • area: main
  • in suites: buster
  • size: 6,412 kB
  • sloc: ansic: 39,852; sh: 3,777; perl: 467; makefile: 229; sed: 24
file content (66 lines) | stat: -rw-r--r-- 1,767 bytes parent folder | download | duplicates (10)
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
% This file illustrates the use of 'post_file_hook', which gets called
% immediately before a message is posted.  In this example, the header
% and body parts of the message are separated, and a shell command is run
% on the body part, finally the head and body are re-assembled.

define post_file_hook_command (cmd, file)
{
   variable header_file, body_file;
   variable fp, header_fp, body_fp;
   variable line;
   
   if (1 != get_yes_no_cancel (sprintf ("Execute %s on message", cmd)))
     return;

   fp = fopen (file, "r");
   if (fp == NULL)
     return;

   header_file = file + "-header";
   body_file = file + "-body";
   
   header_fp = fopen (header_file, "w");
   body_fp = fopen (body_file, "w");
   if ((header_fp == NULL) or (body_fp == NULL))
     return;

   while (-1 != fgets (&line, fp))
     {
	if (line == "\n")
	  break;
	() = fputs (line, header_fp);
     }
   () = fclose (header_fp);
   
   % Now do body
   while (-1 != fgets (&line, fp))
     {
	() = fputs (line, body_fp);
     }
   () = fclose (body_fp);

   () = system (sprintf ("%s %s", cmd, body_file));
   
   fp = fopen (file, "w");
   body_fp = fopen (body_file, "r");
   header_fp = fopen (header_file, "r");
   
   while (-1 != fgets (&line, header_fp))
     () = fputs (line, fp);
   () = fputs ("\n", fp);
   
   while (-1 != fgets (&line, body_fp))
     () = fputs (line, fp);

   % No need to close files unless we want to check for errors.  When
   % file pointer variables go out of scope, slang will close the file.
}

   
define post_file_hook (file)
{
   % Note: the post_file_hook_command function may be called multiple times, 
   % e.g., once to spell-check the article, once to grammar check it, 
   % and so on.
   post_file_hook_command ("ispell -x", file);
}