Advertisement
Guest User

Untitled

a guest
May 24th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 3.21 KB | None | 0 0
  1. Only in dmenu-4.0/: dmenu
  2. diff -u dmenu.old/dmenu-4.0/dmenu.c dmenu-4.0/dmenu.c
  3. --- dmenu.old/dmenu-4.0/dmenu.c 2009-04-18 12:50:04.000000000 +0100
  4. +++ dmenu-4.0/dmenu.c   2010-05-11 11:27:36.530236498 +0100
  5. @@ -89,6 +89,9 @@
  6.  static int (*fstrncmp)(const char *, const char *, size_t n) = strncmp;
  7.  static char *(*fstrstr)(const char *, const char *) = strstr;
  8.  
  9. +static char* menuoncommandline = 0;
  10. +static char* menudeliminator = "\n";
  11. +
  12.  void
  13.  appenditem(Item *i, Item **list, Item **last) {
  14.     if(!(*last))
  15. @@ -160,10 +163,12 @@
  16.         free(allitems);
  17.         allitems = itm;
  18.     }
  19. -   if(dc.font.set)
  20. +   if(dc.font.set) {
  21.         XFreeFontSet(dpy, dc.font.set);
  22. -   else
  23. +   }
  24. +   else {
  25.         XFreeFont(dpy, dc.font.xfont);
  26. +   }
  27.     XFreePixmap(dpy, dc.drawable);
  28.     XFreeGC(dpy, dc.gc);
  29.     XDestroyWindow(dpy, win);
  30. @@ -663,6 +668,33 @@
  31.     return textnw(text, strlen(text)) + dc.font.height;
  32.  }
  33.  
  34. +void
  35. +commandlinemenu(const char *menu_p, const char* deliminator) {
  36. +   Item *it, *new;
  37. +   char* m_item = NULL;
  38. +   char* menu = strdup(menu_p);
  39. +
  40. +   it = NULL;
  41. +  
  42. +   if (menu == NULL)  eprint("Failed to malloc \"menu\"");
  43. +
  44. +   for (m_item = strtok(menu, deliminator); m_item; m_item = strtok(NULL, deliminator)){
  45. +       if(!(new = (Item *)malloc(sizeof(Item))))
  46. +           eprint("fatal: could not mall   oc() %u bytes\n", sizeof(Item));
  47. +       new->next = new->left = new->right = NULL;
  48. +       new->text = strdup(m_item);
  49. +       if (menu == NULL)  eprint("Failed to malloc \"new->text\"");
  50. +      
  51. +       if(!it)
  52. +           allitems = new;
  53. +       else
  54. +           it->next = new;
  55. +       it = new;
  56. +   }  
  57. +  
  58. +   free (menu);
  59. +}
  60. +
  61.  int
  62.  main(int argc, char *argv[]) {
  63.     unsigned int i;
  64. @@ -693,26 +725,41 @@
  65.         }
  66.         else if(!strcmp(argv[i], "-sf")) {
  67.             if(++i < argc) selfgcolor = argv[i];
  68. -       }
  69. -       else if(!strcmp(argv[i], "-v"))
  70. +       } else if (!strcmp(argv[i], "-m")) {
  71. +           if (++i < argc) menuoncommandline = argv[i];
  72. +           else eprint("-m missing paramiter\n");
  73. +       } else if (!strcmp(argv[i], "-d")) {
  74. +           if (++i < argc) menudeliminator = argv[i];
  75. +           else eprint("-d missing paramiter\n");
  76. +       } else if(!strcmp(argv[i], "-v"))
  77.             eprint("dmenu-"VERSION", © 2006-2008 dmenu engineers, see LICENSE for details\n");
  78.         else
  79.             eprint("usage: dmenu [-i] [-b] [-fn <font>] [-nb <color>] [-nf <color>]\n"
  80. -                  "             [-p <prompt>] [-sb <color>] [-sf <color>] [-v]\n");
  81. +                  "             [-p <prompt>] [-sb <color>] [-sf <color>] [-v]\n"
  82. +                  "             [-m <menu>] [-d <deliminator>]\n");
  83.     if(!setlocale(LC_CTYPE, "") || !XSupportsLocale())
  84.         fprintf(stderr, "warning: no locale support\n");
  85.     if(!(dpy = XOpenDisplay(NULL)))
  86.         eprint("dmenu: cannot open display\n");
  87.     screen = DefaultScreen(dpy);
  88.     root = RootWindow(dpy, screen);
  89. +  
  90. +   if (menuoncommandline) {
  91. +       commandlinemenu(menuoncommandline, menudeliminator);
  92. +   }
  93.  
  94.     if(isatty(STDIN_FILENO)) {
  95. -       readstdin();
  96. +       if (menuoncommandline == NULL) {
  97. +           readstdin();
  98. +       }
  99.         running = grabkeyboard();
  100.     }
  101. -   else { /* prevent keypress loss */
  102. +   else { /* prevent keypress loss */     
  103.         running = grabkeyboard();
  104. -       readstdin();
  105. +      
  106. +       if (menuoncommandline == NULL) {
  107. +           readstdin();
  108. +       }
  109.     }
  110.  
  111.     setup(topbar);
  112. Only in dmenu-4.0/: dmenuCommandLine.diff
  113. Only in dmenu-4.0/: dmenu.o
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement