Home
       sacc-onionmarks.patch - onion-completion - bash-tab-completion for onion adresses
  HTML git clone git://kroovy.de/onion-completion
   DIR Log
   DIR Files
   DIR Refs
   DIR README
       ---
       sacc-onionmarks.patch (3195B)
       ---
            1 From d2cbbc988dff27fc57b51d6239843d937311765a Mon Sep 17 00:00:00 2001
            2 From: kroovy <me@kroovy.de>
            3 Date: Sat, 23 Sep 2017 12:22:47 +0200
            4 Subject: [PATCH] implement onion-bookmarks
            5 
            6 ---
            7  config.def.h |  4 ++++
            8  config.mk    |  6 +++---
            9  ui_ti.c      | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
           10  3 files changed, 57 insertions(+), 3 deletions(-)
           11 
           12 diff --git a/config.def.h b/config.def.h
           13 index c44147d..6b9344c 100644
           14 --- a/config.def.h
           15 +++ b/config.def.h
           16 @@ -12,6 +12,7 @@
           17  #define _key_pgnext        'l' /* view highlighted item */
           18  #define _key_pgprev        'h' /* view previous item */
           19  #define _key_uri        'u' /* print item uri */
           20 +#define _key_onionBM        'o' /* bookmark current onion-uri */
           21  #define _key_fetch        'L' /* refetch current item */
           22  #define _key_help        '?' /* display help */
           23  #define _key_quit        'q' /* exit sacc */
           24 @@ -21,3 +22,6 @@ static char *plumber = "xdg-open";
           25  
           26  /* temporary directory */
           27  static char *tmpdir = "/tmp/sacc";
           28 +
           29 +/* onion bookmark file */
           30 +static char *onion_bookmarks = "/home/kroovy/.onion-bookmarks";
           31 diff --git a/config.mk b/config.mk
           32 index c6fe28d..4015519 100644
           33 --- a/config.mk
           34 +++ b/config.mk
           35 @@ -3,10 +3,10 @@ PREFIX = /usr/local
           36  
           37  # UI type
           38  # txt (textual)
           39 -UI=txt
           40 +#UI=txt
           41  # ti (screen-oriented)
           42 -#UI=ti
           43 -#UIFLAGS=-lcurses
           44 +UI=ti
           45 +UIFLAGS=-lcurses
           46  
           47  # Stock FLAGS
           48  SACCCFLAGS = -D_DEFAULT_SOURCE $(CFLAGS)
           49 diff --git a/ui_ti.c b/ui_ti.c
           50 index 09f5127..22e2a10 100644
           51 --- a/ui_ti.c
           52 +++ b/ui_ti.c
           53 @@ -109,6 +109,7 @@ help(Item *entry)
           54                         "Right, " S(_key_pgnext) ": view highlighted item.\n"
           55                         "Left, " S(_key_pgprev) ": view previous item.\n"
           56                         S(_key_uri) ": print item uri.\n"
           57 +                       S(_key_onionBM) ": bookmark current onion-uri.\n"
           58                         S(_key_help) ": show this help.\n"
           59                         "^D, " S(_key_quit) ": exit sacc.\n"
           60          };
           61 @@ -200,6 +201,52 @@ displayuri(Item *item)
           62          fflush(stdout);
           63  }
           64  
           65 +static void
           66 +onionBM(Item *item)
           67 +{
           68 +        char buf[64], *line;
           69 +        int i, n, contains = 0, onion = 0;
           70 +        FILE *f;
           71 +        
           72 +        putp(tparm(save_cursor));
           73 +        putp(tparm(cursor_address, lines-1, 0));
           74 +        putp(tparm(enter_standout_mode));
           75 +        
           76 +        f = fopen(onion_bookmarks, "ra+");
           77 +        
           78 +        if (f == NULL) {
           79 +                printf("Error opening %s", onion_bookmarks);
           80 +                putp(tparm(exit_standout_mode));
           81 +                putp(tparm(restore_cursor));
           82 +                fflush(stdout);
           83 +                return;
           84 +        }
           85 +        
           86 +        if (strstr(item->host, ".onion") != NULL)
           87 +                onion = 1;
           88 +        
           89 +        for (i = 0; (line = fgets(buf, sizeof(buf), f)) != NULL; i++) {
           90 +                line[strlen(line)-1] = '\0';
           91 +                if (strcmp(line, item->host) == 0)
           92 +                        contains = 1;
           93 +        }
           94 +        
           95 +        if (!onion) {
           96 +                n = printf("Not an onion-uri!");
           97 +        } else if (contains) {
           98 +                n = printf("Onion-uri is already stored");
           99 +        } else {
          100 +                fprintf(f, "%s\n", item->host);
          101 +                n = printf("Onion-uri successfully stored");
          102 +        }
          103 +        
          104 +        fclose(f);
          105 +        putp(tparm(exit_standout_mode));
          106 +        printf("%*s", columns-n, " ");
          107 +        putp(tparm(restore_cursor));
          108 +        fflush(stdout);
          109 +}
          110 +
          111  void
          112  uidisplay(Item *entry)
          113  {
          114 @@ -454,6 +501,9 @@ uiselectitem(Item *entry)
          115                          if (dir)
          116                                  displayuri(&dir->items[dir->curline]);
          117                          continue;
          118 +                case _key_onionBM:
          119 +                                onionBM(&dir->items[dir->curline]);
          120 +                        continue;
          121                  case _key_help: /* FALLTHROUGH */
          122                          return help(entry);
          123                  default:
          124 -- 
          125 2.12.2
          126