示例#1
0
// copied from cPecanRealign
struct PairwiseAlignment *convertAlignedPairsToPairwiseAlignment(char *seqName1, char *seqName2, double score,
        int64_t length1, int64_t length2, stList *alignedPairs) {
    //Make pairwise alignment
    int64_t pX = -1, pY = -1, mL = 0;
    //Create an end matched pair, which is used to ensure the alignment has the correct end indels.
    struct List *opList = constructEmptyList(0, (void (*)(void *)) destructAlignmentOperation);
    stList_append(alignedPairs, stIntTuple_construct2(length1, length2));
    for (int64_t i = 0; i < stList_length(alignedPairs); i++) {
        stIntTuple *alignedPair = stList_get(alignedPairs, i);
        int64_t x = stIntTuple_get(alignedPair, 0);
        int64_t y = stIntTuple_get(alignedPair, 1);
        assert(x - pX > 0);
        assert(y - pY > 0);
        if (x - pX > 0 && y - pY > 0) { //This is a hack for filtering
            if (x - pX > 1) { //There is an indel.
                if (mL > 0) {
                    listAppend(opList, constructAlignmentOperation(PAIRWISE_MATCH, mL, 0));
                    mL = 0;
                }
                listAppend(opList, constructAlignmentOperation(PAIRWISE_INDEL_X, x - pX - 1, 0));
            }
            if (y - pY > 1) {
                if (mL > 0) {
                    listAppend(opList, constructAlignmentOperation(PAIRWISE_MATCH, mL, 0));
                    mL = 0;
                }
                listAppend(opList, constructAlignmentOperation(PAIRWISE_INDEL_Y, y - pY - 1, 0));
            }
            mL++;
            pX = x;
            pY = y;
        }
    }
    //Deal with a trailing match, but exclude the final match
    if (mL > 1) {
        listAppend(opList, constructAlignmentOperation(PAIRWISE_MATCH, mL - 1, 0));
    }
    stIntTuple_destruct(stList_pop(alignedPairs));
    //Construct the alignment
    struct PairwiseAlignment *pA = constructPairwiseAlignment(seqName1, 0, length1, 1, seqName2, 0, length2, 1, score,
            opList);
    return pA;
}
示例#2
0
genxStatus genxStartElement(genxElement e)
{
  genxWriter w = e->writer;
  int i;

  switch (w->sequence)
  {
  case SEQUENCE_NO_DOC:
  case SEQUENCE_POST_DOC:
    return w->status = GENX_SEQUENCE_ERROR;
  case SEQUENCE_START_TAG:
  case SEQUENCE_ATTRIBUTES:
    if ((w->status = writeStartTag(w)) != GENX_SUCCESS)
      return w->status;
    break;
  case SEQUENCE_PRE_DOC:
  case SEQUENCE_CONTENT:
    break;
  }

  w->sequence = SEQUENCE_START_TAG;

  /* clear provided attributes */
  for (i = 0; i < w->attributes.count; i++)
    ((genxAttribute) w->attributes.pointers[i])->provided = 0;

  /*
   * push the stack.  We push a NULL after a pointer to this element
   *  because the stack will also contain pointers to the namespace
   *  attributes that got declared here, so we can keep track of what's
   *  in effect.  I.e. a single stack entry consists logically of a pointer
   *  to an element object, a NULL, then zero or more pairs of pointers to
   *  namespace objects/declarations
   */
  if ((w->status = listAppend(&w->stack, e)) != GENX_SUCCESS)
    return w->status;
  if ((w->status = listAppend(&w->stack, NULL)) != GENX_SUCCESS)
    return w->status;

  w->nowStarting = e;

  return GENX_SUCCESS;
}
// Append pointer to new element to list l
void listAppend( list* l, char* e ){
  if( l->element == NULL ){ l->element=e; l->next=NULL; return; }
  if( l->next == NULL ){
    l->next=malloc( sizeof(list) );
    l->next->element = NULL;
    l->next->prev = l;
    l->next->next = NULL;
  }
  listAppend( l->next, e );
}
示例#4
0
int main() {
	Node head1 = nodeCreate(3);
	Node head2 = nodeCreate(3);

	int array1[] = {8,7,8,9,2};
	for(int i = 0; i < 2; i++) {
		head1 = listAppend(head1, array1[i]);
	}
	int array2[] = {4,5,3};
	for(int i = 0; i < 2; i++) {
		head2 = listAppend(head2, array2[i]);
	}

	printf("1.1 list 1 and the linked list is now:\n");

	Node item = head1;
	while(item->next != NULL) {
		printf("%d ", item->num);
		item = item->next;
	}
	printf("%d\n\n\n\n", item->num);

	printf("1.2 list 2 and the linked list is now:\n");

	item = head2;
	while(item->next != NULL) {
		printf("%d ", item->num);
		item = item->next;
	}
	printf("%d\n\n\n\n", item->num);

	Node head = addTwoLists(head1, head2);

	item = head;
	while(item->next != NULL) {
		printf("%d ", item->num);
		item = item->next;
	}
	printf("%d\n\n\n\n", item->num);

	return 0;
}
示例#5
0
文件: builtin.c 项目: o-/Rexperiments
/* This is a primitive SPECIALSXP */
SEXP attribute_hidden do_onexit(SEXP call, SEXP op, SEXP args, SEXP rho)
{
    RCNTXT *ctxt;
    SEXP code, oldcode, tmp, argList;
    int addit = 0;
    static SEXP do_onexit_formals = NULL;

    if (do_onexit_formals == NULL)
        do_onexit_formals = allocFormalsList2(install("expr"), install("add"));

    PROTECT(argList =  matchArgs(do_onexit_formals, args, call));
    if (CAR(argList) == R_MissingArg) code = R_NilValue;
    else code = CAR(argList);
    if (CADR(argList) != R_MissingArg) {
	addit = asLogical(eval(CADR(args), rho));
	if (addit == NA_INTEGER)
	    errorcall(call, _("invalid '%s' argument"), "add");
    }

    ctxt = R_GlobalContext;
    /* Search for the context to which the on.exit action is to be
       attached. Lexical scoping is implemented by searching for the
       first closure call context with an environment matching the
       expression evaluation environment. */
    while (ctxt != R_ToplevelContext &&
	   !((ctxt->callflag & CTXT_FUNCTION) && ctxt->cloenv == rho) )
	ctxt = ctxt->nextcontext;
    if (ctxt->callflag & CTXT_FUNCTION)
    {
	if (addit && (oldcode = ctxt->conexit) != R_NilValue ) {
	    if ( CAR(oldcode) != R_BraceSymbol )
	    {
		PROTECT(tmp = allocList(3));
		SETCAR(tmp, R_BraceSymbol);
		SETCADR(tmp, oldcode);
		SETCADDR(tmp, code);
		SET_TYPEOF(tmp, LANGSXP);
		ctxt->conexit = tmp;
		UNPROTECT(1);
	    }
	    else
	    {
		PROTECT(tmp = allocList(1));
		SETCAR(tmp, code);
		ctxt->conexit = listAppend(duplicate(oldcode),tmp);
		UNPROTECT(1);
	    }
	}
	else
	    ctxt->conexit = code;
    }
    UNPROTECT(1);
    return R_NilValue;
}
示例#6
0
static int DecodeBlockette(UINT8 *start, UINT32 seqno, LNKLST *list, BOOL *error)
{
int len;
QDP_DT_BLOCKETTE blk;

    *error = FALSE;

    blk.seqno   = seqno;
    blk.channel = start[0];
    blk.ident = BlocketteIdent(blk.channel);
    blk.resid = BlocketteResid(blk.channel);
    blk.is_status = IsStatusBlockette(blk.channel);
    if ((blk.format = BlocketteFormat(blk.ident)) == QDP_BT_UNKNOWN) {
        *error = TRUE;
        errno = EINVAL;
        return 0;
    }

    blk.root = blk.channel;
    switch (blk.format) {
      case QDP_BT_38:
        len = Decode_BT_38(start, &blk, &blk.data.bt_38, error); break;
      case QDP_BT_816:
        len = Decode_BT_816(start, &blk, &blk.data.bt_816, error); break;
      case QDP_BT_316:
        len = Decode_BT_316(start, &blk, &blk.data.bt_316, error); break;
      case QDP_BT_32:
        len = Decode_BT_32(start, &blk, &blk.data.bt_32, error); break;
      case QDP_BT_232:
        len = Decode_BT_232(start, &blk, &blk.data.bt_232, error); break;
      case QDP_BT_COMP:
        blk.root = blk.channel & 0xe7;
        len = Decode_BT_COMP(start, &blk, &blk.data.bt_comp, error); break;
      case QDP_BT_MULT:
        blk.root = blk.channel & 0xe7;
        len = Decode_BT_MULT(start, &blk, &blk.data.bt_mult, error); break;
      case QDP_BT_SPEC:
        blk.root = 0;
        len = Decode_BT_SPEC(start, &blk, &blk.data.bt_spec, error); break;
      default:
        errno = EINVAL;
        *error = TRUE;
        break;
    }
    if (*error) return 0;

    if (!listAppend(list, &blk, sizeof(QDP_DT_BLOCKETTE))) {
        *error = TRUE;
        return 0;
    }

    return len;
}
示例#7
0
文件: list.c 项目: LCAD-UFES/MAE
int main (int argc, char **argv)
{
   LIST *list = NULL;
   char info[3]= "Oi\0";
   NO *aux;
 
   list = listCreate();
   listAppend (list, (void *) info);
   listAppend (list, (void *) info);
   listAppend (list, (void *) info);
   listAppend (list, (void *) info);
 
    for (aux = list->head; aux != NULL; aux = aux->next)
        printf("%s\n", aux->info);    
 
    listEmpty (list);
    
    for (aux = list->head; aux != NULL; aux = aux->next)
        printf("%s\n", aux->info);    
  
  return (0);  
}
示例#8
0
文件: bogo.c 项目: hainp/bogo-c
void processChar(struct List *rules, struct List *transList, bgstr chr) {
    struct List *applicable_rules = listNew();

    // Build a list of applicable rules whose key matches chr
    struct ListItem *iter = rules->first;
    while (iter != NULL) {
        struct RuleT *rule = (struct RuleT *) iter->item;
        if (bgstrEqual(rule->key, chr)) {
            listAppend(applicable_rules, rule);
        }
        iter = iter->next;
    }

    struct TransT *newTrans = new(struct TransT);

    // A transformation is by default an appending one
    newTrans->rule = new(struct RuleT);
    memcpy(newTrans->rule, &APPEND_RULE, sizeof(struct RuleT));
    bgstrAssign(newTrans->rule->key, chr);

    if (applicable_rules->length != 0) {
        struct ListItem *ruleIter = rules->first;
        while (ruleIter != NULL) {
            struct RuleT *rule = (struct RuleT *) ruleIter->item;

            if (rule->type == TRANS_MARK) {
                findMarkTarget(transList, newTrans, rule);
            } else {
                // Must be tonal then
//                findToneTarget(transList, newTrans, rule);
            }

            ruleIter = ruleIter->next;
        }
    }

    listAppend(transList, newTrans);
    freeList(applicable_rules);
}
示例#9
0
void
queuePush(Queue *queue,
        void *data) {

    TracePrintf(4, "queuePush: data is at %p\n", data);

    queue->tail = listAppend(queue->tail, data);
    if (queue->tail->next)
        queue->tail = queue->tail->next;
    else
        queue->head = queue->tail;
    queue->length++;
}
示例#10
0
int qdplusReadStateFile(QDPLUS *handle)
{
FILE *fp;
int status;
UINT16 flag;
UINT64 serialno;
LNKLST_NODE *crnt;
QDPLUS_STATE state;
QDPLUS_DIGITIZER *digitizer;

    status = QDPLUS_STATE_BUG;
    if ((fp = OpenStateFile(handle, "rb", &status)) == NULL) return status;

    if (fread(&flag, sizeof(UINT16), 1, fp) != 1) {
        status = feof(fp) ? QDPLUS_STATE_EMPTY : QDPLUS_STATE_IOERR;
        fclose(fp);
        return status;
    }

    if (flag != QDPLUS_FLAG_CLEAN) {
        fclose(fp);
        return QDPLUS_STATE_DIRTY;
    }

    while (fread(&serialno, sizeof(UINT64), 1, fp) == 1) {
        if ((digitizer = qdplusGetDigitizer(handle, serialno)) == NULL) {
            fclose(fp);
            return QDPLUS_STATE_BUG;
        }
        if (digitizer->state != NULL) listDestroy(digitizer->state);
        if ((digitizer->state = listCreate()) == NULL) {
            fclose(fp);
            return QDPLUS_STATE_NOMEM;
        }
        while ((status = ReadState(fp, &state)) == STATE_READ_OK) {
            if (!listAppend(digitizer->state, &state, sizeof(QDPLUS_STATE))) {
                fclose(fp);
                return QDPLUS_STATE_NOMEM;
            }
        }
        if (status != STATE_READ_FINISHED) {
            fclose(fp);
            return QDPLUS_STATE_IOERR;
        }
    }

    status = feof(fp) ? QDPLUS_STATE_OK : QDPLUS_STATE_IOERR;
    fclose(fp);

    return status;
}
示例#11
0
ISI_DL_MASTER *isidlOpenDiskLoopSet(LNKLST *sitelist, ISI_GLOB *glob, LOGIO *lp, int perm)
{
int i;
char *site;
ISI_DL *dl;
ISI_DL_MASTER *master = NULL;
static char *fid = "isidlOpenDiskLoopSet";

    if (glob == NULL) {
        logioMsg(lp, LOG_ERR, "%s: NULL input(s)", fid);
        errno = EINVAL;
        return NULL;
    }

    if (sitelist == NULL) sitelist = isidbSystemList(glob->db);

    if ((master = (ISI_DL_MASTER *) malloc(sizeof(ISI_DL_MASTER))) == NULL) {
        logioMsg(lp, LOG_ERR, "%s: malloc: %s", fid, strerror(errno));
        return NULL;
    }

    listInit(&master->list);
    master->glob = glob;
    master->lp   = lp;
    master->dl   = NULL;
    master->ndl  = 0;

    for (i=0; i < (int) sitelist->count; i++) {
        site = (char *) sitelist->array[i];
        if ((dl = isidlOpenDiskLoop(master->glob, site, lp, perm)) == NULL) {
            logioMsg(lp, LOG_ERR, "%s: WARNING: failed to open '%s` disk loop", fid, site);
        } else if (!listAppend(&master->list, dl, sizeof(ISI_DL))) {
            logioMsg(lp, LOG_ERR, "%s: listAppend: %s", fid, strerror(errno));
            return FailedOpen(dl, master);
        } else {
            free(dl);
            dl = NULL;
        }
    }

    if (!listSetArrayView(&master->list)) {
        logioMsg(lp, LOG_ERR, "%s: listSetArrayView: %s", fid, strerror(errno));
        return FailedOpen(NULL, master);
    }

    master->dl = (ISI_DL **) master->list.array;
    master->ndl = master->list.count;

    return master;
}
示例#12
0
static void putMessagetoList(char *msg)
    {
    if(messageList==NULL) 
        {
        messageList=malloc(sizeof(LNKLST));
        if(messageList==NULL)
            {
/*    log error           */
            exit(1);
            }
        listInit(messageList);
        }
    listAppend(messageList, msg, strlen(msg)+1);

    }
