Logo Search packages:      
Sourcecode: cbmconvert version File versions  Download package

util.h

Go to the documentation of this file.
/**
 * @file util.h
 * Definitions of data types and utility functions
 * @author Marko Mäkelä (marko.makela@nic.funet.fi)
 */

/*
** Copyright © 1993-1997,2001 Marko Mäkelä
**
**     This program is free software; you can redistribute it and/or modify
**     it under the terms of the GNU General Public License as published by
**     the Free Software Foundation; either version 2 of the License, or
**     (at your option) any later version.
**
**     This program is distributed in the hope that it will be useful,
**     but WITHOUT ANY WARRANTY; without even the implied warranty of
**     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
**     GNU General Public License for more details.
**
**     You should have received a copy of the GNU General Public License
**     along with this program; if not, write to the Free Software
**     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#ifndef UTIL_H
#  define UTIL_H

/**
 * Rounded integer division
 * @param a the numerator
 * @param b the denominator
 * @return  a divided by b, rounded up to the next integer value
 */
00034 #  define rounddiv(a,b) ((a + b - 1) / b)
/**
 * Determine the number of elements in an array
 * @param a an array
 * @return  number of elements in the array
 */
00040 #  define elementsof(a) ((sizeof a) / (sizeof *a))

#  if defined(__MSDOS__) || defined(MSDOS)
/** Directory path separator character */
#    define PATH_SEPARATOR '\\'
#  else
/** Directory path separator character */
00047 #    define PATH_SEPARATOR '/'
#  endif

#  include <limits.h>

/* Common data types */

#  if UCHAR_MAX != 255
#    error "Wrong unsigned char range!"
#  endif
/** A data type of exactly one byte */
00058 typedef unsigned char byte_t;
#  if UINT_MAX < 65535
#    error "Insufficient unsigned int range!"
#  endif
/** An unsigned data type with at least 16 bits of precision */
00063 typedef unsigned int word_t;
#  if UINT_MAX >= 16777216
/** An unsigned data type with at least 24 bits of precision */
typedef unsigned int tbyte_t;
#  else
#    if ULONG_MAX < 16777216
#      error "Insufficient unsigned long range!"
#    endif
/** An unsigned data type with at least 24 bits of precision */
00072 typedef unsigned long int tbyte_t;
#  endif

/** Truth value */
00076 typedef enum
{
00078   false = 0,      /**< false, binary digit '0' */
00079   true            /**< true, binary digit '1' */
} bool;

/** Commodore file types */
00083 enum Filetype
{
00085   DEL = 0x80,     /**< Deleted (sequential) file */
00086   SEQ,            /**< Sequential data file */
00087   PRG,            /**< Sequential program file */
00088   USR,            /**< Sequential data file with user-defined structure */
00089   REL,            /**< Random-access data file */
00090   CBM       /**< 1581 partition */
};

/** Commodore file name */
00094 struct Filename
{
  /** The file name, padded with shifted spaces */
00097   unsigned char name[16];
  /** The file type */
00099   enum Filetype type;
  /** Record length for random-access (relative) files */
00101   byte_t recordLength;
};

/** Disk image types */
00105 enum ImageType
{
00107   ImUnknown,      /**< Unknown or unrecognized image */
00108   Im1541,   /**< 35-track 1541, 3040 or 4040 disk image */
00109   Im1571,   /**< 70-track 1571 disk image */
00110   Im1581    /**< 80-track 1581 disk image */
};

/** Options for getDirEnt () */
00114 enum DirEntOpts
{
00116   DirEntDontCreate, /**< only try to find the file name */
00117   DirEntOnlyCreate, /**< only create a new slot */
00118   DirEntFindOrCreate/**< create the directory entry if it doesn't exist */
};

/** Disk image */
00122 struct Image
{
  /** type of disk image */
00125   enum ImageType type;
  /** getDirEnt() behaviour */
00127   enum DirEntOpts direntOpts;
  /** (active) directory track number */
00129   byte_t dirtrack;
  /** disk image file name on the host system */
00131   unsigned char* name;
  /** disk image data */
00133   byte_t* buf;
  /** lower limits of partitions (for the 1581) */
00135   byte_t partBots[80];
  /** upper limits of partitions (for the 1581) */
00137   byte_t partTops[80];
  /** parent partitions (for the 1581) */
00139   byte_t partUpper[80];
};

/** An entry in a file archive */
00143 struct ArchiveEntry
{
  /** Pointer to next archive entry */
00146   struct ArchiveEntry* next;
  /** The file name of the entry */
00148   struct Filename name;
  /** Length of the entry in bytes */
00150   size_t length;
  /** The contents of the entry */
00152   byte_t* data;
};

/** A file archive */
00156 struct Archive
{
  /** The first archive entry */
00159   struct ArchiveEntry* first;
  /** The last archive entry */
00161   struct ArchiveEntry* last;
};

/* Utility functions */

/** Convert a file name to a printable null-terminated string.
 * @param name    the PETSCII file name to be converted
 * @return  the corresponding ASCII file name
 */
const char*
getFilename (const struct Filename* name);

/** Verbosity level of diagnostic output */
00174 enum Verbosity
{
00176   Errors,   /**< Display only errors; report an error */
00177   Warnings, /**< Display errors and warnings; report a warning */
00178   Everything      /**< Display everything; report an informational message */
};

/** Call-back function for diagnostic output
 * @param verbosity     the verbosity level
 * @param name          the file name associated with the message (or NULL)
 * @param format  printf-like format string followed by arguments
 */
00186 typedef void log_t (enum Verbosity verbosity,
                const struct Filename* name,
                const char* format, ...);

#endif /* UTIL_H */

Generated by  Doxygen 1.6.0   Back to index