pcb 4.1.1
An interactive printed circuit board layout editor.

file.c File Reference

File save, load, merge ... routines. More...

#include "global.h"
#include <dirent.h>
#include <time.h>
#include <sys/stat.h>
#include <stdio.h>
#include "buffer.h"
#include "change.h"
#include "create.h"
#include "crosshair.h"
#include "data.h"
#include "edif_parse.h"
#include "error.h"
#include "file.h"
#include "hid.h"
#include "layerflags.h"
#include "misc.h"
#include "mymem.h"
#include "parse_l.h"
#include "pcb-printf.h"
#include "polygon.h"
#include "rats.h"
#include "remove.h"
#include "set.h"
#include "strflags.h"
Include dependency graph for file.c:

Go to the source code of this file.

Defines

#define F2S(OBJ, TYPE)   flags_to_string ((OBJ)->Flags, TYPE)
#define PCB_FILE_VERSION_BURIED_VIAS   20170218
#define PCB_FILE_VERSION_HOLES   20100606
#define PCB_FILE_VERSION_BASELINE   20091103
#define BLANK(x)

Functions

static void PrintQuotedString (FILE *FP, char *S)
 Writes the quoted string created by another subroutine.
static void WritePCBInfoHeader (FILE *FP)
 Writes layout header information.
static void WritePCBDataHeader (FILE *FP)
 Writes data header.
static void WritePCBFontData (FILE *FP)
 Writes font data of non empty symbols.
static void WriteViaData (FILE *FP, DataType *Data)
 Writes via data.
static void WritePCBRatData (FILE *FP)
 Writes rat-line data.
static void WriteElementData (FILE *FP, DataType *Data)
 Writes element data.
static void WriteLayerData (FILE *FP, Cardinal Number, LayerType *layer)
 Writes layer data.
static int WritePCB (FILE *FP)
 Writes PCB to file.
static int WritePCBFile (char *Filename)
 Writes PCB to file.
static int WritePipe (char *Filename, bool thePcb)
 Writes to pipe using the command defined by Settings.SaveCommand f are replaced by the passed filename.
static int ParseLibraryTree (void)
 This function loads the newlib footprints into the Library.
static int LoadNewlibFootprintsFromDir (char *libpath, char *toppath, bool recursive)
 Parse the directory tree where newlib footprints are found.
int PCBFileVersionNeeded (void)
static int string_cmp (const char *a, const char *b)
static int netlist_sort (const void *va, const void *vb)
static int netnode_sort (const void *va, const void *vb)
static void sort_library (LibraryType *lib)
void sort_netlist ()
FILE * CheckAndOpenFile (char *Filename, bool Confirm, bool AllButton, bool *WasAllButton, bool *WasCancelButton)
 Opens a file and check if it exists.
FILE * OpenConnectionDataFile (void)
 Opens a file for saving connection data.
int SaveBufferElements (char *Filename)
 Save elements in the current buffer.
int SavePCB (char *file)
 Save PCB.
static void set_some_route_style ()
 Set the route style to the first one, if the current one doesn't happen to match any.
static int real_load_pcb (char *Filename, bool revert)
 Load PCB.
int LoadPCB (char *file)
 Load PCB.
int RevertPCB (void)
 Revert PCB.
static void WriteAttributeList (FILE *FP, AttributeListType *list, char *prefix)
 Writes out an attribute list.
static void WritePCBNetlistData (FILE *FP)
 Writes netlist data.
static int WriteBuffer (FILE *FP)
 Writes just the elements in the buffer to file.
void SaveInTMP (void)
 Saves the layout in a temporary file.
void EmergencySave (void)
void DisableEmergencySave (void)
static void backup_cb (hidval data)
 Callback for the autosave.
void EnableAutosave (void)
void Backup (void)
 Creates a backup file.
void SaveTMPData (void)
 Makes a temporary copy of the data.
void RemoveTMPData (void)
 Removes the temporary copy of the data file.
int ReadLibraryContents (void)
 Read contents of the library description file (for M4) and then read in M4 libs.
int ReadNetlist (char *filename)
 Read in a netlist and store it in the netlist menu.
static int ReadEdifNetlist (char *filename)
int ImportNetlist (char *filename)

Variables

static char TMPFilename [80]
static int netlist_sort_offset = 0
static bool dont_save_any_more = false
 Front-end for 'SaveInTMP()'.
static hidval backup_timer

Detailed Description

File save, load, merge ... routines.


Copyright.


PCB, interactive printed circuit board design

Copyright (C) 1994,1995,1996,1997,1998,2005,2006 Thomas Nau

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

