- Main Page
- Related Pages
- Data Structures
- Files
- Examples

- File List

# /home/v/Kate/WORK_TREES/kate-sorceress-backup/v/src/kate/src/kate.c

    00001 /* Copyright (C) 2008, 2009 Vincent Penquerc'h.
    00002    This file is part of the Kate codec library.
    00003    Written by Vincent Penquerc'h.
    00004
    00005    Use, distribution and reproduction of this library is governed
    00006    by a BSD style source license included with this source in the
    00007    file 'COPYING'. Please read these terms before distributing. */
    00008
    00009
    00010 #define KATE_INTERNAL
    00011 #include "kate_internal.h"
    00012
    00013 #ifdef HAVE_STDLIB_H
    00014 #include <stdlib.h>
    00015 #endif
    00016 #ifdef HAVE_STRING_H
    00017 #include <string.h>
    00018 #endif
    00019 #include "kate/kate.h"
    00020 #include "kate_decode_state.h"
    00021 #include "kate_encode_state.h"
    00022
    00023 #define MKVER1(x) #x
    00024 #define MKVER2(x,y) MKVER1(x) "." MKVER1(y)
    00025 #define MKVER3(x,y,z) MKVER1(x)"."MKVER1(y)"."MKVER1(z)
    00026
    00032 int kate_get_version(void)
    00033 {
    00034   return (KATE_VERSION_MAJOR<<16)|(KATE_VERSION_MINOR<<8)|KATE_VERSION_PATCH;
    00035 }
    00036
    00042 const char *kate_get_version_string(void)
    00043 {
    00044   return "libkate " MKVER3(KATE_VERSION_MAJOR,KATE_VERSION_MINOR,KATE_VERSION_PATCH) " (Tiger)";
    00045 }
    00046
    00052 int kate_get_bitstream_version(void)
    00053 {
    00054   return (KATE_BITSTREAM_VERSION_MAJOR<<8)|(KATE_BITSTREAM_VERSION_MINOR);
    00055 }
    00056
    00062 const char *kate_get_bitstream_version_string(void)
    00063 {
    00064   return "kate bitstream " MKVER2(KATE_BITSTREAM_VERSION_MAJOR,KATE_BITSTREAM_VERSION_MINOR);
    00065 }
    00066
    00074 int kate_clear(kate_state *k)
    00075 {
    00076   if (!k) return KATE_E_INVALID_PARAMETER;
    00077
    00078   if (k->kds) {
    00079     kate_decode_state_destroy(k->kds);
    00080     k->kds=NULL;
    00081   }
    00082   if (k->kes) {
    00083     kate_encode_state_destroy(k->kes);
    00084     k->kes=NULL;
    00085   }
    00086
    00087   return 0;
    00088 }
    00089
    00090 static inline int kate_ascii_tolower(int c) __attribute__((const));
    00091 static inline int kate_ascii_tolower(int c)
    00092 {
    00093   if (c>='A' && c<='Z') return c|32;
    00094   return c;
    00095 }
    00096
    00097 int kate_ascii_strncasecmp(const char *s0,const char *s1,size_t n)
    00098 {
    00099   while (n--) {
    00100     int c0=kate_ascii_tolower(*s0++);
    00101     int c1=kate_ascii_tolower(*s1++);
    00102     if (c0!=c1) return c0-c1;
    00103     if (!c0) return 0;
    00104   }
    00105   return 0;
    00106 }
    00107
    00115 int kate_region_init(kate_region *kr)
    00116 {
    00117   static const kate_region default_region={
    00118     kate_percentage,
    00119     10,80,80,10,
    00120     -1,
    00121     0,
    00122     0,
    00123     {0,0,0,0,0,0}
    00124   };
    00125
    00126   if (!kr) return KATE_E_INVALID_PARAMETER;
    00127   memcpy(kr,&default_region,sizeof(kate_region));
    00128   return 0;
    00129 }
    00130
    00138 int kate_style_init(kate_style *ks)
    00139 {
    00140   static const kate_style default_style={
    00141     0,0,
    00142     {255,255,255,255},
    00143     {0,0,0,0},
    00144     {255,255,255,255},
    00145     kate_pixel,
    00146     -1,-1,
    00147     kate_pixel,
    00148     0,0,0,0,
    00149     0,
    00150     0,
    00151     0,
    00152     0,
    00153     0,
    00154     kate_wrap_word,
    00155     0,
    00156     NULL,
    00157     {0,0,0,0,0,0,0,0,0}
    00158   };
    00159
    00160   if (!ks) return KATE_E_INVALID_PARAMETER;
    00161   memcpy(ks,&default_style,sizeof(kate_style));
    00162   return 0;
    00163 }
    00164
    00172 int kate_palette_init(kate_palette *kp)
    00173 {
    00174   static const kate_palette default_palette={
    00175     0,
    00176     NULL,
    00177     {0,0}
    00178   };
    00179
    00180   if (!kp) return KATE_E_INVALID_PARAMETER;
    00181   memcpy(kp,&default_palette,sizeof(kate_palette));
    00182   return 0;
    00183 }
    00184
    00192 int kate_bitmap_init(kate_bitmap *kb)
    00193 {
    00194   static const kate_bitmap default_bitmap={
    00195     0,0,
    00196     0,
    00197     kate_bitmap_type_png,
    00198     {0,0},
    00199     -1,
    00200     NULL,
    00201     0,
    00202     0,0
    00203   };
    00204
    00205   if (!kb) return KATE_E_INVALID_PARAMETER;
    00206   memcpy(kb,&default_bitmap,sizeof(kate_bitmap));
    00207   return 0;
    00208 }
    00209
    00217 int kate_curve_init(kate_curve *kc)
    00218 {
    00219   static const kate_curve default_curve={
    00220     kate_curve_none,
    00221     0,
    00222     NULL,
    00223     {0,0,0,0,0}
    00224   };
    00225
    00226   if (!kc) return KATE_E_INVALID_PARAMETER;
    00227   memcpy(kc,&default_curve,sizeof(kate_curve));
    00228   return 0;
    00229 }
    00230
    00238 int kate_motion_init(kate_motion *km)
    00239 {
    00240   static const kate_motion default_motion={
    00241     0,
    00242     NULL,
    00243     NULL,
    00244     kate_motion_mapping_none,
    00245     kate_motion_mapping_none,
    00246     kate_motion_semantics_time,
    00247     0,
    00248     0,
    00249     {0,0,0,0,0}
    00250   };
    00251
    00252   if (!km) return KATE_E_INVALID_PARAMETER;
    00253   memcpy(km,&default_motion,sizeof(kate_motion));
    00254   return 0;
    00255 }
    00256
    00257 void *kate_checked_malloc(size_t n,size_t sz)
    00258 {
    00259   size_t mul;
    00260   if (kate_check_mul_overflow(n,sz,&mul)) return NULL;
    00261   return kate_malloc(mul);
    00262 }
    00263
    00264 void *kate_checked_realloc(void *ptr,size_t n,size_t sz)
    00265 {
    00266   size_t mul;
    00267   if (kate_check_mul_overflow(n,sz,&mul)) return NULL;
    00268   return kate_realloc(ptr,mul);
    00269 }
    00270