示例#13
0
static BOOL AddAddr(LNKLST *list, char **token, int ntoken)
{
Q330_ADDR addr;

    if (ntoken != 4) {
        errno = EINVAL;
        return FALSE;
    }
    strlcpy(addr.name, token[1], MAXPATHLEN+1);
    addr.serialno = (UINT64) strtoll(token[2], NULL, 16);
    addr.authcode = (UINT64) strtoll(token[3], NULL, 16);
    if (!listAppend(list, &addr, sizeof(Q330_ADDR))) return FALSE;
    
    return TRUE;
}
示例#14
0
int main (int argc, char **argv)
{
int i;
char *dbspec = NULL;
LNKLST sitelist, *list = NULL;
ISI_GLOB glob;
BOOL verbose = FALSE;
ISI_DL_MASTER *master;

    listInit(&sitelist);
    for (i = 1; i < argc; i++) {
        if (strncmp(argv[i], "db=", strlen("db=")) == 0) {
            dbspec = argv[i] + strlen("db=");
        } else if (strcasecmp(argv[i], "-v") == 0) {
            verbose = TRUE;
        } else {
            list = &sitelist;
            if (!listAppend(list, argv[i], strlen(argv[i])+1)) {
                perror("listAppend");
                exit(1);
            }
        }
    }
    if (list != NULL && !listSetArrayView(list)) {
        perror("listSetArrayView");
        exit(1);
    }

    if (!isidlSetGlobalParameters(dbspec, argv[0], &glob)) {
        fprintf(stderr, "%s: isidlSetGlobalParameters: %s\n", argv[0], strerror(errno));
        exit(1);
    }

    if ((master = isidlOpenDiskLoopSet(list, &glob, NULL, ISI_RDONLY)) == NULL) {
        fprintf(stderr, "unable to open disk loop(s)\n");
        exit(1);
    }

    for (i = 0; i < master->ndl; i++) {
        if (i) printf("\n");
        if (master->dl[i]->flags & ISI_DL_FLAGS_HAVE_META) {
            process(master->dl[i], verbose);
        } else {
            printf("No '%s' metadata\n", master->dl[i]->sys->site);
        }
    }
    exit(0);
}
示例#15
0
struct List *parseTrioFile(char *trioFile) {
    FILE *fileHandle = fopen(trioFile, "r");
    int bytesRead;
    int nBytes = 100;
    char *cA;
    int j;

