summaryrefslogtreecommitdiff
path: root/setup/txt2man.c
blob: 8769374314593325f11c4e7bfec6003b68334f99 (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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
 *
 * This file is part of Open Sound System.
 *
 * Copyright (C) 4Front Technologies 1996-2008.
 *
 * This this source file is released under GPL v2 license (no other versions).
 * See the COPYING file included in the main directory of this source
 * distribution for the license terms and conditions.
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <time.h>
#include <string.h>

int section = 0;
char *volume = "Unknown volume";
char *title = "unknown";

int
main (int argc, char *argv[])
{
  char line[1024], *s, upper;
  const char * date;
  int c;
  FILE *f;
  time_t tt;
  extern char *optarg;
  extern int optind;

  if (time (&tt) == (time_t)-1) date = "August 31, 2006";
  else {
    date = ctime (&tt);
    s = strchr (date, '\n');
    if (s) *s = '\0';
  }

  while ((c = getopt (argc, argv, "v:s:t:")) != EOF)
    switch (c)
      {
      case 'v':
	volume = optarg;
	break;
      case 't':
	title = optarg;
	break;
      case 's':
	section = atoi (optarg);
	break;
      }

  if (optind >= argc)
    {
      fprintf (stderr, "%s: No input file specified\n", argv[0]);
      exit (-1);
    }

  if ((f = fopen (argv[optind], "r")) == NULL)
    {
      perror (argv[optind]);
      exit (-1);
    }

  printf (".\" Automatically generated text\n");
  printf (".TH %s %d \"%s\" \"4Front Technologies\" \"%s\"\n", title, section, date, volume);

  while (fgets (line, sizeof (line), f) != NULL)
    {
      s = line;
      upper = 1;

      while (*s && *s != '\n')
	{
	  if (!isupper (*s) && *s != ' ')
	    upper = 0;
	  s++;
	}
      *s = 0;
      if (line[0] == 0)
	upper = 0;

      if (upper) {
	printf (".SH %s\n", line);
      } else {
	  s = line;

	  while (isspace(*s)) s++;
	  if (*s == '\0') {
	    printf (".PP\n");
	    continue;
	  }
	  if (*s == 'o' && isspace(s[1]))
	    {
	      printf (".IP \\(bu 3\n");
	      s += 2;
	      printf ("%s\n", s);
	      continue;
	    }
	  if (*s == '-' && !isspace(s[1])) {
            printf (".TP\n");
            printf ("\\fB");
            while (!isspace (*s)) printf ("%c", *s++);
            printf ("\\fP\n");
            while (isspace(*s)) s++;
          }
	  printf ("%s\n", s);
	}
    }

  fclose (f);

  exit (0);
}