Skip to content

Commit

Permalink
cleanup and fixed -m flag parsing issue
Browse files Browse the repository at this point in the history
  • Loading branch information
reginaldford committed Mar 10, 2024
1 parent 5495702 commit cb64a8b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 32 deletions.
Empty file modified sms_src/examples/cxSetParent.sms
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion sms_src/examples/watch.sms
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/local/bin/sms -qm 0.1
#!/usr/local/bin/sms -qm 1.1
# Tiny rendition of the linux 'watch' program
{
let cmd = _args[size(_args) - 1];
Expand Down
14 changes: 0 additions & 14 deletions src/main/object/sm_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,6 @@ sm_object *sm_node_get(sm_node *self, char *needle, int len);
sm_node *sm_node_get_leaf(sm_node *root, char *needle, int len);
/// Set the value of the leaf node addressed by value
void sm_node_set(sm_node *node, int which, sm_object *value);
/** @brief Return the sm_node child index correlating to this character
@param c A-Z,a-z,_, or single quote ("calculus prime symbol")
@note Char ASCII
@note ' is 39
@note 0-9 is 48-57
@note A-Z is 65-90
@note _ is 95
@note a-z is 98-122
@note Total: 64 */
int sm_node_map_index(char c);
/** @brief Inverse of sm_map_index.
@return A letter , underscore, or single quote
@param i Integer from 0 to 63 **/
char sm_node_bit_unindex(int i);
/// Add a child node to root node (parent node)
/// @param where Specifies which character this node represents
bool sm_node_insert(struct sm_node *root, struct sm_node *new_node, int where);
Expand Down
31 changes: 17 additions & 14 deletions src/main/sm_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,32 @@ int sm_is_unit(char c) {

// Parse a c string into an integer specifying a number of bytes.
uint64_t sm_bytelength_parse(char *str, int length) {
char buffer[32]; // 16 characters for the numeric value
for (int i = 0; i < 32; i++) {
char buffer[length]; // 16 characters for the numeric value
int j = 0; // j is index, skipping spaces
for (int i = 0; i <= length; i++) {
char current_char = str[i];
if (current_char == 0) {
buffer[i] = 0;
buffer[j] = 0;
// If no unit is given, assume megabytes (m)
return (uint64_t)atof(buffer) * 1024 * 1024;
uint64_t l = atof(buffer) * 1024 * 1024;
return (double)atof(buffer) * 1024 * 1024;
}
if (sm_is_digit(current_char) || current_char == '.')
buffer[i] = current_char;
else if (sm_is_unit(current_char) != -1) {
if (sm_is_digit(current_char) || current_char == '.') {
buffer[j] = current_char;
j++;
} else if (sm_is_unit(current_char) != -1) {
// 0 means b, 1 means k, etc.
int unit = sm_is_unit(current_char);
int unit_in_bytes = pow(1024, unit);
buffer[i] = 0;
buffer[j] = 0;
j++;
return unit_in_bytes * atof(buffer);
} else if (current_char == 0) {
buffer[i] = 0;
return (uint64_t)atof(buffer);
} else
break;
} else if (current_char == ' ')
continue;
else
continue;
}
return -1;
return atof(buffer);
}

void sm_print_fancy_bytelength(uint64_t bytelength) {
Expand Down
5 changes: 2 additions & 3 deletions src/main/sm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,8 @@ int main(int num_args, char *argv[]) {
printf("-e Print the evaluation of an expression. sms -e \"2*sin(PI/4)\"\n");
printf("-s Run Script file. sms -s script.sms\n");
printf("-i Run a file, then start the REPL. sms -i script.sms\n");
printf("-c Custom argument. Accessed via _args sms -c \"a single string\"\n");
printf("\nIf the -m flag is used, it must be first. sms -m 4 -s x1.sms -i x2.sms\n");
printf("Some flags can be repeated and all flags are executed in order.\n");
printf("-c Custom argument. Accessed via _args. sms -c \"a single string\"\n");
printf("\nDo not put a space after the m flag. sms -m4.4 -s x1.sms -i x2.sms\n");
clean_exit(&env, 0);
break;
case 'q':
Expand Down

0 comments on commit cb64a8b

Please sign in to comment.