bool Parse(const QByteArray& rss, Visitor& visitor) { Dbg("Parsing rss feed in %1% bytes", rss.size()); QXmlStreamReader xml(rss); if (!xml.readNextStartElement() || xml.name() != RSS::FEED) { Dbg("Invalid rss content"); return false; } while (xml.readNextStartElement()) { const QStringRef tag = xml.name(); if (tag == RSS::ENTRY) { const Entry entry = ParseEntry(xml); visitor.OnEntry(entry); } else { xml.skipCurrentElement(); } } return !xml.error(); }
void NumberEntry::SetFormat(const char *format) { if (m_items != NULL) delete[] m_items; m_index = 0; m_count = CountEntries(format); m_items = new HOLDER[m_count]; for (int i = 0; i < m_count; i++) format = ParseEntry(format, m_items + i); }
/////////////////////////////////////////////////////////////////////// /// Function: XosWebRtcClientConnection:: /// /// Author: $author$ /// Date: 4/1/2012 /////////////////////////////////////////////////////////////////////// void XosWebRtcClientConnection::OnRead(talk_base::AsyncSocket* socket) { LOG(INFO) << __FUNCTION__; size_t content_length = 0; if (ReadIntoBuffer(socket, &control_data_, &content_length)) { size_t peer_id = 0, eoh = 0; bool ok = ParseServerResponse(control_data_, content_length, &peer_id, &eoh); if (ok) { if (my_id_ == -1) { // First response. Let's store our server assigned ID. ASSERT(state_ == SIGNING_IN); my_id_ = peer_id; ASSERT(my_id_ != -1); // The body of the response will be a list of already connected peers. if (content_length) { size_t pos = eoh + 4; while (pos < control_data_.size()) { size_t eol = control_data_.find('\n', pos); if (eol == std::string::npos) break; int id = 0; std::string name; bool connected; if (ParseEntry(control_data_.substr(pos, eol - pos), &name, &id, &connected) && id != my_id_) { peers_[id] = name; callback_->OnPeerConnected(id, name); } pos = eol + 1; } } ASSERT(is_connected()); callback_->OnSignedIn(); } else if (state_ == SIGNING_OUT) { Close(); callback_->OnDisconnected(); } else if (state_ == SIGNING_OUT_WAITING) { SignOut(); } } control_data_.clear(); if (state_ == SIGNING_IN) { ASSERT(hanging_get_->GetState() == talk_base::Socket::CS_CLOSED); state_ = CONNECTED; hanging_get_->Connect(server_address_); } } }
/* ============ sdGUIDFile::CheckForUpdates ============ */ void sdGUIDFile::CheckForUpdates( bool removeOldEntries ) { idFile* file = fileSystem->OpenFileRead( guidFileName ); if ( !file ) { return; } bool changed = file->Timestamp() != fileTimestamp; fileTimestamp = file->Timestamp(); fileSystem->CloseFile( file ); if ( !changed ) { return; } ClearGUIDStates(); idLexer src( LEXFL_NOSTRINGCONCAT | LEXFL_NOSTRINGESCAPECHARS | LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_ALLOWBACKSLASHSTRINGCONCAT | LEXFL_NOFATALERRORS ); src.LoadFile( guidFileName ); if ( !src.IsLoaded() ) { return; } idToken token; while ( true ) { if ( !src.ReadToken( &token ) ) { break; } if ( !token.Icmp( "entry" ) ) { if ( !ParseEntry( src ) ) { src.Warning( "Error Parsing Entry" ); break; } } else { src.Warning( "Invalid Token '%s'", token.c_str() ); break; } } if ( removeOldEntries ) { RemoveOldEntries(); } }
char * CreateManpageName( char * entry, int section, /* FIXME: unused */ int flags) { char * cp; char page[BUFSIZ]; char sect[BUFSIZ]; ParseEntry(entry, NULL, sect, page); #ifndef CRAY if ( (cp = rindex(page, '.')) != NULL) { if ( (int)strlen(cp) > 2 ) { *cp++ = '('; while( (cp[1] != '\0') ) { *cp = *(cp + 1); cp++; } *cp++ = ')'; *cp = '\0'; } else *cp = '\0'; } #else /* CRAY - pick up the Cray name from the section */ if ( (cp = rindex(page, '.')) == NULL) cp = page + strlen(page); if ((flags & MSUFFIX) && strlen(sect) > 4) { char *p = sect + 4; *cp++ = '('; while (*p) *cp++ = *p++; *cp++ = ')'; } *cp = '\0'; #endif /* CRAY */ return(StrAlloc(page)); }
void DebuggerTree::BuildTreeCDB(Watch* watch, const wxString& infoText) { //Local variables // hThisInstance = 0x00400000 // hPrevInstance = 0x00000000 // lpszArgument = 0x00151ef5 "" // nCmdShow = 10 // hwnd = 0x7ffd8000 // messages = struct tagMSG // wincl = struct tagWNDCLASSEXA wxTreeItemId parent = m_pTree->GetRootItem(); wxTreeItemId node = parent; wxArrayString lines = GetArrayFromString(infoText, _T('\n'), false); for (unsigned int i = 0; i < lines.GetCount(); ++i) { size_t thiscol = lines[i].find_first_not_of(_T(" \t")); size_t nextcol = i < lines.GetCount() - 1 ? lines[i + 1].find_first_not_of(_T(" \t")) : wxString::npos; bool opbrace = false; bool clbrace = false; if (thiscol < nextcol) { // add child node parent = node; opbrace = true; } else if (thiscol > nextcol) { // go one level up parent = m_pTree->GetItemParent(parent); clbrace = true; } if (opbrace) lines[i].Append(_T(" = {")); if (clbrace) lines[i].Append(_T("}")); } wxString str = GetStringFromArray(lines, _T(",")); ParseEntry(m_RootEntry, watch, str); }
/////////////////////////////////////////////////////////////////////// /// Function: XosWebRtcClientConnection:: /// /// Author: $author$ /// Date: 4/1/2012 /////////////////////////////////////////////////////////////////////// void XosWebRtcClientConnection::OnHangingGetRead(talk_base::AsyncSocket* socket) { LOG(INFO) << __FUNCTION__; size_t content_length = 0; if (ReadIntoBuffer(socket, ¬ification_data_, &content_length)) { size_t peer_id = 0, eoh = 0; bool ok = ParseServerResponse(notification_data_, content_length, &peer_id, &eoh); if (ok) { // Store the position where the body begins. size_t pos = eoh + 4; if (my_id_ == static_cast<int>(peer_id)) { // A notification about a new member or a member that just // disconnected. int id = 0; std::string name; bool connected = false; if (ParseEntry(notification_data_.substr(pos), &name, &id, &connected)) { if (connected) { peers_[id] = name; callback_->OnPeerConnected(id, name); } else { peers_.erase(id); callback_->OnPeerDisconnected(id); } } } else { OnMessageFromPeer(peer_id, notification_data_.substr(pos)); } } notification_data_.clear(); } if (hanging_get_->GetState() == talk_base::Socket::CS_CLOSED && state_ == CONNECTED) { hanging_get_->Connect(server_address_); } }
void DebuggerTree::BuildTreeGDB(Watch* watch, const wxString& infoText) { // Manager::Get()->GetLogManager()->DebugLog("DebuggerTree::BuildTree(): Parsing '%s'", infoText.c_str()); wxString buffer = infoText; // remove CRLFs (except if inside quotes) int len = buffer.Length(); bool inQuotes = false; for (int i = 0; i < len; ++i) { if (buffer.GetChar(i) == _T('"') && (i == 0 || (i > 0 && buffer.GetChar(i - 1) != _T('\\')))) inQuotes = !inQuotes; if (!inQuotes) { if (buffer.GetChar(i) == _T('\r')) buffer.SetChar(i, _T(' ')); else if (buffer.GetChar(i) == _T('\n')) buffer.SetChar(i, _T(',')); } } ParseEntry(m_RootEntry, watch, buffer); }
void DebuggerTree::ParseEntry(WatchTreeEntry& entry, Watch* watch, wxString& text, long array_index) { if (text.IsEmpty()) return; // Manager::Get()->GetLogManager()->DebugLog(F(_T("DebuggerTree::ParseEntry(): %s"), text.c_str())); while (1) { // trim the string from left and right text.Trim(true); text.Trim(false); // find position of '{', '}' and ',' ***outside*** of any quotes. // decide which is nearer to the start int braceOpenPos = FindCharOutsideQuotes(text, _T('{')); if (braceOpenPos == -1) braceOpenPos = 0xFFFFFE; int braceClosePos = FindCharOutsideQuotes(text, _T('}')); if (braceClosePos == -1) braceClosePos = 0xFFFFFE; int commaPos = FindCommaPos(text); if (commaPos == -1) commaPos = 0xFFFFFE; int pos = std::min(commaPos, std::min(braceOpenPos, braceClosePos)); if (pos == 0xFFFFFE) { // no comma, opening or closing brace if (text.Right(3).Matches(_T(" = "))) text.Truncate(text.Length() - 3); if (!text.IsEmpty()) { entry.AddChild(text, watch); text.Clear(); } break; } else { // display array on a single line? // normal (multiple lines) display is taken care below, with array indexing if (watch && watch->is_array && braceOpenPos != 0xFFFFFE && braceClosePos != 0xFFFFFE) { wxString tmp = text.Left(braceClosePos + 1); // if more than one opening/closing brace, then it's a complex array so // ignore single-line if (text.Freq(_T('{')) == 1 && text.Freq(_T('}')) == 1) { // array on single line for up to 8 (by default) elements // if more elements, fall through to the multi-line display int commas = Manager::Get()->GetConfigManager(_T("debugger"))->ReadInt(_T("/single_line_array_elem_count"), 8); if (tmp.Freq(_T(',')) < commas) { // array watch type tmp[braceOpenPos] = _T('['); tmp.Last() = _T(']'); entry.AddChild(tmp, watch); text.Remove(0, braceClosePos + 1); continue; } } } wxString tmp = text.Left(pos); WatchTreeEntry* newchild = 0; if (tmp.Right(3).Matches(_T(" = "))) tmp.Truncate(tmp.Length() - 3); // remove " = " if last in string if (!tmp.IsEmpty()) { // take array indexing into account (if applicable) if (array_index != -1) { tmp.Prepend(wxString::Format(_T("[%ld]: "), array_index)); // if array element would occur multiple times, gdb adds as default "<repeated xx times> to the output // so we have to look for it and increase the array_index correctly // as default we increase by 1 long incIndex = 1; if (reRepeatedElements.Matches(tmp)) { reRepeatedElements.GetMatch(tmp, 1).ToLong(&incIndex); } array_index += incIndex; } newchild = &entry.AddChild(tmp, watch); } text.Remove(0, pos + 1); if (pos == braceOpenPos) { if (!newchild) newchild = &entry; // enable array indexing (if applicable) bool no_indexing = array_index == -1; if (watch && watch->is_array && no_indexing && text.Freq(_T('{')) == 0 && text.Freq(_T('}')) == 1) // don't index complex arrays { array_index = 0; } ParseEntry(*newchild, watch, text, array_index); // proceed one level deeper // reset array indexing if (no_indexing) array_index = -1; } else if (pos == braceClosePos) break; // return one level up } } }
STATUSCODE ParseFile( PPARSERDATA pParserData, PWSTR pFilename ) /*++ Routine Description: Parse a PCL-XL printer description file Arguments: pParserData - Points to parser data structure pFilename - Specifies the name of the file to be parsed Return Value: ERR_NONE if successful, error code otherwise --*/ { STATUSCODE status; PFILEOBJ pFile; INT syntaxErrors; // // Map the file into memory for read-only access // Verbose(("File %ws\n", pFilename)); if (! (pFile = CreateFileObj(pFilename))) return ERR_FILE; pParserData->pFile = pFile; // // Compute the 16-bit CRC checksum of the file content // pParserData->checksum = ComputeCrc16Checksum(pFile->pStartPtr, pFile->fileSize, pParserData->checksum); // // Process entries in the file // while ((status = ParseEntry(pParserData)) != ERR_EOF) { if (status != ERR_NONE && status != ERR_SYNTAX) { DeleteFileObj(pFile); return status; } } if (EndOfFile(pFile) && !EndOfLine(pFile)) { Warning(("Incomplete last line ignored.\n")); } // // Unmap the file and return to the caller // syntaxErrors = pFile->syntaxErrors; DeleteFileObj(pFile); if (syntaxErrors > 0) { Error(("%d syntax error(s) found in %ws\n", syntaxErrors, pFilename)); return ERR_SYNTAX; } return ERR_NONE; }
FILE * Format(ManpageGlobals * man_globals, char * entry) { FILE * file = NULL; #ifdef HAS_MKSTEMP int fd; #endif Widget manpage = man_globals->manpagewidgets.manpage; char cmdbuf[BUFSIZ], tmp[BUFSIZ], filename[BUFSIZ], error_buf[BUFSIZ]; char path[BUFSIZ], sect[BUFSIZ]; XEvent event; Position x,y; /* location to pop up the "would you like to save" widget. */ #ifndef HAS_MKSTEMP if ( !UncompressUnformatted(man_globals, entry, filename) ) { #else if ( !UncompressUnformatted(man_globals, entry, filename, &file) ) { #endif /* We Really could not find it, this should never happen, yea right. */ snprintf(error_buf, sizeof(error_buf), "Could not open manual page, %s", entry); PopupWarning(man_globals, error_buf); XtPopdown( XtParent(man_globals->standby) ); return(NULL); } #ifndef HAS_MKSTEMP if ((file = fopen(filename, "r")) != NULL) { #else if (file != NULL) { #endif char line[BUFSIZ]; if (fgets(line, sizeof(line), file) != NULL) { if (strncmp(line, ".so ", 4) == 0) { line[strlen(line) - 1] = '\0'; fclose(file); unlink(filename); if (line[4] != '/') { char *ptr = NULL; strcpy(tmp, entry); if ((ptr = rindex(tmp, '/')) != NULL) { *ptr = '\0'; if ((ptr = rindex(tmp, '/')) != NULL) ptr[1] = '\0'; } } else *tmp = '\0'; snprintf(filename, sizeof(filename), "%s%s", tmp, line + 4); return (Format(man_globals, filename)); } } fclose(file); } Popup(XtParent(man_globals->standby), XtGrabExclusive); while ( !XCheckTypedWindowEvent(XtDisplay(man_globals->standby), XtWindow(man_globals->standby), Expose, &event) ); XtDispatchEvent( &event ); XFlush(XtDisplay(man_globals->standby)); strcpy(tmp,MANTEMP); /* Get a temp file. */ #ifndef HAS_MKSTEMP (void) mktemp(tmp); #else fd = mkstemp(tmp); file = fdopen(fd, "r"); #endif strcpy(man_globals->tempfile, tmp); ParseEntry(entry, path, sect, NULL); #ifndef HANDLE_ROFFSEQ #ifndef HAS_MKSTEMP snprintf(cmdbuf, sizeof(cmdbuf), "cd %s ; %s %s %s > %s %s", path, TBL, filename, FORMAT, man_globals->tempfile, "2> /dev/null"); #else snprintf(cmdbuf, sizeof(cmdbuf), "cd %s ; %s %s %s >> %s %s", path, TBL, filename, FORMAT, man_globals->tempfile, "2> /dev/null"); #endif #else /* Handle more flexible way of specifying the formatting pipeline */ if (! ConstructCommand(cmdbuf, path, filename, man_globals->tempfile)) { sprintf(error_buf, "Constructed command was too long!"); PopupWarning(man_globals, error_buf); file = NULL; } else #endif /* HANDLE_ROFFSEQ */ if(system(cmdbuf) != 0) { /* execute search. */ snprintf(error_buf, sizeof(error_buf), "Something went wrong trying to run the command: %s", cmdbuf); PopupWarning(man_globals, error_buf); file = NULL; } else { #ifndef HAS_MKSTEMP if ((file = fopen(man_globals->tempfile,"r")) == NULL) { sprintf(error_buf, "Something went wrong in retrieving the %s", "temp file, try cleaning up /tmp"); PopupWarning(man_globals, error_buf); } else { #endif XtPopdown( XtParent(man_globals->standby) ); if ( (man_globals->save == NULL) || (man_globals->manpagewidgets.manpage == NULL) ) unlink(man_globals->tempfile); else { char * ptr, catdir[BUFSIZ]; /* * If the catdir is writeable then ask the user if he/she wants to * write the man page to it. */ strcpy(catdir, man_globals->save_file); if ( (ptr = rindex(catdir, '/')) != NULL) { *ptr = '\0'; if ( access(catdir, W_OK) != 0 ) unlink(man_globals->tempfile); else { x = (Position) Width(man_globals->manpagewidgets.manpage)/2; y = (Position) Height(man_globals->manpagewidgets.manpage)/2; XtTranslateCoords(manpage, x, y, &x, &y); PositionCenter( man_globals->save, (int) x, (int) y, 0, 0, 0, 0); XtPopup( man_globals->save, XtGrabExclusive); } } else unlink(man_globals->tempfile); } #ifndef HAS_MKSTEMP } #endif } /* * If the original was compressed or in another format, delete temporary file. */ if (man_globals->deletetempfile) unlink(filename); return(file); } #ifdef HANDLE_ROFFSEQ /* Function Name: ConstructCommand * Description: Constructs the pipeline of commands necessary to format * a manual page. * Arguments: cmdbuf - the buffer into which to write the command * path - the directory in which the original man page resides * filename - the (uncompressed) manpage source file * tempfile - the name of a temporary file to direct the final * output of the pipeline into * Returns: TRUE if the command fit into the buffer, FALSE if it would * be too long (more than BUFSIZ characters) */ static Boolean ConstructCommand(cmdbuf, path, filename, tempfile) char *cmdbuf, *path, *filename, *tempfile; { /* The original code did the following to produce a command line: * sprintf(cmdbuf,"cd %s ; %s %s %s > %s %s", path, TBL, * filename, FORMAT, man_globals->tempfile, "2> /dev/null"); * We are more flexible and follow more or less the algorithm used * by the Linux man command: * + Obtain a string of letters from the following sources in order * of preference: * + a command line option (not implemented in xman; it's probably not * useful) * + the first line of the manpage source, if it is of the form: * '\" <string> * + the MANROFFSEQ environment variable * + a default string; this is "". * + Interpret the string as a pipeline of filters: * + e = eqn g = grap p = pic t = tbl v = vgrind r = refer * + zsoelim is always run as the first preprocessor in any case. * * Strictly speaking we should save a catpage iff the string comes * from the file or is the default. * * You'll notice that we format a man page into ASCII text output and then * attempt to interpret things like L^HL as bold and so forth. This * is so obviously the Wrong Thing it's untrue. */ char *c = cmdbuf; /* current posn in buffer */ int left = BUFSIZ; /* space left in buffer */ int used; char *fmt; FILE *file; char fmtbuf[128]; int gotfmt = 0; /* set to 1 if we got a directive from source */ char *fname = NULL; #ifdef __UNIXOS2__ int i; #endif fmt = NULL; /* If you have a command line option that gives a setting for fmt, set it here. */ if (!fmt) { /* This is the tricky bit: extract a format string from the source file * Annoyingly, filename might be relative or absolute. We cheat and * use system to get the thing to a known absoute filename. */ if (filename[0] == '/') { fname = filename; } else { fname = malloc(strlen(path) + 1 + strlen(filename) + 1); if (!fname) return FALSE; sprintf(fname, "%s/%s", path, filename); } if ((file = fopen(fname, "r")) && (fgets(fmtbuf, sizeof(fmtbuf), file)) && (!memcmp(fmtbuf, "'\\\" ", 4))) { /* that's squote-backslash-dquote-space */ int len; fmt = fmtbuf + 3; len = strlen(fmt); if (len && (fmt[len-1] == '\n')) { fmt[len-1] = 0; gotfmt++; } } if (fname && fname != filename) free(fname); if (!gotfmt) /* not there or some error */ { fmt = getenv("MANROFFSEQ"); } } if (!fmt) { fmt = DEFAULT_MANROFFSEQ; } /* Start with the first fixed part of the command line */ #ifdef __UNIXOS2__ for (i = 0; i < strlen(path); i++) { if (path[i] == '/') path[i] = '\\'; } used = snprintf(c, left, "cd %s & %s %s ", path, ZSOELIM, filename); #else used = snprintf(c, left, "cd %s; %s %s ", path, ZSOELIM, filename); #endif left -= used; c += used; if (left <= 1) return (FALSE); /* Now add preprocessors of the form '| processor' */ for ( ; *fmt; fmt++) { char *filter; switch (*fmt) { case 'e': filter = EQN; break; case 'g': filter = GRAP; break; case 'p': filter = PIC; break; case 't': filter = TBL; break; case 'v': filter = VGRIND; break; case 'r': filter = REFER; break; default: filter = NULL; break; } if (filter) { used = snprintf(c, left, " | %s ", filter); left -= used; c += used; if (left <= 1) return (FALSE); } } /* Now add the fixed trailing part 'formatprog > tempfile 2> /dev/null' */ #ifdef __UNIXOS2__ used = snprintf(c, left, " | %s > %s 2>NUL", FORMAT, tempfile); #else #ifndef HAS_MKSTEMP used = snprintf(c, left, " | %s > %s 2>/dev/null", FORMAT, tempfile); #else used = snprintf(c, left, " | %s >> %s 2>/dev/null", FORMAT, tempfile); #endif #endif /* __UNIXOS2__ */ left -= used; if (left <= 1) return (FALSE); return (TRUE); } #endif /* HANDLE_ROFFSEQ */ /* Function Name: UncompressUnformatted * Description: Finds an uncompressed unformatted manual page. * Arguments: man_globals - the psuedo global structure. * entry - the manual page entry. * RETURNED filename - location to put the name of the file. * Returns: TRUE if the file was found. */ static Boolean #ifndef HAS_MKSTEMP UncompressUnformatted(ManpageGlobals * man_globals, char * entry, char * filename) #else UncompressUnformatted(ManpageGlobals * man_globals, char * entry, char * filename, FILE **file) #endif { char path[BUFSIZ], page[BUFSIZ], section[BUFSIZ], input[BUFSIZ]; int len_cat = strlen(CAT), len_man = strlen(MAN); #if defined(SMAN) && defined(SFORMAT) int len_sman = strlen(SMAN); #endif ParseEntry(entry, path, section, page); man_globals->bzip2 = FALSE; man_globals->lzma = FALSE; #if defined(__OpenBSD__) || defined(__NetBSD__) /* * look for uncompressed file in machine subdir first */ snprintf(filename, BUFSIZ, "%s/%s%s/%s/%s", path, MAN, section + len_cat, MACHINE, page); if ( access( filename, R_OK ) == 0 ) { man_globals->compress = FALSE; man_globals->gzip = FALSE; man_globals->deletetempfile = FALSE; snprintf(man_globals->save_file, sizeof(man_globals->save_file), "%s/%s%s/%s/%s", path, CAT, section + len_cat, MACHINE, page); return(TRUE); } /* * Then for compressed files in an uncompressed directory. */ snprintf(input, sizeof(input), "%s.%s", filename, COMPRESSION_EXTENSION); #ifndef HAS_MKSTEMP if ( UncompressNamed(man_globals, input, filename) ) { #else if ( UncompressNamed(man_globals, input, filename, file) ) { #endif man_globals->compress = TRUE; man_globals->deletetempfile = TRUE; snprintf(man_globals->save_file, sizeof(man_globals->save_file), "%s/%s%s/%s.%s", path, CAT, section + len_cat, page, COMPRESSION_EXTENSION); return(TRUE); } #ifdef GZIP_EXTENSION else { snprintf(input, sizeof(input), "%s.%s", filename, GZIP_EXTENSION); #ifndef HAS_MKSTEMP if ( UncompressNamed(man_globals, input, filename) ) { #else if ( UncompressNamed(man_globals, input, filename, file) ) { #endif man_globals->compress = TRUE; man_globals->gzip = TRUE; man_globals->deletetempfile = TRUE; snprintf(man_globals->save_file, sizeof(man_globals->save_file), "%s/%s%s/%s.%s", path, CAT, section + len_cat, page, GZIP_EXTENSION); return(TRUE); } } #endif /* GZIP_EXTENSION */ #endif /* __OpenBSD__ || __NetBSD__ */ #ifdef BZIP2_EXTENSION { sprintf(input, "%s.%s", filename, BZIP2_EXTENSION); #ifndef HAS_MKSTEMP if ( UncompressNamed(man_globals, input, filename) ) { #else if ( UncompressNamed(man_globals, input, filename, file) ) { #endif man_globals->compress = TRUE; man_globals->gzip = FALSE; man_globals->bzip2 = TRUE; sprintf(man_globals->save_file, "%s/%s%s/%s.%s", path, CAT, section + len_cat, page, BZIP2_EXTENSION); return(TRUE); } } #endif /* BZIP2_EXTENSION */ #ifdef LZMA_EXTENSION { sprintf(input, "%s.%s", filename, LZMA_EXTENSION); #ifndef HAS_MKSTEMP if ( UncompressNamed(man_globals, input, filename) ) { #else if ( UncompressNamed(man_globals, input, filename, file) ) { #endif man_globals->compress = TRUE; man_globals->gzip = FALSE; man_globals->lzma = TRUE; sprintf(man_globals->save_file, "%s/%s%s/%s.%s", path, CAT, section + len_cat, page, LZMA_EXTENSION); return(TRUE); } } #endif /* LZMA_EXTENSION */ /* * Look for uncompressed file first. */ snprintf(filename, BUFSIZ, "%s/%s%s/%s", path, MAN, section + len_man, page); if ( access( filename, R_OK ) == 0 ) { man_globals->compress = FALSE; man_globals->gzip = FALSE; man_globals->deletetempfile = FALSE; snprintf(man_globals->save_file, sizeof(man_globals->save_file), "%s/%s%s/%s", path, CAT, section + len_cat, page); return(TRUE); } #if defined(SMAN) && defined(SFORMAT) /* * Look for uncompressed sgml file next. */ snprintf(input, BUFSIZ, "%s/%s%s/%s", path, SMAN, section + len_sman, page); #ifndef HAS_MKSTEMP if ( SgmlToRoffNamed(man_globals, input, filename) ) { #else if ( SgmlToRoffNamed(man_globals, input, filename, file) ) { #endif man_globals->compress = FALSE; man_globals->gzip = FALSE; man_globals->deletetempfile = TRUE; snprintf(man_globals->save_file, sizeof(man_globals->save_file), "%s/%s%s/%s", path, CAT, section + len_cat, page); return(TRUE); } #endif /* * Then for compressed files in an uncompressed directory. */ snprintf(input, sizeof(input), "%s.%s", filename, COMPRESSION_EXTENSION); #ifndef HAS_MKSTEMP if ( UncompressNamed(man_globals, input, filename) ) { #else if ( UncompressNamed(man_globals, input, filename, file) ) { #endif man_globals->compress = TRUE; man_globals->deletetempfile = TRUE; snprintf(man_globals->save_file, sizeof(man_globals->save_file), "%s/%s%s/%s.%s", path, CAT, section + len_cat, page, COMPRESSION_EXTENSION); return(TRUE); } #ifdef GZIP_EXTENSION else { snprintf(input, sizeof(input), "%s.%s", filename, GZIP_EXTENSION); #ifndef HAS_MKSTEMP if ( UncompressNamed(man_globals, input, filename) ) { #else if ( UncompressNamed(man_globals, input, filename, file) ) { #endif man_globals->compress = TRUE; man_globals->gzip = TRUE; man_globals->deletetempfile = TRUE; snprintf(man_globals->save_file, sizeof(man_globals->save_file), "%s/%s%s/%s.%s", path, CAT, section + len_cat, page, GZIP_EXTENSION); return(TRUE); } } #endif #ifdef BZIP2_EXTENSION { sprintf(input, "%s.%s", filename, BZIP2_EXTENSION); #ifndef HAS_MKSTEMP if ( UncompressNamed(man_globals, input, filename) ) { #else if ( UncompressNamed(man_globals, input, filename, file) ) { #endif man_globals->compress = TRUE; man_globals->gzip = TRUE; sprintf(man_globals->save_file, "%s/%s%s/%s.%s", path, CAT, section + len_cat, page, BZIP2_EXTENSION); return(TRUE); } } #endif #ifdef LZMA_EXTENSION { sprintf(input, "%s.%s", filename, LZMA_EXTENSION); #ifndef HAS_MKSTEMP if ( UncompressNamed(man_globals, input, filename) ) { #else if ( UncompressNamed(man_globals, input, filename, file) ) { #endif man_globals->compress = TRUE; man_globals->lzma = TRUE; sprintf(man_globals->save_file, "%s/%s%s/%s.%s", path, CAT, section + len_cat, page, LZMA_EXTENSION); return(TRUE); } } #endif /* * And lastly files in a compressed directory. */ snprintf(input, sizeof(input), "%s/%s%s.%s/%s", path, MAN, section + len_man, COMPRESSION_EXTENSION, page); #ifndef HAS_MKSTEMP if ( UncompressNamed(man_globals, input, filename) ) { #else if ( UncompressNamed(man_globals, input, filename, file) ) { #endif man_globals->compress = TRUE; man_globals->deletetempfile = TRUE; snprintf(man_globals->save_file, sizeof(man_globals->save_file), "%s/%s%s.%s/%s", path, CAT, section + len_cat, COMPRESSION_EXTENSION, page); return(TRUE); } return(FALSE); } /* Function Name: AddCursor * Description: This function adds the cursor to the window. * Arguments: w - the widget to add the cursor to. * cursor - the cursor to add to this widget. * Returns: none */ void AddCursor(Widget w, Cursor cursor) { XColor colors[2]; Arg args[10]; Cardinal num_args = 0; Colormap c_map; if (!XtIsRealized(w)) { PopupWarning(NULL, "Widget is not realized, no cursor added.\n"); return; } XtSetArg( args[num_args], XtNcolormap, &c_map); num_args++; XtGetValues( w, args, num_args); colors[0].pixel = resources.cursors.fg_color; colors[1].pixel = resources.cursors.bg_color; XQueryColors (XtDisplay(w), c_map, colors, 2); XRecolorCursor(XtDisplay(w), cursor, colors, colors+1); XDefineCursor(XtDisplay(w),XtWindow(w),cursor); } /* Function Name: ChangeLabel * Description: This function changes the label field of the * given widget to the string in str. * Arguments: w - the widget. * str - the string to change the label to. * Returns: none */ void ChangeLabel(Widget w, char * str) { Arg arglist[3]; /* An argument list. */ if (w == NULL) return; XtSetArg(arglist[0], XtNlabel, str); /* shouldn't really have to do this. */ XtSetArg(arglist[1], XtNwidth, 0); XtSetArg(arglist[2], XtNheight, 0); XtSetValues(w, arglist, (Cardinal) 1); } /* * In an ideal world this would be part of the XToolkit, and I would not * have to do it, but such is life sometimes. Perhaps in X11R3. */ /* Function Name: PositionCenter * Description: This function positions the given widgets center * in the following location. * Arguments: widget - the widget widget to postion * x,y - The location for the center of the widget * above - number of pixels above center to locate this widget * left - number of pixels left of center to locate this widget * h_space, v_space - how close to get to the edges of the * parent window. * Returns: none * Note: This should only be used with a popup widget that has override * redirect set. */ void PositionCenter(Widget widget, int x, int y, int above, int left, int v_space, int h_space) { Arg wargs[2]; int x_temp,y_temp; /* location of the new window. */ int parent_height,parent_width; /* Height and width of the parent widget or the root window if it has no parent. */ x_temp = x - left - Width(widget) / 2 + BorderWidth(widget); y_temp = y - above - Height(widget) / 2 + BorderWidth(widget); parent_height = HeightOfScreen(XtScreen(widget)); parent_width = WidthOfScreen(XtScreen(widget)); /* * Check to make sure that all edges are within the viewable part of the * root window, and if not then force them to be. */ if (x_temp < h_space) x_temp = v_space; if (y_temp < v_space) (y_temp = 2); if ( y_temp + Height(widget) + v_space > parent_height ) y_temp = parent_height - Height(widget) - v_space; if ( x_temp + Width(widget) + h_space > parent_width ) x_temp = parent_width - Width(widget) - h_space; XtSetArg(wargs[0], XtNx, x_temp); XtSetArg(wargs[1], XtNy, y_temp); XtSetValues(widget, wargs, 2); } /* Function Name: ParseEntry(entry, path, sect, page) * Description: Parses the manual pages entry filenames. * Arguments: str - the full path name. * path - the path name. RETURNED * sect - the section name. RETURNED * page - the page name. RETURNED * Returns: none. */ void ParseEntry(char *entry, char *path, char *sect, char *page) { char *c, temp[BUFSIZ]; strcpy(temp, entry); c = rindex(temp, '/'); if (c == NULL) PrintError("index failure in ParseEntry."); *c++ = '\0'; if (page != NULL) strcpy(page, c); c = rindex(temp, '/'); if (c == NULL) PrintError("index failure in ParseEntry."); *c++ = '\0'; #if defined(SFORMAT) && defined(SMAN) /* sgmltoroff sometimes puts an extra ./ in the path to .so entries */ if (strcmp(c, ".") == 0) { c = rindex(temp, '/'); if (c == NULL) PrintError("index failure in ParseEntry."); *c++ = '\0'; } #endif #if defined(__OpenBSD__) || defined(__NetBSD__) /* Skip machine subdirectory if present */ if (strcmp(c, MACHINE) == 0) { c = rindex(temp, '/'); if (c == NULL) PrintError("index failure in ParseEntry."); *c++ = '\0'; } #endif if (sect != NULL) strcpy(sect, c); if (path != NULL) strcpy(path, temp); } /* Function Name: GetGlobals * Description: Gets the psuedo globals associated with the * manpage associated with this widget. * Arguments: w - a widget in the manpage. * Returns: the psuedo globals. * Notes: initial_widget is a globals variable. * manglobals_context is a global variable. */ ManpageGlobals * GetGlobals(Widget w) { Widget temp; caddr_t data; while ( (temp = XtParent(w)) != initial_widget && (temp != NULL)) w = temp; if (temp == NULL) XtAppError(XtWidgetToApplicationContext(w), "Xman: Could not locate widget in tree, exiting"); if (XFindContext(XtDisplay(w), XtWindow(w), manglobals_context, &data) != XCSUCCESS) XtAppError(XtWidgetToApplicationContext(w), "Xman: Could not find global data, exiting"); return( (ManpageGlobals *) data); } /* Function Name: SaveGlobals * Description: Saves the psuedo globals on the widget passed * to this function, although GetGlobals assumes that * the data is associated with the popup child of topBox. * Arguments: w - the widget to associate the data with. * globals - data to associate with this widget. * Returns: none. * Notes: WIDGET MUST BE REALIZED. * manglobals_context is a global variable. */ void SaveGlobals(Widget w, ManpageGlobals * globals) { if (XSaveContext(XtDisplay(w), XtWindow(w), manglobals_context, (caddr_t) globals) != XCSUCCESS) XtAppError(XtWidgetToApplicationContext(w), "Xman: Could not save global data, are you out of memory?"); } /* Function Name: RemoveGlobals * Description: Removes the psuedo globals from the widget passed * to this function. * Arguments: w - the widget to remove the data from. * Returns: none. * Notes: WIDGET MUST BE REALIZED. * manglobals_context is a global variable. */ void RemoveGlobals(Widget w) { if (XDeleteContext(XtDisplay(w), XtWindow(w), manglobals_context) != XCSUCCESS) XtAppError(XtWidgetToApplicationContext(w), "Xman: Could not remove global data?"); }
FILE * FindManualFile(ManpageGlobals * man_globals, int section_num, int entry_num) { FILE * file; char path[BUFSIZ], page[BUFSIZ], section[BUFSIZ], *temp; char filename[BUFSIZ]; char * entry = manual[section_num].entries[entry_num]; int len_cat = strlen(CAT); #if defined(ISC) || defined(__SCO__) || defined(__UNIXWARE__) int i; #endif temp = CreateManpageName(entry, 0, 0); snprintf(man_globals->manpage_title, sizeof(man_globals->manpage_title), "The current manual page is: %s.", temp); XtFree(temp); ParseEntry(entry, path, section, page); /* * Look for uncompressed files first. */ #if defined(__OpenBSD__) || defined(__NetBSD__) /* look in machine subdir first */ snprintf(filename, sizeof(filename), "%s/%s%s/%s/%s", path, CAT, section + len_cat, MACHINE, page); if ( (file = fopen(filename,"r")) != NULL) return(file); #endif snprintf(filename, sizeof(filename), "%s/%s%s/%s", path, CAT, section + len_cat, page); if ( (file = fopen(filename,"r")) != NULL) return(file); /* * Then for compressed files in an uncompressed directory. */ #if !defined(ISC) && !defined(__UNIXWARE__) #if defined(__OpenBSD__) || defined(__NetBSD__) /* look in machine subdir first */ snprintf(filename, sizeof(filename), "%s/%s%s/%s/%s.%s", path, CAT, section + len_cat, MACHINE, page, COMPRESSION_EXTENSION); if ( (file = Uncompress(man_globals, filename)) != NULL) return(file); #endif snprintf(filename, sizeof(filename), "%s/%s%s/%s.%s", path, CAT, section + len_cat, page, COMPRESSION_EXTENSION); if ( (file = Uncompress(man_globals, filename)) != NULL) return(file); #ifdef GZIP_EXTENSION else { #if defined(__OpenBSD__) || defined(__NetBSD__) /* look in machine subdir first */ snprintf(filename, sizeof(filename), "%s/%s%s/%s/%s.%s", path, CAT, section + len_cat, MACHINE, page, GZIP_EXTENSION); if ( (file = Uncompress(man_globals, filename)) != NULL) return(file); #endif snprintf(filename, sizeof(filename), "%s/%s%s/%s.%s", path, CAT, section + len_cat, page, GZIP_EXTENSION); if ( (file = Uncompress(man_globals, filename)) != NULL) return(file); } #endif #ifdef BZIP2_EXTENSION #if defined(__OpenBSD__) || defined(__NetBSD__) /* look in machine subdir first */ snprintf(filename, sizeof(filename), "%s/%s%s/%s/%s.%s", path, CAT, section + len_cat, MACHINE, page, BZIP2_EXTENSION); if ( (file = Uncompress(man_globals, filename)) != NULL) return(file); #endif { sprintf(filename, "%s/%s%s/%s.%s", path, CAT, section + len_cat, page, BZIP2_EXTENSION); if ( (file = Uncompress(man_globals, filename)) != NULL) return(file); } #endif #ifdef LZMA_EXTENSION { sprintf(filename, "%s/%s%s/%s.%s", path, CAT, section + len_cat, page, LZMA_EXTENSION); if ( (file = Uncompress(man_globals, filename)) != NULL) return(file); } #endif #else for(i = 0; i < strlen(COMPRESSION_EXTENSIONS); i++) { snprintf(filename, sizeof(filename), "%s/%s%s/%s.%c", path, CAT, section + len_cat, page, COMPRESSION_EXTENSIONS[i]); uncompress_format = uncompress_formats[i]; #ifdef DEBUG printf("Trying .%c ...\n", COMPRESSION_EXTENSIONS[i]); #endif if ( (file = Uncompress(man_globals, filename)) != NULL) return(file); } #endif /* * And lastly files in a compressed directory. * * The directory is not actually compressed it is just named man#.Z * and all files in it are compressed without the .Z extension. * HP does it this way (really :-). */ snprintf(filename, sizeof(filename), "%s/%s%s.%s/%s", path, CAT, section + len_cat, COMPRESSION_EXTENSION, page); if ( (file = Uncompress(man_globals, filename)) != NULL) return(file); /* * We did not find any preformatted manual pages, try to format it. */ return(Format(man_globals, entry)); }