+struct spreadsheet *
+gnumeric_probe (const char *filename)
+{
+ int ret;
+ struct gnumeric_reader *r = NULL;
+ xmlTextReaderPtr xtr;
+
+ gzFile gz = gzopen (filename, "r");
+
+ if (NULL == gz)
+ return NULL;
+
+ xtr = xmlReaderForIO ((xmlInputReadCallback) gzread,
+ (xmlInputCloseCallback) gzclose, gz,
+ NULL, NULL, 0);
+
+ if (xtr == NULL)
+ return NULL;
+
+ r = xzalloc (sizeof *r);
+
+ r->xtr = xtr;
+ r->sheet_total = -1;
+ r->state = STATE_PRE_INIT;
+
+
+ /* Advance to the start of the workbook.
+ This gives us some confidence that we are actually dealing with a gnumeric
+ spreadsheet.
+ */
+ while ( (r->state != STATE_INIT )
+ && 1 == (ret = xmlTextReaderRead (r->xtr)))
+ {
+ process_node (r);
+ }
+
+ if (ret != 1)
+ {
+ /* Not a gnumeric spreadsheet */
+ free (r);
+ gzclose (gz);
+ return NULL;
+ }
+
+ r->spreadsheet.type = SPREADSHEET_GNUMERIC;
+ r->spreadsheet.sheets = r->sheet_total;
+ r->spreadsheet.make_reader = NULL;
+
+
+ return &r->spreadsheet;
+}
+