runtime.bas 90 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357
  1. SUB RunTimeFunctions
  2. LOCAL X1$
  3. LOCAL O1$ ' "%o"
  4. LOCAL D1$ ' "%.15G"
  5. LOCAL D2$ ' "%.19LG"
  6. LOCAL T0$ ' "%H:%M:%S"
  7. LOCAL T1$ ' "%H"
  8. LOCAL T2$ ' "%M"
  9. LOCAL T3$ ' "%S"
  10. LOCAL T4$ ' "%p"
  11. LOCAL T5$ ' "%Y"
  12. LOCAL T6$ ' "%m"
  13. LOCAL T7$ ' "%d"
  14. LOCAL T8$ ' "%A"
  15. LOCAL T9$ ' "%w"
  16. LOCAL T10$ ' "%j"
  17. LOCAL T11$ ' "%V" [ISO week date standard (ISO-8601)]
  18. LOCAL T12$ ' "%m/%d/%y"
  19. LOCAL T13$ ' %A, %B %d, %Y [DAY OF WEEK, MONTH NAME, DAY, FULL YEAR]
  20. LOCAL TDIR$
  21. D1$ = VCHR$(8,34,37,32,46,49,53,71,34)
  22. D2$ = VCHR$(9,34,37,32,46,49,57,76,71,34)
  23. O1$ = VCHR$(4,34,37,111,34)
  24. T0$ = VCHR$(10,34,37,72,58,37,77,58,37,83,34)
  25. T1$ = VCHR$(4,34,37, 72,34)
  26. T2$ = VCHR$(4,34,37, 77,34)
  27. T3$ = VCHR$(4,34,37, 83,34)
  28. T4$ = VCHR$(4,34,37,112,34)
  29. T5$ = VCHR$(4,34,37, 89,34)
  30. T6$ = VCHR$(4,34,37,109,34)
  31. T7$ = VCHR$(4,34,37,100,34)
  32. T8$ = VCHR$(4,34,37, 65,34)
  33. T9$ = VCHR$(4,34,37,119,34)
  34. T10$ = VCHR$(4,34,37,106,34)
  35. T11$ = VCHR$(4,34,37, 86,34)
  36. T12$ = VCHR$(10,34,37,109,47,37,100,47,37,121,34)
  37. T13$ = VCHR$(15,34,37,65,44,32,37,66,32,37,100,44,32,37,89,34)
  38. X1$ = VCHR$(4,34,37,88,34)
  39. TDIR$= ENC$("/tmp/mbc.XXXXXXXX")
  40. 'U1$ = VCHR$(7,37,39,42,46,42,32,102)
  41. FPRINT Outfile,""
  42. FPRINT Outfile,"// *************************************************"
  43. FPRINT Outfile,"// " + $BCX_STR_RUNTIME
  44. FPRINT Outfile,"// *************************************************"
  45. FPRINT Outfile,""
  46. IF NoRT=TRUE THEN EXIT SUB
  47. IF UseFlag THEN
  48. IF Use_Turbo THEN
  49. FPRINT Outfile,"char *BCX_TmpStr (size_t Bites)"
  50. FPRINT Outfile,"{"
  51. FPRINT Outfile," static int StrCnt;"
  52. FPRINT Outfile," static char *StrFunc[",TurboSize,"];"
  53. FPRINT Outfile," StrCnt=((StrCnt+1) &",TurboSize-1,");"
  54. FPRINT Outfile," #if defined BCX_MAX_VAR_SIZE"
  55. FPRINT Outfile," if(Bites*sizeof(char)>BCX_MAX_VAR_SIZE)"
  56. FPRINT Outfile," {"
  57. FPRINT Outfile," printf(";ENC$("Buffer Overflow caught in BCX_TmpStr - requested space of %d EXCEEDS %d\\n");",(int)(Bites*sizeof(char)),BCX_MAX_VAR_SIZE);"
  58. FPRINT Outfile," abort();"
  59. FPRINT Outfile," }"
  60. FPRINT Outfile," #endif"
  61. FPRINT Outfile," StrFunc[StrCnt]=(char*)realloc(StrFunc[StrCnt],Bites + 128);"
  62. FPRINT Outfile," return (char*)memset(StrFunc[StrCnt],0,Bites+128);"
  63. FPRINT Outfile,"}\n\n"
  64. ELSE
  65. FPRINT Outfile,"char *BCX_TmpStr (size_t Bites)"
  66. FPRINT Outfile,"{"
  67. FPRINT Outfile," static int StrCnt;"
  68. FPRINT Outfile," static char *StrFunc[65535];"
  69. FPRINT Outfile," StrCnt=(StrCnt + 1) & 65535;"
  70. FPRINT Outfile," if(StrFunc[StrCnt]) free (StrFunc[StrCnt]);"
  71. FPRINT Outfile," #if defined BCX_MAX_VAR_SIZE"
  72. FPRINT Outfile," if(Bites*sizeof(char)>BCX_MAX_VAR_SIZE)"
  73. FPRINT Outfile," {"
  74. FPRINT Outfile," printf(",ENC$("Buffer Overflow caught in BCX_TmpStr - requested space of %d EXCEEDS %d\\n"),",(int)(Bites*sizeof(char)),BCX_MAX_VAR_SIZE);"
  75. FPRINT Outfile," abort();"
  76. FPRINT Outfile," }"
  77. FPRINT Outfile," #endif"
  78. FPRINT Outfile," return StrFunc[StrCnt]=(char*)calloc(Bites+128,sizeof(char));"
  79. FPRINT Outfile,"}\n\n"
  80. END IF
  81. END IF
  82. IF Use_CopyFile THEN
  83. FPRINT Outfile,"void CopyFile (char *InFile,char *TmpFile,int OverWrite)"
  84. FPRINT Outfile,"{"
  85. FPRINT Outfile," #define BLOCKCOPYSIZE (10 * 1000*1024)"
  86. FPRINT Outfile," char* tmp=0;"
  87. FPRINT Outfile," UINT blocks=1;"
  88. FPRINT Outfile," UINT overage=0;"
  89. FPRINT Outfile," UINT i;"
  90. FPRINT Outfile," FILE *FP1,*FP2;"
  91. FPRINT Outfile," if(!OverWrite)"
  92. FPRINT Outfile," {"
  93. FPRINT Outfile," if(Exist(TmpFile)) return;"
  94. FPRINT Outfile," }"
  95. FPRINT Outfile," if(Exist(InFile))"
  96. FPRINT Outfile," {"
  97. FPRINT Outfile," UINT length = lof(InFile);"
  98. FPRINT Outfile," if(length > BLOCKCOPYSIZE)"
  99. FPRINT Outfile," {"
  100. FPRINT Outfile," blocks = length/BLOCKCOPYSIZE;"
  101. FPRINT Outfile," overage= length % BLOCKCOPYSIZE;"
  102. FPRINT Outfile," length = BLOCKCOPYSIZE;"
  103. FPRINT Outfile," }"
  104. FPRINT Outfile,""
  105. FPRINT Outfile," tmp=(char*)calloc(16+length,1);"
  106. FPRINT Outfile,""
  107. FPRINT Outfile," if((FP1=fopen(InFile,",ENC$("rb"),"))==0)"
  108. FPRINT Outfile," {"
  109. FPRINT Outfile," fprintf(stderr,",ENC$("Can't open file %s\\n"),",InFile);"
  110. FPRINT Outfile," exit(1);"
  111. FPRINT Outfile," }"
  112. FPRINT Outfile," if((FP2=fopen(TmpFile,",ENC$("wb+"),"))==0)"
  113. FPRINT Outfile," {"
  114. FPRINT Outfile," fprintf(stderr,",ENC$("Can't open file %s\\n"),",TmpFile);"
  115. FPRINT Outfile," exit(1);"
  116. FPRINT Outfile," }"
  117. FPRINT Outfile," for(i=0; i<blocks; i+=1)"
  118. FPRINT Outfile," {"
  119. FPRINT Outfile," fread(tmp,1,length,FP1);"
  120. FPRINT Outfile," fwrite(tmp,1,length,FP2);"
  121. FPRINT Outfile," }"
  122. FPRINT Outfile," if(overage>0)"
  123. FPRINT Outfile," {"
  124. FPRINT Outfile," fread(tmp,1,overage,FP1);"
  125. FPRINT Outfile," fwrite(tmp,1,overage,FP2);"
  126. FPRINT Outfile," }"
  127. FPRINT Outfile," fclose(FP2); fclose(FP1);"
  128. FPRINT Outfile," if(tmp) free(tmp);"
  129. FPRINT Outfile," struct stat st;"
  130. FPRINT Outfile," if(stat(InFile, &st) != -1)"
  131. FPRINT Outfile," chmod(TmpFile,st.st_mode);"
  132. FPRINT Outfile," }"
  133. FPRINT Outfile,"}\n\n"
  134. END IF
  135. IF Use_Str_Cmp THEN
  136. FPRINT Outfile,"int str_cmp (char *a, char *b)"
  137. FPRINT Outfile,"{"
  138. FPRINT Outfile," int counter=0;"
  139. FPRINT Outfile," for(;;)"
  140. FPRINT Outfile," {"
  141. FPRINT Outfile," if((a[counter]^b[counter]))"
  142. FPRINT Outfile," {"
  143. FPRINT Outfile," if((UINT) a[counter]>= (UINT) b[counter])"
  144. FPRINT Outfile," return 1;"
  145. FPRINT Outfile," return -1;"
  146. FPRINT Outfile," }"
  147. FPRINT Outfile," if(!a[counter]) return 0;"
  148. FPRINT Outfile," counter++;"
  149. FPRINT Outfile," }"
  150. FPRINT Outfile,"}\n\n"
  151. END IF
  152. IF Use_Eof THEN
  153. FPRINT Outfile,"int EoF (FILE* stream)"
  154. FPRINT Outfile,"{"
  155. FPRINT Outfile," register int c, status = ((c = fgetc(stream)) == EOF);"
  156. FPRINT Outfile," ungetc(c,stream);"
  157. FPRINT Outfile," return status;"
  158. FPRINT Outfile,"}\n\n"
  159. END IF
  160. IF Use_Cint THEN
  161. FPRINT Outfile,"int Cint (double A)"
  162. FPRINT Outfile,"{"
  163. FPRINT Outfile," return (A >=0 ? (int)(A+0.5) : (int)(A-0.5));"
  164. FPRINT Outfile,"}\n\n"
  165. END IF
  166. IF Use_Clng THEN
  167. FPRINT Outfile,"long CLNG (double A)"
  168. FPRINT Outfile,"{"
  169. FPRINT Outfile," float r=.5;"
  170. FPRINT Outfile," double a=A-(long)A;"
  171. FPRINT Outfile," if(A<0) { r=-.5; a=-a; }"
  172. FPRINT Outfile," if(((long)A % 2)==0&&a<=.5)"
  173. FPRINT Outfile," return (long)A;"
  174. FPRINT Outfile," else"
  175. FPRINT Outfile," return (long)(A+r);"
  176. FPRINT Outfile,"}\n\n"
  177. END IF
  178. IF Use_Left THEN
  179. FPRINT Outfile,"char *left (char *S, int length)"
  180. FPRINT Outfile,"{"
  181. FPRINT Outfile," int tmplen = strlen(S);"
  182. FPRINT Outfile," if(length<1) return BCX_TmpStr(1);"
  183. FPRINT Outfile," if(length<tmplen) tmplen=length;"
  184. FPRINT Outfile," char *strtmp = BCX_TmpStr(tmplen);"
  185. FPRINT Outfile," return (char*)memcpy(strtmp,S,tmplen);"
  186. FPRINT Outfile,"}\n\n"
  187. END IF
  188. IF Use_Right THEN
  189. FPRINT Outfile,"char *right (char *S, int length)"
  190. FPRINT Outfile,"{"
  191. FPRINT Outfile," int tmplen = strlen(S);"
  192. FPRINT Outfile," char *BCX_RetStr = BCX_TmpStr(tmplen);"
  193. FPRINT Outfile," tmplen -= length;"
  194. FPRINT Outfile," if (tmplen<0) tmplen = 0;"
  195. FPRINT Outfile," return strcpy(BCX_RetStr, &S[tmplen]);"
  196. FPRINT Outfile,"}\n\n"
  197. END IF
  198. IF Use_Rpad THEN
  199. FPRINT Outfile,"char *rpad (char *a, int L, int c)"
  200. FPRINT Outfile,"{"
  201. FPRINT Outfile," char *strtmp;"
  202. FPRINT Outfile," int s = strlen(a);"
  203. FPRINT Outfile," if((L-s)<1) return a;"
  204. FPRINT Outfile," strtmp=BCX_TmpStr(L);"
  205. FPRINT Outfile," strcpy(strtmp,a);"
  206. FPRINT Outfile," memset(&strtmp[s],c,(L-s));"
  207. FPRINT Outfile," return strtmp;"
  208. FPRINT Outfile,"}\n\n"
  209. END IF
  210. IF Use_Lpad THEN
  211. FPRINT Outfile,"char *lpad (char *a, int L, int c)"
  212. FPRINT Outfile,"{"
  213. FPRINT Outfile," char *strtmp;"
  214. FPRINT Outfile," L=L-strlen(a);"
  215. FPRINT Outfile," if(L<1) return a;"
  216. FPRINT Outfile," strtmp = BCX_TmpStr(L);"
  217. FPRINT Outfile," memset(strtmp,c,L);"
  218. FPRINT Outfile," return strcat(strtmp,a);"
  219. FPRINT Outfile,"}\n\n"
  220. END IF
  221. IF Use_Mid THEN
  222. FPRINT Outfile,"char *mid (char *S, int start, int length)"
  223. FPRINT Outfile,"{"
  224. FPRINT Outfile," char *strtmp;"
  225. FPRINT Outfile," int tmplen = strlen(S);"
  226. FPRINT Outfile," if(start>tmplen||start<1) return BCX_TmpStr(1);"
  227. FPRINT Outfile," if (length<0 || length>(tmplen-start)+1)"
  228. FPRINT Outfile," length = (tmplen-start)+1;"
  229. FPRINT Outfile," strtmp = BCX_TmpStr(length);"
  230. FPRINT Outfile," return (char*)memcpy(strtmp,&S[start-1],length);"
  231. FPRINT Outfile,"}\n\n"
  232. END IF
  233. IF Use_Trim THEN
  234. FPRINT Outfile,"char *trim (char *S)"
  235. FPRINT Outfile,"{"
  236. FPRINT Outfile," while(*S==32 || *S==9 || *S==10 || *S==11 || *S==13)"
  237. ' tab ,carriage return, vertical tab, newline, space
  238. FPRINT Outfile," S++;"
  239. FPRINT Outfile," int i = strlen(S);"
  240. FPRINT Outfile," while( i>0 && (S[i-1]==32 || S[i-1]==9 || S[i-1]==10"
  241. FPRINT Outfile," || S[i-1]==11 || S[i-1]==13))"
  242. FPRINT Outfile," i--;"
  243. FPRINT Outfile," char *strtmp=BCX_TmpStr(i);"
  244. FPRINT Outfile," return (char*)memcpy(strtmp,S,i);"
  245. FPRINT Outfile,"}\n\n"
  246. END IF
  247. IF Use_Ltrim THEN
  248. FPRINT Outfile,"char *ltrim (char *S, char c)"
  249. FPRINT Outfile,"{"
  250. FPRINT Outfile," if(S[0]==0) return S;"
  251. FPRINT Outfile," while((*S==32 || *S==c) && *S !=0) S++;"
  252. FPRINT Outfile," char *strtmp = BCX_TmpStr(strlen(S));"
  253. FPRINT Outfile," return strcpy(strtmp,S);"
  254. FPRINT Outfile,"}\n\n"
  255. END IF
  256. IF Use_Rtrim THEN
  257. FPRINT Outfile,"char *rtrim (char *S,char c)"
  258. FPRINT Outfile,"{"
  259. FPRINT Outfile," if(S[0]==0) return S;"
  260. FPRINT Outfile," int i = strlen(S);"
  261. FPRINT Outfile," while(i>0 && (S[i-1]==c || S[i-1]==32))"
  262. FPRINT Outfile," i--;"
  263. FPRINT Outfile," char *strtmp = BCX_TmpStr(i);"
  264. FPRINT Outfile," return (char*)memcpy(strtmp,S,i);"
  265. FPRINT Outfile,"}\n\n"
  266. END IF
  267. IF Use_Strim THEN
  268. FPRINT Outfile,"char *strim (char *src)"
  269. FPRINT Outfile,"{"
  270. FPRINT Outfile," char *strtmp = BCX_TmpStr(strlen(src));"
  271. FPRINT Outfile," char *dst = strtmp;"
  272. FPRINT Outfile," while (isspace((unsigned char)*src)) src++;"
  273. FPRINT Outfile," do"
  274. FPRINT Outfile," {"
  275. FPRINT Outfile," while (*src && !isspace((unsigned char)*src)) *dst++ = *src++;"
  276. FPRINT Outfile," if (*src)"
  277. FPRINT Outfile," {"
  278. FPRINT Outfile," *dst++ = *src++;"
  279. FPRINT Outfile," while (isspace((unsigned char)*src)) src++;"
  280. FPRINT Outfile," }"
  281. FPRINT Outfile," } while (*src);"
  282. FPRINT Outfile," if (isspace((unsigned char)*(--dst))) *dst = 0;"
  283. FPRINT Outfile," return strtmp;"
  284. FPRINT Outfile,"}\n\n"
  285. END IF
  286. IF Use_Command THEN
  287. FPRINT Outfile,"char *command (int nArg)"
  288. FPRINT Outfile," {"
  289. FPRINT Outfile," int i = 0;"
  290. FPRINT Outfile," char *retstr=BCX_TmpStr(1);"
  291. FPRINT Outfile," if(nArg < i) // return entire commandline"
  292. FPRINT Outfile," {"
  293. FPRINT Outfile," retstr = BCX_TmpStr(G_argc * 2048);"
  294. FPRINT Outfile," for(i=1; i < G_argc; i++)"
  295. FPRINT Outfile," {"
  296. FPRINT Outfile," strcat(retstr, G_argv[i]);"
  297. FPRINT Outfile," strcat(retstr, SPC);"
  298. FPRINT Outfile," }"
  299. FPRINT Outfile," }"
  300. FPRINT Outfile," else if(nArg < G_argc)"
  301. FPRINT Outfile," {"
  302. FPRINT Outfile," retstr = BCX_TmpStr(strlen(G_argv[nArg]) + 1);"
  303. FPRINT Outfile," strcpy(retstr, G_argv[nArg]);"
  304. FPRINT Outfile," }"
  305. FPRINT Outfile," return retstr;"
  306. FPRINT Outfile,"}\n\n"
  307. END IF
  308. IF Use_Extract THEN
  309. FPRINT Outfile,"char *extract (char *mane, char *match)"
  310. FPRINT Outfile,"{"
  311. FPRINT Outfile," char *a;"
  312. FPRINT Outfile," char *strtmp = BCX_TmpStr(strlen(mane));"
  313. FPRINT Outfile," if(*match!=0)"
  314. FPRINT Outfile," {"
  315. FPRINT Outfile," a=_strstr_(mane,match);"
  316. FPRINT Outfile," if(a) return (char*)memcpy(strtmp,mane,a-mane);"
  317. FPRINT Outfile," }"
  318. FPRINT Outfile," return strcpy(strtmp,mane);"
  319. FPRINT Outfile,"}\n\n"
  320. END IF
  321. IF Use_Remain THEN
  322. FPRINT Outfile,"char *remain (char *mane, char *mat)"
  323. FPRINT Outfile,"{"
  324. FPRINT Outfile," char *p = strstr(mane,mat);"
  325. FPRINT Outfile," if(p)"
  326. FPRINT Outfile," {"
  327. FPRINT Outfile," p+=(strlen(mat));"
  328. FPRINT Outfile," return p;"
  329. FPRINT Outfile," }"
  330. FPRINT Outfile," return mane;"
  331. FPRINT Outfile,"}\n\n"
  332. END IF
  333. IF Use_Replace THEN
  334. FPRINT Outfile,"char *replace (char *src, char *pat, char *rep)"
  335. FPRINT Outfile,"{"
  336. FPRINT Outfile," size_t patsz, repsz, tmpsz, delta;"
  337. FPRINT Outfile," char *strtmp, *p, *q, *r;"
  338. FPRINT Outfile," if (!pat || !*pat)"
  339. FPRINT Outfile," {"
  340. FPRINT Outfile," strtmp = BCX_TmpStr(strlen(src));"
  341. FPRINT Outfile," if (!strtmp) return NULL;"
  342. FPRINT Outfile," return strcpy(strtmp, src);"
  343. FPRINT Outfile," }"
  344. FPRINT Outfile," repsz = strlen(rep);"
  345. FPRINT Outfile," patsz = strlen(pat);"
  346. FPRINT Outfile," for (tmpsz=0, p=src; (q=_strstr_(p,pat))!=0; p=q+patsz)"
  347. FPRINT Outfile," tmpsz += (size_t) (q - p) + repsz;"
  348. FPRINT Outfile," tmpsz += strlen(p);"
  349. FPRINT Outfile," strtmp = BCX_TmpStr(tmpsz);"
  350. FPRINT Outfile," if (!strtmp) return NULL;"
  351. FPRINT Outfile," for (r=strtmp,p=src; (q=_strstr_(p,pat))!=0;p=q+patsz)"
  352. FPRINT Outfile," {"
  353. FPRINT Outfile," delta = (size_t) (q-p);"
  354. FPRINT Outfile," memcpy(r,p,delta); r += delta;"
  355. FPRINT Outfile," strcpy(r,rep); r += repsz;"
  356. FPRINT Outfile," }"
  357. FPRINT Outfile," strcpy(r,p);"
  358. FPRINT Outfile," return strtmp;"
  359. FPRINT Outfile,"}\n\n"
  360. END IF
  361. IF Use_Reverse THEN
  362. FPRINT Outfile,"char *reverse (char *s)"
  363. FPRINT Outfile,"{"
  364. FPRINT Outfile," int j=strlen(s);"
  365. FPRINT Outfile," char *rstr = BCX_TmpStr(j);"
  366. FPRINT Outfile," while(j) rstr[--j] = *(s++);"
  367. FPRINT Outfile," return rstr;"
  368. FPRINT Outfile,"}\n\n"
  369. END IF
  370. IF Use_Findfirst THEN
  371. FPRINT Outfile,"char *findfirst (char *filespec, FILE_FIND_DATA *FindData)"
  372. FPRINT Outfile,"{"
  373. FPRINT Outfile," struct dirent *dp;"
  374. FPRINT Outfile," struct stat st;"
  375. FPRINT Outfile,""
  376. FPRINT Outfile," if(FindData->FileHandle)"
  377. FPRINT Outfile," closedir(FindData->FileHandle);"
  378. FPRINT Outfile,""
  379. FPRINT Outfile," strcpy(FindData->path, BcxSplitPath(filespec, FDRV|FPATH));"
  380. FPRINT Outfile," strcpy(FindData->cFileSpec,BcxSplitPath(filespec, FNAME|FEXT));"
  381. FPRINT Outfile," if(*FindData->path==0) strcpy(FindData->path, ",ENC$("."),");"
  382. FPRINT Outfile,""
  383. FPRINT Outfile," FindData->FileHandle=opendir(FindData->path);"
  384. FPRINT Outfile,""
  385. FPRINT Outfile," while(FindData->FileHandle)"
  386. FPRINT Outfile," {"
  387. FPRINT Outfile," dp=readdir(FindData->FileHandle);"
  388. FPRINT Outfile," if(dp==NULL) break;"
  389. FPRINT Outfile,""
  390. FPRINT Outfile," if(like(dp->d_name,FindData->cFileSpec))"
  391. FPRINT Outfile," {"
  392. FPRINT Outfile," strcpy(FindData->cFileName,dp->d_name);"
  393. FPRINT Outfile," lstat(join(2,FindData->path,dp->d_name), &st);"
  394. FPRINT Outfile," FindData->dwFileAttributes = st.st_mode;"
  395. FPRINT Outfile," return FindData->cFileName;"
  396. FPRINT Outfile," }"
  397. FPRINT Outfile," }"
  398. FPRINT Outfile,""
  399. FPRINT Outfile," *FindData->cFileName=0;"
  400. FPRINT Outfile," return FindData->cFileName;"
  401. FPRINT Outfile,"}\n\n"
  402. END IF
  403. IF Use_Findnext THEN
  404. FPRINT Outfile,"char *findnext (FILE_FIND_DATA *FindData)"
  405. FPRINT Outfile,"{"
  406. FPRINT Outfile," struct dirent *dp;"
  407. FPRINT Outfile," struct stat st;"
  408. FPRINT Outfile,""
  409. FPRINT Outfile," while(FindData->FileHandle)"
  410. FPRINT Outfile," {"
  411. FPRINT Outfile," dp=readdir(FindData->FileHandle);"
  412. FPRINT Outfile," if(dp==NULL) break;"
  413. FPRINT Outfile,""
  414. FPRINT Outfile," if(like(dp->d_name,FindData->cFileSpec))"
  415. FPRINT Outfile," {"
  416. FPRINT Outfile," strcpy(FindData->cFileName,dp->d_name);"
  417. FPRINT Outfile," lstat(join(2,FindData->path,dp->d_name), &st);"
  418. FPRINT Outfile," FindData->dwFileAttributes = st.st_mode;"
  419. FPRINT Outfile," return FindData->cFileName;"
  420. FPRINT Outfile," }"
  421. FPRINT Outfile," }"
  422. FPRINT Outfile,""
  423. FPRINT Outfile," *FindData->cFileName=0;"
  424. FPRINT Outfile," return FindData->cFileName;"
  425. FPRINT Outfile,"}\n\n"
  426. END IF
  427. IF Use_Ucase THEN
  428. FPRINT Outfile,"char *ucase (char *S)"
  429. FPRINT Outfile,"{"
  430. FPRINT Outfile," char *strtmp = BCX_TmpStr(strlen(S));"
  431. FPRINT Outfile," return _strupr_(strcpy(strtmp,S));"
  432. FPRINT Outfile,"}\n\n"
  433. END IF
  434. IF Use_Lcase THEN
  435. FPRINT Outfile,"char *lcase (char *S)"
  436. FPRINT Outfile,"{"
  437. FPRINT Outfile," char *strtmp = BCX_TmpStr(strlen(S));"
  438. FPRINT Outfile," return _strlwr_(strcpy(strtmp,S));"
  439. FPRINT Outfile,"}\n\n"
  440. END IF
  441. IF Use_Mcase THEN
  442. FPRINT Outfile,"char *mcase (char *S)"
  443. FPRINT Outfile,"{"
  444. FPRINT Outfile," char *strtmp = BCX_TmpStr(strlen(S)+1);"
  445. FPRINT Outfile," char *s = strtmp;"
  446. FPRINT Outfile," _strlwr_(strcpy(strtmp,S));"
  447. FPRINT Outfile," while(*s)"
  448. FPRINT Outfile," {"
  449. FPRINT Outfile," if(islower(*s))"
  450. FPRINT Outfile," {"
  451. FPRINT Outfile," *s-=32;"
  452. FPRINT Outfile," while(isalpha(*++s));"
  453. FPRINT Outfile," }"
  454. FPRINT Outfile," s++;"
  455. FPRINT Outfile," }"
  456. FPRINT Outfile," return strtmp;"
  457. FPRINT Outfile,"}\n\n"
  458. END IF
  459. IF Use_Remove THEN
  460. FPRINT Outfile,"char *RemoveStr (char *a, char *b)"
  461. FPRINT Outfile,"{"
  462. FPRINT Outfile," char *strtmp, *p, *d;"
  463. FPRINT Outfile," int tmplen;"
  464. FPRINT Outfile," strtmp = d = BCX_TmpStr(strlen(a));"
  465. FPRINT Outfile," if(!b || !*b) return strcpy(strtmp,a);"
  466. FPRINT Outfile," p=_strstr_(a,b); tmplen = strlen(b);"
  467. FPRINT Outfile," while(p)"
  468. FPRINT Outfile," {"
  469. FPRINT Outfile," memcpy(d,a,p-a);"
  470. FPRINT Outfile," d+= (p-a);"
  471. FPRINT Outfile," a=p+tmplen;"
  472. FPRINT Outfile," p=_strstr_(a,b);"
  473. FPRINT Outfile," }"
  474. FPRINT Outfile," strcpy(d,a);"
  475. FPRINT Outfile," return strtmp;"
  476. FPRINT Outfile,"}\n\n"
  477. END IF
  478. IF Use_IRemove THEN
  479. FPRINT Outfile,"char *IRemoveStr (char *a, char *b)"
  480. FPRINT Outfile,"{"
  481. FPRINT Outfile," char *strtmp, *p, *d;"
  482. FPRINT Outfile," int tmplen;"
  483. FPRINT Outfile," strtmp = d = BCX_TmpStr(strlen(a));"
  484. FPRINT Outfile," if(!b || !*b) return strcpy(strtmp,a);"
  485. FPRINT Outfile," p=_stristr_(a,b); tmplen = strlen(b);"
  486. FPRINT Outfile," while(p)"
  487. FPRINT Outfile," {"
  488. FPRINT Outfile," memcpy(d,a,p-a);"
  489. FPRINT Outfile," d+= (p-a);"
  490. FPRINT Outfile," a=p+tmplen;"
  491. FPRINT Outfile," p=_stristr_(a,b);"
  492. FPRINT Outfile," }"
  493. FPRINT Outfile," strcpy(d,a);"
  494. FPRINT Outfile," return strtmp;"
  495. FPRINT Outfile,"}\n\n"
  496. END IF
  497. IF Use_Ins THEN
  498. FPRINT Outfile,"char *ins (char *S, int i, char *a)"
  499. FPRINT Outfile,"{"
  500. FPRINT Outfile," int j = strlen(S);"
  501. FPRINT Outfile," if(i<1 || i>j+1) return S;"
  502. FPRINT Outfile," char *strtmp = BCX_TmpStr(j + strlen(a));"
  503. FPRINT Outfile," memcpy(strtmp,S,--i);"
  504. FPRINT Outfile," strcpy(&strtmp[i],a);"
  505. FPRINT Outfile," return strcat(strtmp,&S[i]);"
  506. FPRINT Outfile,"}\n\n"
  507. END IF
  508. IF Use_Del THEN
  509. FPRINT Outfile,"char *del (char *S, int i, int j)"
  510. FPRINT Outfile,"{"
  511. FPRINT Outfile," int ln = strlen(S);"
  512. FPRINT Outfile," if(i<1 || i>ln) return S;"
  513. FPRINT Outfile," char *strtmp = BCX_TmpStr(ln);"
  514. FPRINT Outfile," memcpy(strtmp,S,--i);"
  515. FPRINT Outfile," return strcat(strtmp,&S[i+j]);"
  516. FPRINT Outfile,"}\n\n"
  517. END IF
  518. IF Use_Str THEN
  519. FPRINT Outfile,"char *str (double d)"
  520. FPRINT Outfile,"{"
  521. FPRINT Outfile," char *strtmp = BCX_TmpStr(16);"
  522. FPRINT Outfile," sprintf(strtmp,";D1$;",d);"
  523. FPRINT Outfile," return strtmp;"
  524. FPRINT Outfile,"}\n\n"
  525. END IF
  526. IF Use_Strl THEN
  527. FPRINT Outfile,"char *strl (long double d)"
  528. FPRINT Outfile,"{"
  529. FPRINT Outfile," char *strtmp = BCX_TmpStr(27);"
  530. FPRINT Outfile," sprintf(strtmp,";D2$;",d);"
  531. FPRINT Outfile," return strtmp;"
  532. FPRINT Outfile,"}\n\n"
  533. END IF
  534. IF Use_Curdir THEN
  535. FPRINT Outfile,"char *curdir (void)"
  536. FPRINT Outfile,"{"
  537. FPRINT Outfile," char *strtmp = BCX_TmpStr(2048);"
  538. FPRINT Outfile," char *res=getcwd(strtmp, 1024);"
  539. FPRINT Outfile," return strtmp;"
  540. FPRINT Outfile,"}\n\n"
  541. END IF
  542. IF Use_Hex THEN
  543. FPRINT Outfile,"char *hex (int a)"
  544. FPRINT Outfile,"{"
  545. FPRINT Outfile," char *strtmp = BCX_TmpStr(16);"
  546. FPRINT Outfile," sprintf(strtmp,";enc$("%02X");",a);"
  547. FPRINT Outfile," return strtmp;"
  548. FPRINT Outfile,"}\n\n"
  549. END IF
  550. IF Use_Tempdir THEN
  551. FPRINT Outfile,"char *tempdir (void)"
  552. FPRINT Outfile,"{"
  553. FPRINT Outfile," char *strtmp = BCX_TmpStr(2048);"
  554. FPRINT Outfile," if(!Exist(";enc$("/tmp/mbc.compiler");")) {"
  555. FPRINT Outfile," mkdir (";enc$("/tmp/mbc.compiler");",0755);"
  556. FPRINT Outfile," }"
  557. FPRINT Outfile," strcpy(strtmp,";enc$("/tmp/mbc.compiler");");"
  558. FPRINT Outfile," return strtmp;"
  559. FPRINT Outfile,"}\n\n"
  560. END IF
  561. IF Use_Sysdir THEN
  562. FPRINT Outfile,"char *sysdir (void)"
  563. FPRINT Outfile,"{"
  564. FPRINT Outfile," char *strtmp = BCX_TmpStr(2048);"
  565. FPRINT Outfile," GetSystemDirectory (strtmp,2048);"
  566. FPRINT Outfile," return strtmp;"
  567. FPRINT Outfile,"}\n\n"
  568. END IF
  569. IF Use_Repeat THEN
  570. FPRINT Outfile,"char *repeat (int count, char *a)"
  571. FPRINT Outfile,"{"
  572. FPRINT Outfile," char *strtmp = BCX_TmpStr((1+count)*strlen(a));"
  573. FPRINT Outfile," while(count-->0) strtmp = strcat(strtmp, a);"
  574. FPRINT Outfile," return strtmp;"
  575. FPRINT Outfile,"}\n\n"
  576. END IF
  577. IF Use_String THEN
  578. FPRINT Outfile,"char *stringx (int count, int a)"
  579. FPRINT Outfile,"{"
  580. FPRINT Outfile," if(count<1) return BCX_TmpStr(1);"
  581. FPRINT Outfile," char *strtmp = BCX_TmpStr(count);"
  582. FPRINT Outfile," return (char*)memset(strtmp,a,count);"
  583. FPRINT Outfile,"}\n\n"
  584. END IF
  585. IF Use_Shell THEN
  586. FPRINT Outfile,"void Shell (char *cmd)"
  587. FPRINT Outfile,"{"
  588. FPRINT Outfile," int res=system(cmd);"
  589. FPRINT Outfile,"}\n\n"
  590. END IF
  591. IF Use_Space THEN
  592. FPRINT Outfile,"char *space (int count)"
  593. FPRINT Outfile,"{"
  594. FPRINT Outfile," if(count<1) return BCX_TmpStr(1);"
  595. FPRINT Outfile," char *strtmp = BCX_TmpStr(count);"
  596. FPRINT Outfile," return (char*)memset(strtmp,32,count);"
  597. FPRINT Outfile,"}\n\n"
  598. END IF
  599. IF Use_Time THEN
  600. FPRINT Outfile,"char *timef (int t)"
  601. FPRINT Outfile,"{"
  602. FPRINT Outfile," time_t elapse_time;"
  603. FPRINT Outfile," struct tm *tp;"
  604. FPRINT Outfile," char *strtmp = BCX_TmpStr(256);"
  605. FPRINT Outfile," time (&elapse_time);"
  606. FPRINT Outfile," tp = localtime(&elapse_time);"
  607. FPRINT Outfile," switch (t)"
  608. FPRINT Outfile," {"
  609. FPRINT Outfile," case 0:"
  610. FPRINT Outfile," strftime(strtmp,256,",T0$, ",tp); break;"
  611. FPRINT Outfile," case 1:"
  612. FPRINT Outfile," strftime(strtmp,256,",T1$, ",tp); break;"
  613. FPRINT Outfile," case 2:"
  614. FPRINT Outfile," strftime(strtmp,256,",T2$, ",tp); break;"
  615. FPRINT Outfile," case 3:"
  616. FPRINT Outfile," strftime(strtmp,256,",T3$, ",tp); break;"
  617. FPRINT Outfile," case 4:"
  618. FPRINT Outfile," strftime(strtmp,256,",T4$, ",tp); break;"
  619. FPRINT Outfile," case 5:"
  620. FPRINT Outfile," strftime(strtmp,256,",T5$, ",tp); break;"
  621. FPRINT Outfile," case 6:"
  622. FPRINT Outfile," strftime(strtmp,256,",T6$, ",tp); break;"
  623. FPRINT Outfile," case 7:"
  624. FPRINT Outfile," strftime(strtmp,256,",T7$, ",tp); break;"
  625. FPRINT Outfile," case 8:"
  626. FPRINT Outfile," strftime(strtmp,256,",T8$, ",tp); break;"
  627. FPRINT Outfile," case 9:"
  628. FPRINT Outfile," strftime(strtmp,256,",T9$, ",tp); break;"
  629. FPRINT Outfile," case 10:"
  630. FPRINT Outfile," strftime(strtmp,256,",T10$, ",tp); break;"
  631. FPRINT Outfile," case 11:"
  632. FPRINT Outfile," strftime(strtmp,256,",T11$, ",tp); break;"
  633. FPRINT Outfile," case 12:"
  634. FPRINT Outfile," strftime(strtmp,256,",T12$, ",tp); break;"
  635. FPRINT Outfile," case 13:"
  636. FPRINT Outfile," strftime(strtmp,256,",T13$, ",tp); break;"
  637. FPRINT Outfile," }"
  638. FPRINT Outfile," return strtmp;"
  639. FPRINT Outfile,"}\n\n"
  640. END IF
  641. IF Use_Enclose THEN
  642. FPRINT Outfile,"char *enc (char *A, int L, int R)"
  643. FPRINT Outfile,"{"
  644. FPRINT Outfile," char *BCX_RetStr = BCX_TmpStr(strlen(A)+3);"
  645. FPRINT Outfile," if(L==0) L=34;"
  646. FPRINT Outfile," if(R==0) R=L;"
  647. FPRINT Outfile," sprintf(BCX_RetStr,",ENC$("%c%s%c%s"),",L,A,R,",ENC$("\0"),");"
  648. FPRINT Outfile," return BCX_RetStr;"
  649. FPRINT Outfile,"}\n\n"
  650. END IF
  651. IF Use_Chr THEN
  652. FPRINT Outfile,"char *chr (int a,int b,int c,int d,int e,int f,int g,int h,int i,int j)"
  653. FPRINT Outfile,"{"
  654. FPRINT Outfile," char *strtmp = BCX_TmpStr(11);"
  655. FPRINT Outfile," strtmp[0] = a;"
  656. FPRINT Outfile," strtmp[1] = b;"
  657. FPRINT Outfile," strtmp[2] = c;"
  658. FPRINT Outfile," strtmp[3] = d;"
  659. FPRINT Outfile," strtmp[4] = e;"
  660. FPRINT Outfile," strtmp[5] = f;"
  661. FPRINT Outfile," strtmp[6] = g;"
  662. FPRINT Outfile," strtmp[7] = h;"
  663. FPRINT Outfile," strtmp[8] = i;"
  664. FPRINT Outfile," strtmp[9] = j;"
  665. FPRINT Outfile," strtmp[10] = 0;"
  666. FPRINT Outfile," return strtmp;"
  667. FPRINT Outfile,"}\n\n"
  668. END IF
  669. IF Use_VChr THEN
  670. FPRINT Outfile,"char *vchr(int charcount, ...)"
  671. FPRINT Outfile,"{"
  672. FPRINT Outfile," int c = 0, i = charcount;"
  673. FPRINT Outfile," char *s_ = BCX_TmpStr(charcount + 1);"
  674. FPRINT Outfile," va_list marker;"
  675. FPRINT Outfile," s_[i] = 0;"
  676. FPRINT Outfile," va_start(marker, charcount);"
  677. FPRINT Outfile," while(i-- > 0) s_[c++] = va_arg(marker,int);"
  678. FPRINT Outfile," va_end(marker);"
  679. FPRINT Outfile," return s_;"
  680. FPRINT Outfile,"}\n\n"
  681. END IF
  682. IF Use_Join THEN
  683. FPRINT Outfile,"char * join(int n, ...)"
  684. FPRINT Outfile,"{"
  685. FPRINT Outfile," int i = n, tmplen = 0;"
  686. FPRINT Outfile," char *strtmp, *s_;"
  687. FPRINT Outfile,""
  688. FPRINT Outfile," va_list marker;"
  689. FPRINT Outfile," va_start(marker, n); // Initialize variable arguments"
  690. FPRINT Outfile," while(i-- > 0)"
  691. FPRINT Outfile," {"
  692. FPRINT Outfile," s_ = va_arg(marker, char *);"
  693. FPRINT Outfile," if(s_) tmplen += strlen(s_);"
  694. FPRINT Outfile," }"
  695. FPRINT Outfile," strtmp = BCX_TmpStr(tmplen);"
  696. FPRINT Outfile," va_end(marker); // Reset variable arguments"
  697. FPRINT Outfile," i = n;"
  698. FPRINT Outfile," va_start(marker, n); // Initialize variable arguments"
  699. FPRINT Outfile," while(i-- > 0)"
  700. FPRINT Outfile," {"
  701. FPRINT Outfile," s_ = va_arg(marker, char *);"
  702. FPRINT Outfile," if(s_) strcat(strtmp, s_);"
  703. FPRINT Outfile," }"
  704. FPRINT Outfile," va_end(marker); // Reset variable arguments"
  705. FPRINT Outfile," return strtmp;"
  706. FPRINT Outfile,"}\n\n"
  707. END IF
  708. IF Use_Environ THEN
  709. FPRINT Outfile,"char* Environ(char *S)"
  710. FPRINT Outfile,"{"
  711. FPRINT Outfile," char *strtmp, *tmp;"
  712. FPRINT Outfile,""
  713. FPRINT Outfile," tmp = getenv(S);"
  714. FPRINT Outfile," if(tmp != NULL) {"
  715. FPRINT Outfile," strtmp = BCX_TmpStr(strlen(tmp)+1);"
  716. FPRINT Outfile," return strcpy(strtmp, tmp);"
  717. FPRINT Outfile," }"
  718. FPRINT Outfile," return BCX_TmpStr(1);"
  719. FPRINT Outfile,"}\n\n"
  720. END IF
  721. IF Use_Oct THEN
  722. FPRINT Outfile,"char *oct (int a)"
  723. FPRINT Outfile,"{"
  724. FPRINT Outfile," char *strtmp = BCX_TmpStr(2048);"
  725. FPRINT Outfile," sprintf(strtmp,";O1$;",a);"
  726. FPRINT Outfile," return strtmp;"
  727. FPRINT Outfile,"}\n\n"
  728. END IF
  729. IF Use_Bin THEN
  730. FPRINT Outfile,"char* Bin(int number)"
  731. FPRINT Outfile,"{"
  732. FPRINT Outfile," char *strtmp = BCX_TmpStr(2048);"
  733. FPRINT Outfile," itoa(number,strtmp,2);"
  734. FPRINT Outfile," return strtmp;"
  735. FPRINT Outfile,"}\n\n"
  736. END IF
  737. IF Use_Pause THEN
  738. FPRINT Outfile,"void Pause(void)"
  739. FPRINT Outfile,"{"
  740. FPRINT Outfile," printf(", ENC$("\\n%s\\n"), ",", ENC$("Press any key to continue . . ."), ");"
  741. FPRINT Outfile," _getch_(TRUE);"
  742. FPRINT Outfile,"}\n\n"
  743. END IF
  744. IF Use_Keypress THEN
  745. FPRINT Outfile,"int keypress(void)"
  746. FPRINT Outfile,"{"
  747. FPRINT Outfile," return _getch_(TRUE);"
  748. FPRINT Outfile,"}\n\n"
  749. END IF
  750. IF Use_Inkey THEN
  751. FPRINT Outfile,"char* inkey(void)"
  752. FPRINT Outfile,"{"
  753. FPRINT Outfile," char *strtmp = BCX_TmpStr(2);"
  754. FPRINT Outfile," strtmp[0] = _getch_(FALSE);"
  755. FPRINT Outfile," if(strtmp[0] == -1) strtmp[0] = 0;"
  756. FPRINT Outfile," return strtmp;"
  757. FPRINT Outfile,"}\n\n"
  758. END IF
  759. IF Use_InkeyD THEN
  760. FPRINT Outfile,"int inkeyd(void)"
  761. FPRINT Outfile,"{"
  762. FPRINT Outfile," return _getch_(TRUE);"
  763. FPRINT Outfile,"}\n\n"
  764. END IF
  765. '/***** 2010-12-08 Added to support INSTAT -AIR *****/
  766. IF Use_Instat THEN
  767. FPRINT Outfile,"int kbhit(void)"
  768. FPRINT Outfile,"{"
  769. FPRINT Outfile," struct termios oldt, newt;"
  770. FPRINT Outfile," int ch;"
  771. FPRINT Outfile," int oldf;"
  772. FPRINT Outfile," tcgetattr(STDIN_FILENO, &oldt);"
  773. FPRINT Outfile," newt = oldt;"
  774. FPRINT Outfile," newt.c_lflag &= ~(ICANON | ECHO);"
  775. FPRINT Outfile," tcsetattr(STDIN_FILENO, TCSANOW, &newt);"
  776. FPRINT Outfile," oldf = fcntl(STDIN_FILENO, F_GETFL, 0);"
  777. FPRINT Outfile," fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);"
  778. FPRINT Outfile," ch = getchar();"
  779. FPRINT Outfile," tcsetattr(STDIN_FILENO, TCSANOW, &oldt);"
  780. FPRINT Outfile," fcntl(STDIN_FILENO, F_SETFL, oldf);"
  781. FPRINT Outfile," if(ch != EOF)"
  782. FPRINT Outfile," {"
  783. FPRINT Outfile," ungetc(ch, stdin);"
  784. FPRINT Outfile," return 1;"
  785. FPRINT Outfile," }"
  786. FPRINT Outfile," return 0;"
  787. FPRINT Outfile,"}\n\n"
  788. END IF
  789. IF Use_GetCh THEN
  790. FPRINT Outfile,"int _getch_(int waitkey)"
  791. FPRINT Outfile,"{"
  792. FPRINT Outfile," struct termios initial_settings, new_settings;"
  793. FPRINT Outfile," unsigned char ch;"
  794. FPRINT Outfile,""
  795. FPRINT Outfile," tcgetattr(0,&initial_settings);"
  796. FPRINT Outfile," new_settings = initial_settings;"
  797. FPRINT Outfile," new_settings.c_lflag &= ~ICANON;"
  798. FPRINT Outfile," new_settings.c_lflag &= ~ECHO;"
  799. FPRINT Outfile," new_settings.c_lflag &= ~ISIG;"
  800. FPRINT Outfile," new_settings.c_cc[VMIN] = waitkey;"
  801. FPRINT Outfile," new_settings.c_cc[VTIME] = 0;"
  802. FPRINT Outfile," tcsetattr(0, TCSANOW, &new_settings);"
  803. FPRINT Outfile,""
  804. FPRINT Outfile," //read(0,&ch,1);"
  805. FPRINT Outfile," ch = getchar();"
  806. FPRINT Outfile," tcsetattr(0, TCSANOW, &initial_settings);"
  807. FPRINT Outfile," return ch;"
  808. FPRINT Outfile,"}\n\n"
  809. END IF
  810. IF Use_Now THEN
  811. FPRINT Outfile,"char *now (void)"
  812. FPRINT Outfile,"{"
  813. FPRINT Outfile," time_t elapse_time;"
  814. FPRINT Outfile," struct tm *tp;"
  815. FPRINT Outfile," char *strtmp = BCX_TmpStr(2048);"
  816. FPRINT Outfile," time(&elapse_time);"
  817. FPRINT Outfile," tp=localtime(&elapse_time);"
  818. FPRINT Outfile," strftime(strtmp,256,", ENC$("%m/%d/%y %I:%M:%S: %p"), ",tp);"
  819. FPRINT Outfile," return strtmp;"
  820. FPRINT Outfile,"}"
  821. END IF
  822. IF Use_AppExePath THEN
  823. FPRINT Outfile,"char *AppExePath (void)"
  824. FPRINT Outfile,"{"
  825. FPRINT Outfile," char fullpath[MAX_PATH];"
  826. FPRINT Outfile," int length;"
  827. !#if defined (__APPLE__)
  828. FPRINT Outfile," pid_t pid = getpid();"
  829. FPRINT Outfile," length = proc_pidpath (pid, fullpath, sizeof(fullpath));"
  830. !#else
  831. FPRINT Outfile," length = readlink(", ENC$("/proc/self/exe"),", fullpath, MAX_PATH);"
  832. !#endif
  833. FPRINT Outfile," if(length < 1) return BCX_TmpStr(1);"
  834. FPRINT Outfile,""
  835. FPRINT Outfile," fullpath[length] = 0;"
  836. FPRINT Outfile," return BcxSplitPath(fullpath, FDRV|FPATH);"
  837. FPRINT Outfile,"}\n\n"
  838. END IF
  839. IF Use_AppExeName THEN
  840. FPRINT Outfile,"char *AppExeName (void)"
  841. FPRINT Outfile,"{"
  842. FPRINT Outfile," return BcxSplitPath(G_argv[0], FNAME|FEXT);"
  843. FPRINT Outfile,"}\n\n"
  844. END IF
  845. IF Use_TempFileName THEN
  846. FPRINT Outfile,"char * TempFileName (char *dr, char *prefix)"
  847. FPRINT Outfile,"{"
  848. FPRINT Outfile," static unsigned int count;"
  849. FPRINT Outfile," char *f, *tmpstr = BCX_TmpStr(MAX_PATH);"
  850. FPRINT Outfile," int i, length;"
  851. FPRINT Outfile,""
  852. FPRINT Outfile," if(!count) srand(time(0));"
  853. FPRINT Outfile,""
  854. FPRINT Outfile," if(dr) strcpy(tmpstr, dr);"
  855. FPRINT Outfile," length = strlen(tmpstr);"
  856. FPRINT Outfile," if(length && (tmpstr[length-1] != '\\\\' && tmpstr[length-1] != '/'))"
  857. FPRINT Outfile," tmpstr[length++] = '/';"
  858. FPRINT Outfile," if(prefix) strcpy(&tmpstr[length], prefix);"
  859. FPRINT Outfile," f = &tmpstr[strlen(tmpstr)];"
  860. FPRINT Outfile,""
  861. FPRINT Outfile," do {"
  862. FPRINT Outfile," count++;"
  863. FPRINT Outfile," for(i=0; i<5; i+=1)"
  864. FPRINT Outfile," {"
  865. FPRINT Outfile," do {"
  866. FPRINT Outfile," f[i]=(char)(rnd()*122);"
  867. FPRINT Outfile," }while((f[i]<65)||(f[i]>90&&f[i]<97));"
  868. FPRINT Outfile," }"
  869. FPRINT Outfile," snprintf(&f[5],3,",ENC$("%x"),", count);"
  870. FPRINT Outfile," } while (Exist(tmpstr));"
  871. FPRINT Outfile,""
  872. FPRINT Outfile," return tmpstr;"
  873. FPRINT Outfile,"}\n\n"
  874. END IF
  875. IF Use_Boolstr THEN
  876. FPRINT Outfile,"char * BoolStr (int a)"
  877. FPRINT Outfile,"{"
  878. FPRINT Outfile," char *BCX_RetStr=BCX_TmpStr(5);"
  879. FPRINT Outfile," if(a) return strcpy(BCX_RetStr,",ENC$("True"),");"
  880. FPRINT Outfile," return strcpy(BCX_RetStr,",ENC$("False"),");"
  881. FPRINT Outfile,"}\n\n"
  882. END IF
  883. IF Use_Using THEN
  884. FPRINT Outfile,"char *Using (char *Mask, double Num)"
  885. FPRINT Outfile,"{"
  886. FPRINT Outfile," int Spaces = 0;"
  887. FPRINT Outfile," int CntDec = 0;"
  888. FPRINT Outfile," int Decimals = 0;"
  889. FPRINT Outfile," int Dollar = 0;"
  890. FPRINT Outfile," char* BCX_RetStr = BCX_TmpStr(512);"
  891. FPRINT Outfile," char Buf_1[512]={0};"
  892. FPRINT Outfile," char* p = Mask;"
  893. FPRINT Outfile," char* r;"
  894. FPRINT Outfile," int len;"
  895. FPRINT Outfile,""
  896. FPRINT Outfile," while (*p)"
  897. FPRINT Outfile," {"
  898. FPRINT Outfile," if (*p == 36) Dollar++;"
  899. FPRINT Outfile," if (*p == 32) Spaces++;"
  900. FPRINT Outfile," if ((*p == 32 || *p == 35)&& CntDec) Decimals++;"
  901. FPRINT Outfile," if (*p == 46) CntDec = 1;"
  902. FPRINT Outfile," p++;"
  903. FPRINT Outfile," }"
  904. FPRINT Outfile," sprintf(Buf_1,", ENC$("%1.*f"), ",Decimals,Num);"
  905. FPRINT Outfile,""
  906. FPRINT Outfile," len = strlen(Buf_1)-Decimals-(Decimals>0?1:0);"
  907. FPRINT Outfile," r = BCX_RetStr+Dollar+Spaces;"
  908. FPRINT Outfile," p = Buf_1;"
  909. FPRINT Outfile," while (*p)"
  910. FPRINT Outfile," {"
  911. FPRINT Outfile," *r++ = *p++;"
  912. FPRINT Outfile," if (--len>2 && *(p-1) != '-' && len % 3 == 0)"
  913. FPRINT Outfile," {"
  914. FPRINT Outfile," *r++ = ',';"
  915. FPRINT Outfile," }"
  916. FPRINT Outfile," }"
  917. FPRINT Outfile," if(Dollar) BCX_RetStr[Spaces]=36;"
  918. FPRINT Outfile," if(Spaces) memset(BCX_RetStr,32,Spaces);"
  919. FPRINT Outfile,""
  920. FPRINT Outfile," return BCX_RetStr;"
  921. FPRINT Outfile,"}\n\n"
  922. END IF
  923. IF Use_SearchPath THEN
  924. FPRINT Outfile,"char *SEARCHPATH (char *szFile)"
  925. FPRINT Outfile,"{"
  926. FPRINT Outfile," char *BCX_RetStr=BCX_TmpStr(MAX_PATH+1);"
  927. FPRINT Outfile," PCHAR lpbs=0;"
  928. FPRINT Outfile," SearchPath(0,szFile,0,MAX_PATH,BCX_RetStr,&lpbs);"
  929. FPRINT Outfile," if(lpbs) *lpbs=0;"
  930. FPRINT Outfile," return BCX_RetStr;"
  931. FPRINT Outfile,"}\n\n"
  932. END IF
  933. IF Use_Instrrev THEN
  934. FPRINT Outfile,"int InstrRev (char *s, char *p, int os, int sens)"
  935. FPRINT Outfile,"{"
  936. FPRINT Outfile," int sl, pl, ox;"
  937. FPRINT Outfile," int (*cmp)(const char *, const char *, size_t );"
  938. FPRINT Outfile,""
  939. FPRINT Outfile," if (!s || !p) return 0;"
  940. FPRINT Outfile," sl = strlen(s); pl = strlen(p);"
  941. FPRINT Outfile," if (os > sl || sl == 0 || pl == 0 || (ox = sl - pl) < 0)"
  942. FPRINT Outfile," return 0;"
  943. FPRINT Outfile,""
  944. FPRINT Outfile," if (os <= 0) "
  945. FPRINT Outfile," os = ox ;"
  946. FPRINT Outfile," else if(os >= pl)"
  947. FPRINT Outfile," os = os - pl ;"
  948. FPRINT Outfile," else"
  949. FPRINT Outfile," return 0;"
  950. FPRINT Outfile,""
  951. FPRINT Outfile," cmp = (sens ? strncasecmp : strncmp);"
  952. FPRINT Outfile," do { if (cmp(s + os , p, pl) == 0)"
  953. FPRINT Outfile," return os+1;"
  954. FPRINT Outfile," } while (os--);"
  955. FPRINT Outfile," return 0;"
  956. FPRINT Outfile,"}\n\n"
  957. END IF
  958. IF Use_Instr THEN
  959. FPRINT Outfile,"int instr_b(char* mane,char* match,int offset,int sensflag)"
  960. FPRINT Outfile,"{"
  961. FPRINT Outfile," char *s;"
  962. FPRINT Outfile," if (!mane || !match || ! *match || offset>(int)strlen(mane)) return 0;"
  963. FPRINT Outfile," if (sensflag)"
  964. FPRINT Outfile," s = _stristr_(offset>0 ? mane+offset-1 : mane,match);"
  965. FPRINT Outfile," else"
  966. FPRINT Outfile," s = _strstr_(offset>0 ? mane+offset-1 : mane,match);"
  967. FPRINT Outfile," return s ? (int)(s-mane)+1 : 0;"
  968. FPRINT Outfile,"}\n\n"
  969. END IF
  970. IF UseLCaseTbl THEN
  971. FPRINT Outfile,"char *MakeLCaseTbl (void)"
  972. FPRINT Outfile,"{"
  973. FPRINT Outfile," static char tbl[256];"
  974. FPRINT Outfile," if(!tbl['a'])"
  975. FPRINT Outfile," {"
  976. FPRINT Outfile," int i; for (i=0; i < 256; i++)"
  977. FPRINT Outfile," tbl[i] = (char)(int)tolower(i);"
  978. FPRINT Outfile," }"
  979. FPRINT Outfile," return tbl;"
  980. FPRINT Outfile,"}\n\n"
  981. END IF
  982. IF Use_Stristr THEN
  983. FPRINT Outfile,"char *_stristr_(char *String, char *Pattern)"
  984. FPRINT Outfile,"{"
  985. FPRINT Outfile," int mi=-1;"
  986. FPRINT Outfile," char *LowCase = MakeLCaseTbl();"
  987. FPRINT Outfile," while(Pattern[++mi])"
  988. FPRINT Outfile," {"
  989. FPRINT Outfile," if(String[mi]==0) return 0;"
  990. FPRINT Outfile," if(LowCase[(unsigned char)String[mi]]!=LowCase[(unsigned char)Pattern[mi]])"
  991. FPRINT Outfile," { String++; mi=-1; }"
  992. FPRINT Outfile," }"
  993. FPRINT Outfile," return String;"
  994. FPRINT Outfile,"}\n\n"
  995. END IF
  996. IF Use_StrStr THEN
  997. FPRINT Outfile,"char *_strstr_(char *String, char *Pattern)"
  998. FPRINT Outfile,"{"
  999. FPRINT Outfile," int mi=-1;"
  1000. FPRINT Outfile," while(Pattern[++mi])"
  1001. FPRINT Outfile," {"
  1002. FPRINT Outfile," if(String[mi]==0) return 0;"
  1003. FPRINT Outfile," if(String[mi]!=Pattern[mi])"
  1004. FPRINT Outfile," { String++; mi=-1; }"
  1005. FPRINT Outfile," }"
  1006. FPRINT Outfile," return String;"
  1007. FPRINT Outfile,"}\n\n"
  1008. END IF
  1009. IF Use_Inchr THEN
  1010. FPRINT Outfile,"int inchr (char *A, char *B)"
  1011. FPRINT Outfile,"{"
  1012. FPRINT Outfile," char* C=A;"
  1013. FPRINT Outfile," while(*C)"
  1014. FPRINT Outfile," {"
  1015. FPRINT Outfile," if(*C==*B) return C-A+1;"
  1016. FPRINT Outfile," C++;"
  1017. FPRINT Outfile," }"
  1018. FPRINT Outfile," return 0;"
  1019. FPRINT Outfile,"}\n\n"
  1020. END IF
  1021. IF Use_Asc THEN
  1022. FPRINT Outfile,"extern int asc (char *z,int index)"
  1023. FPRINT Outfile,"{"
  1024. FPRINT Outfile," return (unsigned char) z[index];"
  1025. FPRINT Outfile,"}\n\n"
  1026. END IF
  1027. IF Use_Sgn THEN
  1028. FPRINT Outfile,"double sgn (double a)"
  1029. FPRINT Outfile,"{"
  1030. FPRINT Outfile," if(a<0) return -1;"
  1031. FPRINT Outfile," if(a>0) return 1;"
  1032. FPRINT Outfile," return 0;"
  1033. FPRINT Outfile,"}\n\n"
  1034. END IF
  1035. IF Use_Round THEN
  1036. FPRINT Outfile,"double Round (double n, int d)"
  1037. FPRINT Outfile,"{"
  1038. FPRINT Outfile," return (floor((n)*pow(10.0,(d))+0.5)/pow(10.0,(d)));"
  1039. FPRINT Outfile,"}\n\n"
  1040. END IF
  1041. IF Use_Embed THEN
  1042. FPRINT Outfile,"char* GetResource (int *resource)"
  1043. FPRINT Outfile,"{"
  1044. FPRINT Outfile," char *BCX_RetStr={0};"
  1045. FPRINT Outfile," static char* dat;"
  1046. FPRINT Outfile," memset(&dat,0,sizeof(char *));"
  1047. FPRINT Outfile," dat=(char*)resource;"
  1048. FPRINT Outfile," BCX_RetStr=BCX_TmpStr(strlen(dat));"
  1049. FPRINT Outfile," strcpy(BCX_RetStr,dat);"
  1050. FPRINT Outfile," return BCX_RetStr;"
  1051. FPRINT Outfile,"}\n\n"
  1052. END IF
  1053. IF Use_Exist THEN
  1054. FPRINT Outfile,"bool Exist (char *szFilePath)"
  1055. FPRINT Outfile,"{"
  1056. FPRINT Outfile," int retstat;"
  1057. FPRINT Outfile," struct stat sb;"
  1058. FPRINT Outfile," retstat = stat(szFilePath, &sb);"
  1059. FPRINT Outfile," if(retstat != -1)"
  1060. FPRINT Outfile," return TRUE;"
  1061. FPRINT Outfile," return FALSE;"
  1062. FPRINT Outfile,"}\n\n"
  1063. END IF
  1064. IF Use_Tally THEN
  1065. FPRINT Outfile,"int tally (char *szLine, char *szChar, int sensflag)"
  1066. FPRINT Outfile,"{"
  1067. FPRINT Outfile," if(!*szChar) return 0;"
  1068. FPRINT Outfile," int mlen = strlen(szChar);"
  1069. FPRINT Outfile," int iCount = 0;"
  1070. FPRINT Outfile," char *p = (sensflag == 0 ? _strstr_(szLine, szChar) : _stristr_(szLine, szChar));"
  1071. FPRINT Outfile," while (p)"
  1072. FPRINT Outfile," {"
  1073. FPRINT Outfile," iCount++;"
  1074. FPRINT Outfile," p+=mlen;"
  1075. FPRINT Outfile," p = (sensflag == 0 ? _strstr_(p, szChar) : _stristr_(p, szChar));"
  1076. FPRINT Outfile," }"
  1077. FPRINT Outfile," return iCount;"
  1078. FPRINT Outfile,"}\n\n"
  1079. END IF
  1080. IF Use_Timer THEN
  1081. FPRINT Outfile,"float timer (void)"
  1082. FPRINT Outfile,"{"
  1083. FPRINT Outfile," return ((double)clock()/CLOCKS_PER_SEC);"
  1084. FPRINT Outfile,"}\n\n"
  1085. END IF
  1086. IF Use_Rnd THEN
  1087. FPRINT Outfile,"float rnd (void)"
  1088. FPRINT Outfile,"{"
  1089. FPRINT Outfile," return (float)rand()/RAND_MAX;"
  1090. FPRINT Outfile,"}\n\n"
  1091. END IF
  1092. IF Use_Exp THEN
  1093. FPRINT Outfile,"double Exp (double arg)"
  1094. FPRINT Outfile,"{"
  1095. FPRINT Outfile," return pow(2.718281828459045,arg);"
  1096. FPRINT Outfile,"}\n\n"
  1097. END IF
  1098. IF Use_Randomize THEN
  1099. FPRINT Outfile,"void randomize (unsigned int seed)"
  1100. FPRINT Outfile,"{"
  1101. FPRINT Outfile," srand(seed);"
  1102. FPRINT Outfile,"}\n\n"
  1103. END IF
  1104. IF Use_Max THEN
  1105. FPRINT Outfile,"double _MAX_ (double a, double b)"
  1106. FPRINT Outfile,"{"
  1107. FPRINT Outfile," if(a>b)"
  1108. FPRINT Outfile," return a;"
  1109. FPRINT Outfile," return b;"
  1110. FPRINT Outfile,"}\n\n"
  1111. END IF
  1112. IF Use_Min THEN
  1113. FPRINT Outfile,"double _MIN_ (double a, double b)"
  1114. FPRINT Outfile,"{"
  1115. FPRINT Outfile," if(a<b)"
  1116. FPRINT Outfile," return a;"
  1117. FPRINT Outfile," return b;"
  1118. FPRINT Outfile,"}\n\n"
  1119. END IF
  1120. IF Use_Locate THEN
  1121. FPRINT Outfile,"void locate (int row,int col,int show,int shape)"
  1122. FPRINT Outfile,"{"
  1123. FPRINT Outfile," printf(",ENC$("%c%s%u%s%u%s"),",27,",ENC$("["),",row,",ENC$(";"),",col,",ENC$("H"),");"
  1124. FPRINT Outfile," // find cursor size/shape function!"
  1125. FPRINT Outfile,"}\n\n"
  1126. END IF
  1127. IF Use_Cls THEN
  1128. FPRINT Outfile,"void cls (void)"
  1129. FPRINT Outfile,"{"
  1130. FPRINT Outfile," printf(",ENC$("%s%s%s%s"),",ESC,",ENC$("[2J"),",ESC,",ENC$("[H"),");"
  1131. FPRINT Outfile,"}\n\n"
  1132. END IF
  1133. IF Use_Color THEN
  1134. FPRINT Outfile,"void color (int fg,int bg)"
  1135. FPRINT Outfile,"{"
  1136. FPRINT Outfile," printf(",ENC$("%c%s%u%s%u%s"),",27,",ENC$("["),",30+(fg&7),",ENC$(";"),",40+(bg&7),",ENC$("m"),");"
  1137. FPRINT Outfile,"}\n\n"
  1138. END IF
  1139. IF Use_Midstr THEN
  1140. FPRINT Outfile,"void midstr (char *src, int st, int length, char *rep)"
  1141. FPRINT Outfile,"{"
  1142. FPRINT Outfile," int srclen = strlen(src);"
  1143. FPRINT Outfile," if(st>srclen++ || st<1) return;"
  1144. FPRINT Outfile," int replen = strlen(rep);"
  1145. FPRINT Outfile," if(replen < length || length==-1) length=replen;"
  1146. FPRINT Outfile," if((st+length) > srclen) length=srclen-st;"
  1147. FPRINT Outfile," memcpy(&src[st-1],rep,length);"
  1148. FPRINT Outfile,"}\n\n"
  1149. END IF
  1150. IF Use_Swap THEN
  1151. FPRINT Outfile,"void swap ( UCHAR* A, UCHAR* B, int length)"
  1152. FPRINT Outfile,"{"
  1153. FPRINT Outfile," UCHAR t;"
  1154. FPRINT Outfile," while(length--)"
  1155. FPRINT Outfile," {"
  1156. FPRINT Outfile," t = *A;"
  1157. FPRINT Outfile," *(A++) = *B;"
  1158. FPRINT Outfile," *(B++) = t;"
  1159. FPRINT Outfile," }"
  1160. FPRINT Outfile,"}\n\n"
  1161. END IF
  1162. IF Use_Like THEN
  1163. FPRINT Outfile,"int like (char *raw, char *pat)"
  1164. FPRINT Outfile,"{"
  1165. FPRINT Outfile," char a, b, d;"
  1166. FPRINT Outfile," char *r, *p;"
  1167. FPRINT Outfile," int star = 0;"
  1168. FPRINT Outfile," for(;;) {"
  1169. FPRINT Outfile," if ((d = *pat++)==0) return (star || !*raw);"
  1170. FPRINT Outfile," else if (d == '*') star = 1;"
  1171. FPRINT Outfile," else if (d == '?') { if (!*raw++) return 0; }"
  1172. FPRINT Outfile," else break;"
  1173. FPRINT Outfile," }"
  1174. FPRINT Outfile," b = d;"
  1175. FPRINT Outfile," do if ((a = *raw++) == b) {"
  1176. FPRINT Outfile," r = raw;"
  1177. FPRINT Outfile," p = pat;"
  1178. FPRINT Outfile," do {"
  1179. FPRINT Outfile," if ((d = *p++) == '*')"
  1180. FPRINT Outfile," if (like(r, p - 1)) return 1;"
  1181. FPRINT Outfile," else break;"
  1182. FPRINT Outfile," else if (!d) {"
  1183. FPRINT Outfile," if (!*r) return 1;"
  1184. FPRINT Outfile," else break;"
  1185. FPRINT Outfile," }"
  1186. FPRINT Outfile," } while (*r++ == d || d == '?');"
  1187. FPRINT Outfile," } while (star && a);"
  1188. FPRINT Outfile," return 0;"
  1189. FPRINT Outfile,"}\n\n"
  1190. END IF
  1191. IF Use_Lof THEN
  1192. FPRINT Outfile,"DWORD lof (char *FileName)"
  1193. FPRINT Outfile,"{"
  1194. FPRINT Outfile,""
  1195. FPRINT Outfile," int retstat;"
  1196. FPRINT Outfile," struct stat sb;"
  1197. FPRINT Outfile," retstat = stat(FileName, &sb);"
  1198. FPRINT Outfile," if(retstat != -1)"
  1199. FPRINT Outfile," return sb.st_size;"
  1200. FPRINT Outfile," return 0;"
  1201. FPRINT Outfile,"}\n\n"
  1202. END IF
  1203. IF Use_Iif THEN
  1204. FPRINT Outfile,"double iif (bool cond, double tp, double fp)"
  1205. FPRINT Outfile,"{"
  1206. FPRINT Outfile," if(cond) return tp;"
  1207. FPRINT Outfile," return fp;"
  1208. FPRINT Outfile,"}\n\n"
  1209. END IF
  1210. IF Use_sziif THEN
  1211. FPRINT Outfile,"char * sziif (bool i, char *a, char *b)"
  1212. FPRINT Outfile,"{"
  1213. FPRINT Outfile," if(i) return a;"
  1214. FPRINT Outfile," return b;"
  1215. FPRINT Outfile,"}\n\n"
  1216. END IF
  1217. IF Use_DynamicA THEN
  1218. FPRINT Outfile,"void *CreateArr(void *a, int elem_size, int update, int num_dims, ... )"
  1219. FPRINT Outfile,"{"
  1220. FPRINT Outfile," va_list ap;"
  1221. FPRINT Outfile," void *RetPtr;"
  1222. FPRINT Outfile,""
  1223. FPRINT Outfile," va_start(ap, num_dims);"
  1224. FPRINT Outfile," RetPtr = CreateArr_internal(a, elem_size, update, num_dims, ap);"
  1225. FPRINT Outfile," va_end(ap);"
  1226. FPRINT Outfile," return (RetPtr);"
  1227. FPRINT Outfile,"}\n\n"
  1228. FPRINT Outfile,"void *CreateArr_internal(void *a, int elem_size, int update, int num_dims, va_list ap)"
  1229. FPRINT Outfile,"{"
  1230. FPRINT Outfile," size_t s, s1, s2;"
  1231. FPRINT Outfile," void **vp;"
  1232. FPRINT Outfile," va_list marker;"
  1233. FPRINT Outfile," "
  1234. FPRINT Outfile,"#ifdef va_copy"
  1235. FPRINT Outfile," va_copy(marker, ap);"
  1236. FPRINT Outfile,"#else"
  1237. FPRINT Outfile," marker = ap;"
  1238. FPRINT Outfile,"#endif"
  1239. FPRINT Outfile," s = va_arg(marker, size_t);"
  1240. FPRINT Outfile," s2 = s + 2;"
  1241. FPRINT Outfile," if(num_dims == 1)"
  1242. FPRINT Outfile," {"
  1243. FPRINT Outfile," if(update && a)"
  1244. FPRINT Outfile," a=realloc(a,s2*elem_size);"
  1245. FPRINT Outfile," else"
  1246. FPRINT Outfile," a=calloc(s2,elem_size);"
  1247. FPRINT Outfile," return a;"
  1248. FPRINT Outfile," }"
  1249. FPRINT Outfile," else"
  1250. FPRINT Outfile," if(update && a)"
  1251. FPRINT Outfile," {"
  1252. FPRINT Outfile," s1 = 0;"
  1253. FPRINT Outfile," vp = (void**)a;"
  1254. FPRINT Outfile," while(*vp && s1 <= s)"
  1255. FPRINT Outfile," {"
  1256. FPRINT Outfile," vp++;"
  1257. FPRINT Outfile," s1++;"
  1258. FPRINT Outfile," }"
  1259. FPRINT Outfile," if(s1 > s)"
  1260. FPRINT Outfile," {"
  1261. FPRINT Outfile," vp--;"
  1262. FPRINT Outfile," DestroyArr(vp, num_dims, 0);"
  1263. FPRINT Outfile," }"
  1264. FPRINT Outfile," a=realloc(a,s2*sizeof(int));"
  1265. FPRINT Outfile," s1 = 0;"
  1266. FPRINT Outfile," vp = (void**)a;"
  1267. FPRINT Outfile," while(*vp && s1 <= s)"
  1268. FPRINT Outfile," {"
  1269. FPRINT Outfile," vp++;"
  1270. FPRINT Outfile," s1++;"
  1271. FPRINT Outfile," }"
  1272. FPRINT Outfile," while(s1 < s2)"
  1273. FPRINT Outfile," {"
  1274. FPRINT Outfile," *(((int *)vp)) = 0;"
  1275. FPRINT Outfile," vp++;"
  1276. FPRINT Outfile," s1++;"
  1277. FPRINT Outfile," }"
  1278. FPRINT Outfile," }"
  1279. FPRINT Outfile," else"
  1280. FPRINT Outfile," a=calloc(s2*sizeof(int),1);"
  1281. FPRINT Outfile," vp = (void**)a;"
  1282. FPRINT Outfile," if(--num_dims > 0)"
  1283. FPRINT Outfile," {"
  1284. FPRINT Outfile," for(s1 = 0; s1 < s; s1++)"
  1285. FPRINT Outfile," {"
  1286. FPRINT Outfile," vp[s1] = CreateArr_internal(vp[s1], elem_size, update, num_dims, marker);"
  1287. FPRINT Outfile," }"
  1288. FPRINT Outfile," }"
  1289. FPRINT Outfile," return a;"
  1290. FPRINT Outfile,"}\n\n"
  1291. FPRINT Outfile,"void DestroyArr (void** a,int num_dims, int top_free)"
  1292. FPRINT Outfile,"{"
  1293. FPRINT Outfile," int i = 0;"
  1294. FPRINT Outfile," static int s = 0;"
  1295. FPRINT Outfile," if(num_dims == 1)"
  1296. FPRINT Outfile," {"
  1297. FPRINT Outfile," free(a);"
  1298. FPRINT Outfile," return;"
  1299. FPRINT Outfile," }"
  1300. FPRINT Outfile," s++;"
  1301. FPRINT Outfile," num_dims--; "
  1302. FPRINT Outfile," while(a[i])"
  1303. FPRINT Outfile," {"
  1304. FPRINT Outfile," DestroyArr((void**)a[i], num_dims, top_free);"
  1305. FPRINT Outfile," if(num_dims > 1)"
  1306. FPRINT Outfile," free(a[i]);"
  1307. FPRINT Outfile," a[i++]=NULL;"
  1308. FPRINT Outfile," }"
  1309. FPRINT Outfile," s--;"
  1310. FPRINT Outfile," if(s == 0 && top_free)"
  1311. FPRINT Outfile," free(a);"
  1312. FPRINT Outfile,"}\n\n"
  1313. END IF
  1314. IF Use_Idxqsort THEN
  1315. FPRINT Outfile,"int IdxCompare (const void *one, const void *two)"
  1316. FPRINT Outfile,"{"
  1317. FPRINT Outfile," int *ptr1 = (int *)(one);"
  1318. FPRINT Outfile," int *ptr2 = (int *)(two);"
  1319. FPRINT Outfile," return strcasecmp (pppStr[Key][*ptr1],pppStr[Key][*ptr2]);"
  1320. FPRINT Outfile,"}\n\n"
  1321. END IF
  1322. IF Use_IdxqsortSt THEN
  1323. FPRINT Outfile,"int IdxCompareSt (const void* one, const void* two)"
  1324. FPRINT Outfile,"{"
  1325. FPRINT Outfile,"#define compare1 cmp1+(StructSize * (*(UINT *)(one)))"
  1326. FPRINT Outfile,"#define compare2 cmp1+(StructSize * (*(UINT *)(two)))"
  1327. FPRINT Outfile,""
  1328. FPRINT Outfile," if (Key==0)" 'String
  1329. FPRINT Outfile," return strcasecmp(compare1, compare2);"
  1330. FPRINT Outfile,""
  1331. FPRINT Outfile," if (Key==1)" 'Integer
  1332. FPRINT Outfile," {"
  1333. FPRINT Outfile," if (*(int*)(compare1) < *(int*)(compare2)) return -1;"
  1334. FPRINT Outfile," if (*(int*)(compare1) > *(int*)(compare2)) return 1;"
  1335. FPRINT Outfile," return 0;"
  1336. FPRINT Outfile," }"
  1337. FPRINT Outfile,""
  1338. FPRINT Outfile," if (Key==2)" 'Double
  1339. FPRINT Outfile," {"
  1340. FPRINT Outfile," if (*(double*)(compare1) < *(double*)(compare2)) return -1;"
  1341. FPRINT Outfile," if (*(double*)(compare1) > *(double*)(compare2)) return 1;"
  1342. FPRINT Outfile," return 0;"
  1343. FPRINT Outfile," }"
  1344. FPRINT Outfile,""
  1345. FPRINT Outfile," if (Key==3)" 'Unsigned integer
  1346. FPRINT Outfile," {"
  1347. FPRINT Outfile," if (*(UINT*)(compare1) < *(UINT*)(compare2)) return -1;"
  1348. FPRINT Outfile," if (*(UINT*)(compare1) > *(UINT*)(compare2)) return 1;"
  1349. FPRINT Outfile," }"
  1350. FPRINT Outfile,"return 0;"
  1351. FPRINT Outfile,"}\n\n"
  1352. END IF
  1353. IF Use_PtrqsortSt THEN
  1354. FPRINT Outfile,"int PtrCompareSt (const void* one, const void* two)"
  1355. FPRINT Outfile,"{"
  1356. FPRINT Outfile,"#define pcompare1 ((char*)(one)+OffSet)"
  1357. FPRINT Outfile,"#define pcompare2 ((char*)(two)+OffSet)"
  1358. FPRINT Outfile,""
  1359. FPRINT Outfile," if (Key==0)"
  1360. FPRINT Outfile," return strcasecmp(pcompare1, pcompare2);"
  1361. FPRINT Outfile,""
  1362. FPRINT Outfile," if (Key==1)"
  1363. FPRINT Outfile," {"
  1364. FPRINT Outfile," if (*(int*)(pcompare1) < *(int*)(pcompare2)) return -1;"
  1365. FPRINT Outfile," if (*(int*)(pcompare1) > *(int*)(pcompare2)) return 1;"
  1366. FPRINT Outfile," return 0;"
  1367. FPRINT Outfile," }"
  1368. FPRINT Outfile,""
  1369. FPRINT Outfile," if (Key==2)"
  1370. FPRINT Outfile," {"
  1371. FPRINT Outfile," if (*(double*)(pcompare1) < *(double*)(pcompare2)) return -1;"
  1372. FPRINT Outfile," if (*(double*)(pcompare1) > *(double*)(pcompare2)) return 1;"
  1373. FPRINT Outfile," return 0;"
  1374. FPRINT Outfile," }"
  1375. FPRINT Outfile,""
  1376. FPRINT Outfile," if (Key==3)"
  1377. FPRINT Outfile," {"
  1378. FPRINT Outfile," if (*(UINT*)(pcompare1) < *(UINT*)(pcompare2)) return -1;"
  1379. FPRINT Outfile," if (*(UINT*)(pcompare1) > *(UINT*)(pcompare2)) return 1;"
  1380. FPRINT Outfile," }"
  1381. FPRINT Outfile,"return 0;"
  1382. FPRINT Outfile,"}\n\n"
  1383. END IF
  1384. IF Use_Strqsorta THEN
  1385. FPRINT Outfile,"int StrCompareA (const void *arg1, const void *arg2)"
  1386. FPRINT Outfile,"{"
  1387. FPRINT Outfile," char *v1 = (char*) arg1;"
  1388. FPRINT Outfile," char *v2 = (char*) arg2;"
  1389. FPRINT Outfile," return strcasecmp (v1,v2);"
  1390. FPRINT Outfile,"}\n\n"
  1391. END IF
  1392. IF Use_Strqsortd THEN
  1393. FPRINT Outfile,"int StrCompareD (const void *arg1, const void *arg2)"
  1394. FPRINT Outfile,"{"
  1395. FPRINT Outfile," char *v1 = (char*) arg1;"
  1396. FPRINT Outfile," char *v2 = (char*) arg2;"
  1397. FPRINT Outfile," return strcasecmp (v2,v1);"
  1398. FPRINT Outfile,"}\n\n"
  1399. END IF
  1400. IF Use_DynStrqsorta THEN
  1401. FPRINT Outfile,"int DynStrCompareA (const void *arg1, const void *arg2)"
  1402. FPRINT Outfile,"{"
  1403. FPRINT Outfile," char *v1 = *(char **) arg1;"
  1404. FPRINT Outfile," char *v2 = *(char **) arg2;"
  1405. FPRINT Outfile," return strcasecmp(v1, v2);"
  1406. FPRINT Outfile,"}\n\n"
  1407. END IF
  1408. IF Use_DynStrqsortd THEN
  1409. FPRINT Outfile,"int DynStrCompareD (const void *arg1, const void *arg2)"
  1410. FPRINT Outfile,"{"
  1411. FPRINT Outfile," char *v1 = *(char **) arg1;"
  1412. FPRINT Outfile," char *v2 = *(char **) arg2;"
  1413. FPRINT Outfile," return strcasecmp(v2, v1);"
  1414. FPRINT Outfile,"}\n\n"
  1415. END IF
  1416. IF Use_Numqsortaint THEN
  1417. FPRINT Outfile,"int NumCompareAint (const void *one, const void *two)"
  1418. FPRINT Outfile,"{"
  1419. FPRINT Outfile," int *ptr1 = (int *)(one);"
  1420. FPRINT Outfile," int *ptr2 = (int *)(two);"
  1421. FPRINT Outfile," if (*ptr1 < *ptr2) return -1;"
  1422. FPRINT Outfile," else if (*ptr1 == *ptr2) return 0;"
  1423. FPRINT Outfile," else return 1;"
  1424. FPRINT Outfile,"}\n\n"
  1425. END IF
  1426. IF Use_Numqsortdint THEN
  1427. FPRINT Outfile,"int NumCompareDint (const void *one, const void *two)"
  1428. FPRINT Outfile,"{"
  1429. FPRINT Outfile," int *ptr1 = (int *)(one);"
  1430. FPRINT Outfile," int *ptr2 = (int *)(two);"
  1431. FPRINT Outfile," if (*ptr1 > *ptr2) return -1;"
  1432. FPRINT Outfile," else if (*ptr1 == *ptr2) return 0;"
  1433. FPRINT Outfile," else return 1;"
  1434. FPRINT Outfile,"}\n\n"
  1435. END IF
  1436. IF Use_Numqsortafloat THEN
  1437. FPRINT Outfile,"int NumCompareAfloat (const void *one, const void *two)"
  1438. FPRINT Outfile,"{"
  1439. FPRINT Outfile," float *ptr1 = (float *)(one);"
  1440. FPRINT Outfile," float *ptr2 = (float *)(two);"
  1441. FPRINT Outfile," if (*ptr1 < *ptr2) return -1;"
  1442. FPRINT Outfile," else if (*ptr1 == *ptr2) return 0;"
  1443. FPRINT Outfile," else return 1;"
  1444. FPRINT Outfile,"}\n\n"
  1445. END IF
  1446. IF Use_Numqsortdfloat THEN
  1447. FPRINT Outfile,"int NumCompareDfloat (const void *one, const void *two)"
  1448. FPRINT Outfile,"{"
  1449. FPRINT Outfile," float *ptr1 = (float *)(one);"
  1450. FPRINT Outfile," float *ptr2 = (float *)(two);"
  1451. FPRINT Outfile," if (*ptr1 > *ptr2) return -1;"
  1452. FPRINT Outfile," else if (*ptr1 == *ptr2) return 0;"
  1453. FPRINT Outfile," else return 1;"
  1454. FPRINT Outfile,"}\n\n"
  1455. END IF
  1456. IF Use_Numqsortadouble THEN
  1457. FPRINT Outfile,"int NumCompareAdouble (const void *one, const void *two)"
  1458. FPRINT Outfile,"{"
  1459. FPRINT Outfile," double *ptr1 = (double *)(one);"
  1460. FPRINT Outfile," double *ptr2 = (double *)(two);"
  1461. FPRINT Outfile," if (*ptr1 < *ptr2) return -1;"
  1462. FPRINT Outfile," else if (*ptr1 == *ptr2) return 0;"
  1463. FPRINT Outfile," else return 1;"
  1464. FPRINT Outfile,"}\n\n"
  1465. END IF
  1466. IF Use_Numqsortddouble THEN
  1467. FPRINT Outfile,"int NumCompareDdouble (const void *one, const void *two)"
  1468. FPRINT Outfile,"{"
  1469. FPRINT Outfile," double *ptr1 = (double *)(one);"
  1470. FPRINT Outfile," double *ptr2 = (double *)(two);"
  1471. FPRINT Outfile," if (*ptr1 > *ptr2) return -1;"
  1472. FPRINT Outfile," else if (*ptr1 == *ptr2) return 0;"
  1473. FPRINT Outfile," else return 1;"
  1474. FPRINT Outfile,"}\n\n"
  1475. END IF
  1476. IF Use_FillArray THEN
  1477. FPRINT Outfile,"int fillarray(char *input, int ArrayType, int MaxCnt, void *Array)"
  1478. FPRINT Outfile,"{"
  1479. FPRINT Outfile," if(MaxCnt < 1) return -1;"
  1480. FPRINT Outfile," int c = 0, cnt=-1, cnt2;"
  1481. FPRINT Outfile," char A[65535];"
  1482. FPRINT Outfile," int *intptr = (int *)Array;"
  1483. FPRINT Outfile," float *floatptr = (float *)Array;"
  1484. FPRINT Outfile," double *doubleptr = (double *)Array;"
  1485. FPRINT Outfile," long double *ldoubleptr = (long double *)Array;"
  1486. FPRINT Outfile," for(;;)"
  1487. FPRINT Outfile," {"
  1488. FPRINT Outfile," cnt2=0;"
  1489. FPRINT Outfile," while(input[++cnt]!=',')"
  1490. FPRINT Outfile," {"
  1491. FPRINT Outfile," if(input[cnt]==0) break;"
  1492. FPRINT Outfile," A[cnt2++]=input[cnt];"
  1493. FPRINT Outfile," }"
  1494. FPRINT Outfile," A[cnt2]=0;"
  1495. FPRINT Outfile," if(cnt2==0||c==MaxCnt) break;"
  1496. FPRINT Outfile," "
  1497. FPRINT Outfile," if(ArrayType==2)"
  1498. FPRINT Outfile," intptr[c++] = atoi(A);"
  1499. FPRINT Outfile," else if(ArrayType==3)"
  1500. FPRINT Outfile," floatptr[c++] = atof(A);"
  1501. FPRINT Outfile," else if(ArrayType==4)"
  1502. FPRINT Outfile," doubleptr[c++] = atof(A);"
  1503. FPRINT Outfile," else if(ArrayType==5)"
  1504. FPRINT Outfile," ldoubleptr[c++] = atof(A);"
  1505. FPRINT Outfile,""
  1506. FPRINT Outfile," if(input[cnt]==0) break;"
  1507. FPRINT Outfile," } "
  1508. FPRINT Outfile," return (c-1);"
  1509. FPRINT Outfile,"}\n\n"
  1510. END IF
  1511. IF Use_Loc THEN
  1512. FPRINT Outfile,"int loc(FILE *fp, int fplen)"
  1513. FPRINT Outfile,"{"
  1514. FPRINT Outfile," fpos_t t;"
  1515. FPRINT Outfile," fgetpos(fp, &t);"
  1516. FPRINT Outfile,"#if defined( __POCC__ )"
  1517. FPRINT Outfile," t.off %= fplen;"
  1518. FPRINT Outfile," return (int)t.off;"
  1519. FPRINT Outfile,"#else"
  1520. FPRINT Outfile," t %= fplen;"
  1521. FPRINT Outfile," return (int)t;"
  1522. FPRINT Outfile,"#endif"
  1523. FPRINT Outfile,"}\n\n"
  1524. END IF
  1525. IF Use_Rec THEN
  1526. FPRINT Outfile,"int rec(FILE *fp, int fplen)"
  1527. FPRINT Outfile,"{"
  1528. FPRINT Outfile," fpos_t t;"
  1529. FPRINT Outfile," fgetpos(fp, &t);"
  1530. FPRINT Outfile,"#if defined( __POCC__ )"
  1531. FPRINT Outfile," t.off /= fplen;"
  1532. FPRINT Outfile," return (int)++t.off;"
  1533. FPRINT Outfile,"#else"
  1534. FPRINT Outfile," t /= fplen;"
  1535. FPRINT Outfile," return (int)++t;"
  1536. FPRINT Outfile,"#endif"
  1537. FPRINT Outfile,"}\n\n"
  1538. END IF
  1539. IF Use_RecCount THEN
  1540. FPRINT Outfile,"int reccount(FILE *fp, int fplen)"
  1541. FPRINT Outfile,"{"
  1542. FPRINT Outfile," fpos_t t;"
  1543. FPRINT Outfile," fseek(fp,0,SEEK_END);"
  1544. FPRINT Outfile," fgetpos(fp, &t);"
  1545. FPRINT Outfile,"#if defined( __POCC__ )"
  1546. FPRINT Outfile," t.off /= fplen;"
  1547. FPRINT Outfile," return (int)t.off;"
  1548. FPRINT Outfile,"#else"
  1549. FPRINT Outfile," t /= fplen;"
  1550. FPRINT Outfile," return (int)t;"
  1551. FPRINT Outfile,"#endif"
  1552. FPRINT Outfile,"}\n\n"
  1553. END IF
  1554. IF Use_Scan THEN
  1555. FPRINT Outfile,"int scan(char *input, char *format, ... )"
  1556. FPRINT Outfile,"{"
  1557. FPRINT Outfile," int c,d ;"
  1558. FPRINT Outfile," char *s_;"
  1559. FPRINT Outfile," int *intptr;"
  1560. FPRINT Outfile," float *floatptr;"
  1561. FPRINT Outfile," double *doubleptr;"
  1562. FPRINT Outfile," char A[50][65535];"
  1563. FPRINT Outfile," va_list marker;"
  1564. FPRINT Outfile," c = 0;"
  1565. FPRINT Outfile," d = Split(A,input,"; ENC$(",") ; ");"
  1566. FPRINT Outfile," va_start(marker, format); //Initialize arguments"
  1567. FPRINT Outfile," while(d && *format)"
  1568. FPRINT Outfile," {"
  1569. FPRINT Outfile," if(*format == '%') format++;"
  1570. FPRINT Outfile," if(*format == 's')"
  1571. FPRINT Outfile," {"
  1572. FPRINT Outfile," s_ = va_arg(marker, char *);"
  1573. FPRINT Outfile," strcpy(s_, A[c]);"
  1574. FPRINT Outfile," c++;"
  1575. FPRINT Outfile," d--;"
  1576. FPRINT Outfile," }"
  1577. FPRINT Outfile," if(*format == 'd')"
  1578. FPRINT Outfile," {"
  1579. FPRINT Outfile," intptr = va_arg(marker, int *);"
  1580. FPRINT Outfile," *intptr = atoi(A[c]);"
  1581. FPRINT Outfile," c++;"
  1582. FPRINT Outfile," d--;"
  1583. FPRINT Outfile," }"
  1584. FPRINT Outfile," if(*format == 'g')"
  1585. FPRINT Outfile," {"
  1586. FPRINT Outfile," floatptr = va_arg(marker, float *);"
  1587. FPRINT Outfile," *floatptr = atof(A[c]);"
  1588. FPRINT Outfile," c++;"
  1589. FPRINT Outfile," d--;"
  1590. FPRINT Outfile," }"
  1591. FPRINT Outfile," if(*format == 'l')"
  1592. FPRINT Outfile," {"
  1593. FPRINT Outfile," format++;"
  1594. FPRINT Outfile," doubleptr = va_arg(marker, double *);"
  1595. FPRINT Outfile," *doubleptr = atof(A[c]);"
  1596. FPRINT Outfile," c++;"
  1597. FPRINT Outfile," d--;"
  1598. FPRINT Outfile," }"
  1599. FPRINT Outfile," format++;"
  1600. FPRINT Outfile," }"
  1601. FPRINT Outfile," va_end(marker); // Reset variable arguments"
  1602. FPRINT Outfile," if(d) return(1); // More data than variables"
  1603. FPRINT Outfile," if(*format == 0) return(0); // OK"
  1604. FPRINT Outfile," return(-1); // More variables than data"
  1605. FPRINT Outfile,"}\n\n"
  1606. END IF
  1607. IF Use_Split THEN
  1608. FPRINT Outfile,"int Split (char Buf[][65535], char *T, char *Delim, int Flg)"
  1609. FPRINT Outfile,"{"
  1610. FPRINT Outfile," int Begin = 0;"
  1611. FPRINT Outfile," int Count = 0;"
  1612. FPRINT Outfile," int Quote = 0;"
  1613. FPRINT Outfile," int Index,i;"
  1614. FPRINT Outfile," int lenT = strlen(T);"
  1615. FPRINT Outfile," char Chr34[2]={34,0};"
  1616. FPRINT Outfile," for(Index=1;Index<=lenT;Index++)"
  1617. FPRINT Outfile," {"
  1618. FPRINT Outfile," if(instr_b(Delim,mid(T,Index,1))&&!Quote)"
  1619. FPRINT Outfile," {"
  1620. FPRINT Outfile," strcpy(Buf[Count],(char*)mid(T,Begin,Index-Begin));"
  1621. FPRINT Outfile," if ((Flg & 2) == 0) // 0 if old version"
  1622. FPRINT Outfile," Count++;"
  1623. FPRINT Outfile," else"
  1624. FPRINT Outfile," if (Buf[Count][0] != 0) Count++;"
  1625. FPRINT Outfile," Begin=0;"
  1626. FPRINT Outfile," if((Flg & 1) == 1) // 1 if true"
  1627. FPRINT Outfile," strcpy(Buf[Count++],(char*)mid(T,Index,1));"
  1628. FPRINT Outfile," }"
  1629. FPRINT Outfile," else"
  1630. FPRINT Outfile," {"
  1631. FPRINT Outfile," if(strcmp(mid(T,Index,1),Chr34)==0) Quote=!Quote;"
  1632. FPRINT Outfile," if(Begin==0) Begin=Index;"
  1633. FPRINT Outfile," }"
  1634. FPRINT Outfile," }"
  1635. FPRINT Outfile," if(Begin)"
  1636. FPRINT Outfile," strcpy(Buf[Count++],(char*)mid(T,Begin,Index-Begin));"
  1637. FPRINT Outfile," if((Flg & 1) == 0) // 0 if false"
  1638. FPRINT Outfile," for(i=0;i<Count;i++) strcpy(Buf[i],(char*)RemoveStr(Buf[i],Chr34));"
  1639. FPRINT Outfile," return Count;"
  1640. FPRINT Outfile,"}\n\n"
  1641. END IF
  1642. IF Use_DSplit THEN
  1643. FPRINT Outfile,"int DSplit (PCHAR *Buf, char *T, char *Delim, int Flg)"
  1644. FPRINT Outfile,"{"
  1645. FPRINT Outfile," int Begin=0;"
  1646. FPRINT Outfile," int Count=0;"
  1647. FPRINT Outfile," int Quote=0;"
  1648. FPRINT Outfile," int Index=0;"
  1649. FPRINT Outfile," int lenT = strlen(T);"
  1650. FPRINT Outfile," char Chr34[2]={34,0};"
  1651. FPRINT Outfile," for(Index=1;Index<=lenT;Index++)"
  1652. FPRINT Outfile," {"
  1653. FPRINT Outfile," if(instr_b(Delim,mid(T,Index,1))&&!Quote)"
  1654. FPRINT Outfile," {"
  1655. FPRINT Outfile," strcpy(Buf[Count],(char*)mid(T,Begin,Index-Begin));"
  1656. FPRINT Outfile," if ((Flg & 2) == 0) // 0 if old version"
  1657. FPRINT Outfile," Count++;"
  1658. FPRINT Outfile," else"
  1659. FPRINT Outfile," if (Buf[Count][0] != 0) Count++;"
  1660. FPRINT Outfile," Begin=0;"
  1661. FPRINT Outfile," if((Flg & 1) == 1) // 1 if true"
  1662. FPRINT Outfile," strcpy(Buf[Count++],(char*)mid(T,Index,1));"
  1663. FPRINT Outfile," }"
  1664. FPRINT Outfile," else"
  1665. FPRINT Outfile," {"
  1666. FPRINT Outfile," if(strcmp(mid(T,Index,1),Chr34)==0) Quote=!Quote;"
  1667. FPRINT Outfile," if(Begin==0) Begin=Index;"
  1668. FPRINT Outfile," }"
  1669. FPRINT Outfile," }"
  1670. FPRINT Outfile," if(Begin) strcpy(Buf[Count++],(char*)mid(T,Begin,Index-Begin));"
  1671. FPRINT Outfile," if((Flg & 1) == 0) // 0 if false"
  1672. FPRINT Outfile," for(Index=0;Index<Count;Index++) strcpy(Buf[Index],(char*)RemoveStr(Buf[Index],Chr34));"
  1673. FPRINT Outfile," return Count;"
  1674. FPRINT Outfile,"}\n\n"
  1675. END IF
  1676. IF Use_Bin2dec THEN
  1677. FPRINT Outfile,"int Bin2Dec (char *cptr)"
  1678. FPRINT Outfile,"{"
  1679. FPRINT Outfile," int i, j = 0;"
  1680. FPRINT Outfile," while(cptr && *cptr && strchr(";ENC$("01");", *cptr))"
  1681. FPRINT Outfile," {"
  1682. FPRINT Outfile," i = *cptr++ - '0';"
  1683. FPRINT Outfile," j <<= 1;"
  1684. FPRINT Outfile," j |= (i & 0x01);"
  1685. FPRINT Outfile," }"
  1686. FPRINT Outfile," return(j);"
  1687. FPRINT Outfile,"}\n\n"
  1688. END IF
  1689. IF Use_Hex2Dec THEN
  1690. FPRINT Outfile,"int Hex2Dec (char *szInput)"
  1691. FPRINT Outfile,"{"
  1692. FPRINT Outfile," char ch;"
  1693. FPRINT Outfile," char *dwLen = szInput+strlen(szInput);"
  1694. FPRINT Outfile," char *LowCase = MakeLCaseTbl();"
  1695. FPRINT Outfile," DWORD dwOut = 0;"
  1696. FPRINT Outfile," while(*szInput)"
  1697. FPRINT Outfile," {"
  1698. FPRINT Outfile," ch = LowCase[(unsigned char)*szInput++];"
  1699. FPRINT Outfile," if((ch >= 'a' && ch <= 'f') || (ch >= '0' && ch <= '9'))"
  1700. FPRINT Outfile," dwOut |=((int)ch - (ch>'9' ? 'a'-10 : '0')) << ((dwLen - szInput) << 2);"
  1701. FPRINT Outfile," }"
  1702. FPRINT Outfile," return dwOut;"
  1703. FPRINT Outfile,"}\n\n"
  1704. END IF
  1705. IF Use_Verify THEN
  1706. FPRINT Outfile,"int Verify (char *Src, char *Allowed)"
  1707. FPRINT Outfile,"{"
  1708. FPRINT Outfile," int i, j;"
  1709. FPRINT Outfile," for (i=1; i<=strlen(Src); i++)"
  1710. FPRINT Outfile," {"
  1711. FPRINT Outfile," j=VerifyInstr(Allowed,mid(Src,i,1));"
  1712. FPRINT Outfile," if (!j) return 0;"
  1713. FPRINT Outfile," }"
  1714. FPRINT Outfile," return TRUE;"
  1715. FPRINT Outfile,"}\n\n"
  1716. FPRINT Outfile,"int VerifyInstr(char* mane,char* match,int offset)"
  1717. FPRINT Outfile,"{"
  1718. FPRINT Outfile," char *s;"
  1719. FPRINT Outfile," if (!mane || !match || !*match || offset>(int)strlen(mane)) return 0;"
  1720. FPRINT Outfile," s = strstr (offset>0 ? mane+offset-1 : mane,match);"
  1721. FPRINT Outfile," return s ? (int)(s-mane)+1 : 0;"
  1722. FPRINT Outfile,"}\n\n"
  1723. END IF
  1724. IF Use_Retain THEN
  1725. FPRINT Outfile,"char *Retain (char *Text, char *ValidChars)"
  1726. FPRINT Outfile,"{"
  1727. FPRINT Outfile," char *BCX_RetStr=BCX_TmpStr(strlen(Text));"
  1728. FPRINT Outfile," char *temp=BCX_RetStr;"
  1729. FPRINT Outfile," while(*Text)"
  1730. FPRINT Outfile," {"
  1731. FPRINT Outfile," if(strchr(ValidChars,*Text)) *(temp++) = *Text;"
  1732. FPRINT Outfile," Text++;"
  1733. FPRINT Outfile," }"
  1734. FPRINT Outfile," return BCX_RetStr;"
  1735. FPRINT Outfile,"}\n\n"
  1736. END IF
  1737. IF Use_LoadFile THEN
  1738. FPRINT Outfile,"char* LoadFile (char *N)"
  1739. FPRINT Outfile,"{"
  1740. FPRINT Outfile," FILE* FP1;"
  1741. FPRINT Outfile," char* BCX_RetStr;"
  1742. FPRINT Outfile," if(Exist(N))"
  1743. FPRINT Outfile," {"
  1744. FPRINT Outfile," BCX_RetStr=BCX_TmpStr(lof(N));"
  1745. FPRINT Outfile," if((FP1=fopen(N,", ENC$("rb"), "))!=0)"
  1746. FPRINT Outfile," GET(FP1,BCX_RetStr,lof(N));"
  1747. FPRINT Outfile," fclose(FP1);"
  1748. FPRINT Outfile," return BCX_RetStr;"
  1749. FPRINT Outfile," }"
  1750. FPRINT Outfile," else"
  1751. FPRINT Outfile," {"
  1752. FPRINT Outfile," BCX_RetStr=BCX_TmpStr(64);"
  1753. FPRINT Outfile," return strcpy(BCX_RetStr,", ENC$("File Not Found"), ");"
  1754. FPRINT Outfile," }"
  1755. FPRINT Outfile,"}\n\n"
  1756. END IF
  1757. IF Use_Freefile THEN
  1758. FPRINT Outfile,"FILE* FreeFile (void)"
  1759. FPRINT Outfile,"{"
  1760. FPRINT Outfile," static FILE *pf;"
  1761. FPRINT Outfile," if(pf){free(pf);pf=NULL;}"
  1762. FPRINT Outfile," pf = (FILE*)calloc(sizeof(FILE*),sizeof(FILE*));"
  1763. FPRINT Outfile," return pf;"
  1764. FPRINT Outfile,"}\n\n"
  1765. END IF
  1766. IF Use_Run THEN
  1767. FPRINT Outfile,"int Run (char* Cmdline, int ShowHide, int WaitState)"
  1768. FPRINT Outfile,"{"
  1769. FPRINT Outfile," int processId;"
  1770. FPRINT Outfile," char *s, *p, *cmd_line;"
  1771. FPRINT Outfile,""
  1772. FPRINT Outfile," cmd_line=(char*)malloc(strlen(Cmdline)+1);"
  1773. FPRINT Outfile," if(cmd_line==NULL) return -2;"
  1774. FPRINT Outfile,""
  1775. FPRINT Outfile," strcpy(cmd_line, Cmdline);"
  1776. FPRINT Outfile," p = s = cmd_line;"
  1777. FPRINT Outfile," processId=fork();"
  1778. FPRINT Outfile," if(processId==0)"
  1779. FPRINT Outfile," {"
  1780. FPRINT Outfile," PCHAR argv[30];"
  1781. FPRINT Outfile," int i=0;"
  1782. FPRINT Outfile," while(*p)"
  1783. FPRINT Outfile," {"
  1784. FPRINT Outfile," if(*p==34)"
  1785. FPRINT Outfile," {"
  1786. FPRINT Outfile," while(*(++p)!=34) {}"
  1787. FPRINT Outfile," }"
  1788. FPRINT Outfile," if(*p==32)"
  1789. FPRINT Outfile," {"
  1790. FPRINT Outfile," while(*(p+1)==32) p++;"
  1791. FPRINT Outfile," argv[i++]=s;"
  1792. FPRINT Outfile," *p=0; s=p+1;"
  1793. FPRINT Outfile," }"
  1794. FPRINT Outfile," p++;"
  1795. FPRINT Outfile," }"
  1796. FPRINT Outfile," argv[i] = s;"
  1797. FPRINT Outfile," argv[i+1]= 0;"
  1798. FPRINT Outfile," execvp(argv[0],argv);"
  1799. FPRINT Outfile," printf(",ENC$("Failed to run%s\\n"),",argv[0]);"
  1800. FPRINT Outfile," exit(-1);"
  1801. FPRINT Outfile," }"
  1802. FPRINT Outfile," else if(processId!=-1)"
  1803. FPRINT Outfile," {"
  1804. FPRINT Outfile," if(WaitState) waitpid(processId,NULL,0);"
  1805. FPRINT Outfile," }"
  1806. FPRINT Outfile," waitpid(-1,NULL,WNOHANG);"
  1807. FPRINT Outfile," free(cmd_line), cmd_line=NULL;"
  1808. FPRINT Outfile," return processId;"
  1809. FPRINT Outfile,"}\n\n"
  1810. END IF
  1811. IF Use_Download THEN
  1812. FPRINT Outfile,"int Download (char *URL,char *Localname)"
  1813. FPRINT Outfile,"{"
  1814. FPRINT Outfile," int RetVal;"
  1815. '~ FPRINT Outfile," RetVal=BCX_DynaCall (", ENC$("URLDownloadToFile"), "," ;
  1816. '~ FPRINT Outfile, ENC$("urlmon.dll"), ",5,NULL,URL,Localname,0,NULL);"
  1817. FPRINT Outfile," return RetVal=!RetVal;"
  1818. FPRINT Outfile,"}\n\n"
  1819. END IF
  1820. IF Use_PeekStr THEN
  1821. FPRINT Outfile,"char *peekstr (LPVOID Src, int Count)"
  1822. FPRINT Outfile,"{"
  1823. FPRINT Outfile," char *Des=BCX_TmpStr(Count);"
  1824. FPRINT Outfile," memmove(Des,Src,Count);"
  1825. FPRINT Outfile," return Des;"
  1826. FPRINT Outfile,"}\n\n"
  1827. END IF
  1828. IF Use_QBColor THEN
  1829. FPRINT Outfile,"int qbcolor (int N)"
  1830. FPRINT Outfile,"{"
  1831. FPRINT Outfile," switch (N)"
  1832. FPRINT Outfile," {"
  1833. FPRINT Outfile," case 0 : return RGB(0,0,0);"
  1834. FPRINT Outfile," case 1 : return RGB(0,0,128);"
  1835. FPRINT Outfile," case 2 : return RGB(0,128,0);"
  1836. FPRINT Outfile," case 3 : return RGB(0,128,128);"
  1837. FPRINT Outfile," case 4 : return RGB(196,0,0);"
  1838. FPRINT Outfile," case 5 : return RGB(128,0,128);"
  1839. FPRINT Outfile," case 6 : return RGB(128,64,0);"
  1840. FPRINT Outfile," case 7 : return RGB(196,196,196);"
  1841. FPRINT Outfile," case 8 : return RGB(128,128,128);"
  1842. FPRINT Outfile," case 9 : return RGB(0,0, 255);"
  1843. FPRINT Outfile," case 10 : return RGB(0,255,0);"
  1844. FPRINT Outfile," case 11 : return RGB(0,255,255);"
  1845. FPRINT Outfile," case 12 : return RGB(255,0,0);"
  1846. FPRINT Outfile," case 13 : return RGB(255,0,255);"
  1847. FPRINT Outfile," case 14 : return RGB(255,255,0);"
  1848. FPRINT Outfile," case 15 : return RGB(255,255,255);"
  1849. FPRINT Outfile," case 16 : return RGB(164,164,164);"
  1850. FPRINT Outfile," case 17 : return RGB(128,160,255);"
  1851. FPRINT Outfile," case 18 : return RGB(160,255,160);"
  1852. FPRINT Outfile," case 19 : return RGB(160,255,255);"
  1853. FPRINT Outfile," case 20 : return RGB(255,160,160);"
  1854. FPRINT Outfile," case 21 : return RGB(255,160,255);"
  1855. FPRINT Outfile," case 22 : return RGB(255,255,160);"
  1856. FPRINT Outfile," case 23 : return RGB(212,212,212);"
  1857. FPRINT Outfile," case 24 : return RGB(180,180,180);"
  1858. FPRINT Outfile," case 25 : return RGB(188,220,255);"
  1859. FPRINT Outfile," case 26 : return RGB(220,255,220);"
  1860. FPRINT Outfile," case 27 : return RGB(220,255,255);"
  1861. FPRINT Outfile," case 28 : return RGB(255,220,220);"
  1862. FPRINT Outfile," case 29 : return RGB(255,220,255);"
  1863. FPRINT Outfile," case 30 : return RGB(255,255,220);"
  1864. FPRINT Outfile," case 31 : return RGB(228,228,228);"
  1865. FPRINT Outfile," }"
  1866. FPRINT Outfile,"return 0;"
  1867. FPRINT Outfile,"}\n\n"
  1868. END IF
  1869. IF Use_Cvi THEN
  1870. FPRINT Outfile,"short CVI (char *s)"
  1871. FPRINT Outfile,"{"
  1872. FPRINT Outfile," return ((short*)s)[0];"
  1873. FPRINT Outfile,"}\n\n"
  1874. END IF
  1875. IF Use_Mki THEN
  1876. FPRINT Outfile,"char *MKI (short cvt)"
  1877. FPRINT Outfile,"{"
  1878. FPRINT Outfile," static char temp[3];"
  1879. FPRINT Outfile," return (char *)memmove(temp,&cvt,2);"
  1880. FPRINT Outfile,"}\n\n"
  1881. END IF
  1882. IF Use_Cvl THEN
  1883. FPRINT Outfile,"long CVL (char *s)"
  1884. FPRINT Outfile,"{"
  1885. FPRINT Outfile," return ((long*)s)[0];"
  1886. FPRINT Outfile,"}\n\n"
  1887. END IF
  1888. IF Use_Mkl THEN
  1889. FPRINT Outfile,"char *MKL (int cvt)"
  1890. FPRINT Outfile,"{"
  1891. FPRINT Outfile," static char temp[5];"
  1892. FPRINT Outfile," return (char *) memmove(temp,&cvt,4);"
  1893. FPRINT Outfile,"}\n\n"
  1894. END IF
  1895. IF Use_Cvs THEN
  1896. FPRINT Outfile,"float CVS (char *s)"
  1897. FPRINT Outfile,"{"
  1898. FPRINT Outfile," return ((float*)s)[0];"
  1899. FPRINT Outfile,"}\n\n"
  1900. END IF
  1901. IF Use_Mks THEN
  1902. FPRINT Outfile,"char *MKS (float cvt)"
  1903. FPRINT Outfile,"{"
  1904. FPRINT Outfile," static char temp[5];"
  1905. FPRINT Outfile," return (char *) memmove(temp,&cvt,4);"
  1906. FPRINT Outfile,"}\n\n"
  1907. END IF
  1908. IF Use_Cvd THEN
  1909. FPRINT Outfile,"double CVD (char *s)"
  1910. FPRINT Outfile,"{"
  1911. FPRINT Outfile," return ((double*)s)[0];"
  1912. FPRINT Outfile,"}\n\n"
  1913. END IF
  1914. IF Use_Cvld THEN
  1915. FPRINT Outfile,"long double CVLD (char *s)"
  1916. FPRINT Outfile,"{"
  1917. FPRINT Outfile," return ((long double*)s)[0];"
  1918. FPRINT Outfile,"}\n\n"
  1919. END IF
  1920. IF Use_Mkd THEN
  1921. FPRINT Outfile,"char *MKD (double cvt)"
  1922. FPRINT Outfile,"{"
  1923. FPRINT Outfile," static char temp[9];"
  1924. FPRINT Outfile," return (char *) memmove(temp,&cvt,8);"
  1925. FPRINT Outfile,"}\n\n"
  1926. END IF
  1927. IF Use_Mkld THEN
  1928. FPRINT Outfile,"char *MKLD (long double cvt)"
  1929. FPRINT Outfile,"{"
  1930. FPRINT Outfile," static char temp[11];"
  1931. FPRINT Outfile," return (char *) memmove(temp,&cvt,10);"
  1932. FPRINT Outfile,"}\n\n"
  1933. END IF
  1934. IF Use_BcxSplitPath THEN
  1935. FPRINT Outfile,"char *BcxSplitPath (char *FPath, int mask)"
  1936. FPRINT Outfile,"{"
  1937. FPRINT Outfile," if(!FPath) return BCX_TmpStr(1);"
  1938. FPRINT Outfile," char *BCX_RetStr=BCX_TmpStr(strlen(FPath));"
  1939. FPRINT Outfile," char tmp[MAX_PATH*4];"
  1940. FPRINT Outfile," _splitpath_(FPath,tmp,&tmp[MAX_PATH],&tmp[MAX_PATH*2],&tmp[MAX_PATH*3]);"
  1941. FPRINT Outfile," if(mask & FDRV) strcat(BCX_RetStr,tmp);"
  1942. FPRINT Outfile," if(mask & FPATH)strcat(BCX_RetStr,&tmp[MAX_PATH]);"
  1943. FPRINT Outfile," if(mask & FNAME)strcat(BCX_RetStr,&tmp[MAX_PATH*2]);"
  1944. FPRINT Outfile," if(mask & FEXT) strcat(BCX_RetStr,&tmp[MAX_PATH*3]);"
  1945. FPRINT Outfile," return BCX_RetStr;"
  1946. FPRINT Outfile,"}\n\n"
  1947. FPRINT Outfile," void _splitpath_(const char* path, char* drv, char* dir, char* name, char* ext)"
  1948. FPRINT Outfile," {"
  1949. FPRINT Outfile," const char* pend; /* end of processed string */"
  1950. FPRINT Outfile," const char* p; /* search pointer */"
  1951. FPRINT Outfile," const char* s; /* copy pointer */"
  1952. FPRINT Outfile," "
  1953. FPRINT Outfile," /* extract drive name */"
  1954. FPRINT Outfile," if (path[0] && path[1]==':') {"
  1955. FPRINT Outfile," if (drv) {"
  1956. FPRINT Outfile," *drv++ = *path++;"
  1957. FPRINT Outfile," *drv++ = *path++;"
  1958. FPRINT Outfile," *drv = 0;"
  1959. FPRINT Outfile," }"
  1960. FPRINT Outfile," } else if (drv)"
  1961. FPRINT Outfile," *drv = 0;"
  1962. FPRINT Outfile," "
  1963. FPRINT Outfile," /* search for end of string or stream separator */"
  1964. FPRINT Outfile," for(pend=path; *pend && *pend!=':'; )"
  1965. FPRINT Outfile," pend++;"
  1966. FPRINT Outfile," "
  1967. FPRINT Outfile," /* search for begin of file extension */"
  1968. FPRINT Outfile," for(p=pend; p > path && *--p != '\\\\' && *p!='/'; )"
  1969. FPRINT Outfile," if (*p == '.') {"
  1970. FPRINT Outfile," pend = p;"
  1971. FPRINT Outfile," break;"
  1972. FPRINT Outfile," }"
  1973. FPRINT Outfile," "
  1974. FPRINT Outfile," if (ext)"
  1975. FPRINT Outfile," {"
  1976. FPRINT Outfile," s=pend;"
  1977. FPRINT Outfile," do{ *ext++ = *s; } while(*s++);"
  1978. FPRINT Outfile," }"
  1979. FPRINT Outfile," /* search for end of directory name */"
  1980. FPRINT Outfile," for(p=pend; p > path; )"
  1981. FPRINT Outfile," if (*--p == '\\\\' || *p == '/') {"
  1982. FPRINT Outfile," p++;"
  1983. FPRINT Outfile," break;"
  1984. FPRINT Outfile," }"
  1985. FPRINT Outfile," "
  1986. FPRINT Outfile," if (name) {"
  1987. FPRINT Outfile," for(s=p; s<pend; )"
  1988. FPRINT Outfile," *name++ = *s++;"
  1989. FPRINT Outfile," "
  1990. FPRINT Outfile," *name = 0;"
  1991. FPRINT Outfile," }"
  1992. FPRINT Outfile," "
  1993. FPRINT Outfile," if (dir) {"
  1994. FPRINT Outfile," for(s=path; s<p; )"
  1995. FPRINT Outfile," *dir++ = *s++;"
  1996. FPRINT Outfile," "
  1997. FPRINT Outfile," *dir = 0;"
  1998. FPRINT Outfile," }"
  1999. FPRINT Outfile," }\n"
  2000. END IF
  2001. IF Use_StrUpLow THEN
  2002. FPRINT Outfile,"char *_strupr_(char *string)"
  2003. FPRINT Outfile,"{"
  2004. FPRINT Outfile," char *s;"
  2005. FPRINT Outfile,""
  2006. FPRINT Outfile," if (string)"
  2007. FPRINT Outfile," {"
  2008. FPRINT Outfile," for(s = string; *s; ++s)"
  2009. FPRINT Outfile," *s = toupper(*s);"
  2010. FPRINT Outfile," }"
  2011. FPRINT Outfile," return string;"
  2012. FPRINT Outfile,"}\n"
  2013. FPRINT Outfile,"char *_strlwr_(char *string)"
  2014. FPRINT Outfile,"{"
  2015. FPRINT Outfile," char *s;"
  2016. FPRINT Outfile,""
  2017. FPRINT Outfile," if (string)"
  2018. FPRINT Outfile," {"
  2019. FPRINT Outfile," for (s = string; *s; ++s)"
  2020. FPRINT Outfile," *s = tolower(*s);"
  2021. FPRINT Outfile," }"
  2022. FPRINT Outfile," return string;"
  2023. FPRINT Outfile,"}\n"
  2024. END IF
  2025. IF Use_Strtoken THEN
  2026. FPRINT Outfile,"char * StrToken (char *Source, char *TokenChar, int n)"
  2027. FPRINT Outfile,"{"
  2028. FPRINT Outfile," char *BCX_RetStr={0};"
  2029. FPRINT Outfile," char *RetVal;"
  2030. FPRINT Outfile," char *Copy;"
  2031. FPRINT Outfile," int Posn=0;"
  2032. FPRINT Outfile," int Find=0;"
  2033. FPRINT Outfile," int LenSrc=strlen(Source);"
  2034. FPRINT Outfile," RetVal=(char*)calloc(LenSrc+1,1);"
  2035. FPRINT Outfile," Copy=Source;"
  2036. FPRINT Outfile," if(tally(Source,TokenChar)==0)"
  2037. FPRINT Outfile," {"
  2038. FPRINT Outfile," BCX_RetStr=BCX_TmpStr(1);"
  2039. FPRINT Outfile," if(RetVal)free(RetVal);"
  2040. FPRINT Outfile," return BCX_RetStr;"
  2041. FPRINT Outfile," }"
  2042. FPRINT Outfile," if(n==1)"
  2043. FPRINT Outfile," {"
  2044. FPRINT Outfile," BCX_RetStr=BCX_TmpStr(LenSrc);"
  2045. FPRINT Outfile," strcpy(BCX_RetStr,(char*)extract(Source,TokenChar));"
  2046. FPRINT Outfile," if(RetVal)free(RetVal);"
  2047. FPRINT Outfile," return BCX_RetStr;"
  2048. FPRINT Outfile," }"
  2049. FPRINT Outfile," if(n>tally(Source,TokenChar)+1)"
  2050. FPRINT Outfile," {"
  2051. FPRINT Outfile," BCX_RetStr=BCX_TmpStr(1);"
  2052. FPRINT Outfile," if(RetVal)free(RetVal);"
  2053. FPRINT Outfile," return BCX_RetStr;"
  2054. FPRINT Outfile," }"
  2055. FPRINT Outfile," while(*Copy)"
  2056. FPRINT Outfile," {"
  2057. FPRINT Outfile," if(*Copy==TokenChar[0]) Find++;"
  2058. FPRINT Outfile," if(Find==n) break;"
  2059. FPRINT Outfile," Copy++;"
  2060. FPRINT Outfile," Posn++;"
  2061. FPRINT Outfile," }"
  2062. FPRINT Outfile," if(n==tally(Source,TokenChar)+1)"
  2063. FPRINT Outfile," {"
  2064. FPRINT Outfile," Posn=LenSrc;"
  2065. FPRINT Outfile," Copy=Source+Posn;"
  2066. FPRINT Outfile," while(*Copy&&Source[Posn]!=TokenChar[0])"
  2067. FPRINT Outfile," {"
  2068. FPRINT Outfile," Posn--;"
  2069. FPRINT Outfile," Copy--;"
  2070. FPRINT Outfile," }"
  2071. FPRINT Outfile," }"
  2072. FPRINT Outfile," strcpy(RetVal,(char*)mid(Source,1,Posn));"
  2073. FPRINT Outfile," strcpy(RetVal,(char*)mid(RetVal,InstrRev(RetVal,TokenChar)));"
  2074. FPRINT Outfile," BCX_RetStr=BCX_TmpStr(LenSrc);"
  2075. FPRINT Outfile," strcpy(BCX_RetStr,(char*)RemoveStr(RetVal,TokenChar));"
  2076. FPRINT Outfile," if(RetVal)free(RetVal);"
  2077. FPRINT Outfile," return BCX_RetStr;"
  2078. FPRINT Outfile,"}\n\n"
  2079. END IF
  2080. IF Use_iReplace THEN
  2081. FPRINT Outfile,"char *iReplace (char *src, char *pat, char *rep)"
  2082. FPRINT Outfile,"{"
  2083. FPRINT Outfile," size_t patsz, repsz, tmpsz, delta;"
  2084. FPRINT Outfile," char *strtmp, *p, *q, *r;"
  2085. FPRINT Outfile," if (!pat || !*pat)"
  2086. FPRINT Outfile," {"
  2087. FPRINT Outfile," strtmp = BCX_TmpStr(strlen(src));"
  2088. FPRINT Outfile," if (!strtmp) return NULL;"
  2089. FPRINT Outfile," return strcpy(strtmp, src);"
  2090. FPRINT Outfile," }"
  2091. FPRINT Outfile," repsz = strlen(rep);"
  2092. FPRINT Outfile," patsz = strlen(pat);"
  2093. FPRINT Outfile," for (tmpsz=0, p=src;(q=_stristr_(p,pat))!=0; p=q+patsz)"
  2094. FPRINT Outfile," tmpsz += (size_t) (q - p) + repsz;"
  2095. FPRINT Outfile," tmpsz += strlen(p);"
  2096. FPRINT Outfile," strtmp = BCX_TmpStr(tmpsz);"
  2097. FPRINT Outfile," if (!strtmp) return NULL;"
  2098. FPRINT Outfile," for (r=strtmp,p=src;(q=_stristr_(p,pat))!=0;p=q+patsz)"
  2099. FPRINT Outfile," {"
  2100. FPRINT Outfile," delta = (size_t) (q-p);"
  2101. FPRINT Outfile," memcpy(r,p,delta); r += delta;"
  2102. FPRINT Outfile," strcpy(r,rep); r += repsz;"
  2103. FPRINT Outfile," }"
  2104. FPRINT Outfile," strcpy(r,p);"
  2105. FPRINT Outfile," return strtmp;"
  2106. FPRINT Outfile,"}\n\n"
  2107. END IF
  2108. IF Use_WideToAnsi THEN
  2109. FPRINT Outfile,"char* WideToAnsi (wchar_t *WideStr, UINT CodePage,DWORD dwFlags)"
  2110. FPRINT Outfile,"{"
  2111. FPRINT Outfile," char *BCX_RetStr={0};"
  2112. FPRINT Outfile," UINT uLen;"
  2113. FPRINT Outfile," uLen=wcstombs(NULL, WideStr, 0); //WideCharToMultiByte(CodePage,dwFlags,WideStr,-1,0,0,0,0);"
  2114. FPRINT Outfile," BCX_RetStr=(char*)BCX_TmpStr(uLen);"
  2115. FPRINT Outfile," wcstombs(BCX_RetStr, WideStr, uLen); //WideCharToMultiByte(CodePage,dwFlags,WideStr,-1,BCX_RetStr,uLen,0,0);"
  2116. FPRINT Outfile," return BCX_RetStr;"
  2117. FPRINT Outfile,"}\n\n"
  2118. END IF
  2119. IF Use_SysStr THEN
  2120. FPRINT Outfile,"BSTR SysStr (char * szIn, int widstr, int bfree)"
  2121. FPRINT Outfile,"{"
  2122. FPRINT Outfile," static BSTR bStr[32];"
  2123. FPRINT Outfile," static int index;"
  2124. FPRINT Outfile," if(bfree)"
  2125. FPRINT Outfile," {"
  2126. FPRINT Outfile," for(index=0; index<32; index+=1) "
  2127. FPRINT Outfile," SysFreeString(bStr[index]);"
  2128. FPRINT Outfile," return 0;"
  2129. FPRINT Outfile," }"
  2130. FPRINT Outfile," index=(++index & 31);"
  2131. FPRINT Outfile," SysFreeString(bStr[index]);"
  2132. FPRINT Outfile," int length=strlen(szIn);"
  2133. FPRINT Outfile," if(widstr)"
  2134. FPRINT Outfile," {"
  2135. FPRINT Outfile," bStr[index]=SysAllocStringLen(NULL, (2*length));"
  2136. FPRINT Outfile," MultiByteToWideChar(CP_ACP,0,szIn,-1,bStr[index],(2*length+1));"
  2137. FPRINT Outfile," }else{"
  2138. FPRINT Outfile," bStr[index]=SysAllocStringByteLen(szIn, length);"
  2139. FPRINT Outfile," }"
  2140. FPRINT Outfile," return bStr[index];"
  2141. FPRINT Outfile,"}\n\n"
  2142. END IF
  2143. IF Use_AnsiToWide THEN
  2144. FPRINT Outfile,"wchar_t *AnsiToWide (char *AnsiStr, UINT CodePage,DWORD dwFlags)"
  2145. FPRINT Outfile,"{"
  2146. FPRINT Outfile," UINT uLen;"
  2147. FPRINT Outfile," wchar_t *WideStr;"
  2148. FPRINT Outfile," uLen=mbstowcs(NULL, AnsiStr, 0); //MultiByteToWideChar(CodePage,dwFlags,AnsiStr,-1,0,0);"
  2149. FPRINT Outfile," if(uLen<=1) return (wchar_t*)BCX_TmpStr(2);"
  2150. FPRINT Outfile," WideStr = (wchar_t*)BCX_TmpStr(2*uLen);"
  2151. FPRINT Outfile," mbstowcs(WideStr, AnsiStr, uLen); //MultiByteToWideChar(CodePage,dwFlags,AnsiStr,uLen,WideStr,uLen);"
  2152. FPRINT Outfile," return WideStr;"
  2153. FPRINT Outfile,"}\n\n"
  2154. END IF
  2155. IF Use_FileLocked THEN
  2156. FPRINT Outfile,"int FileLocked (char *Filename)"
  2157. FPRINT Outfile,"{"
  2158. FPRINT Outfile," FILE *FP=fopen(Filename,", ENC$("rb+"), ");"
  2159. FPRINT Outfile," if(FP==0) return 1;"
  2160. FPRINT Outfile," fclose(FP);"
  2161. FPRINT Outfile," return 0;"
  2162. FPRINT Outfile,"}\n\n"
  2163. END IF
  2164. IF Use_ContainedIn THEN
  2165. FPRINT Outfile,"int containedin(char * Token,char **Contain ,int c)"
  2166. FPRINT Outfile," {"
  2167. FPRINT Outfile," int i=0;"
  2168. FPRINT Outfile," while(Contain[i][0])"
  2169. FPRINT Outfile," {"
  2170. FPRINT Outfile," if(0 == ((c == 0 || c == 2) ? strcmp(Contain[i],Token) : strcasecmp(Contain[i],Token)))"
  2171. FPRINT Outfile," {"
  2172. FPRINT Outfile," return ((c < 2) ? 0 : i);"
  2173. FPRINT Outfile," }"
  2174. FPRINT Outfile," i++;"
  2175. FPRINT Outfile," }"
  2176. FPRINT Outfile," return -1;"
  2177. FPRINT Outfile," }\n\n"
  2178. END IF
  2179. IF Use_FindInType THEN
  2180. FPRINT Outfile,"int FindInType(char *Token,char *StOffset,int StSize,int start,int finish,int c,int *idx)"
  2181. FPRINT Outfile," {"
  2182. FPRINT Outfile," int j;"
  2183. FPRINT Outfile," char *Srch;"
  2184. FPRINT Outfile," int (*cmp)(const char*,const char*);"
  2185. FPRINT Outfile," cmp = ((c == 0 || c == 2) ? strcmp : strcasecmp);"
  2186. FPRINT Outfile," for(j=start; j<=finish; j++)"
  2187. FPRINT Outfile," {"
  2188. FPRINT Outfile," Srch = StOffset + ((idx==0) ? j*StSize : idx[j]*StSize);"
  2189. FPRINT Outfile," if(cmp(Srch,Token)==0)"
  2190. FPRINT Outfile," {"
  2191. FPRINT Outfile," return ((c < 2) ? 0 : j);"
  2192. FPRINT Outfile," }"
  2193. FPRINT Outfile," }"
  2194. FPRINT Outfile," return -1;"
  2195. FPRINT Outfile," }\n\n"
  2196. END IF
  2197. IF Use_StartupCode THEN
  2198. FPRINT Outfile,"int BCX_StartupCode_(void)"
  2199. FPRINT Outfile,"{"
  2200. FOR INTEGER i = 1 TO StartNdx
  2201. FPRINT Outfile," " + StartSub$[i] + "();"
  2202. NEXT
  2203. FPRINT Outfile," return 1;"
  2204. FPRINT Outfile,"}\n\n"
  2205. END IF
  2206. IF Use_ExitCode THEN
  2207. FPRINT Outfile,"int BCX_ExitCode_(void)"
  2208. FPRINT Outfile,"{"
  2209. FOR INTEGER i = 1 TO ExitNdx
  2210. FPRINT Outfile," atexit(" + ExitSub$[i] + ");"
  2211. NEXT
  2212. FPRINT Outfile," return 1;"
  2213. FPRINT Outfile,"}\n\n"
  2214. END IF
  2215. if Use_Socket then
  2216. FPRINT Outfile,"sockaddr_in sock_addr (char *ServerName,int port)"
  2217. FPRINT Outfile,"{"
  2218. FPRINT Outfile," in_addr iaHost;"
  2219. FPRINT Outfile," hostent* lpHostEntry;"
  2220. FPRINT Outfile," sockaddr_in saServer;"
  2221. FPRINT Outfile," iaHost.s_addr=inet_addr(ServerName);"
  2222. FPRINT Outfile," if(iaHost.s_addr==INADDR_NONE)"
  2223. FPRINT Outfile," {"
  2224. FPRINT Outfile," lpHostEntry=gethostbyname(ServerName);"
  2225. FPRINT Outfile," }"
  2226. FPRINT Outfile," else"
  2227. FPRINT Outfile," {"
  2228. FPRINT Outfile," lpHostEntry=gethostbyaddr((char*)&iaHost,sizeof(in_addr),AF_INET);"
  2229. FPRINT Outfile," }"
  2230. FPRINT Outfile," if(lpHostEntry==NULL)"
  2231. FPRINT Outfile," {"
  2232. FPRINT Outfile," printf("+enc$("Error! HOST NOT FOUND: %s\\n")+", ServerName);"
  2233. FPRINT Outfile," }"
  2234. FPRINT Outfile," else"
  2235. FPRINT Outfile," {"
  2236. FPRINT Outfile," saServer.sin_port=htons(port);"
  2237. FPRINT Outfile," saServer.sin_family=AF_INET;"
  2238. FPRINT Outfile," saServer.sin_addr=*(in_addr*)lpHostEntry->h_addr;"
  2239. FPRINT Outfile," }"
  2240. FPRINT Outfile," return saServer;"
  2241. FPRINT Outfile,"}\n\n"
  2242. FPRINT Outfile,"int connect_socket (sockaddr_in saServer)"
  2243. FPRINT Outfile,"{"
  2244. FPRINT Outfile," int Socket, nRet;"
  2245. FPRINT Outfile," Socket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);"
  2246. FPRINT Outfile," if(Socket==-1)"
  2247. FPRINT Outfile," {"
  2248. FPRINT Outfile," return Socket;"
  2249. FPRINT Outfile," }"
  2250. FPRINT Outfile," nRet=connect(Socket,(sockaddr*)&saServer,sizeof(sockaddr_in));"
  2251. FPRINT Outfile," if(nRet==-1)"
  2252. FPRINT Outfile," {"
  2253. FPRINT Outfile," close(Socket);"
  2254. FPRINT Outfile," return nRet;"
  2255. FPRINT Outfile," }"
  2256. FPRINT Outfile," return Socket;"
  2257. FPRINT Outfile,"}\n\n"
  2258. FPRINT Outfile,"int BcxSocket (char *ServerName,int port)"
  2259. FPRINT Outfile,"{"
  2260. FPRINT Outfile," sockaddr_in saServer;"
  2261. FPRINT Outfile," saServer=sock_addr(ServerName,port);"
  2262. FPRINT Outfile," return connect_socket(saServer);"
  2263. FPRINT Outfile,"}\n\n"
  2264. FPRINT Outfile,"int BcxSocketSend (int Socket, char *szBuffer)"
  2265. FPRINT Outfile,"{"
  2266. FPRINT Outfile," static int nRet;"
  2267. FPRINT Outfile," nRet=send(Socket,szBuffer,strlen(szBuffer),0);"
  2268. FPRINT Outfile," if(nRet==-1)"
  2269. FPRINT Outfile," {"
  2270. FPRINT Outfile," close(Socket);"
  2271. FPRINT Outfile," }"
  2272. FPRINT Outfile," return nRet;"
  2273. FPRINT Outfile,"}\n\n"
  2274. FPRINT Outfile,"int BcxSocketRead (int Socket, char *szBuffer)"
  2275. FPRINT Outfile,"{"
  2276. FPRINT Outfile," return read(Socket,szBuffer,strlen(szBuffer));"
  2277. FPRINT Outfile,"}\n\n"
  2278. FPRINT Outfile,"void BcxSocketClose(int Socket) {"
  2279. FPRINT Outfile," close(Socket);"
  2280. FPRINT Outfile,"}\n\n"
  2281. end if
  2282. '/***** 2013-06-26 New REGEX Keywords -AIR *****/
  2283. '/***** 2018-12-12 Changed to regmatch -AIR *****/
  2284. IF Use_RegEx THEN
  2285. FPRINT Outfile,"bool regmatch (char *buffer, char *pattern, REGEX* retval)"
  2286. FPRINT Outfile,"{"
  2287. FPRINT Outfile," static int t;"
  2288. ' FPRINT Outfile," memset(&t,0,sizeof(t));"
  2289. FPRINT Outfile," static int i;"
  2290. ' FPRINT Outfile," memset(&i,0,sizeof(i));"
  2291. FPRINT Outfile," static regex_t re;"
  2292. ' FPRINT Outfile," memset(&re,0,sizeof(re));"
  2293. FPRINT Outfile," t=regcomp( &re,pattern,REG_ICASE|REG_EXTENDED);"
  2294. FPRINT Outfile," if(t)"
  2295. FPRINT Outfile," {"
  2296. FPRINT Outfile," regerror(t, &re,buffer,sizeof(buffer));"
  2297. FPRINT Outfile," printf("+enc$("regex error: %s %s")+",buffer,pattern);"
  2298. FPRINT Outfile," return 0;"
  2299. FPRINT Outfile," }"
  2300. FPRINT Outfile," t=regexec( &re,buffer,1023,(*retval).matches,0);"
  2301. FPRINT Outfile," (*retval).count=re.re_nsub;"
  2302. FPRINT Outfile," if(!t)"
  2303. FPRINT Outfile," {"
  2304. FPRINT Outfile," for(i=1; i<=(*retval).count; i+=1)"
  2305. FPRINT Outfile," {"
  2306. FPRINT Outfile," if((*retval).matches[i].rm_so>=0)"
  2307. FPRINT Outfile," {"
  2308. FPRINT Outfile," (*retval).results[i]=peekstr( &buffer[(*retval).matches[i].rm_so],((*retval).matches[i].rm_eo-(*retval).matches[i].rm_so));"
  2309. FPRINT Outfile," }"
  2310. FPRINT Outfile," }"
  2311. FPRINT Outfile," }"
  2312. FPRINT Outfile," regfree( &re);"
  2313. FPRINT Outfile," if(!t)"
  2314. FPRINT Outfile," {"
  2315. FPRINT Outfile," return TRUE;"
  2316. FPRINT Outfile," }"
  2317. FPRINT Outfile," else"
  2318. FPRINT Outfile," {"
  2319. FPRINT Outfile," return FALSE;"
  2320. FPRINT Outfile," }"
  2321. FPRINT Outfile,"}\n\n"
  2322. END IF
  2323. END SUB 'RunTimeFunctions