acl.yy.cpp 49 KB

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