File: mbi.c

package info (click to toggle)
mercury 0.9-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 18,488 kB
  • ctags: 9,800
  • sloc: objc: 146,680; ansic: 51,418; sh: 6,436; lisp: 1,567; cpp: 1,040; perl: 854; makefile: 450; asm: 232; awk: 203; exp: 32; fortran: 3; csh: 1
file content (116 lines) | stat: -rw-r--r-- 2,091 bytes parent folder | download
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
/*
** Copyright (C) 1997 The University of Melbourne.
** This file may only be copied under the terms of the GNU Library General
** Public License - see the file COPYING.LIB in the Mercury distribution.
**
** $Id: mbi.c,v 1.9 1997/07/27 14:59:24 fjh Exp $
*/

/* Imports */

	/*
	** Interface to Mercury runtime must be included first.
	*/
#include	"imp.h"

#include	<stdlib.h>
#include	<stdio.h>
#include	<unistd.h>
#include	<getopt.h>

#include	"util.h"
#include	"mem.h"
#include	"mbi.h"


/* Exports */


/* Local declarations */

static char
rcs_id[]	= "$Id: mbi.c,v 1.9 1997/07/27 14:59:24 fjh Exp $";

static void
usage(void);

static char*
program_name	= NULL;

/* Implementation */

int
BC_mbi_main(int argc, char* argv[])
{
	int	c;

	/* We do this in case we change the program name. */
	program_name = argv[0];

	/* Don't use default error messages from getopt() */
	opterr = 0;

	/* Read options */
	while ((c = getopt(argc,argv,"h")) != EOF) {
		switch (c) {
			case 'h':
				usage();
				exit(EXIT_SUCCESS);
				break;
			default:
				usage();
				exit(EXIT_FAILURE);
				break;
		}
	}

	/* We _must_ have a file argument */
	if (optind == argc) {
		usage();
	} else {
		/* Process each bytecode file in order */
		int 	i;
		char	*filename;
		FILE	*fp;

		for (i = optind; i < argc; i++) {
			filename = argv[i];
			if ((fp = fopen(filename, "r")) != NULL) {
#if 0
				if (is bytecode file) /* file ext = .mb */
				{
					read bytecodes into code area
					and store label and procedure
					entry points, etc.
				}
				else if (is shared library) /* file ext = .so*/
				{
					do a dlopen and add to list
					of shlibs.
				} else {
					error: wrong file extension
				}
				
#endif /* 0 */
			} else {
				/* XXX: Give better error message */
				MB_util_error("can not open file \"%s\"",
					filename);
			}
		} /* end for */

		/*
		 * XXX: Now start the bytecode interpreter
		 * Fire up the read-eval-print loop?
		 */

	} /* end else */

	exit(EXIT_SUCCESS);
} /* end main() */

static void
usage(void)
{
	fprintf(stderr, "Usage: %s [-h] files\n", program_name);
}