char * ISpellChecker::loadDictionary (const char * szdict) { std::vector<std::string> dict_names; s_buildHashNames (dict_names, szdict); for (size_t i = 0; i < dict_names.size(); i++) { if (linit(const_cast<char*>(dict_names[i].c_str())) >= 0) return g_strdup (dict_names[i].c_str()); } return NULL; }
/*------------------------------------------------------------------------ * sysinit -- initialize all Xinu data structeres and devices *------------------------------------------------------------------------ */ LOCAL int sysinit() { int i,j; struct pentry *pptr; struct sentry *sptr; struct mblock *mptr; numproc = 0; /* initialize system variables */ nextproc = NPROC-1; nextsem = NSEM-1; nextlock = NLOCKS - 1; /* PA3 */ nextqueue = NPROC; /* q[0..NPROC-1] are processes */ map_pos = 0; /* initialize free memory list */ /* PC version has to pre-allocate 640K-1024K "hole" */ if (maxaddr+1 > (char *)HOLESTART) { memlist.mnext = mptr = (struct mblock *) roundmb(&end); mptr->mnext = (struct mblock *)HOLEEND; mptr->mlen = (int) truncew(((unsigned) HOLESTART - (unsigned)&end)); mptr->mlen -= 4; mptr = (struct mblock *) HOLEEND; mptr->mnext = 0; mptr->mlen = (int) truncew((unsigned)maxaddr - HOLEEND - NULLSTK); } else { /* initialize free memory list */ memlist.mnext = mptr = (struct mblock *) roundmb(&end); mptr->mnext = 0; mptr->mlen = (int) truncew((unsigned)maxaddr - (int)&end - NULLSTK); } for (i=0 ; i<NPROC ; i++) /* initialize process table */ proctab[i].pstate = PRFREE; pptr = &proctab[NULLPROC]; /* initialize null process entry */ pptr->pstate = PRCURR; for (j=0; j<7; j++) pptr->pname[j] = "prnull"[j]; pptr->plimit = (WORD)(maxaddr + 1) - NULLSTK; pptr->pbase = (WORD) maxaddr - 3; pptr->pesp = pptr->pbase-4; /* for stkchk; rewritten before used */ *( (int *)pptr->pbase ) = MAGIC; pptr->paddr = (WORD) nulluser; pptr->pargs = 0; pptr->pprio = 0; currpid = NULLPROC; linit(); for (i=0 ; i<NSEM ; i++) { /* initialize semaphores */ (sptr = &semaph[i])->sstate = SFREE; sptr->sqtail = 1 + (sptr->sqhead = newqueue()); } for(i = 0;i < TOTAL_MAPS;i++) lock_map[i] = -1; rdytail = 1 + (rdyhead=newqueue());/* initialize ready list */ #ifdef MEMMARK _mkinit(); /* initialize memory marking */ #endif #ifdef RTCLOCK clkinit(); /* initialize r.t.clock */ #endif pci_init(); /* PCI */ mon_init(); /* init monitor */ // ripinit(); #ifdef NDEVS for (i=0 ; i<NDEVS ; i++ ) { init_dev(i); } #endif return(OK); }
/********************* KINSol **************************************** * * This routine is the main driver of the KINSol package. It manages the * computational process of computing an approximate solution to the * system func(uu) = 0. Routine KINLinSolDrv handles the process of * obtaining a solution to the system J x = b , where x is an increment * from the last iterate uu. It then calls a global strategy routine * (either KINLinesearch or KINInexactNewton) to apply that increment xx * to the last iterate uu, creating a new iterate value uu. Finally * KINConstraint and KINStop are called to require that the user-specified * constraints are satisfied and if the iteration process has produced an * approximate iterate within the desired tolerance, resp. * * ****************************************************************************/ int KINSol(void *kinmem, integer Neq, N_Vector uu, SysFn func, int globalstrategy, N_Vector uscale, N_Vector fscale, real fnormtol, real scsteptol, N_Vector constraints, boole optIn, long int iopt[], real ropt[], void *f_data) { real fnormp = 0.0, f1normp = 0.0, epsmin = 0.0; int ret, globalstratret = 0; boole maxStepTaken = 0, noMinEps; N_Vector bb, xx; KINMem kin_mem; /* Check for legal memory pointers. */ kin_mem = (KINMem)kinmem; if (kinmem == NULL) { fprintf(stdout, MSG_KINSOL_NO_MEM); return(KINSOL_NO_MEM); } if (lmem == NULL) { fprintf(msgfp, MSG_LSOLV_NO_MEM); return(KINSOL_LSOLV_NO_MEM); } ret = KINSolInit(kinmem, Neq, uu, func, globalstrategy, uscale, fscale, fnormtol, scsteptol, constraints, optIn, iopt, ropt, f_data); if (ret < 0) { /* input errors */ fprintf(msgfp, " Input errors \n\n"); return(KINSOL_INPUT_ERROR); } else if (ret > 0) return(KINSOL_INITIAL_GUESS_OK); /* the initial guess satisfied the system func(uu)=0. , to the * required tolerances */ ret = linit(kin_mem, &setupNonNull); if (ret != 0) { fprintf(msgfp, MSG_LINIT_FAIL); return(KINSOL_INPUT_ERROR); } /* put in some define's for ease in working with the KINSol mem block */ #define Neq (kin_mem->kin_Neq) #define func (kin_mem->kin_func) #define f_data (kin_mem->kin_f_data) #define fnormtol (kin_mem->kin_fnormtol) #define scsteptol (kin_mem->kin_scsteptol) #define iopt (kin_mem->kin_iopt) #define ropt (kin_mem->kin_ropt) #define uu (kin_mem->kin_uu) #define uscale (kin_mem->kin_uscale) #define fscale (kin_mem->kin_fscale) #define globalstrategy (kin_mem->kin_globalstrategy) #define constraints (kin_mem->kin_constraints) #define ioptExists (kin_mem->kin_ioptExists) #define roptExists (kin_mem->kin_roptExists) #define sJpnorm (kin_mem->kin_sJpnorm) #define sfdotJp (kin_mem->kin_sfdotJp) ncscmx = 0; /* the following logic allows the choice of whether or not to force a call * to the preconditioner precond upon a given call to KINSol */ if (ioptExists && optIn) { if (iopt[PRECOND_NO_INIT] != 0 && iopt[PRECOND_NO_INIT] != 1) iopt[PRECOND_NO_INIT] = 0; } else pthrsh = TWO; if (ioptExists && optIn && iopt[PRECOND_NO_INIT] == 0) pthrsh = TWO; if (ioptExists && optIn && iopt[NO_MIN_EPS] > 0) noMinEps = TRUE; else { noMinEps = FALSE; epsmin = POINTOH1 * fnormtol; } loop { nni++; /* calculate the epsilon for this iteration based on eta from the * routine KINForcingTerm */ eps = (eta + uround) * fnorm; if (!noMinEps) eps = MAX(epsmin, eps); /* call KINLinSolDrv to calculate the approximate Newton step using * the appropriate Krylov algorithm */ /* use unew as work space for bb, the rhs vector, in the Newton steps * and pp as xx, the x in J x = b */ bb = unew; xx = pp; ret = KINLinSolDrv((struct KINMemRec *)kinmem, bb, xx); /* evaluate the return code from KINLinSolDrv */ if (ret != 0) break; /* call the appropriate routine to calculate an acceptable step pp */ if (globalstrategy == INEXACT_NEWTON) globalstratret = KINInexactNewton((struct KINMemRec *)kinmem, &fnormp, &f1normp, &maxStepTaken); else if (globalstrategy == LINESEARCH) globalstratret = KINLineSearch((struct KINMemRec *)kinmem, &fnormp, &f1normp, &maxStepTaken); /* if too many beta condition failures, stop iteration */ if (nbcf > MXNBCF) { ret = KINSOL_LINESEARCH_BCFAIL; break; } /* Evaluate eta by calling the forcing term routine */ if (callForcingTerm) KINForcingTerm((struct KINMemRec *)kinmem, fnormp); /* call KINStop to check if tolerances are met at this iteration */ fnorm = fnormp; ret = KINStop((struct KINMemRec *)kinmem, maxStepTaken, globalstratret); /* update uu after the iteration */ N_VScale(ONE, unew, uu); f1norm = f1normp; /* print out the current nni, fnorm, and nfe values for printfl>0) */ if (printfl > 0) fprintf(msgfp, "KINSol nni= %4ld fnorm= %26.16g nfe=%6ld\n", nni, fnorm, nfe); if (ret != 0) break; /* ret == 0 means keep iterating ; != 0 means there * is some reason to stop the iteration process and * return to the users code. */ fflush(msgfp); } /* End of step loop; load optional outputs and return */ if (ioptExists) { iopt[NNI] = nni; iopt[NFE] = nfe; iopt[NBCF] = nbcf; iopt[NBKTRK] = nbktrk; } if (roptExists) { ropt[FNORM] = fnorm; ropt[STEPL] = stepl; } if (printfl > 0) fprintf(msgfp, "KINSol return value %d\n", ret); if (printfl > 0) { if (ret == KINSOL_SUCCESS) fprintf(msgfp, "---KINSOL_SUCCESS\n"); if (ret == KINSOL_STEP_LT_STPTOL) fprintf(msgfp, "---KINSOL_STEP_LT_STPTOL\n"); if (ret == KINSOL_LNSRCH_NONCONV) fprintf(msgfp, "---KINSOL_LNSRCH_NONCONV"); if (ret == KINSOL_MAXITER_REACHED) fprintf(msgfp, "---KINSOL_MAXITER_REACHED\n"); if (ret == KINSOL_MXNEWT_5X_EXCEEDED) fprintf(msgfp, "---KINSOL_MXNEWT_5X_EXCEEDED\n"); if (ret == KINSOL_KRYLOV_FAILURE) fprintf(msgfp, "---KINSOL_KRYLOV_FAILURE\n"); if (ret == KINSOL_PRECONDSET_FAILURE) fprintf(msgfp, "---KINSOL_PRECONDSET_FAILURE\n"); if (ret == KINSOL_PRECONDSOLVE_FAILURE) fprintf(msgfp, "---KINSOL_PRECONDSOLVE_FAILURE\n"); } return(ret); }
/** * @brief ... * @param argc * @param argv * @param lib */ int my_main(int argc, char *argv[], char lib) { char *wchars = NULL; char *preftype = NULL; static char outbuf[BUFSIZ]; int arglen, old_argc; char *cpd = NULL; char *Cmd = *argv; /* Pointer to name of $(LIBDIR)/dict */ char *LibDict = NULL; islib = lib; old_argc = argc; Trynum = 0; sprintf(hashname, "%s/%s", LIBDIR, DEFHASH); strcpy(signs, DEFAULT_SIGNS); argv++; argc--; while (argc && **argv == '-') { /* * Trying to add a new flag? Can't remember what's been used? * Here's a handy guide: * * Used: * ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789 * ^^^^ ^^^ ^ ^^ ^^ * abcdefghijklmnopqrstuvwxyz * ^^^^^^* ^^^*^ ^^*^^^* */ arglen = strlen(*argv); add_inc = 0; switch ((*argv)[1]) { case 'v': option_v(Cmd, argc, argv, arglen); break; case 'n': preftype = option_n(Cmd, preftype, arglen); break; case 't': /* TeX mode */ preftype = option_t(Cmd, preftype, arglen); break; case 'T': /* Set preferred file type */ preftype = option_T(Cmd, argc, argv); break; case 'A': option_A(Cmd, arglen); break; case 'a': option_a(Cmd, arglen); break; case 'D': option_D(Cmd, arglen); break; case 'J': option_J(Cmd, arglen); break; case 'e': option_e(Cmd, arglen, argv); break; case 'c': option_c(Cmd, arglen, argv); break; case 'b': option_b(Cmd, arglen); break; case 'x': option_x(Cmd, arglen); break; case 'f': option_f(Cmd, argc, argv); break; case 'L': option_L(Cmd, argc, argv); break; case 'l': option_l(Cmd, arglen); break; case 'S': option_S(Cmd, arglen); break; case 'B': /* -B: report missing blanks */ option_B(Cmd, arglen); break; case 'C': /* -C: compound words are acceptable */ option_C(Cmd, arglen); break; case 'P': /* -P: don't gen non-dict poss's */ option_P(Cmd, arglen); break; case 'm': /* -m: make all poss affix combos*/ option_m(Cmd, arglen); break; case 'N': /* -N: suppress minimenu */ option_N(Cmd, arglen); break; case 'M': option_M(Cmd, arglen); break; /* -M: force minimenu */ case 'p': option_p(LibDict, &cpd, Cmd, argc, argv); break; case 'd': option_d(LibDict, cpd, Cmd, argc, argv); break; case 'V': /* Display 8-bit characters as M-xxx */ option_V(Cmd, arglen); break; case 'w': wchars = (*argv)+2; if (*wchars == '\0') { argv++; argc--; if (argc == 0) usage(Cmd); wchars = *argv; } break; case 'W': option_W(Cmd, argc, argv); break; case 'o': option_o(Cmd, argc, argv); break; case 'g': option_g(Cmd, arglen); break; case 'u': option_u(Cmd, arglen); break; case 'y': option_y(Cmd, arglen); break; case 'z': option_z(Cmd, arglen); break; default: usage(Cmd); } /* end switch */ if (add_inc) { argv++; argc--; } argv++; argc--; } if (!argc && !lflag && !aflag && !eflag && !dumpflag) usage(Cmd); verify_files(argc, argv); if (!oflag) strcpy(o_form, DEF_OUT); if (linit() < 0) exit(1); /* Force an error */ det_prefstringchar(preftype); if (prefstringchar < 0) defdupchar = 0; else defdupchar = prefstringchar; if (missingspaceflag < 0) missingspaceflag = hashheader.defspaceflag; if (tryhardflag < 0) tryhardflag = hashheader.defhardflag; initckch(wchars); process_LibDict(LibDict, cpd); if (process_a_e_and_d_flags() == 0) return 0; if (!islib) setbuf(stdout, outbuf); /* process lflag (also used with the -c option) */ if (lflag) { infile = stdin; outfile = stdout; if (!islib) checkfile(); return 0; } /* n. of parameters advanced */ return old_argc - argc; }