void testStringWithFixedLen() { SString S; CreateString(S); PrintString(S); SString S2; CreateString(S2); PrintString(S2); SString T; StrConcat(T, S, S2); PrintString(T); SString Sub; SubString(Sub, T, 2, 3); PrintString(Sub); printf("compare two string:\n"); SString s1; CreateString(s1); PrintString(s1); SString s2; CreateString(s2); PrintString(s2); int result = StrCompare(s1, s2); if (!result) printf("s1 == s2"); else if (result > 0) printf("s1 > s2"); else printf("s1 < s2"); printf("\n"); }
void PrintLabel( const char *labelName, const char *format, va_list *args ) { Str *label = StrNew( labelName ); Str *formatString = StrNew( format ); Str *messageString = StrConcat( label, formatString ); Print( messageString->value, args ); StrDel( label ); StrDel( formatString ); StrDel( messageString ); }
int main(int argc,char *argv[]) { HString H,T,Sub,S; char str[]="123456"; char arr[]="12345678"; StrAssign(&H,str); StrAssign(&T,arr); PrintStr(H); printf("\n"); PrintStr(T); printf("\n"); printf("Length:%d,compare:%d\n",StrLength(H),StrCompare(H,T)); SubString(&Sub,H,2,3); PrintStr(Sub); printf("\n"); StrConcat(&S,H,T); printf("\n"); PrintStr(S); }
int ecMkV1C(const char * const str, ...) { char *line, *verbatim; va_list ap; int rv; if((verbatim = ecMkVerbatimStr(str)) == 0) return E_NoMem; if((line = StrConcat(5, "%@VERBATIM(", verbatim, ")", str, verbatim)) == 0) { error_out_of_memory(); myfree(verbatim); return E_NoMem; } myfree(verbatim); va_start(ap, str); rv = ecMkvcmd(lflag_echo? 0: EC_CMD_SILENT, line, ap); myfree(line); return rv; }
Widget XmdsCreateDisplay(Widget parent, String name, ArgList args, Cardinal argcount) { XmdsDisplayPart info = {-1,0}; Widget w; Arg lab_args[] = {{XmNlabelString, 0}, {XmNuserData, DisplayUserData}}; Arg *merged_args; int nid; XmdsSetSubvalues(&info, resources, XtNumber(resources), args, argcount); if (info.nid == -1) info.nid = XmdsGetDeviceNid(); if (info.nid != -1) nid = info.nid + info.nid_offset; else nid = -1; if (nid != -1) { static struct descriptor_d display_dsc = {0, DTYPE_T, CLASS_D, 0}; static struct descriptor_xd xd = {0, DTYPE_DSC, CLASS_XD, 0, 0}; struct descriptor nid_dsc = {sizeof(int), DTYPE_NID, CLASS_S, (char *)0}; int status; nid_dsc.pointer = (char *)&nid; status = TdiEvaluate(&nid_dsc, &xd MDS_END_ARG); if (status&1) { status = TdiDecompile(&xd, &display_dsc MDS_END_ARG); if (status&1) { static DESCRIPTOR(zero_dsc, "\0"); StrConcat((struct descriptor *)&display_dsc, (struct descriptor *)&display_dsc, &zero_dsc MDS_END_ARG); lab_args[0].value = (long)XmStringCreateSimple(display_dsc.pointer); } else lab_args[0].value = (long)XmStringCreateSimple("Error - Decomp"); } else lab_args[0].value = (long)XmStringCreateSimple("Error - Eval"); } merged_args = XtMergeArgLists(args, argcount, lab_args, XtNumber(lab_args)); w = XmCreateLabel(parent, name, merged_args, XtNumber(lab_args) + argcount); XtFree((char *)lab_args[0].value); XtFree((char *)merged_args); return w; }
int main() { std::cout << StrConcat(1, "sb") << std::endl; return 0; }
int Tdi0Decompile_R( struct descriptor_r *pin, int prec, struct descriptor_d *pout) { struct descriptor_r *r_ptr; char *ptext; struct TdiFunctionStruct *fun_ptr; int narg = pin->ndesc; int m, lorr, newone, status = 1; struct op_rec *pop; unsigned int dtype; enum OpcOpcodes opcode; switch (pin->dtype) { default : status = Append("%Unknown%", pout); break; case DTYPE_PARAM : case DTYPE_SIGNAL : case DTYPE_DIMENSION : case DTYPE_WINDOW : case DTYPE_SLOPE : case DTYPE_CONGLOM : case DTYPE_ACTION : case DTYPE_DISPATCH : case DTYPE_PROGRAM : case DTYPE_ROUTINE : case DTYPE_PROCEDURE : case DTYPE_METHOD : case DTYPE_DEPENDENCY : case DTYPE_CONDITION : case DTYPE_WITH_UNITS : case DTYPE_WITH_ERROR : case DTYPE_OPAQUE : build: status = Append("Build_", pout); if (status&1) status = Append(bname[pin->dtype - DTYPE_PARAM], pout); if (status&1) status = Append("(", pout); if (pin->length) { if (pin->length == 1) opcode = (enum OpcOpcodes)(*(unsigned char *)pin->pointer); else if (pin->length == 2) opcode = (enum OpcOpcodes)(*(unsigned short *)pin->pointer); else if (pin->length == 4) opcode = (enum OpcOpcodes)(*(unsigned int *)pin->pointer); else opcode = (enum OpcOpcodes)-1; if (status&1) status = TdiSingle(opcode, pout); if (status&1) status = Append(", ", pout); } if (status&1) status = Arguments(0, 0, ")", pin, pout); break; case DTYPE_RANGE : opcode = OpcDtypeRange; goto range; case DTYPE_FUNCTION : opcode = (enum OpcOpcodes)(*(unsigned short *)pin->pointer); if ((int)opcode >= TdiFUNCTION_MAX) return (int)(opcode = (enum OpcOpcodes)0); range: fun_ptr = (struct TdiFunctionStruct *)&TdiRefFunction[opcode]; if (narg < fun_ptr->m1 || narg > fun_ptr->m2) goto cannot; else if (fun_ptr->token == LEX_CONST) status = Append(fun_ptr->name, pout); /***************************************** Functions, subscripts, and constructors. *****************************************/ else switch (opcode) { default : /*intrinsic(arg, ...)*/ cannot: status = Append(fun_ptr->name, pout); if (status&1) status = Arguments(0, "(", ")", pin, pout); break; case OpcFun : /*fun ident(arg, ...) stmt*/ if (prec < P_STMT) status = Append("(", pout); if (status&1) status = Append("Fun ", pout); if (!(status&1)) break; r_ptr = (struct descriptor_r *)pin->dscptrs[0]; if (r_ptr->dtype == DTYPE_T) status = StrAppend(pout, r_ptr); else status = Tdi0Decompile(r_ptr, P_SUBS, pout); if (status&1) status = Arguments(2, " (", ") ", pin, pout); if (status&1) status = CompoundStatement(1, (struct descriptor_r **)&pin->dscptrs[1], pout); if (status&1 && prec < P_STMT) status = Append(")", pout); break; case OpcIn : /*input argument*/ case OpcInOut : /*input and output argument*/ case OpcOptional : /*optional argument*/ case OpcOut : /*output argument*/ case OpcPrivate : /*private ident*/ case OpcPublic : /*public ident*/ status = Append(fun_ptr->name, pout); if (status & 1) status = Append(" ", pout); r_ptr = (struct descriptor_r *)pin->dscptrs[0]; if (status & 1) if (r_ptr->dtype == DTYPE_T) status = StrAppend(pout, r_ptr); else status = Tdi0Decompile(r_ptr, P_SUBS, pout); break; case OpcExtFunction : /*_label(arg, ...)*/ if (pin->dscptrs[0] != 0 || pin->dscptrs[1] == 0 || pin->dscptrs[1]->dtype != DTYPE_T) goto cannot; status = StrAppend(pout, pin->dscptrs[1]); if (status&1) status = Arguments(2, "(", ")", pin, pout); break; case OpcSubscript : /*postfix[subscript, ...]*/ status = Tdi0Decompile(pin->dscptrs[0], P_SUBS, pout); if (status&1) status = Arguments(1, "[", "]", pin, pout); break; case OpcVector : /*[elem, ...]*/ status = Arguments(0, "[", "]", pin, pout); break; /**************** Unary operations. ****************/ case OpcInot : case OpcNot : case OpcPreDec : case OpcPreInc : case OpcUnaryMinus :case OpcUnaryPlus : case OpcPostDec : case OpcPostInc : for (pop = unary; pop->opcode; pop++) if ((enum OpcOpcodes)pop->opcode == opcode) break; newone = pop->prec; lorr = pop->lorr; if ( lorr > 0) status = Append(pop->symbol, pout); if (status&1 && prec <= newone) status = Append("(", pout); if (status&1) status = Tdi0Decompile(pin->dscptrs[0], newone + lorr, pout); if (status&1 && prec <= newone) status = Append(")", pout); if (status&1 && lorr < 0) status = Append(pop->symbol, pout); break; /*********************** Binary/n-ary operations. ***********************/ case OpcEqualsFirst : r_ptr = (struct descriptor_r *)pin->dscptrs[0]; newone = *(unsigned short *)r_ptr->pointer; narg = r_ptr->ndesc; goto first; case OpcPower : case OpcDivide : case OpcMultiply : case OpcAdd : case OpcSubtract : case OpcShiftLeft : case OpcShiftRight : case OpcConcat : case OpcIsIn : case OpcGe : case OpcGt : case OpcLe : case OpcLt : case OpcEq : case OpcNe : case OpcAnd : case OpcNand : case OpcOr : case OpcNor : case OpcEqv : case OpcNeqv : case OpcPromote : case OpcEquals : case OpcDtypeRange : case OpcComma : case OpcConditional : r_ptr = (struct descriptor_r *)pin; newone = (int)opcode; first: for (pop = binary; pop->opcode; pop++) if (pop->opcode == newone) break; newone = pop->prec; lorr = pop->lorr; if (opcode == OpcEqualsFirst) { newone = binary[2].prec; lorr = binary[2].lorr; } if (prec <= newone) status = Append("(", pout); if (opcode == OpcConditional) { if (status&1) status = Tdi0Decompile(r_ptr->dscptrs[2], newone - lorr, pout); if (status&1) status = Append(pop->symbol, pout); if (status&1) status = Tdi0Decompile(r_ptr->dscptrs[0], newone, pout); if (status&1) status = Append(" : ", pout); if (status&1) status = Tdi0Decompile(r_ptr->dscptrs[1], newone + lorr, pout); } else { if (status&1) status = Tdi0Decompile(r_ptr->dscptrs[0], newone - lorr, pout); for (m = 1; m < narg; m++) { if (status&1) status = Append(pop->symbol, pout); if (status&1 && pin != r_ptr) status = Append("= ", pout); if (status&1) status = Tdi0Decompile(r_ptr->dscptrs[m], newone + lorr, pout); } } if (status&1 && prec <= newone) status = Append(")", pout); break; /***************************************** C-language constructs followed by newline. Plus WHERE. *****************************************/ case OpcBreak : /*break;*/ case OpcContinue : /*continue;*/ if (prec < P_STMT) status = Append("(", pout); if (status&1) status = Append(fun_ptr->name, pout); if (status&1) status = OneStatement(0, pout); if (prec < P_STMT && status&1) status = Append(")", pout); break; case OpcCase : /*case (xxx) stmt ...*/ if (prec < P_STMT) status = Append("(", pout); if (status&1) status = Append("Case (", pout); if (status&1) status = Tdi0Decompile(pin->dscptrs[0], P_STMT, pout); if (status&1) status = Append(") ", pout); if (status&1) status = MultiStatement(narg-1, (struct descriptor_r **)&pin->dscptrs[1], pout); if (prec < P_STMT && status&1) status = Append(")", pout); break; case OpcDefault : /*case default stmt ...*/ if (prec < P_STMT) status = Append("(", pout); if (status&1) status = Append("Case Default ", pout); if (status&1) status = MultiStatement(narg, (struct descriptor_r **)&pin->dscptrs[0], pout); if (prec < P_STMT && status&1) status = Append(")", pout); break; case OpcDo : /*do {stmt} while (exp); Note argument order is (exp,stmt,...)*/ if (prec < P_STMT) status = Append("(", pout); if (status&1) status = Append("DO {", pout); if (status&1) status = MultiStatement(narg-1, (struct descriptor_r **)&pin->dscptrs[1], pout); if (status&1) status = Append("} While ", pout); if (status&1) status = Tdi0Decompile(pin->dscptrs[0], P_STMT, pout); if (status&1) status = MultiStatement(0, (struct descriptor_r **)0, pout); if (prec < P_STMT && status&1) status = Append(")", pout); break; case OpcFor : /*for (init;test;step) stmt*/ if (prec < P_STMT) status = Append("(", pout); if (status&1) status = Append("For (", pout); if (status&1) status = Tdi0Decompile(pin->dscptrs[0], P_STMT, pout); if (status&1) status = Append("; ", pout); if (status&1) status = Tdi0Decompile(pin->dscptrs[1], P_STMT, pout); if (status&1) status = Append("; ", pout); if (status&1) status = Tdi0Decompile(pin->dscptrs[2], P_STMT, pout); if (status&1) status = Append(") ", pout); if (status&1) status = CompoundStatement(narg-3, (struct descriptor_r **)&pin->dscptrs[3], pout); if (prec < P_STMT && status&1) status = Append(")", pout); break; case OpcGoto : /*goto xxx;*/ if (prec < P_STMT) status = Append("(", pout); if (status&1) status = Append("GoTo ", pout); if (status&1) status = StrAppend(pout, pin->dscptrs[0]); if (status&1) status = OneStatement(0, pout); if (prec < P_STMT && status&1) status = Append(")", pout); break; case OpcIf : /*if (exp) stmt else stmt*/ case OpcWhere : /*where (exp) stmt elsewhere stmt*/ if (prec < P_STMT) status = Append("(", pout); if (status&1) status = Append((opcode == OpcIf) ? "If (" : "Where (", pout); if (status&1) status = Tdi0Decompile(pin->dscptrs[0], P_STMT, pout); if (status&1) status = Append(") ", pout); if (status&1) status = CompoundStatement(1, (struct descriptor_r **)&pin->dscptrs[1], pout); if (status&1 && narg >= 3) { status = Append((opcode == OpcIf) ? " Else " : " ElseWhere ", pout); if (status&1) status = CompoundStatement(1, (struct descriptor_r **)&pin->dscptrs[2], pout); } if (prec < P_STMT && status&1) status = Append(")", pout); break; case OpcLabel : /*xxx : stmt ...*/ if (prec < P_STMT) status = Append("(", pout); if (status&1) status = Append("Label ", pout); if (status&1) status = StrAppend(pout, pin->dscptrs[0]); if (status&1) status = Append(" : ", pout); if (status&1) status = MultiStatement(narg-1, (struct descriptor_r **)&pin->dscptrs[1], pout); if (prec < P_STMT && status&1) status = Append(")", pout); break; case OpcReturn : /*return (optional-exp);*/ if (prec < P_STMT) status = Append("(", pout); if (status&1) status = Append("Return (", pout); if (status&1) status = Tdi0Decompile(pin->ndesc ? pin->dscptrs[0] : 0, P_STMT, pout); if (status&1) status = Append(")", pout); if (status&1) status = OneStatement(0, pout); if (prec < P_STMT && status&1) status = Append(")", pout); break; case OpcStatement : /*{stmt ...}*/ if (prec < P_STMT) status = Append("(", pout); if (status&1) status = MultiStatement(narg, (struct descriptor_r **)&pin->dscptrs[0], pout); if (prec < P_STMT && status&1) status = Append(")", pout); break; case OpcSwitch : /*switch (exp) stmt*/ case OpcWhile : /*while (exp) stmt*/ if (prec < P_STMT) status = Append("(", pout); if (status&1) status = Append((opcode == OpcSwitch) ? "Switch (" : "While (", pout); if (status&1) status = Tdi0Decompile(pin->dscptrs[0], P_STMT, pout); if (status&1) status = Append(") ", pout); if (status&1) status = CompoundStatement(narg-1, (struct descriptor_r **)&pin->dscptrs[1], pout); if (prec < P_STMT && status&1) status = Append(")", pout); break; } /******************** End of opcode switch. ********************/ break; case DTYPE_CALL : /*label->label(arg, ...) or label->label:type(arg, ...)*/ if (pin->dscptrs[0] == 0 || pin->dscptrs[0]->dtype != DTYPE_T) goto build; if (pin->dscptrs[1] == 0 || pin->dscptrs[1]->dtype != DTYPE_T) goto build; status = StrConcat((struct descriptor *)pout, (struct descriptor *)pout, pin->dscptrs[0], &ARROW, pin->dscptrs[1] MDS_END_ARG); if (status&1 && pin->length && pin->pointer) { dtype = *(char *)pin->pointer; if (dtype < TdiCAT_MAX) ptext = TdiREF_CAT[dtype].name; else if (dtype == DTYPE_NID) ptext = "Nid"; else if (dtype == DTYPE_PATH) ptext = "Path"; else ptext = "%Unknown%"; status = Append(":", pout); if (status&1) status = Append(ptext , pout); } if (status&1) status = Arguments(2, "(", ")", pin, pout); break; } /******************* End of dtype switch. *******************/ return status; }
STATIC_ROUTINE int DependencyGet(int prec, struct descriptor_r *pin, struct descriptor_d *pout) { int now = 0, status = 1; struct descriptor *pwhich = 0; switch (pin->dtype) { case DTYPE_EVENT: status = StrConcat((struct descriptor *)pout, (struct descriptor *)pout, &LEFT_ANGLE, pin, &RIGHT_ANGLE MDS_END_ARG); break; case DTYPE_NID: { char *path = TreeGetMinimumPath(0, *(int *)pin->pointer); if (path != NULL) { DESCRIPTOR_FROM_CSTRING(path_d, path); status = StrAppend(pout, &path_d); TreeFree(path); } else status = TreeFAILURE; } break; case DTYPE_PATH: status = StrAppend(pout, pin); break; case DTYPE_DEPENDENCY: switch (*(short *)pin->pointer) { case TreeDEPENDENCY_AND: now = P_AND; pwhich = (struct descriptor *)&AND; break; case TreeDEPENDENCY_OR: now = P_OR; pwhich = (struct descriptor *)&OR; break; default: status = TdiINV_OPC; break; } if (status & 1 && now < prec) status = StrAppend(pout, &LEFT_PAREN); if (status & 1) status = DependencyGet(now - 1, (struct descriptor_r *)pin->dscptrs[0], pout); if (status & 1) status = StrAppend(pout, pwhich); if (status & 1) status = DependencyGet(now + 1, (struct descriptor_r *)pin->dscptrs[1], pout); if (status & 1 && now < prec) status = StrAppend(pout, &RIGHT_PAREN); break; case DTYPE_CONDITION: switch (*((short *)pin->pointer)) { case TreeNEGATE_CONDITION: pwhich = (struct descriptor *)&NEGATE; break; case TreeIGNORE_UNDEFINED: pwhich = (struct descriptor *)&IGNORE_UNDEFINED; break; case TreeIGNORE_STATUS: pwhich = (struct descriptor *)&IGNORE_STATUS; break; default: status = TdiINV_OPC; break; } if (status & 1) status = StrAppend(pout, pwhich); if (status & 1) status = DependencyGet(P_UNARY, (struct descriptor_r *)pin->dscptrs[0], pout); break; default: status = TdiINVDTYDSC; break; } return status; }