Delete all traces of scanf(), as it won't be part of 1.0.7.
[mpsl.git] / mpsl_m.c
blobd858af79bc15caa0cae39fd983a8de27531883c1
1 /*
3 MPSL - Minimum Profit Scripting Language
4 Copyright (C) 2003/2007 Angel Ortega <angel@triptico.com>
6 mpsl_m.c - Minimum Profit Scripting Language main()
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 http://www.triptico.com
26 #include "config.h"
28 #include <stdio.h>
29 #include <string.h>
30 #include <wchar.h>
31 #include "mpdm.h"
32 #include "mpsl.h"
34 /*******************
35 Code
36 ********************/
38 int mpsl_main(int argc, char *argv[])
40 mpdm_t v;
41 char *immscript = NULL;
42 FILE *script = stdin;
43 int ret = 0;
44 int dump_only = 0;
46 /* skip the executable */
47 argv++;
48 argc--;
50 while (argc > 0) {
51 if (strcmp(argv[0], "-v") == 0 || strcmp(argv[0], "--help") == 0) {
52 printf("MPSL %s - Minimum Profit Scripting Language\n", VERSION);
53 printf("Copyright (C) 2003-2007 Angel Ortega <angel@triptico.com>\n");
54 printf
55 ("This software is covered by the GPL license. NO WARRANTY.\n\n");
57 printf("Usage: mpsl [-d] [-e 'script' | script.mpsl ]\n\n");
59 return 0;
61 else
62 if (strcmp(argv[0], "-d") == 0)
63 dump_only = 1;
64 else
65 if (strcmp(argv[0], "-e") == 0) {
66 argv++;
67 argc--;
68 immscript = argv[0];
70 else {
71 /* next argument is a script name; open it */
72 if ((script = fopen(argv[0], "r")) == NULL) {
73 fprintf(stderr, "Can't open '%s'\n", argv[0]);
74 return 1;
78 argv++;
79 argc--;
82 mpsl_startup();
84 /* set arguments */
85 mpsl_argv(argc, argv);
87 /* compile */
88 if (immscript != NULL)
89 v = mpsl_compile(MPDM_MBS(immscript));
90 else
91 v = mpsl_compile_file(MPDM_F(script));
93 if (v != NULL) {
94 if (dump_only)
95 mpdm_dump(v);
96 else
97 mpdm_exec(v, NULL);
100 /* prints the error, if any */
101 if ((v = mpsl_error(NULL)) != NULL) {
102 mpdm_write_wcs(stderr, mpdm_string(v));
103 fprintf(stderr, "\n");
105 ret = 1;
108 mpsl_shutdown();
110 return ret;
114 int main(int argc, char *argv[])
116 return mpsl_main(argc, argv);