JWM Source Documentation
Typedefs | Functions | Variables
parse.c File Reference

JWM configuration parser. More...

#include "jwm.h"
#include "parse.h"
#include "lex.h"
#include "settings.h"
#include "menu.h"
#include "root.h"
#include "tray.h"
#include "group.h"
#include "misc.h"
#include "swallow.h"
#include "pager.h"
#include "error.h"
#include "key.h"
#include "main.h"
#include "font.h"
#include "icon.h"
#include "command.h"
#include "taskbar.h"
#include "traybutton.h"
#include "clock.h"
#include "dock.h"
#include "background.h"
#include "spacer.h"
#include "desktop.h"
#include "border.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <errno.h>

Go to the source code of this file.

Typedefs

typedef void(* AddTrayActionFunc )(TrayComponentType *, const char *, int)
 

Functions

static char ParseFile (const char *fileName, int depth)
 Parse a specific file.
 
static char * ReadFile (FILE *fd)
 Read a file.
 
static TokenNodeTokenizeFile (const char *fileName)
 Tokenize a file by memory mapping it.
 
static TokenNodeTokenizePipe (const char *command)
 Tokenize the output of a command.
 
static void Parse (const TokenNode *start, int depth)
 Parse a token list.
 
static void ParseInclude (const TokenNode *tp, int depth)
 Parse an include.
 
static void ParseDesktops (const TokenNode *tp)
 Parse desktop configuration.
 
static void ParseDesktop (int desktop, const TokenNode *tp)
 Parse a configuration for a specific desktop.
 
static void ParseDesktopBackground (int desktop, const TokenNode *tp)
 Parse a background for a desktop.
 
static MenuParseMenu (const TokenNode *start)
 Parse a menu.
 
static void ParseRootMenu (const TokenNode *start)
 Parse a root menu.
 
static MenuItemParseMenuItem (const TokenNode *start, Menu *menu, MenuItem *last)
 Parse a menu item.
 
static MenuItemInsertMenuItem (MenuItem *last)
 Insert a new menu item into a menu.
 
static MenuItemParseMenuInclude (const TokenNode *tp, Menu *menu, MenuItem *last)
 Parse a menu include.
 
static TokenNodeParseMenuIncludeHelper (const TokenNode *tp, const char *command)
 Get tokens from a menu include (either dynamic or static).
 
static void ParseTray (const TokenNode *tp)
 Parse tray.
 
static void ParsePager (const TokenNode *tp, TrayType *tray)
 Parse a pager tray component.
 
static void ParseTaskList (const TokenNode *tp, TrayType *tray)
 Parse a task list tray component.
 
static void ParseSwallow (const TokenNode *tp, TrayType *tray)
 Parse a swallow tray component.
 
static void ParseTrayButton (const TokenNode *tp, TrayType *tray)
 Parse a button tray component.
 
static void ParseClock (const TokenNode *tp, TrayType *tray)
 Parse a clock tray component.
 
static void ParseTrayComponentActions (const TokenNode *tp, TrayComponentType *cp, AddTrayActionFunc func)
 Parse tray component actions.
 
static void ParseDock (const TokenNode *tp, TrayType *tray)
 Parse a dock tray component.
 
static void ParseSpacer (const TokenNode *tp, TrayType *tray)
 Parse a spacer tray component.
 
static void ParseGroup (const TokenNode *tp)
 Parse an option group.
 
static void ParseGroupOption (const TokenNode *tp, struct GroupType *group, const char *option)
 Parse a option group option.
 
static void ParseWindowStyle (const TokenNode *tp)
 Parse window style.
 
static void ParseActiveWindowStyle (const TokenNode *tp)
 Parse active window style information.
 
static void ParseTrayStyle (const TokenNode *tp, FontType font, ColorType fg)
 Parse tray style.
 
static void ParseActive (const TokenNode *tp, ColorType fg, ColorType bg1, ColorType bg2, ColorType up, ColorType down)
 Parse active tray style.
 
static void ParsePagerStyle (const TokenNode *tp)
 Parse pager style.
 
static void ParseClockStyle (const TokenNode *tp)
 Parse clock style.
 
static void ParseMenuStyle (const TokenNode *tp)
 Parse menu style.
 
static void ParsePopupStyle (const TokenNode *tp)
 Parse popup style.
 
static void ParseKey (const TokenNode *tp)
 Parse a key binding.
 
static void ParseSnapMode (const TokenNode *tp)
 Parse snap mode for moving windows.
 
static void ParseMoveMode (const TokenNode *tp)
 Parse move mode.
 
