summaryrefslogtreecommitdiff
path: root/src/info2html/main.c
blob: 398ae2afbf88a9db47af319aee67a0bd4e6e3088 (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
/* little test main() to see how we're doing */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "data.h"
#include "html.h"
#include "parse.h"
#include "utils.h"
#include "version.h"

int
main(argc, argv)
int argc;
char **argv;
{
  FILE *f;
  char line[250];

  int result;

  NODE *node;

if (!be_quiet)
  printf("info2html Version %s\n",INFO2HTML_VERSION);

  if (argc == 1)
    {
      f = stdin;
      strcpy(work_filename, "STDIN");
    }
  else
    {
      if ((f=fopen(argv[1], "r"))==NULL) {
	fprintf(stderr, "File %s not found.\n",argv[1]);
	exit(1);
      }
      strcpy(work_filename, argv[1]);
    }

  work_line_number = 0;


  /* scan for start of real data */
  for (;1;) {
    fgets(line,250,f);
    if (feof(f))
      {
	fprintf(stderr,"Info file had no contents\n");
	exit(1);
      }

    work_line_number++;
    if (*line == INFO_COOKIE)
      break;

  }

  /* hack, just send to stdout for now */
  fprintf(stdout, "<BODY><HTML>\n");

  /* big loop to identify sections of info files */
  /* NEW PLAN - format on the fly */
  /* No need to store all nodes, etc since we let web server */
  /* handle resolving tags!                                  */
  for (;1;) {
    fgets(line,250,f);
    if (feof(f))
      break;

    work_line_number++;

    /* found a node definition line */
    if (!strncmp(line, "File:", 5))
      {
	node = alloc_node();
	result=read_node( f, line, node );
	if ( result == READ_ERR )
	  {
	    fprintf(stderr, "Error reading the node contents\n");
	    fprintf(stderr, "line was |%s|\n",line);
	    continue;
	  }

	strcpy(work_node,node->nodename);

#ifdef DEBUG
        printf("NEW NODE\n");
	printf("\tFile:|%s|\n\tNode:|%s|\n\tNext:|%s|\n",
	       node->filename, node->nodename,node->next);
	printf("\tPrev:|%s|\n\tUp:|%s|\n\n", node->prev, node->up);
	printf("------------------------------------------------------\n");
#endif
	/* now lets make some html */
	/* first make sure the subdir for this info file exists */
	dump_html_for_node( node );

	if (node)
	  {
	    if ( node->contents )
	      free(node->contents);

	    free(node);
	  }
      }
    else
      continue;
  }
  fprintf(stdout, "</BODY></HTML>\n");
  return 0;
}