| 1 | /* glpsdf.c (plain data file reading routines) */cxx . . $ `<file>/external/glpk/glpsdf.c`/ |
| 2 | |
| 3 | /*********************************************************************** |
| 4 | * This code is part of GLPK (GNU Linear Programming Kit). |
| 5 | * |
| 6 | * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, |
| 7 | * 2009, 2010 Andrew Makhorin, Department for Applied Informatics, |
| 8 | * Moscow Aviation Institute, Moscow, Russia. All rights reserved. |
| 9 | * E-mail: <[email protected]>. |
| 10 | * |
| 11 | * GLPK is free software: you can redistribute it and/or modify it |
| 12 | * under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation, either version 3 of the License, or |
| 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * GLPK is distributed in the hope that it will be useful, but WITHOUT |
| 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 18 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public |
| 19 | * License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with GLPK. If not, see <http://www.gnu.org/licenses/>. |
| 23 | ***********************************************************************/ |
| 24 | |
| 25 | #define GLPSDF_Hcxx . . $ `external/glpk/glpsdf.c:25:9`! |
| 26 | |
| 27 | #define GLP_DATA_DEFINEDcxx . . $ `external/glpk/glpsdf.c:27:9`! |
| 28 | typedef struct glp_datacxx . . $ glp_data# glp_datacxx . . $ glp_data#; |
| 29 | |
| 30 | #include "glpapi.h"cxx . . $ `<file>/external/glpk/glpapi.h`/ |
| 31 | |
| 32 | struct glp_datacxx . . $ glp_data# |
| 33 | { /* plain data file */ |
| 34 | char *fnamecxx . . $ glp_data#fname.; |
| 35 | /* name of data file */ |
| 36 | XFILEcxx . . $ XFILE# *fpcxx . . $ glp_data#fp.; |
| 37 | /* stream assigned to data file */ |
| 38 | void *jumpcxx . . $ glp_data#jump.; /* jmp_buf jump; */ |
| 39 | /* label for go to in case of error */ |
| 40 | int countcxx . . $ glp_data#count.; |
| 41 | /* line count */ |
| 42 | int ccxx . . $ glp_data#c.; |
| 43 | /* current character of XEOF */ |
| 44 | char itemcxx . . $ glp_data#item.[255+1]; |
| 45 | /* current data item */ |
| 46 | }; |
| 47 | |
| 48 | static void next_charcxx . . $ next_char(b3db5f7887c63f2b).(glp_datacxx . . $ glp_data# *data); |
| 49 | |
| 50 | glp_datacxx . . $ glp_data# *glp_sdf_open_filecxx . . $ glp_sdf_open_file(5d91e689407a173f).(const char *fname) |
| 51 | { /* open plain data file */ |
| 52 | glp_datacxx . . $ glp_data# *data = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 53 | XFILEcxx . . $ XFILE# *fp; |
| 54 | jmp_bufcxx . . $ jmp_buf# jump; |
| 55 | fp = xfopencxx . . $ `external/glpk/glpenv.h:193:9`!(fname, "r"); |
| 56 | if (fp == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 57 | { xprintfcxx . . $ `external/glpk/glpenv.h:145:9`!("Unable to open `%s' - %s\n", fname, xerrmsgcxx . . $ `external/glpk/glpenv.h:190:9`!()); |
| 58 | goto done; |
| 59 | } |
| 60 | data = xmalloccxx . . $ `external/glpk/glpenv.h:167:9`!(sizeof(glp_datacxx . . $ glp_data#)); |
| 61 | data->fnamecxx . . $ glp_data#fname. = xmalloccxx . . $ `external/glpk/glpenv.h:167:9`!(strlencxx . . $ strlen(751346f8406fd082).(fname)+1); |
| 62 | strcpycxx . . $ strcpy(b7b3a83273496486).(data->fnamecxx . . $ glp_data#fname., fname); |
| 63 | data->fpcxx . . $ glp_data#fp. = fp; |
| 64 | data->jumpcxx . . $ glp_data#jump. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 65 | data->countcxx . . $ glp_data#count. = 0; |
| 66 | data->ccxx . . $ glp_data#c. = '\n'; |
| 67 | data->itemcxx . . $ glp_data#item.[0] = '\0'; |
| 68 | /* read the very first character */ |
| 69 | if (setjmpcxx . . $ `<external>/4367339001007250937/setjmp.h:49:9`!(jump)) |
| 70 | { glp_sdf_close_filecxx . . $ glp_sdf_close_file(b3db5f7887c63f2b).(data); |
| 71 | data = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 72 | goto done; |
| 73 | } |
| 74 | data->jumpcxx . . $ glp_data#jump. = jump; |
| 75 | next_charcxx . . $ next_char(b3db5f7887c63f2b).(data); |
| 76 | data->jumpcxx . . $ glp_data#jump. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 77 | done: return data; |
| 78 | } |
| 79 | |
| 80 | void glp_sdf_set_jumpcxx . . $ glp_sdf_set_jump(1cde2723aef1bf7c).(glp_datacxx . . $ glp_data# *data, void *jump) |
| 81 | { /* set up error handling */ |
| 82 | data->jumpcxx . . $ glp_data#jump. = jump; |
| 83 | return; |
| 84 | } |
| 85 | |
| 86 | void glp_sdf_errorcxx . . $ glp_sdf_error(732b9407be774b3c).(glp_datacxx . . $ glp_data# *data, const char *fmt, ...) |
| 87 | { /* print error message */ |
| 88 | va_listcxx . . $ va_list# arg; |
| 89 | xprintfcxx . . $ `external/glpk/glpenv.h:145:9`!("%s:%d: ", data->fnamecxx . . $ glp_data#fname., data->countcxx . . $ glp_data#count.); |
| 90 | va_startcxx . . $ `<external>/8105065126723003039/stdarg.h:50:9`!(arg, fmt); |
| 91 | xvprintfcxx . . $ `external/glpk/glpenv.h:149:9`!(fmt, arg); |
| 92 | va_endcxx . . $ `<external>/8105065126723003039/stdarg.h:52:9`!(arg); |
| 93 | if (data->jumpcxx . . $ glp_data#jump. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 94 | xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!(""); |
| 95 | else |
| 96 | longjmpcxx . . $ longjmp(d25daf25a2f573dc).(data->jumpcxx . . $ glp_data#jump., 1); |
| 97 | /* no return */ |
| 98 | } |
| 99 | |
| 100 | void glp_sdf_warningcxx . . $ glp_sdf_warning(732b9407be774b3c).(glp_datacxx . . $ glp_data# *data, const char *fmt, ...) |
| 101 | { /* print warning message */ |
| 102 | va_listcxx . . $ va_list# arg; |
| 103 | xprintfcxx . . $ `external/glpk/glpenv.h:145:9`!("%s:%d: warning: ", data->fnamecxx . . $ glp_data#fname., data->countcxx . . $ glp_data#count.); |
| 104 | va_startcxx . . $ `<external>/8105065126723003039/stdarg.h:50:9`!(arg, fmt); |
| 105 | xvprintfcxx . . $ `external/glpk/glpenv.h:149:9`!(fmt, arg); |
| 106 | va_endcxx . . $ `<external>/8105065126723003039/stdarg.h:52:9`!(arg); |
| 107 | return; |
| 108 | } |
| 109 | |
| 110 | static void next_charcxx . . $ next_char(b3db5f7887c63f2b).(glp_datacxx . . $ glp_data# *data) |
| 111 | { /* read next character */ |
| 112 | int c; |
| 113 | if (data->ccxx . . $ glp_data#c. == XEOFcxx . . $ `external/glpk/glpenv.h:131:9`!) |
| 114 | glp_sdf_errorcxx . . $ glp_sdf_error(732b9407be774b3c).(data, "unexpected end of file\n"); |
| 115 | else if (data->ccxx . . $ glp_data#c. == '\n') |
| 116 | data->countcxx . . $ glp_data#count.++; |
| 117 | c = xfgetccxx . . $ `external/glpk/glpenv.h:202:9`!(data->fpcxx . . $ glp_data#fp.); |
| 118 | if (c < 0) |
| 119 | { if (xferrorcxx . . $ `external/glpk/glpenv.h:196:9`!(data->fpcxx . . $ glp_data#fp.)) |
| 120 | glp_sdf_errorcxx . . $ glp_sdf_error(732b9407be774b3c).(data, "read error - %s\n", xerrmsgcxx . . $ `external/glpk/glpenv.h:190:9`!()); |
| 121 | else if (data->ccxx . . $ glp_data#c. == '\n') |
| 122 | c = XEOFcxx . . $ `external/glpk/glpenv.h:131:9`!; |
| 123 | else |
| 124 | { glp_sdf_warningcxx . . $ glp_sdf_warning(732b9407be774b3c).(data, "missing final end of line\n"); |
| 125 | c = '\n'; |
| 126 | } |
| 127 | } |
| 128 | else if (c == '\n') |
| 129 | ; |
| 130 | else if (isspacecxx . . $ `<external>/17904084882347303253/ctype.h:197:10`!(c)) |
| 131 | c = ' '; |
| 132 | else if (iscntrlcxx . . $ `<external>/17904084882347303253/ctype.h:191:10`!(c)) |
| 133 | glp_sdf_errorcxx . . $ glp_sdf_error(732b9407be774b3c).(data, "invalid control character 0x%02X\n", c); |
| 134 | data->ccxx . . $ glp_data#c. = c; |
| 135 | return; |
| 136 | } |
| 137 | |
| 138 | static void skip_padcxx . . $ skip_pad(b3db5f7887c63f2b).(glp_datacxx . . $ glp_data# *data) |
| 139 | { /* skip uninteresting characters and comments */ |
| 140 | loop: while (data->ccxx . . $ glp_data#c. == ' ' || data->ccxx . . $ glp_data#c. == '\n') |
| 141 | next_charcxx . . $ next_char(b3db5f7887c63f2b).(data); |
| 142 | if (data->ccxx . . $ glp_data#c. == '/') |
| 143 | { next_charcxx . . $ next_char(b3db5f7887c63f2b).(data); |
| 144 | if (data->ccxx . . $ glp_data#c. != '*') |
| 145 | glp_sdf_errorcxx . . $ glp_sdf_error(732b9407be774b3c).(data, "invalid use of slash\n"); |
| 146 | next_charcxx . . $ next_char(b3db5f7887c63f2b).(data); |
| 147 | for (;;) |
| 148 | { if (data->ccxx . . $ glp_data#c. == '*') |
| 149 | { next_charcxx . . $ next_char(b3db5f7887c63f2b).(data); |
| 150 | if (data->ccxx . . $ glp_data#c. == '/') |
| 151 | { next_charcxx . . $ next_char(b3db5f7887c63f2b).(data); |
| 152 | break; |
| 153 | } |
| 154 | } |
| 155 | next_charcxx . . $ next_char(b3db5f7887c63f2b).(data); |
| 156 | } |
| 157 | goto loop; |
| 158 | } |
| 159 | return; |
| 160 | } |
| 161 | |
| 162 | static void next_itemcxx . . $ next_item(b3db5f7887c63f2b).(glp_datacxx . . $ glp_data# *data) |
| 163 | { /* read next item */ |
| 164 | int len; |
| 165 | skip_padcxx . . $ skip_pad(b3db5f7887c63f2b).(data); |
| 166 | len = 0; |
| 167 | while (!(data->ccxx . . $ glp_data#c. == ' ' || data->ccxx . . $ glp_data#c. == '\n')) |
| 168 | { data->itemcxx . . $ glp_data#item.[len++] = (char)data->ccxx . . $ glp_data#c.; |
| 169 | if (len == sizeof(data->itemcxx . . $ glp_data#item.)) |
| 170 | glp_sdf_errorcxx . . $ glp_sdf_error(732b9407be774b3c).(data, "data item `%.31s...' too long\n", |
| 171 | data->itemcxx . . $ glp_data#item.); |
| 172 | next_charcxx . . $ next_char(b3db5f7887c63f2b).(data); |
| 173 | } |
| 174 | data->itemcxx . . $ glp_data#item.[len] = '\0'; |
| 175 | return; |
| 176 | } |
| 177 | |
| 178 | int glp_sdf_read_intcxx . . $ glp_sdf_read_int(4c8393da7a19ee9).(glp_datacxx . . $ glp_data# *data) |
| 179 | { /* read integer number */ |
| 180 | int x; |
| 181 | next_itemcxx . . $ next_item(b3db5f7887c63f2b).(data); |
| 182 | switch (str2intcxx . . $ `external/glpk/glplib.h:81:9`!(data->itemcxx . . $ glp_data#item., &x)) |
| 183 | { case 0: |
| 184 | break; |
| 185 | case 1: |
| 186 | glp_sdf_errorcxx . . $ glp_sdf_error(732b9407be774b3c).(data, "integer `%s' out of range\n", |
| 187 | data->itemcxx . . $ glp_data#item.); |
| 188 | case 2: |
| 189 | glp_sdf_errorcxx . . $ glp_sdf_error(732b9407be774b3c).(data, "cannot convert `%s' to integer\n", |
| 190 | data->itemcxx . . $ glp_data#item.); |
| 191 | default: |
| 192 | xassertcxx . . $ `external/glpk/glpenv.h:162:9`!(data != data); |
| 193 | } |
| 194 | return x; |
| 195 | } |
| 196 | |
| 197 | double glp_sdf_read_numcxx . . $ glp_sdf_read_num(13e2a95c29cbbff7).(glp_datacxx . . $ glp_data# *data) |
| 198 | { /* read floating-point number */ |
| 199 | double x; |
| 200 | next_itemcxx . . $ next_item(b3db5f7887c63f2b).(data); |
| 201 | switch (str2numcxx . . $ `external/glpk/glplib.h:85:9`!(data->itemcxx . . $ glp_data#item., &x)) |
| 202 | { case 0: |
| 203 | break; |
| 204 | case 1: |
| 205 | glp_sdf_errorcxx . . $ glp_sdf_error(732b9407be774b3c).(data, "number `%s' out of range\n", |
| 206 | data->itemcxx . . $ glp_data#item.); |
| 207 | case 2: |
| 208 | glp_sdf_errorcxx . . $ glp_sdf_error(732b9407be774b3c).(data, "cannot convert `%s' to number\n", |
| 209 | data->itemcxx . . $ glp_data#item.); |
| 210 | default: |
| 211 | xassertcxx . . $ `external/glpk/glpenv.h:162:9`!(data != data); |
| 212 | } |
| 213 | return x; |
| 214 | } |
| 215 | |
| 216 | const char *glp_sdf_read_itemcxx . . $ glp_sdf_read_item(3605c128bfdc088).(glp_datacxx . . $ glp_data# *data) |
| 217 | { /* read data item */ |
| 218 | next_itemcxx . . $ next_item(b3db5f7887c63f2b).(data); |
| 219 | return data->itemcxx . . $ glp_data#item.; |
| 220 | } |
| 221 | |
| 222 | const char *glp_sdf_read_textcxx . . $ glp_sdf_read_text(3605c128bfdc088).(glp_datacxx . . $ glp_data# *data) |
| 223 | { /* read text until end of line */ |
| 224 | int c, len = 0; |
| 225 | for (;;) |
| 226 | { c = data->ccxx . . $ glp_data#c.; |
| 227 | next_charcxx . . $ next_char(b3db5f7887c63f2b).(data); |
| 228 | if (c == ' ') |
| 229 | { /* ignore initial spaces */ |
| 230 | if (len == 0) continue; |
| 231 | /* and multiple ones */ |
| 232 | if (data->itemcxx . . $ glp_data#item.[len-1] == ' ') continue; |
| 233 | } |
| 234 | else if (c == '\n') |
| 235 | { /* remove trailing space */ |
| 236 | if (len > 0 && data->itemcxx . . $ glp_data#item.[len-1] == ' ') len--; |
| 237 | /* and stop reading */ |
| 238 | break; |
| 239 | } |
| 240 | /* add current character to the buffer */ |
| 241 | data->itemcxx . . $ glp_data#item.[len++] = (char)c; |
| 242 | if (len == sizeof(data->itemcxx . . $ glp_data#item.)) |
| 243 | glp_sdf_errorcxx . . $ glp_sdf_error(732b9407be774b3c).(data, "line too long\n", data->itemcxx . . $ glp_data#item.); |
| 244 | } |
| 245 | data->itemcxx . . $ glp_data#item.[len] = '\0'; |
| 246 | return data->itemcxx . . $ glp_data#item.; |
| 247 | } |
| 248 | |
| 249 | int glp_sdf_linecxx . . $ glp_sdf_line(4c8393da7a19ee9).(glp_datacxx . . $ glp_data# *data) |
| 250 | { /* determine current line number */ |
| 251 | return data->countcxx . . $ glp_data#count.; |
| 252 | } |
| 253 | |
| 254 | void glp_sdf_close_filecxx . . $ glp_sdf_close_file(b3db5f7887c63f2b).(glp_datacxx . . $ glp_data# *data) |
| 255 | { /* close plain data file */ |
| 256 | xfclosecxx . . $ `external/glpk/glpenv.h:211:9`!(data->fpcxx . . $ glp_data#fp.); |
| 257 | xfreecxx . . $ `external/glpk/glpenv.h:175:9`!(data->fnamecxx . . $ glp_data#fname.); |
| 258 | xfreecxx . . $ `external/glpk/glpenv.h:175:9`!(data); |
| 259 | return; |
| 260 | } |
| 261 | |
| 262 | /* eof */ |