static int dict_ordered(Word data, int count, int ex ARG_LD) { int ordered = TRUE; Word n1, n2; if ( count > 0 ) { data++; /* skip to key */ deRef2(data, n1); if ( !is_key(*n1) ) return -1; } for(; count > 1; count--, data += 2, n1=n2) { deRef2(data+2, n2); if ( !is_key(*n2) ) return -1; if ( *n1 < *n2 ) continue; if ( *n1 > *n2 ) ordered = FALSE; if ( *n1 == *n2 ) { if ( ex ) { term_t t = PL_new_term_ref(); *valTermRef(t) = linkVal(n1); PL_error(NULL, 0, NULL, ERR_DUPLICATE_KEY, t); } return -2; } } return ordered; }
/* * Read memory statistics data */ static void get_paging_data(struct paging_data *pd) { static const char *key_pgpgin = "pgpgin"; static const char *key_nr_free_pages = "nr_free_pages"; static const char parse_error_msg[] = "error parsing /proc/vmstat"; char *cp, *xp; bool found_pgpgin = false; bool found_nr_free_pages = false; int nfound = 0; const int need_found = 2; pd->ts = getnow(); pd->mem_pages = sysconf(_SC_PHYS_PAGES); if (pd->mem_pages <= 0) fatal_msg("unable to get system memory size"); read_whole_file("/proc/vmstat", &vmstat, &vmstat_size, 4096); for (cp = vmstat; *cp != '\0';) { if (is_key(&cp, key_pgpgin)) { if (!consume_umax(&cp, &pd->pgpgin)) fatal_msg(parse_error_msg); if (!found_pgpgin) { found_pgpgin = true; if (need_found == ++nfound) break; } } else if (is_key(&cp, key_nr_free_pages)) { if (!consume_umax(&cp, &pd->nr_free_pages)) fatal_msg(parse_error_msg); if (!found_nr_free_pages) { found_nr_free_pages = true; if (need_found == ++nfound) break; } } else { xp = strchr(cp, '\n'); if (!xp) break; cp = xp + 1; } } if (need_found != nfound) fatal_msg(parse_error_msg); }
static void sort_secondary(struct tracing_map *map, const struct tracing_map_sort_entry **entries, unsigned int n_entries, struct tracing_map_sort_key *primary_key, struct tracing_map_sort_key *secondary_key) { int (*primary_fn)(const struct tracing_map_sort_entry **, const struct tracing_map_sort_entry **); int (*secondary_fn)(const struct tracing_map_sort_entry **, const struct tracing_map_sort_entry **); unsigned i, start = 0, n_sub = 1; if (is_key(map, primary_key->field_idx)) primary_fn = cmp_entries_key; else primary_fn = cmp_entries_sum; if (is_key(map, secondary_key->field_idx)) secondary_fn = cmp_entries_key; else secondary_fn = cmp_entries_sum; for (i = 0; i < n_entries - 1; i++) { const struct tracing_map_sort_entry **a = &entries[i]; const struct tracing_map_sort_entry **b = &entries[i + 1]; if (primary_fn(a, b) == 0) { n_sub++; if (i < n_entries - 2) continue; } if (n_sub < 2) { start = i + 1; n_sub = 1; continue; } set_sort_key(map, secondary_key); sort(&entries[start], n_sub, sizeof(struct tracing_map_sort_entry *), (int (*)(const void *, const void *))secondary_fn, NULL); set_sort_key(map, primary_key); start = i + 1; n_sub = 1; } }
virtual int evaluate(char* buf, int maxbuf, Range range) const { char *pbuf = buf; int rem = maxbuf; VSCI end = parser.const_list().end(); for (VSCI i = parser.const_list().begin(); i != end && rem > 0; ++i){ dbg(3, "item: %s", i->c_str()); if (is_key(*i)){ int rc = evaluate_key( i->c_str(), pbuf, rem, range); if (rc > 0){ dbg(2, "evaluate OK : %s", pbuf); rem -= rc; pbuf += rc; continue; } } strncpy(pbuf, i->c_str(), rem); pbuf += strlen(pbuf); rem -= strlen(pbuf); } dbg(2, "outputs buf \"%s\"", buf); if (verbose) fprintf(stderr, "%s \"%s\"\n", _PFN, buf); assert(pbuf-buf < maxbuf); return pbuf - buf; }
void load(list<Expression*>& expressions) { /* load expressions from file, NO shell subst */ char line[256]; int iline = 0; while(fgets(line, sizeof(line), fp)){ chomp(line); dbg(2, "[%2d] \"%s\"", ++iline, line); if (is_key(line)){ char *equals = index(line, '='); if (equals == 0){ err("NOT key=value \"%s\"", line); continue; }else{ *equals = '\0'; char* key = line; char* value = equals + 1; expressions.push_front( new RootExpression( key, value, NOSUBS)); } }else if (is_comment(line) || is_blank(line)){ continue; }else{ err("continuation not supported at this time"); } } }
void test_basic_operations(const T &value) { constexpr grnxx::DataType data_type = T::type(); // Create a table and insert the first row. auto db = grnxx::open_db(""); auto table = db->create_table("Table"); grnxx::Int row_id = table->insert_row(); // Create a column named "Column". auto column = table->create_column("Column", data_type); assert(column->table() == table); assert(column->name() == "Column"); assert(column->data_type() == data_type); assert(!column->reference_table()); assert(!column->is_key()); assert(column->num_indexes() == 0); // Check if N/A is stored or not. grnxx::Datum datum; T stored_value; column->get(row_id, &datum); assert(datum.type() == data_type); datum.force(&stored_value); assert(stored_value.is_na()); // Set a value and get it. column->set(row_id, value); column->get(row_id, &datum); assert(datum.type() == data_type); datum.force(&stored_value); assert(stored_value.match(value)); }
int read_user(t_list *head) { char read_char[4] = {0}; while (42) { tputs(tgetstr("cl", NULL), 1, ft_putschar); so_printed(head); print_cursor(head); ft_strclr(read_char); read(0, read_char, 3); head = is_key(head, read_char); head = is_spc(head, read_char); if (read_char[0] == 10 && read_char[1] == 0) return (0); else if ((KEYDEL) || (KEYSUP)) { head->slc = -1; head = head->next; if (head->next == head && head->slc == -1) return (-1); } else if (read_char[0] == 27 && read_char[1] == 0) return (-1); } return (0); }
void SinkBase::cb_data(mblk_t *m) { uint32_t st = mblk_get_timestamp_info(m); mblk_t *fm = dupmsg(m); mblk_meta_copy(m, fm); MSQueue *queue = post_handle(fm); // 此处 dupmsg(m) 将不会导致 m 被释放 bool first = true; unsigned char *obuf = 0; size_t olen = 0; int index = 0; size_t off = 0; bool key = false; while (mblk_t *om = ms_queue_get(queue)) { int dlen = size_for(index, om); obuf = (unsigned char*)realloc(obuf, off + dlen); save_for(index, om, obuf + off); if (index == 0) key = is_key(index, om); index++; off += dlen; // 处理时间戳回绕 if (first_frame_) { first_frame_ = false; } else { uint32_t delta = st - last_stamp_; // 检查,是否乱序,乱序包直接扔掉! if (delta > 0x80000000) { fprintf(stderr, "??? maybe timestamp confusioned!, curr=%u, last=%u\n", st, last_stamp_); return; } next_stamp_ += delta / payload_freq(); } last_stamp_ = st; freemsg(om); } if (cb_data_ && obuf) { cb_data_(opaque_, next_stamp_, obuf, off, key); } if (obuf) free(obuf); }
int find_arg(const char keychar, const char* keyword, int argc, char** argv) { size_t i; for(i=0;i<argc;++i) { argkey_t token = is_key(argv[i]); if(token==KEYWORD && strcmp(keyword,argv[i]+2)==0) return i; if(token==KEYCHAR && argv[i][1]==keychar) return i; } return -1; }
void Aquarium::run( void ) { cout << "running Aquarium" << endl; while ( ! is_closed() ) { // cout << "iteration de la simulation" << endl; if ( is_key() ) { cout << "Vous avez presse la touche " << static_cast<unsigned char>( key() ); cout << " (" << key() << ")" << endl; if ( is_keyESC() ) close(); } flotte->step(); display( *flotte ); wait( delay ); } // while }
// ------ Begin of MouseSDL::is_key -------// int MouseSDL::is_key(unsigned scanCode, unsigned short skeyState, char *keyStr, unsigned flags) { int len = strlen(keyStr); if( len == 0) return 0; if( len == 1) return is_key(scanCode, skeyState, keyStr[0], flags); const char *priChar = NULL; const char *numLockChar = NULL; int onNumPad = 0; switch(scanCode) { case SDLK_F1: numLockChar = priChar = "F1"; break; case SDLK_F2: numLockChar = priChar = "F2"; break; case SDLK_F3: numLockChar = priChar = "F3"; break; case SDLK_F4: numLockChar = priChar = "F4"; break; case SDLK_F5: numLockChar = priChar = "F5"; break; case SDLK_F6: numLockChar = priChar = "F6"; break; case SDLK_F7: numLockChar = priChar = "F7"; break; case SDLK_F8: numLockChar = priChar = "F8"; break; case SDLK_F9: numLockChar = priChar = "F9"; break; case SDLK_F10: numLockChar = priChar = "F10"; break; case SDLK_F11: numLockChar = priChar = "F11"; break; case SDLK_F12: numLockChar = priChar = "F12"; break; case SDLK_KP_7: priChar = "HOME"; numLockChar = "7"; onNumPad = 1; break; case SDLK_KP_8: priChar = "UP"; numLockChar = "8"; onNumPad = 1; break; case SDLK_KP_9: priChar = "PAGE UP"; numLockChar = "9"; onNumPad = 1; break; case SDLK_KP_4: priChar = "LEFT"; numLockChar = "4"; onNumPad = 1; break; case SDLK_KP_5: priChar = "CENTER"; numLockChar = "5"; onNumPad = 1; break; case SDLK_KP_6: priChar = "RIGHT"; numLockChar = "6"; onNumPad = 1; break; case SDLK_KP_1: priChar = "END"; numLockChar = "1"; onNumPad = 1; break; case SDLK_KP_2: priChar = "DOWN"; numLockChar = "2"; onNumPad = 1; break; case SDLK_KP_3: priChar = "PAGE DOWN"; numLockChar = "3"; onNumPad = 1; break; case SDLK_KP_0: priChar = "INSERT"; numLockChar = "0"; onNumPad = 1; break; case SDLK_KP_PERIOD: priChar = "DELETE"; numLockChar = "."; onNumPad = 1; break; // keys above arrow keys case SDLK_HOME: priChar = numLockChar = "HOME"; break; case SDLK_UP: priChar = numLockChar = "UP"; break; case SDLK_PAGEUP: priChar = numLockChar = "PAGE UP"; break; case SDLK_LEFT: priChar = numLockChar = "LEFT"; break; case SDLK_RIGHT: priChar = numLockChar = "RIGHT"; break; case SDLK_END: priChar = numLockChar = "END"; break; case SDLK_DOWN: priChar = numLockChar = "DOWN"; break; case SDLK_PAGEDOWN: priChar = numLockChar = "PAGE DOWN"; break; case SDLK_INSERT: priChar = numLockChar = "INSERT"; break; case SDLK_DELETE: priChar = numLockChar = "DELETE"; break; // 104-key only case SDLK_LGUI: priChar = numLockChar = "LEFT WINDOW"; break; case SDLK_RGUI: priChar = numLockChar = "RIGHT WINDOW"; break; case SDLK_MENU: priChar = numLockChar = "APP MENU"; break; } // check flags int retFlag = 1; // check shift key state if( !(flags & K_IGNORE_SHIFT) ) { if( flags & K_IS_SHIFT ) { if( !(skeyState & SHIFT_KEY_MASK) ) retFlag = 0; } else { if( skeyState & SHIFT_KEY_MASK ) retFlag = 0; } } // check contrl key state if( !(flags & K_IGNORE_CTRL) ) { if( flags & K_IS_CTRL ) { if( !(skeyState & CONTROL_KEY_MASK) ) retFlag = 0; } else { if( skeyState & CONTROL_KEY_MASK ) retFlag = 0; } } // check alt key state if( !(flags & K_IGNORE_ALT) ) { if( flags & K_IS_ALT ) { if( !(skeyState & ALT_KEY_MASK) ) retFlag = 0; } else { if( skeyState & ALT_KEY_MASK ) retFlag = 0; } } // check numpad state if( !(flags & K_IGNORE_NUMPAD) ) { if( flags & K_ON_NUMPAD ) { if( !onNumPad ) retFlag = 0; } else { if( onNumPad ) retFlag = 0; } } const char *outChar = skeyState & NUM_LOCK_STATE_MASK ? numLockChar : priChar; int retFlag2 = outChar ? !strcmp(outChar, keyStr) : 0; return retFlag && retFlag2; }
RootExpression( const char* _key, const char* _expr, int nosubs = 0) : Expression(_key, _expr, nosubs) { int ix = 0; if (substitutions.size() == 0){ create(); } if (nosubs) return; dbg(1, "top level expression %s", _expr); loop: VSI end = parser.list().end(); for (VSI i = parser.list().begin(); i != end; ++i, ++ix){ dbg(2, "%2d: \"%s\" %s", ix, i->c_str(), is_key(*i)? "ISKEY": "not key"); if (!is_key(*i)){ continue; } dbg(3, "we have a key \"%s\" possible subs %d", i->c_str(), substitutions.size()); /* * compare with the evaluations first. * these guys don't substitute, and they are few */ int nosub = 0; VECI endev = evaluations.end(); for (VECI ev = evaluations.begin(); ev != endev; ++ev){ if (i->compare((*ev)->key.c_str()) == 0){ nosub = 1; break; } } if (nosub){ dbg(3, "nosub"); continue; } // now check key for substitutions VECI endse = substitutions.end(); for (VECI se = substitutions.begin();se != endse;++se){ dbg(3, "substitutions %s", (*se)->key.c_str()); if (i->compare((*se)->key.c_str()) == 0){ dbg(2,"substitute %s",(*se)->key.c_str()); substitute(i, *se); goto loop; } } } }
/** * tracing_map_sort_entries - Sort the current set of tracing_map_elts in a map * @map: The tracing_map * @sort_key: The sort key to use for sorting * @sort_entries: outval: pointer to allocated and sorted array of entries * * tracing_map_sort_entries() sorts the current set of entries in the * map and returns the list of tracing_map_sort_entries containing * them to the client in the sort_entries param. The client can * access the struct tracing_map_elt element of interest directly as * the 'elt' field of a returned struct tracing_map_sort_entry object. * * The sort_key has only two fields: idx and descending. 'idx' refers * to the index of the field added via tracing_map_add_sum_field() or * tracing_map_add_key_field() when the tracing_map was initialized. * 'descending' is a flag that if set reverses the sort order, which * by default is ascending. * * The client should not hold on to the returned array but should use * it and call tracing_map_destroy_sort_entries() when done. * * Return: the number of sort_entries in the struct tracing_map_sort_entry * array, negative on error */ int tracing_map_sort_entries(struct tracing_map *map, struct tracing_map_sort_key *sort_keys, unsigned int n_sort_keys, struct tracing_map_sort_entry ***sort_entries) { int (*cmp_entries_fn)(const struct tracing_map_sort_entry **, const struct tracing_map_sort_entry **); struct tracing_map_sort_entry *sort_entry, **entries; int i, n_entries, ret; entries = vmalloc(map->max_elts * sizeof(sort_entry)); if (!entries) return -ENOMEM; for (i = 0, n_entries = 0; i < map->map_size; i++) { struct tracing_map_entry *entry; entry = TRACING_MAP_ENTRY(map->map, i); if (!entry->key || !entry->val) continue; entries[n_entries] = create_sort_entry(entry->val->key, entry->val); if (!entries[n_entries++]) { ret = -ENOMEM; goto free; } } if (n_entries == 0) { ret = 0; goto free; } if (n_entries == 1) { *sort_entries = entries; return 1; } ret = merge_dups(entries, n_entries, map->key_size); if (ret < 0) goto free; n_entries -= ret; if (is_key(map, sort_keys[0].field_idx)) cmp_entries_fn = cmp_entries_key; else cmp_entries_fn = cmp_entries_sum; set_sort_key(map, &sort_keys[0]); sort(entries, n_entries, sizeof(struct tracing_map_sort_entry *), (int (*)(const void *, const void *))cmp_entries_fn, NULL); if (n_sort_keys > 1) sort_secondary(map, (const struct tracing_map_sort_entry **)entries, n_entries, &sort_keys[0], &sort_keys[1]); *sort_entries = entries; return n_entries; free: tracing_map_destroy_sort_entries(entries, n_entries); return ret; }
int main (int argc, char *argv[]) { GtkWidget *dialog; char *ret; const char *message; GOptionContext *ctx; bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); /* Option parsing */ ctx = g_option_context_new ("- New mdm login"); g_option_context_add_main_entries (ctx, options, _("main options")); g_option_context_parse (ctx, &argc, &argv, NULL); g_option_context_free (ctx); mdm_log_init (); mdm_log_set_debug (debug_in); if (send_command != NULL) { if ( ! mdmcomm_is_daemon_running (FALSE)) { mdm_common_error (_("Error: MDM (MDM Display Manager) is not running.")); mdm_common_error (_("You might be using a different display manager.")); return 1; } } else { /* * The --command argument does not display anything, so avoid * running gtk_init until it finishes. Sometimes the * --command argument is used when there is no display so it * will fail and cause the program to exit, complaining about * "no display". */ gtk_init (&argc, &argv); if ( ! mdmcomm_is_daemon_running (TRUE)) { return 1; } } mdmcomm_open_connection_to_daemon (); /* Process --command option */ g_type_init (); if (send_command != NULL) { /* gdk_init is needed for cookie code to get display */ gdk_init (&argc, &argv); if (authenticate) auth_cookie = mdmcomm_get_auth_cookie (); /* * If asking for a translatable config value, then try to get * the translated value first. If this fails, then go ahead * and call the normal sockets command. */ if (strncmp (send_command, MDM_SUP_GET_CONFIG " ", strlen (MDM_SUP_GET_CONFIG " ")) == 0) { gchar *value = NULL; const char *key = &send_command[strlen (MDM_SUP_GET_CONFIG " ")]; if (is_key (MDM_KEY_WELCOME, key)) { value = mdm_config_get_translated_string ((gchar *)key); if (value != NULL) { ret = g_strdup_printf ("OK %s", value); } } /* * If the above didn't return a value, then must be a * different key, so call the daemon. */ if (value == NULL) ret = mdmcomm_send_cmd_to_daemon_with_args (send_command, auth_cookie, 5); } else { ret = mdmcomm_send_cmd_to_daemon_with_args (send_command, auth_cookie, 5); } /* At this point we are done using the socket, so close it */ mdmcomm_close_connection_to_daemon (); if (ret != NULL) { g_print ("%s\n", ret); return 0; } else { dialog = hig_dialog_new (NULL /* parent */, GTK_DIALOG_MODAL /* flags */, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Cannot communicate with MDM " "(The MDM Display Manager)"), _("Perhaps you have an old version " "of MDM running.")); gtk_widget_show_all (dialog); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); return 1; } } /* * Always attempt to get cookie and authenticate. On remote * servers */ auth_cookie = mdmcomm_get_auth_cookie (); /* check for other displays/logged in users */ check_for_users (); if (auth_cookie == NULL) { /* At this point we are done using the socket, so close it */ mdmcomm_close_connection_to_daemon (); dialog = hig_dialog_new (NULL /* parent */, GTK_DIALOG_MODAL /* flags */, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("You do not seem to be logged in on the " "console"), _("Starting a new login only " "works correctly on the console.")); gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); gtk_widget_show_all (dialog); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); return 1; } ret = mdmcomm_send_cmd_to_daemon_with_args (MDM_SUP_FLEXI_XSERVER, auth_cookie, 5); g_free (auth_cookie); g_strfreev (args_remaining); /* At this point we are done using the socket, so close it */ mdmcomm_close_connection_to_daemon (); if (ret != NULL && strncmp (ret, "OK ", 3) == 0) { /* if we switched to a different screen as a result of this, * lock the current screen */ if ( ! no_lock ) { maybe_lock_screen (); } /* all fine and dandy */ g_free (ret); return 0; } message = mdmcomm_get_error_message (ret); dialog = hig_dialog_new (NULL /* parent */, GTK_DIALOG_MODAL /* flags */, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Cannot start new display"), message); gtk_widget_show_all (dialog); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); g_free (ret); return 1; }
/// reads the file bool Leo::Ini::read() { if( !is_open ) return false; if( file_readed ) return false; MemElement current_section; bool in_section = false; while( true ) { Line line = read_line(); if( eof_reached && line.str.empty() ) break; if( line.tag.str.empty() ) { // simple comment comments.push_back( line ); continue; } if( is_section( line.tag.str ) ) { if( in_section ) { elements.push_back( current_section ); current_section.clear(); } // create a new section current_section.line = line; current_section.section = extract_section_name( line.tag.str ); current_section.type = Element::SECTION; in_section = true; } else if( is_key( line.tag.str ) && in_section ) { // create a new key MemElement me; me.line = line; me.section = current_section.section; me.key = extract_key_name( line.tag.str ); me.value = extract_key_data( line.tag.str ); me.type = Element::KEY; current_section.mem_elements.push_back( me ); } } if( !current_section.section.empty() ) elements.push_back( current_section ); file_readed = true; return true; }
OBJECT InsertSym(FULL_CHAR *str, unsigned char xtype, FILE_POS *xfpos, unsigned char xprecedence, BOOLEAN xindefinite, BOOLEAN xrecursive, unsigned xpredefined, OBJECT xenclosing, OBJECT xbody) { register int sum, rlen; register unsigned char *x; OBJECT p, q, s, tmp, link, entry, plink; int len; debug3(DST, DD, "InsertSym( %s, %s, in %s )", Image(xtype), str, SymName(xenclosing)); if( !LexLegalName(str) ) Error(29, 3, "invalid symbol name %s", WARN, xfpos, str); New(s, xtype); FposCopy(fpos(s), *xfpos); has_body(s) = FALSE; filter(s) = nilobj; use_invocation(s) = nilobj; imports(s) = nilobj; imports_encl(s) = FALSE; right_assoc(s) = TRUE; precedence(s) = xprecedence; indefinite(s) = xindefinite; recursive(s) = xrecursive; predefined(s) = xpredefined; enclosing(s) = xenclosing; sym_body(s) = xbody; base_uses(s) = nilobj; uses(s) = nilobj; marker(s) = nilobj; cross_sym(s) = nilobj; is_extern_target(s) = FALSE; uses_extern_target(s)= FALSE; visible(s) = FALSE; uses_galley(s) = FALSE; horiz_galley(s) = ROWM; has_compulsory(s) = 0; is_compulsory(s) = FALSE; uses_count(s) = 0; dirty(s) = FALSE; if( enclosing(s) != nilobj && type(enclosing(s)) == NPAR ) dirty(s) = dirty(enclosing(s)) = TRUE; has_par(s) = FALSE; has_lpar(s) = FALSE; has_rpar(s) = FALSE; if( is_par(type(s)) ) has_par(enclosing(s)) = TRUE; if( type(s) == LPAR ) has_lpar(enclosing(s)) = TRUE; if( type(s) == RPAR ) has_rpar(enclosing(s)) = TRUE; /* assign a code letter between a and z to any NPAR symbol */ if( type(s) == NPAR ) { if( LastDown(enclosing(s)) != enclosing(s) ) { Child(tmp, LastDown(enclosing(s))); if( type(tmp) == NPAR ) { if( npar_code(tmp) == 'z' || npar_code(tmp) == ' ' ) npar_code(s) = ' '; else npar_code(s) = npar_code(tmp)+1; } else npar_code(s) = 'a'; } else npar_code(s) = 'a'; } has_target(s) = FALSE; force_target(s) = FALSE; if( !StringEqual(str, KW_TARGET) ) is_target(s) = FALSE; else { is_target(s) = has_target(enclosing(s)) = TRUE; /* if @Target is found after @Key, take note of external target */ if( has_key(enclosing(s)) && xbody != nilobj && is_cross(type(xbody)) ) { if( LastDown(xbody) != Down(xbody) ) { OBJECT sym; Child(sym, Down(xbody)); if( type(sym) == CLOSURE ) { is_extern_target(actual(sym)) = TRUE; uses_extern_target(actual(sym)) = TRUE; } } } } has_tag(s) = is_tag(s) = FALSE; has_key(s) = is_key(s) = FALSE; has_optimize(s) = is_optimize(s) = FALSE; has_merge(s) = is_merge(s) = FALSE; has_enclose(s) = is_enclose(s) = FALSE; if( enclosing(s) != nilobj && type(enclosing(s)) == LOCAL ) { if( StringEqual(str, KW_TAG) ) is_tag(s) = has_tag(enclosing(s)) = dirty(enclosing(s)) = TRUE; if( StringEqual(str, KW_OPTIMIZE) ) is_optimize(s) = has_optimize(enclosing(s)) = TRUE; if( StringEqual(str, KW_KEY) ) { is_key(s) = has_key(enclosing(s)) = dirty(enclosing(s)) = TRUE; /* if @Key is found after @Target, take note of external target */ for( link=Down(enclosing(s)); link!=enclosing(s); link=NextDown(link) ) { Child(p, link); if( is_target(p) && sym_body(p)!=nilobj && is_cross(type(sym_body(p))) ) { OBJECT sym; Child(sym, Down(sym_body(p))); if( type(sym) == CLOSURE ) { is_extern_target(actual(sym)) = TRUE; uses_extern_target(actual(sym)) = TRUE; } } } } if( StringEqual(str, KW_MERGE) ) is_merge(s) = has_merge(enclosing(s)) = TRUE; if( StringEqual(str, KW_ENCLOSE) ) is_enclose(s) = has_enclose(enclosing(s)) = TRUE; } if( StringEqual(str, KW_FILTER) ) { if( type(s) != LOCAL || enclosing(s) == StartSym ) Error(29, 4, "%s must be a local definition", WARN, &fpos(s), str); else if( !has_rpar(enclosing(s)) ) Error(29, 14, "%s must lie within a symbol with a right parameter", WARN, &fpos(s), KW_FILTER); else { filter(enclosing(s)) = s; precedence(enclosing(s)) = FILTER_PREC; } } if( type(s) == RPAR && has_body(enclosing(s)) && (is_tag(s) || is_key(s) || is_optimize(s)) ) Error(29, 5, "a body parameter may not be named %s", WARN, &fpos(s), str); if( type(s) == RPAR && has_target(enclosing(s)) && (is_tag(s) || is_key(s) || is_optimize(s)) ) Error(29, 6, "the right parameter of a galley may not be called %s", WARN, &fpos(s), str); len = StringLength(str); hash(str, len, sum); ifdebug(DST, D, sym_spread[sum]++; sym_count++); entry = (OBJECT) &symtab[sum]; for( plink = Down(entry); plink != entry; plink = NextDown(plink) ) { Child(p, plink); if( length(p) == len && StringEqual(str, string(p)) ) { for( link = Down(p); link != p; link = NextDown(link) ) { Child(q, link); if( enclosing(s) == enclosing(q) ) { Error(29, 7, "symbol %s previously defined at%s", WARN, &fpos(s), str, EchoFilePos(&fpos(q)) ); if( AltErrorFormat ) { Error(29, 13, "symbol %s previously defined here", WARN, &fpos(q), str); } break; } } goto wrapup; } } /* need a new OBJECT as well as s */ NewWord(p, WORD, len, xfpos); length(p) = len; StringCopy(string(p), str); Link(entry, p); wrapup: Link(p, s); if( enclosing(s) != nilobj ) Link(enclosing(s), s); debug2(DST, DD, "InsertSym Link(%s, %s) and returning.", SymName(enclosing(s)), SymName(s)); return s; } /* end InsertSym */
int main() { libyang::S_Context ctx; try { ctx = std::make_shared<libyang::Context>("/etc/sysrepo/yang"); } catch( const std::exception& e ) { std::cout << e.what() << std::endl; auto errors = get_ly_errors(ctx); for(auto error = errors.begin() ; error != errors.end() ; ++error) { std::cout << "err: " << (*error)->err() << std::endl; std::cout << "vecode: " << (*error)->vecode() << std::endl; std::cout << "errmsg: " << (*error)->errmsg() << std::endl; std::cout << "errpath: " << (*error)->errpath() << std::endl; std::cout << "errapptag: " << (*error)->errapptag() << std::endl; } return -1; } auto module = ctx->get_module("turing-machine"); if (module) { std::cout << module->name() << std::endl; } else { module = ctx->load_module("turing-machine"); } libyang::S_Data_Node node; try { node = ctx->parse_data_path("/etc/sysrepo/data/turing-machine.startup", LYD_XML, LYD_OPT_CONFIG); } catch( const std::exception& e ) { std::cout << e.what() << std::endl; } if (!node) { std::cout << "parse_path did not return any nodes" << std::endl; } else { std::cout << "tree_dfs\n" << std::endl; auto data_list = node->tree_dfs(); for(auto elem = data_list.begin() ; elem != data_list.end() ; ++elem) { std::cout << "name: " << (*elem)->schema()->name() << " type: " << (*elem)->schema()->nodetype() << std::endl; } std::cout << "\nChild of " << node->schema()->name() << " is: " << node->child()->schema()->name() << "\n" << std::endl; std::cout << "tree_for\n" << std::endl; data_list = node->child()->child()->tree_dfs(); for(auto elem = data_list.begin() ; elem != data_list.end() ; ++elem) { std::cout << "child of " << node->child()->schema()->name() << " is: " << (*elem)->schema()->name() << " type: " << (*elem)->schema()->nodetype() << std::endl; } std::cout << "\n schema tree_dfs\n" << std::endl; auto schema_list = node->schema()->tree_dfs(); for(auto elem = schema_list.begin() ; elem != schema_list.end() ; ++elem) { std::cout << "schema name " << (*elem)->name() << " type " << (*elem)->nodetype() << std::endl; if (LYS_LEAF == (*elem)->nodetype()) { auto leaf = libyang::Schema_Node_Leaf(*elem); auto list = leaf.is_key(); if (list) { std::cout << "leaf " << leaf.name() << " is a key for the list " << list->name() << std::endl; } } } } return 0; }
void poxc_lex(FILE * fp) { // Clean up first tk_type = TYPE_UNKNOWN; tk_value = -1; int pos = 0; // Cursor of current char in tk_text tk_text = malloc(MAX_NAME_LEN); if (tk_text == NULL) throw(ERR_MEMOP_FAILED); char ch; while (!feof(fp)){ ch = getc(fp); // Skip blank // The '\r' is for Mac, not for Windows!!! // F**k Windows, f**k Bill! if (ch != ' ' && ch != '\t' && ch != '\n' && ch != '\r' && ch != '#') break; // Skip comment if (ch == '#') while ((ch = getc(fp)) != '\n') if (feof(fp)) break; } if (feof(fp)){ lex_finished = true; return; } // Identifier or label if (ch == ':' || ch == '.' || ch == '_' || isalpha(ch)){ tk_type = TYPE_IDENT; tk_text[pos++] = ch; while (isalnum(ch = getc(fp)) || ch == '.' || ch == '_'){ if (feof(fp)) break; if (pos == MAX_NAME_LEN) throw(ERR_ID_TOO_LONG); tk_text[pos++] = ch; } tk_text[pos] = 0; // A STRING ends with 0 // Is label? if (tk_text[0] == ':'){ tk_type = TYPE_LABEL; tk_value = symtab_append_label(tk_text); free(tk_text); tk_text = NULL; } // Is keyword? else if (is_key(tk_text)) tk_type = TYPE_KEY; // Oh, that's a variable else { tk_value = symtab_append_var(tk_text); free(tk_text); tk_text = NULL; } } // Value else if (isdigit(ch)){ tk_type = TYPE_VALUE; tk_text[pos++] = ch; while (isdigit(ch = getc(fp))){ if (feof(fp)) break; if (pos == MAX_NAME_LEN) throw(ERR_ID_TOO_LONG); tk_text[pos++] = ch; } tk_text[pos] = 0; tk_value = symtab_append_value(tk_text); free(tk_text); tk_text = NULL; } // Unknown else { debug("%c", ch); throw(ERR_UNKNOWN_CH); } }
// --------------------------------------------------------------------------- // // ----------- bool bToolGeomWithJoin::get_join(bGenericGeoElement* o, i2dvertex* res, double* d){ join_prm p; bool found=false; *d=LONG_MAX; o->getVertices(&p.ref); get_cur(&p.vx); get_clic(&p.prev); if(_jnea&&_use_nea){ if((!_k_nea)||((_k_nea)&&(is_key(_k_nea)))){ p.dmax=-1; if(_jnea->process(kExtProcessCallWithParams,&p)){ *res=p.res; *d=p.d; found=true; } } } if(_jdir&&_use_dir){ if((!_k_dir)||((_k_dir)&&(is_key(_k_dir)))){ p.dmax=-1; if((_jdir->process(kExtProcessCallWithParams,&p))&&(p.d<*d)){ *res=p.res; *d=p.d; found=true; } } } if(_jang&&_use_ang){ if((!_k_ang)||((_k_ang)&&(is_key(_k_ang)))){ p.dmax=-1; if((_jang->process(kExtProcessCallWithParams,&p))&&(p.d<*d)){ bGenericType* tp=_gapp->typesMgr()->get(o->getType()); // Controle pour les linéaires, pour éviter les rabbatements sur les extrémités : utile ? if(tp->kind()==kBaseKindPolyline){ i2dvertex* vx; int nv; bool bad=false; for(long i=0;i<ivs_n_parts(p.ref);i++){ vx=ivs2_part(p.ref,i,&nv); if(eq_ivx2(&p.res,&vx[0]) || eq_ivx2(&p.res,&vx[nv-1]) ){ bad=true; break; } } if(!bad){ *res=p.res; *d=p.d; found=true; } } else{ *res=p.res; *d=p.d; found=true; } } } } if(_jend&&_use_end){ if((!_k_end)||((_k_end)&&(is_key(_k_end)))){ p.dmax=-1; if((_jend->process(kExtProcessCallWithParams,&p))&&(p.d<*d)){ *res=p.res; *d=p.d; found=true; } } } return(found); }
int main (int argc, char *argv[]) { GtkWidget *dialog; char *command; char *version; char *ret; const char *message; GOptionContext *ctx; bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); /* Option parsing */ ctx = g_option_context_new ("- New mdm login"); g_option_context_add_main_entries (ctx, options, _("main options")); g_option_context_parse (ctx, &argc, &argv, NULL); g_option_context_free (ctx); if (monte_carlo_pi) { calc_pi (); return 0; } mdm_log_init (); mdm_log_set_debug (debug_in); if (args_remaining != NULL && args_remaining[0] != NULL) server = args_remaining[0]; if (send_command != NULL) { if ( ! mdmcomm_check (FALSE)) { mdm_common_error (_("Error: MDM (MDM Display Manager) is not running.")); mdm_common_error (_("You might be using a different display manager.")); return 1; } } else { /* * The --command argument does not display anything, so avoid * running gtk_init until it finishes. Sometimes the * --command argument is used when there is no display so it * will fail and cause the program to exit, complaining about * "no display". */ gtk_init (&argc, &argv); if ( ! mdmcomm_check (TRUE)) { return 1; } } /* Start reading config data in bulk */ mdmcomm_comm_bulk_start (); /* Process --command option */ g_type_init (); if (send_command != NULL) { /* gdk_init is needed for cookie code to get display */ gdk_init (&argc, &argv); if (authenticate) auth_cookie = mdmcomm_get_auth_cookie (); /* * If asking for a translatable config value, then try to get * the translated value first. If this fails, then go ahead * and call the normal sockets command. */ if (strncmp (send_command, MDM_SUP_GET_CONFIG " ", strlen (MDM_SUP_GET_CONFIG " ")) == 0) { gchar *value = NULL; const char *key = &send_command[strlen (MDM_SUP_GET_CONFIG " ")]; if (is_key (MDM_KEY_WELCOME, key) || is_key (MDM_KEY_REMOTE_WELCOME, key)) { value = mdm_config_get_translated_string ((gchar *)key); if (value != NULL) { ret = g_strdup_printf ("OK %s", value); } } /* * If the above didn't return a value, then must be a * different key, so call mdmcomm_call_mdm. */ if (value == NULL) ret = mdmcomm_call_mdm (send_command, auth_cookie, "1.0.0.0", 5); } else { ret = mdmcomm_call_mdm (send_command, auth_cookie, "1.0.0.0", 5); } /* At this point we are done using the socket, so close it */ mdmcomm_comm_bulk_stop (); if (ret != NULL) { g_print ("%s\n", ret); return 0; } else { dialog = hig_dialog_new (NULL /* parent */, GTK_DIALOG_MODAL /* flags */, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Cannot communicate with MDM " "(The MDM Display Manager)"), _("Perhaps you have an old version " "of MDM running.")); gtk_widget_show_all (dialog); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); return 1; } } /* * Now process what mdmflexiserver is more frequently used to * do, start VT (Virtual Terminal) sesions - at least on * systems where it is supported. On systems where it is not * supporteed VT stands for "Very Tight" and will mess up your * display if you use it. Tight! So do not use it. * * I would accept a patch to disable it on such systems, but it * is easy to avoid not using it as long as your distro does not * put the menu choice in the application launch button on the * panel (don't ship the desktop file). */ /* * Always attempt to get cookie and authenticate. On remote * servers */ auth_cookie = mdmcomm_get_auth_cookie (); if (use_xnest) { char *cookie = mdmcomm_get_a_cookie (FALSE /* binary */); if (cookie == NULL) { /* At this point we are done using the socket, so close it */ mdmcomm_comm_bulk_stop (); dialog = hig_dialog_new (NULL /* parent */, GTK_DIALOG_MODAL /* flags */, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("You do not seem to have the " "authentication needed for this " "operation"), _("Perhaps your .Xauthority " "file is not set up correctly.")); gtk_widget_show_all (dialog); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); return 1; } command = g_strdup_printf (MDM_SUP_FLEXI_XNEST " %s %d %s %s", mdmcomm_get_display (), (int)getuid (), cookie, XauFileName ()); g_free (cookie); version = "1.0.0.0"; auth_cookie = NULL; } else { /* check for other displays/logged in users */ check_for_users (); if (auth_cookie == NULL) { /* At this point we are done using the socket, so close it */ mdmcomm_comm_bulk_stop (); dialog = hig_dialog_new (NULL /* parent */, GTK_DIALOG_MODAL /* flags */, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("You do not seem to be logged in on the " "console"), _("Starting a new login only " "works correctly on the console.")); gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); gtk_widget_show_all (dialog); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); return 1; } read_servers (); server = choose_server (); if (server == NULL) command = g_strdup (MDM_SUP_FLEXI_XSERVER); else command = g_strdup_printf (MDM_SUP_FLEXI_XSERVER " %s", server); version = "1.0.0.0"; } ret = mdmcomm_call_mdm (command, auth_cookie, version, 5); g_free (command); g_free (auth_cookie); g_strfreev (args_remaining); /* At this point we are done using the socket, so close it */ mdmcomm_comm_bulk_stop (); if (ret != NULL && strncmp (ret, "OK ", 3) == 0) { /* if we switched to a different screen as a result of this, * lock the current screen */ if ( ! no_lock && ! use_xnest) { maybe_lock_screen (); } /* all fine and dandy */ g_free (ret); return 0; } message = mdmcomm_get_error_message (ret, use_xnest); dialog = hig_dialog_new (NULL /* parent */, GTK_DIALOG_MODAL /* flags */, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Cannot start new display"), message); gtk_widget_show_all (dialog); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); g_free (ret); return 1; }