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
558af6d7
Commit
558af6d7
authored
Feb 27, 2011
by
Dick Hollenbeck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add EscapedUTF8() and revise ReadDelimitedText() to complement it
parent
90dc2908
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
104 additions
and
42 deletions
+104
-42
string.cpp
common/string.cpp
+59
-17
kicad_string.h
include/kicad_string.h
+25
-7
toolchain-mingw.cmake
new/toolchain-mingw.cmake
+1
-1
class_pcb_text.cpp
pcbnew/class_pcb_text.cpp
+17
-13
ioascii.cpp
pcbnew/ioascii.cpp
+2
-4
No files found.
common/string.cpp
View file @
558af6d7
...
@@ -8,32 +8,74 @@
...
@@ -8,32 +8,74 @@
#include "kicad_string.h"
#include "kicad_string.h"
/* read a double-quote delimited text from source and put it in in dest,
int
ReadDelimitedText
(
char
*
aDest
,
const
char
*
aSource
,
int
aDestSize
)
* read NbMaxChar bytes max
{
* return the char count read from source
if
(
aDestSize
<=
0
)
*/
return
0
;
int
ReadDelimitedText
(
char
*
dest
,
char
*
source
,
int
NbMaxChar
)
bool
inside
=
false
;
char
*
start
=
aDest
;
char
*
limit
=
aDest
+
aDestSize
-
1
;
char
cc
;
while
(
(
cc
=
*
aSource
++
)
!=
0
&&
aDest
<
limit
)
{
if
(
cc
==
'\\'
)
{
cc
=
*
aSource
++
;
if
(
inside
)
*
aDest
++
=
cc
;
}
else
if
(
cc
==
'"'
)
{
if
(
inside
)
break
;
// 2nd double quote is end of delimited text
inside
=
true
;
// first delimiter found, make note, do not copy
}
else
if
(
inside
)
{
*
aDest
++
=
cc
;
}
}
*
aDest
=
0
;
return
aDest
-
start
;
}
std
::
string
EscapedUTF8
(
const
wxString
&
aString
)
{
{
int
ii
,
jj
,
flag
=
0
;
std
::
string
utf8
=
TO_UTF8
(
aString
);
std
::
string
ret
;
for
(
ii
=
0
,
jj
=
0
;
ii
<
NbMaxChar
-
1
;
jj
++
,
source
++
)
// ret += '"';
for
(
std
::
string
::
const_iterator
it
=
utf8
.
begin
();
it
!=
utf8
.
end
();
++
it
)
{
{
if
(
*
source
==
0
)
// this escaping strategy is designed to be compatible with ReadDelimitedText():
break
;
/* E.O.L. */
if
(
*
it
==
'"'
)
if
(
*
source
==
'"'
)
/* delimiter is " */
{
{
if
(
flag
)
ret
+=
'\\'
;
break
;
/* End of delimited text */
ret
+=
'"'
;
flag
=
1
;
/* First delimiter found. */
}
}
else
if
(
flag
)
else
if
(
*
it
==
'\\'
)
{
{
*
dest
=
*
source
;
dest
++
;
ii
++
;
ret
+=
'\\'
;
// double it up
ret
+=
'\\'
;
}
}
else
ret
+=
*
it
;
}
}
*
dest
=
0
;
/* Null terminated */
// ret += '"';
return
jj
;
return
ret
;
}
}
...
...
include/kicad_string.h
View file @
558af6d7
...
@@ -14,14 +14,32 @@
...
@@ -14,14 +14,32 @@
char
*
strupper
(
char
*
Text
);
char
*
strupper
(
char
*
Text
);
char
*
strlower
(
char
*
Text
);
char
*
strlower
(
char
*
Text
);
/* Read string delimited with (") character.
* Upload NbMaxChar max
/**
* Returns the number of codes read in source
* Function ReadDelimitedText
* dest is terminated by NULL
* extracts bytes from @a aSource delimited string segment to @a aDest buffer.
* The extracted string will be null terminated even if truncation is necessary
* because aDestSize was not large enough.
*
* @param aDest is the destination byte buffer.
* @param aSource is the source bytes as a C string.
* @param aDestSize is the size of the destination byte buffer.
* @return int - the number of bytes extracted.
*/
*/
int
ReadDelimitedText
(
char
*
dest
,
int
ReadDelimitedText
(
char
*
aDest
,
const
char
*
aSource
,
int
aDestSize
);
char
*
source
,
int
NbMaxChar
);
/**
* Function EscapedUTF8
* returns an 8 bit UTF8 string given aString in unicode form.
* Any double quoted or back slashes are prefixed with a '\\' byte and the form
* of this UTF8 byte string is compatible with function ReadDelimitedText().
*
* @param aString is the input string to convert.
* @return std::string - the escaped input text, without the wrapping double quotes.
*/
std
::
string
EscapedUTF8
(
const
wxString
&
aString
);
/* Read one line line from a file.
/* Read one line line from a file.
* Returns the first useful line read by eliminating blank lines and comments.
* Returns the first useful line read by eliminating blank lines and comments.
...
...
new/toolchain-mingw.cmake
View file @
558af6d7
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
# It is here to assist Dick with verifying compilation of /new stuff with mingw (under linux)
# It is here to assist Dick with verifying compilation of /new stuff with mingw (under linux)
set
(
CMAKE_SYSTEM_NAME
Linux
)
set
(
CMAKE_SYSTEM_NAME
Windows
)
#-----<configuration>-----------------------------------------------
#-----<configuration>-----------------------------------------------
...
...
pcbnew/class_pcb_text.cpp
View file @
558af6d7
...
@@ -80,31 +80,31 @@ void TEXTE_PCB::Copy( TEXTE_PCB* source )
...
@@ -80,31 +80,31 @@ void TEXTE_PCB::Copy( TEXTE_PCB* source )
*/
*/
int
TEXTE_PCB
::
ReadTextePcbDescr
(
LINE_READER
*
aReader
)
int
TEXTE_PCB
::
ReadTextePcbDescr
(
LINE_READER
*
aReader
)
{
{
char
*
L
ine
;
char
*
l
ine
;
char
text
[
1024
];
char
text
[
1024
];
char
style
[
256
];
char
style
[
256
];
while
(
aReader
->
ReadLine
()
)
while
(
aReader
->
ReadLine
()
)
{
{
L
ine
=
aReader
->
Line
();
l
ine
=
aReader
->
Line
();
if
(
strnicmp
(
L
ine
,
"$EndTEXTPCB"
,
11
)
==
0
)
if
(
strnicmp
(
l
ine
,
"$EndTEXTPCB"
,
11
)
==
0
)
return
0
;
return
0
;
if
(
strncmp
(
L
ine
,
"Te"
,
2
)
==
0
)
/* Text line (first line for multi line texts */
if
(
strncmp
(
l
ine
,
"Te"
,
2
)
==
0
)
/* Text line (first line for multi line texts */
{
{
ReadDelimitedText
(
text
,
L
ine
+
2
,
sizeof
(
text
)
);
ReadDelimitedText
(
text
,
l
ine
+
2
,
sizeof
(
text
)
);
m_Text
=
CONV_FROM_UTF8
(
text
);
m_Text
=
CONV_FROM_UTF8
(
text
);
continue
;
continue
;
}
}
if
(
strncmp
(
L
ine
,
"nl"
,
2
)
==
0
)
/* next line of the current text */
if
(
strncmp
(
l
ine
,
"nl"
,
2
)
==
0
)
/* next line of the current text */
{
{
ReadDelimitedText
(
text
,
L
ine
+
2
,
sizeof
(
text
)
);
ReadDelimitedText
(
text
,
l
ine
+
2
,
sizeof
(
text
)
);
m_Text
.
Append
(
'\n'
);
m_Text
.
Append
(
'\n'
);
m_Text
+=
CONV_FROM_UTF8
(
text
);
m_Text
+=
CONV_FROM_UTF8
(
text
);
continue
;
continue
;
}
}
if
(
strncmp
(
L
ine
,
"Po"
,
2
)
==
0
)
if
(
strncmp
(
l
ine
,
"Po"
,
2
)
==
0
)
{
{
sscanf
(
L
ine
+
2
,
" %d %d %d %d %d %d"
,
sscanf
(
l
ine
+
2
,
" %d %d %d %d %d %d"
,
&
m_Pos
.
x
,
&
m_Pos
.
y
,
&
m_Size
.
x
,
&
m_Size
.
y
,
&
m_Pos
.
x
,
&
m_Pos
.
y
,
&
m_Size
.
x
,
&
m_Size
.
y
,
&
m_Thickness
,
&
m_Orient
);
&
m_Thickness
,
&
m_Orient
);
...
@@ -115,11 +115,11 @@ int TEXTE_PCB::ReadTextePcbDescr( LINE_READER* aReader )
...
@@ -115,11 +115,11 @@ int TEXTE_PCB::ReadTextePcbDescr( LINE_READER* aReader )
m_Size
.
y
=
5
;
m_Size
.
y
=
5
;
continue
;
continue
;
}
}
if
(
strncmp
(
L
ine
,
"De"
,
2
)
==
0
)
if
(
strncmp
(
l
ine
,
"De"
,
2
)
==
0
)
{
{
style
[
0
]
=
0
;
style
[
0
]
=
0
;
int
normal_display
=
1
;
int
normal_display
=
1
;
sscanf
(
L
ine
+
2
,
" %d %d %lX %s
\n
"
,
&
m_Layer
,
&
normal_display
,
sscanf
(
l
ine
+
2
,
" %d %d %lX %s
\n
"
,
&
m_Layer
,
&
normal_display
,
&
m_TimeStamp
,
style
);
&
m_TimeStamp
,
style
);
m_Mirror
=
normal_display
?
false
:
true
;
m_Mirror
=
normal_display
?
false
:
true
;
...
@@ -157,18 +157,22 @@ bool TEXTE_PCB::Save( FILE* aFile ) const
...
@@ -157,18 +157,22 @@ bool TEXTE_PCB::Save( FILE* aFile ) const
const
char
*
style
=
m_Italic
?
"Italic"
:
"Normal"
;
const
char
*
style
=
m_Italic
?
"Italic"
:
"Normal"
;
wxArrayString
*
list
=
wxStringSplit
(
m_Text
,
'\n'
);
wxArrayString
*
list
=
wxStringSplit
(
m_Text
,
'\n'
);
for
(
unsigned
ii
=
0
;
ii
<
list
->
Count
();
ii
++
)
for
(
unsigned
ii
=
0
;
ii
<
list
->
Count
();
ii
++
)
{
{
wxString
txt
=
list
->
Item
(
ii
);
wxString
txt
=
list
->
Item
(
ii
);
if
(
ii
==
0
)
if
(
ii
==
0
)
fprintf
(
aFile
,
"Te
\"
%s
\"\n
"
,
CONV_TO_UTF8
(
txt
)
);
fprintf
(
aFile
,
"Te
\"
%s
\"\n
"
,
EscapedUTF8
(
txt
).
c_str
(
)
);
else
else
fprintf
(
aFile
,
"nl
\"
%s
\"\n
"
,
CONV_TO_UTF8
(
txt
)
);
fprintf
(
aFile
,
"nl
\"
%s
\"\n
"
,
CONV_TO_UTF8
(
txt
)
);
}
}
delete
(
list
);
delete
list
;
fprintf
(
aFile
,
"Po %d %d %d %d %d %d
\n
"
,
fprintf
(
aFile
,
"Po %d %d %d %d %d %d
\n
"
,
m_Pos
.
x
,
m_Pos
.
y
,
m_Size
.
x
,
m_Size
.
y
,
m_Thickness
,
m_Orient
);
m_Pos
.
x
,
m_Pos
.
y
,
m_Size
.
x
,
m_Size
.
y
,
m_Thickness
,
m_Orient
);
fprintf
(
aFile
,
"De %d %d %lX %s
\n
"
,
m_Layer
,
fprintf
(
aFile
,
"De %d %d %lX %s
\n
"
,
m_Layer
,
m_Mirror
?
0
:
1
,
m_Mirror
?
0
:
1
,
m_TimeStamp
,
style
);
m_TimeStamp
,
style
);
...
...
pcbnew/ioascii.cpp
View file @
558af6d7
...
@@ -327,13 +327,11 @@ int WinEDA_BasePcbFrame::ReadSetup( LINE_READER* aReader )
...
@@ -327,13 +327,11 @@ int WinEDA_BasePcbFrame::ReadSetup( LINE_READER* aReader )
}
}
catch
(
IO_ERROR
&
e
)
catch
(
IO_ERROR
&
e
)
{
{
#if 1
wxString
msg
;
wxString
msg
;
msg
.
Printf
(
wxT
(
"Error reading PcbPlotParams from %s:
\n
%s"
),
msg
.
Printf
(
_
(
"Error reading PcbPlotParams from %s:
\n
%s"
),
aReader
->
GetSource
().
GetData
(),
aReader
->
GetSource
().
GetData
(),
e
.
errorText
.
GetData
()
);
e
.
errorText
.
GetData
()
);
wxMessageBox
(
msg
,
wxT
(
"Open Board File"
),
wxICON_ERROR
);
wxMessageBox
(
msg
,
_
(
"Open Board File"
),
wxICON_ERROR
);
#endif
}
}
continue
;
continue
;
...
...
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