static void ParseResizeMode (const TokenNode *tp)
 Parse resize mode.
 
static void ParseFocusModel (const TokenNode *tp)
 Parse focus model.
 
static AlignmentType ParseTextAlignment (const TokenNode *tp)
 Parse text alignment.
 
static void ParseDecorations (const TokenNode *tp, DecorationsType *deco)
 Parse decorations type.
 
static void ParseGradient (const char *value, ColorType a, ColorType b)
 Parse a color which may be a gradient.
 
static char * FindAttribute (AttributeNode *ap, const char *name)
 Find an attribute in a list of attributes.
 
static int ParseTokenValue (const StringMappingType *mapping, int count, const TokenNode *tp, int def)
 Parse a token value using a string mapping.
 
static int ParseAttribute (const StringMappingType *mapping, int count, const TokenNode *tp, const char *attr, int def)
 Parse a string using a string mapping.
 
static unsigned int ParseUnsigned (const TokenNode *tp, const char *str)
 Parse an unsigned integer.
 
static unsigned int ParseOpacity (const TokenNode *tp, const char *str)
 Parse opacity (a float between 0.0 and 1.0).
 
static WinLayerType ParseLayer (const TokenNode *tp, const char *str)
 Parse layer.
 
static StatusWindowType ParseStatusWindowType (const TokenNode *tp)
 Parse status window type.
 
static void InvalidTag (const TokenNode *tp, TokenType parent)
 Display an invalid tag error message.
 
static void ParseError (const TokenNode *tp, const char *str,...)
 Display a parser error.
 
void ParseConfig (const char *fileName)
 Parse the JWM configuration.
 
MenuParseDynamicMenu (const char *command)
 Parse a dynamic menu (called from menu code).
 
void ParseTrayButtonStyle (const TokenNode *tp)
 Parse the tray button style.
 

Variables

static const StringMappingType KEY_MAP []
 Mapping of key names to key types.
 
static const unsigned int KEY_MAP_COUNT = ARRAY_LENGTH(KEY_MAP)
 
static const StringMappingType OPTION_MAP []
 Mapping of names to group options.
 
static const unsigned int OPTION_MAP_COUNT = ARRAY_LENGTH(OPTION_MAP)
 
static const char * DEFAULT_TITLE = "JWM"
 
static const char * LABEL_ATTRIBUTE = "label"
 
static const char * ICON_ATTRIBUTE = "icon"
 
static const char * TOOLTIP_ATTRIBUTE = "tooltip"
 
static const char * CONFIRM_ATTRIBUTE = "confirm"
 
static const char * LABELED_ATTRIBUTE = "labeled"
 
static const char * ONROOT_ATTRIBUTE = "onroot"
 
static const char * X_ATTRIBUTE = "x"
 
static const char * Y_ATTRIBUTE = "y"
 
static const char * WIDTH_ATTRIBUTE = "width"
 
static const char * HEIGHT_ATTRIBUTE = "height"
 
static const char * DYNAMIC_ATTRIBUTE = "dynamic"
 
static const char * FALSE_VALUE = "false"
 
static const char * TRUE_VALUE = "true"
 

Detailed Description

JWM configuration parser.

Author
Joe Wingbermuehle
Date
2004-2006

Definition in file parse.c.

Typedef Documentation

typedef void(* AddTrayActionFunc)(TrayComponentType *, const char *, int)

Definition at line 167 of file parse.c.

Function Documentation

char * FindAttribute ( AttributeNode ap,
const char *  name 
)
static
MenuItem * InsertMenuItem ( MenuItem last)
static

Insert a new menu item into a menu.

Definition at line 506 of file parse.c.

References CreateMenuItem(), MENU_ITEM_NORMAL, and MenuItem::next.

Referenced by ParseMenuItem().

void InvalidTag ( const TokenNode tp,
TokenType  parent 
)
static
void Parse ( const TokenNode start,
int  depth 
)
static
void ParseActive ( const TokenNode tp,
ColorType  fg,
ColorType  bg1,
ColorType  bg2,
ColorType  up,
ColorType  down 
)
static
void ParseActiveWindowStyle ( const TokenNode tp)
static
int ParseAttribute ( const StringMappingType mapping,
int  count,
const TokenNode tp,
const char *  attr,
int  def 
)
static

Parse a string using a string mapping.

Definition at line 1823 of file parse.c.

References _, TokenNode::attributes, FindAttribute(), FindValue(), JLIKELY, and ParseError().

Referenced by ParseStatusWindowType(), and ParseTray().

