"Fossies" - the Fresh Open Source Software Archive

Member "ne-3.2.1/src/ext.c.in" (30 Sep 2019, 1537 Bytes) of package /linux/misc/ne-3.2.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "ext.c.in": 3.0.1_vs_3.1.0.

    1 /* Extern's for names and abbreviations of all the commands.
    2 
    3     Copyright (C) 1993-1998 Sebastiano Vigna 
    4     Copyright (C) 1999-2019 Todd M. Lewis and Sebastiano Vigna
    5 
    6     This file is part of ne, the nice editor.
    7 
    8     This library is free software; you can redistribute it and/or modify it
    9     under the terms of the GNU General Public License as published by
   10     the Free Software Foundation; either version 3 of the License, or (at your
   11     option) any later version.
   12 
   13     This library is distributed in the hope that it will be useful, but
   14     WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
   15     or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   16     for more details.
   17 
   18     You should have received a copy of the GNU General Public License
   19     along with this program; if not, see <http://www.gnu.org/licenses/>.  */
   20 
   21 #include "ne.h"
   22 #include "strings.h"
   23 
   24 struct e2s {
   25     const char * ext;
   26     const char * syn;
   27 };
   28 
   29 /* A list of mappings extension -> syntax. MUST be sorted on the first field. */
   30 
   31 static struct e2s const e2s[] = {
   32 <%%EXTMAP%%>
   33 };
   34 
   35 static int extcmp(struct e2s const *a, struct e2s const *b) {
   36     return strcasecmp(a->ext, b->ext);
   37 }
   38 
   39 /* Searches for a mapping matching the given extension in e2s; if found, returns the
   40    resulting syntax. Otherwise, returns ext. */
   41 
   42 const char *ext2syntax(const char * const ext) {
   43     struct e2s key, *t;
   44     key.ext = ext;
   45     key.syn = NULL;
   46     t = bsearch(&key, e2s, sizeof e2s / sizeof *e2s, sizeof *e2s, (int (*)(const void *, const void *))extcmp);
   47     return t ? t->syn : ext;
   48 }