home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume19 / Xod / part04 < prev    next >
Encoding:
Text File  |  1993-04-28  |  9.6 KB  |  402 lines

  1. Newsgroups: comp.sources.x
  2. From: rfs@se28.wg2.waii.com (Robert Starr)
  3. Subject: v19i021:  Xod - Octal dump for Xwindows, Part04/04
  4. Message-ID: <1993Mar9.211240.22017@sparky.imd.sterling.com>
  5. X-Md4-Signature: f8d51d4eb1796c6bf477c37a579f9b8d
  6. Date: Tue, 9 Mar 1993 21:12:40 GMT
  7. Approved: chris@sparky.imd.sterling.com
  8.  
  9. Submitted-by: rfs@se28.wg2.waii.com (Robert Starr)
  10. Posting-number: Volume 19, Issue 21
  11. Archive-name: Xod/part04
  12. Environment: X11R4 X11R5 gcc
  13.  
  14. ---- Cut Here and unpack ----
  15. #!/bin/sh
  16. # this is part 4 of a multipart archive
  17. # do not concatenate these parts, unpack them in order with /bin/sh
  18. # file xod.pt continued
  19. #
  20. CurArch=4
  21. if test ! -r s2_seq_.tmp
  22. then echo "Please unpack part 1 first!"
  23.      exit 1; fi
  24. ( read Scheck
  25.   if test "$Scheck" != $CurArch
  26.   then echo "Please unpack part $Scheck next!"
  27.        exit 1;
  28.   else exit 0; fi
  29. ) < s2_seq_.tmp || exit 1
  30. echo "x - Continuing file xod.pt"
  31. sed 's/^X//' << 'SHAR_EOF' >> xod.pt
  32. Xvoid DisplayLine _P_XOD((unsigned char *data, int length, int line));
  33. Xvoid DisplayFullPage _P_XOD((int line, int moff));
  34. Xvoid RedisplayPage _P_XOD((void));
  35. X
  36. X/* utils.c */
  37. Xint CursorAt _P_XOD((int x, int y));
  38. Xint ClearScreen _P_XOD((void));
  39. Xlong AddressConvert _P_XOD((char *caddr));
  40. X
  41. X/* fileio.c */
  42. Xvoid DataLocation _P_XOD((int *line, int *moff));
  43. Xlong GetDataOffset _P_XOD((void));
  44. Xchar *GetFileName _P_XOD((void));
  45. XBoolean IsAtEOF _P_XOD((void));
  46. Xint DoSearch _P_XOD((unsigned char *pattern, int len));
  47. Xunsigned char *ReadBlock _P_XOD((int startline, int width, int height, int moff));
  48. Xint ReadNbytes _P_XOD((long begin, int n, unsigned char *where));
  49. Xunsigned char ByteAtPosition _P_XOD((int line, int chpos));
  50. XBoolean AddressOnScreen _P_XOD((long addr));
  51. XBoolean FileOpen _P_XOD((char *filename));
  52. X
  53. X/* cmdline.c */
  54. Xvoid ParseCommandLine _P_XOD((int argc, char **argv));
  55. X
  56. X/* mkwidgets.c */
  57. Xvoid PopupGotoByte _P_XOD((void));
  58. Xvoid MakeWidgets _P_XOD((int *argc, char **argv));
  59. X
  60. X/* getres.c */
  61. Xchar *RevVideo _P_XOD((void));
  62. Xvoid FigureRevVidSeq _P_XOD((void));
  63. Xvoid XodGetResources _P_XOD((Widget top));
  64. X
  65. X#undef _P_XOD
  66. SHAR_EOF
  67. echo "File xod.pt is complete"
  68. chmod 0644 xod.pt || echo "restore of xod.pt fails"
  69. set `wc -c xod.pt`;Sum=$1
  70. if test "$Sum" != "5051"
  71. then echo original size 5051, current size $Sum;fi
  72. echo "x - extracting xutils.c (Text)"
  73. sed 's/^X//' << 'SHAR_EOF' > xutils.c &&
  74. Xstatic char *RcsID = "$Id: xutils.c,v 1.8 1993/03/02 00:49:03 rfs Exp $";
  75. X/*
  76. X * $Log: xutils.c,v $
  77. X * Revision 1.8  1993/03/02  00:49:03  rfs
  78. X * Fixed up.
  79. X *
  80. X * Revision 1.7  1993/02/26  21:39:16  rfs
  81. X * Handle decoding of bytes
  82. X *
  83. X * Revision 1.6  1993/02/14  01:17:06  rfs
  84. X * New handling of status line.
  85. X *
  86. X * Revision 1.5  1993/02/13  23:27:17  rfs
  87. X * Added widget association routines.
  88. X *
  89. X * Revision 1.4  1993/02/13  18:00:12  rfs
  90. X * Added routines to set and get mouse coordinates.
  91. X *
  92. X * Revision 1.3  1993/02/13  13:39:54  rfs
  93. X * added function ResetMouseCoord
  94. X *
  95. X * Revision 1.2  1993/02/13  13:21:27  rfs
  96. X * byte offset now reflects where the cursor is.
  97. X *
  98. X * Revision 1.1  1993/02/13  12:02:17  rfs
  99. X * Initial revision
  100. X *
  101. X *
  102. X*/
  103. X
  104. X
  105. X#include <xod.h>
  106. X#include <xod.pt>
  107. X#include <buttonndx.h>
  108. X
  109. X/* widget association list */
  110. Xstatic WidgetList wassoc =  NULL;
  111. Xstatic int wassoccnt = 0;
  112. X
  113. Xstatic int fwidth, fheight;
  114. X/* mouse coord's in row/column xy's */
  115. Xstatic int mousex = 1;
  116. Xstatic int mousey = 1;
  117. X
  118. X/* revert mouse coordinates to the root */
  119. XResetMouseCoord(void) {
  120. X    mousex = mousey = 1;
  121. X}
  122. X
  123. Xvoid
  124. XGetMouseCoord(int *x, int *y) {
  125. X    *x = mousex;
  126. X    *y = mousey;
  127. X}
  128. X
  129. Xvoid
  130. XSetMouseCoord(int x, int y) {
  131. X    mousex = x;
  132. X    mousey = y;
  133. X}
  134. X
  135. X/*
  136. X * Considering each data byte as displayed consumes a single
  137. X * coordinate, find where cursor is.
  138. X*/
  139. Xvoid
  140. XGetCursorOnData(int *x, int *y) {
  141. X    int width, mx, my;
  142. X
  143. X    GetFormat(&width);
  144. X    width++;
  145. X    GetMouseCoord(&mx, &my);
  146. X    *y = my;
  147. X    *x = ((mx-1)/width)+1;
  148. X}
  149. X
  150. X/* also pretends the x & y are based on displayed bytes */
  151. Xvoid
  152. XSetCursorOnData(int x, int y) {
  153. X    int  mx, my, width;
  154. X
  155. X    GetFormat(&width);
  156. X    width++;
  157. X    MouseUnhighlight(mousex, mousey);
  158. X    mousex = (x-1)*width + 1;
  159. X    if (y < 1) y = 1;
  160. X    mousey = y;
  161. X    MouseHighlight(mousex, mousey);
  162. X    UpdateByteOffset();
  163. X}
  164. X
  165. X/* compute absolute byte the cursor resides on */
  166. Xint
  167. XAbsByteOffset(void) {
  168. X    int  offset, width;
  169. X
  170. X    GetFormat(&width);
  171. X    width++;
  172. X    offset = (mousey-1)*BytesHoriz;
  173. X    offset += (mousex-1)/width;
  174. X    return offset;
  175. X}
  176. X
  177. XCursorToAbsByte(long addr) {
  178. X    long upperleft, filesize;
  179. X    int  x, y, line, moff;
  180. X
  181. X    DataLocation(&line, &moff);
  182. X    filesize = CurrentFileSize();
  183. X    if (addr > filesize) addr = filesize;
  184. X    if (addr < 0) addr = 0;
  185. X    if (!AddressOnScreen(addr)) {
  186. X        line = (addr-moff)/BytesHoriz;
  187. X        if (line < 0) line = 0;
  188. X        DisplayFullPage(line, moff);
  189. X    }
  190. X    upperleft = GetDataOffset();
  191. X    y = ((addr-upperleft)/BytesHoriz)+1;
  192. X    x = ((addr-upperleft) % BytesHoriz)+1;
  193. X    SetCursorOnData(x, y);
  194. X}
  195. X
  196. X/* update the byte offset label */
  197. Xvoid
  198. XUpdateByteOffset(void) {
  199. X    long addr;
  200. X    int  line, moff;
  201. X
  202. X    DataLocation(&line, &moff);
  203. X    addr = (line*BytesHoriz) + moff;
  204. X    addr += AbsByteOffset();
  205. X    XtVaSetValues(ByteOffsetWidget, XtNlabel, FmtOffset(addr), NULL);
  206. X}
  207. X
  208. X
  209. X/* decode the data the mouse is on in a variety of formats */
  210. Xvoid
  211. XDoDecode(int mode) {
  212. X    char buffer[MAXLEN];
  213. X    unsigned short us;
  214. X    unsigned long ul;
  215. X    float f;
  216. X    double d;
  217. X    int  line, moff;
  218. X    long addr;
  219. X
  220. X    DataLocation(&line, &moff);
  221. X    addr = (line*BytesHoriz) + moff;
  222. X    addr += AbsByteOffset();
  223. X
  224. X    switch (mode) {
  225. X        case Short:
  226. X        case uShort:
  227. X            ReadNbytes(addr, sizeof(unsigned short), (unsigned char *)&us);
  228. X            sprintf(buffer, (mode==Short) ? "%d" : "%u", us);
  229. X            XtVaSetValues(DecodeWidget, XtNlabel, buffer, NULL);
  230. X            break;
  231. X        case Long:
  232. X        case uLong:
  233. X            ReadNbytes(addr, sizeof(unsigned long), (unsigned char *)&ul);
  234. X            sprintf(buffer, (mode==Long) ? "%d" : "%u", ul);
  235. X            XtVaSetValues(DecodeWidget, XtNlabel, buffer, NULL);
  236. X            break;
  237. X        case Float:
  238. X            ReadNbytes(addr, sizeof(float), (unsigned char *)&f);
  239. X            sprintf(buffer, "%f", f);
  240. X            XtVaSetValues(DecodeWidget, XtNlabel, buffer, NULL);
  241. X            break;
  242. X        case Double:
  243. X            ReadNbytes(addr, sizeof(double), (unsigned char *)&d);
  244. X            sprintf(buffer, "%f", d);
  245. X            XtVaSetValues(DecodeWidget, XtNlabel, buffer, NULL);
  246. X            break;
  247. X    }
  248. X}
  249. X
  250. Xstatic char *
  251. XWhatMode(int mode) {
  252. X    char *amode = "?";
  253. X    switch (mode) {
  254. X        case HEX:
  255. X            amode = "hex"; break;
  256. X        case OCTAL:
  257. X            amode = "octal"; break;
  258. X        case DECIMAL:
  259. X            amode = "decimal"; break;
  260. X        case ASCII:
  261. X            amode = "ascii"; break;
  262. X    }
  263. X    return amode;
  264. X}
  265. X
  266. Xvoid
  267. XUpdateAll(int mode, long addr) {
  268. X    SetAddressMode(mode);
  269. X    ShowByteAddress(addr);
  270. X    UpdateStatus();
  271. X}
  272. X
  273. X/* update the status line */
  274. Xvoid
  275. XUpdateStatus(void) {
  276. X    char buffer[MAXLEN];
  277. X    long addr;
  278. X    int  line, moff;
  279. X
  280. X    UpdateByteOffset();
  281. X    DataLocation(&line, &moff);
  282. X    addr = (line*BytesHoriz) + moff;
  283. X    ShowByteAddress(addr);
  284. X    sprintf(buffer, "< %s, offset %s, data %s >", GetFileName(),
  285. X        WhatMode(OffsetMode), WhatMode(DataMode));
  286. X    XtVaSetValues(StatusWidget, XtNlabel, buffer, NULL);
  287. X}
  288. X
  289. X/* set a widget's label field */
  290. Xvoid
  291. XSetWidgetLabel(Widget w, char *value) {
  292. X    XtVaSetValues(w, XtNlabel, value, NULL);
  293. X}
  294. X
  295. X/* Send a string to the CTW widget */
  296. XSendString(char *string) {
  297. X    ctw_add_string((CtwWidget)ctwWidget, string, strlen(string));
  298. X    if (*(string+strlen(string)-1) == '\n')
  299. X        ctw_add_string((CtwWidget)ctwWidget, "\r", 1);
  300. X}
  301. X
  302. Xvoid
  303. Xget_font_size(CtwWidget w, int *fwidth, int *fheight) {
  304. X    char **attr_names;
  305. X    int    len;
  306. X    int    *flags;
  307. X
  308. X    len = ctw_get_attributes((CtwWidget)ctwWidget, &flags, &attr_names);
  309. X    *fwidth = flags[CTW_FONT_SIZE] >> 16;
  310. X    *fheight = flags[CTW_FONT_SIZE] & 0xffff;
  311. X}
  312. X
  313. Xstatic
  314. XFontSizes(void) {
  315. X    if (fwidth) return;
  316. X    get_font_size((CtwWidget)ctwWidget, &fwidth, &fheight);
  317. X}
  318. X
  319. Xstatic
  320. XFindCharUnderMouse(int x, int y) {
  321. X    int  row, column;
  322. X    int  width;
  323. X
  324. X    FontSizes();
  325. X    GetFormat(&width);
  326. X    width++;
  327. X    /* xlate an absolute mouse xy to a char xy (root 1,1) */
  328. X    column = x/fwidth+1;
  329. X    row = y/fheight+1;
  330. X    if (column < 1) column = 1;
  331. X    if (row < 1) row = 1;
  332. X    /* make clicking in packed area look like clicking over data */
  333. X    if (column >= PackedColumn()) {
  334. X        column = ((column-PackedColumn()) * width)+1;
  335. X    }
  336. X    if (column > (BytesHoriz*width))
  337. X        return;
  338. X    MouseUnhighlight(mousex, mousey);
  339. X    CursorAt(row, column);
  340. X    mousex = column;
  341. X    mousey = row;
  342. X    MouseHighlight(column, row);
  343. X    UpdateByteOffset();
  344. X}
  345. X
  346. XXtCallbackProc
  347. XMouseCB(Widget widget, char *name, ctw_callback_t *reason) {
  348. X    Window root, child;
  349. X    int  rx, ry, wx, wy;
  350. X    unsigned int mask;
  351. X
  352. X    XQueryPointer(XtDisplay(widget), XtWindow(widget), &root, &child, &rx, &ry,
  353. X        &wx, &wy, &mask);
  354. X    FindCharUnderMouse(wx, wy);
  355. X    return;
  356. X}
  357. X
  358. X/* build & manage table associating one widget with another */
  359. Xvoid
  360. XAddWidgetAssoc(Widget a, Widget b) {
  361. X    int  ndx, realndx;
  362. X
  363. X    wassoccnt++;
  364. X    wassoc = (WidgetList)XtRealloc((char *)wassoc, 
  365. X        wassoccnt*(2*sizeof(Widget)));
  366. X    ndx = wassoccnt-1;
  367. X    realndx = 2*ndx;
  368. X
  369. X    wassoc[realndx] = a;
  370. X    wassoc[realndx+1] = b;
  371. X}
  372. X
  373. XWidget
  374. XGetWidgetAssoc(Widget w) {
  375. X    Widget assoc = NULL;
  376. X    int  i, ndx;
  377. X
  378. X    for (i=0; i < wassoccnt; i++) {
  379. X        ndx = i*2;
  380. X        if (wassoc[ndx] == w) {
  381. X            assoc = wassoc[ndx+1];
  382. X            break;
  383. X        }
  384. X    }
  385. X    return assoc;
  386. X}
  387. SHAR_EOF
  388. chmod 0644 xutils.c || echo "restore of xutils.c fails"
  389. set `wc -c xutils.c`;Sum=$1
  390. if test "$Sum" != "6641"
  391. then echo original size 6641, current size $Sum;fi
  392. rm -f s2_seq_.tmp
  393. echo "You have unpacked the last part"
  394. exit 0
  395.  
  396. exit 0 # Just in case...
  397. -- 
  398.   // chris@IMD.Sterling.COM            | Send comp.sources.x submissions to:
  399. \X/  Amiga - The only way to fly!      |
  400.  "It's intuitively obvious to the most |    sources-x@imd.sterling.com
  401.   casual observer..."                  |
  402.