PageRenderTime 74ms CodeModel.GetById 37ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/harbour/src/compiler/cmdcheck.c

#
C | 1217 lines | 968 code | 141 blank | 108 comment | 251 complexity | 2e99cfd46de0c06a7c51ea80b7825352 MD5 | raw file
Possible License(s): AGPL-1.0, BSD-3-Clause, CC-BY-SA-3.0, LGPL-3.0, GPL-2.0, LGPL-2.0, LGPL-2.1
  1. /*
  2. * $Id: cmdcheck.c 17184 2012-01-06 15:28:23Z vszakats $
  3. */
  4. /*
  5. * Harbour Project source code:
  6. * Compiler command line and HARBOURCMD/CLIPPERCMD checking
  7. *
  8. * Copyright 1999 {list of individual authors and e-mail addresses}
  9. * www - http://harbour-project.org
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version, with one exception:
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA (or visit
  24. * their web site at http://www.gnu.org/).
  25. *
  26. */
  27. /*
  28. * The following parts are Copyright of the individual authors.
  29. * www - http://harbour-project.org
  30. *
  31. * Copyright 2000 Ron Pinkas <Ron@Profit-Master.com>
  32. * hb_compChkCompilerSwitch()
  33. *
  34. * Copyright 1999 Jose Lalin <dezac@corevia.com>
  35. * hb_compChkEnvironVar()
  36. *
  37. * Copyright 1999-2001 Viktor Szakats (harbour syenar.net)
  38. * PackDateTime()
  39. * hb_compChkDefineSwitch()
  40. * hb_compChkDefines()
  41. *
  42. * See COPYING for licensing terms.
  43. *
  44. */
  45. #include "hbcomp.h"
  46. #include "hbdate.h"
  47. /* TODO: Add support for this compiler switches
  48. -r -t || hb_getenv( "TMP" )
  49. */
  50. /* NOTE: Making the date and time info to fit into 32 bits can only be done
  51. in a "lossy" way, in practice that means it's not possible to unpack
  52. the exact date/time info from the resulting HB_ULONG. Since the year
  53. is only stored in 6 bits, 1980 will result in the same bit pattern
  54. as 2044. The purpose of this value is only used to *differenciate*
  55. between the dates ( the exact dates are not significant ), so this
  56. can be used here without problems. [vszakats] */
  57. /* 76543210765432107654321076543210
  58. |.......|.......|.......|.......
  59. |____| Year 6 bits
  60. |__| Month 4 bits
  61. |___| Day 5 bits
  62. |___| Hour 5 bits
  63. |____| Minute 6 bits
  64. |____| Second 6 bits */
  65. static HB_ULONG PackDateTime( void )
  66. {
  67. union
  68. {
  69. struct
  70. {
  71. HB_U32 second : 6; /* bits: 0 - 5 */
  72. HB_U32 minute : 6; /* bits: 6 - 11 */
  73. HB_U32 hour : 5; /* bits: 12 - 16 */
  74. HB_U32 day : 5; /* bits: 16 - 21 */
  75. HB_U32 month : 4; /* bits: 22 - 25 */
  76. HB_U32 year : 6; /* bits: 26 - 31 */
  77. } ts;
  78. HB_U32 val;
  79. } u;
  80. int iYear, iMonth, iDay, iHour, iMinute, iSecond, iMillisec;
  81. hb_timeStampGetLocal( &iYear, &iMonth, &iDay,
  82. &iHour, &iMinute, &iSecond, &iMillisec );
  83. u.ts.year = iYear - 1980;
  84. u.ts.month = iMonth;
  85. u.ts.day = iDay;
  86. u.ts.hour = iHour;
  87. u.ts.minute = iMinute;
  88. u.ts.second = iSecond;
  89. return u.val;
  90. }
  91. static void hb_notSupportedInfo( HB_COMP_DECL, const char *szSwitch )
  92. {
  93. char buffer[ 512 ];
  94. hb_snprintf( buffer, sizeof( buffer ),
  95. "Not yet supported command line option: %s\n", szSwitch );
  96. hb_compOutStd( HB_COMP_PARAM, buffer );
  97. }
  98. static void hb_compChkEnvironVar( HB_COMP_DECL, const char *szSwitch )
  99. {
  100. if( szSwitch && !HB_COMP_PARAM->fExit )
  101. {
  102. const char *s = szSwitch;
  103. /* If szSwitch doesn't start with a HB_OSOPTSEP char
  104. * show an error
  105. */
  106. if( !HB_ISOPTSEP( *s ) )
  107. hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'F', HB_COMP_ERR_BADOPTION, s, NULL );
  108. else
  109. {
  110. s++;
  111. switch( *s )
  112. {
  113. case 'a':
  114. case 'A':
  115. if( *( s + 1 ) == '-' )
  116. HB_COMP_PARAM->fAutoMemvarAssume = HB_FALSE;
  117. else
  118. HB_COMP_PARAM->fAutoMemvarAssume = HB_TRUE;
  119. break;
  120. case 'b':
  121. case 'B':
  122. {
  123. unsigned int i = 0;
  124. char *szOption = hb_strupr( hb_strdup( s ) );
  125. while( i < strlen( szOption ) && !HB_ISOPTSEP( szOption[i] ) )
  126. i++;
  127. szOption[i] = '\0';
  128. if( strcmp( szOption, "BUILD" ) == 0 )
  129. HB_COMP_PARAM->fBuildInfo = HB_TRUE;
  130. else
  131. {
  132. if( *( s + 1 ) == '-' )
  133. HB_COMP_PARAM->fDebugInfo = HB_FALSE;
  134. else
  135. {
  136. HB_COMP_PARAM->fDebugInfo = HB_TRUE;
  137. HB_COMP_PARAM->fLineNumbers = HB_TRUE;
  138. }
  139. }
  140. hb_xfree( szOption );
  141. break;
  142. }
  143. case 'c':
  144. case 'C':
  145. {
  146. unsigned int i = 0;
  147. char *szOption = hb_strupr( hb_strdup( s ) );
  148. while( i < strlen( szOption ) && !HB_ISOPTSEP( szOption[i] ) )
  149. i++;
  150. szOption[i] = '\0';
  151. if( strcmp( szOption, "CREDITS" ) == 0 ||
  152. strcmp( szOption, "CREDIT" ) == 0 ||
  153. strcmp( szOption, "CREDI" ) == 0 ||
  154. strcmp( szOption, "CRED" ) == 0 )
  155. HB_COMP_PARAM->fCredits = HB_TRUE;
  156. else
  157. hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'F', HB_COMP_ERR_BADOPTION, szOption, NULL );
  158. hb_xfree( szOption );
  159. break;
  160. }
  161. case 'd':
  162. case 'D':
  163. /* NOTE: Ignore these -d switches will be processed separately */
  164. break;
  165. case 'e':
  166. case 'E':
  167. if( *( s + 1 ) == 's' || *( s + 1 ) == 'S' )
  168. {
  169. switch( *( s + 2 ) )
  170. {
  171. case '\0':
  172. case '0':
  173. HB_COMP_PARAM->iExitLevel = HB_EXITLEVEL_DEFAULT;
  174. break;
  175. case '1':
  176. HB_COMP_PARAM->iExitLevel = HB_EXITLEVEL_SETEXIT;
  177. break;
  178. case '2':
  179. HB_COMP_PARAM->iExitLevel = HB_EXITLEVEL_DELTARGET;
  180. break;
  181. default:
  182. hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'F', HB_COMP_ERR_BADOPTION, s, NULL );
  183. }
  184. }
  185. else
  186. hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'F', HB_COMP_ERR_BADOPTION, s, NULL );
  187. break;
  188. case 'g':
  189. case 'G':
  190. switch( *( s + 1 ) )
  191. {
  192. case 'c':
  193. case 'C':
  194. HB_COMP_PARAM->iLanguage = HB_LANG_C;
  195. switch( *( s + 2 ) )
  196. {
  197. case '3':
  198. HB_COMP_PARAM->iGenCOutput = HB_COMPGENC_REALCODE;
  199. break;
  200. case '2':
  201. HB_COMP_PARAM->iGenCOutput = HB_COMPGENC_VERBOSE;
  202. break;
  203. case '1':
  204. HB_COMP_PARAM->iGenCOutput = HB_COMPGENC_NORMAL;
  205. break;
  206. case '\0':
  207. case '0':
  208. HB_COMP_PARAM->iGenCOutput = HB_COMPGENC_COMPACT;
  209. break;
  210. default:
  211. hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'F', HB_COMP_ERR_BADOPTION, s, NULL );
  212. }
  213. break;
  214. case 'h':
  215. case 'H':
  216. HB_COMP_PARAM->iLanguage = HB_LANG_PORT_OBJ;
  217. break;
  218. case 'd':
  219. case 'D':
  220. if( HB_COMP_PARAM->szDepExt )
  221. {
  222. hb_xfree( HB_COMP_PARAM->szDepExt );
  223. HB_COMP_PARAM->szDepExt = NULL;
  224. }
  225. if( s[2] == '-' )
  226. HB_COMP_PARAM->iTraceInclude = 0;
  227. else if( s[2] == '.' || s[2] == '\0' )
  228. {
  229. HB_COMP_PARAM->iTraceInclude = 2;
  230. if( s[2] != '\0' )
  231. HB_COMP_PARAM->szDepExt = hb_strdup( s + 2 );
  232. }
  233. else
  234. hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'F', HB_COMP_ERR_BADOPTION, s, NULL );
  235. break;
  236. case 'e':
  237. case 'E':
  238. switch( *( s + 2 ) )
  239. {
  240. case '1':
  241. HB_COMP_PARAM->iErrorFmt = HB_ERRORFMT_IDE;
  242. break;
  243. case '\0':
  244. case '0':
  245. HB_COMP_PARAM->iErrorFmt = HB_ERRORFMT_CLIPPER;
  246. break;
  247. default:
  248. hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'F', HB_COMP_ERR_BADOPTION, s, NULL );
  249. }
  250. break;
  251. default:
  252. hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'F', HB_COMP_ERR_UNSUPPORTED_LANG, NULL, NULL );
  253. break;
  254. }
  255. break;
  256. /* NOTE:
  257. h or H from HELP or help
  258. */
  259. case 'h':
  260. case 'H':
  261. case '?':
  262. break;
  263. /* NOTE:
  264. It already has support for several include files
  265. */
  266. case 'i':
  267. case 'I':
  268. switch( *( s + 1 ) )
  269. {
  270. case '-':
  271. HB_COMP_PARAM->fINCLUDE = HB_FALSE;
  272. break;
  273. case '+':
  274. HB_COMP_PARAM->fINCLUDE = HB_TRUE;
  275. break;
  276. default:
  277. hb_pp_addSearchPath( HB_COMP_PARAM->pLex->pPP, s + 1, HB_FALSE );
  278. }
  279. break;
  280. case 'j':
  281. case 'J':
  282. HB_COMP_PARAM->fI18n = HB_TRUE;
  283. if( s[ 1 ] )
  284. HB_COMP_PARAM->pI18nFileName = hb_fsFNameSplit( s + 1 );
  285. break;
  286. case 'k':
  287. case 'K':
  288. {
  289. int i = 1;
  290. while( s[i] && !HB_COMP_PARAM->fExit )
  291. {
  292. switch( s[i++] )
  293. {
  294. case '?':
  295. hb_compPrintLogo( HB_COMP_PARAM );
  296. hb_compPrintModes( HB_COMP_PARAM );
  297. HB_COMP_PARAM->fLogo = HB_FALSE;
  298. HB_COMP_PARAM->fQuiet = HB_TRUE;
  299. break;
  300. case 'h':
  301. case 'H':
  302. /* default Harbour mode */
  303. if( s[i] == '-' )
  304. {
  305. i++;
  306. HB_COMP_PARAM->supported &= ~HB_COMPFLAG_HARBOUR;
  307. }
  308. else
  309. HB_COMP_PARAM->supported |= HB_COMPFLAG_HARBOUR;
  310. break;
  311. case 'c':
  312. case 'C':
  313. /* clear all flags - minimal set of features */
  314. HB_COMP_PARAM->supported &= HB_COMPFLAG_SHORTCUTS;
  315. HB_COMP_PARAM->supported |= HB_COMPFLAG_OPTJUMP |
  316. HB_COMPFLAG_MACROTEXT;
  317. break;
  318. case 'x':
  319. case 'X':
  320. if( s[i] == '-' )
  321. {
  322. i++;
  323. HB_COMP_PARAM->supported &= ~HB_COMPFLAG_XBASE;
  324. }
  325. else
  326. HB_COMP_PARAM->supported |= HB_COMPFLAG_XBASE;
  327. break;
  328. case 'i':
  329. case 'I':
  330. if( s[i] == '-' )
  331. {
  332. i++;
  333. HB_COMP_PARAM->supported &= ~HB_COMPFLAG_HB_INLINE;
  334. }
  335. else
  336. HB_COMP_PARAM->supported |= HB_COMPFLAG_HB_INLINE;
  337. break;
  338. case 'j':
  339. case 'J':
  340. if( s[i] == '+' )
  341. {
  342. i++;
  343. HB_COMP_PARAM->supported |= HB_COMPFLAG_OPTJUMP;
  344. }
  345. else
  346. HB_COMP_PARAM->supported &= ~HB_COMPFLAG_OPTJUMP;
  347. break;
  348. case 'm':
  349. case 'M':
  350. if( s[i] == '+' )
  351. {
  352. i++;
  353. HB_COMP_PARAM->supported |= HB_COMPFLAG_MACROTEXT;
  354. }
  355. else
  356. HB_COMP_PARAM->supported &= ~HB_COMPFLAG_MACROTEXT;
  357. break;
  358. case 'r':
  359. case 'R':
  360. if( s[i] == '-' )
  361. {
  362. i++;
  363. HB_COMP_PARAM->supported &= ~HB_COMPFLAG_RT_MACRO;
  364. }
  365. else
  366. HB_COMP_PARAM->supported |= HB_COMPFLAG_RT_MACRO;
  367. break;
  368. case 's':
  369. case 'S':
  370. if( s[i] == '-' )
  371. {
  372. i++;
  373. HB_COMP_PARAM->supported &= ~HB_COMPFLAG_ARRSTR;
  374. }
  375. else
  376. HB_COMP_PARAM->supported |= HB_COMPFLAG_ARRSTR;
  377. break;
  378. case 'o':
  379. case 'O':
  380. if( s[i] == '-' )
  381. {
  382. i++;
  383. HB_COMP_PARAM->supported &= ~HB_COMPFLAG_EXTOPT;
  384. }
  385. else
  386. HB_COMP_PARAM->supported |= HB_COMPFLAG_EXTOPT;
  387. break;
  388. default:
  389. hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'F', HB_COMP_ERR_BADOPTION, s, NULL );
  390. break;
  391. }
  392. }
  393. break;
  394. }
  395. case 'l':
  396. case 'L':
  397. if( *( s + 1 ) == '-' )
  398. HB_COMP_PARAM->fLineNumbers = HB_TRUE;
  399. else
  400. HB_COMP_PARAM->fLineNumbers = HB_FALSE;
  401. break;
  402. case 'm':
  403. case 'M':
  404. if( *( s + 1 ) == '-' )
  405. HB_COMP_PARAM->fSingleModule = HB_FALSE;
  406. else
  407. HB_COMP_PARAM->fSingleModule = HB_TRUE;
  408. break;
  409. case 'n':
  410. case 'N':
  411. HB_COMP_PARAM->fNoStartUp = s[ 1 ] == '1';
  412. switch( s[ 1 ] )
  413. {
  414. case '-':
  415. HB_COMP_PARAM->iStartProc = 0;
  416. break;
  417. case '\0':
  418. case '0':
  419. case '1':
  420. HB_COMP_PARAM->iStartProc = 1;
  421. break;
  422. case '2':
  423. HB_COMP_PARAM->iStartProc = 2;
  424. break;
  425. default:
  426. hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'F', HB_COMP_ERR_BADOPTION, s, NULL );
  427. }
  428. break;
  429. case 'o':
  430. case 'O':
  431. HB_COMP_PARAM->pOutPath = hb_fsFNameSplit( s + 1 );
  432. break;
  433. /* Added for preprocessor needs */
  434. case 'p':
  435. case 'P':
  436. if( s[ 1 ] == '+' && s[ 2 ] == '\0' )
  437. HB_COMP_PARAM->fPPT = HB_TRUE;
  438. else
  439. {
  440. if( HB_COMP_PARAM->pPpoPath )
  441. {
  442. hb_xfree( HB_COMP_PARAM->pPpoPath );
  443. HB_COMP_PARAM->pPpoPath = NULL;
  444. }
  445. if( s[ 1 ] == '-' && s[ 2 ] == '\0' )
  446. HB_COMP_PARAM->fPPO = HB_FALSE;
  447. else
  448. {
  449. if( s[ 1 ] )
  450. HB_COMP_PARAM->pPpoPath = hb_fsFNameSplit( s + 1 );
  451. HB_COMP_PARAM->fPPO = HB_TRUE;
  452. }
  453. }
  454. break;
  455. case 'q':
  456. case 'Q':
  457. switch( *( s + 1 ) )
  458. {
  459. case '2':
  460. HB_COMP_PARAM->fFullQuiet = HB_TRUE;
  461. case '0':
  462. HB_COMP_PARAM->fLogo = HB_FALSE;
  463. default:
  464. HB_COMP_PARAM->fQuiet = HB_TRUE;
  465. }
  466. break;
  467. case 'r':
  468. case 'R':
  469. if( *( s + 1 ) == ':' )
  470. {
  471. int iOverflow;
  472. int iCycles = ( int ) hb_strValInt( s + 2, &iOverflow );
  473. if( !iOverflow && iCycles > 0 )
  474. HB_COMP_PARAM->iMaxTransCycles = iCycles;
  475. }
  476. else
  477. {
  478. /* TODO: Implement this switch */
  479. hb_notSupportedInfo( HB_COMP_PARAM, s );
  480. }
  481. break;
  482. case 's':
  483. case 'S':
  484. switch( *( s + 1 ) )
  485. {
  486. case '\0':
  487. HB_COMP_PARAM->iSyntaxCheckOnly = 1;
  488. break;
  489. case '-':
  490. HB_COMP_PARAM->iSyntaxCheckOnly = 0;
  491. break;
  492. case 'm':
  493. case 'M':
  494. if( s[2] == '\0' )
  495. {
  496. HB_COMP_PARAM->iSyntaxCheckOnly = 2;
  497. break;
  498. }
  499. default:
  500. hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'F', HB_COMP_ERR_BADOPTION, s, NULL );
  501. }
  502. break;
  503. case 't':
  504. case 'T':
  505. /* TODO: Implement this switch */
  506. hb_notSupportedInfo( HB_COMP_PARAM, s );
  507. break;
  508. case 'u':
  509. case 'U':
  510. if( ( s[1] == 'N' || s[1] == 'n' ) &&
  511. ( s[2] == 'D' || s[2] == 'd' ) &&
  512. ( s[3] == 'E' || s[3] == 'e' ) &&
  513. ( s[4] == 'F' || s[4] == 'f' ) && s[5] == ':' )
  514. {
  515. /* NOTE: Ignore these -undef: switches (will be processed
  516. * separately) except -undef:.arch.
  517. */
  518. if( s[6] == '.' &&
  519. ( s[7] == 'A' || s[7] == 'a' ) &&
  520. ( s[8] == 'R' || s[8] == 'r' ) &&
  521. ( s[9] == 'C' || s[9] == 'c' ) &&
  522. ( s[10] == 'H' || s[10] == 'h' ) &&
  523. s[11] == '.' )
  524. {
  525. HB_COMP_PARAM->fNoArchDefs = HB_TRUE;
  526. }
  527. break;
  528. }
  529. /* extended definitions file (-u+<file>) */
  530. if( s[1] == '+' )
  531. {
  532. if( s[2] )
  533. {
  534. if( HB_COMP_PARAM->iStdChExt == 0 )
  535. HB_COMP_PARAM->szStdChExt = ( char ** )
  536. hb_xgrab( sizeof( char * ) );
  537. else
  538. HB_COMP_PARAM->szStdChExt = ( char ** )
  539. hb_xrealloc( HB_COMP_PARAM->szStdChExt,
  540. ( HB_COMP_PARAM->iStdChExt + 1 ) *
  541. sizeof( char * ) );
  542. HB_COMP_PARAM->szStdChExt[ HB_COMP_PARAM->iStdChExt++ ] =
  543. hb_strdup( s + 2 );
  544. }
  545. else
  546. hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'F', HB_COMP_ERR_BADOPTION, s, NULL );
  547. }
  548. else
  549. {
  550. if( HB_COMP_PARAM->szStdCh )
  551. hb_xfree( HB_COMP_PARAM->szStdCh );
  552. HB_COMP_PARAM->szStdCh = hb_strdup( s + 1 );
  553. }
  554. break;
  555. case 'v':
  556. case 'V':
  557. if( *( s + 1 ) == '-' )
  558. HB_COMP_PARAM->fForceMemvars = HB_FALSE;
  559. else
  560. HB_COMP_PARAM->fForceMemvars = HB_TRUE;
  561. break;
  562. case 'w':
  563. case 'W':
  564. HB_COMP_PARAM->iWarnings = 1;
  565. if( s[1] )
  566. { /*there is -w<0,1,2,3> probably */
  567. HB_COMP_PARAM->iWarnings = s[1] - '0';
  568. if( HB_COMP_PARAM->iWarnings < 0 || HB_COMP_PARAM->iWarnings > 3 )
  569. hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'F', HB_COMP_ERR_BADOPTION, s, NULL );
  570. }
  571. break;
  572. case 'x':
  573. case 'X':
  574. {
  575. unsigned int i = 1;
  576. while( s[i] && !HB_ISOPTSEP( s[i] ) &&
  577. i < sizeof( HB_COMP_PARAM->szPrefix ) - 1 )
  578. {
  579. ++i;
  580. }
  581. if( i > 1 )
  582. {
  583. memcpy( HB_COMP_PARAM->szPrefix, s + 1, i - 1 );
  584. HB_COMP_PARAM->szPrefix[ i - 1 ] = '_';
  585. HB_COMP_PARAM->szPrefix[ i ] = '\0';
  586. }
  587. else
  588. {
  589. hb_snprintf( HB_COMP_PARAM->szPrefix,
  590. sizeof( HB_COMP_PARAM->szPrefix ),
  591. "%08lX_", PackDateTime() );
  592. }
  593. break;
  594. }
  595. #ifdef YYDEBUG
  596. case 'y':
  597. case 'Y':
  598. yydebug = HB_TRUE;
  599. break;
  600. #endif
  601. case 'z':
  602. case 'Z':
  603. if( *( s + 1 ) == '-' )
  604. HB_COMP_PARAM->supported |= HB_COMPFLAG_SHORTCUTS;
  605. else
  606. HB_COMP_PARAM->supported &= ~HB_COMPFLAG_SHORTCUTS;
  607. break;
  608. default:
  609. hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'F', HB_COMP_ERR_BADOPTION, s, NULL );
  610. break;
  611. }
  612. }
  613. }
  614. }
  615. void hb_compChkCompilerSwitch( HB_COMP_DECL, int iArg, const char * const Args[] )
  616. {
  617. /* If iArg is passed check the command line options */
  618. if( iArg )
  619. {
  620. int i;
  621. /* Check all switches in command line
  622. They start with an OS_OPT_DELIMITER char
  623. */
  624. for( i = 1; i < iArg && !HB_COMP_PARAM->fExit; i++ )
  625. {
  626. const char * szSwitch = Args[i];
  627. if( !HB_ISOPTSEP( szSwitch[0] ) )
  628. continue;
  629. if( szSwitch[0] == '-' )
  630. {
  631. int j = 1;
  632. char Switch[7];
  633. Switch[0] = '-';
  634. while( szSwitch[j] && !HB_COMP_PARAM->fExit )
  635. {
  636. Switch[1] = szSwitch[j];
  637. if( szSwitch[j + 1] == '-' )
  638. {
  639. Switch[2] = '-';
  640. Switch[3] = '\0';
  641. hb_compChkEnvironVar( HB_COMP_PARAM, Switch );
  642. j += 2;
  643. continue;
  644. }
  645. else
  646. {
  647. switch( Switch[1] )
  648. {
  649. case 'b':
  650. case 'B':
  651. if( ( szSwitch[j + 1] == 'U' || szSwitch[j + 1] == 'u' ) &&
  652. ( szSwitch[j + 2] == 'I' || szSwitch[j + 2] == 'i' ) &&
  653. ( szSwitch[j + 3] == 'L' || szSwitch[j + 3] == 'l' ) &&
  654. ( szSwitch[j + 4] == 'D' || szSwitch[j + 4] == 'd' ) )
  655. {
  656. Switch[2] = 'U';
  657. Switch[3] = 'I';
  658. Switch[4] = 'L';
  659. Switch[5] = 'D';
  660. Switch[6] = '\0';
  661. hb_compChkEnvironVar( HB_COMP_PARAM, Switch );
  662. j += 5;
  663. continue;
  664. }
  665. else if( !szSwitch[j + 1] )
  666. {
  667. Switch[2] = '\0';
  668. hb_compChkEnvironVar( HB_COMP_PARAM, Switch );
  669. j += 1;
  670. continue;
  671. }
  672. break;
  673. case 'c':
  674. case 'C':
  675. if( ( szSwitch[j + 1] == 'R' || szSwitch[j + 1] == 'r' ) &&
  676. ( szSwitch[j + 2] == 'E' || szSwitch[j + 2] == 'e' ) &&
  677. ( szSwitch[j + 3] == 'D' || szSwitch[j + 3] == 'd' ) )
  678. {
  679. Switch[2] = 'R';
  680. Switch[3] = 'E';
  681. Switch[4] = 'D';
  682. Switch[5] = '\0';
  683. j += 4;
  684. if( szSwitch[j] == 'I' || szSwitch[j] == 'i' )
  685. {
  686. j++;
  687. if( szSwitch[j] == 'T' || szSwitch[j] == 't' )
  688. {
  689. j++;
  690. if( szSwitch[j] == 'S' || szSwitch[j] == 's' )
  691. {
  692. j++;
  693. }
  694. }
  695. }
  696. hb_compChkEnvironVar( HB_COMP_PARAM, Switch );
  697. }
  698. else
  699. {
  700. Switch[2] = '\0';
  701. hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'F', HB_COMP_ERR_BADOPTION, Switch, NULL );
  702. }
  703. continue;
  704. case 'd':
  705. case 'D':
  706. szSwitch += ( j - 1 );
  707. hb_compChkEnvironVar( HB_COMP_PARAM, szSwitch );
  708. /* Accept rest as part of #define and continue with next Args[]. */
  709. j = ( int ) strlen( szSwitch );
  710. continue;
  711. case 'e':
  712. case 'E':
  713. if( ( szSwitch[j + 1] == 'S' || szSwitch[j + 1] == 's' ) &&
  714. HB_ISDIGIT( szSwitch[j + 2] ) )
  715. {
  716. Switch[2] = 'S';
  717. Switch[3] = szSwitch[j + 2];
  718. Switch[4] = '\0';
  719. hb_compChkEnvironVar( HB_COMP_PARAM, Switch );
  720. j += 3;
  721. }
  722. else
  723. {
  724. Switch[2] = '\0';
  725. hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'F', HB_COMP_ERR_BADOPTION, Switch, NULL );
  726. }
  727. continue;
  728. case 'g':
  729. case 'G':
  730. if( szSwitch[j + 1] == 'd' || szSwitch[j + 1] == 'D' )
  731. {
  732. szSwitch += ( j - 1 );
  733. hb_compChkEnvironVar( HB_COMP_PARAM, szSwitch );
  734. j = ( int ) strlen( szSwitch );
  735. }
  736. else
  737. {
  738. /* Required argument */
  739. Switch[2] = szSwitch[j + 1];
  740. if( Switch[2] )
  741. {
  742. if( HB_ISDIGIT( szSwitch[j + 2] ) )
  743. {
  744. /* Optional argument */
  745. Switch[3] = szSwitch[j + 2];
  746. Switch[4] = '\0';
  747. j += 3;
  748. }
  749. else
  750. {
  751. /* No optional argument */
  752. Switch[3] = '\0';
  753. j += 2;
  754. }
  755. hb_compChkEnvironVar( HB_COMP_PARAM, Switch );
  756. }
  757. else
  758. hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'F', HB_COMP_ERR_BADOPTION, Switch, NULL );
  759. }
  760. continue;
  761. case 'i':
  762. case 'I':
  763. szSwitch += ( j - 1 );
  764. hb_compChkEnvironVar( HB_COMP_PARAM, szSwitch );
  765. /* Accept rest as IncludePath and continue with next Args[]. */
  766. j = ( int ) strlen( szSwitch );
  767. continue;
  768. case 'j':
  769. case 'J':
  770. szSwitch += ( j - 1 );
  771. hb_compChkEnvironVar( HB_COMP_PARAM, szSwitch );
  772. j = ( int ) strlen( szSwitch );
  773. continue;
  774. case 'k':
  775. case 'K':
  776. szSwitch += ( j - 1 );
  777. hb_compChkEnvironVar( HB_COMP_PARAM, szSwitch );
  778. /* Accept rest as part of #define and continue with next Args[]. */
  779. j = ( int ) strlen( szSwitch );
  780. continue;
  781. case 'n':
  782. case 'N':
  783. /* Required argument */
  784. if( szSwitch[j + 1] )
  785. {
  786. /* Optional argument */
  787. Switch[2] = szSwitch[j + 1];
  788. Switch[3] = '\0';
  789. j += 2;
  790. }
  791. else
  792. {
  793. /* No optional argument */
  794. Switch[2] = '\0';
  795. j += 1;
  796. }
  797. hb_compChkEnvironVar( HB_COMP_PARAM, Switch );
  798. continue;
  799. case 'o':
  800. case 'O':
  801. szSwitch += ( j - 1 );
  802. hb_compChkEnvironVar( HB_COMP_PARAM, szSwitch );
  803. /* Accept rest as OutputPath and continue with next Args[]. */
  804. j = ( int ) strlen( szSwitch );
  805. continue;
  806. case 'p':
  807. case 'P':
  808. if( szSwitch[j + 1] )
  809. {
  810. szSwitch += ( j - 1 );
  811. hb_compChkEnvironVar( HB_COMP_PARAM, szSwitch );
  812. /* Accept rest as PPOPath and continue with next Args[]. */
  813. j += ( int ) strlen( szSwitch ) - 1;
  814. }
  815. else
  816. {
  817. Switch[2] = '\0';
  818. hb_compChkEnvironVar( HB_COMP_PARAM, Switch );
  819. j++;
  820. }
  821. continue;
  822. case 'q':
  823. case 'Q':
  824. if( HB_ISDIGIT( szSwitch[j + 1] ) )
  825. {
  826. Switch[2] = szSwitch[j + 1];
  827. Switch[3] = '\0';
  828. hb_compChkEnvironVar( HB_COMP_PARAM, Switch );
  829. j += 2;
  830. continue;
  831. }
  832. else
  833. {
  834. Switch[2] = '\0';
  835. hb_compChkEnvironVar( HB_COMP_PARAM, Switch );
  836. }
  837. break;
  838. case 'r':
  839. case 'R':
  840. hb_compChkEnvironVar( HB_COMP_PARAM, szSwitch );
  841. j = ( int ) strlen( szSwitch ) - 1;
  842. break;
  843. case 's':
  844. case 'S':
  845. ++j;
  846. Switch[2] = Switch[3] = Switch[4] = '\0';
  847. if( szSwitch[j] == 'm' || szSwitch[j] == 'M' )
  848. {
  849. Switch[2] = szSwitch[j++];
  850. if( HB_ISDIGIT( szSwitch[j] ) || szSwitch[j] == '-' )
  851. Switch[3] = szSwitch[j++];
  852. }
  853. hb_compChkEnvironVar( HB_COMP_PARAM, Switch );
  854. continue;
  855. case 'u':
  856. case 'U':
  857. szSwitch += ( j - 1 );
  858. hb_compChkEnvironVar( HB_COMP_PARAM, szSwitch );
  859. /* Accept rest as part of .ch Path or "undef:<id>" and continue with next Args[]. */
  860. j = ( int ) strlen( szSwitch );
  861. continue;
  862. case 'w':
  863. case 'W':
  864. if( HB_ISDIGIT( szSwitch[j + 1] ) )
  865. {
  866. Switch[2] = szSwitch[j + 1];
  867. Switch[3] = '\0';
  868. hb_compChkEnvironVar( HB_COMP_PARAM, Switch );
  869. j += 2;
  870. continue;
  871. }
  872. else
  873. {
  874. Switch[2] = '\0';
  875. hb_compChkEnvironVar( HB_COMP_PARAM, Switch );
  876. }
  877. break;
  878. case 'x':
  879. case 'X':
  880. szSwitch += ( j - 1 );
  881. hb_compChkEnvironVar( HB_COMP_PARAM, szSwitch );
  882. /* Accept rest as INIT Symbol and continue with next Args[]. */
  883. j = ( int ) strlen( szSwitch );
  884. continue;
  885. case '-':
  886. {
  887. int l = ++j;
  888. while( szSwitch[j] && !HB_ISOPTSEP( szSwitch[j] ) )
  889. j++;
  890. if( szSwitch[l-1] == '-' && j-l == 7 &&
  891. memcmp( &szSwitch[l], "version", 7 ) == 0 )
  892. {
  893. HB_COMP_PARAM->fLogo = HB_TRUE;
  894. HB_COMP_PARAM->fQuiet = HB_TRUE;
  895. }
  896. else if( szSwitch[l-1] == '-' && j-l == 4 &&
  897. memcmp( &szSwitch[l], "help", 4 ) == 0 )
  898. {
  899. HB_COMP_PARAM->fLogo = HB_TRUE;
  900. HB_COMP_PARAM->fQuiet = HB_FALSE;
  901. HB_COMP_PARAM->fExit = HB_FALSE;
  902. }
  903. else
  904. hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'F', HB_COMP_ERR_BADOPTION, &szSwitch[l], NULL );
  905. if( szSwitch[j] )
  906. ++j;
  907. continue;
  908. }
  909. default:
  910. Switch[2] = '\0';
  911. hb_compChkEnvironVar( HB_COMP_PARAM, Switch );
  912. }
  913. }
  914. j++;
  915. }
  916. continue;
  917. }
  918. while( !HB_COMP_PARAM->fExit )
  919. {
  920. int j = 1;
  921. const char *szSwitch1 = szSwitch + j; /* hack to avoid what is seems a bug in 'Apple clang version 2.1 (tags/Apple/clang-163.7.1) (based on LLVM 3.0svn)' / XCode 4.1 [vszakats] */
  922. while( *szSwitch1 && !HB_ISOPTSEP( *szSwitch1 ) )
  923. {
  924. j++;
  925. szSwitch1++;
  926. }
  927. if( szSwitch[j] == '/' )
  928. {
  929. char * szTmp = hb_strndup( szSwitch, j );
  930. hb_compChkEnvironVar( HB_COMP_PARAM, szTmp );
  931. hb_xfree( szTmp );
  932. szSwitch += j;
  933. }
  934. else
  935. {
  936. hb_compChkEnvironVar( HB_COMP_PARAM, szSwitch );
  937. break;
  938. }
  939. }
  940. }
  941. }
  942. else
  943. /* Chech the environment variables */
  944. {
  945. /* NOTE: CLIPPERCMD enviroment variable
  946. is overriden if HARBOURCMD exists
  947. */
  948. char *szStrEnv = hb_getenv( "HARBOURCMD" );
  949. if( !szStrEnv || szStrEnv[0] == '\0' )
  950. {
  951. if( szStrEnv )
  952. hb_xfree( szStrEnv );
  953. szStrEnv = hb_getenv( "CLIPPERCMD" );
  954. }
  955. if( szStrEnv )
  956. {
  957. char *szSwitch, *szPtr;
  958. szPtr = szStrEnv;
  959. while( *szPtr && !HB_COMP_PARAM->fExit )
  960. {
  961. while( *szPtr == ' ' )
  962. ++szPtr;
  963. szSwitch = szPtr;
  964. if( *szSwitch )
  965. {
  966. while( *++szPtr )
  967. {
  968. if( *szPtr == ' ' )
  969. {
  970. *szPtr++ = '\0';
  971. break;
  972. }
  973. }
  974. hb_compChkEnvironVar( HB_COMP_PARAM, szSwitch );
  975. }
  976. }
  977. hb_xfree( szStrEnv );
  978. }
  979. }
  980. }
  981. void hb_compChkPaths( HB_COMP_DECL )
  982. {
  983. char *szInclude = hb_getenv( "INCLUDE" );
  984. if( szInclude )
  985. {
  986. if( szInclude[0] != '\0' )
  987. hb_pp_addSearchPath( HB_COMP_PARAM->pLex->pPP, szInclude, HB_FALSE );
  988. hb_xfree( szInclude );
  989. }
  990. }
  991. static void hb_compChkDefineSwitch( HB_COMP_DECL, const char *pszSwitch )
  992. {
  993. if( pszSwitch && HB_ISOPTSEP( pszSwitch[0] ) )
  994. {
  995. if( pszSwitch[1] == 'd' || pszSwitch[1] == 'D' )
  996. {
  997. if( pszSwitch[2] )
  998. {
  999. char *szDefText = hb_strdup( pszSwitch + 2 ), *szAssign;
  1000. szAssign = strchr( szDefText, '=' );
  1001. if( szAssign )
  1002. *szAssign++ = '\0';
  1003. hb_pp_addDefine( HB_COMP_PARAM->pLex->pPP, szDefText, szAssign );
  1004. hb_xfree( szDefText );
  1005. }
  1006. }
  1007. else if( ( pszSwitch[1] == 'U' || pszSwitch[1] == 'u' ) &&
  1008. ( pszSwitch[2] == 'N' || pszSwitch[2] == 'n' ) &&
  1009. ( pszSwitch[3] == 'D' || pszSwitch[3] == 'd' ) &&
  1010. ( pszSwitch[4] == 'E' || pszSwitch[4] == 'e' ) &&
  1011. ( pszSwitch[5] == 'F' || pszSwitch[5] == 'f' ) &&
  1012. pszSwitch[6] == ':' )
  1013. {
  1014. char *szDefText = hb_strdup( pszSwitch + 7 );
  1015. unsigned int i = 0;
  1016. while( szDefText[i] && !HB_ISOPTSEP( szDefText[i] ) )
  1017. {
  1018. i++;
  1019. }
  1020. szDefText[i] = '\0';
  1021. if( szDefText[0] )
  1022. {
  1023. if( hb_stricmp( szDefText, ".ARCH." ) == 0 )
  1024. hb_pp_delDefine( HB_COMP_PARAM->pLex->pPP, szDefText );
  1025. }
  1026. hb_xfree( szDefText );
  1027. }
  1028. }
  1029. }
  1030. void hb_compChkDefines( HB_COMP_DECL, int iArg, const char * const Args[] )
  1031. {
  1032. /* Check the environment variables */
  1033. {
  1034. /* NOTE: CLIPPERCMD enviroment variable is overriden
  1035. if HARBOURCMD exists */
  1036. char *szStrEnv = hb_getenv( "HARBOURCMD" );
  1037. if( !szStrEnv || szStrEnv[0] == '\0' )
  1038. {
  1039. if( szStrEnv )
  1040. hb_xfree( szStrEnv );
  1041. szStrEnv = hb_getenv( "CLIPPERCMD" );
  1042. }
  1043. if( szStrEnv )
  1044. {
  1045. char *szSwitch, *szPtr;
  1046. szPtr = szStrEnv;
  1047. while( *szPtr && !HB_COMP_PARAM->fExit )
  1048. {
  1049. while( *szPtr == ' ' )
  1050. ++szPtr;
  1051. szSwitch = szPtr;
  1052. if( *szSwitch )
  1053. {
  1054. while( *++szPtr )
  1055. {
  1056. if( *szPtr == ' ' )
  1057. {
  1058. *szPtr++ = '\0';
  1059. break;
  1060. }
  1061. }
  1062. hb_compChkDefineSwitch( HB_COMP_PARAM, szSwitch );
  1063. }
  1064. }
  1065. hb_xfree( szStrEnv );
  1066. }
  1067. }
  1068. /* Check the command line options */
  1069. {
  1070. int i;
  1071. /* Check all switches in command line They start with an OS_OPT_DELIMITER
  1072. char */
  1073. for( i = 1; i < iArg; i++ )
  1074. hb_compChkDefineSwitch( HB_COMP_PARAM, Args[i] );
  1075. }
  1076. }