17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 2368ae3684Seota * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*921a817eSRichard PALO * 26*921a817eSRichard PALO * Copyright 2015 PALO, Richard. All rights reserved. 277c478bd9Sstevel@tonic-gate */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #ifndef _SYS_KOBJ_LEX_H 307c478bd9Sstevel@tonic-gate #define _SYS_KOBJ_LEX_H 317c478bd9Sstevel@tonic-gate 32*921a817eSRichard PALO #include <sys/ctype.h> 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate #ifdef __cplusplus 357c478bd9Sstevel@tonic-gate extern "C" { 367c478bd9Sstevel@tonic-gate #endif 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate /* 397c478bd9Sstevel@tonic-gate * This file contains declarations for lex and its associated functions that 407c478bd9Sstevel@tonic-gate * are used by the kernel to parse the contents of system files. 417c478bd9Sstevel@tonic-gate * 427c478bd9Sstevel@tonic-gate * These lex functions are for a few selected kernel modules that are required 437c478bd9Sstevel@tonic-gate * to parse contents of file(s) on disk. This file is not for general kernel 447c478bd9Sstevel@tonic-gate * usage. 457c478bd9Sstevel@tonic-gate */ 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate #define isunary(ch) ((ch) == '~' || (ch) == '-') 487c478bd9Sstevel@tonic-gate 497c478bd9Sstevel@tonic-gate #define iswhite(ch) ((ch) == ' ' || (ch) == '\t') 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate #define isnewline(ch) ((ch) == '\n' || (ch) == '\r' || (ch) == '\f') 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate #define isalphanum(ch) (isalpha(ch) || isdigit(ch)) 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate #define isnamechar(ch) (isalphanum(ch) || (ch) == '_' || (ch) == '-') 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gate typedef enum { 5868ae3684Seota UNEXPECTED = -1, 597c478bd9Sstevel@tonic-gate EQUALS, 607c478bd9Sstevel@tonic-gate AMPERSAND, 617c478bd9Sstevel@tonic-gate BIT_OR, 627c478bd9Sstevel@tonic-gate STAR, 637c478bd9Sstevel@tonic-gate POUND, 647c478bd9Sstevel@tonic-gate COLON, 657c478bd9Sstevel@tonic-gate SEMICOLON, 667c478bd9Sstevel@tonic-gate COMMA, 677c478bd9Sstevel@tonic-gate SLASH, 687c478bd9Sstevel@tonic-gate WHITE_SPACE, 697c478bd9Sstevel@tonic-gate NEWLINE, 707c478bd9Sstevel@tonic-gate EOF, 717c478bd9Sstevel@tonic-gate STRING, 727c478bd9Sstevel@tonic-gate HEXVAL, 737c478bd9Sstevel@tonic-gate DECVAL, 747c478bd9Sstevel@tonic-gate NAME 757c478bd9Sstevel@tonic-gate } token_t; 767c478bd9Sstevel@tonic-gate 777c478bd9Sstevel@tonic-gate #ifdef DEBUG 787c478bd9Sstevel@tonic-gate /* string values for token_t */ 797c478bd9Sstevel@tonic-gate extern char *tokennames[]; 807c478bd9Sstevel@tonic-gate #endif /* DEBUG */ 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate /* 837c478bd9Sstevel@tonic-gate * return 1 with sptr pointing to the string represented by token 847c478bd9Sstevel@tonic-gate * On error returns NULL. The memory pointed to by sptr should be 857c478bd9Sstevel@tonic-gate * freed using free_string function. 867c478bd9Sstevel@tonic-gate */ 877c478bd9Sstevel@tonic-gate int kobj_get_string(u_longlong_t *sptr, char *token); 887c478bd9Sstevel@tonic-gate void kobj_free_string(void *ptr, int len); 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate /* 917c478bd9Sstevel@tonic-gate * returns decimal/octal/hex number in valuep 927c478bd9Sstevel@tonic-gate * return 0 on success, -1 on failure 937c478bd9Sstevel@tonic-gate */ 947c478bd9Sstevel@tonic-gate int kobj_getvalue(const char *token, u_longlong_t *valuep); 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate /* prints a formated message via cmn_err */ 977c478bd9Sstevel@tonic-gate /*PRINTFLIKE3*/ 987c478bd9Sstevel@tonic-gate extern void kobj_file_err(int type, struct _buf *file, char *fmt, ...) 997c478bd9Sstevel@tonic-gate __KPRINTFLIKE(3); 1007c478bd9Sstevel@tonic-gate 1017c478bd9Sstevel@tonic-gate /* 1027c478bd9Sstevel@tonic-gate * returns the next token in the file on success, 1037c478bd9Sstevel@tonic-gate * return -1 on failure 1047c478bd9Sstevel@tonic-gate */ 1057c478bd9Sstevel@tonic-gate token_t kobj_lex(struct _buf *file, char *val, size_t size); 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate void kobj_find_eol(struct _buf *file); 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1107c478bd9Sstevel@tonic-gate } 1117c478bd9Sstevel@tonic-gate #endif 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate #endif /* !_SYS_KOBJ_LEX_H */ 114