home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / GFX / viewer / SVLIBS81.LHA / superview-lib / Programmers / Example_Tools / SimpleView / SimpleView.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-13  |  11.5 KB  |  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_SetScreenType(handle, CUSTOMSCREEN, N)))
  238.         {
  239.          if(!(retval = SVL_SuperView(handle, filename)))
  240.           {
  241.            if(!(retval = SVL_GetWindowAddress(handle, &win, N)))
  242.             {
  243.              if(win)
  244.               {
  245.                WaitPort(win->UserPort);
  246.               }
  247.             }
  248.           }
  249.         }
  250.       }
  251.     }
  252.    
  253.    SVL_FreeHandle(handle);
  254.  
  255.   }else retval = SVERR_NO_HANDLE;
  256.  
  257.  if(retval) Leave(SVL_GetErrorString(retval), 0);
  258. }
  259.  
  260. /* *************************************************** */
  261. /* *                             * */
  262. /* * Write-Function                     * */
  263. /* *                             * */
  264. /* *************************************************** */
  265.  
  266. void __regargs SimpleView_Write(char *filename, ULONG type)
  267. {
  268.  APTR handle;
  269.  ULONG retval = SVERR_NO_ERROR;
  270.  
  271.  handle = SVL_AllocHandle(N);
  272.  if(handle)
  273.   {
  274.    if(!(retval = SVL_InitHandleAsDOS(handle, N)))
  275.     {
  276.      if(!(retval = SVL_SetWriteType(handle, type, N)))
  277.       {
  278.        if(!(retval = SVL_SetWriteName(handle, filename, N)))
  279.         {
  280.          if(!(retval = SVL_SetWriteScreen(handle, IntuitionBase->FirstScreen, N)))
  281.           {
  282.            retval = SVL_SuperWrite(handle);
  283.           }
  284.         }
  285.       }
  286.     }
  287.    
  288.    SVL_FreeHandle(handle);
  289.  
  290.   }else retval = SVERR_NO_HANDLE;
  291.  
  292.  if(retval) Leave(SVL_GetErrorString(retval), 0);
  293. }
  294.  
  295. /* *************************************************** */
  296. /* *                             * */
  297. /* * Convert-Function                     * */
  298. /* *                             * */
  299. /* *************************************************** */
  300.  
  301. void __regargs SimpleView_Convert(char *filename, ULONG type)
  302. {
  303.  APTR handleS, handleD;
  304.  
  305.  struct Screen       *sc        = N;
  306.  struct SV_GfxBuffer *gfxbuffer = N;
  307.  
  308.  ULONG retval = SVERR_NO_ERROR;
  309.  char newfilename [256];
  310.  
  311.  
  312.  handleS = SVL_AllocHandle(N);
  313.  if(handleS)
  314.   {
  315.    if(!(retval = SVL_InitHandleAsDOS(handleS, N)))
  316.     {
  317.      if(!(retval = SVL_ReadToGfxBuffer(handleS, filename))) retval = SVL_GetGfxBuffer(handleS, &gfxbuffer, N);
  318.  
  319.      if(!gfxbuffer)
  320.       {
  321.        if(!(retval = SVL_SetWindowIDCMP(handleS, IDCMP_MOUSEBUTTONS, N)))
  322.         {
  323.          if(!(retval = SVL_SetScreenType(handleS, CUSTOMSCREEN, N)))
  324.           {
  325.            if(!(retval = SVL_SuperView(handleS, filename))) retval = SVL_GetScreenAddress(handleS, &sc, N);
  326.           }
  327.         }
  328.       }
  329.  
  330.      if(!retval)
  331.       {
  332.        handleD = SVL_AllocHandle(N);
  333.        if(handleD)
  334.         {
  335.          if(!(retval = SVL_InitHandleAsDOS(handleD, N)))
  336.           {
  337.            strcpy(newfilename, filename);
  338.            strcat(newfilename, ".conv");
  339.  
  340.            if(!(retval = SVL_SetWriteName(handleD, newfilename, N)))
  341.             {
  342.              if(!(retval = SVL_SetWriteType(handleD, type, N)))
  343.               {
  344.                if(sc)        retval = SVL_SetWriteScreen(handleD, sc,        N);
  345.                if(gfxbuffer) retval = SVL_SetGfxBuffer(  handleD, gfxbuffer, N);
  346.  
  347.                if(!retval) retval = SVL_SuperWrite(handleD);
  348.               }
  349.             }
  350.           }
  351.  
  352.          SVL_FreeHandle(handleD);
  353.         }
  354.       }
  355.     }
  356.    
  357.    SVL_FreeHandle(handleS);
  358.  
  359.   }else retval = SVERR_NO_HANDLE;
  360.  
  361.  if(retval) Leave(SVL_GetErrorString(retval), 0);
  362. }
  363.  
  364.  
  365. /* *************************************************** */
  366. /* *                             * */
  367. /* * LEAVE : Global Exit Function Replacement         * */
  368. /* *                             * */
  369. /* *************************************************** */
  370.  
  371. void __regargs Leave(char *endtext, long code)
  372. {
  373.  if(SuperViewBase) CloseLibrary((APTR) SuperViewBase);
  374.  if(AslBase)       CloseLibrary((APTR) AslBase);
  375.  
  376.  if(endtext)       if(!wb) K_Printf("%s\n", endtext);
  377.  
  378.  exit(code);
  379. }
  380.