pcb 4.1.1
An interactive printed circuit board layout editor.

main.c File Reference

Main program, initializes some stuff and handles user input. More...

#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <sys/stat.h>
#include <time.h>
#include "global.h"
#include "data.h"
#include "buffer.h"
#include "create.h"
#include "crosshair.h"
#include "draw.h"
#include "error.h"
#include "file.h"
#include "set.h"
#include "action.h"
#include "misc.h"
#include "lrealpath.h"
#include "free_atexit.h"
#include "polygon.h"
#include "gettext.h"
#include "pcb-printf.h"
#include "strflags.h"
#include "hid/common/actions.h"
#include "hid/hidint.h"
#include "core_lists.h"
Include dependency graph for main.c:

Go to the source code of this file.

Data Structures

struct  UsageNotes

Defines

#define PCBLIBPATH   ".:" PCBLIBDIR
#define SSET(F, D, N, H)
#define ISET(F, D, N, H)
#define BSET(F, D, N, H)
#define RSET(F, D, N, H)
#define CSET(F, D, N, H)
#define COLOR(F, D, N, H)
#define LAYERCOLOR(N, D)
#define LAYERNAME(N, D)
#define LAYERSELCOLOR(N)
#define free0(ptr)

Typedefs

typedef struct UsageNotes UsageNotes

Functions

static void InitHandler (void)
 Initialize signal and error handlers.
void copyright (void)
 Print the copyright notice.
static void u (const char *fmt,...)
static void usage_attr (HID_Attribute *a)
static void usage_hid (HID *h)
static void usage (void)
static void print_defaults_1 (HID_Attribute *a, void *value)
static void print_defaults ()
void save_increments (const Increments *mm, const Increments *mil)
 REGISTER_ATTRIBUTES (main_attribute_list)
static void print_version ()
 Print help or version messages.
static void InitPaths (char *argv0)
 See if argv0 has enough of a path to let lrealpath give the real path.
void pcb_main_uninit (void)
 Free up memory allocated to the PCB.
int main (int argc, char *argv[])
 Main program.

Variables

static char * command_line_pcb
static UsageNotesusage_notes = NULL
static int show_help = 0
static int show_version = 0
static int show_copyright = 0
static int show_defaults = 0
static int show_actions = 0
static int do_dump_actions = 0
static char * grid_units
static Increments increment_mm = { 0 }
static Increments increment_mil = { 0 }
HID_Attribute main_attribute_list []
char * bindir = NULL
char * exec_prefix = NULL
char * pcblibdir = NULL
char * pcblibpath = NULL
char * pcbtreedir = NULL
char * pcbtreepath = NULL
char * homedir = NULL
char * program_name = 0
char * program_basename = 0
char * program_directory = 0

Detailed Description

Main program, initializes some stuff and handles user input.


Copyright.


PCB, interactive printed circuit board design

Copyright (C) 1994,1995,1996, 2004 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

Definition in file main.c.


Define Documentation

#define BSET (   F,
  D,
  N,
 
)
Value:
{ N, H, \
        HID_Boolean, 0, 0, { D, 0, 0 }, 0, &Settings.F }

Definition at line 413 of file main.c.

#define COLOR (   F,
  D,
  N,
 
)
Value:
{ N, H, \
        HID_String, 0, 0, { 0, D, 0 }, 0, &Settings.F }

Definition at line 420 of file main.c.

#define CSET (   F,
  D,
  N,
 
)
Value:
{ N, H, \
        HID_Coord,    0, 0, { 0, 0, 0, D }, 0, &Settings.F }

Definition at line 417 of file main.c.

#define free0 (   ptr)
Value:
do \
    { \
      if (ptr != NULL) \
        { \
          free (ptr); \
          ptr = 0; \
        } \
    } while (0)

Referenced by pcb_main_uninit().

#define ISET (   F,
  D,
  N,
 
)
Value:
{ N, H, \
        HID_Integer, 0, 0, { D, 0, 0 }, 0, &Settings.F }

Definition at line 411 of file main.c.

#define LAYERCOLOR (   N,
 
)
Value:
{ "layer-color-" #N, "Color for layer " #N, \
        HID_String, 0, 0, { 0, D, 0 }, 0, &Settings.LayerColor[N-1] }

Definition at line 422 of file main.c.

