Vikram Narayanan | a8111cf | 2012-04-14 15:25:13 +0530 | [diff] [blame^] | 1 | /*****************************************************************************\ |
| 2 | * layout_common.c |
| 3 | ***************************************************************************** |
| 4 | * Copyright (C) 2012, Vikram Narayanan |
| 5 | * Unified build_opt_tbl and nvramtool |
| 6 | * build_opt_tbl.c |
| 7 | * Copyright (C) 2003 Eric Biederman (ebiederm@xmission.com) |
| 8 | * Copyright (C) 2007-2010 coresystems GmbH |
| 9 | * |
| 10 | * This file is part of nvramtool, a utility for reading/writing coreboot |
| 11 | * parameters and displaying information from the coreboot table. |
| 12 | * For details, see http://coreboot.org/nvramtool. |
| 13 | * |
| 14 | * Please also read the file DISCLAIMER which is included in this software |
| 15 | * distribution. |
| 16 | * |
| 17 | * This program is free software; you can redistribute it and/or modify it |
| 18 | * under the terms of the GNU General Public License (as published by the |
| 19 | * Free Software Foundation) version 2, dated June 1991. |
| 20 | * |
| 21 | * This program is distributed in the hope that it will be useful, but |
| 22 | * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF |
| 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and |
| 24 | * conditions of the GNU General Public License for more details. |
| 25 | * |
| 26 | * You should have received a copy of the GNU General Public License along |
| 27 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 28 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 29 | \*****************************************************************************/ |
| 30 | |
| 31 | #include <ctype.h> |
| 32 | |
| 33 | static int is_ident_nondigit(int c) |
| 34 | { |
| 35 | int result; |
| 36 | switch(c) { |
| 37 | case 'A': case 'B': case 'C': case 'D': |
| 38 | case 'E': case 'F': case 'G': case 'H': |
| 39 | case 'I': case 'J': case 'K': case 'L': |
| 40 | case 'M': case 'N': case 'O': case 'P': |
| 41 | case 'Q': case 'R': case 'S': case 'T': |
| 42 | case 'U': case 'V': case 'W': case 'X': |
| 43 | case 'Y': case 'Z': |
| 44 | case 'a': case 'b': case 'c': case 'd': |
| 45 | case 'e': case 'f': case 'g': case 'h': |
| 46 | case 'i': case 'j': case 'k': case 'l': |
| 47 | case 'm': case 'n': case 'o': case 'p': |
| 48 | case 'q': case 'r': case 's': case 't': |
| 49 | case 'u': case 'v': case 'w': case 'x': |
| 50 | case 'y': case 'z': |
| 51 | case '_': |
| 52 | result = 1; |
| 53 | break; |
| 54 | default: |
| 55 | result = 0; |
| 56 | break; |
| 57 | } |
| 58 | return result; |
| 59 | } |
| 60 | |
| 61 | int is_ident(char *str) |
| 62 | { |
| 63 | int result; |
| 64 | int ch; |
| 65 | ch = *str; |
| 66 | result = 0; |
| 67 | if (is_ident_nondigit(ch)) { |
| 68 | do { |
| 69 | str++; |
| 70 | ch = *str; |
| 71 | } while(ch && (is_ident_nondigit(ch) || (isdigit(ch)))); |
| 72 | result = (ch == '\0'); |
| 73 | } |
| 74 | return result; |
| 75 | } |