void executor::remove_tag(indx id) { indx_set tmp; tmp.insert(id); error(id, 0); remove_tags(tmp); intf->offtag(id); }
int tagfs_rename(const char *path, const char *newpath) { char **tag_array = NULL; int file_id = 0; int i = 0; int num_tags = 0; int retstat = 0; DEBUG(ENTRY); INFO("Moving %s to %s", path, newpath); file_id = file_id_from_path(path); remove_tags(file_id); if(strcmp(dirname(newpath), "/") != 0) { /* deleting will put the file at root. Nothing to add */ num_tags = path_to_array(dirname(newpath), &tag_array); for(i = 0; i < num_tags; i++) { add_tag_to_file(tag_id_from_tag_name(tag_array[i]), file_id); } free_double_ptr((void ***)&tag_array, num_tags); } DEBUG(EXIT); return retstat; }
/* * Remove a file. */ int tagfs_unlink(const char *path) { int retstat = 0; int file_id = 0; DEBUG(ENTRY); INFO("Deleting %s", path); file_id = file_id_from_path(path); if(strcmp(dirname(path), "/") == 0) { remove_file(file_id); } else { remove_tags(file_id); } DEBUG(EXIT); return retstat; }
/* * Takes a stock symbol and a file with a very particular format * as paramters and returns a pointer to a ticker structure. The * ticker structure will contain the values associated with the * given <symbol>, as specified in the file <file_name>. If the * symbol doesn't exist in this file, all fields of the ticker * structure (except the symbol field) will be 0. The symbol field * will always be a copy of the <symbol> input parameter. */ ticker* get_ticker(const char* symbol, const char* file_name) { FILE* f; char* buffer; char* line; ticker* result; int n = 1000; int endloop = 0; if ((f = fopen(file_name, "r")) == 0) { printf("Couldn't open %s.", file_name); abort(); } result = (ticker*) malloc(sizeof(ticker)); malloc_chars(&result->symbol, strlen(SYMBOL)+1); malloc_chars(&buffer, n); strcpy(result->symbol, SYMBOL); result->volume_of_transactions = 0; result->value_of_transactions = 0.0; result->trades = 0; result->last_price = 0.0; result->reference_price = 0.0; result->net_change = 0.0; result->percent_change = 0.0; while (!feof(f) && !endloop) { getline(&buffer, &n, f); line = strstr(buffer, symbol); if (line != 0) { // get the volume of transactions getline(&buffer, &n, f); getline(&buffer, &n, f); remove_tags(&buffer); remove_commas(&buffer); sscanf(buffer, "%ld", &result->volume_of_transactions); // get the value of transactions getline(&buffer, &n, f); getline(&buffer, &n, f); remove_tags(&buffer); remove_commas(&buffer); sscanf(buffer, "%f", &result->value_of_transactions); // get the number of trades getline(&buffer, &n, f); getline(&buffer, &n, f); remove_tags(&buffer); remove_commas(&buffer); sscanf(buffer, "%d", &result->trades); // get the last price getline(&buffer, &n, f); getline(&buffer, &n, f); remove_tags(&buffer); remove_commas(&buffer); sscanf(buffer, "%f", &result->last_price); // get the reference price getline(&buffer, &n, f); getline(&buffer, &n, f); remove_tags(&buffer); remove_commas(&buffer); sscanf(buffer, "%f", &result->reference_price); // get the net change getline(&buffer, &n, f); getline(&buffer, &n, f); remove_tags(&buffer); remove_commas(&buffer); sscanf(buffer, "%f", &result->net_change); // get the percent change getline(&buffer, &n, f); getline(&buffer, &n, f); remove_tags(&buffer); remove_commas(&buffer); sscanf(buffer, "%f", &result->percent_change); endloop = 1; } } fclose(f); free(buffer); return result; }
static char *parseHtmlSummary(char *buffer, char *field, int size, SWISH * sw) { char *p, *q, *tag, *endtag, c = '\0'; char *summary, *beginsum, *endsum, *tmp, *tmp2, *tmp3; int found, lensummary; /* Get the summary if no metaname/field is given */ if (!field && size) { /* Jump title if it exists */ if ((p = lstrstr(buffer, "</title>"))) { p += 8; } else p = buffer; /* Let us try to find <body> */ if ((q = lstrstr(p, "<body"))) { q = strchr(q, '>'); } else q = p; summary = (char *) Mem_ZoneAlloc(sw->Index->perDocTmpZone,strlen(p)+1); strcpy(summary,p); remove_newlines(summary); //$$$$ Todo: remove tag and content of scripts, css, java, embeddedobjects, comments, etc remove_tags(summary); summary = (char *)sw_ConvHTMLEntities2ISO(sw, (unsigned char *)summary); /* use only the required memory -save those not used */ /* 2001-03-13 rasc copy only <size> bytes of string */ if((int) strlen(summary) > size) summary[size]='\0'; return summary; } for (p = buffer, summary = NULL, found = 0, beginsum = NULL, endsum = NULL; p && *p;) { if ((tag = strchr(p, '<')) && ((tag == p) || (*(tag - 1) != '\\'))) { /* Look for non escaped '<' */ tag++; for (endtag = tag;;) if ((endtag = strchr(endtag, '>'))) { if (*(endtag - 1) != '\\') break; else endtag++; } else break; if (endtag) { c = *endtag; *endtag++ = '\0'; if ((tag[0] == '!') && lstrstr(tag, "META") && (lstrstr(tag, "START") || lstrstr(tag, "END"))) { /* Check for META TAG TYPE 1 */ if (lstrstr(tag, "START")) { if ((tmp = lstrstr(tag, "NAME"))) { tmp += 4; if (lstrstr(tmp, field)) { beginsum = endtag; found = 1; } p = endtag; } else p = endtag; } else if (lstrstr(tag, "END")) { if (!found) { p = endtag; } else { endsum = tag - 1; *(endtag - 1) = c; break; } } } /* Check for META TAG TYPE 2 */ else if ((tag[0] != '!') && lstrstr(tag, "META") && (tmp = lstrstr(tag, "NAME")) && (tmp2 = lstrstr(tag, "CONTENT"))) { tmp += 4; tmp3 = lstrstr(tmp, field); if (tmp3 && tmp3 < tmp2) { tmp2 += 7; if ((tmp = strchr(tmp2, '='))) { for (++tmp; isspace((int) ((unsigned char) *tmp)); tmp++); if (*tmp == '\"') { beginsum = tmp + 1; for (tmp = endtag - 1; tmp > beginsum; tmp--) if (*tmp == '\"') break; if (tmp == beginsum) endsum = endtag - 1; else endsum = tmp; } else { beginsum = tmp; endsum = endtag - 1; } found = 1; *(endtag - 1) = c; break; } } p = endtag; } /* Default: Continue */ else { p = endtag; } } else p = NULL; /* tag not closed ->END */ if (endtag) *(endtag - 1) = c; } else { /* No more '<' */ p = NULL; } } if (found && beginsum && endsum && endsum > beginsum) { lensummary = endsum - beginsum; summary = (char *)Mem_ZoneAlloc(sw->Index->perDocTmpZone, lensummary + 1); memcpy(summary, beginsum, lensummary); summary[lensummary] = '\0'; } /* If field is set an no metaname is found, let us search */ /* for something like <field>bla bla </field> */ if (!summary && field) { summary = parsetag(sw, field, buffer, 0, CASE_SENSITIVE_OFF); } /* Finally check for something after title (if exists) and */ /* after <body> (if exists) */ if (!summary) { /* Jump title if it exists */ if ((p = lstrstr(buffer, "</title>"))) { p += 8; } else p = buffer; /* Let us try to find <body> */ if ((q = lstrstr(p, "<body"))) { q = strchr(q, '>'); } else q = p; summary = (char *)Mem_ZoneAlloc(sw->Index->perDocTmpZone,strlen(q) + 1); strcpy(summary,q); } if (summary) { remove_newlines(summary); remove_tags(summary); summary = (char *)sw_ConvHTMLEntities2ISO(sw, (unsigned char *)summary); } if (summary && size && ((int) strlen(summary)) > size) summary[size] = '\0'; return summary; }