3 * Copyright (C) 2004 dmitri (at) users.sourceforge.net
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
23 \brief Tool file parsing functions
32 #define MIN_TOOL_NUMBER 1 /* T01 */
33 #define MAX_TOOL_NUMBER 99 /* T99 */
35 static int have_tools_file
= 0;
36 static double tools
[1+MAX_TOOL_NUMBER
];
39 ProcessToolLine(const char *cp
)
48 /* Skip leading spaces if there are some */
49 while (isspace((int) *cp
)) {
55 fprintf(stderr
, "*** WARNING: Strange tool \"%s\" ignored.\n", cp0
);
58 if ((!isdigit((int) cp
[1])) || (!isdigit((int) cp
[2]))) {
59 fprintf(stderr
, "*** WARNING: No tool number in \"%s\".\n", cp0
);
67 toolNumber
= atoi(tnb
);
68 if ((toolNumber
< MIN_TOOL_NUMBER
) || (toolNumber
> MAX_TOOL_NUMBER
)) {
69 fprintf(stderr
, "*** WARNING: Can't parse tool number in \"%s\".\n", cp0
);
74 cp
+= 3; /* Skip Tnn */
76 /* Skip following spaces if there are some */
77 while (isspace((int) *cp
)) {
82 /* The rest of the line is supposed to be the tool diameter in inches. */
86 fprintf(stderr
, "*** WARNING: Tool T%02d diameter is impossible.\n", toolNumber
);
89 if (toolDia
< 0.001) {
90 fprintf(stderr
, "*** WARNING: Tool T%02d diameter is very small - "
91 "are you sure?\n", toolNumber
);
94 if (tools
[toolNumber
] != 0) {
95 fprintf(stderr
, "*** ERROR: Tool T%02d is already defined.\n", toolNumber
);
96 fprintf(stderr
, "*** Exiting because this is a HOLD error at any board house.\n");
101 tools
[toolNumber
] = toolDia
;
102 } /* ProcessToolLine */
106 gerbv_process_tools_file(const char *tf
)
112 memset(tools
, 0, sizeof(tools
));
119 fprintf(stderr
, "*** ERROR: Failed to open file \"%s\" to read.\n", tf
);
123 memset(buf
, 0, sizeof(buf
));
124 if (NULL
== fgets(buf
, sizeof(buf
)-1, f
))
126 ProcessToolLine(buf
);
131 } /* gerbv_process_tools_file */
135 gerbv_get_tool_diameter(int toolNumber
)
137 if (!have_tools_file
)
139 if ((toolNumber
< MIN_TOOL_NUMBER
) || (toolNumber
> MAX_TOOL_NUMBER
))
141 return tools
[toolNumber
];
142 } /* gerbv_get_tool_diameter */