    char *species[3];

    struct List *speciesList = NULL;
    speciesList = constructEmptyList(0, freeTrioNames);

    cA = st_malloc(nBytes + 1);
    bytesRead = benLine(&cA, &nBytes, fileHandle);

    while(bytesRead != -1) {
        if (bytesRead > 0) {
            species[0] = st_malloc(sizeof(char) * (1 + (bytesRead)));
            species[1] = st_malloc(sizeof(char) * (1 + (bytesRead)));
            species[2] = st_malloc(sizeof(char) * (1 + (bytesRead)));
            j = sscanf(cA, "%s\t%s\t%s", species[0], species[1], species[2]);
            if (j != 3) {
                fprintf(stderr, "Invalid triple line '%s' in '%s'\n", cA, trioFile);
                exit(1);
            }

            cStr_lowerCase(species[0]);
            cStr_lowerCase(species[1]);
            cStr_lowerCase(species[2]);
            qsort(species, 3, sizeof(char *), cStr_compare);

            TrioNames *trio = st_malloc(sizeof(TrioNames));
            trio->speciesA = species[0];
            trio->speciesB = species[1];
            trio->speciesC = species[2];
            
            listAppend(speciesList, trio);
        }
        bytesRead = benLine(&cA, &nBytes, fileHandle);
    }
    fclose(fileHandle);

