t76_width.pas 842 B

12345678910111213141516171819202122232425262728
  1. program t76_width;
  2. { t76 -- write FIELD WIDTHS.
  3. CALC.INC:135 is `writeln(I:2)'; DisplayCell later uses `Value:FW:DEC', the
  4. REAL form, which waits for real support. The width is an EXPRESSION (CALC
  5. passes FW, a variable), and it is pushed after the value, so the runtime's
  6. wrintw reads the value at [BP+6] and the width at [BP+4].
  7. Right-justification: pad = width - characters, the sign counting as one; a
  8. width narrower than the number does not truncate it. The last two lines
  9. are the no-width and width-1 cases, so a writer that always pads (or never
  10. does) is caught as well. }
  11. var
  12. i, w : integer;
  13. begin
  14. i := 7;
  15. writeln (i:3, '|');
  16. writeln (42:5, '|');
  17. writeln (-7:4, '|');
  18. writeln (123:2, '|');
  19. writeln (0:2, '|');
  20. w := 6;
  21. writeln (i:w, '|');
  22. writeln (i:1, '|');
  23. writeln (i, '|')
  24. end.