mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-11-25 19:03:10 +02:00
genkicat/: detect URLs in comments and add PDF hyperlink
We recognize http, https, ftp, and file.
This commit is contained in:
parent
4811fb3d3d
commit
993ea811e5
@ -254,10 +254,25 @@ static void print_comment(FILE *file, const struct line *comment)
|
|||||||
n = 0;
|
n = 0;
|
||||||
for (line = comment; line; line = line->next) {
|
for (line = comment; line; line = line->next) {
|
||||||
n++;
|
n++;
|
||||||
fprintf(file, "%d -%d moveto\n", format->left,
|
fprintf(file, "newpath %d -%d moveto\n", format->left,
|
||||||
format->comment.y+(n-lines)*format->comment_line_skip);
|
format->comment.y+(n-lines)*format->comment_line_skip);
|
||||||
|
if (line->url) {
|
||||||
|
fprintf(file, "currentpoint\n");
|
||||||
|
fprintf(file, "[ /Rect [ ");
|
||||||
|
ps_string(file, line->s);
|
||||||
|
fprintf(file,
|
||||||
|
" false charpath flattenpath pathbbox ]\n");
|
||||||
|
fprintf(file, " /Subtype /Link\n");
|
||||||
|
fprintf(file, " /Border [ 0 0 0 ]\n");
|
||||||
|
fprintf(file, " /Action << /Subtype /URI /URI ");
|
||||||
|
ps_string(file, line->s);
|
||||||
|
fprintf(file, " >>\n");
|
||||||
|
fprintf(file, " /ANN pdfmark\n");
|
||||||
|
fprintf(file, " moveto\n");
|
||||||
|
}
|
||||||
ps_string(file, line->s);
|
ps_string(file, line->s);
|
||||||
fprintf(file, " show\n");
|
fprintf(file, " show\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
fprintf(file, "grestore\n");
|
fprintf(file, "grestore\n");
|
||||||
}
|
}
|
||||||
|
@ -118,10 +118,24 @@ static struct node *find_comp(struct node *node, const char *name)
|
|||||||
|
|
||||||
static struct line *new_line(char *s)
|
static struct line *new_line(char *s)
|
||||||
{
|
{
|
||||||
|
const char *uris[] = {
|
||||||
|
"http://",
|
||||||
|
"https://",
|
||||||
|
"ftp://",
|
||||||
|
"file:/", /* one slash, for RFC3986 file:/localpath */
|
||||||
|
NULL
|
||||||
|
}, **uri = uris;
|
||||||
struct line *line;
|
struct line *line;
|
||||||
|
|
||||||
line = alloc_type(struct line);
|
line = alloc_type(struct line);
|
||||||
line->s = stralloc(s);
|
line->s = stralloc(s);
|
||||||
|
/*
|
||||||
|
* Require a slash at all to avoid misdetection. Require only one slash
|
||||||
|
* for compatibility with RFC3986.
|
||||||
|
*/
|
||||||
|
while (*uri && strncmp(s, *uri, strlen(*uri)))
|
||||||
|
uri++;
|
||||||
|
line->url = !!*uri;
|
||||||
line->next = NULL;
|
line->next = NULL;
|
||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
@ -130,17 +144,19 @@ static struct line *new_line(char *s)
|
|||||||
static void append_line(struct line *line, char *s)
|
static void append_line(struct line *line, char *s)
|
||||||
{
|
{
|
||||||
int len1, len2;
|
int len1, len2;
|
||||||
|
int spc = !line->url;
|
||||||
|
|
||||||
len1 = strlen(line->s);
|
len1 = strlen(line->s);
|
||||||
len2 = strlen(s);
|
len2 = strlen(s);
|
||||||
line->s = realloc(line->s, len1+len2+1+1); /* separating space */
|
line->s = realloc(line->s, len1+len2+spc+1);
|
||||||
if (!line->s) {
|
if (!line->s) {
|
||||||
perror("realloc");
|
perror("realloc");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
line->s[len1] = ' ';
|
if (spc)
|
||||||
memcpy(line->s+len1+1, s, len2);
|
line->s[len1] = ' ';
|
||||||
line->s[len1+len2+1] = 0;
|
memcpy(line->s+len1+spc, s, len2);
|
||||||
|
line->s[len1+len2+spc] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
struct line {
|
struct line {
|
||||||
char *s;
|
char *s;
|
||||||
|
int url; /* 1 if URL */
|
||||||
struct line *next;
|
struct line *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user