OAuth::OAuth(const char *ClientId, const char *ClientSecret, const char *RedirectURI) { d = new OAuthPriv; d->ClientId.Reset(NewStr(ClientId)); d->ClientSecret.Reset(NewStr(ClientSecret)); d->RedirectURI.Reset(NewStr(RedirectURI)); }
GAutoString GetOptionsFile(const char *Ext) { // Get options file GAutoString Status; char Buf[MAX_PATH]; if (LgiApp->GetOption("o", Buf, sizeof(Buf))) { if (FileExists(Buf)) { Status.Reset(NewStr(Buf)); } } if (!Status) { LgiGetExeFile(Buf, sizeof(Buf)); char *File = strrchr(Buf, DIR_CHAR); if (File) { File++; #ifdef WIN32 char *End = strrchr(File, '.'); if (End) { End++; strcpy_s(End, Buf + sizeof(Buf) - End, Ext); } else #endif { // unix apps have no '.' in their name size_t Len = strlen(File); sprintf_s(File + Len, Buf + sizeof(Buf) - (File + Len), ".%s", Ext); } GAutoString BaseName(NewStr(File)); char p[MAX_PATH]; if (Mode == InstallPortable) { LgiGetSystemPath(LSP_APP_INSTALL, p, sizeof(p)); } else { if (LgiGetSystemPath(LSP_APP_ROOT, p, sizeof(p)) && !DirExists(p)) { FileDev->CreateFolder(p); } } LgiMakePath(p, sizeof(p), p, BaseName); Status.Reset(NewStr(p)); } } return Status; }
DWORD CbString::SetStr(char *str) { DWORD len = strlen(str); if (NewStr(len) != ERR_OK) return ERR_FATAL; strcpy(m_str,str); return ERR_OK; }
void GDocApp<OptionsFmt>::SetCurFile(char *f) { if (f != d->CurFile) { d->CurFile.Reset(NewStr(f)); } GAutoString Display; if (SerializeEntry(&Display, &d->CurFile, NULL)) { char s[MAX_PATH + 100]; if (Display) { sprintf_s(s, sizeof(s), "%s [%s%s]", d->AppName, Display.Get(), d->Dirty ? " changed" : ""); } else if (d->Dirty) { sprintf_s(s, sizeof(s), "%s [changed]", d->AppName); } else { strcpy_s(s, sizeof(s), d->AppName); } Name(s); } }
static char * FormatFileName(const char * szFormat, TCascStorage * hs) { char * szFileName; char * szSrc; char * szTrg; // Create copy of the file name szFileName = szSrc = szTrg = NewStr(szFormat, 0); if(szFileName != NULL) { // Format the file name while(szSrc[0] != 0) { if(szSrc[0] == '%') { // Replace "%build%" with a build number if(!strncmp(szSrc, "%build%", 7)) { szTrg += sprintf(szTrg, "%u", hs->dwBuildNumber); szSrc += 7; continue; } } // Just copy the character *szTrg++ = *szSrc++; } // Terminate the target file name szTrg[0] = 0; } return szFileName; }
bool GCombo::Insert(char *p, int Index) { bool Status = false; if (p) { if (Handle()) { char *n = LgiToNativeCp(p); if (n) { if (Index < 0) { Index = GetItems(); } Status = SendMessage(Handle(), CB_INSERTSTRING, Index, (long)n) == Index; DeleteArray(n); } } else { d->InitStrs.Insert(NewStr(p), Index); Status = true; } } return Status; }
GAutoString LgiErrorCodeToString(uint32 Code) { char e[32]; sprintf_s(e, sizeof(e), "Err(%i)", Code); GAutoString s(NewStr(e)); return s; }
/* i hate constants, but 64 bit ints convert to a number that is * length 20 char + sign, make it the nearest power of 2 above 20 */ static String WordToString(const Thing const T) { int i = (int)GetThingData(T); char buf[LARGESTINTLEN]; snprintf((char*)&buf, LARGESTINTLEN, "%d", i); return(NewStr(buf)); }
bool LgiGetsAppForMimeType(const char *Mime, GArray<GAppInfo*> &Apps, int Limit) { bool Status = false; if (Mime) { BMimeType m(Mime); char DefApp[B_MIME_TYPE_LENGTH]; if (m.GetPreferredApp(DefApp) == B_OK) { entry_ref ap; BMimeType a(DefApp); if (a.GetAppHint(&ap) == B_OK) { BPath p; BEntry e(&ap); if (e.GetPath(&p) == B_OK) { GAppInfo *i = new GAppInfo; if (i) { i->Path.Reset(NewStr((char*) p.Path())); Apps[0] = i; Status = true; } } } } } return Status; }
static int FetchAndVerifyConfigFile(TCascStorage * hs, PQUERY_KEY pFileKey, PQUERY_KEY pFileBlob) { TCHAR * szFileName; int nError; // Construct the local file name szFileName = NewStr(hs->szDataPath, 8 + 3 + 3 + 32); if(szFileName == NULL) return ERROR_NOT_ENOUGH_MEMORY; // Add the part where the config file path is AppendConfigFilePath(szFileName, pFileKey); // Load the config file nError = LoadTextFile(szFileName, pFileBlob); if(nError == ERROR_SUCCESS) { // Verify the blob's MD5 if(!VerifyDataBlockHash(pFileBlob->pbData, pFileBlob->cbData, pFileKey->pbData)) { FreeCascBlob(pFileBlob); nError = ERROR_BAD_FORMAT; } } CASC_FREE(szFileName); return nError; }
GDocApp<OptionsFmt>::GDocApp(const char *appname, const TCHAR *icon, char *optsname) { Options = 0; _LangOptsName = 0; d = new GDocAppPrivate(this, optsname); GRect r(0, 0, 800, 600); SetPos(r); MoveToCenter(); _FileMenu = 0; d->AppName = NewStr(appname?appname:(char*)"Lgi.GDocApp"); char p[MAX_PATH]; if (LgiGetSystemPath(LSP_APP_INSTALL, p, sizeof(p))) { LgiMakePath(p, sizeof(p), p, "_write_test.txt"); GFile f; if (!f.Open(p, O_WRITE)) { d->Mode = InstallDesktop; } else { f.Close(); FileDev->Delete(p, false); } } SetQuitOnClose(true); // Setup class if (icon) { #if defined WIN32 GWin32Class *c = GWin32Class::Create(d->AppName); if (c) { #ifdef UNICODE GPointer p; p.w = (TCHAR*)icon; if (p.i < 0x10000) { c->Class.hIcon = LoadIcon(LgiProcessInst(), MAKEINTRESOURCE(icon)); } else { GAutoWString wIcon(NewStrW(icon)); c->Class.hIcon = LoadIcon(LgiProcessInst(), wIcon); } #else c->Class.hIcon = LoadIcon(LgiProcessInst(), ((NativeInt)icon&0xffff0000)?icon:MAKEINTRESOURCE(icon)); #endif } #else if (icon) SetIcon(icon); #endif } }
GDocAppPrivate(GWindow *app, char *param) { App = app; OptionsParam.Reset(NewStr(param)); AppName = 0; Dirty = 0; Mode = InstallPortable; }
int GWindow::OnDrop(char *Format, GVariant *Data, GdcPt2 Pt, int KeyState) { int Status = DROPEFFECT_NONE; if (Format && Data) { if (stricmp(Format, LGI_FileDropFormat) == 0) { GArray<char*> Files; if (Data->IsBinary()) { GToken Uri( (char*)Data->Value.Binary.Data, "\r\n,", true, Data->Value.Binary.Length); for (int n=0; n<Uri.Length(); n++) { char *File = Uri[n]; if (strnicmp(File, "file:", 5) == 0) File += 5; char *i = File, *o = File; while (*i) { if (i[0] == '%' && i[1] && i[2]) { char h[3] = { i[1], i[2], 0 }; *o++ = htoi(h); i += 3; } else { *o++ = *i++; } } *o++ = 0; if (FileExists(File)) { Files.Add(NewStr(File)); } } } if (Files.Length()) { Status = DROPEFFECT_COPY; OnReceiveFiles(Files); Files.DeleteArrays(); } } } return Status; }
static GAutoString DescribeView(GViewI *v) { if (!v) return GAutoString(NewStr("NULL")); char s[512]; int ch = 0; ::GArray<GViewI*> p; for (GViewI *i = v; i; i = i->GetParent()) { p.Add(i); } for (int n=min(3, p.Length()-1); n>=0; n--) { v = p[n]; ch += sprintf_s(s + ch, sizeof(s) - ch, ">%s", v->GetClass()); } return GAutoString(NewStr(s)); }
void PrintGLInfo (){ #ifndef __PSP__ char *extensions; char *p, *oldp; int i; GLint int_val; GLfloat float_val; GLboolean boolean_val; string ss; Message ("Gl vendor: ", (char*)glGetString (GL_VENDOR)); Message ("Gl renderer: ", (char*)glGetString (GL_RENDERER)); Message ("Gl version: ", (char*)glGetString (GL_VERSION)); extensions = NewStr ((char*) glGetString (GL_EXTENSIONS)); Message ("", ""); Message ("Gl extensions:", ""); Message ("", ""); oldp = extensions; while ((p=strchr(oldp,' '))) { *p='\0'; Message (oldp,""); oldp = p+1; } if (*oldp) Message (oldp,""); free (extensions); Message ("", ""); for (i=0; i<(int)(sizeof(gl_values)/sizeof(gl_values[0])); i++) { switch (gl_values[i].type) { case GL_INT: glGetIntegerv (gl_values[i].value, &int_val); ss = Int_StrN (int_val); Message (gl_values[i].name, ss.c_str()); break; case GL_FLOAT: glGetFloatv (gl_values[i].value, &float_val); ss = Float_StrN (float_val, 2); Message (gl_values[i].name, ss.c_str()); break; case GL_UNSIGNED_BYTE: glGetBooleanv (gl_values[i].value, &boolean_val); ss = Int_StrN (boolean_val); Message (gl_values[i].name, ss.c_str()); break; default: Message ("",""); } } #endif }
bool Document::Open(char *FileName, int Attrib) { bool Status = FALSE; if (FileName) { char *FName = NewStr(FileName); DeleteObj(File); File = FName; Status = F.Open(File, Attrib); } return Status; }
bool GMenuItem::Name(const char *n) { bool Status = false; GAutoString p((n) ? NewStrLessAnd(n) : NewStr("")); if (p) { Status = GBase::Name(p); if (Info) Info->SetLabel(p); } return Status; }
GMessage::Result GWindow::OnEvent(GMessage *Msg) { switch (MsgCode(Msg)) { case B_SIMPLE_DATA: { GArray<char*> Files; int32 Count = 0; type_code Type = 0; if (Msg->GetInfo("refs", &Type, &Count) == B_OK) { for (int i=0; i<Count; i++) { entry_ref Ref; if (Msg->FindRef("refs", i, &Ref) == B_OK) { BPath Path(""); BEntry Entry(&Ref, true); Entry.GetPath(&Path); char *p = (char*) Path.Path(); if (p) { Files.Add(NewStr(p)); } } } } if (Files.Length() > 0) { OnReceiveFiles(Files); } Files.DeleteArrays(); break; } case M_COMMAND: { int32 Cmd = 0; int32 Event = 0; Msg->FindInt32("Cmd", &Cmd); Msg->FindInt32("Event", &Event); OnCommand(Cmd, Event, 0); break; } } return GView::OnEvent(Msg); }
static void TestStr() { CommentLine("Test String"); EQ (1, 1); NEQ(1, 232); char * testphrase = "Hello world."; char * str = NewStr(testphrase); NEQ(strlen(str), 0 ); NEQ(LenStr(str), 0 ); EQ (strlen(str), LenStr(str)); EQ (strcmp(testphrase, str), 0); NEQ(str, NULL); DelStr(str); char * tmp = (char *)malloc(sizeof(char) * strlen(str)); sprintf(tmp, "%s", testphrase); String buf = NewStr(tmp); EQ (strcmp(buf, testphrase), 0); String sub = SubStr(tmp, 0, 4); printf ("%s:%d %s:%d\n", buf, LenStr(buf), sub, LenStr(sub)); DelStr(buf); DelStr(sub); }
static GAutoString DescribeView(GViewI *v) { if (!v) return GAutoString(NewStr("NULL")); char s[512]; int ch = 0; ::GArray<GViewI*> p; for (GViewI *i = v; i; i = i->GetParent()) { p.Add(i); } for (int n=min(3, p.Length()-1); n>=0; n--) { char Buf[256] = ""; if (!stricmp(v->GetClass(), "GMdiChild")) sprintf(Buf, "'%s'", v->Name()); v = p[n]; ch += sprintf_s(s + ch, sizeof(s) - ch, "%s>%s", Buf, v->GetClass()); } return GAutoString(NewStr(s)); }
/* ** GetBootFiles -- record list of files in current (boot) directory. ** ** Parameters: ** None. ** ** Returns: ** Number of boot files on success, 0 on failure. ** ** Side Effects: ** Strings in `BootFiles' are freed/allocated. ** ** Warnings: ** - After this routine is called, ParseConfig() must be ** called to re-order it's list of boot file pointers. */ int GetBootFiles(void) { DIR *dfd; struct stat statb; struct dirent *dp; int i; /* * Free the current list of boot files. */ for (i = 0; i < C_MAXFILE && BootFiles[i] != NULL; i++) { FreeStr(BootFiles[i]); BootFiles[i] = NULL; } /* * Open current directory to read boot file names. */ if ((dfd = opendir(".")) == NULL) { /* open BootDir */ syslog(LOG_ERR, "GetBootFiles: can't open directory (%s)\n", BootDir); return(0); } /* * Read each boot file name and allocate space for it in the * list of boot files (BootFiles). All boot files read after * C_MAXFILE will be ignored. */ i = 0; for (dp = readdir(dfd); dp != NULL; dp = readdir(dfd)) { if (stat(dp->d_name, &statb) < 0 || (statb.st_mode & S_IFMT) != S_IFREG) continue; if (i == C_MAXFILE) syslog(LOG_ERR, "GetBootFiles: too many boot files (%s ignored)", dp->d_name); else if ((BootFiles[i] = NewStr(dp->d_name)) != NULL) i++; } (void) closedir(dfd); /* close BootDir */ if (i == 0) /* can't find any boot files */ syslog(LOG_ERR, "GetBootFiles: no boot files (%s)\n", BootDir); return(i); }
bool TextDocument::Insert(GCursor *At, char *Text, int Len) { bool Status = FALSE; if (Text AND Editable) { if (Len < 0) { Len = strlen(Text); } int OldLength = Length; if (SetLength(Length + Len)) { int Offset = (At) ? At->Offset + At->x : 0; // save undo info if (!IgnoreUndo) { TruncateQueue(); // add new undo info in if (UserAction *a = new UserAction) { a->Text = NewStr(Text, Len); a->x = At->x; a->y = At->y; a->Insert = true; Queue.Insert(a); UndoPos = Queue.GetItems(); } } memmove(Data + Offset + Len, Data + Offset, OldLength - Offset + 1); memcpy(Data + Offset, Text, Len); if (At) { At->Length = StrLen(Data + At->Offset); } Lines += CountLines(Text, Len); Status = true; Dirty = true; } } return Status; }
LPSTR CMem::NewStr(LPCTSTR pStr) { DWORD size = 0; if ( pStr == NULL || *pStr == 0 ) size = 1; else size = strlen( pStr ); LPSTR buf = NewStr( size ); if ( pStr == NULL || *pStr == 0 ) *buf = 0; else { strncpy( buf, pStr, size ); buf[ size ] = 0; } // end else return buf; }
GMenuItem::GMenuItem(GMenu *m, GSubMenu *p, const char *txt, int Pos, const char *shortcut) { d = new GMenuItemPrivate; Menu = m; Parent = p; Child = 0; Position = Pos; _Icon = -1; UnsupportedShortcut = false; ShortCut.Reset(NewStr(shortcut)); ShortcutKey = 0; ShortcutMod = 0; GAutoString str(NewStrLessAnd(txt)); if (Info = new LgiMenuItem(this, str, d->Msg = new BMessage(M_COMMAND))) ScanForAccel(); }
bool TextDocument::Delete(GCursor *From, int Len, char *Buffer) { bool Status = FALSE; if (From AND Editable) { int Offset = From->Offset + From->x; Len = min(Length - Offset, Len); // -1 is for NULL terminator if (Len > 0) { char *c = Data + Offset; if (!IgnoreUndo) { TruncateQueue(); // add new undo info in if (UserAction *a = new UserAction) { a->Text = NewStr(c, Len); a->x = From->x; a->y = From->y; a->Insert = false; Queue.Insert(a); UndoPos = Queue.GetItems(); } } if (Buffer) { memcpy(Buffer, c, Len); } Lines -= CountLines(c, Len); memmove(c, c + Len, Length - Offset - Len + 1); Status = SetLength(Length - Len); From->Length = StrLen(Data + From->Offset); Dirty = TRUE; } } return Status; }
char *NewStrLessAnd(char *s) { char *ns = NewStr(s); if (ns) { char *In = ns; char *Out = ns; while (*In) { if (*In != '&') { *Out++ = *In; } In++; } *Out = 0; } return ns; }
int GInput::OnNotify(GViewI *Ctrl, int Flags) { switch (Ctrl->GetId()) { case IDC_CALLBACK: { if (Callback) Callback(this, Edit, CallbackParam); break; } case IDOK: { Str.Reset(NewStr(Edit->Name())); // fall thru } case IDCANCEL: { EndModal(Ctrl->GetId() == IDOK); break; } } return 0; }
// Finds all the filenames in the specified directory that match the specified // filter. Directory should be like "data/textures" or "data/textures/". // Filter can be NULL or "" or "*.bmp" or "map_*" or "map_*.txt" // Set FullFilename to true if you want results like "data/textures/blah.bmp" // or false for "blah.bmp" LList <char *> *ListDirectory( char const *_dir, char const *_filter, bool _fullFilename ) { if(_filter == NULL || _filter[0] == '\0') { _filter = "*"; } // Create a DArray for our results LList <char *> *result = new LList<char *>(); // Now add on all files found locally #ifdef TARGET_MSVC char searchstring [256]; DarwiniaDebugAssert(strlen(_dir) + strlen(_filter) < sizeof(searchstring) - 1); sprintf( searchstring, "%s%s", _dir, _filter ); _finddata_t thisfile; long fileindex = _findfirst( searchstring, &thisfile ); int exitmeplease = 0; while( fileindex != -1 && !exitmeplease ) { if( strcmp( thisfile.name, "." ) != 0 && strcmp( thisfile.name, ".." ) != 0 && !(thisfile.attrib & _A_SUBDIR) ) { char *newname = NULL; if( _fullFilename ) { int len = strlen(_dir) + strlen(thisfile.name); newname = new char [len + 1]; sprintf( newname, "%s%s", _dir, thisfile.name ); } else { int len = strlen(thisfile.name); newname = new char [len + 1]; sprintf( newname, "%s", thisfile.name ); } result->PutData( newname ); } exitmeplease = _findnext( fileindex, &thisfile ); } #else DIR *dir = opendir(_dir); if (dir == NULL) return result; for (struct dirent *entry; (entry = readdir(dir)) != NULL; ) { if (FilterMatch(entry->d_name, _filter)) { char fullname[strlen(_dir) + strlen(entry->d_name) + 2]; sprintf(fullname, "%s%s%s", _dir, _dir[0] ? "/" : "", entry->d_name); if (!IsDirectory(fullname)) { result->PutData( NewStr(_fullFilename ? fullname : entry->d_name)); } } } closedir(dir); #endif return result; }