OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4ScriptMain.cpp File Reference
#include "../../include/c4script/c4script.h"
#include <stdio.h>
#include <string.h>
#include <getopt.h>
Include dependency graph for C4ScriptMain.cpp:

Go to the source code of this file.

Functions

int usage (const char *argv0)
 
int main (int argc, char *argv[])
 

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 30 of file C4ScriptMain.cpp.

References c4s_checkfile(), c4s_checkstring(), c4s_runfile(), c4s_runstring(), and usage().

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)

Here is the call graph for this function:

int usage ( const char *  argv0)

Definition at line 24 of file C4ScriptMain.cpp.

Referenced by main().

25 {
26  fprintf(stderr, "Usage:\n%s -e <script>\n%s <file>\n", argv0, argv0);
27  return 1;
28 }

Here is the caller graph for this function: