spreadsheet: Avoid sharing a dictionary between spreadsheet and client.
[pspp] / src / data / spreadsheet-reader.h
index 960d076b38bdb42d060240c667459650c0fddd97..0f0819b249bbdf6633acbf65949db236611188bc 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 2007, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2007, 2010, 2016 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -45,9 +45,9 @@ bool convert_cell_ref (const char *ref,
                       int *coli, int *rowi);
 
 
-#define _xml(X) (CHAR_CAST (const xmlChar *, X))
+#define _xml(X) (CHAR_CAST (const xmlChar *, (X)))
 
-#define _xmlchar_to_int(X) (atoi(CHAR_CAST (const char *, X)))
+#define _xmlchar_to_int(X) ((X) ? atoi (CHAR_CAST (const char *, (X))) : -1)
 
 enum spreadsheet_type
   {
@@ -59,15 +59,18 @@ enum spreadsheet_type
 
 struct spreadsheet
 {
-  const char *file_name;
+  char *file_name;
 
   enum spreadsheet_type type;
 
   /* The total number of sheets in the "workbook" */
   int n_sheets;
 
-  /* The dictionary */
-  struct dictionary *dict;
+  /* The dictionary for client's reference.
+     Client must clone if it needs a permanent or modifiable copy. */
+  const struct dictionary *dict;
+
+  int ref_cnt;
 };
 
 
@@ -77,9 +80,11 @@ const char * spreadsheet_get_sheet_name (struct spreadsheet *s, int n);
 char * spreadsheet_get_sheet_range (struct spreadsheet *s, int n);
 
 
-char *create_cell_ref (int col0, int row0, int coli, int rowi);
+char * create_cell_ref (int col0, int row0);
+char *create_cell_range (int col0, int row0, int coli, int rowi);
 
-void spreadsheet_close (struct spreadsheet *);
+void spreadsheet_unref (struct spreadsheet *);
+void spreadsheet_ref (struct spreadsheet *);