joe a syntax colorize
Vitezslav Samel
samel na mail.cz
Čtvrtek Srpen 31 15:15:40 CEST 2000
Ahoj!
> > > Uplne postaci pokud se najde nekdo, kdo prekope zdrojaky. Pokud to bude
> > > citelne tak nove features prijdou...
>
> > Pravda, source je ponekud 'malo' ukecany, nicmene presne vecny (s
> > ohledem na optimalizaci pouziti promennych => pritupu do pameti) a
> > priznam se, ze muj kod casto nevypada o mnoho lepe (mam potrebu ++/--
> > davat take hned na misto, kde uz to nevadi nebo potrebuju bez other-side
> > efektu). Algoritmus chapu temer hned, jen mi chvili trvalo nez jsem
> > pochopil, co ze to vraci na konci ten return. Deklarace ala K&R snad
> > nevadi (snad misto goto je vhodnejsi v tomto pripade continue nebo proc
> > rovnou ne break).
> > Ja vim, ze zapisy ala *++s jsou mene prehledne pro ty, kdo casto
>
> O to neslo, blbost jako *++s je jasna asi kazdemu, jde o to, ze autor
> mel na klavesnici porouchany Enter a Tab.
Kdyz jsem hledal v JOEovi, proc mi pri skonceni obcas coredumpuje,
prvni vec, co jsem udelal, bylo prohnani zdrojaku pres indent (myslim, ze
pridat par parametru indentu tak, aby to odpovidalo
/usr/src/linux/Documentation/CodingStyle, by bylo docela vhodne), abych
vubec pochopil co se kde deje. Kdyz uz jsem se v tom orientoval, opravil
chybku v originale (a zase indentovane zdrojaky smazal).
> Na zacatku souboru je jen licence, u funkci neni napsano vubec nic.
> Vsechno je to v jednom adresari, ./configure to nezna apod.
>
> Jednu peknou vlastnost tam vidim, ten clovek psal zasadne kratke funkce
> ccc 30 radku.
;-)
[snip]
> > BTW kde rostou opravdu aktualni source??? (CVS to asi nema, coz?),
> > zacinam mit chut pro svuj milovany editor neco udelat...
>
> v debianu je v2.8
Na konci pridavam patch proti v2.8, ktery:
* prida lokalizaci (patch asi od Vladi MIchla)
* umravni Makefile
* prida dalsi mapovani klavesy End
* upravi verzi (v2.8 --> v2.8patched ;-)))
* odstrani SIGSEGV pri ukoncovani (vsrm() na free() ve vfile.c)
>
> Kazdopadne hodne stesti.... :-)
>
> Karel
Taktez
Vita
[joe-2.8.diff]
diff -urN joe-2.8.orig/.joerc joe-2.8/.joerc
--- joe-2.8.orig/.joerc Sun Jan 8 17:04:50 1995
+++ joe-2.8/.joerc Sun May 14 13:10:29 2000
@@ -477,6 +477,7 @@
eof ^K ^V
eof ^K v
eol .kH Go to end of line
+eol . na 7
eol ^E
exsave ^K X Save and exit
exsave ^K ^X
diff -urN joe-2.8.orig/Makefile joe-2.8/Makefile
--- joe-2.8.orig/Makefile Mon Jan 23 07:01:28 1995
+++ joe-2.8/Makefile Sun May 14 13:11:43 2000
@@ -9,15 +9,15 @@
# to go and where you want the man page
# to go:
-WHEREJOE = /usr/local/bin
-WHERERC = /usr/local/lib
-WHEREMAN = /usr/man/man1
+WHEREJOE = $(TOPDIR)/usr/bin
+WHERERC = $(TOPDIR)/usr/lib/joe
+WHEREMAN = $(TOPDIR)/usr/man/man1
# If you want to use TERMINFO, you have to set
# the following variable to 1. Also you have to
# include some additional libraries- see below.
-TERMINFO = 0
+TERMINFO = 1
# You may also have to add some additional
# defines to get the include files to work
@@ -26,12 +26,10 @@
# for some HPUX systems, you need to add: -D_HPUX_SOURCE
# C compiler options: make's built-in rules use this variable
-
-CFLAGS = -O
+CFLAGS = -O2 -m486 -DUSE_LOCALE
# C compiler to use: make's built-in rules use this variable
-
-CC = cc
+CC = gcc -pipe
# You may have to include some extra libraries
# for some systems
@@ -45,7 +43,7 @@
# add '-ltinfo', '-lcurses' or '-ltermlib',
# depending on the system.
-EXTRALIBS =
+EXTRALIBS = -lncurses
# Object files
@@ -62,67 +60,32 @@
joe: $(OBJS)
rm -f jmacs jstar rjoe jpico
$(CC) $(CFLAGS) -o joe $(OBJS) $(EXTRALIBS)
- ln joe jmacs
- ln joe jstar
- ln joe rjoe
- ln joe jpico
# All object files depend on config.h
-
$(OBJS): config.h
# How to make config.h
-
config.h:
$(CC) conf.c -o conf
./conf $(WHERERC) $(TERMINFO)
# How to make termidx
-
termidx: termidx.o
$(CC) $(CFLAGS) -o termidx termidx.o
# Install proceedure
-
install: joe termidx
- strip joe
- strip termidx
- if [ ! -d $(WHEREJOE) ]; then mkdir $(WHEREJOE); chmod a+rx $(WHEREJOE); fi
- rm -f $(WHEREJOE)/joe $(WHEREJOE)/jmacs $(WHEREJOE)/jstar $(WHEREJOE)/jpico $(WHEREJOE)/rjoe $(WHEREJOE)/termidx
- mv joe $(WHEREJOE)
- ln $(WHEREJOE)/joe $(WHEREJOE)/jmacs
- ln $(WHEREJOE)/joe $(WHEREJOE)/jstar
- ln $(WHEREJOE)/joe $(WHEREJOE)/rjoe
- ln $(WHEREJOE)/joe $(WHEREJOE)/jpico
- mv termidx $(WHEREJOE)
- if [ ! -d $(WHERERC) ]; then mkdir $(WHERERC); chmod a+rx $(WHERERC); fi
- rm -f $(WHERERC)/joerc $(WHERERC)/jmacsrc $(WHERERC)/jstarrc $(WHERERC)/jpicorc $(WHERERC)/rjoerc $(WHEREMAN)/joe.1
- cp joerc $(WHERERC)
- cp jmacsrc $(WHERERC)
- cp jstarrc $(WHERERC)
- cp rjoerc $(WHERERC)
- cp jpicorc $(WHERERC)
- cp joe.1 $(WHEREMAN)
- chmod a+x $(WHEREJOE)/joe
- chmod a+x $(WHEREJOE)/jmacs
- chmod a+x $(WHEREJOE)/jstar
- chmod a+x $(WHEREJOE)/rjoe
- chmod a+x $(WHEREJOE)/jpico
- chmod a+r $(WHERERC)/joerc
- chmod a+r $(WHERERC)/jmacsrc
- chmod a+r $(WHERERC)/jstarrc
- chmod a+r $(WHERERC)/rjoerc
- chmod a+r $(WHERERC)/jpicorc
- chmod a+r $(WHEREMAN)/joe.1
- chmod a+x $(WHEREJOE)/termidx
- rm -f $(WHERERC)/termcap
- cp termcap $(WHERERC)/termcap
- chmod a+r $(WHERERC)/termcap
- rm -f $(WHERERC)/terminfo
- cp terminfo $(WHERERC)/terminfo
- chmod a+r $(WHERERC)/terminfo
+ [ ! -d $(WHEREJOE) ] && mkdir -p $(WHEREJOE)
+ install -s -m 0555 -o bin -g bin joe $(WHEREJOE)
+ ln -s joe $(WHEREJOE)/jmacs
+ ln -s joe $(WHEREJOE)/jstar
+ ln -s joe $(WHEREJOE)/rjoe
+ ln -s joe $(WHEREJOE)/jpico
+ [ ! -d $(WHERERC) ] && mkdir -p $(WHERERC)
+ install -m 0644 -o root -g root joerc jmacsrc jstarrc rjoerc jpicorc $(WHERERC)
+ [ ! -d $(WHEREMAN) ] && mkdir -p $(WHEREMAN)
+ install -m 0444 -o man -g man joe.1 $(WHEREMAN)
# Cleanup proceedure
-
clean:
- rm -f $(OBJS) termidx.o conf conf.o config.h
+ rm -f joe $(OBJS) termidx.o conf conf.o config.h
diff -urN joe-2.8.orig/b.c joe-2.8/b.c
--- joe-2.8.orig/b.c Fri Jan 20 09:38:25 1995
+++ joe-2.8/b.c Sun May 14 13:10:29 2000
@@ -416,7 +416,7 @@
int c=brc(p);
int d=prgetc(q);
prm(q);
- if(crest(c) && !crest(d)) return 1;
+ if(isalnum(c) && !isalnum(d)) return 1;
else return 0;
}
@@ -427,7 +427,7 @@
int d=brc(q);
int c=prgetc(q);
prm(q);
- if(crest(c) && !crest(d)) return 1;
+ if(isalnum(c) && !isalnum(d)) return 1;
else return 0;
}
diff -urN joe-2.8.orig/b.h joe-2.8/b.h
--- joe-2.8.orig/b.h Wed Dec 21 13:04:46 1994
+++ joe-2.8/b.h Sun May 14 13:10:29 2000
@@ -211,7 +211,8 @@
B *bnext();
B *bprev();
-extern int error;
+#define error berror
+extern int berror;
char **getbufs();
diff -urN joe-2.8.orig/conf.c joe-2.8/conf.c
--- joe-2.8.orig/conf.c Fri Jan 13 18:10:33 1995
+++ joe-2.8/conf.c Sun May 14 13:10:29 2000
@@ -168,7 +168,7 @@
fprintf(f,"\n");
fprintf(f,"#ifndef HZ\n");
- fprintf(f,"#define HZ 10\n");
+ fprintf(f,"#define HZ 100\n");
fprintf(f,"#endif\n");
fprintf(f,"\n");
@@ -204,8 +204,11 @@
fprintf(f,"\n");
fprintf(f,"char *getenv();\n");
+#if !defined(__linux__) || !defined(__alpha__)
if(sizeof(long)==8) fprintf(f,"int time();\n");
- else fprintf(f,"long time();\n");
+ else
+#endif
+ fprintf(f,"long time();\n");
fprintf(f,"void *malloc();\n");
fprintf(f,"void free();\n");
fprintf(f,"void *calloc();\n");
diff -urN joe-2.8.orig/joerc joe-2.8/joerc
--- joe-2.8.orig/joerc Sun Jan 8 17:04:50 1995
+++ joe-2.8/joerc Sun May 14 13:10:29 2000
@@ -477,6 +477,7 @@
eof ^K ^V
eof ^K v
eol .kH Go to end of line
+eol . na 7
eol ^E
exsave ^K X Save and exit
exsave ^K ^X
diff -urN joe-2.8.orig/main.c joe-2.8/main.c
--- joe-2.8.orig/main.c Sun Jan 22 01:21:08 1995
+++ joe-2.8/main.c Sun May 14 13:10:29 2000
@@ -18,6 +18,9 @@
#include <stdio.h>
#include <fcntl.h>
+#ifdef USE_LOCALE
+#include <locale.h>
+#endif
#include "config.h"
#include "w.h"
#include "tty.h"
@@ -194,6 +197,10 @@
if(getenv("NOXON")) noxon=1;
if(s=getenv("JOETERM")) joeterm=s;
+#ifdef USE_LOCALE
+ setlocale(LC_CTYPE, "");
+#endif
+
#ifndef __MSDOS__
if(!(cap=getcap(NULL,9600,NULL,NULL)))
{
@@ -365,7 +372,7 @@
maint->curwin=maint->topwin;
if(help) helpon(maint);
if(!nonotice)
- msgnw(lastw(maint)->object,"\\i** Joe's Own Editor v2.8 ** Copyright (C) 1995 Joseph H. Allen **\\i");
+ msgnw(lastw(maint)->object,"\\i** Joe's Own Editor v2.8patched ** Copyright (C) 1995 Joseph H. Allen **\\i");
edloop(0);
vclose(vmem);
nclose(n);
diff -urN joe-2.8.orig/scrn.h joe-2.8/scrn.h
--- joe-2.8.orig/scrn.h Thu Oct 6 08:09:04 1994
+++ joe-2.8/scrn.h Sun May 14 13:10:29 2000
@@ -19,6 +19,9 @@
#ifndef _Iscrn
#define _Iscrn 1
+#ifdef USE_LOCALE
+#include <ctype.h>
+#endif
#include "config.h"
#include "termcap.h"
#include "tty.h"
@@ -252,6 +255,15 @@
extern unsigned char xlatc[256];
extern int dspasis;
+#ifdef USE_LOCALE
+#define xlat(a,c) \
+ ( \
+ (isprint(c) || dspasis && ((unsigned)(c)>=128)) ? \
+ ((a)=0) \
+ : \
+ (((a)=xlata[(unsigned)(c)]), ((c)=xlatc[(unsigned)(c)])) \
+ )
+#else
#define xlat(a,c) \
( \
(dspasis && ((unsigned)(c)>=128)) ? \
@@ -259,6 +271,7 @@
: \
(((a)=xlata[(unsigned)(c)]), ((c)=xlatc[(unsigned)(c)])) \
)
+#endif
/* int eraeol(SCRN *t,int x,int y);
*
diff -urN joe-2.8.orig/uedit.c joe-2.8/uedit.c
--- joe-2.8.orig/uedit.c Sun Jan 8 16:47:01 1995
+++ joe-2.8/uedit.c Sun May 14 13:10:29 2000
@@ -103,7 +103,7 @@
lp:
d=' ';
while(c=prgetc(bw->cursor),
- c!= MAXINT && !crest(c) && (!cwhitel(c) || cwhitel(d)))
+ c!= MAXINT && !isalnum(c) && (!cwhitel(c) || cwhitel(d)))
d=c;
if(c==' ')
{
@@ -112,7 +112,7 @@
}
if(c!= MAXINT) pgetc(bw->cursor);
/* Move to beginning of current word */
- while(crest(c=prgetc(bw->cursor)));
+ while(isalnum(c=prgetc(bw->cursor)));
if(c!= MAXINT) pgetc(bw->cursor);
return 0;
}
@@ -128,7 +128,7 @@
lp:
d=' ';
while(c=brc(bw->cursor),
- c!= MAXINT && !crest(c) && (!cwhitel(c) || cwhitel(d)))
+ c!= MAXINT && !isalnum(c) && (!cwhitel(c) || cwhitel(d)))
d=pgetc(bw->cursor);
if(c==' ')
{
@@ -136,7 +136,7 @@
if(!cwhitel(d)) goto lp;
}
/* Move to end of current word */
- while(c=brc(bw->cursor), crest(c)) pgetc(bw->cursor);
+ while(c=brc(bw->cursor), isalnum(c)) pgetc(bw->cursor);
return 0;
}
@@ -588,8 +588,8 @@
{
P *p=pdup(bw->cursor);
int c=brc(p);
- if(crest(c))
- while(c=brc(p), crest(c)) pgetc(p);
+ if(isalnum(c))
+ while(c=brc(p), isalnum(c)) pgetc(p);
else if(cwhitel(c) || c=='\r')
while(c=brc(p), (cwhitel(c) || c=='\r')) pgetc(p);
else pgetc(p);
@@ -608,9 +608,9 @@
{
P *p=pdup(bw->cursor);
int c=prgetc(bw->cursor);
- if(crest(c))
+ if(isalnum(c))
{
- while(c=prgetc(bw->cursor), crest(c));
+ while(c=prgetc(bw->cursor), isalnum(c));
if(c!= MAXINT) pgetc(bw->cursor);
}
else if(cwhitel(c))
diff -urN joe-2.8.orig/usearch.c joe-2.8/usearch.c
--- joe-2.8.orig/usearch.c Wed Dec 21 17:32:48 1994
+++ joe-2.8/usearch.c Sun May 14 13:10:29 2000
@@ -9,6 +9,7 @@
#include "main.h"
#include "undo.h"
#include "usearch.h"
+#include "zstr.h"
int smode=0; /* Decremented to zero by execmd */
int csmode=0; /* Set for continued search mode */
diff -urN joe-2.8.orig/vfile.c joe-2.8/vfile.c
--- joe-2.8.orig/vfile.c Thu Oct 6 07:20:35 1994
+++ joe-2.8/vfile.c Sun May 14 13:10:29 2000
@@ -288,7 +288,8 @@
{
if(vfile->flags) unlink(vfile->name);
else vflshf(vfile);
- vsrm(vfile->name);
+ free(vfile->name);
+ vfile->name = NULL;
}
if(vfile->fd) close(vfile->fd);
free(deque(VFILE,link,vfile));
diff -urN joe-2.8.orig/zstr.c joe-2.8/zstr.c
--- joe-2.8.orig/zstr.c Mon Jan 16 19:02:47 1995
+++ joe-2.8/zstr.c Sun May 14 13:10:29 2000
@@ -42,8 +42,10 @@
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};
+#ifndef USE_LOCALE
int toup(a) { return clower(a) ? a+'A'-'a' : a; }
int todn(a) { return cupper(a) ? a+'a'-'A' : a; }
+#endif
unsigned Umin(a,b) unsigned a,b; { return a<b?a:b; }
unsigned Umax(a,b) unsigned a,b; { return a>b?a:b; }
int Imin(a,b) { return a<b?a:b; }
diff -urN joe-2.8.orig/zstr.h joe-2.8/zstr.h
--- joe-2.8.orig/zstr.h Thu Oct 6 07:20:35 1994
+++ joe-2.8/zstr.h Sun May 14 13:10:29 2000
@@ -20,6 +20,9 @@
#define _Izstr 1
#include "config.h"
+#ifdef USE_LOCALE
+#include <ctype.h>
+#endif
#define _upp 1
#define _low 2
@@ -38,6 +41,12 @@
/* Character type test macros */
+#ifdef USE_LOCALE
+#define cupper isupper
+#define clower islower
+#define calpha isalpha
+#else
+
/* Upper case */
#define cupper(c) (_ctaB[(unsigned char)(c)]&_upp)
@@ -46,6 +55,7 @@
/* Letter */
#define calpha(c) (_ctaB[(unsigned char)(c)]&(_low|_upp))
+#endif
/* First legal character of a C identifier */
#define cfirst(c) (_ctaB[(unsigned char)(c)]&(_low|_upp|_und))
@@ -53,6 +63,10 @@
/* Remaining legal characters of a C identifier */
#define crest(c) (_ctaB[(unsigned char)(c)]&(_low|_upp|_und|_bin|_oct|_dec))
+#ifndef USE_LOCALE
+#define isalnum crest
+#endif
+
/* Binary digit */
#define cbin(c) (_ctaB[(unsigned char)(c)]&(_bin))
@@ -83,11 +97,16 @@
/* long Labs(long n); Return absolute value of given long */
long Labs();
+#ifdef USE_LOCALE
+#define toup toupper
+#define todn tolower
+#else
/* int toup(int c); Convert character to uppercase if it was lowercase */
int toup();
/* int todn(int c); Convert character to lowercase if it was uppercase */
int todn();
+#endif
/* unsigned Umin(unsigned a,unsigned b); Return the smaller unsigned integer */
unsigned Umin();
Další informace o konferenci Linux