Advertisement
Guest User

Untitled

a guest
May 6th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.71 KB | None | 0 0
  1.                 if (editor.ui.getLineType == TEXT_EDIT_DECIMAL)
  2.                 {
  3.                     // char format_string[8]
  4.                     // char digit[8]
  5.                     // int number_format (could use enum)
  6.                     PT_ASSERT(editor.ui.numLen < 8);
  7.                     // print format string to pad with zeros
  8.                     sprintf(format_string, "%%0%ii", editor.ui.numLen);
  9.                     // clear all digits
  10.                     for (int i = 0; i < editor.ui.numLen; i++) {
  11.                         digit[i] = '0';
  12.                     }
  13.                     for (int i = editor.ui.numLen; i < 8; i++) {
  14.                         digit[i] = 0;
  15.                     }
  16.  
  17.                     if ((rawKey >= '0') && (rawKey <= '9'))
  18.                     {
  19.                         // read value
  20.                         if (editor.ui.numPtr32) {
  21.                             // int32
  22.                             number = editor.ui.numPtr32[0];
  23.                             number_format = 3;
  24.                         } else if (editor.ui.numPtr16) {
  25.                             // int 16
  26.                             number = editor.ui.numPtr16[0];
  27.                             number_format = 2;
  28.                         }
  29.  
  30.                         // print value to string
  31.                         sprintf(digit, format_string, number);
  32.  
  33.                         // overwrite digit with input
  34.                         PT_ASSERT(editor.ui.dstPos < editor.ui.numLen);
  35.                         digit[editor.ui.dstPos] = rawKey;
  36.  
  37.                         // read digits and output number
  38.                         number = atoi(digit);
  39.  
  40.                         // write value
  41.                         switch (number_format) {
  42.                             // float
  43.                             case 4: PT_ASSERT(0); break;
  44.                             // int32
  45.                             case 3: editor.ui.numPtr32[0] = number; break;
  46.                             // int16
  47.                             case 2: editor.ui.numPtr16[0] = number; break;
  48.                             // int8
  49.                             case 1: PT_ASSERT(0); break;
  50.                             // invalid
  51.                             case 0: PT_ASSERT(0); break;
  52.                         }
  53.  
  54.                         textMarkerMoveRight();
  55.                         if (editor.ui.dstPos >= editor.ui.numLen)
  56.                             exitGetTextLine(EDIT_TEXT_UPDATE);
  57.                     }
  58.                 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement