Eshu
view release on metacpan or search on metacpan
include/eshu_pl.h view on Meta::CPAN
const char *p = src;
const char *end = src + src_len;
char *result;
eshu_pl_ctx_init(&ctx, cfg);
eshu_buf_init(&out, src_len + 256);
{
int line_num = 1;
while (p < end) {
const char *eol = eshu_find_eol(p);
if (eshu_in_range(cfg, line_num)) {
eshu_pl_process_line(&ctx, &out, p, eol);
} else {
size_t saved = out.len;
eshu_pl_process_line(&ctx, &out, p, eol);
out.len = saved;
eshu_buf_write_trimmed(&out, p, (int)(eol - p));
eshu_buf_putc(&out, '\n');
}
p = eol;
if (*p == '\n') p++;
line_num++;
}
}
/* Flush any remaining buffered POD (no =cut at EOF) */
if (ctx.pod_buf.len > 0) {
char *pod_result;
size_t pod_out_len;
eshu_buf_putc(&ctx.pod_buf, '\0');
ctx.pod_buf.len--;
pod_result = eshu_indent_pod(ctx.pod_buf.data, ctx.pod_buf.len, &ctx.cfg, &pod_out_len);
eshu_buf_write(&out, pod_result, (int)pod_out_len);
free(pod_result);
}
eshu_buf_free(&ctx.pod_buf);
/* NUL-terminate */
eshu_buf_putc(&out, '\0');
out.len--;
*out_len = out.len;
result = out.data;
return result;
}
#include "eshu_hl_util.h"
/* ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
* Perl keyword list
* ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ */
static const char * const eshu_hl_pl_kw[] = {
"BEGIN", "END", "AUTOLOAD", "DESTROY",
"abs", "accept", "alarm", "and", "atan2",
"bind", "binmode", "bless",
"caller", "chdir", "chmod", "chomp", "chop", "chown", "chr",
"chroot", "close", "closedir", "connect", "cos", "crypt",
"dbmclose", "dbmopen", "defined", "delete", "die", "do", "dump",
"each", "else", "elsif", "endgrent", "endhostent", "endnetent",
"endprotoent", "endpwent", "endservent", "eof", "eval", "exec",
"exists", "exit", "exp",
"fcntl", "fileno", "flock", "for", "foreach", "fork", "format",
"formline",
"getc", "getgrent", "getgrgid", "getgrnam", "gethostbyaddr",
"gethostbyname", "gethostent", "getlogin", "getnetbyaddr",
"getnetbyname", "getnetent", "getpeername", "getpgrp", "getppid",
"getpriority", "getprotobyname", "getprotobynumber", "getprotoent",
"getpwent", "getpwnam", "getpwuid", "getservbyname",
"getservbyport", "getservent", "getsockname", "getsockopt",
"given", "glob", "gmtime", "goto", "grep",
"hex",
"if", "import", "index", "int", "ioctl",
"join",
"keys", "kill",
"last", "lc", "lcfirst", "length", "link", "listen", "local",
"localtime", "log", "lstat",
"m", "map", "mkdir", "msgctl", "msgget", "msgrcv", "msgsnd",
"my",
"next", "no",
"oct", "open", "opendir", "or", "ord", "our",
"pack", "package", "pipe", "pop", "pos", "print", "printf",
"prototype", "push",
"q", "qq", "qr", "quotemeta", "qw", "qx",
"rand", "read", "readdir", "readline", "readlink", "readpipe",
"recv", "redo", "ref", "rename", "require", "reset", "return",
"reverse", "rewinddir", "rindex", "rmdir",
"s", "say", "scalar", "seek", "seekdir", "select", "semctl",
"semget", "semop", "send", "setgrent", "sethostent", "setnetent",
"setpgrp", "setpriority", "setprotoent", "setpwent", "setservent",
"setsockopt", "shift", "shmctl", "shmget", "shmread", "shmwrite",
"shutdown", "sin", "sleep", "socket", "socketpair", "sort", "splice",
"split", "sprintf", "sqrt", "srand", "stat", "state", "study", "sub",
"substr", "symlink", "syscall", "sysopen", "sysread", "sysseek",
"system", "syswrite",
"tell", "telldir", "tie", "tied", "time", "times", "tr",
"truncate",
"uc", "ucfirst", "umask", "undef", "unless", "unlink", "unpack",
"unshift", "untie", "until", "use", "utime",
"values", "vec",
"wait", "waitpid", "wantarray", "warn", "when", "while", "write",
"y",
NULL
};
/* ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
* Perl highlighter
* ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ */
/* Paired delimiter map: ( â ), [ â ], { â }, < â > */
static char eshu_hl_paired(char open) {
switch (open) {
case '(': return ')';
case '[': return ']';
case '{': return '}';
case '<': return '>';
default: return open;
( run in 0.682 second using v1.01-cache-2.11-cpan-92ad3014f07 )