/* xls2xml: Converts from Microsoft Excel files to XML. Copyright 1999 Roberto Arturo Tena Sanchez 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 2 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, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* Roberto Arturo Tena Sanchez */ #include #include #include #include #include #include static void normalize_tabs_numbers (magic_parameters * parameters); /* TABID - Sheet Tab Index Array */ int p13D (void) { U8 * p; xmlNodePtr order; char number [5]; /* max number 9999 */ /* magic number: I think no one will have more than 9999 tabs */ assert_return (xls2xml, parameters->record.opcode == 0x13D, 19); order = xmlNewChild (parameters->xml_tree_shortcuts.tabs_state, NULL, (unsigned char *)"order", NULL); test (order != NULL, 10); normalize_tabs_numbers (parameters); for (p = parameters->record.info; p - parameters->record.info < parameters->record.size; p += 2) { if (p != parameters->record.info) sprintf (number, ",%d", fil_sreadU16 (p)); else sprintf (number, "%d", fil_sreadU16 (p)); xmlNodeAddContent (order, (unsigned char *)number); } return 0; } /* Normalize tabs numbers means: 1) must be a zero 2) always consecutive numbers So, if we normalize: "1,2,3" results "0,1,2" if "6,5,4,3,2,1,0" results "6,5,4,3,2,1,0" if "6,2,7,3,32" results "2,0,3,1,4" if "" results "" */ void normalize_tabs_numbers (magic_parameters * parameters) { U16 minnum; U16 maxnum; U16 correction; U16 i, j; U16 temp; if (parameters->record.size == 0) return; correction = 0; /* guess minnum */ maxnum = minnum = fil_sreadU16 (parameters->record.info); for (i = 1; i < parameters->record.size / 2; i++) { if (fil_sreadU16 (parameters->record.info + i*2) < minnum) minnum = fil_sreadU16 (parameters->record.info + i*2); if (fil_sreadU16 (parameters->record.info + i*2) > maxnum) maxnum = fil_sreadU16 (parameters->record.info + i*2); } /* check each number is present and normalize it */ for (i = 0; i < maxnum + 1; i++) { for (j = 0; j < parameters->record.size / 2; j++) if (i == fil_sreadU16 (parameters->record.info + j*2)) { temp = i - correction; fil_swriteU16 ((U8*)(parameters->record.info + j*2), &temp); correction--; break; /* exit j for */ } correction++; } }