Contact addresses for paper mail and Email: Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany Thomas.Nau@rz.uni-ulm.de

Note:
getpid() needs a cast to (int) to get rid of compiler warnings on several architectures.

Definition in file file.c.


Define Documentation

#define BLANK (   x)
Value:
((x) == ' ' || (x) == '\t' || (x) == '\n' \
                || (x) == '\0')

Definition at line 1531 of file file.c.

Referenced by ReadNetlist().

#define F2S (   OBJ,
  TYPE 
)    flags_to_string ((OBJ)->Flags, TYPE)

Definition at line 134 of file file.c.

Referenced by WriteElementData(), WriteLayerData(), WritePCBRatData(), and WriteViaData().

#define PCB_FILE_VERSION_BASELINE   20091103

First version ever saved.

Definition at line 164 of file file.c.

Referenced by PCBFileVersionNeeded().

#define PCB_FILE_VERSION_BURIED_VIAS   20170218

Buried vias

Definition at line 160 of file file.c.

Referenced by PCBFileVersionNeeded().

#define PCB_FILE_VERSION_HOLES   20100606

Hole[] in Polygon.

Definition at line 162 of file file.c.

Referenced by PCBFileVersionNeeded().


Function Documentation

void Backup ( void  )

Creates a backup file.

The default is to use the pcb file name with a "~" appended (like "foo.pcb~") and if we don't have a pcb file name then use the template in BACKUP_NAME.

Definition at line 1084 of file file.c.

References PCBType::Filename, filename, malloc(), PCB, and WritePCBFile().

Referenced by backup_cb().

Here is the call graph for this function:

static void backup_cb ( hidval  data) [static]

Callback for the autosave.

If the backup interval is > 0 then set another timer.
Otherwise we do nothing and it is up to the GUI to call EnableAutosave() after setting Settings.
BackupInterval > 0 again.

Definition at line 1048 of file file.c.

References hid_st::add_timer, Backup(), SettingType::BackupInterval, gui, hidval::ptr, and Settings.

Referenced by EnableAutosave().

Here is the call graph for this function:

FILE* CheckAndOpenFile ( char *  Filename,
bool  Confirm,
bool  AllButton,
bool *  WasAllButton,
bool *  WasCancelButton 
)

Opens a file and check if it exists.

Definition at line 262 of file file.c.

References _, hid_st::confirm_dialog, fp, gui, and OpenErrorMessage().

Referenced by ActionSaveTo(), and OpenConnectionDataFile().

Here is the call graph for this function:

void DisableEmergencySave ( void  )

Definition at line 1032 of file file.c.

References dont_save_any_more.

Referenced by QuitApplication().

void EmergencySave ( void  )

Definition at line 1021 of file file.c.

References dont_save_any_more, and SaveInTMP().

Referenced by main(), MyFatal(), and QuitApplication().

Here is the call graph for this function:

void EnableAutosave ( void  )

Definition at line 1058 of file file.c.

References hid_st::add_timer, backup_cb(), SettingType::BackupInterval, gui, hidval::ptr, Settings, hid_st::stop_timer, and x.

Referenced by config_backup_spin_button_cb(), and main().

Here is the call graph for this function:

int ImportNetlist ( char *  filename)

Definition at line 1659 of file file.c.

References fp, ReadEdifNetlist(), and ReadNetlist().

Referenced by ActionLoadFrom().

Here is the call graph for this function:

static int LoadNewlibFootprintsFromDir ( char *  libpath,
char *  toppath,
bool  recursive 
) [static]

Parse the directory tree where newlib footprints are found.

This is a helper function for ParseLibrary Tree.
Given a char *path, it finds all newlib footprints in that dir, sticks them into the library menu structure named entry, and recurses into subdirectories.

Definition at line 1149 of file file.c.

References _, LibraryEntryType::AllocatedMemory, ChdirErrorMessage(), GetLibraryEntryMemory(), GetLibraryMenuMemory(), GetWorkingDirectory(), len, Library, LibraryEntryType::ListEntry, Message(), NSTRCMP, OpendirErrorMessage(), and LibraryEntryType::Template.

Referenced by ParseLibraryTree().

Here is the call graph for this function:

int LoadPCB ( char *  file)

Load PCB.

Definition at line 498 of file file.c.

References real_load_pcb().

Referenced by ActionLoadFrom(), and main().

Here is the call graph for this function:

static int netlist_sort ( const void *  va,
const void *  vb 
) [static]

Definition at line 217 of file file.c.

References LibraryMenuType::Name, and string_cmp().

Referenced by sort_library().

Here is the call graph for this function:

static int netnode_sort ( const void *  va,
const void *  vb 
) [static]

