1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861
|
// -*- related-file-name: "../include/efont/t1item.hh" -*-
/* t1item.{cc,hh} -- items in a Type 1 font
*
* Copyright (c) 1998-2011 Eddie Kohler
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version. This program is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <efont/t1item.hh>
#include <efont/t1rw.hh>
#include <efont/t1interp.hh>
#include <efont/t1font.hh>
#include <lcdf/strtonum.h>
#include <ctype.h>
#include <string.h>
#include <sys/stat.h>
#ifndef WIN32
# include <unistd.h>
#endif
#if HAVE_BROKEN_STRTOD
# define strtod good_strtod
#endif
namespace Efont {
/*****
* Type1NullItem
**/
void
Type1NullItem::gen(Type1Writer &)
{
}
/*****
* Type1CopyItem
**/
void
Type1CopyItem::gen(Type1Writer &w)
{
w << _value << '\n';
}
/*****
* Type1EexecItem
**/
void
Type1EexecItem::gen(Type1Writer &w)
{
if (_eexec_on)
w << "currentfile eexec\n";
w.switch_eexec(_eexec_on);
}
/*****
* Type1Definition
**/
typedef Vector<double> NumVector;
Type1Definition::Type1Definition(PermString n, const String &v, PermString d)
: _name(n), _val(v), _definer(d)
{
_val.c_str(); // ensure it ends with '\0'
}
Type1Definition *
Type1Definition::make_string(PermString n, const String &v, PermString d)
{
Type1Definition *t1d = new Type1Definition(n, "", d);
t1d->set_string(v);
return t1d;
}
int
Type1Definition::slurp_string(StringAccum &accum, int pos, Type1Reader *reader)
{
int paren_level = 0;
char *s = accum.data() + pos;
do {
switch (*s++) {
case '(': paren_level++; break;
case ')': paren_level--; break;
case '\\': if (paren_level && *s) s++; break;
case 0:
if (!reader) return -1;
pos = s - accum.data();
accum.append('\n'); // add \n
if (!reader->next_line(accum)) return -1;
accum.c_str(); // ensure null termination
s = accum.data() + pos;
break;
}
} while (paren_level);
return s - accum.data();
}
int
Type1Definition::slurp_proc(StringAccum &accum, int pos, Type1Reader *reader)
{
int paren_level = 0;
int brace_level = 0;
char *s = accum.data() + pos;
do {
switch (*s++) {
case '{': if (!paren_level) brace_level++; break;
case '}': if (!paren_level) brace_level--; break;
case '(': paren_level++; break;
case ')': paren_level--; break;
case '\\': if (paren_level && *s) s++; break;
case '%':
if (!paren_level)
while (*s != '\n' && *s != '\r' && *s)
s++;
break;
case 0:
if (!reader) return -1;
pos = s - accum.data();
accum.append('\n'); // add \n
if (!reader->next_line(accum)) return -1;
accum.c_str(); // ensure null termination
s = accum.data() + pos;
break;
}
} while (brace_level);
return s - accum.data();
}
Type1Definition *
Type1Definition::make(StringAccum &accum, Type1Reader *reader,
bool force_definition)
{
char *s = accum.data();
while (isspace((unsigned char) *s))
s++;
if (*s != '/')
return 0;
s++;
int name_start_pos = s - accum.data();
// find NAME LENGTH
while (!isspace((unsigned char) *s) && *s != '[' && *s != '{' && *s != '('
&& *s != ']' && *s != '}' && *s != ')' && *s)
s++;
if (!*s)
return 0;
int name_end_pos = s - accum.data();
while (isspace((unsigned char) *s))
s++;
int val_pos = s - accum.data();
int val_end_pos = -1;
bool check_def = false;
if (*s == '}' || *s == ']' || *s == ')' || *s == 0)
return 0;
else if (*s == '(')
val_end_pos = slurp_string(accum, val_pos, reader);
else if (*s == '{')
val_end_pos = slurp_proc(accum, val_pos, reader);
else if (*s == '[') {
int brack_level = 0;
do {
switch (*s++) {
case '[': brack_level++; break;
case ']': brack_level--; break;
case '(': case ')': case 0: return 0;
}
} while (brack_level);
val_end_pos = s - accum.data();
} else {
while (!isspace((unsigned char) *s) && *s)
s++;
val_end_pos = s - accum.data();
if (!force_definition) check_def = true;
}
if (val_end_pos < 0)
return 0;
s = accum.data() + val_end_pos;
while (isspace((unsigned char) *s))
s++;
if (check_def && (s[0] != 'd' || s[1] != 'e' || s[2] != 'f'))
if (strncmp(s, "dict def", 8) != 0)
return 0;
PermString name(accum.data()+name_start_pos, name_end_pos - name_start_pos);
PermString def(s, accum.length() - (s - accum.data()));
String value = String(accum.data() + val_pos, val_end_pos - val_pos);
return new Type1Definition(name, value, def);
}
void
Type1Definition::gen(Type1Writer &w)
{
w << '/' << _name << ' ' << _val << ' ' << _definer << '\n';
}
void
Type1Definition::gen(StringAccum &sa)
{
sa << '/' << _name << ' ' << _val << ' ' << _definer;
}
bool
Type1Definition::value_bool(bool &b) const
{
if (_val == "true") {
b = true;
return true;
} else if (_val == "false") {
b = false;
return true;
} else
return false;
}
bool
Type1Definition::value_int(int &i) const
{
char *s;
i = strtol(_val.data(), &s, 10);
return (*s == 0);
}
bool
Type1Definition::value_num(double &d) const
{
char *s;
d = strtonumber(_val.data(), &s);
return (*s == 0);
}
bool
Type1Definition::value_string(String &str) const
{
if (_val.length() == 0 || _val[0] != '(' || _val.back() != ')')
return false;
StringAccum sa;
int pos, first_pos = 1, len = _val.length() - 1;
for (pos = 1; pos < len; pos++)
if (_val[pos] == '\\') {
sa.append(_val.data() + first_pos, pos - first_pos);
pos++;
switch (pos < len ? _val[pos] : -1) {
case '\r':
pos++;
if (pos < len && _val[pos] == '\n')
pos++;
break;
case '\n':
pos++;
break;
case '0': case '1': case '2': case '3':
case '4': case '5': case '6': case '7': {
int c = _val[pos++] - '0';
for (int i = 1; pos < len && i < 3 && _val[pos] >= '0' && _val[pos] <= '7'; i++, pos++)
c = (c << 3) | (_val[pos] - '0');
sa.append((char) c);
break;
}
case 'n':
sa << '\n';
pos++;
break;
case 'r':
sa << '\r';
pos++;
break;
case 't':
sa << '\t';
pos++;
break;
case 'b':
sa << '\b';
pos++;
break;
case 'f':
sa << '\f';
pos++;
break;
default:
sa << _val[pos];
pos++;
break;
}
first_pos = pos;
}
sa.append(_val.data() + first_pos, len - first_pos);
str = sa.take_string();
return true;
}
bool
Type1Definition::value_name(PermString &str) const
{
if (_val.length() == 0 || _val[0] != '/')
return false;
int pos;
for (pos = 1; pos < _val.length(); pos++)
if (isspace((unsigned char) _val[pos]) || _val[pos] == '/')
return false;
str = PermString(_val.data() + 1, pos - 1);
return true;
}
static bool
strtonumvec(const char *f, const char **endf, NumVector &v)
{
v.clear();
char *s = (char *)f;
if (*s != '[' && *s != '{')
return false;
s++;
while (1) {
while (isspace((unsigned char) *s))
s++;
if (isdigit((unsigned char) *s) || *s == '.' || *s == '-')
v.push_back( strtonumber(s, &s) );
else {
if (endf)
*endf = s + 1;
return (*s == ']' || *s == '}');
}
}
}
bool
Type1Definition::value_numvec(NumVector &v) const
{
return strtonumvec(_val.data(), 0, v);
}
static bool
strtonumvec_vec(const char *f, const char **endf, Vector<NumVector> &v)
{
v.clear();
const char *s = f;
if (*s != '[' && *s != '{')
return false;
s++;
while (1) {
while (isspace((unsigned char) *s))
s++;
if (*s == '[' || *s == '{') {
NumVector subv;
if (!strtonumvec(s, &s, subv))
return false;
v.push_back(subv);
} else {
if (endf)
*endf = s + 1;
return (*s == ']' || *s == '}');
}
}
}
bool
Type1Definition::value_numvec_vec(Vector<NumVector> &v) const
{
return strtonumvec_vec(_val.data(), 0, v);
}
bool
Type1Definition::value_normalize(Vector<NumVector> &in,
Vector<NumVector> &out) const
{
in.clear();
out.clear();
const char *s = _val.data();
if (*s++ != '[')
return false;
while (1) {
while (isspace((unsigned char) *s))
s++;
if (*s == '[') {
Vector<NumVector> sub;
if (!strtonumvec_vec(s, &s, sub))
return false;
NumVector subin;
NumVector subout;
for (int i = 0; i < sub.size(); i++)
if (sub[i].size() == 2) {
subin.push_back(sub[i][0]);
subout.push_back(sub[i][1]);
} else
return false;
in.push_back(subin);
out.push_back(subout);
} else
return (*s == ']');
}
}
bool
Type1Definition::value_namevec(Vector<PermString> &v) const
{
v.clear();
const char *s = _val.data();
if (*s++ != '[')
return false;
while (1) {
while (isspace((unsigned char) *s))
s++;
if (*s == '/')
s++;
if (isalnum((unsigned char) *s)) {
const char *start = s;
while (*s && !isspace((unsigned char) *s) && *s != ']' && *s != '/')
s++;
v.push_back(PermString(start, s - start));
} else
return (*s == ']');
}
}
void
Type1Definition::set_bool(bool b)
{
set_val(b ? "true" : "false");
}
void
Type1Definition::set_int(int i)
{
set_val(String(i));
}
void
Type1Definition::set_num(double n)
{
set_val(String(n));
}
void
Type1Definition::set_string(const String &v)
{
const char *s = v.data();
int len = v.length();
int left = 0;
StringAccum sa;
sa << '(';
for (int pos = 0; pos < len; pos++)
if ((s[pos] < ' ' && !isspace((unsigned char) s[pos])) || ((unsigned char)s[pos]) > 0176 || s[pos] == '(' || s[pos] == ')' || s[pos] == '\\') {
sa << v.substring(left, pos - left) << '\\';
if (s[pos] == '(' || s[pos] == ')' || s[pos] == '\\')
sa << s[pos];
else
sprintf(sa.reserve(8), "%03o", (unsigned char) (s[pos]));
left = pos + 1;
}
sa << v.substring(left) << ')';
_val = sa.take_string();
}
void
Type1Definition::set_name(PermString str, bool name)
{
StringAccum sa;
if (name)
sa << '/';
sa << str;
set_val(sa);
}
static void
accum_numvec(StringAccum &sa, const NumVector &nv, bool executable)
{
char open = (executable ? '{' : '[');
for (int i = 0; i < nv.size(); i++)
sa << (i ? ' ' : open) << nv[i];
sa << (executable ? '}' : ']');
}
void
Type1Definition::set_numvec(const NumVector &nv, bool executable)
{
StringAccum sa;
accum_numvec(sa, nv, executable);
set_val(sa);
}
void
Type1Definition::set_numvec_vec(const Vector<NumVector> &nv)
{
StringAccum sa;
sa << '[';
for (int i = 0; i < nv.size(); i++)
accum_numvec(sa, nv[i], false);
sa << ']';
set_val(sa);
}
void
Type1Definition::set_normalize(const Vector<NumVector> &vin,
const Vector<NumVector> &vout)
{
StringAccum sa;
sa << '[';
for (int i = 0; i < vin.size(); i++) {
const NumVector &vini = vin[i];
const NumVector &vouti = vout[i];
sa << '[';
for (int j = 0; j < vini.size(); j++)
sa << '[' << vini[j] << ' ' << vouti[j] << ']';
sa << ']';
}
sa << ']';
set_val(sa);
}
void
Type1Definition::set_namevec(const Vector<PermString> &v, bool executable)
{
StringAccum sa;
sa << '[';
for (int i = 0; i < v.size(); i++) {
if (i) sa << ' ';
if (executable) sa << '/';
sa << v[i];
}
sa << ']';
set_val(sa);
}
/*****
* Type1Encoding
**/
static PermString::Initializer initializer;
static PermString dot_notdef(".notdef");
Type1Encoding::Type1Encoding()
: _v(new PermString[256]), _copy_of(0), _definer("readonly def")
{
for (int i = 0; i < 256; i++)
_v[i] = dot_notdef;
}
Type1Encoding::Type1Encoding(const Type1Encoding &o)
: Type1Item(), _definer(o._definer)
{
if (o._copy_of) {
_v = o._v;
_copy_of = o._copy_of;
} else {
_v = new PermString[256];
_copy_of = 0;
for (int i = 0; i < 256; i++)
_v[i] = o._v[i];
}
}
Type1Encoding::Type1Encoding(Type1Encoding *copy_of)
: _v(copy_of->_v), _copy_of(copy_of), _definer(copy_of->_definer)
{
}
Type1Encoding::~Type1Encoding()
{
if (!_copy_of)
delete[] _v;
}
void
Type1Encoding::unshare()
{
if (_copy_of) {
PermString *new_v = new PermString[256];
memcpy(new_v, _v, sizeof(PermString) * 256);
_v = new_v;
_copy_of = 0;
}
}
void
Type1Encoding::clear()
{
unshare();
for (int i = 0; i < 256; i++)
_v[i] = dot_notdef;
}
static Type1Encoding *canonical_standard_encoding;
Type1Encoding *
Type1Encoding::standard_encoding()
{
if (!canonical_standard_encoding) {
canonical_standard_encoding = new Type1Encoding;
for (int i = 0; i < 256; i++)
if (Charstring::standard_encoding[i])
canonical_standard_encoding->put(i, Charstring::standard_encoding[i]);
}
// Return a copy of the cached encoding. When it's deleted, we won't be.
return new Type1Encoding(canonical_standard_encoding);
}
void
Type1Encoding::gen(Type1Writer &w)
{
if (_copy_of && _copy_of == canonical_standard_encoding)
w << "/Encoding StandardEncoding def\n";
else {
w << "/Encoding 256 array\n0 1 255 {1 index exch /.notdef put} for\n";
for (int i = 0; i < 256; i++)
if (_v[i] != dot_notdef)
w << "dup " << i << " /" << _v[i] << " put\n";
w << _definer << '\n';
}
}
/*****
* Type1Subr
**/
Type1Subr::Type1Subr(PermString n, int num, PermString definer,
int lenIV, const String &s)
: _name(n), _subrno(num), _definer(definer), _cs(lenIV, s)
{
}
Type1Subr::Type1Subr(PermString n, int num, PermString definer,
const Type1Charstring &t1cs)
: _name(n), _subrno(num), _definer(definer), _cs(t1cs)
{
}
Type1Subr *
Type1Subr::make(const char *s_in, int s_len, int cs_pos, int cs_len, int lenIV)
{
/* USAGE NOTE: You must ensure that s_in contains a valid subroutine string
before calling Type1Subr::make. Type1Reader::was_charstring() is a good
guarantee of this.
A valid subroutine string is one of the following:
/[char_name] ### charstring_start ........
dup [subrno] ### charstring_start .... */
const char *s = s_in;
PermString name;
int subrno = 0;
// Force literal spaces rather than isspace().
if (*s == '/') {
const char *nstart = ++s;
while (!isspace((unsigned char) *s) && *s)
s++;
name = PermString(nstart, s - nstart);
} else {
// dup [subrno] ...
s += 3;
while (isspace((unsigned char) *s))
s++;
subrno = strtol(s, (char **)&s, 10);
}
s = s_in + cs_pos;
// Lazily decrypt the charstring.
PermString definer = PermString(s + cs_len, s_len - cs_len - cs_pos);
return new Type1Subr(name, subrno, definer, lenIV, String(s, cs_len));
}
Type1Subr *
Type1Subr::make_subr(int subrno, const Type1Charstring &cs, PermString definer)
{
return new Type1Subr(PermString(), subrno, definer, cs);
}
Type1Subr *
Type1Subr::make_glyph(PermString glyph, const Type1Charstring &cs, PermString definer)
{
return new Type1Subr(glyph, -1, definer, cs);
}
void
Type1Subr::gen(Type1Writer &w)
{
int len = _cs.length();
const unsigned char *data = _cs.data();
if (is_subr())
w << "dup " << _subrno << ' ' << len + w.lenIV() << w.charstring_start();
else
w << '/' << _name << ' ' << len + w.lenIV() << w.charstring_start();
if (w.lenIV() < 0) {
// lenIV < 0 means charstrings are unencrypted
w.print((const char *)data, len);
} else {
// PERFORMANCE NOTE: Putting the charstring in a buffer of known length
// and printing that buffer rather than one char at a time is an OK
// optimization. (around 10%)
unsigned char *buf = new unsigned char[len + w.lenIV()];
unsigned char *t = buf;
int r = t1R_cs;
for (int i = 0; i < w.lenIV(); i++) {
unsigned char c = (unsigned char)(r >> 8);
*t++ = c;
r = ((c + r) * t1C1 + t1C2) & 0xFFFF;
}
for (int i = 0; i < len; i++, data++) {
unsigned char c = (*data ^ (r >> 8));
*t++ = c;
r = ((c + r) * t1C1 + t1C2) & 0xFFFF;
}
w.print((char *)buf, len + w.lenIV());
delete[] buf;
}
w << _definer << '\n';
}
/*****
* Type1SubrGroupItem
**/
Type1SubrGroupItem::Type1SubrGroupItem(Type1Font *font, bool is_subrs, const String &value)
: _font(font), _is_subrs(is_subrs), _value(value)
{
}
Type1SubrGroupItem::Type1SubrGroupItem(const Type1SubrGroupItem &from, Type1Font *font)
: _font(font), _is_subrs(from._is_subrs),
_value(from._value), _end_text(from._end_text)
{
}
void
Type1SubrGroupItem::add_end_text(const String &s)
{
_end_text += s + "\n";
}
void
Type1SubrGroupItem::gen(Type1Writer &w)
{
Type1Font *font = _font;
int pos = _value.find_left(_is_subrs ? " array" : " dict");
if (pos >= 1 && isdigit((unsigned char) _value[pos - 1])) {
int numpos = pos - 1;
while (numpos >= 1 && isdigit((unsigned char) _value[numpos - 1]))
numpos--;
int n;
if (_is_subrs) {
n = font->nsubrs();
while (n && !font->subr(n - 1))
n--;
} else
n = font->nglyphs();
w << _value.substring(0, numpos) << n << _value.substring(pos);
} else
w << _value;
w << '\n';
if (_is_subrs) {
int count = font->nsubrs();
for (int i = 0; i < count; i++)
if (Type1Subr *g = font->subr_x(i))
g->gen(w);
} else {
int count = font->nglyphs();
for (int i = 0; i < count; i++)
if (Type1Subr *g = font->glyph_x(i))
g->gen(w);
}
w << _end_text;
}
/*****
* Type1IncludedFont
**/
Type1IncludedFont::Type1IncludedFont(Type1Font *font, int unique_id)
: _included_font(font), _unique_id(unique_id)
{
}
Type1IncludedFont::~Type1IncludedFont()
{
delete _included_font;
}
void
Type1IncludedFont::gen(Type1Writer &w)
{
FILE *f = tmpfile();
if (!f)
return;
// write included font
Type1PFAWriter new_w(f);
_included_font->write(new_w);
fflush(f);
struct stat s;
fstat(fileno(f), &s);
w << "FontDirectory /" << _included_font->font_name() << " known{\n"
<< "/" << _included_font->font_name()
<< " findfont dup /UniqueID known {dup /UniqueID get "
<< _unique_id
<< " eq exch /FontType get 1 eq and}{pop false}ifelse {\nsave userdict/fbufstr 512 string put\n"
<< (int)(s.st_size / 512)
<< "{currentfile fbufstr readstring{pop}{clear currentfile\nclosefile/fontdownload/unexpectedEOF/.error cvx exec}ifelse}repeat\ncurrentfile "
<< (int)(s.st_size % 512)
<< " string readstring{pop}{clear currentfile\nclosefile/fontdownload/unexpectedEOF/.error cvx exec}ifelse\nrestore}if}if\n";
rewind(f);
char str[2048];
while (1) {
int r = fread(str, 1, 2048, f);
if (r <= 0)
break;
w.print(str, r);
}
fclose(f);
}
}
|