static PyObject *pywrapper_solver(PyObject *self,PyObject *args) { int checkder,inform,iprint,m,n,ncomp; double cnorm,f,nlpsupn,epsfeas,epsopt,snorm; int coded[10]; int *equatn,*linear; double *l,*lambda,*u,*x; return_value = Py_None; setbuf(stderr,(char *) malloc(BUFSIZ)); if (!PyArg_ParseTuple(args,"O!O!O!O!O!O!O!O!O!O!O!O!O!:solver", &PyFunction_Type,&evalf_py, &PyFunction_Type,&evalg_py, &PyFunction_Type,&evalh_py, &PyFunction_Type,&evalc_py, &PyFunction_Type,&evaljac_py, &PyFunction_Type,&evalhc_py, &PyFunction_Type,&evalfc_py, &PyFunction_Type,&evalgjac_py, &PyFunction_Type,&evalhl_py, &PyFunction_Type,&evalhlp_py, &PyFunction_Type,&inip_py, &PyFunction_Type,&endp_py, &PyDict_Type,¶m_py)) goto cleanup; Py_INCREF(evalf_py ); Py_INCREF(evalg_py ); Py_INCREF(evalh_py ); Py_INCREF(evalc_py ); Py_INCREF(evaljac_py ); Py_INCREF(evalhc_py ); Py_INCREF(evalfc_py ); Py_INCREF(evalgjac_py); Py_INCREF(evalhl_py ); Py_INCREF(evalhlp_py ); Py_INCREF(inip_py ); Py_INCREF(endp_py ); Py_INCREF(param_py ); param(&epsfeas,&epsopt,&iprint,&ncomp); if (return_value == NULL) goto cleanup; inip(&n,&x,&l,&u,&m,&lambda,&equatn,&linear,coded,&checkder); if (return_value == NULL) goto cleanup; C2FLOGICALV(equatn,m); C2FLOGICALV(linear,m); C2FLOGICALV(coded,10); Algencan(epsfeas,epsopt,iprint,ncomp,n,x,l,u,m,lambda,equatn, linear,coded,checkder,f,cnorm,snorm,nlpsupn,inform); if (return_value == NULL) goto cleanup; endp(n,x,l,u,m,lambda,equatn,linear); if (return_value == NULL) goto cleanup; cleanup: Py_XDECREF(evalf_py ); Py_XDECREF(evalg_py ); Py_XDECREF(evalh_py ); Py_XDECREF(evalc_py ); Py_XDECREF(evaljac_py ); Py_XDECREF(evalhc_py ); Py_XDECREF(evalfc_py ); Py_XDECREF(evalgjac_py); Py_XDECREF(evalhl_py ); Py_XDECREF(evalhlp_py ); Py_XDECREF(inip_py ); Py_XDECREF(endp_py ); Py_XDECREF(param_py ); fflush(stdout); fflush(stderr); Py_XINCREF(return_value); return return_value; }
static CONN_STATE process( const POLL_MODE pollMode, const char callGrade ) { KWBoolean master = (KWBoolean) ( pollMode == POLL_ACTIVE ? KWTrue : KWFalse ); KWBoolean aborted = KWFalse; XFER_STATE state = (XFER_STATE) (master ? XFER_SENDINIT : XFER_RECVINIT); XFER_STATE old_state = XFER_EXIT; /* Initialized to any state but the original value of "state" */ XFER_STATE save_state = XFER_EXIT; char currentGrade = (char) ((unsigned char) 0xff); /*--------------------------------------------------------------------*/ /* Yea old state machine for the high level file transfer procotol */ /*--------------------------------------------------------------------*/ while( state != XFER_EXIT ) { printmsg(state == old_state ? 14 : 4 , "process: Machine state is = %c", state ); old_state = state; if ( terminate_processing != aborted ) { aborted = terminate_processing; state = XFER_ABORT; } switch( state ) { case XFER_SENDINIT: /* Initialize outgoing protocol */ state = sinit(); break; case XFER_RECVINIT: /* Initialize Receive protocol */ state = rinit(); break; case XFER_MASTER: /* Begin master mode */ master = KWTrue; state = XFER_NEXTJOB; resetGrade( ); /* Reset best grade status */ currentGrade = E_firstGrade; break; case XFER_SLAVE: /* Begin slave mode */ master = KWFalse; state = XFER_RECVHDR; break; case XFER_NEXTJOB: /* Look for work in local queue */ state = scandir( rmtname, currentGrade ); break; case XFER_REQUEST: /* Process next file in current job in queue */ state = newrequest(); break; case XFER_PUTFILE: /* Got local transmit request */ state = ssfile(); break; case XFER_GETFILE: /* Got local tranmit request */ state = srfile(); break; case XFER_SENDDATA: /* Remote accepted our work, send data */ state = sdata(); break; case XFER_SENDEOF: /* File xfer complete, send EOF */ state = seof( master ); break; case XFER_FILEDONE: /* Receive or transmit is complete */ state = (XFER_STATE) (master ? XFER_REQUEST : XFER_RECVHDR); break; case XFER_NEXTGRADE: /* Process next grade of local files */ currentGrade = nextGrade( callGrade ); if ( currentGrade ) state = XFER_NEXTJOB; else state = XFER_NOLOCAL; break; case XFER_NOLOCAL: /* No local work, remote have any? */ state = sbreak(); break; case XFER_NOREMOTE: /* No remote work, local have any? */ state = schkdir( (KWBoolean) (pollMode == POLL_ACTIVE ? KWTrue : KWFalse ), callGrade ); break; case XFER_RECVHDR: /* Receive header from other host */ state = rheader(); break; case XFER_TAKEFILE: /* Set up to receive remote requested file transfer */ state = rrfile(); break; case XFER_GIVEFILE: /* Set up to transmit remote requuest file transfer */ state = rsfile(); break; case XFER_RECVDATA: /* Receive file data from other host */ state = rdata(); break; case XFER_RECVEOF: state = reof(); break; case XFER_LOST: /* Lost the other host, flame out */ printmsg(0,"process: Connection lost to %s, " "previous system state = %c", rmtname, save_state ); hostp->status.hstatus = HS_CALL_FAILED; state = XFER_EXIT; break; case XFER_ABORT: /* Internal error, flame out */ printmsg(0,"process: Aborting connection to %s, " "previous system state = %c", rmtname, save_state ); hostp->status.hstatus = HS_CALL_FAILED; state = XFER_ENDP; break; case XFER_ENDP: /* Terminate the protocol */ state = endp(); break; default: printmsg(0,"process: Unknown state = %c, " "previous system state = %c", state, save_state ); state = XFER_ABORT; break; } /* switch */ save_state = old_state; /* Used only if we abort */ } /* while( state != XFER_EXIT ) */ /*--------------------------------------------------------------------*/ /* Protocol is complete, terminate the connection */ /*--------------------------------------------------------------------*/ return CONN_TERMINATE; } /* process */
void CChildView::OnFileOpen() { CFileDialog* fd = new CFileDialog(true, _T("jfd"), _T("*.jfd")); wstring fileName; fd->m_ofn.lpstrTitle = TEXT("Open save file"); fd->m_ofn.lpstrFilter = TEXT("JFDraw Files (*.jfd)"); if (fd->DoModal() == IDOK) { fileName = fd->GetPathName(); ifstream file(fileName); string rawline; CChildView::Reset(); while (getline(file, rawline)) { if (!rawline.empty()) { stringstream line(rawline); string seg; vector<string> segs; while (getline(line, seg, ',')) { segs.push_back(seg); } if (segs.size() != 7) { continue; } CPoint startp(stoi(segs[1]), stoi(segs[2])); CPoint endp(stoi(segs[3]), stoi(segs[4])); int penWidth = stoi(segs[5]); string text = segs[6]; Fraint::Shape* shape; if (segs[0] == "Circle") { shape = new Fraint::Circle(startp, endp); } else if (segs[0] == "Rectangle") { shape = new Fraint::Rectangle(startp, endp); } else if (segs[0] == "Ellipse") { shape = new Fraint::Ellipse(startp, endp); } else if (segs[0] == "Square") { shape = new Fraint::Square(startp, endp); } else { continue; } shape->SetPenWidth(penWidth); shape->SetText(text); m_Shapes.push_back(shape); } } RedrawShapes(); file.close(); } }