Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Kicad from old PCB french kicad 4022 (2013) to NEW 4.0.7 Stable Release
- // Antonio Villanueva Segura
- #include <iostream>
- #include <fstream>
- #include <string.h>
- #include <stdlib.h> //for system
- using namespace std;
- //OLD FRENCH KICAD
- string sust []={
- "Dessous.Adhes",//0 B.Adhes
- "Dessus.Adhes",//1 F.Adhes
- "Dessous.Pate",//2 B.Paste
- "Dessus.Pate",//3 F.Paste
- "Dessous.SilkS",//4 B.SilkS
- "Dessus.SilkS",//5 F.SilkS
- "Dessous.Masque",//6 B.Mask
- "Dessus.Masque",//7 F.Mask
- "Dessin.User",//8 Dwgs.User
- "Contours.Ci",//9 Margin.....
- "Dessous",//10 F.Cu
- "Dessus"//11 B.Cu
- };
- //New KICAD
- string repl[]={
- "B.Adhes",//0
- "F.Adhes",//1
- "B.Paste",//2
- "F.Paste",//3
- "B.SilkS",//4
- "F.SilkS",//5
- "B.Mask",//6
- "F.Mask",//7
- "Dwgs.User",//8
- "Edge.Cuts",//9
- "F.Cu",//10
- "B.Cu",//11
- "Margin",//12
- "B.CrtYd",//13
- "F.CrtYd",//14
- "B.Fab",//15
- "F.Fab",//16
- };
- int main(int argc, char *argv[]){
- FILE *pipe;//pipe for read dir *.kicad_pcb
- char buf[256]{0};//for read *.kicad_pcb file name
- string line;
- double pos(0);
- size_t it(0);
- cout <<" Kicad PCB converter .From old french 4022 to 4.0.7 stable "<<endl
- <<" By default, looks for *.kicad_pcb extensions ,but we can indicate "
- <<" the name as argument \n p.e (./kicad name.pcb )"<<endl<<endl;;
- if (argc ==1){//Not Params ...then search for ...ls *.kicad_pcb
- if ((pipe=popen ( "ls *.kicad_pcb","r")) <0 ){//Open system ls *.kicad_pcb
- cout<<"Error Open PIPE"<<endl;return 0;//Error OPEN PIPE
- }
- else {
- fgets(buf,256,pipe);//retrieve filename from *.kicad_pcb
- if (strlen(buf)<1 ){cout<<"Error input File";return 0;}
- buf[strlen (buf)-1]=0;
- pclose (pipe);
- }
- }
- else {
- memcpy (buf,argv[1],strlen (argv[1]));
- }
- ifstream read (string (buf),std::ifstream::in);
- ofstream write (string (buf) + "_NEW");
- cout <<"Imput PCB KICAD File = "<< buf <<endl;//Print graphic imput debug
- if (read.is_open())
- {
- while ( getline (read,line) )
- {
- for (it=0;it < (sizeof (sust) /sizeof (sust[0]) );it++){
- //If find pattern , replace it
- if ( (pos=line.find(sust [it]))< string::npos ){//Find !
- line.replace(pos,sust[it].length(),repl[it] );//Replace
- }
- }
- //cout <<line<<endl;//Graphic ctrl.
- write<<line<<endl;//Out text
- line.clear();
- }
- //Close
- read.close();
- write.close();
- //Rename files
- string move ("mv "+string (buf)+" "+string (buf)+"_OLD");
- system (move.c_str());
- move ="mv "+string (buf)+"_NEW"+" "+string (buf);
- system (move.c_str());
- }
- else cout << "Unable to open file";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement