void LocalGlob(LineListPtr fileList, char *pattern) { string pattern2; string cmd; longstring gfile; FILE *volatile fp; volatile Sig_t si, sp; STRNCPY(pattern2, pattern); /* Don't nuke the original. */ /* Pre-process for ~'s. */ ExpandTilde(pattern2, sizeof(pattern2)); /* Initialize the list. */ fileList->first = fileList->last = NULL; if (GLOBCHARSINSTR(pattern2)) { /* Do it the easy way and have the shell do the dirty * work for us. */ sprintf(cmd, "%s -d %s", LS, pattern2); fp = NULL; if (setjmp(gLocalGlobJmp) == 0) { fp = POpen(cmd, "r", 0); if (fp == NULL) { DebugMsg("Could not lglob: %s\n", cmd); return; } sp = SIGNAL(SIGPIPE, LGlobHandler); si = SIGNAL(SIGINT, LGlobHandler); while (FGets(gfile, sizeof(gfile), (FILE *) fp) != NULL) { TraceMsg("Lglob [%s]\n", gfile); AddLine(fileList, gfile); } } (void) SIGNAL(SIGPIPE, SIG_IGN); if (fp != NULL) (void) PClose((FILE *) fp); (void) SIGNAL(SIGPIPE, sp); (void) SIGNAL(SIGINT, si); } else { /* Or, if there were no globbing characters in 'pattern', then the * pattern is really just a single pathname. */ AddLine(fileList, pattern2); } } /* LocalGlob */
Bool TIDY_CALL tidyFileExists( ctmbstr filename ) { ctmbstr fname = (tmbstr) ExpandTilde( filename ); #ifndef NO_ACCESS_SUPPORT Bool exists = ( access(fname, 0) == 0 ); #else Bool exists; /* at present */ FILE* fin = fopen(fname, "r"); if (fin != NULL) fclose(fin); exists = ( fin != NULL ); #endif if ( fname != filename ) MemFree( (tmbstr) fname ); return exists; }
const char* FBDirectory::InterpTilde(const char* path) { static char realpath[MAXPATHLEN+1]; const char* beg = strrchr(path, '~'); boolean validTilde = beg != nil && (beg == path || *(beg-1) == '/'); if (validTilde) { const char* end = strchr(beg, '/'); int length = (end == nil) ? strlen(beg) : end - beg; const char* expandedTilde = ExpandTilde(beg, length); if (expandedTilde == nil) { validTilde = false; } else { strcpy(realpath, expandedTilde); if (end != nil) { strcat(realpath, end); } } } return validTilde ? realpath : path; }
static void fileCB(Widget widget, WindowInfo *window, Atom *sel, Atom *type, char *value, int *length, int *format) { char nameText[MAXPATHLEN], includeName[MAXPATHLEN]; char filename[MAXPATHLEN], pathname[MAXPATHLEN]; char *inPtr, *outPtr; #ifdef VMS #ifndef __DECC static char includeDir[] = "sys$library:"; #else static char includeDir[] = "decc$library_include:"; #endif #else static char includeDir[] = "/usr/include/"; #endif /* VMS */ /* get the string, or skip if we can't get the selection data, or it's obviously not a file name */ if (*type == XT_CONVERT_FAIL || value == NULL) { XBell(TheDisplay, 0); return; } if (*length > MAXPATHLEN || *length == 0) { XBell(TheDisplay, 0); XtFree(value); return; } /* should be of type text??? */ if (*format != 8) { fprintf(stderr, "NEdit: Can't handle non 8-bit text\n"); XBell(TheDisplay, 0); XtFree(value); return; } strncpy(nameText, value, *length); XtFree(value); nameText[*length] = '\0'; /* extract name from #include syntax */ if (sscanf(nameText, "#include \"%[^\"]\"", includeName) == 1) strcpy(nameText, includeName); else if (sscanf(nameText, "#include <%[^<>]>", includeName) == 1) sprintf(nameText, "%s%s", includeDir, includeName); /* strip whitespace from name */ for (inPtr=nameText, outPtr=nameText; *inPtr!='\0'; inPtr++) if (*inPtr != ' ' && *inPtr != '\t' && *inPtr != '\n') *outPtr++ = *inPtr; *outPtr = '\0'; #ifdef VMS /* If path name is relative, make it refer to current window's directory */ if ((strchr(nameText, ':') == NULL) && (strlen(nameText) > 1) && !((nameText[0] == '[') && (nameText[1] != '-') && (nameText[1] != '.'))) { strcpy(filename, window->path); strcat(filename, nameText); strcpy(nameText, filename); } #else /* Process ~ characters in name */ ExpandTilde(nameText); /* If path name is relative, make it refer to current window's directory */ if (nameText[0] != '/') { strcpy(filename, window->path); strcat(filename, nameText); strcpy(nameText, filename); } #endif /* Expand wildcards in file name. Some older systems don't have the glob subroutine for expanding file names, in these cases, either don't expand names, or try to use the Motif internal parsing routine _XmOSGetDirEntries, which is not guranteed to be available, but in practice is there and does work. */ #if defined(DONT_HAVE_GLOB) || defined(VMS) /* Open the file */ if (ParseFilename(nameText, filename, pathname) != 0) { XBell(TheDisplay, 0); return; } EditExistingFile(window, filename, pathname, 0, NULL, False, NULL, GetPrefOpenInTab(), False); #elif defined(USE_MOTIF_GLOB) { char **nameList = NULL; int i, nFiles = 0, maxFiles = 30; if (ParseFilename(nameText, filename, pathname) != 0) { XBell(TheDisplay, 0); return; } _XmOSGetDirEntries(pathname, filename, XmFILE_ANY_TYPE, False, True, &nameList, &nFiles, &maxFiles); for (i=0; i<nFiles; i++) { if (ParseFilename(nameList[i], filename, pathname) != 0) { XBell(TheDisplay, 0); } else { EditExistingFile(window, filename, pathname, 0, NULL, False, NULL, GetPrefOpenInTab(), False); } } for (i=0; i<nFiles; i++) { XtFree(nameList[i]); } XtFree((char *)nameList); } #else { glob_t globbuf; int i; glob(nameText, GLOB_NOCHECK, NULL, &globbuf); for (i=0; i<(int)globbuf.gl_pathc; i++) { if (ParseFilename(globbuf.gl_pathv[i], filename, pathname) != 0) XBell(TheDisplay, 0); else EditExistingFile(GetPrefOpenInTab()? window : NULL, filename, pathname, 0, NULL, False, NULL, GetPrefOpenInTab(), False); } globfree(&globbuf); } #endif CheckCloseDim(); }
/* open the file and parse its contents */ int ParseConfigFileEnc( TidyDocImpl* doc, ctmbstr file, ctmbstr charenc ) { uint opterrs = doc->optionErrors; tmbstr fname = (tmbstr) ExpandTilde( file ); TidyConfigImpl* cfg = &doc->config; FILE* fin = fopen( fname, "r" ); int enc = CharEncodingId( charenc ); if ( fin == NULL || enc < 0 ) { FileError( doc, fname, TidyConfig ); return -1; } else { tchar c; cfg->cfgIn = FileInput( doc, fin, enc ); c = FirstChar( cfg ); for ( c = SkipWhite(cfg); c != EndOfStream; c = NextProperty(cfg) ) { uint ix = 0; tmbchar name[ TIDY_MAX_NAME ] = {0}; /* // or # start a comment */ if ( c == '/' || c == '#' ) continue; while ( ix < sizeof(name)-1 && c != '\n' && c != EndOfStream && c != ':' ) { name[ ix++ ] = (tmbchar) c; /* Option names all ASCII */ c = AdvanceChar( cfg ); } if ( c == ':' ) { const TidyOptionImpl* option = lookupOption( name ); c = AdvanceChar( cfg ); if ( option ) option->parser( doc, option ); else { if (NULL != doc->pOptCallback) { TidyConfigImpl* cfg = &doc->config; tmbchar buf[8192]; uint i = 0; tchar delim = 0; Bool waswhite = yes; tchar c = SkipWhite( cfg ); if ( c == '"' || c == '\'' ) { delim = c; c = AdvanceChar( cfg ); } while ( i < sizeof(buf)-2 && c != EndOfStream && c != '\r' && c != '\n' ) { if ( delim && c == delim ) break; if ( IsWhite(c) ) { if ( waswhite ) { c = AdvanceChar( cfg ); continue; } c = ' '; } else waswhite = no; buf[i++] = (tmbchar) c; c = AdvanceChar( cfg ); } buf[i] = '\0'; if (no == (*doc->pOptCallback)( name, buf )) ReportUnknownOption( doc, name ); } else ReportUnknownOption( doc, name ); } } } fclose( fin ); MemFree( (void *)cfg->cfgIn->source.sourceData ); /* fix for bug #810259 */ freeStreamIn( cfg->cfgIn ); cfg->cfgIn = NULL; } if ( fname != (tmbstr) file ) MemFree( fname ); AdjustConfig( doc ); /* any new config errors? If so, return warning status. */ return (doc->optionErrors > opterrs ? 1 : 0); }