Definition at line 231 of file file.c.

References LibraryEntryType::ListEntry, and string_cmp().

Referenced by sort_library().

Here is the call graph for this function:

FILE* OpenConnectionDataFile ( void  )

Opens a file for saving connection data.

Definition at line 308 of file file.c.

References _, CheckAndOpenFile(), hid_st::fileselect, fp, and gui.

Here is the call graph for this function:

static int ParseLibraryTree ( void  ) [static]

This function loads the newlib footprints into the Library.

It examines all directories pointed to by Settings.LibraryTree. It calls the subfunction LoadNewlibFootprintsFromDir to put the footprints into PCB's internal datastructures.

Definition at line 1330 of file file.c.

References _, ChdirErrorMessage(), GetWorkingDirectory(), SettingType::LibraryTree, LoadNewlibFootprintsFromDir(), Message(), and Settings.

Referenced by ReadLibraryContents().

Here is the call graph for this function:

int PCBFileVersionNeeded ( void  )

This is the version needed by the file we're saving.

Definition at line 167 of file file.c.

References ALLPOLYGON_LOOP, PCBType::Data, END_LOOP, ENDALL_LOOP, PCB, PCB_FILE_VERSION_BASELINE, PCB_FILE_VERSION_BURIED_VIAS, PCB_FILE_VERSION_HOLES, and VIA_LOOP.

Referenced by WritePCBDataHeader().

static void PrintQuotedString ( FILE *  FP,
char *  S 
) [static]

Writes the quoted string created by another subroutine.

Definition at line 516 of file file.c.

References CreateQuotedString(), and DynamicStringType::Data.

Referenced by WriteAttributeList(), WriteElementData(), WriteLayerData(), WritePCBDataHeader(), WritePCBNetlistData(), and WriteViaData().

Here is the call graph for this function:

static int ReadEdifNetlist ( char *  filename) [static]

Definition at line 1684 of file file.c.

References _, Message(), and ParseEDIF().

Referenced by ImportNetlist().

Here is the call graph for this function:

int ReadNetlist ( char *  filename)
static int real_load_pcb ( char *  Filename,
bool  revert 
) [static]
void RemoveTMPData ( void  )

Removes the temporary copy of the data file.

Definition at line 1134 of file file.c.

References TMPFilename.

Referenced by Parse().

int RevertPCB ( void  )

Revert PCB.

Definition at line 507 of file file.c.

References PCBType::Filename, PCB, and real_load_pcb().

Referenced by ActionLoadFrom(), and info_bar_response_cb().

Here is the call graph for this function:

int SaveBufferElements ( char *  Filename)

Save elements in the current buffer.

Definition at line 342 of file file.c.

References SWAP_IDENT, SwapBuffers(), and WritePipe().

Referenced by ActionPasteBuffer(), and ActionSaveTo().

Here is the call graph for this function:

void SaveInTMP ( void  )

Saves the layout in a temporary file.

This is used for fatal errors and does not call the program specified in 'saveCommand' for safety reasons.

Definition at line 1001 of file file.c.

References _, PCBType::Changed, filename, Message(), PCB, and WritePCBFile().

Referenced by ActionNew(), and EmergencySave().

Here is the call graph for this function:

int SavePCB ( char *  file)

Save PCB.

Definition at line 358 of file file.c.

References gui, hid_st::notify_save_pcb, and WritePipe().

Referenced by ActionSaveTo().

Here is the call graph for this function:

void SaveTMPData ( void  )

Makes a temporary copy of the data.

This is useful for systems which doesn't support calling functions on exit.
We use this to save the data before LEX and YACC functions are called because they are able to abort the program.

Definition at line 1124 of file file.c.

References TMPFilename, and WritePCBFile().

Referenced by Parse().

Here is the call graph for this function:

static void set_some_route_style ( ) [static]

Set the route style to the first one, if the current one doesn't happen to match any.

This way, "revert" won't change the route style.

Definition at line 379 of file file.c.

References RouteStyleType::Diameter, hid_get_flag(), RouteStyleType::Hole, RouteStyleType::Keepaway, PCB, PCBType::RouteStyle, SetKeepawayWidth(), SetLineSize(), SetViaDrillingHole(), SetViaSize(), and RouteStyleType::Thick.

Referenced by real_load_pcb().

Here is the call graph for this function:

static void sort_library ( LibraryType lib) [static]

Definition at line 241 of file file.c.

References LibraryMenuType::Entry, LibraryMenuType::EntryN, LibraryType::Menu, LibraryType::MenuN, netlist_sort(), and netnode_sort().

Referenced by ReadLibraryContents(), and sort_netlist().

Here is the call graph for this function:

