aboutsummaryrefslogtreecommitdiffhomepage
path: root/libslang/slsh/scripts/htmlstrip
blob: c6a6b36e36fe264caad940b37b2482364aadd4f6 (plain)
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
#! /usr/bin/env slsh
% -*- mode: slang -*-
%_debug_info = 1;

% This file strips HTML tags from one or more html files and write the result
% to stdout.  It is very simple minded.

define process_file (file)
{
   variable fp, l;

   if (file != NULL)
     {
	fp = fopen (file, "r");
	if (fp == NULL)
	  {
	     () = fputs (sprintf ("Unable to open %s\n", file), stderr);
	     return;
	  }
     }
   else fp = stdin;

   foreach (fp)
     {
	l = ();

	l = strtrim (str_uncomment_string (l, "<", ">"));
	!if (strlen (l))
	  continue;

	() = fputs (l, stdout);
	() = fputs ("\n", stdout);
     }
}

if (__argc == 1)
{
   if (isatty (stdin))
     {
	() = fprintf (stderr, "Usage: %s [files...]\n", __argv[0]);
	exit (1);
     }
   process_file (NULL);
   exit (0);
}

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