free web hosting | free hosting | Web Hosting | Free Website Submission | shopping cart | php hosting
 
DocDatatypes Home

DocDatatypes: How to

DocDatatypes Home
How to add text.datatype support to your own programs
Adding datatype support is very easy, you should use the code below as a guide, in your own program you can make it be more professional by telling the user the file type as well which you can find out at the GetDTAttrs() stage. If you have any problems just email me.
This file is included in the DocDatatypes archive.

/*
 * $VER: loaddttext.c 0.1 (01.05.2000)
 *
 * Shows how to load text files using datatypes.library, using the
 * text.datatype class and its sub classes
 *
 * Written by Amarpreet Singh Munde. (docdatatypes@yahoo.com) http://go.to/docdatatypes
 *
 */

/* amiga includes */
#include <exec/types.h>
#include <exec/memory.h>
#include <exec/libraries.h>
#include <dos/dos.h>
#include <datatypes/datatypes.h>
#include <datatypes/datatypesclass.h>
#include <datatypes/textclass.h>

/* amiga prototypes */
#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#include <clib/datatypes_protos.h>

/* ansi includes */
#include <string.h>

/* Library Structures */
extern struct Library *SysBase, *DOSBase;
struct Library *DataTypesBase;

/* Main Prog */
int main( void )
{
 if( (SysBase -> lib_Version) < 39UL )
 {
  Printf( "requires 3.x or beyond to run\n" );
 }
 else
 {
  /* Open the libraries */
  if( DataTypesBase = OpenLibrary("datatypes.library", 39))
  {
   /*
    * filename is the name of the file you want to load
    * size should be whatever you want including path
    */
   char filename[128] = "loaddttext.c";

   /* dto is a pointer to the datatype object */
   Object   *dto;

   /*
    * Here we specify a GroupID of Text so it will only return if
    * it is a text object
    */
   if(dto = NewDTObject(filename, DTA_GroupID, GID_TEXT, TAG_DONE))
   {
    /* len is the size of the text buffer */
    ULONG len;
    /* buffer is the pointer to the actual text */
    STRPTR buffer;

    /*
     * Get the attributes that we need to determine
     * memory needed and where text buffer is
     * You can also get any other attribute you may need
     */
    GetDTAttrs (dto,
     TDTA_Buffer, (ULONG)&buffer,
     TDTA_BufferLen, (ULONG)&len,
     TAG_DONE);

    /* Make sure we have a text buffer */
    if (buffer && len)
    {
     /*
      * here you copy the datatypes buffer to your own buffer
      * because we will free it via DisposeDTObject below
      */
    }
    else
    {
     Printf("Text Object info could not be determined\n");
    }

    /* Dispose of the DataType object */
    DisposeDTObject( dto );
   }
   else
   {
    Printf("Couldn't open object \n");
   }

   CloseLibrary(DataTypesBase);
  }
  else
  {
   /*
    * Couldn't open datatypes.library, Version 39 or higher
    * You should use version 39 since it has all the needed functions, there is no need in using a version above 39
    */
   Printf("Couldn't open datatypes.library V39\n");
  }
 }
}

To allow the support of saving files is a little bit more difficult, if you would like help in how to do this please contact me, it can be done. The first program to support Native File Format Saving via DocDatatypes is SpitFire the Palm Desktop for Amiga.
 
 

Copyright (©)2000-2005 by Amarpreet Singh Munde.