    free(cA);

    return speciesList;
}
示例#16
0
Event *event_construct2(Name name, const char *header, float branchLength, Event *parentEvent,
        Event *childEvent, EventTree *eventTree) {
    Event *event;
    event = event_construct(name, header, branchLength, parentEvent, eventTree);
#ifndef NDEBUG
    assert(parentEvent != NULL);
    assert(childEvent != NULL);
    assert(listContains(parentEvent->children, childEvent));
#endif
    listRemove(parentEvent->children, childEvent);
    listAppend(event->children, childEvent);
    childEvent->parent = event;
    childEvent->branchLength = childEvent->branchLength - event->branchLength;
    if (childEvent->branchLength < 0.0) {
        childEvent->branchLength = 0.0;
    }
    return event;
}
示例#17
0
Event *event_construct(Name name, const char *header, float branchLength, Event *parentEvent,
        EventTree *eventTree) {
    assert(eventTree_getEvent(eventTree, name) == NULL); //the event must not already exist in the tree.
    Event *event;
    event = st_malloc(sizeof(Event));
    event->name = name;
    event->parent = parentEvent;
    event->children = constructEmptyList(0, NULL);
    event->header = stString_copy(header == NULL ? "" : header);
    event->branchLength = branchLength < 0.0 ? 0.0 : branchLength;
    event->isOutgroup = 0;
    if (parentEvent != NULL) {
        listAppend(parentEvent->children, event);
    }
    event->eventTree = eventTree;
    eventTree_addEvent(eventTree, event);
    return event;
}
示例#18
0
void event_destruct(Event *event) {
    int64_t i;
    Event *childEvent;
    Event *parentEvent = event_getParent(event);
    if (parentEvent != NULL) {
        listRemove(parentEvent->children, event);
    }
    eventTree_removeEvent(event_getEventTree(event), event);
    for (i = 0; i < event->children->length; i++) {
        childEvent = event->children->list[i];
        childEvent->parent = parentEvent;
        if (parentEvent != NULL) {
            listAppend(parentEvent->children, childEvent);
        }
    }
    destructList(event->children);
    free(event->header);
    free(event);
}
示例#19
0
文件: RCR.c 项目: BigNerd95/Samote
List* setCommandsFile(FILE* fp){

    List* codeList = newList();

    if (fp){
        char str[64];
        int code, lineRes;

        str[63] = '\0';
        do {
            lineRes = fscanf(fp, "%63s %i\n", str, &code);
            if (lineRes == 2){
                listAppend(codeList, str, code);
            }
        } while (lineRes != EOF);
    }

    return codeList;
}
示例#20
0
int main() {
	Node head = nodeCreate(1);
	printf("1. head is %d\n\n\n\n", head->num);

	printf("2. The list and the linked list is now:\n");
	int array[] = {10, 3, 10, 7, 2, 11, 5, 9, 11, 6, 0, 6, 11, 6};

	for(int i = 0; i < 9; i++) {
		head = listAppend(head, array[i]);
	}

	Node item = head;
	while(item->next != NULL) {
		printf("%d ", item->num);
		item = item->next;
	}
	printf("%d\n\n\n\n", item->num);

	printf("3. Now we are testing the nodDel() function.\n");
	Node target = listSearch(head, 1);
	head = nodeDel(head, target);

	printf("4.\n");

	// printf("3. Now we are testing the delDups() function.\n");
	// head = delDups(head);
	item = head;
	if(head == NULL)
	{
		printf("The list is empty");
	}
	else
	{
		while(item->next != NULL) {
			printf("%d ", item->num);
			item = item->next;
		}
		printf("%d\n\n\n\n", item->num);		
	}

	return 0;
}
示例#21
0
/*
 * DeclareElement - see genx.h for details
 */
