viwmfs.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * viwmfs.c
  3. * Copyright © 2008, 2009 Martin Duquesnoy <xorg62@gmail.com>
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are
  8. * met:
  9. *
  10. * * Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * * Redistributions in binary form must reproduce the above
  13. * copyright notice, this list of conditions and the following disclaimer
  14. * in the documentation and/or other materials provided with the
  15. * distribution.
  16. * * Neither the name of the nor the names of its
  17. * contributors may be used to endorse or promote products derived from
  18. * this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. #include "wmfs.h"
  33. vicmd_to_uicb vicmd[] =
  34. {
  35. {"r", "reload"},
  36. {"q", "quit"},
  37. {"t", "tag"},
  38. {"tn", "tag_next"},
  39. {"tp", "tag_prev"},
  40. {"ln", "layout_next"},
  41. {"lp", "layout_prev"},
  42. {"s", "screen_select"},
  43. {"screen", "screen_select"},
  44. {"sn", "screen_next"},
  45. {"sp", "screen_prev"},
  46. {"cc", "client_kill"},
  47. {"ct", "tag_transfert"},
  48. {"client_transfert", "tag_transfert"},
  49. {"cn", "client_next"},
  50. {"cp", "client_prev"},
  51. {"csn", "client_swap_next"},
  52. {"csp", "client_swap_prev"},
  53. {"tm", "toggle_max"},
  54. {"tf", "toggle_free"},
  55. };
  56. void
  57. viwmfs_help(void)
  58. {
  59. printf("ViWMFS commands list:\n");
  60. return;
  61. }
  62. void
  63. viwmfs(int argc, char **argv)
  64. {
  65. int i;
  66. char *cmd, str[256] = { 0 };
  67. Bool e;
  68. if(!argc)
  69. return;
  70. if(argc > 3)
  71. {
  72. for(i = 2; i < argc; ++i)
  73. {
  74. strcat(str, argv[i]);
  75. if(*(str + strlen(str) - 1) != ':')
  76. strcat(str, " ");
  77. }
  78. }
  79. else
  80. strcpy(str, argv[2]);
  81. if(*str == ':')
  82. {
  83. for(i = 0; i < strlen(str); str[i] = str[i + 1], ++i);
  84. cmd = _strdup(str);
  85. for(i = 0; cmd[i] && cmd[i] != ' '; ++i);
  86. cmd[i] = '\0';
  87. for(i = 0; i < LEN(vicmd); ++i)
  88. if(!strncmp(cmd, vicmd[i].cmd, strlen(cmd)))
  89. {
  90. exec_uicb_function(vicmd[i].uicb, str + strlen(cmd));
  91. e = True;
  92. break;
  93. }
  94. /* For uicb function with normal name specified */
  95. if(!e)
  96. exec_uicb_function(cmd, str + strlen(cmd));
  97. }
  98. return;
  99. }