home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / commercial-software / programming / AZTEC302.ZIP / MISC.ARC < prev    next >
Text File  |  1998-09-16  |  14KB  |  751 lines

  1. atoi.c
  2. /* Copyright (C) 1981,1982 by Manx Software Systems */
  3. #include <ctype.h>
  4.  
  5. atoi(cp)
  6. register char *cp;
  7. {
  8.     register unsigned i;
  9.     register sign;
  10.  
  11.     while (*cp == ' ' || *cp == '\t')
  12.         ++cp;
  13.     sign = 0;
  14.     if ( *cp == '-' ) {
  15.         sign = 1;
  16.         ++cp;
  17.     } else if ( *cp == '+' )
  18.         ++cp;
  19.  
  20.     for ( i = 0 ; isdigit(*cp) ; )
  21.         i = i*10 + *cp++ - '0';
  22.     return sign ? -i : i;
  23. }
  24. atol.c
  25. /* Copyright (C) 1982 by Manx Software Systems */
  26. #include <ctype.h>
  27.  
  28. long
  29. atol(cp)
  30. register char *cp;
  31. {
  32.     long n;
  33.     register sign;
  34.  
  35.     while (*cp == ' ' || *cp == '\t')
  36.         ++cp;
  37.     sign = 0;
  38.     if ( *cp == '-' ) {
  39.         sign = 1;
  40.         ++cp;
  41.     } else if ( *cp == '+' )
  42.         ++cp;
  43.  
  44.     for ( n = 0 ; isdigit(*cp) ; )
  45.         n = n*10 + *cp++ - '0';
  46.     return sign ? -n : n;
  47. }
  48. calloc.c
  49. /* Copyright (C) 1984 by Manx Software Systems */
  50.  
  51. char *calloc(nelem, size)
  52. unsigned nelem, size;
  53. {
  54.     register unsigned i = nelem*size;
  55.     register char *cp, *malloc();
  56.  
  57.     if ((cp = malloc(i)) != (char *)0)
  58.         setmem(cp, i, 0);
  59.     return cp;
  60. }
  61. ctype.c
  62. /* Copyright (C) 1984 by Manx Software Systems */
  63.  
  64. char ctp_[129] = {
  65.     0,                                /*    EOF */
  66.     0x20,    0x20,    0x20,    0x20,    /*    nul    soh    stx    etx    */
  67.     0x20,    0x20,    0x20,    0x20,    /*    eot    enq    ack    bel    */
  68.     0x20,    0x30,    0x30,    0x30,    /*    bs    ht    nl    vt    */
  69.     0x30,    0x30,    0x20,    0x20,    /*    ff    cr    so    si    */
  70.     0x20,    0x20,    0x20,    0x20,    /*    dle    dc1    dc2    dc3    */
  71.     0x20,    0x20,    0x20,    0x20,    /*    dc4    nak    syn    etb    */
  72.     0x20,    0x20,    0x20,    0x20,    /*    can    em    sub    esc    */
  73.     0x20,    0x20,    0x20,    0x20,    /*    fs    gs    rs    us    */
  74.     0x90,    0x40,    0x40,    0x40,    /*    sp    !    "    #    */
  75.     0x40,    0x40,    0x40,    0x40,    /*    $    %    &    '    */
  76.     0x40,    0x40,    0x40,    0x40,    /*    (    )    *    +    */
  77.     0x40,    0x40,    0x40,    0x40,    /*    ,    -    .    /    */
  78.     0x0C,    0x0C,    0x0C,    0x0C,    /*    0    1    2    3    */
  79.     0x0C,    0x0C,    0x0C,    0x0C,    /*    4    5    6    7    */
  80.     0x0C,    0x0C,    0x40,    0x40,    /*    8    9    :    ;    */
  81.     0x40,    0x40,    0x40,    0x40,    /*    <    =    >    ?    */
  82.     0x40,    0x09,    0x09,    0x09,    /*    @    A    B    C    */
  83.     0x09,    0x09,    0x09,    0x01,    /*    D    E    F    G    */
  84.     0x01,    0x01,    0x01,    0x01,    /*    H    I    J    K    */
  85.     0x01,    0x01,    0x01,    0x01,    /*    L    M    N    O    */
  86.     0x01,    0x01,    0x01,    0x01,    /*    P    Q    R    S    */
  87.     0x01,    0x01,    0x01,    0x01,    /*    T    U    V    W    */
  88.     0x01,    0x01,    0x01,    0x40,    /*    X    Y    Z    [    */
  89.     0x40,    0x40,    0x40,    0x01,    /*    \    ]    ^    _    */
  90.     0x40,    0x0A,    0x0A,    0x0A,    /*    `    a    b    c    */
  91.     0x0A,    0x0A,    0x0A,    0x02,    /*    d    e    f    g    */
  92.     0x02,    0x02,    0x02,    0x02,    /*    h    i    j    k    */
  93.     0x02,    0x02,    0x02,    0x02,    /*    l    m    n    o    */
  94.     0x02,    0x02,    0x02,    0x02,    /*    p    q    r    s    */
  95.     0x02,    0x02,    0x02,    0x02,    /*    t    u    v    w    */
  96.     0x02,    0x02,    0x02,    0x40,    /*    x    y    z    {    */
  97.     0x40,    0x40,    0x40,    0x20,    /*    |    }    ~    del    */
  98. } ;
  99. format.c
  100. /* Copyright (C) 1981,1982,1983 by Manx Software Systems */
  101. #include <ctype.h>
  102.  
  103. #if MPU8080 || MPUZ80
  104. char *_fmtcvt();
  105. #else
  106.  
  107. static char *
  108. _fmtcvt(ap, base, cp, len)
  109. int *ap; register char *cp;
  110. {
  111.     register unsigned long val;
  112.     static char digits[]="0123456789abcdef";
  113.  
  114.     if (len == sizeof(long))
  115.         val = *(long *)ap;
  116.     else if (base > 0)
  117.         val = *(unsigned *)ap;
  118.     else
  119.         val = *ap;
  120.  
  121.     len = 0;
  122.     if (base < 0) {
  123.         base = -base;
  124.         if ((long)val < 0) {
  125.             val = -val;
  126.             len = 1;
  127.         }
  128.     }
  129.  
  130.     do {
  131.         *--cp = digits[(int)(val%base)];
  132.     } while ((val /= base) != 0);
  133.     if (len)
  134.         *--cp = '-';
  135.     return cp;
  136. }
  137. #endif
  138.  
  139. format(putsub, fmt, argp)
  140. register int (*putsub)(); register char *fmt; char *argp;
  141. {
  142.     register int c;
  143.     union {
  144.         int *ip;
  145.         char *cp;
  146.         char **cpp;
  147. #ifdef FLOAT
  148.         double *dp;
  149. #endif
  150.     } args; 
  151.     int charcount;
  152.     int rj, fillc;
  153.     int maxwidth, width;
  154.     int i, k;
  155.     char *cp;
  156.     auto char s[200];
  157.  
  158.     charcount = 0;
  159.     args.cp = argp;
  160.     while ( c = *fmt++ ) {
  161.         if ( c == '%' ) {
  162.             s[14] = 0;
  163.             rj = 1;
  164.             fillc = ' ';
  165.             maxwidth = 10000;
  166.             if ((c = *fmt++) == '-') {
  167.                 rj = 0;
  168.                 c = *fmt++;
  169.             }
  170.             if (c == '0') {
  171.                 fillc = '0';
  172.                 c = *fmt++;
  173.             }
  174.             if (c == '*') {
  175.                 width = *args.ip++;
  176.                 c = *fmt++;
  177.             } else {
  178.                 for (width = 0 ; isdigit(c) ; c = *fmt++)
  179.                     width = width*10 + c - '0';
  180.             }
  181.             if ( c == '.' ) {
  182.                 if ((c = *fmt++) == '*') {
  183.                     maxwidth = *args.ip++;
  184.                     c = *fmt++;
  185.                 } else {
  186.                     for (maxwidth = 0 ; isdigit(c) ; c = *fmt++)
  187.                         maxwidth = maxwidth*10 + c - '0';
  188.                 }
  189.             }
  190.             i = sizeof(int);
  191.             if (c == 'l') {
  192.                 c = *fmt++;
  193.                 i = sizeof(long);
  194.             } else if (c == 'h')
  195.                 c = *fmt++;
  196.  
  197.             switch ( c ) {
  198.             case 'o':
  199.                 k = 8;
  200.                 goto do_conversion;
  201.             case 'u':
  202.                 k = 10;
  203.                 goto do_conversion;
  204.             case 'x':
  205.                 k = 16;
  206.                 goto do_conversion;
  207.  
  208.             case 'd':
  209.                 k = -10;
  210.     do_conversion:
  211.                 cp = _fmtcvt(args.cp, k, s+14, i);
  212.                 args.cp += i;
  213.                 break;
  214.  
  215.             case 's':
  216.                 i = strlen(cp = *args.cpp++);
  217.                 goto havelen;
  218. #ifdef FLOAT
  219.             case 'e':
  220.             case 'f':
  221.             case 'g':
  222.                 ftoa(*args.dp++, s, maxwidth==10000?6:maxwidth, c-'e');
  223.                 i = strlen(cp = s);
  224.                 maxwidth = 200;
  225.                 goto havelen;
  226. #endif
  227.  
  228.             case 'c':
  229.                 c = *args.ip++;
  230.             default:
  231.                 *(cp = s+13) = c;
  232.                 break;
  233.             }
  234.  
  235.             i = (s+14) - cp;
  236.         havelen:
  237.             if ( i > maxwidth )
  238.                 i = maxwidth;
  239.             
  240.             if ( rj ) {
  241.                 for (; width-- > i ; ++charcount)
  242.                     if ((*putsub)(fillc) == -1)
  243.                         return -1;
  244.             }
  245.             for ( k = 0 ; *cp && k < maxwidth ; ++k )
  246.                 if ((*putsub)(*cp++) == -1)
  247.                     return -1;
  248.             charcount += k;
  249.             
  250.             if ( !rj ) {
  251.                 for (; width-- > i ; ++charcount)
  252.                     if ((*putsub)(' ') == -1)
  253.                         return -1;
  254.             }
  255.         } else {
  256.             if ((*putsub)(c) == -1)
  257.                 return -1;
  258.             ++charcount;
  259.         }
  260.     }
  261.     return charcount;
  262. }
  263.  
  264. malloc.c
  265. /* Copyright (C) 1985 by Manx Software Systems, Inc. */
  266.  
  267. #ifdef __LDATA
  268. typedef long size_t;
  269. char *_ptradd();
  270. long _ptrdiff();
  271. #define bump(p,i) ((l_t *)_ptradd((p),(long)(i)))
  272. #define ptrdiff(p1,p2) _ptrdiff(p1,p2)
  273. #else
  274. typedef unsigned size_t;
  275. #define bump(p,i) ((l_t *)((char *)(p)+(i)))
  276. #define ptrdiff(p1,p2) (unsigned)((char *)(p1)-(char *)(p2))
  277. #endif
  278.  
  279. typedef struct list {
  280.     struct list *next;
  281. } l_t;
  282. static l_t first, *current;
  283. static l_t *endmarker = &first, *restart = &first;
  284. static size_t keep;
  285.  
  286. #define INUSE    1
  287. #define inuse(p) (*(size_t *)(p)&INUSE)
  288. #define markblk(p) (*(size_t *)(p) |= INUSE)
  289. #define unmark(p) (*(size_t *)(p) &= ~INUSE)
  290. #define chain(p)    ((l_t *)(*(size_t *)(p) & ~INUSE))
  291.  
  292. #define BLOCK    (512*sizeof(l_t))    /* # of bytes to ask sbrk for */
  293.  
  294. char *
  295. realloc(area, size)
  296. register char *area; unsigned size;
  297. {
  298.     register char *cp, *end;
  299.     size_t osize;
  300.     char *malloc();
  301.  
  302.     end = (char *)chain((l_t *)area-1);
  303.     if ((osize = ptrdiff(end, area)) > size) {
  304.         osize = size;
  305.         end = (char *)bump(area, osize);
  306.     }
  307.     free(area);
  308.     if ((cp = malloc(size)) != 0 && cp != area) {
  309.         movmem(area, cp, osize);
  310.         if ((char *)current >= area && (char *)current < end)
  311.             *(size_t *)bump(cp, ptrdiff(current,area)) = keep;
  312.     }
  313.     return cp;
  314. }
  315.  
  316. char *
  317. malloc(size)
  318. unsigned size;
  319. {
  320.     register l_t *ptr, *temp, *lastfree;
  321.     register size_t len;
  322.     int times;
  323.     char *sbrk();
  324.  
  325.     size = ((size+sizeof(l_t)*2-1)/sizeof(l_t))*sizeof(l_t);
  326.     if (current == 0) {
  327.         first.next = &first;
  328.         markblk(&first);
  329.         current = &first;
  330.     }
  331.     for (times = 0, lastfree = ptr = current ; ; ptr = chain(ptr)) {
  332.         if (ptr == endmarker) {
  333.             if (++times > 1) {
  334.                 len = BLOCK;
  335.                 if ((temp = (l_t *)sbrk((int)len)) == (l_t *)-1)
  336.                     return 0;
  337.                 if (temp != bump(ptr,sizeof(l_t))) {
  338.                     /* non-contiguous allocation */
  339.                     ptr->next = temp;
  340.                     markblk(ptr);
  341.                     len -= sizeof(l_t);
  342.                     ptr = temp;
  343.                 }
  344.                 temp = bump(ptr, len);
  345.                 ptr->next = temp;
  346.                 temp->next = &first;    /* new end marker */
  347.                 markblk(temp);
  348.                 endmarker = temp;
  349.                 if (chain(lastfree) == ptr)
  350.                     ptr = lastfree;
  351.             }
  352.         }
  353.         if (inuse(ptr))
  354.             continue;
  355.         lastfree = ptr;
  356.         while (!inuse(temp = chain(ptr)))
  357.             ptr->next = temp->next;
  358.         len = ptrdiff(temp,ptr);
  359.         if (len >= size) {
  360.             if (len > size) {
  361.                 ptr->next = bump(ptr, size);
  362.                 keep = *(size_t *)ptr->next;
  363.                 ptr->next->next = temp;
  364.             }
  365.             current = ptr->next;
  366.             markblk(ptr);
  367.             return (char *)(ptr+1);
  368.         }
  369.     }
  370. }
  371.  
  372. free(p)
  373. char *p;
  374. {
  375.     register l_t *ptr;
  376.  
  377.     ptr = (l_t *)p - 1;
  378.     if (!inuse(ptr))
  379.         return -1;
  380.     unmark(ptr);
  381.     current = ptr;
  382.     return 0;
  383. }
  384. qsort.c
  385. /* Copyright (C) 1984 by Manx Software Systems */
  386.  
  387. qsort(base, nel, size, compar)
  388. char *base; unsigned nel, size; int (*compar)();
  389. {
  390.     register char *i,*j,*x,*r;
  391.     auto struct stk {
  392.         char *l, *r;
  393.     } stack[16];
  394.     struct stk *sp;
  395.  
  396.     sp = stack;
  397.     r = base + (nel-1)*size;
  398.     for (;;) {
  399.         do {
  400.             x = base + (r-base)/size/2 * size;
  401.             i = base;
  402.             j = r;
  403.             do {
  404.                 while ((*compar)(i,x) < 0)
  405.                     i += size;
  406.                 while ((*compar)(x,j) < 0)
  407.                     j -= size;
  408.                 if (i < j) {
  409.                     swapmem(i, j, size);
  410.                     if (i == x)
  411.                         x = j;
  412.                     else if (j == x)
  413.                         x = i;
  414.                 }
  415.                 if (i <= j) {
  416.                     i += size;
  417.                     j -= size;
  418.                 }
  419.             } while (i <= j);
  420.             if (j-base < r-i) {
  421.                 if (i < r) {    /* stack request for right partition */
  422.                     sp->l = i;
  423.                     sp->r = r;
  424.                     ++sp;
  425.                 }
  426.                 r = j;            /* continue sorting left partition */
  427.             } else {
  428.                 if (base < j) {    /* stack request for left partition */
  429.                     sp->l = base;
  430.                     sp->r = j;
  431.                     ++sp;
  432.                 }
  433.                 base = i;        /* continue sorting right partition */
  434.             }
  435.         } while (base < r);
  436.  
  437.         if (sp <= stack)
  438.             break;
  439.         --sp;
  440.         base = sp->l;
  441.         r = sp->r;
  442.     }
  443. }
  444. scan.c
  445. /* Copyright (C) 1982, 1984 by Manx Software Systems */
  446. #include <ctype.h>
  447.  
  448. #define EOF    -1
  449.  
  450. static int maxwidth;
  451. static int (*gsub)();
  452. char *strchr();
  453.  
  454. scanfmt(getsub, fmt, args)
  455. int (*getsub)(); register char *fmt; register int **args;
  456. {
  457. #ifdef FLOAT
  458.     double atof();
  459. #endif
  460.     long lv;
  461.     register int c, count, base, cc;
  462.     char suppress, lflag, widflg;
  463.     char *cp;
  464.     auto char tlist[130];
  465.     static char list[] = "ABCDEFabcdef9876543210";
  466.     static char vals[] = {
  467.             10,11,12,13,14,15,10,11,12,13,14,15,9,8,7,6,5,4,3,2,1,0
  468.     };
  469.  
  470.     count = 0;
  471.     gsub = getsub;
  472.     while (c = *fmt++) {
  473.         if (c == '%') {
  474.             widflg = lflag = suppress = 0;
  475.             maxwidth = 127;
  476.             if (*fmt == '*') {
  477.                 ++fmt;
  478.                 suppress = 1;
  479.             }
  480.             if (isdigit(*fmt)) {
  481.                 maxwidth = 0;
  482.                 do {
  483.                     maxwidth = maxwidth*10 + *fmt - '0';
  484.                 } while (isdigit(*++fmt));
  485.                 widflg = 1;
  486.             }
  487.             if (*fmt == 'l') {
  488.                 lflag = 1;
  489.                 ++fmt;
  490.             }
  491.     
  492.             switch (cc = *fmt++) {
  493.             case '%':
  494.                 c = '%';
  495.                 goto matchit;
  496.             case 'h':            /* specify short (for compatibility) */
  497.                 lflag = 0;
  498.                 goto decimal;
  499.             case 'D':
  500.                 lflag = 1;
  501.             case 'd':
  502.     decimal:
  503.                 c = 12;
  504.                 base = 10;
  505.                 goto getval;
  506.  
  507.             case 'X':
  508.                 lflag = 1;
  509.             case 'x':
  510.                 c = 0;
  511.                 base = 16;
  512.                 goto getval;
  513.  
  514.             case 'O':
  515.                 lflag = 1;
  516.             case 'o':
  517.                 c = 14;
  518.                 base = 8;
  519.     getval:
  520.                 if (skipblank())
  521.                     goto stopscan;
  522.                 if (getnum(&list[c], &vals[c], base, &lv) == 0)
  523.                     goto stopscan;
  524.                 if (!suppress) {
  525.                     if (lflag)
  526.                         *(long *)(*args++) = lv;
  527.                     else
  528.                         **args++ = lv;
  529.                     ++count;
  530.                 }
  531.                 break;
  532.  
  533. #ifdef FLOAT
  534.             case 'E':
  535.             case 'F':
  536.                 lflag = 1;
  537.             case 'e':
  538.             case 'f':
  539.                 if (skipblank())
  540.                     goto stopscan;
  541.                 if (getflt(tlist))
  542.                     goto stopscan;
  543.                 if (!suppress) {
  544.                     if (lflag)
  545.                         *(double *)(*args++) = atof(tlist);
  546.                     else
  547.                         *(float *)(*args++) = atof(tlist);
  548.                     ++count;
  549.                 }
  550.                 break;
  551. #endif
  552.             case '[':
  553.                 lflag = 0;
  554.                 if (*fmt == '^' || *fmt == '~') {
  555.                     ++fmt;
  556.                     lflag = 1;
  557.                 }
  558.                 for (cp = tlist ; (c = *fmt++) != ']' ; )
  559.                     *cp++ = c;
  560.                 *cp = 0;
  561.                 goto string;
  562.             case 's':
  563.                 lflag = 1;
  564.                 tlist[0] = ' ';
  565.                 tlist[1] = '\t';
  566.                 tlist[2] = '\n';
  567.                 tlist[3] = 0;
  568.     string:
  569.                 if (skipblank())
  570.                     goto stopscan;
  571.     charstring:
  572.                 if (!suppress)
  573.                     cp = (char *)*args++;
  574.                 widflg = 0;
  575.                 while (maxwidth--) {
  576.                     if ((c = (*gsub)(0)) == EOF)
  577.                         break;
  578.                     if (lflag ? (strchr(tlist,c)!=0) : (strchr(tlist,c)==0)) {
  579.                         (*gsub)(1);    /* unget last character */
  580.                         break;
  581.                     }
  582.                     if (!suppress)
  583.                         *cp++ = c;
  584.                     widflg = 1;
  585.                 }
  586.                 if (!widflg)
  587.                     goto stopscan;
  588.                 if (!suppress) {
  589.                     if (cc != 'c')
  590.                         *cp = 0;
  591.                     ++count;
  592.                 }
  593.                 break;
  594.  
  595.             case 'c':
  596.                 if (!widflg)
  597.                     maxwidth = 1;
  598.                 tlist[0] = 0;
  599.                 lflag = 1;
  600.                 goto charstring;
  601.             }
  602.         } else if (isspace(c)) {
  603.             if (skipblank())
  604.                 goto stopscan;
  605.         } else {
  606. matchit:
  607.             if ((*gsub)(0) != c) {
  608.                 (*gsub)(1);
  609.                 goto stopscan;
  610.             }
  611.         }
  612.     }
  613.  
  614. stopscan:
  615.     if (count == 0) {
  616.         if ((*gsub)(0) == EOF)
  617.             return EOF;
  618.         (*gsub)(1);
  619.     }
  620.     return count;
  621. }
  622.  
  623. skipblank()
  624. {
  625.     while (isspace((*gsub)(0)))
  626.         ;
  627.     if ((*gsub)(1) == EOF)
  628.         return EOF;
  629.     return 0;
  630. }
  631.  
  632. #ifdef FLOAT
  633. getflt(buffer)
  634. char *buffer;
  635. {
  636.     register char *cp;
  637.     register int c;
  638.     char decpt, sign, exp;
  639.  
  640.     sign = exp = decpt = 0;
  641.  
  642.     for (cp = buffer ; maxwidth-- ; *cp++ = c) {
  643.         c = (*gsub)(0);
  644.         if (!isdigit(c)) {
  645.             if (!decpt && c == '.')
  646.                 decpt = 1;
  647.             else if (!exp && (c == 'e' || c == 'E') && cp != buffer) {
  648.                 sign = 0;
  649.                 exp = decpt = 1;
  650.                 continue;
  651.             } else if (sign || (c != '-' && c != '+')) {
  652.                 (*gsub)(1);
  653.                 break;
  654.             }
  655.         }
  656.         sign = 1;
  657.     }
  658.     *cp = 0;
  659.     return cp==buffer;
  660. }
  661. #endif
  662.  
  663. getnum(list, values, base, valp)
  664. char *list; char *values; long *valp;
  665. {
  666.     register char *cp;
  667.     register int c, cnt;
  668.     long val;
  669.     int sign;
  670.  
  671.     if (maxwidth <= 0)
  672.         return 0L;
  673.     val = cnt = sign = 0;
  674.     if ((c = (*gsub)(0)) == '-') {
  675.         sign = 1;
  676.         ++cnt;
  677.     } else if (c == '+')
  678.         ++cnt;
  679.     else
  680.         (*gsub)(1);
  681.  
  682.     for ( ; cnt < maxwidth ; ++cnt) {
  683.         if ((cp = strchr(list, c = (*gsub)(0))) == 0) {
  684.             if (base == 16 && val == 0 && (c=='x' || c=='X'))
  685.                 continue;
  686.             (*gsub)(1);
  687.             break;
  688.         }
  689.         val *= base;
  690.         val += values[cp-list];
  691.     }
  692.     if (sign)
  693.         *valp = -val;
  694.     else
  695.         *valp = val;
  696.     return cnt;
  697. }
  698.  
  699. sprintf.c
  700. /* Copyright (C) 1982 by Manx Software Systems */
  701. static char *buff;
  702.  
  703. sprintf(str,fmt,args)
  704. char *str, *fmt; unsigned args;
  705. {
  706.     int spsub();
  707.     register int i;
  708.  
  709.     buff = str;
  710.     i = format(spsub,fmt,&args);
  711.     *buff = 0;
  712.     return i;
  713. }
  714.  
  715. static
  716. spsub(c)
  717. {
  718.     return (*buff++ = c)&0xff;
  719. }
  720.  
  721. sscanf.c
  722. /* Copyright (C) 1983 by Manx Software Systems */
  723. static char *scnstr;
  724. static char quit;
  725.  
  726. sscanf(string, fmt, arg)
  727. char *string, *fmt; int *arg;
  728. {
  729.     int sgetc();
  730.  
  731.     scnstr = string;
  732.     quit = 0;
  733.     return scanfmt(sgetc, fmt, &arg);
  734. }
  735.  
  736. static
  737. sgetc(what)
  738. {
  739.     if (what == 0) {
  740.         if (*scnstr)
  741.             return *scnstr++ & 255;
  742.         quit = 1;
  743.     } else {
  744.         if (!quit)
  745.             return *--scnstr & 255;
  746.     }
  747.     return -1;
  748. }
  749. ;
  750.     if (mdmask&1) {
  751.         if ((chp->c_read = dev->d