void *vec_gro(void *v, size_t s) { unsigned int i; unsigned int j; unsigned int n; void *w; /* Determine the total length and last free record of vector (v, s). */ for (j = 0; LAST(v, s, j) == 0; j = NEXT(v, s, j)) ; n = NEXT(v, s, j); /* Reallocate the vector at twice the size and extend the free list. */ if ((w = realloc(v, 2 * n * s))) { for (i = n; i < 2 * n - 1; ++i) { NEXT(w, s, i) = i + 1; LAST(w, s, i) = 0; } NEXT(w, s, i) = i + 1; LAST(w, s, i) = 1; LAST(w, s, j) = 0; return w; } return NULL; }
int WWIV_make_path(const char *s) { char current_path[MAX_PATH], *p, *flp; p = flp = WWIV_STRDUP(s); getcwd(current_path, MAX_PATH); if (LAST(p) == WWIV_FILE_SEPERATOR_CHAR) { LAST(p) = 0; } if (*p == WWIV_FILE_SEPERATOR_CHAR) { chdir(WWIV_FILE_SEPERATOR_STRING); p++; } for (; (p = strtok(p, WWIV_FILE_SEPERATOR_STRING)) != 0; p = 0) { if (chdir(p)) { if (mkdir(p)) { chdir(current_path); return -1; } chdir(p); } } chdir(current_path); if (flp) { free(flp); } return 0; }
unsigned int vec_add(void *v, size_t s) { /* Return the first record on the free list. */ if (LAST(v, s, 0) == 0) { unsigned int i = NEXT(v, s, 0); NEXT(v, s, 0) = NEXT(v, s, i); LAST(v, s, 0) = LAST(v, s, i); return i; } return 0; }
int make_path(char *s) { SEH_PUSH("make_path"); char current_path[MAX_PATH], *p, *flp; p = flp = _strdup(s); _getdcwd(0, current_path, MAX_PATH); int current_drive = toupper(*current_path) - '@'; if (LAST(p) == WWIV_FILE_SEPERATOR_CHAR) { LAST(p) = 0; } if (p[1] == ':') { int drive = toupper(p[0]) - 'A' + 1; if (_chdrive(drive)) { _chdir(current_path); _chdrive(current_drive); return -2; } p += 2; } if ( *p == WWIV_FILE_SEPERATOR_CHAR ) { _chdir( WWIV_FILE_SEPERATOR_STRING ); p++; } for (; (p = strtok(p, WWIV_FILE_SEPERATOR_STRING)) != 0; p = 0) { if (_chdir(p)) { if (_mkdir(p)) { _chdir(current_path); _chdrive(current_drive); return -1; } _chdir(p); } } _chdir(current_path); if (flp) { free(flp); } return 0; }
void vec_del(void *v, size_t s, unsigned int k) { unsigned int i; /* Insert record K into the free list. */ for (i = 0; i < k; i = NEXT(v, s, i)) if (k < NEXT(v, s, i)) { NEXT(v, s, k) = NEXT(v, s, i); LAST(v, s, k) = LAST(v, s, i); NEXT(v, s, i) = k; LAST(v, s, i) = 0; } }
int main(int argc, char **argv) { if (argc < 2) { print_usage(); } int option; while((option = getopt(argc, argv, "f:i:l:w")) != -1) { switch (option) { case 'i' : FIRST_INC_LAST(atoi(optarg), atoi(optarg), atoi(optarg)); break; case 'f' : FIRST_LAST(atoi(optarg), atoi(optarg)); break; case 'l' : LAST(atoi(optarg)); break; case '?' : printf("Unknown option %c. \n", optopt); break; default : print_usage(); } } return 0; }
void *List_remove_it(List *l, List_Iterator *it) { void *tmp; if (!l || !l->count || !it) return NULL; tmp = it->data; if (l->count == 1) { l->first = NULL; l->last = NULL; } else if (it == FIRST(l)) // The node is the first of the list { l->first = it->next; it->next->prev = NULL; } else if (it == LAST(l)) // The node is the last { l->last = it->prev; it->prev->next = NULL; } else // The node is somewhere in the middle { it->next->prev = it->prev; it->prev->next = it->next; } free(it); l->count--; return tmp; }
void pdf_write_outlines(PDF *p) { int i; if (p->outline_count == 0) /* no outlines: return */ return; pdc_begin_obj(p->out, p->outlines[0].obj_id); /* root outline object */ pdc_begin_dict(p->out); if (p->outlines[0].count != 0) pdc_printf(p->out, "/Count %d\n", COUNT(0)); pdc_objref(p->out, "/First", OBJ_ID(FIRST(0))); pdc_objref(p->out, "/Last", OBJ_ID(LAST(0))); pdc_end_dict(p->out); pdc_end_obj(p->out); /* root outline object */ #define PDF_FLUSH_AFTER_MANY_OUTLINES 1000 /* ca. 50-100 KB */ for (i = 1; i <= p->outline_count; i++) { /* reduce memory usage for many outline entries */ if (i % PDF_FLUSH_AFTER_MANY_OUTLINES == 0) pdc_flush_stream(p->out); pdf_write_outline_dict(p, i); } }
Word C1DTOEDGELIST(Word cl, Word cm, Word cr) { Word E,L,i,Ll,Lr,l,a,b,t; Step1: /* Initialize. */ E = NIL; Step2: /* Get adjacencies for (cl,cm) and (cr,cm). */ L = FIRST(ADJ_2D_PART(cm,cl,cr,P,J)); i = LAST(LELTI(cm,INDX)); Ll = NIL; Lr = NIL; while(L != NIL) { ADV(L,&l,&L); FIRST2(l,&a,&b); if (FIRST(a) == i) { t = a; a = b; b = t; } if (FIRST(a) < i) Ll = COMP(LIST2(a,b),Ll); else Lr = COMP(LIST2(a,b),Lr); } Step3: /* Get edges from adjacency info. */ E = CONC(ADJ2DITOEL(Ll,cl,cm),E); E = CONC(ADJ2DITOEL(Lr,cr,cm),E); Return: /* Prepare to return. */ return E; }
unsigned int vec_chk(void *v, size_t s, unsigned int i) { unsigned int j; for (j = 0; !LAST(v, s, j); j = NEXT(v, s, j)) if (i == j) return 0; return 1; }
Word LDCOEFMASK(Word c, Word P, Word J) { Word *A,P_2,n,i,M,P_1,L,m,j,p,Lp,h,q,v,l; Step1: /* Set up A to be a characteristic vector for the set of level 2 proj fac's whose leading coefficients vanish in c. */ P_2 = LELTI(P,2); n = THIRD(LELTI(LAST(P_2),PO_LABEL)); A = GETARRAY(n + 1); for(i = 1; i <= n; i++) A[i] = 0; Step2: /* Set L to be the list of projection factors which vanish in c. */ M = LELTI(c,MULSUB); P_1 = LELTI(P,1); L = NIL; while(M != NIL) { ADV(M,&m,&M); j = FIRST(m); do ADV(P_1,&p,&P_1); while(j != THIRD(LELTI(p,PO_LABEL))); L = COMP(p,L); } Step3: /* Set Lp to the list of projection polynomials with factors in L. */ Lp = NIL; while(L != NIL) { ADV(L,&p,&L); for(h = LELTI(p,PO_PARENT); h != NIL; h = RED(h)) Lp = COMP(THIRD(FIRST(h)),Lp); } Step4: /* Run through the histories of each polynomial in Lp. If the polynomial is the leading coefficient of some bivariate projection factor, set A at the index for that projection factor to 1. */ while(Lp != NIL) { ADV(Lp,&p,&Lp); for(h = LELTI(p,PO_PARENT); h != NIL; h = RED(h)) { q = FIRST(h); if (FIRST(q) == PO_LCO) { l = LELTI(THIRD(q),PO_LABEL); if (SECOND(l) == 2) A[ THIRD(l) ] = 1; } } } Step5: /* Create the vector itself! */ v = NIL; while(P_2 != NIL) { ADV(P_2,&p,&P_2); j = THIRD(LELTI(p,PO_LABEL)); v = COMP(A[j],v); } v = INV(v); Return: /* Prepare to return. */ FREEARRAY(A); return v; }
static void findstats(Pos p, Ori o) { /* Recalculate cross assert and score total at 'p' */ Pos left, right; Word lword, rword; Node n; Edge e; int s; lword.n = rword.n = 0; if(EDGE(p)) return; /* find word to the left */ s = 0; for(left=PREV(p,o); HASLETTER(left); left = PREV(left,o)) ; left = NEXT(left,o); while (HASLETTER(left)) { lword.c[lword.n++] = LETTER(left); s += SCORE(left); left = NEXT(left,o); } /* find word to the right */ for(right=NEXT(p,o); HASLETTER(right); right = NEXT(right,o)) { rword.c[rword.n++] = LETTER(right); s += SCORE(right); } if(DBG) { wordprint(&lword); print("X"); wordprint(&rword); print(" [%d] ", s); } SIDE(p,o) = s; ISANCHOR(p) = true; /* calculate cross asserts */ CROSS(p,o) = 0; n = traverse(root, &lword, 0); assert(n>=0); if(n>0) do { e = dict[n++]; if ( (rword.n && isword(NODE(e), &rword)) || (!rword.n && TERM(e)) ) { CROSS(p,o) |= 1 << LET(e); DPRINT("%c, ", LET(e)+'a'); } } while (!(LAST(e))); DPRINT("\n"); }
void lastrev(const char *working_dir, const char *filename, const char **vers_ptr, time_t * time_ptr, const char **lock_ptr) { int n; TRY tried; for (n = 0; (tried = try_order(n)) != DontTry; n++) { #ifdef RCS_PATH if (tried == TryRcs) { LAST(rcslast); } #endif #ifdef SCCS_PATH if (tried == TrySccs) { LAST(sccslast); } #endif #ifdef CMV_PATH if (tried == TryCmVision) { LAST(cmv_last); } #endif #ifdef CVS_PATH if (tried == TryCvs) { LAST(cvslast); } #endif #ifdef SVN_PATH if (tried == TrySvn) { LAST(svnlast); } #endif if (*time_ptr != 0 || (*vers_ptr != 0 && *vers_ptr[0] != '?') || (*lock_ptr != 0 && *lock_ptr[0] != '?')) break; } }
/* t <- SCREENBYQUANTIFIER(c) c : a qepcad cell t : true if c can't be dismissed based on quantifier information and false if it can */ BDigit QepcadCls::SCREENBYQUANTIFIER(Word c) { Word k, I, Q, t; Step1: /* Initialization */ k = LELTI(c,LEVEL); I = LELTI(c,INDX); t = TRUE; Step2: /* If the cell is in bound space, check quantifier! */ if (k > GVNFV) { Q = LELTI(GVQ,k - GVNFV); switch(Q) { case FULLDE: if (LAST(I) % 2 == 0) t = FALSE; break; case FULLDA: if (LAST(I) % 2 == 0) t = FALSE; break; } } Return: /* Prepare to return */ return t; }
void *vec_new(size_t n, size_t s) { void *v; unsigned int i; /* Allocate an empty vector and initialize the free list. */ if ((v = calloc(n * s, 1))) { for (i = 0; i < n - 1; ++i) { NEXT(v, s, i) = i + 1; LAST(v, s, i) = 0; } NEXT(v, s, i) = i + 1; LAST(v, s, i) = 1; return v; } return NULL; }
int WWIV_make_path(const char *s) { char drive, current_path[MAX_PATH], current_drive, *p, *flp; p = flp = WWIV_STRDUP(s); _getdcwd(0, current_path, MAX_PATH); current_drive = static_cast< char >(*current_path - '@'); if (LAST(p) == WWIV_FILE_SEPERATOR_CHAR) { LAST(p) = 0; } if (p[1] == ':') { drive = static_cast< char >(wwiv::UpperCase<char>(p[0]) - 'A' + 1); if (_chdrive(drive)) { _chdir(current_path); _chdrive(current_drive); return -2; } p += 2; } if (*p == WWIV_FILE_SEPERATOR_CHAR) { _chdir(WWIV_FILE_SEPERATOR_STRING); p++; } for (; (p = strtok(p, WWIV_FILE_SEPERATOR_STRING)) != 0; p = 0) { if (_chdir(p)) { if (_mkdir(p)) { _chdir(current_path); _chdrive(current_drive); return -1; } _chdir(p); } } _chdir(current_path); if (flp) { free(flp); } return 0; }
unsigned int vec_all(void *v, size_t s, unsigned int *i, unsigned int *j) { *i = *i + 1; /* Continue in an unfinished block. Stop on the last block. */ if (NEXT(v, s, *j) > *i) return 1; if (LAST(v, s, *j) == 1) return 0; /* Skip over free blocks to the next allocated block. */ do { *i = NEXT(v, s, *j) + 1; *j = NEXT(v, s, *j); } while (NEXT(v, s, *j) == *i && LAST(v, s, *j) == 0); /* Indicate whether anything remains to be iterated. */ return (NEXT(v, s, *j) > *i); }
/*>PDB *blAppendPDB(PDB *first, PDB *second) ----------------------------------------- *//** \param[in] *first First linked list (may be NULL) \param[in] *second Second linked list \return Start of list Appends list second onto first. Returns start of new list (useful if first was NULL). - 13.05.92 Original - 09.07.93 Changed to use LAST() - 07.07.14 Use bl prefix for functions By: CTP */ PDB *blAppendPDB(PDB *first, PDB *second) { PDB *p; if(first == NULL) return(second); p = first; LAST(p); p->next = second; return(first); }
/* This function returns TRUE if a stack should be raised over cell c, and FALSE otherwise. */ BDigit QepcadCls::SCREEN(Word c) { Word T,k,I; T = LELTI(c,TRUTH); k = LELTI(c,LEVEL); I = LELTI(c,INDX); return ( // k == 0 || <-- Removed and added k == 0 to last two cases below ( (T != NA) && (T == UNDET || (PCFULL == 'y' && k < GVNFV)) && (PCUSEDES != 'y' || ISDESIRED(c,PCDESIRED) == 1) && (k == 0 || SCREENBYQUANTIFIER(c)) && (k == 0 || !PCMZERROR || k > GVNFV || LAST(I) % 2) )); }
char *make_abs_path(char *checkdir, const char* maindir) { SEH_PUSH("make_abs_path()"); char newdir[_MAX_PATH]; if ((strlen(checkdir) < 3) || (checkdir[1] != ':') || (checkdir[2] != '\\')) { cd_to(maindir); cd_to(checkdir); if (LAST(checkdir) == '\\') { get_dir(newdir, true); } else { get_dir(newdir, false); } cd_to(maindir); strcpy(checkdir, newdir); } return checkdir; }
int map_save(combat_game * map) { unsigned int hash; char filename[128]; char options[20]; char *map_data; int handle, a; hash = _generate_hash((char*)combat_options_string_write(map, 1)); snprintf(filename, sizeof(filename), "%s/%s.%u", GLOBAL_MAPS, map->name, hash); handle = ggz_conf_parse(filename, GGZ_CONF_RDWR | GGZ_CONF_CREATE); if (handle < 0) { snprintf(filename, sizeof(filename), "%s/.ggz/combat/maps/%s.%u", getenv("HOME"), map->name, hash); handle = ggz_conf_parse(filename, GGZ_CONF_RDWR | GGZ_CONF_CREATE); if (handle < 0) { snprintf(filename, sizeof(filename), "%s/.ggz", getenv("HOME")); mkdir(filename, S_IRWXU | S_IRGRP | S_IXGRP); snprintf(filename, sizeof(filename), "%s/.ggz/combat", getenv("HOME")); mkdir(filename, S_IRWXU | S_IRGRP | S_IXGRP); snprintf(filename, sizeof(filename), "%s/.ggz/combat/maps", getenv("HOME")); mkdir(filename, S_IRWXU | S_IRGRP | S_IXGRP); snprintf(filename, sizeof(filename), "%s/.ggz/combat/maps/%s.%u", getenv("HOME"), map->name, hash); handle = ggz_conf_parse(filename, GGZ_CONF_RDWR | GGZ_CONF_CREATE); if (handle < 0) { // Give up game_message ("I couldn't write the map to disk"); return -1; } } } // Width/height ggz_conf_write_int(handle, "map", "width", map->width); ggz_conf_write_int(handle, "map", "height", map->height); // Army data for (a = 0; a < 12; a++) ggz_conf_write_int(handle, "army", file_unit_name[a], map->army[map->number][a]); // Map data map_data = (char *)ggz_malloc(map->width * map->height + 1); for (a = 0; a < map->width * map->height; a++) { if (GET_OWNER(map->map[a].type) >= 0) { // Intial position! map_data[a] = GET_OWNER(map->map[a].type) + 49; } else { // Get's terrain switch (LAST(map->map[a].type)) { case T_OPEN: map_data[a] = 'O'; break; case T_NULL: map_data[a] = 'N'; break; case T_LAKE: map_data[a] = 'L'; break; } } } map_data[map->width * map->height] = 0; ggz_conf_write_string(handle, "map", "data", map_data); // Options snprintf(options, sizeof(filename), "%lX", map->options); ggz_conf_write_string(handle, "options", "bin1", options); ggz_conf_commit(handle); return 0; }
static noinline void save_stack(struct drm_mm_node *node) { unsigned long entries[STACKDEPTH]; struct stack_trace trace = { .entries = entries, .max_entries = STACKDEPTH, .skip = 1 }; save_stack_trace(&trace); if (trace.nr_entries != 0 && trace.entries[trace.nr_entries-1] == ULONG_MAX) trace.nr_entries--; /* May be called under spinlock, so avoid sleeping */ node->stack = depot_save_stack(&trace, GFP_NOWAIT); } static void show_leaks(struct drm_mm *mm) { struct drm_mm_node *node; unsigned long entries[STACKDEPTH]; char *buf; buf = kmalloc(BUFSZ, GFP_KERNEL); if (!buf) return; list_for_each_entry(node, drm_mm_nodes(mm), node_list) { struct stack_trace trace = { .entries = entries, .max_entries = STACKDEPTH }; if (!node->stack) { DRM_ERROR("node [%08llx + %08llx]: unknown owner\n", node->start, node->size); continue; } depot_fetch_stack(node->stack, &trace); snprint_stack_trace(buf, BUFSZ, &trace, 0); DRM_ERROR("node [%08llx + %08llx]: inserted at\n%s", node->start, node->size, buf); } kfree(buf); } #undef STACKDEPTH #undef BUFSZ #else static void save_stack(struct drm_mm_node *node) { } static void show_leaks(struct drm_mm *mm) { } #endif #define START(node) ((node)->start) #define LAST(node) ((node)->start + (node)->size - 1) INTERVAL_TREE_DEFINE(struct drm_mm_node, rb, u64, __subtree_last, START, LAST, static inline, drm_mm_interval_tree) struct drm_mm_node * __drm_mm_interval_first(const struct drm_mm *mm, u64 start, u64 last) { return drm_mm_interval_tree_iter_first((struct rb_root_cached *)&mm->interval_tree, start, last) ?: (struct drm_mm_node *)&mm->head_node; } EXPORT_SYMBOL(__drm_mm_interval_first); static void drm_mm_interval_tree_add_node(struct drm_mm_node *hole_node, struct drm_mm_node *node) { struct drm_mm *mm = hole_node->mm; struct rb_node **link, *rb; struct drm_mm_node *parent; bool leftmost = true; node->__subtree_last = LAST(node); if (hole_node->allocated) { rb = &hole_node->rb; while (rb) { parent = rb_entry(rb, struct drm_mm_node, rb); if (parent->__subtree_last >= node->__subtree_last) break; parent->__subtree_last = node->__subtree_last; rb = rb_parent(rb); } rb = &hole_node->rb; link = &hole_node->rb.rb_right; leftmost = false; } else {
void copy_to_cooked(struct tty_struct * tty) { signed char c; while (!EMPTY(tty->read_q) && !FULL(tty->secondary)) { GETCH(tty->read_q,c); if (c==13) if (I_CRNL(tty)) c=10; else if (I_NOCR(tty)) continue; else ; else if (c==10 && I_NLCR(tty)) c=13; if (I_UCLC(tty)) c=tolower(c); if (L_CANON(tty)) { if (c==ERASE_CHAR(tty)) { if (EMPTY(tty->secondary) || (c=LAST(tty->secondary))==10 || c==EOF_CHAR(tty)) continue; if (L_ECHO(tty)) { if (c<32) PUTCH(127,tty->write_q); PUTCH(127,tty->write_q); tty->write(tty); } DEC(tty->secondary.head); continue; } if (c==STOP_CHAR(tty)) { tty->stopped=1; continue; } if (c==START_CHAR(tty)) { tty->stopped=0; continue; } } if (!L_ISIG(tty)) { if (c==INTR_CHAR(tty)) { tty_intr(tty,SIGINT); continue; } } if (c==10 || c==EOF_CHAR(tty)) tty->secondary.data++; if (L_ECHO(tty)) { if (c==10) { PUTCH(10,tty->write_q); PUTCH(13,tty->write_q); } else if (c<32) { if (L_ECHOCTL(tty)) { PUTCH('^',tty->write_q); PUTCH(c+64,tty->write_q); } } else PUTCH(c,tty->write_q); tty->write(tty); } PUTCH(c,tty->secondary); } wake_up(&tty->secondary.proc_list); }
/** * Options constructor * @param argc the number of command line arguments from console * @param argv a char array of command line arguments from console */ Options::Options(int argc, char **argv) { /* Default geometry input file */ _geometry_file = _relative_path + "xml-sample/geometry_1810_1_8.xml"; _material_file = _relative_path + "xml-sample/material_1810_1_8g.xml"; /* convergence options */ _moc_conv_thresh = 1e-5; /* convergence on MOC sweeps */ /* FIXME: was 1e-10 before */ _l2_norm_conv_thresh = 1e-7; /* convergence on acceleration iteration */ /* most important acceleration options */ _linear_prolongation = false; _exact_prolongation = false; _acc_after_MOC_converge = false; _run_all = false; _cmfd = false; _loo = false; _loo1 = false; _loo2 = false; _damp_factor = 1.0; _boundary_iteration = 0; _first_diffusion = true; /* run diffusion for 1st iter */ _num_first_diffusion = 2; /* number of diffusion iterations */ _update_boundary = true; /* update boundary angular flux */ _reflect_outgoing = true; /* newest incoming flux during HO MOC */ _use_up_scattering_xs = true; if (std::string(getenv("PWD")).find("Release") != std::string::npos) _relative_path = "../"; else _relative_path = ""; // was running: 0.4 and 16 for b&w criticals _track_spacing = 0.3; /* Default C4 track spacing: 0.05cm */ _num_azim = 8; /* Default C4 # azimuthal angle: 64*/ /* MOC options */ _verbosity = "NORMAL"; /* Default logging level */ _dump_geometry = false; /* Default: not dump geometry */ _extension = "png"; /* Default: plot in png */ _compute_pin_powers = false; /* Default: not compute pin powers */ _compress_cross_sections = false; /* Default: not compress xs */ /* other acceleration options */ _cmfd_level = 0; /* Default cmfd level is 0: pin-wise */ _multigroup = true; /* sets CMFD to one group structure */ _k_guess = 1.5; _update_keff = false; /* Default: not use CMFD's k */ _print_matrices = false; /* Default will not print matrices */ _diffusion_correction = false; /* plotting options */ _bit_dimension = 1000; /* y dimension of plots */ _plot_FSRs = false; /* plot FSR index w/ quadrature ID */ _plot_specs = false; /* plot mat, cell, FSR, track, seg */ _plot_quad_flux = false; /* plot quad flux, net current, xs */ _plot_fluxes = false; /* plot colors, not values*/ _plot_current = false; /* plot cmfd currents */ _plot_diffusion = false; /* FIXME: does nothing now */ _plot_keff = false; /* Default will not plot keff */ _plot_prolongation = false; /* All extra options get placed into this array, which can be used * to call sub-initializers (petsc, for instance) */ extra_argc = 0; extra_argv = (char **)malloc(sizeof(*this->extra_argv) * argc); for (int i = 0 ; i < argc; i++) extra_argv[i] = NULL; for (int i = 0; i < argc; i++) { if (i > 0) { if (LAST("--geometryfile") || LAST("-g")) { _geometry_file = argv[i]; } else if (LAST("--materialfile") || LAST("-m")) { _material_file = argv[i]; } else if (LAST("--trackspacing") || LAST("-ts")) _track_spacing = atof(argv[i]); else if (LAST("--numazimuthal") || LAST("-na")) _num_azim = atoi(argv[i]); else if (LAST("--boundaryiteration") || LAST("-bi")) _boundary_iteration = atoi(argv[i]); else if (LAST("--dampfactor") || LAST("-df")) _damp_factor = atof(argv[i]); else if (LAST("--bitdimension") || LAST("-bd")) _bit_dimension = atoi(argv[i]); else if (LAST("--verbosity") || LAST("-v")) _verbosity = strdup(argv[i]); else if (LAST("--kguess") || LAST("-k")) _k_guess = atof(argv[i]); else if (strcmp(argv[i], "-dg") == 0 || strcmp(argv[i], "--dumpgeometry") == 0) _dump_geometry = true; else if (LAST("--extension") || LAST("-ex")) _extension = argv[i]; else if (strcmp(argv[i], "-noconv") == 0) _acc_after_MOC_converge = false; else if (strcmp(argv[i], "-debug") == 0) { _acc_after_MOC_converge = true; _first_diffusion = false; } else if (strcmp(argv[i], "-lp") == 0 || strcmp(argv[i], "--linearprolongation") == 0) { _linear_prolongation = true; _exact_prolongation = false; } else if (strcmp(argv[i], "-nlp") == 0 || strcmp(argv[i], "--nolinearprolongation") == 0) _linear_prolongation = false; else if (strcmp(argv[i], "-ep") == 0 || strcmp(argv[i], "--exactprolongation") == 0) { _linear_prolongation = false; _exact_prolongation = true; } else if (strcmp(argv[i], "-nep") == 0 || strcmp(argv[i], "--noexactprolongation") == 0) _exact_prolongation = false; else if (strcmp(argv[i], "-pFSR") == 0 || strcmp(argv[i], "--plotFSRs") == 0) _plot_FSRs = true; else if (strcmp(argv[i], "-ps") == 0 || strcmp(argv[i], "--plotspecs") == 0) _plot_specs = true; else if (strcmp(argv[i], "-pf") == 0 || strcmp(argv[i], "--plotfluxes") == 0) _plot_fluxes = true; else if (strcmp(argv[i], "-pp") == 0 || strcmp(argv[i], "--plotprolongation") == 0) _plot_prolongation = true; else if (strcmp(argv[i], "-cp") == 0 || strcmp(argv[i], "--computepowers") == 0) _compute_pin_powers = true; else if (strcmp(argv[i], "-cxs") == 0 || strcmp(argv[i], "--compressxs") == 0) _compress_cross_sections = true; else if (strcmp(argv[i], "-uk") == 0 || strcmp(argv[i], "--updatekeff") == 0) _update_keff = true; else if (strcmp(argv[i], "-ub") == 0 || strcmp(argv[i], "--updateboundary") == 0) _update_boundary = true; else if (strcmp(argv[i], "-nub") == 0 || strcmp(argv[i], "--noupdateboundary") == 0) _update_boundary = false; else if (strcmp(argv[i], "-ro") == 0 || strcmp(argv[i], "--reflectoutgoing") == 0) _reflect_outgoing = true; else if (strcmp(argv[i], "-nro") == 0 || strcmp(argv[i], "--noreflectoutgoing") == 0) _reflect_outgoing = false; else if (strcmp(argv[i], "-nc") == 0 || strcmp(argv[i], "--nocmfd") == 0) _cmfd = false; else if (strcmp(argv[i], "-wc") == 0 || strcmp(argv[i], "--withcmfd") == 0) { _cmfd = true; _loo = false; _damp_factor = 1; //0.66; } else if (strcmp(argv[i], "-nl") == 0 || strcmp(argv[i], "--noloo") == 0) _loo = false; else if (strcmp(argv[i], "-wl") == 0 || strcmp(argv[i], "--withloo") == 0) { _cmfd = false; _loo = true; _loo1 = false; _loo2 = true; _damp_factor = 1.0; } else if (strcmp(argv[i], "-wl1") == 0 || strcmp(argv[i], "--withloo1") == 0) { _cmfd = false; _loo = true; _loo1 = true; _loo2 = false; _damp_factor = 1.0; } else if (strcmp(argv[i], "-wl2") == 0 || strcmp(argv[i], "--withloo2") == 0) { _cmfd = false; _loo = true; _loo1 = false; _loo2 = true; _damp_factor = 1.0; } else if (strcmp(argv[i], "-wa") == 0 || strcmp(argv[i], "--withall") == 0) { _run_all = true; _cmfd = true; } else if (strcmp(argv[i], "-pc") == 0 || strcmp(argv[i], "--plotcurrent") == 0) _plot_current = true; else if (strcmp(argv[i], "-pk") == 0 || strcmp(argv[i], "--plotkeff") == 0) _plot_keff = true; else if (LAST("-diff") || LAST("--diffusion")) { _first_diffusion = true; _num_first_diffusion = atoi(argv[i]); } else if (strcmp(argv[i], "-ndiff") == 0 || strcmp(argv[i], "--nodiffusion") == 0) { _first_diffusion = false; _num_first_diffusion = 0; } else if (strcmp(argv[i], "-pd") == 0 || strcmp(argv[i], "--plotdiffusion") == 0) _plot_diffusion = true; else if (LAST("--fluxconv") || LAST("-fc")) { _moc_conv_thresh = atof(argv[i]); _l2_norm_conv_thresh = _moc_conv_thresh * 1e-2; } else if (LAST("--l2normconv") || LAST("-lc")) _l2_norm_conv_thresh = atof(argv[i]); else if (strcmp(argv[i], "-mg") == 0 || strcmp(argv[i], "--multigroup") == 0) _multigroup = true; else if (strcmp(argv[i], "-sg") == 0 || strcmp(argv[i], "--singlegroup") == 0) _multigroup = false; else if (strcmp(argv[i], "-pm") == 0 || strcmp(argv[i], "--printmatrices") == 0) _print_matrices = true; else if (LAST("--cmfdlevel") || LAST("-cl")) _cmfd_level = atoi(argv[i]); else if (strcmp(argv[i], "-dc")==0 || strcmp(argv[i], "--diffusioncorrection") == 0) _diffusion_correction = true; else if (strcmp(argv[i], "-nup")==0 || strcmp(argv[i], "--noupscattering") == 0) _use_up_scattering_xs = false; else this->extra_argv[this->extra_argc++] = strdup(argv[i]); } } /* If debug mode is on for CMFD, damping factor has to be 1.0 because * otherwise D tilde is picking up 0.0 as old values */ if ((_acc_after_MOC_converge) && (_cmfd)) _damp_factor = 1.0; }
/** * Options constructor * @param argc the number of command line arguments from console * @param argv a char array of command line arguments from console */ Options::Options(int argc, const char **argv) { /* Checks the working directory to set the relative path for input files * This is important so that default input files work when program is run * from both eclipse and the console */ if (std::string(getenv("PWD")).find("Release") != std::string::npos) _relative_path = "../"; else _relative_path = ""; _geometry_file = _relative_path + "xml-sample/SimpleLattice/geometry.xml"; /* Default geometry input file */ _material_file = _relative_path + "xml-sample/SimpleLattice/material.xml"; /* Default material input file */ _track_spacing = 0.1; /* Default track spacing */ _num_azim = 16; /* Default number of azimuthal angles */ _bit_dimension = 1000; /* y dimension of tracks and segments plots */ _verbosity = "NORMAL"; /* Default logging level */ _dump_geometry = false; /* Default will not dump geometry */ _extension = "png"; /* Default will plot png */ _plot_specs = false; /* Default will not plot materials, cells, FSRs, tracks, or segments */ _plot_fluxes = false; /* Default will not plot fluxes */ _compute_pin_powers = false; /* Default will not compute pin powers */ _compress_cross_sections = false;/* Default will not compress cross-sections */ _cmfd = true; /* Default will not perform CMFD acceleration */ _plot_current = false; /* Default will not plot net current */ for (int i = 0; i < argc; i++) { if (i > 0) { if (LAST("--geometryfile") || LAST("-g")) { _geometry_file = argv[i]; } else if (LAST("--materialfile") || LAST("-m")) { _material_file = argv[i]; } else if (LAST("--trackspacing") || LAST("-ts")) _track_spacing = atof(argv[i]); else if (LAST("--numazimuthal") || LAST("-na")) _num_azim = atoi(argv[i]); else if (LAST("--bitdimension") || LAST("-bd")) _bit_dimension = atoi(argv[i]); else if (LAST("--verbosity") || LAST("-v")) _verbosity = strdup(argv[i]); else if (strcmp(argv[i], "-dg") == 0 || strcmp(argv[i], "--dumpgeometry") == 0) _dump_geometry = true; else if (LAST("--extension") || LAST("-ex")) _extension = argv[i]; else if (strcmp(argv[i], "-ps") == 0 || strcmp(argv[i], "--plotspecs") == 0) _plot_specs = true; else if (strcmp(argv[i], "-pf") == 0 || strcmp(argv[i], "--plotfluxes") == 0) _plot_fluxes = true; else if (strcmp(argv[i], "-cp") == 0 || strcmp(argv[i], "--computepowers") == 0) _compute_pin_powers = true; else if (strcmp(argv[i], "-cxs") == 0 || strcmp(argv[i], "--compressxs") == 0) _compress_cross_sections = true; else if (strcmp(argv[i], "-pc") == 0 || strcmp(argv[i], "--plotcurrent") == 0) _plot_current = true; } } }
static int pdf_insert_bookmark( PDF *p, const char *hypertext, pdf_outline *outline, int jndex) { static const char fn[] = "pdf_insert_bookmark"; pdf_outline *root, *self; int parent; int self_idx; int pageno = pdf_current_page(p); /* allocation */ if (p->outline_count == 0) { p->outline_capacity = OUTLINE_CHUNKSIZE; p->outlines = (pdf_outline *) pdc_calloc(p->pdc, sizeof(pdf_outline) * p->outline_capacity, fn); /* populate the root outline object */ root = &p->outlines[0]; pdf_init_outline(p, root); root->obj_id = pdc_alloc_id(p->out); root->open = pdc_true; /* set the open mode show bookmarks if we have at least one, * and the client didn't already set his own open mode. */ pdf_fix_openmode(p); } else if (p->outline_count + 1 >= p->outline_capacity) { p->outline_capacity *= 2; p->outlines = (pdf_outline *) pdc_realloc(p->pdc, p->outlines, sizeof(pdf_outline) * p->outline_capacity, fn); } /* copy */ self_idx = ++p->outline_count; self = &p->outlines[self_idx]; memcpy(self, outline, sizeof(pdf_outline)); self->obj_id = pdc_alloc_id(p->out); self->text = (char *) hypertext; self->page_id = pdf_get_page_id(p, 0); parent = self->parent; /* default destination */ if (self->action == NULL && self->dest == NULL) self->dest = pdf_init_destination(p); /* no destination */ if (self->dest != NULL && self->dest->name != NULL && !strlen(self->dest->name)) { pdf_cleanup_destination(p, self->dest); self->dest = NULL; } /* current page */ if (self->dest) { /* this ugly code is for compatibility with the ** obsolete "bookmarkdest" parameter. */ if (self->dest->pgnum == 0) self->dest->pgnum = pdf_current_page(p); if (self->dest->pgnum == 0) { self->dest->pgnum = 1; } else if (self->dest->page == PDC_BAD_ID) { self->dest->page = pdf_get_page_id(p, self->dest->pgnum); } } /* special case: empty list. */ if (FIRST(parent) == 0) { if (jndex > 0) pdc_error(p->pdc, PDC_E_OPT_ILLINTEGER, "index", pdc_errprintf(p->pdc, "%d", jndex), 0, 0); FIRST(parent) = LAST(parent) = self_idx; self->in_order = pdc_true; } else switch (jndex) { case -2: /* insert "in order" */ { /* the "natural" case: append to the end if appropriate. */ if (pageno >= search_backward(p, -1, LAST(parent))) { self->prev = LAST(parent); NEXT(LAST(parent)) = self_idx; LAST(parent) = self_idx; } else { int idx; int curr_pg = 1; int next_pg; for (idx = FIRST(parent); idx != 0; idx = NEXT(idx)) { if (!IN_ORDER(idx)) continue; next_pg = pdf_search_page_fwd(p, curr_pg, PAGE_ID(idx)); /* TODO: understand why this can happen. */ if (next_pg < 1) { idx = 0; break; } if (next_pg > pageno) { self->next = idx; self->prev = PREV(idx); PREV(idx) = self_idx; if (self->prev == 0) FIRST(parent) = self_idx; else NEXT(self->prev) = self_idx; break; } curr_pg = next_pg; } /* if there are no "in order" bookmarks yet, ** we simply append this one to the end. */ if (idx == 0) { self->prev = LAST(parent); NEXT(LAST(parent)) = self_idx; LAST(parent) = self_idx; } } self->in_order = pdc_true; break; } case -1: /* append to the end */ { self->prev = LAST(parent); NEXT(LAST(parent)) = self_idx; LAST(parent) = self_idx; self->in_order = (pageno >= search_backward(p, pageno, self->prev)); break; } case 0: /* insert at the beginning */ { self->next = FIRST(parent); PREV(FIRST(parent)) = self_idx; FIRST(parent) = self_idx; self->in_order = (pageno <= search_forward(p, pageno, self->next)); break; } default: /* insert before [1..LAST] */ { int i; int target = FIRST(parent); for (i = 0; i < jndex; ++i) { if (target == LAST(parent)) pdc_error(p->pdc, PDC_E_OPT_ILLINTEGER, "index", pdc_errprintf(p->pdc, "%d", jndex), 0, 0); target = NEXT(target); } self->next = target; self->prev = PREV(target); NEXT(self->prev) = PREV(self->next) = self_idx; self->in_order = ((pageno >= search_backward(p, pageno, self->prev)) && (pageno <= search_forward(p, pageno, self->next))); break; } } /* else switch */ /* increase the number of open sub-entries for all relevant ancestors */ do { COUNT(parent)++; } while (OPEN(parent) && (parent = PARENT(parent)) != 0); return (self_idx); /* caller may use this as handle */ }
#include "sound_defs.h" //---------------------------------------------// // Tone arrays // frequency | duration const tone_t _beep_1000Hz_10ms[] = { { FREQ(1000), LAST(10) }, {0, 0} }; const tone_t _beep_800Hz_10ms[] = { { FREQ(800), LAST(10) }, {0, 0} }; const tone_t _beep_600Hz_10ms[] = { { FREQ(600), LAST(10) }, {0, 0} }; const tone_t _silence_10ms[] = { { 0, LAST(50) }, {0, 0} };
static void pdf_write_outline_dict(PDF *p, int entry) { pdf_outline *outline = &p->outlines[entry]; pdc_id act_idlist[PDF_MAX_EVENTS]; /* write action objects */ if (outline->action) pdf_parse_and_write_actionlist(p, event_bookmark, act_idlist, (const char *) outline->action); pdc_begin_obj(p->out, OBJ_ID(entry)); /* outline object */ pdc_begin_dict(p->out); pdc_objref(p->out, "/Parent", OBJ_ID(PARENT(entry))); /* outline destination */ if (outline->dest) { pdc_puts(p->out, "/Dest"); pdf_write_destination(p, outline->dest); } /* write Action entries */ else if (outline->action) pdf_write_action_entries(p, event_bookmark, act_idlist); pdc_puts(p->out, "/Title"); /* outline text */ pdf_put_hypertext(p, outline->text); pdc_puts(p->out, "\n"); if (PREV(entry)) pdc_objref(p->out, "/Prev", OBJ_ID(PREV(entry))); if (NEXT(entry)) pdc_objref(p->out, "/Next", OBJ_ID(NEXT(entry))); if (FIRST(entry)) { pdc_objref(p->out, "/First", OBJ_ID(FIRST(entry))); pdc_objref(p->out, "/Last", OBJ_ID(LAST(entry))); } if (COUNT(entry)) { if (OPEN(entry)) pdc_printf(p->out, "/Count %d\n", COUNT(entry)); /* open */ else pdc_printf(p->out, "/Count %d\n", -COUNT(entry));/* closed */ } /* Color */ if (outline->textcolor[0] != 0.0 || outline->textcolor[1] != 0.0 || outline->textcolor[2] != 0.0) pdc_printf(p->out, "/C[%f %f %f]\n", outline->textcolor[0], outline->textcolor[1], outline->textcolor[2]); /* FontStyle */ if (outline->fontstyle != fnt_Normal) { int fontstyle = 0; if (outline->fontstyle == fnt_Bold) fontstyle = 2; if (outline->fontstyle == fnt_Italic) fontstyle = 1; if (outline->fontstyle == fnt_BoldItalic) fontstyle = 3; pdc_printf(p->out, "/F %d\n", fontstyle); } pdc_end_dict(p->out); pdc_end_obj(p->out); /* outline object */ }
/** * Options constructor * @param argc the number of command line arguments from console * @param argv a char array of command line arguments from console */ Options::Options(int argc, const char **argv) { _num_neut = 1000000; /* default number of neutrons */ _two_theta_min = 20; /* default two theta minimum */ _two_theta_max = 80; /* default two theta maximum */ _bin_spacing = .01; /* default two theta bin spacing */ _verbosity = "NORMAL"; /* default logging level */ _crystal = "sc"; /* default crystal */ _radius = .1; /* default ionic radius (nm) */ _crystal_size = 100; /* default crystal size in (nm) */ _radiation = "neutron"; /* default radiation is neutrons */ _energy = .025; /* default energy of radiation */ _debye = .5; /* default value for Debye-Waller factor */ _batches = 1; /* default number of batches */ _scherrer = false; /* default scherrer particle size calc */ for (int i = 0; i < argc; i++) { if (i > 0) { if (LAST("--numneut") || LAST("-nn")) _num_neut = atoi(argv[i]); else if (LAST("--twothetamin") || LAST("-ttmin")) _two_theta_min = atof(argv[i]); else if (LAST("--twothetamax") || LAST("-ttmax")) _two_theta_max = atof(argv[i]); else if (LAST("--binspacing") || LAST("-bs")) _bin_spacing = atof(argv[i]); else if (LAST("--verbosity") || LAST("-v")) _verbosity = strdup(argv[i]); else if (LAST("--crystal") || LAST("-ctl")) _crystal = argv[i]; else if (LAST("--radius") || LAST("-rd")) _radius = atof(argv[i]); else if (LAST("--crystalsize") || LAST("-cs")) _crystal_size = atof(argv[i]); else if (LAST("--radiation") || LAST("-rad")) _radiation = argv[i]; else if (LAST("--energy") || LAST("-nrg")) _energy = atof(argv[i]); else if (LAST("--debye") || LAST("-dw")) _debye = atof(argv[i]); else if (LAST("--batches") || LAST("-bt")) _batches = atoi(argv[i]); else if (LAST("--scherrer") || LAST("-sc")) _scherrer = argv[i]; } } }
static void eraser(unsigned char c, struct tty_struct *tty) { enum { ERASE, WERASE, KILL } kill_type; int seen_alnums; if (tty->secondary.head == tty->canon_head) { /* opost('\a', tty); */ /* what do you think? */ return; } if (c == ERASE_CHAR(tty)) kill_type = ERASE; else if (c == WERASE_CHAR(tty)) kill_type = WERASE; else { if (!L_ECHO(tty)) { tty->secondary.head = tty->canon_head; return; } if (!L_ECHOK(tty) || !L_ECHOKE(tty)) { tty->secondary.head = tty->canon_head; if (tty->erasing) { opost('/', tty); tty->erasing = 0; } echo_char(KILL_CHAR(tty), tty); /* Add a newline if ECHOK is on and ECHOKE is off. */ if (L_ECHOK(tty)) opost('\n', tty); return; } kill_type = KILL; } seen_alnums = 0; while (tty->secondary.head != tty->canon_head) { c = LAST(&tty->secondary); if (kill_type == WERASE) { /* Equivalent to BSD's ALTWERASE. */ if (isalnum(c) || c == '_') seen_alnums++; else if (seen_alnums) break; } DEC(tty->secondary.head); if (L_ECHO(tty)) { if (L_ECHOPRT(tty)) { if (!tty->erasing) { opost('\\', tty); tty->erasing = 1; } echo_char(c, tty); } else if (!L_ECHOE(tty)) { echo_char(ERASE_CHAR(tty), tty); } else if (c == '\t') { unsigned int col = tty->canon_column; unsigned long tail = tty->canon_head; /* Find the column of the last char. */ while (tail != tty->secondary.head) { c = tty->secondary.buf[tail]; if (c == '\t') col = (col | 7) + 1; else if (iscntrl(c)) { if (L_ECHOCTL(tty)) col += 2; } else col++; INC(tail); } /* Now backup to that column. */ while (tty->column > col) { /* Can't use opost here. */ put_tty_queue('\b', &tty->write_q); tty->column--; } } else { if (iscntrl(c) && L_ECHOCTL(tty)) { opost('\b', tty); opost(' ', tty); opost('\b', tty); } if (!iscntrl(c) || L_ECHOCTL(tty)) { opost('\b', tty); opost(' ', tty); opost('\b', tty); } } } if (kill_type == ERASE) break; } if (tty->erasing && tty->secondary.head == tty->canon_head) { opost('/', tty); tty->erasing = 0; } }