ACE_Event_Handler* UNIXConnect ( const JCharacter* socketName ) { // This specifies the address to which we will connect. ACE_UNIX_Addr addr(socketName); // This object will handle the transaction with the server. UNIXHandler* handler = new UNIXHandler; assert( handler != NULL ); // This object will hook the UNIXHandler's ACE_LSOCK_Stream up when // a connection is established. UNIXConnector* connector = new UNIXConnector; assert( connector != NULL ); // Begin waiting for a connection. ACE_Synch_Options options(ACE_Synch_Options::USE_REACTOR, ACE_Time_Value(kMaxWaitSeconds)); if (connector->connect(handler, addr, options) == -1 && jerrno() != EAGAIN) { cerr << "error trying to connect: " << jerrno() << endl; exit(1); } return connector; }
static B jtdolock(J jt,B lk,F f,I i,I n){I e;long c;fpos_t v; fpos_t q; c=fgetpos(f,(fpos_t*)&q); if(0!=c)R (B)jerrno(); v=i; c=fsetpos(f,(fpos_t*)&v); if(0!=c)R (B)jerrno(); e=_locking(_fileno(f),lk?_LK_NBLCK:_LK_UNLCK,(long)n); fsetpos(f,(fpos_t*)&q); R !e?1:errno==EACCES?0:(B)jerrno(); }
JError JGetFileLength ( const JCharacter* name, JSize* size ) { ACE_stat info; if (ACE_OS::stat(name, &info) == 0) { *size = info.st_size; return JNoError(); } *size = 0; const int err = jerrno(); if (err == ENOENT) { return JDirEntryDoesNotExist(name); } else { return JUnexpectedError(err); } }
JError JCreatePipe ( int fd[2] ) { jclear_errno(); if (pipe(fd) == 0) { return JNoError(); } const int err = jerrno(); if (err == EFAULT) { return JSegFault(); } else if (err == EMFILE || err == ENFILE) { return JTooManyDescriptorsOpen(); } else { return JUnexpectedError(err); } }
JError JSendSignalToProcess ( const pid_t pid, const int signal ) { jclear_errno(); if (ACE_OS::kill(pid, signal) == 0) { return JNoError(); } const int err = jerrno(); if (err == EINVAL) { return JInvalidSignal(); } else if (err == ESRCH) { return JInvalidProcess(); } else if (err == EPERM) { return JCanNotSignalProcess(); } else { return JUnexpectedError(err); } }
void JCheckForNewerVersion ( JPrefsManager* prefsMgr, const JPrefID& prefID ) { const JString& versionURL = JGetString("VERSION_URL"); JString protocol, host, path; JIndex port; if (!JParseURL(versionURL, &protocol, &host, &port, &path)) { cerr << "unable to parse url: " << versionURL << endl; return; } if (port == 0 && !JGetDefaultPort(protocol, &port)) { cerr << "unknown protocol in versionURL: " << versionURL << endl; return; } VersionSocket* socket = new VersionSocket(host, path, prefsMgr, prefID); assert( socket != NULL ); const JString vers = socket->GetLatestVersion(); if (socket->TimeToRemind()) { const JCharacter* map[] = { "vers", vers, "site", host }; const JString msg = JGetString("JRemindNewVersion", map, sizeof(map)); if ((JGetUserNotification())->AskUserYes(msg)) { (JGetWebBrowser())->ShowURL(JGetString("DOWNLOAD_URL")); } } if (socket->TimeToCheck()) { ACE_INET_Addr addr(port, host); VersionConnector* connector = new VersionConnector; assert( connector != NULL ); if (connector->connect(socket, addr, ACE_Synch_Options::asynch) == -1 && jerrno() != EAGAIN) { // cerr << "unable to open socket: " << versionURL << endl; delete connector; } } else { delete socket; } }
JError JGetPermissions ( const JCharacter* name, mode_t* perms ) { ACE_stat info; if (ACE_OS::stat(name, &info) == 0) { *perms = info.st_mode; return JNoError(); } *perms = 0; const int err = jerrno(); if (err == ENOENT) { return JDirEntryDoesNotExist(name); } else { return JUnexpectedError(err); } }
JError JGetOwnerGroup ( const JCharacter* name, gid_t* gid ) { ACE_stat info; if (ACE_OS::stat(name, &info) == 0) { *gid = info.st_gid; return JNoError(); } *gid = 0; const int err = jerrno(); if (err == ENOENT) { return JDirEntryDoesNotExist(name); } else { return JUnexpectedError(err); } }
JError JGetModificationTime ( const JCharacter* name, time_t* modTime ) { ACE_stat info; if (ACE_OS::stat(name, &info) == 0) { *modTime = info.st_mtime; return JNoError(); } *modTime = 0; const int err = jerrno(); if (err == ENOENT) { return JDirEntryDoesNotExist(name); } else { return JUnexpectedError(err); } }
JError JGetSymbolicLinkTarget ( const char* linkFullName, JString* targetFullName ) { const JSize kBufferSize = 10000; char buf[ kBufferSize ]; const long linkNameSize = readlink(linkFullName, buf, kBufferSize-1); if (linkNameSize != -1) { targetFullName->Set(buf, linkNameSize); return JNoError(); } targetFullName->Clear(); const int err = jerrno(); if (err == ENOTDIR) { return JComponentNotDirectory(linkFullName); } else if (err == ENAMETOOLONG) { return JNameTooLong(); } else if (err == ENOENT) { return JDirEntryDoesNotExist(linkFullName); } else if (err == EPERM || err == EACCES) { return JAccessDenied(linkFullName); } else if (err == ELOOP) { return JTooManyLinks(linkFullName); } else if (err == EINVAL) { return JNotSymbolicLink(linkFullName); } else if (err == EIO) { return JGeneralIO(); } else if (err == EFAULT) { return JSegFault(); } else if (err == ENOMEM) { return JNoKernelMemory(); } else { return JUnexpectedError(err); } }
JError JMkDir ( const JCharacter* dirName, const mode_t mode ) { jclear_errno(); if (mkdir(dirName, mode) == 0) { return JNoError(); } const int err = jerrno(); if (err == EEXIST) { return JDirEntryAlreadyExists(dirName); } else if (err == EFAULT) { return JSegFault(); } else if (err == EACCES) { return JAccessDenied(dirName); } else if (err == ENAMETOOLONG) { return JNameTooLong(); } else if (err == ENOENT) { return JBadPath(dirName); } else if (err == ENOTDIR) { return JComponentNotDirectory(dirName); } else if (err == ENOMEM) { return JNoKernelMemory(); } else if (err == EROFS) { return JFileSystemReadOnly(); } else if (err == ELOOP) { return JPathContainsLoop(dirName); } else if (err == ENOSPC) { return JFileSystemFull(); } else { return JUnexpectedError(err); } }
JError JRemoveDirectory ( const JCharacter* dirName ) { jclear_errno(); if (rmdir(dirName) == 0) { return JNoError(); } const int err = jerrno(); if (err == EPERM || err == EACCES) { return JAccessDenied(dirName); } else if (err == EFAULT) { return JSegFault(); } else if (err == ENAMETOOLONG) { return JNameTooLong(); } else if (err == ENOENT) { return JBadPath(dirName); } else if (err == ENOTDIR) { return JComponentNotDirectory(dirName); } else if (err == ENOTEMPTY) { return JDirectoryNotEmpty(dirName); } else if (err == EBUSY) { return JDirectoryBusy(dirName); } else if (err == ENOMEM) { return JNoKernelMemory(); } else if (err == EROFS) { return JFileSystemReadOnly(); } else if (err == ELOOP) { return JPathContainsLoop(dirName); } else { return JUnexpectedError(err); } }
JError JCreateTempFile ( const JCharacter* path, const JCharacter* prefix, JString* fullName ) { JString p; if (!JStringEmpty(path)) { p = path; } else if (!JGetTempDirectory(&p)) { return JDirEntryDoesNotExist("/tmp"); } if (!JStringEmpty(prefix)) { p = JCombinePathAndName(p, prefix); } else { p = JCombinePathAndName(p, "temp_file_"); } p += "XXXXXX"; char* s = p.AllocateCString(); jclear_errno(); int fd = mkstemp(s); if (fd != -1) { close(fd); *fullName = s; delete [] s; return JNoError(); } fullName->Clear(); delete [] s; // EINVAL counts as unexpected const int err = jerrno(); if (err == EEXIST) { return JAccessDenied(p); } else { return JUnexpectedError(err); } }
JError JSetPermissions ( const JCharacter* name, const mode_t perms ) { jclear_errno(); if (chmod(name, perms) == 0) { return JNoError(); } const int err = jerrno(); if (err == EPERM || err == EACCES) { return JAccessDenied(name); } else if (err == EROFS) { return JFileSystemReadOnly(); } else if (err == EFAULT) { return JSegFault(); } else if (err == ENAMETOOLONG) { return JNameTooLong(); } else if (err == ENOENT) { return JDirEntryDoesNotExist(name); } else if (err == ENOMEM) { return JNoKernelMemory(); } else if (err == ENOTDIR) { return JComponentNotDirectory(name); } else if (err == ELOOP) { return JPathContainsLoop(name); } else { return JUnexpectedError(err); } }
JError JRemoveFile ( const JCharacter* fileName ) { jclear_errno(); if (remove(fileName) == 0) { return JNoError(); } const int err = jerrno(); if (err == EFAULT) { return JSegFault(); } else if (err == EACCES || err == EPERM) { return JAccessDenied(fileName); } else if (err == ENAMETOOLONG) { return JNameTooLong(); } else if (err == ENOENT) { return JBadPath(fileName); } else if (err == ENOTDIR) { return JComponentNotDirectory(fileName); } else if (err == EISDIR) { return JTriedToRemoveDirectory(); } else if (err == ENOMEM) { return JNoKernelMemory(); } else if (err == EROFS) { return JFileSystemReadOnly(); } else { return JUnexpectedError(err); } }
JError JChangeDirectory ( const JCharacter* dirName ) { jclear_errno(); if (chdir(dirName) == 0) { return JNoError(); } const int err = jerrno(); if (err == EPERM || err == EACCES) { return JAccessDenied(dirName); } else if (err == EFAULT) { return JSegFault(); } else if (err == ENAMETOOLONG) { return JNameTooLong(); } else if (err == ENOENT) { return JBadPath(dirName); } else if (err == ENOMEM) { return JNoKernelMemory(); } else if (err == ENOTDIR) { return JComponentNotDirectory(dirName); } else if (err == ELOOP) { return JPathContainsLoop(dirName); } else { return JUnexpectedError(err); } }
static B jtwa(J jt,F f,I j,A w){C*x;I n,p=0;size_t q=1; RZ(f&&w); n=AN(w)*(C2T&AT(w)?2:1); x=CAV(w); #if !SY_WINCE {INT64 v; v= j+((0>j)?fsize(f):0); fsetpos(f,(fpos_t*)&v);} #else fseek(f,(long)(0>j?1+j:j),0>j?SEEK_END:SEEK_SET); #endif clearerr(f); while(q&&n>p){ p+=q=fwrite(p+x,sizeof(C),(size_t)(n-p),f); if(ferror(f))R jerrno()?1:0; } R 1; } /* write/append string w to file f at j */
JError JWaitForChild ( const pid_t pid, ACE_exitcode* status ) { int err; do { jclear_errno(); ACE_OS::waitpid(pid, status, 0); err = jerrno(); } while (err == EINTR); return JNoError(); }
A jtrd(J jt,F f,I j,I n){A z;C*x;I p=0;size_t q=1; RZ(f); if(0>n){if(j<0) n=-j; else n=fsize(f)-j;} #if !SY_WINCE {INT64 v; v= j+((0>j)?fsize(f):0); fsetpos(f,(fpos_t*)&v);} #else fseek(f,(long)(0>j?1+j:j),0>j?SEEK_END:SEEK_SET); #endif clearerr(f); GA(z,LIT,n,1,0); x=CAV(z); while(q&&n>p){ p+=q=fread(p+x,sizeof(C),(size_t)(n-p),f); if(ferror(f))R jerrno(); } R z; } /* read file f for n bytes at j */
JError JWaitForChild ( const JBoolean block, pid_t* pid, ACE_exitcode* status ) { int err; do { jclear_errno(); *pid = ACE_OS::waitpid(-1, status, (block ? 0 : WNOHANG)); err = jerrno(); } while (err == EINTR); return JNoError(); }
JError JCreatePipe ( int fd[2] ) { jclear_errno(); if (_pipe(fd, 4096, _O_BINARY) == 0) { return JNoError(); } const int err = jerrno(); if (err == EMFILE || err == ENFILE) { return JTooManyDescriptorsOpen(); } else { return JUnexpectedError(err); } }
JError JRenameDirEntry ( const JCharacter* oldName, const JCharacter* newName ) { if (JNameUsed(newName)) { return JDirEntryAlreadyExists(newName); } else if (JSameDirEntry(oldName, newName)) { return JNoError(); } jclear_errno(); if (rename(oldName, newName) == 0) { return JNoError(); } const int err = jerrno(); if (err == EISDIR) { return JCantRenameFileToDirectory(oldName, newName); } else if (err == EXDEV) { return JCantRenameAcrossFilesystems(); } else if (err == ENOTEMPTY) { return JCantRenameToNonemptyDirectory(); } else if (err == EEXIST) { return JDirEntryAlreadyExists(newName); } else if (err == EBUSY) { return JFileBusy(newName); } else if (err == EINVAL) { return JDirectoryCantBeOwnChild(); } else if (err == EMLINK) { return JTooManyLinks(oldName); } else if (err == ENOTDIR) { return JComponentNotDirectory(oldName, newName); } else if (err == EFAULT) { return JSegFault(); } else if (err == EACCES || err == EPERM) { return JAccessDenied(oldName, newName); } else if (err == ENAMETOOLONG) { return JNameTooLong(); } else if (err == ENOENT) { return JBadPath(oldName, newName); } else if (err == ENOMEM) { return JNoKernelMemory(); } else if (err == EROFS) { return JFileSystemReadOnly(); } else if (err == ELOOP) { return JPathContainsLoop(oldName, newName); } else if (err == ENOSPC) { return JFileSystemFull(); } else { return JUnexpectedError(err); } }
JError JCreateSymbolicLink ( const JCharacter* src, const JCharacter* dest ) { jclear_errno(); if (symlink(src, dest) == 0) { return JNoError(); } const int err = jerrno(); if (err == EPERM || err == EACCES) { return JAccessDenied(dest); } else if (err == EFAULT) { return JSegFault(); } else if (err == ENAMETOOLONG) { return JNameTooLong(); } else if (err == ENOENT) { return JBadPath(dest); } else if (err == ENOTDIR) { return JComponentNotDirectory(dest); } else if (err == ENOMEM) { return JNoKernelMemory(); } else if (err == EROFS) { return JFileSystemReadOnly(); } else if (err == EEXIST) { return JDirEntryAlreadyExists(dest); } else if (err == ELOOP) { return JPathContainsLoop(dest); } else if (err == ENOSPC) { return JFileSystemFull(); } else if (err == EIO) { return JGeneralIO(); } else { return JUnexpectedError(err); } }
void SMTPMessage::Send() { HandleAddresses(); AppendToOutbox("From "); AppendToOutbox(*itsFrom); AppendToOutbox(" "); struct timeb tp; ftime(&tp); JString date(ctime(&(tp.time))); AppendToOutbox(date); std::istrstream is(date.GetCString(), date.GetLength()); JString dow; JString mon; JString day; JString rest; dow = JReadUntilws(is); mon = JReadUntilws(is); day = JReadUntilws(is); JReadAll(is, &rest); AppendToOutbox("Date: "); AppendToOutbox(dow); AppendToOutbox(", "); AppendToOutbox(day); AppendToOutbox(" "); AppendToOutbox(mon); AppendToOutbox(" "); AppendToOutbox(rest); JString addrStr = itsSMTPServer; if (!addrStr.Contains(":")) { addrStr += ":25"; } ACE_INET_Addr addr(addrStr); itsLink = new InetLink; assert(itsLink != NULL); itsConnector = new INETConnector; assert( itsConnector != NULL ); ACE_Synch_Options options(ACE_Synch_Options::USE_REACTOR, ACE_Time_Value(kMaxWaitSeconds)); if (itsConnector->connect(itsLink, addr, options) == -1 && jerrno() != EAGAIN) { JString notice = "No response from sendmail : Error number "; int errNumber = jerrno(); notice += JString(errNumber); JGetUserNotification()->ReportError(notice); itsDeleteTask = new JXTimerTask(1000,kJTrue); assert( itsDeleteTask != NULL ); itsDeleteTask->Start(); ListenTo(itsDeleteTask); Broadcast(SendFailure()); // itsLink = NULL; return; } itsTimeoutTask = new JXTimerTask(kMaxWaitSeconds * 1000,kJTrue); assert( itsTimeoutTask != NULL ); itsTimeoutTask->Start(); ListenTo(itsTimeoutTask); ClearWhenGoingAway(itsLink, &itsLink); }
JError JExecute ( const JCharacter* argv[], const JSize size, pid_t* childPID, const JExecuteAction toAction, int* toFD, const JExecuteAction origFromAction, int* fromFD, const JExecuteAction errAction, int* errFD ) { assert( size > sizeof(JCharacter*) ); assert( argv[ (size/sizeof(JCharacter*)) - 1 ] == NULL ); const JExecuteAction fromAction = (origFromAction == kJForceNonblockingPipe ? kJCreatePipe : origFromAction); assert( toAction != kJTossOutput && toAction != kJAttachToFromFD && toAction != kJForceNonblockingPipe ); assert( fromAction != kJAttachToFromFD ); assert( errAction != kJForceNonblockingPipe ); assert( (toAction != kJCreatePipe && toAction != kJAttachToFD) || toFD != NULL ); assert( (fromAction != kJCreatePipe && fromAction != kJAttachToFD) || fromFD != NULL ); assert( (errAction != kJCreatePipe && errAction != kJAttachToFD) || errFD != NULL ); JString progName; if (!JProgramAvailable(argv[0], &progName)) { return JProgramNotAvailable(argv[0]); } argv[0] = progName.GetCString(); int fd[3][2]; if (toAction == kJCreatePipe) { const JError err = JCreatePipe(fd[0]); if (!err.OK()) { return err; } } if (fromAction == kJCreatePipe) { const JError err = JCreatePipe(fd[1]); if (!err.OK()) { if (toAction == kJCreatePipe) { close(fd[0][0]); close(fd[0][1]); } return err; } } if (errAction == kJCreatePipe) { const JError err = JCreatePipe(fd[2]); if (!err.OK()) { if (toAction == kJCreatePipe) { close(fd[0][0]); close(fd[0][1]); } if (fromAction == kJCreatePipe) { close(fd[1][0]); close(fd[1][1]); } return err; } } pid_t pid; const JError err = JThisProcess::Fork(&pid); if (!err.OK()) { if (toAction == kJCreatePipe) { close(fd[0][0]); close(fd[0][1]); } if (fromAction == kJCreatePipe) { close(fd[1][0]); close(fd[1][1]); } if (errAction == kJCreatePipe) { close(fd[2][0]); close(fd[2][1]); } return err; } // child else if (pid == 0) { const int stdinFD = fileno(stdin); if (toAction == kJCreatePipe) { dup2(fd[0][0], stdinFD); close(fd[0][0]); close(fd[0][1]); } else if (toAction == kJAttachToFD) { dup2(*toFD, stdinFD); close(*toFD); } const int stdoutFD = fileno(stdout); if (fromAction == kJCreatePipe) { dup2(fd[1][1], stdoutFD); close(fd[1][0]); close(fd[1][1]); } else if (fromAction == kJAttachToFD) { dup2(*fromFD, stdoutFD); close(*fromFD); } else if (fromAction == kJTossOutput) { FILE* nullFile = fopen("/dev/null", "a"); int nullfd = fileno(nullFile); dup2(nullfd, stdoutFD); fclose(nullFile); } const int stderrFD = fileno(stderr); if (errAction == kJCreatePipe) { dup2(fd[2][1], stderrFD); close(fd[2][0]); close(fd[2][1]); } else if (errAction == kJAttachToFD) { dup2(*errFD, stderrFD); close(*errFD); } else if (errAction == kJTossOutput) { FILE* nullFile = fopen("/dev/null", "a"); int nullfd = fileno(nullFile); dup2(nullfd, stderrFD); fclose(nullFile); } else if (errAction == kJAttachToFromFD && fromAction != kJIgnoreConnection) { dup2(stdoutFD, stderrFD); } ACE_OS::execvp(argv[0], const_cast<char* const*>(argv)); cerr << "Unable to run program \"" << argv[0] << '"' << endl; cerr << endl; cerr << "JExecute()::execvp() failed" << endl; cerr << "Errno value: " << jerrno() << endl; JThisProcess::Exit(1); return JNoError(); } // parent else { if (origFromAction == kJForceNonblockingPipe) { pid_t pid2; const JError err2 = JThisProcess::Fork(&pid2); if (err2.OK() && pid2 == 0) { for (int i=0; i<150; i++) { JWait(0.1); int value = fcntl(fd[1][1], F_GETFL, 0); if (value & O_NONBLOCK) { cerr << "turning off nonblocking for cout: " << value << endl; fcntl(fd[1][1], F_SETFL, value & (~ O_NONBLOCK)); } } JThisProcess::Exit(0); return JNoError(); } JProcess* p = new JProcess(pid2); p->KillAtExit(kJTrue); } if (toAction == kJCreatePipe) { close(fd[0][0]); *toFD = fd[0][1]; } if (fromAction == kJCreatePipe) { close(fd[1][1]); *fromFD = fd[1][0]; } if (errAction == kJCreatePipe) { close(fd[2][1]); *errFD = fd[2][0]; } if (childPID == NULL) { return JWaitForChild(pid); } else { *childPID = pid; return JNoError(); } } }
JError JFOpen ( const JCharacter* fileName, const JCharacter* mode, FILE** stream ) { jclear_errno(); *stream = fopen(fileName, mode); if (*stream != NULL) { return JNoError(); } const int err = jerrno(); if (err == EINVAL) { return JInvalidOpenMode(fileName); } else if (err == EEXIST) { return JDirEntryAlreadyExists(fileName); } else if (err == EISDIR) { return JIsADirectory(); } else if (err == EACCES || err == ETXTBSY) { return JAccessDenied(fileName); } else if (err == EFAULT) { return JSegFault(); } else if (err == ENAMETOOLONG) { return JNameTooLong(); } else if (err == ENOENT) { return JBadPath(fileName); } else if (err == ENOTDIR) { return JComponentNotDirectory(fileName); } else if (err == EMFILE || err == ENFILE) { return JTooManyDescriptorsOpen(); } else if (err == ENOMEM) { return JNoKernelMemory(); } else if (err == EROFS) { return JFileSystemReadOnly(); } else if (err == ELOOP) { return JPathContainsLoop(fileName); } else if (err == ENOSPC) { return JFileSystemFull(); } else { return JUnexpectedError(err); } }
JError JCreateTempDirectory ( const JCharacter* path, const JCharacter* prefix, JString* fullName ) { JString p; if (!JStringEmpty(path)) { p = path; } else if (!JGetTempDirectory(&p)) { return JDirEntryDoesNotExist("/tmp"); } if (!JStringEmpty(prefix)) { p = JCombinePathAndName(p, prefix); } else { p = JCombinePathAndName(p, "temp_dir_"); } p += "XXXXXX"; char* s = p.AllocateCString(); jclear_errno(); char* d = mkdtemp(s); if (d != NULL) { *fullName = s; JAppendDirSeparator(fullName); delete [] s; return JNoError(); } fullName->Clear(); delete [] s; // EINVAL counts as unexpected const int err = jerrno(); if (err == EEXIST) { return JDirEntryAlreadyExists(p); } else if (err == EFAULT) { return JSegFault(); } else if (err == EACCES) { return JAccessDenied(p); } else if (err == ENAMETOOLONG) { return JNameTooLong(); } else if (err == ENOENT) { return JBadPath(p); } else if (err == ENOTDIR) { return JComponentNotDirectory(p); } else if (err == ENOMEM) { return JNoKernelMemory(); } else if (err == EROFS) { return JFileSystemReadOnly(); } else if (err == ELOOP) { return JPathContainsLoop(p); } else if (err == ENOSPC) { return JFileSystemFull(); } else { return JUnexpectedError(err); } }
static B jtdolock(J jt,B lk,F f,I i,I n){I e; e=lk?lock(fileno(f),i,n):unlock(fileno(f),i,n); R !e?1:errno==EACCES?0:jerrno(); }
JBoolean JRecurseFunction ( const JCharacter* origExpr, const JSize origLength, const JVariableList* theVariableList, JFunction** theFunction, const JBoolean allowUIF ) { *theFunction = NULL; // remove enclosing parentheses const JCharacter* expr = origExpr; const JSize length = JStripParentheses(&expr, origLength); if (length == 0) { (JGetUserNotification())->ReportError("You specified an empty function"); return kJFalse; } // check for summation (+,-) JParseResult result = JParseAsSummation(expr, length, theVariableList, theFunction, allowUIF); if (result == kJParsedOK) { return kJTrue; } else if (result == kJParseError) { return kJFalse; } // check for product before division // so we correctly parse x/y*z as (x/y)*z result = JParseAsProduct(expr, length, theVariableList, theFunction, allowUIF); if (result == kJParsedOK) { return kJTrue; } else if (result == kJParseError) { return kJFalse; } // check for division result = JParseAsDivision(expr, length, theVariableList, theFunction, allowUIF); if (result == kJParsedOK) { return kJTrue; } else if (result == kJParseError) { return kJFalse; } // check for exponentiation result = JParseAsExponentiation(expr, length, theVariableList, theFunction, allowUIF); if (result == kJParsedOK) { return kJTrue; } else if (result == kJParseError) { return kJFalse; } // check for standard function result = JParseAsFunctionWithArgs(expr, length, theVariableList, theFunction, allowUIF); if (result == kJParsedOK) { return kJTrue; } else if (result == kJParseError) { return kJFalse; } // check for function of discrete variable result = JParseAsFunctionOfDiscrete(expr, length, theVariableList, theFunction, allowUIF); if (result == kJParsedOK) { return kJTrue; } else if (result == kJParseError) { return kJFalse; } // check for named constant if (JIsNamedConstant(expr, length, theFunction)) { return kJTrue; } // check for variable name result = JParseAsNumericVariable(expr, length, theVariableList, theFunction, allowUIF); if (result == kJParsedOK) { return kJTrue; } else if (result == kJParseError) { return kJFalse; } // check for empty JUserInputFunction if (allowUIF && JStringsEqual(expr, length, JUserInputFunction::GetEmptyString())) { *theFunction = new JUserInputFunction(theVariableList, JGetCurrFontManager(), JGetCurrColormap()); assert( *theFunction != NULL ); return kJTrue; } // check for constant, must occupy entire string JString valueStr(expr, length); JBoolean isPercentage = kJFalse; if (valueStr.GetLastCharacter() == '%') { isPercentage = kJTrue; valueStr.RemoveSubstring(valueStr.GetLength(), valueStr.GetLength()); valueStr.TrimWhitespace(); } JFloat value; if (valueStr.ConvertToFloat(&value)) { if (isPercentage) { value /= 100.0; } *theFunction = new JConstantValue(value); assert( *theFunction != NULL ); return kJTrue; } else if (jerrno() == ERANGE) { JString errorStr(expr, length); errorStr.Prepend("\""); errorStr += "\" is too large to be represented."; (JGetUserNotification())->ReportError(errorStr); return kJFalse; } // this string is not a function JString errorStr(expr, length); errorStr.Prepend("\""); errorStr += "\" is not a valid function."; (JGetUserNotification())->ReportError(errorStr); return kJFalse; }
int main ( int argc, char* argv[] ) { if (argc == 1) { char buffer[BUFSIZ]; while (1) { ssize_t count = read(0, buffer, sizeof(buffer)); if (count < 0 && jerrno() == EINTR) { // keep going } else if (count <= 0) { break; } else { // cerr << count << endl; cout.write(buffer, count); JWait(0.01); } } return 0; } JProcess* p; int fromFD; const JError err = JProcess::Create(&p, argv[1], kJIgnoreConnection, NULL, kJForceNonblockingPipe, &fromFD, kJAttachToFromFD, NULL); if (err.OK()) { char buffer[BUFSIZ]; while (1) { ssize_t count = read(fromFD, buffer, sizeof(buffer)); if (count < 0 && jerrno() == EINTR) { // keep going } else if (count <= 0) { break; } else { // cerr << count << endl; cout.write(buffer, count); JWait(0.02); } } /* ProcessLink* link = new ProcessLink(fromFD); assert( link != NULL ); ACE_Time_Value delta(20); ACE_Reactor::instance()->run_reactor_event_loop(delta); link->Dump(); delete link; */ return 0; } else { JInitCore(); err.ReportIfError(); return 1; } }