-
Notifications
You must be signed in to change notification settings - Fork 72
/
sort_len.ahk
44 lines (42 loc) · 21 KB
/
sort_len.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
sort_len(byref str, del := "`n", shortFirst:=true, omitEmpty:=true){
; source, see: 'c souce\sort_len.c'
; Functions:
static pr := getProcAddress("MSVCRT.dll", "realloc")
static fr := getProcAddress("MSVCRT.dll", "free")
static cpy := getProcAddress("MSVCRT.dll", "memcpy")
static bin
local
;return DllCall(bin, "ptr", &str, "ptr", &del, "int", shortFirst, "uint", strlen(del), "ptr", pr,"ptr", fr,"ptr", cpy, "ptr", callbackcreate("mb", "f cdecl"), "cdecl") ; db
r:=DllCall(bin, "ptr", &str, "ptr", &del, "int", shortFirst, "uint", strlen(del), "int", omitEmpty, "ptr", pr,"ptr", fr,"ptr", cpy, "cdecl")
if omitEmpty && r
varsetcapacity(str, -1)
return r != -1 ; 0 on fail, 1 on success
; Closure
init(){
static flProtect:=0x40, flAllocationType:=0x1000 ; PAGE_EXECUTE_READWRITE ; MEM_COMMIT
static _ := init() ; static initialisation
raw32:=strsplit("1398167381,9235585,2223702016,40996,615811840,164,2888084619,1711276032,251672707,247684,1048798720,3179548416,2231369731,3045330925,3338665987,3355714628,3338665984,9220,2499739648,46116,2311095552,608471495,2441350944,3338665987,3355714628,3338665984,9220,2499739648,46116,2311095552,254026820,642692,608487168,51204,604292864,0,3022296319,2231369728,264341952,634500,2382006528,2089488479,1099768868,608995600,609519912,281510688,2467289401,264387009,3389637267,606356537,968987407,254289020,3356082323,2215625348,4175,606358667,1552668985,2467242020,268122562,3255353491,271942671,3632857088,3239043203,3640066792,3800285833,4102295299,3338665986,3,3352267008,1,608996096,33194792,455,2215575552,4150,3338926723,1091,1204224000,4,71419648,0,276530447,1137115136,8,138921728,0,955,138528512,0,12223,3323904,3492347904,337921161,11960,3251644672,3229811432,608471297,48283928,472138889,539249803,9766029,1711276032,2378231567,1284178196,688858148,62980354,254288964,286195985,1109987072,1091637008,1074859792,1109987088,1091637024,1074859808,1109987104,1091637040,1074859824,1109987120,1091637056,1074859840,1109987136,1091637072,1074859856,1109987152,1091637088,1074859872,1109987168,1091637104,1074859888,2183729008,128,2155942159,251658240,8421393,688848896,36994,2165378816,144,2424312079,251658240,10519081,286195712,41089,2148601600,160,405044355,253064460,11567657,286195712,45185,2148601600,176,472138891,1144768297,344790052,1962510595,608471915,612141864,33129248,606362763,9897159,3338665984,37636,80150528,144,21138688,80167540,135,612141824,46301992,3338860931,33540,80150528,135,2334225408,3340772420,36868,1149960192,80159780,144,608471808,2416232232,0,28896645,3120562176,0,3351594255,3941444,3338665984,842540100,2298478592,608471495,2213579084,1153896416,6180,1153892352,3289124,3906011136,3766737143,267925767,3341403975,1149879177,1200439332,612141560,65585492,2298593411,3243779140,3984917472,1545880713,268387725,3347694148,3221346441,1149886249,4026621988,1210350729,1344554121,823150221,612141567,608471340,112660328,740588683,2357975857,40996,608487168,4294967068,1149855487,3062699044,0,2367620237,3071230220,3229967873,996548468,1947477060,29590398,2686749835,2365587456,210575108,28774209,1975551334,29372897,608487363,284,266044672,32645,612666112,160,405030019,1015244289,2215575672,1497,3247042305,2422645483,9225345,3677421568,1583077513,3351469407,807150660,3338665984,202908740,3204448256,50,337921223,50,1776933681,838860797,29393856,1091876623,1175730534,247170319,3308847104,246646287,2238054400,971142610,1954877381,3925868543,4294967161,740588681,807697547,337927305,2198862649,1588,337935499,941900939,210630713,4294966461,3343323135,941900937,1009009803,1108342841,608471495,608471868,2311586088,2336498756,29591808,2311555576,2335450180,2367956036,16792916,608471496,956336996,3598847938,2231369733,1347008,1149965685,4169339940,672435506,3766730777,46170928,64007951,2367693900,1418269188,1149857828,25887780,1814318217,4280550537,11805844,3229941760,1814318219,1881429131,239698959,2089484288,25781284,3263764361,337921163,740588683,1680100489,1149878273,2223704100,40996,2013564160,69485705,2304377997,2499748868,48164,2344649984,258221132,919172,608471808,17402676,18124224,1814316169,337921163,135808141,960562317,1150488518,1413178404,3054463012,258221148,3272130707,203785231,4253220864,478547726,2332033036,2235573372,2391019519,251658248,4286777015,42558977,210273295,1149960192,3071226916,3229811294,50299649,1711281293,255925385,811908,1186402048,67076868,289704294,1199836930,251658252,2198226615,2305164543,251924804,797572,1186402048,100631304,289704294,260312838,251658252,2198488759,2305165311,252186948,798597,1186402048,1149855244,129632785,956301312,256648316,58244,612139776,1685456456,1814316171,1612989443,740588683,337927307,1680098503,0,1881429129,1149880321,1149987876,1418416164,1149463588,2197906468,258347200,2213568623,286200002,1418326114,1418423332,1413178404,3664926756,1545880715,1881429131,740588681,337927305,1144635905,2020889636,874806411,1444722447,3489790089,1092389222,956383885,258045637,21372087,478766840,37915969,1349961017,1176286991,2305226753,1116553500,1992636675,481759039,1727529286,2369854601,3308848194,3071225462,4160833052,1092389222,956646029,253589189,21372087,478766840,105024833,209110329,1175762703,874791939,1091864934,337927307,1143227531,402778881,740580353,472153219,1451495423,2348810236,11019396,3229941760,108102671,2223702016,45092,264275200,696197,608471808,264275224,693124,759467264,614238976,160,2894713393,44068,608471296,608471852,608471320,273059092,472138889,472144955,2366653325,2467238444,264649153,3238576275,99714063,3162701824,44068,2249133568,1507,1076120715,2215627141,714,2198255375,2305163769,3011776259,251658250,2197964471,2305164025,2215576131,2614,71743247,1711536515,251937673,661892,1186402048,83460870,105089382,175408143,3071213568,4186114118,1133078021,1468272392,251658250,2198488759,2305165305,2232355395,2618,205960975,2305216393,129502275,956301312,256648316,65924,612139776,1551238728,1613003915,1344556171,874792135,0,1143227529,3154374401,40996,615287552,172,695144294,2198914947,20194372,2333131139,255075396,1005612817,1918379076,612142051,608471900,615287108,172,2084173825,2215597092,158,1178384143,2197949581,2218328512,44068,615287552,160,1300007270,260011520,2370190519,2305163788,2365607292,2352546120,44068,258438656,21904567,2089379537,1217200205,613169410,172,3071234166,3506523708,1300007270,55086336,2888076345,1979711488,1018629945,1724973390,5078153,956582029,11281548,578158592,1312601871,17154179,612645329,172,1300007270,252409344,21367991,1284073168,2483224645,44068,610009856,611091244,2232353044,4294966840,405042315,2888084619,3338665984,1582148,251658240,210630063,608471862,610044732,4286090552,956427139,1686507487,2298478599,11281580,1284177920,4119406628,606368907,3280145387,266287361,473734,2651097856,4000628869,2308506763,18097228,608471488,608471816,2550434592,69485705,2686747787,2365587456,76113924,613744420,188,2215624837,1977,337923211,3952684035,610044849,266044732,4294789765,613190655,176,91539845,2305217073,610044688,608471832,1958774064,2314613039,2333353052,2301633660,611093491,615811872,184,10310795,91542149,4280554633,29590486,3967278905,337927307,539247755,4280550537,12067988,1149960192,76097572,613744420,184,606356619,4280550537,12067988,3296788480,140,1583077513,3150142815,4294967295,673465543,0,807683271,50,3224470507,1210350723,2911309574,268435453,3163227831,40996,1727891712,3092710537,1,4294840041,608961535,3910241056,4294965876,539247755,14488717,2298478592,2298750036,2302944340,2499748868,46116,2311095552,2335450180,256123988,558724,608471808,609519908,609519876,604277060,3022296319,2231369728,608471488,609520416,629411652,2332033032,2301109316,2298750036,2499748868,46116,2311095552,444862401,2332033032,18097220,608451008,608471344,696454980,2332033026,2301633628,2635369927,16,2089410345,2056070180,956599792,1680112777,1150010249,1552495652,3489754148,1552663353,2467247140,24126532,289181179,673471625,2089417529,2089514020,2467242020,58205252,258221180,2015648950,1881431050,2089404217,2467262500,609485760,609499424,265783592,3255419539,606370947,3231125261,3280261153,114852879,1418395648,1413051428,2467262500,612121026,3230863212,2215625224,1726,673469579,807689355,2299519619,609520592,48808228,3766737143,970426627,265980368,4286969926,673479817,2088984180,2332108836,2369004612,2089484627,80158756,152,2667890432,0,10028231,1946157056,612139831,80151336,144,2533672704,0,9503943,2365587456,410321491,9438407,3338665984,38660,80150528,145,55807232,673479819,606356619,337927307,606356679,0,2082755721,1149892649,3900909604,48808196,2298593411,3245089860,1149829856,1149988900,76375076,612142008,2311520564,2338595964,18883708,2311586247,2339644540,2301371516,829957188,609520576,4010763876,4010763977,608469970,688849188,1418396172,286225444,1418396180,286226468,1418396180,3229819940,609499920,2345562732,2339382340,2306614356,2301371516,18097244,608451010,2371974184,1144586562,2089501732,1552626724,80158756,151,2466563840,0,9503943,1979711488,2265237307,0,8586439,3338665984,33028,1116536832,608450818,2333963844,3342083196,34564,2089484288,80158756,135,2164573952,0,539247755,941915275,807697465,673467529,606356617,874792075,539247753,1143227531,74679311,1149829120,4058591268,2348810230,11281580,3224436736,1175238415,1124895078,956416131,2314303429,11281580,2213085184,2348810235,2335712324,2369528924,3951296376,266287361,363907,615811328,164,2888084617,3338665984,1320004,2332033024,2334401652,3945276524,7769354,956427139,2337108959,3229982212,1150022260,2357919901,40996,2311061760,2332566596,2334139460,1149868036,1149961252,76354596,604277057,3156514047,2231369728,1585713088,2332033027,16817484,3943965772,3922866611,4294965237,337921163,2753868939,2332033024,11281580,1418395648,210581540,608471808,4290937128,54525951,10495116,479002624,688098192,2311061992,2332566596,2334139460,210341892,608471332,613744388,188,2215624837,761,337921163,50587689,2955189387,2231369728,608471515,2189758228,2332033026,2232951884,4018409417,2298478593,759467463,613714688,160,2888084617,2298478592,2335450180,10495108,479002624,273059192,472138889,1133371273,1003956496,253502556,3325673875,146838287,2558791617,2197815298,11281596,252575744,166534,608996096,264865088,104580,112660224,1711405443,2215576457,937,38188815,1711470979,251806601,247940,1186402048,66683652,71534950,61572111,3071213568,4186113606,1133078020,2391019270,251658243,2198357687,2305164793,2215577667,881,172406543,1711798659,252330889,199045,1186402048,1724745996,3087811465,7,1277455417,16417807,2088960000,1980123172,612107093,608996192,615287632,172,740574407,0,941900937,258397953,3347263855,281117456,740574339,608471809,1997606700,608451568,2346938968,2338071676,2302157892,11281580,4160815104,1411677241,10388495,1284177920,3071218724,3238086204,956416131,11281540,2305163264,2249148988,128,337931403,1178384143,3238128009,1245481318,956385421,11281548,1685454848,1312601871,2305222913,1217219132,613169410,172,3071233654,3909176892,1245481318,956516493,11281548,947257344,1312601871,2305222913,1217219132,613169412,172,3071222390,3229830716,971571461,11281540,2305163264,209078844,1175238415,337921027,1108117862,2888088715,50331648,20194396,2199135356,18359404,4265248015,3677487103,4294528233,2210411007,105391228,4276061967,3071279103,612141830,76113428,112762,1038680064,2315255807,615287790,172,2335575181,2335974484,52962372,10495116,3263234048,1073741823,2341477517,31992067,608471488,608471816,2416216864,2300841097,4278461508,12330132,3229941760,2223731572,45092,264275200,4294496388,65939967,611617075,612666132,160,337935499,2305217073,3001645076,2348810232,2334139476,824714316,610044864,649366820,0,8520903,3338665984,33540,80150528,129,29393664,1966274691,4051364323,834666495,3137339392,1,4293916905,4294949887,1726611455,2348810232,11281580,3224436736,1175238415,1124895078,956416131,2314303429,11281580,3588816896,2348810238,2334925948,823403612,213323712,210331206,29393730,4051158329,740588681,337927305,4294260713,3194879,45809664,3909091328,4294963093,4130457905,4294405353,608471551,4219791672,62455807,2298478592,4129155535,45678591,2298478592,4128369103,96141311,3909091328,4294964231,1210,4093503744,62586879,3909091328,4294964211,698,4092193024,29032447,3909091328,4294964191,1722,4090882304,112787455,2298478592,4123650511,96010239,2298478592,4122864079,79233023,2298478592,4122077647,28901375,2298478592,4121291215,112787455,2298478592,4244302285,1150025727,2089496612,1552624676,1418400804,80163876,130,609520384,2181351200,0,8455367,2197815296,1144586688,3665118244,740588681,337927305,4294610921,112895,3448307712,4294750185,375039,3448307712,4294747113,309503,3448307712,4294744041,243967,3448307712,4294740969,178431,3448307712,4294737897,264583679,4293972100,3531958015,4038951951,3271688191,2686749835,3909091328,4294963328,874792075,472145035,539247753,4294361321,608996351,608471840,610044724,608995612,608471332,4138199328,3375497215,337921223,0,4075405961,2348810234,3910935644,4294964877,2425393296,2425393296,2425393296",",")
raw64:=strsplit("1447122753,1413567809,1398167381,2834071880,1711276032,1207974275,2303249289,3330885079,265193796,223108,981689856,1568935680,1157627907,2215627141,852,2428160305,4278190081,18359444,2236088320,3314108864,54166543,3375431680,51386,613744384,280,1237353800,2215626633,2025,3367684401,4278190080,18359444,2303262720,1149847746,2236426276,3397652434,1224736775,1225803661,26250637,961085440,3498659010,1220711183,1225834627,2467284793,1287784896,88658057,200,1103444297,1237357327,2467285561,3221832896,2215625348,2391,3364326729,1224736768,2467284281,3476638146,146838287,1015287746,1090519049,252233206,177540,1170688256,0,28918016,1090519040,1991,3091267584,49,182081,3120562176,1,3578039625,4010763776,4010763977,3804317888,210585858,3523300375,838370113,252193039,252725289,286195985,1210650370,1210650400,1091637040,1108414224,1210650384,1210650432,1091637072,1108414240,1210650400,1210650464,1091637104,1108414256,2284392240,128,2424842511,251658240,255869201,255869457,10520617,688848896,45192,1091636992,1108414288,2284392272,192,3498584335,251658240,257966353,257966609,14714921,688848896,61576,1091636992,1108414320,2284392304,256,277358863,251658241,8421649,286195712,32898,2284392192,288,814229775,251658241,9470225,286195712,36994,2284392192,320,1351100687,251658241,10518801,286195712,41090,2284392192,352,1887971599,1090519041,254820749,11567377,286195712,45186,1153911040,197,3342925824,34564,3342925824,33284,561250304,2290468681,1,1090519040,12879815,0,3342925824,50306,0,3103163648,1,186,3326414592,611092812,3028894776,65572,2311162112,9446532,2303197184,266372088,1143227591,0,1076118727,50,3353923912,842277956,1291845632,4148755849,132154328,1192216633,1103178177,1149879177,1099783204,613190136,140,2198071489,2223571392,34852,65061120,2223634053,33828,4282813696,1170359311,826659377,1153534436,2303056009,1220618710,2303246337,1215308868,1284110337,2303219748,1215833156,1209026445,1612989577,263655236,4294950721,3979476991,4202255,738495809,264276297,1715668151,427081861,3359196262,3313724020,76366081,3230222636,1124382479,1975551334,29372903,29311429,2231369728,1148614125,2202132617,2204500422,251675452,281220,4093722880,2422649579,1156985157,2169041033,43204,1600019200,1096565085,1096696157,826655583,850936265,822083584,4251118034,258408447,17439,1217249329,344801537,3364440072,1393866511,1326725478,139035919,3459842048,138511887,2238054400,970683858,3951064526,611072902,2441285428,2332033028,1212163140,673467531,894733636,266877184,1149879623,1149976612,3896067108,2311406095,2370053188,2370633541,34052,21757952,3892399553,1091144516,2303201419,1129325644,956959885,797052881,2231369732,479020242,2199024914,3524866813,2201019011,255918786,2302792367,1284196563,2302949412,2223590618,38948,2357806080,37924,2492023808,32804,3523299328,610044228,76367976,1149847745,2336770084,613744392,280,1153467720,1747213451,613714756,128,613190468,148,612666188,152,121275407,2336751616,1212687436,2303000969,3800646680,613714244,128,1208782154,608995660,344803432,1150110803,2499739693,75812,3229960192,608996172,2492154984,32804,3800305408,1207959558,1210336395,692358477,210585864,479022121,277563401,1107594574,436505930,1103575372,1220645647,1612989499,3230863169,264308805,407172,218006272,103646735,1821048832,3984940068,79397903,256114688,4253222839,2302961153,981733120,1140850694,38778639,21073228,1258487171,1711277197,1108117830,102073359,256114688,2198095799,1147536381,33703049,104039439,256114688,2198226871,1147536637,67257481,102073359,256114688,2198357943,1147536893,100811913,100107279,256114688,2198489015,1147537405,134366345,98141455,256114688,1712080823,38046020,505866,2336489472,9446532,960757760,257696836,59524,612139776,1316357720,608996172,3224454512,422350155,610044748,3375449464,1725235528,74387267,3246604547,286212609,1224738116,1141948547,2284096571,1912602624,2626372834,33828,3623961600,614218564,140,9667599,2302738432,29393856,213323590,3355527495,1181140537,1984040073,3230220668,213323590,3355527495,210323046,1082999874,3325641729,256271222,1229393079,1181140993,1145179273,1140998285,1299629625,213323590,3355527495,210323046,1082999874,4030284035,256259955,1229393079,1181140993,1145179273,1090797709,561246265,213323590,96502599,969408841,2303092422,225853964,79105860,3355527239,76104806,1149978690,21319716,268518612,4294935361,4232479759,2303066111,4018753010,615811908,256,611093324,4135929144,41649167,2336489472,17835164,2235891712,1870991323,1157627908,2235940913,3515434450,73434127,2302935040,264253890,17439,481759044,3229829191,2211547393,3325624770,478757990,1105819467,2202136577,3597992425,1171753284,2937049649,1224247806,2336538625,2336236660,1094984812,2197941891,960561645,2525171694,1090519043,2302999689,2302157908,1091431415,1090635395,2198859321,877,1173391684,1216812171,8721549,1157627904,3748975237,611617608,3590408232,3310652233,3767092224,1208388420,1296239757,2499788801,75812,3229960192,67929103,54788096,2343627558,1162093676,2303586953,3029026031,65572,1821068288,3984930852,4278945039,3163291647,69668,1962902784,1727410437,2303013769,608472022,1958774068,611617575,3163244596,73764,266023168,17439,3712781129,3380955136,3623813748,29590344,3967278649,4293495116,18883732,2336751616,4280820812,18883732,2303459328,613744633,288,4294654697,4290658815,1224736767,673465543,0,874792135,50,2336791531,1211638860,1220609165,1210336393,3909126984,4294966337,760515908,1284196352,2302949412,1246766164,13964429,1275068416,1210340489,405050623,1207959553,2337063045,1145578580,1344556171,54166543,2370699264,38172,2302935040,1212687436,1344554121,1290373452,2303515273,4281869404,18359444,2236088320,1552633024,2336503844,1279796300,1344554123,51479567,2303459328,1145578564,941902985,1222281548,1344554121,608996168,613744424,280,1153467720,941902987,608471884,1418415176,2215596068,728,874794123,2311665988,2300670922,29524945,1238448449,13108423,1090519040,9045191,3338665984,34820,3748986880,1076122763,874796089,1221953869,673465481,608471372,1417940792,1140850690,874794121,4294604521,611093503,1955284036,3984801828,4001579265,4114170881,41911823,826605568,3163113700,63524,1418281984,2302949412,4102637031,1224116545,351002249,8658703,0,1140977027,2249188665,141,2336614537,2370340612,34076,2235891712,1222735040,673471491,3310652233,1224247552,1145441421,21824395,613744576,296,264275272,120196,3946513152,2210410935,106439804,4225664783,3071279103,76113415,112714,854130688,1224736764,673469579,2422652977,1162135369,0,80167168,7,33867520,0,79725384,13122888,3698655232,4294452457,1157204479,941905035,616336200,248,1156811080,2303063689,3431549414,1221132616,673465483,4115958603,3640739840,609519940,747457080,4290658736,1157627903,1090536843,21884969,613744576,296,264275272,4294793348,613190655,272,1155631429,941905035,1156655425,2231389443,2558857161,1157627904,628413061,835356996,3071231168,2202552068,3515417024,956416643,2302961350,3916909316,1106313537,1963059843,4130424283,4294772969,1418413311,2302949412,1224640992,21546889,1284196544,2302945316,1094198356,4294967230,1418414591,2370568429,2370349348,2336555788,692134916,3221310960,673486079,1207959553,2215624837,4294966465,613190468,272,609520452,3380954424,4238902287,4146724863,1173981505,824445955,2302830290,2481539860,838860796,213323730,210331223,3263383632,2010528001,4216318448,3224502271,3488218929,3103784955,2,4294590953,112895,938016768,3103784954,6,4294585833,375039,602472448,3103784954,4,4294580713,243967,266928128,1157627898,1076120713,608995652,4162709812,3191996415,4294967295,4294713577,4169745663,1290766669,941911179,3922102593,4294966285,1308526917,2337075081,3912770668,4294966269,1171622221,2303590025,3314109935,4294700265,1170813439,1424614449,973078526,1216614342,1728053239,2215629445,4294965047,99206401,2432696311,2425393296",",")
if !(pr*fr*cpy)
throw exception("Failed to retrieve function pointers: " pr "`t" fr "`t" cpt ".")
bin:=DllCall("Kernel32.dll\VirtualAlloc", "Uptr",0, "Ptr", (raw:=A_PtrSize==4?raw32:raw64).length()*4, "Uint", flAllocationType, "Uint", flProtect, "Ptr")
for k, i in raw
NumPut(integer(i), bin+(k-1)*4, "Int")
}
getProcAddress(dll, fn){
return DllCall("Kernel32.dll\GetProcAddress", "Ptr", DllCall("Kernel32.dll\GetModuleHandle", "Str", dll, "Ptr"), "AStr", fn, "Ptr")
}
}
; due to:
; https://autohotkey.com/boards/viewtopic.php?p=183090#p183090
; v2
g(byref str, del := "`n", omit := "`r", split := false){
local
lens := []
loop parse, str, del, omit
lens[l := strlen(A_LoopField)] := "", __slen%l% .= A_LoopField . del
varsetcapacity(str,varsetcapacity(str)+2)
for l in lens
str .= __slen%l%
str := rtrim(str, del)
}