summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2008-09-07 18:07:38 +0200
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2008-09-07 18:07:38 +0200
commit4ce660903f966504c2828039e355118d4956af4d (patch)
tree366c9f6df367320a8bb1b2c1c23f7dcf71bff7d7
parent7be4bae40736f364d65cfb56067203451da053a0 (diff)
read command from stdin
-rw-r--r--src/pnmcurvedit.cxx39
1 files changed, 37 insertions, 2 deletions
diff --git a/src/pnmcurvedit.cxx b/src/pnmcurvedit.cxx
index bb93099..52a473d 100644
--- a/src/pnmcurvedit.cxx
+++ b/src/pnmcurvedit.cxx
@@ -7,7 +7,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <math.h>
+#include <ctype.h>
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
@@ -15,11 +15,12 @@
#include "CurveEditor.H"
static CurveEditor *ce;
+static char cmd[2048];
static void editor_cb(Fl_Widget* o, void* d) {
double x, y;
- printf("pnmcurve -c ");
+ printf("%s ", cmd);
for (int i = 0; i<ce->get_n(); i++) {
if (i != 0)
printf(",");
@@ -30,6 +31,38 @@ static void editor_cb(Fl_Widget* o, void* d) {
fflush(stdout);
}
+static void
+stdin_cb(int fd, void *d) {
+ char *curve = NULL;
+
+ fgets(cmd, sizeof(cmd), stdin);
+
+ for (int i = strlen(cmd) - 1; i >= 0; i--) {
+ if (isspace(cmd[i])) {
+ cmd[i] = '\0';
+ if (curve)
+ break;
+ } else {
+ curve = &cmd[i];
+ }
+ }
+
+ if (curve) {
+ double X, Y;
+ char *pstr;
+
+ ce->clear();
+ while (pstr = strsep(&curve, ",")) {
+ if (sscanf(pstr, "%lf:%lf", &X, &Y) != 2 ||
+ X < 0 || X > 1 || Y < 0 || Y > 1) {
+ fprintf(stderr, "Could not parse control point %s.\n", pstr);
+ continue;
+ }
+ ce->add_point(X, Y);
+ }
+ }
+}
+
int
main(int argc, char **argv) {
Fl_Double_Window window(800, 600, "pnmcurvedit");
@@ -42,5 +75,7 @@ main(int argc, char **argv) {
window.resizable(ce);
window.show();
+ Fl::add_fd(0, FL_READ, stdin_cb);
+
return Fl::run();
}