| 1 |
/* Copyright (C) 2008, 2009 Vincent Penquerc'h. |
| 2 |
This file is part of the Kate codec library. |
| 3 |
Written by Vincent Penquerc'h. |
| 4 |
|
| 5 |
Use, distribution and reproduction of this library is governed |
| 6 |
by a BSD style source license included with this source in the |
| 7 |
file 'COPYING'. Please read these terms before distributing. */ |
| 8 |
|
| 9 |
|
| 10 |
#ifndef KATE_kate_internal_h_GUARD |
| 11 |
#define KATE_kate_internal_h_GUARD |
| 12 |
|
| 13 |
#define KATE_LIMIT_COMMENTS 4096 |
| 14 |
#define KATE_LIMIT_COMMENT_LENGTH 4096 |
| 15 |
#define KATE_LIMIT_REGIONS 4096 |
| 16 |
#define KATE_LIMIT_STYLES 4096 |
| 17 |
#define KATE_LIMIT_CURVE_POINTS 4096 |
| 18 |
#define KATE_LIMIT_CURVES 4096 |
| 19 |
#define KATE_LIMIT_MOTION_CURVES 4096 |
| 20 |
#define KATE_LIMIT_MOTIONS 4096 |
| 21 |
#define KATE_LIMIT_PALETTES 4096 |
| 22 |
#define KATE_LIMIT_BITMAPS 4096 |
| 23 |
#define KATE_LIMIT_BITMAP_SIZE 4096 |
| 24 |
#define KATE_LIMIT_BITMAP_RAW_SIZE 4194304 |
| 25 |
#define KATE_LIMIT_FONT_RANGES 4096 |
| 26 |
#define KATE_LIMIT_FONT_MAPPINGS 4096 |
| 27 |
#define KATE_LIMIT_FONT_MAPPING_RANGES 4096 |
| 28 |
#define KATE_LIMIT_TEXT_MOTIONS 4096 |
| 29 |
#define KATE_LIMIT_LANGUAGE_LENGTH 1024 |
| 30 |
#define KATE_LIMIT_TEXT_LENGTH 1048576 |
| 31 |
|
| 32 |
#include "config.h" |
| 33 |
|
| 34 |
#include "kate/kate.h" |
| 35 |
|
| 36 |
#if !defined __GNUC__ || (((__GNUC__*0x100)+(__GNUC_MINOR__+0))<0x0303) |
| 37 |
#define __attribute__(x) |
| 38 |
#endif |
| 39 |
|
| 40 |
#ifdef __ELF__ |
| 41 |
#define kate_internal __attribute__((visibility("internal"))) |
| 42 |
#else |
| 43 |
#define kate_internal |
| 44 |
#endif |
| 45 |
|
| 46 |
/* from http://www.fefe.de/intof.html */ |
| 47 |
#define KATE_TYPE_HALF_MAX_SIGNED(type) ((type)1 << (sizeof(type)*8-2)) |
| 48 |
#define KATE_TYPE_MAX_SIGNED(type) (KATE_TYPE_HALF_MAX_SIGNED(type) - 1 + KATE_TYPE_HALF_MAX_SIGNED(type)) |
| 49 |
#define KATE_TYPE_MIN_SIGNED(type) (-1 - KATE_TYPE_MAX_SIGNED(type)) |
| 50 |
#define KATE_TYPE_MIN(type) ((type)-1 < 1?KATE_TYPE_MIN_SIGNED(type):(type)0) |
| 51 |
#define KATE_TYPE_MAX(type) ((type)~KATE_TYPE_MIN(type)) |
| 52 |
|
| 53 |
static inline int kate_check_add_overflow(size_t x,size_t y,size_t *res) __attribute__((pure)); |
| 54 |
static inline int kate_check_add_overflow(size_t x,size_t y,size_t *res) |
| 55 |
{ |
| 56 |
if (KATE_TYPE_MAX(size_t)-(y)>=x) { |
| 57 |
if (res) *res=x+y; |
| 58 |
return 0; |
| 59 |
} |
| 60 |
return KATE_E_LIMIT; |
| 61 |
} |
| 62 |
|
| 63 |
static inline int kate_check_mul_overflow_generic(size_t x,size_t y,size_t *res) __attribute__((pure)); |
| 64 |
static inline int kate_check_mul_overflow_generic(size_t x,size_t y,size_t *res) |
| 65 |
{ |
| 66 |
kate_uint64_t r,mask; |
| 67 |
if ((x&y)>>(sizeof(size_t)*4)) return KATE_E_LIMIT; |
| 68 |
mask=KATE_TYPE_MAX(size_t)>>(sizeof(size_t)*4); |
| 69 |
r=(x>>(sizeof(size_t)*4))*(y&mask)+(y>>(sizeof(size_t)*4))*(x&mask); |
| 70 |
if (r>>(sizeof(size_t)*4)) return KATE_E_LIMIT; |
| 71 |
r<<=(sizeof(size_t)*4); |
| 72 |
return kate_check_add_overflow(r,(x&mask)*(y&mask),res); |
| 73 |
} |
| 74 |
|
| 75 |
static inline int kate_check_mul_overflow(size_t x,size_t y,size_t *res) __attribute__((pure)); |
| 76 |
static inline int kate_check_mul_overflow(size_t x,size_t y,size_t *res) |
| 77 |
{ |
| 78 |
if (sizeof(size_t)>4) { |
| 79 |
return kate_check_mul_overflow_generic(x,y,res); |
| 80 |
} |
| 81 |
else { |
| 82 |
kate_uint64_t r=((kate_uint64_t)x)*y; |
| 83 |
if ((r>>(sizeof(size_t)*4))>>(sizeof(size_t)*4)) return KATE_E_LIMIT; |
| 84 |
if (res) *res=(size_t)r; |
| 85 |
return 0; |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
/* granule operations */ |
| 90 |
extern kate_int64_t kate_time_granule(const kate_info *ki,kate_float base,kate_float offset) kate_internal; |
| 91 |
|
| 92 |
/* motions */ |
| 93 |
extern int kate_motion_destroy(const kate_info *ki,kate_motion **motions,const int *destroy,size_t nmotions,int force) kate_internal; |
| 94 |
|
| 95 |
/* event tracking */ |
| 96 |
extern kate_event *kate_event_create(const kate_info *ki) kate_internal; |
| 97 |
extern int kate_event_track(kate_event *ev) kate_internal; |
| 98 |
extern int kate_event_release(kate_event *ev) kate_internal; |
| 99 |
extern int kate_event_destroy(kate_event *ev) kate_internal; |
| 100 |
|
| 101 |
/* checks for header references */ |
| 102 |
extern int kate_find_region(const kate_info *ki,const kate_region *kr); |
| 103 |
extern int kate_find_style(const kate_info *ki,const kate_style *ks); |
| 104 |
extern int kate_find_curve(const kate_info *ki,const kate_curve *kc); |
| 105 |
extern int kate_find_motion(const kate_info *ki,const kate_motion *km); |
| 106 |
extern int kate_find_palette(const kate_info *ki,const kate_palette *kp); |
| 107 |
extern int kate_find_bitmap(const kate_info *ki,const kate_bitmap *kb); |
| 108 |
extern int kate_find_font_range(const kate_info *ki,const kate_font_range *kfr); |
| 109 |
extern int kate_find_font_mapping(const kate_info *ki,const kate_font_mapping *kfm); |
| 110 |
|
| 111 |
/* utility */ |
| 112 |
extern int kate_ascii_strncasecmp(const char *s0,const char *s1,size_t n) kate_internal __attribute__((pure)); |
| 113 |
extern int kate_ascii_strcasecmp(const char *s0,const char *s1) kate_internal __attribute__((pure)); |
| 114 |
|
| 115 |
extern int kate_is_valid_code_point(int c) kate_internal __attribute__((const)); |
| 116 |
|
| 117 |
extern int kate_font_check_ranges(const kate_font_mapping *kfm); |
| 118 |
|
| 119 |
extern void *kate_checked_malloc(size_t n,size_t sz) kate_internal __attribute__((malloc)); |
| 120 |
extern void *kate_checked_realloc(void *ptr,size_t n,size_t sz) kate_internal; |
| 121 |
|
| 122 |
#endif |
| 123 |
|