- /* slmput.cpp by K.Tsuru */
- // function ID = 204, 261 DARDIX
- /***************
- SLong class
- output
- ****************/
- #ifndef SN_H
- #include "sn.h"
- #endif
- static int putcr(int cr, FILE* out){
- if(cr) putc('\n', out);
- return cr ? 1 : 0;
- }
- static int putdelmt(int d, FILE* out){
- if(d) putc(d, out);
- return d ? 1 : 0;
- }
-
- /*
- It returns n-th digit by a character. n = 0 for first position
- For continuously picking out a static array buff[] is used.
- */
- int SLong::CharNthFig(long n) const{
- static int pos = -1;
- static char buff[DFIGURES+1];
- int p, r;
-
- if(n < 0){ pos = -1; return 0; } //initialize
-
- p = int(n/DFIGURES); //There is in figure[p].
- r = int(n%DFIGURES); //r-th position in figure[p].
-
- if(p != pos){ //renew buff[] and pos
- pos = p;
- fType f = figure(p);
- for(int j = 0; j < DFIGURES; j++){//pack into buff[] in reverse order
- buff[j] = '0' + f%10; // f = 1234 --> buff[] = "4321"
- f /= 10;
- }
- }
- return (int)buff[r];
- }
- /*
- main body, usage : x.Put()
- */
- long SLong::Put(long fU, int pL, int cl, int dm) const{
- if(fU > 0) {
- figUnit = fU; perLine = pL; lineFormat = cl; delmt = dm; // copy to static variable
- } else if(fU == 0){ fU = LONG_MAX; delmt = 0; }
-
- SignCheck(204); // sign == UNDECIDED ?
- FILE* out = FileStream();
-
- SLong temp(*this);
-
- ioCount=0; //counter for output characters
- long f = temp.DFigures();
- long numCount = f; //counter for output digits
- int uCount = 0; //counter for 'fig' figures
- long lunit = perLine ? perLine : (displayWidth+1)/(fU+1); //units per line
-
- if(temp.Sign(204) == 0){ putc('0', out); ioCount++; goto Ret; }
- if(!lunit) lunit = 1;
- //output negative sign
- if( Sign(204) == -1 ){ putc('-', out); ioCount++; }
-
- //integral part
- temp.CharNthFig(-1L);
- while(1){
- putc( temp.CharNthFig(numCount -1), out );
- numCount--; ioCount++;
- if(!numCount) break;
- if( !(numCount % fU) ) { //output one unit
- uCount++;
- if(!(uCount % lunit)){ //reach the end of line
- if(delmt != ' ') ioCount += putdelmt(delmt, out);
- if(lineFormat & CONTINUE){ putc('\\', out); ioCount++; }
- if(lineFormat & CRLF){ putc('\n', out); ioCount++; }
- if(lineFormat == NO_CR) ioCount += putdelmt(delmt, out);
- } else ioCount += putdelmt(delmt, out);
- }
- }
- Ret:
- ioCount += putcr( lineFormat & END_CR, out );
- return --ioCount; //It does not output a delimiter at the end.
- }
slmput.cpp : last modifiled at 2017/07/17 16:56:41(2,435 bytes)
created at 2017/10/07 10:26:49
The creation time of this html file is 2017/11/09 14:52:03 (Thu Nov 09 14:52:03 2017).