... | ... |
@@ -22,13 +22,6 @@ |
22 | 22 |
#define PLUGINNAME "prototypes" |
23 | 23 |
#define MAXINDEXDATALEN 1024 |
24 | 24 |
|
25 |
-typedef enum protolang_t { |
|
26 |
- protolang_undefined=-1, |
|
27 |
- protolang_c=0, |
|
28 |
- protolang_tcl, |
|
29 |
- protolang_end, |
|
30 |
-} protolang_t; |
|
31 |
- |
|
32 | 25 |
typedef struct protoindex_t { |
33 | 26 |
int nentries; |
34 | 27 |
const char **index; |
... | ... |
@@ -232,16 +225,8 @@ redata_prototypes_get(redata_t *redata, long pos) |
232 | 225 |
} status; |
233 | 226 |
if(redata==NULL || pos<0 || (cproto=cproto_getplugin(redata))==NULL) |
234 | 227 |
return(NULL); /* sanity check failed */ |
235 |
- if(cproto->lastprotolang==protolang_undefined) { |
|
236 |
- char linebuf[1024]; |
|
237 |
- if(redata_line_getstartstr(redata,0,linebuf,sizeof(linebuf))!=0) |
|
238 |
- return(NULL); /* couldn't detect file type using first line */ |
|
239 |
- if(linebuf[0]=='#' && (mystrstr(linebuf,"tclsh")!=NULL || mystrstr(linebuf,"wish")!=NULL || mystrstr(linebuf,"expect")!=NULL)) |
|
240 |
- cproto->lastprotolang=protolang_tcl; |
|
241 |
- else |
|
242 |
- cproto->lastprotolang=protolang_c; |
|
243 |
- cproto->lastpos=-1; |
|
244 |
- } |
|
228 |
+ if(cproto->lastprotolang==protolang_undefined) |
|
229 |
+ redata_prototypes_detectlang(redata); |
|
245 | 230 |
protoindex=cproto->protoindexes+cproto->lastprotolang; |
246 | 231 |
if(pos==cproto->lastpos) |
247 | 232 |
return((cproto->lastindex!=-1)?(protoindex->values[cproto->lastindex]):NULL); |
... | ... |
@@ -339,8 +324,22 @@ redata_prototypes_get(redata_t *redata, long pos) |
339 | 324 |
return(NULL); |
340 | 325 |
} |
341 | 326 |
|
342 |
- |
|
343 |
- |
|
327 |
+protolang_t |
|
328 |
+redata_prototypes_detectlang(redata_t *redata) |
|
329 |
+{ |
|
330 |
+ cproto_t *cproto; |
|
331 |
+ char linebuf[1024]; |
|
332 |
+ if(redata==NULL || (cproto=cproto_getplugin(redata))==NULL) |
|
333 |
+ return(protolang_undefined); /* sanity check failed */ |
|
334 |
+ if(redata_line_getstartstr(redata,0,linebuf,sizeof(linebuf))!=0) |
|
335 |
+ return(protolang_undefined); /* couldn't detect file type using first line */ |
|
336 |
+ if(linebuf[0]=='#' && (mystrstr(linebuf,"tclsh")!=NULL || mystrstr(linebuf,"wish")!=NULL || mystrstr(linebuf,"expect")!=NULL)) |
|
337 |
+ cproto->lastprotolang=protolang_tcl; |
|
338 |
+ else |
|
339 |
+ cproto->lastprotolang=protolang_c; |
|
340 |
+ cproto->lastpos=-1; |
|
341 |
+ return(cproto->lastprotolang); |
|
342 |
+} |
|
344 | 343 |
|
345 | 344 |
static int |
346 | 345 |
cproto_buffer_inv(cproto_t *cproto) |
... | ... |
@@ -11,8 +11,19 @@ |
11 | 11 |
* This program is licensed under the terms of GNU GPL v2.1+ |
12 | 12 |
*/ |
13 | 13 |
|
14 |
+#ifndef RE_PLUGIN_PROTOTYPES_H |
|
15 |
+#define RE_PLUGIN_PROTOTYPES_H |
|
16 |
+typedef enum protolang_t { |
|
17 |
+ protolang_undefined=-1, |
|
18 |
+ protolang_c=0, |
|
19 |
+ protolang_tcl, |
|
20 |
+ protolang_end, |
|
21 |
+} protolang_t; |
|
14 | 22 |
|
15 | 23 |
int redata_prototypes_register(redata_t *redata, redata_plugin_t *slot); |
16 | 24 |
int redata_prototypes_unregister(redata_t *redata, redata_plugin_t *slot,char *filename); |
17 | 25 |
|
18 | 26 |
const char *redata_prototypes_get(redata_t *redata, long pos); |
27 |
+ |
|
28 |
+protolang_t redata_prototypes_detectlang(redata_t *redata); |
|
29 |
+#endif |
... | ... |
@@ -150,7 +150,8 @@ typedef enum typeprintout_t { |
150 | 150 |
printoutView=0, |
151 | 151 |
printoutCopy, |
152 | 152 |
printoutHelp, |
153 |
- printoutManpage |
|
153 |
+ printoutManpage, |
|
154 |
+ printoutManpageCurlang, |
|
154 | 155 |
} typeprintout_t; |
155 | 156 |
|
156 | 157 |
typedef struct printout_t { |
... | ... |
@@ -540,7 +541,9 @@ fprintf(stderr,"RENDER\n"); |
540 | 541 |
case SDL_MOUSEMOTION: |
541 | 542 |
if(!(event.type==SDL_MOUSEMOTION && re->mouseselactive==0) |
542 | 543 |
&& printout->type!=printoutHelp |
543 |
- && printout->type!=printoutManpage) { |
|
544 |
+ && printout->type!=printoutManpage |
|
545 |
+ && printout->type!=printoutManpageCurlang |
|
546 |
+ ) { |
|
544 | 547 |
int mx,my; |
545 | 548 |
int newposx,newposy; |
546 | 549 |
long tmppos; |
... | ... |
@@ -1369,6 +1372,8 @@ fprintf(stderr,"SDL_KEYDOWN: BACKSPACE%s\n",(event==&fakeevent)?" (fake)":""); |
1369 | 1372 |
re_addprint(re,printoutHelp); |
1370 | 1373 |
} else if(event->key.keysym.sym==SDLK_F1 && (SDL_GetModState()&KMOD_CTRL)!=0 && (SDL_GetModState()&(KMOD_SHIFT|KMOD_ALT))==0 ) { |
1371 | 1374 |
re_addprint(re,printoutManpage); |
1375 |
+ } else if(event->key.keysym.sym==SDLK_F1 && (SDL_GetModState()&KMOD_CTRL)!=0 && (SDL_GetModState()&KMOD_SHIFT)!=0 && (SDL_GetModState()&KMOD_ALT)==0) { |
|
1376 |
+ re_addprint(re,printoutManpageCurlang); |
|
1372 | 1377 |
} else if(event->key.keysym.sym==SDLK_F2 || (event->key.keysym.sym==SDLK_s && (SDL_GetModState()&KMOD_CTRL)!=0)) { |
1373 | 1378 |
char *errormsg=NULL; |
1374 | 1379 |
if(redata_save(re->data,re->filename,&errormsg)!=-1) |
... | ... |
@@ -2360,7 +2365,7 @@ Printout window\n\ |
2360 | 2365 |
redata_op_add(re->prints[i].data,0,helptext,sizeof(helptext)-1,NULL); |
2361 | 2366 |
re->contentsdirty=1; |
2362 | 2367 |
} |
2363 |
- } else if(typeprintout==printoutManpage) { |
|
2368 |
+ } else if(typeprintout==printoutManpage || typeprintout==printoutManpageCurlang) { |
|
2364 | 2369 |
char searchbuf[1024]; /* magic number: max. size of string to search (truncated if bigger) */ |
2365 | 2370 |
char title[256]; |
2366 | 2371 |
int lenprefix; |
... | ... |
@@ -2368,7 +2373,11 @@ Printout window\n\ |
2368 | 2373 |
long tmppos; |
2369 | 2374 |
int nread; |
2370 | 2375 |
FILE *fp; |
2371 |
- strncpy(searchbuf,"man ",sizeof(searchbuf)); |
|
2376 |
+ protolang_t curlang; |
|
2377 |
+ curlang=redata_prototypes_detectlang(re->data); |
|
2378 |
+ strncpy(searchbuf,(typeprintout==printoutManpageCurlang && curlang==protolang_c)?"man 2 " |
|
2379 |
+ :(typeprintout==printoutManpageCurlang && curlang==protolang_tcl)?"man 3tcl " |
|
2380 |
+ :"man ",sizeof(searchbuf)); |
|
2372 | 2381 |
searchbuf[sizeof(searchbuf)-1]='\0'; |
2373 | 2382 |
lenprefix=strlen(searchbuf); |
2374 | 2383 |
fp=NULL; |
... | ... |
@@ -2699,6 +2708,7 @@ re_drawcontents(re_t *re, printout_t *printout) |
2699 | 2708 |
flaglineno=(printout==NULL)?re->showlinenumbers: |
2700 | 2709 |
(printout->type==printoutHelp)?0: |
2701 | 2710 |
(printout->type==printoutManpage)?0: |
2711 |
+ (printout->type==printoutManpageCurlang)?0: |
|
2702 | 2712 |
1; |
2703 | 2713 |
linenosize=linenowidth=0; |
2704 | 2714 |
if(printout==NULL && re->viewonly==1) { |
... | ... |
@@ -2731,7 +2741,7 @@ re_drawcontents(re_t *re, printout_t *printout) |
2731 | 2741 |
} |
2732 | 2742 |
if(redata_linecol2pos(data,curline,curcol,&cursorpos,NULL)!=0) |
2733 | 2743 |
return(0); /* error obtaining position */ |
2734 |
- bgcolor=(printout!=NULL && (printout->type==printoutHelp || printout->type==printoutManpage)) |
|
2744 |
+ bgcolor=(printout!=NULL && (printout->type==printoutHelp || printout->type==printoutManpage || printout->type==printoutManpageCurlang )) |
|
2735 | 2745 |
?COLOR_PRINTOUTSTRIPE(re) |
2736 | 2746 |
:COLOR_BACKGROUND(re); |
2737 | 2747 |
reui_fill(ui,x0-linenowidth,y0,w,h,bgcolor); |
... | ... |
@@ -2748,7 +2758,7 @@ re_drawcontents(re_t *re, printout_t *printout) |
2748 | 2758 |
/* highlight current line (in printouts, highlight alternating lines) */ |
2749 | 2759 |
if(printout==NULL) { |
2750 | 2760 |
reui_fill(ui,x0-linenowidth,y0+(curline-originline)*ui->fontheight,w,ui->fontheight+1,COLOR_PRINTOUTSTRIPE(re)); |
2751 |
- } else if(printout!=NULL && (printout->type==printoutHelp || printout->type==printoutManpage)) { |
|
2761 |
+ } else if(printout!=NULL && (printout->type==printoutHelp || printout->type==printoutManpage || printout->type==printoutManpageCurlang)) { |
|
2752 | 2762 |
; /* help bgcolor already filled */ |
2753 | 2763 |
} else { |
2754 | 2764 |
for(y=y0+((printout->data==NULL)?1:(printout->originline%2))*ui->fontheight;y<(y0+h);y+=ui->fontheight*2) |