1: /*	@(#)mout.c	4.2	6/14/83	*/
   2: 
   3: #include <stdio.h>
   4: #include <mp.h>
   5: m_in(a,b,f) MINT *a; FILE *f;
   6: {   MINT x,y,ten;
   7:     int sign,c;
   8:     short qten,qy;
   9:     xfree(a);
  10:     sign=1;
  11:     ten.len=1;
  12:     ten.val= &qten;
  13:     qten=b;
  14:     x.len=0;
  15:     y.len=1;
  16:     y.val= &qy;
  17:     while((c=getc(f))!=EOF)
  18:     switch(c)
  19:     {
  20:     case '\\':  getc(f);
  21:         continue;
  22:     case '\t':
  23:     case '\n': a->len *= sign;
  24:         xfree(&x);
  25:         return(0);
  26:     case ' ':
  27:         continue;
  28:     case '-': sign = -sign;
  29:         continue;
  30:     default: if(c>='0' && c<= '9')
  31:         {   qy=c-'0';
  32:             mult(&x,&ten,a);
  33:             madd(a,&y,a);
  34:             move(a,&x);
  35:             continue;
  36:         }
  37:         else
  38:         {   VOID ungetc(c,stdin);
  39:             a->len *= sign;
  40:             return(0);
  41:         }
  42:     }
  43:     return(EOF);
  44: }
  45: m_out(a,b,f) MINT *a; FILE *f;
  46: {   int sign,xlen,i;
  47:     short r;
  48:     MINT x;
  49:     char *obuf;
  50:     register char *bp;
  51:     sign=1;
  52:     xlen=a->len;
  53:     if(xlen<0)
  54:     {   xlen= -xlen;
  55:         sign= -1;
  56:     }
  57:     if(xlen==0)
  58:     {   fprintf(f,"0\n");
  59:         return;
  60:     }
  61:     x.len=xlen;
  62:     x.val=xalloc(xlen,"m_out");
  63:     for(i=0;i<xlen;i++) x.val[i]=a->val[i];
  64:     obuf=(char *)malloc(7*xlen);
  65:     bp=obuf+7*xlen-1;
  66:     *bp--=0;
  67:     while(x.len>0)
  68:     {   for(i=0;i<10&&x.len>0;i++)
  69:         {   sdiv(&x,b,&x,&r);
  70:             *bp--=r+'0';
  71:         }
  72:         if(x.len>0) *bp--=' ';
  73:     }
  74:     if(sign==-1) *bp--='-';
  75:     fprintf(f,"%s\n",bp+1);
  76:     free(obuf);
  77:     FREE(x)
  78:     return;
  79: }
  80: sdiv(a,n,q,r) MINT *a,*q; short *r;
  81: {   MINT x,y;
  82:     int sign;
  83:     sign=1;
  84:     x.len=a->len;
  85:     x.val=a->val;
  86:     if(n<0)
  87:     {   sign= -sign;
  88:         n= -n;
  89:     }
  90:     if(x.len<0)
  91:     {   sign = -sign;
  92:         x.len= -x.len;
  93:     }
  94:     s_div(&x,n,&y,r);
  95:     xfree(q);
  96:     q->val=y.val;
  97:     q->len=sign*y.len;
  98:     *r = *r*sign;
  99:     return;
 100: }
 101: s_div(a,n,q,r) MINT *a,*q; short *r;
 102: {   int qlen,i;
 103:     long int x;
 104:     short *qval;
 105:     x=0;
 106:     qlen=a->len;
 107:     qval=xalloc(qlen,"s_div");
 108:     for(i=qlen-1;i>=0;i--)
 109:     {
 110:         x=x*0100000L+a->val[i];
 111:         qval[i]=x/n;
 112:         x=x%n;
 113:     }
 114:     *r=x;
 115:     if(qlen && qval[qlen-1]==0) qlen--;
 116:     q->len=qlen;
 117:     q->val=qval;
 118:     if(qlen==0) shfree(qval);
 119:     return;
 120: }
 121: min(a) MINT *a;
 122: {
 123:     return(m_in(a,10,stdin));
 124: }
 125: omin(a) MINT *a;
 126: {
 127:     return(m_in(a,8,stdin));
 128: }
 129: mout(a) MINT *a;
 130: {
 131:     m_out(a,10,stdout);
 132: }
 133: omout(a) MINT *a;
 134: {
 135:     m_out(a,8,stdout);
 136: }
 137: fmout(a,f) MINT *a; FILE *f;
 138: {   m_out(a,10,f);
 139: }
 140: fmin(a,f) MINT *a; FILE *f;
 141: {
 142:     return(m_in(a,10,f));
 143: }

Defined functions

fmin defined in line 140; never used
fmout defined in line 137; never used
m_in defined in line 5; used 3 times
m_out defined in line 45; used 3 times
min defined in line 121; used 2 times
mout defined in line 129; never used
omin defined in line 125; never used
omout defined in line 133; never used
s_div defined in line 101; used 1 times
  • in line 94
sdiv defined in line 80; used 1 times
  • in line 69
Last modified: 1983-07-26
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 771
Valid CSS Valid XHTML 1.0 Strict