From d04f9676e0d9e415c9ebed34dc90bcb200b81d97 Mon Sep 17 00:00:00 2001 From: Theo de Raadt Date: Mon, 1 Dec 2008 23:31:42 +0000 Subject: there is zero reason for this parse.y to look different from the others; ok uwe --- usr.sbin/btctl/parse.y | 228 +++++++++++++++++++++++-------------------------- 1 file changed, 109 insertions(+), 119 deletions(-) (limited to 'usr.sbin/btctl') diff --git a/usr.sbin/btctl/parse.y b/usr.sbin/btctl/parse.y index 644ab248720..a9523d75e7e 100644 --- a/usr.sbin/btctl/parse.y +++ b/usr.sbin/btctl/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.3 2008/11/26 06:51:04 uwe Exp $ */ +/* $OpenBSD: parse.y,v 1.4 2008/12/01 23:31:41 deraadt Exp $ */ /* * Copyright (c) 2008 Uwe Stuehler @@ -23,17 +23,20 @@ */ %{ -#include +#include +#include +#include #include #include -#include -#include -#include #include -#include #include +#include +#include +#include +#include +#include #include "btctl.h" #include "btd.h" @@ -99,127 +102,114 @@ void must_write(const void *, size_t); %type pin_opt %% -grammar -: /* empty */ -| grammar '\n' -| grammar main '\n' -| grammar error '\n' -{ - file->errors++; -} -; +ruleset : /* empty */ + | ruleset '\n' + | ruleset main '\n' + | ruleset error '\n' { file->errors++; } + ; -main -: INTERFACE address name_opt disabled_opt -{ - btctl_interface_stmt stmt; +main : INTERFACE address name_opt disabled_opt { + btctl_interface_stmt stmt; - bdaddr_copy(&stmt.addr, &$2); + bdaddr_copy(&stmt.addr, &$2); - strbufcpy("interface name", $3, stmt.name); - free($3); + strbufcpy("interface name", $3, stmt.name); + free($3); - stmt.flags = $4 ? BTCTL_INTERFACE_DISABLED : 0; + stmt.flags = $4 ? BTCTL_INTERFACE_DISABLED : 0; - switch (exec_stmt(BTCTL_INTERFACE_STMT, &stmt, sizeof(stmt))) { - case 0: break; - case EEXIST: - yyerror("interface %s is already defined", - bdaddr_any(&stmt.addr) ? "*" : - bt_ntoa(&stmt.addr, NULL)); - YYERROR; - default: - yyerror("could not add interface"); - YYERROR; - } -} -| ATTACH address type_opt pin_opt -{ - btctl_attach_stmt stmt; - - bdaddr_copy(&stmt.addr, &$2); - - stmt.type = $3; - - if ($4 != NULL) { - strbufcpy("PIN code", $4, stmt.pin); - stmt.pin_size = strlen(stmt.pin); - free($4); - } else - stmt.pin_size = 0; - - switch (exec_stmt(BTCTL_ATTACH_STMT, &stmt, sizeof(stmt))) { - case 0: break; - case EEXIST: - yyerror("device %s is already defined", - bdaddr_any(&stmt.addr) ? "*" : - bt_ntoa(&stmt.addr, NULL)); - YYERROR; - default: - yyerror("could not add device"); - YYERROR; - } -} -; - -name_opt -: /* empty */ -{ $$ = NULL; } -| NAME STRING -{ $$ = $2; } -; - -disabled_opt -: /* empty */ -{ $$ = 0; } -| DISABLED -{ $$ = 1; } -; - -type_opt -: /* empty */ -{ $$ = BTDEV_NONE; } -| TYPE NONE -{ $$ = BTDEV_NONE; } -| TYPE HID -{ $$ = BTDEV_HID; } -| TYPE HSET -{ $$ = BTDEV_HSET; } -| TYPE HF -{ $$ = BTDEV_HF; } -; - -pin_opt -: /* empty */ -{ $$ = NULL; } -| PIN STRING -{ - if (($$ = calloc(HCI_PIN_SIZE, sizeof(uint8_t))) == NULL) - fatal("pin_opt calloc"); + switch (exec_stmt(BTCTL_INTERFACE_STMT, &stmt, sizeof(stmt))) { + case 0: + break; + case EEXIST: + yyerror("interface %s is already defined", + bdaddr_any(&stmt.addr) ? "*" : + bt_ntoa(&stmt.addr, NULL)); + YYERROR; + default: + yyerror("could not add interface"); + YYERROR; + } + } + | ATTACH address type_opt pin_opt { + btctl_attach_stmt stmt; - strlcpy($$, $2, HCI_PIN_SIZE); - free($2); -} -; + bdaddr_copy(&stmt.addr, &$2); -address -: STRING -{ - if (strcmp($1, "*")) { - bt_aton($1, &$$); - - if (bdaddr_any(&$$)) { - /* 0:0:0:0:0:0 could be misinterpreted */ - yyerror("invalid address '%s'", $1); - free($1); - YYERROR; - } + stmt.type = $3; - free($1); - } else - bdaddr_copy(&$$, BDADDR_ANY); -} -; + if ($4 != NULL) { + strbufcpy("PIN code", $4, stmt.pin); + stmt.pin_size = strlen(stmt.pin); + free($4); + } else + stmt.pin_size = 0; + + switch (exec_stmt(BTCTL_ATTACH_STMT, &stmt, sizeof(stmt))) { + case 0: + break; + case EEXIST: + yyerror("device %s is already defined", + bdaddr_any(&stmt.addr) ? "*" : + bt_ntoa(&stmt.addr, NULL)); + YYERROR; + default: + yyerror("could not add device"); + YYERROR; + } + } + ; + +name_opt : /* empty */ + { $$ = NULL; } + | NAME STRING + { $$ = $2; } + ; + +disabled_opt : /* empty */ + { $$ = 0; } + | DISABLED + { $$ = 1; } + ; + +type_opt : /* empty */ + { $$ = BTDEV_NONE; } + | TYPE NONE + { $$ = BTDEV_NONE; } + | TYPE HID + { $$ = BTDEV_HID; } + | TYPE HSET + { $$ = BTDEV_HSET; } + | TYPE HF + { $$ = BTDEV_HF; } + ; + +pin_opt : /* empty */ + { $$ = NULL; } + | PIN STRING { + if (($$ = calloc(HCI_PIN_SIZE, sizeof(uint8_t))) == NULL) + fatal("pin_opt calloc"); + + strlcpy($$, $2, HCI_PIN_SIZE); + free($2); + } + ; + +address : STRING { + if (strcmp($1, "*")) { + bt_aton($1, &$$); + + if (bdaddr_any(&$$)) { + /* 0:0:0:0:0:0 could be misinterpreted */ + yyerror("invalid address '%s'", $1); + free($1); + YYERROR; + } + free($1); + } else + bdaddr_copy(&$$, BDADDR_ANY); + } + ; %% -- cgit v1.2.3