Пример #1
0
int main(void) {
    LinkedList List;
    u16 * ship = NULL;
    GBA_STATE state = GBA_STARTING;
    int i;
    int sze = 3;
    int time = 0;
    int rate = 10;
    int tlRow = 1;
    int tlCol = 2;
    int H = 21;
    int W = 32;
    int row = 80 - H;
    int col = 240 - W;
    LLNode * here;
    ship = (u16 *) malloc(H * W);
    fillPatch(ship,(u16 *) ShipBitmap, tlRow, tlCol, H, W);
    for(i = 0; i < 4; i++) colorIndex[i] = findbestColor(COLOR(12 + 4*i, 0, 0), StarrySkyPal);
    load_palette((u16 *) StarrySkyPal);
    List = emptyList();
    setup();
    while (1) {
        waitForScan();
        flipPage();
        switch (state) {
            case GBA_STARTING:
                copy_full_screen((u16 *) Start_ScreenBitmap);
                if (check_key(BUTTON_NDX_START) == KEY_RELEASED) {
                    state = GBA_RUNNING;
                } 
                break;
            case GBA_RUNNING:
                if(KEY_DOWN_NOW(BUTTON_DOWN)&&(row<(SCREEN_HEIGHT - H))) row++;
                if(KEY_DOWN_NOW(BUTTON_UP)&&(row > 0)) row--;
                if(KEY_DOWN_NOW(BUTTON_RIGHT)&&(col < SCREEN_WIDTH - W)) col++;
                if(KEY_DOWN_NOW(BUTTON_LEFT)&&(col>0)) col--;
                if (time % rate == 0) {
                    /*random size for the Astroids*/
                    addAstroid(&List, sze + (rand() % 4));
                }
                time++;
                update(&List);
                copy_full_screen((u16 *) StarrySkyBitmap);
                getPatch(ship, row, col, H, W);
                display(List);
                here = List.head;
                /*Collision Detection*/
                while(here){
                    if((here->data->row > (row - here->data->side)) && 
                       (here->data->row < (row + H)) && (here->data->col == col + 10)){
                        state = GBA_STARTING;
                        break;
                    }
                    here = here->next;
                }
                break;
        }
    }
    delete(&List);
    free(ship);
    return 0;
}
Пример #2
0
void QDropboxJson::parseString(QString strJson)
{
#ifdef QTDROPBOX_DEBUG
    qDebug() << "parse string = " << strJson << endl;
#endif

    // clear all existing data
    emptyList();

    // basically a json is valid until it is invalidated
    valid = true;

    if(!strJson.startsWith("{") ||
            !strJson.endsWith("}"))
    {
#ifdef QTDROPBOX_DEBUG
    qDebug() << "string does not start with { " << endl;
#endif

		if(strJson.startsWith("[") && strJson.endsWith("]"))
		{
#ifdef QTDROPBOX_DEBUG
			qDebug() << "JSON is anonymous array" << endl;
#endif
			_anonymousArray = true;
			// fix json to be parseable by the algorithm below
			strJson = "{\"_anonArray\":"+strJson+"}";
		}
		else
		{
			valid = false;
			return;
		}
    }

    QString buffer   = "";
    QString key      = "";
    QString value    = "";

    bool isKey       = true;
    bool insertValue = false;
    bool isJson      = false;
    bool isArray     = false;
    bool openQuotes  = false;


    for(int i=0; i<strJson.size(); ++i)
    {
        switch(strJson.at(i).toLatin1())
        {
        case '"':
            if(!isKey)
            {
                buffer += "\"";
                openQuotes = !openQuotes;
            }
            continue;
            break;
        case ' ':
            if(!isKey)
                buffer += " ";
            continue;
            break;
        case '}':
	    if(openQuotes)
	      buffer += "}";
            continue;
            break;
        case ':':
            if(!isKey)
            {
                buffer += ":";
                continue;
            }
#ifdef QTDROPBOX_DEBUG
            qDebug() << "key = " << buffer << endl;
#endif

            key    = buffer.trimmed();
            buffer = "";
            isKey  = false;
            break;
        case ',':
            if(openQuotes)
			{
				buffer += ',';
                continue;
			}
#ifdef QTDROPBOX_DEBUG
            qDebug() << "value = " << buffer << endl;
#endif
            value       = buffer.trimmed();
            buffer      = "";
            isKey       = true;
            insertValue = true;
            break;
        case '{':
            if(i == 0)
                continue;
	    if(!openQuotes)
              isJson  = true;
            buffer += '{';
            break;
        case '[':
	    if(!openQuotes)
              isArray = true;
            buffer += '[';
            break;
        default:
            buffer += strJson.at(i);
            break;
        }

        if(isJson)
        {
            // create new json object with data until }
            qdropboxjson_entry e;
			int offset = parseSubJson(strJson, i, &e);
            valueMap[key] = e;
            key = "";

            // ignore next ,
            i = offset+1;
            buffer      = "";
            isJson      = false;
            insertValue = false;
            isKey       = true;
            //continue;
        }

		 if(isArray)
         {
			 // value is an array value -> parse array
			 bool inString    = false;
			 bool arrayEnd    = false;
			 int j = i+1;
			 buffer = "[";
			 for(;!arrayEnd && j<strJson.size();++j)
			 {
				 QChar arrC = strJson.at(j);
				 switch(arrC.toLatin1())
				 {
				 case '"': 
					 inString = !inString;
					 buffer += arrC;
					 break;
				 case ']':
					 buffer += "]";
					 if(!inString)
						 arrayEnd = true;
					 break;
				 case '\\':
					 if(strJson.at(j+1) == '"') // escaped double quote
					 {
						 buffer += "\"";
						 j++;
					 }
					 else
						 buffer += "\\";
					 break;
				 default:
					 buffer += arrC;
					 break;
				 }
			 }
			 
			 // save array value string (buffer)
			 value       = buffer;
			 buffer      = "";
			 i           = j;
			 insertValue = true;
			 isArray     = false;
			 isKey       = true; // next element is started
		 }

        if(insertValue)
        {
#ifdef QTDROPBOX_DEBUG
            qDebug() << "insert value " << key << " with content = " << value.trimmed() << " and type = " << interpretType(value.trimmed()) << endl;
#endif
            qdropboxjson_entry e;
			QString *valuePointer = new QString(value.trimmed());
			e.value.value = valuePointer;
            e.type        = interpretType(value.trimmed());
            valueMap[key] = e;

            key   = "";
            value = "";
            insertValue = false;
        }
    }

    // there's some key left
    if(key.compare(""))
    {
#ifdef QTDROPBOX_DEBUG
            qDebug() << "rest value = " << buffer << endl;
#endif
        // but no value in the buffer -> json is invalid because a value is missing
        if(!buffer.compare(""))
        {
            valid = false;
        }
        else
        {
            // if there's a value left we store it
            qdropboxjson_entry e;
            e.value.value = new QString(buffer.trimmed());
            e.type        = interpretType(buffer.trimmed());
            valueMap[key] = e;
        }

    }

    return;
}
Пример #3
0
CMainWindow::CMainWindow(QWidget *parent) : QMainWindow(parent) {
    setupUi(this);

    pads = emptyList()  << SPad(QString::fromUtf8("Bass Drum 2"), 35, QByteArray("1000000110100000"))
                        << SPad(QString::fromUtf8("Bass Drum 1"), 36, QByteArray("0000000000000000"))
                        << SPad(QString::fromUtf8("Side Stick/Rimshot"), 37, QByteArray("0000000000000000"))
                        << SPad(QString::fromUtf8("Snare Drum 1"), 38, QByteArray("0000000000000000"))
                        << SPad(QString::fromUtf8("Hand Clap"), 39, QByteArray("0000000000000000"))
                        << SPad(QString::fromUtf8("Snare Drum 2"), 40, QByteArray("0000100000001000"))
                        << SPad(QString::fromUtf8("Low Tom 2"), 41, QByteArray("0000000000000000"))
                        << SPad(QString::fromUtf8("Closed Hi-hat"), 42, QByteArray("1010100010101000"))
                        << SPad(QString::fromUtf8("Low Tom 1"), 43, QByteArray("0000000000000000"))
                        << SPad(QString::fromUtf8("Pedal Hi-hat"), 44, QByteArray("0000000000000000"))
                        << SPad(QString::fromUtf8("Mid Tom 2"), 45, QByteArray("0000000000000000"))
                        << SPad(QString::fromUtf8("Open Hi-hat"), 46, QByteArray("0000001000000010"))
                        << SPad(QString::fromUtf8("Mid Tom 1"), 47, QByteArray("0000000000000000"))
                        << SPad(QString::fromUtf8("High Tom 2"), 48, QByteArray("0000000000000000"))
                        << SPad(QString::fromUtf8("Crash Cymbal 1"), 49, QByteArray("0000000000000000"))
                        << SPad(QString::fromUtf8("High Tom 1"), 50, QByteArray("0000000000000000"))
                        << SPad(QString::fromUtf8("Ride Cymbal 1"), 51, QByteArray("0000000000000000"))
                        << SPad(QString::fromUtf8("Splash Cymbal"), 55, QByteArray("0000000000000000"))
                        << SPad(QString::fromUtf8("Crash Cymbal 2"), 57, QByteArray("0000000000000000"))
                        << SPad(QString::fromUtf8("Ride Cymbal 2"), 59, QByteArray("0000000000000000"))
                        ;

    setStyleSheet("QMainWindow { background-color: #efefef; }");

    settings = new QSettings("clebail", "qtdrum");

    spNbBeat->setMinimum(MIN_BEAT);
    spNbBeat->setMaximum(MAX_BEAT);
    spNbDiv->setMinimum(MIN_DIV);
    spNbDiv->setMaximum(MAX_DIV);

    ssTemps->setSegmentColor(QColor(0x93, 0x65, 0xb8));
    taTimer->setSegmentColor(QColor(0x1f, 0xb5, 0xac));

    cbMidiPort->addItems(CDrumKit::getInstance()->getMidiPorts());

    drumWidget->addPads(&pads);

    playing = false;
    timerParams.drumWidget = drumWidget;

    realTimeTimer = new QTimer(this);
    realTimeTimer->setInterval(ONE_SECOND);
    connect(realTimeTimer, SIGNAL(timeout()), this, SLOT(onRealTimeTimer()));

    isOpenFileUnsaved = false;
    setOpenFileName("unamed.qdr", "unamed.qdr");

    CDrumKit::getInstance()->init(cbMidiPort->currentIndex());

    connect(&timerParams, SIGNAL(tempsUpdate(int)), this, SLOT(onTempsUpdate(int)));

    bells = new Phonon::MediaObject(this);
    bellsOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
    Phonon::createPath(bells, bellsOutput);

    qApp->installEventFilter(this);
}
Пример #4
0
SM_Dropbox_Json::~SM_Dropbox_Json()
{
    emptyList();
}
Пример #5
0
/*Tar bort och frigör minne för listan*/
void destroyList(List *myList)
{
	emptyList(myList);
	free(myList);
	myList = NULL;
}
void dijkstra_algorithm(struct Graph *graph ,struct Graph *dijsktra)
{
     int V = graph->V;
     struct Node *UnvistedNodeList =  InitialNode_List(V);
     //struct AdjListNode *CurrentNode = graph->array[0].head;
 
    int currentNodeValue_graph;
    struct Node * VisitedNodeList = NULL;

    VisitedNodeList = Update_VisitedNode_List(VisitedNodeList , 0);
    UnvistedNodeList = Update_UnvistedNode_List(UnvistedNodeList , 0);
  
     //printf("started");
     while(emptyList(UnvistedNodeList))//run till the list becomes empty
     {
        //printf("1st while loop started");
        int nextMinimumNodeWeigh = 9999;
        int nextMinimumNode, currentNodeValue;
        struct AdjListNode* Node  = NULL;

        struct Node * traverse_node = VisitedNodeList;   // for traverersing the visited node to get next minimum Node
        while(emptyList(traverse_node)) 
            {
                //printf("2nd while loop started");
                currentNodeValue = traverse_node->val;

                Node =  graph->array[currentNodeValue].head;
                while(Node)
                {
                    //printf("3rd while loop started");
                    if((nextMinimumNodeWeigh > Node->weigh) && (val_not_present_inList(VisitedNodeList,Node->val)))
                      {
                        currentNodeValue_graph = currentNodeValue;
                        nextMinimumNode = Node->val;
                        nextMinimumNodeWeigh = Node->weigh;
                        }
                    Node = Node->next;
               }
              // printf("1st while loop over");
               traverse_node  = Update_UnvistedNode_List(traverse_node,currentNodeValue);
            }
           // printf("2nd while loop started");
       

          addEdge(dijsktra , currentNodeValue_graph ,nextMinimumNode , nextMinimumNodeWeigh);
            // update the weigh of the node
          struct AdjListNode * updatedWeighList = graph->array[nextMinimumNode].head;
          while(updatedWeighList)
          {
        
            if(val_not_present_inList(VisitedNodeList,updatedWeighList->val))
            {
                updatedWeighList->weigh = updatedWeighList->weigh + nextMinimumNodeWeigh;

                /// the graph is non directive
                struct AdjListNode * updatedWeighList1 = graph->array[updatedWeighList->val].head;
                while(updatedWeighList1)
                {
                    if(updatedWeighList1->val==nextMinimumNode)
                    {
                      updatedWeighList1->weigh = updatedWeighList1->weigh + nextMinimumNodeWeigh;  
                      break;
                    }
                    updatedWeighList1 = updatedWeighList1->next;
                }

            }
            updatedWeighList = updatedWeighList->next;           
          }       

       // printf("4th while loop over");
        VisitedNodeList = Update_VisitedNode_List(VisitedNodeList,nextMinimumNode);   //update visited node list
        UnvistedNodeList = Update_UnvistedNode_List(UnvistedNodeList , nextMinimumNode);

     }

    //printf("1st while loop over");
}
Пример #7
0
QDropboxJson::~QDropboxJson()
{
    emptyList();
}
Пример #8
0
Stack::~Stack() {
    emptyList();
}
Пример #9
0
/* Compute how many nodes there are in the LLS */
int lengthList(typeList lis) {
    if (emptyList(lis))
        return 0;
    else
        return 1 + lengthList(lis->next);
}
Пример #10
0
static void removeVisibleFacetsGetHorizonAndAvailablePoints(
  zhull_t * const zh, index_t point_index,
  facet_t *f,
  list_t *horizon_fcts,
  list_t *horizon_fcts_edges,
  list_t *other_horizon_edges,
  list_t *avail_points)
{

  index_t j,k;
  facet_t *n;
  float d;
  list_t visible_fcts = emptyList();
  list_t fcts_to_visit = emptyList();
  list_t fcts_visited = emptyList();
//    list_t list_for_printing = emptyList();

  *avail_points = emptyList();
  *horizon_fcts = emptyList();
  *horizon_fcts_edges = emptyList();
  *other_horizon_edges = emptyList();

  d=distancePointPlane(getPoint(zh->pts,point_index),f->plane);
//    printf("distance %5.2f\n",d);
  appendToList(&fcts_to_visit,entry_makePointer(f));
  if (d>=TOL_OUTSIDEPOINT) {
    while (getLength(fcts_to_visit)>0) {
      // visiting only visible facets
      // horizon: edges to invisible or coincident neighbors
      f=getFacetByIndex(fcts_to_visit,0);
      appendToList(&visible_fcts,entry_makePointer(f));
      appendListToList(avail_points, f->outsideset);
      for (j=0; j<getLength(f->neighbors); j++) {
        n=getFacetByIndex(f->neighbors,j);
        d=distancePointPlane(getPoint(zh->pts,point_index),n->plane);
        if (d>=TOL_OUTSIDEPOINT) {  // visit visible neighbors
          appendToList(&fcts_to_visit,entry_makePointer(n));
        } else { // horizon: coincident or invisible neighbors
          k=findValueInList(getEntry(f->corners,(j+1)%getLength(f->corners)),
                            n->corners);
          appendToList(horizon_fcts,entry_makePointer(n));
          appendToList(horizon_fcts_edges,entry_makeIndex(k));
          appendToList(other_horizon_edges,entry_makeIndex(getNumPoints(zh->pts)));
        }
      }
      removeValueFromList(&fcts_to_visit,entry_makePointer(f));
      appendToList(&fcts_visited,entry_makePointer(f));
      removeValueListFromList(&fcts_to_visit,fcts_visited);
    }
//        printf("removing facets\n");
//        list_for_printing=findValueListInList(visible_fcts,zh->facets);
//        printList(list_for_printing);
//        freeList(&list_for_printing);
    removeFacetByPointerList(zh,visible_fcts);
    freeList(&visible_fcts);
    freeList(&fcts_to_visit);
    freeList(&fcts_visited);
    sortHorizonEdges(horizon_fcts, horizon_fcts_edges, other_horizon_edges);
    //printHorizonEdges(horizon_fcts,horizon_fcts_edges,other_horizon_edges);
  } else if (d>=TOL_INSIDEPOINT) {
    // all coincident surfaces shall be removed
    // horizon might not be defined by facets
    while (getLength(fcts_to_visit)>0) {
      f=getFacetByIndex(fcts_to_visit,0);
      appendToList(&visible_fcts,entry_makePointer(f));
      appendListToList(avail_points, f->outsideset);
      appendListToList(avail_points, f->insideset);
      for (j=0; j<getLength(f->neighbors); j++) {
        n=getFacetByIndex(f->neighbors,j);
        d=distancePointPlane(getPoint(zh->pts,point_index),n->plane);
        if (d>=TOL_INSIDEPOINT) { // coincident facet
          if (notInList(entry_makePointer(n),visible_fcts)) {
            appendToList(&fcts_to_visit,entry_makePointer(n));
          }
          if ((innerProduct(f->plane.normal,n->plane.normal)<
               -1.0f+TOL_DEGENERATE)&&
              (distancePointLineOnPlane(getPoint(zh->pts,point_index),
                                        getLine(zh,f,j),
                                        f->plane)<TOL_INSIDEPOINT)) {
            // coincident facets with opposite surface orientation
            // yield an edge to keep despite all facets will be removed
            // as soon as edge is invisible to point
            appendToList(horizon_fcts,entry_makePointer(0));
            appendToList(other_horizon_edges,
                         getEntry(f->corners,j));
            appendToList(horizon_fcts_edges,
                         getEntry(f->corners,(j+1)%getLength(f->corners)));
          }
        } else { // invisible facet forms horizon that persists
          k=findValueInList(getEntry(f->corners,(j+1)%getLength(f->corners)),
                            n->corners);

          appendToList(horizon_fcts,entry_makePointer(n));
          appendToList(horizon_fcts_edges,entry_makeIndex(k));
          appendToList(other_horizon_edges,entry_makeIndex(getNumPoints(zh->pts)));
        }
      }
      removeValueFromList(&fcts_to_visit,entry_makePointer(f));
      appendToList(&fcts_visited,entry_makePointer(f));
      removeValueListFromList(&fcts_to_visit,fcts_visited);
    }
//        printf("removing facets\n");
//        list_for_printing=findValueListInList(visible_fcts,zh->facets);
//        printList(list_for_printing);
//        freeList(&list_for_printing);
    removeFacetByPointerList(zh,visible_fcts);
    sortHorizonEdges(horizon_fcts, horizon_fcts_edges,other_horizon_edges);
    //printHorizonEdges(horizon_fcts,horizon_fcts_edges,other_horizon_edges);
    freeList(&visible_fcts);
    freeList(&fcts_to_visit);
    freeList(&fcts_visited);
  }
}
Пример #11
0
int main(int argc, char** argv) {
    int buffSize = 2048;
    char buff[buffSize];
    struct Node *n1;
    if((n1 = initList()) == NULL){
        printf("Not enough memory!\n");
        return -1;
    }
    
    printf("Append A\n");
    appendNode(n1, 0, "A", 1, 12, 12);
    bzero(buff, buffSize);
    BuffAllNodes(n1, buff, buffSize);
    printf("%s\n",buff);
    
    printf("Delete n1\n");
    emptyList(n1);
    bzero(buff, buffSize);
    BuffAllNodes(n1, buff, buffSize);
    printf("%s\n",buff);
    
    printf("Append AA\n");
    appendNode(n1, 0, "AA", 2, 12, 12);
    bzero(buff, buffSize);
    BuffAllNodes(n1, buff, buffSize);
    printf("%s\n",buff);
    
    printf("Append B\n");
    appendNode(n1, 5, "B", 1, 12, 12);
    bzero(buff, buffSize);
    BuffAllNodes(n1, buff, buffSize);
    printf("%s\n",buff);
    
    emptyList(n1);
    bzero(buff, buffSize);
    BuffAllNodes(n1, buff, buffSize);
    printf("%s\n",buff);
    
    printf("Append AAA\n");
    appendNode(n1, 0, "AAA", 3, 12, 12);
    bzero(buff, buffSize);
    BuffAllNodes(n1, buff, buffSize);
    printf("%s\n",buff);
    
    printf("Append BB\n");
    appendNode(n1, 5, "BB", 2, 12, 12);
    bzero(buff, buffSize);
    BuffAllNodes(n1, buff, buffSize);
    printf("%s\n",buff);
    
    printf("Append C\n");
    appendNode(n1, 6, "C", 1, 12, 12);
    bzero(buff, buffSize);
    BuffAllNodes(n1, buff, buffSize);
    printf("%s\n",buff);
    
    emptyList(n1);
    bzero(buff, buffSize);
    BuffAllNodes(n1, buff, buffSize);
    printf("%s\n",buff);
    
    printf("Append KOPHS\n");
    appendNode(n1, 0, "KOPHS", 5, 12, 12);
    bzero(buff, buffSize);
    BuffAllNodes(n1, buff, buffSize);
    printf("%s\n",buff);
    
    printf("Append TESTS\n");
    appendNode(n1, 10, "TESTS", 5, 12, 12);
    bzero(buff, buffSize);
    BuffAllNodes(n1, buff, buffSize);
    printf("%s\n",buff);
    
    printf("Append THESE\n");
    appendNode(n1, 234, "THESE", 15, 12, 12);
    bzero(buff, buffSize);
    BuffAllNodes(n1, buff, buffSize);
    printf("%s\n",buff);
    
    deleteNode(n1, "THESE");
    bzero(buff, buffSize);
    BuffAllNodes(n1, buff, buffSize);
    printf("%s\n",buff);
    
    deleteNode(n1, "KOPHSS");
    bzero(buff, buffSize);
    BuffAllNodes(n1, buff, buffSize);
    printf("%s\n",buff);
    
    deleteNode(n1, "KOPHS");
    bzero(buff, buffSize);
    BuffAllNodes(n1, buff, buffSize);
    printf("%s\n",buff);
    
    deleteNode(n1, "ABCD");
    bzero(buff, buffSize);
    BuffAllNodes(n1, buff, buffSize);
    printf("%s\n",buff);
    
    deleteNode(n1, "TESTS");
    bzero(buff, buffSize);
    BuffAllNodes(n1, buff, buffSize);
    printf("%s\n",buff);
    
    printf("Append a1\n");
    appendNode(n1, 23, "a1", 2, 12, 12);
    bzero(buff, buffSize);
    BuffAllNodes(n1, buff, buffSize);
    printf("%s\n",buff);
    
    printf("Append a2\n");
    appendNode(n1, 10, "a2", 2, 12, 12);
    bzero(buff, buffSize);
    BuffAllNodes(n1, buff, buffSize);
    printf("%s\n",buff);
    
    printf("Append a3\n");
    appendNode(n1, 234, "a3", 2, 12, 12);
    bzero(buff, buffSize);
    BuffAllNodes(n1, buff, buffSize);
    printf("%s\n",buff);

    printf("Append a4\n");
    appendNode(n1, 0, "a4", 2, 12, 12);
    bzero(buff, buffSize);
    BuffAllNodes(n1, buff, buffSize);
    printf("%s\n",buff);
    
    printf("Append a5\n");
    appendNode(n1, 10, "a5", 2, 12, 12);
    bzero(buff, buffSize);
    BuffAllNodes(n1, buff, buffSize);
    printf("%s\n",buff);
    
    printf("Append a6\n");
    appendNode(n1, 234, "a6", 2, 12, 12);
    bzero(buff, buffSize);
    BuffAllNodes(n1, buff, buffSize);
    printf("%s\n",buff);
    
    deleteNode(n1, "TESTS");
    bzero(buff, buffSize);
    BuffAllNodes(n1, buff, buffSize);
    printf("%s\n",buff);
    
    deleteNode(n1, "a5");
    bzero(buff, buffSize);
    BuffAllNodes(n1, buff, buffSize);
    printf("%s\n",buff);
    
    deleteNode(n1, "a3");
    bzero(buff, buffSize);
    BuffAllNodes(n1, buff, buffSize);
    printf("%s\n",buff);
    
    printf("Append a7\n");
    appendNode(n1, 234, "a7", 2, 12, 12);
    bzero(buff, buffSize);
    BuffAllNodes(n1, buff, buffSize);
    printf("%s\n",buff);
    
    printf("Append a7\n");
    appendNode(n1, 234, "a7", 2, 12, 12);
    bzero(buff, buffSize);
    BuffAllNodes(n1, buff, buffSize);
    printf("%s\n",buff);
    
    printf("Append a1\n");
    appendNode(n1, 234, "a1", 2, 12, 12);
    bzero(buff, buffSize);
    BuffAllNodes(n1, buff, buffSize);
    printf("%s\n",buff);
    
    printf("Append a3\n");
    appendNode(n1, 234, "a3", 2, 12, 12);
    bzero(buff, buffSize);
    BuffAllNodes(n1, buff, buffSize);
    printf("%s\n",buff);
    
    deleteNode(n1, "a1");
    bzero(buff, buffSize);
    BuffAllNodes(n1, buff, buffSize);
    printf("%s\n",buff);
    
    deleteNode(n1, "a2");
    bzero(buff, buffSize);
    BuffAllNodes(n1, buff, buffSize);
    printf("%s\n",buff);
    
    printf("Append a8\n");
    appendNode(n1, 234, "a8", 2, 12, 12);
    bzero(buff, buffSize);
    BuffAllNodes(n1, buff, buffSize);
    printf("%s\n",buff);
    
    deleteList(n1);
    
    return 0;
}
Пример #12
0
static void zhullInitialFacets(zhull_t *zh)
{
  list_t assoc = emptyList();
  list_t new_facets = emptyList();
  index_t i;
  index_t idx[3]= {0,1,2};
  list_t list=initListIndex(idx,3);
  if (getNumPoints(zh->pts)>= 3) {
    //      printf("initListFromTo: %d..%d\n", 0,getNumPoints(zh->pts)-1);
    assoc = initListFromTo(0,getNumPoints(zh->pts)-1);
    //     printList(assoc);
    new_facets = appendNewFacets(zh,2);
    if (getLength(new_facets)==2) {
      do {  // circumvent coincident points
        if (distancePointPoint(
              getPoint(zh->pts,idx[0]),
              getPoint(zh->pts,idx[1])
            )>TOL_DEGENERATE) {
          break;
        } else {
          idx[1]++;
        }
      } while (idx[1]<getNumPoints(zh->pts));
      if (idx[1]<getNumPoints(zh->pts)) {
        do { // circumvent degenerate triangles
          list=initListIndex(idx,3);
          if (lengthVector(normalOfListedPoints(zh->pts,list))>TOL_DEGENERATE) {
            break;
          } else {
            idx[2]++;
            freeList(&list);
          }
        } while (idx[2]<getNumPoints(zh->pts));
        if (idx[2]<getNumPoints(zh->pts)) {
          getFacetByIndex(new_facets,0)->corners = list;
          appendListToList(&(zh->used_pts),list);
          list=initListIndex(idx,3);
          reverseList(&list);
          getFacetByIndex(new_facets,1)->corners = list;
          getFacetByIndex(new_facets,0)->neighbors =
            initConstantList(entry_makePointer(getFacetByIndex(new_facets,1)),3);
          getFacetByIndex(new_facets,1)->neighbors =
            initConstantList(entry_makePointer(getFacetByIndex(new_facets,0)),3);
          for (i=0; i<2; i++) {
            getFacetByIndex(new_facets,i)->plane =
              planeFromListedPoints(zh->pts, getFacetByIndex(new_facets,i)->corners);
            getFacetByIndex(new_facets,i)->outsideset = emptyList();
            getFacetByIndex(new_facets,i)->insideset = emptyList();
            getFacetByIndex(new_facets,i)->maxdistance = 0.0f;
            //printf("removing facests\n");
            //printList(getFacetByIndex(new_facets,i)->corners);
            removeValueListFromList(&assoc,getFacetByIndex(new_facets,i)->corners);
          }
          //printf("dividePoints...");
          //printList(assoc);
          dividePointsBetweenNewFacets(zh, assoc, new_facets);
        }
      }
    }
    freeList(&new_facets);
    freeList(&assoc);
  }
}
Пример #13
0
/*
 * This method accepts a file name and loads its content into the given ProcessList structure
 */
