home *** CD-ROM | disk | FTP | other *** search
- /*
- The output routines used by the SB structure handlers. Each structure is
- presented as a menu of up to 16 items; the text for these items is
- contained in the static array called textlines[].
- */
-
- #include "header/sb.h"
-
- #define FLAGFIELDS 4
- #define MIN(x,y) ((x)<(y)?(x):(y))
-
- extern struct IntuiText ChoiceText[], BackIText;
- static char textlines[MAXGADG + 1][80];
-
- /* put
-
- Build a line showing the contents of one member of a system structure, and
- add it to the textlines[] array, which will eventually be sent to the
- screen as IntuiText.
-
- Parameters:
- option the number of the textlines[] element put() is to fill
- stuff a pointer to StructData structure (see header/sb.h)
- base a pointer to the system structure being examined
- offset for system structures with more than 16 members, an offset to
- the first element to be displayed on the current menu page
- */
-
- put (option, stuff, base, offset)
- int option;
- struct StructData *stuff;
- register char *base;
- register int offset;
- {
- register long lnum;
- register int inum;
- register int i;
- char buf[40];
-
- /* move the structure member's name and type description into array */
- sprintf(textlines[option], "%-16s%-24s",
- stuff->membername, stuff->membertype);
-
- /* convert member contents to ascii according to printttype code */
- switch (stuff->printtype)
- {
- case PRNULL: /* don't print anything */
- buf[0] = '\0';
- break;
- case PRLONG: /* print a long */
- lnum = *(long *)(base + offset);
- sprintf(buf, "$%8lx %10ld", lnum, lnum);
- break;
- case PRINT: /* print an int */
- inum = *(int *)(base + offset);
- sprintf(buf, "$%8x %10d", inum, inum);
- break;
- case PRBYTE: /* print a byte */
- inum = *(base + offset);
- sprintf(buf, "$%8x %10d", inum, inum);
- break;
- case PRSTRING: /* print a string */
- if (!(lnum = *(long *)(base + offset) ))
- sprintf(buf, "NULL");
- else
- {
- /* we only have room to display 30 characters */
- for (i = 0; i < 30 && ((char *)lnum)[i]; i++)
- buf[i + 1] = ((char *)lnum)[i];
- buf[0] = buf[i + 1] = '\"';
- buf[i + 2] = '\0';
- if (((char *)lnum)[i])
- strcat(buf, "...");
- }
- break;
- case PRPTR: /* print a pointer */
- if (!(lnum = *(long *)(base + offset)))
- sprintf(buf, "NULL");
- else
- sprintf(buf, "$%8lx %10ld", lnum, lnum);
- break;
- case PRULONG: /* print an unsigned long */
- lnum = *(long *)(base + offset);
- sprintf(buf, "$%8lx %10lu", lnum, lnum);
- break;
- case PRUINT: /* print an unsigned int */
- inum = *(int *)(base + offset);
- sprintf(buf, "$%8x %10u", inum, inum);
- break;
- case PRUBYTE: /* print an unsigned byte */
- inum = *(base + offset);
- sprintf(buf, "$%8x %10u", inum, inum);
- break;
- }
- strcat(textlines[option], buf);
-
- /* make corresponding IntuiText point at the newly created line */
- ChoiceText[option].IText = (UBYTE *)textlines[option];
- }
-
-
- /* FlagPrint
-
- Given a title (string), an array of names (names) and a 32-bit pile of
- flags (flags), build 4-up lines specifying the set flags, and install them
- in the textlines[] array.
- */
-
- FlagPrint (string, names, flags)
- char *string, **names;
- ULONG flags;
- {
- int i, line, fields = FLAGFIELDS;
- char buf[32];
-
- /* Use "Previous Level" as text on the escape gadget */
- SetBackText(1);
-
- /* No indirection allowed through these lines, so start them with a '-'.
- And make IntuiText point at where the strings will be.
- */
- for (i = 0; i < 8; i++)
- {
- strcpy(textlines[i], "-");
- ChoiceText[i].IText = (UBYTE *)textlines[i];
- }
-
- /* print the supplied header string */
- putHeader(string, NULL);
-
- for (i = line = 0; i < 32; i++)
- {
- if ((flags & (1L << i)) && names[i])
- {
- sprintf(buf, "%-19s", names[i]);
- strcat(textlines[line], buf);
- if (!--fields)
- {
- ChoiceText[line].IText = (UBYTE *)textlines[line];
- line++;
- fields = FLAGFIELDS;
- }
- }
- }
- if (fields < FLAGFIELDS)
- ChoiceText[line].IText = (UBYTE *)textlines[line];
- /* while (GetChoice(line + 1))
- putHeader(string, NULL)*/
-
- GetChoice(line + 1);
- }
-
-
- /* HexDump
-
- Dump memory as hex in byte, word or longword units. If the size argument
- is -1, the dump continues until exited by the user.
- */
-
- HexDump (string, address, unit, size)
- char *address, *string;
- int unit;
- long size;
- {
- int line = 0;
- int c;
- char *buf[80];
-
- BackIText.IText = (UBYTE *)" Exit Hex Dump ";
-
- /* We want an infinite dump for size == -1, but settle for 0x7ffff */
- if (size == -1)
- size = 0x7ffff;
- do
- {
- /* Create a header for a page of hexdump, and display it */
- sprintf(buf, "%s from %lx (%ld)", string, address, address);
- putHeader(buf, NULL);
-
- /* Dump out a page, or the specified range if less */
- if (line == MAXGADG)
- line = 0;
- while (line < MAXGADG && size > 0)
- {
- HexLine(address, unit, line++, size);
- size -= 16;
- address += 16;
- }
-
- /* Let user decide to quit or do more (if there's more to do) */
- c = GetChoice(size > 0 ? MAXGADG + 1 : line);
- } while (size > 0 && c == MOREGADG);
- }
-
-
- /* HexLine
-
- Generate a line of hexdump in the specified unit (byte, word, long)
- */
-
- HexLine (address, unit, line, size)
- UBYTE *address;
- int unit, line;
- long size;
- {
- USHORT i, j;
- char buf[80];
- static char hexdigit[] = "0123456789ABCDEF";
-
- sprintf(textlines[line], "-%6lx: ", address);
-
- for (i = 0; i < MIN(size, 16); i += unit)
- {
- switch (unit)
- {
- case BYTESIZE:
- j = *(address + i);
- sprintf(buf, "%c%c ", hexdigit[j / 16], hexdigit[j % 16]);
- break;
- case INTSIZE:
- sprintf(buf, "%04x ", *(int *)(address + i));
- break;
- case PTRSIZE:
- sprintf(buf, "%08lx ", *(long *)(address + i));
- break;
- }
- strcat(textlines[line], buf);
- }
- ChoiceText[line].IText = (UBYTE *)textlines[line];
- }
-
-
- /* SetOptionText
-
- Fill up the textlines array by repeated calls to put().
- */
-
- SetOptionText (hdrtext, data, object, size, offset)
- char *hdrtext;
- struct StructData *data;
- APTR object;
- int size, offset;
- {
- int i, sum;
-
- /* Set escape text to "Previous level" or "Previous page" depending on
- value of offset (will be zero if this is first page of structure
- */
- SetBackText(offset ? 1 : 0 );
-
- /* Display name and address of object */
- putHeader(hdrtext, object);
-
- /* Build lines of text while stepping through the structure */
- for (i = sum = 0; i < size; i++)
- {
- put(i, &data[i], object, sum + offset);
- sum += data[i].datasize;
- }
-
- /* Tell caller how far we got into the structure */
- return (sum + offset);
- }
-
-
- /* PrString
-
- Print a text string
- */
-
- PrString (heading, string)
- char *heading, *string;
- {
- char *newstring, *malloc();
-
- putHeader(heading, NULL);
- newstring = malloc(strlen(string) + 2);
- *newstring = '-';
- strcpy(newstring + 1, string);
- ChoiceText[0].IText = (UBYTE *)newstring;
- GetChoice(1);
- free(newstring);
- }
-
-
-