home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 5 / FreshFish_July-August1994.bin / useful / dist / gfx / show / superview-lib / programmers / example_tools / simpleview / simpleview.c < prev    next >
C/C++ Source or Header  |  1994-07-04  |  12KB  |  394 lines

  1. /* ======================================================================== */
  2. /* = Programmname    : SimpleView V6.5                      = */
  3. /* =                                      = */
  4. /* ======================================================================== */
  5. /* = Author/Copyright : (c) 1993-94 by Andreas Ralph Kleinert.            = */
  6. /* =               Freeware. All rights reserved.              = */
  7. /* =                                      = */
  8. /* =                   Use it as an example for programming               = */
  9. /* =                   superview.library !                                = */
  10. /* =                                      = */
  11. /* ======================================================================== */
  12. /* = Function          : SVObject operations :                             = */
  13. /* =                - Write WB-Screen content (IFF-ILBM/-ACBM)        = */
  14. /* =                - Show graphics         (all SVObjects)          = */
  15. /* =                - Convert graphics     (IFF-ILBM/-ACBM)         = */
  16. /* ======================================================================== */
  17. /* = Last Update      : 14.6.1994                      = */
  18. /* =                                      = */
  19. /* ======================================================================== */
  20. /* = Remarks          : Needs "asl.library" V37+                          = */
  21. /* =                and "superview.library" V6+.                      = */
  22. /* =                                      = */
  23. /* =            Based on KILBM V1.32.                             = */
  24. /* =                                      = */
  25. /* ======================================================================== */
  26. /* = Compiler          : SAS/C V6.51                        = */
  27. /* =                (smakefile)                                       = */
  28. /* ======================================================================== */
  29.  
  30. #include <intuition/intuitionbase.h>
  31.  
  32. #include <superview/superview.h>
  33.  
  34. #include <libraries/asl.h>
  35. #include <workbench/startup.h>
  36. #include <exec/interrupts.h>
  37.  
  38. #include <proto/exec.h>
  39. #include <proto/dos.h>
  40. #include <proto/intuition.h>
  41. #include <proto/graphics.h>
  42. #include <proto/asl.h>
  43. #include <proto/superview.h>
  44.  
  45. #include <stdio.h>
  46. #include <stdlib.h>
  47. #include <string.h>
  48.  
  49.  
  50.    /* Help- and Info- Texts */
  51.  
  52. char entry1_text  [] = "\2331;32;40mSimpleView V6.5 \2330;32;40m\2333;32;40m(FREEWARE)\2330;32;40m\n(c) 1993-94 by Andreas Ralph Kleinert.\nAndreas R. Kleinert, Grube Hohe Grethe 23, D-57074 Siegen, Germany.\n";
  53. char entry2_text  [] = "Uses superview.library to write, show and convert IFF-ILBM/-ACBM.\n";
  54. char entry3_text  [] = "USAGE : \2330;33;40mSimpleView\2330;31;40m -[w | wp | wa | r | s | ci | cip | ca | ?] <PicFileName>\n";
  55. char entry4_text  [] = "   '-w'   -> Write current screen page to IFF-ILBM-file (unpacked).\n";
  56. char entry5_text  [] = "   '-wp'  -> Write current screen page to IFF-ILBM-file (packed).\n";
  57. char entry6_text  [] = "   '-wa'  -> Write current screen page to IFF-ACBM-file.\n";
  58. char entry7_text  [] = "   '-s'   -> Show an IFF-ILBM-/ACBM-file (optional).\n";
  59. char entry8_text  [] = "   '-ci'  -> Convert IFF-ACBM to IFF-ILBM (unpacked).\n";
  60. char entry9_text  [] = "   '-cip' -> Convert IFF-ACBM to IFF-ILBM (packed).\n";
  61. char entry10_text [] = "   '-ca'  -> Convert IFF-ILBM to IFF-ACBM.\n";
  62. char entry11_text [] = "   '?'    -> This text.\n";
  63.  
  64.  
  65. char ver_text [] = "\0$VER: SimpleView V6.5 (14.6.94)";
  66.  
  67.  
  68. /* *************************************************** */
  69. /* *                             * */
  70. /* * Error-Messages for Leave() and KF_Message()     * */
  71. /* *                             * */
  72. /* *************************************************** */
  73.  
  74. char intuitionlib_text    [] = "You need \42intuition.library\42 V37+ !";
  75. char graphicslib_text    [] = "You need \42graphics.library\42 V37+ !";
  76. char asllib_text     [] = "You need \42asl.library\42 V37+ !";
  77. char svlib_text     [] = "You need \42superview.library\42 V6+ !";
  78.  
  79.  
  80. /* *************************************************** */
  81. /* *                             * */
  82. /* * MACROs for Version-Tests                 * */
  83. /* *                             * */
  84. /* *************************************************** */
  85.  
  86. #define LibVer(x) ( ((struct Library *) x)->lib_Version )
  87. #define OS_VER      LibVer(SysBase)
  88.  
  89.  
  90. /* *************************************************** */
  91. /* *                             * */
  92. /* * Function Declarations                 * */
  93. /* *                             * */
  94. /* *************************************************** */
  95.  
  96. void __regargs SimpleView_Show(char *filename);
  97. void __regargs SimpleView_Write(char *filename, ULONG type);
  98. void __regargs SimpleView_Convert(char *filename, ULONG type);
  99.  
  100.  
  101. void __regargs Leave(char *endtext, long code);
  102.  
  103.  
  104.    /* Functions from module "SimpleView_Subs.o" : */
  105.  
  106. extern void __stdargs K_Printf(char *formatstring, ...);
  107.  
  108.  
  109. /* *************************************************** */
  110. /* *                             * */
  111. /* * Additional Base Declarations             * */
  112. /* *                             * */
  113. /* *************************************************** */
  114.  
  115. extern struct ExecBase *SysBase;
  116.  
  117. struct IntuitionBase *IntuitionBase = N;
  118. struct GfxBase       *GfxBase       = N;
  119. struct Library       *AslBase       = N;
  120. struct SuperViewBase *SuperViewBase = N;
  121.  
  122.  
  123. /* *************************************************** */
  124. /* *                             * */
  125. /* * MAIN                         * */
  126. /* *                             * */
  127. /* *************************************************** */
  128.  
  129. extern struct WBStartup *WBenchMsg;
  130. char                *wbloadname = N;
  131. long                     wb         = FALSE;
  132.  
  133. void main(long argc, char **argv)
  134. {
  135.  if(!argc)
  136.   {
  137.    wb = TRUE;
  138.  
  139.    if(WBenchMsg->sm_NumArgs>1) wbloadname = WBenchMsg->sm_ArgList[1].wa_Name;
  140.   }
  141.  
  142.  if( argc > 3 || (argv[1][0] =='?')||(argv[2][0] =='?'))
  143.   {
  144.    K_Printf("%s%s%s%s%s%s%s%s%s%s%s", entry1_text, entry2_text, entry3_text, entry4_text, entry5_text, entry6_text, entry7_text, entry8_text, entry9_text, entry10_text, entry11_text);
  145.  
  146.    Leave(N, 0);
  147.   }
  148.  
  149.  IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 37);
  150.  if(!IntuitionBase) Leave(intuitionlib_text, 100);
  151.  
  152.  GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 37);
  153.  if(!GfxBase) Leave(graphicslib_text, 101);
  154.  
  155.  AslBase = (struct Library *) OpenLibrary("asl.library", 37);
  156.  if(!AslBase) Leave(asllib_text, 102);
  157.  
  158.  SuperViewBase = (struct SuperViewBase *) OpenLibrary("superview.library", 6);
  159.  if(!SuperViewBase) Leave(svlib_text, 103);
  160.  
  161.  
  162.  /* Show */
  163.  
  164.  if(argc < 2 && !wbloadname)
  165.   {
  166.    struct FileRequester     *request;
  167.    struct TagItem __aligned  tags[4];
  168.    char                      namebuffer [256];
  169.  
  170.    namebuffer[0] = (char) 0;
  171.  
  172.    tags[0].ti_Tag  = (Tag)   ASL_Hail;
  173.    tags[0].ti_Data = (ULONG) "Select Picture to Display :";
  174.  
  175.    tags[1].ti_Tag  = (Tag)   ASL_OKText;
  176.    tags[1].ti_Data = (ULONG) " Display ";
  177.  
  178.    tags[2].ti_Tag  = (Tag)   ASL_CancelText;
  179.    tags[2].ti_Data = (ULONG) " Quit ";
  180.  
  181.    tags[3].ti_Tag  = (Tag)   TAG_DONE;
  182.    tags[3].ti_Data = (ULONG) N;
  183.  
  184.    request = AllocAslRequest(ASL_FileRequest, N);
  185.    if(request)
  186.     {
  187.      if(AslRequest(request, &tags[0]))
  188.       {
  189.        strcpy(namebuffer, request->rf_Dir);
  190.        if(    (namebuffer[strlen(namebuffer)-1] !=      ':')
  191.            && (namebuffer[strlen(namebuffer)-1] !=      '/')
  192.            && (namebuffer[0]                    != (char) 0) ) strcat(namebuffer, "/");
  193.  
  194.        strcat(namebuffer, request->rf_File);
  195.  
  196.        if(namebuffer[0] != (char) 0) SimpleView_Show(namebuffer);
  197.       }
  198.  
  199.      FreeAslRequest(request);
  200.     }
  201.   }else
  202.   {
  203.    if(wbloadname) SimpleView_Show(wbloadname);
  204.     else
  205.      {
  206.       /* Show */
  207.  
  208.       if(argv[1][0]!=(char) '-') SimpleView_Show(argv[1]); /* no option given,  */
  209.                                                            /* but PicFileName ! */
  210.  
  211.       if(!stricmp(argv [1],"-s"))  SimpleView_Show(argv[2]);
  212.  
  213.       /* Write */
  214.  
  215.       if(!stricmp(argv [1],"-w"))  SimpleView_Write(argv[2], SV_SUBTYPE_ILBM);
  216.       if(!stricmp(argv [1],"-wp")) SimpleView_Write(argv[2], SV_SUBTYPE_ILBM_01);
  217.       if(!stricmp(argv [1],"-wa")) SimpleView_Write(argv[2], SV_SUBTYPE_ACBM);
  218.  
  219.       /* Convert (Show & Write) */
  220.  
  221.       if(!stricmp(argv [1],"-ci"))  SimpleView_Convert(argv[2], SV_SUBTYPE_ILBM);
  222.       if(!stricmp(argv [1],"-cip")) SimpleView_Convert(argv[2], SV_SUBTYPE_ILBM_01);
  223.       if(!stricmp(argv [1],"-ca"))  SimpleView_Convert(argv[2], SV_SUBTYPE_ACBM);
  224.      }
  225.   }
  226.  
  227.  Leave(N, 0);
  228. }
  229.  
  230. /* *************************************************** */
  231. /* *                             * */
  232. /* * Show-Function                     * */
  233. /* *                             * */
  234. /* *