Browse Source

Add NUMERIC compare macros to simplify code

Scott Lahteine 9 years ago
parent
commit
f1ed310322
2 changed files with 6 additions and 4 deletions
  1. 4
    4
      Marlin/Marlin_main.cpp
  2. 2
    0
      Marlin/macros.h

+ 4
- 4
Marlin/Marlin_main.cpp View File

1060
   while (c == ' ') c = seen_pointer[++i];
1060
   while (c == ' ') c = seen_pointer[++i];
1061
   if (c == '-' || c == '+') c = seen_pointer[++i];
1061
   if (c == '-' || c == '+') c = seen_pointer[++i];
1062
   if (c == '.') c = seen_pointer[++i];
1062
   if (c == '.') c = seen_pointer[++i];
1063
-  return (c >= '0' && c <= '9');
1063
+  return NUMERIC(c);
1064
 }
1064
 }
1065
 
1065
 
1066
 float code_value() {
1066
 float code_value() {
6066
   //  - Bypass N[-0-9][0-9]*[ ]*
6066
   //  - Bypass N[-0-9][0-9]*[ ]*
6067
   //  - Overwrite * with nul to mark the end
6067
   //  - Overwrite * with nul to mark the end
6068
   while (*current_command == ' ') ++current_command;
6068
   while (*current_command == ' ') ++current_command;
6069
-  if (*current_command == 'N' && ((current_command[1] >= '0' && current_command[1] <= '9') || current_command[1] == '-')) {
6069
+  if (*current_command == 'N' && NUMERIC_SIGNED(current_command[1])) {
6070
     current_command += 2; // skip N[-0-9]
6070
     current_command += 2; // skip N[-0-9]
6071
-    while (*current_command >= '0' && *current_command <= '9') ++current_command; // skip [0-9]*
6071
+    while (NUMERIC(*current_command)) ++current_command; // skip [0-9]*
6072
     while (*current_command == ' ') ++current_command; // skip [ ]*
6072
     while (*current_command == ' ') ++current_command; // skip [ ]*
6073
   }
6073
   }
6074
   char* starpos = strchr(current_command, '*');  // * should always be the last parameter
6074
   char* starpos = strchr(current_command, '*');  // * should always be the last parameter
6668
     if (*p == 'N') {
6668
     if (*p == 'N') {
6669
       SERIAL_PROTOCOL(' ');
6669
       SERIAL_PROTOCOL(' ');
6670
       SERIAL_ECHO(*p++);
6670
       SERIAL_ECHO(*p++);
6671
-      while ((*p >= '0' && *p <= '9') || *p == '-')
6671
+      while (NUMERIC_SIGNED(*p))
6672
         SERIAL_ECHO(*p++);
6672
         SERIAL_ECHO(*p++);
6673
     }
6673
     }
6674
     SERIAL_PROTOCOLPGM(" P"); SERIAL_PROTOCOL(int(BLOCK_BUFFER_SIZE - movesplanned() - 1));
6674
     SERIAL_PROTOCOLPGM(" P"); SERIAL_PROTOCOL(int(BLOCK_BUFFER_SIZE - movesplanned() - 1));

+ 2
- 0
Marlin/macros.h View File

51
 #define ENABLED(b) _CAT(SWITCH_ENABLED_, b)
51
 #define ENABLED(b) _CAT(SWITCH_ENABLED_, b)
52
 #define DISABLED(b) (!_CAT(SWITCH_ENABLED_, b))
52
 #define DISABLED(b) (!_CAT(SWITCH_ENABLED_, b))
53
 
53
 
54
+#define NUMERIC(a) ((a) >= '0' && '9' >= (a))
55
+#define NUMERIC_SIGNED(a) (NUMERIC(a) || (a) == '-')
54
 #define COUNT(a) (sizeof(a)/sizeof(*a))
56
 #define COUNT(a) (sizeof(a)/sizeof(*a))
55
 
57
 
56
 #endif //__MACROS_H
58
 #endif //__MACROS_H

Loading…
Cancel
Save