[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemacs-commit] qemacs bufed.c buffer.c clang.c dired.c docbook...
From: |
Charlie Gordon |
Subject: |
[Qemacs-commit] qemacs bufed.c buffer.c clang.c dired.c docbook... |
Date: |
Sat, 04 Jan 2014 17:28:38 +0000 |
CVSROOT: /sources/qemacs
Module name: qemacs
Changes by: Charlie Gordon <chqrlie> 14/01/04 17:28:38
Modified files:
. : bufed.c buffer.c clang.c dired.c docbook.c
hex.c html.c htmlsrc.c image.c latex-mode.c
lisp.c makemode.c mpeg.c perl.c qe.c qe.h
script.c variables.c video.c xml.c
Log message:
improve mode selection, cleanup
* pass ModeDef pointer to mode_probe functions
* add extensions field to mode structure
* rename ascii mode to binary mode
* rename mode variables and fields to more specific names
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/bufed.c?cvsroot=qemacs&r1=1.22&r2=1.23
http://cvs.savannah.gnu.org/viewcvs/qemacs/buffer.c?cvsroot=qemacs&r1=1.48&r2=1.49
http://cvs.savannah.gnu.org/viewcvs/qemacs/clang.c?cvsroot=qemacs&r1=1.40&r2=1.41
http://cvs.savannah.gnu.org/viewcvs/qemacs/dired.c?cvsroot=qemacs&r1=1.31&r2=1.32
http://cvs.savannah.gnu.org/viewcvs/qemacs/docbook.c?cvsroot=qemacs&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/qemacs/hex.c?cvsroot=qemacs&r1=1.29&r2=1.30
http://cvs.savannah.gnu.org/viewcvs/qemacs/html.c?cvsroot=qemacs&r1=1.21&r2=1.22
http://cvs.savannah.gnu.org/viewcvs/qemacs/htmlsrc.c?cvsroot=qemacs&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/qemacs/image.c?cvsroot=qemacs&r1=1.22&r2=1.23
http://cvs.savannah.gnu.org/viewcvs/qemacs/latex-mode.c?cvsroot=qemacs&r1=1.33&r2=1.34
http://cvs.savannah.gnu.org/viewcvs/qemacs/lisp.c?cvsroot=qemacs&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/qemacs/makemode.c?cvsroot=qemacs&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/qemacs/mpeg.c?cvsroot=qemacs&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/qemacs/perl.c?cvsroot=qemacs&r1=1.8&r2=1.9
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.c?cvsroot=qemacs&r1=1.106&r2=1.107
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.h?cvsroot=qemacs&r1=1.105&r2=1.106
http://cvs.savannah.gnu.org/viewcvs/qemacs/script.c?cvsroot=qemacs&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/qemacs/variables.c?cvsroot=qemacs&r1=1.9&r2=1.10
http://cvs.savannah.gnu.org/viewcvs/qemacs/video.c?cvsroot=qemacs&r1=1.14&r2=1.15
http://cvs.savannah.gnu.org/viewcvs/qemacs/xml.c?cvsroot=qemacs&r1=1.11&r2=1.12
Patches:
Index: bufed.c
===================================================================
RCS file: /sources/qemacs/qemacs/bufed.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -b -r1.22 -r1.23
--- bufed.c 27 Dec 2013 01:54:12 -0000 1.22
+++ bufed.c 4 Jan 2014 17:26:30 -0000 1.23
@@ -1,8 +1,8 @@
/*
* Buffer editor mode for QEmacs.
*
- * Copyright (c) 2001, 2002 Fabrice Bellard.
- * Copyright (c) 2002-2013 Charlie Gordon.
+ * Copyright (c) 2001-2002 Fabrice Bellard.
+ * Copyright (c) 2002-2014 Charlie Gordon.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -69,17 +69,17 @@
eb_printf(b, " %-2s%-16s", flags, hs->items.items[i]->str);
if (b1) {
char path[MAX_FILENAME_SIZE];
- const char *mode;
+ const char *mode_name;
EditState *e;
if (b1->saved_data) {
- mode = b1->saved_data->mode->name;
+ mode_name = b1->saved_data->mode->name;
} else {
- mode = "none";
+ mode_name = "none";
for (e = qs->first_window; e != NULL; e = e->next_window) {
if (e->b == b1) {
if (e->mode) {
- mode = e->mode->name;
+ mode_name = e->mode->name;
break;
}
}
@@ -87,7 +87,7 @@
}
eb_printf(b, " %10d %-8s %-8s %s",
- b1->total_size, b1->charset->name, mode,
+ b1->total_size, b1->charset->name, mode_name,
make_user_path(path, sizeof(path), b1->filename));
}
eb_printf(b, "\n");
Index: buffer.c
===================================================================
RCS file: /sources/qemacs/qemacs/buffer.c,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -b -r1.48 -r1.49
--- buffer.c 4 Jan 2014 15:54:48 -0000 1.48
+++ buffer.c 4 Jan 2014 17:27:00 -0000 1.49
@@ -1660,7 +1660,7 @@
*/
int eb_save_buffer(EditBuffer *b)
{
- int ret, mode;
+ int ret, st_mode;
char buf1[MAX_FILENAME_SIZE];
const char *filename;
struct stat st;
@@ -1670,9 +1670,9 @@
filename = b->filename;
/* get old file permission */
- mode = 0644;
+ st_mode = 0644;
if (stat(filename, &st) == 0)
- mode = st.st_mode & 0777;
+ st_mode = st.st_mode & 0777;
/* backup old file if present */
if (strlen(filename) < MAX_FILENAME_SIZE - 1) {
@@ -1682,14 +1682,14 @@
}
}
- /* CG: should pass mode to buffer_save */
+ /* CG: should pass st_mode to buffer_save */
ret = b->data_type->buffer_save(b, 0, b->total_size, filename);
if (ret < 0)
return ret;
#ifndef CONFIG_WIN32
- /* set correct file mode to old file permissions */
- chmod(filename, mode);
+ /* set correct file st_mode to old file permissions */
+ chmod(filename, st_mode);
#endif
/* reset log */
/* CG: should not do this! */
Index: clang.c
===================================================================
RCS file: /sources/qemacs/qemacs/clang.c,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -b -r1.40 -r1.41
--- clang.c 23 Nov 2013 19:11:13 -0000 1.40
+++ clang.c 4 Jan 2014 17:27:00 -0000 1.41
@@ -1,8 +1,8 @@
/*
* C mode for QEmacs.
*
- * Copyright (c) 2001, 2002 Fabrice Bellard.
- * Copyright (c) 2002-2008 Charlie Gordon.
+ * Copyright (c) 2001-2002 Fabrice Bellard.
+ * Copyright (c) 2002-2014 Charlie Gordon.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -44,7 +44,7 @@
"char|double|float|int|long|unsigned|short|signed|void|var|"
"_Bool|_Complex|_Imaginary|";
-static const char *c_mode_extensions =
+static const char c_mode_extensions[] =
"c|h|y|l|lex|e|qe|cs|idl|jav|java|js|json|"
"ec|ecp|" /* Informix embedded C */
"pgc|" /* Postgres embedded C */
@@ -599,10 +599,10 @@
{
}
-static int c_mode_probe(ModeProbeData *p)
+static int c_mode_probe(ModeDef *mode, ModeProbeData *p)
{
/* currently, only use the file extension */
- if (match_extension(p->filename, c_mode_extensions))
+ if (match_extension(p->filename, mode->extensions))
return 80;
/* weaker match on C comment start */
@@ -613,6 +613,10 @@
if (p->buf[0] == '/' && p->buf[1] == '/')
return 50;
+ /* same for file starting with '#include' */
+ if (strstart(cs8(p->buf), "#include", NULL))
+ return 50;
+
/* same for file starting with '#pragma' as in #pragma once */
if (strstart(cs8(p->buf), "#pragma", NULL))
return 50;
@@ -653,9 +657,10 @@
{
const char *p;
- /* c mode is almost like the text mode, so we copy and patch it */
+ /* C mode is almost like the text mode, so we copy and patch it */
memcpy(&c_mode, &text_mode, sizeof(ModeDef));
c_mode.name = "C";
+ c_mode.extensions = c_mode_extensions;
c_mode.mode_probe = c_mode_probe;
c_mode.mode_init = c_mode_init;
Index: dired.c
===================================================================
RCS file: /sources/qemacs/qemacs/dired.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -b -r1.31 -r1.32
--- dired.c 27 Dec 2013 01:54:12 -0000 1.31
+++ dired.c 4 Jan 2014 17:27:02 -0000 1.32
@@ -1,8 +1,8 @@
/*
* Directory editor mode for QEmacs.
*
- * Copyright (c) 2001, 2002 Fabrice Bellard.
- * Copyright (c) 2002-2008 Charlie Gordon.
+ * Copyright (c) 2001-2002 Fabrice Bellard.
+ * Copyright (c) 2002-2014 Charlie Gordon.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -43,7 +43,7 @@
/* opaque structure for sorting DiredState.items StringArray */
typedef struct DiredItem {
DiredState *state;
- mode_t mode;
+ mode_t st_mode;
off_t size;
time_t mtime;
int offset;
@@ -122,29 +122,29 @@
const StringItem *item2 = *(const StringItem **)p2;
const DiredItem *dip1 = item1->opaque;
const DiredItem *dip2 = item2->opaque;
- int mode = dip1->state->sort_mode, res;
+ int sort_mode = dip1->state->sort_mode, res;
int is_dir1, is_dir2;
- if (mode & DIRED_SORT_GROUP) {
- is_dir1 = !!S_ISDIR(dip1->mode);
- is_dir2 = !!S_ISDIR(dip2->mode);
+ if (sort_mode & DIRED_SORT_GROUP) {
+ is_dir1 = !!S_ISDIR(dip1->st_mode);
+ is_dir2 = !!S_ISDIR(dip2->st_mode);
if (is_dir1 != is_dir2)
return is_dir2 - is_dir1;
}
for (;;) {
- if (mode & DIRED_SORT_DATE) {
+ if (sort_mode & DIRED_SORT_DATE) {
if (dip1->mtime != dip2->mtime) {
res = (dip1->mtime < dip2->mtime) ? -1 : 1;
break;
}
}
- if (mode & DIRED_SORT_SIZE) {
+ if (sort_mode & DIRED_SORT_SIZE) {
if (dip1->size != dip2->size) {
res = (dip1->size < dip2->size) ? -1 : 1;
break;
}
}
- if (mode & DIRED_SORT_EXTENSION) {
+ if (sort_mode & DIRED_SORT_EXTENSION) {
res = qe_strcollate(get_extension(dip1->name),
get_extension(dip2->name));
if (res)
@@ -153,7 +153,7 @@
res = qe_strcollate(dip1->name, dip2->name);
break;
}
- return (mode & DIRED_SORT_DESCENDING) ? -res : res;
+ return (sort_mode & DIRED_SORT_DESCENDING) ? -res : res;
}
/* select current item */
@@ -358,7 +358,7 @@
dip = qe_malloc_hack(DiredItem, plen);
dip->state = hs;
- dip->mode = st.st_mode;
+ dip->st_mode = st.st_mode;
dip->size = st.st_size;
dip->mtime = st.st_mtime;
dip->mark = ' ';
@@ -513,9 +513,9 @@
}
/* can only apply dired mode on directories */
-static int dired_mode_probe(ModeProbeData *p)
+static int dired_mode_probe(ModeDef *mode, ModeProbeData *p)
{
- if (S_ISDIR(p->mode))
+ if (S_ISDIR(p->st_mode))
return 100;
else
return 0;
Index: docbook.c
===================================================================
RCS file: /sources/qemacs/qemacs/docbook.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- docbook.c 12 Dec 2007 02:24:33 -0000 1.6
+++ docbook.c 4 Jan 2014 17:27:02 -0000 1.7
@@ -21,10 +21,11 @@
#include "qe.h"
#include "css.h"
-static int docbook_mode_probe(ModeProbeData *p1)
+static int docbook_mode_probe(ModeDef *mode, ModeProbeData *p1)
{
- if (xml_mode_probe(p1) == 0)
+ if (xml_mode.mode_probe(&xml_mode, p1) == 0)
return 0;
+
/* well, very crude, but it may work OK */
if (strstr((const char *)p1->buf, "DocBook"))
return 100;
@@ -44,6 +45,7 @@
/* inherit from html mode */
memcpy(&docbook_mode, &html_mode, sizeof(ModeDef));
docbook_mode.name = "docbook";
+ docbook_mode.extensions = NULL;
docbook_mode.mode_probe = docbook_mode_probe;
docbook_mode.mode_init = docbook_mode_init;
Index: hex.c
===================================================================
RCS file: /sources/qemacs/qemacs/hex.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -b -r1.29 -r1.30
--- hex.c 25 Apr 2008 10:46:59 -0000 1.29
+++ hex.c 4 Jan 2014 17:27:03 -0000 1.30
@@ -1,8 +1,8 @@
/*
* Hexadecimal modes for QEmacs.
*
- * Copyright (c) 2000, 2001 Fabrice Bellard.
- * Copyright (c) 2002-2008 Charlie Gordon.
+ * Copyright (c) 2000-2001 Fabrice Bellard.
+ * Copyright (c) 2002-2014 Charlie Gordon.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -21,13 +21,6 @@
#include "qe.h"
-/* CG: should get rid of this forward reference */
-#if defined(__GNUC__) && (__GNUC__ >= 4)
-static ModeDef hex_mode;
-#else
-extern ModeDef hex_mode;
-#endif
-
static int to_disp(int c)
{
#if 1
@@ -155,7 +148,7 @@
CMD_DEF_END,
};
-static int ascii_mode_init(EditState *s, ModeSavedData *saved_data)
+static int binary_mode_init(EditState *s, ModeSavedData *saved_data)
{
QEFont *font;
QEStyleDef style;
@@ -214,7 +207,7 @@
return 0;
}
-static int hex_mode_probe(ModeProbeData *p)
+static int hex_mode_probe(ModeDef *mode, ModeProbeData *p)
{
if (detect_binary(p->buf, p->buf_size))
return 50;
@@ -331,11 +324,11 @@
return pos;
}
-static ModeDef ascii_mode = {
- "ascii",
+static ModeDef binary_mode = {
+ .name = "binary",
.instance_size = 0,
.mode_probe = NULL,
- .mode_init = ascii_mode_init,
+ .mode_init = binary_mode_init,
.mode_close = text_mode_close,
.text_display = hex_display,
.text_backward_offset = hex_backward_offset,
@@ -350,8 +343,8 @@
.get_mode_line = hex_mode_line,
};
-static ModeDef hex_mode = {
- "hex",
+ModeDef hex_mode = {
+ .name = "hex",
.instance_size = 0,
.mode_probe = hex_mode_probe,
.mode_init = hex_mode_init,
@@ -372,12 +365,12 @@
static int hex_init(void)
{
/* first register mode(s) */
- qe_register_mode(&ascii_mode);
+ qe_register_mode(&binary_mode);
qe_register_mode(&hex_mode);
/* commands and default keys */
qe_register_cmd_table(hex_commands, &hex_mode);
- qe_register_cmd_table(hex_commands, &ascii_mode);
+ qe_register_cmd_table(hex_commands, &binary_mode);
/* additional mode specific keys */
qe_register_binding(KEY_TAB, "toggle-hex", &hex_mode);
Index: html.c
===================================================================
RCS file: /sources/qemacs/qemacs/html.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -b -r1.21 -r1.22
--- html.c 25 Apr 2008 10:46:59 -0000 1.21
+++ html.c 4 Jan 2014 17:27:04 -0000 1.22
@@ -1,7 +1,7 @@
/*
* Graphical HTML mode for QEmacs.
*
- * Copyright (c) 2001, 2002 Fabrice Bellard.
+ * Copyright (c) 2001-2002 Fabrice Bellard.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -827,7 +827,7 @@
}
/* search for HTML tag */
-static int html_mode_probe(ModeProbeData *p1)
+static int html_mode_probe(ModeDef *mode, ModeProbeData *p1)
{
const unsigned char *p = p1->buf;
int c, score;
@@ -874,7 +874,7 @@
};
ModeDef html_mode = {
- "html",
+ .name = "html",
.instance_size = sizeof(HTMLState),
.mode_probe = html_mode_probe,
.mode_init = html_mode_init,
Index: htmlsrc.c
===================================================================
RCS file: /sources/qemacs/qemacs/htmlsrc.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- htmlsrc.c 8 Jan 2008 16:37:54 -0000 1.4
+++ htmlsrc.c 4 Jan 2014 17:27:25 -0000 1.5
@@ -1,7 +1,7 @@
/*
* HTML Source mode for QEmacs.
*
- * Copyright (c) 2000-2008 Charlie Gordon.
+ * Copyright (c) 2000-2014 Charlie Gordon.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,8 +20,6 @@
#include "qe.h"
-static const char *html_mode_extensions = "html|htm|asp|shtml|hta|htp|phtml";
-
static int get_html_entity(unsigned int *p)
{
unsigned int *p_start, c;
@@ -251,12 +249,12 @@
return 0;
}
-static int htmlsrc_mode_probe(ModeProbeData *p)
+static int htmlsrc_mode_probe(ModeDef *mode, ModeProbeData *p)
{
const char *buf = (const char*)p->buf;
/* first check file extension */
- if (match_extension(p->filename, html_mode_extensions))
+ if (match_extension(p->filename, mode->extensions))
return 80;
/* then try buffer contents */
@@ -292,9 +290,10 @@
static int htmlsrc_init(void)
{
- /* c mode is almost like the text mode, so we copy and patch it */
+ /* html-src mode is almost like the text mode, so we copy and patch it */
memcpy(&htmlsrc_mode, &text_mode, sizeof(ModeDef));
htmlsrc_mode.name = "html-src";
+ htmlsrc_mode.extensions = "html|htm|asp|shtml|hta|htp|phtml";
htmlsrc_mode.mode_probe = htmlsrc_mode_probe;
htmlsrc_mode.mode_init = htmlsrc_mode_init;
Index: image.c
===================================================================
RCS file: /sources/qemacs/qemacs/image.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -b -r1.22 -r1.23
--- image.c 23 Dec 2013 23:26:43 -0000 1.22
+++ image.c 4 Jan 2014 17:27:38 -0000 1.23
@@ -1,7 +1,7 @@
/*
* Image mode for QEmacs.
*
- * Copyright (c) 2002, 2003 Fabrice Bellard.
+ * Copyright (c) 2002-2003 Fabrice Bellard.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -246,7 +246,7 @@
}
#endif
-static int image_mode_probe(ModeProbeData *pd)
+static int image_mode_probe(ModeDef *mode, ModeProbeData *pd)
{
AVProbeData avpd;
AVImageFormat *fmt;
@@ -828,7 +828,7 @@
};
ModeDef image_mode = {
- "image",
+ .name = "image",
.instance_size = sizeof(ImageState),
.mode_probe = image_mode_probe,
.mode_init = image_mode_init,
Index: latex-mode.c
===================================================================
RCS file: /sources/qemacs/qemacs/latex-mode.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -b -r1.33 -r1.34
--- latex-mode.c 24 Dec 2013 23:42:10 -0000 1.33
+++ latex-mode.c 4 Jan 2014 17:28:18 -0000 1.34
@@ -24,8 +24,6 @@
#define MAX_BUF_SIZE 512
-static ModeDef latex_mode;
-
/* TODO: add state handling to allow colorization of elements longer
* than one line (eg, multi-line functions and strings)
*/
@@ -123,12 +121,12 @@
*colorize_state_ptr = state;
}
-static int latex_mode_probe(ModeProbeData *p)
+static int latex_mode_probe(ModeDef *mode, ModeProbeData *p)
{
/* currently, only use the file extension */
/* Halibut (by Simon Tatham) has a syntax similar to TeX and uses
* .but extension */
- if (match_extension(p->filename, "tex|but"))
+ if (match_extension(p->filename, mode->extensions))
return 100;
return 0;
@@ -326,11 +324,14 @@
CMD_DEF_END,
};
+static ModeDef latex_mode;
+
static int latex_init(void)
{
/* LaTeX mode is almost like the text mode, so we copy and patch it */
memcpy(&latex_mode, &text_mode, sizeof(ModeDef));
latex_mode.name = "LaTeX";
+ latex_mode.extensions = "tex|but";
latex_mode.mode_probe = latex_mode_probe;
latex_mode.mode_init = latex_mode_init;
Index: lisp.c
===================================================================
RCS file: /sources/qemacs/qemacs/lisp.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- lisp.c 4 Apr 2008 07:11:07 -0000 1.1
+++ lisp.c 4 Jan 2014 17:28:32 -0000 1.2
@@ -1,7 +1,7 @@
/*
* Lisp Source mode for QEmacs.
*
- * Copyright (c) 2000-2008 Charlie Gordon.
+ * Copyright (c) 2000-2014 Charlie Gordon.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -22,8 +22,6 @@
/* TODO: lisp-indent = 2 */
-static const char *lisp_mode_extensions = "ll|li|lh|lo|lm|lisp|el";
-
/*---------------- Lisp colors ----------------*/
#define IN_COMMENT 0x01
@@ -105,10 +103,10 @@
#undef LISP_COMMENT
#undef LISP_STRING
-static int lisp_mode_probe(ModeProbeData *p)
+static int lisp_mode_probe(ModeDef *mode, ModeProbeData *p)
{
/* just check file extension */
- if (match_extension(p->filename, lisp_mode_extensions)
+ if (match_extension(p->filename, mode->extensions)
|| strstart(p->filename, ".emacs", NULL))
return 80;
@@ -135,9 +133,10 @@
static int lisp_init(void)
{
- /* c mode is almost like the text mode, so we copy and patch it */
+ /* lisp mode is almost like the text mode, so we copy and patch it */
memcpy(&lisp_mode, &text_mode, sizeof(ModeDef));
lisp_mode.name = "Lisp";
+ lisp_mode.extensions = "ll|li|lh|lo|lm|lisp|el";
lisp_mode.mode_probe = lisp_mode_probe;
lisp_mode.mode_init = lisp_mode_init;
Index: makemode.c
===================================================================
RCS file: /sources/qemacs/qemacs/makemode.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- makemode.c 8 Apr 2008 06:54:44 -0000 1.5
+++ makemode.c 4 Jan 2014 17:28:34 -0000 1.6
@@ -1,7 +1,7 @@
/*
* Makefile mode for QEmacs.
*
- * Copyright (c) 2000-2008 Charlie Gordon.
+ * Copyright (c) 2000-2014 Charlie Gordon.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -144,12 +144,12 @@
#undef MAKEFILE_TARGET
#undef MAKEFILE_MACRO
-static int makefile_mode_probe(ModeProbeData *p)
+static int makefile_mode_probe(ModeDef *mode, ModeProbeData *p)
{
const char *base = get_basename(p->filename);
/* check file name or extension */
- if (match_extension(base, "mk|mak")
+ if (match_extension(base, mode->extensions)
|| stristart(base, "makefile", NULL))
return 70;
@@ -176,9 +176,10 @@
static int makefile_init(void)
{
- /* c mode is almost like the text mode, so we copy and patch it */
+ /* Makefile mode is almost like the text mode, so we copy and patch it */
memcpy(&makefile_mode, &text_mode, sizeof(ModeDef));
makefile_mode.name = "Makefile";
+ makefile_mode.extensions = "mk|mak";
makefile_mode.mode_probe = makefile_mode_probe;
makefile_mode.mode_init = makefile_mode_init;
Index: mpeg.c
===================================================================
RCS file: /sources/qemacs/qemacs/mpeg.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- mpeg.c 8 Jan 2008 16:37:55 -0000 1.5
+++ mpeg.c 4 Jan 2014 17:28:35 -0000 1.6
@@ -151,7 +151,7 @@
return 0;
}
-static int mpeg_mode_probe(ModeProbeData *p)
+static int mpeg_mode_probe(ModeDef *mode, ModeProbeData *p)
{
if (p->buf_size >= 4 &&
p->buf[0] == 0x00 &&
@@ -164,13 +164,13 @@
}
static ModeDef mpeg_mode = {
- "mpeg",
- mode_probe: mpeg_mode_probe,
- mode_init: mpeg_mode_init,
- mode_close: NULL,
- text_display: mpeg_display,
- text_backward_offset: mpeg_backward_offset,
- write_char: hex_write_char,
+ .name = "mpeg",
+ .mode_probe = mpeg_mode_probe,
+ .mode_init = mpeg_mode_init,
+ .mode_close = NULL,
+ .text_display = mpeg_display,
+ .text_backward_offset = mpeg_backward_offset,
+ .write_char = hex_write_char,
};
static int mpeg_init(void)
Index: perl.c
===================================================================
RCS file: /sources/qemacs/qemacs/perl.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- perl.c 18 Jan 2008 17:03:35 -0000 1.8
+++ perl.c 4 Jan 2014 17:28:35 -0000 1.9
@@ -1,7 +1,7 @@
/*
* Perl Source mode for QEmacs.
*
- * Copyright (c) 2000-2008 Charlie Gordon.
+ * Copyright (c) 2000-2014 Charlie Gordon.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,8 +20,6 @@
#include "qe.h"
-static const char *perl_mode_extensions = "pl|perl|pm";
-
/*---------------- Perl colors ----------------*/
#define PERL_TEXT QE_STYLE_DEFAULT
@@ -330,10 +328,10 @@
#undef IN_FORMAT
#undef IN_INPUT
-static int perl_mode_probe(ModeProbeData *p)
+static int perl_mode_probe(ModeDef *mode, ModeProbeData *p)
{
/* just check file extension */
- if (match_extension(p->filename, perl_mode_extensions))
+ if (match_extension(p->filename, mode->extensions))
return 80;
if (p->buf[0] == '#' && p->buf[1] == '!' &&
@@ -363,9 +361,10 @@
static int perl_init(void)
{
- /* c mode is almost like the text mode, so we copy and patch it */
+ /* perl mode is almost like the text mode, so we copy and patch it */
memcpy(&perl_mode, &text_mode, sizeof(ModeDef));
perl_mode.name = "Perl";
+ perl_mode.extensions = "pl|perl|pm";
perl_mode.mode_probe = perl_mode_probe;
perl_mode.mode_init = perl_mode_init;
Index: qe.c
===================================================================
RCS file: /sources/qemacs/qemacs/qe.c,v
retrieving revision 1.106
retrieving revision 1.107
diff -u -b -r1.106 -r1.107
--- qe.c 27 Dec 2013 02:04:21 -0000 1.106
+++ qe.c 4 Jan 2014 17:28:35 -0000 1.107
@@ -1,8 +1,8 @@
/*
* QEmacs, tiny but powerful multimode editor
*
- * Copyright (c) 2000, 2001, 2002 Fabrice Bellard.
- * Copyright (c) 2000-2013 Charlie Gordon.
+ * Copyright (c) 2000-2002 Fabrice Bellard.
+ * Copyright (c) 2000-2014 Charlie Gordon.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -1731,10 +1731,12 @@
probe_data.buf_size = size;
probe_data.real_filename = s->b->filename;
probe_data.total_size = s->b->total_size;
+ probe_data.st_mode = 0644;
probe_data.filename = reduce_filename(fname, sizeof(fname),
get_basename(s->b->filename));
/* CG: should pass EditState? QEmacsState ? */
+ /* Should cycle modes in order of decreasing scores */
m = m0 = s->mode;
for (;;) {
m = m->next;
@@ -1743,7 +1745,7 @@
if (m == m0)
break;
if (!m->mode_probe
- || m->mode_probe(&probe_data) > 0) {
+ || m->mode_probe(m, &probe_data) > 0) {
edit_set_mode(s, m);
break;
}
@@ -1972,9 +1974,9 @@
s->indent_size = indent_width;
}
-void do_set_indent_tabs_mode(EditState *s, int mode)
+void do_set_indent_tabs_mode(EditState *s, int val)
{
- s->indent_tabs_mode = (mode != 0);
+ s->indent_tabs_mode = (val != 0);
}
/* compute string for the first part of the mode line (flags,
@@ -3004,6 +3006,7 @@
{
int line, col;
+ /* CG: beware: offset may fall inside a character */
eb_get_pos(s->b, &line, &col, offset);
return eb_goto_pos(s->b, line, 0);
}
@@ -5349,7 +5352,7 @@
splitpath(buf, buf_size, NULL, 0, buf1);
}
-static ModeDef *probe_mode(EditState *s, int mode, const uint8_t *buf,
+static ModeDef *probe_mode(EditState *s, int st_mode, const uint8_t *buf,
int len, long total_size)
{
QEmacsState *qs = s->qe_state;
@@ -5357,19 +5360,19 @@
EditBuffer *b;
ModeDef *m, *selected_mode;
ModeProbeData probe_data;
- int best_probe_percent, percent;
+ int best_probe_score, score;
const uint8_t *p;
b = s->b;
selected_mode = NULL;
- best_probe_percent = 0;
+ best_probe_score = 0;
probe_data.buf = buf;
probe_data.buf_size = len;
p = memchr(buf, '\n', len);
probe_data.line_len = p ? p - buf : len;
probe_data.real_filename = b->filename;
- probe_data.mode = mode;
+ probe_data.st_mode = st_mode;
probe_data.total_size = total_size;
probe_data.filename = reduce_filename(fname, sizeof(fname),
get_basename(b->filename));
@@ -5378,10 +5381,10 @@
m = qs->first_mode;
while (m != NULL) {
if (m->mode_probe) {
- percent = m->mode_probe(&probe_data);
- if (percent > best_probe_percent) {
+ score = m->mode_probe(m, &probe_data);
+ if (score > best_probe_score) {
selected_mode = m;
- best_probe_percent = percent;
+ best_probe_score = score;
}
}
m = m->next;
@@ -5395,7 +5398,7 @@
{
u8 buf[4097];
char filename[MAX_FILENAME_SIZE];
- int mode, buf_size;
+ int st_mode, buf_size;
ModeDef *selected_mode;
EditBuffer *b;
EditBufferDataType *bdt;
@@ -5462,11 +5465,11 @@
edit_set_mode(s, selected_mode);
return;
} else {
- mode = st.st_mode;
+ st_mode = st.st_mode;
buf_size = 0;
f = NULL;
/* CG: should check for ISDIR and do dired */
- if (S_ISREG(mode)) {
+ if (S_ISREG(st_mode)) {
f = fopen(filename, "r");
if (!f)
goto fail;
@@ -5480,7 +5483,7 @@
}
}
buf[buf_size] = '\0';
- selected_mode = probe_mode(s, mode, buf, buf_size, st.st_size);
+ selected_mode = probe_mode(s, st_mode, buf, buf_size, st.st_size);
if (!selected_mode)
goto fail1;
bdt = selected_mode->data_type;
@@ -5521,19 +5524,19 @@
static void load_completion_cb(void *opaque, int err)
{
EditState *s = opaque;
- int mode;
+ int st_mode;
- mode = S_IFREG;
+ st_mode = S_IFREG;
/* CG: potential problem: EXXX may be negative, as in Haiku */
if (err == -ENOENT || err == -ENOTDIR) {
put_status(s, "(New file)");
} else if (err == -EISDIR) {
- mode = S_IFDIR;
+ st_mode = S_IFDIR;
} else if (err < 0) {
put_status(s, "Could not read file");
}
if (!s->b->probed)
- probe_mode(s, mode);
+ probe_mode(s, st_mode);
edit_display(s->qe_state);
dpy_flush(&global_screen);
}
@@ -6961,7 +6964,8 @@
}
#endif
-static int text_mode_probe(__unused__ ModeProbeData *p)
+static int text_mode_probe(__unused__ ModeDef *mode,
+ __unused__ ModeProbeData *p)
{
#if 0
/* text mode inappropriate for huge binary files */
@@ -7013,7 +7017,7 @@
}
ModeDef text_mode = {
- "text",
+ .name = "text",
.instance_size = 0,
.mode_probe = text_mode_probe,
.mode_init = text_mode_init,
@@ -7394,7 +7398,7 @@
const char str_version[] = "QEmacs version " QE_VERSION;
const char str_credits[] = "Copyright (c) 2000-2003 Fabrice Bellard\n"
- "Copyright (c) 2000-2008 Charlie Gordon\n";
+ "Copyright (c) 2000-2014 Charlie Gordon\n";
static void show_version(void)
{
Index: qe.h
===================================================================
RCS file: /sources/qemacs/qemacs/qe.h,v
retrieving revision 1.105
retrieving revision 1.106
diff -u -b -r1.105 -r1.106
--- qe.h 2 Jan 2014 11:28:30 -0000 1.105
+++ qe.h 4 Jan 2014 17:28:36 -0000 1.106
@@ -858,7 +858,7 @@
int eb_next_line(EditBuffer *b, int offset);
void eb_register_data_type(EditBufferDataType *bdt);
-EditBufferDataType *eb_probe_data_type(const char *filename, int mode,
+EditBufferDataType *eb_probe_data_type(const char *filename, int st_mode,
uint8_t *buf, int buf_size);
void eb_set_data_type(EditBuffer *b, EditBufferDataType *bdt);
void eb_invalidate_raw_data(EditBuffer *b);
@@ -952,7 +952,7 @@
int y_disp; /* virtual position of the displayed text */
int x_disp[2]; /* position for LTR and RTL text resp. */
int minibuf; /* true if single line editing */
- int disp_width; /* width in hex or ascii mode */
+ int disp_width; /* width in binary, hex and unihex modes */
int hex_mode; /* true if we are currently editing hexa */
int unihex_mode; /* true if unihex editing (hex_mode must be true too) */
int hex_nibble; /* current hexa nibble */
@@ -1039,31 +1039,36 @@
#define SAVED_DATA_SIZE offsetof(EditState, end_of_saved_data)
typedef struct DisplayState DisplayState;
+typedef struct ModeProbeData ModeProbeData;
+typedef struct ModeSavedData ModeSavedData;
+typedef struct ModeDef ModeDef;
-typedef struct ModeProbeData {
+struct ModeProbeData {
const char *real_filename;
const char *filename; /* reduced filename for mode matching purposes */
const u8 *buf;
int buf_size;
int line_len;
- int mode; /* unix mode */
+ int st_mode; /* unix file mode */
long total_size;
-} ModeProbeData;
+};
/* private data saved by a mode so that it can be restored when the
mode is started again on a buffer */
-typedef struct ModeSavedData {
- struct ModeDef *mode; /* the mode is saved there */
+struct ModeSavedData {
+ ModeDef *mode; /* the mode is saved there */
char generic_data[SAVED_DATA_SIZE]; /* generic text data */
int data_size; /* mode specific saved data */
char data[1];
-} ModeSavedData;
+};
-typedef struct ModeDef {
+struct ModeDef {
const char *name;
+ const char *extensions;
//const char *mode_line;
int instance_size; /* size of malloced instance */
- int (*mode_probe)(ModeProbeData *); /* return the percentage of confidence
*/
+ /* return the percentage of confidence */
+ int (*mode_probe)(ModeDef *, ModeProbeData *);
int (*mode_init)(EditState *, ModeSavedData *);
void (*mode_close)(EditState *);
/* save the internal state of the mode so that it can be opened
@@ -1099,8 +1104,8 @@
/* mode specific key bindings */
struct KeyDef *first_key;
- struct ModeDef *next;
-} ModeDef;
+ ModeDef *next;
+};
/* special bit to indicate tty styles (for shell mode) */
#define QE_STYLE_TTY 0x800
@@ -1673,7 +1678,7 @@
void do_what_cursor_position(EditState *s);
void do_set_tab_width(EditState *s, int tab_width);
void do_set_indent_width(EditState *s, int indent_width);
-void do_set_indent_tabs_mode(EditState *s, int mode);
+void do_set_indent_tabs_mode(EditState *s, int val);
void display_window_borders(EditState *e);
QEStyleDef *find_style(const char *name);
void style_completion(CompleteState *cp);
@@ -1744,6 +1749,8 @@
/* hex.c */
+extern ModeDef hex_mode;
+
void hex_write_char(EditState *s, int key);
/* list.c */
@@ -1755,14 +1762,17 @@
int list_get_offset(EditState *s);
/* dired.c */
+
void do_dired(EditState *s);
/* c_mode.c */
+
void c_colorize_line(unsigned int *buf, int len,
int *colorize_state_ptr, int state_only);
/* xml.c */
-int xml_mode_probe(ModeProbeData *p1);
+
+extern ModeDef xml_mode;
/* html.c */
@@ -1773,10 +1783,12 @@
int is_html, const char *default_stylesheet);
/* image.c */
+
void fill_border(EditState *s, int x, int y, int w, int h, int color);
int qe_bitmap_format_to_pix_fmt(int format);
/* shell.c */
+
const char *get_shell(void);
#define SF_INTERACTIVE 0x01
Index: script.c
===================================================================
RCS file: /sources/qemacs/qemacs/script.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- script.c 12 Jan 2008 09:57:41 -0000 1.1
+++ script.c 4 Jan 2014 17:28:36 -0000 1.2
@@ -1,7 +1,7 @@
/*
* Shell script mode for QEmacs.
*
- * Copyright (c) 2000-2008 Charlie Gordon.
+ * Copyright (c) 2000-2014 Charlie Gordon.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,8 +20,6 @@
#include "qe.h"
-static const char *script_mode_extensions = "sh|bash|zsh";
-
/*---------------- Perl colors ----------------*/
enum {
@@ -104,9 +102,9 @@
}
}
-static int script_mode_probe(ModeProbeData *p)
+static int script_mode_probe(ModeDef *mode, ModeProbeData *p)
{
- if (match_extension(p->filename, script_mode_extensions))
+ if (match_extension(p->filename, mode->extensions))
return 80;
if (p->buf[0] == '#') {
@@ -138,9 +136,10 @@
static int script_init(void)
{
- /* c mode is almost like the text mode, so we copy and patch it */
+ /* Shell-script mode is almost like the text mode, so we copy and patch it
*/
memcpy(&script_mode, &text_mode, sizeof(ModeDef));
script_mode.name = "Shell-script";
+ script_mode.extensions = "sh|bash|zsh";
script_mode.mode_probe = script_mode_probe;
script_mode.mode_init = script_mode_init;
Index: variables.c
===================================================================
RCS file: /sources/qemacs/qemacs/variables.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- variables.c 22 Nov 2013 20:50:21 -0000 1.9
+++ variables.c 4 Jan 2014 17:28:36 -0000 1.10
@@ -1,7 +1,7 @@
/*
* Module for handling variables in QEmacs
*
- * Copyright (c) 2000-2008 Charlie Gordon.
+ * Copyright (c) 2000-2014 Charlie Gordon.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -74,7 +74,7 @@
*/
//G_VAR( "text-mode-line", text_mode.mode_line, VAR_STRING, VAR_RW )
- //G_VAR( "ascii-mode-line", ascii_mode.mode_line, VAR_STRING, VAR_RW )
+ //G_VAR( "binary-mode-line", binary_mode.mode_line, VAR_STRING, VAR_RW )
//G_VAR( "hex-mode-line", hex_mode.mode_line, VAR_STRING, VAR_RW )
//G_VAR( "unicode-mode-line", unihex_mode.mode_line, VAR_STRING, VAR_RW )
Index: video.c
===================================================================
RCS file: /sources/qemacs/qemacs/video.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- video.c 23 Dec 2013 23:26:43 -0000 1.14
+++ video.c 4 Jan 2014 17:28:37 -0000 1.15
@@ -1,7 +1,7 @@
/*
* Video mode for QEmacs
*
- * Copyright (c) 2002, 2003 Fabrice Bellard.
+ * Copyright (c) 2002-2003 Fabrice Bellard.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -96,7 +96,7 @@
{
}
-static int video_mode_probe(ModeProbeData *pd)
+static int video_mode_probe(ModeDef *mode, ModeProbeData *pd)
{
AVProbeData avpd;
AVInputFormat *fmt;
@@ -951,7 +951,7 @@
};
ModeDef video_mode = {
- "av",
+ .name = "av",
.instance_size = sizeof(VideoState),
.mode_probe = video_mode_probe,
.mode_init = video_mode_init,
Index: xml.c
===================================================================
RCS file: /sources/qemacs/qemacs/xml.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- xml.c 3 Jan 2008 09:51:32 -0000 1.11
+++ xml.c 4 Jan 2014 17:28:37 -0000 1.12
@@ -160,7 +160,7 @@
*colorize_state_ptr = state;
}
-int xml_mode_probe(ModeProbeData *p1)
+static int xml_mode_probe(ModeDef *mode, ModeProbeData *p1)
{
const u8 *p;
@@ -185,11 +185,11 @@
return 0;
}
-static ModeDef xml_mode;
+ModeDef xml_mode;
static int xml_init(void)
{
- /* c mode is almost like the text mode, so we copy and patch it */
+ /* xml mode is almost like the text mode, so we copy and patch it */
memcpy(&xml_mode, &text_mode, sizeof(ModeDef));
xml_mode.name = "xml";
xml_mode.mode_probe = xml_mode_probe;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Qemacs-commit] qemacs bufed.c buffer.c clang.c dired.c docbook...,
Charlie Gordon <=