//=========================================================================== // helpers to remove excess info int trim_address(char q[MAX_PATH], int is, int js) { char *p; p = (strchr(q, is)); if (p != NULL) { p = _strrev(strrchr(_strrev(q), js)); strcpy(q, (const char *)(p)); return 1; } return 0; }
int _tmain(int argc, _TCHAR* argv[]) { TCHAR szBuf[200]; wscanf_s(L"%ls", szBuf, _countof(szBuf)); HANDLE hFileRes = CreateFile(szBuf, GENERIC_WRITE | GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFileRes == INVALID_HANDLE_VALUE) { printf("打开文件出错\n"); } DWORD dwFileSize = GetFileSize(hFileRes, NULL); HANDLE hFileMap = CreateFileMapping(hFileRes, NULL, PAGE_READWRITE, 0, dwFileSize + sizeof(char), NULL); if (hFileMap == NULL) { printf("创建文件映射对象失败\n"); } PVOID pvFile = MapViewOfFile(hFileMap, FILE_MAP_WRITE, 0, 0, 0); if (pvFile == NULL) { printf("映射文件失败\n"); } PSTR psFile = (PSTR)pvFile; psFile[dwFileSize / sizeof(char)] = 0; _strrev(psFile); SetFilePointer(hFileRes, dwFileSize, NULL, FILE_BEGIN); SetEndOfFile(hFileRes); UnmapViewOfFile(pvFile); CloseHandle(hFileRes); CloseHandle(hFileMap); return 0; }
/* int数字转换为字符串 */ extern char *integerToString(int num) { char *str = (char *)calloc(12, sizeof(char)); if (str == NULL) { consoleLog("在转化为字符串时出现了无法申请内存的现象"); return NULL; } int flag = 0; int count = 0; if (num < 0) { num *= -1; flag = 1; } do { str[count++] = num % 10 + 48; num /= 10; } while (num != 0); if (flag) { str[count++] = '-'; } str[count] = '\0'; return _strrev(str); }
Complex * Gates::reverse_kronecker(Complex * kron, int kron_size){ /*ENTANGLEMENT MIGHT NOT NEED TO BE IMPLEMENTED //TODO: CHECK IF KRON IS ENTANGLED if (entangler.is_gateout_entangled(kron)){ //ENTANGLE std::cout << "Entangled" << std::endl; } //TODO: IF IT IS -> ADD THIS KRON TO THE ENTANGLEMENT LIST //TODO: UPDATE ALL ENTANGLEMENTS */ int reversed_kron_size = (log(kron_size) / log(2)) * 2; Complex * reversed_kronecker = new Complex[reversed_kron_size+2]; for (int i = 0; i < reversed_kron_size;i++) reversed_kronecker[i] = Complex(0, 0); for (int i = 0; i<kron_size; i++) if (kron[i].re == 1){ int toBinSize = log(kron_size) / log(2); char *toBin = new char[toBinSize]; toBin = utils.long2binstr(i, toBinSize); _strrev(toBin); int index_rev_kro = 0; //USE ITS OWN INDEX BECAUSE J IS THE INDEX OF TOBIN AN TOBIN HAS TO GO REVERSED for (int j = 0; j < toBinSize; j++){ if (toBin[j] == '1') reversed_kronecker[index_rev_kro+1] = Complex(1, 0); else reversed_kronecker[index_rev_kro] = Complex(1, 0); index_rev_kro +=2; } delete [] toBin; break; } return reversed_kronecker; }
/* ********************************************************************************* */ char* extract_filename(char *path, char* fname) { char temp[MAX_PATH]; int i,j; int len; len = strlen(path); memset(temp, 0x0, sizeof(temp)); deb("path: %s", path); for(i=len-1,j=0;i;i--) { if(path[i] == '\\' || path[i] == ':' || path[i] == '/' || path[i] == 0x20) break; else { //deb("c %c", path[i]); temp[j++] = path[i]; } } deb("temp: %s", temp); strcpy(fname, temp); _strrev(fname); deb("extracted name: %s", fname); return fname; }
// convert the whole part char *convertWhole(int wholeVal, unsigned int dst_base){ unsigned int index = 0; char c; char *newNum = (char*)malloc(100); // case the number is 0 if (wholeVal == 0) newNum[index++] = '0'; // create the whole part string while (wholeVal != 0){ c = (wholeVal%dst_base); //break numbers according to the base wholeVal = (wholeVal / dst_base); // create the charcters for the string if (c >= 10 && c <= 35) c = c + 'A'; else c = c + '0'; // store the char in the string newNum[index++] = c; } newNum[index] = '\0'; // reverse the string _strrev(newNum); return newNum; }
void Registration::GenerateKey(char szName[16], SIZE_T length, char szOutput[20]) { char szSerial[128]; int iFillCount = 0; if (length < 16) { iFillCount = 16-length; } strcpy_s(szSerial, sizeof(szSerial), szName); bool bSwitch = false; for (int i = 0; i < iFillCount; i++) { char cNext; !bSwitch ? cNext = szName[i] : cNext = szName[length-i]; szSerial[length+i] = cNext; bSwitch = !bSwitch; } szSerial[length+iFillCount] = 0; /* Wir haben ejtzt einen 16-Stelligen String + 0 */ strcpy_s(szSerial, sizeof(szSerial), _strrev(szSerial)); cCRC *pCrc = new cCRC; DWORD dwCrc32 = pCrc->crc32(szName); for (unsigned int i = 0; i < strlen(szSerial); i++) { // Irgendwie verhunzen szSerial[i] >>= 1; szSerial[i] *= (char)i; szSerial[i] ^= dwCrc32; // erst positive zahl dann nur zahlen und große buchstaben char cMod = (szSerial[i] & 0x7F) % 42; szSerial[i] = cMod + 48; // paar sonderzeichen dazwischen, einfach addieren damit wir in den Buchstabenbereich kommen if (szSerial[i] >= 0x3A && szSerial[i] <= 0x40) { szSerial[i] += 7; } } /* Bindestriche einfügen */ char szFinalSerial[20]; char *c = szSerial; int i; for (i = 0; *c; ++i) szFinalSerial[i] = i%5==4 ? '-' : *c++; szFinalSerial[i] = '\0'; // in Final OUtput schreiben strcpy_s(szOutput, 20, szFinalSerial); }
extern "C" unsigned char* __cdecl _mbsrev_l( unsigned char* string, _locale_t plocinfo ) { unsigned char* start = string; unsigned char* left = string; unsigned char c; _LocaleUpdate _loc_update(plocinfo); /* validation section */ _VALIDATE_RETURN(string != NULL, EINVAL, NULL); if (_loc_update.GetLocaleT()->mbcinfo->ismbcodepage == 0) { return (unsigned char*)_strrev((char*)string); } /* first go through and reverse the bytes in MBCS chars */ while (*string) { if (_ismbblead_l(*string++, _loc_update.GetLocaleT())) { if (*string) { c = *string; *string = *(string - 1); *(string - 1) = c; string++; } else { /* second byte is EOS There is nothing really satisfying to do here. We have a string that ends in leadbyte,'\0'. Reversing this would lead to the leadbyte becoming falsely attached to the character before it: (XL0 -> LX0, X has suddenly become a trailbyte) So what we choose to do is assert and purge the dud byte from within the string. */ errno = EINVAL; _ASSERTE(("Bad MBCS string passed into _mbsrev", 0)); /* String has at least moved once already, so this is safe */ _ASSERTE(string > start); /* move back one to point at the dud leadbyte */ --string; /* now truncate the string one byte earlier */ *string = '\0'; break; } } } /* now reverse the whole string */ string--; while (left < string) { c = *left; *left++ = *string; *string-- = c; } return (start); }
void fun(char* s,int n) { char* p=s; int temp,jinwei; for(*p=n+'0', jinwei=0;!(*p=='0'&&jinwei==1);p++) ((temp = (*p-'0')*n+jinwei)>9)?(*(p+1)=temp%10+'0',jinwei=temp/10):(*(p+1)=temp+'0',jinwei=0); *++p='1',*++p='\0'; _strrev(s); }
/** *将时间戳转化为字符串形式 *@param time_t time时间 *@return char* 时间戳字符串 *@author Hafrans Newton */ extern char *timestampToString(time_t timeb) { char str[4096] = { '\0' }; int i = 0; do { str[i++] = timeb % 10 + 48; } while ((timeb /= 10)); str[i + 1] = '\0'; return _strrev(str); }
char * SDL_strrev(char *string) { #if defined(HAVE__STRREV) return _strrev(string); #else size_t len = SDL_strlen(string); char *a = &string[0]; char *b = &string[len - 1]; len /= 2; while (len--) { char c = *a; *a++ = *b; *b-- = c; } return string; #endif /* HAVE__STRREV */ }
static int _lltoa( UITYPE x, char *buf, int prec, unsigned base ) { int digits = 0; int c; if (prec < 0) prec = 1; while (x > 0 || digits < prec) { c = x % base; x = x / base; if (c < 10) c += '0'; else c = (c - 10) + 'a'; buf[digits++] = c; } buf[digits] = 0; _strrev(buf); return digits; }
int isPalindrome_num(long long int n){ /* ****<string.h> Used to check number is palindrome or not """ isPalindrome_num(n) return 1 if palindrome return 0 if not palindrome """ */ char a[30]; char b[30]; sprintf(a,"%d",n); //convert number in string & store it in array a strcpy(b,a); //copy b<-a _strrev(b); //reverse b if(strcmp(a,b)==0) //compare return 1; else return 0; }
// explode packed sets of bar CString CEANBase::Explode (int nDigit, char chSet) { CString strPack = m_strEAN[nDigit]; if (chSet == 'B') { _strrev (strPack.GetBuffer (-1)); strPack.ReleaseBuffer (); } char chFirst = chSet == 'C' ? '1' : '0'; CString strResult; for (int i = 0; i < strPack.GetLength (); i++) { for (int j = 0; j < strPack.GetAt (i) - '0'; j++) strResult += chFirst; chFirst = chFirst == '1' ? '0' : '1'; } return strResult; }
unsigned char * __cdecl _mbsrev( unsigned char *string ) { unsigned char *start = string; unsigned char *left = string; unsigned char c; if (0 == __mbcodepage) return _strrev(string); _mlock(_MB_CP_LOCK); /* first go through and reverse the bytes in MBCS chars */ while ( *string ) { if ( _ISLEADBYTE(*string++) ) { if ( *string ) { c = *string; *string = *(string - 1); *(string - 1) = c; string++; } else /* second byte is EOS */ break; } } /* now reverse the whole string */ string--; while ( left < string ) { c = *left; *left++ = *string; *string-- = c; } _munlock(_MB_CP_LOCK); return ( start ); }
char *GetRowName(long iRow) { static char row_name[64]; size_t str_len = 0; while (iRow > 0) { int num_data = iRow % 26; iRow /= 26; if (num_data == 0) { num_data = 26; iRow--; } row_name[str_len] = (char)((num_data - 1) + 'A'); str_len++; } row_name[str_len] = '\0'; //反转 _strrev(row_name); return row_name; }
//取得列的名称,比如27->AA char *IllusionExcelFile::GetColumnName(long icolumn) { static char column_name[64]; size_t str_len = 0; while (icolumn > 0) { int num_data = icolumn % 26; icolumn /= 26; if (num_data == 0) { num_data = 26; icolumn--; } column_name[str_len] = (char)((num_data - 1) + 'A'); str_len++; } column_name[str_len] = '\0'; //反转 _strrev(column_name); return column_name; }
void MakeAbsolutePath( char *adir, char *rdir, char *fulldir ) // NOTE: adir cannot include a filename! { // combine relative or absolute path rdir with an absolute directory int subdirs, r, a; // e.g. rdir="..\mydir\image.bmp" and adir="C:\ourdir\yourdir\" char *f; // then fulldir = "C:\ourdir\mydir\image.bmp" bool skipit; f = fulldir; // form output string in reverse r = strlen(rdir) - 1; a = strlen(adir) - 1; // start at back of input strings if ( rdir[1] == ':' ) subdirs = 0; // have absolute path else subdirs = 1; // number of subdirs to backup + 1 while ( r >= 0 ) { // move subdir to fulldir string if ( rdir[r] != '\\' ) *f++ = rdir[r--]; else { // hit new subdir delimiter skipit = false; if ( r > 1 ) // check for .. if ( (rdir[r-1] == '.') && (rdir[r-2] == '.') ) skipit = true; // if found skip over it if ( skipit ) // skip .. and don't copy backslash { subdirs++; r = r - 3; } else *f++ = rdir[r--]; // otherwise copy backslash and continue } } if ( subdirs ) // rdir was relative not absolute { subdirs--; // will need to copy rest of adir while ( subdirs ) // peel off subdirs of adir { a--; // skip over last backslash while ( (a>=0) && (adir[a] != '\\') ) a--; // skip over subdir subdirs--; // do next subdir } while ( a >= 0 ) *f++ = adir[a--]; // copy rest of adir to complete path } *f = '\0'; _strrev(fulldir); // reverse string to correct order }
bool CConsoleOGL::CmdShip(char *szCmdParam) { bool goodToGo = true; char *allocFileName = new char[ strlen(szCmdParam)+1 ]; strcpy( allocFileName, szCmdParam ); //------------------- // Tokenize Path //------------------- _strrev( allocFileName ); // reverse the string char *token = strtok(allocFileName, " /\"\0\\"); // search for the first slash or quote if(token != NULL) { _strrev(token); // flip the filename around again // to get the correct name strcpy(allocFileName, token); // copy back into the cmdParam, just to make sure allocFileName[strlen(allocFileName) + 1] = NULL; // terminate it! to be really sure } else { print( 0, "Invalid Filename!" ); SAFE_DELARY( allocFileName ); goodToGo = false; return false; } //------------------- // Append new path // & extension //------------------- char *fileAndPath = NULL; int pathSize = strlen("ships/") + strlen(allocFileName) + strlen(".ase") + 1; fileAndPath = new char[ pathSize ]; memset(fileAndPath, NULL, pathSize); strcpy(fileAndPath, "ships/"); strcat(fileAndPath, allocFileName); // case-insensitive scan for .ASE ending if( strncmp(_strrev(_strlwr(fileAndPath)), "esa.", 4) ) // if the extension isn't there strcat(_strrev(fileAndPath), ".ase"); // reverse it back and append extension else _strrev(fileAndPath); // reverse it back anyway // SAFE_DELARY(allocFileName); // this stopped working all of a sudden! //------------------- // Test to see if the // file exists //------------------- if( this->client->player.ship.openFile(fileAndPath) ) this->client->player.ship.closeFile(); else { print( 0, "Couldn't open %s", fileAndPath ); error.msg( "Couldn't open %s", fileAndPath ); SAFE_DELARY( fileAndPath ); goodToGo = false; return false; } // the filename was ok, so we'll load the ship if( goodToGo == true ) { print( 0, "Loading ship..." ); // Unload everything // look at the comment for CmdTrack above! // We make sure the new ship exists before unloading the old ship // then this->client->player.ship.unload(); // Load everything bool success = 0; if( this->client->scene.initialized ) { this->client->player.ship.attachToScene( &this->client->scene ); success = this->client->player.ship.load( szCmdParam ); } else { error.msg( "ERROR: Scene not loaded!" ); print( 0, "ERROR: Scene not loaded!" ); // was printf(0, "...") whoops! success = 0; } if(success) { print( 0, "Ship loaded successfully!"); } else { this->client->player.ship.load( NULL ); error.msg( "ERROR: Couldn't load ship" ); print( 0, "ERROR: Couldn't load ship" ); } } return(true); }
int main() { char pals[1024] = "mississippiarozaupalanalapuazoraaaaasobakabosavjfhdlomosmokinggnikomsomolsfsdlfhbvhamanaplanacanalpanamajfgjbf4603974fg4u"; const int n = strlen(pals); strcpy(pals + n + 1, pals); _strrev(pals + n + 1); // SuffixSet sufs(pals, 2 * n + 1); printf("building suffix tree... "); for (int i = 0; i != 2 * n + 1; ++i) sufs.push_back(); printf("done!\n"); printf("lca preprocessing... "); patl::lca_oracle<SuffixSet> lca(sufs); printf("done!\n"); printf("leaf preprocessing... "); patl::leaf_oracle<SuffixSet> leaf(sufs); printf("done!\n"); // printf("---\n"); for (int i = 1; i != n; ++i) { const vertex v = lca( leaf(pals + i), leaf(pals + 2 * n + 1 - i)); const int q = v.prefix_length() / 8; if (q) printf("% 4d %s\n", i, std::string(pals + i - q, 2 * q).c_str()); } { printf("***\n"); std::vector<int> d(n); int l = 0, r = -1; for (int i = 0; i < n; ++i) { int k = (i > r ? 0 : patl::impl::get_min(d[l + r - i + 1], r - i + 1)) + 1; while (i + k - 1 < n && i - k >= 0 && pals[i + k - 1] == pals[i - k]) ++k; d[i] = --k; if (i + k - 1 > r) { l = i - k; r = i + k - 1; } if (d[i]) printf("% 4d %s\n", i, std::string(pals + i - d[i], 2 * d[i]).c_str()); } } // printf("---\n"); for (int i = 1; i != n; ++i) { const vertex v = lca( leaf(pals + i), leaf(pals + 2 * n - i)); const int q = v.prefix_length() / 8 - 1; if (q) printf("% 4d %s\n", i, std::string(pals + i - q, 2 * q + 1).c_str()); } { printf("***\n"); std::vector<int> d(n); int l = 0, r = -1; for (int i = 0; i != n; ++i) { int k = (i > r ? 0 : patl::impl::get_min(d[l + r - i], r - i)) + 1; while (i + k < n && i - k >= 0 && pals[i + k] == pals[i - k]) ++k; d[i] = --k; if (i + k > r) { l = i - k; r = i + k; } if (d[i]) printf("% 4d %s\n", i, std::string(pals + i - d[i], 2 * d[i] + 1).c_str()); } } }
bool CScene::load(char *aseFilename) { // remove leading and trailing spaces // strrlc(aseFilename); // !!!does nothing because aseFilename isn't directly operated on!!! // strrtc(aseFilename); // !!!does nothing because aseFilename isn't directly operated on!!! char *allocFileName = new char[ strlen(aseFilename)+1 ]; strcpy( allocFileName, aseFilename ); //------------------- // Tokenize Path //------------------- _strrev( allocFileName ); // reverse the string char *token = strtok(allocFileName, " /\"\0\\"); // search for the first slash or quote if(token != NULL) { _strrev(token); // flip the filename around again // to get the correct name strcpy(allocFileName, token); // copy back into the cmdParam, just to make sure allocFileName[strlen(allocFileName) + 1] = NULL; // terminate it! to be really sure } else { //console->print( 0, "Invalid Filename!" ); return false; } //------------------- // Append new path // & extension //------------------- char *fileAndPath = NULL; int pathSize = strlen("tracks/") + strlen(allocFileName) + strlen(".ase") + 1; fileAndPath = new char[ pathSize ]; memset(fileAndPath, NULL, pathSize); strcpy(fileAndPath, "tracks/"); strcat(fileAndPath, allocFileName); // case-insensitive scan for .ASE ending if( strncmp(_strrev(_strlwr(fileAndPath)), "esa.", 4) ) // if the extension isn't there strcat(_strrev(fileAndPath), ".ase"); // reverse it back and append extension else _strrev(fileAndPath); // reverse it back anyway // SAFE_DELARY(allocFileName); // this stopped working all of a sudden! //------------------- // Test to see if the // file exists //------------------- if( this->openFile(fileAndPath) ) this->closeFile(); else { //console->print( 0, "Couldn't open %s", fileAndPath ); error.msg( "Couldn't open %s", fileAndPath ); SAFE_DELARY( fileAndPath ); return false; } //------------------- // Do the loading //------------------- if( !this->initialized ) init(); // inits the scene if( this->convert(fileAndPath) ) { // Load and play the music mod = NULL; //FMUSIC_LoadSong( "audio/nova.s3m" ); /* if(!mod) { //error.msg("CLIENT: CScene::Load(): %s", FMOD_ErrorString(FSOUND_GetError())); error.msg( "CLIENT: CScene::Load(): couldn't load song" ); } FMUSIC_PlaySong(mod); */ SAFE_DELARY( fileAndPath ); return true; } else { SAFE_DELARY( fileAndPath ); return false; } }
int getopt(int argc, char *argv[], char *opstring) { static char *pIndexPosition = NULL; /* place inside current argv string */ char *pArgString = NULL; /* where to start from next */ char *pOptString = NULL; /* the string in our program */ char temp[1024]; char tempOptArg[1024]; // Initailize the local variables. memset(temp, 0, 1024); memset(tempOptArg, 0, 1024); if (pIndexPosition != NULL) { /* we last left off inside an argv string */ if (*(++pIndexPosition)) { /* there is more to come in the most recent argv */ pArgString = pIndexPosition; } } if (pArgString == NULL) { /* we didn't leave off in the middle of an argv string */ if (optind >= argc) { /* more command-line arguments than the argument count */ pIndexPosition = NULL; /* not in the middle of anything */ return EOF; /* used up all command-line arguments */ } /*--------------------------------------------------------------------- * If the next argv[] is not an option, there can be no more options. *-------------------------------------------------------------------*/ pArgString = argv[optind++]; /* set this to the next argument ptr */ if (('/' != *pArgString) && /* doesn't start with a slash or a dash? */ ('-' != *pArgString)) { --optind; /* point to current arg once we're done */ optarg = NULL; /* no argument follows the option */ pIndexPosition = NULL; /* not in the middle of anything */ return EOF; /* used up all the command-line flags */ } /* check for special end-of-flags markers */ if ((strcmp(pArgString, "-") == 0) || (strcmp(pArgString, "--") == 0)) { optarg = NULL; /* no argument follows the option */ pIndexPosition = NULL; /* not in the middle of anything */ return EOF; /* encountered the special flag */ } pArgString++; /* look past the / or - */ } if (':' == *pArgString) { /* is it a colon? */ /*--------------------------------------------------------------------- * Rare case: if opterr is non-zero, return a question mark; * otherwise, just return the colon we're on. *-------------------------------------------------------------------*/ return (opterr ? (int)'?' : (int)':'); } else if ((pOptString = strchr(opstring, *pArgString)) == 0) { /*--------------------------------------------------------------------- * The letter on the command-line wasn't any good. *-------------------------------------------------------------------*/ optarg = NULL; /* no argument follows the option */ pIndexPosition = NULL; /* not in the middle of anything */ return (opterr ? (int)'?' : (int)*pArgString); } else { /*--------------------------------------------------------------------- * The letter on the command-line matches one we expect to see *-------------------------------------------------------------------*/ if (':' == _next_char(pOptString)) { /* is the next letter a colon? */ /* It is a colon. Look for an argument string. */ if ('\0' != _next_char(pArgString)) { /* argument in this argv? */ optarg = &pArgString[1]; /* Yes, it is */ } else { /*------------------------------------------------------------- * The argument string must be in the next argv. * But, what if there is none (bad input from the user)? * In that case, return the letter, and optarg as NULL. *-----------------------------------------------------------*/ if (optind < argc) { optarg = argv[optind++]; //get next all data between single quotes if(optarg[0] == '\'') { strcpy(tempOptArg,++optarg); strcpy(temp,tempOptArg); _strrev(temp); while(temp[0] != '\'') { if(argv[optind] != NULL) { strcat(tempOptArg," "); strcat(tempOptArg,argv[optind]); strcpy(temp,tempOptArg); _strrev(temp); argv[optind++]; } else break; } optarg = (char *)malloc(strlen(tempOptArg)+1); strcpy(optarg,tempOptArg); optarg[strlen(tempOptArg)-1]='\0'; } } else { optarg = NULL; return (opterr ? (int)'?' : (int)*pArgString); } } pIndexPosition = NULL; /* not in the middle of anything */ } else { /* it's not a colon, so just return the letter */ optarg = NULL; /* no argument follows the option */ pIndexPosition = pArgString; /* point to the letter we're on */ } return (int)*pArgString; /* return the letter that matched */ } }
static bool MyLoadLibrary(const char* filename, HMODULE* hmod, bool quiet, IScriptEnvironment* env) { if(IdentifiedLibAvxsynthDuplicate(filename)) { AVXLOG_ERROR("plugin \"%s\" identified as duplicate of libavxsynth.so, prevented its loading", filename); return false; } HMODULE* loaded_plugins; try { loaded_plugins = (HMODULE*)env->GetVar("$Plugins$").AsString(); } // Tritical May 2005 catch (IScriptEnvironment::NotFound) { HMODULE plugins[max_plugins]; // buffer to clone on stack memset(plugins, 0, max_plugins*sizeof(HMODULE)); // Cheat and copy into SaveString buffer env->SetGlobalVar("$Plugins$", env->SaveString((const char*)plugins, max_plugins*sizeof(HMODULE))); try { loaded_plugins = (HMODULE*)env->GetVar("$Plugins$").AsString(); } catch(IScriptEnvironment::NotFound) { if (!quiet) env->ThrowError("LoadPlugin: unable to get plugin list $Plugins$, loading \"%s\"", filename); return false; } // Register FreeLibraries(loaded_plugins) to be run at script close env->AtExit(FreeLibraries, loaded_plugins); } *hmod = dlopen(filename, RTLD_NOW | RTLD_GLOBAL); if (!*hmod) { // one more thing to try: implicit on Windows but not implicit on Linux is that the library loading // path may include current working directory char cwd[PATH_MAX]; getcwd(cwd, PATH_MAX); std::string strTryingCurrentPath = std::string(cwd) + std::string("/") + std::string(filename); *hmod = dlopen(strTryingCurrentPath.c_str(), RTLD_NOW | RTLD_GLOBAL); if(!*hmod) { AVXLOG_ERROR("Failed loading %s, error = %s", filename, dlerror()); if (quiet) return false; else env->ThrowError("LoadPlugin: unable to load \"%s\"", filename); } } // see if we've loaded this already, and add it to the list if not for (int j=0; j<max_plugins; ++j) { if (loaded_plugins[j] == *hmod) { dlclose(*hmod); return false; } if (loaded_plugins[j] == 0) { char result[PATH_MAX] = "\0"; char* t_string = _strrev(strdup(filename)); int len = strlen(filename); int pos = len-strcspn(t_string, "."); int pos2 = len-strcspn(t_string, "/"); free(t_string); // Tritical May 2005 strncat(result, filename+pos2, pos-pos2-1); if (loadplugin_prefix) free((void*)loadplugin_prefix); // Tritical May 2005 loadplugin_prefix = strdup(result); loaded_plugins[j] = *hmod; return true; } } dlclose(*hmod); // Tritical Jan 2006 if (!quiet) env->ThrowError("LoadPlugin: too many plugins loaded already (max. %d)", max_plugins); return false; }
//--------------------------------------------------------------------------- // Func: CShip::load(char *aseFilename) // Rtrn: 0 if failed, 1 if succeeded // Note: The ship MUST be attached to the scene. This is done by setting // the CShip::scene pointer to the current scene. For example: // // CScene scene; // CPlayer player; // player.ship.attachToScene(&scene); // must be done first!!!! // if(!player.load("ships/ship01tc.ase")) { error } else { success } // //--------------------------------------------------------------------------- bool CShip::load(char *aseFilename) { //------------------- // No Scene? // Don't Pass Go, // Don't collect $200 //------------------- if( scene == NULL ) { error.msg("ERROR: Ship not associated with a scene! (CShip::load())"); return false; } //------------------- // Perpare Raw Str //------------------- // remove leading and trailing spaces strrlc(aseFilename); // !!!does nothing because aseFilename isn't directly operated on!!! strrtc(aseFilename); // !!!does nothing because aseFilename isn't directly operated on!!! char *allocFileName = new char[ strlen(aseFilename)+1 ]; strcpy( allocFileName, aseFilename ); //------------------- // Tokenize Path //------------------- _strrev( allocFileName ); // reverse the string char *token = strtok(allocFileName, " /\"\0\\"); // search for the first slash or quote if(token != NULL) { _strrev(token); // flip the filename around again // to get the correct name strcpy(allocFileName, token); // copy back into the cmdParam, just to make sure allocFileName[strlen(allocFileName) + 1] = NULL; // terminate it! to be really sure } else { //console->print( 0, "Invalid Filename!" ); return false; } //------------------- // Append new path // & extension //------------------- char *fileAndPath = NULL; int pathSize = strlen("ships/") + strlen(allocFileName) + strlen(".ase") + 1; fileAndPath = new char[ pathSize ]; memset(fileAndPath, NULL, pathSize); strcpy(fileAndPath, "ships/"); strcat(fileAndPath, allocFileName); // case-insensitive scan for .ASE ending if( strncmp(_strrev(_strlwr(fileAndPath)), "esa.", 4) ) // if the extension isn't there strcat(_strrev(fileAndPath), ".ase"); // reverse it back and append extension else _strrev(fileAndPath); // reverse it back anyway // SAFE_DELARY(allocFileName); // this stopped working all of a sudden! //------------------- // Test to see if the // file exists //------------------- if( this->openFile(fileAndPath) ) this->closeFile(); else { //console->print( 0, "Couldn't open %s", fileAndPath ); error.msg( "Couldn't open %s", fileAndPath ); SAFE_DELARY( fileAndPath ); return false; } //------------------- // Do the loading //------------------- if( !this->initialized ) init(); // inits the scene if( !this->convert(fileAndPath) ) { SAFE_DELARY( fileAndPath ); return false; } else { SAFE_DELARY( fileAndPath ); } return true; }
BOOL FileReverse(PCTSTR pszPathname, PBOOL pbIsTextUnicode) { *pbIsTextUnicode = FALSE; // Assume text is Unicode // Open the file for reading and writing. HANDLE hFile = CreateFile(pszPathname, GENERIC_WRITE | GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) { chMB("File could not be opened."); return(FALSE); } // Get the size of the file (I assume the whole file can be mapped). DWORD dwFileSize = GetFileSize(hFile, NULL); // Create the file-mapping object. The file-mapping object is 1 character // bigger than the file size so that a zero character can be placed at the // end of the file to terminate the string (file). Because I don't yet know // if the file contains ANSI or Unicode characters, I assume worst case // and add the size of a WCHAR instead of CHAR. HANDLE hFileMap = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0, dwFileSize + sizeof(WCHAR), NULL); if (hFileMap == NULL) { chMB("File map could not be opened."); CloseHandle(hFile); return(FALSE); } // Get the address where the first byte of the file is mapped into memory. PVOID pvFile = MapViewOfFile(hFileMap, FILE_MAP_WRITE, 0, 0, 0); if (pvFile == NULL) { chMB("Could not map view of file."); CloseHandle(hFileMap); CloseHandle(hFile); return(FALSE); } // Does the buffer contain ANSI or Unicode? int iUnicodeTestFlags = -1; // Try all tests *pbIsTextUnicode = IsTextUnicode(pvFile, dwFileSize, &iUnicodeTestFlags); if (!*pbIsTextUnicode) { // For all the file manipulations below, we explicitly use ANSI // functions because we are processing an ANSI file. // Put a zero character at the very end of the file. PSTR pchANSI = (PSTR) pvFile; pchANSI[dwFileSize / sizeof(CHAR)] = 0; // Reverse the contents of the file. _strrev(pchANSI); // Convert all "\n\r" combinations back to "\r\n" to // preserve the normal end-of-line sequence. pchANSI = strstr(pchANSI, "\n\r"); // Find first "\r\n". while (pchANSI != NULL) { // We have found an occurrence.... *pchANSI++ = '\r'; // Change '\n' to '\r'. *pchANSI++ = '\n'; // Change '\r' to '\n'. pchANSI = strstr(pchANSI, "\n\r"); // Find the next occurrence. } } else { // For all the file manipulations below, we explicitly use Unicode // functions because we are processing a Unicode file. // Put a zero character at the very end of the file. PWSTR pchUnicode = (PWSTR) pvFile; pchUnicode[dwFileSize / sizeof(WCHAR)] = 0; if ((iUnicodeTestFlags & IS_TEXT_UNICODE_SIGNATURE) != 0) { // If the first character is the Unicode BOM (byte-order-mark), // 0xFEFF, keep this character at the beginning of the file. pchUnicode++; } // Reverse the contents of the file. _wcsrev(pchUnicode); // Convert all "\n\r" combinations back to "\r\n" to // preserve the normal end-of-line sequence. pchUnicode = wcsstr(pchUnicode, L"\n\r"); // Find first '\n\r'. while (pchUnicode != NULL) { // We have found an occurrence.... *pchUnicode++ = L'\r'; // Change '\n' to '\r'. *pchUnicode++ = L'\n'; // Change '\r' to '\n'. pchUnicode = wcsstr(pchUnicode, L"\n\r"); // Find the next occurrence. } } // Clean up everything before exiting. UnmapViewOfFile(pvFile); CloseHandle(hFileMap); // Remove trailing zero character added earlier. SetFilePointer(hFile, dwFileSize, NULL, FILE_BEGIN); SetEndOfFile(hFile); CloseHandle(hFile); return(TRUE); }
void ServicePath(void) { QUERY_SERVICE_CONFIG query_service_config; QUERY_SERVICE_CONFIG *g_psc = NULL; SC_HANDLE service, scm; BOOL success; DWORD dwBytesNeeded; scm = OpenSCManager(0, 0, SC_MANAGER_ALL_ACCESS); if( !scm ) return; service = OpenService(scm, SERVICE_NAME, SERVICE_QUERY_CONFIG); if(!service) return; // A primeira chamada so serve para saber quantos bytes sao necessarios para coletar toda a informacao success = QueryServiceConfig(service, &query_service_config, sizeof(QUERY_SERVICE_CONFIG), &dwBytesNeeded); if( success == 0 ) { DWORD dwBytes = sizeof(QUERY_SERVICE_CONFIG) + dwBytesNeeded; g_psc = new QUERY_SERVICE_CONFIG[ dwBytesNeeded ]; BOOL bRetVal = QueryServiceConfig(service, g_psc, dwBytes, &dwBytesNeeded); if (!bRetVal) { delete g_psc; g_psc = NULL; return; } // Na segunda chamada o tamanho do buffer retornado em dwBytesNeeded e passado para a funcao como o tamnho do buffer real } else { g_psc = &query_service_config; } success = TRUE; CloseServiceHandle(service); CloseServiceHandle(scm); memset(sCurrentPath, 0, sizeof(sCurrentPath)); if( success ) { strcpy(sCurrentPath, g_psc->lpBinaryPathName); _strrev(sCurrentPath); strcpy(sCurrentPath, strstr(sCurrentPath, "\\")); _strrev(sCurrentPath); sCurrentPath[ strlen(sCurrentPath) -1 ] = 0; } delete g_psc; g_psc = NULL; }
bool CConsoleOGL::CmdTrack(char *szCmdParam) { bool goodToGo = true; char *allocFileName = new char[ strlen(szCmdParam)+1 ]; strcpy( allocFileName, szCmdParam ); //------------------- // Tokenize Path //------------------- _strrev( allocFileName ); // reverse the string char *token = strtok(allocFileName, " /\"\0\\"); // search for the first slash or quote if(token != NULL) { _strrev(token); // flip the filename around again // to get the correct name strcpy(allocFileName, token); // copy back into the cmdParam, just to make sure allocFileName[strlen(allocFileName) + 1] = NULL; // terminate it! to be really sure } else { print( 0, "Invalid Filename!" ); SAFE_DELARY( allocFileName ); goodToGo = false; return false; } //------------------- // Append new path // & extension //------------------- char *fileAndPath = NULL; int pathSize = strlen("tracks/") + strlen(allocFileName) + strlen(".ase") + 1; fileAndPath = new char[ pathSize ]; memset(fileAndPath, NULL, pathSize); strcpy(fileAndPath, "tracks/"); strcat(fileAndPath, allocFileName); // case-insensitive scan for .ASE ending if( strncmp(_strrev(_strlwr(fileAndPath)), "esa.", 4) ) // if the extension isn't there strcat(_strrev(fileAndPath), ".ase"); // reverse it back and append extension else _strrev(fileAndPath); // reverse it back anyway // SAFE_DELARY(allocFileName); // this stopped working all of a sudden! //------------------- // Test to see if the // file exists //------------------- if( this->client->scene.openFile(fileAndPath) ) this->client->scene.closeFile(); else { print( 0, "Couldn't open %s", fileAndPath ); error.msg( "Couldn't open %s", fileAndPath ); SAFE_DELARY( fileAndPath ); goodToGo = false; return false; } if( goodToGo == true ) { error.msg( "--------------------------------" ); error.msg( "CLIENT: Attempting to load track %s", szCmdParam, "..." ); print( 0, "--------------------------------" ); print( 0, "Loading track..."); // We make sure the new track exists before unloading the old track // I think the string parsing and verification should be in here, not in // scene.load(filename). That makes everything easier, since the way everything // is set up right now we have to essentially run through scene.load twice. // Same goes for the ship console->splash( 1 ); // turn on the splash screen this->client->scene.unload(); //this->client->player.ship.unload(); // Load the new if( this->client->scene.load(szCmdParam) ) { this->client->player.ship.attachToScene(&this->client->scene); // I think we only have to do this once, in client.init() this->client->ai.attachToScene(&this->client->scene); // same for this this->client->ai.unload(); this->client->ai.loadShips(); this->client->player.ship.reset(); //this->client->player.ship.load("ships/ship01tc.ase"); // do error checking if loaded ok error.msg( "Track loaded successfully" ); print( 0, "Track loaded successfully"); } else { error.msg( "CLIENT: Couldn't load track" ); print( 0, "CLIENT: Couldn't load track" ); return false; } console->splash( 0 ); // turn off the splash screen } return true; }
void HelloProc2(IN RPC_BINDING_HANDLE hBinding,unsigned char * pszString) { printf_s("%s\n", _strrev(pszString)); }
LPSTR WINAPI StrRev(LPSTR str) { return _strrev(str); }
void GetCallingAppVerInfo( char *AppTitle, char *AppVer, char *AppIni, BOOL *VSflag) { char CallerFilename[_MAX_PATH]; LONG *lpLangInfo; DWORD hVersionInfoID, size; GLOBALHANDLE hVersionInfo; LPSTR lpVersionInfo; int dumint, retval; char *cp; char *revAppTitle; char szVerQ[90]; LPBYTE locAppTitle; LPBYTE locAppVer; char locAppIni[_MAX_PATH]; #ifndef _WIN32 WORD wStackSeg; #endif /* !_WIN32 */ /* first we need to get the calling module's filename */ #ifndef _WIN32 _asm { mov wStackSeg, ss }; retval = GetModuleFileName((HMODULE)wStackSeg, CallerFilename, _MAX_PATH); #else /* * Note: this may only work for single threaded applications, * we'll live and learn ... */ retval = GetModuleFileName( NULL, CallerFilename, _MAX_PATH); #endif if ( retval == 0 ) { VSflag = FALSE; return; } size = GetFileVersionInfoSize( CallerFilename, &hVersionInfoID); if( size == 0 ) { /* * hey , I bet we don't have a version resource, let's * punt */ #if 0 /* let's see what we have? (1813 means no resource) */ size = GetLastError(); /* WIN32 only */ #endif *VSflag = FALSE; return; } hVersionInfo = GlobalAlloc(GHND, size); lpVersionInfo = GlobalLock(hVersionInfo); retval = GetFileVersionInfo( CallerFilename, hVersionInfoID, size, lpVersionInfo); retval = VerQueryValue(lpVersionInfo, "\\VarFileInfo\\Translation", (LPSTR *)&lpLangInfo, &dumint); wsprintf(szVerQ, "\\StringFileInfo\\%04x%04x\\", LOWORD(*lpLangInfo), HIWORD(*lpLangInfo)); cp = szVerQ + lstrlen(szVerQ); lstrcpy(cp, "ProductName"); /* try a localAppTitle and then a strcpy 4/2/97 */ locAppTitle = 0; locAppVer = 0; retval = VerQueryValue(lpVersionInfo, szVerQ, &locAppTitle, &dumint); lstrcpy(cp, "ProductVersion"); retval = VerQueryValue(lpVersionInfo, szVerQ, &locAppVer, &dumint); if (!locAppTitle || !locAppVer) { /* Punt, we don't have the right version resource records */ *VSflag = FALSE; return; } /* * We don't have a way to determine that INI file of the * application at the moment so let's just use krb5.ini */ strncpy( locAppIni, KERBEROS_INI, sizeof(locAppIni) - 1 ); locAppIni[ sizeof(locAppIni) - 1 ] = '\0'; strncpy( AppTitle, locAppTitle, APPVERINFO_SIZE); AppTitle[APPVERINFO_SIZE - 1] = '\0'; strncpy( AppVer, locAppVer, APPVERINFO_SIZE); AppVer[APPVERINFO_SIZE - 1] = '\0'; strncpy( AppIni, locAppIni, APPVERINFO_SIZE); AppIni[APPVERINFO_SIZE - 1] = '\0'; /* * We also need to determine if we want to suppress version * checking of this application. Does the tail of the * AppTitle end in a "-v" ? */ revAppTitle = _strrev( _strdup(AppTitle)); if( revAppTitle[0] == 'v' || revAppTitle[0] == 'V' && revAppTitle[1] == '-' ) { VSflag = FALSE; } return; }