int readDataFromFile(const char* file_name, ProcessList *processList){
	FILE* file = fopen (file_name, "r");
	int i = 0;

	if(file == NULL){
		printf("You have to provide a file named 'input.txt' \n Exiting now.\n");
		return 0;
	}

	//fscanf (file, "%d", &i);
	//printf ("%d ", i);

	IntList *intList = malloc(sizeof(IntList));

	int lineCounter = 0; // counter to count lines in the input file
	int numCounter = 0; // counter for each number in a line
	while(1){
		fscanf (file, "%d", &i);


		if(i == -99){

			//printf("\n");
			// we have a line of data now which needs to be added to processList
			ProcessInfo *processTmp = &processList->processList[lineCounter];
			processTmp->processId = intList->list[0];
			processTmp->arrivalTime = intList->list[1];

			processTmp->burstCompletedPos = 0;
			processTmp->isSubmitted = 0;
			processTmp->isCompleted = 0;

			// from intList->list[2] to end each even num is cpu burst and odd ones are io burst
			if(intList->size < 2) printf("invalid input data");

			processTmp->burstList.size = 0;
			processTmp->ioList.size = 0;

			int i;
			for(i=2; i<intList->size; i++){
				if (i%2 == 0){
					addNumToList(&processTmp->burstList, intList->list[i]); //even = cpu burst
				}else{
					addNumToList(&processTmp->ioList, intList->list[i]); //odd = io burst
				}
			}

			processList->size++;
			lineCounter++;
			emptyList(intList);
		}else{
			//processList->processList[counter].
			addNumToList(intList, i);
			//printf ("%d ", i);
		}

		numCounter++;
		if(feof (file)) break;
	}
	fclose (file);

	return 1;
}
Пример #14
0
void SM_Dropbox_Json::clear()
{
    emptyList();
    return;
}
void deleteList(LIST_HEAD *list) {
    emptyList(list);
    free(list);
}
Пример #16
0
/* Write the LLS on the screen (iterative) */
void write_LLS(typeList lis) {
    while (!emptyList(lis)) {
        printf("%d ", lis->data);
        lis = lis->next;
    }
}
Пример #17
0
MemberList::~MemberList()
{
    emptyList(head);
}
Пример #18
0
/* Recursive version of writeNodeF() */
void writeNodeF_r(FILE *outfile, typeList lis) {
    if (!emptyList(lis)) {
        writeDataTypeF(outfile, lis->data);
        writeNodeF_r(outfile, lis->next);
    }
}
Пример #19
0
AST performAction(AST t)
{
	AST s = t;
	AST ret;
	
	if(s->kind == ACTION_NK)
	{
		AST x = performAction(s->fields.subtrees.s1);
		AST y = applyNode(s->fields.subtrees.s2,x);
		ret = performAction(simplify(y));
	}
	else if(s->kind == BASIC_FUNC_NK)
	{
		if(s->extra == PRILST_FK)
		{
			AST x= simplify(s->fields.subtrees.s1);
			while(x->kind != EMPTYLIST)
			{	
				if(x->kind == ERROR_NK)
					ret= errorNode(x->fields.stringval);
				AST y = applyBasicFunc(x,"head");
				AST tmp = simplify(y);
				printValue(simplify(tmp));
				y = applyBasicFunc(x,"tail");
				x = simplify(y);
			}
			ret = emptyList();
		}
		else if(s->extra == PRINT_FK)
		{
			AST r = simplify(s->fields.subtrees.s1);
			printValue(r);
			ret = emptyList();
		}
		else if(s->extra == PROD_FK)
		{
			ret = simplify(s->fields.subtrees.s1);
		}
		else if(s->extra == READI_FK)
		{
			char str[11];
			if(fgets(str,11,stdin) != NULL)		
				ret = numberNode(atoi(str));
			else
				ret = errorNode("Not a valid number");
		}
		else if(s->extra == READC_FK)
		{
			char str[2];
			if(fgets(str,2,stdin) != NULL)		
				ret = charNode(str);
			else
				ret = errorNode("Not a valid character");
		}
		else
		{
			ret = errorNode("No action specified");
		}
	}
	else if(s->kind == ERROR_NK)
	{
		ret = errorNode(s->fields.stringval);
	}
	else
	{
		ret = errorNode("No action specified");
	}
	return ret;
}
Пример #20
0
int main(int argc, char** argv)
{
    #ifdef printauthor
    printf("artur goncalves, 69271\n");
    #endif // printauthor

    if (argc < 3 || argc % 2 != 1)
    {
        printf("Usage: %s name.surname IP [-t talkport] [-d dnsport] [-i saIP] [-p saport]\n", argv[0]);
        exit(-2);
    }

    // Set default values for arguments
    myTalkPort = 30000;
    myDnsPort = 30000;
    saPort = 58000;
    saIP.s_addr = 0;

    myName = argv[1];
    if (strstr(myName, ".") == NULL)
    {
        printf("Error on argument 'name.surname'. Must be separated by '.'\n");
        exit(-2);
    }
    if (inet_aton(argv[2], &myIP) == 0)
    {
        perror("Error parsing argument IP. Should be on dot-decimal notation.\n");
        exit(-2);
    }

    // Parse optional arguments
    int i;
    for (i = 3; i < argc - 1; i += 2)
    {
        if (strcmp(argv[i], "-t") == 0)
            myTalkPort = atoi(argv[i+1]);

        if (strcmp(argv[i], "-d") == 0)
            myDnsPort = atoi(argv[i+1]);

        if (strcmp(argv[i], "-i") == 0)
        {
            if (inet_aton(argv[i+1], &saIP) == 0)
            {
                perror("Error parsing saIP");
                exit(-2);
            }
        }

        if (strcmp(argv[i], "-p") == 0)
            saPort = atoi(argv[i+1]);
    }

    // Get default IP if it has not been set
    if (saIP.s_addr == 0)
        getDefaultSS(&saIP);

    fd_set rfds;
    int ret;
    char buffer[2048];
    buffer[2047] = '\0';    // Ensure buffer is always null-terminated.
    int max = 0;

    contacts = newList();
    talkServerSocket = prepareTalkServer();

    // Set handler the SIGINT (Ctrl+C) signal, which automatically leaves before terminating
    signal(SIGINT, sigintHandler);

    printPrompt();

    // Run while in normal conditions, or while we're in the process of leaving and exiting
    while (isRunning || joinStatus != NotJoined)
    {
        FD_ZERO(&rfds);
        FD_SET(STDIN_FILENO, &rfds);
        max = (STDIN_FILENO > max) ? STDIN_FILENO : max;

        // Add different sockets to rfds if they are ready to be used

        /* Always add the TCP server socket for starting chats
           There's no problem if we're not even joined yet, the chats only depend on the
           rest of the program to find the IP+port. */
        FD_SET(talkServerSocket, &rfds);
        max = (talkServerSocket > max) ? talkServerSocket : max;

        // Chat socket, possibly open with a contact
        if (talkSocket != -1)
        {
            FD_SET(talkSocket, &rfds);
            max = (talkSocket > max) ? talkSocket : max;
        }

        // DNS socket, used to trade behind-the-scenes messages like queries, etc
        if (dnsSocket != -1)
        {
            FD_SET(dnsSocket, &rfds);
            max = (dnsSocket > max) ? dnsSocket : max;
        }

        // Set timeout if state is not stable (if we are waiting for OKs, etc)
        struct timeval timeout;
        struct timeval* pTimeout = NULL;
        if ((joinStatus != Joined && joinStatus != NotJoined)
            ||
            (findStatus != NotFinding))
        {
            pTimeout = &timeout;
            timeout.tv_sec = 10;
            timeout.tv_usec = 0;
        }

        // Multiplex all possible inputs
        ret = select(max + 1, &rfds, NULL, NULL, pTimeout);
        if (ret < 0)
        {
            // If user pressed Ctrl+C (INTerRuption), don't leave the loop yet
            // We must wait the 'leave' messages and OKs to be sent
            // ...unless we are not joined to begin with
            if (errno == EINTR)
            {
                if (joinStatus == NotJoined)
                    break;
                else
                    continue;
            }

            perror("Error on select()");
            exit(-1);
        }

        // Handle a timeout
        if (ret == 0)
        {
            if (joinStatus != Joined)
            {
                if (joinStatus < Joined)
                    printf("Join timed out. Aborted join. Please try again.\n");
                else
                    printf("Leave timed out. Forced leave.\n");
                    logm(1, "Other members' state may be inconsistent. Sent UNR to Surname Server just in case.\n");

                abortJoin();
            }

            if (findStatus != NotFinding)
            {
                findStatus = NotFinding;
                printf("Find timed out. Find cancelled.\n");
            }
        }

        // Read user commands from stdin
        if (FD_ISSET(STDIN_FILENO, &rfds))
        {
            fgets(buffer, 2047, stdin);
            parseCommand(buffer, &isRunning);

            printPrompt();
        }

        // Read messages from current call
        if (talkSocket != -1 && FD_ISSET(talkSocket, &rfds))
        {
            receiveMessage(buffer);
        }

        // Accept an imcoming call from the Call Server
        if (talkServerSocket != -1 && FD_ISSET(talkServerSocket, &rfds))
        {
            acceptCall();
        }

        // Handle a query or reply on the DNS
        if (dnsSocket != -1 && FD_ISSET(dnsSocket, &rfds))
        {
            parseServerCommand(&isRunning);
        }
    }

    // Loop ends when user wants to close program

    // Free memory
    emptyList(contacts);
    free(contacts);

    logm(1, "Exiting gracefully.\n");
    exit(0);
}
Пример #21
0
void QDropboxJson::clear()
{
    emptyList();
    return;
}
Пример #22
0
BomKeyNode::BomKeyNode(): KeyValNode("bom", mList = emptyList()) {
    mHead = NULL;
    mMajor = 1;
    mCount = 0;
}