home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0040 - 0049 / ibm0040-0049 / ibm0040.tar / ibm0040 / IMGPROC.ZIP / C6VIEW.ZIP / VIEW.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-10-11  |  4.9 KB  |  155 lines

  1. /*
  2. Copyright 1990 by John Wiley & Sons, Inc.
  3.           All Rights Reserved.
  4. */
  5. /****************************************/
  6. /*  PCX/TIFF File View Utility Program  */
  7. /*       written in Turbo C 2.0         */
  8. /*                by                    */
  9. /*         Craig A. Lindley             */
  10. /*  Usage:                              */
  11. /*   view [-v ?] filename[.pcx | .tif]  */
  12. /*   Vers: 2.1  Last Update: 10/11/90   */
  13. /****************************************/
  14. /*
  15. NOTE:
  16. This example program must be compiled using Turbo's medium
  17. memory model because of its size.
  18. */
  19.  
  20. #include <stdio.h>
  21. #include <process.h>
  22. #include <conio.h>
  23. #include <dos.h>
  24. #include <graphics.h>
  25. #include <string.h>
  26. #include <io.h>
  27. #include "misc.h"
  28. #include "pcx.h"
  29. #include "tiffintf.h"
  30.  
  31. #define MAXFILENAMELENGTH 30 /* max supported length of filename */
  32.  
  33. extern struct PCX_File PCXData;
  34.  
  35. /* current revision level */
  36. unsigned Release = 2;
  37. unsigned Revision = 1;
  38.  
  39. /*
  40. This function provides help in the advent of operator error.
  41. Program terminates after help is given
  42. */
  43.  
  44. void ShowHelp( void )
  45. {
  46.    printf("\nView usage: view [-v ?] filename[.pcx | .tif] <cr>\n");
  47.    printf("  -v displays image file information\n");
  48.    printf("  ? or -?  displays this help text\n");
  49.    printf("  filename is name given to PCX or TIFF image file\n\n");
  50.    exit(EBadParms);
  51. }
  52.  
  53. void main(unsigned argc, char *argv[])
  54. {
  55.    unsigned Verbose = FALSE;
  56.    unsigned FileNameCounter, ArgIndex, StrLength;
  57.    char    *ImageFileName;
  58.    char    FileName[MAXFILENAMELENGTH];
  59.    char    PCXFileName[MAXFILENAMELENGTH];
  60.    char    TIFFFileName[MAXFILENAMELENGTH];
  61.  
  62.    clrscr();
  63.    printf("View - PCX or TIFF Image File Display Program\n");
  64.    printf("  Version: %d.%d by Craig A. Lindley\n\n",Release,Revision);
  65.  
  66.    /* parse all command line arguments */
  67.  
  68.    FileNameCounter = 0;                /* count of user specified filenames */
  69.    for (ArgIndex=1; ArgIndex < argc; ArgIndex++)
  70.    {
  71.       if (*argv[ArgIndex] != '-')      /* if not a cmd line switch */
  72.       {                                /* must be a filename */
  73.      if (*argv[ArgIndex] == '?')   /* help requested ? */
  74.         ShowHelp();
  75.      if (FileNameCounter > 1)      /* only one filename allowed */
  76.             ShowHelp();                /* if more then error exit */
  77.      ImageFileName = argv[ArgIndex];  /* save image filename */
  78.          FileNameCounter++;            /* inc count for error check */
  79.       }
  80.       else                             /* its a cmd line switch */
  81.       {
  82.          switch (*(argv[ArgIndex]+1))     /* parse the cmd line */
  83.          {
  84.             case 'v':
  85.             case 'V':
  86.               Verbose = TRUE;
  87.               break;
  88.             case '?':
  89.           ShowHelp();
  90.               break;
  91.         default:
  92.           printf("Error - invalid cmd line switch encountered\n");
  93.           ShowHelp();
  94.          }
  95.       }
  96.    }
  97.    if (FileNameCounter != 1)
  98.    {
  99.       printf("Error: a single PCX or TIFF filename must be specified\n");
  100.       ShowHelp();
  101.    }
  102.  
  103.    printf("Press the <Enter> key to terminate display\n\n\n");
  104.    delay(1000);
  105.    /*
  106.    Check for which type of file to display. This
  107.    sometimes means adding filename extensions if
  108.    one was not specified by the user.
  109.    */
  110.    strupr(ImageFileName);                    /* Convert to upper case */
  111.    if (strstr(ImageFileName,".PCX"))         /* does it have a .PCX ext ? */
  112.       DisplayPCXFile(ImageFileName,Verbose); /* display PCX file */
  113.    else if (strstr(ImageFileName,".TIF"))    /* does it have a .TIF ext ? */
  114.       DisplayTIFFFile(ImageFileName,Verbose);/* display TIFF file */
  115.    else
  116.    {
  117.       strcpy(FileName,"");                   /* make storage empty */
  118.  
  119.       /* find filename length minus the extension */
  120.       StrLength = strcspn(ImageFileName,".");
  121.  
  122.       if (StrLength == 0)                    /* no ext specified */
  123.      strncat(FileName,ImageFileName,MAXFILENAMELENGTH); /* copy filename completely */
  124.       else                                   /* an ext was specified */
  125.      strncat(FileName,ImageFileName,StrLength); /* copy name only */
  126.       /*
  127.       Copy the processed file name to each of the
  128.       filename storage areas and append the appropriate string.
  129.       */
  130.       strcpy(PCXFileName,FileName);
  131.       strcat(PCXFileName,".PCX");
  132.       strcpy(TIFFFileName,FileName);
  133.       strcat(TIFFFileName,".TIF");
  134.       /*
  135.       Determine is files with these extensions really
  136.       exist. If so display with appropriate
  137.       function.
  138.       */
  139.       if (access(PCXFileName,0) == 0)          /* does PCX file exist ? */
  140.      DisplayPCXFile(PCXFileName,Verbose);  /* yes then display */
  141.       else if (access(TIFFFileName,0) == 0)    /* does TIFF file exist ? */
  142.      DisplayTIFFFile(TIFFFileName,Verbose);/* yes then display */
  143.       else
  144.       {
  145.      printf("Neither file %s nor %s found\n",
  146.          PCXFileName,TIFFFileName);
  147.      exit(EFileNotFound);
  148.       }
  149.    }
  150.    getchar();
  151.    restorecrtmode();
  152.    closegraph();
  153. }
  154.  
  155.