1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-04 22:58:26 +02:00

genkicat/: detect URLs in comments and add PDF hyperlink

We recognize http, https, ftp, and file.
This commit is contained in:
Werner Almesberger 2012-07-14 21:51:28 -03:00
parent 4811fb3d3d
commit 993ea811e5
3 changed files with 37 additions and 5 deletions

View File

@ -254,10 +254,25 @@ static void print_comment(FILE *file, const struct line *comment)
n = 0;
for (line = comment; line; line = line->next) {
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);
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);
fprintf(file, " show\n");
}
fprintf(file, "grestore\n");
}

View File

@ -118,10 +118,24 @@ static struct node *find_comp(struct node *node, const char *name)
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;
line = alloc_type(struct line);
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;
return line;
}
@ -130,17 +144,19 @@ static struct line *new_line(char *s)
static void append_line(struct line *line, char *s)
{
int len1, len2;
int spc = !line->url;
len1 = strlen(line->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) {
perror("realloc");
exit(1);
}
line->s[len1] = ' ';
memcpy(line->s+len1+1, s, len2);
line->s[len1+len2+1] = 0;
if (spc)
line->s[len1] = ' ';
memcpy(line->s+len1+spc, s, len2);
line->s[len1+len2+spc] = 0;
}

View File

@ -17,6 +17,7 @@
struct line {
char *s;
int url; /* 1 if URL */
struct line *next;
};