home *** CD-ROM | disk | FTP | other *** search
/ Micro R&D 1 / MicroRD-CD-ROM-Vol1-1994.iso / os30 / cli / wbinfo10.lha / wbinfo / wbinfo.c < prev    next >
C/C++ Source or Header  |  1993-06-19  |  3KB  |  167 lines

  1.  
  2. /*
  3.  *  wbinfo.c
  4.  *
  5.  *  Author: Georg Hessmann (hessmann@informatik.uni-hamburg.de)
  6.  *
  7.  *
  8.  *  Program for 3.x or higher!
  9.  *
  10.  *  Open the workbnch information requester for a given file.
  11.  *
  12.  *  Need SAS/C to compile. Other compilers need small changes.
  13.  *
  14.  *
  15.  *  Copyright: source is public domain, no copyright
  16.  *
  17.  *  Version history:
  18.  *
  19.  *  1.0  20.Jul.93  First release.
  20.  *
  21.  *
  22.  */
  23.  
  24.  
  25. #define VERSION "1.0"
  26.  
  27. static const char version[] = "\0$VER: wbinfo " VERSION " (20.06.93)";
  28.  
  29.  
  30.  
  31. /*
  32.  * Amiga-Includes
  33.  */
  34.  
  35. #include <exec/types.h>
  36. #include <dos/dos.h>
  37. #include <dos/dosasl.h>
  38. #include <workbench/workbench.h>
  39.  
  40. #include <clib/dos_protos.h>
  41. #include <clib/exec_protos.h>
  42. #include <clib/wb_protos.h>
  43. #include <clib/intuition_protos.h>
  44. #include <pragmas/dos_pragmas.h>
  45. #include <pragmas/exec_pragmas.h>
  46. #include <pragmas/wb_pragmas.h>
  47. #include <pragmas/intuition_pragmas.h>
  48.  
  49.  
  50. /*
  51.  * Define SAS/C builtin functions
  52.  */
  53.  
  54. typedef unsigned int size_t;
  55. #define strlen __builtin_strlen
  56. extern int strlen(char *);
  57. extern void   *__builtin_memcpy(void *, const void *, size_t);
  58. #define memcpy(a,b,c) __builtin_memcpy(a,b,c)
  59. extern char *strcpy(char *, const char *);
  60. extern char   *__builtin_strcpy(char *, const char *);
  61. #define strcpy(a,b) __builtin_strcpy(a,b)
  62.  
  63.  
  64.  
  65.  
  66. /*
  67.  * Template for ReadArgs()
  68.  */
  69.  
  70. #define TEMPLATE    "NAME/A,PUBSCREEN/K"
  71.  
  72.  
  73.  
  74.  
  75. /*
  76.  * Main function. Must be the first in the module
  77.  */
  78.  
  79. long __saveds main(void)
  80. {
  81.   long rc = RETURN_OK;
  82.  
  83.   struct Library       * DOSBase;
  84.   struct Library       * WorkbenchBase;
  85.   struct Library       * IntuitionBase;
  86.  
  87.   long            options[2];
  88.   struct RDArgs * args;
  89.  
  90.   char PubName[MAXPUBSCREENNAME+1];
  91.  
  92.   DOSBase = OpenLibrary("dos.library", 36);    // need at least 36 for PutStr()
  93.   
  94.   if (DOSBase && DOSBase->lib_Version < 39) {
  95.     PutStr("Need system version 39.x or higher!\n");
  96.     CloseLibrary(DOSBase);
  97.     return RETURN_FAIL;
  98.   }
  99.  
  100.   WorkbenchBase = OpenLibrary("workbench.library", 39);
  101.   IntuitionBase = OpenLibrary("intuition.library", 39);
  102.   if (!(WorkbenchBase && IntuitionBase)) return RETURN_FAIL;
  103.  
  104.   options[0] = options[1] = 0L;
  105.   args = ReadArgs(TEMPLATE, options, NULL);
  106.  
  107.   if (args) {
  108.     char * file    = (char *)options[0];
  109.     char * pubname = (char *)options[1];
  110.     
  111.     if (pubname) {
  112.       if (strlen(pubname) >= sizeof(PubName)) {        // test max length
  113.         PrintFault(ERROR_BUFFER_OVERFLOW, pubname);
  114.         rc = RETURN_FAIL;
  115.       }
  116.       else {
  117.         strcpy(PubName, pubname);
  118.       }
  119.     }
  120.     else {
  121.       GetDefaultPubScreen(PubName);
  122.     }
  123.  
  124.     if (rc == RETURN_OK) {
  125.       struct Screen * screen = LockPubScreen(PubName);
  126.         
  127.       if (screen) {
  128.         BPTR lock = Lock(file, ACCESS_READ);
  129.  
  130.         if (lock) {
  131.           BPTR par;
  132.           par = ParentDir(lock);
  133.           if (!par) par = DupLock(lock);    // for Devices
  134.           
  135.           if (!WBInfo(par, file, screen)) rc = RETURN_WARN;
  136.           if (par) UnLock(par);
  137.  
  138.           UnLock(lock);
  139.         }
  140.         else {
  141.           PrintFault(IoErr(), file);
  142.           rc = RETURN_ERROR;
  143.         }
  144.      
  145.         UnlockPubScreen(NULL, screen);
  146.       }
  147.       else {    // error message for 'pubscreen not found' ... ??
  148.         PrintFault(ERROR_OBJECT_NOT_FOUND, pubname);
  149.         rc = RETURN_FAIL;
  150.       }
  151.     }
  152.     
  153.     FreeArgs(args);
  154.   }
  155.   else {
  156.     PrintFault(IoErr(), NULL);
  157.     rc = RETURN_ERROR;
  158.   }
  159.   
  160.   CloseLibrary(WorkbenchBase);
  161.   CloseLibrary(IntuitionBase);
  162.   CloseLibrary(DOSBase);
  163.  
  164.   return rc;
  165. }
  166.  
  167.