void sort_netlist ( void  )

Definition at line 251 of file file.c.

References netlist_sort_offset, PCBType::NetlistLib, PCB, and sort_library().

Referenced by Netlist(), ReadNetlist(), and real_load_pcb().

Here is the call graph for this function:

static int string_cmp ( const char *  a,
const char *  b 
) [static]

Definition at line 187 of file file.c.

Referenced by netlist_sort(), and netnode_sort().

static void WriteAttributeList ( FILE *  FP,
AttributeListType list,
char *  prefix 
) [static]

Writes out an attribute list.

Definition at line 528 of file file.c.

References AttributeListType::List, AttributeType::name, AttributeListType::Number, PrintQuotedString(), and AttributeType::value.

Referenced by WriteElementData(), WriteLayerData(), and WritePCB().

Here is the call graph for this function:

static int WriteBuffer ( FILE *  FP) [static]

Writes just the elements in the buffer to file.

Definition at line 872 of file file.c.

References max_copper_layer, PASTEBUFFER, SILK_LAYER, STATUS_OK, WriteElementData(), WriteLayerData(), and WriteViaData().

Referenced by WritePipe().

Here is the call graph for this function:

static int WritePCBFile ( char *  Filename) [static]

Writes PCB to file.

Definition at line 913 of file file.c.

References fp, OpenErrorMessage(), STATUS_ERROR, and WritePCB().

Referenced by Backup(), SaveInTMP(), and SaveTMPData().

Here is the call graph for this function:

static void WritePCBFontData ( FILE *  FP) [static]

Writes font data of non empty symbols.

Definition at line 610 of file file.c.

References SymbolType::Delta, PCBType::Font, SymbolType::Line, line, SymbolType::LineN, PCB, pcb_fprintf(), FontType::Symbol, and SymbolType::Valid.

Referenced by WritePCB().

Here is the call graph for this function:

static void WritePCBInfoHeader ( FILE *  FP) [static]

Writes layout header information.

Definition at line 546 of file file.c.

References Progname.

Referenced by WritePCB().

static void WritePCBNetlistData ( FILE *  FP) [static]

Writes netlist data.

Definition at line 677 of file file.c.

References LibraryMenuType::Entry, LibraryMenuType::EntryN, LibraryEntryType::ListEntry, LibraryType::Menu, LibraryType::MenuN, n, LibraryMenuType::Name, PCBType::NetlistLib, PCB, PrintQuotedString(), LibraryMenuType::Style, and UNKNOWN.

Referenced by WritePCB().

Here is the call graph for this function:

static void WritePCBRatData ( FILE *  FP) [static]

Writes rat-line data.

Definition at line 659 of file file.c.

References PCBType::Data, F2S, RatType::group1, RatType::group2, line, PCB, pcb_fprintf(), and DataType::Rat.

Referenced by WritePCB().

Here is the call graph for this function:

static int WritePipe ( char *  Filename,
bool  thePcb 
) [static]

Writes to pipe using the command defined by Settings.SaveCommand f are replaced by the passed filename.

Definition at line 933 of file file.c.

References command, PCBType::Data, DynamicStringType::Data, DSAddCharacter(), DSAddString(), DSClearString(), EMPTY_STRING_P, fp, PCBType::is_footprint, Message(), PCB, PopenErrorMessage(), SettingType::SaveCommand, Settings, STATUS_ERROR, WriteBuffer(), WriteElementData(), and WritePCB().

Referenced by SaveBufferElements(), and SavePCB().

Here is the call graph for this function:

static void WriteViaData ( FILE *  FP,
DataType Data 
) [static]

Writes via data.

Definition at line 639 of file file.c.

References pin_st::BuriedFrom, pin_st::BuriedTo, pin_st::Clearance, pin_st::DrillingHole, EMPTY, F2S, pin_st::Mask, pin_st::Name, pcb_fprintf(), PrintQuotedString(), pin_st::Thickness, DataType::Via, pin_st::X, and pin_st::Y.

Referenced by WriteBuffer(), and WritePCB().

Here is the call graph for this function:


Variable Documentation

hidval backup_timer [static]

Definition at line 1037 of file file.c.

bool dont_save_any_more = false [static]

Front-end for 'SaveInTMP()'.

Just makes sure that the routine is only called once.

Definition at line 1019 of file file.c.

Referenced by DisableEmergencySave(), and EmergencySave().

int netlist_sort_offset = 0 [static]

Definition at line 214 of file file.c.

Referenced by sort_netlist().

char TMPFilename[80] [static]

Definition at line 110 of file file.c.

Referenced by RemoveTMPData(), and SaveTMPData().