Jelajahi Sumber

style: 调整函数和宏的名字

SongZihuan 4 tahun lalu
induk
melakukan
b9b7a0f190

+ 5 - 1
VirtulMathCore/CMakeLists.txt

@@ -19,10 +19,14 @@ AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/signalhandler HANDLER_LIST)
 AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/md5 MD5_LIST)
 
 ADD_LIBRARY(VirtualMathCore STATIC ${SRC_LIST} ${GC_LIST} ${PASER_LIST} ${MEM_LIST} ${FILE_LIST} ${ARGUMENT_LIST} ${OFUNC_LIST} ${HANDLER_LIST} ${CLIB_LIST} ${MD5_LIST})
-TARGET_LINK_LIBRARIES(VirtualMathCore ffi)
 IF (NOT (${CMAKE_SYSTEM_NAME} STREQUAL "Windows"))
+    TARGET_LINK_LIBRARIES(VirtualMathCore ffi)
     TARGET_LINK_LIBRARIES(VirtualMathCore dl)
 ELSE()
+    TARGET_LINK_LIBRARIES(VirtualMathCore libffi)
     ADD_LIBRARY(dlwin32 STATIC src/win/dlfcn_win32.c)
     TARGET_LINK_LIBRARIES(VirtualMathCore dlwin32)
+
+    ADD_LIBRARY(gowin32 STATIC src/win/getopt_win.c)
+    TARGET_LINK_LIBRARIES(VirtualMathCore gowin32)
 ENDIF()

+ 4 - 3
VirtulMathCore/include/macro.h

@@ -6,12 +6,9 @@
 #include <stdlib.h>
 #include <stdarg.h>
 #include <sys/stat.h>
-#include <getopt.h>
-#include <unistd.h>
 #include <ctype.h>
 #include <setjmp.h>
 #include <signal.h>
-#include <unistd.h>
 #include <wchar.h>
 #include <wctype.h>
 #include <locale.h>
@@ -19,8 +16,12 @@
 
 #ifdef __linux__
 #include <dlfcn.h>
+#include <getopt.h>
+#include <unistd.h>
 #else
+#include <windows.h>
 #include "win/dlfcn_win32.h"
+#include "win/getopt_win.h"
 #endif
 
 // 布尔逻辑的定义

+ 124 - 124
VirtulMathCore/include/token.h

@@ -3,132 +3,132 @@
 
 #include <__macro.h>
 
-#define MATHER_NUMBER 0
-#define MATHER_STRING 1
-#define MATHER_VAR 2
-
-#define MATHER_EOF 3
-#define MATHER_ENTER 4
-#define MATHER_SPACE 5
-
-#define MATHER_IF 6
-#define MATHER_ELIF 7
-#define MATHER_WHILE 8
-#define MATHER_FOR 9
-#define MATHER_IN 10
-#define MATHER_TRY 11
-#define MATHER_EXCEPT 12
-#define MATHER_AS 13
-#define MATHER_WITH 14
-#define MATHER_DO 15
-#define MATHER_ELSE 16
-#define MATHER_FINALLY 17
-#define MATHER_DEFAULT 18
-#define MATHER_GLOBAL 19
-#define MATHER_NONLOCAL 20
-#define MATHER_PUBLIC 21
-#define MATHER_PROTECT 22
-#define MATHER_PRIVATE 23
-#define MATHER_TRUE 24
-#define MATHER_FALSE 25
-#define MATHER_NULL 26
-#define MATHER_DEF 27
-#define MATHER_CLASS 28
-#define MATHER_BLOCK 29
-#define MATHER_BREAK 30
-#define MATHER_CONTINUE 31
-#define MATHER_REGO 32
-#define MATHER_RESTART 33
-#define MATHER_RETURN 34
-#define MATHER_YIELD 35
-#define MATHER_IMPORT 36
-#define MATHER_INCLUDE 37
-
-#define MATHER_ADD 38
-#define MATHER_SUB 39
-#define MATHER_MUL 40
-#define MATHER_DIV 41
-#define MATHER_INTDIV 42
-#define MATHER_PER 43
-#define MATHER_POW 44
-#define MATHER_LESS 45
-#define MATHER_LESSEQ 46
-#define MATHER_MORE 47
-#define MATHER_MOREEQ 48
-#define MATHER_EQ 49
-#define MATHER_NOTEQ 50
-
-#define MATHER_BITAND 51
-#define MATHER_BITOR 52
-#define MATHER_BITXOR 53
-#define MATHER_BITNOT 54
-#define MATHER_BITLEFT 55
-#define MATHER_BITRIGHT 56
-
-#define MATHER_BOOLAND 57
-#define MATHER_BOOLOR 58
-#define MATHER_BOOLNOT 59
-
-#define MATHER_ASSIGNMENT 60
-#define MATHER_POINT 61
-#define MATHER_AT 62
-#define MATHER_SVAR 63
-
-#define MATHER_LP 64
-#define MATHER_RP 65
-#define MATHER_LB 66
-#define MATHER_RB 67
-#define MATHER_LC 68
-#define MATHER_RC 69
-#define MATHER_COMMA 70
-#define MATHER_COLON 71
-#define MATHER_SEMICOLON 72
-#define MATHER_LINK 73
-#define MATHER_RAISE 74
-#define MATHER_FROM 75
-#define MATHER_ASSERT 76
-#define MATHER_LAMBDA 77
-#define MATHER_NOTENTER 78
-#define MATHER_COMMENT 79
-#define MATHER_GOTO 80
-#define MATHER_LABEL 81
-#define MATHER_PASSVALUE 82
-#define MATHER_DEL 83
-
-#define MATHER_MAX 84
+#define MATHER_NUMBER (0)
+#define MATHER_STRING (1)
+#define MATHER_VAR (2)
+
+#define MATHER_EOF (3)
+#define MATHER_ENTER (4)
+#define MATHER_SPACE (5)
+
+#define MATHER_IF (6)
+#define MATHER_ELIF (7)
+#define MATHER_WHILE (8)
+#define MATHER_FOR (9)
+#define MATHER_IN (10)
+#define MATHER_TRY (11)
+#define MATHER_EXCEPT (12)
+#define MATHER_AS (13)
+#define MATHER_WITH (14)
+#define MATHER_DO (15)
+#define MATHER_ELSE (16)
+#define MATHER_FINALLY (17)
+#define MATHER_DEFAULT (18)
+#define MATHER_GLOBAL (19)
+#define MATHER_NONLOCAL (20)
+#define MATHER_PUBLIC (21)
+#define MATHER_PROTECT (22)
+#define MATHER_PRIVATE (23)
+#define MATHER_TRUE (24)
+#define MATHER_FALSE (25)
+#define MATHER_NULL (26)
+#define MATHER_DEF (27)
+#define MATHER_CLASS (28)
+#define MATHER_BLOCK (29)
+#define MATHER_BREAK (30)
+#define MATHER_CONTINUE (31)
+#define MATHER_REGO (32)
+#define MATHER_RESTART (33)
+#define MATHER_RETURN (34)
+#define MATHER_YIELD (35)
+#define MATHER_IMPORT (36)
+#define MATHER_INCLUDE (37)
+
+#define MATHER_ADD (38)
+#define MATHER_SUB (39)
+#define MATHER_MUL (40)
+#define MATHER_DIV (41)
+#define MATHER_INTDIV (42)
+#define MATHER_PER (43)
+#define MATHER_POW (44)
+#define MATHER_LESS (45)
+#define MATHER_LESSEQ (46)
+#define MATHER_MORE (47)
+#define MATHER_MOREEQ (48)
+#define MATHER_EQ (49)
+#define MATHER_NOTEQ (50)
+
+#define MATHER_BITAND (51)
+#define MATHER_BITOR (52)
+#define MATHER_BITXOR (53)
+#define MATHER_BITNOT (54)
+#define MATHER_BITLEFT (55)
+#define MATHER_BITRIGHT (56)
+
+#define MATHER_BOOLAND (57)
+#define MATHER_BOOLOR (58)
+#define MATHER_BOOLNOT (59)
+
+#define MATHER_ASSIGNMENT (60)
+#define MATHER_POINT (61)
+#define MATHER_AT (62)
+#define MATHER_SVAR (63)
+
+#define MATHER_LP (64)
+#define MATHER_RP (65)
+#define MATHER_LB (66)
+#define MATHER_RB (67)
+#define MATHER_LC (68)
+#define MATHER_RC (69)
+#define MATHER_COMMA (70)
+#define MATHER_COLON (71)
+#define MATHER_SEMICOLON (72)
+#define MATHER_LINK (73)
+#define MATHER_RAISE (74)
+#define MATHER_FROM (75)
+#define MATHER_ASSERT (76)
+#define MATHER_LAMBDA (77)
+#define MATHER_NOTENTER (78)
+#define MATHER_COMMENT (79)
+#define MATHER_GOTO (80)
+#define MATHER_LABEL (81)
+#define MATHER_PASSVALUE (82)
+#define MATHER_DEL (83)
+
+#define MATHER_MAX (84)
 
 // 从-6开始是为了避开status的特殊值,尽管这并没有什么影响
