UilSrcSrc.c 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these librararies and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /*
  24. * @OSF_COPYRIGHT@
  25. * COPYRIGHT NOTICE
  26. * Copyright (c) 1990, 1991, 1992, 1993 Open Software Foundation, Inc.
  27. * ALL RIGHTS RESERVED (MOTIF). See the file named COPYRIGHT.MOTIF for
  28. * the full copyright text.
  29. */
  30. /*
  31. * HISTORY
  32. */
  33. #ifdef REV_INFO
  34. #ifndef lint
  35. static char rcsid[] = "$TOG: UilSrcSrc.c /main/13 1997/03/12 15:21:40 dbl $"
  36. #endif
  37. #endif
  38. /*
  39. * (c) Copyright 1989, 1990, DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS. */
  40. /*
  41. **++
  42. ** FACILITY:
  43. **
  44. ** User Interface Language Compiler (UIL)
  45. **
  46. ** ABSTRACT:
  47. **
  48. ** This module contains the procedure for managing the UIL source
  49. ** files.
  50. **
  51. **--
  52. **/
  53. /*
  54. **
  55. ** INCLUDE FILES
  56. **
  57. **/
  58. #include "UilDefI.h"
  59. /* %COMPLETE */
  60. #include <sys/stat.h>
  61. /*
  62. **
  63. ** DEFINE and MACRO DEFINITIONS
  64. **
  65. **/
  66. /*
  67. **
  68. ** EXTERNAL VARIABLE DECLARATIONS
  69. **
  70. **/
  71. /*
  72. **
  73. ** GLOBAL VARIABLE DECLARATIONS
  74. **
  75. **/
  76. /*
  77. ** define the source buffer data structures
  78. */
  79. externaldef(uil_comp_glbl) src_source_buffer_type *src_az_current_source_buffer;
  80. externaldef(uil_comp_glbl) src_source_buffer_type *src_az_avail_source_buffer;
  81. externaldef(uil_comp_glbl) src_message_item_type *src_az_orphan_messages;
  82. /* %COMPLETE */
  83. externaldef(uil_comp_glbl) long Uil_file_size;
  84. struct stat stbuf;
  85. /*
  86. ** define the source record data structures
  87. */
  88. externaldef(uil_comp_glbl) src_source_record_type
  89. *src_az_current_source_record;
  90. externaldef(uil_comp_glbl) src_source_record_type
  91. *src_az_first_source_record;
  92. externaldef(uil_comp_glbl) uil_fcb_type
  93. *src_az_source_file_table[src_k_max_source_files];
  94. externaldef(uil_comp_glbl) int
  95. src_l_last_source_file_number;
  96. /*
  97. **
  98. ** OWN VARIABLE DECLARATIONS
  99. **
  100. **/
  101. static uil_fcb_type *main_fcb;
  102. static char *include_dir;
  103. static unsigned short main_dir_len;
  104. /*
  105. **++
  106. ** FUNCTIONAL DESCRIPTION:
  107. **
  108. ** This procedure initializes the reading of the UIL source program.
  109. **
  110. ** FORMAL PARAMETERS:
  111. **
  112. ** none
  113. **
  114. ** IMPLICIT INPUTS:
  115. **
  116. ** Uil_cmd_z_command
  117. **
  118. ** IMPLICIT OUTPUTS:
  119. **
  120. ** src_az_first_source_buffer
  121. ** src_az_current_source_buffer
  122. ** src_l_last_source_file_number
  123. ** src_az_source_file_table
  124. ** src_az_current_source_record
  125. ** main_fcb
  126. ** include_dir
  127. ** main_dir_len
  128. **
  129. ** FUNCTION VALUE:
  130. **
  131. ** void
  132. **
  133. ** SIDE EFFECTS:
  134. **
  135. ** source file is opened
  136. ** source buffer structure is setup
  137. ** source record structure is setup
  138. **
  139. **--
  140. **/
  141. void
  142. src_initialize_source(void)
  143. {
  144. /* initialize source data structures */
  145. src_az_current_source_buffer = NULL;
  146. src_az_avail_source_buffer = NULL;
  147. src_l_last_source_file_number = -1;
  148. src_az_first_source_record = NULL;
  149. src_az_current_source_record =
  150. (src_source_record_type *) &src_az_first_source_record;
  151. /* Initialize Own storage */
  152. main_fcb = NULL;
  153. include_dir = NULL;
  154. main_dir_len = 0;
  155. /* open the source file */
  156. if ( Uil_cmd_z_command.ac_source_file == NULL )
  157. diag_issue_diagnostic (d_src_open,
  158. diag_k_no_source, diag_k_no_column,
  159. "<null file name>");
  160. src_open_file ( Uil_cmd_z_command.ac_source_file, NULL );
  161. /* fixes initial filename is NULL bug in callable UIL */
  162. Uil_current_file = Uil_cmd_z_command.ac_source_file;
  163. return;
  164. }
  165. /*
  166. **++
  167. ** FUNCTIONAL DESCRIPTION:
  168. **
  169. ** This procedure does the cleanup processing of the source files
  170. ** structures.
  171. **
  172. ** FORMAL PARAMETERS:
  173. **
  174. ** none
  175. **
  176. ** IMPLICIT INPUTS:
  177. **
  178. ** Uil_cmd_z_command
  179. ** src_az_first_source_buffer
  180. ** src_az_current_source_buffer
  181. ** src_l_last_source_file_number
  182. ** src_az_source_file_table
  183. ** src_az_current_source_record
  184. **
  185. ** IMPLICIT OUTPUTS:
  186. **
  187. ** none
  188. **
  189. ** FUNCTION VALUE:
  190. **
  191. ** void
  192. **
  193. ** SIDE EFFECTS:
  194. **
  195. ** structures are freed
  196. **
  197. **--
  198. **/
  199. void
  200. Uil_src_cleanup_source(void)
  201. {
  202. int i; /* index over fcbs */
  203. src_source_buffer_type *buffer_to_free;
  204. src_source_record_type *record_to_free;
  205. src_machine_code_type *first_code_item;
  206. src_machine_code_type *code_item_to_free;
  207. status l_close_status;
  208. /*
  209. ** Loop through all open files freeing their fcbs
  210. */
  211. for (i = 0; i <= src_l_last_source_file_number; i++)
  212. {
  213. /* it is possible to get an error before the files are open,
  214. so check and see if table is NULL before opening */
  215. if (src_az_source_file_table[i] == NULL)
  216. continue;
  217. l_close_status = close_source_file (src_az_source_file_table[i]);
  218. if ( l_close_status == src_k_close_error )
  219. {
  220. diag_issue_diagnostic (d_src_close,
  221. diag_k_no_source, diag_k_no_column,
  222. src_az_source_file_table[i]->expanded_name);
  223. }
  224. _free_memory ((char*)src_az_source_file_table [i]);
  225. src_az_source_file_table[i] = NULL;
  226. }
  227. /*
  228. ** Loop through list of current source buffers, freeing them
  229. */
  230. while (src_az_current_source_buffer != NULL)
  231. {
  232. buffer_to_free = src_az_current_source_buffer;
  233. src_az_current_source_buffer =
  234. src_az_current_source_buffer->az_prior_source_buffer;
  235. _free_memory ((char*)buffer_to_free);
  236. }
  237. /*
  238. ** Loop through list of source records, freeing them
  239. */
  240. while (src_az_first_source_record != NULL)
  241. {
  242. record_to_free = src_az_first_source_record;
  243. first_code_item = record_to_free->az_machine_code_list;
  244. while (first_code_item != NULL)
  245. {
  246. code_item_to_free = first_code_item;
  247. first_code_item = first_code_item->az_next_machine_code;
  248. _free_memory((char *)code_item_to_free);
  249. }
  250. src_az_first_source_record =
  251. src_az_first_source_record->az_next_source_record;
  252. _free_memory ((char*)record_to_free);
  253. }
  254. /*
  255. ** Free Own storage
  256. */
  257. /* BEGIN OSF FIX pir 2240 */
  258. /* Memory pointed to by main_fcb already freed. */
  259. /* END OSF FIX pir 2240 */
  260. _free_memory (include_dir);
  261. return;
  262. }
  263. /*
  264. **++
  265. ** FUNCTIONAL DESCRIPTION:
  266. **
  267. ** This procedure opens a file and sets up the static pointers to
  268. ** read from this file.
  269. **
  270. ** FORMAL PARAMETERS:
  271. **
  272. ** c_file_name file to open
  273. **
  274. ** IMPLICIT INPUTS:
  275. **
  276. ** src_az_first_source_buffer
  277. ** src_az_current_source_buffer
  278. ** src_l_last_source_file_number
  279. ** src_az_source_file_table
  280. **
  281. ** IMPLICIT OUTPUTS:
  282. **
  283. ** src_az_first_source_buffer
  284. ** src_az_current_source_buffer
  285. ** src_l_last_source_file_number
  286. ** src_az_source_file_table
  287. **
  288. ** FUNCTION VALUE:
  289. **
  290. ** void
  291. **
  292. ** SIDE EFFECTS:
  293. **
  294. ** input file is opened
  295. ** input buffer structure is setup
  296. ** input record structure is setup
  297. **
  298. **--
  299. **/
  300. void
  301. src_open_file (XmConst char *c_file_name,
  302. char *full_file_name)
  303. {
  304. uil_fcb_type *az_fcb; /* file control block ptr */
  305. status l_open_status; /* status variable */
  306. src_source_buffer_type *az_source_buffer; /* source buffer ptr */
  307. /* allocate fcb and source buffer */
  308. az_fcb = (uil_fcb_type *) _get_memory (sizeof (uil_fcb_type));
  309. if (src_az_avail_source_buffer != NULL) {
  310. az_source_buffer = src_az_avail_source_buffer;
  311. src_az_avail_source_buffer =
  312. src_az_avail_source_buffer->az_prior_source_buffer;
  313. } else {
  314. az_source_buffer =
  315. (src_source_buffer_type *)
  316. _get_memory (sizeof (src_source_buffer_type));
  317. }
  318. /* Call the OS-specific open file procedure */
  319. l_open_status = open_source_file (
  320. c_file_name,
  321. az_fcb,
  322. az_source_buffer );
  323. /* If the file is not found, a fatal error is generated. */
  324. if ( l_open_status == src_k_open_error ) {
  325. diag_issue_diagnostic( d_src_open,
  326. diag_k_no_source, diag_k_no_column,
  327. c_file_name );
  328. }
  329. /* put fcb in the file table */
  330. src_l_last_source_file_number++;
  331. if (src_l_last_source_file_number >= src_k_max_source_files) {
  332. diag_issue_diagnostic (
  333. d_src_limit,
  334. src_az_current_source_record,
  335. src_az_current_source_buffer -> w_current_position - 1,
  336. az_fcb->expanded_name );
  337. }
  338. src_az_source_file_table[ src_l_last_source_file_number ] = az_fcb;
  339. /* Complete the OS-independent initialization. Get the size of the file
  340. ** for %complete info then initialize a source
  341. ** buffer placing a null in the buffer will cause the lexical analyzer
  342. ** to start by reading the first line of the file
  343. */
  344. /* %COMPLETE */
  345. if (stat(az_fcb->expanded_name, &stbuf) == -1) {
  346. diag_issue_diagnostic( d_src_open,
  347. diag_k_no_source, diag_k_no_column,
  348. az_fcb->expanded_name );
  349. }
  350. Uil_file_size = stbuf.st_size;
  351. if (full_file_name != NULL)
  352. strcpy (full_file_name, az_fcb->expanded_name);
  353. az_fcb->v_position_before_get = FALSE;
  354. az_source_buffer->w_current_line_number = 0;
  355. az_source_buffer->b_file_number = src_l_last_source_file_number;
  356. az_source_buffer->w_current_position = 0;
  357. az_source_buffer->c_text[ 0 ] = 0;
  358. /* make the source buffer current */
  359. az_source_buffer->az_prior_source_buffer =
  360. src_az_current_source_buffer;
  361. src_az_current_source_buffer = az_source_buffer;
  362. return;
  363. }
  364. /*
  365. **++
  366. ** FUNCTIONAL DESCRIPTION:
  367. **
  368. ** This procedure reads the next source line;
  369. **
  370. ** FORMAL PARAMETERS:
  371. **
  372. ** none
  373. **
  374. ** IMPLICIT INPUTS:
  375. **
  376. ** src_az_source_file_table
  377. **
  378. ** IMPLICIT OUTPUTS:
  379. **
  380. ** src_az_current_source_buffer
  381. ** src_az_current_source_record
  382. **
  383. ** FUNCTION VALUE:
  384. **
  385. ** src_k_end_source no more source lines
  386. ** src_k_read_normal new line in the source buffer
  387. **
  388. ** SIDE EFFECTS:
  389. **
  390. ** may issue diagnostics if error occurs reading record
  391. ** may restore previous source upon reaching end of current source
  392. **
  393. **--
  394. **/
  395. status
  396. src_get_source_line(void)
  397. {
  398. uil_fcb_type *az_fcb;
  399. src_source_record_type *az_source_record;
  400. status l_read_status;
  401. /* Return if already at the end of file */
  402. if (src_az_current_source_buffer == NULL)
  403. return src_k_end_source;
  404. /* Find the current fcb */
  405. az_fcb = src_az_source_file_table
  406. [ src_az_current_source_buffer->b_file_number ];
  407. /* Read the next record */
  408. l_read_status = get_line( az_fcb );
  409. /* Increment lines processed count, and update current file */
  410. Uil_lines_processed++;
  411. Uil_current_file = az_fcb->expanded_name;
  412. if ( (l_read_status == src_k_read_normal) ||
  413. (l_read_status == src_k_read_truncated) )
  414. {
  415. /* Read was successful
  416. * Set position to the start of the record */
  417. src_az_current_source_buffer->w_current_position = 0;
  418. /* Allocate and initialize a source record */
  419. az_source_record =
  420. (src_source_record_type *)
  421. _get_memory( sizeof( src_source_record_type ) );
  422. az_source_record->az_next_source_record = NULL;
  423. az_source_record->w_line_number =
  424. ++src_az_current_source_buffer->w_current_line_number;
  425. az_source_record->b_file_number =
  426. src_az_current_source_buffer->b_file_number;
  427. az_source_record->az_message_list = NULL;
  428. az_source_record->az_machine_code_list = NULL;
  429. az_source_record->w_machine_code_cnt = 0;
  430. az_source_record->z_access_key = az_fcb->last_key;
  431. /* was uninitialized; fixes listing problem on HP (RAP) */
  432. az_source_record->b_flags = 0;
  433. /* Link the source record to the end of source record list */
  434. src_az_current_source_record->az_next_source_record =
  435. az_source_record;
  436. src_az_current_source_record = az_source_record;
  437. if (l_read_status == src_k_read_truncated)
  438. diag_issue_diagnostic( d_src_truncate,
  439. src_az_current_source_record,
  440. diag_k_no_column,
  441. src_k_max_source_line_length );
  442. return src_k_read_normal;
  443. }
  444. /* Check for end of file */
  445. if (l_read_status == src_k_end_source)
  446. {
  447. src_source_buffer_type *az_prior_source_buffer;
  448. /* get prior source buffer */
  449. az_prior_source_buffer =
  450. src_az_current_source_buffer->az_prior_source_buffer;
  451. /* place current source buffer on the available list */
  452. src_az_current_source_buffer->az_prior_source_buffer =
  453. src_az_avail_source_buffer;
  454. src_az_avail_source_buffer = src_az_current_source_buffer;
  455. /* if there is no prior source buffer - return end of source */
  456. if (az_prior_source_buffer == NULL)
  457. return src_k_end_source;
  458. /* restore the prior buffer as current */
  459. src_az_current_source_buffer = az_prior_source_buffer;
  460. return src_k_read_normal;
  461. }
  462. /* must have been an error */
  463. diag_issue_diagnostic( d_src_read,
  464. src_az_current_source_record,
  465. diag_k_no_column,
  466. az_fcb->expanded_name );
  467. _assert( FALSE, "read past source error" );
  468. return(src_k_read_error);
  469. }
  470. /*
  471. **++
  472. ** FUNCTIONAL DESCRIPTION:
  473. **
  474. ** open the source file.
  475. **
  476. ** FORMAL PARAMETERS:
  477. **
  478. ** c_file_name source file to open
  479. ** az_fcb file control block for the file
  480. ** az_source_buffer source buffer for the file
  481. **
  482. ** IMPLICIT INPUTS:
  483. **
  484. ** none
  485. **
  486. ** IMPLICIT OUTPUTS:
  487. **
  488. ** none
  489. **
  490. ** FUNCTION VALUE:
  491. **
  492. ** src_k_open_normal
  493. ** src_k_open_error
  494. **
  495. ** SIDE EFFECTS:
  496. **
  497. ** file is opened and has a source buffer associated with it
  498. **
  499. **--
  500. **/
  501. status
  502. open_source_file( XmConst char *c_file_name,
  503. uil_fcb_type *az_fcb,
  504. src_source_buffer_type *az_source_buffer )
  505. {
  506. static unsigned short main_dir_len = 0;
  507. boolean main_file;
  508. int i; /* loop index through include files */
  509. char buffer[256];
  510. /* place the file name in the expanded_name buffer */
  511. strcpy(buffer, c_file_name);
  512. /* Determine if this is the main file or an include file. */
  513. main_file = (main_fcb == NULL);
  514. if (main_file) {
  515. char XmConst * ptr;
  516. unsigned short len;
  517. /* Save the directory info for the main file. */
  518. for (len = strlen (c_file_name),
  519. ptr = & c_file_name [len - 1];
  520. len > 0; len--, ptr--) {
  521. if ((* ptr) == '/') {
  522. break;
  523. }
  524. }
  525. main_dir_len = len;
  526. main_fcb = az_fcb;
  527. /* Open the main file. */
  528. az_fcb->az_file_ptr = fopen(c_file_name, "r");
  529. } else {
  530. static char XmConst c_include_dir[]= "/usr/include/";
  531. Boolean search_user_include=True;
  532. Boolean specific_directory=False;
  533. /* See if the file name has a leading slash and set the flag.
  534. Look in the specified directory for the include file. If the dir
  535. is not specified (leading slash), look in the main file's directory */
  536. if (c_file_name[0] == '/') {
  537. specific_directory = True;
  538. }
  539. if (!specific_directory) {
  540. _move (buffer, main_fcb -> expanded_name, main_dir_len);
  541. _move (& buffer [main_dir_len],
  542. c_file_name, strlen (c_file_name) + 1); /* + NULL */
  543. } else {
  544. strcpy (buffer, c_file_name);
  545. }
  546. /* Open the include file. */
  547. az_fcb->az_file_ptr = fopen (buffer, "r");
  548. /* If a specific directory was specified, or if the file was found,
  549. then we are done. */
  550. if ( (specific_directory) || (az_fcb -> az_file_ptr != NULL) ) {
  551. goto open_label;
  552. }
  553. /* Look in the command line specified include directories, if any. */
  554. for (i = 0; i < Uil_cmd_z_command.include_dir_count; i++) {
  555. int inc_dir_len;
  556. inc_dir_len = strlen (Uil_cmd_z_command.ac_include_dir[i]);
  557. if (inc_dir_len == 0) {
  558. search_user_include = False;
  559. }
  560. _move (buffer, Uil_cmd_z_command.ac_include_dir[i], inc_dir_len);
  561. /* Add '/' if not specified at end of directory */
  562. if (Uil_cmd_z_command.ac_include_dir[i][inc_dir_len - 1] != '/') {
  563. buffer [inc_dir_len] = '/';
  564. inc_dir_len++;
  565. };
  566. _move (& buffer [inc_dir_len],
  567. c_file_name, strlen (c_file_name) + 1); /* + NULL */
  568. /* Open the include file. If found, we are done. */
  569. az_fcb->az_file_ptr = fopen (buffer, "r");
  570. if (az_fcb -> az_file_ptr != NULL) {
  571. goto open_label;
  572. }
  573. }
  574. /* Look in the default include directory. */
  575. if (search_user_include) {
  576. _move(buffer, c_include_dir, sizeof c_include_dir - 1); /* no NULL */
  577. _move(&buffer[sizeof c_include_dir - 1],
  578. c_file_name, strlen (c_file_name) + 1); /* + NULL */
  579. /* Open the include file. */
  580. az_fcb->az_file_ptr = fopen (buffer, "r");
  581. }
  582. }
  583. open_label:
  584. /* check the open status. */
  585. if (az_fcb->az_file_ptr == NULL)
  586. return src_k_open_error;
  587. /* open succeeded - place buffer address in fcb */
  588. az_fcb->c_buffer = az_source_buffer->c_text;
  589. az_fcb->c_buffer[ src_k_max_source_line_length ] = 0;
  590. strcpy(az_fcb->expanded_name, buffer);
  591. return src_k_open_normal;
  592. }
  593. /*
  594. **++
  595. ** FUNCTIONAL DESCRIPTION:
  596. **
  597. ** close the source file.
  598. **
  599. ** FORMAL PARAMETERS:
  600. **
  601. ** az_fcb file control block for the file
  602. **
  603. ** IMPLICIT INPUTS:
  604. **
  605. ** none
  606. **
  607. ** IMPLICIT OUTPUTS:
  608. **
  609. ** none
  610. **
  611. ** FUNCTION VALUE:
  612. **
  613. ** src_k_close_normal
  614. ** src_k_close_error
  615. **
  616. ** SIDE EFFECTS:
  617. **
  618. ** none
  619. **
  620. **--
  621. **/
  622. status
  623. close_source_file( uil_fcb_type *az_fcb )
  624. {
  625. status l_close_status;
  626. /*
  627. ** Close the file
  628. */
  629. l_close_status = fclose (az_fcb->az_file_ptr);
  630. if ( l_close_status != EOF )
  631. return src_k_close_normal;
  632. else
  633. return src_k_close_error;
  634. }
  635. /*
  636. **++
  637. ** FUNCTIONAL DESCRIPTION:
  638. **
  639. ** read line of the source file.
  640. **
  641. ** FORMAL PARAMETERS:
  642. **
  643. ** az_fcb file control block for the file
  644. **
  645. ** IMPLICIT INPUTS:
  646. **
  647. ** none
  648. **
  649. ** IMPLICIT OUTPUTS:
  650. **
  651. ** none
  652. **
  653. ** FUNCTION VALUE:
  654. **
  655. ** src_k_read_normal
  656. ** src_k_read_error
  657. ** src_k_read_truncated
  658. ** src_k_end_source
  659. **
  660. ** SIDE EFFECTS:
  661. **
  662. ** next record in file is read
  663. **
  664. **--
  665. **/
  666. status
  667. get_line( uil_fcb_type *az_fcb )
  668. {
  669. status l_read_status;
  670. char *c_new_line;
  671. /*
  672. ** if v_position_before_get is true, we need to reposition
  673. ** before the get because another retrieve has altered the
  674. ** current record.
  675. */
  676. if (az_fcb->v_position_before_get)
  677. {
  678. fseek( az_fcb->az_file_ptr,
  679. az_fcb->last_key.l_key,
  680. 0 );
  681. l_read_status = (status) (fgets(az_fcb->c_buffer,
  682. src_k_max_source_line_length,
  683. az_fcb->az_file_ptr) != NULL);
  684. az_fcb->v_position_before_get = FALSE;
  685. }
  686. /* get the current offset */
  687. az_fcb->last_key.l_key = ftell(az_fcb->az_file_ptr);
  688. /* read the next line */
  689. l_read_status = (status) (fgets(az_fcb->c_buffer,
  690. src_k_max_source_line_length,
  691. az_fcb->az_file_ptr) != NULL );
  692. if ( l_read_status != 0 )
  693. {
  694. /* Read was successful
  695. * Find \n character an replace with a null */
  696. c_new_line = (char *) strchr( az_fcb->c_buffer, '\n' );
  697. if (c_new_line == NULL) {
  698. /* Fix for CR 3044 -- only return truncated if not at eof */
  699. if (!feof(az_fcb->az_file_ptr))
  700. return src_k_read_truncated;
  701. } else {
  702. *c_new_line = 0;
  703. }
  704. return src_k_read_normal;
  705. }
  706. /* Check for end of file */
  707. if (feof(az_fcb->az_file_ptr))
  708. {
  709. if (sym_az_current_section_entry->prev_section != NULL)
  710. {
  711. sym_include_file_entry_type *include_entry;
  712. /*
  713. ** This is the end of an include file. Set the pointers so that the sections
  714. ** in the include file hang off the previous list correctly.
  715. */
  716. include_entry = (sym_include_file_entry_type *)
  717. sym_az_current_section_entry->prev_section->entries;
  718. include_entry->sections = sym_az_current_section_entry;
  719. sym_az_current_section_entry = sym_az_current_section_entry->prev_section;
  720. }
  721. return src_k_end_source;
  722. }
  723. /* must have been an error */
  724. return src_k_read_error;
  725. }
  726. /*
  727. **++
  728. ** FUNCTIONAL DESCRIPTION:
  729. **
  730. ** re-read line of the source file.
  731. **
  732. ** FORMAL PARAMETERS:
  733. **
  734. ** az_fcb file control block for the file
  735. ** c_buffer pointer to buffer to hold the source line
  736. ** z_access_key key to retrieve the source line
  737. **
  738. ** IMPLICIT INPUTS:
  739. **
  740. ** none
  741. **
  742. ** IMPLICIT OUTPUTS:
  743. **
  744. ** v_position_before_read = TRUE
  745. **
  746. ** FUNCTION VALUE:
  747. **
  748. ** true if the record can be retrieved
  749. ** false if the record cannot be retrieved
  750. **
  751. ** SIDE EFFECTS:
  752. **
  753. ** change next record for the file
  754. **
  755. **--
  756. **/
  757. boolean
  758. reget_line( uil_fcb_type *az_fcb,
  759. char *c_buffer,
  760. XmConst z_key *z_access_key )
  761. {
  762. status l_read_status;
  763. char *c_new_line;
  764. fseek( az_fcb->az_file_ptr,
  765. z_access_key->l_key,
  766. 0 );
  767. l_read_status = (status) (fgets(c_buffer,
  768. src_k_max_source_line_length,
  769. az_fcb->az_file_ptr) != NULL );
  770. az_fcb->v_position_before_get = TRUE;
  771. if ( l_read_status != 0 )
  772. {
  773. /* Read was successful
  774. * Find \n character an replace with a null */
  775. c_new_line = (char *) strchr( c_buffer, '\n' );
  776. if (c_new_line == NULL) {
  777. /* Fix for CR 3044 -- only return truncated if not at eof */
  778. if (!feof(az_fcb->az_file_ptr))
  779. return src_k_read_truncated;
  780. } else {
  781. *c_new_line = 0;
  782. }
  783. return TRUE;
  784. }
  785. /* must have been an error */
  786. return FALSE;
  787. }
  788. /*
  789. **++
  790. ** FUNCTIONAL DESCRIPTION:
  791. **
  792. ** Given a source record, this function returns the file name of
  793. ** the file containing that source record.
  794. **
  795. ** FORMAL PARAMETERS:
  796. **
  797. ** az_src_rec pointer to a source record structure
  798. **
  799. ** IMPLICIT INPUTS:
  800. **
  801. ** src_az_source_file_table
  802. **
  803. ** IMPLICIT OUTPUTS:
  804. **
  805. ** none
  806. **
  807. ** FUNCTION VALUE:
  808. **
  809. ** pointer to the file name string
  810. **
  811. ** SIDE EFFECTS:
  812. **
  813. ** none
  814. **
  815. **--
  816. **/
  817. char
  818. *src_get_file_name(XmConst src_source_record_type *az_src_rec)
  819. {
  820. uil_fcb_type *fcb;
  821. /* Find the correct fcb */
  822. fcb = src_az_source_file_table[ az_src_rec->b_file_number ];
  823. /* Return a pointer to file name */
  824. return fcb->expanded_name;
  825. }
  826. /*
  827. **++
  828. ** FUNCTIONAL DESCRIPTION:
  829. **
  830. ** Given a source record, this function retrieves the text of the
  831. ** line corresponding to that source line.
  832. **
  833. ** FORMAL PARAMETERS:
  834. **
  835. ** az_src_rec pointer to a source record structure
  836. ** c_buffer pointer to buffer to hold the text
  837. **
  838. ** IMPLICIT INPUTS:
  839. **
  840. ** src_az_source_file_table
  841. **
  842. ** IMPLICIT OUTPUTS:
  843. **
  844. ** none
  845. **
  846. ** FUNCTION VALUE:
  847. **
  848. ** true if there is a source line
  849. ** false if there is no source line
  850. **
  851. ** SIDE EFFECTS:
  852. **
  853. ** buffer is set to the contents of source line
  854. **
  855. **--
  856. **/
  857. static char XmConst no_source[] = "[ source not available ]";
  858. boolean src_retrieve_source
  859. (XmConst src_source_record_type *az_src_rec,
  860. char *c_buffer)
  861. {
  862. uil_fcb_type *fcb;
  863. /* check if there is any source */
  864. if (az_src_rec == diag_k_no_source)
  865. {
  866. _move( c_buffer, no_source, sizeof no_source );
  867. return FALSE;
  868. }
  869. /*
  870. ** check if we are dealing with the current source record
  871. ** in which case we don't need to reread the source
  872. */
  873. if ((az_src_rec->b_file_number ==
  874. src_az_current_source_buffer->b_file_number)
  875. &&
  876. (az_src_rec->w_line_number ==
  877. src_az_current_source_buffer->w_current_line_number)
  878. )
  879. {
  880. strcpy( c_buffer,
  881. src_az_current_source_buffer->c_text);
  882. return TRUE;
  883. }
  884. /*
  885. ** Will have to reread the data from the file.
  886. */
  887. /* Find the correct fcb */
  888. fcb = src_az_source_file_table[ az_src_rec->b_file_number ];
  889. /* get the line */
  890. if (reget_line( fcb, c_buffer, (z_key *) &(az_src_rec->z_access_key) ))
  891. return TRUE;
  892. _move( c_buffer, no_source, sizeof no_source );
  893. return FALSE;
  894. }
  895. /*
  896. **++
  897. ** FUNCTIONAL DESCRIPTION:
  898. **
  899. ** This function adds diagnostic information to the source representation.
  900. ** This permit diagnostics to be placed in the listing.
  901. **
  902. ** FORMAL PARAMETERS:
  903. **
  904. ** az_src_rec source line diagnostic issued against
  905. ** l_src_pos offset of diagnostic in the source line
  906. ** c_msg_text text of diagnostic
  907. ** l_msg_number message number for diagnostic
  908. **
  909. ** IMPLICIT INPUTS:
  910. **
  911. ** none
  912. **
  913. ** IMPLICIT OUTPUTS:
  914. **
  915. ** none
  916. **
  917. ** FUNCTION VALUE:
  918. **
  919. ** void
  920. **
  921. ** SIDE EFFECTS:
  922. **
  923. ** diagnostic stuff away in the source structure
  924. **
  925. **--
  926. **/
  927. void
  928. src_append_diag_info( XmConst src_source_record_type *az_src_rec,
  929. XmConst int l_src_pos,
  930. XmConst char *c_msg_text,
  931. XmConst int l_msg_number )
  932. {
  933. src_message_item_type *az_msg_item;
  934. int l_msg_length;
  935. src_message_item_type *current;
  936. src_message_item_type **prior;
  937. /*
  938. ** create the message item and fill it in.
  939. */
  940. l_msg_length = strlen( c_msg_text ) + 1; /* includes null */
  941. az_msg_item = (src_message_item_type *)
  942. _get_memory( sizeof( src_message_item_type ) + l_msg_length );
  943. az_msg_item->l_message_number = l_msg_number;
  944. az_msg_item->b_source_pos = l_src_pos;
  945. _move( (az_msg_item->c_text), c_msg_text, l_msg_length );
  946. /*
  947. ** Link the message from its source line
  948. ** Messages are in ascending column order for a line with
  949. ** messages without column info at the end
  950. ** Messages without source are appended to a list of orphans
  951. */
  952. if (az_src_rec == diag_k_no_source)
  953. prior = &src_az_orphan_messages;
  954. else
  955. prior = (src_message_item_type **)&(az_src_rec->az_message_list);
  956. current = *prior;
  957. for (;
  958. current != NULL;
  959. prior = &(current->az_next_message),
  960. current = *prior )
  961. {
  962. if (l_src_pos < (int)current->b_source_pos)
  963. break;
  964. }
  965. az_msg_item->az_next_message = current;
  966. *prior = az_msg_item;
  967. return;
  968. }
  969. /*
  970. **++
  971. ** FUNCTIONAL DESCRIPTION:
  972. **
  973. ** This function adds machine code information to the source
  974. ** representation. This permits machine code to be placed in the listing.
  975. **
  976. ** FORMAL PARAMETERS:
  977. **
  978. ** az_src_rec source line machine code is associated with.
  979. ** l_offset offset in the record for this code element
  980. ** l_code_len length of the binary machine code buffer
  981. ** c_code buffer containing the machine code in binary form
  982. ** c_text_arg text of machine code; optional
  983. **
  984. ** IMPLICIT INPUTS:
  985. **
  986. ** none
  987. **
  988. ** IMPLICIT OUTPUTS:
  989. **
  990. ** none
  991. **
  992. ** FUNCTION VALUE:
  993. **
  994. ** void
  995. **
  996. ** SIDE EFFECTS:
  997. **
  998. ** Machine code stuffed away in the source structure
  999. **
  1000. **--
  1001. **/
  1002. void
  1003. src_append_machine_code ( src_source_record_type *az_src_rec,
  1004. XmConst int l_offset,
  1005. XmConst int l_code_len,
  1006. XmConst char *c_code,
  1007. XmConst char *c_text_arg )
  1008. {
  1009. src_machine_code_type *az_code_item;
  1010. int l_text_len;
  1011. XmConst char *c_text;
  1012. if (c_text_arg == NULL) {
  1013. c_text = "";
  1014. } else {
  1015. c_text = c_text_arg;
  1016. }
  1017. /*
  1018. ** create the machine code item and fill it in.
  1019. */
  1020. l_text_len = strlen( c_text ) + 1; /* includes null */
  1021. az_code_item = (src_machine_code_type *) _get_memory(
  1022. sizeof( src_machine_code_type ) + l_text_len + l_code_len );
  1023. az_code_item -> w_offset = l_offset;
  1024. az_code_item -> w_code_len = l_code_len;
  1025. _move( (az_code_item->data.c_data), c_code, l_code_len );
  1026. _move( &(az_code_item->data.c_data [l_code_len]), c_text, l_text_len );
  1027. /*
  1028. ** Link the machine code to its source line, at the head of
  1029. ** the machine code list.
  1030. */
  1031. az_code_item->az_next_machine_code = az_src_rec->az_machine_code_list;
  1032. az_src_rec->az_machine_code_list = az_code_item;
  1033. az_src_rec->w_machine_code_cnt++;
  1034. return;
  1035. }