dirparse.pas 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. This unit implements some support functions for the parsing of directives
  4. and option strings
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit dirparse;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. globtype;
  23. function UpdateTargetSwitchStr(s: string; var a: ttargetswitches; global: boolean): boolean;
  24. implementation
  25. uses
  26. globals,
  27. cutils,
  28. symtable;
  29. function UpdateTargetSwitchStr(s: string; var a: ttargetswitches; global: boolean): boolean;
  30. var
  31. tok,
  32. value : string;
  33. setstr: string[2];
  34. equalspos: longint;
  35. doset,
  36. gotvalue,
  37. found : boolean;
  38. opt : ttargetswitch;
  39. begin
  40. result:=true;
  41. repeat
  42. tok:=GetToken(s,',');
  43. if tok='' then
  44. break;
  45. setstr:=upper(copy(tok,length(tok),1));
  46. if setstr='-' then
  47. begin
  48. setlength(tok,length(tok)-1);
  49. doset:=false;
  50. end
  51. else
  52. doset:=true;
  53. { value specified? }
  54. gotvalue:=false;
  55. equalspos:=pos('=',tok);
  56. if equalspos<>0 then
  57. begin
  58. value:=copy(tok,equalspos+1,length(tok));
  59. delete(tok,equalspos,length(tok));
  60. gotvalue:=true;
  61. end;
  62. found:=false;
  63. uppervar(tok);
  64. for opt:=low(ttargetswitch) to high(ttargetswitch) do
  65. begin
  66. if TargetSwitchStr[opt].name=tok then
  67. begin
  68. found:=true;
  69. break;
  70. end;
  71. end;
  72. if found then
  73. begin
  74. if not global and
  75. TargetSwitchStr[opt].isglobal then
  76. result:=false
  77. else if not TargetSwitchStr[opt].hasvalue then
  78. begin
  79. if gotvalue then
  80. result:=false;
  81. if (TargetSwitchStr[opt].define<>'') and (doset xor (opt in a)) then
  82. if doset then
  83. def_system_macro(TargetSwitchStr[opt].define)
  84. else
  85. undef_system_macro(TargetSwitchStr[opt].define);
  86. if doset then
  87. include(a,opt)
  88. else
  89. exclude(a,opt)
  90. end
  91. else
  92. begin
  93. if not gotvalue or
  94. not doset then
  95. result:=false
  96. else
  97. begin
  98. case opt of
  99. ts_auto_getter_prefix:
  100. prop_auto_getter_prefix:=value;
  101. ts_auto_setter_predix:
  102. prop_auto_setter_prefix:=value;
  103. else
  104. begin
  105. writeln('Internalerror 2012053001');
  106. halt(1);
  107. end;
  108. end;
  109. end;
  110. end;
  111. end
  112. else
  113. result:=false;
  114. until false;
  115. end;
  116. end.