1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
/*
* tags file symbol lookup
* Copyright
* (C) 1992 Joseph H. Allen
*
* This file is part of JOE (Joe's Own Editor)
*/
#include "config.h"
#include "types.h"
__RCSID("$MirOS: contrib/code/jupp/utag.c,v 1.11 2017/12/07 02:10:19 tg Exp $");
#include "b.h"
#include "bw.h"
#include "main.h"
#include "pw.h"
#include "tab.h"
#include "ufile.h"
#include "usearch.h"
#include "utag.h"
#include "utils.h"
#include "vs.h"
#include "charmap.h"
#include "w.h"
static int dotag(BW *bw, unsigned char *s, void *obj, int *notify)
{
unsigned char buf[512];
FILE *f;
unsigned char *t = NULL;
if (notify) {
*notify = 1;
}
if (bw->b->name) {
t = vsncpy(t, 0, sz(bw->b->name));
t = vsncpy(sv(t), sc(":"));
t = vsncpy(sv(t), sv(s));
}
f = fopen("tags", "r");
if (!f) {
msgnw(bw->parent, UC "Couldn't open tags file");
vsrm(s);
vsrm(t);
return -1;
}
while (fgets((char *)buf, 512, f)) {
int x, y, c;
for (x = 0; buf[x] && buf[x] != ' ' && buf[x] != '\t'; ++x) ;
c = buf[x];
buf[x] = 0;
if (!strcmp(s, buf) || (t && !strcmp(t, buf))) {
buf[x] = c;
while (buf[x] == ' ' || buf[x] == '\t') {
++x;
}
for (y = x; buf[y] && buf[y] != ' ' && buf[y] != '\t' && buf[y] != '\n'; ++y) ;
if (x != y) {
c = buf[y];
buf[y] = 0;
if (doswitch(bw, vsncpy(NULL, 0, sz(buf + x)), NULL, NULL)) {
vsrm(s);
vsrm(t);
fclose(f);
return -1;
}
bw = maint->curwin->object.bw;
buf[y] = c;
while (buf[y] == ' ' || buf[y] == '\t') {
++y;
}
for (x = y; buf[x] && buf[x] != '\n'; ++x) ;
buf[x] = 0;
if (x != y) {
long line = 0;
if (buf[y] >= '0' && buf[y] <= '9') {
line = ustol(buf + y, NULL, USTOL_AUTO);
if (line >= 1) {
int omid = mid;
mid = 1;
pline(bw->cursor, line - 1), bw->cursor->xcol = piscol(bw->cursor);
dofollows();
mid = omid;
} else {
msgnw(bw->parent, UC "Invalid line number");
}
} else {
if (buf[y] == '/' || buf[y] == '?') {
++y;
if (buf[y] == '^')
buf[--y] = '\\';
for (x = y+1; buf[x] && buf[x] != '\n' && buf[x-1] != '/'; ++x);
}
if (buf[x - 1] == '/' || buf[x - 1] == '?') {
--x;
buf[x] = 0;
if (buf[x - 1] == '$') {
buf[x - 1] = '\\';
buf[x] = '$';
++x;
buf[x] = 0;
}
}
if (x != y) {
vsrm(s);
vsrm(t);
fclose(f);
return dopfnext(bw, mksrch(vsncpy(NULL, 0, sz(buf + y)), NULL, 0, 0, -1, 0, 0), NULL);
}
}
}
vsrm(s);
vsrm(t);
fclose(f);
return 0;
}
}
}
msgnw(bw->parent, UC "Not found");
vsrm(s);
vsrm(t);
fclose(f);
return -1;
}
static B *taghist = NULL;
int utag(BW *bw)
{
BW *pbw;
pbw = wmkpw(bw->parent, UC "Tag search: ", &taghist, dotag, NULL, NULL, cmplt, NULL, NULL, locale_map);
if (pbw && joe_isalnux(bw->b->o.charmap,brch(bw->cursor))) {
P *p = pdup(bw->cursor);
P *q = pdup(p);
int c;
while (joe_isalnux(bw->b->o.charmap,(c = prgetc(p))))
/* do nothing */;
if (c != NO_MORE_DATA) {
pgetc(p);
}
pset(q, p);
while (joe_isalnux(bw->b->o.charmap,(c = pgetc(q))))
/* do nothing */;
if (c != NO_MORE_DATA) {
prgetc(q);
}
binsb(pbw->cursor, bcpy(p, q));
pset(pbw->cursor, pbw->b->eof);
pbw->cursor->xcol = piscol(pbw->cursor);
prm(p);
prm(q);
}
if (pbw) {
return 0;
} else {
return -1;
}
}
|