string tag(const string &tag, const string &cls, const string &body, int id = -1) { std::stringstream s; s << open_tag(tag, cls, id); s << body; s << close_tag(tag); return s.str(); }
void style(boost::filesystem::path filepath) { open_tag("style"); insert_text(filesystem::read_file(filepath)); next_line(); close_tag("style"); }
void js_inline(boost::filesystem::path filepath) { ensure(html_locations::in_head,"Cannot link to script out of head!"); open_tag("script"); insert_text(filesystem::read_file(filepath)); next_line(); close_tag("script"); }
__uint _fastcall _read_tags( __uint count, PCTAG_NAME names, Ppmc_value_t values, __uint & existed ) { RTK_CURSOR hNode, hTag; NODE_KEY cachedNode; RTK_TAG *pTag; __uint i, valids; valids = 0; existed = 0; ZeroMemory(values, sizeof(values[0]) * count); if(!lock_rtdb(false, 1000)){ return 0; } hNode = 0; hTag = 0; RTK_TIME now; rtk_time_mark(&now); hNode = 0; memset(&cachedNode, 0, sizeof(cachedNode)); for(i=0; i<count; i++){ if(!(cachedNode == names[i].node)){ close_handle(hNode); hNode = 0; } if(!hNode){ hNode = open_node(&names[i].node); cachedNode = names[i].node; } if(!hNode){ values[i].Flags &= ~TF_Valid; continue; } hTag = open_tag(hNode, &names[i].sname); if(hTag){ existed++; pTag = (RTK_TAG*)cursor_get_item(hTag); double diff; diff = rtk_time_diff(&now, &pTag->d.CachedTime); if(diff > (g_fltTagLife*2)){ mark_expired(pTag); } values[i] = pTag->d.Value; valids++; close_handle(hTag); }else{ values[i].Flags &= ~TF_Valid; } } close_handle(hNode); unlock_rtdb(); return valids; }
RTDB_API RTK_CURSOR PMC_API open_tag_t( RTK_CURSOR node, const char * short_name ) { TAG_NAME tn; tagname_by_text(&tn, short_name); return open_tag(node, &tn.sname); }
RTDB_API PRTK_TAG PMC_API query_tag( RTK_CURSOR node, PCSHORT_TAG_NAME tag ) { assert(is_hnode(node)); RTK_CURSOR handle; handle = open_tag(node, tag); PRTK_TAG p = (PRTK_TAG)cursor_get_item(handle); close_handle(handle); return p; }
/* * ----------------------------------------------------------------------- * token_processing: * Calls the routine corresponding to the token id * passed in the parameter from the token table, tokentable * return codes : -1 - error * : 0 - successful * ----------------------------------------------------------------------- */ static int token_processing(pr_context_t *context) { uval_t uval; int retstat; int tokenid = context->tokenid; if ((tokenid > 0) && (tokenid <= MAXTOKEN) && (tokentable[tokenid].func != NOFUNC)) { /* * First check if there's a previous record that needs to be * closed off now; then checkpoint our progress as needed. */ if ((retstat = check_close_rec(context, tokenid)) != 0) return (retstat); checkpoint_progress(context); /* print token name */ if (context->format & PRF_XMLM) { retstat = open_tag(context, tokenid); } else { if (!(context->format & PRF_RAWM) && (tokentable[tokenid].t_name != (char *)0)) { uval.uvaltype = PRA_STRING; uval.string_val = gettext(tokentable[tokenid].t_name); } else { uval.uvaltype = PRA_BYTE; uval.char_val = tokenid; } retstat = pa_print(context, &uval, 0); } if (retstat == 0) retstat = (*tokentable[tokenid].func)(context); /* * For XML, close the token tag. Header tokens wrap the * entire record, so they only get closed later implicitly; * here, just make sure the header open tag gets finished. */ if ((retstat == 0) && (context->format & PRF_XMLM)) { if (!is_header_token(tokenid)) retstat = close_tag(context, tokenid); else retstat = finish_open_tag(context); } return (retstat); } /* here if token id is not in table */ (void) fprintf(stderr, gettext("praudit: No code associated with " "token id %d\n"), tokenid); return (0); }
static void json_backup(char *statbuf, struct conf *conf) { char *cp=NULL; if((cp=strstr(statbuf, " (deletable)"))) { *cp='\0'; cp++; } open_tag(2, NULL); printf(" \"timestamp\": \"%s\",\n", statbuf); printf(" \"deletable\": \"%s\"", cp?"true":"false"); if(conf->backup) { printf(",\n"); printf(" \"directory\": \"%s\",\n", conf->browsedir?conf->browsedir:""); printf(" \"regex\": \"%s\",\n", conf->regex?conf->regex:""); open_tag(3, "items"); } }
RTDB_API RTK_CURSOR PMC_API open_tag_f( PCTAG_NAME tag ) { RTK_CURSOR hNode; hNode = open_node(&tag->node); if(!hNode){ return 0; } RTK_CURSOR handle; handle = open_tag(hNode, &tag->sname); close_handle(hNode); return handle; }
static void ls_long_output_json(struct sbuf *sb) { static char buf[2048]; char *esc_fname=NULL; char *esc_lname=NULL; char *fname=sb->path.buf; char *lname=sb->link.buf; struct stat *statp=&sb->statp; *buf='\0'; if(fname) esc_fname=json_escape(fname); if(lname) esc_lname=json_escape(lname); open_tag(4, NULL); printf( " \"name\": \"%s\",\n" " \"link\": \"%s\",\n" " \"st_dev\": %lu,\n" " \"st_ino\": %lu,\n" " \"st_mode\": %u,\n" " \"st_nlink\": %lu,\n" " \"st_uid\": %u,\n" " \"st_gid\": %u,\n" " \"st_rdev\": %lu,\n" " \"st_size\": %ld,\n" " \"st_atime\": %ld,\n" " \"st_mtime\": %ld,\n" " \"st_ctime\": %ld", esc_fname?esc_fname:"", esc_lname?esc_lname:"", (long unsigned int)statp->st_dev, (long unsigned int)statp->st_ino, (unsigned int)statp->st_mode, (long unsigned int)statp->st_nlink, (unsigned int)statp->st_uid, (unsigned int)statp->st_gid, (long unsigned int)statp->st_rdev, (long int)statp->st_size, (long int)statp->st_atime, (long int)statp->st_mtime, (long int)statp->st_ctime); if(esc_fname) free(esc_fname); if(esc_lname) free(esc_lname); }
static void PMC_API _on_drop_tags(PCRTK_PACKET packet) { __uint count, i; PTAG_NAME name; RTK_CURSOR hNode; count = packet->data_size / sizeof(TAG_NAME); if(packet->data_size % sizeof(TAG_NAME)){ return; } if( !lock_rtdb(true, 100) ){ return; } hNode = HNODE_LOCAL_MACHINE; for(i=0, name=(PTAG_NAME)packet->data; i<count; i++, name++){ RTK_CURSOR hTag; hTag = open_tag(hNode, &name->sname); if(hTag){ cursor_delete(hTag); } } unlock_rtdb(); }
int do_list_client(struct asfd *asfd, struct conf *conf, enum action act, int json) { int ret=-1; char msg[512]=""; char *dpth=NULL; struct sbuf *sb=NULL; int json_started=0; struct iobuf *rbuf=asfd->rbuf; //logp("in do_list\n"); if(conf->browsedir) snprintf(msg, sizeof(msg), "listb %s:%s", conf->backup?conf->backup:"", conf->browsedir); else snprintf(msg, sizeof(msg), "list %s:%s", conf->backup?conf->backup:"", conf->regex?conf->regex:""); if(asfd->write_str(asfd, CMD_GEN, msg) || asfd->read_expect(asfd, CMD_GEN, "ok")) goto end; if(!(sb=sbuf_alloc(conf))) goto end; iobuf_init(&sb->path); iobuf_init(&sb->link); iobuf_init(&sb->attr); if(json) { open_tag(0, NULL); open_tag(1, "backups"); json_started++; } // This should probably should use the sbuf stuff. while(1) { sbuf_free_content(sb); iobuf_free_content(rbuf); if(asfd->read(asfd)) break; if(rbuf->cmd==CMD_TIMESTAMP) { // A backup timestamp, just print it. if(json) json_backup(rbuf->buf, conf); else { printf("Backup: %s\n", rbuf->buf); if(conf->browsedir) printf("Listing directory: %s\n", conf->browsedir); if(conf->regex) printf("With regex: %s\n", conf->regex); } continue; } else if(rbuf->cmd!=CMD_ATTRIBS) { iobuf_log_unexpected(rbuf, __func__); goto end; } iobuf_copy(&sb->attr, rbuf); iobuf_init(rbuf); attribs_decode(sb); if(asfd->read(asfd)) { logp("got stat without an object\n"); goto end; } iobuf_copy(&sb->path, rbuf); iobuf_init(rbuf); if(sb->path.cmd==CMD_DIRECTORY || sb->path.cmd==CMD_FILE || sb->path.cmd==CMD_ENC_FILE || sb->path.cmd==CMD_EFS_FILE || sb->path.cmd==CMD_SPECIAL) { list_item(json, act, sb); } else if(cmd_is_link(sb->path.cmd)) // symlink or hardlink { if(asfd->read(asfd) || rbuf->cmd!=sb->path.cmd) { logp("could not get link %c:%s\n", sb->path.cmd, sb->path.buf); goto end; } iobuf_copy(&sb->link, rbuf); iobuf_init(rbuf); list_item(json, act, sb); } else { fprintf(stderr, "unlistable %c:%s\n", sb->path.cmd, sb->path.buf?sb->path.buf:""); } } ret=0; end: if(json && json_started) close_tag(0); printf("\n"); iobuf_free_content(&sb->path); iobuf_free_content(&sb->link); iobuf_free_content(&sb->attr); if(dpth) free(dpth); sbuf_free(&sb); if(!ret) logp("List finished ok\n"); return ret; }
static void ls_short_output_json(struct sbuf *sb) { open_tag(4, NULL); printf(" \"%s\"", sb->path.buf); }
string open_div(const string &cls, int id = -1) { return open_tag("div", cls, id) + "\n"; }
string open_span(const string &cls, int id = -1) { return open_tag("span", cls, id); }
static void do_new_spitfile(dbref player, char *arg1, help_file *help_dat) { help_indx *entry = NULL; FILE *fp; char *p, line[LINE_SIZE + 1]; char the_topic[LINE_SIZE + 2]; int default_topic = 0; size_t n; if (*arg1 == '\0') { default_topic = 1; arg1 = (char *) help_dat->command; } else if (*arg1 == '&') { notify(player, T("Help topics don't start with '&'.")); return; } if (strlen(arg1) > LINE_SIZE) *(arg1 + LINE_SIZE) = '\0'; if (help_dat->admin) { sprintf(the_topic, "&%s", arg1); } else strcpy(the_topic, arg1); if (!help_dat->indx || help_dat->entries == 0) { notify(player, T("Sorry, that command is temporarily unvailable.")); do_rawlog(LT_ERR, "No index for %s.", help_dat->command); return; } entry = help_find_entry(help_dat, the_topic); if (!entry && default_topic) entry = help_find_entry(help_dat, (help_dat->admin ? "&help" : "help")); if (!entry) { notify_format(player, T("No entry for '%s'."), arg1); return; } if ((fp = fopen(help_dat->file, FOPEN_READ)) == NULL) { notify(player, T("Sorry, that function is temporarily unavailable.")); do_log(LT_ERR, 0, 0, "Can't open text file %s for reading", help_dat->file); return; } if (fseek(fp, entry->pos, 0) < 0L) { notify(player, T("Sorry, that function is temporarily unavailable.")); do_rawlog(LT_ERR, "Seek error in file %s", help_dat->file); return; } strcpy(the_topic, strupper(entry->topic + (*entry->topic == '&'))); /* ANSI topics */ notify_format(player, "%s%s%s", ANSI_HILITE, the_topic, ANSI_END); if (SUPPORT_PUEBLO) notify_noenter(player, open_tag("SAMP")); for (n = 0; n < BUFFER_LEN; n++) { if (fgets(line, LINE_SIZE, fp) == NULL) break; if (line[0] == '&') break; if (line[0] == '\n') { notify(player, " "); } else { for (p = line; *p != '\0'; p++) if (*p == '\n') *p = '\0'; notify(player, line); } } if (SUPPORT_PUEBLO) notify(player, close_tag("SAMP")); fclose(fp); if (n >= BUFFER_LEN) notify_format(player, T("%s output truncated."), help_dat->command); }
guint8 * gimp_text_buffer_serialize (GtkTextBuffer *register_buffer, GtkTextBuffer *content_buffer, const GtkTextIter *start, const GtkTextIter *end, gsize *length, gpointer user_data) { GString *string; GtkTextIter iter, old_iter; GSList *tag_list; GSList *active_tags; string = g_string_new ("<markup>"); iter = *start; tag_list = NULL; active_tags = NULL; do { GSList *tmp; gchar *tmp_text, *escaped_text; active_tags = NULL; tag_list = gtk_text_iter_get_tags (&iter); /* Handle added tags */ for (tmp = tag_list; tmp; tmp = tmp->next) { GtkTextTag *tag = tmp->data; open_tag (GIMP_TEXT_BUFFER (register_buffer), string, tag); active_tags = g_slist_prepend (active_tags, tag); } g_slist_free (tag_list); old_iter = iter; /* Now try to go to either the next tag toggle, or if a pixbuf appears */ while (TRUE) { gunichar ch = gtk_text_iter_get_char (&iter); if (ch == 0xFFFC) { /* pixbuf? can't happen! */ } else if (ch == 0) { break; } else { gtk_text_iter_forward_char (&iter); } if (gtk_text_iter_toggles_tag (&iter, NULL)) break; } /* We might have moved too far */ if (gtk_text_iter_compare (&iter, end) > 0) iter = *end; /* Append the text */ tmp_text = gtk_text_iter_get_slice (&old_iter, &iter); escaped_text = g_markup_escape_text (tmp_text, -1); g_free (tmp_text); g_string_append (string, escaped_text); g_free (escaped_text); /* Close any open tags */ for (tmp = active_tags; tmp; tmp = tmp->next) close_tag (GIMP_TEXT_BUFFER (register_buffer), string, tmp->data); g_slist_free (active_tags); } while (! gtk_text_iter_equal (&iter, end)); g_string_append (string, "</markup>"); *length = string->len; return (guint8 *) g_string_free (string, FALSE); }
guint8 * gimp_text_buffer_serialize (GtkTextBuffer *register_buffer, GtkTextBuffer *content_buffer, const GtkTextIter *start, const GtkTextIter *end, gsize *length, gpointer user_data) { GString *string; GtkTextIter iter, old_iter; GSList *tag_list, *new_tag_list; GSList *active_tags; string = g_string_new ("<markup>"); iter = *start; tag_list = NULL; active_tags = NULL; do { GList *added, *removed; GList *tmp; gchar *tmp_text, *escaped_text; new_tag_list = gtk_text_iter_get_tags (&iter); find_list_delta (tag_list, new_tag_list, &added, &removed); /* Handle removed tags */ for (tmp = removed; tmp; tmp = tmp->next) { GtkTextTag *tag = tmp->data; /* Only close the tag if we didn't close it before (by using * the stack logic in the while() loop below) */ if (g_slist_find (active_tags, tag)) { /* Drop all tags that were opened after this one (which are * above this on in the stack), but move them to the added * list so they get re-opened again, *unless* they are also * closed at this iter */ while (active_tags->data != tag) { close_tag (GIMP_TEXT_BUFFER (register_buffer), string, active_tags->data); /* if it also in the list of removed tags, *don't* add * it to the list of added tags again */ if (! g_list_find (removed, active_tags->data)) added = g_list_prepend (added, active_tags->data); active_tags = g_slist_remove (active_tags, active_tags->data); } /* then, close the tag itself */ close_tag (GIMP_TEXT_BUFFER (register_buffer), string, tag); active_tags = g_slist_remove (active_tags, active_tags->data); } } /* Handle added tags */ for (tmp = added; tmp; tmp = tmp->next) { GtkTextTag *tag = tmp->data; open_tag (GIMP_TEXT_BUFFER (register_buffer), string, tag); active_tags = g_slist_prepend (active_tags, tag); } g_slist_free (tag_list); tag_list = new_tag_list; g_list_free (added); g_list_free (removed); old_iter = iter; /* Now try to go to either the next tag toggle, or if a pixbuf appears */ while (TRUE) { gunichar ch = gtk_text_iter_get_char (&iter); if (ch == 0xFFFC) { /* pixbuf? can't happen! */ } else if (ch == 0) { break; } else { gtk_text_iter_forward_char (&iter); } if (gtk_text_iter_toggles_tag (&iter, NULL)) break; } /* We might have moved too far */ if (gtk_text_iter_compare (&iter, end) > 0) iter = *end; /* Append the text */ tmp_text = gtk_text_iter_get_slice (&old_iter, &iter); escaped_text = g_markup_escape_text (tmp_text, -1); g_free (tmp_text); g_string_append (string, escaped_text); g_free (escaped_text); } while (! gtk_text_iter_equal (&iter, end)); g_slist_free (tag_list); /* Close any open tags */ for (tag_list = active_tags; tag_list; tag_list = tag_list->next) close_tag (GIMP_TEXT_BUFFER (register_buffer), string, tag_list->data); g_slist_free (active_tags); g_string_append (string, "</markup>"); *length = string->len; return (guint8 *) g_string_free (string, FALSE); }