void ParseClock ( const TokenNode tp,
TrayType tray 
)
static
void ParseClockStyle ( const TokenNode tp)
static
void ParseConfig ( const char *  fileName)

Parse the JWM configuration.

Parse a configuration file.

Definition at line 223 of file parse.c.

References _, JUNLIKELY, ParseError(), ParseFile(), ValidateKeys(), and ValidateTrayButtons().

Referenced by main(), and ReloadMenu().

void ParseDecorations ( const TokenNode tp,
DecorationsType deco 
)
static

Parse decorations type.

Definition at line 1738 of file parse.c.

References _, TokenNode::attributes, DECO_FLAT, DECO_MOTIF, FindAttribute(), and ParseError().

Referenced by ParseMenuStyle(), ParseTrayStyle(), and ParseWindowStyle().

void ParseDesktop ( int  desktop,
const TokenNode tp 
)
static

Parse a configuration for a specific desktop.

Definition at line 1016 of file parse.c.

References TokenNode::attributes, FindAttribute(), InvalidTag(), TokenNode::next, ParseDesktopBackground(), SetDesktopName(), TokenNode::subnodeHead, TOK_BACKGROUND, TOK_DESKTOP, and TokenNode::type.

Referenced by ParseDesktops().

void ParseDesktopBackground ( int  desktop,
const TokenNode tp 
)
static

Parse a background for a desktop.

Definition at line 1040 of file parse.c.

References TokenNode::attributes, FindAttribute(), SetBackground(), and TokenNode::value.

Referenced by ParseDesktop(), and ParseDesktops().

void ParseDesktops ( const TokenNode tp)
static
void ParseDock ( const TokenNode tp,
TrayType tray 
)
static

Parse a dock tray component.

Definition at line 1459 of file parse.c.

References AddTrayComponent(), Assert, TokenNode::attributes, CreateDock(), FindAttribute(), JLIKELY, ParseUnsigned(), TrayComponentType::width, and WIDTH_ATTRIBUTE.

Referenced by ParseTray().

Menu* ParseDynamicMenu ( const char *  command)
read

Parse a dynamic menu (called from menu code).

Parse a dynamic menu.

Definition at line 792 of file parse.c.

References JLIKELY, ParseMenu(), ParseMenuIncludeHelper(), and ReleaseTokens().

Referenced by PatchMenu(), and ShowRootMenu().

void ParseError ( const TokenNode tp,
const char *  str,
  ... 
)
static
char ParseFile ( const char *  fileName,
int  depth 
)
static

Parse a specific file.

Returns
1 on success and 0 on failure.

Definition at line 239 of file parse.c.

References _, JUNLIKELY, MAX_INCLUDE_DEPTH, Parse(), ParseError(), ReleaseTokens(), and TokenizeFile().

Referenced by ParseConfig(), and ParseInclude().

void ParseFocusModel ( const TokenNode tp)
static

Parse focus model.

Definition at line 389 of file parse.c.

References ARRAY_LENGTH, FOCUS_CLICK, FOCUS_SLOPPY, Settings::focusModel, ParseTokenValue(), and settings.

Referenced by Parse().

void ParseGradient ( const char *  value,
ColorType  a,
ColorType  b 
)
static

Parse a color which may be a gradient.

Definition at line 1753 of file parse.c.

References AllocateStack, ReleaseStack, and SetColor().

Referenced by ParseActive(), ParseActiveWindowStyle(), ParseClockStyle(), ParseMenuStyle(), ParseTrayButtonStyle(), ParseTrayStyle(), and ParseWindowStyle().

void ParseGroup ( const TokenNode tp)
static
void ParseGroupOption ( const TokenNode tp,
struct GroupType group,
const char *  option 
)
static
void ParseInclude ( const TokenNode tp,
int  depth 
)
static

Parse an include.

Definition at line 951 of file parse.c.

References _, JLIKELY, JUNLIKELY, Parse(), ParseError(), ParseFile(), ReleaseTokens(), TokenizePipe(), and TokenNode::value.

Referenced by Parse().

void ParseKey ( const TokenNode tp)
static
WinLayerType ParseLayer ( const TokenNode tp,
const char *  str 
)
static

Parse layer.

Definition at line 1979 of file parse.c.

References _, ARRAY_LENGTH, FindValue(), JLIKELY, LAYER_ABOVE, LAYER_BELOW, LAYER_NORMAL, and ParseError().

Referenced by ParseGroupOption(), and ParseTray().

