OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4ScriptMain.cpp
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2012-2016, The OpenClonk Team and contributors
5  *
6  * Distributed under the terms of the ISC license; see accompanying file
7  * "COPYING" for details.
8  *
9  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
10  * See accompanying file "TRADEMARK" for details.
11  *
12  * To redistribute this file separately, substitute the full license texts
13  * for the above references.
14  */
15 
16 // Do not include C4Include.h - this file tests whether
17 // c4script.h is useable without that.
18 #include "../../include/c4script/c4script.h"
19 
20 #include <stdio.h>
21 #include <string.h>
22 #include <getopt.h>
23 
24 int usage(const char *argv0)
25 {
26  fprintf(stderr, "Usage:\n%s -e <script>\n%s <file>\n", argv0, argv0);
27  return 1;
28 }
29 
30 int main(int argc, char *argv[])
31 {
32  if (argc < 2)
33  return usage(argv[0]);
34 
35  bool check = false;
36  char *runstring = nullptr;
37 
38  while (1)
39  {
40  static option long_options[] =
41  {
42  {"check", no_argument, 0, 'c'},
43  {"execute", required_argument, 0, 'e'},
44  {0, 0, 0, 0}
45  };
46 
47  int option_index;
48  int c = getopt_long(argc, argv, "ce:", long_options, &option_index);
49  if (c == -1) break;
50  switch (c)
51  {
52  case 'c':
53  check = true;
54  break;
55  case 'e':
56  runstring = optarg;
57  break;
58  default:
59  return usage(argv[0]);
60  }
61  }
62 
63  if (runstring)
64  {
65  if (argc - optind != 0)
66  return usage(argv[0]);
67  if (check)
68  return c4s_checkstring(runstring);
69  else
70  return c4s_runstring(runstring);
71  }
72  else
73  {
74  if (argc - optind != 1)
75  return usage(argv[0]);
76  if (check)
77  return c4s_checkfile(argv[optind]);
78  else
79  return c4s_runfile(argv[optind]);
80  }
81 }
int c4s_checkfile(const char *filename)
int c4s_runfile(const char *filename)
int c4s_checkstring(const char *script)
int c4s_runstring(const char *script)
int usage(const char *argv0)
int main(int argc, char *argv[])