|
|
1.1 ! root 1: /*++ ! 2: ! 3: Copyright (c) 1991 Microsoft Corporation ! 4: ! 5: Module Name: ! 6: ! 7: mcutil.c ! 8: ! 9: Abstract: ! 10: ! 11: This file contains utility functions for the Win32 Message Compiler (MC) ! 12: ! 13: --*/ ! 14: ! 15: #include "mc.h" ! 16: ! 17: ! 18: /*++ ! 19: ! 20: Routine Description: ! 21: ! 22: This routine simply writes/overwrites Name, ID and Value ! 23: to a link list of NAME_INFO structures. ! 24: ! 25: Arguments: ! 26: ! 27: PNAME_INFO ! 28: Keyword such as "Facility", "Serverity", ... ! 29: Lauguage Identifier; a combination of a Primary Language ID, ! 30: Sublanguage ID pair such as LANG_NEUTRAL, SUBLANG_NEUTRAL ! 31: An option value specfic to the keyword. ! 32: ! 33: Return Value: ! 34: ! 35: The list PNAME_INFO ! 36: ! 37: --*/ ! 38: ! 39: PNAME_INFO ! 40: McAddName( ! 41: PNAME_INFO *NameListHead, ! 42: char *Name, ! 43: ULONG Id, ! 44: PVOID Value ! 45: ) ! 46: { ! 47: PNAME_INFO p; ! 48: int n; ! 49: ! 50: while (p = *NameListHead) { ! 51: if (!(n = stricmp( p->Name, Name ))) { ! 52: if (p->Id != Id) { ! 53: McInputError( "Redefining value of %s", FALSE, Name ); ! 54: } ! 55: ! 56: p->Id = Id; ! 57: p->Value = Value; ! 58: p->Used = FALSE; ! 59: return( p ); ! 60: } ! 61: else ! 62: if (n < 0) { ! 63: break; ! 64: } ! 65: ! 66: NameListHead = &p->Next; ! 67: } ! 68: ! 69: p = malloc( sizeof( *p ) + strlen( Name ) ); ! 70: p->LastId = 0; ! 71: p->Id = Id; ! 72: p->Value = Value; ! 73: p->Used = FALSE; ! 74: strcpy( p->Name, Name ); ! 75: p->Next = *NameListHead; ! 76: *NameListHead = p; ! 77: return( p ); ! 78: } ! 79: ! 80: ! 81: ! 82: /*++ ! 83: ! 84: Routine Description: ! 85: ! 86: This routine returns the NAME_INFO structure cooresponding to the ! 87: given Keyword. ! 88: ! 89: Arguments: ! 90: ! 91: PNAME_INFO ! 92: Keyword such as "Facility", "Serverity", ... ! 93: ! 94: Return Value: ! 95: ! 96: Either the NAME_INFO structure cooresponding to the keyname or NULL ! 97: ! 98: --*/ ! 99: ! 100: ! 101: PNAME_INFO ! 102: McFindName( ! 103: PNAME_INFO NameListHead, ! 104: char *Name ! 105: ) ! 106: { ! 107: PNAME_INFO p; ! 108: ! 109: p = NameListHead; ! 110: while (p) { ! 111: if (!stricmp( p->Name, Name )) { ! 112: p->Used = TRUE; ! 113: break; ! 114: } ! 115: ! 116: p = p->Next; ! 117: } ! 118: ! 119: return( p ); ! 120: } ! 121: ! 122: ! 123: ! 124: /*++ ! 125: ! 126: Routine Description: ! 127: ! 128: This converts a string value to the corresponding integer value ! 129: in the specified base. ! 130: ! 131: Arguments: ! 132: ! 133: String image of an integer ! 134: Base of resultant integer ! 135: Pointer to a unsigned long ! 136: ! 137: ! 138: Return Value: ! 139: ! 140: A unsigned long ! 141: ! 142: --*/ ! 143: ! 144: BOOLEAN ! 145: McCharToInteger( ! 146: PCHAR String, ! 147: int Base, ! 148: PULONG Value ! 149: ) ! 150: { ! 151: CHAR c; ! 152: ULONG Result, Digit, Shift; ! 153: ! 154: c = *String++; ! 155: if (!Base) { ! 156: Base = 10; ! 157: Shift = 0; ! 158: if (c == '0') { ! 159: c = *String++; ! 160: if (c == 'x') { ! 161: Base = 16; ! 162: Shift = 4; ! 163: } ! 164: else ! 165: if (c == 'o') { ! 166: Base = 8; ! 167: Shift = 3; ! 168: } ! 169: else ! 170: if (c == 'b') { ! 171: Base = 2; ! 172: Shift = 1; ! 173: } ! 174: else { ! 175: String--; ! 176: } ! 177: ! 178: c = *String++; ! 179: } ! 180: } ! 181: else { ! 182: switch( Base ) { ! 183: case 16: Shift = 4; break; ! 184: case 8: Shift = 3; break; ! 185: case 2: Shift = 1; break; ! 186: case 10: Shift = 0; break; ! 187: default: return( FALSE ); ! 188: } ! 189: } ! 190: ! 191: Result = 0; ! 192: while (c) { ! 193: if (c >= '0' && c <= '9') { ! 194: Digit = c - '0'; ! 195: } ! 196: else ! 197: if (c >= 'A' && c <= 'F') { ! 198: Digit = c - 'A' + 10; ! 199: } ! 200: else ! 201: if (c >= 'a' && c <= 'f') { ! 202: Digit = c - 'a' + 10; ! 203: } ! 204: else { ! 205: break; ! 206: } ! 207: ! 208: if ((int)Digit >= Base) { ! 209: break; ! 210: } ! 211: ! 212: if (Shift == 0) { ! 213: Result = (Base * Result) + Digit; ! 214: } ! 215: else { ! 216: Result = (Result << Shift) | Digit; ! 217: } ! 218: ! 219: c = *String++; ! 220: } ! 221: ! 222: *Value = Result; ! 223: return( TRUE ); ! 224: } ! 225: ! 226: /*++ ! 227: ! 228: Routine Description: ! 229: ! 230: Duplicates a string ! 231: ! 232: Arguments: ! 233: ! 234: A string value ! 235: ! 236: Return Value: ! 237: ! 238: The duplicated string value ! 239: ! 240: --*/ ! 241: ! 242: ! 243: char * ! 244: McMakeString( ! 245: char *String ! 246: ) ! 247: { ! 248: char *s; ! 249: ! 250: s = malloc( strlen( String ) + 1 ); ! 251: strcpy( s, String ); ! 252: return( s ); ! 253: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.