genxElement genxDeclareElement(genxWriter w,
			       genxNamespace ns, constUtf8 type, 
			       genxStatus * statusP)
{
  genxElement old;
  genxElement el;

  if ((w->status = checkNCName(w, type)) != GENX_SUCCESS)
  {
    *statusP = w->status;
    return NULL;
  }

  /* already declared? */
  old = findElement(&w->elements, (ns == NULL) ? NULL : ns->name, type);
  if (old)
    return old;

  if ((el = (genxElement) allocate(w, sizeof(struct genxElement_rec))) == NULL)
  {
    w->status = *statusP = GENX_ALLOC_FAILED;
    return NULL;
  }

  el->writer = w;
  el->ns = ns;
  if ((el->type = copy(w, type)) == NULL)
  {
    w->status = *statusP = GENX_ALLOC_FAILED;
    return NULL;
  }

  if ((w->status = listAppend(&w->elements, el)) != GENX_SUCCESS)
  {
    *statusP = w->status;
    return NULL;
  }
  
  *statusP = GENX_SUCCESS;
  return el;
}
示例#22
0
static Something systemArgs(Thread *thread) {
    stackPush(NOTHINGNESS, 1, 0, thread);
    
    Object *listObject = newObject(CL_LIST);
    stackSetVariable(0, somethingObject(listObject), thread);
    
    List *newList = listObject->value;
    newList->capacity = cliArgumentCount;
    Object *items = newArray(sizeof(Something) * cliArgumentCount);
    
    listObject = stackGetVariable(0, thread).object;
    
    ((List *)listObject->value)->items = items;
    
    for (int i = 0; i < cliArgumentCount; i++) {
        listAppend(listObject, somethingObject(stringFromChar(cliArguments[i])), thread);
    }
    
    stackPop(thread);
    return somethingObject(listObject);
}
示例#23
0
int main() {
    Node head = nodeCreate(1);
    printf("1. head is %d\n\n\n\n", head->num);

    printf("2. The list and the linked list is now:\n");
    int array[] = {4, 3, 2, 7, 2, 6, 5, 9, 5, 6, 0, 6, 11, 6};

    for(int i = 0; i < 14; i++) {
        head = listAppend(head, array[i]);
    }

    Node item = head;
    while(item->next != NULL) {
        printf("%d ", item->num);
        item = item->next;
    }
    printf("%d\n\n\n\n", item->num);

    printf("3. Now we are testing listSort() function.\n");
    Node sorted;
    sorted = listSort(head);
    printf("The list after sorting is:");
    item = sorted;
    while(item->next != NULL) {
        printf("%d ", item->num);
        item = item->next;
    }
    printf("%d\n\n\n\n", item->num);

    printf("4. Now we are testing deleting the duplicated element.\n");
    Node headFin = removeDup(sorted);
    item = headFin;
    while(item->next != NULL) {
        printf("%d ", item->num);
        item = item->next;
    }
    printf("%d\n", item->num);

    return 0;
}
BufferedStream  *utilOpenBufferedStream(char *pFileName)
	{
	int nLen;
	BufferedStream  *p;
	BufferedStream  obf;

	UINT32 count = 0;
	LNKLST_NODE *crnt;

    crnt = listFirstNode(&list);
    while (crnt != NULL) 
		{
		p = (BufferedStream  *)crnt->payload;
		if(strcmp(p->cFileName, pFileName)==0)
			{
			return p;
			}
        crnt = listNextNode(crnt);
		}
	
	nLen = strlen(pFileName);
	if(nLen<sizeof(obf.cFileName)-1)
		STRCPY(obf.cFileName, pFileName);
	else
		{
		strncpy(obf.cFileName, pFileName, sizeof(obf.cFileName)-1);
		obf.cFileName[sizeof(obf.cFileName)-1]=0;
		}

	obf.nBytes=0;
	obf.nTotalBytes=0;

	if(listAppend(&list, &obf, sizeof(obf)))
		{
		crnt = listLastNode(&list);
		p = (BufferedStream  *)crnt->payload;
		return p;
		}
	return NULL;
	}
