HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UT_SysSpecific.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * Authored by:
7  * Chris Thompson
8  * Side Effects Software Inc.
9  *
10  * NAME: UT_SysSpecific.h (Utility Library, C++)
11  *
12  * COMMENTS: Functions related to operating-system specific
13  * preferences, defaults, helper applications, etc.
14  * The difference between this file and UT_SysClone
15  * is that that one simply replaces SGI system calls with
16  * custom calls of the same name, while SysSpecific is a true
17  * wrapper that hides even the system call name under a "UT"-
18  * prefixed name.
19  *
20  */
21 
22 #ifndef __UT_SysSpecific_h__
23 #define __UT_SysSpecific_h__
24 
25 #include "UT_API.h"
26 #include "UT_Defines.h"
27 #include <SYS/SYS_Platform.h>
28 #include <stdlib.h>
29 #include <stdarg.h>
30 #include <stdio.h>
31 #include <string>
32 
33 class UT_String;
34 
35 // Returns the name of the user's text editor.
36 // (This is determined by the EDITOR environment variable;
37 // a system-appropriate default editor is chosen if EDITOR
38 // is not set.)
39 // Do not free() or delete[] the returned pointer.
40 UT_API extern const char *UTgetTextEditor(bool &is_graphical);
41 
42 UT_API extern void UTinvokeTextEditor(const char *fileToEdit, UT_Bool blocking, const char *title);
43 
44 UT_API extern UT_Bool UTopenShell(UT_Bool blocking, const char *title);
45 
46 UT_API extern UT_Bool UTrunTextProgram(const char *commandLine, UT_Bool blocking, const char *title);
47 
48 UT_API extern UT_Bool UTrunGraphicalProgram(const char *commandLine, UT_Bool blocking, const char *title);
49 
50 // 'in_shell' causes commandLine to be executed in csh on NT, instead of the
51 // brain-dead command prompt (which doesn't support I/O redirection & such).
52 // It has no effect on other UNIX based OSes.
53 UT_API extern int UTsystem(const char *commandLine, bool in_shell = false);
54 
55 // Starts an external web browser and opens a URL.
56 UT_API extern void UTopenURLInWebBrowser( const char * url );
57 
58 UT_API extern void UTgetProcessor(int &majortype, int &flags);
59 
60 // Gets OS_PROC
61 static inline const char *UTgetOsProc() { return SYSgetOsProc(); }
62 
63 // Sets name to a hardened version of the users name, ie: "jlait".
64 // If alphaonly is set, it will munge the user name to be something
65 // with no spaces by adding _, etc.
66 // Defaults to login name, but can be overridden.
67 UT_API extern void UTgetUserName(UT_String &name, int alphaonly = 1);
68 
69 // you@machine
70 // The machine defaults to your host name, but can be overridden
71 UT_API extern void UTgetMachineName(UT_String &name, int alphaonly = 1);
72 
73 // machine
74 // The machine defaults to your host name, but can be overridden
75 UT_API extern void UTgetUserMachineName(UT_String &name, int alphaonly = 1);
76 
77 UT_API extern void UTdisplayMessageWindow(const char *message_text,
78  const char *message_title = "Houdini Error");
79 UT_API extern void UTdisplayMessageWindowWithHelpURL(const char *message_text,
80  const char *help_url,
81  const char *message_title = "Houdini Error");
82 UT_API extern bool UTdisplayConfirmationWindow(const char *message_text,
83  const char *message_title = "Houdini");
84 
85 static inline int
86 UTvsnprintf(char *str, size_t size, const char *format, va_list ap)
87 {
88  // Windows prefixes vsnprintf with an underscore for some reason.
89 #ifdef WIN32
90  return _vsnprintf(str, size, format, ap);
91 #else
92  int result;
93  va_list ap_copy;
94 
95  // We need to make a copy of the argument pointer in case we
96  // have to call UTvsnprintf multiple times. It is generally not safe to
97  // re-use the same va_list in multiple calls. Reusing the same va_list
98  // caused a crash on a 64 bit Linux machine compiled with gcc 3.4.
99  // va_copy only became standard with C99 and is currently not supported
100  // on Windows.
101  va_copy(ap_copy, ap);
102  result = vsnprintf(str, size, format, ap_copy);
103  va_end(ap_copy);
104  return result;
105 #endif
106 }
107 
108 UT_API extern std::string
110 
111 #if defined(IRIX6)
112 // The Irix compiler gets confused when it has to do two conversions at the
113 // same time, from non-const->const and from type A->B. This is a perfectly
114 // legal operation, but it barfs on it. So, on Irix, we use old C-style
115 // casts instead.
116 // i.e.,
117 // void *p;
118 // const Foo *x = static_cast<const Foo *>(p);
119 // fails but both of these suceed:
120 // const Foo *x = static_cast<const Foo *>(static_cast<const void *>(p));
121 // const Foo *x = static_cast<const Foo *>(static_cast<Foo *>(p));
122 #define UTstatic_cast(Type, Data) ((Type)(Data))
123 #else
124 #define UTstatic_cast(Type, Data) static_cast<Type>(Data)
125 #endif
126 
127 #endif // __UT_SysSpecific_h__
int UT_Bool
Definition: UT_Defines.h:46
UT_API const char * UTgetTextEditor(bool &is_graphical)
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
UT_API void UTgetMachineName(UT_String &name, int alphaonly=1)
UT_API void UTgetProcessor(int &majortype, int &flags)
GLbitfield flags
Definition: glcorearb.h:1595
#define UT_API
Definition: UT_API.h:12
UT_API void UTgetUserMachineName(UT_String &name, int alphaonly=1)
GLsizeiptr size
Definition: glcorearb.h:663
UT_API UT_Bool UTrunGraphicalProgram(const char *commandLine, UT_Bool blocking, const char *title)
UT_API void UTinvokeTextEditor(const char *fileToEdit, UT_Bool blocking, const char *title)
UT_API std::string UTunmangleClassNameFromTypeIdName(const std::string &name)
UT_API bool UTdisplayConfirmationWindow(const char *message_text, const char *message_title="Houdini")
UT_API UT_Bool UTopenShell(UT_Bool blocking, const char *title)
UT_API void UTdisplayMessageWindowWithHelpURL(const char *message_text, const char *help_url, const char *message_title="Houdini Error")
UT_API void UTopenURLInWebBrowser(const char *url)
SYS_API const char * SYSgetOsProc()
Find the name of the operating system that Houdini was compiled for.
GLuint const GLchar * name
Definition: glcorearb.h:785
UT_API UT_Bool UTrunTextProgram(const char *commandLine, UT_Bool blocking, const char *title)
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:107
UT_API void UTdisplayMessageWindow(const char *message_text, const char *message_title="Houdini Error")
UT_API int UTsystem(const char *commandLine, bool in_shell=false)
UT_API void UTgetUserName(UT_String &name, int alphaonly=1)