- ListLine* L;
-
- /* Get the length of the line */
- unsigned Len = SB_GetLen (Line);
-
- /* Ignore trailing newlines */
- while (Len > 0 && SB_AtUnchecked (Line, Len-1) == '\n') {
- --Len;
- }
-
- /* Allocate memory */
- L = xmalloc (sizeof (ListLine) + Len);
-
- /* Initialize the fields. */
- L->Next = 0;
- L->FragList = 0;
- L->FragLast = 0;
- L->PC = GetPC ();
- L->Reloc = GetRelocMode ();
- L->File = File;
- L->Depth = Depth;
- L->Output = (ListingEnabled > 0);
- L->ListBytes = (unsigned char) ListBytes;
- memcpy (L->Line, SB_GetConstBuf (Line), Len);
- L->Line[Len] = '\0';
-
- /* Insert the line into the list of lines */
- if (LineList == 0) {
- LineList = L;
- } else {
- LineLast->Next = L;
- }
- LineLast = L;
+ ListLine* L;
+
+ /* Get the length of the line */
+ unsigned Len = SB_GetLen (Line);
+
+ /* Ignore trailing newlines */
+ while (Len > 0 && SB_AtUnchecked (Line, Len-1) == '\n') {
+ --Len;
+ }
+
+ /* Allocate memory */
+ L = xmalloc (sizeof (ListLine) + Len);
+
+ /* Initialize the fields. */
+ L->Next = 0;
+ L->FragList = 0;
+ L->FragLast = 0;
+ L->PC = GetPC ();
+ L->Reloc = GetRelocMode ();
+ L->File = File;
+ L->Depth = Depth;
+ L->Output = (ListingEnabled > 0);
+ L->ListBytes = (unsigned char) ListBytes;
+ memcpy (L->Line, SB_GetConstBuf (Line), Len);
+ L->Line[Len] = '\0';
+
+ /* Insert the line into the list of lines */
+ if (LineList == 0) {
+ LineList = L;
+ } else {
+ LineLast->Next = L;
+ }
+ LineLast = L;
- /* Make the last loaded line the current line */
- /* ###### This code is a hack! We really need to do it right
- * as soon as we know, how:-(
- */
- if (LineCur && LineCur->Next && LineCur->Next != LineLast) {
- ListLine* L = LineCur;
- do {
- L = L->Next;
- /* Set the values for this line */
- CHECK (L != 0);
- L->PC = GetPC ();
- L->Reloc = GetRelocMode ();
- L->Output = (ListingEnabled > 0);
- L->ListBytes = (unsigned char) ListBytes;
- } while (L->Next != LineLast);
- }
- LineCur = LineLast;
-
- /* Set the values for this line */
- CHECK (LineCur != 0);
- LineCur->PC = GetPC ();
- LineCur->Reloc = GetRelocMode ();
- LineCur->Output = (ListingEnabled > 0);
- LineCur->ListBytes = (unsigned char) ListBytes;
+ /* Make the last loaded line the current line */
+ /* ###### This code is a hack! We really need to do it right
+ * as soon as we know, how:-(
+ */
+ if (LineCur && LineCur->Next && LineCur->Next != LineLast) {
+ ListLine* L = LineCur;
+ do {
+ L = L->Next;
+ /* Set the values for this line */
+ CHECK (L != 0);
+ L->PC = GetPC ();
+ L->Reloc = GetRelocMode ();
+ L->Output = (ListingEnabled > 0);
+ L->ListBytes = (unsigned char) ListBytes;
+ } while (L->Next != LineLast);
+ }
+ LineCur = LineLast;
+
+ /* Set the values for this line */
+ CHECK (LineCur != 0);
+ LineCur->PC = GetPC ();
+ LineCur->Reloc = GetRelocMode ();
+ LineCur->Output = (ListingEnabled > 0);
+ LineCur->ListBytes = (unsigned char) ListBytes;
- '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
+ '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
- char* Buf;
- char* B;
- unsigned Count;
- unsigned I;
- char* Line;
-
- /* If we should not output this line, go to the next */
- if (L->Output == 0) {
- L = L->Next;
- continue;
- }
-
- /* If we don't have a fragment list for this line, things are easy */
- if (L->FragList == 0) {
- PrintLine (F, MakeLineHeader (HeaderBuf, L), L->Line, L);
- L = L->Next;
- continue;
- }
-
- /* Count the number of bytes in the complete fragment list */
- Count = 0;
- Frag = L->FragList;
- while (Frag) {
- Count += Frag->Len;
- Frag = Frag->LineList;
- }
-
- /* Allocate memory for the given number of bytes */
- Buf = xmalloc (Count*2+1);
-
- /* Copy an ASCII representation of the bytes into the buffer */
- B = Buf;
- Frag = L->FragList;
- while (Frag) {
-
- /* Write data depending on the type */
- switch (Frag->Type) {
-
- case FRAG_LITERAL:
- for (I = 0; I < Frag->Len; ++I) {
- B = AddHex (B, Frag->V.Data[I]);
- }
- break;
-
- case FRAG_EXPR:
- case FRAG_SEXPR:
- B = AddMult (B, 'r', Frag->Len*2);
- break;
-
- case FRAG_FILL:
- B = AddMult (B, 'x', Frag->Len*2);
- break;
-
- default:
- Internal ("Invalid fragment type: %u", Frag->Type);
-
- }
-
- /* Next fragment */
- Frag = Frag->LineList;
-
- }
-
- /* Limit the number of bytes actually printed */
- if (L->ListBytes != 0) {
- /* Not unlimited */
- if (Count > L->ListBytes) {
- Count = L->ListBytes;
- }
- }
-
- /* Output the data. The format of a listing line is:
- *
- * PPPPPPm I 11 22 33 44
- *
- * where
- *
- * PPPPPP is the PC
- * m is the mode ('r' or empty)
- * I is the include level
- * 11 .. are code or data bytes
- */
- Line = L->Line;
- B = Buf;
- while (Count) {
-
- unsigned Chunk;
- char* P;
-
- /* Prepare the line header */
- MakeLineHeader (HeaderBuf, L);
-
- /* Get the number of bytes for the next line */
- Chunk = Count;
- if (Chunk > 4) {
- Chunk = 4;
- }
- Count -= Chunk;
-
- /* Increment the program counter. Since we don't need the PC stored
- * in the LineList object for anything else, just increment this
- * variable.
- */
- L->PC += Chunk;
-
- /* Copy the bytes into the line */
- P = HeaderBuf + 11;
- for (I = 0; I < Chunk; ++I) {
- *P++ = *B++;
- *P++ = *B++;
- *P++ = ' ';
- }
-
- /* Output this line */
- PrintLine (F, HeaderBuf, Line, L);
-
- /* Don't output a line twice */
- Line = "";
-
- }
-
- /* Delete the temporary buffer */
- xfree (Buf);
-
- /* Next line */
- L = L->Next;
+ char* Buf;
+ char* B;
+ unsigned Count;
+ unsigned I;
+ char* Line;
+
+ /* If we should not output this line, go to the next */
+ if (L->Output == 0) {
+ L = L->Next;
+ continue;
+ }
+
+ /* If we don't have a fragment list for this line, things are easy */
+ if (L->FragList == 0) {
+ PrintLine (F, MakeLineHeader (HeaderBuf, L), L->Line, L);
+ L = L->Next;
+ continue;
+ }
+
+ /* Count the number of bytes in the complete fragment list */
+ Count = 0;
+ Frag = L->FragList;
+ while (Frag) {
+ Count += Frag->Len;
+ Frag = Frag->LineList;
+ }
+
+ /* Allocate memory for the given number of bytes */
+ Buf = xmalloc (Count*2+1);
+
+ /* Copy an ASCII representation of the bytes into the buffer */
+ B = Buf;
+ Frag = L->FragList;
+ while (Frag) {
+
+ /* Write data depending on the type */
+ switch (Frag->Type) {
+
+ case FRAG_LITERAL:
+ for (I = 0; I < Frag->Len; ++I) {
+ B = AddHex (B, Frag->V.Data[I]);
+ }
+ break;
+
+ case FRAG_EXPR:
+ case FRAG_SEXPR:
+ B = AddMult (B, 'r', Frag->Len*2);
+ break;
+
+ case FRAG_FILL:
+ B = AddMult (B, 'x', Frag->Len*2);
+ break;
+
+ default:
+ Internal ("Invalid fragment type: %u", Frag->Type);
+
+ }
+
+ /* Next fragment */
+ Frag = Frag->LineList;
+
+ }
+
+ /* Limit the number of bytes actually printed */
+ if (L->ListBytes != 0) {
+ /* Not unlimited */
+ if (Count > L->ListBytes) {
+ Count = L->ListBytes;
+ }
+ }
+
+ /* Output the data. The format of a listing line is:
+ *
+ * PPPPPPm I 11 22 33 44
+ *
+ * where
+ *
+ * PPPPPP is the PC
+ * m is the mode ('r' or empty)
+ * I is the include level
+ * 11 .. are code or data bytes
+ */
+ Line = L->Line;
+ B = Buf;
+ while (Count) {
+
+ unsigned Chunk;
+ char* P;
+
+ /* Prepare the line header */
+ MakeLineHeader (HeaderBuf, L);
+
+ /* Get the number of bytes for the next line */
+ Chunk = Count;
+ if (Chunk > 4) {
+ Chunk = 4;
+ }
+ Count -= Chunk;
+
+ /* Increment the program counter. Since we don't need the PC stored
+ * in the LineList object for anything else, just increment this
+ * variable.
+ */
+ L->PC += Chunk;
+
+ /* Copy the bytes into the line */
+ P = HeaderBuf + 11;
+ for (I = 0; I < Chunk; ++I) {
+ *P++ = *B++;
+ *P++ = *B++;
+ *P++ = ' ';
+ }
+
+ /* Output this line */
+ PrintLine (F, HeaderBuf, Line, L);
+
+ /* Don't output a line twice */
+ Line = "";
+
+ }
+
+ /* Delete the temporary buffer */
+ xfree (Buf);
+
+ /* Next line */
+ L = L->Next;