示例#25
0
int main() {
	Node head = nodeCreate(1);
	printf("1. head is %d\n\n\n\n", head->num);

	printf("2. The list and the linked list is now:\n");
	int array[] = {10, 3, 10, 7, 2, 9, 5, 9, 11, 6, 0, 6, 11, 6};

	for(int i = 0; i < 9; i++) {
		head = listAppend(head, array[i]);
	}

	Node item = head;
	while(item->next != NULL) {
		printf("%d ", item->num);
		item = item->next;
	}
	printf("%d\n\n\n\n", item->num);

	Node target = listSearch(head, 11);

	_Bool isDel = NodeDelWithNoReturnValue(target);
	if(isDel == true) 
	{
		item = head;
		while(item->next != NULL) {
			printf("%d ", item->num);
			item = item->next;
		}
		printf("%d\n\n\n\n", item->num);		
	}
	else
	{
		printf("can not delete\n");
	}

	return 0;
}
示例#26
0
List * parseValueList(Collector * c, Tokenizer * tt) {
	List * args = newList(c); if (!args) goto fail;

	TokenType t = tokenizerNext(tt);
	if (t != TOK_LPAREN) goto fail;

	char * sp = tt->bp;
	t = tokenizerNext(tt);
	if (t == TOK_RPAREN) return args;

	tokenizerSet(tt, sp);
	do {
		Object * arg = parseValue(c, tt); if (!arg) goto fail;
		if (!listAppend(args, arg)) goto fail;
		t = tokenizerNext(tt);

		if (t == TOK_RPAREN) {
			return args;
		}
	} while (t == TOK_COMMA);

fail:
	return NULL;
}
示例#27
0
static stream_t *getStream(int nstream)
    {
    stream_t stt, *pstt;

    LNKLST_NODE *node; 
    node = listFirstNode(streamList);

    while (node != NULL) 
        {
        pstt = node->payload;
        if(pstt->nstream==nstream) break;
        node = listNextNode(node);
        }

    if(node==NULL)
        {
        stt.t       = 0.;
        stt.nstream = nstream;
        listAppend(streamList, &stt, sizeof(stt)); 
        node = listLastNode(streamList);
        }

    return (stream_t *)node->payload;
    }
