int main(){ struct arrayList* list = arrayListCreate(); arrayListAdd(list, "TOM"); arrayListAdd(list, "JERRY"); arrayListAdd(list, "Song of ice and fire"); arrayListAdd(list, "Game of Throne"); arrayListPrint(list); arrayListDelete(list, 2); arrayListPrint(list); return 0; }
int notifyListQueue(const void *data) { int result = 0; if (msgList) { arrayListAdd(msgList, (void *) data); result = 1; } return result; }
int listSetInsert(int element, arrayList l) { if (listSetIsFull(l)) { printf("%d", l[1]); return -1; } if (arrayListNextIndexOf(1, element, l) == -1) { arrayListAdd(element, l); return 0; } return -1; }
/** * xslDbgShellAddParam: * @arg: A string comprised of two words separated by * one or more spaces which are in UTF-8 * * Add a libxslt parameter to be sent to libxslt later on * * Returns 1 on success, * 0 otherwise */ int xslDbgShellAddParam(xmlChar * arg) { int result = 0; parameterItemPtr paramItem = NULL; static const char *errorPrompt = I18N_NOOP("Failed to add parameter"); xmlChar *opts[2]; if (!arg) { xsldbgGenericErrorFunc(i18n("Error: Invalid arguments for the command %1.\n").arg("addparam")); }else{ if ((xmlStrLen(arg) > 1) && splitString(arg, 2, opts) == 2) { int count; for (count = 0; count < arrayListCount(optionsGetParamItemList()); count++){ paramItem = (parameterItemPtr)arrayListGet(optionsGetParamItemList(), count); if (paramItem != NULL){ if (xmlStrCmp(opts[0], paramItem->name) == 0){ /* parameter exist just update its value */ if (paramItem->value) xmlFree(paramItem->value); paramItem->value = xmlStrdup(opts[1]); return 1; } } } paramItem = optionsParamItemNew(opts[0], opts[1]); result = arrayListAdd(optionsGetParamItemList(), paramItem); } else { xsldbgGenericErrorFunc(i18n("Error: Invalid arguments for the command %1.\n").arg("addparam")); } } if (!result) xsldbgGenericErrorFunc(QString("Error: %1\n").arg(i18n(errorPrompt))); else { xsldbgGenericErrorFunc("\n"); } return result; }
/** * breakPointAdd: * @url: Non-null, non-empty file name that has been loaded by * debugger * @lineNumber: @lineNumber >= 0 and is available in url specified and * points to an xml element * @templateName: The template name of breakPoint or NULL * @modeName : The mode of breakpoint or NULL * @type: Valid BreakPointTypeEnum * * Add break point at file and line number specified * * Returns 1 if successful, * 0 otherwise */ int breakPointAdd(const xmlChar * url, long lineNumber, const xmlChar * templateName, const xmlChar * modeName, BreakPointTypeEnum type) { int result = 0, breakPointType = type; xmlHashTablePtr breakPointHash = NULL; /* hash of breakPoints */ breakPointPtr breakPtr; if (!breakList) { #ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS xsltGenericError(xsltGenericErrorContext, "Error: Breakpoints structures not initialized\n"); #endif return result; } if (!url || (lineNumber == -1)) { #ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS xsltGenericError(xsltGenericErrorContext, "Error: Invalid url or line number to breakPointAdd\n"); #endif return result; } /* if breakpoint already exists then don;t add it */ if (breakPointIsPresent(url, lineNumber)) { #ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS xsltGenericError(xsltGenericErrorContext, "Warning: Breakpoint at file %s: line %d exists\n", url, lineNumber); #endif return result; } breakPtr = breakPointItemNew(); if (breakPtr) { breakPtr->url = (xmlChar *) xmlMemStrdup((char *) url); breakPtr->lineNo = lineNumber; if (templateName) breakPtr->templateName = xmlStrdup( templateName); else breakPtr->templateName = NULL; if (modeName) breakPtr->modeName = xmlStrdup(modeName); else breakPtr->modeName = NULL; breakPtr->type = BreakPointTypeEnum(breakPointType); /* add new breakPoint to the right hash table */ breakPointHash = breakPointGetLineNoHash(lineNumber); if (breakPointHash) { result = lineNoItemAdd(breakPointHash, breakPtr); } else { /* Grow breakList size */ int lineIndex; int newEntries = breakList->count; xmlHashTablePtr hash; result = 1; if ((lineNumber < breakList->count) && breakList->count) { #ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS xsltGenericError(xsltGenericErrorContext, "Error: Unable to find breakpoint line hash at %d\n", lineNumber); #endif } else { if (breakList->count + newEntries < lineNumber) newEntries = lineNumber - breakList->count + 1; #ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS /* * xsltGenericError(xsltGenericErrorContext, * "Size of line list was %d adding %d entries\n", * breakList->count, newEntries); */ #endif lineIndex = 0; while ((lineIndex < newEntries) && result) { hash = lineNoItemNew(); if (hash) { result = result && arrayListAdd(breakList, hash); } else { result = 0; #ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS xsltGenericError(xsltGenericErrorContext, "Error: Unable to create hash table breakPoint list: memory error\n"); #endif return result; } lineIndex++; } /* find the newly added hashtable of breakpoints */ breakPointHash = breakPointGetLineNoHash(lineNumber); if (breakPointHash) { result = lineNoItemAdd(breakPointHash, breakPtr); } else { #ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS xsltGenericError(xsltGenericErrorContext, "Error: Unable to create new breakPoint:interal error\n"); #endif return result; } } } } else { #ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS xsltGenericError(xsltGenericErrorContext, "Error: Unable to create new breakPoint: memory error\n"); #endif } if (result && (optionsGetIntOption(OPTIONS_GDB) > 1) && (xsldbgValidateBreakpoints != BREAKPOINTS_BEING_VALIDATED)){ breakPointPrint(breakPtr); xsldbgGenericErrorFunc("\n"); } return result; }