listing.c 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665
  1. /* listing.c - maintain assembly listings
  2. Copyright (C) 1991-2022 Free Software Foundation, Inc.
  3. This file is part of GAS, the GNU Assembler.
  4. GAS is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3, or (at your option)
  7. any later version.
  8. GAS is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GAS; see the file COPYING. If not, write to the Free
  14. Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
  15. 02110-1301, USA. */
  16. /* Contributed by Steve Chamberlain <sac@cygnus.com>
  17. A listing page looks like:
  18. LISTING_HEADER sourcefilename pagenumber
  19. TITLE LINE
  20. SUBTITLE LINE
  21. linenumber address data source
  22. linenumber address data source
  23. linenumber address data source
  24. linenumber address data source
  25. If not overridden, the listing commands are:
  26. .title "stuff"
  27. Put "stuff" onto the title line
  28. .sbttl "stuff"
  29. Put stuff onto the subtitle line
  30. If these commands come within 10 lines of the top of the page, they
  31. will affect the page they are on, as well as any subsequent page
  32. .eject
  33. Throw a page
  34. .list
  35. Increment the enable listing counter
  36. .nolist
  37. Decrement the enable listing counter
  38. .psize Y[,X]
  39. Set the paper size to X wide and Y high. Setting a psize Y of
  40. zero will suppress form feeds except where demanded by .eject
  41. If the counter goes below zero, listing is suppressed.
  42. Listings are a maintained by read calling various listing_<foo>
  43. functions. What happens most is that the macro NO_LISTING is not
  44. defined (from the Makefile), then the macro LISTING_NEWLINE expands
  45. into a call to listing_newline. The call is done from read.c, every
  46. time it sees a newline, and -l is on the command line.
  47. The function listing_newline remembers the frag associated with the
  48. newline, and creates a new frag - note that this is wasteful, but not
  49. a big deal, since listing slows things down a lot anyway. The
  50. function also remembers when the filename changes.
  51. When all the input has finished, and gas has had a chance to settle
  52. down, the listing is output. This is done by running down the list of
  53. frag/source file records, and opening the files as needed and printing
  54. out the bytes and chars associated with them.
  55. The only things which the architecture can change about the listing
  56. are defined in these macros:
  57. LISTING_HEADER The name of the architecture
  58. LISTING_WORD_SIZE The make of the number of bytes in a word, this determines
  59. the clumping of the output data. eg a value of
  60. 2 makes words look like 1234 5678, whilst 1
  61. would make the same value look like 12 34 56
  62. 78
  63. LISTING_LHS_WIDTH Number of words of above size for the lhs
  64. LISTING_LHS_WIDTH_SECOND Number of words for the data on the lhs
  65. for the second line
  66. LISTING_LHS_CONT_LINES Max number of lines to use up for a continuation
  67. LISTING_RHS_WIDTH Number of chars from the input file to print
  68. on a line. */
  69. #include "as.h"
  70. #include "filenames.h"
  71. #include "safe-ctype.h"
  72. #include "input-file.h"
  73. #include "subsegs.h"
  74. #include "bfdver.h"
  75. #include <time.h>
  76. #include <stdarg.h>
  77. #ifndef NO_LISTING
  78. #ifndef LISTING_HEADER
  79. #define LISTING_HEADER "GAS LISTING"
  80. #endif
  81. #ifndef LISTING_WORD_SIZE
  82. #define LISTING_WORD_SIZE 4
  83. #endif
  84. #ifndef LISTING_LHS_WIDTH
  85. #define LISTING_LHS_WIDTH ((LISTING_WORD_SIZE) > 4 ? 1 : 4 / (LISTING_WORD_SIZE))
  86. #endif
  87. #ifndef LISTING_LHS_WIDTH_SECOND
  88. #define LISTING_LHS_WIDTH_SECOND LISTING_LHS_WIDTH
  89. #endif
  90. #ifndef LISTING_RHS_WIDTH
  91. #define LISTING_RHS_WIDTH 100
  92. #endif
  93. #ifndef LISTING_LHS_CONT_LINES
  94. #define LISTING_LHS_CONT_LINES 4
  95. #endif
  96. #define MAX_DATELEN 30
  97. /* This structure remembers which .s were used. */
  98. typedef struct file_info_struct
  99. {
  100. struct file_info_struct * next;
  101. char * filename;
  102. long pos;
  103. unsigned int linenum;
  104. int at_end;
  105. } file_info_type;
  106. enum edict_enum
  107. {
  108. EDICT_NONE,
  109. EDICT_SBTTL,
  110. EDICT_TITLE,
  111. EDICT_NOLIST,
  112. EDICT_LIST,
  113. EDICT_NOLIST_NEXT,
  114. EDICT_EJECT
  115. };
  116. struct list_message
  117. {
  118. char *message;
  119. struct list_message *next;
  120. };
  121. /* This structure remembers which line from which file goes into which
  122. frag. */
  123. struct list_info_struct
  124. {
  125. /* Frag which this line of source is nearest to. */
  126. fragS *frag;
  127. /* The actual line in the source file. */
  128. unsigned int line;
  129. /* Pointer to the file info struct for the file which this line
  130. belongs to. */
  131. file_info_type *file;
  132. /* The expanded text of any macro that may have been executing. */
  133. char *line_contents;
  134. /* Next in list. */
  135. struct list_info_struct *next;
  136. /* Pointer to the file info struct for the high level language
  137. source line that belongs here. */
  138. file_info_type *hll_file;
  139. /* High level language source line. */
  140. unsigned int hll_line;
  141. /* Pointers to linked list of messages associated with this line. */
  142. struct list_message *messages, *last_message;
  143. enum edict_enum edict;
  144. char *edict_arg;
  145. /* Nonzero if this line is to be omitted because it contains
  146. debugging information. This can become a flags field if we come
  147. up with more information to store here. */
  148. int debugging;
  149. };
  150. typedef struct list_info_struct list_info_type;
  151. int listing_lhs_width = LISTING_LHS_WIDTH;
  152. int listing_lhs_width_second = LISTING_LHS_WIDTH_SECOND;
  153. int listing_lhs_cont_lines = LISTING_LHS_CONT_LINES;
  154. int listing_rhs_width = LISTING_RHS_WIDTH;
  155. struct list_info_struct * listing_tail;
  156. static file_info_type * file_info_head;
  157. static file_info_type * last_open_file_info;
  158. static FILE * last_open_file;
  159. static struct list_info_struct * head;
  160. static int paper_width = 200;
  161. static int paper_height = 60;
  162. extern int listing;
  163. /* File to output listings to. */
  164. static FILE *list_file;
  165. /* This static array is used to keep the text of data to be printed
  166. before the start of the line. */
  167. #define MAX_BYTES \
  168. (((LISTING_WORD_SIZE * 2) + 1) * listing_lhs_width \
  169. + ((((LISTING_WORD_SIZE * 2) + 1) * listing_lhs_width_second) \
  170. * listing_lhs_cont_lines) \
  171. + 20)
  172. static char *data_buffer;
  173. /* Prototypes. */
  174. static void listing_message (const char *, const char *);
  175. static file_info_type *file_info (const char *);
  176. static void new_frag (void);
  177. static void listing_page (list_info_type *);
  178. static unsigned int calc_hex (list_info_type *);
  179. static void print_lines (list_info_type *, unsigned int, const char *,
  180. unsigned int);
  181. static void list_symbol_table (void);
  182. static int debugging_pseudo (list_info_type *, const char *);
  183. static void listing_listing (char *);
  184. static void
  185. listing_message (const char *name, const char *message)
  186. {
  187. if (listing_tail != (list_info_type *) NULL)
  188. {
  189. char *n = concat (name, message, (char *) NULL);
  190. struct list_message *lm = XNEW (struct list_message);
  191. lm->message = n;
  192. lm->next = NULL;
  193. if (listing_tail->last_message)
  194. listing_tail->last_message->next = lm;
  195. else
  196. listing_tail->messages = lm;
  197. listing_tail->last_message = lm;
  198. }
  199. }
  200. void
  201. listing_warning (const char *message)
  202. {
  203. listing_message (_("Warning: "), message);
  204. }
  205. void
  206. listing_error (const char *message)
  207. {
  208. listing_message (_("Error: "), message);
  209. }
  210. static file_info_type *
  211. file_info (const char *file_name)
  212. {
  213. /* Find an entry with this file name. */
  214. file_info_type *p = file_info_head;
  215. while (p != (file_info_type *) NULL)
  216. {
  217. if (filename_cmp (p->filename, file_name) == 0)
  218. return p;
  219. p = p->next;
  220. }
  221. /* Make new entry. */
  222. p = XNEW (file_info_type);
  223. p->next = file_info_head;
  224. file_info_head = p;
  225. p->filename = xstrdup (file_name);
  226. p->pos = 0;
  227. p->linenum = 0;
  228. p->at_end = 0;
  229. return p;
  230. }
  231. static void
  232. new_frag (void)
  233. {
  234. frag_wane (frag_now);
  235. frag_new (0);
  236. }
  237. void
  238. listing_newline (char *ps)
  239. {
  240. const char *file;
  241. unsigned int line;
  242. static unsigned int last_line = 0xffff;
  243. static const char *last_file = NULL;
  244. list_info_type *new_i = NULL;
  245. if (listing == 0)
  246. return;
  247. if (now_seg == absolute_section)
  248. return;
  249. #ifdef OBJ_ELF
  250. /* In ELF, anything in a section beginning with .debug or .line is
  251. considered to be debugging information. This includes the
  252. statement which switches us into the debugging section, which we
  253. can only set after we are already in the debugging section. */
  254. if ((listing & LISTING_NODEBUG) != 0
  255. && listing_tail != NULL
  256. && ! listing_tail->debugging)
  257. {
  258. const char *segname;
  259. segname = segment_name (now_seg);
  260. if (startswith (segname, ".debug")
  261. || startswith (segname, ".line"))
  262. listing_tail->debugging = 1;
  263. }
  264. #endif
  265. /* PR 21977 - use the physical file name not the logical one unless high
  266. level source files are being included in the listing. */
  267. if (listing & LISTING_HLL)
  268. file = as_where (&line);
  269. else
  270. file = as_where_physical (&line);
  271. if (ps == NULL)
  272. {
  273. if (line == last_line
  274. && !(last_file && file && filename_cmp (file, last_file)))
  275. return;
  276. new_i = XNEW (list_info_type);
  277. /* Detect if we are reading from stdin by examining the file
  278. name returned by as_where().
  279. [FIXME: We rely upon the name in the strcmp below being the
  280. same as the one used by input_scrub_new_file(), if that is
  281. not true, then this code will fail].
  282. If we are reading from stdin, then we need to save each input
  283. line here (assuming of course that we actually have a line of
  284. input to read), so that it can be displayed in the listing
  285. that is produced at the end of the assembly. */
  286. if (strcmp (file, _("{standard input}")) == 0
  287. && input_line_pointer != NULL)
  288. {
  289. char *copy, *src, *dest;
  290. int len;
  291. int seen_quote = 0;
  292. int seen_slash = 0;
  293. for (copy = input_line_pointer;
  294. *copy && (seen_quote
  295. || is_end_of_line [(unsigned char) *copy] != 1);
  296. copy++)
  297. {
  298. if (seen_slash)
  299. seen_slash = 0;
  300. else if (*copy == '\\')
  301. seen_slash = 1;
  302. else if (*copy == '"')
  303. seen_quote = !seen_quote;
  304. }
  305. len = copy - input_line_pointer + 1;
  306. copy = XNEWVEC (char, len);
  307. src = input_line_pointer;
  308. dest = copy;
  309. while (--len)
  310. {
  311. unsigned char c = *src++;
  312. /* Omit control characters in the listing. */
  313. if (!ISCNTRL (c))
  314. *dest++ = c;
  315. }
  316. *dest = 0;
  317. new_i->line_contents = copy;
  318. }
  319. else
  320. new_i->line_contents = NULL;
  321. }
  322. else
  323. {
  324. new_i = XNEW (list_info_type);
  325. new_i->line_contents = ps;
  326. }
  327. last_line = line;
  328. last_file = file;
  329. new_frag ();
  330. if (listing_tail)
  331. listing_tail->next = new_i;
  332. else
  333. head = new_i;
  334. listing_tail = new_i;
  335. new_i->frag = frag_now;
  336. new_i->line = line;
  337. new_i->file = file_info (file);
  338. new_i->next = (list_info_type *) NULL;
  339. new_i->messages = NULL;
  340. new_i->last_message = NULL;
  341. new_i->edict = EDICT_NONE;
  342. new_i->hll_file = (file_info_type *) NULL;
  343. new_i->hll_line = 0;
  344. new_i->debugging = 0;
  345. new_frag ();
  346. #ifdef OBJ_ELF
  347. /* In ELF, anything in a section beginning with .debug or .line is
  348. considered to be debugging information. */
  349. if ((listing & LISTING_NODEBUG) != 0)
  350. {
  351. const char *segname;
  352. segname = segment_name (now_seg);
  353. if (startswith (segname, ".debug")
  354. || startswith (segname, ".line"))
  355. new_i->debugging = 1;
  356. }
  357. #endif
  358. }
  359. /* Attach all current frags to the previous line instead of the
  360. current line. This is called by the MIPS backend when it discovers
  361. that it needs to add some NOP instructions; the added NOP
  362. instructions should go with the instruction that has the delay, not
  363. with the new instruction. */
  364. void
  365. listing_prev_line (void)
  366. {
  367. list_info_type *l;
  368. fragS *f;
  369. if (head == (list_info_type *) NULL
  370. || head == listing_tail)
  371. return;
  372. new_frag ();
  373. for (l = head; l->next != listing_tail; l = l->next)
  374. ;
  375. for (f = frchain_now->frch_root; f != (fragS *) NULL; f = f->fr_next)
  376. if (f->line == listing_tail)
  377. f->line = l;
  378. listing_tail->frag = frag_now;
  379. new_frag ();
  380. }
  381. /* This function returns the next source line from the file supplied,
  382. truncated to size. It appends a fake line to the end of each input
  383. file to make using the returned buffer simpler. */
  384. static const char *
  385. buffer_line (file_info_type *file, char *line, unsigned int size)
  386. {
  387. unsigned int count = 0;
  388. int c;
  389. char *p = line;
  390. /* If we couldn't open the file, return an empty line. */
  391. if (file->at_end)
  392. return "";
  393. /* Check the cache and see if we last used this file. */
  394. if (!last_open_file_info || file != last_open_file_info)
  395. {
  396. if (last_open_file)
  397. {
  398. last_open_file_info->pos = ftell (last_open_file);
  399. fclose (last_open_file);
  400. }
  401. /* Open the file in the binary mode so that ftell above can
  402. return a reliable value that we can feed to fseek below. */
  403. last_open_file_info = file;
  404. last_open_file = fopen (file->filename, FOPEN_RB);
  405. if (last_open_file == NULL)
  406. {
  407. file->at_end = 1;
  408. return "";
  409. }
  410. /* Seek to where we were last time this file was open. */
  411. if (file->pos)
  412. fseek (last_open_file, file->pos, SEEK_SET);
  413. }
  414. c = fgetc (last_open_file);
  415. while (c != EOF && c != '\n' && c != '\r')
  416. {
  417. if (++count < size)
  418. *p++ = c;
  419. c = fgetc (last_open_file);
  420. }
  421. /* If '\r' is followed by '\n', swallow that. Likewise, if '\n'
  422. is followed by '\r', swallow that as well. */
  423. if (c == '\r' || c == '\n')
  424. {
  425. int next = fgetc (last_open_file);
  426. if ((c == '\r' && next != '\n')
  427. || (c == '\n' && next != '\r'))
  428. ungetc (next, last_open_file);
  429. }
  430. if (c == EOF)
  431. {
  432. file->at_end = 1;
  433. if (count + 3 < size)
  434. {
  435. *p++ = '.';
  436. *p++ = '.';
  437. *p++ = '.';
  438. }
  439. }
  440. file->linenum++;
  441. *p++ = 0;
  442. return line;
  443. }
  444. /* This function rewinds the requested file back to the line requested,
  445. reads it in again into the buffer provided and then restores the file
  446. back to its original location. */
  447. static void
  448. rebuffer_line (file_info_type * file,
  449. unsigned int linenum,
  450. char * buffer,
  451. unsigned int size)
  452. {
  453. unsigned int count = 0;
  454. unsigned int current_line;
  455. char * p = buffer;
  456. long pos;
  457. long pos2;
  458. int c;
  459. bool found = false;
  460. /* Sanity checks. */
  461. if (file == NULL || buffer == NULL || size <= 1 || file->linenum <= linenum)
  462. return;
  463. /* Check the cache and see if we last used this file. */
  464. if (last_open_file_info == NULL || file != last_open_file_info)
  465. {
  466. if (last_open_file)
  467. {
  468. last_open_file_info->pos = ftell (last_open_file);
  469. fclose (last_open_file);
  470. }
  471. /* Open the file in the binary mode so that ftell above can
  472. return a reliable value that we can feed to fseek below. */
  473. last_open_file_info = file;
  474. last_open_file = fopen (file->filename, FOPEN_RB);
  475. if (last_open_file == NULL)
  476. {
  477. file->at_end = 1;
  478. return;
  479. }
  480. /* Seek to where we were last time this file was open. */
  481. if (file->pos)
  482. fseek (last_open_file, file->pos, SEEK_SET);
  483. }
  484. /* Remember where we are in the current file. */
  485. pos2 = pos = ftell (last_open_file);
  486. if (pos < 3)
  487. return;
  488. current_line = file->linenum;
  489. /* Leave room for the nul at the end of the buffer. */
  490. size -= 1;
  491. buffer[size] = 0;
  492. /* Increment the current line count by one.
  493. This is to allow for the fact that we are searching for the
  494. start of a previous line, but we do this by detecting end-of-line
  495. character(s) not start-of-line characters. */
  496. ++ current_line;
  497. while (pos2 > 0 && ! found)
  498. {
  499. char * ptr;
  500. /* Move backwards through the file, looking for earlier lines. */
  501. pos2 = (long) size > pos2 ? 0 : pos2 - size;
  502. fseek (last_open_file, pos2, SEEK_SET);
  503. /* Our caller has kindly provided us with a buffer, so we use it. */
  504. if (fread (buffer, 1, size, last_open_file) != size)
  505. {
  506. as_warn (_("unable to rebuffer file: %s\n"), file->filename);
  507. return;
  508. }
  509. for (ptr = buffer + size; ptr >= buffer; -- ptr)
  510. {
  511. if (*ptr == '\n')
  512. {
  513. -- current_line;
  514. if (current_line == linenum)
  515. {
  516. /* We have found the start of the line we seek. */
  517. found = true;
  518. /* FIXME: We could skip the read-in-the-line code
  519. below if we know that we already have the whole
  520. line in the buffer. */
  521. /* Advance pos2 to the newline character we have just located. */
  522. pos2 += (ptr - buffer);
  523. /* Skip the newline and, if present, the carriage return. */
  524. if (ptr + 1 == buffer + size)
  525. {
  526. ++pos2;
  527. if (fgetc (last_open_file) == '\r')
  528. ++ pos2;
  529. }
  530. else
  531. pos2 += (ptr[1] == '\r' ? 2 : 1);
  532. /* Move the file pointer to this location. */
  533. fseek (last_open_file, pos2, SEEK_SET);
  534. break;
  535. }
  536. }
  537. }
  538. }
  539. /* Read in the line. */
  540. c = fgetc (last_open_file);
  541. while (c != EOF && c != '\n' && c != '\r')
  542. {
  543. if (count < size)
  544. *p++ = c;
  545. count++;
  546. c = fgetc (last_open_file);
  547. }
  548. /* If '\r' is followed by '\n', swallow that. Likewise, if '\n'
  549. is followed by '\r', swallow that as well. */
  550. if (c == '\r' || c == '\n')
  551. {
  552. int next = fgetc (last_open_file);
  553. if ((c == '\r' && next != '\n')
  554. || (c == '\n' && next != '\r'))
  555. ungetc (next, last_open_file);
  556. }
  557. /* Terminate the line. */
  558. *p++ = 0;
  559. /* Reset the file position. */
  560. fseek (last_open_file, pos, SEEK_SET);
  561. }
  562. static const char *fn;
  563. static unsigned int eject; /* Eject pending. */
  564. static unsigned int page; /* Current page number. */
  565. static const char *title; /* Current title. */
  566. static const char *subtitle; /* Current subtitle. */
  567. static unsigned int on_page; /* Number of lines printed on current page. */
  568. static void
  569. listing_page (list_info_type *list)
  570. {
  571. /* Grope around, see if we can see a title or subtitle edict coming up
  572. soon. (we look down 10 lines of the page and see if it's there) */
  573. if ((eject || (on_page >= (unsigned int) paper_height))
  574. && paper_height != 0)
  575. {
  576. unsigned int c = 10;
  577. int had_title = 0;
  578. int had_subtitle = 0;
  579. page++;
  580. while (c != 0 && list)
  581. {
  582. if (list->edict == EDICT_SBTTL && !had_subtitle)
  583. {
  584. had_subtitle = 1;
  585. subtitle = list->edict_arg;
  586. }
  587. if (list->edict == EDICT_TITLE && !had_title)
  588. {
  589. had_title = 1;
  590. title = list->edict_arg;
  591. }
  592. list = list->next;
  593. c--;
  594. }
  595. if (page > 1)
  596. {
  597. fprintf (list_file, "\f");
  598. }
  599. fprintf (list_file, "%s %s \t\t\tpage %d\n", LISTING_HEADER, fn, page);
  600. fprintf (list_file, "%s\n", title);
  601. fprintf (list_file, "%s\n", subtitle);
  602. on_page = 3;
  603. eject = 0;
  604. }
  605. }
  606. /* Print a line into the list_file. Update the line count
  607. and if necessary start a new page. */
  608. static void
  609. emit_line (list_info_type * list, const char * format, ...)
  610. {
  611. va_list args;
  612. va_start (args, format);
  613. vfprintf (list_file, format, args);
  614. on_page++;
  615. listing_page (list);
  616. va_end (args);
  617. }
  618. static unsigned int
  619. calc_hex (list_info_type *list)
  620. {
  621. int data_buffer_size;
  622. list_info_type *first = list;
  623. unsigned int address = ~(unsigned int) 0;
  624. fragS *frag;
  625. fragS *frag_ptr;
  626. unsigned int octet_in_frag;
  627. /* Find first frag which says it belongs to this line. */
  628. frag = list->frag;
  629. while (frag && frag->line != list)
  630. frag = frag->fr_next;
  631. frag_ptr = frag;
  632. data_buffer_size = 0;
  633. /* Dump all the frags which belong to this line. */
  634. while (frag_ptr != (fragS *) NULL && frag_ptr->line == first)
  635. {
  636. /* Print as many bytes from the fixed part as is sensible. */
  637. octet_in_frag = 0;
  638. while (octet_in_frag < frag_ptr->fr_fix
  639. && data_buffer_size < MAX_BYTES - 3)
  640. {
  641. if (address == ~(unsigned int) 0)
  642. address = frag_ptr->fr_address / OCTETS_PER_BYTE;
  643. sprintf (data_buffer + data_buffer_size,
  644. "%02X",
  645. (frag_ptr->fr_literal[octet_in_frag]) & 0xff);
  646. data_buffer_size += 2;
  647. octet_in_frag++;
  648. }
  649. if (frag_ptr->fr_type == rs_fill)
  650. {
  651. unsigned int var_rep_max = octet_in_frag;
  652. unsigned int var_rep_idx = octet_in_frag;
  653. /* Print as many bytes from the variable part as is sensible. */
  654. while ((octet_in_frag
  655. < frag_ptr->fr_fix + frag_ptr->fr_var * frag_ptr->fr_offset)
  656. && data_buffer_size < MAX_BYTES - 3)
  657. {
  658. if (address == ~(unsigned int) 0)
  659. address = frag_ptr->fr_address / OCTETS_PER_BYTE;
  660. sprintf (data_buffer + data_buffer_size,
  661. "%02X",
  662. (frag_ptr->fr_literal[var_rep_idx]) & 0xff);
  663. data_buffer_size += 2;
  664. var_rep_idx++;
  665. octet_in_frag++;
  666. if (var_rep_idx >= frag_ptr->fr_fix + frag_ptr->fr_var)
  667. var_rep_idx = var_rep_max;
  668. }
  669. }
  670. frag_ptr = frag_ptr->fr_next;
  671. }
  672. data_buffer[data_buffer_size] = '\0';
  673. return address;
  674. }
  675. static void
  676. print_lines (list_info_type *list, unsigned int lineno,
  677. const char *string, unsigned int address)
  678. {
  679. unsigned int idx;
  680. unsigned int nchars;
  681. unsigned int lines;
  682. unsigned int octet_in_word = 0;
  683. char *src = data_buffer;
  684. int cur;
  685. struct list_message *msg;
  686. /* Print the stuff on the first line. */
  687. listing_page (list);
  688. nchars = (LISTING_WORD_SIZE * 2 + 1) * listing_lhs_width;
  689. /* Print the hex for the first line. */
  690. if (address == ~(unsigned int) 0)
  691. {
  692. fprintf (list_file, "% 4d ", lineno);
  693. for (idx = 0; idx < nchars; idx++)
  694. fprintf (list_file, " ");
  695. emit_line (NULL, "\t%s\n", string ? string : "");
  696. return;
  697. }
  698. if (had_errors ())
  699. fprintf (list_file, "% 4d ???? ", lineno);
  700. else
  701. fprintf (list_file, "% 4d %04x ", lineno, address);
  702. /* And the data to go along with it. */
  703. idx = 0;
  704. cur = 0;
  705. while (src[cur] && idx < nchars)
  706. {
  707. int offset;
  708. offset = cur;
  709. fprintf (list_file, "%c%c", src[offset], src[offset + 1]);
  710. cur += 2;
  711. octet_in_word++;
  712. if (octet_in_word == LISTING_WORD_SIZE)
  713. {
  714. fprintf (list_file, " ");
  715. idx++;
  716. octet_in_word = 0;
  717. }
  718. idx += 2;
  719. }
  720. for (; idx < nchars; idx++)
  721. fprintf (list_file, " ");
  722. emit_line (list, "\t%s\n", string ? string : "");
  723. for (msg = list->messages; msg; msg = msg->next)
  724. emit_line (list, "**** %s\n", msg->message);
  725. for (lines = 0;
  726. lines < (unsigned int) listing_lhs_cont_lines
  727. && src[cur];
  728. lines++)
  729. {
  730. nchars = ((LISTING_WORD_SIZE * 2) + 1) * listing_lhs_width_second - 1;
  731. idx = 0;
  732. /* Print any more lines of data, but more compactly. */
  733. fprintf (list_file, "% 4d ", lineno);
  734. while (src[cur] && idx < nchars)
  735. {
  736. int offset;
  737. offset = cur;
  738. fprintf (list_file, "%c%c", src[offset], src[offset + 1]);
  739. cur += 2;
  740. idx += 2;
  741. octet_in_word++;
  742. if (octet_in_word == LISTING_WORD_SIZE)
  743. {
  744. fprintf (list_file, " ");
  745. idx++;
  746. octet_in_word = 0;
  747. }
  748. }
  749. emit_line (list, "\n");
  750. }
  751. }
  752. static void
  753. list_symbol_table (void)
  754. {
  755. extern symbolS *symbol_rootP;
  756. int got_some = 0;
  757. symbolS *ptr;
  758. eject = 1;
  759. listing_page (NULL);
  760. for (ptr = symbol_rootP; ptr != (symbolS *) NULL; ptr = symbol_next (ptr))
  761. {
  762. if (SEG_NORMAL (S_GET_SEGMENT (ptr))
  763. || S_GET_SEGMENT (ptr) == absolute_section)
  764. {
  765. /* Don't report section symbols. They are not interesting. */
  766. if (symbol_section_p (ptr))
  767. continue;
  768. if (S_GET_NAME (ptr))
  769. {
  770. char buf[30], fmt[8];
  771. valueT val = S_GET_VALUE (ptr);
  772. /* @@ Note that this is dependent on the compilation options,
  773. not solely on the target characteristics. */
  774. if (sizeof (val) == 4 && sizeof (int) == 4)
  775. sprintf (buf, "%08lx", (unsigned long) val);
  776. else if (sizeof (val) <= sizeof (unsigned long))
  777. {
  778. sprintf (fmt, "%%0%lulx",
  779. (unsigned long) (sizeof (val) * 2));
  780. sprintf (buf, fmt, (unsigned long) val);
  781. }
  782. #if defined (BFD64)
  783. else if (sizeof (val) > 4)
  784. sprintf_vma (buf, val);
  785. #endif
  786. else
  787. abort ();
  788. if (!got_some)
  789. {
  790. fprintf (list_file, "DEFINED SYMBOLS\n");
  791. on_page++;
  792. got_some = 1;
  793. }
  794. if (symbol_get_frag (ptr) && symbol_get_frag (ptr)->line)
  795. {
  796. fprintf (list_file, "%20s:%-5d %s:%s %s\n",
  797. symbol_get_frag (ptr)->line->file->filename,
  798. symbol_get_frag (ptr)->line->line,
  799. segment_name (S_GET_SEGMENT (ptr)),
  800. buf, S_GET_NAME (ptr));
  801. }
  802. else
  803. {
  804. fprintf (list_file, "%33s:%s %s\n",
  805. segment_name (S_GET_SEGMENT (ptr)),
  806. buf, S_GET_NAME (ptr));
  807. }
  808. on_page++;
  809. listing_page (NULL);
  810. }
  811. }
  812. }
  813. if (!got_some)
  814. {
  815. fprintf (list_file, "NO DEFINED SYMBOLS\n");
  816. on_page++;
  817. }
  818. emit_line (NULL, "\n");
  819. got_some = 0;
  820. for (ptr = symbol_rootP; ptr != (symbolS *) NULL; ptr = symbol_next (ptr))
  821. {
  822. if (S_GET_NAME (ptr) && strlen (S_GET_NAME (ptr)) != 0)
  823. {
  824. if (S_GET_SEGMENT (ptr) == undefined_section)
  825. {
  826. if (!got_some)
  827. {
  828. got_some = 1;
  829. emit_line (NULL, "UNDEFINED SYMBOLS\n");
  830. }
  831. emit_line (NULL, "%s\n", S_GET_NAME (ptr));
  832. }
  833. }
  834. }
  835. if (!got_some)
  836. emit_line (NULL, "NO UNDEFINED SYMBOLS\n");
  837. }
  838. typedef struct cached_line
  839. {
  840. file_info_type * file;
  841. unsigned int line;
  842. char buffer [LISTING_RHS_WIDTH];
  843. } cached_line;
  844. static void
  845. print_source (file_info_type * current_file,
  846. list_info_type * list,
  847. unsigned int width)
  848. {
  849. #define NUM_CACHE_LINES 3
  850. static cached_line cached_lines[NUM_CACHE_LINES];
  851. static int next_free_line = 0;
  852. cached_line * cache = NULL;
  853. if (current_file->linenum > list->hll_line
  854. && list->hll_line > 0)
  855. {
  856. /* This can happen with modern optimizing compilers. The source
  857. lines from the high level language input program are split up
  858. and interleaved, meaning the line number we want to display
  859. (list->hll_line) can have already been displayed. We have
  860. three choices:
  861. a. Do nothing, since we have already displayed the source
  862. line. This was the old behaviour.
  863. b. Display the particular line requested again, but only
  864. that line. This is the new behaviour.
  865. c. Display the particular line requested again and reset
  866. the current_file->line_num value so that we redisplay
  867. all the following lines as well the next time we
  868. encounter a larger line number. */
  869. int i;
  870. /* Check the cache, maybe we already have the line saved. */
  871. for (i = 0; i < NUM_CACHE_LINES; i++)
  872. if (cached_lines[i].file == current_file
  873. && cached_lines[i].line == list->hll_line)
  874. {
  875. cache = cached_lines + i;
  876. break;
  877. }
  878. if (i == NUM_CACHE_LINES)
  879. {
  880. cache = cached_lines + next_free_line;
  881. next_free_line ++;
  882. if (next_free_line == NUM_CACHE_LINES)
  883. next_free_line = 0;
  884. cache->file = current_file;
  885. cache->line = list->hll_line;
  886. cache->buffer[0] = 0;
  887. rebuffer_line (current_file, cache->line, cache->buffer, width);
  888. }
  889. emit_line (list, "%4u:%-13s **** %s\n",
  890. cache->line, cache->file->filename, cache->buffer);
  891. return;
  892. }
  893. if (!current_file->at_end)
  894. {
  895. int num_lines_shown = 0;
  896. while (current_file->linenum < list->hll_line
  897. && !current_file->at_end)
  898. {
  899. const char *p;
  900. cache = cached_lines + next_free_line;
  901. cache->file = current_file;
  902. cache->line = current_file->linenum + 1;
  903. cache->buffer[0] = 0;
  904. p = buffer_line (current_file, cache->buffer, width);
  905. /* Cache optimization: If printing a group of lines
  906. cache the first and last lines in the group. */
  907. if (num_lines_shown == 0)
  908. {
  909. next_free_line ++;
  910. if (next_free_line == NUM_CACHE_LINES)
  911. next_free_line = 0;
  912. }
  913. emit_line (list, "%4u:%-13s **** %s\n",
  914. cache->line, cache->file->filename, p);
  915. num_lines_shown ++;
  916. }
  917. }
  918. }
  919. /* Sometimes the user doesn't want to be bothered by the debugging
  920. records inserted by the compiler, see if the line is suspicious. */
  921. static int
  922. debugging_pseudo (list_info_type *list, const char *line)
  923. {
  924. #ifdef OBJ_ELF
  925. static int in_debug;
  926. int was_debug;
  927. #endif
  928. if (list->debugging)
  929. {
  930. #ifdef OBJ_ELF
  931. in_debug = 1;
  932. #endif
  933. return 1;
  934. }
  935. #ifdef OBJ_ELF
  936. was_debug = in_debug;
  937. in_debug = 0;
  938. #endif
  939. while (ISSPACE (*line))
  940. line++;
  941. if (*line != '.')
  942. {
  943. #ifdef OBJ_ELF
  944. /* The ELF compiler sometimes emits blank lines after switching
  945. out of a debugging section. If the next line drops us back
  946. into debugging information, then don't print the blank line.
  947. This is a hack for a particular compiler behaviour, not a
  948. general case. */
  949. if (was_debug
  950. && *line == '\0'
  951. && list->next != NULL
  952. && list->next->debugging)
  953. {
  954. in_debug = 1;
  955. return 1;
  956. }
  957. #endif
  958. return 0;
  959. }
  960. line++;
  961. if (startswith (line, "def"))
  962. return 1;
  963. if (startswith (line, "val"))
  964. return 1;
  965. if (startswith (line, "scl"))
  966. return 1;
  967. if (startswith (line, "line"))
  968. return 1;
  969. if (startswith (line, "endef"))
  970. return 1;
  971. if (startswith (line, "ln"))
  972. return 1;
  973. if (startswith (line, "type"))
  974. return 1;
  975. if (startswith (line, "size"))
  976. return 1;
  977. if (startswith (line, "dim"))
  978. return 1;
  979. if (startswith (line, "tag"))
  980. return 1;
  981. if (startswith (line, "stabs"))
  982. return 1;
  983. if (startswith (line, "stabn"))
  984. return 1;
  985. return 0;
  986. }
  987. static void
  988. listing_listing (char *name ATTRIBUTE_UNUSED)
  989. {
  990. list_info_type *list = head;
  991. file_info_type *current_hll_file = (file_info_type *) NULL;
  992. char *buffer;
  993. const char *p;
  994. int show_listing = 1;
  995. unsigned int width;
  996. buffer = XNEWVEC (char, listing_rhs_width);
  997. data_buffer = XNEWVEC (char, MAX_BYTES);
  998. eject = 1;
  999. list = head->next;
  1000. while (list)
  1001. {
  1002. unsigned int list_line;
  1003. width = listing_rhs_width > paper_width ? paper_width :
  1004. listing_rhs_width;
  1005. list_line = list->line;
  1006. switch (list->edict)
  1007. {
  1008. case EDICT_LIST:
  1009. /* Skip all lines up to the current. */
  1010. list_line--;
  1011. break;
  1012. case EDICT_NOLIST:
  1013. show_listing--;
  1014. break;
  1015. case EDICT_NOLIST_NEXT:
  1016. if (show_listing == 0)
  1017. list_line--;
  1018. break;
  1019. case EDICT_EJECT:
  1020. break;
  1021. case EDICT_NONE:
  1022. break;
  1023. case EDICT_TITLE:
  1024. title = list->edict_arg;
  1025. break;
  1026. case EDICT_SBTTL:
  1027. subtitle = list->edict_arg;
  1028. break;
  1029. default:
  1030. abort ();
  1031. }
  1032. if (show_listing <= 0)
  1033. {
  1034. while (list->file->linenum < list_line
  1035. && !list->file->at_end)
  1036. p = buffer_line (list->file, buffer, width);
  1037. }
  1038. if (list->edict == EDICT_LIST
  1039. || (list->edict == EDICT_NOLIST_NEXT && show_listing == 0))
  1040. {
  1041. /* Enable listing for the single line that caused the enable. */
  1042. list_line++;
  1043. show_listing++;
  1044. }
  1045. if (show_listing > 0)
  1046. {
  1047. /* Scan down the list and print all the stuff which can be done
  1048. with this line (or lines). */
  1049. if (list->hll_file)
  1050. current_hll_file = list->hll_file;
  1051. if (current_hll_file && list->hll_line && (listing & LISTING_HLL))
  1052. print_source (current_hll_file, list, width);
  1053. if (list->line_contents)
  1054. {
  1055. if (!((listing & LISTING_NODEBUG)
  1056. && debugging_pseudo (list, list->line_contents)))
  1057. print_lines (list,
  1058. list->file->linenum == 0 ? list->line : list->file->linenum,
  1059. list->line_contents, calc_hex (list));
  1060. free (list->line_contents);
  1061. list->line_contents = NULL;
  1062. }
  1063. else
  1064. {
  1065. while (list->file->linenum < list_line
  1066. && !list->file->at_end)
  1067. {
  1068. unsigned int address;
  1069. p = buffer_line (list->file, buffer, width);
  1070. if (list->file->linenum < list_line)
  1071. address = ~(unsigned int) 0;
  1072. else
  1073. address = calc_hex (list);
  1074. if (!((listing & LISTING_NODEBUG)
  1075. && debugging_pseudo (list, p)))
  1076. print_lines (list, list->file->linenum, p, address);
  1077. }
  1078. }
  1079. if (list->edict == EDICT_EJECT)
  1080. eject = 1;
  1081. }
  1082. if (list->edict == EDICT_NOLIST_NEXT && show_listing == 1)
  1083. --show_listing;
  1084. list = list->next;
  1085. }
  1086. free (buffer);
  1087. free (data_buffer);
  1088. data_buffer = NULL;
  1089. }
  1090. /* Print time stamp in ISO format: yyyy-mm-ddThh:mm:ss.ss+/-zzzz. */
  1091. static void
  1092. print_timestamp (void)
  1093. {
  1094. const time_t now = time (NULL);
  1095. struct tm * timestamp;
  1096. char stampstr[MAX_DATELEN];
  1097. /* Any portable way to obtain subsecond values??? */
  1098. timestamp = localtime (&now);
  1099. strftime (stampstr, MAX_DATELEN, "%Y-%m-%dT%H:%M:%S.000%z", timestamp);
  1100. fprintf (list_file, _("\n time stamp \t: %s\n\n"), stampstr);
  1101. }
  1102. static void
  1103. print_single_option (char * opt, int *pos)
  1104. {
  1105. int opt_len = strlen (opt);
  1106. if ((*pos + opt_len) < paper_width)
  1107. {
  1108. fprintf (list_file, _("%s "), opt);
  1109. *pos = *pos + opt_len;
  1110. }
  1111. else
  1112. {
  1113. fprintf (list_file, _("\n\t%s "), opt);
  1114. *pos = opt_len;
  1115. }
  1116. }
  1117. /* Print options passed to as. */
  1118. static void
  1119. print_options (char ** argv)
  1120. {
  1121. const char *field_name = _("\n options passed\t: ");
  1122. int pos = strlen (field_name);
  1123. char **p;
  1124. fputs (field_name, list_file);
  1125. for (p = &argv[1]; *p != NULL; p++)
  1126. if (**p == '-')
  1127. {
  1128. /* Ignore these. */
  1129. if (strcmp (*p, "-o") == 0)
  1130. {
  1131. if (p[1] != NULL)
  1132. p++;
  1133. continue;
  1134. }
  1135. if (strcmp (*p, "-v") == 0)
  1136. continue;
  1137. print_single_option (*p, &pos);
  1138. }
  1139. }
  1140. /* Print a first section with basic info like file names, as version,
  1141. options passed, target, and timestamp.
  1142. The format of this section is as follows:
  1143. AS VERSION
  1144. fieldname TAB ':' fieldcontents
  1145. { TAB fieldcontents-cont } */
  1146. static void
  1147. listing_general_info (char ** argv)
  1148. {
  1149. /* Print the stuff on the first line. */
  1150. eject = 1;
  1151. listing_page (NULL);
  1152. fprintf (list_file,
  1153. _(" GNU assembler version %s (%s)\n\t using BFD version %s."),
  1154. VERSION, TARGET_ALIAS, BFD_VERSION_STRING);
  1155. print_options (argv);
  1156. fprintf (list_file, _("\n input file \t: %s"), fn);
  1157. fprintf (list_file, _("\n output file \t: %s"), out_file_name);
  1158. fprintf (list_file, _("\n target \t: %s"), TARGET_CANONICAL);
  1159. print_timestamp ();
  1160. }
  1161. void
  1162. listing_print (char *name, char **argv)
  1163. {
  1164. int using_stdout;
  1165. title = "";
  1166. subtitle = "";
  1167. if (name == NULL)
  1168. {
  1169. list_file = stdout;
  1170. using_stdout = 1;
  1171. }
  1172. else
  1173. {
  1174. list_file = fopen (name, FOPEN_WT);
  1175. if (list_file != NULL)
  1176. using_stdout = 0;
  1177. else
  1178. {
  1179. as_warn (_("can't open %s: %s"), name, xstrerror (errno));
  1180. list_file = stdout;
  1181. using_stdout = 1;
  1182. }
  1183. }
  1184. if (listing & LISTING_NOFORM)
  1185. paper_height = 0;
  1186. if (listing & LISTING_GENERAL)
  1187. listing_general_info (argv);
  1188. if (listing & LISTING_LISTING)
  1189. listing_listing (name);
  1190. if (listing & LISTING_SYMBOLS)
  1191. list_symbol_table ();
  1192. if (! using_stdout)
  1193. {
  1194. if (fclose (list_file) == EOF)
  1195. as_warn (_("can't close %s: %s"), name, xstrerror (errno));
  1196. }
  1197. if (last_open_file)
  1198. fclose (last_open_file);
  1199. }
  1200. void
  1201. listing_file (const char *name)
  1202. {
  1203. fn = name;
  1204. }
  1205. void
  1206. listing_eject (int ignore ATTRIBUTE_UNUSED)
  1207. {
  1208. if (listing)
  1209. listing_tail->edict = EDICT_EJECT;
  1210. }
  1211. /* Turn listing on or off. An argument of 0 means to turn off
  1212. listing. An argument of 1 means to turn on listing. An argument
  1213. of 2 means to turn off listing, but as of the next line; that is,
  1214. the current line should be listed, but the next line should not. */
  1215. void
  1216. listing_list (int on)
  1217. {
  1218. if (listing)
  1219. {
  1220. switch (on)
  1221. {
  1222. case 0:
  1223. if (listing_tail->edict == EDICT_LIST)
  1224. listing_tail->edict = EDICT_NONE;
  1225. else
  1226. listing_tail->edict = EDICT_NOLIST;
  1227. break;
  1228. case 1:
  1229. if (listing_tail->edict == EDICT_NOLIST
  1230. || listing_tail->edict == EDICT_NOLIST_NEXT)
  1231. listing_tail->edict = EDICT_NONE;
  1232. else
  1233. listing_tail->edict = EDICT_LIST;
  1234. break;
  1235. case 2:
  1236. listing_tail->edict = EDICT_NOLIST_NEXT;
  1237. break;
  1238. default:
  1239. abort ();
  1240. }
  1241. }
  1242. }
  1243. void
  1244. listing_psize (int width_only)
  1245. {
  1246. if (! width_only)
  1247. {
  1248. paper_height = get_absolute_expression ();
  1249. if (paper_height < 0 || paper_height > 1000)
  1250. {
  1251. paper_height = 0;
  1252. as_warn (_("strange paper height, set to no form"));
  1253. }
  1254. if (*input_line_pointer != ',')
  1255. {
  1256. demand_empty_rest_of_line ();
  1257. return;
  1258. }
  1259. ++input_line_pointer;
  1260. }
  1261. {
  1262. expressionS exp;
  1263. (void) expression_and_evaluate (& exp);
  1264. if (exp.X_op == O_constant)
  1265. {
  1266. offsetT new_width = exp.X_add_number;
  1267. if (new_width > 7)
  1268. paper_width = new_width;
  1269. else
  1270. as_bad (_("new paper width is too small"));
  1271. }
  1272. else if (exp.X_op != O_absent)
  1273. as_bad (_("bad or irreducible expression for paper width"));
  1274. else
  1275. as_bad (_("missing expression for paper width"));
  1276. }
  1277. demand_empty_rest_of_line ();
  1278. }
  1279. void
  1280. listing_nopage (int ignore ATTRIBUTE_UNUSED)
  1281. {
  1282. paper_height = 0;
  1283. }
  1284. void
  1285. listing_title (int depth)
  1286. {
  1287. int quoted;
  1288. char *start;
  1289. char *ttl;
  1290. unsigned int length;
  1291. SKIP_WHITESPACE ();
  1292. if (*input_line_pointer != '\"')
  1293. quoted = 0;
  1294. else
  1295. {
  1296. quoted = 1;
  1297. ++input_line_pointer;
  1298. }
  1299. start = input_line_pointer;
  1300. while (*input_line_pointer)
  1301. {
  1302. if (quoted
  1303. ? *input_line_pointer == '\"'
  1304. : is_end_of_line[(unsigned char) *input_line_pointer])
  1305. {
  1306. if (listing)
  1307. {
  1308. length = input_line_pointer - start;
  1309. ttl = xmemdup0 (start, length);
  1310. listing_tail->edict = depth ? EDICT_SBTTL : EDICT_TITLE;
  1311. listing_tail->edict_arg = ttl;
  1312. }
  1313. if (quoted)
  1314. input_line_pointer++;
  1315. demand_empty_rest_of_line ();
  1316. return;
  1317. }
  1318. else if (*input_line_pointer == '\n')
  1319. {
  1320. as_bad (_("new line in title"));
  1321. demand_empty_rest_of_line ();
  1322. return;
  1323. }
  1324. else
  1325. {
  1326. input_line_pointer++;
  1327. }
  1328. }
  1329. }
  1330. void
  1331. listing_source_line (unsigned int line)
  1332. {
  1333. if (listing)
  1334. {
  1335. new_frag ();
  1336. listing_tail->hll_line = line;
  1337. new_frag ();
  1338. }
  1339. }
  1340. void
  1341. listing_source_file (const char *file)
  1342. {
  1343. if (listing)
  1344. listing_tail->hll_file = file_info (file);
  1345. }
  1346. #else
  1347. /* Dummy functions for when compiled without listing enabled. */
  1348. void
  1349. listing_list (int on)
  1350. {
  1351. s_ignore (0);
  1352. }
  1353. void
  1354. listing_eject (int ignore)
  1355. {
  1356. s_ignore (0);
  1357. }
  1358. void
  1359. listing_psize (int ignore)
  1360. {
  1361. s_ignore (0);
  1362. }
  1363. void
  1364. listing_nopage (int ignore)
  1365. {
  1366. s_ignore (0);
  1367. }
  1368. void
  1369. listing_title (int depth)
  1370. {
  1371. s_ignore (0);
  1372. }
  1373. void
  1374. listing_file (const char *name)
  1375. {
  1376. }
  1377. void
  1378. listing_newline (char *name)
  1379. {
  1380. }
  1381. void
  1382. listing_source_line (unsigned int n)
  1383. {
  1384. }
  1385. void
  1386. listing_source_file (const char *n)
  1387. {
  1388. }
  1389. #endif