[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemacs-commit] qemacs qe.c qe.h util.c
From: |
Charlie Gordon |
Subject: |
[Qemacs-commit] qemacs qe.c qe.h util.c |
Date: |
Fri, 21 Dec 2007 14:27:12 +0000 |
CVSROOT: /cvsroot/qemacs
Module name: qemacs
Changes by: Charlie Gordon <chqrlie> 07/12/21 14:27:12
Modified files:
. : qe.c qe.h util.c
Log message:
added const void *memstr(const void *buf, int size, const char *str);
added line_len and total_size in ModeProbeData structure
extended SEARCH_LENGTH to 256, allowing upto 256 matches in incremental
C-s
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.c?cvsroot=qemacs&r1=1.49&r2=1.50
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.h?cvsroot=qemacs&r1=1.44&r2=1.45
http://cvs.savannah.gnu.org/viewcvs/qemacs/util.c?cvsroot=qemacs&r1=1.29&r2=1.30
Patches:
Index: qe.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/qe.c,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -b -r1.49 -r1.50
--- qe.c 21 Dec 2007 12:30:56 -0000 1.49
+++ qe.c 21 Dec 2007 14:27:11 -0000 1.50
@@ -4937,20 +4937,25 @@
splitpath(buf, buf_size, NULL, 0, buf1);
}
-static ModeDef *probe_mode(EditState *s, int mode, uint8_t *buf, int len)
+static ModeDef *probe_mode(EditState *s, int mode, const uint8_t *buf,
+ int len, long total_size)
{
EditBuffer *b = s->b;
ModeDef *m, *selected_mode;
ModeProbeData probe_data;
int best_probe_percent, percent;
+ const uint8_t *p;
m = s->qe_state->first_mode;
selected_mode = NULL;
best_probe_percent = 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.filename = b->filename;
probe_data.mode = mode;
+ probe_data.total_size = total_size;
while (m != NULL) {
if (m->mode_probe) {
@@ -5015,7 +5020,7 @@
/* Try to determine the desired mode based on the filename.
* This avoids having to set c-mode for each new .c or .h file. */
buf[0] = '\0';
- selected_mode = probe_mode(s, S_IFREG, buf, 0);
+ selected_mode = probe_mode(s, S_IFREG, buf, 0, 0);
/* XXX: avoid loading file */
if (selected_mode)
do_set_mode(s, selected_mode, NULL);
@@ -5023,6 +5028,7 @@
} else {
mode = st.st_mode;
buf_size = 0;
+ f = NULL;
if (S_ISREG(mode)) {
f = fopen(filename, "r");
if (!f)
@@ -5031,14 +5037,13 @@
if (buf_size < 0) {
fail1:
fclose(f);
+ f = NULL;
goto fail;
}
- } else {
- f = NULL;
}
}
buf[buf_size] = '\0';
- selected_mode = probe_mode(s, mode, buf, buf_size);
+ selected_mode = probe_mode(s, mode, buf, buf_size, st.st_size);
if (!selected_mode)
goto fail1;
bdt = selected_mode->data_type;
@@ -5058,6 +5063,7 @@
/* XXX: invalid place */
edit_invalidate(s);
return;
+
fail:
put_status(s, "Could not open '%s'", filename);
}
@@ -5388,7 +5394,8 @@
}
}
-#define SEARCH_LENGTH 80
+/* should separate search string length and number of match positions */
+#define SEARCH_LENGTH 256
#define FOUND_TAG 0x80000000
/* store last searched string */
Index: qe.h
===================================================================
RCS file: /cvsroot/qemacs/qemacs/qe.h,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -b -r1.44 -r1.45
--- qe.h 21 Dec 2007 12:30:56 -0000 1.44
+++ qe.h 21 Dec 2007 14:27:11 -0000 1.45
@@ -218,6 +218,7 @@
void skip_spaces(const char **pp);
int strfind(const char *keytable, const char *str, int casefold);
+const void *memstr(const void *buf, int size, const char *str);
#define stristart(str, val, ptr) qe_stristart(str, val, ptr)
int stristart(const char *str, const char *val, const char **ptr);
@@ -961,11 +962,12 @@
struct DisplayState;
typedef struct ModeProbeData {
- char *filename;
- unsigned char *buf;
+ const char *filename;
+ const u8 *buf;
int buf_size;
- //int total_size;
+ int line_len;
int mode; /* unix mode */
+ long total_size;
} ModeProbeData;
/* private data saved by a mode so that it can be restored when the
Index: util.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/util.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -b -r1.29 -r1.30
--- util.c 21 Dec 2007 12:30:34 -0000 1.29
+++ util.c 21 Dec 2007 14:27:11 -0000 1.30
@@ -391,6 +391,29 @@
}
}
+const void *memstr(const void *buf, int size, const char *str)
+{
+ int c, len;
+ const u8 *p, *buf_max;
+
+ c = *str++;
+ if (!c) {
+ /* empty string matches start of buffer */
+ return buf;
+ }
+
+ len = strlen(str);
+ if (len >= size)
+ return NULL;
+
+ buf_max = (const u8*)buf + size - len;
+ for (p = buf; p < buf_max; p++) {
+ if (*p == c && !memcmp(p + 1, str, len))
+ return p;
+ }
+ return NULL;
+}
+
void skip_spaces(const char **pp)
{
const char *p;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Qemacs-commit] qemacs qe.c qe.h util.c,
Charlie Gordon <=