bool action::is_equal(action const & a) const { if (kind() != a.kind()) return false; switch (kind()) { case action_kind::Skip: return true; case action_kind::Binder: case action_kind::Binders: case action_kind::Expr: return rbp() == a.rbp(); case action_kind::Ext: return m_ptr == a.m_ptr; case action_kind::LuaExt: return get_lua_fn() == a.get_lua_fn(); case action_kind::Exprs: return rbp() == a.rbp() && get_sep() == a.get_sep() && get_rec() == a.get_rec() && get_initial() == a.get_initial() && get_terminator() == a.get_terminator() && is_fold_right() == a.is_fold_right(); case action_kind::ScopedExpr: return rbp() == a.rbp() && get_rec() == a.get_rec(); } lean_unreachable(); // LCOV_EXCL_LINE }
/* mkdir -p */ int mkdir_p(char *dir, unsigned int mode) { PRFileInfo info; int rval; char sep = get_sep(dir); rval = PR_GetFileInfo(dir, &info); if (PR_SUCCESS == rval) { if (PR_FILE_DIRECTORY != info.type) /* not a directory */ { PR_Delete(dir); if (PR_SUCCESS != PR_MkDir(dir, mode)) { LDAPDebug(LDAP_DEBUG_ANY, "mkdir_p %s: error %d (%s)\n", dir, PR_GetError(),slapd_pr_strerror(PR_GetError())); return -1; } } return 0; } else { /* does not exist */ char *p, *e; char c[2] = {0, 0}; int len = strlen(dir); rval = 0; e = dir + len - 1; if (*e == sep) { c[1] = *e; *e = '\0'; } c[0] = '/'; p = strrchr(dir, sep); if (NULL != p) { *p = '\0'; rval = mkdir_p(dir, mode); *p = c[0]; } if (c[1]) *e = c[1]; if (0 != rval) return rval; if (PR_SUCCESS != PR_MkDir(dir, mode)) { LDAPDebug(LDAP_DEBUG_ANY, "mkdir_p %s: error %d (%s)\n", dir, PR_GetError(),slapd_pr_strerror(PR_GetError())); return -1; } return 0; } }
// Similar to is_equal, but ignores information that is "irrelevant" for parsing. // For example, for Exprs actions, get_rec and get_initial are not relevant when parsing the input stream. // We only need them when we reach an accepting state. bool action::is_equivalent(action const & a) const { if (kind() != a.kind()) return false; switch (kind()) { case action_kind::Exprs: return rbp() == a.rbp() && get_sep() == a.get_sep() && get_terminator() == a.get_terminator(); case action_kind::ScopedExpr: return rbp() == a.rbp(); default: return is_equal(a); } }
extern void generate_list(void) { sqlite3_stmt *stmt = (sqlite3_stmt *)NULL; char *ztail = (char *)NULL; int rc; if ((sqlite3_prepare(G_db, "select replace(list,',',char(?))" " from(select replace(list, ',,', ',') as list" " from(select distinct stem||case word" " when '' then '' else ','" " ||group_concat(distinct word) end list" " from (select upper(substr(stem,1,1))||" " substr(stem,2,length(stem)-1) as stem," " upper(substr(word,1,1))||" " substr(word,2,length(word)-1) as word" " from words" " where stem is not null" " union" " select upper(substr(word,1,1))||" " substr(word,2,length(word)-1) as stem," " '' as word" " from words" " where stem is null" " order by 1) x" " group by stem) y) z" " order by 1", -1, &stmt, (const char **)&ztail) != SQLITE_OK) || (sqlite3_bind_int(stmt, 1, (int)get_sep())!= SQLITE_OK)) { fprintf(stderr, "generate_list 0: %s\n", (char *)sqlite3_errmsg(G_db)); (void)sqlite3_close(G_db); exit(1); } while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) { printf("%s\n", (char *)sqlite3_column_text(stmt, 0)); } if (rc != SQLITE_DONE) { fprintf(stderr, "generate_list 1: %s\n", (char *)sqlite3_errmsg(G_db)); (void)sqlite3_close(G_db); exit(1); } else { (void)sqlite3_finalize(stmt); } }
static int ldbm_instance_config_instance_dir_set(void *arg, void *value, char *errorbuf, int phase, int apply) { ldbm_instance *inst = (ldbm_instance *)arg; if (!apply) { return LDAP_SUCCESS; } if ((value == NULL) || (strlen(value) == 0)) { inst->inst_dir_name = NULL; inst->inst_parent_dir_name = NULL; } else { char *dir = (char *)value; if (is_fullpath(dir)) { char sep = get_sep(dir); char *p = strrchr(dir, sep); if (NULL == p) /* should not happens, tho */ { inst->inst_parent_dir_name = NULL; inst->inst_dir_name = rel2abspath(dir); /* normalize dir; strdup'ed in rel2abspath */ } else { *p = '\0'; inst->inst_parent_dir_name = rel2abspath(dir); /* normalize dir; strdup'ed in rel2abspath */ inst->inst_dir_name = slapi_ch_strdup(p+1); *p = sep; } } else { inst->inst_parent_dir_name = NULL; inst->inst_dir_name = slapi_ch_strdup(dir); } } return LDAP_SUCCESS; }
static void * ldbm_instance_config_instance_dir_get(void *arg) { ldbm_instance *inst = (ldbm_instance *)arg; if (inst->inst_dir_name == NULL) return slapi_ch_strdup(""); else if (inst->inst_parent_dir_name) { int len = strlen(inst->inst_parent_dir_name) + strlen(inst->inst_dir_name) + 2; char *full_inst_dir = (char *)slapi_ch_malloc(len); PR_snprintf(full_inst_dir, len, "%s%c%s", inst->inst_parent_dir_name, get_sep(inst->inst_parent_dir_name), inst->inst_dir_name); return full_inst_dir; } else return slapi_ch_strdup(inst->inst_dir_name); }
baseline find_baseline(char *file1,char *file2) { #define MAX_STVEC 1000 int N_STVEC;/*Number of state vectors in scene-- must be >=2.*/ int i; double range,dop; double Bn[MAX_STVEC],Bp[MAX_STVEC]; stateVector stVec; baseline base = {0.0, 0.0, 0.0, 0.0, 1.0}; meta_parameters *meta1 = meta_read(file1); meta_parameters *meta2 = meta_read(file2); int ncol; quietflag = TRUE; ncol = meta1->sar->original_sample_count; /*Calculate the range and doppler of beam center.*/ range = meta_get_slant(meta1,0,ncol/2); dop = meta_get_dop(meta1,0,ncol/2); if (meta1->state_vectors==NULL) { sprintf(errbuf," ERROR: The image file '%s' has no\n" " state vectors!\n",file1); printErr(errbuf); } N_STVEC=meta1->state_vectors->vector_count; /*Get image 1's state vectors, and advance each of image 2's so they line up. This creates an array of normal and parallel baseline values.*/ for (i=0;i<N_STVEC;i++) { stVec=meta1->state_vectors->vecs[i].vec; get_sep(stVec,meta2,range,dop,&Bn[i],&Bp[i]); } /*Find constant baseline value: Just average the normal and parallel baselines. */ for (i=0;i<N_STVEC;i++) { base.Bn+=Bn[i]; base.Bp+=Bp[i]; } base.Bn/=N_STVEC; base.Bp/=N_STVEC; i=N_STVEC/2; if (!quietflag) printf(" Orbit Curvature=%.2fm normal, %.2fm parallel\n", Bn[i]-base.Bn,Bp[i]-base.Bp); /*Find change in baseline value: Average the baseline delta for each point. */ for (i=0;i<N_STVEC;i++) { /* double weight=0.5-((double)i)/(N_STVEC-1);*/ /* change we made once for Radarsat processing; needs to be looked at some more when time permits */ double weight=-0.5+((double)i)/(N_STVEC-1); if (weight!=0.0) { base.dBn+=(Bn[i]-base.Bn)/weight; base.dBp+=(Bp[i]-base.Bp)/weight; } } base.dBn/=(N_STVEC-1); base.dBp/=(N_STVEC-1); base.temporal=get_days(meta1->state_vectors,meta2->state_vectors); return base; }
static void help(const char *s0, int flag) { const long long_help = flag & h_LONG; long n; entree *ep; char *s = get_sep(s0); if (isdigit((int)*s)) { digit_help(s,flag); return; } if (flag & h_APROPOS) { external_help(s,-1); return; } /* Get meaningful answer on '\ps 5' (e.g. from <F1>) */ if (*s == '\\') { char *t = s+1; pari_skip_alpha(&t); *t = '\0'; } if (isalpha((int)*s)) { if (!strncmp(s, "default", 7)) { /* special-case ?default(dft_name), e.g. default(log) */ char *t = s+7; pari_skip_space(&t); if (*t == '(') { t++; pari_skip_space(&t); cut_trailing_garbage(t); if (pari_is_default(t)) { default_help(t,flag); return; } } } cut_trailing_garbage(s); } if (long_help && (n = ok_external_help(&s))) { external_help(s,n); return; } switch (*s) { case '*' : commands(-1); return; case '\0': menu_commands(); return; case '\\': slash_commands(); return; case '.' : member_commands(); return; } ep = is_entry(s); if (!ep) { if (pari_is_default(s)) default_help(s,flag); else if (long_help) external_help(s,3); else if (!cb_pari_whatnow || !cb_pari_whatnow(pariOut, s,1)) simple_help(s,"unknown identifier"); return; } if (EpVALENCE(ep) == EpALIAS) { pari_printf("%s is aliased to:\n\n",s); ep = do_alias(ep); } switch(EpVALENCE(ep)) { case EpVAR: if (!ep->help) { if (typ((GEN)ep->value)!=t_CLOSURE) simple_help(s, "user defined variable"); else { GEN str = closure_get_text((GEN)ep->value); if (typ(str) == t_VEC) pari_printf("%s =\n %Ps\n", ep->name, ep->value); } return; } break; case EpINSTALL: if (!ep->help) { simple_help(s, "installed function"); return; } break; case EpNEW: if (!ep->help) { simple_help(s, "new identifier"); return; }; break; default: /* built-in function */ if (!ep->help) pari_err_BUG("gp_help (no help found)"); /*paranoia*/ if (long_help) { external_help(ep->name,3); return; } } print_text(ep->help); }
extern int process_pptx(char *pptx_file) { // Returns the number of slides, -1 in case of severe failure // (if the file doesn't exist, 0 is returned) mz_bool status; mz_zip_archive zip_archive; char *xml_slide; size_t xml_sz; char *p; char *q; char *s; char *t; int i; int deckid; int maxslide = 0; int notenum; int slidenum = 0; int slideid; char xmlrel[FILENAME_MAX]; short kw; short level; memset(&zip_archive, 0, sizeof(zip_archive)); status = mz_zip_reader_init_file(&zip_archive, pptx_file, 0); if (!status) { fprintf(stderr, "Cannot read %s!\n", pptx_file); } else { deckid = new_deck(pptx_file); // Get and print information about each file in the archive. for (i = 0; i < (int)mz_zip_reader_get_num_files(&zip_archive); i++) { mz_zip_archive_file_stat file_stat; if (!mz_zip_reader_file_stat(&zip_archive, i, &file_stat)) { fprintf(stderr, "mz_zip_reader_file_stat() failed!\n"); mz_zip_reader_end(&zip_archive); return -1; } if (!mz_zip_reader_is_file_a_directory(&zip_archive, i)) { if ((strncmp(file_stat.m_filename, "ppt/notesSlides/", 16) == 0) && strncmp(file_stat.m_filename, "ppt/notesSlides/_rels/", 22)) { // Notes // // *** ACHTUNG *** // Note numbers don't match the corresponding slide number, // that would be too easy. You have to dig into "_rels" // if (!sscanf(&(file_stat.m_filename[26]), "%d", ¬enum)) { fprintf(stderr, "Failed to extract note num from %s\n", &(file_stat.m_filename[16])); return -1; } sprintf(xmlrel, "ppt/notesSlides/_rels/notesSlide%d.xml.rels", notenum); if ((xml_slide = (char *)mz_zip_reader_extract_file_to_heap(&zip_archive, (const char *)xmlrel, &xml_sz, (mz_uint)0)) != (char *)NULL) { // Try to find the b****y slide number if ((p = strstr(xml_slide, "Target=\"../slides/slide")) != NULL) { if (!sscanf(&(p[23]), "%d", &slidenum)) { fprintf(stderr, "Failed to extract slidenum from %s\n", &(p[36])); return -1; } } free(xml_slide); } if (slidenum) { if (slidenum > maxslide) { maxslide = slidenum; } slideid = new_slide(deckid, slidenum); xml_sz = 0; if ((xml_slide = (char *)mz_zip_reader_extract_file_to_heap(&zip_archive, (const char *)file_stat.m_filename, &xml_sz, (mz_uint)0)) != (char *)NULL) { if (get_mode() & OPT_TAGS) { // Exclusively look for indexing words in the notes q = xml_slide; level = 0; while ((p = strchr(q, '[')) != (char *)NULL) { level++; do { p++; } while (isspace(*p)); q = p + 1; while (*q && ((*q != ']') || (level > 1))) { switch (*q) { case '[': level++; break; case ']': level--; break; default: break; } q++; } if (*q == ']') { *q = '\0'; if (get_sep() == ';') { // Replace HTML entities if there are any replace_entities(p); } while ((s = strchr(p, get_sep())) != (char *)NULL) { *s++ = '\0'; if (*p == get_kw()) { p++; kw = 1; } else { if (autokw()) { kw = lowercase_word(p); } else { kw = 0; } } if ((t = cleanup(p)) != (char *)NULL) { new_word_as_is(t, slideid, 'T', kw); free(t); } p = s; while (isspace(*p)) { p++; } } if (*p == get_kw()) { p++; kw = 1; } else { if (autokw()) { kw = lowercase_word(p); } else { kw = 0; } } if ((t = cleanup(p)) != (char *)NULL) { new_word_as_is(t, slideid, 'T', kw); free(t); } p = 1 + q; } else { break; } } } else { // Analyze text analyze_text(slideid, xml_slide, 'N'); } free(xml_slide); } else { fprintf(stderr, "Extract flopped\n"); return -1; } } } // We look at regular slides even if we are only interested // in tags to check that we aren't missing any slide without // notes and that our tag count is correct if ((strncmp(file_stat.m_filename, "ppt/slides/", 11) == 0) && strncmp(file_stat.m_filename, "ppt/slides/_rels/", 17)) { // Regular slide if (!sscanf(&(file_stat.m_filename[16]), "%d", &slidenum)) { fprintf(stderr, "Failed to extract num from %s\n", &(file_stat.m_filename[11])); return -1; } if (slidenum > maxslide) { maxslide = slidenum; } slideid = new_slide(deckid, slidenum); if (!(get_mode() & OPT_TAGS)) { xml_sz = 0; if ((xml_slide = (char *)mz_zip_reader_extract_file_to_heap(&zip_archive, (const char *)file_stat.m_filename, &xml_sz, (mz_uint)0)) != (char *)NULL) { // Analyze text analyze_text(slideid, xml_slide, 'S'); // Analyze images analyze_pic(slideid, xml_slide); free(xml_slide); } else { fprintf(stderr, "Extract flopped\n"); return -1; } } } } } // Close the archive, freeing any resources it was using mz_zip_reader_end(&zip_archive); } return maxslide; }