summaryrefslogtreecommitdiff
path: root/xmlspec/spec2xml.cpp
blob: 4f398f1233a35724bdc45c9594da4348bfe402e1 (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
// standard C++ includes
#include <fstream>

// our includes
#include "XMLSpec.h"

// rpm includes
#include <rpmbuild.h>

// display some usage
int usage()
{
		printf("Usage: spec2xml input [output]\n");
		printf("Converts the input pkg.spec file to a pkg.spec.xml\n");
		printf("file for use in an rpmbuild command.\n\n");
		return 1;
}

// program entry point
int main(int argc,
		 char** argv)
{
	printf("\nspec2xml, version 0.01\n");
	if (argc != 2 && argc != 3) {
		usage();
		return 1;
	}

	Spec pSpec = NULL;
	printf("Parsing RPM spec %s:\n", argv[1]);
	if (!parseSpec(&pSpec, argv[1], "/", "/var/tmp", 0, NULL, NULL, 1, 0)) {
		printf("\tOk, spec parsed.\n");
		printf("Creating XML structures:\n");
		XMLSpec* pXSpec = XMLSpec::structCreate(pSpec);
		if (pXSpec) {
			printf("\tOk, structures created.\n");
			if (argc == 3) {
				printf("Writing XML to %s ... ", argv[2]);
				ofstream fOut(argv[2]);
				if (fOut.is_open()) {
					pXSpec->toXMLFile(fOut);
					fOut.close();
					printf("Ok.\n");
				}
				else {
					delete pSpec;
					printf("Failed.\n");
					return 2;
				}
			}
			else if (argc == 2) {
				pXSpec->toXMLFile(cout);
			}

			delete pSpec;
			return 0;
		}
	}

	printf("\tFailed.\n");
	return 3;
}