-#define COMMAND (-6)
-#define OPERATION (-7)
-#define POLYNOMIAL (-8)
-#define FACTOR (-9)
-#define BASEVALUE (-10)
-#define ASSIGNMENT (-11)
-#define CODE (-12)
-#define FUNCTION (-13)
-#define CALLBACK -14
-#define IF_BRANCH -15
-#define WHILE_BRANCH -16
-#define BREAK -17
-#define CONTINUE -18
-#define REGO -19
-#define RETURN -20
-#define RESTART -21
-#define TRY_BRANCH -22
-#define RAISE -23
-#define TUPLE -24
-#define INCLUDE -25
-#define YIELD -26
-#define IMPORT -27
-#define VARCONTROL -28
-#define ASSERT -29
-#define DO_BRANCH -30
-#define WITH_BRANCH -31
-#define GOTO -32
-#define LABEL -33
-#define DECORATION -34
-#define FOR_BRANCH -35
-#define DEL -36
+#define T_COMMAND (-6)
+#define T_OPERATION (-7)
+#define T_POLYNOMIAL (-8)
+#define T_FACTOR (-9)
+#define T_BASEVALUE (-10)
+#define T_ASSIGNMENT (-11)
+#define T_CODE (-12)
+#define T_FUNCTION (-13)
+#define T_CALLFUNC (-14)
+#define T_IF_BRANCH (-15)
+#define T_WHILE_BRANCH (-16)
+#define T_BREAK (-17)
+#define T_CONTINUE (-18)
+#define T_REGO (-19)
+#define T_RETURN (-20)
+#define T_RESTART (-21)
+#define T_TRY_BRANCH (-22)
+#define T_RAISE (-23)
+#define T_TUPLE (-24)
+#define T_INCLUDE (-25)
+#define T_YIELD (-26)
+#define T_IMPORT (-27)
+#define T_VARCONTROL (-28)
+#define T_ASSERT (-29)
+#define T_DO_BRANCH (-30)
+#define T_WITH_BRANCH (-31)
+#define T_GOTO (-32)
+#define T_LABEL (-33)
+#define T_DECORATION (-34)
+#define T_FOR_BRANCH (-35)
+#define T_DEL (-36)
 
 struct Token{
     int token_type;  // 记录token的类型,大于0的数字均为lex匹配器所匹配,小于0的为syntax解析器所匹配

+ 7 - 7
VirtulMathCore/include/value.h

@@ -3,15 +3,15 @@
 #include "__macro.h"
 
 // 标准错误信息定义
-#define INSTANCE_ERROR(class) L"Instance error when calling func, call non-"#class" "#class" method"
-#define VALUE_ERROR(value, acc) L###value" value is not a "#acc" (may be modified by an external program)"
-#define ONLY_ACC(var, value) L###var" only accepts "#value
-#define ERROR_INIT(class) L###class" get wrong initialization parameters"
+#define INSTANCE_ERROR(class) L"Instance error when calling func, call non-" L###class L" " L###class L" method"
+#define VALUE_ERROR(value, acc) L###value L" value is not a " L###acc L" (may be modified by an external program)"
+#define ONLY_ACC(var, value) L###var L" only accepts " L###value
+#define ERROR_INIT(class) L###class L" get wrong initialization parameters"
 #define MANY_ARG L"Too many parameters"
 #define FEW_ARG L"Too few parameters"
-#define CUL_ERROR(opt) L###opt" operation gets incorrect value"
-#define OBJ_NOTSUPPORT(opt) L"Object does not support "#opt" operation"
-#define RETURN_ERROR(func, type) L###func" func should return "#type" type data"
+#define CUL_ERROR(opt) L###opt L" operation gets incorrect value"
+#define OBJ_NOTSUPPORT(opt) L"Object does not support " L###opt L" operation"
+#define RETURN_ERROR(func, type) L###func L" func should return " L###type L" type data"
 #define KEY_INTERRUPT L"KeyInterrupt"
 
 typedef struct Argument Argument;

+ 179 - 0
VirtulMathCore/include/win/getopt_win.h

@@ -0,0 +1,179 @@
+/* Declarations for getopt.
+   Copyright (C) 1989-1994,1996-1999,2001,2003,2004,2009,2010
+   Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#ifndef _GETOPT_H
+
+#ifndef __need_getopt
+# define _GETOPT_H 1
+#endif
+
+   /* If __GNU_LIBRARY__ is not already defined, either we are being used
+	  standalone, or this is the first header included in the source file.
+	  If we are being used with glibc, we need to include <features.h>, but
+	  that does not exist if we are standalone.  So: if __GNU_LIBRARY__ is
+	  not defined, include <ctype.h>, which will pull in <features.h> for us
+	  if it's from glibc.  (Why ctype.h?  It's guaranteed to exist and it
+	  doesn't flood the namespace with stuff the way some other headers do.)  */
+#if !defined __GNU_LIBRARY__
+# include <ctype.h>
+#endif
+
+#ifndef __THROW
+# ifndef __GNUC_PREREQ
+#  define __GNUC_PREREQ(maj, min) (0)
+# endif
+# if defined __cplusplus && __GNUC_PREREQ (2,8)
+#  define __THROW	throw ()
+# else
+#  define __THROW
+# endif
+#endif
+
+#ifdef	__cplusplus
+extern "C" {
+#endif
+
+	/* For communication from `getopt' to the caller.
+	   When `getopt' finds an option that takes an argument,
+	   the argument value is returned here.
+	   Also, when `ordering' is RETURN_IN_ORDER,
+	   each non-option ARGV-element is returned here.  */
+
+	extern char* optarg;
+
+	/* Index in ARGV of the next element to be scanned.
+	   This is used for communication to and from the caller
+	   and for communication between successive calls to `getopt'.
+	   On entry to `getopt', zero means this is the first call; initialize.
+	   When `getopt' returns -1, this is the index of the first of the
+	   non-option elements that the caller should itself scan.
+	   Otherwise, `optind' communicates from one call to the next
+	   how much of ARGV has been scanned so far.  */
+
+	extern int optind;
+
+	/* Callers store zero here to inhibit the error message `getopt' prints
+	   for unrecognized options.  */
+
+	extern int opterr;
+
+	/* Set to an option character which was unrecognized.  */
+
+	extern int optopt;
+
+#ifndef __need_getopt
+	/* Describe the long-named options requested by the application.
+	   The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
+	   of `struct option' terminated by an element containing a name which is
+	   zero.
+	   The field `has_arg' is:
+	   no_argument		(or 0) if the option does not take an argument,
+	   required_argument	(or 1) if the option requires an argument,
+	   optional_argument 	(or 2) if the option takes an optional argument.
+	   If the field `flag' is not NULL, it points to a variable that is set
+	   to the value given in the field `val' when the option is found, but
+	   left unchanged if the option is not found.
+	   To have a long-named option do something other than set an `int' to
+	   a compiled-in constant, such as set a value from `optarg', set the
+	   option's `flag' field to zero and its `val' field to a nonzero
+	   value (the equivalent single-letter option character, if there is
+	   one).  For long options that have a zero `flag' field, `getopt'
+	   returns the contents of the `val' field.  */
+
+	struct option
+	{
+		const char* name;
+		/* has_arg can't be an enum because some compilers complain about
+		   type mismatches in all the code that assumes it is an int.  */
+		int has_arg;
+		int* flag;
+		int val;
+	};
+
+	/* Names for the values of the `has_arg' field of `struct option'.  */
+
+# define no_argument		0
+# define required_argument	1
+# define optional_argument	2
+#endif	/* need getopt */
+
+
+/* Get definitions and prototypes for functions to process the
+   arguments in ARGV (ARGC of them, minus the program name) for
+   options given in OPTS.
+   Return the option character from OPTS just read.  Return -1 when
+   there are no more options.  For unrecognized options, or options
+   missing arguments, `optopt' is set to the option letter, and '?' is
+   returned.
+   The OPTS string is a list of characters which are recognized option
+   letters, optionally followed by colons, specifying that that letter
+   takes an argument, to be placed in `optarg'.
+   If a letter in OPTS is followed by two colons, its argument is
+   optional.  This behavior is specific to the GNU `getopt'.
+   The argument `--' causes premature termination of argument
+   scanning, explicitly telling `getopt' that there are no more
+   options.
+   If OPTS begins with `--', then non-option arguments are treated as
+   arguments to the option '\0'.  This behavior is specific to the GNU
+   `getopt'.  */
+
+#ifdef __GNU_LIBRARY__
+   /* Many other libraries have conflicting prototypes for getopt, with
+	  differences in the consts, in stdlib.h.  To avoid compilation
+	  errors, only prototype getopt for the GNU C library.  */
+	extern int getopt(int ___argc, char* const* ___argv, const char* __shortopts)
+		__THROW;
+
+# if defined __need_getopt && defined __USE_POSIX2 \
+  && !defined __USE_POSIX_IMPLICITLY && !defined __USE_GNU
+	/* The GNU getopt has more functionality than the standard version.  The
+	   additional functionality can be disable at runtime.  This redirection
+	   helps to also do this at runtime.  */
+#  ifdef __REDIRECT
+	extern int __REDIRECT_NTH(getopt, (int ___argc, char* const* ___argv,
+		const char* __shortopts),
+		__posix_getopt);
+#  else
+	extern int __posix_getopt(int ___argc, char* const* ___argv,
+		const char* __shortopts) __THROW;
+#   define getopt __posix_getopt
+#  endif
+# endif
+#else /* not __GNU_LIBRARY__ */
+	extern int getopt();
+#endif /* __GNU_LIBRARY__ */
+
+#ifndef __need_getopt
+	extern int getopt_long(int ___argc, char* const* ___argv,
+		const char* __shortopts,
+		const struct option* __longopts, int* __longind)
+		__THROW;
+	extern int getopt_long_only(int ___argc, char* const* ___argv,
+		const char* __shortopts,
+		const struct option* __longopts, int* __longind)
+		__THROW;
+
+#endif
+
+#ifdef	__cplusplus
+}
+#endif
+
+/* Make sure we later can get all the definitions and declarations.  */
+#undef __need_getopt
+
+#endif /* getopt.h */

+ 2 - 2
VirtulMathCore/ofunc/src/str.c

@@ -97,7 +97,7 @@ ResultType str_down(O_FUNC){
                            {.must=-1}};
     vnum size;
     vnum index;
-    wchar_t element[2] = {};
+    wchar_t element[2];  // TODO-szh 设置为空
     setResultCore(result);
     parserArgumentUnion(ap, arg, CNEXT_NT);
     if (!CHECK_RESULT(result))
@@ -141,7 +141,7 @@ ResultType str_to_list(O_FUNC){
     {
         Argument *new_list = NULL;
         for (vnum i = 0; i < size; i ++) {
-            wchar_t str[2] = {};
+            wchar_t str[2] = { NUL };  // TODO-szh 设置为空
             str[0] = ap[0].value->value->data.str.str[i];
             makeStringValue(str, LINEFILE, CNEXT_NT);
             new_list = connectValueArgument(result->value, new_list);

+ 3 - 3
VirtulMathCore/ofunc/src/vobject.c

@@ -150,7 +150,7 @@ ResultType vobject_repo(O_FUNC){
 
     switch (value->type){
         case V_num: {
-            char str[30] = {};
+            char str[30] = { NUL };
             snprintf(str, 30, "%lld", value->data.num.num);
             repo = memStrToWcs(str, false);
             break;
@@ -159,13 +159,13 @@ ResultType vobject_repo(O_FUNC){
             repo = memWidecpy(value->data.str.str);
             break;
         case V_func: {
-            char str[30] = {};
+            char str[30] = { NUL };
             snprintf(str, 30, "(func on %p)", value);
             repo = memStrToWcs(str, false);
             break;
         }
         case V_class: {
-            char str[30] = {};
+            char str[30] = { NUL };
             snprintf(str, 30, "(class on %p)", value);
             repo = memStrToWcs(str, false);
             break;

+ 4 - 4
VirtulMathCore/parser/__grammar.c

@@ -122,7 +122,7 @@ bool callParserCode(P_FUNC, Statement **st, char *message, long int line) {
     Token *tmp;
     *st = NULL;
     parserCode(CP_FUNC);
-    if (!call_success(pm) || readBackToken(pm) != CODE) {
+    if (!call_success(pm) || readBackToken(pm) != T_CODE) {
         if (message != NULL)
             syntaxError(pm, syntax_error, line, 1, message);
         return false;
@@ -137,7 +137,7 @@ bool callParserAs(P_FUNC, Statement **st, char *message){
     *st = NULL;
     if (readBackToken(pm) == MATHER_AS) {
         delToken(pm);
-        return callChildStatement(CP_FUNC, parserOperation, OPERATION, st, message);
+        return callChildStatement(CP_FUNC, parserOperation, T_OPERATION, st, message);
     }
     return true;
 }
@@ -229,7 +229,7 @@ bool parserParameter(P_FUNC, Parameter **pt, bool enter, bool is_formal, bool is
         parserPolynomial(CP_FUNC);
         if (!call_success(pm))
             goto error_;
-        if (readBackToken(pm) != POLYNOMIAL) {
+        if (readBackToken(pm) != T_POLYNOMIAL) {
             if (status == s_3) {
                 long int line = pm->tm->ts->token_list->line;
                 syntaxError(pm, syntax_error, line, LINEFILE);
@@ -271,7 +271,7 @@ bool parserParameter(P_FUNC, Parameter **pt, bool enter, bool is_formal, bool is
             new_pt = connectValueParameter(tmp->data.st, new_pt, is_sep == 1);
         else if (pt_type == name_par){
             Statement *tmp_value;
-            if (!callChildStatement(CP_FUNC, parserPolynomial, POLYNOMIAL, &tmp_value, "Don't get a parameter value"))
+            if (!callChildStatement(CP_FUNC, parserPolynomial, T_POLYNOMIAL, &tmp_value, "Don't get a parameter value"))
                 goto error_;
             new_pt = connectNameParameter(tmp_value, tmp->data.st, new_pt);
             if (!checkToken(pm, sep))

+ 89 - 87
VirtulMathCore/parser/grammar.c

@@ -74,7 +74,7 @@ void parserCommandList(P_FUNC, bool global, bool is_one, Statement *st) {
             Token *command_token = NULL;
             int stop;
             have_command = true;
-            if (!callChildToken(CP_FUNC, parserCommand, COMMAND, &command_token, command_message, command_list_error))
+            if (!callChildToken(CP_FUNC, parserCommand, T_COMMAND, &command_token, command_message, command_list_error))
                 break;
             line = command_token->line;
             stop = readBackToken(pm);
@@ -133,77 +133,77 @@ void parserCommand(P_FUNC){
     token_type = readBackToken(pm);
     switch (token_type) {
         case MATHER_AT :
-            status = callChildStatement(CP_FUNC, parserDecoration, DECORATION, &st, NULL);
+            status = callChildStatement(CP_FUNC, parserDecoration, T_DECORATION, &st, NULL);
             break;
         case MATHER_NONLOCAL :
         case MATHER_GLOBAL :
         case MATHER_DEFAULT :
-            status = callChildStatement(CP_FUNC, parserVarControl, VARCONTROL, &st, NULL);
+            status = callChildStatement(CP_FUNC, parserVarControl, T_VARCONTROL, &st, NULL);
             break;
         case MATHER_CLASS :
         case MATHER_DEF :
-            status = callChildStatement(CP_FUNC, parserDef, FUNCTION, &st, NULL);
+            status = callChildStatement(CP_FUNC, parserDef, T_FUNCTION, &st, NULL);
             break;
         case MATHER_GOTO :
-            status = callChildStatement(CP_FUNC, parserGoto, GOTO, &st, NULL);
+            status = callChildStatement(CP_FUNC, parserGoto, T_GOTO, &st, NULL);
             break;
         case MATHER_LABEL :
-            status = callChildStatement(CP_FUNC, parserLabel, LABEL, &st, NULL);
+            status = callChildStatement(CP_FUNC, parserLabel, T_LABEL, &st, NULL);
             break;
         case MATHER_DO :
-            status = callChildStatement(CP_FUNC, parserDo, DO_BRANCH, &st, NULL);
+            status = callChildStatement(CP_FUNC, parserDo, T_DO_BRANCH, &st, NULL);
             break;
         case MATHER_WITH :
-            status = callChildStatement(CP_FUNC, parserWith, WITH_BRANCH, &st, NULL);
+            status = callChildStatement(CP_FUNC, parserWith, T_WITH_BRANCH, &st, NULL);
             break;
         case MATHER_IF :
-            status = callChildStatement(CP_FUNC, parserIf, IF_BRANCH, &st, NULL);
+            status = callChildStatement(CP_FUNC, parserIf, T_IF_BRANCH, &st, NULL);
             break;
         case MATHER_FOR :
-            status = callChildStatement(CP_FUNC, parserFor, FOR_BRANCH, &st, NULL);
+            status = callChildStatement(CP_FUNC, parserFor, T_FOR_BRANCH, &st, NULL);
             break;
         case MATHER_WHILE :
-            status = callChildStatement(CP_FUNC, parserWhile, WHILE_BRANCH, &st, NULL);
+            status = callChildStatement(CP_FUNC, parserWhile, T_WHILE_BRANCH, &st, NULL);
             break;
         case MATHER_TRY :
-            status = callChildStatement(CP_FUNC, parserTry, TRY_BRANCH, &st, NULL);
+            status = callChildStatement(CP_FUNC, parserTry, T_TRY_BRANCH, &st, NULL);
             break;
         case MATHER_BREAK :
-            status = commandCallControl_(CP_FUNC, makeBreakStatement, BREAK, &st, false, NULL);
+            status = commandCallControl_(CP_FUNC, makeBreakStatement, T_BREAK, &st, false, NULL);
             break;
         case MATHER_CONTINUE :
-            status = commandCallControl_(CP_FUNC, makeContinueStatement, CONTINUE, &st, false, NULL);
+            status = commandCallControl_(CP_FUNC, makeContinueStatement, T_CONTINUE, &st, false, NULL);
             break;
         case MATHER_RESTART :
-            status = commandCallControl_(CP_FUNC, makeRestartStatement, RESTART, &st, false, NULL);
+            status = commandCallControl_(CP_FUNC, makeRestartStatement, T_RESTART, &st, false, NULL);
             break;
         case MATHER_REGO :
-            status = commandCallControl_(CP_FUNC, makeRegoStatement, REGO, &st, false, NULL);
+            status = commandCallControl_(CP_FUNC, makeRegoStatement, T_REGO, &st, false, NULL);
             break;
         case MATHER_RETURN :
-            status = commandCallControl_(CP_FUNC, makeReturnStatement, RETURN, &st, false, NULL);
+            status = commandCallControl_(CP_FUNC, makeReturnStatement, T_RETURN, &st, false, NULL);
             break;
         case MATHER_YIELD :
-            status = commandCallControl_(CP_FUNC, makeYieldStatement, YIELD, &st, false, NULL);
+            status = commandCallControl_(CP_FUNC, makeYieldStatement, T_YIELD, &st, false, NULL);
             break;
         case MATHER_RAISE :
-            status = commandCallControl_(CP_FUNC, makeRaiseStatement, RAISE, &st, false, NULL);
+            status = commandCallControl_(CP_FUNC, makeRaiseStatement, T_RAISE, &st, false, NULL);
             break;
         case MATHER_ASSERT :
-            status = commandCallControl_(CP_FUNC, makeAssertStatement, ASSERT, &st, true,
+            status = commandCallControl_(CP_FUNC, makeAssertStatement, T_ASSERT, &st, true,
                                          "parserAssert: Don't get conditions after assert");
             break;
         case MATHER_INCLUDE :
-            status = commandCallControl_(CP_FUNC, makeIncludeStatement, INCLUDE, &st, true,
+            status = commandCallControl_(CP_FUNC, makeIncludeStatement, T_INCLUDE, &st, true,
                                          "parserInclude: Don't get file after include");
             break;
         case MATHER_DEL :
-            status = commandCallControl_(CP_FUNC, makeDelStatement, DEL, &st, true,
+            status = commandCallControl_(CP_FUNC, makeDelStatement, T_DEL, &st, true,
                                          "parserInclude: Don't get operation after del");
             break;
         case MATHER_FROM :
         case MATHER_IMPORT :
-            status = callChildStatement(CP_FUNC, parserImport, IMPORT, &st, NULL);
+            status = callChildStatement(CP_FUNC, parserImport, T_IMPORT, &st, NULL);
             break;
         case MATHER_STRING:
         case MATHER_NUMBER:
@@ -217,7 +217,7 @@ void parserCommand(P_FUNC){
         case MATHER_PRIVATE:
         case MATHER_PUBLIC:
         case MATHER_PASSVALUE:
-            status = callChildStatement(CP_FUNC, parserOperation, OPERATION, &st, NULL);
+            status = callChildStatement(CP_FUNC, parserOperation, T_OPERATION, &st, NULL);
             break;
         default:
             status = false;
@@ -225,7 +225,7 @@ void parserCommand(P_FUNC){
     }
     if (!status)
         goto return_;
-    addStatementToken(COMMAND, st, pm);
+    addStatementToken(T_COMMAND, st, pm);
     return_: return;
 }
 
@@ -239,7 +239,7 @@ void parserDecoration(P_FUNC){
         line = delToken(pm);
         if (tmp == MATHER_ENTER)
             continue;
-        if (!callChildStatement(CP_FUNC, parserOperation, OPERATION, &dst, "Don't get a decoration operation"))
+        if (!callChildStatement(CP_FUNC, parserOperation, T_OPERATION, &dst, "Don't get a decoration operation"))
             goto error_;
         ds = connectDecorationStatement(dst, ds);
     }
@@ -247,13 +247,13 @@ void parserDecoration(P_FUNC){
         syntaxError(pm, syntax_error, line, 1, "Don't get a decoration object");
         goto error_;
     }
-    if (!callChildStatement(CP_FUNC, parserDef, FUNCTION, &st, "Don't get a decoration object"))
+    if (!callChildStatement(CP_FUNC, parserDef, T_FUNCTION, &st, "Don't get a decoration object"))
         goto error_;
     if (tmp == MATHER_CLASS)
         st->u.set_class.decoration = ds;
     else
         st->u.set_function.decoration = ds;
-    addStatementToken(DECORATION, st, pm);
+    addStatementToken(T_DECORATION, st, pm);
     return;
 
     error_:
@@ -287,15 +287,15 @@ void parserLabel(P_FUNC){
         goto error_;
     }
 
-    if (checkToken(pm, MATHER_AS) && !callChildStatement(CP_FUNC, parserOperation, OPERATION, &var, "Don't get a label var"))
+    if (checkToken(pm, MATHER_AS) && !callChildStatement(CP_FUNC, parserOperation, T_OPERATION, &var, "Don't get a label var"))
         goto error_;
 
-    if (checkToken(pm, MATHER_COLON) && !callChildStatement(CP_FUNC, parserOperation, OPERATION, &command, "Don't get a label command"))
+    if (checkToken(pm, MATHER_COLON) && !callChildStatement(CP_FUNC, parserOperation, T_OPERATION, &command, "Don't get a label command"))
         goto error_;
 
 
     st = makeLabelStatement(var, command, label, line, pm->file);
-    addStatementToken(LABEL, st, pm);
+    addStatementToken(T_LABEL, st, pm);
     memFree(label);
     return;
 
@@ -320,17 +320,17 @@ void parserGoto(P_FUNC){
     Statement *return_ = NULL;
     long int line = delToken(pm);
 
-    if (!callChildStatement(CP_FUNC, parserOperation, OPERATION, &label, "Don't get a goto label"))
+    if (!callChildStatement(CP_FUNC, parserOperation, T_OPERATION, &label, "Don't get a goto label"))
         goto error_;
 
-    if (checkToken(pm, MATHER_AT) && !callChildStatement(CP_FUNC, parserOperation, OPERATION, &times, "Don't get a goto times"))
+    if (checkToken(pm, MATHER_AT) && !callChildStatement(CP_FUNC, parserOperation, T_OPERATION, &times, "Don't get a goto times"))
         goto error_;
 
-    if (checkToken(pm, MATHER_COLON) && !callChildStatement(CP_FUNC, parserOperation, OPERATION, &return_, "Don't get a goto return"))
+    if (checkToken(pm, MATHER_COLON) && !callChildStatement(CP_FUNC, parserOperation, T_OPERATION, &return_, "Don't get a goto return"))
         goto error_;
 
     st = makeGotoStatement(return_, times, label, line, pm->file);
-    addStatementToken(GOTO, st, pm);
+    addStatementToken(T_GOTO, st, pm);
     return;
 
     error_:
@@ -363,17 +363,17 @@ void parserImport(P_FUNC) {
                 is_lock = true;
                 break;
             default:
-                syntaxError(pm, syntax_error, opt->line, 1, "Don't get a aut token");
+                syntaxError(pm, syntax_error, line, 1, "Don't get a aut token");
                 goto return_;
         }
         delToken(pm);
     }
 
-    if (!callChildStatement(CP_FUNC, parserOperation, OPERATION, &opt, "Don't get a import file"))
+    if (!callChildStatement(CP_FUNC, parserOperation, T_OPERATION, &opt, "Don't get a import file"))
         goto return_;
     if (token_type == MATHER_IMPORT) {
         Statement *as = NULL;
-        if (checkToken(pm, MATHER_AS) && !callChildStatement(CP_FUNC, parserOperation, OPERATION, &as, "Don't get a as after import")) {
+        if (checkToken(pm, MATHER_AS) && !callChildStatement(CP_FUNC, parserOperation, T_OPERATION, &as, "Don't get a as after import")) {
             freeStatement(opt);
             goto return_;
         }
@@ -413,7 +413,7 @@ void parserImport(P_FUNC) {
         st = makeFromImportStatement(opt, as, pt, is_lock);
     }
 
-    addStatementToken(IMPORT, st, pm);
+    addStatementToken(T_IMPORT, st, pm);
     return_:
     return;
 }
@@ -439,7 +439,7 @@ void parserVarControl(P_FUNC) {
         goto return_;
     }
     st = makeDefaultVarStatement(var, line, pm->file, token_type == MATHER_DEFAULT ? default_ : token_type == MATHER_GLOBAL ? global_ : nonlocal_);
-    addStatementToken(VARCONTROL, st, pm);
+    addStatementToken(T_VARCONTROL, st, pm);
     return_:
     return;
 }
@@ -459,7 +459,7 @@ void parserControl(P_FUNC, MakeControlFunction callBack, int type, bool must_ope
     Token *tmp = NULL;
     long int line = delToken(pm);
     parserOperation(CP_FUNC);
-    if (call_success(pm) && readBackToken(pm) == OPERATION){
+    if (call_success(pm) && readBackToken(pm) == T_OPERATION){
         tmp = popNewToken(pm->tm);
         opt = tmp->data.st;
         freeToken(tmp, false);
@@ -480,7 +480,7 @@ void parserDo(P_FUNC){
     Statement *do_code = NULL;
     long int line = delToken(pm);
     if (readBackToken(pm) == MATHER_WHILE){  // do...while语句
-        if (!callChildStatement(CP_FUNC, parserWhile, WHILE_BRANCH, &st, "Don't get a while code"))
+        if (!callChildStatement(CP_FUNC, parserWhile, T_WHILE_BRANCH, &st, "Don't get a while code"))
             goto error_;
         st->u.while_branch.type = do_while_;
     }
@@ -492,7 +492,7 @@ void parserDo(P_FUNC){
         switch (readBackToken(pm)){
             case MATHER_IF: {
                 StatementList *do_sl = NULL;
-                if (!callChildStatement(CP_FUNC, parserIf, IF_BRANCH, &st, "Don't get a if code after do"))
+                if (!callChildStatement(CP_FUNC, parserIf, T_IF_BRANCH, &st, "Don't get a if code after do"))
                     goto error_;
                 do_sl = makeStatementList(NULL, NULL, do_code, do_b);
                 do_sl->next = st->u.if_branch.if_list;
@@ -500,17 +500,17 @@ void parserDo(P_FUNC){
                 break;
             }
             case MATHER_WHILE:
-                if (!callChildStatement(CP_FUNC, parserWhile, WHILE_BRANCH, &st, "Don't get a while code after do"))
+                if (!callChildStatement(CP_FUNC, parserWhile, T_WHILE_BRANCH, &st, "Don't get a while code after do"))
                     goto error_;
                 st->u.while_branch.first = do_code;
                 break;
             case MATHER_FOR:
-                if (!callChildStatement(CP_FUNC, parserFor, FOR_BRANCH, &st, "Don't get a for code after do"))
+                if (!callChildStatement(CP_FUNC, parserFor, T_FOR_BRANCH, &st, "Don't get a for code after do"))
                     goto error_;
                 st->u.for_branch.first_do = do_code;
                 break;
             case MATHER_DEF:
-                if (!callChildStatement(CP_FUNC, parserDef, FUNCTION, &st, "Don't get a func def after do"))
+                if (!callChildStatement(CP_FUNC, parserDef, T_FUNCTION, &st, "Don't get a func def after do"))
                     goto error_;
                 st->u.set_function.first_do = do_code;
                 break;
@@ -520,7 +520,7 @@ void parserDo(P_FUNC){
                     syntaxError(pm, syntax_error, tmp_line, 1, "Don't get while after do");
                     goto error_;
                 }
-                if (!callChildStatement(CP_FUNC, parserWhile, WHILE_BRANCH, &st, "Don't get a while code"))
+                if (!callChildStatement(CP_FUNC, parserWhile, T_WHILE_BRANCH, &st, "Don't get a while code"))
                     goto error_;
                 st->u.while_branch.type = do_while_;
                 st->u.while_branch.first = do_code;
@@ -538,7 +538,7 @@ void parserDo(P_FUNC){
         }
     }
 
-    addStatementToken(DO_BRANCH, st, pm);
+    addStatementToken(T_DO_BRANCH, st, pm);
     return;
 
     error_:
@@ -555,14 +555,14 @@ void parserFor(P_FUNC){
     long int line = delToken(pm);
     {
         Statement *code_tmp = NULL, *var_tmp = NULL, *iter_tmp = NULL;
-        if (!callChildStatement(CP_FUNC, parserOperation, OPERATION, &var_tmp, "Don't get a for var"))
+        if (!callChildStatement(CP_FUNC, parserOperation, T_OPERATION, &var_tmp, "Don't get a for var"))
             goto error_;
         if (!checkToken(pm, MATHER_IN)){
             freeStatement(var_tmp);
             syntaxError(pm, syntax_error, line, 1, "Don't get in after for");
             goto error_;
         }
-        if (!callChildStatement(CP_FUNC, parserOperation, OPERATION, &iter_tmp, "Don't get a for condition")) {
+        if (!callChildStatement(CP_FUNC, parserOperation, T_OPERATION, &iter_tmp, "Don't get a for condition")) {
             freeStatement(var_tmp);
             goto error_;
         }
@@ -617,7 +617,7 @@ void parserFor(P_FUNC){
     st->u.for_branch.else_list = else_st;
     st->u.for_branch.finally = finally_st;
     st->u.for_branch.after_do = do_st;
-    addStatementToken(FOR_BRANCH, st, pm);
+    addStatementToken(T_FOR_BRANCH, st, pm);
     return;
 
     error_:
@@ -639,7 +639,7 @@ void parserWith(P_FUNC){
     long int tmp_line;
 
     line = delToken(pm);
-    if (!callChildStatement(CP_FUNC, parserOperation, OPERATION, &condition_tmp, "Don't get a with operation"))
+    if (!callChildStatement(CP_FUNC, parserOperation, T_OPERATION, &condition_tmp, "Don't get a with operation"))
         goto error_;
     if (!callParserAs(CP_FUNC, &var_tmp, "Don't get a with var"))
         goto error_;
@@ -673,7 +673,7 @@ void parserWith(P_FUNC){
     st->u.with_branch.with_list = sl;
     st->u.with_branch.else_list = else_st;
     st->u.with_branch.finally = finally_st;
-    addStatementToken(WITH_BRANCH, st, pm);
+    addStatementToken(T_WITH_BRANCH, st, pm);
     return;
 
     error_:
@@ -705,7 +705,8 @@ void parserIf(P_FUNC){
     Statement *finally_st = NULL;
     StatementList *sl = NULL;
     bool have_if = false;
-    long int line = 0;
+    fline line = 0;
+    fline tmp_line = 0;
     again:
     switch (readBackToken(pm)) {
         case MATHER_IF:
@@ -714,17 +715,18 @@ void parserIf(P_FUNC){
             else
                 have_if = true;
             line = delToken(pm);
+            tmp_line = line;
             goto not_del;
         case MATHER_ELIF: {
             Statement *code_tmp = NULL, *var_tmp = NULL, *condition_tmp = NULL;
-            long int tmp_line = delToken(pm);
+            tmp_line = delToken(pm);
             if (else_st != NULL) {
                 syntaxError(pm, syntax_error, tmp_line, 1, "get elif after else");
                 goto error_;
             }
 
             not_del:
-            if (!callChildStatement(CP_FUNC, parserOperation, OPERATION, &condition_tmp, "Don't get a if condition"))
+            if (!callChildStatement(CP_FUNC, parserOperation, T_OPERATION, &condition_tmp, "Don't get a if condition"))
                 goto error_;
 
             if (!callParserAs(CP_FUNC, &var_tmp, "Don't get a while var")) {
@@ -744,14 +746,14 @@ void parserIf(P_FUNC){
             if (else_st != NULL)
                 goto default_;
             Statement *code_tmp = NULL;
-            long int tmp_line = delToken(pm);
+            tmp_line = delToken(pm);
             if (!callParserCode(CP_FUNC, &code_tmp, "Don't get a if...do code", tmp_line))
                 goto error_;
             sl = connectStatementList(sl, makeStatementList(NULL, NULL, code_tmp, do_b));
             goto again;
         }
         case MATHER_ELSE: {
-            long int tmp_line = delToken(pm);
+            tmp_line = delToken(pm);
             if (else_st != NULL) {
                 syntaxError(pm, syntax_error, tmp_line, 1, "get else after else");
                 goto error_;
@@ -761,7 +763,7 @@ void parserIf(P_FUNC){
             goto again;
         }
         case MATHER_FINALLY: {
-            long int tmp_line = delToken(pm);
+            tmp_line = delToken(pm);
             if (!callParserCode(CP_FUNC, &finally_st, "Don't get a if...finally code", tmp_line))
                 goto error_;
             break;
@@ -782,7 +784,7 @@ void parserIf(P_FUNC){
     st->u.if_branch.if_list = sl;
     st->u.if_branch.else_list = else_st;
     st->u.if_branch.finally = finally_st;
-    addStatementToken(IF_BRANCH, st, pm);
+    addStatementToken(T_IF_BRANCH, st, pm);
     return;
 
     error_:
@@ -821,7 +823,7 @@ void parserWhile(P_FUNC){
 
             Statement *code_tmp = NULL, *var_tmp = NULL, *condition_tmp = NULL;
             line = delToken(pm);
-            if (!callChildStatement(CP_FUNC, parserOperation, OPERATION, &condition_tmp, "Don't get a while condition"))
+            if (!callChildStatement(CP_FUNC, parserOperation, T_OPERATION, &condition_tmp, "Don't get a while condition"))
                 goto error_;
 
             if (!callParserAs(CP_FUNC, &var_tmp, "Don't get a while var")){
@@ -879,7 +881,7 @@ void parserWhile(P_FUNC){
     st->u.while_branch.else_list = else_st;
     st->u.while_branch.finally = finally_st;
     st->u.while_branch.after = do_st;
-    addStatementToken(WHILE_BRANCH, st, pm);
+    addStatementToken(T_WHILE_BRANCH, st, pm);
     return;
 
     error_:
@@ -926,7 +928,7 @@ void parserTry(P_FUNC){
                 goto error_;
             }
             if (readBackToken(pm) != MATHER_LC)
-                callChildStatement(CP_FUNC, parserOperation, OPERATION, &condition_tmp, NULL);
+                callChildStatement(CP_FUNC, parserOperation, T_OPERATION, &condition_tmp, NULL);
 
             if (!callParserAs(CP_FUNC, &var_tmp, "Don't get a except var")){
                 freeStatement(condition_tmp);
@@ -973,7 +975,7 @@ void parserTry(P_FUNC){
     st->u.try_branch.except_list = sl;
     st->u.try_branch.else_list = else_st;
     st->u.try_branch.finally = finally_st;
-    addStatementToken(TRY_BRANCH, st, pm);
+    addStatementToken(T_TRY_BRANCH, st, pm);
     return;
 
     error_:
@@ -999,7 +1001,7 @@ void parserDef(P_FUNC){
     int type = readBackToken(pm);
     long int line = delToken(pm);
 
-    if (!callChildStatement(CP_FUNC, parserBaseValue, BASEVALUE, &name_tmp,
+    if (!callChildStatement(CP_FUNC, parserBaseValue, T_BASEVALUE, &name_tmp,
                             "Don't get a func/V_class name"))
         goto error_;
 
@@ -1025,7 +1027,7 @@ void parserDef(P_FUNC){
     else
         st = makeClassStatement(name_tmp, code_tmp, pt);
     addLexToken(pm, MATHER_ENTER);
-    addStatementToken(FUNCTION, st, pm);
+    addStatementToken(T_FUNCTION, st, pm);
     return;
 
     error_:
@@ -1064,7 +1066,7 @@ void parserCode(P_FUNC) {
     }
 
     return_:
-    addStatementToken(CODE, st, pm);
+    addStatementToken(T_CODE, st, pm);
     return;
 
     error_:
@@ -1078,9 +1080,9 @@ void parserCode(P_FUNC) {
  */
 void parserOperation(P_FUNC){
     Statement *operation_st = NULL;
-    if (!callChildStatement(CP_FUNC, parserAssignment, ASSIGNMENT, &operation_st, NULL))
+    if (!callChildStatement(CP_FUNC, parserAssignment, T_ASSIGNMENT, &operation_st, NULL))
         goto return_;
-    addStatementToken(OPERATION, operation_st, pm);
+    addStatementToken(T_OPERATION, operation_st, pm);
     return_:
     return;
 }
@@ -1112,7 +1114,7 @@ bool switchAssignment(P_FUNC, int symbol, Statement **st){
 }
 
 void parserAssignment(P_FUNC){
-    return twoOperation(CP_FUNC, parserTuple, switchAssignment, checkAssignmentLeft, TUPLE, ASSIGNMENT,
+    return twoOperation(CP_FUNC, parserTuple, switchAssignment, checkAssignmentLeft, T_TUPLE, T_ASSIGNMENT,
                         "polynomial", "assignment", true);
 }
 
@@ -1134,10 +1136,10 @@ void parserTuple(P_FUNC){
         goto parserPt;
     }
 
-    if (!callChildToken(CP_FUNC, parserPolynomial, POLYNOMIAL, &tmp, NULL, syntax_error))
+    if (!callChildToken(CP_FUNC, parserPolynomial, T_POLYNOMIAL, &tmp, NULL, syntax_error))
         goto return_;
     if (readBackToken(pm) != MATHER_COMMA){
-        tmp->token_type = TUPLE;
+        tmp->token_type = T_TUPLE;
         addToken_(pm ,tmp);
         goto return_;
     }
@@ -1150,7 +1152,7 @@ void parserTuple(P_FUNC){
         goto return_;
     }
     st = makeTupleStatement(pt, L_tuple, pt->data.value->line, pm->file);
-    addStatementToken(TUPLE, st, pm);
+    addStatementToken(T_TUPLE, st, pm);
 
     return_:
     return;
@@ -1177,7 +1179,7 @@ bool switchPolynomial(P_FUNC, int symbol, Statement **st){
     return true;
 }
 void parserPolynomial(P_FUNC){
-    return twoOperation(CP_FUNC, parserFactor, switchPolynomial, NULL, FACTOR, POLYNOMIAL,
+    return twoOperation(CP_FUNC, parserFactor, switchPolynomial, NULL, T_FACTOR, T_POLYNOMIAL,
                         "factor", "polynomial", false);
 }
 
@@ -1202,7 +1204,7 @@ bool switchFactor(P_FUNC, int symbol, Statement **st){
     return true;
 }
 void parserFactor(P_FUNC){
-    return twoOperation(CP_FUNC, parserCallBack, switchFactor, NULL, CALLBACK, FACTOR,
+    return twoOperation(CP_FUNC, parserCallBack, switchFactor, NULL, T_CALLFUNC, T_FACTOR,
                         "call back", "factor", false);
 }
 
@@ -1239,7 +1241,7 @@ bool tailSlice(P_FUNC, Token *left_token, Statement **st){
     enum SliceType type;  // 0-slice  1-down
     long int line = delToken(pm);
 
-    if (!callChildToken(CP_FUNC, parserPolynomial, POLYNOMIAL, &tmp, "Don't get slice/down element", syntax_error))
+    if (!callChildToken(CP_FUNC, parserPolynomial, T_POLYNOMIAL, &tmp, "Don't get slice/down element", syntax_error))
         return false;
     else if (readBackToken(pm) == MATHER_COLON)
         type = SliceType_slice_;
@@ -1265,7 +1267,7 @@ bool tailSlice(P_FUNC, Token *left_token, Statement **st){
 bool taliPoint(P_FUNC, Token *left_token, Statement **st){
     Statement *right_st = NULL;
     delToken(pm);
-    if (!callChildStatement(CP_FUNC, parserBaseValue, BASEVALUE, &right_st, "Don't get a BaseValue after point"))
+    if (!callChildStatement(CP_FUNC, parserBaseValue, T_BASEVALUE, &right_st, "Don't get a BaseValue after point"))
         return false;
     *st = makeOperationStatement(OPT_POINT, left_token->data.st, right_st);
     return true;
@@ -1274,7 +1276,7 @@ bool taliPoint(P_FUNC, Token *left_token, Statement **st){
 bool taliLink(P_FUNC, Token *left_token, Statement **st){
     Statement *right_st = NULL;
     delToken(pm);
-    if (!callChildStatement(CP_FUNC, parserBaseValue, BASEVALUE, &right_st, "Don't get a BaseValue after link"))
+    if (!callChildStatement(CP_FUNC, parserBaseValue, T_BASEVALUE, &right_st, "Don't get a BaseValue after link"))
         return false;
     *st = makeOperationStatement(OPT_LINK, left_token->data.st, right_st);
     return true;
@@ -1286,11 +1288,11 @@ void parserCallBack(P_FUNC){
         Token *left_token = NULL;
         struct Statement *st = NULL;
 
-        if (readBackToken(pm) != CALLBACK){
+        if (readBackToken(pm) != T_CALLFUNC){
 
-            if (!callChildStatement(CP_FUNC, parserBaseValue, BASEVALUE, &st, NULL))
+            if (!callChildStatement(CP_FUNC, parserBaseValue, T_BASEVALUE, &st, NULL))
                 goto return_;
-            addStatementToken(CALLBACK, st, pm);
+            addStatementToken(T_CALLFUNC, st, pm);
             continue;
         }
         left_token = popNewToken(pm->tm);
@@ -1306,7 +1308,7 @@ void parserCallBack(P_FUNC){
             backToken_(pm, left_token);
             goto return_;
         }
-        addStatementToken(CALLBACK, st, pm);
+        addStatementToken(T_CALLFUNC, st, pm);
         freeToken(left_token, false);
     }
     return_: return;
@@ -1329,7 +1331,7 @@ int getOperation(P_FUNC, int right_type, Statement **st, char *name){
     if (checkToken(pm, right_type))
         goto return_;
 
-    if (!callChildStatement(CP_FUNC, parserOperation, OPERATION, st, NULL))
+    if (!callChildStatement(CP_FUNC, parserOperation, T_OPERATION, st, NULL))
         return 0;
 
     if (!checkToken(pm, right_type)){
@@ -1392,7 +1394,7 @@ void parserBaseValue(P_FUNC){
                 lambda_st = makeStatement(value_token->line, pm->file);
                 goto not_lambda_st;
             }
-            if (!callChildStatement(CP_FUNC, parserOperation, OPERATION, &lambda_st,
+            if (!callChildStatement(CP_FUNC, parserOperation, T_OPERATION, &lambda_st,
                                     "Don't get a lambda operation")) {
                 freeToken(value_token, true);
                 goto return_;
@@ -1406,7 +1408,7 @@ void parserBaseValue(P_FUNC){
             break;
         case MATHER_SVAR: {
             Statement *svar_st = NULL;
-            if (!callChildStatement(CP_FUNC, parserBaseValue, BASEVALUE, &svar_st, NULL)) {
+            if (!callChildStatement(CP_FUNC, parserBaseValue, T_BASEVALUE, &svar_st, NULL)) {
                 syntaxError(pm, syntax_error, value_token->line, 1, "Don't get super var after $");
                 freeToken(value_token, true);
                 goto return_;
@@ -1503,7 +1505,7 @@ void parserBaseValue(P_FUNC){
                 goto return_;
             }
             delToken(pm);
-            if (!callChildStatement(CP_FUNC, parserBaseValue, BASEVALUE, &st, "Don't get Base Value after aut token")) {
+            if (!callChildStatement(CP_FUNC, parserBaseValue, T_BASEVALUE, &st, "Don't get Base Value after aut token")) {
                 freeToken(value_token, true);
                 goto return_;
             }
@@ -1526,7 +1528,7 @@ void parserBaseValue(P_FUNC){
         }
     }
     freeToken(value_token, false);
-    addStatementToken(BASEVALUE, st, pm);
+    addStatementToken(T_BASEVALUE, st, pm);
 
     return_: return;
 }

+ 2 - 1
VirtulMathCore/src/runcall.c

@@ -8,7 +8,7 @@ ResultType setClass(FUNC) {
 
     call = getArgument(st->u.set_class.father, false, CNEXT_NT);
     if (!CHECK_RESULT(result))
-        goto error_;
+        goto error_return;
 
     class_inherit = setFather(call);
     freeArgument(call, false);
@@ -54,6 +54,7 @@ ResultType setClass(FUNC) {
 
     error_:
     gc_freeTmpLink(&tmp->gc_status);
+    error_return:
     setResultErrorSt(E_BaseException, NULL, false, st, CNEXT_NT);
     return result->type;
 }

+ 4 - 3
VirtulMathCore/src/runfile.c

@@ -70,7 +70,8 @@ int checkFileDir(char **file_dir, FUNC) {
         return 1;
 
     {
-        char arr_cwd[200] = {};
+        char *getcwd(char *buf,size_t size);
+        char arr_cwd[200];
         char *p_cwd = NULL;
         getcwd(arr_cwd, 200);
 #ifdef __linux__
@@ -243,7 +244,7 @@ ResultType importFile(FUNC) {
     char *split_path = NULL;
     char *path = NULL;
     LinkValue *imp_value = NULL;
-    char md5_str[MD5_STRING] = {};
+    char md5_str[MD5_STRING];
 
     setResultCore(result);
     gc_freeze(inter, var_list, NULL, true);
@@ -297,7 +298,7 @@ ResultType fromImportFile(FUNC) {
     Statement *file = st->u.from_import_file.file;
     char *split_path = NULL;
     char *path = NULL;
-    char md5_str[MD5_STRING] = {};
+    char md5_str[MD5_STRING];  // TODO-szh 设置为空字符串
     VarList *imp_var = NULL;
     LinkValue *imp_value;
     Parameter *pt = st->u.from_import_file.pt;

+ 2 - 2
VirtulMathCore/src/runoperation.c

@@ -201,7 +201,7 @@ ResultType pointDel(Statement *name, FUNC_NT) {
     }
 
     gc_freeze(inter, var_list, object, true);
-    if (right->type == OPERATION && (right->u.operation.OperationType == OPT_POINT || right->u.operation.OperationType == OPT_LINK))
+    if (right->type == T_OPERATION && (right->u.operation.OperationType == OPT_POINT || right->u.operation.OperationType == OPT_LINK))
         pointDel(name->u.operation.right, CFUNC_NT(object, result, belong));
     else
         delCore(name->u.operation.right, true, CFUNC_NT(object, result, belong));
@@ -433,7 +433,7 @@ ResultType pointAss(Statement *name, LinkValue *value, FUNC_NT) {
     }
 
     gc_freeze(inter, var_list, object, true);
-    if (right->type == OPERATION && (right->u.operation.OperationType == OPT_POINT || right->u.operation.OperationType == OPT_LINK))
+    if (right->type == T_OPERATION && (right->u.operation.OperationType == OPT_POINT || right->u.operation.OperationType == OPT_LINK))
         pointAss(name->u.operation.right, value, CFUNC_NT(object, result, belong));
     else
         assCore(name->u.operation.right, value, true, false, CFUNC_NT(object, result, belong));

+ 1244 - 0
VirtulMathCore/src/win/getopt_win.c

@@ -0,0 +1,1244 @@
+/* Getopt for GNU.
+NOTE: getopt is now part of the C library, so if you don't know what
+"Keep this file name-space clean" means, talk to drepper@gnu.org
+before changing it!
+Copyright (C) 1987,88,89,90,91,92,93,94,95,96,98,99,2000,2001
+Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Lesser General Public License for more details.
+You should have received a copy of the GNU Lesser General Public
+License along with the GNU C Library; if not, write to the Free
+Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.  */
+
+/* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>.
+Ditto for AIX 3.2 and <stdlib.h>.  */
+#ifndef _NO_PROTO
+# define _NO_PROTO
+#endif
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#if !defined __STDC__ || !__STDC__
+/* This is a separate conditional since some stdc systems
+reject `defined (const)'.  */
+# ifndef const
+#  define const
+# endif
+#endif
+
+#include <stdio.h>
+
+/* Comment out all this code if we are using the GNU C Library, and are not
+actually compiling the library itself.  This code is part of the GNU C
+Library, but also included in many other GNU distributions.  Compiling
+and linking in this code is a waste when using the GNU C library
+(especially if it is a shared library).  Rather than having every GNU
+program understand `configure --with-gnu-libc' and omit the object files,
+it is simpler to just do this in the source for each such file.  */
+
+#define GETOPT_INTERFACE_VERSION 2
+#if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2
+# include <gnu-versions.h>
+# if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
+#  define ELIDE_CODE
+# endif
+#endif
+
+#ifndef ELIDE_CODE
+
+
+/* This needs to come after some library #include
+to get __GNU_LIBRARY__ defined.  */
+#ifdef	__GNU_LIBRARY__
+/* Don't include stdlib.h for non-GNU C libraries because some of them
+contain conflicting prototypes for getopt.  */
+# include <stdlib.h>
+# include <unistd.h>
+#endif	/* GNU C library.  */
+
+#ifdef VMS
+# include <unixlib.h>
+# if HAVE_STRING_H - 0
+#  include <string.h>
+# endif
+#endif
+
+#ifndef _
+/* This is for other GNU distributions with internationalized messages.  */
+# if (HAVE_LIBINTL_H && ENABLE_NLS) || defined _LIBC
+#  include <libintl.h>
+#  ifndef _
+#   define _(msgid)	gettext (msgid)
+#  endif
+# else
+#  define _(msgid)	(msgid)
+# endif
+# if defined _LIBC && defined USE_IN_LIBIO
+#  include <wchar.h>
+# endif
+#endif
+
+/* This version of `getopt' appears to the caller like standard Unix `getopt'
+but it behaves differently for the user, since it allows the user
+to intersperse the options with the other arguments.
+As `getopt' works, it permutes the elements of ARGV so that,
+when it is done, all the options precede everything else.  Thus
+all application programs are extended to handle flexible argument order.
+Setting the environment variable POSIXLY_CORRECT disables permutation.
+Then the behavior is completely standard.
+GNU application programs can use a third alternative mode in which
+they can distinguish the relative order of options and other arguments.  */
+
+#include "win/getopt_win.h"
+
+/* For communication from `getopt' to the caller.
+When `getopt' finds an option that takes an argument,
+the argument value is returned here.
+Also, when `ordering' is RETURN_IN_ORDER,
+each non-option ARGV-element is returned here.  */
+
+char* optarg;
+
+/* Index in ARGV of the next element to be scanned.
+This is used for communication to and from the caller
+and for communication between successive calls to `getopt'.
+On entry to `getopt', zero means this is the first call; initialize.
+When `getopt' returns -1, this is the index of the first of the
+non-option elements that the caller should itself scan.
+Otherwise, `optind' communicates from one call to the next
+how much of ARGV has been scanned so far.  */
+
+/* 1003.2 says this must be 1 before any call.  */
+int optind = 1;
+
+/* Formerly, initialization of getopt depended on optind==0, which
+causes problems with re-calling getopt as programs generally don't
+know that. */
+
+int __getopt_initialized;
+
+/* The next char to be scanned in the option-element
+in which the last option character we returned was found.
+This allows us to pick up the scan where we left off.
+If this is zero, or a null string, it means resume the scan
+by advancing to the next ARGV-element.  */
+
+static char* nextchar;
+
+/* Callers store zero here to inhibit the error message
+for unrecognized options.  */
+
+int opterr = 1;
+
+/* Set to an option character which was unrecognized.
+This must be initialized on some systems to avoid linking in the
+system's own getopt implementation.  */
+
+int optopt = '?';
+
+/* Describe how to deal with options that follow non-option ARGV-elements.
+If the caller did not specify anything,
+the default is REQUIRE_ORDER if the environment variable
+POSIXLY_CORRECT is defined, PERMUTE otherwise.
+REQUIRE_ORDER means don't recognize them as options;
+stop option processing when the first non-option is seen.
+This is what Unix does.
+This mode of operation is selected by either setting the environment
+variable POSIXLY_CORRECT, or using `+' as the first character
+of the list of option characters.
+PERMUTE is the default.  We permute the contents of ARGV as we scan,
+so that eventually all the non-options are at the end.  This allows options
+to be given in any order, even with programs that were not written to
+expect this.
+RETURN_IN_ORDER is an option available to programs that were written
+to expect options and other ARGV-elements in any order and that care about
+the ordering of the two.  We describe each non-option ARGV-element
+as if it were the argument of an option with character code 1.
+Using `-' as the first character of the list of option characters
+selects this mode of operation.
+The special argument `--' forces an end of option-scanning regardless
+of the value of `ordering'.  In the case of RETURN_IN_ORDER, only
+`--' can cause `getopt' to return -1 with `optind' != ARGC.  */
+
+static enum
+{
+	REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
+} ordering;
+
+/* Value of POSIXLY_CORRECT environment variable.  */
+static char* posixly_correct;
+
+#ifdef	__GNU_LIBRARY__
+/* We want to avoid inclusion of string.h with non-GNU libraries
+because there are many ways it can cause trouble.
+On some systems, it contains special magic macros that don't work
+in GCC.  */
+# include <string.h>
+# define my_index	strchr
+#else
+
+#define HAVE_STRING_H 1
+# if HAVE_STRING_H
+#  include <string.h>
+# else
+#  include <strings.h>
+# endif
+
+/* Avoid depending on library functions or files
+whose names are inconsistent.  */
+
+#ifndef getenv
+extern char* getenv();
+#endif
+
+static char*
+my_index(str, chr)
+const char* str;
+int chr;
+{
+	while (*str)
+	{
+		if (*str == chr)
+			return (char*)str;
+		str++;
+	}
+	return 0;
+}
+
+/* If using GCC, we can safely declare strlen this way.
+If not using GCC, it is ok not to declare it.  */
+#ifdef __GNUC__
+/* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h.
+That was relevant to code that was here before.  */
+# if (!defined __STDC__ || !__STDC__) && !defined strlen
+/* gcc with -traditional declares the built-in strlen to return int,
+and has done so at least since version 2.4.5. -- rms.  */
+extern int strlen(const char*);
+# endif /* not __STDC__ */
+#endif /* __GNUC__ */
+
+#endif /* not __GNU_LIBRARY__ */
+
+/* Handle permutation of arguments.  */
+
+/* Describe the part of ARGV that contains non-options that have
+been skipped.  `first_nonopt' is the index in ARGV of the first of them;
+`last_nonopt' is the index after the last of them.  */
+
+static int first_nonopt;
+static int last_nonopt;
+
+#ifdef _LIBC
+/* Stored original parameters.
+XXX This is no good solution.  We should rather copy the args so
+that we can compare them later.  But we must not use malloc(3).  */
+extern int __libc_argc;
+extern char** __libc_argv;
+
+/* Bash 2.0 gives us an environment variable containing flags
+indicating ARGV elements that should not be considered arguments.  */
+
+# ifdef USE_NONOPTION_FLAGS
+/* Defined in getopt_init.c  */
+extern char* __getopt_nonoption_flags;
+
+static int nonoption_flags_max_len;
+static int nonoption_flags_len;
+# endif
+
+# ifdef USE_NONOPTION_FLAGS
+#  define SWAP_FLAGS(ch1, ch2) \
+if (nonoption_flags_len > 0)						      \
+{									      \
+	char __tmp = __getopt_nonoption_flags[ch1];			      \
+	__getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2];	      \
+	__getopt_nonoption_flags[ch2] = __tmp;				      \
+}
+# else
+#  define SWAP_FLAGS(ch1, ch2)
+# endif
+#else	/* !_LIBC */
+# define SWAP_FLAGS(ch1, ch2)
+#endif	/* _LIBC */
+
+/* Exchange two adjacent subsequences of ARGV.
+One subsequence is elements [first_nonopt,last_nonopt)
+which contains all the non-options that have been skipped so far.
+The other is elements [last_nonopt,optind), which contains all
+the options processed since those non-options were skipped.
+`first_nonopt' and `last_nonopt' are relocated so that they describe
+the new indices of the non-options in ARGV after they are moved.  */
+
+#if defined __STDC__ && __STDC__
+static void exchange(char**);
+#endif
+
+static void
+exchange(argv)
+char** argv;
+{
+	int bottom = first_nonopt;
+	int middle = last_nonopt;
+	int top = optind;
+	char* tem;
+
+	/* Exchange the shorter segment with the far end of the longer segment.
+	That puts the shorter segment into the right place.
+	It leaves the longer segment in the right place overall,
+	but it consists of two parts that need to be swapped next.  */
+
+#if defined _LIBC && defined USE_NONOPTION_FLAGS
+	/* First make sure the handling of the `__getopt_nonoption_flags'
+	string can work normally.  Our top argument must be in the range
+	of the string.  */
+	if (nonoption_flags_len > 0 && top >= nonoption_flags_max_len)
+	{
+		/* We must extend the array.  The user plays games with us and
+		presents new arguments.  */
+		char* new_str = malloc(top + 1);
+		if (new_str == NULL)
+			nonoption_flags_len = nonoption_flags_max_len = 0;
+		else
+		{
+			memset(__mempcpy(new_str, __getopt_nonoption_flags,
+				nonoption_flags_max_len),
+				'\0', top + 1 - nonoption_flags_max_len);
+			nonoption_flags_max_len = top + 1;
+			__getopt_nonoption_flags = new_str;
+		}
+	}
+#endif
+
+	while (top > middle && middle > bottom)
+	{
+		if (top - middle > middle - bottom)
+		{
+			/* Bottom segment is the short one.  */
+			int len = middle - bottom;
+			register int i;
+
+			/* Swap it with the top part of the top segment.  */
+			for (i = 0; i < len; i++)
+			{
+				tem = argv[bottom + i];
+				argv[bottom + i] = argv[top - (middle - bottom) + i];
+				argv[top - (middle - bottom) + i] = tem;
+				SWAP_FLAGS(bottom + i, top - (middle - bottom) + i);
+			}
+			/* Exclude the moved bottom segment from further swapping.  */
+			top -= len;
+		}
+		else
+		{
+			/* Top segment is the short one.  */
+			int len = top - middle;
+			register int i;
+
+			/* Swap it with the bottom part of the bottom segment.  */
+			for (i = 0; i < len; i++)
+			{
+				tem = argv[bottom + i];
+				argv[bottom + i] = argv[middle + i];
+				argv[middle + i] = tem;
+				SWAP_FLAGS(bottom + i, middle + i);
+			}
+			/* Exclude the moved top segment from further swapping.  */
+			bottom += len;
+		}
+	}
+
+	/* Update records for the slots the non-options now occupy.  */
+
+	first_nonopt += (optind - last_nonopt);
+	last_nonopt = optind;
+}
+
+/* Initialize the internal data when the first call is made.  */
+
+#if defined __STDC__ && __STDC__
+static const char* _getopt_initialize(int, char* const*, const char*);
+#endif
+static const char*
+_getopt_initialize(argc, argv, optstring)
+int argc;
+char* const* argv;
+const char* optstring;
+{
+	/* Start processing options with ARGV-element 1 (since ARGV-element 0
+	is the program name); the sequence of previously skipped
+	non-option ARGV-elements is empty.  */
+
+	first_nonopt = last_nonopt = optind;
+
+	nextchar = NULL;
+
+	posixly_correct = getenv("POSIXLY_CORRECT");
+
+	/* Determine how to handle the ordering of options and nonoptions.  */
+
+	if (optstring[0] == '-')
+	{
+		ordering = RETURN_IN_ORDER;
+		++optstring;
+	}
+	else if (optstring[0] == '+')
+	{
+		ordering = REQUIRE_ORDER;
+		++optstring;
+	}
+	else if (posixly_correct != NULL)
+		ordering = REQUIRE_ORDER;
+	else
+		ordering = PERMUTE;
+
+#if defined _LIBC && defined USE_NONOPTION_FLAGS
+	if (posixly_correct == NULL
+		&& argc == __libc_argc && argv == __libc_argv)
+	{
+		if (nonoption_flags_max_len == 0)
+		{
+			if (__getopt_nonoption_flags == NULL
+				|| __getopt_nonoption_flags[0] == '\0')
+				nonoption_flags_max_len = -1;
+			else
+			{
+				const char* orig_str = __getopt_nonoption_flags;
+				int len = nonoption_flags_max_len = strlen(orig_str);
+				if (nonoption_flags_max_len < argc)
+					nonoption_flags_max_len = argc;
+				__getopt_nonoption_flags =
+					(char*)malloc(nonoption_flags_max_len);
+				if (__getopt_nonoption_flags == NULL)
+					nonoption_flags_max_len = -1;
+				else
+					memset(__mempcpy(__getopt_nonoption_flags, orig_str, len),
+						'\0', nonoption_flags_max_len - len);
+			}
+		}
+		nonoption_flags_len = nonoption_flags_max_len;
+	}
+	else
+		nonoption_flags_len = 0;
+#endif
+
+	return optstring;
+}
+
+/* Scan elements of ARGV (whose length is ARGC) for option characters
+given in OPTSTRING.
+If an element of ARGV starts with '-', and is not exactly "-" or "--",
+then it is an option element.  The characters of this element
+(aside from the initial '-') are option characters.  If `getopt'
+is called repeatedly, it returns successively each of the option characters
+from each of the option elements.
+If `getopt' finds another option character, it returns that character,
+updating `optind' and `nextchar' so that the next call to `getopt' can
+resume the scan with the following option character or ARGV-element.
+If there are no more option characters, `getopt' returns -1.
+Then `optind' is the index in ARGV of the first ARGV-element
+that is not an option.  (The ARGV-elements have been permuted
+so that those that are not options now come last.)
+OPTSTRING is a string containing the legitimate option characters.
+If an option character is seen that is not listed in OPTSTRING,
+return '?' after printing an error message.  If you set `opterr' to
+zero, the error message is suppressed but we still return '?'.
+If a char in OPTSTRING is followed by a colon, that means it wants an arg,
+so the following text in the same ARGV-element, or the text of the following
+ARGV-element, is returned in `optarg'.  Two colons mean an option that
+wants an optional arg; if there is text in the current ARGV-element,
+it is returned in `optarg', otherwise `optarg' is set to zero.
+If OPTSTRING starts with `-' or `+', it requests different methods of
+handling the non-option ARGV-elements.
+See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
+Long-named options begin with `--' instead of `-'.
+Their names may be abbreviated as long as the abbreviation is unique
+or is an exact match for some defined option.  If they have an
+argument, it follows the option name in the same ARGV-element, separated
+from the option name by a `=', or else the in next ARGV-element.
+When `getopt' finds a long-named option, it returns 0 if that option's
+`flag' field is nonzero, the value of the option's `val' field
+if the `flag' field is zero.
+The elements of ARGV aren't really const, because we permute them.
+But we pretend they're const in the prototype to be compatible
+with other systems.
+LONGOPTS is a vector of `struct option' terminated by an
+element containing a name which is zero.
+LONGIND returns the index in LONGOPT of the long-named option found.
+It is only valid when a long-named option has been found by the most
+recent call.
+If LONG_ONLY is nonzero, '-' as well as '--' can introduce
+long-named options.  */
+
+int
+_getopt_internal(argc, argv, optstring, longopts, longind, long_only)
+int argc;
+char* const* argv;
+const char* optstring;
+const struct option* longopts;
+int* longind;
+int long_only;
+{
+	int print_errors = opterr;
+	if (optstring[0] == ':')
+		print_errors = 0;
+
+	if (argc < 1)
+		return -1;
+
+	optarg = NULL;
+
+	if (optind == 0 || !__getopt_initialized)
+	{
+		if (optind == 0)
+			optind = 1;	/* Don't scan ARGV[0], the program name.  */
+		optstring = _getopt_initialize(argc, argv, optstring);
+		__getopt_initialized = 1;
+	}
+
+	/* Test whether ARGV[optind] points to a non-option argument.
+	Either it does not have option syntax, or there is an environment flag
+	from the shell indicating it is not an option.  The later information
+	is only used when the used in the GNU libc.  */
+#if defined _LIBC && defined USE_NONOPTION_FLAGS
+# define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0'	      \
+	|| (optind < nonoption_flags_len			      \
+	&& __getopt_nonoption_flags[optind] == '1'))
+#else
+# define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0')
+#endif
+
+	if (nextchar == NULL || *nextchar == '\0')
+	{
+		/* Advance to the next ARGV-element.  */
+
+		/* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been
+		moved back by the user (who may also have changed the arguments).  */
+		if (last_nonopt > optind)
+			last_nonopt = optind;
+		if (first_nonopt > optind)
+			first_nonopt = optind;
+
+		if (ordering == PERMUTE)
+		{
+			/* If we have just processed some options following some non-options,
+			exchange them so that the options come first.  */
+
+			if (first_nonopt != last_nonopt && last_nonopt != optind)
+				exchange((char**)argv);
+			else if (last_nonopt != optind)
+				first_nonopt = optind;
+
+			/* Skip any additional non-options
+			and extend the range of non-options previously skipped.  */
+
+			while (optind < argc && NONOPTION_P)
+				optind++;
+			last_nonopt = optind;
+		}
+
+		/* The special ARGV-element `--' means premature end of options.
+		Skip it like a null option,
+		then exchange with previous non-options as if it were an option,
+		then skip everything else like a non-option.  */
+
+		if (optind != argc && !strcmp(argv[optind], "--"))
+		{
+			optind++;
+
+			if (first_nonopt != last_nonopt && last_nonopt != optind)
+				exchange((char**)argv);
+			else if (first_nonopt == last_nonopt)
+				first_nonopt = optind;
+			last_nonopt = argc;
+
+			optind = argc;
+		}
+
+		/* If we have done all the ARGV-elements, stop the scan
+		and back over any non-options that we skipped and permuted.  */
+
+		if (optind == argc)
+		{
+			/* Set the next-arg-index to point at the non-options
+			that we previously skipped, so the caller will digest them.  */
+			if (first_nonopt != last_nonopt)
+				optind = first_nonopt;
+			return -1;
+		}
+
+		/* If we have come to a non-option and did not permute it,
+		either stop the scan or describe it to the caller and pass it by.  */
+
+		if (NONOPTION_P)
+		{
+			if (ordering == REQUIRE_ORDER)
+				return -1;
+			optarg = argv[optind++];
+			return 1;
+		}
+
+		/* We have found another option-ARGV-element.
+		Skip the initial punctuation.  */
+
+		nextchar = (argv[optind] + 1
+			+ (longopts != NULL && argv[optind][1] == '-'));
+	}
+
+	/* Decode the current option-ARGV-element.  */
+
+	/* Check whether the ARGV-element is a long option.
+	If long_only and the ARGV-element has the form "-f", where f is
+	a valid short option, don't consider it an abbreviated form of
+	a long option that starts with f.  Otherwise there would be no
+	way to give the -f short option.
+	On the other hand, if there's a long option "fubar" and
+	the ARGV-element is "-fu", do consider that an abbreviation of
+	the long option, just like "--fu", and not "-f" with arg "u".
+	This distinction seems to be the most useful approach.  */
+
+	if (longopts != NULL
+		&& (argv[optind][1] == '-'
+			|| (long_only && (argv[optind][2] || !my_index(optstring, argv[optind][1])))))
+	{
+		char* nameend;
+		const struct option* p;
+		const struct option* pfound = NULL;
+		int exact = 0;
+		int ambig = 0;
+		int indfound = -1;
+		int option_index;
+
+		for (nameend = nextchar; *nameend && *nameend != '='; nameend++)
+			/* Do nothing.  */;
+
+		/* Test all long options for either exact match
+		or abbreviated matches.  */
+		for (p = longopts, option_index = 0; p->name; p++, option_index++)
+			if (!strncmp(p->name, nextchar, nameend - nextchar))
+			{
+				if ((unsigned int)(nameend - nextchar)
+					== (unsigned int)strlen(p->name))
+				{
+					/* Exact match found.  */
+					pfound = p;
+					indfound = option_index;
+					exact = 1;
+					break;
+				}
+				else if (pfound == NULL)
+				{
+					/* First nonexact match found.  */
+					pfound = p;
+					indfound = option_index;
+				}
+				else if (long_only
+					|| pfound->has_arg != p->has_arg
+					|| pfound->flag != p->flag
+					|| pfound->val != p->val)
+					/* Second or later nonexact match found.  */
+					ambig = 1;
+			}
+
+		if (ambig && !exact)
+		{
+			if (print_errors)
+			{
+#if defined _LIBC && defined USE_IN_LIBIO
+				char* buf;
+
+				__asprintf(&buf, _("%s: option `%s' is ambiguous\n"),
+					argv[0], argv[optind]);
+
+				if (_IO_fwide(stderr, 0) > 0)
+					__fwprintf(stderr, L"%s", buf);
+				else
+					fputs(buf, stderr);
+
+				free(buf);
+#else
+				fprintf(stderr, _("%s: option `%s' is ambiguous\n"),
+					argv[0], argv[optind]);
+#endif
+			}
+			nextchar += strlen(nextchar);
+			optind++;
+			optopt = 0;
+			return '?';
+		}
+
+		if (pfound != NULL)
+		{
+			option_index = indfound;
+			optind++;
+			if (*nameend)
+			{
+				/* Don't test has_arg with >, because some C compilers don't
+				allow it to be used on enums.  */
+				if (pfound->has_arg)
+					optarg = nameend + 1;
+				else
+				{
+					if (print_errors)
+					{
+#if defined _LIBC && defined USE_IN_LIBIO
+						char* buf;
+#endif
+
+						if (argv[optind - 1][1] == '-')
+						{
+							/* --option */
+#if defined _LIBC && defined USE_IN_LIBIO
+							__asprintf(&buf, _("\
+											   %s: option `--%s' doesn't allow an argument\n"),
+								argv[0], pfound->name);
+#else
+							fprintf(stderr, _("\
+											  %s: option `--%s' doesn't allow an argument\n"),
+								argv[0], pfound->name);
+#endif
+						}
+						else
+						{
+							/* +option or -option */
+#if defined _LIBC && defined USE_IN_LIBIO
+							__asprintf(&buf, _("\
+											   %s: option `%c%s' doesn't allow an argument\n"),
+								argv[0], argv[optind - 1][0],
+								pfound->name);
+#else
+							fprintf(stderr, _("\
+											  %s: option `%c%s' doesn't allow an argument\n"),
+								argv[0], argv[optind - 1][0], pfound->name);
+#endif
+						}
+
+#if defined _LIBC && defined USE_IN_LIBIO
+						if (_IO_fwide(stderr, 0) > 0)
+							__fwprintf(stderr, L"%s", buf);
+						else
+							fputs(buf, stderr);
+
+						free(buf);
+#endif
+					}
+
+					nextchar += strlen(nextchar);
+
+					optopt = pfound->val;
+					return '?';
+				}
+			}
+			else if (pfound->has_arg == 1)
+			{
+				if (optind < argc)
+					optarg = argv[optind++];
+				else
+				{
+					if (print_errors)
+					{
+#if defined _LIBC && defined USE_IN_LIBIO
+						char* buf;
+
+						__asprintf(&buf,
+							_("%s: option `%s' requires an argument\n"),
+							argv[0], argv[optind - 1]);
+
+						if (_IO_fwide(stderr, 0) > 0)
+							__fwprintf(stderr, L"%s", buf);
+						else
+							fputs(buf, stderr);
+
+						free(buf);
+#else
+						fprintf(stderr,
+							_("%s: option `%s' requires an argument\n"),
+							argv[0], argv[optind - 1]);
+#endif
+					}
+					nextchar += strlen(nextchar);
+					optopt = pfound->val;
+					return optstring[0] == ':' ? ':' : '?';
+				}
+			}
+			nextchar += strlen(nextchar);
+			if (longind != NULL)
+				*longind = option_index;
+			if (pfound->flag)
+			{
+				*(pfound->flag) = pfound->val;
+				return 0;
+			}
+			return pfound->val;
+		}
+
+		/* Can't find it as a long option.  If this is not getopt_long_only,
+		or the option starts with '--' or is not a valid short
+		option, then it's an error.
+		Otherwise interpret it as a short option.  */
+		if (!long_only || argv[optind][1] == '-'
+			|| my_index(optstring, *nextchar) == NULL)
+		{
+			if (print_errors)
+			{
+#if defined _LIBC && defined USE_IN_LIBIO
+				char* buf;
+#endif
+
+				if (argv[optind][1] == '-')
+				{
+					/* --option */
+#if defined _LIBC && defined USE_IN_LIBIO
+					__asprintf(&buf, _("%s: unrecognized option `--%s'\n"),
+						argv[0], nextchar);
+#else
+					fprintf(stderr, _("%s: unrecognized option `--%s'\n"),
+						argv[0], nextchar);
+#endif
+				}
+				else
+				{
+					/* +option or -option */
+#if defined _LIBC && defined USE_IN_LIBIO
+					__asprintf(&buf, _("%s: unrecognized option `%c%s'\n"),
+						argv[0], argv[optind][0], nextchar);
+#else
+					fprintf(stderr, _("%s: unrecognized option `%c%s'\n"),
+						argv[0], argv[optind][0], nextchar);
+#endif
+				}
+
+#if defined _LIBC && defined USE_IN_LIBIO
+				if (_IO_fwide(stderr, 0) > 0)
+					__fwprintf(stderr, L"%s", buf);
+				else
+					fputs(buf, stderr);
+
+				free(buf);
+#endif
+			}
+			nextchar = (char*)"";
+			optind++;
+			optopt = 0;
+			return '?';
+		}
+	}
+
+	/* Look at and handle the next short option-character.  */
+
+	{
+		char c = *nextchar++;
+		char* temp = my_index(optstring, c);
+
+		/* Increment `optind' when we start to process its last character.  */
+		if (*nextchar == '\0')
+			++optind;
+
+		if (temp == NULL || c == ':')
+		{
+			if (print_errors)
+			{
+#if defined _LIBC && defined USE_IN_LIBIO
+				char* buf;
+#endif
+
+				if (posixly_correct)
+				{
+					/* 1003.2 specifies the format of this message.  */
+#if defined _LIBC && defined USE_IN_LIBIO
+					__asprintf(&buf, _("%s: illegal option -- %c\n"),
+						argv[0], c);
+#else
+					fprintf(stderr, _("%s: illegal option -- %c\n"), argv[0], c);
+#endif
+				}
+				else
+				{
+#if defined _LIBC && defined USE_IN_LIBIO
+					__asprintf(&buf, _("%s: invalid option -- %c\n"),
+						argv[0], c);
+#else
+					fprintf(stderr, _("%s: invalid option -- %c\n"), argv[0], c);
+#endif
+				}
+
+#if defined _LIBC && defined USE_IN_LIBIO
+				if (_IO_fwide(stderr, 0) > 0)
+					__fwprintf(stderr, L"%s", buf);
+				else
+					fputs(buf, stderr);
+
+				free(buf);
+#endif
+			}
+			optopt = c;
+			return '?';
+		}
+		/* Convenience. Treat POSIX -W foo same as long option --foo */
+		if (temp[0] == 'W' && temp[1] == ';')
+		{
+			char* nameend;
+			const struct option* p;
+			const struct option* pfound = NULL;
+			int exact = 0;
+			int ambig = 0;
+			int indfound = 0;
+			int option_index;
+
+			/* This is an option that requires an argument.  */
+			if (*nextchar != '\0')
+			{
+				optarg = nextchar;
+				/* If we end this ARGV-element by taking the rest as an arg,
+				we must advance to the next element now.  */
+				optind++;
+			}
+			else if (optind == argc)
+			{
+				if (print_errors)
+				{
+					/* 1003.2 specifies the format of this message.  */
+#if defined _LIBC && defined USE_IN_LIBIO
+					char* buf;
+
+					__asprintf(&buf, _("%s: option requires an argument -- %c\n"),
+						argv[0], c);
+
+					if (_IO_fwide(stderr, 0) > 0)
+						__fwprintf(stderr, L"%s", buf);
+					else
+						fputs(buf, stderr);
+
+					free(buf);
+#else
+					fprintf(stderr, _("%s: option requires an argument -- %c\n"),
+						argv[0], c);
+#endif
+				}
+				optopt = c;
+				if (optstring[0] == ':')
+					c = ':';
+				else
+					c = '?';
+				return c;
+			}
+			else
+				/* We already incremented `optind' once;
+				increment it again when taking next ARGV-elt as argument.  */
+				optarg = argv[optind++];
+
+			/* optarg is now the argument, see if it's in the
+			table of longopts.  */
+
+			for (nextchar = nameend = optarg; *nameend && *nameend != '='; nameend++)
+				/* Do nothing.  */;
+
+			/* Test all long options for either exact match
+			or abbreviated matches.  */
+			for (p = longopts, option_index = 0; p->name; p++, option_index++)
+				if (!strncmp(p->name, nextchar, nameend - nextchar))
+				{
+					if ((unsigned int)(nameend - nextchar) == strlen(p->name))
+					{
+						/* Exact match found.  */
+						pfound = p;
+						indfound = option_index;
+						exact = 1;
+						break;
+					}
+					else if (pfound == NULL)
+					{
+						/* First nonexact match found.  */
+						pfound = p;
+						indfound = option_index;
+					}
+					else
+						/* Second or later nonexact match found.  */
+						ambig = 1;
+				}
+			if (ambig && !exact)
+			{
+				if (print_errors)
+				{
+#if defined _LIBC && defined USE_IN_LIBIO
+					char* buf;
+
+					__asprintf(&buf, _("%s: option `-W %s' is ambiguous\n"),
+						argv[0], argv[optind]);
+
+					if (_IO_fwide(stderr, 0) > 0)
+						__fwprintf(stderr, L"%s", buf);
+					else
+						fputs(buf, stderr);
+
+					free(buf);
+#else
+					fprintf(stderr, _("%s: option `-W %s' is ambiguous\n"),
+						argv[0], argv[optind]);
+#endif
+				}
+				nextchar += strlen(nextchar);
+				optind++;
+				return '?';
+			}
+			if (pfound != NULL)
+			{
+				option_index = indfound;
+				if (*nameend)
+				{
+					/* Don't test has_arg with >, because some C compilers don't
+					allow it to be used on enums.  */
+					if (pfound->has_arg)
+						optarg = nameend + 1;
+					else
+					{
+						if (print_errors)
+						{
+#if defined _LIBC && defined USE_IN_LIBIO
+							char* buf;
+
+							__asprintf(&buf, _("\
+											   %s: option `-W %s' doesn't allow an argument\n"),
+								argv[0], pfound->name);
+
+							if (_IO_fwide(stderr, 0) > 0)
+								__fwprintf(stderr, L"%s", buf);
+							else
+								fputs(buf, stderr);
+
+							free(buf);
+#else
+							fprintf(stderr, _("\
+											  %s: option `-W %s' doesn't allow an argument\n"),
+								argv[0], pfound->name);
+#endif
+						}
+
+						nextchar += strlen(nextchar);
+						return '?';
+					}
+				}
+				else if (pfound->has_arg == 1)
+				{
+					if (optind < argc)
+						optarg = argv[optind++];
+					else
+					{
+						if (print_errors)
+						{
+#if defined _LIBC && defined USE_IN_LIBIO
+							char* buf;
+
+							__asprintf(&buf, _("\
+											   %s: option `%s' requires an argument\n"),
+								argv[0], argv[optind - 1]);
+
+							if (_IO_fwide(stderr, 0) > 0)
+								__fwprintf(stderr, L"%s", buf);
+							else
+								fputs(buf, stderr);
+
+							free(buf);
+#else
+							fprintf(stderr,
+								_("%s: option `%s' requires an argument\n"),
+								argv[0], argv[optind - 1]);
+#endif
+						}
+						nextchar += strlen(nextchar);
+						return optstring[0] == ':' ? ':' : '?';
+					}
+				}
+				nextchar += strlen(nextchar);
+				if (longind != NULL)
+					*longind = option_index;
+				if (pfound->flag)
+				{
+					*(pfound->flag) = pfound->val;
+					return 0;
+				}
+				return pfound->val;
+			}
+			nextchar = NULL;
+			return 'W';	/* Let the application handle it.   */
+		}
+		if (temp[1] == ':')
+		{
+			if (temp[2] == ':')
+			{
+				/* This is an option that accepts an argument optionally.  */
+				if (*nextchar != '\0')
+				{
+					optarg = nextchar;
+					optind++;
+				}
+				else
+					optarg = NULL;
+				nextchar = NULL;
+			}
+			else
+			{
+				/* This is an option that requires an argument.  */
+				if (*nextchar != '\0')
+				{
+					optarg = nextchar;
+					/* If we end this ARGV-element by taking the rest as an arg,
+					we must advance to the next element now.  */
+					optind++;
+				}
+				else if (optind == argc)
+				{
+					if (print_errors)
+					{
+						/* 1003.2 specifies the format of this message.  */
+#if defined _LIBC && defined USE_IN_LIBIO
+						char* buf;
+
+						__asprintf(&buf,
+							_("%s: option requires an argument -- %c\n"),
+							argv[0], c);
+
+						if (_IO_fwide(stderr, 0) > 0)
+							__fwprintf(stderr, L"%s", buf);
+						else
+							fputs(buf, stderr);
+
+						free(buf);
+#else
+						fprintf(stderr,
+							_("%s: option requires an argument -- %c\n"),
+							argv[0], c);
+#endif
+					}
+					optopt = c;
+					if (optstring[0] == ':')
+						c = ':';
+					else
+						c = '?';
+				}
+				else
+					/* We already incremented `optind' once;
+					increment it again when taking next ARGV-elt as argument.  */
+					optarg = argv[optind++];
+				nextchar = NULL;
+			}
+		}
+		return c;
+	}
+}
+
+int
+getopt(argc, argv, optstring)
+int argc;
+char* const* argv;
+const char* optstring;
+{
+	return _getopt_internal(argc, argv, optstring,
+		(const struct option*)0,
+		(int*)0,
+		0);
+}
+
+
+
+
+int
+getopt_long(int argc, char* const* argv, const char* options,
+	const struct option* long_options, int* opt_index)
+{
+	return _getopt_internal(argc, argv, options, long_options, opt_index, 0, 0);
+}
+
+int
+getopt_long_only(int argc, char* const* argv, const char* options,
+	const struct option* long_options, int* opt_index)
+{
+	return _getopt_internal(argc, argv, options, long_options, opt_index, 1, 0);
+}
+
+
+
+
+
+#endif	/* Not ELIDE_CODE.  */
+
+#ifdef TEST
+
+/* Compile with -DTEST to make an executable for use in testing
+the above definition of `getopt'.  */
+
+int
+main(argc, argv)
+int argc;
+char** argv;
+{
+	int c;
+	int digit_optind = 0;
+
+	while (1)
+	{
+		int this_option_optind = optind ? optind : 1;
+
+		c = getopt(argc, argv, "abc:d:0123456789");
+		if (c == -1)
+			break;
+
+		switch (c)
+		{
+		case '0':
+		case '1':
+		case '2':
+		case '3':
+		case '4':
+		case '5':
+		case '6':
+		case '7':
+		case '8':
+		case '9':
+			if (digit_optind != 0 && digit_optind != this_option_optind)
+				printf("digits occur in two different argv-elements.\n");
+			digit_optind = this_option_optind;
+			printf("option %c\n", c);
+			break;
+
+		case 'a':
+			printf("option a\n");
+			break;
+
+		case 'b':
+			printf("option b\n");
+			break;
+
+		case 'c':
+			printf("option c with value `%s'\n", optarg);
+			break;
+
+		case '?':
+			break;
+
+		default:
+			printf("?? getopt returned character code 0%o ??\n", c);
+		}
+	}
+
+	if (optind < argc)
+	{
+		printf("non-option ARGV-elements: ");
+		while (optind < argc)
+			printf("%s ", argv[optind++]);
+		printf("\n");
+	}
+
+	exit(0);
+}
+
+#endif /* TEST */