void TFileViewer::readFile( const char *fName ) { delete fileName; limit.x = 0; fileName = newStr( fName ); fileLines = new TLineCollection(5, 5); ifstream fileToView( fName ); if( !fileToView ) { messageBox( "Invalid drive or directory", mfError | mfOKButton ); isValid = False; } else { char line[maxLineLength+1]; while( !lowMemory() && !fileToView.eof() && fileToView.get( line, sizeof line ) != 0 ) { char c; fileToView.get(c); // grab trailing newline limit.x = max( limit.x, strlen( line ) ); fileLines->insert( newStr( line ) ); } isValid = True; } limit.y = fileLines->getCount(); }
DWORD EnhancedStatusLine::WinMessage(DWORD iMessage, DWORD wParam ,DWORD lParam) { switch (iMessage) { case SB_SETPARTS: for (int i=0; i < count; i++) delete items[i].text; delete items; count = wParam; items = new statusItem[count]; for (int i=0; i < wParam; i++) { items[i].offset = ((int *)lParam)[i]; items[i].text = newStr(""); } break; case SB_SETTEXT: wParam &= 0x1f; wParam--; if (wParam < count) { delete items[wParam].text; items[wParam].text = newStr((char *)lParam); drawView(); } break; } }
int TDataBase::compare( void *key1, void *key2 ) { char *string1, *string2; string1 = strupr( newStr( (char *)key1 ) ); string2 = strupr( newStr( (char *)key2 ) ); // string1 = new char[81]; // string2 = new char[81]; // TDBEntry *entry1 = // (TDBEntry *)indexCache->getItem( (RecordDescriptor *)key1 ); // ((TDBEntry *)entry1)->getKey( string1, 80 ); // // TDBEntry *entry2 = // (TDBEntry *)indexCache->getItem( (RecordDescriptor *)key2 ); // ((TDBEntry *)entry2)->getKey( string2, 80 ); // strupr( string1 ); // strupr( string2 ); int result = strcmp( string1, string2 ); delete[] string1; delete[] string2; return result; }
const char *FindCaseInsensitive ( const char *_fullPath ) { if ( !_fullPath ) return NULL; static char retval[PATH_MAX]; char *dir = NULL, *file = NULL; if ( (dir = GetDirectoryPart(_fullPath)) != NULL ) { // Make our own copy of the result, since GetDirectoryPart // and GetFilenamePart use the same variable for temp // storage. dir = newStr(dir); } if ( !dir ) { // No directory provided. Assume working directory. file = newStr(_fullPath); } else { // Kill the last slash dir[strlen(dir) - 1] = '\0'; file = newStr(GetFilenamePart(_fullPath)); } LList <char *> *files = ListDirectory(dir, file); delete [] dir; delete [] file; dir = file = NULL; // We shouldn't have found more than one match. AppAssert(files->Size() <= 1); // No results, so maybe the file does not exist. if ( files->Size() == 0 ) return _fullPath; // Copy the corrected path back, and prepare to return it. memset ( retval, 0, sizeof ( retval ) ); AppAssert ( strlen ( files->GetData(0) ) < PATH_MAX ); strcpy ( retval, files->GetData(0) ); // Negate the possibility of a memory access violation. // This way, we can simply strcpy the result inline without // worrying about a buffer overflow. AppAssert(strlen(retval) == strlen(_fullPath)); while ( files->Size() ) { char *data = files->GetData(0); files->RemoveData(0); delete [] data; } delete files; return retval; }
char *newStr(const void *str, unsigned len, unsigned short elementSize, unsigned short codePage) { char *out = newStr(len, elementSize, codePage); memcpy(out, str, len*elementSize); memset(out + len*elementSize, 0, 2); return out; }
void OptionBinds::Item::newString(Option::Priority priority, const std::string & value) { if (newStr) newStr(priority, value); else option->set(priority, value); }
TRadioField::TRadioField( TMeasurements& m, const char *aLabel, ushort aStringLength, TSItem *aStrings, TSItem *aDeviceStrings, ushort options ) : TField( m, TRadioField::controlSize, aLabel, aStringLength, options ), strings( aStrings ) { short i = 0; TSItem *p; for( p = aDeviceStrings; p != 0; p = p->next ) i++; deviceStrings = new TStringCollection( i, 0 ); while( aDeviceStrings != 0 ) { p = aDeviceStrings; deviceStrings->atInsert( deviceStrings->getCount(), newStr( aDeviceStrings->value ) ); aDeviceStrings = aDeviceStrings->next; delete p; } adjustRBMeasurements( m, aStrings ); createControl( m ); if( aLabel ) createLabel( m, aLabel ); }
char * loadTGA(char * loc, int * x, int *y, short * bpp) { //Loads the TGA data from file (deylen - 02/06/2009) int size; char * data; unsigned short w, h; FILE * f; if (!(f = fopen(loc, "rb"))) loadTGAFail(loc); fseek(f, 12, SEEK_SET); if (fread(&w, 2, 1, f) != 1) loadTGAFail(loc); if (fread(&h, 2, 1, f) != 1) loadTGAFail(loc); if (fread(bpp, 1, 1, f) != 1) loadTGAFail(loc); fseek(f, 18, SEEK_SET); *x = w; *y = h; *bpp /= 8; size = (*x) * (*y) * (*bpp); data = newStr(size); if (fread(data, sizeof(unsigned char), size, f) < size) { free(data); pfatal("Could not read all of data from file. Make sure you have saved the Image without RLE compression\n"); } fclose(f); return data; }
void Read(VMachine** pvm) { VMachine*vm = *pvm; int i=0; SymDesc* s= start; while(s) { if (s->cont) vm->str[i] = newStr(s->cont); else vm->str[i] = newStr2(); s->idx = i ++; s = s->next; } vm->ninstr = Len(intcode); vm->instr = (Instr*)malloc(vm->ninstr * sizeof(Instr)); IntInstr *cinstr = intcode; for (i=0;i<vm->ninstr;i++) { switch (cinstr->opcode) { case OP_NOP : vm->instr[i] = newInstr(OP_NOP,0); break; case OP_PUSH : vm->instr[i] = newInstr(OP_PUSH,cinstr->str->idx);break; case OP_GETTOP : vm->instr[i] = newInstr(OP_GETTOP,cinstr->str->idx); break; case OP_DISCARD : vm->instr[i] = newInstr(OP_DISCARD,0);break; case OP_PRINT : vm->instr[i] = newInstr(OP_PRINT,0); break; case OP_INPUT : vm->instr[i] = newInstr(OP_INPUT,cinstr->str->idx); break; case OP_JMP : vm->instr[i] = newInstr(OP_JMP,cinstr->target->n - i); break; case OP_JMPF : vm->instr[i] = newInstr(OP_JMPF,cinstr->target->n - i); break; case OP_STR_EQUAL : vm->instr[i] = newInstr(OP_STR_EQUAL,0);break; case OP_BOOL_EQUAL : vm->instr[i] = newInstr(OP_BOOL_EQUAL,0);break; case OP_CONCAT : vm->instr[i] = newInstr(OP_CONCAT,0); break; case OP_BOOL2STR : vm->instr[i] = newInstr(OP_BOOL2STR,0);break; case JUMPTARGET : vm->instr[i] = newInstr(OP_NOP,0);break; } cinstr = cinstr->next; } }
Tex * newLetter(char * data, int x, int y, int size, int bpp, int w) { /* Create a single letter (deylen - 14/5/2009)*/ int a; char * letterDat = newStr(size * (size * bpp)); char * p, * p2 = letterDat; Tex * letter; p = data + (x * (size * bpp)) + (y * (size * (w * bpp))); /* Setting the start point of our texture (deylen - 14/05/2009)*/ /* - - - - - - - - - - * * - - - - _ _ - - - - * * - - - | | - - - * * - @ - | A | - B - * * - - - | _ _ | - - - * * - - - - - - - - - - * * - - - - - - - - - - * * * A is the area of the whole texture that we will extract for our letter (deylen - 14/05/2009)*/ for (a=0; a < size; a++){ p2 = strcpyN(p2, p, size * bpp); p += w * bpp; }/* copying the data into letterDat by way of pointer p2 (deylen - 14/05/2009)*/ /* add <w * bpp> to move to the next row of the texture (deylen - 14/05/2009)*/ letter = newTexChar(letterDat, size, size, bpp); free(letterDat); return letter; }
static Func *newFunc(const char *name, Cons *args, CodeGenFunc gen) { int argc = 0; for(Cons *c=args; c!=NULL; c=c->cdr) { argc++; } Func *f = new Func(); f->name = newStr(name); f->argc = argc; f->args = argc != 0 ? new const char *[argc] : NULL; int i = 0; for(Cons *c=args; c!=NULL; c=c->cdr) { f->args[i++] = newStr(c->str); } f->code = NULL; f->codegen = gen; return f; }
wxString DIALOG_CREATE_ARRAY::ARRAY_OPTIONS::InterpolateNumberIntoString( int aN, const wxString& aPattern ) const { wxString newStr( aPattern ); newStr.Replace( "%s", GetItemNumber( aN ), false ); return newStr; }
char *cpyStr(const void *vdelphiStr) { const char *delphiStr = (const char*)vdelphiStr; return newStr( (const void*)(delphiStr-0), *(unsigned*)(delphiStr-4), *(unsigned short*)(delphiStr-10), *(unsigned short*)(delphiStr-12)); }
Client & Client::operator<< ( int n ) { char buf[1024]; ACE_OS::sprintf(buf,"(%d)\n",n); ACE_SString newStr(buf); *this << newStr; return *this; }
TMenuItem::TMenuItem( const char *aName, ushort aCommand, ushort aKeyCode, ushort aHelpCtx, char *p, TMenuItem *aNext ) { name = newStr( aName ); command = aCommand; disabled = Boolean(!TView::commandEnabled(command)); keyCode = aKeyCode; helpCtx = aHelpCtx; if( p == 0 ) param = 0; else param = newStr( p ); next = aNext; }
void LLPathfindingNavMesh::handleNavMeshResult(const LLSD &pContent, U32 pNavMeshVersion) { llassert(pContent.has(NAVMESH_VERSION_FIELD)); if (pContent.has(NAVMESH_VERSION_FIELD)) { llassert(pContent.get(NAVMESH_VERSION_FIELD).isInteger()); llassert(pContent.get(NAVMESH_VERSION_FIELD).asInteger() >= 0); U32 embeddedNavMeshVersion = static_cast<U32>(pContent.get(NAVMESH_VERSION_FIELD).asInteger()); llassert(embeddedNavMeshVersion == pNavMeshVersion); // stinson 03/13/2012 : does this ever occur? if (embeddedNavMeshVersion != pNavMeshVersion) { LL_WARNS() << "Mismatch between expected and embedded navmesh versions occurred" << LL_ENDL; pNavMeshVersion = embeddedNavMeshVersion; } } if (mNavMeshStatus.getVersion() == pNavMeshVersion) { ENavMeshRequestStatus status; if ( pContent.has(NAVMESH_DATA_FIELD) ) { const LLSD::Binary &value = pContent.get(NAVMESH_DATA_FIELD).asBinary(); unsigned int binSize = value.size(); std::string newStr(reinterpret_cast<const char *>(&value[0]), binSize); std::istringstream streamdecomp( newStr ); unsigned int decompBinSize = 0; bool valid = false; U8* pUncompressedNavMeshContainer = unzip_llsdNavMesh( valid, decompBinSize, streamdecomp, binSize ) ; if ( !valid ) { LL_WARNS() << "Unable to decompress the navmesh llsd." << LL_ENDL; status = kNavMeshRequestError; } else { llassert(pUncompressedNavMeshContainer); mNavMeshData.resize( decompBinSize ); memcpy( &mNavMeshData[0], &pUncompressedNavMeshContainer[0], decompBinSize ); status = kNavMeshRequestCompleted; } if ( pUncompressedNavMeshContainer ) { free( pUncompressedNavMeshContainer ); } } else { LL_WARNS() << "No mesh data received" << LL_ENDL; status = kNavMeshRequestError; } setRequestStatus(status); } }
struct node * readATree (FILE * f){ char c, buffer[LINELENGTH]; struct node * newTree; c = fgetc(f); fgets(buffer, LINELENGTH, f); buffer[strlen(buffer)-1]='\0'; newTree = newNode(newStr(buffer),0,0); if (c == 'Q'){ newTree->left = readATree(f); newTree->right = readATree(f); } return newTree; }
static Cons *copyCons(Cons *cons) { if(cons == NULL) return NULL; Cons *c = new Cons(cons->type); switch(cons->type) { case CONS_INT: c->i = cons->i; break; case CONS_STR: c->str = newStr(cons->str); break; case CONS_FLOAT: c->f = cons->f; break; case CONS_CAR: c->car = copyCons(cons->car); break; default: abort(); } if(cons->cdr != NULL) c->cdr = copyCons(cons->cdr); return c; }
/* * Incarca continutul fisierului in buffere interne. */ void TInterior::readFile(const char *fileName) { ifstream fileToView(fileName); if (fileToView) { char buf[maxLineLength]; while (lineCount < maxLines && fileToView.getline(buf, maxLineLength) != 0) { lines[lineCount] = newStr(buf); lineCount++; } } }
TMenuItem::TMenuItem( const char *aName, ushort aKeyCode, TMenu *aSubMenu, ushort aHelpCtx, TMenuItem *aNext ) { name = newStr( aName ); command = 0; disabled = Boolean(!TView::commandEnabled(command)); keyCode = aKeyCode; helpCtx = aHelpCtx; subMenu = aSubMenu; next = aNext; }
TButton::TButton( const TRect& bounds, const char *aTitle, ushort aCommand, ushort aFlags) : TView( bounds ), flags( aFlags ), amDefault( Boolean( (aFlags & bfDefault) != 0 ) ), title( newStr( aTitle ) ), command( aCommand ) { options |= ofSelectable | ofFirstClick | ofPreProcess | ofPostProcess; eventMask |= evBroadcast; if( !commandEnabled(aCommand) ) state |= sfDisabled; }
static ValueType genSetq(Func *, Cons *cons, CodeBuilder *cb, int sp) { assert(cons->type == CONS_STR); const char *name = cons->str; cons = cons->cdr; Cons *expr = cons; Variable *v = new Variable(); v->name = newStr(name); v->value.i = 0; cb->getCtx()->putVar(v); v->type = codegen(expr, cb, sp); cb->createStoreGlobal(sp, v); return v->type; }
void myParserEDM::Qt_extractString(char *str, char *retStr, int *status) { int startPos = 0; retStr[0] = '\0'; QString newStr(str); startPos =newStr.indexOf("}("); if(startPos > -1) { newStr.remove(0,startPos+2); } else { *status = false; return; } if(newStr.endsWith(")")) newStr.remove(newStr.size()-1,1); strcpy(retStr, (char*) newStr.toLatin1().constData()); *status = true; }
bool DoesFileExist(const char *_fullPath) { #ifndef WIN32 char *path = newStr(_fullPath); FILE *f = fopen(FindCaseInsensitive(path), "r"); delete [] path; #else FILE *f = fopen(_fullPath, "r"); #endif if(f) { fclose(f); return true; } return false; }
TReference *TRefTable::getReference( char *topic ) { TReference *ref; int i; if (search(topic, i)) ref = (TReference *) at(i); else { ref = new TReference; ref->topic = newStr(topic); ref->resolved = False; ref->val.fixUpList = 0; insert(ref); } return(ref); }
//////////////////////////////////////////////////////////////////////////////////////// /// \brief Fonction qui permet de modifier la taille de la cha�e de caract�e /// /// \param newSize : Nouvelle taille. /// /// \see /// http://www.cplusplus.com/ref/cstdio/sprintf.html //////////////////////////////////////////////////////////////////////////////////////// void CString::resize(int newSize) { if (newSize > 0) { char tmp[10]; sprintf(tmp, "%%.%is", newSize); CString newStr(tmp, s); set(newStr.s); } else { // On le remet �vide delete [] s; s = new char [1]; s[0] = '\0'; } }
char * getFileText(char * loc) { FILE * f; if ((f = fopen(loc, "rb")) < 0) return NULL; fseek(f, 0, SEEK_END); int len = ftell(f); fseek(f, 0, SEEK_SET); char * data = newStr(len); data[fread(data, sizeof(char), len, f)] = '\0'; fclose(f); return data; }
TWindow::TWindow(const TRect &bounds, const char *aTitle, short aNumber ) : TGroup(bounds), flags(wfMove | wfGrow | wfClose | wfZoom), zoomRect(getBounds()), number(aNumber), palette(wpBlueWindow), title(newStr(aTitle)), TWindowInit(TWindow::initFrame) { state |= sfShadow; options |= ofSelectable | ofTopSelect; growMode = gfGrowAll | gfGrowRel; if (createFrame != 0 && (frame = createFrame(getExtent())) != 0) insert(frame); }
void readFile( const char *fileName ) { ifstream fileToView( fileName ); if( !fileToView ) { cout << "Invalid file name..." << endl; exit( 1 ); } else { char buf[maxLineLength]; while( lineCount < maxLines && fileToView.getline( buf, maxLineLength ) != 0 ) { lines[lineCount] = newStr( buf ); lineCount++; } } }
/* * Remove forbidden characters from a filename */ const QString lamexp_clean_filename(const QString &str) { QString newStr(str); QRegExp rx("\"(.+)\""); rx.setMinimal(true); newStr.replace("\\", "-"); newStr.replace(" / ", ", "); newStr.replace("/", ","); newStr.replace(":", "-"); newStr.replace("*", "x"); newStr.replace("?", ""); newStr.replace("<", "["); newStr.replace(">", "]"); newStr.replace("|", "!"); newStr.replace(rx, "`\\1´"); newStr.replace("\"", "'"); return newStr.simplified(); }