misc.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $XConsortium: misc.c /main/5 1996/10/04 16:21:08 drk $ */
  24. /* Copyright (c) 1991, 1992 UNIX System Laboratories, Inc. */
  25. /* All Rights Reserved */
  26. /* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF */
  27. /* UNIX System Laboratories, Inc. */
  28. /* The copyright notice above does not evidence any */
  29. /* actual or intended publication of such source code. */
  30. #include "name.h"
  31. #include "shell.h"
  32. #include "stdio.h"
  33. #include <X11/X.h>
  34. #include <X11/Intrinsic.h>
  35. #include <X11/IntrinsicP.h>
  36. #define NO_AST
  37. #include "dtksh.h"
  38. #undef NO_AST
  39. #include "exksh.h" /* which includes sys/types.h */
  40. /* #include <sys/param.h> */
  41. #include <string.h>
  42. /* #include <search.h> */
  43. #include <ctype.h>
  44. #include "docall.h"
  45. #include "msgs.h"
  46. static char use[] = "0x%lx";
  47. int
  48. symcomp(
  49. void *sym1,
  50. void *sym2 )
  51. {
  52. return(strcmp(((struct symarray *) sym1)->str, ((struct symarray *) sym2)->str));
  53. }
  54. void *
  55. getaddr(
  56. char *str )
  57. {
  58. if (isdigit(str[0]))
  59. return((void *) strtoul(str, NULL, 0));
  60. else
  61. return((void *) fsym(str, -1));
  62. }
  63. int
  64. do_deref(
  65. int argc,
  66. char **argv )
  67. {
  68. unsigned char *ptr;
  69. long i, len = 0;
  70. short longwise = -1;
  71. char printit = 0;
  72. static char xk_ret_buffer[1024];
  73. char * errmsg;
  74. for (i = 1; (i < argc) && argv[i] != NULL && argv[i][0] == '-'; i++) {
  75. if (isdigit(argv[i][1])) {
  76. if (longwise < 0)
  77. longwise = 0;
  78. ptr = (unsigned char *) argv[i] + 1;
  79. xk_par_int(&ptr, &len, NULL);
  80. if (!len) {
  81. errmsg = strdup(GETMESSAGE(10,1,
  82. "An invalid length parameter was specified: %s"));
  83. printerrf(argv[0], errmsg,
  84. argv[i], NULL, NULL, NULL, NULL, NULL,
  85. NULL, NULL);
  86. free(errmsg);
  87. return(SH_FAIL);
  88. }
  89. }
  90. else if (argv[i][1] == 'l')
  91. longwise = 1;
  92. else if (argv[i][1] == 'p')
  93. printit = 1;
  94. }
  95. if (longwise < 0)
  96. longwise = 1;
  97. if (!len)
  98. len = sizeof(long);
  99. if (i >= argc) {
  100. XK_USAGE(argv[0]);
  101. }
  102. ptr = (unsigned char *) getaddr(argv[i++]);
  103. if (ptr) {
  104. if ( ((i < argc) && argv[i]) || printit) {
  105. char *dbuf, *p;
  106. int totlen;
  107. char buf[10 * BUFSIZ];
  108. int incr;
  109. if (printit)
  110. totlen = len + 1 + 1;
  111. else
  112. totlen = len + strlen(argv[i]) + 1 + 1;
  113. dbuf = (char *) (totlen < (10 * BUFSIZ - 1)) ? buf : malloc(totlen);
  114. if (printit)
  115. strcpy(dbuf, "0x");
  116. else
  117. sprintf(dbuf, "%s=0x", argv[i]);
  118. p = dbuf + strlen(dbuf);
  119. incr = longwise ? sizeof(long) : sizeof(char);
  120. for (i=0; i < len; i += incr, p += 2 * incr)
  121. sprintf(p, "%*.*x", incr * 2, incr * 2, longwise ? *((unsigned long *) (ptr + i)) : (unsigned long) (ptr[i]));
  122. if (printit)
  123. ALTPUTS(dbuf);
  124. else
  125. env_set(dbuf);
  126. if (dbuf != buf)
  127. free(dbuf);
  128. }
  129. else {
  130. if (len > sizeof(unsigned long)) {
  131. char tmpBuf[30];
  132. sprintf(tmpBuf, "%ld", (long)sizeof(unsigned long));
  133. errmsg = strdup(GETMESSAGE(10,2,
  134. "To set RET, the length must be less than: %s"));
  135. printerrf(argv[0], errmsg,
  136. tmpBuf, NULL, NULL, NULL, NULL, NULL, NULL,
  137. NULL);
  138. free(errmsg);
  139. return(SH_FAIL);
  140. }
  141. sprintf(xk_ret_buffer, use, *((unsigned long *) ptr));
  142. xk_ret_buf = xk_ret_buffer;
  143. }
  144. return(SH_SUCC);
  145. }
  146. errmsg = strdup(GetSharedMsg(DT_UNDEF_SYMBOL));
  147. printerrf(argv[0], errmsg, argv[--i], NULL, NULL, NULL,
  148. NULL, NULL, NULL, NULL);
  149. free(errmsg);
  150. return(SH_FAIL);
  151. }
  152. void *
  153. nop(
  154. void *var )
  155. {
  156. return(var);
  157. }
  158. void *
  159. save_alloc(
  160. void *var )
  161. {
  162. return(var);
  163. }