void TEST01_Sqstr_main() { SqString s, s1, s2, s3, s4; printf("(1)建立串s和串s1\n"); StrAssign(s, "abcdefghefghijklmn"); StrAssign(s1, "xyz"); printf("(2)输出串s:"); DispStr(s); printf("(3)串s的长度:%d\n", StrLength(s)); printf("(4)在串s的第9个字符位置插入串s1而产生串s2\n"); s2 = InsStr(s, 9, s1); printf("(5)输出串s2:"); DispStr(s2); printf("(6)删除串s第2个字符开始的5个字符而产生串s2\n"); s2 = DelStr(s, 2, 5); printf("(7)输出串s2:"); DispStr(s2); printf("(8)将串s第2个字符开始的5个字符替换成串s1而产生串s2\n"); s2 = RepStr(s, 2, 5, s1); printf("(9)输出串s2:"); DispStr(s2); printf("(10)提取串s的第2个字符开始的10个字符而产生串s3\n"); s3 = SubStr(s, 2, 10); printf("(11)输出串s3:"); DispStr(s3); printf("(12)将串s1和串s2连接起来而产生串s4\n"); s4 = Concat(s1, s2); printf("(13)输出串s4:"); DispStr(s4); }
LinkString *RepStrAll(LinkString *s, LinkString *s1, LinkString *s2) { int i; i = Index(s, s1); while (i >= 0) { DelStr(s, i + 1, StrLength(s1)); /*删除串s1*/ InsStr(s, i + 1, s2); /*插入串s2*/ i = Index(s, s1); } return (s); }
unsigned char GateServo::dispatcher(String message) { //TODO : insert dispatcher if (0==msgCompare(message,1,myName)){ engine(&message); return 1; } else if (0 == msgCompare(message, 1, TIMETICK)) { message = myName; InsStr(message, ENTRYSENSOR); engine(&message); return 1; } return 0; }
static void test_inserts(int level) { static bool first = TRUE; int ch; int limit; int row = 1; int col; int row2, col2; int length; wchar_t buffer[BUFSIZ]; WINDOW *look = 0; WINDOW *work = 0; WINDOW *show = 0; int margin = (2 * MY_TABSIZE) - 1; Options option = ((m_opt ? oMove : oDefault) | ((w_opt || (level > 0)) ? oWindow : oDefault)); if (first) { static char cmd[80]; setlocale(LC_ALL, ""); putenv(strcpy(cmd, "TABSIZE=8")); initscr(); (void) cbreak(); /* take input chars one at a time, no wait for \n */ (void) noecho(); /* don't echo input */ keypad(stdscr, TRUE); } limit = LINES - 5; if (level > 0) { look = newwin(limit, COLS - (2 * (level - 1)), 0, level - 1); work = newwin(limit - 2, COLS - (2 * level), 1, level); show = newwin(4, COLS, limit + 1, 0); box(look, 0, 0); wnoutrefresh(look); limit -= 2; } else { work = stdscr; show = derwin(stdscr, 4, COLS, limit + 1, 0); } keypad(work, TRUE); for (col = margin + 1; col < COLS; col += MY_TABSIZE) MvWVLine(work, row, col, '.', limit - 2); MvWVLine(work, row, margin, ACS_VLINE, limit - 2); MvWVLine(work, row, margin + 1, ACS_VLINE, limit - 2); limit /= 2; MvWAddStr(work, 1, 2, "String"); MvWAddStr(work, limit + 1, 2, "Chars"); wnoutrefresh(work); buffer[length = 0] = '\0'; legend(show, level, option, buffer, length); wnoutrefresh(show); doupdate(); /* * Show the characters inserted in color, to distinguish from those that * are shifted. */ if (has_colors()) { start_color(); init_pair(1, COLOR_WHITE, COLOR_BLUE); wbkgdset(work, COLOR_PAIR(1) | ' '); } while ((ch = read_linedata(work)) != ERR && !isQUIT(ch)) { wmove(work, row, margin + 1); switch (ch) { case key_RECUR: test_inserts(level + 1); touchwin(look); touchwin(work); touchwin(show); wnoutrefresh(look); wnoutrefresh(work); wnoutrefresh(show); doupdate(); break; case key_NEWLINE: if (row < limit) { ++row; /* put the whole string in, all at once */ col2 = margin + 1; switch (option) { case oDefault: if (n_opt > 1) { for (col = 0; col < length; col += n_opt) { col2 = ColOf(buffer, col, margin); if (move(row, col2) != ERR) { InsNStr(buffer + col, LEN(col)); } } } else { if (move(row, col2) != ERR) { InsStr(buffer); } } break; case oMove: if (n_opt > 1) { for (col = 0; col < length; col += n_opt) { col2 = ColOf(buffer, col, margin); MvInsNStr(row, col2, buffer + col, LEN(col)); } } else { MvInsStr(row, col2, buffer); } break; case oWindow: if (n_opt > 1) { for (col = 0; col < length; col += n_opt) { col2 = ColOf(buffer, col, margin); if (wmove(work, row, col2) != ERR) { WInsNStr(work, buffer + col, LEN(col)); } } } else { if (wmove(work, row, col2) != ERR) { WInsStr(work, buffer); } } break; case oMoveWindow: if (n_opt > 1) { for (col = 0; col < length; col += n_opt) { col2 = ColOf(buffer, col, margin); MvWInsNStr(work, row, col2, buffer + col, LEN(col)); } } else { MvWInsStr(work, row, col2, buffer); } break; } /* do the corresponding single-character insertion */ row2 = limit + row; for (col = 0; col < length; ++col) { col2 = ColOf(buffer, col, margin); switch (option) { case oDefault: if (move(row2, col2) != ERR) { InsCh((chtype) buffer[col]); } break; case oMove: MvInsCh(row2, col2, (chtype) buffer[col]); break; case oWindow: if (wmove(work, row2, col2) != ERR) { WInsCh(work, (chtype) buffer[col]); } break; case oMoveWindow: MvWInsCh(work, row2, col2, (chtype) buffer[col]); break; } } } else { beep(); } break; default: buffer[length++] = ch; buffer[length] = '\0'; /* put the string in, one character at a time */ col = ColOf(buffer, length - 1, margin); switch (option) { case oDefault: if (move(row, col) != ERR) { InsStr(buffer + length - 1); } break; case oMove: MvInsStr(row, col, buffer + length - 1); break; case oWindow: if (wmove(work, row, col) != ERR) { WInsStr(work, buffer + length - 1); } break; case oMoveWindow: MvWInsStr(work, row, col, buffer + length - 1); break; } /* do the corresponding single-character insertion */ switch (option) { case oDefault: if (move(limit + row, col) != ERR) { InsCh((chtype) ch); } break; case oMove: MvInsCh(limit + row, col, (chtype) ch); break; case oWindow: if (wmove(work, limit + row, col) != ERR) { WInsCh(work, (chtype) ch); } break; case oMoveWindow: MvWInsCh(work, limit + row, col, (chtype) ch); break; } wnoutrefresh(work); legend(show, level, option, buffer, length); wnoutrefresh(show); doupdate(); break; } } if (level > 0) { delwin(show); delwin(work); delwin(look); } }
integer ExeI() /* execute an I command */ { unsigned char InChar; DBGFEN(1,"ExeI",NULL); if (EStTop > EStBot) { /* if numeric argument */ if (GetNmA() == FAILURE) { /* get numeric argument */ DBGFEX(1,DbgFNm,"FAILURE, GetNmA() failed"); return FAILURE; } if (CmdMod & ATSIGN) { /* if it's n@I// */ if (IncCBP() == FAILURE) { DBGFEX(1,DbgFNm,"FAILURE, 1st IncCBP() failed"); return FAILURE; } if (IncCBP() == FAILURE) { DBGFEX(1,DbgFNm,"FAILURE, 2nd IncCBP() failed"); return FAILURE; } if (*CBfPtr != *(CBfPtr-1)) { ErrMsg(ERR_IIA); /* illegal insert arg */ DBGFEX(1,DbgFNm,"FAILURE, illegal insert arg"); return FAILURE; } } else { /* else must be nI$ */ if ((CBfPtr+1) == CStEnd) { if (MStTop < 0) { ErrUTC(); DBGFEX(1,DbgFNm,"FAILURE, unterminated command"); return FAILURE; } else { DBGFEX(1,DbgFNm,"SUCCESS"); return SUCCESS; } } if (*(CBfPtr+1) != ESCAPE) { ErrMsg(ERR_IIA); /* illegal insert arg */ DBGFEX(1,DbgFNm,"FAILURE, illegal insert arg"); return FAILURE; } } InChar = (char)NArgmt; if (InsStr(&InChar, (ptrdiff_t)1) == FAILURE) { DBGFEX(1,DbgFNm,"FAILURE, InsStr() failed"); return FAILURE; } } else { /* else no numeric argument */ if (FindES(ESCAPE) == FAILURE) { DBGFEX(1,DbgFNm,"FAILURE, FindES() failed"); return FAILURE; } if (InsStr(ArgPtr, CBfPtr-ArgPtr) == FAILURE) { DBGFEX(1,DbgFNm,"FAILURE, InsStr() failed"); return FAILURE; } } CmdMod = '\0'; /* clear modifiers flags */ DBGFEX(1,DbgFNm,"SUCCESS"); return SUCCESS; }