Check that the unit argument matches one of the known units, and returns * the conversion factor to meters (you need to divide meters by the conversion * factor to convert to the right unit). * * If the unit is not valid, an error is reported to the client, and a value * less than zero is returned. */
| 126 | * If the unit is not valid, an error is reported to the client, and a value |
| 127 | * less than zero is returned. */ |
| 128 | double extractUnitOrReply(client *c, robj *unit) { |
| 129 | char *u = szFromObj(unit); |
| 130 | |
| 131 | if (!strcmp(u, "m")) { |
| 132 | return 1; |
| 133 | } else if (!strcmp(u, "km")) { |
| 134 | return 1000; |
| 135 | } else if (!strcmp(u, "ft")) { |
| 136 | return 0.3048; |
| 137 | } else if (!strcmp(u, "mi")) { |
| 138 | return 1609.34; |
| 139 | } else { |
| 140 | addReplyError(c, |
| 141 | "unsupported unit provided. please use m, km, ft, mi"); |
| 142 | return -1; |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | /* Input Argument Helper. |
| 147 | * Extract the distance from the specified two arguments starting at 'argv' |
no test coverage detected