Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kicad-source-mirror
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Elphel
kicad-source-mirror
Commits
40e69c9b
Commit
40e69c9b
authored
Sep 29, 2008
by
dickelbeck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove trailing whitespace
parent
ab1df3f1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
69 deletions
+69
-69
dsn.cpp
pcbnew/dsn.cpp
+69
-69
No files found.
pcbnew/dsn.cpp
View file @
40e69c9b
...
@@ -4,26 +4,26 @@
...
@@ -4,26 +4,26 @@
*
*
* Copyright (C) 2007-2008 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2007-2008 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2007 Kicad Developers, see change_log.txt for contributors.
* Copyright (C) 2007 Kicad Developers, see change_log.txt for contributors.
*
*
* This program is free software; you can redistribute it and/or
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* of the License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
*/
#include <cstdarg>
#include <cstdarg>
#include <cstdio>
#include <cstdio>
#include <cstdlib> // bsearch()
#include <cstdlib> // bsearch()
...
@@ -63,7 +63,7 @@ struct KEYWORD
...
@@ -63,7 +63,7 @@ struct KEYWORD
// This MUST be sorted alphabetically, and also so MUST enum DSN_T {} be alphabetized.
// This MUST be sorted alphabetically, and also so MUST enum DSN_T {} be alphabetized.
// These MUST all be lower case because of the conversion to lowercase in findToken().
// These MUST all be lower case because of the conversion to lowercase in findToken().
const
static
KEYWORD
tokens
[]
=
{
const
static
KEYWORD
tokens
[]
=
{
TOKDEF
(
absolute
),
TOKDEF
(
absolute
),
TOKDEF
(
added
),
TOKDEF
(
added
),
...
@@ -461,7 +461,7 @@ static int compare( const void* a1, const void* a2 )
...
@@ -461,7 +461,7 @@ static int compare( const void* a1, const void* a2 )
{
{
const
KEYWORD
*
k1
=
(
const
KEYWORD
*
)
a1
;
const
KEYWORD
*
k1
=
(
const
KEYWORD
*
)
a1
;
const
KEYWORD
*
k2
=
(
const
KEYWORD
*
)
a2
;
const
KEYWORD
*
k2
=
(
const
KEYWORD
*
)
a2
;
int
ret
=
strcmp
(
k1
->
name
,
k2
->
name
);
int
ret
=
strcmp
(
k1
->
name
,
k2
->
name
);
return
ret
;
return
ret
;
}
}
...
@@ -475,11 +475,11 @@ LINE_READER::LINE_READER( FILE* aFile, unsigned aMaxLineLength )
...
@@ -475,11 +475,11 @@ LINE_READER::LINE_READER( FILE* aFile, unsigned aMaxLineLength )
lineNum
=
0
;
lineNum
=
0
;
maxLineLength
=
aMaxLineLength
;
maxLineLength
=
aMaxLineLength
;
// the real capacity is 10 bytes larger than requested.
// the real capacity is 10 bytes larger than requested.
capacity
=
aMaxLineLength
+
10
;
capacity
=
aMaxLineLength
+
10
;
line
=
new
char
[
capacity
];
line
=
new
char
[
capacity
];
line
[
0
]
=
'\0'
;
line
[
0
]
=
'\0'
;
length
=
0
;
length
=
0
;
}
}
...
@@ -488,7 +488,7 @@ LINE_READER::LINE_READER( FILE* aFile, unsigned aMaxLineLength )
...
@@ -488,7 +488,7 @@ LINE_READER::LINE_READER( FILE* aFile, unsigned aMaxLineLength )
int
LINE_READER
::
ReadLine
()
throw
(
IOError
)
int
LINE_READER
::
ReadLine
()
throw
(
IOError
)
{
{
const
char
*
p
=
fgets
(
line
,
capacity
,
fp
);
const
char
*
p
=
fgets
(
line
,
capacity
,
fp
);
if
(
!
p
)
if
(
!
p
)
{
{
line
[
0
]
=
0
;
line
[
0
]
=
0
;
...
@@ -498,12 +498,12 @@ int LINE_READER::ReadLine() throw (IOError)
...
@@ -498,12 +498,12 @@ int LINE_READER::ReadLine() throw (IOError)
{
{
length
=
strlen
(
line
);
length
=
strlen
(
line
);
if
(
length
>
maxLineLength
)
if
(
length
>
maxLineLength
)
throw
IOError
(
_
(
"Line length exceeded"
)
);
throw
IOError
(
_
(
"Line length exceeded"
)
);
++
lineNum
;
++
lineNum
;
}
}
return
length
;
return
length
;
}
}
...
@@ -519,12 +519,12 @@ LEXER::LEXER( FILE* aFile, const wxString& aFilename ) :
...
@@ -519,12 +519,12 @@ LEXER::LEXER( FILE* aFile, const wxString& aFilename ) :
filename
=
aFilename
;
filename
=
aFilename
;
space_in_quoted_tokens
=
true
;
space_in_quoted_tokens
=
true
;
// "start" should never change until we change the reader. The DSN
// "start" should never change until we change the reader. The DSN
// format spec supports an include file mechanism but we can add that later
// format spec supports an include file mechanism but we can add that later
// using a std::stack to hold a stack of LINE_READERs to track nesting.
// using a std::stack to hold a stack of LINE_READERs to track nesting.
start
=
(
char
*
)
reader
;
start
=
(
char
*
)
reader
;
limit
=
start
;
limit
=
start
;
next
=
start
;
next
=
start
;
}
}
...
@@ -535,19 +535,19 @@ int LEXER::findToken( const std::string& tok )
...
@@ -535,19 +535,19 @@ int LEXER::findToken( const std::string& tok )
// convert to lower case once, this should be faster than using strcasecmp()
// convert to lower case once, this should be faster than using strcasecmp()
// for each test in compare().
// for each test in compare().
lowercase
.
clear
();
lowercase
.
clear
();
for
(
std
::
string
::
const_iterator
iter
=
tok
.
begin
();
iter
!=
tok
.
end
();
++
iter
)
for
(
std
::
string
::
const_iterator
iter
=
tok
.
begin
();
iter
!=
tok
.
end
();
++
iter
)
lowercase
+=
(
char
)
tolower
(
*
iter
);
lowercase
+=
(
char
)
tolower
(
*
iter
);
KEYWORD
search
;
KEYWORD
search
;
search
.
name
=
lowercase
.
c_str
();
search
.
name
=
lowercase
.
c_str
();
const
KEYWORD
*
findings
=
(
const
KEYWORD
*
)
bsearch
(
&
search
,
const
KEYWORD
*
findings
=
(
const
KEYWORD
*
)
bsearch
(
&
search
,
tokens
,
sizeof
(
tokens
)
/
sizeof
(
tokens
[
0
]),
tokens
,
sizeof
(
tokens
)
/
sizeof
(
tokens
[
0
]),
sizeof
(
KEYWORD
),
compare
);
sizeof
(
KEYWORD
),
compare
);
if
(
findings
)
if
(
findings
)
// return findings->token;
// return findings->token;
return
findings
-
tokens
;
return
findings
-
tokens
;
else
else
return
-
1
;
return
-
1
;
}
}
...
@@ -556,7 +556,7 @@ int LEXER::findToken( const std::string& tok )
...
@@ -556,7 +556,7 @@ int LEXER::findToken( const std::string& tok )
const
char
*
LEXER
::
GetTokenText
(
DSN_T
aTok
)
const
char
*
LEXER
::
GetTokenText
(
DSN_T
aTok
)
{
{
const
char
*
ret
;
const
char
*
ret
;
if
(
aTok
<
0
)
if
(
aTok
<
0
)
{
{
switch
(
aTok
)
switch
(
aTok
)
...
@@ -596,7 +596,7 @@ const char* LEXER::GetTokenText( DSN_T aTok )
...
@@ -596,7 +596,7 @@ const char* LEXER::GetTokenText( DSN_T aTok )
{
{
ret
=
tokens
[
aTok
].
name
;
ret
=
tokens
[
aTok
].
name
;
}
}
return
ret
;
return
ret
;
}
}
...
@@ -604,44 +604,44 @@ const char* LEXER::GetTokenText( DSN_T aTok )
...
@@ -604,44 +604,44 @@ const char* LEXER::GetTokenText( DSN_T aTok )
wxString
LEXER
::
GetTokenString
(
DSN_T
aTok
)
wxString
LEXER
::
GetTokenString
(
DSN_T
aTok
)
{
{
wxString
ret
;
wxString
ret
;
ret
<<
wxT
(
"'"
)
<<
CONV_FROM_UTF8
(
GetTokenText
(
aTok
)
)
<<
wxT
(
"'"
);
ret
<<
wxT
(
"'"
)
<<
CONV_FROM_UTF8
(
GetTokenText
(
aTok
)
)
<<
wxT
(
"'"
);
return
ret
;
return
ret
;
}
}
void
LEXER
::
ThrowIOError
(
wxString
aText
,
int
charOffset
)
throw
(
IOError
)
void
LEXER
::
ThrowIOError
(
wxString
aText
,
int
charOffset
)
throw
(
IOError
)
{
{
aText
<<
wxT
(
" "
)
<<
_
(
"in file"
)
<<
wxT
(
"
\"
"
)
<<
filename
aText
<<
wxT
(
" "
)
<<
_
(
"in file"
)
<<
wxT
(
"
\"
"
)
<<
filename
<<
wxT
(
"
\"
"
)
<<
_
(
"on line"
)
<<
wxT
(
" "
)
<<
reader
.
LineNumber
()
<<
wxT
(
"
\"
"
)
<<
_
(
"on line"
)
<<
wxT
(
" "
)
<<
reader
.
LineNumber
()
<<
wxT
(
" "
)
<<
_
(
"at offset"
)
<<
wxT
(
" "
)
<<
charOffset
;
<<
wxT
(
" "
)
<<
_
(
"at offset"
)
<<
wxT
(
" "
)
<<
charOffset
;
throw
IOError
(
aText
);
throw
IOError
(
aText
);
}
}
DSN_T
LEXER
::
NextTok
()
throw
(
IOError
)
DSN_T
LEXER
::
NextTok
()
throw
(
IOError
)
{
{
char
*
cur
=
next
;
char
*
cur
=
next
;
char
*
head
=
cur
;
char
*
head
=
cur
;
prevTok
=
curTok
;
prevTok
=
curTok
;
if
(
curTok
!=
T_EOF
)
if
(
curTok
!=
T_EOF
)
{
{
if
(
cur
>=
limit
)
if
(
cur
>=
limit
)
{
{
L_read
:
L_read
:
int
len
=
readLine
();
int
len
=
readLine
();
if
(
len
==
0
)
if
(
len
==
0
)
{
{
curTok
=
T_EOF
;
curTok
=
T_EOF
;
goto
exit
;
goto
exit
;
}
}
cur
=
start
;
cur
=
start
;
// skip leading whitespace
// skip leading whitespace
while
(
cur
<
limit
&&
isspace
(
*
cur
)
)
while
(
cur
<
limit
&&
isspace
(
*
cur
)
)
++
cur
;
++
cur
;
...
@@ -659,12 +659,12 @@ L_read:
...
@@ -659,12 +659,12 @@ L_read:
if
(
cur
>=
limit
)
if
(
cur
>=
limit
)
goto
L_read
;
goto
L_read
;
// switching the string_quote character
// switching the string_quote character
if
(
prevTok
==
T_string_quote
)
if
(
prevTok
==
T_string_quote
)
{
{
static
const
wxString
errtxt
(
_
(
"String delimiter must be a single character of ',
\"
, or $"
));
static
const
wxString
errtxt
(
_
(
"String delimiter must be a single character of ',
\"
, or $"
));
char
cc
=
*
cur
;
char
cc
=
*
cur
;
switch
(
cc
)
switch
(
cc
)
{
{
...
@@ -675,36 +675,36 @@ L_read:
...
@@ -675,36 +675,36 @@ L_read:
default
:
default
:
ThrowIOError
(
errtxt
,
CurOffset
()
);
ThrowIOError
(
errtxt
,
CurOffset
()
);
}
}
curText
.
clear
();
curText
.
clear
();
curText
+=
cc
;
curText
+=
cc
;
head
=
cur
+
1
;
head
=
cur
+
1
;
if
(
head
<
limit
&&
*
head
!=
')'
&&
*
head
!=
'('
&&
!
isspace
(
*
head
)
)
if
(
head
<
limit
&&
*
head
!=
')'
&&
*
head
!=
'('
&&
!
isspace
(
*
head
)
)
{
{
ThrowIOError
(
errtxt
,
CurOffset
()
);
ThrowIOError
(
errtxt
,
CurOffset
()
);
}
}
curTok
=
T_QUOTE_DEF
;
curTok
=
T_QUOTE_DEF
;
goto
exit
;
goto
exit
;
}
}
if
(
*
cur
==
'('
)
if
(
*
cur
==
'('
)
{
{
curText
.
clear
();
curText
.
clear
();
curText
+=
*
cur
;
curText
+=
*
cur
;
curTok
=
T_LEFT
;
curTok
=
T_LEFT
;
head
=
cur
+
1
;
head
=
cur
+
1
;
goto
exit
;
goto
exit
;
}
}
if
(
*
cur
==
')'
)
if
(
*
cur
==
')'
)
{
{
curText
.
clear
();
curText
.
clear
();
curText
+=
*
cur
;
curText
+=
*
cur
;
curTok
=
T_RIGHT
;
curTok
=
T_RIGHT
;
head
=
cur
+
1
;
head
=
cur
+
1
;
goto
exit
;
goto
exit
;
...
@@ -722,8 +722,8 @@ L_read:
...
@@ -722,8 +722,8 @@ L_read:
curTok
=
T_DASH
;
curTok
=
T_DASH
;
goto
exit
;
goto
exit
;
}
}
// handle T_NUMBER
// handle T_NUMBER
if
(
strchr
(
"+-.0123456789"
,
*
cur
)
)
if
(
strchr
(
"+-.0123456789"
,
*
cur
)
)
{
{
head
=
cur
+
1
;
head
=
cur
+
1
;
...
@@ -737,63 +737,63 @@ L_read:
...
@@ -737,63 +737,63 @@ L_read:
curTok
=
T_NUMBER
;
curTok
=
T_NUMBER
;
goto
exit
;
goto
exit
;
}
}
// else it was something like +5V, fall through below
// else it was something like +5V, fall through below
}
}
// a quoted string
// a quoted string
if
(
*
cur
==
stringDelimiter
)
if
(
*
cur
==
stringDelimiter
)
{
{
++
cur
;
// skip over the leading delimiter: ",', or $
++
cur
;
// skip over the leading delimiter: ",', or $
head
=
cur
;
head
=
cur
;
while
(
head
<
limit
&&
!
isStringTerminator
(
*
head
)
)
while
(
head
<
limit
&&
!
isStringTerminator
(
*
head
)
)
++
head
;
++
head
;
if
(
head
>=
limit
)
if
(
head
>=
limit
)
{
{
wxString
errtxt
(
_
(
"Un-terminated delimited string"
)
);
wxString
errtxt
(
_
(
"Un-terminated delimited string"
)
);
ThrowIOError
(
errtxt
,
CurOffset
()
);
ThrowIOError
(
errtxt
,
CurOffset
()
);
}
}
curText
.
clear
();
curText
.
clear
();
curText
.
append
(
cur
,
head
);
curText
.
append
(
cur
,
head
);
++
head
;
// skip over the trailing delimiter
++
head
;
// skip over the trailing delimiter
curTok
=
T_STRING
;
curTok
=
T_STRING
;
goto
exit
;
goto
exit
;
}
}
// a token we hope to find in the tokens[] array. If not, then
// a token we hope to find in the tokens[] array. If not, then
// call it a T_SYMBOL.
// call it a T_SYMBOL.
{
{
head
=
cur
+
1
;
head
=
cur
+
1
;
while
(
head
<
limit
&&
!
isspace
(
*
head
)
&&
*
head
!=
')'
&&
*
head
!=
'('
)
while
(
head
<
limit
&&
!
isspace
(
*
head
)
&&
*
head
!=
')'
&&
*
head
!=
'('
)
++
head
;
++
head
;
curText
.
clear
();
curText
.
clear
();
curText
.
append
(
cur
,
head
);
curText
.
append
(
cur
,
head
);
int
found
=
findToken
(
curText
);
int
found
=
findToken
(
curText
);
if
(
found
!=
-
1
)
if
(
found
!=
-
1
)
curTok
=
(
DSN_T
)
found
;
curTok
=
(
DSN_T
)
found
;
else
// unrecogized token, call it a symbol
else
// unrecogized token, call it a symbol
curTok
=
T_SYMBOL
;
curTok
=
T_SYMBOL
;
}
}
}
}
exit
:
// single point of exit
exit
:
// single point of exit
curOffset
=
cur
-
start
;
curOffset
=
cur
-
start
;
next
=
head
;
next
=
head
;
// printf("tok:\"%s\"\n", curText.c_str() );
// printf("tok:\"%s\"\n", curText.c_str() );
return
curTok
;
return
curTok
;
}
}
...
@@ -811,19 +811,19 @@ int main( int argc, char** argv )
...
@@ -811,19 +811,19 @@ int main( int argc, char** argv )
// wxString filename( wxT("/tmp/fpcroute/Sample_1sided/demo_1sided.dsn") );
// wxString filename( wxT("/tmp/fpcroute/Sample_1sided/demo_1sided.dsn") );
wxString filename( wxT("/tmp/testdesigns/test.dsn") );
wxString filename( wxT("/tmp/testdesigns/test.dsn") );
FILE* fp = wxFopen( filename, wxT("r") );
FILE* fp = wxFopen( filename, wxT("r") );
if( !fp )
if( !fp )
{
{
fprintf( stderr, "unable to open file \"%s\"\n",
fprintf( stderr, "unable to open file \"%s\"\n",
(const char*) filename.mb_str() );
(const char*) filename.mb_str() );
exit(1);
exit(1);
}
}
DSN::LEXER lexer( fp, filename );
DSN::LEXER lexer( fp, filename );
try
try
{
{
int tok;
int tok;
while( (tok = lexer.NextTok()) != DSN::T_EOF )
while( (tok = lexer.NextTok()) != DSN::T_EOF )
...
@@ -837,7 +837,7 @@ int main( int argc, char** argv )
...
@@ -837,7 +837,7 @@ int main( int argc, char** argv )
}
}
fclose( fp );
fclose( fp );
return 0;
return 0;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment