home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume36 / chiaro / part14 < prev    next >
Encoding:
Text File  |  1993-03-25  |  54.9 KB  |  1,841 lines

  1. Newsgroups: comp.sources.misc
  2. From: jwbirdsa@picarefy.picarefy.com (James W. Birdsall)
  3. Subject: v36i084:  chiaro - Image Utilities, Part14/18
  4. Message-ID: <1993Mar26.202909.14935@sparky.imd.sterling.com>
  5. X-Md4-Signature: 60bd4c2ae8b0dad3837fd4cf3cdd5bc0
  6. Date: Fri, 26 Mar 1993 20:29:09 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: jwbirdsa@picarefy.picarefy.com (James W. Birdsall)
  10. Posting-number: Volume 36, Issue 84
  11. Archive-name: chiaro/part14
  12. Environment: UNIX, Sun, DECstation, 3B1
  13.  
  14. #! /bin/sh
  15. # This is a shell archive.  Remove anything before this line, then feed it
  16. # into a shell via "sh file" or similar.  To overwrite existing files,
  17. # type "sh file -c".
  18. # Contents:  src/img.c src/re.c src/xbm.c templates/pcix.h
  19. # Wrapped by kent@sparky on Thu Mar 25 11:20:06 1993
  20. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  21. echo If this archive is complete, you will see the following message:
  22. echo '          "shar: End of archive 14 (of 18)."'
  23. if test -f 'src/img.c' -a "${1}" != "-c" ; then 
  24.   echo shar: Will not clobber existing file \"'src/img.c'\"
  25. else
  26.   echo shar: Extracting \"'src/img.c'\" \(11120 characters\)
  27.   sed "s/^X//" >'src/img.c' <<'END_OF_FILE'
  28. X/***************************************************************************
  29. X*   IMG.C                                                                  *
  30. X*   MODULE:  IMG                                                           *
  31. X*   OS:      UNIX                                                          *
  32. X*                                                                          *
  33. X*   Copyright (c) 1993 James W. Birdsall. All Rights Reserved.             *
  34. X*                                                                          *
  35. X*   $Id: img.c,v 1.5 1993/03/02 00:55:29 jwbirdsa Exp $
  36. X*                                                                          *
  37. X*   REMEMBER THAT HEADER OF IMG FILE CONTAINS WORDS IN MOTOROLA FORMAT!    *
  38. X*                                                                          *
  39. X*   This file contains functions to process IMG format files.              *
  40. X*   Functions:                                                             *
  41. X*      img_verify    - checks filename to see if it is an IMG file         *
  42. X*      img_getheader - extracts header data from IMG file                  *
  43. X*                                                                          *
  44. X*      img_errstring - converts error code into message                    *
  45. X*                                                                          *
  46. X***************************************************************************/
  47. X
  48. X#include "config.h"
  49. X
  50. X/*
  51. X** system includes <>
  52. X*/
  53. X
  54. X#include <stdio.h>
  55. X#ifndef NO_STR_INC
  56. X#ifdef STRING_PLURAL
  57. X#include <strings.h>
  58. X#else
  59. X#include <string.h>
  60. X#endif
  61. X#endif
  62. X
  63. X
  64. X/*
  65. X** custom includes ""
  66. X*/
  67. X
  68. X#include "depend.h"
  69. X#include "formats.h"
  70. X#include "img.h"
  71. X
  72. X
  73. X/*
  74. X** local #defines
  75. X*/
  76. X
  77. X/*
  78. X** misc: copyright strings, version macros, etc.
  79. X*/
  80. X
  81. X/*
  82. X** typedefs
  83. X*/
  84. X
  85. X/*
  86. X** global variables
  87. X*/
  88. X
  89. X/*
  90. X** static globals
  91. X*/
  92. X
  93. Xstatic char CONST rcsid[] = "$Id: img.c,v 1.5 1993/03/02 00:55:29 jwbirdsa Exp $";
  94. X
  95. X
  96. X/*
  97. X** function prototypes
  98. X*/
  99. X
  100. X#ifdef NO_STR_INC
  101. Xextern char *strrchr();
  102. Xextern int strcmp();
  103. X#endif
  104. X
  105. X
  106. X/*
  107. X** functions
  108. X*/
  109. X
  110. X
  111. X/***************************************************************************
  112. X*   FUNCTION:    img_verify                                                *
  113. X*                                                                          *
  114. X*   DESCRIPTION:                                                           *
  115. X*                                                                          *
  116. X*       Verifies that a file is an IMG file by checking filename against   *
  117. X*       list of extensions. Reads IMG version number from start of file.   *
  118. X*                                                                          *
  119. X*   ENTRY:                                                                 *
  120. X*                                                                          *
  121. X*       filename - name of file to be verified                             *
  122. X*       version  - pointer to unsigned long in which format/version value  *
  123. X*                  is returned                                             *
  124. X*       exts     - array of string pointers, list of extensions for IMG    *
  125. X*                  files                                                   *
  126. X*                                                                          *
  127. X*   EXIT:                                                                  *
  128. X*                                                                          *
  129. X*       Returns an error/status code.                                      *
  130. X*                                                                          *
  131. X*   CONSTRAINTS/SIDE EFFECTS:                                              *
  132. X*                                                                          *
  133. X***************************************************************************/
  134. XULONG
  135. X#ifdef __STDC__
  136. Ximg_verify(char *filename, ULONG *version, char **exts)
  137. X#else
  138. Ximg_verify(filename, version, exts)
  139. Xchar *filename;
  140. XULONG *version;
  141. Xchar **exts;
  142. X#endif
  143. X{
  144. X    char *extptr;
  145. X    int loop;
  146. X    FILE *imgfile;
  147. X    int verno;
  148. X    ULONG retval;
  149. X
  150. X    /* Search for '.' marking extension. */
  151. X
  152. X    extptr = strrchr(filename, '.');
  153. X    if (NULL == extptr)
  154. X    {
  155. X        /* No extension, cannot classify. */
  156. X
  157. X        *version = IMG_NOT;
  158. X        return 0;
  159. X    }
  160. X    extptr++;
  161. X
  162. X    /* Now we have the extension, check against list. */
  163. X
  164. X    for (loop = 0; exts[loop] != NULL; loop++)
  165. X    {
  166. X        /* Case-sensitive string compare. */
  167. X
  168. X        if (strcmp(extptr, exts[loop]) == 0)
  169. X        {
  170. X            /* Match, so break out of loop. */
  171. X
  172. X            break;
  173. X        }
  174. X    }
  175. X
  176. X    /* Check exit from loop. */
  177. X
  178. X    if (NULL == exts[loop])
  179. X    {
  180. X        /* No match, return. */
  181. X
  182. X        *version = IMG_NOT;
  183. X        return 0;
  184. X    }
  185. X
  186. X    /* Extension is valid for type IMG, so process accordingly. */
  187. X
  188. X    if ((imgfile = fopen(filename, FOPEN_READ_BINARY)) == (FILE *) NULL)
  189. X    {
  190. X        return IMG_FILEERR_E;
  191. X    }
  192. X
  193. X    /* Read version number, MSB. */
  194. X
  195. X    if ((loop = fgetc(imgfile)) == EOF)
  196. X    {
  197. X        *version = IMG_NOT;
  198. X        retval = (feof(imgfile) ? ST_SUCCESS : IMG_FILEERR_E);
  199. X        fclose(imgfile);
  200. X        return retval;
  201. X    }
  202. X    verno = (loop & 0x00FF);
  203. X    verno <<= 8;
  204. X
  205. X    /* Read version number, LSB. */
  206. X
  207. X    if ((loop = fgetc(imgfile)) == EOF)
  208. X    {
  209. X        *version = IMG_NOT;
  210. X        retval = (feof(imgfile) ? ST_SUCCESS : IMG_FILEERR_E);
  211. X        fclose(imgfile);
  212. X        return retval;
  213. X    }
  214. X    verno |= (loop & 0x00FF);
  215. X
  216. X    /* Set version according to verno */
  217. X
  218. X    *version = ((1 == verno) ? IMG_VER1 : IMG_NOT);
  219. X
  220. X    /* Close file. */
  221. X
  222. X    if (fclose(imgfile))
  223. X    {
  224. X        return IMG_FILEERR_E;
  225. X    }
  226. X
  227. X    /* Return OK. */
  228. X
  229. X    return 0;
  230. X} /* end of img_verify() */
  231. X
  232. X
  233. X/***************************************************************************
  234. X*   FUNCTION:    img_getheader                                             *
  235. X*                                                                          *
  236. X*   DESCRIPTION:                                                           *
  237. X*                                                                          *
  238. X*       Assumes that file is an IMG file. Reads header from file, extracts *
  239. X*       data into IMG_HDR structure.                                       *
  240. X*                                                                          *
  241. X*   ENTRY:                                                                 *
  242. X*                                                                          *
  243. X*       infile  - file to be processed                                     *
  244. X*       results - pointer to IMG_HDR structure in which data from header   *
  245. X*                 is returned                                              *
  246. X*                                                                          *
  247. X*   EXIT:                                                                  *
  248. X*                                                                          *
  249. X*       Returns an error/status code.                                      *
  250. X*                                                                          *
  251. X*   CONSTRAINTS/SIDE EFFECTS:                                              *
  252. X*                                                                          *
  253. X*       Leaves file pointing to beginning of image data.                   *
  254. X*                                                                          *
  255. X***************************************************************************/
  256. XULONG
  257. X#ifdef __STDC__
  258. Ximg_getheader(FILE *infile, IMG_HDR *results)
  259. X#else
  260. Ximg_getheader(infile, results)
  261. XFILE *infile;
  262. XIMG_HDR *results;
  263. X#endif
  264. X{
  265. X    UCHAR rawhdr[IMG_HDR_LEN];
  266. X
  267. X    /* Make sure we're at beginning of file. */
  268. X
  269. X    if (fseek(infile, 0L, SEEK_SET))
  270. X    {
  271. X        return IMG_FILEERR_E;
  272. X    }
  273. X
  274. X    /* Read raw bytes into buffer. */
  275. X
  276. X    if (fread(rawhdr, 1, IMG_HDR_LEN, infile) != IMG_HDR_LEN)
  277. X    {
  278. X        return (feof(infile) ? IMG_UNEOF_E : IMG_FILEERR_E);
  279. X    }
  280. X
  281. X    /* Extract info from raw header. */
  282. X
  283. X#if 0
  284. X    /* Someday this code may be meaningful. */
  285. X
  286. X    results->version = (ULONG) CONSTRUCT_M_UINT(rawhdr + IMG_HDR_VERS_OFF);
  287. X#else
  288. X    results->version = IMG_VER1;
  289. X#endif
  290. X
  291. X    results->headerlen = CONSTRUCT_M_UINT(rawhdr + IMG_HDR_HLEN_OFF);
  292. X    results->planes = CONSTRUCT_M_UINT(rawhdr + IMG_HDR_PLANES_OFF);
  293. X    results->patternlen = CONSTRUCT_M_UINT(rawhdr + IMG_HDR_PLEN_OFF);
  294. X    results->pixwid = CONSTRUCT_M_UINT(rawhdr + IMG_HDR_PWID_OFF);
  295. X    results->pixhi = CONSTRUCT_M_UINT(rawhdr + IMG_HDR_PHI_OFF);
  296. X    results->imwid = CONSTRUCT_M_UINT(rawhdr + IMG_HDR_IMWID_OFF);
  297. X    results->imhi = CONSTRUCT_M_UINT(rawhdr + IMG_HDR_IMHI_OFF);
  298. X
  299. X    /* Set file to point to start of data. */
  300. X
  301. X    if (fseek(infile, (long) (results->headerlen * 2), SEEK_SET))
  302. X    {
  303. X        return IMG_FILEERR_E;
  304. X    }
  305. X
  306. X    /* Return OK. */
  307. X
  308. X    return 0;
  309. X} /* end of img_getheader() */
  310. X
  311. X
  312. X/***************************************************************************
  313. X*   FUNCTION: img_errstring                                                *
  314. X*                                                                          *
  315. X*   DESCRIPTION:                                                           *
  316. X*                                                                          *
  317. X*      Returns a string corresponding to an error code.                    *
  318. X*                                                                          *
  319. X*   ENTRY:                                                                 *
  320. X*                                                                          *
  321. X*      errcode - error code to be translated                               *
  322. X*                                                                          *
  323. X*   EXIT:                                                                  *
  324. X*                                                                          *
  325. X*      Returns a pointer to the appropriate string, or NULL if there is    *
  326. X*      no appropriate string.                                              *
  327. X*                                                                          *
  328. X*   CONSTRAINTS/SIDE EFFECTS:                                              *
  329. X*                                                                          *
  330. X***************************************************************************/
  331. Xchar *
  332. X#ifdef __STDC__
  333. Ximg_errstring(ULONG errcode)
  334. X#else
  335. Ximg_errstring(errcode)
  336. XULONG errcode;
  337. X#endif
  338. X{
  339. X    char *temp;
  340. X
  341. X    /* If error code not from this module, return NULL. */
  342. X
  343. X    if ((errcode & ST_MOD_MASK) != IMG_MODULE)
  344. X    {
  345. X        return NULL;
  346. X    }
  347. X
  348. X    /* Process by code. */
  349. X
  350. X    switch (ERRSEV(errcode))
  351. X    {
  352. X        case ERRSEV(IMG_NOTIMG_E):
  353. X            temp = "File is not a IMG format file.";
  354. X            break;
  355. X        case ERRSEV(IMG_FILEERR_E):
  356. X            temp = "Error accessing file.";
  357. X            break;
  358. X        case ERRSEV(IMG_UNEOF_E):
  359. X            temp = "Unexpected End of File";
  360. X            break;
  361. X
  362. X        default:
  363. X            temp = NULL;
  364. X            break;
  365. X    }
  366. X
  367. X    return temp;
  368. X} /* end of img_errstring() */
  369. X
  370. END_OF_FILE
  371.   if test 11120 -ne `wc -c <'src/img.c'`; then
  372.     echo shar: \"'src/img.c'\" unpacked with wrong size!
  373.   fi
  374.   # end of 'src/img.c'
  375. fi
  376. if test -f 'src/re.c' -a "${1}" != "-c" ; then 
  377.   echo shar: Will not clobber existing file \"'src/re.c'\"
  378. else
  379.   echo shar: Extracting \"'src/re.c'\" \(28428 characters\)
  380.   sed "s/^X//" >'src/re.c' <<'END_OF_FILE'
  381. X/***************************************************************************
  382. X*   RE.C                                                                   *
  383. X*   MODULE:  FORMATS                                                       *
  384. X*   OS:      UNIX                                                          *
  385. X*                                                                          *
  386. X*   Copyright (c) 1993 James W. Birdsall. All Rights Reserved.             *
  387. X*                                                                          *
  388. X*   The Graphics Interchange Format(c) is the Copyright property of        *
  389. X*   CompuServe Incorporated. GIF(sm) is a Service Mark property of         *
  390. X*   CompuServe Incorporated.                                               *
  391. X*                                                                          *
  392. X*   $Id: re.c,v 1.2 1993/03/18 21:15:35 jwbirdsa Exp $
  393. X*                                                                          *
  394. X*   Functions to recognize file formats.                                   *
  395. X*                                                                          *
  396. X*   Functions in this file are:                                            *
  397. X*                                                                          *
  398. X*     re_ident   - identify a file                                         *
  399. X*     re_init    - initialize the recognizer module                        *
  400. X*     re_deinit  - deinitialize the recognizer module                      *
  401. X*     re_extlist - get the extension list for a type                       *
  402. X*                                                                          *
  403. X***************************************************************************/
  404. X
  405. X#include "config.h"
  406. X
  407. X/*
  408. X** system includes <>
  409. X*/
  410. X
  411. X#include <stdio.h>
  412. X#include <ctype.h>
  413. X#ifndef NO_STDLIB
  414. X#include <stdlib.h>
  415. X#endif
  416. X#ifndef NO_MEMOP
  417. X#include <memory.h>
  418. X#endif
  419. X#ifndef NO_MALLOCHDR
  420. X#include <malloc.h>
  421. X#endif
  422. X#ifndef NO_STR_INC
  423. X#ifdef STRING_PLURAL
  424. X#include <strings.h>
  425. X#else
  426. X#include <string.h>
  427. X#endif
  428. X#endif
  429. X
  430. X
  431. X/*
  432. X** custom includes ""
  433. X*/
  434. X
  435. X#include "depend.h"
  436. X
  437. X#include "formats.h"
  438. X#include "re.h"
  439. X
  440. X#include "fb.h"
  441. X#include "gif.h"
  442. X#include "img.h"
  443. X#include "jfif.h"
  444. X#include "sr.h"
  445. X#include "tga.h"
  446. X#include "pnm.h"
  447. X#include "xbm.h"
  448. X#include "bmp.h"
  449. X#include "pcx.h"
  450. X
  451. X
  452. X/*
  453. X** local #defines
  454. X*/
  455. X
  456. X#define EXTS_GUESS  5             /* initial guess at extensions/type */
  457. X
  458. X
  459. X/*
  460. X** misc: copyright strings, version macros, etc.
  461. X*/
  462. X
  463. Xstatic char CONST rcsid[] = "$Id: re.c,v 1.2 1993/03/18 21:15:35 jwbirdsa Exp $";
  464. X
  465. X
  466. X/*
  467. X** typedefs
  468. X*/
  469. X
  470. Xtypedef struct bb {
  471. X    char name[15];
  472. X    char **exts;
  473. X    struct bb *next;
  474. X} EXTLIST;
  475. X
  476. X
  477. X/*
  478. X** global variables
  479. X*/
  480. X
  481. Xstatic EXTLIST *extlist = NULL;          /* list of format extensions */
  482. X
  483. Xstatic char scratch[80];                 /* local scratchpad */
  484. X
  485. X
  486. X/*
  487. X** function prototypes
  488. X*/
  489. X
  490. X#ifdef  __STDC__
  491. X# define P_(s) s
  492. X#else
  493. X# define P_(s) ()
  494. X#endif
  495. X
  496. Xstatic int searchpath P_((char *progname, char *retbuf));
  497. X
  498. X#undef P_
  499. X
  500. X
  501. X#ifdef NO_STDLIB
  502. Xextern char *getenv();
  503. X#endif
  504. X
  505. X#ifdef NO_STR_INC
  506. Xextern char *strcpy();
  507. Xextern char *strchr();
  508. Xextern char *strrchr();
  509. Xextern int strlen();
  510. Xextern int strcmp();
  511. X#ifndef NO_STRDUP
  512. Xextern char *strdup();
  513. X#endif
  514. X#endif
  515. X
  516. Xextern int access();
  517. X
  518. X/*
  519. X** functions
  520. X*/
  521. X
  522. X
  523. X/***************************************************************************
  524. X*   FUNCTION: re_ident                                                     *
  525. X*                                                                          *
  526. X*   DESCRIPTION:                                                           *
  527. X*                                                                          *
  528. X*       Examines a given file to determine if it is of a known bitmap      *
  529. X*       format.                                                            *
  530. X*                                                                          *
  531. X*   ENTRY:                                                                 *
  532. X*                                                                          *
  533. X*       filename - name of file to be examined                             *
  534. X*       format   - place to return format code                             *
  535. X*                                                                          *
  536. X*   EXIT:                                                                  *
  537. X*                                                                          *
  538. X*       Returns error/status code.                                         *
  539. X*                                                                          *
  540. X*   CONSTRAINTS/SIDE EFFECTS:                                              *
  541. X*                                                                          *
  542. X***************************************************************************/
  543. XULONG
  544. X#ifdef __STDC__
  545. Xre_ident(char *filename, ULONG *format)
  546. X#else
  547. Xre_ident(filename, format)
  548. Xchar *filename;
  549. XULONG *format;
  550. X#endif
  551. X{
  552. X    ULONG status;
  553. X    char **exts;
  554. X
  555. X    /*
  556. X    ** Check each format in turn.
  557. X    */
  558. X
  559. X    /* GIF */
  560. X
  561. X    if ((status = gif_verify(filename, format, re_extlist(GIF_MAIN))) != 0)
  562. X    {
  563. X        return status;
  564. X    }
  565. X    if (*format != FORMAT_NOT)
  566. X    {
  567. X        return 0;
  568. X    }
  569. X
  570. X    /* IMG */
  571. X
  572. X    if ((exts = re_extlist(IMG_MAIN)) != (char **) NULL)
  573. X    {
  574. X        /* Got a match, so use supplied list. */
  575. X        if ((status = img_verify(filename, format, exts)) != 0)
  576. X        {
  577. X            return status;
  578. X        }
  579. X        if (*format != FORMAT_NOT)
  580. X        {
  581. X            return 0;
  582. X        }
  583. X    }
  584. X
  585. X    /* JFIF */
  586. X
  587. X    if ((exts = re_extlist(JFIF_MAIN)) != (char **) NULL)
  588. X    {
  589. X        /* Got a match, so use supplied list. */
  590. X        if ((status = jfif_verify(filename, format, exts)) != 0)
  591. X        {
  592. X            return status;
  593. X        }
  594. X        if (*format != FORMAT_NOT)
  595. X        {
  596. X            return 0;
  597. X        }
  598. X    }
  599. X
  600. X    /* SR (Sun Raster) */
  601. X
  602. X    if ((status = sr_verify(filename, format, re_extlist(SR_MAIN))) != 0)
  603. X    {
  604. X        return status;
  605. X    }
  606. X    if (*format != FORMAT_NOT)
  607. X    {
  608. X        return 0;
  609. X    }
  610. X
  611. X    /* TGA */
  612. X
  613. X    if ((exts = re_extlist(TGA_MAIN)) != (char **) NULL)
  614. X    {
  615. X        /* Got a match, so use supplied list. */
  616. X        if ((status = tga_verify(filename, format, exts)) != 0)
  617. X        {
  618. X            return status;
  619. X        }
  620. X        if (*format != FORMAT_NOT)
  621. X        {
  622. X            return 0;
  623. X        }
  624. X    }
  625. X
  626. X    /* PBM */
  627. X
  628. X    if ((exts = re_extlist(PBM_MAIN)) != (char **) NULL)
  629. X    {
  630. X        /* Got a match, so use supplied list. */
  631. X        if ((status = pbm_verify(filename, format, exts)) != 0)
  632. X        {
  633. X            return status;
  634. X        }
  635. X        if (*format != FORMAT_NOT)
  636. X        {
  637. X            return 0;
  638. X        }
  639. X    }
  640. X
  641. X    /* PGM */
  642. X
  643. X    if ((exts = re_extlist(PGM_MAIN)) != (char **) NULL)
  644. X    {
  645. X        /* Got a match, so use supplied list. */
  646. X        if ((status = pgm_verify(filename, format, exts)) != 0)
  647. X        {
  648. X            return status;
  649. X        }
  650. X        if (*format != FORMAT_NOT)
  651. X        {
  652. X            return 0;
  653. X        }
  654. X    }
  655. X
  656. X    /* PPM */
  657. X
  658. X    if ((exts = re_extlist(PPM_MAIN)) != (char **) NULL)
  659. X    {
  660. X        /* Got a match, so use supplied list. */
  661. X        if ((status = ppm_verify(filename, format, exts)) != 0)
  662. X        {
  663. X            return status;
  664. X        }
  665. X        if (*format != FORMAT_NOT)
  666. X        {
  667. X            return 0;
  668. X        }
  669. X    }
  670. X
  671. X    /* XBM */
  672. X
  673. X    if ((exts = re_extlist(XBM_MAIN)) != (char **) NULL)
  674. X    {
  675. X        /* Got a match, so use supplied list. */
  676. X        if ((status = xbm_verify(filename, format, exts)) != 0)
  677. X        {
  678. X            return status;
  679. X        }
  680. X        if (*format != FORMAT_NOT)
  681. X        {
  682. X            return 0;
  683. X        }
  684. X    }
  685. X
  686. X    /* BMP */
  687. X
  688. X    if ((exts = re_extlist(BMP_MAIN)) != (char **) NULL)
  689. X    {
  690. X        /* Got a match, so use supplied list. */
  691. X        if ((status = bmp_verify(filename, format, exts)) != 0)
  692. X        {
  693. X            return status;
  694. X        }
  695. X        if (*format != FORMAT_NOT)
  696. X        {
  697. X            return 0;
  698. X        }
  699. X    }
  700. X
  701. X    /* PCX */
  702. X
  703. X    if ((exts = re_extlist(PCX_MAIN)) != (char **) NULL)
  704. X    {
  705. X        /* Got a match, so use supplied list. */
  706. X        if ((status = pcx_verify(filename, format, exts)) != 0)
  707. X        {
  708. X            return status;
  709. X        }
  710. X        if (*format != FORMAT_NOT)
  711. X        {
  712. X            return 0;
  713. X        }
  714. X    }
  715. X
  716. X    /* File type not recognized at all. Return unrecognized. */
  717. X
  718. X    return FM_UNRECOGNIZED_W;
  719. X} /* end of re_ident() */
  720. X
  721. X
  722. X/***************************************************************************
  723. X*   FUNCTION:    re_init                                                   *
  724. X*                                                                          *
  725. X*   DESCRIPTION:                                                           *
  726. X*                                                                          *
  727. X*       Reads extension lists from configuration file.                     *
  728. X*                                                                          *
  729. X*   ENTRY:                                                                 *
  730. X*                                                                          *
  731. X*       progname - path to CHILS executable                                *
  732. X*       cfg_name - name of configuration file                              *
  733. X*       envvar   - name of environment variable                            *
  734. X*                                                                          *
  735. X*   EXIT:                                                                  *
  736. X*                                                                          *
  737. X*       Returns an error/status code.                                      *
  738. X*                                                                          *
  739. X*   CONSTRAINTS/SIDE EFFECTS:                                              *
  740. X*                                                                          *
  741. X*       Builds the list of extension lists.                                *
  742. X*                                                                          *
  743. X***************************************************************************/
  744. XULONG
  745. X#ifdef __STDC__
  746. Xre_init(char *progname, char *cfg_name, char *envvar)
  747. X#else
  748. Xre_init(progname, cfg_name, envvar)
  749. Xchar *progname;
  750. Xchar *cfg_name;
  751. Xchar *envvar;
  752. X#endif
  753. X{
  754. X    FILE *configfile;
  755. X    int loop, go;
  756. X    EXTLIST *tempext;
  757. X    int c;
  758. X    int extcount, extarraysize;
  759. X    char **tempre;
  760. X    char *chihome;
  761. X    char *term;
  762. X
  763. X    /*
  764. X    ** First, find configuration file -- check for configuration file in
  765. X    ** current directory.
  766. X    */
  767. X
  768. X    if ((configfile = fopen(cfg_name, "r")) == (FILE *) NULL)
  769. X    {
  770. X        /*
  771. X        ** If not, check for environment variable.
  772. X        */
  773. X
  774. X        if ((chihome = getenv(envvar)) != (char *) NULL)
  775. X        {
  776. X            strcpy(scratch, chihome);
  777. X        }
  778. X        else
  779. X        {
  780. X            /* 
  781. X            ** Last chance -- check directory where program resides.
  782. X            */
  783. X
  784. X            /* First, create filespec. */
  785. X
  786. X            strcpy(scratch, progname);
  787. X            if ((term = strrchr(scratch, '/')) == NULL)
  788. X            {
  789. X                /* Program is either in current directory or in path. */
  790. X
  791. X                if (access(progname, 1) == 0)
  792. X                {
  793. X                    /* 
  794. X                    ** Oops -- program is in current directory, and we already 
  795. X                    ** looked there, so abort.
  796. X                    */
  797. X    
  798. X                    return FM_NOCFGFILE_W;
  799. X                }
  800. X
  801. X                /* Program is in path, so search path for it. */
  802. X
  803. X                if (searchpath(progname, scratch) == -1)
  804. X                {
  805. X                    /*
  806. X                    ** Didn't find the program in the path, so who knows
  807. X                    ** where it came from? (and hence where to look for the
  808. X                    ** config file)
  809. X                    */
  810. X    
  811. X                    return FM_NOCFGFILE_W;
  812. X                }
  813. X            }
  814. X            else
  815. X            {
  816. X                /* Program name includes path, use it. */
  817. X
  818. X                *term = '\0';
  819. X            }
  820. X        }
  821. X
  822. X        /*
  823. X        ** Got a base name, now make a full name out of it and try to open
  824. X        ** that file.
  825. X        */
  826. X
  827. X        loop = strlen(scratch);
  828. X        scratch[loop] = '/';
  829. X        strcpy((scratch + loop + 1), cfg_name);
  830. X        if ((configfile = fopen(scratch, "r")) == (FILE *) NULL)
  831. X        {
  832. X            return FM_NOCFGFILE_W;
  833. X        }
  834. X    }
  835. X
  836. X    /*
  837. X    ** Read entries from file.
  838. X    */
  839. X
  840. X    while (feof(configfile) == 0)
  841. X    {
  842. X        /*
  843. X        ** Read forward to non-whitespace.
  844. X        */
  845. X
  846. X        while ((c = fgetc(configfile)) != EOF)
  847. X        {
  848. X            if (isspace(c) == 0)
  849. X            {
  850. X               break;
  851. X            }
  852. X        }
  853. X        if (EOF == c)
  854. X        {
  855. X            continue;
  856. X        }
  857. X
  858. X        /*
  859. X        ** If it's a '#', read forward to next newline and start over.
  860. X        */
  861. X
  862. X        if ('#' == c)
  863. X        {
  864. X            while ((c = fgetc(configfile)) != EOF)
  865. X            {
  866. X                if ('\n' == c)
  867. X                {
  868. X                    break;
  869. X                }
  870. X            }
  871. X            continue;
  872. X        }
  873. X
  874. X        /*
  875. X        ** Found something that's not whitespace or a comment,
  876. X        ** must be an entry. So get name of type.
  877. X        */
  878. X
  879. X        scratch[0] = c;
  880. X        for (loop = 1; isspace((c = fgetc(configfile))) == 0; loop++)
  881. X        {
  882. X            if (EOF == c)
  883. X            {
  884. X                scratch[loop] = '\0';
  885. X                fprintf(stderr,
  886. X                        "WARNING: Type name %s has no extension list in %s\n",
  887. X                        scratch, cfg_name);
  888. X                break;
  889. X            }
  890. X            scratch[loop] = (char) c;
  891. X        }
  892. X        if (EOF == c)
  893. X        {
  894. X            continue;
  895. X        }
  896. X        scratch[loop] = '\0';
  897. X
  898. X        /*
  899. X        ** Search through format name list for match, case sensitive.
  900. X        */
  901. X
  902. X        for (loop = 0; formatsearch[loop].name[0] != '\0'; loop++)
  903. X        {
  904. X            if (strcmp(formatsearch[loop].name, scratch) == 0)
  905. X            {
  906. X                /* Got a match, break out. */
  907. X
  908. X                break;
  909. X            }
  910. X        }
  911. X        if ('\0' == formatsearch[loop].name[0])
  912. X        {
  913. X            /* Didn't get a match. */
  914. X
  915. X            fprintf(stderr,
  916. X                 "WARNING: Unrecognized format id %s in configuration file.\n",
  917. X                 scratch);
  918. X
  919. X            /* So read forward to next newline and continue. */
  920. X
  921. X            while ((c = fgetc(configfile)) != EOF)
  922. X            {
  923. X                if ('\n' == c)
  924. X                {
  925. X                    break;
  926. X                }
  927. X            }
  928. X            continue;
  929. X        }
  930. X
  931. X        /*
  932. X        ** Allocate an EXTLIST structure, initialize.
  933. X        */
  934. X
  935. X        if ((tempext = (EXTLIST *) malloc(sizeof(EXTLIST))) == 
  936. X            (EXTLIST *) NULL)
  937. X        {
  938. X            fclose(configfile);
  939. X            return FM_NOMEM_F;
  940. X        }
  941. X
  942. X        /* Copy name into EXTLIST structure. */
  943. X
  944. X        strcpy(tempext->name, formatsearch[loop].name);
  945. X
  946. X        /*
  947. X        ** Read extensions.
  948. X        */
  949. X
  950. X        go = 1;
  951. X        extcount = 0;
  952. X        extarraysize = EXTS_GUESS;
  953. X        tempext->exts = (char **) malloc((extarraysize + 1) * sizeof(char *));
  954. X        if (((char **) NULL) == tempext->exts)
  955. X        {
  956. X            fclose(configfile);
  957. X            return FM_NOMEM_F;
  958. X        }
  959. X        while (1 == go)
  960. X        {
  961. X            /* Skip forward to next non-whitespace, non-comma. */
  962. X
  963. X            while ((c = fgetc(configfile)) != EOF)
  964. X            {
  965. X                if (',' == c)
  966. X                {
  967. X                    continue;
  968. X                }
  969. X                if (isspace(c) == 0)
  970. X                {
  971. X                    break;
  972. X                }
  973. X            }
  974. X            if (EOF == c)
  975. X            {
  976. X                go = 0;
  977. X                continue;
  978. X            }
  979. X            scratch[0] = c;
  980. X
  981. X            /* Read characters until hit comma, whitespace, or EOF. */
  982. X
  983. X            for (loop = 1; (c = fgetc(configfile)) != EOF; loop++)
  984. X            {
  985. X                if ('\n' == c)
  986. X                {
  987. X                    go = 0;
  988. X                    break;
  989. X                }
  990. X                if ((isspace(c)) || (',' == c))
  991. X                {
  992. X                    break;
  993. X                }
  994. X                scratch[loop] = (char) c;
  995. X            }
  996. X            scratch[loop] = '\0';
  997. X
  998. X            /* Check extension length. */
  999. X
  1000. X            if ('\0' == scratch[0])
  1001. X            {
  1002. X                fprintf(stderr,
  1003. X                        "WARNING: Skipping null extension for type %s\n",
  1004. X                        tempext->name);
  1005. X            }
  1006. X
  1007. X            /* Is array large enough? */
  1008. X
  1009. X            if (extcount >= extarraysize)
  1010. X            {
  1011. X                extarraysize += EXTS_GUESS;
  1012. X                tempre = (char **) realloc(tempext->exts,
  1013. X                                           ((extarraysize + 1) * 
  1014. X                                            sizeof(char *)));
  1015. X                if (((char **) NULL) == tempre)
  1016. X                {
  1017. X                    fclose(configfile);
  1018. X                    return FM_NOMEM_F;
  1019. X                }
  1020. X                tempext->exts = tempre;
  1021. X            }
  1022. X
  1023. X            /* Put extension into array. */
  1024. X
  1025. X            tempext->exts[extcount++] = strdup(scratch);
  1026. X        }
  1027. X
  1028. X        /*
  1029. X        ** If error while reading extensions, break out of loop,
  1030. X        ** else clean up a bit.
  1031. X        */
  1032. X
  1033. X        if (-1 == go)
  1034. X        {
  1035. X            break;
  1036. X        }
  1037. X
  1038. X        /* Check that there were extensions. */
  1039. X
  1040. X        if (0 == extcount)
  1041. X        {
  1042. X            /* If none, free structures and get another entry. */
  1043. X
  1044. X            fprintf(stderr, "WARNING: No extensions found for type %s\n",
  1045. X                    tempext->name);
  1046. X            free(tempext->exts);
  1047. X            free(tempext);
  1048. X            continue;
  1049. X        }
  1050. X
  1051. X        /* Shrink exts to minimum size necessary. */
  1052. X
  1053. X        tempre = (char **) realloc(tempext->exts,
  1054. X                                   ((extcount + 1) * sizeof(char *)));
  1055. X        if (((char **) NULL) == tempre)
  1056. X        {
  1057. X            fclose(configfile);
  1058. X            return FM_NOMEM_F;
  1059. X        }
  1060. X        else
  1061. X        {
  1062. X            tempext->exts = tempre;
  1063. X        }
  1064. X        tempext->exts[extcount] = (char *) NULL;
  1065. X
  1066. X        /* Put extension list on list of extension lists. */
  1067. X
  1068. X        tempext->next = extlist;
  1069. X        extlist = tempext;
  1070. X
  1071. X        /* Go get another entry. */
  1072. X
  1073. X        if (fseek(configfile, -1L, SEEK_CUR) != 0)
  1074. X        {
  1075. X            fclose(configfile);
  1076. X            return FM_READERR_E;
  1077. X        }
  1078. X    }
  1079. X
  1080. X    /*
  1081. X    ** Clean up.
  1082. X    */
  1083. X
  1084. X    fclose(configfile);
  1085. X
  1086. X    return ST_SUCCESS;
  1087. X} /* end of re_init() */
  1088. X
  1089. X
  1090. X/***************************************************************************
  1091. X*   FUNCTION:  re_deinit                                                   *
  1092. X*                                                                          *
  1093. X*   DESCRIPTION:                                                           *
  1094. X*                                                                          *
  1095. X*       Frees extension lists.                                             *
  1096. X*                                                                          *
  1097. X*   ENTRY:                                                                 *
  1098. X*                                                                          *
  1099. X*       Nothing.                                                           *
  1100. X*                                                                          *
  1101. X*   EXIT:                                                                  *
  1102. X*                                                                          *
  1103. X*       Returns nothing.                                                   *
  1104. X*                                                                          *
  1105. X*   CONSTRAINTS/SIDE EFFECTS:                                              *
  1106. X*                                                                          *
  1107. X***************************************************************************/
  1108. XVOID
  1109. Xre_deinit()
  1110. X{
  1111. X    EXTLIST *temp;
  1112. X    int loop;
  1113. X
  1114. X    /* Free extension list, if present. */
  1115. X
  1116. X    while (extlist != (EXTLIST *) NULL)
  1117. X    {
  1118. X        temp = extlist;
  1119. X        extlist = extlist->next;
  1120. X        for (loop = 0; temp->exts[loop] != NULL; loop++)
  1121. X        {
  1122. X            free(temp->exts[loop]);
  1123. X        }
  1124. X        free(temp->exts);
  1125. X        free(temp);
  1126. X    }
  1127. X
  1128. X    return;
  1129. X} /* end of re_deinit() */
  1130. X
  1131. X
  1132. X/***************************************************************************
  1133. X*   FUNCTION:  re_extlist                                                  *
  1134. X*                                                                          *
  1135. X*   DESCRIPTION:                                                           *
  1136. X*                                                                          *
  1137. X*       Searches list of extension lists for list belonging to given       *
  1138. X*       image format.                                                      *
  1139. X*                                                                          *
  1140. X*   ENTRY:                                                                 *
  1141. X*                                                                          *
  1142. X*       fortype - format id                                                *
  1143. X*                                                                          *
  1144. X*   EXIT:                                                                  *
  1145. X*                                                                          *
  1146. X*       Pointer to extension list (array of strings), or NULL if no        *
  1147. X*       extension list exists for the given format.                        *
  1148. X*                                                                          *
  1149. X*   CONSTRAINTS/SIDE EFFECTS:                                              *
  1150. X*                                                                          *
  1151. X***************************************************************************/
  1152. Xchar **
  1153. X#ifdef __STDC__
  1154. Xre_extlist(char *fortype)
  1155. X#else
  1156. Xre_extlist(fortype)
  1157. Xchar *fortype;
  1158. X#endif
  1159. X{
  1160. X    EXTLIST *tempext;
  1161. X
  1162. X    /* Search list of extension lists for keyword. */
  1163. X
  1164. X    for (tempext = extlist; tempext != (EXTLIST *) NULL;
  1165. X         tempext = tempext->next)
  1166. X    {
  1167. X        if (strcmp(tempext->name, fortype) == 0)
  1168. X        {
  1169. X            /* Got a match, break out. */
  1170. X
  1171. X            break;
  1172. X        }
  1173. X    }
  1174. X
  1175. X    /* Check exit from loop. */
  1176. X
  1177. X    if (((EXTLIST *) NULL) == tempext)
  1178. X    {
  1179. X        /* No match, so return NULL. */
  1180. X
  1181. X        return (char **) NULL;
  1182. X    }
  1183. X
  1184. X    /* Got a match, return it. */
  1185. X
  1186. X    return tempext->exts;
  1187. X} /* end of re_extlist() */
  1188. X
  1189. X
  1190. X/***************************************************************************
  1191. X*   FUNCTION: re_errstring                                                 *
  1192. X*                                                                          *
  1193. X*   DESCRIPTION:                                                           *
  1194. X*                                                                          *
  1195. X*       Returns a string corresponding to the given error.                 *
  1196. X*                                                                          *
  1197. X*   ENTRY:                                                                 *
  1198. X*                                                                          *
  1199. X*       errcode - error code to be translated                              *
  1200. X*                                                                          *
  1201. X*   EXIT:                                                                  *
  1202. X*                                                                          *
  1203. X*       Returns a pointer to the appropriate string, or NULL if there is   *
  1204. X*       no appropriate string.                                             *
  1205. X*                                                                          *
  1206. X*   CONSTRAINTS/SIDE EFFECTS:                                              *
  1207. X*                                                                          *
  1208. X***************************************************************************/
  1209. Xchar *
  1210. X#ifdef __STDC__
  1211. Xre_errstring(ULONG errcode)
  1212. X#else
  1213. Xre_errstring(errcode)
  1214. XULONG errcode;
  1215. X#endif
  1216. X{
  1217. X    char *temp;
  1218. X
  1219. X    /* If not an FM module error code, return NULL. */
  1220. X
  1221. X    if (MODULE(errcode) != MODULE(FM_MODULE))
  1222. X    {
  1223. X        return NULL;
  1224. X    }
  1225. X
  1226. X    /* Process by code. */
  1227. X
  1228. X    switch (ERRSEV(errcode))
  1229. X    {
  1230. X        case ERRSEV(FM_UNRECOGNIZED_W):
  1231. X            temp = "File type not recognized.";
  1232. X            break;
  1233. X        case ERRSEV(FM_EOF_W):
  1234. X            temp = "EOF encountered when tokenizing file.";
  1235. X            break;
  1236. X        case ERRSEV(FM_NOCFGFILE_W):
  1237. X            temp = "Cannot find configuration file.";
  1238. X            break;
  1239. X
  1240. X        case ERRSEV(FM_READERR_E):
  1241. X            temp = "Critical error reading configuration file.";
  1242. X            break;
  1243. X        case ERRSEV(FM_FILEERR_E):
  1244. X            temp = "Read error when tokenizing file.";
  1245. X            break;
  1246. X
  1247. X        case ERRSEV(FM_NOMEM_F):
  1248. X            temp = "Out of memory processing configuration file.";
  1249. X            break;
  1250. X
  1251. X        default:
  1252. X            temp = NULL;
  1253. X            break;
  1254. X    }
  1255. X
  1256. X    return temp;
  1257. X} /* end of re_errstring() */
  1258. X
  1259. X
  1260. X/***************************************************************************
  1261. X*   FUNCTION:  searchpath  STATIC                                          *
  1262. X*                                                                          *
  1263. X*   DESCRIPTION:                                                           *
  1264. X*                                                                          *
  1265. X*       This function searches for an executable file progname in all      *
  1266. X*       the directories in the path.                                       *
  1267. X*                                                                          *
  1268. X*   ENTRY:                                                                 *
  1269. X*                                                                          *
  1270. X*       progname - name of program to be found                             *
  1271. X*       retbuf   - buffer in which to return directory in which program    *
  1272. X*                  was found                                               *
  1273. X*                                                                          *
  1274. X*   EXIT:                                                                  *
  1275. X*                                                                          *
  1276. X*       Returns 0 and directory on success, -1 on failure (and contents    *
  1277. X*       of retbuf are undefined).                                          *
  1278. X*                                                                          *
  1279. X*   CONSTRAINTS/SIDE EFFECTS:                                              *
  1280. X*                                                                          *
  1281. X***************************************************************************/
  1282. Xstatic int
  1283. X#ifdef __STDC__
  1284. Xsearchpath(char *progname, char *retbuf)
  1285. X#else
  1286. Xsearchpath(progname, retbuf)
  1287. Xchar *progname;
  1288. Xchar *retbuf;
  1289. X#endif
  1290. X{
  1291. X    char *path;
  1292. X    char *working;
  1293. X    char *candidate;
  1294. X    char *term;
  1295. X    char *term2;
  1296. X
  1297. X    /* Retrieve path from environment. */
  1298. X
  1299. X    if ((path = getenv("PATH")) == NULL)
  1300. X    {
  1301. X        return -1;
  1302. X    }
  1303. X
  1304. X    /* Make a working copy that we can munge. */
  1305. X
  1306. X    if ((working = strdup(path)) == NULL)
  1307. X    {
  1308. X        return -1;
  1309. X    }
  1310. X
  1311. X    /* Loop through the working copy. */
  1312. X
  1313. X    for (candidate = working, term = NULL; candidate != NULL; )
  1314. X    {
  1315. X        /* Find the next colon, terminate the candidate string there. */
  1316. X
  1317. X        term = strchr(candidate, ':');
  1318. X        if (term != NULL)
  1319. X        {
  1320. X            *term = '\0';
  1321. X        }   
  1322. X
  1323. X        /* Copy candidate into retbuf, add '/' and progname. */
  1324. X
  1325. X        strcpy(retbuf, candidate);
  1326. X        term2 = retbuf + strlen(retbuf);
  1327. X        if (term2 != retbuf)
  1328. X        {
  1329. X            *term2 = '/';
  1330. X            *(term2 + 1) = '\0';
  1331. X        }
  1332. X        strcat(retbuf, progname);
  1333. X
  1334. X        /* Does it exist? */
  1335. X
  1336. X        if (access(retbuf, 1) == 0)
  1337. X        {
  1338. X           /* Yes, so trim retbuf to be just the directory and return. */
  1339. X
  1340. X           *term2 = '\0';
  1341. X           free(working);
  1342. X           return 0;
  1343. X        }
  1344. X
  1345. X        /* Doesn't exist, so go on to next one if there is one. */
  1346. X
  1347. X        candidate = ((term != NULL) ? (term + 1) : NULL);
  1348. X    }
  1349. X
  1350. X    /* Not found. */
  1351. X
  1352. X    free(working);
  1353. X
  1354. X    return -1;
  1355. X} /* end of static searchpath() */
  1356. X
  1357. END_OF_FILE
  1358.   if test 28428 -ne `wc -c <'src/re.c'`; then
  1359.     echo shar: \"'src/re.c'\" unpacked with wrong size!
  1360.   fi
  1361.   # end of 'src/re.c'
  1362. fi
  1363. if test -f 'src/xbm.c' -a "${1}" != "-c" ; then 
  1364.   echo shar: Will not clobber existing file \"'src/xbm.c'\"
  1365. else
  1366.   echo shar: Extracting \"'src/xbm.c'\" \(11149 characters\)
  1367.   sed "s/^X//" >'src/xbm.c' <<'END_OF_FILE'
  1368. X/***************************************************************************
  1369. X*   XBM.C                                                                  *
  1370. X*   MODULE:  XBM                                                           *
  1371. X*   OS:      UNIX                                                          *
  1372. X*                                                                          *
  1373. X*   Copyright (c) 1993 James W. Birdsall. All Rights Reserved.             *
  1374. X*                                                                          *
  1375. X*   $Id: xbm.c,v 1.1 1993/03/02 01:01:00 jwbirdsa Exp $
  1376. X*                                                                          *
  1377. X*   This file contains functions to process XBM format files.              *
  1378. X*   Functions:                                                             *
  1379. X*      xbm_verify    - checks filename to see if it is an XBM file         *
  1380. X*      xbm_getheader - extracts header data from XBM file                  *
  1381. X*                                                                          *
  1382. X*      xbm_errstring - converts error code into message                    *
  1383. X*                                                                          *
  1384. X***************************************************************************/
  1385. X
  1386. X#include "config.h"
  1387. X
  1388. X/*
  1389. X** system includes <>
  1390. X*/
  1391. X
  1392. X#include <stdio.h>
  1393. X#ifndef NO_STDLIB
  1394. X#include <stdlib.h>
  1395. X#endif
  1396. X#ifndef NO_STR_INC
  1397. X#ifdef STRING_PLURAL
  1398. X#include <strings.h>
  1399. X#else
  1400. X#include <string.h>
  1401. X#endif
  1402. X#endif
  1403. X
  1404. X
  1405. X/*
  1406. X** custom includes ""
  1407. X*/
  1408. X
  1409. X#include "depend.h"
  1410. X#include "formats.h"
  1411. X#include "xbm.h"
  1412. X#include "token.h"
  1413. X
  1414. X
  1415. X/*
  1416. X** local #defines
  1417. X*/
  1418. X
  1419. X/*
  1420. X** misc: copyright strings, version macros, etc.
  1421. X*/
  1422. X
  1423. X/*
  1424. X** typedefs
  1425. X*/
  1426. X
  1427. X/*
  1428. X** global variables
  1429. X*/
  1430. X
  1431. X/*
  1432. X** static globals
  1433. X*/
  1434. X
  1435. Xstatic char CONST rcsid[] = "$Id: xbm.c,v 1.1 1993/03/02 01:01:00 jwbirdsa Exp $";
  1436. X
  1437. X
  1438. X/*
  1439. X** function prototypes
  1440. X*/
  1441. X
  1442. X#ifdef NO_STDLIB
  1443. Xextern long atol();
  1444. X#endif
  1445. X
  1446. X#ifdef NO_STR_INC
  1447. Xextern char *strchr();
  1448. Xextern char *strrchr();
  1449. Xextern int strcmp();
  1450. X#ifndef NO_STRDUP
  1451. Xextern char *strdup();
  1452. X#endif
  1453. X#endif
  1454. X
  1455. X
  1456. X/*
  1457. X** functions
  1458. X*/
  1459. X
  1460. X
  1461. X/***************************************************************************
  1462. X*   FUNCTION:    xbm_verify                                                *
  1463. X*                                                                          *
  1464. X*   DESCRIPTION:                                                           *
  1465. X*                                                                          *
  1466. X*       Verifies that a file is an XBM file by checking filename against   *
  1467. X*       list of extensions. Reads XBM version number from start of file.   *
  1468. X*                                                                          *
  1469. X*   ENTRY:                                                                 *
  1470. X*                                                                          *
  1471. X*       filename - name of file to be verified                             *
  1472. X*       version  - pointer to unsigned long in which format/version value  *
  1473. X*                  is returned                                             *
  1474. X*       exts     - array of string pointers, list of extensions for XBM    *
  1475. X*                  files                                                   *
  1476. X*                                                                          *
  1477. X*   EXIT:                                                                  *
  1478. X*                                                                          *
  1479. X*       Returns an error/status code.                                      *
  1480. X*                                                                          *
  1481. X*   CONSTRAINTS/SIDE EFFECTS:                                              *
  1482. X*                                                                          *
  1483. X***************************************************************************/
  1484. XULONG
  1485. X#ifdef __STDC__
  1486. Xxbm_verify(char *filename, ULONG *version, char **exts)
  1487. X#else
  1488. Xxbm_verify(filename, version, exts)
  1489. Xchar *filename;
  1490. XULONG *version;
  1491. Xchar **exts;
  1492. X#endif
  1493. X{
  1494. X    char *extptr;
  1495. X    int loop;
  1496. X
  1497. X    /* Search for '.' marking extension. */
  1498. X
  1499. X    extptr = strrchr(filename, '.');
  1500. X    if (NULL == extptr)
  1501. X    {
  1502. X        /* No extension, cannot classify. */
  1503. X
  1504. X        *version = XBM_NOT;
  1505. X        return 0;
  1506. X    }
  1507. X    extptr++;
  1508. X
  1509. X    /* Now we have the extension, check against list. */
  1510. X
  1511. X    for (loop = 0; exts[loop] != NULL; loop++)
  1512. X    {
  1513. X        /* Case-sensitive string compare. */
  1514. X
  1515. X        if (strcmp(extptr, exts[loop]) == 0)
  1516. X        {
  1517. X            /* Match, so break out of loop. */
  1518. X
  1519. X            break;
  1520. X        }
  1521. X    }
  1522. X
  1523. X    /* Check exit from loop. */
  1524. X
  1525. X    if (NULL == exts[loop])
  1526. X    {
  1527. X        /* No match, return. */
  1528. X
  1529. X        *version = XBM_NOT;
  1530. X        return 0;
  1531. X    }
  1532. X
  1533. X    /* Set version. */
  1534. X
  1535. X    *version = XBM_1;
  1536. X
  1537. X    /* Return OK. */
  1538. X
  1539. X    return 0;
  1540. X} /* end of xbm_verify() */
  1541. X
  1542. X
  1543. X/***************************************************************************
  1544. X*   FUNCTION:    xbm_getheader                                             *
  1545. X*                                                                          *
  1546. X*   DESCRIPTION:                                                           *
  1547. X*                                                                          *
  1548. X*       Assumes that file is an XBM file. Reads header from file, extracts *
  1549. X*       data into XBM_HDR structure.                                       *
  1550. X*                                                                          *
  1551. X*   ENTRY:                                                                 *
  1552. X*                                                                          *
  1553. X*       infile  - file to be processed                                     *
  1554. X*       results - pointer to XBM_HDR structure in which data from header   *
  1555. X*                 is returned                                              *
  1556. X*                                                                          *
  1557. X*   EXIT:                                                                  *
  1558. X*                                                                          *
  1559. X*       Returns an error/status code.                                      *
  1560. X*                                                                          *
  1561. X*   CONSTRAINTS/SIDE EFFECTS:                                              *
  1562. X*                                                                          *
  1563. X*       Leaves file pointing to beginning of image data.                   *
  1564. X*                                                                          *
  1565. X***************************************************************************/
  1566. XULONG
  1567. X#ifdef __STDC__
  1568. Xxbm_getheader(FILE *infile, XBM_HDR *results)
  1569. X#else
  1570. Xxbm_getheader(infile, results)
  1571. XFILE *infile;
  1572. XXBM_HDR *results;
  1573. X#endif
  1574. X{
  1575. X    char *token;
  1576. X    char *search;
  1577. X
  1578. X    /* Make sure we're at beginning of file. */
  1579. X
  1580. X    if (fseek(infile, 0L, SEEK_SET))
  1581. X    {
  1582. X        return XBM_FILEERR_E;
  1583. X    }
  1584. X
  1585. X    /* Get first token, should be '#define'. */
  1586. X
  1587. X    if ((token = fm_token(infile)) == NULL)
  1588. X    {
  1589. X        return XBM_FILEERR_E;
  1590. X    }
  1591. X    if (strcmp(token, "#define") != 0)
  1592. X    {
  1593. X        /* Not an XBM. */
  1594. X
  1595. X        free(token);
  1596. X        return XBM_NOTXBM_E;
  1597. X    }
  1598. X    free(token);
  1599. X
  1600. X    /* Get next token. */
  1601. X
  1602. X    if ((token = fm_token(infile)) == NULL)
  1603. X    {
  1604. X        return XBM_FILEERR_E;
  1605. X    }
  1606. X    if ((search = strchr(token, '_')) == NULL)
  1607. X    {
  1608. X        free(token);
  1609. X        return XBM_NOTXBM_E;
  1610. X    }
  1611. X    if (strcmp(search, "_width") != 0)
  1612. X    {
  1613. X        free(token);
  1614. X        return XBM_NOTXBM_E;
  1615. X    }
  1616. X    *search = '\0';
  1617. X    results->imname = token;
  1618. X
  1619. X    /* Get width value. */
  1620. X
  1621. X    if ((token = fm_token(infile)) == NULL)
  1622. X    {
  1623. X        return XBM_FILEERR_E;
  1624. X    }
  1625. X    if ((results->imwid = atol(token)) == 0L)
  1626. X    {
  1627. X        free(results->imname);
  1628. X        free(token);
  1629. X        return XBM_NOTXBM_E;
  1630. X    }
  1631. X
  1632. X    /* Get next token, should be '#define'. */
  1633. X
  1634. X    if ((token = fm_token(infile)) == NULL)
  1635. X    {
  1636. X        return XBM_FILEERR_E;
  1637. X    }
  1638. X    if (strcmp(token, "#define") != 0)
  1639. X    {
  1640. X        /* Not an XBM. */
  1641. X
  1642. X        free(token);
  1643. X        free(results->imname);
  1644. X        return XBM_NOTXBM_E;
  1645. X    }
  1646. X    free(token);
  1647. X
  1648. X    /* Get next token. */
  1649. X
  1650. X    if ((token = fm_token(infile)) == NULL)
  1651. X    {
  1652. X        return XBM_FILEERR_E;
  1653. X    }
  1654. X    if ((search = strchr(token, '_')) == NULL)
  1655. X    {
  1656. X        free(token);
  1657. X        free(results->imname);
  1658. X        return XBM_NOTXBM_E;
  1659. X    }
  1660. X    if (strcmp(search, "_height") != 0)
  1661. X    {
  1662. X        free(token);
  1663. X        free(results->imname);
  1664. X        return XBM_NOTXBM_E;
  1665. X    }
  1666. X    free(token);
  1667. X
  1668. X    /* Get height value. */
  1669. X
  1670. X    if ((token = fm_token(infile)) == NULL)
  1671. X    {
  1672. X        return XBM_FILEERR_E;
  1673. X    }
  1674. X    if ((results->imhi = atol(token)) == 0L)
  1675. X    {
  1676. X        free(token);
  1677. X        free(results->imname);
  1678. X        return XBM_NOTXBM_E;
  1679. X    }
  1680. X
  1681. X    /* File already set to point to start of data. */
  1682. X
  1683. X    /* Return OK. */
  1684. X
  1685. X    return 0;
  1686. X} /* end of xbm_getheader() */
  1687. X
  1688. X
  1689. X/***************************************************************************
  1690. X*   FUNCTION: xbm_errstring                                                *
  1691. X*                                                                          *
  1692. X*   DESCRIPTION:                                                           *
  1693. X*                                                                          *
  1694. X*      Returns a string corresponding to an error code.                    *
  1695. X*                                                                          *
  1696. X*   ENTRY:                                                                 *
  1697. X*                                                                          *
  1698. X*      errcode - error code to be translated                               *
  1699. X*                                                                          *
  1700. X*   EXIT:                                                                  *
  1701. X*                                                                          *
  1702. X*      Returns a pointer to the appropriate string, or NULL if there is    *
  1703. X*      no appropriate string.                                              *
  1704. X*                                                                          *
  1705. X*   CONSTRAINTS/SIDE EFFECTS:                                              *
  1706. X*                                                                          *
  1707. X***************************************************************************/
  1708. Xchar *
  1709. X#ifdef __STDC__
  1710. Xxbm_errstring(ULONG errcode)
  1711. X#else
  1712. Xxbm_errstring(errcode)
  1713. XULONG errcode;
  1714. X#endif
  1715. X{
  1716. X    char *temp;
  1717. X
  1718. X    /* If error code not from this module, return NULL. */
  1719. X
  1720. X    if ((errcode & ST_MOD_MASK) != XBM_MODULE)
  1721. X    {
  1722. X        return NULL;
  1723. X    }
  1724. X
  1725. X    /* Process by code. */
  1726. X
  1727. X    switch (ERRSEV(errcode))
  1728. X    {
  1729. X        case ERRSEV(XBM_NOTXBM_E):
  1730. X            temp = "File is not a XBM format file.";
  1731. X            break;
  1732. X        case ERRSEV(XBM_FILEERR_E):
  1733. X            temp = "Error accessing file.";
  1734. X            break;
  1735. X        case ERRSEV(XBM_UNEOF_E):
  1736. X            temp = "Unexpected End of File";
  1737. X            break;
  1738. X
  1739. X        default:
  1740. X            temp = NULL;
  1741. X            break;
  1742. X    }
  1743. X
  1744. X    return temp;
  1745. X} /* end of xbm_errstring() */
  1746. X
  1747. END_OF_FILE
  1748.   if test 11149 -ne `wc -c <'src/xbm.c'`; then
  1749.     echo shar: \"'src/xbm.c'\" unpacked with wrong size!
  1750.   fi
  1751.   # end of 'src/xbm.c'
  1752. fi
  1753. if test -f 'templates/pcix.h' -a "${1}" != "-c" ; then 
  1754.   echo shar: Will not clobber existing file \"'templates/pcix.h'\"
  1755. else
  1756.   echo shar: Extracting \"'templates/pcix.h'\" \(819 characters\)
  1757.   sed "s/^X//" >'templates/pcix.h' <<'END_OF_FILE'
  1758. X/*
  1759. X** Configuration file for PC/IX 1.0 and 1.1 with the stock compiler.
  1760. X*/
  1761. X
  1762. X#define CONFIG_H
  1763. X
  1764. X/* no memory functions */
  1765. X#define NO_MEMOP
  1766. X
  1767. X/* no stdlib.h */
  1768. X#define NO_STDLIB
  1769. X
  1770. X/* no malloc.h */
  1771. X#define NO_MALLOCHDR
  1772. X
  1773. X/* void not really supported */
  1774. X#define NO_VOID
  1775. X
  1776. X/* 16-bit ints */
  1777. X#define INT16
  1778. X
  1779. X/* cc doesn't support "const" type */
  1780. X#define NO_CONST
  1781. X
  1782. X/* ustat() function present */
  1783. X#define USTAT
  1784. X#define SYS_BLOCKSIZE       512
  1785. X
  1786. X/* no strdup() function */
  1787. X#define NO_STRDUP
  1788. X
  1789. X/* small memory size */
  1790. X#define SMALL_MEM
  1791. X
  1792. X/* no directory-access functions */
  1793. X#define DIR_NODIR
  1794. X
  1795. X/* no rename() function */
  1796. X#define NO_RENAME
  1797. X
  1798. X/* enable progress indicator */
  1799. X#define PROGRESS_IND
  1800. X
  1801. X/* errno.h does not declare errno */
  1802. X#define NO_ERRNO
  1803. X
  1804. X/* no string include files */
  1805. X#define NO_STR_INC
  1806. X
  1807. X/* have TERMCAP */
  1808. X#define HAS_TERMCAP
  1809. END_OF_FILE
  1810.   if test 819 -ne `wc -c <'templates/pcix.h'`; then
  1811.     echo shar: \"'templates/pcix.h'\" unpacked with wrong size!
  1812.   fi
  1813.   # end of 'templates/pcix.h'
  1814. fi
  1815. echo shar: End of archive 14 \(of 18\).
  1816. cp /dev/null ark14isdone
  1817. MISSING=""
  1818. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ; do
  1819.     if test ! -f ark${I}isdone ; then
  1820.     MISSING="${MISSING} ${I}"
  1821.     fi
  1822. done
  1823. if test "${MISSING}" = "" ; then
  1824.     echo You have unpacked all 18 archives.
  1825.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1826. else
  1827.     echo You still must unpack the following archives:
  1828.     echo "        " ${MISSING}
  1829. fi
  1830. exit 0
  1831. exit 0 # Just in case...
  1832.