• R/O
  • SSH
  • HTTPS

ttssh2: 提交


Commit MetaInfo

修订版8652 (tree)
时间2020-03-30 01:34:55
作者zmatsuo

Log Message

マクロ内の識別子に関するいくつかの上限をなくした

- 変数(ラベルも含む)の数の上限

- 変更前の上限
- 整数変数 256+4個
- 文字列変数 256+20個
- 整数配列変数 256個
- 文字列配列変数 256個
- ラベルの個数 512個

- 識別子長上限 (MaxNameLen)

- 変更前の上限
- 32バイト

- 文字列変数に格納できる文字長上限 (MaxStrLen)

- 変更前の上限
- 512バイト(文字列終端'\0'含む)

更改概述

差异

--- branches/unicode_macro_2/teraterm/ttpmacro/ttmparse.c (revision 8651)
+++ branches/unicode_macro_2/teraterm/ttpmacro/ttmparse.c (revision 8652)
@@ -1,6 +1,6 @@
11 /*
22 * Copyright (C) 1994-1998 T. Teranishi
3- * (C) 2005-2019 TeraTerm Project
3+ * (C) 2005-2020 TeraTerm Project
44 * All rights reserved.
55 *
66 * Redistribution and use in source and binary forms, with or without
@@ -59,9 +59,16 @@
5959
6060 typedef struct {
6161 int size;
62- PStrVal val;
62+// PStrVal val;
63+ char **val;
6364 } TStrAry, *PStrAry;
6465
66+typedef struct {
67+ BINT val;
68+ WORD level;
69+} TLab;
70+
71+#if 0
6572 // 変数の個数を128->256、ラベルの個数を256->512へ拡張した。(2006.2.1 yutaka)
6673 // 変数の個数を、InitTTL で作っているシステム変数の分だけ追加した。(2006.7.26 maya)
6774 #define MaxNumOfIntVar (LONG)(256+4)
@@ -90,8 +97,33 @@
9097 static HANDLE HStrBuff;
9198 static PCHAR StrBuff;
9299 static WORD IntVarCount, StrVarCount, LabVarCount, IntAryVarCount, StrAryVarCount;
100+#endif
93101
102+typedef enum {
103+ TypeUnknown = TypUnknown,
104+ TypeInteger = TypInteger,
105+ //TypeLogical = TypLogical,
106+ TypeString = TypString,
107+ TypeLabel = TypLabel,
108+ TypeIntArray = TypIntArray,
109+ TypeStrArray = TypStrArray,
110+} VariableType_t;
94111
112+typedef struct {
113+ char *Name;
114+ VariableType_t Type;
115+ union {
116+ char *Str;
117+ int Int;
118+ TLab Lab;
119+ TIntAry IntAry;
120+ TStrAry StrAry;
121+ } Value;
122+} Variable_t;
123+
124+static Variable_t *Variables;
125+static int VariableCount;
126+
95127 // トークンの解析開始位置を更新する。
96128 static void UpdateLineParsePtr(void)
97129 {
@@ -101,6 +133,7 @@
101133
102134 BOOL InitVar()
103135 {
136+#if 0
104137 HNameBuff = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT,NameBuffLen);
105138 if (HNameBuff==NULL) return FALSE;
106139 NameBuff = NULL;
@@ -113,13 +146,21 @@
113146 LabVarCount = 0;
114147 StrVarCount = 0;
115148 return TRUE;
149+#else
150+ Variables = NULL;
151+ VariableCount = 0;
152+ return TRUE;
153+#endif
116154 }
117155
118156 void EndVar()
119157 {
158+#if 0
120159 UnlockVar();
121160 GlobalFree(HNameBuff);
122161 GlobalFree(HStrBuff);
162+#endif
163+ // TODO Variables をすべて free する
123164 }
124165
125166 void DispErr(WORD Err)
@@ -168,6 +209,7 @@
168209
169210 void LockVar()
170211 {
212+#if 0
171213 if (NameBuff==NULL)
172214 NameBuff = GlobalLock(HNameBuff);
173215 if (NameBuff==NULL)
@@ -177,10 +219,12 @@
177219 StrBuff = GlobalLock(HStrBuff);
178220 if (StrBuff==NULL)
179221 PostQuitMessage(0);
222+#endif
180223 }
181224
182225 void UnlockVar()
183226 {
227+#if 0
184228 if (NameBuff!=NULL)
185229 GlobalUnlock(HNameBuff);
186230 NameBuff = NULL;
@@ -188,6 +232,7 @@
188232 if (StrBuff!=NULL)
189233 GlobalUnlock(HStrBuff);
190234 StrBuff = NULL;
235+#endif
191236 }
192237
193238 BOOL CheckReservedWord(PCHAR Str, LPWORD WordId)
@@ -858,6 +903,7 @@
858903
859904 BOOL CheckVar(PCHAR Name, LPWORD VarType, PVarId VarId)
860905 {
906+#if 0
861907 int i;
862908 long P;
863909
@@ -909,10 +955,40 @@
909955 }
910956
911957 return FALSE;
958+#else
959+ int i;
960+ const Variable_t *v = Variables;
961+ for (i = 0; i < VariableCount; v++,i++) {
962+ if (_stricmp(v->Name, Name) == 0) {
963+ *VarType = v->Type;
964+ *VarId = (TVarId)i;
965+ return TRUE;
966+ }
967+ }
968+ *VarType = TypUnknown;
969+ *VarId = 0;
970+ return FALSE;
971+#endif
912972 }
913973
974+static Variable_t *NewVar(const char *name, VariableType_t type)
975+{
976+ Variable_t *new_v = realloc(Variables, sizeof(Variable_t) * (VariableCount + 1));
977+ if (new_v == NULL) {
978+ // TODO メモリがない
979+ return NULL;
980+ };
981+ Variables = new_v;
982+ Variable_t *v = &Variables[VariableCount];
983+ VariableCount++;
984+ v->Name = strdup(name);
985+ v->Type = type;
986+ return v;
987+}
988+
914989 BOOL NewIntVar(PCHAR Name, int InitVal)
915990 {
991+#if 0
916992 long P;
917993
918994 if (IntVarCount>=MaxNumOfIntVar) return FALSE;
@@ -921,10 +997,16 @@
921997 IntVal[IntVarCount] = InitVal;
922998 IntVarCount++;
923999 return TRUE;
1000+#else
1001+ Variable_t *v = NewVar(Name, TypeInteger);
1002+ v->Value.Int = InitVal;
1003+ return TRUE;
1004+#endif
9241005 }
9251006
9261007 BOOL NewStrVar(PCHAR Name, PCHAR InitVal)
9271008 {
1009+#if 0
9281010 long P;
9291011
9301012 if (StrVarCount>=MaxNumOfStrVar) return FALSE;
@@ -934,10 +1016,16 @@
9341016 strncpy_s(&StrBuff[P],MaxStrLen,InitVal,_TRUNCATE);
9351017 StrVarCount++;
9361018 return TRUE;
1019+#else
1020+ Variable_t *v = NewVar(Name, TypeString);
1021+ v->Value.Str = strdup(InitVal);
1022+ return TRUE;
1023+#endif
9371024 }
9381025
9391026 int NewIntAryVar(PCHAR Name, int size)
9401027 {
1028+#if 0
9411029 long P;
9421030 if (IntAryVarCount >= MaxNumOfIntAryVar) return ErrTooManyVar;
9431031 if (size <= 0 || size > 65536) return ErrOutOfRange;
@@ -950,10 +1038,22 @@
9501038
9511039 IntAryVarCount++;
9521040 return 0;
1041+#else
1042+ Variable_t *v = NewVar(Name, TypeIntArray);
1043+ TIntAry *intAry = &v->Value.IntAry;
1044+ int *array = calloc(size, sizeof(int));
1045+ if (array == NULL) {
1046+ return ErrFewMemory;
1047+ }
1048+ intAry->val = array;
1049+ intAry->size = size;
1050+ return 0;
1051+#endif
9531052 }
9541053
9551054 int NewStrAryVar(PCHAR Name, int size)
9561055 {
1056+#if 0
9571057 long P;
9581058 if (StrAryVarCount >= MaxNumOfStrAryVar) return ErrTooManyVar;
9591059 if (size <= 0 || size > 65536) return ErrOutOfRange;
@@ -966,10 +1066,22 @@
9661066
9671067 StrAryVarCount++;
9681068 return 0;
1069+#else
1070+ Variable_t *v = NewVar(Name, TypeStrArray);
1071+ TStrAry *strAry = &v->Value.StrAry;
1072+ char **array = calloc(size, sizeof(char *));
1073+ if (array == NULL) {
1074+ return ErrFewMemory;
1075+ }
1076+ strAry->val = array;
1077+ strAry->size = size;
1078+ return 0;
1079+#endif
9691080 }
9701081
9711082 BOOL NewLabVar(PCHAR Name, BINT InitVal, WORD ILevel)
9721083 {
1084+#if 0
9731085 long P;
9741086
9751087 if (LabVarCount>=MaxNumOfLabVar) return FALSE;
@@ -980,18 +1092,59 @@
9801092 LabLevel[LabVarCount] = LOBYTE(ILevel);
9811093 LabVarCount++;
9821094 return TRUE;
1095+#else
1096+ Variable_t *v = NewVar(Name, TypeLabel);
1097+ TLab *lab = &v->Value.Lab;
1098+ lab->val = InitVal;
1099+ lab->level = ILevel;
1100+ return TRUE;
1101+#endif
9831102 }
9841103
9851104 void DelLabVar(WORD ILevel)
9861105 {
1106+#if 0
9871107 while ((LabVarCount>0) && (LabLevel[LabVarCount-1]>=ILevel))
9881108 LabVarCount--;
1109+#else
1110+ Variable_t *v = Variables;
1111+ for (;;) {
1112+ if (v == &Variables[VariableCount]) {
1113+ // 最後まで来た
1114+ break;
1115+ }
1116+ if (v->Type == TypeLabel) {
1117+ if (v->Value.Lab.level >= ILevel) {
1118+ size_t left;
1119+ // 削除する
1120+ free(v->Name);
1121+ // 後ろを前につめる
1122+ left = &Variables[VariableCount - 1] - v;
1123+ if (left > 0) {
1124+ memmove(v, v+1, sizeof(Variable_t) * left);
1125+ }
1126+ // 1つ減る
1127+ VariableCount--;
1128+
1129+ continue;
1130+ }
1131+ }
1132+ v++;
1133+ }
1134+ Variables = realloc(Variables, sizeof(Variable_t) * VariableCount);
1135+#endif
9891136 }
9901137
9911138 void CopyLabel(WORD ILabel, BINT far *Ptr, LPWORD Level)
9921139 {
1140+#if 0
9931141 *Ptr = LabVal[ILabel];
9941142 *Level = (WORD)LabLevel[ILabel];
1143+#else
1144+ Variable_t *v = &Variables[ILabel];
1145+ *Ptr = v->Value.Lab.val;
1146+ *Level = v->Value.Lab.level;
1147+#endif
9951148 }
9961149
9971150 /*
@@ -1028,14 +1181,28 @@
10281181 }
10291182 else if (CheckVar(Name, ValType, &VarId)) {
10301183 switch (*ValType) {
1184+#if 0
10311185 case TypInteger: *Val = IntVal[VarId]; break;
1186+#else
1187+ case TypInteger:
1188+ *Val = Variables[VarId].Value.Int;
1189+ break;
1190+#endif
10321191 case TypString: *Val = VarId; break;
10331192 case TypIntArray:
10341193 if (GetIndex(&Index, Err)) {
1194+#if 0
10351195 if (Index >= 0 && Index < IntAryVal[VarId].size) {
10361196 *Val = IntAryVal[VarId].val[Index];
10371197 *ValType = TypInteger;
10381198 }
1199+#else
1200+ TIntAry *intAry = &Variables[VarId].Value.IntAry;
1201+ if (Index >= 0 && Index < intAry->size) {
1202+ *Val = intAry->val[Index];
1203+ *ValType = TypInteger;
1204+ }
1205+#endif
10391206 else {
10401207 *Err = ErrOutOfRange;
10411208 }
@@ -1664,6 +1831,7 @@
16641831
16651832 void SetIntVal(TVarId VarId, int Val)
16661833 {
1834+#if 0
16671835 if (VarId >> 16) {
16681836 IntAryVal[(VarId>>16)-1].val[VarId & 0xffff] = Val;
16691837 }
@@ -1670,10 +1838,22 @@
16701838 else {
16711839 IntVal[VarId] = Val;
16721840 }
1841+#else
1842+ if (VarId >> 16) {
1843+ Variable_t *v = &Variables[(VarId>>16)-1];
1844+ int *int_val = &v->Value.IntAry.val[VarId & 0xffff];
1845+ *int_val = Val;
1846+ }
1847+ else {
1848+ Variable_t *v = &Variables[VarId];
1849+ v->Value.Int = Val;
1850+ }
1851+#endif
16731852 }
16741853
16751854 int CopyIntVal(TVarId VarId)
16761855 {
1856+#if 0
16771857 if (VarId >> 16) {
16781858 return IntAryVal[(VarId>>16)-1].val[VarId & 0xffff];
16791859 }
@@ -1680,6 +1860,17 @@
16801860 else {
16811861 return IntVal[VarId];
16821862 }
1863+#else
1864+ Variable_t *v;
1865+ if (VarId >> 16) {
1866+ v = &Variables[(VarId>>16)-1];
1867+ return v->Value.IntAry.val[VarId & 0xffff];
1868+ }
1869+ else {
1870+ v = &Variables[VarId];
1871+ return v->Value.Int;
1872+ }
1873+#endif
16831874 }
16841875
16851876 void GetIntVar(PVarId VarId, LPWORD Err)
@@ -1792,13 +1983,29 @@
17921983
17931984 void SetStrVal(TVarId VarId, const char *Str)
17941985 {
1986+#if 0
17951987 // StrBuf の運用上 MaxStrLen が正しいサイズなのでサイズを固定
17961988 // (2007.6.23 maya)
17971989 strncpy_s(StrVarPtr(VarId), MaxStrLen, Str, _TRUNCATE);
1990+#else
1991+ if (VarId >> 16) {
1992+ Variable_t *v = &Variables[(VarId>>16)-1];
1993+ char **str = &v->Value.StrAry.val[VarId & 0xffff];
1994+ free(*str);
1995+ *str = strdup(Str);
1996+ }
1997+ else {
1998+ Variable_t *v = &Variables[VarId];
1999+ char **str = &v->Value.Str;
2000+ free(*str);
2001+ *str = strdup(Str);
2002+ }
2003+#endif
17982004 }
17992005
18002006 PCHAR StrVarPtr(TVarId VarId)
18012007 {
2008+#if 0
18022009 if (VarId >> 16) {
18032010 return StrAryVal[(VarId>>16)-1].val[VarId & 0xffff];
18042011 }
@@ -1805,6 +2012,17 @@
18052012 else {
18062013 return &StrBuff[VarId*MaxStrLen];
18072014 }
2015+#else
2016+ Variable_t *v;
2017+ if (VarId >> 16) {
2018+ v = &Variables[(VarId>>16)-1];
2019+ return v->Value.StrAry.val[VarId & 0xffff];
2020+ }
2021+ else {
2022+ v = &Variables[VarId];
2023+ return v->Value.Str;
2024+ }
2025+#endif
18082026 }
18092027
18102028 // for ifdefined (2006.9.23 maya)
@@ -1824,6 +2042,7 @@
18242042 switch (*ValType) {
18252043 case TypIntArray:
18262044 if (GetIndex(&Index, Err)) {
2045+#if 0
18272046 if (Index >= 0 && Index < IntAryVal[VarId].size) {
18282047 *ValType = TypInteger;
18292048 }
@@ -1830,6 +2049,15 @@
18302049 else {
18312050 *ValType = TypUnknown;
18322051 }
2052+#else
2053+ TIntAry *intAry = &Variables[VarId].Value.IntAry;
2054+ if (Index >= 0 && Index < intAry->size) {
2055+ *ValType = TypInteger;
2056+ }
2057+ else {
2058+ *ValType = TypUnknown;
2059+ }
2060+#endif
18332061 }
18342062 break;
18352063 case TypStrArray:
@@ -1876,6 +2104,7 @@
18762104
18772105 TVarId GetIntVarFromArray(TVarId VarId, int Index, LPWORD Err)
18782106 {
2107+#if 0
18792108 if (Index < 0 || Index >= IntAryVal[VarId].size) {
18802109 *Err = ErrOutOfRange;
18812110 return -1;
@@ -1882,10 +2111,20 @@
18822111 }
18832112 *Err = 0;
18842113 return ((VarId+1) << 16) | Index;
2114+#else
2115+ TIntAry *intAry = &Variables[VarId].Value.IntAry;
2116+ if (Index < 0 || Index >= intAry->size) {
2117+ *Err = ErrOutOfRange;
2118+ return -1;
2119+ }
2120+ *Err = 0;
2121+ return ((VarId+1) << 16) | Index;
2122+#endif
18852123 }
18862124
18872125 TVarId GetStrVarFromArray(TVarId VarId, int Index, LPWORD Err)
18882126 {
2127+#if 0
18892128 if (Index < 0 || Index >= StrAryVal[VarId].size) {
18902129 *Err = ErrOutOfRange;
18912130 return -1;
@@ -1892,6 +2131,15 @@
18922131 }
18932132 *Err = 0;
18942133 return ((VarId+1) << 16) | Index;
2134+#else
2135+ TStrAry *strAry = &Variables[VarId].Value.StrAry;
2136+ if (Index < 0 || Index >= strAry->size) {
2137+ *Err = ErrOutOfRange;
2138+ return -1;
2139+ }
2140+ *Err = 0;
2141+ return ((VarId+1) << 16) | Index;
2142+#endif
18952143 }
18962144
18972145 void GetAryVar(PVarId VarId, WORD VarType, LPWORD Err)
@@ -1944,10 +2192,20 @@
19442192
19452193 int GetIntAryVarSize(TVarId VarId)
19462194 {
2195+#if 0
19472196 return IntAryVal[VarId].size;
2197+#else
2198+ TIntAry *intAry = &Variables[VarId].Value.IntAry;
2199+ return intAry->size;
2200+#endif
19482201 }
19492202
19502203 int GetStrAryVarSize(TVarId VarId)
19512204 {
2205+#if 0
19522206 return StrAryVal[VarId].size;
2207+#else
2208+ TIntAry *strAry = &Variables[VarId].Value.IntAry;
2209+ return strAry->size;
2210+#endif
19532211 }
Show on old repository browser