extensions/spellcheck/hunspell/src/filemgr.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/extensions/spellcheck/hunspell/src/filemgr.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,80 @@
     1.4 +/******* BEGIN LICENSE BLOCK *******
     1.5 + * Version: MPL 1.1/GPL 2.0/LGPL 2.1
     1.6 + * 
     1.7 + * The contents of this file are subject to the Mozilla Public License Version
     1.8 + * 1.1 (the "License"); you may not use this file except in compliance with
     1.9 + * the License. You may obtain a copy of the License at
    1.10 + * http://www.mozilla.org/MPL/
    1.11 + * 
    1.12 + * Software distributed under the License is distributed on an "AS IS" basis,
    1.13 + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
    1.14 + * for the specific language governing rights and limitations under the
    1.15 + * License.
    1.16 + * 
    1.17 + * The Initial Developers of the Original Code are Kevin Hendricks (MySpell)
    1.18 + * and László Németh (Hunspell). Portions created by the Initial Developers
    1.19 + * are Copyright (C) 2002-2005 the Initial Developers. All Rights Reserved.
    1.20 + * 
    1.21 + * Contributor(s): László Németh (nemethl@gyorsposta.hu)
    1.22 + *                 Caolan McNamara (caolanm@redhat.com)
    1.23 + * 
    1.24 + * Alternatively, the contents of this file may be used under the terms of
    1.25 + * either the GNU General Public License Version 2 or later (the "GPL"), or
    1.26 + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
    1.27 + * in which case the provisions of the GPL or the LGPL are applicable instead
    1.28 + * of those above. If you wish to allow use of your version of this file only
    1.29 + * under the terms of either the GPL or the LGPL, and not to allow others to
    1.30 + * use your version of this file under the terms of the MPL, indicate your
    1.31 + * decision by deleting the provisions above and replace them with the notice
    1.32 + * and other provisions required by the GPL or the LGPL. If you do not delete
    1.33 + * the provisions above, a recipient may use your version of this file under
    1.34 + * the terms of any one of the MPL, the GPL or the LGPL.
    1.35 + *
    1.36 + ******* END LICENSE BLOCK *******/
    1.37 +
    1.38 +#include <stdlib.h>
    1.39 +#include <string.h>
    1.40 +#include <stdio.h>
    1.41 +
    1.42 +#include "filemgr.hxx"
    1.43 +
    1.44 +int FileMgr::fail(const char * err, const char * par) {
    1.45 +    fprintf(stderr, err, par);
    1.46 +    return -1;
    1.47 +}
    1.48 +
    1.49 +FileMgr::FileMgr(const char * file, const char * key) {
    1.50 +    linenum = 0;
    1.51 +    hin = NULL;
    1.52 +    fin = fopen(file, "r");
    1.53 +    if (!fin) {
    1.54 +        // check hzipped file
    1.55 +        char * st = (char *) malloc(strlen(file) + strlen(HZIP_EXTENSION) + 1);
    1.56 +        if (st) {
    1.57 +            strcpy(st, file);
    1.58 +            strcat(st, HZIP_EXTENSION);
    1.59 +            hin = new Hunzip(st, key);
    1.60 +            free(st);
    1.61 +        }
    1.62 +    }    
    1.63 +    if (!fin && !hin) fail(MSG_OPEN, file);
    1.64 +}
    1.65 +
    1.66 +FileMgr::~FileMgr()
    1.67 +{
    1.68 +    if (fin) fclose(fin);
    1.69 +    if (hin) delete hin;
    1.70 +}
    1.71 +
    1.72 +char * FileMgr::getline() {
    1.73 +    const char * l;
    1.74 +    linenum++;
    1.75 +    if (fin) return fgets(in, BUFSIZE - 1, fin);
    1.76 +    if (hin && (l = hin->getline())) return strcpy(in, l);
    1.77 +    linenum--;
    1.78 +    return NULL;
    1.79 +}
    1.80 +
    1.81 +int FileMgr::getlinenum() {
    1.82 +    return linenum;
    1.83 +}

mercurial