libkate: /home/v/Kate/WORK_TREES/kate-sorceress-backup/v/src/kate/src/kate_high.c Source File

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

- File List

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

    00001 /* Copyright (C) 2008 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 #include "kate/kate.h"
    00017 #include "kate_decode_state.h"
    00018
    00027 int kate_high_decode_init(kate_state *k)
    00028 {
    00029   int ret;
    00030   kate_info *ki;
    00031   kate_comment *kc;
    00032
    00033   if (!k) return KATE_E_INVALID_PARAMETER;
    00034
    00035   k->kes=NULL;
    00036   k->kds=kate_decode_state_create();
    00037   if (!k->kds) return KATE_E_OUT_OF_MEMORY;
    00038
    00039   ki=(kate_info*)kate_malloc(sizeof(kate_info));
    00040   if (!ki) {
    00041     kate_decode_state_destroy(k->kds);
    00042     return KATE_E_OUT_OF_MEMORY;
    00043   }
    00044   kc=(kate_comment*)kate_malloc(sizeof(kate_comment));
    00045   if (!kc) {
    00046     kate_free(ki);
    00047     kate_decode_state_destroy(k->kds);
    00048     return KATE_E_OUT_OF_MEMORY;
    00049   }
    00050
    00051   ret=kate_info_init(ki);
    00052   if (ret<0) {
    00053     kate_free(ki);
    00054     kate_free(kc);
    00055     kate_decode_state_destroy(k->kds);
    00056     return ret;
    00057   }
    00058
    00059   ret=kate_comment_init(kc);
    00060   if (ret<0) {
    00061     kate_free(ki);
    00062     kate_free(kc);
    00063     kate_info_clear(ki);
    00064     kate_decode_state_destroy(k->kds);
    00065     return ret;
    00066   }
    00067
    00068   k->kds->ki=ki;
    00069   k->kds->kc=kc;
    00070
    00071   k->ki=k->kds->ki;
    00072
    00073   return 0;
    00074 }
    00075
    00085 int kate_high_decode_packetin(kate_state *k,kate_packet *kp,kate_const kate_event **ev)
    00086 {
    00087   int ret;
    00088
    00089   if (!k || !kp) return KATE_E_INVALID_PARAMETER;
    00090   if (!k->kds) return KATE_E_INIT;
    00091   if (!k->kds->ki) return KATE_E_INIT;
    00092   if (!k->kds->kc) return KATE_E_INIT;
    00093
    00094   if (ev) *ev=NULL;
    00095   if (k->kds->ki->probe>=0) {
    00096     /* still probing headers */
    00097     ret=kate_decode_headerin(k->kds->ki,k->kds->kc,kp);
    00098     if (ret>0) {
    00099       k->kds->ki->probe=-1;
    00100       ret=0;
    00101     }
    00102     return ret;
    00103   }
    00104   else {
    00105     /* in data */
    00106     int eos=0;
    00107     ret=kate_decode_packetin(k,kp);
    00108     if (ret<0) return ret;
    00109     if (ret>0) eos=1;
    00110     ret=kate_decode_eventout(k,ev);
    00111     if (ret<0) return ret;
    00112     return eos;
    00113   }
    00114 }
    00115
    00123 int kate_high_decode_clear(kate_state *k)
    00124 {
    00125   kate_info *ki;
    00126   kate_comment *kc;
    00127
    00128   if (!k) return KATE_E_INVALID_PARAMETER;
    00129   if (!k->kds) return KATE_E_INIT;
    00130
    00131   /* kate_clear will clear kds, so save what we need first */
    00132   ki=k->kds->ki;
    00133   kc=k->kds->kc;
    00134
    00135   kate_clear(k);
    00136
    00137   kate_free(kc);
    00138   kate_free(ki);
    00139
    00140   return 0;
    00141 }
    00142
    00149 const kate_comment *kate_high_decode_get_comments(kate_state *k)
    00150 {
    00151   if (!k) return NULL;
    00152   if (!k->kds) return NULL;
    00153
    00154   return k->kds->kc;
    00155 }
    00156