static void DoubleToStr(const double dblNum, char* strDblNum) { double dbl = dblNum; double decNum; int signFlag = 0; int intVal = 0; int intLen = 0; int i; int dCount; // check for negative number if (dbl < 0) { dbl = -1 * dbl; } // get whole number intVal = (int)dbl; intLen = (intVal == 0 ? 1 : IntLen(intVal)); for (i = intLen - 1; i >= 0; i--) { strDblNum[i] = (char)(intVal % 10 + '0'); intVal = intVal / 10; } strDblNum[intLen] = '.'; dCount = intLen + 1; decNum = dbl - (int) dbl; while (dCount < 16) { decNum = decNum * 10; strDblNum[dCount] = (char)((int)decNum + '0'); decNum = decNum - (int)decNum; dCount++; } strDblNum[dCount] = '\0'; }
int main(int argc, char** argv) { if(argc!=2) return 1; int fd; struct stat st; uint8_t *pdata; uint8_t ch,c; size_t shift=0,len; fd=open(argv[1],O_RDONLY); if(fd==-1) return 1; if(fstat(fd,&st)!=0) return 1; if(st.st_size==0) return 1; pdata=(uint8_t*) mmap(0,st.st_size,PROT_READ,MAP_SHARED,fd,0); while(shift<st.st_size) { c=pdata[shift]; if(c==bdct) {ch='d'; write(stdout,&ch,1);} if(c==blst) {ch='l'; write(stdout,&ch,1);} if(c==edct || pdata[shift]==elst) {ch='e'; write(stdout,&ch,1);} if((c>=48 && c<=57) || c=='+' || c=='-') { len=IntLen(pdata,shift,st.st_size); ch='i'; write(stdout,&ch,1); write(stdout,pdata+shift,len); ch='e'; write(stdout,&ch,1); shift+=len-1; } if(c==quo) { len=StrLen(pdata,shift,st.st_size); PrintDec(len); ch=':'; write(stdout,&ch,1); shift++; while(1) { c=pdata[shift]; if(c==quo) break; if(c==scr) { shift++; c=pdata[shift]; if(c=='x') { shift++; ch=Hex2Sym(pdata,shift); shift++; } else { switch(c) { case('n'): {ch='\n'; break;} case('a'): {ch='\a'; break;} case('b'): {ch='\b'; break;} case('e'): {ch='\e'; break;} case('f'): {ch='\f'; break;} case('r'): {ch='\r'; break;} case('t'): {ch='\t'; break;} case('v'): {ch='\v'; break;} default: ch=c; } } } else ch=c; write(stdout,&ch,1); shift++; } }