char* DLLCALL prep_dir(const char* base, char* path, size_t buflen) { #ifdef __unix__ char *p; #endif char str[MAX_PATH+1]; char abspath[MAX_PATH+1]; char ch; if(!path[0]) return(path); if(path[0]!='\\' && path[0]!='/' && path[1]!=':') { /* Relative directory */ ch=*lastchar(base); if(ch=='\\' || ch=='/') sprintf(str,"%s%s",base,path); else sprintf(str,"%s%c%s",base,PATH_DELIM,path); } else strcpy(str,path); #ifdef __unix__ /* Change backslashes to forward slashes on Unix */ for(p=str;*p;p++) if(*p=='\\') *p='/'; #endif backslashcolon(str); strcat(str,"."); /* Change C: to C:. and C:\SBBS\ to C:\SBBS\. */ FULLPATH(abspath,str,buflen); /* Change C:\SBBS\NODE1\..\EXEC to C:\SBBS\EXEC */ backslash(abspath); sprintf(path,"%.*s",(int)(buflen-1),abspath); return(path); }
int MIValue::ParseString(String const &s, int i) { Clear(); type = MIString; if(!expect("ParseString", '"', i, s)) return s.GetCount(); i++; while(s[i]) { // verbatim if escaped if(s[i] == '\\') string.Cat(backslash(s, i)); else if(s[i] == '"') { i++; break; } else string.Cat(s[i]); i++; } if(!expect("ParseString", '"', i-1, s)) return s.GetCount(); return i; }
bool toSaveMap(const QString &file, std::map<QString, QString> &pairs) { QString data; { // qt4 QRegExp newline(QString::fromLatin1("\n")); // qt4 QRegExp backslash(QString::fromLatin1("\\")); QString newline("\n"); QString backslash("\\"); for (std::map<QString, QString>::iterator i = pairs.begin(); i != pairs.end(); i++) { QString str = (*i).first; str.append(QString::fromLatin1("=")); str.replace(backslash, QString::fromLatin1("\\\\")); str.replace(newline, QString::fromLatin1("\\n")); QString line = (*i).second; line.replace(backslash, QString::fromLatin1("\\\\")); line.replace(newline, QString::fromLatin1("\\n")); str += line.toUtf8(); str += QString::fromLatin1("\n"); data += str; } } return Utils::toWriteFile(file, data); }
//-------------------------------------- S32 Platform::getFileSize(const char *pFilePath) { if (!pFilePath || !*pFilePath) return -1; TempAlloc< TCHAR > buf( dStrlen( pFilePath ) + 1 ); #ifdef UNICODE convertUTF8toUTF16( pFilePath, buf, buf.size ); #else dStrcpy( buf, pFilePath ); #endif backslash( buf ); // Get file info WIN32_FIND_DATA findData; HANDLE handle = FindFirstFile(buf, &findData); if(handle == INVALID_HANDLE_VALUE) return -1; FindClose(handle); // if the file is a Directory, Offline, System or Temporary then FALSE if (findData.dwFileAttributes & (FILE_ATTRIBUTE_DIRECTORY| FILE_ATTRIBUTE_OFFLINE| FILE_ATTRIBUTE_SYSTEM| FILE_ATTRIBUTE_TEMPORARY) ) return -1; // must be a real file then return findData.nFileSizeLow; }
int MIValue::ParseAngle(String const &s, int i) { Clear(); type = MIString; int aCount = 0; if(!expect("ParseAngle", '<', i, s)) return s.GetCount(); string = "<"; aCount++; i++; while(s[i]) { // verbatim if escaped if(s[i] == '\\') string.Cat(backslash(s, i)); else if(s[i] == '>' && !--aCount) { i++; break; } else { string.Cat(s[i]); if(s[i] == '<') aCount++; } i++; } if(!expect("ParseAngle", '>', i-1, s)) return s.GetCount(); string.Cat('>'); return i; }
static char * get_path (Camera *camera, const char *folder, const char *filename) { char *path; char *xfolder, *xfilename; xfolder = strdup_to_latin1 (folder); if (!xfolder) return NULL; xfilename = _convert_for_device (camera, filename); if (!xfilename) { free (xfolder); return NULL; } path = malloc(strlen(xfolder)+1+strlen(xfilename)+1); if (!path) { free (xfolder); return NULL; } strcpy (path, xfolder); strcat (path, "/"); backslash (path); strcat (path, xfilename); free (xfolder); free (xfilename); return path; }
bool Platform::getFileTimes(const char *filePath, FileTime *createTime, FileTime *modifyTime) { WIN32_FIND_DATA findData; TempAlloc< TCHAR > fp( dStrlen( filePath ) + 1 ); #ifdef UNICODE convertUTF8toUTF16( filePath, fp, fp.size ); #else dStrcpy( fp, filePath ); #endif backslash( fp ); HANDLE h = FindFirstFile(fp, &findData); if(h == INVALID_HANDLE_VALUE) return false; if(createTime) { createTime->v1 = findData.ftCreationTime.dwLowDateTime; createTime->v2 = findData.ftCreationTime.dwHighDateTime; } if(modifyTime) { modifyTime->v1 = findData.ftLastWriteTime.dwLowDateTime; modifyTime->v2 = findData.ftLastWriteTime.dwHighDateTime; } FindClose(h); return true; }
long DLLCALL getdirsize(const char* path, BOOL include_subdirs, BOOL subdir_only) { char match[MAX_PATH+1]; glob_t g; unsigned gi; long count=0; if(!isdir(path)) return -1; SAFECOPY(match,path); backslash(match); strcat(match,ALLFILES); glob(match,GLOB_MARK,NULL,&g); if(include_subdirs && !subdir_only) count=g.gl_pathc; else for(gi=0;gi<g.gl_pathc;gi++) { if(*lastchar(g.gl_pathv[gi])=='/') { if(!include_subdirs) continue; } else if(subdir_only) continue; count++; } globfree(&g); return(count); }
static void genseq(STR *s) { char *ep; wchar_t wc; size_t clen; if (s->which == STRING1) errx(1, "sequences only valid in string2"); if (*s->str == '\\') s->lastch = backslash(s, NULL); else { clen = mbrtowc(&wc, s->str, MB_LEN_MAX, NULL); if (clen == (size_t)-1 || clen == (size_t)-2) errc(1, EILSEQ, NULL); s->lastch = wc; s->str += clen; } if (*s->str != '*') errx(1, "misplaced sequence asterisk"); switch (*++s->str) { case '\\': s->cnt = backslash(s, NULL); break; case ']': s->cnt = 0; ++s->str; break; default: if (isdigit((u_char)*s->str)) { s->cnt = strtol(s->str, &ep, 0); if (*ep == ']') { s->str = ep + 1; break; } } errx(1, "illegal sequence count"); /* NOTREACHED */ } s->state = s->cnt ? SEQUENCE : INFINITE; }
int next(STR *s) { int ch; switch (s->state) { case EOS: return (0); case INFINITE: return (1); case NORMAL: switch (ch = (u_char)*s->str) { case '\0': s->state = EOS; return (0); case '\\': s->lastch = backslash(s); break; case '[': if (bracket(s)) return (next(s)); /* FALLTHROUGH */ default: ++s->str; s->lastch = ch; break; } /* We can start a range at any time. */ if (s->str[0] == '-' && genrange(s)) return (next(s)); return (1); case RANGE: if (s->cnt-- == 0) { s->state = NORMAL; return (next(s)); } ++s->lastch; return (1); case SEQUENCE: if (s->cnt-- == 0) { s->state = NORMAL; return (next(s)); } return (1); case SET: if ((s->lastch = s->set[s->cnt++]) == OOBCH) { s->state = NORMAL; return (next(s)); } return (1); default: return (0); } /* NOTREACHED */ }
bool dFileRename(const char *oldName, const char *newName) { AssertFatal( oldName != NULL && newName != NULL, "dFileRename - NULL file name" ); TempAlloc< TCHAR > oldf( dStrlen( oldName ) + 1 ); TempAlloc< TCHAR > newf( dStrlen( newName ) + 1 ); #ifdef UNICODE convertUTF8toUTF16( oldName, oldf, oldf.size ); convertUTF8toUTF16( newName, newf, newf.size ); #else dStrcpy(oldf, oldName); dStrcpy(newf, newName); #endif backslash(oldf); backslash(newf); return MoveFile( oldf, newf ); }
int backslash(int c) { if(c!='\\'){ if(c=='\n') error("newline in character or string constant"); return c; } c=getc(); if('0'<=c && c<='7'){ int n; n=c-'0'; c=getc(); if(n==0 && (c=='x' || c=='X')){ c=getc(); if(!ishex(c)){ ungetc(); return 0; } n=tohex(c); c=getc(); if(!ishex(c)){ ungetc(); return n; } n=16*n+tohex(c); return n; } if(c<'0' || '7'<c){ ungetc(); return n; } n=8*n+c-'0'; c=getc(); if(c<'0' || '7'<c){ ungetc(); return n; } n=8*n+c-'0'; return n; } if(c=='b') return '\b'; if(c=='f') return '\f'; if(c=='n') return '\n'; if(c=='r') return '\r'; if(c=='t') return '\t'; if(c=='\n') return backslash(getc()); return c; }
static int genrange(STR *s, int was_octal) { int stopval, octal; char *savestart; int n, cnt, *p; size_t clen; wchar_t wc; octal = 0; savestart = s->str; if (*++s->str == '\\') stopval = backslash(s, &octal); else { clen = mbrtowc(&wc, s->str, MB_LEN_MAX, NULL); if (clen == (size_t)-1 || clen == (size_t)-2) errc(1, EILSEQ, NULL); stopval = wc; s->str += clen; } /* * XXX Characters are not ordered according to collating sequence in * multibyte locales. */ if (octal || was_octal || MB_CUR_MAX > 1) { if (stopval < s->lastch) { s->str = savestart; return (0); } s->cnt = stopval - s->lastch + 1; s->state = RANGE; --s->lastch; return (1); } if (charcoll((const void *)&stopval, (const void *)&(s->lastch)) < 0) { s->str = savestart; return (0); } if ((s->set = p = malloc((NCHARS_SB + 1) * sizeof(int))) == NULL) err(1, "genrange() malloc"); for (cnt = 0; cnt < NCHARS_SB; cnt++) if (charcoll((const void *)&cnt, (const void *)&(s->lastch)) >= 0 && charcoll((const void *)&cnt, (const void *)&stopval) <= 0) *p++ = cnt; *p = OOBCH; n = p - s->set; s->cnt = 0; s->state = SET; if (n > 1) mergesort(s->set, n, sizeof(*(s->set)), charcoll); return (1); }
bool toSQL::saveSQL(const QString &filename, bool all) { allocCheck(); QString data; QRegExp backslash(QString::fromLatin1("\\")); QRegExp newline(QString::fromLatin1("\n")); for (sqlMap::iterator i = Definitions->begin(); i != Definitions->end(); i++) { QString str; definition &def = (*i).second; QString name = (*i).first; if (def.Modified || all) { QString line = name; line += "="; QString t = def.Description; t.replace(backslash, QString::fromLatin1("\\\\")); t.replace(newline, QString::fromLatin1("\\n")); line += t; str = line; str += "\n"; } for (std::list<version>::iterator j = def.Versions.begin(); j != def.Versions.end(); j++) { version &ver = (*j); if (ver.Modified || all) { QString line = name; line += "["; line += ver.Version; line += "]["; line += ver.Provider; line += "]="; QString t(ver.SQL); t.replace(backslash, QString::fromLatin1("\\\\")); t.replace(newline, QString::fromLatin1("\\n")); line += t; str += line; str += "\n"; } } data += str; } // TODO: data shouldn't be a QString // if we use QByteArray, there would be no need to re-encode // save as UTF8 encoded file return Utils::toWriteFile(filename, data.toUtf8()); }
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { /* ***************** */ /* Declare variables */ /* ***************** */ double *r, *rx, *y, *A, *b; /*mxGetPr, mxGetPr, mxGetPr, rx, r*/ mwSize i, j, J, Jstart; /*p, 0, 0, Jstart, 0. Dependent on the size of other mwSize variables.*/ mwSize p, pp, m; /*mxGetN, mxGetM*/ /* ********************************************** */ /* Determine input sizes and perform error checks */ /* ********************************************** */ if (nrhs<2 || nrhs>2) mexErrMsgTxt("Two arguments must be passed"); if (nlhs>1) mexErrMsgTxt("ArrayInv produces only one output"); if (!mxIsDouble(prhs[0]) || !mxIsDouble(prhs[1])) mexErrMsgTxt("Input arguments of inproper type"); if (mxIsSparse(prhs[0]) || mxIsSparse(prhs[1])) mexErrMsgTxt("Input arguments of inproper type"); m=mxGetM(prhs[0]); p=mxGetN(prhs[0]); if (mxGetNumberOfElements(prhs[1])!=m*p*p) mexErrMsgTxt("Inputs are not compatible"); pp=p*p; r=mxGetPr(prhs[0]); rx=mxGetPr(prhs[1]); plhs[0]=mxCreateDoubleMatrix(m,p,mxREAL); y=mxGetPr(plhs[0]); A=mxCalloc(pp,sizeof(double)); b=mxCalloc(p,sizeof(double)); Jstart=0; for(i=0; i<m; i++, Jstart++) { for (j=0, J=Jstart; j<p; j++, J+=m) { b[j]=r[J]; A[j]=rx[J]; } for (;j<pp; j++, J+=m) A[j]=rx[J]; backslash(A,b,b,p,1); for (j=0, J=Jstart; j<p; j++, J+=m) y[J]=b[j]; } mxFree(A); mxFree(b); }
char *complete_path(char *dest, char *path, char *filename) { if(path != NULL) { strcpy(dest, path); backslash(dest); } else dest[0]=0; if(filename != NULL) strcat(dest, filename); fexistcase(dest); /* TODO: Hack: Fixes upr/lwr case fname */ return(dest); }
int main() { int i; char *s; for (s = "bfnrtvx"; *s; s++) printf("%c = 0x%x\n", *s, backslash(*s)); f(); g(); h(); for (i = 0x1000000; i&0x7000000; i += 0x1000000) big(i); limit(); return 0; }
static void genseq(STR *s) { char *ep; if (s->which == STRING1) errx(1, "sequences only valid in string2"); if (*s->str == '\\') s->lastch = backslash(s); else s->lastch = *s->str++; if (*s->str != '*') errx(1, "misplaced sequence asterisk"); switch (*++s->str) { case '\\': s->cnt = backslash(s); break; case ']': s->cnt = 0; ++s->str; break; default: if (isdigit((u_char)*s->str)) { s->cnt = strtol(s->str, &ep, 0); if (*ep == ']') { s->str = ep + 1; break; } } errx(1, "illegal sequence count"); /* NOTREACHED */ } s->state = s->cnt ? SEQUENCE : INFINITE; }
static void genequiv(STR *s) { int i, p, pri; char src[2], dst[3]; size_t clen; wchar_t wc; if (*s->str == '\\') { s->equiv[0] = backslash(s, NULL); if (*s->str != '=') errx(1, "misplaced equivalence equals sign"); s->str += 2; } else { clen = mbrtowc(&wc, s->str, MB_LEN_MAX, NULL); if (clen == (size_t)-1 || clen == (size_t)-2 || clen == 0) errc(1, EILSEQ, NULL); s->equiv[0] = wc; if (s->str[clen] != '=') errx(1, "misplaced equivalence equals sign"); s->str += clen + 2; } /* * Calculate the set of all characters in the same equivalence class * as the specified character (they will have the same primary * collation weights). * XXX Knows too much about how strxfrm() is implemented. Assumes * it fills the string with primary collation weight bytes. Only one- * to-one mappings are supported. * XXX Equivalence classes not supported in multibyte locales. */ src[0] = (char)s->equiv[0]; src[1] = '\0'; if (MB_CUR_MAX == 1 && strxfrm(dst, src, sizeof(dst)) == 1) { pri = (unsigned char)*dst; for (p = 1, i = 1; i < NCHARS_SB; i++) { *src = i; if (strxfrm(dst, src, sizeof(dst)) == 1 && pri && pri == (unsigned char)*dst) s->equiv[p++] = i; } s->equiv[p] = OOBCH; } s->cnt = 0; s->state = SET; s->set = s->equiv; }
bool Platform::setCurrentDirectory(StringTableEntry newDir) { if (Platform::getWebDeployment()) return true; TempAlloc< TCHAR > buf( dStrlen( newDir ) + 2 ); #ifdef UNICODE convertUTF8toUTF16( newDir, buf, buf.size - 1 ); #else dStrcpy( buf, newDir ); #endif backslash( buf ); return SetCurrentDirectory( buf ); }
static int genrange(STR *s) { int stopval; char *savestart; savestart = s->str; stopval = *++s->str == '\\' ? backslash(s) : (u_char)*s->str++; if (stopval < (u_char)s->lastch) { s->str = savestart; return (0); } s->cnt = stopval - s->lastch + 1; s->state = RANGE; --s->lastch; return (1); }
/* * Skip to next option in the string */ static char * opt(char **p) { char *cp = *p; char *dp = cp; char *s = cp; top: while (*cp && *cp != ';') { if (*cp == '"') { /* * Skip past string */ for (cp++; *cp && *cp != '"'; cp++) if (*cp == '\\') *dp++ = backslash(&cp); else *dp++ = *cp; if (*cp) cp++; } else { *dp++ = *cp++; } } /* * Skip past any remaining ';'s */ while (*cp == ';') cp++; /* * If we have a zero length string * and there are more fields, then * parse the next one. This allows * sequences of empty fields. */ if (*cp && dp == s) goto top; *dp = '\0'; *p = cp; return s; }
sequence<T> inv(const sequence<T>& X, int t1, int t2) { int YL = t2-t1+1; // Convolution matrix mat<T> CX = convmat(X,YL); // Impulse function int DL = CX.rows(); vec<T> D = zeros(DL); int i = -t1-X.t1(); if(i > 0 && i < DL) D(i) = 1; // Inverse sequence vec<T> Y = backslash( CX, D ); return sequence<T>( Y, t1 ); }
//----------------------------------------------------------------------------- bool dFileDelete(const char * name) { AssertFatal( name != NULL, "dFileDelete - NULL file name" ); TempAlloc< TCHAR > buf( dStrlen( name ) + 1 ); #ifdef UNICODE convertUTF8toUTF16( name, buf, buf.size ); #else dStrcpy( buf, name ); #endif backslash( buf ); if( Platform::isFile( name ) ) return DeleteFile( buf ); else return RemoveDirectory( buf ); }
vec CoSaMP(const mat & Phi, const vec & u, int K, int max_iter, double tol1, int D){ assert(K<= 2*D); assert(K>=1); assert(Phi.rows() == Phi.cols()); assert(Phi.rows() == D); assert(u.size() == D); vec Sest = zeros(D); vec utrue = Sest; vec v = u; int t=1; ivec T2; while (t<max_iter){ ivec z = sort_index(fabs(Phi.transpose() * v)); z = reverse(z); ivec Omega = head(z,2*K); ivec T=sort_union(Omega,T2); mat phit=get_cols(Phi, T); vec b; bool ret = backslash(phit, u, b); assert(ret); ret = false;//avoid warning b= fabs(b); ivec z3 = sort_index(b); z3 = reverse(z3); Sest=zeros(D); for (int i=0; i< K; i++) set_val(Sest, z3[i], b[z3[i]]); ivec z2 = sort_index(fabs(Sest)); z2 = reverse(z2); T2 = head(z2,K-1); v=u-Phi*Sest; double n2 = max(fabs(v)); if (n2 < tol1) break; t++; } return Sest; }
int main(void) { int c; const int done = 0; /* just a dummy for the infinite loop */ int status = 1; /* 1 at line begin, 2 for failure, 0 otherwise */ while(!done) { while(isspace(c = getch())) { putchar(c); if(c == '\n') status = 1; } if(c == '#' && status == 1) status = preproc(); else if(c == '\\') status = backslash(); else if(c == '/') status = comment(); else if(c == '\"') status = literal(); else if(c == EOF) return 0; else if(!isalpha(c) && c != '_') { putchar(c); status = 0; } else { ungetch(c); status = readword(); } if(status == 2) return 1; } return 0; } /* end main() */
static void genequiv(STR *s) { int i, p, pri; char src[2], dst[3]; if (*s->str == '\\') { s->equiv[0] = backslash(s); if (*s->str != '=') errx(1, "misplaced equivalence equals sign"); s->str += 2; } else { s->equiv[0] = s->str[0]; if (s->str[1] != '=') errx(1, "misplaced equivalence equals sign"); s->str += 3; } /* * Calculate the set of all characters in the same equivalence class * as the specified character (they will have the same primary * collation weights). * XXX Knows too much about how strxfrm() is implemented. Assumes * it fills the string with primary collation weight bytes. Only one- * to-one mappings are supported. */ src[0] = s->equiv[0]; src[1] = '\0'; if (strxfrm(dst, src, sizeof(dst)) == 1) { pri = (unsigned char)*dst; for (p = 1, i = 1; i < NCHARS; i++) { *src = i; if (strxfrm(dst, src, sizeof(dst)) == 1 && pri && pri == (unsigned char)*dst) s->equiv[p++] = i; } s->equiv[p] = OOBCH; } s->cnt = 0; s->state = SET; s->set = s->equiv; }
/* * comment: Prints comments without changes. */ int comment(void) { int c; int after_star = 0; putchar('/'); if((c = getch()) == '*') { /* comment begin */ putchar(c); c = getch(); while(c != EOF) { if(c == '\\') { backslash(); after_star = 0; } else if(c == '*') { after_star = 1; putchar(c); } else if(c == '/' && after_star) { putchar(c); return 0; } else { after_star = 0; putchar(c); } c = getch(); } if(c == EOF) return EOF; putchar(c); return 0; } else { ungetch(c); return 0; } } /* end comment() */
/* * literal: Prints string literals without changes. */ int literal(void) { int c; putchar('\"'); c = getch(); while(c != '\"' && c != EOF) { if(c == '\\') backslash(); else putchar(c); c = getch(); } if(c == EOF) return EOF; putchar(c); return 0; } /* end literal() */
//-------------------------------------- bool Platform::isDirectory(const char *pDirPath) { if (!pDirPath || !*pDirPath) return false; TempAlloc< TCHAR > buf( dStrlen( pDirPath ) + 1 ); #ifdef UNICODE convertUTF8toUTF16( pDirPath, buf, buf.size ); #else dStrcpy( buf, pDirPath ); #endif backslash( buf ); // Get file info WIN32_FIND_DATA findData; HANDLE handle = FindFirstFile(buf, &findData); // [neo, 5/15/2007] // This check was AFTER FindClose for some reason - this is most probably the // original intent. if(handle == INVALID_HANDLE_VALUE) return false; FindClose(handle); // if the file is a Directory, Offline, System or Temporary then FALSE if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { // make sure it's a valid game directory if (findData.dwFileAttributes & (FILE_ATTRIBUTE_OFFLINE|FILE_ATTRIBUTE_SYSTEM) ) return false; // must be a directory return true; } return false; }