/*
 * lsb2rdf.c
 * Parse a text file containing sh-style comments and output serel rdf/xml.
 *
 * Copyright (C) Leni Mayo 2002
 *
 *	This program is free software; you can redistribute it and/or modify
 *	it under the terms of the GNU General Public License, version 2, as
 *	published by the Free Software Foundation.
 *
 *	This program is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the
 *	GNU General Public License for more details.
 *
 *	You should have received a copy of the GNU General Public License
 *	along with this program; if not, write to the Free Software
 *	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

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

#include "servercommon.h"
#include "rdfcommon.h"
#include "parselsb2rdf.h"

int main(int argc, char *argv[]) 
{
	char *argv0 = argv[0];
	FILE *fp;
	int i;
	int ret = 0;
	ParseBootResult parseResult;

	if (argc < 2)
	{
		fprintf(stderr, "Usage: %s: file1 file2 ... \n", argv0);
		return 1;
	}

	print_rdf_header(stdout);
	fprintf(stdout, "\n");

	for (i = 1; i < argc; i++)
	{
		fp = fopen(argv[i], "r");

		if (fp == NULL)
		{
			fprintf(stderr, "Unable to open %s for reading.", argv[i]);
			ret = 1;
		}
		else
		{
			parseResult = parseLsbToRdf(fp, stdout, argv[i]);

			if (parseResult != eParseBootSuccess)
			{
				if (parseResult == eParseBootFailed)
				{
					/* presumably generate_xml() has spat out an error message
					*/
				}
				else
				{
					assert(parseResult == eParseBootEmpty);

					fprintf(stdout, "<!-- No Linux Standards Base boot script comments found in: %s. -->\n", argv[i]);
				}
			}

			fclose(fp);
		}
	}

	fprintf(stdout, "\n");

	print_rdf_trailer(stdout);

	return ret;
}