Menu * ParseMenu ( const TokenNode start)
static
MenuItem * ParseMenuInclude ( const TokenNode tp,
Menu menu,
MenuItem last 
)
static

Parse a menu include.

Definition at line 780 of file parse.c.

References JLIKELY, ParseMenuIncludeHelper(), ParseMenuItem(), ReleaseTokens(), TokenNode::subnodeHead, and TokenNode::value.

Referenced by ParseMenuItem().

TokenNode * ParseMenuIncludeHelper ( const TokenNode tp,
const char *  command 
)
static

Get tokens from a menu include (either dynamic or static).

Definition at line 759 of file parse.c.

References _, JUNLIKELY, ParseError(), ReleaseTokens(), TOK_JWM, TokenizeFile(), TokenizePipe(), and TokenNode::type.

Referenced by ParseDynamicMenu(), and ParseMenuInclude().

MenuItem * ParseMenuItem ( const TokenNode start,
Menu menu,
MenuItem last 
)
static
void ParseMenuStyle ( const TokenNode tp)
static
void ParseMoveMode ( const TokenNode tp)
static
unsigned int ParseOpacity ( const TokenNode tp,
const char *  str 
)
static

Parse opacity (a float between 0.0 and 1.0).

Definition at line 1960 of file parse.c.

References _, JUNLIKELY, ParseError(), and ParseFloat().

Referenced by ParseActiveWindowStyle(), ParseGroupOption(), ParseMenuStyle(), ParseTrayStyle(), and ParseWindowStyle().

void ParsePager ( const TokenNode tp,
TrayType tray 
)
static

Parse a pager tray component.

Definition at line 1229 of file parse.c.

References AddTrayComponent(), Assert, TokenNode::attributes, CreatePager(), FindAttribute(), LABELED_ATTRIBUTE, and TRUE_VALUE.

Referenced by ParseTray().

void ParsePagerStyle ( const TokenNode tp)
static
void ParsePopupStyle ( const TokenNode tp)
static
void ParseResizeMode ( const TokenNode tp)
static
void ParseRootMenu ( const TokenNode start)
static

Parse a root menu.

Definition at line 485 of file parse.c.

References TokenNode::attributes, CopyString(), Menu::dynamic, DYNAMIC_ATTRIBUTE, FindAttribute(), ONROOT_ATTRIBUTE, ParseMenu(), and SetRootMenu().

Referenced by Parse().

void ParseSnapMode ( const TokenNode tp)
static

Parse snap mode for moving windows.

Definition at line 399 of file parse.c.

References ARRAY_LENGTH, TokenNode::attributes, FindAttribute(), ParseTokenValue(), ParseUnsigned(), settings, SNAP_BORDER, SNAP_NONE, SNAP_SCREEN, Settings::snapDistance, and Settings::snapMode.

Referenced by Parse().

void ParseSpacer ( const TokenNode tp,
TrayType tray 
)
static
StatusWindowType ParseStatusWindowType ( const TokenNode tp)
static

Parse status window type.

Definition at line 1996 of file parse.c.

References ARRAY_LENGTH, ParseAttribute(), SW_CORNER, SW_OFF, SW_SCREEN, and SW_WINDOW.

Referenced by ParseMoveMode(), and ParseResizeMode().

void ParseSwallow ( const TokenNode tp,
TrayType tray 
)
static
void ParseTaskList ( const TokenNode tp,
TrayType tray 
)
static

Parse a task list tray component.

Definition at line 1250 of file parse.c.

References AddTrayComponent(), Assert, TokenNode::attributes, CreateTaskBar(), FALSE_VALUE, FindAttribute(), SetMaxTaskBarItemWidth(), SetTaskBarHeight(), and SetTaskBarLabeled().

Referenced by ParseTray().

AlignmentType ParseTextAlignment ( const TokenNode tp)
static

Parse text alignment.

Definition at line 855 of file parse.c.

References _, ALIGN_CENTER, ALIGN_LEFT, ALIGN_RIGHT, ARRAY_LENGTH, TokenNode::attributes, FindAttribute(), FindValue(), JLIKELY, Warning(), and TrayComponentType::x.

Referenced by ParseWindowStyle().

int ParseTokenValue ( const StringMappingType mapping,
int  count,
const TokenNode tp,
int  def 
)
static

Parse a token value using a string mapping.

Definition at line 1805 of file parse.c.

References _, FindValue(), GetTokenName(), JLIKELY, JUNLIKELY, ParseError(), and TokenNode::value.

Referenced by ParseFocusModel(), ParseMoveMode(), ParseResizeMode(), and ParseSnapMode().

