From: <prn...@us...> - 2012-09-07 14:14:25
|
Revision: 10973 http://octave.svn.sourceforge.net/octave/?rev=10973&view=rev Author: prnienhuis Date: 2012-09-07 14:14:16 +0000 (Fri, 07 Sep 2012) Log Message: ----------- CDLF to LF Modified Paths: -------------- trunk/octave-forge/main/io/src/cell2csv.cc trunk/octave-forge/main/io/src/csv2cell.cc trunk/octave-forge/main/io/src/csvconcat.cc trunk/octave-forge/main/io/src/csvexplode.cc trunk/octave-forge/main/io/src/xmlread.cc trunk/octave-forge/main/io/src/xmltree.c trunk/octave-forge/main/io/src/xmltree.h trunk/octave-forge/main/io/src/xmltree_read.c trunk/octave-forge/main/io/src/xmltree_read.h Modified: trunk/octave-forge/main/io/src/cell2csv.cc =================================================================== --- trunk/octave-forge/main/io/src/cell2csv.cc 2012-09-07 14:13:02 UTC (rev 10972) +++ trunk/octave-forge/main/io/src/cell2csv.cc 2012-09-07 14:14:16 UTC (rev 10973) @@ -1,116 +1,117 @@ // Copyright (C) 2004 Laurent Mazet <ma...@cr...> -// -// 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 the Free Software -// Foundation; either version 3 of the License, or (at your option) any later -// version. -// -// This program is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -// details. -// -// You should have received a copy of the GNU General Public License along with -// this program; if not, see <http://www.gnu.org/licenses/>. - -#include <fstream> - -#include <octave/oct.h> -#include <octave/Cell.h> - -DEFUN_DLD (cell2csv, args, nargout, - "-*- texinfo -*-\n" - "@deftypefn {Loadable Function} {} cell2csv (@var{file}, @var{c})\n" - "@deftypefnx {Loadable Function} {} cell2csv (@var{file}, @var{c}, @var{sep})\n" - "@deftypefnx {Loadable Function} {} cell2csv (@var{file}, @var{c}, @var{sep}, @var{prot})\n" - "\n" - "Create a CSV file from a cell array. " - "@var{sep} (character value) changes the character used to separate two fields. " - "The default value is a comma " - "(@code{,}). @var{prot} (character value) changes the character used to protect a string. " - "Default value is a double quote (@code{\"}).\n" - "@end deftypefn") { - - /* Check argument */ - if ((args.length() < 2) || (args.length() > 4)) { - print_usage (); - return octave_value(); - } - - /* Get arguments */ - std::string file = args(0).string_value(); - - Cell c = args(1).cell_value(); - - std::string sep = (args.length() > 2) ? args(2).string_value() : ","; - if (sep.length() != 1) { - error("cell2csv: separator can only be one character\n"); - return octave_value(); - } - - std::string prot = (args.length() > 3) ? args(3).string_value() : "\""; - if (prot.length() != 1) { - error("cell2csv: protector can only be one character\n"); - return octave_value(); - } - - /* Open file */ - std::ofstream fd(file.c_str()); - if (!fd.is_open()) { - error("cell2csv: cannot open file %s for writing\n", file.c_str()); - return octave_value(); - } - - /* Concat a cell into a string */ - std::string word; - - /* For each element */ - for (int i=0, il=c.rows(); i<il; i++) { - - for (int j=0, jl=c.columns(); j<jl; j++) { - word = ""; - - /* Add separator */ - if (j != 0) - word += sep; - - if (c(i, j).is_real_scalar()) { - - /* Output real value */ - char tmp[20]; - sprintf(tmp, "%g", c(i, j).double_value()); - word += tmp; + // + // 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 the Free Software + // Foundation; either version 3 of the License, or (at your option) any later + // version. + // + // This program is distributed in the hope that it will be useful, but WITHOUT + // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + // details. + // + // You should have received a copy of the GNU General Public License along with + // this program; if not, see <http://www.gnu.org/licenses/>. + + #include <fstream> + + #include <octave/oct.h> + #include <octave/Cell.h> + + DEFUN_DLD (cell2csv, args, nargout, + "-*- texinfo -*-\n" + "@deftypefn {Loadable Function} {} cell2csv (@var{file}, @var{c})\n" + "@deftypefnx {Loadable Function} {} cell2csv (@var{file}, @var{c}, @var{sep})\n" + "@deftypefnx {Loadable Function} {} cell2csv (@var{file}, @var{c}, @var{sep}, @var{prot})\n" + "\n" + "Create a CSV file from a cell array. " + "@var{sep} (character value) changes the character used to separate two fields. " + "The default value is a comma " + "(@code{,}). @var{prot} (character value) changes the character used to protect a string. " + "Default value is a double quote (@code{\"}).\n" + "@end deftypefn") { + + /* Check argument */ + if ((args.length() < 2) || (args.length() > 4)) { + print_usage (); + return octave_value(); } - - else if (c(i, j).is_string()) { - /* Output string value */ - std::string str = c(i, j).string_value(); - if (str.find(sep) != str.npos) { - size_t pos = 0; - while ((pos=str.find(prot, pos)) != str.npos) { - str.replace(pos, 1, prot+prot); - pos += 2; + + /* Get arguments */ + std::string file = args(0).string_value(); + + Cell c = args(1).cell_value(); + + std::string sep = (args.length() > 2) ? args(2).string_value() : ","; + if (sep.length() != 1) { + error("cell2csv: separator can only be one character\n"); + return octave_value(); + } + + std::string prot = (args.length() > 3) ? args(3).string_value() : "\""; + if (prot.length() != 1) { + error("cell2csv: protector can only be one character\n"); + return octave_value(); + } + + /* Open file */ + std::ofstream fd(file.c_str()); + if (!fd.is_open()) { + error("cell2csv: cannot open file %s for writing\n", file.c_str()); + return octave_value(); + } + + /* Concat a cell into a string */ + std::string word; + + /* For each element */ + for (int i=0, il=c.rows(); i<il; i++) { + + for (int j=0, jl=c.columns(); j<jl; j++) { + word = ""; + + /* Add separator */ + if (j != 0) + word += sep; + + if (c(i, j).is_real_scalar()) { + + /* Output real value */ + char tmp[20]; + sprintf(tmp, "%g", c(i, j).double_value()); + word += tmp; } - str = prot + str + prot; + + else if (c(i, j).is_string()) { + /* Output string value */ + std::string str = c(i, j).string_value(); + if (str.find(sep) != str.npos) { + size_t pos = 0; + while ((pos=str.find(prot, pos)) != str.npos) { + str.replace(pos, 1, prot+prot); + pos += 2; + } + str = prot + str + prot; + } + word += str; + } + + else if (!c(i, j).is_empty()) { + /* Output NaN value */ + warning ("cell2csv: empty cell or not a real or a string value - converted to 'NaN'\n"); + word += "NaN"; + } + + fd << word; } - word += str; + + /* Add end of line */ + fd << std::endl; } - - else if (!c(i, j).is_empty()) { - /* Output NaN value */ - warning ("cell2csv: empty cell or not a real or a string value - converted to 'NaN'\n"); - word += "NaN"; - } - - fd << word; + + /* Close file */ + fd.close(); + + return octave_value(); } - - /* Add end of line */ - fd << std::endl; - } - - /* Close file */ - fd.close(); - - return octave_value(); -} + \ No newline at end of file Modified: trunk/octave-forge/main/io/src/csv2cell.cc =================================================================== --- trunk/octave-forge/main/io/src/csv2cell.cc 2012-09-07 14:13:02 UTC (rev 10972) +++ trunk/octave-forge/main/io/src/csv2cell.cc 2012-09-07 14:14:16 UTC (rev 10973) @@ -1,131 +1,85 @@ // Copyright (C) 2004 Laurent Mazet <ma...@cr...> -// -// 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 the Free Software -// Foundation; either version 3 of the License, or (at your option) any later -// version. -// -// This program is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -// details. -// -// You should have received a copy of the GNU General Public License along with -// this program; if not, see <http://www.gnu.org/licenses/>. - -#include <fstream> - -#include <octave/oct.h> -#include <octave/Cell.h> - -#define MAXSTRINGLENGTH 4096 - -DEFUN_DLD (csv2cell, args, nargout, - "-*- texinfo -*-\n" - "@deftypefn {Loadable Function} {@var{c} = } csv2cell (@var{file})\n" - "@deftypefnx {Loadable Function} {@var{c} = } csv2cell (@var{file}, @var{sep})\n" - "@deftypefnx {Loadable Function} {@var{c} = } csv2cell (@var{file}, @var{sep}, @var{prot})\n" - "\n" - "Read a CSV (Comma Separated Values) file and convert it into a cell array. " - "@var{sep} (a character value) changes the character used to separate two fields. " - "The default value is a comma " - "(@code{,}). @var{prot} (character value) changes the character used to protect a string. " - "The default is a double quote (@code{\"}).\n" - "The maximum line width of the csv file is 4092 characters.\n" - "@end deftypefn") { - - /* Get arguments */ - const int nargin = args.length (); - octave_value_list retval; - if (nargin == 0) - { - error ("csv2cell: not enough input arguments"); - return retval; - } + // + // 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 the Free Software + // Foundation; either version 3 of the License, or (at your option) any later + // version. + // + // This program is distributed in the hope that it will be useful, but WITHOUT + // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + // details. + // + // You should have received a copy of the GNU General Public License along with + // this program; if not, see <http://www.gnu.org/licenses/>. - const std::string file = args (0).string_value (); - - const std::string _sep = (nargin > 1) ? args (1).string_value () : ","; - if (_sep.length() != 1) - { - error ("csv2cell: separator value can only be one character\n"); - return retval; - } - char sep = _sep[0]; - - const std::string _prot = (nargin > 2) ? args (2).string_value () : "\""; - if (_prot.length() != 1) - { - error ("csv2cell: protector value can be only one character\n"); - return retval; - } - char prot = _prot[0]; - - /* Open file */ - std::ifstream fd (file.c_str ()); - if (!fd.is_open ()) - { - error ("csv2cell: cannot open file %s for reading\n", file.c_str()); - return retval; - } - fd.seekg (0, std::ios::end); - long fdend = fd.tellg (); - fd.seekg (0, std::ios::beg); - - if (fd.tellg () >= fdend) - return octave_value (Cell (0, 0)); - - /* Buffers */ - char line [MAXSTRINGLENGTH]; - std::string str, word; - bool inside = false; - - /* Read a line */ - str = ""; - fd.getline (line, MAXSTRINGLENGTH); - while (fd.fail ()) - { - fd.clear (); - str += line; - fd.getline (line, MAXSTRINGLENGTH); - } - str += line; - - /* Parse first to get number of columns */ - int nbcolumns = 0; - for (int i = 0, len = str.length (); i <= len; i++) - if (((i==len) || (str [i] == sep)) && (!inside)) - nbcolumns++; - else if ((inside) && (str [i] == prot) && ((i < len) && (str [i+1] == prot))) - ++i; - else if (str [i] == prot) - inside = !inside; - - /* Read all the file to get number of rows */ - int nbrows = 1; - while (fd.tellg () < fdend) - { - fd.getline (line, MAXSTRINGLENGTH); - while (fd.fail ()) + #include <fstream> + + #include <octave/oct.h> + #include <octave/Cell.h> + + #define MAXSTRINGLENGTH 4096 + + DEFUN_DLD (csv2cell, args, nargout, + "-*- texinfo -*-\n" + "@deftypefn {Loadable Function} {@var{c} = } csv2cell (@var{file})\n" + "@deftypefnx {Loadable Function} {@var{c} = } csv2cell (@var{file}, @var{sep})\n" + "@deftypefnx {Loadable Function} {@var{c} = } csv2cell (@var{file}, @var{sep}, @var{prot})\n" + "\n" + "Read a CSV (Comma Separated Values) file and convert it into a cell array. " + "@var{sep} (a character value) changes the character used to separate two fields. " + "The default value is a comma " + "(@code{,}). @var{prot} (character value) changes the character used to protect a string. " + "The default is a double quote (@code{\"}).\n" + "The maximum line width of the csv file is 4092 characters.\n" + "@end deftypefn") { + + /* Get arguments */ + const int nargin = args.length (); + octave_value_list retval; + if (nargin == 0) { - fd.clear (); - fd.getline (line, MAXSTRINGLENGTH); + error ("csv2cell: not enough input arguments"); + return retval; } - nbrows++; - } - - /* Rewind */ - fd.seekg (0, std::ios::beg); - if (!fd.good ()) - { - error ("csv2cell: cannot reread %s\n", file.c_str ()); - return retval; - } - - /* Read all the file until the end */ - Cell c (nbrows, nbcolumns); - for (int i = 0; i < nbrows; i++) - { + + const std::string file = args (0).string_value (); + + const std::string _sep = (nargin > 1) ? args (1).string_value () : ","; + if (_sep.length() != 1) + { + error ("csv2cell: separator value can only be one character\n"); + return retval; + } + char sep = _sep[0]; + + const std::string _prot = (nargin > 2) ? args (2).string_value () : "\""; + if (_prot.length() != 1) + { + error ("csv2cell: protector value can be only one character\n"); + return retval; + } + char prot = _prot[0]; + + /* Open file */ + std::ifstream fd (file.c_str ()); + if (!fd.is_open ()) + { + error ("csv2cell: cannot open file %s for reading\n", file.c_str()); + return retval; + } + fd.seekg (0, std::ios::end); + long fdend = fd.tellg (); + fd.seekg (0, std::ios::beg); + + if (fd.tellg () >= fdend) + return octave_value (Cell (0, 0)); + + /* Buffers */ + char line [MAXSTRINGLENGTH]; + std::string str, word; + bool inside = false; + /* Read a line */ str = ""; fd.getline (line, MAXSTRINGLENGTH); @@ -136,58 +90,105 @@ fd.getline (line, MAXSTRINGLENGTH); } str += line; - - /* Explode a line into a sub cell */ - word = ""; - inside = false; - int j = 0; - for (int k = 0, len = str.length (); k <= len; k++) + + /* Parse first to get number of columns */ + int nbcolumns = 0; + for (int i = 0, len = str.length (); i <= len; i++) + if (((i==len) || (str [i] == sep)) && (!inside)) + nbcolumns++; + else if ((inside) && (str [i] == prot) && ((i < len) && (str [i+1] == prot))) + ++i; + else if (str [i] == prot) + inside = !inside; + + /* Read all the file to get number of rows */ + int nbrows = 1; + while (fd.tellg () < fdend) { - if (((k == len) || (str [k] == sep)) && (!inside)) + fd.getline (line, MAXSTRINGLENGTH); + while (fd.fail ()) { - /* Check number of columns */ - if (j == nbcolumns) + fd.clear (); + fd.getline (line, MAXSTRINGLENGTH); + } + nbrows++; + } + + /* Rewind */ + fd.seekg (0, std::ios::beg); + if (!fd.good ()) + { + error ("csv2cell: cannot reread %s\n", file.c_str ()); + return retval; + } + + /* Read all the file until the end */ + Cell c (nbrows, nbcolumns); + for (int i = 0; i < nbrows; i++) + { + /* Read a line */ + str = ""; + fd.getline (line, MAXSTRINGLENGTH); + while (fd.fail ()) + { + fd.clear (); + str += line; + fd.getline (line, MAXSTRINGLENGTH); + } + str += line; + + /* Explode a line into a sub cell */ + word = ""; + inside = false; + int j = 0; + for (int k = 0, len = str.length (); k <= len; k++) + { + if (((k == len) || (str [k] == sep)) && (!inside)) { - fd.close (); - error ("csv2cell: incorrect CSV file, line %d too long\n", i+1); - return retval; + /* Check number of columns */ + if (j == nbcolumns) + { + fd.close (); + error ("csv2cell: incorrect CSV file, line %d too long\n", i+1); + return retval; + } + + /* Check if scalar */ + const char *word_str = word.c_str (); + char *err; + double val = strtod (word_str, &err); + + /* Store into the cell */ + c (i, j++) = ((word == "") || (err != word_str+word.length())) ? + octave_value (word) : octave_value (val); + word = ""; } - - /* Check if scalar */ - const char *word_str = word.c_str (); - char *err; - double val = strtod (word_str, &err); - - /* Store into the cell */ - c (i, j++) = ((word == "") || (err != word_str+word.length())) ? - octave_value (word) : octave_value (val); - word = ""; + else if ((inside) && (str[k]==prot) && ((k<len) && (str[k+1]==prot))) + { + /* Insisde a string */ + word += prot; + ++k; + } + else if (str[k] == prot) + /* Changing */ + inside = !inside; + else + word += str[k]; } - else if ((inside) && (str[k]==prot) && ((k<len) && (str[k+1]==prot))) + + /* Check number of columns */ + if (j != nbcolumns) { - /* Insisde a string */ - word += prot; - ++k; + fd.close (); + error ("csv2cell: incorrect CSV file, line %d too short\n", i+1); + return retval; } - else if (str[k] == prot) - /* Changing */ - inside = !inside; - else - word += str[k]; } - - /* Check number of columns */ - if (j != nbcolumns) - { - fd.close (); - error ("csv2cell: incorrect CSV file, line %d too short\n", i+1); - return retval; - } + + /* Close file */ + fd.close (); + + retval (0) = c; + return retval; } - - /* Close file */ - fd.close (); - - retval (0) = c; - return retval; -} + \ No newline at end of file Modified: trunk/octave-forge/main/io/src/csvconcat.cc =================================================================== --- trunk/octave-forge/main/io/src/csvconcat.cc 2012-09-07 14:13:02 UTC (rev 10972) +++ trunk/octave-forge/main/io/src/csvconcat.cc 2012-09-07 14:14:16 UTC (rev 10973) @@ -1,98 +1,99 @@ // Copyright (C) 2004 Laurent Mazet <ma...@cr...> -// -// 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 the Free Software -// Foundation; either version 3 of the License, or (at your option) any later -// version. -// -// This program is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -// details. -// -// You should have received a copy of the GNU General Public License along with -// this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> -#include <octave/Cell.h> - -DEFUN_DLD (csvconcat, args, nargout, - "-*- texinfo -*-\n" - "@deftypefn {Loadable Function} {@var{str} = } csvconcat (@var{c})\n" - "@deftypefnx {Loadable Function} {@var{str} = } csvconcat (@var{c}, @var{sep})\n" - "@deftypefnx {Loadable Function} {@var{str} = } csvconcat (@var{c}, @var{sep}, @var{prot})\n" - "\n" - "Concatenate a cell into a CSV string or array of strings. " - "@var{sep} (character value) changes the character used to separate two fields. " - "The default value is a comma " - "(@code{,}). @var{prot} (character value) changes the character used to protect a string. " - "The default is a double quote (@code{\"}).\n" - "@end deftypefn") { - - /* Check argument */ - if ((args.length() < 1) || (args.length() > 3)) { - print_usage (); - return octave_value(); - } - - /* Get arguments */ - Cell c = args(0).cell_value(); - - std::string sep = (args.length() > 1) ? args(1).string_value() : ","; - if (sep.length() != 1) { - error("csvconcat: separator can only be one character\n"); - return octave_value(); - } - - std::string prot = (args.length() > 2) ? args(2).string_value() : "\""; - if (prot.length() != 1) { - error("csvconcat: protector can only be one character\n"); - return octave_value(); - } - - /* Concat a cell into a string */ - string_vector vec(c.rows()); - std::string word; - - /* For each element */ - for (int i=0, il=c.rows(); i<il; i++) { - word = ""; - for (int j=0, jl=c.columns(); j<jl; j++) { - - /* Add separator */ - if (j != 0) - word += sep; - - if (c(i, j).is_real_scalar()) { - - /* Output real value */ - char tmp[20]; - sprintf(tmp, "%g", c(i, j).double_value()); - word += tmp; + // + // 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 the Free Software + // Foundation; either version 3 of the License, or (at your option) any later + // version. + // + // This program is distributed in the hope that it will be useful, but WITHOUT + // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + // details. + // + // You should have received a copy of the GNU General Public License along with + // this program; if not, see <http://www.gnu.org/licenses/>. + + #include <octave/oct.h> + #include <octave/Cell.h> + + DEFUN_DLD (csvconcat, args, nargout, + "-*- texinfo -*-\n" + "@deftypefn {Loadable Function} {@var{str} = } csvconcat (@var{c})\n" + "@deftypefnx {Loadable Function} {@var{str} = } csvconcat (@var{c}, @var{sep})\n" + "@deftypefnx {Loadable Function} {@var{str} = } csvconcat (@var{c}, @var{sep}, @var{prot})\n" + "\n" + "Concatenate a cell into a CSV string or array of strings. " + "@var{sep} (character value) changes the character used to separate two fields. " + "The default value is a comma " + "(@code{,}). @var{prot} (character value) changes the character used to protect a string. " + "The default is a double quote (@code{\"}).\n" + "@end deftypefn") { + + /* Check argument */ + if ((args.length() < 1) || (args.length() > 3)) { + print_usage (); + return octave_value(); } - - else if (c(i, j).is_string()) { - /* Output string value */ - std::string str = c(i, j).string_value(); - if (str.find(sep) != str.npos) { - unsigned int pos = 0; - while ((pos=str.find(prot, pos)) != str.npos) { - str.replace(pos, 1, prot+prot); - pos += 2; - } - str = prot + str + prot; - } - word += str; + + /* Get arguments */ + Cell c = args(0).cell_value(); + + std::string sep = (args.length() > 1) ? args(1).string_value() : ","; + if (sep.length() != 1) { + error("csvconcat: separator can only be one character\n"); + return octave_value(); } - - else { - /* Output NaN value */ - warning ("csvconcat: empty cell or not a real or string value - converted to 'NaN'\n"); - word += "NaN"; + + std::string prot = (args.length() > 2) ? args(2).string_value() : "\""; + if (prot.length() != 1) { + error("csvconcat: protector can only be one character\n"); + return octave_value(); } + + /* Concat a cell into a string */ + string_vector vec(c.rows()); + std::string word; + + /* For each element */ + for (int i=0, il=c.rows(); i<il; i++) { + word = ""; + for (int j=0, jl=c.columns(); j<jl; j++) { + + /* Add separator */ + if (j != 0) + word += sep; + + if (c(i, j).is_real_scalar()) { + + /* Output real value */ + char tmp[20]; + sprintf(tmp, "%g", c(i, j).double_value()); + word += tmp; + } + + else if (c(i, j).is_string()) { + /* Output string value */ + std::string str = c(i, j).string_value(); + if (str.find(sep) != str.npos) { + unsigned int pos = 0; + while ((pos=str.find(prot, pos)) != str.npos) { + str.replace(pos, 1, prot+prot); + pos += 2; + } + str = prot + str + prot; + } + word += str; + } + + else { + /* Output NaN value */ + warning ("csvconcat: empty cell or not a real or string value - converted to 'NaN'\n"); + word += "NaN"; + } + } + vec(i) = word; + } + + return octave_value(vec); } - vec(i) = word; - } - - return octave_value(vec); -} + \ No newline at end of file Modified: trunk/octave-forge/main/io/src/csvexplode.cc =================================================================== --- trunk/octave-forge/main/io/src/csvexplode.cc 2012-09-07 14:13:02 UTC (rev 10972) +++ trunk/octave-forge/main/io/src/csvexplode.cc 2012-09-07 14:14:16 UTC (rev 10973) @@ -1,96 +1,97 @@ // Copyright (C) 2004 Laurent Mazet <ma...@cr...> -// -// 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 the Free Software -// Foundation; either version 3 of the License, or (at your option) any later -// version. -// -// This program is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -// details. -// -// You should have received a copy of the GNU General Public License along with -// this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> -#include <octave/Cell.h> - -DEFUN_DLD (csvexplode, args, nargout, - "-*- texinfo -*-\n" - "@deftypefn {Loadable Function} {@var{c} =} csvexplode (@var{str})\n" - "@deftypefnx {Loadable Function} {@var{c} =} csvexplode (@var{str}, @var{sep})\n" - "@deftypefnx {Loadable Function} {@var{c} =} csvexplode (@var{str}, @var{sep}, @var{prot})\n" - "\n" - "Explode a CSV string into a cell. " - "@var{sep} (character value) changes the character used to separate two fields. " - "The default value is a comma (@code{,}). @var{prot} (character value) changes " - "the character used to protect a string. The default is a double quote (@code{\"}).\n" - "@end deftypefn") { - - /* Check argument */ - if ((args.length() < 1) || (args.length() > 3)) { - print_usage (); - return octave_value(); - } - - /* Get arguments */ - if (!args(0).is_string()) { - if (args(0).is_cell()) - return octave_value(args(0)); - else - return octave_value(Cell(args(0))); - } - std::string str = args(0).string_value(); - - std::string _sep = (args.length() > 1) ? args(1).string_value() : ","; - if (_sep.length() != 1) { - error("csvexplode: separator can only be one character\n"); - return octave_value(); - } - char sep = _sep[0]; - - std::string _prot = (args.length() > 2) ? args(2).string_value() : "\""; - if (_prot.length() != 1) { - error("csvexplode: protector can only be one character\n"); - return octave_value(); - } - char prot = _prot[0]; - - /* Explode a line into a cell */ - Cell retval; - std::string word; - bool inside = false; - for (int i=0, len=str.length(); i<=len; i++) { - if (((i==len) || (str[i] == sep)) && (!inside)) { - - /* Extand cell */ - retval.resize(dim_vector(1, retval.columns()+1)); - - /* Check if scalar */ - const char *word_str=word.c_str(); - char *err; - double val = strtod (word_str, &err); - - /* Store into the cell */ - retval(0, retval.columns()-1) = - ((word == "") || (err != word_str+word.length())) ? - octave_value(word) : octave_value(val); - - word = ""; + // + // 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 the Free Software + // Foundation; either version 3 of the License, or (at your option) any later + // version. + // + // This program is distributed in the hope that it will be useful, but WITHOUT + // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + // details. + // + // You should have received a copy of the GNU General Public License along with + // this program; if not, see <http://www.gnu.org/licenses/>. + + #include <octave/oct.h> + #include <octave/Cell.h> + + DEFUN_DLD (csvexplode, args, nargout, + "-*- texinfo -*-\n" + "@deftypefn {Loadable Function} {@var{c} =} csvexplode (@var{str})\n" + "@deftypefnx {Loadable Function} {@var{c} =} csvexplode (@var{str}, @var{sep})\n" + "@deftypefnx {Loadable Function} {@var{c} =} csvexplode (@var{str}, @var{sep}, @var{prot})\n" + "\n" + "Explode a CSV string into a cell. " + "@var{sep} (character value) changes the character used to separate two fields. " + "The default value is a comma (@code{,}). @var{prot} (character value) changes " + "the character used to protect a string. The default is a double quote (@code{\"}).\n" + "@end deftypefn") { + + /* Check argument */ + if ((args.length() < 1) || (args.length() > 3)) { + print_usage (); + return octave_value(); + } + + /* Get arguments */ + if (!args(0).is_string()) { + if (args(0).is_cell()) + return octave_value(args(0)); + else + return octave_value(Cell(args(0))); + } + std::string str = args(0).string_value(); + + std::string _sep = (args.length() > 1) ? args(1).string_value() : ","; + if (_sep.length() != 1) { + error("csvexplode: separator can only be one character\n"); + return octave_value(); + } + char sep = _sep[0]; + + std::string _prot = (args.length() > 2) ? args(2).string_value() : "\""; + if (_prot.length() != 1) { + error("csvexplode: protector can only be one character\n"); + return octave_value(); + } + char prot = _prot[0]; + + /* Explode a line into a cell */ + Cell retval; + std::string word; + bool inside = false; + for (int i=0, len=str.length(); i<=len; i++) { + if (((i==len) || (str[i] == sep)) && (!inside)) { + + /* Extand cell */ + retval.resize(dim_vector(1, retval.columns()+1)); + + /* Check if scalar */ + const char *word_str=word.c_str(); + char *err; + double val = strtod (word_str, &err); + + /* Store into the cell */ + retval(0, retval.columns()-1) = + ((word == "") || (err != word_str+word.length())) ? + octave_value(word) : octave_value(val); + + word = ""; + } + else if ((inside) && (str[i]==prot) && ((i<len) && (str[i+1]==prot))) { + + /* Insisde a string */ + word += prot; + ++i; + } + else if (str[i] == prot) + /* Changing */ + inside = !inside; + else + word += str[i]; + } + + return octave_value(retval); } - else if ((inside) && (str[i]==prot) && ((i<len) && (str[i+1]==prot))) { - - /* Insisde a string */ - word += prot; - ++i; - } - else if (str[i] == prot) - /* Changing */ - inside = !inside; - else - word += str[i]; - } - - return octave_value(retval); -} + \ No newline at end of file Modified: trunk/octave-forge/main/io/src/xmlread.cc =================================================================== --- trunk/octave-forge/main/io/src/xmlread.cc 2012-09-07 14:13:02 UTC (rev 10972) +++ trunk/octave-forge/main/io/src/xmlread.cc 2012-09-07 14:14:16 UTC (rev 10973) @@ -1,151 +1,152 @@ // Copyright (C) 2004 Laurent Mazet <ma...@cr...> -// -// 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 the Free Software -// Foundation; either version 3 of the License, or (at your option) any later -// version. -// -// This program is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -// details. -// -// You should have received a copy of the GNU General Public License along with -// this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> -#include <octave/lo-ieee.h> -#include <octave/oct-map.h> -#include <octave/Cell.h> - -extern "C" { -#include "xmltree.h" -#include "xmltree_read.h" -} - -octave_value get_element (element *root) { - int length, rows, columns; - - string_vector tmp_array; - ComplexMatrix tmp_matrix; - Octave_map tmp_structure; - Cell tmp_cell; - octave_value_list tmp_list; - - octave_value retval; - - if (!root) - return retval; - - switch (root->def_value) { - case value_scalar: - switch (root->const_value) { - case const_true: retval = octave_value(true); break; - case const_false: retval = octave_value(false); break; - case const_inf: retval = octave_value(octave_Inf); break; - case const_neginf: retval = octave_value(-octave_Inf); break; - case const_nan: retval = octave_value(octave_NaN); break; - case const_na: retval = octave_value(octave_NA); break; - case const_undef: retval = octave_value(root->scalar_value); break; + // + // 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 the Free Software + // Foundation; either version 3 of the License, or (at your option) any later + // version. + // + // This program is distributed in the hope that it will be useful, but WITHOUT + // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + // details. + // + // You should have received a copy of the GNU General Public License along with + // this program; if not, see <http://www.gnu.org/licenses/>. + + #include <octave/oct.h> + #include <octave/lo-ieee.h> + #include <octave/oct-map.h> + #include <octave/Cell.h> + + extern "C" { + #include "xmltree.h" + #include "xmltree_read.h" } - break; - - case value_complex: - retval = - octave_value(Complex(get_element(root->child).double_value(), - get_element(root->child->next).double_value())); - break; - - case value_string: - retval = octave_value(root->string_value); - break; - - case value_array: - rows = root->rows; - root = root->child; - tmp_array = string_vector(rows); - for (int k=0; (k<rows) && (root); k++, root = root->next) - tmp_array(k) = get_element(root).string_value(); - retval = octave_value(tmp_array); - break; - - case value_matrix: - rows = root->rows; - columns = root->columns; - root = root->child; - tmp_matrix = ComplexMatrix(rows, columns); - for (int k=0; (k<rows) && (root); k++) - for (int l=0; (l<columns) && (root); l++, root = root->next) - tmp_matrix(k, l) = get_element(root).complex_value(); - if (tmp_matrix.all_elements_are_real()) - retval = octave_value(real(tmp_matrix)); - else - retval = octave_value(tmp_matrix); - break; - - case value_structure: - root = root->child; - for (int k=0; root; root = root->next) - if (root->name) - tmp_structure.assign(root->name, get_element(root)); - else { - char *name = new char[7]; - sprintf (name, "__%04d", k++); - warning ("no field name in structure."); - tmp_structure.assign(name, get_element(root)); - delete[] name; + + octave_value get_element (element *root) { + int length, rows, columns; + + string_vector tmp_array; + ComplexMatrix tmp_matrix; + Octave_map tmp_structure; + Cell tmp_cell; + octave_value_list tmp_list; + + octave_value retval; + + if (!root) + return retval; + + switch (root->def_value) { + case value_scalar: + switch (root->const_value) { + case const_true: retval = octave_value(true); break; + case const_false: retval = octave_value(false); break; + case const_inf: retval = octave_value(octave_Inf); break; + case const_neginf: retval = octave_value(-octave_Inf); break; + case const_nan: retval = octave_value(octave_NaN); break; + case const_na: retval = octave_value(octave_NA); break; + case const_undef: retval = octave_value(root->scalar_value); break; + } + break; + + case value_complex: + retval = + octave_value(Complex(get_element(root->child).double_value(), + get_element(root->child->next).double_value())); + break; + + case value_string: + retval = octave_value(root->string_value); + break; + + case value_array: + rows = root->rows; + root = root->child; + tmp_array = string_vector(rows); + for (int k=0; (k<rows) && (root); k++, root = root->next) + tmp_array(k) = get_element(root).string_value(); + retval = octave_value(tmp_array); + break; + + case value_matrix: + rows = root->rows; + columns = root->columns; + root = root->child; + tmp_matrix = ComplexMatrix(rows, columns); + for (int k=0; (k<rows) && (root); k++) + for (int l=0; (l<columns) && (root); l++, root = root->next) + tmp_matrix(k, l) = get_element(root).complex_value(); + if (tmp_matrix.all_elements_are_real()) + retval = octave_value(real(tmp_matrix)); + else + retval = octave_value(tmp_matrix); + break; + + case value_structure: + root = root->child; + for (int k=0; root; root = root->next) + if (root->name) + tmp_structure.assign(root->name, get_element(root)); + else { + char *name = new char[7]; + sprintf (name, "__%04d", k++); + warning ("no field name in structure."); + tmp_structure.assign(name, get_element(root)); + delete[] name; + } + retval = octave_value(tmp_structure); + break; + + case value_list: + length = root->length; + root = root->child; + //tmp_list = octave_value_list(length); + for (int k=0; (k<length) && (root); k++, root = root->next) + tmp_list(k) = get_element(root); + retval = octave_value(tmp_list); + break; + + case value_cell: + rows = root->rows; + columns = root->columns; + root = root->child; + tmp_cell = Cell(rows, columns); + for (int k=0; (k<rows) && (root); k++) + for (int l=0; (l<columns) && (root); l++, root = root->next) + tmp_cell(k, l) = get_element(root); + retval = octave_value(tmp_cell); + break; + + default: + warning ("unknown type.\n"); } - retval = octave_value(tmp_structure); - break; - - case value_list: - length = root->length; - root = root->child; - //tmp_list = octave_value_list(length); - for (int k=0; (k<length) && (root); k++, root = root->next) - tmp_list(k) = get_element(root); - retval = octave_value(tmp_list); - break; - case value_cell: - rows = root->rows; - columns = root->columns; - root = root->child; - tmp_cell = Cell(rows, columns); - for (int k=0; (k<rows) && (root); k++) - for (int l=0; (l<columns) && (root); l++, root = root->next) - tmp_cell(k, l) = get_element(root); - retval = octave_value(tmp_cell); - break; - - default: - warning ("unknown type.\n"); - } - - return retval; -} - -DEFUN_DLD (xmlread, args, nargout, - "-*- texinfo -*-\n" - "@deftypefn {Loadable Function} {@var{value} =} xmlread(@var{filename})\n" - "Read a @var{value} from @var{filename} as an XML file\n" - "@end deftypefn") { - - /* Check argument */ - if (args.length() != 1) { - print_usage (); - return octave_value_list(); - } - - /* Read file */ - std::string filename = args(0).string_value(); - element *root = read_xmltree(filename.c_str()); - if (!root) - return octave_value_list(); - - /* step down into the element tree */ - octave_value retval = get_element (root->child); - free_element (root); - - return retval; -} + return retval; + } + + DEFUN_DLD (xmlread, args, nargout, + "-*- texinfo -*-\n" + "@deftypefn {Loadable Function} {@var{value} =} xmlread(@var{filename})\n" + "Read a @var{value} from @var{filename} as an XML file\n" + "@end deftypefn") { + + /* Check argument */ + if (args.length() != 1) { + print_usage (); + return octave_value_list(); + } + + /* Read file */ + std::string filename = args(0).string_value(); + element *root = read_xmltree(filename.c_str()); + if (!root) + return octave_value_list(); + + /* step down into the element tree */ + octave_value retval = get_element (root->child); + free_element (root); + + return retval; + } + \ No newline at end of file Modified: trunk/octave-forge/main/io/src/xmltree.c =================================================================== --- trunk/octave-forge/main/io/src/xmltree.c 2012-09-07 14:13:02 UTC (rev 10972) +++ trunk/octave-forge/main/io/src/xmltree.c 2012-09-07 14:14:16 UTC (rev 10973) @@ -1,171 +1,172 @@ // Copyright (C) 2004 Laurent Mazet <ma...@cr...> -// -// 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 the Free Software -// Foundation; either version 3 of the License, or (at your option) any later -// version. -// -// This program is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -// details. -// -// You should have received a copy of the GNU General Public License along with -// this program; if not, see <http://www.gnu.org/licenses/>. - -#include <stdio.h> -#include <stdlib.h> - -#include "xmltree.h" - -element *new_element () { - - element *new; - new = (element *) malloc (sizeof(element)); - if (!new) - perror("xmltree: not enough memory for new_element()\n"); - - new->next = new->child = NULL; - - new->def_value = value_undef; - new->const_value = const_undef; - new->scalar_value = 0; - new->string_value = NULL; - - new->name = NULL; - new->length = new->rows = new->columns = new->nb_elements = 0; - - return new; -} - -element *new_next (element *pred) { - - element *new = new_element(); - - if (pred) - pred->next = new; - - return new; -} - -element *new_child (element *father) { - - element *new = new_element(); - - if (father) - father->child = new; - - return new; -} - -void free_element (element *root) { - - if (!root) - return; - - if (root->next) - free_element (root->next); - if (root->child) - free_element (root->child); - - if (root->string_value) - free (root->string_value); - if (root->name) - free (root->name); - - free (root); -} - -void print_level(int l) { - int i; - for (i=0; i<l; i++) - printf (" "); -} - -void print_element (element *root, int l) { - - if (!root) - return; - - if (root->name) { - print_level(l); - printf ("name: %s\n", root->name); - } - - print_level(l); - switch (root->def_value) { - case value_scalar: - printf ("scalar: "); - switch (root->const_value) { - case const_true: printf ("true\n"); break; - case const_false: printf ("false\n"); break; - case const_inf: printf ("inf\n"); break; - case const_neginf: printf ("neginf\n"); break; - case const_nan: printf ("nan\n"); break; - case const_na: printf ("na\n"); break; - case const_undef: printf ("%f\n", root->scalar_value); break; + // + // 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 the Free Software + // Foundation; either version 3 of the License, or (at your option) any later + // version. + // + // This program is distributed in the hope that it will be useful, but WITHOUT + // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + // details. + // + // You should have received a copy of the GNU General Public License along with + // this program; if not, see <http://www.gnu.org/licenses/>. + + #include <stdio.h> + #include <stdlib.h> + + #include "xmltree.h" + + element *new_element () { + + element *new; + new = (element *) malloc (sizeof(element)); + if (!new) + perror("xmltree: not enough memory for new_element()\n"); + + new->next = new->child = NULL; + + new->def_value = value_undef; + new->const_value = const_undef; + new->scalar_value = 0; + new->string_value = NULL; + + new->name = NULL; + new->length = new->rows = new->columns = new->nb_elements = 0; + + return new; } - break; - case value_data: - printf ("data:\n"); - break; - case value_complex: - printf ("complex:\n"); - break; - case value_string: - printf ("string (%d): %s\n", root->length, root->string_value); - break; - case value_array: - printf ("array (%d):\n", root->rows); - break; - case value_matrix: - printf ("matrix (%d, %d):\n", root->rows, root->columns); - break; - case value_structure: - printf ("structure:\n"); - break; - case value_list: - printf ("list (%d):\n", root->length); - break; - case value_cell: - printf ("cell (%d, %d):\n", root->rows, root->columns); - break; - default: - printf ("???:\n"); - } - - if (root->child) { - print_level(l); - printf ("child:\n"); - print_element (root->child, l+1); - } - - if (root->next) { - print_level(l); - printf ("next:\n"); - print_element (root->next, l); - } -} - -list *new_list(list *father) { - - list *new; - new = (list *) malloc (sizeof(list)); - if (!new) - perror("xmltree: not enough memory for new_list()\n"); - - new->prev = father; - - new->root = NULL; - - return new; -} - -list *pop_list(list *child) { - list *father; - - father = child->prev; - free (child); - - return father; -} + + element *new_next (element *pred) { + + element *new = new_element(); + + if (pred) + pred->next = new; + + return new; + } + + element *new_child (element *father) { + + element *new = new_element(); + + if (father) + father->child = new; + + return new; + } + + void free_element (element *root) { + + if (!root) + return; + + if (root->next) + free_element (root->next); + if (root->child) + free_element (root->child); + + if (root->string_value) + free (root->string_value); + if (root->name) + free (root->name); + + free (root); + } + + void print_level(int l) { + int i; + for (i=0; i<l; i++) + printf (" "); + } + + void print_element (element *root, int l) { + + if (!root) + return; + + if (root->name) { + print_level(l); + printf ("name: %s\n", root->name); + } + + print_level(l); + switch (root->def_value) { + case value_scalar: + printf ("scalar: "); + switch (root->const_value) { + case const_true: printf ("true\n"); break; + case const_false: printf ("false\n"); break; + case const_inf: printf ("inf\n"); break; + case const_neginf: printf ("neginf\n"); break; + case const_nan: printf ("nan\n"); break; + case const_na: printf ("na\n"); break; + case const_undef: printf ("%f\n", root->scalar_value); break; + } + break; + case value_data: + printf ("data:\n"); + break; + case value_complex: + printf ("complex:\n"); + break; + case value_string: + printf ("string (%d): %s\n", root->length, root->string_value); + break; + case value_array: + printf ("array (%d):\n", root->rows); + break; + case value_matrix: + printf ("matrix (%d, %d):\n", root->rows, root->columns); + break; + case value_structure: + printf ("structure:\n"); + break; + case value_list: + printf ("list (%d):\n", root->length); + break; + case value_cell: + printf ("cell (%d, %d):\n", root->rows, root->columns); + break; + default: + printf ("???:\n"); + } + + if (root->child) { + print_level(l); + printf ("child:\n"); + print_element (root->child, l+1); + } + + if (root->next) { + print_level(l); + printf ("next:\n"); + print_element (root->next, l); + } + } + + list *new_list(list *father) { + + list *new; + new = (list *) malloc (sizeof(list)); + if (!new) + perror("xmltree: not enough memory for new_list()\n"); + + new->prev = father; + + new->root = NULL; + + return new; + } + + list *pop_list(list *child) { + list *father; + + father = child->prev; + free (child); + + return father; + } + \ No newline at end of file Modified: trunk/octave-forge/main/io/src/xmltree.h =================================================================== --- trunk/octave-forge/main/io/src/xmltree.h 2012-09-07 14:13:02 UTC (rev 10972) +++ trunk/octave-forge/main/io/src/xmltree.h 2012-09-07 14:14:16 UTC (rev 10973) @@ -1,80 +1,81 @@ // Copyright (C) 2004 Laurent Mazet <ma...@cr...> -// -// 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 the Free Software -// Foundation; either version 3 of the License, or (at your option) any later -// version. -// -// This program is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -// details. -// -// You should have received a copy of the GNU General Public License along with -// this program; if not, see <http://www.gnu.org/licenses/>. - -/* - xmltree structure - */ - -#if !defined(__XMLTREE_H__) -#define __XMLTREE_H__ - -typedef enum { - value_undef = 0, - value_scalar, - value_complex, - value_string, - value_array, - value_matrix, - value_structure, - value_list, - value_cell, - value_data } t_value; - -typedef enum { - const_undef = 0, - const_true, - const_false, - const_inf, - const_neginf, - const_na, - const_nan } t_const; - -typedef struct _element { - struct _element *next; - struct _element *child; - - /* values */ - t_value def_value; - t_const const_value; - double scalar_value; - char *string_value; - - /* parameters */ - char *name; - int length; - int rows; - int columns; - - /* check */ - int nb_elements; - -} element; - -typedef struct _list { - struct _list *prev; - - element **root; -} list; - -element *new_element (); -element *new_next (element *pred); -element *new_child (element *father); -void free_element (element *root); -void print_element (element *root, int l); - -list *new_list(list *father); -list *pop_list(list *child); - -#endif /* __XMLTREE_H__ */ + // + // 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 the Free Software + // Foundation; either version 3 of the License, or (at your option) any later + // version. + // + // This program is distributed in the hope that it will be useful, but WITHOUT + // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + // details. + // + // You should have received a copy of the GNU General Public License along with + // this program; if not, see <http://www.gnu.org/licenses/>. + + /* + xmltree structure + */ + + #if !defined(__XMLTREE_H__) + #define __XMLTREE_H__ + + typedef enum { + value_undef = 0, + value_scalar, + value_complex, + value_string, + value_array, + value_matrix, + value_structure, + value_list, + value_cell, + value_data } t_value; + + typedef enum { + const_undef = 0, + const_true, + const_false, + const_inf, + const_neginf, + const_na, + const_nan } t_const; + + typedef struct _element { + struct _element *next; + struct _element *child; + + /* values */ + t_value def_value; + t_const const_value; + double scalar_value; + char *string_value; + + /* parameters */ + char *name; + int length; + int rows; + int columns; + + /* check */ + int nb_elements; + + } element; + + typedef struct _list { + struct _list *prev; + + element **root; + } list; + + element *new_element (); + element *new_next (element *pred); + element *new_child (element *father); + void free_element (element *root); + void print_element (element *root, int l); + + list *new_list(list *father); + list *pop_list(list *child); + + #endif /* __XMLTREE_H__ */ + \ No newline at end of file Modified: trunk/octave-forge/main/io/src/xmltree_read.c =================================================================== --- trunk/octave-forge/main/io/src/xmltree_read.c 2012-09-07 14:13:02 UTC (rev 10972) +++ trunk/octave-forge/main/io/src/xmltree_read.c 2012-09-07 14:14:16 UTC (rev 10973) @@ -1,4438 +1,4439 @@ /* A lexical scanner generated by flex */ - -/* Scanner skeleton version: - * $Header$ - */ - -#define FLEX_SCANNER -#define XML__FLEX_MAJOR_VERSION 2 -#define XML__FLEX_MINOR_VERSION 5 - -#include <stdio.h> -#include <errno.h> - -/* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */ -#ifdef c_plusplus -#ifndef __cplusplus -#define __cplusplus -#endif -#endif - - -#ifdef __cplusplus - -#include <stdlib.h> -#ifndef _WIN32 -#include <unistd.h> -#endif - -/* Use prototypes in function declarations. */ -#define XML__USE_PROTOS - -/* The "const" storage-class-modifier is valid. */ -#define XML__USE_CONST - -#else /* ! __cplusplus */ - -#if __STDC__ - -#define XML__USE_PROTOS -#define XML__USE_CONST - -#endif /* __STDC__ */ -#endif /* ! __cplusplus */ - -#ifdef __TURBOC__ - #pragma warn -rch - #pragma warn -use -#include <io.h> -#include <stdlib.h> -#define XML__USE_CONST -#define XML__USE_PROTOS -#endif - -#ifdef XML__USE_CONST -#define xml_const const -#else -#define xml_const -#endif - - -#ifdef XML__USE_PROTOS -#define XML__PROTO(proto) proto -#else -#define XML__PROTO(proto) () -#endif - - -/* Returned upon end-of-file. */ -#define XML__NULL 0 - -/* Promotes a possibly negative, possibly signed char to an unsigned - * integer for use as an array index. If the signed char is negative, - * we want to instead treat it as an 8-bit unsigned char, hence the - * double cast. - */ -#define XML__SC_TO_UI(c) ((unsigned int) (unsigned char) c) - -/* Enter a start condition. This macro really ought to take a parameter, - * but we do it the disgusting crufty way forced on us by the ()-less - * definition of BEGIN. - */ -#define BEGIN xml__start = 1 + 2 * - -/* Translate the current start state into a value that can be later handed - * to BEGIN to return to the state. The XML_STATE alias is for lex - * compatibility. - */ -#define XML__START ((xml__start - 1) / 2) -#define XML_STATE XML__START - -/* Action number for EOF rule of a given start state. */ -#define XML__STATE_EOF(state) (XML__END_OF_BUFFER + state + 1) - -/* Special action meaning "start processing a new file". */ -#define XML__NEW_FILE xml_restart( xml_in ) - -#define XML__END_OF_BUFFER_CHAR 0 - -/* Size of default input buffer. */ -#define XML__BUF_SIZE 16384 - -typedef struct xml__buffer_state *XML__BUFFER_STATE; - -extern int xml_leng; -extern FILE *xml_in, *xml_out; - -#define EOB_ACT_CONTINUE_SCAN 0 -#define EOB_ACT_END_OF_FILE 1 -#define EOB_ACT_LAST_MATCH 2 - -/* The funky do-while in the following #define is used to turn the definition - * int a single C statement (which needs a semi-colon terminator). This - * avoids problems with code like: - * - * if ( condition_holds ) - * xml_less( 5 ); - * else ... [truncated message content] |