home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD2.bin / bbs / gfx / superview-lib-9.12.lha / SuperView-Lib / Programmers / Example_Tools / SimpleView / SimpleView.c < prev    next >
C/C++ Source or Header  |  1994-12-28  |  12KB  |  380 lines

  1. /* ======================================================================== */
  2. /* = Programmname    : SimpleView V7.1                      = */
  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      : 15.7.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 <exec/types.h>
  31. #include <exec/memory.h>
  32.  
  33. #include <intuition/intuitionbase.h> /* accessing IntuitionBase->FirstScreen */
  34.  
  35. #include <superview/superview.h>
  36. #include <superview/superviewbase.h>
  37.  
  38. #include <libraries/asl.h>
  39. #include <workbench/startup.h>
  40.  
  41. #include <proto/exec.h>
  42. #include <proto/dos.h>
  43. #include <proto/asl.h>
  44. #include <proto/superview.h>
  45.  
  46. #include <stdio.h>
  47. #include <stdlib.h>
  48. #include <string.h>
  49.  
  50.  
  51.    /* Help- and Info- Texts */
  52.  
  53. char entry1_text  [] = "\2331;32;40mSimpleView V7.1 \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";
  54. char entry2_text  [] = "Uses superview.library to write, show and convert IFF-ILBM/-ACBM.\n";
  55. char entry3_text  [] = "USAGE : \2330;33;40mSimpleView\2330;31;40m -[w | wp | wa | r | s | ci | cip | ca | ?] <PicFileName>\n";
  56. char entry4_text  [] = "   '-w'   -> Write current screen page to IFF-ILBM-file (unpacked).\n";
  57. char entry5_text  [] = "   '-wp'  -> Write current screen page to IFF-ILBM-file (packed).\n";
  58. char entry6_text  [] = "   '-wa'  -> Write current screen page to IFF-ACBM-file.\n";
  59. char entry7_text  [] = "   '-s'   -> Show an IFF-ILBM-/ACBM-file (optional).\n";
  60. char entry8_text  [] = "   '-ci'  -> Convert IFF-ACBM to IFF-ILBM (unpacked).\n";
  61. char entry9_text  [] = "   '-cip' -> Convert IFF-ACBM to IFF-ILBM (packed).\n";
  62. char entry10_text [] = "   '-ca'  -> Convert IFF-ILBM to IFF-ACBM.\n";
  63. char entry11_text [] = "   '?'    -> This text.\n";
  64.  
  65.  
  66. char ver_text [] = "\0$VER: SimpleView V7.1 (15.7.94)";
  67.  
  68.  
  69. /* *************************************************** */
  70. /* *                             * */
  71. /* * Error-Messages for Leave() and KF_Message()     * */
  72. /* *                             * */
  73. /* *************************************************** */
  74.  
  75. char asllib_text     [] = "You need \42asl.library\42 V37+ !";
  76. char svlib_text     [] = "You need \42superview.library\42 V6+ !";
  77.  
  78.  
  79. /* *************************************************** */
  80. /* *                             * */
  81. /* * Function Declarations                 * */
  82. /* *                             * */
  83. /* *************************************************** */
  84.  
  85. void __regargs SimpleView_Show(char *filename);
  86. void __regargs SimpleView_Write(char *filename, ULONG type);
  87. void __regargs SimpleView_Convert(char *filename, ULONG type);
  88.  
  89.  
  90. void __regargs Leave(char *endtext, long code);
  91.  
  92.  
  93.    /* Functions from module "SimpleView_Subs.o" : */
  94.  
  95. extern void __stdargs K_Printf(char *formatstring, ...);
  96.  
  97.  
  98. /* *************************************************** */
  99. /* *                             * */
  100. /* * Additional Base Declarations             * */
  101. /* *                             * */
  102. /* *************************************************** */
  103.  
  104. extern struct ExecBase *SysBase;
  105.  
  106. struct Library       *AslBase       = N;
  107. struct SuperViewBase *SuperViewBase = N;
  108. struct IntuitionBase *IntuitionBase = N; /* Copied from SuperViewBase.  */
  109.                                          /* Do not close. Only used for */ 
  110.                                          /* accessing FrontScreen       */
  111.  
  112.  
  113. /* *************************************************** */
  114. /* *                             * */
  115. /* * MAIN                         * */
  116. /* *                             * */
  117. /* *************************************************** */
  118.  
  119. extern struct WBStartup *WBenchMsg;
  120. char                *wbloadname = N;
  121. long                     wb         = FALSE;
  122.  
  123. void main(long argc, char **argv)
  124. {
  125.  if(!argc)
  126.   {
  127.    wb = TRUE;
  128.  
  129.    if(WBenchMsg->sm_NumArgs>1) wbloadname = WBenchMsg->sm_ArgList[1].wa_Name;
  130.   }
  131.  
  132.  if( argc > 3 || (argv[1][0] =='?')||(argv[2][0] =='?'))
  133.   {
  134.    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);
  135.  
  136.    Leave(N, 0);
  137.   }
  138.  
  139.  AslBase = (struct Library *) OpenLibrary("asl.library", 37);
  140.  if(!AslBase) Leave(asllib_text, 102);
  141.  
  142.  SuperViewBase = (struct SuperViewBase *) OpenLibrary("superview.library", 6);
  143.  if(!SuperViewBase) Leave(svlib_text, 103);
  144.  
  145.  IntuitionBase = SuperViewBase->svb_IntuitionBase;
  146.  
  147.  /* ^ if NULL, sv-lib wouldn't have opened ! */
  148.  
  149.  
  150.  /* Show */
  151.  
  152.  if(argc < 2 && !wbloadname)
  153.   {
  154.    struct FileRequester     *request;
  155.    struct TagItem __aligned  tags[4];
  156.    char                      namebuffer [256];
  157.  
  158.    namebuffer[0] = (char) 0;
  159.  
  160.    tags[0].ti_Tag  = (Tag)   ASL_Hail;
  161.    tags[0].ti_Data = (ULONG) "Select Picture to Display :";
  162.  
  163.    tags[1].ti_Tag  = (Tag)   ASL_OKText;
  164.    tags[1].ti_Data = (ULONG) " Display ";
  165.  
  166.    tags[2].ti_Tag  = (Tag)   ASL_CancelText;
  167.    tags[2].ti_Data = (ULONG) " Quit ";
  168.  
  169.    tags[3].ti_Tag  = (Tag)   TAG_DONE;
  170.    tags[3].ti_Data = (ULONG) N;
  171.  
  172.    request = AllocAslRequest(ASL_FileRequest, N);
  173.    if(request)
  174.     {
  175.      if(AslRequest(request, &tags[0]))
  176.       {
  177.        strcpy(namebuffer, request->rf_Dir);
  178.        if(    (namebuffer[strlen(namebuffer)-1] !=      ':')
  179.            && (namebuffer[strlen(namebuffer)-1] !=      '/')
  180.            && (namebuffer[0]                    != (char) 0) ) strcat(namebuffer, "/");
  181.  
  182.        strcat(namebuffer, request->rf_File);
  183.  
  184.        if(namebuffer[0] != (char) 0) SimpleView_Show(namebuffer);
  185.       }
  186.  
  187.      FreeAslRequest(request);
  188.     }
  189.   }else
  190.   {
  191.    if(wbloadname) SimpleView_Show(wbloadname);
  192.     else
  193.      {
  194.       /* Show */
  195.  
  196.       if(argv[1][0]!=(char) '-') SimpleView_Show(argv[1]); /* no option given,  */
  197.                                                            /* but PicFileName ! */
  198.  
  199.       if(!stricmp(argv [1],"-s"))  SimpleView_Show(argv[2]);
  200.  
  201.       /* Write */
  202.  
  203.       if(!stricmp(argv [1],"-w"))  SimpleView_Write(argv[2], SV_SUBTYPE_ILBM);
  204.       if(!stricmp(argv [1],"-wp")) SimpleView_Write(argv[2], SV_SUBTYPE_ILBM_01);
  205.       if(!stricmp(argv [1],"-wa")) SimpleView_Write(argv[2], SV_SUBTYPE_ACBM);
  206.  
  207.       /* Convert (Show & Write) */
  208.  
  209.       if(!stricmp(argv [1],"-ci"))  SimpleView_Convert(argv[2], SV_SUBTYPE_ILBM);
  210.       if(!stricmp(argv [1],"-cip")) SimpleView_Convert(argv[2], SV_SUBTYPE_ILBM_01);
  211.       if(!stricmp(argv [1],"-ca"))  SimpleView_Convert(argv[2], SV_SUBTYPE_ACBM);
  212.      }
  213.   }
  214.  
  215.  Leave(N, 0);
  216. }
  217.  
  218. /* *************************************************** */
  219. /* *                             * */
  220. /* * Show-Function                     * */
  221. /* *                             * */
  222. /* *************************************************** */
  223.  
  224. void __regargs SimpleView_Show(char *filename)
  225. {
  226.  APTR handle;
  227.  struct Window *win;
  228.  ULONG retval = SVERR_NO_ERROR;
  229.  
  230.  handle = SVL_AllocHandle(N);
  231.  if(handle)
  232.   {
  233.    if(!(retval = SVL_InitHandleAsDOS(handle, N)))
  234.     {
  235.      if(!(retval = SVL_SetWindowIDCMP(handle, IDCMP_MOUSEBUTTONS, N)))
  236.       {
  237.        if(!(retval = SVL_SetScreen