home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / c / rflic2 / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-01  |  2.6 KB  |  96 lines

  1. /* main.c - This module opens up a graphics display,  and sends all the
  2.  * flics in the command line over to routines in readflic.c to play back.
  3.  *
  4.  * Copyright (c) 1992 Jim Kent.  This file may be freely used, modified,
  5.  * copied and distributed.  This file was first published as part of
  6.  * an article for Dr. Dobb's Journal March 1993 issue.
  7.  */
  8.  
  9. #include <stdio.h>   
  10. #include "types.h"
  11. #include "pcclone.h"
  12. #include "flic.h"
  13. #include "readflic.h"
  14.  
  15. static char about[] =
  16. "READFLIC - a program that plays back .FLI and .FLC files.  This is \n"
  17. "not the fastest flic player in the world.  It is an example written \n"
  18. "purely in C to illustrate decoding the flic file format.\n"
  19. "READFLIC is copyright (c) 1992 Jim Kent.  It is freely distributable.\n"
  20. "Please see the March 1993 Dr. Dobb's Journal for source code.\n"
  21. "Usage:\n"
  22. "   readflic flic1.flc ... flicN.flc\n"
  23. "Hit any key to stop the program.";
  24.  
  25. static void center_flic(Flic *flic, Screen *s)
  26.     /* Set flic.xoff and flic.yoff so flic plays centered rather
  27.      * than in upper left corner of display. */
  28. {
  29.     flic->xoff = (screen_width(s) - (signed)flic->head.width)/2;
  30.     flic->yoff = (screen_height(s) - (signed)flic->head.height)/2;
  31. }
  32.  
  33. void main(int argc, char *argv[])
  34.     /* Check command line.  If empty print usage message.  Otherwise
  35.      * open up machine for animation (get screen, clock & keyboard)
  36.      * and play back flics.
  37.      */
  38. {
  39. ErrCode err;
  40. char *title = argv[1];
  41. Flic flic;
  42. int i;
  43. Machine machine;
  44.  
  45.     /* Check command line for any flics.  If none then print usage
  46.      * instructions and exit. */
  47. if (argc < 2)
  48.     {
  49.     puts(about);
  50.     return;
  51.     }
  52. if ((err = machine_open(&machine)) >= Success)
  53.     {
  54.     if (argc == 2)
  55.         {
  56.             /* If just one flic in command line play it in loop mode. */
  57.         title = argv[1];
  58.         if ((err = flic_open(&flic, title)) >= Success)
  59.             {
  60.             center_flic(&flic, &machine.screen);
  61.             err = flic_play_loop(&flic, &machine);
  62.             flic_close(&flic);
  63.             }
  64.         }
  65.     else
  66.         {
  67.             /* If more than one flic play them once each, and then
  68.              * loop around to first one. */
  69.         for (;;)
  70.             {
  71.             for (i=1; i<argc; ++i)
  72.                 {
  73.                 title = argv[i];
  74.                 if ((err = flic_open(&flic, title)) >= Success)
  75.                     {
  76.                     center_flic(&flic, &machine.screen);
  77.                     err = flic_play_once(&flic, &machine);
  78.                     flic_close(&flic);
  79.                     }
  80.                 if (err < Success)
  81.                     break;
  82.                 }
  83.             if (err < Success)
  84.                 break;
  85.             }
  86.         }
  87.     machine_close(&machine);
  88.     }
  89.     /* Report errors back in text mode. */
  90. if (err < Success && err != ErrCancel)
  91.     {
  92.     printf("READFLIC had troubles with %s.\n%s.\n"
  93.     , title, flic_err_string(err) );
  94.     }
  95. }
  96.