我需要以批处理文件的形式完成这项艰巨的任务,用 C 语言不是最难的,但在 DOS 中是地狱(至少对我来说!)我需要将结构转换为单个 var(字符串)才能在我的程序中再次将它们转换为该结构。不要担心复出,它已经完成了。
该结构的大小会有所不同,并且在 [0] 内有一个索引,该索引必须是我的 var 中的第一项。
这里是这些结构的一个例子(只有 3 个):
level.waypoints[0] = spawnstruct();
level.waypoints[0].origin = (1774.5,834.7,67.6);
level.waypoints[0].type = "stand";
level.waypoints[0].childCount = 2;
level.waypoints[0].children[0] = 1;
level.waypoints[0].children[1] = 6;
level.waypoints[1] = spawnstruct();
level.waypoints[1].origin = (1780.6,639.1,65.5);
level.waypoints[1].type = "stand";
level.waypoints[1].childCount = 2;
level.waypoints[1].children[0] = 7;
level.waypoints[1].children[1] = 0;
level.waypoints[2] = spawnstruct();
level.waypoints[2].origin = (1902.2,-345.2,74.2);
level.waypoints[2].type = "stand";
level.waypoints[2].childCount = 2;
level.waypoints[2].children[0] = 3;
level.waypoints[2].children[1] = 97;
level.waypoints[3] = spawnstruct();
level.waypoints[3].origin = ... (goes on...)
所以第一个结构:
level.waypoints[0] = spawnstruct();
level.waypoints[0].origin = (1774.5,834.7,67.6);
level.waypoints[0].type = "stand";
level.waypoints[0].childCount = 2;
level.waypoints[0].children[0] = 1;
level.waypoints[0].children[1] = 6;
我需要将此结构转换为这一行:
set flwp_0 "0,1774.5,834.7,67.6,stand,2,1,6"
其中 0 (flwp_) 是索引,也是“”中的第一项。
所以这个例子中的另外两个将是:
set flwp_1 "1,1780.6,639.1,65.5,3,7,0,30"
set flwp_2 "2,1902.2,-345.2,74.2,2,3,97"
childCount 可以是任何值,但我认为不会超过 9。所以,我们有多少 childCount,下一行会有更多的孩子。
但是我只需要 childCount 值之后的值,所以我使用该值知道该字符串中还有多少可用的项目,所以没问题。
我正在考虑首先删除我不需要的所有内容(按顺序):
level.waypoints[
] = spawnstruct();
].origin = (
);
].type = "
";
].childCount =
].children[0] =
].children[1] =
].children[2] =
].children[3] =
].children[4] =
].children[5] =
].children[6] =
].children[7] =
].children[8] =
].children[9] =
;
这将在第一个结构中留下类似的内容:
0
01774.5,834.7,67.6
0stand
02
01
06
现在我需要阅读它并转换成我的单行字符串。但是我很难知道正确的索引,因为可能是第一个值,但是如果索引有 2 个或 3 个字符?
我也在考虑用一些信息替换来跟踪我,所以不会替换文件的“]”,所以我会知道索引之前是什么,之后是值。
我也试图循环但没有成功创建一个索引,如:
level.waypoints[X]
其中 X 是从 0 到 1000(我不相信会通过那个数字)
它不起作用,也许我的第一个想法更好......:\
我需要一个(或多个)批处理文件来将内部具有类似结构的多个文件转换为新文件,并将值作为我在上面详细描述的字符串。
有任何想法吗?
谢谢!
@Squashman 此外,如您所见,结果的顺序有点混乱:
set flwp_0 "0,1774.5,834.7,67.6,stand,2,1,6"
set flwp_100 "100,1636.76,371.924,240.125,stand,2,101,99"
set flwp_101 "101,1861.45,437.846,240.125,stand,2,102,100"
set flwp_102 "102,1843.93,557.03,240.125,stand,2,103,101"
set flwp_103 "103,1504.58,553.357,64.125,stand,2,8,102"
set flwp_104 "104,653.17,1675.32,64.125,stand,2,26,105"
set flwp_105 "105,338.784,1680.49,232.125,stand,2,104,133"
set flwp_106 "106,-919.398,1537.7,80.125,stand,3,107,109,150"
set flwp_107 "107,-928.311,1111.47,80.125,stand,3,108,106,149"
set flwp_108 "108,-696.488,1095.93,80.125,stand,2,36,107"
set flwp_109 "109,-787.781,1566.87,80.125,stand,2,106,110"
set flwp_10 "10,1423.3,-403.8,64.3,stand,4,11,12,15,3"
set flwp_110 "110,-754.274,1716.71,80.125,stand,2,109,34"
set flwp_111 "111,-736.201,1887.87,64.125,stand,4,112,34,151,152"
set flwp_112 "112,-454.293,1879.4,64.125,stand,4,111,33,34,152"
set flwp_113 "113,125.395,-451.579,58.6958,stand,3,51,114,142"
set flwp_114 "114,282.593,-447.87,68.125,stand,2,115,113"
set flwp_115 "115,304.311,-271.206,68.125,stand,2,116,114"
set flwp_116 "116,447.128,-292.167,68.125,stand,3,118,115,117"
set flwp_117 "117,437.415,-443.822,68.125,stand,2,67,116"
set flwp_118 "118,582.932,-297.811,126.125,stand,2,119,116"
set flwp_119 "119,561.586,-485.701,204.125,stand,2,120,118"
set flwp_11 "11,1240.1,-249.7,74.1,stand,5,9,16,10,12,15"
set flwp_120 "120,423.422,-470.754,204.125,stand,2,119,135"
set flwp_121 "121,1164.82,-1203.64,72.125,stand,4,123,14,126,122"
set flwp_122 "122,1064.12,-1299.76,72.125,stand,3,123,125,121"
set flwp_123 "123,1117.59,-1476.49,72.125,stand,3,124,122,121"
set flwp_124 "124,861.878,-1497.7,72.125,stand,2,125,123"
set flwp_125 "125,878.58,-1294.38,72.125,stand,2,124,122"
是否可以按正确的顺序写入文件?
再次非常感谢您的帮助@Squashman
干杯
好的,顺序真的无关紧要,但是我很难将每个文件都变成一个新文件...我尝试了这个但没有成功:
@echo off
setlocal enabledelayedexpansion
for %%f in (*.gsc) do (
FOR /F "tokens=1-2 delims==;^(^) " %%G IN (%%f) do set %%~G=%%~H
FOR /F "tokens=2 delims=[]" %%G IN ('set level.waypoints ^|find /I "spawnstruct"') do (
SET waypoints=!waypoints! %%G
)
FOR %%G IN (%waypoints%) do (
set line=%%G,!level.waypoints[%%G].origin!,!level.waypoints[%%G].type!,!level.waypoints[%%G].childCount!
FOR /F "tokens=2 delims==" %%H IN ('set level.waypoints[%%G].children') DO set line=!line!,%%H
set line=set flwp_%%G "!line!"
echo !line! >> %%f.cfg
)
)
pause
有什么线索吗?
========================================
好的,现在我们非常接近了!只需要处理带有的行,level.waypoints[
其余的必须被忽略,并添加一个我已经成功完成的最终关闭变量:
@echo off
setlocal enableDelayedExpansion
set findtext="level.waypoints["
for %%F in (*.gsc) do (
set "out="
set "i=x"
> "%%~nF.cfg" (
for /f usebackq^ tokens^=2^,4^,5^ delims^=[]^=(^)^;^"^ %%A in ("%%F") do (
if %%A neq !i! (
if defined out echo !out!"
set /a "i=%%A, j=0"
set "out=set flwp_!i! "!i!"
) else (
set /a j+=1
if !j! leq 3 (set "out=!out!,%%B") else set "out=!out!,%%C"
)
)
if defined out echo !out!"
set /a "fim=i+1"
echo set flwp_!fim! "eof"
)
)
现在我该如何添加findstr %findtext%
到这些循环中?我尝试了许多不同的方式,但语法错误......你能帮帮我吗?:D
非常感谢 @Squashman 和 @dbenham 到现在为止的所有帮助。
干杯