home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume37 / xd / part01 < prev    next >
Encoding:
Text File  |  1993-05-15  |  18.8 KB  |  666 lines

  1. Newsgroups: comp.sources.misc
  2. From: kelvin@autodesk.com (John Walker)
  3. Subject: v37i056:  xd - Hexadecimal dump/load/edit filter, Part01/01
  4. Message-ID: <1993May16.010225.16229@sparky.imd.sterling.com>
  5. X-Md4-Signature: 87362a932d771d68189158665f1dcdf0
  6. Date: Sun, 16 May 1993 01:02:25 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: kelvin@autodesk.com (John Walker)
  10. Posting-number: Volume 37, Issue 56
  11. Archive-name: xd/part01
  12. Environment: UNIX, Sun, SGI
  13.  
  14. XD dumps files as hex bytes, optionally showing the same bytes as ISO
  15. characters, with non-printing characters (defined according to ISO
  16. 8859/1 Latin-1) rendered as periods.  File addresses are shown as hex
  17. numbers without leading zeroes.
  18.  
  19. If you specify the "-l" option, XD will *read* a dump file in the same
  20. format it writes and create a binary file from the hex data.  This
  21. allows you to dump a binary file with XD, edit it with your favourite
  22. text editor, then make a new binary file containing whatever changes
  23. you made.  When creating a binary file, XD normally assumes you've
  24. only changed data in place (neither expanding nor contracting the
  25. file) and verifies file addresses to guarantee this.  However, if you
  26. set the "-s" (stream) option, file addresses are ignored and you're
  27. free to insert or delete bytes at will.  These options effectively
  28. turn your existing text editor into a binary file editor without
  29. requiring you to learn any new commands.
  30.  
  31. Finally, the "-d" option reads a binary file and emits a C language
  32. data declaration which contains the data from the file.  This is handy
  33. when you wish to embed binary data within programs.
  34.  
  35. ------------------------------ Cut here -----------------------------
  36. #! /bin/sh
  37. # This is a shell archive.  Remove anything before this line, then feed it
  38. # into a shell via "sh file" or similar.  To overwrite existing files,
  39. # type "sh file -c".
  40. # Contents:  README Makefile xd.1 xd.c
  41. # Wrapped by kent@sparky on Sat May 15 19:59:25 1993
  42. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  43. echo If this archive is complete, you will see the following message:
  44. echo '          "shar: End of archive 1 (of 1)."'
  45. if test -f 'README' -a "${1}" != "-c" ; then 
  46.   echo shar: Will not clobber existing file \"'README'\"
  47. else
  48.   echo shar: Extracting \"'README'\" \(2665 characters\)
  49.   sed "s/^X//" >'README' <<'END_OF_FILE'
  50. X                                  XD
  51. X                      Hexadecimal dump and load
  52. X
  53. X                            by John Walker
  54. X                 Revision 1  --  December 30th, 1991
  55. X
  56. XThis program was created  out  of  exasperation  with  the  Unix  "od"
  57. Xprogram  which,  notwithstanding  its  acronym  of  "octal  dump" will
  58. Xhappily make hexadecimal dumps of files but, in tribute to  the  past,
  59. Xrefuses to display file addresses as anything other than octal.
  60. X
  61. XXD is a hexadecimal file dump program without pretensions of grandeur.
  62. XIt  dumps files as hex bytes, optionally showing the same bytes as ISO
  63. Xcharacters,  with  non-printing  characters  (defined according to ISO
  64. X8859/1 Latin-1) rendered as periods.  File addresses are shown as  hex
  65. Xnumbers without leading zeroes.
  66. X
  67. XXD  has  a  few  more little tricks up its sleeve.  If you specify the
  68. X"-l" option, XD will *read* a dump file in the same format  it  writes
  69. Xand create a binary file from the hex data.  This allows you to dump a
  70. Xbinary file with XD, edit it with your  favourite  text  editor,  then
  71. Xmake  a  new  binary  file containing whatever changes you made.  When
  72. Xcreating a binary file, XD normally assumes you've only  changed  data
  73. Xin  place  (neither  expanding  nor contracting the file) and verifies
  74. Xfile addresses to guarantee  this.   However,  if  you  set  the  "-s"
  75. X(stream)  option, file addresses are ignored and you're free to insert
  76. Xor delete bytes at will.  These options effectively turn your existing
  77. Xtext  editor  into a binary file editor without requiring you to learn
  78. Xany new commands.
  79. X
  80. XFinally, the "-d" option reads a binary file and emits  a  C  language
  81. Xdata declaration which contains the data from the file.  This is handy
  82. Xwhen you wish to embed binary data within programs.
  83. X
  84. XXD is written to be as portable as possible.  It does assume that file
  85. XI/O  is not subjected to end of line translation; if you're porting it
  86. Xto a  system  such  as  MS-DOS  which  requires  binary  files  to  be
  87. Xexplicitly  declared,  you'll  have  to  add  code appropriate to your
  88. Xcompiler.
  89. X
  90. XAUTHOR
  91. X            John Walker
  92. X            Autodesk Neuchatel
  93. X            Avenue des Champs-Montants 14b
  94. X            CH-2074 MARIN
  95. X            Switzerland
  96. X            Usenet: kelvin@autodesk.com
  97. X            Fax:    038/33 88 15
  98. X            Voice:  038/33 76 33
  99. X
  100. XThis program is in the public domain: "Do what thou wilt shall be  the
  101. Xwhole  of  the  law".   I'd  appreciate receiving any bug fixes and/or
  102. Xenhancements,  which  I'll  incorporate  in  future  versions  of  the
  103. Xprogram.   Please leave the original attribution information intact so
  104. Xthat credit and blame may be properly apportioned.
  105. END_OF_FILE
  106.   if test 2665 -ne `wc -c <'README'`; then
  107.     echo shar: \"'README'\" unpacked with wrong size!
  108.   fi
  109.   # end of 'README'
  110. fi
  111. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  112.   echo shar: Will not clobber existing file \"'Makefile'\"
  113. else
  114.   echo shar: Extracting \"'Makefile'\" \(1058 characters\)
  115.   sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  116. X
  117. XCFLAGS = -O
  118. X
  119. Xxd:    xd.o
  120. X    cc $(CFLAGS) xd.o -o xd
  121. X    strip xd
  122. X
  123. Xclean:
  124. X    rm -f xd *.bak core *.out *.o *.shar
  125. X
  126. Xshar:
  127. X    shar -b -v README Makefile xd.1 xd.c >xd.shar
  128. X
  129. Xlint:
  130. X    lint -h xd.c
  131. X
  132. Xmanpage:
  133. X    nroff -man xd.1 | more
  134. X
  135. Xprintman:
  136. X    ptroff -man xd.1
  137. X
  138. X#   The following test should produce no error messages from XD or CMP
  139. X
  140. Xtest:    xd
  141. X    xd xd /tmp/xd1.bak
  142. X    xd -l /tmp/xd1.bak /tmp/xd2.bak
  143. X    cmp /tmp/xd2.bak xd
  144. X    xd -c xd /tmp/xd3.bak
  145. X    xd -l /tmp/xd3.bak /tmp/xd4.bak
  146. X    cmp /tmp/xd4.bak xd
  147. X    xd -l -s /tmp/xd3.bak /tmp/xd4.bak
  148. X    cmp /tmp/xd4.bak xd
  149. X    sed 's/........//' /tmp/xd3.bak >/tmp/xd5.bak
  150. X    xd -l -s /tmp/xd5.bak /tmp/xd6.bak
  151. X    cmp /tmp/xd6.bak xd
  152. X    echo Hello there >/tmp/xd10.bak
  153. X    xd /tmp/xd10.bak >/tmp/xd7.bak
  154. X    sed '1d' /tmp/xd3.bak >>/tmp/xd7.bak
  155. X    xd -l -s /tmp/xd7.bak /tmp/xd8.bak
  156. X    cp /tmp/xd10.bak /tmp/xd9.bak
  157. X    tail +17c xd >>/tmp/xd9.bak
  158. X    cmp /tmp/xd8.bak /tmp/xd9.bak
  159. X    cat xd | xd -dDeFile >/tmp/xd10.c
  160. X    echo "main() {write(1,DeFile,sizeof DeFile); return 0;}" >>/tmp/xd10.c
  161. X    cc /tmp/xd10.c -o /tmp/xd10.bak
  162. X    /tmp/xd10.bak >/tmp/xd11.bak
  163. X    cmp /tmp/xd11.bak xd
  164. END_OF_FILE
  165.   if test 1058 -ne `wc -c <'Makefile'`; then
  166.     echo shar: \"'Makefile'\" unpacked with wrong size!
  167.   fi
  168.   # end of 'Makefile'
  169. fi
  170. if test -f 'xd.1' -a "${1}" != "-c" ; then 
  171.   echo shar: Will not clobber existing file \"'xd.1'\"
  172. else
  173.   echo shar: Extracting \"'xd.1'\" \(4623 characters\)
  174.   sed "s/^X//" >'xd.1' <<'END_OF_FILE'
  175. X'\" t
  176. X.TH XD 1 "30 DEC 1991"
  177. X.UC 4
  178. X.SH NAME
  179. Xxd \- binary to hexadecimal filter
  180. X.SH SYNOPSIS
  181. X.B xd
  182. X[
  183. X.B \-c
  184. X.BI \-d label
  185. X.B \-l
  186. X.B \-s
  187. X] [
  188. X.I infile
  189. X[
  190. X.I outfile
  191. X] ]
  192. X.SH DESCRIPTION
  193. X.B xd
  194. Xdumps files in hexadecimal, optionally with ISO characters side by
  195. Xside.  Unlike
  196. X.BR od ,
  197. Xfile addresses are given in hex, not octal.
  198. X.PP
  199. X.B xd
  200. Xcan
  201. X.I read
  202. Xdump files in the same format it writes and create binary files from
  203. Xthe hex data therein.  This allows you to dump a binary file with
  204. X.BR xd ,
  205. Xedit it with your  favourite  text  editor,  then
  206. Xmake  a  new  binary  file containing whatever changes you've made.  When
  207. Xcreating a binary file,
  208. X.B xd
  209. Xnormally assumes you've only modified data in place (neither expanding
  210. Xnor contracting the file) and verifies file addresses to guarantee
  211. Xthis.  However, a ``stream'' option is available which ignores file
  212. Xaddresses so you're free to insert and delete bytes at
  213. Xwill.
  214. X.B xd
  215. Xthus turns your existing text editor into a binary file editor without
  216. Xrequiring you to learn any new commands.
  217. X.PP
  218. XFinally,
  219. X.B xd
  220. Xcan read a binary file and emit a C language data declaration which
  221. Xcontains the data from the file.  This is handy when you wish to embed
  222. Xbinary data within C programs.
  223. X.SH OPTIONS
  224. X.TP 10
  225. X.B \-c
  226. XDisplay ISO characters alongside the hexadecimal dump.  Non-printing
  227. Xcharacters (according to ISO 8859/1) are shown as periods.  The ISO
  228. Xcharacters are separated from the hexadecimal dump by vertical bar
  229. Xcharacters, which
  230. X.B xd
  231. Xtreats as comment delimiters when loading a hex file.
  232. X.TP
  233. X.BI \-d label
  234. XDumps the file as a C language declaration of an array of
  235. X.B unsigned char
  236. Xwhich, when compiled, will contain the same data as the binary input file.
  237. XThe C array declaration is given the variable name
  238. X.IR label ,
  239. Xor
  240. X.B xd_data
  241. Xif no
  242. X.I label
  243. Xspecification is given.  Data are declared as individual bytes to
  244. Xguarantee portability across architectures with different byte ordering
  245. Xconventions, and are expressed as decimal numbers in lines of less than
  246. X80 characters for maximum portability among compilers.  The
  247. XC operator
  248. X.B sizeof
  249. Xmay be applied to the array
  250. X.I label
  251. Xto obtain its length in bytes.
  252. X.TP
  253. X.B \-l
  254. XLoad file from hexadecimal dump.
  255. X.B xd
  256. Xreads a file in the same format it writes, creating a binary output
  257. Xfile.  Each line is assumed to begin with a file address terminated by
  258. Xa colon.  Each data byte must be two hexadecimal characters (letters
  259. Xmay be upper or lower case), and any characters after a vertical bar
  260. Xare ignored (thus discarding any ISO characters included in the
  261. Xdump with the
  262. X.B \-c
  263. Xoption).  If the
  264. X.B \-s
  265. Xoption is not specified, each file address is checked against the
  266. Xnumber of bytes written so far to guarantee that no bytes have been
  267. Xadded or deleted.
  268. X.TP
  269. X.B \-s
  270. XStream input when loading file.  If this option is specified in conjunction
  271. Xwith the
  272. X.B \-l
  273. Xoption, file addresses are not verified when loading a file and, in fact,
  274. Xneed not be specified at all.  This option treats the input file as stream
  275. Xof bytes, each specified by two hexadecimal digits.  This option allows
  276. Xyou to create a dump with
  277. X.BR xd ,
  278. Xedit it as you wish with any text editor, inserting and deleting bytes
  279. Xin the file wherever you like, then create a binary file from the
  280. Xmodified dump with the command
  281. X.B xd \-l \-s
  282. X.IR "dumpfile outfile" .
  283. X.TP
  284. X.B \-u
  285. XPrint how-to-call information.
  286. X.SH FILES
  287. XIf no
  288. X.I infile
  289. Xis specified,
  290. X.B xd
  291. Xobtains its input from standard input; if no
  292. X.I outfile
  293. Xis given, output is sent to standard output.  The input and
  294. Xoutput are processed in a strictly serial manner regardless
  295. Xof options; consequently
  296. X.B xd
  297. Xmay be used in pipelines without restrictions.
  298. X.SH BUGS
  299. X.PP
  300. XInput error checking in load mode might be improved.  Note that each
  301. Xbyte in load mode must be specified as exactly two adjacent
  302. Xhexadecimal digits and bytes must be separated by white space.  While these
  303. Xrestrictions could be easily relaxed in the scanner, doing so would
  304. Xmake
  305. X.B xd
  306. Xmore vulnerable to typos in its input file, potentially leading to
  307. Xvery difficult to find errors in the binary files it creates.
  308. X.SH "SEE ALSO"
  309. X.PD
  310. X.BR cc (1),
  311. X.BR od (1),
  312. X.BR iso_8859_1 (7)
  313. X.ne 10
  314. X.SH AUTHOR
  315. X.RS 5
  316. X.nf
  317. XJohn Walker
  318. XAutodesk Neuch\o'^a'tel
  319. XAvenue des Champs-Montants 14b
  320. XCH-2074 MARIN
  321. XSuisse/Schweiz/Svizzera/Switzerland
  322. X.PD 0
  323. X.TP 9
  324. XUsenet:
  325. Xkelvin@autodesk.com
  326. X.TP
  327. XFax:
  328. X038/33 88 15
  329. X.TP
  330. XVoice:
  331. X038/33 76 33
  332. X.fi
  333. X.RE
  334. X.PD
  335. X.PP
  336. XPermission to use, copy, modify, and distribute this software and its
  337. Xdocumentation for any purpose and without fee is hereby granted,
  338. Xwithout any conditions or restrictions.  This software is provided ``as
  339. Xis'' without express or implied warranty.
  340. END_OF_FILE
  341.   if test 4623 -ne `wc -c <'xd.1'`; then
  342.     echo shar: \"'xd.1'\" unpacked with wrong size!
  343.   fi
  344.   # end of 'xd.1'
  345. fi
  346. if test -f 'xd.c' -a "${1}" != "-c" ; then 
  347.   echo shar: Will not clobber existing file \"'xd.c'\"
  348. else
  349.   echo shar: Extracting \"'xd.c'\" \(6491 characters\)
  350.   sed "s/^X//" >'xd.c' <<'END_OF_FILE'
  351. X/*
  352. X
  353. X        Hex dump and load utility
  354. X
  355. X        John Walker
  356. X        Autodesk Neuchatel
  357. X        Avenue des Champs-Montants 14b
  358. X        CH-2074 MARIN
  359. X        Switzerland
  360. X        Usenet: kelvin@autodesk.com
  361. X        Fax:    038/33 88 15
  362. X        Voice:  038/33 76 33
  363. X
  364. X*/
  365. X
  366. X
  367. X#include <stdio.h>
  368. X#include <ctype.h>
  369. X
  370. X#define FALSE    0
  371. X#define TRUE    1
  372. X
  373. X#define EOS     '\0'
  374. X
  375. Xstatic char addrformat[80] = "%6X";
  376. Xstatic char dataformat1[80] = "%02X";
  377. Xstatic int bytesperline = 16, doublechar = FALSE,
  378. X       dflen = 2, loading = FALSE, streaming = FALSE;
  379. Xstatic unsigned long fileaddr;
  380. Xstatic unsigned char lineecho[32];
  381. X
  382. X/*  OUTLINE  --  Edit a line of binary data into the selected output
  383. X         format.  */
  384. X
  385. Xstatic void outline(out, dat, len)
  386. X  FILE *out;
  387. X  unsigned char *dat;
  388. X  int len;
  389. X{
  390. X    char oline[132];
  391. X    int i;
  392. X
  393. X    sprintf(oline, addrformat, fileaddr);
  394. X    strcat(oline, ":");
  395. X    for (i = 0; i < len; i++) {
  396. X    char outedit[80];
  397. X
  398. X    sprintf(outedit, dataformat1, dat[i]);
  399. X        strcat(oline, (i == (bytesperline / 2)) ? "  " : " ");
  400. X    strcat(oline, outedit);
  401. X    }
  402. X
  403. X    if (doublechar) {
  404. X    char oc[2];
  405. X    int shortfall = ((bytesperline - len) * (dflen + 1)) +
  406. X            (len <= (bytesperline / 2) ? 1 : 0);
  407. X
  408. X    while (shortfall-- > 0) {
  409. X            strcat(oline, " ");
  410. X    }
  411. X    oc[1] = EOS;
  412. X        strcat(oline, " | ");
  413. X    for (i = 0; i < len; i++) {
  414. X        int b = dat[i];
  415. X
  416. X            /* Map non-printing characters to "." according to the
  417. X           definitions for ISO 8859/1 Latin-1. */
  418. X
  419. X            if (b < ' ' || (b > '~' && b < 145)
  420. X            || (b > 146 && b < 160)) {
  421. X                b = '.';
  422. X        }
  423. X        oc[0] = b;
  424. X        strcat(oline, oc);
  425. X    }
  426. X    }
  427. X    strcat(oline, "\n");
  428. X    fputs(oline, out);
  429. X}
  430. X
  431. X/*  INTERPLINE    --  Interpret a line of input.    */
  432. X
  433. Xstatic int interpline(line, lineno, out)
  434. X  char *line;
  435. X  int lineno;
  436. X  FILE *out;
  437. X{
  438. X    char *cp = line;
  439. X    char c;
  440. X    long lfaddr;
  441. X    int gfaddr = FALSE;
  442. X
  443. X    /* Scan the line for a possible alternative format information
  444. X       following a vertical bar and delete it. */
  445. X
  446. X    while ((c = *cp++) != EOS) {
  447. X        if (c == '|') {
  448. X        cp[-1] = EOS;
  449. X        break;
  450. X    }
  451. X    }
  452. X
  453. X    /* Scan the line for a file address terminated by a colon.    Save
  454. X       the file address. */
  455. X
  456. X    cp = line;
  457. X
  458. X    while ((c = *cp++) != EOS) {
  459. X        if (c == ':') {
  460. X        int sa;
  461. X        char tchar;
  462. X
  463. X        cp[-1] = EOS;
  464. X            sa = sscanf(line, "%lx%c", &lfaddr, &tchar);
  465. X        if (sa == 0 || (sa > 1 && tchar != EOS)) {
  466. X        fprintf(stderr,
  467. X                    "Bad hexadecimal file address \"%s\" on line %d:\n",
  468. X            line, lineno);
  469. X        return FALSE;
  470. X        }
  471. X        gfaddr = TRUE;
  472. X            cp[-1] = ':';
  473. X        break;
  474. X    }
  475. X    }
  476. X    if (!gfaddr) {
  477. X    cp = line;
  478. X    }
  479. X    if (!streaming) {
  480. X    if (!gfaddr) {
  481. X            fprintf(stderr, "File address missing on line %d:\n", lineno);
  482. X            fprintf(stderr, "%s\n", line);
  483. X        return FALSE;
  484. X    }
  485. X    if (lfaddr != fileaddr) {
  486. X            fprintf(stderr, "File address sequence error on line %d.\n",
  487. X        lineno);
  488. X            fprintf(stderr, "  Expected 0%X, received 0%X.\n", fileaddr,
  489. X        lfaddr);
  490. X            fprintf(stderr, "%s\n", line);
  491. X        return FALSE;
  492. X    }
  493. X    }
  494. X
  495. X    while ((c = *cp++) != EOS) {
  496. X    if (!isspace(c)) {
  497. X        if (isxdigit(c) &&
  498. X        isxdigit(*cp) &&
  499. X        (cp[1] == EOS || isspace(cp[1]))) {
  500. X        int b;
  501. X
  502. X                sscanf(cp - 1, "%2x", &b);
  503. X        putc(b, out);
  504. X        fileaddr++;
  505. X        cp += 2;
  506. X        } else {
  507. X                fprintf(stderr, "Improper hex value, \"%c%c%c\" on line %d:\n",
  508. X            c, *cp, cp[1], lineno);
  509. X                fprintf(stderr, "%s\n", line);
  510. X        fprintf(stderr,
  511. X                    "Bytes must be specified as two hexadecimal\n");
  512. X                fprintf(stderr, "digits separated by white space.\n");
  513. X        return FALSE;
  514. X        }
  515. X    }
  516. X    }
  517. X    return TRUE;
  518. X}
  519. X
  520. X/*  Main program  */
  521. X
  522. Xint main(argc, argv)
  523. X  int argc; char *argv[];
  524. X{
  525. X    int i, b, bp, cdata = FALSE, f = 0;
  526. X    char *cp, *clabel, opt;
  527. X    FILE *in = stdin, *out = stdout;
  528. X
  529. X    for (i = 1; i < argc; i++) {
  530. X    cp = argv[i];
  531. X        if (*cp == '-') {
  532. X        opt = *(++cp);
  533. X        if (islower(opt))
  534. X        opt = toupper(opt);
  535. X        switch (opt) {
  536. X
  537. X                case 'C':
  538. X            doublechar = TRUE;
  539. X            break;
  540. X
  541. X                case 'D':
  542. X            cdata = TRUE;
  543. X            clabel = cp + 1;
  544. X            break;
  545. X
  546. X                case 'L':
  547. X            loading = TRUE;
  548. X            break;
  549. X
  550. X                case 'S':
  551. X            streaming = TRUE;
  552. X            break;
  553. X
  554. X                case '?':
  555. X                case 'U':
  556. X    fprintf(stderr,"\nXD  --  Hex dump.  Call");
  557. X    fprintf(stderr,
  558. X       "\n             with xd [input [output]]");
  559. X    fprintf(stderr,"\n");
  560. X    fprintf(stderr,"\n         Options:");
  561. X    fprintf(stderr,"\n              -C      Dump as ISO characters");
  562. X    fprintf(stderr,"\n              -Dlabel Dump as a C data declaration");
  563. X    fprintf(stderr,"\n              -L      Load file from hex dump");
  564. X    fprintf(stderr,"\n              -S      Stream load (don't check file addresses)");
  565. X    fprintf(stderr,"\n");
  566. X            return 0;
  567. X        }
  568. X    } else {
  569. X        switch (f) {
  570. X        case 0:
  571. X                    if ((in = fopen(cp, "r")) == NULL) {
  572. X                        fprintf(stderr, "Cannot open input file %s\n", cp);
  573. X            return 2;
  574. X            }
  575. X            f++;
  576. X            break;
  577. X
  578. X        case 1:
  579. X                    if ((out = fopen(cp, "w")) == NULL) {
  580. X                        fprintf(stderr, "Cannot open output file %s\n", cp);
  581. X            return 2;
  582. X            }
  583. X            f++;
  584. X            break;
  585. X
  586. X        default:
  587. X                    fprintf(stderr, "Too many file names specified.\n");
  588. X        }
  589. X    }
  590. X    }
  591. X
  592. X    bp = 0;
  593. X    fileaddr = 0;
  594. X
  595. X    if (loading) {
  596. X    char inline[256];
  597. X    int lineno = 0;
  598. X
  599. X    while (fgets(inline, (sizeof inline) - 2, in)) {
  600. X        lineno++;
  601. X        if (!interpline(inline, lineno, out)) {
  602. X        fclose(out);
  603. X        return 2;
  604. X        }
  605. X    }
  606. X    } else {
  607. X    if (cdata) {
  608. X        char cout[80];
  609. X
  610. X            fprintf(out, "unsigned char %s[] = {\n",
  611. X                clabel[0] == EOS ? "xd_data" : clabel);
  612. X            strcpy(cout, "    ");
  613. X
  614. X        while ((b = getc(in)) != EOF) {
  615. X        if (strlen(cout) > 72) {
  616. X                    fprintf(out, "%s\n", cout);
  617. X                    strcpy(cout, "    ");
  618. X        }
  619. X                sprintf(cout + strlen(cout), "%d,", b);
  620. X        }
  621. X        if (strlen(cout) > 4) {
  622. X        cout[strlen(cout) - 1] = EOS; /* Strip trailing comma */
  623. X                fprintf(out, "%s\n", cout);
  624. X        }
  625. X            fprintf(out, "};\n");
  626. X    } else {
  627. X        while ((b = getc(in)) != EOF) {
  628. X        if (bp >= bytesperline) {
  629. X            outline(out, lineecho, bp);
  630. X            bp = 0;
  631. X            fileaddr += bytesperline;
  632. X        }
  633. X        lineecho[bp++] = b;
  634. X        }
  635. X
  636. X        if (bp > 0) {
  637. X        outline(out, lineecho, bp);
  638. X        }
  639. X    }
  640. X    }
  641. X    return 0;
  642. X}
  643. END_OF_FILE
  644.   if test 6491 -ne `wc -c <'xd.c'`; then
  645.     echo shar: \"'xd.c'\" unpacked with wrong size!
  646.   fi
  647.   # end of 'xd.c'
  648. fi
  649. echo shar: End of archive 1 \(of 1\).
  650. cp /dev/null ark1isdone
  651. MISSING=""
  652. for I in 1 ; do
  653.     if test ! -f ark${I}isdone ; then
  654.     MISSING="${MISSING} ${I}"
  655.     fi
  656. done
  657. if test "${MISSING}" = "" ; then
  658.     echo You have the archive.
  659.     rm -f ark[1-9]isdone
  660. else
  661.     echo You still must unpack the following archives:
  662.     echo "        " ${MISSING}
  663. fi
  664. exit 0
  665. exit 0 # Just in case...
  666.