home *** CD-ROM | disk | FTP | other *** search
- /* Height of a string calculation routine, Copyright 1991 John Bridges */
-
-
- #define code _based(_segname("_CODE"))
-
- unsigned code _acrtused; /* Dummy variable required by linker */
-
- struct
- {
- unsigned char widths[256];
- unsigned char gap;
- unsigned char vgap;
- unsigned char xsize;
- unsigned char ysize;
- } code cb;
-
- /* Called function has standard C Parameters passed to it */
-
- unsigned long far main(argc, argv)
- int argc;
- char **argv;
- {
- if (argc == 1)
- return (unsigned long) (void far *) &cb;
- else
- return height(num(argv[1]), argv[2]);
- }
-
- num(unsigned char *pt)
- {
- unsigned int j;
-
- if (((unsigned int *) pt)[-1] == 1)
- return (int) *(unsigned long *) pt;
- j = 0;
- while (*pt >= '0' && *pt <= '9') /* loop through and convert */
- j = j * 10 + (*pt++ - '0');
- return j;
- }
-
- height(width, ourstr)
- int width;
- unsigned char *ourstr;
- {
- register int ch;
- register unsigned char *pt;
- int xw, xx, oxx;
- int tx, ty;
- unsigned char *wpt;
- int swpt;
- int pch;
-
- pt = ourstr;
- tx = 0;
- ty = 0;
- glp: wpt = 0;
- swpt = 0;
- pch = 0;
- xx = tx;
- while (ch = *pt)
- {
- if (ch == '\r')
- {
- ++pt;
- continue;
- }
- if (ch == '\n' && pt[1] > ' ' && xx > tx)
- {
- if (pch == ' ')
- {
- ++pt;
- continue;
- }
- ch = ' ';
- }
- if (ch == '\n')
- {
- xx = 0;
- }
- else if (ch == 255)
- {
- --xx;
- }
- else
- {
- xx += cb.widths[ch];
- }
- if (xx > width + 1 + cb.gap)
- break;
- if (ch == ' ' || ch == '-' || ch == ',')
- {
- oxx = xx;
- wpt = pt;
- swpt = (ch == ' ');
- }
- ++pt;
- pch = ch;
- }
- if (!wpt)
- {
- if (tx > 0 && ch)
- wpt = ourstr - 1;
- else
- wpt = pt;
- }
- else
- {
- if (xx <= width + 1 + cb.gap)
- {
- wpt = pt;
- }
- else
- {
- xx = oxx;
- if (swpt)
- xx -= cb.widths[' '];
- }
- }
- pt = ourstr;
- pch = 0;
- while (ch = *pt)
- {
- if (ch == '\r')
- {
- ++pt;
- continue;
- }
- if (ch == 255)
- {
- --tx;
- ++pt;
- continue;
- }
- if (ch == '\n' && pt[1] > ' ' && tx > 0)
- {
- if (pch == ' ')
- {
- ++pt;
- continue;
- }
- ch = ' ';
- }
- if (pt > wpt || ch == '\n')
- {
- tx = 0;
- ty += cb.ysize + cb.vgap;
- if (ch == '\n')
- {
- ++pt;
- }
- while (*pt == ' ')
- ++pt;
- ourstr = pt;
- goto glp;
- }
- pch = ch;
- ++pt;
- tx += cb.widths[ch];
- }
- if (tx)
- ty += cb.ysize + cb.vgap;
- return ty;
- }
-
-