home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / math / pac / atoi.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-05  |  6.4 KB  |  210 lines

  1. /* atoi.c */
  2. /**********************************************************************
  3. *    File Name     : atoi.c
  4. *    Function      : ascii/decimal/octal/hex converter of pac
  5. *    Author        : Istvan Mohos, 1987
  6. ***********************************************************************/
  7.  
  8. #include "defs.h"
  9. #define ATOIMAP
  10. #include "maps.h"
  11. #undef ATOIMAP
  12.  
  13. byte_conv(from)
  14. int from;
  15. {
  16.     char c, bbuf[10], *bb;
  17.     int pyp, pxp;
  18.     int ri, ffd, value;
  19.     static char *fid = "byte_conv";
  20.  
  21.     _TR
  22.     CYX;
  23.     switch(from) {
  24.         case 4:
  25.             mvaddstr(UTOP + 1, ATOIX, "ENTER 3");
  26.             mvaddstr(UTOP + 2, ATOIX, "DECIMAL");
  27.             mvaddstr(UTOP + 3, ATOIX, "DIGITS ");
  28.             value = -1;
  29.             while(value == -1) {
  30.                 mvaddstr(UTOP, ATOIX, "dec    ");
  31.  
  32.                 ledit(bbuf, a_ed_map, UTOP, ATOIX+4, ATOIX+6, 0, 1, 1);
  33.                 if (!*bbuf)
  34.                     continue;
  35.                 value = 0;
  36.                 upcase(bbuf);
  37.                 bb = bbuf;
  38.                 for (ri = strlen(bbuf); --ri >= 0; bb++) {
  39.                     value *= 10;
  40.                     value += (*bb > 57) ? (*bb - 55) : (*bb - 48);
  41.                 }
  42.                 if (value < 0 || value > 127) {
  43.                     value = -1;
  44.                     continue;
  45.                 }
  46.             }
  47.             move(UTOP, ATOIX);
  48.             printw("dec %3d", value);
  49.  
  50.             move(UTOP + 1, ATOIX);
  51.             if (value == 127)
  52.                 printw("asc DEL");
  53.             else if (value < 33)
  54.                 printw("%s",lotab[value]);
  55.             else
  56.                 printw("asc   %c",value);
  57.  
  58.             move(UTOP + 2, ATOIX);
  59.             printw("oct %.3o", value);
  60.  
  61.             move(UTOP + 3, ATOIX);
  62.             printw("hex  %.2x", value);
  63.             break;
  64.         case 1:
  65.         default:
  66.             ri = 0;
  67. #ifdef sun
  68.             signal(SIGHUP,  Save_sig[ri++]);
  69.             signal(SIGINT,  Save_sig[ri++]);
  70.             signal(SIGQUIT, Save_sig[ri++]);
  71.             signal(SIGTERM, Save_sig[ri++]);
  72. #else
  73.             Save_sig[ri++] = signal(SIGHUP,  SIG_IGN);
  74.             Save_sig[ri++] = signal(SIGINT,  SIG_IGN);
  75.             Save_sig[ri++] = signal(SIGQUIT, SIG_IGN);
  76.             Save_sig[ri++] = signal(SIGTERM, SIG_IGN);
  77. #endif /* sun */
  78.  
  79. #ifndef REALUNIX
  80. #ifdef sun
  81.             signal(SIGTSTP, Save_sig[ri++]);
  82.             signal(SIGCONT, Save_sig[ri++]);
  83. #else
  84.             Save_sig[ri++] = signal(SIGTSTP, SIG_IGN);
  85.             Save_sig[ri++] = signal(SIGCONT, SIG_IGN);
  86. #endif /* sun */
  87. #endif /* !REALUNIX */
  88.  
  89.             mvaddstr(UTOP + 1, ATOIX, "    HIT");
  90.             mvaddstr(UTOP + 2, ATOIX, "    ANY");
  91.             mvaddstr(UTOP + 3, ATOIX, "    KEY");
  92.             mvaddstr(UTOP, ATOIX, "asc    ");
  93.             move(UTOP, ATOIX + 6);
  94.             pfresh();
  95.             ffd = dup(0);
  96.             close(0);
  97.             read(ffd, &c, 1);
  98.             dup(ffd);
  99.             close(ffd);
  100.             value = c & 127;
  101.  
  102.             move(UTOP, ATOIX);
  103.             if (value == 127)
  104.                 printw("asc DEL");
  105.             else if (value < 33)
  106.                 printw("%s",lotab[value]);
  107.             else
  108.                 printw("asc   %c",value);
  109.             move(UTOP + 1, ATOIX);
  110.             printw("dec %3d", value);
  111.             move(UTOP + 2, ATOIX);
  112.             printw("oct %.3o", value);
  113.             move(UTOP + 3, ATOIX);
  114.             printw("hex  %.2x", value);
  115.  
  116.             ri = 0;
  117.             signal(SIGHUP,  Save_sig[ri++]);
  118.             signal(SIGINT,  Save_sig[ri++]);
  119.             signal(SIGQUIT, Save_sig[ri++]);
  120.             signal(SIGTERM, Save_sig[ri++]);
  121.  
  122. #ifndef REALUNIX
  123.             signal(SIGTSTP, Save_sig[ri++]);
  124.             signal(SIGCONT, Save_sig[ri++]);
  125. #endif
  126.             break;
  127.         case 15:
  128.             mvaddstr(UTOP + 1, ATOIX, "ENTER 3");
  129.             mvaddstr(UTOP + 2, ATOIX, "OCTAL  ");
  130.             mvaddstr(UTOP + 3, ATOIX, "DIGITS ");
  131.             value = -1;
  132.             while(value == -1) {
  133.                 mvaddstr(UTOP, ATOIX, "oct    ");
  134.  
  135.                 ledit(bbuf, a_ed_map, UTOP, ATOIX+4, ATOIX+6, 0, 1, 1);
  136.                 if (!*bbuf)
  137.                     continue;
  138.                 value = 0;
  139.                 upcase(bbuf);
  140.                 bb = bbuf;
  141.                 for (ri = strlen(bbuf); --ri >= 0; bb++) {
  142.                     value <<= 3;
  143.                     value += (*bb > 57) ? (*bb - 55) : (*bb - 48);
  144.                 }
  145.                 if (value < 0 || value > 127) {
  146.                     value = -1;
  147.                     continue;
  148.                 }
  149.             }
  150.             move(UTOP, ATOIX);
  151.             printw("oct %.3o", value);
  152.  
  153.             move(UTOP + 1, ATOIX);
  154.             if (value == 127)
  155.                 printw("asc DEL");
  156.             else if (value < 33)
  157.                 printw("%s",lotab[value]);
  158.             else
  159.                 printw("asc   %c",value);
  160.             move(UTOP + 2, ATOIX);
  161.             printw("dec %3d", value);
  162.             move(UTOP + 3, ATOIX);
  163.             printw("hex  %.2x", value);
  164.             break;
  165.         case 24:
  166.             mvaddstr(UTOP + 1, ATOIX, "ENTER 2");
  167.             mvaddstr(UTOP + 2, ATOIX, "HEX    ");
  168.             mvaddstr(UTOP + 3, ATOIX, "DIGITS ");
  169.             value = -1;
  170.             while(value == -1) {
  171.                 mvaddstr(UTOP, ATOIX, "hex    ");
  172.  
  173.                 ledit(bbuf, a_ed_map, UTOP, ATOIX+4, ATOIX+6, 0, 1, 1);
  174.                 if (!*bbuf)
  175.                     continue;
  176.                 value = 0;
  177.                 upcase(bbuf);
  178.                 bb = bbuf;
  179.                 for (ri = strlen(bbuf); --ri >= 0; bb++) {
  180.                     value <<= 4;
  181.                     value += (*bb > 57) ? (*bb - 55) : (*bb - 48);
  182.                 }
  183.                 if (value < 0 || value > 127) {
  184.                     value = -1;
  185.                     continue;
  186.                 }
  187.             }
  188.             move(UTOP, ATOIX);
  189.             printw("hex  %.2x", value);
  190.  
  191.             move(UTOP + 1, ATOIX);
  192.             if (value == 127)
  193.                 printw("asc DEL");
  194.             else if (value < 33)
  195.                 printw("%s",lotab[value]);
  196.             else
  197.                 printw("asc   %c",value);
  198.  
  199.             move(UTOP + 2, ATOIX);
  200.             printw("dec %3d", value);
  201.             move(UTOP + 3, ATOIX);
  202.             printw("oct %.3o", value);
  203.             break;
  204.     }
  205.     PYX;
  206.     pfresh();
  207. TR_
  208. }
  209.  
  210.