static void cleanupStringP(char **loc) { char *s; if ( (s=*loc) ) { *loc = NULL; remove_string(s); } }
int replace_string(char source[], char find[], char replace[]) { int found; int f_length; for (f_length = 0; find[f_length] != '\0'; ++f_length) { } found = find_string(source, find); if (found != -1) { remove_string(source, found, f_length); insert_string(source, replace, found); } return found; }
static void cleanupOptListP(opt_list **listp) { opt_list *l, *n; if ( (l=*listp) ) { *listp = NULL; for(; l; l=n) { n = l->next; remove_string(l->opt_val); freeHeap(l, sizeof(*l)); } } }
int main() { char str[] = "chatterbox"; char substr[SIZE]; printf("position = %i\n", find_string(str, "ter")); remove_string(str, 2, 4); printf("%s\n", str); sub_string(str, 2, 29, substr); printf("%s\n", substr); return 0; }
void getenc(encoding ev, int width[256]) { int i, SCMseen, Ccnt, wx, cc; FILE *afm; char *name, ns; for (i=0; i < 256; i++) { ev[i] = NULL; width[i] = -1000; } if (encfile) { enc = fopen(encfile, "r"); if (enc == NULL) fatal("Can't open %s\n", encfile); if (nextsymbol() != '/') fatal("missing '/encoding' in %s\n", encfile); if (nextsymbol() != '[') fatal("missing '[' in %s\n", encfile); i = 0; while (i < 256 && (ns = nextsymbol()) == '/') { name = string(pline); if (strcmp(name, ".notdef") == 0) { i++; remove_string(); continue; } addcc(name, i++); } if (i != 256) fatal("missing %d symbols in %s\n", 256-i, encfile); if (nextsymbol() != ']') fatal("missing ']' in %s\n", encfile); fclose(enc); } afm = fopen(afmfile, "r"); if (afm == NULL) fatal("Can't open %s\n", afmfile); SCMseen = 0; Ccnt = 0; while (fgets(line, LINEBUF-1, afm)) if (strncmp(line, "StartCharMetrics", 16) == 0) { SCMseen = 1; break; } if (SCMseen == 0) fatal("%s: no valid AFM file\n", afmfile); while (fgets(line, LINEBUF-1, afm)) { if (strncmp(line, "EndCharMetrics", 14) == 0) break; if (strncmp(line, "C ", 2) != 0) fatal("%s: unexpected line\n", afmfile); /* Gracefully terminate when the AFM file is not valid. Every line */ /* in the AFM file should specify a "C"haracter, a "WX"idth, and */ /* a "N"ame. (ndw) */ pline = value_after(line, "C"); if (pline == NULL) fatal("\nBad char metric in %s (no char):\n\t %s\n", afmfile, line); cc = decimal(pline); pline = value_after(pline, "WX"); if (pline == NULL) fatal("\nBad char metric in %s (no width):\n\t %s\n", afmfile, line); wx = decimal(pline); pline = value_after(pline, "N"); if (pline == NULL) fatal("\nBad char metric in %s (no name):\n\t %s\n", afmfile, line); name = string(pline); if (encfile) { if ((i = getcc(name)) == -1) { remove_string(); continue; } do { /* allow more occurences per name */ ev[i] = name; width[i] = wx; i = getcc(name); } while (i >= 0); } else if (cc >= 0 && cc <= 255) { /* ndw: 10/13/92 */ ev[cc] = name; width[cc] = wx; } else if (cc > 255) printf("Char code %d ignored (out of range).\n", cc); Ccnt++; } if (Ccnt == 0) fatal("%s: no characters selected\n", afmfile); }
/* Play at (i, j) for color. No legality check is done here. We need * to properly update the board array, the next_stone array, and the * ko point. */ static void play_move(int i, int j, int color) { int pos = POS(i, j); int captured_stones = 0; int k; /* Reset the ko point. */ ko_i = -1; ko_j = -1; /* Nothing more happens if the move was a pass. */ if (pass_move(i, j)) return; /* If the move is a suicide we only need to remove the adjacent * friendly stones. */ if (suicide(i, j, color)) { for (k = 0; k < 4; k++) { int ai = i + deltai[k]; int aj = j + deltaj[k]; if (on_board(ai, aj) && get_board(ai, aj) == color) remove_string(ai, aj); } return; } /* Not suicide. Remove captured opponent strings. */ for (k = 0; k < 4; k++) { int ai = i + deltai[k]; int aj = j + deltaj[k]; if (on_board(ai, aj) && get_board(ai, aj) == OTHER_COLOR(color) && !has_additional_liberty(ai, aj, i, j)) captured_stones += remove_string(ai, aj); } /* Put down the new stone. Initially build a single stone string by * setting next_stone[pos] pointing to itself. */ board[pos] = color; next_stone[pos] = pos; /* If we have friendly neighbor strings we need to link the strings * together. */ for (k = 0; k < 4; k++) { int ai = i + deltai[k]; int aj = j + deltaj[k]; int pos2 = POS(ai, aj); /* Make sure that the stones are not already linked together. This * may happen if the same string neighbors the new stone in more * than one direction. */ if (on_board(ai, aj) && board[pos2] == color && !same_string(pos, pos2)) { /* The strings are linked together simply by swapping the the * next_stone pointers. */ int tmp = next_stone[pos2]; next_stone[pos2] = next_stone[pos]; next_stone[pos] = tmp; } } /* If we have captured exactly one stone and the new string is a * single stone it may have been a ko capture. */ if (captured_stones == 1 && next_stone[pos] == pos) { int ai, aj; /* Check whether the new string has exactly one liberty. If so it * would be an illegal ko capture to play there immediately. We * know that there must be a liberty immediately adjacent to the * new stone since we captured one stone. */ for (k = 0; k < 4; k++) { ai = i + deltai[k]; aj = j + deltaj[k]; if (on_board(ai, aj) && get_board(ai, aj) == EMPTY) break; } if (!has_additional_liberty(i, j, ai, aj)) { ko_i = ai; ko_j = aj; } } }
void QTextDocumentPrivate::move(int pos, int to, int length, QTextUndoCommand::Operation op) { Q_ASSERT(to <= fragments.length() && to <= pos); Q_ASSERT(pos >= 0 && pos+length <= fragments.length()); Q_ASSERT(blocks.length() == fragments.length()); if (pos == to) return; const bool needsInsert = to != -1; #if !defined(QT_NO_DEBUG) const bool startAndEndInSameFrame = (frameAt(pos) == frameAt(pos + length - 1)); const bool endIsEndOfChildFrame = (isAncestorFrame(frameAt(pos), frameAt(pos + length - 1)) && text.at(find(pos + length - 1)->stringPosition) == QTextEndOfFrame); const bool startIsStartOfFrameAndEndIsEndOfFrameWithCommonParent = (text.at(find(pos)->stringPosition) == QTextBeginningOfFrame && text.at(find(pos + length - 1)->stringPosition) == QTextEndOfFrame && frameAt(pos)->parentFrame() == frameAt(pos + length - 1)->parentFrame()); const bool isFirstTableCell = (qobject_cast<QTextTable *>(frameAt(pos + length - 1)) && frameAt(pos + length - 1)->parentFrame() == frameAt(pos)); Q_ASSERT(startAndEndInSameFrame || endIsEndOfChildFrame || startIsStartOfFrameAndEndIsEndOfFrameWithCommonParent || isFirstTableCell); #endif beginEditBlock(); split(pos); split(pos+length); uint dst = needsInsert ? fragments.findNode(to) : 0; uint dstKey = needsInsert ? fragments.position(dst) : 0; uint x = fragments.findNode(pos); uint end = fragments.findNode(pos+length); uint w = 0; while (x != end) { uint n = fragments.next(x); uint key = fragments.position(x); uint b = blocks.findNode(key+1); QTextBlockData *B = blocks.fragment(b); int blockRevision = B->revision; QTextFragmentData *X = fragments.fragment(x); QTextUndoCommand c = { QTextUndoCommand::Removed, true, op, X->format, X->stringPosition, key, { X->size }, blockRevision }; QTextUndoCommand cInsert = { QTextUndoCommand::Inserted, true, op, X->format, X->stringPosition, dstKey, { X->size }, blockRevision }; if (key+1 != blocks.position(b)) { // qDebug("remove_string from %d length %d", key, X->size); Q_ASSERT(noBlockInString(text.mid(X->stringPosition, X->size))); w = remove_string(key, X->size, op); if (needsInsert) { insert_string(dstKey, X->stringPosition, X->size, X->format, op); dstKey += X->size; } } else { // qDebug("remove_block at %d", key); Q_ASSERT(X->size == 1 && isValidBlockSeparator(text.at(X->stringPosition))); b = blocks.previous(b); B = 0; c.command = blocks.size(b) == 1 ? QTextUndoCommand::BlockDeleted : QTextUndoCommand::BlockRemoved; w = remove_block(key, &c.blockFormat, QTextUndoCommand::BlockAdded, op); if (needsInsert) { insert_block(dstKey++, X->stringPosition, X->format, c.blockFormat, op, QTextUndoCommand::BlockRemoved); cInsert.command = blocks.size(b) == 1 ? QTextUndoCommand::BlockAdded : QTextUndoCommand::BlockInserted; cInsert.blockFormat = c.blockFormat; } } appendUndoItem(c); if (B) B->revision = undoState; x = n; if (needsInsert) appendUndoItem(cInsert); } if (w) unite(w); Q_ASSERT(blocks.length() == fragments.length()); endEditBlock(); }
unsigned ConfigElem::remove_unsigned( const char *propname ) { string temp = remove_string( propname ); return strtoul( temp.c_str(), NULL, 0 ); // TODO check unsigned range }
int ConfigElem::remove_int( const char *propname ) { string temp = remove_string( propname ); return atoi( temp.c_str() ); }
void getenc(char **fontname, char **encname, encoding ev, int width[256]) { int i, len, SCMseen, Ccnt, wx, cc; FILE *afm; char *name, ns; for (i=0; i < 256; i++) { ev[i] = NULL; width[i] = -1000; } if (encfile) { enc = fopen(encfile, "r"); if (enc == NULL) fatal("Can't open %s\n", encfile); if (nextsymbol() != '/') fatal("missing '/encoding' in %s\n", encfile); *encname = nextpsname(); if (nextsymbol() != '[') fatal("missing '[' in %s\n", encfile); i = 0; while (i < 256 && (ns = nextsymbol()) == '/') { name = my_string(pline); if (strcmp(name, ".notdef") == 0) { i++; remove_string(); continue; } addcc(name, i++); } if (i != 256) fatal("missing %d symbols in %s\n", 256-i, encfile); if (nextsymbol() != ']') fatal("missing ']' in %s\n", encfile); fclose(enc); } afm = fopen(afmfile, "r"); if (afm == NULL) fatal("Can't open %s\n", afmfile); /* * Scan header of AFM file and take the FontName and EncodingScheme * (used for identification purposes in the PK postamble) * Stop after reading `StartCharMetrics'. */ SCMseen = 0; Ccnt = 0; while (fgets(line, LINEBUF-1, afm)) { if (strncmp(line, "FontName", 8) == 0) { pline = value_after(line, "FontName"); len = strlen(pline); if (*(pline+len-1) == '\n') { *(pline+len-1) = '\0'; len--; } *fontname = malloc(len + 1); if (*fontname == NULL) fatal("Out of memory\n"); strcpy(*fontname, pline); } else if (encname == NULL && strncmp(line, "EncodingScheme", 8) == 0) { pline = value_after(line, "EncodingScheme"); len = strlen(pline); if (*(pline+len-1) == '\n') { *(pline+len-1) = '\0'; len--; } *encname = malloc(len + 1); if (*encname == NULL) fatal("Out of memory\n"); strcpy(*encname, pline); } else if (strncmp(line, "StartCharMetrics", 16) == 0) { SCMseen = 1; break; } } if (SCMseen == 0) fatal("%s: no metrics info\n", afmfile); while (fgets(line, LINEBUF-1, afm)) { if (strncmp(line, "EndCharMetrics", 14) == 0) break; if (strncmp(line, "C ", 2) != 0) fatal("%s: unexpected line\n", afmfile); /* Gracefully terminate when the AFM file is not valid. Every line */ /* in the AFM file should specify a "C"haracter, a "WX"idth, and */ /* a "N"ame. (ndw) */ pline = value_after(line, "C"); if (pline == NULL) fatal("\nBad char metric in %s (no char):\n\t %s\n", afmfile, line); cc = decimal(pline); pline = value_after(pline, "WX"); if (pline == NULL) fatal("\nBad char metric in %s (no width):\n\t %s\n", afmfile, line); wx = decimal(pline); pline = value_after(pline, "N"); if (pline == NULL) fatal("\nBad char metric in %s (no name):\n\t %s\n", afmfile, line); name = my_string(pline); if (encfile) { if ((i = getcc(name)) == -1) { remove_string(); continue; } do { /* allow more occurences per name */ ev[i] = name; width[i] = wx; i = getcc(name); } while (i >= 0); } else if (cc >= 0 && cc <= 255) { /* ndw: 10/13/92 */ ev[cc] = name; width[cc] = wx; } else if (cc > 255) msg("Char code %d ignored (out of range).\n", cc); Ccnt++; } if (Ccnt == 0) fatal("%s: no characters selected\n", afmfile); }