#define LAYERNAME (   N,
 
)
Value:
{ "layer-name-" #N, "Name for layer " #N, \
        HID_String, 0, 0, { 0, D, 0 }, 0, &Settings.DefaultLayerName[N-1] }

Definition at line 424 of file main.c.

#define LAYERSELCOLOR (   N)
Value:
{ "layer-selected-color-" #N, "Color for layer " #N " when selected", \
        HID_String, 0, 0, { 0, "#00ffff", 0 }, 0, &Settings.LayerSelectedColor[N-1] }

Definition at line 426 of file main.c.

#define PCBLIBPATH   ".:" PCBLIBDIR

Definition at line 83 of file main.c.

#define RSET (   F,
  D,
  N,
 
)
Value:
{ N, H, \
        HID_Real,    0, 0, { 0, 0, D }, 0, &Settings.F }

Definition at line 415 of file main.c.

#define SSET (   F,
  D,
  N,
 
)
Value:
{ N, H, \
        HID_String,  0, 0, { 0, D, 0 }, 0, &Settings.F }

Definition at line 409 of file main.c.


Typedef Documentation

typedef struct UsageNotes UsageNotes

Function Documentation

void copyright ( void  )

Print the copyright notice.

Definition at line 124 of file main.c.

References Progname.

Referenced by main().

static void InitHandler ( void  ) [static]

Initialize signal and error handlers.

Definition at line 95 of file main.c.

Referenced by main().

static void InitPaths ( char *  argv0) [static]

See if argv0 has enough of a path to let lrealpath give the real path.

This should be the case if you invoke pcb with something like /usr/local/bin/pcb or ./pcb or ./foo/pcb but if you just use pcb and it exists in your path, you'll just get back pcb again.

Definition at line 1697 of file main.c.

References bindir, HID_Attribute::default_val, exec_prefix, homedir, lrealpath(), main_attribute_list, malloc(), NSTRCMP, pcblibdir, pcblibpath, pcbtreedir, pcbtreepath, and HID_Attr_Val::str_value.

Referenced by main().

Here is the call graph for this function:

int main ( int  argc,
char *  argv[] 
)

Main program.

Init application:

  • make program name available for error handlers
  • evaluate special options
  • initialize toplevel shell and resources
  • create an empty PCB with default symbols
  • initialize all other widgets
  • update screen and get size of drawing area
  • evaluate command-line arguments
  • register 'call on exit()' function

Definition at line 1978 of file main.c.

References _, SettingType::ActionString, ARROW_MODE, bind_textdomain_codeset, bindtextdomain, command_line_pcb, copyright(), CreateNewPCB(), CreateNewPCBPost(), PCBType::Data, SettingType::DefaultLayerName, do_dump_actions, hid_st::do_export, dump_actions(), SettingType::ElementPath, EmergencySave(), EnableAutosave(), hid_st::exporter, exporter, PCBType::Filename, SettingType::FontPath, SettingType::GnetlistProgram, SettingType::Groups, gui, hid_action(), hid_actionl(), hid_find_exporter(), hid_find_gui(), hid_find_printer(), hid_init(), hid_load_settings(), hid_parse_actions(), InitBuffers(), InitCrosshair(), InitHandler(), initialize_units(), SettingType::InitialLayerStack, InitPaths(), SettingType::LayerColor, PCBType::LayerGroups, DataType::LayerN, SettingType::LayerSelectedColor, LayerStringToLayerStack(), leaky_init(), Library, SettingType::LibraryCommandDir, SettingType::LibraryPath, SettingType::LibraryTree, LoadPCB(), SettingType::MakeProgram, LibraryType::MenuN, Message(), hid_st::parse_arguments, ParseGroupString(), PCB, pcb_dbus_finish(), pcb_dbus_setup(), pcb_main_uninit(), polygon_init(), print_actions(), print_defaults(), print_version(), hid_st::printer, Progname, program_basename, program_directory, program_name, ReadLibraryContents(), ResetStackAndVisibility(), SettingType::ScriptFilename, SetMode(), Settings, show_actions, show_copyright, show_defaults, show_help, show_version, stroke_init(), textdomain, UNKNOWN, and usage().

Here is the call graph for this function:

void pcb_main_uninit ( void  )

Free up memory allocated to the PCB.

