2 * Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
11 #include "ppapi/native_client/src/trusted/plugin/utility.h"
15 int gNaClPluginDebugPrintEnabled = -1;
16 FILE* gNaClPluginLogFile = NULL;
19 * Prints formatted message to the log.
21 int NaClPluginPrintLog(const char *format, ...) {
22 if (NULL == gNaClPluginLogFile) {
27 va_start(arg, format);
28 done = vfprintf(gNaClPluginLogFile, format, arg);
30 fflush(gNaClPluginLogFile);
35 * Opens file where plugin log should be written. The file name is
36 * taken from NACL_PLUGIN_LOG environment variable.
37 * If environment variable doesn't exist or file can't be opened,
38 * the function returns stdout.
40 FILE* NaClPluginLogFileEnv() {
41 char* file = getenv("NACL_PLUGIN_LOG");
43 FILE* log_file = fopen(file, "w+");
44 if (NULL == log_file) {
53 * Currently looks for presence of NACL_PLUGIN_DEBUG and returns
54 * 0 if absent and 1 if present. In the future we may include notions
57 int NaClPluginDebugPrintCheckEnv() {
58 char* env = getenv("NACL_PLUGIN_DEBUG");
62 bool IsValidIdentifierString(const char* strval, uint32_t* length) {
63 // This function is supposed to recognize valid ECMAScript identifiers,
65 // http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf
66 // It is currently restricted to only the ASCII subset.
67 // TODO(sehr): Recognize the full Unicode formulation of identifiers.
68 // TODO(sehr): Make this table-driven if efficiency becomes a problem.
75 static const char* kValidFirstChars =
76 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz$_";
77 static const char* kValidOtherChars =
78 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz$_"
80 if (NULL == strchr(kValidFirstChars, strval[0])) {
84 for (pos = 1; ; ++pos) {
93 if (NULL == strchr(kValidOtherChars, c)) {
103 } // namespace plugin