void ParseTray ( const TokenNode tp)
static
void ParseTrayButton ( const TokenNode tp,
TrayType tray 
)
static
void ParseTrayButtonStyle ( const TokenNode tp)
void ParseTrayComponentActions ( const TokenNode tp,
TrayComponentType cp,
AddTrayActionFunc  func 
)
static

Parse tray component actions.

Definition at line 1423 of file parse.c.

References TokenNode::attributes, FindAttribute(), InvalidTag(), TokenNode::next, TokenNode::subnodeHead, TOK_BUTTON, TokenNode::type, and TokenNode::value.

Referenced by ParseClock(), and ParseTrayButton().

void ParseTrayStyle ( const TokenNode tp,
FontType  font,
ColorType  fg 
)
static
unsigned int ParseUnsigned ( const TokenNode tp,
const char *  str 
)
static
void ParseWindowStyle ( const TokenNode tp)
static
char * ReadFile ( FILE *  fd)
static

Read a file.

Definition at line 1841 of file parse.c.

References _, Allocate, BLOCK_SIZE, FatalError(), JUNLIKELY, Reallocate, and Warning().

Referenced by TokenizePipe().

TokenNode * TokenizeFile ( const char *  fileName)
static

Tokenize a file by memory mapping it.

Definition at line 1883 of file parse.c.

References CopyString(), ExpandPath(), JUNLIKELY, Release, and Tokenize().

Referenced by ParseFile(), and ParseMenuIncludeHelper().

TokenNode * TokenizePipe ( const char *  command)
static

Tokenize the output of a command.

Definition at line 1915 of file parse.c.

References CopyString(), ExpandPath(), JLIKELY, JUNLIKELY, ReadFile(), Release, and Tokenize().

Referenced by ParseInclude(), and ParseMenuIncludeHelper().

Variable Documentation

const char* CONFIRM_ATTRIBUTE = "confirm"
static

Definition at line 131 of file parse.c.

Referenced by ParseMenuItem().

const char* DEFAULT_TITLE = "JWM"
static

Definition at line 127 of file parse.c.

Referenced by ParseMenu(), and ParseMenuItem().

const char* DYNAMIC_ATTRIBUTE = "dynamic"
static

Definition at line 138 of file parse.c.

Referenced by ParseRootMenu().

const char* FALSE_VALUE = "false"
static

Definition at line 140 of file parse.c.

Referenced by ParseMenuItem(), and ParseTaskList().

const char* HEIGHT_ATTRIBUTE = "height"
static
const char* ICON_ATTRIBUTE = "icon"
static

Definition at line 129 of file parse.c.

Referenced by ParseMenuItem(), and ParseTrayButton().

const StringMappingType KEY_MAP[]
static

Mapping of key names to key types.

Note that this mapping must be sorted.

Definition at line 45 of file parse.c.

const unsigned int KEY_MAP_COUNT = ARRAY_LENGTH(KEY_MAP)
static

Definition at line 86 of file parse.c.

Referenced by ParseKey().

const char* LABEL_ATTRIBUTE = "label"
static

Definition at line 128 of file parse.c.

Referenced by ParseMenu(), ParseMenuItem(), and ParseTrayButton().

const char* LABELED_ATTRIBUTE = "labeled"
static

Definition at line 132 of file parse.c.

Referenced by ParseMenu(), ParseMenuItem(), and ParsePager().

const char* ONROOT_ATTRIBUTE = "onroot"
static

Definition at line 133 of file parse.c.

Referenced by ParseRootMenu().

const StringMappingType OPTION_MAP[]
static

Mapping of names to group options.

Note that this mapping must be sorted.

Definition at line 91 of file parse.c.

const unsigned int OPTION_MAP_COUNT = ARRAY_LENGTH(OPTION_MAP)
static

Definition at line 125 of file parse.c.

Referenced by ParseGroupOption().

const char* TOOLTIP_ATTRIBUTE = "tooltip"
static

Definition at line 130 of file parse.c.

Referenced by ParseMenuItem().

const char* TRUE_VALUE = "true"
static

Definition at line 141 of file parse.c.

Referenced by ParseMenu(), ParseMenuItem(), ParsePager(), and ParseTrayStyle().

const char* WIDTH_ATTRIBUTE = "width"
static
const char* X_ATTRIBUTE = "x"
static

Definition at line 134 of file parse.c.

Referenced by ParseTray().

const char* Y_ATTRIBUTE = "y"
static

Definition at line 135 of file parse.c.

Referenced by ParseTray().

joewing.net / Projects / JWM