...
|
...
|
@@ -31,6 +31,8 @@
|
31
|
31
|
#define SELECTBUFBLOCK 16384
|
32
|
32
|
#define SIZEBLOCKPRINTS 32
|
33
|
33
|
|
|
34
|
+#define VIEWONLYPROGNAME "review"
|
|
35
|
+
|
34
|
36
|
#define COMMAND_WARNING "(!)"
|
35
|
37
|
#define COMMAND_INFO "(i)"
|
36
|
38
|
#define COMMAND_GOTOLINE "Go to line:"
|
...
|
...
|
@@ -68,6 +70,7 @@ typedef struct print_t {
|
68
|
70
|
typedef struct re_t {
|
69
|
71
|
redata_t *data;
|
70
|
72
|
reui_t *ui;
|
|
73
|
+ int viewonly;
|
71
|
74
|
int flag_newfile;
|
72
|
75
|
char filename[PATH_MAX];
|
73
|
76
|
int x, y, w, h; // contents rect
|
...
|
...
|
@@ -149,7 +152,7 @@ main(int argc, char *argv[])
|
149
|
152
|
int flag_had_events;
|
150
|
153
|
time_t lastidle,now;
|
151
|
154
|
int load_pending;
|
152
|
|
- int i;
|
|
155
|
+ int i,l;
|
153
|
156
|
if(argc!=2 || strcmp(argv[argc-1],"--help")==0) {
|
154
|
157
|
fprintf(stderr,"Syntax: %s filename\n",argv[0]);
|
155
|
158
|
return(1);
|
...
|
...
|
@@ -158,6 +161,8 @@ main(int argc, char *argv[])
|
158
|
161
|
fprintf(stderr,"ERROR: couldn't init structs.\n");
|
159
|
162
|
return(2);
|
160
|
163
|
}
|
|
164
|
+ if((i=strlen(argv[0]))>=(l=strlen(VIEWONLYPROGNAME)) && strcmp(argv[0]+i-l,VIEWONLYPROGNAME)==0)
|
|
165
|
+ re->viewonly=1;
|
161
|
166
|
if((ssel=sselect_init())==NULL) {
|
162
|
167
|
fprintf(stderr,"ERROR: couln't init internal data.\n");
|
163
|
168
|
re_free(re),re=NULL;
|
...
|
...
|
@@ -323,6 +328,28 @@ fprintf(stderr,"RENDER\n");
|
323
|
328
|
case SDL_KEYDOWN:
|
324
|
329
|
case SDL_TEXTINPUT:
|
325
|
330
|
case SDL_TEXTEDITING:
|
|
331
|
+ if(re->viewonly && (event.type==SDL_TEXTINPUT || event.type==SDL_TEXTEDITING))
|
|
332
|
+ break;
|
|
333
|
+ if(re->viewonly && event.type==SDL_KEYDOWN) {
|
|
334
|
+ if(event.key.keysym.sym==SDLK_ESCAPE) {
|
|
335
|
+ do_exit=1;
|
|
336
|
+ } if(event.key.keysym.sym==SDLK_DOWN || event.key.keysym.sym==SDLK_UP) {
|
|
337
|
+ if(event.key.keysym.sym==SDLK_UP && re->originline==0)
|
|
338
|
+ break; /* nothing to do, at top */
|
|
339
|
+ re->originline+=((event.key.keysym.sym==SDLK_UP)?-1:1);
|
|
340
|
+ re->curline+=((event.key.keysym.sym==SDLK_UP)?-1:1);
|
|
341
|
+ re->headerdirty=1;
|
|
342
|
+ re->contentsdirty=1;
|
|
343
|
+ } else if(event.key.keysym.sym==SDLK_LEFT || event.key.keysym.sym==SDLK_RIGHT) {
|
|
344
|
+ if(event.key.keysym.sym==SDLK_LEFT && re->origincol==0)
|
|
345
|
+ break; /* nothing to do, at top */
|
|
346
|
+ re->origincol+=((event.key.keysym.sym==SDLK_LEFT)?-1:1)*8;
|
|
347
|
+ re->origincol=(re->origincol<0)?0:re->origincol;
|
|
348
|
+ re->headerdirty=1;
|
|
349
|
+ re->contentsdirty=1;
|
|
350
|
+ }
|
|
351
|
+ break;
|
|
352
|
+ }
|
326
|
353
|
if(re->command==NULL || strcmp(re->command,COMMAND_WARNING)==0 || strcmp(re->command,COMMAND_INFO)==0)
|
327
|
354
|
re_processkey_editing(re,&event);
|
328
|
355
|
else if(re->command[0]=='\0')
|
...
|
...
|
@@ -708,7 +735,7 @@ fprintf(stderr,"SDL_KEYDOWN: sym:%i\n",event->key.keysym.sym);
|
708
|
735
|
re->contentsdirty=1;
|
709
|
736
|
}
|
710
|
737
|
}
|
711
|
|
- } else if(event->key.keysym.sym==SDLK_LEFT || event->key.keysym.sym==SDLK_RIGHT) {
|
|
738
|
+ } else if((event->key.keysym.sym==SDLK_LEFT || event->key.keysym.sym==SDLK_RIGHT)) {
|
712
|
739
|
int oldcol=re->curcol,oldline=re->curline;
|
713
|
740
|
if(re_moveleftright(re,(event->key.keysym.sym==SDLK_LEFT)?-1:1)==0 && (SDL_GetModState()&KMOD_SHIFT)!=0 && (re->curcol!=oldcol || re->curline!=oldline)) {
|
714
|
741
|
re_sel_resize(re,oldcol,oldline,(event->key.keysym.sym==SDLK_LEFT)?-1:1);
|
...
|
...
|
@@ -1829,6 +1856,7 @@ re_drawcontents(re_t *re, printout_t *printout)
|
1829
|
1856
|
char matchingchar;
|
1830
|
1857
|
int mline,mcol;
|
1831
|
1858
|
long cursorpos;
|
|
1859
|
+ printout_t fakeprintout;
|
1832
|
1860
|
const char *hint;
|
1833
|
1861
|
const char selcolornormal[]={"\xde\xcf\x7f\xff"};
|
1834
|
1862
|
const char selcolorcurline[]={"\xf0\xea\xc9\xff"};
|
...
|
...
|
@@ -1846,7 +1874,14 @@ re_drawcontents(re_t *re, printout_t *printout)
|
1846
|
1874
|
curcol=re->curcol;
|
1847
|
1875
|
maxcol=re->maxcol;
|
1848
|
1876
|
maxrow=re->maxrow;
|
1849
|
|
- if(printout!=NULL) {
|
|
1877
|
+ if(printout==NULL && re->viewonly==1) {
|
|
1878
|
+ memset(&fakeprintout,0,sizeof(printout_t));
|
|
1879
|
+ fakeprintout.ui=re->ui;
|
|
1880
|
+ fakeprintout.data=re->data;
|
|
1881
|
+ fakeprintout.originline=re->originline;
|
|
1882
|
+ fakeprintout.origincol=re->origincol;
|
|
1883
|
+ printout=&fakeprintout;
|
|
1884
|
+ } else if(printout!=NULL) {
|
1850
|
1885
|
ui=printout->ui;
|
1851
|
1886
|
data=printout->data;
|
1852
|
1887
|
x0=0;
|
...
|
...
|
@@ -2002,7 +2037,7 @@ re_drawcontents(re_t *re, printout_t *printout)
|
2002
|
2037
|
}
|
2003
|
2038
|
}
|
2004
|
2039
|
/* all done */
|
2005
|
|
- if(printout==NULL) {
|
|
2040
|
+ if(printout==NULL || printout==&fakeprintout) {
|
2006
|
2041
|
re->contentsdirty=0;
|
2007
|
2042
|
ui->rendererdirty=1;
|
2008
|
2043
|
} else {
|