示例#28
0
MenuListDRC::MenuListDRC(s32 w, s32 h,MainWindowContent * _contentWindow)
    : GuiFrame(w, h)
    , contentWindow(_contentWindow)
    , width(w)
    , height(h)
    , bgImageColor(w, h, (GX2Color){ 0, 0, 0, 0 })
    , homeSeperator(gettext("Home"))
    , elementHome(gettext("Home"), "homeIcon.png", ContentTemplate::CONTENT_HOME)
    , controllerSeperator("Controller")
    , elementGamePad(UController_Type_Gamepad)
    , elementProController1(UController_Type_Pro1)
    , elementProController2(UController_Type_Pro2)
    , elementProController3(UController_Type_Pro3)
    , elementProController4(UController_Type_Pro4)
    , otherSeperator(gettext("Other"))
    , elementHelp(gettext("Help"),     "helpIcon.png", ContentTemplate::CONTENT_HELP)
    , elementNetworkHelp(  gettext("Network Client"),     "netbtn.png", ContentTemplate::CONTENT_NETWORK_HELP)
    , elementSettings(  gettext("Settings"),     "settingsbtn.png", ContentTemplate::CONTENT_SETTINGS)
    , elementAbout(gettext("About"),    "aboutIcon.png", ContentTemplate::CONTENT_ABOUT)
    , buttonUpTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_UP | GuiTrigger::STICK_L_UP, true)
    , buttonDownTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_DOWN | GuiTrigger::STICK_L_DOWN, true)
    , touchTrigger(GuiTrigger::CHANNEL_1, GuiTrigger::VPAD_TOUCH)
    , DPADButtons(0,0)
    , VPADDrag(w,h)
    , wpadTouchTrigger(GuiTrigger::CHANNEL_2 | GuiTrigger::CHANNEL_3 | GuiTrigger::CHANNEL_4 | GuiTrigger::CHANNEL_5, GuiTrigger::BUTTON_A)
{
    bgImageColor.setImageColor((GX2Color){  255, 255, 255, 255 }, 0);
    bgImageColor.setImageColor((GX2Color){  255, 255, 255, 255 }, 1);
    bgImageColor.setImageColor((GX2Color){  255, 255, 255, 255 }, 2);
    bgImageColor.setImageColor((GX2Color){  255, 255, 255, 255 }, 3);

    append(&bgImageColor);

    listAppend(&homeSeperator);
    listAppend(&elementHome);
    listAppend(&controllerSeperator);
    listAppend(&elementGamePad);
    listAppend(&elementProController1);
    listAppend(&elementProController2);
    listAppend(&elementProController3);
    listAppend(&elementProController4);
    listAppend(&otherSeperator);
    listAppend(&elementNetworkHelp);
    listAppend(&elementHelp);
    listAppend(&elementSettings);
    listAppend(&elementAbout);

    sizeListElementsAll = listElementsAll.size();
    sizeListElementsButtons = listElementsButtons.size();

    DPADButtons.setTrigger(&buttonDownTrigger);
    DPADButtons.setTrigger(&buttonUpTrigger);
    DPADButtons.clicked.connect(this, &MenuListDRC::OnDPADClick);

    VPADDrag.setTrigger(&touchTrigger);
    VPADDrag.setTrigger(&wpadTouchTrigger);
    VPADDrag.dragged.connect(this, &MenuListDRC::OnDrag);

    append(&VPADDrag);
    append(&DPADButtons);
    scroll_needs_update = true;
    dpad_selection_changed = true;
}
示例#29
0
int main(int argc, char *argv[])
{
    List list;
    Data *data[6];

    int i, errors = 0;

    for (i = 0; i < 6; i++) {
        data[i] = calloc(1, sizeof(Data));
    }

    listInitialize(&list);

    TEST_INT(listLength(&list), 0);
    TEST_INT(listIsEmpty(&list),  TRUE);

    listAppendTail(&list, data[0]);
    listAppendTail(&list, data[1]);
    listAppendTail(&list, data[2]);
    listAppendTail(&list, data[3]);

    TEST_INT(listLength(&list), 4);
    TEST_INT(listIsEmpty(&list),  FALSE);

    TEST_PTR(listHead(&list), data[0]);
    TEST_PTR(listTail(&list), data[3]);

    TEST_PTR(listNext(data[0]), data[1]);
    TEST_PTR(listNext(data[1]), data[2]);
    TEST_PTR(listNext(data[2]), data[3]);
    TEST_PTR(listNext(data[3]), NULL);

    TEST_PTR(listPrev(data[3]), data[2]);
    TEST_PTR(listPrev(data[2]), data[1]);
    TEST_PTR(listPrev(data[1]), data[0]);
    TEST_PTR(listPrev(data[0]), NULL);

    TEST_PTR(listContaining(data[0]), &list);
    TEST_PTR(listContaining(data[1]), &list);
    TEST_PTR(listContaining(data[2]), &list);
    TEST_PTR(listContaining(data[3]), &list);

    listRemove(&list, data[0]);
    listRemove(&list, data[1]);
    listRemove(&list, data[2]);
    listRemove(&list, data[3]);

    TEST_INT(listLength(&list), 0);
    TEST_INT(listIsEmpty(&list),  TRUE);

    TEST_PTR(listContaining(data[0]), NULL);
    TEST_PTR(listContaining(data[1]), NULL);
    TEST_PTR(listContaining(data[2]), NULL);
    TEST_PTR(listContaining(data[3]), NULL);

    listInsertHead(&list, data[3]);
    listInsertHead(&list, data[2]);
    listInsertHead(&list, data[1]);
    listInsertHead(&list, data[0]);

    TEST_INT(listLength(&list), 4);
    TEST_INT(listIsEmpty(&list),  FALSE);

    TEST_PTR(listHead(&list), data[0]);
    TEST_PTR(listTail(&list), data[3]);

    TEST_PTR(listNext(data[0]), data[1]);
    TEST_PTR(listNext(data[1]), data[2]);
    TEST_PTR(listNext(data[2]), data[3]);
    TEST_PTR(listNext(data[3]), NULL);

    TEST_PTR(listPrev(data[3]), data[2]);
    TEST_PTR(listPrev(data[2]), data[1]);
    TEST_PTR(listPrev(data[1]), data[0]);
    TEST_PTR(listPrev(data[0]), NULL);

    TEST_PTR(listRemoveHead(&list), data[0]);
    TEST_PTR(listRemoveHead(&list), data[1]);
    TEST_PTR(listRemoveTail(&list), data[3]);
    TEST_PTR(listRemoveTail(&list), data[2]);

    TEST_INT(listLength(&list), 0);
    TEST_INT(listIsEmpty(&list),  TRUE);

    listAppendTail(&list, data[0]);
    listAppendTail(&list, data[3]);
    listAppend(&list, data[1], data[0]);
    listInsert(&list, data[2], data[3]);

    TEST_PTR(listRemoveHead(&list), data[0]);
    TEST_PTR(listRemoveHead(&list), data[1]);
    TEST_PTR(listRemoveTail(&list), data[3]);
    TEST_PTR(listRemoveTail(&list), data[2]);

    data[0]->i = 3;
    data[1]->i = 4;
    data[2]->i = 5;
    data[3]->i = 1;
    data[4]->i = 2;
    data[5]->i = 3;

    listAppendTail(&list, data[0]);
    listAppendTail(&list, data[1]);
    listAppendTail(&list, data[2]);
    listAppendTail(&list, data[3]);
    listAppendTail(&list, data[4]);
    listAppendTail(&list, data[5]);

    listSort(&list, cmp);

    TEST_PTR(listRemoveHead(&list), data[3]);
    TEST_PTR(listRemoveHead(&list), data[4]);
    TEST_PTR(listRemoveHead(&list), data[0]);
    TEST_PTR(listRemoveHead(&list), data[5]);
    TEST_PTR(listRemoveHead(&list), data[1]);
    TEST_PTR(listRemoveHead(&list), data[2]);

    exit(errors);
}
示例#30
0
/** Open all required output files
	
	Note: for LLgen output an output file is created for each input file. 
	Further, two files, <prefix>pars.h and <prefix>pars.c, are created.
*/
static void openOutputs(void) {
	const char *cExtension = "c", *hExtension = "h";
	FileListItem *currentItem;
	const char *inputName, *prefixText;
	char *outputName;
	size_t lenPrefix;
	int i;

	if (option.extensions) {
		char *extension = listIndex(option.extensions, 0);
		if (extension != NULL)
			cExtension = extension;
		if (listSize(option.extensions) > 1 && (extension = listIndex(option.extensions, 1)) != NULL)
			hExtension = extension;
	}
	
	outputs = newList();
	
	if (listSize(option.inputFileList) == 0) {
		ASSERT(option.outputBaseName != NULL);
		currentItem = (FileListItem *) safeMalloc(sizeof(FileListItem), "openOutputs");
		/* Note that for LLgen style outputs the use of include files is
		   prohibited, so fileName still points to the string "<stdin>". */
		currentItem->sourceFileName = fileName;
		currentItem->firstNonTerminal = true;
		outputName = createNameWithExtension(option.outputBaseName, cExtension);
		currentItem->output = checkAndOpenFile(outputName, true);
		listAppend(outputs, currentItem);
	} else {
		/* Open the different output files */
		for (i = 0; i < listSize(option.inputFileList); i++) {
			inputName = (const char *) listIndex(option.inputFileList, i);
			
			currentItem = (FileListItem *) safeMalloc(sizeof(FileListItem), "openOutputs");
			currentItem->sourceFileName = inputName;
			/* Set the flag that indicates that we haven't yet generated a
			   NonTerminal */
			currentItem->firstNonTerminal = true;
			
			/* For LLgen style outputs we never keep the directory, as multiple 
			   directories may be present for different files. */
			inputName = baseName(inputName);
			outputName = createNameWithExtension(inputName, cExtension);
			for (i = 0; i < listSize(outputs); i++) {
				FileListItem *itemToCheck = (FileListItem *) listIndex(outputs, i);
				if (strcmp(outputName, itemToCheck->output->name) == 0)
					fatal("Input files %s and %s map to the same output name.\n", itemToCheck->output->name, outputName);
			}
			currentItem->output = checkAndOpenFile(outputName, true);
			listAppend(outputs, currentItem);
		}
	}
	
	/* Open Lpars.h and Lpars.c, or appropriatly prefixed version of them */
	if (prefixDirective == NULL) {
		prefixText = "L";
		lenPrefix = 1;
	} else {
		prefixText = prefixDirective->token[0]->text;
		lenPrefix = strlen(prefixText);
	}

	outputName = (char *) safeMalloc(strlen(prefixText) + 6 + strlen(hExtension), "openOutputs");
	sprintf(outputName, "%spars.%s", prefixText, hExtension);
	hOutput = checkAndOpenFile(outputName, false);
	outputName = (char *) safeMalloc(strlen(prefixText) + 6 + strlen(cExtension), "openOutputs");
	sprintf(outputName, "%spars.%s", prefixText, cExtension);
	cOutput = checkAndOpenFile(outputName, true);
}