PGPError pgpGetMinValidity( PGPOptionListRef optionList, PGPValidity *failValidity, /* Output parameters */ PGPValidity *warnValidity ) { PGPError err; PGPOption op; PGPUInt32 temp; /* Init return pointers */ pgpa( pgpaAddrValid( failValidity, PGPValidity ) ); pgpa( pgpaAddrValid( warnValidity, PGPValidity ) ); /* XXX Need to fix these based on trust model and other aspects */ *failValidity = kPGPValidity_Unknown; *warnValidity = kPGPValidity_Marginal; if( IsPGPError( err = pgpSearchOptionSingle( optionList, kPGPOptionType_FailBelowValidity, &op ) ) ) goto error; if( IsOp( op ) ) { if( IsPGPError( err = pgpOptionUInt( &op, &temp ) ) ) goto error; *failValidity = (PGPValidity)temp; } if( IsPGPError( err = pgpSearchOptionSingle( optionList, kPGPOptionType_WarnBelowValidity, &op ) ) ) goto error; if( IsOp( op ) ) { if( IsPGPError( err = pgpOptionUInt( &op, &temp ) ) ) goto error; *warnValidity = (PGPValidity)temp; } return kPGPError_NoErr; error: return err; }
double Expression::Parse(const string& token, vector<vector<Expression> >& sSheet, deque<double>& terms) { if (token.length() == 0) { throw runtime_error("Parsing failed: please trim whitespace"); } else if (IsVal(token)) { return atof(token.c_str()); } else if (IsRef(token)) { return Deref(token, sSheet); } else if (IsOp(token)) { return Oper(token, terms); } else { throw runtime_error("Parsing failed with: " + token); } }
inline Node2D* Eval2D(std::string & s){ std::string T; if(isdigit(s[0])){ T=GetNumber(s); if(s.size()>0){ if(IsOp(s[0])){ char Op=s[0]; s.erase(s.begin()); return new OperatorNode2D(T,s,Op); } } else return new Leaf2D(T); } else if(s[0]=='x'||s[0]=='y'){ if(s.size()==1) return new Leaf2D(s); else{ T+=s[0]; s.erase(s.begin()); char Op=s[0]; s.erase(s.begin()); return new OperatorNode2D(T,s,Op); } } else if(IsFunc(s[0])){ T=GetFunc(s); if(OnlyFunc(T+s)){return new FunctionNode2D(T);} else{ char op=s[0]; s.erase(s.begin()); return new OperatorNode2D(T,s,op); } } if(OnlyParenth(s)){ s.erase(s.begin()); s.pop_back(); return Eval2D(s); } T=GetParenth(s); char op=s[0]; s.erase(s.begin()); return new OperatorNode2D(T,s,op); }
char* CalcExpresion(char* str) { char* cp = str; int num[BUF_MAX] = { 0, }; // 숫자배열 저장 char op[BUF_MAX][2] = { 0, }; // 0번행은 Op저장, 1번행은 우선순위 저장 char temp[BUF_MAX] = { 0, }; char A[BUF_MAX] = { 0, }; char P[2] = { 0, 0 }; int flagMinus = 1; int i = 0; int idxNum = 0; int idxOp = 0; int eval = 0; switch(*str) // 첫번째 글자체크 비연속 +, 비연속 -, 숫자 만 허용하고 나머지는 모두 에러 { case '+': zStrcpy(temp, str); zStrcpy(str, temp+1); break; case '-': if (*(str+1) == '-') { flagMinus = 1; zStrcpy(temp, str); zStrcpy(str, temp+2); break; } flagMinus = -1; zStrcpy(temp, str); zStrcpy(str, temp+1); break; default: if (!IsDigit(*str)) { Error("!!! The Expresion has Error !!!\n"); } break; } while (*str != '\0') // 첫번째 기호를 제거했기 때문에 첫번째 글자는 숫자로 시작한다. { if (!(IsOp(*str) || IsDigit(*str))) // 숫자나 기호만 허용된다. { Error("!!! The Expresion has Error !!!\n"); } i = 0; while (IsDigit(*str)) { A[i] = *str; // atoi() 용 임시버퍼 i++; str++; } num[idxNum] = zAtoi(A) * flagMinus; flagMinus = 1; idxNum++; while (i-- != 0) { A[i] = '\0'; } if (!IsOp(*str)) { if (op[0][0] == 0) { break; } if (*str == '\0') { break; } Error("!!! The Expresion has Error !!!\n"); } while (IsOp(*str)) { P[0] = *str++; P[1] = *str; if (IsDigit(P[1])) { break; } switch (P[1]) { case '+': str++; break; case '-': flagMinus = -1; str++; break; case '*': case '/': case '%': Error("!!! The Expresion has Error !!!\n"); default: Error("!!! The Expresion has Error !!!\n"); } break; } op[idxOp][0] = P[0]; idxOp++; P[0] = 0; P[1] = 0; } OrderOp(op); // Op 배열에 우선순위를 기록한다. eval = EvalExpresion(num, op); return zItoa(eval, cp); }
PGPError pgpSetupOutputPipeline( PGPContextRef context, /* Input params */ PGPOptionListRef optionList, PGPEnv *env, PGPBoolean fEncrypt, PGPBoolean fSign, PGPBoolean fDetachedSig, PGPBoolean fAppendOutput, PGPBoolean fExported509Keys, PGPPipeline ***tail, /* Input/output param */ PFLConstFileSpecRef *outFileRef, /* Output params */ PGPFile **pfout, PGPByte **outBufPtr, PGPByte ***outBufPtrPtr, PGPSize *outBufLength, PGPSize **outBufUsed, PGPPipeline **outPipe ) { PGPOption op; /* Selected option from list */ PGPError err; /* Error return code */ PGPFileType filetype; /* Type of output file we open */ PGPUInt32 fDiscard; /* Discard output option flag */ PGPBoolean fArmor; /* Ascii armor */ PGPMemoryMgrRef memoryMgr = NULL; /* Init return data to default states */ pgpa( pgpaAddrValid( outFileRef, PFLConstFileSpecRef ) ); pgpa( pgpaAddrValid( pfout, PGPFile * ) ); pgpa( pgpaAddrValid( outBufPtr, PGPByte * ) ); pgpa( pgpaAddrValid( outBufLength, PGPSize ) ); pgpa( pgpaAddrValid( outBufUsed, PGPSize * ) ); pgpa( pgpaAddrValid( outPipe, PGPPipeline * ) ); *outFileRef = NULL; *pfout = NULL; *outBufPtr = NULL; *outBufLength = 0; *outBufUsed = NULL; *outPipe = NULL; memoryMgr = PGPGetContextMemoryMgr( context ); /* See if there is an output file specified */ if( IsPGPError( err = pgpSearchOptionSingle( optionList, kPGPOptionType_OutputFileRef, &op ) ) ) goto error; if( IsOp( op ) ) { /* Have an output file specified */ PGPFileOpenFlags flags; if( IsPGPError( err = pgpOptionPtr( &op, (void **)outFileRef ) ) ) goto error; /* See whether we are outputing an encrypted vs ascii armored file */ fArmor = pgpenvGetInt( env, PGPENV_ARMOR, NULL, NULL ); if( fArmor) { filetype = kPGPFileTypeArmorFile; } else if( fEncrypt ) { filetype = kPGPFileTypeEncryptedData; } else if( fSign ) { if( fDetachedSig ) { filetype = kPGPFileTypeDetachedSig; } else { filetype = kPGPFileTypeSignedData; } } else if( fExported509Keys ) { filetype = kPGPFileTypeExported509Keys; } else { pgpDebugMsg( "pgpSetupOutputPipeline(): Unknown file type" ); filetype = kPGPFileTypeNone; } /* Open output file */ flags = fAppendOutput ? kPGPFileOpenStdAppendFlags : kPGPFileOpenStdWriteFlags ; *pfout = pgpFileRefOpen( context, *outFileRef, flags, filetype, &err ); if( NULL==(int)( *pfout ) ) { goto error; } /* Set up output pipeline. This reads and writes *tail. */ if( NULL==(int)( pgpFileWriteCreate( context, *tail, *pfout, 1 ) ) ) { err = kPGPError_OutOfMemory; goto error; } } /* See if there is an output buffer specified */ if( IsPGPError( err = pgpSearchOptionSingle( optionList, kPGPOptionType_OutputBuffer, &op ) ) ) goto error; if( IsOp( op ) ) { /* Have an output buffer specified */ if( NULL!=(int)( *outFileRef ) ) { pgpDebugMsg( "Error: multiple output options" ); err = kPGPError_BadParams; goto error; } if( IsPGPError( err = pgpOptionPtrLengthPtr( &op, (void **)outBufPtr, outBufLength, (void **)outBufUsed ) ) ) goto error; *outPipe = pgpMemModCreate( context, *tail, (char *) *outBufPtr, *outBufLength); if ( NULL==(int)( *outPipe ) ) { err = kPGPError_OutOfMemory; /* What else could it be? */ goto error; } if( fAppendOutput ) { /* Skip past existing buffer contents */ if( IsPGPError( err = (*outPipe)->annotate( *outPipe, NULL, PGPANN_MEM_PREPEND, (unsigned char *)*outBufPtr, **outBufUsed ) ) ) goto error; } } /* Check for variable-sized output buffer specification */ if( IsPGPError( err = pgpSearchOptionSingle( optionList, kPGPOptionType_OutputAllocatedBuffer, &op ) ) ) goto error; if( IsOp( op ) ) { /* Have an output buffer specified */ if( NULL!=(int)( *outFileRef ) || NULL!=(int)( *outBufPtr ) ) { pgpDebugMsg( "Error: multiple output options" ); err = kPGPError_BadParams; goto error; } if( IsPGPError( err = pgpOptionPtrLengthPtr( &op, (void **)outBufPtrPtr, outBufLength, (void **)outBufUsed ) ) ) goto error; *outPipe = pgpVariableMemModCreate( context, *tail, *outBufLength ); if ( NULL==(int)( *outPipe ) ) { err = kPGPError_OutOfMemory; /* What else could it be? */ goto error; } if( fAppendOutput && **outBufUsed != 0 ) { /* Prepend existing buffer contents */ if( IsPGPError( err = (*outPipe)->annotate( *outPipe, NULL, PGPANN_MEM_PREPEND, (unsigned char *)**outBufPtrPtr, **outBufUsed ) ) ) goto error; /* Free buffer now that we have captured it */ PGPFreeData( **outBufPtrPtr ); **outBufPtrPtr = NULL; } } if( IsPGPError( err = pgpFindOptionArgs( optionList, kPGPOptionType_DiscardOutput, FALSE, "%d", &fDiscard ) ) ) goto error; if( fDiscard ) { /* User wants to go to /dev/null */ if( NULL!=(int)( *outFileRef ) || NULL!=(int)( *outBufPtr ) || NULL!=(int)( *outBufPtrPtr ) ) { pgpDebugMsg( "Error: multiple output options" ); err = kPGPError_BadParams; goto error; } if ( NULL==(int)( pgpDevNullCreate( context, *tail ) ) ) { err = kPGPError_OutOfMemory; /* What else could it be? */ goto error; } } else if( NULL==(int)( *outFileRef ) && NULL==(int)( *outBufPtr ) && NULL==(int)( *outBufPtrPtr ) ) { pgpDebugMsg( "Error: no output options" ); err = kPGPError_BadParams; goto error; } return kPGPError_NoErr; error: *outFileRef = NULL; if( NULL!=(int)( *pfout ) ) { pgpFileClose( *pfout ); *pfout = NULL; } *outBufPtr = NULL; *outBufPtrPtr = NULL; *outBufLength = 0; *outPipe = NULL; return err; }
PGPError pgpSetupInput( PGPContextRef context, /* Input params */ PGPOptionListRef optionList, PgpLiteralParams *literal, PGPRandomContext *rng, PGPBoolean inputMode, PGPBoolean detachedSignature, PFLConstFileSpecRef *inFileRef, /* Output params */ PGPFileRead **pfrin, PGPFileDataType *inFileDataType, PGPByte **inBufPtr, PGPSize *inBufLength ) { PGPOption op; /* Selected option from list */ PGPError err; /* Error return code */ static char fyeomagic[] = "_CONSOLE"; /* Display-only mode */ PGPUInt32 localEncode; /* Special input encoding (macbin) */ PGPFileOpenFlags localEncodeFlags; /* Flag form of localEncode */ PGPByte const *peekBuf; /* For RNG seeding from file */ PGPSize peekLength; /* Length of peekBuf */ /* Init return data to default states */ pgpa( pgpaAddrValid( inFileRef, PFLConstFileSpecRef ) ); pgpa( pgpaAddrValid( pfrin, PGPFileRead * ) ); pgpa( pgpaAddrValid( inFileDataType, PGPFileDataType ) ); pgpa( pgpaAddrValid( inBufPtr, PGPByte * ) ); pgpa( pgpaAddrValid( inBufLength, PGPSize ) ); *inFileRef = NULL; *pfrin = NULL; *inFileDataType = kPGPFileDataType_Unknown; *inBufPtr = NULL; *inBufLength = 0; if( NULL!=(int)( literal) ) { pgpa( pgpaAddrValid( literal, PgpLiteralParams ) ); literal->filename = NULL; literal->timestamp = ( PGPUInt32 ) 0; } if( NULL!=(int)( literal ) ) { /* First check "for your eyes only" mode, flag with magic filename */ PGPUInt32 fFYEO; if( IsPGPError( err = pgpFindOptionArgs( optionList, kPGPOptionType_ForYourEyesOnly, FALSE, "%d", &fFYEO ) ) ) goto error; if( fFYEO ) { literal->filename = pgpAllocCString( context, fyeomagic ); } } /* See if there is an input file specified */ if( IsPGPError( err = pgpSearchOptionSingle( optionList, kPGPOptionType_InputFileRef, &op ) ) ) goto error; if( IsOp( op ) ) { /* File input */ if( IsPGPError( err = pgpOptionPtr( &op, (void **)inFileRef ) ) ) goto error; if( NULL!=(int)( literal ) ) { if( NULL==(int)( literal->filename ) ) { char *filerefname; void *vfilerefname; if( IsPGPError( err = pgpFindOptionArgs( optionList, kPGPOptionType_InputFileName, FALSE, "%p", &vfilerefname ) ) ) goto error; filerefname = (char *)vfilerefname; if( NULL!=(int)( filerefname ) ) { literal->filename = pgpAllocCString( context, filerefname ); } else { filerefname = pgpGetFileRefName( *inFileRef ); literal->filename = pgpAllocCString( context, filerefname ); PGPFreeData( filerefname ); } } } localEncodeFlags = (PGPFileOpenFlags)0; if( inputMode ) { if( IsPGPError( err = pgpSearchOptionSingle( optionList, kPGPOptionType_LocalEncoding, &op ) ) ) goto error; if( IsOp( op ) ) { if( IsPGPError( err = pgpOptionUInt( &op, &localEncode ) ) ) goto error; localEncodeFlags = pgpLocalEncodingToFlags( localEncode ); } } localEncodeFlags |= kPGPFileOpenReadPerm; if( detachedSignature) { localEncodeFlags |= kPGPFileOpenLocalEncodeHashOnly; } /* Open input file */ *pfrin = pgpFileRefReadCreate( context, *inFileRef, localEncodeFlags, &err, inFileDataType ); if( NULL==(int)( *pfrin ) ) { goto error; } if( NULL!=(int)( rng ) ) { /* Add some data from the file to the RNG for more entropy */ peekBuf = pgpFileReadPeek( *pfrin, &peekLength ); pgpRandomAddBytes( rng, peekBuf, peekLength ); } } /* See if there is a buffer specified */ if( IsPGPError( err = pgpSearchOptionSingle( optionList, kPGPOptionType_InputBuffer, &op ) ) ) goto error; if( IsOp( op ) ) { /* Buffer input */ if ( NULL!=(int)( *inFileRef ) ) { /* Error if buffer input also specified */ pgpDebugMsg( "Error: multiple input options" ); err = kPGPError_BadParams; goto error; } if( NULL!=(int)( literal ) ) { /* * Fake up filename if FYEO mode above didn't set it. * Earlier versions of PGP used the fake filename "stdin". * However this cannot be distinguished from the case where * a file with that name is encrypted. We will change to using * an empty string for this case, if no name was specified. */ if( NULL==(int)( literal->filename ) ) { char *filerefname; void *vfilerefname; if( IsPGPError( err = pgpFindOptionArgs( optionList, kPGPOptionType_InputFileName, FALSE, "%p", &vfilerefname ) ) ) goto error; filerefname = (char *)vfilerefname; if( NULL==(int)( filerefname ) ) { filerefname = (char *)""; } literal->filename = pgpAllocCString( context, filerefname ); } } if( IsPGPError( err = pgpOptionPtrLength( &op, (void **)inBufPtr, inBufLength ) ) ) goto error; if( NULL!=(int)( rng ) ) { /* Pre-seed RNG with some entropy from buffer */ pgpRandomAddBytes( rng, *inBufPtr, pgpMin( 1024, *inBufLength ) ); } } /* Must have some input */ if ( NULL==(int)( *inBufPtr ) && NULL==(int)( *inFileRef ) ) { pgpDebugMsg( "Error: no input options" ); err = kPGPError_BadParams; goto error; } return kPGPError_NoErr; error: *inFileRef = NULL; if( NULL!=(int)( *pfrin ) ) { pgpFileReadDestroy( *pfrin ); *pfrin = NULL; } *inBufPtr = NULL; *inBufLength = 0; if( NULL!=(int)( literal ) ) { if( NULL!=(int)( literal->filename ) ) { pgpContextMemFree( context, (char *)literal->filename ); literal->filename = NULL; } } return err; }