owbase.pas 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. {
  2. $Id$
  3. Copyright (c) 1999 by Peter Vreman
  4. Contains the base stuff for writing for object files to disk
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit owbase;
  19. interface
  20. type
  21. pobjectwriter=^tobjectwriter;
  22. tobjectwriter=object
  23. constructor Init;
  24. destructor Done;virtual;
  25. procedure create(const fn:string);virtual;
  26. procedure close;virtual;
  27. procedure writesym(sym:string);virtual;
  28. procedure write(var b;len:longint);virtual;
  29. private
  30. f : file;
  31. opened : boolean;
  32. buf : pchar;
  33. bufidx : longint;
  34. procedure writebuf;
  35. end;
  36. implementation
  37. const
  38. {$ifdef TP}
  39. bufsize = 256;
  40. {$else}
  41. bufsize = 32768;
  42. {$endif}
  43. constructor tobjectwriter.init;
  44. begin
  45. getmem(buf,bufsize);
  46. bufidx:=0;
  47. opened:=false;
  48. end;
  49. destructor tobjectwriter.done;
  50. begin
  51. if opened then
  52. close;
  53. freemem(buf,bufsize);
  54. end;
  55. procedure tobjectwriter.create(const fn:string);
  56. begin
  57. assign(f,fn);
  58. {$I-}
  59. rewrite(f,1);
  60. {$I+}
  61. if ioresult<>0 then
  62. exit;
  63. bufidx:=0;
  64. opened:=true;
  65. end;
  66. procedure tobjectwriter.close;
  67. begin
  68. if bufidx>0 then
  69. writebuf;
  70. system.close(f);
  71. opened:=false;
  72. end;
  73. procedure tobjectwriter.writebuf;
  74. begin
  75. blockwrite(f,buf^,bufidx);
  76. bufidx:=0;
  77. end;
  78. procedure tobjectwriter.writesym(sym:string);
  79. begin
  80. end;
  81. procedure tobjectwriter.write(var b;len:longint);
  82. var
  83. p : pchar;
  84. left,
  85. idx : longint;
  86. begin
  87. p:=pchar(@b);
  88. idx:=0;
  89. while len>0 do
  90. begin
  91. left:=bufsize-bufidx;
  92. if len>left then
  93. begin
  94. move(p[idx],buf[bufidx],left);
  95. dec(len,left);
  96. inc(idx,left);
  97. inc(bufidx,left);
  98. writebuf;
  99. end
  100. else
  101. begin
  102. move(p[idx],buf[bufidx],len);
  103. inc(bufidx,len);
  104. exit;
  105. end;
  106. end;
  107. end;
  108. end.
  109. {
  110. $Log$
  111. Revision 1.1 1999-05-01 13:24:26 peter
  112. * merged nasm compiler
  113. * old asm moved to oldasm/
  114. Revision 1.2 1999/03/18 20:30:51 peter
  115. + .a writer
  116. Revision 1.1 1999/03/08 14:51:11 peter
  117. + smartlinking for ag386bin
  118. }