fbpdf: add 'o' command and -o option for specifying the first page
authorAli Gholami Rudi <ali@rudi.ir>
Mon, 8 Apr 2013 16:47:32 +0000 (8 21:17 +0430)
committerAli Gholami Rudi <ali@rudi.ir>
Mon, 8 Apr 2013 16:47:32 +0000 (8 21:17 +0430)
For pdf files that start with roman numbers, the first page can be
adjusted with this command so that G command matches page numbers.
Note that all other commands, such as jumping to a mark and going to
the previous page, work as before.

README
fbpdf.c

diff --git a/README b/README
index 06fb8e8..332b124 100644 (file)
--- a/README
+++ b/README
@@ -10,7 +10,7 @@ can compile it using "make fbpdf".  See the Makefile for other
 targets.  The following options can be specified when starting
 fbpdf (or fbdjvu and fbpdf2):
 
-  fbpdf [-r rotation] [-z zoom x10] [-p page] filename
+  fbpdf [-r rotation] [-z zoom x10] [-p page] [-o first page] filename
 
 KEYS
 ====
@@ -26,6 +26,7 @@ KEY           ACTION
 ^F/J           next page
 ^B/K           previous page
 G              goto page (goto the last page if no prefix)
+o              set first page ('5G' after '3o' goes to page 8)
 z              set zoom multiplied by 10 (i.e. '15z' = 150%)
 r              set rotation in degrees
 i              print info
diff --git a/fbpdf.c b/fbpdf.c
index db256df..3adf31e 100644 (file)
--- a/fbpdf.c
+++ b/fbpdf.c
@@ -41,6 +41,7 @@ static int rotate;
 static int head;
 static int left;
 static int count;
+static int first;              /* first_page - 1 */
 
 static void draw(void)
 {
@@ -194,7 +195,7 @@ static void mainloop(void)
                        break;
                case 'G':
                        setmark('\'');
-                       showpage(getcount(doc_pages(doc)), 0);
+                       showpage(getcount(doc_pages(doc) - first) + first, 0);
                        break;
                case 'z':
                        zoom_page(getcount(15));
@@ -233,6 +234,9 @@ static void mainloop(void)
                case '\'':
                        jmpmark(readkey(), c == '`');
                        break;
+               case 'o':
+                       first = getcount(1) - 1;
+                       break;
                default:
                        if (isdigit(c))
                                count = count * 10 + c - '0';
@@ -292,7 +296,7 @@ static void mainloop(void)
 }
 
 static char *usage =
-       "usage: fbpdf [-r rotation] [-z zoom x10] [-p page] filename\n";
+       "usage: fbpdf [-r rotation] [-z zoom x10] [-p page] [-o first page] filename\n";
 
 int main(int argc, char *argv[])
 {
@@ -307,14 +311,21 @@ int main(int argc, char *argv[])
                fprintf(stderr, "cannot open <%s>\n", filename);
                return 1;
        }
-       while (i + 2 < argc && argv[i][0] == '-') {
-               if (argv[i][1] == 'r')
-                       rotate = atoi(argv[i + 1]);
-               if (argv[i][1] == 'z')
-                       zoom = atoi(argv[i + 1]);
-               if (argv[i][1] == 'p')
-                       num = atoi(argv[i + 1]);
-               i += 2;
+       for (i = 1; i < argc && argv[i][0] == '-'; i++) {
+               switch (argv[i][1]) {
+               case 'r':
+                       rotate = atoi(argv[i][2] ? argv[i] + 2 : argv[++i]);
+                       break;
+               case 'z':
+                       zoom = atoi(argv[i][2] ? argv[i] + 2 : argv[++i]);
+                       break;
+               case 'p':
+                       num = atoi(argv[i][2] ? argv[i] + 2 : argv[++i]);
+                       break;
+               case 'o':
+                       first = atoi(argv[i][2] ? argv[i] + 2 : argv[++i]) - 1;
+                       break;
+               }
        }
        printf("\x1b[?25l");            /* hide the cursor */
        printf("\x1b[2J");              /* clear the screen */