Why bother when we're about to exit ?
Because it removes some false positives from heap bug detectors such as lib dmalloc.

Warning:
Please do not free the below variables like:
  for (i = 0; i < MAX_LAYER; i++)
    free (Settings.DefaultLayerName[i]);

  if (Settings.FontFile != NULL)
    {
      free (Settings.FontFile);
      Settings.FontFile = NULL;
    }
as these are initialized to static strings and freeing them causes segfaults when terminating the program.

Definition at line 1910 of file main.c.

References bindir, exec_prefix, free0, FreePCBMemory(), SettingType::GnetlistProgram, gui, hid_uninit(), homedir, SettingType::MakeProgram, PCB, pcblibdir, program_directory, Settings, hid_st::uninit, uninit_strflags_buf(), uninit_strflags_layerlist(), and UninitBuffers().

Referenced by main(), and QuitApplication().

Here is the call graph for this function:

static void print_defaults ( ) [static]
static void print_version ( ) [static]

Print help or version messages.

Definition at line 1670 of file main.c.

Referenced by main().

void save_increments ( const Increments mm,
const Increments mil 
)

Definition at line 439 of file main.c.

Referenced by config_sizes_apply().

static void usage ( void  ) [static]

Definition at line 263 of file main.c.

References HID_AttrNode::attributes, exporter, gui, hid_attr_nodes, hid_enumerate(), HID_AttrNode::n, UsageNotes::next, HID_AttrNode::next, Progname, UsageNotes::seen, u(), usage_attr(), and usage_hid().

Referenced by main().

Here is the call graph for this function:

static void usage_attr ( HID_Attribute a) [static]
static void usage_hid ( HID h) [static]

Definition at line 234 of file main.c.

References exporter, hid_st::get_export_options, hid_st::gui, malloc(), hid_st::name, UsageNotes::next, UsageNotes::seen, usage_attr(), and usage_notes.

Referenced by usage().

Here is the call graph for this function:


Variable Documentation

char* bindir = NULL

The dir in which PCB installation was found.

Definition at line 1680 of file main.c.

Referenced by InitPaths(), pcb_main_uninit(), and REGISTER_FLAGS().

char* command_line_pcb [static]

Definition at line 118 of file main.c.

Referenced by main().

int do_dump_actions = 0 [static]

Definition at line 434 of file main.c.

Referenced by main().

char* exec_prefix = NULL

Definition at line 1681 of file main.c.

Referenced by hid_init(), InitPaths(), and pcb_main_uninit().

char* grid_units [static]

Definition at line 435 of file main.c.

Referenced by REGISTER_ATTRIBUTES().

Increments increment_mil = { 0 } [static]

Definition at line 437 of file main.c.

Increments increment_mm = { 0 } [static]

Definition at line 436 of file main.c.

Definition at line 445 of file main.c.

Referenced by InitPaths().

char* pcblibdir = NULL

The system M4 fp directory.

Definition at line 1682 of file main.c.

Referenced by hid_load_settings(), InitPaths(), load_rc_files(), and pcb_main_uninit().

char* pcblibpath = NULL

The search path for M4 fps.

Definition at line 1683 of file main.c.

Referenced by InitPaths().

char* pcbtreedir = NULL

The system newlib fp directory.

Definition at line 1684 of file main.c.

Referenced by InitPaths().

char* pcbtreepath = NULL

The search path for newlib fps.

Definition at line 1685 of file main.c.

Referenced by InitPaths().

char* program_basename = 0

Definition at line 1897 of file main.c.

Referenced by main().

char* program_directory = 0

Definition at line 1898 of file main.c.

Referenced by main(), and pcb_main_uninit().

char* program_name = 0

Definition at line 1896 of file main.c.

Referenced by main().

int show_actions = 0 [static]

Definition at line 433 of file main.c.

Referenced by main().

int show_copyright = 0 [static]

Definition at line 431 of file main.c.

Referenced by main().

int show_defaults = 0 [static]

Definition at line 432 of file main.c.

Referenced by main().

int show_help = 0 [static]

Definition at line 429 of file main.c.

Referenced by main().

int show_version = 0 [static]

Definition at line 430 of file main.c.

Referenced by main().

UsageNotes* usage_notes = NULL [static]

Definition at line 161 of file main.c.

Referenced by usage_hid().