On Fri, Jan 28, 2011 at 8:41 PM, Stephan Beal <[email protected]> wrote:

> stephan@ludo:~/cvs/fossil/fossil$ ./fossil time -json -n 2
>

For the curious, here's what the code looks like, minus the "AS" tags i had
to add to the SQL and the new json lib:

in timeline_cmd():

  int const isJson = (NULL == find_option("json","J",0)) ? 0 : 1;
...
  if( isJson ){
    cson_value * cv = NULL;
    int rc;
    blob_appendf(&sql, " LIMIT %d", n);
    rc = cson_sqlite3_sql_to_json( g.db, &cv, blob_str(&sql) );
    blob_reset(&sql);
    if( NULL != cv ){
      cson_output_opt outOpt = cson_output_opt_empty;
      cson_buffer buf = cson_buffer_empty;
      outOpt.addNewline = 0/*we'll do this ourselves below*/;
      outOpt.indentation = 1/*FIXME: make this configurable*/;
      cson_buffer_reserve( &buf, 512 );
      rc = cson_output_buffer( cv, &buf, &outOpt );
      cson_value_free(cv);
      if( 0 == rc ){
        puts((char const *)buf.mem);
      }
      cson_buffer_reserve(&buf, 0);
    }
    if( 0 != rc ){
      fossil_fatal("sql-to-JSON conversion failed with code %d (%s)!",
                   rc, cson_err_string(rc));
    }
  }
// else as before...

There are a couple of fixmes/todos:

- output to cgi_printf() when in CGI mode. First need to find how to set the
response content type to application/json.
- make the indentation configurable, e.g. --indent N. (0=off, 1=1 tab/level,
>1=n spaces/level).
- figure out exactly which data needs to be in there. Currently i'm
piggybacking off of timeline_query_for_tty(), so we get whatever it serves.

-- 
----- stephan beal
http://wanderinghorse.net/home/stephan/
_______________________________________________
fossil-users mailing list
[email protected]
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users

Reply via email to