acl.yy.cpp 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027
  1. /** BEGIN COPYRIGHT BLOCK
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * All rights reserved.
  37. * END COPYRIGHT BLOCK **/
  38. /* A lexical scanner generated by flex */
  39. #define FLEX_SCANNER
  40. #define ACL_FLEX_MAJOR_VERSION 2
  41. #define ACL_FLEX_MINOR_VERSION 5
  42. #include <stdio.h>
  43. /* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */
  44. #ifdef c_plusplus
  45. #ifndef __cplusplus
  46. #define __cplusplus
  47. #endif
  48. #endif
  49. #ifdef __cplusplus
  50. #include <stdlib.h>
  51. /* Use prototypes in function declarations. */
  52. #define ACL_USE_PROTOS
  53. /* The "const" storage-class-modifier is valid. */
  54. #define ACL_USE_CONST
  55. #else /* ! __cplusplus */
  56. #if __STDC__
  57. #define ACL_USE_PROTOS
  58. #define ACL_USE_CONST
  59. #endif /* __STDC__ */
  60. #endif /* ! __cplusplus */
  61. #ifdef __TURBOC__
  62. #pragma warn -rch
  63. #pragma warn -use
  64. #include <io.h>
  65. #include <stdlib.h>
  66. #define ACL_USE_CONST
  67. #define ACL_USE_PROTOS
  68. #endif
  69. #ifdef ACL_USE_CONST
  70. #define aclconst const
  71. #else
  72. #define aclconst
  73. #endif
  74. #ifdef ACL_USE_PROTOS
  75. #define ACL_PROTO(proto) proto
  76. #else
  77. #define ACL_PROTO(proto) ()
  78. #endif
  79. /* Returned upon end-of-file. */
  80. #define ACL_NULL 0
  81. /* Promotes a possibly negative, possibly signed char to an unsigned
  82. * integer for use as an array index. If the signed char is negative,
  83. * we want to instead treat it as an 8-bit unsigned char, hence the
  84. * double cast.
  85. */
  86. #define ACL_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
  87. /* Enter a start condition. This macro really ought to take a parameter,
  88. * but we do it the disgusting crufty way forced on us by the ()-less
  89. * definition of BEGIN.
  90. */
  91. #define BEGIN acl_start = 1 + 2 *
  92. /* Translate the current start state into a value that can be later handed
  93. * to BEGIN to return to the state. The ACLSTATE alias is for lex
  94. * compatibility.
  95. */
  96. #define ACL_START ((acl_start - 1) / 2)
  97. #define ACLSTATE ACL_START
  98. /* Action number for EOF rule of a given start state. */
  99. #define ACL_STATE_EOF(state) (ACL_END_OF_BUFFER + state + 1)
  100. /* Special action meaning "start processing a new file". */
  101. #define ACL_NEW_FILE aclrestart( aclin )
  102. #define ACL_END_OF_BUFFER_CHAR 0
  103. /* Size of default input buffer. */
  104. #define ACL_BUF_SIZE 16384
  105. typedef struct acl_buffer_state *ACL_BUFFER_STATE;
  106. extern int aclleng;
  107. extern FILE *aclin, *aclout;
  108. #define EOB_ACT_CONTINUE_SCAN 0
  109. #define EOB_ACT_END_OF_FILE 1
  110. #define EOB_ACT_LAST_MATCH 2
  111. /* The funky do-while in the following #define is used to turn the definition
  112. * int a single C statement (which needs a semi-colon terminator). This
  113. * avoids problems with code like:
  114. *
  115. * if ( condition_holds )
  116. * aclless( 5 );
  117. * else
  118. * do_something_else();
  119. *
  120. * Prior to using the do-while the compiler would get upset at the
  121. * "else" because it interpreted the "if" statement as being all
  122. * done when it reached the ';' after the aclless() call.
  123. */
  124. /* Return all but the first 'n' matched characters back to the input stream. */
  125. #define aclless(n) \
  126. do \
  127. { \
  128. /* Undo effects of setting up acltext. */ \
  129. *acl_cp = acl_hold_char; \
  130. ACL_RESTORE_ACL_MORE_OFFSET \
  131. acl_c_buf_p = acl_cp = acl_bp + n - ACL_MORE_ADJ; \
  132. ACL_DO_BEFORE_ACTION; /* set up acltext again */ \
  133. } \
  134. while ( 0 )
  135. #define unput(c) aclunput( c, acltext_ptr )
  136. /* The following is because we cannot portably get our hands on size_t
  137. * (without autoconf's help, which isn't available because we want
  138. * flex-generated scanners to compile on their own).
  139. */
  140. typedef unsigned int acl_size_t;
  141. struct acl_buffer_state
  142. {
  143. FILE *acl_input_file;
  144. char *acl_ch_buf; /* input buffer */
  145. char *acl_buf_pos; /* current position in input buffer */
  146. /* Size of input buffer in bytes, not including room for EOB
  147. * characters.
  148. */
  149. acl_size_t acl_buf_size;
  150. /* Number of characters read into acl_ch_buf, not including EOB
  151. * characters.
  152. */
  153. int acl_n_chars;
  154. /* Whether we "own" the buffer - i.e., we know we created it,
  155. * and can PERM_REALLOC() it to grow it, and should PERM_FREE() it to
  156. * delete it.
  157. */
  158. int acl_is_our_buffer;
  159. /* Whether this is an "interactive" input source; if so, and
  160. * if we're using stdio for input, then we want to use getc()
  161. * instead of fread(), to make sure we stop fetching input after
  162. * each newline.
  163. */
  164. int acl_is_interactive;
  165. /* Whether we're considered to be at the beginning of a line.
  166. * If so, '^' rules will be active on the next match, otherwise
  167. * not.
  168. */
  169. int acl_at_bol;
  170. /* Whether to try to fill the input buffer when we reach the
  171. * end of it.
  172. */
  173. int acl_fill_buffer;
  174. int acl_buffer_status;
  175. #define ACL_BUFFER_NEW 0
  176. #define ACL_BUFFER_NORMAL 1
  177. /* When an EOF's been seen but there's still some text to process
  178. * then we mark the buffer as ACL_EOF_PENDING, to indicate that we
  179. * shouldn't try reading from the input source any more. We might
  180. * still have a bunch of tokens to match, though, because of
  181. * possible backing-up.
  182. *
  183. * When we actually see the EOF, we change the status to "new"
  184. * (via aclrestart()), so that the user can continue scanning by
  185. * just pointing aclin at a new input file.
  186. */
  187. #define ACL_BUFFER_EOF_PENDING 2
  188. };
  189. static ACL_BUFFER_STATE acl_current_buffer = 0;
  190. /* We provide macros for accessing buffer states in case in the
  191. * future we want to put the buffer states in a more general
  192. * "scanner state".
  193. */
  194. #define ACL_CURRENT_BUFFER acl_current_buffer
  195. /* acl_hold_char holds the character lost when acltext is formed. */
  196. static char acl_hold_char;
  197. static int acl_n_chars; /* number of characters read into acl_ch_buf */
  198. int aclleng;
  199. /* Points to current character in buffer. */
  200. static char *acl_c_buf_p = (char *) 0;
  201. static int acl_init = 1; /* whether we need to initialize */
  202. static int acl_start = 0; /* start state number */
  203. /* Flag which is used to allow aclwrap()'s to do buffer switches
  204. * instead of setting up a fresh aclin. A bit of a hack ...
  205. */
  206. static int acl_did_buffer_switch_on_eof;
  207. void aclrestart ACL_PROTO(( FILE *input_file ));
  208. void acl_switch_to_buffer ACL_PROTO(( ACL_BUFFER_STATE new_buffer ));
  209. void acl_load_buffer_state ACL_PROTO(( void ));
  210. ACL_BUFFER_STATE acl_create_buffer ACL_PROTO(( FILE *file, int size ));
  211. void acl_delete_buffer ACL_PROTO(( ACL_BUFFER_STATE b ));
  212. void acl_init_buffer ACL_PROTO(( ACL_BUFFER_STATE b, FILE *file ));
  213. void acl_flush_buffer ACL_PROTO(( ACL_BUFFER_STATE b ));
  214. #define ACL_FLUSH_BUFFER acl_flush_buffer( acl_current_buffer )
  215. ACL_BUFFER_STATE acl_scan_buffer ACL_PROTO(( char *base, acl_size_t size ));
  216. ACL_BUFFER_STATE acl_scan_string ACL_PROTO(( aclconst char *str ));
  217. ACL_BUFFER_STATE acl_scan_bytes ACL_PROTO(( aclconst char *bytes, int len ));
  218. static void *ACL_FLEX_ALLOC ACL_PROTO(( acl_size_t ));
  219. static void *ACL_FLEX_REALLOC ACL_PROTO(( void *, acl_size_t ));
  220. static void ACL_FLEX_FREE ACL_PROTO(( void * ));
  221. #define acl_new_buffer acl_create_buffer
  222. #define acl_set_interactive(is_interactive) \
  223. { \
  224. if ( ! acl_current_buffer ) \
  225. acl_current_buffer = acl_create_buffer( aclin, ACL_BUF_SIZE ); \
  226. acl_current_buffer->acl_is_interactive = is_interactive; \
  227. }
  228. #define acl_set_bol(at_bol) \
  229. { \
  230. if ( ! acl_current_buffer ) \
  231. acl_current_buffer = acl_create_buffer( aclin, ACL_BUF_SIZE ); \
  232. acl_current_buffer->acl_at_bol = at_bol; \
  233. }
  234. #define ACL_AT_BOL() (acl_current_buffer->acl_at_bol)
  235. typedef unsigned char ACL_CHAR;
  236. FILE *aclin = (FILE *) 0, *aclout = (FILE *) 0;
  237. typedef int acl_state_type;
  238. extern char *acltext;
  239. #define acltext_ptr acltext
  240. static acl_state_type acl_get_previous_state ACL_PROTO(( void ));
  241. static acl_state_type acl_try_NUL_trans ACL_PROTO(( acl_state_type current_state ));
  242. static int acl_get_next_buffer ACL_PROTO(( void ));
  243. static void acl_fatal_error ACL_PROTO(( aclconst char msg[] ));
  244. /* Done after the current pattern has been matched and before the
  245. * corresponding action - sets up acltext.
  246. */
  247. #define ACL_DO_BEFORE_ACTION \
  248. acltext_ptr = acl_bp; \
  249. aclleng = (int) (acl_cp - acl_bp); \
  250. acl_hold_char = *acl_cp; \
  251. *acl_cp = '\0'; \
  252. acl_c_buf_p = acl_cp;
  253. #define ACL_NUM_RULES 30
  254. #define ACL_END_OF_BUFFER 31
  255. static aclconst short int acl_accept[104] =
  256. { 0,
  257. 0, 0, 31, 30, 2, 1, 30, 30, 3, 28,
  258. 29, 25, 22, 24, 29, 29, 29, 29, 29, 29,
  259. 29, 29, 29, 2, 1, 27, 0, 4, 3, 29,
  260. 26, 23, 29, 29, 29, 29, 9, 29, 29, 29,
  261. 14, 29, 21, 29, 29, 29, 29, 6, 29, 29,
  262. 20, 29, 29, 29, 29, 29, 19, 29, 29, 29,
  263. 29, 29, 29, 29, 29, 29, 13, 29, 29, 29,
  264. 18, 29, 7, 29, 29, 29, 29, 29, 29, 29,
  265. 29, 8, 29, 29, 29, 29, 29, 29, 29, 29,
  266. 11, 12, 15, 29, 17, 5, 29, 16, 29, 29,
  267. 29, 10, 0
  268. } ;
  269. static aclconst int acl_ec[256] =
  270. { 0,
  271. 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
  272. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  273. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  274. 1, 2, 4, 5, 6, 1, 1, 1, 1, 7,
  275. 7, 8, 1, 7, 8, 8, 1, 8, 8, 8,
  276. 8, 8, 8, 8, 8, 8, 8, 1, 7, 9,
  277. 10, 11, 1, 1, 12, 13, 14, 15, 16, 17,
  278. 8, 18, 19, 8, 8, 20, 21, 22, 23, 8,
  279. 8, 24, 25, 26, 27, 28, 29, 8, 30, 8,
  280. 1, 1, 1, 1, 8, 1, 12, 13, 14, 15,
  281. 16, 17, 8, 18, 19, 8, 8, 20, 21, 22,
  282. 23, 8, 8, 24, 25, 26, 27, 28, 29, 8,
  283. 30, 8, 7, 1, 7, 1, 1, 1, 1, 1,
  284. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  285. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  286. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  287. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  288. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  289. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  290. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  291. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  292. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  293. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  294. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  295. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  296. 1, 1, 1, 1, 1
  297. } ;
  298. static aclconst int acl_meta[31] =
  299. { 0,
  300. 1, 1, 2, 1, 1, 1, 1, 3, 1, 1,
  301. 1, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  302. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
  303. } ;
  304. static aclconst short int acl_base[108] =
  305. { 0,
  306. 0, 0, 118, 119, 115, 0, 106, 28, 0, 119,
  307. 0, 105, 119, 104, 21, 90, 96, 89, 87, 85,
  308. 92, 91, 87, 103, 0, 119, 33, 119, 0, 0,
  309. 119, 119, 79, 83, 17, 87, 0, 75, 78, 22,
  310. 81, 72, 0, 73, 72, 69, 71, 0, 70, 80,
  311. 0, 73, 64, 77, 58, 71, 0, 65, 60, 66,
  312. 63, 53, 51, 64, 63, 51, 0, 53, 57, 56,
  313. 0, 47, 0, 48, 50, 49, 50, 50, 46, 44,
  314. 40, 0, 39, 38, 37, 36, 49, 38, 43, 39,
  315. 0, 0, 0, 36, 0, 0, 36, 0, 33, 16,
  316. 24, 0, 119, 48, 51, 54, 29
  317. } ;
  318. static aclconst short int acl_def[108] =
  319. { 0,
  320. 103, 1, 103, 103, 103, 104, 103, 105, 106, 103,
  321. 107, 103, 103, 103, 107, 107, 107, 107, 107, 107,
  322. 107, 107, 107, 103, 104, 103, 105, 103, 106, 107,
  323. 103, 103, 107, 107, 107, 107, 107, 107, 107, 107,
  324. 107, 107, 107, 107, 107, 107, 107, 107, 107, 107,
  325. 107, 107, 107, 107, 107, 107, 107, 107, 107, 107,
  326. 107, 107, 107, 107, 107, 107, 107, 107, 107, 107,
  327. 107, 107, 107, 107, 107, 107, 107, 107, 107, 107,
  328. 107, 107, 107, 107, 107, 107, 107, 107, 107, 107,
  329. 107, 107, 107, 107, 107, 107, 107, 107, 107, 107,
  330. 107, 107, 0, 103, 103, 103, 103
  331. } ;
  332. static aclconst short int acl_nxt[150] =
  333. { 0,
  334. 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
  335. 14, 15, 11, 16, 17, 11, 11, 11, 18, 11,
  336. 11, 19, 20, 11, 11, 21, 11, 22, 23, 11,
  337. 28, 30, 28, 33, 34, 28, 49, 28, 54, 102,
  338. 35, 101, 36, 55, 100, 50, 37, 38, 25, 99,
  339. 25, 27, 27, 27, 29, 98, 29, 97, 96, 95,
  340. 94, 93, 92, 91, 90, 89, 88, 87, 86, 85,
  341. 84, 83, 82, 81, 80, 79, 78, 77, 76, 75,
  342. 74, 73, 72, 71, 70, 69, 68, 67, 66, 65,
  343. 64, 63, 62, 61, 60, 59, 58, 57, 56, 53,
  344. 52, 51, 48, 47, 24, 46, 45, 44, 43, 42,
  345. 41, 40, 39, 32, 31, 26, 24, 103, 3, 103,
  346. 103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
  347. 103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
  348. 103, 103, 103, 103, 103, 103, 103, 103, 103
  349. } ;
  350. static aclconst short int acl_chk[150] =
  351. { 0,
  352. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  353. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  354. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  355. 8, 107, 8, 15, 15, 27, 35, 27, 40, 101,
  356. 15, 100, 15, 40, 99, 35, 15, 15, 104, 97,
  357. 104, 105, 105, 105, 106, 94, 106, 90, 89, 88,
  358. 87, 86, 85, 84, 83, 81, 80, 79, 78, 77,
  359. 76, 75, 74, 72, 70, 69, 68, 66, 65, 64,
  360. 63, 62, 61, 60, 59, 58, 56, 55, 54, 53,
  361. 52, 50, 49, 47, 46, 45, 44, 42, 41, 39,
  362. 38, 36, 34, 33, 24, 23, 22, 21, 20, 19,
  363. 18, 17, 16, 14, 12, 7, 5, 3, 103, 103,
  364. 103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
  365. 103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
  366. 103, 103, 103, 103, 103, 103, 103, 103, 103
  367. } ;
  368. static acl_state_type acl_last_accepting_state;
  369. static char *acl_last_accepting_cpos;
  370. /* The intent behind this definition is that it'll catch
  371. * any uses of REJECT which flex missed.
  372. */
  373. #define REJECT reject_used_but_not_detected
  374. #define aclmore() aclmore_used_but_not_detected
  375. #define ACL_MORE_ADJ 0
  376. #define ACL_RESTORE_ACL_MORE_OFFSET
  377. char *acltext;
  378. #line 1 "aclscan.l"
  379. #define INITIAL 0
  380. /*
  381. * Lexical analyzer for ACL
  382. */
  383. #line 6 "aclscan.l"
  384. #include "acl.tab.h" /* token codes */
  385. #include <base/file.h>
  386. #include <libaccess/acl.h>
  387. #include <libaccess/nserror.h>
  388. #include "aclpriv.h"
  389. #include <string.h>
  390. #include <stdio.h>
  391. #include <ctype.h>
  392. #include <libaccess/aclerror.h>
  393. #ifdef XP_WIN32
  394. #include <io.h>
  395. #endif
  396. #include "parse.h"
  397. #include "aclscan.h"
  398. static int acl_scanner_input(char *buffer, int max_size);
  399. #define ACL_NEVER_INTERACTIVE 1
  400. #undef ACL_INPUT
  401. #define ACL_INPUT(buf, result, max) (result = acl_scanner_input(buf, max))
  402. static int acl_lineno;
  403. static int acl_tokenpos;
  404. static char acl_filename[500];
  405. static NSErr_t *acl_errp;
  406. static int acl_use_buffer;
  407. static char *acl_buffer;
  408. static int acl_buffer_length;
  409. static int acl_buffer_offset;
  410. static char *last_string;
  411. static SYS_FILE acl_prfd;
  412. #line 466 "acl.yy.cpp"
  413. /* Macros after this point can all be overridden by user definitions in
  414. * section 1.
  415. */
  416. #ifndef ACL_SKIP_ACLWRAP
  417. #ifdef __cplusplus
  418. extern "C" int aclwrap ACL_PROTO(( void ));
  419. #else
  420. extern int aclwrap ACL_PROTO(( void ));
  421. #endif
  422. #endif
  423. #ifndef ACL_NO_UNPUT
  424. static void aclunput ACL_PROTO(( int c, char *buf_ptr ));
  425. #endif
  426. #ifndef acltext_ptr
  427. static void acl_flex_strncpy ACL_PROTO(( char *, aclconst char *, int ));
  428. #endif
  429. #ifdef ACL_NEED_STRLEN
  430. static int acl_flex_strlen ACL_PROTO(( aclconst char * ));
  431. #endif
  432. #ifndef ACL_NO_INPUT
  433. #ifdef __cplusplus
  434. static int aclinput ACL_PROTO(( void ));
  435. #else
  436. static int input ACL_PROTO(( void ));
  437. #endif
  438. #endif
  439. #if ACL_STACK_USED
  440. static int acl_start_stack_ptr = 0;
  441. static int acl_start_stack_depth = 0;
  442. static int *acl_start_stack = 0;
  443. #ifndef ACL_NO_PUSH_STATE
  444. static void acl_push_state ACL_PROTO(( int new_state ));
  445. #endif
  446. #ifndef ACL_NO_POP_STATE
  447. static void acl_pop_state ACL_PROTO(( void ));
  448. #endif
  449. #ifndef ACL_NO_TOP_STATE
  450. static int acl_top_state ACL_PROTO(( void ));
  451. #endif
  452. #else
  453. #define ACL_NO_PUSH_STATE 1
  454. #define ACL_NO_POP_STATE 1
  455. #define ACL_NO_TOP_STATE 1
  456. #endif
  457. #ifdef ACL_MALLOC_DECL
  458. ACL_MALLOC_DECL
  459. #else
  460. #if __STDC__
  461. #ifndef __cplusplus
  462. #include <stdlib.h>
  463. #endif
  464. #else
  465. /* Just try to get by without declaring the routines. This will fail
  466. * miserably on non-ANSI systems for which sizeof(size_t) != sizeof(int)
  467. * or sizeof(void*) != sizeof(int).
  468. */
  469. #endif
  470. #endif
  471. /* Amount of stuff to slurp up with each read. */
  472. #ifndef ACL_READ_BUF_SIZE
  473. #define ACL_READ_BUF_SIZE 8192
  474. #endif
  475. /* Copy whatever the last rule matched to the standard output. */
  476. #ifndef ECHO
  477. /* This used to be an fputs(), but since the string might contain NUL's,
  478. * we now use fwrite().
  479. */
  480. #define ECHO (void) fwrite( acltext, aclleng, 1, aclout )
  481. #endif
  482. /* Gets input and stuffs it into "buf". number of characters read, or ACL_NULL,
  483. * is returned in "result".
  484. */
  485. #ifndef ACL_INPUT
  486. #define ACL_INPUT(buf,result,max_size) \
  487. if ( acl_current_buffer->acl_is_interactive ) \
  488. { \
  489. int c = '*', n; \
  490. for ( n = 0; n < max_size && \
  491. (c = getc( aclin )) != EOF && c != '\n'; ++n ) \
  492. buf[n] = (char) c; \
  493. if ( c == '\n' ) \
  494. buf[n++] = (char) c; \
  495. if ( c == EOF && ferror( aclin ) ) \
  496. ACL_FATAL_ERROR( "input in flex scanner failed" ); \
  497. result = n; \
  498. } \
  499. else if ( ((result = fread( buf, 1, max_size, aclin )) == 0) \
  500. && ferror( aclin ) ) \
  501. ACL_FATAL_ERROR( "input in flex scanner failed" );
  502. #endif
  503. /* No semi-colon after return; correct usage is to write "aclterminate();" -
  504. * we don't want an extra ';' after the "return" because that will cause
  505. * some compilers to complain about unreachable statements.
  506. */
  507. #ifndef aclterminate
  508. #define aclterminate() return ACL_NULL
  509. #endif
  510. /* Number of entries by which start-condition stack grows. */
  511. #ifndef ACL_START_STACK_INCR
  512. #define ACL_START_STACK_INCR 25
  513. #endif
  514. /* Report a fatal error. */
  515. #ifndef ACL_FATAL_ERROR
  516. #define ACL_FATAL_ERROR(msg) acl_fatal_error( msg )
  517. #endif
  518. /* Default declaration of generated scanner - a define so the user can
  519. * easily add parameters.
  520. */
  521. #ifndef ACL_DECL
  522. #define ACL_DECL int acllex ACL_PROTO(( void ))
  523. #endif
  524. /* Code executed at the beginning of each rule, after acltext and aclleng
  525. * have been set up.
  526. */
  527. #ifndef ACL_USER_ACTION
  528. #define ACL_USER_ACTION
  529. #endif
  530. /* Code executed at the end of each rule. */
  531. #ifndef ACL_BREAK
  532. #define ACL_BREAK break;
  533. #endif
  534. #define ACL_RULE_SETUP \
  535. ACL_USER_ACTION
  536. ACL_DECL
  537. {
  538. register acl_state_type acl_current_state;
  539. register char *acl_cp, *acl_bp;
  540. register int acl_act;
  541. #line 47 "aclscan.l"
  542. #line 620 "acl.yy.cpp"
  543. if ( acl_init )
  544. {
  545. acl_init = 0;
  546. #ifdef ACL_USER_INIT
  547. ACL_USER_INIT;
  548. #endif
  549. if ( ! acl_start )
  550. acl_start = 1; /* first start state */
  551. if ( ! aclin )
  552. aclin = stdin;
  553. if ( ! aclout )
  554. aclout = stdout;
  555. if ( ! acl_current_buffer )
  556. acl_current_buffer =
  557. acl_create_buffer( aclin, ACL_BUF_SIZE );
  558. acl_load_buffer_state();
  559. }
  560. while ( 1 ) /* loops until end-of-file is reached */
  561. {
  562. acl_cp = acl_c_buf_p;
  563. /* Support of acltext. */
  564. *acl_cp = acl_hold_char;
  565. /* acl_bp points to the position in acl_ch_buf of the start of
  566. * the current run.
  567. */
  568. acl_bp = acl_cp;
  569. acl_current_state = acl_start;
  570. acl_match:
  571. do
  572. {
  573. register ACL_CHAR acl_c = acl_ec[ACL_SC_TO_UI(*acl_cp)];
  574. if ( acl_accept[acl_current_state] )
  575. {
  576. acl_last_accepting_state = acl_current_state;
  577. acl_last_accepting_cpos = acl_cp;
  578. }
  579. while ( acl_chk[acl_base[acl_current_state] + acl_c] != acl_current_state )
  580. {
  581. acl_current_state = (int) acl_def[acl_current_state];
  582. if ( acl_current_state >= 104 )
  583. acl_c = acl_meta[(unsigned int) acl_c];
  584. }
  585. acl_current_state = acl_nxt[acl_base[acl_current_state] + (unsigned int) acl_c];
  586. ++acl_cp;
  587. }
  588. while ( acl_base[acl_current_state] != 119 );
  589. acl_find_action:
  590. acl_act = acl_accept[acl_current_state];
  591. if ( acl_act == 0 )
  592. { /* have to back up */
  593. acl_cp = acl_last_accepting_cpos;
  594. acl_current_state = acl_last_accepting_state;
  595. acl_act = acl_accept[acl_current_state];
  596. }
  597. ACL_DO_BEFORE_ACTION;
  598. do_action: /* This label is used only to access EOF actions. */
  599. switch ( acl_act )
  600. { /* beginning of action switch */
  601. case 0: /* must back up */
  602. /* undo the effects of ACL_DO_BEFORE_ACTION */
  603. *acl_cp = acl_hold_char;
  604. acl_cp = acl_last_accepting_cpos;
  605. acl_current_state = acl_last_accepting_state;
  606. goto acl_find_action;
  607. case 1:
  608. ACL_RULE_SETUP
  609. #line 49 "aclscan.l"
  610. {
  611. acl_lineno++;
  612. acl_tokenpos = 0;
  613. aclless(1);
  614. }
  615. ACL_BREAK
  616. case 2:
  617. ACL_RULE_SETUP
  618. #line 55 "aclscan.l"
  619. ;
  620. ACL_BREAK
  621. case 3:
  622. ACL_RULE_SETUP
  623. #line 57 "aclscan.l"
  624. ;
  625. ACL_BREAK
  626. case ACL_STATE_EOF(INITIAL):
  627. #line 59 "aclscan.l"
  628. {
  629. acllval.string = NULL;
  630. last_string = acllval.string;
  631. return(0);
  632. }
  633. ACL_BREAK
  634. case 4:
  635. ACL_RULE_SETUP
  636. #line 65 "aclscan.l"
  637. {
  638. acllval.string = PERM_STRDUP( acltext+1 );
  639. last_string = acllval.string;
  640. if ( acllval.string[aclleng-2] != '"' )
  641. fprintf(stderr, "Unterminated string\n") ;
  642. else
  643. acllval.string[aclleng-2] = '\0';
  644. acl_tokenpos += aclleng;
  645. return ACL_QSTRING_TOK;
  646. }
  647. ACL_BREAK
  648. case 5:
  649. ACL_RULE_SETUP
  650. #line 77 "aclscan.l"
  651. {
  652. last_string = NULL;
  653. acl_tokenpos += aclleng;
  654. return ACL_ABSOLUTE_TOK;
  655. }
  656. ACL_BREAK
  657. case 6:
  658. ACL_RULE_SETUP
  659. #line 83 "aclscan.l"
  660. {
  661. last_string = NULL;
  662. acl_tokenpos += aclleng;
  663. return ACL_ACL_TOK;
  664. }
  665. ACL_BREAK
  666. case 7:
  667. ACL_RULE_SETUP
  668. #line 89 "aclscan.l"
  669. {
  670. last_string = NULL;
  671. acl_tokenpos += aclleng;
  672. return ACL_ALLOW_TOK;
  673. }
  674. ACL_BREAK
  675. case 8:
  676. ACL_RULE_SETUP
  677. #line 95 "aclscan.l"
  678. {
  679. last_string = NULL;
  680. acl_tokenpos += aclleng;
  681. return ACL_ALWAYS_TOK;
  682. }
  683. ACL_BREAK
  684. case 9:
  685. ACL_RULE_SETUP
  686. #line 101 "aclscan.l"
  687. {
  688. last_string = NULL;
  689. acl_tokenpos += aclleng;
  690. return ACL_AT_TOK;
  691. }
  692. ACL_BREAK
  693. case 10:
  694. ACL_RULE_SETUP
  695. #line 107 "aclscan.l"
  696. {
  697. last_string = NULL;
  698. acl_tokenpos += aclleng;
  699. return ACL_AUTHENTICATE_TOK;
  700. }
  701. ACL_BREAK
  702. case 11:
  703. ACL_RULE_SETUP
  704. #line 113 "aclscan.l"
  705. {
  706. last_string = NULL;
  707. acl_tokenpos += aclleng;
  708. return ACL_CONTENT_TOK;
  709. }
  710. ACL_BREAK
  711. case 12:
  712. ACL_RULE_SETUP
  713. #line 119 "aclscan.l"
  714. {
  715. last_string = NULL;
  716. acl_tokenpos += aclleng;
  717. return ACL_DEFAULT_TOK;
  718. }
  719. ACL_BREAK
  720. case 13:
  721. ACL_RULE_SETUP
  722. #line 125 "aclscan.l"
  723. {
  724. last_string = NULL;
  725. acl_tokenpos += aclleng;
  726. return ACL_DENY_TOK;
  727. }
  728. ACL_BREAK
  729. case 14:
  730. ACL_RULE_SETUP
  731. #line 131 "aclscan.l"
  732. {
  733. last_string = NULL;
  734. acl_tokenpos += aclleng;
  735. return ACL_IN_TOK;
  736. }
  737. ACL_BREAK
  738. case 15:
  739. ACL_RULE_SETUP
  740. #line 137 "aclscan.l"
  741. {
  742. last_string = NULL;
  743. acl_tokenpos += aclleng;
  744. return ACL_INHERIT_TOK;
  745. }
  746. ACL_BREAK
  747. case 16:
  748. ACL_RULE_SETUP
  749. #line 143 "aclscan.l"
  750. {
  751. last_string = NULL;
  752. acl_tokenpos += aclleng;
  753. return ACL_TERMINAL_TOK;
  754. }
  755. ACL_BREAK
  756. case 17:
  757. ACL_RULE_SETUP
  758. #line 149 "aclscan.l"
  759. {
  760. last_string = NULL;
  761. acl_tokenpos += aclleng;
  762. return ACL_VERSION_TOK;
  763. }
  764. ACL_BREAK
  765. case 18:
  766. ACL_RULE_SETUP
  767. #line 155 "aclscan.l"
  768. {
  769. last_string = NULL;
  770. acl_tokenpos += aclleng;
  771. return ACL_WITH_TOK;
  772. }
  773. ACL_BREAK
  774. case 19:
  775. ACL_RULE_SETUP
  776. #line 161 "aclscan.l"
  777. {
  778. last_string = NULL;
  779. acl_tokenpos += aclleng;
  780. return ACL_NOT_TOK;
  781. }
  782. ACL_BREAK
  783. case 20:
  784. ACL_RULE_SETUP
  785. #line 167 "aclscan.l"
  786. {
  787. last_string = NULL;
  788. acllval.ival = ACL_EXPR_OP_AND;
  789. acl_tokenpos += aclleng;
  790. return ACL_AND_TOK;
  791. }
  792. ACL_BREAK
  793. case 21:
  794. ACL_RULE_SETUP
  795. #line 174 "aclscan.l"
  796. {
  797. last_string = NULL;
  798. acllval.ival = ACL_EXPR_OP_OR;
  799. acl_tokenpos += aclleng;
  800. return ACL_OR_TOK;
  801. }
  802. ACL_BREAK
  803. case 22:
  804. ACL_RULE_SETUP
  805. #line 181 "aclscan.l"
  806. {
  807. last_string = NULL;
  808. acllval.ival = CMP_OP_EQ;
  809. acl_tokenpos += aclleng;
  810. return ACL_EQ_TOK;
  811. }
  812. ACL_BREAK
  813. case 23:
  814. ACL_RULE_SETUP
  815. #line 188 "aclscan.l"
  816. {
  817. last_string = NULL;
  818. acllval.ival = CMP_OP_GE;
  819. acl_tokenpos += aclleng;
  820. return ACL_GE_TOK;
  821. }
  822. ACL_BREAK
  823. case 24:
  824. ACL_RULE_SETUP
  825. #line 195 "aclscan.l"
  826. {
  827. last_string = NULL;
  828. acllval.ival = CMP_OP_GT;
  829. acl_tokenpos += aclleng;
  830. return ACL_GT_TOK;
  831. }
  832. ACL_BREAK
  833. case 25:
  834. ACL_RULE_SETUP
  835. #line 202 "aclscan.l"
  836. {
  837. last_string = NULL;
  838. acllval.ival = CMP_OP_LT;
  839. acl_tokenpos += aclleng;
  840. return ACL_LT_TOK;
  841. }
  842. ACL_BREAK
  843. case 26:
  844. ACL_RULE_SETUP
  845. #line 209 "aclscan.l"
  846. {
  847. last_string = NULL;
  848. acllval.ival = CMP_OP_LE;
  849. acl_tokenpos += aclleng;
  850. return ACL_LE_TOK;
  851. }
  852. ACL_BREAK
  853. case 27:
  854. ACL_RULE_SETUP
  855. #line 216 "aclscan.l"
  856. {
  857. last_string = NULL;
  858. acllval.ival = CMP_OP_NE;
  859. acl_tokenpos += aclleng;
  860. return ACL_NE_TOK;
  861. }
  862. ACL_BREAK
  863. case 28:
  864. ACL_RULE_SETUP
  865. #line 223 "aclscan.l"
  866. {
  867. last_string = NULL;
  868. acl_tokenpos += aclleng;
  869. return acltext[0];
  870. }
  871. ACL_BREAK
  872. case 29:
  873. ACL_RULE_SETUP
  874. #line 229 "aclscan.l"
  875. {
  876. acl_tokenpos += aclleng;
  877. acllval.string = PERM_STRDUP( acltext );
  878. last_string = acllval.string;
  879. return ACL_VARIABLE_TOK;
  880. }
  881. ACL_BREAK
  882. case 30:
  883. ACL_RULE_SETUP
  884. #line 235 "aclscan.l"
  885. ECHO;
  886. ACL_BREAK
  887. #line 983 "acl.yy.cpp"
  888. case ACL_END_OF_BUFFER:
  889. {
  890. /* Amount of text matched not including the EOB char. */
  891. int acl_amount_of_matched_text = (int) (acl_cp - acltext_ptr) - 1;
  892. /* Undo the effects of ACL_DO_BEFORE_ACTION. */
  893. *acl_cp = acl_hold_char;
  894. ACL_RESTORE_ACL_MORE_OFFSET
  895. if ( acl_current_buffer->acl_buffer_status == ACL_BUFFER_NEW )
  896. {
  897. /* We're scanning a new file or input source. It's
  898. * possible that this happened because the user
  899. * just pointed aclin at a new source and called
  900. * acllex(). If so, then we have to assure
  901. * consistency between acl_current_buffer and our
  902. * globals. Here is the right place to do so, because
  903. * this is the first action (other than possibly a
  904. * back-up) that will match for the new input source.
  905. */
  906. acl_n_chars = acl_current_buffer->acl_n_chars;
  907. acl_current_buffer->acl_input_file = aclin;
  908. acl_current_buffer->acl_buffer_status = ACL_BUFFER_NORMAL;
  909. }
  910. /* Note that here we test for acl_c_buf_p "<=" to the position
  911. * of the first EOB in the buffer, since acl_c_buf_p will
  912. * already have been incremented past the NUL character
  913. * (since all states make transitions on EOB to the
  914. * end-of-buffer state). Contrast this with the test
  915. * in input().
  916. */
  917. if ( acl_c_buf_p <= &acl_current_buffer->acl_ch_buf[acl_n_chars] )
  918. { /* This was really a NUL. */
  919. acl_state_type acl_next_state;
  920. acl_c_buf_p = acltext_ptr + acl_amount_of_matched_text;
  921. acl_current_state = acl_get_previous_state();
  922. /* Okay, we're now positioned to make the NUL
  923. * transition. We couldn't have
  924. * acl_get_previous_state() go ahead and do it
  925. * for us because it doesn't know how to deal
  926. * with the possibility of jamming (and we don't
  927. * want to build jamming into it because then it
  928. * will run more slowly).
  929. */
  930. acl_next_state = acl_try_NUL_trans( acl_current_state );
  931. acl_bp = acltext_ptr + ACL_MORE_ADJ;
  932. if ( acl_next_state )
  933. {
  934. /* Consume the NUL. */
  935. acl_cp = ++acl_c_buf_p;
  936. acl_current_state = acl_next_state;
  937. goto acl_match;
  938. }
  939. else
  940. {
  941. acl_cp = acl_c_buf_p;
  942. goto acl_find_action;
  943. }
  944. }
  945. else switch ( acl_get_next_buffer() )
  946. {
  947. case EOB_ACT_END_OF_FILE:
  948. {
  949. acl_did_buffer_switch_on_eof = 0;
  950. if ( aclwrap() )
  951. {
  952. /* Note: because we've taken care in
  953. * acl_get_next_buffer() to have set up
  954. * acltext, we can now set up
  955. * acl_c_buf_p so that if some total
  956. * hoser (like flex itself) wants to
  957. * call the scanner after we return the
  958. * ACL_NULL, it'll still work - another
  959. * ACL_NULL will get returned.
  960. */
  961. acl_c_buf_p = acltext_ptr + ACL_MORE_ADJ;
  962. acl_act = ACL_STATE_EOF(ACL_START);
  963. goto do_action;
  964. }
  965. else
  966. {
  967. if ( ! acl_did_buffer_switch_on_eof )
  968. ACL_NEW_FILE;
  969. }
  970. break;
  971. }
  972. case EOB_ACT_CONTINUE_SCAN:
  973. acl_c_buf_p =
  974. acltext_ptr + acl_amount_of_matched_text;
  975. acl_current_state = acl_get_previous_state();
  976. acl_cp = acl_c_buf_p;
  977. acl_bp = acltext_ptr + ACL_MORE_ADJ;
  978. goto acl_match;
  979. case EOB_ACT_LAST_MATCH:
  980. acl_c_buf_p =
  981. &acl_current_buffer->acl_ch_buf[acl_n_chars];
  982. acl_current_state = acl_get_previous_state();
  983. acl_cp = acl_c_buf_p;
  984. acl_bp = acltext_ptr + ACL_MORE_ADJ;
  985. goto acl_find_action;
  986. }
  987. break;
  988. }
  989. default:
  990. ACL_FATAL_ERROR(
  991. "fatal flex scanner internal error--no action found" );
  992. } /* end of action switch */
  993. } /* end of scanning one token */
  994. } /* end of acllex */
  995. /* acl_get_next_buffer - try to read in a new buffer
  996. *
  997. * Returns a code representing an action:
  998. * EOB_ACT_LAST_MATCH -
  999. * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
  1000. * EOB_ACT_END_OF_FILE - end of file
  1001. */
  1002. static int acl_get_next_buffer()
  1003. {
  1004. register char *dest = acl_current_buffer->acl_ch_buf;
  1005. register char *source = acltext_ptr;
  1006. register int number_to_move, i;
  1007. int ret_val;
  1008. if ( acl_c_buf_p > &acl_current_buffer->acl_ch_buf[acl_n_chars + 1] )
  1009. ACL_FATAL_ERROR(
  1010. "fatal flex scanner internal error--end of buffer missed" );
  1011. if ( acl_current_buffer->acl_fill_buffer == 0 )
  1012. { /* Don't try to fill the buffer, so this is an EOF. */
  1013. if ( acl_c_buf_p - acltext_ptr - ACL_MORE_ADJ == 1 )
  1014. {
  1015. /* We matched a single character, the EOB, so
  1016. * treat this as a final EOF.
  1017. */
  1018. return EOB_ACT_END_OF_FILE;
  1019. }
  1020. else
  1021. {
  1022. /* We matched some text prior to the EOB, first
  1023. * process it.
  1024. */
  1025. return EOB_ACT_LAST_MATCH;
  1026. }
  1027. }
  1028. /* Try to read more data. */
  1029. /* First move last chars to start of buffer. */
  1030. number_to_move = (int) (acl_c_buf_p - acltext_ptr) - 1;
  1031. for ( i = 0; i < number_to_move; ++i )
  1032. *(dest++) = *(source++);
  1033. if ( acl_current_buffer->acl_buffer_status == ACL_BUFFER_EOF_PENDING )
  1034. /* don't do the read, it's not guaranteed to return an EOF,
  1035. * just force an EOF
  1036. */
  1037. acl_n_chars = 0;
  1038. else
  1039. {
  1040. int num_to_read =
  1041. acl_current_buffer->acl_buf_size - number_to_move - 1;
  1042. while ( num_to_read <= 0 )
  1043. { /* Not enough room in the buffer - grow it. */
  1044. #ifdef ACL_USES_REJECT
  1045. ACL_FATAL_ERROR(
  1046. "input buffer overflow, can't enlarge buffer because scanner uses REJECT" );
  1047. #else
  1048. /* just a shorter name for the current buffer */
  1049. ACL_BUFFER_STATE b = acl_current_buffer;
  1050. int acl_c_buf_p_offset =
  1051. (int) (acl_c_buf_p - b->acl_ch_buf);
  1052. if ( b->acl_is_our_buffer )
  1053. {
  1054. int new_size = b->acl_buf_size * 2;
  1055. if ( new_size <= 0 )
  1056. b->acl_buf_size += b->acl_buf_size / 8;
  1057. else
  1058. b->acl_buf_size *= 2;
  1059. b->acl_ch_buf = (char *)
  1060. /* Include room in for 2 EOB chars. */
  1061. ACL_FLEX_REALLOC( (void *) b->acl_ch_buf,
  1062. b->acl_buf_size + 2 );
  1063. }
  1064. else
  1065. /* Can't grow it, we don't own it. */
  1066. b->acl_ch_buf = 0;
  1067. if ( ! b->acl_ch_buf )
  1068. ACL_FATAL_ERROR(
  1069. "fatal error - scanner input buffer overflow" );
  1070. acl_c_buf_p = &b->acl_ch_buf[acl_c_buf_p_offset];
  1071. num_to_read = acl_current_buffer->acl_buf_size -
  1072. number_to_move - 1;
  1073. #endif
  1074. }
  1075. if ( num_to_read > ACL_READ_BUF_SIZE )
  1076. num_to_read = ACL_READ_BUF_SIZE;
  1077. /* Read in more data. */
  1078. ACL_INPUT( (&acl_current_buffer->acl_ch_buf[number_to_move]),
  1079. acl_n_chars, num_to_read );
  1080. }
  1081. if ( acl_n_chars == 0 )
  1082. {
  1083. if ( number_to_move == ACL_MORE_ADJ )
  1084. {
  1085. ret_val = EOB_ACT_END_OF_FILE;
  1086. aclrestart( aclin );
  1087. }
  1088. else
  1089. {
  1090. ret_val = EOB_ACT_LAST_MATCH;
  1091. acl_current_buffer->acl_buffer_status =
  1092. ACL_BUFFER_EOF_PENDING;
  1093. }
  1094. }
  1095. else
  1096. ret_val = EOB_ACT_CONTINUE_SCAN;
  1097. acl_n_chars += number_to_move;
  1098. acl_current_buffer->acl_ch_buf[acl_n_chars] = ACL_END_OF_BUFFER_CHAR;
  1099. acl_current_buffer->acl_ch_buf[acl_n_chars + 1] = ACL_END_OF_BUFFER_CHAR;
  1100. acltext_ptr = &acl_current_buffer->acl_ch_buf[0];
  1101. return ret_val;
  1102. }
  1103. /* acl_get_previous_state - get the state just before the EOB char was reached */
  1104. static acl_state_type acl_get_previous_state()
  1105. {
  1106. register acl_state_type acl_current_state;
  1107. register char *acl_cp;
  1108. acl_current_state = acl_start;
  1109. for ( acl_cp = acltext_ptr + ACL_MORE_ADJ; acl_cp < acl_c_buf_p; ++acl_cp )
  1110. {
  1111. register ACL_CHAR acl_c = (*acl_cp ? acl_ec[ACL_SC_TO_UI(*acl_cp)] : 1);
  1112. if ( acl_accept[acl_current_state] )
  1113. {
  1114. acl_last_accepting_state = acl_current_state;
  1115. acl_last_accepting_cpos = acl_cp;
  1116. }
  1117. while ( acl_chk[acl_base[acl_current_state] + acl_c] != acl_current_state )
  1118. {
  1119. acl_current_state = (int) acl_def[acl_current_state];
  1120. if ( acl_current_state >= 104 )
  1121. acl_c = acl_meta[(unsigned int) acl_c];
  1122. }
  1123. acl_current_state = acl_nxt[acl_base[acl_current_state] + (unsigned int) acl_c];
  1124. }
  1125. return acl_current_state;
  1126. }
  1127. /* acl_try_NUL_trans - try to make a transition on the NUL character
  1128. *
  1129. * synopsis
  1130. * next_state = acl_try_NUL_trans( current_state );
  1131. */
  1132. #ifdef ACL_USE_PROTOS
  1133. static acl_state_type acl_try_NUL_trans( acl_state_type acl_current_state )
  1134. #else
  1135. static acl_state_type acl_try_NUL_trans( acl_current_state )
  1136. acl_state_type acl_current_state;
  1137. #endif
  1138. {
  1139. register int acl_is_jam;
  1140. register char *acl_cp = acl_c_buf_p;
  1141. register ACL_CHAR acl_c = 1;
  1142. if ( acl_accept[acl_current_state] )
  1143. {
  1144. acl_last_accepting_state = acl_current_state;
  1145. acl_last_accepting_cpos = acl_cp;
  1146. }
  1147. while ( acl_chk[acl_base[acl_current_state] + acl_c] != acl_current_state )
  1148. {
  1149. acl_current_state = (int) acl_def[acl_current_state];
  1150. if ( acl_current_state >= 104 )
  1151. acl_c = acl_meta[(unsigned int) acl_c];
  1152. }
  1153. acl_current_state = acl_nxt[acl_base[acl_current_state] + (unsigned int) acl_c];
  1154. acl_is_jam = (acl_current_state == 103);
  1155. return acl_is_jam ? 0 : acl_current_state;
  1156. }
  1157. #ifndef ACL_NO_UNPUT
  1158. #ifdef ACL_USE_PROTOS
  1159. static void aclunput( int c, register char *acl_bp )
  1160. #else
  1161. static void aclunput( c, acl_bp )
  1162. int c;
  1163. register char *acl_bp;
  1164. #endif
  1165. {
  1166. register char *acl_cp = acl_c_buf_p;
  1167. /* undo effects of setting up acltext */
  1168. *acl_cp = acl_hold_char;
  1169. if ( acl_cp < acl_current_buffer->acl_ch_buf + 2 )
  1170. { /* need to shift things up to make room */
  1171. /* +2 for EOB chars. */
  1172. register int number_to_move = acl_n_chars + 2;
  1173. register char *dest = &acl_current_buffer->acl_ch_buf[
  1174. acl_current_buffer->acl_buf_size + 2];
  1175. register char *source =
  1176. &acl_current_buffer->acl_ch_buf[number_to_move];
  1177. while ( source > acl_current_buffer->acl_ch_buf )
  1178. *--dest = *--source;
  1179. acl_cp += (int) (dest - source);
  1180. acl_bp += (int) (dest - source);
  1181. acl_n_chars = acl_current_buffer->acl_buf_size;
  1182. if ( acl_cp < acl_current_buffer->acl_ch_buf + 2 )
  1183. ACL_FATAL_ERROR( "flex scanner push-back overflow" );
  1184. }
  1185. *--acl_cp = (char) c;
  1186. acltext_ptr = acl_bp;
  1187. acl_hold_char = *acl_cp;
  1188. acl_c_buf_p = acl_cp;
  1189. }
  1190. #endif /* ifndef ACL_NO_UNPUT */
  1191. #ifdef __cplusplus
  1192. static int aclinput()
  1193. #else
  1194. static int input()
  1195. #endif
  1196. {
  1197. int c;
  1198. *acl_c_buf_p = acl_hold_char;
  1199. if ( *acl_c_buf_p == ACL_END_OF_BUFFER_CHAR )
  1200. {
  1201. /* acl_c_buf_p now points to the character we want to return.
  1202. * If this occurs *before* the EOB characters, then it's a
  1203. * valid NUL; if not, then we've hit the end of the buffer.
  1204. */
  1205. if ( acl_c_buf_p < &acl_current_buffer->acl_ch_buf[acl_n_chars] )
  1206. /* This was really a NUL. */
  1207. *acl_c_buf_p = '\0';
  1208. else
  1209. { /* need more input */
  1210. int offset = acl_c_buf_p - acltext_ptr;
  1211. ++acl_c_buf_p;
  1212. switch ( acl_get_next_buffer() )
  1213. {
  1214. case EOB_ACT_END_OF_FILE:
  1215. {
  1216. if ( aclwrap() )
  1217. {
  1218. acl_c_buf_p = acltext_ptr + offset;
  1219. return EOF;
  1220. }
  1221. if ( ! acl_did_buffer_switch_on_eof )
  1222. ACL_NEW_FILE;
  1223. #ifdef __cplusplus
  1224. return aclinput();
  1225. #else
  1226. return input();
  1227. #endif
  1228. }
  1229. case EOB_ACT_CONTINUE_SCAN:
  1230. acl_c_buf_p = acltext_ptr + offset;
  1231. break;
  1232. case EOB_ACT_LAST_MATCH:
  1233. #ifdef __cplusplus
  1234. ACL_FATAL_ERROR(
  1235. "unexpected last match in aclinput()" );
  1236. #else
  1237. ACL_FATAL_ERROR(
  1238. "unexpected last match in input()" );
  1239. #endif
  1240. }
  1241. }
  1242. }
  1243. c = *(unsigned char *) acl_c_buf_p; /* cast for 8-bit char's */
  1244. *acl_c_buf_p = '\0'; /* preserve acltext */
  1245. acl_hold_char = *++acl_c_buf_p;
  1246. return c;
  1247. }
  1248. #ifdef ACL_USE_PROTOS
  1249. void aclrestart( FILE *input_file )
  1250. #else
  1251. void aclrestart( input_file )
  1252. FILE *input_file;
  1253. #endif
  1254. {
  1255. if ( ! acl_current_buffer )
  1256. acl_current_buffer = acl_create_buffer( aclin, ACL_BUF_SIZE );
  1257. acl_init_buffer( acl_current_buffer, input_file );
  1258. acl_load_buffer_state();
  1259. }
  1260. #ifdef ACL_USE_PROTOS
  1261. void acl_switch_to_buffer( ACL_BUFFER_STATE new_buffer )
  1262. #else
  1263. void acl_switch_to_buffer( new_buffer )
  1264. ACL_BUFFER_STATE new_buffer;
  1265. #endif
  1266. {
  1267. if ( acl_current_buffer == new_buffer )
  1268. return;
  1269. if ( acl_current_buffer )
  1270. {
  1271. /* Flush out information for old buffer. */
  1272. *acl_c_buf_p = acl_hold_char;
  1273. acl_current_buffer->acl_buf_pos = acl_c_buf_p;
  1274. acl_current_buffer->acl_n_chars = acl_n_chars;
  1275. }
  1276. acl_current_buffer = new_buffer;
  1277. acl_load_buffer_state();
  1278. /* We don't actually know whether we did this switch during
  1279. * EOF (aclwrap()) processing, but the only time this flag
  1280. * is looked at is after aclwrap() is called, so it's safe
  1281. * to go ahead and always set it.
  1282. */
  1283. acl_did_buffer_switch_on_eof = 1;
  1284. }
  1285. #ifdef ACL_USE_PROTOS
  1286. void acl_load_buffer_state( void )
  1287. #else
  1288. void acl_load_buffer_state()
  1289. #endif
  1290. {
  1291. acl_n_chars = acl_current_buffer->acl_n_chars;
  1292. acltext_ptr = acl_c_buf_p = acl_current_buffer->acl_buf_pos;
  1293. aclin = acl_current_buffer->acl_input_file;
  1294. acl_hold_char = *acl_c_buf_p;
  1295. }
  1296. #ifdef ACL_USE_PROTOS
  1297. ACL_BUFFER_STATE acl_create_buffer( FILE *file, int size )
  1298. #else
  1299. ACL_BUFFER_STATE acl_create_buffer( file, size )
  1300. FILE *file;
  1301. int size;
  1302. #endif
  1303. {
  1304. ACL_BUFFER_STATE b;
  1305. b = (ACL_BUFFER_STATE) ACL_FLEX_ALLOC( sizeof( struct acl_buffer_state ) );
  1306. if ( ! b )
  1307. ACL_FATAL_ERROR( "out of dynamic memory in acl_create_buffer()" );
  1308. b->acl_buf_size = size;
  1309. /* acl_ch_buf has to be 2 characters longer than the size given because
  1310. * we need to put in 2 end-of-buffer characters.
  1311. */
  1312. b->acl_ch_buf = (char *) ACL_FLEX_ALLOC( b->acl_buf_size + 2 );
  1313. if ( ! b->acl_ch_buf )
  1314. ACL_FATAL_ERROR( "out of dynamic memory in acl_create_buffer()" );
  1315. b->acl_is_our_buffer = 1;
  1316. acl_init_buffer( b, file );
  1317. return b;
  1318. }
  1319. #ifdef ACL_USE_PROTOS
  1320. void acl_delete_buffer( ACL_BUFFER_STATE b )
  1321. #else
  1322. void acl_delete_buffer( b )
  1323. ACL_BUFFER_STATE b;
  1324. #endif
  1325. {
  1326. if ( ! b )
  1327. return;
  1328. if ( b == acl_current_buffer )
  1329. acl_current_buffer = (ACL_BUFFER_STATE) 0;
  1330. if ( b->acl_is_our_buffer )
  1331. ACL_FLEX_FREE( (void *) b->acl_ch_buf );
  1332. ACL_FLEX_FREE( (void *) b );
  1333. }
  1334. #ifndef ACL_ALWAYS_INTERACTIVE
  1335. #ifndef ACL_NEVER_INTERACTIVE
  1336. extern int isatty ACL_PROTO(( int ));
  1337. #endif
  1338. #endif
  1339. #ifdef ACL_USE_PROTOS
  1340. void acl_init_buffer( ACL_BUFFER_STATE b, FILE *file )
  1341. #else
  1342. void acl_init_buffer( b, file )
  1343. ACL_BUFFER_STATE b;
  1344. FILE *file;
  1345. #endif
  1346. {
  1347. acl_flush_buffer( b );
  1348. b->acl_input_file = file;
  1349. b->acl_fill_buffer = 1;
  1350. #if ACL_ALWAYS_INTERACTIVE
  1351. b->acl_is_interactive = 1;
  1352. #else
  1353. #if ACL_NEVER_INTERACTIVE
  1354. b->acl_is_interactive = 0;
  1355. #else
  1356. b->acl_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
  1357. #endif
  1358. #endif
  1359. }
  1360. #ifdef ACL_USE_PROTOS
  1361. void acl_flush_buffer( ACL_BUFFER_STATE b )
  1362. #else
  1363. void acl_flush_buffer( b )
  1364. ACL_BUFFER_STATE b;
  1365. #endif
  1366. {
  1367. b->acl_n_chars = 0;
  1368. /* We always need two end-of-buffer characters. The first causes
  1369. * a transition to the end-of-buffer state. The second causes
  1370. * a jam in that state.
  1371. */
  1372. b->acl_ch_buf[0] = ACL_END_OF_BUFFER_CHAR;
  1373. b->acl_ch_buf[1] = ACL_END_OF_BUFFER_CHAR;
  1374. b->acl_buf_pos = &b->acl_ch_buf[0];
  1375. b->acl_at_bol = 1;
  1376. b->acl_buffer_status = ACL_BUFFER_NEW;
  1377. if ( b == acl_current_buffer )
  1378. acl_load_buffer_state();
  1379. }
  1380. #ifndef ACL_NO_SCAN_BUFFER
  1381. #ifdef ACL_USE_PROTOS
  1382. ACL_BUFFER_STATE acl_scan_buffer( char *base, acl_size_t size )
  1383. #else
  1384. ACL_BUFFER_STATE acl_scan_buffer( base, size )
  1385. char *base;
  1386. acl_size_t size;
  1387. #endif
  1388. {
  1389. ACL_BUFFER_STATE b;
  1390. if ( size < 2 ||
  1391. base[size-2] != ACL_END_OF_BUFFER_CHAR ||
  1392. base[size-1] != ACL_END_OF_BUFFER_CHAR )
  1393. /* They forgot to leave room for the EOB's. */
  1394. return 0;
  1395. b = (ACL_BUFFER_STATE) ACL_FLEX_ALLOC( sizeof( struct acl_buffer_state ) );
  1396. if ( ! b )
  1397. ACL_FATAL_ERROR( "out of dynamic memory in acl_scan_buffer()" );
  1398. b->acl_buf_size = size - 2; /* "- 2" to take care of EOB's */
  1399. b->acl_buf_pos = b->acl_ch_buf = base;
  1400. b->acl_is_our_buffer = 0;
  1401. b->acl_input_file = 0;
  1402. b->acl_n_chars = b->acl_buf_size;
  1403. b->acl_is_interactive = 0;
  1404. b->acl_at_bol = 1;
  1405. b->acl_fill_buffer = 0;
  1406. b->acl_buffer_status = ACL_BUFFER_NEW;
  1407. acl_switch_to_buffer( b );
  1408. return b;
  1409. }
  1410. #endif
  1411. #ifndef ACL_NO_SCAN_STRING
  1412. #ifdef ACL_USE_PROTOS
  1413. ACL_BUFFER_STATE acl_scan_string( aclconst char *str )
  1414. #else
  1415. ACL_BUFFER_STATE acl_scan_string( str )
  1416. aclconst char *str;
  1417. #endif
  1418. {
  1419. int len;
  1420. for ( len = 0; str[len]; ++len )
  1421. ;
  1422. return acl_scan_bytes( str, len );
  1423. }
  1424. #endif
  1425. #ifndef ACL_NO_SCAN_BYTES
  1426. #ifdef ACL_USE_PROTOS
  1427. ACL_BUFFER_STATE acl_scan_bytes( aclconst char *bytes, int len )
  1428. #else
  1429. ACL_BUFFER_STATE acl_scan_bytes( bytes, len )
  1430. aclconst char *bytes;
  1431. int len;
  1432. #endif
  1433. {
  1434. ACL_BUFFER_STATE b;
  1435. char *buf;
  1436. acl_size_t n;
  1437. int i;
  1438. /* Get memory for full buffer, including space for trailing EOB's. */
  1439. n = len + 2;
  1440. buf = (char *) ACL_FLEX_ALLOC( n );
  1441. if ( ! buf )
  1442. ACL_FATAL_ERROR( "out of dynamic memory in acl_scan_bytes()" );
  1443. for ( i = 0; i < len; ++i )
  1444. buf[i] = bytes[i];
  1445. buf[len] = buf[len+1] = ACL_END_OF_BUFFER_CHAR;
  1446. b = acl_scan_buffer( buf, n );
  1447. if ( ! b )
  1448. ACL_FATAL_ERROR( "bad buffer in acl_scan_bytes()" );
  1449. /* It's okay to grow etc. this buffer, and we should throw it
  1450. * away when we're done.
  1451. */
  1452. b->acl_is_our_buffer = 1;
  1453. return b;
  1454. }
  1455. #endif
  1456. #ifndef ACL_NO_PUSH_STATE
  1457. #ifdef ACL_USE_PROTOS
  1458. static void acl_push_state( int new_state )
  1459. #else
  1460. static void acl_push_state( new_state )
  1461. int new_state;
  1462. #endif
  1463. {
  1464. if ( acl_start_stack_ptr >= acl_start_stack_depth )
  1465. {
  1466. acl_size_t new_size;
  1467. acl_start_stack_depth += ACL_START_STACK_INCR;
  1468. new_size = acl_start_stack_depth * sizeof( int );
  1469. if ( ! acl_start_stack )
  1470. acl_start_stack = (int *) ACL_FLEX_ALLOC( new_size );
  1471. else
  1472. acl_start_stack = (int *) ACL_FLEX_REALLOC(
  1473. (void *) acl_start_stack, new_size );
  1474. if ( ! acl_start_stack )
  1475. ACL_FATAL_ERROR(
  1476. "out of memory expanding start-condition stack" );
  1477. }
  1478. acl_start_stack[acl_start_stack_ptr++] = ACL_START;
  1479. BEGIN(new_state);
  1480. }
  1481. #endif
  1482. #ifndef ACL_NO_POP_STATE
  1483. static void acl_pop_state()
  1484. {
  1485. if ( --acl_start_stack_ptr < 0 )
  1486. ACL_FATAL_ERROR( "start-condition stack underflow" );
  1487. BEGIN(acl_start_stack[acl_start_stack_ptr]);
  1488. }
  1489. #endif
  1490. #ifndef ACL_NO_TOP_STATE
  1491. static int acl_top_state()
  1492. {
  1493. return acl_start_stack[acl_start_stack_ptr - 1];
  1494. }
  1495. #endif
  1496. #ifndef ACL_EXIT_FAILURE
  1497. #define ACL_EXIT_FAILURE 2
  1498. #endif
  1499. #ifdef ACL_USE_PROTOS
  1500. static void acl_fatal_error( aclconst char msg[] )
  1501. #else
  1502. static void acl_fatal_error( msg )
  1503. char msg[];
  1504. #endif
  1505. {
  1506. (void) fprintf( stderr, "%s\n", msg );
  1507. exit( ACL_EXIT_FAILURE );
  1508. }
  1509. /* Redefine aclless() so it works in section 3 code. */
  1510. #undef aclless
  1511. #define aclless(n) \
  1512. do \
  1513. { \
  1514. /* Undo effects of setting up acltext. */ \
  1515. acltext[aclleng] = acl_hold_char; \
  1516. acl_c_buf_p = acltext + n; \
  1517. acl_hold_char = *acl_c_buf_p; \
  1518. *acl_c_buf_p = '\0'; \
  1519. aclleng = n; \
  1520. } \
  1521. while ( 0 )
  1522. /* Internal utility routines. */
  1523. #ifndef acltext_ptr
  1524. #ifdef ACL_USE_PROTOS
  1525. static void acl_flex_strncpy( char *s1, aclconst char *s2, int n )
  1526. #else
  1527. static void acl_flex_strncpy( s1, s2, n )
  1528. char *s1;
  1529. aclconst char *s2;
  1530. int n;
  1531. #endif
  1532. {
  1533. register int i;
  1534. for ( i = 0; i < n; ++i )
  1535. s1[i] = s2[i];
  1536. }
  1537. #endif
  1538. #ifdef ACL_NEED_STRLEN
  1539. #ifdef ACL_USE_PROTOS
  1540. static int acl_flex_strlen( aclconst char *s )
  1541. #else
  1542. static int acl_flex_strlen( s )
  1543. aclconst char *s;
  1544. #endif
  1545. {
  1546. register int n;
  1547. for ( n = 0; s[n]; ++n )
  1548. ;
  1549. return n;
  1550. }
  1551. #endif
  1552. #ifdef ACL_USE_PROTOS
  1553. static void *ACL_FLEX_ALLOC( acl_size_t size )
  1554. #else
  1555. static void *ACL_FLEX_ALLOC( size )
  1556. acl_size_t size;
  1557. #endif
  1558. {
  1559. return (void *) PERM_MALLOC( size );
  1560. }
  1561. #ifdef ACL_USE_PROTOS
  1562. static void *ACL_FLEX_REALLOC( void *ptr, acl_size_t size )
  1563. #else
  1564. static void *ACL_FLEX_REALLOC( ptr, size )
  1565. void *ptr;
  1566. acl_size_t size;
  1567. #endif
  1568. {
  1569. /* The cast to (char *) in the following accommodates both
  1570. * implementations that use char* generic pointers, and those
  1571. * that use void* generic pointers. It works with the latter
  1572. * because both ANSI C and C++ allow castless assignment from
  1573. * any pointer type to void*, and deal with argument conversions
  1574. * as though doing an assignment.
  1575. */
  1576. return (void *) PERM_REALLOC( (char *) ptr, size );
  1577. }
  1578. #ifdef ACL_USE_PROTOS
  1579. static void ACL_FLEX_FREE( void *ptr )
  1580. #else
  1581. static void ACL_FLEX_FREE( ptr )
  1582. void *ptr;
  1583. #endif
  1584. {
  1585. PERM_FREE( ptr );
  1586. }
  1587. #if ACL_MAIN
  1588. int main()
  1589. {
  1590. acllex();
  1591. return 0;
  1592. }
  1593. #endif
  1594. #line 235 "aclscan.l"
  1595. void
  1596. acl_detab(char *t, char *s)
  1597. {
  1598. int ii;
  1599. int pos;
  1600. int len;
  1601. if (s == NULL || t == NULL)
  1602. return;
  1603. len = strlen(s);
  1604. pos = 0;
  1605. for (ii = 0; ii < len; ii++) {
  1606. if (s[ii] == '\t') {
  1607. t[pos] = ' ';
  1608. } else {
  1609. t[pos] = s[ii];
  1610. }
  1611. pos++;
  1612. }
  1613. t[pos] = '\0';
  1614. return;
  1615. }
  1616. void
  1617. aclerror(const char *s)
  1618. {
  1619. char errorStr[256];
  1620. #if defined(UTEST) || defined(ACL_COMPILER)
  1621. printf("ACL file: %s\n", acl_filename);
  1622. printf("Syntax error at line: %d, token: %s\n", acl_lineno, acltext);
  1623. if ( last_string )
  1624. PERM_FREE(last_string);
  1625. #else
  1626. sprintf(errorStr, "%d", acl_lineno);
  1627. if (acltext) {
  1628. nserrGenerate(acl_errp, ACLERRPARSE, ACLERR1780, ACL_Program,
  1629. 3, acl_filename, errorStr, acltext);
  1630. } else {
  1631. nserrGenerate(acl_errp, ACLERRPARSE, ACLERR1780, ACL_Program,
  1632. 2, acl_filename, errorStr);
  1633. }
  1634. if ( last_string )
  1635. PERM_FREE(last_string);
  1636. #endif
  1637. }
  1638. int
  1639. acl_InitScanner(NSErr_t *errp, char *filename, char *buffer)
  1640. {
  1641. acl_errp = errp;
  1642. acl_lineno = 1;
  1643. acl_use_buffer = (filename == NULL) ? 1 : 0 ;
  1644. if ( filename != NULL ) {
  1645. strcpy(acl_filename, filename);
  1646. #ifdef UTEST
  1647. aclin = fopen(filename, "r");
  1648. if ( aclin == NULL ) {
  1649. return(-1);
  1650. }
  1651. #else
  1652. acl_prfd = system_fopenRO(filename);
  1653. if ( acl_prfd == NULL ) {
  1654. return(-1);
  1655. }
  1656. aclin = (FILE *) acl_prfd;
  1657. #endif
  1658. aclrestart(aclin);
  1659. } else if ( buffer != NULL ) {
  1660. strcpy(acl_filename, "internal-buffer");
  1661. acl_buffer_offset = 0;
  1662. acl_buffer_length = strlen(buffer);
  1663. acl_buffer = PERM_STRDUP(buffer);
  1664. if (acl_buffer == NULL)
  1665. return(-1);
  1666. aclrestart(NULL);
  1667. } else {
  1668. return(-1);
  1669. }
  1670. return(0);
  1671. }
  1672. int
  1673. acl_EndScanner()
  1674. {
  1675. acl_lineno = 0;
  1676. if ( acl_use_buffer) {
  1677. if ( acl_buffer )
  1678. PERM_FREE(acl_buffer);
  1679. } else if ( aclin ) {
  1680. #ifdef UTEST
  1681. fclose(aclin);
  1682. #else
  1683. if ( acl_prfd ) {
  1684. system_fclose(acl_prfd);
  1685. acl_prfd = NULL;
  1686. }
  1687. #endif
  1688. aclin = NULL ;
  1689. }
  1690. return(0);
  1691. }
  1692. int
  1693. aclwrap()
  1694. {
  1695. return(1);
  1696. }
  1697. static int
  1698. acl_scanner_input(char *buffer, int max_size)
  1699. {
  1700. int len = 0;
  1701. if ( acl_use_buffer ) {
  1702. len = (acl_buffer_length > max_size) ? max_size :
  1703. acl_buffer_length;
  1704. memcpy(buffer, (const void *) &acl_buffer[acl_buffer_offset],
  1705. len);
  1706. acl_buffer_length -= len;
  1707. acl_buffer_offset += len;
  1708. }
  1709. #ifdef UTEST
  1710. else if ( ((len = fread( buffer, 1, max_size, aclin )) == 0)
  1711. && ferror( aclin ) ) {
  1712. aclerror( "scanner input failed" );
  1713. }
  1714. #else
  1715. else if ( (len = system_fread( acl_prfd, buffer, max_size)) < 0 ) {
  1716. aclerror( "scanner input failed" );
  1717. }
  1718. #endif
  1719. return(len);
  1720. }