hotspot/agent/src/os/win32/ioUtils.cpp
author trims
Thu, 27 May 2010 19:08:38 -0700
changeset 5547 f4b087cbb361
parent 1 489c9b5090e2
permissions -rw-r--r--
6941466: Oracle rebranding changes for Hotspot repositories Summary: Change all the Sun copyrights to Oracle copyright Reviewed-by: ohair
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
     2
 * Copyright (c) 2000, 2001, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
#include <ctype.h>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
#include <string.h>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
#include "ioUtils.hpp"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
#include "IOBuf.hpp"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
bool
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
scanInt(char** data, int* num) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  *num = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  // Skip whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  while ((**data != 0) && (isspace(**data))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
    ++*data;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  if (**data == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  while ((**data != 0) && (!isspace(**data))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
    char cur = **data;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
    if ((cur < '0') || (cur > '9')) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    *num *= 10;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    *num += cur - '0';
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
    ++*data;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
bool
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
scanUnsignedLong(char** data, unsigned long* num) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  *num = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  // Skip whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  while ((**data != 0) && (isspace(**data))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    ++*data;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  if (**data == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  while ((**data != 0) && (!isspace(**data))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    char cur = **data;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    if ((cur < '0') || (cur > '9')) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    *num *= 10;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    *num += cur - '0';
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    ++*data;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
bool
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
charToNibble(char ascii, int* value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  if (ascii >= '0' && ascii <= '9') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    *value = ascii - '0';
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  } else if (ascii >= 'A' && ascii <= 'F') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    *value = 10 + ascii - 'A';
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  } else if (ascii >= 'a' && ascii <= 'f') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    *value = 10 + ascii - 'a';
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
bool
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
scanAddress(char** data, unsigned long* addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  *addr = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  // Skip whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  while ((**data != 0) && (isspace(**data))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    ++*data;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  if (**data == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  if (strncmp(*data, "0x", 2) != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  *data += 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  while ((**data != 0) && (!isspace(**data))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    int val;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    bool res = charToNibble(**data, &val);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    if (!res) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    *addr <<= 4;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    *addr |= val;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    ++*data;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
bool
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
scanAndSkipBinEscapeChar(char** data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  // Skip whitespace
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  while ((**data != 0) && (isspace(**data))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    ++*data;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  if (!IOBuf::isBinEscapeChar(**data)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  ++*data;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
bool
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
scanBinUnsignedLong(char** data, unsigned long* num) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  *num = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  for (int i = 0; i < 4; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    unsigned char val = (unsigned char) **data;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
    *num = (*num << 8) | val;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
    ++*data;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
}