Skip to content

Commit

Permalink
Add conditional to fix sign skip if number written as e.g. '-.4' inst…
Browse files Browse the repository at this point in the history
…ead of '-0.4', change name from msolvtextview.c to gtksolver.c
  • Loading branch information
David C. Rankin committed Apr 10, 2019
1 parent c97ae49 commit 8881d9f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
22 changes: 18 additions & 4 deletions src/msolvtextview.c → src/gtksolver.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ void btnsolv_activate (GtkWidget *widget, gpointer data)
app_t *inst = data;
gint line;
size_t i;
gchar *buf, c;
gchar *buf, c, last = 0, prevlast = 0;
gboolean havevalue = FALSE;
GtkTextIter start, end;
GtkTextIter start, end, lastiter, previter;
// GtkTextBuffer *buffer = GTK_TEXT_BUFFER(data);
GtkTextBuffer *buffer;

Expand All @@ -76,14 +76,28 @@ void btnsolv_activate (GtkWidget *widget, gpointer data)
/* get start and end iters for buffer */
gtk_text_buffer_get_start_iter (buffer, &start);
gtk_text_buffer_get_end_iter (buffer, &end);
lastiter = start;

/* advance start iter to beginning of first value */
/* advance start iter to beginning of first value
* (updated to handle -0.4 or -.4)
*/
do {
c = gtk_text_iter_get_char (&start);
if (c == '.' || c == '-' || c == '+' || isdigit (c)) {
if (isdigit (c)) {
// if (last == '.' || last == '-' || last == '+')
if (last == '.' || last == '-' || last == '+') {
if (last == '.' && (prevlast == '-' || prevlast == '+'))
start = previter;
else
start = lastiter;
}
havevalue = TRUE;
break;
}
prevlast = last ? last : c;
last = c;
previter = lastiter;
lastiter = start;
} while (gtk_text_iter_forward_char (&start) &&
!gtk_text_iter_equal (&start, &end));

Expand Down
7 changes: 5 additions & 2 deletions src/mtrx_t.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,14 @@ T *parse_dbl_array (char *buf, size_t *nelem)
errno = 0; /* reset errno before each conversion */
if (n == *nelem) /* check if realloc required */
array = xrealloc_x2 (array, sizeof *array, nelem);
/* skip any non-digit characters */
/* skip any non-digit characters
*
* TODO: update to check digit after "-." (e.g. "-.4")
*/
while (*nptr && ((*nptr != '-' && *nptr != '+' && *nptr != '.' &&
(*nptr < '0' || '9' < *nptr)) ||
((*nptr == '-' || *nptr == '+' || *nptr == '.') &&
(*(nptr+1) < '0' || '9' < *(nptr+1)))))
(*(nptr+1) != '.' && (*(nptr+1) < '0' || '9' < *(nptr+1))))))
nptr++;

if (!*nptr) /* check if at end of buf */
Expand Down

0 comments on commit 8881d9f

Please sign in to comment.